support delete node in batch

This commit is contained in:
codetypes committed 2024-07-16 18:00:16 +08:00
1 parent 5c57212a90
commit 028ffb8961
3 files changed
+22 -13

No files matched your search

+7 -7
View File
@@ -48,7 +48,7 @@
"react": "^18.2.0",
"react-dom": "^18.2.0",
"sass": "^1.60.0",
"typescript": "^5.4.5",
"typescript": "^5.5.3",
"vite": "^4.1.4",
"vite-electron-plugin": "^0.8.3",
"vite-plugin-electron": "^0.28.4",
@@ -9148,9 +9148,9 @@
}
},
"node_modules/typescript": {
"version": "5.4.5",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-5.4.5.tgz",
"integrity": "sha512-vcI4UpRgg81oIRUFwR0WSIHKt11nJ7SAVlYNIu+QpqeyXP+gpQJy/Z4+F0aGxSE4MqwjyXvW/TzgkLAx2AGHwQ==",
"version": "5.5.3",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-5.5.3.tgz",
"integrity": "sha512-/hreyEujaB0w76zKo6717l3L0o/qEUtRgdvUBvlkhoWeOVMjMuHNHk0BRBzikzuGDqNmPQbg5ifMEqsHLiIUcQ==",
"dev": true,
"bin": {
"tsc": "bin/tsc",
@@ -16415,9 +16415,9 @@
}
},
"typescript": {
"version": "5.4.5",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-5.4.5.tgz",
"integrity": "sha512-vcI4UpRgg81oIRUFwR0WSIHKt11nJ7SAVlYNIu+QpqeyXP+gpQJy/Z4+F0aGxSE4MqwjyXvW/TzgkLAx2AGHwQ==",
"version": "5.5.3",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-5.5.3.tgz",
"integrity": "sha512-/hreyEujaB0w76zKo6717l3L0o/qEUtRgdvUBvlkhoWeOVMjMuHNHk0BRBzikzuGDqNmPQbg5ifMEqsHLiIUcQ==",
"dev": true
},
"undici-types": {
+1 -1
View File
@@ -40,7 +40,7 @@
"react": "^18.2.0",
"react-dom": "^18.2.0",
"sass": "^1.60.0",
"typescript": "^5.4.5",
"typescript": "^5.5.3",
"vite": "^4.1.4",
"vite-electron-plugin": "^0.8.3",
"vite-plugin-electron": "^0.28.4",
+14 -5
View File
@@ -16,7 +16,7 @@ import { Editor } from "../components/editor";
let buildDir: string | undefined;
interface BatchScript {
processTree?(tree: TreeModel): TreeModel;
processTree?(tree: TreeModel, path: string): TreeModel;
processNode?(node: NodeModel, tree: TreeModel): NodeModel;
}
@@ -319,14 +319,23 @@ export const useWorkspace = create<WorkspaceStore>((set, get) => ({
const treeStr = fs.readFileSync(file.path, "utf8");
let tree: TreeModel | undefined = JSON.parse(treeStr);
if (batch.processTree && tree) {
tree = batch.processTree(tree);
tree = batch.processTree(tree, file.path);
}
if (tree && batch.processNode) {
const processNode = (node: NodeModel) => {
batch.processNode?.(node, tree!);
node.children?.forEach((child) => processNode(child));
if (node.children) {
const children: NodeModel[] = [];
node.children?.forEach((child) => {
const newChild = processNode(child);
if (newChild) {
children.push(newChild);
}
});
node.children = children;
}
return batch.processNode?.(node, tree!);
};
processNode(tree.root);
tree.root = processNode(tree.root) ?? ({} as NodeModel);
}
if (tree) {
fs.writeFileSync(file.path, JSON.stringify(tree, null, 2));