mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-02-04 15:10:06 +00:00
Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: Benjamin Lu <benceruleanlu@proton.me> Co-authored-by: github-actions <github-actions@github.com>
26 lines
868 B
TypeScript
26 lines
868 B
TypeScript
import type {
|
|
InputSpec as InputSpecV2,
|
|
TreeSelectInputSpec
|
|
} from '@/schemas/nodeDef/nodeDefSchemaV2'
|
|
import type { ComfyWidgetConstructorV2 } from '@/scripts/widgets'
|
|
|
|
import type { LGraphNode } from '../../lib/litegraph/src/litegraph'
|
|
import type { ITreeSelectWidget } from '../../lib/litegraph/src/types/widgets'
|
|
|
|
export const useTreeSelectWidget = (): ComfyWidgetConstructorV2 => {
|
|
return (node: LGraphNode, inputSpec: InputSpecV2): ITreeSelectWidget => {
|
|
const { name, options = {} } = inputSpec as TreeSelectInputSpec
|
|
const isMultiple = options.multiple || false
|
|
const defaultValue = isMultiple ? [] : ''
|
|
|
|
const widget = node.addWidget('treeselect', name, defaultValue, () => {}, {
|
|
serialize: true,
|
|
values: options.values || [],
|
|
multiple: isMultiple,
|
|
...options
|
|
}) as ITreeSelectWidget
|
|
|
|
return widget
|
|
}
|
|
}
|