IContext > IInput

This commit is contained in:
barsdeveloper
2022-04-14 23:04:44 +02:00
parent d6aa7b22d2
commit 796deac851
9 changed files with 43 additions and 29 deletions

View File

@@ -3,7 +3,7 @@
/**
* @typedef {import("../Blueprint").default} Blueprint
* @typedef {import("../entity/IEntity").default} IEntity
* @typedef {import("../input/IContext").default} IContext
* @typedef {import("../input/IInput").default} IInput
* @typedef {import("../template/ITemplate").default} ITemplate
*/
@@ -40,7 +40,7 @@ export default class IElement extends HTMLElement {
this.#template = template
}
/** @type {IContext[]} */
/** @type {IInput[]} */
inputObjects = []
/**
@@ -61,11 +61,9 @@ export default class IElement extends HTMLElement {
connectedCallback() {
this.#blueprint = this.closest("ueb-blueprint")
this.template.setup(this)
this.inputObjects = this.createInputObjects()
}
disconnectedCallback() {
this.inputObjects.forEach(v => v.unlistenDOMElement())
this.template.cleanup(this)
}
@@ -77,7 +75,7 @@ export default class IElement extends HTMLElement {
}
/**
* @template {IContext} V
* @template {IInput} V
* @param {new (...args: any[]) => V} type
* @returns {V}
*/

View File

@@ -9,7 +9,7 @@ import Configuration from "../Configuration"
/**
* @template {HTMLElement} T
*/
export default class IContext {
export default class IInput {
/** @type {T} */
#target

View File

@@ -1,9 +1,9 @@
// @ts-check
import IContext from "../IContext"
import IInput from "../IInput"
import ObjectSerializer from "../../serialization/ObjectSerializer"
export default class Copy extends IContext {
export default class Copy extends IInput {
/** @type {(e: ClipboardEvent) => void} */
#copyHandler

View File

@@ -1,10 +1,10 @@
// @ts-check
import IContext from "../IContext"
import IInput from "../IInput"
import NodeElement from "../../element/NodeElement"
import ObjectSerializer from "../../serialization/ObjectSerializer"
export default class Paste extends IContext {
export default class Paste extends IInput {
/** @type {(e: ClipboardEvent) => void} */
#pasteHandle

View File

@@ -1,11 +1,11 @@
// @ts-check
import Configuration from "../../Configuration"
import IContext from "../IContext"
import IInput from "../IInput"
import ISerializer from "../../serialization/ISerializer"
import KeyBindingEntity from "../../entity/KeyBindingEntity"
export default class IKeyboardShortcut extends IContext {
export default class IKeyboardShortcut extends IInput {
/** @type {KeyBindingEntity[]} */
#activationKeys

View File

@@ -1,6 +1,6 @@
// @ts-check
import IContext from "../IContext"
import IInput from "../IInput"
import Utility from "../../Utility"
/**
@@ -9,9 +9,9 @@ import Utility from "../../Utility"
/**
* @template {HTMLElement} T
* @extends {IContext<T>}
* @extends {IInput<T>}
*/
export default class IPointing extends IContext {
export default class IPointing extends IInput {
constructor(target, blueprint, options) {
super(target, blueprint, options)

View File

@@ -1,8 +1,8 @@
// @ts-check
import IContext from "../IContext"
import IInput from "../IInput"
export default class Unfocus extends IContext {
export default class Unfocus extends IInput {
/** @type {(e: MouseEvent) => void} */
#clickHandler

View File

@@ -9,6 +9,9 @@
*/
export default class ITemplate {
/** @type {Object[]} */
inputObjects = []
/**
* @param {T} entity
*/
@@ -22,11 +25,17 @@ export default class ITemplate {
setup(element) {
// TODO replace with the safer element.setHTML(...) when it will be availableBreack
element.innerHTML = this.render(element)
this.inputObjects = this.createInputObjects()
}
/**
* @param {T} element
*/
cleanup(element) {
this.inputObjects.forEach(v => v.unlistenDOMElement())
}
createInputObjects() {
return []
}
}