Reroute insert and splice

This commit is contained in:
space-nuko
2023-05-23 21:17:13 -05:00
parent fcd1737b98
commit 47b0dabd80
6 changed files with 77 additions and 11 deletions

View File

@@ -196,8 +196,9 @@ export default class ComfyGraphNode extends LGraphNode {
updateNodes.push(node);
} else {
// We've found an output
const nodeOutType = node.inputs && node.inputs[link?.target_slot] && node.inputs[link.target_slot].type ? node.inputs[link.target_slot].type : null;
if (inputType && nodeOutType !== inputType) {
let nodeOutType = node.inputs && node.inputs[link?.target_slot] != null ? node.inputs[link.target_slot].type : null;
nodeOutType ||= "*"
if (inputType && nodeOutType !== inputType && nodeOutType !== "*") {
// The output doesnt match our input so disconnect it
node.disconnectInput(link.target_slot);
} else {

View File

@@ -76,6 +76,31 @@ export default class ComfyReroute extends ComfyGraphNode {
};
override getExtraMenuOptions(_, options: ContextMenuItem[]): ContextMenuItem[] | null {
const canSplice = this.getInputLink(0) != null && this.getOutputLinks(0).length > 0;
options.push({
content: "Splice & Remove",
disabled: !canSplice,
callback: () => {
const inputLink = this.getInputLink(0);
const outputLinks = this.getOutputLinks(0);
if (!inputLink || !outputLinks)
return;
const inputNode = this.graph.getNodeById(inputLink.origin_id)
this.graph.removeLink(inputLink.id);
for (const outputLink of outputLinks) {
const outputNode = this.graph.getNodeById(outputLink.target_id)
this.graph.removeLink(outputLink.id);
inputNode.connect(inputLink.origin_slot, outputNode, outputLink.target_slot);
}
this.graph.remove(this);
}
})
options.unshift(
{
content: (this.properties.showOutputText ? "Hide" : "Show") + " Type",