Comment now drag nodes

This commit is contained in:
barsdeveloper
2022-12-11 21:58:40 +01:00
parent fffe3f7ad1
commit 16a00b409c
17 changed files with 208 additions and 40 deletions

View File

@@ -78,7 +78,16 @@ export default class NodeElement extends ISelectableDraggableElement {
}
#pins
#boundComments
/** @type {NodeElement[]} */
boundComments = []
#commentDragged = false
#commentDragHandler = e => {
if (!this.selected && !this.#commentDragged) {
this.addLocation(e.detail.value) // if selected it will already move
this.#commentDragged = true
this.addNextUpdatedCallbacks(() => this.#commentDragged = false)
}
}
/**
* @param {ObjectEntity} entity
@@ -122,6 +131,32 @@ export default class NodeElement extends ISelectableDraggableElement {
return new NodeElement(entity)
}
/** @param {NodeElement} commentNode */
bindToComment(commentNode) {
if (!this.boundComments.includes(commentNode)) {
commentNode.addEventListener(Configuration.nodeDragEventName, this.#commentDragHandler)
this.boundComments.push(commentNode)
}
}
/** @param {NodeElement} commentNode */
unbindFromComment(commentNode) {
const commentIndex = this.boundComments.indexOf(commentNode)
if (commentIndex >= 0) {
commentNode.removeEventListener(Configuration.nodeDragEventName, this.#commentDragHandler)
this.boundComments[commentIndex] = this.boundComments[this.boundComments.length - 1]
this.boundComments.pop()
}
}
/** @param {NodeElement} commentNode */
isInsideComment(commentNode) {
return this.topBoundary() >= commentNode.topBoundary()
&& this.rightBoundary() <= commentNode.rightBoundary()
&& this.bottomBoundary() <= commentNode.bottomBoundary()
&& this.leftBoundary() >= commentNode.leftBoundary()
}
disconnectedCallback() {
super.disconnectedCallback()
this.acknowledgeDelete()