Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

RightPanelTabs.tsx

776 lines28.2 KB

1import type { ContextMenuItem, PreviewSessionSnapshot, PullRequestState } from "@t3tools/contracts";
2import { getTerminalLabel } from "@t3tools/shared/terminalLabels";
3import {
4 Bot,
5 FileDiff,
6 Files,
7 GitPullRequest,
8 Globe2,
9 Plus,
10 TerminalSquare,
11 X,
12} from "lucide-react";
13import {
14 type KeyboardEvent as ReactKeyboardEvent,
15 type MouseEvent as ReactMouseEvent,
16 type ReactElement,
17 type ReactNode,
18 useCallback,
19 useEffect,
20 useRef,
21 useState,
22} from "react";
23​
24import { isElectron } from "~/env";
25import type { DesktopPreviewOverlay } from "~/previewStateStore";
26import type { RightPanelSurface } from "~/rightPanelStore";
27import { cn } from "~/lib/utils";
28import { readLocalApi } from "~/localApi";
29import { Button } from "~/components/ui/button";
30import { Tooltip, TooltipPopup, TooltipTrigger } from "~/components/ui/tooltip";
31import { Kbd } from "~/components/ui/kbd";
32import { Menu, MenuItem, MenuPopup, MenuTrigger } from "~/components/ui/menu";
33import { ScrollArea } from "~/components/ui/scroll-area";
34import { faviconUrlForOrigin } from "~/lib/favicon";
35import { useTheme } from "~/hooks/useTheme";
36import { COLLAPSED_SIDEBAR_TITLEBAR_INSET_CLASS } from "~/workspaceTitlebar";
37​
38import { PreviewPanelShell, type PreviewPanelMode } from "./preview/PreviewPanelShell";
39import { FaviconImage } from "./preview/PreviewFaviconIcon";
40import { PierreEntryIcon } from "./chat/PierreEntryIcon";
41​
42interface RightPanelTabsProps {
43 mode: PreviewPanelMode;
44 maximized?: boolean;
45 /** Forwarded to PreviewPanelShell so this surface persists its own width. */
46 widthStorageKey?: string;
47 /** Forwarded to PreviewPanelShell as the initial width before a user resize. */
48 defaultWidth?: number;
49 layoutControls?: ReactNode;
50 surfaces: readonly RightPanelSurface[];
51 activeSurfaceId: string | null;
52 pendingSurfaceIds: ReadonlySet<string>;
53 previewSessions: Readonly<Record<string, PreviewSessionSnapshot>>;
54 desktopByTabId: Readonly<Record<string, DesktopPreviewOverlay>>;
55 terminalLabelsById: ReadonlyMap<string, string>;
56 onActivate: (surface: RightPanelSurface) => void;
57 onCloseSurface: (surface: RightPanelSurface) => void;
58 onCloseOtherSurfaces: (surface: RightPanelSurface) => void;
59 onCloseSurfacesToRight: (surface: RightPanelSurface) => void;
60 onCloseAllSurfaces: () => void;
61 onCopyFilePath: (relativePath: string) => void;
62 onAddBrowser: () => void;
63 onAddTerminal: () => void;
64 onAddDiff: () => void;
65 onAddFiles: () => void;
66 onAddPullRequest: () => void;
67 onAddAgents: () => void;
68 browserAvailable: boolean;
69 terminalAvailable: boolean;
70 diffAvailable: boolean;
71 filesAvailable: boolean;
72 pullRequestAvailable: boolean;
73 agentsAvailable: boolean;
74 pullRequestStatuses?: Readonly<Record<string, PullRequestTabStatus>>;
75 /** Running + waiting subagents; badges the Agents card in the empty state. */
76 liveAgentCount: number;
77 children: ReactNode;
79​
80export interface PullRequestTabStatus {
81 projectId: string;
82 repository: string;
83 number: number;
84 state: PullRequestState;
85 isDraft: boolean;
87​
88const SURFACE_DISABLED_REASONS = {
89 browser: "Browser previews are only available in the T3 Code desktop app.",
90 terminal: "Terminal surfaces are only available from a project thread.",
91 files: "Files are only available when a project is open.",
92 diff: "Diff is only available for server threads in Git repositories.",
93 pullRequest: "This thread's branch has no pull request yet.",
94 agents: "Agents are only available from a thread.",
95} as const;
96​
97/** Overlays that must win over the launcher's letter shortcuts. */
98const LAUNCHER_SHORTCUT_BLOCKING_LAYERS = [
99 '[data-slot="dialog-popup"]',
100 '[data-slot="alert-dialog-popup"]',
101 '[data-slot="command-dialog-popup"]',
102 '[data-slot="menu-popup"]',
103 '[data-slot="select-popup"]',
104 '[data-slot="popover-popup"]',
105 '[data-slot="combobox-popup"]',
106 '[data-slot="autocomplete-popup"]',
107].join(",");
108​
109/** One-line unavailability hints for the empty-state cards. */
110const SURFACE_UNAVAILABLE_HINTS = {
111 browser: "Only available in the desktop app.",
112 terminal: "Available when a project is open.",
113 files: "Available when a project is open.",
114 diff: "Available for Git repositories.",
115 pullRequest: "No pull request on this branch yet.",
116 agents: "Available from a thread.",
117} as const;
118​
119type TabContextMenuAction = "copy-path" | "close" | "close-others" | "close-to-right" | "close-all";
120​
121function DisabledReasonTooltip(props: { reason: string; trigger: ReactElement }) {
122 return (
123 <Tooltip>
124 <TooltipTrigger render={props.trigger} />
125 <TooltipPopup side="top">{props.reason}</TooltipPopup>
126 </Tooltip>
127 );
129​
130function SurfaceMenuItem(props: {
131 available: boolean;
132 disabledReason?: string;
133 onClick: () => void;
134 children: ReactNode;
135}) {
136 const item = (
137 <MenuItem
138 className={!props.available ? "data-disabled:pointer-events-auto" : undefined}
139 onClick={props.onClick}
140 disabled={!props.available}
141 >
142 {props.children}
143 </MenuItem>
144 );
145 if (props.available || !props.disabledReason) return item;
146 return <DisabledReasonTooltip reason={props.disabledReason} trigger={item} />;
148​
149/**
150 * Card launcher shown when the right panel has no surfaces. Keyboard-first
151 * without palette chrome: a surface's letter opens it directly from anywhere
152 * outside a typing context, and arrows plus Enter work while the launcher is
153 * focused. The highlight only appears on hover or arrow use. Unavailable
154 * surfaces stay visible with a one-line reason.
155 */
156function RightPanelEmptyState(props: {
157 onAddBrowser: () => void;
158 onAddTerminal: () => void;
159 onAddDiff: () => void;
160 onAddFiles: () => void;
161 onAddPullRequest: () => void;
162 onAddAgents: () => void;
163 browserAvailable: boolean;
164 terminalAvailable: boolean;
165 diffAvailable: boolean;
166 filesAvailable: boolean;
167 pullRequestAvailable: boolean;
168 agentsAvailable: boolean;
169 liveAgentCount: number;
170}) {
171 // -1 means no highlight: it only appears on hover or arrow use.
172 const [highlight, setHighlight] = useState(-1);
173​
174 const actions = [
175 {
176 label: "Browser",
177 description: "Open a local app or URL.",
178 icon: Globe2,
179 shortcut: "B",
180 available: props.browserAvailable,
181 disabledReason: SURFACE_UNAVAILABLE_HINTS.browser,
182 onClick: props.onAddBrowser,
183 badgeCount: 0,
184 },
185 {
186 label: "Terminal",
187 description: "Start a shell in this workspace.",
188 icon: TerminalSquare,
189 shortcut: "T",
190 available: props.terminalAvailable,
191 disabledReason: SURFACE_UNAVAILABLE_HINTS.terminal,
192 onClick: props.onAddTerminal,
193 badgeCount: 0,
194 },
195 {
196 label: "Files",
197 description: "Browse and read workspace files.",
198 icon: Files,
199 shortcut: "F",
200 available: props.filesAvailable,
201 disabledReason: SURFACE_UNAVAILABLE_HINTS.files,
202 onClick: props.onAddFiles,
203 badgeCount: 0,
204 },
205 {
206 label: "Diff",
207 description: "Review changes in this thread.",
208 icon: FileDiff,
209 shortcut: "D",
210 available: props.diffAvailable,
211 disabledReason: SURFACE_UNAVAILABLE_HINTS.diff,
212 onClick: props.onAddDiff,
213 badgeCount: 0,
214 },
215 {
216 label: "Pull request",
217 description: "Open this branch's pull request.",
218 icon: GitPullRequest,
219 shortcut: "P",
220 available: props.pullRequestAvailable,
221 disabledReason: SURFACE_UNAVAILABLE_HINTS.pullRequest,
222 onClick: props.onAddPullRequest,
223 badgeCount: 0,
224 },
225 {
226 label: "Agents",
227 description: "Follow subagents and workflows.",
228 icon: Bot,
229 shortcut: "A",
230 available: props.agentsAvailable,
231 disabledReason: SURFACE_UNAVAILABLE_HINTS.agents,
232 onClick: props.onAddAgents,
233 badgeCount: props.liveAgentCount,
234 },
235 ] as const;
236​
237 type SurfaceAction = (typeof actions)[number];
238​
239 const availableActions = actions.filter((action) => action.available);
240 const highlightIndex =
241 availableActions.length === 0 ? -1 : Math.min(highlight, availableActions.length - 1);
242​
243 // Letter shortcuts work while the launcher is visible, not only while it
244 // is focused; focus moves around too easily (stray clicks) to carry them.
245 // Capture phase so app-level key handlers cannot swallow the event first;
246 // typing contexts and already-handled events are left alone.
247 const shortcutActionsRef = useRef(availableActions);
248 useEffect(() => {
249 shortcutActionsRef.current = availableActions;
250 });
251 useEffect(() => {
252 const handler = (event: KeyboardEvent) => {
253 if (event.defaultPrevented || event.isComposing) return;
254 if (event.metaKey || event.ctrlKey || event.altKey) return;
255 if (document.querySelector(LAUNCHER_SHORTCUT_BLOCKING_LAYERS)) return;
256 const target = event.target;
257 if (target instanceof HTMLElement) {
258 if (target.closest("input, textarea, select")) return;
259 // An empty contenteditable (the chat composer at rest) does not
260 // count as typing; letters only become text once a draft exists.
261 const editable = target.isContentEditable ? target : target.closest("[contenteditable]");
262 if (editable && (editable.textContent ?? "").trim().length > 0) return;
263 }
264 const action = shortcutActionsRef.current.find(
265 (candidate) => candidate.shortcut.toLowerCase() === event.key.toLowerCase(),
266 );
267 if (!action) return;
268 event.preventDefault();
269 event.stopPropagation();
270 action.onClick();
271 };
272 window.addEventListener("keydown", handler, true);
273 return () => window.removeEventListener("keydown", handler, true);
274 }, []);
275​
276 const handleKeyDown = (event: ReactKeyboardEvent<HTMLDivElement>) => {
277 if (event.defaultPrevented || event.metaKey || event.ctrlKey || event.altKey) return;
278 if (availableActions.length === 0) return;
279 if (event.key === "ArrowDown" || event.key === "ArrowRight") {
280 event.preventDefault();
281 setHighlight((highlightIndex + 1) % availableActions.length);
282 return;
283 }
284 if (event.key === "ArrowUp" || event.key === "ArrowLeft") {
285 event.preventDefault();
286 setHighlight(
287 highlightIndex === -1
288 ? availableActions.length - 1
289 : (highlightIndex - 1 + availableActions.length) % availableActions.length,
290 );
291 return;
292 }
293 if (event.key === "Enter") {
294 // A focused card button owns its own activation; only open from the
295 // highlight when the container itself has focus.
296 if (event.target instanceof HTMLElement && event.target.closest("button")) return;
297 const action = availableActions[highlightIndex];
298 if (!action) return;
299 event.preventDefault();
300 action.onClick();
301 }
302 };
303​
304 // Stable identity so React only runs this callback ref on mount/unmount;
305 // an inline arrow would re-attach and re-focus on every render.
306 const focusOnMount = useCallback((node: HTMLDivElement | null) => {
307 node?.focus();
308 }, []);
309​
310 const isHighlighted = (action: SurfaceAction) =>
311 highlightIndex !== -1 && availableActions[highlightIndex] === action;
312​
313 const actionIcon = (action: SurfaceAction, iconClassName = "size-4") => {
314 const Icon = action.icon;
315 return (
316 <span className="relative inline-flex shrink-0">
317 <Icon className={iconClassName} />
318 {action.badgeCount > 0 ? (
319 <span
320 aria-hidden
321 className="absolute -top-1.5 -right-2 flex h-3.5 min-w-3.5 items-center justify-center rounded-full bg-info px-1 text-[9px] font-semibold tabular-nums text-white"
322 >
323 {action.badgeCount}
324 </span>
325 ) : null}
326 </span>
327 );
328 };
329​
330 const cardShellClass =
331 "rounded-lg border border-border/80 bg-card dark:border-transparent dark:shadow-none dark:inset-ring-1 dark:inset-ring-white/5";
332 const highlightedCardClass = "bg-accent/60 dark:inset-ring-white/20";
333​
334 return (
335 <div
336 ref={focusOnMount}
337 tabIndex={0}
338 onKeyDown={handleKeyDown}
339 aria-label="Open a surface"
340 data-surface-launcher-keys={availableActions.map((action) => action.shortcut).join("")}
341 className={cn(
342 "flex min-h-0 flex-1 items-center justify-center overflow-y-auto px-6 pt-6 outline-none",
343 // The panel topbar sits above this container; matching bottom padding
344 // keeps the cards centered against the full panel, not the leftover.
345 "pb-[calc(var(--workspace-topbar-height)+--spacing(6))]",
346 )}
347 >
348 <div className="relative w-full max-w-lg">
349 <div className="absolute inset-x-0 bottom-full mb-5 text-center">
350 <h3 className="font-medium text-foreground text-sm">Open a surface</h3>
351 <p className="mt-1 text-muted-foreground text-xs">
352 Choose what to show in the right panel.
353 </p>
354 </div>
355 <div className="grid grid-cols-2 gap-2">
356 {actions.map((action) =>
357 action.available ? (
358 <button
359 key={action.label}
360 type="button"
361 onClick={action.onClick}
362 onMouseEnter={() => setHighlight(availableActions.indexOf(action))}
363 onMouseLeave={() =>
364 setHighlight((current) =>
365 current === availableActions.indexOf(action) ? -1 : current,
366 )
367 }
368 className={cn(
369 "relative flex w-full cursor-pointer flex-col items-start p-4 text-left transition hover:border-border hover:bg-accent/60",
370 cardShellClass,
371 isHighlighted(action) && highlightedCardClass,
372 )}
373 >
374 <Kbd className="absolute top-3 right-3">{action.shortcut}</Kbd>
375 <span className="flex items-center gap-2 pe-8">
376 {actionIcon(action)}
377 <span className="font-medium text-sm">{action.label}</span>
378 </span>
379 <span className="mt-1.5 text-muted-foreground text-xs leading-relaxed">
380 {action.description}
381 </span>
382 </button>
383 ) : (
384 <div
385 key={action.label}
386 className={cn(
387 "relative flex w-full flex-col items-start p-4 opacity-40",
388 cardShellClass,
389 )}
390 >
391 <Kbd className="absolute top-3 right-3">{action.shortcut}</Kbd>
392 <span className="flex items-center gap-2 pe-8">
393 {actionIcon(action)}
394 <span className="font-medium text-sm">{action.label}</span>
395 </span>
396 <span className="mt-1.5 text-muted-foreground text-xs leading-relaxed">
397 {action.disabledReason}
398 </span>
399 </div>
400 ),
401 )}
402 </div>
403 </div>
404 </div>
405 );
407​
408function surfaceTitle(
409 surface: RightPanelSurface,
410 sessions: Readonly<Record<string, PreviewSessionSnapshot>>,
411 terminalLabelsById: ReadonlyMap<string, string>,
412): string {
413 switch (surface.kind) {
414 case "diff":
415 return "Diff";
416 case "files":
417 return "Files";
418 case "file":
419 return surface.relativePath.slice(surface.relativePath.lastIndexOf("/") + 1);
420 case "terminal":
421 return (
422 terminalLabelsById.get(surface.activeTerminalId) ??
423 getTerminalLabel(surface.activeTerminalId)
424 );
425 case "pull-request":
426 return `#${surface.number}`;
427 case "agents":
428 return "Agents";
429 case "preview": {
430 const snapshot = surface.resourceId ? sessions[surface.resourceId] : null;
431 if (!snapshot || snapshot.navStatus._tag === "Idle") return "Browser";
432 if (snapshot.navStatus.title.trim().length > 0) return snapshot.navStatus.title;
433 try {
434 return new URL(snapshot.navStatus.url).host || "Browser";
435 } catch {
436 return "Browser";
437 }
438 }
439 }
441​
442function PreviewFavicon({ capturedUrl, url }: { capturedUrl: string | null; url: string | null }) {
443 const publicProviderUrl = faviconUrlForOrigin(url, 32);
444 return (
445 <FaviconImage
446 sources={[capturedUrl, publicProviderUrl]}
447 fallback={<Globe2 className="size-3 shrink-0" />}
448 className="size-3 shrink-0 rounded-sm object-contain"
449 />
450 );
452​
453function sameOrigin(left: string, right: string): boolean {
454 try {
455 return new URL(left).origin === new URL(right).origin;
456 } catch {
457 return false;
458 }
460​
461function SurfaceIcon({
462 surface,
463 sessions,
464 desktopByTabId,
465 theme,
466 pullRequestStatuses,
467}: {
468 surface: RightPanelSurface;
469 sessions: Readonly<Record<string, PreviewSessionSnapshot>>;
470 desktopByTabId: Readonly<Record<string, DesktopPreviewOverlay>>;
471 theme: "light" | "dark";
472 pullRequestStatuses: Readonly<Record<string, PullRequestTabStatus>> | undefined;
473}) {
474 switch (surface.kind) {
475 case "preview": {
476 const snapshot = surface.resourceId ? sessions[surface.resourceId] : null;
477 const url = !snapshot || snapshot.navStatus._tag === "Idle" ? null : snapshot.navStatus.url;
478 const favicon = snapshot ? (desktopByTabId[snapshot.tabId]?.favicon ?? null) : null;
479 const capturedUrl =
480 favicon && url && sameOrigin(favicon.pageUrl, url) ? favicon.dataUrl : null;
481 return <PreviewFavicon capturedUrl={capturedUrl} url={url} />;
482 }
483 case "diff":
484 return <FileDiff className="size-3 shrink-0" />;
485 case "files":
486 return <Files className="size-3 shrink-0" />;
487 case "file":
488 return (
489 <PierreEntryIcon
490 pathValue={surface.relativePath}
491 kind="file"
492 theme={theme}
493 className="size-3"
494 />
495 );
496 case "terminal":
497 return <TerminalSquare className="size-3 shrink-0" />;
498 case "pull-request": {
499 const status = pullRequestStatuses?.[surface.id] ?? null;
500 const toneClassName =
501 status?.state === "merged"
502 ? "text-violet-600 dark:text-violet-300/90"
503 : status?.state === "closed"
504 ? "text-red-600 dark:text-red-300/90"
505 : status?.isDraft
506 ? "text-zinc-500 dark:text-zinc-400/80"
507 : status?.state === "open"
508 ? "text-emerald-600 dark:text-emerald-300/90"
509 : "text-muted-foreground";
510 return <GitPullRequest className={cn("size-3 shrink-0", toneClassName)} />;
511 }
512 case "agents":
513 return <Bot className="size-3 shrink-0" />;
514 }
516​
517export function RightPanelTabs(props: RightPanelTabsProps) {
518 const ownsDesktopTitleBar = isElectron && props.mode === "inline";
519 const { resolvedTheme } = useTheme();
520 const tabListRef = useRef<HTMLDivElement>(null);
521​
522 const handleTabContextMenu = useCallback(
523 async (event: ReactMouseEvent, surface: RightPanelSurface) => {
524 event.preventDefault();
525 event.stopPropagation();
526​
527 const api = readLocalApi();
528 if (!api) return;
529​
530 const surfaceIndex = props.surfaces.findIndex((entry) => entry.id === surface.id);
531 if (surfaceIndex < 0) return;
532​
533 const items: ContextMenuItem<TabContextMenuAction>[] = [];
534 if (surface.kind === "file") {
535 items.push({ id: "copy-path", label: "Copy path" });
536 }
537 items.push(
538 { id: "close", label: "Close" },
539 {
540 id: "close-others",
541 label: "Close others",
542 disabled: props.surfaces.length <= 1,
543 },
544 {
545 id: "close-to-right",
546 label: "Close to the right",
547 disabled: surfaceIndex >= props.surfaces.length - 1,
548 },
549 {
550 id: "close-all",
551 label: "Close all",
552 disabled: props.surfaces.length === 0,
553 },
554 );
555​
556 const action = await api.contextMenu.show(items, { x: event.clientX, y: event.clientY });
557 switch (action) {
558 case "copy-path":
559 if (surface.kind === "file") props.onCopyFilePath(surface.relativePath);
560 break;
561 case "close":
562 props.onCloseSurface(surface);
563 break;
564 case "close-others":
565 props.onCloseOtherSurfaces(surface);
566 break;
567 case "close-to-right":
568 props.onCloseSurfacesToRight(surface);
569 break;
570 case "close-all":
571 props.onCloseAllSurfaces();
572 break;
573 case null:
574 break;
575 }
576 },
577 [props],
578 );
579 const handleTabMouseDown = useCallback((event: ReactMouseEvent) => {
580 if (event.button !== 1) return;
581 event.preventDefault();
582 }, []);
583 const handleTabAuxClick = useCallback(
584 (event: ReactMouseEvent, surface: RightPanelSurface) => {
585 if (event.button !== 1) return;
586 event.preventDefault();
587 event.stopPropagation();
588 props.onCloseSurface(surface);
589 },
590 [props],
591 );
592​
593 useEffect(() => {
594 const activeTab = tabListRef.current?.querySelector<HTMLElement>("[data-active-tab='true']");
595 activeTab?.scrollIntoView({ block: "nearest", inline: "nearest" });
596 }, [props.activeSurfaceId]);
597​
598 return (
599 <PreviewPanelShell
600 mode={props.mode}
601 {...(props.maximized !== undefined ? { maximized: props.maximized } : {})}
602 {...(props.widthStorageKey !== undefined ? { widthStorageKey: props.widthStorageKey } : {})}
603 {...(props.defaultWidth !== undefined ? { defaultWidth: props.defaultWidth } : {})}
604 >
605 <div
606 className={cn(
607 "flex h-[var(--workspace-topbar-height)] min-h-[var(--workspace-topbar-height)] shrink-0 items-center gap-1 pl-2",
608 // The sheet overlays from the viewport top, so its tab bar keeps
609 // the titlebar's height: a compact row re-centers the layout
610 // controls a few pixels higher and the cluster jumps on open.
611 props.mode === "inline" && !props.layoutControls ? "pr-28" : "pr-3",
612 ownsDesktopTitleBar && "wco:pr-[calc(var(--workspace-native-controls-inset)+6rem)]",
613 props.mode === "inline" && props.maximized && COLLAPSED_SIDEBAR_TITLEBAR_INSET_CLASS,
614 )}
615 data-right-panel-tabbar
616 >
617 <ScrollArea
618 ref={tabListRef}
619 hideScrollbars
620 scrollFade
621 className={cn("min-w-0 flex-1 rounded-none", ownsDesktopTitleBar && "drag-region")}
622 data-right-panel-tab-list
623 >
624 <div className="flex h-full w-max min-w-full items-center gap-1">
625 {props.surfaces.map((surface) => {
626 const active = surface.id === props.activeSurfaceId;
627 const pending = props.pendingSurfaceIds.has(surface.id);
628 const title = surfaceTitle(surface, props.previewSessions, props.terminalLabelsById);
629 return (
630 <div
631 key={surface.id}
632 data-active-tab={active}
633 onMouseDown={handleTabMouseDown}
634 onAuxClick={(event) => handleTabAuxClick(event, surface)}
635 onContextMenu={(event) => void handleTabContextMenu(event, surface)}
636 className={cn(
637 "cursor-pointer group/tab flex h-6 max-w-36 shrink-0 items-center gap-0.5 rounded-md pr-2 pl-1.5 text-xs",
638 active
639 ? "bg-accent text-foreground"
640 : "text-muted-foreground hover:bg-accent/60 hover:text-foreground",
641 )}
642 >
643 <button
644 type="button"
645 className="cursor-pointer group/close relative flex size-4 shrink-0 items-center justify-center rounded-sm hover:bg-muted"
646 aria-label={`Close ${title}`}
647 onClick={() => props.onCloseSurface(surface)}
648 >
649 <span className="relative flex size-3 items-center justify-center group-hover/tab:hidden group-focus-visible/close:hidden">
650 <SurfaceIcon
651 surface={surface}
652 sessions={props.previewSessions}
653 desktopByTabId={props.desktopByTabId}
654 theme={resolvedTheme}
655 pullRequestStatuses={props.pullRequestStatuses}
656 />
657 {pending ? (
658 <span
659 className="absolute -right-0.5 -bottom-0.5 size-1.5 rounded-full bg-current"
660 aria-hidden
661 />
662 ) : null}
663 </span>
664 <X className="hidden size-3 group-hover/tab:block group-focus-visible/close:block" />
665 </button>
666 <Tooltip>
667 <TooltipTrigger
668 render={
669 <button
670 type="button"
671 className="cursor-pointer flex min-w-0 items-center"
672 onClick={() => props.onActivate(surface)}
673 >
674 <span className="truncate">{title}</span>
675 </button>
676 }
677 />
678 <TooltipPopup>{title}</TooltipPopup>
679 </Tooltip>
680 </div>
681 );
682 })}
683 {props.surfaces.length > 0 ? (
684 <Menu>
685 <MenuTrigger
686 render={
687 <Button
688 aria-label="Add panel surface"
689 className="size-6 shrink-0 text-muted-foreground hover:text-foreground"
690 size="icon-xs"
691 variant="ghost"
692 />
693 }
694 >
695 <Plus className="size-3.5" />
696 </MenuTrigger>
697 <MenuPopup align="start" side="bottom" sideOffset={6} className="min-w-44">
698 <SurfaceMenuItem
699 available={props.browserAvailable}
700 disabledReason={SURFACE_DISABLED_REASONS.browser}
701 onClick={props.onAddBrowser}
702 >
703 <Globe2 />
704 Browser
705 </SurfaceMenuItem>
706 <SurfaceMenuItem
707 available={props.terminalAvailable}
708 disabledReason={SURFACE_DISABLED_REASONS.terminal}
709 onClick={props.onAddTerminal}
710 >
711 <TerminalSquare />
712 Terminal
713 </SurfaceMenuItem>
714 <SurfaceMenuItem
715 available={props.filesAvailable}
716 disabledReason={SURFACE_DISABLED_REASONS.files}
717 onClick={props.onAddFiles}
718 >
719 <Files />
720 Files
721 </SurfaceMenuItem>
722 <SurfaceMenuItem
723 available={props.diffAvailable}
724 disabledReason={SURFACE_DISABLED_REASONS.diff}
725 onClick={props.onAddDiff}
726 >
727 <FileDiff />
728 Diff
729 </SurfaceMenuItem>
730 <SurfaceMenuItem
731 available={props.pullRequestAvailable}
732 disabledReason={SURFACE_DISABLED_REASONS.pullRequest}
733 onClick={props.onAddPullRequest}
734 >
735 <GitPullRequest />
736 Pull request
737 </SurfaceMenuItem>
738 <SurfaceMenuItem
739 available={props.agentsAvailable}
740 disabledReason={SURFACE_DISABLED_REASONS.agents}
741 onClick={props.onAddAgents}
742 >
743 <Bot />
744 Agents
745 </SurfaceMenuItem>
746 </MenuPopup>
747 </Menu>
748 ) : null}
749 </div>
750 </ScrollArea>
751 {props.layoutControls}
752 </div>
753 <div className="flex min-h-0 flex-1 flex-col" data-right-panel-surface-content>
754 {props.activeSurfaceId === null ? (
755 <RightPanelEmptyState
756 onAddBrowser={props.onAddBrowser}
757 onAddTerminal={props.onAddTerminal}
758 onAddDiff={props.onAddDiff}
759 onAddFiles={props.onAddFiles}
760 onAddPullRequest={props.onAddPullRequest}
761 onAddAgents={props.onAddAgents}
762 browserAvailable={props.browserAvailable}
763 terminalAvailable={props.terminalAvailable}
764 diffAvailable={props.diffAvailable}
765 filesAvailable={props.filesAvailable}
766 pullRequestAvailable={props.pullRequestAvailable}
767 agentsAvailable={props.agentsAvailable}
768 liveAgentCount={props.liveAgentCount}
769 />
770 ) : (
771 props.children
772 )}
773 </div>
774 </PreviewPanelShell>
775 );