mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-02-02 14:27:40 +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 { clamp, LiteGraph } from "@/litegraph"
|
||||
@@ -5,7 +6,13 @@ import { clamp, LiteGraph } from "@/litegraph"
|
||||
import { BaseSteppedWidget } from "./BaseSteppedWidget"
|
||||
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[] {
|
||||
return Array.isArray(values) ? values : Object.keys(values)
|
||||
@@ -24,12 +31,11 @@ export class ComboWidget extends BaseSteppedWidget implements IComboWidget {
|
||||
this.value = widget.value
|
||||
}
|
||||
|
||||
#getValues(): Values {
|
||||
#getValues(node: LGraphNode): Values {
|
||||
const { values } = this.options
|
||||
if (values == null) throw new Error("[ComboWidget]: values is required")
|
||||
|
||||
return typeof values === "function"
|
||||
// @ts-expect-error handle () => string[] type that is not typed in IWidgetOptions
|
||||
? values(this, node)
|
||||
: values
|
||||
}
|
||||
@@ -65,7 +71,7 @@ export class ComboWidget extends BaseSteppedWidget implements IComboWidget {
|
||||
}
|
||||
|
||||
#tryChangeValue(delta: number, options: WidgetEventOptions): void {
|
||||
const values = this.#getValues()
|
||||
const values = this.#getValues(options.node)
|
||||
const indexedValues = toArray(values)
|
||||
|
||||
// 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 })
|
||||
|
||||
// Otherwise, show dropdown menu
|
||||
const values = this.#getValues()
|
||||
const values = this.#getValues(node)
|
||||
const values_list = toArray(values)
|
||||
|
||||
// Handle center click - show dropdown menu
|
||||
|
||||
Reference in New Issue
Block a user