Line data Source code
1 : import type { LGraphNode } from '@/lib/litegraph/src/litegraph'
2 : import type { ITextareaWidget } from '@comfyorg/graph-model/widgets'
3 : import { isTextareaInputSpec } from '@comfyorg/object-info-parser/schemas/nodeDefSchemaV2'
4 : import type {
5 : InputSpec as InputSpecV2,
6 : TextareaInputSpec
7 : } from '@comfyorg/object-info-parser/schemas/nodeDefSchemaV2'
8 : import type { ComfyWidgetConstructorV2 } from '@/types/widgetConstructor'
9 :
10 2356 : export const useTextareaWidget = (): ComfyWidgetConstructorV2 => {
11 2356 : return (node: LGraphNode, inputSpec: InputSpecV2): ITextareaWidget => {
12 0 : if (!isTextareaInputSpec(inputSpec)) {
13 0 : console.error('Invalid input spec for textarea widget')
14 : }
15 :
16 0 : const textareaSpec = inputSpec as TextareaInputSpec
17 0 : const { name, options } = textareaSpec
18 0 : const defaultValue = textareaSpec.default ?? options?.default ?? ''
19 : const rows = textareaSpec.rows ?? options?.rows ?? 5
20 : const cols = textareaSpec.cols ?? options?.cols ?? 50
21 :
22 0 : const widgetOptions = { rows, cols }
23 :
24 : const widget = node.addWidget('textarea', name, defaultValue, () => {}, {
25 : serialize: true,
26 : ...widgetOptions
27 : }) as ITextareaWidget
28 :
29 0 : return widget
30 : }
31 : }
|