Skip to content

Commit 00dec90

Browse files
committed
Tentatively add rest of widget composables
1 parent ee7fa62 commit 00dec90

8 files changed

+195
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import type { LGraphNode } from '@comfyorg/litegraph'
2+
import type { IFileUploadWidget } from '@comfyorg/litegraph/dist/types/widgets'
3+
4+
import type {
5+
FileUploadInputSpec,
6+
InputSpec as InputSpecV2
7+
} from '@/schemas/nodeDef/nodeDefSchemaV2'
8+
import type { ComfyWidgetConstructorV2 } from '@/scripts/widgets'
9+
10+
export const useFileUploadWidget = (): ComfyWidgetConstructorV2 => {
11+
return (node: LGraphNode, inputSpec: InputSpecV2): IFileUploadWidget => {
12+
const { name, options = {} } = inputSpec as FileUploadInputSpec
13+
14+
const widget = node.addWidget('fileupload', name, '', () => {}, {
15+
serialize: true,
16+
...(options as Record<string, unknown>)
17+
}) as IFileUploadWidget
18+
19+
return widget
20+
}
21+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import type { LGraphNode } from '@comfyorg/litegraph'
2+
import type { IGalleriaWidget } from '@comfyorg/litegraph/dist/types/widgets'
3+
4+
import type {
5+
GalleriaInputSpec,
6+
InputSpec as InputSpecV2
7+
} from '@/schemas/nodeDef/nodeDefSchemaV2'
8+
import type { ComfyWidgetConstructorV2 } from '@/scripts/widgets'
9+
10+
export const useGalleriaWidget = (): ComfyWidgetConstructorV2 => {
11+
return (node: LGraphNode, inputSpec: InputSpecV2): IGalleriaWidget => {
12+
const { name, options = {} } = inputSpec as GalleriaInputSpec
13+
14+
const widget = node.addWidget(
15+
'galleria',
16+
name,
17+
options.images || [],
18+
() => {},
19+
{
20+
serialize: true,
21+
...options
22+
}
23+
) as IGalleriaWidget
24+
25+
return widget
26+
}
27+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import type { LGraphNode } from '@comfyorg/litegraph'
2+
import type { IImageCompareWidget } from '@comfyorg/litegraph/dist/types/widgets'
3+
4+
import type {
5+
ImageCompareInputSpec,
6+
InputSpec as InputSpecV2
7+
} from '@/schemas/nodeDef/nodeDefSchemaV2'
8+
import type { ComfyWidgetConstructorV2 } from '@/scripts/widgets'
9+
10+
export const useImageCompareWidget = (): ComfyWidgetConstructorV2 => {
11+
return (node: LGraphNode, inputSpec: InputSpecV2): IImageCompareWidget => {
12+
const { name, options = {} } = inputSpec as ImageCompareInputSpec
13+
14+
const widget = node.addWidget('imagecompare', name, ['', ''], () => {}, {
15+
serialize: true,
16+
...options
17+
}) as IImageCompareWidget
18+
19+
return widget
20+
}
21+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import type { LGraphNode } from '@comfyorg/litegraph'
2+
import type { IImageWidget } from '@comfyorg/litegraph/dist/types/widgets'
3+
4+
import type {
5+
ImageInputSpec,
6+
InputSpec as InputSpecV2
7+
} from '@/schemas/nodeDef/nodeDefSchemaV2'
8+
import type { ComfyWidgetConstructorV2 } from '@/scripts/widgets'
9+
10+
export const useImageWidget = (): ComfyWidgetConstructorV2 => {
11+
return (node: LGraphNode, inputSpec: InputSpecV2): IImageWidget => {
12+
const { name, options = {} } = inputSpec as ImageInputSpec
13+
14+
const widget = node.addWidget('image', name, '', () => {}, {
15+
serialize: true,
16+
...options
17+
}) as IImageWidget
18+
19+
return widget
20+
}
21+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import type { LGraphNode } from '@comfyorg/litegraph'
2+
import type { IMultiSelectWidget } from '@comfyorg/litegraph/dist/types/widgets'
3+
4+
import type {
5+
InputSpec as InputSpecV2,
6+
MultiSelectInputSpec
7+
} from '@/schemas/nodeDef/nodeDefSchemaV2'
8+
import type { ComfyWidgetConstructorV2 } from '@/scripts/widgets'
9+
10+
export const useMultiSelectWidget = (): ComfyWidgetConstructorV2 => {
11+
return (node: LGraphNode, inputSpec: InputSpecV2): IMultiSelectWidget => {
12+
const { name, options = {} } = inputSpec as MultiSelectInputSpec
13+
14+
const widget = node.addWidget('multiselect', name, [], () => {}, {
15+
serialize: true,
16+
values: options.values || [],
17+
...options
18+
}) as IMultiSelectWidget
19+
20+
return widget
21+
}
22+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import type { LGraphNode } from '@comfyorg/litegraph'
2+
import type { ISelectButtonWidget } from '@comfyorg/litegraph/dist/types/widgets'
3+
4+
import type {
5+
InputSpec as InputSpecV2,
6+
SelectButtonInputSpec
7+
} from '@/schemas/nodeDef/nodeDefSchemaV2'
8+
import type { ComfyWidgetConstructorV2 } from '@/scripts/widgets'
9+
10+
export const useSelectButtonWidget = (): ComfyWidgetConstructorV2 => {
11+
return (node: LGraphNode, inputSpec: InputSpecV2): ISelectButtonWidget => {
12+
const { name, options = {} } = inputSpec as SelectButtonInputSpec
13+
const values = options.values || []
14+
15+
const widget = node.addWidget(
16+
'selectbutton',
17+
name,
18+
values[0] || '',
19+
(_value: string) => {},
20+
{
21+
serialize: true,
22+
values,
23+
...options
24+
}
25+
) as ISelectButtonWidget
26+
27+
return widget
28+
}
29+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import type { LGraphNode } from '@comfyorg/litegraph'
2+
import type { ITextareaWidget } from '@comfyorg/litegraph/dist/types/widgets'
3+
4+
import type {
5+
InputSpec as InputSpecV2,
6+
TextareaInputSpec
7+
} from '@/schemas/nodeDef/nodeDefSchemaV2'
8+
import type { ComfyWidgetConstructorV2 } from '@/scripts/widgets'
9+
10+
export const useTextareaWidget = (): ComfyWidgetConstructorV2 => {
11+
return (node: LGraphNode, inputSpec: InputSpecV2): ITextareaWidget => {
12+
const { name, options = {} } = inputSpec as TextareaInputSpec
13+
14+
const widget = node.addWidget(
15+
'textarea',
16+
name,
17+
options.default || '',
18+
() => {},
19+
{
20+
serialize: true,
21+
rows: options.rows || 5,
22+
cols: options.cols || 50,
23+
...options
24+
}
25+
) as ITextareaWidget
26+
27+
return widget
28+
}
29+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import type { LGraphNode } from '@comfyorg/litegraph'
2+
import type { ITreeSelectWidget } from '@comfyorg/litegraph/dist/types/widgets'
3+
4+
import type {
5+
InputSpec as InputSpecV2,
6+
TreeSelectInputSpec
7+
} from '@/schemas/nodeDef/nodeDefSchemaV2'
8+
import type { ComfyWidgetConstructorV2 } from '@/scripts/widgets'
9+
10+
export const useTreeSelectWidget = (): ComfyWidgetConstructorV2 => {
11+
return (node: LGraphNode, inputSpec: InputSpecV2): ITreeSelectWidget => {
12+
const { name, options = {} } = inputSpec as TreeSelectInputSpec
13+
const isMultiple = options.multiple || false
14+
const defaultValue = isMultiple ? [] : ''
15+
16+
const widget = node.addWidget('treeselect', name, defaultValue, () => {}, {
17+
serialize: true,
18+
values: options.values || [],
19+
multiple: isMultiple,
20+
...options
21+
}) as ITreeSelectWidget
22+
23+
return widget
24+
}
25+
}

0 commit comments

Comments
 (0)