{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "conversation-timeline",
  "title": "Conversation Timeline",
  "author": "AlgorizeTech",
  "description": "A dense rail of thin marks, one per message, that expands into a labelled list on hover — a minimap for long chats. Use it beside a conversation to jump between messages.",
  "dependencies": [],
  "registryDependencies": [
    "utils"
  ],
  "files": [
    {
      "path": "src/components/custom/blocks/ConversationTimelineBlock.tsx",
      "content": "\"use client\";\n\nimport { cn } from \"@/lib/utils\";\nimport { useEffect, useRef, useState, useSyncExternalStore } from \"react\";\n\nconst REDUCED_MOTION = \"(prefers-reduced-motion: reduce)\";\nconst subscribeReducedMotion = (onChange: () => void) => {\n  const mq = window.matchMedia(REDUCED_MOTION);\n  mq.addEventListener(\"change\", onChange);\n  return () => mq.removeEventListener(\"change\", onChange);\n};\n/** The visitor's reduced-motion preference; false while server-rendering. */\nconst useReducedMotion = () =>\n  useSyncExternalStore(\n    subscribeReducedMotion,\n    () => window.matchMedia(REDUCED_MOTION).matches,\n    () => false,\n  );\n\nconst NO_HOVER = \"(hover: none)\";\nconst subscribeNoHover = (onChange: () => void) => {\n  const mq = window.matchMedia(NO_HOVER);\n  mq.addEventListener(\"change\", onChange);\n  return () => mq.removeEventListener(\"change\", onChange);\n};\n/** True on touch-only devices, which have no hover; false while server-rendering. */\nconst useNoHover = () =>\n  useSyncExternalStore(\n    subscribeNoHover,\n    () => window.matchMedia(NO_HOVER).matches,\n    () => false,\n  );\n\nconst TRANSITION_MS = 300;\nconst MARK_WIDTH = 28;\nconst GAP = 12;\n\nexport interface TimelineCheckpoint {\n  id: string;\n  label: string;\n  sublabel?: string;\n  role?: \"user\" | \"assistant\" | \"system\";\n}\n\nexport interface ConversationTimelineProps {\n  /** Read-only, so an `as const` list is accepted as written. */\n  checkpoints: readonly TimelineCheckpoint[];\n  activeId?: string;\n  onSelect?: (id: string) => void;\n  /** Which side the text sits — \"right\" (default) or \"left\". */\n  side?: \"left\" | \"right\";\n  /** Per-row height once expanded (hovering / focusing the rail), in px. Default 24. */\n  rowHeight?: number;\n  /** Per-row height at rest — just the marks, tightly packed. Default 10. */\n  collapsedRowHeight?: number;\n  /** Rows visible before scrolling. Height = visibleCount * rowHeight. Default 10. */\n  visibleCount?: number;\n  /** Fixed label column width (px) — labels truncate past this. Default 240. */\n  labelWidth?: number;\n  /**\n   * Render the label column. Turn it off where width is tight — beside a chat\n   * on a phone — and the rail becomes a marks-only minimap: the messages it\n   * points at already carry the text. Marks keep their `aria-label`. Default true.\n   */\n  showLabels?: boolean;\n  /** Accent colour for the active row's line. Defaults to the theme's primary. */\n  accent?: string;\n  className?: string;\n}\n\n/**\n * A dense rail of thin marks, one per message. Hover or focus expands it into\n * the full labelled list: rows grow to `rowHeight` and labels fade in. The row\n * under the cursor gets extra emphasis on top of that. `visibleCount` rows are\n * shown at once and the rest scroll.\n */\nexport function ConversationTimeline({\n  checkpoints,\n  activeId,\n  onSelect,\n  side = \"right\",\n  rowHeight = 24,\n  collapsedRowHeight = 10,\n  visibleCount = 10,\n  labelWidth = 240,\n  showLabels = true,\n  accent = \"var(--primary)\",\n  className,\n}: ConversationTimelineProps) {\n  const [hoveredId, setHoveredId] = useState<string | null>(null);\n  // Touch has no hover, so stay expanded and keep the labels reachable. The\n  // rail starts expanded there and follows the media query whenever it flips;\n  // adjusted while rendering rather than in an effect.\n  const noHover = useNoHover();\n  const [expanded, setExpanded] = useState(noHover);\n  const [prevNoHover, setPrevNoHover] = useState(noHover);\n  if (noHover !== prevNoHover) {\n    setPrevNoHover(noHover);\n    setExpanded(noHover);\n  }\n  const reduce = useReducedMotion();\n  const isRight = side === \"right\";\n\n  // Rows resize from 10px to 24px while scrolled, so the same scrollTop would\n  // point at a different row. Anchor to the row element at the top and read\n  // its live `offsetTop` instead of computing one from an assumed row height,\n  // which would fight the in-progress transition.\n  const containerRef = useRef<HTMLDivElement>(null);\n  const rowRefs = useRef<(HTMLButtonElement | null)[]>([]);\n  const anchorIndexRef = useRef(0);\n  const captureScrollAnchor = () => {\n    const el = containerRef.current;\n    if (!el) return;\n    const idx = rowRefs.current.findIndex(\n      (row) => row && row.offsetTop + row.offsetHeight > el.scrollTop,\n    );\n    anchorIndexRef.current = idx < 0 ? 0 : idx;\n  };\n  useEffect(() => {\n    const el = containerRef.current;\n    const anchor = rowRefs.current[anchorIndexRef.current];\n    if (!el || !anchor) return;\n    const apply = () => {\n      el.scrollTop = anchor.offsetTop;\n    };\n    apply();\n    if (reduce) return;\n    // Re-applied every frame for the transition's duration. The anchor's\n    // offsetTop moves a little each frame, so re-reading it keeps the view\n    // tracking rather than jumping once at the end.\n    let raf = 0;\n    const deadline = performance.now() + TRANSITION_MS + 50;\n    const tick = () => {\n      apply();\n      if (performance.now() < deadline) raf = requestAnimationFrame(tick);\n    };\n    raf = requestAnimationFrame(tick);\n    return () => cancelAnimationFrame(raf);\n    // eslint-disable-next-line react-hooks/exhaustive-deps\n  }, [expanded]);\n\n  // Height is the only animated dimension. Gap and width stay fixed so the\n  // rail never resizes horizontally and only one property drives layout.\n  const transition = reduce\n    ? \"none\"\n    : `height ${TRANSITION_MS}ms var(--ease-smooth, cubic-bezier(0.4, 0, 0.2, 1))`;\n  // +4px absorbs the hover nudge's translateX so it never clips against the\n  // rail's own overflow-x boundary.\n  const railWidth = MARK_WIDTH + 4 + (showLabels ? GAP + labelWidth : 0);\n  // With the scrollbar hidden there's no native cue that a taller list\n  // continues past view — fade the top/bottom edges as the affordance, but\n  // only when there's actually more to scroll to.\n  const isScrollable = checkpoints.length > visibleCount;\n  const edgeFade = isScrollable\n    ? \"linear-gradient(to bottom, transparent, black 12px, black calc(100% - 12px), transparent)\"\n    : undefined;\n\n  return (\n    <div\n      ref={containerRef}\n      className={cn(\n        \"[scrollbar-width:none] [&::-webkit-scrollbar]:hidden [&::-webkit-scrollbar]:w-0 [&::-webkit-scrollbar]:h-0 relative flex flex-col overflow-y-auto overflow-x-hidden\",\n        className,\n      )}\n      style={{\n        width: railWidth,\n        maxHeight: visibleCount * (expanded ? rowHeight : collapsedRowHeight),\n        transition,\n        // Native scroll anchoring doesn't handle this case (every row resizes\n        // at once) and otherwise fights our own re-anchoring above.\n        overflowAnchor: \"none\",\n        WebkitMaskImage: edgeFade,\n        maskImage: edgeFade,\n      }}\n      onMouseEnter={() => {\n        captureScrollAnchor();\n        setExpanded(true);\n      }}\n      onMouseLeave={() => {\n        captureScrollAnchor();\n        setExpanded(false);\n        setHoveredId(null);\n      }}\n      onFocus={() => {\n        captureScrollAnchor();\n        setExpanded(true);\n      }}\n      onBlur={(e) => {\n        if (!e.currentTarget.contains(e.relatedTarget)) {\n          captureScrollAnchor();\n          setExpanded(false);\n        }\n      }}\n    >\n      {checkpoints.map((cp, i) => {\n        const isActive = cp.id === activeId;\n        const isHovered = cp.id === hoveredId;\n\n        return (\n          <button\n            key={cp.id}\n            ref={(el) => {\n              rowRefs.current[i] = el;\n            }}\n            type=\"button\"\n            onMouseEnter={() => setHoveredId(cp.id)}\n            onMouseLeave={() => setHoveredId(null)}\n            onClick={() => onSelect?.(cp.id)}\n            aria-label={cp.label}\n            aria-current={isActive || undefined}\n            className={cn(\n              \"group flex items-center outline-none cursor-pointer shrink-0 active:scale-[0.96] transition-transform\",\n              \"focus-visible:outline-2 focus-visible:outline-offset-2\",\n              \"focus-visible:outline-ring\",\n              isRight ? \"flex-row\" : \"flex-row-reverse\",\n            )}\n            style={{\n              height: expanded ? rowHeight : collapsedRowHeight,\n              gap: GAP,\n              transition,\n            }}\n          >\n            {/* the mark — fixed length, never moves. Standout comes from\n                colour and opacity, not width, so the line stays put on hover. */}\n            <span\n              className=\"shrink-0 rounded-full transition-[opacity,background-color] duration-150 ease-out\"\n              style={{\n                height: 2,\n                width: MARK_WIDTH,\n                background: isActive ? accent : \"currentColor\",\n                opacity: isActive ? 1 : isHovered ? 0.8 : 0.28,\n              }}\n            />\n\n            {/* the label — invisible at rest (the collapsed row has no room\n                for it anyway), fades in once the rail expands. Font-weight\n                stays constant (active = medium, rest = normal) so it never\n                changes layout width; hover emphasis is colour + a\n                post-layout transform only, so it can never nudge the marks. */}\n            {showLabels && (\n              <span\n                className={cn(\n                  \"min-w-0 whitespace-nowrap tracking-[-0.01em] truncate\",\n                  isRight ? \"text-left origin-left\" : \"text-right origin-right\",\n                  isActive ? \"font-medium\" : \"font-normal\",\n                  isHovered\n                    ? \"text-foreground\"\n                    : isActive\n                      ? \"text-foreground/90\"\n                      : \"text-muted-foreground\",\n                )}\n                style={{\n                  width: labelWidth,\n                  fontSize: 13,\n                  opacity: expanded ? 1 : 0,\n                  // Nudge only — no scale. Scaling a truncated, fixed-width,\n                  // edge-clipped label grows its rendered footprint past the\n                  // rail's own clip boundary and cuts off the ellipsis itself.\n                  transform: `translateX(${isHovered ? (isRight ? 3 : -3) : 0}px)`,\n                  // Opacity rides the same pace as the row's expand/collapse\n                  // (it's part of that motion); colour and the hover nudge are\n                  // a separate, snappier per-row response — one shared\n                  // duration for both made the hover feel sluggish.\n                  transition: reduce\n                    ? \"none\"\n                    : `opacity ${TRANSITION_MS}ms var(--ease-smooth, cubic-bezier(0.4, 0, 0.2, 1)), color 150ms ease-out, transform 150ms ease-out`,\n                }}\n              >\n                {cp.label}\n              </span>\n            )}\n          </button>\n        );\n      })}\n    </div>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/custom/blocks/ConversationTimelineBlock.tsx"
    }
  ],
  "docs": "Named export: ConversationTimeline (plus the TimelineCheckpoint type). `checkpoints` is `{ id, label, sublabel?, role? }[]`, `activeId` marks the selected row with `accent` and `onSelect` receives a clicked id. `side` puts labels left or right; `rowHeight` / `collapsedRowHeight` set the expanded and resting row sizes, `visibleCount` caps rows before scrolling and `labelWidth` fixes the label column. Hover or focus expands it; touch devices stay expanded; respects prefers-reduced-motion.",
  "categories": [
    "navigation",
    "communication"
  ],
  "type": "registry:component"
}
