fumadocs-core 12.5.2 → 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,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,
@@ -1,8 +1,4 @@
1
- import {
2
- __async,
3
- __objRest,
4
- __spreadValues
5
- } from "../chunk-CWMXXUWU.js";
1
+ import "../chunk-MLKGABMK.js";
6
2
 
7
3
  // src/search-algolia/client.ts
8
4
  import { useState } from "react";
@@ -29,31 +25,30 @@ function groupResults(hits) {
29
25
  }
30
26
  return grouped;
31
27
  }
32
- function searchDocs(index, query, options) {
33
- return __async(this, null, function* () {
34
- if (query.length === 0) {
35
- const result2 = yield index.search(query, __spreadValues({
36
- distinct: 1,
37
- hitsPerPage: 8
38
- }, options));
39
- return groupResults(result2.hits).filter((hit) => hit.type === "page");
40
- }
41
- const result = yield index.search(query, __spreadValues({
42
- distinct: 5,
43
- hitsPerPage: 10
44
- }, options));
45
- return groupResults(result.hits);
28
+ async function searchDocs(index, query, options) {
29
+ if (query.length === 0) {
30
+ const result2 = await index.search(query, {
31
+ distinct: 1,
32
+ hitsPerPage: 8,
33
+ ...options
34
+ });
35
+ return groupResults(result2.hits).filter((hit) => hit.type === "page");
36
+ }
37
+ const result = await index.search(query, {
38
+ distinct: 5,
39
+ hitsPerPage: 10,
40
+ ...options
46
41
  });
42
+ return groupResults(result.hits);
47
43
  }
48
- function useAlgoliaSearch(index, _a = {}) {
49
- var _b = _a, { allowEmpty = true } = _b, options = __objRest(_b, ["allowEmpty"]);
44
+ function useAlgoliaSearch(index, { allowEmpty = true, ...options } = {}) {
50
45
  const [search, setSearch] = useState("");
51
46
  const query = useSWR(
52
47
  ["algolia-search", search, allowEmpty, options],
53
- () => __async(this, null, function* () {
48
+ async () => {
54
49
  if (allowEmpty && search.length === 0) return "empty";
55
50
  return searchDocs(index, search, options);
56
- }),
51
+ },
57
52
  {
58
53
  keepPreviousData: true
59
54
  }
@@ -1,26 +1,19 @@
1
- import {
2
- __async,
3
- __spreadValues
4
- } from "../chunk-CWMXXUWU.js";
1
+ import "../chunk-MLKGABMK.js";
5
2
 
6
3
  // src/search-algolia/server.ts
7
- function sync(client, options) {
8
- return __async(this, null, function* () {
9
- const { document = "document", documents } = options;
10
- const index = client.initIndex(document);
11
- yield setIndexSettings(index);
12
- yield updateDocuments(index, documents);
13
- });
4
+ async function sync(client, options) {
5
+ const { document = "document", documents } = options;
6
+ const index = client.initIndex(document);
7
+ await setIndexSettings(index);
8
+ await updateDocuments(index, documents);
14
9
  }
15
- function setIndexSettings(index) {
16
- return __async(this, null, function* () {
17
- yield index.setSettings({
18
- attributeForDistinct: "page_id",
19
- attributesToRetrieve: ["title", "section", "content", "url", "section_id"],
20
- searchableAttributes: ["title", "section", "content"],
21
- attributesToSnippet: [],
22
- attributesForFaceting: ["tag"]
23
- });
10
+ async function setIndexSettings(index) {
11
+ await index.setSettings({
12
+ attributeForDistinct: "page_id",
13
+ attributesToRetrieve: ["title", "section", "content", "url", "section_id"],
14
+ searchableAttributes: ["title", "section", "content"],
15
+ attributesToSnippet: [],
16
+ attributesForFaceting: ["tag"]
24
17
  });
25
18
  }
26
19
  function getSections(page) {
@@ -28,8 +21,8 @@ function getSections(page) {
28
21
  return page.structured.contents.flatMap((p) => {
29
22
  const heading = p.heading ? page.structured.headings.find((h) => p.heading === h.id) : null;
30
23
  const section = {
31
- section: heading == null ? void 0 : heading.content,
32
- section_id: heading == null ? void 0 : heading.id,
24
+ section: heading?.content,
25
+ section_id: heading?.id,
33
26
  content: p.content
34
27
  };
35
28
  if (heading && !scannedHeadings.has(heading.id)) {
@@ -46,21 +39,21 @@ function getSections(page) {
46
39
  return section;
47
40
  });
48
41
  }
49
- function updateDocuments(index, documents) {
50
- return __async(this, null, function* () {
51
- const objects = documents.flatMap((page) => {
52
- return getSections(page).map(
53
- (section, idx) => __spreadValues(__spreadValues({
54
- objectID: `${page._id}-${idx.toString()}`,
55
- title: page.title,
56
- url: page.url,
57
- page_id: page._id,
58
- tag: page.tag
59
- }, section), page.extra_data)
60
- );
61
- });
62
- yield index.replaceAllObjects(objects);
42
+ async function updateDocuments(index, documents) {
43
+ const objects = documents.flatMap((page) => {
44
+ return getSections(page).map(
45
+ (section, idx) => ({
46
+ objectID: `${page._id}-${idx.toString()}`,
47
+ title: page.title,
48
+ url: page.url,
49
+ page_id: page._id,
50
+ tag: page.tag,
51
+ ...section,
52
+ ...page.extra_data
53
+ })
54
+ );
63
55
  });
56
+ await index.replaceAllObjects(objects);
64
57
  }
65
58
  export {
66
59
  setIndexSettings,
@@ -1,20 +1,14 @@
1
1
  import {
2
2
  remarkHeading
3
- } from "../chunk-QRNTLL6S.js";
4
- import {
5
- __async,
6
- __spreadProps,
7
- __spreadValues
8
- } from "../chunk-CWMXXUWU.js";
3
+ } from "../chunk-YKIM647L.js";
4
+ import "../chunk-MLKGABMK.js";
9
5
 
10
6
  // src/server/get-toc.ts
11
7
  import { remark } from "remark";
12
- function getTableOfContents(content) {
13
- return __async(this, null, function* () {
14
- const result = yield remark().use(remarkHeading).process(content);
15
- if ("toc" in result.data) return result.data.toc;
16
- return [];
17
- });
8
+ async function getTableOfContents(content) {
9
+ const result = await remark().use(remarkHeading).process(content);
10
+ if ("toc" in result.data) return result.data.toc;
11
+ return [];
18
12
  }
19
13
 
20
14
  // src/server/page-tree-utils.ts
@@ -43,11 +37,10 @@ function findNeighbour(tree, url) {
43
37
  }
44
38
  function separatePageTree(pageTree) {
45
39
  return pageTree.children.flatMap((child) => {
46
- var _a;
47
40
  if (child.type !== "folder") return [];
48
41
  return {
49
42
  name: child.name,
50
- url: (_a = child.index) == null ? void 0 : _a.url,
43
+ url: child.index?.url,
51
44
  children: child.children
52
45
  };
53
46
  });
@@ -57,42 +50,40 @@ function separatePageTree(pageTree) {
57
50
  var page_tree_exports = {};
58
51
 
59
52
  // src/server/git-api.ts
60
- function getGithubLastEdit(_0) {
61
- return __async(this, arguments, function* ({
62
- repo,
63
- token,
64
- owner,
65
- path,
66
- options = {},
67
- params: customParams = {}
68
- }) {
69
- const headers = new Headers(options.headers);
70
- const params = new URLSearchParams();
71
- params.set("path", path);
72
- params.set("page", "1");
73
- params.set("per_page", "1");
74
- for (const [key, value] of Object.entries(customParams)) {
75
- params.set(key, value);
76
- }
77
- if (token) {
78
- headers.append("authorization", token);
53
+ async function getGithubLastEdit({
54
+ repo,
55
+ token,
56
+ owner,
57
+ path,
58
+ options = {},
59
+ params: customParams = {}
60
+ }) {
61
+ const headers = new Headers(options.headers);
62
+ const params = new URLSearchParams();
63
+ params.set("path", path);
64
+ params.set("page", "1");
65
+ params.set("per_page", "1");
66
+ for (const [key, value] of Object.entries(customParams)) {
67
+ params.set(key, value);
68
+ }
69
+ if (token) {
70
+ headers.append("authorization", token);
71
+ }
72
+ const res = await fetch(
73
+ `https://api.github.com/repos/${owner}/${repo}/commits?${params.toString()}`,
74
+ {
75
+ cache: "force-cache",
76
+ ...options,
77
+ headers
79
78
  }
80
- const res = yield fetch(
81
- `https://api.github.com/repos/${owner}/${repo}/commits?${params.toString()}`,
82
- __spreadProps(__spreadValues({
83
- cache: "force-cache"
84
- }, options), {
85
- headers
86
- })
79
+ );
80
+ if (!res.ok)
81
+ throw new Error(
82
+ `Failed to fetch last edit time from Git ${await res.text()}`
87
83
  );
88
- if (!res.ok)
89
- throw new Error(
90
- `Failed to fetch last edit time from Git ${yield res.text()}`
91
- );
92
- const data = yield res.json();
93
- if (data.length === 0) return null;
94
- return new Date(data[0].commit.committer.date);
95
- });
84
+ const data = await res.json();
85
+ if (data.length === 0) return null;
86
+ return new Date(data[0].commit.committer.date);
96
87
  }
97
88
  export {
98
89
  page_tree_exports as PageTree,
package/dist/sidebar.js CHANGED
@@ -1,8 +1,4 @@
1
- import {
2
- __objRest,
3
- __spreadProps,
4
- __spreadValues
5
- } from "./chunk-CWMXXUWU.js";
1
+ import "./chunk-MLKGABMK.js";
6
2
 
7
3
  // src/sidebar.tsx
8
4
  import {
@@ -21,41 +17,36 @@ function useSidebarContext() {
21
17
  return ctx;
22
18
  }
23
19
  function SidebarProvider(props) {
24
- var _a, _b;
25
20
  const [openInner, setOpenInner] = useState(false);
26
21
  const [open, setOpen] = [
27
- (_a = props.open) != null ? _a : openInner,
28
- (_b = props.onOpenChange) != null ? _b : setOpenInner
22
+ props.open ?? openInner,
23
+ props.onOpenChange ?? setOpenInner
29
24
  ];
30
25
  return /* @__PURE__ */ jsx(SidebarContext.Provider, { value: [open, setOpen], children: props.children });
31
26
  }
32
- function SidebarTrigger(_a) {
33
- var _b = _a, {
34
- as
35
- } = _b, props = __objRest(_b, [
36
- "as"
37
- ]);
27
+ function SidebarTrigger({
28
+ as,
29
+ ...props
30
+ }) {
38
31
  const [open, setOpen] = useSidebarContext();
39
- const As = as != null ? as : "button";
32
+ const As = as ?? "button";
40
33
  return /* @__PURE__ */ jsx(
41
34
  As,
42
- __spreadValues({
35
+ {
43
36
  "aria-label": "Toggle Sidebar",
44
37
  "data-open": open,
45
38
  onClick: useCallback(() => {
46
39
  setOpen(!open);
47
- }, [open, setOpen])
48
- }, props)
40
+ }, [open, setOpen]),
41
+ ...props
42
+ }
49
43
  );
50
44
  }
51
- function SidebarList(_a) {
52
- var _b = _a, {
53
- as,
54
- blockScrollingWidth
55
- } = _b, props = __objRest(_b, [
56
- "as",
57
- "blockScrollingWidth"
58
- ]);
45
+ function SidebarList({
46
+ as,
47
+ blockScrollingWidth,
48
+ ...props
49
+ }) {
59
50
  const [open] = useSidebarContext();
60
51
  const [isBlocking, setIsBlocking] = useState(false);
61
52
  useEffect(() => {
@@ -74,13 +65,13 @@ function SidebarList(_a) {
74
65
  }, [blockScrollingWidth]);
75
66
  return /* @__PURE__ */ jsx(
76
67
  RemoveScroll,
77
- __spreadProps(__spreadValues({
78
- as: as != null ? as : "aside",
68
+ {
69
+ as: as ?? "aside",
79
70
  "data-open": open,
80
- enabled: Boolean(isBlocking && open)
81
- }, props), {
71
+ enabled: Boolean(isBlocking && open),
72
+ ...props,
82
73
  children: props.children
83
- })
74
+ }
84
75
  );
85
76
  }
86
77
  export {