Feature:1.支持配置节点文本编辑框、节点备注浮层的z-index。2.支持点击画布区域外结束节点编辑状态
This commit is contained in:
parent
9fc2dbabd4
commit
d45a18904e
@ -95,7 +95,13 @@ const defaultOpt = {
|
|||||||
initRootNodePosition: null,
|
initRootNodePosition: null,
|
||||||
// 导出png、svg、pdf时的图形内边距
|
// 导出png、svg、pdf时的图形内边距
|
||||||
exportPaddingX: 10,
|
exportPaddingX: 10,
|
||||||
exportPaddingY: 10
|
exportPaddingY: 10,
|
||||||
|
// 节点文本编辑框的z-index
|
||||||
|
nodeTextEditZIndex: 3000,
|
||||||
|
// 节点备注浮层的z-index
|
||||||
|
nodeNoteTooltipZIndex: 3000,
|
||||||
|
// 是否在点击了画布外的区域时结束节点文本的编辑状态
|
||||||
|
isEndNodeTextEditOnClickOuter: true
|
||||||
}
|
}
|
||||||
|
|
||||||
// 思维导图
|
// 思维导图
|
||||||
|
|||||||
@ -27,6 +27,7 @@ class Event extends EventEmitter {
|
|||||||
|
|
||||||
// 绑定函数上下文
|
// 绑定函数上下文
|
||||||
bindFn() {
|
bindFn() {
|
||||||
|
this.onBodyClick = this.onBodyClick.bind(this)
|
||||||
this.onDrawClick = this.onDrawClick.bind(this)
|
this.onDrawClick = this.onDrawClick.bind(this)
|
||||||
this.onMousedown = this.onMousedown.bind(this)
|
this.onMousedown = this.onMousedown.bind(this)
|
||||||
this.onMousemove = this.onMousemove.bind(this)
|
this.onMousemove = this.onMousemove.bind(this)
|
||||||
@ -41,6 +42,7 @@ class Event extends EventEmitter {
|
|||||||
|
|
||||||
// 绑定事件
|
// 绑定事件
|
||||||
bind() {
|
bind() {
|
||||||
|
document.body.addEventListener('click', this.onBodyClick)
|
||||||
this.mindMap.svg.on('click', this.onDrawClick)
|
this.mindMap.svg.on('click', this.onDrawClick)
|
||||||
this.mindMap.el.addEventListener('mousedown', this.onMousedown)
|
this.mindMap.el.addEventListener('mousedown', this.onMousedown)
|
||||||
this.mindMap.svg.on('mousedown', this.onSvgMousedown)
|
this.mindMap.svg.on('mousedown', this.onSvgMousedown)
|
||||||
@ -55,6 +57,7 @@ class Event extends EventEmitter {
|
|||||||
|
|
||||||
// 解绑事件
|
// 解绑事件
|
||||||
unbind() {
|
unbind() {
|
||||||
|
document.body.removeEventListener('click', this.onBodyClick)
|
||||||
this.mindMap.svg.off('click', this.onDrawClick)
|
this.mindMap.svg.off('click', this.onDrawClick)
|
||||||
this.mindMap.el.removeEventListener('mousedown', this.onMousedown)
|
this.mindMap.el.removeEventListener('mousedown', this.onMousedown)
|
||||||
window.removeEventListener('mousemove', this.onMousemove)
|
window.removeEventListener('mousemove', this.onMousemove)
|
||||||
@ -71,6 +74,11 @@ class Event extends EventEmitter {
|
|||||||
this.emit('draw_click', e)
|
this.emit('draw_click', e)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 页面的单击事件
|
||||||
|
onBodyClick(e) {
|
||||||
|
this.emit('body_click', e)
|
||||||
|
}
|
||||||
|
|
||||||
// svg画布的鼠标按下事件
|
// svg画布的鼠标按下事件
|
||||||
onSvgMousedown(e) {
|
onSvgMousedown(e) {
|
||||||
this.emit('svg_mousedown', e)
|
this.emit('svg_mousedown', e)
|
||||||
|
|||||||
@ -99,6 +99,9 @@ class RichText {
|
|||||||
if (!this.textEditNode) {
|
if (!this.textEditNode) {
|
||||||
this.textEditNode = document.createElement('div')
|
this.textEditNode = document.createElement('div')
|
||||||
this.textEditNode.style.cssText = `position:fixed;box-sizing: border-box;box-shadow: 0 0 20px rgba(0,0,0,.5);outline: none; word-break: break-all;padding: 3px 5px;margin-left: -5px;margin-top: -3px;`
|
this.textEditNode.style.cssText = `position:fixed;box-sizing: border-box;box-shadow: 0 0 20px rgba(0,0,0,.5);outline: none; word-break: break-all;padding: 3px 5px;margin-left: -5px;margin-top: -3px;`
|
||||||
|
this.textEditNode.addEventListener('click', e => {
|
||||||
|
e.stopPropagation()
|
||||||
|
})
|
||||||
document.body.appendChild(this.textEditNode)
|
document.body.appendChild(this.textEditNode)
|
||||||
}
|
}
|
||||||
// 原始宽高
|
// 原始宽高
|
||||||
@ -107,6 +110,7 @@ class RichText {
|
|||||||
let originHeight = g.attr('data-height')
|
let originHeight = g.attr('data-height')
|
||||||
// 使用节点的填充色,否则如果节点颜色是白色的话编辑时看不见
|
// 使用节点的填充色,否则如果节点颜色是白色的话编辑时看不见
|
||||||
let bgColor = node.style.merge('fillColor')
|
let bgColor = node.style.merge('fillColor')
|
||||||
|
this.textEditNode.style.zIndex = this.mindMap.opt.nodeTextEditZIndex
|
||||||
this.textEditNode.style.backgroundColor = bgColor === 'transparent' ? '#fff' : bgColor
|
this.textEditNode.style.backgroundColor = bgColor === 'transparent' ? '#fff' : bgColor
|
||||||
this.textEditNode.style.minWidth = originWidth + 'px'
|
this.textEditNode.style.minWidth = originWidth + 'px'
|
||||||
this.textEditNode.style.minHeight = originHeight + 'px'
|
this.textEditNode.style.minHeight = originHeight + 'px'
|
||||||
|
|||||||
@ -23,6 +23,12 @@ export default class TextEdit {
|
|||||||
// 隐藏文本编辑框
|
// 隐藏文本编辑框
|
||||||
this.hideEditTextBox()
|
this.hideEditTextBox()
|
||||||
})
|
})
|
||||||
|
this.mindMap.on('body_click', () => {
|
||||||
|
// 隐藏文本编辑框
|
||||||
|
if (this.mindMap.opt.isEndNodeTextEditOnClickOuter) {
|
||||||
|
this.hideEditTextBox()
|
||||||
|
}
|
||||||
|
})
|
||||||
this.mindMap.on('svg_mousedown', () => {
|
this.mindMap.on('svg_mousedown', () => {
|
||||||
// 隐藏文本编辑框
|
// 隐藏文本编辑框
|
||||||
this.hideEditTextBox()
|
this.hideEditTextBox()
|
||||||
@ -73,6 +79,9 @@ export default class TextEdit {
|
|||||||
this.textEditNode.addEventListener('keyup', e => {
|
this.textEditNode.addEventListener('keyup', e => {
|
||||||
e.stopPropagation()
|
e.stopPropagation()
|
||||||
})
|
})
|
||||||
|
this.textEditNode.addEventListener('click', e => {
|
||||||
|
e.stopPropagation()
|
||||||
|
})
|
||||||
document.body.appendChild(this.textEditNode)
|
document.body.appendChild(this.textEditNode)
|
||||||
}
|
}
|
||||||
let scale = this.mindMap.view.scale
|
let scale = this.mindMap.view.scale
|
||||||
@ -80,6 +89,7 @@ export default class TextEdit {
|
|||||||
let fontSize = node.style.merge('fontSize')
|
let fontSize = node.style.merge('fontSize')
|
||||||
let textLines = node.nodeData.data.text.split(/\n/gim)
|
let textLines = node.nodeData.data.text.split(/\n/gim)
|
||||||
node.style.domText(this.textEditNode, scale, textLines.length)
|
node.style.domText(this.textEditNode, scale, textLines.length)
|
||||||
|
this.textEditNode.style.zIndex = this.mindMap.opt.nodeTextEditZIndex
|
||||||
this.textEditNode.innerHTML = textLines.join('<br>')
|
this.textEditNode.innerHTML = textLines.join('<br>')
|
||||||
this.textEditNode.style.minWidth = rect.width + 10 + 'px'
|
this.textEditNode.style.minWidth = rect.width + 10 + 'px'
|
||||||
this.textEditNode.style.minHeight = rect.height + 6 + 'px'
|
this.textEditNode.style.minHeight = rect.height + 6 + 'px'
|
||||||
|
|||||||
@ -205,13 +205,14 @@ function createNoteNode() {
|
|||||||
if (!this.noteEl) {
|
if (!this.noteEl) {
|
||||||
this.noteEl = document.createElement('div')
|
this.noteEl = document.createElement('div')
|
||||||
this.noteEl.style.cssText = `
|
this.noteEl.style.cssText = `
|
||||||
position: absolute;
|
position: absolute;
|
||||||
padding: 10px;
|
padding: 10px;
|
||||||
border-radius: 5px;
|
border-radius: 5px;
|
||||||
box-shadow: 0 2px 5px rgb(0 0 0 / 10%);
|
box-shadow: 0 2px 5px rgb(0 0 0 / 10%);
|
||||||
display: none;
|
display: none;
|
||||||
background-color: #fff;
|
background-color: #fff;
|
||||||
`
|
z-index: ${ this.mindMap.opt.nodeNoteTooltipZIndex }
|
||||||
|
`
|
||||||
document.body.appendChild(this.noteEl)
|
document.body.appendChild(this.noteEl)
|
||||||
}
|
}
|
||||||
this.noteEl.innerText = this.nodeData.data.note
|
this.noteEl.innerText = this.nodeData.data.note
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user