Skip to content

Commit 3baa747

Browse files
committed
Swap back to keyed dynamic combos
Support inline inputs for dynamic combos - Functionality currently disabled. Need to verify vue mode and check with design Always show input socket on inline inputs
1 parent 7670124 commit 3baa747

File tree

5 files changed

+39
-28
lines changed

5 files changed

+39
-28
lines changed

src/core/graph/widgets/dynamicWidgets.ts

Lines changed: 33 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,30 @@ import { app } from '@/scripts/app'
2222
import type { ComfyApp } from '@/scripts/app'
2323
import { isStrings } from '@/utils/typeGuardUtil'
2424

25+
const INLINE_INPUTS = false
26+
2527
type MatchTypeNode = LGraphNode &
2628
Pick<Required<LGraphNode>, 'comfyMatchType' | 'onConnectionsChange'>
2729

30+
function ensureWidgetForInput(node: LGraphNode, input: INodeInputSlot) {
31+
if (input.widget?.name) return
32+
node.widgets ??= []
33+
node.widgets.push({
34+
name: input.name,
35+
y: 0,
36+
type: 'shim',
37+
options: {},
38+
draw(ctx, _n, _w, y) {
39+
ctx.save()
40+
ctx.fillStyle = LiteGraph.NODE_TEXT_COLOR
41+
ctx.fillText(input.label ?? input.name, 20, y + 15)
42+
ctx.restore()
43+
}
44+
})
45+
input.alwaysVisible = true
46+
input.widget = { name: input.name }
47+
}
48+
2849
function dynamicComboWidget(
2950
node: LGraphNode,
3051
inputName: string,
@@ -84,21 +105,22 @@ function dynamicComboWidget(
84105
[newSpec.optional, true]
85106
]
86107
for (const [inputType, isOptional] of inputTypes)
87-
for (const name in inputType ?? {}) {
88-
addNodeInput(
89-
node,
90-
transformInputSpecV1ToV2(inputType![name], {
91-
name,
92-
isOptional
93-
})
94-
)
108+
for (const key in inputType ?? {}) {
109+
const name = `${widget.name}.${key}`
110+
const specToAdd = transformInputSpecV1ToV2(inputType![key], {
111+
name,
112+
isOptional
113+
})
114+
specToAdd.display_name = key
115+
addNodeInput(node, specToAdd)
95116
currentDynamicNames.push(name)
117+
if (INLINE_INPUTS) ensureWidgetForInput(node, node.inputs.at(-1)!)
96118
if (
97119
!inputsToRemove[name] ||
98-
Array.isArray(inputType![name][0]) ||
120+
Array.isArray(inputType![key][0]) ||
99121
!LiteGraph.isValidConnection(
100122
inputsToRemove[name].type,
101-
inputType![name][0]
123+
inputType![key][0]
102124
)
103125
)
104126
continue
@@ -380,21 +402,7 @@ function applyAutogrow(node: LGraphNode, untypedInputSpec: InputSpecV2) {
380402
.map((namedSpec) => {
381403
addNodeInput(node, namedSpec)
382404
const input = spliceInputs(node, node.inputs.length - 1, 1)[0]
383-
if (input.widget?.name || inputsV2.length == 1) return input
384-
node.widgets ??= []
385-
node.widgets.push({
386-
name: input.name,
387-
y: 0,
388-
type: 'shim',
389-
options: {},
390-
draw(ctx, _n, _w, y) {
391-
ctx.save()
392-
ctx.fillStyle = LiteGraph.NODE_TEXT_COLOR
393-
ctx.fillText(input.name, 20, y + 15)
394-
ctx.restore()
395-
}
396-
})
397-
input.widget = { name: input.name }
405+
if (inputsV2.length !== 1) ensureWidgetForInput(node, input)
398406
return input
399407
})
400408
spliceInputs(node, insertionIndex, 0, ...newInputs)

src/lib/litegraph/src/LGraphNode.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3979,7 +3979,8 @@ export class LGraphNode
39793979
isValidTarget ||
39803980
!slot.isWidgetInputSlot ||
39813981
this.#isMouseOverWidget(this.getWidgetFromSlot(slot)) ||
3982-
slot.isConnected
3982+
slot.isConnected ||
3983+
slot.alwaysVisible
39833984
) {
39843985
ctx.globalAlpha = isValid ? editorAlpha : 0.4 * editorAlpha
39853986
slot.draw(ctx, {

src/lib/litegraph/src/interfaces.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,7 @@ export interface IWidgetLocator {
343343
export interface INodeInputSlot extends INodeSlot {
344344
link: LinkId | null
345345
widget?: IWidgetLocator
346+
alwaysVisible?: boolean
346347

347348
/**
348349
* Internal use only; API is not finalised and may change at any time.

src/lib/litegraph/src/node/NodeInputSlot.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import type { IBaseWidget } from '@/lib/litegraph/src/types/widgets'
1717

1818
export class NodeInputSlot extends NodeSlot implements INodeInputSlot {
1919
link: LinkId | null
20+
alwaysVisible?: boolean
2021

2122
get isWidgetInputSlot(): boolean {
2223
return !!this.widget

tests-ui/tests/widgets/dynamicCombo.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@ describe('Dynamic Combos', () => {
103103
node.widgets[0].value = '1'
104104
expect(node.widgets.length).toBe(2)
105105
expect(node.inputs.length).toBe(4)
106-
expect(node.inputs[1].name).toBe('0.0.0')
107-
expect(node.inputs[3].name).toBe('2.0.0')
106+
expect(node.inputs[1].name).toBe('0.0.0.0')
107+
expect(node.inputs[3].name).toBe('2.2.0.0')
108108
})
109109
})
110110
describe('Autogrow', () => {

0 commit comments

Comments
 (0)