Use V2 schema in widget constructors (Part 1) (#2860)

This commit is contained in:
Chenlei Hu
2025-03-04 17:22:13 -05:00
committed by GitHub
parent 89b73429b7
commit 6255cea181
6 changed files with 139 additions and 135 deletions

View File

@@ -1,28 +1,33 @@
import type { LGraphNode } from '@comfyorg/litegraph'
import { type InputSpec, isBooleanInputSpec } from '@/schemas/nodeDefSchema'
import type { ComfyWidgetConstructor } from '@/scripts/widgets'
import {
type InputSpec,
isBooleanInputSpec
} from '@/schemas/nodeDef/nodeDefSchemaV2'
import { type ComfyWidgetConstructorV2 } from '@/scripts/widgets'
export const useBooleanWidget = () => {
const widgetConstructor: ComfyWidgetConstructor = (
const widgetConstructor: ComfyWidgetConstructorV2 = (
node: LGraphNode,
inputName: string,
inputData: InputSpec
inputSpec: InputSpec
) => {
if (!isBooleanInputSpec(inputData)) {
throw new Error(`Invalid input data: ${inputData}`)
if (!isBooleanInputSpec(inputSpec)) {
throw new Error(`Invalid input data: ${inputSpec}`)
}
const inputOptions = inputData[1] ?? {}
const defaultVal = inputOptions?.default ?? false
const defaultVal = inputSpec.default ?? false
const options = {
on: inputOptions?.label_on,
off: inputOptions?.label_off
on: inputSpec.label_on,
off: inputSpec.label_off
}
return {
widget: node.addWidget('toggle', inputName, defaultVal, () => {}, options)
}
return node.addWidget(
'toggle',
inputSpec.name,
defaultVal,
() => {},
options
)
}
return widgetConstructor