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