{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "sidebar-01",
  "title": "可收起侧栏",
  "description": "基于官方 Sidebar 的可收起侧栏：搜索过滤、手风琴分组、带引导线的子项，收起成图标栏后悬停浮出子菜单，手机端沿用抽屉。",
  "dependencies": [
    "lucide-react"
  ],
  "registryDependencies": [
    "sidebar",
    "dropdown-menu",
    "tooltip",
    "collapsible",
    "button",
    "breadcrumb",
    "separator",
    "https://yiui.dev/r/grid-layout.json"
  ],
  "files": [
    {
      "path": "src/registry/blocks/sidebar-01/page.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\n\nimport { Sidebar01Shell } from \"@/components/sidebar-01/shell\"\n\n/**\n * 页面入口。nav-data.ts 里的地址只是示例（这些路由并不存在），\n * 所以这里拦截跳转，用本地状态模拟「当前页」，点侧栏就能看到高亮、展开和面包屑的变化。\n *\n * 接入真实路由时：把 navigation 换成 Next 的 Link 和 usePathname，并把 nav-data.ts 改成你自己的地址：\n *\n *   import Link from \"next/link\"\n *   import { usePathname } from \"next/navigation\"\n *   <Sidebar01Shell currentHref={usePathname()} linkComponent={Link} />\n */\nexport default function Sidebar01Page() {\n  const [href, setHref] = React.useState(\"/content/articles\")\n  return (\n    <Sidebar01Shell\n      currentHref={href}\n      navigation={{ intercept: true, onNavigate: ({ href }) => setHref(href) }}\n    />\n  )\n}\n",
      "type": "registry:page",
      "target": "app/sidebar-01/page.tsx"
    },
    {
      "path": "src/registry/blocks/sidebar-01/sidebar-01.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport {\n  LayersIcon,\n  PanelLeftCloseIcon,\n  PanelLeftOpenIcon,\n  SearchIcon,\n} from \"lucide-react\"\n\nimport { cn } from \"@/lib/utils\"\nimport { Button } from \"@/components/ui/button\"\nimport {\n  Sidebar,\n  SidebarContent,\n  SidebarFooter,\n  SidebarGroup,\n  SidebarGroupContent,\n  SidebarGroupLabel,\n  SidebarHeader,\n  SidebarInput,\n  SidebarMenu,\n  SidebarRail,\n  useSidebar,\n} from \"@/components/ui/sidebar\"\nimport { TooltipProvider } from \"@/components/ui/tooltip\"\nimport { DEFAULT_LABELS, type Sidebar01Labels } from \"./config\"\nimport {\n  Sidebar01Context,\n  useSidebar01,\n  type Sidebar01ContextValue,\n} from \"./context\"\nimport { NavAnchor } from \"./nav-anchor\"\nimport { DEFAULT_BRAND, DEFAULT_FOOTER_ITEMS, DEFAULT_GROUPS } from \"./nav-data\"\nimport { NavItem } from \"./nav-parts\"\nimport type {\n  Sidebar01Brand,\n  Sidebar01Group,\n  Sidebar01Item,\n  Sidebar01Navigation,\n} from \"./types\"\nimport {\n  collectHrefs,\n  filterGroups,\n  findActiveHref,\n  findActiveParentId,\n  formatLabel,\n} from \"./utils\"\n\ntype Sidebar01Props = Omit<\n  React.ComponentProps<typeof Sidebar>,\n  \"collapsible\" | \"children\"\n> & {\n  /**\n   * 导航分组\n   * @default 示例数据（nav-data.ts）\n   */\n  groups?: Sidebar01Group[]\n  /**\n   * 固定在底部的次要入口，只放链接\n   * @default 帮助中心、设置\n   */\n  footerItems?: Sidebar01Item[]\n  /** 品牌：方形 logo + 名称 */\n  brand?: Sidebar01Brand\n  /** 当前地址（pathname），用来高亮当前项并默认展开它所在的父项 */\n  currentHref?: string\n  /**\n   * 手风琴：同一时间只展开一个父项\n   * @default true\n   */\n  accordion?: boolean\n  /** 链接行为：点击回调与拦截跳转，同 app-shell-01 的 NavLinkBehavior */\n  navigation?: Sidebar01Navigation\n  /**\n   * 链接组件，换成 Next 的 Link 即可走客户端路由\n   * @default \"a\"\n   */\n  linkComponent?: React.ElementType\n  /** 覆盖默认文案 */\n  labels?: Partial<Sidebar01Labels>\n}\n\n/** 品牌方块：默认图标可通过 brand.logo 替换。 */\nfunction BrandLogo({ logo }: { logo?: React.ReactNode }) {\n  return (\n    <span\n      data-slot=\"sidebar-01-logo\"\n      className=\"flex size-8 shrink-0 items-center justify-center rounded-md bg-sidebar-primary text-sidebar-primary-foreground [&_svg:not([class*='size-'])]:size-4\"\n    >\n      {logo ?? <LayersIcon />}\n    </span>\n  )\n}\n\nfunction Sidebar01Header({\n  brand,\n  query,\n  onQueryChange,\n}: {\n  brand: Sidebar01Brand\n  query: string\n  onQueryChange: (query: string) => void\n}) {\n  const { labels } = useSidebar01()\n  const { toggleSidebar } = useSidebar()\n  const name = (\n    <>\n      <BrandLogo logo={brand.logo} />\n      <span className=\"truncate text-sm font-semibold\">{brand.name}</span>\n    </>\n  )\n  return (\n    <>\n      {/* 品牌带高 56px（h-14），底线与右侧顶栏的底线连成一条 */}\n      <SidebarHeader className=\"h-14 shrink-0 justify-center border-b border-sidebar-border\">\n        <div className=\"flex items-center gap-2\">\n          {brand.href ? (\n            <NavAnchor\n              href={brand.href}\n              className=\"flex min-w-0 flex-1 items-center gap-2 rounded-md outline-hidden group-data-[collapsible=icon]:hidden focus-visible:ring-2 focus-visible:ring-sidebar-ring\"\n            >\n              {name}\n            </NavAnchor>\n          ) : (\n            <div className=\"flex min-w-0 flex-1 items-center gap-2 group-data-[collapsible=icon]:hidden\">\n              {name}\n            </div>\n          )}\n          <Button\n            variant=\"ghost\"\n            size=\"icon-sm\"\n            aria-label={labels.collapse}\n            onClick={toggleSidebar}\n            className=\"group-data-[collapsible=icon]:hidden\"\n          >\n            <PanelLeftCloseIcon />\n          </Button>\n          {/* 收起后图标栏只有 32px：logo 本身就是展开按钮，悬停时换成展开图标 */}\n          <Button\n            variant=\"ghost\"\n            size=\"icon\"\n            aria-label={labels.expand}\n            onClick={toggleSidebar}\n            className=\"group/expand relative hidden p-0 group-data-[collapsible=icon]:flex\"\n          >\n            <span className=\"transition-opacity group-hover/expand:opacity-0 group-focus-visible/expand:opacity-0\">\n              <BrandLogo logo={brand.logo} />\n            </span>\n            <PanelLeftOpenIcon className=\"absolute opacity-0 transition-opacity group-hover/expand:opacity-100 group-focus-visible/expand:opacity-100\" />\n          </Button>\n        </div>\n      </SidebarHeader>\n      <div className=\"relative shrink-0 border-b border-sidebar-border p-2 group-data-[collapsible=icon]:hidden\">\n        <SearchIcon\n          aria-hidden\n          className=\"pointer-events-none absolute top-1/2 left-4.5 size-4 -translate-y-1/2 text-muted-foreground\"\n        />\n        <SidebarInput\n          type=\"search\"\n          aria-label={labels.search}\n          placeholder={labels.searchPlaceholder}\n          value={query}\n          onChange={(event) => onQueryChange(event.target.value)}\n          className=\"pl-8 [&::-webkit-search-cancel-button]:appearance-none\"\n        />\n      </div>\n    </>\n  )\n}\n\n/**\n * 可收起侧栏：基于 shadcn 官方 Sidebar（`collapsible=\"icon\"`），补上收起后的浮出子菜单。\n * 必须放在 `SidebarProvider` 内；移动端沿用官方的 Sheet 抽屉。\n */\nfunction Sidebar01({\n  groups = DEFAULT_GROUPS,\n  footerItems = DEFAULT_FOOTER_ITEMS,\n  brand = DEFAULT_BRAND,\n  currentHref,\n  accordion = true,\n  navigation,\n  linkComponent = \"a\",\n  labels: labelsProp,\n  className,\n  ...props\n}: Sidebar01Props) {\n  const labels = React.useMemo(\n    () => ({ ...DEFAULT_LABELS, ...labelsProp }),\n    [labelsProp],\n  )\n  const activeHref = React.useMemo(\n    () => findActiveHref(collectHrefs(groups, footerItems), currentHref),\n    [groups, footerItems, currentHref],\n  )\n  const activeParentId = findActiveParentId(groups, activeHref)\n\n  // 当前页面所在的父项初始就展开；地址变化落到别的父项时也跟着展开\n  const [expandedIds, setExpandedIds] = React.useState<string[]>(\n    activeParentId ? [activeParentId] : [],\n  )\n  const [lastActiveParentId, setLastActiveParentId] =\n    React.useState(activeParentId)\n  if (activeParentId !== lastActiveParentId) {\n    setLastActiveParentId(activeParentId)\n    if (activeParentId) {\n      setExpandedIds((current) => {\n        if (accordion) return [activeParentId]\n        return current.includes(activeParentId)\n          ? current\n          : [...current, activeParentId]\n      })\n    }\n  }\n\n  const setExpanded = React.useCallback(\n    (id: string, open: boolean) => {\n      setExpandedIds((current) => {\n        if (accordion) return open ? [id] : current.filter((x) => x !== id)\n        return open\n          ? current.includes(id)\n            ? current\n            : [...current, id]\n          : current.filter((x) => x !== id)\n      })\n    },\n    [accordion],\n  )\n\n  const [query, setQuery] = React.useState(\"\")\n  const visibleGroups = React.useMemo(\n    () => filterGroups(groups, query),\n    [groups, query],\n  )\n  const searching = query.trim() !== \"\"\n\n  const context = React.useMemo<Sidebar01ContextValue>(\n    () => ({\n      labels,\n      linkComponent,\n      navigation,\n      activeHref,\n      expandedIds,\n      searching,\n      setExpanded,\n    }),\n    [\n      labels,\n      linkComponent,\n      navigation,\n      activeHref,\n      expandedIds,\n      searching,\n      setExpanded,\n    ],\n  )\n\n  return (\n    <Sidebar01Context.Provider value={context}>\n      <TooltipProvider>\n        <Sidebar\n          collapsible=\"icon\"\n          className={cn(\"border-sidebar-border\", className)}\n          {...props}\n        >\n          <Sidebar01Header\n            brand={brand}\n            query={query}\n            onQueryChange={setQuery}\n          />\n          <SidebarContent data-slot=\"sidebar-01-content\">\n            <nav aria-label={labels.navLabel}>\n              {visibleGroups.map((group) => (\n                <SidebarGroup key={group.id}>\n                  <SidebarGroupLabel>{group.label}</SidebarGroupLabel>\n                  <SidebarGroupContent>\n                    <SidebarMenu>\n                      {group.items.map((item) => (\n                        <NavItem key={item.id} item={item} />\n                      ))}\n                    </SidebarMenu>\n                  </SidebarGroupContent>\n                </SidebarGroup>\n              ))}\n            </nav>\n            <div role=\"status\" className=\"group-data-[collapsible=icon]:hidden\">\n              {searching && visibleGroups.length === 0 ? (\n                <p className=\"px-4 py-6 text-center text-sm text-muted-foreground\">\n                  {formatLabel(labels.empty, { query: query.trim() })}\n                </p>\n              ) : null}\n            </div>\n          </SidebarContent>\n          <SidebarFooter className=\"border-t border-sidebar-border\">\n            <nav aria-label={labels.footerLabel}>\n              <SidebarMenu>\n                {footerItems.map((item) => (\n                  <NavItem key={item.id} item={item} />\n                ))}\n              </SidebarMenu>\n            </nav>\n          </SidebarFooter>\n          <SidebarRail />\n        </Sidebar>\n      </TooltipProvider>\n    </Sidebar01Context.Provider>\n  )\n}\n\nexport { Sidebar01 }\nexport type { Sidebar01Props }\n",
      "type": "registry:component",
      "target": "@components/sidebar-01/sidebar-01.tsx"
    },
    {
      "path": "src/registry/blocks/sidebar-01/shell.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\n\nimport { cn } from \"@/lib/utils\"\nimport {\n  Breadcrumb,\n  BreadcrumbItem,\n  BreadcrumbList,\n  BreadcrumbPage,\n  BreadcrumbSeparator,\n} from \"@/components/ui/breadcrumb\"\nimport { Separator } from \"@/components/ui/separator\"\nimport {\n  SidebarInset,\n  SidebarProvider,\n  SidebarTrigger,\n} from \"@/components/ui/sidebar\"\nimport {\n  GridColumns,\n  GridContainer,\n  GridSection,\n  GridSeparator,\n} from \"@/components/ui/grid-layout/grid-layout\"\nimport { Sidebar01, type Sidebar01Props } from \"./sidebar-01\"\nimport { DEFAULT_FOOTER_ITEMS, DEFAULT_GROUPS } from \"./nav-data\"\nimport { collectHrefs, findActiveHref, findTrail } from \"./utils\"\n\n/** 演示用的占位指标，固定值，保证预渲染稳定。 */\nconst STATS = [\n  { label: \"本月发布\", value: \"24\", hint: \"较上月多 6 篇\" },\n  { label: \"待审核\", value: \"3\", hint: \"最早一篇等待 2 天\" },\n  { label: \"平均阅读时长\", value: \"4 分 12 秒\", hint: \"近 30 天\" },\n]\n\n/** 演示页的占位文案 */\nconst COPY = {\n  eyebrow: \"内容 / 编辑台\",\n  intro:\n    \"这里是占位内容。收起侧栏后，把鼠标移到带子菜单的图标上，会在右侧浮出子菜单。\",\n}\n\nconst ROWS = [\n  \"春季专题策划稿\",\n  \"读者来信合集\",\n  \"编辑部周报\",\n  \"新栏目试运行说明\",\n]\n\n/**\n * 演示页的外壳：SidebarProvider + Sidebar01 + SidebarInset（顶栏 + 线条网格主区）。\n * 安装后的 page.tsx 和文档预览共用它；真实项目里换成自己的布局即可。\n */\nfunction Sidebar01Shell({\n  className,\n  ...props\n}: Omit<Sidebar01Props, \"variant\">) {\n  const groups = props.groups ?? DEFAULT_GROUPS\n  const footerItems = props.footerItems ?? DEFAULT_FOOTER_ITEMS\n  const trail = findTrail(\n    groups,\n    footerItems,\n    findActiveHref(collectHrefs(groups, footerItems), props.currentHref),\n  )\n  const title = trail[trail.length - 1] ?? \"工作概览\"\n\n  return (\n    // 触屏上菜单行加高到 40px，收起后的图标栏跟着加宽到 56px 才放得下\n    <SidebarProvider\n      defaultOpen\n      className={cn(\"pointer-coarse:[--sidebar-width-icon:3.5rem]!\", className)}\n    >\n      <Sidebar01 variant=\"sidebar\" {...props} />\n      <SidebarInset className=\"min-w-0 overflow-x-clip\">\n        <header className=\"sticky top-0 z-10 flex h-14 shrink-0 items-center gap-2 border-b border-edge bg-background px-3\">\n          <SidebarTrigger aria-label=\"切换侧栏\" />\n          <Separator\n            orientation=\"vertical\"\n            className=\"h-4 data-vertical:self-center\"\n          />\n          <Breadcrumb>\n            <BreadcrumbList>\n              {trail.map((name, index) => (\n                <React.Fragment key={`${index}-${name}`}>\n                  {index > 0 ? <BreadcrumbSeparator /> : null}\n                  <BreadcrumbItem>\n                    {index === trail.length - 1 ? (\n                      <BreadcrumbPage>{name}</BreadcrumbPage>\n                    ) : (\n                      <span>{name}</span>\n                    )}\n                  </BreadcrumbItem>\n                </React.Fragment>\n              ))}\n            </BreadcrumbList>\n          </Breadcrumb>\n        </header>\n        <GridContainer className=\"[--grid-width:64rem]\">\n          <GridSection className=\"px-4 py-8 sm:px-6\">\n            <p className=\"font-mono text-xs text-muted-foreground\">\n              {COPY.eyebrow}\n            </p>\n            <h1 className=\"mt-2 text-2xl font-semibold tracking-tight\">\n              {title}\n            </h1>\n            <p className=\"mt-2 max-w-xl text-sm leading-7 text-muted-foreground\">\n              {COPY.intro}\n            </p>\n          </GridSection>\n          <GridSeparator />\n          <GridSection>\n            <GridColumns className=\"sm:grid-cols-3\">\n              {STATS.map((stat) => (\n                <div key={stat.label} className=\"p-4 sm:p-6\">\n                  <p className=\"text-sm text-muted-foreground\">{stat.label}</p>\n                  <p className=\"mt-1 text-2xl font-semibold tabular-nums\">\n                    {stat.value}\n                  </p>\n                  <p className=\"mt-1 text-xs text-muted-foreground\">\n                    {stat.hint}\n                  </p>\n                </div>\n              ))}\n            </GridColumns>\n          </GridSection>\n          <GridSeparator />\n          <GridSection>\n            <ul className=\"divide-y divide-dashed divide-edge\">\n              {ROWS.map((row, index) => (\n                <li\n                  key={row}\n                  className=\"flex items-center gap-3 px-4 py-3 text-sm sm:px-6\"\n                >\n                  <span className=\"font-mono text-xs text-muted-foreground tabular-nums\">\n                    {String(index + 1).padStart(2, \"0\")}\n                  </span>\n                  <span className=\"truncate\">{row}</span>\n                </li>\n              ))}\n            </ul>\n          </GridSection>\n        </GridContainer>\n      </SidebarInset>\n    </SidebarProvider>\n  )\n}\n\nexport { Sidebar01Shell }\n",
      "type": "registry:component",
      "target": "@components/sidebar-01/shell.tsx"
    },
    {
      "path": "src/registry/blocks/sidebar-01/nav-parts.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport { ChevronRightIcon } from \"lucide-react\"\n\nimport { cn } from \"@/lib/utils\"\nimport {\n  Collapsible,\n  CollapsibleContent,\n  CollapsibleTrigger,\n} from \"@/components/ui/collapsible\"\nimport {\n  DropdownMenu,\n  DropdownMenuContent,\n  DropdownMenuGroup,\n  DropdownMenuItem,\n  DropdownMenuLabel,\n  DropdownMenuTrigger,\n} from \"@/components/ui/dropdown-menu\"\nimport {\n  SidebarMenuBadge,\n  SidebarMenuButton,\n  SidebarMenuItem,\n  SidebarMenuSub,\n  SidebarMenuSubButton,\n  SidebarMenuSubItem,\n  useSidebar,\n} from \"@/components/ui/sidebar\"\nimport { ROW_CLASS, SUB_ROW_CLASS } from \"./config\"\nimport { useSidebar01 } from \"./context\"\nimport { NavAnchor } from \"./nav-anchor\"\nimport type { Sidebar01Item, Sidebar01SubItem } from \"./types\"\nimport { normalizeHref } from \"./utils\"\n\n/** 子项左侧的一小段横线，连到父级的竖向引导线上（竖线 = 容器左边框）。 */\nconst CONNECTOR_CLASS =\n  \"before:pointer-events-none before:absolute before:top-1/2 before:-left-2.5 before:h-px before:w-2.5 before:bg-sidebar-border\"\n\nfunction isActiveSub(sub: Sidebar01SubItem, activeHref?: string) {\n  return activeHref !== undefined && normalizeHref(sub.href) === activeHref\n}\n\nfunction SubBadge({ children }: { children: React.ReactNode }) {\n  return (\n    <span\n      data-slot=\"sidebar-01-sub-badge\"\n      className=\"ms-auto shrink-0 text-xs text-sidebar-foreground/70 tabular-nums\"\n    >\n      {children}\n    </span>\n  )\n}\n\n/** 没有子项的条目；收起后悬停或聚焦时用 Tooltip 显示名称。 */\nfunction NavLeaf({ item }: { item: Sidebar01Item }) {\n  const { activeHref } = useSidebar01()\n  const isActive =\n    activeHref !== undefined &&\n    item.href !== undefined &&\n    normalizeHref(item.href) === activeHref\n  return (\n    <SidebarMenuItem>\n      <SidebarMenuButton\n        tooltip={item.label}\n        isActive={isActive}\n        className={cn(ROW_CLASS, item.badge !== undefined && \"pr-9\")}\n        render={\n          <NavAnchor\n            href={item.href ?? \"#\"}\n            aria-current={isActive ? \"page\" : undefined}\n          />\n        }\n      >\n        <item.icon />\n        <span>{item.label}</span>\n      </SidebarMenuButton>\n      {item.badge !== undefined ? (\n        <SidebarMenuBadge className=\"top-1/2! -translate-y-1/2\">\n          {item.badge}\n        </SidebarMenuBadge>\n      ) : null}\n    </SidebarMenuItem>\n  )\n}\n\n/** 展开态的父项：Collapsible + 带引导线的子项列表。 */\nfunction ExpandedParent({ item }: { item: Sidebar01Item }) {\n  const { activeHref, expandedIds, searching, setExpanded } = useSidebar01()\n  const subs = item.items ?? []\n  const open = searching || expandedIds.includes(item.id)\n  const hasActive = subs.some((sub) => isActiveSub(sub, activeHref))\n  return (\n    <SidebarMenuItem>\n      <Collapsible\n        open={open}\n        onOpenChange={(next) => setExpanded(item.id, next)}\n      >\n        <CollapsibleTrigger\n          render={\n            <SidebarMenuButton\n              className={cn(ROW_CLASS, hasActive && \"font-medium\")}\n            />\n          }\n        >\n          <item.icon />\n          {/* 有计数时给绝对定位的徽标让出位置 */}\n          <span className={cn(\"truncate\", item.badge !== undefined && \"pe-8\")}>\n            {item.label}\n          </span>\n          <ChevronRightIcon\n            aria-hidden\n            className={cn(\n              \"ms-auto transition-transform duration-200 motion-reduce:transition-none\",\n              open && \"rotate-90\",\n            )}\n          />\n        </CollapsibleTrigger>\n        {item.badge !== undefined ? (\n          <SidebarMenuBadge className=\"top-4! right-7 -translate-y-1/2 pointer-coarse:top-5!\">\n            {item.badge}\n          </SidebarMenuBadge>\n        ) : null}\n        <CollapsibleContent className=\"h-(--collapsible-panel-height) overflow-hidden transition-[height] duration-200 data-ending-style:h-0 data-starting-style:h-0 motion-reduce:transition-none\">\n          <SidebarMenuSub>\n            {subs.map((sub) => {\n              const isActive = isActiveSub(sub, activeHref)\n              return (\n                <SidebarMenuSubItem key={sub.id} className={CONNECTOR_CLASS}>\n                  <SidebarMenuSubButton\n                    isActive={isActive}\n                    className={cn(SUB_ROW_CLASS, isActive && \"font-medium\")}\n                    render={\n                      <NavAnchor\n                        href={sub.href}\n                        aria-current={isActive ? \"page\" : undefined}\n                      />\n                    }\n                  >\n                    <span>{sub.label}</span>\n                    {sub.badge !== undefined ? (\n                      <SubBadge>{sub.badge}</SubBadge>\n                    ) : null}\n                  </SidebarMenuSubButton>\n                </SidebarMenuSubItem>\n              )\n            })}\n          </SidebarMenuSub>\n        </CollapsibleContent>\n      </Collapsible>\n    </SidebarMenuItem>\n  )\n}\n\n/**\n * 收起态的父项：官方 Sidebar 收起后子菜单会被隐藏，这里用 Menu 浮层补上。\n * 悬停（带安全三角，鼠标移向浮层途中不会闪退）、点击、Enter / Space / → 都能打开；\n * 方向键在子项间移动，Esc 关闭并把焦点还给图标，点子项跳转并关闭。\n */\nfunction CollapsedParent({ item }: { item: Sidebar01Item }) {\n  const { activeHref } = useSidebar01()\n  const subs = item.items ?? []\n  const hasActive = subs.some((sub) => isActiveSub(sub, activeHref))\n\n  // Menu 默认只响应 Enter / Space / ↑ / ↓，补上 →（侧栏子菜单向右展开）\n  function handleKeyDown(event: React.KeyboardEvent<HTMLElement>) {\n    if (\n      event.key === \"ArrowRight\" &&\n      event.currentTarget.getAttribute(\"aria-expanded\") !== \"true\"\n    ) {\n      event.preventDefault()\n      event.currentTarget.click()\n    }\n  }\n\n  return (\n    <SidebarMenuItem>\n      <DropdownMenu>\n        <DropdownMenuTrigger\n          openOnHover\n          delay={60}\n          closeDelay={120}\n          onKeyDown={handleKeyDown}\n          render={\n            <SidebarMenuButton\n              isActive={hasActive}\n              className={cn(\n                ROW_CLASS,\n                \"data-popup-open:bg-sidebar-accent data-popup-open:text-sidebar-accent-foreground\",\n              )}\n            />\n          }\n        >\n          <item.icon />\n          <span>{item.label}</span>\n        </DropdownMenuTrigger>\n        <DropdownMenuContent\n          side=\"right\"\n          align=\"start\"\n          sideOffset={8}\n          alignOffset={-4}\n          className=\"w-52 min-w-52 bg-sidebar text-sidebar-foreground shadow-sm ring-sidebar-border\"\n        >\n          <DropdownMenuGroup>\n            <DropdownMenuLabel className=\"px-2 py-1.5 text-sm font-medium text-sidebar-foreground\">\n              {item.label}\n            </DropdownMenuLabel>\n            <div\n              role=\"presentation\"\n              className=\"mx-3.5 flex flex-col gap-1 border-l border-sidebar-border px-2.5 pt-0.5 pb-1\"\n            >\n              {subs.map((sub) => {\n                const isActive = isActiveSub(sub, activeHref)\n                return (\n                  <DropdownMenuItem\n                    key={sub.id}\n                    data-active={isActive || undefined}\n                    aria-current={isActive ? \"page\" : undefined}\n                    className={cn(\n                      \"h-7 px-2 focus:bg-sidebar-accent focus:text-sidebar-accent-foreground data-active:bg-sidebar-accent data-active:font-medium data-active:text-sidebar-accent-foreground\",\n                      SUB_ROW_CLASS,\n                      CONNECTOR_CLASS,\n                    )}\n                    render={<NavAnchor href={sub.href} />}\n                  >\n                    <span className=\"truncate\">{sub.label}</span>\n                    {sub.badge !== undefined ? (\n                      <SubBadge>{sub.badge}</SubBadge>\n                    ) : null}\n                  </DropdownMenuItem>\n                )\n              })}\n            </div>\n          </DropdownMenuGroup>\n        </DropdownMenuContent>\n      </DropdownMenu>\n    </SidebarMenuItem>\n  )\n}\n\n/** 按当前侧栏状态选择渲染方式：收起（仅桌面）用浮层，其余用折叠列表。 */\nfunction NavItem({ item }: { item: Sidebar01Item }) {\n  const { isMobile, state } = useSidebar()\n  if (!item.items?.length) return <NavLeaf item={item} />\n  return state === \"collapsed\" && !isMobile ? (\n    <CollapsedParent item={item} />\n  ) : (\n    <ExpandedParent item={item} />\n  )\n}\n\nexport { NavItem, NavLeaf }\n",
      "type": "registry:component",
      "target": "@components/sidebar-01/nav-parts.tsx"
    },
    {
      "path": "src/registry/blocks/sidebar-01/nav-anchor.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\n\nimport { useSidebar } from \"@/components/ui/sidebar\"\nimport { useSidebar01 } from \"./context\"\n\n/**\n * 导航链接：默认渲染 `<a>`，可通过 Sidebar01 的 `linkComponent` 换成 Next 的 Link。\n * 保留 Cmd/Ctrl 点击等原生行为，只处理普通左键点击；手机上点击后自动关闭抽屉。\n * 通过 `render={<NavAnchor href=\"…\" />}` 交给侧栏按钮或浮层条目使用。\n */\nfunction NavAnchor({\n  href,\n  onClick,\n  ...props\n}: React.ComponentProps<\"a\"> & { href: string }) {\n  const { linkComponent: LinkComponent, navigation } = useSidebar01()\n  const { isMobile, setOpenMobile } = useSidebar()\n\n  function handleClick(event: React.MouseEvent<HTMLAnchorElement>) {\n    onClick?.(event)\n    if (\n      event.button !== 0 ||\n      event.metaKey ||\n      event.ctrlKey ||\n      event.shiftKey ||\n      event.altKey\n    ) {\n      return\n    }\n    if (navigation?.intercept) event.preventDefault()\n    navigation?.onNavigate?.({ href })\n    if (isMobile) setOpenMobile(false)\n  }\n\n  return (\n    <LinkComponent\n      data-slot=\"sidebar-01-link\"\n      href={href}\n      onClick={handleClick}\n      // 拦截跳转时地址只是标识（预览里这些路由并不存在），换成 Link 时不要预取\n      {...(navigation?.intercept && LinkComponent !== \"a\"\n        ? { prefetch: false }\n        : null)}\n      {...props}\n    />\n  )\n}\n\nexport { NavAnchor }\n",
      "type": "registry:component",
      "target": "@components/sidebar-01/nav-anchor.tsx"
    },
    {
      "path": "src/registry/blocks/sidebar-01/context.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\n\nimport type { Sidebar01Labels } from \"./config\"\nimport type { Sidebar01Navigation } from \"./types\"\n\ntype Sidebar01ContextValue = {\n  labels: Sidebar01Labels\n  linkComponent: React.ElementType\n  navigation?: Sidebar01Navigation\n  /** 与当前地址匹配的 href（已规范化） */\n  activeHref?: string\n  /** 展开着的父项 id */\n  expandedIds: string[]\n  /** 搜索中：命中的父项一律展开，忽略 expandedIds */\n  searching: boolean\n  setExpanded: (id: string, open: boolean) => void\n}\n\nconst Sidebar01Context = React.createContext<Sidebar01ContextValue | null>(null)\n\nfunction useSidebar01() {\n  const context = React.useContext(Sidebar01Context)\n  if (!context) {\n    throw new Error(\"Sidebar01 的子组件必须放在 Sidebar01 内部。\")\n  }\n  return context\n}\n\nexport { Sidebar01Context, useSidebar01 }\nexport type { Sidebar01ContextValue }\n",
      "type": "registry:component",
      "target": "@components/sidebar-01/context.tsx"
    },
    {
      "path": "src/registry/blocks/sidebar-01/nav-data.ts",
      "content": "import {\n  ChartColumnIcon,\n  FileTextIcon,\n  ImagesIcon,\n  LayoutDashboardIcon,\n  LifeBuoyIcon,\n  MessageSquareIcon,\n  PlugIcon,\n  SettingsIcon,\n  ShieldCheckIcon,\n  TagsIcon,\n  UsersIcon,\n} from \"lucide-react\"\n\nimport type { Sidebar01Brand, Sidebar01Group, Sidebar01Item } from \"./types\"\n\n/** 示例数据：一个内容运营后台。换成你自己的路由即可。 */\nconst DEFAULT_BRAND: Sidebar01Brand = { name: \"内容工作台\" }\n\nconst DEFAULT_GROUPS: Sidebar01Group[] = [\n  {\n    id: \"content\",\n    label: \"内容\",\n    items: [\n      {\n        id: \"overview\",\n        label: \"工作概览\",\n        icon: LayoutDashboardIcon,\n        href: \"/overview\",\n      },\n      {\n        id: \"articles\",\n        label: \"文章\",\n        icon: FileTextIcon,\n        badge: 8,\n        items: [\n          { id: \"all\", label: \"全部文章\", href: \"/content/articles\" },\n          { id: \"drafts\", label: \"草稿箱\", href: \"/content/drafts\", badge: 5 },\n          { id: \"review\", label: \"待审核\", href: \"/content/review\", badge: 3 },\n          { id: \"archive\", label: \"已归档\", href: \"/content/archive\" },\n        ],\n      },\n      {\n        id: \"media\",\n        label: \"媒体库\",\n        icon: ImagesIcon,\n        items: [\n          { id: \"images\", label: \"图片\", href: \"/media/images\" },\n          { id: \"videos\", label: \"视频\", href: \"/media/videos\" },\n          { id: \"files\", label: \"文件\", href: \"/media/files\" },\n        ],\n      },\n      {\n        id: \"comments\",\n        label: \"评论\",\n        icon: MessageSquareIcon,\n        href: \"/comments\",\n        badge: 12,\n      },\n    ],\n  },\n  {\n    id: \"operations\",\n    label: \"运营\",\n    items: [\n      {\n        id: \"taxonomy\",\n        label: \"栏目与标签\",\n        icon: TagsIcon,\n        items: [\n          { id: \"categories\", label: \"栏目\", href: \"/taxonomy/categories\" },\n          { id: \"tags\", label: \"标签\", href: \"/taxonomy/tags\" },\n        ],\n      },\n      {\n        id: \"subscribers\",\n        label: \"订阅用户\",\n        icon: UsersIcon,\n        items: [\n          { id: \"list\", label: \"用户列表\", href: \"/subscribers/list\" },\n          { id: \"segments\", label: \"用户分组\", href: \"/subscribers/segments\" },\n          { id: \"exports\", label: \"导出记录\", href: \"/subscribers/exports\" },\n        ],\n      },\n      {\n        id: \"analytics\",\n        label: \"数据分析\",\n        icon: ChartColumnIcon,\n        items: [\n          { id: \"traffic\", label: \"访问流量\", href: \"/analytics/traffic\" },\n          { id: \"sources\", label: \"来源渠道\", href: \"/analytics/sources\" },\n          { id: \"retention\", label: \"阅读留存\", href: \"/analytics/retention\" },\n        ],\n      },\n    ],\n  },\n  {\n    id: \"system\",\n    label: \"系统\",\n    items: [\n      {\n        id: \"members\",\n        label: \"成员与权限\",\n        icon: ShieldCheckIcon,\n        items: [\n          { id: \"people\", label: \"团队成员\", href: \"/members/people\" },\n          { id: \"roles\", label: \"角色权限\", href: \"/members/roles\" },\n        ],\n      },\n      {\n        id: \"integrations\",\n        label: \"集成\",\n        icon: PlugIcon,\n        href: \"/integrations\",\n      },\n    ],\n  },\n]\n\n/** 固定在底部的次要入口，只放链接。 */\nconst DEFAULT_FOOTER_ITEMS: Sidebar01Item[] = [\n  { id: \"help\", label: \"帮助中心\", icon: LifeBuoyIcon, href: \"/help\" },\n  { id: \"settings\", label: \"设置\", icon: SettingsIcon, href: \"/settings\" },\n]\n\nexport { DEFAULT_BRAND, DEFAULT_FOOTER_ITEMS, DEFAULT_GROUPS }\n",
      "type": "registry:component",
      "target": "@components/sidebar-01/nav-data.ts"
    },
    {
      "path": "src/registry/blocks/sidebar-01/config.ts",
      "content": "/** 所有可见文案，通过 `labels` 属性逐项覆盖；含 `{query}` 的文案渲染时填入实际值。 */\nconst DEFAULT_LABELS = {\n  navLabel: \"主导航\",\n  footerLabel: \"辅助入口\",\n  collapse: \"收起侧栏\",\n  expand: \"展开侧栏\",\n  search: \"搜索导航\",\n  searchPlaceholder: \"搜索导航…\",\n  empty: \"没有找到「{query}」相关的导航项\",\n}\n\ntype Sidebar01Labels = typeof DEFAULT_LABELS\n\n/** 行高：触屏上加高一档（32 → 40）；收起后的图标按钮也跟着变大，需要配合 SidebarProvider 加宽图标栏，见文档 */\nconst ROW_CLASS =\n  \"pointer-coarse:h-10 pointer-coarse:group-data-[collapsible=icon]:size-10!\"\n/** 二级行高：28 → 36 */\nconst SUB_ROW_CLASS = \"pointer-coarse:h-9\"\n\nexport { DEFAULT_LABELS, ROW_CLASS, SUB_ROW_CLASS }\nexport type { Sidebar01Labels }\n",
      "type": "registry:component",
      "target": "@components/sidebar-01/config.ts"
    },
    {
      "path": "src/registry/blocks/sidebar-01/types.ts",
      "content": "import type * as React from \"react\"\nimport type { LucideIcon } from \"lucide-react\"\n\n/** 二级条目：只能是链接。 */\ntype Sidebar01SubItem = {\n  id: string\n  label: string\n  href: string\n  /** 右侧计数，例如待处理数量 */\n  badge?: string | number\n}\n\n/** 一级条目：有 `items` 时是可展开的父项（本身不跳转），否则是直接跳转的链接。 */\ntype Sidebar01Item = {\n  id: string\n  label: string\n  icon: LucideIcon\n  href?: string\n  badge?: string | number\n  items?: Sidebar01SubItem[]\n}\n\n/** 带小标题的一组条目。 */\ntype Sidebar01Group = {\n  id: string\n  label: string\n  items: Sidebar01Item[]\n}\n\ntype Sidebar01Brand = {\n  name: string\n  /** 方形 logo；不传时用默认图标 */\n  logo?: React.ReactNode\n  /** 传入后品牌区变成链接 */\n  href?: string\n}\n\n/** 导航链接的统一行为，与 app-shell-01 的 NavLinkBehavior 一致。 */\ntype Sidebar01Navigation = {\n  /** 点击任一导航链接后触发（手机上抽屉随后自动关闭） */\n  onNavigate?: (payload: { href: string }) => void\n  /** 为 true 时拦截浏览器默认跳转，由 onNavigate 自行处理（单页演示、预览用） */\n  intercept?: boolean\n}\n\nexport type {\n  Sidebar01Brand,\n  Sidebar01Group,\n  Sidebar01Item,\n  Sidebar01Navigation,\n  Sidebar01SubItem,\n}\n",
      "type": "registry:component",
      "target": "@components/sidebar-01/types.ts"
    },
    {
      "path": "src/registry/blocks/sidebar-01/utils.ts",
      "content": "import type { Sidebar01Group, Sidebar01Item } from \"./types\"\n\n/** 去掉查询串、哈希与末尾斜杠，便于比较（项目使用 trailingSlash 时尤其需要）。 */\nfunction normalizeHref(href: string) {\n  const path = href.split(/[?#]/)[0] ?? \"\"\n  return path.length > 1 ? path.replace(/\\/+$/, \"\") : path || \"/\"\n}\n\nfunction matches(current: string, href: string) {\n  const target = normalizeHref(href)\n  return current === target || current.startsWith(`${target}/`)\n}\n\n/** 所有可跳转的 href（父项自身没有 href 时不算）。 */\nfunction collectHrefs(groups: Sidebar01Group[], footerItems: Sidebar01Item[]) {\n  const hrefs: string[] = []\n  const visit = (item: Sidebar01Item) => {\n    if (item.href) hrefs.push(item.href)\n    for (const sub of item.items ?? []) hrefs.push(sub.href)\n  }\n  for (const group of groups) group.items.forEach(visit)\n  footerItems.forEach(visit)\n  return hrefs\n}\n\n/** 在所有条目里找出与当前地址匹配最长的那个 href（已规范化），没有命中返回 undefined。 */\nfunction findActiveHref(hrefs: string[], currentHref?: string) {\n  if (!currentHref) return undefined\n  const current = normalizeHref(currentHref)\n  let best: string | undefined\n  for (const href of hrefs) {\n    if (!matches(current, href)) continue\n    const normalized = normalizeHref(href)\n    if (!best || normalized.length > best.length) best = normalized\n  }\n  return best\n}\n\n/** 当前页面所在的父项 id，用来决定初始展开哪一项。 */\nfunction findActiveParentId(groups: Sidebar01Group[], activeHref?: string) {\n  if (!activeHref) return undefined\n  for (const group of groups) {\n    for (const item of group.items) {\n      if (item.items?.some((sub) => normalizeHref(sub.href) === activeHref)) {\n        return item.id\n      }\n    }\n  }\n  return undefined\n}\n\n/** 面包屑：分组 → 一级 → 二级，未命中返回空数组。 */\nfunction findTrail(\n  groups: Sidebar01Group[],\n  footerItems: Sidebar01Item[],\n  activeHref?: string,\n) {\n  if (!activeHref) return []\n  for (const group of groups) {\n    for (const item of group.items) {\n      if (item.href && normalizeHref(item.href) === activeHref) {\n        return [group.label, item.label]\n      }\n      const sub = item.items?.find((s) => normalizeHref(s.href) === activeHref)\n      if (sub) return [group.label, item.label, sub.label]\n    }\n  }\n  for (const item of footerItems) {\n    if (item.href && normalizeHref(item.href) === activeHref)\n      return [item.label]\n  }\n  return []\n}\n\n/** 按关键字过滤导航：匹配父项名称时保留全部子项，只匹配子项时只保留命中的子项。 */\nfunction filterGroups(groups: Sidebar01Group[], query: string) {\n  const keyword = query.trim().toLowerCase()\n  if (!keyword) return groups\n  const hit = (text: string) => text.toLowerCase().includes(keyword)\n  return groups\n    .map((group) => ({\n      ...group,\n      items: group.items.flatMap((item): Sidebar01Item[] => {\n        if (hit(item.label)) return [item]\n        const subs = item.items?.filter((sub) => hit(sub.label)) ?? []\n        return subs.length ? [{ ...item, items: subs }] : []\n      }),\n    }))\n    .filter((group) => group.items.length > 0)\n}\n\nfunction formatLabel(template: string, values: Record<string, string>) {\n  return template.replace(/\\{(\\w+)\\}/g, (_, key: string) => values[key] ?? \"\")\n}\n\nexport {\n  collectHrefs,\n  filterGroups,\n  findActiveHref,\n  findActiveParentId,\n  findTrail,\n  formatLabel,\n  normalizeHref,\n}\n",
      "type": "registry:component",
      "target": "@components/sidebar-01/utils.ts"
    }
  ],
  "cssVars": {
    "theme": {
      "color-edge": "var(--edge)"
    },
    "light": {
      "edge": "color-mix(in oklch, var(--foreground) 12%, transparent)"
    },
    "dark": {
      "edge": "color-mix(in oklch, var(--foreground) 18%, transparent)"
    }
  },
  "meta": {
    "iframeHeight": "760px"
  },
  "type": "registry:block"
}
