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