Feat:节点比对全部改为通过uid对比

This commit is contained in:
wanglin2
2023-09-07 18:45:02 +08:00
parent 1d04038609
commit 5585d2a4f7
7 changed files with 21 additions and 21 deletions

View File

@@ -382,7 +382,7 @@ class Render {
// 检索某个节点在激活列表里的索引
findActiveNodeIndex(node) {
return this.activeNodeList.findIndex(item => {
return item === node
return item.uid === node.uid
})
}
@@ -390,7 +390,7 @@ class Render {
getNodeIndex(node) {
return node.parent
? node.parent.children.findIndex(item => {
return item === node
return item.uid === node.uid
})
: 0
}
@@ -553,7 +553,7 @@ class Render {
let parent = node.parent
let childList = parent.children
let index = childList.findIndex(item => {
return item === node
return item.uid === node.uid
})
if (index === -1 || index === 0) {
return
@@ -580,7 +580,7 @@ class Render {
let parent = node.parent
let childList = parent.children
let index = childList.findIndex(item => {
return item === node
return item.uid === node.uid
})
if (index === -1 || index === childList.length - 1) {
return
@@ -752,7 +752,7 @@ class Render {
let nodeParent = node.parent
let nodeBorthers = nodeParent.children
let nodeIndex = nodeBorthers.findIndex(item => {
return item === node
return item.uid === node.uid
})
if (nodeIndex === -1) {
return
@@ -764,7 +764,7 @@ class Render {
let existParent = exist.parent
let existBorthers = existParent.children
let existIndex = existBorthers.findIndex(item => {
return item === exist
return item.uid === exist.uid
})
if (existIndex === -1) {
return
@@ -791,7 +791,7 @@ class Render {
let nodeParent = node.parent
let nodeBorthers = nodeParent.children
let nodeIndex = nodeBorthers.findIndex(item => {
return item === node
return item.uid === node.uid
})
if (nodeIndex === -1) {
return
@@ -803,7 +803,7 @@ class Render {
let existParent = exist.parent
let existBorthers = existParent.children
let existIndex = existBorthers.findIndex(item => {
return item === exist
return item.uid === exist.uid
})
if (existIndex === -1) {
return

View File

@@ -794,12 +794,12 @@ class Node {
// 检测当前节点是否是某个节点的祖先节点
isParent(node) {
if (this === node) {
if (this.uid === node.uid) {
return false
}
let parent = node.parent
while (parent) {
if (this === parent) {
if (this.uid === parent.uid) {
return true
}
parent = parent.parent
@@ -809,11 +809,11 @@ class Node {
// 检测当前节点是否是某个节点的兄弟节点
isBrother(node) {
if (!this.parent || this === node) {
if (!this.parent || this.uid === node.uid) {
return false
}
return this.parent.children.find(item => {
return item === node
return item.uid === node.uid
})
}

View File

@@ -362,7 +362,7 @@ class AssociativeLine {
if (node.nodeData.data.isActive) {
this.mindMap.renderer.setNodeActive(node, false)
}
if (node === this.creatingStartNode || this.overlapNode) {
if (node.uid === this.creatingStartNode.uid || this.overlapNode) {
return
}
let { left, top, width, height } = node
@@ -379,7 +379,7 @@ class AssociativeLine {
// 完成创建连接线
completeCreateLine(node) {
if (this.creatingStartNode === node) return
if (this.creatingStartNode.uid === node.uid) return
this.addLine(this.creatingStartNode, node)
if (this.overlapNode && this.overlapNode.nodeData.data.isActive) {
this.mindMap.renderer.setNodeActive(this.overlapNode, false)

View File

@@ -218,7 +218,7 @@ class Drag extends Base {
if (node.nodeData.data.isActive) {
this.mindMap.renderer.setNodeActive(node, false)
}
if (node === this.node || this.node.isParent(node)) {
if (node.uid === this.node.uid) {
return
}
if (this.overlapNode || (this.prevNode && this.nextNode)) {
@@ -231,7 +231,7 @@ class Drag extends Base {
return item !== this.node
}) : []
let index = checkList.findIndex((item) => {
return item === node
return item.uid === node.uid
})
let prevBrother = null
let nextBrother = null

View File

@@ -94,7 +94,7 @@ class KeyboardNavigation {
// 遍历节点树
bfsWalk(this.mindMap.renderer.root, node => {
// 跳过当前聚焦的节点
if (node === currentActiveNode) return
if (node.uid === currentActiveNode.uid) return
// 当前遍历到的节点的位置信息
let rect = this.getNodeRect(node)
let { left, top, right, bottom } = rect
@@ -131,7 +131,7 @@ class KeyboardNavigation {
checkNodeDis
}) {
bfsWalk(this.mindMap.renderer.root, node => {
if (node === currentActiveNode) return
if (node.uid === currentActiveNode.uid) return
let rect = this.getNodeRect(node)
let { left, top, right, bottom } = rect
let match = false
@@ -173,7 +173,7 @@ class KeyboardNavigation {
let cX = (currentActiveNodeRect.right + currentActiveNodeRect.left) / 2
let cY = (currentActiveNodeRect.bottom + currentActiveNodeRect.top) / 2
bfsWalk(this.mindMap.renderer.root, node => {
if (node === currentActiveNode) return
if (node.uid === currentActiveNode.uid) return
let rect = this.getNodeRect(node)
let { left, top, right, bottom } = rect
// 遍历到的节点的中心点

View File

@@ -49,7 +49,7 @@ class NodeImgAdjust {
// 如果当前正在拖动调整中那么直接返回
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.img = img

View File

@@ -49,7 +49,7 @@ class Painter {
!this.isInPainter ||
!this.painterNode ||
!node ||
node === this.painterNode
node.uid === this.painterNode.uid
)
return
const style = {}