// @ts-check import html from "./html" import PinElement from "../element/PinElement" import sanitizeText from "./sanitizeText" import SelectableDraggableTemplate from "./SelectableDraggableTemplate" /** * @typedef {import("../element/NodeElement").default} NodeElement */ export default class NodeTemplate extends SelectableDraggableTemplate { /** * Computes the html content of the target element. * @param {NodeElement} node Graph node element * @returns The result html */ render(node) { return html`
${sanitizeText(node.getNodeName())}
` } /** * Applies the style to the element. * @param {NodeElement} node Element of the graph */ apply(node) { super.apply(node) const nodeName = node.entity.getFullName() node.dataset.name = sanitizeText(nodeName) if (node.selected) { node.classList.add("ueb-selected") } if (node.entity.AdvancedPinDisplay) { node.dataset.advancedDisplay = node.entity.AdvancedPinDisplay.toString() } node.style.setProperty("--ueb-position-x", sanitizeText(node.location[0])) node.style.setProperty("--ueb-position-y", sanitizeText(node.location[1])) /** @type {HTMLElement} */ let inputContainer = node.querySelector(".ueb-node-inputs") /** @type {HTMLElement} */ let outputContainer = node.querySelector(".ueb-node-outputs") let pins = node.getPinEntities() pins.filter(v => v.isInput()).forEach(v => inputContainer.appendChild(new PinElement(v))) pins.filter(v => v.isOutput()).forEach(v => outputContainer.appendChild(new PinElement(v))) } /** * Applies the style to the element. * @param {NodeElement} node Element of the graph */ applyRename(node) { const nodeName = node.entity.getFullName() node.dataset.name = sanitizeText(nodeName) // @ts-expect-error node.querySelector(".ueb-node-name-text").innerText = sanitizeText(node.entity.getFullName()) } /** * @param {NodeElement} node * @returns {NodeListOf} */ getPinElements(node) { return node.querySelectorAll("ueb-pin") } }