fumadocs-core 12.0.2 → 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 };
@@ -1,42 +1,56 @@
1
- import "./chunk-UWTMEZUM.js";
1
+ 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;
@@ -2,7 +2,7 @@ import {
2
2
  __objRest,
3
3
  __spreadProps,
4
4
  __spreadValues
5
- } from "./chunk-UWTMEZUM.js";
5
+ } from "./chunk-CWMXXUWU.js";
6
6
 
7
7
  // src/link.tsx
8
8
  import Original from "next/link";
@@ -1,11 +1,11 @@
1
1
  "use client";
2
2
  import {
3
3
  Link
4
- } from "./chunk-2BP57A6C.js";
4
+ } from "./chunk-XB7CNOKH.js";
5
5
  import {
6
6
  __objRest,
7
7
  __spreadValues
8
- } from "./chunk-UWTMEZUM.js";
8
+ } from "./chunk-CWMXXUWU.js";
9
9
 
10
10
  // src/dynamic-link.tsx
11
11
  import { useParams } from "next/navigation";
@@ -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
  }
package/dist/link.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  Link
3
- } from "./chunk-2BP57A6C.js";
4
- import "./chunk-UWTMEZUM.js";
3
+ } from "./chunk-XB7CNOKH.js";
4
+ import "./chunk-CWMXXUWU.js";
5
5
  export {
6
6
  Link as default
7
7
  };
