Type addDOMWidget (#2705)

This commit is contained in:
bymyself
2025-02-24 08:32:43 -07:00
committed by GitHub
parent 97f9d654b6
commit 81102604f5
3 changed files with 18 additions and 6 deletions

View File

@@ -28,6 +28,12 @@ export interface DOMWidget<T extends HTMLElement, V extends object | string>
options: DOMWidgetOptions<T, V>
value: V
y?: number
/**
* @deprecated Legacy property used by some extensions for customtext
* (textarea) widgets. Use `element` instead as it provides the same
* functionality and works for all DOMWidget types.
*/
inputEl?: T
callback?: (value: V) => void
/**
* Draw the widget on the canvas.

View File

@@ -432,11 +432,14 @@ export const useLitegraphService = () => {
host.el,
{
host,
// @ts-expect-error `getHeight` of image host returns void instead of number.
getHeight: host.getHeight,
onDraw: host.onDraw,
hideOnZoom: false
}
)
) as IWidget & {
options: { host: ReturnType<typeof createImageHost> }
}
widget.serializeValue = () => undefined
widget.options.host.updateImages(this.imgs)
}

View File

@@ -1,7 +1,7 @@
import '@comfyorg/litegraph'
import type { LLink, Size } from '@comfyorg/litegraph'
import type { DOMWidget } from '@/scripts/domWidget'
import type { DOMWidget, DOMWidgetOptions } from '@/scripts/domWidget'
import type { ComfyNodeDef } from '@/types/apiTypes'
import type { NodeId } from './comfyWorkflow'
@@ -112,12 +112,15 @@ declare module '@comfyorg/litegraph' {
*/
isVirtualNode?: boolean
addDOMWidget(
addDOMWidget<
T extends HTMLElement = HTMLElement,
V extends object | string = string
>(
name: string,
type: string,
element: HTMLElement,
options?: Record<string, any>
): DOMWidget
element: T,
options?: DOMWidgetOptions<T, V>
): DOMWidget<T, V>
animatedImages?: boolean
imgs?: HTMLImageElement[]