mirror of
https://github.com/barsdeveloper/ueblueprint.git
synced 2026-02-04 08:41:34 +08:00
Refactoring and bugfixing
This commit is contained in:
@@ -1,18 +1,19 @@
|
||||
import { PinEntity } from "../../dist/ueblueprint"
|
||||
import Template from "./Template"
|
||||
|
||||
export default class NodeTemplate extends Template {
|
||||
|
||||
/**
|
||||
* Computes the html content of the target element.
|
||||
* @param {HTMLElement} element Target element
|
||||
* @param {HTMLElement} entity Entity representing the element
|
||||
* @returns The computed html
|
||||
*/
|
||||
header(element) {
|
||||
header(entity) {
|
||||
return `
|
||||
<div class="ueb-node-header">
|
||||
<span class="ueb-node-name">
|
||||
<span class="ueb-node-symbol"></span>
|
||||
<span class="ueb-node-text">${element.graphNodeName}</span>
|
||||
<span class="ueb-node-text">${entity.graphNodeName}</span>
|
||||
</span>
|
||||
</div>
|
||||
`
|
||||
@@ -20,27 +21,30 @@ export default class NodeTemplate extends Template {
|
||||
|
||||
/**
|
||||
* Computes the html content of the target element.
|
||||
* @param {HTMLElement} element Target element
|
||||
* @param {import("../entity/ObjectEntity").default} entity Entity representing the element
|
||||
* @returns The computed html
|
||||
*/
|
||||
body(element) {
|
||||
body(entity) {
|
||||
let inputs = entity.CustomProperties.filter(v => v instanceof PinEntity)
|
||||
let outputs = inputs.filter(v => v.isOutput())
|
||||
inputs = inputs.filter(v => !v.isOutput())
|
||||
return `
|
||||
<div class="ueb-node-body">
|
||||
<div class="ueb-node-inputs">
|
||||
${element.inputs.forEach((input, index) => `
|
||||
${inputs.map((input, index) => `
|
||||
<div class="ueb-node-input ueb-node-value-${input.type}">
|
||||
<span class="ueb-node-value-icon ${element.inputs[index].connected ? 'ueb-node-value-fill' : ''}"></span>
|
||||
<span class="ueb-node-value-icon ${inputs[index].connected ? 'ueb-node-value-fill' : ''}"></span>
|
||||
${input.name}
|
||||
</div>
|
||||
`) ?? ''}
|
||||
`).join("") ?? ""}
|
||||
</div>
|
||||
<div class="ueb-node-outputs">
|
||||
${element.outputs.forEach((output, index) => `
|
||||
${outputs.map((output, index) => `
|
||||
<div class="ueb-node-output ueb-node-value-${output.type}">
|
||||
${output.name}
|
||||
<span class="ueb-node-value-icon ${element.outputs[index].connected ? 'ueb-node-value-fill' : ''}"></span>
|
||||
<span class="ueb-node-value-icon ${entity.outputs[index].connected ? 'ueb-node-value-fill' : ''}"></span>
|
||||
</div>
|
||||
`) ?? ''}
|
||||
`).join("") ?? ''}
|
||||
</div>
|
||||
</div>
|
||||
`
|
||||
@@ -48,15 +52,15 @@ export default class NodeTemplate extends Template {
|
||||
|
||||
/**
|
||||
* Computes the html content of the target element.
|
||||
* @param {HTMLElement} element Target element
|
||||
* @param {HTMLElement} entity Entity representing the element
|
||||
* @returns The computed html
|
||||
*/
|
||||
render(element) {
|
||||
render(entity) {
|
||||
return `
|
||||
<div class="ueb-node-border">
|
||||
<div class="ueb-node-content">
|
||||
${this.header(element)}
|
||||
${this.body(element)}
|
||||
${this.header(entity)}
|
||||
${this.body(entity)}
|
||||
</div>
|
||||
</div>
|
||||
`
|
||||
|
||||
@@ -5,19 +5,19 @@ export default class Template {
|
||||
|
||||
/**
|
||||
* Computes the html content of the target element.
|
||||
* @param {GraphNode} element Target element
|
||||
* @param {Entity} entity Entity representing the element
|
||||
* @returns The computed html
|
||||
*/
|
||||
render(element) {
|
||||
render(entity) {
|
||||
return ``
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the html elements rendered by this template.
|
||||
* @param {GraphNode} element Target element
|
||||
* @param {GraphNode} entity Entity representing the element
|
||||
* @returns The rendered elements
|
||||
*/
|
||||
getElements(element) {
|
||||
getElements(entity) {
|
||||
let aDiv = document.createElement('div')
|
||||
aDiv.innerHTML = this.render(element)
|
||||
return aDiv.childNodes
|
||||
|
||||
Reference in New Issue
Block a user