Make elements default constructible, testing wip

This commit is contained in:
barsdeveloper
2022-12-24 15:29:12 +01:00
parent 7ed36f21e5
commit c3ab6478b0
53 changed files with 992 additions and 712 deletions

View File

@@ -17,11 +17,11 @@ export default class Copy extends IInput {
}
listenEvents() {
document.body.addEventListener("copy", this.#copyHandler)
window.addEventListener("copy", this.#copyHandler)
}
unlistenEvents() {
document.body.removeEventListener("copy", this.#copyHandler)
window.removeEventListener("copy", this.#copyHandler)
}
copied() {

View File

@@ -2,7 +2,10 @@ import ElementFactory from "../../element/ElementFactory"
import IInput from "../IInput"
import ObjectSerializer from "../../serialization/ObjectSerializer"
/** @typedef {import("../../element/NodeElement").default} NodeElement */
/**
* @typedef {import("../../element/NodeElement").default} NodeElement
* @typedef {import("../../element/NodeElement").NodeElementConstructor} NodeElementConstructor
*/
export default class Paste extends IInput {
@@ -20,11 +23,11 @@ export default class Paste extends IInput {
}
listenEvents() {
document.body.addEventListener("paste", this.#pasteHandle)
window.addEventListener("paste", this.#pasteHandle)
}
unlistenEvents() {
document.body.removeEventListener("paste", this.#pasteHandle)
window.removeEventListener("paste", this.#pasteHandle)
}
pasted(value) {
@@ -33,8 +36,8 @@ export default class Paste extends IInput {
let count = 0
let nodes = Paste.#serializer.readMultiple(value).map(entity => {
/** @type {NodeElement} */
// @ts-expect-error
let node = new (ElementFactory.getConstructor("ueb-node"))(entity)
let node = /** @type {NodeElementConstructor} */(ElementFactory.getConstructor("ueb-node"))
.newObject(entity)
top += node.locationY
left += node.locationX
++count

View File

@@ -3,8 +3,9 @@ import ElementFactory from "../../element/ElementFactory"
import IMouseClickDrag from "./IMouseClickDrag"
/**
* @typedef {import("../../element/PinElement").default} PinElement
* @typedef {import("../../element/LinkElement").default} LinkElement
* @typedef {import("../../element/LinkElement").LinkElementConstructor} LinkElementConstructor
* @typedef {import("../../element/PinElement").default} PinElement
* @typedef {import("../../template/node/KnotNodeTemplate").default} KnotNodeTemplate
*/
@@ -71,8 +72,8 @@ export default class MouseCreateLink extends IMouseClickDrag {
this.#knotPin = this.target
}
/** @type {LinkElement} */
// @ts-expect-error
this.link = new (ElementFactory.getConstructor("ueb-link"))(this.target, null)
this.link = /** @type {LinkElementConstructor} */(ElementFactory.getConstructor("ueb-link"))
.newObject(this.target, null)
this.blueprint.linksContainerElement.prepend(this.link)
this.link.setMessagePlaceNode()
this.#listenedPins = this.blueprint.querySelectorAll("ueb-pin")