@docusaurus/theme-search-algolia 3.9.1 → 3.9.2-alpha.0

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.
@@ -43,7 +43,7 @@ export function useAlgoliaAskAi(props) {
43
43
  setIsAskAiActive(askAiToggle);
44
44
  }, []);
45
45
  const extraAskAiProps = {
46
- askAi,
46
+ askAi: askAi,
47
47
  canHandleAskAi,
48
48
  isAskAiActive,
49
49
  onAskAiToggle,
@@ -27,7 +27,7 @@ export function useSearchResultUrlProcessor() {
27
27
  return url;
28
28
  }
29
29
  // Otherwise => transform to relative URL for SPA navigation
30
- const relativeUrl = `${parsedURL.pathname + parsedURL.hash}`;
30
+ const relativeUrl = `${parsedURL.pathname}${parsedURL.search}${parsedURL.hash}`;
31
31
  return withBaseUrl(replacePathname(relativeUrl, replaceSearchResultPathname));
32
32
  }, [withBaseUrl, externalUrlRegex, replaceSearchResultPathname]);
33
33
  }
@@ -5,4 +5,20 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
  import { type ReactNode } from 'react';
8
- export default function SearchBar(): ReactNode;
8
+ import type { DocSearchModalProps, DocSearchTranslations } from '@docsearch/react';
9
+ import type { ThemeConfigAlgolia } from '@docusaurus/theme-search-algolia';
10
+ type DocSearchProps = Omit<DocSearchModalProps, 'onClose' | 'initialScrollY'> & {
11
+ contextualSearch?: string;
12
+ externalUrlRegex?: string;
13
+ searchPagePath: boolean | string;
14
+ askAi?: Exclude<(DocSearchModalProps & {
15
+ askAi: unknown;
16
+ })['askAi'], string | undefined>;
17
+ };
18
+ interface DocSearchV4Props extends Omit<DocSearchProps, 'askAi'> {
19
+ indexName: string;
20
+ askAi?: ThemeConfigAlgolia['askAi'];
21
+ translations?: DocSearchTranslations;
22
+ }
23
+ export default function SearchBar(props: Partial<DocSearchV4Props>): ReactNode;
24
+ export {};
@@ -217,7 +217,13 @@ function DocSearch({externalUrlRegex, ...props}) {
217
217
  </>
218
218
  );
219
219
  }
