@@ -54,7 +54,6 @@ export interface LearningMapEditorProps {
5454 language ?: string ;
5555 onChange ?: ( data : RoadmapData ) => void ;
5656 jsonStore ?: string ;
57- onLoadExternal ?: ( id : string ) => void ;
5857}
5958
6059const getDefaultFilename = ( ) => {
@@ -68,36 +67,33 @@ export function LearningMapEditor({
6867 language = "en" ,
6968 onChange,
7069 jsonStore = "https://json.openpatch.org" ,
71- onLoadExternal,
7270} : LearningMapEditorProps ) {
73- const { screenToFlowPosition, zoomIn, zoomOut, setCenter, fitView, getNodes, getEdges } = useReactFlow ( ) ;
74- const [ roadmapState , setRoadmapState , { undo, redo, canUndo, canRedo, reset, resetInitialState } ] = useUndoable < RoadmapData > ( {
75- settings : { } ,
76- version : 1 ,
77- } ) ;
71+
72+ const parsedRoadmap = parseRoadmapData ( roadmapData || "" ) ;
73+ const { screenToFlowPosition, zoomIn, zoomOut, setCenter, fitView } = useReactFlow ( ) ;
74+ const [ roadmapState , setRoadmapState , { undo, redo, canUndo, canRedo, reset, resetInitialState } ] = useUndoable < RoadmapData > ( parsedRoadmap ) ;
7875
7976 const [ saved , setSaved ] = useState ( true ) ;
8077 const [ didUndoRedo , setDidUndoRedo ] = useState ( false ) ;
8178 const [ previewMode , setPreviewMode ] = useState ( false ) ;
8279 const [ debugMode , setDebugMode ] = useState ( false ) ;
83- const [ nodes , setNodes , onNodesChange ] = useNodesState < NodeData > ( [ ] ) ;
84- const [ edges , setEdges , onEdgesChange ] = useEdgesState < Edge > ( [ ] ) ;
85- const [ settings , setSettings ] = useState < Settings > ( { background : { color : "#ffffff" } } ) ;
86- const [ showGrid , setShowGrid ] = useState ( true ) ;
80+ const [ nodes , setNodes , onNodesChange ] = useNodesState < NodeData > ( parsedRoadmap . nodes ) ;
81+ const [ edges , setEdges , onEdgesChange ] = useEdgesState < Edge > ( parsedRoadmap . edges ) ;
82+ const [ settings , setSettings ] = useState < Settings > ( parsedRoadmap . settings ) ;
83+ const [ showGrid , setShowGrid ] = useState ( false ) ;
8784 const [ clipboard , setClipboard ] = useState < { nodes : Node < NodeData > [ ] ; edges : Edge [ ] } | null > ( null ) ;
8885
8986 // Use language from settings if available, otherwise use prop
9087 const effectiveLanguage = settings ?. language || language ;
9188 const t = getTranslations ( effectiveLanguage ) ;
9289
9390 const keyboardShortcuts = [
94- { action : t . shortcuts . save , shortcut : "Ctrl+S" } ,
9591 { action : t . shortcuts . undo , shortcut : "Ctrl+Z" } ,
9692 { action : t . shortcuts . redo , shortcut : "Ctrl+Y or Ctrl+Shift+Z" } ,
97- { action : t . shortcuts . addTaskNode , shortcut : "Ctrl+A " } ,
98- { action : t . shortcuts . addTopicNode , shortcut : "Ctrl+O " } ,
99- { action : t . shortcuts . addImageNode , shortcut : "Ctrl+I " } ,
100- { action : t . shortcuts . addTextNode , shortcut : "Ctrl+B " } ,
93+ { action : t . shortcuts . addTaskNode , shortcut : "Ctrl+1 " } ,
94+ { action : t . shortcuts . addTopicNode , shortcut : "Ctrl+2 " } ,
95+ { action : t . shortcuts . addImageNode , shortcut : "Ctrl+3 " } ,
96+ { action : t . shortcuts . addTextNode , shortcut : "Ctrl+4 " } ,
10197 { action : t . shortcuts . deleteNodeEdge , shortcut : "Delete" } ,
10298 { action : t . shortcuts . togglePreviewMode , shortcut : "Ctrl+P" } ,
10399 { action : t . shortcuts . toggleDebugMode , shortcut : "Ctrl+D" } ,
@@ -139,7 +135,6 @@ export function LearningMapEditor({
139135 const [ edgeDrawerOpen , setEdgeDrawerOpen ] = useState ( false ) ;
140136
141137 useEffect ( ( ) => {
142- const parsedRoadmap = parseRoadmapData ( roadmapData || "" ) ;
143138 loadRoadmapStateIntoReactFlowState ( parsedRoadmap ) ;
144139 resetInitialState ( parsedRoadmap ) ;
145140 } , [ roadmapData ] )
@@ -414,11 +409,9 @@ export function LearningMapEditor({
414409 // Auto-save when changes are made
415410 useEffect ( ( ) => {
416411 if ( ! saved ) {
417- const timeoutId = setTimeout ( ( ) => {
412+ setTimeout ( ( ) => {
418413 handleSave ( ) ;
419- } , 1000 ) ; // Auto-save after 1 second of inactivity
420-
421- return ( ) => clearTimeout ( timeoutId ) ;
414+ } , 2000 ) ;
422415 }
423416 } , [ saved , handleSave ] ) ;
424417
@@ -711,22 +704,21 @@ export function LearningMapEditor({
711704 handleRedo ( ) ;
712705 }
713706 // add task node shortcut
714- if ( ( e . ctrlKey || e . metaKey ) && e . key . toLowerCase ( ) === 'a ' && ! e . shiftKey ) {
707+ if ( ( e . ctrlKey || e . metaKey ) && e . key === '1 ' && ! e . shiftKey ) {
715708 e . preventDefault ( ) ;
716709 addNewNode ( "task" ) ;
717710 }
718711 // add topic node shortcut
719- if ( ( e . ctrlKey || e . metaKey ) && e . key . toLowerCase ( ) === 'o ' && ! e . shiftKey ) {
712+ if ( ( e . ctrlKey || e . metaKey ) && e . key === '2 ' && ! e . shiftKey ) {
720713 e . preventDefault ( ) ;
721714 addNewNode ( "topic" ) ;
722715 }
723716 // add image node shortcut
724- if ( ( e . ctrlKey || e . metaKey ) && e . key . toLowerCase ( ) === 'i ' && ! e . shiftKey ) {
717+ if ( ( e . ctrlKey || e . metaKey ) && e . key === '3 ' && ! e . shiftKey ) {
725718 e . preventDefault ( ) ;
726719 addNewNode ( "image" ) ;
727720 }
728- // add text node shortcut - changed to Ctrl+T
729- if ( ( e . ctrlKey || e . metaKey ) && e . key . toLowerCase ( ) === 'b' && ! e . shiftKey ) {
721+ if ( ( e . ctrlKey || e . metaKey ) && e . key === '4' && ! e . shiftKey ) {
730722 e . preventDefault ( ) ;
731723 addNewNode ( "text" ) ;
732724 }
@@ -840,14 +832,12 @@ export function LearningMapEditor({
840832 backgroundColor : settings ?. background ?. color || "#ffffff" ,
841833 } }
842834 >
843- { nodes . length === 0 && edges . filter ( e => ! e . id . startsWith ( "debug-" ) ) . length === 0 && (
844- < WelcomeMessage
845- onOpenFile = { handleOpen }
846- onAddTopic = { ( ) => addNewNode ( "topic" ) }
847- onShowHelp = { ( ) => setHelpOpen ( true ) }
848- language = { effectiveLanguage }
849- />
850- ) }
835+ { nodes . length === 0 && edges . length === 0 && < WelcomeMessage
836+ onOpenFile = { handleOpen }
837+ onAddTopic = { ( ) => addNewNode ( "topic" ) }
838+ onShowHelp = { ( ) => setHelpOpen ( true ) }
839+ language = { effectiveLanguage }
840+ /> }
851841 < ReactFlow
852842 nodes = { nodes }
853843 edges = { edges }
0 commit comments