Line data Source code
1 : import type { INodeSlot } from '@comfyorg/graph-model/interfaces'
2 : import type { INodeInputSlot } from '@comfyorg/graph-model/slots'
3 : import { useLinkStore } from '@/stores/linkStore'
4 : import type { GraphScope } from '@comfyorg/graph-model/graphScopeId'
5 : import type { NodeId } from '@comfyorg/graph-model/nodeId'
6 : import { isSlotObject } from '@/utils/typeGuardUtil'
7 :
8 10817 : function coerceINodeSlot(input: INodeInputSlot): INodeSlot {
9 10817 : return isSlotObject(input)
10 : ? input
11 : : {
12 : name: typeof input === 'string' ? input : '',
13 : type: 'any',
14 : boundingRect: [0, 0, 0, 0]
15 : }
16 : }
17 :
18 26675 : function inputHasWidget(input: INodeInputSlot) {
19 26675 : return isSlotObject(input) && 'widget' in input && input.widget
20 : }
21 :
22 8276 : export function nonWidgetedInputs(
23 : inputs: INodeInputSlot[] | undefined
24 : ): INodeSlot[] {
25 8276 : if (!inputs) return []
26 :
27 8276 : return inputs.filter((input) => !inputHasWidget(input)).map(coerceINodeSlot)
28 : }
29 :
30 25 : export function linkedWidgetedInputs(
31 : nodeId: NodeId,
32 : inputs: INodeInputSlot[] | undefined,
33 : scope: GraphScope
34 : ): INodeSlot[] {
35 25 : if (!inputs) return []
36 :
37 25 : const linkStore = useLinkStore()
38 25 : return inputs
39 : .filter(
40 : (input, index) =>
41 : inputHasWidget(input) &&
42 : linkStore.isInputSlotConnected(scope, nodeId, index)
43 : )
44 : .map(coerceINodeSlot)
45 : }
|