@docusaurus/theme-search-algolia 2.0.0-beta.1 → 2.0.0-beta.10

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 (36) hide show
  1. package/copyUntypedFiles.js +20 -0
  2. package/lib/index.d.ts +11 -0
  3. package/lib/index.js +85 -0
  4. package/lib/templates/opensearch.d.ts +8 -0
  5. package/lib/templates/opensearch.js +23 -0
  6. package/lib/theme/SearchBar/index.d.ts +9 -0
  7. package/lib/theme/SearchBar/index.js +153 -0
  8. package/lib/theme/SearchBar/styles.css +21 -0
  9. package/lib/theme/SearchBar/styles.module.css +20 -0
  10. package/lib/theme/SearchMetadata/index.d.ts +10 -0
  11. package/lib/theme/SearchMetadata/index.js +20 -0
  12. package/lib/theme/SearchPage/index.d.ts +9 -0
  13. package/lib/theme/SearchPage/index.js +299 -0
  14. package/lib/theme/SearchPage/styles.module.css +119 -0
  15. package/lib/theme/hooks/useAlgoliaContextualFacetFilters.d.ts +8 -0
  16. package/lib/theme/hooks/useAlgoliaContextualFacetFilters.js +15 -0
  17. package/lib/theme/hooks/useSearchQuery.d.ts +9 -0
  18. package/lib/theme/hooks/useSearchQuery.js +43 -0
  19. package/lib/validateThemeConfig.d.ts +13 -0
  20. package/lib/validateThemeConfig.js +39 -0
  21. package/package.json +24 -12
  22. package/src/__tests__/validateThemeConfig.test.js +14 -0
  23. package/src/{index.js → index.ts} +37 -19
  24. package/src/templates/{opensearch.js → opensearch.ts} +4 -2
  25. package/src/theme/SearchBar/{index.js → index.tsx} +78 -26
  26. package/src/theme/{SearchMetadatas/index.js → SearchMetadata/index.tsx} +9 -2
  27. package/src/theme/SearchPage/{index.js → index.tsx} +81 -51
  28. package/src/theme/hooks/{useAlgoliaContextualFacetFilters.js → useAlgoliaContextualFacetFilters.ts} +4 -3
  29. package/src/theme/hooks/useSearchQuery.ts +63 -0
  30. package/src/theme-search-algolia.d.ts +47 -0
  31. package/src/types.d.ts +10 -0
  32. package/src/{validateThemeConfig.js → validateThemeConfig.ts} +10 -7
  33. package/tsconfig.browser.json +8 -0
  34. package/tsconfig.json +9 -0
  35. package/tsconfig.server.json +4 -0
  36. package/src/theme/hooks/useSearchQuery.js +0 -44
@@ -0,0 +1,47 @@
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
+ declare module '@docusaurus/theme-search-algolia' {
9
+ export type Options = never;
10
+ }
11
+
12
+ declare module '@theme/hooks/useSearchQuery' {
13
+ export interface SearchQuery {
14
+ searchQuery: string;
15
+ setSearchQuery: (newSearchQuery: string) => void;
16
+ generateSearchPageLink: (targetSearchQuery: string) => string;
17
+ }
18
+
19
+ export default function useSearchQuery(): SearchQuery;
20
+ }
21
+
22
+ declare module '@theme/hooks/useAlgoliaContextualFacetFilters' {
23
+ export type useAlgoliaContextualFacetFiltersReturns = [string, string[]];
24
+
25
+ export default function useAlgoliaContextualFacetFilters(): useAlgoliaContextualFacetFiltersReturns;
26
+ }
27
+
28
+ declare module '@theme/SearchPage' {
29
+ const SearchPage: () => JSX.Element;
30
+ export default SearchPage;
31
+ }
32
+
33
+ declare module '@theme/SearchMetadata' {
34
+ export type SearchMetadataProps = {
35
+ readonly locale?: string;
36
+ readonly version?: string;
37
+ readonly tag?: string;
38
+ };
39
+
40
+ const SearchMetadata: (props: SearchMetadataProps) => JSX.Element;
41
+ export default SearchMetadata;
42
+ }
43
+
44
+ declare module '@theme/SearchBar' {
45
+ const SearchBar: () => JSX.Element;
46
+ export default SearchBar;
47
+ }
package/src/types.d.ts ADDED
@@ -0,0 +1,10 @@
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
+ /// <reference types="@docusaurus/module-type-aliases" />
9
+ /// <reference types="@docusaurus/theme-common" />
10
+ /// <reference types="@docusaurus/theme-classic" />
@@ -5,7 +5,8 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
 
