1.优化重复的历史数据;2.修复节点编辑时的方向键冲突;3.修复拖拽节点的id丢失问题
This commit is contained in:
parent
8dcfdcc44a
commit
5313b9b69c
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "simple-mind-map",
|
"name": "simple-mind-map",
|
||||||
"version": "0.4.5",
|
"version": "0.4.6",
|
||||||
"description": "一个简单的web在线思维导图",
|
"description": "一个简单的web在线思维导图",
|
||||||
"authors": [
|
"authors": [
|
||||||
{
|
{
|
||||||
|
|||||||
@ -76,6 +76,10 @@ class Command {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
let data = this.getCopyData()
|
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.history.push(simpleDeepClone(data))
|
||||||
this.activeHistoryIndex = this.history.length - 1
|
this.activeHistoryIndex = this.history.length - 1
|
||||||
this.mindMap.emit('data_change', data)
|
this.mindMap.emit('data_change', data)
|
||||||
|
|||||||
@ -1,4 +1,3 @@
|
|||||||
import { isKey } from './utils/keyMap'
|
|
||||||
import { bfsWalk } from './utils'
|
import { bfsWalk } from './utils'
|
||||||
|
|
||||||
// 键盘导航类
|
// 键盘导航类
|
||||||
@ -8,22 +7,29 @@ class KeyboardNavigation {
|
|||||||
this.opt = opt
|
this.opt = opt
|
||||||
this.mindMap = opt.mindMap
|
this.mindMap = opt.mindMap
|
||||||
this.onKeyup = this.onKeyup.bind(this)
|
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) {
|
onKeyup(dir) {
|
||||||
;['Left', 'Up', 'Right', 'Down'].forEach(dir => {
|
if (this.mindMap.renderer.activeNodeList.length > 0) {
|
||||||
if (isKey(e, dir)) {
|
this.focus(dir)
|
||||||
if (this.mindMap.renderer.activeNodeList.length > 0) {
|
} else {
|
||||||
this.focus(dir)
|
let root = this.mindMap.renderer.root
|
||||||
} else {
|
this.mindMap.renderer.moveNodeToCenter(root)
|
||||||
let root = this.mindMap.renderer.root
|
root.active()
|
||||||
this.mindMap.renderer.moveNodeToCenter(root)
|
}
|
||||||
root.active()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 聚焦到下一个节点
|
// 聚焦到下一个节点
|
||||||
|
|||||||
@ -355,7 +355,7 @@ class Render {
|
|||||||
|
|
||||||
// 插入同级节点,多个节点只会操作第一个节点
|
// 插入同级节点,多个节点只会操作第一个节点
|
||||||
|
|
||||||
insertNode() {
|
insertNode(openEdit = true) {
|
||||||
if (this.activeNodeList.length <= 0) {
|
if (this.activeNodeList.length <= 0) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -369,7 +369,7 @@ class Render {
|
|||||||
}
|
}
|
||||||
let index = this.getNodeIndex(first)
|
let index = this.getNodeIndex(first)
|
||||||
first.parent.nodeData.children.splice(index + 1, 0, {
|
first.parent.nodeData.children.splice(index + 1, 0, {
|
||||||
inserting: true,
|
inserting: openEdit,
|
||||||
data: {
|
data: {
|
||||||
text: text,
|
text: text,
|
||||||
expand: true
|
expand: true
|
||||||
@ -382,7 +382,7 @@ class Render {
|
|||||||
|
|
||||||
// 插入子节点
|
// 插入子节点
|
||||||
|
|
||||||
insertChildNode() {
|
insertChildNode(openEdit = true) {
|
||||||
if (this.activeNodeList.length <= 0) {
|
if (this.activeNodeList.length <= 0) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -392,7 +392,7 @@ class Render {
|
|||||||
}
|
}
|
||||||
let text = node.isRoot ? '二级节点' : '分支主题'
|
let text = node.isRoot ? '二级节点' : '分支主题'
|
||||||
node.nodeData.children.push({
|
node.nodeData.children.push({
|
||||||
inserting: true,
|
inserting: openEdit,
|
||||||
data: {
|
data: {
|
||||||
text: text,
|
text: text,
|
||||||
expand: true
|
expand: true
|
||||||
@ -629,7 +629,7 @@ class Render {
|
|||||||
if (node.isRoot) {
|
if (node.isRoot) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
let copyData = copyNodeTree({}, node)
|
let copyData = copyNodeTree({}, node, false, true)
|
||||||
this.removeActiveNode(node)
|
this.removeActiveNode(node)
|
||||||
this.removeOneNode(node)
|
this.removeOneNode(node)
|
||||||
this.mindMap.emit('node_active', null, this.activeNodeList)
|
this.mindMap.emit('node_active', null, this.activeNodeList)
|
||||||
|
|||||||
@ -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)
|
tree.data = simpleDeepClone(root.nodeData ? root.nodeData.data : root.data)
|
||||||
// 去除节点id,因为节点id不能重复
|
// 去除节点id,因为节点id不能重复
|
||||||
if (tree.data.id) delete tree.data.id
|
if (tree.data.id && !keepId) delete tree.data.id
|
||||||
if (removeActiveState) {
|
if (removeActiveState) {
|
||||||
tree.data.isActive = false
|
tree.data.isActive = false
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user