Feat:新增创建新节点时默认不聚焦新节点的配置选项
This commit is contained in:
parent
70c32e3c74
commit
2d50106ce7
@ -229,5 +229,7 @@ export const defaultOpt = {
|
|||||||
highlightNodeBoxStyle: {
|
highlightNodeBoxStyle: {
|
||||||
stroke: 'rgb(94, 200, 248)',
|
stroke: 'rgb(94, 200, 248)',
|
||||||
fill: 'transparent'
|
fill: 'transparent'
|
||||||
}
|
},
|
||||||
|
// 创建新节点时默认不聚焦新节点,不进入新节点的编辑状态
|
||||||
|
notFocusNewNodeOnCreateNewNode: false
|
||||||
}
|
}
|
||||||
|
|||||||
@ -344,10 +344,7 @@ class Render {
|
|||||||
let isChange = false
|
let isChange = false
|
||||||
isChange = this.lastActiveNode !== node
|
isChange = this.lastActiveNode !== node
|
||||||
if (!isChange) {
|
if (!isChange) {
|
||||||
isChange = !checkNodeListIsEqual(
|
isChange = !checkNodeListIsEqual(this.lastActiveNodeList, activeNodeList)
|
||||||
this.lastActiveNodeList,
|
|
||||||
activeNodeList
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
if (!isChange) return
|
if (!isChange) return
|
||||||
this.lastActiveNode = node
|
this.lastActiveNode = node
|
||||||
@ -541,16 +538,20 @@ class Render {
|
|||||||
this.textEdit.hideEditTextBox()
|
this.textEdit.hideEditTextBox()
|
||||||
const {
|
const {
|
||||||
defaultInsertSecondLevelNodeText,
|
defaultInsertSecondLevelNodeText,
|
||||||
defaultInsertBelowSecondLevelNodeText
|
defaultInsertBelowSecondLevelNodeText,
|
||||||
|
notFocusNewNodeOnCreateNewNode
|
||||||
} = this.mindMap.opt
|
} = this.mindMap.opt
|
||||||
const list = appointNodes.length > 0 ? appointNodes : this.activeNodeList
|
const list = appointNodes.length > 0 ? appointNodes : this.activeNodeList
|
||||||
const handleMultiNodes = list.length > 1
|
const handleMultiNodes = list.length > 1
|
||||||
const isRichText = !!this.mindMap.richText
|
const isRichText = !!this.mindMap.richText
|
||||||
|
const focusNewNode = notFocusNewNodeOnCreateNewNode
|
||||||
|
? false
|
||||||
|
: handleMultiNodes || !openEdit
|
||||||
const params = {
|
const params = {
|
||||||
expand: true,
|
expand: true,
|
||||||
richText: isRichText,
|
richText: isRichText,
|
||||||
resetRichText: isRichText,
|
resetRichText: isRichText,
|
||||||
isActive: handleMultiNodes || !openEdit // 如果同时对多个节点插入子节点,那么需要把新增的节点设为激活状态。如果不进入编辑状态,那么也需要手动设为激活状态
|
isActive: focusNewNode // 如果同时对多个节点插入子节点,那么需要把新增的节点设为激活状态。如果不进入编辑状态,那么也需要手动设为激活状态
|
||||||
}
|
}
|
||||||
// 动态指定的子节点数据也需要添加相关属性
|
// 动态指定的子节点数据也需要添加相关属性
|
||||||
appointChildren = addDataToAppointNodes(appointChildren, {
|
appointChildren = addDataToAppointNodes(appointChildren, {
|
||||||
@ -569,7 +570,8 @@ class Render {
|
|||||||
// 计算插入位置
|
// 计算插入位置
|
||||||
const index = getNodeDataIndex(node)
|
const index = getNodeDataIndex(node)
|
||||||
const newNodeData = {
|
const newNodeData = {
|
||||||
inserting: handleMultiNodes ? false : openEdit, // 如果同时对多个节点插入子节点,那么无需进入编辑模式,
|
inserting:
|
||||||
|
notFocusNewNodeOnCreateNewNode || handleMultiNodes ? false : openEdit, // 如果同时对多个节点插入子节点,那么无需进入编辑模式,
|
||||||
data: {
|
data: {
|
||||||
text: text,
|
text: text,
|
||||||
...params,
|
...params,
|
||||||
@ -581,7 +583,7 @@ class Render {
|
|||||||
parent.nodeData.children.splice(index + 1, 0, newNodeData)
|
parent.nodeData.children.splice(index + 1, 0, newNodeData)
|
||||||
})
|
})
|
||||||
// 如果同时对多个节点插入子节点,需要清除原来激活的节点
|
// 如果同时对多个节点插入子节点,需要清除原来激活的节点
|
||||||
if (handleMultiNodes || !openEdit) {
|
if (focusNewNode) {
|
||||||
this.clearActiveNodeList()
|
this.clearActiveNodeList()
|
||||||
}
|
}
|
||||||
this.mindMap.render()
|
this.mindMap.render()
|
||||||
@ -597,11 +599,13 @@ class Render {
|
|||||||
this.textEdit.hideEditTextBox()
|
this.textEdit.hideEditTextBox()
|
||||||
const list = appointNodes.length > 0 ? appointNodes : this.activeNodeList
|
const list = appointNodes.length > 0 ? appointNodes : this.activeNodeList
|
||||||
const isRichText = !!this.mindMap.richText
|
const isRichText = !!this.mindMap.richText
|
||||||
|
const { notFocusNewNodeOnCreateNewNode } = this.mindMap.opt
|
||||||
|
const focusNewNode = !notFocusNewNodeOnCreateNewNode
|
||||||
const params = {
|
const params = {
|
||||||
expand: true,
|
expand: true,
|
||||||
richText: isRichText,
|
richText: isRichText,
|
||||||
resetRichText: isRichText,
|
resetRichText: isRichText,
|
||||||
isActive: true
|
isActive: focusNewNode
|
||||||
}
|
}
|
||||||
nodeList = addDataToAppointNodes(nodeList, params)
|
nodeList = addDataToAppointNodes(nodeList, params)
|
||||||
list.forEach(node => {
|
list.forEach(node => {
|
||||||
@ -617,7 +621,9 @@ class Render {
|
|||||||
)
|
)
|
||||||
parent.nodeData.children.splice(index + 1, 0, ...newNodeList)
|
parent.nodeData.children.splice(index + 1, 0, ...newNodeList)
|
||||||
})
|
})
|
||||||
this.clearActiveNodeList()
|
if (focusNewNode) {
|
||||||
|
this.clearActiveNodeList()
|
||||||
|
}
|
||||||
this.mindMap.render()
|
this.mindMap.render()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -635,16 +641,20 @@ class Render {
|
|||||||
this.textEdit.hideEditTextBox()
|
this.textEdit.hideEditTextBox()
|
||||||
const {
|
const {
|
||||||
defaultInsertSecondLevelNodeText,
|
defaultInsertSecondLevelNodeText,
|
||||||
defaultInsertBelowSecondLevelNodeText
|
defaultInsertBelowSecondLevelNodeText,
|
||||||
|
notFocusNewNodeOnCreateNewNode
|
||||||
} = this.mindMap.opt
|
} = this.mindMap.opt
|
||||||
const list = appointNodes.length > 0 ? appointNodes : this.activeNodeList
|
const list = appointNodes.length > 0 ? appointNodes : this.activeNodeList
|
||||||
const handleMultiNodes = list.length > 1
|
const handleMultiNodes = list.length > 1
|
||||||
const isRichText = !!this.mindMap.richText
|
const isRichText = !!this.mindMap.richText
|
||||||
|
const focusNewNode = notFocusNewNodeOnCreateNewNode
|
||||||
|
? false
|
||||||
|
: handleMultiNodes || !openEdit
|
||||||
const params = {
|
const params = {
|
||||||
expand: true,
|
expand: true,
|
||||||
richText: isRichText,
|
richText: isRichText,
|
||||||
resetRichText: isRichText,
|
resetRichText: isRichText,
|
||||||
isActive: handleMultiNodes || !openEdit // 如果同时对多个节点插入子节点,那么需要把新增的节点设为激活状态。如果不进入编辑状态,那么也需要手动设为激活状态
|
isActive: focusNewNode // 如果同时对多个节点插入子节点,那么需要把新增的节点设为激活状态。如果不进入编辑状态,那么也需要手动设为激活状态
|
||||||
}
|
}
|
||||||
// 动态指定的子节点数据也需要添加相关属性
|
// 动态指定的子节点数据也需要添加相关属性
|
||||||
appointChildren = addDataToAppointNodes(appointChildren, {
|
appointChildren = addDataToAppointNodes(appointChildren, {
|
||||||
@ -661,7 +671,8 @@ class Render {
|
|||||||
? defaultInsertSecondLevelNodeText
|
? defaultInsertSecondLevelNodeText
|
||||||
: defaultInsertBelowSecondLevelNodeText
|
: defaultInsertBelowSecondLevelNodeText
|
||||||
const newNode = {
|
const newNode = {
|
||||||
inserting: handleMultiNodes ? false : openEdit, // 如果同时对多个节点插入子节点,那么无需进入编辑模式
|
inserting:
|
||||||
|
notFocusNewNodeOnCreateNewNode || handleMultiNodes ? false : openEdit, // 如果同时对多个节点插入子节点,那么无需进入编辑模式
|
||||||
data: {
|
data: {
|
||||||
text: text,
|
text: text,
|
||||||
uid: createUid(),
|
uid: createUid(),
|
||||||
@ -677,7 +688,7 @@ class Render {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
// 如果同时对多个节点插入子节点,需要清除原来激活的节点
|
// 如果同时对多个节点插入子节点,需要清除原来激活的节点
|
||||||
if (handleMultiNodes || !openEdit) {
|
if (focusNewNode) {
|
||||||
this.clearActiveNodeList()
|
this.clearActiveNodeList()
|
||||||
}
|
}
|
||||||
this.mindMap.render()
|
this.mindMap.render()
|
||||||
@ -693,11 +704,13 @@ class Render {
|
|||||||
this.textEdit.hideEditTextBox()
|
this.textEdit.hideEditTextBox()
|
||||||
const list = appointNodes.length > 0 ? appointNodes : this.activeNodeList
|
const list = appointNodes.length > 0 ? appointNodes : this.activeNodeList
|
||||||
const isRichText = !!this.mindMap.richText
|
const isRichText = !!this.mindMap.richText
|
||||||
|
const { notFocusNewNodeOnCreateNewNode } = this.mindMap.opt
|
||||||
|
const focusNewNode = !notFocusNewNodeOnCreateNewNode
|
||||||
const params = {
|
const params = {
|
||||||
expand: true,
|
expand: true,
|
||||||
richText: isRichText,
|
richText: isRichText,
|
||||||
resetRichText: isRichText,
|
resetRichText: isRichText,
|
||||||
isActive: true
|
isActive: focusNewNode
|
||||||
}
|
}
|
||||||
childList = addDataToAppointNodes(childList, params)
|
childList = addDataToAppointNodes(childList, params)
|
||||||
list.forEach(node => {
|
list.forEach(node => {
|
||||||
@ -714,7 +727,9 @@ class Render {
|
|||||||
expand: true
|
expand: true
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
this.clearActiveNodeList()
|
if (focusNewNode) {
|
||||||
|
this.clearActiveNodeList()
|
||||||
|
}
|
||||||
this.mindMap.render()
|
this.mindMap.render()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -727,16 +742,20 @@ class Render {
|
|||||||
this.textEdit.hideEditTextBox()
|
this.textEdit.hideEditTextBox()
|
||||||
const {
|
const {
|
||||||
defaultInsertSecondLevelNodeText,
|
defaultInsertSecondLevelNodeText,
|
||||||
defaultInsertBelowSecondLevelNodeText
|
defaultInsertBelowSecondLevelNodeText,
|
||||||
|
notFocusNewNodeOnCreateNewNode
|
||||||
} = this.mindMap.opt
|
} = this.mindMap.opt
|
||||||
const list = appointNodes.length > 0 ? appointNodes : this.activeNodeList
|
const list = appointNodes.length > 0 ? appointNodes : this.activeNodeList
|
||||||
const handleMultiNodes = list.length > 1
|
const handleMultiNodes = list.length > 1
|
||||||
const isRichText = !!this.mindMap.richText
|
const isRichText = !!this.mindMap.richText
|
||||||
|
const focusNewNode = notFocusNewNodeOnCreateNewNode
|
||||||
|
? false
|
||||||
|
: handleMultiNodes || !openEdit
|
||||||
const params = {
|
const params = {
|
||||||
expand: true,
|
expand: true,
|
||||||
richText: isRichText,
|
richText: isRichText,
|
||||||
resetRichText: isRichText,
|
resetRichText: isRichText,
|
||||||
isActive: handleMultiNodes || !openEdit // 如果同时对多个节点插入子节点,那么需要把新增的节点设为激活状态。如果不进入编辑状态,那么也需要手动设为激活状态
|
isActive: focusNewNode // 如果同时对多个节点插入子节点,那么需要把新增的节点设为激活状态。如果不进入编辑状态,那么也需要手动设为激活状态
|
||||||
}
|
}
|
||||||
list.forEach(node => {
|
list.forEach(node => {
|
||||||
if (node.isGeneralization || node.isRoot) {
|
if (node.isGeneralization || node.isRoot) {
|
||||||
@ -747,7 +766,8 @@ class Render {
|
|||||||
? defaultInsertSecondLevelNodeText
|
? defaultInsertSecondLevelNodeText
|
||||||
: defaultInsertBelowSecondLevelNodeText
|
: defaultInsertBelowSecondLevelNodeText
|
||||||
const newNode = {
|
const newNode = {
|
||||||
inserting: handleMultiNodes ? false : openEdit, // 如果同时对多个节点插入子节点,那么无需进入编辑模式
|
inserting:
|
||||||
|
notFocusNewNodeOnCreateNewNode || handleMultiNodes ? false : openEdit, // 如果同时对多个节点插入子节点,那么无需进入编辑模式
|
||||||
data: {
|
data: {
|
||||||
text: text,
|
text: text,
|
||||||
uid: createUid(),
|
uid: createUid(),
|
||||||
@ -762,7 +782,7 @@ class Render {
|
|||||||
parent.nodeData.children.splice(index, 1, newNode)
|
parent.nodeData.children.splice(index, 1, newNode)
|
||||||
})
|
})
|
||||||
// 如果同时对多个节点插入子节点,需要清除原来激活的节点
|
// 如果同时对多个节点插入子节点,需要清除原来激活的节点
|
||||||
if (handleMultiNodes || !openEdit) {
|
if (focusNewNode) {
|
||||||
this.clearActiveNodeList()
|
this.clearActiveNodeList()
|
||||||
}
|
}
|
||||||
this.mindMap.render()
|
this.mindMap.render()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user