Skip to content

Commit 88e5728

Browse files
committed
Typing fixes, fallback to schema
1 parent bbab14d commit 88e5728

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

src/core/graph/widgets/dynamicWidgets.ts

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -352,8 +352,6 @@ function applyAutogrow(node: LGraphNode, untypedInputSpec: InputSpecV2) {
352352
transformInputSpecV1ToV2(v, { name, isOptional })
353353
)
354354
)
355-
if (inputsV2.length !== 1)
356-
throw new Error('Autogrow: Only 1 input per group is currently supported')
357355

358356
function nameToInputIndex(name: string) {
359357
const index = node.inputs.findIndex((input) => input.name === name)
@@ -370,7 +368,9 @@ function applyAutogrow(node: LGraphNode, untypedInputSpec: InputSpecV2) {
370368
const ordinal = trackedInputs.length
371369
const inputGroup = inputsV2.map((input) => ({
372370
...input,
373-
name: names ? names[ordinal] : (prefix ?? '') + ordinal,
371+
name: names
372+
? names[ordinal]
373+
: ((inputsV2.length == 1 ? prefix : input.name) ?? '') + ordinal,
374374
isOptional: ordinal >= (min ?? 0) || input.isOptional
375375
}))
376376
const newInputs = inputGroup
@@ -379,7 +379,23 @@ function applyAutogrow(node: LGraphNode, untypedInputSpec: InputSpecV2) {
379379
)
380380
.map((namedSpec) => {
381381
addNodeInput(node, namedSpec)
382-
return spliceInputs(node, node.inputs.length - 1, 1)[0]
382+
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 }
398+
return input
383399
})
384400
spliceInputs(node, insertionIndex, 0, ...newInputs)
385401
trackedInputs.push(inputGroup.map((inp) => inp.name))
@@ -394,7 +410,9 @@ function applyAutogrow(node: LGraphNode, untypedInputSpec: InputSpecV2) {
394410
const group = trackedInputs[groupIndex]
395411
for (const nameToRemove of group) {
396412
const inputIndex = nameToInputIndex(nameToRemove)
397-
spliceInputs(node, inputIndex, 1)
413+
const input = spliceInputs(node, inputIndex, 1)[0]
414+
if (!input.widget?.name) continue
415+
node.removeWidgetByName(input.widget.name)
398416
}
399417
trackedInputs.splice(groupIndex, 1)
400418
node.size[1] = node.computeSize([...node.size])[1]

0 commit comments

Comments
 (0)