diff --git a/src/types/widgets.ts b/src/types/widgets.ts index 6c9f488b1..4230457cd 100644 --- a/src/types/widgets.ts +++ b/src/types/widgets.ts @@ -45,6 +45,7 @@ export type IWidget = | IComboWidget | ICustomWidget | ISliderWidget + | IButtonWidget export interface IBooleanWidget extends IBaseWidget { type?: "toggle" @@ -74,10 +75,16 @@ export type IStringWidgetType = IStringWidget["type"] | IMultilineStringWidget[" /** A widget with a string value */ export interface IStringWidget extends IBaseWidget { - type?: "string" | "text" | "button" + type?: "string" | "text" value: string } +export interface IButtonWidget extends IBaseWidget { + type?: "button" + value: undefined + clicked: boolean +} + /** A widget with a string value and a multiline text input */ export interface IMultilineStringWidget extends IBaseWidget { @@ -117,7 +124,6 @@ export interface IBaseWidget { options: IWidgetOptions marker?: number label?: string - clicked?: boolean name?: string /** Widget type (see {@link TWidgetType}) */ type?: TWidgetType diff --git a/src/widgets/ButtonWidget.ts b/src/widgets/ButtonWidget.ts index f7d33726e..97ea5c30f 100644 --- a/src/widgets/ButtonWidget.ts +++ b/src/widgets/ButtonWidget.ts @@ -1,19 +1,20 @@ -import type { IStringWidget, IWidgetOptions } from "@/types/widgets" +import type { IButtonWidget, IWidgetOptions } from "@/types/widgets" import { BaseWidget } from "./BaseWidget" import type { LGraphNode } from "@/LGraphNode" import type { CanvasMouseEvent } from "@/types/events" import type { LGraphCanvas } from "@/LGraphCanvas" -export class ButtonWidget extends BaseWidget implements IStringWidget { - // IStringWidget properties +export class ButtonWidget extends BaseWidget implements IButtonWidget { + // IButtonWidget properties declare type: "button" - declare value: string declare options: IWidgetOptions + declare clicked: boolean + declare value: undefined - constructor(widget: IStringWidget) { + constructor(widget: IButtonWidget) { super(widget) this.type = "button" - this.value = widget.value ?? "" + this.clicked = widget.clicked ?? false } /** diff --git a/src/widgets/TextWidget.ts b/src/widgets/TextWidget.ts index 4aacb2c57..468e16c8d 100644 --- a/src/widgets/TextWidget.ts +++ b/src/widgets/TextWidget.ts @@ -12,7 +12,7 @@ export class TextWidget extends BaseWidget implements IStringWidget { constructor(widget: IStringWidget) { super(widget) - this.type = widget.type as "text" | "string" + this.type = widget.type ?? "string" this.value = widget.value?.toString() ?? "" }