@next-library/theme 1.0.7 → 1.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/client.js CHANGED
@@ -1,6 +1,6 @@
1
1
  'use client';
2
2
  import * as React6 from 'react';
3
- import React6__default, { useState, useRef, useEffect, useCallback, useMemo } from 'react';
3
+ import React6__default, { useState, useRef, useEffect, useCallback, useMemo, useSyncExternalStore } from 'react';
4
4
  import { useScroll, useMotionValueEvent, motion } from 'motion/react';
5
5
  import { clsx } from 'clsx';
6
6
  import { twMerge } from 'tailwind-merge';
@@ -2293,7 +2293,7 @@ function StickyBanner({
2293
2293
  locale = "en",
2294
2294
  closeLabel
2295
2295
  }) {
2296
- const [open, setOpen] = useState(true);
2296
+ const [open2, setOpen] = useState(true);
2297
2297
  const { scrollY } = useScroll();
2298
2298
  const translations2 = getTranslations(locale);
2299
2299
  const ariaLabel = closeLabel || translations2.closeBanner;
@@ -2316,8 +2316,8 @@ function StickyBanner({
2316
2316
  opacity: 0
2317
2317
  },
2318
2318
  animate: {
2319
- y: open ? 0 : -100,
2320
- opacity: open ? 1 : 0
2319
+ y: open2 ? 0 : -100,
2320
+ opacity: open2 ? 1 : 0
2321
2321
  },
2322
2322
  transition: {
2323
2323
  duration: 0.3,
@@ -2335,7 +2335,7 @@ function StickyBanner({
2335
2335
  scale: 1
2336
2336
  },
2337
2337
  className: "absolute top-1/2 right-2 -translate-y-1/2 cursor-pointer",
2338
- onClick: () => setOpen(!open),
2338
+ onClick: () => setOpen(!open2),
2339
2339
  "aria-label": ariaLabel,
2340
2340
  children: /* @__PURE__ */ jsx(CloseIcon, { className: "h-5 w-5 text-white", "aria-hidden": "true" })
2341
2341
  }
@@ -2487,7 +2487,7 @@ function SearchBar({ language = "en", className }) {
2487
2487
  const router = useRouter();
2488
2488
  const translations2 = getTranslations(language);
2489
2489
  const [mounted, setMounted] = useState(false);
2490
- const [open, setOpen] = useState(false);
2490
+ const [open2, setOpen] = useState(false);
2491
2491
  const [query, setQuery] = useState("");
2492
2492
  const [results, setResults] = useState([]);
2493
2493
  const [recent, setRecent] = useState([]);
@@ -2534,7 +2534,7 @@ function SearchBar({ language = "en", className }) {
2534
2534
  return () => window.removeEventListener("keydown", onKey);
2535
2535
  }, [isMac]);
2536
2536
  useEffect(() => {
2537
- if (!open) return;
2537
+ if (!open2) return;
2538
2538
  setRecent(readRecent());
2539
2539
  const t = setTimeout(() => inputRef.current?.focus(), 20);
2540
2540
  const prev = document.body.style.overflow;
@@ -2543,9 +2543,9 @@ function SearchBar({ language = "en", className }) {
2543
2543
  clearTimeout(t);
2544
2544
  document.body.style.overflow = prev;
2545
2545
  };
2546
- }, [open]);
2546
+ }, [open2]);
2547
2547
  useEffect(() => {
2548
- if (!open) return;
2548
+ if (!open2) return;
2549
2549
  if (!query.trim()) {
2550
2550
  setResults([]);
2551
2551
  setIsLoading(false);
@@ -2566,10 +2566,10 @@ function SearchBar({ language = "en", className }) {
2566
2566
  }
2567
2567
  }, 180);
2568
2568
  return () => clearTimeout(id2);
2569
- }, [query, language, open]);
2569
+ }, [query, language, open2]);
2570
2570
  const flat = useMemo(() => query.trim() ? results : [], [query, results]);
