Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
413 lines (366 loc) · 13.3 KB

File metadata and controls

413 lines (366 loc) · 13.3 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
import React, { useState, useRef, useEffect } from 'react';
import { motion, AnimatePresence, Reorder } from 'framer-motion';
import { X, Plus, MessageSquare, Bot, AlertCircle, Loader2, Folder, BarChart, Server, Settings, FileText } from 'lucide-react';
import { useTabState } from '@/hooks/useTabState';
import { Tab, useTabContext } from '@/contexts/TabContext';
import { cn } from '@/lib/utils';
import { useTrackEvent } from '@/hooks';
import { useTranslation } from 'react-i18next';
interface TabItemProps {
tab: Tab;
isActive: boolean;
onClose: (id: string) => void;
onClick: (id: string) => void;
isDragging?: boolean;
setDraggedTabId?: (id: string | null) => void;
}
const TabItem: React.FC<TabItemProps> = ({ tab, isActive, onClose, onClick, isDragging = false, setDraggedTabId }) => {
const { t } = useTranslation();
const [isHovered, setIsHovered] = useState(false);
const getIcon = () => {
switch (tab.type) {
case 'chat':
return MessageSquare;
case 'agent':
case 'agents':
return Bot;
case 'projects':
return Folder;
case 'usage':
return BarChart;
case 'mcp':
return Server;
case 'settings':
return Settings;
case 'claude-md':
case 'claude-file':
return FileText;
case 'agent-execution':
case 'create-agent':
case 'import-agent':
return Bot;
default:
return MessageSquare;
}
};
const getStatusIcon = () => {
switch (tab.status) {
case 'running':
return <Loader2 className="w-3 h-3 animate-spin" />;
case 'error':
return <AlertCircle className="w-3 h-3 text-red-500" />;
default:
return null;
}
};
const Icon = getIcon();
const statusIcon = getStatusIcon();
return (
<Reorder.Item
value={tab}
id={tab.id}
dragListener={true}
transition={{ duration: 0.1 }} // Snappy reorder animation
className={cn(
"relative flex items-center gap-2 text-sm cursor-pointer select-none group",
"transition-colors duration-100 overflow-hidden border-r border-border/20",
"before:absolute before:bottom-0 before:left-0 before:right-0 before:h-0.5 before:transition-colors before:duration-100",
isActive
? "bg-card text-card-foreground before:bg-primary"
: "bg-transparent text-muted-foreground hover:bg-muted/40 hover:text-foreground before:bg-transparent",
isDragging && "bg-card border-primary/50 shadow-sm z-50",
"min-w-[120px] max-w-[220px] h-8 px-3"
)}
onMouseEnter={() => setIsHovered(true)}
onMouseLeave={() => setIsHovered(false)}
onClick={() => onClick(tab.id)}
onDragStart={() => setDraggedTabId?.(tab.id)}
onDragEnd={() => setDraggedTabId?.(null)}
>
{/* Tab Icon */}
<div className="flex-shrink-0">
<Icon className="w-4 h-4" />
</div>
{/* Tab Title */}
<span className="flex-1 truncate text-xs font-medium min-w-0">
{tab.title}
</span>
{/* Status Indicators - always takes up space */}
<div className="flex items-center gap-1.5 flex-shrink-0 w-6 justify-end">
{statusIcon && (
<span className="flex items-center justify-center">
{statusIcon}
</span>
)}
{tab.hasUnsavedChanges && !statusIcon && (
<span
className="w-1.5 h-1.5 bg-primary rounded-full"
title={t('tabManager.unsavedChanges')}
/>
)}
</div>
{/* Close Button - Always reserves space */}
<button
onClick={(e) => {
e.stopPropagation();
onClose(tab.id);
}}
className={cn(
"flex-shrink-0 w-4 h-4 flex items-center justify-center rounded-sm",
"transition-all duration-100 hover:bg-destructive/20 hover:text-destructive",
"focus:outline-none focus:ring-1 focus:ring-destructive/50",
(isHovered || isActive) ? "opacity-100" : "opacity-0"
)}
title={t('tabManager.closeTab', { title: tab.title })}
tabIndex={-1}
>
<X className="w-3 h-3" />
</button>
</Reorder.Item>
);
};
interface TabManagerProps {
className?: string;
}
export const TabManager: React.FC<TabManagerProps> = ({ className }) => {
const { t } = useTranslation();
const {
tabs,
activeTabId,
createChatTab,
createProjectsTab,
closeTab,
switchToTab,
canAddTab
} = useTabState();
// Access reorderTabs from context
const { reorderTabs } = useTabContext();
const scrollContainerRef = useRef<HTMLDivElement>(null);
const [showLeftScroll, setShowLeftScroll] = useState(false);
const [showRightScroll, setShowRightScroll] = useState(false);
const [draggedTabId, setDraggedTabId] = useState<string | null>(null);
// Analytics tracking
const trackEvent = useTrackEvent();
// Listen for tab switch events
useEffect(() => {
const handleSwitchToTab = (event: CustomEvent) => {
const { tabId } = event.detail;
switchToTab(tabId);
};
window.addEventListener('switch-to-tab', handleSwitchToTab as EventListener);
return () => {
window.removeEventListener('switch-to-tab', handleSwitchToTab as EventListener);
};
}, [switchToTab]);
// Listen for keyboard shortcut events
useEffect(() => {
const handleCreateTab = () => {
createProjectsTab();
trackEvent.tabCreated('projects');
};
const handleCloseTab = async () => {
if (activeTabId) {
const tab = tabs.find(t => t.id === activeTabId);
if (tab) {
trackEvent.tabClosed(tab.type);
}
await closeTab(activeTabId);
}
};
const handleNextTab = () => {
const currentIndex = tabs.findIndex(tab => tab.id === activeTabId);
const nextIndex = (currentIndex + 1) % tabs.length;
if (tabs[nextIndex]) {
switchToTab(tabs[nextIndex].id);
}
};
const handlePreviousTab = () => {
const currentIndex = tabs.findIndex(tab => tab.id === activeTabId);
const previousIndex = currentIndex === 0 ? tabs.length - 1 : currentIndex - 1;
if (tabs[previousIndex]) {
switchToTab(tabs[previousIndex].id);
}
};
const handleTabByIndex = (event: CustomEvent) => {
const { index } = event.detail;
if (tabs[index]) {
switchToTab(tabs[index].id);
}
};
window.addEventListener('create-chat-tab', handleCreateTab);
window.addEventListener('close-current-tab', handleCloseTab);
window.addEventListener('switch-to-next-tab', handleNextTab);
window.addEventListener('switch-to-previous-tab', handlePreviousTab);
window.addEventListener('switch-to-tab-by-index', handleTabByIndex as EventListener);
return () => {
window.removeEventListener('create-chat-tab', handleCreateTab);
window.removeEventListener('close-current-tab', handleCloseTab);
window.removeEventListener('switch-to-next-tab', handleNextTab);
window.removeEventListener('switch-to-previous-tab', handlePreviousTab);
window.removeEventListener('switch-to-tab-by-index', handleTabByIndex as EventListener);
};
}, [tabs, activeTabId, createChatTab, closeTab, switchToTab]);
// Check scroll buttons visibility
const checkScrollButtons = () => {
const container = scrollContainerRef.current;
if (!container) return;
const { scrollLeft, scrollWidth, clientWidth } = container;
setShowLeftScroll(scrollLeft > 0);
setShowRightScroll(scrollLeft + clientWidth < scrollWidth - 1);
};
useEffect(() => {
checkScrollButtons();
const container = scrollContainerRef.current;
if (!container) return;
container.addEventListener('scroll', checkScrollButtons);
window.addEventListener('resize', checkScrollButtons);
return () => {
container.removeEventListener('scroll', checkScrollButtons);
window.removeEventListener('resize', checkScrollButtons);
};
}, [tabs]);
const handleReorder = (newOrder: Tab[]) => {
// Find the positions that changed
const oldOrder = tabs.map(tab => tab.id);
const newOrderIds = newOrder.map(tab => tab.id);
// Find what moved
const movedTabId = newOrderIds.find((id, index) => oldOrder[index] !== id);
if (!movedTabId) return;
const oldIndex = oldOrder.indexOf(movedTabId);
const newIndex = newOrderIds.indexOf(movedTabId);
if (oldIndex !== -1 && newIndex !== -1 && oldIndex !== newIndex) {
// Use the context's reorderTabs function
reorderTabs(oldIndex, newIndex);
// Track the reorder event
trackEvent.featureUsed?.('tab_reorder', 'drag_drop', {
from_index: oldIndex,
to_index: newIndex
});
}
};
const handleCloseTab = async (id: string) => {
const tab = tabs.find(t => t.id === id);
if (tab) {
trackEvent.tabClosed(tab.type);
}
await closeTab(id);
};
const handleNewTab = () => {
if (canAddTab()) {
createProjectsTab();
trackEvent.tabCreated('projects');
}
};
const scrollTabs = (direction: 'left' | 'right') => {
const container = scrollContainerRef.current;
if (!container) return;
const scrollAmount = 200;
const newScrollLeft = direction === 'left'
? container.scrollLeft - scrollAmount
: container.scrollLeft + scrollAmount;
container.scrollTo({
left: newScrollLeft,
behavior: 'smooth'
});
};
return (
<div className={cn("flex items-stretch bg-muted/15 relative border-b border-border/50", className)}>
{/* Left fade gradient */}
{showLeftScroll && (
<div className="absolute left-0 top-0 bottom-0 w-8 bg-gradient-to-r from-muted/15 to-transparent pointer-events-none z-10" />
)}
{/* Left scroll button */}
<AnimatePresence>
{showLeftScroll && (
<motion.button
initial={{ opacity: 0 }}
animate={{ opacity: 1 }}
exit={{ opacity: 0 }}
onClick={() => scrollTabs('left')}
className={cn(
"p-1.5 hover:bg-muted/80 rounded-sm z-20 ml-1",
"transition-colors duration-200 flex items-center justify-center",
"bg-background/80 backdrop-blur-sm shadow-sm border border-border/50"
)}
title={t('tabManager.scrollLeft')}
>
<svg className="w-3.5 h-3.5" viewBox="0 0 24 24" fill="none" stroke="currentColor">
<path d="M15 18l-6-6 6-6" strokeWidth={2} strokeLinecap="round" strokeLinejoin="round" />
</svg>
</motion.button>
)}
</AnimatePresence>
{/* Tabs container */}
<div
ref={scrollContainerRef}
className="flex-1 flex overflow-x-auto scrollbar-hide"
style={{ scrollbarWidth: 'none', msOverflowStyle: 'none' }}
>
<div className="flex items-stretch h-8">
<Reorder.Group
axis="x"
values={tabs}
onReorder={handleReorder}
className="flex items-stretch"
layoutScroll={false}
>
{tabs.map((tab) => (
<TabItem
key={tab.id}
tab={tab}
isActive={tab.id === activeTabId}
onClose={handleCloseTab}
onClick={switchToTab}
isDragging={draggedTabId === tab.id}
setDraggedTabId={setDraggedTabId}
/>
))}
</Reorder.Group>
{/* New tab button - positioned right after tabs */}
<motion.button
onClick={handleNewTab}
disabled={!canAddTab()}
whileTap={canAddTab() ? { scale: 0.97 } : {}}
transition={{ duration: 0.15 }}
className={cn(
"px-2 mx-1 rounded-md flex items-center justify-center flex-shrink-0",
"bg-background/50 backdrop-blur-sm h-8",
canAddTab()
? "hover:bg-muted/60 text-muted-foreground hover:text-foreground"
: "opacity-50 cursor-not-allowed text-muted-foreground"
)}
title={canAddTab() ? t('tabManager.newProject') : t('tabManager.maximumTabs')}
>
<Plus className="w-4 h-4" />
</motion.button>
</div>
</div>
{/* Right fade gradient */}
{showRightScroll && (
<div className="absolute right-0 top-0 bottom-0 w-8 bg-gradient-to-l from-muted/15 to-transparent pointer-events-none z-10" />
)}
{/* Right scroll button */}
<AnimatePresence>
{showRightScroll && (
<motion.button
initial={{ opacity: 0 }}
animate={{ opacity: 1 }}
exit={{ opacity: 0 }}
onClick={() => scrollTabs('right')}
className={cn(
"p-1.5 hover:bg-muted/80 rounded-sm z-20 mr-1",
"transition-colors duration-200 flex items-center justify-center",
"bg-background/80 backdrop-blur-sm shadow-sm border border-border/50"
)}
title={t('tabManager.scrollRight')}
>
<svg className="w-3.5 h-3.5" viewBox="0 0 24 24" fill="none" stroke="currentColor">
<path d="M9 18l6-6-6-6" strokeWidth={2} strokeLinecap="round" strokeLinejoin="round" />
</svg>
</motion.button>
)}
</AnimatePresence>
</div>
);
};
export default TabManager;
Morty Proxy This is a proxified and sanitized view of the page, visit original site.