fumadocs-core 12.0.3 → 12.0.4

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.
@@ -1,11 +1,25 @@
1
- import { R as Root } from './page-tree-_z0bnHIU.js';
2
- import 'react';
1
+ import { ReactNode } from 'react';
2
+ import { R as Root } from './page-tree-BTCDMLTU.js';
3
3
 
4
4
  interface BreadcrumbItem {
5
- name: string;
6
- url: string | null;
5
+ name: ReactNode;
6
+ url?: string;
7
7
  }
8
- declare function useBreadcrumb(url: string, tree: Root): BreadcrumbItem[];
9
- declare function getBreadcrumbItems(url: string, tree: Root): BreadcrumbItem[];
8
+ interface BreadcrumbOptions {
9
+ /**
10
+ * Include the page itself in the breadcrumb items array
11
+ *
12
+ * @defaultValue true
13
+ */
14
+ includePage?: boolean;
15
+ /**
16
+ * Count separator as an item
17
+ *
18
+ * @defaultValue false
19
+ */
20
+ includeSeparator?: boolean;
21
+ }
22
+ declare function useBreadcrumb(url: string, tree: Root, options?: BreadcrumbOptions): BreadcrumbItem[];
23
+ declare function getBreadcrumbItems(url: string, tree: Root, options?: BreadcrumbOptions): BreadcrumbItem[];
10
24
 
11
- export { type BreadcrumbItem, getBreadcrumbItems, useBreadcrumb };
25
+ export { type BreadcrumbItem, type BreadcrumbOptions, getBreadcrumbItems, useBreadcrumb };
@@ -2,41 +2,55 @@ import "./chunk-CWMXXUWU.js";
2
2
 
3
3
  // src/breadcrumb.tsx
4
4
  import { useMemo } from "react";
