Compare commits

...

1 Commits

Author SHA1 Message Date
Austin Mroz
33761d82fe Support keeping value across dynamic combo options 2026-02-07 12:10:14 -08:00
2 changed files with 19 additions and 1 deletions

View File

@@ -95,7 +95,9 @@ function dynamicComboWidget(
const newSpec = value ? options[value] : undefined
const removedInputs = remove(node.inputs, isInGroup)
for (const widget of remove(node.widgets, isInGroup)) widget.onRemove?.()
const removedWidgets = remove(node.widgets, isInGroup)
for (const widget of removedWidgets) widget.onRemove?.()
if (!newSpec) return
@@ -174,6 +176,18 @@ function dynamicComboWidget(
)
}
}
for (const widget of removedWidgets) {
const newMatchingWidget = addedWidgets.find((w) => w.name === widget.name)
if (!newMatchingWidget || newMatchingWidget.type !== widget.type) continue
const nameSegment = widget.name.slice(widget.name.lastIndexOf('.') + 1)
const spec =
newSpec.required?.[nameSegment] ?? newSpec.optional?.[nameSegment]
if (spec?.[1] && 'default' in spec?.[1]) continue
newMatchingWidget.value = widget.value
newMatchingWidget.callback?.(widget.value)
}
node.size[1] = node.computeSize([...node.size])[1]
if (!node.graph) return

View File

@@ -24,6 +24,10 @@ function onValueChange(this: INumericWidget, v: number) {
// Round to nearest step, accounting for offset
this.value = Math.round((v - offset) / step) * step + offset
}
if (this.options.min !== undefined && this.value < this.options.min)
this.value = this.options.min
if (this.options.max !== undefined && this.value > this.options.max)
this.value = this.options.max
}
export const _for_testing = {