fumadocs-core 10.0.0 → 10.0.2

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.
@@ -21,12 +21,12 @@ function remarkHeading() {
21
21
  const toc = [];
22
22
  slugger.reset();
23
23
  visit(node, ["heading"], (heading) => {
24
- var _a;
24
+ var _a, _b;
25
25
  heading.data || (heading.data = {});
26
26
  (_a = heading.data).hProperties || (_a.hProperties = {});
27
27
  const text = flattenNode(heading);
28
28
  const properties = heading.data.hProperties;
29
- const id = slugger.slug(properties.id || text);
29
+ const id = slugger.slug((_b = properties.id) != null ? _b : text);
30
30
  properties.id = id;
31
31
  toc.push({
32
32
  title: text,
@@ -2,7 +2,7 @@ import {
2
2
  flattenNode,
3
3
  remarkHeading,
4
4
  visit
5
- } from "../chunk-GT3Y35O6.js";
5
+ } from "../chunk-M6ZDX3QR.js";
6
6
  import {
7
7
  slash
8
8
  } from "../chunk-UWEEHUJV.js";
@@ -8,6 +8,11 @@ interface UseDocsSearch {
8
8
  keepPreviousData: true;
9
9
  }>;
10
10
  }
11
- declare function useDocsSearch(locale?: string, tag?: string): UseDocsSearch;
11
+ /**
12
+ * @param locale - Filter with locale
13
+ * @param tag - Filter with specific tag
14
+ * @param api - The Search API URL
15
+ */
16
+ declare function useDocsSearch(locale?: string, tag?: string, api?: string): UseDocsSearch;
12
17
 
13
18
  export { useDocsSearch };
@@ -21,14 +21,12 @@ function fetchDocs(api, query, locale, tag) {
21
21
  return yield res.json();
22
22
  });
23
23
  }
24
- function useDocsSearch(locale, tag) {
24
+ function useDocsSearch(locale, tag, api = "/api/search") {
25
25
  const [search, setSearch] = useState("");
26
26
  const debouncedValue = useDebounce(search, 100);
27
27
  const query = useSWR(
28
- ["/api/search", debouncedValue, locale, tag],
29
- (_0) => __async(this, [_0], function* ([api, value]) {
30
- return fetchDocs(api, value, locale, tag);
31
- }),
28
+ [api, debouncedValue, locale, tag],
29
+ (args) => fetchDocs(...args),
32
30
  {
33
31
  keepPreviousData: true
34
32
  }
@@ -5,7 +5,7 @@ import {
5
5
 
6
6
  // src/search/server.ts
7
7
  import { Document } from "flexsearch";
8
- import nextLib from "next/server";
8
+ import { NextResponse } from "next/server";
9
9
  function createSearchAPI(type, options) {
10
10
  if (type === "simple") {
11
11
  return initSearchAPI(options);
@@ -32,7 +32,7 @@ function createI18nSearchAPI(type, options) {
32
32
  if (handler)
33
33
  return handler.GET(request);
34
34
  }
35
- return nextLib.NextResponse.json([]);
35
+ return NextResponse.json([]);
36
36
  }
37
37
  };
38
38
  }
@@ -80,20 +80,20 @@ function initSearchAPI({ indexes, language }) {
80
80
  const { searchParams } = request.nextUrl;
81
81
  const query = searchParams.get("query");
82
82
  if (!query)
83
- return nextLib.NextResponse.json([]);
83
+ return NextResponse.json([]);
84
84
  const results = index.search(query, 5, {
85
85
  enrich: true,
86
86
  suggest: true
87
87
  });
88
88
  if (results.length === 0)
89
- return nextLib.NextResponse.json([]);
89
+ return NextResponse.json([]);
90
90
  const pages = results[0].result.map((page) => ({
91
91
  type: "page",
92
92
  content: page.doc.title,
93
93
  id: page.doc.url,
94
94
  url: page.doc.url
95
95
  }));
96
- return nextLib.NextResponse.json(pages);
96
+ return NextResponse.json(pages);
97
97
  }
98
98
  };
99
99
  }
@@ -158,7 +158,7 @@ function initSearchAPIAdvanced({
158
158
  const query = request.nextUrl.searchParams.get("query");
159
159
  const paramTag = request.nextUrl.searchParams.get("tag");
160
160
  if (!query)
161
- return nextLib.NextResponse.json([]);
161
+ return NextResponse.json([]);
162
162
  const results = index.search(query, 5, {
163
163
  enrich: true,
164
164
  tag: paramTag != null ? paramTag : void 0,
@@ -197,7 +197,7 @@ function initSearchAPIAdvanced({
197
197
  });
198
198
  sortedResult.push(...items);
199
199
  }
200
- return nextLib.NextResponse.json(sortedResult);
200
+ return NextResponse.json(sortedResult);
201
201
  }
202
202
  };
203
203
  }
@@ -49,7 +49,7 @@ function useAlgoliaSearch(index, _a = {}) {
49
49
  var _b = _a, { allowEmpty = true } = _b, options = __objRest(_b, ["allowEmpty"]);
50
50
  const [search, setSearch] = useState("");
51
51
  const query = useSWR(
52
- ["/api/search", search, allowEmpty, options],
52
+ ["algolia-search", search, allowEmpty, options],
53
53
  () => __async(this, null, function* () {
54
54
  if (allowEmpty && search.length === 0)
55
55
  return "empty";
@@ -42,4 +42,4 @@ interface BaseIndex {
42
42
  content: string;
43
43
  }
44
44
 
45
- export { type BaseIndex, setIndexSettings, sync, updateDocuments };
45
+ export { type BaseIndex, type SyncOptions, setIndexSettings, sync, updateDocuments };
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  remarkHeading
3
- } from "../chunk-GT3Y35O6.js";
3
+ } from "../chunk-M6ZDX3QR.js";
4
4
  import {
5
5
  __async
6
6
  } from "../chunk-WEAGW6MQ.js";
@@ -17,6 +17,8 @@ interface FileInfo {
17
17
  name: string;
18
18
  dirname: string;
19
19
  }
20
+ declare function parseFilePath(path: string): FileInfo;
21
+ declare function parseFolderPath(path: string): FileInfo;
20
22
 
21
23
  interface LoadOptions {
22
24
  files: VirtualFile[];
@@ -30,15 +32,11 @@ interface VirtualFile {
30
32
  type: 'page' | 'meta';
31
33
  data: unknown;
32
34
  }
33
- interface LoadResult {
34
- storage: Storage;
35
- }
36
35
  type Transformer = (context: {
37
36
  storage: Storage;
38
37
  getSlugs: (info: FileInfo) => string[];
39
38
  getUrl: (slugs: string[], locale?: string) => string;
40
39
  }) => void;
41
- declare function load(options: LoadOptions): LoadResult;
42
40
 
43
41
  interface LoaderConfig {
44
42
  source: SourceConfig;
@@ -85,6 +83,8 @@ interface LoaderOutput<Config extends LoaderConfig> {
85
83
  */
86
84
  getPage: (slugs: string[] | undefined, language?: string) => Page<Config['source']['pageData']> | undefined;
87
85
  }
86
+ declare function createGetUrl(baseUrl: string): (slugs: string[], locale?: string) => string;
87
+ declare function getSlugs(info: FileInfo): string[];
88
88
  type InferSourceConfig<T> = T extends Source<infer Config> ? Config : never;
89
89
  declare function loader<Options extends LoaderOptions>(options: Options): LoaderOutput<{
90
90
  source: InferSourceConfig<Options['source']>;
@@ -176,4 +176,4 @@ interface CreatePageTreeBuilderOptions {
176
176
  }
177
177
  declare function createPageTreeBuilder({ storage, resolveIcon, }: CreatePageTreeBuilderOptions): PageTreeBuilder;
178
178
 
179
- export { type BuildPageTreeOptionsWithI18n, type CreatePageTreeBuilderOptions, fileSystem as FileSystem, type InferMetaType, type InferPageType, type LoadOptions, type LoadResult, type LoaderOptions, type LoaderOutput, type MetaData, type PageData, type PageTreeBuilder, type Source, type Transformer, type VirtualFile, createPageTreeBuilder, load, loader };
179
+ export { type BuildPageTreeOptionsWithI18n, type CreatePageTreeBuilderOptions, type FileInfo, fileSystem as FileSystem, type InferMetaType, type InferPageType, type LoadOptions, type LoaderConfig, type LoaderOptions, type LoaderOutput, type MetaData, type PageData, type PageTreeBuilder, type Source, type SourceConfig, type Transformer, type VirtualFile, createGetUrl, createPageTreeBuilder, getSlugs, loader, parseFilePath, parseFolderPath };
@@ -151,7 +151,7 @@ function buildFolderNode(folder, defaultIsRoot, ctx) {
151
151
  });
152
152
  children = nodes != null ? nodes : restNodes;
153
153
  }
154
- return {
154
+ return removeUndefined({
155
155
  type: "folder",
156
156
  name: (_e = (_d = meta == null ? void 0 : meta.title) != null ? _d : index == null ? void 0 : index.name) != null ? _e : pathToName(folder.file.name),
157
157
  icon: ctx.resolveIcon(meta == null ? void 0 : meta.icon),
@@ -159,7 +159,7 @@ function buildFolderNode(folder, defaultIsRoot, ctx) {
159
159
  defaultOpen: meta == null ? void 0 : meta.defaultOpen,
160
160
  index,
161
161
  children
162
- };
162
+ });
163
163
  }
164
164
  function buildFileNode(page, ctx) {
165
165
  let localePage = page;
@@ -170,12 +170,12 @@ function buildFileNode(page, ctx) {
170
170
  if (result)
171
171
  localePage = result;
172
172
  }
173
- return {
173
+ return removeUndefined({
174
174
  type: "page",
175
175
  name: localePage.data.title,
176
176
  icon: ctx.resolveIcon(localePage.data.icon),
177
177
  url: localePage.url
178
- };
178
+ });
179
179
  }
180
180
  function build(ctx) {
181
181
  const root = ctx.storage.root();
@@ -217,6 +217,14 @@ function createPageTreeBuilder({
217
217
  function pathToName(path2) {
218
218
  return path2.slice(0, 1).toUpperCase() + path2.slice(1);
219
219
  }
220
+ function removeUndefined(value) {
221
+ const obj = value;
222
+ Object.keys(obj).forEach((key) => {
223
+ if (obj[key] === void 0)
224
+ delete obj[key];
225
+ });
226
+ return value;
227
+ }
220
228
 
221
229
  // src/source/load.ts
222
230
  import * as path from "path";
@@ -411,7 +419,10 @@ function createOutput({
411
419
  }
412
420
  export {
413
421
  file_system_exports as FileSystem,
422
+ createGetUrl,
414
423
  createPageTreeBuilder,
415
- load,
416
- loader
424
+ getSlugs,
425
+ loader,
426
+ parseFilePath,
427
+ parseFolderPath
417
428
  };
package/dist/toc.d.ts CHANGED
@@ -1,20 +1,21 @@
1
1
  import * as react from 'react';
2
- import { HTMLAttributes, AnchorHTMLAttributes } from 'react';
3
- import { T as TableOfContents, a as TOCItemType } from './get-toc-YF_TdazL.js';
2
+ import { HTMLAttributes, RefObject, ReactNode, AnchorHTMLAttributes } from 'react';
3
+ import { T as TableOfContents } from './get-toc-YF_TdazL.js';
4
4
 
5
5
  declare const useActiveAnchor: (url: string) => boolean;
6
- declare const TOCProvider: react.ForwardRefExoticComponent<HTMLAttributes<HTMLDivElement> & {
6
+ interface TOCProviderProps extends HTMLAttributes<HTMLDivElement> {
7
7
  toc: TableOfContents;
8
- } & react.RefAttributes<HTMLDivElement>>;
9
- type TOCItemProps = AnchorHTMLAttributes<HTMLAnchorElement> & {
10
- href: string;
11
- /** @deprecated You don't need to pass this anymore */
12
- item?: TOCItemType;
13
- };
14
- declare const TOCItem: react.ForwardRefExoticComponent<AnchorHTMLAttributes<HTMLAnchorElement> & {
8
+ }
9
+ declare const TOCProvider: react.ForwardRefExoticComponent<TOCProviderProps & react.RefAttributes<HTMLDivElement>>;
10
+ interface TOCScrollProvider {
11
+ containerRef: RefObject<HTMLElement>;
12
+ toc: TableOfContents;
13
+ children: ReactNode;
14
+ }
15
+ declare function TOCScrollProvider({ toc, containerRef, children, }: TOCScrollProvider): JSX.Element;
16
+ interface TOCItemProps extends AnchorHTMLAttributes<HTMLAnchorElement> {
15
17
  href: string;
16
- /** @deprecated You don't need to pass this anymore */
17
- item?: TOCItemType | undefined;
18
- } & react.RefAttributes<HTMLAnchorElement>>;
18
+ }
19
+ declare const TOCItem: react.ForwardRefExoticComponent<TOCItemProps & react.RefAttributes<HTMLAnchorElement>>;
19
20
 
20
- export { TOCItem, type TOCItemProps, TOCProvider, useActiveAnchor };
21
+ export { TOCItem, type TOCItemProps, TOCProvider, type TOCProviderProps, TOCScrollProvider, useActiveAnchor };
package/dist/toc.js CHANGED
@@ -74,16 +74,23 @@ var useActiveAnchor = (url) => {
74
74
  var TOCProvider = forwardRef(
75
75
  (_a, ref) => {
76
76
  var _b = _a, { toc } = _b, props = __objRest(_b, ["toc"]);
77
- const headings = useMemo(() => {
78
- return toc.map((item) => item.url.split("#")[1]);
79
- }, [toc]);
80
77
  const containerRef = useRef(null);
81
78
  const mergedRef = mergeRefs(containerRef, ref);
82
- const activeAnchor = useAnchorObserver(headings);
83
- return /* @__PURE__ */ jsx("div", __spreadProps(__spreadValues({ ref: mergedRef }, props), { children: /* @__PURE__ */ jsx(ActiveAnchorContext.Provider, { value: { containerRef, activeAnchor }, children: props.children }) }));
79
+ return /* @__PURE__ */ jsx("div", __spreadProps(__spreadValues({ ref: mergedRef }, props), { children: /* @__PURE__ */ jsx(TOCScrollProvider, { toc, containerRef, children: props.children }) }));
84
80
  }
85
81
  );
86
82
  TOCProvider.displayName = "TOCProvider";
83
+ function TOCScrollProvider({
84
+ toc,
85
+ containerRef,
86
+ children
87
+ }) {
88
+ const headings = useMemo(() => {
89
+ return toc.map((item) => item.url.split("#")[1]);
90
+ }, [toc]);
91
+ const activeAnchor = useAnchorObserver(headings);
92
+ return /* @__PURE__ */ jsx(ActiveAnchorContext.Provider, { value: { containerRef, activeAnchor }, children });
93
+ }
87
94
  var TOCItem = forwardRef(
88
95
  (props, ref) => {
89
96
  const { containerRef } = useContext(ActiveAnchorContext);
@@ -109,5 +116,6 @@ TOCItem.displayName = "TOCItem";
109
116
  export {
110
117
  TOCItem,
111
118
  TOCProvider,
119
+ TOCScrollProvider,
112
120
  useActiveAnchor
113
121
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fumadocs-core",
3
- "version": "10.0.0",
3
+ "version": "10.0.2",
4
4
  "description": "The library for building a documentation website in Next.js",
5
5
  "keywords": [
6
6
  "NextJs",
@@ -108,40 +108,39 @@
108
108
  "dist/*"
109
109
  ],
110
110
  "dependencies": {
111
- "@formatjs/intl-localematcher": "^0.5.0",
112
- "@shikijs/rehype": "1.1.7",
113
- "@shikijs/transformers": "1.1.7",
114
- "flexsearch": "0.7.21",
111
+ "@formatjs/intl-localematcher": "^0.5.4",
112
+ "@shikijs/rehype": "^1.1.7",
113
+ "@shikijs/transformers": "^1.1.7",
114
+ "flexsearch": "^0.7.43",
115
115
  "github-slugger": "^2.0.0",
116
116
  "hast-util-to-estree": "^3.1.0",
117
117
  "negotiator": "^0.6.3",
118
- "react-remove-scroll": "^2.5.6",
118
+ "react-remove-scroll": "^2.5.7",
119
119
  "remark": "^15.0.0",
120
120
  "remark-gfm": "^4.0.0",
121
- "remark-mdx": "^3.0.0",
121
+ "remark-mdx": "^3.0.1",
122
122
  "scroll-into-view-if-needed": "^3.1.0",
123
- "shiki": "1.1.7",
124
- "swr": "^2.2.2",
123
+ "shiki": "^1.1.7",
124
+ "swr": "^2.2.5",
125
125
  "unist-util-visit": "^5.0.0"
126
126
  },
127
127
  "devDependencies": {
128
- "@algolia/client-search": "^4.20.0",
129
- "@next/eslint-plugin-next": "^14.0.0",
128
+ "@algolia/client-search": "^4.22.1",
130
129
  "@types/flexsearch": "0.7.6",
131
130
  "@types/hast": "^3.0.4",
132
131
  "@types/mdast": "^4.0.3",
133
- "@types/negotiator": "^0.6.1",
132
+ "@types/negotiator": "^0.6.3",
134
133
  "@types/node": "18.17.5",
135
- "@types/react": "18.2.0",
136
- "@types/react-dom": "18.2.1",
137
- "algoliasearch": "^4.20.0",
138
- "next": "14.1.1",
134
+ "@types/react": "^18.2.0",
135
+ "@types/react-dom": "^18.2.1",
136
+ "algoliasearch": "^4.22.1",
137
+ "next": "^14.1.2",
139
138
  "unified": "^11.0.4",
140
139
  "eslint-config-custom": "0.0.0",
141
140
  "tsconfig": "0.0.0"
142
141
  },
143
142
  "peerDependencies": {
144
- "next": ">= 13.4",
143
+ "next": ">= 14.1.0",
145
144
  "react": ">= 18",
146
145
  "react-dom": ">= 18"
147
146
  },