mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-04-29 10:42:44 +00:00
Fix regression in legacy widget-values-as-function (#990)
Resolves issue with KJNodes get/set nodes.

Downstream consumer:
c3dc82108a/web/js/setgetnodes.js (L401-L404)
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
import type { LGraphNode } from "@/LGraphNode"
|
||||||
import type { IComboWidget, IWidgetOptions } from "@/types/widgets"
|
import type { IComboWidget, IWidgetOptions } from "@/types/widgets"
|
||||||
|
|
||||||
import { clamp, LiteGraph } from "@/litegraph"
|
import { clamp, LiteGraph } from "@/litegraph"
|
||||||
@@ -5,7 +6,13 @@ import { clamp, LiteGraph } from "@/litegraph"
|
|||||||
import { BaseSteppedWidget } from "./BaseSteppedWidget"
|
import { BaseSteppedWidget } from "./BaseSteppedWidget"
|
||||||
import { BaseWidget, type DrawWidgetOptions, type WidgetEventOptions } from "./BaseWidget"
|
import { BaseWidget, type DrawWidgetOptions, type WidgetEventOptions } from "./BaseWidget"
|
||||||
|
|
||||||
type Values = string[] | Record<string, string>
|
/**
|
||||||
|
* This is used as an (invalid) assertion to resolve issues with legacy duck-typed values.
|
||||||
|
*
|
||||||
|
* Function style in use by:
|
||||||
|
* https://github.com/kijai/ComfyUI-KJNodes/blob/c3dc82108a2a86c17094107ead61d63f8c76200e/web/js/setgetnodes.js#L401-L404
|
||||||
|
*/
|
||||||
|
type Values = string[] | Record<string, string> | ((widget: ComboWidget, node: LGraphNode) => string[])
|
||||||
|
|
||||||
function toArray(values: Values): string[] {
|
function toArray(values: Values): string[] {
|
||||||
return Array.isArray(values) ? values : Object.keys(values)
|
return Array.isArray(values) ? values : Object.keys(values)
|
||||||
@@ -24,12 +31,11 @@ export class ComboWidget extends BaseSteppedWidget implements IComboWidget {
|
|||||||
this.value = widget.value
|
this.value = widget.value
|
||||||
}
|
}
|
||||||
|
|
||||||
#getValues(): Values {
|
#getValues(node: LGraphNode): Values {
|
||||||
const { values } = this.options
|
const { values } = this.options
|
||||||
if (values == null) throw new Error("[ComboWidget]: values is required")
|
if (values == null) throw new Error("[ComboWidget]: values is required")
|
||||||
|
|
||||||
return typeof values === "function"
|
return typeof values === "function"
|
||||||
// @ts-expect-error handle () => string[] type that is not typed in IWidgetOptions
|
|
||||||
? values(this, node)
|
? values(this, node)
|
||||||
: values
|
: values
|
||||||
}
|
}
|
||||||
@@ -65,7 +71,7 @@ export class ComboWidget extends BaseSteppedWidget implements IComboWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#tryChangeValue(delta: number, options: WidgetEventOptions): void {
|
#tryChangeValue(delta: number, options: WidgetEventOptions): void {
|
||||||
const values = this.#getValues()
|
const values = this.#getValues(options.node)
|
||||||
const indexedValues = toArray(values)
|
const indexedValues = toArray(values)
|
||||||
|
|
||||||
// avoids double click event
|
// avoids double click event
|
||||||
@@ -195,7 +201,7 @@ export class ComboWidget extends BaseSteppedWidget implements IComboWidget {
|
|||||||
if (x > width - 40) return this.incrementValue({ e, node, canvas })
|
if (x > width - 40) return this.incrementValue({ e, node, canvas })
|
||||||
|
|
||||||
// Otherwise, show dropdown menu
|
// Otherwise, show dropdown menu
|
||||||
const values = this.#getValues()
|
const values = this.#getValues(node)
|
||||||
const values_list = toArray(values)
|
const values_list = toArray(values)
|
||||||
|
|
||||||
// Handle center click - show dropdown menu
|
// Handle center click - show dropdown menu
|
||||||
|
|||||||
Reference in New Issue
Block a user