fix(脑图): 脑图复制/粘贴去除空节点

This commit is contained in:
baiqi 2024-07-09 13:59:40 +08:00 committed by 刘瑞斌
parent 2de9d0534d
commit 026b8a9786
3 changed files with 24 additions and 10 deletions

View File

@ -388,14 +388,23 @@
window.minder.execCommand('Paste'); window.minder.execCommand('Paste');
let pastedNodes: MinderJsonNode[] = window.minder.getSelectedNodes(); let pastedNodes: MinderJsonNode[] = window.minder.getSelectedNodes();
if (pastedNodes.length > 0) { if (pastedNodes.length > 0) {
pastedNodes = pastedNodes.map((e) => { pastedNodes = pastedNodes
e.data = { .filter((e) => {
...(e.data as MinderJsonNodeData), if (e.data?.id !== 'fakeNode' && e.data?.type !== 'tmp') {
isNew: true, return true;
id: getGenerateId(), }
}; window.minder.removeNode(e);
return e; return false;
}); })
.map((e) => {
e.data = {
...(e.data as MinderJsonNodeData),
isNew: true,
id: getGenerateId(),
count: e.children?.length || 0,
};
return e;
});
} }
break; break;
case 'delete': case 'delete':

View File

@ -62,7 +62,12 @@ const useMinderStore = defineStore('minder', {
this.mold = val; this.mold = val;
}, },
setClipboard(nodes?: MinderJsonNode[]) { setClipboard(nodes?: MinderJsonNode[]) {
this.clipboard = mapTree(nodes || [], (node) => ({ ...node, id: getGenerateId(), type: 'ADD' })); this.clipboard = mapTree(nodes || [], (node) => {
if (node.id !== 'fakeNode' && node.type !== 'tmp') {
return { ...node, id: getGenerateId(), type: 'ADD' };
}
return null;
});
}, },
setMinderUnsaved(val: boolean) { setMinderUnsaved(val: boolean) {
this.minderUnsaved = val; this.minderUnsaved = val;

View File

@ -268,7 +268,7 @@ export function mapTree<T>(
} }
return newNode; return newNode;
}) })
.filter(Boolean); .filter((node: TreeNode<T> | null) => node !== null);
} }
return mapFunc(cloneTree, parentPath, level, parent); return mapFunc(cloneTree, parentPath, level, parent);
} }