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

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 (35) hide show
  1. package/README.md +1 -1
  2. package/dist/esm/{AskAiScreenState-CRHicWbN.d.ts → AskAiScreenState-Bw2WIgv_.d.ts} +5 -2
  3. package/dist/esm/{DocSearch-HJsNvtZr.d.ts → DocSearch-CVj6U-nI.d.ts} +4 -18
  4. package/dist/esm/{DocSearchAskAiModal-KaA6fBV4.js → DocSearchAskAiModal-BczGFkvR.js} +26 -33
  5. package/dist/esm/DocSearchAskAiModal-BczGFkvR.js.map +1 -0
  6. package/dist/esm/{DocSearchAskAiModal-B7vpLudE.d.ts → DocSearchAskAiModal-MF2py4NM.d.ts} +4 -4
  7. package/dist/esm/{DocSearchModal-CpvDjo1O.js → DocSearchModal-D_tfhoN1.js} +13 -21
  8. package/dist/esm/DocSearchModal-D_tfhoN1.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 +4 -9
  12. package/dist/esm/docsearchAi.js +14 -4
  13. package/dist/esm/docsearchAi.js.map +1 -1
  14. package/dist/esm/index.d.ts +2 -2
  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-D8P3VEXa.js} +90 -55
  20. package/dist/esm/normalizeDocSearchIndexes-D8P3VEXa.js.map +1 -0
  21. package/dist/esm/sidepanel.d.ts +14 -22
  22. package/dist/esm/sidepanel.js +14 -11
  23. package/dist/esm/sidepanel.js.map +1 -1
  24. package/dist/esm/{useSuggestedQuestions-CG2H3qm4.js → useSuggestedQuestions-Ds7H1JCr.js} +36 -26
  25. package/dist/esm/useSuggestedQuestions-Ds7H1JCr.js.map +1 -0
  26. package/dist/esm/version.d.ts +1 -1
  27. package/dist/esm/version.js +1 -1
  28. package/dist/esm/version.js.map +1 -1
  29. package/dist/umd/index.js +43 -41
  30. package/dist/umd/index.js.map +1 -1
  31. package/package.json +4 -4
  32. package/dist/esm/DocSearchAskAiModal-KaA6fBV4.js.map +0 -1
  33. package/dist/esm/DocSearchModal-CpvDjo1O.js.map +0 -1
  34. package/dist/esm/normalizeDocSearchIndexes-DAzlMybx.js.map +0 -1
  35. 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-D8P3VEXa.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,8 +78,6 @@ const _excluded = [
76
78
  "recentSearchesLimit",
77
79
  "recentSearchesWithFavoritesLimit",
78
80
  "indices",
79
- "indexName",
80
- "searchParameters",
81
81
  "facets"
82
82
  ];
83
83
  const _excluded2 = [
@@ -87,7 +87,7 @@ const _excluded2 = [
87
87
  ];
88
88
  function DocSearchModal(_ref) {
89
89
  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);
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, facets } = _ref, props = _objectWithoutProperties(_ref, _excluded);
91
91
  const { footer: footerTranslations, searchBox: searchBoxTranslations, facets: facetBarTranslations } = translations, screenStateTranslations = _objectWithoutProperties(translations, _excluded2);
