@myrialabs/clopen 0.1.3 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,616 +1,623 @@
1
- <script lang="ts">
2
- import { browser } from '$frontend/lib/app-environment';
3
- import { onMount, onDestroy } from 'svelte';
4
- import Icon from '$frontend/lib/components/common/Icon.svelte';
5
- import AvatarBubble from '$frontend/lib/components/common/AvatarBubble.svelte';
6
- import { sessionState } from '$frontend/lib/stores/core/sessions.svelte';
7
- import { projectState } from '$frontend/lib/stores/core/projects.svelte';
8
- import { presenceState } from '$frontend/lib/stores/core/presence.svelte';
9
- import { userStore } from '$frontend/lib/stores/features/user.svelte';
10
- import {
11
- workspaceState,
12
- type PanelId,
13
- swapPanel,
14
- splitPanel,
15
- closePanel,
16
- canClosePanel,
17
- PANEL_OPTIONS
18
- } from '$frontend/lib/stores/ui/workspace.svelte';
19
- import type { IconName } from '$shared/types/ui/icons';
20
- import type { DeviceSize } from '$frontend/lib/constants/preview';
21
-
22
- import { DEVICE_VIEWPORTS } from '$frontend/lib/constants/preview';
23
-
24
- interface Props {
25
- panelId: PanelId;
26
- chatPanelRef?: any;
27
- filesPanelRef?: any;
28
- terminalPanelRef?: any;
29
- previewPanelRef?: any;
30
- gitPanelRef?: any;
31
- onHistoryOpen?: () => void;
32
- }
33
-
34
- const {
35
- panelId,
36
- chatPanelRef,
37
- filesPanelRef,
38
- terminalPanelRef,
39
- previewPanelRef,
40
- gitPanelRef,
41
- onHistoryOpen
42
- }: Props = $props();
43
-
44
- const panel = $derived(workspaceState.panels[panelId]);
45
- const iconName = $derived((panel?.icon ?? 'lucide:box') as IconName);
46
-
47
- // Mobile detection
48
- let isMobile = $state(false);
49
-
50
- // Chat session users (other users in the same chat session, excluding self)
51
- const chatSessionUsers = $derived.by(() => {
52
- if (panelId !== 'chat') return [];
53
- const projectId = projectState.currentProject?.id;
54
- const chatSessionId = sessionState.currentSession?.id;
55
- const currentUserId = userStore.currentUser?.id;
56
- if (!projectId || !chatSessionId) return [];
57
- const status = presenceState.statuses.get(projectId);
58
- if (!status?.chatSessionUsers) return [];
59
- const users = status.chatSessionUsers[chatSessionId] || [];
60
- return currentUserId ? users.filter(u => u.userId !== currentUserId) : users;
61
- });
62
-
63
- // Chat session users popover
64
- let showChatUsersPopover = $state(false);
65
- let chatUsersContainer = $state<HTMLDivElement | null>(null);
66
-
67
- function toggleChatUsersPopover(e: MouseEvent) {
68
- e.stopPropagation();
69
- showChatUsersPopover = !showChatUsersPopover;
70
- }
71
-
72
- $effect(() => {
73
- if (showChatUsersPopover) {
74
- const handleClickOutside = (e: MouseEvent) => {
75
- if (chatUsersContainer && !chatUsersContainer.contains(e.target as Node)) {
76
- showChatUsersPopover = false;
77
- }
78
- };
79
- document.addEventListener('click', handleClickOutside, true);
80
- return () => document.removeEventListener('click', handleClickOutside, true);
81
- }
82
- });
83
-
84
- // Panel actions menu state
85
- let showActionsMenu = $state(false);
86
-
87
- function toggleActionsMenu(e: MouseEvent) {
88
- e.stopPropagation();
89
- showActionsMenu = !showActionsMenu;
90
- }
91
-
92
- function closeActionsMenu() {
93
- showActionsMenu = false;
94
- }
95
-
96
- function handleSwap(newPanelId: PanelId) {
97
- swapPanel(panelId, newPanelId);
98
- closeActionsMenu();
99
- }
100
-
101
- function handleSplit(direction: 'vertical' | 'horizontal') {
102
- splitPanel(panelId, direction);
103
- closeActionsMenu();
104
- }
105
-
106
- function handleClose() {
107
- closePanel(panelId);
108
- closeActionsMenu();
109
- }
110
-
111
- // Preview panel device dropdown state
112
- let showDeviceDropdown = $state(false);
113
-
114
- // Git remote dropdown state
115
- let showRemoteDropdown = $state(false);
116
-
117
- function toggleDeviceDropdown() {
118
- showDeviceDropdown = !showDeviceDropdown;
119
- }
120
-
121
- function closeDeviceDropdown() {
122
- showDeviceDropdown = false;
123
- }
124
-
125
- function selectDevice(size: DeviceSize) {
126
- previewPanelRef?.panelActions?.setDeviceSize(size);
127
- closeDeviceDropdown();
128
- }
129
-
130
- function handleResize() {
131
- if (browser) {
132
- isMobile = window.innerWidth < 1024;
133
- }
134
- }
135
-
136
- onMount(() => {
137
- handleResize();
138
- if (browser) {
139
- window.addEventListener('resize', handleResize);
140
- }
141
- });
142
-
143
- onDestroy(() => {
144
- if (browser) {
145
- window.removeEventListener('resize', handleResize);
146
- }
147
- });
148
- </script>
149
-
150
- <header
151
- class="flex items-center justify-between shrink-0 {isMobile
152
- ? 'h-11 pb-2 px-4 bg-white/90 dark:bg-slate-900/98 border-b border-slate-200 dark:border-slate-800'
153
- : 'py-2.5 px-3.5 bg-slate-100 dark:bg-slate-800/80 border-b border-slate-200 dark:border-slate-800'}"
154
- >
155
- <div class="flex items-center text-sm font-medium text-slate-900 dark:text-slate-100">
156
- <!-- Panel layout actions (⋮ menu) -->
157
- {#if !isMobile}
158
- <div class="relative -ml-0.5 mr-2 border-slate-200 dark:border-slate-700">
159
- <button
160
- type="button"
161
- class="flex items-center justify-center w-6 h-6 bg-transparent border-none rounded-md text-slate-400 cursor-pointer transition-all duration-150 hover:bg-violet-500/10 hover:text-slate-700 dark:hover:text-slate-200"
162
- onclick={toggleActionsMenu}
163
- title="Panel actions"
164
- >
165
- <Icon name="lucide:ellipsis-vertical" class="w-3.5 h-3.5" />
166
- </button>
167
-
168
- {#if showActionsMenu}
169
- <div class="fixed inset-0 z-40" onclick={closeActionsMenu}></div>
170
- <div class="absolute top-full left-0 mt-1 z-50 bg-white dark:bg-slate-800 border border-slate-200 dark:border-slate-700 rounded-lg shadow-lg overflow-hidden min-w-44 py-1">
171
- <!-- Switch to section -->
172
- <div class="px-3 py-1.5 text-3xs font-semibold text-slate-400 dark:text-slate-500 uppercase tracking-wider">
173
- Switch to
174
- </div>
175
- {#each PANEL_OPTIONS as option}
176
- <button
177
- type="button"
178
- class="flex items-center gap-2.5 w-full px-3 py-1.5 text-left text-xs bg-transparent border-none cursor-pointer transition-all duration-150 hover:bg-violet-500/10
179
- {option.id === panelId ? 'text-violet-600 dark:text-violet-400 font-medium' : 'text-slate-700 dark:text-slate-300'}"
180
- onclick={() => handleSwap(option.id)}
181
- disabled={option.id === panelId}
182
- >
183
- <Icon name={option.icon} class="w-3.5 h-3.5" />
184
- <span class="flex-1">{option.title}</span>
185
- {#if option.id === panelId}
186
- <Icon name="lucide:check" class="w-3 h-3 text-violet-600 dark:text-violet-400" />
187
- {/if}
188
- </button>
189
- {/each}
190
-
191
- <!-- Divider -->
192
- <div class="my-1 border-t border-slate-200 dark:border-slate-700"></div>
193
-
194
- <!-- Split actions -->
195
- <button
196
- type="button"
197
- class="flex items-center gap-2.5 w-full px-3 py-1.5 text-left text-xs bg-transparent border-none cursor-pointer transition-all duration-150 hover:bg-violet-500/10 text-slate-700 dark:text-slate-300"
198
- onclick={() => handleSplit('vertical')}
199
- >
200
- <Icon name="lucide:columns-2" class="w-3.5 h-3.5" />
201
- <span>Split Right</span>
202
- </button>
203
- <button
204
- type="button"
205
- class="flex items-center gap-2.5 w-full px-3 py-1.5 text-left text-xs bg-transparent border-none cursor-pointer transition-all duration-150 hover:bg-violet-500/10 text-slate-700 dark:text-slate-300"
206
- onclick={() => handleSplit('horizontal')}
207
- >
208
- <Icon name="lucide:rows-2" class="w-3.5 h-3.5" />
209
- <span>Split Down</span>
210
- </button>
211
-
212
- <!-- Divider -->
213
- <div class="my-1 border-t border-slate-200 dark:border-slate-700"></div>
214
-
215
- <!-- Close -->
216
- <button
217
- type="button"
218
- class="flex items-center gap-2.5 w-full px-3 py-1.5 text-left text-xs bg-transparent border-none cursor-pointer transition-all duration-150 hover:bg-red-500/10 text-red-600 dark:text-red-400 disabled:opacity-40 disabled:cursor-not-allowed"
219
- onclick={handleClose}
220
- disabled={!canClosePanel()}
221
- title={!canClosePanel() ? 'Cannot close last panel' : 'Close this panel'}
222
- >
223
- <Icon name="lucide:x" class="w-3.5 h-3.5" />
224
- <span>Close Panel</span>
225
- </button>
226
- </div>
227
- {/if}
228
- </div>
229
- {/if}
230
- <Icon name={iconName} class="w-4 h-4 text-violet-600" />
231
- <span class="ml-2.5">{panel?.title ?? 'Panel'}</span>
232
- </div>
233
-
234
- <div class="flex items-center">
235
- <!-- Panel-specific actions -->
236
- <div class="flex items-center gap-1.5">
237
- {#if panelId === 'chat'}
238
- {#if chatSessionUsers.length > 0}
239
- <div class="relative" bind:this={chatUsersContainer}>
240
- <div class="flex items-center -space-x-1.5 mr-1 cursor-pointer" title="Users in this session" onclick={toggleChatUsersPopover}>
241
- {#each chatSessionUsers.slice(0, 3) as user}
242
- <AvatarBubble {user} size="sm" />
243
- {/each}
244
- {#if chatSessionUsers.length > 3}
245
- <span class="w-5 h-5 rounded-full bg-gradient-to-br from-slate-500 to-slate-600 dark:from-slate-600 dark:to-slate-700 text-white text-4xs font-bold flex items-center justify-center border-2 border-white dark:border-slate-800 z-10">
246
- +{chatSessionUsers.length - 3}
247
- </span>
248
- {/if}
249
- </div>
250
- {#if showChatUsersPopover}
251
- <div class="absolute top-full right-0 mt-2 py-2 px-1 bg-white dark:bg-slate-800 border border-slate-200 dark:border-slate-700 rounded-lg shadow-lg z-50 min-w-[160px]">
252
- <div class="px-2 pb-1.5 text-left text-xs font-semibold text-slate-500 dark:text-slate-400">
253
- In this session ({chatSessionUsers.length})
254
- </div>
255
- {#each chatSessionUsers as user}
256
- <div class="flex items-center gap-2 px-2 py-1.5 rounded-md">
257
- <AvatarBubble {user} size="sm" showName={true} />
258
- </div>
259
- {/each}
260
- </div>
261
- {/if}
262
- </div>
263
- {/if}
264
- <button
265
- type="button"
266
- class="flex items-center justify-center {isMobile ? 'w-9 h-9' : 'w-6 h-6'} bg-transparent border-none rounded-md text-slate-500 cursor-pointer transition-all duration-150 hover:bg-violet-500/10 hover:text-slate-900 dark:hover:text-slate-100"
267
- onclick={onHistoryOpen}
268
- title="Switch Session"
269
- >
270
- <Icon name="lucide:history" class={isMobile ? 'w-4.5 h-4.5' : 'w-4 h-4'} />
271
- </button>
272
- {#if sessionState.messages.length > 0}
273
- <button
274
- type="button"
275
- class="flex items-center justify-center {isMobile ? 'w-9 h-9' : 'w-6 h-6'} bg-transparent border-none rounded-md text-slate-500 cursor-pointer transition-all duration-150 hover:bg-violet-500/10 hover:text-slate-900 dark:hover:text-slate-100"
276
- onclick={() => chatPanelRef?.panelActions?.checkpoints()}
277
- title="Restore Checkpoint"
278
- >
279
- <Icon name="lucide:undo-2" class={isMobile ? 'w-4.5 h-4.5' : 'w-4 h-4'} />
280
- </button>
281
- {/if}
282
- <button
283
- type="button"
284
- class="flex items-center justify-center {isMobile ? 'w-9 h-9' : 'w-6 h-6'} bg-transparent border-none rounded-md text-slate-500 cursor-pointer transition-all duration-150 hover:bg-violet-500/10 hover:text-slate-900 dark:hover:text-slate-100"
285
- onclick={() => chatPanelRef?.panelActions?.newChat()}
286
- title="New Chat"
287
- >
288
- <Icon name="lucide:plus" class={isMobile ? 'w-4.5 h-4.5' : 'w-4 h-4'} />
289
- </button>
290
- {:else if panelId === 'files'}
291
- <!-- Hide view mode toggles when in two-column mode -->
292
- {#if !filesPanelRef?.panelActions?.isTwoColumnMode()}
293
- <div class="flex gap-1 bg-slate-100/80 dark:bg-slate-800/50 rounded-md">
294
- <button
295
- type="button"
296
- class="flex items-center justify-center {isMobile ? 'w-9 h-9' : 'w-6 h-6'} bg-transparent border-none rounded text-slate-500 cursor-pointer transition-all duration-150 hover:bg-violet-500/10 hover:text-slate-900 dark:hover:text-slate-100 disabled:opacity-40 disabled:cursor-not-allowed
297
- {filesPanelRef?.panelActions?.getViewMode() === 'tree'
298
- ? 'bg-violet-500/15 dark:bg-violet-500/25 text-violet-600'
299
- : ''}"
300
- onclick={() => filesPanelRef?.panelActions?.setViewMode('tree')}
301
- title="Tree View"
302
- >
303
- <Icon name="lucide:folder-tree" class={isMobile ? 'w-4.5 h-4.5' : 'w-4 h-4'} />
304
- </button>
305
- <button
306
- type="button"
307
- class="flex items-center justify-center {isMobile ? 'w-9 h-9' : 'w-6 h-6'} bg-transparent border-none rounded text-slate-500 cursor-pointer transition-all duration-150 hover:bg-violet-500/10 hover:text-slate-900 dark:hover:text-slate-100 disabled:opacity-40 disabled:cursor-not-allowed
308
- {filesPanelRef?.panelActions?.getViewMode() === 'viewer'
309
- ? 'bg-violet-500/15 dark:bg-violet-500/25 text-violet-600'
310
- : ''}"
311
- onclick={() => filesPanelRef?.panelActions?.setViewMode('viewer')}
312
- disabled={!filesPanelRef?.panelActions?.canShowViewer()}
313
- title="File Viewer"
314
- >
315
- <Icon name="lucide:file-code" class={isMobile ? 'w-4.5 h-4.5' : 'w-4 h-4'} />
316
- </button>
317
- </div>
318
- {/if}
319
- {:else if panelId === 'terminal'}
320
- <button
321
- type="button"
322
- class="flex items-center justify-center {isMobile ? 'w-9 h-9' : 'w-6 h-6'} bg-transparent border-none rounded-md text-slate-500 cursor-pointer transition-all duration-150 hover:bg-violet-500/10 hover:text-slate-900 dark:hover:text-slate-100"
323
- onclick={() => terminalPanelRef?.panelActions?.handleClear()}
324
- title="Clear Terminal"
325
- >
326
- <Icon name="lucide:trash-2" class={isMobile ? 'w-4.5 h-4.5' : 'w-4 h-4'} />
327
- </button>
328
- {#if !isMobile || terminalPanelRef?.panelActions?.isExecuting()}
329
- <button
330
- type="button"
331
- class="flex items-center justify-center {isMobile ? 'w-9 h-9' : 'w-6 h-6'} bg-transparent border-none rounded-md {isMobile ? 'text-red-600 dark:text-red-400' : 'text-slate-500'} cursor-pointer transition-all duration-150 hover:bg-red-500/10 hover:text-red-600 dark:hover:text-red-400 disabled:opacity-50 disabled:cursor-not-allowed"
332
- onclick={() => terminalPanelRef?.panelActions?.handleCancel()}
333
- disabled={terminalPanelRef?.panelActions?.isCancelling()}
334
- title="{isMobile ? 'Cancel Command (Ctrl+C)' : 'Send Ctrl+C Signal'}"
335
- >
336
- {#if terminalPanelRef?.panelActions?.isCancelling()}
337
- <div
338
- class="{isMobile ? 'w-4.5 h-4.5' : 'w-4 h-4'} border-2 border-red-500/20 border-t-red-600 rounded-full animate-spin"
339
- ></div>
340
- {:else}
341
- <Icon name="lucide:square" class={isMobile ? 'w-4.5 h-4.5' : 'w-4 h-4'} />
342
- {/if}
343
- </button>
344
- {/if}
345
- {:else if panelId === 'preview'}
346
- <!-- Connection status indicator -->
347
- <!-- {@const sessionInfo = previewPanelRef?.panelActions?.getSessionInfo()}
348
- {@const isStreamReady = previewPanelRef?.panelActions?.getIsStreamReady()}
349
- {@const errorMessage = previewPanelRef?.panelActions?.getErrorMessage()}
350
- {@const url = previewPanelRef?.panelActions?.getUrl()}
351
-
352
- {#if url}
353
- <div class="flex items-center gap-1.5 {isMobile ? 'px-2 h-9' : 'px-2 h-6'} rounded-md">
354
- <div class="relative">
355
- {#if !sessionInfo}
356
- <span class="w-2 h-2 rounded-full block bg-amber-400"></span>
357
- {:else if errorMessage}
358
- <span class="w-2 h-2 rounded-full block bg-red-500"></span>
359
- {:else if isStreamReady}
360
- <span class="w-2 h-2 rounded-full block bg-emerald-500"></span>
361
- <span class="absolute inset-0 w-2 h-2 bg-emerald-500 rounded-full animate-ping opacity-75"></span>
362
- {:else}
363
- <span class="w-2 h-2 rounded-full block bg-blue-400 animate-pulse"></span>
364
- {/if}
365
- </div>
366
- <span class="text-xs font-medium {
367
- !sessionInfo ? 'text-amber-600 dark:text-amber-400' :
368
- errorMessage ? 'text-red-600 dark:text-red-400' :
369
- isStreamReady ? 'text-emerald-600 dark:text-emerald-400' :
370
- 'text-blue-600 dark:text-blue-400'
371
- }">
372
- {!sessionInfo ? 'Ready' : errorMessage ? 'Offline' : isStreamReady ? 'Online' : 'Connecting'}
373
- </span>
374
- </div>
375
- {/if} -->
376
-
377
- <!-- Device size dropdown -->
378
- <div class="relative {isMobile ? '' : 'mr-1.5'}">
379
- <button
380
- type="button"
381
- class="flex items-center justify-center gap-1.5 {isMobile ? 'px-2 h-9' : 'px-1 h-6'} bg-transparent border-none rounded-md text-slate-500 cursor-pointer transition-all duration-150 hover:bg-violet-500/10 hover:text-slate-900 dark:hover:text-slate-100"
382
- onclick={toggleDeviceDropdown}
383
- title="Select device size"
384
- >
385
- {#if previewPanelRef?.panelActions?.getDeviceSize() === 'desktop'}
386
- <Icon name="lucide:monitor" class={isMobile ? 'w-4.5 h-4.5' : 'w-4 h-4'} />
387
- <span class="text-xs font-medium">Desktop</span>
388
- {:else if previewPanelRef?.panelActions?.getDeviceSize() === 'laptop'}
389
- <Icon name="lucide:laptop" class={isMobile ? 'w-4.5 h-4.5' : 'w-4 h-4'} />
390
- <span class="text-xs font-medium">Laptop</span>
391
- {:else if previewPanelRef?.panelActions?.getDeviceSize() === 'tablet'}
392
- <Icon name="lucide:tablet" class={isMobile ? 'w-4.5 h-4.5' : 'w-4 h-4'} />
393
- <span class="text-xs font-medium">Tablet</span>
394
- {:else}
395
- <Icon name="lucide:smartphone" class={isMobile ? 'w-4.5 h-4.5' : 'w-4 h-4'} />
396
- <span class="text-xs font-medium">Mobile</span>
397
- {/if}
398
- <Icon name="lucide:chevron-down" class={isMobile ? 'w-3.5 h-3.5' : 'w-3 h-3'} />
399
- </button>
400
-
401
- <!-- Dropdown menu -->
402
- {#if showDeviceDropdown}
403
- <div
404
- class="fixed inset-0 z-40"
405
- onclick={closeDeviceDropdown}
406
- ></div>
407
- <div class="absolute top-full right-0 mt-1 z-50 bg-white dark:bg-slate-800 border border-slate-200 dark:border-slate-700 rounded-lg shadow-lg overflow-hidden {isMobile ? 'min-w-44' : 'min-w-40'}">
408
- <button
409
- type="button"
410
- class="flex items-center gap-2.5 w-full px-3 {isMobile ? 'py-2.5' : 'py-2'} text-left text-sm bg-transparent border-none cursor-pointer transition-all duration-150 hover:bg-violet-500/10 {previewPanelRef?.panelActions?.getDeviceSize() === 'desktop' ? 'bg-violet-500/5 text-violet-600' : 'text-slate-700 dark:text-slate-300'}"
411
- onclick={() => selectDevice('desktop')}
412
- >
413
- <Icon name="lucide:monitor" class={isMobile ? 'w-4.5 h-4.5' : 'w-4 h-4'} />
414
- <div class="flex-1">
415
- <div class="font-medium">Desktop</div>
416
- <div class="text-xs text-slate-500 dark:text-slate-400">
417
- {DEVICE_VIEWPORTS.desktop.width}×{DEVICE_VIEWPORTS.desktop.height}
418
- </div>
419
- </div>
420
- {#if previewPanelRef?.panelActions?.getDeviceSize() === 'desktop'}
421
- <Icon name="lucide:check" class="{isMobile ? 'w-4.5 h-4.5' : 'w-4 h-4'} text-violet-600" />
422
- {/if}
423
- </button>
424
- <button
425
- type="button"
426
- class="flex items-center gap-2.5 w-full px-3 {isMobile ? 'py-2.5' : 'py-2'} text-left text-sm bg-transparent border-none cursor-pointer transition-all duration-150 hover:bg-violet-500/10 {previewPanelRef?.panelActions?.getDeviceSize() === 'laptop' ? 'bg-violet-500/5 text-violet-600' : 'text-slate-700 dark:text-slate-300'}"
427
- onclick={() => selectDevice('laptop')}
428
- >
429
- <Icon name="lucide:laptop" class={isMobile ? 'w-4.5 h-4.5' : 'w-4 h-4'} />
430
- <div class="flex-1">
431
- <div class="font-medium">Laptop</div>
432
- <div class="text-xs text-slate-500 dark:text-slate-400">
433
- {DEVICE_VIEWPORTS.laptop.width}×{DEVICE_VIEWPORTS.laptop.height}
434
- </div>
435
- </div>
436
- {#if previewPanelRef?.panelActions?.getDeviceSize() === 'laptop'}
437
- <Icon name="lucide:check" class="{isMobile ? 'w-4.5 h-4.5' : 'w-4 h-4'} text-violet-600" />
438
- {/if}
439
- </button>
440
- <button
441
- type="button"
442
- class="flex items-center gap-2.5 w-full px-3 {isMobile ? 'py-2.5' : 'py-2'} text-left text-sm bg-transparent border-none cursor-pointer transition-all duration-150 hover:bg-violet-500/10 {previewPanelRef?.panelActions?.getDeviceSize() === 'tablet' ? 'bg-violet-500/5 text-violet-600' : 'text-slate-700 dark:text-slate-300'}"
443
- onclick={() => selectDevice('tablet')}
444
- >
445
- <Icon name="lucide:tablet" class={isMobile ? 'w-4.5 h-4.5' : 'w-4 h-4'} />
446
- <div class="flex-1">
447
- <div class="font-medium">Tablet</div>
448
- <div class="text-xs text-slate-500 dark:text-slate-400">
449
- {DEVICE_VIEWPORTS.tablet.width}×{DEVICE_VIEWPORTS.tablet.height}
450
- </div>
451
- </div>
452
- {#if previewPanelRef?.panelActions?.getDeviceSize() === 'tablet'}
453
- <Icon name="lucide:check" class="{isMobile ? 'w-4.5 h-4.5' : 'w-4 h-4'} text-violet-600" />
454
- {/if}
455
- </button>
456
- <button
457
- type="button"
458
- class="flex items-center gap-2.5 w-full px-3 {isMobile ? 'py-2.5' : 'py-2'} text-left text-sm bg-transparent border-none cursor-pointer transition-all duration-150 hover:bg-violet-500/10 {previewPanelRef?.panelActions?.getDeviceSize() === 'mobile' ? 'bg-violet-500/5 text-violet-600' : 'text-slate-700 dark:text-slate-300'}"
459
- onclick={() => selectDevice('mobile')}
460
- >
461
- <Icon name="lucide:smartphone" class={isMobile ? 'w-4.5 h-4.5' : 'w-4 h-4'} />
462
- <div class="flex-1">
463
- <div class="font-medium">Mobile</div>
464
- <div class="text-xs text-slate-500 dark:text-slate-400">
465
- {DEVICE_VIEWPORTS.mobile.width}×{DEVICE_VIEWPORTS.mobile.height}
466
- </div>
467
- </div>
468
- {#if previewPanelRef?.panelActions?.getDeviceSize() === 'mobile'}
469
- <Icon name="lucide:check" class="{isMobile ? 'w-4.5 h-4.5' : 'w-4 h-4'} text-violet-600" />
470
- {/if}
471
- </button>
472
- </div>
473
- {/if}
474
- </div>
475
-
476
- <!-- Rotation toggle -->
477
- <button
478
- type="button"
479
- class="flex items-center justify-center gap-1.5 {isMobile ? 'px-2 h-9' : 'px-1 h-6'} bg-transparent border-none rounded-md text-slate-500 cursor-pointer transition-all duration-150 hover:bg-violet-500/10 hover:text-slate-900 dark:hover:text-slate-100"
480
- onclick={() => previewPanelRef?.panelActions?.toggleRotation()}
481
- title="Toggle orientation"
482
- >
483
- <Icon name="lucide:rotate-cw" class={isMobile ? 'w-4.5 h-4.5' : 'w-4 h-4'} />
484
- <span class="text-xs font-medium">
485
- {previewPanelRef?.panelActions?.getRotation() === 'portrait' ? 'Portrait' : 'Landscape'}
486
- </span>
487
- </button>
488
-
489
- <!-- Scale info badge -->
490
- <div class="flex items-center gap-1.5 {isMobile ? 'px-2.5 h-9 bg-transparent' : 'px-2 h-6 bg-slate-100/60 dark:bg-slate-800/40'} rounded-md text-xs font-medium text-slate-500">
491
- <Icon name="lucide:move-diagonal" class={isMobile ? 'w-4 h-4' : 'w-3.5 h-3.5'} />
492
- <span>{Math.round((previewPanelRef?.panelActions?.getScale() || 1) * 100)}%</span>
493
- </div>
494
- {:else if panelId === 'git'}
495
- <!-- View mode toggles (only in single-column mode, like Files panel) -->
496
- {#if !gitPanelRef?.panelActions?.isTwoColumnMode()}
497
- <div class="flex gap-1 bg-slate-100/80 dark:bg-slate-800/50 rounded-md">
498
- <button
499
- type="button"
500
- class="flex items-center justify-center {isMobile ? 'w-9 h-9' : 'w-6 h-6'} bg-transparent border-none rounded text-slate-500 cursor-pointer transition-all duration-150 hover:bg-violet-500/10 hover:text-slate-900 dark:hover:text-slate-100
501
- {gitPanelRef?.panelActions?.getViewMode() === 'list'
502
- ? 'bg-violet-500/15 dark:bg-violet-500/25 text-violet-600'
503
- : ''}"
504
- onclick={() => gitPanelRef?.panelActions?.setViewMode('list')}
505
- title="Changes List"
506
- >
507
- <Icon name="lucide:list" class={isMobile ? 'w-4.5 h-4.5' : 'w-4 h-4'} />
508
- </button>
509
- <button
510
- type="button"
511
- class="flex items-center justify-center {isMobile ? 'w-9 h-9' : 'w-6 h-6'} bg-transparent border-none rounded text-slate-500 cursor-pointer transition-all duration-150 hover:bg-violet-500/10 hover:text-slate-900 dark:hover:text-slate-100 disabled:opacity-40 disabled:cursor-not-allowed
512
- {gitPanelRef?.panelActions?.getViewMode() === 'diff'
513
- ? 'bg-violet-500/15 dark:bg-violet-500/25 text-violet-600'
514
- : ''}"
515
- onclick={() => gitPanelRef?.panelActions?.setViewMode('diff')}
516
- disabled={!gitPanelRef?.panelActions?.canShowDiff()}
517
- title="Diff Viewer"
518
- >
519
- <Icon name="lucide:file-diff" class={isMobile ? 'w-4.5 h-4.5' : 'w-4 h-4'} />
520
- </button>
521
- </div>
522
- {/if}
523
- {@const hasRemotes = gitPanelRef?.panelActions?.getHasRemotes()}
524
- {@const remoteName = gitPanelRef?.panelActions?.getSelectedRemote() || 'origin'}
525
- {@const gitRemotes = gitPanelRef?.panelActions?.getRemotes() || []}
526
-
527
- <!-- Remote selector -->
528
- {#if hasRemotes}
529
- <div class="relative">
530
- <button
531
- type="button"
532
- class="flex items-center gap-1 {isMobile ? 'h-9 px-2' : 'h-6 px-1.5'} bg-transparent border-none rounded-md text-slate-500 cursor-pointer transition-all duration-150 hover:bg-violet-500/10 hover:text-slate-900 dark:hover:text-slate-100"
533
- onclick={() => showRemoteDropdown = !showRemoteDropdown}
534
- title="Select remote"
535
- >
536
- <Icon name="lucide:globe" class={isMobile ? 'w-4 h-4' : 'w-3.5 h-3.5'} />
537
- <span class="text-xs font-medium">{remoteName}</span>
538
- {#if gitRemotes.length > 1}
539
- <Icon name="lucide:chevron-down" class="w-3 h-3" />
540
- {/if}
541
- </button>
542
-
543
- {#if showRemoteDropdown && gitRemotes.length > 1}
544
- <div class="fixed inset-0 z-40" onclick={() => showRemoteDropdown = false}></div>
545
- <div class="absolute top-full right-0 mt-1 z-50 bg-white dark:bg-slate-800 border border-slate-200 dark:border-slate-700 rounded-lg shadow-lg overflow-hidden min-w-36">
546
- {#each gitRemotes as remote (remote.name)}
547
- <button
548
- type="button"
549
- class="flex items-center gap-2 w-full px-3 py-2 text-left text-xs bg-transparent border-none cursor-pointer transition-all duration-150 hover:bg-violet-500/10
550
- {remote.name === remoteName ? 'text-violet-600 font-medium' : 'text-slate-700 dark:text-slate-300'}"
551
- onclick={() => { gitPanelRef?.panelActions?.setSelectedRemote(remote.name); showRemoteDropdown = false; }}
552
- >
553
- <Icon name="lucide:globe" class="w-3.5 h-3.5 shrink-0" />
554
- <div class="flex-1 min-w-0">
555
- <div>{remote.name}</div>
556
- <div class="text-3xs text-slate-400 truncate font-mono">{remote.fetchUrl}</div>
557
- </div>
558
- {#if remote.name === remoteName}
559
- <Icon name="lucide:check" class="w-3.5 h-3.5 text-violet-600 shrink-0" />
560
- {/if}
561
- </button>
562
- {/each}
563
- </div>
564
- {/if}
565
- </div>
566
- {:else if gitPanelRef?.panelActions?.getIsRepo()}
567
- <span class="text-xs text-slate-400 italic px-1">no remote</span>
568
- {/if}
569
-
570
- <!-- Fetch -->
571
- <button
572
- type="button"
573
- class="flex items-center justify-center gap-1 {isMobile ? 'h-9 px-2' : 'h-6 px-1.5'} bg-transparent border-none rounded-md text-slate-500 cursor-pointer transition-all duration-150 hover:bg-violet-500/10 hover:text-slate-900 dark:hover:text-slate-100 disabled:opacity-50 disabled:cursor-not-allowed"
574
- onclick={() => gitPanelRef?.panelActions?.fetch()}
575
- disabled={gitPanelRef?.panelActions?.getIsFetching() || !hasRemotes}
576
- title={hasRemotes ? `Fetch from ${remoteName}` : 'No remote configured'}
577
- >
578
- {#if gitPanelRef?.panelActions?.getIsFetching()}
579
- <div class="{isMobile ? 'w-4.5 h-4.5' : 'w-4 h-4'} border-2 border-slate-300/30 border-t-slate-500 rounded-full animate-spin"></div>
580
- {:else}
581
- <Icon name="lucide:cloud-download" class={isMobile ? 'w-4.5 h-4.5' : 'w-4 h-4'} />
582
- {/if}
583
- </button>
584
- <!-- Pull -->
585
- <button
586
- type="button"
587
- class="flex items-center justify-center gap-1 {isMobile ? 'h-9 px-2' : 'h-6 px-1.5'} bg-transparent border-none rounded-md text-slate-500 cursor-pointer transition-all duration-150 hover:bg-violet-500/10 hover:text-slate-900 dark:hover:text-slate-100 disabled:opacity-50 disabled:cursor-not-allowed"
588
- onclick={() => gitPanelRef?.panelActions?.pull()}
589
- disabled={gitPanelRef?.panelActions?.getIsPulling() || !hasRemotes}
590
- title={hasRemotes ? `Pull from ${remoteName}` : 'No remote configured'}
591
- >
592
- {#if gitPanelRef?.panelActions?.getIsPulling()}
593
- <div class="{isMobile ? 'w-4.5 h-4.5' : 'w-4 h-4'} border-2 border-slate-300/30 border-t-slate-500 rounded-full animate-spin"></div>
594
- {:else}
595
- <Icon name="lucide:arrow-down-to-line" class={isMobile ? 'w-4.5 h-4.5' : 'w-4 h-4'} />
596
- {/if}
597
- </button>
598
- <!-- Push -->
599
- <button
600
- type="button"
601
- class="flex items-center justify-center gap-1 {isMobile ? 'h-9 px-2' : 'h-6 px-1.5'} bg-transparent border-none rounded-md text-slate-500 cursor-pointer transition-all duration-150 hover:bg-violet-500/10 hover:text-slate-900 dark:hover:text-slate-100 disabled:opacity-50 disabled:cursor-not-allowed"
602
- onclick={() => gitPanelRef?.panelActions?.push()}
603
- disabled={gitPanelRef?.panelActions?.getIsPushing() || !hasRemotes}
604
- title={hasRemotes ? `Push to ${remoteName}` : 'No remote configured'}
605
- >
606
- {#if gitPanelRef?.panelActions?.getIsPushing()}
607
- <div class="{isMobile ? 'w-4.5 h-4.5' : 'w-4 h-4'} border-2 border-slate-300/30 border-t-slate-500 rounded-full animate-spin"></div>
608
- {:else}
609
- <Icon name="lucide:arrow-up-from-line" class={isMobile ? 'w-4.5 h-4.5' : 'w-4 h-4'} />
610
- {/if}
611
- </button>
612
- {/if}
613
- </div>
614
-
615
- </div>
616
- </header>
1
+ <script lang="ts">
2
+ import { browser } from '$frontend/lib/app-environment';
3
+ import { onMount, onDestroy } from 'svelte';
4
+ import Icon from '$frontend/lib/components/common/Icon.svelte';
5
+ import AvatarBubble from '$frontend/lib/components/common/AvatarBubble.svelte';
6
+ import { sessionState } from '$frontend/lib/stores/core/sessions.svelte';
7
+ import { projectState } from '$frontend/lib/stores/core/projects.svelte';
8
+ import { presenceState } from '$frontend/lib/stores/core/presence.svelte';
9
+ import { userStore } from '$frontend/lib/stores/features/user.svelte';
10
+ import {
11
+ workspaceState,
12
+ type PanelId,
13
+ swapPanel,
14
+ splitPanel,
15
+ closePanel,
16
+ canClosePanel,
17
+ PANEL_OPTIONS
18
+ } from '$frontend/lib/stores/ui/workspace.svelte';
19
+ import type { IconName } from '$shared/types/ui/icons';
20
+ import type { DeviceSize } from '$frontend/lib/constants/preview';
21
+
22
+ import { DEVICE_VIEWPORTS } from '$frontend/lib/constants/preview';
23
+
24
+ interface Props {
25
+ panelId: PanelId;
26
+ chatPanelRef?: any;
27
+ filesPanelRef?: any;
28
+ terminalPanelRef?: any;
29
+ previewPanelRef?: any;
30
+ gitPanelRef?: any;
31
+ onHistoryOpen?: () => void;
32
+ }
33
+
34
+ const {
35
+ panelId,
36
+ chatPanelRef,
37
+ filesPanelRef,
38
+ terminalPanelRef,
39
+ previewPanelRef,
40
+ gitPanelRef,
41
+ onHistoryOpen
42
+ }: Props = $props();
43
+
44
+ const panel = $derived(workspaceState.panels[panelId]);
45
+ const iconName = $derived((panel?.icon ?? 'lucide:box') as IconName);
46
+
47
+ // Mobile detection
48
+ let isMobile = $state(false);
49
+
50
+ // Chat session users (other users in the same chat session, excluding self)
51
+ const chatSessionUsers = $derived.by(() => {
52
+ if (panelId !== 'chat') return [];
53
+ const projectId = projectState.currentProject?.id;
54
+ const chatSessionId = sessionState.currentSession?.id;
55
+ const currentUserId = userStore.currentUser?.id;
56
+ if (!projectId || !chatSessionId) return [];
57
+ const status = presenceState.statuses.get(projectId);
58
+ if (!status?.chatSessionUsers) return [];
59
+ const users = status.chatSessionUsers[chatSessionId] || [];
60
+ return currentUserId ? users.filter(u => u.userId !== currentUserId) : users;
61
+ });
62
+
63
+ // Chat session users popover
64
+ let showChatUsersPopover = $state(false);
65
+ let chatUsersContainer = $state<HTMLDivElement | null>(null);
66
+
67
+ function toggleChatUsersPopover(e: MouseEvent) {
68
+ e.stopPropagation();
69
+ showChatUsersPopover = !showChatUsersPopover;
70
+ }
71
+
72
+ $effect(() => {
73
+ if (showChatUsersPopover) {
74
+ const handleClickOutside = (e: MouseEvent) => {
75
+ if (chatUsersContainer && !chatUsersContainer.contains(e.target as Node)) {
76
+ showChatUsersPopover = false;
77
+ }
78
+ };
79
+ document.addEventListener('click', handleClickOutside, true);
80
+ return () => document.removeEventListener('click', handleClickOutside, true);
81
+ }
82
+ });
83
+
84
+ // Panel actions menu state
85
+ let showActionsMenu = $state(false);
86
+ let actionsButtonRef = $state<HTMLButtonElement | null>(null);
87
+ let menuPosition = $state({ top: 0, left: 0 });
88
+
89
+ function toggleActionsMenu(e: MouseEvent) {
90
+ e.stopPropagation();
91
+ if (!showActionsMenu && actionsButtonRef) {
92
+ const rect = actionsButtonRef.getBoundingClientRect();
93
+ menuPosition = { top: rect.bottom + 4, left: rect.left };
94
+ }
95
+ showActionsMenu = !showActionsMenu;
96
+ }
97
+
98
+ function closeActionsMenu() {
99
+ showActionsMenu = false;
100
+ }
101
+
102
+ function handleSwap(newPanelId: PanelId) {
103
+ swapPanel(panelId, newPanelId);
104
+ closeActionsMenu();
105
+ }
106
+
107
+ function handleSplit(direction: 'vertical' | 'horizontal') {
108
+ splitPanel(panelId, direction);
109
+ closeActionsMenu();
110
+ }
111
+
112
+ function handleClose() {
113
+ closePanel(panelId);
114
+ closeActionsMenu();
115
+ }
116
+
117
+ // Preview panel device dropdown state
118
+ let showDeviceDropdown = $state(false);
119
+
120
+ // Git remote dropdown state
121
+ let showRemoteDropdown = $state(false);
122
+
123
+ function toggleDeviceDropdown() {
124
+ showDeviceDropdown = !showDeviceDropdown;
125
+ }
126
+
127
+ function closeDeviceDropdown() {
128
+ showDeviceDropdown = false;
129
+ }
130
+
131
+ function selectDevice(size: DeviceSize) {
132
+ previewPanelRef?.panelActions?.setDeviceSize(size);
133
+ closeDeviceDropdown();
134
+ }
135
+
136
+ function handleResize() {
137
+ if (browser) {
138
+ isMobile = window.innerWidth < 1024;
139
+ }
140
+ }
141
+
142
+ onMount(() => {
143
+ handleResize();
144
+ if (browser) {
145
+ window.addEventListener('resize', handleResize);
146
+ }
147
+ });
148
+
149
+ onDestroy(() => {
150
+ if (browser) {
151
+ window.removeEventListener('resize', handleResize);
152
+ }
153
+ });
154
+ </script>
155
+
156
+ <header
157
+ class="flex items-center justify-between shrink-0 {isMobile
158
+ ? 'h-11 pb-2 px-4 bg-white/90 dark:bg-slate-900/98 border-b border-slate-200 dark:border-slate-800'
159
+ : 'py-2.5 px-3.5 bg-slate-100 dark:bg-slate-800/80 border-b border-slate-200 dark:border-slate-800'}"
160
+ >
161
+ <div class="flex items-center text-sm font-medium text-slate-900 dark:text-slate-100">
162
+ <!-- Panel layout actions (⋮ menu) -->
163
+ {#if !isMobile}
164
+ <div class="relative -ml-0.5 mr-2 border-slate-200 dark:border-slate-700">
165
+ <button
166
+ bind:this={actionsButtonRef}
167
+ type="button"
168
+ class="flex items-center justify-center w-6 h-6 bg-transparent border-none rounded-md text-slate-400 cursor-pointer transition-all duration-150 hover:bg-violet-500/10 hover:text-slate-700 dark:hover:text-slate-200"
169
+ onclick={toggleActionsMenu}
170
+ title="Panel actions"
171
+ >
172
+ <Icon name="lucide:ellipsis-vertical" class="w-3.5 h-3.5" />
173
+ </button>
174
+
175
+ {#if showActionsMenu}
176
+ <div class="fixed inset-0 z-40" onclick={closeActionsMenu}></div>
177
+ <div class="fixed z-50 bg-white dark:bg-slate-800 border border-slate-200 dark:border-slate-700 rounded-lg shadow-lg overflow-hidden min-w-44 py-1" style="top: {menuPosition.top}px; left: {menuPosition.left}px;">
178
+ <!-- Switch to section -->
179
+ <div class="px-3 py-1.5 text-3xs font-semibold text-slate-400 dark:text-slate-500 uppercase tracking-wider">
180
+ Switch to
181
+ </div>
182
+ {#each PANEL_OPTIONS as option}
183
+ <button
184
+ type="button"
185
+ class="flex items-center gap-2.5 w-full px-3 py-1.5 text-left text-xs bg-transparent border-none cursor-pointer transition-all duration-150 hover:bg-violet-500/10
186
+ {option.id === panelId ? 'text-violet-600 dark:text-violet-400 font-medium' : 'text-slate-700 dark:text-slate-300'}"
187
+ onclick={() => handleSwap(option.id)}
188
+ disabled={option.id === panelId}
189
+ >
190
+ <Icon name={option.icon} class="w-3.5 h-3.5" />
191
+ <span class="flex-1">{option.title}</span>
192
+ {#if option.id === panelId}
193
+ <Icon name="lucide:check" class="w-3 h-3 text-violet-600 dark:text-violet-400" />
194
+ {/if}
195
+ </button>
196
+ {/each}
197
+
198
+ <!-- Divider -->
199
+ <div class="my-1 border-t border-slate-200 dark:border-slate-700"></div>
200
+
201
+ <!-- Split actions -->
202
+ <button
203
+ type="button"
204
+ class="flex items-center gap-2.5 w-full px-3 py-1.5 text-left text-xs bg-transparent border-none cursor-pointer transition-all duration-150 hover:bg-violet-500/10 text-slate-700 dark:text-slate-300"
205
+ onclick={() => handleSplit('vertical')}
206
+ >
207
+ <Icon name="lucide:columns-2" class="w-3.5 h-3.5" />
208
+ <span>Split Right</span>
209
+ </button>
210
+ <button
211
+ type="button"
212
+ class="flex items-center gap-2.5 w-full px-3 py-1.5 text-left text-xs bg-transparent border-none cursor-pointer transition-all duration-150 hover:bg-violet-500/10 text-slate-700 dark:text-slate-300"
213
+ onclick={() => handleSplit('horizontal')}
214
+ >
215
+ <Icon name="lucide:rows-2" class="w-3.5 h-3.5" />
216
+ <span>Split Down</span>
217
+ </button>
218
+
219
+ <!-- Divider -->
220
+ <div class="my-1 border-t border-slate-200 dark:border-slate-700"></div>
221
+
222
+ <!-- Close -->
223
+ <button
224
+ type="button"
225
+ class="flex items-center gap-2.5 w-full px-3 py-1.5 text-left text-xs bg-transparent border-none cursor-pointer transition-all duration-150 hover:bg-red-500/10 text-red-600 dark:text-red-400 disabled:opacity-40 disabled:cursor-not-allowed"
226
+ onclick={handleClose}
227
+ disabled={!canClosePanel()}
228
+ title={!canClosePanel() ? 'Cannot close last panel' : 'Close this panel'}
229
+ >
230
+ <Icon name="lucide:x" class="w-3.5 h-3.5" />
231
+ <span>Close Panel</span>
232
+ </button>
233
+ </div>
234
+ {/if}
235
+ </div>
236
+ {/if}
237
+ <Icon name={iconName} class="w-4 h-4 text-violet-600" />
238
+ <span class="ml-2.5">{panel?.title ?? 'Panel'}</span>
239
+ </div>
240
+
241
+ <div class="flex items-center">
242
+ <!-- Panel-specific actions -->
243
+ <div class="flex items-center gap-1.5">
244
+ {#if panelId === 'chat'}
245
+ {#if chatSessionUsers.length > 0}
246
+ <div class="relative" bind:this={chatUsersContainer}>
247
+ <div class="flex items-center -space-x-1.5 mr-1 cursor-pointer" title="Users in this session" onclick={toggleChatUsersPopover}>
248
+ {#each chatSessionUsers.slice(0, 3) as user}
249
+ <AvatarBubble {user} size="sm" />
250
+ {/each}
251
+ {#if chatSessionUsers.length > 3}
252
+ <span class="w-5 h-5 rounded-full bg-gradient-to-br from-slate-500 to-slate-600 dark:from-slate-600 dark:to-slate-700 text-white text-4xs font-bold flex items-center justify-center border-2 border-white dark:border-slate-800 z-10">
253
+ +{chatSessionUsers.length - 3}
254
+ </span>
255
+ {/if}
256
+ </div>
257
+ {#if showChatUsersPopover}
258
+ <div class="absolute top-full right-0 mt-2 py-2 px-1 bg-white dark:bg-slate-800 border border-slate-200 dark:border-slate-700 rounded-lg shadow-lg z-50 min-w-[160px]">
259
+ <div class="px-2 pb-1.5 text-left text-xs font-semibold text-slate-500 dark:text-slate-400">
260
+ In this session ({chatSessionUsers.length})
261
+ </div>
262
+ {#each chatSessionUsers as user}
263
+ <div class="flex items-center gap-2 px-2 py-1.5 rounded-md">
264
+ <AvatarBubble {user} size="sm" showName={true} />
265
+ </div>
266
+ {/each}
267
+ </div>
268
+ {/if}
269
+ </div>
270
+ {/if}
271
+ <button
272
+ type="button"
273
+ class="flex items-center justify-center {isMobile ? 'w-9 h-9' : 'w-6 h-6'} bg-transparent border-none rounded-md text-slate-500 cursor-pointer transition-all duration-150 hover:bg-violet-500/10 hover:text-slate-900 dark:hover:text-slate-100"
274
+ onclick={onHistoryOpen}
275
+ title="Switch Session"
276
+ >
277
+ <Icon name="lucide:history" class={isMobile ? 'w-4.5 h-4.5' : 'w-4 h-4'} />
278
+ </button>
279
+ {#if sessionState.messages.length > 0}
280
+ <button
281
+ type="button"
282
+ class="flex items-center justify-center {isMobile ? 'w-9 h-9' : 'w-6 h-6'} bg-transparent border-none rounded-md text-slate-500 cursor-pointer transition-all duration-150 hover:bg-violet-500/10 hover:text-slate-900 dark:hover:text-slate-100"
283
+ onclick={() => chatPanelRef?.panelActions?.checkpoints()}
284
+ title="Restore Checkpoint"
285
+ >
286
+ <Icon name="lucide:undo-2" class={isMobile ? 'w-4.5 h-4.5' : 'w-4 h-4'} />
287
+ </button>
288
+ {/if}
289
+ <button
290
+ type="button"
291
+ class="flex items-center justify-center {isMobile ? 'w-9 h-9' : 'w-6 h-6'} bg-transparent border-none rounded-md text-slate-500 cursor-pointer transition-all duration-150 hover:bg-violet-500/10 hover:text-slate-900 dark:hover:text-slate-100"
292
+ onclick={() => chatPanelRef?.panelActions?.newChat()}
293
+ title="New Chat"
294
+ >
295
+ <Icon name="lucide:plus" class={isMobile ? 'w-4.5 h-4.5' : 'w-4 h-4'} />
296
+ </button>
297
+ {:else if panelId === 'files'}
298
+ <!-- Hide view mode toggles when in two-column mode -->
299
+ {#if !filesPanelRef?.panelActions?.isTwoColumnMode()}
300
+ <div class="flex gap-1 bg-slate-100/80 dark:bg-slate-800/50 rounded-md">
301
+ <button
302
+ type="button"
303
+ class="flex items-center justify-center {isMobile ? 'w-9 h-9' : 'w-6 h-6'} bg-transparent border-none rounded text-slate-500 cursor-pointer transition-all duration-150 hover:bg-violet-500/10 hover:text-slate-900 dark:hover:text-slate-100 disabled:opacity-40 disabled:cursor-not-allowed
304
+ {filesPanelRef?.panelActions?.getViewMode() === 'tree'
305
+ ? 'bg-violet-500/15 dark:bg-violet-500/25 text-violet-600'
306
+ : ''}"
307
+ onclick={() => filesPanelRef?.panelActions?.setViewMode('tree')}
308
+ title="Tree View"
309
+ >
310
+ <Icon name="lucide:folder-tree" class={isMobile ? 'w-4.5 h-4.5' : 'w-4 h-4'} />
311
+ </button>
312
+ <button
313
+ type="button"
314
+ class="flex items-center justify-center {isMobile ? 'w-9 h-9' : 'w-6 h-6'} bg-transparent border-none rounded text-slate-500 cursor-pointer transition-all duration-150 hover:bg-violet-500/10 hover:text-slate-900 dark:hover:text-slate-100 disabled:opacity-40 disabled:cursor-not-allowed
315
+ {filesPanelRef?.panelActions?.getViewMode() === 'viewer'
316
+ ? 'bg-violet-500/15 dark:bg-violet-500/25 text-violet-600'
317
+ : ''}"
318
+ onclick={() => filesPanelRef?.panelActions?.setViewMode('viewer')}
319
+ disabled={!filesPanelRef?.panelActions?.canShowViewer()}
320
+ title="File Viewer"
321
+ >
322
+ <Icon name="lucide:file-code" class={isMobile ? 'w-4.5 h-4.5' : 'w-4 h-4'} />
323
+ </button>
324
+ </div>
325
+ {/if}
326
+ {:else if panelId === 'terminal'}
327
+ <button
328
+ type="button"
329
+ class="flex items-center justify-center {isMobile ? 'w-9 h-9' : 'w-6 h-6'} bg-transparent border-none rounded-md text-slate-500 cursor-pointer transition-all duration-150 hover:bg-violet-500/10 hover:text-slate-900 dark:hover:text-slate-100"
330
+ onclick={() => terminalPanelRef?.panelActions?.handleClear()}
331
+ title="Clear Terminal"
332
+ >
333
+ <Icon name="lucide:trash-2" class={isMobile ? 'w-4.5 h-4.5' : 'w-4 h-4'} />
334
+ </button>
335
+ {#if !isMobile || terminalPanelRef?.panelActions?.isExecuting()}
336
+ <button
337
+ type="button"
338
+ class="flex items-center justify-center {isMobile ? 'w-9 h-9' : 'w-6 h-6'} bg-transparent border-none rounded-md {isMobile ? 'text-red-600 dark:text-red-400' : 'text-slate-500'} cursor-pointer transition-all duration-150 hover:bg-red-500/10 hover:text-red-600 dark:hover:text-red-400 disabled:opacity-50 disabled:cursor-not-allowed"
339
+ onclick={() => terminalPanelRef?.panelActions?.handleCancel()}
340
+ disabled={terminalPanelRef?.panelActions?.isCancelling()}
341
+ title="{isMobile ? 'Cancel Command (Ctrl+C)' : 'Send Ctrl+C Signal'}"
342
+ >
343
+ {#if terminalPanelRef?.panelActions?.isCancelling()}
344
+ <div
345
+ class="{isMobile ? 'w-4.5 h-4.5' : 'w-4 h-4'} border-2 border-red-500/20 border-t-red-600 rounded-full animate-spin"
346
+ ></div>
347
+ {:else}
348
+ <Icon name="lucide:square" class={isMobile ? 'w-4.5 h-4.5' : 'w-4 h-4'} />
349
+ {/if}
350
+ </button>
351
+ {/if}
352
+ {:else if panelId === 'preview'}
353
+ <!-- Connection status indicator -->
354
+ <!-- {@const sessionInfo = previewPanelRef?.panelActions?.getSessionInfo()}
355
+ {@const isStreamReady = previewPanelRef?.panelActions?.getIsStreamReady()}
356
+ {@const errorMessage = previewPanelRef?.panelActions?.getErrorMessage()}
357
+ {@const url = previewPanelRef?.panelActions?.getUrl()}
358
+
359
+ {#if url}
360
+ <div class="flex items-center gap-1.5 {isMobile ? 'px-2 h-9' : 'px-2 h-6'} rounded-md">
361
+ <div class="relative">
362
+ {#if !sessionInfo}
363
+ <span class="w-2 h-2 rounded-full block bg-amber-400"></span>
364
+ {:else if errorMessage}
365
+ <span class="w-2 h-2 rounded-full block bg-red-500"></span>
366
+ {:else if isStreamReady}
367
+ <span class="w-2 h-2 rounded-full block bg-emerald-500"></span>
368
+ <span class="absolute inset-0 w-2 h-2 bg-emerald-500 rounded-full animate-ping opacity-75"></span>
369
+ {:else}
370
+ <span class="w-2 h-2 rounded-full block bg-blue-400 animate-pulse"></span>
371
+ {/if}
372
+ </div>
373
+ <span class="text-xs font-medium {
374
+ !sessionInfo ? 'text-amber-600 dark:text-amber-400' :
375
+ errorMessage ? 'text-red-600 dark:text-red-400' :
376
+ isStreamReady ? 'text-emerald-600 dark:text-emerald-400' :
377
+ 'text-blue-600 dark:text-blue-400'
378
+ }">
379
+ {!sessionInfo ? 'Ready' : errorMessage ? 'Offline' : isStreamReady ? 'Online' : 'Connecting'}
380
+ </span>
381
+ </div>
382
+ {/if} -->
383
+
384
+ <!-- Device size dropdown -->
385
+ <div class="relative {isMobile ? '' : 'mr-1.5'}">
386
+ <button
387
+ type="button"
388
+ class="flex items-center justify-center gap-1.5 {isMobile ? 'px-2 h-9' : 'px-1 h-6'} bg-transparent border-none rounded-md text-slate-500 cursor-pointer transition-all duration-150 hover:bg-violet-500/10 hover:text-slate-900 dark:hover:text-slate-100"
389
+ onclick={toggleDeviceDropdown}
390
+ title="Select device size"
391
+ >
392
+ {#if previewPanelRef?.panelActions?.getDeviceSize() === 'desktop'}
393
+ <Icon name="lucide:monitor" class={isMobile ? 'w-4.5 h-4.5' : 'w-4 h-4'} />
394
+ <span class="text-xs font-medium">Desktop</span>
395
+ {:else if previewPanelRef?.panelActions?.getDeviceSize() === 'laptop'}
396
+ <Icon name="lucide:laptop" class={isMobile ? 'w-4.5 h-4.5' : 'w-4 h-4'} />
397
+ <span class="text-xs font-medium">Laptop</span>
398
+ {:else if previewPanelRef?.panelActions?.getDeviceSize() === 'tablet'}
399
+ <Icon name="lucide:tablet" class={isMobile ? 'w-4.5 h-4.5' : 'w-4 h-4'} />
400
+ <span class="text-xs font-medium">Tablet</span>
401
+ {:else}
402
+ <Icon name="lucide:smartphone" class={isMobile ? 'w-4.5 h-4.5' : 'w-4 h-4'} />
403
+ <span class="text-xs font-medium">Mobile</span>
404
+ {/if}
405
+ <Icon name="lucide:chevron-down" class={isMobile ? 'w-3.5 h-3.5' : 'w-3 h-3'} />
406
+ </button>
407
+
408
+ <!-- Dropdown menu -->
409
+ {#if showDeviceDropdown}
410
+ <div
411
+ class="fixed inset-0 z-40"
412
+ onclick={closeDeviceDropdown}
413
+ ></div>
414
+ <div class="absolute top-full right-0 mt-1 z-50 bg-white dark:bg-slate-800 border border-slate-200 dark:border-slate-700 rounded-lg shadow-lg overflow-hidden {isMobile ? 'min-w-44' : 'min-w-40'}">
415
+ <button
416
+ type="button"
417
+ class="flex items-center gap-2.5 w-full px-3 {isMobile ? 'py-2.5' : 'py-2'} text-left text-sm bg-transparent border-none cursor-pointer transition-all duration-150 hover:bg-violet-500/10 {previewPanelRef?.panelActions?.getDeviceSize() === 'desktop' ? 'bg-violet-500/5 text-violet-600' : 'text-slate-700 dark:text-slate-300'}"
418
+ onclick={() => selectDevice('desktop')}
419
+ >
420
+ <Icon name="lucide:monitor" class={isMobile ? 'w-4.5 h-4.5' : 'w-4 h-4'} />
421
+ <div class="flex-1">
422
+ <div class="font-medium">Desktop</div>
423
+ <div class="text-xs text-slate-500 dark:text-slate-400">
424
+ {DEVICE_VIEWPORTS.desktop.width}×{DEVICE_VIEWPORTS.desktop.height}
425
+ </div>
426
+ </div>
427
+ {#if previewPanelRef?.panelActions?.getDeviceSize() === 'desktop'}
428
+ <Icon name="lucide:check" class="{isMobile ? 'w-4.5 h-4.5' : 'w-4 h-4'} text-violet-600" />
429
+ {/if}
430
+ </button>
431
+ <button
432
+ type="button"
433
+ class="flex items-center gap-2.5 w-full px-3 {isMobile ? 'py-2.5' : 'py-2'} text-left text-sm bg-transparent border-none cursor-pointer transition-all duration-150 hover:bg-violet-500/10 {previewPanelRef?.panelActions?.getDeviceSize() === 'laptop' ? 'bg-violet-500/5 text-violet-600' : 'text-slate-700 dark:text-slate-300'}"
434
+ onclick={() => selectDevice('laptop')}
435
+ >
436
+ <Icon name="lucide:laptop" class={isMobile ? 'w-4.5 h-4.5' : 'w-4 h-4'} />
437
+ <div class="flex-1">
438
+ <div class="font-medium">Laptop</div>
439
+ <div class="text-xs text-slate-500 dark:text-slate-400">
440
+ {DEVICE_VIEWPORTS.laptop.width}×{DEVICE_VIEWPORTS.laptop.height}
441
+ </div>
442
+ </div>
443
+ {#if previewPanelRef?.panelActions?.getDeviceSize() === 'laptop'}
444
+ <Icon name="lucide:check" class="{isMobile ? 'w-4.5 h-4.5' : 'w-4 h-4'} text-violet-600" />
445
+ {/if}
446
+ </button>
447
+ <button
448
+ type="button"
449
+ class="flex items-center gap-2.5 w-full px-3 {isMobile ? 'py-2.5' : 'py-2'} text-left text-sm bg-transparent border-none cursor-pointer transition-all duration-150 hover:bg-violet-500/10 {previewPanelRef?.panelActions?.getDeviceSize() === 'tablet' ? 'bg-violet-500/5 text-violet-600' : 'text-slate-700 dark:text-slate-300'}"
450
+ onclick={() => selectDevice('tablet')}
451
+ >
452
+ <Icon name="lucide:tablet" class={isMobile ? 'w-4.5 h-4.5' : 'w-4 h-4'} />
453
+ <div class="flex-1">
454
+ <div class="font-medium">Tablet</div>
455
+ <div class="text-xs text-slate-500 dark:text-slate-400">
456
+ {DEVICE_VIEWPORTS.tablet.width}×{DEVICE_VIEWPORTS.tablet.height}
457
+ </div>
458
+ </div>
459
+ {#if previewPanelRef?.panelActions?.getDeviceSize() === 'tablet'}
460
+ <Icon name="lucide:check" class="{isMobile ? 'w-4.5 h-4.5' : 'w-4 h-4'} text-violet-600" />
461
+ {/if}
462
+ </button>
463
+ <button
464
+ type="button"
465
+ class="flex items-center gap-2.5 w-full px-3 {isMobile ? 'py-2.5' : 'py-2'} text-left text-sm bg-transparent border-none cursor-pointer transition-all duration-150 hover:bg-violet-500/10 {previewPanelRef?.panelActions?.getDeviceSize() === 'mobile' ? 'bg-violet-500/5 text-violet-600' : 'text-slate-700 dark:text-slate-300'}"
466
+ onclick={() => selectDevice('mobile')}
467
+ >
468
+ <Icon name="lucide:smartphone" class={isMobile ? 'w-4.5 h-4.5' : 'w-4 h-4'} />
469
+ <div class="flex-1">
470
+ <div class="font-medium">Mobile</div>
471
+ <div class="text-xs text-slate-500 dark:text-slate-400">
472
+ {DEVICE_VIEWPORTS.mobile.width}×{DEVICE_VIEWPORTS.mobile.height}
473
+ </div>
474
+ </div>
475
+ {#if previewPanelRef?.panelActions?.getDeviceSize() === 'mobile'}
476
+ <Icon name="lucide:check" class="{isMobile ? 'w-4.5 h-4.5' : 'w-4 h-4'} text-violet-600" />
477
+ {/if}
478
+ </button>
479
+ </div>
480
+ {/if}
481
+ </div>
482
+
483
+ <!-- Rotation toggle -->
484
+ <button
485
+ type="button"
486
+ class="flex items-center justify-center gap-1.5 {isMobile ? 'px-2 h-9' : 'px-1 h-6'} bg-transparent border-none rounded-md text-slate-500 cursor-pointer transition-all duration-150 hover:bg-violet-500/10 hover:text-slate-900 dark:hover:text-slate-100"
487
+ onclick={() => previewPanelRef?.panelActions?.toggleRotation()}
488
+ title="Toggle orientation"
489
+ >
490
+ <Icon name="lucide:rotate-cw" class={isMobile ? 'w-4.5 h-4.5' : 'w-4 h-4'} />
491
+ <span class="text-xs font-medium">
492
+ {previewPanelRef?.panelActions?.getRotation() === 'portrait' ? 'Portrait' : 'Landscape'}
493
+ </span>
494
+ </button>
495
+
496
+ <!-- Scale info badge -->
497
+ <div class="flex items-center gap-1.5 {isMobile ? 'px-2.5 h-9 bg-transparent' : 'px-2 h-6 bg-slate-100/60 dark:bg-slate-800/40'} rounded-md text-xs font-medium text-slate-500">
498
+ <Icon name="lucide:move-diagonal" class={isMobile ? 'w-4 h-4' : 'w-3.5 h-3.5'} />
499
+ <span>{Math.round((previewPanelRef?.panelActions?.getScale() || 1) * 100)}%</span>
500
+ </div>
501
+ {:else if panelId === 'git'}
502
+ <!-- View mode toggles (only in single-column mode, like Files panel) -->
503
+ {#if !gitPanelRef?.panelActions?.isTwoColumnMode()}
504
+ <div class="flex gap-1 bg-slate-100/80 dark:bg-slate-800/50 rounded-md">
505
+ <button
506
+ type="button"
507
+ class="flex items-center justify-center {isMobile ? 'w-9 h-9' : 'w-6 h-6'} bg-transparent border-none rounded text-slate-500 cursor-pointer transition-all duration-150 hover:bg-violet-500/10 hover:text-slate-900 dark:hover:text-slate-100
508
+ {gitPanelRef?.panelActions?.getViewMode() === 'list'
509
+ ? 'bg-violet-500/15 dark:bg-violet-500/25 text-violet-600'
510
+ : ''}"
511
+ onclick={() => gitPanelRef?.panelActions?.setViewMode('list')}
512
+ title="Changes List"
513
+ >
514
+ <Icon name="lucide:list" class={isMobile ? 'w-4.5 h-4.5' : 'w-4 h-4'} />
515
+ </button>
516
+ <button
517
+ type="button"
518
+ class="flex items-center justify-center {isMobile ? 'w-9 h-9' : 'w-6 h-6'} bg-transparent border-none rounded text-slate-500 cursor-pointer transition-all duration-150 hover:bg-violet-500/10 hover:text-slate-900 dark:hover:text-slate-100 disabled:opacity-40 disabled:cursor-not-allowed
519
+ {gitPanelRef?.panelActions?.getViewMode() === 'diff'
520
+ ? 'bg-violet-500/15 dark:bg-violet-500/25 text-violet-600'
521
+ : ''}"
522
+ onclick={() => gitPanelRef?.panelActions?.setViewMode('diff')}
523
+ disabled={!gitPanelRef?.panelActions?.canShowDiff()}
524
+ title="Diff Viewer"
525
+ >
526
+ <Icon name="lucide:file-diff" class={isMobile ? 'w-4.5 h-4.5' : 'w-4 h-4'} />
527
+ </button>
528
+ </div>
529
+ {/if}
530
+ {@const hasRemotes = gitPanelRef?.panelActions?.getHasRemotes()}
531
+ {@const remoteName = gitPanelRef?.panelActions?.getSelectedRemote() || 'origin'}
532
+ {@const gitRemotes = gitPanelRef?.panelActions?.getRemotes() || []}
533
+
534
+ <!-- Remote selector -->
535
+ {#if hasRemotes}
536
+ <div class="relative">
537
+ <button
538
+ type="button"
539
+ class="flex items-center gap-1 {isMobile ? 'h-9 px-2' : 'h-6 px-1.5'} bg-transparent border-none rounded-md text-slate-500 cursor-pointer transition-all duration-150 hover:bg-violet-500/10 hover:text-slate-900 dark:hover:text-slate-100"
540
+ onclick={() => showRemoteDropdown = !showRemoteDropdown}
541
+ title="Select remote"
542
+ >
543
+ <Icon name="lucide:globe" class={isMobile ? 'w-4 h-4' : 'w-3.5 h-3.5'} />
544
+ <span class="text-xs font-medium">{remoteName}</span>
545
+ {#if gitRemotes.length > 1}
546
+ <Icon name="lucide:chevron-down" class="w-3 h-3" />
547
+ {/if}
548
+ </button>
549
+
550
+ {#if showRemoteDropdown && gitRemotes.length > 1}
551
+ <div class="fixed inset-0 z-40" onclick={() => showRemoteDropdown = false}></div>
552
+ <div class="absolute top-full right-0 mt-1 z-50 bg-white dark:bg-slate-800 border border-slate-200 dark:border-slate-700 rounded-lg shadow-lg overflow-hidden min-w-36">
553
+ {#each gitRemotes as remote (remote.name)}
554
+ <button
555
+ type="button"
556
+ class="flex items-center gap-2 w-full px-3 py-2 text-left text-xs bg-transparent border-none cursor-pointer transition-all duration-150 hover:bg-violet-500/10
557
+ {remote.name === remoteName ? 'text-violet-600 font-medium' : 'text-slate-700 dark:text-slate-300'}"
558
+ onclick={() => { gitPanelRef?.panelActions?.setSelectedRemote(remote.name); showRemoteDropdown = false; }}
559
+ >
560
+ <Icon name="lucide:globe" class="w-3.5 h-3.5 shrink-0" />
561
+ <div class="flex-1 min-w-0">
562
+ <div>{remote.name}</div>
563
+ <div class="text-3xs text-slate-400 truncate font-mono">{remote.fetchUrl}</div>
564
+ </div>
565
+ {#if remote.name === remoteName}
566
+ <Icon name="lucide:check" class="w-3.5 h-3.5 text-violet-600 shrink-0" />
567
+ {/if}
568
+ </button>
569
+ {/each}
570
+ </div>
571
+ {/if}
572
+ </div>
573
+ {:else if gitPanelRef?.panelActions?.getIsRepo()}
574
+ <span class="text-xs text-slate-400 italic px-1">no remote</span>
575
+ {/if}
576
+
577
+ <!-- Fetch -->
578
+ <button
579
+ type="button"
580
+ class="flex items-center justify-center gap-1 {isMobile ? 'h-9 px-2' : 'h-6 px-1.5'} bg-transparent border-none rounded-md text-slate-500 cursor-pointer transition-all duration-150 hover:bg-violet-500/10 hover:text-slate-900 dark:hover:text-slate-100 disabled:opacity-50 disabled:cursor-not-allowed"
581
+ onclick={() => gitPanelRef?.panelActions?.fetch()}
582
+ disabled={gitPanelRef?.panelActions?.getIsFetching() || !hasRemotes}
583
+ title={hasRemotes ? `Fetch from ${remoteName}` : 'No remote configured'}
584
+ >
585
+ {#if gitPanelRef?.panelActions?.getIsFetching()}
586
+ <div class="{isMobile ? 'w-4.5 h-4.5' : 'w-4 h-4'} border-2 border-slate-300/30 border-t-slate-500 rounded-full animate-spin"></div>
587
+ {:else}
588
+ <Icon name="lucide:cloud-download" class={isMobile ? 'w-4.5 h-4.5' : 'w-4 h-4'} />
589
+ {/if}
590
+ </button>
591
+ <!-- Pull -->
592
+ <button
593
+ type="button"
594
+ class="flex items-center justify-center gap-1 {isMobile ? 'h-9 px-2' : 'h-6 px-1.5'} bg-transparent border-none rounded-md text-slate-500 cursor-pointer transition-all duration-150 hover:bg-violet-500/10 hover:text-slate-900 dark:hover:text-slate-100 disabled:opacity-50 disabled:cursor-not-allowed"
595
+ onclick={() => gitPanelRef?.panelActions?.pull()}
596
+ disabled={gitPanelRef?.panelActions?.getIsPulling() || !hasRemotes}
597
+ title={hasRemotes ? `Pull from ${remoteName}` : 'No remote configured'}
598
+ >
599
+ {#if gitPanelRef?.panelActions?.getIsPulling()}
600
+ <div class="{isMobile ? 'w-4.5 h-4.5' : 'w-4 h-4'} border-2 border-slate-300/30 border-t-slate-500 rounded-full animate-spin"></div>
601
+ {:else}
602
+ <Icon name="lucide:arrow-down-to-line" class={isMobile ? 'w-4.5 h-4.5' : 'w-4 h-4'} />
603
+ {/if}
604
+ </button>
605
+ <!-- Push -->
606
+ <button
607
+ type="button"
608
+ class="flex items-center justify-center gap-1 {isMobile ? 'h-9 px-2' : 'h-6 px-1.5'} bg-transparent border-none rounded-md text-slate-500 cursor-pointer transition-all duration-150 hover:bg-violet-500/10 hover:text-slate-900 dark:hover:text-slate-100 disabled:opacity-50 disabled:cursor-not-allowed"
609
+ onclick={() => gitPanelRef?.panelActions?.push()}
610
+ disabled={gitPanelRef?.panelActions?.getIsPushing() || !hasRemotes}
611
+ title={hasRemotes ? `Push to ${remoteName}` : 'No remote configured'}
612
+ >
613
+ {#if gitPanelRef?.panelActions?.getIsPushing()}
614
+ <div class="{isMobile ? 'w-4.5 h-4.5' : 'w-4 h-4'} border-2 border-slate-300/30 border-t-slate-500 rounded-full animate-spin"></div>
615
+ {:else}
616
+ <Icon name="lucide:arrow-up-from-line" class={isMobile ? 'w-4.5 h-4.5' : 'w-4 h-4'} />
617
+ {/if}
618
+ </button>
619
+ {/if}
620
+ </div>
621
+
622
+ </div>
623
+ </header>