From 5745e4567ba0e6273f3079b30b05f49e2b13b94f Mon Sep 17 00:00:00 2001 From: wanglin2 <1013335014@qq.com> Date: Sat, 12 Aug 2023 10:57:51 +0800 Subject: [PATCH] =?UTF-8?q?Feat:=E4=BF=AE=E6=94=B9=E5=A4=8D=E5=88=B6?= =?UTF-8?q?=E7=B2=98=E8=B4=B4=E5=AE=9E=E7=8E=B0=E6=96=B9=E5=BC=8F,?= =?UTF-8?q?=E5=8E=BB=E9=99=A4=E5=88=9B=E5=BB=BA=E9=9A=90=E8=97=8F=E8=BE=93?= =?UTF-8?q?=E5=85=A5=E6=A1=86,=E6=94=AF=E6=8C=81=E8=B7=A8=E6=B5=8F?= =?UTF-8?q?=E8=A7=88=E5=99=A8=E7=B2=98=E8=B4=B4=E6=80=9D=E7=BB=B4=E5=AF=BC?= =?UTF-8?q?=E5=9B=BE=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- simple-mind-map/package-lock.json | 4 +- simple-mind-map/src/core/render/Render.js | 58 ++++++++++++++++++++--- 2 files changed, 53 insertions(+), 9 deletions(-) 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) {