import { useEffect } from "react"; type DocumentActionDialogProps = | { type: "new-location"; busy?: false; onCurrentWindow: () => void; onNewWindow: () => void; onCancel: () => void; } | { type: "unsaved"; busy: boolean; onSave: () => void; onDiscard: () => void; onCancel: () => void; }; export function DocumentActionDialog( props: DocumentActionDialogProps ) { useEffect(() => { const handleKeyDown = (event: KeyboardEvent) => { if (event.key === "Escape" && !props.busy) { event.preventDefault(); props.onCancel(); } }; window.addEventListener("keydown", handleKeyDown); return () => window.removeEventListener("keydown", handleKeyDown); }, [props]); const isNewLocation = props.type === "new-location"; return (
{isNewLocation ? "请选择在当前窗口新建,或者保留当前文档并打开一个新窗口。" : "当前文档包含尚未保存的修改。继续操作前,可以先保存这些内容。"}