* 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)
| 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 |
no test coverage detected