fumadocs-ui 16.6.1 → 16.6.2

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.
@@ -398,7 +398,6 @@
398
398
  @source inline("start-0");
399
399
  @source inline("sticky");
400
400
  @source inline("still");
401
- @source inline("string");
402
401
  @source inline("stroke");
403
402
  @source inline("stroke-current/25");
404
403
  @source inline("strokeDasharray");
@@ -66,7 +66,6 @@
66
66
  @source inline("absolute");
67
67
  @source inline("action");
68
68
  @source inline("active");
69
- @source inline("activeType");
70
69
  @source inline("add");
71
70
  @source inline("advanced");
72
71
  @source inline("after");
@@ -93,6 +92,7 @@
93
92
  @source inline("aria-selected");
94
93
  @source inline("as");
95
94
  @source inline("aside");
95
+ @source inline("assume");
96
96
  @source inline("assumes");
97
97
  @source inline("async");
98
98
  @source inline("at");
@@ -619,6 +619,7 @@
619
619
  @source inline("nextIdRef");
620
620
  @source inline("nextPage");
621
621
  @source inline("node");
622
+ @source inline("nodes");
622
623
  @source inline("none");
623
624
  @source inline("noopener");
624
625
  @source inline("noreferrer");
@@ -991,6 +992,7 @@
991
992
  @source inline("type");
992
993
  @source inline("typeof");
993
994
  @source inline("types");
995
+ @source inline("unchanged");
994
996
  @source inline("undefined");
995
997
  @source inline("under");
996
998
  @source inline("underline");
@@ -74,9 +74,11 @@ declare function SidebarViewport(props: ScrollAreaProps): react_jsx_runtime0.JSX
74
74
  declare function SidebarSeparator(props: ComponentProps<'p'>): react_jsx_runtime0.JSX.Element;
75
75
  declare function SidebarItem({
76
76
  icon,
77
+ active,
77
78
  children,
78
79
  ...props
79
80
  }: LinkProps & {
81
+ active?: boolean;
80
82
  icon?: ReactNode;
81
83
  }): react_jsx_runtime0.JSX.Element;
82
84
  declare function SidebarFolder({
@@ -96,8 +98,11 @@ declare function SidebarFolderTrigger({
96
98
  }: CollapsibleTriggerProps): react_jsx_runtime0.JSX.Element;
97
99
  declare function SidebarFolderLink({
98
100
  children,
101
+ active,
99
102
  ...props
100
- }: LinkProps): react_jsx_runtime0.JSX.Element;
103
+ }: LinkProps & {
104
+ active?: boolean;
105
+ }): react_jsx_runtime0.JSX.Element;
101
106
  declare function SidebarFolderContent(props: CollapsibleContentProps): react_jsx_runtime0.JSX.Element;
102
107
  declare function SidebarTrigger({
103
108
  children,
@@ -1,7 +1,6 @@
1
1
  'use client';
2
2
 
3
3
  import { cn } from "../../utils/cn.js";
4
- import { isActive } from "../../utils/urls.js";
5
4
  import { Collapsible, CollapsibleContent, CollapsibleTrigger } from "../ui/collapsible.js";
6
5
  import { ScrollArea, ScrollViewport } from "../ui/scroll-area.js";
7
6
  import { createContext, use, useEffect, useMemo, useRef, useState } from "react";
@@ -134,11 +133,9 @@ function SidebarSeparator(props) {
134
133
  children: props.children
135
134
  });
136
135
  }
