Line data Source code
1 : <script setup lang="ts">
2 : import { remove } from 'es-toolkit'
3 : import { computed } from 'vue'
4 :
5 : import type { LinearInput } from '@/platform/workflow/management/stores/comfyWorkflow'
6 : import { useAppModeStore } from '@/stores/appModeStore'
7 : import type { WidgetId } from '@comfyorg/graph-model/widgetId'
8 : import { cn } from '@comfyorg/tailwind-utils'
9 :
10 : const { widgetId, name } = defineProps<{
11 : widgetId?: WidgetId
12 : enable: boolean
13 : name: string
14 : }>()
15 :
16 15370 : const appModeStore = useAppModeStore()
17 15370 : const isPromoted = computed(() => appModeStore.selectedInputs.some(matchesThis))
18 :
19 1129 : function matchesThis([storedId]: LinearInput) {
20 1129 : return widgetId !== undefined && storedId === widgetId
21 : }
22 48 : function togglePromotion() {
23 48 : if (!widgetId) return
24 48 : if (isPromoted.value) remove(appModeStore.selectedInputs, matchesThis)
25 48 : else appModeStore.selectedInputs.push([widgetId, name])
26 : }
27 15370 : </script>
28 : <template>
29 : <div
30 43195 : v-if="enable"
31 : class="pointer-events-auto relative flex min-w-0 cursor-pointer gap-1"
32 : @pointerdown.capture.stop.prevent="togglePromotion"
33 : @click.capture.stop.prevent
34 : @pointerup.capture.stop.prevent
35 : @pointermove.capture.stop.prevent
36 : @contextmenu.capture.stop.prevent
37 : >
38 : <div
39 : :class="
40 : cn(
41 : 'm-1 size-4 self-center rounded-sm border border-primary',
42 : isPromoted && 'flex items-center bg-primary'
43 : )
44 : "
45 : >
46 : <i
47 : v-if="isPromoted"
48 : class="place-center icon-[lucide--check] bg-background"
49 : />
50 : </div>
51 : <div
52 : :class="
53 : cn(
54 : 'pointer-events-none grid min-w-0 flex-1 grid-cols-1 items-stretch rounded-lg ring-primary',
55 : isPromoted && 'ring-2'
56 : )
57 : "
58 : >
59 : <slot />
60 : </div>
61 : <div class="absolute size-full rounded-lg hover:bg-primary/10" />
62 : </div>
63 : <slot v-else />
64 : </template>
|