mirror of
https://github.com/barsdeveloper/ueblueprint.git
synced 2026-03-17 05:47:34 +08:00
Link implementation wip
This commit is contained in:
@@ -1,29 +1,61 @@
|
||||
import GraphLink from "../../graph/GraphLink"
|
||||
import MouseClickDrag from "./MouseClickDrag"
|
||||
|
||||
export default class MouseCreateLink extends MouseClickDrag {
|
||||
|
||||
/** @type {(e: MouseEvent) => void} */
|
||||
#mouseenterHandler
|
||||
|
||||
/** @type {(e: MouseEvent) => void} */
|
||||
#mouseleaveHandler
|
||||
|
||||
constructor(target, blueprint, options) {
|
||||
super(target, blueprint, options)
|
||||
/** @type {import("../../graph/GraphPin").default} */
|
||||
this.target
|
||||
/** @type {import("../../graph/GraphLink").default} */
|
||||
this.link
|
||||
/** @type {import("../../entity/PinEntity").default} */
|
||||
this.enteredPin
|
||||
|
||||
let self = this
|
||||
this.#mouseenterHandler = e => {
|
||||
if (!self.enteredPin) {
|
||||
self.enteredPin = e.target
|
||||
}
|
||||
}
|
||||
this.#mouseleaveHandler = e => {
|
||||
if (self.enteredPin == e.target) {
|
||||
self.enteredPin = null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
startDrag() {
|
||||
let link = this.target.dragLink()
|
||||
|
||||
this.link = new GraphLink(this.target, null)
|
||||
this.blueprint.nodesContainerElement.insertBefore(this.link, this.blueprint.selectorElement.nextElementSibling)
|
||||
this.blueprint.querySelectorAll("ueb-pin." + this.target.isInput() ? "output" : "input")
|
||||
.forEach(pin => {
|
||||
pin.addEventListener("mouseenter", this.#mouseenterHandler)
|
||||
pin.addEventListener("mouseleave", this.#mouseleaveHandler)
|
||||
})
|
||||
}
|
||||
|
||||
dragTo(location, movement) {
|
||||
//this.selectorElement.doSelecting(location)
|
||||
this.link.setDestinationLocation(location)
|
||||
}
|
||||
|
||||
endDrag() {
|
||||
if (this.started) {
|
||||
//this.selectorElement.finishSelecting()
|
||||
this.blueprint.querySelectorAll("ueb-pin." + this.target.isInput() ? "output" : "input")
|
||||
.forEach(pin => {
|
||||
pin.removeEventListener("mouseenter", this.#mouseenterHandler)
|
||||
pin.removeEventListener("mouseleave", this.#mouseleaveHandler)
|
||||
})
|
||||
if (this.enteredPin) {
|
||||
this.link.setDestinationPin(this.link)
|
||||
} else {
|
||||
// this.blueprint.unselectAll()
|
||||
// this.link.remove()
|
||||
}
|
||||
this.link = null
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user