Skip to content

Commit fb14d24

Browse files
authored
[upstream] Upstream PreviewAny from rgthree-comfy (#3640)
1 parent 0481560 commit fb14d24

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

src/extensions/core/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import './load3d'
1010
import './maskeditor'
1111
import './nodeTemplates'
1212
import './noteNode'
13+
import './previewAny'
1314
import './rerouteNode'
1415
import './saveImageExtraOutput'
1516
import './saveMesh'

src/extensions/core/previewAny.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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

Comments
 (0)