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

75 lines
2.5 KiB
JavaScript
Executable File

import MouseIgnore from "../../input/mouse/MouseIgnore.js"
import ITemplate from "../ITemplate.js"
/** @extends {ITemplate<InputElement>} */
export default class InputTemplate extends ITemplate {
#focusHandler = () => {
this.blueprint.acknowledgeEditText(true)
if (this.element.selectOnFocus) {
getSelection().selectAllChildren(this.element)
}
}
#focusoutHandler = () => {
this.blueprint.acknowledgeEditText(false)
getSelection().removeAllRanges() // Deselect eventually selected text inside the input
}
/** @param {Event} e */
#inputSingleLineHandler = e =>
/** @type {HTMLElement} */(e.target).querySelectorAll("br").forEach(br => br.remove())
/** @param {KeyboardEvent} e */
#onKeydownBlurOnEnterHandler = e => {
if (e.code == "Enter" && !e.shiftKey) {
/** @type {HTMLElement} */(e.target).blur()
}
}
/** @param {InputElement} element */
initialize(element) {
super.initialize(element)
this.element.classList.add("ueb-pin-input-content")
this.element.setAttribute("role", "textbox")
if (this.element.contentEditable !== "false") {
this.element.contentEditable = "true"
}
}
/** @param {PropertyValues} changedProperties */
firstUpdated(changedProperties) {
super.firstUpdated(changedProperties)
const event = new Event("input", { bubbles: true })
this.element.dispatchEvent(event)
}
createInputObjects() {
return [
...super.createInputObjects(),
// Prevents creating links when selecting text and other undesired mouse actions detection
new MouseIgnore(this.element, this.blueprint),
]
}
setup() {
super.setup()
this.element.addEventListener("focus", this.#focusHandler)
this.element.addEventListener("focusout", this.#focusoutHandler)
if (this.element.singleLine) {
this.element.addEventListener("input", this.#inputSingleLineHandler)
}
if (this.element.blurOnEnter) {
this.element.addEventListener("keydown", this.#onKeydownBlurOnEnterHandler)
}
}
cleanup() {
super.cleanup()
this.element.removeEventListener("focus", this.#focusHandler)
this.element.removeEventListener("focusout", this.#focusoutHandler)
this.element.removeEventListener("input", this.#inputSingleLineHandler)
this.element.removeEventListener("keydown", this.#onKeydownBlurOnEnterHandler)
}
}