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

Method disconnectInput

src/LGraphNode.ts:2874–2961  ·  view source on GitHub ↗

* Disconnect one input * @param slot Input slot index, or the name of the slot * @param keepReroutes If `true`, reroutes will not be garbage collected. * @returns true if disconnected successfully or already disconnected, otherwise false

(slot: number | string, keepReroutes?: boolean)

Source from the content-addressed store, hash-verified

2872 * @returns true if disconnected successfully or already disconnected, otherwise false
2873 */
2874 disconnectInput(slot: number | string, keepReroutes?: boolean): boolean {
2875 // Allow search by string
2876 if (typeof slot === "string") {
2877 slot = this.findInputSlot(slot)
2878 if (slot == -1) {
2879 if (LiteGraph.debug) console.log(`Connect: Error, no slot of name ${slot}`)
2880 return false
2881 }
2882 } else if (!this.inputs || slot >= this.inputs.length) {
2883 if (LiteGraph.debug) {
2884 console.log("Connect: Error, slot number not found")
2885 }
2886 return false
2887 }
2888
2889 const input = this.inputs[slot]
2890 if (!input) {
2891 console.debug("disconnectInput: input not found", slot, this.inputs)
2892 return false
2893 }
2894
2895 const { graph } = this
2896 if (!graph) throw new NullGraphError()
2897
2898 // Break floating links
2899 if (input._floatingLinks?.size) {
2900 for (const link of input._floatingLinks) {
2901 graph.removeFloatingLink(link)
2902 }
2903 }
2904
2905 const link_id = this.inputs[slot].link
2906 if (link_id != null) {
2907 this.inputs[slot].link = null
2908
2909 // remove other side
2910 const link_info = graph._links.get(link_id)
2911 if (link_info) {
2912 // Let SubgraphInput do the disconnect.
2913 if (link_info.origin_id === -10 && "inputNode" in graph) {
2914 graph.inputNode._disconnectNodeInput(this, input, link_info)
2915 return true
2916 }
2917
2918 const target_node = graph.getNodeById(link_info.origin_id)
2919 if (!target_node) {
2920 console.debug("disconnectInput: target node not found", link_info.origin_id)
2921 return false
2922 }
2923
2924 const output = target_node.outputs[link_info.origin_slot]
2925 if (!(output?.links?.length)) {
2926 console.debug("disconnectInput: output not found", link_info.origin_slot)
2927 return false
2928 }
2929
2930 // search in the inputs list for this link
2931 let i = 0

Callers 12

removeInputMethod · 0.95
LGraphNode.test.tsFile · 0.80
connectSlotsMethod · 0.80
#processNodeClickMethod · 0.80
inner_option_clickedMethod · 0.80
removeMethod · 0.80
removeLinkMethod · 0.80
convertToSubgraphMethod · 0.80
connectToInputMethod · 0.80
connectToInputMethod · 0.80
disconnectMethod · 0.80

Calls 7

findInputSlotMethod · 0.95
setDirtyCanvasMethod · 0.95
getMethod · 0.80
_disconnectNodeInputMethod · 0.80
removeFloatingLinkMethod · 0.65
getNodeByIdMethod · 0.65
disconnectMethod · 0.45

Tested by

no test coverage detected