137
- function SidebarItem({ icon, children, ...props }) {
138
- const pathname = usePathname();
136
+ function SidebarItem({ icon, active = false, children, ...props }) {
139
137
  const ref = useRef(null);
140
138
  const { prefetch } = useSidebar();
141
- const active = props.href !== void 0 && isActive(props.href, pathname, false);
142
139
  useAutoScroll(active, ref);
143
140
  return /* @__PURE__ */ jsxs(Link, {
144
141
  ref,
@@ -190,12 +187,10 @@ function SidebarFolderTrigger({ children, ...props }) {
190
187
  children
191
188
  });
192
189
  }
193
- function SidebarFolderLink({ children, ...props }) {
190
+ function SidebarFolderLink({ children, active = false, ...props }) {
194
191
  const ref = useRef(null);
195
192
  const { open, setOpen, collapsible } = use(FolderContext);
196
193
  const { prefetch } = useSidebar();
197
- const pathname = usePathname();
198
- const active = props.href !== void 0 && isActive(props.href, pathname, false);
199
194
  useAutoScroll(active, ref);
200
195
  return /* @__PURE__ */ jsxs(Link, {
201
196
  ref,
@@ -1,3 +1,6 @@
1
+ 'use client';
2
+
3
+ import { useLinkItemActive } from "../../utils/link-item.js";
1
4
  import { jsx, jsxs } from "react/jsx-runtime";
2
5
 
3
6
  //#region src/components/sidebar/link-item.tsx
@@ -6,6 +9,7 @@ function createLinkItemRenderer({ SidebarFolder, SidebarFolderContent, SidebarFo
6
9
  * Render sidebar items from page tree
7
10
  */
8
11
  return function SidebarLinkItem({ item, ...props }) {
12
+ const active = useLinkItemActive(item);
9
13
  if (item.type === "custom") return /* @__PURE__ */ jsx("div", {
10
14
  ...props,
11
15
  children: item.children
@@ -14,6 +18,7 @@ function createLinkItemRenderer({ SidebarFolder, SidebarFolderContent, SidebarFo
14
18
  ...props,
15
19
  children: [item.url ? /* @__PURE__ */ jsxs(SidebarFolderLink, {
16
20
  href: item.url,
21
+ active,
17
22
  external: item.external,
18
23
  children: [item.icon, item.text]
19
24
  }) : /* @__PURE__ */ jsxs(SidebarFolderTrigger, { children: [item.icon, item.text] }), /* @__PURE__ */ jsx(SidebarFolderContent, { children: item.items.map((child, i) => /* @__PURE__ */ jsx(SidebarLinkItem, { item: child }, i)) })]
@@ -22,6 +27,7 @@ function createLinkItemRenderer({ SidebarFolder, SidebarFolderContent, SidebarFo
22
27
  href: item.url,
23
28
  icon: item.icon,
24
29
  external: item.external,
30
+ active,
25
31
  ...props,
26
32
  children: item.text
27
33
  });
@@ -1,55 +1,69 @@
1
1
  import { useTreeContext, useTreePath } from "../../contexts/tree.js";
2
- import { Fragment, useMemo } from "react";
2
+ import { isActive } from "../../utils/urls.js";
3
+ import { Fragment, createContext, use, useMemo } from "react";
4
+ import { usePathname } from "fumadocs-core/framework";
3
5
  import { jsx, jsxs } from "react/jsx-runtime";
4
6
 
5
7
  //#region src/components/sidebar/page-tree.tsx
8
+ const RendererContext = createContext(null);
6
9
  function createPageTreeRenderer({ SidebarFolder, SidebarFolderContent, SidebarFolderLink, SidebarFolderTrigger, SidebarSeparator, SidebarItem }) {
7
- function PageTreeFolder({ item, children }) {
8
- const path = useTreePath();
9
- return /* @__PURE__ */ jsxs(SidebarFolder, {
10
- collapsible: item.collapsible,
11
- active: path.includes(item),
12
- defaultOpen: item.defaultOpen,
13
- children: [item.index ? /* @__PURE__ */ jsxs(SidebarFolderLink, {
14
- href: item.index.url,
15
- external: item.index.external,
16
- children: [item.icon, item.name]
17
- }) : /* @__PURE__ */ jsxs(SidebarFolderTrigger, { children: [item.icon, item.name] }), /* @__PURE__ */ jsx(SidebarFolderContent, { children })]
10
+ function renderList(nodes) {
11
+ return nodes.map((node, i) => /* @__PURE__ */ jsx(PageTreeNode, { node }, i));
12
+ }
13
+ function PageTreeNode({ node }) {
14
+ const { Separator, Item, Folder, pathname } = use(RendererContext);
15
+ if (node.type === "separator") {
16
+ if (Separator) return /* @__PURE__ */ jsx(Separator, { item: node });
17
+ return /* @__PURE__ */ jsxs(SidebarSeparator, { children: [node.icon, node.name] });
18
+ }
19
+ if (node.type === "folder") {
20
+ const path = useTreePath();
21
+ if (Folder) return /* @__PURE__ */ jsx(Folder, {
22
+ item: node,
23
+ children: renderList(node.children)
24
+ });
25
+ return /* @__PURE__ */ jsxs(SidebarFolder, {
26
+ collapsible: node.collapsible,
27
+ active: path.includes(node),
28
+ defaultOpen: node.defaultOpen,
29
+ children: [node.index ? /* @__PURE__ */ jsxs(SidebarFolderLink, {
30
+ href: node.index.url,
31
+ active: isActive(node.index.url, pathname),
32
+ external: node.index.external,
33
+ children: [node.icon, node.name]
34
+ }) : /* @__PURE__ */ jsxs(SidebarFolderTrigger, { children: [node.icon, node.name] }), /* @__PURE__ */ jsx(SidebarFolderContent, { children: renderList(node.children) })]
35
+ });
36
+ }
37
+ if (Item) return /* @__PURE__ */ jsx(Item, { item: node });
38
+ return /* @__PURE__ */ jsx(SidebarItem, {
39
+ href: node.url,
40
+ external: node.external,
41
+ active: isActive(node.url, pathname),
42
+ icon: node.icon,
43
+ children: node.name
18
44
  });
19
45
  }
20
46
  /**
21
47
  * Render sidebar items from page tree
22
48
  */
23
49
  return function SidebarPageTree(components) {
50
+ const { Folder, Item, Separator } = components;
24
51
  const { root } = useTreeContext();
25
- const { Separator, Item, Folder = PageTreeFolder } = components;
26
- return useMemo(() => {
27
- function renderSidebarList(items) {
28
- return items.map((item, i) => {
29
- if (item.type === "separator") {
30
- if (Separator) return /* @__PURE__ */ jsx(Separator, { item }, i);
31
- return /* @__PURE__ */ jsxs(SidebarSeparator, { children: [item.icon, item.name] }, i);
32
- }
33
- if (item.type === "folder") return /* @__PURE__ */ jsx(Folder, {
34
- item,
35
- children: renderSidebarList(item.children)
36
- }, i);
37
- if (Item) return /* @__PURE__ */ jsx(Item, { item }, item.url);
38
- return /* @__PURE__ */ jsx(SidebarItem, {
39
- href: item.url,
40
- external: item.external,
41
- icon: item.icon,
42
- children: item.name
43
- }, item.url);
44
- });
45
- }
46
- return /* @__PURE__ */ jsx(Fragment, { children: renderSidebarList(root.children) }, root.$id);
47
- }, [
48
- Folder,
49
- Item,
50
- Separator,
51
- root
52
- ]);
52
+ const pathname = usePathname();
53
+ return /* @__PURE__ */ jsx(RendererContext, {
54
+ value: useMemo(() => ({
55
+ Folder,
56
+ Item,
57
+ Separator,
58
+ pathname
59
+ }), [
60
+ Folder,
61
+ Item,
62
+ Separator,
63
+ pathname
64
+ ]),
65
+ children: /* @__PURE__ */ jsx(Fragment, { children: renderList(root.children) }, root.$id)
66
+ });
53
67
  };
54
68
  }
55
69
 
@@ -150,7 +150,7 @@ function PageFooter({ items, children, className, ...props }) {
150
150
  const pathname = usePathname();
151
151
  const { previous, next } = useMemo(() => {
152
152
  if (items) return items;
153
- const idx = footerList.findIndex((item) => isActive(item.url, pathname, false));
153
+ const idx = footerList.findIndex((item) => isActive(item.url, pathname));
154
154
  if (idx === -1) return {};
155
155
  return {
156
156
  previous: footerList[idx - 1],
@@ -178,7 +178,7 @@ function PageFooter({ items, children, className, ...props }) {
178
178
  const pathname = usePathname();
179
179
  const { previous, next } = useMemo(() => {
180
180
  if (items) return items;
181
- const idx = footerList.findIndex((item) => isActive(item.url, pathname, false));
181
+ const idx = footerList.findIndex((item) => isActive(item.url, pathname));
182
182
  if (idx === -1) return {};
183
183
  return {
184
184
  previous: footerList[idx - 1],
@@ -4,7 +4,7 @@ import * as class_variance_authority_types0 from "class-variance-authority/types
4
4
 
5
5
  //#region src/layouts/home/client.d.ts
6
6
  declare const navItemVariants: (props?: ({
7
- variant?: "icon" | "button" | "main" | null | undefined;
7
+ variant?: "main" | "icon" | "button" | null | undefined;
8
8
  } & class_variance_authority_types0.ClassProp) | undefined) => string;
9
9
  declare function Header({
10
10
  nav,
@@ -150,7 +150,7 @@ function PageFooter({ items, children, className, ...props }) {
150
150
  const pathname = usePathname();
151
151
  const { previous, next } = useMemo(() => {
152
152
  if (items) return items;
153
- const idx = footerList.findIndex((item) => isActive(item.url, pathname, false));
153
+ const idx = footerList.findIndex((item) => isActive(item.url, pathname));
154
154
  if (idx === -1) return {};
155
155
  return {
156
156
  previous: footerList[idx - 1],
@@ -1,4 +1,4 @@
1
- import { ButtonItemType, CustomItemType, IconItemType, LinkItem, LinkItemType, MainItemType, MenuItemType } from "../../utils/link-item.js";
1
+ import { ButtonItemType, CustomItemType, IconItemType, LinkItem, LinkItemType, MainItemType, MenuItemType, useLinkItemActive } from "../../utils/link-item.js";
2
2
  import * as react from "react";
3
3
  import { ComponentProps, ReactNode } from "react";
4
4
  import * as react_jsx_runtime0 from "react/jsx-runtime";
@@ -72,4 +72,4 @@ declare function useLinkItems({
72
72
  all: LinkItemType[];
73
73
  };
74
74
  //#endregion
75
- export { BaseLayoutProps, ButtonItemType, CustomItemType, IconItemType, LinkItem, LinkItemType, MainItemType, MenuItemType, NavOptions, renderTitleNav, resolveLinkItems, useLinkItems };
75
+ export { BaseLayoutProps, ButtonItemType, CustomItemType, IconItemType, LinkItem, LinkItemType, MainItemType, MenuItemType, NavOptions, renderTitleNav, resolveLinkItems, useLinkItemActive, useLinkItems };
@@ -79,7 +79,8 @@ declare function LinkItem({
79
79
  item,
80
80
  ...props
81
81
  }: Omit<ComponentProps<'a'>, 'href'> & {
82
- item: WithHref;
82
+ item: LinkItemType & WithHref;
83
83
  }): react_jsx_runtime0.JSX.Element;
84
+ declare function useLinkItemActive(link: LinkItemType): boolean;
84
85
  //#endregion
85
- export { ButtonItemType, CustomItemType, IconItemType, LinkItem, LinkItemType, MainItemType, MenuItemType };
86
+ export { ButtonItemType, CustomItemType, IconItemType, LinkItem, LinkItemType, MainItemType, MenuItemType, useLinkItemActive };
@@ -7,9 +7,7 @@ import Link from "fumadocs-core/link";
7
7
 
8
8
  //#region src/utils/link-item.tsx
9
9
  function LinkItem({ ref, item, ...props }) {
10
- const pathname = usePathname();
11
- const activeType = item.active ?? "url";
12
- const active = activeType !== "none" && isActive(item.url, pathname, activeType === "nested-url");
10
+ const active = useLinkItemActive(item);
13
11
  return /* @__PURE__ */ jsx(Link, {
14
12
  ref,
15
13
  href: item.url,
@@ -19,6 +17,12 @@ function LinkItem({ ref, item, ...props }) {
19
17
  children: props.children
20
18
  });
21
19
  }
20
+ function useLinkItemActive(link) {
21
+ const pathname = usePathname();
22
+ if (link.type === "custom" || !link.url) return false;
23
+ if (link.active === "none") return false;
24
+ return isActive(link.url, pathname, link.active === "nested-url");
25
+ }
22
26
 
23
27
  //#endregion
24
- export { LinkItem };
28
+ export { LinkItem, useLinkItemActive };
@@ -6,7 +6,7 @@ function normalize(urlOrPath) {
6
6
  /**
7
7
  * @returns if `href` is matching the given pathname
8
8
  */
9
- function isActive(href, pathname, nested = true) {
9
+ function isActive(href, pathname, nested = false) {
10
10
  href = normalize(href);
11
11
  pathname = normalize(pathname);
12
12
  return href === pathname || nested && pathname.startsWith(`${href}/`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fumadocs-ui",
3
- "version": "16.6.1",
3
+ "version": "16.6.2",
4
4
  "description": "The Radix UI version of Fumadocs UI",
5
5
  "keywords": [
6
6
  "Docs",
@@ -135,7 +135,7 @@
135
135
  "unified": "^11.0.5",
136
136
  "@fumadocs/cli": "1.2.4",
137
137
  "eslint-config-custom": "0.0.0",
138
- "fumadocs-core": "16.6.1",
138
+ "fumadocs-core": "16.6.2",
139
139
  "tsconfig": "0.0.0"
140
140
  },
141
141
  "peerDependencies": {
@@ -143,7 +143,7 @@
143
143
  "next": "16.x.x",
144
144
  "react": "^19.2.0",
145
145
  "react-dom": "^19.2.0",
146
- "fumadocs-core": "16.6.1"
146
+ "fumadocs-core": "16.6.2"
147
147
  },
148
148
  "peerDependenciesMeta": {
149
149
  "next": {