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:
filtered
2025-03-22 09:23:20 +11:00
committed by GitHub
parent 7c6245ab1c
commit 2dbd5f4cf0
3 changed files with 50 additions and 7 deletions

View File

@@ -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)