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