diff --git a/css/ueblueprint-style.css b/css/ueblueprint-style.css index 0747bc6..3481219 100644 --- a/css/ueblueprint-style.css +++ b/css/ueblueprint-style.css @@ -285,8 +285,8 @@ u-blueprint[data-focused="true"] .ueb-viewport-body { margin-right: auto; } -.ueb-node-input, -.ueb-node-output { +u-pin { + display: block; padding: 4px 8px; cursor: pointer; } diff --git a/dist/ueblueprint.js b/dist/ueblueprint.js index 095fd64..de9b08a 100644 --- a/dist/ueblueprint.js +++ b/dist/ueblueprint.js @@ -974,7 +974,7 @@ class PinReferenceEntity extends Entity { } } -class PinEntity extends Entity { +class PinEntity$1 extends Entity { static attributes = { PinId: GuidEntity, @@ -1007,23 +1007,7 @@ class PinEntity extends Entity { } getAttributes() { - return PinEntity.attributes - } - - /** - * - * @returns {String} - */ - getPinDisplayName() { - return this.PinName - } - - isConnected() { - return this.LinkedTo.length > 0 - } - - getType() { - return this.PinType.PinCategory ?? "object" + return PinEntity$1.attributes } isInput() { @@ -1037,6 +1021,14 @@ class PinEntity extends Entity { return true } } + + isConnected() { + return this.LinkedTo.length > 0 + } + + getType() { + return this.PinType.PinCategory ?? "object" + } } /** @@ -1066,6 +1058,83 @@ class SelectableDraggableTemplate extends Template { } } +/** + * @typedef {import("../graph/GraphPin").default} GraphPin + */ +class PinTemplate extends Template { + + /** + * Computes the html content of the pin. + * @param {GraphPin} pin Pin entity + * @returns The result html + */ + render(pin) { + if (pin.isInput()) { + return html` + + ${pin.getPinDisplayName()} + ` + } else { + return html` + ${pin.getPinDisplayName()} + + ` + } + } + + /** + * Applies the style to the element. + * @param {GraphPin} pin Element of the graph + */ + apply(pin) { + super.apply(pin); + pin.classList.add("ueb-node-" + pin.isInput() ? "input" : "output", "ueb-node-value-" + pin.getType()); + } +} + +class GraphPin extends GraphElement { + + constructor(entity) { + super(entity, new PinTemplate()); + /** @type {import("../entity/PinEntity").default} */ + this.entity; + } + + connectedCallback() { + super.connectedCallback(); + } + + /** + * + * @returns {String} + */ + getPinDisplayName() { + return this.entity.PinName + } + + getAttributes() { + return PinEntity.attributes + } + + isInput() { + return this.entity.isInput() + } + + isOutput() { + return this.entity.isOutput() + } + + isConnected() { + return this.entity.isConnected() + } + + getType() { + return this.entity.getType() + } +} + +customElements.define("u-pin", GraphPin); + /** * @typedef {import("../graph/GraphNode").default} GraphNode */ @@ -1078,12 +1147,6 @@ class NodeTemplate extends SelectableDraggableTemplate { */ header(node) { return html` -