mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-01-26 19:09:52 +00:00
## Summary Fixes the case where a value is updated in the graph but the result doesn't reflect on the widget representation on the relevant node. ## Changes - **What**: Uses vanilla Vue utilities instead of a special utility - **What**: Fewer places where state could be desynced. ┆Issue is synchronized with this [Notion page](https://www.notion.so/PR-6741-Fix-WIP-Simplify-the-widget-state-logic-2af6d73d36508160b729db50608a2ea9) by [Unito](https://www.unito.io) --------- Co-authored-by: github-actions <github-actions@github.com>
51 lines
1.6 KiB
TypeScript
51 lines
1.6 KiB
TypeScript
/*
|
|
Preview Any - original implement from
|
|
https://github.com/rgthree/rgthree-comfy/blob/main/py/display_any.py
|
|
upstream requested in https://github.com/Kosinkadink/rfcs/blob/main/rfcs/0000-corenodes.md#preview-nodes
|
|
*/
|
|
import { app } from '@/scripts/app'
|
|
import { type DOMWidget } from '@/scripts/domWidget'
|
|
import { ComfyWidgets } from '@/scripts/widgets'
|
|
import { useExtensionService } from '@/services/extensionService'
|
|
|
|
useExtensionService().registerExtension({
|
|
name: 'Comfy.PreviewAny',
|
|
async beforeRegisterNodeDef(nodeType, nodeData) {
|
|
if (nodeData.name === 'PreviewAny') {
|
|
const onNodeCreated = nodeType.prototype.onNodeCreated
|
|
|
|
nodeType.prototype.onNodeCreated = function () {
|
|
onNodeCreated ? onNodeCreated.apply(this, []) : undefined
|
|
|
|
const showValueWidget = ComfyWidgets['STRING'](
|
|
this,
|
|
'preview',
|
|
['STRING', { multiline: true }],
|
|
app
|
|
).widget as DOMWidget<HTMLTextAreaElement, string>
|
|
|
|
showValueWidget.options.read_only = true
|
|
|
|
showValueWidget.element.readOnly = true
|
|
showValueWidget.element.disabled = true
|
|
|
|
showValueWidget.serialize = false
|
|
}
|
|
|
|
const onExecuted = nodeType.prototype.onExecuted
|
|
|
|
nodeType.prototype.onExecuted = function (message) {
|
|
onExecuted === null || onExecuted === void 0
|
|
? void 0
|
|
: onExecuted.apply(this, [message])
|
|
|
|
const previewWidget = this.widgets?.find((w) => w.name === 'preview')
|
|
|
|
if (previewWidget) {
|
|
previewWidget.value = message.text[0]
|
|
}
|
|
}
|
|
}
|
|
}
|
|
})
|