@docusaurus/theme-search-algolia 2.0.0-beta.16 → 2.0.0-beta.19

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.
@@ -8,7 +8,7 @@ import {useContextualSearchFilters} from '@docusaurus/theme-common';
8
8
  // Translate search-engine agnostic search filters to Algolia search filters
9
9
  export function useAlgoliaContextualFacetFilters() {
10
10
  const {locale, tags} = useContextualSearchFilters();
11
- // seems safe to convert locale->language, see AlgoliaSearchMetadata comment
11
+ // Seems safe to convert locale->language, see AlgoliaSearchMetadata comment
12
12
  const languageFilter = `language:${locale}`;
13
13
  const tagsFilter = tags.map((tag) => `docusaurus_tag:${tag}`);
14
14
  return [languageFilter, tagsFilter];
package/lib/index.js CHANGED
@@ -8,16 +8,14 @@
8
8
  Object.defineProperty(exports, '__esModule', {value: true});
9
9
  exports.validateThemeConfig = void 0;
10
10
  const tslib_1 = require('tslib');
11
- const path_1 = (0, tslib_1.__importDefault)(require('path'));
12
- const fs_extra_1 = (0, tslib_1.__importDefault)(require('fs-extra'));
11
+ const path_1 = tslib_1.__importDefault(require('path'));
12
+ const fs_extra_1 = tslib_1.__importDefault(require('fs-extra'));
13
13
  const eta_1 = require('eta');
14
14
  const utils_1 = require('@docusaurus/utils');
15
15
  const theme_translations_1 = require('@docusaurus/theme-translations');
16
- const logger_1 = (0, tslib_1.__importDefault)(require('@docusaurus/logger'));
17
- const opensearch_1 = (0, tslib_1.__importDefault)(
18
- require('./templates/opensearch'),
19
- );
20
- const lodash_1 = (0, tslib_1.__importDefault)(require('lodash'));
16
+ const logger_1 = tslib_1.__importDefault(require('@docusaurus/logger'));
17
+ const opensearch_1 = tslib_1.__importDefault(require('./templates/opensearch'));
18
+ const lodash_1 = tslib_1.__importDefault(require('lodash'));
21
19
  const getCompiledOpenSearchTemplate = lodash_1.default.memoize(() =>
22
20
  (0, eta_1.compile)(opensearch_1.default.trim()),
23
21
  );
@@ -38,10 +36,10 @@ function themeSearchAlgolia(context) {
38
36
  return {
39
37
  name: 'docusaurus-theme-search-algolia',
40
38
  getThemePath() {
41
- return path_1.default.resolve(__dirname, '../lib/theme');
39
+ return '../lib/theme';
42
40
  },
43
41
  getTypeScriptThemePath() {
44
- return path_1.default.resolve(__dirname, '../src/theme');
42
+ return '../src/theme';
45
43
  },
46
44
  getDefaultCodeTranslationMessages() {
47
45
  return (0, theme_translations_1.readDefaultCodeTranslationMessages)({
@@ -15,7 +15,6 @@ import {isRegexpStringMatch, useSearchPage} from '@docusaurus/theme-common';
15
15
  import {DocSearchButton, useDocSearchKeyboardEvents} from '@docsearch/react';
16
16
  import {useAlgoliaContextualFacetFilters} from '@docusaurus/theme-search-algolia/client';
17
17
  import Translate, {translate} from '@docusaurus/Translate';
18
- import styles from './styles.module.css';
19
18
  let DocSearchModal = null;
20
19
  function Hit({hit, children}) {
21
20
  return <Link to={hit.url}>{children}</Link>;
@@ -37,22 +36,15 @@ function mergeFacetFilters(f1, f2) {
37
36
  return [...normalize(f1), ...normalize(f2)];
38
37
  }
39
38
  function DocSearch({contextualSearch, externalUrlRegex, ...props}) {
40
- var _a, _b;
41
39
  const {siteMetadata} = useDocusaurusContext();
42
40
  const contextualSearchFacetFilters = useAlgoliaContextualFacetFilters();
43
- const configFacetFilters =
44
- (_b =
45
- (_a = props.searchParameters) === null || _a === void 0
46
- ? void 0
47
- : _a.facetFilters) !== null && _b !== void 0
48
- ? _b
49
- : [];
41
+ const configFacetFilters = props.searchParameters?.facetFilters ?? [];
50
42
  const facetFilters = contextualSearch
51
43
  ? // Merge contextual search filters with config filters
52
44
  mergeFacetFilters(contextualSearchFacetFilters, configFacetFilters)
53
45
  : // ... or use config facetFilters
54
46
  configFacetFilters;
55
- // we let user override default searchParameters if he wants to
47
+ // We let user override default searchParameters if she wants to
56
48
  const searchParameters = {
57
49
  ...props.searchParameters,
58
50
  facetFilters,
@@ -86,11 +78,8 @@ function DocSearch({contextualSearch, externalUrlRegex, ...props}) {
86
78
  });
87
79
  }, [importDocSearchModalIfNeeded, setIsOpen]);
88
80
  const onClose = useCallback(() => {
89
- var _a;
90
81
  setIsOpen(false);
91
- (_a = searchContainer.current) === null || _a === void 0
92
- ? void 0
93
- : _a.remove();
82
+ searchContainer.current?.remove();
94
83
  }, [setIsOpen]);
95
84
  const onInput = useCallback(
96
85
  (event) => {
@@ -169,19 +158,17 @@ function DocSearch({contextualSearch, externalUrlRegex, ...props}) {
169
158
  />
170
159
  </Head>
171
160
 
172
- <div className={styles.searchBox}>
173
- <DocSearchButton
174
- onTouchStart={importDocSearchModalIfNeeded}
175
- onFocus={importDocSearchModalIfNeeded}
176
- onMouseOver={importDocSearchModalIfNeeded}
177
- onClick={onOpen}
178
- ref={searchButtonRef}
179
- translations={{
180
- buttonText: translatedSearchLabel,
181
- buttonAriaLabel: translatedSearchLabel,
182
- }}
183
- />
184
- </div>
161
+ <DocSearchButton
162
+ onTouchStart={importDocSearchModalIfNeeded}
163
+ onFocus={importDocSearchModalIfNeeded}
164
+ onMouseOver={importDocSearchModalIfNeeded}
165
+ onClick={onOpen}
166
+ ref={searchButtonRef}
167
+ translations={{
168
+ buttonText: translatedSearchLabel,
169
+ buttonAriaLabel: translatedSearchLabel,
170
+ }}
171
+ />
185
172
 
186
173
  {isOpen &&
187
174
  DocSearchModal &&
@@ -13,6 +13,7 @@ import Head from '@docusaurus/Head';
13
13
  import Link from '@docusaurus/Link';
14
14
  import ExecutionEnvironment from '@docusaurus/ExecutionEnvironment';
15
15
  import {
16
+ HtmlClassNameProvider,
16
17
  useTitleFormatter,
17
18
  usePluralForm,
18
19
  isRegexpStringMatch,
@@ -109,7 +110,7 @@ function SearchVersionSelectList({docsSearchVersionsHelpers}) {
109
110
  </div>
110
111
  );
111
112
  }
112
- export default function SearchPage() {
113
+ function SearchPageContent() {
113
114
  const {
114
115
  siteConfig: {themeConfig},
115
116
  i18n: {currentLocale},
@@ -173,7 +174,7 @@ export default function SearchPage() {
173
174
  algoliaHelper.on(
174
175
  'result',
175
176
  ({results: {query, hits, page, nbHits, nbPages}}) => {
176
- if (query === '' || !(hits instanceof Array)) {
177
+ if (query === '' || !Array.isArray(hits)) {
177
178
  searchResultStateDispatcher({type: 'reset'});
178
179
  return;
179
180
  }
@@ -293,7 +294,7 @@ export default function SearchPage() {
293
294
  makeSearch(searchResultState.lastPage);
294
295
  }, [makeSearch, searchResultState.lastPage]);
295
296
  return (
296
- <Layout wrapperClassName="search-page-wrapper">
297
+ <Layout>
297
298
  <Head>
298
299
  <title>{useTitleFormatter(getTitle())}</title>
299
300
  {/*
@@ -453,3 +454,10 @@ export default function SearchPage() {
453
454
  </Layout>
454
455
  );
455
456
  }
457
+ export default function SearchPage() {
458
+ return (
459
+ <HtmlClassNameProvider className="search-page-wrapper">
460
+ <SearchPageContent />
461
+ </HtmlClassNameProvider>
462
+ );
463
+ }
@@ -5,14 +5,11 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
  import { Joi } from '@docusaurus/utils-validation';
8
- import type { ThemeConfig, Validate, ValidationResult } from '@docusaurus/types';
8
+ import type { ThemeConfig, ThemeConfigValidationContext } from '@docusaurus/types';
9
9
  export declare const DEFAULT_CONFIG: {
10
10
  contextualSearch: boolean;
11
11
  searchParameters: {};
12
12
  searchPagePath: string;
13
13
  };
14
14
  export declare const Schema: Joi.ObjectSchema<any>;
15
- export declare function validateThemeConfig({ validate, themeConfig, }: {
16
- validate: Validate<ThemeConfig>;
17
- themeConfig: ThemeConfig;
18
- }): ValidationResult<ThemeConfig>;
15
+ export declare function validateThemeConfig({ validate, themeConfig, }: ThemeConfigValidationContext<ThemeConfig>): ThemeConfig;
@@ -9,7 +9,7 @@ Object.defineProperty(exports, '__esModule', {value: true});
9
9
  exports.validateThemeConfig = exports.Schema = exports.DEFAULT_CONFIG = void 0;
10
10
  const utils_validation_1 = require('@docusaurus/utils-validation');
11
11
  exports.DEFAULT_CONFIG = {
12
- // enabled by default, as it makes sense in most cases
12
+ // Enabled by default, as it makes sense in most cases
13
13
  // see also https://github.com/facebook/docusaurus/issues/5880
14
14
  contextualSearch: true,
15
15
  searchParameters: {},
package/package.json CHANGED
@@ -1,8 +1,11 @@
1
1
  {
2
2
  "name": "@docusaurus/theme-search-algolia",
3
- "version": "2.0.0-beta.16",
3
+ "version": "2.0.0-beta.19",
4
4
  "description": "Algolia search component for Docusaurus.",
5
5
  "main": "lib/index.js",
6
+ "sideEffects": [
7
+ "*.css"
8
+ ],
6
9
  "exports": {
7
10
  "./client": "./lib/client/index.js",
8
11
  ".": "./lib/index.js"
@@ -26,23 +29,24 @@
26
29
  },
27
30
  "dependencies": {
28
31
  "@docsearch/react": "^3.0.0",
29
- "@docusaurus/core": "2.0.0-beta.16",
30
- "@docusaurus/logger": "2.0.0-beta.16",
31
- "@docusaurus/theme-common": "2.0.0-beta.16",
32
- "@docusaurus/theme-translations": "2.0.0-beta.16",
33
- "@docusaurus/utils": "2.0.0-beta.16",
34
- "@docusaurus/utils-validation": "2.0.0-beta.16",
35
- "algoliasearch": "^4.12.1",
36
- "algoliasearch-helper": "^3.7.0",
32
+ "@docusaurus/core": "2.0.0-beta.19",
33
+ "@docusaurus/logger": "2.0.0-beta.19",
34
+ "@docusaurus/plugin-content-docs": "2.0.0-beta.19",
35
+ "@docusaurus/theme-common": "2.0.0-beta.19",
36
+ "@docusaurus/theme-translations": "2.0.0-beta.19",
37
+ "@docusaurus/utils": "2.0.0-beta.19",
38
+ "@docusaurus/utils-validation": "2.0.0-beta.19",
39
+ "algoliasearch": "^4.13.0",
40
+ "algoliasearch-helper": "^3.8.2",
37
41
  "clsx": "^1.1.1",
38
42
  "eta": "^1.12.3",
39
- "fs-extra": "^10.0.1",
43
+ "fs-extra": "^10.1.0",
40
44
  "lodash": "^4.17.21",
41
- "tslib": "^2.3.1",
45
+ "tslib": "^2.4.0",
42
46
  "utility-types": "^3.10.0"
43
47
  },
44
48
  "devDependencies": {
45
- "@docusaurus/module-type-aliases": "2.0.0-beta.16"
49
+ "@docusaurus/module-type-aliases": "2.0.0-beta.19"
46
50
  },
47
51
  "peerDependencies": {
48
52
  "react": "^16.8.4 || ^17.0.0",
@@ -51,5 +55,5 @@
51
55
  "engines": {
52
56
  "node": ">=14"
53
57
  },
54
- "gitHead": "eb43c4d4f95a4fb97dc9bb9dc615413e0dc2e1e7"
58
+ "gitHead": "a71e60a49cce93c1006ef10c41ac03187f057102"
55
59
  }
@@ -11,7 +11,7 @@ import {useContextualSearchFilters} from '@docusaurus/theme-common';
11
11
  export function useAlgoliaContextualFacetFilters(): [string, string[]] {
12
12
  const {locale, tags} = useContextualSearchFilters();
13
13
 
14
- // seems safe to convert locale->language, see AlgoliaSearchMetadata comment
14
+ // Seems safe to convert locale->language, see AlgoliaSearchMetadata comment
15
15
  const languageFilter = `language:${locale}`;
16
16
 
17
17
  const tagsFilter = tags.map((tag) => `docusaurus_tag:${tag}`);
package/src/index.ts CHANGED
@@ -47,10 +47,10 @@ export default function themeSearchAlgolia(context: LoadContext): Plugin<void> {
47
47
  name: 'docusaurus-theme-search-algolia',
48
48
 
49
49
  getThemePath() {
50
- return path.resolve(__dirname, '../lib/theme');
50
+ return '../lib/theme';
51
51
  },
52
52
  getTypeScriptThemePath() {
53
- return path.resolve(__dirname, '../src/theme');
53
+ return '../src/theme';
54
54
  },
55
55
 
56
56
  getDefaultCodeTranslationMessages() {
@@ -14,9 +14,9 @@ import Link from '@docusaurus/Link';
14
14
  import Head from '@docusaurus/Head';
15
15
  import {isRegexpStringMatch, useSearchPage} from '@docusaurus/theme-common';
16
16
  import {DocSearchButton, useDocSearchKeyboardEvents} from '@docsearch/react';
17
+ import type {SearchClient} from 'algoliasearch/lite';
17
18
  import {useAlgoliaContextualFacetFilters} from '@docusaurus/theme-search-algolia/client';
18
19
  import Translate, {translate} from '@docusaurus/Translate';
19
- import styles from './styles.module.css';
20
20
 
21
21
  import type {
22
22
  DocSearchModal as DocSearchModalType,
@@ -99,7 +99,7 @@ function DocSearch({
99
99
  : // ... or use config facetFilters
100
100
  configFacetFilters;
101
101
 
102
- // we let user override default searchParameters if he wants to
102
+ // We let user override default searchParameters if she wants to
103
103
  const searchParameters: DocSearchProps['searchParameters'] = {
104
104
  ...props.searchParameters,
105
105
  facetFilters,
@@ -145,7 +145,7 @@ function DocSearch({
145
145
  }, [setIsOpen]);
146
146
 
147
147
  const onInput = useCallback(
148
- (event) => {
148
+ (event: KeyboardEvent) => {
149
149
  importDocSearchModalIfNeeded().then(() => {
150
150
  setIsOpen(true);
151
151
  setInitialQuery(event.key);
@@ -194,7 +194,7 @@ function DocSearch({
194
194
  );
195
195
 
196
196
  const transformSearchClient = useCallback(
197
- (searchClient) => {
197
+ (searchClient: SearchClient) => {
198
198
  searchClient.addAlgoliaAgent(
199
199
  'docusaurus',
200
200
  siteMetadata.docusaurusVersion,
@@ -232,19 +232,17 @@ function DocSearch({
232
232
  />
233
233
  </Head>
234
234
 
235
- <div className={styles.searchBox}>
236
- <DocSearchButton
237
- onTouchStart={importDocSearchModalIfNeeded}
238
- onFocus={importDocSearchModalIfNeeded}
239
- onMouseOver={importDocSearchModalIfNeeded}
240
- onClick={onOpen}
241
- ref={searchButtonRef}
242
- translations={{
243
- buttonText: translatedSearchLabel,
244
- buttonAriaLabel: translatedSearchLabel,
245
- }}
246
- />
247
- </div>
235
+ <DocSearchButton
236
+ onTouchStart={importDocSearchModalIfNeeded}
237
+ onFocus={importDocSearchModalIfNeeded}
238
+ onMouseOver={importDocSearchModalIfNeeded}
239
+ onClick={onOpen}
240
+ ref={searchButtonRef}
241
+ translations={{
242
+ buttonText: translatedSearchLabel,
243
+ buttonAriaLabel: translatedSearchLabel,
244
+ }}
245
+ />
248
246
 
249
247
  {isOpen &&
250
248
  DocSearchModal &&
@@ -17,6 +17,7 @@ import Head from '@docusaurus/Head';
17
17
  import Link from '@docusaurus/Link';
18
18
  import ExecutionEnvironment from '@docusaurus/ExecutionEnvironment';
19
19
  import {
20
+ HtmlClassNameProvider,
20
21
  useTitleFormatter,
21
22
  usePluralForm,
22
23
  isRegexpStringMatch,
@@ -53,15 +54,16 @@ function useDocsSearchVersionsHelpers() {
53
54
 
54
55
  // State of the version select menus / algolia facet filters
55
56
  // docsPluginId -> versionName map
56
- const [searchVersions, setSearchVersions] = useState<Record<string, string>>(
57
- () =>
58
- Object.entries(allDocsData).reduce(
59
- (acc, [pluginId, pluginData]) => ({
60
- ...acc,
61
- [pluginId]: pluginData.versions[0].name,
62
- }),
63
- {},
64
- ),
57
+ const [searchVersions, setSearchVersions] = useState<{
58
+ [pluginId: string]: string;
59
+ }>(() =>
60
+ Object.entries(allDocsData).reduce(
61
+ (acc, [pluginId, pluginData]) => ({
62
+ ...acc,
63
+ [pluginId]: pluginData.versions[0]!.name,
64
+ }),
65
+ {},
66
+ ),
65
67
  );
66
68
 
67
69
  // Set the value of a single select menu
@@ -149,7 +151,7 @@ type ResultDispatcher =
149
151
  | {type: 'update'; value: ResultDispatcherState}
150
152
  | {type: 'advance'; value?: undefined};
151
153
 
152
- export default function SearchPage(): JSX.Element {
154
+ function SearchPageContent(): JSX.Element {
153
155
  const {
154
156
  siteConfig: {themeConfig},
155
157
  i18n: {currentLocale},
@@ -218,7 +220,7 @@ export default function SearchPage(): JSX.Element {
218
220
  algoliaHelper.on(
219
221
  'result',
220
222
  ({results: {query, hits, page, nbHits, nbPages}}) => {
221
- if (query === '' || !(hits instanceof Array)) {
223
+ if (query === '' || !Array.isArray(hits)) {
222
224
  searchResultStateDispatcher({type: 'reset'});
223
225
  return;
224
226
  }
@@ -277,7 +279,7 @@ export default function SearchPage(): JSX.Element {
277
279
  const {
278
280
  isIntersecting,
279
281
  boundingClientRect: {y: currentY},
280
- } = entries[0];
282
+ } = entries[0]!;
281
283
 
282
284
  if (isIntersecting && prevY.current > currentY) {
283
285
  searchResultStateDispatcher({type: 'advance'});
@@ -356,7 +358,7 @@ export default function SearchPage(): JSX.Element {
356
358
  }, [makeSearch, searchResultState.lastPage]);
357
359
 
358
360
  return (
359
- <Layout wrapperClassName="search-page-wrapper">
361
+ <Layout>
360
362
  <Head>
361
363
  <title>{useTitleFormatter(getTitle())}</title>
362
364
  {/*
@@ -516,3 +518,11 @@ export default function SearchPage(): JSX.Element {
516
518
  </Layout>
517
519
  );
518
520
  }
521
+
522
+ export default function SearchPage(): JSX.Element {
523
+ return (
524
+ <HtmlClassNameProvider className="search-page-wrapper">
525
+ <SearchPageContent />
526
+ </HtmlClassNameProvider>
527
+ );
528
+ }
@@ -15,7 +15,7 @@ declare module '@docusaurus/theme-search-algolia' {
15
15
  appId: string;
16
16
  apiKey: string;
17
17
  indexName: string;
18
- searchParameters: Record<string, unknown>;
18
+ searchParameters: {[key: string]: unknown};
19
19
  searchPagePath: string | false | null;
20
20
  };
21
21
  };
@@ -6,10 +6,13 @@
6
6
  */
7
7
 
8
8
  import {Joi} from '@docusaurus/utils-validation';
9
- import type {ThemeConfig, Validate, ValidationResult} from '@docusaurus/types';
9
+ import type {
10
+ ThemeConfig,
11
+ ThemeConfigValidationContext,
12
+ } from '@docusaurus/types';
10
13
 
11
14
  export const DEFAULT_CONFIG = {
12
- // enabled by default, as it makes sense in most cases
15
+ // Enabled by default, as it makes sense in most cases
13
16
  // see also https://github.com/facebook/docusaurus/issues/5880
14
17
  contextualSearch: true,
15
18
 
@@ -45,9 +48,6 @@ export const Schema = Joi.object({
45
48
  export function validateThemeConfig({
46
49
  validate,
47
50
  themeConfig,
48
- }: {
49
- validate: Validate<ThemeConfig>;
50
- themeConfig: ThemeConfig;
51
- }): ValidationResult<ThemeConfig> {
51
+ }: ThemeConfigValidationContext<ThemeConfig>): ThemeConfig {
52
52
  return validate(Schema, themeConfig);
53
53
  }
@@ -1,20 +0,0 @@
1
- /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- */
7
-
8
- @media (max-width: 996px) {
9
- .searchBox {
10
- position: absolute;
11
- right: var(--ifm-navbar-padding-horizontal);
12
- }
13
- }
14
-
15
- @media (min-width: 997px) {
16
- .searchBox {
17
- padding: var(--ifm-navbar-item-padding-vertical)
18
- var(--ifm-navbar-item-padding-horizontal);
19
- }
20
- }
@@ -1,20 +0,0 @@
1
- /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- */
7
-
8
- @media (max-width: 996px) {
9
- .searchBox {
10
- position: absolute;
11
- right: var(--ifm-navbar-padding-horizontal);
12
- }
13
- }
14
-
15
- @media (min-width: 997px) {
16
- .searchBox {
17
- padding: var(--ifm-navbar-item-padding-vertical)
18
- var(--ifm-navbar-item-padding-horizontal);
19
- }
20
- }