@stainless-api/docs-search 0.1.0-beta.7 → 0.1.0-beta.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { i as search } from "./algolia-BOY-OcxU.js";
|
|
2
|
-
import
|
|
2
|
+
import { createContext, useCallback, useContext } from "react";
|
|
3
3
|
import { jsx } from "react/jsx-runtime";
|
|
4
4
|
|
|
5
5
|
//#region src/context.tsx
|
|
6
6
|
function createStrictContext(displayName) {
|
|
7
|
-
const Context =
|
|
7
|
+
const Context = createContext(null);
|
|
8
8
|
Context.displayName = displayName;
|
|
9
9
|
function useStrictContext() {
|
|
10
|
-
const context =
|
|
10
|
+
const context = useContext(Context);
|
|
11
11
|
if (context === null) throw new Error(`use${displayName} must be used within a ${displayName}Provider`);
|
|
12
12
|
return context;
|
|
13
13
|
}
|
|
@@ -16,10 +16,10 @@ function createStrictContext(displayName) {
|
|
|
16
16
|
const [Provider, useSearchContext] = createStrictContext("SearchContext");
|
|
17
17
|
function useSearch() {
|
|
18
18
|
const { settings } = useSearchContext();
|
|
19
|
-
return (params) => search({
|
|
19
|
+
return useCallback((params) => search({
|
|
20
20
|
settings,
|
|
21
21
|
params
|
|
22
|
-
});
|
|
22
|
+
}), [settings]);
|
|
23
23
|
}
|
|
24
24
|
function SearchProvider({ children, ...props }) {
|
|
25
25
|
return /* @__PURE__ */ jsx(Provider, {
|
package/dist/context.d.ts
CHANGED
package/dist/context.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import "./indexer-DBU0POrK.js";
|
|
2
2
|
import "./algolia-BOY-OcxU.js";
|
|
3
|
-
import { n as useSearch, r as useSearchContext, t as SearchProvider } from "./context-
|
|
3
|
+
import { n as useSearch, r as useSearchContext, t as SearchProvider } from "./context-CBZeYd0O.js";
|
|
4
4
|
|
|
5
5
|
export { SearchProvider, useSearch, useSearchContext };
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import "./indexer-DBU0POrK.js";
|
|
2
2
|
import { t as QueryKinds } from "./types-BhJLoaNF.js";
|
|
3
3
|
import "./algolia-BOY-OcxU.js";
|
|
4
|
-
import { n as useSearch, r as useSearchContext } from "./context-
|
|
4
|
+
import { n as useSearch, r as useSearchContext } from "./context-CBZeYd0O.js";
|
|
5
5
|
import { t as guideSearch } from "./pagefind-Dcn-gjDe.js";
|
|
6
|
-
import
|
|
6
|
+
import { createElement, useEffect, useRef, useState } from "react";
|
|
7
7
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
8
8
|
import { BookOpenText, Box, Code, Folder, Search, Wrench } from "lucide-react";
|
|
9
9
|
import { useLanguage } from "@stainless-api/docs-ui/contexts";
|
|
@@ -224,31 +224,36 @@ function SearchForm() {
|
|
|
224
224
|
const search = useSearch();
|
|
225
225
|
const language = useLanguage();
|
|
226
226
|
const { onSelect, pageFind } = useSearchContext();
|
|
227
|
-
const [results, setResults] =
|
|
228
|
-
const [filterKind, setFilterKind] =
|
|
229
|
-
const [searchQuery, setSearchQuery] =
|
|
230
|
-
const inputRef =
|
|
231
|
-
|
|
227
|
+
const [results, setResults] = useState(null);
|
|
228
|
+
const [filterKind, setFilterKind] = useState("all");
|
|
229
|
+
const [searchQuery, setSearchQuery] = useState("");
|
|
230
|
+
const inputRef = useRef(null);
|
|
231
|
+
useEffect(() => {
|
|
232
232
|
const guideLimit = filterKind === "guide" ? 25 : 5;
|
|
233
233
|
const kind = ["all", "guide"].includes(filterKind) ? void 0 : filterKind;
|
|
234
|
-
const
|
|
234
|
+
const ac = new AbortController();
|
|
235
|
+
Promise.all([pageFind ? guideSearch(pageFind, searchQuery, guideLimit) : [], search({
|
|
235
236
|
query: searchQuery,
|
|
236
237
|
kind,
|
|
237
238
|
language
|
|
238
|
-
})])
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
239
|
+
})]).then(([guideResults, apiResults]) => {
|
|
240
|
+
if (ac.signal.aborted) return;
|
|
241
|
+
setResults({
|
|
242
|
+
items: filterKind === "guide" ? guideResults : filterKind === "all" ? [...guideResults.slice(0, 5), ...apiResults?.hits ?? []] : apiResults?.hits ?? [],
|
|
243
|
+
counts: {
|
|
244
|
+
...apiResults?.facets?.["kind"],
|
|
245
|
+
guide: guideResults.length,
|
|
246
|
+
all: apiResults?.nbHits
|
|
247
|
+
}
|
|
248
|
+
});
|
|
249
|
+
}).catch(() => {});
|
|
250
|
+
return () => ac.abort();
|
|
251
|
+
}, [
|
|
249
252
|
searchQuery,
|
|
250
253
|
filterKind,
|
|
251
|
-
language
|
|
254
|
+
language,
|
|
255
|
+
search,
|
|
256
|
+
pageFind
|
|
252
257
|
]);
|
|
253
258
|
return /* @__PURE__ */ jsxs("div", {
|
|
254
259
|
className: style.SearchForm,
|
|
@@ -286,7 +291,7 @@ function SearchFilter({ results, filterKind, onChange }) {
|
|
|
286
291
|
variant: filterKind === kind ? "accent" : "outline",
|
|
287
292
|
onClick: () => onChange?.(kind),
|
|
288
293
|
children: [
|
|
289
|
-
|
|
294
|
+
createElement(QueryKindDisplay[kind].icon, {
|
|
290
295
|
size: 16,
|
|
291
296
|
className: style.Icon
|
|
292
297
|
}),
|
|
@@ -303,8 +308,8 @@ function SearchFilter({ results, filterKind, onChange }) {
|
|
|
303
308
|
});
|
|
304
309
|
}
|
|
305
310
|
function SearchModal({ id, open: isOpen }) {
|
|
306
|
-
const [open, setOpen] =
|
|
307
|
-
|
|
311
|
+
const [open, setOpen] = useState(isOpen ?? false);
|
|
312
|
+
useEffect(() => {
|
|
308
313
|
if (open) document.body.style.overflow = "hidden";
|
|
309
314
|
else document.body.style.overflow = "";
|
|
310
315
|
return () => {
|