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

View file

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