* Removes a node from the graph * @param node the instance of the node
(node: LGraphNode | LGraphGroup)
| 866 | * @param node the instance of the node |
| 867 | */ |
| 868 | remove(node: LGraphNode | LGraphGroup): void { |
| 869 | // LEGACY: This was changed from constructor === LiteGraph.LGraphGroup |
| 870 | if (node instanceof LGraphGroup) { |
| 871 | this.canvasAction(c => c.deselect(node)) |
| 872 | |
| 873 | const index = this._groups.indexOf(node) |
| 874 | if (index != -1) { |
| 875 | this._groups.splice(index, 1) |
| 876 | } |
| 877 | node.graph = undefined |
| 878 | this._version++ |
| 879 | this.setDirtyCanvas(true, true) |
| 880 | this.change() |
| 881 | return |
| 882 | } |
| 883 | |
| 884 | // not found |
| 885 | if (this._nodes_by_id[node.id] == null) { |
| 886 | console.warn("LiteGraph: node not found", node) |
| 887 | return |
| 888 | } |
| 889 | // cannot be removed |
| 890 | if (node.ignore_remove) { |
| 891 | console.warn("LiteGraph: node cannot be removed", node) |
| 892 | return |
| 893 | } |
| 894 | |
| 895 | // sure? - almost sure is wrong |
| 896 | this.beforeChange() |
| 897 | |
| 898 | const { inputs, outputs } = node |
| 899 | |
| 900 | // disconnect inputs |
| 901 | if (inputs) { |
| 902 | for (const [i, slot] of inputs.entries()) { |
| 903 | if (slot.link != null) node.disconnectInput(i, true) |
| 904 | } |
| 905 | } |
| 906 | |
| 907 | // disconnect outputs |
| 908 | if (outputs) { |
| 909 | for (const [i, slot] of outputs.entries()) { |
| 910 | if (slot.links?.length) node.disconnectOutput(i) |
| 911 | } |
| 912 | } |
| 913 | |
| 914 | // Floating links |
| 915 | for (const link of this.floatingLinks.values()) { |
| 916 | if (link.origin_id === node.id || link.target_id === node.id) { |
| 917 | this.removeFloatingLink(link) |
| 918 | } |
| 919 | } |
| 920 | |
| 921 | // callback |
| 922 | node.onRemoved?.() |
| 923 | |
| 924 | node.graph = null |
| 925 | this._version++ |
no test coverage detected