Line data Source code
1 : <script setup lang="ts">
2 : import type { MenuItem } from '@comfyorg/design-system/lib/menu/types'
3 : import { useFullscreen, usePointerSwipe } from '@vueuse/core'
4 : import { computed, ref, useTemplateRef } from 'vue'
5 : import { useI18n } from 'vue-i18n'
6 :
7 : import AssetsSidebarTab from '@/components/sidebar/tabs/AssetsSidebarTab.vue'
8 : import CurrentUserButton from '@/components/topbar/CurrentUserButton.vue'
9 : import Button from '@comfyorg/design-system/button/Button'
10 : import Menu from '@comfyorg/design-system/menu/Menu'
11 : import MenuRadioGroup from '@comfyorg/design-system/menu/MenuRadioGroup'
12 : import { useCurrentUser } from '@/composables/auth/useCurrentUser'
13 : import { APP_MODE_FEEDBACK_FORM_URL } from '@/platform/surveys/appModeFeedback'
14 : import { useWorkflowService } from '@/platform/workflow/core/services/workflowService'
15 : import { useWorkflowStore } from '@/platform/workflow/management/stores/workflowStore'
16 : import { useCanvasStore } from '@/renderer/core/canvas/canvasStore'
17 : import LinearControls from '@/renderer/extensions/linearMode/LinearControls.vue'
18 : import LinearPreview from '@/renderer/extensions/linearMode/LinearPreview.vue'
19 : import MobileError from '@/renderer/extensions/linearMode/MobileError.vue'
20 : import { useThemeService } from '@/platform/theme/themeService'
21 : import { useErrorOverlayState } from '@/platform/workflowErrors/overlay/useErrorOverlayState'
22 : import { useQueueStore } from '@/stores/queueStore'
23 : import { useMenuItemStore } from '@/stores/menuItemStore'
24 : import { useThemeStore } from '@/platform/theme/themeStore'
25 : import { cn } from '@comfyorg/tailwind-utils'
26 :
27 2355 : const tabs = [
28 : ['linearMode.mobileControls', 'icon-[lucide--play]', 'control'],
29 : ['nodeHelpPage.outputs', 'icon-[comfy--image-ai-edit]', 'preview'],
30 : ['sideToolbar.assets', 'icon-[lucide--images]', 'output']
31 : ]
32 :
33 1 : const canvasStore = useCanvasStore()
34 1 : const themeService = useThemeService()
35 1 : const themeStore = useThemeStore()
36 1 : const { isLoggedIn } = useCurrentUser()
37 1 : const { isVisible: isErrorOverlayVisible } = useErrorOverlayState()
38 1 : const { t } = useI18n()
39 1 : const { commandIdToMenuItem } = useMenuItemStore()
40 1 : const queueStore = useQueueStore()
41 1 : const workflowService = useWorkflowService()
42 1 : const workflowStore = useWorkflowStore()
43 1 : const { toggle: toggleFullscreen } = useFullscreen(undefined, {
44 : autoExit: true
45 : })
46 :
47 1 : const activeIndex = ref(1)
48 1 : const sliderPaneRef = useTemplateRef('sliderPaneRef')
49 1 : const sliderWidth = computed(() => sliderPaneRef.value?.offsetWidth)
50 :
51 1 : const { distanceX, isSwiping } = usePointerSwipe(sliderPaneRef, {
52 : disableTextSelect: true,
53 : onSwipeEnd() {
54 0 : if (
55 : !sliderWidth.value ||
56 : Math.abs(distanceX.value) / sliderWidth.value < 0.4
57 : )
58 0 : return
59 0 : if (distanceX.value < 0)
60 0 : activeIndex.value = Math.max(activeIndex.value - 1, 0)
61 0 : else activeIndex.value = Math.min(activeIndex.value + 1, tabs.length - 1)
62 : }
63 : })
64 :
65 1 : const translate = computed(() => {
66 : const slideOffset =
67 : isSwiping.value && sliderWidth.value
68 : ? distanceX.value / sliderWidth.value
69 : : 0
70 : const totalOffset = slideOffset + activeIndex.value
71 1 : return `${totalOffset * -100}vw`
72 : })
73 :
74 0 : function onClick(index: number) {
75 0 : if (Math.abs(distanceX.value) > 30) return
76 0 : activeIndex.value = index
77 : }
78 :
79 1 : const workflowOptions = computed(() =>
80 : workflowStore.openWorkflows.map((workflow) => ({
81 : value: workflow.path,
82 : label: workflow.filename,
83 : icon: workflow.activeState?.extra?.linearMode
84 : ? 'icon-[lucide--panels-top-left]'
85 : : undefined
86 : }))
87 : )
88 1 : const activeWorkflowPath = computed({
89 : get: () => workflowStore.activeWorkflow?.path ?? '',
90 : set: (path: string) => {
91 0 : const workflow = workflowStore.getWorkflowByPath(path)
92 0 : if (workflow)
93 0 : void workflowService.openWorkflow(workflow, { initiator: 'user' })
94 : }
95 : })
96 :
97 1 : const menuEntries = computed<MenuItem[]>(() => [
98 : {
99 : ...commandIdToMenuItem('Comfy.BrowseTemplates'),
100 : label: t('sideToolbar.templates'),
101 : icon: 'icon-[comfy--template]'
102 : },
103 : { separator: true },
104 : {
105 : label: t('icon.file'),
106 : items: [
107 : commandIdToMenuItem('Comfy.RenameWorkflow'),
108 : commandIdToMenuItem('Comfy.DuplicateWorkflow'),
109 : { separator: true },
110 : commandIdToMenuItem('Comfy.SaveWorkflow'),
111 : commandIdToMenuItem('Comfy.SaveWorkflowAs'),
112 : { separator: true },
113 : commandIdToMenuItem('Comfy.ExportWorkflow'),
114 : commandIdToMenuItem('Comfy.ExportWorkflowAPI')
115 : ]
116 : },
117 : {
118 : label: t('g.edit'),
119 : items: [
120 : commandIdToMenuItem('Comfy.Undo'),
121 : commandIdToMenuItem('Comfy.Redo'),
122 : { separator: true },
123 : commandIdToMenuItem('Comfy.RefreshNodeDefinitions'),
124 : commandIdToMenuItem('Comfy.Memory.UnloadModels'),
125 : commandIdToMenuItem('Comfy.Memory.UnloadModelsAndExecutionCache')
126 : ]
127 : },
128 : {
129 : label: t('linearMode.enterNodeGraph'),
130 : icon: 'icon-[comfy--workflow]',
131 : badge: t('contextMenu.new'),
132 : command: () => (canvasStore.linearMode = false)
133 : },
134 : { separator: true },
135 : {
136 : label: t('menu.theme'),
137 : items: themeStore.presets.map((palette) => ({
138 : label: palette.name,
139 : icon:
140 : themeStore.activePresetId === palette.id ? 'icon-[lucide--check]' : '',
141 : command: () => themeService.setActiveTheme(palette.id)
142 : }))
143 : },
144 : { separator: true },
145 : {
146 : ...commandIdToMenuItem('Comfy.ShowSettingsDialog'),
147 : label: t('menu.settings')
148 : },
149 : {
150 : label: t('linearMode.giveFeedback'),
151 : icon: 'icon-[lucide--megaphone] size-4',
152 : command: () =>
153 : window.open(APP_MODE_FEEDBACK_FORM_URL, '_blank', 'noopener,noreferrer')
154 : },
155 : {
156 : label: t('menu.fullscreen'),
157 : icon: 'icon-[lucide--fullscreen]',
158 : command: toggleFullscreen
159 : }
160 : ])
161 1 : </script>
162 : <template>
163 1 : <section
164 : class="absolute flex size-full flex-col bg-secondary"
165 : data-testid="linear-mobile"
166 : >
167 : <header
168 : class="flex h-16 w-full items-center gap-3 border-b border-border/50 bg-background px-4 py-3"
169 : >
170 : <Menu :items="menuEntries" :label="$t('linearMode.appModeToolbar.apps')">
171 : <template #trigger>
172 : <Button
173 : size="icon"
174 : icon="icon-[lucide--menu]"
175 : :aria-label="$t('g.more')"
176 : />
177 : </template>
178 : </Menu>
179 : <Menu>
180 : <template #trigger>
181 : <Button
182 : variant="secondary"
183 : class="min-w-0 flex-1"
184 : data-testid="linear-mobile-workflows"
185 : icon="icon-[lucide--panels-top-left]"
186 : >
187 : <span
188 : class="min-w-0 flex-1 truncate"
189 : v-text="workflowStore.activeWorkflow?.filename"
190 : />
191 : <i class="icon-[lucide--chevron-down]" aria-hidden="true" />
192 : </Button>
193 : </template>
194 : <MenuRadioGroup
195 : v-model="activeWorkflowPath"
196 : :options="workflowOptions"
197 : />
198 : </Menu>
199 : <CurrentUserButton v-if="isLoggedIn" :show-arrow="false" />
200 : </header>
201 : <div class="size-full rounded-b-4xl contain-content">
202 : <div
203 : :class="
204 : cn('relative size-full', !isSwiping && 'transition-[translate]')
205 : "
206 : :style="{ translate }"
207 : >
208 : <div
209 : id="mobile-app-control-panel"
210 : class="absolute h-full w-screen overflow-y-auto contain-size"
211 : role="tabpanel"
212 : :aria-hidden="activeIndex !== 0"
213 : aria-labelledby="mobile-app-control-tab"
214 : :inert="activeIndex !== 0"
215 : >
216 : <LinearControls mobile @navigate-outputs="activeIndex = 1" />
217 : </div>
218 : <div
219 : id="mobile-app-preview-panel"
220 : class="absolute top-0 left-[100vw] flex h-full w-screen flex-col bg-background"
221 : role="tabpanel"
222 : :aria-hidden="activeIndex !== 1"
223 : aria-labelledby="mobile-app-preview-tab"
224 : :inert="activeIndex !== 1"
225 : >
226 : <MobileError
227 : v-if="isErrorOverlayVisible"
228 : @navigate-controls="activeIndex = 0"
229 : />
230 : <LinearPreview v-else mobile @navigate-controls="activeIndex = 0" />
231 : </div>
232 : <AssetsSidebarTab
233 : id="mobile-app-output-panel"
234 : class="absolute top-0 left-[200vw] h-full w-screen bg-background"
235 : role="tabpanel"
236 : :aria-hidden="activeIndex !== 2"
237 : aria-labelledby="mobile-app-output-tab"
238 : :inert="activeIndex !== 2"
239 : :closable="false"
240 : />
241 : </div>
242 : </div>
243 : <div
244 : ref="sliderPaneRef"
245 : class="flex h-22 w-full items-center justify-around gap-4 bg-secondary p-4"
246 : role="tablist"
247 : >
248 3 : <Button
249 : v-for="([label, icon, id], index) in tabs"
250 : :id="`mobile-app-${id}-tab`"
251 : :key="label"
252 : :variant="index === activeIndex ? 'secondary' : 'muted-textonly'"
253 : class="h-14 grow flex-col"
254 : role="tab"
255 : :aria-selected="index === activeIndex"
256 : :aria-controls="`mobile-app-${id}-panel`"
257 : @click="onClick(index)"
258 : >
259 : <div class="relative size-4">
260 : <i :class="icon" />
261 : <div
262 : v-if="index === 1 && isErrorOverlayVisible"
263 : class="absolute -top-1 -right-1 size-2 rounded-full bg-destructive"
264 : />
265 : <div
266 : v-else-if="
267 : index === 1 &&
268 : (queueStore.runningTasks.length > 0 ||
269 : queueStore.pendingTasks.length > 0)
270 : "
271 : class="absolute -top-1 -right-1 size-2 animate-pulse rounded-full bg-primary"
272 : />
273 : </div>
274 : {{ t(label) }}
275 : </Button>
276 : </div>
277 : </section>
278 : </template>
|