LCOV - code coverage report
Current view: top level - src/components/node - NodePreview.vue Coverage Total Hit
Test: ComfyUI E2E Coverage Lines: 92.0 % 25 23
Test Date: 2026-11-17 04:17:53

            Line data    Source code
       1              : <!-- Reference:
       2              : https://github.com/Nuked88/ComfyUI-N-Sidebar/blob/7ae7da4a9761009fb6629bc04c683087a3e168db/app/js/functions/sb_fn.js#L149
       3              : -->
       4              : <template>
       5              :   <LGraphNodePreview
       6           90 :     v-if="shouldRenderVueNodes"
       7              :     :node-def="nodeDef"
       8              :     :position="position"
       9              :   />
      10              :   <div v-else class="_sb_node_preview bg-node" data-testid="node-preview">
      11              :     <div class="_sb_table">
      12              :       <div
      13              :         class="node_header text-ellipsis"
      14              :         data-testid="node-header"
      15              :         :title="nodeDef.display_name"
      16              :         :style="{
      17              :           backgroundColor: litegraphColors.nodeDefaultColor,
      18              :           color: litegraphColors.nodeTitleColor
      19              :         }"
      20              :       >
      21              :         <div class="_sb_dot headdot pr-3" data-testid="head-dot" />
      22              :         {{ nodeDef.display_name }}
      23              :       </div>
      24              :       <div class="_sb_preview_badge">{{ $t('g.preview') }}</div>
      25              : 
      26              :       <!-- Node slot I/O -->
      27          209 :       <div
      28              :         v-for="[slotInput, slotOutput] in zip(slotInputDefs, allOutputDefs)"
      29              :         :key="(slotInput?.name || '') + (slotOutput?.index.toString() || '')"
      30              :         class="_sb_row slot_row"
      31              :       >
      32              :         <div class="_sb_col">
      33              :           <div v-if="slotInput" :class="cn('_sb_dot', slotInput.type)" />
      34              :         </div>
      35              :         <div class="_sb_col">
      36              :           {{ slotInput ? slotInput.name : '' }}
      37              :         </div>
      38              :         <div class="_sb_col middle-column" />
      39              :         <div
      40              :           class="_sb_col _sb_inherit"
      41              :           :style="{
      42              :             color: litegraphColors.nodeTextColor
      43              :           }"
      44              :         >
      45              :           {{ slotOutput ? slotOutput.name : '' }}
      46              :         </div>
      47              :         <div class="_sb_col">
      48              :           <div v-if="slotOutput" :class="cn('_sb_dot', slotOutput.type)" />
      49              :         </div>
      50              :       </div>
      51              : 
      52              :       <!-- Node widget inputs -->
      53          293 :       <div
      54              :         v-for="widgetInput in widgetInputDefs"
      55              :         :key="widgetInput.name"
      56              :         class="_sb_row _long_field"
      57              :       >
      58              :         <div class="_sb_col _sb_arrow">&#x25C0;</div>
      59              :         <div
      60              :           class="_sb_col"
      61              :           :style="{
      62              :             color: litegraphColors.widgetSecondaryTextColor
      63              :           }"
      64              :         >
      65              :           {{ widgetInput.name }}
      66              :         </div>
      67              :         <div class="_sb_col middle-column" />
      68              :         <div
      69              :           class="_sb_col _sb_inherit"
      70              :           :style="{ color: litegraphColors.widgetTextColor }"
      71              :         >
      72              :           {{ truncateDefaultValue(widgetInput.default) }}
      73              :         </div>
      74              :         <div class="_sb_col _sb_arrow">&#x25B6;</div>
      75              :       </div>
      76              :     </div>
      77              :     <SanitizedHtml
      78              :       v-if="renderedDescription"
      79              :       class="_sb_description"
      80              :       data-testid="node-description"
      81              :       :style="{
      82              :         color: litegraphColors.widgetSecondaryTextColor,
      83              :         backgroundColor: litegraphColors.widgetBackgroundColor
      84              :       }"
      85              :       :html="renderedDescription"
      86              :     />
      87              :   </div>
      88              : </template>
      89              : 
      90              : <script setup lang="ts">
      91              : import { cn } from '@comfyorg/tailwind-utils'
      92              : import { truncate, zip } from 'es-toolkit/compat'
      93              : import { computed } from 'vue'
      94              : 
      95              : import SanitizedHtml from '@comfyorg/design-system/common/SanitizedHtml'
      96              : import { useVueFeatureFlags } from '@/composables/useVueFeatureFlags'
      97              : import LGraphNodePreview from '@/renderer/extensions/vueNodes/components/LGraphNodePreview.vue'
      98              : import type { ComfyNodeDef as ComfyNodeDefV2 } from '@comfyorg/object-info-parser/schemas/nodeDefSchemaV2'
      99              : import { flattenInputSpecs } from '@/core/graph/nodeDef/inputSpecInterpreter'
     100              : import { useWidgetStore } from '@/stores/widgetStore'
     101              : import { useThemeStore } from '@/platform/theme/themeStore'
     102              : import { renderMarkdownToHtml } from '@/utils/markdownRendererUtil'
     103              : 
     104              : const { nodeDef, position = 'absolute' } = defineProps<{
     105              :   nodeDef: ComfyNodeDefV2
     106              :   position?: 'absolute' | 'relative'
     107              : }>()
     108              : 
     109           90 : const { shouldRenderVueNodes } = useVueFeatureFlags()
     110              : 
     111           90 : const themeStore = useThemeStore()
     112           90 : const litegraphColors = computed(() => themeStore.activeTheme.canvas)
     113              : 
     114           90 : const widgetStore = useWidgetStore()
     115              : 
     116           90 : const { description } = nodeDef
     117           90 : const renderedDescription = computed(() => {
     118           85 :   if (!description) return ''
     119           44 :   return renderMarkdownToHtml(description)
     120              : })
     121              : 
     122           90 : const allInputDefs = flattenInputSpecs(nodeDef.inputs)
     123           90 : const allOutputDefs = nodeDef.outputs
     124           90 : const slotInputDefs = allInputDefs.filter(
     125              :   (input) => !widgetStore.inputIsWidget(input)
     126              : )
     127           90 : const widgetInputDefs = allInputDefs.filter((input) =>
     128              :   widgetStore.inputIsWidget(input)
     129              : )
     130           90 : const truncateDefaultValue = (
     131              :   value: unknown,
     132              :   charLimit: number = 32
     133              : ): string => {
     134          293 :   let stringValue: string
     135              : 
     136          293 :   if (typeof value === 'object' && value !== null) {
     137            0 :     stringValue = JSON.stringify(value)
     138          293 :   } else if (Array.isArray(value)) {
     139            0 :     stringValue = JSON.stringify(value)
     140          293 :   } else if (typeof value === 'string') {
     141            1 :     stringValue = value
     142              :   } else {
     143          292 :     stringValue = String(value)
     144              :   }
     145              : 
     146          293 :   return truncate(stringValue, { length: charLimit })
     147              : }
     148              : </script>
     149              : 
     150              : <style scoped>
     151              : .slot_row {
     152              :   padding: 2px;
     153              : }
     154              : 
     155              : /* Original N-Sidebar styles */
     156              : ._sb_dot {
     157              :   width: 8px;
     158              :   height: 8px;
     159              :   border-radius: 50%;
     160              :   background-color: grey;
     161              : }
     162              : 
     163              : .node_header {
     164              :   line-height: 1;
     165              :   padding: 8px 13px 7px;
     166              :   margin-bottom: 5px;
     167              :   font-size: 15px;
     168              :   text-wrap: nowrap;
     169              :   overflow: hidden;
     170              :   display: flex;
     171              :   align-items: center;
     172              : }
     173              : 
     174              : .headdot {
     175              :   width: 10px;
     176              :   height: 10px;
     177              :   float: inline-start;
     178              :   margin-right: 8px;
     179              : }
     180              : 
     181              : .IMAGE {
     182              :   background-color: #64b5f6;
     183              : }
     184              : 
     185              : .VAE {
     186              :   background-color: #ff6e6e;
     187              : }
     188              : 
     189              : .LATENT {
     190              :   background-color: #ff9cf9;
     191              : }
     192              : 
     193              : .MASK {
     194              :   background-color: #81c784;
     195              : }
     196              : 
     197              : .CONDITIONING {
     198              :   background-color: #ffa931;
     199              : }
     200              : 
     201              : .CLIP {
     202              :   background-color: #ffd500;
     203              : }
     204              : 
     205              : .MODEL {
     206              :   background-color: #b39ddb;
     207              : }
     208              : 
     209              : .CONTROL_NET {
     210              :   background-color: #a5d6a7;
     211              : }
     212              : 
     213              : ._sb_node_preview {
     214              :   color: var(--muted-foreground);
     215              :   border: 1px solid var(--muted-foreground);
     216              :   min-width: 300px;
     217              :   width: min-content;
     218              :   height: fit-content;
     219              :   z-index: var(--z-index-overlay);
     220              :   border-radius: 12px;
     221              :   overflow: hidden;
     222              :   font-size: 12px;
     223              :   padding-bottom: 10px;
     224              : }
     225              : 
     226              : ._sb_node_preview ._sb_description {
     227              :   margin: 10px;
     228              :   padding: 6px;
     229              :   background: var(--border);
     230              :   border-radius: 5px;
     231              :   font-style: italic;
     232              :   font-weight: 500;
     233              :   font-size: 0.9rem;
     234              :   word-break: break-word;
     235              : }
     236              : 
     237              : ._sb_table {
     238              :   display: grid;
     239              : 
     240              :   grid-column-gap: 10px;
     241              :   /* Spazio tra le colonne */
     242              :   width: 100%;
     243              :   /* Imposta la larghezza della tabella al 100% del contenitore */
     244              : }
     245              : 
     246              : ._sb_row {
     247              :   display: grid;
     248              :   grid-template-columns: 10px 1fr 1fr 1fr 10px;
     249              :   grid-column-gap: 10px;
     250              :   align-items: center;
     251              :   padding-left: 9px;
     252              :   padding-right: 9px;
     253              : }
     254              : 
     255              : ._sb_row_string {
     256              :   grid-template-columns: 10px 1fr 1fr 10fr 1fr;
     257              : }
     258              : 
     259              : ._sb_col {
     260              :   border: 0 solid #000;
     261              :   display: flex;
     262              :   align-items: flex-end;
     263              :   flex-direction: row-reverse;
     264              :   flex-wrap: nowrap;
     265              :   align-content: flex-start;
     266              :   justify-content: flex-end;
     267              : }
     268              : 
     269              : ._sb_inherit {
     270              :   display: inherit;
     271              : }
     272              : 
     273              : ._long_field {
     274              :   background: var(--background);
     275              :   border: 2px solid var(--border);
     276              :   margin: 5px 5px 0;
     277              :   border-radius: 10px;
     278              :   line-height: 1.7;
     279              :   text-wrap: nowrap;
     280              : }
     281              : 
     282              : ._sb_arrow {
     283              :   color: var(--foreground);
     284              : }
     285              : 
     286              : ._sb_preview_badge {
     287              :   text-align: center;
     288              :   background: var(--input);
     289              :   font-weight: 700;
     290              :   color: var(--destructive);
     291              : }
     292              : </style>
        

Generated by: LCOV version 2.0-1