Feat:新增拦截节点开始拖拽的实例化选项

This commit is contained in:
街角小林
2024-06-24 18:42:14 +08:00
parent 1ec723db0e
commit a047dabbd0
2 changed files with 13 additions and 5 deletions

View File

@@ -256,6 +256,8 @@ export const defaultOpt = {
handleDragCloneNode: null,
// 即将拖拽完成前调用该函数,函数接收一个对象作为参数:{overlapNodeUid,prevNodeUid,nextNodeUid}代表拖拽信息如果要阻止本次拖拽那么可以返回true此时node_dragend事件不会再触发。函数可以是异步函数返回Promise实例
beforeDragEnd: null,
// 即将开始调整节点前调用该函数函数接收当前即将被拖拽的节点实例列表作为参数如果要阻止本次拖拽那么可以返回true
beforeDragStart: null,
// 【Watermark插件】
// 水印配置
@@ -380,5 +382,5 @@ export const defaultOpt = {
beforeHideRichTextEdit: null,
// 设置富文本节点编辑框和节点大小一致,形成伪原地编辑的效果
// 需要注意的是,只有当节点内只有文本、且形状是矩形才会有比较好的效果
richTextEditFakeInPlace: false,
richTextEditFakeInPlace: false
}

View File

@@ -19,7 +19,7 @@ class Drag extends Base {
// 复位
reset() {
// 是否正在跳转
// 是否正在拖拽
this.isDragging = false
// 鼠标按下的节点
this.mousedownNode = null
@@ -223,7 +223,7 @@ class Drag extends Base {
// 拖动中
onMove(x, y, e) {
if (!this.isMousedown) {
if (!this.isMousedown || !this.isDragging) {
return
}
// 更新克隆节点的位置
@@ -245,9 +245,8 @@ class Drag extends Base {
}
// 开始拖拽时初始化一些数据
handleStartMove() {
async handleStartMove() {
if (!this.isDragging) {
this.isDragging = true
// 鼠标按下的节点
let node = this.mousedownNode
// 计算鼠标按下的位置距离节点左上角的距离
@@ -268,12 +267,19 @@ class Drag extends Base {
// 否则只拖拽按下的节点
this.beingDragNodeList = [node]
}
// 拦截拖拽
const { beforeDragStart } = this.mindMap.opt
if (typeof beforeDragStart === 'function') {
const stop = await beforeDragStart([...this.beingDragNodeList])
if (stop) return
}
// 将节点树转为节点数组
this.nodeTreeToList()
// 创建克隆节点
this.createCloneNode()
// 清除当前所有激活的节点
this.mindMap.execCommand('CLEAR_ACTIVE_NODE')
this.isDragging = true
}
}