diff --git a/dist/ueblueprint.js b/dist/ueblueprint.js index d728a44..bbb1e9f 100755 --- a/dist/ueblueprint.js +++ b/dist/ueblueprint.js @@ -611,7 +611,10 @@ class SelectorElement extends IElement { customElements.define(SelectorElement.tagName, SelectorElement); -/** @typedef {import("../Blueprint").default} Blueprint */ +/** + * @typedef {import("../Blueprint").default} Blueprint + * @typedef {import("../entity/PinReferenceEntity").default} PinReferenceEntity + */ class BlueprintTemplate extends ITemplate { header(element) { return html` @@ -730,6 +733,18 @@ class BlueprintTemplate extends ITemplate { applyEndDragScrolling(blueprint) { blueprint.dataset.dragScrolling = false; } + + /** + * + * @param {Blueprint} blueprint + * @param {PinReferenceEntity} pinReference + * @returns + */ + getPin(blueprint, pinReference) { + return blueprint.querySelector( + `ueb-node[data-name="${pinReference.objectName}"] ueb-pin[data-id="${pinReference.pinGuid}"]` + ) + } } class IContext { @@ -2275,38 +2290,6 @@ class MouseTracking extends IPointing { } } -/** - * @template Key - * @template Value - */ -class MultiKeyWeakMap { - - map = new WeakMap() - - constructor() { - return new Proxy(this.map, this) - } - - /** - * @param {WeakMap} target - * @param {Key} p - * @param {*} receiver - * @returns {Value} - */ - get(target, p, receiver) { - return Utility.objectGet(target, p) - } - - /** - * @param {WeakMap} target - * @param {Key} p - * @param {Value} value - */ - set(target, p, value) { - return Utility.objectSet(target, p, value, true, WeakMap) - } -} - /** * @typedef {import("../../element/ISelectableDraggableElement").default} ISelectableDraggableElement */ @@ -2669,6 +2652,7 @@ class PinTemplate extends ITemplate { "ueb-node-" + (pin.isInput() ? "input" : pin.isOutput() ? "output" : "hidden"), "ueb-pin-" + sanitizeText(pin.getType()) ); + pin.dataset.id = pin.GetPinIdValue(); pin.clickableElement = pin; window.customElements.whenDefined("ueb-node").then(pin.nodeElement = pin.closest("ueb-node")); pin.getLinks().forEach(pinReference => { @@ -2742,12 +2726,12 @@ class PinElement extends IElement { ] } - /** @type {GuidEntity} */ + /** @return {GuidEntity} */ GetPinId() { return this.entity.PinId } - /** @type {GuidEntity} */ + /** @return {String} */ GetPinIdValue() { return this.GetPinId().value } @@ -2895,6 +2879,7 @@ class NodeTemplate extends SelectableDraggableTemplate { if (node.selected) { node.classList.add("ueb-selected"); } + node.dataset.name = node.getNodeName(); node.style.setProperty("--ueb-position-x", sanitizeText(node.location[0])); node.style.setProperty("--ueb-position-y", sanitizeText(node.location[1])); /** @type {HTMLElement} */ @@ -3146,27 +3131,13 @@ class Zoom extends IMouseWheel { } /** - * @typedef {import("./entity/GuidEntity").default} GuidEntity * @typedef {import("./element/PinElement").default} PinElement + * @typedef {import("./entity/GuidEntity").default} GuidEntity + * @typedef {import("./entity/PinReferenceEntity").default} PinReferenceEntity */ class Blueprint extends IElement { static tagName = "ueb-blueprint" - /** @type {MultiKeyWeakMap} */ - #pinGuidMap = new Proxy(new MultiKeyWeakMap(), { - get(target, p, receiver) { - if (p instanceof PinReferenceEntity) { - p = [p.objectName, p.pinGuid]; - } - return Reflect.get(target, p) - }, - set(target, p, value) { - if (p instanceof PinReferenceEntity) { - p = [p.objectName, p.pinGuid]; - } - return Reflect.set(target, p, value) - } - }) /** @type {number} */ gridSize = Configuration.gridSize /** @type {NodeElement[]}" */ @@ -3451,7 +3422,7 @@ class Blueprint extends IElement { * @param {PinReferenceEntity} pinReference */ getPin(pinReference) { - return this.#pinGuidMap[pinReference] + return this.template.getPin(this, pinReference) } /** @@ -3492,14 +3463,6 @@ class Blueprint extends IElement { const intoArray = element => { if (element instanceof NodeElement) { this.nodes.push(element); - element.getPinElements().forEach( - pinElement => this.#pinGuidMap[ - new PinReferenceEntity({ - objectName: pinElement.getNodeElement().getNodeName(), - pinGuid: pinElement.GetPinId(), - }) - ] = pinElement - ); } else if (element instanceof LinkElement) { this.links.push(element); } diff --git a/js/Blueprint.js b/js/Blueprint.js index b345db3..1d4d415 100755 --- a/js/Blueprint.js +++ b/js/Blueprint.js @@ -7,7 +7,6 @@ import KeyboardSelectAll from "./input/keybaord/KeyboardSelectAll" import LinkElement from "./element/LinkElement" import MouseScrollGraph from "./input/mouse/MouseScrollGraph" import MouseTracking from "./input/mouse/MouseTracking" -import MultiKeyWeakMap from "./MultiKeyMap" import NodeElement from "./element/NodeElement" import Paste from "./input/common/Paste" import Select from "./input/mouse/Select" @@ -15,30 +14,15 @@ import SelectorElement from "./element/SelectorElement" import Unfocus from "./input/mouse/Unfocus" import Utility from "./Utility" import Zoom from "./input/mouse/Zoom" -import PinReferenceEntity from "./entity/PinReferenceEntity" /** - * @typedef {import("./entity/GuidEntity").default} GuidEntity * @typedef {import("./element/PinElement").default} PinElement + * @typedef {import("./entity/GuidEntity").default} GuidEntity + * @typedef {import("./entity/PinReferenceEntity").default} PinReferenceEntity */ export default class Blueprint extends IElement { static tagName = "ueb-blueprint" - /** @type {MultiKeyWeakMap} */ - #pinGuidMap = new Proxy(new MultiKeyWeakMap(), { - get(target, p, receiver) { - if (p instanceof PinReferenceEntity) { - p = [p.objectName, p.pinGuid] - } - return Reflect.get(target, p) - }, - set(target, p, value) { - if (p instanceof PinReferenceEntity) { - p = [p.objectName, p.pinGuid] - } - return Reflect.set(target, p, value) - } - }) /** @type {number} */ gridSize = Configuration.gridSize /** @type {NodeElement[]}" */ @@ -323,7 +307,7 @@ export default class Blueprint extends IElement { * @param {PinReferenceEntity} pinReference */ getPin(pinReference) { - return this.#pinGuidMap[pinReference] + return this.template.getPin(this, pinReference) } /** @@ -364,14 +348,6 @@ export default class Blueprint extends IElement { const intoArray = element => { if (element instanceof NodeElement) { this.nodes.push(element) - element.getPinElements().forEach( - pinElement => this.#pinGuidMap[ - new PinReferenceEntity({ - objectName: pinElement.getNodeElement().getNodeName(), - pinGuid: pinElement.GetPinId(), - }) - ] = pinElement - ) } else if (element instanceof LinkElement) { this.links.push(element) } diff --git a/js/MultiKeyMap.js b/js/MultiKeyMap.js deleted file mode 100644 index 7b72e72..0000000 --- a/js/MultiKeyMap.js +++ /dev/null @@ -1,33 +0,0 @@ -import Utility from "./Utility" - -/** - * @template Key - * @template Value - */ -export default class MultiKeyWeakMap { - - map = new WeakMap() - - constructor() { - return new Proxy(this.map, this) - } - - /** - * @param {WeakMap} target - * @param {Key} p - * @param {*} receiver - * @returns {Value} - */ - get(target, p, receiver) { - return Utility.objectGet(target, p) - } - - /** - * @param {WeakMap} target - * @param {Key} p - * @param {Value} value - */ - set(target, p, value) { - return Utility.objectSet(target, p, value, true, WeakMap) - } -} \ No newline at end of file diff --git a/js/element/PinElement.js b/js/element/PinElement.js index 909157d..0d216ee 100644 --- a/js/element/PinElement.js +++ b/js/element/PinElement.js @@ -41,12 +41,12 @@ export default class PinElement extends IElement { ] } - /** @type {GuidEntity} */ + /** @return {GuidEntity} */ GetPinId() { return this.entity.PinId } - /** @type {GuidEntity} */ + /** @return {String} */ GetPinIdValue() { return this.GetPinId().value } diff --git a/js/template/BlueprintTemplate.js b/js/template/BlueprintTemplate.js index 1536ec9..049fbf3 100755 --- a/js/template/BlueprintTemplate.js +++ b/js/template/BlueprintTemplate.js @@ -4,7 +4,10 @@ import ITemplate from "./ITemplate" import sanitizeText from "./sanitizeText" import SelectorElement from "../element/SelectorElement" -/** @typedef {import("../Blueprint").default} Blueprint */ +/** + * @typedef {import("../Blueprint").default} Blueprint + * @typedef {import("../entity/PinReferenceEntity").default} PinReferenceEntity + */ export default class BlueprintTemplate extends ITemplate { header(element) { return html` @@ -123,4 +126,16 @@ export default class BlueprintTemplate extends ITemplate { applyEndDragScrolling(blueprint) { blueprint.dataset.dragScrolling = false } + + /** + * + * @param {Blueprint} blueprint + * @param {PinReferenceEntity} pinReference + * @returns + */ + getPin(blueprint, pinReference) { + return blueprint.querySelector( + `ueb-node[data-name="${pinReference.objectName}"] ueb-pin[data-id="${pinReference.pinGuid}"]` + ) + } } diff --git a/js/template/NodeTemplate.js b/js/template/NodeTemplate.js index f4b6fda..cc587d6 100755 --- a/js/template/NodeTemplate.js +++ b/js/template/NodeTemplate.js @@ -41,6 +41,7 @@ export default class NodeTemplate extends SelectableDraggableTemplate { if (node.selected) { node.classList.add("ueb-selected") } + node.dataset.name = node.getNodeName() node.style.setProperty("--ueb-position-x", sanitizeText(node.location[0])) node.style.setProperty("--ueb-position-y", sanitizeText(node.location[1])) /** @type {HTMLElement} */ diff --git a/js/template/PinTemplate.js b/js/template/PinTemplate.js index 2addee4..090c425 100755 --- a/js/template/PinTemplate.js +++ b/js/template/PinTemplate.js @@ -39,6 +39,7 @@ export default class PinTemplate extends ITemplate { "ueb-node-" + (pin.isInput() ? "input" : pin.isOutput() ? "output" : "hidden"), "ueb-pin-" + sanitizeText(pin.getType()) ) + pin.dataset.id = pin.GetPinIdValue() pin.clickableElement = pin window.customElements.whenDefined("ueb-node").then(pin.nodeElement = pin.closest("ueb-node")) pin.getLinks().forEach(pinReference => {