1- import { LGraphNode , LiteGraph } from '@comfyorg/litegraph'
1+ import { LGraphNode , LegacyWidget , LiteGraph } from '@comfyorg/litegraph'
22import type {
33 IBaseWidget ,
4- ICustomWidget ,
54 IWidgetOptions
65} from '@comfyorg/litegraph/dist/types/widgets'
76import _ from 'lodash'
@@ -13,9 +12,9 @@ import { useDomWidgetStore } from '@/stores/domWidgetStore'
1312import { generateUUID } from '@/utils/formatUtil'
1413
1514export interface BaseDOMWidget < V extends object | string >
16- extends ICustomWidget {
15+ extends IBaseWidget < V , string , DOMWidgetOptions < V > > {
1716 // ICustomWidget properties
18- type : 'custom'
17+ type : string
1918 options : DOMWidgetOptions < V >
2019 value : V
2120 callback ?: ( value : V ) => void
@@ -89,39 +88,33 @@ export const isComponentWidget = <V extends object | string>(
8988) : widget is ComponentWidget < V > => 'component' in widget && ! ! widget . component
9089
9190abstract class BaseDOMWidgetImpl < V extends object | string >
91+ extends LegacyWidget < IBaseWidget < V , string , DOMWidgetOptions < V > > >
9292 implements BaseDOMWidget < V >
9393{
9494 static readonly DEFAULT_MARGIN = 10
95- readonly type : 'custom'
96- readonly name : string
97- readonly options : DOMWidgetOptions < V >
98- computedHeight ?: number
99- y : number = 0
100- callback ?: ( value : V ) => void
95+ declare readonly name : string
96+ declare readonly options : DOMWidgetOptions < V >
97+ declare callback ?: ( value : V ) => void
10198
10299 readonly id : string
103- readonly node : LGraphNode
104100
105101 constructor ( obj : {
106102 node : LGraphNode
107103 name : string
108104 type : string
109105 options : DOMWidgetOptions < V >
110106 } ) {
111- // @ts -expect-error custom widget type
112- this . type = obj . type
113- this . name = obj . name
114- this . options = obj . options
107+ const { node, name, type, options } = obj
108+ super ( { y : 0 , name, type, options } , node )
115109
116110 this . id = generateUUID ( )
117- this . node = obj . node
118111 }
119112
120- get value ( ) : V {
113+ override get value ( ) : V {
121114 return this . options . getValue ?.( ) ?? ( '' as V )
122115 }
123116
124- set value ( v : V ) {
117+ override set value ( v : V ) {
125118 this . options . setValue ?.( v )
126119 this . callback ?.( this . value )
127120 }
@@ -134,7 +127,7 @@ abstract class BaseDOMWidgetImpl<V extends object | string>
134127 return ! [ 'hidden' ] . includes ( this . type ) && this . node . isWidgetVisible ( this )
135128 }
136129
137- draw (
130+ override draw (
138131 ctx : CanvasRenderingContext2D ,
139132 _node : LGraphNode ,
140133 widget_width : number ,
@@ -168,7 +161,7 @@ export class DOMWidgetImpl<T extends HTMLElement, V extends object | string>
168161 extends BaseDOMWidgetImpl < V >
169162 implements DOMWidget < T , V >
170163{
171- readonly element : T
164+ override readonly element : T
172165
173166 constructor ( obj : {
174167 node : LGraphNode
@@ -183,7 +176,6 @@ export class DOMWidgetImpl<T extends HTMLElement, V extends object | string>
183176
184177 /** Extract DOM widget size info */
185178 computeLayoutSize ( node : LGraphNode ) {
186- // @ts -expect-error custom widget type
187179 if ( this . type === 'hidden' ) {
188180 return {
189181 minHeight : 0 ,
@@ -257,7 +249,7 @@ export class ComponentWidgetImpl<V extends object | string>
257249 }
258250 }
259251
260- serializeValue ( ) : V {
252+ override serializeValue ( ) : V {
261253 return toRaw ( this . value )
262254 }
263255}
0 commit comments