mirror of
https://github.com/barsdeveloper/ueblueprint.git
synced 2026-05-17 10:17:29 +08:00
Various fixes and refactoring
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
// @ts-check
|
||||
|
||||
import Configuration from "../Configuration"
|
||||
import IElement from "./IElement"
|
||||
import MouseMoveNodes from "../input/mouse/MouseMoveNodes"
|
||||
|
||||
@@ -39,7 +40,7 @@ export default class ISelectableDraggableElement extends IElement {
|
||||
this.location = value
|
||||
this.template.applyLocation(this)
|
||||
if (this.blueprint) {
|
||||
const dragLocalEvent = new CustomEvent(this.blueprint.settings.nodeDragLocalEventName, {
|
||||
const dragLocalEvent = new CustomEvent(Configuration.nodeDragLocalEventName, {
|
||||
detail: {
|
||||
value: d
|
||||
},
|
||||
@@ -60,15 +61,15 @@ export default class ISelectableDraggableElement extends IElement {
|
||||
}
|
||||
this.selected = value
|
||||
if (this.selected) {
|
||||
this.blueprint.addEventListener(this.blueprint.settings.nodeDragEventName, this.dragHandler)
|
||||
this.blueprint.addEventListener(Configuration.nodeDragEventName, this.dragHandler)
|
||||
} else {
|
||||
this.blueprint.removeEventListener(this.blueprint.settings.nodeDragEventName, this.dragHandler)
|
||||
this.blueprint.removeEventListener(Configuration.nodeDragEventName, this.dragHandler)
|
||||
}
|
||||
this.template.applySelected(this)
|
||||
}
|
||||
|
||||
dispatchDragEvent(value) {
|
||||
const dragEvent = new CustomEvent(this.blueprint.settings.nodeDragEventName, {
|
||||
const dragEvent = new CustomEvent(Configuration.nodeDragEventName, {
|
||||
detail: {
|
||||
value: value
|
||||
},
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
// @ts-check
|
||||
|
||||
import Configuration from "../Configuration"
|
||||
import IElement from "./IElement"
|
||||
import LinkTemplate from "../template/LinkTemplate"
|
||||
|
||||
@@ -10,10 +11,60 @@ import LinkTemplate from "../template/LinkTemplate"
|
||||
export default class LinkElement extends IElement {
|
||||
|
||||
static tagName = "ueb-link"
|
||||
|
||||
/** @type {PinElement} */
|
||||
#source
|
||||
get sourcePin() {
|
||||
return this.#source
|
||||
}
|
||||
set sourcePin(pin) {
|
||||
if (this.#source) {
|
||||
const nodeElement = this.#source.getNodeElement()
|
||||
nodeElement.removeEventListener(Configuration.nodeDeleteEventName, this.#nodeDeleteHandler)
|
||||
nodeElement.removeEventListener(Configuration.nodeDragLocalEventName, this.#nodeDragSourceHandler)
|
||||
if (this.#destination) {
|
||||
this.#unlinkPins()
|
||||
}
|
||||
}
|
||||
this.#source = pin
|
||||
if (this.#source) {
|
||||
const nodeElement = this.#source.getNodeElement()
|
||||
this.originatesFromInput = pin.isInput()
|
||||
nodeElement.addEventListener(Configuration.nodeDeleteEventName, this.#nodeDeleteHandler)
|
||||
nodeElement.addEventListener(Configuration.nodeDragLocalEventName, this.#nodeDragSourceHandler)
|
||||
this.setSourceLocation()
|
||||
if (this.#destination) {
|
||||
this.#linkPins()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** @type {PinElement} */
|
||||
#destination
|
||||
get destinationPin() {
|
||||
return this.#destination
|
||||
}
|
||||
set destinationPin(pin) {
|
||||
if (this.#destination) {
|
||||
const nodeElement = this.#destination.getNodeElement()
|
||||
nodeElement.removeEventListener(Configuration.nodeDeleteEventName, this.#nodeDeleteHandler)
|
||||
nodeElement.removeEventListener(Configuration.nodeDragLocalEventName, this.#nodeDragDestinatonHandler)
|
||||
if (this.#source) {
|
||||
this.#unlinkPins()
|
||||
}
|
||||
}
|
||||
this.#destination = pin
|
||||
if (this.#destination) {
|
||||
const nodeElement = this.#destination.getNodeElement()
|
||||
nodeElement.addEventListener(Configuration.nodeDeleteEventName, this.#nodeDeleteHandler)
|
||||
nodeElement.addEventListener(Configuration.nodeDragLocalEventName, this.#nodeDragDestinatonHandler)
|
||||
this.setDestinationLocation()
|
||||
if (this.#source) {
|
||||
this.#linkPins()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#nodeDeleteHandler
|
||||
#nodeDragSourceHandler
|
||||
#nodeDragDestinatonHandler
|
||||
@@ -38,10 +89,10 @@ export default class LinkElement extends IElement {
|
||||
this.#nodeDragSourceHandler = e => self.addSourceLocation(e.detail.value)
|
||||
this.#nodeDragDestinatonHandler = e => self.addDestinationLocation(e.detail.value)
|
||||
if (source) {
|
||||
this.setSourcePin(source)
|
||||
this.sourcePin = source
|
||||
}
|
||||
if (destination) {
|
||||
this.setDestinationPin(destination)
|
||||
this.destinationPin = destination
|
||||
}
|
||||
if (source && destination) {
|
||||
this.#linkPins()
|
||||
@@ -124,71 +175,6 @@ export default class LinkElement extends IElement {
|
||||
this.template.applyFullLocation(this)
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {PinElement}
|
||||
*/
|
||||
getSourcePin() {
|
||||
return this.#source
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {PinElement} pin
|
||||
*/
|
||||
setSourcePin(pin) {
|
||||
if (this.#source) {
|
||||
const settings = this.#source.blueprint.settings
|
||||
const nodeElement = this.#source.getNodeElement()
|
||||
nodeElement.removeEventListener(settings.nodeDeleteEventName, this.#nodeDeleteHandler)
|
||||
nodeElement.removeEventListener(settings.nodeDragLocalEventName, this.#nodeDragSourceHandler)
|
||||
if (this.#destination) {
|
||||
this.#unlinkPins()
|
||||
}
|
||||
}
|
||||
this.#source = pin
|
||||
if (this.#source) {
|
||||
const nodeElement = this.#source.getNodeElement()
|
||||
const settings = this.#source.blueprint.settings
|
||||
this.originatesFromInput = pin.isInput()
|
||||
nodeElement.addEventListener(settings.nodeDeleteEventName, this.#nodeDeleteHandler)
|
||||
nodeElement.addEventListener(settings.nodeDragLocalEventName, this.#nodeDragSourceHandler)
|
||||
this.setSourceLocation()
|
||||
if (this.#destination) {
|
||||
this.#linkPins()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {PinElement}
|
||||
*/
|
||||
getDestinationPin() {
|
||||
return this.#destination
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {PinElement} pin
|
||||
*/
|
||||
setDestinationPin(pin) {
|
||||
if (this.#destination) {
|
||||
const nodeElement = this.#destination.getNodeElement()
|
||||
nodeElement.removeEventListener(this.blueprint.settings.nodeDeleteEventName, this.#nodeDeleteHandler)
|
||||
nodeElement.removeEventListener(this.blueprint.settings.nodeDragLocalEventName, this.#nodeDragDestinatonHandler)
|
||||
if (this.#source) {
|
||||
this.#unlinkPins()
|
||||
}
|
||||
}
|
||||
this.#destination = pin
|
||||
if (this.#destination) {
|
||||
const nodeElement = this.#destination.getNodeElement()
|
||||
nodeElement.addEventListener(this.blueprint.settings.nodeDeleteEventName, this.#nodeDeleteHandler)
|
||||
nodeElement.addEventListener(this.blueprint.settings.nodeDragLocalEventName, this.#nodeDragDestinatonHandler)
|
||||
this.setDestinationLocation()
|
||||
if (this.#source) {
|
||||
this.#linkPins()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {LinkMessageElement} linkMessage
|
||||
*/
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
// @ts-check
|
||||
|
||||
import Configuration from "../Configuration"
|
||||
import ISelectableDraggableElement from "./ISelectableDraggableElement"
|
||||
import NodeTemplate from "../template/NodeTemplate"
|
||||
import ObjectEntity from "../entity/ObjectEntity"
|
||||
import SerializerFactory from "../serialization/SerializerFactory"
|
||||
import PinEntity from "../entity/PinEntity"
|
||||
import SerializerFactory from "../serialization/SerializerFactory"
|
||||
|
||||
export default class NodeElement extends ISelectableDraggableElement {
|
||||
|
||||
@@ -34,7 +35,7 @@ export default class NodeElement extends ISelectableDraggableElement {
|
||||
}
|
||||
|
||||
getNodeName() {
|
||||
return this.entity.getName()
|
||||
return this.entity.getFullName()
|
||||
}
|
||||
|
||||
getPinElements() {
|
||||
@@ -63,7 +64,7 @@ export default class NodeElement extends ISelectableDraggableElement {
|
||||
}
|
||||
|
||||
dispatchDeleteEvent(value) {
|
||||
let deleteEvent = new CustomEvent(this.blueprint.settings.nodeDeleteEventName, {
|
||||
let deleteEvent = new CustomEvent(Configuration.nodeDeleteEventName, {
|
||||
bubbles: true,
|
||||
cancelable: true,
|
||||
})
|
||||
|
||||
@@ -20,14 +20,15 @@ export default class PinElement extends IElement {
|
||||
"string": StringPinTemplate,
|
||||
}
|
||||
|
||||
#color = ""
|
||||
|
||||
/** @type {NodeElement} */
|
||||
nodeElement
|
||||
|
||||
/** @type {HTMLElement} */
|
||||
clickableElement
|
||||
|
||||
/** @type {String} */
|
||||
#color
|
||||
connections = 0
|
||||
|
||||
constructor(entity) {
|
||||
super(
|
||||
|
||||
Reference in New Issue
Block a user