Files
ueblueprint/js/template/pin/EnumPinTemplate.js
BarsDev 6ba2705386 Large refactoring and new nodes
* Fix node reference when changing elements

* Fix ScriptVariables parsing

* Fix invariant text and niagara types

* Niagara convert nodes

* Move node tests to own files

* More Niagara tests

* Niagara float and smaller fixes

* More Decoding

* More decoding

* WIP

* Float is real

* WIP

* More types and colors

* Test case and small polish

* WIP

* WIP

* Fix niagara script variables merging

* Fix Niagara variables

* Fixing mirrored ExportPath

* Fix Export paths name adjustments

* Simplify arc calculation

* Simplify a bit arc calculation

* source / destionation => origin / target

* Minor refactoring

* Fix switched link position

* Rename some properties for uniformity

* Fix input escape

* Simplify test

* About window

* Dialog backdrop style

* About dialog touches

* Remove dependency and minot improvement

* Light mode

* Fix link location and css small improvement

* Link direction and minor fixes

* Some minor fixes and refactoring

* Refactoring WIP

* Shorting repetitive bits

* More tests

* Simplify linking tests
2025-02-07 00:36:03 +02:00

78 lines
2.5 KiB
JavaScript
Executable File

import { html } from "lit"
import Configuration from "../../Configuration.js"
import StringEntity from "../../entity/StringEntity.js"
import Utility from "../../Utility.js"
import IInputPinTemplate from "./IInputPinTemplate.js"
/** @extends IInputPinTemplate<EnumEntity> */
export default class EnumPinTemplate extends IInputPinTemplate {
static saveEachInputChange = true // Otherwise save only on focus out
/** @type {DropdownElement} */
#dropdownElement
#dropdownEntries = []
setup() {
super.setup()
const enumEntries = this.element.nodeElement.entity.EnumEntries?.valueOf()
this.#dropdownEntries =
enumEntries?.map(k => {
if (k.valueOf() === "") {
k = new StringEntity("None")
}
return [
k,
this.element.nodeElement.getPinEntities().find(pinEntity => k === pinEntity.PinName)
?.PinFriendlyName.toString()
?? k
]
})
?? Configuration.CommonEnums[this.element.entity.getSubCategory()]?.map(k =>
k instanceof Array
? k
: [k, Utility.formatStringName(k)]
)
?? []
const defaultEntry = this.element.getDefaultValue()?.toString()
if (!this.#dropdownEntries.find(([k, v]) => k === defaultEntry)) {
this.#dropdownEntries.push([defaultEntry, Utility.formatStringName(defaultEntry)])
}
this.element.requestUpdate()
}
renderInput() {
return html`
<ueb-dropdown
class="ueb-pin-input-wrapper ueb-pin-input"
.options="${this.#dropdownEntries}"
.selectedOption="${this.element.defaultValue}"
>
</ueb-dropdown>
`
}
/** @param {PropertyValues} changedProperties */
firstUpdated(changedProperties) {
super.firstUpdated(changedProperties)
this.#dropdownElement = this.element.querySelector("ueb-dropdown")
}
getInputs() {
return [this.#dropdownElement.getValue()]
}
/**
* @this {EnumPinTemplate}
* @param {String[]} values
* @param {String[]} rawValues
*/
setDefaultValue(values = [], rawValues) {
const value = this.element.getDefaultValue()
value.value = values[0]
this.element.setDefaultValue(value)
this.element.requestUpdate()
}
}