mirror of
https://github.com/barsdeveloper/ueblueprint.git
synced 2026-02-03 23:55:04 +08:00
59 lines
1.7 KiB
JavaScript
59 lines
1.7 KiB
JavaScript
import Configuration from "../Configuration"
|
|
import IElement from "./IElement"
|
|
import Utility from "../Utility"
|
|
import IDraggableElement from "./IDraggableElement"
|
|
|
|
/**
|
|
* @typedef {import("../template/SelectableDraggableTemplate").default} SelectableDraggableTemplate
|
|
* @typedef {import("../entity/IEntity").default} IEntity
|
|
*/
|
|
|
|
/**
|
|
* @template {IEntity} T
|
|
* @template {SelectableDraggableTemplate} U
|
|
* @extends {IDraggableElement<T, U>}
|
|
*/
|
|
export default class ISelectableDraggableElement extends IDraggableElement {
|
|
|
|
static properties = {
|
|
...super.properties,
|
|
selected: {
|
|
type: Boolean,
|
|
attribute: "data-selected",
|
|
reflect: true,
|
|
converter: Utility.booleanConverter,
|
|
},
|
|
}
|
|
|
|
constructor(...args) {
|
|
super(...args)
|
|
this.selected = false
|
|
this.listeningDrag = false
|
|
let self = this
|
|
this.dragHandler = e => self.addLocation(e.detail.value)
|
|
}
|
|
|
|
connectedCallback() {
|
|
super.connectedCallback()
|
|
this.setSelected(this.selected)
|
|
}
|
|
|
|
disconnectedCallback() {
|
|
super.disconnectedCallback()
|
|
this.blueprint.removeEventListener(Configuration.nodeDragGeneralEventName, this.dragHandler)
|
|
}
|
|
|
|
setSelected(value = true) {
|
|
this.selected = value
|
|
if (this.blueprint) {
|
|
if (this.selected) {
|
|
this.listeningDrag = true
|
|
this.blueprint.addEventListener(Configuration.nodeDragGeneralEventName, this.dragHandler)
|
|
} else {
|
|
this.blueprint.removeEventListener(Configuration.nodeDragGeneralEventName, this.dragHandler)
|
|
this.listeningDrag = false
|
|
}
|
|
}
|
|
}
|
|
}
|