@docsearch/react 5.0.0-beta.1 → 5.0.0-beta.3

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.
Files changed (38) hide show
  1. package/README.md +1 -1
  2. package/dist/esm/{AskAiScreenState-CRHicWbN.d.ts → AskAiScreenState-Sqbn60f2.d.ts} +5 -2
  3. package/dist/esm/{DocSearch-HJsNvtZr.d.ts → DocSearch-BVqxFxTw.d.ts} +20 -43
  4. package/dist/esm/{DocSearchAskAiModal-KaA6fBV4.js → DocSearchAskAiModal-C_sH1j8Y.js} +31 -38
  5. package/dist/esm/DocSearchAskAiModal-C_sH1j8Y.js.map +1 -0
  6. package/dist/esm/{DocSearchAskAiModal-B7vpLudE.d.ts → DocSearchAskAiModal-DpB7pLCC.d.ts} +4 -4
  7. package/dist/esm/{DocSearchModal-CpvDjo1O.js → DocSearchModal-CITTG0fe.js} +20 -26
  8. package/dist/esm/DocSearchModal-CITTG0fe.js.map +1 -0
  9. package/dist/esm/askaiModal.d.ts +1 -1
  10. package/dist/esm/askaiModal.js +1 -1
  11. package/dist/esm/docsearchAi.d.ts +13 -110
  12. package/dist/esm/docsearchAi.js +14 -4
  13. package/dist/esm/docsearchAi.js.map +1 -1
  14. package/dist/esm/index.d.ts +4 -4
  15. package/dist/esm/index.js +15 -5
  16. package/dist/esm/index.js.map +1 -1
  17. package/dist/esm/modal.d.ts +1 -1
  18. package/dist/esm/modal.js +1 -1
  19. package/dist/esm/{normalizeDocSearchIndexes-DAzlMybx.js → normalizeDocSearchIndexes-ChnVvoVt.js} +105 -74
  20. package/dist/esm/normalizeDocSearchIndexes-ChnVvoVt.js.map +1 -0
  21. package/dist/esm/sidepanel.d.ts +31 -27
  22. package/dist/esm/sidepanel.js +14 -11
  23. package/dist/esm/sidepanel.js.map +1 -1
  24. package/dist/esm/useDocSearchKeyboardEvents.js +1 -1
  25. package/dist/esm/useDocSearchKeyboardEvents.js.map +1 -1
  26. package/dist/esm/useSearchClient-mIHVB6ga.js.map +1 -1
  27. package/dist/esm/{useSuggestedQuestions-CG2H3qm4.js → useSuggestedQuestions-DwcUPOf_.js} +107 -50
  28. package/dist/esm/useSuggestedQuestions-DwcUPOf_.js.map +1 -0
  29. package/dist/esm/version.d.ts +1 -1
  30. package/dist/esm/version.js +1 -1
  31. package/dist/esm/version.js.map +1 -1
  32. package/dist/umd/index.js +44 -42
  33. package/dist/umd/index.js.map +1 -1
  34. package/package.json +4 -4
  35. package/dist/esm/DocSearchAskAiModal-KaA6fBV4.js.map +0 -1
  36. package/dist/esm/DocSearchModal-CpvDjo1O.js.map +0 -1
  37. package/dist/esm/normalizeDocSearchIndexes-DAzlMybx.js.map +0 -1
  38. package/dist/esm/useSuggestedQuestions-CG2H3qm4.js.map +0 -1
@@ -1,5 +1,5 @@
1
1
  import { t as _objectSpread2 } from "./objectSpread2-BNmiQYyW.js";
2
- import { C as noop, S as scrollTo, T as identity, _ as Hit, a as NoResultsScreen, b as SearchBoxForm, d as useRefreshOnInitialQuery, f as useModalRefs, g as useDocSearchFacets, h as useSendItemClickEvent, i as ResultsScreen, l as useStoredDocSearches, m as useInitialModalQuery, n as buildNoQuerySources, o as ErrorScreen, p as useModalEnvironment, r as buildQuerySources, s as StoredSearchesSections, t as normalizeDocSearchIndexes, u as useSaveRecentSearch, v as Footer, w as isModifierEvent, x as FacetBar, y as ModalShell } from "./normalizeDocSearchIndexes-DAzlMybx.js";
2
+ import { C as noop, E as identity, S as scrollTo, T as isModifierEvent, _ as Hit, a as NoResultsScreen, b as SearchBoxForm, d as useRefreshOnInitialQuery, f as useModalRefs, g as useDocSearchFacets, h as useSendItemClickEvent, i as ResultsScreen, l as useStoredDocSearches, m as useInitialModalQuery, n as buildNoQuerySources, o as ErrorScreen, p as useModalEnvironment, r as buildQuerySources, s as StoredSearchesSections, t as normalizeDocSearchIndexes, u as useSaveRecentSearch, v as Footer, w as isQueryEmpty, x as FacetBar, y as ModalShell } from "./normalizeDocSearchIndexes-ChnVvoVt.js";
3
3
  import { t as _objectWithoutProperties } from "./objectWithoutProperties-phqYxDS0.js";
4
4
  import { t as useSearchClient } from "./useSearchClient-mIHVB6ga.js";
5
5
  import React from "react";
