fumadocs-core 15.0.6 → 15.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.
@@ -1,5 +1,5 @@
1
1
  import { ReactNode } from 'react';
2
- import { R as Root, N as Node } from './page-tree-r8qjoUla.js';
2
+ import { R as Root, N as Node } from './page-tree-B1oLifVu.js';
3
3
 
4
4
  interface BreadcrumbItem {
5
5
  name: ReactNode;
@@ -19,23 +19,21 @@ var defaultThemes = {
19
19
  light: "github-light",
20
20
  dark: "github-dark"
21
21
  };
22
+ var defaultEngine;
22
23
  async function _highlight(code, options) {
23
24
  const { getSingletonHighlighter } = await import("shiki");
24
- const { lang, components: _, engine: defaultEngine, ...rest } = options;
25
+ const { lang, components: _, engine, ...rest } = options;
25
26
  let themes = { themes: defaultThemes };
26
27
  if ("theme" in options && options.theme) {
27
28
  themes = { theme: options.theme };
28
29
  } else if ("themes" in options && options.themes) {
29
30
  themes = { themes: options.themes };
30
31
  }
31
- let engine = defaultEngine;
32
- if (!engine) {
33
- const { createOnigurumaEngine } = await import("shiki/engine/oniguruma");
34
- engine = await createOnigurumaEngine(await import("shiki/wasm"));
35
- }
36
32
  const highlighter = await getSingletonHighlighter({
37
33
  langs: [lang],
38
- engine,
34
+ engine: engine ?? (defaultEngine ??= await import("shiki/engine/oniguruma").then(
35
+ (res) => res.createOnigurumaEngine(import("shiki/wasm"))
36
+ )),
39
37
  themes: "theme" in themes ? [themes.theme] : Object.values(themes.themes).filter((v) => v !== void 0)
40
38
  });
41
39
  return highlighter.codeToHast(code, {
@@ -9,7 +9,7 @@ import {
9
9
  import {
10
10
  createStyleTransformer,
11
11
  defaultThemes
12
- } from "../chunk-VD7J34CI.js";
12
+ } from "../chunk-SCQ5QN2V.js";
13
13
  import "../chunk-MLKGABMK.js";
14
14
 
15
15
  // src/mdx-plugins/index.ts
@@ -18,6 +18,7 @@ interface Item {
18
18
  interface Separator {
19
19
  type: 'separator';
20
20
  name: ReactNode;
21
+ icon?: ReactElement;
21
22
  }
22
23
  interface Folder {
23
24
  $ref?: {
@@ -8,7 +8,7 @@ import 'mdast';
8
8
  import 'unified';
9
9
  import 'unist-util-visit';
10
10
  import 'react';
11
- import '../page-tree-r8qjoUla.js';
11
+ import '../page-tree-B1oLifVu.js';
12
12
 
13
13
  type AdvancedDocument = TypedDocument<Orama<typeof advancedSchema>>;
14
14
  declare const advancedSchema: {
@@ -1,6 +1,6 @@
1
1
  export { a as TOCItemType, T as TableOfContents, g as getTableOfContents } from '../get-toc-Cr2URuiP.js';
2
- import { N as Node, I as Item, R as Root } from '../page-tree-r8qjoUla.js';
3
- export { p as PageTree } from '../page-tree-r8qjoUla.js';
2
+ import { N as Node, I as Item, R as Root } from '../page-tree-B1oLifVu.js';
3
+ export { p as PageTree } from '../page-tree-B1oLifVu.js';
4
4
  export { S as SortedResult } from '../types-Ch8gnVgO.js';
5
5
  import { Metadata } from 'next';
6
6
  import { NextRequest } from 'next/server';
@@ -4,7 +4,7 @@ import {
4
4
  import {
5
5
  createStyleTransformer,
6
6
  highlight
7
- } from "../chunk-VD7J34CI.js";
7
+ } from "../chunk-SCQ5QN2V.js";
8
8
  import "../chunk-MLKGABMK.js";
9
9
 
10
10
  // src/server/get-toc.ts
@@ -1,6 +1,6 @@
1
1
  import { ReactElement } from 'react';
2
2
  import { I as I18nConfig } from '../config-inq6kP6y.js';
3
- import { R as Root, I as Item, F as Folder$1, S as Separator } from '../page-tree-r8qjoUla.js';
3
+ import { R as Root, I as Item, F as Folder$1, S as Separator } from '../page-tree-B1oLifVu.js';
4
4
 
5
5
  interface FileInfo {
6
6
  /**
@@ -13,7 +13,7 @@ import {
13
13
  // src/source/page-tree-builder.ts
14
14
  var group = /^\((?<name>.+)\)$/;
15
15
  var link = /^(?:\[(?<icon>[^\]]+)])?\[(?<name>[^\]]+)]\((?<url>[^)]+)\)$/;
16
- var separator = /^---(?<name>.*?)---$/;
16
+ var separator = /^---(?:\[(?<icon>[^\]]+)])?(?<name>.+)---$/;
17
17
  var rest = "...";
18
18
  var restReversed = "z...a";
19
19
  var extractPrefix = "...";
@@ -52,9 +52,10 @@ function resolveFolderItem(folder, item, ctx, addedNodePaths) {
52
52
  if (match?.groups) {
53
53
  const node = {
54
54
  type: "separator",
55
+ icon: ctx.options.resolveIcon?.(match.groups.icon),
55
56
  name: match.groups.name
56
57
  };
57
- return [ctx.options.attachSeparator?.(node) ?? node];
58
+ return [removeUndefined(ctx.options.attachSeparator?.(node) ?? node)];
58
59
  }
59
60
  match = link.exec(item);
60
61
  if (match?.groups) {
@@ -89,8 +90,7 @@ function resolveFolderItem(folder, item, ctx, addedNodePaths) {
89
90
  }
90
91
  function buildFolderNode(folder, isGlobalRoot, ctx) {
91
92
  const metaPath = resolvePath(folder.file.path, "meta");
92
- let meta = ctx.storage.read(metaPath, "meta");
93
- meta = findLocalizedFile(metaPath, "meta", ctx) ?? meta;
93
+ const meta = findLocalizedFile(metaPath, "meta", ctx) ?? ctx.storage.read(metaPath, "meta");
94
94
  const indexFile = ctx.storage.read(
95
95
  resolvePath(folder.file.flattenedPath, "index"),
96
96
  "page"
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Don't use this, could be deleted anytime.
3
+ *
4
+ * @internal
5
+ */
6
+ declare function useEffectEvent<F extends (...params: never[]) => unknown>(callback: F): F;
7
+
8
+ export { useEffectEvent };
@@ -0,0 +1,13 @@
1
+ "use client";
2
+ import "../chunk-MLKGABMK.js";
3
+
4
+ // src/utils/use-effect-event.ts
5
+ import { useCallback, useRef } from "react";
6
+ function useEffectEvent(callback) {
7
+ const ref = useRef(callback);
8
+ ref.current = callback;
9
+ return useCallback((...params) => ref.current(...params), []);
10
+ }
11
+ export {
12
+ useEffectEvent
13
+ };
@@ -3,7 +3,7 @@ import {
3
3
  _highlight,
4
4
  _renderHighlight,
5
5
  highlight
6
- } from "../chunk-VD7J34CI.js";
6
+ } from "../chunk-SCQ5QN2V.js";
7
7
  import "../chunk-MLKGABMK.js";
8
8
 
9
9
  // src/utils/use-shiki.tsx
@@ -28,7 +28,6 @@ function getHighlightOptions(from) {
28
28
  engine: jsEngine
29
29
  };
30
30
  }
31
- var cache = /* @__PURE__ */ new Map();
32
31
  function useShiki(code, {
33
32
  defaultValue,
34
33
  scriptKey,
@@ -45,13 +44,9 @@ function useShiki(code, {
45
44
  });
46
45
  const [rendered, setRendered] = useState(() => {
47
46
  if (defaultValue) return defaultValue;
48
- const cached = cache.get(key);
49
- if (cached) return cached;
50
47
  const hast = globalThis._use_shiki?.get(scriptKey);
51
48
  if (hast) {
52
- const node = _renderHighlight(hast, shikiOptions);
53
- cache.set(key, node);
54
- return node;
49
+ return _renderHighlight(hast, shikiOptions);
55
50
  }
56
51
  currentTask.current = void 0;
57
52
  const Pre = options.components?.pre ?? "pre";
@@ -71,7 +66,6 @@ function useShiki(code, {
71
66
  };
72
67
  currentTask.current = task;
73
68
  highlight(code, shikiOptions).then((result) => {
74
- cache.set(key, result);
75
69
  if (!task.aborted) setRendered(result);
76
70
  });
77
71
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fumadocs-core",
3
- "version": "15.0.6",
3
+ "version": "15.0.8",
4
4
  "description": "The library for building a documentation website in Next.js",
5
5
  "keywords": [
6
6
  "NextJs",
@@ -56,6 +56,10 @@
56
56
  "import": "./dist/utils/use-shiki.js",
57
57
  "types": "./dist/utils/use-shiki.d.ts"
58
58
  },
59
+ "./utils/use-effect-event": {
60
+ "import": "./dist/utils/use-effect-event.js",
61
+ "types": "./dist/utils/use-effect-event.d.ts"
62
+ },
59
63
  "./link": {
60
64
  "import": "./dist/link.js",
61
65
  "types": "./dist/link.d.ts"