@@ -27,6 +27,7 @@ type RehypeCodeOptions = RehypeShikiOptions & {
27
27
  * Default language
28
28
  *
29
29
  * @defaultValue plaintext
30
+ * @deprecated Use `defaultLanguage` instead
30
31
  */
31
32
  defaultLang?: string;
32
33
  /**
@@ -6,9 +6,8 @@ import {
6
6
  slash
7
7
  } from "../chunk-UWEEHUJV.js";
8
8
  import {
9
- __async,
10
9
  __spreadValues
11
- } from "../chunk-UWTMEZUM.js";
10
+ } from "../chunk-CWMXXUWU.js";
12
11
 
13
12
  // src/mdx-plugins/index.ts
14
13
  import {
@@ -22,20 +21,6 @@ import {
22
21
  transformerNotationWordHighlight
23
22
  } from "@shikijs/transformers";
24
23
 
25
- // src/mdx-plugins/hast-utils.ts
26
- function visit(node, tagNames, handler) {
27
- if (node.type === "element") {
28
- if (tagNames.includes(node.tagName)) {
29
- handler(node);
30
- return;
31
- }
32
- }
33
- if ("children" in node)
34
- node.children.forEach((n) => {
35
- visit(n, tagNames, handler);
36
- });
37
- }
38
-
39
24
  // src/mdx-plugins/transformer-icon.ts
40
25
  import { toEstree } from "hast-util-to-estree";
41
26
  var defaultShortcuts = {
@@ -287,7 +272,7 @@ var rehypeCodeDefaultOptions = {
287
272
  light: "github-light",
288
273
  dark: "github-dark"
289
274
  },
290
- defaultLang: "plaintext",
275
+ defaultLanguage: "plaintext",
291
276
  defaultColor: false,
292
277
  transformers: [
293
278
  transformerNotationHighlight(),
@@ -316,7 +301,7 @@ function rehypeCode(options = {}) {
316
301
  codeOptions.transformers || (codeOptions.transformers = []);
317
302
  codeOptions.transformers = [
318
303
  {
319
- name: "rehype-code:filter-meta",
304
+ name: "rehype-code:pre-process",
320
305
  preprocess(code, { meta }) {
321
306
  var _a;
322
307
  if (meta && codeOptions.filterMetaString) {
@@ -341,33 +326,16 @@ function rehypeCode(options = {}) {
341
326
  transformerIcon(codeOptions.icon)
342
327
  ];
343
328
  }
344
- const prefix = "language-";
345
- const transformer = rehypeShiki.call(this, codeOptions);
346
- return (root, file) => __async(this, null, function* () {
347
- visit(root, ["pre"], (element) => {
348
- var _a;
349
- const head = element.children[0];
350
- if (element.children.length === 0 || head.type !== "element" || head.tagName !== "code")
351
- return;
352
- (_a = head.properties).className || (_a.className = []);
353
- const classes = head.properties.className;
354
- if (!Array.isArray(classes)) return;
355
- const hasLanguage = classes.some(
356
- (d) => typeof d === "string" && d.startsWith(prefix)
357
- );
358
- if (!hasLanguage && codeOptions.defaultLang)
359
- classes.push(`${prefix}${codeOptions.defaultLang}`);
360
- });
361
- if (transformer)
362
- yield transformer.call(this, root, file, () => {
363
- });
364
- });
329
+ if (codeOptions.defaultLang) {
330
+ codeOptions.defaultLanguage = codeOptions.defaultLang;
331
+ }
332
+ return rehypeShiki.call(this, codeOptions);
365
333
  }
366
334
 
367
335
  // src/mdx-plugins/remark-image.ts
368
336
  import { existsSync } from "fs";
369
337
  import path from "path";
370
- import { visit as visit2 } from "unist-util-visit";
338
+ import { visit } from "unist-util-visit";
371
339
  var VALID_BLUR_EXT = [".jpeg", ".png", ".webp", ".avif", ".jpg"];
372
340
  var EXTERNAL_URL_REGEX = /^https?:\/\//;
373
341
  var PUBLIC_DIR = path.join(process.cwd(), "public");
@@ -376,7 +344,7 @@ function remarkImage({
376
344
  } = {}) {
377
345
  return (tree, _file, done) => {
378
346
  const importsToInject = [];
379
- visit2(tree, "image", (node) => {
347
+ visit(tree, "image", (node) => {
380
348
  var _a;
381
349
  let url = decodeURI(node.url);
382
350
  if (!url || EXTERNAL_URL_REGEX.test(url)) {
@@ -460,7 +428,7 @@ import Slugger from "github-slugger";
460
428
  import { remark } from "remark";
461
429
  import remarkGfm from "remark-gfm";
462
430
  import remarkMdx from "remark-mdx";
463
- import { visit as visit3 } from "unist-util-visit";
431
+ import { visit as visit2 } from "unist-util-visit";
464
432
  var slugger = new Slugger();
465
433
  function remarkStructure({
466
434
  types = ["paragraph", "blockquote", "heading"]
@@ -469,7 +437,7 @@ function remarkStructure({
469
437
  slugger.reset();
470
438
  const data = { contents: [], headings: [] };
471
439
  let lastHeading = "";
472
- visit3(node, types, (element) => {
440
+ visit2(node, types, (element) => {
473
441
  var _a, _b;
474
442
  if (element.type === "root") return;
475
443
  const content = flattenNode(element).trim();
@@ -1,4 +1,4 @@
1
- import "./chunk-UWTMEZUM.js";
1
+ import "./chunk-CWMXXUWU.js";
2
2
 
3
3
  // src/middleware.ts
4
4
  import { match as matchLocale } from "@formatjs/intl-localematcher";
@@ -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
1
  import {
2
2
  __async
3
- } from "../chunk-UWTMEZUM.js";
3
+ } from "../chunk-CWMXXUWU.js";
4
4
 
5
5
  // src/search/client.ts
6
6
  import { useEffect, useState } from "react";
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  __spreadProps,
3
3
  __spreadValues
4
- } from "../chunk-UWTMEZUM.js";
4
+ } from "../chunk-CWMXXUWU.js";
5
5
 
6
6
  // src/search/server.ts
7
7
  import { Document } from "flexsearch";
@@ -2,7 +2,7 @@ import {
2
2
  __async,
3
3
  __objRest,
4
4
  __spreadValues
5
- } from "../chunk-UWTMEZUM.js";
5
+ } from "../chunk-CWMXXUWU.js";
6
6
 
7
7
  // src/search-algolia/client.ts
8
8
  import { useState } from "react";
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  __async,
3
3
  __spreadValues
4
- } from "../chunk-UWTMEZUM.js";
4
+ } from "../chunk-CWMXXUWU.js";
5
5
 
6
6
  // src/search-algolia/server.ts
7
7
  import { randomUUID } from "crypto";
@@ -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
  /**
@@ -3,7 +3,7 @@ import {
3
3
  } from "../chunk-QRNTLL6S.js";
4
4
  import {
5
5
  __async
6
- } from "../chunk-UWTMEZUM.js";
6
+ } from "../chunk-CWMXXUWU.js";
7
7
 
8
8
  // src/server/get-toc.ts
9
9
  import { remark } from "remark";
package/dist/sidebar.js CHANGED
@@ -2,7 +2,7 @@ import {
2
2
  __objRest,
3
3
  __spreadProps,
4
4
  __spreadValues
5
- } from "./chunk-UWTMEZUM.js";
5
+ } from "./chunk-CWMXXUWU.js";
6
6
 
7
7
  // src/sidebar.tsx
8
8
  import {
@@ -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;
@@ -5,7 +5,7 @@ import {
5
5
  __export,
6
6
  __objRest,
7
7
  __spreadValues
8
- } from "../chunk-UWTMEZUM.js";
8
+ } from "../chunk-CWMXXUWU.js";
9
9
 
10
10
  // src/source/path.ts
11
11
  import { parse } from "path";
@@ -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)
@@ -6,7 +6,7 @@ import {
6
6
  __objRest,
7
7
  __spreadProps,
8
8
  __spreadValues
9
- } from "./chunk-UWTMEZUM.js";
9
+ } from "./chunk-CWMXXUWU.js";
10
10
 
11
11
  // src/toc-internal.tsx
12
12
  import {
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/dist/toc.js CHANGED
@@ -6,7 +6,7 @@ import {
6
6
  __objRest,
7
7
  __spreadProps,
8
8
  __spreadValues
9
- } from "./chunk-UWTMEZUM.js";
9
+ } from "./chunk-CWMXXUWU.js";
10
10
 
11
11
  // src/toc.tsx
12
12
  import {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fumadocs-core",
3
- "version": "12.0.2",
3
+ "version": "12.0.4",
4
4
  "description": "The library for building a documentation website in Next.js",
5
5
  "keywords": [
6
6
  "NextJs",
@@ -120,8 +120,8 @@
120
120
  ],
121
121
  "dependencies": {
122
122
  "@formatjs/intl-localematcher": "^0.5.4",
123
- "@shikijs/rehype": "^1.6.3",
124
- "@shikijs/transformers": "^1.6.3",
123
+ "@shikijs/rehype": "^1.6.4",
124
+ "@shikijs/transformers": "^1.6.4",
125
125
  "flexsearch": "0.7.21",
126
126
  "github-slugger": "^2.0.0",
127
127
  "hast-util-to-estree": "^3.1.0",
@@ -132,7 +132,7 @@
132
132
  "remark-gfm": "^4.0.0",
133
133
  "remark-mdx": "^3.0.1",
134
134
  "scroll-into-view-if-needed": "^3.1.0",
135
- "shiki": "^1.6.3",
135
+ "shiki": "^1.6.4",
136
136
  "swr": "^2.2.5",
137
137
  "unist-util-visit": "^5.0.0"
138
138
  },
@@ -148,7 +148,7 @@
148
148
  "@types/react": "^18.3.3",
149
149
  "@types/react-dom": "^18.3.0",
150
150
  "algoliasearch": "^4.23.3",
151
- "next": "^14.2.3",
151
+ "next": "^14.2.4",
152
152
  "unified": "^11.0.4",
153
153
  "eslint-config-custom": "0.0.0",
154
154
  "tsconfig": "0.0.0"
File without changes