fumadocs-core 15.0.15 → 15.0.17

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.
@@ -9,9 +9,11 @@ import {
9
9
  useId,
10
10
  useMemo,
11
11
  useRef,
12
- useState
12
+ use,
13
+ useState,
14
+ useLayoutEffect
13
15
  } from "react";
14
- import { Fragment, jsx, jsxs } from "react/jsx-runtime";
16
+ import { jsx } from "react/jsx-runtime";
15
17
  var jsEngine;
16
18
  function getHighlightOptions(from) {
17
19
  if (from.engine) return from;
@@ -30,7 +32,7 @@ function useShiki(code, {
30
32
  withPrerenderScript = false,
31
33
  ...options
32
34
  }, deps) {
33
- const scriptKey = useId();
35
+ const markupId = useId();
34
36
  const key = useMemo(
35
37
  () => deps ? JSON.stringify(deps) : `${options.lang}:${code}`,
36
38
  [code, deps, options.lang]
@@ -42,27 +44,19 @@ function useShiki(code, {
42
44
  });
43
45
  const [rendered, setRendered] = useState(() => {
44
46
  if (defaultValue) return defaultValue;
45
- const hast = globalThis._use_shiki?.get(scriptKey);
46
- if (hast && withPrerenderScript) {
47
- return /* @__PURE__ */ jsxs(Fragment, { children: [
48
- /* @__PURE__ */ jsx(PrerenderScript, { scriptKey, tree: hast }),
49
- _renderHighlight(hast, shikiOptions)
50
- ] });
47
+ const element = withPrerenderScript && typeof document !== "undefined" ? document.querySelector(`[data-markup-id="${markupId}"]`) : null;
48
+ const attr = element?.getAttribute("data-markup");
49
+ if (attr) {
50
+ const hast = JSON.parse(attr);
51
+ return renderHighlightWithMarkup(markupId, hast, shikiOptions, attr);
51
52
  }
52
53
  currentTask.current = void 0;
53
54
  const Pre = options.components?.pre ?? "pre";
54
55
  const Code = options.components?.code ?? "code";
55
56
  return /* @__PURE__ */ jsx(Pre, { children: /* @__PURE__ */ jsx(Code, { children: code }) });
56
57
  });
57
- if (typeof window === "undefined") {
58
- return _highlight(code, shikiOptions).then((tree) => {
59
- return /* @__PURE__ */ jsxs(Fragment, { children: [
60
- withPrerenderScript && /* @__PURE__ */ jsx(PrerenderScript, { scriptKey, tree }),
61
- _renderHighlight(tree, shikiOptions)
62
- ] });
63
- });
64
- }
65
- if (!currentTask.current || currentTask.current.key !== key) {
58
+ useLayoutEffect(() => {
59
+ if (currentTask.current?.key === key) return;
66
60
  if (currentTask.current) {
67
61
  currentTask.current.aborted = true;
68
62
  }
@@ -74,15 +68,32 @@ function useShiki(code, {
74
68
  void highlight(code, shikiOptions).then((result) => {
75
69
  if (!task.aborted) setRendered(result);
76
70
  });
71
+ }, [key]);
72
+ if (typeof window === "undefined") {
73
+ return use(
74
+ _highlight(code, shikiOptions).then(
75
+ (tree) => renderHighlightWithMarkup(markupId, tree, shikiOptions)
76
+ )
77
+ );
77
78
  }
78
79
  return rendered;
79
80
  }
80
- function PrerenderScript({
81
- scriptKey,
82
- tree
83
- }) {
84
- return /* @__PURE__ */ jsx("script", { children: `if (typeof globalThis._use_shiki === "undefined") globalThis._use_shiki = new Map()
85
- globalThis._use_shiki.set(${JSON.stringify(scriptKey)}, ${JSON.stringify(tree)})` });
81
+ function renderHighlightWithMarkup(id, tree, shikiOptions, rawAttr) {
82
+ const Pre = shikiOptions.components?.pre ?? "pre";
83
+ return _renderHighlight(tree, {
84
+ ...shikiOptions,
85
+ components: {
86
+ ...shikiOptions.components,
87
+ pre: (props) => /* @__PURE__ */ jsx(
88
+ Pre,
89
+ {
90
+ ...props,
91
+ "data-markup-id": id,
92
+ "data-markup": rawAttr ?? JSON.stringify(tree)
93
+ }
94
+ )
95
+ }
96
+ });
86
97
  }
87
98
 
88
99
  export {
@@ -1,15 +1,9 @@
1
1
  import { ReactNode, DependencyList } from 'react';
2
2
  import { HighlightOptions } from './index.js';
3
- import { Root } from 'hast';
4
3
  import 'shiki';
5
4
  import 'shiki/themes';
6
5
  import 'hast-util-to-jsx-runtime';
7
6
 
8
- declare global {
9
- interface Window {
10
- _use_shiki?: Map<string, Root>;
11
- }
12
- }
13
7
  declare function useShiki(code: string, { defaultValue, withPrerenderScript, ...options }: HighlightOptions & {
14
8
  withPrerenderScript?: boolean;
15
9
  defaultValue?: ReactNode;
@@ -1,7 +1,7 @@
1
1
  "use client";
2
2
  import {
3
3
  useShiki
4
- } from "../chunk-QWBSUU36.js";
4
+ } from "../chunk-Q73QZKHO.js";
5
5
  import "../chunk-E7AASGCN.js";
6
6
  import "../chunk-MLKGABMK.js";
7
7
  export {
@@ -5,7 +5,42 @@ import "./chunk-MLKGABMK.js";
5
5
 
6
6
  // src/search/client/orama-cloud.ts
7
7
  async function searchDocs(query, tag, options) {
8
- const { client, params: extraParams = {} } = options;
8
+ const list = [];
9
+ const { index = "default", client, params: extraParams = {} } = options;
10
+ if (index === "crawler") {
11
+ const result2 = await client.search({
12
+ ...extraParams,
13
+ term: query,
14
+ where: {
15
+ category: tag ? {
16
+ eq: tag.slice(0, 1).toUpperCase() + tag.slice(1)
17
+ } : void 0,
18
+ ...extraParams.where
19
+ },
20
+ limit: 10
21
+ });
22
+ if (!result2) return list;
23
+ if (index === "crawler") {
24
+ for (const hit of result2.hits) {
25
+ const doc = hit.document;
26
+ list.push(
27
+ {
28
+ id: hit.id,
29
+ type: "page",
30
+ content: doc.title,
31
+ url: doc.path
32
+ },
33
+ {
34
+ id: "page" + hit.id,
35
+ type: "text",
36
+ content: doc.content,
37
+ url: doc.path
38
+ }
39
+ );
40
+ }
41
+ return list;
42
+ }
43
+ }
9
44
  const params = {
10
45
  ...extraParams,
11
46
  term: query,
@@ -20,9 +55,8 @@ async function searchDocs(query, tag, options) {
20
55
  }
21
56
  };
22
57
  const result = await client.search(params);
23
- if (!result) return [];
24
- const list = [];
25
- for (const item of result.groups ?? []) {
58
+ if (!result || !result.groups) return list;
59
+ for (const item of result.groups) {
26
60
  let addedHead = false;
27
61
  for (const hit of item.result) {
28
62
  const doc = hit.document;
@@ -28,6 +28,12 @@ interface AlgoliaOptions extends SearchOptions {
28
28
 
29
29
  interface OramaCloudOptions {
30
30
  client: OramaClient;
31
+ /**
32
+ * The type of your index.
33
+ *
34
+ * You can set it to `crawler` if you use crawler instead of the JSON index with schema provided by Fumadocs
35
+ */
36
+ index?: 'default' | 'crawler';
31
37
  params?: ClientSearchParams;
32
38
  }
33
39
 
@@ -53,7 +53,7 @@ function useDocsSearch(client, locale, tag, delayMs = 100, allowEmpty = false, k
53
53
  return searchDocs(index, debouncedValue, tag, rest);
54
54
  }
55
55
  if (client.type === "orama-cloud") {
56
- const { searchDocs } = await import("../orama-cloud-NHMXDFR2.js");
56
+ const { searchDocs } = await import("../orama-cloud-USLSOSXS.js");
57
57
  return searchDocs(debouncedValue, tag, client);
58
58
  }
59
59
  const { createStaticClient } = await import("../static-VESU2S64.js");
@@ -1,7 +1,7 @@
1
+ import "../chunk-WQMD6AUR.js";
1
2
  import {
2
3
  remarkHeading
3
4
  } from "../chunk-IYQ35KI2.js";
4
- import "../chunk-WQMD6AUR.js";
5
5
  import {
6
6
  createStyleTransformer,
7
7
  highlight
@@ -4,4 +4,3 @@ import '../highlight/index.js';
4
4
  import 'shiki';
5
5
  import 'shiki/themes';
6
6
  import 'hast-util-to-jsx-runtime';
7
- import 'hast';
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  useShiki
3
- } from "../chunk-QWBSUU36.js";
3
+ } from "../chunk-Q73QZKHO.js";
4
4
  import "../chunk-E7AASGCN.js";
5
5
  import "../chunk-MLKGABMK.js";
6
6
  export {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fumadocs-core",
3
- "version": "15.0.15",
3
+ "version": "15.0.17",
4
4
  "description": "The library for building a documentation website in Next.js",
5
5
  "keywords": [
6
6
  "NextJs",
@@ -90,19 +90,19 @@
90
90
  ],
91
91
  "dependencies": {
92
92
  "@formatjs/intl-localematcher": "^0.6.0",
93
- "@orama/orama": "^3.1.1",
94
- "@shikijs/rehype": "^3.1.0",
95
- "@shikijs/transformers": "^3.1.0",
93
+ "@orama/orama": "^3.1.3",
94
+ "@shikijs/rehype": "^3.2.1",
95
+ "@shikijs/transformers": "^3.2.1",
96
96
  "github-slugger": "^2.0.0",
97
- "hast-util-to-estree": "^3.1.2",
98
- "hast-util-to-jsx-runtime": "^2.3.5",
99
- "image-size": "^2.0.0",
97
+ "hast-util-to-estree": "^3.1.3",
98
+ "hast-util-to-jsx-runtime": "^2.3.6",
99
+ "image-size": "^2.0.1",
100
100
  "negotiator": "^1.0.0",
101
101
  "react-remove-scroll": "^2.6.3",
102
102
  "remark": "^15.0.0",
103
103
  "remark-gfm": "^4.0.1",
104
104
  "scroll-into-view-if-needed": "^3.1.0",
105
- "shiki": "^3.1.0",
105
+ "shiki": "^3.2.1",
106
106
  "unist-util-visit": "^5.0.0"
107
107
  },
108
108
  "devDependencies": {
@@ -113,13 +113,13 @@
113
113
  "@types/hast": "^3.0.4",
114
114
  "@types/mdast": "^4.0.3",
115
115
  "@types/negotiator": "^0.6.3",
116
- "@types/node": "22.13.8",
116
+ "@types/node": "22.13.10",
117
117
  "@types/react": "^19.0.10",
118
118
  "@types/react-dom": "^19.0.4",
119
119
  "algoliasearch": "4.24.0",
120
120
  "mdast-util-mdx-jsx": "^3.2.0",
121
121
  "mdast-util-mdxjs-esm": "^2.0.1",
122
- "next": "^15.2.0",
122
+ "next": "^15.2.2",
123
123
  "remark-mdx": "^3.1.0",
124
124
  "remark-rehype": "^11.1.1",
125
125
  "typescript": "^5.8.2",