From b1885ebec88e6f127534ba40ac0f0bfb836e3794 Mon Sep 17 00:00:00 2001 From: filtered <176114999+webfiltered@users.noreply.github.com> Date: Mon, 3 Mar 2025 00:47:48 +1100 Subject: [PATCH] Remove redundant code - onGetInputs / onGetOutputs (#674) - Removes unused context menu for optional in/outputs - At the top of the node context menu, greyed out `Inputs` and `Outputs` - API does not fit with current design - If required, rewrite would be simpler --- src/LGraphCanvas.ts | 125 -------------------------------------------- src/LGraphNode.ts | 2 - 2 files changed, 127 deletions(-) diff --git a/src/LGraphCanvas.ts b/src/LGraphCanvas.ts index a44e02cb6..420a86449 100644 --- a/src/LGraphCanvas.ts +++ b/src/LGraphCanvas.ts @@ -448,9 +448,6 @@ export class LGraphCanvas implements ConnectionColorContext { readonly viewport?: Rect autoresize: boolean static active_canvas: LGraphCanvas - static onMenuNodeOutputs?( - entries: (IContextMenuValue | null)[], - ): (IContextMenuValue | null)[] frame = 0 last_draw_time = 0 render_time = 0 @@ -919,87 +916,6 @@ export class LGraphCanvas implements ConnectionColorContext { static onMenuCollapseAll() {} static onMenuNodeEdit() {} - /** @param _options Parameter is never used */ - static showMenuNodeOptionalInputs( - v: unknown, - /** Unused - immediately overwritten */ - _options: boolean, - e: MouseEvent, - prev_menu: ContextMenu, - node: LGraphNode, - ): boolean | undefined { - if (!node) return - - const canvas = LGraphCanvas.active_canvas - const ref_window = canvas.getCanvasWindow() - - const options = node.onGetInputs - ? node.onGetInputs() - : undefined - - let entries: (IContextMenuValue | null)[] = [] - if (options) { - for (const entry of options) { - if (!entry) { - entries.push(null) - continue - } - let label = entry[0] - entry[2] ||= {} - - if (entry[2].label) { - label = entry[2].label - } - - entry[2].removable = true - const data: IContextMenuValue = { content: label, value: entry } - if (entry[1] == LiteGraph.ACTION) { - data.className = "event" - } - entries.push(data) - } - } - - const retEntries = node.onMenuNodeInputs?.(entries) - if (retEntries) entries = retEntries - - if (!entries.length) { - console.log("no input entries") - return - } - - new LiteGraph.ContextMenu( - entries, - { - event: e, - callback: inner_clicked, - parentMenu: prev_menu, - node: node, - }, - // @ts-expect-error Unused param - ref_window, - ) - - function inner_clicked(this: ContextMenuDivElement, v: IContextMenuValue, e: MouseEvent, prev: ContextMenu) { - if (!node) return - - v.callback?.call(this, node, v, e, prev) - - if (!v.value) return - if (!node.graph) throw new NullGraphError() - - node.graph.beforeChange() - node.addInput(v.value[0], v.value[1], v.value[2]) - - // callback to the node when adding a slot - node.onNodeInputAdd?.(v.value) - canvas.setDirty(true, true) - node.graph.afterChange() - } - - return false - } - /** @param _options Parameter is never used */ static showMenuNodeOptionalOutputs( v: unknown, @@ -1013,42 +929,8 @@ export class LGraphCanvas implements ConnectionColorContext { const canvas = LGraphCanvas.active_canvas - const options = node.onGetOutputs - ? node.onGetOutputs() - : undefined - let entries: (IContextMenuValue | null)[] = [] - if (options) { - for (const entry of options) { - if (!entry) { - // separator? - entries.push(null) - continue - } - if ( - node.flags && - node.flags.skip_repeated_outputs && - node.findOutputSlot(entry[0]) != -1 - ) { - // skip the ones already on - continue - } - let label = entry[0] - entry[2] ||= {} - if (entry[2].label) { - label = entry[2].label - } - entry[2].removable = true - const data: IContextMenuValue = { content: label, value: entry } - if (entry[1] == LiteGraph.EVENT) { - data.className = "event" - } - entries.push(data) - } - } - - if (this.onMenuNodeOutputs) entries = this.onMenuNodeOutputs(entries) if (LiteGraph.do_add_triggers_slots) { // canvas.allow_addOutSlot_onExecuted if (node.findOutputSlot("onExecuted") == -1) { @@ -7213,7 +7095,6 @@ export class LGraphCanvas implements ConnectionColorContext { content: "Inputs", has_submenu: true, disabled: true, - callback: LGraphCanvas.showMenuNodeOptionalInputs, }, { content: "Outputs", @@ -7287,12 +7168,6 @@ export class LGraphCanvas implements ConnectionColorContext { ) } - const inputs = node.onGetInputs?.() - if (inputs?.length) options[0].disabled = false - - const outputs = node.onGetOutputs?.() - if (outputs?.length) options[1].disabled = false - const extra = node.getExtraMenuOptions?.(this, options) if (Array.isArray(extra) && extra.length > 0) { extra.push(null) diff --git a/src/LGraphNode.ts b/src/LGraphNode.ts index 784774b05..dbaa12ebb 100644 --- a/src/LGraphNode.ts +++ b/src/LGraphNode.ts @@ -522,8 +522,6 @@ export class LGraphNode implements Positionable, IPinnable, IColorable { this: LGraphNode, entries: (IContextMenuValue | null)[], ): (IContextMenuValue | null)[] - onGetInputs?(this: LGraphNode): INodeSlotContextItem[] - onGetOutputs?(this: LGraphNode): INodeSlotContextItem[] onMouseUp?(this: LGraphNode, e: CanvasMouseEvent, pos: Point): void onMouseEnter?(this: LGraphNode, e: CanvasMouseEvent): void /** Blocks drag if return value is truthy. @param pos Offset from {@link LGraphNode.pos}. */