fumadocs-core 12.5.3 → 12.5.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,6 +1,4 @@
1
- import {
2
- __objRest
3
- } from "./chunk-CWMXXUWU.js";
1
+ import "./chunk-MLKGABMK.js";
4
2
 
5
3
  // src/breadcrumb.tsx
6
4
  import { useMemo } from "react";
@@ -11,9 +9,8 @@ function useBreadcrumb(url, tree, options) {
11
9
  );
12
10
  }
13
11
  function getBreadcrumbItems(url, tree, options = {}) {
14
- var _b;
15
- const _a = options, { includeRoot } = _a, rest = __objRest(_a, ["includeRoot"]);
16
- const path = (_b = searchPath(tree.children, url, rest)) != null ? _b : [];
12
+ const { includeRoot, ...rest } = options;
13
+ const path = searchPath(tree.children, url, rest) ?? [];
17
14
  if (includeRoot) {
18
15
  path.unshift({
19
16
  name: tree.name,
@@ -23,13 +20,12 @@ function getBreadcrumbItems(url, tree, options = {}) {
23
20
  return path;
24
21
  }
25
22
  function searchPath(nodes, url, options) {
26
- var _a, _b;
27
23
  const { includePage = true, includeSeparator = false } = options;
28
24
  let separator;
29
25
  for (const node of nodes) {
30
26
  if (includeSeparator && node.type === "separator") separator = node.name;
31
27
  if (node.type === "folder") {
32
- if (((_a = node.index) == null ? void 0 : _a.url) === url) {
28
+ if (node.index?.url === url) {
33
29
  const items2 = [];
34
30
  if (separator) items2.push({ name: separator });
35
31
  if (options.includePage)
@@ -43,7 +39,7 @@ function searchPath(nodes, url, options) {
43
39
  if (items) {
44
40
  items.unshift({
45
41
  name: node.name,
46
- url: (_b = node.index) == null ? void 0 : _b.url
42
+ url: node.index?.url
47
43
  });
48
44
  if (separator) items.unshift({ name: separator });
49
45
  return items;
@@ -0,0 +1,42 @@
1
+ // src/link.tsx
2
+ import Original from "next/link";
3
+ import { forwardRef } from "react";
4
+ import { jsx } from "react/jsx-runtime";
5
+ var Link = forwardRef(
6
+ ({
7
+ href = "#",
8
+ external = !(href.startsWith("/") || href.startsWith("#") || href.startsWith(".")),
9
+ prefetch,
10
+ replace,
11
+ ...props
12
+ }, ref) => {
13
+ if (external) {
14
+ return /* @__PURE__ */ jsx(
15
+ "a",
16
+ {
17
+ ref,
18
+ href,
19
+ rel: "noreferrer noopener",
20
+ target: "_blank",
21
+ ...props,
22
+ children: props.children
23
+ }
24
+ );
25
+ }
26
+ return /* @__PURE__ */ jsx(
27
+ Original,
28
+ {
29
+ ref,
30
+ href,
31
+ prefetch,
32
+ replace,
33
+ ...props
34
+ }
35
+ );
36
+ }
37
+ );
38
+ Link.displayName = "Link";
39
+
40
+ export {
41
+ Link
42
+ };
@@ -0,0 +1,13 @@
1
+ // src/utils/use-on-change.ts
2
+ import { useState } from "react";
3
+ function useOnChange(value, onChange) {
4
+ const [prev, setPrev] = useState(value);
5
+ if (prev !== value) {
6
+ onChange(value, prev);
7
+ setPrev(value);
8
+ }
9
+ }
10
+
11
+ export {
12
+ useOnChange
13
+ };
@@ -0,0 +1,9 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __export = (target, all) => {
3
+ for (var name in all)
4
+ __defProp(target, name, { get: all[name], enumerable: true });
5
+ };
6
+
7
+ export {
8
+ __export
9
+ };
@@ -26,7 +26,7 @@ function useAnchorObserver(watch) {
26
26
  return entry.target.id;
27
27
  }
28
28
  }
29
- return f != null ? f : watch[0];
29
+ return f ?? watch[0];
30
30
  });
31
31
  },
32
32
  { rootMargin: `0% 0% -80% 0%` }
@@ -12,7 +12,7 @@ function flattenNode(node) {
12
12
 
13
13
  // src/mdx-plugins/remark-heading.ts
14
14
  var slugger = new Slugger();
15
- var regex = new RegExp("\\s*\\[#(?<slug>[^]+?)]\\s*$");
15
+ var regex = /\s*\[#(?<slug>[^]+?)]\s*$/;
16
16
  function remarkHeading({
17
17
  slug: defaultSlug,
18
18
  customId = true
@@ -21,13 +21,12 @@ function remarkHeading({
21
21
  const toc = [];
22
22
  slugger.reset();
23
23
  visit(root, "heading", (heading) => {
24
- var _a;
25
- heading.data || (heading.data = {});
26
- (_a = heading.data).hProperties || (_a.hProperties = {});
24
+ heading.data ||= {};
25
+ heading.data.hProperties ||= {};
27
26
  const lastNode = heading.children.at(-1);
28
- if (!heading.data.hProperties.id && (lastNode == null ? void 0 : lastNode.type) === "text" && customId) {
27
+ if (!heading.data.hProperties.id && lastNode?.type === "text" && customId) {
29
28
  const match = regex.exec(lastNode.value);
30
- if (match == null ? void 0 : match[1]) {
29
+ if (match?.[1]) {
31
30
  heading.data.hProperties.id = match[1];
32
31
  lastNode.value = lastNode.value.slice(0, match.index);
33
32
  }
@@ -1,28 +1,24 @@
1
1
  "use client";
2
2
  import {
3
3
  Link
4
- } from "./chunk-UMTVJNLA.js";
5
- import {
6
- __objRest,
7
- __spreadValues
8
- } from "./chunk-CWMXXUWU.js";
4
+ } from "./chunk-DVOZJZGH.js";
5
+ import "./chunk-MLKGABMK.js";
9
6
 
10
7
  // src/dynamic-link.tsx
11
8
  import { useParams } from "next/navigation";
12
9
  import { forwardRef, useMemo } from "react";
13
10
  import { jsx } from "react/jsx-runtime";
14
11
  var DynamicLink = forwardRef(
15
- (_a, ref) => {
16
- var _b = _a, { href } = _b, props = __objRest(_b, ["href"]);
12
+ ({ href, ...props }, ref) => {
17
13
  const params = useParams();
18
14
  const url = useMemo(() => {
19
- return href == null ? void 0 : href.replace(/\[.*\]/, (key) => {
15
+ return href?.replace(/\[.*\]/, (key) => {
20
16
  const mappedKey = key.slice(1, -1);
21
17
  const value = mappedKey in params ? params[mappedKey] : "undefined";
22
18
  return typeof value === "string" ? value : value.join("/");
23
19
  });
24
20
  }, [params, href]);
25
- return /* @__PURE__ */ jsx(Link, __spreadValues({ ref, href: url }, props));
21
+ return /* @__PURE__ */ jsx(Link, { ref, href: url, ...props });
26
22
  }
27
23
  );
28
24
  DynamicLink.displayName = "DynamicLink";
package/dist/link.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  Link
3
- } from "./chunk-UMTVJNLA.js";
4
- import "./chunk-CWMXXUWU.js";
3
+ } from "./chunk-DVOZJZGH.js";
4
+ import "./chunk-MLKGABMK.js";
5
5
  export {
6
6
  Link as default
7
7
  };
@@ -1,13 +1,11 @@
1
1
  import {
2
2
  flattenNode,
3
3
  remarkHeading
4
- } from "../chunk-QRNTLL6S.js";
4
+ } from "../chunk-YKIM647L.js";
5
5
  import {
6
6
  slash
7
7
  } from "../chunk-UWEEHUJV.js";
8
- import {
9
- __spreadValues
10
- } from "../chunk-CWMXXUWU.js";
8
+ import "../chunk-MLKGABMK.js";
11
9
 
12
10
  // src/mdx-plugins/index.ts
13
11
  import {
@@ -140,8 +138,14 @@ var defaultIcons = {
140
138
  }
141
139
  };
142
140
  function transformerIcon(options = {}) {
143
- const shortcuts = __spreadValues(__spreadValues({}, defaultShortcuts), options.shortcuts);
144
- const icons = __spreadValues(__spreadValues({}, defaultIcons), options.extend);
141
+ const shortcuts = {
142
+ ...defaultShortcuts,
143
+ ...options.shortcuts
144
+ };
145
+ const icons = {
146
+ ...defaultIcons,
147
+ ...options.extend
148
+ };
145
149
  const defaultIcon = "default" in icons ? icons.default : void 0;
146
150
  return {
147
151
  name: "rehype-code:icon",
@@ -162,15 +166,15 @@ function transformerIcon(options = {}) {
162
166
  var metaValues = [
163
167
  {
164
168
  name: "title",
165
- regex: new RegExp('title="(?<value>[^"]*)"')
169
+ regex: /title="(?<value>[^"]*)"/
166
170
  },
167
171
  {
168
172
  name: "custom",
169
- regex: new RegExp('custom="(?<value>[^"]+)"')
173
+ regex: /custom="(?<value>[^"]+)"/
170
174
  },
171
175
  {
172
176
  name: "tab",
173
- regex: new RegExp('tab="(?<value>[^"]+)"')
177
+ regex: /tab="(?<value>[^"]+)"/
174
178
  }
175
179
  ];
176
180
  var rehypeCodeDefaultOptions = {
@@ -203,15 +207,17 @@ var rehypeCodeDefaultOptions = {
203
207
  }
204
208
  };
205
209
  function rehypeCode(options = {}) {
206
- const codeOptions = __spreadValues(__spreadValues({}, rehypeCodeDefaultOptions), options);
207
- codeOptions.transformers || (codeOptions.transformers = []);
210
+ const codeOptions = {
211
+ ...rehypeCodeDefaultOptions,
212
+ ...options
213
+ };
214
+ codeOptions.transformers ||= [];
208
215
  codeOptions.transformers = [
209
216
  {
210
217
  name: "rehype-code:pre-process",
211
218
  preprocess(code, { meta }) {
212
- var _a;
213
219
  if (meta && codeOptions.filterMetaString) {
214
- meta.__raw = codeOptions.filterMetaString((_a = meta.__raw) != null ? _a : "");
220
+ meta.__raw = codeOptions.filterMetaString(meta.__raw ?? "");
215
221
  }
216
222
  return code.replace(/\n$/, "");
217
223
  },
@@ -245,7 +251,7 @@ function transformerTab() {
245
251
  name: "rehype-code:tab",
246
252
  root(root) {
247
253
  const meta = this.options.meta;
248
- if (typeof (meta == null ? void 0 : meta.tab) !== "string") return root;
254
+ if (typeof meta?.tab !== "string") return root;
249
255
  return {
250
256
  type: "root",
251
257
  children: [
@@ -279,7 +285,6 @@ function remarkImage({
279
285
  return (tree, _file, done) => {
280
286
  const importsToInject = [];
281
287
  visit(tree, "image", (node) => {
282
- var _a;
283
288
  let url = decodeURI(node.url);
284
289
  if (!url || EXTERNAL_URL_REGEX.test(url)) {
285
290
  return;
@@ -301,7 +306,7 @@ function remarkImage({
301
306
  {
302
307
  type: "mdxJsxAttribute",
303
308
  name: "alt",
304
- value: (_a = node.alt) != null ? _a : "image"
309
+ value: node.alt ?? "image"
305
310
  },
306
311
  hasBlur && {
307
312
  type: "mdxJsxAttribute",
@@ -372,14 +377,13 @@ function remarkStructure({
372
377
  const data = { contents: [], headings: [] };
373
378
  let lastHeading = "";
374
379
  visit2(node, types, (element) => {
375
- var _a, _b;
376
380
  if (element.type === "root") return;
377
381
  const content = flattenNode(element).trim();
378
382
  if (element.type === "heading") {
379
- element.data || (element.data = {});
380
- (_a = element.data).hProperties || (_a.hProperties = {});
383
+ element.data ||= {};
384
+ element.data.hProperties ||= {};
381
385
  const properties = element.data.hProperties;
382
- const id = (_b = properties.id) != null ? _b : slugger.slug(content);
386
+ const id = properties.id ?? slugger.slug(content);
383
387
  data.headings.push({
384
388
  id,
385
389
  content
@@ -1,4 +1,4 @@
1
- import "./chunk-CWMXXUWU.js";
1
+ import "./chunk-MLKGABMK.js";
2
2
 
3
3
  // src/middleware.ts
4
4
  import { match as matchLocale } from "@formatjs/intl-localematcher";
@@ -1,21 +1,17 @@
1
- import {
2
- __async
3
- } from "../chunk-CWMXXUWU.js";
1
+ import "../chunk-MLKGABMK.js";
4
2
 
5
3
  // src/search/client.ts
6
4
  import { useEffect, useState } from "react";
7
5
  import useSWR from "swr";
8
- function fetchDocs(api, query, locale, tag) {
9
- return __async(this, null, function* () {
10
- if (query.length === 0) return "empty";
11
- const params = new URLSearchParams();
12
- params.set("query", query);
13
- if (locale) params.set("locale", locale);
14
- if (tag) params.set("tag", tag);
15
- const res = yield fetch(`${api}?${params.toString()}`);
16
- if (!res.ok) throw new Error(yield res.text());
17
- return yield res.json();
18
- });
6
+ async function fetchDocs(api, query, locale, tag) {
7
+ if (query.length === 0) return "empty";
8
+ const params = new URLSearchParams();
9
+ params.set("query", query);
10
+ if (locale) params.set("locale", locale);
11
+ if (tag) params.set("tag", tag);
12
+ const res = await fetch(`${api}?${params.toString()}`);
13
+ if (!res.ok) throw new Error(await res.text());
14
+ return await res.json();
19
15
  }
20
16
  function useDocsSearch(locale, tag, api = "/api/search", delayMs = 100) {
21
17
  const [search, setSearch] = useState("");
@@ -1,8 +1,4 @@
1
- import {
2
- __async,
3
- __spreadProps,
4
- __spreadValues
5
- } from "../chunk-CWMXXUWU.js";
1
+ import "../chunk-MLKGABMK.js";
6
2
 
7
3
  // src/search/server.ts
8
4
  import { Document } from "flexsearch";
@@ -10,18 +6,15 @@ import { NextResponse } from "next/server";
10
6
  function create(search) {
11
7
  return {
12
8
  search,
13
- GET(request) {
14
- return __async(this, null, function* () {
15
- var _a2, _b;
16
- const query = request.nextUrl.searchParams.get("query");
17
- if (!query) return NextResponse.json([]);
18
- return NextResponse.json(
19
- yield search(query, {
20
- tag: (_a2 = request.nextUrl.searchParams.get("tag")) != null ? _a2 : void 0,
21
- locale: (_b = request.nextUrl.searchParams.get("locale")) != null ? _b : void 0
22
- })
23
- );
24
- });
9
+ async GET(request) {
10
+ const query = request.nextUrl.searchParams.get("query");
11
+ if (!query) return NextResponse.json([]);
12
+ return NextResponse.json(
13
+ await search(query, {
14
+ tag: request.nextUrl.searchParams.get("tag") ?? void 0,
15
+ locale: request.nextUrl.searchParams.get("locale") ?? void 0
16
+ })
17
+ );
25
18
  }
26
19
  };
27
20
  }
@@ -38,68 +31,67 @@ function createI18nSearchAPI(type, options) {
38
31
  map.set(
39
32
  v.language,
40
33
  // @ts-expect-error -- Index depends on generic types
41
- createSearchAPI(type, __spreadProps(__spreadValues({}, options), {
34
+ createSearchAPI(type, {
35
+ ...options,
42
36
  language: v.language,
43
37
  indexes: v.indexes
44
- }))
38
+ })
45
39
  );
46
40
  }
47
- return create((query, searchOptions) => __async(this, null, function* () {
48
- if (searchOptions == null ? void 0 : searchOptions.locale) {
41
+ return create(async (query, searchOptions) => {
42
+ if (searchOptions?.locale) {
49
43
  const handler = map.get(searchOptions.locale);
50
44
  if (handler) return handler.search(query, searchOptions);
51
45
  }
52
46
  return [];
53
- }));
47
+ });
54
48
  }
55
49
  function initSearchAPI({ indexes, language }) {
56
50
  const store = ["title", "url"];
57
- function getDocument() {
58
- return __async(this, null, function* () {
59
- const items = typeof indexes === "function" ? yield indexes() : indexes;
60
- const index = new Document({
61
- language,
62
- optimize: true,
63
- cache: 100,
64
- document: {
65
- id: "url",
66
- store,
67
- index: [
68
- {
69
- field: "title",
70
- tokenize: "forward",
71
- resolution: 9
72
- },
73
- {
74
- field: "content",
75
- tokenize: "strict",
76
- context: {
77
- depth: 1,
78
- resolution: 9
79
- }
80
- },
81
- {
82
- field: "keywords",
83
- tokenize: "strict",
51
+ async function getDocument() {
52
+ const items = typeof indexes === "function" ? await indexes() : indexes;
53
+ const index = new Document({
54
+ language,
55
+ optimize: true,
56
+ cache: 100,
57
+ document: {
58
+ id: "url",
59
+ store,
60
+ index: [
61
+ {
62
+ field: "title",
63
+ tokenize: "forward",
64
+ resolution: 9
65
+ },
66
+ {
67
+ field: "content",
68
+ tokenize: "strict",
69
+ context: {
70
+ depth: 1,
84
71
  resolution: 9
85
72
  }
86
- ]
87
- }
88
- });
89
- for (const page of items) {
90
- index.add({
91
- title: page.title,
92
- url: page.url,
93
- content: page.content,
94
- keywords: page.keywords
95
- });
73
+ },
74
+ {
75
+ field: "keywords",
76
+ tokenize: "strict",
77
+ resolution: 9
78
+ }
79
+ ]
96
80
  }
97
- return index;
98
81
  });
82
+ for (const page of items) {
83
+ index.add({
84
+ title: page.title,
85
+ url: page.url,
86
+ content: page.content,
87
+ keywords: page.keywords
88
+ });
89
+ }
90
+ return index;
99
91
  }
100
92
  const doc = getDocument();
101
- return create((query) => __async(this, null, function* () {
102
- const results = (yield doc).search(query, 5, {
93
+ return create(async (query) => {
94
+ const results = (await doc).search(query, 5, {
103
95
  enrich: true,
104
96
  suggest: true
105
97
  });
@@ -110,7 +102,7 @@ function initSearchAPI({ indexes, language }) {
110
102
  id: page.doc.url,
111
103
  url: page.doc.url
112
104
  }));
113
- }));
105
+ });
114
106
  }
115
107
  function initSearchAPIAdvanced({
116
108
  indexes,
@@ -118,85 +110,82 @@ function initSearchAPIAdvanced({
118
110
  tag = false
119
111
  }) {
120
112
  const store = ["id", "url", "content", "page_id", "type", "keywords"];
121
- function getDocument() {
122
- return __async(this, null, function* () {
123
- const items = typeof indexes === "function" ? yield indexes() : indexes;
124
- const index = new Document({
125
- language,
126
- cache: 100,
127
- optimize: true,
128
- document: {
129
- id: "id",
130
- tag: tag ? "tag" : void 0,
131
- store,
132
- index: [
133
- {
134
- field: "content",
135
- tokenize: "forward",
136
- context: { depth: 2, bidirectional: true, resolution: 9 }
137
- },
138
- {
139
- field: "keywords",
140
- tokenize: "strict",
141
- resolution: 9
142
- }
143
- ]
144
- }
113
+ async function getDocument() {
114
+ const items = typeof indexes === "function" ? await indexes() : indexes;
115
+ const index = new Document({
116
+ language,
117
+ cache: 100,
118
+ optimize: true,
119
+ document: {
120
+ id: "id",
121
+ tag: tag ? "tag" : void 0,
122
+ store,
123
+ index: [
124
+ {
125
+ field: "content",
126
+ tokenize: "forward",
127
+ context: { depth: 2, bidirectional: true, resolution: 9 }
128
+ },
129
+ {
130
+ field: "keywords",
131
+ tokenize: "strict",
132
+ resolution: 9
133
+ }
134
+ ]
135
+ }
136
+ });
137
+ for (const page of items) {
138
+ const data = page.structuredData;
139
+ let id = 0;
140
+ index.add({
141
+ id: page.id,
142
+ page_id: page.id,
143
+ type: "page",
144
+ content: page.title,
145
+ keywords: page.keywords,
146
+ tag: page.tag,
147
+ url: page.url
145
148
  });
146
- for (const page of items) {
147
- const data = page.structuredData;
148
- let id = 0;
149
+ for (const heading of data.headings) {
149
150
  index.add({
150
- id: page.id,
151
+ id: page.id + (id++).toString(),
151
152
  page_id: page.id,
152
- type: "page",
153
- content: page.title,
154
- keywords: page.keywords,
153
+ type: "heading",
155
154
  tag: page.tag,
156
- url: page.url
155
+ url: `${page.url}#${heading.id}`,
156
+ content: heading.content
157
157
  });
158
- for (const heading of data.headings) {
159
- index.add({
160
- id: page.id + (id++).toString(),
161
- page_id: page.id,
162
- type: "heading",
163
- tag: page.tag,
164
- url: `${page.url}#${heading.id}`,
165
- content: heading.content
166
- });
167
- }
168
- for (const content of data.contents) {
169
- index.add({
170
- id: page.id + (id++).toString(),
171
- page_id: page.id,
172
- tag: page.tag,
173
- type: "text",
174
- url: content.heading ? `${page.url}#${content.heading}` : page.url,
175
- content: content.content
176
- });
177
- }
178
158
  }
179
- return index;
180
- });
159
+ for (const content of data.contents) {
160
+ index.add({
161
+ id: page.id + (id++).toString(),
162
+ page_id: page.id,
163
+ tag: page.tag,
164
+ type: "text",
165
+ url: content.heading ? `${page.url}#${content.heading}` : page.url,
166
+ content: content.content
167
+ });
168
+ }
169
+ }
170
+ return index;
181
171
  }
182
172
  const doc = getDocument();
183
- return create((query, options) => __async(this, null, function* () {
184
- var _a, _b, _c;
185
- const index = yield doc;
173
+ return create(async (query, options) => {
174
+ const index = await doc;
186
175
  const results = index.search(query, 5, {
187
176
  enrich: true,
188
- tag: options == null ? void 0 : options.tag,
177
+ tag: options?.tag,
189
178
  limit: 6
190
179
  });
191
180
  const map = /* @__PURE__ */ new Map();
192
- for (const item of (_b = (_a = results[0]) == null ? void 0 : _a.result) != null ? _b : []) {
181
+ for (const item of results[0]?.result ?? []) {
193
182
  if (item.doc.type === "page") {
194
183
  if (!map.has(item.doc.id)) {
195
184
  map.set(item.doc.id, []);
196
185
  }
197
186
  continue;
198
187
  }
199
- const list = (_c = map.get(item.doc.page_id)) != null ? _c : [];
188
+ const list = map.get(item.doc.page_id) ?? [];
200
189
  list.push({
201
190
  id: item.doc.id,
202
191
  content: item.doc.content,
@@ -218,7 +207,7 @@ function initSearchAPIAdvanced({
218
207
  sortedResult.push(...items);
219
208
  }
220
209
  return sortedResult;
221
- }));
210
+ });
222
211
  }
223
212
  export {
224
213
  createI18nSearchAPI,