Line data Source code
1 : <script setup lang="ts">
2 : import { cn } from '@comfyorg/tailwind-utils'
3 : import {
4 : breakpointsTailwind,
5 : unrefElement,
6 : useBreakpoints,
7 : useElementSize
8 : } from '@vueuse/core'
9 : import { storeToRefs } from 'pinia'
10 : import { computed, useTemplateRef } from 'vue'
11 :
12 : import AppBuilder from '@/components/builder/AppBuilder.vue'
13 : import AppModeToolbar from '@/components/appMode/AppModeToolbar.vue'
14 : import ExtensionSlot from '@/components/common/ExtensionSlot.vue'
15 : import SideToolbar from '@/components/sidebar/SideToolbar.vue'
16 : import WorkflowTabs from '@/components/topbar/WorkflowTabs.vue'
17 : import SplitterGroup from '@comfyorg/design-system/splitter/SplitterGroup'
18 : import SplitterPanel from '@comfyorg/design-system/splitter/SplitterPanel'
19 : import SplitterResizeHandle from '@comfyorg/design-system/splitter/SplitterResizeHandle'
20 : import { usePanelSizing } from '@/composables/usePanelSizing'
21 : import { COACH_IDS } from '@/platform/onboarding/onboardingTours'
22 : import { vCoachmark } from '@/platform/onboarding/vCoachmark'
23 : import { useSettingStore } from '@/platform/settings/settingStore'
24 : import LinearControls from '@/renderer/extensions/linearMode/LinearControls.vue'
25 : import LinearPreview from '@/renderer/extensions/linearMode/LinearPreview.vue'
26 : import LinearProgressBar from '@/renderer/extensions/linearMode/LinearProgressBar.vue'
27 : import MobileDisplay from '@/renderer/extensions/linearMode/MobileDisplay.vue'
28 : import { useWorkspaceStore } from '@/stores/workspaceStore'
29 : import { useAppMode } from '@/composables/useAppMode'
30 : import {
31 : BUILDER_MIN_SIZE,
32 : SIDEBAR_MIN_SIZE,
33 : SIDEBAR_MIN_WIDTH,
34 : SIDE_PANEL_SIZE,
35 : SIDE_TOOLBAR_WIDTH
36 : } from '@/constants/splitterConstants'
37 : import { useAppModeStore } from '@/stores/appModeStore'
38 : import { useAgentDockMount } from '@/workbench/extensions/agent/composables/useAgentDockMount'
39 :
40 2355 : const settingStore = useSettingStore()
41 89 : const { docked: agentDocked, DockedAgentPanel } = useAgentDockMount()
42 89 : const workspaceStore = useWorkspaceStore()
43 89 : const { isBuilderMode, isArrangeMode } = useAppMode()
44 89 : const appModeStore = useAppModeStore()
45 89 : const { hasOutputs } = storeToRefs(appModeStore)
46 :
47 89 : const mobileDisplay = useBreakpoints(breakpointsTailwind).smaller('md')
48 :
49 89 : const activeTab = computed(() => workspaceStore.sidebarTab.activeSidebarTab)
50 89 : const assetsPanelCoach = computed(() =>
51 : activeTab.value?.id === 'assets' ? COACH_IDS.assetsPanel : undefined
52 : )
53 89 : const sidebarOnLeft = computed(
54 : () => settingStore.get('Comfy.Sidebar.Location') === 'left'
55 : )
56 89 : const showLeftBuilder = computed(
57 : () => !sidebarOnLeft.value && isArrangeMode.value
58 : )
59 89 : const showRightBuilder = computed(
60 : () => sidebarOnLeft.value && isArrangeMode.value
61 : )
62 89 : const hasLeftPanel = computed(
63 : () =>
64 : isArrangeMode.value ||
65 : (sidebarOnLeft.value && activeTab.value) ||
66 : (!sidebarOnLeft.value && !isBuilderMode.value && hasOutputs.value)
67 : )
68 89 : const hasRightPanel = computed(
69 : () =>
70 : isArrangeMode.value ||
71 : (sidebarOnLeft.value && !isBuilderMode.value && hasOutputs.value) ||
72 : (!sidebarOnLeft.value && activeTab.value)
73 : )
74 89 : const leftPanelVisible = computed(
75 : () => hasLeftPanel.value && !(showRightBuilder.value && !activeTab.value)
76 : )
77 89 : const rightPanelVisible = computed(
78 : () => hasRightPanel.value && !(showLeftBuilder.value && !activeTab.value)
79 : )
80 :
81 466 : function sidePanelMinSize(isBuilder: boolean) {
82 466 : return Math.max(
83 : isBuilder ? BUILDER_MIN_SIZE : SIDEBAR_MIN_SIZE,
84 : availableSplitterWidth.value > 0
85 : ? (SIDEBAR_MIN_WIDTH / availableSplitterWidth.value) * 100
86 : : 0
87 : )
88 : }
89 :
90 89 : const workspaceRef = useTemplateRef('workspace')
91 89 : const { width: workspaceWidth } = useElementSize(workspaceRef)
92 89 : const availableSplitterWidth = computed(() =>
93 : Math.max(
94 : 0,
95 : workspaceWidth.value -
96 : (isBuilderMode.value ? 0 : SIDE_TOOLBAR_WIDTH) -
97 : Number(leftPanelVisible.value) -
98 : Number(rightPanelVisible.value)
99 : )
100 : )
101 89 : const {
102 : panelPercentages,
103 : panelRefs,
104 : onResizeStart,
105 : onResizeDragging,
106 : onResizeEnd
107 : } = usePanelSizing(
108 : [
109 : {
110 : id: 'linear-left-panel',
111 : storageKey: 'Comfy.LinearView.LeftPanelWidth',
112 : visible: () => Boolean(leftPanelVisible.value),
113 : minWidth: SIDEBAR_MIN_WIDTH,
114 : defaultWidth: () =>
115 : Math.max(SIDEBAR_MIN_WIDTH, (window.innerWidth * SIDE_PANEL_SIZE) / 100)
116 : },
117 : {
118 : id: 'linear-right-panel',
119 : storageKey: 'Comfy.LinearView.RightPanelWidth',
120 : visible: () => Boolean(rightPanelVisible.value),
121 : minWidth: SIDEBAR_MIN_WIDTH,
122 : defaultWidth: () =>
123 : Math.max(SIDEBAR_MIN_WIDTH, (window.innerWidth * SIDE_PANEL_SIZE) / 100)
124 : }
125 : ],
126 : availableSplitterWidth,
127 : () => window.innerWidth * 0.2
128 : )
129 :
130 89 : const bottomLeftRef = useTemplateRef('bottomLeftRef')
131 89 : const bottomRightRef = useTemplateRef('bottomRightRef')
132 89 : const linearWorkflowRef = useTemplateRef('linearWorkflowRef')
133 :
134 3 : function dragDrop(e: DragEvent) {
135 3 : const { dataTransfer } = e
136 3 : if (dataTransfer) linearWorkflowRef.value?.handleDragDrop()
137 : }
138 89 : </script>
139 : <template>
140 93 : <MobileDisplay v-if="mobileDisplay" />
141 : <div v-else class="absolute flex size-full flex-col" @dragover.prevent>
142 : <div
143 : class="workflow-tabs-container pointer-events-auto h-(--workflow-tabs-height) w-full border-b border-border/50 shadow-md"
144 : >
145 : <WorkflowTabs />
146 : </div>
147 : <div class="flex min-h-0 flex-1 bg-secondary">
148 : <div
149 : ref="workspace"
150 : data-testid="linear-workspace-column"
151 : :class="
152 : cn(
153 : 'flex min-w-0 flex-1 overflow-hidden',
154 : sidebarOnLeft ? 'flex-row' : 'flex-row-reverse'
155 : )
156 : "
157 : >
158 : <SideToolbar
159 : v-if="!isBuilderMode"
160 : :visible-tab-ids="['assets', 'apps']"
161 : force-connected
162 : hide-workspace-toggles
163 : />
164 : <SplitterGroup
165 : class="h-full flex-1 border-none bg-secondary"
166 : @keydown.capture="onResizeStart"
167 : @keyup="onResizeEnd"
168 : @focusout="onResizeEnd"
169 : >
170 : <SplitterPanel
171 : v-if="leftPanelVisible"
172 : id="linear-left-panel"
173 : :ref="panelRefs.first"
174 : data-testid="linear-left-panel"
175 : :order="1"
176 : :default-size="panelPercentages[0]"
177 : :min-size="sidePanelMinSize(showLeftBuilder)"
178 : class="arrange-panel min-w-78 overflow-hidden bg-background outline-none"
179 : >
180 : <AppBuilder v-if="showLeftBuilder" />
181 : <div
182 : v-else-if="sidebarOnLeft && activeTab"
183 : v-coachmark="assetsPanelCoach"
184 : class="size-full overflow-x-hidden border-r border-border/50"
185 : >
186 : <ExtensionSlot :extension="activeTab" />
187 : </div>
188 : <LinearControls
189 : v-else-if="!isArrangeMode"
190 : ref="linearWorkflowRef"
191 : :toast-to="unrefElement(bottomLeftRef) ?? undefined"
192 : />
193 : </SplitterPanel>
194 : <SplitterResizeHandle
195 : v-if="leftPanelVisible"
196 : @dragging="onResizeDragging($event, 'linear-left-panel')"
197 : />
198 : <SplitterPanel
199 : id="linearCenterPanel"
200 : v-coachmark="COACH_IDS.outputs"
201 : :order="2"
202 : data-testid="linear-center-panel"
203 : :default-size="panelPercentages[1]"
204 : :min-size="
205 : availableSplitterWidth > 0
206 : ? ((workspaceWidth * 0.2) / availableSplitterWidth) * 100
207 : : 0
208 : "
209 : class="relative flex min-w-[20vw] flex-col gap-4 text-muted-foreground outline-none"
210 : @drop="dragDrop"
211 : >
212 : <LinearProgressBar
213 : data-testid="linear-header-progress-bar"
214 : class="absolute top-0 left-0 z-21 h-1 w-[calc(100%+16px)]"
215 : />
216 : <LinearPreview
217 : :run-button-click="linearWorkflowRef?.runButtonClick"
218 : />
219 : <div class="absolute top-2 left-2 z-21">
220 : <AppModeToolbar v-if="!isBuilderMode" />
221 : </div>
222 : <div ref="bottomLeftRef" class="absolute bottom-7 left-4 z-20" />
223 : <div ref="bottomRightRef" class="absolute right-4 bottom-7 z-20" />
224 : </SplitterPanel>
225 : <SplitterResizeHandle
226 : v-if="rightPanelVisible"
227 : @dragging="onResizeDragging($event, 'linear-right-panel')"
228 : />
229 : <SplitterPanel
230 : v-if="rightPanelVisible"
231 : id="linear-right-panel"
232 : :ref="panelRefs.last"
233 : data-testid="linear-right-panel"
234 : :order="3"
235 : :default-size="panelPercentages[2]"
236 : :min-size="sidePanelMinSize(showRightBuilder)"
237 : class="arrange-panel min-w-78 overflow-hidden bg-background outline-none"
238 : >
239 : <AppBuilder v-if="showRightBuilder" />
240 : <LinearControls
241 : v-else-if="sidebarOnLeft && !isArrangeMode"
242 : ref="linearWorkflowRef"
243 : :toast-to="unrefElement(bottomRightRef) ?? undefined"
244 : />
245 : <div
246 : v-else-if="activeTab"
247 : v-coachmark="assetsPanelCoach"
248 : class="h-full overflow-x-hidden border-l border-border/50"
249 : >
250 : <ExtensionSlot :extension="activeTab" />
251 : </div>
252 : </SplitterPanel>
253 : </SplitterGroup>
254 : </div>
255 : <!-- App mode hides the canvas, so the panel never meets bare graph. -->
256 : <component
257 : :is="DockedAgentPanel"
258 : v-if="agentDocked"
259 : :has-opaque-neighbor="true"
260 : />
261 : </div>
262 : </div>
263 : </template>
|