Line data Source code
1 : <template>
2 2880 : <div
3 : class="pointer-events-none absolute top-0 left-0 isolate flex size-full flex-col"
4 : >
5 : <slot name="workflow-tabs" />
6 :
7 : <div class="pointer-events-none flex min-h-0 flex-1">
8 : <div
9 : :class="
10 : cn(
11 : 'pointer-events-none flex min-w-0 flex-1 overflow-hidden',
12 : sidebarLocation === 'left' ? 'flex-row' : 'flex-row-reverse'
13 : )
14 : "
15 : >
16 : <div class="side-toolbar-container">
17 : <slot name="side-toolbar" />
18 : </div>
19 :
20 : <div
21 : ref="mainSplitterRef"
22 : class="pointer-events-none min-w-0 flex-1 overflow-hidden"
23 : >
24 : <SplitterGroup
25 : class="pointer-events-none border-none bg-transparent"
26 : @keydown.capture="onResizeStart"
27 : @keyup="onResizeEnd"
28 : @focusout="onResizeEnd"
29 : @layout="saveMainSplitterLayout"
30 : >
31 : <SplitterPanel
32 : v-if="firstPanelMounted"
33 : v-show="firstPanelRendered"
34 : id="first-side-panel"
35 : :key="isSelectMode ? mainSplitterStateKey : 'first-side-panel'"
36 : :ref="panelRefs.first"
37 : :order="1"
38 : :class="
39 : sidebarLocation === 'left'
40 : ? 'side-bar-panel pointer-events-auto bg-background focus-visible:outline-hidden'
41 : : 'pointer-events-auto bg-background focus-visible:outline-hidden'
42 : "
43 : :min-size="
44 : sidebarLocation === 'left'
45 : ? sidebarMinSize
46 : : isSelectMode
47 : ? BUILDER_MIN_SIZE
48 : : propertiesMinSize
49 : "
50 : :default-size="firstPanelDefaultSize"
51 : :role="sidebarLocation === 'left' ? 'complementary' : undefined"
52 : :aria-label="
53 : sidebarLocation === 'left'
54 : ? t('sideToolbar.sidebar')
55 : : undefined
56 : "
57 : >
58 : <slot
59 : v-if="sidebarLocation === 'left' && sidebarPanelVisible"
60 : name="side-bar-panel"
61 : />
62 : <slot
63 : v-else-if="sidebarLocation === 'right'"
64 : name="right-side-panel"
65 : />
66 : </SplitterPanel>
67 : <SplitterResizeHandle
68 : v-if="firstPanelMounted"
69 : :disabled="!firstPanelRendered"
70 : :tabindex="firstPanelRendered ? 0 : -1"
71 : :class="
72 : cn(
73 : 'pointer-events-auto',
74 : !firstPanelRendered && 'hidden',
75 : sidebarLocation === 'left' && 'bg-border/50'
76 : )
77 : "
78 : @dragging="onResizeDragging($event, 'first-side-panel')"
79 : />
80 :
81 : <SplitterPanel
82 : id="main-panel"
83 : :order="2"
84 : :min-size="isSelectMode ? 0 : centerMinSize"
85 : :default-size="centerPanelDefaultSize"
86 : class="flex flex-col"
87 : >
88 : <div
89 : :class="!graphMeetsAgentPanel && 'mr-(--comfy-canvas-gutter)'"
90 : >
91 : <slot name="topmenu" :sidebar-panel-visible />
92 : </div>
93 :
94 : <SplitterGroup
95 : data-testid="graph-canvas-gutter"
96 : :class="
97 : cn(
98 : 'pointer-events-none mb-(--comfy-canvas-gutter) ml-(--comfy-canvas-gutter) h-auto flex-1 border-none bg-transparent',
99 : !graphMeetsAgentPanel && 'mr-(--comfy-canvas-gutter)'
100 : )
101 : "
102 : direction="vertical"
103 : style="width: auto"
104 : @layout="saveBottomPanelLayout"
105 : >
106 : <SplitterPanel
107 : id="graph-canvas-panel"
108 : :order="1"
109 : :default-size="bottomPanelDefaultSizes[0]"
110 : class="graph-canvas-panel relative overflow-visible [anchor-name:--graph-canvas-panel]"
111 : >
112 : <slot name="graph-canvas-panel" />
113 : </SplitterPanel>
114 : <SplitterResizeHandle
115 : :disabled="!bottomPanelRendered"
116 : :tabindex="bottomPanelRendered ? 0 : -1"
117 : :class="
118 : cn(
119 : 'pointer-events-auto translate-y-1 rounded-t-lg',
120 : !bottomPanelRendered && 'hidden'
121 : )
122 : "
123 : @dragging="!$event && flushLayouts()"
124 : />
125 : <SplitterPanel
126 : v-show="bottomPanelRendered"
127 : id="bottom-panel"
128 : :order="2"
129 : :default-size="bottomPanelDefaultSizes[1]"
130 : class="bottom-panel pointer-events-auto max-w-full overflow-x-auto rounded-lg border bg-background focus-visible:outline-hidden"
131 : >
132 : <slot name="bottom-panel" />
133 : </SplitterPanel>
134 : </SplitterGroup>
135 : </SplitterPanel>
136 :
137 : <SplitterResizeHandle
138 : v-if="lastPanelMounted"
139 : :disabled="!lastPanelRendered"
140 : :tabindex="lastPanelRendered ? 0 : -1"
141 : :class="
142 : cn(
143 : 'pointer-events-auto',
144 : !lastPanelRendered && 'hidden',
145 : sidebarLocation === 'right' && 'bg-border/50'
146 : )
147 : "
148 : @dragging="onResizeDragging($event, 'last-side-panel')"
149 : />
150 : <SplitterPanel
151 : v-if="lastPanelMounted"
152 : v-show="lastPanelRendered"
153 : id="last-side-panel"
154 : :key="isSelectMode ? mainSplitterStateKey : 'last-side-panel'"
155 : :ref="panelRefs.last"
156 : :order="3"
157 : :class="
158 : sidebarLocation === 'right'
159 : ? 'side-bar-panel pointer-events-auto bg-background focus-visible:outline-hidden'
160 : : 'pointer-events-auto bg-background focus-visible:outline-hidden'
161 : "
162 : :min-size="
163 : sidebarLocation === 'right'
164 : ? sidebarMinSize
165 : : isSelectMode
166 : ? BUILDER_MIN_SIZE
167 : : propertiesMinSize
168 : "
169 : :default-size="lastPanelDefaultSize"
170 : :role="sidebarLocation === 'right' ? 'complementary' : undefined"
171 : :aria-label="
172 : sidebarLocation === 'right'
173 : ? t('sideToolbar.sidebar')
174 : : undefined
175 : "
176 : >
177 : <slot v-if="sidebarLocation === 'left'" name="right-side-panel" />
178 : <slot
179 : v-else-if="sidebarLocation === 'right' && sidebarPanelVisible"
180 : name="side-bar-panel"
181 : />
182 : </SplitterPanel>
183 : </SplitterGroup>
184 : </div>
185 : </div>
186 :
187 : <slot
188 : name="agent-panel"
189 : :has-opaque-neighbor="agentPanelHasOpaqueNeighbor"
190 : />
191 : </div>
192 : </div>
193 : </template>
194 :
195 : <script setup lang="ts">
196 : import { cn } from '@comfyorg/tailwind-utils'
197 : import { useElementSize } from '@vueuse/core'
198 : import { debounce } from 'es-toolkit/compat'
199 : import { storeToRefs } from 'pinia'
200 : import {
201 : computed,
202 : onBeforeUnmount,
203 : ref,
204 : shallowRef,
205 : watch,
206 : watchEffect
207 : } from 'vue'
208 : import { useI18n } from 'vue-i18n'
209 :
210 : import SplitterGroup from '@comfyorg/design-system/splitter/SplitterGroup'
211 : import SplitterPanel from '@comfyorg/design-system/splitter/SplitterPanel'
212 : import SplitterResizeHandle from '@comfyorg/design-system/splitter/SplitterResizeHandle'
213 : import { useAppMode } from '@/composables/useAppMode'
214 : import { usePanelSizing } from '@/composables/usePanelSizing'
215 : import {
216 : BUILDER_MIN_SIZE,
217 : CENTER_PANEL_MIN_WIDTH,
218 : CENTER_PANEL_SIZE,
219 : PROPERTIES_PANEL_MIN_WIDTH,
220 : SIDEBAR_MIN_SIZE,
221 : SIDEBAR_MIN_WIDTH,
222 : SIDE_PANEL_SIZE,
223 : SIDE_TOOLBAR_WIDTH
224 : } from '@/constants/splitterConstants'
225 : import { useSettingStore } from '@/platform/settings/settingStore'
226 : import { useCanvasStore } from '@/renderer/core/canvas/canvasStore'
227 : import { useBottomPanelStore } from '@/stores/workspace/bottomPanelStore'
228 : import { usePropertiesPanelStore } from '@/renderer/extensions/propertiesPanel/propertiesPanelStore'
229 : import { useSidebarTabStore } from '@/stores/workspace/sidebarTabStore'
230 : import { useWorkspaceStore } from '@/stores/workspaceStore'
231 : import {
232 : loadSplitterSizes,
233 : saveSplitterSizes
234 : } from '@/utils/splitterPersistence'
235 : import { savedPanelPercent } from '@/utils/splitterWidthUtil'
236 : import { useAgentPanelStore } from '@/workbench/extensions/agent/stores/agent/agentPanelStore'
237 :
238 2355 : const workspaceStore = useWorkspaceStore()
239 2355 : const settingStore = useSettingStore()
240 2355 : const propertiesPanelStore = usePropertiesPanelStore()
241 2355 : const sidebarTabStore = useSidebarTabStore()
242 2355 : const agentPanelStore = useAgentPanelStore()
243 2355 : const { t } = useI18n()
244 2355 : const sidebarLocation = computed<'left' | 'right'>(() =>
245 : settingStore.get('Comfy.Sidebar.Location')
246 : )
247 :
248 2355 : const unifiedWidth = computed(() =>
249 : settingStore.get('Comfy.Sidebar.UnifiedWidth')
250 : )
251 :
252 2355 : const { focusMode } = storeToRefs(workspaceStore)
253 2355 : const { isPickingNodes: agentNodeSelectionActive } =
254 : storeToRefs(useCanvasStore())
255 :
256 2355 : const { isSelectMode, isBuilderMode } = useAppMode()
257 2355 : const { activeSidebarTabId, activeSidebarTab } = storeToRefs(sidebarTabStore)
258 2355 : const { bottomPanelVisible } = storeToRefs(useBottomPanelStore())
259 2355 : const { isOpen: propertiesPanelVisible } = storeToRefs(propertiesPanelStore)
260 2355 : const { isVisible: agentPanelOpen } = storeToRefs(agentPanelStore)
261 2355 : const oppositeSidePanelVisible = computed(
262 : () => propertiesPanelVisible.value || isSelectMode.value
263 : )
264 :
265 2355 : const agentPanelHasOpaqueNeighbor = computed(
266 : () =>
267 : (sidebarLocation.value === 'right' &&
268 : sidebarPanelVisible.value &&
269 : !agentNodeSelectionActive.value &&
270 : !focusMode.value) ||
271 : (sidebarLocation.value === 'left' &&
272 : oppositeSidePanelVisible.value &&
273 : !agentNodeSelectionActive.value &&
274 : !focusMode.value)
275 : )
276 :
277 : /**
278 : * The graph's right gutter is what separates it from whatever is drawn beside
279 : * it. When that is the agent panel, the panel's own gutter already spaces the
280 : * two and a second one reads as a gap.
281 : */
282 2355 : const graphMeetsAgentPanel = computed(
283 : () => agentPanelOpen.value && !agentPanelHasOpaqueNeighbor.value
284 : )
285 :
286 2355 : const sidebarPanelVisible = computed(
287 : () => activeSidebarTab.value !== null && !isBuilderMode.value
288 : )
289 :
290 2355 : watchEffect(() => {
291 2677 : agentPanelStore.setReservedWorkspaceWidth(
292 : SIDE_TOOLBAR_WIDTH +
293 : (sidebarPanelVisible.value &&
294 : !focusMode.value &&
295 : !agentNodeSelectionActive.value
296 : ? SIDEBAR_MIN_WIDTH
297 : : 0)
298 : )
299 : })
300 :
301 2355 : const firstPanelVisible = computed(
302 : () => sidebarLocation.value === 'left' || oppositeSidePanelVisible.value
303 : )
304 2355 : const lastPanelVisible = computed(
305 : () => sidebarLocation.value === 'right' || oppositeSidePanelVisible.value
306 : )
307 2355 : const firstPanelMounted = computed(
308 : () =>
309 : firstPanelVisible.value &&
310 : (sidebarLocation.value === 'right' || sidebarPanelVisible.value)
311 : )
312 2355 : const lastPanelMounted = computed(
313 : () =>
314 : lastPanelVisible.value &&
315 : (sidebarLocation.value === 'left' || sidebarPanelVisible.value)
316 : )
317 2355 : const firstPanelRendered = computed(
318 : () =>
319 : firstPanelMounted.value &&
320 : !focusMode.value &&
321 : !agentNodeSelectionActive.value
322 : )
323 2355 : const lastPanelRendered = computed(
324 : () =>
325 : lastPanelMounted.value &&
326 : !focusMode.value &&
327 : !agentNodeSelectionActive.value
328 : )
329 2355 : const bottomPanelRendered = computed(
330 : () =>
331 : bottomPanelVisible.value &&
332 : !focusMode.value &&
333 : !agentNodeSelectionActive.value
334 : )
335 :
336 2355 : const bothSidePanelsVisible = computed(
337 : () =>
338 : !focusMode.value &&
339 : sidebarPanelVisible.value &&
340 : oppositeSidePanelVisible.value
341 : )
342 :
343 2355 : const mainSplitterRef = ref<HTMLElement | null>(null)
344 2355 : const { width: mainSplitterWidth } = useElementSize(mainSplitterRef)
345 2355 : const availableSplitterWidth = computed(() =>
346 : Math.max(
347 : 0,
348 : mainSplitterWidth.value -
349 : Number(firstPanelRendered.value) -
350 : Number(lastPanelRendered.value)
351 : )
352 : )
353 2355 : const centerMinSize = computed(() =>
354 : availableSplitterWidth.value > 0
355 : ? (CENTER_PANEL_MIN_WIDTH / availableSplitterWidth.value) * 100
356 : : 0
357 : )
358 2355 : const sidebarMinSize = computed(() =>
359 : availableSplitterWidth.value
360 : ? (SIDEBAR_MIN_WIDTH / availableSplitterWidth.value) * 100
361 : : SIDEBAR_MIN_SIZE
362 : )
363 2355 : const propertiesMinSize = computed(() =>
364 : availableSplitterWidth.value
365 : ? (PROPERTIES_PANEL_MIN_WIDTH / availableSplitterWidth.value) * 100
366 : : BUILDER_MIN_SIZE
367 : )
368 :
369 2355 : const centerPanelFallbackSize = computed(() =>
370 : bothSidePanelsVisible.value ? 100 - 2 * SIDE_PANEL_SIZE : CENTER_PANEL_SIZE
371 : )
372 :
373 2355 : const sidebarTabKey = computed(() =>
374 : unifiedWidth.value
375 : ? 'unified-sidebar'
376 : : (activeSidebarTabId.value ?? 'default-sidebar')
377 : )
378 :
379 2355 : const sidebarStateKey = computed(() => {
380 2593 : const base = sidebarTabKey.value
381 2593 : if (sidebarLocation.value === 'left' && !oppositeSidePanelVisible.value) {
382 2385 : return base
383 : }
384 2593 : const suffix = oppositeSidePanelVisible.value ? '-with-offside' : ''
385 2593 : return `${base}-${sidebarLocation.value}${suffix}`
386 : })
387 :
388 2355 : const mainSplitterStateKey = computed(() =>
389 : isSelectMode.value
390 : ? sidebarLocation.value === 'left'
391 : ? 'builder-splitter'
392 : : 'builder-splitter-right'
393 : : sidebarStateKey.value
394 : )
395 2355 : const mainPanelCount = computed(
396 : () => 1 + Number(firstPanelMounted.value) + Number(lastPanelMounted.value)
397 : )
398 2355 : const savedMainPanelSizes = shallowRef<number[]>()
399 2355 : const persistMainLayout = debounce(saveSplitterSizes, 100)
400 2355 : const persistBottomLayout = debounce(saveSplitterSizes, 100)
401 :
402 886 : function flushLayouts() {
403 886 : persistMainLayout.flush()
404 886 : persistBottomLayout.flush()
405 : }
406 :
407 2355 : onBeforeUnmount(flushLayouts)
408 2355 : watch(mainSplitterStateKey, () => persistMainLayout.flush(), { flush: 'sync' })
409 2355 : watch(
410 : [mainSplitterStateKey, mainPanelCount],
411 : ([key, count]) => {
412 2968 : savedMainPanelSizes.value = loadSplitterSizes(key, count)
413 : },
414 : { immediate: true }
415 : )
416 2355 : const sidebarWidthKey = computed(() => {
417 2361 : const base =
418 : sidebarLocation.value === 'left'
419 : ? 'Comfy.Sidebar.LeftWidth'
420 : : 'Comfy.Sidebar.RightWidth'
421 2361 : return unifiedWidth.value ? base : `${base}.${sidebarTabKey.value}`
422 : })
423 475 : function defaultPanelWidth(isSidebarPanel: boolean) {
424 475 : const plainStateKey =
425 : sidebarLocation.value === 'left'
426 : ? sidebarTabKey.value
427 : : `${sidebarTabKey.value}-right`
428 475 : const offsideStateKey = `${sidebarTabKey.value}-${sidebarLocation.value}-with-offside`
429 : const stateKeys = isSidebarPanel
430 : ? oppositeSidePanelVisible.value
431 : ? [offsideStateKey, plainStateKey]
432 : : [plainStateKey, offsideStateKey]
433 : : [offsideStateKey]
434 : const edge =
435 : (sidebarLocation.value === 'left') === isSidebarPanel ? 'first' : 'last'
436 475 : const percent =
437 : savedPanelPercent((key) => localStorage.getItem(key), stateKeys, edge) ??
438 : SIDE_PANEL_SIZE
439 475 : return Math.max(
440 : isSidebarPanel ? SIDEBAR_MIN_WIDTH : PROPERTIES_PANEL_MIN_WIDTH,
441 : Math.round((percent / 100) * (window.innerWidth - SIDE_TOOLBAR_WIDTH))
442 : )
443 : }
444 2355 : const {
445 : panelPercentages,
446 : panelRefs,
447 : onResizeStart,
448 : onResizeDragging: updatePanelResize,
449 : onResizeEnd: savePanelWidth
450 : } = usePanelSizing(
451 : [
452 : {
453 : id: 'first-side-panel',
454 : storageKey: () =>
455 : sidebarLocation.value === 'left'
456 : ? sidebarWidthKey.value
457 : : 'Comfy.RightSidePanel.Width',
458 : visible: () => firstPanelRendered.value && !isSelectMode.value,
459 : minWidth: () =>
460 : sidebarLocation.value === 'left'
461 : ? SIDEBAR_MIN_WIDTH
462 : : PROPERTIES_PANEL_MIN_WIDTH,
463 : defaultWidth: () => defaultPanelWidth(sidebarLocation.value === 'left')
464 : },
465 : {
466 : id: 'last-side-panel',
467 : storageKey: () =>
468 : sidebarLocation.value === 'right'
469 : ? sidebarWidthKey.value
470 : : 'Comfy.RightSidePanel.Width',
471 : visible: () => lastPanelRendered.value && !isSelectMode.value,
472 : minWidth: () =>
473 : sidebarLocation.value === 'right'
474 : ? SIDEBAR_MIN_WIDTH
475 : : PROPERTIES_PANEL_MIN_WIDTH,
476 : defaultWidth: () => defaultPanelWidth(sidebarLocation.value === 'right')
477 : }
478 : ],
479 : availableSplitterWidth,
480 : CENTER_PANEL_MIN_WIDTH
481 : )
482 :
483 868 : function onResizeEnd() {
484 868 : savePanelWidth()
485 868 : flushLayouts()
486 : }
487 :
488 30 : function onResizeDragging(dragging: boolean, panelId: string) {
489 30 : updatePanelResize(dragging, panelId)
490 30 : if (!dragging) flushLayouts()
491 : }
492 :
493 2355 : const firstPanelDefaultSize = computed(() =>
494 : !isSelectMode.value
495 : ? panelPercentages.value[0]
496 : : (savedMainPanelSizes.value?.[0] ??
497 : (sidebarLocation.value === 'left'
498 : ? Math.max(SIDE_PANEL_SIZE, sidebarMinSize.value)
499 : : SIDE_PANEL_SIZE))
500 : )
501 2355 : const centerPanelDefaultSize = computed(() => {
502 5591 : if (!isSelectMode.value) return panelPercentages.value[1]
503 5591 : const index = firstPanelRendered.value ? 1 : 0
504 5591 : return savedMainPanelSizes.value?.[index] ?? centerPanelFallbackSize.value
505 : })
506 2355 : const lastPanelDefaultSize = computed(() =>
507 : !isSelectMode.value
508 : ? panelPercentages.value[2]
509 : : (savedMainPanelSizes.value?.[mainPanelCount.value - 1] ??
510 : (sidebarLocation.value === 'right'
511 : ? Math.max(SIDE_PANEL_SIZE, sidebarMinSize.value)
512 : : SIDE_PANEL_SIZE))
513 : )
514 :
515 3259 : function saveMainSplitterLayout(sizes: number[]) {
516 3259 : if (!isSelectMode.value || sizes.length === 1) return
517 59 : savedMainPanelSizes.value = sizes
518 59 : persistMainLayout(mainSplitterStateKey.value, sizes)
519 : }
520 :
521 2355 : const bottomPanelStateKey = 'bottom-panel-splitter'
522 2355 : const bottomPanelDefaultSizes = shallowRef(
523 : loadSplitterSizes(bottomPanelStateKey, 2) ?? [50, 50]
524 : )
525 :
526 2400 : function saveBottomPanelLayout(sizes: number[]) {
527 2400 : bottomPanelDefaultSizes.value = sizes
528 2400 : persistBottomLayout(bottomPanelStateKey, sizes)
529 : }
530 : </script>
|