diff --git a/src/LGraphCanvas.ts b/src/LGraphCanvas.ts index 65c6b1782..cd64e95a5 100644 --- a/src/LGraphCanvas.ts +++ b/src/LGraphCanvas.ts @@ -2357,17 +2357,14 @@ export class LGraphCanvas implements ConnectionColorContext { const x = pos[0] - node.pos[0] const y = pos[1] - node.pos[1] - // @ts-expect-error https://github.com/Comfy-Org/litegraph.js/issues/616 const WidgetClass = WIDGET_TYPE_MAP[widget.type] if (WidgetClass) { const widgetInstance = toClass(WidgetClass, widget) - // @ts-expect-error https://github.com/Comfy-Org/litegraph.js/issues/616 pointer.onClick = () => widgetInstance.onClick({ e, node, canvas: this, }) - // @ts-expect-error https://github.com/Comfy-Org/litegraph.js/issues/616 pointer.onDrag = eMove => widgetInstance.onDrag?.({ e: eMove, node, diff --git a/src/LGraphNode.ts b/src/LGraphNode.ts index fc95fb64d..c3a70cd4f 100644 --- a/src/LGraphNode.ts +++ b/src/LGraphNode.ts @@ -1688,6 +1688,7 @@ export class LGraphNode implements Positionable, IPinnable, IColorable { value: value, callback: typeof callback !== "function" ? undefined : callback, options, + y: 0, } if (w.options.y !== undefined) { @@ -1708,7 +1709,6 @@ export class LGraphNode implements Positionable, IPinnable, IColorable { addCustomWidget(custom_widget: T): T { this.widgets ||= [] - // @ts-expect-error https://github.com/Comfy-Org/litegraph.js/issues/616 const WidgetClass = WIDGET_TYPE_MAP[custom_widget.type] const widget = WidgetClass ? new WidgetClass(custom_widget) as IWidget : custom_widget this.widgets.push(widget) @@ -3283,7 +3283,6 @@ export class LGraphNode implements Positionable, IPinnable, IColorable { // @ts-expect-error https://github.com/Comfy-Org/litegraph.js/issues/616 type: linkOverWidgetType, link: 0, - // @ts-expect-error https://github.com/Comfy-Org/litegraph.js/issues/616 }).draw(ctx, { pos: [10, y + 10], colorContext }) } @@ -3294,13 +3293,10 @@ export class LGraphNode implements Positionable, IPinnable, IColorable { if (w.disabled) ctx.globalAlpha *= 0.5 const widget_width = w.width || width - // @ts-expect-error https://github.com/Comfy-Org/litegraph.js/issues/616 const WidgetClass: typeof WIDGET_TYPE_MAP[string] = WIDGET_TYPE_MAP[w.type] if (WidgetClass) { - // @ts-expect-error https://github.com/Comfy-Org/litegraph.js/issues/616 toClass(WidgetClass, w).drawWidget(ctx, { y, width: widget_width, show_text, margin }) } else { - // @ts-expect-error https://github.com/Comfy-Org/litegraph.js/issues/616 w.draw?.(ctx, this, widget_width, y, H) } ctx.globalAlpha = editorAlpha @@ -3552,7 +3548,6 @@ export class LGraphNode implements Positionable, IPinnable, IColorable { const actualSlot = this.inputs[slot.index] const offset = LiteGraph.NODE_SLOT_HEIGHT * 0.5 - // @ts-expect-error https://github.com/Comfy-Org/litegraph.js/issues/616 actualSlot.pos = [offset, widget.y + offset] this.layoutSlot(actualSlot, { slotIndex: slot.index }) } diff --git a/src/types/widgets.ts b/src/types/widgets.ts index 8d234177a..55d08656d 100644 --- a/src/types/widgets.ts +++ b/src/types/widgets.ts @@ -66,32 +66,32 @@ export type IWidget = | IKnobWidget export interface IBooleanWidget extends IBaseWidget { - type?: "toggle" + type: "toggle" value: boolean } /** Any widget that uses a numeric backing */ export interface INumericWidget extends IBaseWidget { - type?: "number" + type: "number" value: number } export interface ISliderWidget extends IBaseWidget { - type?: "slider" + type: "slider" value: number options: IWidgetSliderOptions marker?: number } export interface IKnobWidget extends IBaseWidget { - type?: "knob" + type: "knob" value: number options: IWidgetKnobOptions } /** A combo-box widget (dropdown, select, etc) */ export interface IComboWidget extends IBaseWidget { - type?: "combo" + type: "combo" value: string | number options: IWidgetOptions } @@ -100,12 +100,12 @@ export type IStringWidgetType = IStringWidget["type"] | IMultilineStringWidget[" /** A widget with a string value */ export interface IStringWidget extends IBaseWidget { - type?: "string" | "text" + type: "string" | "text" value: string } export interface IButtonWidget extends IBaseWidget { - type?: "button" + type: "button" value: undefined clicked: boolean } @@ -114,7 +114,7 @@ export interface IButtonWidget extends IBaseWidget { export interface IMultilineStringWidget extends IBaseWidget { - type?: "multiline" + type: "multiline" value: string /** HTML textarea element */ @@ -123,7 +123,7 @@ export interface IMultilineStringWidget label?: string - type?: TWidgetType + type: TWidgetType value?: TWidgetValue - y?: number + y: number = 0 last_y?: number width?: number disabled?: boolean @@ -42,6 +42,7 @@ export abstract class BaseWidget implements IBaseWidget { Object.assign(this, widget) this.name = widget.name this.options = widget.options + this.type = widget.type } get outline_color() {