{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "chat-minimap",
  "title": "Chat Minimap",
  "description": "A rail of lines that maps a conversation, built on shadcn Button, Card, HoverCard and Tooltip.",
  "dependencies": [
    "cn"
  ],
  "registryDependencies": [
    "button",
    "card",
    "hover-card",
    "tooltip"
  ],
  "files": [
    {
      "path": "registry/notra/chat-minimap/components/chat-minimap.tsx",
      "content": "\"use client\";\n\nimport { cn } from \"cn\";\nimport { createContext, use } from \"react\";\n\nimport { Button } from \"@/components/ui/button\";\nimport {\n  Card,\n  CardDescription,\n  CardHeader,\n  CardTitle,\n} from \"@/components/ui/card\";\nimport {\n  HoverCard,\n  HoverCardContent,\n  HoverCardTrigger,\n} from \"@/components/ui/hover-card\";\nimport {\n  Tooltip,\n  TooltipContent,\n  TooltipTrigger,\n} from \"@/components/ui/tooltip\";\n\nimport { isChatMinimapPayload } from \"../lib/chat-minimap\";\nimport type {\n  ChatMinimapItemProps,\n  ChatMinimapNavButtonProps,\n  ChatMinimapPayload,\n  ChatMinimapProps,\n  ChatMinimapSide,\n} from \"../types/chat-minimap\";\n\nconst HOVER_OPEN_DELAY_MS = 80;\nconst HOVER_CLOSE_DELAY_MS = 100;\nconst ITEM_FALLOFF_CLASS_NAME =\n  \"[&:is(:hover,:focus-visible)_svg]:w-6 [&:has(+[data-slot=chat-minimap-item]:is(:hover,:focus-visible))_svg]:w-5 [[data-slot=chat-minimap-item]:is(:hover,:focus-visible)+&_svg]:w-5 [&:has(+*+[data-slot=chat-minimap-item]:is(:hover,:focus-visible))_svg]:w-4 [[data-slot=chat-minimap-item]:is(:hover,:focus-visible)+*+&_svg]:w-4 focus-visible:text-foreground [&:has(+[data-slot=chat-minimap-item]:is(:hover,:focus-visible))]:text-foreground/75 [[data-slot=chat-minimap-item]:is(:hover,:focus-visible)+&]:text-foreground/75 [&:has(+*+[data-slot=chat-minimap-item]:is(:hover,:focus-visible))]:text-foreground/55 [[data-slot=chat-minimap-item]:is(:hover,:focus-visible)+*+&]:text-foreground/55\";\n\nconst ChatMinimapContext = createContext<ChatMinimapSide>(\"right\");\n\nexport const ChatMinimap = ({\n  children,\n  className,\n  side = \"right\",\n  ...props\n}: ChatMinimapProps) => (\n  <ChatMinimapContext value={side}>\n    <HoverCard>\n      {({ payload }) => (\n        <>\n          <nav\n            aria-label=\"Conversation turns\"\n            className={cn(\n              \"group/chat-minimap flex w-fit flex-col\",\n              side === \"left\" ? \"items-end\" : \"items-start\",\n              className\n            )}\n            data-side={side}\n            data-slot=\"chat-minimap\"\n            {...props}\n          >\n            {children}\n          </nav>\n          <HoverCardContent\n            align=\"center\"\n            className=\"w-64 bg-transparent p-0 shadow-none ring-0\"\n            side={side}\n            sideOffset={8}\n          >\n            {isChatMinimapPayload(payload) ? (\n              <Card\n                className=\"bg-popover text-popover-foreground shadow-lg\"\n                data-slot=\"chat-minimap-card\"\n                size=\"sm\"\n              >\n                <CardHeader className=\"gap-0.5\">\n                  <CardTitle className=\"truncate text-sm\">\n                    {payload.title}\n                  </CardTitle>\n                  {payload.description ? (\n                    <CardDescription className=\"line-clamp-2 text-xs leading-relaxed\">\n                      {payload.description}\n                    </CardDescription>\n                  ) : null}\n                </CardHeader>\n              </Card>\n            ) : null}\n          </HoverCardContent>\n        </>\n      )}\n    </HoverCard>\n  </ChatMinimapContext>\n);\n\nexport const ChatMinimapItem = ({\n  active = false,\n  className,\n  description,\n  title,\n  ...props\n}: ChatMinimapItemProps) => {\n  const side = use(ChatMinimapContext);\n  const payload: ChatMinimapPayload = { description, title };\n\n  return (\n    <HoverCardTrigger\n      closeDelay={HOVER_CLOSE_DELAY_MS}\n      delay={HOVER_OPEN_DELAY_MS}\n      payload={payload}\n      render={\n        <Button\n          className={cn(\n            \"text-muted-foreground/40 hover:text-foreground data-active:text-foreground data-popup-open:text-foreground h-2 w-8 rounded-none px-1 transition-colors hover:bg-transparent dark:hover:bg-transparent\",\n            ITEM_FALLOFF_CLASS_NAME,\n            side === \"left\" ? \"justify-end\" : \"justify-start\",\n            className\n          )}\n          data-active={active || undefined}\n          data-slot=\"chat-minimap-item\"\n          size=\"icon-xs\"\n          variant=\"ghost\"\n          {...props}\n        />\n      }\n    >\n      <svg\n        aria-hidden=\"true\"\n        className={cn(\n          \"size-auto h-0.5 w-3 overflow-visible transition-[width] duration-200 ease-out motion-reduce:transition-none\",\n          side === \"left\" && \"-scale-x-100\"\n        )}\n        preserveAspectRatio=\"none\"\n        viewBox=\"0 0 24 2\"\n      >\n        <rect fill=\"currentColor\" height=\"2\" width=\"24\" />\n      </svg>\n      <span className=\"sr-only\">{title}</span>\n    </HoverCardTrigger>\n  );\n};\n\nexport const ChatMinimapNavButton = ({\n  className,\n  direction,\n  label = direction === \"previous\" ? \"Previous turn\" : \"Next turn\",\n  ...props\n}: ChatMinimapNavButtonProps) => {\n  const side = use(ChatMinimapContext);\n\n  return (\n    <Tooltip>\n      <TooltipTrigger\n        render={\n          <Button\n            aria-label={label}\n            className={cn(\n              \"text-muted-foreground hover:text-foreground h-5 w-8 rounded-none px-1 opacity-0 transition-opacity duration-150 hover:bg-transparent hover:opacity-100 focus-visible:opacity-100 motion-reduce:transition-none dark:hover:bg-transparent pointer-coarse:opacity-100\",\n              side === \"left\" ? \"justify-end\" : \"justify-start\",\n              className\n            )}\n            data-direction={direction}\n            data-slot=\"chat-minimap-nav-button\"\n            size=\"icon-xs\"\n            variant=\"ghost\"\n            {...props}\n          />\n        }\n      >\n        <svg\n          aria-hidden=\"true\"\n          className={cn(\n            \"size-auto w-2.5\",\n            direction === \"next\" && \"rotate-180\"\n          )}\n          fill=\"none\"\n          stroke=\"currentColor\"\n          strokeLinecap=\"round\"\n          strokeLinejoin=\"round\"\n          strokeWidth=\"1.5\"\n          viewBox=\"0 0 10 6\"\n        >\n          <path d=\"M.75 5.25 5 1l4.25 4.25\" />\n        </svg>\n      </TooltipTrigger>\n      <TooltipContent\n        className=\"whitespace-nowrap\"\n        side={direction === \"previous\" ? \"top\" : \"bottom\"}\n      >\n        {label}\n      </TooltipContent>\n    </Tooltip>\n  );\n};\n",
      "type": "registry:component",
      "target": "components/chat-minimap/components/chat-minimap.tsx"
    },
    {
      "path": "registry/notra/chat-minimap/types/chat-minimap.ts",
      "content": "import type { ComponentProps, ReactNode } from \"react\";\n\nimport type { Button } from \"@/components/ui/button\";\n\nexport type ChatMinimapSide = \"left\" | \"right\";\n\nexport interface ChatMinimapPayload {\n  description?: ReactNode;\n  title: ReactNode;\n}\n\nexport interface ChatMinimapProps extends ComponentProps<\"nav\"> {\n  /** Which side of the rail the preview card opens on. */\n  side?: ChatMinimapSide;\n}\n\nexport interface ChatMinimapItemProps extends Omit<\n  ComponentProps<typeof Button>,\n  \"title\"\n> {\n  active?: boolean;\n  description?: ReactNode;\n  title: ReactNode;\n}\n\nexport interface ChatMinimapNavButtonProps extends ComponentProps<\n  typeof Button\n> {\n  direction: \"previous\" | \"next\";\n  label?: string;\n}\n\nexport interface ChatMinimapDemoTurn {\n  description: string;\n  id: string;\n  title: string;\n}\n\nexport interface ChatMinimapExampleProps {\n  initialStart?: number;\n  side?: ChatMinimapSide;\n  turns?: readonly ChatMinimapDemoTurn[];\n}\n",
      "type": "registry:lib",
      "target": "components/chat-minimap/types/chat-minimap.ts"
    },
    {
      "path": "registry/notra/chat-minimap/lib/chat-minimap.ts",
      "content": "import type { ChatMinimapPayload } from \"../types/chat-minimap\";\n\nexport const isChatMinimapPayload = (\n  value: unknown\n): value is ChatMinimapPayload =>\n  typeof value === \"object\" && value !== null && \"title\" in value;\n",
      "type": "registry:lib",
      "target": "components/chat-minimap/lib/chat-minimap.ts"
    },
    {
      "path": "registry/notra/chat-minimap/hooks/use-chat-minimap-scroll-spy.ts",
      "content": "\"use client\";\n\nimport { useCallback, useEffect, useRef, useState } from \"react\";\n\ntype TurnRef = (element: HTMLElement | null) => void;\n\nexport const useChatMinimapScrollSpy = (turnCount: number) => {\n  const [root, setRoot] = useState<HTMLElement | null>(null);\n  const [visible, setVisible] = useState<ReadonlySet<number>>(new Set());\n  const elements = useRef(new Map<number, HTMLElement>());\n  const turnRefs = useRef(new Map<number, TurnRef>());\n\n  useEffect(() => {\n    if (!root) {\n      return;\n    }\n    const indexes = new Map<Element, number>();\n    const inView = new Set<number>();\n    const observer = new IntersectionObserver(\n      (entries) => {\n        for (const entry of entries) {\n          const index = indexes.get(entry.target);\n          if (index === undefined) {\n            continue;\n          }\n          if (entry.isIntersecting) {\n            inView.add(index);\n          } else {\n            inView.delete(index);\n          }\n        }\n        setVisible(new Set(inView));\n      },\n      { root }\n    );\n    for (const [index, element] of elements.current) {\n      if (index < turnCount) {\n        indexes.set(element, index);\n        observer.observe(element);\n      }\n    }\n    return () => observer.disconnect();\n  }, [root, turnCount]);\n\n  const turnRef = useCallback((index: number) => {\n    const cached = turnRefs.current.get(index);\n    if (cached) {\n      return cached;\n    }\n    const ref: TurnRef = (element) => {\n      if (element) {\n        elements.current.set(index, element);\n      } else {\n        elements.current.delete(index);\n      }\n    };\n    turnRefs.current.set(index, ref);\n    return ref;\n  }, []);\n\n  const scrollToTurn = useCallback(\n    (index: number) => {\n      const element = elements.current.get(index);\n      if (!(root && element)) {\n        return;\n      }\n      root.scrollBy({\n        behavior: \"smooth\",\n        top:\n          element.getBoundingClientRect().top -\n          root.getBoundingClientRect().top,\n      });\n    },\n    [root]\n  );\n\n  return { rootRef: setRoot, scrollToTurn, turnRef, visible };\n};\n",
      "type": "registry:hook",
      "target": "components/chat-minimap/hooks/use-chat-minimap-scroll-spy.ts"
    }
  ],
  "type": "registry:component"
}