From ef9d8b0ea47f5ed552f182ebedb68b081c763d98 Mon Sep 17 00:00:00 2001 From: wanglin2 <1013335014@qq.com> Date: Fri, 4 Aug 2023 09:11:02 +0800 Subject: [PATCH] =?UTF-8?q?Fix=EF=BC=9A=E4=BF=AE=E5=A4=8D=E7=A7=BB?= =?UTF-8?q?=E5=8A=A8=E8=8A=82=E7=82=B9=E6=97=B6=E6=96=B0=E4=BD=8D=E7=BD=AE?= =?UTF-8?q?=E7=9A=84=E6=8F=90=E7=A4=BA=E5=9D=97=E8=BF=87=E5=A4=A7=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= 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/constants/defaultOptions.js | 4 +++- simple-mind-map/src/plugins/Drag.js | 14 ++++++++------ 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/simple-mind-map/package-lock.json b/simple-mind-map/package-lock.json index 29f719ea..160c304d 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.7", + "version": "0.6.11-fix.1", "lockfileVersion": 2, "requires": true, "packages": { "": { - "version": "0.6.7", + "version": "0.6.11-fix.1", "license": "MIT", "dependencies": { "@svgdotjs/svg.js": "^3.0.16", diff --git a/simple-mind-map/src/constants/defaultOptions.js b/simple-mind-map/src/constants/defaultOptions.js index babb77d5..2c72933e 100644 --- a/simple-mind-map/src/constants/defaultOptions.js +++ b/simple-mind-map/src/constants/defaultOptions.js @@ -124,5 +124,7 @@ export const defaultOpt = { // 自定义返回节点内容的方法 customCreateNodeContent: null, // 指定内部一些元素(节点文本编辑元素、节点备注显示元素、关联线文本编辑元素、节点图片调整按钮元素)添加到的位置,默认添加到document.body下 - customInnerElsAppendTo: null + customInnerElsAppendTo: null, + // 拖拽元素时,指示元素新位置的块的最大高度 + nodeDragPlaceholderMaxSize: 20 } diff --git a/simple-mind-map/src/plugins/Drag.js b/simple-mind-map/src/plugins/Drag.js index 1e54dd84..28a8b354 100644 --- a/simple-mind-map/src/plugins/Drag.js +++ b/simple-mind-map/src/plugins/Drag.js @@ -44,6 +44,7 @@ class Drag extends Base { this.mouseMoveY = 0 // 鼠标移动的距离距鼠标按下的位置距离多少以上才认为是拖动事件 this.checkDragOffset = 10 + this.minOffset = 10 } // 绑定事件 @@ -206,6 +207,7 @@ class Drag extends Base { if (!this.drawTransform) { return } + const { nodeDragPlaceholderMaxSize } = this.mindMap.opt let x = this.mouseMoveX let y = this.mouseMoveY this.overlapNode = null @@ -247,19 +249,19 @@ class Drag extends Base { let prevNodeRect = this.getNodeRect(prevBrother) prevBrotherOffset = nodeRect.top - prevNodeRect.bottom // 间距小于10就当它不存在 - prevBrotherOffset = prevBrotherOffset >= 10 ? prevBrotherOffset / 2 : 0 + prevBrotherOffset = prevBrotherOffset >= this.minOffset ? prevBrotherOffset / 2 : 0 } else { // 没有前一个兄弟节点,那么假设和前一个节点的距离为20 - prevBrotherOffset = 10 + prevBrotherOffset = this.minOffset } // 和后一个兄弟节点的距离 let nextBrotherOffset = 0 if (nextBrother) { let nextNodeRect = this.getNodeRect(nextBrother) nextBrotherOffset = nextNodeRect.top - nodeRect.bottom - nextBrotherOffset = nextBrotherOffset >= 10 ? nextBrotherOffset / 2 : 0 + nextBrotherOffset = nextBrotherOffset >= this.minOffset ? nextBrotherOffset / 2 : 0 } else { - nextBrotherOffset = 10 + nextBrotherOffset = this.minOffset } if (nodeRect.left <= x && nodeRect.right >= x) { // 检测兄弟节点位置 @@ -272,11 +274,11 @@ class Drag extends Base { y >= nodeRect.top && y <= nodeRect.top + oneFourthHeight if (checkIsPrevNode) { this.prevNode = node - let size = nextBrotherOffset > 0 ? nextBrotherOffset : 5 + let size = nextBrotherOffset > 0 ? Math.min(nextBrotherOffset, nodeDragPlaceholderMaxSize) : 5 this.placeholder.size(node.width, size).move(nodeRect.originLeft, nodeRect.originBottom) } else if (checkIsNextNode) { this.nextNode = node - let size = prevBrotherOffset > 0 ? prevBrotherOffset : 5 + let size = prevBrotherOffset > 0 ? Math.min(prevBrotherOffset, nodeDragPlaceholderMaxSize) : 5 this.placeholder.size(node.width, size).move(nodeRect.originLeft, nodeRect.originTop - size) } }