Update widget types to match Litegraph changes (#3808)

This commit is contained in:
filtered
2025-05-08 06:56:53 +10:00
committed by GitHub
parent 6fdef0308b
commit 3aea2c120a
11 changed files with 45 additions and 44 deletions

View File

@@ -5,7 +5,8 @@ import {
LGraphNode,
LiteGraph
} from '@comfyorg/litegraph'
import type { IWidget, Vector2 } from '@comfyorg/litegraph'
import type { Vector2 } from '@comfyorg/litegraph'
import type { IBaseWidget } from '@comfyorg/litegraph/dist/types/widgets'
import _ from 'lodash'
import type { ToastMessageOptions } from 'primevue/toast'
import { reactive } from 'vue'
@@ -94,7 +95,7 @@ function sanitizeNodeName(string: string) {
}
type Clipspace = {
widgets?: Pick<IWidget, 'type' | 'name' | 'value'>[] | null
widgets?: Pick<IBaseWidget, 'type' | 'name' | 'value'>[] | null
imgs?: HTMLImageElement[] | null
original_imgs?: HTMLImageElement[] | null
images?: any[] | null
@@ -387,7 +388,6 @@ export class ComfyApp {
const index = node.widgets.findIndex((obj) => obj.name === 'image')
if (index >= 0) {
if (
// @ts-expect-error custom widget type
node.widgets[index].type != 'image' &&
typeof node.widgets[index].value == 'string' &&
clip_image.filename
@@ -409,7 +409,6 @@ export class ComfyApp {
)
if (prop && prop.type != 'button') {
if (
// @ts-expect-error Custom widget type
prop.type != 'image' &&
typeof prop.value == 'string' &&
// @ts-expect-error Custom widget value
@@ -421,7 +420,6 @@ export class ComfyApp {
resultItem.filename +
(resultItem.type ? ` [${resultItem.type}]` : '')
} else {
// @ts-expect-error fixme ts strict error
prop.value = value
prop.callback?.(value)
}
@@ -1101,10 +1099,8 @@ export class ComfyApp {
) {
if (widget.name == 'control_after_generate') {
if (widget.value === true) {
// @ts-expect-error string is not assignable to boolean
widget.value = 'randomize'
} else if (widget.value === false) {
// @ts-expect-error string is not assignable to boolean
widget.value = 'fixed'
}
}
@@ -1535,10 +1531,8 @@ export class ComfyApp {
for (const widget of node.widgets) {
if (widget.type === 'combo') {
if (def['input'].required?.[widget.name] !== undefined) {
// @ts-expect-error Requires discriminated union
widget.options.values = def['input'].required[widget.name][0]
} else if (def['input'].optional?.[widget.name] !== undefined) {
// @ts-expect-error Requires discriminated union
widget.options.values = def['input'].optional[widget.name][0]
}
}

View File

@@ -1,7 +1,7 @@
import { LGraphNode, LiteGraph } from '@comfyorg/litegraph'
import type {
IBaseWidget,
ICustomWidget,
IWidget,
IWidgetOptions
} from '@comfyorg/litegraph/dist/types/widgets'
import _ from 'lodash'
@@ -81,11 +81,11 @@ export interface DOMWidgetOptions<V extends object | string>
}
export const isDOMWidget = <T extends HTMLElement, V extends object | string>(
widget: IWidget
widget: IBaseWidget
): widget is DOMWidget<T, V> => 'element' in widget && !!widget.element
export const isComponentWidget = <V extends object | string>(
widget: IWidget
widget: IBaseWidget
): widget is ComponentWidget<V> => 'component' in widget && !!widget.component
abstract class BaseDOMWidgetImpl<V extends object | string>

View File

@@ -1,4 +1,5 @@
import { IWidget, LGraphNode } from '@comfyorg/litegraph'
import { LGraphNode } from '@comfyorg/litegraph'
import type { IBaseWidget } from '@comfyorg/litegraph/dist/types/widgets'
import { useChainCallback } from '@/composables/functional/useChainCallback'
import { useBooleanWidget } from '@/composables/widgets/useBooleanWidget'
@@ -10,7 +11,7 @@ const FloatWidget = useFloatWidget()
const BooleanWidget = useBooleanWidget()
function addWidgetFromValue(node: LGraphNode, value: unknown) {
let widget: IWidget
let widget: IBaseWidget
if (typeof value === 'string') {
widget = StringWidget(node, {

View File

@@ -1,6 +1,6 @@
import type { LGraphNode } from '@comfyorg/litegraph'
import type { IWidget } from '@comfyorg/litegraph'
import { type LGraphNode, isComboWidget } from '@comfyorg/litegraph'
import type {
IBaseWidget,
IComboWidget,
IStringWidget
} from '@comfyorg/litegraph/dist/types/widgets'
@@ -25,7 +25,7 @@ import './errorNodeWidgets'
export type ComfyWidgetConstructorV2 = (
node: LGraphNode,
inputSpec: InputSpecV2
) => IWidget
) => IBaseWidget
export type ComfyWidgetConstructor = (
node: LGraphNode,
@@ -33,7 +33,7 @@ export type ComfyWidgetConstructor = (
inputData: InputSpec,
app: ComfyApp,
widgetName?: string
) => { widget: IWidget; minWidth?: number; minHeight?: number }
) => { widget: IBaseWidget; minWidth?: number; minHeight?: number }
/**
* Transforms a V2 widget constructor to a V1 widget constructor.
@@ -60,7 +60,7 @@ function controlValueRunBefore() {
return useSettingStore().get('Comfy.WidgetControlMode') === 'before'
}
export function updateControlWidgetLabel(widget: IWidget) {
export function updateControlWidgetLabel(widget: IBaseWidget) {
if (controlValueRunBefore()) {
widget.label = t('g.control_before_generate')
} else {
@@ -73,7 +73,7 @@ const HAS_EXECUTED = Symbol()
export function addValueControlWidget(
node: LGraphNode,
targetWidget: IWidget,
targetWidget: IBaseWidget,
defaultValue?: string,
_values?: unknown,
widgetName?: string,
@@ -98,7 +98,7 @@ export function addValueControlWidget(
export function addValueControlWidgets(
node: LGraphNode,
targetWidget: IWidget,
targetWidget: IBaseWidget,
defaultValue?: string,
options?: Record<string, any>,
inputData?: InputSpec
@@ -136,7 +136,7 @@ export function addValueControlWidgets(
updateControlWidgetLabel(valueControl)
const widgets: [IComboWidget, ...IStringWidget[]] = [valueControl]
const isCombo = targetWidget.type === 'combo'
const isCombo = isComboWidget(targetWidget)
let comboFilter: IStringWidget
if (isCombo && valueControl.options.values) {
// @ts-expect-error Combo widget values may be a dictionary or legacy function type