Line data Source code
1 : import TextPreviewWidget from '@/components/graph/widgets/TextPreviewWidget.vue'
2 : import { resolveNodeRootGraphId } from '@/lib/litegraph/src/litegraph'
3 : import type { LGraphNode } from '@/lib/litegraph/src/litegraph'
4 : import type { InputSpec } from '@comfyorg/object-info-parser/schemas/nodeDefSchemaV2'
5 : import { ComponentWidgetImpl, addWidget } from '@/scripts/domWidget'
6 : import { useApp } from '@/scripts/appInstance'
7 : import type { ComfyWidgetConstructorV2 } from '@/types/widgetConstructor'
8 : import type { IBaseWidget } from '@comfyorg/graph-model/widgets'
9 : import { useWidgetValueStore } from '@/stores/widgetValueStore'
10 : import { widgetId } from '@comfyorg/graph-model/widgetId'
11 :
12 : const PADDING = 16
13 :
14 2355 : export function useTextPreviewWidget(
15 : options: {
16 : minHeight?: number
17 : } = {}
18 : ): ComfyWidgetConstructorV2 {
19 11 : function widgetConstructor(
20 : node: LGraphNode,
21 : inputSpec: InputSpec
22 : ): IBaseWidget {
23 11 : const widget = new ComponentWidgetImpl<string | object>({
24 : node,
25 : name: inputSpec.name,
26 : component: TextPreviewWidget,
27 : inputSpec,
28 : options: {
29 : getValue: () => {
30 26 : const value =
31 : useWidgetValueStore().getWidget(
32 : widgetId(
33 : resolveNodeRootGraphId(node, useApp().rootGraph.id),
34 : node.id,
35 : inputSpec.name
36 : )
37 : )?.value ?? ''
38 26 : return typeof value === 'number' || typeof value === 'boolean'
39 : ? String(value)
40 : : value
41 : },
42 : setValue: (value: string | object) => {
43 12 : const graphId = resolveNodeRootGraphId(node, useApp().rootGraph.id)
44 12 : const widgetState = useWidgetValueStore().getWidget(
45 : widgetId(graphId, node.id, inputSpec.name)
46 : )
47 12 : if (widgetState)
48 12 : widgetState.value =
49 : typeof value === 'string' ? value : String(value)
50 : },
51 : getMinHeight: () => options.minHeight ?? 42 + PADDING,
52 : serialize: false,
53 : read_only: true
54 : },
55 : type: inputSpec.type
56 : })
57 11 : widget.serialize = false
58 11 : addWidget(node, widget)
59 11 : return widget
60 : }
61 :
62 2355 : return widgetConstructor
63 : }
|