Input system cleanup

This commit is contained in:
barsdeveloper
2022-11-10 22:43:47 +01:00
parent 101071f137
commit 18bf858db3
16 changed files with 183 additions and 170 deletions

View File

@@ -73,8 +73,8 @@ export default class ColorPickerWindowTemplate extends WindowTemplate {
/** @param {KeyboardEvent} e */
e => {
if (e.code == "Enter") {
action(e)
e.preventDefault()
action(e)
}
}
@@ -341,21 +341,21 @@ export default class ColorPickerWindowTemplate extends WindowTemplate {
<div class="ueb-color-control">
<span class="ueb-color-control-label">Hex Linear</span>
<div class="ueb-color-picker-hex-linear ueb-text-input">
<span class="ueb-pin-input-content" role="textbox" contenteditable="true"
<ueb-input
.innerText="${colorRGB}"
@focusout="${this.#hexRGBHandler}"
@keydown="${this.#doOnEnter(this.#hexRGBHandler)}">
</span>
</ueb-input>
</div>
</div>
<div class="ueb-color-control">
<span class="ueb-color-control-label">Hex sRGB</span>
<div class="ueb-color-picker-hex-srgb ueb-text-input">
<span class="ueb-pin-input-content" role="textbox" contenteditable="true"
<ueb-input
.innerText="${colorSRGB}"
@focusout="${this.#hexSRGBHandler}"
@keydown="${this.#doOnEnter(this.#hexSRGBHandler)}">
</span>
</ueb-input>
</div>
</div>
</div>

View File

@@ -1,8 +1,7 @@
import { html } from "lit"
import { html, nothing } from "lit"
import MouseIgnore from "../input/mouse/MouseIgnore"
import PinTemplate from "./PinTemplate"
import Utility from "../Utility"
/**
* @template T
* @typedef {import("../element/PinElement").default<T>} PinElement
@@ -34,19 +33,16 @@ export default class IInputPinTemplate extends PinTemplate {
.replace(/(?<=\n\s*)$/, "\n") // Put back trailing double newline
}
#onFocusOutHandler = () => this.setInputs(this.getInputs(), true)
/** @param {Map} changedProperties */
firstUpdated(changedProperties) {
super.firstUpdated(changedProperties)
this.#inputContentElements = /** @type {HTMLElement[]} */([...this.element.querySelectorAll("ueb-input")])
if (this.#inputContentElements.length) {
this.setInputs(this.getInputs(), false)
let self = this
this.onFocusOutHandler = e => {
e.preventDefault()
self.setInputs(this.getInputs(), true)
}
this.#inputContentElements.forEach(element => {
element.addEventListener("focusout", this.onFocusOutHandler)
element.addEventListener("focusout", this.#onFocusOutHandler)
})
}
}
@@ -54,7 +50,7 @@ export default class IInputPinTemplate extends PinTemplate {
cleanup() {
super.cleanup()
this.#inputContentElements.forEach(element => {
element.removeEventListener("focusout", this.onFocusOutHandler)
element.removeEventListener("focusout", this.#onFocusOutHandler)
})
}
@@ -100,6 +96,6 @@ export default class IInputPinTemplate extends PinTemplate {
</div>
`
}
return html``
return nothing
}
}

View File

@@ -3,6 +3,7 @@ import { css, nothing } from "lit"
/**
* @typedef {import("../element/IElement").default} IElement
* @typedef {import("../input/IInput").default} IInput
* @typedef {import("lit").TemplateResult<1>} TemplateResult
*/
/** @template {IElement} T */
@@ -40,6 +41,7 @@ export default class ITemplate {
update(changedProperties) {
}
/** @returns {TemplateResult | symbol} */
render() {
return nothing
}

View File

@@ -1,4 +1,3 @@
import FocusTextEdit from "../input/common/FocusTextEdit"
import ITemplate from "./ITemplate"
/** @typedef {import ("../element/InputElement").default} InputElement */
@@ -6,18 +5,49 @@ import ITemplate from "./ITemplate"
/** @extends {ITemplate<InputElement>} */
export default class InputTemplate extends ITemplate {
createInputObjects() {
return [
...super.createInputObjects(),
new FocusTextEdit(this.element, this.element.blueprint),
]
#focusHandler = () => this.element.blueprint.dispatchEditTextEvent(true)
#focusoutHandler = () => {
this.element.blueprint.dispatchEditTextEvent(false)
document.getSelection()?.removeAllRanges() // Deselect eventually selected text inside the input
}
#inputSingleLineHandler =
/** @param {InputEvent} e */
e => /** @type {HTMLElement} */(e.target).querySelectorAll("br").forEach(br => br.remove())
#onKeydownBlurOnEnterHandler =
/** @param {KeyboardEvent} e */
e => {
if (e.code == "Enter" && !e.shiftKey) {
/** @type {HTMLElement} */(e.target).blur()
}
}
/** @param {Map} changedProperties */
firstUpdated(changedProperties) {
super.firstUpdated(changedProperties)
/** @param {InputElement} element */
constructed(element) {
super.constructed(element)
this.element.classList.add("ueb-pin-input-content")
this.element.setAttribute("role", "textbox")
this.element.contentEditable = "true"
}
}
connectedCallback() {
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() {
this.element.removeEventListener("focus", this.#focusHandler)
this.element.removeEventListener("focusout", this.#focusoutHandler)
if (this.element.singleLine) {
this.element.removeEventListener("input", this.#inputSingleLineHandler)
}
if (this.element.blurOnEnter) {
this.element.removeEventListener("keydown", this.#onKeydownBlurOnEnterHandler)
}
}
}

View File

@@ -1,10 +1,11 @@
import { html } from "lit"
import { html, nothing } from "lit"
import ITemplate from "./ITemplate"
import MouseCreateLink from "../input/mouse/MouseCreateLink"
import Utility from "../Utility"
/**
* @typedef {import("../input/IInput").default} IInput
* @typedef {import("lit").TemplateResult} TemplateResult
*/
/**
* @template T
@@ -50,6 +51,7 @@ export default class PinTemplate extends ITemplate {
`
}
/** @returns {TemplateResult | symbol} */
renderIcon() {
return html`
<svg viewBox="0 0 32 32" xmlns="http://www.w3.org/2000/svg">
@@ -59,8 +61,9 @@ export default class PinTemplate extends ITemplate {
`
}
/** @returns {TemplateResult | symbol} */
renderInput() {
return html``
return nothing
}
/** @param {Map} changedProperties */

View File

@@ -17,7 +17,7 @@ export default class RealPinTemplate extends INumericPinTemplate {
if (this.element.isInput()) {
return html`
<div class="ueb-pin-input">
<ueb-input
<ueb-input .singleLine="${true}"
.innerText="${IInputPinTemplate.stringFromUEToInput(Utility.minDecimals(this.element.entity.DefaultValue))}">
</ueb-input>
</div>

View File

@@ -1,9 +1,12 @@
import { html } from "lit"
import { html, nothing } from "lit"
import Configuration from "../Configuration"
import IDraggablePositionedTemplate from "./IDraggablePositionedTemplate"
import MouseMoveDraggable from "../input/mouse/MouseMoveDraggable"
/** @typedef {import("../element/WindowElement").default} WindowElement */
/**
* @typedef {import("../element/WindowElement").default} WindowElement
* @typedef {import("lit").TemplateResult<1>} TemplateResult
*/
/** @extends {IDraggablePositionedTemplate<WindowElement>} */
export default class WindowTemplate extends IDraggablePositionedTemplate {
@@ -46,8 +49,9 @@ export default class WindowTemplate extends IDraggablePositionedTemplate {
return html`Window`
}
/** @returns {TemplateResult | symbol} */
renderContent() {
return html``
return nothing
}
apply() {