diff --git a/simple-mind-map/package-lock.json b/simple-mind-map/package-lock.json index ee730af9..a3858abc 100644 --- a/simple-mind-map/package-lock.json +++ b/simple-mind-map/package-lock.json @@ -1,11 +1,11 @@ { "name": "simple-mind-map", - "version": "0.6.12", + "version": "0.6.13", "lockfileVersion": 2, "requires": true, "packages": { "": { - "version": "0.6.12", + "version": "0.6.13", "license": "MIT", "dependencies": { "@svgdotjs/svg.js": "^3.0.16", diff --git a/simple-mind-map/src/core/render/Render.js b/simple-mind-map/src/core/render/Render.js index b5294043..752ac75a 100644 --- a/simple-mind-map/src/core/render/Render.js +++ b/simple-mind-map/src/core/render/Render.js @@ -444,7 +444,12 @@ class Render { } // 插入同级节点,多个节点只会操作第一个节点 - insertNode(openEdit = true, appointNodes = [], appointData = null) { + insertNode( + openEdit = true, + appointNodes = [], + appointData = null, + appointChildren = [] + ) { appointNodes = this.formatAppointNodes(appointNodes) if (this.activeNodeList.length <= 0 && appointNodes.length <= 0) { return @@ -480,14 +485,19 @@ class Render { resetRichText: isRichText, ...(appointData || {}) }, - children: [] + children: [...appointChildren] }) this.mindMap.render() } } // 插入子节点 - insertChildNode(openEdit = true, appointNodes = [], appointData = null) { + insertChildNode( + openEdit = true, + appointNodes = [], + appointData = null, + appointChildren = [] + ) { appointNodes = this.formatAppointNodes(appointNodes) if (this.activeNodeList.length <= 0 && appointNodes.length <= 0) { return @@ -518,7 +528,7 @@ class Render { resetRichText: isRichText, ...(appointData || {}) }, - children: [] + children: [...appointChildren] }) // 插入子节点时自动展开子节点 node.nodeData.data.expand = true @@ -586,15 +596,29 @@ class Render { // 复制节点 copy() { this.beingCopyData = this.copyNode() + this.setCoptyDataToClipboard(this.beingCopyData) } // 剪切节点 cut() { this.mindMap.execCommand('CUT_NODE', copyData => { this.beingCopyData = copyData + this.setCoptyDataToClipboard(copyData) }) } + // 将粘贴或剪切的数据设置到用户剪切板中 + setCoptyDataToClipboard(data) { + if (navigator.clipboard) { + navigator.clipboard.writeText( + JSON.stringify({ + simpleMindMap: true, + data + }) + ) + } + } + // 粘贴节点 paste() { if (this.beingCopyData) { @@ -642,9 +666,29 @@ class Render { if (this.currentBeingPasteType === CONSTANTS.PASTE_TYPE.CLIP_BOARD) { // 存在文本,则创建子节点 if (text) { - this.mindMap.execCommand('INSERT_CHILD_NODE', false, [], { - text - }) + // 判断粘贴的是否是simple-mind-map的数据 + let smmData = null + try { + const parsedData = JSON.parse(text) + if (parsedData && parsedData.simpleMindMap) { + smmData = parsedData.data + } + } catch (error) {} + if (smmData) { + this.mindMap.execCommand( + 'INSERT_CHILD_NODE', + false, + [], + { + ...smmData.data + }, + [...smmData.children] + ) + } else { + this.mindMap.execCommand('INSERT_CHILD_NODE', false, [], { + text + }) + } } // 存在图片,则添加到当前激活节点 if (img) {