From 04bd165acb8f98a582e4fb6890e092eea7b21aa2 Mon Sep 17 00:00:00 2001 From: bymyself Date: Tue, 21 Oct 2025 16:26:56 -0700 Subject: [PATCH] handle legacy step value --- src/composables/graph/useGraphNodeManager.ts | 85 +++++++++++++++++++- 1 file changed, 84 insertions(+), 1 deletion(-) diff --git a/src/composables/graph/useGraphNodeManager.ts b/src/composables/graph/useGraphNodeManager.ts index 24b2b1a64..3a951c5e9 100644 --- a/src/composables/graph/useGraphNodeManager.ts +++ b/src/composables/graph/useGraphNodeManager.ts @@ -18,6 +18,7 @@ import { isDOMWidget } from '@/scripts/domWidget' import { useNodeDefStore } from '@/stores/nodeDefStore' import type { WidgetValue } from '@/types/simplifiedWidget' +<<<<<<< HEAD import type { LGraph, LGraphBadge, @@ -32,6 +33,10 @@ export interface WidgetSlotMetadata { index: number linked: boolean } +======= +import type { LGraph, LGraphNode } from '../../lib/litegraph/src/litegraph' +import type { IBaseWidget } from '../../lib/litegraph/src/types/widgets' +>>>>>>> 06c19dad7 (handle legacy step value) export interface SafeWidgetData { name: string @@ -45,6 +50,11 @@ export interface SafeWidgetData { isDOMWidget?: boolean } +type NumericWidgetOptions = Record & { + step?: number + step2?: number +} + export interface VueNodeData { id: string title: string @@ -121,14 +131,39 @@ export function useGraphNodeManager(graph: LGraph): GraphNodeManager { // Extract safe data from LiteGraph node for Vue consumption function extractVueNodeData(node: LGraphNode): VueNodeData { + type NumericWidgetOptions = Record & { + step?: number + step2?: number + } + // Determine subgraph ID - null for root graph, string for subgraphs const subgraphId = node.graph && 'id' in node.graph && node.graph !== node.graph.rootGraph ? String(node.graph.id) : null + const cloneWidgetOptions = (widget: IBaseWidget) => { + const options = widget.options + ? ({ ...widget.options } as NumericWidgetOptions) + : undefined + if ( + options && + (widget.type === 'number' || widget.type === 'slider') && + options.step2 === undefined && + typeof options.step === 'number' + ) { + const baseStep = Number.isFinite(options.step) + ? (options.step as number) + : 10 + const legacyStep = baseStep === 0 ? 10 : baseStep + options.step2 = legacyStep * 0.1 + } + return options + } + // Extract safe widget data const slotMetadata = new Map() +<<<<<<< HEAD const reactiveWidgets = shallowReactive(node.widgets ?? []) Object.defineProperty(node, 'widgets', { get() { @@ -136,9 +171,57 @@ export function useGraphNodeManager(graph: LGraph): GraphNodeManager { }, set(v) { reactiveWidgets.splice(0, reactiveWidgets.length, ...v) +======= + // For combo widgets, if value is undefined, use the first option as default + if ( + value === undefined && + widget.type === 'combo' && + widget.options?.values && + Array.isArray(widget.options.values) && + widget.options.values.length > 0 + ) { + value = widget.options.values[0] + } + const spec = nodeDefStore.getInputSpecForWidget(node, widget.name) + + return { + name: widget.name, + type: widget.type, + value, + label: widget.label, + options: cloneWidgetOptions(widget), + callback: widget.callback, + spec + } + } catch (error) { + return { + name: widget.name || 'unknown', + type: widget.type || 'text', + value: undefined + } +>>>>>>> 06c19dad7 (handle legacy step value) } }) + const cloneWidgetOptions = (widget: IBaseWidget) => { + const options = widget.options + ? ({ ...widget.options } as NumericWidgetOptions) + : undefined + if ( + options && + (widget.type === 'number' || widget.type === 'slider') && + options.step2 === undefined && + typeof options.step === 'number' + ) { + const baseStep = Number.isFinite(options.step) + ? (options.step as number) + : 10 + const legacyStep = baseStep === 0 ? 10 : baseStep + options.step2 = legacyStep * 0.1 + } + return options + } + const safeWidgets = reactiveComputed(() => { node.inputs?.forEach((input, index) => { if (!input?.widget?.name) return @@ -171,7 +254,7 @@ export function useGraphNodeManager(graph: LGraph): GraphNodeManager { type: widget.type, value: value, label: widget.label, - options: widget.options ? { ...widget.options } : undefined, + options: cloneWidgetOptions(widget), callback: widget.callback, spec, slotMetadata: slotInfo,