mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-04-30 03:01:54 +00:00
Add persistence to proxy widgets
This commit is contained in:
@@ -576,7 +576,26 @@ export class SubgraphNode extends LGraphNode implements BaseLGraph {
|
|||||||
// Call parent serialize method
|
// Call parent serialize method
|
||||||
return super.serialize()
|
return super.serialize()
|
||||||
}
|
}
|
||||||
addProxyWidget(nodeId, widgetName) {
|
onPropertyChanged(k, property) {
|
||||||
|
if (k !== "proxyWidgets") return
|
||||||
|
this.widgets = this.widgets.filter((w) => !w.isProxyWidget)
|
||||||
|
setTimeout(() => {
|
||||||
|
for (const [nodeId, widgetName] of property)
|
||||||
|
this.addProxyFromOverlay({
|
||||||
|
__proto__:{nodeId, widgetName}})
|
||||||
|
}, 0)
|
||||||
|
|
||||||
|
}
|
||||||
|
addProxyWidget(nodeId: string, widgetName: string) {
|
||||||
|
const overlay = {nodeId, widgetName}
|
||||||
|
this.properties.proxyWidgets ??= []
|
||||||
|
//NOTE: This doesn't trigger onPropertyChanged
|
||||||
|
this.properties.proxyWidgets.push([overlay.nodeId, overlay.widgetName])
|
||||||
|
this.addProxyFromOverlay({__proto__:overlay})
|
||||||
|
}
|
||||||
|
addProxyFromOverlay(overlay: Object) {
|
||||||
|
overlay.graph = this.subgraph
|
||||||
|
overlay.isProxyWidget = true
|
||||||
//TODO: Add minimal caching for linkedWidget?
|
//TODO: Add minimal caching for linkedWidget?
|
||||||
//use a weakref and only trigger recalc on calls when undefined?
|
//use a weakref and only trigger recalc on calls when undefined?
|
||||||
//TODO: call toConcrete when resolved and hold reference?
|
//TODO: call toConcrete when resolved and hold reference?
|
||||||
@@ -591,37 +610,30 @@ export class SubgraphNode extends LGraphNode implements BaseLGraph {
|
|||||||
if (!n) return
|
if (!n) return
|
||||||
return n.widgets.find((w) => w.name === widgetName)
|
return n.widgets.find((w) => w.name === widgetName)
|
||||||
}
|
}
|
||||||
const overlay: object = {nodeId, widgetName, graph: subgraphNode.subgraph}
|
|
||||||
const handler = Object.fromEntries(['get', 'set', 'getPrototypeOf', 'ownKeys', 'has'].map((s) => {
|
const handler = Object.fromEntries(['get', 'set', 'getPrototypeOf', 'ownKeys', 'has'].map((s) => {
|
||||||
const func = function(t,p,...rest) {
|
const func = function(t,p,...rest) {
|
||||||
if (s == 'get' && p == '_overlay')
|
if (s == 'get' && p == '_overlay')
|
||||||
return overlay
|
return overlay
|
||||||
const lw = linkedWidget(overlay.graph, overlay.nodeId, overlay.widgetName)
|
const lw = linkedWidget(overlay.graph, overlay.nodeId, overlay.widgetName)
|
||||||
if (s == 'get' && p == 'node') {
|
if (s == 'get' && p == 'node') {
|
||||||
//This is more dangerous than I would like for custom nodes. It probably breaks something
|
|
||||||
return subgraphNode
|
return subgraphNode
|
||||||
return {pos: subgraphNode.pos, __proto__:lw.node}
|
|
||||||
}
|
}
|
||||||
//NOTE: p may be undefined
|
//NOTE: p may be undefined
|
||||||
let r = rest.at(-1)
|
let r = rest.at(-1)
|
||||||
if (['y', 'last_y', 'width', 'computedHeight', 'computedDisabled', 'afterQueued', 'beforeQueued', 'onRemove'].includes(p))
|
if (['y', 'last_y', 'width', 'computedHeight', 'computedDisabled', 'afterQueued', 'beforeQueued', 'onRemove', 'isProxyWidget'].includes(p))
|
||||||
t = overlay
|
t = overlay
|
||||||
else if (p == "value") {
|
else {
|
||||||
t = lw
|
|
||||||
r = lw
|
|
||||||
} else {
|
|
||||||
t = lw
|
t = lw
|
||||||
if (!t)
|
if (!t)
|
||||||
return//TODO: pass to overlay subitem to display a disconnected state
|
t = {__proto__: overlay, draw: drawDisconnected}
|
||||||
|
if (p == "value")
|
||||||
|
r = t
|
||||||
}
|
}
|
||||||
return Reflect[s](t,p,...rest.slice(0,-1),r)
|
return Reflect[s](t,p,...rest.slice(0,-1),r)
|
||||||
}
|
}
|
||||||
return [s, func]
|
return [s, func]
|
||||||
}))
|
}))
|
||||||
const w = new Proxy(overlay, handler)
|
const w = new Proxy(overlay, handler)
|
||||||
//add widget to domwidgetstore
|
|
||||||
if (linkedWidget(overlay.graph, overlay.nodeId, overlay.widgetName))
|
|
||||||
"..."
|
|
||||||
this.widgets.push(w)
|
this.widgets.push(w)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user