@hanzo/docs-core 16.2.5
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.
- package/LICENSE +21 -0
- package/README.md +5 -0
- package/dist/algolia-IZEDLPHE.js +58 -0
- package/dist/breadcrumb.d.ts +46 -0
- package/dist/breadcrumb.js +81 -0
- package/dist/chunk-5PMI7QDD.js +220 -0
- package/dist/chunk-ADBHPKXG.js +78 -0
- package/dist/chunk-APKPSBSB.js +74 -0
- package/dist/chunk-CH7YHH7V.js +222 -0
- package/dist/chunk-EFVXL2PP.js +144 -0
- package/dist/chunk-EMWGTXSW.js +19 -0
- package/dist/chunk-FAEPKD7U.js +20 -0
- package/dist/chunk-FUUVPEA5.js +29 -0
- package/dist/chunk-GINBKBVQ.js +12 -0
- package/dist/chunk-GLRQBLGN.js +59 -0
- package/dist/chunk-JUF4WZ6G.js +117 -0
- package/dist/chunk-K4WNLOVQ.js +75 -0
- package/dist/chunk-L4JKQWCM.js +131 -0
- package/dist/chunk-MA6O2UUE.js +50 -0
- package/dist/chunk-ONG4RVCR.js +8 -0
- package/dist/chunk-OTD7MV33.js +53 -0
- package/dist/chunk-PFNP6PEB.js +11 -0
- package/dist/chunk-QJRXMG4S.js +275 -0
- package/dist/chunk-SH7BNTG7.js +38 -0
- package/dist/chunk-TWIDBWFG.js +84 -0
- package/dist/chunk-U67V476Y.js +35 -0
- package/dist/chunk-VLSDGCJE.js +47 -0
- package/dist/chunk-W6WTLKRA.js +73 -0
- package/dist/chunk-X2HFD5QJ.js +275 -0
- package/dist/chunk-XJ6ZQNEX.js +91 -0
- package/dist/chunk-XN2LKXFZ.js +101 -0
- package/dist/chunk-XOFXGHS4.js +93 -0
- package/dist/chunk-XZSI7AHE.js +67 -0
- package/dist/chunk-YVVDKJ2H.js +34 -0
- package/dist/chunk-ZMWYLUDP.js +21 -0
- package/dist/content/github.d.ts +40 -0
- package/dist/content/github.js +44 -0
- package/dist/content/index.d.ts +16 -0
- package/dist/content/index.js +30 -0
- package/dist/content/mdx/preset-bundler.d.ts +31 -0
- package/dist/content/mdx/preset-bundler.js +72 -0
- package/dist/content/mdx/preset-runtime.d.ts +31 -0
- package/dist/content/mdx/preset-runtime.js +71 -0
- package/dist/content/toc.d.ts +21 -0
- package/dist/content/toc.js +22 -0
- package/dist/definitions-pJ7PybYY.d.ts +60 -0
- package/dist/dynamic-link.d.ts +12 -0
- package/dist/dynamic-link.js +32 -0
- package/dist/fetch-IBTWQCJR.js +22 -0
- package/dist/framework/index.d.ts +41 -0
- package/dist/framework/index.js +18 -0
- package/dist/framework/next.d.ts +12 -0
- package/dist/framework/next.js +31 -0
- package/dist/framework/react-router.d.ts +12 -0
- package/dist/framework/react-router.js +59 -0
- package/dist/framework/tanstack.d.ts +15 -0
- package/dist/framework/tanstack.js +72 -0
- package/dist/framework/waku.d.ts +12 -0
- package/dist/framework/waku.js +63 -0
- package/dist/highlight/client.d.ts +15 -0
- package/dist/highlight/client.js +18 -0
- package/dist/highlight/index.d.ts +30 -0
- package/dist/highlight/index.js +13 -0
- package/dist/i18n/index.d.ts +39 -0
- package/dist/i18n/index.js +9 -0
- package/dist/i18n/middleware.d.ts +34 -0
- package/dist/i18n/middleware.js +76 -0
- package/dist/link.d.ts +18 -0
- package/dist/link.js +9 -0
- package/dist/loader-BvlPPJX0.d.ts +321 -0
- package/dist/mdx-plugins/codeblock-utils.d.ts +29 -0
- package/dist/mdx-plugins/codeblock-utils.js +9 -0
- package/dist/mdx-plugins/index.d.ts +20 -0
- package/dist/mdx-plugins/index.js +73 -0
- package/dist/mdx-plugins/rehype-code.d.ts +55 -0
- package/dist/mdx-plugins/rehype-code.js +15 -0
- package/dist/mdx-plugins/rehype-toc.d.ts +14 -0
- package/dist/mdx-plugins/rehype-toc.js +7 -0
- package/dist/mdx-plugins/remark-admonition.d.ts +20 -0
- package/dist/mdx-plugins/remark-admonition.js +8 -0
- package/dist/mdx-plugins/remark-code-tab.d.ts +30 -0
- package/dist/mdx-plugins/remark-code-tab.js +8 -0
- package/dist/mdx-plugins/remark-directive-admonition.d.ts +27 -0
- package/dist/mdx-plugins/remark-directive-admonition.js +7 -0
- package/dist/mdx-plugins/remark-gfm.d.ts +1 -0
- package/dist/mdx-plugins/remark-gfm.js +7 -0
- package/dist/mdx-plugins/remark-heading.d.ts +31 -0
- package/dist/mdx-plugins/remark-heading.js +8 -0
- package/dist/mdx-plugins/remark-image.d.ts +57 -0
- package/dist/mdx-plugins/remark-image.js +7 -0
- package/dist/mdx-plugins/remark-mdx-files.d.ts +40 -0
- package/dist/mdx-plugins/remark-mdx-files.js +7 -0
- package/dist/mdx-plugins/remark-mdx-mermaid.d.ts +15 -0
- package/dist/mdx-plugins/remark-mdx-mermaid.js +7 -0
- package/dist/mdx-plugins/remark-npm.d.ts +31 -0
- package/dist/mdx-plugins/remark-npm.js +8 -0
- package/dist/mdx-plugins/remark-steps.d.ts +23 -0
- package/dist/mdx-plugins/remark-steps.js +7 -0
- package/dist/mdx-plugins/remark-structure.d.ts +71 -0
- package/dist/mdx-plugins/remark-structure.js +12 -0
- package/dist/mixedbread-RAHDVXGJ.js +118 -0
- package/dist/negotiation/index.d.ts +19 -0
- package/dist/negotiation/index.js +11 -0
- package/dist/orama-cloud-UZAPMPFV.js +93 -0
- package/dist/page-tree/index.d.ts +33 -0
- package/dist/page-tree/index.js +17 -0
- package/dist/search/algolia.d.ts +69 -0
- package/dist/search/algolia.js +71 -0
- package/dist/search/client.d.ts +140 -0
- package/dist/search/client.js +99 -0
- package/dist/search/index.d.ts +26 -0
- package/dist/search/index.js +7 -0
- package/dist/search/orama-cloud.d.ts +79 -0
- package/dist/search/orama-cloud.js +60 -0
- package/dist/search/server.d.ts +136 -0
- package/dist/search/server.js +400 -0
- package/dist/source/client/index.d.ts +16 -0
- package/dist/source/client/index.js +41 -0
- package/dist/source/index.d.ts +42 -0
- package/dist/source/index.js +776 -0
- package/dist/source/plugins/lucide-icons.d.ts +14 -0
- package/dist/source/plugins/lucide-icons.js +23 -0
- package/dist/source/schema.d.ts +26 -0
- package/dist/source/schema.js +25 -0
- package/dist/static-A2YJ5TXV.js +62 -0
- package/dist/toc.d.ts +43 -0
- package/dist/toc.js +151 -0
- package/dist/util-bZU2QeJ2.d.ts +6 -0
- package/dist/utils/use-effect-event.d.ts +9 -0
- package/dist/utils/use-effect-event.js +16 -0
- package/dist/utils/use-media-query.d.ts +3 -0
- package/dist/utils/use-media-query.js +23 -0
- package/dist/utils/use-on-change.d.ts +8 -0
- package/dist/utils/use-on-change.js +7 -0
- package/package.json +222 -0
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { Algoliasearch } from 'algoliasearch';
|
|
2
|
+
import { StructuredData } from '../mdx-plugins/remark-structure.js';
|
|
3
|
+
import 'mdast';
|
|
4
|
+
import 'unified';
|
|
5
|
+
import 'mdast-util-mdx-jsx';
|
|
6
|
+
|
|
7
|
+
interface DocumentRecord {
|
|
8
|
+
/**
|
|
9
|
+
* The ID of document, must be unique
|
|
10
|
+
*/
|
|
11
|
+
_id: string;
|
|
12
|
+
title: string;
|
|
13
|
+
description?: string;
|
|
14
|
+
breadcrumbs?: string[];
|
|
15
|
+
/**
|
|
16
|
+
* URL to the page
|
|
17
|
+
*/
|
|
18
|
+
url: string;
|
|
19
|
+
structured: StructuredData;
|
|
20
|
+
/**
|
|
21
|
+
* Tag to filter results
|
|
22
|
+
*/
|
|
23
|
+
tag?: string;
|
|
24
|
+
/**
|
|
25
|
+
* Data to be added to each section index
|
|
26
|
+
*/
|
|
27
|
+
extra_data?: object;
|
|
28
|
+
}
|
|
29
|
+
interface SyncOptions {
|
|
30
|
+
/**
|
|
31
|
+
* Index Name for documents.
|
|
32
|
+
*/
|
|
33
|
+
indexName?: string;
|
|
34
|
+
/**
|
|
35
|
+
* Search indexes
|
|
36
|
+
*/
|
|
37
|
+
documents: DocumentRecord[];
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Update index settings and replace all objects
|
|
41
|
+
*
|
|
42
|
+
* @param client - Algolia Admin Client
|
|
43
|
+
* @param options - Index Options
|
|
44
|
+
*/
|
|
45
|
+
declare function sync(client: Algoliasearch, options: SyncOptions): Promise<void>;
|
|
46
|
+
declare function setIndexSettings(client: Algoliasearch, indexName: string): Promise<void>;
|
|
47
|
+
declare function updateDocuments(client: Algoliasearch, indexName: string, documents: DocumentRecord[]): Promise<void>;
|
|
48
|
+
interface BaseIndex {
|
|
49
|
+
objectID: string;
|
|
50
|
+
title: string;
|
|
51
|
+
url: string;
|
|
52
|
+
tag?: string;
|
|
53
|
+
/**
|
|
54
|
+
* The id of page, used for distinct
|
|
55
|
+
*/
|
|
56
|
+
page_id: string;
|
|
57
|
+
/**
|
|
58
|
+
* Heading content
|
|
59
|
+
*/
|
|
60
|
+
section?: string;
|
|
61
|
+
/**
|
|
62
|
+
* Heading (anchor) id
|
|
63
|
+
*/
|
|
64
|
+
section_id?: string;
|
|
65
|
+
breadcrumbs?: string[];
|
|
66
|
+
content: string;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export { type BaseIndex, type DocumentRecord, type SyncOptions, setIndexSettings, sync, updateDocuments };
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import "../chunk-U67V476Y.js";
|
|
2
|
+
|
|
3
|
+
// src/search/algolia.ts
|
|
4
|
+
async function sync(client, options) {
|
|
5
|
+
const { indexName = "document", documents } = options;
|
|
6
|
+
await setIndexSettings(client, indexName);
|
|
7
|
+
await updateDocuments(client, indexName, documents);
|
|
8
|
+
}
|
|
9
|
+
async function setIndexSettings(client, indexName) {
|
|
10
|
+
await client.setSettings({
|
|
11
|
+
indexName,
|
|
12
|
+
indexSettings: {
|
|
13
|
+
attributeForDistinct: "page_id",
|
|
14
|
+
attributesToRetrieve: [
|
|
15
|
+
"title",
|
|
16
|
+
"section",
|
|
17
|
+
"content",
|
|
18
|
+
"url",
|
|
19
|
+
"section_id",
|
|
20
|
+
"breadcrumbs"
|
|
21
|
+
],
|
|
22
|
+
searchableAttributes: ["title", "section", "content"],
|
|
23
|
+
attributesToSnippet: [],
|
|
24
|
+
attributesForFaceting: ["tag"]
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
function toIndex(page) {
|
|
29
|
+
let id = 0;
|
|
30
|
+
const indexes = [];
|
|
31
|
+
const scannedHeadings = /* @__PURE__ */ new Set();
|
|
32
|
+
function createIndex(section, sectionId, content) {
|
|
33
|
+
return {
|
|
34
|
+
objectID: `${page._id}-${(id++).toString()}`,
|
|
35
|
+
breadcrumbs: page.breadcrumbs,
|
|
36
|
+
title: page.title,
|
|
37
|
+
url: page.url,
|
|
38
|
+
page_id: page._id,
|
|
39
|
+
tag: page.tag,
|
|
40
|
+
section,
|
|
41
|
+
section_id: sectionId,
|
|
42
|
+
content,
|
|
43
|
+
...page.extra_data
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
if (page.description)
|
|
47
|
+
indexes.push(createIndex(void 0, void 0, page.description));
|
|
48
|
+
const { headings, contents } = page.structured;
|
|
49
|
+
for (const p of contents) {
|
|
50
|
+
const heading = p.heading ? headings.find((h) => p.heading === h.id) : null;
|
|
51
|
+
const index = createIndex(heading?.content, heading?.id, p.content);
|
|
52
|
+
if (heading && !scannedHeadings.has(heading.id)) {
|
|
53
|
+
scannedHeadings.add(heading.id);
|
|
54
|
+
indexes.push(createIndex(heading.content, heading.id, heading.content));
|
|
55
|
+
}
|
|
56
|
+
indexes.push(index);
|
|
57
|
+
}
|
|
58
|
+
return indexes;
|
|
59
|
+
}
|
|
60
|
+
async function updateDocuments(client, indexName, documents) {
|
|
61
|
+
const objects = documents.flatMap(toIndex);
|
|
62
|
+
await client.replaceAllObjects({
|
|
63
|
+
indexName,
|
|
64
|
+
objects
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
export {
|
|
68
|
+
setIndexSettings,
|
|
69
|
+
sync,
|
|
70
|
+
updateDocuments
|
|
71
|
+
};
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { DependencyList } from 'react';
|
|
2
|
+
import { AnyOrama } from '@orama/orama';
|
|
3
|
+
import '../mdx-plugins/remark-structure.js';
|
|
4
|
+
import { BaseIndex } from './algolia.js';
|
|
5
|
+
import { LiteClient, SearchResponse } from 'algoliasearch/lite';
|
|
6
|
+
import { OramaCloud, OramaCloudSearchParams } from '@orama/core';
|
|
7
|
+
import Mixedbread from '@mixedbread/sdk';
|
|
8
|
+
import { SortedResult } from './index.js';
|
|
9
|
+
import 'mdast';
|
|
10
|
+
import 'unified';
|
|
11
|
+
import 'mdast-util-mdx-jsx';
|
|
12
|
+
import 'algoliasearch';
|
|
13
|
+
|
|
14
|
+
interface FetchOptions {
|
|
15
|
+
/**
|
|
16
|
+
* API route for search endpoint, support absolute URLs.
|
|
17
|
+
*
|
|
18
|
+
* @defaultValue '/api/search'
|
|
19
|
+
*/
|
|
20
|
+
api?: string;
|
|
21
|
+
/**
|
|
22
|
+
* Filter results with specific tag(s).
|
|
23
|
+
*/
|
|
24
|
+
tag?: string | string[];
|
|
25
|
+
/**
|
|
26
|
+
* Filter by locale
|
|
27
|
+
*/
|
|
28
|
+
locale?: string;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
interface StaticOptions {
|
|
32
|
+
/**
|
|
33
|
+
* Where to download exported search indexes (URL)
|
|
34
|
+
*
|
|
35
|
+
* @defaultValue '/api/search'
|
|
36
|
+
*/
|
|
37
|
+
from?: string;
|
|
38
|
+
initOrama?: (locale?: string) => AnyOrama | Promise<AnyOrama>;
|
|
39
|
+
/**
|
|
40
|
+
* Filter results with specific tag(s).
|
|
41
|
+
*/
|
|
42
|
+
tag?: string | string[];
|
|
43
|
+
/**
|
|
44
|
+
* Filter by locale (unsupported at the moment)
|
|
45
|
+
*/
|
|
46
|
+
locale?: string;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
interface AlgoliaOptions {
|
|
50
|
+
indexName: string;
|
|
51
|
+
client: LiteClient;
|
|
52
|
+
/**
|
|
53
|
+
* Filter results with specific tag.
|
|
54
|
+
*/
|
|
55
|
+
tag?: string;
|
|
56
|
+
locale?: string;
|
|
57
|
+
onSearch?: (query: string, tag?: string, locale?: string) => Promise<{
|
|
58
|
+
results: SearchResponse<BaseIndex>[];
|
|
59
|
+
}>;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
interface OramaCloudOptions {
|
|
63
|
+
client: OramaCloud;
|
|
64
|
+
/**
|
|
65
|
+
* The type of your index.
|
|
66
|
+
*
|
|
67
|
+
* You can set it to `crawler` if you use crawler instead of the JSON index with schema provided by Fumadocs
|
|
68
|
+
*/
|
|
69
|
+
index?: 'default' | 'crawler';
|
|
70
|
+
params?: Partial<OramaCloudSearchParams>;
|
|
71
|
+
/**
|
|
72
|
+
* Filter results with specific tag.
|
|
73
|
+
*/
|
|
74
|
+
tag?: string;
|
|
75
|
+
/**
|
|
76
|
+
* Filter by locale (unsupported at the moment)
|
|
77
|
+
*/
|
|
78
|
+
locale?: string;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
interface MixedbreadOptions {
|
|
82
|
+
/**
|
|
83
|
+
* The ID of the vector store to search in
|
|
84
|
+
*/
|
|
85
|
+
vectorStoreId: string;
|
|
86
|
+
/**
|
|
87
|
+
* The Mixedbread SDK client instance
|
|
88
|
+
*/
|
|
89
|
+
client: Mixedbread;
|
|
90
|
+
/**
|
|
91
|
+
* Filter results with specific tag.
|
|
92
|
+
*/
|
|
93
|
+
tag?: string;
|
|
94
|
+
/**
|
|
95
|
+
* Filter by locale (unsupported at the moment)
|
|
96
|
+
*/
|
|
97
|
+
locale?: string;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
interface UseDocsSearch {
|
|
101
|
+
search: string;
|
|
102
|
+
setSearch: (v: string) => void;
|
|
103
|
+
query: {
|
|
104
|
+
isLoading: boolean;
|
|
105
|
+
data?: SortedResult[] | 'empty';
|
|
106
|
+
error?: Error;
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
type Client = ({
|
|
110
|
+
type: 'fetch';
|
|
111
|
+
} & FetchOptions) | ({
|
|
112
|
+
type: 'static';
|
|
113
|
+
} & StaticOptions) | ({
|
|
114
|
+
type: 'algolia';
|
|
115
|
+
} & AlgoliaOptions) | ({
|
|
116
|
+
type: 'orama-cloud';
|
|
117
|
+
} & OramaCloudOptions) | ({
|
|
118
|
+
type: 'mixedbread';
|
|
119
|
+
} & MixedbreadOptions);
|
|
120
|
+
/**
|
|
121
|
+
* Provide a hook to query different official search clients.
|
|
122
|
+
*
|
|
123
|
+
* Note: it will re-query when its parameters changed, make sure to use `useMemo()` on `clientOptions` or define `deps` array.
|
|
124
|
+
*/
|
|
125
|
+
declare function useDocsSearch(clientOptions: Client & {
|
|
126
|
+
/**
|
|
127
|
+
* The debounced delay for performing a search (in ms).
|
|
128
|
+
* .
|
|
129
|
+
* @defaultValue 100
|
|
130
|
+
*/
|
|
131
|
+
delayMs?: number;
|
|
132
|
+
/**
|
|
133
|
+
* still perform search even if query is empty.
|
|
134
|
+
*
|
|
135
|
+
* @defaultValue false
|
|
136
|
+
*/
|
|
137
|
+
allowEmpty?: boolean;
|
|
138
|
+
}, deps?: DependencyList): UseDocsSearch;
|
|
139
|
+
|
|
140
|
+
export { type AlgoliaOptions, type Client, type FetchOptions, type OramaCloudOptions, type StaticOptions, useDocsSearch };
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import {
|
|
2
|
+
useOnChange
|
|
3
|
+
} from "../chunk-EMWGTXSW.js";
|
|
4
|
+
import "../chunk-U67V476Y.js";
|
|
5
|
+
|
|
6
|
+
// src/search/client.ts
|
|
7
|
+
import { useRef, useState as useState2 } from "react";
|
|
8
|
+
|
|
9
|
+
// src/utils/use-debounce.ts
|
|
10
|
+
import { useEffect, useState } from "react";
|
|
11
|
+
function useDebounce(value, delayMs = 1e3) {
|
|
12
|
+
const [debouncedValue, setDebouncedValue] = useState(value);
|
|
13
|
+
useEffect(() => {
|
|
14
|
+
if (delayMs === 0) return;
|
|
15
|
+
const handler = window.setTimeout(() => {
|
|
16
|
+
setDebouncedValue(value);
|
|
17
|
+
}, delayMs);
|
|
18
|
+
return () => clearTimeout(handler);
|
|
19
|
+
}, [delayMs, value]);
|
|
20
|
+
if (delayMs === 0) return value;
|
|
21
|
+
return debouncedValue;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// src/search/client.ts
|
|
25
|
+
function isDeepEqual(a, b) {
|
|
26
|
+
if (a === b) return true;
|
|
27
|
+
if (Array.isArray(a) && Array.isArray(b)) {
|
|
28
|
+
return b.length === a.length && a.every((v, i) => isDeepEqual(v, b[i]));
|
|
29
|
+
}
|
|
30
|
+
if (typeof a === "object" && a && typeof b === "object" && b) {
|
|
31
|
+
const aKeys = Object.keys(a);
|
|
32
|
+
const bKeys = Object.keys(b);
|
|
33
|
+
return aKeys.length === bKeys.length && aKeys.every(
|
|
34
|
+
(key) => Object.hasOwn(b, key) && isDeepEqual(a[key], b[key])
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
function useDocsSearch(clientOptions, deps) {
|
|
40
|
+
const { delayMs = 100, allowEmpty = false, ...client } = clientOptions;
|
|
41
|
+
const [search, setSearch] = useState2("");
|
|
42
|
+
const [results, setResults] = useState2("empty");
|
|
43
|
+
const [error, setError] = useState2();
|
|
44
|
+
const [isLoading, setIsLoading] = useState2(false);
|
|
45
|
+
const debouncedValue = useDebounce(search, delayMs);
|
|
46
|
+
const onStart = useRef(void 0);
|
|
47
|
+
useOnChange(
|
|
48
|
+
[deps ?? clientOptions, debouncedValue],
|
|
49
|
+
() => {
|
|
50
|
+
if (onStart.current) {
|
|
51
|
+
onStart.current();
|
|
52
|
+
onStart.current = void 0;
|
|
53
|
+
}
|
|
54
|
+
setIsLoading(true);
|
|
55
|
+
let interrupt = false;
|
|
56
|
+
onStart.current = () => {
|
|
57
|
+
interrupt = true;
|
|
58
|
+
};
|
|
59
|
+
async function run() {
|
|
60
|
+
if (debouncedValue.length === 0 && !allowEmpty) return "empty";
|
|
61
|
+
if (client.type === "fetch") {
|
|
62
|
+
const { fetchDocs } = await import("../fetch-IBTWQCJR.js");
|
|
63
|
+
return fetchDocs(debouncedValue, client);
|
|
64
|
+
}
|
|
65
|
+
if (client.type === "algolia") {
|
|
66
|
+
const { searchDocs } = await import("../algolia-IZEDLPHE.js");
|
|
67
|
+
return searchDocs(debouncedValue, client);
|
|
68
|
+
}
|
|
69
|
+
if (client.type === "orama-cloud") {
|
|
70
|
+
const { searchDocs } = await import("../orama-cloud-UZAPMPFV.js");
|
|
71
|
+
return searchDocs(debouncedValue, client);
|
|
72
|
+
}
|
|
73
|
+
if (client.type === "static") {
|
|
74
|
+
const { search: search2 } = await import("../static-A2YJ5TXV.js");
|
|
75
|
+
return search2(debouncedValue, client);
|
|
76
|
+
}
|
|
77
|
+
if (client.type === "mixedbread") {
|
|
78
|
+
const { search: search2 } = await import("../mixedbread-RAHDVXGJ.js");
|
|
79
|
+
return search2(debouncedValue, client);
|
|
80
|
+
}
|
|
81
|
+
throw new Error("unknown search client");
|
|
82
|
+
}
|
|
83
|
+
void run().then((res) => {
|
|
84
|
+
if (interrupt) return;
|
|
85
|
+
setError(void 0);
|
|
86
|
+
setResults(res);
|
|
87
|
+
}).catch((err) => {
|
|
88
|
+
setError(err);
|
|
89
|
+
}).finally(() => {
|
|
90
|
+
setIsLoading(false);
|
|
91
|
+
});
|
|
92
|
+
},
|
|
93
|
+
deps ? void 0 : (a, b) => !isDeepEqual(a, b)
|
|
94
|
+
);
|
|
95
|
+
return { search, setSearch, query: { isLoading, data: results, error } };
|
|
96
|
+
}
|
|
97
|
+
export {
|
|
98
|
+
useDocsSearch
|
|
99
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
|
|
3
|
+
interface SortedResult<Content = string> {
|
|
4
|
+
id: string;
|
|
5
|
+
url: string;
|
|
6
|
+
type: 'page' | 'heading' | 'text';
|
|
7
|
+
content: Content;
|
|
8
|
+
/**
|
|
9
|
+
* breadcrumbs to be displayed on UI
|
|
10
|
+
*/
|
|
11
|
+
breadcrumbs?: Content[];
|
|
12
|
+
contentWithHighlights?: HighlightedText<Content>[];
|
|
13
|
+
}
|
|
14
|
+
type ReactSortedResult = SortedResult<ReactNode>;
|
|
15
|
+
interface HighlightedText<Content = string> {
|
|
16
|
+
type: 'text';
|
|
17
|
+
content: Content;
|
|
18
|
+
styles?: {
|
|
19
|
+
highlight?: boolean;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
declare function createContentHighlighter(query: string | RegExp): {
|
|
23
|
+
highlight(content: string): HighlightedText[];
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export { type HighlightedText, type ReactSortedResult, type SortedResult, createContentHighlighter };
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { StructuredData } from '../mdx-plugins/remark-structure.js';
|
|
2
|
+
import '../mdx-plugins/remark-heading.js';
|
|
3
|
+
import '../mdx-plugins/remark-code-tab.js';
|
|
4
|
+
import { OramaCloud } from '@orama/core';
|
|
5
|
+
import 'mdast';
|
|
6
|
+
import 'unified';
|
|
7
|
+
import 'mdast-util-mdx-jsx';
|
|
8
|
+
|
|
9
|
+
interface SyncOptions {
|
|
10
|
+
/**
|
|
11
|
+
* Index name to sync
|
|
12
|
+
*/
|
|
13
|
+
index: string;
|
|
14
|
+
documents: OramaDocument[];
|
|
15
|
+
/**
|
|
16
|
+
* Deploy changes
|
|
17
|
+
*
|
|
18
|
+
* @defaultValue true
|
|
19
|
+
*/
|
|
20
|
+
autoDeploy?: boolean;
|
|
21
|
+
}
|
|
22
|
+
type I18nSyncOptions = Omit<SyncOptions, 'index' | 'documents'> & {
|
|
23
|
+
/**
|
|
24
|
+
* Indexes to sync.
|
|
25
|
+
*
|
|
26
|
+
* Pairs of `locale`-`index`.
|
|
27
|
+
**/
|
|
28
|
+
indexes: Record<string, string>;
|
|
29
|
+
documents: {
|
|
30
|
+
locale: string;
|
|
31
|
+
items: OramaDocument[];
|
|
32
|
+
}[];
|
|
33
|
+
};
|
|
34
|
+
interface OramaDocument {
|
|
35
|
+
/**
|
|
36
|
+
* The ID of document, must be unique
|
|
37
|
+
*/
|
|
38
|
+
id: string;
|
|
39
|
+
title: string;
|
|
40
|
+
description?: string;
|
|
41
|
+
/**
|
|
42
|
+
* URL to the page
|
|
43
|
+
*/
|
|
44
|
+
url: string;
|
|
45
|
+
structured: StructuredData;
|
|
46
|
+
/**
|
|
47
|
+
* Tag to filter results
|
|
48
|
+
*/
|
|
49
|
+
tag?: string;
|
|
50
|
+
/**
|
|
51
|
+
* Data to be added to each section index
|
|
52
|
+
*/
|
|
53
|
+
extra_data?: object;
|
|
54
|
+
breadcrumbs?: string[];
|
|
55
|
+
}
|
|
56
|
+
interface OramaIndex {
|
|
57
|
+
id: string;
|
|
58
|
+
title: string;
|
|
59
|
+
url: string;
|
|
60
|
+
tag?: string;
|
|
61
|
+
/**
|
|
62
|
+
* The id of page, used for `group by`
|
|
63
|
+
*/
|
|
64
|
+
page_id: string;
|
|
65
|
+
/**
|
|
66
|
+
* Heading content
|
|
67
|
+
*/
|
|
68
|
+
section?: string;
|
|
69
|
+
breadcrumbs?: string[];
|
|
70
|
+
/**
|
|
71
|
+
* Heading (anchor) id
|
|
72
|
+
*/
|
|
73
|
+
section_id?: string;
|
|
74
|
+
content: string;
|
|
75
|
+
}
|
|
76
|
+
declare function sync(orama: OramaCloud, options: SyncOptions): Promise<void>;
|
|
77
|
+
declare function syncI18n(orama: OramaCloud, options: I18nSyncOptions): Promise<void>;
|
|
78
|
+
|
|
79
|
+
export { type I18nSyncOptions, type OramaDocument, type OramaIndex, type SyncOptions, sync, syncI18n };
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import "../chunk-U67V476Y.js";
|
|
2
|
+
|
|
3
|
+
// src/search/orama-cloud.ts
|
|
4
|
+
async function sync(orama, options) {
|
|
5
|
+
const { autoDeploy = true } = options;
|
|
6
|
+
const index = orama.index.set(options.index);
|
|
7
|
+
await index.transaction.open();
|
|
8
|
+
await index.transaction.insertDocuments(
|
|
9
|
+
options.documents.flatMap(toIndex)
|
|
10
|
+
);
|
|
11
|
+
if (autoDeploy) await index.transaction.commit();
|
|
12
|
+
}
|
|
13
|
+
async function syncI18n(orama, options) {
|
|
14
|
+
const { autoDeploy = true, indexes } = options;
|
|
15
|
+
const tasks = options.documents.map(async (document) => {
|
|
16
|
+
const index = orama.index.set(indexes[document.locale]);
|
|
17
|
+
await index.transaction.open();
|
|
18
|
+
await index.transaction.insertDocuments(
|
|
19
|
+
document.items.flatMap(toIndex)
|
|
20
|
+
);
|
|
21
|
+
if (autoDeploy) await index.transaction.commit();
|
|
22
|
+
});
|
|
23
|
+
await Promise.all(tasks);
|
|
24
|
+
}
|
|
25
|
+
function toIndex(page) {
|
|
26
|
+
let id = 0;
|
|
27
|
+
const indexes = [];
|
|
28
|
+
const scannedHeadings = /* @__PURE__ */ new Set();
|
|
29
|
+
function createIndex(section, sectionId, content) {
|
|
30
|
+
return {
|
|
31
|
+
id: `${page.id}-${(id++).toString()}`,
|
|
32
|
+
title: page.title,
|
|
33
|
+
url: page.url,
|
|
34
|
+
// TODO: explicit declare enums
|
|
35
|
+
page_id: page.id,
|
|
36
|
+
tag: page.tag,
|
|
37
|
+
section,
|
|
38
|
+
section_id: sectionId,
|
|
39
|
+
content,
|
|
40
|
+
breadcrumbs: page.breadcrumbs,
|
|
41
|
+
...page.extra_data
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
if (page.description)
|
|
45
|
+
indexes.push(createIndex(void 0, void 0, page.description));
|
|
46
|
+
page.structured.contents.forEach((p) => {
|
|
47
|
+
const heading = p.heading ? page.structured.headings.find((h) => p.heading === h.id) : null;
|
|
48
|
+
const index = createIndex(heading?.content, heading?.id, p.content);
|
|
49
|
+
if (heading && !scannedHeadings.has(heading.id)) {
|
|
50
|
+
scannedHeadings.add(heading.id);
|
|
51
|
+
indexes.push(createIndex(heading.content, heading.id, heading.content));
|
|
52
|
+
}
|
|
53
|
+
indexes.push(index);
|
|
54
|
+
});
|
|
55
|
+
return indexes;
|
|
56
|
+
}
|
|
57
|
+
export {
|
|
58
|
+
sync,
|
|
59
|
+
syncI18n
|
|
60
|
+
};
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { TypedDocument, Orama, Language, RawData, create, SearchParams } from '@orama/orama';
|
|
2
|
+
import { StructuredData } from '../mdx-plugins/remark-structure.js';
|
|
3
|
+
import { SortedResult } from './index.js';
|
|
4
|
+
export { HighlightedText, ReactSortedResult, createContentHighlighter } from './index.js';
|
|
5
|
+
import { I18nConfig } from '../i18n/index.js';
|
|
6
|
+
import { f as LoaderOutput, b as LoaderConfig, I as InferPageType } from '../loader-BvlPPJX0.js';
|
|
7
|
+
import 'mdast';
|
|
8
|
+
import 'unified';
|
|
9
|
+
import 'mdast-util-mdx-jsx';
|
|
10
|
+
import 'react';
|
|
11
|
+
import '../definitions-pJ7PybYY.js';
|
|
12
|
+
|
|
13
|
+
type SimpleDocument = TypedDocument<Orama<typeof simpleSchema>>;
|
|
14
|
+
declare const simpleSchema: {
|
|
15
|
+
readonly url: "string";
|
|
16
|
+
readonly title: "string";
|
|
17
|
+
readonly breadcrumbs: "string[]";
|
|
18
|
+
readonly description: "string";
|
|
19
|
+
readonly content: "string";
|
|
20
|
+
readonly keywords: "string";
|
|
21
|
+
};
|
|
22
|
+
type AdvancedDocument = TypedDocument<Orama<typeof advancedSchema>>;
|
|
23
|
+
declare const advancedSchema: {
|
|
24
|
+
readonly content: "string";
|
|
25
|
+
readonly page_id: "string";
|
|
26
|
+
readonly type: "string";
|
|
27
|
+
readonly breadcrumbs: "string[]";
|
|
28
|
+
readonly tags: "enum[]";
|
|
29
|
+
readonly url: "string";
|
|
30
|
+
readonly embeddings: "vector[512]";
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
type Awaitable<T> = T | Promise<T>;
|
|
34
|
+
interface Options<S extends LoaderOutput<LoaderConfig>> extends Omit<AdvancedOptions, 'indexes'> {
|
|
35
|
+
localeMap?: {
|
|
36
|
+
[K in S extends LoaderOutput<infer C> ? C['i18n'] extends I18nConfig<infer Languages> ? Languages : string : string]?: Partial<AdvancedOptions> | Language;
|
|
37
|
+
};
|
|
38
|
+
buildIndex?: (page: InferPageType<S>) => Awaitable<AdvancedIndex>;
|
|
39
|
+
}
|
|
40
|
+
declare function createFromSource<S extends LoaderOutput<LoaderConfig>>(source: S, options?: Options<S>): SearchAPI;
|
|
41
|
+
|
|
42
|
+
type I18nOptions<O extends SimpleOptions | AdvancedOptions, Idx> = Omit<O, 'language' | 'indexes'> & {
|
|
43
|
+
i18n: I18nConfig;
|
|
44
|
+
/**
|
|
45
|
+
* Map locale name from i18n config to Orama compatible `language` or options
|
|
46
|
+
*/
|
|
47
|
+
localeMap?: Record<string, Language | Partial<O> | undefined>;
|
|
48
|
+
indexes: WithLocale<Idx>[] | Dynamic<WithLocale<Idx>>;
|
|
49
|
+
};
|
|
50
|
+
type I18nSimpleOptions = I18nOptions<SimpleOptions, Index>;
|
|
51
|
+
type I18nAdvancedOptions = I18nOptions<AdvancedOptions, AdvancedIndex>;
|
|
52
|
+
type WithLocale<T> = T & {
|
|
53
|
+
locale: string;
|
|
54
|
+
};
|
|
55
|
+
declare function createI18nSearchAPI<T extends 'simple' | 'advanced'>(type: T, options: T extends 'simple' ? I18nSimpleOptions : I18nAdvancedOptions): SearchAPI;
|
|
56
|
+
|
|
57
|
+
type SearchType = 'simple' | 'advanced';
|
|
58
|
+
type ExportedData = (RawData & {
|
|
59
|
+
type: SearchType;
|
|
60
|
+
}) | {
|
|
61
|
+
type: 'i18n';
|
|
62
|
+
data: Record<string, RawData & {
|
|
63
|
+
type: SearchType;
|
|
64
|
+
}>;
|
|
65
|
+
};
|
|
66
|
+
interface SearchServer {
|
|
67
|
+
search: (query: string, options?: {
|
|
68
|
+
locale?: string;
|
|
69
|
+
tag?: string | string[];
|
|
70
|
+
mode?: 'vector' | 'full';
|
|
71
|
+
}) => Promise<SortedResult[]>;
|
|
72
|
+
/**
|
|
73
|
+
* Export the database
|
|
74
|
+
*
|
|
75
|
+
* You can reference the exported database to implement client-side search
|
|
76
|
+
*/
|
|
77
|
+
export: () => Promise<ExportedData>;
|
|
78
|
+
}
|
|
79
|
+
interface SearchAPI extends SearchServer {
|
|
80
|
+
GET: (request: Request) => Promise<Response>;
|
|
81
|
+
/**
|
|
82
|
+
* `GET` route handler that exports search indexes for static search.
|
|
83
|
+
*/
|
|
84
|
+
staticGET: () => Promise<Response>;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Resolve indexes dynamically
|
|
88
|
+
*/
|
|
89
|
+
type Dynamic<T> = () => T[] | Promise<T[]>;
|
|
90
|
+
type OramaInput = Parameters<typeof create>[0];
|
|
91
|
+
type SharedOptions = Pick<OramaInput, 'sort' | 'components' | 'plugins'> & {
|
|
92
|
+
language?: string;
|
|
93
|
+
tokenizer?: Required<OramaInput>['components']['tokenizer'];
|
|
94
|
+
};
|
|
95
|
+
interface SimpleOptions extends SharedOptions {
|
|
96
|
+
indexes: Index[] | Dynamic<Index>;
|
|
97
|
+
/**
|
|
98
|
+
* Customise search options on server
|
|
99
|
+
*/
|
|
100
|
+
search?: Partial<SearchParams<Orama<typeof simpleSchema>, SimpleDocument>>;
|
|
101
|
+
}
|
|
102
|
+
interface AdvancedOptions extends SharedOptions {
|
|
103
|
+
indexes: AdvancedIndex[] | Dynamic<AdvancedIndex>;
|
|
104
|
+
/**
|
|
105
|
+
* Customise search options on server
|
|
106
|
+
*/
|
|
107
|
+
search?: Partial<SearchParams<Orama<typeof advancedSchema>, AdvancedDocument>>;
|
|
108
|
+
}
|
|
109
|
+
declare function createSearchAPI<T extends SearchType>(type: T, options: T extends 'simple' ? SimpleOptions : AdvancedOptions): SearchAPI;
|
|
110
|
+
interface Index {
|
|
111
|
+
title: string;
|
|
112
|
+
description?: string;
|
|
113
|
+
breadcrumbs?: string[];
|
|
114
|
+
content: string;
|
|
115
|
+
url: string;
|
|
116
|
+
keywords?: string;
|
|
117
|
+
}
|
|
118
|
+
declare function initSimpleSearch(options: SimpleOptions): SearchServer;
|
|
119
|
+
interface AdvancedIndex {
|
|
120
|
+
id: string;
|
|
121
|
+
title: string;
|
|
122
|
+
description?: string;
|
|
123
|
+
breadcrumbs?: string[];
|
|
124
|
+
/**
|
|
125
|
+
* Required if tag filter is enabled
|
|
126
|
+
*/
|
|
127
|
+
tag?: string | string[];
|
|
128
|
+
/**
|
|
129
|
+
* preprocess mdx content with `structure`
|
|
130
|
+
*/
|
|
131
|
+
structuredData: StructuredData;
|
|
132
|
+
url: string;
|
|
133
|
+
}
|
|
134
|
+
declare function initAdvancedSearch(options: AdvancedOptions): SearchServer;
|
|
135
|
+
|
|
136
|
+
export { type AdvancedIndex, type AdvancedOptions, type Dynamic, type ExportedData, type Index, type SearchAPI, type SearchServer, type SimpleOptions, SortedResult, createFromSource, createI18nSearchAPI, createSearchAPI, initAdvancedSearch, initSimpleSearch };
|