@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.
- package/copyUntypedFiles.js +20 -0
- package/lib/index.d.ts +11 -0
- package/lib/index.js +85 -0
- package/lib/templates/opensearch.d.ts +8 -0
- package/lib/templates/opensearch.js +23 -0
- package/lib/theme/SearchBar/index.d.ts +9 -0
- package/lib/theme/SearchBar/index.js +153 -0
- package/lib/theme/SearchBar/styles.css +21 -0
- package/lib/theme/SearchBar/styles.module.css +20 -0
- package/lib/theme/SearchMetadata/index.d.ts +10 -0
- package/lib/theme/SearchMetadata/index.js +20 -0
- package/lib/theme/SearchPage/index.d.ts +9 -0
- package/lib/theme/SearchPage/index.js +299 -0
- package/lib/theme/SearchPage/styles.module.css +119 -0
- package/lib/theme/hooks/useAlgoliaContextualFacetFilters.d.ts +8 -0
- package/lib/theme/hooks/useAlgoliaContextualFacetFilters.js +15 -0
- package/lib/theme/hooks/useSearchQuery.d.ts +9 -0
- package/lib/theme/hooks/useSearchQuery.js +43 -0
- package/lib/validateThemeConfig.d.ts +13 -0
- package/lib/validateThemeConfig.js +39 -0
- package/package.json +24 -12
- package/src/__tests__/validateThemeConfig.test.js +14 -0
- package/src/{index.js → index.ts} +37 -19
- package/src/templates/{opensearch.js → opensearch.ts} +4 -2
- package/src/theme/SearchBar/{index.js → index.tsx} +78 -26
- package/src/theme/{SearchMetadatas/index.js → SearchMetadata/index.tsx} +9 -2
- package/src/theme/SearchPage/{index.js → index.tsx} +81 -51
- package/src/theme/hooks/{useAlgoliaContextualFacetFilters.js → useAlgoliaContextualFacetFilters.ts} +4 -3
- package/src/theme/hooks/useSearchQuery.ts +63 -0
- package/src/theme-search-algolia.d.ts +47 -0
- package/src/types.d.ts +10 -0
- package/src/{validateThemeConfig.js → validateThemeConfig.ts} +10 -7
- package/tsconfig.browser.json +8 -0
- package/tsconfig.json +9 -0
- package/tsconfig.server.json +4 -0
- 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
|
-
|
|
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
|
-
|
|
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
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -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;
|