@stainless-api/docs-search 0.1.0-beta.2 → 0.1.0-beta.21

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,5 +1,5 @@
1
- import { n as generateIndex, t as generateChatIndex } from "./indexer-DBU0POrK.js";
2
- import { i as SearchableAttributesProse, n as SearchableAttributes, r as SearchableAttributesChat } from "./types-BhJLoaNF.js";
1
+ import { n as generateIndex, t as generateChatIndex } from "./indexer-BDmIxFRi.js";
2
+ import { i as SearchableAttributesProse, n as SearchableAttributes, r as SearchableAttributesChat } from "./types-DyGUPDP0.js";
3
3
  import { searchClient } from "@algolia/client-search";
4
4
 
5
5
  //#region src/providers/algolia.ts
@@ -1,13 +1,13 @@
1
- import { i as search } from "./algolia-BOY-OcxU.js";
2
- import * as React from "react";
1
+ import { i as search } from "./algolia-gvZUkKkS.js";
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 = React.createContext(null);
7
+ const Context = createContext(null);
8
8
  Context.displayName = displayName;
9
9
  function useStrictContext() {
10
- const context = React.useContext(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
@@ -1,5 +1,4 @@
1
- import { f as ResultType, g as SearchSettings, h as SearchParams } from "./types-Gg968wOz.js";
2
- import * as React from "react";
1
+ import { f as ResultType, g as SearchSettings, h as SearchParams } from "./types-fPzO2V0p.js";
3
2
  import * as react_jsx_runtime0 from "react/jsx-runtime";
4
3
 
5
4
  //#region src/context.d.ts
package/dist/context.js CHANGED
@@ -1,5 +1,5 @@
1
- import "./indexer-DBU0POrK.js";
2
- import "./algolia-BOY-OcxU.js";
3
- import { n as useSearch, r as useSearchContext, t as SearchProvider } from "./context-CBTWkDal.js";
1
+ import "./indexer-BDmIxFRi.js";
2
+ import "./algolia-gvZUkKkS.js";
3
+ import { n as useSearch, r as useSearchContext, t as SearchProvider } from "./context-BeqLpg4u.js";
4
4
 
5
5
  export { SearchProvider, useSearch, useSearchContext };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { l as QueryKindsType, u as ResultData } from "./types-Gg968wOz.js";
1
+ import { l as QueryKindsType, u as ResultData } from "./types-fPzO2V0p.js";
2
2
  import * as react_jsx_runtime0 from "react/jsx-runtime";
3
3
 
4
4
  //#region src/form.d.ts
package/dist/index.js CHANGED
@@ -1,14 +1,15 @@
1
- import "./indexer-DBU0POrK.js";
2
- import { t as QueryKinds } from "./types-BhJLoaNF.js";
3
- import "./algolia-BOY-OcxU.js";
4
- import { n as useSearch, r as useSearchContext } from "./context-CBTWkDal.js";
5
- import { t as guideSearch } from "./pagefind-Dcn-gjDe.js";
6
- import * as React from "react";
1
+ import "./indexer-BDmIxFRi.js";
2
+ import { t as QueryKinds } from "./types-DyGUPDP0.js";
3
+ import "./algolia-gvZUkKkS.js";
4
+ import { n as useSearch, r as useSearchContext } from "./context-BeqLpg4u.js";
5
+ import { t as guideSearch } from "./pagefind-DCvI8YmZ.js";
6
+ import { createElement, useEffect, useRef, useState } from "react";
7
7
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
8
- import { BookOpenText, Box, Code, Folder, Search, Wrench, X } from "lucide-react";
8
+ import { BookOpenText, Box, Code, Folder, Search, Wrench } from "lucide-react";
9
9
  import { useLanguage } from "@stainless-api/docs-ui/contexts";
10
10
  import { useComponents } from "@stainless-api/docs-ui/contexts/use-components";
11
11
  import style from "@stainless-api/docs-ui/style";
12
+ import { Button } from "@stainless-api/ui-primitives";
12
13
 
13
14
  //#region src/results.tsx
14
15
  const QueryKindDisplay = {
@@ -223,35 +224,40 @@ function SearchForm() {
223
224
  const search = useSearch();
224
225
  const language = useLanguage();
225
226
  const { onSelect, pageFind } = useSearchContext();
226
- const [results, setResults] = React.useState(null);
227
- const [filterKind, setFilterKind] = React.useState("all");
228
- const [searchQuery, setSearchQuery] = React.useState("");
229
- const inputRef = React.useRef(null);
230
- async function performSearch() {
231
- const guideLimit = filterKind === "guide" ? 25 : 5;
232
- const kind = ["all", "guide"].includes(filterKind) ? void 0 : filterKind;
233
- const [guideResults, apiResults] = await Promise.all([pageFind ? guideSearch(pageFind, searchQuery, guideLimit) : [], search({
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
+ const guideLimit = 25;
233
+ const apiKindFilter = ["all", "guide"].includes(filterKind) ? void 0 : filterKind;
234
+ const ac = new AbortController();
235
+ Promise.all([pageFind ? guideSearch(pageFind, searchQuery, guideLimit) : [], search({
234
236
  query: searchQuery,
235
- kind,
237
+ kind: apiKindFilter,
236
238
  language
237
- })]);
238
- setResults({
239
- items: filterKind === "guide" ? guideResults : filterKind === "all" ? [...guideResults.slice(0, 5), ...apiResults?.hits ?? []] : apiResults?.hits ?? [],
240
- counts: {
241
- ...apiResults?.facets?.["kind"],
242
- guide: guideResults.length,
243
- all: apiResults?.nbHits
244
- }
245
- });
246
- }
247
- function clearInput() {
248
- setSearchQuery("");
249
- inputRef?.current?.focus();
250
- }
251
- React.useEffect(() => void performSearch(), [
239
+ })]).then(([guideResults, apiResults]) => {
240
+ if (ac.signal.aborted) return;
241
+ setResults({
242
+ items: filterKind === "guide" ? guideResults : filterKind === "all" ? [
243
+ ...guideResults.slice(0, 5),
244
+ ...apiResults?.hits ?? [],
245
+ ...guideResults.slice(5)
246
+ ] : apiResults?.hits ?? [],
247
+ counts: {
248
+ ...apiResults?.facets?.["kind"],
249
+ guide: guideResults.length,
250
+ all: (apiResults?.nbHits ?? 0) + guideResults.length
251
+ }
252
+ });
253
+ }).catch(() => {});
254
+ return () => ac.abort();
255
+ }, [
252
256
  searchQuery,
253
257
  filterKind,
254
- language
258
+ language,
259
+ search,
260
+ pageFind
255
261
  ]);
256
262
  return /* @__PURE__ */ jsxs("div", {
257
263
  className: style.SearchForm,
@@ -264,19 +270,13 @@ function SearchForm() {
264
270
  size: 16,
265
271
  className: style.Icon
266
272
  }),
267
- right: searchQuery && /* @__PURE__ */ jsx(X, {
268
- cursor: "pointer",
269
- onClick: () => clearInput(),
270
- size: 16,
271
- className: style.Icon
272
- }),
273
273
  value: searchQuery,
274
274
  placeholder: "Search"
275
275
  }),
276
276
  /* @__PURE__ */ jsx(SearchFilter, {
277
277
  results,
278
278
  filterKind,
279
- onChange: (filterKind$1) => setFilterKind(filterKind$1)
279
+ onChange: (filterKind) => setFilterKind(filterKind)
280
280
  }),
281
281
  /* @__PURE__ */ jsx(Docs.ListView, {
282
282
  items: results?.items ?? [],
@@ -287,16 +287,15 @@ function SearchForm() {
287
287
  });
288
288
  }
289
289
  function SearchFilter({ results, filterKind, onChange }) {
290
- const Docs = useComponents();
291
290
  const { pageFind } = useSearchContext();
292
- const toggles = pageFind ? QueryKinds : QueryKinds.slice(0, -1);
291
+ const toggles = pageFind ? QueryKinds : QueryKinds.filter((k) => k !== "guide");
293
292
  return /* @__PURE__ */ jsx("div", {
294
293
  className: style.SearchFilter,
295
- children: toggles.map((kind, index) => /* @__PURE__ */ jsxs(Docs.ToggleButton, {
296
- selected: filterKind === kind,
294
+ children: toggles.map((kind, index) => /* @__PURE__ */ jsxs(Button, {
295
+ variant: filterKind === kind ? "accent" : "outline",
297
296
  onClick: () => onChange?.(kind),
298
297
  children: [
299
- React.createElement(QueryKindDisplay[kind].icon, {
298
+ createElement(QueryKindDisplay[kind].icon, {
300
299
  size: 16,
301
300
  className: style.Icon
302
301
  }),
@@ -313,7 +312,14 @@ function SearchFilter({ results, filterKind, onChange }) {
313
312
  });
314
313
  }
315
314
  function SearchModal({ id, open: isOpen }) {
316
- const [open, setOpen] = React.useState(isOpen ?? false);
315
+ const [open, setOpen] = useState(isOpen ?? false);
316
+ useEffect(() => {
317
+ if (open) document.body.style.overflow = "hidden";
318
+ else document.body.style.overflow = "";
319
+ return () => {
320
+ document.body.style.overflow = "";
321
+ };
322
+ }, [open]);
317
323
  return /* @__PURE__ */ jsx("div", {
318
324
  id,
319
325
  onToggle: (ev) => setOpen(ev.newState === "open"),
package/dist/mcp.d.ts CHANGED
@@ -1,13 +1,11 @@
1
- import { n as IndexEntry, r as IndexMethod } from "./types-Gg968wOz.js";
1
+ import { b as Spec, n as IndexEntry, r as IndexMethod } from "./types-fPzO2V0p.js";
2
2
  import { DocsLanguage } from "@stainless-api/docs-ui/routing";
3
- import * as SDKJSON from "@stainless/sdk-json";
4
3
 
5
4
  //#region src/indexer.d.ts
6
-
7
- declare function generateIndex(spec: SDKJSON.Spec, renderMarkdownFn?: (_: string) => string | null, includeTypes?: boolean): Generator<IndexEntry>;
5
+ declare function generateIndex(spec: Spec, renderMarkdownFn?: (_: string) => string | null, includeTypes?: boolean): Generator<IndexEntry>;
8
6
  //#endregion
9
7
  //#region src/mcp.d.ts
10
8
  type Item = IndexEntry & IndexMethod;
11
- declare function render(spec: SDKJSON.Spec, language: DocsLanguage, items: Item[], includeModelProperties: boolean): any;
9
+ declare function render(spec: Spec, language: DocsLanguage, items: Item[], includeModelProperties: boolean): any;
12
10
  //#endregion
13
11
  export { generateIndex, render };
package/dist/mcp.js CHANGED
@@ -1,4 +1,4 @@
1
- import { n as generateIndex } from "./indexer-DBU0POrK.js";
1
+ import { n as generateIndex } from "./indexer-BDmIxFRi.js";
2
2
  import { parseStainlessPath } from "@stainless-api/docs-ui/routing";
3
3
  import { renderMarkdown } from "@stainless-api/docs-ui/markdown";
4
4
  import { getResourceFromSpec } from "@stainless-api/docs-ui/utils";
@@ -1,9 +1,8 @@
1
- import { f as ResultType, g as SearchSettings, h as SearchParams, s as ProseIndexEntry } from "../types-Gg968wOz.js";
2
- import * as SDKJSON from "@stainless/sdk-json";
1
+ import { b as Spec, f as ResultType, g as SearchSettings, h as SearchParams, s as ProseIndexEntry } from "../types-fPzO2V0p.js";
3
2
 
4
3
  //#region src/providers/algolia.d.ts
5
- declare function buildIndex(appId: string, indexName: string, writeKey: string, spec: SDKJSON.Spec, renderMarkdown: (_: string) => string | null): Promise<void>;
6
- declare function buildChatIndex(appId: string, indexName: string, writeKey: string, spec: SDKJSON.Spec): Promise<void>;
4
+ declare function buildIndex(appId: string, indexName: string, writeKey: string, spec: Spec, renderMarkdown: (_: string) => string | null): Promise<void>;
5
+ declare function buildChatIndex(appId: string, indexName: string, writeKey: string, spec: Spec): Promise<void>;
7
6
  declare function buildProseIndex(appId: string, indexName: string, writeKey: string, objects: ProseIndexEntry[]): Promise<void>;
8
7
  declare function search({
9
8
  settings: {
@@ -1,4 +1,4 @@
1
- import "../indexer-DBU0POrK.js";
2
- import { i as search, n as buildIndex, r as buildProseIndex, t as buildChatIndex } from "../algolia-BOY-OcxU.js";
1
+ import "../indexer-BDmIxFRi.js";
2
+ import { i as search, n as buildIndex, r as buildProseIndex, t as buildChatIndex } from "../algolia-gvZUkKkS.js";
3
3
 
4
4
  export { buildChatIndex, buildIndex, buildProseIndex, search };
@@ -1,15 +1,14 @@
1
- import { n as IndexEntry } from "../types-Gg968wOz.js";
1
+ import { b as Spec, n as IndexEntry } from "../types-fPzO2V0p.js";
2
2
  import { DocsLanguage } from "@stainless-api/docs-ui/routing";
3
3
  import * as fuse_js0 from "fuse.js";
4
4
  import { FuseIndex } from "fuse.js";
5
- import * as SDKJSON from "@stainless/sdk-json";
6
5
 
7
6
  //#region src/providers/fuse.d.ts
8
7
  type FuseIndexData = {
9
8
  content: IndexEntry[];
10
9
  index: FuseIndex<IndexEntry>;
11
10
  };
12
- declare function buildIndex(spec: SDKJSON.Spec, language?: DocsLanguage): FuseIndexData;
11
+ declare function buildIndex(spec: Spec, language?: DocsLanguage): FuseIndexData;
13
12
  declare function search({
14
13
  content,
15
14
  index
@@ -1,5 +1,5 @@
1
- import { n as generateIndex } from "../indexer-DBU0POrK.js";
2
- import { n as SearchableAttributes } from "../types-BhJLoaNF.js";
1
+ import { n as generateIndex } from "../indexer-BDmIxFRi.js";
2
+ import { n as SearchableAttributes } from "../types-DyGUPDP0.js";
3
3
  import Fuse from "fuse.js";
4
4
 
5
5
  //#region src/providers/fuse.ts
@@ -1,4 +1,4 @@
1
- import { t as GuideResultType } from "../types-Gg968wOz.js";
1
+ import { t as GuideResultType } from "../types-fPzO2V0p.js";
2
2
 
3
3
  //#region src/providers/pagefind.d.ts
4
4
  declare function guideSearch(loadPath: string, query: string, limit?: number): Promise<GuideResultType[]>;
@@ -1,3 +1,3 @@
1
- import { t as guideSearch } from "../pagefind-Dcn-gjDe.js";
1
+ import { t as guideSearch } from "../pagefind-DCvI8YmZ.js";
2
2
 
3
3
  export { guideSearch };
@@ -1,9 +1,8 @@
1
- import { n as IndexEntry } from "../types-Gg968wOz.js";
1
+ import { b as Spec, n as IndexEntry } from "../types-fPzO2V0p.js";
2
2
  import { DocsLanguage } from "@stainless-api/docs-ui/routing";
3
- import * as SDKJSON from "@stainless/sdk-json";
4
3
 
5
4
  //#region src/providers/walker.d.ts
6
- declare function buildIndex(spec: SDKJSON.Spec): Generator<IndexEntry, any, any>;
5
+ declare function buildIndex(spec: Spec): Generator<IndexEntry, any, any>;
7
6
  declare function search(index: Generator<IndexEntry>, language: DocsLanguage, query: string, limit?: number): IndexEntry[];
8
7
  //#endregion
9
8
  export { buildIndex, search };
@@ -1,5 +1,5 @@
1
- import { n as generateIndex } from "../indexer-DBU0POrK.js";
2
- import { n as SearchableAttributes } from "../types-BhJLoaNF.js";
1
+ import { n as generateIndex } from "../indexer-BDmIxFRi.js";
2
+ import { n as SearchableAttributes } from "../types-DyGUPDP0.js";
3
3
 
4
4
  //#region src/providers/walker.ts
5
5
  function buildIndex(spec) {
@@ -1,11 +1,11 @@
1
1
  //#region src/types.ts
2
2
  const QueryKinds = [
3
3
  "all",
4
+ "guide",
4
5
  "resource",
5
6
  "http_method",
6
7
  "model",
7
- "property",
8
- "guide"
8
+ "property"
9
9
  ];
10
10
  const SearchableAttributes = [
11
11
  "name",