diff --git a/simple-mind-map/package.json b/simple-mind-map/package.json index 5c446feb..5f154591 100644 --- a/simple-mind-map/package.json +++ b/simple-mind-map/package.json @@ -1,6 +1,6 @@ { "name": "simple-mind-map", - "version": "0.4.5", + "version": "0.4.6", "description": "一个简单的web在线思维导图", "authors": [ { diff --git a/simple-mind-map/src/Command.js b/simple-mind-map/src/Command.js index 25ad3f33..71a88be1 100644 --- a/simple-mind-map/src/Command.js +++ b/simple-mind-map/src/Command.js @@ -76,6 +76,10 @@ class Command { return } let data = this.getCopyData() + // 此次数据和上次一样则不重复添加 + if (this.history.length > 0 && JSON.stringify(this.history[this.history.length - 1]) === JSON.stringify(data)) { + return + } this.history.push(simpleDeepClone(data)) this.activeHistoryIndex = this.history.length - 1 this.mindMap.emit('data_change', data) diff --git a/simple-mind-map/src/KeyboardNavigation.js b/simple-mind-map/src/KeyboardNavigation.js index a8c7d1c6..0408dfae 100644 --- a/simple-mind-map/src/KeyboardNavigation.js +++ b/simple-mind-map/src/KeyboardNavigation.js @@ -1,4 +1,3 @@ -import { isKey } from './utils/keyMap' import { bfsWalk } from './utils' // 键盘导航类 @@ -8,22 +7,29 @@ class KeyboardNavigation { this.opt = opt this.mindMap = opt.mindMap this.onKeyup = this.onKeyup.bind(this) - this.mindMap.on('keyup', this.onKeyup) + this.mindMap.keyCommand.addShortcut('Left', () => { + this.onKeyup('Left') + }) + this.mindMap.keyCommand.addShortcut('Up', () => { + this.onKeyup('Up') + }) + this.mindMap.keyCommand.addShortcut('Right', () => { + this.onKeyup('Right') + }) + this.mindMap.keyCommand.addShortcut('Down', () => { + this.onKeyup('Down') + }) } // 处理按键事件 - onKeyup(e) { - ;['Left', 'Up', 'Right', 'Down'].forEach(dir => { - if (isKey(e, dir)) { - if (this.mindMap.renderer.activeNodeList.length > 0) { - this.focus(dir) - } else { - let root = this.mindMap.renderer.root - this.mindMap.renderer.moveNodeToCenter(root) - root.active() - } - } - }) + onKeyup(dir) { + if (this.mindMap.renderer.activeNodeList.length > 0) { + this.focus(dir) + } else { + let root = this.mindMap.renderer.root + this.mindMap.renderer.moveNodeToCenter(root) + root.active() + } } // 聚焦到下一个节点 diff --git a/simple-mind-map/src/Render.js b/simple-mind-map/src/Render.js index 6d3c92e5..4c87a471 100644 --- a/simple-mind-map/src/Render.js +++ b/simple-mind-map/src/Render.js @@ -355,7 +355,7 @@ class Render { // 插入同级节点,多个节点只会操作第一个节点 - insertNode() { + insertNode(openEdit = true) { if (this.activeNodeList.length <= 0) { return } @@ -369,7 +369,7 @@ class Render { } let index = this.getNodeIndex(first) first.parent.nodeData.children.splice(index + 1, 0, { - inserting: true, + inserting: openEdit, data: { text: text, expand: true @@ -382,7 +382,7 @@ class Render { // 插入子节点 - insertChildNode() { + insertChildNode(openEdit = true) { if (this.activeNodeList.length <= 0) { return } @@ -392,7 +392,7 @@ class Render { } let text = node.isRoot ? '二级节点' : '分支主题' node.nodeData.children.push({ - inserting: true, + inserting: openEdit, data: { text: text, expand: true @@ -629,7 +629,7 @@ class Render { if (node.isRoot) { return } - let copyData = copyNodeTree({}, node) + let copyData = copyNodeTree({}, node, false, true) this.removeActiveNode(node) this.removeOneNode(node) this.mindMap.emit('node_active', null, this.activeNodeList) diff --git a/simple-mind-map/src/utils/index.js b/simple-mind-map/src/utils/index.js index 35f8f812..7a825a6e 100644 --- a/simple-mind-map/src/utils/index.js +++ b/simple-mind-map/src/utils/index.js @@ -134,10 +134,10 @@ export const copyRenderTree = (tree, root) => { } // 复制节点树数据 -export const copyNodeTree = (tree, root, removeActiveState = false) => { +export const copyNodeTree = (tree, root, removeActiveState = false, keepId = false) => { tree.data = simpleDeepClone(root.nodeData ? root.nodeData.data : root.data) // 去除节点id,因为节点id不能重复 - if (tree.data.id) delete tree.data.id + if (tree.data.id && !keepId) delete tree.data.id if (removeActiveState) { tree.data.isActive = false }