optimize file format
This commit is contained in:
1 parent
e8ae056461
commit
53c1912fa0
9 files changed
+115
-168
No files matched your search
@@ -3,9 +3,8 @@
|
||||
"desc": "",
|
||||
"firstid": 1,
|
||||
"export": true,
|
||||
"declare": {
|
||||
"imports": [],
|
||||
"vars": [
|
||||
"import": [],
|
||||
"declvar": [
|
||||
{
|
||||
"name": "context",
|
||||
"desc": "上下文"
|
||||
@@ -14,8 +13,7 @@
|
||||
"name": "version",
|
||||
"desc": "版本"
|
||||
}
|
||||
]
|
||||
},
|
||||
],
|
||||
"root": {
|
||||
"id": 1,
|
||||
"name": "Sequence"
|
||||
|
||||
@@ -3,11 +3,8 @@
|
||||
"desc": "",
|
||||
"firstid": 1,
|
||||
"export": true,
|
||||
"declare": {
|
||||
"imports": [
|
||||
"vars/declare-core.json"
|
||||
],
|
||||
"vars": [
|
||||
"import": ["vars/declare-core.json"],
|
||||
"declvar": [
|
||||
{
|
||||
"name": "owner",
|
||||
"desc": "所有者"
|
||||
@@ -16,8 +13,7 @@
|
||||
"name": "skill",
|
||||
"desc": "技能"
|
||||
}
|
||||
]
|
||||
},
|
||||
],
|
||||
"root": {
|
||||
"id": 1,
|
||||
"name": "Sequence"
|
||||
|
||||
@@ -3,17 +3,13 @@
|
||||
"desc": "",
|
||||
"firstid": 1,
|
||||
"export": true,
|
||||
"declare": {
|
||||
"imports": [
|
||||
"vars/declare-core.json"
|
||||
],
|
||||
"vars": [
|
||||
"import": ["vars/declare-core.json"],
|
||||
"declvar": [
|
||||
{
|
||||
"name": "test",
|
||||
"desc": "测试"
|
||||
}
|
||||
]
|
||||
},
|
||||
],
|
||||
"root": {
|
||||
"id": 1,
|
||||
"name": "Sequence",
|
||||
|
||||
@@ -6,12 +6,11 @@
|
||||
"group": [
|
||||
"Client"
|
||||
],
|
||||
"declare": {
|
||||
"imports": [
|
||||
"import": [
|
||||
"vars/declare-core.json",
|
||||
"vars/declare-vars.json"
|
||||
],
|
||||
"vars": [
|
||||
"declvar": [
|
||||
{
|
||||
"name": "target",
|
||||
"desc": "目标"
|
||||
@@ -24,8 +23,7 @@
|
||||
"name": "test",
|
||||
"desc": "测试"
|
||||
}
|
||||
]
|
||||
},
|
||||
],
|
||||
"root": {
|
||||
"id": 1,
|
||||
"name": "Sequence",
|
||||
|
||||
+57
-63
@@ -49,9 +49,9 @@ interface FilterOption {
|
||||
}
|
||||
|
||||
const collectVarDefs = (editor: EditorStore) => {
|
||||
const vars: VarDef[] = editor.declare.vars.slice();
|
||||
loadVarDef(editor.declare.imports).forEach((v) => vars.push(v));
|
||||
loadSubtreeVarDef(editor.data).forEach((v) => vars.push(v));
|
||||
const vars: VarDef[] = editor.declvar.slice();
|
||||
loadVarDef(editor.import).forEach((v) => vars.push(v));
|
||||
loadSubtreeVarDef(editor.root).forEach((v) => vars.push(v));
|
||||
return vars;
|
||||
};
|
||||
|
||||
@@ -69,33 +69,35 @@ const refreshTreeData = (data: TreeGraphData) => {
|
||||
};
|
||||
|
||||
const isTreeUpdated = (editor: EditorStore, editTree: EditTree) => {
|
||||
const data = editTree.data;
|
||||
if (
|
||||
editor.firstid !== data.firstid ||
|
||||
editor.export !== data.export ||
|
||||
editor.name !== data.name ||
|
||||
editor.desc !== data.desc
|
||||
editor.data.firstid !== editTree.data.firstid ||
|
||||
editor.data.export !== editTree.data.export ||
|
||||
editor.data.name !== editTree.data.name ||
|
||||
editor.data.desc !== editTree.data.desc
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
|
||||
for (let i = 0; i < Math.max(editor.declare.vars.length, data.declare.vars.length); i++) {
|
||||
const v1: VarDef | undefined = editor.declare.vars[i];
|
||||
const v2: VarDef | undefined = data.declare.vars[i];
|
||||
let max = Math.max(editor.declvar.length, editTree.data.declvar.length);
|
||||
for (let i = 0; i < max; i++) {
|
||||
const v1: VarDef | undefined = editor.declvar[i];
|
||||
const v2: VarDef | undefined = editTree.data.declvar[i];
|
||||
if (v1?.name !== v2?.name || v1?.desc !== v2?.desc) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
for (let i = 0; i < Math.max(editor.group.length, data.group.length); i++) {
|
||||
if (editor.group[i] !== data.group[i]) {
|
||||
max = Math.max(editor.data.group.length, editTree.data.group.length);
|
||||
for (let i = 0; i < max; i++) {
|
||||
if (editor.data.group[i] !== editTree.data.group[i]) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
for (let i = 0; i < Math.max(editor.declare.imports.length, data.declare.imports.length); i++) {
|
||||
const v1: ImportDef | undefined = editor.declare.imports[i];
|
||||
const v2: ImportDef | undefined = data.declare.imports[i];
|
||||
max = Math.max(editor.import.length, editTree.data.import.length);
|
||||
for (let i = 0; i < max; i++) {
|
||||
const v1: ImportDef | undefined = editor.import[i];
|
||||
const v2: ImportDef | undefined = editTree.data.import[i];
|
||||
if (v1?.path !== v2?.path) {
|
||||
return true;
|
||||
}
|
||||
@@ -241,7 +243,7 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
|
||||
const onSearchChange = (option: FilterOption) => {
|
||||
option.results.length = 0;
|
||||
editor.searchingText = option.filterStr;
|
||||
filterNodes(option, editor.data);
|
||||
filterNodes(option, editor.root);
|
||||
setFilterOption({
|
||||
...option,
|
||||
});
|
||||
@@ -259,7 +261,7 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
|
||||
const updateSearchState = () => {
|
||||
const option = { ...filterOption };
|
||||
option.results.length = 0;
|
||||
filterNodes(option, editor.data);
|
||||
filterNodes(option, editor.root);
|
||||
setFilterOption({
|
||||
...option,
|
||||
});
|
||||
@@ -356,7 +358,7 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
|
||||
}
|
||||
}
|
||||
};
|
||||
return traverse(editor.data) as TreeGraphData;
|
||||
return traverse(editor.root) as TreeGraphData;
|
||||
};
|
||||
|
||||
const includeString = (content: string | undefined, option: FilterOption) => {
|
||||
@@ -455,23 +457,23 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
|
||||
};
|
||||
|
||||
const refresh = () => {
|
||||
const rootNode = b3util.createNode(editor.data);
|
||||
const rootNode = b3util.createNode(editor.root);
|
||||
editor.modifiedTime = fs.statSync(editor.path).mtimeMs;
|
||||
editor.data = createTreeData(rootNode);
|
||||
editor.autoId = b3util.refreshTreeDataId(editor.data, editor.firstid);
|
||||
editor.graph.changeData(editor.data);
|
||||
editor.root = createTreeData(rootNode);
|
||||
editor.autoId = b3util.refreshTreeDataId(editor.root, editor.data.firstid);
|
||||
editor.graph.changeData(editor.root);
|
||||
editor.graph.layout();
|
||||
restoreViewport();
|
||||
};
|
||||
|
||||
const reload = () => {
|
||||
const file = readJson(editor.path) as TreeModel;
|
||||
editor.data = createTreeData(file.root);
|
||||
editor.autoId = b3util.refreshTreeDataId(editor.data, editor.firstid);
|
||||
editor.root = createTreeData(file.root);
|
||||
editor.autoId = b3util.refreshTreeDataId(editor.root, editor.data.firstid);
|
||||
editor.unsave = false;
|
||||
updateState();
|
||||
if (editor.graph) {
|
||||
editor.graph.changeData(editor.data);
|
||||
editor.graph.changeData(editor.root);
|
||||
editor.graph.layout();
|
||||
restoreViewport();
|
||||
}
|
||||
@@ -479,7 +481,7 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
|
||||
|
||||
const checkSubtree = () => {
|
||||
if (editor.graph) {
|
||||
if (isSubtreeUpdated(editor.data)) {
|
||||
if (isSubtreeUpdated(editor.root)) {
|
||||
refresh();
|
||||
pushHistory();
|
||||
onChange();
|
||||
@@ -536,13 +538,17 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
|
||||
|
||||
const updateTree = (editTree: EditTree) => {
|
||||
if (isTreeUpdated(editor, editTree)) {
|
||||
editor.desc = editTree.data.desc || "";
|
||||
editor.export = editTree.data.export !== false;
|
||||
editor.group = editTree.data.group || [];
|
||||
editor.firstid = editTree.data.firstid ?? 1;
|
||||
editor.declare.vars = editTree.data.declare.vars || [];
|
||||
editor.declare.imports = editTree.data.declare.imports || [];
|
||||
b3util.updateUsingGroups(editor.group);
|
||||
editor.data.desc = editTree.data.desc || "";
|
||||
editor.data.export = editTree.data.export !== false;
|
||||
editor.data.group = editTree.data.group || [];
|
||||
editor.data.firstid = editTree.data.firstid ?? 1;
|
||||
editor.declvar = editTree.data.declvar || [];
|
||||
editor.import = editTree.data.import || [];
|
||||
editor.data.import = editor.import.map((v) => v.path).sort();
|
||||
editor.data.declvar = editor.declvar
|
||||
.map((v) => ({ ...v }))
|
||||
.sort((a, b) => a.name.localeCompare(b.name));
|
||||
b3util.updateUsingGroups(editor.data.group);
|
||||
b3util.updateUsingVars(collectVarDefs(editor));
|
||||
refresh();
|
||||
onChange();
|
||||
@@ -578,7 +584,7 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
|
||||
|
||||
const pushHistory = () => {
|
||||
editor.historyStack.length = ++editor.historyIndex;
|
||||
editor.historyStack.push(b3util.createNode(editor.data));
|
||||
editor.historyStack.push(b3util.createNode(editor.root));
|
||||
};
|
||||
|
||||
const copyNode = () => {
|
||||
@@ -649,9 +655,9 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
|
||||
refreshItem(parentData);
|
||||
updateGrahp();
|
||||
} else {
|
||||
editor.data = createTreeData(JSON.parse(str), editor.selectedId);
|
||||
editor.autoId = b3util.refreshTreeDataId(editor.data, editor.firstid);
|
||||
editor.graph.changeData(editor.data);
|
||||
editor.root = createTreeData(JSON.parse(str), editor.selectedId);
|
||||
editor.autoId = b3util.refreshTreeDataId(editor.root, editor.data.firstid);
|
||||
editor.graph.changeData(editor.root);
|
||||
editor.graph.render();
|
||||
editor.graph.layout();
|
||||
}
|
||||
@@ -723,9 +729,9 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
|
||||
};
|
||||
|
||||
const useStackData = (data: NodeModel) => {
|
||||
editor.data = createTreeData(data);
|
||||
editor.autoId = b3util.refreshTreeDataId(editor.data, editor.firstid);
|
||||
editor.graph.changeData(editor.data);
|
||||
editor.root = createTreeData(data);
|
||||
editor.autoId = b3util.refreshTreeDataId(editor.root, editor.data.firstid);
|
||||
editor.graph.changeData(editor.root);
|
||||
editor.graph.layout();
|
||||
restoreViewport();
|
||||
onChange();
|
||||
@@ -761,25 +767,13 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
|
||||
const save = () => {
|
||||
if (editor.unsave || !fs.existsSync(editor.path)) {
|
||||
const path = editor.path;
|
||||
editor.autoId = b3util.refreshTreeDataId(editor.data, editor.firstid);
|
||||
const root = b3util.createFileData(editor.data);
|
||||
const treeModel = {
|
||||
name: Path.basenameWithoutExt(path),
|
||||
desc: editor.desc,
|
||||
firstid: editor.firstid ?? 1,
|
||||
export: editor.export,
|
||||
group: editor.group ?? [],
|
||||
declare: {
|
||||
imports: editor.declare.imports.map((v) => v.path).sort(),
|
||||
vars: editor.declare.vars.sort((a, b) => a.name.localeCompare(b.name)),
|
||||
},
|
||||
root,
|
||||
} as TreeModel;
|
||||
editor.autoId = b3util.refreshTreeDataId(editor.root, editor.data.firstid);
|
||||
editor.data.root = b3util.createFileData(editor.root);
|
||||
editor.modifiedTime = Date.now();
|
||||
fs.writeFileSync(path, JSON.stringify(treeModel, null, 2));
|
||||
fs.writeFileSync(path, JSON.stringify(editor.data, null, 2));
|
||||
workspace.updateFileMeta(editor);
|
||||
editor.unsave = false;
|
||||
editor.graph.changeData(editor.data);
|
||||
editor.graph.changeData(editor.root);
|
||||
editor.graph.layout();
|
||||
restoreViewport();
|
||||
updateSearchState();
|
||||
@@ -924,7 +918,7 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
|
||||
const data = findDataById(e.item.getID());
|
||||
data.output?.forEach((v) => v && highlight.push(v));
|
||||
}
|
||||
const changed = findHightlight(editor.data, highlight);
|
||||
const changed = findHightlight(editor.root, highlight);
|
||||
if (changed.length > 0) {
|
||||
const refreshHighlight = (node: TreeGraphData) => {
|
||||
const item = editor.graph.findById(node.id);
|
||||
@@ -942,7 +936,7 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
|
||||
node.children.forEach(refreshHighlight);
|
||||
}
|
||||
};
|
||||
refreshHighlight(editor.data);
|
||||
refreshHighlight(editor.root);
|
||||
}
|
||||
if (highlight.length === 0 && editor.searchingText) {
|
||||
onSearchChange({
|
||||
@@ -1126,8 +1120,8 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
|
||||
onChange();
|
||||
});
|
||||
|
||||
refreshTreeData(editor.data);
|
||||
editor.graph.data(editor.data);
|
||||
refreshTreeData(editor.root);
|
||||
editor.graph.data(editor.root);
|
||||
editor.graph.render();
|
||||
if (editor.graphMatrix) {
|
||||
restoreViewport();
|
||||
@@ -1249,7 +1243,7 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
|
||||
useEffect(() => {
|
||||
if (workspace.editing === editor) {
|
||||
checkSubtree();
|
||||
b3util.updateUsingGroups(editor.group);
|
||||
b3util.updateUsingGroups(editor.data.group);
|
||||
b3util.updateUsingVars(collectVarDefs(editor));
|
||||
}
|
||||
}, [workspace.editing]);
|
||||
@@ -1257,7 +1251,7 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
|
||||
// check should repaint node
|
||||
useEffect(() => {
|
||||
if (editor.graph) {
|
||||
editor.graph.changeData(editor.data);
|
||||
editor.graph.changeData(editor.root);
|
||||
editor.graph.layout();
|
||||
restoreViewport();
|
||||
}
|
||||
|
||||
@@ -94,16 +94,16 @@ const TreeInspector: FC = () => {
|
||||
// set form values
|
||||
useEffect(() => {
|
||||
const data = workspace.editingTree.data;
|
||||
loadVarDef(data.declare.imports);
|
||||
loadVarDef(data.import);
|
||||
form.resetFields();
|
||||
form.setFieldValue("name", data.name);
|
||||
form.setFieldValue("desc", data.desc);
|
||||
form.setFieldValue("export", data.export !== false);
|
||||
form.setFieldValue("firstid", data.firstid);
|
||||
form.setFieldValue("group", groupDefs);
|
||||
form.setFieldValue("declare.vars", data.declare?.vars);
|
||||
form.setFieldValue("declare.imports", data.declare?.imports);
|
||||
form.setFieldValue("declare.subtree", data.declare?.subtree);
|
||||
form.setFieldValue("declvar", data.declvar);
|
||||
form.setFieldValue("import", data.import);
|
||||
form.setFieldValue("subtree", data.subtree);
|
||||
}, [workspace.editingTree, groupDefs]);
|
||||
|
||||
const finish = (values: any) => {
|
||||
@@ -117,11 +117,10 @@ const TreeInspector: FC = () => {
|
||||
.map((v) => (v.value ? v.name : undefined))
|
||||
.filter((v) => v)
|
||||
.sort(),
|
||||
declare: {
|
||||
vars: (values["declare.vars"] as VarDef[])
|
||||
declvar: (values["declvar"] as VarDef[])
|
||||
.filter((v) => v && v.name)
|
||||
.sort((a, b) => a.name.localeCompare(b.name)),
|
||||
imports: (values["declare.imports"] as ImportDef[])
|
||||
import: (values["import"] as ImportDef[])
|
||||
.filter((v) => v && v.path)
|
||||
.sort((a, b) => a.path.localeCompare(b.path))
|
||||
.map((v) => ({
|
||||
@@ -129,7 +128,6 @@ const TreeInspector: FC = () => {
|
||||
vars: v.vars ?? [],
|
||||
})),
|
||||
},
|
||||
},
|
||||
} as EditTree);
|
||||
};
|
||||
|
||||
@@ -200,7 +198,7 @@ const TreeInspector: FC = () => {
|
||||
<Divider orientation="left">
|
||||
<h4>{t("tree.vars")}</h4>
|
||||
</Divider>
|
||||
<Form.List name="declare.vars">
|
||||
<Form.List name="declvar">
|
||||
{(items, { add, remove }, { errors }) => (
|
||||
<div style={{ display: "flex", flexDirection: "column", rowGap: 0 }}>
|
||||
{items.map((item) => (
|
||||
@@ -285,12 +283,12 @@ const TreeInspector: FC = () => {
|
||||
)}
|
||||
</Form.List>
|
||||
</>
|
||||
{workspace.editingTree.data.declare.subtree.length > 0 && (
|
||||
{workspace.editingTree.data.subtree.length > 0 && (
|
||||
<>
|
||||
<Divider orientation="left">
|
||||
<h4>{t("tree.vars.subtree")}</h4>
|
||||
</Divider>
|
||||
<Form.List name="declare.subtree">
|
||||
<Form.List name="subtree">
|
||||
{(vars) => (
|
||||
<div style={{ display: "flex", flexDirection: "column", rowGap: 0 }}>
|
||||
{vars.map((v, idx, arr) => (
|
||||
@@ -354,7 +352,7 @@ const TreeInspector: FC = () => {
|
||||
<Divider orientation="left">
|
||||
<h4>{t("tree.vars.imports")}</h4>
|
||||
</Divider>
|
||||
<Form.List name="declare.imports">
|
||||
<Form.List name="import">
|
||||
{(items, { add, remove }, { errors }) => (
|
||||
<div style={{ display: "flex", flexDirection: "column", rowGap: 4 }}>
|
||||
{items.map((item) => (
|
||||
@@ -610,7 +608,7 @@ const NodeInspector: FC = () => {
|
||||
}
|
||||
});
|
||||
} else {
|
||||
collect(workspace.editing?.data);
|
||||
collect(workspace.editing?.root);
|
||||
}
|
||||
return options;
|
||||
}, [workspace.editing, usingVars]);
|
||||
|
||||
@@ -12,7 +12,7 @@ import { message } from "../misc/hooks";
|
||||
import i18n from "../misc/i18n";
|
||||
import Path from "../misc/path";
|
||||
import { zhNodeDef } from "../misc/template";
|
||||
import { readJson, writeJson } from "../misc/util";
|
||||
import { readJson, readTree, writeJson } from "../misc/util";
|
||||
import { useSetting } from "./setting-context";
|
||||
|
||||
let buildDir: string | undefined;
|
||||
@@ -44,17 +44,11 @@ export type EditEvent =
|
||||
|
||||
export class EditorStore {
|
||||
path: string;
|
||||
data: TreeGraphData;
|
||||
desc: string;
|
||||
export: boolean;
|
||||
name: string;
|
||||
firstid: number;
|
||||
group: string[];
|
||||
data: TreeModel;
|
||||
|
||||
declare: {
|
||||
imports: ImportDef[];
|
||||
vars: VarDef[];
|
||||
};
|
||||
root: TreeGraphData;
|
||||
import: ImportDef[];
|
||||
declvar: VarDef[];
|
||||
|
||||
autoId: number = 1;
|
||||
dragSrcId?: string;
|
||||
@@ -78,25 +72,18 @@ export class EditorStore {
|
||||
|
||||
constructor(path: string) {
|
||||
this.path = path;
|
||||
|
||||
const file = readJson(path) as TreeModel;
|
||||
this.data = b3util.createTreeData(file.root);
|
||||
this.data = readTree(path);
|
||||
this.data.name = Path.basenameWithoutExt(path);
|
||||
this.data.firstid = this.data.firstid ?? 1;
|
||||
this.data.group = this.data.group ?? [];
|
||||
this.data.import = this.data.import ?? [];
|
||||
this.data.declvar = this.data.declvar ?? [];
|
||||
this.root = b3util.createTreeData(this.data.root);
|
||||
this.modifiedTime = fs.statSync(path).mtimeMs;
|
||||
this.desc = file.desc ?? "";
|
||||
this.export = file.export !== false;
|
||||
this.name = file.name || path.slice(0, -5);
|
||||
this.firstid = file.firstid ?? 1;
|
||||
this.group = file.group ?? [];
|
||||
this.declare = {
|
||||
vars: file.declare?.vars ?? [],
|
||||
imports:
|
||||
file.declare?.imports?.map((v) => ({
|
||||
path: v,
|
||||
vars: [],
|
||||
})) ?? [],
|
||||
};
|
||||
this.autoId = b3util.refreshTreeDataId(this.data, this.firstid);
|
||||
this.historyStack.push(b3util.createNode(this.data));
|
||||
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.historyIndex = 0;
|
||||
}
|
||||
}
|
||||
@@ -129,12 +116,10 @@ export type EditTree = {
|
||||
export?: boolean;
|
||||
firstid?: number;
|
||||
group: string[];
|
||||
declare: {
|
||||
imports: ImportDef[];
|
||||
vars: VarDef[];
|
||||
import: ImportDef[];
|
||||
declvar: VarDef[];
|
||||
subtree: VarDef[];
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
export type FileMeta = {
|
||||
@@ -459,8 +444,8 @@ export const useWorkspace = create<WorkspaceStore>((set, get) => ({
|
||||
const workspace = get();
|
||||
const path = workspace.relative(editor.path);
|
||||
const file = workspace.allFiles.get(path);
|
||||
if (file && file.desc !== editor.desc) {
|
||||
file.desc = editor.desc;
|
||||
if (file && file.desc !== editor.data.desc) {
|
||||
file.desc = editor.data.desc;
|
||||
set({ allFiles: new Map(workspace.allFiles) });
|
||||
workspace.saveWorkspace();
|
||||
}
|
||||
@@ -518,21 +503,7 @@ export const useWorkspace = create<WorkspaceStore>((set, get) => ({
|
||||
let editting = workspace.editing;
|
||||
if (editors.length && path === editting?.path) {
|
||||
editting = editors[idx === editors.length ? idx - 1 : idx];
|
||||
set({
|
||||
editingTree: {
|
||||
data: {
|
||||
name: editting.name,
|
||||
desc: editting.desc,
|
||||
firstid: editting.firstid,
|
||||
group: editting.group,
|
||||
declare: {
|
||||
vars: editting.declare.vars,
|
||||
imports: editting.declare.imports,
|
||||
subtree: loadSubtreeVarDef(editting.data),
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
workspace.onEditingTree(editting);
|
||||
}
|
||||
if (editors.length === 0) {
|
||||
editting = undefined;
|
||||
@@ -681,16 +652,10 @@ export const useWorkspace = create<WorkspaceStore>((set, get) => ({
|
||||
set({
|
||||
editingTree: {
|
||||
data: {
|
||||
name: editor.name,
|
||||
desc: editor.desc,
|
||||
export: editor.export,
|
||||
firstid: editor.firstid,
|
||||
group: editor.group,
|
||||
declare: {
|
||||
imports: editor.declare.imports,
|
||||
vars: editor.declare.vars,
|
||||
subtree: loadSubtreeVarDef(editor.data),
|
||||
},
|
||||
...editor.data,
|
||||
import: editor.import,
|
||||
declvar: editor.declvar,
|
||||
subtree: loadSubtreeVarDef(editor.root),
|
||||
},
|
||||
},
|
||||
editingNodeDef: null,
|
||||
|
||||
+4
-6
@@ -51,12 +51,10 @@ export interface TreeModel {
|
||||
name: string;
|
||||
desc?: string;
|
||||
export?: boolean;
|
||||
firstid?: number;
|
||||
group?: string[];
|
||||
declare?: {
|
||||
imports?: string[];
|
||||
vars?: VarDef[];
|
||||
};
|
||||
firstid: number;
|
||||
group: string[];
|
||||
import: string[];
|
||||
declvar: VarDef[];
|
||||
root: NodeModel;
|
||||
}
|
||||
|
||||
|
||||
+6
-2
@@ -700,6 +700,10 @@ export const createFileData = (data: TreeGraphData, includeSubtree?: boolean) =>
|
||||
export const createNewTree = (path: string) => {
|
||||
const tree: TreeModel = {
|
||||
name: Path.basenameWithoutExt(path),
|
||||
firstid: 1,
|
||||
group: [],
|
||||
import: [],
|
||||
declvar: [],
|
||||
root: {
|
||||
id: 1,
|
||||
name: "Sequence",
|
||||
@@ -729,8 +733,8 @@ export const loadVarDef = (list: ImportDef[]) => {
|
||||
filter.set(path, true);
|
||||
try {
|
||||
const model: TreeModel = readTree(`${workdir}/${path}`);
|
||||
model.declare?.vars?.forEach((v) => vars.push(v));
|
||||
model.declare?.imports?.forEach((v) => load(v));
|
||||
model.declvar.forEach((v) => vars.push(v));
|
||||
model.import.forEach((v) => load(v));
|
||||
} catch (e) {
|
||||
alertError(`parsing error: ${path}`);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user