boltdocs 3.3.4 → 3.3.6
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/dist/{build-COgv-rkY.mjs → build-BJnL-FHG.mjs} +1 -1
- package/dist/{build-1CsvBIsN.cjs → build-CxT38vPv.cjs} +1 -1
- package/dist/client/index.cjs +80 -32
- package/dist/client/index.d.cts +1 -1
- package/dist/client/index.d.ts +1 -1
- package/dist/client/index.js +78 -31
- package/dist/client/mdx.cjs +1 -1
- package/dist/client/mdx.js +1 -1
- package/dist/client/primitives.cjs +4 -4
- package/dist/client/primitives.d.cts +40 -9
- package/dist/client/primitives.d.ts +40 -9
- package/dist/client/primitives.js +4 -4
- package/dist/config-B3_iVsbi.mjs +7 -0
- package/dist/{config-PLvresCv.cjs → config-BC_qhXws.cjs} +1 -1
- package/dist/config-BJp3lGzE.cjs +7 -0
- package/dist/{dev-C_9iBwmu.cjs → dev-46NiL0MC.cjs} +1 -1
- package/dist/{dev-UWVM3ah-.mjs → dev-C4kjO5xs.mjs} +1 -1
- package/dist/{docs-layout-CbZ7LDRe.js → docs-layout-D3Fmb0Wd.js} +16 -117
- package/dist/{docs-layout-vzfXed1Q.cjs → docs-layout-SgphExoE.cjs} +16 -123
- package/dist/{doctor-DMECtdK6.cjs → doctor-BqxOFRt3.cjs} +1 -1
- package/dist/{doctor-i8Qmd8DJ.mjs → doctor-Cv5lXnay.mjs} +1 -1
- package/dist/{doctor-FuFY1jBz.cjs → doctor-TS3JGNEU.cjs} +1 -1
- package/dist/{image-B-NDSDuY.js → image-BAiDReNd.js} +1 -1
- package/dist/{image-Hnaa2bJd.cjs → image-Bkx85rsq.cjs} +1 -1
- package/dist/{index-Cg3TmXIZ.d.ts → index-B1Mx0dHl.d.ts} +30 -6
- package/dist/{index-CSiMUBhC.d.cts → index-DLaHgD-i.d.cts} +30 -6
- package/dist/{link-vZjmD-es.cjs → link-hLWOsx0x.cjs} +59 -28
- package/dist/{link-CgdI6O2o.js → link-q1qHNGK_.js} +54 -29
- package/dist/{mdx-BRT71V5Q.js → mdx-CJGWzBGy.js} +2 -2
- package/dist/{mdx-D0Absdq5.cjs → mdx-Qi0DmaY8.cjs} +2 -2
- package/dist/node/cli-entry.cjs +1 -1
- package/dist/node/cli-entry.mjs +1 -1
- package/dist/node/highlight.d.cts +2 -2
- package/dist/node/highlight.d.mts +2 -2
- package/dist/node/index.cjs +1 -1
- package/dist/node/index.d.cts +7 -4
- package/dist/node/index.d.mts +7 -4
- package/dist/node/index.mjs +1 -1
- package/dist/node/mdx/shiki-adapter.cjs +1 -1
- package/dist/node/mdx/shiki-adapter.d.cts +7 -2
- package/dist/node/mdx/shiki-adapter.d.mts +7 -2
- package/dist/node/mdx/shiki-adapter.mjs +1 -1
- package/dist/node-7Cfw6nMr.cjs +23 -0
- package/dist/node-CT2E84nY.mjs +23 -0
- package/dist/{package-Cwma8oO7.cjs → package-Bah2tHjK.cjs} +1 -1
- package/dist/{package-CKC-4LtU.mjs → package-D6bf68FR.mjs} +1 -1
- package/dist/plugin-AgNI3ktz.cjs +69 -0
- package/dist/plugin-BAv_pYLt.mjs +69 -0
- package/dist/{plugin-context-BxF88sW4.cjs → plugin-context-BZs5lvDu.cjs} +3 -3
- package/dist/{plugin-context-BKK-nfOd.mjs → plugin-context-b5qVVQSU.mjs} +2 -2
- package/dist/{plugin-lifecycle-BjMclfc3.cjs → plugin-lifecycle-s89gzTlh.cjs} +1 -1
- package/dist/{registry-BbB6NqSv.d.cts → registry-B8pt41zj.d.cts} +1 -1
- package/dist/{registry-sJqDv0kE.d.mts → registry-BrrH2X9c.d.mts} +1 -1
- package/dist/routes-CzhKOw67.cjs +6 -0
- package/dist/{routes-C3_w9fLX.cjs → routes-Dq_2EUIB.cjs} +1 -1
- package/dist/routes-Dw6g0bfF.mjs +6 -0
- package/dist/search-dialog-BYZS9aeO.cjs +747 -0
- package/dist/{search-dialog-x_qHU8ty.cjs → search-dialog-CguKVtUu.cjs} +145 -5
- package/dist/{search-dialog-MmwxFMmE.js → search-dialog-DQwod5Xc.js} +1 -1
- package/dist/search-dialog-DzObE-Ar.js +717 -0
- package/dist/{search-dialog-DmirOMPg.cjs → search-dialog-QgKRRbsI.cjs} +1 -1
- package/dist/{search-dialog-BqkzDTq2.js → search-dialog-mYnqU4v7.js} +134 -6
- package/dist/{types-Db6zToZH.d.mts → types-74i_xUe2.d.mts} +1 -1
- package/dist/{types-o7iZ2BAR.d.cts → types-X_Pwk8Cg.d.cts} +1 -1
- package/dist/virtual-modules-C3S3Nz8r.cjs +40 -0
- package/dist/virtual-modules-CaxqrFd6.mjs +40 -0
- package/package.json +4 -3
- package/dist/config-CrsQJHQz.cjs +0 -7
- package/dist/config-DC0nMMk7.mjs +0 -7
- package/dist/node-C3HctGaH.cjs +0 -23
- package/dist/node-CUiheODn.mjs +0 -23
- package/dist/plugin-BX6TXR8x.cjs +0 -69
- package/dist/plugin-C8UMIA-4.mjs +0 -69
- package/dist/routes-C0kb4ue6.cjs +0 -6
- package/dist/routes-C4wrLWwu.mjs +0 -6
- package/dist/search-dialog-D3jtaw6w.cjs +0 -525
- package/dist/search-dialog-DRiXejws.js +0 -501
- package/dist/virtual-modules-XBiJoTsp.mjs +0 -39
- package/dist/virtual-modules-hndVivLR.cjs +0 -39
|
@@ -1,525 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Boltdocs - https://boltdocs.vercel.app
|
|
3
|
-
* Copyright (c) 2026 Jesus Alcala
|
|
4
|
-
* Licensed under the MIT License.
|
|
5
|
-
*/
|
|
6
|
-
const require_router = require('./router-C3kygdRK.cjs');
|
|
7
|
-
const require_link = require('./link-vZjmD-es.cjs');
|
|
8
|
-
const require_search_dialog = require('./search-dialog-x_qHU8ty.cjs');
|
|
9
|
-
let react = require("react");
|
|
10
|
-
let react_jsx_runtime = require("react/jsx-runtime");
|
|
11
|
-
let flexsearch = require("flexsearch");
|
|
12
|
-
let virtual_boltdocs_search = require("virtual:boltdocs-search");
|
|
13
|
-
virtual_boltdocs_search = require_router.__toESM(virtual_boltdocs_search);
|
|
14
|
-
|
|
15
|
-
//#region src/client/hooks/use-routes.ts
|
|
16
|
-
/**
|
|
17
|
-
* Hook to access the framework's routing state.
|
|
18
|
-
* Returns both the complete set of routes and a filtered list based on the current
|
|
19
|
-
* version and locale.
|
|
20
|
-
*/
|
|
21
|
-
function useRoutes() {
|
|
22
|
-
const routeContext = require_link.useRoutesContext();
|
|
23
|
-
const allRoutes = routeContext.routes;
|
|
24
|
-
const routeIndex = routeContext.index || {
|
|
25
|
-
byPath: new Map(allRoutes.map((route) => [require_link.normalizePath(route.path), route])),
|
|
26
|
-
hintsByPath: /* @__PURE__ */ new Map(),
|
|
27
|
-
collectionNames: []
|
|
28
|
-
};
|
|
29
|
-
const config = require_link.useConfig();
|
|
30
|
-
const location = require_router.useLocation();
|
|
31
|
-
const { pathname } = location;
|
|
32
|
-
const { currentLocale: currentLocaleStore, currentVersion: currentVersionStore } = require_link.useBoltdocsContext();
|
|
33
|
-
const currentPath = require_link.normalizePath(pathname);
|
|
34
|
-
const currentRoute = routeIndex.byPath.get(currentPath);
|
|
35
|
-
const pathParts = pathname.split("/").filter(Boolean);
|
|
36
|
-
const urlLocale = config.i18n ? pathParts.find((part) => Array.isArray(config.i18n?.locales) ? config.i18n?.locales.includes(part) : part in (config.i18n?.locales || {})) : void 0;
|
|
37
|
-
const currentLocale = config.i18n ? urlLocale || currentLocaleStore || config.i18n.defaultLocale : void 0;
|
|
38
|
-
const configuredVersions = config.versions?.versions || [];
|
|
39
|
-
const currentVersion = config.versions ? configuredVersions.some((version) => version.path === currentVersionStore) ? currentVersionStore : config.versions.defaultVersion : void 0;
|
|
40
|
-
const routes = (0, react.useMemo)(() => {
|
|
41
|
-
if (!allRoutes) return [];
|
|
42
|
-
const alternateCounts = /* @__PURE__ */ new Map();
|
|
43
|
-
const defaultLocale = config.i18n?.defaultLocale || "";
|
|
44
|
-
const defaultVersion = config.versions?.defaultVersion || "";
|
|
45
|
-
for (const r of allRoutes) {
|
|
46
|
-
const locale = r.locale || defaultLocale;
|
|
47
|
-
const version = r.version || defaultVersion;
|
|
48
|
-
const key = `${r.filePath}::${locale}::${version}`;
|
|
49
|
-
alternateCounts.set(key, (alternateCounts.get(key) || 0) + 1);
|
|
50
|
-
}
|
|
51
|
-
return allRoutes.filter((r) => {
|
|
52
|
-
const localeMatch = config.i18n ? (r.locale || config.i18n.defaultLocale) === currentLocale : true;
|
|
53
|
-
const versionMatch = config.versions ? (r.version || config.versions.defaultVersion) === currentVersion : true;
|
|
54
|
-
if (!(localeMatch && versionMatch)) return false;
|
|
55
|
-
const pathParts = pathname.split("/").filter(Boolean);
|
|
56
|
-
const isCurrentLocalePrefixed = !!(config.i18n && pathParts.includes(currentLocaleStore || config.i18n.defaultLocale));
|
|
57
|
-
const isCurrentVersionPrefixed = !!(config.versions && !!currentVersion && pathParts.includes(currentVersion));
|
|
58
|
-
const isRouteLocalePrefixed = !!r.locale;
|
|
59
|
-
const isRouteVersionPrefixed = !!r.version;
|
|
60
|
-
const locale = r.locale || defaultLocale;
|
|
61
|
-
const version = r.version || defaultVersion;
|
|
62
|
-
const key = `${r.filePath}::${locale}::${version}`;
|
|
63
|
-
if ((alternateCounts.get(key) || 0) > 1) {
|
|
64
|
-
const localeMismatch = config.i18n && isCurrentLocalePrefixed !== isRouteLocalePrefixed;
|
|
65
|
-
const versionMismatch = config.versions && isCurrentVersionPrefixed !== isRouteVersionPrefixed;
|
|
66
|
-
if (localeMismatch || versionMismatch) return false;
|
|
67
|
-
}
|
|
68
|
-
return true;
|
|
69
|
-
});
|
|
70
|
-
}, [
|
|
71
|
-
allRoutes,
|
|
72
|
-
config,
|
|
73
|
-
pathname,
|
|
74
|
-
currentLocale,
|
|
75
|
-
currentVersion,
|
|
76
|
-
currentLocaleStore
|
|
77
|
-
]);
|
|
78
|
-
const collections = (0, react.useMemo)(() => new Set(routeIndex.collectionNames), [routeIndex.collectionNames]);
|
|
79
|
-
return {
|
|
80
|
-
routes,
|
|
81
|
-
allRoutes,
|
|
82
|
-
currentRoute,
|
|
83
|
-
isCollectionPage: !!currentRoute?.collection || location.pathname.split("/").filter(Boolean).some((segment) => collections.has(segment.toLowerCase())),
|
|
84
|
-
currentLocale,
|
|
85
|
-
currentVersion
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
//#endregion
|
|
90
|
-
//#region src/client/components/internal/error-boundary.tsx
|
|
91
|
-
function InternalFallback({ error, resetErrorBoundary, className }) {
|
|
92
|
-
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
93
|
-
role: "alert",
|
|
94
|
-
className: require_link.cn("p-2 font-mono flex flex-col items-center justify-between min-h-[30vh]", className),
|
|
95
|
-
children: [
|
|
96
|
-
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
97
|
-
className: "text-lg font-semibold text-danger-500",
|
|
98
|
-
children: "Something went wrong"
|
|
99
|
-
}),
|
|
100
|
-
error?.message && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("pre", {
|
|
101
|
-
className: "text-sm mt-2 max-w-md overflow-auto whitespace-pre-wrap break-word",
|
|
102
|
-
children: error.message
|
|
103
|
-
}),
|
|
104
|
-
error?.stack && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("details", {
|
|
105
|
-
className: "mt-2 max-w-md text-left text-xs",
|
|
106
|
-
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("summary", {
|
|
107
|
-
className: "cursor-pointer text-muted select-none outline-none",
|
|
108
|
-
children: "Error details"
|
|
109
|
-
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("pre", {
|
|
110
|
-
className: "mt-2 p-2 bg-soft rounded border-subtle border overflow-auto max-h-48 whitespace-pre-wrap break-words",
|
|
111
|
-
children: error.stack
|
|
112
|
-
})]
|
|
113
|
-
}),
|
|
114
|
-
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
115
|
-
className: "flex items-center gap-2 mt-2",
|
|
116
|
-
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
117
|
-
type: "button",
|
|
118
|
-
onClick: resetErrorBoundary,
|
|
119
|
-
className: "px-2 py-3 bg-soft rounded border-subtle border font-mono font-semibold text-body hover:scale-105 transition-transform active:scale-95 cursor-pointer",
|
|
120
|
-
children: "Try again"
|
|
121
|
-
}), typeof window !== "undefined" && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
122
|
-
type: "button",
|
|
123
|
-
onClick: () => window.location.reload(),
|
|
124
|
-
className: "px-2 py-3 rounded font-mono font-semibold text-muted hover:text-body transition-colors cursor-pointer",
|
|
125
|
-
children: "Reload page"
|
|
126
|
-
})]
|
|
127
|
-
})
|
|
128
|
-
]
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
function InternalErrorBoundary({ children, fallback, resetKeys }) {
|
|
132
|
-
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_search_dialog.ErrorBoundary, {
|
|
133
|
-
fallback,
|
|
134
|
-
resetKeys,
|
|
135
|
-
FallbackComponent: !fallback ? InternalFallback : void 0,
|
|
136
|
-
children
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
//#endregion
|
|
141
|
-
//#region src/client/hooks/use-search.ts
|
|
142
|
-
function useSearch(routes) {
|
|
143
|
-
const { currentLocale, currentVersion } = useRoutes();
|
|
144
|
-
const config = require_link.useConfig();
|
|
145
|
-
const algoliaConfig = config.integrations?.search?.algolia;
|
|
146
|
-
const [isOpen, setIsOpen] = (0, react.useState)(false);
|
|
147
|
-
const [query, setQuery] = (0, react.useState)("");
|
|
148
|
-
const [index, setIndex] = (0, react.useState)(null);
|
|
149
|
-
const [algoliaResults, setAlgoliaResults] = (0, react.useState)([]);
|
|
150
|
-
const [searchData, setSearchData] = (0, react.useState)([]);
|
|
151
|
-
const [searchDataLoading, setSearchDataLoading] = (0, react.useState)(false);
|
|
152
|
-
const [searchDataError, setSearchDataError] = (0, react.useState)(null);
|
|
153
|
-
const searchGeneration = (0, react.useRef)(0);
|
|
154
|
-
const loadingGeneration = (0, react.useRef)(null);
|
|
155
|
-
const navigate = require_router.useNavigate();
|
|
156
|
-
(0, react.useEffect)(() => {
|
|
157
|
-
if (algoliaConfig || !isOpen) return;
|
|
158
|
-
if (searchData.length > 0) return;
|
|
159
|
-
setSearchDataLoading(true);
|
|
160
|
-
setSearchDataError(null);
|
|
161
|
-
let active = true;
|
|
162
|
-
const generation = ++searchGeneration.current;
|
|
163
|
-
loadingGeneration.current = generation;
|
|
164
|
-
(0, virtual_boltdocs_search.default)().then((data) => {
|
|
165
|
-
if (!active || generation !== searchGeneration.current) return;
|
|
166
|
-
setSearchData(data || []);
|
|
167
|
-
if (loadingGeneration.current === generation) {
|
|
168
|
-
loadingGeneration.current = null;
|
|
169
|
-
setSearchDataLoading(false);
|
|
170
|
-
}
|
|
171
|
-
}).catch((err) => {
|
|
172
|
-
if (!active || generation !== searchGeneration.current) return;
|
|
173
|
-
console.error("[boltdocs] Failed to load search index:", err);
|
|
174
|
-
setSearchDataError(err);
|
|
175
|
-
if (loadingGeneration.current === generation) {
|
|
176
|
-
loadingGeneration.current = null;
|
|
177
|
-
setSearchDataLoading(false);
|
|
178
|
-
}
|
|
179
|
-
});
|
|
180
|
-
return () => {
|
|
181
|
-
active = false;
|
|
182
|
-
};
|
|
183
|
-
}, [
|
|
184
|
-
isOpen,
|
|
185
|
-
algoliaConfig,
|
|
186
|
-
searchData.length
|
|
187
|
-
]);
|
|
188
|
-
(0, react.useEffect)(() => {
|
|
189
|
-
if (!{}.hot) return;
|
|
190
|
-
const applyFrontmatterDelta = (payload) => {
|
|
191
|
-
const updated = payload.search?.updated ?? [];
|
|
192
|
-
const deleted = new Set(payload.search?.deleted ?? []);
|
|
193
|
-
searchGeneration.current += 1;
|
|
194
|
-
if (loadingGeneration.current !== null) {
|
|
195
|
-
loadingGeneration.current = null;
|
|
196
|
-
setSearchDataLoading(false);
|
|
197
|
-
}
|
|
198
|
-
setSearchData((prev) => {
|
|
199
|
-
const map = new Map(prev.map((d) => [d.id, d]));
|
|
200
|
-
for (const doc of updated) map.set(doc.id, doc);
|
|
201
|
-
for (const id of deleted) map.delete(id);
|
|
202
|
-
return Array.from(map.values());
|
|
203
|
-
});
|
|
204
|
-
setIndex(null);
|
|
205
|
-
};
|
|
206
|
-
const refreshFromAsset = async () => {
|
|
207
|
-
const generation = ++searchGeneration.current;
|
|
208
|
-
loadingGeneration.current = generation;
|
|
209
|
-
setSearchDataLoading(true);
|
|
210
|
-
try {
|
|
211
|
-
const data = await (0, virtual_boltdocs_search.default)({ bustCache: true });
|
|
212
|
-
if (generation !== searchGeneration.current) return;
|
|
213
|
-
setSearchData(data || []);
|
|
214
|
-
setSearchDataError(null);
|
|
215
|
-
setIndex(null);
|
|
216
|
-
} catch (error) {
|
|
217
|
-
if (generation !== searchGeneration.current) return;
|
|
218
|
-
console.error("[boltdocs] Failed to refresh search index:", error);
|
|
219
|
-
setSearchDataError(error instanceof Error ? error : new Error(String(error)));
|
|
220
|
-
} finally {
|
|
221
|
-
if (generation === searchGeneration.current) {
|
|
222
|
-
loadingGeneration.current = null;
|
|
223
|
-
setSearchDataLoading(false);
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
};
|
|
227
|
-
const hot = {}.hot;
|
|
228
|
-
hot.on("boltdocs:frontmatter-update", applyFrontmatterDelta);
|
|
229
|
-
hot.on("boltdocs:mdx-update", refreshFromAsset);
|
|
230
|
-
return () => {
|
|
231
|
-
hot.off?.("boltdocs:frontmatter-update", applyFrontmatterDelta);
|
|
232
|
-
hot.off?.("boltdocs:mdx-update", refreshFromAsset);
|
|
233
|
-
};
|
|
234
|
-
}, []);
|
|
235
|
-
(0, react.useEffect)(() => {
|
|
236
|
-
const handleKeyDown = (e) => {
|
|
237
|
-
if ((/Mac/.test(navigator.userAgent) ? e.metaKey : e.ctrlKey) && (e.key === "k" || e.key === "j")) {
|
|
238
|
-
e.preventDefault();
|
|
239
|
-
setIsOpen((prev) => !prev);
|
|
240
|
-
}
|
|
241
|
-
};
|
|
242
|
-
window.addEventListener("keydown", handleKeyDown);
|
|
243
|
-
return () => window.removeEventListener("keydown", handleKeyDown);
|
|
244
|
-
}, []);
|
|
245
|
-
const handleSelect = (0, react.useCallback)((key) => {
|
|
246
|
-
const path = String(key);
|
|
247
|
-
if (!path) return;
|
|
248
|
-
setIsOpen(false);
|
|
249
|
-
const url = new URL(path, window.location.origin);
|
|
250
|
-
if (query) url.searchParams.set("hl", query);
|
|
251
|
-
navigate(`${url.pathname}${url.search}${url.hash}`);
|
|
252
|
-
}, [navigate, query]);
|
|
253
|
-
(0, react.useEffect)(() => {
|
|
254
|
-
if (algoliaConfig) return;
|
|
255
|
-
if (!isOpen || searchData.length === 0 || index) return;
|
|
256
|
-
const newIndex = new flexsearch.Index({
|
|
257
|
-
tokenize: "forward",
|
|
258
|
-
cache: true
|
|
259
|
-
});
|
|
260
|
-
for (let i = 0; i < searchData.length; i++) {
|
|
261
|
-
const doc = searchData[i];
|
|
262
|
-
if (!doc) continue;
|
|
263
|
-
newIndex.add(i, `${doc.title} ${doc.content}`);
|
|
264
|
-
}
|
|
265
|
-
setIndex(newIndex);
|
|
266
|
-
}, [
|
|
267
|
-
isOpen,
|
|
268
|
-
index,
|
|
269
|
-
algoliaConfig,
|
|
270
|
-
searchData
|
|
271
|
-
]);
|
|
272
|
-
(0, react.useEffect)(() => {
|
|
273
|
-
if (!algoliaConfig) return;
|
|
274
|
-
if (!query) {
|
|
275
|
-
setAlgoliaResults([]);
|
|
276
|
-
return;
|
|
277
|
-
}
|
|
278
|
-
const delayDebounceFn = setTimeout(async () => {
|
|
279
|
-
try {
|
|
280
|
-
const url = `https://${algoliaConfig.appId}-dsn.algolia.net/1/indexes/${algoliaConfig.indexName}/query`;
|
|
281
|
-
const facetFilters = [];
|
|
282
|
-
if (currentLocale) facetFilters.push(`lang:${currentLocale}`);
|
|
283
|
-
if (currentVersion) facetFilters.push(`version:${currentVersion}`);
|
|
284
|
-
let params = `query=${encodeURIComponent(query)}&hitsPerPage=20`;
|
|
285
|
-
if (facetFilters.length > 0) params += `&facetFilters=${encodeURIComponent(JSON.stringify(facetFilters))}`;
|
|
286
|
-
const response = await fetch(url, {
|
|
287
|
-
method: "POST",
|
|
288
|
-
headers: {
|
|
289
|
-
"Content-Type": "application/json",
|
|
290
|
-
"X-Algolia-API-Key": algoliaConfig.apiKey,
|
|
291
|
-
"X-Algolia-Application-Id": algoliaConfig.appId
|
|
292
|
-
},
|
|
293
|
-
body: JSON.stringify({ params })
|
|
294
|
-
});
|
|
295
|
-
if (!response.ok) throw new Error(`Algolia search request failed: ${response.statusText}`);
|
|
296
|
-
setAlgoliaResults(((await response.json()).hits || []).map((hit) => {
|
|
297
|
-
let path = hit.url || "";
|
|
298
|
-
try {
|
|
299
|
-
if (path.startsWith("http://") || path.startsWith("https://")) {
|
|
300
|
-
const urlObj = new URL(path);
|
|
301
|
-
path = urlObj.pathname + urlObj.search + urlObj.hash;
|
|
302
|
-
}
|
|
303
|
-
} catch {}
|
|
304
|
-
const hierarchy = hit.hierarchy || {};
|
|
305
|
-
const levels = [
|
|
306
|
-
hierarchy.lvl0,
|
|
307
|
-
hierarchy.lvl1,
|
|
308
|
-
hierarchy.lvl2,
|
|
309
|
-
hierarchy.lvl3,
|
|
310
|
-
hierarchy.lvl4,
|
|
311
|
-
hierarchy.lvl5,
|
|
312
|
-
hierarchy.lvl6
|
|
313
|
-
].filter(Boolean);
|
|
314
|
-
const title = levels[levels.length - 1] || "Documentation";
|
|
315
|
-
const bio = levels.join(" > ");
|
|
316
|
-
return {
|
|
317
|
-
id: hit.objectID || path,
|
|
318
|
-
title,
|
|
319
|
-
path,
|
|
320
|
-
bio,
|
|
321
|
-
groupTitle: hierarchy.lvl0 || "Docs",
|
|
322
|
-
isHeading: !!hit.anchor || path.includes("#")
|
|
323
|
-
};
|
|
324
|
-
}));
|
|
325
|
-
} catch (err) {
|
|
326
|
-
console.error("Error fetching search results from Algolia:", err);
|
|
327
|
-
}
|
|
328
|
-
}, 250);
|
|
329
|
-
return () => clearTimeout(delayDebounceFn);
|
|
330
|
-
}, [
|
|
331
|
-
query,
|
|
332
|
-
algoliaConfig,
|
|
333
|
-
currentLocale,
|
|
334
|
-
currentVersion
|
|
335
|
-
]);
|
|
336
|
-
return {
|
|
337
|
-
isOpen,
|
|
338
|
-
setIsOpen,
|
|
339
|
-
query,
|
|
340
|
-
setQuery,
|
|
341
|
-
list: (0, react.useMemo)(() => {
|
|
342
|
-
if (!query) return routes.filter((r) => {
|
|
343
|
-
const routeLocale = r.locale || config.i18n?.defaultLocale;
|
|
344
|
-
const routeVersion = r.version || config.versions?.defaultVersion;
|
|
345
|
-
return (!currentLocale || routeLocale === currentLocale) && (!currentVersion || routeVersion === currentVersion);
|
|
346
|
-
}).slice(0, 10).map((r) => ({
|
|
347
|
-
id: r.path,
|
|
348
|
-
title: r.title,
|
|
349
|
-
path: r.path,
|
|
350
|
-
bio: r.description || "",
|
|
351
|
-
groupTitle: r.groupTitle
|
|
352
|
-
}));
|
|
353
|
-
if (algoliaConfig) return algoliaResults;
|
|
354
|
-
if (!index) return [];
|
|
355
|
-
const searchResults = index.search(query, {
|
|
356
|
-
limit: 20,
|
|
357
|
-
suggest: true
|
|
358
|
-
});
|
|
359
|
-
const results = [];
|
|
360
|
-
const seen = /* @__PURE__ */ new Set();
|
|
361
|
-
for (const id of searchResults) {
|
|
362
|
-
const doc = searchData[typeof id === "number" ? id : Number(id)];
|
|
363
|
-
if (!doc) continue;
|
|
364
|
-
const docLocale = doc.locale || config.i18n?.defaultLocale;
|
|
365
|
-
const docVersion = doc.version || config.versions?.defaultVersion;
|
|
366
|
-
const localeMatch = !currentLocale || docLocale === currentLocale || !doc.locale && currentLocale === config.i18n?.defaultLocale;
|
|
367
|
-
if (!(!currentVersion || docVersion === currentVersion)) continue;
|
|
368
|
-
if (seen.has(doc.url)) continue;
|
|
369
|
-
seen.add(doc.url);
|
|
370
|
-
results.push({
|
|
371
|
-
id: doc.url,
|
|
372
|
-
title: doc.title,
|
|
373
|
-
path: doc.url,
|
|
374
|
-
bio: doc.display,
|
|
375
|
-
groupTitle: doc.display.split(" > ")[0],
|
|
376
|
-
isHeading: doc.url.includes("#"),
|
|
377
|
-
localeMatch
|
|
378
|
-
});
|
|
379
|
-
}
|
|
380
|
-
return results.filter((result) => result.localeMatch).slice(0, 10);
|
|
381
|
-
}, [
|
|
382
|
-
query,
|
|
383
|
-
index,
|
|
384
|
-
currentLocale,
|
|
385
|
-
currentVersion,
|
|
386
|
-
routes,
|
|
387
|
-
searchData,
|
|
388
|
-
algoliaConfig,
|
|
389
|
-
algoliaResults,
|
|
390
|
-
config
|
|
391
|
-
]),
|
|
392
|
-
searchDataLoading,
|
|
393
|
-
searchDataError,
|
|
394
|
-
handleSelect,
|
|
395
|
-
input: {
|
|
396
|
-
value: query,
|
|
397
|
-
onChange: (e) => setQuery(e.target.value)
|
|
398
|
-
}
|
|
399
|
-
};
|
|
400
|
-
}
|
|
401
|
-
|
|
402
|
-
//#endregion
|
|
403
|
-
//#region src/client/components/ui-base/search-dialog.tsx
|
|
404
|
-
function Highlight({ text, query, markClassName }) {
|
|
405
|
-
if (!query || !text) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, { children: text });
|
|
406
|
-
const escapedQuery = query.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
407
|
-
const regex = new RegExp(`(${escapedQuery})`, "gi");
|
|
408
|
-
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, { children: text.split(regex).map((part, i) => regex.test(part) ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("mark", {
|
|
409
|
-
className: require_link.cn("bg-primary-500/20 text-primary-600 dark:text-primary-400 font-bold px-0.5 rounded-sm", markClassName),
|
|
410
|
-
children: part
|
|
411
|
-
}, i) : part) });
|
|
412
|
-
}
|
|
413
|
-
function SearchDialog({ routes, className, markClassName }) {
|
|
414
|
-
const { isOpen, setIsOpen, query, setQuery, list, searchDataLoading, searchDataError, handleSelect } = useSearch(routes);
|
|
415
|
-
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
|
|
416
|
-
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)(require_search_dialog.Navbar.SearchTrigger.Desktop, {
|
|
417
|
-
onPress: () => setIsOpen(true),
|
|
418
|
-
className: "rounded-xl border border-subtle bg-surface text-muted transition-all duration-200 hover:border-primary-500/50 hover:text-body hover:bg-soft/50 hover:shadow-sm active:scale-[0.98] focus-visible:ring-2 focus-visible:ring-primary-500/30",
|
|
419
|
-
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
420
|
-
className: "flex items-center gap-2",
|
|
421
|
-
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_link.Search, { size: 16 }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
422
|
-
className: "hidden sm:inline-block",
|
|
423
|
-
children: "Search docs..."
|
|
424
|
-
})]
|
|
425
|
-
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_search_dialog.Navbar.SearchTrigger.Kbd, { className: "[&_kbd]:bg-main [&_kbd]:border [&_kbd]:border-subtle [&_kbd]:rounded [&_kbd]:px-1.5 [&_kbd]:h-5 [&_kbd]:w-5" })]
|
|
426
|
-
}),
|
|
427
|
-
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_search_dialog.Navbar.SearchTrigger.Mobile, {
|
|
428
|
-
onPress: () => setIsOpen(true),
|
|
429
|
-
className: "rounded-xl text-muted transition-all duration-200 hover:text-body active:scale-95 focus-visible:ring-2 focus-visible:ring-primary-500/30",
|
|
430
|
-
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_link.Search, { size: 20 })
|
|
431
|
-
}),
|
|
432
|
-
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(InternalErrorBoundary, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_search_dialog.SearchDialog.Overlay, {
|
|
433
|
-
isOpen,
|
|
434
|
-
isDismissable: true,
|
|
435
|
-
onOpenChange: () => setIsOpen(false),
|
|
436
|
-
className: require_link.cn("fixed inset-0 z-100 flex items-center justify-center p-4 bg-black/40 backdrop-blur-xs animate-fade-in", className),
|
|
437
|
-
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_search_dialog.SearchDialog.Content, {
|
|
438
|
-
className: "w-full max-w-lg bg-main border border-subtle shadow-md rounded-2xl overflow-hidden p-6",
|
|
439
|
-
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_search_dialog.SearchDialog.Dialog, {
|
|
440
|
-
"aria-label": "Search documentation",
|
|
441
|
-
className: "flex flex-col min-h-0 h-[450px]",
|
|
442
|
-
children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(require_search_dialog.SearchDialog.Autocomplete, {
|
|
443
|
-
className: "flex flex-col min-h-0",
|
|
444
|
-
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)(require_search_dialog.SearchDialog.Input, {
|
|
445
|
-
value: query,
|
|
446
|
-
onChange: setQuery,
|
|
447
|
-
className: "flex items-center gap-2 border border-subtle bg-surface px-4 py-2.5 rounded-xl focus-within:border-primary-500 mb-4",
|
|
448
|
-
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_search_dialog.SearchDialog.Input.SearchInput, {
|
|
449
|
-
placeholder: "Search documentation...",
|
|
450
|
-
className: "w-full bg-transparent outline-none text-body text-sm"
|
|
451
|
-
}), query && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_search_dialog.SearchDialog.Input.Button, {
|
|
452
|
-
onPress: () => setQuery(""),
|
|
453
|
-
className: "text-muted hover:text-body hover:bg-surface rounded-md p-1 cursor-pointer select-none transition-colors",
|
|
454
|
-
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_link.X, { size: 16 })
|
|
455
|
-
})]
|
|
456
|
-
}), searchDataLoading ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
457
|
-
className: "flex flex-1 items-center justify-center px-4 py-8 text-sm text-muted",
|
|
458
|
-
children: "Loading search index…"
|
|
459
|
-
}) : searchDataError ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
460
|
-
className: "flex flex-1 items-center justify-center px-4 py-8 text-center text-sm text-muted",
|
|
461
|
-
children: "Search is temporarily unavailable."
|
|
462
|
-
}) : query && list.length === 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
463
|
-
className: "flex flex-1 items-center justify-center px-4 py-8 text-sm text-muted",
|
|
464
|
-
children: "No results found."
|
|
465
|
-
}) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_search_dialog.SearchDialog.List, {
|
|
466
|
-
items: list,
|
|
467
|
-
onAction: handleSelect,
|
|
468
|
-
children: (item) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(require_search_dialog.SearchDialog.Item, {
|
|
469
|
-
textValue: item.title,
|
|
470
|
-
className: "flex items-center gap-3 px-4 py-2 rounded-xl group dark:hover:bg-primary-300/40 hover:bg-primary-200/50 transition-colors duration-100",
|
|
471
|
-
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_search_dialog.SearchDialog.Item.Icon, {
|
|
472
|
-
isHeading: item.isHeading,
|
|
473
|
-
className: "text-muted group-hover:text-primary-500 group-focus:text-primary-500"
|
|
474
|
-
}), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
475
|
-
className: "flex flex-col justify-center min-w-0",
|
|
476
|
-
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_search_dialog.SearchDialog.Item.Title, {
|
|
477
|
-
className: "text-sm font-medium text-body truncate dark:group-hover:text-primary-100",
|
|
478
|
-
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Highlight, {
|
|
479
|
-
text: item.title,
|
|
480
|
-
query,
|
|
481
|
-
markClassName
|
|
482
|
-
})
|
|
483
|
-
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_search_dialog.SearchDialog.Item.Bio, {
|
|
484
|
-
className: "text-xs text-muted truncate",
|
|
485
|
-
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Highlight, {
|
|
486
|
-
text: item.bio,
|
|
487
|
-
query,
|
|
488
|
-
markClassName
|
|
489
|
-
})
|
|
490
|
-
})]
|
|
491
|
-
})]
|
|
492
|
-
}, item.id)
|
|
493
|
-
})]
|
|
494
|
-
})
|
|
495
|
-
})
|
|
496
|
-
})
|
|
497
|
-
}) })
|
|
498
|
-
] });
|
|
499
|
-
}
|
|
500
|
-
|
|
501
|
-
//#endregion
|
|
502
|
-
Object.defineProperty(exports, 'InternalErrorBoundary', {
|
|
503
|
-
enumerable: true,
|
|
504
|
-
get: function () {
|
|
505
|
-
return InternalErrorBoundary;
|
|
506
|
-
}
|
|
507
|
-
});
|
|
508
|
-
Object.defineProperty(exports, 'SearchDialog', {
|
|
509
|
-
enumerable: true,
|
|
510
|
-
get: function () {
|
|
511
|
-
return SearchDialog;
|
|
512
|
-
}
|
|
513
|
-
});
|
|
514
|
-
Object.defineProperty(exports, 'useRoutes', {
|
|
515
|
-
enumerable: true,
|
|
516
|
-
get: function () {
|
|
517
|
-
return useRoutes;
|
|
518
|
-
}
|
|
519
|
-
});
|
|
520
|
-
Object.defineProperty(exports, 'useSearch', {
|
|
521
|
-
enumerable: true,
|
|
522
|
-
get: function () {
|
|
523
|
-
return useSearch;
|
|
524
|
-
}
|
|
525
|
-
});
|