From 29bb27aa2332092dad074a5dbe09fbb02ce856d7 Mon Sep 17 00:00:00 2001 From: wanglin2 <1013335014@qq.com> Date: Fri, 1 Sep 2023 10:41:36 +0800 Subject: [PATCH] =?UTF-8?q?Feat=EF=BC=9A=E4=BC=98=E5=8C=96=E9=BC=A0?= =?UTF-8?q?=E6=A0=87=E6=8C=89=E4=B8=8B=E8=8A=82=E7=82=B9=E4=BA=8B=E4=BB=B6?= =?UTF-8?q?=E9=80=BB=E8=BE=91=EF=BC=8C=E5=9C=A8=E5=8F=B3=E9=94=AE=E6=8B=96?= =?UTF-8?q?=E6=8B=BD=E7=94=BB=E5=B8=83=E6=A8=A1=E5=BC=8F=E4=B8=8B=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E5=8F=B3=E9=94=AE=E6=8C=89=E4=BD=8F=E6=A0=B9=E8=8A=82?= =?UTF-8?q?=E7=82=B9=E6=8B=96=E6=8B=BD=E7=94=BB=E5=B8=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/constants/defaultOptions.js | 6 +++++- simple-mind-map/src/core/render/node/Node.js | 21 +++++++++++++------ 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/simple-mind-map/src/constants/defaultOptions.js b/simple-mind-map/src/constants/defaultOptions.js index 1f1b5709..1945944b 100644 --- a/simple-mind-map/src/constants/defaultOptions.js +++ b/simple-mind-map/src/constants/defaultOptions.js @@ -182,5 +182,9 @@ export const defaultOpt = { // 节点鼠标hover和激活时显示的矩形边框距节点内容的距离 hoverRectPadding: 2, // 双击节点进入节点文本编辑时是否默认选中文本,默认只在创建新节点时会选中 - selectTextOnEnterEditText: false + selectTextOnEnterEditText: false, + // 拖拽模式 + // default:按住画布、根节点都可拖拽画布 + // noCanvas:按住根节点和 + dragMode: '' } diff --git a/simple-mind-map/src/core/render/node/Node.js b/simple-mind-map/src/core/render/node/Node.js index 2bc4408c..9bca88b9 100644 --- a/simple-mind-map/src/core/render/node/Node.js +++ b/simple-mind-map/src/core/render/node/Node.js @@ -394,14 +394,23 @@ class Node { this.active(e) }) this.group.on('mousedown', e => { - if (this.isRoot && e.which === 3 && !this.mindMap.opt.readonly) { - e.stopPropagation() - } - if (!this.isRoot && e.which !== 2 && !this.mindMap.opt.readonly) { - e.stopPropagation() + const { readonly, enableCtrlKeyNodeSelection, useLeftKeySelectionRightKeyDrag } = this.mindMap.opt + // 只读模式不需要阻止冒泡 + if (!readonly) { + if (this.isRoot) { + // 根节点,右键拖拽画布模式下不需要阻止冒泡 + if (e.which === 3 && !useLeftKeySelectionRightKeyDrag) { + e.stopPropagation() + } + } else { + // 非根节点,且按下的是非鼠标中键,需要阻止事件冒泡 + if (e.which !== 2) { + e.stopPropagation() + } + } } // 多选和取消多选 - if (e.ctrlKey && this.mindMap.opt.enableCtrlKeyNodeSelection) { + if (e.ctrlKey && enableCtrlKeyNodeSelection) { this.isMultipleChoice = true let isActive = this.nodeData.data.isActive if (!isActive)