LCOV - code coverage report
Current view: top level - src/renderer/extensions/vueNodes/components - NodeSlots.vue Coverage Total Hit
Test: ComfyUI E2E Coverage Lines: 92.5 % 40 37
Test Date: 2026-11-17 04:17:53

            Line data    Source code
       1              : <template>
       2         8542 :   <div v-if="renderError" class="node-error p-2 text-sm text-destructive">
       3              :     {{ st('nodeErrors.slots', 'Node Slots Error') }}
       4              :   </div>
       5              :   <div
       6              :     v-else
       7              :     ref="slots"
       8              :     :class="
       9              :       cn(
      10              :         'flex min-w-0 justify-between',
      11              :         unified &&
      12              :           'pointer-events-none absolute inset-0 z-30 items-center opacity-0'
      13              :       )
      14              :     "
      15              :   >
      16              :     <div
      17              :       v-if="filteredInputs.length"
      18              :       :class="cn('flex min-w-0 flex-col', unifiedDotsClass)"
      19              :     >
      20        11176 :       <InputSlot
      21              :         v-for="(input, index) in filteredInputs"
      22              :         :key="`input-${input.name}-${getActualInputIndex(input, index)}`"
      23              :         :slot-data="input"
      24              :         :node-type="nodeData?.type || ''"
      25              :         :node-id="nodeData.id"
      26              :         :has-error="inputHasError(input)"
      27              :         :index="getActualInputIndex(input, index)"
      28              :         :connected="isInputConnected(getActualInputIndex(input, index))"
      29              :       />
      30              :     </div>
      31              : 
      32              :     <div
      33              :       v-if="nodeData.outputs.length"
      34              :       :class="cn('ml-auto flex min-w-0 flex-col', unifiedDotsClass)"
      35              :     >
      36        10833 :       <OutputSlot
      37              :         v-for="(output, index) in nodeData.outputs"
      38              :         :key="`output-${output.name}-${index}`"
      39              :         :slot-data="output"
      40              :         :node-type="nodeData?.type || ''"
      41              :         :node-id="nodeData.id"
      42              :         :index="index"
      43              :         :connected="isOutputConnected(index)"
      44              :       />
      45              :     </div>
      46              :   </div>
      47              : </template>
      48              : 
      49              : <script setup lang="ts">
      50              : import { computed, onErrorCaptured, ref, useTemplateRef, watch } from 'vue'
      51              : 
      52              : import { useErrorHandling } from '@/composables/useErrorHandling'
      53              : import { st } from '@/i18n'
      54              : import type { INodeSlot } from '@/lib/litegraph/src/litegraph'
      55              : import { useCanvasStore } from '@/renderer/core/canvas/canvasStore'
      56              : import { syncSlotOffsets } from '@/renderer/core/layout/slots/syncSlotOffsets'
      57              : import { layoutStore } from '@/renderer/core/layout/store/layoutStore'
      58              : import {
      59              :   linkedWidgetedInputs,
      60              :   nonWidgetedInputs
      61              : } from '@/renderer/extensions/vueNodes/utils/nodeDataUtils'
      62              : import { useExecutionErrorStore } from '@/stores/executionErrorStore'
      63              : import { useLinkStore } from '@/stores/linkStore'
      64              : import type { GraphScope } from '@comfyorg/graph-model/graphScopeId'
      65              : import {
      66              :   toOwningGraphId,
      67              :   toRootGraphId
      68              : } from '@comfyorg/graph-model/graphScopeId'
      69              : import type { NodeState } from '@comfyorg/graph-model/nodeState'
      70              : import { locatorIdFromState } from '@/utils/graphTraversalUtil'
      71              : import { cn } from '@comfyorg/tailwind-utils'
      72              : 
      73              : import InputSlot from './InputSlot.vue'
      74              : import OutputSlot from './OutputSlot.vue'
      75              : 
      76              : const {
      77              :   nodeData,
      78              :   unified = false,
      79              :   syncLayout = true
      80              : } = defineProps<{
      81              :   nodeData: NodeState
      82              :   unified?: boolean
      83              :   syncLayout?: boolean
      84              : }>()
      85         8061 : const canvasStore = useCanvasStore()
      86         8061 : const slots = useTemplateRef<HTMLElement>('slots')
      87         8061 : const executionErrorStore = useExecutionErrorStore()
      88         8061 : const linkStore = useLinkStore()
      89         8061 : const nodeLocatorId = computed(() =>
      90              :   locatorIdFromState(nodeData, canvasStore.rootGraphId)
      91              : )
      92         8061 : const nodeScope = computed<GraphScope | null>(() => {
      93         8103 :   const graph = canvasStore.currentGraph
      94         8103 :   return graph
      95              :     ? {
      96              :         rootGraphId: toRootGraphId(graph.rootGraph.id),
      97              :         owningGraphId: toOwningGraphId(nodeData.graphId)
      98              :       }
      99              :     : null
     100              : })
     101              : 
     102         8061 : const linkedWidgetInputs = computed(() =>
     103              :   unified && nodeScope.value
     104              :     ? linkedWidgetedInputs(nodeData.id, nodeData.inputs, nodeScope.value)
     105              :     : []
     106              : )
     107              : 
     108        11176 : function isInputConnected(index: number): boolean {
     109        11176 :   const scope = nodeScope.value
     110        11176 :   if (!scope) return false
     111        11176 :   return linkStore.isInputSlotConnected(scope, nodeData.id, index)
     112              : }
     113              : 
     114        10833 : function isOutputConnected(index: number): boolean {
     115        10833 :   const scope = nodeScope.value
     116        10833 :   if (!scope) return false
     117        10833 :   return linkStore.isOutputSlotConnected(scope, nodeData.id, index)
     118              : }
     119              : 
     120         8061 : const filteredInputs = computed(() => [
     121              :   ...nonWidgetedInputs(nodeData.inputs),
     122              :   ...linkedWidgetInputs.value
     123              : ])
     124              : 
     125         8061 : const layoutKey = computed(() =>
     126              :   [
     127              :     ...filteredInputs.value.map((input, index) =>
     128              :       getActualInputIndex(input, index)
     129              :     ),
     130              :     '|',
     131              :     ...nodeData.outputs.keys(),
     132              :     unified
     133              :   ].join(':')
     134              : )
     135              : 
     136         8061 : watch(
     137              :   [
     138              :     layoutKey,
     139              :     slots,
     140              :     () => canvasStore.rootGraphId,
     141              :     () => layoutStore.slotOffsetVersion
     142              :   ],
     143              :   () => {
     144         8217 :     const rootGraphId = canvasStore.rootGraphId
     145         8217 :     if (syncLayout && slots.value && rootGraphId) {
     146         8192 :       syncSlotOffsets(slots.value, rootGraphId, nodeData.id)
     147              :     }
     148              :   },
     149              :   { flush: 'post' }
     150              : )
     151              : 
     152        11176 : function inputHasError(input: INodeSlot): boolean {
     153        11176 :   const locatorId = nodeLocatorId.value
     154        11176 :   if (!locatorId) return false
     155              : 
     156        11176 :   return executionErrorStore.slotHasError(locatorId, input.name)
     157              : }
     158              : 
     159         8061 : const unifiedDotsClass = computed((): string =>
     160              :   cn(
     161              :     unified &&
     162              :       'grid grid-cols-1 grid-rows-1 place-items-center gap-0 *:col-span-full *:row-span-full'
     163              :   )
     164              : )
     165              : 
     166              : // Get the actual index of an input slot in the node's inputs array
     167              : // (accounting for filtered widget slots)
     168        44289 : function getActualInputIndex(input: INodeSlot, filteredIndex: number): number {
     169        44289 :   const actualIndex = nodeData.inputs.findIndex((i) => i === input)
     170        44289 :   return actualIndex !== -1 ? actualIndex : filteredIndex
     171              : }
     172              : 
     173              : // Error boundary implementation
     174         8061 : const renderError = ref<string | null>(null)
     175         8061 : const { toastErrorHandler } = useErrorHandling()
     176              : 
     177         8061 : onErrorCaptured((error) => {
     178            0 :   renderError.value = error.message
     179            0 :   toastErrorHandler(error)
     180            0 :   return false
     181              : })
     182              : </script>
        

Generated by: LCOV version 2.0-1