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