fix(脑图): 脑图复制/粘贴去除空节点
This commit is contained in:
parent
2de9d0534d
commit
026b8a9786
|
@ -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':
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue