From f9cf25ad82eefc1e8d99b026817ced280983f421 Mon Sep 17 00:00:00 2001 From: filtered <176114999+webfiltered@users.noreply.github.com> Date: Tue, 1 Jul 2025 12:58:28 -0700 Subject: [PATCH] Add subgraph IO change event handlers (#1096) --- src/subgraph/SubgraphNode.ts | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/subgraph/SubgraphNode.ts b/src/subgraph/SubgraphNode.ts index 643ed823f..eba4bc33e 100644 --- a/src/subgraph/SubgraphNode.ts +++ b/src/subgraph/SubgraphNode.ts @@ -41,6 +41,40 @@ export class SubgraphNode extends LGraphNode implements BaseLGraph { ) { super(subgraph.name, subgraph.id) + // Update this node when the subgraph input / output slots are changed + const subgraphEvents = this.subgraph.events + subgraphEvents.addEventListener("input-added", (e) => { + const { name, type } = e.detail.input + this.addInput(name, type) + }) + subgraphEvents.addEventListener("removing-input", (e) => { + this.removeInput(e.detail.index) + }) + + subgraphEvents.addEventListener("output-added", (e) => { + const { name, type } = e.detail.output + this.addOutput(name, type) + }) + subgraphEvents.addEventListener("removing-output", (e) => { + this.removeOutput(e.detail.index) + }) + + subgraphEvents.addEventListener("renaming-input", (e) => { + const { index, newName } = e.detail + const input = this.inputs.at(index) + if (!input) throw new Error("Subgraph input not found") + + input.label = newName + }) + + subgraphEvents.addEventListener("renaming-output", (e) => { + const { index, newName } = e.detail + const output = this.outputs.at(index) + if (!output) throw new Error("Subgraph output not found") + + output.label = newName + }) + this.type = subgraph.id this.configure(instanceData) }