From b988238155e70209622a098ef861c68d5fa8412d Mon Sep 17 00:00:00 2001 From: filtered <176114999+webfiltered@users.noreply.github.com> Date: Sun, 20 Apr 2025 18:35:45 +1000 Subject: [PATCH] [Cleanup] Assorted minor code clean-up (#943) Adds one warning log for an extreme edge case. --- src/LGraphCanvas.ts | 8 ++++---- src/utils/uuid.ts | 5 ++--- test/LinkConnector.test.ts | 4 ++-- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/LGraphCanvas.ts b/src/LGraphCanvas.ts index 9201bf13bb..d128756450 100644 --- a/src/LGraphCanvas.ts +++ b/src/LGraphCanvas.ts @@ -936,9 +936,11 @@ export class LGraphCanvas implements ConnectionColorContext { canvas.graph.beforeChange() const node = LiteGraph.createNode(value.value) if (node) { - if (!first_event) throw new TypeError("Context menu event was null. This should not occure in normal usage.") + if (!first_event) throw new TypeError("Context menu event was null. This should not occur in normal usage.") node.pos = canvas.convertEventToCanvasOffset(first_event) canvas.graph.add(node) + } else { + console.warn("Failed to create node of type:", value.value) } callback?.(node) @@ -5518,6 +5520,7 @@ export class LGraphCanvas implements ConnectionColorContext { allow_searchbox: this.allow_searchbox, showSearchBox: this.showSearchBox, }, optPass || {}) + const dirty = () => this.#dirty() const that = this const { graph } = this const { afterRerouteId } = opts @@ -5594,11 +5597,8 @@ export class LGraphCanvas implements ConnectionColorContext { callback: inner_clicked, }) - const dirty = () => this.#dirty() - // callback function inner_clicked(v: string | undefined, options: IContextMenuOptions, e: MouseEvent) { - // console.log("Process showConnectionMenu selection"); switch (v) { case "Add Node": LGraphCanvas.onMenuAdd(null, null, e, menu, function (node) { diff --git a/src/utils/uuid.ts b/src/utils/uuid.ts index 0a907a5860..a9ee701097 100644 --- a/src/utils/uuid.ts +++ b/src/utils/uuid.ts @@ -18,13 +18,12 @@ const randomStorage = new Uint32Array(31) */ export function createUuidv4(): UUID { if (typeof crypto?.randomUUID === "function") return crypto.randomUUID() - // Assertion: `replaceAll` returns `string`; UUID format must be asserted below if (typeof crypto?.getRandomValues === "function") { const random = crypto.getRandomValues(randomStorage) let i = 0 return "10000000-1000-4000-8000-100000000000".replaceAll(/[018]/g, a => - (Number(a) ^ ((random[i++] * 3.725_290_298_461_914e-9) >> (Number(a) * 0.25))).toString(16)) as UUID + (Number(a) ^ ((random[i++] * 3.725_290_298_461_914e-9) >> (Number(a) * 0.25))).toString(16)) } return "10000000-1000-4000-8000-100000000000".replaceAll(/[018]/g, a => - (Number(a) ^ ((Math.random() * 16) >> (Number(a) * 0.25))).toString(16)) as UUID + (Number(a) ^ ((Math.random() * 16) >> (Number(a) * 0.25))).toString(16)) } diff --git a/test/LinkConnector.test.ts b/test/LinkConnector.test.ts index 8f9d7ec9cb..b4ac22483d 100644 --- a/test/LinkConnector.test.ts +++ b/test/LinkConnector.test.ts @@ -1,4 +1,4 @@ -import type { MovingRenderLink } from "@/canvas/MovingRenderLink" +import type { MovingInputLink } from "@/canvas/MovingInputLink" import type { LinkNetwork } from "@/interfaces" import type { ISlotType } from "@/interfaces" @@ -248,7 +248,7 @@ describe("LinkConnector", () => { fromDirection: LinkDirection.RIGHT, toType: "input", link: new LLink(1, "number", 1, 0, 2, 0), - } as MovingRenderLink + } as MovingInputLink connector.events.dispatch("input-moved", mockRenderLink) expect(listener).toHaveBeenCalled()