fix(脑图): 脑图复制/粘贴去除空节点
This commit is contained in:
parent
2de9d0534d
commit
026b8a9786
|
@ -388,11 +388,20 @@
|
||||||
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
|
||||||
|
.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 = {
|
||||||
...(e.data as MinderJsonNodeData),
|
...(e.data as MinderJsonNodeData),
|
||||||
isNew: true,
|
isNew: true,
|
||||||
id: getGenerateId(),
|
id: getGenerateId(),
|
||||||
|
count: e.children?.length || 0,
|
||||||
};
|
};
|
||||||
return e;
|
return e;
|
||||||
});
|
});
|
||||||
|
|
|
@ -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;
|
||||||
|
|
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue