Line data Source code
1 : <template>
2 2450 : <nav
3 : ref="sideToolbarRef"
4 : data-testid="side-toolbar"
5 : :inert="isHidden"
6 : :aria-hidden="isHidden"
7 : :class="
8 : cn(
9 : 'side-tool-bar-container flex h-full flex-col items-center bg-transparent transition-[max-width,opacity,transform] duration-300 ease-in-out',
10 : {
11 : 'small-sidebar': isSmall,
12 : 'connected-sidebar pointer-events-auto': isConnected,
13 : 'floating-sidebar py-(--comfy-canvas-gutter)': !isConnected,
14 : 'ml-(--comfy-canvas-gutter)':
15 : !isConnected && !isHidden && sidebarLocation === 'left',
16 : 'mr-(--comfy-canvas-gutter)':
17 : !isConnected && !isHidden && sidebarLocation === 'right',
18 : 'overflowing-sidebar': isOverflowing,
19 : 'overflow-hidden border-r border-border/50 shadow-md': isConnected,
20 : 'pointer-events-none overflow-hidden opacity-0': isHidden,
21 : '-translate-x-8': isHidden && sidebarLocation === 'left',
22 : 'translate-x-8': isHidden && sidebarLocation === 'right'
23 : }
24 : )
25 : "
26 : :style="{ maxWidth: isHidden ? '0px' : 'var(--sidebar-width)' }"
27 : >
28 : <div
29 : :class="
30 : isOverflowing
31 : ? 'side-tool-bar-container overflow-y-auto'
32 : : 'flex h-full flex-col'
33 : "
34 : >
35 : <div
36 : ref="topToolbarRef"
37 : data-testid="sidebar-top-group"
38 : :class="groupClasses"
39 : >
40 : <ComfyMenuButton />
41 12019 : <SidebarExtensionTabButton
42 : v-for="tab in tabs"
43 : :key="tab.id"
44 : :tab
45 : :tooltip-suffix="getTabTooltipSuffix(tab)"
46 : :is-small
47 : :selected="tab.id === selectedTab?.id"
48 : @click="onTabClick(tab)"
49 : />
50 : <SidebarTemplatesButton />
51 : </div>
52 :
53 : <div ref="bottomToolbarRef" :class="cn('mt-auto', groupClasses)">
54 : <SidebarLogoutIcon v-if="userStore.isMultiUserServer" :is-small />
55 : <SidebarHelpCenterIcon :is-small />
56 : <SidebarBottomPanelToggleButton
57 : v-if="!isCloud && !hideWorkspaceToggles"
58 : :is-small
59 : />
60 : <SidebarShortcutsToggleButton v-if="!hideWorkspaceToggles" :is-small />
61 : <SidebarSettingsButton :is-small />
62 : <CurrentUserButton
63 : v-if="showProfileButton"
64 : :show-arrow="false"
65 : :side="sidebarLocation === 'left' ? 'right' : 'left'"
66 : class="flex w-full shrink-0 justify-center pb-1"
67 : />
68 : </div>
69 : </div>
70 : <HelpCenterPopups :is-small />
71 : <Suspense v-if="NightlySurveyController">
72 : <component :is="NightlySurveyController" />
73 : </Suspense>
74 : </nav>
75 : </template>
76 :
77 : <script setup lang="ts">
78 : import { useResizeObserver } from '@vueuse/core'
79 : import { debounce } from 'es-toolkit/compat'
80 : import {
81 : computed,
82 : defineAsyncComponent,
83 : nextTick,
84 : onBeforeUnmount,
85 : onMounted,
86 : ref,
87 : watch
88 : } from 'vue'
89 : import { useI18n } from 'vue-i18n'
90 :
91 : import HelpCenterPopups from '@/components/helpcenter/HelpCenterPopups.vue'
92 : import ComfyMenuButton from '@/components/sidebar/ComfyMenuButton.vue'
93 : import SidebarBottomPanelToggleButton from '@/components/sidebar/SidebarBottomPanelToggleButton.vue'
94 : import SidebarSettingsButton from '@/components/sidebar/SidebarSettingsButton.vue'
95 : import SidebarShortcutsToggleButton from '@/components/sidebar/SidebarShortcutsToggleButton.vue'
96 : import CurrentUserButton from '@/components/topbar/CurrentUserButton.vue'
97 : import { useCurrentUser } from '@/composables/auth/useCurrentUser'
98 : import { useFeatureFlags } from '@/composables/useFeatureFlags'
99 : import { isCloud, isDesktop, isNightly } from '@/platform/distribution/types'
100 : import { useSettingStore } from '@/platform/settings/settingStore'
101 : import { useTelemetry } from '@comfyorg/telemetry'
102 : import { useCanvasStore } from '@/renderer/core/canvas/canvasStore'
103 : import { useCommandStore } from '@/platform/keybindings/commandStore'
104 : import { useKeybindingStore } from '@comfyorg/keybindings/keybindingStore'
105 : import { useUserStore } from '@/stores/userStore'
106 : import { useWorkspaceStore } from '@/stores/workspaceStore'
107 : import type { SidebarTabExtension } from '@/types/extensionTypes'
108 : import { cn } from '@comfyorg/tailwind-utils'
109 :
110 : import SidebarHelpCenterIcon from './SidebarHelpCenterIcon.vue'
111 : import SidebarExtensionTabButton from './SidebarExtensionTabButton.vue'
112 : import SidebarLogoutIcon from './SidebarLogoutIcon.vue'
113 : import SidebarTemplatesButton from './SidebarTemplatesButton.vue'
114 :
115 : const {
116 : visibleTabIds,
117 : forceConnected = false,
118 : hideWorkspaceToggles = false
119 : } = defineProps<{
120 : visibleTabIds?: string[]
121 : forceConnected?: boolean
122 : hideWorkspaceToggles?: boolean
123 : }>()
124 :
125 2093 : const NightlySurveyController =
126 : isNightly && !isCloud && !isDesktop
127 : ? defineAsyncComponent(
128 : () => import('@/platform/surveys/NightlySurveyController.vue')
129 : )
130 : : undefined
131 :
132 2093 : const { t } = useI18n()
133 2093 : const workspaceStore = useWorkspaceStore()
134 2093 : const settingStore = useSettingStore()
135 2093 : const userStore = useUserStore()
136 2093 : const { isLoggedIn } = useCurrentUser()
137 2093 : const { flags } = useFeatureFlags()
138 2093 : const showProfileButton = computed(
139 : () => flags.billingNewUxEnabled && isLoggedIn.value
140 : )
141 2093 : const commandStore = useCommandStore()
142 2093 : const canvasStore = useCanvasStore()
143 2093 : const sideToolbarRef = ref<HTMLElement>()
144 2093 : const topToolbarRef = ref<HTMLElement>()
145 2093 : const bottomToolbarRef = ref<HTMLElement>()
146 :
147 2093 : const isSmall = computed(
148 : () => settingStore.get('Comfy.Sidebar.Size') === 'small'
149 : )
150 2093 : const sidebarLocation = computed<'left' | 'right'>(() =>
151 : settingStore.get('Comfy.Sidebar.Location')
152 : )
153 2093 : const sidebarStyle = computed(() => settingStore.get('Comfy.Sidebar.Style'))
154 2093 : const isConnected = computed(
155 : () =>
156 : forceConnected ||
157 : selectedTab.value ||
158 : isOverflowing.value ||
159 : sidebarStyle.value === 'connected'
160 : )
161 :
162 2093 : const tabs = computed(() => {
163 2097 : const all = workspaceStore.getSidebarTabs()
164 2097 : return visibleTabIds
165 : ? all.filter((tab) => visibleTabIds.includes(tab.id))
166 : : all
167 : })
168 2093 : const selectedTab = computed(() => workspaceStore.sidebarTab.activeSidebarTab)
169 2093 : const isHidden = computed(() => canvasStore.isPickingNodes)
170 :
171 : /**
172 : * Handle sidebar tab icon click.
173 : * - Emits UI button telemetry for known tabs
174 : * - Delegates to the corresponding toggle command
175 : */
176 2093 : const onTabClick = async (item: SidebarTabExtension) => {
177 298 : const telemetry = useTelemetry()
178 :
179 298 : const isNodeLibraryTab = item.id === 'node-library'
180 298 : const isModelLibraryTab = item.id === 'model-library'
181 298 : const isWorkflowsTab = item.id === 'workflows'
182 298 : const isAssetsTab = item.id === 'assets'
183 :
184 298 : if (isNodeLibraryTab)
185 77 : telemetry?.trackUiButtonClicked({
186 : button_id: 'sidebar_tab_node_library_selected',
187 : element_group: 'sidebar'
188 : })
189 221 : else if (isModelLibraryTab)
190 36 : telemetry?.trackUiButtonClicked({
191 : button_id: 'sidebar_tab_model_library_selected',
192 : element_group: 'sidebar'
193 : })
194 185 : else if (isWorkflowsTab)
195 99 : telemetry?.trackUiButtonClicked({
196 : button_id: 'sidebar_tab_workflows_selected',
197 : element_group: 'sidebar'
198 : })
199 86 : else if (isAssetsTab)
200 78 : telemetry?.trackUiButtonClicked({
201 : button_id: 'sidebar_tab_assets_media_selected',
202 : element_group: 'sidebar'
203 : })
204 :
205 298 : await commandStore.commands
206 : .find((cmd) => cmd.id === `Workspace.ToggleSidebarTab.${item.id}`)
207 : ?.function?.()
208 : }
209 :
210 2093 : const keybindingStore = useKeybindingStore()
211 2093 : const getTabTooltipSuffix = (tab: SidebarTabExtension) => {
212 12019 : const shortcut = keybindingStore
213 : .getKeybindingByCommandId(`Workspace.ToggleSidebarTab.${tab.id}`)
214 : ?.combo.toString()
215 12019 : return shortcut ? t('g.shortcutSuffix', { shortcut }) : ''
216 : }
217 :
218 2093 : const isOverflowing = ref(false)
219 2093 : const groupClasses = computed(() =>
220 : cn(
221 : 'sidebar-item-group flex shrink-0 flex-col items-center overflow-hidden',
222 : isConnected.value
223 : ? 'border border-transparent'
224 : : 'pointer-events-auto floating-panel p-0'
225 : )
226 : )
227 :
228 2355 : const CANVAS_GUTTER_VAR = '--comfy-canvas-gutter'
229 :
230 : /**
231 : * The canvas gutter in pixels. Custom properties come back from
232 : * `getComputedStyle` unresolved, so the token is measured through a length
233 : * property the browser does resolve.
234 : */
235 2095 : function canvasGutter(): number {
236 2095 : const probe = document.createElement('div')
237 2095 : probe.style.position = 'absolute'
238 2095 : probe.style.visibility = 'hidden'
239 2095 : probe.style.marginLeft = `var(${CANVAS_GUTTER_VAR})`
240 2095 : document.body.append(probe)
241 2095 : const px = parseFloat(getComputedStyle(probe).marginLeft)
242 2095 : probe.remove()
243 2095 : return Number.isFinite(px) ? px : 0
244 : }
245 :
246 2355 : const ENTER_OVERFLOW_MARGIN = 20
247 2355 : const EXIT_OVERFLOW_MARGIN = 50
248 :
249 2093 : const checkOverflow = debounce(() => {
250 2140 : if (!sideToolbarRef.value || !topToolbarRef.value || !bottomToolbarRef.value)
251 1 : return
252 :
253 2139 : const containerHeight = sideToolbarRef.value.clientHeight
254 : const topHeight = topToolbarRef.value.scrollHeight
255 : const bottomHeight = bottomToolbarRef.value.scrollHeight
256 : const contentHeight = topHeight + bottomHeight
257 :
258 2140 : if (isOverflowing.value) {
259 6 : isOverflowing.value = containerHeight < contentHeight + EXIT_OVERFLOW_MARGIN
260 : } else {
261 2133 : isOverflowing.value =
262 : containerHeight < contentHeight + ENTER_OVERFLOW_MARGIN
263 : }
264 : }, 16)
265 :
266 2093 : onMounted(() => {
267 2093 : if (!sideToolbarRef.value) return
268 :
269 2093 : const overflowObserver = useResizeObserver(
270 : sideToolbarRef.value,
271 : checkOverflow
272 : )
273 :
274 2093 : checkOverflow()
275 2093 : watch(showProfileButton, checkOverflow)
276 :
277 2093 : onBeforeUnmount(() => {
278 157 : overflowObserver.stop()
279 : })
280 :
281 2093 : watch(
282 : [isSmall, sidebarLocation],
283 : async () => {
284 2104 : if (canvasStore.canvas) {
285 2104 : if (sidebarLocation.value === 'left') {
286 2095 : await nextTick()
287 2095 : const sidebarRight =
288 : sideToolbarRef.value?.getBoundingClientRect()?.right
289 2095 : canvasStore.canvas.fpsInfoLocation = [
290 : sidebarRight === undefined
291 : ? undefined
292 : : sidebarRight + canvasGutter(),
293 : null
294 : ]
295 : } else {
296 9 : canvasStore.canvas.fpsInfoLocation = null
297 : }
298 2104 : canvasStore.canvas.setDirty(false, true)
299 : }
300 : },
301 : { immediate: true }
302 : )
303 : })
304 : </script>
305 :
306 : <style>
307 : :root {
308 : --sidebar-padding: 4px;
309 : --sidebar-icon-size: 1rem;
310 :
311 : --sidebar-default-floating-width: 48px;
312 : --sidebar-default-connected-width: calc(
313 : var(--sidebar-default-floating-width) + var(--sidebar-padding) * 2
314 : );
315 : --sidebar-default-item-height: 56px;
316 :
317 : --sidebar-small-floating-width: 48px;
318 : --sidebar-small-connected-width: calc(
319 : var(--sidebar-small-floating-width) + var(--sidebar-padding) * 2
320 : );
321 : --sidebar-small-item-height: 48px;
322 :
323 : --sidebar-width: var(--sidebar-default-floating-width);
324 : --sidebar-item-height: var(--sidebar-default-item-height);
325 : }
326 :
327 : .side-tool-bar-container.small-sidebar {
328 : --sidebar-width: var(--sidebar-small-floating-width);
329 : --sidebar-item-height: var(--sidebar-small-item-height);
330 : }
331 :
332 : .side-tool-bar-container.connected-sidebar {
333 : --sidebar-width: var(--sidebar-default-connected-width);
334 : }
335 :
336 : .side-tool-bar-container.small-sidebar.connected-sidebar {
337 : --sidebar-width: var(--sidebar-small-connected-width);
338 : }
339 : </style>
340 :
341 : <style scoped>
342 : .connected-sidebar {
343 : padding: var(--sidebar-padding) 0;
344 : background-color: var(--background);
345 : }
346 : </style>
|