@docusaurus/theme-search-algolia 3.6.3-canary-6181 → 3.6.3-canary-6183
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/lib/theme/SearchBar/index.js +83 -66
- package/package.json +10 -10
- package/src/theme/SearchBar/index.tsx +102 -80
- package/src/theme-search-algolia.d.ts +27 -14
|
@@ -22,6 +22,70 @@ import Translate from '@docusaurus/Translate';
|
|
|
22
22
|
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
|
|
23
23
|
import translations from '@theme/SearchTranslations';
|
|
24
24
|
let DocSearchModal = null;
|
|
25
|
+
function importDocSearchModalIfNeeded() {
|
|
26
|
+
if (DocSearchModal) {
|
|
27
|
+
return Promise.resolve();
|
|
28
|
+
}
|
|
29
|
+
return Promise.all([
|
|
30
|
+
import('@docsearch/react/modal'),
|
|
31
|
+
import('@docsearch/react/style'),
|
|
32
|
+
import('./styles.css'),
|
|
33
|
+
]).then(([{DocSearchModal: Modal}]) => {
|
|
34
|
+
DocSearchModal = Modal;
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
function useNavigator({externalUrlRegex}) {
|
|
38
|
+
const history = useHistory();
|
|
39
|
+
const [navigator] = useState(() => {
|
|
40
|
+
return {
|
|
41
|
+
navigate(params) {
|
|
42
|
+
// Algolia results could contain URL's from other domains which cannot
|
|
43
|
+
// be served through history and should navigate with window.location
|
|
44
|
+
if (isRegexpStringMatch(externalUrlRegex, params.itemUrl)) {
|
|
45
|
+
window.location.href = params.itemUrl;
|
|
46
|
+
} else {
|
|
47
|
+
history.push(params.itemUrl);
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
});
|
|
52
|
+
return navigator;
|
|
53
|
+
}
|
|
54
|
+
function useTransformSearchClient() {
|
|
55
|
+
const {
|
|
56
|
+
siteMetadata: {docusaurusVersion},
|
|
57
|
+
} = useDocusaurusContext();
|
|
58
|
+
return useCallback(
|
|
59
|
+
(searchClient) => {
|
|
60
|
+
searchClient.addAlgoliaAgent('docusaurus', docusaurusVersion);
|
|
61
|
+
return searchClient;
|
|
62
|
+
},
|
|
63
|
+
[docusaurusVersion],
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
function useTransformItems(props) {
|
|
67
|
+
const processSearchResultUrl = useSearchResultUrlProcessor();
|
|
68
|
+
const [transformItems] = useState(() => {
|
|
69
|
+
return (items) =>
|
|
70
|
+
props.transformItems
|
|
71
|
+
? // Custom transformItems
|
|
72
|
+
props.transformItems(items)
|
|
73
|
+
: // Default transformItems
|
|
74
|
+
items.map((item) => ({
|
|
75
|
+
...item,
|
|
76
|
+
url: processSearchResultUrl(item.url),
|
|
77
|
+
}));
|
|
78
|
+
});
|
|
79
|
+
return transformItems;
|
|
80
|
+
}
|
|
81
|
+
function useResultsFooterComponent({closeModal}) {
|
|
82
|
+
return useMemo(
|
|
83
|
+
() =>
|
|
84
|
+
({state}) =>
|
|
85
|
+
<ResultsFooter state={state} onClose={closeModal} />,
|
|
86
|
+
[closeModal],
|
|
87
|
+
);
|
|
88
|
+
}
|
|
25
89
|
function Hit({hit, children}) {
|
|
26
90
|
return <Link to={hit.url}>{children}</Link>;
|
|
27
91
|
}
|
|
@@ -37,13 +101,11 @@ function ResultsFooter({state, onClose}) {
|
|
|
37
101
|
</Link>
|
|
38
102
|
);
|
|
39
103
|
}
|
|
40
|
-
function
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
const {siteMetadata} = useDocusaurusContext();
|
|
46
|
-
const processSearchResultUrl = useSearchResultUrlProcessor();
|
|
104
|
+
function useSearchParameters({contextualSearch, ...props}) {
|
|
105
|
+
function mergeFacetFilters(f1, f2) {
|
|
106
|
+
const normalize = (f) => (typeof f === 'string' ? [f] : f);
|
|
107
|
+
return [...normalize(f1), ...normalize(f2)];
|
|
108
|
+
}
|
|
47
109
|
const contextualSearchFacetFilters = useAlgoliaContextualFacetFilters();
|
|
48
110
|
const configFacetFilters = props.searchParameters?.facetFilters ?? [];
|
|
49
111
|
const facetFilters = contextualSearch
|
|
@@ -51,29 +113,22 @@ function DocSearch({contextualSearch, externalUrlRegex, ...props}) {
|
|
|
51
113
|
mergeFacetFilters(contextualSearchFacetFilters, configFacetFilters)
|
|
52
114
|
: // ... or use config facetFilters
|
|
53
115
|
configFacetFilters;
|
|
54
|
-
// We let
|
|
55
|
-
|
|
116
|
+
// We let users override default searchParameters if they want to
|
|
117
|
+
return {
|
|
56
118
|
...props.searchParameters,
|
|
57
119
|
facetFilters,
|
|
58
120
|
};
|
|
59
|
-
|
|
121
|
+
}
|
|
122
|
+
function DocSearch({externalUrlRegex, ...props}) {
|
|
123
|
+
const navigator = useNavigator({externalUrlRegex});
|
|
124
|
+
const searchParameters = useSearchParameters({...props});
|
|
125
|
+
const transformItems = useTransformItems(props);
|
|
126
|
+
const transformSearchClient = useTransformSearchClient();
|
|
60
127
|
const searchContainer = useRef(null);
|
|
61
|
-
// TODO remove after React 19 upgrade
|
|
128
|
+
// TODO remove "as any" after React 19 upgrade
|
|
62
129
|
const searchButtonRef = useRef(null);
|
|
63
130
|
const [isOpen, setIsOpen] = useState(false);
|
|
64
131
|
const [initialQuery, setInitialQuery] = useState(undefined);
|
|
65
|
-
const importDocSearchModalIfNeeded = useCallback(() => {
|
|
66
|
-
if (DocSearchModal) {
|
|
67
|
-
return Promise.resolve();
|
|
68
|
-
}
|
|
69
|
-
return Promise.all([
|
|
70
|
-
import('@docsearch/react/modal'),
|
|
71
|
-
import('@docsearch/react/style'),
|
|
72
|
-
import('./styles.css'),
|
|
73
|
-
]).then(([{DocSearchModal: Modal}]) => {
|
|
74
|
-
DocSearchModal = Modal;
|
|
75
|
-
});
|
|
76
|
-
}, []);
|
|
77
132
|
const prepareSearchContainer = useCallback(() => {
|
|
78
133
|
if (!searchContainer.current) {
|
|
79
134
|
const divElement = document.createElement('div');
|
|
@@ -84,7 +139,7 @@ function DocSearch({contextualSearch, externalUrlRegex, ...props}) {
|
|
|
84
139
|
const openModal = useCallback(() => {
|
|
85
140
|
prepareSearchContainer();
|
|
86
141
|
importDocSearchModalIfNeeded().then(() => setIsOpen(true));
|
|
87
|
-
}, [
|
|
142
|
+
}, [prepareSearchContainer]);
|
|
88
143
|
const closeModal = useCallback(() => {
|
|
89
144
|
setIsOpen(false);
|
|
90
145
|
searchButtonRef.current?.focus();
|
|
@@ -103,45 +158,7 @@ function DocSearch({contextualSearch, externalUrlRegex, ...props}) {
|
|
|
103
158
|
},
|
|
104
159
|
[openModal],
|
|
105
160
|
);
|
|
106
|
-
const
|
|
107
|
-
navigate({itemUrl}) {
|
|
108
|
-
// Algolia results could contain URL's from other domains which cannot
|
|
109
|
-
// be served through history and should navigate with window.location
|
|
110
|
-
if (isRegexpStringMatch(externalUrlRegex, itemUrl)) {
|
|
111
|
-
window.location.href = itemUrl;
|
|
112
|
-
} else {
|
|
113
|
-
history.push(itemUrl);
|
|
114
|
-
}
|
|
115
|
-
},
|
|
116
|
-
}).current;
|
|
117
|
-
const transformItems = useRef((items) =>
|
|
118
|
-
props.transformItems
|
|
119
|
-
? // Custom transformItems
|
|
120
|
-
props.transformItems(items)
|
|
121
|
-
: // Default transformItems
|
|
122
|
-
items.map((item) => ({
|
|
123
|
-
...item,
|
|
124
|
-
url: processSearchResultUrl(item.url),
|
|
125
|
-
})),
|
|
126
|
-
).current;
|
|
127
|
-
// @ts-expect-error: TODO fix lib issue after React 19, using JSX.Element
|
|
128
|
-
const resultsFooterComponent = useMemo(
|
|
129
|
-
() =>
|
|
130
|
-
// eslint-disable-next-line react/no-unstable-nested-components
|
|
131
|
-
(footerProps) =>
|
|
132
|
-
<ResultsFooter {...footerProps} onClose={closeModal} />,
|
|
133
|
-
[closeModal],
|
|
134
|
-
);
|
|
135
|
-
const transformSearchClient = useCallback(
|
|
136
|
-
(searchClient) => {
|
|
137
|
-
searchClient.addAlgoliaAgent(
|
|
138
|
-
'docusaurus',
|
|
139
|
-
siteMetadata.docusaurusVersion,
|
|
140
|
-
);
|
|
141
|
-
return searchClient;
|
|
142
|
-
},
|
|
143
|
-
[siteMetadata.docusaurusVersion],
|
|
144
|
-
);
|
|
161
|
+
const resultsFooterComponent = useResultsFooterComponent({closeModal});
|
|
145
162
|
useDocSearchKeyboardEvents({
|
|
146
163
|
isOpen,
|
|
147
164
|
onOpen: openModal,
|
|
@@ -168,7 +185,7 @@ function DocSearch({contextualSearch, externalUrlRegex, ...props}) {
|
|
|
168
185
|
onMouseOver={importDocSearchModalIfNeeded}
|
|
169
186
|
onClick={openModal}
|
|
170
187
|
ref={searchButtonRef}
|
|
171
|
-
translations={translations.button}
|
|
188
|
+
translations={props.translations?.button ?? translations.button}
|
|
172
189
|
/>
|
|
173
190
|
|
|
174
191
|
{isOpen &&
|
|
@@ -186,10 +203,10 @@ function DocSearch({contextualSearch, externalUrlRegex, ...props}) {
|
|
|
186
203
|
{...(props.searchPagePath && {
|
|
187
204
|
resultsFooterComponent,
|
|
188
205
|
})}
|
|
206
|
+
placeholder={translations.placeholder}
|
|
189
207
|
{...props}
|
|
208
|
+
translations={props.translations?.modal ?? translations.modal}
|
|
190
209
|
searchParameters={searchParameters}
|
|
191
|
-
placeholder={translations.placeholder}
|
|
192
|
-
translations={translations.modal}
|
|
193
210
|
/>,
|
|
194
211
|
searchContainer.current,
|
|
195
212
|
)}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@docusaurus/theme-search-algolia",
|
|
3
|
-
"version": "3.6.3-canary-
|
|
3
|
+
"version": "3.6.3-canary-6183",
|
|
4
4
|
"description": "Algolia search component for Docusaurus.",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"sideEffects": [
|
|
@@ -34,13 +34,13 @@
|
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"@docsearch/react": "^3.8.1",
|
|
37
|
-
"@docusaurus/core": "3.6.3-canary-
|
|
38
|
-
"@docusaurus/logger": "3.6.3-canary-
|
|
39
|
-
"@docusaurus/plugin-content-docs": "3.6.3-canary-
|
|
40
|
-
"@docusaurus/theme-common": "3.6.3-canary-
|
|
41
|
-
"@docusaurus/theme-translations": "3.6.3-canary-
|
|
42
|
-
"@docusaurus/utils": "3.6.3-canary-
|
|
43
|
-
"@docusaurus/utils-validation": "3.6.3-canary-
|
|
37
|
+
"@docusaurus/core": "3.6.3-canary-6183",
|
|
38
|
+
"@docusaurus/logger": "3.6.3-canary-6183",
|
|
39
|
+
"@docusaurus/plugin-content-docs": "3.6.3-canary-6183",
|
|
40
|
+
"@docusaurus/theme-common": "3.6.3-canary-6183",
|
|
41
|
+
"@docusaurus/theme-translations": "3.6.3-canary-6183",
|
|
42
|
+
"@docusaurus/utils": "3.6.3-canary-6183",
|
|
43
|
+
"@docusaurus/utils-validation": "3.6.3-canary-6183",
|
|
44
44
|
"algoliasearch": "^5.17.1",
|
|
45
45
|
"algoliasearch-helper": "^3.22.6",
|
|
46
46
|
"clsx": "^2.0.0",
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"utility-types": "^3.10.0"
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
|
-
"@docusaurus/module-type-aliases": "3.6.3-canary-
|
|
54
|
+
"@docusaurus/module-type-aliases": "3.6.3-canary-6183"
|
|
55
55
|
},
|
|
56
56
|
"peerDependencies": {
|
|
57
57
|
"react": "^18.0.0 || ^19.0.0",
|
|
@@ -60,5 +60,5 @@
|
|
|
60
60
|
"engines": {
|
|
61
61
|
"node": ">=18.0"
|
|
62
62
|
},
|
|
63
|
-
"gitHead": "
|
|
63
|
+
"gitHead": "6cef90aa1f1fefedf86fe1ae9f28a5c74cb79ba9"
|
|
64
64
|
}
|
|
@@ -34,6 +34,7 @@ import type {
|
|
|
34
34
|
DocSearchModalProps,
|
|
35
35
|
StoredDocSearchHit,
|
|
36
36
|
DocSearchTransformClient,
|
|
37
|
+
DocSearchHit,
|
|
37
38
|
} from '@docsearch/react';
|
|
38
39
|
|
|
39
40
|
import type {AutocompleteState} from '@algolia/autocomplete-core';
|
|
@@ -50,6 +51,85 @@ type DocSearchProps = Omit<
|
|
|
50
51
|
|
|
51
52
|
let DocSearchModal: typeof DocSearchModalType | null = null;
|
|
52
53
|
|
|
54
|
+
function importDocSearchModalIfNeeded() {
|
|
55
|
+
if (DocSearchModal) {
|
|
56
|
+
return Promise.resolve();
|
|
57
|
+
}
|
|
58
|
+
return Promise.all([
|
|
59
|
+
import('@docsearch/react/modal') as Promise<
|
|
60
|
+
typeof import('@docsearch/react')
|
|
61
|
+
>,
|
|
62
|
+
import('@docsearch/react/style'),
|
|
63
|
+
import('./styles.css'),
|
|
64
|
+
]).then(([{DocSearchModal: Modal}]) => {
|
|
65
|
+
DocSearchModal = Modal;
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function useNavigator({
|
|
70
|
+
externalUrlRegex,
|
|
71
|
+
}: Pick<DocSearchProps, 'externalUrlRegex'>) {
|
|
72
|
+
const history = useHistory();
|
|
73
|
+
const [navigator] = useState<DocSearchModalProps['navigator']>(() => {
|
|
74
|
+
return {
|
|
75
|
+
navigate(params) {
|
|
76
|
+
// Algolia results could contain URL's from other domains which cannot
|
|
77
|
+
// be served through history and should navigate with window.location
|
|
78
|
+
if (isRegexpStringMatch(externalUrlRegex, params.itemUrl)) {
|
|
79
|
+
window.location.href = params.itemUrl;
|
|
80
|
+
} else {
|
|
81
|
+
history.push(params.itemUrl);
|
|
82
|
+
}
|
|
83
|
+
},
|
|
84
|
+
};
|
|
85
|
+
});
|
|
86
|
+
return navigator;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function useTransformSearchClient(): DocSearchModalProps['transformSearchClient'] {
|
|
90
|
+
const {
|
|
91
|
+
siteMetadata: {docusaurusVersion},
|
|
92
|
+
} = useDocusaurusContext();
|
|
93
|
+
return useCallback(
|
|
94
|
+
(searchClient: DocSearchTransformClient) => {
|
|
95
|
+
searchClient.addAlgoliaAgent('docusaurus', docusaurusVersion);
|
|
96
|
+
return searchClient;
|
|
97
|
+
},
|
|
98
|
+
[docusaurusVersion],
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function useTransformItems(props: Pick<DocSearchProps, 'transformItems'>) {
|
|
103
|
+
const processSearchResultUrl = useSearchResultUrlProcessor();
|
|
104
|
+
const [transformItems] = useState<DocSearchModalProps['transformItems']>(
|
|
105
|
+
() => {
|
|
106
|
+
return (items: DocSearchHit[]) =>
|
|
107
|
+
props.transformItems
|
|
108
|
+
? // Custom transformItems
|
|
109
|
+
props.transformItems(items)
|
|
110
|
+
: // Default transformItems
|
|
111
|
+
items.map((item) => ({
|
|
112
|
+
...item,
|
|
113
|
+
url: processSearchResultUrl(item.url),
|
|
114
|
+
}));
|
|
115
|
+
},
|
|
116
|
+
);
|
|
117
|
+
return transformItems;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function useResultsFooterComponent({
|
|
121
|
+
closeModal,
|
|
122
|
+
}: {
|
|
123
|
+
closeModal: () => void;
|
|
124
|
+
}): DocSearchProps['resultsFooterComponent'] {
|
|
125
|
+
return useMemo(
|
|
126
|
+
() =>
|
|
127
|
+
({state}) =>
|
|
128
|
+
<ResultsFooter state={state} onClose={closeModal} />,
|
|
129
|
+
[closeModal],
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
|
|
53
133
|
function Hit({
|
|
54
134
|
hit,
|
|
55
135
|
children,
|
|
@@ -79,19 +159,15 @@ function ResultsFooter({state, onClose}: ResultsFooterProps) {
|
|
|
79
159
|
);
|
|
80
160
|
}
|
|
81
161
|
|
|
82
|
-
function
|
|
83
|
-
const normalize = (f: FacetFilters): FacetFilters =>
|
|
84
|
-
typeof f === 'string' ? [f] : f;
|
|
85
|
-
return [...normalize(f1), ...normalize(f2)];
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
function DocSearch({
|
|
162
|
+
function useSearchParameters({
|
|
89
163
|
contextualSearch,
|
|
90
|
-
externalUrlRegex,
|
|
91
164
|
...props
|
|
92
|
-
}: DocSearchProps) {
|
|
93
|
-
|
|
94
|
-
|
|
165
|
+
}: DocSearchProps): DocSearchProps['searchParameters'] {
|
|
166
|
+
function mergeFacetFilters(f1: FacetFilters, f2: FacetFilters): FacetFilters {
|
|
167
|
+
const normalize = (f: FacetFilters): FacetFilters =>
|
|
168
|
+
typeof f === 'string' ? [f] : f;
|
|
169
|
+
return [...normalize(f1), ...normalize(f2)];
|
|
170
|
+
}
|
|
95
171
|
|
|
96
172
|
const contextualSearchFacetFilters =
|
|
97
173
|
useAlgoliaContextualFacetFilters() as FacetFilters;
|
|
@@ -105,37 +181,27 @@ function DocSearch({
|
|
|
105
181
|
: // ... or use config facetFilters
|
|
106
182
|
configFacetFilters;
|
|
107
183
|
|
|
108
|
-
// We let
|
|
109
|
-
|
|
184
|
+
// We let users override default searchParameters if they want to
|
|
185
|
+
return {
|
|
110
186
|
...props.searchParameters,
|
|
111
187
|
facetFilters,
|
|
112
188
|
};
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
function DocSearch({externalUrlRegex, ...props}: DocSearchProps) {
|
|
192
|
+
const navigator = useNavigator({externalUrlRegex});
|
|
193
|
+
const searchParameters = useSearchParameters({...props});
|
|
194
|
+
const transformItems = useTransformItems(props);
|
|
195
|
+
const transformSearchClient = useTransformSearchClient();
|
|
113
196
|
|
|
114
|
-
const history = useHistory();
|
|
115
197
|
const searchContainer = useRef<HTMLDivElement | null>(null);
|
|
116
|
-
// TODO remove after React 19 upgrade
|
|
198
|
+
// TODO remove "as any" after React 19 upgrade
|
|
117
199
|
const searchButtonRef = useRef<HTMLButtonElement>(null as any);
|
|
118
200
|
const [isOpen, setIsOpen] = useState(false);
|
|
119
201
|
const [initialQuery, setInitialQuery] = useState<string | undefined>(
|
|
120
202
|
undefined,
|
|
121
203
|
);
|
|
122
204
|
|
|
123
|
-
const importDocSearchModalIfNeeded = useCallback(() => {
|
|
124
|
-
if (DocSearchModal) {
|
|
125
|
-
return Promise.resolve();
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
return Promise.all([
|
|
129
|
-
import('@docsearch/react/modal') as Promise<
|
|
130
|
-
typeof import('@docsearch/react')
|
|
131
|
-
>,
|
|
132
|
-
import('@docsearch/react/style'),
|
|
133
|
-
import('./styles.css'),
|
|
134
|
-
]).then(([{DocSearchModal: Modal}]) => {
|
|
135
|
-
DocSearchModal = Modal;
|
|
136
|
-
});
|
|
137
|
-
}, []);
|
|
138
|
-
|
|
139
205
|
const prepareSearchContainer = useCallback(() => {
|
|
140
206
|
if (!searchContainer.current) {
|
|
141
207
|
const divElement = document.createElement('div');
|
|
@@ -147,7 +213,7 @@ function DocSearch({
|
|
|
147
213
|
const openModal = useCallback(() => {
|
|
148
214
|
prepareSearchContainer();
|
|
149
215
|
importDocSearchModalIfNeeded().then(() => setIsOpen(true));
|
|
150
|
-
}, [
|
|
216
|
+
}, [prepareSearchContainer]);
|
|
151
217
|
|
|
152
218
|
const closeModal = useCallback(() => {
|
|
153
219
|
setIsOpen(false);
|
|
@@ -169,51 +235,7 @@ function DocSearch({
|
|
|
169
235
|
[openModal],
|
|
170
236
|
);
|
|
171
237
|
|
|
172
|
-
const
|
|
173
|
-
navigate({itemUrl}: {itemUrl?: string}) {
|
|
174
|
-
// Algolia results could contain URL's from other domains which cannot
|
|
175
|
-
// be served through history and should navigate with window.location
|
|
176
|
-
if (isRegexpStringMatch(externalUrlRegex, itemUrl)) {
|
|
177
|
-
window.location.href = itemUrl!;
|
|
178
|
-
} else {
|
|
179
|
-
history.push(itemUrl!);
|
|
180
|
-
}
|
|
181
|
-
},
|
|
182
|
-
}).current;
|
|
183
|
-
|
|
184
|
-
const transformItems = useRef<DocSearchModalProps['transformItems']>(
|
|
185
|
-
(items) =>
|
|
186
|
-
props.transformItems
|
|
187
|
-
? // Custom transformItems
|
|
188
|
-
props.transformItems(items)
|
|
189
|
-
: // Default transformItems
|
|
190
|
-
items.map((item) => ({
|
|
191
|
-
...item,
|
|
192
|
-
url: processSearchResultUrl(item.url),
|
|
193
|
-
})),
|
|
194
|
-
).current;
|
|
195
|
-
|
|
196
|
-
// @ts-expect-error: TODO fix lib issue after React 19, using JSX.Element
|
|
197
|
-
const resultsFooterComponent: DocSearchProps['resultsFooterComponent'] =
|
|
198
|
-
useMemo(
|
|
199
|
-
() =>
|
|
200
|
-
// eslint-disable-next-line react/no-unstable-nested-components
|
|
201
|
-
(footerProps: Omit<ResultsFooterProps, 'onClose'>): ReactNode =>
|
|
202
|
-
<ResultsFooter {...footerProps} onClose={closeModal} />,
|
|
203
|
-
[closeModal],
|
|
204
|
-
);
|
|
205
|
-
|
|
206
|
-
const transformSearchClient = useCallback(
|
|
207
|
-
(searchClient: DocSearchTransformClient) => {
|
|
208
|
-
searchClient.addAlgoliaAgent(
|
|
209
|
-
'docusaurus',
|
|
210
|
-
siteMetadata.docusaurusVersion,
|
|
211
|
-
);
|
|
212
|
-
|
|
213
|
-
return searchClient;
|
|
214
|
-
},
|
|
215
|
-
[siteMetadata.docusaurusVersion],
|
|
216
|
-
);
|
|
238
|
+
const resultsFooterComponent = useResultsFooterComponent({closeModal});
|
|
217
239
|
|
|
218
240
|
useDocSearchKeyboardEvents({
|
|
219
241
|
isOpen,
|
|
@@ -242,7 +264,7 @@ function DocSearch({
|
|
|
242
264
|
onMouseOver={importDocSearchModalIfNeeded}
|
|
243
265
|
onClick={openModal}
|
|
244
266
|
ref={searchButtonRef}
|
|
245
|
-
translations={translations.button}
|
|
267
|
+
translations={props.translations?.button ?? translations.button}
|
|
246
268
|
/>
|
|
247
269
|
|
|
248
270
|
{isOpen &&
|
|
@@ -260,10 +282,10 @@ function DocSearch({
|
|
|
260
282
|
{...(props.searchPagePath && {
|
|
261
283
|
resultsFooterComponent,
|
|
262
284
|
})}
|
|
285
|
+
placeholder={translations.placeholder}
|
|
263
286
|
{...props}
|
|
287
|
+
translations={props.translations?.modal ?? translations.modal}
|
|
264
288
|
searchParameters={searchParameters}
|
|
265
|
-
placeholder={translations.placeholder}
|
|
266
|
-
translations={translations.modal}
|
|
267
289
|
/>,
|
|
268
290
|
searchContainer.current,
|
|
269
291
|
)}
|
|
@@ -7,23 +7,36 @@
|
|
|
7
7
|
|
|
8
8
|
declare module '@docusaurus/theme-search-algolia' {
|
|
9
9
|
import type {DeepPartial} from 'utility-types';
|
|
10
|
+
import type {DocSearchProps} from '@docsearch/react';
|
|
10
11
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
12
|
+
// DocSearch props that Docusaurus exposes directly through props forwarding
|
|
13
|
+
type DocusaurusDocSearchProps = Pick<
|
|
14
|
+
DocSearchProps,
|
|
15
|
+
| 'appId'
|
|
16
|
+
| 'apiKey'
|
|
17
|
+
| 'indexName'
|
|
18
|
+
| 'placeholder'
|
|
19
|
+
| 'translations'
|
|
20
|
+
| 'searchParameters'
|
|
21
|
+
| 'insights'
|
|
22
|
+
| 'initialQuery'
|
|
23
|
+
>;
|
|
24
|
+
|
|
25
|
+
type ThemeConfigAlgolia = DocusaurusDocSearchProps & {
|
|
26
|
+
// Docusaurus custom options, not coming from DocSearch
|
|
27
|
+
contextualSearch: boolean;
|
|
28
|
+
externalUrlRegex?: string;
|
|
29
|
+
searchPagePath: string | false | null;
|
|
30
|
+
replaceSearchResultPathname?: {
|
|
31
|
+
from: string;
|
|
32
|
+
to: string;
|
|
25
33
|
};
|
|
26
34
|
};
|
|
35
|
+
|
|
36
|
+
export type ThemeConfig = DocusaurusDocSearchProps & {
|
|
37
|
+
algolia: ThemeConfigAlgolia;
|
|
38
|
+
};
|
|
39
|
+
|
|
27
40
|
export type UserThemeConfig = DeepPartial<ThemeConfig>;
|
|
28
41
|
}
|
|
29
42
|
|