mirror of
https://github.com/barsdeveloper/ueblueprint.git
synced 2026-02-15 17:54:52 +08:00
Fix pins retrieval
This commit is contained in:
83
dist/ueblueprint.js
vendored
83
dist/ueblueprint.js
vendored
@@ -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<String, PinElement>} */
|
||||
#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);
|
||||
}
|
||||
|
||||
@@ -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<String, PinElement>} */
|
||||
#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)
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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}"]`
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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} */
|
||||
|
||||
@@ -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 => {
|
||||
|
||||
Reference in New Issue
Block a user