5
- function useBreadcrumb(url, tree) {
6
- return useMemo(() => getBreadcrumbItems(url, tree), [tree, url]);
5
+ function useBreadcrumb(url, tree, options = {}) {
6
+ return useMemo(
7
+ () => getBreadcrumbItems(url, tree, options),
8
+ [tree, url, options]
9
+ );
7
10
  }
8
- function getBreadcrumbItems(url, tree) {
9
- var _a;
10
- return (_a = searchPath(tree.children, url)) != null ? _a : [];
11
+ function getBreadcrumbItems(url, tree, options = {}) {
12
+ var _a, _b, _c;
13
+ return (_c = searchPath(tree.children, url, {
14
+ includePage: (_a = options.includePage) != null ? _a : true,
15
+ includeSeparator: (_b = options.includeSeparator) != null ? _b : false
16
+ })) != null ? _c : [];
11
17
  }
12
- function searchPath(nodes, url) {
18
+ function searchPath(nodes, url, options) {
13
19
  var _a, _b;
20
+ let separator;
14
21
  for (const node of nodes) {
22
+ if (options.includeSeparator && node.type === "separator")
23
+ separator = node.name;
15
24
  if (node.type === "folder") {
16
- if (node.index && node.index.url === url) {
17
- return [
18
- {
25
+ if (((_a = node.index) == null ? void 0 : _a.url) === url) {
26
+ const items2 = [];
27
+ if (separator) items2.push({ name: separator });
28
+ if (options.includePage)
29
+ items2.push({
19
30
  name: node.index.name,
20
31
  url: node.index.url
21
- }
22
- ];
32
+ });
33
+ return items2;
23
34
  }
24
- const items = searchPath(node.children, url);
25
- if (items !== null) {
35
+ const items = searchPath(node.children, url, options);
36
+ if (items) {
26
37
  items.unshift({
27
38
  name: node.name,
28
- url: (_b = (_a = node.index) == null ? void 0 : _a.url) != null ? _b : null
39
+ url: (_b = node.index) == null ? void 0 : _b.url
29
40
  });
41
+ if (separator) items.unshift({ name: separator });
30
42
  return items;
31
43
  }
32
44
  }
33
45
  if (node.type === "page" && node.url === url) {
34
- return [
35
- {
46
+ const items = [];
47
+ if (separator) items.push({ name: separator });
48
+ if (options.includePage)
49
+ items.push({
36
50
  name: node.name,
37
51
  url: node.url
38
- }
39
- ];
52
+ });
53
+ return items;
40
54
  }
41
55
  }
42
56
  return null;
@@ -1,5 +1,7 @@
1
+ import { ReactNode } from 'react';
2
+
1
3
  interface TOCItemType {
2
- title: string;
4
+ title: ReactNode;
3
5
  url: string;
4
6
  depth: number;
5
7
  }
@@ -1,20 +1,20 @@
1
- import { ReactElement } from 'react';
1
+ import { ReactNode, ReactElement } from 'react';
2
2
 
3
3
  interface Root {
4
- name: string;
4
+ name: ReactNode;
5
5
  children: Node[];
6
6
  }
7
7
  type Node = Item | Separator | Folder;
8
8
  interface Item {
9
9
  type: 'page';
10
- name: string;
10
+ name: ReactNode;
11
11
  url: string;
12
12
  external?: boolean;
13
13
  icon?: ReactElement;
14
14
  }
15
15
  interface Separator {
16
16
  type: 'separator';
17
- name: string;
17
+ name: ReactNode;
18
18
  }
19
19
  interface Folder {
20
20
  /**
@@ -22,7 +22,7 @@ interface Folder {
22
22
  */
23
23
  id?: string;
24
24
  type: 'folder';
25
- name: string;
25
+ name: ReactNode;
26
26
  root?: boolean;
27
27
  defaultOpen?: boolean;
28
28
  index?: Item;
@@ -1,6 +1,6 @@
1
- export { a as TOCItemType, T as TableOfContents, g as getTableOfContents } from '../get-toc-B-AMfFKT.js';
2
- import { N as Node, I as Item, R as Root } from '../page-tree-_z0bnHIU.js';
3
- export { p as PageTree } from '../page-tree-_z0bnHIU.js';
1
+ export { a as TOCItemType, T as TableOfContents, g as getTableOfContents } from '../get-toc-CM4X3hbw.js';
2
+ import { N as Node, I as Item, R as Root } from '../page-tree-BTCDMLTU.js';
3
+ export { p as PageTree } from '../page-tree-BTCDMLTU.js';
4
4
  import 'react';
5
5
 
6
6
  /**
@@ -1,5 +1,5 @@
1
1
  import { ReactElement } from 'react';
2
- import { R as Root, I as Item, F as Folder$1, S as Separator } from '../page-tree-_z0bnHIU.js';
2
+ import { R as Root, I as Item, F as Folder$1, S as Separator } from '../page-tree-BTCDMLTU.js';
3
3
 
4
4
  interface FileInfo {
5
5
  locale?: string;
@@ -1,6 +1,6 @@
1
1
  import * as react from 'react';
2
2
  import { ReactNode, RefObject, AnchorHTMLAttributes } from 'react';
3
- import { T as TableOfContents } from './get-toc-B-AMfFKT.js';
3
+ import { T as TableOfContents } from './get-toc-CM4X3hbw.js';
4
4
 
5
5
  /**
6
6
  * The id of active anchor (doesn't include hash)
package/dist/toc.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as react from 'react';
2
2
  import { HTMLAttributes, RefObject, ReactNode, AnchorHTMLAttributes } from 'react';
3
- import { T as TableOfContents } from './get-toc-B-AMfFKT.js';
3
+ import { T as TableOfContents } from './get-toc-CM4X3hbw.js';
4
4
 
5
5
  declare const useActiveAnchor: (url: string) => boolean;
6
6
  interface TOCProviderProps extends HTMLAttributes<HTMLDivElement> {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fumadocs-core",
3
- "version": "12.0.3",
3
+ "version": "12.0.4",
4
4
  "description": "The library for building a documentation website in Next.js",
5
5
  "keywords": [
6
6
  "NextJs",