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

View File

@ -62,7 +62,12 @@ const useMinderStore = defineStore('minder', {
this.mold = val;
},
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) {
this.minderUnsaved = val;

View File

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