mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-02-02 14:27:40 +00:00
[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:
@@ -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,
|
||||
|
||||
@@ -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 })
|
||||
}
|
||||
|
||||
@@ -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<string>
|
||||
}
|
||||
@@ -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<TElement extends HTMLElement = HTMLTextAreaElement> extends
|
||||
IBaseWidget {
|
||||
|
||||
type?: "multiline"
|
||||
type: "multiline"
|
||||
value: string
|
||||
|
||||
/** HTML textarea element */
|
||||
@@ -123,7 +123,7 @@ export interface IMultilineStringWidget<TElement extends HTMLElement = HTMLTextA
|
||||
|
||||
/** A custom widget - accepts any value and has no built-in special handling */
|
||||
export interface ICustomWidget extends IBaseWidget {
|
||||
type?: "custom"
|
||||
type: "custom"
|
||||
value: string | object
|
||||
}
|
||||
|
||||
@@ -147,7 +147,7 @@ export interface IBaseWidget {
|
||||
|
||||
label?: string
|
||||
/** Widget type (see {@link TWidgetType}) */
|
||||
type?: TWidgetType
|
||||
type: TWidgetType
|
||||
value?: TWidgetValue
|
||||
|
||||
/**
|
||||
@@ -159,7 +159,7 @@ export interface IBaseWidget {
|
||||
/**
|
||||
* The starting y position of the widget after layout.
|
||||
*/
|
||||
y?: number
|
||||
y: number
|
||||
|
||||
/**
|
||||
* The y position of the widget after drawing (rendering).
|
||||
|
||||
@@ -10,9 +10,9 @@ export abstract class BaseWidget implements IBaseWidget {
|
||||
name: string
|
||||
options: IWidgetOptions<unknown>
|
||||
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() {
|
||||
|
||||
Reference in New Issue
Block a user