92
92
  const [state, setState] = React.useState({
93
93
  query: "",
@@ -102,15 +102,7 @@ function DocSearchModal(_ref) {
102
102
  const { containerRef, modalRef, formElementRef, dropdownRef, inputRef, snippetLength } = useModalRefs();
103
103
  const { initialQuery, initialQueryFromSelection } = useInitialModalQuery(initialQueryFromProp);
104
104
  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
- ]);
105
+ const indexes = React.useMemo(() => normalizeDocSearchIndexes({ indices }), [indices]);
114
106
  const defaultIndexName = indexes[0].name;
115
107
  const autocompleteRef = React.useRef(void 0);
116
108
  const { visibleFacets, facetSelections, facetSelectionsRef, handleFacetSelectionChange, clearFacetSelections } = useDocSearchFacets({
@@ -147,7 +139,7 @@ function DocSearchModal(_ref) {
147
139
  setState(changes.state);
148
140
  },
149
141
  getSources({ query, state: sourcesState, setContext, setStatus }) {
150
- if (!query) return buildNoQuerySources({
142
+ if (isQueryEmpty(query)) return buildNoQuerySources({
151
143
  recentSearches,
152
144
  favoriteSearches,
153
145
  saveRecentSearch,
@@ -196,7 +188,7 @@ function DocSearchModal(_ref) {
196
188
  });
197
189
  let showDocsearchDropdown = true;
198
190
  const hasCollections = state.collections.some((collection) => collection.items.length > 0);
199
- if (state.status === "idle" && hasCollections === false && state.query.length === 0) showDocsearchDropdown = false;
191
+ if (state.status === "idle" && hasCollections === false && isQueryEmpty(state.query)) showDocsearchDropdown = false;
200
192
  return /* @__PURE__ */ React.createElement(ModalShell, {
201
193
  state,
202
194
  containerRef,
@@ -208,13 +200,13 @@ function DocSearchModal(_ref) {
208
200
  searchBox: /* @__PURE__ */ React.createElement(KeywordSearchBox, _objectSpread2(_objectSpread2({}, autocomplete), {}, {
209
201
  state,
210
202
  placeholder: placeholder || "Search docs",
211
- autoFocus: initialQuery.length === 0,
203
+ autoFocus: isQueryEmpty(initialQuery),
212
204
  inputRef,
213
205
  isFromSelection: Boolean(initialQuery) && initialQuery === initialQueryFromSelection,
214
206
  translations: searchBoxTranslations,
215
207
  onClose
216
208
  })),
217
- filterBar: state.query !== "" ? /* @__PURE__ */ React.createElement(FacetBar, {
209
+ filterBar: !isQueryEmpty(state.query) ? /* @__PURE__ */ React.createElement(FacetBar, {
218
210
  facets: visibleFacets,
219
211
  selections: facetSelections,
220
212
  translations: facetBarTranslations,
@@ -247,4 +239,4 @@ function DocSearchModal(_ref) {
247
239
 
248
240
  //#endregion
249
241
  export { DocSearchModal as t };
250
- //# sourceMappingURL=DocSearchModal-CpvDjo1O.js.map
242
+ //# sourceMappingURL=DocSearchModal-D_tfhoN1.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DocSearchModal-D_tfhoN1.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 ...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 {\n containerRef,\n modalRef,\n formElementRef,\n dropdownRef,\n inputRef,\n snippetLength,\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 snippetLength,\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 snippetLength,\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={<Footer translations={footerTranslations} />}\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-MF2py4NM.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-BczGFkvR.js";
2
2
 
3
3
  export { DocSearchAskAiModal };
@@ -1,5 +1,5 @@
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-CVj6U-nI.js";
3
3
  import { DocSearchRef, InitialAskAiMessage } from "@docsearch/core";
4
4
  import React, { JSX } from "react";
5
5
  import { SearchParamsObject } from "algoliasearch/lite";
@@ -134,11 +134,6 @@ interface PromptSuggestions {
134
134
  hitsPerPage?: number;
135
135
  }
136
136
  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
137
  /**
143
138
  * The API key to use for the ask AI feature. Your assistant will use this API
144
139
  * key to search the index. If not provided, the API key will be used.
@@ -149,8 +144,8 @@ interface DocSearchAskAi {
149
144
  * ID to search the index. If not provided, the app ID will be used.
150
145
  */
151
146
  appId?: string;
152
- /** The assistant ID to use for the ask AI feature. */
153
- assistantId: string;
147
+ /** The Agent Studio Agent ID to use for the Ask AI feature. */
148
+ agentId: string;
154
149
  /**
155
150
  * Enables displaying suggested questions on Ask AI's new conversation screen.
156
151
  *
@@ -214,7 +209,7 @@ interface DocSearchAIProps extends DocSearchProps {
214
209
  interceptAskAiEvent?: (initialMessage: InitialAskAiMessage) => boolean | void;
215
210
  }
216
211
  declare const DocSearchAI: React.ForwardRefExoticComponent<DocSearchAIProps & React.RefAttributes<DocSearchRef>>;
217
- declare function DocSearchAIInner(props: DocSearchAIProps): JSX.Element;
212
+ declare function DocSearchAIInner(props: Omit<DocSearchAIProps, 'appId' | 'apiKey'>): JSX.Element;
218
213
  //#endregion
219
214
  export { AgentStudioIndices, AgentStudioSearchControls, AgentStudioSearchParameters, AskAiSearchParameters, DocSearchAI, DocSearchAIInner, DocSearchAIProps, DocSearchAskAi, Memory, PromptSuggestions, type ToolCalls };
220
215
  //# 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-BczGFkvR.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 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 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 /** 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 { appId, apiKey, ...props }: DocSearchAIProps,\n ref: React.ForwardedRef<DocSearchRef>\n): JSX.Element {\n return (\n <DocSearchProvider\n {...props}\n appId={appId}\n apiKey={apiKey}\n ref={ref}\n >\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":";;;;;;;;;mBAyOI,SAAO;AADX,SAAS,qBACP,MACA,KACa;KAFb,EAAE,OAAO,iBAAW;CAGpB,OACE,oCAACA,6CACK;EACG;EACC;EACH;EAGY,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, 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-CVj6U-nI.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
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";
7
+ import { n as DocSearchAskAiModalProps, r as DocSearchAskAiModalTranslations, t as DocSearchAskAiModal } from "./DocSearchAskAiModal-MF2py4NM.js";
8
8
  import { version } from "./version.js";
9
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 };
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-BczGFkvR.js";
5
+ import { t as DocSearchModal } from "./DocSearchModal-D_tfhoN1.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 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 /**\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 { 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":";;;;;;;;;;;;;mBA+JI,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 ModalTranslations, l as DocSearchModal, u as DocSearchModalProps } from "./DocSearch-CVj6U-nI.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-D_tfhoN1.js";
2
2
 
3
3
  export { DocSearchModal };