Feat:新增拦截删除节点图片的实例化选项

This commit is contained in:
街角小林
2024-09-09 18:04:37 +08:00
parent 007a5f2815
commit ef526fe302
2 changed files with 13 additions and 3 deletions

View File

@@ -410,5 +410,9 @@ export const defaultOpt = {
// 【Painter】插件
// 是否只格式刷节点手动设置的样式,不考虑节点通过主题的应用的样式
onlyPainterNodeCustomStyles: false
onlyPainterNodeCustomStyles: false,
// 【NodeImgAdjust】插件
// 拦截节点图片的删除点击节点图片上的删除按钮删除图片前会调用该函数如果函数返回true则取消删除
beforeDeleteNodeImg: null
}

View File

@@ -192,8 +192,14 @@ class NodeImgAdjust {
if (this.isMousedown) return
this.hideHandleEl()
})
btnRemove.addEventListener('click', e => {
this.mindMap.execCommand('SET_NODE_IMAGE', this.node, { url: null })
btnRemove.addEventListener('click', async e => {
let stop = false
if (typeof this.mindMap.opt.beforeDeleteNodeImg === 'function') {
stop = await this.mindMap.opt.beforeDeleteNodeImg(this.node)
}
if (!stop) {
this.mindMap.execCommand('SET_NODE_IMAGE', this.node, { url: null })
}
})
// 添加元素到页面
const targetNode = this.mindMap.opt.customInnerElsAppendTo || document.body