mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-05-01 03:31:58 +00:00
fix: Custom Combo options display in Nodes 2.0 (#9324)
## Summary Keep the value in the store instead of in the closure. ┆Issue is synchronized with this [Notion page](https://www.notion.so/PR-9324-fix-Custom-Combo-options-display-in-Nodes-2-0-3166d73d3650814db361c41ebdb1d222) by [Unito](https://www.unito.io)
This commit is contained in:
@@ -6,6 +6,7 @@ import { LGraphNode } from '@/lib/litegraph/src/LGraphNode'
|
|||||||
import { LLink } from '@/lib/litegraph/src/litegraph'
|
import { LLink } from '@/lib/litegraph/src/litegraph'
|
||||||
import type { ComfyNodeDef } from '@/schemas/nodeDefSchema'
|
import type { ComfyNodeDef } from '@/schemas/nodeDefSchema'
|
||||||
import { app } from '@/scripts/app'
|
import { app } from '@/scripts/app'
|
||||||
|
import { useWidgetValueStore } from '@/stores/widgetValueStore'
|
||||||
|
|
||||||
function applyToGraph(this: LGraphNode, extraLinks: LLink[] = []) {
|
function applyToGraph(this: LGraphNode, extraLinks: LLink[] = []) {
|
||||||
if (!this.outputs[0].links?.length || !this.graph) return
|
if (!this.outputs[0].links?.length || !this.graph) return
|
||||||
@@ -74,17 +75,25 @@ function onCustomComboCreated(this: LGraphNode) {
|
|||||||
function addOption(node: LGraphNode) {
|
function addOption(node: LGraphNode) {
|
||||||
if (!node.widgets) return
|
if (!node.widgets) return
|
||||||
const newCount = node.widgets.length - 1
|
const newCount = node.widgets.length - 1
|
||||||
node.addWidget('string', `option${newCount}`, '', () => {})
|
const widgetName = `option${newCount}`
|
||||||
const widget = node.widgets.at(-1)
|
const widget = node.addWidget('string', widgetName, '', () => {})
|
||||||
if (!widget) return
|
if (!widget) return
|
||||||
|
|
||||||
let value = ''
|
|
||||||
Object.defineProperty(widget, 'value', {
|
Object.defineProperty(widget, 'value', {
|
||||||
get() {
|
get() {
|
||||||
return value
|
return useWidgetValueStore().getWidget(
|
||||||
|
app.rootGraph.id,
|
||||||
|
node.id,
|
||||||
|
widgetName
|
||||||
|
)?.value
|
||||||
},
|
},
|
||||||
set(v) {
|
set(v: string) {
|
||||||
value = v
|
const state = useWidgetValueStore().getWidget(
|
||||||
|
app.rootGraph.id,
|
||||||
|
node.id,
|
||||||
|
widgetName
|
||||||
|
)
|
||||||
|
if (state) state.value = v
|
||||||
updateCombo()
|
updateCombo()
|
||||||
if (!node.widgets) return
|
if (!node.widgets) return
|
||||||
const lastWidget = node.widgets.at(-1)
|
const lastWidget = node.widgets.at(-1)
|
||||||
|
|||||||
Reference in New Issue
Block a user