Skip to content

Commit 3aea2c1

Browse files
authored
Update widget types to match Litegraph changes (#3808)
1 parent 6fdef03 commit 3aea2c1

File tree

11 files changed

+45
-44
lines changed

11 files changed

+45
-44
lines changed

src/composables/useRefreshableSelection.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import type { IWidget, LGraphNode } from '@comfyorg/litegraph'
1+
import type { LGraphNode } from '@comfyorg/litegraph'
2+
import type { IBaseWidget } from '@comfyorg/litegraph/dist/types/widgets'
23
import { computed, ref, watchEffect } from 'vue'
34

45
import { useCanvasStore } from '@/stores/graphStore'
@@ -8,9 +9,11 @@ interface RefreshableItem {
89
refresh: () => Promise<void> | void
910
}
1011

11-
type RefreshableWidget = IWidget & RefreshableItem
12+
type RefreshableWidget = IBaseWidget & RefreshableItem
1213

13-
const isRefreshableWidget = (widget: IWidget): widget is RefreshableWidget =>
14+
const isRefreshableWidget = (
15+
widget: IBaseWidget
16+
): widget is RefreshableWidget =>
1417
'refresh' in widget && typeof widget.refresh === 'function'
1518

1619
/**

src/extensions/core/contextMenuFilter.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { LGraphCanvas, LiteGraph } from '@comfyorg/litegraph'
1+
import { LGraphCanvas, LiteGraph, isComboWidget } from '@comfyorg/litegraph'
22

33
import { app } from '../../scripts/app'
44

@@ -33,7 +33,7 @@ const ext = {
3333
const clickedComboValue = currentNode?.widgets
3434
?.filter(
3535
(w) =>
36-
w.type === 'combo' && w.options.values?.length === values.length
36+
isComboWidget(w) && w.options.values?.length === values.length
3737
)
3838
.find((w) =>
3939
// @ts-expect-error Poorly typed; filter above "should" mitigate exceptions

src/extensions/core/groupNode.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1231,7 +1231,6 @@ export class GroupNodeHandler {
12311231
const widgetName = self.groupData.oldToNewWidgetMap[n][w]
12321232
const widget = this.widgets.find((w) => w.name === widgetName)
12331233
if (widget) {
1234-
// @ts-expect-error fixme ts strict error
12351234
widget.type = 'hidden'
12361235
widget.computeSize = () => [0, -4]
12371236
}

src/extensions/core/load3d.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
import type { IStringWidget } from '@comfyorg/litegraph/dist/types/widgets'
1+
import type {
2+
IComboWidget,
3+
IStringWidget
4+
} from '@comfyorg/litegraph/dist/types/widgets'
25
import { nextTick } from 'vue'
36

47
import Load3D from '@/components/load3d/Load3D.vue'
@@ -116,7 +119,7 @@ useExtensionService().registerExtension({
116119
if (fileInput.files?.length) {
117120
const modelWidget = node.widgets?.find(
118121
(w) => w.name === 'model_file'
119-
) as IStringWidget
122+
) as IComboWidget & { options: { values: string[] } }
120123

121124
node.properties['Texture'] = undefined
122125

@@ -138,7 +141,6 @@ useExtensionService().registerExtension({
138141

139142
if (uploadPath && modelWidget) {
140143
if (!modelWidget.options?.values?.includes(uploadPath)) {
141-
// @ts-expect-error Fails due to earlier type-assertion of IStringWidget
142144
modelWidget.options?.values?.push(uploadPath)
143145
}
144146

@@ -292,7 +294,6 @@ useExtensionService().registerExtension({
292294

293295
if (uploadPath && modelWidget) {
294296
if (!modelWidget.options?.values?.includes(uploadPath)) {
295-
// @ts-expect-error Fails due to earlier type-assertion of IStringWidget
296297
modelWidget.options?.values?.push(uploadPath)
297298
}
298299

src/extensions/core/load3d/Load3DConfiguration.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { IWidget } from '@comfyorg/litegraph'
1+
import type { IBaseWidget } from '@comfyorg/litegraph/dist/types/widgets'
22

33
import Load3d from '@/extensions/core/load3d/Load3d'
44
import Load3dUtils from '@/extensions/core/load3d/Load3dUtils'
@@ -15,17 +15,20 @@ class Load3DConfiguration {
1515

1616
configure(
1717
loadFolder: 'input' | 'output',
18-
modelWidget: IWidget,
18+
modelWidget: IBaseWidget,
1919
cameraState?: any,
20-
width: IWidget | null = null,
21-
height: IWidget | null = null
20+
width: IBaseWidget | null = null,
21+
height: IBaseWidget | null = null
2222
) {
2323
this.setupModelHandling(modelWidget, loadFolder, cameraState)
2424
this.setupTargetSize(width, height)
2525
this.setupDefaultProperties()
2626
}
2727

28-
private setupTargetSize(width: IWidget | null, height: IWidget | null) {
28+
private setupTargetSize(
29+
width: IBaseWidget | null,
30+
height: IBaseWidget | null
31+
) {
2932
if (width && height) {
3033
this.load3d.setTargetSize(width.value as number, height.value as number)
3134

@@ -51,7 +54,7 @@ class Load3DConfiguration {
5154
}
5255

5356
private setupModelHandling(
54-
modelWidget: IWidget,
57+
modelWidget: IBaseWidget,
5558
loadFolder: 'input' | 'output',
5659
cameraState?: any
5760
) {

src/extensions/core/widgetInputs.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ import type {
33
INodeInputSlot,
44
INodeOutputSlot,
55
ISlotType,
6-
IWidget,
76
LLink,
87
Vector2
98
} from '@comfyorg/litegraph'
109
import type { CanvasMouseEvent } from '@comfyorg/litegraph/dist/types/events'
10+
import type { IBaseWidget } from '@comfyorg/litegraph/dist/types/widgets'
1111

1212
import {
1313
type CallbackParams,
@@ -226,7 +226,7 @@ export class PrimitiveNode extends LGraphNode {
226226

227227
// Store current size as addWidget resizes the node
228228
const [oldWidth, oldHeight] = this.size
229-
let widget: IWidget | undefined
229+
let widget: IBaseWidget | undefined
230230
if (type in ComfyWidgets) {
231231
widget = (ComfyWidgets[type](this, 'value', inputData, app) || {}).widget
232232
} else {
@@ -426,7 +426,7 @@ function getConfig(this: LGraphNode, widgetName: string) {
426426
*/
427427
export function convertToInput(
428428
node: LGraphNode,
429-
widget: IWidget
429+
widget: IBaseWidget
430430
): INodeInputSlot | undefined {
431431
console.warn(
432432
'Please remove call to convertToInput. Widget to socket conversion is no longer necessary, as they co-exist now.'

src/scripts/app.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import {
55
LGraphNode,
66
LiteGraph
77
} from '@comfyorg/litegraph'
8-
import type { IWidget, Vector2 } from '@comfyorg/litegraph'
8+
import type { Vector2 } from '@comfyorg/litegraph'
9+
import type { IBaseWidget } from '@comfyorg/litegraph/dist/types/widgets'
910
import _ from 'lodash'
1011
import type { ToastMessageOptions } from 'primevue/toast'
1112
import { reactive } from 'vue'
@@ -94,7 +95,7 @@ function sanitizeNodeName(string: string) {
9495
}
9596

9697
type Clipspace = {
97-
widgets?: Pick<IWidget, 'type' | 'name' | 'value'>[] | null
98+
widgets?: Pick<IBaseWidget, 'type' | 'name' | 'value'>[] | null
9899
imgs?: HTMLImageElement[] | null
99100
original_imgs?: HTMLImageElement[] | null
100101
images?: any[] | null
@@ -387,7 +388,6 @@ export class ComfyApp {
387388
const index = node.widgets.findIndex((obj) => obj.name === 'image')
388389
if (index >= 0) {
389390
if (
390-
// @ts-expect-error custom widget type
391391
node.widgets[index].type != 'image' &&
392392
typeof node.widgets[index].value == 'string' &&
393393
clip_image.filename
@@ -409,7 +409,6 @@ export class ComfyApp {
409409
)
410410
if (prop && prop.type != 'button') {
411411
if (
412-
// @ts-expect-error Custom widget type
413412
prop.type != 'image' &&
414413
typeof prop.value == 'string' &&
415414
// @ts-expect-error Custom widget value
@@ -421,7 +420,6 @@ export class ComfyApp {
421420
resultItem.filename +
422421
(resultItem.type ? ` [${resultItem.type}]` : '')
423422
} else {
424-
// @ts-expect-error fixme ts strict error
425423
prop.value = value
426424
prop.callback?.(value)
427425
}
@@ -1101,10 +1099,8 @@ export class ComfyApp {
11011099
) {
11021100
if (widget.name == 'control_after_generate') {
11031101
if (widget.value === true) {
1104-
// @ts-expect-error string is not assignable to boolean
11051102
widget.value = 'randomize'
11061103
} else if (widget.value === false) {
1107-
// @ts-expect-error string is not assignable to boolean
11081104
widget.value = 'fixed'
11091105
}
11101106
}
@@ -1535,10 +1531,8 @@ export class ComfyApp {
15351531
for (const widget of node.widgets) {
15361532
if (widget.type === 'combo') {
15371533
if (def['input'].required?.[widget.name] !== undefined) {
1538-
// @ts-expect-error Requires discriminated union
15391534
widget.options.values = def['input'].required[widget.name][0]
15401535
} else if (def['input'].optional?.[widget.name] !== undefined) {
1541-
// @ts-expect-error Requires discriminated union
15421536
widget.options.values = def['input'].optional[widget.name][0]
15431537
}
15441538
}

src/scripts/domWidget.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { LGraphNode, LiteGraph } from '@comfyorg/litegraph'
22
import type {
3+
IBaseWidget,
34
ICustomWidget,
4-
IWidget,
55
IWidgetOptions
66
} from '@comfyorg/litegraph/dist/types/widgets'
77
import _ from 'lodash'
@@ -81,11 +81,11 @@ export interface DOMWidgetOptions<V extends object | string>
8181
}
8282

8383
export const isDOMWidget = <T extends HTMLElement, V extends object | string>(
84-
widget: IWidget
84+
widget: IBaseWidget
8585
): widget is DOMWidget<T, V> => 'element' in widget && !!widget.element
8686

8787
export const isComponentWidget = <V extends object | string>(
88-
widget: IWidget
88+
widget: IBaseWidget
8989
): widget is ComponentWidget<V> => 'component' in widget && !!widget.component
9090

9191
abstract class BaseDOMWidgetImpl<V extends object | string>

src/scripts/errorNodeWidgets.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { IWidget, LGraphNode } from '@comfyorg/litegraph'
1+
import { LGraphNode } from '@comfyorg/litegraph'
2+
import type { IBaseWidget } from '@comfyorg/litegraph/dist/types/widgets'
23

34
import { useChainCallback } from '@/composables/functional/useChainCallback'
45
import { useBooleanWidget } from '@/composables/widgets/useBooleanWidget'
@@ -10,7 +11,7 @@ const FloatWidget = useFloatWidget()
1011
const BooleanWidget = useBooleanWidget()
1112

1213
function addWidgetFromValue(node: LGraphNode, value: unknown) {
13-
let widget: IWidget
14+
let widget: IBaseWidget
1415

1516
if (typeof value === 'string') {
1617
widget = StringWidget(node, {

src/scripts/widgets.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import type { LGraphNode } from '@comfyorg/litegraph'
2-
import type { IWidget } from '@comfyorg/litegraph'
1+
import { type LGraphNode, isComboWidget } from '@comfyorg/litegraph'
32
import type {
3+
IBaseWidget,
44
IComboWidget,
55
IStringWidget
66
} from '@comfyorg/litegraph/dist/types/widgets'
@@ -25,15 +25,15 @@ import './errorNodeWidgets'
2525
export type ComfyWidgetConstructorV2 = (
2626
node: LGraphNode,
2727
inputSpec: InputSpecV2
28-
) => IWidget
28+
) => IBaseWidget
2929

3030
export type ComfyWidgetConstructor = (
3131
node: LGraphNode,
3232
inputName: string,
3333
inputData: InputSpec,
3434
app: ComfyApp,
3535
widgetName?: string
36-
) => { widget: IWidget; minWidth?: number; minHeight?: number }
36+
) => { widget: IBaseWidget; minWidth?: number; minHeight?: number }
3737

3838
/**
3939
* Transforms a V2 widget constructor to a V1 widget constructor.
@@ -60,7 +60,7 @@ function controlValueRunBefore() {
6060
return useSettingStore().get('Comfy.WidgetControlMode') === 'before'
6161
}
6262

63-
export function updateControlWidgetLabel(widget: IWidget) {
63+
export function updateControlWidgetLabel(widget: IBaseWidget) {
6464
if (controlValueRunBefore()) {
6565
widget.label = t('g.control_before_generate')
6666
} else {
@@ -73,7 +73,7 @@ const HAS_EXECUTED = Symbol()
7373

7474
export function addValueControlWidget(
7575
node: LGraphNode,
76-
targetWidget: IWidget,
76+
targetWidget: IBaseWidget,
7777
defaultValue?: string,
7878
_values?: unknown,
7979
widgetName?: string,
@@ -98,7 +98,7 @@ export function addValueControlWidget(
9898

9999
export function addValueControlWidgets(
100100
node: LGraphNode,
101-
targetWidget: IWidget,
101+
targetWidget: IBaseWidget,
102102
defaultValue?: string,
103103
options?: Record<string, any>,
104104
inputData?: InputSpec
@@ -136,7 +136,7 @@ export function addValueControlWidgets(
136136
updateControlWidgetLabel(valueControl)
137137
const widgets: [IComboWidget, ...IStringWidget[]] = [valueControl]
138138

139-
const isCombo = targetWidget.type === 'combo'
139+
const isCombo = isComboWidget(targetWidget)
140140
let comboFilter: IStringWidget
141141
if (isCombo && valueControl.options.values) {
142142
// @ts-expect-error Combo widget values may be a dictionary or legacy function type

0 commit comments

Comments
 (0)