Line data Source code
1 : import { storeToRefs } from 'pinia'
2 : import { computed, toValue } from 'vue'
3 : import type { MaybeRefOrGetter, Ref } from 'vue'
4 :
5 : import { useWorkflowStore } from '@/platform/workflow/management/stores/workflowStore'
6 : import type { NodeId } from '@comfyorg/graph-model/nodeId'
7 : import { useNodeOutputStore } from '@/stores/nodeOutputStore'
8 :
9 2355 : export const useNodePreviewState = (
10 : nodeIdMaybe: MaybeRefOrGetter<NodeId>,
11 : options?: {
12 : isCollapsed?: Ref<boolean>
13 : }
14 : ) => {
15 8015 : const nodeId = toValue(nodeIdMaybe)
16 8015 : const workflowStore = useWorkflowStore()
17 8015 : const { nodePreviewImages } = storeToRefs(useNodeOutputStore())
18 :
19 8015 : const locatorId = computed(() => workflowStore.nodeIdToNodeLocatorId(nodeId))
20 :
21 8015 : const previewUrls = computed(() => {
22 8177 : const key = locatorId.value
23 8177 : if (!key) return undefined
24 8177 : const urls = nodePreviewImages.value[key]
25 8177 : return urls?.length ? urls : undefined
26 : })
27 :
28 8015 : const hasPreview = computed(() => !!previewUrls.value?.length)
29 :
30 : const latestPreviewUrl = computed(() => {
31 29 : const urls = previewUrls.value
32 29 : return urls?.length ? urls.at(-1)! : ''
33 : })
34 :
35 : const shouldShowPreviewImg = computed(() => {
36 8034 : if (!options?.isCollapsed) {
37 0 : return hasPreview.value
38 : }
39 8034 : return !options.isCollapsed.value && hasPreview.value
40 : })
41 :
42 8015 : return {
43 : locatorId,
44 : previewUrls,
45 : hasPreview,
46 : latestPreviewUrl,
47 : shouldShowPreviewImg
48 : }
49 : }
|