diff --git a/src/components/rightSidePanel/parameters/SectionWidgets.vue b/src/components/rightSidePanel/parameters/SectionWidgets.vue index 6d87cab6d1..1ecac869f3 100644 --- a/src/components/rightSidePanel/parameters/SectionWidgets.vue +++ b/src/components/rightSidePanel/parameters/SectionWidgets.vue @@ -12,6 +12,9 @@ import type { } from '@/lib/litegraph/src/litegraph' import type { IBaseWidget } from '@/lib/litegraph/src/types/widgets' import { useCanvasStore } from '@/renderer/core/canvas/canvasStore' +import { useNodeDefStore } from '@/stores/nodeDefStore' +import { getWidgetDefaultValue } from '@/utils/widgetUtil' +import type { WidgetValue } from '@/utils/widgetUtil' import PropertiesAccordionItem from '../layout/PropertiesAccordionItem.vue' import { HideLayoutFieldKey } from '@/types/widgetTypes' @@ -57,6 +60,7 @@ watchEffect(() => (widgets.value = widgetsProp)) provide(HideLayoutFieldKey, true) const canvasStore = useCanvasStore() +const nodeDefStore = useNodeDefStore() const { t } = useI18n() const getNodeParentGroup = inject(GetNodeParentGroupKey, null) @@ -118,15 +122,31 @@ function handleLocateNode() { } } -function handleWidgetValueUpdate( - widget: IBaseWidget, - newValue: string | number | boolean | object -) { - widget.value = newValue - widget.callback?.(newValue) +function writeWidgetValue(widget: IBaseWidget, value: WidgetValue) { + widget.value = value + widget.callback?.(value) canvasStore.canvas?.setDirty(true, true) } +function handleResetAllWidgets() { + for (const { widget, node: widgetNode } of widgetsProp) { + const spec = nodeDefStore.getInputSpecForWidget(widgetNode, widget.name) + const defaultValue = getWidgetDefaultValue(spec) + if (defaultValue !== undefined) { + writeWidgetValue(widget, defaultValue) + } + } +} + +function handleWidgetValueUpdate(widget: IBaseWidget, newValue: WidgetValue) { + if (newValue === undefined) return + writeWidgetValue(widget, newValue) +} + +function handleWidgetReset(widget: IBaseWidget, newValue: WidgetValue) { + writeWidgetValue(widget, newValue) +} + defineExpose({ widgetsContainer, rootElement @@ -157,6 +177,17 @@ defineExpose({ {{ parentGroup.title }} +