8
- const {Joi} = require('@docusaurus/utils-validation');
8
+ import {Joi} from '@docusaurus/utils-validation';
9
+ import type {ThemeConfig, Validate, ValidationResult} from '@docusaurus/types';
9
10
 
10
11
  const DEFAULT_CONFIG = {
11
12
  contextualSearch: false, // future: maybe we want to enable this by default
@@ -18,11 +19,11 @@ const DEFAULT_CONFIG = {
18
19
  };
19
20
  exports.DEFAULT_CONFIG = DEFAULT_CONFIG;
20
21
 
21
- const Schema = Joi.object({
22
+ export const Schema = Joi.object({
22
23
  algolia: Joi.object({
23
24
  // Docusaurus attributes
24
25
  contextualSearch: Joi.boolean().default(DEFAULT_CONFIG.contextualSearch),
25
-
26
+ externalUrlRegex: Joi.string().optional(),
26
27
  // Algolia attributes
27
28
  appId: Joi.string().default(DEFAULT_CONFIG.appId),
28
29
  apiKey: Joi.string().required(),
@@ -35,11 +36,13 @@ const Schema = Joi.object({
35
36
  .required()
36
37
  .unknown(), // DocSearch 3 is still alpha: don't validate the rest for now
37
38
  });
38
- exports.Schema = Schema;
39
39
 
40
- exports.validateThemeConfig = function validateThemeConfig({
40
+ export function validateThemeConfig({
41
41
  validate,
42
42
  themeConfig,
43
- }) {
43
+ }: {
44
+ validate: Validate<ThemeConfig>;
45
+ themeConfig: ThemeConfig;
46
+ }): ValidationResult<ThemeConfig> {
44
47
  return validate(Schema, themeConfig);
45
- };
48
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "module": "esnext",
5
+ "jsx": "react-native"
6
+ },
7
+ "include": ["src/theme/", "src/*.d.ts"]
8
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,9 @@
1
+ {
2
+ "extends": "../../tsconfig.json",
3
+ "compilerOptions": {
4
+ "lib": ["DOM", "ES2019"],
5
+ "rootDir": "src",
6
+ "baseUrl": "src",
7
+ "outDir": "lib"
8
+ }
9
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "include": ["src/*.ts", "src/templates/*.ts"]
4
+ }
@@ -1,44 +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
- import {useHistory, useLocation} from '@docusaurus/router';
9
- import ExecutionEnvironment from '@docusaurus/ExecutionEnvironment';
10
- import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
11
-
12
- const SEARCH_PARAM_QUERY = 'q';
13
-
14
- function useSearchQuery() {
15
- const history = useHistory();
16
- const location = useLocation();
17
- const {siteConfig: {baseUrl} = {}} = useDocusaurusContext();
18
-
19
- return {
20
- searchValue:
21
- (ExecutionEnvironment.canUseDOM &&
22
- new URLSearchParams(location.search).get(SEARCH_PARAM_QUERY)) ||
23
- '',
24
- updateSearchPath: (searchValue) => {
25
- const searchParams = new URLSearchParams(location.search);
26
-
27
- if (searchValue) {
28
- searchParams.set(SEARCH_PARAM_QUERY, searchValue);
29
- } else {
30
- searchParams.delete(SEARCH_PARAM_QUERY);
31
- }
32
-
33
- history.replace({
34
- search: searchParams.toString(),
35
- });
36
- },
37
- generateSearchPageLink: (searchValue) => {
38
- // Refer to https://github.com/facebook/docusaurus/pull/2838
39
- return `${baseUrl}search?q=${encodeURIComponent(searchValue)}`;
40
- },
41
- };
42
- }
43
-
44
- export default useSearchQuery;