(
/** The (sub)graph that contains this subgraph instance. */
override readonly graph: GraphOrSubgraph,
/** The definition of this subgraph; how its nodes are configured, etc. */
readonly subgraph: Subgraph,
instanceData: ExportedSubgraphInstance,
)
| 45 | #eventAbortController = new AbortController() |
| 46 | |
| 47 | constructor( |
| 48 | /** The (sub)graph that contains this subgraph instance. */ |
| 49 | override readonly graph: GraphOrSubgraph, |
| 50 | /** The definition of this subgraph; how its nodes are configured, etc. */ |
| 51 | readonly subgraph: Subgraph, |
| 52 | instanceData: ExportedSubgraphInstance, |
| 53 | ) { |
| 54 | super(subgraph.name, subgraph.id) |
| 55 | |
| 56 | // Update this node when the subgraph input / output slots are changed |
| 57 | const subgraphEvents = this.subgraph.events |
| 58 | const { signal } = this.#eventAbortController |
| 59 | |
| 60 | subgraphEvents.addEventListener("input-added", (e) => { |
| 61 | const subgraphInput = e.detail.input |
| 62 | const { name, type } = subgraphInput |
| 63 | if (this.inputs.some(i => i.name == name)) |
| 64 | return |
| 65 | const input = this.addInput(name, type) |
| 66 | |
| 67 | this.#addSubgraphInputListeners(subgraphInput, input) |
| 68 | }, { signal }) |
| 69 | |
| 70 | subgraphEvents.addEventListener("removing-input", (e) => { |
| 71 | const widget = e.detail.input._widget |
| 72 | if (widget) this.ensureWidgetRemoved(widget) |
| 73 | |
| 74 | this.removeInput(e.detail.index) |
| 75 | this.setDirtyCanvas(true, true) |
| 76 | }, { signal }) |
| 77 | |
| 78 | subgraphEvents.addEventListener("output-added", (e) => { |
| 79 | const { name, type } = e.detail.output |
| 80 | this.addOutput(name, type) |
| 81 | }, { signal }) |
| 82 | |
| 83 | subgraphEvents.addEventListener("removing-output", (e) => { |
| 84 | this.removeOutput(e.detail.index) |
| 85 | this.setDirtyCanvas(true, true) |
| 86 | }, { signal }) |
| 87 | |
| 88 | subgraphEvents.addEventListener("renaming-input", (e) => { |
| 89 | const { index, newName } = e.detail |
| 90 | const input = this.inputs.at(index) |
| 91 | if (!input) throw new Error("Subgraph input not found") |
| 92 | |
| 93 | input.label = newName |
| 94 | }, { signal }) |
| 95 | |
| 96 | subgraphEvents.addEventListener("renaming-output", (e) => { |
| 97 | const { index, newName } = e.detail |
| 98 | const output = this.outputs.at(index) |
| 99 | if (!output) throw new Error("Subgraph output not found") |
| 100 | |
| 101 | output.label = newName |
| 102 | }, { signal }) |
| 103 | |
| 104 | this.type = subgraph.id |
nothing calls this directly
no test coverage detected