diff --git a/sample/vars/declare-vars.json b/sample/vars/declare-vars.json index a85524d..8b0e299 100644 --- a/sample/vars/declare-vars.json +++ b/sample/vars/declare-vars.json @@ -3,7 +3,9 @@ "desc": "", "firstid": 1, "export": true, - "import": ["vars/declare-core.json"], + "import": [ + "vars/declare-core.json" + ], "declvar": [ { "name": "owner", @@ -17,5 +19,6 @@ "root": { "id": 1, "name": "Sequence" - } -} + }, + "group": [] +} \ No newline at end of file diff --git a/sample/vars/test-vars.json b/sample/vars/test-vars.json index ba2d793..d71bf8a 100644 --- a/sample/vars/test-vars.json +++ b/sample/vars/test-vars.json @@ -18,10 +18,6 @@ { "name": "target1", "desc": "其它目标" - }, - { - "name": "test", - "desc": "测试" } ], "root": { diff --git a/src/components/editor.tsx b/src/components/editor.tsx index 2dbe65e..835a9c5 100644 --- a/src/components/editor.tsx +++ b/src/components/editor.tsx @@ -218,6 +218,8 @@ export const Editor: FC = ({ onUpdate: updateState, data: editor, . relative: state.relative, updateFileMeta: state.updateFileMeta, nodeDefs: state.nodeDefs, + editingTree: state.editingTree, + editingNode: state.editingNode, })) ); @@ -550,6 +552,7 @@ export const Editor: FC = ({ onUpdate: updateState, data: editor, . .sort((a, b) => a.name.localeCompare(b.name)); b3util.updateUsingGroups(editor.data.group); b3util.updateUsingVars(collectVarDefs(editor)); + pushHistory(); refresh(); onChange(); } @@ -584,7 +587,16 @@ export const Editor: FC = ({ onUpdate: updateState, data: editor, . const pushHistory = () => { editor.historyStack.length = ++editor.historyIndex; - editor.historyStack.push(b3util.createNode(editor.root)); + editor.historyStack.push( + JSON.stringify( + { + ...editor.data, + root: b3util.createNode(editor.root), + }, + null, + 2 + ) + ); }; const copyNode = () => { @@ -728,13 +740,23 @@ export const Editor: FC = ({ onUpdate: updateState, data: editor, . editor.graph.findById(data.id)?.draw(); }; - const useStackData = (data: NodeModel) => { - editor.root = createTreeData(data); + const useStackData = (str: string) => { + const data = JSON.parse(str) as TreeModel; + editor.data = data; + editor.root = createTreeData(data.root); + editor.import = data.import.map((v) => ({ path: v, vars: [] })); + editor.declvar = data.declvar.map((v) => ({ ...v })); editor.autoId = b3util.refreshTreeDataId(editor.root, editor.data.firstid); editor.graph.changeData(editor.root); editor.graph.layout(); restoreViewport(); onChange(); + + if (workspace.editingTree) { + workspace.onEditingTree(editor); + } else if (workspace.editingNode) { + selectNode(workspace.editingNode.data.id.toString()); + } }; const updateGrahp = () => { @@ -744,16 +766,14 @@ export const Editor: FC = ({ onUpdate: updateState, data: editor, . const undo = () => { if (editor.historyIndex > 0) { - const data = editor.historyStack[--editor.historyIndex]; - useStackData(data); + useStackData(editor.historyStack[--editor.historyIndex]); updateSearchState(); } }; const redo = () => { if (editor.historyIndex < editor.historyStack.length - 1) { - const data = editor.historyStack[++editor.historyIndex]; - useStackData(data); + useStackData(editor.historyStack[++editor.historyIndex]); updateSearchState(); } }; diff --git a/src/contexts/workspace-context.ts b/src/contexts/workspace-context.ts index 92770dd..74b28fa 100644 --- a/src/contexts/workspace-context.ts +++ b/src/contexts/workspace-context.ts @@ -58,7 +58,7 @@ export class EditorStore { alertReload: boolean = false; searchingText?: string; - historyStack: NodeModel[] = []; + historyStack: string[] = []; historyIndex: number = 0; selectedId?: string | null; @@ -79,7 +79,16 @@ export class EditorStore { this.import = this.data.import.map((v) => ({ path: v, vars: [] })); this.declvar = this.data.declvar.map((v) => ({ ...v })); this.autoId = b3util.refreshTreeDataId(this.root, this.data.firstid); - this.historyStack.push(b3util.createNode(this.root)); + this.historyStack.push( + JSON.stringify( + { + ...this.data, + root: b3util.createNode(this.root), + }, + null, + 2 + ) + ); this.historyIndex = 0; } } diff --git a/src/misc/b3util.ts b/src/misc/b3util.ts index 5cb02b5..1ff4763 100644 --- a/src/misc/b3util.ts +++ b/src/misc/b3util.ts @@ -721,6 +721,7 @@ export const loadVarDef = (list: ImportDef[]) => { // TODO: check file date // TODO: use cache if (entry.vars.length) { + entry.vars.forEach((v) => all.add(v)); continue; } const filter: Map = new Map();