import { html, nothing } from "lit" import Configuration from "../../Configuration" import ElementFactory from "../../element/ElementFactory" import ISelectableDraggableTemplate from "../ISelectableDraggableTemplate" import SVGIcon from "../../SVGIcon" import Utility from "../../Utility" /** * @typedef {import("../../element/NodeElement").default} NodeElement * @typedef {import("../../element/PinElement").default} PinElement * @typedef {import("../../element/PinElement").PinElementConstructor} PinElementConstructor * @typedef {import("lit").PropertyValues} PropertyValues */ /** @extends {ISelectableDraggableTemplate} */ export default class NodeTemplate extends ISelectableDraggableTemplate { /** @typedef {typeof NodeTemplate} NodeTemplateConstructor */ hasSubtitle = false static nodeStyleClasses = ["ueb-node-style-default"] toggleAdvancedDisplayHandler = () => { this.element.toggleShowAdvancedPinDisplay() this.element.addNextUpdatedCallbacks(() => this.element.acknowledgeReflow(), true) } /** @param {NodeElement} element */ initialize(element) { super.initialize(element) this.element.classList.add(.../** @type {NodeTemplateConstructor} */(this.constructor).nodeStyleClasses) this.element.style.setProperty("--ueb-node-color", this.getColor().cssText) } getColor() { return Configuration.nodeColor(this.element) } render() { return html` ${this.renderTop()} ${this.element.enabledState?.toString() == "DevelopmentOnly" ? html` Development Only ` : nothing} ${this.element.advancedPinDisplay ? html` ${SVGIcon.expandIcon} ` : nothing} ` } renderNodeIcon() { return Configuration.nodeIcon(this.element) } renderNodeName() { return this.element.getNodeDisplayName() } renderTop() { const icon = this.renderNodeIcon() const name = this.renderNodeName() return html` ${icon ? html` ${icon} ` : nothing} ${name ? html` ${name} ${this.hasSubtitle && this.element.entity.FunctionReference.MemberParent ? html` Target is ${Utility.formatStringName(this.element.entity.FunctionReference.MemberParent.getName())} `: nothing} ` : nothing} ` } /** @param {PropertyValues} changedProperties */ firstUpdated(changedProperties) { super.firstUpdated(changedProperties) this.setupPins() this.element.updateComplete.then(() => this.element.acknowledgeReflow()) } setupPins() { const inputContainer = /** @type {HTMLElement} */(this.element.querySelector(".ueb-node-inputs")) const outputContainer = /** @type {HTMLElement} */(this.element.querySelector(".ueb-node-outputs")) this.element.nodeNameElement = /** @type {HTMLElement} */(this.element.querySelector(".ueb-node-name-text")) this.element.getPinElements().forEach(p => { if (p.isInput()) { inputContainer.appendChild(p) } else if (p.isOutput()) { outputContainer.appendChild(p) } }) } createPinElements() { return this.element.getPinEntities() .filter(v => !v.isHidden()) .map(pinEntity => { this.hasSubtitle = this.hasSubtitle || pinEntity.getDisplayName() === "Target" let pinElement = /** @type {PinElementConstructor} */(ElementFactory.getConstructor("ueb-pin")) .newObject(pinEntity, undefined, this.element) return pinElement }) } /** * @param {NodeElement} node * @returns {NodeListOf} */ getPinElements(node) { return node.querySelectorAll("ueb-pin") } linksChanged() { } }