From 388594e29afc51857726a2357a363b65895ac493 Mon Sep 17 00:00:00 2001 From: wanglin2 <1013335014@qq.com> Date: Wed, 5 Apr 2023 08:45:23 +0800 Subject: [PATCH] =?UTF-8?q?Fix:=E4=BF=AE=E5=A4=8D=E5=BF=AB=E9=80=9F?= =?UTF-8?q?=E6=93=8D=E4=BD=9C=E6=97=B6=E8=8A=82=E7=82=B9=E4=BD=8D=E7=BD=AE?= =?UTF-8?q?=E4=B8=8D=E6=AD=A3=E7=A1=AE=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- simple-mind-map/index.js | 8 +++++++- simple-mind-map/src/KeyCommand.js | 2 +- simple-mind-map/src/Node.js | 18 ++++++++++++++---- simple-mind-map/src/layouts/Base.js | 2 +- 4 files changed, 23 insertions(+), 7 deletions(-) diff --git a/simple-mind-map/index.js b/simple-mind-map/index.js index 022c7f68..c97dac8f 100644 --- a/simple-mind-map/index.js +++ b/simple-mind-map/index.js @@ -82,7 +82,13 @@ const defaultOpt = { expandBtnIcon: { open: '',// svg字符串 close: '' - } + }, + // 是否只有当鼠标在画布内才响应快捷键事件 + enableShortcutOnlyWhenMouseInSvg: true, + // 是否开启节点动画过渡 + enableNodeTransitionMove: true, + // 如果开启节点动画过渡,可以通过该属性设置过渡的时间,单位ms + nodeTransitionMoveDuration: 300 } // 思维导图 diff --git a/simple-mind-map/src/KeyCommand.js b/simple-mind-map/src/KeyCommand.js index 5405ee02..9130e73e 100644 --- a/simple-mind-map/src/KeyCommand.js +++ b/simple-mind-map/src/KeyCommand.js @@ -52,7 +52,7 @@ export default class KeyCommand { this.isInSvg = false }) window.addEventListener('keydown', e => { - if (this.isPause || !this.isInSvg) { + if (this.isPause || (this.mindMap.opt.enableShortcutOnlyWhenMouseInSvg && !this.isInSvg)) { return } Object.keys(this.shortcutMap).forEach(key => { diff --git a/simple-mind-map/src/Node.js b/simple-mind-map/src/Node.js index 287fe21b..fa208f11 100644 --- a/simple-mind-map/src/Node.js +++ b/simple-mind-map/src/Node.js @@ -414,6 +414,7 @@ class Node { if (!this.group) { return } + let { enableNodeTransitionMove, nodeTransitionMoveDuration } = this.mindMap.opt // 需要移除展开收缩按钮 if (this._expandBtn && this.nodeData.children.length <= 0) { this.removeExpandBtn() @@ -425,9 +426,9 @@ class Node { this.renderGeneralization() // 更新节点位置 let t = this.group.transform() - if (!isLayout) { + if (!isLayout && enableNodeTransitionMove) { this.group - .animate(300) + .animate(nodeTransitionMoveDuration) .translate( this.left - t.translateX, this.top - t.translateY @@ -457,10 +458,13 @@ class Node { // 递归渲染 render(callback = () => {}) { + let { enableNodeTransitionMove, nodeTransitionMoveDuration } = this.mindMap.opt // 节点 // 重新渲染连线 this.renderLine() + let isLayout = false if (!this.group) { + isLayout = true // 创建组 this.group = new G() this.group.css({ @@ -469,7 +473,7 @@ class Node { this.bindGroupEvent() this.draw.add(this.group) this.layout() - this.update(true) + this.update(isLayout) } else { this.draw.add(this.group) if (this.needLayout) { @@ -498,7 +502,13 @@ class Node { }) ) } else { - callback() + if (enableNodeTransitionMove && !isLayout) { + setTimeout(() => { + callback() + }, nodeTransitionMoveDuration) + } else { + callback() + } } // 手动插入的节点立即获得焦点并且开启编辑模式 if (this.nodeData.inserting) { diff --git a/simple-mind-map/src/layouts/Base.js b/simple-mind-map/src/layouts/Base.js index 70569c31..e6827e1e 100644 --- a/simple-mind-map/src/layouts/Base.js +++ b/simple-mind-map/src/layouts/Base.js @@ -67,7 +67,7 @@ class Base { newNode.getSize() newNode.needLayout = true } - } else if (this.nodePool[data.data.uid]) { + } else if (this.nodePool[data.data.uid] && !this.renderer.reRender) { // 数据上没有保存节点引用,但是通过uid找到了缓存的节点,也可以复用 newNode = this.nodePool[data.data.uid] // 保存该节点上一次的数据