|
| 1 | +<template> |
| 2 | + <div v-if="renderError" class="node-error p-1 text-red-500 text-xs">⚠️</div> |
| 3 | + <div |
| 4 | + v-else |
| 5 | + class="lg-slot lg-slot--input flex items-center cursor-crosshair group" |
| 6 | + :class="{ |
| 7 | + 'opacity-70': readonly, |
| 8 | + 'lg-slot--connected': connected, |
| 9 | + 'lg-slot--compatible': compatible, |
| 10 | + 'lg-slot--dot-only': dotOnly, |
| 11 | + 'pr-2 hover:bg-black/5': !dotOnly |
| 12 | + }" |
| 13 | + :style="{ |
| 14 | + height: slotHeight + 'px' |
| 15 | + }" |
| 16 | + @pointerdown="handleClick" |
| 17 | + > |
| 18 | + <!-- Connection Dot --> |
| 19 | + <div class="w-5 h-5 flex items-center justify-center group/slot"> |
| 20 | + <div |
| 21 | + class="w-2 h-2 rounded-full bg-white transition-all duration-150 group-hover/slot:w-2.5 group-hover/slot:h-2.5 group-hover/slot:border-2 group-hover/slot:border-white" |
| 22 | + :style="{ |
| 23 | + backgroundColor: slotColor |
| 24 | + }" |
| 25 | + /> |
| 26 | + </div> |
| 27 | + |
| 28 | + <!-- Slot Name --> |
| 29 | + <span v-if="!dotOnly" class="text-xs text-surface-700 whitespace-nowrap"> |
| 30 | + {{ slotData.name || `Input ${index}` }} |
| 31 | + </span> |
| 32 | + </div> |
| 33 | +</template> |
| 34 | + |
| 35 | +<script setup lang="ts"> |
| 36 | +import { computed, onErrorCaptured, ref } from 'vue' |
| 37 | +
|
| 38 | +import { useErrorHandling } from '@/composables/useErrorHandling' |
| 39 | +import { getSlotColor } from '@/constants/slotColors' |
| 40 | +import { |
| 41 | + COMFY_VUE_NODE_DIMENSIONS, |
| 42 | + INodeSlot, |
| 43 | + LGraphNode |
| 44 | +} from '@/lib/litegraph/src/litegraph' |
| 45 | +
|
| 46 | +interface InputSlotProps { |
| 47 | + node?: LGraphNode |
| 48 | + slotData: INodeSlot |
| 49 | + index: number |
| 50 | + connected?: boolean |
| 51 | + compatible?: boolean |
| 52 | + readonly?: boolean |
| 53 | + dotOnly?: boolean |
| 54 | +} |
| 55 | +
|
| 56 | +const props = defineProps<InputSlotProps>() |
| 57 | +
|
| 58 | +const emit = defineEmits<{ |
| 59 | + 'slot-click': [event: PointerEvent] |
| 60 | +}>() |
| 61 | +
|
| 62 | +// Error boundary implementation |
| 63 | +const renderError = ref<string | null>(null) |
| 64 | +const { toastErrorHandler } = useErrorHandling() |
| 65 | +
|
| 66 | +onErrorCaptured((error) => { |
| 67 | + renderError.value = error.message |
| 68 | + toastErrorHandler(error) |
| 69 | + return false |
| 70 | +}) |
| 71 | +
|
| 72 | +// Get slot color based on type |
| 73 | +const slotColor = computed(() => getSlotColor(props.slotData.type)) |
| 74 | +
|
| 75 | +// Get slot height from litegraph constants |
| 76 | +const slotHeight = COMFY_VUE_NODE_DIMENSIONS.components.SLOT_HEIGHT |
| 77 | +
|
| 78 | +// Handle click events |
| 79 | +const handleClick = (event: PointerEvent) => { |
| 80 | + if (!props.readonly) { |
| 81 | + emit('slot-click', event) |
| 82 | + } |
| 83 | +} |
| 84 | +</script> |
0 commit comments