mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-03-08 06:30:04 +00:00
Update node search to use litegraph LinkConnector (#3546)
Co-authored-by: github-actions <github-actions@github.com>
This commit is contained in:
@@ -1,75 +0,0 @@
|
||||
import type {
|
||||
ConnectingLink,
|
||||
INodeInputSlot,
|
||||
INodeOutputSlot,
|
||||
INodeSlot,
|
||||
ISlotType,
|
||||
LGraphNode,
|
||||
Vector2
|
||||
} from '@comfyorg/litegraph'
|
||||
import { LiteGraph } from '@comfyorg/litegraph'
|
||||
import { RerouteId } from '@comfyorg/litegraph/dist/Reroute'
|
||||
|
||||
export class ConnectingLinkImpl implements ConnectingLink {
|
||||
constructor(
|
||||
public node: LGraphNode,
|
||||
public slot: number,
|
||||
public input: INodeInputSlot | null | undefined | any,
|
||||
public output: INodeOutputSlot | null | undefined | any,
|
||||
public pos: Vector2,
|
||||
public afterRerouteId?: RerouteId
|
||||
) {}
|
||||
|
||||
static createFromPlainObject(obj: ConnectingLink) {
|
||||
return new ConnectingLinkImpl(
|
||||
obj.node,
|
||||
obj.slot,
|
||||
obj.input,
|
||||
obj.output,
|
||||
obj.pos,
|
||||
obj.afterRerouteId
|
||||
)
|
||||
}
|
||||
|
||||
get type(): ISlotType | null {
|
||||
const result = this.input ? this.input.type : this.output?.type ?? null
|
||||
return result === -1 ? null : result
|
||||
}
|
||||
|
||||
/**
|
||||
* Which slot type is release and need to be reconnected.
|
||||
* - 'output' means we need a new node's outputs slot to connect with this link
|
||||
*/
|
||||
get releaseSlotType(): 'input' | 'output' {
|
||||
return this.output ? 'input' : 'output'
|
||||
}
|
||||
|
||||
connectTo(newNode: LGraphNode) {
|
||||
const newNodeSlots =
|
||||
this.releaseSlotType === 'output' ? newNode.outputs : newNode.inputs
|
||||
if (!newNodeSlots) return
|
||||
|
||||
const newNodeSlot = newNodeSlots.findIndex(
|
||||
(slot: INodeSlot) =>
|
||||
this.type && LiteGraph.isValidConnection(slot.type, this.type)
|
||||
)
|
||||
|
||||
if (newNodeSlot === -1) {
|
||||
console.warn(
|
||||
`Could not find slot with type ${this.type} on node ${newNode.title}. This should never happen`
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
if (this.releaseSlotType === 'input') {
|
||||
this.node.connect(this.slot, newNode, newNodeSlot, this.afterRerouteId)
|
||||
} else {
|
||||
newNode.connect(newNodeSlot, this.node, this.slot, this.afterRerouteId)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export type CanvasDragAndDropData<T = any> = {
|
||||
type: 'add-node'
|
||||
data: T
|
||||
}
|
||||
Reference in New Issue
Block a user