Line data Source code
1 : import type { LGraphNode } from '@comfyorg/graph-model/entityRegistry'
2 : import type { INodeInputSlot } from '@comfyorg/graph-model/slots'
3 :
4 : import { isWidgetValue } from '@comfyorg/graph-model/widgets'
5 : import { useWidgetValueStore } from '@/stores/widgetValueStore'
6 :
7 : /**
8 : * Copies a promoted host widget's value onto the interior widget it forwards to.
9 : *
10 : * A promoted input holds the user-facing value on the host subgraph node and
11 : * never writes it through, so unpacking must move it or the edit is lost.
12 : */
13 53 : export function adoptPromotedWidgetValue(
14 : hostInput: INodeInputSlot,
15 : targetNode: LGraphNode,
16 : targetSlot: number
17 : ): void {
18 53 : const { widgetId } = hostInput
19 53 : if (!widgetId) return
20 :
21 53 : const value = useWidgetValueStore().getWidget(widgetId)?.value
22 53 : if (value === undefined || !isWidgetValue(value)) return
23 :
24 53 : if (targetSlot < 0 || targetSlot >= targetNode.inputs.length) return
25 11 : const targetInput = targetNode.inputs[targetSlot]
26 :
27 11 : const widget = targetNode.getWidgetFromSlot(targetInput)
28 51 : if (!widget) return
29 :
30 11 : widget.value = value
31 : }
|