@docusaurus/theme-search-algolia 0.0.0-5953 → 0.0.0-5955
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 +26 -26
- package/package.json +10 -10
- package/src/theme/SearchBar/index.tsx +27 -26
|
@@ -73,29 +73,29 @@ function DocSearch({contextualSearch, externalUrlRegex, ...props}) {
|
|
|
73
73
|
DocSearchModal = Modal;
|
|
74
74
|
});
|
|
75
75
|
}, []);
|
|
76
|
-
const
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
76
|
+
const prepareSearchContainer = useCallback(() => {
|
|
77
|
+
if (!searchContainer.current) {
|
|
78
|
+
const divElement = document.createElement('div');
|
|
79
|
+
searchContainer.current = divElement;
|
|
80
|
+
document.body.insertBefore(divElement, document.body.firstChild);
|
|
81
|
+
}
|
|
82
|
+
}, []);
|
|
83
|
+
const openModal = useCallback(() => {
|
|
84
|
+
prepareSearchContainer();
|
|
85
|
+
importDocSearchModalIfNeeded().then(() => setIsOpen(true));
|
|
86
|
+
}, [importDocSearchModalIfNeeded, prepareSearchContainer]);
|
|
87
|
+
const closeModal = useCallback(() => {
|
|
87
88
|
setIsOpen(false);
|
|
88
|
-
searchContainer.current?.remove();
|
|
89
89
|
searchButtonRef.current?.focus();
|
|
90
|
-
}, [
|
|
91
|
-
const
|
|
90
|
+
}, []);
|
|
91
|
+
const handleInput = useCallback(
|
|
92
92
|
(event) => {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
93
|
+
// prevents duplicate key insertion in the modal input
|
|
94
|
+
event.preventDefault();
|
|
95
|
+
setInitialQuery(event.key);
|
|
96
|
+
openModal();
|
|
97
97
|
},
|
|
98
|
-
[
|
|
98
|
+
[openModal],
|
|
99
99
|
);
|
|
100
100
|
const navigator = useRef({
|
|
101
101
|
navigate({itemUrl}) {
|
|
@@ -122,8 +122,8 @@ function DocSearch({contextualSearch, externalUrlRegex, ...props}) {
|
|
|
122
122
|
() =>
|
|
123
123
|
// eslint-disable-next-line react/no-unstable-nested-components
|
|
124
124
|
(footerProps) =>
|
|
125
|
-
<ResultsFooter {...footerProps} onClose={
|
|
126
|
-
[
|
|
125
|
+
<ResultsFooter {...footerProps} onClose={closeModal} />,
|
|
126
|
+
[closeModal],
|
|
127
127
|
);
|
|
128
128
|
const transformSearchClient = useCallback(
|
|
129
129
|
(searchClient) => {
|
|
@@ -137,9 +137,9 @@ function DocSearch({contextualSearch, externalUrlRegex, ...props}) {
|
|
|
137
137
|
);
|
|
138
138
|
useDocSearchKeyboardEvents({
|
|
139
139
|
isOpen,
|
|
140
|
-
onOpen,
|
|
141
|
-
onClose,
|
|
142
|
-
onInput,
|
|
140
|
+
onOpen: openModal,
|
|
141
|
+
onClose: closeModal,
|
|
142
|
+
onInput: handleInput,
|
|
143
143
|
searchButtonRef,
|
|
144
144
|
});
|
|
145
145
|
return (
|
|
@@ -159,7 +159,7 @@ function DocSearch({contextualSearch, externalUrlRegex, ...props}) {
|
|
|
159
159
|
onTouchStart={importDocSearchModalIfNeeded}
|
|
160
160
|
onFocus={importDocSearchModalIfNeeded}
|
|
161
161
|
onMouseOver={importDocSearchModalIfNeeded}
|
|
162
|
-
onClick={
|
|
162
|
+
onClick={openModal}
|
|
163
163
|
ref={searchButtonRef}
|
|
164
164
|
translations={translations.button}
|
|
165
165
|
/>
|
|
@@ -169,7 +169,7 @@ function DocSearch({contextualSearch, externalUrlRegex, ...props}) {
|
|
|
169
169
|
searchContainer.current &&
|
|
170
170
|
createPortal(
|
|
171
171
|
<DocSearchModal
|
|
172
|
-
onClose={
|
|
172
|
+
onClose={closeModal}
|
|
173
173
|
initialScrollY={window.scrollY}
|
|
174
174
|
initialQuery={initialQuery}
|
|
175
175
|
navigator={navigator}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@docusaurus/theme-search-algolia",
|
|
3
|
-
"version": "0.0.0-
|
|
3
|
+
"version": "0.0.0-5955",
|
|
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.5.2",
|
|
37
|
-
"@docusaurus/core": "0.0.0-
|
|
38
|
-
"@docusaurus/logger": "0.0.0-
|
|
39
|
-
"@docusaurus/plugin-content-docs": "0.0.0-
|
|
40
|
-
"@docusaurus/theme-common": "0.0.0-
|
|
41
|
-
"@docusaurus/theme-translations": "0.0.0-
|
|
42
|
-
"@docusaurus/utils": "0.0.0-
|
|
43
|
-
"@docusaurus/utils-validation": "0.0.0-
|
|
37
|
+
"@docusaurus/core": "0.0.0-5955",
|
|
38
|
+
"@docusaurus/logger": "0.0.0-5955",
|
|
39
|
+
"@docusaurus/plugin-content-docs": "0.0.0-5955",
|
|
40
|
+
"@docusaurus/theme-common": "0.0.0-5955",
|
|
41
|
+
"@docusaurus/theme-translations": "0.0.0-5955",
|
|
42
|
+
"@docusaurus/utils": "0.0.0-5955",
|
|
43
|
+
"@docusaurus/utils-validation": "0.0.0-5955",
|
|
44
44
|
"algoliasearch": "^4.18.0",
|
|
45
45
|
"algoliasearch-helper": "^3.13.3",
|
|
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": "0.0.0-
|
|
54
|
+
"@docusaurus/module-type-aliases": "0.0.0-5955"
|
|
55
55
|
},
|
|
56
56
|
"peerDependencies": {
|
|
57
57
|
"react": "^18.0.0",
|
|
@@ -60,5 +60,5 @@
|
|
|
60
60
|
"engines": {
|
|
61
61
|
"node": ">=18.0"
|
|
62
62
|
},
|
|
63
|
-
"gitHead": "
|
|
63
|
+
"gitHead": "c8e95ee9d05bde7247861eda7582356a97a0d5ef"
|
|
64
64
|
}
|
|
@@ -136,31 +136,32 @@ function DocSearch({
|
|
|
136
136
|
});
|
|
137
137
|
}, []);
|
|
138
138
|
|
|
139
|
-
const
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
139
|
+
const prepareSearchContainer = useCallback(() => {
|
|
140
|
+
if (!searchContainer.current) {
|
|
141
|
+
const divElement = document.createElement('div');
|
|
142
|
+
searchContainer.current = divElement;
|
|
143
|
+
document.body.insertBefore(divElement, document.body.firstChild);
|
|
144
|
+
}
|
|
145
|
+
}, []);
|
|
146
|
+
|
|
147
|
+
const openModal = useCallback(() => {
|
|
148
|
+
prepareSearchContainer();
|
|
149
|
+
importDocSearchModalIfNeeded().then(() => setIsOpen(true));
|
|
150
|
+
}, [importDocSearchModalIfNeeded, prepareSearchContainer]);
|
|
149
151
|
|
|
150
|
-
const
|
|
152
|
+
const closeModal = useCallback(() => {
|
|
151
153
|
setIsOpen(false);
|
|
152
|
-
searchContainer.current?.remove();
|
|
153
154
|
searchButtonRef.current?.focus();
|
|
154
|
-
}, [
|
|
155
|
+
}, []);
|
|
155
156
|
|
|
156
|
-
const
|
|
157
|
+
const handleInput = useCallback(
|
|
157
158
|
(event: KeyboardEvent) => {
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
159
|
+
// prevents duplicate key insertion in the modal input
|
|
160
|
+
event.preventDefault();
|
|
161
|
+
setInitialQuery(event.key);
|
|
162
|
+
openModal();
|
|
162
163
|
},
|
|
163
|
-
[
|
|
164
|
+
[openModal],
|
|
164
165
|
);
|
|
165
166
|
|
|
166
167
|
const navigator = useRef({
|
|
@@ -192,8 +193,8 @@ function DocSearch({
|
|
|
192
193
|
() =>
|
|
193
194
|
// eslint-disable-next-line react/no-unstable-nested-components
|
|
194
195
|
(footerProps: Omit<ResultsFooterProps, 'onClose'>): JSX.Element =>
|
|
195
|
-
<ResultsFooter {...footerProps} onClose={
|
|
196
|
-
[
|
|
196
|
+
<ResultsFooter {...footerProps} onClose={closeModal} />,
|
|
197
|
+
[closeModal],
|
|
197
198
|
);
|
|
198
199
|
|
|
199
200
|
const transformSearchClient = useCallback(
|
|
@@ -210,9 +211,9 @@ function DocSearch({
|
|
|
210
211
|
|
|
211
212
|
useDocSearchKeyboardEvents({
|
|
212
213
|
isOpen,
|
|
213
|
-
onOpen,
|
|
214
|
-
onClose,
|
|
215
|
-
onInput,
|
|
214
|
+
onOpen: openModal,
|
|
215
|
+
onClose: closeModal,
|
|
216
|
+
onInput: handleInput,
|
|
216
217
|
searchButtonRef,
|
|
217
218
|
});
|
|
218
219
|
|
|
@@ -233,7 +234,7 @@ function DocSearch({
|
|
|
233
234
|
onTouchStart={importDocSearchModalIfNeeded}
|
|
234
235
|
onFocus={importDocSearchModalIfNeeded}
|
|
235
236
|
onMouseOver={importDocSearchModalIfNeeded}
|
|
236
|
-
onClick={
|
|
237
|
+
onClick={openModal}
|
|
237
238
|
ref={searchButtonRef}
|
|
238
239
|
translations={translations.button}
|
|
239
240
|
/>
|
|
@@ -243,7 +244,7 @@ function DocSearch({
|
|
|
243
244
|
searchContainer.current &&
|
|
244
245
|
createPortal(
|
|
245
246
|
<DocSearchModal
|
|
246
|
-
onClose={
|
|
247
|
+
onClose={closeModal}
|
|
247
248
|
initialScrollY={window.scrollY}
|
|
248
249
|
initialQuery={initialQuery}
|
|
249
250
|
navigator={navigator}
|