@@ -44,14 +44,16 @@ const ScreenState = React.memo((_ref) => {
44
44
  var _props$state;
45
45
  let { translations = {} } = _ref, props = _objectWithoutProperties(_ref, _excluded$1);
46
46
  if (((_props$state = props.state) === null || _props$state === void 0 ? void 0 : _props$state.status) === "error") return /* @__PURE__ */ React.createElement(ErrorScreen, { translations: translations === null || translations === void 0 ? void 0 : translations.errorScreen });
47
- if (!props.state.query) return /* @__PURE__ */ React.createElement(KeywordStartScreen, _objectSpread2(_objectSpread2({}, props), {}, {
47
+ if (isQueryEmpty(props.state.query)) return /* @__PURE__ */ React.createElement(KeywordStartScreen, _objectSpread2(_objectSpread2({}, props), {}, {
48
48
  hasCollections: props.hasCollections,
49
49
  translations: translations === null || translations === void 0 ? void 0 : translations.startScreen
50
50
  }));
51
51
  if (!props.hasCollections) return /* @__PURE__ */ React.createElement(NoResultsScreen, _objectSpread2(_objectSpread2({}, props), {}, { translations: translations === null || translations === void 0 ? void 0 : translations.noResultsScreen }));
52
52
  return /* @__PURE__ */ React.createElement(ResultsScreen, _objectSpread2(_objectSpread2({}, props), {}, { translations: translations === null || translations === void 0 ? void 0 : translations.resultsScreen }));
53
- }, function areEqual(_prevProps, nextProps) {
54
- return nextProps.state.status === "loading" || nextProps.state.status === "stalled";
53
+ }, function areEqual(prevProps, nextProps) {
54
+ const isLoading = nextProps.state.status === "loading" || nextProps.state.status === "stalled";
55
+ const isWaitingForCollections = nextProps.state.status === "idle" && !isQueryEmpty(nextProps.state.query) && prevProps.state.query !== nextProps.state.query && prevProps.state.collections === nextProps.state.collections;
56
+ return isLoading || isWaitingForCollections;
55
57
  });
56
58
 
57
59
  //#endregion
@@ -76,9 +78,8 @@ const _excluded = [
76
78
  "recentSearchesLimit",
77
79
  "recentSearchesWithFavoritesLimit",
78
80
  "indices",
79
- "indexName",
80
- "searchParameters",
81
- "facets"
81
+ "facets",
82
+ "footerAction"
82
83
  ];
83
84
  const _excluded2 = [
84
85
  "footer",
@@ -87,7 +88,7 @@ const _excluded2 = [
87
88
  ];
88
89
  function DocSearchModal(_ref) {
89
90
  var _translations$searchB;
90
- let { appId, apiKey, maxResultsPerGroup, theme, onClose = noop, transformItems = identity, hitComponent = Hit, resultsFooterComponent = () => null, navigator, initialScrollY = 0, transformSearchClient = identity, disableUserPersonalization = false, initialQuery: initialQueryFromProp = "", translations = {}, getMissingResultsUrl, insights = false, recentSearchesLimit = 7, recentSearchesWithFavoritesLimit = 4, indices = [], indexName, searchParameters, facets } = _ref, props = _objectWithoutProperties(_ref, _excluded);
91
+ let { appId, apiKey, maxResultsPerGroup, theme, onClose = noop, transformItems = identity, hitComponent = Hit, resultsFooterComponent = () => null, navigator, initialScrollY = 0, transformSearchClient = identity, disableUserPersonalization = false, initialQuery: initialQueryFromProp = "", translations = {}, getMissingResultsUrl, insights = false, recentSearchesLimit = 7, recentSearchesWithFavoritesLimit = 4, indices, facets, footerAction } = _ref, props = _objectWithoutProperties(_ref, _excluded);
91
92
  const { footer: footerTranslations, searchBox: searchBoxTranslations, facets: facetBarTranslations } = translations, screenStateTranslations = _objectWithoutProperties(translations, _excluded2);
92
93
  const [state, setState] = React.useState({
93
94
  query: "",
@@ -99,18 +100,10 @@ function DocSearchModal(_ref) {
99
100
  status: "idle"
100
101
  });
101
102
  const placeholder = (translations === null || translations === void 0 || (_translations$searchB = translations.searchBox) === null || _translations$searchB === void 0 ? void 0 : _translations$searchB.placeholderText) || props.placeholder || "Search docs";
102
- const { containerRef, modalRef, formElementRef, dropdownRef, inputRef, snippetLength } = useModalRefs();
103
+ const { containerRef, modalRef, formElementRef, dropdownRef, inputRef } = useModalRefs();
103
104
  const { initialQuery, initialQueryFromSelection } = useInitialModalQuery(initialQueryFromProp);
104
105
  const searchClient = useSearchClient(appId, apiKey, transformSearchClient);
105
- const indexes = React.useMemo(() => normalizeDocSearchIndexes({
106
- indexName,
107
- indices,
108
- searchParameters
109
- }), [
110
- indexName,
111
- indices,
112
- searchParameters
113
- ]);
106
+ const indexes = React.useMemo(() => normalizeDocSearchIndexes({ indices }), [indices]);
114
107
  const defaultIndexName = indexes[0].name;
115
108
  const autocompleteRef = React.useRef(void 0);
116
109
  const { visibleFacets, facetSelections, facetSelectionsRef, handleFacetSelectionChange, clearFacetSelections } = useDocSearchFacets({
@@ -147,7 +140,7 @@ function DocSearchModal(_ref) {
147
140
  setState(changes.state);
148
141
  },
149
142
  getSources({ query, state: sourcesState, setContext, setStatus }) {
150
- if (!query) return buildNoQuerySources({
143
+ if (isQueryEmpty(query)) return buildNoQuerySources({
151
144
  recentSearches,
152
145
  favoriteSearches,
153
146
  saveRecentSearch,
@@ -161,7 +154,6 @@ function DocSearchModal(_ref) {
161
154
  setStatus,
162
155
  searchClient,
163
156
  indexes,
164
- snippetLength,
165
157
  insights: Boolean(insights),
166
158
  appId,
167
159
  apiKey,
@@ -183,7 +175,6 @@ function DocSearchModal(_ref) {
183
175
  inputRef,
184
176
  initialScrollY,
185
177
  modalRef,
186
- snippetLength,
187
178
  theme
188
179
  });
189
180
  React.useEffect(() => {
@@ -196,7 +187,7 @@ function DocSearchModal(_ref) {
196
187
  });
197
188
  let showDocsearchDropdown = true;
198
189
  const hasCollections = state.collections.some((collection) => collection.items.length > 0);
199
- if (state.status === "idle" && hasCollections === false && state.query.length === 0) showDocsearchDropdown = false;
190
+ if (state.status === "idle" && hasCollections === false && isQueryEmpty(state.query)) showDocsearchDropdown = false;
200
191
  return /* @__PURE__ */ React.createElement(ModalShell, {
201
192
  state,
202
193
  containerRef,
@@ -208,13 +199,13 @@ function DocSearchModal(_ref) {
208
199
  searchBox: /* @__PURE__ */ React.createElement(KeywordSearchBox, _objectSpread2(_objectSpread2({}, autocomplete), {}, {
209
200
  state,
210
201
  placeholder: placeholder || "Search docs",
211
- autoFocus: initialQuery.length === 0,
202
+ autoFocus: isQueryEmpty(initialQuery),
212
203
  inputRef,
213
204
  isFromSelection: Boolean(initialQuery) && initialQuery === initialQueryFromSelection,
214
205
  translations: searchBoxTranslations,
215
206
  onClose
216
207
  })),
217
- filterBar: state.query !== "" ? /* @__PURE__ */ React.createElement(FacetBar, {
208
+ filterBar: !isQueryEmpty(state.query) ? /* @__PURE__ */ React.createElement(FacetBar, {
218
209
  facets: visibleFacets,
219
210
  selections: facetSelections,
220
211
  translations: facetBarTranslations,
@@ -240,11 +231,14 @@ function DocSearchModal(_ref) {
240
231
  if (!isModifierEvent(event)) onClose();
241
232
  }
242
233
  })),
243
- footer: /* @__PURE__ */ React.createElement(Footer, { translations: footerTranslations }),
234
+ footer: /* @__PURE__ */ React.createElement(Footer, {
235
+ translations: footerTranslations,
236
+ footerAction
237
+ }),
244
238
  onClose
245
239
  });
246
240
  }
247
241
 
248
242
  //#endregion
249
243
  export { DocSearchModal as t };
250
- //# sourceMappingURL=DocSearchModal-CpvDjo1O.js.map
244
+ //# sourceMappingURL=DocSearchModal-CITTG0fe.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DocSearchModal-CITTG0fe.js","names":[],"sources":["../../src/components/KeywordSearchBox.tsx","../../src/components/KeywordStartScreen.tsx","../../src/ScreenState.tsx","../../src/DocSearchModal.tsx"],"sourcesContent":["import type {\n AutocompleteApi,\n AutocompleteState,\n} from '@algolia/autocomplete-core';\nimport React, { type JSX, type RefObject } from 'react';\n\nimport type { InternalDocSearchHit } from '../types';\n\nimport { SearchBoxForm } from './ui/SearchBoxForm';\n\nexport type KeywordSearchBoxTranslations = Partial<{\n clearButtonTitle: string;\n clearButtonAriaLabel: string;\n closeButtonText: string;\n closeButtonAriaLabel: string;\n placeholderText: string;\n enterKeyHint: string;\n searchInputLabel: string;\n}>;\n\ninterface KeywordSearchBoxProps extends AutocompleteApi<\n InternalDocSearchHit,\n React.FormEvent,\n React.MouseEvent,\n React.KeyboardEvent\n> {\n state: AutocompleteState<InternalDocSearchHit>;\n autoFocus: boolean;\n inputRef: RefObject<HTMLInputElement | null>;\n onClose: () => void;\n placeholder: string;\n isFromSelection: boolean;\n translations?: KeywordSearchBoxTranslations;\n}\n\nexport function KeywordSearchBox({\n translations = {},\n ...props\n}: KeywordSearchBoxProps): JSX.Element {\n const {\n clearButtonTitle = 'Clear',\n clearButtonAriaLabel = 'Clear the query',\n closeButtonText = 'Close',\n closeButtonAriaLabel = 'Close',\n searchInputLabel = 'Search',\n } = translations;\n\n const actionsBeforeClose = (\n <>\n <button\n className=\"DocSearch-Clear\"\n type=\"reset\"\n aria-label={clearButtonAriaLabel}\n hidden={!props.state.query}\n tabIndex={props.state.query ? 0 : -1}\n aria-hidden={!props.state.query ? 'true' : 'false'}\n >\n {clearButtonTitle}\n </button>\n\n {props.state.query && <div className=\"DocSearch-Divider\" />}\n </>\n );\n\n return (\n <SearchBoxForm\n {...props}\n clearButtonTitle={clearButtonTitle}\n clearButtonAriaLabel={clearButtonAriaLabel}\n closeButtonText={closeButtonText}\n closeButtonAriaLabel={closeButtonAriaLabel}\n searchInputLabel={searchInputLabel}\n inputProps={{\n enterKeyHint: 'search',\n }}\n actionsBeforeClose={actionsBeforeClose}\n />\n );\n}\n","import React, { type JSX } from 'react';\n\nimport type { ScreenStateProps } from '../ScreenState';\nimport type { InternalDocSearchHit } from '../types';\n\nimport type { StoredSearchesSectionsTranslations } from './ui/StoredSearchesSections';\nimport { StoredSearchesSections } from './ui/StoredSearchesSections';\n\nexport type KeywordStartScreenTranslations = StoredSearchesSectionsTranslations;\n\ntype KeywordStartScreenProps = Omit<\n ScreenStateProps<InternalDocSearchHit>,\n 'translations'\n> & {\n hasCollections: boolean;\n translations?: KeywordStartScreenTranslations;\n};\n\nexport function KeywordStartScreen({\n translations = {},\n ...props\n}: KeywordStartScreenProps): JSX.Element | null {\n return (\n <div className=\"DocSearch-Dropdown-Container\">\n <StoredSearchesSections {...props} translations={translations} />\n </div>\n );\n}\n","import type {\n AutocompleteApi,\n AutocompleteState,\n BaseItem,\n} from '@algolia/autocomplete-core';\nimport React from 'react';\n\nimport type { KeywordStartScreenTranslations } from './components/KeywordStartScreen';\nimport { KeywordStartScreen } from './components/KeywordStartScreen';\nimport type { DocSearchProps } from './DocSearch';\nimport type { ErrorScreenTranslations } from './ErrorScreen';\nimport { ErrorScreen } from './ErrorScreen';\nimport type { NoResultsScreenTranslations } from './NoResultsScreen';\nimport { NoResultsScreen } from './NoResultsScreen';\nimport type { ResultsScreenTranslations } from './ResultsScreen';\nimport { ResultsScreen } from './ResultsScreen';\nimport type { StoredSearchPlugin } from './stored-searches';\nimport type { InternalDocSearchHit, StoredDocSearchHit } from './types';\nimport { isQueryEmpty } from './utils';\n\nexport type ScreenStateTranslations = Partial<{\n errorScreen: ErrorScreenTranslations;\n startScreen: KeywordStartScreenTranslations;\n noResultsScreen: NoResultsScreenTranslations;\n resultsScreen: ResultsScreenTranslations;\n}>;\n\nexport interface ScreenStateProps<\n TItem extends BaseItem,\n> extends AutocompleteApi<\n TItem,\n React.FormEvent,\n React.MouseEvent,\n React.KeyboardEvent\n> {\n state: AutocompleteState<TItem>;\n recentSearches: StoredSearchPlugin<StoredDocSearchHit>;\n favoriteSearches: StoredSearchPlugin<StoredDocSearchHit>;\n onItemClick: (\n item: InternalDocSearchHit,\n event: KeyboardEvent | MouseEvent\n ) => void;\n inputRef: React.MutableRefObject<HTMLInputElement | null>;\n hitComponent: DocSearchProps['hitComponent'];\n indexName: string;\n disableUserPersonalization: boolean;\n resultsFooterComponent: DocSearchProps['resultsFooterComponent'];\n translations: ScreenStateTranslations;\n getMissingResultsUrl?: DocSearchProps['getMissingResultsUrl'];\n hasCollections: boolean;\n resultBadgeKey?: string;\n}\n\nexport const ScreenState = React.memo(\n ({ translations = {}, ...props }: ScreenStateProps<InternalDocSearchHit>) => {\n if (props.state?.status === 'error') {\n return <ErrorScreen translations={translations?.errorScreen} />;\n }\n\n if (isQueryEmpty(props.state.query)) {\n return (\n <KeywordStartScreen\n {...props}\n hasCollections={props.hasCollections}\n translations={translations?.startScreen}\n />\n );\n }\n\n if (!props.hasCollections) {\n return (\n <NoResultsScreen\n {...props}\n translations={translations?.noResultsScreen}\n />\n );\n }\n\n return (\n <ResultsScreen {...props} translations={translations?.resultsScreen} />\n );\n },\n function areEqual(prevProps, nextProps) {\n const isLoading =\n nextProps.state.status === 'loading' ||\n nextProps.state.status === 'stalled';\n\n const isWaitingForCollections =\n nextProps.state.status === 'idle' &&\n !isQueryEmpty(nextProps.state.query) &&\n prevProps.state.query !== nextProps.state.query &&\n prevProps.state.collections === nextProps.state.collections;\n\n return isLoading || isWaitingForCollections;\n }\n);\n","import { createAutocomplete } from '@algolia/autocomplete-core';\nimport React, { type JSX } from 'react';\n\nimport type { FacetBarTranslations } from './components/FacetBar';\nimport { FacetBar } from './components/FacetBar';\nimport type { KeywordSearchBoxTranslations } from './components/KeywordSearchBox';\nimport { KeywordSearchBox } from './components/KeywordSearchBox';\nimport { ModalShell } from './components/ui/ModalShell';\nimport type { DocSearchProps } from './DocSearch';\nimport type { FooterTranslations } from './Footer';\nimport { Footer } from './Footer';\nimport { Hit } from './Hit';\nimport { useDocSearchFacets } from './hooks/useDocSearchFacets';\nimport { useSendItemClickEvent } from './hooks/useDocSearchInsights';\nimport { useInitialModalQuery } from './hooks/useInitialModalQuery';\nimport { useModalEnvironment } from './hooks/useModalEnvironment';\nimport { useModalRefs } from './hooks/useModalRefs';\nimport { useRefreshOnInitialQuery } from './hooks/useRefreshOnInitialQuery';\nimport { useSaveRecentSearch } from './hooks/useSaveRecentSearch';\nimport { useStoredDocSearches } from './hooks/useStoredDocSearches';\nimport type { ScreenStateTranslations } from './ScreenState';\nimport { ScreenState } from './ScreenState';\nimport type { DocSearchState, InternalDocSearchHit } from './types';\nimport { useSearchClient } from './useSearchClient';\nimport {\n identity,\n isModifierEvent,\n isQueryEmpty,\n noop,\n scrollTo as scrollToUtils,\n} from './utils';\nimport {\n buildNoQuerySources,\n buildQuerySources,\n type BuildQuerySourcesState,\n} from './utils/createDocSearchSources';\nimport { normalizeDocSearchIndexes } from './utils/normalizeDocSearchIndexes';\n\nexport type ModalTranslations = Partial<{\n searchBox: KeywordSearchBoxTranslations;\n footer: FooterTranslations;\n facets: FacetBarTranslations;\n}> &\n ScreenStateTranslations;\n\nexport type DocSearchModalProps = DocSearchProps & {\n initialScrollY: number;\n onClose?: () => void;\n translations?: ModalTranslations;\n};\n\nexport function DocSearchModal({\n appId,\n apiKey,\n maxResultsPerGroup,\n theme,\n onClose = noop,\n transformItems = identity,\n hitComponent = Hit,\n resultsFooterComponent = (): JSX.Element | null => null,\n navigator,\n initialScrollY = 0,\n transformSearchClient = identity,\n disableUserPersonalization = false,\n initialQuery: initialQueryFromProp = '',\n translations = {},\n getMissingResultsUrl,\n insights = false,\n recentSearchesLimit = 7,\n recentSearchesWithFavoritesLimit = 4,\n indices,\n facets,\n footerAction,\n ...props\n}: DocSearchModalProps): JSX.Element {\n const {\n footer: footerTranslations,\n searchBox: searchBoxTranslations,\n facets: facetBarTranslations,\n ...screenStateTranslations\n } = translations;\n const [state, setState] = React.useState<\n DocSearchState<InternalDocSearchHit>\n >({\n query: '',\n collections: [],\n completion: null,\n context: {},\n isOpen: false,\n activeItemId: null,\n status: 'idle',\n });\n\n const placeholder =\n translations?.searchBox?.placeholderText ||\n props.placeholder ||\n 'Search docs';\n\n const { containerRef, modalRef, formElementRef, dropdownRef, inputRef } =\n useModalRefs();\n const { initialQuery, initialQueryFromSelection } =\n useInitialModalQuery(initialQueryFromProp);\n\n const searchClient = useSearchClient(appId, apiKey, transformSearchClient);\n\n const indexes = React.useMemo(\n () =>\n normalizeDocSearchIndexes({\n indices,\n }),\n [indices]\n );\n const defaultIndexName = indexes[0].name;\n\n const autocompleteRef =\n React.useRef<\n ReturnType<\n typeof createAutocomplete<\n InternalDocSearchHit,\n React.FormEvent<HTMLFormElement>,\n React.MouseEvent,\n React.KeyboardEvent\n >\n >\n >(undefined);\n\n const {\n visibleFacets,\n facetSelections,\n facetSelectionsRef,\n handleFacetSelectionChange,\n clearFacetSelections,\n } = useDocSearchFacets({\n facets,\n indexes,\n searchClient,\n onSelectionsChange: () => autocompleteRef.current?.refresh(),\n });\n\n const { favoriteSearches, recentSearches } = useStoredDocSearches({\n defaultIndexName,\n recentSearchesLimit,\n recentSearchesWithFavoritesLimit,\n });\n const saveRecentSearch = useSaveRecentSearch({\n favoriteSearches,\n recentSearches,\n disableUserPersonalization,\n });\n const sendItemClickEvent = useSendItemClickEvent(state);\n\n if (!autocompleteRef.current) {\n autocompleteRef.current = createAutocomplete({\n id: 'docsearch',\n defaultActiveItemId: 0,\n openOnFocus: true,\n initialState: {\n query: initialQuery,\n context: {\n searchSuggestions: [],\n },\n },\n insights: Boolean(insights),\n navigator,\n onStateChange(changes) {\n setState(changes.state);\n },\n getSources({ query, state: sourcesState, setContext, setStatus }) {\n if (isQueryEmpty(query)) {\n const noQuerySources = buildNoQuerySources({\n recentSearches,\n favoriteSearches,\n saveRecentSearch,\n onClose,\n disableUserPersonalization,\n });\n return noQuerySources;\n }\n\n const querySourcesState: BuildQuerySourcesState = {\n context: sourcesState.context,\n };\n\n const algoliaSourcesPromise = buildQuerySources({\n query,\n state: querySourcesState,\n setContext,\n setStatus,\n searchClient,\n indexes,\n insights: Boolean(insights),\n appId,\n apiKey,\n maxResultsPerGroup,\n transformItems,\n saveRecentSearch,\n onClose,\n facetSelections: facetSelectionsRef,\n });\n\n return algoliaSourcesPromise;\n },\n });\n }\n\n const autocomplete = autocompleteRef.current;\n\n const { getEnvironmentProps, getRootProps, refresh } = autocomplete;\n\n useModalEnvironment({\n getEnvironmentProps,\n containerRef,\n dropdownRef,\n formElementRef,\n inputRef,\n initialScrollY,\n modalRef,\n theme,\n });\n\n React.useEffect(() => {\n if (dropdownRef.current) {\n scrollToUtils(dropdownRef.current);\n }\n }, [state.query, dropdownRef]);\n\n useRefreshOnInitialQuery({ initialQuery, inputRef, refresh });\n\n // hide the dropdown on idle and no collections\n let showDocsearchDropdown = true;\n const hasCollections = state.collections.some(\n (collection) => collection.items.length > 0\n );\n if (\n state.status === 'idle' &&\n hasCollections === false &&\n isQueryEmpty(state.query)\n ) {\n showDocsearchDropdown = false;\n }\n\n return (\n <ModalShell\n state={state}\n containerRef={containerRef}\n modalRef={modalRef}\n formElementRef={formElementRef}\n dropdownRef={dropdownRef}\n getRootProps={getRootProps}\n showDropdown={showDocsearchDropdown}\n searchBox={\n <KeywordSearchBox\n {...autocomplete}\n state={state}\n placeholder={placeholder || 'Search docs'}\n autoFocus={isQueryEmpty(initialQuery)}\n inputRef={inputRef}\n isFromSelection={\n Boolean(initialQuery) && initialQuery === initialQueryFromSelection\n }\n translations={searchBoxTranslations}\n onClose={onClose}\n />\n }\n filterBar={\n !isQueryEmpty(state.query) ? (\n <FacetBar\n facets={visibleFacets}\n selections={facetSelections}\n translations={facetBarTranslations}\n clearSelections={clearFacetSelections}\n onSelectionChange={handleFacetSelectionChange}\n />\n ) : null\n }\n screenState={\n <ScreenState\n {...autocomplete}\n indexName={defaultIndexName}\n state={state}\n hitComponent={hitComponent}\n resultsFooterComponent={resultsFooterComponent}\n disableUserPersonalization={disableUserPersonalization}\n recentSearches={recentSearches}\n favoriteSearches={favoriteSearches}\n inputRef={inputRef}\n translations={screenStateTranslations}\n getMissingResultsUrl={getMissingResultsUrl}\n hasCollections={hasCollections}\n resultBadgeKey={props.resultBadgeKey}\n onItemClick={(item, event) => {\n sendItemClickEvent(item);\n saveRecentSearch(item);\n if (!isModifierEvent(event)) {\n onClose();\n }\n }}\n />\n }\n footer={\n <Footer translations={footerTranslations} footerAction={footerAction} />\n }\n onClose={onClose}\n />\n );\n}\n"],"mappings":"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"}
@@ -1,2 +1,2 @@
1
- import { n as DocSearchAskAiModalProps, r as DocSearchAskAiModalTranslations, t as DocSearchAskAiModal } from "./DocSearchAskAiModal-B7vpLudE.js";
1
+ import { n as DocSearchAskAiModalProps, r as DocSearchAskAiModalTranslations, t as DocSearchAskAiModal } from "./DocSearchAskAiModal-DpB7pLCC.js";
2
2
  export { DocSearchAskAiModal, DocSearchAskAiModalProps, DocSearchAskAiModalTranslations };
@@ -1,3 +1,3 @@
1
- import { t as DocSearchAskAiModal } from "./DocSearchAskAiModal-KaA6fBV4.js";
1
+ import { t as DocSearchAskAiModal } from "./DocSearchAskAiModal-C_sH1j8Y.js";
2
2
 
3
3
  export { DocSearchAskAiModal };
@@ -1,8 +1,7 @@
1
1
  import { o as ToolCalls } from "./index-Bqqv4HmN.js";
2
- import { a as DocSearchProps } from "./DocSearch-HJsNvtZr.js";
2
+ import { a as DocSearchProps } from "./DocSearch-BVqxFxTw.js";
3
3
  import { DocSearchRef, InitialAskAiMessage } from "@docsearch/core";
4
4
  import React, { JSX } from "react";
5
- import { SearchParamsObject } from "algoliasearch/lite";
6
5
  //#region src/DocSearchAI.d.ts
7
6
  interface AskAiSearchParameters {
8
7
  facetFilters?: string[];
@@ -12,103 +11,6 @@ interface AskAiSearchParameters {
12
11
  distinct?: boolean | number | string;
13
12
  }
14
13
  type AgentStudioSearchParameters = Record<string, Omit<AskAiSearchParameters, 'facetFilters'>>;
15
- interface IndexTextParam {
16
- exposed: boolean;
17
- default?: string;
18
- }
19
- interface NumberConstraint {
20
- min?: number;
21
- max?: number;
22
- }
23
- interface IndexNumberParam {
24
- exposed: boolean;
25
- default?: number;
26
- constraint?: NumberConstraint;
27
- }
28
- interface StringArrayConstraints {
29
- values?: string[];
30
- }
31
- interface IndexStringArrayParam {
32
- exposed: boolean;
33
- default?: string[];
34
- constraint?: StringArrayConstraints;
35
- merge?: boolean;
36
- }
37
- interface IndexFacetParam {
38
- exposed: false;
39
- default?: string[];
40
- }
41
- interface AgentStudioSearchControls {
42
- /**
43
- * Augmented query for the MCP search tool to use.
44
- *
45
- * @default undefined
46
- */
47
- query?: IndexTextParam;
48
- /**
49
- * Number of hits for the MCP to return per page.
50
- *
51
- * @default { exposed: false, default: 7 }
52
- */
53
- hits_per_page?: IndexNumberParam;
54
- /**
55
- * The page number the MCP should pull results from.
56
- *
57
- * @default { exposed: false, default: 0 }
58
- */
59
- page?: IndexNumberParam;
60
- /**
61
- * List of attributes that the MCP can retrieve from the index.
62
- *
63
- * @default { exposed: false, default: ['*'] }
64
- */
65
- attributesToRetrieve?: IndexStringArrayParam;
66
- /**
67
- * List of fields that the MCP will return to the Agent.
68
- *
69
- * @default { exposed: false, default: ["hits", "nbHits", "page", "nbPages", "hitsPerPage", "facets"] }
70
- */
71
- responseFields?: IndexStringArrayParam;
72
- /**
73
- * Defined facets the MCP will use when querying the index.
74
- *
75
- * @default undefined
76
- */
77
- facets?: IndexFacetParam;
78
- /**
79
- * Any other custom properties the MCP should send when querying the index.
80
- *
81
- * @default undefined
82
- */
83
- custom?: Record<string, unknown>;
84
- }
85
- interface AgentStudioIndices {
86
- /** The name of the index used by the search tool. */
87
- index: string;
88
- /** A brief description for the search tool. */
89
- description: string;
90
- /**
91
- * A description used to steer the agent on how/when to use the search tool.
92
- *
93
- * @default ''
94
- */
95
- enhancedDescription?: string;
96
- /**
97
- * Default search parameters for the internal (non-MCP) search tool path.
98
- *
99
- * @default undefined
100
- */
101
- searchParameters?: SearchParamsObject;
102
- /**
103
- * Structured search parameters for the MCP-based search tool path.
104
- *
105
- * Each parameter controls whether it is exposed to the LLM and it's default
106
- * value.
107
- *
108
- * @default undefined
109
- */
110
- searchControls?: AgentStudioSearchControls;
111
- }
112
14
  interface Memory {
113
15
  /**
114
16
  * Determines whether or not to display the memory based tool calls.
@@ -134,11 +36,6 @@ interface PromptSuggestions {
134
36
  hitsPerPage?: number;
135
37
  }
136
38
  interface DocSearchAskAi {
137
- /**
138
- * The index name to use for the Ask AI feature. Your assistant will search
139
- * for relevant documents. If not provided, the root index name will be used.
140
- */
141
- indexName?: string;
142
39
  /**
143
40
  * The API key to use for the ask AI feature. Your assistant will use this API
144
41
  * key to search the index. If not provided, the API key will be used.
@@ -149,8 +46,8 @@ interface DocSearchAskAi {
149
46
  * ID to search the index. If not provided, the app ID will be used.
150
47
  */
151
48
  appId?: string;
152
- /** The assistant ID to use for the ask AI feature. */
153
- assistantId: string;
49
+ /** The Agent Studio Agent ID to use for the Ask AI feature. */
50
+ agentId: string;
154
51
  /**
155
52
  * Enables displaying suggested questions on Ask AI's new conversation screen.
156
53
  *
@@ -167,8 +64,14 @@ interface DocSearchAskAi {
167
64
  * }
168
65
  */
169
66
  searchParameters?: AgentStudioSearchParameters;
170
- /** List of dynamic indices for the Agent Studio search tool to use. */
171
- indices?: AgentStudioIndices[];
67
+ /**
68
+ * Index names for the Agent Studio search tool on this request.
69
+ *
70
+ * Agent Studio expects names only. Put descriptions and tool defaults on the
71
+ * agent configuration. Put per-index runtime overrides in
72
+ * `searchParameters`.
73
+ */
74
+ indices?: string[];
172
75
  /**
173
76
  * Use custom tools driven by Agent Studio.
174
77
  *
@@ -214,7 +117,7 @@ interface DocSearchAIProps extends DocSearchProps {
214
117
  interceptAskAiEvent?: (initialMessage: InitialAskAiMessage) => boolean | void;
215
118
  }
216
119
  declare const DocSearchAI: React.ForwardRefExoticComponent<DocSearchAIProps & React.RefAttributes<DocSearchRef>>;
217
- declare function DocSearchAIInner(props: DocSearchAIProps): JSX.Element;
120
+ declare function DocSearchAIInner(props: Omit<DocSearchAIProps, 'appId' | 'apiKey'>): JSX.Element;
218
121
  //#endregion
219
- export { AgentStudioIndices, AgentStudioSearchControls, AgentStudioSearchParameters, AskAiSearchParameters, DocSearchAI, DocSearchAIInner, DocSearchAIProps, DocSearchAskAi, Memory, PromptSuggestions, type ToolCalls };
122
+ export { AgentStudioSearchParameters, AskAiSearchParameters, DocSearchAI, DocSearchAIInner, DocSearchAIProps, DocSearchAskAi, Memory, PromptSuggestions, type ToolCalls };
220
123
  //# sourceMappingURL=docsearchAi.d.ts.map
@@ -1,24 +1,34 @@
1
1
  import { t as _objectSpread2 } from "./objectSpread2-BNmiQYyW.js";
2
2
  import { t as DocSearchButton } from "./DocSearchButton-CaxxOzQU.js";
3
- import { t as DocSearchAskAiModal } from "./DocSearchAskAiModal-KaA6fBV4.js";
3
+ import { t as _objectWithoutProperties } from "./objectWithoutProperties-phqYxDS0.js";
4
+ import { t as DocSearchAskAiModal } from "./DocSearchAskAiModal-C_sH1j8Y.js";
4
5
  import { DocSearch, useDocSearch } from "@docsearch/core";
5
6
  import React from "react";
6
7
  import { createPortal } from "react-dom";
7
8
 
8
9
  //#region src/DocSearchAI.tsx
9
- function DocSearchAIComponent(props, ref) {
10
- return /* @__PURE__ */ React.createElement(DocSearch, _objectSpread2(_objectSpread2({}, props), {}, { ref }), /* @__PURE__ */ React.createElement(DocSearchAIInner, props));
10
+ const _excluded = ["appId", "apiKey"];
11
+ function DocSearchAIComponent(_ref, ref) {
12
+ let { appId, apiKey } = _ref, props = _objectWithoutProperties(_ref, _excluded);
13
+ return /* @__PURE__ */ React.createElement(DocSearch, _objectSpread2(_objectSpread2({}, props), {}, {
14
+ appId,
15
+ apiKey,
16
+ ref
17
+ }), /* @__PURE__ */ React.createElement(DocSearchAIInner, props));
11
18
  }
12
19
  const DocSearchAI = React.forwardRef(DocSearchAIComponent);
13
20
  function DocSearchAIInner(props) {
14
21
  var _props$translations, _props$translations2, _props$portalContaine;
15
- const { searchButtonRef, keyboardShortcuts, isModalActive, isAskAiActive, initialQuery, onAskAiToggle, openModal, closeModal, isHybridModeSupported } = useDocSearch();
22
+ const { searchButtonRef, keyboardShortcuts, isModalActive, isAskAiActive, initialQuery, onAskAiToggle, openModal, closeModal, isHybridModeSupported, appId, apiKey } = useDocSearch();
23
+ if (!appId || !apiKey) throw new Error("`DocSearchAI` requires `appId` and `apiKey` props.");
16
24
  return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(DocSearchButton, {
17
25
  keyboardShortcuts,
18
26
  ref: searchButtonRef,
19
27
  translations: (_props$translations = props.translations) === null || _props$translations === void 0 ? void 0 : _props$translations.button,
20
28
  onClick: openModal
21
29
  }), isModalActive && createPortal(/* @__PURE__ */ React.createElement(DocSearchAskAiModal, _objectSpread2(_objectSpread2({}, props), {}, {
30
+ appId,
31
+ apiKey,
22
32
  initialScrollY: window.scrollY,
23
33
  initialQuery,
24
34
  translations: props === null || props === void 0 || (_props$translations2 = props.translations) === null || _props$translations2 === void 0 ? void 0 : _props$translations2.modal,
@@ -1 +1 @@
1
- {"version":3,"file":"docsearchAi.js","names":["DocSearchProvider"],"sources":["../../src/DocSearchAI.tsx"],"sourcesContent":["import { DocSearch as DocSearchProvider, useDocSearch } from '@docsearch/core';\nimport type { DocSearchRef, InitialAskAiMessage } from '@docsearch/core';\nimport type { SearchParamsObject } from 'algoliasearch/lite';\nimport React, { type JSX } from 'react';\nimport { createPortal } from 'react-dom';\n\nimport type { DocSearchProps } from './DocSearch';\nimport { DocSearchAskAiModal } from './DocSearchAskAiModal';\nimport { DocSearchButton } from './DocSearchButton';\nimport type { ToolCalls } from './types/AskiAi';\n\nexport interface AskAiSearchParameters {\n facetFilters?: string[];\n filters?: string;\n attributesToRetrieve?: string[];\n restrictSearchableAttributes?: string[];\n distinct?: boolean | number | string;\n}\n\nexport type AgentStudioSearchParameters = Record<\n string,\n Omit<AskAiSearchParameters, 'facetFilters'>\n>;\n\ninterface IndexTextParam {\n exposed: boolean;\n default?: string;\n}\n\ninterface NumberConstraint {\n min?: number;\n max?: number;\n}\n\ninterface IndexNumberParam {\n exposed: boolean;\n default?: number;\n constraint?: NumberConstraint;\n}\n\ninterface StringArrayConstraints {\n values?: string[];\n}\n\ninterface IndexStringArrayParam {\n exposed: boolean;\n default?: string[];\n constraint?: StringArrayConstraints;\n merge?: boolean;\n}\n\ninterface IndexFacetParam {\n exposed: false;\n default?: string[];\n}\n\nexport interface AgentStudioSearchControls {\n /**\n * Augmented query for the MCP search tool to use.\n *\n * @default undefined\n */\n query?: IndexTextParam;\n /**\n * Number of hits for the MCP to return per page.\n *\n * @default { exposed: false, default: 7 }\n */\n hits_per_page?: IndexNumberParam;\n /**\n * The page number the MCP should pull results from.\n *\n * @default { exposed: false, default: 0 }\n */\n page?: IndexNumberParam;\n /**\n * List of attributes that the MCP can retrieve from the index.\n *\n * @default { exposed: false, default: ['*'] }\n */\n attributesToRetrieve?: IndexStringArrayParam;\n /**\n * List of fields that the MCP will return to the Agent.\n *\n * @default { exposed: false, default: [\"hits\", \"nbHits\", \"page\", \"nbPages\", \"hitsPerPage\", \"facets\"] }\n */\n responseFields?: IndexStringArrayParam;\n /**\n * Defined facets the MCP will use when querying the index.\n *\n * @default undefined\n */\n facets?: IndexFacetParam;\n /**\n * Any other custom properties the MCP should send when querying the index.\n *\n * @default undefined\n */\n custom?: Record<string, unknown>;\n}\n\nexport interface AgentStudioIndices {\n /** The name of the index used by the search tool. */\n index: string;\n /** A brief description for the search tool. */\n description: string;\n /**\n * A description used to steer the agent on how/when to use the search tool.\n *\n * @default ''\n */\n enhancedDescription?: string;\n /**\n * Default search parameters for the internal (non-MCP) search tool path.\n *\n * @default undefined\n */\n searchParameters?: SearchParamsObject;\n /**\n * Structured search parameters for the MCP-based search tool path.\n *\n * Each parameter controls whether it is exposed to the LLM and it's default\n * value.\n *\n * @default undefined\n */\n searchControls?: AgentStudioSearchControls;\n}\n\nexport interface Memory {\n /**\n * Determines whether or not to display the memory based tool calls.\n *\n * @default false\n */\n enabled?: boolean;\n /**\n * The JWT used by the agent to know which user's memory to read.\n *\n * @see https://www.algolia.com/doc/guides/algolia-ai/agent-studio/how-to/user-authentication\n */\n userToken?: string;\n}\n\nexport interface PromptSuggestions {\n /** The name of the index where the prompt suggestions are stored. */\n indexName: string;\n /**\n * The number of prompt suggestions that are retrieved and displayed.\n *\n * @default 3\n */\n hitsPerPage?: number;\n}\n\nexport interface DocSearchAskAi {\n /**\n * The index name to use for the Ask AI feature. Your assistant will search\n * for relevant documents. If not provided, the root index name will be used.\n */\n indexName?: string;\n /**\n * The API key to use for the ask AI feature. Your assistant will use this API\n * key to search the index. If not provided, the API key will be used.\n */\n apiKey?: string;\n /**\n * The app ID to use for the ask AI feature. Your assistant will use this app\n * ID to search the index. If not provided, the app ID will be used.\n */\n appId?: string;\n /** The assistant ID to use for the ask AI feature. */\n assistantId: string;\n /**\n * Enables displaying suggested questions on Ask AI's new conversation screen.\n *\n * @default false\n */\n suggestedQuestions?: boolean;\n /**\n * The search parameters to use for the ask AI feature. Keyed by the index\n * name.\n *\n * @example\n * {\n * \"INDEX_NAME\": { distinct: false }\n * }\n */\n searchParameters?: AgentStudioSearchParameters;\n /** List of dynamic indices for the Agent Studio search tool to use. */\n indices?: AgentStudioIndices[];\n /**\n * Use custom tools driven by Agent Studio.\n *\n * For best performance, memoize this object with `useMemo` or define it\n * outside the component. Inline object literals will be recreated every\n * render but will not affect correctness.\n */\n tools?: ToolCalls;\n /**\n * Configuration for the Agent Studio memory feature.\n *\n * @example\n * { enabled: true, userToken: '{{SERVER_GENERATED_JWT_TOKEN}}' }\n *\n * @see https://www.algolia.com/doc/guides/algolia-ai/agent-studio/how-to/memory/overview\n */\n memory?: Memory;\n /**\n * Enables and configures prompt suggestions that are displayed during keyword\n * search.\n *\n * @example\n * { indexName: 'docsearch-markdown_prompt_suggestions', hitsPerPage: 1 }\n *\n * @see https://www.algolia.com/doc/guides/algolia-ai/agent-studio/how-to/integration#prompt-suggestions\n */\n promptSuggestions?: PromptSuggestions;\n}\n\nexport interface DocSearchAIProps extends DocSearchProps {\n /**\n * Configuration or assistant id to enable ask ai mode. Pass a string\n * assistant id or a full config object.\n */\n askAi: DocSearchAskAi | string;\n /**\n * Intercept Ask AI requests (e.g. Submitting a prompt or selecting a\n * suggested question).\n *\n * Return `true` to prevent the default modal Ask AI flow (no toggle, no\n * sendMessage). Useful to route Ask AI into a different UI (e.g.\n * `@docsearch/sidepanel-js`) without flicker.\n */\n interceptAskAiEvent?: (initialMessage: InitialAskAiMessage) => boolean | void;\n}\n\nfunction DocSearchAIComponent(\n props: DocSearchAIProps,\n ref: React.ForwardedRef<DocSearchRef>\n): JSX.Element {\n return (\n <DocSearchProvider {...props} ref={ref}>\n <DocSearchAIInner {...props} />\n </DocSearchProvider>\n );\n}\n\nexport const DocSearchAI = React.forwardRef(DocSearchAIComponent);\n\nexport function DocSearchAIInner(props: DocSearchAIProps): JSX.Element {\n const {\n searchButtonRef,\n keyboardShortcuts,\n isModalActive,\n isAskAiActive,\n initialQuery,\n onAskAiToggle,\n openModal,\n closeModal,\n isHybridModeSupported,\n } = useDocSearch();\n\n return (\n <>\n <DocSearchButton\n keyboardShortcuts={keyboardShortcuts}\n ref={searchButtonRef}\n translations={props.translations?.button}\n onClick={openModal}\n />\n {isModalActive &&\n createPortal(\n <DocSearchAskAiModal\n {...props}\n initialScrollY={window.scrollY}\n initialQuery={initialQuery}\n translations={props?.translations?.modal}\n isAskAiActive={isAskAiActive}\n isHybridModeSupported={isHybridModeSupported}\n onAskAiToggle={onAskAiToggle}\n onClose={closeModal}\n />,\n props.portalContainer ?? document.body\n )}\n </>\n );\n}\n\nexport type { ToolCalls } from './types/AskiAi';\n"],"mappings":";;;;;;;;AA6OA,SAAS,qBACP,OACA,KACa;CACb,OACE,oCAACA,6CAAsB,cAAY,KAEhB,GADjB,oCAAC,kBAAqB,KAAQ,CACb;AAEvB;AAEA,MAAa,cAAc,MAAM,WAAW,oBAAoB;AAEhE,SAAgB,iBAAiB,OAAsC;;CACrE,MAAM,EACJ,iBACA,mBACA,eACA,eACA,cACA,eACA,WACA,YACA,0BACE,aAAa;CAEjB,OACE,0DACE,oCAAC,iBAAD;EACqB;EACnB,KAAK;EACL,qCAAc,MAAM,wFAAc;EAClC,SAAS;CACV,IACA,iBACC,aACE,oCAAC,uDACK;EACJ,gBAAgB,OAAO;EACT;EACd,4EAAc,MAAO,0FAAc;EACpB;EACQ;EACR;EACf,SAAS;EACV,6BACD,MAAM,wFAAmB,SAAS,IACpC,CACF;AAEN"}
1
+ {"version":3,"file":"docsearchAi.js","names":["DocSearchProvider"],"sources":["../../src/DocSearchAI.tsx"],"sourcesContent":["import { DocSearch as DocSearchProvider, useDocSearch } from '@docsearch/core';\nimport type { DocSearchRef, InitialAskAiMessage } from '@docsearch/core';\nimport React, { type JSX } from 'react';\nimport { createPortal } from 'react-dom';\n\nimport type { DocSearchProps } from './DocSearch';\nimport { DocSearchAskAiModal } from './DocSearchAskAiModal';\nimport { DocSearchButton } from './DocSearchButton';\nimport type { ToolCalls } from './types/AskiAi';\n\nexport interface AskAiSearchParameters {\n facetFilters?: string[];\n filters?: string;\n attributesToRetrieve?: string[];\n restrictSearchableAttributes?: string[];\n distinct?: boolean | number | string;\n}\n\nexport type AgentStudioSearchParameters = Record<\n string,\n Omit<AskAiSearchParameters, 'facetFilters'>\n>;\n\nexport interface Memory {\n /**\n * Determines whether or not to display the memory based tool calls.\n *\n * @default false\n */\n enabled?: boolean;\n /**\n * The JWT used by the agent to know which user's memory to read.\n *\n * @see https://www.algolia.com/doc/guides/algolia-ai/agent-studio/how-to/user-authentication\n */\n userToken?: string;\n}\n\nexport interface PromptSuggestions {\n /** The name of the index where the prompt suggestions are stored. */\n indexName: string;\n /**\n * The number of prompt suggestions that are retrieved and displayed.\n *\n * @default 3\n */\n hitsPerPage?: number;\n}\n\nexport interface DocSearchAskAi {\n /**\n * The API key to use for the ask AI feature. Your assistant will use this API\n * key to search the index. If not provided, the API key will be used.\n */\n apiKey?: string;\n /**\n * The app ID to use for the ask AI feature. Your assistant will use this app\n * ID to search the index. If not provided, the app ID will be used.\n */\n appId?: string;\n /** The Agent Studio Agent ID to use for the Ask AI feature. */\n agentId: string;\n /**\n * Enables displaying suggested questions on Ask AI's new conversation screen.\n *\n * @default false\n */\n suggestedQuestions?: boolean;\n /**\n * The search parameters to use for the ask AI feature. Keyed by the index\n * name.\n *\n * @example\n * {\n * \"INDEX_NAME\": { distinct: false }\n * }\n */\n searchParameters?: AgentStudioSearchParameters;\n /**\n * Index names for the Agent Studio search tool on this request.\n *\n * Agent Studio expects names only. Put descriptions and tool defaults on the\n * agent configuration. Put per-index runtime overrides in\n * `searchParameters`.\n */\n indices?: string[];\n /**\n * Use custom tools driven by Agent Studio.\n *\n * For best performance, memoize this object with `useMemo` or define it\n * outside the component. Inline object literals will be recreated every\n * render but will not affect correctness.\n */\n tools?: ToolCalls;\n /**\n * Configuration for the Agent Studio memory feature.\n *\n * @example\n * { enabled: true, userToken: '{{SERVER_GENERATED_JWT_TOKEN}}' }\n *\n * @see https://www.algolia.com/doc/guides/algolia-ai/agent-studio/how-to/memory/overview\n */\n memory?: Memory;\n /**\n * Enables and configures prompt suggestions that are displayed during keyword\n * search.\n *\n * @example\n * { indexName: 'docsearch-markdown_prompt_suggestions', hitsPerPage: 1 }\n *\n * @see https://www.algolia.com/doc/guides/algolia-ai/agent-studio/how-to/integration#prompt-suggestions\n */\n promptSuggestions?: PromptSuggestions;\n}\n\nexport interface DocSearchAIProps extends DocSearchProps {\n /**\n * Configuration or assistant id to enable ask ai mode. Pass a string\n * assistant id or a full config object.\n */\n askAi: DocSearchAskAi | string;\n /**\n * Intercept Ask AI requests (e.g. Submitting a prompt or selecting a\n * suggested question).\n *\n * Return `true` to prevent the default modal Ask AI flow (no toggle, no\n * sendMessage). Useful to route Ask AI into a different UI (e.g.\n * `@docsearch/sidepanel-js`) without flicker.\n */\n interceptAskAiEvent?: (initialMessage: InitialAskAiMessage) => boolean | void;\n}\n\nfunction DocSearchAIComponent(\n { appId, apiKey, ...props }: DocSearchAIProps,\n ref: React.ForwardedRef<DocSearchRef>\n): JSX.Element {\n return (\n <DocSearchProvider {...props} appId={appId} apiKey={apiKey} ref={ref}>\n <DocSearchAIInner {...props} />\n </DocSearchProvider>\n );\n}\n\nexport const DocSearchAI = React.forwardRef(DocSearchAIComponent);\n\nexport function DocSearchAIInner(\n props: Omit<DocSearchAIProps, 'appId' | 'apiKey'>\n): JSX.Element {\n const {\n searchButtonRef,\n keyboardShortcuts,\n isModalActive,\n isAskAiActive,\n initialQuery,\n onAskAiToggle,\n openModal,\n closeModal,\n isHybridModeSupported,\n appId,\n apiKey,\n } = useDocSearch();\n\n if (!appId || !apiKey) {\n throw new Error('`DocSearchAI` requires `appId` and `apiKey` props.');\n }\n\n return (\n <>\n <DocSearchButton\n keyboardShortcuts={keyboardShortcuts}\n ref={searchButtonRef}\n translations={props.translations?.button}\n onClick={openModal}\n />\n {isModalActive &&\n createPortal(\n <DocSearchAskAiModal\n {...props}\n appId={appId}\n apiKey={apiKey}\n initialScrollY={window.scrollY}\n initialQuery={initialQuery}\n translations={props?.translations?.modal}\n isAskAiActive={isAskAiActive}\n isHybridModeSupported={isHybridModeSupported}\n onAskAiToggle={onAskAiToggle}\n onClose={closeModal}\n />,\n props.portalContainer ?? document.body\n )}\n </>\n );\n}\n\nexport type { ToolCalls } from './types/AskiAi';\n"],"mappings":";;;;;;;;;mBAqII,SAAO;AADX,SAAS,qBACP,MACA,KACa;KAFb,EAAE,OAAO,iBAAW;CAGpB,OACE,oCAACA,6CAAsB;EAAc;EAAe;EAAa;EAE9C,GADjB,oCAAC,kBAAqB,KAAQ,CACb;AAEvB;AAEA,MAAa,cAAc,MAAM,WAAW,oBAAoB;AAEhE,SAAgB,iBACd,OACa;;CACb,MAAM,EACJ,iBACA,mBACA,eACA,eACA,cACA,eACA,WACA,YACA,uBACA,OACA,WACE,aAAa;CAEjB,IAAI,CAAC,SAAS,CAAC,QACb,MAAM,IAAI,MAAM,oDAAoD;CAGtE,OACE,0DACE,oCAAC,iBAAD;EACqB;EACnB,KAAK;EACL,qCAAc,MAAM,wFAAc;EAClC,SAAS;CACV,IACA,iBACC,aACE,oCAAC,uDACK;EACG;EACC;EACR,gBAAgB,OAAO;EACT;EACd,4EAAc,MAAO,0FAAc;EACpB;EACQ;EACR;EACf,SAAS;EACV,6BACD,MAAM,wFAAmB,SAAS,IACpC,CACF;AAEN"}
@@ -1,9 +1,9 @@
1
1
  import { a as StoredDocSearchHit, c as AskAiFeedbackReason, d as DocSearchHit, i as StoredAskAiState, l as OnAskAiFeedback, n as SuggestedQuestionHit, o as ToolCalls, r as StoredAskAiMessage, s as AskAiFeedbackPayload, t as SuggestedQuestion, u as DocSearchState } from "./index-Bqqv4HmN.js";
2
2
  import { t as DocSearchTheme } from "./DocSearchTheme-DvL4mf0D.js";
3
- import { a as DocSearchProps, c as DocSearchTranslations, d as ModalTranslations, i as DocSearchInner, l as DocSearchModal, n as DocSearchFacet, o as DocSearchRef, r as DocSearchIndex, s as DocSearchTransformClient, t as DocSearch, u as DocSearchModalProps, v as InternalDocSearchHit } from "./DocSearch-HJsNvtZr.js";
3
+ import { a as DocSearchProps, b as InternalDocSearchHit, c as DocSearchTranslations, d as DocSearchModal, f as DocSearchModalProps, i as DocSearchInner, l as HitComponentProps, n as DocSearchFacet, o as DocSearchRef, p as ModalTranslations, r as DocSearchIndex, s as DocSearchTransformClient, t as DocSearch, u as ResultsFooterComponentProps } from "./DocSearch-BVqxFxTw.js";
4
4
  import { n as useDocSearchKeyboardEvents, r as KeyboardShortcuts, t as UseDocSearchKeyboardEventsProps } from "./useDocSearchKeyboardEvents-u23fFhR9.js";
5
5
  import { n as DocSearchButton, r as DocSearchButtonProps, t as ButtonTranslations } from "./DocSearchButton-CZM_jACU.js";
6
- import { AgentStudioIndices, AgentStudioSearchControls, AgentStudioSearchParameters, AskAiSearchParameters, DocSearchAI, DocSearchAIInner, DocSearchAIProps, DocSearchAskAi, Memory, PromptSuggestions } from "./docsearchAi.js";
7
- import { n as DocSearchAskAiModalProps, r as DocSearchAskAiModalTranslations, t as DocSearchAskAiModal } from "./DocSearchAskAiModal-B7vpLudE.js";
6
+ import { AgentStudioSearchParameters, AskAiSearchParameters, DocSearchAI, DocSearchAIInner, DocSearchAIProps, DocSearchAskAi, Memory, PromptSuggestions } from "./docsearchAi.js";
7
+ import { n as DocSearchAskAiModalProps, r as DocSearchAskAiModalTranslations, t as DocSearchAskAiModal } from "./DocSearchAskAiModal-DpB7pLCC.js";
8
8
  import { version } from "./version.js";
9
- export { AgentStudioIndices, AgentStudioSearchControls, AgentStudioSearchParameters, AskAiFeedbackPayload, AskAiFeedbackReason, AskAiSearchParameters, ButtonTranslations, DocSearch, DocSearchAI, DocSearchAIInner, DocSearchAIProps, DocSearchAskAi, DocSearchAskAiModal, DocSearchAskAiModalProps, DocSearchAskAiModalTranslations, DocSearchButton, DocSearchButtonProps, DocSearchFacet, DocSearchHit, DocSearchIndex, DocSearchInner, DocSearchModal, DocSearchModalProps, DocSearchProps, type DocSearchRef, DocSearchState, DocSearchTheme, DocSearchTransformClient, DocSearchTranslations, InternalDocSearchHit, KeyboardShortcuts, Memory, ModalTranslations, OnAskAiFeedback, PromptSuggestions, StoredAskAiMessage, StoredAskAiState, StoredDocSearchHit, SuggestedQuestion, SuggestedQuestionHit, type ToolCalls, UseDocSearchKeyboardEventsProps, useDocSearchKeyboardEvents, version };
9
+ export { AgentStudioSearchParameters, AskAiFeedbackPayload, AskAiFeedbackReason, AskAiSearchParameters, ButtonTranslations, DocSearch, DocSearchAI, DocSearchAIInner, DocSearchAIProps, DocSearchAskAi, DocSearchAskAiModal, DocSearchAskAiModalProps, DocSearchAskAiModalTranslations, DocSearchButton, DocSearchButtonProps, DocSearchFacet, DocSearchHit, DocSearchIndex, DocSearchInner, DocSearchModal, DocSearchModalProps, DocSearchProps, type DocSearchRef, DocSearchState, DocSearchTheme, DocSearchTransformClient, DocSearchTranslations, HitComponentProps, InternalDocSearchHit, KeyboardShortcuts, Memory, ModalTranslations, OnAskAiFeedback, PromptSuggestions, ResultsFooterComponentProps, StoredAskAiMessage, StoredAskAiState, StoredDocSearchHit, SuggestedQuestion, SuggestedQuestionHit, type ToolCalls, UseDocSearchKeyboardEventsProps, useDocSearchKeyboardEvents, version };
package/dist/esm/index.js CHANGED
@@ -1,7 +1,8 @@
1
1
  import { t as _objectSpread2 } from "./objectSpread2-BNmiQYyW.js";
2
2
  import { t as DocSearchButton } from "./DocSearchButton-CaxxOzQU.js";
3
- import { t as DocSearchAskAiModal } from "./DocSearchAskAiModal-KaA6fBV4.js";
4
- import { t as DocSearchModal } from "./DocSearchModal-CpvDjo1O.js";
3
+ import { t as _objectWithoutProperties } from "./objectWithoutProperties-phqYxDS0.js";
4
+ import { t as DocSearchAskAiModal } from "./DocSearchAskAiModal-C_sH1j8Y.js";
5
+ import { t as DocSearchModal } from "./DocSearchModal-CITTG0fe.js";
5
6
  import { version } from "./version.js";
6
7
  import { DocSearchAI, DocSearchAIInner } from "./docsearchAi.js";
7
8
  import { useDocSearchKeyboardEvents } from "./useDocSearchKeyboardEvents.js";
@@ -10,19 +11,28 @@ import React from "react";
10
11
  import { createPortal } from "react-dom";
11
12
 
12
13
  //#region src/DocSearch.tsx
13
- function DocSearchComponent(props, ref) {
14
- return /* @__PURE__ */ React.createElement(DocSearch$1, _objectSpread2(_objectSpread2({}, props), {}, { ref }), /* @__PURE__ */ React.createElement(DocSearchInner, props));
14
+ const _excluded = ["appId", "apiKey"];
15
+ function DocSearchComponent(_ref, ref) {
16
+ let { appId, apiKey } = _ref, props = _objectWithoutProperties(_ref, _excluded);
17
+ return /* @__PURE__ */ React.createElement(DocSearch$1, _objectSpread2(_objectSpread2({}, props), {}, {
18
+ appId,
19
+ apiKey,
20
+ ref
21
+ }), /* @__PURE__ */ React.createElement(DocSearchInner, props));
15
22
  }
16
23
  const DocSearch = React.forwardRef(DocSearchComponent);
17
24
  function DocSearchInner(props) {
18
25
  var _props$translations, _props$translations2, _props$portalContaine;
19
- const { searchButtonRef, keyboardShortcuts, isModalActive, initialQuery, openModal, closeModal } = useDocSearch();
26
+ const { searchButtonRef, keyboardShortcuts, isModalActive, initialQuery, openModal, closeModal, appId, apiKey } = useDocSearch();
27
+ if (!appId || !apiKey) throw new Error("`DocSearch` requires `appId` and `apiKey` props.");
20
28
  return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(DocSearchButton, {
21
29
  keyboardShortcuts,
22
30
  ref: searchButtonRef,
23
31
  translations: (_props$translations = props.translations) === null || _props$translations === void 0 ? void 0 : _props$translations.button,
24
32
  onClick: openModal
25
33
  }), isModalActive && createPortal(/* @__PURE__ */ React.createElement(DocSearchModal, _objectSpread2(_objectSpread2({}, props), {}, {
34
+ appId,
35
+ apiKey,
26
36
  initialScrollY: window.scrollY,
27
37
  initialQuery,
28
38
  translations: props === null || props === void 0 || (_props$translations2 = props.translations) === null || _props$translations2 === void 0 ? void 0 : _props$translations2.modal,
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["DocSearchProvider"],"sources":["../../src/DocSearch.tsx"],"sourcesContent":["import type {\n AutocompleteOptions,\n AutocompleteState,\n} from '@algolia/autocomplete-core';\nimport { DocSearch as DocSearchProvider, useDocSearch } from '@docsearch/core';\nimport type { DocSearchModalShortcuts, DocSearchRef } from '@docsearch/core';\nimport type { LiteClient, SearchParamsObject } from 'algoliasearch/lite';\nimport React, { type JSX } from 'react';\nimport { createPortal } from 'react-dom';\n\nimport { DocSearchButton } from './DocSearchButton';\nimport type { ButtonTranslations } from './DocSearchButton';\nimport { DocSearchModal } from './DocSearchModal';\nimport type { ModalTranslations } from './DocSearchModal';\nimport type {\n DocSearchHit,\n DocSearchTheme,\n InternalDocSearchHit,\n StoredDocSearchHit,\n} from './types';\n\nexport type { DocSearchRef } from '@docsearch/core';\n\nexport type DocSearchTranslations = Partial<{\n button: ButtonTranslations;\n modal: ModalTranslations;\n}>;\n\n// The interface that describes the minimal implementation required for the algoliasearch client, when using the [`transformSearchClient`](https://docsearch.algolia.com/docs/api/#transformsearchclient) option.\nexport type DocSearchTransformClient = {\n search: LiteClient['search'];\n addAlgoliaAgent: LiteClient['addAlgoliaAgent'];\n transporter: Pick<LiteClient['transporter'], 'algoliaAgent'>;\n};\n\nexport interface DocSearchIndex {\n name: string;\n searchParameters?: SearchParamsObject;\n}\n\nexport interface DocSearchFacet {\n key: string;\n label?: string;\n}\n\nexport interface DocSearchProps {\n /** Algolia application id used by the search client. */\n appId: string;\n /** Public api key with search permissions for the index. */\n apiKey: string;\n /**\n * Name of the algolia index to query.\n *\n * @deprecated `indexName` will be removed in a future version. Please use\n * `indices` property going forward.\n */\n indexName?: string;\n /**\n * List of indices and _optional_ searchParameters to be used for search.\n *\n * @see {@link https://docsearch.algolia.com/docs/api#indices}\n */\n indices?: Array<DocSearchIndex | string>;\n /**\n * Facets to display as keyword-search filter controls. Values are read\n * dynamically from the configured Algolia indices.\n *\n * @default [ ]\n */\n facets?: DocSearchFacet[];\n /** Theme overrides applied to the modal and related components. */\n theme?: DocSearchTheme;\n /** Placeholder text for the search input. */\n placeholder?: string;\n /**\n * Additional algolia search parameters to merge into each query.\n *\n * @deprecated `searchParameters` will be removed in a future version. Please\n * use `indices` property going forward.\n */\n searchParameters?: SearchParamsObject;\n /** Maximum number of hits to display per source/group. */\n maxResultsPerGroup?: number;\n /** Hook to post-process hits before rendering. */\n transformItems?: (items: DocSearchHit[]) => DocSearchHit[];\n /**\n * Custom component to render an individual hit. Supports template patterns:\n *\n * - HTML strings with html helper: (props, { html }) => html`<div>...</div>`\n * - JSX templates: (props) => <div>...</div>\n * - Function-based templates: (props) => string | JSX.Element | Function.\n */\n hitComponent?: (\n props: {\n hit: InternalDocSearchHit | StoredDocSearchHit;\n children: React.ReactNode;\n },\n helpers?: {\n html: (template: TemplateStringsArray, ...values: any[]) => any;\n }\n ) => JSX.Element;\n /**\n * Custom component rendered at the bottom of the results panel. Supports\n * template patterns:\n *\n * - HTML strings with html helper: (props, { html }) => html`<div>...</div>`\n * - JSX templates: (props) => <div>...</div>\n * - Function-based templates: (props) => string | JSX.Element | Function.\n */\n resultsFooterComponent?: (\n props: {\n state: AutocompleteState<InternalDocSearchHit>;\n },\n helpers?: {\n html: (template: TemplateStringsArray, ...values: any[]) => any;\n }\n ) => JSX.Element | null;\n /** Hook to wrap or modify the algolia search client. */\n transformSearchClient?: (\n searchClient: DocSearchTransformClient\n ) => DocSearchTransformClient;\n /** Disable storage and usage of recent and favorite searches. */\n disableUserPersonalization?: boolean;\n /** Query string to prefill when opening the modal. */\n initialQuery?: string;\n /** Custom navigator for controlling link navigation. */\n navigator?: AutocompleteOptions<InternalDocSearchHit>['navigator'];\n /** Localized strings for the button and modal ui. */\n translations?: DocSearchTranslations;\n /** Builds a url to report missing results for a given query. */\n getMissingResultsUrl?: ({ query }: { query: string }) => string;\n /** Insights client integration options to send analytics events. */\n insights?: AutocompleteOptions<InternalDocSearchHit>['insights'];\n /**\n * The container element where the modal should be portaled to. Defaults to\n * document.body.\n */\n portalContainer?: DocumentFragment | Element;\n /**\n * Limit of how many recent searches should be saved/displayed..\n *\n * @default 7\n */\n recentSearchesLimit?: number;\n /**\n * Limit of how many recent searches should be saved/displayed when there are\n * favorited searches..\n *\n * @default 4\n */\n recentSearchesWithFavoritesLimit?: number;\n /**\n * Configuration for keyboard shortcuts. Allows enabling/disabling specific\n * shortcuts.\n *\n * @default `{ 'Ctrl/Cmd+K': true, '/': true }`\n */\n keyboardShortcuts?: DocSearchModalShortcuts;\n /**\n * The key used to render a custom badge for each hit. Key must match a\n * property returned in `searchParameters.attributesToRetrieve`.\n *\n * @example\n * 'version';\n * 'hierarchy.lvl1';\n * 'tags[2]';\n *\n * @default undefined\n */\n resultBadgeKey?: string;\n}\n\nfunction DocSearchComponent(\n props: DocSearchProps,\n ref: React.ForwardedRef<DocSearchRef>\n): JSX.Element {\n return (\n <DocSearchProvider {...props} ref={ref}>\n <DocSearchInner {...props} />\n </DocSearchProvider>\n );\n}\n\nexport const DocSearch = React.forwardRef(DocSearchComponent);\n\nexport function DocSearchInner(props: DocSearchProps): JSX.Element {\n const {\n searchButtonRef,\n keyboardShortcuts,\n isModalActive,\n initialQuery,\n openModal,\n closeModal,\n } = useDocSearch();\n\n return (\n <>\n <DocSearchButton\n keyboardShortcuts={keyboardShortcuts}\n ref={searchButtonRef}\n translations={props.translations?.button}\n onClick={openModal}\n />\n {isModalActive &&\n createPortal(\n <DocSearchModal\n {...props}\n initialScrollY={window.scrollY}\n initialQuery={initialQuery}\n translations={props?.translations?.modal}\n onClose={closeModal}\n />,\n props.portalContainer ?? document.body\n )}\n </>\n );\n}\n"],"mappings":";;;;;;;;;;;;AA4KA,SAAS,mBACP,OACA,KACa;CACb,OACE,oCAACA,+CAAsB,cAAY,KAEhB,GADjB,oCAAC,gBAAmB,KAAQ,CACX;AAEvB;AAEA,MAAa,YAAY,MAAM,WAAW,kBAAkB;AAE5D,SAAgB,eAAe,OAAoC;;CACjE,MAAM,EACJ,iBACA,mBACA,eACA,cACA,WACA,eACE,aAAa;CAEjB,OACE,0DACE,oCAAC,iBAAD;EACqB;EACnB,KAAK;EACL,qCAAc,MAAM,wFAAc;EAClC,SAAS;CACV,IACA,iBACC,aACE,oCAAC,kDACK;EACJ,gBAAgB,OAAO;EACT;EACd,4EAAc,MAAO,0FAAc;EACnC,SAAS;EACV,6BACD,MAAM,wFAAmB,SAAS,IACpC,CACF;AAEN"}
1
+ {"version":3,"file":"index.js","names":["DocSearchProvider"],"sources":["../../src/DocSearch.tsx"],"sourcesContent":["import type {\n AutocompleteOptions,\n AutocompleteState,\n} from '@algolia/autocomplete-core';\nimport { DocSearch as DocSearchProvider, useDocSearch } from '@docsearch/core';\nimport type { DocSearchModalShortcuts, DocSearchRef } from '@docsearch/core';\nimport type { LiteClient, SearchParamsObject } from 'algoliasearch/lite';\nimport React, { type JSX } from 'react';\nimport { createPortal } from 'react-dom';\n\nimport { DocSearchButton } from './DocSearchButton';\nimport type { ButtonTranslations } from './DocSearchButton';\nimport { DocSearchModal } from './DocSearchModal';\nimport type { ModalTranslations } from './DocSearchModal';\nimport type {\n DocSearchHit,\n DocSearchTheme,\n InternalDocSearchHit,\n StoredDocSearchHit,\n} from './types';\n\nexport type { DocSearchRef } from '@docsearch/core';\n\nexport type DocSearchTranslations = Partial<{\n button: ButtonTranslations;\n modal: ModalTranslations;\n}>;\n\n// The interface that describes the minimal implementation required for the algoliasearch client, when using the [`transformSearchClient`](https://docsearch.algolia.com/docs/api/#transformsearchclient) option.\nexport type DocSearchTransformClient = {\n search: LiteClient['search'];\n addAlgoliaAgent: LiteClient['addAlgoliaAgent'];\n transporter: Pick<LiteClient['transporter'], 'algoliaAgent'>;\n};\n\nexport interface DocSearchIndex {\n name: string;\n searchParameters?: SearchParamsObject;\n}\n\nexport interface DocSearchFacet {\n key: string;\n label?: string;\n}\n\nexport interface HitComponentProps {\n hit: InternalDocSearchHit | StoredDocSearchHit;\n children: React.ReactNode;\n}\n\nexport interface ResultsFooterComponentProps {\n state: AutocompleteState<InternalDocSearchHit>;\n}\n\nexport interface DocSearchProps {\n /** Algolia application id used by the search client. */\n appId: string;\n /** Public api key with search permissions for the index. */\n apiKey: string;\n /**\n * List of indices and _optional_ searchParameters to be used for search.\n *\n * @see {@link https://docsearch.algolia.com/docs/api#indices}\n */\n indices: Array<DocSearchIndex | string>;\n /**\n * Facets to display as keyword-search filter controls. Values are read\n * dynamically from the configured Algolia indices.\n *\n * @default [ ]\n */\n facets?: DocSearchFacet[];\n /** Theme overrides applied to the modal and related components. */\n theme?: DocSearchTheme;\n /** Placeholder text for the search input. */\n placeholder?: string;\n /** Maximum number of hits to display per source/group. */\n maxResultsPerGroup?: number;\n /** Hook to post-process hits before rendering. */\n transformItems?: (items: DocSearchHit[]) => DocSearchHit[];\n /** Custom component to render an individual hit. */\n hitComponent?: (props: HitComponentProps) => JSX.Element;\n /** Custom component rendered at the bottom of the results panel. */\n resultsFooterComponent?: (\n props: ResultsFooterComponentProps\n ) => JSX.Element | null;\n /**\n * A custom action that can be rendered in the Modal's footer before the\n * Algolia logo. The component will be rendered as a child of `<div\n * className=\"DocSearch-Footer-Action\" />`.\n */\n footerAction?: React.ReactNode;\n /** Hook to wrap or modify the algolia search client. */\n transformSearchClient?: (\n searchClient: DocSearchTransformClient\n ) => DocSearchTransformClient;\n /** Disable storage and usage of recent and favorite searches. */\n disableUserPersonalization?: boolean;\n /** Query string to prefill when opening the modal. */\n initialQuery?: string;\n /** Custom navigator for controlling link navigation. */\n navigator?: AutocompleteOptions<InternalDocSearchHit>['navigator'];\n /** Localized strings for the button and modal ui. */\n translations?: DocSearchTranslations;\n /** Builds a url to report missing results for a given query. */\n getMissingResultsUrl?: ({ query }: { query: string }) => string;\n /** Insights client integration options to send analytics events. */\n insights?: AutocompleteOptions<InternalDocSearchHit>['insights'];\n /**\n * The container element where the modal should be portaled to. Defaults to\n * document.body.\n */\n portalContainer?: DocumentFragment | Element;\n /**\n * Limit of how many recent searches should be saved/displayed..\n *\n * @default 7\n */\n recentSearchesLimit?: number;\n /**\n * Limit of how many recent searches should be saved/displayed when there are\n * favorited searches..\n *\n * @default 4\n */\n recentSearchesWithFavoritesLimit?: number;\n /**\n * Configuration for keyboard shortcuts. Allows enabling/disabling specific\n * shortcuts.\n *\n * @default `{ 'Ctrl/Cmd+K': true, '/': true }`\n */\n keyboardShortcuts?: DocSearchModalShortcuts;\n /**\n * The key used to render a custom badge for each hit. Key must match a\n * property returned in `searchParameters.attributesToRetrieve`.\n *\n * @example\n * 'version';\n * 'hierarchy.lvl1';\n * 'tags[2]';\n *\n * @default undefined\n */\n resultBadgeKey?: string;\n}\n\nfunction DocSearchComponent(\n { appId, apiKey, ...props }: DocSearchProps,\n ref: React.ForwardedRef<DocSearchRef>\n): JSX.Element {\n return (\n <DocSearchProvider {...props} appId={appId} apiKey={apiKey} ref={ref}>\n <DocSearchInner {...props} />\n </DocSearchProvider>\n );\n}\n\nexport const DocSearch = React.forwardRef(DocSearchComponent);\n\nexport function DocSearchInner(\n props: Omit<DocSearchProps, 'appId' | 'apiKey'>\n): JSX.Element {\n const {\n searchButtonRef,\n keyboardShortcuts,\n isModalActive,\n initialQuery,\n openModal,\n closeModal,\n appId,\n apiKey,\n } = useDocSearch();\n\n if (!appId || !apiKey) {\n throw new Error('`DocSearch` requires `appId` and `apiKey` props.');\n }\n\n return (\n <>\n <DocSearchButton\n keyboardShortcuts={keyboardShortcuts}\n ref={searchButtonRef}\n translations={props.translations?.button}\n onClick={openModal}\n />\n {isModalActive &&\n createPortal(\n <DocSearchModal\n {...props}\n appId={appId}\n apiKey={apiKey}\n initialScrollY={window.scrollY}\n initialQuery={initialQuery}\n translations={props?.translations?.modal}\n onClose={closeModal}\n />,\n props.portalContainer ?? document.body\n )}\n </>\n );\n}\n"],"mappings":";;;;;;;;;;;;;mBAoJI,SAAO;AADX,SAAS,mBACP,MACA,KACa;KAFb,EAAE,OAAO,iBAAW;CAGpB,OACE,oCAACA,+CAAsB;EAAc;EAAe;EAAa;EAE9C,GADjB,oCAAC,gBAAmB,KAAQ,CACX;AAEvB;AAEA,MAAa,YAAY,MAAM,WAAW,kBAAkB;AAE5D,SAAgB,eACd,OACa;;CACb,MAAM,EACJ,iBACA,mBACA,eACA,cACA,WACA,YACA,OACA,WACE,aAAa;CAEjB,IAAI,CAAC,SAAS,CAAC,QACb,MAAM,IAAI,MAAM,kDAAkD;CAGpE,OACE,0DACE,oCAAC,iBAAD;EACqB;EACnB,KAAK;EACL,qCAAc,MAAM,wFAAc;EAClC,SAAS;CACV,IACA,iBACC,aACE,oCAAC,kDACK;EACG;EACC;EACR,gBAAgB,OAAO;EACT;EACd,4EAAc,MAAO,0FAAc;EACnC,SAAS;EACV,6BACD,MAAM,wFAAmB,SAAS,IACpC,CACF;AAEN"}
@@ -1,2 +1,2 @@
1
- import { d as ModalTranslations, l as DocSearchModal, u as DocSearchModalProps } from "./DocSearch-HJsNvtZr.js";
1
+ import { d as DocSearchModal, f as DocSearchModalProps, p as ModalTranslations } from "./DocSearch-BVqxFxTw.js";
2
2
  export { DocSearchModal, DocSearchModalProps, ModalTranslations };
package/dist/esm/modal.js CHANGED
@@ -1,3 +1,3 @@
1
- import { t as DocSearchModal } from "./DocSearchModal-CpvDjo1O.js";
1
+ import { t as DocSearchModal } from "./DocSearchModal-CITTG0fe.js";
2
2
 
3
3
  export { DocSearchModal };