import html from "./html" import PinEntity from "../entity/PinEntity" import SelectableDraggableTemplate from "./SelectableDraggableTemplate" /** * @typedef {import("../graph/GraphNode").default} GraphNode */ export default class NodeTemplate extends SelectableDraggableTemplate { /** * Computes the html content of the target element. * @param {GraphNode} node Graph node element * @returns The result html */ header(node) { return html`
${node.entity.getNodeDisplayName()}
` } /** * Computes the html content of the target element. * @param {GraphNode} node Graph node element * @returns The result html */ body(node) { /** @type {PinEntity[]} */ let inputs = node.entity.CustomProperties.filter(v => v instanceof PinEntity) let outputs = inputs.filter(v => v.isOutput()) inputs = inputs.filter(v => v.isInput()) return html`
${inputs.map((input, index) => html`
${input.getPinDisplayName()}
`).join("") ?? ""}
${outputs.map((output, index) => html`
${output.getPinDisplayName()}
`).join('') ?? ''}
` } /** * Computes the html content of the target element. * @param {GraphNode} node Graph node element * @returns The result html */ render(node) { return html`
${this.header(node)} ${this.body(node)}
` } /** * Returns the html elements rendered from this template. * @param {GraphNode} node Element of the graph */ apply(node) { super.apply(node) node.classList.add("ueb-node") if (node.selected) { node.classList.add("ueb-selected") } node.style.setProperty("--ueb-position-x", node.location[0]) node.style.setProperty("--ueb-position-y", node.location[1]) } }