diff --git a/.changeset/quiet-hosts-keep.md b/.changeset/quiet-hosts-keep.md new file mode 100644 index 0000000..331d4dc --- /dev/null +++ b/.changeset/quiet-hosts-keep.md @@ -0,0 +1,10 @@ +--- +"@learningmap/learningmap": patch +"@learningmap/web-component": patch +--- + +Respect `disableFileOperations` and `disablePersist` everywhere in the editor + +- The welcome screen no longer offers to open a file when file operations are disabled, and no longer says the data is stored in the browser when persistence is disabled +- The save shortcut (Ctrl/⌘+S) no longer downloads a copy when file operations are disabled; the keystroke is left to the host page +- The editor web component accepts `disable-persist` diff --git a/packages/learningmap/src/KeyboardShortcuts.tsx b/packages/learningmap/src/KeyboardShortcuts.tsx index 6cfa70d..564bacb 100644 --- a/packages/learningmap/src/KeyboardShortcuts.tsx +++ b/packages/learningmap/src/KeyboardShortcuts.tsx @@ -7,6 +7,11 @@ import { createNode, CreatableNodeType } from "./nodeFactory"; interface KeyboardShortcutsProps { jsonStore?: string; keyBindings?: Partial; + /** + * The host keeps the file: the save shortcut does not download a copy and + * is left to the host instead. + */ + disableFileOperations?: boolean; } // Default keybindings @@ -62,7 +67,8 @@ const matchesKeyBinding = (e: KeyboardEvent, binding: KeyBinding | undefined): b export const KeyboardShortcuts = ({ jsonStore = "https://json.openpatch.org", - keyBindings: customKeyBindings = {} + keyBindings: customKeyBindings = {}, + disableFileOperations = false, }: KeyboardShortcutsProps) => { // Merge custom keybindings with defaults const keyBindings = { ...defaultKeyBindings, ...customKeyBindings }; @@ -246,6 +252,7 @@ export const KeyboardShortcuts = ({ e.preventDefault(); onAddNode("text"); } else if (matchesKeyBinding(e, keyBindings.save)) { + if (disableFileOperations) return; e.preventDefault(); onSave(); } else if (matchesKeyBinding(e, keyBindings.undo)) { diff --git a/packages/learningmap/src/LearningMapEditor.tsx b/packages/learningmap/src/LearningMapEditor.tsx index 5c35f5a..112916d 100644 --- a/packages/learningmap/src/LearningMapEditor.tsx +++ b/packages/learningmap/src/LearningMapEditor.tsx @@ -82,7 +82,11 @@ export function LearningMapEditor({ return ( <> {/* Keyboard shortcuts handler */} - + {/* Toolbar */} @@ -94,7 +98,9 @@ export function LearningMapEditor({ {previewMode && } {!previewMode && <> {/* Welcome message when empty */} - {nodes.length === 0 && edges.length === 0 && } + {nodes.length === 0 && edges.length === 0 && ( + + )} {/* Main canvas */} diff --git a/packages/learningmap/src/WelcomeMessage.tsx b/packages/learningmap/src/WelcomeMessage.tsx index c838b46..257e3f2 100644 --- a/packages/learningmap/src/WelcomeMessage.tsx +++ b/packages/learningmap/src/WelcomeMessage.tsx @@ -6,7 +6,17 @@ import logo from "./logo.svg"; import { useFileOperations } from "./useFileOperations"; import { createNode } from "./nodeFactory"; -export const WelcomeMessage: React.FC = () => { +interface WelcomeMessageProps { + /** The host keeps the file, so there is nothing to open here. */ + disableFileOperations?: boolean; + /** Nothing is kept in the browser, so it should not say so. */ + disablePersist?: boolean; +} + +export const WelcomeMessage: React.FC = ({ + disableFileOperations = false, + disablePersist = false, +}) => { // Get state and actions from store const addNode = useEditorStore(state => state.addNode); const setHelpOpen = useEditorStore(state => state.setHelpOpen); @@ -36,12 +46,14 @@ export const WelcomeMessage: React.FC = () => {

Logo {t.welcomeTitle}

-

{t.welcomeSubtitle}

+ {!disablePersist &&

{t.welcomeSubtitle}

}
- + {!disableFileOperations && ( + + )}