Feat:节点比对全部改为通过uid对比
This commit is contained in:
parent
1d04038609
commit
5585d2a4f7
@ -382,7 +382,7 @@ class Render {
|
|||||||
// 检索某个节点在激活列表里的索引
|
// 检索某个节点在激活列表里的索引
|
||||||
findActiveNodeIndex(node) {
|
findActiveNodeIndex(node) {
|
||||||
return this.activeNodeList.findIndex(item => {
|
return this.activeNodeList.findIndex(item => {
|
||||||
return item === node
|
return item.uid === node.uid
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -390,7 +390,7 @@ class Render {
|
|||||||
getNodeIndex(node) {
|
getNodeIndex(node) {
|
||||||
return node.parent
|
return node.parent
|
||||||
? node.parent.children.findIndex(item => {
|
? node.parent.children.findIndex(item => {
|
||||||
return item === node
|
return item.uid === node.uid
|
||||||
})
|
})
|
||||||
: 0
|
: 0
|
||||||
}
|
}
|
||||||
@ -553,7 +553,7 @@ class Render {
|
|||||||
let parent = node.parent
|
let parent = node.parent
|
||||||
let childList = parent.children
|
let childList = parent.children
|
||||||
let index = childList.findIndex(item => {
|
let index = childList.findIndex(item => {
|
||||||
return item === node
|
return item.uid === node.uid
|
||||||
})
|
})
|
||||||
if (index === -1 || index === 0) {
|
if (index === -1 || index === 0) {
|
||||||
return
|
return
|
||||||
@ -580,7 +580,7 @@ class Render {
|
|||||||
let parent = node.parent
|
let parent = node.parent
|
||||||
let childList = parent.children
|
let childList = parent.children
|
||||||
let index = childList.findIndex(item => {
|
let index = childList.findIndex(item => {
|
||||||
return item === node
|
return item.uid === node.uid
|
||||||
})
|
})
|
||||||
if (index === -1 || index === childList.length - 1) {
|
if (index === -1 || index === childList.length - 1) {
|
||||||
return
|
return
|
||||||
@ -752,7 +752,7 @@ class Render {
|
|||||||
let nodeParent = node.parent
|
let nodeParent = node.parent
|
||||||
let nodeBorthers = nodeParent.children
|
let nodeBorthers = nodeParent.children
|
||||||
let nodeIndex = nodeBorthers.findIndex(item => {
|
let nodeIndex = nodeBorthers.findIndex(item => {
|
||||||
return item === node
|
return item.uid === node.uid
|
||||||
})
|
})
|
||||||
if (nodeIndex === -1) {
|
if (nodeIndex === -1) {
|
||||||
return
|
return
|
||||||
@ -764,7 +764,7 @@ class Render {
|
|||||||
let existParent = exist.parent
|
let existParent = exist.parent
|
||||||
let existBorthers = existParent.children
|
let existBorthers = existParent.children
|
||||||
let existIndex = existBorthers.findIndex(item => {
|
let existIndex = existBorthers.findIndex(item => {
|
||||||
return item === exist
|
return item.uid === exist.uid
|
||||||
})
|
})
|
||||||
if (existIndex === -1) {
|
if (existIndex === -1) {
|
||||||
return
|
return
|
||||||
@ -791,7 +791,7 @@ class Render {
|
|||||||
let nodeParent = node.parent
|
let nodeParent = node.parent
|
||||||
let nodeBorthers = nodeParent.children
|
let nodeBorthers = nodeParent.children
|
||||||
let nodeIndex = nodeBorthers.findIndex(item => {
|
let nodeIndex = nodeBorthers.findIndex(item => {
|
||||||
return item === node
|
return item.uid === node.uid
|
||||||
})
|
})
|
||||||
if (nodeIndex === -1) {
|
if (nodeIndex === -1) {
|
||||||
return
|
return
|
||||||
@ -803,7 +803,7 @@ class Render {
|
|||||||
let existParent = exist.parent
|
let existParent = exist.parent
|
||||||
let existBorthers = existParent.children
|
let existBorthers = existParent.children
|
||||||
let existIndex = existBorthers.findIndex(item => {
|
let existIndex = existBorthers.findIndex(item => {
|
||||||
return item === exist
|
return item.uid === exist.uid
|
||||||
})
|
})
|
||||||
if (existIndex === -1) {
|
if (existIndex === -1) {
|
||||||
return
|
return
|
||||||
|
|||||||
@ -794,12 +794,12 @@ class Node {
|
|||||||
|
|
||||||
// 检测当前节点是否是某个节点的祖先节点
|
// 检测当前节点是否是某个节点的祖先节点
|
||||||
isParent(node) {
|
isParent(node) {
|
||||||
if (this === node) {
|
if (this.uid === node.uid) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
let parent = node.parent
|
let parent = node.parent
|
||||||
while (parent) {
|
while (parent) {
|
||||||
if (this === parent) {
|
if (this.uid === parent.uid) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
parent = parent.parent
|
parent = parent.parent
|
||||||
@ -809,11 +809,11 @@ class Node {
|
|||||||
|
|
||||||
// 检测当前节点是否是某个节点的兄弟节点
|
// 检测当前节点是否是某个节点的兄弟节点
|
||||||
isBrother(node) {
|
isBrother(node) {
|
||||||
if (!this.parent || this === node) {
|
if (!this.parent || this.uid === node.uid) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
return this.parent.children.find(item => {
|
return this.parent.children.find(item => {
|
||||||
return item === node
|
return item.uid === node.uid
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -362,7 +362,7 @@ class AssociativeLine {
|
|||||||
if (node.nodeData.data.isActive) {
|
if (node.nodeData.data.isActive) {
|
||||||
this.mindMap.renderer.setNodeActive(node, false)
|
this.mindMap.renderer.setNodeActive(node, false)
|
||||||
}
|
}
|
||||||
if (node === this.creatingStartNode || this.overlapNode) {
|
if (node.uid === this.creatingStartNode.uid || this.overlapNode) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
let { left, top, width, height } = node
|
let { left, top, width, height } = node
|
||||||
@ -379,7 +379,7 @@ class AssociativeLine {
|
|||||||
|
|
||||||
// 完成创建连接线
|
// 完成创建连接线
|
||||||
completeCreateLine(node) {
|
completeCreateLine(node) {
|
||||||
if (this.creatingStartNode === node) return
|
if (this.creatingStartNode.uid === node.uid) return
|
||||||
this.addLine(this.creatingStartNode, node)
|
this.addLine(this.creatingStartNode, node)
|
||||||
if (this.overlapNode && this.overlapNode.nodeData.data.isActive) {
|
if (this.overlapNode && this.overlapNode.nodeData.data.isActive) {
|
||||||
this.mindMap.renderer.setNodeActive(this.overlapNode, false)
|
this.mindMap.renderer.setNodeActive(this.overlapNode, false)
|
||||||
|
|||||||
@ -218,7 +218,7 @@ class Drag extends Base {
|
|||||||
if (node.nodeData.data.isActive) {
|
if (node.nodeData.data.isActive) {
|
||||||
this.mindMap.renderer.setNodeActive(node, false)
|
this.mindMap.renderer.setNodeActive(node, false)
|
||||||
}
|
}
|
||||||
if (node === this.node || this.node.isParent(node)) {
|
if (node.uid === this.node.uid) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (this.overlapNode || (this.prevNode && this.nextNode)) {
|
if (this.overlapNode || (this.prevNode && this.nextNode)) {
|
||||||
@ -231,7 +231,7 @@ class Drag extends Base {
|
|||||||
return item !== this.node
|
return item !== this.node
|
||||||
}) : []
|
}) : []
|
||||||
let index = checkList.findIndex((item) => {
|
let index = checkList.findIndex((item) => {
|
||||||
return item === node
|
return item.uid === node.uid
|
||||||
})
|
})
|
||||||
let prevBrother = null
|
let prevBrother = null
|
||||||
let nextBrother = null
|
let nextBrother = null
|
||||||
|
|||||||
@ -94,7 +94,7 @@ class KeyboardNavigation {
|
|||||||
// 遍历节点树
|
// 遍历节点树
|
||||||
bfsWalk(this.mindMap.renderer.root, node => {
|
bfsWalk(this.mindMap.renderer.root, node => {
|
||||||
// 跳过当前聚焦的节点
|
// 跳过当前聚焦的节点
|
||||||
if (node === currentActiveNode) return
|
if (node.uid === currentActiveNode.uid) return
|
||||||
// 当前遍历到的节点的位置信息
|
// 当前遍历到的节点的位置信息
|
||||||
let rect = this.getNodeRect(node)
|
let rect = this.getNodeRect(node)
|
||||||
let { left, top, right, bottom } = rect
|
let { left, top, right, bottom } = rect
|
||||||
@ -131,7 +131,7 @@ class KeyboardNavigation {
|
|||||||
checkNodeDis
|
checkNodeDis
|
||||||
}) {
|
}) {
|
||||||
bfsWalk(this.mindMap.renderer.root, node => {
|
bfsWalk(this.mindMap.renderer.root, node => {
|
||||||
if (node === currentActiveNode) return
|
if (node.uid === currentActiveNode.uid) return
|
||||||
let rect = this.getNodeRect(node)
|
let rect = this.getNodeRect(node)
|
||||||
let { left, top, right, bottom } = rect
|
let { left, top, right, bottom } = rect
|
||||||
let match = false
|
let match = false
|
||||||
@ -173,7 +173,7 @@ class KeyboardNavigation {
|
|||||||
let cX = (currentActiveNodeRect.right + currentActiveNodeRect.left) / 2
|
let cX = (currentActiveNodeRect.right + currentActiveNodeRect.left) / 2
|
||||||
let cY = (currentActiveNodeRect.bottom + currentActiveNodeRect.top) / 2
|
let cY = (currentActiveNodeRect.bottom + currentActiveNodeRect.top) / 2
|
||||||
bfsWalk(this.mindMap.renderer.root, node => {
|
bfsWalk(this.mindMap.renderer.root, node => {
|
||||||
if (node === currentActiveNode) return
|
if (node.uid === currentActiveNode.uid) return
|
||||||
let rect = this.getNodeRect(node)
|
let rect = this.getNodeRect(node)
|
||||||
let { left, top, right, bottom } = rect
|
let { left, top, right, bottom } = rect
|
||||||
// 遍历到的节点的中心点
|
// 遍历到的节点的中心点
|
||||||
|
|||||||
@ -49,7 +49,7 @@ class NodeImgAdjust {
|
|||||||
// 如果当前正在拖动调整中那么直接返回
|
// 如果当前正在拖动调整中那么直接返回
|
||||||
if (this.isMousedown || this.isAdjusted || this.mindMap.opt.readonly) return
|
if (this.isMousedown || this.isAdjusted || this.mindMap.opt.readonly) return
|
||||||
// 如果在当前节点内移动,以及自定义元素已经是显示状态,那么直接返回
|
// 如果在当前节点内移动,以及自定义元素已经是显示状态,那么直接返回
|
||||||
if (this.node === node && this.isShowHandleEl) return
|
if ((this.node && this.node.uid === node.uid) && this.isShowHandleEl) return
|
||||||
// 更新当前节点信息
|
// 更新当前节点信息
|
||||||
this.node = node
|
this.node = node
|
||||||
this.img = img
|
this.img = img
|
||||||
|
|||||||
@ -49,7 +49,7 @@ class Painter {
|
|||||||
!this.isInPainter ||
|
!this.isInPainter ||
|
||||||
!this.painterNode ||
|
!this.painterNode ||
|
||||||
!node ||
|
!node ||
|
||||||
node === this.painterNode
|
node.uid === this.painterNode.uid
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
const style = {}
|
const style = {}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user