Line data Source code
1 : <template>
2 29 : <PopoverRoot v-model:open="isOpen">
3 : <PopoverTrigger as-child>
4 : <Button
5 : :tooltip="t('g.arrange')"
6 : variant="muted-textonly"
7 : :aria-label="t('g.arrange')"
8 : >
9 : <div class="flex items-center gap-1 px-0">
10 : <i class="icon-[lucide--layout-grid]" />
11 : <i class="icon-[lucide--chevron-down]" />
12 : </div>
13 : </Button>
14 : </PopoverTrigger>
15 : <PopoverContent
16 : :side-offset="5"
17 : class="w-auto overflow-visible rounded-lg border-border/50 p-2 shadow-sm"
18 : >
19 : <div v-if="activeLayout" class="flex w-32 items-center px-2 py-1">
20 : <Slider
21 : :model-value="[gap]"
22 : :min="MIN_ARRANGE_GAP"
23 : :max="MAX_ARRANGE_GAP"
24 : :step="1"
25 : :aria-label="t('g.arrangeSpacing')"
26 : @update:model-value="onSliderUpdate"
27 : @value-commit="onSliderCommit"
28 : />
29 : </div>
30 : <div v-else class="flex gap-1">
31 : <Button
32 : :tooltip="t('g.arrangeVertically')"
33 : variant="muted-textonly"
34 : :aria-label="t('g.arrangeVertically')"
35 : @click="start('vertical')"
36 : >
37 : <i class="icon-[lucide--stretch-horizontal]" />
38 : </Button>
39 : <Button
40 : :tooltip="t('g.arrangeHorizontally')"
41 : variant="muted-textonly"
42 : :aria-label="t('g.arrangeHorizontally')"
43 : @click="start('horizontal')"
44 : >
45 : <i class="icon-[lucide--stretch-vertical]" />
46 : </Button>
47 : <Button
48 : :tooltip="t('g.arrangeAsGrid')"
49 : variant="muted-textonly"
50 : :aria-label="t('g.arrangeAsGrid')"
51 : @click="start('grid')"
52 : >
53 : <i class="icon-[lucide--grid-3x3]" />
54 : </Button>
55 : </div>
56 : <PopoverArrow class="fill-background stroke-border/50" />
57 : </PopoverContent>
58 : </PopoverRoot>
59 : </template>
60 :
61 : <script setup lang="ts">
62 : import { PopoverArrow, PopoverRoot, PopoverTrigger } from 'reka-ui'
63 : import { ref, watch } from 'vue'
64 : import { useI18n } from 'vue-i18n'
65 :
66 : import Button from '@comfyorg/design-system/button/Button'
67 : import PopoverContent from '@comfyorg/design-system/popover/PopoverContent'
68 : import Slider from '@comfyorg/design-system/slider/Slider'
69 : import {
70 : MAX_ARRANGE_GAP,
71 : MIN_ARRANGE_GAP
72 : } from '@/composables/graph/useArrangeNodes'
73 : import { useArrangeSession } from '@/composables/graph/useArrangeSession'
74 :
75 29 : const { t } = useI18n()
76 29 : const { activeLayout, gap, start, previewGap, commitGap, reset } =
77 : useArrangeSession()
78 :
79 29 : const isOpen = ref(false)
80 :
81 29 : watch(isOpen, (open) => {
82 0 : if (!open) reset()
83 : })
84 :
85 29 : const firstValue = (value: number[] | undefined): number | undefined =>
86 : value?.[0]
87 :
88 29 : const onSliderUpdate = (value: number[] | undefined) => {
89 0 : const next = firstValue(value)
90 0 : if (next !== undefined) previewGap(next)
91 : }
92 :
93 29 : const onSliderCommit = (value: number[]) => {
94 0 : const next = firstValue(value)
95 0 : if (next !== undefined) commitGap(next)
96 : }
97 : </script>
|