@devries-cameron20 / t3code Mirror · read-only / commits / 76e4aac3e9
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 22, 20:45 UTC

refactor(web): the timeline minimap lives in its own file (#22662)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Julius Marminge committed Oct 21, 2026 at 01:12 UTC 76e4aac3e9b90ae2395bb62fa540e90b43bd70a6
2 files changed +337 -333
apps/web/src/components/chat/MessagesTimeline.tsx
+2 -333
@@ -16,11 +16,7 @@ import {
16 getQuestionTextPreview,
17 hasQuestionAnswer,
18 } from "@t3tools/client-runtime/work-log/user-input";
19 -import {
20 - deriveTimelineMinimapItems,
21 - resolveTimelineMinimapPreview,
22 - type TimelineMinimapItem,
23 -} from "./timelineMinimapItems";
19 +import { deriveTimelineMinimapItems } from "./timelineMinimapItems";
20 import {
21 COMPOSER_CONTEXT_KINDS,
22 ORCHESTRATION_V2_WORKSPACE_PREPARATION_FAILURE_CODE,
@@ -127,7 +123,6 @@ import {
123 CheckIcon,
124 ChevronDownIcon,
125 ChevronRightIcon,
130 - ChevronUpIcon,
126 CircleAlertIcon,
127 DownloadIcon,
128 EyeIcon,
@@ -210,12 +205,7 @@ import {
205 resolveTimelineMinimapCurrentIndex,
206 isTimelineMinimapRowVisible,
207 resolveTimelineMinimapVisibleRange,
213 - resolveTimelineMinimapHeightStyle,
208 resolveTimelineMinimapHitStripWidth,
215 - resolveTimelineMinimapIndexFromPointer,
216 - resolveTimelineMinimapInteractiveWidth,
217 - resolveTimelineMinimapNavigationInteractive,
218 - resolveTimelineMinimapTopPercent,
209 resolveWorkGroupScrollIndex,
210 shouldCollapseUserMessage,
211 shouldFollowWorkGroupAppend,
@@ -230,7 +220,6 @@ import {
220 worktreeSetupAgentStarted,
221 type StableMessagesTimelineRowsState,
222 type MessagesTimelineRow,
233 - TIMELINE_MINIMAP_MIN_ITEMS,
223 type TimelineLatestRun,
224 type WorkGroupScrollAnchor,
225 } from "./MessagesTimeline.logic";
@@ -309,6 +298,7 @@ import {
298 formatReviewCommentFence,
299 type ReviewCommentContext,
300 } from "../../reviewCommentContext";
301 +import { TimelineMinimap } from "./TimelineMinimap";
302
303 interface TimelineRowSharedState {
304 citationRequest: AssistantCitationTarget | null;
@@ -1630,327 +1620,6 @@ function getItemType(item: MessagesTimelineRow) {
1620 return `message:${item.message.role}:${lengthBucket}`;
1621 }
1622
1633 -function timelineMinimapEventTargetsPreview(target: EventTarget): boolean {
1634 - return target instanceof Element && target.closest("[data-minimap-preview]") !== null;
1635 -}
1636 -
1637 -// A release outside the window can skip `mouseup`, so the next button-free
1638 -// `mousemove` also counts.
1639 -function onMouseButtonsReleased(onRelease: () => void): () => void {
1640 - const check = (event: globalThis.MouseEvent) => {
1641 - if (event.buttons !== 0) return;
1642 - stop();
1643 - onRelease();
1644 - };
1645 - const stop = () => {
1646 - window.removeEventListener("mouseup", check);
1647 - window.removeEventListener("mousemove", check);
1648 - };
1649 - window.addEventListener("mouseup", check);
1650 - window.addEventListener("mousemove", check);
1651 - return stop;
1652 -}
1653 -
1654 -function TimelineMinimap({
1655 - hasPersistentGutter,
1656 - hitStripWidth,
1657 - currentIndex,
1658 - items,
1659 - stripMap,
1660 - onWheel,
1661 - onSelect,
1662 -}: {
1663 - hasPersistentGutter: boolean;
1664 - hitStripWidth: number;
1665 - currentIndex: number | null;
1666 - items: ReadonlyArray<TimelineMinimapItem>;
1667 - stripMap: Map<string, HTMLSpanElement>;
1668 - onWheel: (event: WheelEvent) => void;
1669 - onSelect: (item: TimelineMinimapItem) => void;
1670 -}) {
1671 - const [activeIndex, setActiveIndex] = useState<number | null>(null);
1672 - const wheelTargetRef = (node: HTMLDivElement | null) => {
1673 - if (!node) return;
1674 - node.addEventListener("wheel", onWheel, { passive: false });
1675 - return () => node.removeEventListener("wheel", onWheel);
1676 - };
1677 -
1678 - const pressedOnStripRef = useRef(false);
1679 - const [passThrough, setPassThrough] = useState(false);
1680 -
1681 - useEffect(() => {
1682 - if (!passThrough) return;
1683 - return onMouseButtonsReleased(() => setPassThrough(false));
1684 - }, [passThrough]);
1685 -
1686 - const resolvedActiveIndex =
1687 - activeIndex !== null && activeIndex < items.length ? activeIndex : null;
1688 - const activeItem = resolveTimelineMinimapPreview(
1689 - resolvedActiveIndex === null ? null : (items[resolvedActiveIndex] ?? null),
1690 - );
1691 - const navigationInteractive =
1692 - resolveTimelineMinimapNavigationInteractive(hitStripWidth) && !passThrough;
1693 - const activeTopPercent =
1694 - resolvedActiveIndex === null
1695 - ? 0
1696 - : resolveTimelineMinimapTopPercent(resolvedActiveIndex, items.length);
1697 - const activeTooltipTranslate =
1698 - resolvedActiveIndex === null
1699 - ? "-50%"
1700 - : resolvedActiveIndex === 0
1701 - ? "0%"
1702 - : resolvedActiveIndex === items.length - 1
1703 - ? "-100%"
1704 - : "-50%";
1705 - const resolvedCurrentIndex =
1706 - currentIndex !== null && currentIndex >= 0 && currentIndex < items.length ? currentIndex : null;
1707 - const previousItem =
1708 - resolvedCurrentIndex === null ? null : (items[resolvedCurrentIndex - 1] ?? null);
1709 - const nextItem = resolvedCurrentIndex === null ? null : (items[resolvedCurrentIndex + 1] ?? null);
1710 -
1711 - const resolveActiveIndexFromPointer = (event: MouseEvent<HTMLElement>) => {
1712 - const rect = event.currentTarget.getBoundingClientRect();
1713 - return resolveTimelineMinimapIndexFromPointer({
1714 - itemCount: items.length,
1715 - railTop: rect.top,
1716 - railHeight: rect.height,
1717 - pointerY: event.clientY,
1718 - });
1719 - };
1720 -
1721 - const updateActiveIndexFromPointer = (event: MouseEvent<HTMLElement>) => {
1722 - const nextIndex = resolveActiveIndexFromPointer(event);
1723 - setActiveIndex(nextIndex);
1724 - };
1725 -
1726 - const moveActiveIndex = (delta: number) => {
1727 - setActiveIndex((current) => {
1728 - const base = current ?? 0;
1729 - return Math.max(0, Math.min(items.length - 1, base + delta));
1730 - });
1731 - };
1732 -
1733 - if (items.length < TIMELINE_MINIMAP_MIN_ITEMS) {
1734 - return null;
1735 - }
1736 -
1737 - return (
1738 - <div
1739 - className={cn(
1740 - "group/minimap pointer-events-none absolute inset-y-0 left-0 z-40 hidden w-18 [@media(pointer:fine)]:block",
1741 - hasPersistentGutter
1742 - ? "opacity-100"
1743 - : "opacity-0 transition-opacity duration-150 hover:opacity-100 focus-within:opacity-100",
1744 - )}
1745 - data-testid="timeline-minimap"
1746 - data-persistent-gutter={hasPersistentGutter ? "true" : "false"}
1747 - ref={wheelTargetRef}
1748 - >
1749 - <div className="relative h-full w-full select-none">
1750 - <div
1751 - className={cn(
1752 - "absolute top-1/2 left-3 -translate-y-1/2",
1753 - hitStripWidth > 0 && !passThrough ? "pointer-events-auto" : "pointer-events-none",
1754 - )}
1755 - onMouseDown={() => {
1756 - if (pressedOnStripRef.current) return;
1757 - pressedOnStripRef.current = true;
1758 - onMouseButtonsReleased(() => {
1759 - pressedOnStripRef.current = false;
1760 - });
1761 - }}
1762 - onMouseMove={(event) => {
1763 - if (event.buttons !== 0 && !pressedOnStripRef.current) setPassThrough(true);
1764 - }}
1765 - style={{
1766 - height: resolveTimelineMinimapHeightStyle(items.length),
1767 - width: resolveTimelineMinimapInteractiveWidth(hitStripWidth, activeItem !== null),
1768 - }}
1769 - >
1770 - <TimelineMinimapNavigationButton
1771 - direction="previous"
1772 - disabled={previousItem === null}
1773 - interactive={navigationInteractive}
1774 - onClick={() => {
1775 - if (previousItem) onSelect(previousItem);
1776 - }}
1777 - />
1778 - <button
1779 - aria-label={`Jump to message: ${activeItem?.userText ?? "User message"}`}
1780 - className="absolute inset-y-0 left-0 w-full cursor-pointer bg-transparent focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring/70"
1781 - onBlur={() => setActiveIndex(null)}
1782 - onClick={(event) => {
1783 - if (timelineMinimapEventTargetsPreview(event.target)) {
1784 - return;
1785 - }
1786 - const nextIndex = resolveActiveIndexFromPointer(event);
1787 - const selectedItem = nextIndex === null ? null : (items[nextIndex] ?? null);
1788 - if (selectedItem) {
1789 - onSelect(selectedItem);
1790 - }
1791 - event.currentTarget.blur();
1792 - }}
1793 - onFocus={() => setActiveIndex((current) => current ?? resolvedCurrentIndex ?? 0)}
1794 - onKeyDown={(event) => {
1795 - if (event.key === "ArrowDown") {
1796 - event.preventDefault();
1797 - moveActiveIndex(1);
1798 - } else if (event.key === "ArrowUp") {
1799 - event.preventDefault();
1800 - moveActiveIndex(-1);
1801 - } else if (event.key === "Home") {
1802 - event.preventDefault();
1803 - setActiveIndex(0);
1804 - } else if (event.key === "End") {
1805 - event.preventDefault();
1806 - setActiveIndex(items.length - 1);
1807 - } else if (event.key === "Enter" || event.key === " ") {
1808 - event.preventDefault();
1809 - if (activeItem) {
1810 - onSelect(activeItem);
1811 - }
1812 - }
1813 - }}
1814 - onMouseLeave={() => setActiveIndex(null)}
1815 - onMouseMove={(event) => {
1816 - if (event.buttons !== 0 && !pressedOnStripRef.current) return;
1817 - updateActiveIndexFromPointer(event);
1818 - }}
1819 - onMouseDown={(event) => {
1820 - if (timelineMinimapEventTargetsPreview(event.target)) {
1821 - return;
1822 - }
1823 - event.preventDefault();
1824 - }}
1825 - type="button"
1826 - >
1827 - <div className="absolute top-0 left-3 h-full w-px bg-border/15" />
1828 - {items.map((item, index) => {
1829 - const top = `${resolveTimelineMinimapTopPercent(index, items.length)}%`;
1830 - const activeDistance =
1831 - resolvedActiveIndex === null ? null : Math.abs(index - resolvedActiveIndex);
1832 - return (
1833 - // Compositor-friendly on purpose: in-view state and the hover
1834 - // fisheye animate constantly (every scroll tick and streaming
1835 - // update flips a band of strips), so the strip animates only
1836 - // transform and opacity.
1837 - <span
1838 - aria-hidden="true"
1839 - className={cn(
1840 - "group/strip pointer-events-none absolute left-0 h-0.5 w-6 origin-left -translate-y-1/2 rounded-full transition-transform duration-150",
1841 - activeDistance === 0 ? "bg-muted-foreground/75" : "bg-muted-foreground/35",
1842 - activeDistance === 0
1843 - ? "scale-x-100"
1844 - : activeDistance === 1
1845 - ? "scale-x-[0.667]"
1846 - : activeDistance === 2
1847 - ? "scale-x-[0.417]"
1848 - : "scale-x-[0.333]",
1849 - )}
1850 - data-in-view="false"
1851 - data-minimap-strip
1852 - key={item.id}
1853 - ref={(node) => {
1854 - if (node) {
1855 - stripMap.set(item.id, node);
1856 - } else {
1857 - stripMap.delete(item.id);
1858 - }
1859 - }}
1860 - style={{ top }}
1861 - >
1862 - <span className="absolute inset-0 rounded-full bg-foreground/90 opacity-0 transition-opacity duration-150 group-data-[in-view=true]/strip:opacity-100" />
1863 - </span>
1864 - );
1865 - })}
1866 - {activeItem ? (
1867 - <span
1868 - className="pointer-events-auto absolute left-8 w-80 cursor-text select-text"
1869 - data-minimap-preview
1870 - onMouseMove={(event) => event.stopPropagation()}
1871 - style={{
1872 - top: `${activeTopPercent}%`,
1873 - transform: `translateY(${activeTooltipTranslate})`,
1874 - }}
1875 - >
1876 - <span className="dropdown-glass block rounded-xl p-3 text-left text-popover-foreground shadow-xl shadow-black/25">
1877 - <span className="block max-w-full overflow-hidden text-ellipsis whitespace-nowrap text-sm font-medium leading-5">
1878 - {activeItem.userText ?? "User message"}
1879 - </span>
1880 - {activeItem.assistantText ? (
1881 - <span
1882 - className="mt-1 max-h-[3.75rem] overflow-hidden text-muted-foreground text-sm leading-5"
1883 - style={{
1884 - display: "-webkit-box",
1885 - WebkitBoxOrient: "vertical",
1886 - WebkitLineClamp: 3,
1887 - }}
1888 - >
1889 - {activeItem.assistantText}
1890 - </span>
1891 - ) : null}
1892 - </span>
1893 - </span>
1894 - ) : null}
1895 - </button>
1896 - <TimelineMinimapNavigationButton
1897 - direction="next"
1898 - disabled={nextItem === null}
1899 - interactive={navigationInteractive}
1900 - onClick={() => {
1901 - if (nextItem) onSelect(nextItem);
1902 - }}
1903 - />
1904 - </div>
1905 - </div>
1906 - </div>
1907 - );
1908 -}
1909 -
1910 -function TimelineMinimapNavigationButton({
1911 - direction,
1912 - disabled,
1913 - interactive,
1914 - onClick,
1915 -}: {
1916 - direction: "previous" | "next";
1917 - disabled: boolean;
1918 - interactive: boolean;
1919 - onClick: () => void;
1920 -}) {
1921 - const previous = direction === "previous";
1922 - const label = previous ? "Previous turn" : "Next turn";
1923 - const Icon = previous ? ChevronUpIcon : ChevronDownIcon;
1924 -
1925 - return (
1926 - <Tooltip>
1927 - <TooltipTrigger
1928 - render={
1929 - <span
1930 - className={cn(
1931 - "absolute left-1 z-10 inline-flex -translate-x-1/2 opacity-0 transition-opacity duration-150 hover:opacity-100 focus-within:opacity-100",
1932 - interactive ? "pointer-events-auto" : "pointer-events-none",
1933 - previous ? "bottom-[calc(100%+2px)]" : "top-[calc(100%+2px)]",
1934 - )}
1935 - />
1936 - }
1937 - >
1938 - <Button
1939 - aria-label={label}
1940 - disabled={disabled}
1941 - onClick={onClick}
1942 - size="icon-micro"
1943 - type="button"
1944 - variant="ghost-muted"
1945 - >
1946 - <Icon className="size-4 text-foreground/90" />
1947 - </Button>
1948 - </TooltipTrigger>
1949 - <TooltipPopup side={previous ? "top" : "bottom"}>{label}</TooltipPopup>
1950 - </Tooltip>
1951 - );
1952 -}
1953 -
1623 type TimelineWorkEntry = Extract<MessagesTimelineRow, { kind: "work" }>["groupedEntries"][number];
1624 type TimelineRow = MessagesTimelineRow;
1625
apps/web/src/components/chat/TimelineMinimap.tsx new
+335
@@ -0,0 +1,335 @@
1 +import { resolveTimelineMinimapPreview, type TimelineMinimapItem } from "./timelineMinimapItems";
2 +import { useEffect, useRef, useState, type MouseEvent } from "react";
3 +import { ChevronDownIcon, ChevronUpIcon } from "lucide-react";
4 +import { Button } from "../ui/button";
5 +import {
6 + resolveTimelineMinimapHeightStyle,
7 + resolveTimelineMinimapIndexFromPointer,
8 + resolveTimelineMinimapInteractiveWidth,
9 + resolveTimelineMinimapNavigationInteractive,
10 + resolveTimelineMinimapTopPercent,
11 + TIMELINE_MINIMAP_MIN_ITEMS,
12 +} from "./MessagesTimeline.logic";
13 +import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip";
14 +import { cn } from "~/lib/utils";
15 +
16 +function timelineMinimapEventTargetsPreview(target: EventTarget): boolean {
17 + return target instanceof Element && target.closest("[data-minimap-preview]") !== null;
18 +}
19 +
20 +// A release outside the window can skip `mouseup`, so the next button-free
21 +// `mousemove` also counts.
22 +function onMouseButtonsReleased(onRelease: () => void): () => void {
23 + const check = (event: globalThis.MouseEvent) => {
24 + if (event.buttons !== 0) return;
25 + stop();
26 + onRelease();
27 + };
28 + const stop = () => {
29 + window.removeEventListener("mouseup", check);
30 + window.removeEventListener("mousemove", check);
31 + };
32 + window.addEventListener("mouseup", check);
33 + window.addEventListener("mousemove", check);
34 + return stop;
35 +}
36 +
37 +export function TimelineMinimap({
38 + hasPersistentGutter,
39 + hitStripWidth,
40 + currentIndex,
41 + items,
42 + stripMap,
43 + onWheel,
44 + onSelect,
45 +}: {
46 + hasPersistentGutter: boolean;
47 + hitStripWidth: number;
48 + currentIndex: number | null;
49 + items: ReadonlyArray<TimelineMinimapItem>;
50 + stripMap: Map<string, HTMLSpanElement>;
51 + onWheel: (event: WheelEvent) => void;
52 + onSelect: (item: TimelineMinimapItem) => void;
53 +}) {
54 + const [activeIndex, setActiveIndex] = useState<number | null>(null);
55 + const wheelTargetRef = (node: HTMLDivElement | null) => {
56 + if (!node) return;
57 + node.addEventListener("wheel", onWheel, { passive: false });
58 + return () => node.removeEventListener("wheel", onWheel);
59 + };
60 +
61 + const pressedOnStripRef = useRef(false);
62 + const [passThrough, setPassThrough] = useState(false);
63 +
64 + useEffect(() => {
65 + if (!passThrough) return;
66 + return onMouseButtonsReleased(() => setPassThrough(false));
67 + }, [passThrough]);
68 +
69 + const resolvedActiveIndex =
70 + activeIndex !== null && activeIndex < items.length ? activeIndex : null;
71 + const activeItem = resolveTimelineMinimapPreview(
72 + resolvedActiveIndex === null ? null : (items[resolvedActiveIndex] ?? null),
73 + );
74 + const navigationInteractive =
75 + resolveTimelineMinimapNavigationInteractive(hitStripWidth) && !passThrough;
76 + const activeTopPercent =
77 + resolvedActiveIndex === null
78 + ? 0
79 + : resolveTimelineMinimapTopPercent(resolvedActiveIndex, items.length);
80 + const activeTooltipTranslate =
81 + resolvedActiveIndex === null
82 + ? "-50%"
83 + : resolvedActiveIndex === 0
84 + ? "0%"
85 + : resolvedActiveIndex === items.length - 1
86 + ? "-100%"
87 + : "-50%";
88 + const resolvedCurrentIndex =
89 + currentIndex !== null && currentIndex >= 0 && currentIndex < items.length ? currentIndex : null;
90 + const previousItem =
91 + resolvedCurrentIndex === null ? null : (items[resolvedCurrentIndex - 1] ?? null);
92 + const nextItem = resolvedCurrentIndex === null ? null : (items[resolvedCurrentIndex + 1] ?? null);
93 +
94 + const resolveActiveIndexFromPointer = (event: MouseEvent<HTMLElement>) => {
95 + const rect = event.currentTarget.getBoundingClientRect();
96 + return resolveTimelineMinimapIndexFromPointer({
97 + itemCount: items.length,
98 + railTop: rect.top,
99 + railHeight: rect.height,
100 + pointerY: event.clientY,
101 + });
102 + };
103 +
104 + const updateActiveIndexFromPointer = (event: MouseEvent<HTMLElement>) => {
105 + const nextIndex = resolveActiveIndexFromPointer(event);
106 + setActiveIndex(nextIndex);
107 + };
108 +
109 + const moveActiveIndex = (delta: number) => {
110 + setActiveIndex((current) => {
111 + const base = current ?? 0;
112 + return Math.max(0, Math.min(items.length - 1, base + delta));
113 + });
114 + };
115 +
116 + if (items.length < TIMELINE_MINIMAP_MIN_ITEMS) {
117 + return null;
118 + }
119 +
120 + return (
121 + <div
122 + className={cn(
123 + "group/minimap pointer-events-none absolute inset-y-0 left-0 z-40 hidden w-18 [@media(pointer:fine)]:block",
124 + hasPersistentGutter
125 + ? "opacity-100"
126 + : "opacity-0 transition-opacity duration-150 hover:opacity-100 focus-within:opacity-100",
127 + )}
128 + data-testid="timeline-minimap"
129 + data-persistent-gutter={hasPersistentGutter ? "true" : "false"}
130 + ref={wheelTargetRef}
131 + >
132 + <div className="relative h-full w-full select-none">
133 + <div
134 + className={cn(
135 + "absolute top-1/2 left-3 -translate-y-1/2",
136 + hitStripWidth > 0 && !passThrough ? "pointer-events-auto" : "pointer-events-none",
137 + )}
138 + onMouseDown={() => {
139 + if (pressedOnStripRef.current) return;
140 + pressedOnStripRef.current = true;
141 + onMouseButtonsReleased(() => {
142 + pressedOnStripRef.current = false;
143 + });
144 + }}
145 + onMouseMove={(event) => {
146 + if (event.buttons !== 0 && !pressedOnStripRef.current) setPassThrough(true);
147 + }}
148 + style={{
149 + height: resolveTimelineMinimapHeightStyle(items.length),
150 + width: resolveTimelineMinimapInteractiveWidth(hitStripWidth, activeItem !== null),
151 + }}
152 + >
153 + <TimelineMinimapNavigationButton
154 + direction="previous"
155 + disabled={previousItem === null}
156 + interactive={navigationInteractive}
157 + onClick={() => {
158 + if (previousItem) onSelect(previousItem);
159 + }}
160 + />
161 + <button
162 + aria-label={`Jump to message: ${activeItem?.userText ?? "User message"}`}
163 + className="absolute inset-y-0 left-0 w-full cursor-pointer bg-transparent focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring/70"
164 + onBlur={() => setActiveIndex(null)}
165 + onClick={(event) => {
166 + if (timelineMinimapEventTargetsPreview(event.target)) {
167 + return;
168 + }
169 + const nextIndex = resolveActiveIndexFromPointer(event);
170 + const selectedItem = nextIndex === null ? null : (items[nextIndex] ?? null);
171 + if (selectedItem) {
172 + onSelect(selectedItem);
173 + }
174 + event.currentTarget.blur();
175 + }}
176 + onFocus={() => setActiveIndex((current) => current ?? resolvedCurrentIndex ?? 0)}
177 + onKeyDown={(event) => {
178 + if (event.key === "ArrowDown") {
179 + event.preventDefault();
180 + moveActiveIndex(1);
181 + } else if (event.key === "ArrowUp") {
182 + event.preventDefault();
183 + moveActiveIndex(-1);
184 + } else if (event.key === "Home") {
185 + event.preventDefault();
186 + setActiveIndex(0);
187 + } else if (event.key === "End") {
188 + event.preventDefault();
189 + setActiveIndex(items.length - 1);
190 + } else if (event.key === "Enter" || event.key === " ") {
191 + event.preventDefault();
192 + if (activeItem) {
193 + onSelect(activeItem);
194 + }
195 + }
196 + }}
197 + onMouseLeave={() => setActiveIndex(null)}
198 + onMouseMove={(event) => {
199 + if (event.buttons !== 0 && !pressedOnStripRef.current) return;
200 + updateActiveIndexFromPointer(event);
201 + }}
202 + onMouseDown={(event) => {
203 + if (timelineMinimapEventTargetsPreview(event.target)) {
204 + return;
205 + }
206 + event.preventDefault();
207 + }}
208 + type="button"
209 + >
210 + <div className="absolute top-0 left-3 h-full w-px bg-border/15" />
211 + {items.map((item, index) => {
212 + const top = `${resolveTimelineMinimapTopPercent(index, items.length)}%`;
213 + const activeDistance =
214 + resolvedActiveIndex === null ? null : Math.abs(index - resolvedActiveIndex);
215 + return (
216 + // Compositor-friendly on purpose: in-view state and the hover
217 + // fisheye animate constantly (every scroll tick and streaming
218 + // update flips a band of strips), so the strip animates only
219 + // transform and opacity.
220 + <span
221 + aria-hidden="true"
222 + className={cn(
223 + "group/strip pointer-events-none absolute left-0 h-0.5 w-6 origin-left -translate-y-1/2 rounded-full transition-transform duration-150",
224 + activeDistance === 0 ? "bg-muted-foreground/75" : "bg-muted-foreground/35",
225 + activeDistance === 0
226 + ? "scale-x-100"
227 + : activeDistance === 1
228 + ? "scale-x-[0.667]"
229 + : activeDistance === 2
230 + ? "scale-x-[0.417]"
231 + : "scale-x-[0.333]",
232 + )}
233 + data-in-view="false"
234 + data-minimap-strip
235 + key={item.id}
236 + ref={(node) => {
237 + if (node) {
238 + stripMap.set(item.id, node);
239 + } else {
240 + stripMap.delete(item.id);
241 + }
242 + }}
243 + style={{ top }}
244 + >
245 + <span className="absolute inset-0 rounded-full bg-foreground/90 opacity-0 transition-opacity duration-150 group-data-[in-view=true]/strip:opacity-100" />
246 + </span>
247 + );
248 + })}
249 + {activeItem ? (
250 + <span
251 + className="pointer-events-auto absolute left-8 w-80 cursor-text select-text"
252 + data-minimap-preview
253 + onMouseMove={(event) => event.stopPropagation()}
254 + style={{
255 + top: `${activeTopPercent}%`,
256 + transform: `translateY(${activeTooltipTranslate})`,
257 + }}
258 + >
259 + <span className="dropdown-glass block rounded-xl p-3 text-left text-popover-foreground shadow-xl shadow-black/25">
260 + <span className="block max-w-full overflow-hidden text-ellipsis whitespace-nowrap text-sm font-medium leading-5">
261 + {activeItem.userText ?? "User message"}
262 + </span>
263 + {activeItem.assistantText ? (
264 + <span
265 + className="mt-1 max-h-[3.75rem] overflow-hidden text-muted-foreground text-sm leading-5"
266 + style={{
267 + display: "-webkit-box",
268 + WebkitBoxOrient: "vertical",
269 + WebkitLineClamp: 3,
270 + }}
271 + >
272 + {activeItem.assistantText}
273 + </span>
274 + ) : null}
275 + </span>
276 + </span>
277 + ) : null}
278 + </button>
279 + <TimelineMinimapNavigationButton
280 + direction="next"
281 + disabled={nextItem === null}
282 + interactive={navigationInteractive}
283 + onClick={() => {
284 + if (nextItem) onSelect(nextItem);
285 + }}
286 + />
287 + </div>
288 + </div>
289 + </div>
290 + );
291 +}
292 +
293 +function TimelineMinimapNavigationButton({
294 + direction,
295 + disabled,
296 + interactive,
297 + onClick,
298 +}: {
299 + direction: "previous" | "next";
300 + disabled: boolean;
301 + interactive: boolean;
302 + onClick: () => void;
303 +}) {
304 + const previous = direction === "previous";
305 + const label = previous ? "Previous turn" : "Next turn";
306 + const Icon = previous ? ChevronUpIcon : ChevronDownIcon;
307 +
308 + return (
309 + <Tooltip>
310 + <TooltipTrigger
311 + render={
312 + <span
313 + className={cn(
314 + "absolute left-1 z-10 inline-flex -translate-x-1/2 opacity-0 transition-opacity duration-150 hover:opacity-100 focus-within:opacity-100",
315 + interactive ? "pointer-events-auto" : "pointer-events-none",
316 + previous ? "bottom-[calc(100%+2px)]" : "top-[calc(100%+2px)]",
317 + )}
318 + />
319 + }
320 + >
321 + <Button
322 + aria-label={label}
323 + disabled={disabled}
324 + onClick={onClick}
325 + size="icon-micro"
326 + type="button"
327 + variant="ghost-muted"
328 + >
329 + <Icon className="size-4 text-foreground/90" />
330 + </Button>
331 + </TooltipTrigger>
332 + <TooltipPopup side={previous ? "top" : "bottom"}>{label}</TooltipPopup>
333 + </Tooltip>
334 + );
335 +}