Fixed drag-and-drop with drag source instead of drag target

This commit is contained in:
Magnus Åhall 2026-06-14 15:02:27 +02:00
parent 63434678ce
commit 04c936e730
2 changed files with 10 additions and 14 deletions

View file

@ -370,7 +370,7 @@ class N2DragIcon extends CustomHTMLElement {
this.style.top = `${e.clientY}px`
})
this.dragTarget = null
this.dragSource = null
}// }}}
start() {// {{{
this.style.display = 'block'
@ -383,11 +383,11 @@ class N2DragIcon extends CustomHTMLElement {
name = '_' + name
this.elIcon.setAttribute('src', `/images/${_VERSION}/icon_drag${name}.svg`)
}// }}}
setTarget(t) {// {{{
this.dragTarget = t
setSource(s) {// {{{
this.dragSource = s
}// }}}
getTarget() {// {{{
return this.dragTarget
getSource() {// {{{
return this.dragSource
}// }}}
}

View file

@ -585,6 +585,7 @@ export class N2TreeNode extends CustomHTMLElement {
e.dataTransfer.setDragImage(blankPixel, 0, 0)
e.dataTransfer.allowedEffects = 'none'
e.stopPropagation()
_app.dragIcon.setSource(this)
_app.dragIcon.start()
}// }}}
dragEnd(e) {// {{{
@ -598,13 +599,12 @@ export class N2TreeNode extends CustomHTMLElement {
}// }}}
async dragDrop(e) {// {{{
e.stopPropagation()
const moveToNode = _app.dragIcon.getTarget()
await _app.moveNode(this.node, moveToNode.node.UUID)
return
const sourceNode = _app.dragIcon.getSource()
await _app.moveNode(sourceNode.node, this.node.UUID)
_app.sidebar.setNodeExpanded(moveToNode, true)
_app.sidebar.setNodeExpanded(this, true)
await this.render(true, true)
await moveToNode.render(true, true)
await sourceNode.render(true, true)
this.dragLeave(e)
}// }}}
@ -615,8 +615,6 @@ export class N2TreeNode extends CustomHTMLElement {
e.stopPropagation()
_app.dragIcon.icon('ok')
this.classList.add('drag-target')
_app.dragIcon.setTarget(this)
}// }}}
dragLeave(e) {// {{{
e.stopPropagation()
@ -624,8 +622,6 @@ export class N2TreeNode extends CustomHTMLElement {
e.dataTransfer.setDragImage(N2TreeNode.DRAG_ICON, -16, 8)
_app.dragIcon.icon('')
this.classList.remove('drag-target')
_app.dragIcon.setTarget(null)
}// }}}
async fetchChildren(force_fetch) {//{{{
if (this.children_populated && !force_fetch)