2571
2571
  useEffect(() => {
2572
- if (!open) return;
2572
+ if (!open2) return;
2573
2573
  const onKey = (e) => {
2574
2574
  if (e.key === "Escape") {
2575
2575
  e.preventDefault();
@@ -2588,7 +2588,7 @@ function SearchBar({ language = "en", className }) {
2588
2588
  };
2589
2589
  window.addEventListener("keydown", onKey);
2590
2590
  return () => window.removeEventListener("keydown", onKey);
2591
- }, [open, flat, selected, close, go]);
2591
+ }, [open2, flat, selected, close, go]);
2592
2592
  useEffect(() => {
2593
2593
  const node = listRef.current?.querySelector('[data-selected="true"]');
2594
2594
  node?.scrollIntoView({ block: "nearest" });
@@ -2615,7 +2615,7 @@ function SearchBar({ language = "en", className }) {
2615
2615
  ]
2616
2616
  }
2617
2617
  );
2618
- const modal = open && mounted ? createPortal(
2618
+ const modal = open2 && mounted ? createPortal(
2619
2619
  /* @__PURE__ */ jsxs("div", { className: "fixed inset-0 z-[100] flex items-start justify-center p-4 pt-[12vh]", role: "dialog", "aria-modal": "true", children: [
2620
2620
  /* @__PURE__ */ jsx("div", { className: "absolute inset-0 bg-background/70 backdrop-blur-sm", onClick: close, "aria-hidden": "true" }),
2621
2621
  /* @__PURE__ */ jsx("div", { className: "cl-beam relative w-full max-w-xl shadow-[0_30px_90px_-24px_rgb(0_0_0/0.55)]", children: /* @__PURE__ */ jsxs("div", { className: "overflow-hidden rounded-[calc(var(--radius)+2px)] bg-popover", children: [
@@ -3466,10 +3466,10 @@ function SidebarProvider({
3466
3466
  const isMobile = useIsMobile();
3467
3467
  const [openMobile, setOpenMobile] = React6.useState(false);
3468
3468
  const [_open, _setOpen] = React6.useState(defaultOpen);
3469
- const open = openProp ?? _open;
3469
+ const open2 = openProp ?? _open;
3470
3470
  const setOpen = React6.useCallback(
3471
3471
  (value) => {
3472
- const openState = typeof value === "function" ? value(open) : value;
3472
+ const openState = typeof value === "function" ? value(open2) : value;
3473
3473
  if (setOpenProp) {
3474
3474
  setOpenProp(openState);
3475
3475
  } else {
@@ -3477,10 +3477,10 @@ function SidebarProvider({
3477
3477
  }
3478
3478
  document.cookie = `${SIDEBAR_COOKIE_NAME}=${openState}; path=/; max-age=${SIDEBAR_COOKIE_MAX_AGE}`;
3479
3479
  },
3480
- [setOpenProp, open]
3480
+ [setOpenProp, open2]
3481
3481
  );
3482
3482
  const toggleSidebar = React6.useCallback(() => {
3483
- return isMobile ? setOpenMobile((open2) => !open2) : setOpen((open2) => !open2);
3483
+ return isMobile ? setOpenMobile((open3) => !open3) : setOpen((open3) => !open3);
3484
3484
  }, [isMobile, setOpen, setOpenMobile]);
3485
3485
  React6.useEffect(() => {
3486
3486
  const handleKeyDown = (event) => {
@@ -3492,18 +3492,18 @@ function SidebarProvider({
3492
3492
  window.addEventListener("keydown", handleKeyDown);
3493
3493
  return () => window.removeEventListener("keydown", handleKeyDown);
3494
3494
  }, [toggleSidebar]);
3495
- const state = open ? "expanded" : "collapsed";
3495
+ const state = open2 ? "expanded" : "collapsed";
3496
3496
  const contextValue = React6.useMemo(
3497
3497
  () => ({
3498
3498
  state,
3499
- open,
3499
+ open: open2,
3500
3500
  setOpen,
3501
3501
  isMobile,
3502
3502
  openMobile,
3503
3503
  setOpenMobile,
3504
3504
  toggleSidebar
3505
3505
  }),
3506
- [state, open, setOpen, isMobile, openMobile, setOpenMobile, toggleSidebar]
3506
+ [state, open2, setOpen, isMobile, openMobile, setOpenMobile, toggleSidebar]
3507
3507
  );
3508
3508
  return /* @__PURE__ */ jsx(SidebarContext.Provider, { value: contextValue, children: /* @__PURE__ */ jsx(TooltipProvider, { delayDuration: 0, children: /* @__PURE__ */ jsx(
3509
3509
  "div",
@@ -4043,6 +4043,7 @@ function SidebarNavigation({
4043
4043
  nodes,
4044
4044
  currentPath,
4045
4045
  language: _language = "en",
4046
+ onNavigateLeaf,
4046
4047
  translations: translations2 = {}
4047
4048
  }) {
4048
4049
  const { toggleFolder = "Toggle folder" } = translations2;
@@ -4050,65 +4051,76 @@ function SidebarNavigation({
4050
4051
  if (!node.websitePath) return null;
4051
4052
  const isActive = isActiveNode(node, currentPath);
4052
4053
  const hasActiveChildNode = hasActiveChild(node, currentPath);
4053
- return node.children && Object.keys(node.children).length > 0 ? /* @__PURE__ */ jsx(Collapsible, { className: "group/collapsible", children: /* @__PURE__ */ jsx(SidebarMenu, { children: /* @__PURE__ */ jsxs(SidebarMenuItem, { children: [
4054
- /* @__PURE__ */ jsxs("div", { className: "flex flex-nowrap items-center gap-2", children: [
4055
- /* @__PURE__ */ jsxs(
4056
- Link3,
4057
- {
4058
- href: node.websitePath,
4059
- className: `group/row relative flex flex-nowrap items-center gap-2 flex-auto py-1.5 pl-3 pr-2 rounded-md text-sm transition-colors hover:bg-accent ${isActive ? "bg-accent font-medium text-foreground before:absolute before:inset-y-1 before:left-0 before:w-0.5 before:rounded-full before:bg-foreground" : hasActiveChildNode ? "text-foreground" : "text-muted-foreground hover:text-foreground"}`,
4060
- children: [
4061
- /* @__PURE__ */ jsxs("div", { className: "flex-none", children: [
4062
- /* @__PURE__ */ jsx(FolderOpenIcon, { className: "h-4 w-4 group-data-[state=closed]/collapsible:hidden" }),
4063
- /* @__PURE__ */ jsx(FolderClosedIcon, { className: "h-4 w-4 group-data-[state=open]/collapsible:hidden" })
4064
- ] }),
4065
- /* @__PURE__ */ jsx("span", { className: `flex-auto ${isActive ? "font-medium" : ""}`, children: node.title })
4066
- ]
4067
- }
4068
- ),
4069
- /* @__PURE__ */ jsxs(
4070
- CollapsibleTrigger2,
4071
- {
4072
- className: "p-1.5 rounded-md text-muted-foreground/70 transition-colors hover:bg-accent hover:text-foreground self-center",
4073
- "aria-label": `${toggleFolder}: ${node.title}`,
4074
- children: [
4075
- /* @__PURE__ */ jsx(
4076
- ChevronRight,
4077
- {
4078
- className: "h-4 w-4 group-data-[state=open]/collapsible:hidden",
4079
- "aria-hidden": "true"
4080
- }
4081
- ),
4082
- /* @__PURE__ */ jsx(
4083
- ChevronDown,
4084
- {
4085
- className: "h-4 w-4 group-data-[state=closed]/collapsible:hidden",
4086
- "aria-hidden": "true"
4087
- }
4088
- )
4089
- ]
4090
- }
4091
- )
4092
- ] }),
4093
- /* @__PURE__ */ jsx(CollapsibleContent2, { children: /* @__PURE__ */ jsx(SidebarMenuSub, { children: Object.entries(node.children || {}).map(([, child]) => {
4094
- if (!child.websitePath) return null;
4095
- const isChildActive = isActiveNode(child, currentPath);
4096
- return /* @__PURE__ */ jsx(SidebarMenuItem, { children: /* @__PURE__ */ jsxs(
4097
- Link3,
4098
- {
4099
- href: child.websitePath,
4100
- className: `group/row relative flex items-center gap-2 py-1.5 pl-3 pr-2 rounded-md text-sm transition-colors hover:bg-accent ${isChildActive ? "bg-accent font-medium text-foreground before:absolute before:inset-y-1 before:left-0 before:w-0.5 before:rounded-full before:bg-foreground" : "text-muted-foreground hover:text-foreground"}`,
4101
- children: [
4102
- child.children && Object.keys(child.children).length > 0 ? /* @__PURE__ */ jsx(FolderClosedIcon, { className: "h-4 w-4 flex-none" }) : /* @__PURE__ */ jsx(FileTextIcon, { className: "h-4 w-4 flex-none" }),
4103
- /* @__PURE__ */ jsx("span", { className: "", children: child.title })
4104
- ]
4105
- }
4106
- ) }, child.websitePath);
4107
- }) }) })
4108
- ] }, node.websitePath) }, `menu-${node.websitePath}`) }, node.websitePath) : /* @__PURE__ */ jsx(SidebarMenu, { children: /* @__PURE__ */ jsx(SidebarMenuItem, { children: /* @__PURE__ */ jsxs(
4054
+ return node.children && Object.keys(node.children).length > 0 ? /* @__PURE__ */ jsx(
4055
+ Collapsible,
4056
+ {
4057
+ defaultOpen: isActive || hasActiveChildNode,
4058
+ className: "group/collapsible",
4059
+ children: /* @__PURE__ */ jsx(SidebarMenu, { children: /* @__PURE__ */ jsxs(SidebarMenuItem, { children: [
4060
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-nowrap items-center gap-2", children: [
4061
+ /* @__PURE__ */ jsxs(
4062
+ Link3,
4063
+ {
4064
+ href: node.websitePath,
4065
+ className: `group/row relative flex flex-nowrap items-center gap-2 flex-auto py-1.5 pl-3 pr-2 rounded-md text-sm transition-colors hover:bg-accent ${isActive ? "bg-accent font-medium text-foreground before:absolute before:inset-y-1 before:left-0 before:w-0.5 before:rounded-full before:bg-foreground" : hasActiveChildNode ? "text-foreground" : "text-muted-foreground hover:text-foreground"}`,
4066
+ children: [
4067
+ /* @__PURE__ */ jsxs("div", { className: "flex-none", children: [
4068
+ /* @__PURE__ */ jsx(FolderOpenIcon, { className: "h-4 w-4 group-data-[state=closed]/collapsible:hidden" }),
4069
+ /* @__PURE__ */ jsx(FolderClosedIcon, { className: "h-4 w-4 group-data-[state=open]/collapsible:hidden" })
4070
+ ] }),
4071
+ /* @__PURE__ */ jsx("span", { className: `flex-auto ${isActive ? "font-medium" : ""}`, children: node.title })
4072
+ ]
4073
+ }
4074
+ ),
4075
+ /* @__PURE__ */ jsxs(
4076
+ CollapsibleTrigger2,
4077
+ {
4078
+ className: "p-1.5 rounded-md text-muted-foreground/70 transition-colors hover:bg-accent hover:text-foreground self-center",
4079
+ "aria-label": `${toggleFolder}: ${node.title}`,
4080
+ children: [
4081
+ /* @__PURE__ */ jsx(
4082
+ ChevronRight,
4083
+ {
4084
+ className: "h-4 w-4 group-data-[state=open]/collapsible:hidden",
4085
+ "aria-hidden": "true"
4086
+ }
4087
+ ),
4088
+ /* @__PURE__ */ jsx(
4089
+ ChevronDown,
4090
+ {
4091
+ className: "h-4 w-4 group-data-[state=closed]/collapsible:hidden",
4092
+ "aria-hidden": "true"
4093
+ }
4094
+ )
4095
+ ]
4096
+ }
4097
+ )
4098
+ ] }),
4099
+ /* @__PURE__ */ jsx(CollapsibleContent2, { children: /* @__PURE__ */ jsx(SidebarMenuSub, { children: Object.entries(node.children || {}).map(([, child]) => {
4100
+ if (!child.websitePath) return null;
4101
+ const isChildActive = isActiveNode(child, currentPath);
4102
+ const childIsLeaf = !child.children || Object.keys(child.children).length === 0;
4103
+ return /* @__PURE__ */ jsx(SidebarMenuItem, { children: /* @__PURE__ */ jsxs(
4104
+ Link3,
4105
+ {
4106
+ href: child.websitePath,
4107
+ onClick: childIsLeaf ? onNavigateLeaf : void 0,
4108
+ className: `group/row relative flex items-center gap-2 py-1.5 pl-3 pr-2 rounded-md text-sm transition-colors hover:bg-accent ${isChildActive ? "bg-accent font-medium text-foreground before:absolute before:inset-y-1 before:left-0 before:w-0.5 before:rounded-full before:bg-foreground" : "text-muted-foreground hover:text-foreground"}`,
4109
+ children: [
4110
+ child.children && Object.keys(child.children).length > 0 ? /* @__PURE__ */ jsx(FolderClosedIcon, { className: "h-4 w-4 flex-none" }) : /* @__PURE__ */ jsx(FileTextIcon, { className: "h-4 w-4 flex-none" }),
4111
+ /* @__PURE__ */ jsx("span", { className: "", children: child.title })
4112
+ ]
4113
+ }
4114
+ ) }, child.websitePath);
4115
+ }) }) })
4116
+ ] }, node.websitePath) }, `menu-${node.websitePath}`)
4117
+ },
4118
+ node.websitePath
4119
+ ) : /* @__PURE__ */ jsx(SidebarMenu, { children: /* @__PURE__ */ jsx(SidebarMenuItem, { children: /* @__PURE__ */ jsxs(
4109
4120
  Link3,
4110
4121
  {
4111
4122
  href: node.websitePath,
4123
+ onClick: onNavigateLeaf,
4112
4124
  className: `group/row relative flex items-center gap-2 py-1.5 pl-3 pr-2 rounded-md text-sm transition-colors hover:bg-accent ${isActive ? "bg-accent font-medium text-foreground before:absolute before:inset-y-1 before:left-0 before:w-0.5 before:rounded-full before:bg-foreground" : "text-muted-foreground hover:text-foreground"}`,
4113
4125
  children: [
4114
4126
  /* @__PURE__ */ jsx(FileTextIcon, { className: "h-4 w-4 flex-none" }),
@@ -4118,7 +4130,34 @@ function SidebarNavigation({
4118
4130
  ) }, node.websitePath) }, `menu-${node.websitePath}`);
4119
4131
  }) }) });
4120
4132
  }
4133
+ var open = false;
4134
+ var listeners = /* @__PURE__ */ new Set();
4135
+ function emit() {
4136
+ for (const listener of listeners) listener();
4137
+ }
4138
+ function setMobileMenuOpen(value) {
4139
+ if (open === value) return;
4140
+ open = value;
4141
+ emit();
4142
+ }
4143
+ function subscribe(listener) {
4144
+ listeners.add(listener);
4145
+ return () => {
4146
+ listeners.delete(listener);
4147
+ };
4148
+ }
4149
+ function getSnapshot() {
4150
+ return open;
4151
+ }
4152
+ function getServerSnapshot() {
4153
+ return false;
4154
+ }
4155
+ function useMobileMenuOpen() {
4156
+ const value = useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);
4157
+ return [value, setMobileMenuOpen];
4158
+ }
4121
4159
  function MobileMenu({ pageData, translations: translations2 = {} }) {
4160
+ const [open2, setOpen] = useMobileMenuOpen();
4122
4161
  if (!pageData) {
4123
4162
  return null;
4124
4163
  }
@@ -4128,7 +4167,7 @@ function MobileMenu({ pageData, translations: translations2 = {} }) {
4128
4167
  mobileMenuDescription = "Mobile navigation menu"
4129
4168
  } = translations2;
4130
4169
  const { sidebar, navigation: nav, computed } = pageData;
4131
- return /* @__PURE__ */ jsx("div", { className: "lg:hidden", children: /* @__PURE__ */ jsxs(Drawer, { direction: "right", children: [
4170
+ return /* @__PURE__ */ jsx("div", { className: "lg:hidden", children: /* @__PURE__ */ jsxs(Drawer, { direction: "right", open: open2, onOpenChange: setOpen, children: [
4132
4171
  /* @__PURE__ */ jsx(DrawerTrigger, { asChild: true, children: /* @__PURE__ */ jsxs(Button, { variant: "ghost", size: "icon", className: "h-9 w-9", children: [
4133
4172
  /* @__PURE__ */ jsx(Menu, { className: "h-4 w-4" }),
4134
4173
  /* @__PURE__ */ jsx("span", { className: "sr-only", children: openMobileMenu })
@@ -4163,7 +4202,8 @@ function MobileMenu({ pageData, translations: translations2 = {} }) {
4163
4202
  {
4164
4203
  nodes: sidebar.items,
4165
4204
  currentPath: `/${computed.lang}/docs/${computed.path}`,
4166
- language: computed.lang
4205
+ language: computed.lang,
4206
+ onNavigateLeaf: () => setOpen(false)
4167
4207
  }
4168
4208
  )
4169
4209
  ] })
@@ -4538,7 +4578,7 @@ function useMediaQuery(query) {
4538
4578
  return value;
4539
4579
  }
4540
4580
  function BreadcrumbToggle({ overflowItems, className }) {
4541
- const [open, setOpen] = React6.useState(false);
4581
+ const [open2, setOpen] = React6.useState(false);
4542
4582
  const isDesktop = useMediaQuery("(min-width: 768px)");
4543
4583
  const handleOverflowItemClick = useCallback(() => {
4544
4584
  setOpen(false);
@@ -4546,7 +4586,7 @@ function BreadcrumbToggle({ overflowItems, className }) {
4546
4586
  if (overflowItems.length === 0) {
4547
4587
  return null;
4548
4588
  }
4549
- return /* @__PURE__ */ jsx(BreadcrumbItem, { className, children: isDesktop ? /* @__PURE__ */ jsxs(DropdownMenu, { open, onOpenChange: setOpen, children: [
4589
+ return /* @__PURE__ */ jsx(BreadcrumbItem, { className, children: isDesktop ? /* @__PURE__ */ jsxs(DropdownMenu, { open: open2, onOpenChange: setOpen, children: [
4550
4590
  /* @__PURE__ */ jsxs(
4551
4591
  DropdownMenuTrigger,
4552
4592
  {
@@ -4567,7 +4607,7 @@ function BreadcrumbToggle({ overflowItems, className }) {
4567
4607
  children: item.label
4568
4608
  }
4569
4609
  ) }) }, index)) })
4570
- ] }) : /* @__PURE__ */ jsxs(Drawer, { open, onOpenChange: setOpen, children: [
4610
+ ] }) : /* @__PURE__ */ jsxs(Drawer, { open: open2, onOpenChange: setOpen, children: [
4571
4611
  /* @__PURE__ */ jsx(DrawerTrigger, { "aria-label": "Show more breadcrumb items", children: /* @__PURE__ */ jsx(BreadcrumbEllipsis, { className: "h-4 w-4" }) }),
4572
4612
  /* @__PURE__ */ jsxs(DrawerContent, { children: [
4573
4613
  /* @__PURE__ */ jsx("div", { className: "grid gap-1 p-4 overflow-y-auto", children: overflowItems.map((item, index) => /* @__PURE__ */ jsx(