Line data Source code
1 : <template>
2 : <div
3 107 : v-if="visible"
4 : ref="modalRoot"
5 : class="absolute right-0 bottom-[62px] flex w-[250px] justify-center border-0! bg-inherit!"
6 : >
7 : <div
8 : class="w-4/5 rounded-lg border bg-background p-2 text-foreground shadow-lg select-none"
9 : :style="filteredMinimapStyles"
10 : @click.stop
11 : >
12 : <div class="flex flex-col gap-1">
13 : <div
14 : class="flex cursor-pointer items-center justify-between rounded-sm px-3 py-2 text-sm hover:bg-accent"
15 : data-testid="zoom-in-action"
16 : @mousedown="startRepeat('Comfy.Canvas.ZoomIn')"
17 : @mouseup="stopRepeat"
18 : @mouseleave="stopRepeat"
19 : >
20 : <span class="font-medium">{{ $t('graphCanvasMenu.zoomIn') }}</span>
21 : <span class="text-[9px]">{{ zoomInCommandText }}</span>
22 : </div>
23 :
24 : <div
25 : class="flex cursor-pointer items-center justify-between rounded-sm px-3 py-2 text-sm hover:bg-accent"
26 : data-testid="zoom-out-action"
27 : @mousedown="startRepeat('Comfy.Canvas.ZoomOut')"
28 : @mouseup="stopRepeat"
29 : @mouseleave="stopRepeat"
30 : >
31 : <span class="font-medium">{{ $t('graphCanvasMenu.zoomOut') }}</span>
32 : <span class="text-[9px]">{{ zoomOutCommandText }}</span>
33 : </div>
34 :
35 : <div
36 : class="flex cursor-pointer items-center justify-between rounded-sm px-3 py-2 text-sm hover:bg-accent"
37 : data-testid="zoom-to-fit-action"
38 : @click="executeCommand('Comfy.Canvas.FitView')"
39 : >
40 : <span class="font-medium">{{ $t('zoomControls.zoomToFit') }}</span>
41 : <span class="text-[9px]">{{ zoomToFitCommandText }}</span>
42 : </div>
43 :
44 : <FormNumberField
45 : class="w-full"
46 : :model-value="canvasStore.appScalePercentage"
47 : :min="1"
48 : :max="1000"
49 : :format-options="{ useGrouping: false, maximumFractionDigits: 0 }"
50 : :aria-label="$t('zoomControls.zoomPercentage')"
51 : data-testid="zoom-percentage-input"
52 : @update:model-value="canvasStore.setAppZoomFromPercentage"
53 : >
54 : <template #suffix>
55 : <span class="shrink-0 text-sm">%</span>
56 : </template>
57 : </FormNumberField>
58 : </div>
59 : </div>
60 : </div>
61 : </template>
62 :
63 : <script setup lang="ts">
64 : import { computed, nextTick, ref, useTemplateRef, watch } from 'vue'
65 :
66 : import FormNumberField from '@/components/common/FormNumberField.vue'
67 : import { useCanvasStore } from '@/renderer/core/canvas/canvasStore'
68 : import { useMinimap } from '@/renderer/extensions/minimap/composables/useMinimap'
69 : import { useCommandStore } from '@/platform/keybindings/commandStore'
70 :
71 68 : const minimap = useMinimap()
72 68 : const commandStore = useCommandStore()
73 68 : const canvasStore = useCanvasStore()
74 68 : const { formatKeySequence } = useCommandStore()
75 :
76 : interface Props {
77 : visible: boolean
78 : }
79 :
80 68 : const props = defineProps<Props>()
81 :
82 68 : const interval = ref<number | null>(null)
83 :
84 68 : const executeCommand = (command: string) => {
85 1 : void commandStore.execute(command)
86 : }
87 :
88 68 : const startRepeat = (command: string) => {
89 33 : if (interval.value) return
90 33 : const cmd = () => commandStore.execute(command)
91 33 : void cmd()
92 33 : interval.value = window.setInterval(cmd, 100)
93 : }
94 :
95 68 : const stopRepeat = () => {
96 34 : if (interval.value) {
97 33 : clearInterval(interval.value)
98 33 : interval.value = null
99 : }
100 : }
101 68 : const filteredMinimapStyles = computed(() => {
102 6 : return {
103 : ...minimap.containerStyles.value,
104 : height: undefined,
105 : width: undefined
106 : }
107 : })
108 68 : const zoomInCommandText = computed(() =>
109 : formatKeySequence(commandStore.getCommand('Comfy.Canvas.ZoomIn'))
110 : )
111 68 : const zoomOutCommandText = computed(() =>
112 : formatKeySequence(commandStore.getCommand('Comfy.Canvas.ZoomOut'))
113 : )
114 68 : const zoomToFitCommandText = computed(() =>
115 : formatKeySequence(commandStore.getCommand('Comfy.Canvas.FitView'))
116 : )
117 68 : const modalRoot = useTemplateRef<HTMLDivElement>('modalRoot')
118 :
119 68 : watch(
120 : () => props.visible,
121 : async (visible) => {
122 8 : if (!visible) return
123 6 : await nextTick()
124 8 : modalRoot.value?.querySelector('input')?.focus()
125 : }
126 : )
127 : </script>
|