220
- export default function SearchBar() {
220
+ export default function SearchBar(props) {
221
221
  const {siteConfig} = useDocusaurusContext();
222
- return <DocSearch {...siteConfig.themeConfig.algolia} />;
222
+ const docSearchProps = {
223
+ ...siteConfig.themeConfig.algolia,
224
+ // Let props override theme config
225
+ // See https://github.com/facebook/docusaurus/pull/11581
226
+ ...props,
227
+ };
228
+ return <DocSearch {...docSearchProps} />;
223
229
  }
@@ -58,13 +58,15 @@ exports.Schema = utils_validation_1.Joi.object({
58
58
  utils_validation_1.Joi.string(),
59
59
  // Full configuration object
60
60
  utils_validation_1.Joi.object({
61
- indexName: utils_validation_1.Joi.string().required(),
62
- apiKey: utils_validation_1.Joi.string().required(),
63
- appId: utils_validation_1.Joi.string().required(),
64
61
  assistantId: utils_validation_1.Joi.string().required(),
62
+ // Optional Ask AI configuration
63
+ indexName: utils_validation_1.Joi.string().optional(),
64
+ apiKey: utils_validation_1.Joi.string().optional(),
65
+ appId: utils_validation_1.Joi.string().optional(),
65
66
  searchParameters: utils_validation_1.Joi.object({
66
67
  facetFilters: FacetFiltersSchema.optional(),
67
68
  }).optional(),
69
+ suggestedQuestions: utils_validation_1.Joi.boolean().optional(),
68
70
  }))
69
71
  .custom((askAiInput, helpers) => {
70
72
  if (!askAiInput) {
@@ -87,6 +89,10 @@ exports.Schema = utils_validation_1.Joi.object({
87
89
  : {}),
88
90
  };
89
91
  }
92
+ // Fill in missing fields with the top-level Algolia config
93
+ askAiInput.indexName = askAiInput.indexName ?? algolia.indexName;
94
+ askAiInput.apiKey = askAiInput.apiKey ?? algolia.apiKey;
95
+ askAiInput.appId = askAiInput.appId ?? algolia.appId;
90
96
  if (askAiInput.searchParameters?.facetFilters === undefined &&
91
97
  algoliaFacetFilters) {
92
98
  askAiInput.searchParameters = askAiInput.searchParameters ?? {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@docusaurus/theme-search-algolia",
3
- "version": "3.9.1",
3
+ "version": "3.9.2-alpha.0",
4
4
  "description": "Algolia search component for Docusaurus.",
5
5
  "main": "lib/index.js",
6
6
  "sideEffects": [
@@ -33,14 +33,15 @@
33
33
  "copy:watch": "node ../../admin/scripts/copyUntypedFiles.js --watch"
34
34
  },
35
35
  "dependencies": {
36
- "@docsearch/react": "^3.9.0 || ^4.1.0",
37
- "@docusaurus/core": "3.9.1",
38
- "@docusaurus/logger": "3.9.1",
39
- "@docusaurus/plugin-content-docs": "3.9.1",
40
- "@docusaurus/theme-common": "3.9.1",
41
- "@docusaurus/theme-translations": "3.9.1",
42
- "@docusaurus/utils": "3.9.1",
43
- "@docusaurus/utils-validation": "3.9.1",
36
+ "@algolia/autocomplete-core": "^1.19.2",
37
+ "@docsearch/react": "^3.9.0 || ^4.3.2",
38
+ "@docusaurus/core": "3.9.2-alpha.0",
39
+ "@docusaurus/logger": "3.9.2-alpha.0",
40
+ "@docusaurus/plugin-content-docs": "3.9.2-alpha.0",
41
+ "@docusaurus/theme-common": "3.9.2-alpha.0",
42
+ "@docusaurus/theme-translations": "3.9.2-alpha.0",
43
+ "@docusaurus/utils": "3.9.2-alpha.0",
44
+ "@docusaurus/utils-validation": "3.9.2-alpha.0",
44
45
  "algoliasearch": "^5.37.0",
45
46
  "algoliasearch-helper": "^3.26.0",
46
47
  "clsx": "^2.0.0",
@@ -51,7 +52,7 @@
51
52
  "utility-types": "^3.10.0"
52
53
  },
53
54
  "devDependencies": {
54
- "@docusaurus/module-type-aliases": "3.9.1"
55
+ "@docusaurus/module-type-aliases": "3.9.2-alpha.0"
55
56
  },
56
57
  "peerDependencies": {
57
58
  "react": "^18.0.0 || ^19.0.0",
@@ -60,5 +61,5 @@
60
61
  "engines": {
61
62
  "node": ">=20.0"
62
63
  },
63
- "gitHead": "c0dd59f0e712f85b6053c59e46b0514b5d2d1414"
64
+ "gitHead": "27626cdd7a102277935f10cc4d8d3f93e211eafe"
64
65
  }
@@ -91,7 +91,7 @@ export function useAlgoliaAskAi(props: DocSearchV4PropsLite): UseAskAiResult {
91
91
  }, []);
92
92
 
93
93
  const extraAskAiProps: UseAskAiResult['extraAskAiProps'] = {
94
- askAi,
94
+ askAi: askAi as any,
95
95
  canHandleAskAi,
96
96
  isAskAiActive,
97
97
  onAskAiToggle,
@@ -43,7 +43,7 @@ export function useSearchResultUrlProcessor(): (url: string) => string {
43
43
  }
44
44
 
45
45
  // Otherwise => transform to relative URL for SPA navigation
46
- const relativeUrl = `${parsedURL.pathname + parsedURL.hash}`;
46
+ const relativeUrl = `${parsedURL.pathname}${parsedURL.search}${parsedURL.hash}`;
47
47
 
48
48
  return withBaseUrl(
49
49
  replacePathname(relativeUrl, replaceSearchResultPathname),
@@ -61,7 +61,7 @@ type DocSearchProps = Omit<
61
61
 
62
62
  // extend DocSearchProps for v4 features
63
63
  // TODO Docusaurus v4: cleanup after we drop support for DocSearch v3
64
- interface DocSearchV4Props extends DocSearchProps {
64
+ interface DocSearchV4Props extends Omit<DocSearchProps, 'askAi'> {
65
65
  indexName: string;
66
66
  askAi?: ThemeConfigAlgolia['askAi'];
67
67
  translations?: DocSearchTranslations;
@@ -199,7 +199,7 @@ function useSearchParameters({
199
199
 
200
200
  function DocSearch({externalUrlRegex, ...props}: DocSearchV4Props) {
201
201
  const navigator = useNavigator({externalUrlRegex});
202
- const searchParameters = useSearchParameters({...props});
202
+ const searchParameters = useSearchParameters({...props} as DocSearchProps);
203
203
  const transformItems = useTransformItems(props);
204
204
  const transformSearchClient = useTransformSearchClient();
205
205
 
@@ -301,7 +301,7 @@ function DocSearch({externalUrlRegex, ...props}: DocSearchV4Props) {
301
301
  resultsFooterComponent,
302
302
  })}
303
303
  placeholder={currentPlaceholder}
304
- {...props}
304
+ {...(props as any)}
305
305
  translations={props.translations?.modal ?? translations.modal}
306
306
  searchParameters={searchParameters}
307
307
  {...extraAskAiProps}
@@ -312,9 +312,15 @@ function DocSearch({externalUrlRegex, ...props}: DocSearchV4Props) {
312
312
  );
313
313
  }
314
314
 
315
- export default function SearchBar(): ReactNode {
315
+ export default function SearchBar(props: Partial<DocSearchV4Props>): ReactNode {
316
316
  const {siteConfig} = useDocusaurusContext();
317
- return (
318
- <DocSearch {...(siteConfig.themeConfig.algolia as DocSearchV4Props)} />
319
- );
317
+
318
+ const docSearchProps: DocSearchV4Props = {
319
+ ...(siteConfig.themeConfig.algolia as DocSearchV4Props),
320
+ // Let props override theme config
321
+ // See https://github.com/facebook/docusaurus/pull/11581
322
+ ...props,
323
+ };
324
+
325
+ return <DocSearch {...docSearchProps} />;
320
326
  }
@@ -11,12 +11,13 @@ declare module '@docsearch/react/useDocSearchKeyboardEvents';
11
11
  declare module '@docsearch/react/version';
12
12
 
13
13
  declare module '@docusaurus/theme-search-algolia' {
14
- import type {DeepPartial, Overwrite} from 'utility-types';
14
+ import type {DeepPartial, Overwrite, Optional} from 'utility-types';
15
15
 
16
16
  import type {DocSearchProps} from '@docsearch/react';
17
17
  import type {FacetFilters} from 'algoliasearch/lite';
18
18
 
19
19
  // The config after normalization (e.g. AskAI string -> object)
20
+ // This matches DocSearch v4.3+ AskAi configuration
20
21
  export type AskAiConfig = {
21
22
  indexName: string;
22
23
  apiKey: string;
@@ -25,6 +26,7 @@ declare module '@docusaurus/theme-search-algolia' {
25
26
  searchParameters?: {
26
27
  facetFilters?: FacetFilters;
27
28
  };
29
+ suggestedQuestions?: boolean;
28
30
  };
29
31
 
30
32
  // DocSearch props that Docusaurus exposes directly through props forwarding
@@ -70,7 +72,9 @@ declare module '@docusaurus/theme-search-algolia' {
70
72
  apiKey: ThemeConfigAlgolia['apiKey'];
71
73
  indexName: ThemeConfigAlgolia['indexName'];
72
74
  // askAi also accepts a shorter string form
73
- askAi?: string | AskAiConfig;
75
+ askAi?:
76
+ | string
77
+ | Optional<AskAiConfig, 'indexName' | 'appId' | 'apiKey'>;
74
78
  }
75
79
  >;
76
80
  };
@@ -67,13 +67,15 @@ export const Schema = Joi.object<ThemeConfig>({
67
67
  Joi.string(),
68
68
  // Full configuration object
69
69
  Joi.object({
70
- indexName: Joi.string().required(),
71
- apiKey: Joi.string().required(),
72
- appId: Joi.string().required(),
73
70
  assistantId: Joi.string().required(),
71
+ // Optional Ask AI configuration
72
+ indexName: Joi.string().optional(),
73
+ apiKey: Joi.string().optional(),
74
+ appId: Joi.string().optional(),
74
75
  searchParameters: Joi.object({
75
76
  facetFilters: FacetFiltersSchema.optional(),
76
77
  }).optional(),
78
+ suggestedQuestions: Joi.boolean().optional(),
77
79
  }),
78
80
  )
79
81
  .custom(
@@ -102,6 +104,10 @@ export const Schema = Joi.object<ThemeConfig>({
102
104
  } satisfies ThemeConfigAlgolia['askAi'];
103
105
  }
104
106
 
107
+ // Fill in missing fields with the top-level Algolia config
108
+ askAiInput.indexName = askAiInput.indexName ?? algolia.indexName;
109
+ askAiInput.apiKey = askAiInput.apiKey ?? algolia.apiKey;
110
+ askAiInput.appId = askAiInput.appId ?? algolia.appId;
105
111
  if (
106
112
  askAiInput.searchParameters?.facetFilters === undefined &&
107
113
  algoliaFacetFilters
@@ -109,6 +115,7 @@ export const Schema = Joi.object<ThemeConfig>({
109
115
  askAiInput.searchParameters = askAiInput.searchParameters ?? {};
110
116
  askAiInput.searchParameters.facetFilters = algoliaFacetFilters;
111
117
  }
118
+
112
119
  return askAiInput;
113
120
  },
114
121
  )