[TS] Remove optional from widget y and type (#752)

- Fixes widget `type` marked as optional - it is required
- Fixes widget `y` marked as optional - now initialised to 0
This commit is contained in:
filtered
2025-03-12 02:46:10 +11:00
committed by GitHub
parent f6c605434b
commit a7f2ff16a9
4 changed files with 15 additions and 22 deletions

View File

@@ -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<T extends IWidget>(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 })
}