Small refactoring

This commit is contained in:
barsdeveloper
2021-12-11 23:58:40 +01:00
parent 6b02ab7e08
commit a5c4f04f2b
11 changed files with 235 additions and 150 deletions

View File

@@ -2,50 +2,35 @@ import html from "./html"
import Template from "./Template"
/**
* @typedef {import("../entity/PinEntity").default} PinEntity
* @typedef {import("../graph/GraphPin").default} GraphPin
*/
export default class PinTemplate extends Template {
/**
* Computes the template for a pin in case it is an input.
* @param {PinEntity} pin Pin entity
* @returns The result html
*/
renderInputPin(pin) {
return html`
<div class="ueb-node-input ueb-node-value-${pin.getType()}">
<span class="ueb-node-value-icon ${pin.isConnected() ? 'ueb-node-value-fill' : ''}"></span>
${pin.getPinDisplayName()}
</div>
`
}
/**
* Computes the template for a pin in case it is an output.
* @param {PinEntity} pin Pin entity
* @returns The result html
*/
renderOutputPin(pin) {
return html`
<div class="ueb-node-output ueb-node-value-${pin.getType()}">
${output.getPinDisplayName()}
<span class="ueb-node-value-icon ${pin.isConnected() ? 'ueb-node-value-fill' : ''}"></span>
</div>
`
}
/**
* Computes the html content of the pin.
* @param {PinEntity} pin Pin entity
* @param {GraphPin} pin Pin entity
* @returns The result html
*/
render(pin) {
if (pin.isInput()) {
return this.renderInputPin(pin)
return html`
<span class="ueb-node-value-icon ${pin.isConnected() ? 'ueb-node-value-fill' : ''}"></span>
${pin.getPinDisplayName()}
`
} else {
return html`
${pin.getPinDisplayName()}
<span class="ueb-node-value-icon ${pin.isConnected() ? 'ueb-node-value-fill' : ''}"></span>
`
}
if (pin.isOutput()) {
return this.renderOutputPin(pin)
}
return ""
}
}
/**
* 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())
}
}