fumadocs-core 14.1.1 → 14.2.1

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.
@@ -11,6 +11,6 @@ type TableOfContents = TOCItemType[];
11
11
  *
12
12
  * @param content - Markdown content
13
13
  */
14
- declare function getTableOfContents(content: string): Promise<TableOfContents>;
14
+ declare function getTableOfContents(content: string): TableOfContents;
15
15
 
16
16
  export { type TableOfContents as T, type TOCItemType as a, getTableOfContents as g };
@@ -3,8 +3,9 @@ import { Root } from 'hast';
3
3
  import { RehypeShikiOptions } from '@shikijs/rehype';
4
4
  import { Processor, Transformer } from 'unified';
5
5
  import { ShikiTransformer } from 'shiki';
6
- import { Root as Root$1, Heading } from 'mdast';
6
+ import { Root as Root$1 } from 'mdast';
7
7
  export { a as StructureOptions, S as StructuredData, r as remarkStructure, s as structure } from '../remark-structure-mP51W1AN.js';
8
+ export { R as RemarkHeadingOptions, r as remarkHeading } from '../remark-heading-BPCoYwjn.js';
8
9
  import 'unist-util-visit';
9
10
 
10
11
  interface CodeBlockIcon {
@@ -87,33 +88,6 @@ interface RemarkImageOptions {
87
88
  */
88
89
  declare function remarkImage({ placeholder, external, useImport, publicDir, }?: RemarkImageOptions): Transformer<Root$1, Root$1>;
89
90
 
90
- declare module 'mdast' {
91
- interface HeadingData extends Data {
92
- hProperties?: {
93
- id?: string;
94
- };
95
- }
96
- }
97
- interface RemarkHeadingOptions {
98
- slug?: (root: Root$1, heading: Heading, text: string) => string;
99
- /**
100
- * Allow custom headings ids
101
- *
102
- * @defaultValue true
103
- */
104
- customId?: boolean;
105
- /**
106
- * Attach an array of `TOCItemType` to `file.data.toc`
107
- *
108
- * @defaultValue true
109
- */
110
- generateToc?: boolean;
111
- }
112
- /**
113
- * Add heading ids and extract TOC
114
- */
115
- declare function remarkHeading({ slug: defaultSlug, customId, generateToc, }?: RemarkHeadingOptions): Transformer<Root$1, Root$1>;
116
-
117
91
  interface RemarkAdmonitionOptions {
118
92
  tag?: string;
119
93
  types?: string[];
@@ -139,4 +113,4 @@ interface RehypeTocOptions {
139
113
  }
140
114
  declare function rehypeToc(this: Processor, { exportToc }?: RehypeTocOptions): Transformer<Root, Root>;
141
115
 
142
- export { type CodeBlockIcon, type RehypeCodeOptions, type RehypeTocOptions, type RemarkAdmonitionOptions, type RemarkHeadingOptions, type RemarkImageOptions, rehypeCode, rehypeCodeDefaultOptions, rehypeToc, remarkAdmonition, remarkHeading, remarkImage, transformerIcon, transformerTab };
116
+ export { type CodeBlockIcon, type RehypeCodeOptions, type RehypeTocOptions, type RemarkAdmonitionOptions, type RemarkImageOptions, rehypeCode, rehypeCodeDefaultOptions, rehypeToc, remarkAdmonition, remarkImage, transformerIcon, transformerTab };
@@ -1,11 +1,11 @@
1
- import {
2
- flattenNode,
3
- remarkHeading
4
- } from "../chunk-4MNUWZIW.js";
5
1
  import {
6
2
  resolvePath,
7
3
  slash
8
4
  } from "../chunk-SHGL6VBO.js";
5
+ import {
6
+ flattenNode,
7
+ remarkHeading
8
+ } from "../chunk-4MNUWZIW.js";
9
9
  import {
10
10
  createStyleTransformer,
11
11
  defaultThemes
@@ -0,0 +1,50 @@
1
+ import {
2
+ removeUndefined
3
+ } from "./chunk-2V6SCS43.js";
4
+ import "./chunk-MLKGABMK.js";
5
+
6
+ // src/search/client/orama-cloud.ts
7
+ async function searchDocs(query, tag, options) {
8
+ const { client, params: extraParams = {} } = options;
9
+ const params = {
10
+ ...extraParams,
11
+ term: query,
12
+ where: removeUndefined({
13
+ tag,
14
+ ...extraParams.where
15
+ }),
16
+ groupBy: {
17
+ properties: ["page_id"],
18
+ maxResult: 7,
19
+ ...extraParams.groupBy
20
+ }
21
+ };
22
+ const result = await client.search(params);
23
+ if (!result) return [];
24
+ const list = [];
25
+ for (const item of result.groups ?? []) {
26
+ let addedHead = false;
27
+ for (const hit of item.result) {
28
+ const doc = hit.document;
29
+ if (!addedHead) {
30
+ list.push({
31
+ id: doc.page_id,
32
+ type: "page",
33
+ content: doc.title,
34
+ url: doc.url
35
+ });
36
+ addedHead = true;
37
+ }
38
+ list.push({
39
+ id: doc.id,
40
+ content: doc.content,
41
+ type: doc.content === doc.section ? "heading" : "text",
42
+ url: doc.section_id ? `${doc.url}#${doc.section_id}` : doc.url
43
+ });
44
+ }
45
+ }
46
+ return list;
47
+ }
48
+ export {
49
+ searchDocs
50
+ };
@@ -0,0 +1,31 @@
1
+ import { Root, Heading } from 'mdast';
2
+ import { Transformer } from 'unified';
3
+
4
+ declare module 'mdast' {
5
+ interface HeadingData extends Data {
6
+ hProperties?: {
7
+ id?: string;
8
+ };
9
+ }
10
+ }
11
+ interface RemarkHeadingOptions {
12
+ slug?: (root: Root, heading: Heading, text: string) => string;
13
+ /**
14
+ * Allow custom headings ids
15
+ *
16
+ * @defaultValue true
17
+ */
18
+ customId?: boolean;
19
+ /**
20
+ * Attach an array of `TOCItemType` to `file.data.toc`
21
+ *
22
+ * @defaultValue true
23
+ */
24
+ generateToc?: boolean;
25
+ }
26
+ /**
27
+ * Add heading ids and extract TOC
28
+ */
29
+ declare function remarkHeading({ slug: defaultSlug, customId, generateToc, }?: RemarkHeadingOptions): Transformer<Root, Root>;
30
+
31
+ export { type RemarkHeadingOptions as R, remarkHeading as r };
@@ -1,6 +1,7 @@
1
1
  import { S as SortedResult } from '../types-Ch8gnVgO.js';
2
2
  import { SearchOptions } from '@algolia/client-search';
3
3
  import { SearchIndex } from 'algoliasearch/lite';
4
+ import { OramaClient, ClientSearchParams } from '@oramacloud/client';
4
5
 
5
6
  interface FetchOptions {
6
7
  /**
@@ -20,6 +21,11 @@ interface AlgoliaOptions extends SearchOptions {
20
21
  index: SearchIndex;
21
22
  }
22
23
 
24
+ interface OramaCloudOptions {
25
+ client: OramaClient;
26
+ params?: ClientSearchParams;
27
+ }
28
+
23
29
  interface UseDocsSearch {
24
30
  search: string;
25
31
  setSearch: (v: string) => void;
@@ -35,7 +41,9 @@ type Client = ({
35
41
  type: 'static';
36
42
  } & StaticOptions) | ({
37
43
  type: 'algolia';
38
- } & AlgoliaOptions);
44
+ } & AlgoliaOptions) | ({
45
+ type: 'orama-cloud';
46
+ } & OramaCloudOptions);
39
47
  /**
40
48
  * @param client - search client
41
49
  * @param locale - Filter with locale
@@ -46,4 +54,4 @@ type Client = ({
46
54
  */
47
55
  declare function useDocsSearch(client: Client, locale?: string, tag?: string, delayMs?: number, allowEmpty?: boolean, key?: string): UseDocsSearch;
48
56
 
49
- export { useDocsSearch };
57
+ export { type AlgoliaOptions, type FetchOptions, type OramaCloudOptions, type StaticOptions, useDocsSearch };
@@ -33,8 +33,8 @@ function useDocsSearch(client, locale, tag, delayMs = 100, allowEmpty = false, k
33
33
  const debouncedValue = useDebounce(search, delayMs);
34
34
  const onStart = useRef2();
35
35
  const cacheKey = useMemo(() => {
36
- return key ?? JSON.stringify([client, debouncedValue, locale, tag]);
37
- }, [client, debouncedValue, locale, tag, key]);
36
+ return key ?? JSON.stringify([client.type, debouncedValue, locale, tag]);
37
+ }, [client.type, debouncedValue, locale, tag, key]);
38
38
  useOnChange(cacheKey, () => {
39
39
  const cached = cache.get(cacheKey);
40
40
  if (onStart.current) {
@@ -63,6 +63,10 @@ function useDocsSearch(client, locale, tag, delayMs = 100, allowEmpty = false, k
63
63
  const { searchDocs } = await import("../algolia-NTWLS6J3.js");
64
64
  return searchDocs(index, debouncedValue, tag, rest);
65
65
  }
66
+ if (client.type === "orama-cloud") {
67
+ const { searchDocs } = await import("../orama-cloud-QNHGN6SO.js");
68
+ return searchDocs(debouncedValue, tag, client);
69
+ }
66
70
  const { createStaticClient } = await import("../static-5GPJ7RUY.js");
67
71
  if (!staticClient) staticClient = createStaticClient(client);
68
72
  return staticClient.search(debouncedValue, locale, tag);
@@ -0,0 +1,76 @@
1
+ import { CloudManager } from '@oramacloud/client';
2
+ import { S as StructuredData } from '../remark-structure-mP51W1AN.js';
3
+ import '../remark-heading-BPCoYwjn.js';
4
+ import 'mdast';
5
+ import 'unified';
6
+ import 'unist-util-visit';
7
+
8
+ interface SyncOptions {
9
+ /**
10
+ * Index name to sync
11
+ */
12
+ index: string;
13
+ documents: OramaDocument[];
14
+ /**
15
+ * Deploy changes
16
+ *
17
+ * @defaultValue true
18
+ */
19
+ autoDeploy?: boolean;
20
+ }
21
+ type I18nSyncOptions = Omit<SyncOptions, 'index' | 'documents'> & {
22
+ /**
23
+ * Indexes to sync.
24
+ *
25
+ * Pairs of `locale`-`index`.
26
+ **/
27
+ indexes: Record<string, string>;
28
+ documents: {
29
+ locale: string;
30
+ items: OramaDocument[];
31
+ }[];
32
+ };
33
+ interface OramaDocument {
34
+ /**
35
+ * The ID of document, must be unique
36
+ */
37
+ id: string;
38
+ title: string;
39
+ description?: string;
40
+ /**
41
+ * URL to the page
42
+ */
43
+ url: string;
44
+ structured: StructuredData;
45
+ /**
46
+ * Tag to filter results
47
+ */
48
+ tag?: string;
49
+ /**
50
+ * Data to be added to each section index
51
+ */
52
+ extra_data?: object;
53
+ }
54
+ interface OramaIndex {
55
+ id: string;
56
+ title: string;
57
+ url: string;
58
+ tag?: string;
59
+ /**
60
+ * The id of page, used for `group by`
61
+ */
62
+ page_id: string;
63
+ /**
64
+ * Heading content
65
+ */
66
+ section?: string;
67
+ /**
68
+ * Heading (anchor) id
69
+ */
70
+ section_id?: string;
71
+ content: string;
72
+ }
73
+ declare function sync(cloudManager: CloudManager, options: SyncOptions): Promise<void>;
74
+ declare function syncI18n(cloudManager: CloudManager, options: I18nSyncOptions): Promise<void>;
75
+
76
+ export { type I18nSyncOptions, type OramaDocument, type OramaIndex, type SyncOptions, sync, syncI18n };
@@ -0,0 +1,52 @@
1
+ import "../chunk-MLKGABMK.js";
2
+
3
+ // src/search/orama-cloud.ts
4
+ async function sync(cloudManager, options) {
5
+ const { autoDeploy = true } = options;
6
+ const index = cloudManager.index(options.index);
7
+ await index.snapshot(options.documents.flatMap(toIndex));
8
+ if (autoDeploy) await index.deploy();
9
+ }
10
+ async function syncI18n(cloudManager, options) {
11
+ const { autoDeploy = true } = options;
12
+ const tasks = options.documents.map(async (document) => {
13
+ const index = cloudManager.index(options.indexes[document.locale]);
14
+ await index.snapshot(document.items.flatMap(toIndex));
15
+ if (autoDeploy) await index.deploy();
16
+ });
17
+ await Promise.all(tasks);
18
+ }
19
+ function toIndex(page) {
20
+ let id = 0;
21
+ const indexes = [];
22
+ const scannedHeadings = /* @__PURE__ */ new Set();
23
+ function createIndex(section, sectionId, content) {
24
+ return {
25
+ id: `${page.id}-${(id++).toString()}`,
26
+ title: page.title,
27
+ url: page.url,
28
+ page_id: page.id,
29
+ tag: page.tag,
30
+ section,
31
+ section_id: sectionId,
32
+ content,
33
+ ...page.extra_data
34
+ };
35
+ }
36
+ if (page.description)
37
+ indexes.push(createIndex(void 0, void 0, page.description));
38
+ page.structured.contents.forEach((p) => {
39
+ const heading = p.heading ? page.structured.headings.find((h) => p.heading === h.id) : null;
40
+ const index = createIndex(heading?.content, heading?.id, p.content);
41
+ if (heading && !scannedHeadings.has(heading.id)) {
42
+ scannedHeadings.add(heading.id);
43
+ indexes.push(createIndex(heading.content, heading.id, heading.content));
44
+ }
45
+ indexes.push(index);
46
+ });
47
+ return indexes;
48
+ }
49
+ export {
50
+ sync,
51
+ syncI18n
52
+ };
@@ -1,4 +1,4 @@
1
- export { a as TOCItemType, T as TableOfContents, g as getTableOfContents } from '../get-toc-CM4X3hbw.js';
1
+ export { a as TOCItemType, T as TableOfContents, g as getTableOfContents } from '../get-toc-Dm1yr2Gr.js';
2
2
  import { N as Node, I as Item, R as Root } from '../page-tree-r8qjoUla.js';
3
3
  export { p as PageTree } from '../page-tree-r8qjoUla.js';
4
4
  export { S as SortedResult } from '../types-Ch8gnVgO.js';
@@ -10,8 +10,8 @@ import "../chunk-MLKGABMK.js";
10
10
 
11
11
  // src/server/get-toc.ts
12
12
  import { remark } from "remark";
13
- async function getTableOfContents(content) {
14
- const result = await remark().use(remarkHeading).process(content);
13
+ function getTableOfContents(content) {
14
+ const result = remark().use(remarkHeading).processSync(content);
15
15
  if ("toc" in result.data) return result.data.toc;
16
16
  return [];
17
17
  }
package/dist/toc.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as react from 'react';
2
2
  import { ReactNode, RefObject, AnchorHTMLAttributes } from 'react';
3
- import { T as TableOfContents } from './get-toc-CM4X3hbw.js';
3
+ import { T as TableOfContents } from './get-toc-Dm1yr2Gr.js';
4
4
 
5
5
  /**
6
6
  * The estimated active heading ID
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fumadocs-core",
3
- "version": "14.1.1",
3
+ "version": "14.2.1",
4
4
  "description": "The library for building a documentation website in Next.js",
5
5
  "keywords": [
6
6
  "NextJs",
@@ -36,6 +36,10 @@
36
36
  "import": "./dist/search/algolia.js",
37
37
  "types": "./dist/search/algolia.d.ts"
38
38
  },
39
+ "./search/orama-cloud": {
40
+ "import": "./dist/search/orama-cloud.js",
41
+ "types": "./dist/search/orama-cloud.d.ts"
42
+ },
39
43
  "./server": {
40
44
  "import": "./dist/server/index.js",
41
45
  "types": "./dist/server/index.d.ts"
@@ -87,17 +91,18 @@
87
91
  "devDependencies": {
88
92
  "@algolia/client-search": "4.24.0",
89
93
  "@mdx-js/mdx": "^3.1.0",
94
+ "@oramacloud/client": "^1.3.19",
90
95
  "@types/estree-jsx": "^1.0.5",
91
96
  "@types/hast": "^3.0.4",
92
97
  "@types/mdast": "^4.0.3",
93
98
  "@types/negotiator": "^0.6.3",
94
- "@types/node": "22.8.1",
99
+ "@types/node": "22.8.6",
95
100
  "@types/react": "^18.3.12",
96
101
  "@types/react-dom": "^18.3.1",
97
102
  "algoliasearch": "4.24.0",
98
103
  "mdast-util-mdx-jsx": "^3.1.3",
99
104
  "mdast-util-mdxjs-esm": "^2.0.1",
100
- "next": "^15.0.0",
105
+ "next": "^15.0.2",
101
106
  "remark-mdx": "^3.1.0",
102
107
  "remark-rehype": "^11.1.1",
103
108
  "shiki-transformers": "^1.0.0",
@@ -106,12 +111,16 @@
106
111
  "tsconfig": "0.0.0"
107
112
  },
108
113
  "peerDependencies": {
114
+ "@oramacloud/client": "1.x.x",
109
115
  "algoliasearch": "4.24.0",
110
116
  "next": "14.x.x || 15.x.x",
111
117
  "react": ">= 18",
112
118
  "react-dom": ">= 18"
113
119
  },
114
120
  "peerDependenciesMeta": {
121
+ "@oramacloud/client": {
122
+ "optional": true
123
+ },
115
124
  "algoliasearch": {
116
125
  "optional": true
117
126
  },