mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-03-02 03:30:04 +00:00
Allow creating floating reroutes from new link menu (#818)
Adds an `Add Reroute` option to the new link menu. Creates a new floating reroute connected to the source slot.
This commit is contained in:
@@ -20,7 +20,7 @@ import type {
|
||||
Size,
|
||||
} from "./interfaces"
|
||||
import type { LGraph } from "./LGraph"
|
||||
import type { RerouteId } from "./Reroute"
|
||||
import type { Reroute, RerouteId } from "./Reroute"
|
||||
import type { CanvasMouseEvent } from "./types/events"
|
||||
import type { ISerialisedNode } from "./types/serialisation"
|
||||
import type { IBaseWidget, IWidget, IWidgetOptions, TWidgetType, TWidgetValue } from "./types/widgets"
|
||||
@@ -2545,6 +2545,31 @@ export class LGraphNode implements Positionable, IPinnable, IColorable {
|
||||
return link
|
||||
}
|
||||
|
||||
connectFloatingReroute(pos: Point, slot: INodeInputSlot | INodeOutputSlot): Reroute {
|
||||
const { graph, id } = this
|
||||
if (!graph) throw new NullGraphError()
|
||||
|
||||
// Assertion: It's either there or it isn't.
|
||||
const inputIndex = this.inputs.indexOf(slot as INodeInputSlot)
|
||||
const outputIndex = this.outputs.indexOf(slot as INodeOutputSlot)
|
||||
if (inputIndex === -1 && outputIndex === -1) throw new Error("Invalid slot")
|
||||
|
||||
const link = new LLink(
|
||||
-1,
|
||||
slot.type,
|
||||
outputIndex === -1 ? -1 : id,
|
||||
outputIndex,
|
||||
inputIndex === -1 ? -1 : id,
|
||||
inputIndex,
|
||||
)
|
||||
const slotType = outputIndex === -1 ? "input" : "output"
|
||||
const reroute = graph.setReroute({ pos, linkIds: [], floating: { slotType } })
|
||||
|
||||
link.parentId = reroute.id
|
||||
graph.addFloatingLink(link)
|
||||
return reroute
|
||||
}
|
||||
|
||||
/**
|
||||
* disconnect one output to an specific node
|
||||
* @param slot (could be the number of the slot or the string with the name of the slot)
|
||||
|
||||
Reference in New Issue
Block a user