Line data Source code
1 : import { watch } from 'vue'
2 :
3 : import { toPreviewText } from '@/extensions/core/textPreviewWidgets'
4 : import { useApp } from '@/scripts/appInstance'
5 : import { useDomWidgetStore } from '@/stores/domWidgetStore'
6 : import { useNodeOutputStore } from '@/stores/nodeOutputStore'
7 :
8 2355 : export function useTextPreviewSystem(): void {
9 2355 : const domWidgets = useDomWidgetStore()
10 2355 : const outputs = useNodeOutputStore()
11 2355 : const app = useApp()
12 :
13 2355 : watch(
14 : () => {
15 9404 : const rootGraph = app.rootGraphOrUndefined
16 9404 : return [...domWidgets.widgetStates.values()].flatMap(({ widget }) => {
17 7301 : const node = widget.node
18 7301 : if (
19 : !rootGraph ||
20 : node.graph?.rootGraph !== rootGraph ||
21 : widget.type !== 'textPreview' ||
22 : (node.comfyClass !== 'PreviewAny' && node.comfyClass !== 'SaveText')
23 : )
24 7180 : return []
25 :
26 7301 : return [
27 : { widget, value: toPreviewText(outputs.getNodeOutputs(node)?.text) }
28 : ]
29 : })
30 : },
31 : (previews) => {
32 9404 : for (const { widget, value } of previews)
33 121 : if (widget.value !== value) widget.value = value
34 : },
35 : { immediate: true }
36 : )
37 : }
|