@@ -3,15 +3,20 @@ import { useEffect } from "react";
33import { useNodeFactoryContext } from "@utils/nodeFactory" ;
44import { useNodeSystemContext } from "@utils/nodeSystem" ;
55import { useNodeHistoryContext } from "@utils/nodeHistory" ;
6- import { downloadScript } from "@utils/compilerTools" ;
76import { usePromptContext } from "@utils/prompt" ;
87import { usePalleteContext } from "@utils/pallete" ;
98import { useVariablesContext } from "@utils/variables" ;
9+ import { loadProject , saveProject } from "@utils/engineTools" ;
10+ import {
11+ getBreadcrumb ,
12+ getWindowTools ,
13+ loadActiveProjectId ,
14+ updatePalleteRegistry ,
15+ } from "@utils/projectTools" ;
1016
1117import { AppWindow } from "@components/window/AppWindow" ;
1218import { Canvas } from "@components/engine/Canvas" ;
1319import { Prompt } from "@components/commons/Prompt" ;
14- import { loadProject , saveProject } from "@utils/engineTools" ;
1520
1621export default function App ( ) {
1722 const { newNode } = useNodeFactoryContext ( ) ! ;
@@ -49,92 +54,54 @@ export default function App() {
4954 requestPrompt,
5055 } = usePromptContext ( ) ! ;
5156
52- const windowTools = [
53- {
54- name : "Refresh" ,
55- icon : "RefreshCw" ,
56- action : ( ) => window . location . reload ( ) ,
57- } ,
58- {
59- name : "Close Node" ,
60- icon : "CircleChevronUp" ,
61- action : closeNode ,
62- disabled : isEntry ( activeNode )
63- } ,
64- {
65- name : "Load Project" ,
66- icon : "HardDriveUpload" ,
67- action : ( ) => loadProject (
57+ const windowTools = getWindowTools (
58+ closeNode ,
59+ isEntry ,
60+ activeNode ,
61+ overrideNodeSystem ,
62+ overrideVariables ,
63+ openNode ,
64+ removeNode ,
65+ nodeSystem ,
66+ entries ,
67+ statesList ,
68+ customComponents ,
69+ ) ;
70+
71+ const windowExtraTitle = getBreadcrumb (
72+ nodeHistory ,
73+ activeNode ,
74+ ) ;
75+
76+ useEffect ( ( ) => {
77+ ( async ( ) => {
78+ const requireLoading = await loadActiveProjectId ( ) ;
79+ if ( ! requireLoading ) return ;
80+
81+ loadProject (
6882 overrideNodeSystem ,
6983 overrideVariables ,
7084 openNode ,
7185 removeNode ,
72- ) ,
73- } ,
74- {
75- name : "Save Project" ,
76- icon : "HardDriveDownload" ,
77- action : ( ) => saveProject (
78- nodeSystem ,
79- entries ,
80- {
81- states : statesList ,
82- customComponents,
83- }
84- ) ,
85- } ,
86- {
87- name : "Compile Project" ,
88- icon : "Rocket" ,
89- action : ( ) => downloadScript ( nodeSystem , entries ) ,
90- } ,
91- ] ;
92-
93- const windowExtraTitle = [
94- ...nodeHistory . current ,
95- activeNode
96- ] . join ( " > " ) ;
86+ )
87+ } ) ( ) ;
88+ } , [
89+ overrideNodeSystem ,
90+ overrideVariables ,
91+ openNode ,
92+ removeNode ,
93+ ] ) ;
9794
9895 useEffect ( ( ) => {
99- entries . map (
100- entry => ( {
101- name : entry ,
102- icon : "Component" ,
103- action : ( ) => openNode ( entry , true ) ,
104- } )
105- ) . forEach ( suggestion => addSuggestion (
106- suggestion , "Entries"
107- ) ) ;
108-
109- addSuggestion ( {
110- name : "New Entry" ,
111- icon : "NotebookPen" ,
112- action : ( ) => {
113- ( async ( ) => {
114- const entryName = (
115- await requestPrompt (
116- "Enter the name of the new Entry Point"
117- )
118- ) ?. trim ( ) . toUpperCase ( ) ;
119-
120- if ( ! entryName ) return ;
121- createEntry ( entryName ) ;
122- openNode ( entryName , true ) ;
123- } ) ( ) ;
124- }
125- } , "Create" ) ;
126-
127- addSuggestion ( {
128- name : "New Component" ,
129- icon : "Puzzle" ,
130- action : promptComponent ,
131- } , "Register" ) ;
132-
133- addSuggestion ( {
134- name : "New State" ,
135- icon : "Puzzle" ,
136- action : promptState ,
137- } , "Register" ) ;
96+ updatePalleteRegistry (
97+ addSuggestion ,
98+ openNode ,
99+ entries ,
100+ createEntry ,
101+ requestPrompt ,
102+ promptComponent ,
103+ promptState ,
104+ )
138105 } , [
139106 addSuggestion ,
140107 openNode ,
@@ -145,6 +112,22 @@ export default function App() {
145112 promptState ,
146113 ] ) ;
147114
115+ useEffect ( ( ) => {
116+ saveProject (
117+ nodeSystem ,
118+ entries ,
119+ {
120+ states : statesList ,
121+ customComponents,
122+ } ,
123+ ) ;
124+ } , [
125+ entries ,
126+ nodeSystem ,
127+ statesList ,
128+ customComponents ,
129+ ] ) ;
130+
148131 return ( < >
149132 < AppWindow
150133 tools = { windowTools }
0 commit comments