mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-04-20 14:30:41 +00:00
Backport of #9221 to `core/1.39` Automatically created by backport workflow. ┆Issue is synchronized with this [Notion page](https://www.notion.so/PR-9223-backport-core-1-39-Prevent-serialization-of-progress-text-to-prompt-3136d73d3650818dbc8bed7f2a312ded) by [Unito](https://www.unito.io) Co-authored-by: AustinMroz <austin@comfy.org>
57 lines
1.6 KiB
TypeScript
57 lines
1.6 KiB
TypeScript
import { ref } from 'vue'
|
|
|
|
import TextPreviewWidget from '@/components/graph/widgets/TextPreviewWidget.vue'
|
|
import type { LGraphNode } from '@/lib/litegraph/src/litegraph'
|
|
import type { InputSpec } from '@/schemas/nodeDef/nodeDefSchemaV2'
|
|
import { ComponentWidgetImpl, addWidget } from '@/scripts/domWidget'
|
|
import type { ComponentWidgetStandardProps } from '@/scripts/domWidget'
|
|
import type { ComfyWidgetConstructorV2 } from '@/scripts/widgets'
|
|
import type { IBaseWidget } from '@/lib/litegraph/src/types/widgets'
|
|
|
|
type TextPreviewCustomProps = Omit<
|
|
InstanceType<typeof TextPreviewWidget>['$props'],
|
|
ComponentWidgetStandardProps
|
|
>
|
|
|
|
const PADDING = 16
|
|
|
|
export function useTextPreviewWidget(
|
|
options: {
|
|
minHeight?: number
|
|
} = {}
|
|
): ComfyWidgetConstructorV2 {
|
|
function widgetConstructor(
|
|
node: LGraphNode,
|
|
inputSpec: InputSpec
|
|
): IBaseWidget {
|
|
const widgetValue = ref<string>('')
|
|
const widget = new ComponentWidgetImpl<
|
|
string | object,
|
|
TextPreviewCustomProps
|
|
>({
|
|
node,
|
|
name: inputSpec.name,
|
|
component: TextPreviewWidget,
|
|
inputSpec,
|
|
props: {
|
|
nodeId: node.id
|
|
},
|
|
options: {
|
|
getValue: () => widgetValue.value,
|
|
setValue: (value: string | object) => {
|
|
widgetValue.value = typeof value === 'string' ? value : String(value)
|
|
},
|
|
getMinHeight: () => options.minHeight ?? 42 + PADDING,
|
|
serialize: false,
|
|
read_only: true
|
|
},
|
|
type: inputSpec.type
|
|
})
|
|
widget.serialize = false
|
|
addWidget(node, widget)
|
|
return widget
|
|
}
|
|
|
|
return widgetConstructor
|
|
}
|