Input cleanup

This commit is contained in:
barsdeveloper
2022-11-11 20:31:17 +01:00
parent 18bf858db3
commit 48065a4777
12 changed files with 91 additions and 112 deletions

View File

@@ -4,42 +4,5 @@ import IInputPinTemplate from "./IInputPinTemplate"
export default class NamePinTemplate extends IInputPinTemplate {
/** @type {(e : InputEvent) => void} */
onInputHandler
/** @param {Map} changedProperties */
firstUpdated(changedProperties) {
super.firstUpdated(changedProperties)
this.onInputHandler = e => {
e.stopPropagation()
if (
e.inputType == "insertParagraph"
|| e.inputType == "insertLineBreak"
|| (e.inputType == "insertFromPaste" && /** @type {HTMLElement} */(e.target).innerText.includes("\n"))
) {
/** @type {HTMLElement} */(e.target).blur() // Loose focus in case it tries to insert newline
this.inputContentElements.forEach(element => element.innerText = element.innerText.replaceAll("\n", ""))
}
}
this.inputContentElements.forEach(element => {
element.addEventListener("input", /** @type {(e : Event) => void} */(this.onInputHandler))
})
}
cleanup() {
super.cleanup()
this.inputContentElements.forEach(element => {
element.removeEventListener("input", /** @type {(e : Event) => void} */(this.onInputHandler))
})
}
getInputs() {
return this.inputContentElements.map(element => element.textContent) // textContent for performance reason
}
/** @param {String[]} values */
setInputs(values = [], updateDefaultValue = true) {
values = values.map(value => value.replaceAll("\n", "")) // get rid of the new lines
super.setInputs(values, updateDefaultValue)
}
static singleLineInput = true
}