Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .changeset/quiet-hosts-keep.md
Original file line number Diff line number Diff line change
@@ -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`
9 changes: 8 additions & 1 deletion packages/learningmap/src/KeyboardShortcuts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ import { createNode, CreatableNodeType } from "./nodeFactory";
interface KeyboardShortcutsProps {
jsonStore?: string;
keyBindings?: Partial<KeyBindings>;
/**
* The host keeps the file: the save shortcut does not download a copy and
* is left to the host instead.
*/
disableFileOperations?: boolean;
}

// Default keybindings
Expand Down Expand Up @@ -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 };
Expand Down Expand Up @@ -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)) {
Expand Down
10 changes: 8 additions & 2 deletions packages/learningmap/src/LearningMapEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,11 @@ export function LearningMapEditor({
return (
<>
{/* Keyboard shortcuts handler */}
<KeyboardShortcuts jsonStore={jsonStore} keyBindings={keyBindings} />
<KeyboardShortcuts
jsonStore={jsonStore}
keyBindings={keyBindings}
disableFileOperations={disableFileOperations}
/>

{/* Toolbar */}
<EditorToolbar disableSharing={disableSharing} disableFileOperations={disableFileOperations} />
Expand All @@ -94,7 +98,9 @@ export function LearningMapEditor({
{previewMode && <LearningMap roadmapData={getRoadmapData()} />}
{!previewMode && <>
{/* Welcome message when empty */}
{nodes.length === 0 && edges.length === 0 && <WelcomeMessage />}
{nodes.length === 0 && edges.length === 0 && (
<WelcomeMessage disableFileOperations={disableFileOperations} disablePersist={disablePersist} />
)}

{/* Main canvas */}
<EditorCanvas />
Expand Down
24 changes: 18 additions & 6 deletions packages/learningmap/src/WelcomeMessage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<WelcomeMessageProps> = ({
disableFileOperations = false,
disablePersist = false,
}) => {
// Get state and actions from store
const addNode = useEditorStore(state => state.addNode);
const setHelpOpen = useEditorStore(state => state.setHelpOpen);
Expand Down Expand Up @@ -36,12 +46,14 @@ export const WelcomeMessage: React.FC = () => {
<h1 className="welcome-title">
<img src={logo} alt="Logo" className="welcome-logo" />
{t.welcomeTitle}</h1>
<p className="welcome-subtitle">{t.welcomeSubtitle}</p>
{!disablePersist && <p className="welcome-subtitle">{t.welcomeSubtitle}</p>}
<div className="welcome-actions">
<button onClick={openRoadmap} className="primary-button">
<FolderOpen size={18} />
{t.welcomeOpenFile}
</button>
{!disableFileOperations && (
<button onClick={openRoadmap} className="primary-button">
<FolderOpen size={18} />
{t.welcomeOpenFile}
</button>
)}
<button onClick={onAddTopic} className="primary-button">
<Plus size={18} />
{t.welcomeAddTopic}
Expand Down
1 change: 1 addition & 0 deletions packages/web-component/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const LearningmapEditorWC = r2wc(LearningMapEditor, {
jsonStore: "string",
disableSharing: "boolean",
disableFileOperations: "boolean",
disablePersist: "boolean",
keyBindings: "json",
onChange: "function",
},
Expand Down
Loading