Line data Source code
1 : <template>
2 10461 : <div v-if="renderError" class="node-error p-1 text-xs text-destructive">
3 : ⚠️
4 : </div>
5 : <Tooltip v-else :disabled="!tooltipText">
6 : <TooltipTrigger as-child>
7 : <div
8 : :class="slotWrapperClass"
9 : @pointerenter="revealLinks"
10 : @pointerleave="unrevealLinks"
11 : >
12 : <div class="relative flex h-full min-w-0 items-center">
13 : <span v-if="!props.dotOnly && !hasNoLabel" class="truncate">
14 : {{
15 : slotData.label ||
16 : slotData.localized_name ||
17 : (slotData.name ?? `Output ${index}`)
18 : }}
19 : </span>
20 : </div>
21 : <!-- Connection Dot -->
22 : <SlotConnectionDot
23 : :slot-key
24 : class="w-3 translate-x-1/2"
25 : :slot-data
26 : @pointerdown="onPointerDown"
27 : />
28 : </div>
29 : </TooltipTrigger>
30 : <TooltipContent side="right">{{ tooltipText }}</TooltipContent>
31 : </Tooltip>
32 : </template>
33 :
34 : <script setup lang="ts">
35 : import { computed, onErrorCaptured, ref } from 'vue'
36 :
37 : import Tooltip from '@comfyorg/design-system/tooltip/Tooltip'
38 : import TooltipContent from '@comfyorg/design-system/tooltip/TooltipContent'
39 : import TooltipTrigger from '@comfyorg/design-system/tooltip/TooltipTrigger'
40 : import { useErrorHandling } from '@/composables/useErrorHandling'
41 : import type { INodeSlot } from '@/lib/litegraph/src/litegraph'
42 : import { useSlotLinkDragUIState } from '@/renderer/core/canvas/links/slotLinkDragUIState'
43 : import { getSlotKey } from '@/renderer/core/layout/slots/slotIdentifier'
44 : import { useNodeTooltips } from '@/renderer/extensions/vueNodes/composables/useNodeTooltips'
45 : import { useSlotLinkInteraction } from '@/renderer/extensions/vueNodes/composables/useSlotLinkInteraction'
46 : import { useSlotLinkReveal } from '@/renderer/extensions/vueNodes/composables/useSlotLinkReveal'
47 : import { cn } from '@comfyorg/tailwind-utils'
48 : import type { NodeId } from '@comfyorg/graph-model/nodeId'
49 :
50 : import SlotConnectionDot from './SlotConnectionDot.vue'
51 :
52 : interface OutputSlotProps {
53 : nodeType?: string
54 : nodeId?: NodeId
55 : slotData: INodeSlot
56 : index: number
57 : connected?: boolean
58 : compatible?: boolean
59 : dotOnly?: boolean
60 : }
61 :
62 10246 : const props = defineProps<OutputSlotProps>()
63 :
64 10246 : const hasNoLabel = computed(
65 : () => !props.slotData.localized_name && props.slotData.name === ''
66 : )
67 10246 : const effectiveDotOnly = computed(() => props.dotOnly || hasNoLabel.value)
68 : // Error boundary implementation
69 10246 : const renderError = ref<string | null>(null)
70 :
71 10246 : const { toastErrorHandler } = useErrorHandling()
72 :
73 10246 : const { getOutputSlotTooltip } = useNodeTooltips(props.nodeType || '')
74 10246 : const tooltipText = computed(() =>
75 : getOutputSlotTooltip(props.slotData, props.index)
76 : )
77 :
78 10246 : const { revealLinks, unrevealLinks } = useSlotLinkReveal({
79 : nodeId: props.nodeId,
80 : index: props.index,
81 : type: 'output'
82 : })
83 :
84 10246 : onErrorCaptured((error) => {
85 0 : unrevealLinks()
86 0 : renderError.value = error.message
87 0 : toastErrorHandler(error)
88 0 : return false
89 : })
90 :
91 10246 : const { state: dragState } = useSlotLinkDragUIState()
92 10246 : const slotKey = computed(() =>
93 : props.nodeId ? getSlotKey(props.nodeId, props.index, false) : undefined
94 : )
95 10246 : const shouldDim = computed(() => {
96 10784 : if (!dragState.active) return false
97 10784 : return !slotKey.value || !dragState.compatible.get(slotKey.value)
98 : })
99 :
100 10246 : const slotWrapperClass = computed(() =>
101 : cn(
102 : 'lg-slot lg-slot--output group flex h-5 items-center justify-end rounded-l-lg',
103 : 'cursor-crosshair',
104 : effectiveDotOnly.value ? 'lg-slot--dot-only justify-center' : 'pl-2',
105 : {
106 : 'lg-slot--connected': props.connected,
107 : 'lg-slot--compatible': props.compatible,
108 : 'opacity-40': shouldDim.value
109 : }
110 : )
111 : )
112 :
113 10246 : const { onPointerDown } = useSlotLinkInteraction({
114 : nodeId: props.nodeId,
115 : index: props.index,
116 : type: 'output'
117 : })
118 : </script>
|