Window introduced

This commit is contained in:
barsdeveloper
2022-09-24 20:27:52 +02:00
parent bf2c3ec939
commit 9a4d323a87
27 changed files with 891 additions and 312 deletions

View File

@@ -1,6 +1,7 @@
import Configuration from "../Configuration"
import IElement from "./IElement"
import Utility from "../Utility"
import IDraggableElement from "./IDraggableElement"
/**
* @typedef {import("../template/SelectableDraggableTemplate").default} SelectableDraggableTemplate
@@ -9,10 +10,10 @@ import Utility from "../Utility"
/**
* @template {IEntity} T
* @template {SelectableDraggableTemplate} U
* @template {IDraggableElement} U
* @extends {IElement<T, U>}
*/
export default class ISelectableDraggableElement extends IElement {
export default class ISelectableDraggableElement extends IDraggableElement {
static properties = {
...super.properties,
@@ -22,24 +23,12 @@ export default class ISelectableDraggableElement extends IElement {
reflect: true,
converter: Utility.booleanConverter,
},
locationX: {
type: Number,
attribute: false,
},
locationY: {
type: Number,
attribute: false,
},
}
constructor(...args) {
super(...args)
this.selected = false
this.locationX = 0
this.locationY = 0
this.listeningDrag = false
let self = this
this.dragHandler = e => self.addLocation(e.detail.value)
}
@@ -54,32 +43,6 @@ export default class ISelectableDraggableElement extends IElement {
this.blueprint.removeEventListener(Configuration.nodeDragEventName, this.dragHandler)
}
/**
* @param {Number[]} param0
*/
setLocation([x, y]) {
const d = [x - this.locationX, y - this.locationY]
this.locationX = x
this.locationY = y
if (this.blueprint) {
const dragLocalEvent = new CustomEvent(Configuration.nodeDragLocalEventName, {
detail: {
value: d,
},
bubbles: false,
cancelable: true
})
this.dispatchEvent(dragLocalEvent)
}
}
/**
* @param {Number[]} param0
*/
addLocation([x, y]) {
this.setLocation([this.locationX + x, this.locationY + y])
}
setSelected(value = true) {
this.selected = value
if (this.blueprint) {
@@ -92,25 +55,4 @@ export default class ISelectableDraggableElement extends IElement {
}
}
}
/**
* @param {Number[]} value
*/
dispatchDragEvent(value) {
const dragEvent = new CustomEvent(Configuration.nodeDragEventName, {
detail: {
value: value
},
bubbles: true,
cancelable: true
})
this.dispatchEvent(dragEvent)
}
snapToGrid() {
const snappedLocation = Utility.snapToGrid([this.locationX, this.locationY], Configuration.gridSize)
if (this.locationX != snappedLocation[0] || this.locationY != snappedLocation[1]) {
this.setLocation(snappedLocation)
}
}
}