MCPcopy Create free account
hub / github.com/Comfy-Org/litegraph.js / connectInputToOutput

Method connectInputToOutput

src/LGraphNode.ts:3468–3531  ·  view source on GitHub ↗

* Attempts to gracefully bypass this node in all of its connections by reconnecting all links. * * Each input is checked against each output. This is done on a matching index basis, i.e. input 3 -> output 3. * If there are any input links remaining, * and flags.{@link INodeFlags

()

Source from the content-addressed store, hash-verified

3466 * @todo Decision: Change API to return array of new links instead?
3467 */
3468 connectInputToOutput(): boolean | undefined {
3469 const { inputs, outputs, graph } = this
3470 if (!inputs || !outputs) return
3471 if (!graph) throw new NullGraphError()
3472
3473 const { _links } = graph
3474 let madeAnyConnections = false
3475
3476 // First pass: only match exactly index-to-index
3477 for (const [index, input] of inputs.entries()) {
3478 if (input.link == null) continue
3479
3480 const output = outputs[index]
3481 if (!output || !LiteGraph.isValidConnection(input.type, output.type)) continue
3482
3483 const inLink = _links.get(input.link)
3484 if (!inLink) continue
3485 const inNode = graph.getNodeById(inLink?.origin_id)
3486 if (!inNode) continue
3487
3488 bypassAllLinks(output, inNode, inLink, graph)
3489 }
3490 // Configured to only use index-to-index matching
3491 if (!(this.flags.keepAllLinksOnBypass ?? LGraphNode.keepAllLinksOnBypass))
3492 return madeAnyConnections
3493
3494 // Second pass: match any remaining links
3495 for (const input of inputs) {
3496 if (input.link == null) continue
3497
3498 const inLink = _links.get(input.link)
3499 if (!inLink) continue
3500 const inNode = graph.getNodeById(inLink?.origin_id)
3501 if (!inNode) continue
3502
3503 for (const output of outputs) {
3504 if (!LiteGraph.isValidConnection(input.type, output.type)) continue
3505
3506 bypassAllLinks(output, inNode, inLink, graph)
3507 break
3508 }
3509 }
3510 return madeAnyConnections
3511
3512 function bypassAllLinks(output: INodeOutputSlot, inNode: LGraphNode, inLink: LLink, graph: LGraph) {
3513 const outLinks = output.links
3514 ?.map(x => _links.get(x))
3515 .filter(x => !!x)
3516 if (!outLinks?.length) return
3517
3518 for (const outLink of outLinks) {
3519 const outNode = graph.getNodeById(outLink.target_id)
3520 if (!outNode) continue
3521
3522 const result = inNode.connect(
3523 inLink.origin_slot,
3524 outNode,
3525 outLink.target_slot,

Callers 1

deleteSelectedMethod · 0.80

Calls 3

isValidConnectionMethod · 0.80
getMethod · 0.80
getNodeByIdMethod · 0.65

Tested by

no test coverage detected