Feat:增加是否阻止mousedown事件默认事件的实例化选项

This commit is contained in:
街角小林
2024-09-25 10:31:39 +08:00
parent 0344599411
commit 82c2d848a9
3 changed files with 12 additions and 4 deletions

View File

@@ -245,6 +245,8 @@ export const defaultOpt = {
emptyTextMeasureHeightText: 'abc123我和你', emptyTextMeasureHeightText: 'abc123我和你',
// 是否在进行节点文本编辑时实时更新节点大小和节点位置,开启后当节点数量比较多时可能会造成卡顿 // 是否在进行节点文本编辑时实时更新节点大小和节点位置,开启后当节点数量比较多时可能会造成卡顿
openRealtimeRenderOnNodeTextEdit: false, openRealtimeRenderOnNodeTextEdit: false,
// 默认会给容器元素el绑定mousedown事件并且会阻止其默认事件这会带来一定问题比如你聚焦在思维导图外的其他输入框点击画布就不会触发其失焦可以通过该选项关闭阻止。关闭后也会带来一定问题比如鼠标框选节点时可能会选中节点文字看你如何取舍
mousedownEventPreventDefault: true,
// 【Select插件】 // 【Select插件】
// 多选节点时鼠标移动到边缘时的画布移动偏移量 // 多选节点时鼠标移动到边缘时的画布移动偏移量

View File

@@ -30,8 +30,11 @@ class View {
}) })
// 拖动视图 // 拖动视图
this.mindMap.event.on('mousedown', e => { this.mindMap.event.on('mousedown', e => {
if (this.mindMap.opt.isDisableDrag) return const { isDisableDrag, mousedownEventPreventDefault } = this.mindMap.opt
if (isDisableDrag) return
if (mousedownEventPreventDefault) {
e.preventDefault() e.preventDefault()
}
this.sx = this.x this.sx = this.x
this.sy = this.y this.sy = this.y
}) })

View File

@@ -41,7 +41,8 @@ class Select {
// 鼠标按下 // 鼠标按下
onMousedown(e) { onMousedown(e) {
if (this.mindMap.opt.readonly) { const { readonly, mousedownEventPreventDefault } = this.mindMap.opt
if (readonly) {
return return
} }
let { useLeftKeySelectionRightKeyDrag } = this.mindMap.opt let { useLeftKeySelectionRightKeyDrag } = this.mindMap.opt
@@ -51,7 +52,9 @@ class Select {
) { ) {
return return
} }
if (mousedownEventPreventDefault) {
e.preventDefault() e.preventDefault()
}
this.isMousedown = true this.isMousedown = true
this.cacheActiveList = [...this.mindMap.renderer.activeNodeList] this.cacheActiveList = [...this.mindMap.renderer.activeNodeList]
let { x, y } = this.mindMap.toPos(e.clientX, e.clientY) let { x, y } = this.mindMap.toPos(e.clientX, e.clientY)