mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-07-19 02:06:38 +00:00
## Summary Add a frontend preview extension for the SaveText node that displays saved text content after execution. ## Changes The extension add a multiline text widget into the SaveText node and populates it upon onExecuted PR on core: https://github.com/Comfy-Org/ComfyUI/pull/14102 ## Review Focus <!-- Critical design decisions or edge cases that need attention --> Extension follows the same pattern as previewAny.ts <!-- If this PR fixes an issue, uncomment and update the line below --> <!-- Fixes #ISSUE_NUMBER --> ## Screenshots <img width="1127" height="421" alt="Screenshot 2026-05-29 194925" src="https://github.com/user-attachments/assets/e7a72807-858b-47c7-be07-595f9e539a49" /> <!-- Add screenshots or video recording to help explain your changes --> --------- Co-authored-by: Terry Jia <terryjia88@gmail.com>
41 lines
877 B
TypeScript
41 lines
877 B
TypeScript
import { computedAsync } from '@vueuse/core'
|
|
import { ref, toValue } from 'vue'
|
|
import type { MaybeRefOrGetter } from 'vue'
|
|
|
|
interface TextSource {
|
|
content?: string
|
|
url?: string
|
|
}
|
|
|
|
export function useTextFileContent(
|
|
source: MaybeRefOrGetter<TextSource | undefined>
|
|
) {
|
|
const isLoading = ref(false)
|
|
const hasError = ref(false)
|
|
|
|
const textContent = computedAsync(
|
|
async () => {
|
|
hasError.value = false
|
|
const { content, url } = toValue(source) ?? {}
|
|
if (content !== undefined) return content
|
|
if (!url) return ''
|
|
|
|
const response = await fetch(url)
|
|
if (!response.ok) {
|
|
hasError.value = true
|
|
return ''
|
|
}
|
|
return await response.text()
|
|
},
|
|
'',
|
|
{
|
|
evaluating: isLoading,
|
|
onError: () => {
|
|
hasError.value = true
|
|
}
|
|
}
|
|
)
|
|
|
|
return { textContent, isLoading, hasError }
|
|
}
|