Open History to see the last commit
1import { pullRequestHostOf, type SourceControlProviderKind } from "@t3tools/contracts";
2import type { EnvironmentThreadShell } from "@t3tools/client-runtime/state/shell";
3import { useProjects, useServerConfigs, useThreadShells } from "~/state/entities";
4import {
5 threadPullRequestKeysEqual,
6 visibleThreadPullRequests,
7} from "@t3tools/shared/threadPullRequests";
8import type {
9 ContextMenuItem,
10 EnvironmentId,
11 PreviewSessionSnapshot,
12 ProjectId,
13 PullRequestState,
14} from "@t3tools/contracts";
15import { getTerminalLabel } from "@t3tools/shared/terminalLabels";
16import {
17 Smartphone,
18 ChevronDown,
19 ChevronLeft,
20 ChevronRight,
21 FileDiff,
22 Files,
23 Globe2,
24 Plus,
25 TerminalSquare,
26 Volume2,
27 VolumeOff,
28} from "lucide-react";
29import {
30 type KeyboardEvent as ReactKeyboardEvent,
31 type MouseEvent as ReactMouseEvent,
32 type ReactElement,
33 type ReactNode,
34 useCallback,
35 useEffect,
36 useMemo,
37 useRef,
38 useState,
39} from "react";
40
41import { isElectron } from "~/env";
42import type { DesktopPreviewOverlay } from "~/previewStateStore";
43import type { RightPanelSurface } from "~/rightPanelStore";
44import { cn } from "~/lib/utils";
45import { readLocalApi } from "~/localApi";
46import { Button } from "~/components/ui/button";
47import { AndroidIcon, AppleIcon } from "~/components/Icons";
48import { Tooltip, TooltipPopup, TooltipTrigger } from "~/components/ui/tooltip";
49import { Kbd } from "~/components/ui/kbd";
50import {
51 Menu,
52 MenuItem,
53 MenuPopup,
54 MenuShortcut,
55 MenuSub,
56 MenuSubPopup,
57 MenuSubTrigger,
58 MenuTrigger,
59} from "~/components/ui/menu";
60import { useBrowserDefaults } from "~/browser/browserDefaults";
61import { ScrollArea } from "~/components/ui/scroll-area";
62import { PanelTabCloseButton } from "~/components/ui/panel-tab-close-button";
63import { faviconUrlForOrigin } from "~/lib/favicon";
64import { useTheme } from "~/hooks/useTheme";
65import type { PreviewPanelInlineSize } from "~/hooks/usePreviewPanelInlineSize";
66import {
67 newestPullRequestSummary,
68 pullRequestEnvironment,
69 useSharedPullRequestSummary,
70} from "~/state/pullRequests";
71import { useEnvironmentQuery } from "~/state/query";
72import { COLLAPSED_SIDEBAR_TITLEBAR_INSET_CLASS } from "~/workspaceTitlebar";
73
74import { PreviewPanelShell, type PreviewPanelMode } from "./preview/PreviewPanelShell";
75import { FaviconImage } from "./preview/PreviewFaviconIcon";
76import { previewBridge } from "./preview/previewBridge";
77import { PierreEntryIcon } from "./chat/PierreEntryIcon";
78import { resolvePullRequestState } from "./pullRequest/pullRequestPresentation";
79import { PullRequestGlyph } from "~/components/pullRequest/pullRequestIcons";
80
81interface RightPanelTabsProps {
82 mode: PreviewPanelMode;
83 maximized?: boolean;
84 open?: boolean;
85 /** Forwarded to PreviewPanelShell so this surface persists its own width. */
86 widthStorageKey?: string;
87 /** Forwarded to PreviewPanelShell as the initial width before a user resize. */
88 defaultWidth?: number;
89 inlineSize?: PreviewPanelInlineSize;
90 layoutControls?: ReactNode;
91 surfaces: readonly RightPanelSurface[];
92 /** Fallback environment for surfaces that do not carry their own. */
93 environmentId: EnvironmentId | null;
94 activeSurfaceId: string | null;
95 pendingSurfaceIds: ReadonlySet<string>;
96 previewSessions: Readonly<Record<string, PreviewSessionSnapshot>>;
97 desktopByTabId: Readonly<Record<string, DesktopPreviewOverlay>>;
98 /**
99 * Maps a server session tab id to the desktop runtime tab id the Electron
100 * preview manager is keyed by. Session ids are only unique within one server
101 * process, so desktop operations must not be addressed with them.
102 */
103 previewRuntimeTabId?: ((tabId: string) => string) | undefined;
104 terminalLabelsById: ReadonlyMap<string, string>;
105 onActivate: (surface: RightPanelSurface) => void;
106 onRenameDevice?: (surfaceId: string, title: string) => void;
107 onCloseSurface: (surface: RightPanelSurface) => void;
108 onCloseOtherSurfaces: (surface: RightPanelSurface) => void;
109 onCloseSurfacesToRight: (surface: RightPanelSurface) => void;
110 onCloseAllSurfaces: () => void;
111 onCopyFilePath: (relativePath: string) => void;
112 onAddBrowser: () => void;
113 /**
114 * Separate from `onAddBrowser` on purpose: that one is passed directly as a
115 * DOM click handler, and a `(profileId?: string)` signature would silently
116 * accept the MouseEvent as a profile id.
117 */
118 onAddBrowserInProfile: (profileId: string) => void;
119 onAddTerminal: () => void;
120 onAddDiff: () => void;
121 onAddFiles: () => void;
122 onAddPullRequest: () => void;
123 onAddPullRequests: () => void;
124 onAddDevice: () => void;
125 browserAvailable: boolean;
126 terminalAvailable: boolean;
127 diffAvailable: boolean;
128 filesAvailable: boolean;
129 pullRequestAvailable: boolean;
130 pullRequestsAvailable: boolean;
131 deviceAvailable: boolean;
132 pullRequestStatusSeeds?: Readonly<Record<string, PullRequestTabStatusSeed>>;
133 children: ReactNode;
134}
135
136export interface PullRequestTabStatus {
137 projectId: string;
138 repository: string;
139 number: number;
140 state: PullRequestState;
141 isDraft: boolean;
142}
143
144export type PullRequestTabStatusSeed = Pick<PullRequestTabStatus, "state" | "isDraft">;
145
146export function shouldOpenDefaultBrowserProfileFromMenuClick(
147 pointerType: string | undefined,
148): boolean {
149 return pointerType !== "touch";
150}
151
152const SURFACE_DISABLED_REASONS = {
153 browser: "Browser previews are only available in the T3 Code desktop app.",
154 terminal: "Terminal surfaces are only available from a project thread.",
155 files: "Files are only available when a project is open.",
156 diff: "Diff is only available for server threads in Git repositories.",
157 pullRequest: "This thread's branch has no pull request yet.",
158 pullRequests: "No linked pull requests are available for this thread.",
159 device: "Devices are only available from a thread.",
160} as const;
161
162/** Overlays that must win over the launcher's letter shortcuts. */
163const LAUNCHER_SHORTCUT_BLOCKING_LAYERS = [
164 '[data-slot="dialog-popup"]',
165 '[data-slot="alert-dialog-popup"]',
166 '[data-slot="command-dialog-popup"]',
167 '[data-slot="menu-popup"]',
168 '[data-slot="select-popup"]',
169 '[data-slot="popover-popup"]',
170 '[data-slot="combobox-popup"]',
171 '[data-slot="autocomplete-popup"]',
172].join(",");
173
174/** One-line unavailability hints for the empty-state rows. */
175const SURFACE_UNAVAILABLE_HINTS = {
176 browser: "Only available in the desktop app.",
177 terminal: "Available when a project is open.",
178 files: "Available when a project is open.",
179 diff: "Available for Git repositories.",
180 pullRequest: "No pull request on this branch yet.",
181 pullRequests: "No linked pull requests available.",
182 device: "Available from a thread.",
183} as const;
184
185type TabContextMenuAction =
186 | "rename"
187 | "copy-path"
188 | "toggle-mute"
189 | "close"
190 | "close-others"
191 | "close-to-right"
192 | "close-all";
193
194const TAB_SCROLL_EDGE_TOLERANCE = 1;
195
196function tabScrollViewport(root: HTMLDivElement | null): HTMLDivElement | null {
197 return root?.querySelector<HTMLDivElement>('[data-slot="scroll-area-viewport"]') ?? null;
198}
199
200/**
201 * Desktop preview tab backing a surface, or null for non-preview surfaces, the
202 * "new browser tab" placeholder, and the web build where no desktop tab exists.
203 */
204function previewTabIdOf(
205 surface: RightPanelSurface,
206 sessions: Readonly<Record<string, PreviewSessionSnapshot>>,
207): string | null {
208 if (surface.kind !== "preview" || !surface.resourceId) return null;
209 return sessions[surface.resourceId]?.tabId ?? null;
210}
211
212/**
213 * Label and enabled state for a preview tab's mute menu entry.
214 * Stays disabled until desktop overlay state arrives: a server session id can
215 * resolve while the preview manager's createTab is still in flight, and muting
216 * then fails with a PreviewTabNotFoundError nothing surfaces to the user.
217 */
218export function tabMuteMenuItem(input: {
219 overlay: DesktopPreviewOverlay | null;
220 canResolveRuntimeTabId: boolean;
221}): { label: string; disabled: boolean } {
222 const muted = input.overlay?.audioMuted ?? false;
223 return {
224 label: muted ? "Unmute tab" : "Mute tab",
225 disabled: input.overlay === null || !input.canResolveRuntimeTabId,
226 };
227}
228
229type TabAudioState = "none" | "audible" | "muted";
230
231/**
232 * A muted tab that is not making sound shows nothing: mute is armed silently,
233 * and the indicator only appears once there is audio to speak of.
234 */
235function tabAudioState(overlay: DesktopPreviewOverlay | null): TabAudioState {
236 if (!overlay?.audible) return "none";
237 return overlay.audioMuted ? "muted" : "audible";
238}
239
240type SurfaceShortcutEvent = Pick<
241 KeyboardEvent,
242 "altKey" | "ctrlKey" | "defaultPrevented" | "isComposing" | "key" | "metaKey"
243>;
244
245export function surfaceShortcutActionForKey<
246 const Action extends { available: boolean; shortcut: string },
247>(actions: readonly Action[], event: SurfaceShortcutEvent): Action | null {
248 if (event.defaultPrevented || event.isComposing) return null;
249 if (event.metaKey || event.ctrlKey || event.altKey) return null;
250 return (
251 actions.find(
252 (action) => action.available && action.shortcut.toLowerCase() === event.key.toLowerCase(),
253 ) ?? null
254 );
255}
256
257/**
258 * A focused editable is a typing context whether or not it has text yet: an
259 * empty chat composer at rest is still where the user's next keystrokes are
260 * meant to land, and claiming launcher letters from it would redirect prompts
261 * into whatever surface opens. The `:not` clause lets `closest` see past
262 * non-editable islands (`contenteditable="false"`) to an editable host around
263 * them, matching ComposerPendingUserInputPanel's typing guard.
264 */
265export function surfaceShortcutTargetsTypingContext(
266 target: { closest(selectors: string): unknown } | null,
267): boolean {
268 return (
269 target?.closest('input, textarea, select, [contenteditable]:not([contenteditable="false"])') !=
270 null
271 );
272}
273
274function DisabledReasonTooltip(props: { reason: string; trigger: ReactElement }) {
275 return (
276 <Tooltip>
277 <TooltipTrigger render={props.trigger} />
278 <TooltipPopup side="top">{props.reason}</TooltipPopup>
279 </Tooltip>
280 );
281}
282
283function SurfaceMenuItem(props: {
284 available: boolean;
285 disabledReason?: string;
286 shortcut: string;
287 onClick: () => void;
288 children: ReactNode;
289}) {
290 const item = (
291 <MenuItem
292 className={!props.available ? "data-disabled:pointer-events-auto" : undefined}
293 onClick={props.onClick}
294 disabled={!props.available}
295 aria-keyshortcuts={props.shortcut}
296 >
297 {props.children}
298 <MenuShortcut>{props.shortcut}</MenuShortcut>
299 </MenuItem>
300 );
301 if (props.available || !props.disabledReason) return item;
302 return <DisabledReasonTooltip reason={props.disabledReason} trigger={item} />;
303}
304
305/**
306 * List launcher shown when the right panel has no surfaces. Keyboard-first
307 * without palette chrome: a surface's letter opens it directly from anywhere
308 * outside a typing context, and arrows plus Enter work while the launcher is
309 * focused. The highlight only appears on hover or arrow use. Unavailable
310 * surfaces stay visible with a one-line reason.
311 */
312function RightPanelEmptyState(props: {
313 onAddBrowser: () => void;
314 onAddBrowserInProfile: (profileId: string) => void;
315 browserProfiles: ReadonlyArray<{ readonly id: string; readonly name: string }>;
316 onAddTerminal: () => void;
317 onAddDiff: () => void;
318 onAddFiles: () => void;
319 onAddPullRequest: () => void;
320 onAddPullRequests: () => void;
321 onAddDevice: () => void;
322 browserAvailable: boolean;
323 terminalAvailable: boolean;
324 diffAvailable: boolean;
325 filesAvailable: boolean;
326 pullRequestAvailable: boolean;
327 pullRequestsAvailable: boolean;
328 deviceAvailable: boolean;
329}) {
330 // -1 means no highlight: it only appears on hover or arrow use.
331 const [highlight, setHighlight] = useState(-1);
332
333 const actions = [
334 {
335 label: "Browser",
336 icon: Globe2,
337 shortcut: "B",
338 available: props.browserAvailable,
339 disabledReason: SURFACE_UNAVAILABLE_HINTS.browser,
340 onClick: props.onAddBrowser,
341 },
342 {
343 label: "Terminal",
344 icon: TerminalSquare,
345 shortcut: "T",
346 available: props.terminalAvailable,
347 disabledReason: SURFACE_UNAVAILABLE_HINTS.terminal,
348 onClick: props.onAddTerminal,
349 },
350 {
351 label: "Files",
352 icon: Files,
353 shortcut: "F",
354 available: props.filesAvailable,
355 disabledReason: SURFACE_UNAVAILABLE_HINTS.files,
356 onClick: props.onAddFiles,
357 },
358 {
359 label: "Diff",
360 icon: FileDiff,
361 shortcut: "D",
362 available: props.diffAvailable,
363 disabledReason: SURFACE_UNAVAILABLE_HINTS.diff,
364 onClick: props.onAddDiff,
365 },
366 {
367 label: "Pull request",
368 icon: PullRequestGlyph.pullRequest,
369 shortcut: "P",
370 available: props.pullRequestAvailable,
371 disabledReason: SURFACE_UNAVAILABLE_HINTS.pullRequest,
372 onClick: props.onAddPullRequest,
373 },
374 {
375 label: "Linked pull requests",
376 icon: PullRequestGlyph.link,
377 shortcut: "L",
378 available: props.pullRequestsAvailable,
379 disabledReason: SURFACE_UNAVAILABLE_HINTS.pullRequests,
380 onClick: props.onAddPullRequests,
381 },
382 {
383 label: "Device",
384 description: "Watch an iOS Simulator or Android Emulator.",
385 icon: Smartphone,
386 shortcut: "M",
387 available: props.deviceAvailable,
388 disabledReason: SURFACE_UNAVAILABLE_HINTS.device,
389 onClick: props.onAddDevice,
390 },
391 ] as const;
392
393 type SurfaceAction = (typeof actions)[number];
394
395 const availableActions = actions.filter((action) => action.available);
396 const highlightIndex =
397 availableActions.length === 0 ? -1 : Math.min(highlight, availableActions.length - 1);
398
399 // Letter shortcuts work while the launcher is visible, not only while it
400 // is focused; focus moves around too easily (stray clicks) to carry them.
401 // Capture phase so app-level key handlers cannot swallow the event first;
402 // typing contexts and already-handled events are left alone.
403 const shortcutActionsRef = useRef(availableActions);
404 useEffect(() => {
405 shortcutActionsRef.current = availableActions;
406 });
407 useEffect(() => {
408 const handler = (event: KeyboardEvent) => {
409 const action = surfaceShortcutActionForKey(shortcutActionsRef.current, event);
410 if (!action) return;
411 if (document.querySelector(LAUNCHER_SHORTCUT_BLOCKING_LAYERS)) return;
412 const target = event.target;
413 if (target instanceof Element && surfaceShortcutTargetsTypingContext(target)) return;
414 event.preventDefault();
415 event.stopPropagation();
416 action.onClick();
417 };
418 window.addEventListener("keydown", handler, true);
419 return () => window.removeEventListener("keydown", handler, true);
420 }, []);
421
422 const handleKeyDown = (event: ReactKeyboardEvent<HTMLDivElement>) => {
423 if (event.defaultPrevented || event.metaKey || event.ctrlKey || event.altKey) return;
424 if (availableActions.length === 0) return;
425 if (event.key === "ArrowDown" || event.key === "ArrowRight") {
426 event.preventDefault();
427 setHighlight((highlightIndex + 1) % availableActions.length);
428 return;
429 }
430 if (event.key === "ArrowUp" || event.key === "ArrowLeft") {
431 event.preventDefault();
432 setHighlight(
433 highlightIndex === -1
434 ? availableActions.length - 1
435 : (highlightIndex - 1 + availableActions.length) % availableActions.length,
436 );
437 return;
438 }
439 if (event.key === "Enter") {
440 // Only activate the highlight when the launcher itself has focus.
441 if (event.target !== event.currentTarget) return;
442 const action = availableActions[highlightIndex];
443 if (!action) return;
444 event.preventDefault();
445 action.onClick();
446 }
447 };
448
449 // Stable identity so React only runs this callback ref on mount/unmount;
450 // an inline arrow would re-attach and re-focus on every render.
451 const focusOnMount = useCallback((node: HTMLDivElement | null) => {
452 node?.focus();
453 }, []);
454
455 const isHighlighted = (action: SurfaceAction) =>
456 highlightIndex !== -1 && availableActions[highlightIndex] === action;
457
458 const actionIcon = (action: SurfaceAction, iconClassName = "size-4") => {
459 const Icon = action.icon;
460 return (
461 <span className="relative inline-flex shrink-0">
462 <Icon className={iconClassName} />
463 </span>
464 );
465 };
466
467 return (
468 <div
469 ref={focusOnMount}
470 tabIndex={0}
471 onKeyDown={handleKeyDown}
472 aria-label="Open a surface"
473 data-surface-launcher-keys={availableActions.map((action) => action.shortcut).join("")}
474 className={cn(
475 "flex min-h-0 flex-1 items-center justify-center overflow-y-auto px-6 pt-6 outline-none",
476 // The panel topbar sits above this container; matching bottom padding
477 // keeps the list centered against the full panel, not the leftover.
478 "pb-[calc(var(--workspace-topbar-height)+--spacing(6))]",
479 )}
480 >
481 <div className="w-full max-w-xs">
482 <h3 className="mb-3 text-center font-medium text-foreground text-sm">Open a surface</h3>
483 <div className="flex flex-col gap-0.5">
484 {actions.map((action) =>
485 action.available ? (
486 // The row is itself a button, so the profile chooser sits beside
487 // it in a wrapper rather than inside it. Hover lives on the
488 // wrapper: the chooser overlays the row, and a pointer moving
489 // onto it must not read as leaving the row.
490 <div
491 key={action.label}
492 className="group relative"
493 onMouseEnter={() => setHighlight(availableActions.indexOf(action))}
494 onMouseLeave={() =>
495 setHighlight((current) =>
496 current === availableActions.indexOf(action) ? -1 : current,
497 )
498 }
499 >
500 <button
501 type="button"
502 onClick={action.onClick}
503 className={cn(
504 "flex h-8 w-full cursor-pointer items-center gap-2.5 rounded-[var(--control-radius)] px-2.5 text-left text-sm transition-colors group-hover:bg-accent/60",
505 isHighlighted(action) && "bg-accent/60",
506 )}
507 >
508 {actionIcon(action, "size-4")}
509 <span
510 className={cn(
511 "min-w-0 flex-1 truncate",
512 action.label === "Browser" && props.browserProfiles.length > 1 && "pr-7",
513 )}
514 >
515 {action.label}
516 </span>
517 <Kbd>{action.shortcut}</Kbd>
518 </button>
519 {/*
520 Same choice the tab bar's "+" menu offers: the row opens the
521 default profile, the chevron picks another. Only worth showing
522 once there is something to choose between.
523 */}
524 {action.label === "Browser" && props.browserProfiles.length > 1 ? (
525 <Menu>
526 <MenuTrigger
527 render={
528 <Button
529 aria-label="Open browser in a profile"
530 className="absolute top-1/2 right-8 -translate-y-1/2 [--control-icon-color:currentColor]"
531 size="icon-xs"
532 variant="ghost-muted"
533 />
534 }
535 >
536 <ChevronDown className="size-3.5" />
537 </MenuTrigger>
538 <MenuPopup
539 align="end"
540 side="bottom"
541 sideOffset={6}
542 className="min-w-40 max-w-56"
543 >
544 {props.browserProfiles.map((profile) => (
545 <MenuItem
546 key={profile.id}
547 onClick={() => props.onAddBrowserInProfile(profile.id)}
548 >
549 <span className="min-w-0 truncate">{profile.name}</span>
550 </MenuItem>
551 ))}
552 </MenuPopup>
553 </Menu>
554 ) : null}
555 </div>
556 ) : (
557 <DisabledReasonTooltip
558 key={action.label}
559 reason={action.disabledReason}
560 trigger={
561 <div
562 tabIndex={0}
563 aria-disabled="true"
564 className="flex h-8 w-full cursor-default items-center gap-2.5 rounded-[var(--control-radius)] px-2.5 text-left text-sm opacity-50"
565 >
566 {actionIcon(action, "size-4")}
567 <span className="min-w-0 flex-1 truncate">{action.label}</span>
568 <Kbd>{action.shortcut}</Kbd>
569 </div>
570 }
571 />
572 ),
573 )}
574 </div>
575 </div>
576 </div>
577 );
578}
579
580function surfaceTitle(
581 surface: RightPanelSurface,
582 sessions: Readonly<Record<string, PreviewSessionSnapshot>>,
583 terminalLabelsById: ReadonlyMap<string, string>,
584): string {
585 switch (surface.kind) {
586 case "diff":
587 return "Diff";
588 case "files":
589 return "Files";
590 case "file":
591 return surface.relativePath.slice(
592 Math.max(surface.relativePath.lastIndexOf("/"), surface.relativePath.lastIndexOf("\\")) + 1,
593 );
594 case "terminal":
595 return (
596 terminalLabelsById.get(surface.activeTerminalId) ??
597 getTerminalLabel(surface.activeTerminalId)
598 );
599 case "pull-request":
600 return `#${surface.number}`;
601 case "pull-requests":
602 return "Pull requests";
603 case "device":
604 return surface.title ?? surface.target?.name ?? "Device";
605 case "preview": {
606 const snapshot = surface.resourceId ? sessions[surface.resourceId] : null;
607 if (!snapshot || snapshot.navStatus._tag === "Idle") return "Browser";
608 if (snapshot.navStatus.title.trim().length > 0) return snapshot.navStatus.title;
609 try {
610 return new URL(snapshot.navStatus.url).host || "Browser";
611 } catch {
612 return "Browser";
613 }
614 }
615 }
616}
617
618function PreviewFavicon({ capturedUrl, url }: { capturedUrl: string | null; url: string | null }) {
619 const publicProviderUrl = faviconUrlForOrigin(url, 32);
620 return (
621 <FaviconImage
622 sources={[capturedUrl, publicProviderUrl]}
623 fallback={<Globe2 className="size-3 shrink-0" />}
624 className="size-3 shrink-0 rounded-sm object-contain"
625 />
626 );
627}
628
629function sameOrigin(left: string, right: string): boolean {
630 try {
631 return new URL(left).origin === new URL(right).origin;
632 } catch {
633 return false;
634 }
635}
636
637function SurfaceIcon({
638 surface,
639 sessions,
640 desktopByTabId,
641 theme,
642 environmentId,
643 pullRequestStatusSeeds,
644}: {
645 surface: RightPanelSurface;
646 sessions: Readonly<Record<string, PreviewSessionSnapshot>>;
647 desktopByTabId: Readonly<Record<string, DesktopPreviewOverlay>>;
648 theme: "light" | "dark";
649 environmentId: EnvironmentId | null;
650 pullRequestStatusSeeds: Readonly<Record<string, PullRequestTabStatusSeed>> | undefined;
651}) {
652 switch (surface.kind) {
653 case "preview": {
654 const snapshot = surface.resourceId ? sessions[surface.resourceId] : null;
655 const url = !snapshot || snapshot.navStatus._tag === "Idle" ? null : snapshot.navStatus.url;
656 const favicon = snapshot ? (desktopByTabId[snapshot.tabId]?.favicon ?? null) : null;
657 const capturedUrl =
658 favicon && url && sameOrigin(favicon.pageUrl, url) ? favicon.dataUrl : null;
659 return <PreviewFavicon capturedUrl={capturedUrl} url={url} />;
660 }
661 case "diff":
662 return <FileDiff className="size-3 shrink-0" />;
663 case "files":
664 return <Files className="size-3 shrink-0" />;
665 case "file":
666 return (
667 <PierreEntryIcon
668 pathValue={surface.relativePath}
669 kind="file"
670 theme={theme}
671 className="size-3"
672 />
673 );
674 case "terminal":
675 return <TerminalSquare className="size-3 shrink-0" />;
676 case "pull-request":
677 return (
678 <PullRequestSurfaceIcon
679 surface={surface}
680 environmentId={environmentId}
681 seed={pullRequestStatusSeeds?.[surface.id]}
682 />
683 );
684 case "pull-requests":
685 return <PullRequestGlyph.link className="size-3 shrink-0" />;
686 case "device":
687 return surface.target?.platform === "ios" ? (
688 <AppleIcon className="size-3 shrink-0" />
689 ) : surface.target?.platform === "android" ? (
690 <AndroidIcon className="size-3 shrink-0" />
691 ) : (
692 <Smartphone className="size-3 shrink-0" />
693 );
694 }
695}
696
697export function resolvePullRequestTabLink(
698 threads: readonly Pick<EnvironmentThreadShell, "environmentId" | "pullRequests">[],
699 environmentId: EnvironmentId | null,
700 host: string | null,
701 reference: { repository: string; number: number },
702) {
703 if (environmentId === null || host === null) return undefined;
704 let newest: EnvironmentThreadShell["pullRequests"][number] | undefined;
705 for (const thread of threads) {
706 if (thread.environmentId !== environmentId) continue;
707 for (const link of visibleThreadPullRequests(thread.pullRequests)) {
708 if (
709 !threadPullRequestKeysEqual(link, {
710 host,
711 repository: reference.repository,
712 number: reference.number,
713 })
714 )
715 continue;
716 if (
717 newest === undefined ||
718 (link.snapshot?.syncedAt ?? "") > (newest.snapshot?.syncedAt ?? "")
719 )
720 newest = link;
721 }
722 }
723 return newest;
724}
725
726function PullRequestSurfaceIcon({
727 surface,
728 environmentId,
729 seed,
730}: {
731 surface: Extract<RightPanelSurface, { kind: "pull-request" }>;
732 environmentId: EnvironmentId | null;
733 seed: PullRequestTabStatusSeed | undefined;
734}) {
735 const resolvedEnvironmentId =
736 (surface.environmentId as EnvironmentId | undefined) ?? environmentId;
737 const projects = useProjects();
738 const threads = useThreadShells();
739 const project = projects.find(
740 (entry) => entry.environmentId === resolvedEnvironmentId && entry.id === surface.projectId,
741 );
742 const identity = project?.repositoryIdentity;
743 const host =
744 surface.host ??
745 (identity?.provider
746 ? pullRequestHostOf(identity, identity.provider as SourceControlProviderKind)
747 : null);
748 const configs = useServerConfigs();
749 const capabilities =
750 resolvedEnvironmentId === null
751 ? undefined
752 : configs.get(resolvedEnvironmentId)?.environment.capabilities;
753 const linkedSnapshot =
754 capabilities?.threadPullRequests === true
755 ? (resolvePullRequestTabLink(threads, resolvedEnvironmentId, host, surface)?.snapshot ?? null)
756 : null;
757 const detail = useEnvironmentQuery(
758 resolvedEnvironmentId === null || capabilities?.pullRequests !== true || linkedSnapshot !== null
759 ? null
760 : pullRequestEnvironment.detail({
761 environmentId: resolvedEnvironmentId,
762 input: {
763 projectId: surface.projectId as ProjectId,
764 ...(capabilities?.threadPullRequests === true && surface.host !== undefined
765 ? { host: surface.host }
766 : {}),
767 repository: surface.repository,
768 number: surface.number,
769 },
770 }),
771 ).data;
772 const reference = useMemo(
773 () => ({
774 projectId: surface.projectId as ProjectId,
775 repository: surface.repository,
776 number: surface.number,
777 }),
778 [surface.projectId, surface.repository, surface.number],
779 );
780 const sharedSummary = useSharedPullRequestSummary(resolvedEnvironmentId, reference, null);
781 // The compact tab intentionally shows lifecycle and draft state only. Conflict warnings have
782 // their own presentation on surfaces that have mergeability, while this tab stays stable as
783 // detail data arrives.
784 const status = linkedSnapshot ?? newestPullRequestSummary(detail, sharedSummary) ?? seed ?? null;
785 if (status === null) {
786 return <PullRequestGlyph.pullRequest className="size-3 shrink-0 text-muted-foreground" />;
787 }
788 const presentation = resolvePullRequestState({
789 state: status.state,
790 isDraft: status.isDraft ?? detail?.isDraft ?? seed?.isDraft ?? false,
791 });
792 return <presentation.Icon className={cn("size-3 shrink-0", presentation.toneClassName)} />;
793}
794
795export function RightPanelTabs(props: RightPanelTabsProps) {
796 const ownsDesktopTitleBar = isElectron && props.mode === "inline";
797 const browserProfiles = useBrowserDefaults().profiles;
798 const { resolvedTheme } = useTheme();
799 const tabListRef = useRef<HTMLDivElement>(null);
800 const [renamingDevice, setRenamingDevice] = useState<string | null>(null);
801 const [addSurfaceMenuOpen, setAddSurfaceMenuOpen] = useState(false);
802 const [tabScrollState, setTabScrollState] = useState({
803 hasOverflow: false,
804 canScrollLeft: false,
805 canScrollRight: false,
806 });
807
808 const updateTabScrollState = useCallback(() => {
809 const viewport = tabScrollViewport(tabListRef.current);
810 if (!viewport) return;
811
812 const hasOverflow = viewport.scrollWidth - viewport.clientWidth > TAB_SCROLL_EDGE_TOLERANCE;
813 const canScrollLeft = hasOverflow && viewport.scrollLeft > TAB_SCROLL_EDGE_TOLERANCE;
814 const canScrollRight =
815 hasOverflow &&
816 viewport.scrollLeft + viewport.clientWidth < viewport.scrollWidth - TAB_SCROLL_EDGE_TOLERANCE;
817 setTabScrollState((current) => {
818 if (
819 current.hasOverflow === hasOverflow &&
820 current.canScrollLeft === canScrollLeft &&
821 current.canScrollRight === canScrollRight
822 ) {
823 return current;
824 }
825 return { hasOverflow, canScrollLeft, canScrollRight };
826 });
827 }, []);
828
829 const scrollTabs = useCallback((direction: -1 | 1) => {
830 const viewport = tabScrollViewport(tabListRef.current);
831 if (!viewport) return;
832 const reduceMotion = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
833 viewport.scrollBy({
834 left: direction * Math.max(120, viewport.clientWidth * 0.75),
835 behavior: reduceMotion ? "auto" : "smooth",
836 });
837 }, []);
838
839 const addSurfaceActions = [
840 {
841 label: "Browser",
842 icon: Globe2,
843 shortcut: "B",
844 available: props.browserAvailable,
845 disabledReason: SURFACE_DISABLED_REASONS.browser,
846 onClick: props.onAddBrowser,
847 },
848 {
849 label: "Terminal",
850 icon: TerminalSquare,
851 shortcut: "T",
852 available: props.terminalAvailable,
853 disabledReason: SURFACE_DISABLED_REASONS.terminal,
854 onClick: props.onAddTerminal,
855 },
856 {
857 label: "Files",
858 icon: Files,
859 shortcut: "F",
860 available: props.filesAvailable,
861 disabledReason: SURFACE_DISABLED_REASONS.files,
862 onClick: props.onAddFiles,
863 },
864 {
865 label: "Diff",
866 icon: FileDiff,
867 shortcut: "D",
868 available: props.diffAvailable,
869 disabledReason: SURFACE_DISABLED_REASONS.diff,
870 onClick: props.onAddDiff,
871 },
872 {
873 label: "Pull request",
874 icon: PullRequestGlyph.pullRequest,
875 shortcut: "P",
876 available: props.pullRequestAvailable,
877 disabledReason: SURFACE_DISABLED_REASONS.pullRequest,
878 onClick: props.onAddPullRequest,
879 },
880 {
881 label: "Linked pull requests",
882 icon: PullRequestGlyph.link,
883 shortcut: "L",
884 available: props.pullRequestsAvailable,
885 disabledReason: SURFACE_DISABLED_REASONS.pullRequests,
886 onClick: props.onAddPullRequests,
887 },
888 {
889 label: "Device",
890 icon: Smartphone,
891 shortcut: "M",
892 available: props.deviceAvailable,
893 disabledReason: SURFACE_DISABLED_REASONS.device,
894 onClick: props.onAddDevice,
895 },
896 ] as const;
897
898 const handleAddSurfaceMenuKeyDown = (event: ReactKeyboardEvent<HTMLDivElement>) => {
899 const action = surfaceShortcutActionForKey(addSurfaceActions, event.nativeEvent);
900 if (!action) return;
901 event.preventDefault();
902 event.stopPropagation();
903 setAddSurfaceMenuOpen(false);
904 action.onClick();
905 };
906
907 const handleTabContextMenu = useCallback(
908 async (event: ReactMouseEvent, surface: RightPanelSurface) => {
909 event.preventDefault();
910 event.stopPropagation();
911
912 const api = readLocalApi();
913 if (!api) return;
914
915 const surfaceIndex = props.surfaces.findIndex((entry) => entry.id === surface.id);
916 if (surfaceIndex < 0) return;
917
918 const items: ContextMenuItem<TabContextMenuAction>[] = [];
919 if (surface.kind === "device" && props.onRenameDevice)
920 items.push({ id: "rename", label: "Rename" });
921 if (surface.kind === "file" && surface.attachment === undefined) {
922 items.push({ id: "copy-path", label: "Copy path" });
923 }
924 const menuPreviewTabId = previewTabIdOf(surface, props.previewSessions);
925 // Desktop overlay state only arrives once the preview manager has created
926 // the tab. A server session id alone can still be ahead of that, and
927 // muting then fails with PreviewTabNotFoundError that nobody surfaces.
928 const menuOverlay = menuPreviewTabId
929 ? (props.desktopByTabId[menuPreviewTabId] ?? null)
930 : null;
931 const menuMuted = menuOverlay?.audioMuted ?? false;
932 if (surface.kind === "preview") {
933 // Not gated on audibility: silencing a quiet tab ahead of time is the
934 // point, so the item is offered whenever the tab is mutable at all.
935 items.push({
936 id: "toggle-mute",
937 ...tabMuteMenuItem({
938 overlay: menuOverlay,
939 canResolveRuntimeTabId: props.previewRuntimeTabId !== undefined,
940 }),
941 });
942 }
943 items.push(
944 { id: "close", label: "Close" },
945 {
946 id: "close-others",
947 label: "Close others",
948 disabled: props.surfaces.length <= 1,
949 },
950 {
951 id: "close-to-right",
952 label: "Close to the right",
953 disabled: surfaceIndex >= props.surfaces.length - 1,
954 },
955 {
956 id: "close-all",
957 label: "Close all",
958 disabled: props.surfaces.length === 0,
959 },
960 );
961
962 const action = await api.contextMenu.show(items, { x: event.clientX, y: event.clientY });
963 switch (action) {
964 case "rename":
965 setRenamingDevice(surface.id);
966 break;
967 case "copy-path":
968 if (surface.kind === "file" && surface.attachment === undefined) {
969 props.onCopyFilePath(surface.relativePath);
970 }
971 break;
972 case "toggle-mute": {
973 // menuOverlay repeats the disabled gate above: the desktop tab must
974 // exist before it can be addressed, however the menu was dismissed.
975 const runtimeTabId =
976 menuPreviewTabId && menuOverlay
977 ? (props.previewRuntimeTabId?.(menuPreviewTabId) ?? null)
978 : null;
979 if (runtimeTabId) {
980 void previewBridge?.setAudioMuted(runtimeTabId, !menuMuted).catch(() => undefined);
981 }
982 break;
983 }
984 case "close":
985 props.onCloseSurface(surface);
986 break;
987 case "close-others":
988 props.onCloseOtherSurfaces(surface);
989 break;
990 case "close-to-right":
991 props.onCloseSurfacesToRight(surface);
992 break;
993 case "close-all":
994 props.onCloseAllSurfaces();
995 break;
996 case null:
997 break;
998 }
999 },
1000 [props],
1001 );
1002 const handleTabMouseDown = useCallback((event: ReactMouseEvent) => {
1003 if (event.button !== 1) return;
1004 event.preventDefault();
1005 }, []);
1006 const handleTabAuxClick = useCallback(
1007 (event: ReactMouseEvent, surface: RightPanelSurface) => {
1008 if (event.button !== 1) return;
1009 event.preventDefault();
1010 event.stopPropagation();
1011 props.onCloseSurface(surface);
1012 },
1013 [props],
1014 );
1015
1016 useEffect(() => {
1017 if (!props.activeSurfaceId || !tabScrollState.hasOverflow) return;
1018 const activeTab = tabListRef.current?.querySelector<HTMLElement>("[data-active-tab='true']");
1019 activeTab?.scrollIntoView({ block: "nearest", inline: "nearest" });
1020 }, [props.activeSurfaceId, tabScrollState.hasOverflow]);
1021
1022 useEffect(() => {
1023 const viewport = tabScrollViewport(tabListRef.current);
1024 if (!viewport) return;
1025
1026 const content = viewport.firstElementChild;
1027 const resizeObserver = new ResizeObserver(updateTabScrollState);
1028 resizeObserver.observe(viewport);
1029 if (content) resizeObserver.observe(content);
1030 viewport.addEventListener("scroll", updateTabScrollState, { passive: true });
1031 updateTabScrollState();
1032
1033 return () => {
1034 resizeObserver.disconnect();
1035 viewport.removeEventListener("scroll", updateTabScrollState);
1036 };
1037 }, [updateTabScrollState]);
1038
1039 useEffect(() => {
1040 const viewport = tabScrollViewport(tabListRef.current);
1041 if (!viewport) return;
1042
1043 const handleWheel = (event: WheelEvent) => {
1044 if (event.ctrlKey) return;
1045 let delta = Math.abs(event.deltaX) > Math.abs(event.deltaY) ? event.deltaX : event.deltaY;
1046 if (event.deltaMode === WheelEvent.DOM_DELTA_LINE) delta *= 16;
1047 if (event.deltaMode === WheelEvent.DOM_DELTA_PAGE) delta *= viewport.clientWidth;
1048 if (delta === 0) return;
1049
1050 const previousScrollLeft = viewport.scrollLeft;
1051 viewport.scrollLeft += delta;
1052 if (viewport.scrollLeft === previousScrollLeft) return;
1053 event.preventDefault();
1054 updateTabScrollState();
1055 };
1056
1057 viewport.addEventListener("wheel", handleWheel, { passive: false });
1058 return () => viewport.removeEventListener("wheel", handleWheel);
1059 }, [updateTabScrollState]);
1060
1061 return (
1062 <PreviewPanelShell
1063 mode={props.mode}
1064 {...(props.maximized !== undefined ? { maximized: props.maximized } : {})}
1065 {...(props.open !== undefined ? { open: props.open } : {})}
1066 {...(props.widthStorageKey !== undefined ? { widthStorageKey: props.widthStorageKey } : {})}
1067 {...(props.defaultWidth !== undefined ? { defaultWidth: props.defaultWidth } : {})}
1068 {...(props.inlineSize ? { inlineSize: props.inlineSize } : {})}
1069 >
1070 <div
1071 className={cn(
1072 "flex h-[var(--workspace-topbar-height)] min-h-[var(--workspace-topbar-height)] shrink-0 items-center gap-1 pl-2",
1073 // The sheet overlays from the viewport top, so its tab bar keeps
1074 // the titlebar's height: a compact row re-centers the layout
1075 // controls a few pixels higher and the cluster jumps on open.
1076 props.mode === "inline" && !props.layoutControls ? "pr-28" : "pr-3",
1077 ownsDesktopTitleBar && "drag-region",
1078 ownsDesktopTitleBar &&
1079 (props.layoutControls
1080 ? "wco:pr-[var(--workspace-native-controls-inset)]"
1081 : "wco:pr-[calc(var(--workspace-native-controls-inset)+6rem)]"),
1082 props.mode === "inline" && props.maximized && COLLAPSED_SIDEBAR_TITLEBAR_INSET_CLASS,
1083 )}
1084 data-right-panel-tabbar
1085 >
1086 <ScrollArea
1087 ref={tabListRef}
1088 hideScrollbars
1089 scrollFade
1090 className="min-w-0 flex-1 rounded-none"
1091 data-right-panel-tab-list
1092 >
1093 <div className="flex h-full w-max min-w-full items-center gap-1">
1094 {props.surfaces.map((surface) => {
1095 const active = surface.id === props.activeSurfaceId;
1096 const pending = props.pendingSurfaceIds.has(surface.id);
1097 const title = surfaceTitle(surface, props.previewSessions, props.terminalLabelsById);
1098 const previewTabId = previewTabIdOf(surface, props.previewSessions);
1099 // Desktop state is keyed by the session id, but desktop actions
1100 // must be addressed with the runtime id.
1101 const audio = tabAudioState(
1102 previewTabId ? (props.desktopByTabId[previewTabId] ?? null) : null,
1103 );
1104 const audioRuntimeTabId = previewTabId
1105 ? (props.previewRuntimeTabId?.(previewTabId) ?? null)
1106 : null;
1107 return (
1108 <div
1109 key={surface.id}
1110 data-active-tab={active}
1111 onMouseDown={handleTabMouseDown}
1112 onAuxClick={(event) => handleTabAuxClick(event, surface)}
1113 onContextMenu={(event) => void handleTabContextMenu(event, surface)}
1114 className={cn(
1115 "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",
1116 ownsDesktopTitleBar && "[-webkit-app-region:no-drag]",
1117 active
1118 ? "bg-accent text-foreground"
1119 : "text-muted-foreground hover:bg-accent/60 hover:text-foreground",
1120 )}
1121 >
1122 <PanelTabCloseButton
1123 label={`Close ${title}`}
1124 onClick={() => props.onCloseSurface(surface)}
1125 >
1126 <SurfaceIcon
1127 surface={surface}
1128 sessions={props.previewSessions}
1129 desktopByTabId={props.desktopByTabId}
1130 theme={resolvedTheme}
1131 environmentId={props.environmentId}
1132 pullRequestStatusSeeds={props.pullRequestStatusSeeds}
1133 />
1134 {pending ? (
1135 <span
1136 className="absolute -right-0.5 -bottom-0.5 size-1.5 rounded-full bg-current"
1137 aria-hidden
1138 />
1139 ) : null}
1140 </PanelTabCloseButton>
1141 {audio === "none" || !audioRuntimeTabId ? null : (
1142 <Tooltip>
1143 <TooltipTrigger
1144 render={
1145 <button
1146 type="button"
1147 className="cursor-pointer flex size-4 shrink-0 items-center justify-center rounded-sm hover:bg-muted"
1148 aria-label={audio === "muted" ? `Unmute ${title}` : `Mute ${title}`}
1149 onClick={(event) => {
1150 // Sibling of the close button, inside a tab that
1151 // activates on click: keep this to the toggle.
1152 event.stopPropagation();
1153 void previewBridge
1154 ?.setAudioMuted(audioRuntimeTabId, audio !== "muted")
1155 .catch(() => undefined);
1156 }}
1157 >
1158 {audio === "muted" ? (
1159 <VolumeOff className="size-3" />
1160 ) : (
1161 <Volume2 className="size-3" />
1162 )}
1163 </button>
1164 }
1165 />
1166 <TooltipPopup>{audio === "muted" ? "Unmute tab" : "Mute tab"}</TooltipPopup>
1167 </Tooltip>
1168 )}
1169 {renamingDevice === surface.id ? (
1170 <input
1171 aria-label="Device tab name"
1172 className="w-24 min-w-0 rounded-sm bg-background px-1 outline-none ring-1 ring-ring"
1173 defaultValue={title}
1174 ref={(element) => {
1175 element?.focus();
1176 element?.select();
1177 }}
1178 onBlur={(event) => {
1179 props.onRenameDevice?.(surface.id, event.currentTarget.value);
1180 setRenamingDevice(null);
1181 }}
1182 onKeyDown={(event) => {
1183 event.stopPropagation();
1184 if (event.key === "Enter") event.currentTarget.blur();
1185 if (event.key === "Escape") {
1186 event.currentTarget.value = title;
1187 event.currentTarget.blur();
1188 }
1189 }}
1190 />
1191 ) : (
1192 <Tooltip>
1193 <TooltipTrigger
1194 render={
1195 <button
1196 type="button"
1197 onDoubleClick={() => {
1198 if (surface.kind === "device" && props.onRenameDevice)
1199 setRenamingDevice(surface.id);
1200 }}
1201 className="cursor-pointer flex min-w-0 items-center"
1202 onClick={() => props.onActivate(surface)}
1203 >
1204 <span className="truncate">{title}</span>
1205 </button>
1206 }
1207 />
1208 <TooltipPopup>{title}</TooltipPopup>
1209 </Tooltip>
1210 )}
1211 </div>
1212 );
1213 })}
1214 {props.surfaces.length > 0 ? (
1215 <Menu open={addSurfaceMenuOpen} onOpenChange={setAddSurfaceMenuOpen}>
1216 <MenuTrigger
1217 render={
1218 <Button
1219 aria-label="Add panel surface"
1220 className="size-6 shrink-0 text-muted-foreground hover:text-foreground"
1221 size="icon-xs"
1222 variant="ghost"
1223 />
1224 }
1225 >
1226 <Plus className="size-3.5" />
1227 </MenuTrigger>
1228 <MenuPopup
1229 align="start"
1230 side="bottom"
1231 sideOffset={6}
1232 className="min-w-44"
1233 onKeyDownCapture={handleAddSurfaceMenuKeyDown}
1234 >
1235 {addSurfaceActions.map((action) => {
1236 const Icon = action.icon;
1237 // Browser collapses into one row: clicking the trigger opens
1238 // the default profile (the common case stays one click),
1239 // while hover or arrow reveals the profiles. The choice
1240 // lives at open time because a tab's profile is fixed then —
1241 // Electron only honours a partition before attach.
1242 if (action.label === "Browser" && action.available) {
1243 return (
1244 <MenuSub key={action.label}>
1245 <MenuSubTrigger
1246 className="[&>svg:last-child]:ms-0"
1247 aria-keyshortcuts={action.shortcut}
1248 onClick={(event) => {
1249 const pointerType =
1250 "pointerType" in event.nativeEvent &&
1251 typeof event.nativeEvent.pointerType === "string"
1252 ? event.nativeEvent.pointerType
1253 : undefined;
1254 // Touch has no hover path to the profile choices:
1255 // its first tap opens the submenu, then a profile
1256 // is selected there. Mouse click keeps the common
1257 // default-profile action at one click.
1258 if (!shouldOpenDefaultBrowserProfileFromMenuClick(pointerType))
1259 return;
1260 setAddSurfaceMenuOpen(false);
1261 action.onClick();
1262 }}
1263 >
1264 <Icon />
1265 {action.label}
1266 <MenuShortcut>{action.shortcut}</MenuShortcut>
1267 </MenuSubTrigger>
1268 {/*
1269 Capped and truncated: profile names are user-supplied
1270 and run to 48 characters, which would otherwise widen
1271 the popup to fit-content and wrap.
1272 */}
1273 <MenuSubPopup className="min-w-40 max-w-56">
1274 {browserProfiles.map((profile) => (
1275 <MenuItem
1276 key={profile.id}
1277 onClick={() => props.onAddBrowserInProfile(profile.id)}
1278 >
1279 <span className="min-w-0 truncate">{profile.name}</span>
1280 </MenuItem>
1281 ))}
1282 </MenuSubPopup>
1283 </MenuSub>
1284 );
1285 }
1286 return (
1287 <SurfaceMenuItem
1288 key={action.label}
1289 available={action.available}
1290 disabledReason={action.disabledReason}
1291 shortcut={action.shortcut}
1292 onClick={action.onClick}
1293 >
1294 <Icon />
1295 {action.label}
1296 </SurfaceMenuItem>
1297 );
1298 })}
1299 </MenuPopup>
1300 </Menu>
1301 ) : null}
1302 </div>
1303 </ScrollArea>
1304 {tabScrollState.hasOverflow ? (
1305 <div
1306 className="flex shrink-0 items-center gap-0.5 [-webkit-app-region:no-drag]"
1307 role="group"
1308 aria-label="Scroll panel tabs"
1309 >
1310 <Tooltip>
1311 <TooltipTrigger
1312 render={
1313 <span className="inline-flex">
1314 <Button
1315 aria-label="Scroll tabs left"
1316 disabled={!tabScrollState.canScrollLeft}
1317 onClick={() => scrollTabs(-1)}
1318 size="icon-xs"
1319 variant="ghost"
1320 >
1321 <ChevronLeft />
1322 </Button>
1323 </span>
1324 }
1325 />
1326 <TooltipPopup>Scroll tabs left</TooltipPopup>
1327 </Tooltip>
1328 <Tooltip>
1329 <TooltipTrigger
1330 render={
1331 <span className="inline-flex">
1332 <Button
1333 aria-label="Scroll tabs right"
1334 disabled={!tabScrollState.canScrollRight}
1335 onClick={() => scrollTabs(1)}
1336 size="icon-xs"
1337 variant="ghost"
1338 >
1339 <ChevronRight />
1340 </Button>
1341 </span>
1342 }
1343 />
1344 <TooltipPopup>Scroll tabs right</TooltipPopup>
1345 </Tooltip>
1346 </div>
1347 ) : null}
1348 {props.layoutControls}
1349 {ownsDesktopTitleBar ? (
1350 <span
1351 aria-hidden
1352 className="pointer-events-none fixed top-[var(--workspace-controls-top)] right-[var(--workspace-controls-right)] h-[var(--workspace-topbar-height)] w-28 [-webkit-app-region:no-drag]"
1353 />
1354 ) : null}
1355 </div>
1356 <div className="flex min-h-0 flex-1 flex-col" data-right-panel-surface-content>
1357 {props.activeSurfaceId === null ? (
1358 <RightPanelEmptyState
1359 onAddBrowser={props.onAddBrowser}
1360 onAddBrowserInProfile={props.onAddBrowserInProfile}
1361 browserProfiles={browserProfiles}
1362 onAddTerminal={props.onAddTerminal}
1363 onAddDiff={props.onAddDiff}
1364 onAddFiles={props.onAddFiles}
1365 onAddPullRequest={props.onAddPullRequest}
1366 onAddPullRequests={props.onAddPullRequests}
1367 onAddDevice={props.onAddDevice}
1368 browserAvailable={props.browserAvailable}
1369 terminalAvailable={props.terminalAvailable}
1370 diffAvailable={props.diffAvailable}
1371 filesAvailable={props.filesAvailable}
1372 pullRequestAvailable={props.pullRequestAvailable}
1373 pullRequestsAvailable={props.pullRequestsAvailable}
1374 deviceAvailable={props.deviceAvailable}
1375 />
1376 ) : (
1377 props.children
1378 )}
1379 </div>
1380 </PreviewPanelShell>
1381 );
1382}