From 796deac851840cfbf25723e933716b1abddee7ae Mon Sep 17 00:00:00 2001 From: barsdeveloper Date: Thu, 14 Apr 2022 23:04:44 +0200 Subject: [PATCH] IContext > IInput --- dist/ueblueprint.js | 31 ++++++++++++++++---------- js/element/IElement.js | 8 +++---- js/input/{IContext.js => IInput.js} | 2 +- js/input/common/Copy.js | 4 ++-- js/input/common/Paste.js | 4 ++-- js/input/keybaord/IKeyboardShortcut.js | 4 ++-- js/input/mouse/IPointing.js | 6 ++--- js/input/mouse/Unfocus.js | 4 ++-- js/template/ITemplate.js | 9 ++++++++ 9 files changed, 43 insertions(+), 29 deletions(-) rename js/input/{IContext.js => IInput.js} (98%) diff --git a/dist/ueblueprint.js b/dist/ueblueprint.js index c3b53c0..bdedbc9 100755 --- a/dist/ueblueprint.js +++ b/dist/ueblueprint.js @@ -163,6 +163,9 @@ const html = String.raw; */ class ITemplate { + /** @type {Object[]} */ + inputObjects = [] + /** * @param {T} entity */ @@ -176,12 +179,18 @@ 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 [] } } @@ -513,7 +522,7 @@ class FastSelectionModel { /** * @typedef {import("../Blueprint").default} Blueprint * @typedef {import("../entity/IEntity").default} IEntity - * @typedef {import("../input/IContext").default} IContext + * @typedef {import("../input/IInput").IInput} IInput * @typedef {import("../template/ITemplate").default} ITemplate */ @@ -550,7 +559,7 @@ class IElement extends HTMLElement { this.#template = template; } - /** @type {IContext[]} */ + /** @type {IInput[]} */ inputObjects = [] /** @@ -571,11 +580,9 @@ 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); } @@ -587,7 +594,7 @@ class IElement extends HTMLElement { } /** - * @template {IContext} V + * @template {IInput} V * @param {new (...args: any[]) => V} type * @returns {V} */ @@ -841,7 +848,7 @@ class BlueprintTemplate extends ITemplate { /** * @template {HTMLElement} T */ -class IContext { +class IInput { /** @type {T} */ #target @@ -1973,7 +1980,7 @@ End Object\n`; // @ts-check -class Copy extends IContext { +class Copy extends IInput { /** @type {(e: ClipboardEvent) => void} */ #copyHandler @@ -2002,7 +2009,7 @@ class Copy extends IContext { // @ts-check -class IKeyboardShortcut extends IContext { +class IKeyboardShortcut extends IInput { /** @type {KeyBindingEntity[]} */ #activationKeys @@ -2122,9 +2129,9 @@ class KeyboardCanc extends IKeyboardShortcut { /** * @template {HTMLElement} T - * @extends {IContext} + * @extends {IInput} */ -class IPointing extends IContext { +class IPointing extends IInput { constructor(target, blueprint, options) { super(target, blueprint, options); @@ -3801,7 +3808,7 @@ customElements.define("ueb-node", NodeElement); // @ts-check -class Paste extends IContext { +class Paste extends IInput { /** @type {(e: ClipboardEvent) => void} */ #pasteHandle @@ -3885,7 +3892,7 @@ class Select extends IMouseClickDrag { // @ts-check -class Unfocus extends IContext { +class Unfocus extends IInput { /** @type {(e: MouseEvent) => void} */ #clickHandler diff --git a/js/element/IElement.js b/js/element/IElement.js index 37602c8..dcbbceb 100644 --- a/js/element/IElement.js +++ b/js/element/IElement.js @@ -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} */ diff --git a/js/input/IContext.js b/js/input/IInput.js similarity index 98% rename from js/input/IContext.js rename to js/input/IInput.js index 762d6da..ce4a5d9 100644 --- a/js/input/IContext.js +++ b/js/input/IInput.js @@ -9,7 +9,7 @@ import Configuration from "../Configuration" /** * @template {HTMLElement} T */ -export default class IContext { +export default class IInput { /** @type {T} */ #target diff --git a/js/input/common/Copy.js b/js/input/common/Copy.js index c3f9d85..43adf7d 100755 --- a/js/input/common/Copy.js +++ b/js/input/common/Copy.js @@ -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 diff --git a/js/input/common/Paste.js b/js/input/common/Paste.js index b05f56c..2e3bf01 100755 --- a/js/input/common/Paste.js +++ b/js/input/common/Paste.js @@ -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 diff --git a/js/input/keybaord/IKeyboardShortcut.js b/js/input/keybaord/IKeyboardShortcut.js index 02de2cd..95fd62a 100644 --- a/js/input/keybaord/IKeyboardShortcut.js +++ b/js/input/keybaord/IKeyboardShortcut.js @@ -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 diff --git a/js/input/mouse/IPointing.js b/js/input/mouse/IPointing.js index 2b4627f..e7ef287 100644 --- a/js/input/mouse/IPointing.js +++ b/js/input/mouse/IPointing.js @@ -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} + * @extends {IInput} */ -export default class IPointing extends IContext { +export default class IPointing extends IInput { constructor(target, blueprint, options) { super(target, blueprint, options) diff --git a/js/input/mouse/Unfocus.js b/js/input/mouse/Unfocus.js index 9e57cae..99ac0ba 100755 --- a/js/input/mouse/Unfocus.js +++ b/js/input/mouse/Unfocus.js @@ -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 diff --git a/js/template/ITemplate.js b/js/template/ITemplate.js index 6803666..b21bd90 100644 --- a/js/template/ITemplate.js +++ b/js/template/ITemplate.js @@ -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 [] } }