From 82c2d848a9f27aac9cbab180c5f6441fc99cb790 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=A1=97=E8=A7=92=E5=B0=8F=E6=9E=97?= <1013335014@qq.com> Date: Wed, 25 Sep 2024 10:31:39 +0800 Subject: [PATCH] =?UTF-8?q?Feat=EF=BC=9A=E5=A2=9E=E5=8A=A0=E6=98=AF?= =?UTF-8?q?=E5=90=A6=E9=98=BB=E6=AD=A2mousedown=E4=BA=8B=E4=BB=B6=E9=BB=98?= =?UTF-8?q?=E8=AE=A4=E4=BA=8B=E4=BB=B6=E7=9A=84=E5=AE=9E=E4=BE=8B=E5=8C=96?= =?UTF-8?q?=E9=80=89=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- simple-mind-map/src/constants/defaultOptions.js | 2 ++ simple-mind-map/src/core/view/View.js | 7 +++++-- simple-mind-map/src/plugins/Select.js | 7 +++++-- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/simple-mind-map/src/constants/defaultOptions.js b/simple-mind-map/src/constants/defaultOptions.js index 5f09a779..a830cdfb 100644 --- a/simple-mind-map/src/constants/defaultOptions.js +++ b/simple-mind-map/src/constants/defaultOptions.js @@ -245,6 +245,8 @@ export const defaultOpt = { emptyTextMeasureHeightText: 'abc123我和你', // 是否在进行节点文本编辑时实时更新节点大小和节点位置,开启后当节点数量比较多时可能会造成卡顿 openRealtimeRenderOnNodeTextEdit: false, + // 默认会给容器元素el绑定mousedown事件,并且会阻止其默认事件,这会带来一定问题,比如你聚焦在思维导图外的其他输入框,点击画布就不会触发其失焦,可以通过该选项关闭阻止。关闭后也会带来一定问题,比如鼠标框选节点时可能会选中节点文字,看你如何取舍 + mousedownEventPreventDefault: true, // 【Select插件】 // 多选节点时鼠标移动到边缘时的画布移动偏移量 diff --git a/simple-mind-map/src/core/view/View.js b/simple-mind-map/src/core/view/View.js index 94980e59..3c6ef130 100644 --- a/simple-mind-map/src/core/view/View.js +++ b/simple-mind-map/src/core/view/View.js @@ -30,8 +30,11 @@ class View { }) // 拖动视图 this.mindMap.event.on('mousedown', e => { - if (this.mindMap.opt.isDisableDrag) return - e.preventDefault() + const { isDisableDrag, mousedownEventPreventDefault } = this.mindMap.opt + if (isDisableDrag) return + if (mousedownEventPreventDefault) { + e.preventDefault() + } this.sx = this.x this.sy = this.y }) diff --git a/simple-mind-map/src/plugins/Select.js b/simple-mind-map/src/plugins/Select.js index d80865f6..eaf93f9b 100644 --- a/simple-mind-map/src/plugins/Select.js +++ b/simple-mind-map/src/plugins/Select.js @@ -41,7 +41,8 @@ class Select { // 鼠标按下 onMousedown(e) { - if (this.mindMap.opt.readonly) { + const { readonly, mousedownEventPreventDefault } = this.mindMap.opt + if (readonly) { return } let { useLeftKeySelectionRightKeyDrag } = this.mindMap.opt @@ -51,7 +52,9 @@ class Select { ) { return } - e.preventDefault() + if (mousedownEventPreventDefault) { + e.preventDefault() + } this.isMousedown = true this.cacheActiveList = [...this.mindMap.renderer.activeNodeList] let { x, y } = this.mindMap.toPos(e.clientX, e.clientY)