[upstream] Upstream PreviewAny from rgthree-comfy (#3640)

This commit is contained in:
Terry Jia
2025-04-29 11:23:30 -04:00
committed by GitHub
parent 04815605b4
commit fb14d24047
2 changed files with 51 additions and 0 deletions

View File

@@ -10,6 +10,7 @@ import './load3d'
import './maskeditor'
import './nodeTemplates'
import './noteNode'
import './previewAny'
import './rerouteNode'
import './saveImageExtraOutput'
import './saveMesh'

View File

@@ -0,0 +1,50 @@
/*
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 { IWidget } from '@comfyorg/litegraph'
import { 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<any, any>
showValueWidget.element.readOnly = 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: IWidget) => w.name === 'preview'
)
if (previewWidget) {
previewWidget.value = message.text[0]
}
}
}
}
})