Line data Source code
1 : <template>
2 9 : <div
3 : class="flex flex-col overflow-hidden rounded-lg border bg-background"
4 : :style="{ width: `${BASE_WIDTH_PX * (scaleFactor / BASE_SCALE)}px` }"
5 : data-testid="node-preview-card"
6 : >
7 : <div ref="previewContainerRef" class="overflow-hidden p-3">
8 : <div
9 : ref="previewWrapperRef"
10 : class="origin-top-left"
11 : :style="{ transform: `scale(${scaleFactor})` }"
12 : >
13 : <LGraphNodePreview :node-def="nodeDef" position="relative" />
14 : </div>
15 : </div>
16 :
17 : <!-- Content Section -->
18 : <div class="flex flex-col gap-2 p-3 pt-1">
19 : <!-- Title -->
20 : <h3 class="m-0 text-xs font-semibold text-foreground">
21 : {{ nodeDef.display_name }}
22 : </h3>
23 :
24 : <!-- Category Path -->
25 : <p
26 : v-if="showCategoryPath && nodeDef.category"
27 : class="-mt-1 truncate text-xs text-muted-foreground"
28 : >
29 : {{ categoryPath }}
30 : </p>
31 :
32 : <!-- Badges -->
33 : <div class="flex flex-wrap gap-2 overflow-hidden empty:hidden">
34 : <NodePricingBadge class="max-w-full truncate" :node-def="nodeDef" />
35 : <NodeProviderBadge :node-def="nodeDef" />
36 : </div>
37 :
38 : <!-- Description -->
39 : <p
40 : v-if="nodeDef.description"
41 : class="m-0 max-h-[30vh] overflow-y-auto text-2xs/normal font-normal text-muted-foreground"
42 : >
43 : {{ nodeDef.description }}
44 : </p>
45 :
46 : <!-- Divider -->
47 : <div
48 : v-if="(inputs.length > 0 || outputs.length > 0) && showInputsAndOutputs"
49 : class="border-t"
50 : />
51 :
52 : <!-- Inputs Section -->
53 : <div
54 : v-if="inputs.length > 0 && showInputsAndOutputs"
55 : class="flex flex-col gap-1 text-2xs"
56 : data-testid="node-preview-inputs"
57 : >
58 : <h4
59 : class="m-0 font-semibold tracking-wide text-muted-foreground uppercase"
60 : >
61 : {{ $t('nodeHelpPage.inputs') }}
62 : </h4>
63 77 : <div
64 : v-for="input in inputs"
65 : :key="input.name"
66 : class="flex items-center justify-between gap-2"
67 : >
68 : <span class="shrink-0 text-foreground">{{ input.name }}</span>
69 : <span class="min-w-0 truncate text-muted-foreground">{{
70 : input.type
71 : }}</span>
72 : </div>
73 : </div>
74 :
75 : <!-- Outputs Section -->
76 : <div
77 : v-if="outputs.length > 0 && showInputsAndOutputs"
78 : class="flex flex-col gap-1 text-2xs"
79 : >
80 : <h4
81 : class="m-0 font-semibold tracking-wide text-muted-foreground uppercase"
82 : >
83 : {{ $t('nodeHelpPage.outputs') }}
84 : </h4>
85 9 : <div
86 : v-for="output in outputs"
87 : :key="output.name"
88 : class="flex items-center justify-between gap-2"
89 : >
90 : <span class="shrink-0 text-foreground">{{ output.name }}</span>
91 : <span class="min-w-0 truncate text-muted-foreground">{{
92 : output.type
93 : }}</span>
94 : </div>
95 : </div>
96 : </div>
97 : </div>
98 : </template>
99 :
100 : <script setup lang="ts">
101 : import { useResizeObserver } from '@vueuse/core'
102 : import { computed, ref } from 'vue'
103 :
104 : import NodePricingBadge from '@/components/node/NodePricingBadge.vue'
105 : import NodeProviderBadge from '@/components/node/NodeProviderBadge.vue'
106 : import LGraphNodePreview from '@/renderer/extensions/vueNodes/components/LGraphNodePreview.vue'
107 : import { flattenInputSpecs } from '@/core/graph/nodeDef/inputSpecInterpreter'
108 : import type { ComfyNodeDefImpl } from '@/core/graph/nodeDef/ComfyNodeDefImpl'
109 :
110 2355 : const BASE_WIDTH_PX = 200
111 2355 : const BASE_SCALE = 0.5
112 2355 : const PREVIEW_CONTAINER_PADDING_PX = 24
113 :
114 : const {
115 : nodeDef,
116 : showInputsAndOutputs = true,
117 : showCategoryPath = false,
118 : scaleFactor = 0.5
119 : } = defineProps<{
120 : nodeDef: ComfyNodeDefImpl
121 : showInputsAndOutputs?: boolean
122 : showCategoryPath?: boolean
123 : scaleFactor?: number
124 : }>()
125 :
126 9 : const previewContainerRef = ref<HTMLElement>()
127 9 : const previewWrapperRef = ref<HTMLElement>()
128 :
129 9 : useResizeObserver(previewWrapperRef, (entries) => {
130 14 : const entry = entries[0]
131 14 : if (entry && previewContainerRef.value) {
132 14 : const scaledHeight = entry.contentRect.height * scaleFactor
133 14 : previewContainerRef.value.style.height = `${scaledHeight + PREVIEW_CONTAINER_PADDING_PX}px`
134 : }
135 : })
136 :
137 9 : const categoryPath = computed(() => nodeDef.category?.replaceAll('/', ' / '))
138 :
139 9 : const inputs = computed(() => {
140 9 : if (!nodeDef.inputs) return []
141 9 : return flattenInputSpecs(nodeDef.inputs)
142 : .filter((input) => !input.hidden)
143 : .map((input) => ({
144 : name: input.name,
145 : type: input.type
146 : }))
147 : })
148 :
149 9 : const outputs = computed(() => {
150 9 : if (!nodeDef.outputs) return []
151 9 : return nodeDef.outputs.map((output) => ({
152 : name: output.name,
153 : type: output.type
154 : }))
155 : })
156 : </script>
|