mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-02-06 16:10:09 +00:00
35 lines
1.0 KiB
TypeScript
35 lines
1.0 KiB
TypeScript
import type { LGraphNode } from '@comfyorg/litegraph'
|
|
import { ref } from 'vue'
|
|
|
|
import TextPreviewWidget from '@/components/graph/widgets/TextPreviewWidget.vue'
|
|
import type { InputSpec } from '@/schemas/nodeDef/nodeDefSchemaV2'
|
|
import { ComponentWidgetImpl, addWidget } from '@/scripts/domWidget'
|
|
import type { ComfyWidgetConstructorV2 } from '@/scripts/widgetTypes'
|
|
|
|
|
|
export const useTextPreviewWidget = () => {
|
|
const widgetConstructor: ComfyWidgetConstructorV2 = (
|
|
node: LGraphNode,
|
|
inputSpec: InputSpec
|
|
) => {
|
|
const widgetValue = ref<string>('')
|
|
const widget = new ComponentWidgetImpl<string | object>({
|
|
node,
|
|
name: inputSpec.name,
|
|
component: TextPreviewWidget,
|
|
inputSpec,
|
|
options: {
|
|
getValue: () => widgetValue.value,
|
|
setValue: (value: string | object) => {
|
|
widgetValue.value = typeof value === 'string' ? value : String(value)
|
|
},
|
|
serialize: false
|
|
}
|
|
})
|
|
addWidget(node, widget)
|
|
return widget
|
|
}
|
|
|
|
return widgetConstructor
|
|
}
|