Files
ueblueprint/js/template/pin/DropdownTemplate.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

63 lines
2.2 KiB
JavaScript
Executable File

import { html } from "lit"
import MouseIgnore from "../../input/mouse/MouseIgnore.js"
import ITemplate from "../ITemplate.js"
/** @extends {ITemplate<DropdownElement>} */
export default class DropdownTemplate extends ITemplate {
/** @type {HTMLSelectElement} */
#selectElement
/** @type {HTMLSelectElement} */
#referenceSelectElement
#changeHandler = e => this.element.selectedOption = /** @type {HTMLSelectElement} */(e.target)
.selectedOptions[0]
.value
render() {
return html`
<select class="ueb-pin-input-content" @change="${this.#changeHandler}">
${this.element.options.map(([k, v]) => html`
<option value="${k}" ?selected="${k === this.element.selectedOption}">${v}</option>
`)}
</select>
<select style="visibility: hidden; position: fixed;">
<option>${this.element.selectedOption}</option>
</select>
`
}
/** @param {PropertyValues} changedProperties */
firstUpdated(changedProperties) {
super.firstUpdated(changedProperties)
this.#selectElement = this.element.querySelector("select:first-child")
this.#referenceSelectElement = this.element.querySelector("select:last-child")
const event = new Event("input", { bubbles: true })
this.#selectElement.dispatchEvent(event)
}
/** @param {PropertyValues} changedProperties */
updated(changedProperties) {
super.updated(changedProperties)
const bounding = this.#referenceSelectElement.getBoundingClientRect()
this.element.style.setProperty("--ueb-dropdown-width", bounding.width + "px")
}
createInputObjects() {
return [
...super.createInputObjects(),
// Prevents creating links when selecting text and other undesired mouse actions detection
new MouseIgnore(this.element, this.blueprint),
]
}
setSelectedValue(value) {
/** @type {HTMLOptionElement} */(this.element.querySelector(`option[value="${value}"]`)).defaultSelected = true
}
getSelectedValue() {
return this.#selectElement.value
}
}