|
| 1 | +/* |
| 2 | +Preview Any - original implement from |
| 3 | +https://github.com/rgthree/rgthree-comfy/blob/main/py/display_any.py |
| 4 | +upstream requested in https://github.com/Kosinkadink/rfcs/blob/main/rfcs/0000-corenodes.md#preview-nodes |
| 5 | + */ |
| 6 | +import { IWidget } from '@comfyorg/litegraph' |
| 7 | + |
| 8 | +import { DOMWidget } from '@/scripts/domWidget' |
| 9 | +import { ComfyWidgets } from '@/scripts/widgets' |
| 10 | +import { useExtensionService } from '@/services/extensionService' |
| 11 | + |
| 12 | +useExtensionService().registerExtension({ |
| 13 | + name: 'Comfy.PreviewAny', |
| 14 | + async beforeRegisterNodeDef(nodeType, nodeData) { |
| 15 | + if (nodeData.name === 'PreviewAny') { |
| 16 | + const onNodeCreated = nodeType.prototype.onNodeCreated |
| 17 | + |
| 18 | + nodeType.prototype.onNodeCreated = function () { |
| 19 | + onNodeCreated ? onNodeCreated.apply(this, []) : undefined |
| 20 | + |
| 21 | + const showValueWidget = ComfyWidgets['STRING']( |
| 22 | + this, |
| 23 | + 'preview', |
| 24 | + ['STRING', { multiline: true }], |
| 25 | + app |
| 26 | + ).widget as DOMWidget<any, any> |
| 27 | + |
| 28 | + showValueWidget.element.readOnly = true |
| 29 | + |
| 30 | + showValueWidget.serialize = false |
| 31 | + } |
| 32 | + |
| 33 | + const onExecuted = nodeType.prototype.onExecuted |
| 34 | + |
| 35 | + nodeType.prototype.onExecuted = function (message) { |
| 36 | + onExecuted === null || onExecuted === void 0 |
| 37 | + ? void 0 |
| 38 | + : onExecuted.apply(this, [message]) |
| 39 | + |
| 40 | + const previewWidget = this.widgets?.find( |
| 41 | + (w: IWidget) => w.name === 'preview' |
| 42 | + ) |
| 43 | + |
| 44 | + if (previewWidget) { |
| 45 | + previewWidget.value = message.text[0] |
| 46 | + } |
| 47 | + } |
| 48 | + } |
| 49 | + } |
| 50 | +}) |
0 commit comments