mirror of
https://github.com/barsdeveloper/ueblueprint.git
synced 2026-02-04 08:50:33 +08:00
Links fixed
This commit is contained in:
2237
dist/ueblueprint.js
vendored
2237
dist/ueblueprint.js
vendored
File diff suppressed because it is too large
Load Diff
@@ -15,10 +15,15 @@ import Unfocus from "./input/mouse/Unfocus"
|
||||
import Utility from "./Utility"
|
||||
import Zoom from "./input/mouse/Zoom"
|
||||
|
||||
/**
|
||||
* @typedef {import("./entity/GuidEntity").default} GuidEntity
|
||||
* @typedef {import("./element/PinElement").default} PinElement
|
||||
*/
|
||||
export default class Blueprint extends IElement {
|
||||
|
||||
static tagName = "ueb-blueprint"
|
||||
#pinGuidMap = new Map()
|
||||
/** @type {WeakMap<GuidEntity, PinElement>} */
|
||||
#pinGuidMap = new WeakMap()
|
||||
/** @type {number} */
|
||||
gridSize = Configuration.gridSize
|
||||
/** @type {NodeElement[]}" */
|
||||
@@ -288,7 +293,6 @@ export default class Blueprint extends IElement {
|
||||
|
||||
/**
|
||||
* Returns the list of nodes in this blueprint. It can filter the list providing just the selected ones.
|
||||
* @returns {NodeElement[]} Nodes
|
||||
*/
|
||||
getNodes(selected = false) {
|
||||
if (selected) {
|
||||
@@ -300,6 +304,13 @@ export default class Blueprint extends IElement {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {GuidEntity} guid
|
||||
*/
|
||||
getPin(guid) {
|
||||
return this.#pinGuidMap[guid]
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the list of links in this blueprint.
|
||||
* @returns {LinkElement[]} Nodes
|
||||
@@ -339,8 +350,7 @@ export default class Blueprint extends IElement {
|
||||
if (element instanceof NodeElement) {
|
||||
this.nodes.push(element)
|
||||
element.getPinElements().forEach(
|
||||
pinElement => this.#pinGuidMap[
|
||||
pinElement.]
|
||||
pinElement => this.#pinGuidMap[pinElement.GetPinId()] = pinElement
|
||||
)
|
||||
} else if (element instanceof LinkElement) {
|
||||
this.links.push(element)
|
||||
|
||||
@@ -53,8 +53,15 @@ export default class LinkElement extends IElement {
|
||||
}
|
||||
|
||||
#unlinkPins() {
|
||||
this.#source.unlinkFrom(this.#destination)
|
||||
this.#destination.unlinkFrom(this.#source)
|
||||
if (this.#source && this.#destination) {
|
||||
this.#source.unlinkFrom(this.#destination)
|
||||
this.#destination.unlinkFrom(this.#source)
|
||||
}
|
||||
}
|
||||
|
||||
disconnectedCallback() {
|
||||
super.disconnectedCallback()
|
||||
this.#unlinkPins()
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -107,6 +107,7 @@ export default class PinElement extends IElement {
|
||||
*/
|
||||
linkTo(targetPinElement) {
|
||||
this.entity.linkTo(targetPinElement.nodeElement.getNodeName(), targetPinElement.entity)
|
||||
this.template.applyConnected(this)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -114,6 +115,7 @@ export default class PinElement extends IElement {
|
||||
*/
|
||||
unlinkFrom(targetPinElement) {
|
||||
this.entity.unlinkFrom(targetPinElement.nodeElement.getNodeName(), targetPinElement.entity)
|
||||
this.template.applyConnected(this)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -71,13 +71,13 @@ export default class PinEntity extends IEntity {
|
||||
linkTo(targetObjectName, targetPinEntity) {
|
||||
/** @type {PinReferenceEntity[]} */
|
||||
this.LinkedTo
|
||||
const pinExists = !this.LinkedTo.find(
|
||||
const linkExists = this.LinkedTo.find(
|
||||
/** @type {PinReferenceEntity} */
|
||||
pinReferenceEntity => {
|
||||
return pinReferenceEntity.objectName == targetObjectName
|
||||
&& pinReferenceEntity.pinGuid == targetPinEntity.PinId
|
||||
})
|
||||
if (pinExists) {
|
||||
if (!linkExists) {
|
||||
this.LinkedTo.push(new PinReferenceEntity({
|
||||
objectName: targetObjectName,
|
||||
pinGuid: targetPinEntity.PinId
|
||||
|
||||
@@ -64,6 +64,7 @@ export default class MouseCreateLink extends IMouseClickDrag {
|
||||
|
||||
startDrag() {
|
||||
this.link = new LinkElement(this.target, null)
|
||||
this.blueprint.nodesContainerElement.prepend(this.link)
|
||||
this.setLinkMessage(LinkMessageElement.placeNode())
|
||||
this.#listenedPins = this.blueprint.querySelectorAll(this.target.constructor.tagName)
|
||||
this.#listenedPins.forEach(pin => {
|
||||
@@ -101,6 +102,5 @@ export default class MouseCreateLink extends IMouseClickDrag {
|
||||
|
||||
setLinkMessage(linkMessage) {
|
||||
this.link.setLinkMessage(linkMessage)
|
||||
this.blueprint.nodesContainerElement.prepend(this.link)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ export default class ISerializer {
|
||||
return `"${value}"`
|
||||
}
|
||||
if (value instanceof Array) {
|
||||
return `(${value.map(v => serialize(v) + ",")})`
|
||||
return `(${value.map(v => serialize(v) + ",").join("")})`
|
||||
}
|
||||
if (value instanceof IEntity) {
|
||||
return serialize(value)
|
||||
|
||||
@@ -54,6 +54,7 @@ export default class NodeTemplate extends SelectableDraggableTemplate {
|
||||
|
||||
/**
|
||||
* @param {NodeElement} node
|
||||
* @returns {NodeListOf<PinElement>}
|
||||
*/
|
||||
getPinElements(node) {
|
||||
return node.querySelectorAll(PinElement.tagName)
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import html from "./html"
|
||||
import ITemplate from "./ITemplate"
|
||||
import LinkElement from "../element/LinkElement"
|
||||
import NodeElement from "../element/NodeElement"
|
||||
import sanitizeText from "./sanitizeText"
|
||||
import Utility from "../Utility"
|
||||
import NodeElement from "../element/NodeElement"
|
||||
|
||||
/**
|
||||
* @typedef {import("../element/NodeElement").default} NodeElement
|
||||
@@ -40,11 +41,15 @@ export default class PinTemplate extends ITemplate {
|
||||
"ueb-pin-" + sanitizeText(pin.getType())
|
||||
)
|
||||
pin.clickableElement = pin
|
||||
pin.nodeElement = pin.closest(NodeElement.tagName)
|
||||
if (!pin.nodeElement) {
|
||||
window.customElements.whenDefined(linkMessage.constructor.tagName).then(linkMessage)
|
||||
}
|
||||
pin.getLin
|
||||
window.customElements.whenDefined(NodeElement.tagName).then(pin.nodeElement = pin.closest(NodeElement.tagName))
|
||||
pin.getLinks().forEach(pinReference => {
|
||||
const targetPin = pin.blueprint.getPin(pinReference.pinGuid)
|
||||
if (linkedToPin) {
|
||||
const [sourcePin, destinationPin] = pin.isOutput() ? [pin, targetPin] : [targetPin, pin]
|
||||
pin.blueprint.addGraphElement(new LinkElement(sourcePin, destinationPin))
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user