mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-02-02 14:27:40 +00:00
handle legacy step value
This commit is contained in:
@@ -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<string, unknown> & {
|
||||
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<string, unknown> & {
|
||||
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<string, WidgetSlotMetadata>()
|
||||
|
||||
<<<<<<< HEAD
|
||||
const reactiveWidgets = shallowReactive<IBaseWidget[]>(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<SafeWidgetData[]>(() => {
|
||||
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,
|
||||
|
||||
Reference in New Issue
Block a user