From 122170fc0d456c04bb9ed08ca02cb11bd16bdfff Mon Sep 17 00:00:00 2001 From: bymyself Date: Thu, 3 Jul 2025 17:14:02 -0700 Subject: [PATCH] [fix] Fix widget value synchronization between Vue and LiteGraph - Widget callbacks now explicitly set widget.value (fixes empty LiteGraph callbacks) - Created useWidgetValue composable for consistent widget patterns - Updated all widget components to use proper props/emit pattern - Callbacks are set up before data extraction to ensure proper state sync --- src/components/graph/vueNodes/NodeWidgets.vue | 7 +- .../graph/vueWidgets/WidgetInputText.vue | 22 ++- .../graph/vueWidgets/WidgetSelect.vue | 19 ++- .../graph/vueWidgets/WidgetSlider.vue | 22 ++- .../graph/vueWidgets/WidgetToggleSwitch.vue | 22 ++- src/composables/graph/useGraphNodeManager.ts | 142 +++++++++++++++++- src/composables/graph/useWidgetValue.ts | 138 +++++++++++++++++ 7 files changed, 349 insertions(+), 23 deletions(-) create mode 100644 src/composables/graph/useWidgetValue.ts diff --git a/src/components/graph/vueNodes/NodeWidgets.vue b/src/components/graph/vueNodes/NodeWidgets.vue index 30e766da2..aa60ea0c9 100644 --- a/src/components/graph/vueNodes/NodeWidgets.vue +++ b/src/components/graph/vueNodes/NodeWidgets.vue @@ -123,12 +123,11 @@ const simplifiedWidget = (widget: SafeWidgetData): SimplifiedWidget => { // Handle widget value updates const handleWidgetUpdate = (widget: SafeWidgetData, value: unknown) => { - widget.value = value - + // Call LiteGraph callback to update the authoritative state + // The callback will trigger the chained callback in useGraphNodeManager + // which will update the Vue state automatically if (widget.callback) { widget.callback(value) } - - // TODO: Implement proper widget change handling to sync back to LiteGraph } diff --git a/src/components/graph/vueWidgets/WidgetInputText.vue b/src/components/graph/vueWidgets/WidgetInputText.vue index 462957335..0c648d927 100644 --- a/src/components/graph/vueWidgets/WidgetInputText.vue +++ b/src/components/graph/vueWidgets/WidgetInputText.vue @@ -3,7 +3,12 @@ - + @@ -16,14 +21,25 @@ import { INPUT_EXCLUDED_PROPS, filterWidgetProps } from '@/utils/widgetPropFilter' - -const value = defineModel({ required: true }) +import { useStringWidgetValue } from '@/composables/graph/useWidgetValue' const props = defineProps<{ widget: SimplifiedWidget + modelValue: string readonly?: boolean }>() +const emit = defineEmits<{ + 'update:modelValue': [value: string] +}>() + +// Use the composable for consistent widget value handling +const { localValue, onChange } = useStringWidgetValue( + props.widget, + props.modelValue, + emit +) + const filteredProps = computed(() => filterWidgetProps(props.widget.options, INPUT_EXCLUDED_PROPS) ) diff --git a/src/components/graph/vueWidgets/WidgetSelect.vue b/src/components/graph/vueWidgets/WidgetSelect.vue index 2639c2e64..fd6ad317c 100644 --- a/src/components/graph/vueWidgets/WidgetSelect.vue +++ b/src/components/graph/vueWidgets/WidgetSelect.vue @@ -4,10 +4,11 @@ widget.name }}