Skip to content

Commit

Permalink
Use LiteGraph validation for node search->create (#822)
Browse files Browse the repository at this point in the history
Adds LiteGraph type to augmentation until LG types are auto-generated
Removes @ts-expect-error
  • Loading branch information
webfiltered authored Sep 13, 2024
1 parent 48f84a4 commit c98ea5b
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
1 change: 0 additions & 1 deletion src/extensions/core/rerouteNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ app.registerExtension({
: null
if (
inputType &&
// @ts-expect-error Will self-resolve when LiteGraph types are generated
!LiteGraph.isValidConnection(inputType, nodeOutType)
) {
// The output doesnt match our input so disconnect it
Expand Down
2 changes: 2 additions & 0 deletions src/types/litegraph-core-augmentation.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ declare module '@comfyorg/litegraph' {
slot_types_out: string[]
slot_types_default_out: Record<string, string[]>
slot_types_default_in: Record<string, string[]>

isValidConnection(type_a: ISlotType, type_b: ISlotType): boolean
}

import type { LiteGraph as LG } from '@comfyorg/litegraph/dist/litegraph'
Expand Down
8 changes: 4 additions & 4 deletions src/types/litegraphTypes.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import {
import type {
ConnectingLink,
LGraphNode,
Vector2,
INodeInputSlot,
INodeOutputSlot,
INodeSlot
} from '@comfyorg/litegraph'
import { LiteGraph } from '@comfyorg/litegraph'

export class ConnectingLinkImpl implements ConnectingLink {
node: LGraphNode
Expand Down Expand Up @@ -56,9 +57,8 @@ export class ConnectingLinkImpl implements ConnectingLink {
this.releaseSlotType === 'output' ? newNode.outputs : newNode.inputs
if (!newNodeSlots) return

const newNodeSlot = newNodeSlots.findIndex(
(slot: INodeSlot) =>
slot.type === this.type || slot.type === '*' || this.type === '*'
const newNodeSlot = newNodeSlots.findIndex((slot: INodeSlot) =>
LiteGraph.isValidConnection(slot.type, this.type)
)

if (newNodeSlot === -1) {
Expand Down

0 comments on commit c98ea5b

Please sign in to comment.