react-instantsearch 7.25.0 → 7.26.1
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/dist/cjs/components/AutocompleteSearch.js +25 -36
- package/dist/cjs/components/Carousel.js +25 -39
- package/dist/cjs/components/index.js +6 -15
- package/dist/cjs/index.js +85 -44
- package/dist/cjs/lib/useStickToBottom.js +11 -17
- package/dist/cjs/package.json +4 -1
- package/dist/cjs/types/PartialKeys.js +2 -1
- package/dist/cjs/types/Translatable.js +2 -1
- package/dist/cjs/types/index.js +1 -26
- package/dist/cjs/ui/Breadcrumb.js +52 -57
- package/dist/cjs/ui/ClearRefinements.js +23 -28
- package/dist/cjs/ui/CurrentRefinements.js +48 -50
- package/dist/cjs/ui/HierarchicalMenu.js +71 -79
- package/dist/cjs/ui/Highlight.js +21 -25
- package/dist/cjs/ui/HitsPerPage.js +31 -34
- package/dist/cjs/ui/InfiniteHits.js +83 -88
- package/dist/cjs/ui/InternalHighlight.js +9 -10
- package/dist/cjs/ui/Menu.js +53 -56
- package/dist/cjs/ui/Pagination.js +117 -124
- package/dist/cjs/ui/PoweredBy.js +33 -37
- package/dist/cjs/ui/RangeInput.js +96 -116
- package/dist/cjs/ui/RefinementList.js +66 -67
- package/dist/cjs/ui/ReverseHighlight.js +21 -25
- package/dist/cjs/ui/SearchBox.js +141 -151
- package/dist/cjs/ui/ShowMoreButton.js +14 -17
- package/dist/cjs/ui/Snippet.js +21 -25
- package/dist/cjs/ui/SortBy.js +32 -36
- package/dist/cjs/ui/Stats.js +29 -32
- package/dist/cjs/ui/ToggleRefinement.js +30 -33
- package/dist/cjs/ui/lib/capitalize.js +5 -7
- package/dist/cjs/ui/lib/index.js +8 -26
- package/dist/cjs/ui/lib/isModifierClick.js +6 -8
- package/dist/cjs/widgets/Autocomplete.js +450 -491
- package/dist/cjs/widgets/Breadcrumb.js +34 -47
- package/dist/cjs/widgets/Chat.js +174 -221
- package/dist/cjs/widgets/ClearRefinements.js +31 -42
- package/dist/cjs/widgets/CurrentRefinements.js +27 -32
- package/dist/cjs/widgets/FilterSuggestions.js +46 -53
- package/dist/cjs/widgets/FrequentlyBoughtTogether.js +66 -74
- package/dist/cjs/widgets/HierarchicalMenu.js +53 -68
- package/dist/cjs/widgets/Highlight.js +31 -31
- package/dist/cjs/widgets/Hits.js +59 -64
- package/dist/cjs/widgets/HitsPerPage.js +32 -38
- package/dist/cjs/widgets/InfiniteHits.js +44 -61
- package/dist/cjs/widgets/LookingSimilar.js +66 -74
- package/dist/cjs/widgets/Menu.js +48 -62
- package/dist/cjs/widgets/Pagination.js +59 -74
- package/dist/cjs/widgets/PoweredBy.js +14 -17
- package/dist/cjs/widgets/RangeInput.js +38 -51
- package/dist/cjs/widgets/RefinementList.js +100 -125
- package/dist/cjs/widgets/RelatedProducts.js +66 -74
- package/dist/cjs/widgets/ReverseHighlight.js +38 -44
- package/dist/cjs/widgets/SearchBox.js +63 -86
- package/dist/cjs/widgets/Snippet.js +31 -31
- package/dist/cjs/widgets/SortBy.js +26 -32
- package/dist/cjs/widgets/Stats.js +54 -68
- package/dist/cjs/widgets/ToggleRefinement.js +33 -38
- package/dist/cjs/widgets/TrendingItems.js +70 -78
- package/dist/cjs/widgets/chat/tools/SearchIndexTool.js +92 -99
- package/dist/cjs/widgets/index.js +77 -289
- package/dist/cjs/widgets/index.umd.js +68 -322
- package/dist/es/components/AutocompleteSearch.js +22 -28
- package/dist/es/components/Carousel.js +23 -31
- package/dist/es/components/index.js +1 -1
- package/dist/es/index.js +29 -4
- package/dist/es/lib/useStickToBottom.js +10 -12
- package/dist/es/package.json +4 -0
- package/dist/es/types/PartialKeys.js +1 -1
- package/dist/es/types/Translatable.js +1 -1
- package/dist/es/types/index.js +1 -2
- package/dist/es/ui/Breadcrumb.js +49 -49
- package/dist/es/ui/ClearRefinements.js +21 -21
- package/dist/es/ui/CurrentRefinements.js +46 -43
- package/dist/es/ui/HierarchicalMenu.js +68 -71
- package/dist/es/ui/Highlight.js +19 -18
- package/dist/es/ui/HitsPerPage.js +29 -27
- package/dist/es/ui/InfiniteHits.js +80 -80
- package/dist/es/ui/InternalHighlight.js +7 -4
- package/dist/es/ui/Menu.js +51 -49
- package/dist/es/ui/Pagination.js +114 -116
- package/dist/es/ui/PoweredBy.js +31 -30
- package/dist/es/ui/RangeInput.js +93 -107
- package/dist/es/ui/RefinementList.js +64 -60
- package/dist/es/ui/ReverseHighlight.js +19 -18
- package/dist/es/ui/SearchBox.js +138 -143
- package/dist/es/ui/ShowMoreButton.js +13 -11
- package/dist/es/ui/Snippet.js +19 -18
- package/dist/es/ui/SortBy.js +30 -29
- package/dist/es/ui/Stats.js +27 -25
- package/dist/es/ui/ToggleRefinement.js +28 -26
- package/dist/es/ui/lib/capitalize.js +5 -3
- package/dist/es/ui/lib/index.js +2 -2
- package/dist/es/ui/lib/isModifierClick.js +6 -4
- package/dist/es/widgets/Autocomplete.js +438 -474
- package/dist/es/widgets/Breadcrumb.js +31 -39
- package/dist/es/widgets/Chat.js +164 -196
- package/dist/es/widgets/ClearRefinements.js +28 -34
- package/dist/es/widgets/CurrentRefinements.js +24 -24
- package/dist/es/widgets/FilterSuggestions.js +41 -42
- package/dist/es/widgets/FrequentlyBoughtTogether.js +62 -65
- package/dist/es/widgets/HierarchicalMenu.js +50 -60
- package/dist/es/widgets/Highlight.js +30 -25
- package/dist/es/widgets/Hits.js +54 -53
- package/dist/es/widgets/HitsPerPage.js +29 -30
- package/dist/es/widgets/InfiniteHits.js +41 -53
- package/dist/es/widgets/LookingSimilar.js +62 -65
- package/dist/es/widgets/Menu.js +45 -54
- package/dist/es/widgets/Pagination.js +56 -66
- package/dist/es/widgets/PoweredBy.js +12 -10
- package/dist/es/widgets/RangeInput.js +35 -43
- package/dist/es/widgets/RefinementList.js +98 -118
- package/dist/es/widgets/RelatedProducts.js +61 -64
- package/dist/es/widgets/ReverseHighlight.js +36 -37
- package/dist/es/widgets/SearchBox.js +61 -79
- package/dist/es/widgets/Snippet.js +30 -25
- package/dist/es/widgets/SortBy.js +23 -24
- package/dist/es/widgets/Stats.js +51 -60
- package/dist/es/widgets/ToggleRefinement.js +30 -30
- package/dist/es/widgets/TrendingItems.js +65 -68
- package/dist/es/widgets/chat/tools/SearchIndexTool.js +89 -91
- package/dist/es/widgets/index.js +27 -26
- package/dist/es/widgets/index.umd.js +36 -33
- package/dist/umd/ReactInstantSearch.js +23411 -30098
- package/dist/umd/ReactInstantSearch.min.js +3 -3
- package/package.json +8 -12
- package/dist/umd/ReactInstantSearch.js.map +0 -1
- package/dist/umd/ReactInstantSearch.min.js.map +0 -1
|
@@ -1,522 +1,486 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
14
|
-
function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
|
|
15
|
-
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
|
|
16
|
-
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
|
|
17
|
-
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
18
|
-
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
19
|
-
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
20
|
-
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
21
|
-
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
|
|
22
|
-
import { createAutocompleteComponent, createAutocompleteDetachedContainerComponent, createAutocompleteDetachedOverlayComponent, createAutocompleteDetachedFormContainerComponent, createAutocompleteDetachedSearchButtonComponent, createAutocompleteIndexComponent, createAutocompletePanelComponent, createAutocompletePropGetters, createAutocompleteSuggestionComponent, createAutocompleteRecentSearchComponent, createAutocompleteStorage, cx } from 'instantsearch-ui-components';
|
|
23
|
-
import React, { createElement, Fragment, useEffect, useId, useMemo, useRef, useState } from 'react';
|
|
24
|
-
import { Configure, Index, useAutocomplete, useInstantSearch, useSearchBox } from 'react-instantsearch-core';
|
|
25
|
-
import { AutocompleteSearch } from "../components/AutocompleteSearch.js";
|
|
26
|
-
import { ReverseHighlight } from "./ReverseHighlight.js";
|
|
1
|
+
import { _ as _$1 } from '@swc/helpers/cjs/_object_spread.cjs';
|
|
2
|
+
import { _ as _$4 } from '@swc/helpers/cjs/_object_spread_props.cjs';
|
|
3
|
+
import { _ } from '@swc/helpers/cjs/_object_without_properties.cjs';
|
|
4
|
+
import { _ as _$5 } from '@swc/helpers/cjs/_sliced_to_array.cjs';
|
|
5
|
+
import { _ as _$2 } from '@swc/helpers/cjs/_to_consumable_array.cjs';
|
|
6
|
+
import { _ as _$3 } from '@swc/helpers/cjs/_type_of.cjs';
|
|
7
|
+
import { createAutocompleteComponent, createAutocompletePanelComponent, createAutocompleteIndexComponent, createAutocompleteSuggestionComponent, createAutocompleteRecentSearchComponent, createAutocompleteDetachedContainerComponent, createAutocompleteDetachedOverlayComponent, createAutocompleteDetachedFormContainerComponent, createAutocompleteDetachedSearchButtonComponent, createAutocompletePropGetters, createAutocompleteStorage, cx } from 'instantsearch-ui-components';
|
|
8
|
+
import React, { createElement, Fragment, useEffect, useMemo, useRef, useState } from 'react';
|
|
9
|
+
import { useInstantSearch, useSearchBox, Index, Configure, useAutocomplete } from 'react-instantsearch-core';
|
|
10
|
+
import { AutocompleteSearch } from '../components/AutocompleteSearch.js';
|
|
11
|
+
import { ReverseHighlight } from './ReverseHighlight.js';
|
|
12
|
+
|
|
27
13
|
var Autocomplete = createAutocompleteComponent({
|
|
28
|
-
|
|
29
|
-
|
|
14
|
+
createElement: createElement,
|
|
15
|
+
Fragment: Fragment
|
|
30
16
|
});
|
|
31
17
|
var AutocompletePanel = createAutocompletePanelComponent({
|
|
32
|
-
|
|
33
|
-
|
|
18
|
+
createElement: createElement,
|
|
19
|
+
Fragment: Fragment
|
|
34
20
|
});
|
|
35
21
|
var AutocompleteIndex = createAutocompleteIndexComponent({
|
|
36
|
-
|
|
37
|
-
|
|
22
|
+
createElement: createElement,
|
|
23
|
+
Fragment: Fragment
|
|
38
24
|
});
|
|
39
25
|
var AutocompleteSuggestion = createAutocompleteSuggestionComponent({
|
|
40
|
-
|
|
41
|
-
|
|
26
|
+
createElement: createElement,
|
|
27
|
+
Fragment: Fragment
|
|
42
28
|
});
|
|
43
29
|
var AutocompleteRecentSearch = createAutocompleteRecentSearchComponent({
|
|
44
|
-
|
|
45
|
-
|
|
30
|
+
createElement: createElement,
|
|
31
|
+
Fragment: Fragment
|
|
46
32
|
});
|
|
47
33
|
var AutocompleteDetachedContainer = createAutocompleteDetachedContainerComponent({
|
|
48
|
-
|
|
49
|
-
|
|
34
|
+
createElement: createElement,
|
|
35
|
+
Fragment: Fragment
|
|
50
36
|
});
|
|
51
37
|
var AutocompleteDetachedOverlay = createAutocompleteDetachedOverlayComponent({
|
|
52
|
-
|
|
53
|
-
|
|
38
|
+
createElement: createElement,
|
|
39
|
+
Fragment: Fragment
|
|
54
40
|
});
|
|
55
41
|
var AutocompleteDetachedFormContainer = createAutocompleteDetachedFormContainerComponent({
|
|
56
|
-
|
|
57
|
-
|
|
42
|
+
createElement: createElement,
|
|
43
|
+
Fragment: Fragment
|
|
58
44
|
});
|
|
59
45
|
var AutocompleteDetachedSearchButton = createAutocompleteDetachedSearchButtonComponent({
|
|
60
|
-
|
|
61
|
-
|
|
46
|
+
createElement: createElement,
|
|
47
|
+
Fragment: Fragment
|
|
62
48
|
});
|
|
49
|
+
var id = 0;
|
|
63
50
|
var usePropGetters = createAutocompletePropGetters({
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
51
|
+
useEffect: useEffect,
|
|
52
|
+
useId: React.useId || function() {
|
|
53
|
+
return React.useState(function() {
|
|
54
|
+
return (id++).toString();
|
|
55
|
+
});
|
|
56
|
+
},
|
|
57
|
+
useMemo: useMemo,
|
|
58
|
+
useRef: useRef,
|
|
59
|
+
useState: useState
|
|
69
60
|
});
|
|
70
61
|
var useStorage = createAutocompleteStorage({
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
62
|
+
useEffect: useEffect,
|
|
63
|
+
useMemo: useMemo,
|
|
64
|
+
useState: useState
|
|
74
65
|
});
|
|
75
66
|
var DEFAULT_DETACHED_MEDIA_QUERY = '(max-width: 680px)';
|
|
76
67
|
var DEFAULT_DETACHED_MODAL_MEDIA_QUERY = '(min-width: 680px)';
|
|
77
68
|
var DETACHED_MEDIA_QUERY_CSS_VAR = '--ais-autocomplete-detached-media-query';
|
|
78
69
|
var DETACHED_MODAL_MEDIA_QUERY_CSS_VAR = '--ais-autocomplete-detached-modal-media-query';
|
|
79
70
|
var DEFAULT_TRANSLATIONS = {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
71
|
+
detachedCancelButtonText: 'Cancel',
|
|
72
|
+
detachedSearchButtonTitle: 'Search',
|
|
73
|
+
detachedClearButtonTitle: 'Clear'
|
|
83
74
|
};
|
|
84
75
|
function getCssMediaQueryValue(name) {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
76
|
+
if (typeof window === 'undefined' || typeof document === 'undefined') {
|
|
77
|
+
return '';
|
|
78
|
+
}
|
|
79
|
+
return getComputedStyle(document.documentElement).getPropertyValue(name).trim();
|
|
89
80
|
}
|
|
90
81
|
function resolveMediaQuery(value, cssVarName, fallback) {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
82
|
+
if (value === '') {
|
|
83
|
+
return '';
|
|
84
|
+
}
|
|
85
|
+
if (value) {
|
|
86
|
+
return value;
|
|
87
|
+
}
|
|
88
|
+
return getCssMediaQueryValue(cssVarName) || fallback;
|
|
98
89
|
}
|
|
99
90
|
function getMediaQueryList(mediaQuery) {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
91
|
+
if (typeof window === 'undefined' || typeof window.matchMedia !== 'function') {
|
|
92
|
+
return null;
|
|
93
|
+
}
|
|
94
|
+
return window.matchMedia(mediaQuery);
|
|
104
95
|
}
|
|
105
|
-
|
|
106
96
|
/**
|
|
107
97
|
* Hook to manage detached (mobile) mode state
|
|
108
|
-
*/
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
98
|
+
*/ function useDetachedMode(mediaQuery) {
|
|
99
|
+
var resolvedMediaQuery = useMemo(function() {
|
|
100
|
+
return resolveMediaQuery(mediaQuery, DETACHED_MEDIA_QUERY_CSS_VAR, DEFAULT_DETACHED_MEDIA_QUERY);
|
|
101
|
+
}, [
|
|
102
|
+
mediaQuery
|
|
103
|
+
]);
|
|
104
|
+
var _useState = _$5(useState(function() {
|
|
105
|
+
var _getMediaQueryList;
|
|
106
|
+
return resolvedMediaQuery ? Boolean((_getMediaQueryList = getMediaQueryList(resolvedMediaQuery)) === null || _getMediaQueryList === void 0 ? void 0 : _getMediaQueryList.matches) : false;
|
|
107
|
+
}), 2), isDetached = _useState[0], setIsDetached = _useState[1];
|
|
108
|
+
var _useState1 = _$5(useState(false), 2), isModalOpen = _useState1[0], setIsModalOpen = _useState1[1];
|
|
109
|
+
var _useState2 = _$5(useState(false), 2), isModalDetached = _useState2[0], setIsModalDetached = _useState2[1];
|
|
110
|
+
useEffect(function() {
|
|
111
|
+
if (!resolvedMediaQuery) {
|
|
112
|
+
setIsDetached(false);
|
|
113
|
+
return function() {};
|
|
114
|
+
}
|
|
115
|
+
var mql = getMediaQueryList(resolvedMediaQuery);
|
|
116
|
+
if (!mql) {
|
|
117
|
+
setIsDetached(false);
|
|
118
|
+
return function() {};
|
|
119
|
+
}
|
|
120
|
+
var handler = function handler(event) {
|
|
121
|
+
var wasDetached = isDetached;
|
|
122
|
+
setIsDetached(event.matches);
|
|
123
|
+
// Close modal if switching from detached to non-detached
|
|
124
|
+
if (wasDetached && !event.matches) {
|
|
125
|
+
setIsModalOpen(false);
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
mql.addEventListener('change', handler);
|
|
129
|
+
return function() {
|
|
130
|
+
return mql.removeEventListener('change', handler);
|
|
131
|
+
};
|
|
132
|
+
}, [
|
|
133
|
+
resolvedMediaQuery,
|
|
134
|
+
isDetached
|
|
135
|
+
]);
|
|
136
|
+
useEffect(function() {
|
|
137
|
+
if (!isDetached) {
|
|
138
|
+
setIsModalDetached(false);
|
|
139
|
+
return function() {};
|
|
140
|
+
}
|
|
141
|
+
var modalMediaQuery = resolveMediaQuery(undefined, DETACHED_MODAL_MEDIA_QUERY_CSS_VAR, DEFAULT_DETACHED_MODAL_MEDIA_QUERY);
|
|
142
|
+
if (!modalMediaQuery) {
|
|
143
|
+
setIsModalDetached(false);
|
|
144
|
+
return function() {};
|
|
145
|
+
}
|
|
146
|
+
var mql = getMediaQueryList(modalMediaQuery);
|
|
147
|
+
if (!mql) {
|
|
148
|
+
setIsModalDetached(false);
|
|
149
|
+
return function() {};
|
|
150
|
+
}
|
|
151
|
+
var handler = function handler(event) {
|
|
152
|
+
setIsModalDetached(event.matches);
|
|
153
|
+
};
|
|
154
|
+
setIsModalDetached(mql.matches);
|
|
155
|
+
mql.addEventListener('change', handler);
|
|
156
|
+
return function() {
|
|
157
|
+
return mql.removeEventListener('change', handler);
|
|
158
|
+
};
|
|
159
|
+
}, [
|
|
160
|
+
isDetached
|
|
161
|
+
]);
|
|
162
|
+
useEffect(function() {
|
|
163
|
+
if (typeof document === 'undefined') return function() {};
|
|
164
|
+
if (isModalOpen) {
|
|
165
|
+
var scrollY = window.scrollY;
|
|
166
|
+
document.body.style.top = "-".concat(scrollY, "px");
|
|
167
|
+
document.body.classList.add('ais-Autocomplete--detached');
|
|
168
|
+
return function() {
|
|
169
|
+
document.body.classList.remove('ais-Autocomplete--detached');
|
|
170
|
+
document.body.style.top = '';
|
|
171
|
+
window.scrollTo(0, scrollY);
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
return function() {};
|
|
175
|
+
}, [
|
|
176
|
+
isModalOpen
|
|
177
|
+
]);
|
|
178
|
+
return {
|
|
179
|
+
isDetached: isDetached,
|
|
180
|
+
isModalDetached: isModalDetached,
|
|
181
|
+
isModalOpen: isModalOpen,
|
|
182
|
+
setIsModalOpen: setIsModalOpen
|
|
173
183
|
};
|
|
174
|
-
}, [isDetached]);
|
|
175
|
-
useEffect(function () {
|
|
176
|
-
if (typeof document === 'undefined') return function () {};
|
|
177
|
-
if (isModalOpen) {
|
|
178
|
-
var scrollY = window.scrollY;
|
|
179
|
-
document.body.style.top = "-".concat(scrollY, "px");
|
|
180
|
-
document.body.classList.add('ais-Autocomplete--detached');
|
|
181
|
-
return function () {
|
|
182
|
-
document.body.classList.remove('ais-Autocomplete--detached');
|
|
183
|
-
document.body.style.top = '';
|
|
184
|
-
window.scrollTo(0, scrollY);
|
|
185
|
-
};
|
|
186
|
-
}
|
|
187
|
-
return function () {};
|
|
188
|
-
}, [isModalOpen]);
|
|
189
|
-
return {
|
|
190
|
-
isDetached: isDetached,
|
|
191
|
-
isModalDetached: isModalDetached,
|
|
192
|
-
isModalOpen: isModalOpen,
|
|
193
|
-
setIsModalOpen: setIsModalOpen
|
|
194
|
-
};
|
|
195
184
|
}
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
})
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
item: cx('ais-AutocompleteSuggestionsItem', showSuggestions === null || showSuggestions === void 0 ? void 0 : (_showSuggestions$clas4 = showSuggestions.classNames) === null || _showSuggestions$clas4 === void 0 ? void 0 : _showSuggestions$clas4.item)
|
|
244
|
-
},
|
|
245
|
-
getQuery: function getQuery(item) {
|
|
246
|
-
return item.query;
|
|
247
|
-
},
|
|
248
|
-
getURL: showSuggestions.getURL
|
|
249
|
-
});
|
|
250
|
-
}
|
|
251
|
-
var recentSearchConfig = showRecent ? {
|
|
252
|
-
headerComponent: _typeof(showRecent) === 'object' ? showRecent.headerComponent : undefined,
|
|
253
|
-
itemComponent: _typeof(showRecent) === 'object' && showRecent.itemComponent ? showRecent.itemComponent : AutocompleteRecentSearch,
|
|
254
|
-
classNames: {
|
|
255
|
-
root: cx('ais-AutocompleteRecentSearches', _typeof(showRecent) === 'object' ? (_showRecent$className = showRecent.classNames) === null || _showRecent$className === void 0 ? void 0 : _showRecent$className.root : undefined),
|
|
256
|
-
list: cx('ais-AutocompleteRecentSearchesList', _typeof(showRecent) === 'object' ? (_showRecent$className2 = showRecent.classNames) === null || _showRecent$className2 === void 0 ? void 0 : _showRecent$className2.list : undefined),
|
|
257
|
-
header: cx('ais-AutocompleteRecentSearchesHeader', _typeof(showRecent) === 'object' ? (_showRecent$className3 = showRecent.classNames) === null || _showRecent$className3 === void 0 ? void 0 : _showRecent$className3.header : undefined),
|
|
258
|
-
item: cx('ais-AutocompleteRecentSearchesItem', _typeof(showRecent) === 'object' ? (_showRecent$className4 = showRecent.classNames) === null || _showRecent$className4 === void 0 ? void 0 : _showRecent$className4.item : undefined)
|
|
185
|
+
function EXPERIMENTAL_Autocomplete(_0) {
|
|
186
|
+
var _0_indices = _0.indices, indices = _0_indices === void 0 ? [] : _0_indices, showSuggestions = _0.showSuggestions, showRecent = _0.showRecent, userSearchParameters = _0.searchParameters, detachedMediaQuery = _0.detachedMediaQuery, tmp = _0.translations, userTranslations = tmp === void 0 ? {} : tmp, props = _(_0, [
|
|
187
|
+
"indices",
|
|
188
|
+
"showSuggestions",
|
|
189
|
+
"showRecent",
|
|
190
|
+
"searchParameters",
|
|
191
|
+
"detachedMediaQuery",
|
|
192
|
+
"translations"
|
|
193
|
+
]);
|
|
194
|
+
var _showRecent_classNames, _showRecent_classNames1, _showRecent_classNames2, _showRecent_classNames3;
|
|
195
|
+
var translations = _$1({}, DEFAULT_TRANSLATIONS, userTranslations);
|
|
196
|
+
var _useInstantSearch = useInstantSearch(), indexUiState = _useInstantSearch.indexUiState, indexRenderState = _useInstantSearch.indexRenderState, status = _useInstantSearch.status;
|
|
197
|
+
var refine = useSearchBox({}, {
|
|
198
|
+
$$type: 'ais.autocomplete',
|
|
199
|
+
$$widgetType: 'ais.autocomplete'
|
|
200
|
+
}).refine;
|
|
201
|
+
var isSearchStalled = status === 'stalled';
|
|
202
|
+
var searchParameters = _$1({
|
|
203
|
+
hitsPerPage: 5
|
|
204
|
+
}, userSearchParameters);
|
|
205
|
+
var indicesConfig = _$2(indices);
|
|
206
|
+
if (showSuggestions === null || showSuggestions === void 0 ? void 0 : showSuggestions.indexName) {
|
|
207
|
+
var _showSuggestions_classNames, _showSuggestions_classNames1, _showSuggestions_classNames2, _showSuggestions_classNames3;
|
|
208
|
+
indicesConfig.unshift({
|
|
209
|
+
indexName: showSuggestions.indexName,
|
|
210
|
+
headerComponent: showSuggestions.headerComponent,
|
|
211
|
+
itemComponent: showSuggestions.itemComponent || function(param) {
|
|
212
|
+
var item = param.item, onSelect = param.onSelect, onApply = param.onApply;
|
|
213
|
+
return /*#__PURE__*/ React.createElement(AutocompleteSuggestion, {
|
|
214
|
+
item: item,
|
|
215
|
+
onSelect: onSelect,
|
|
216
|
+
onApply: onApply
|
|
217
|
+
}, /*#__PURE__*/ React.createElement(ConditionalReverseHighlight, {
|
|
218
|
+
item: item
|
|
219
|
+
}));
|
|
220
|
+
},
|
|
221
|
+
classNames: {
|
|
222
|
+
root: cx('ais-AutocompleteSuggestions', showSuggestions === null || showSuggestions === void 0 ? void 0 : (_showSuggestions_classNames = showSuggestions.classNames) === null || _showSuggestions_classNames === void 0 ? void 0 : _showSuggestions_classNames.root),
|
|
223
|
+
list: cx('ais-AutocompleteSuggestionsList', showSuggestions === null || showSuggestions === void 0 ? void 0 : (_showSuggestions_classNames1 = showSuggestions.classNames) === null || _showSuggestions_classNames1 === void 0 ? void 0 : _showSuggestions_classNames1.list),
|
|
224
|
+
header: cx('ais-AutocompleteSuggestionsHeader', showSuggestions === null || showSuggestions === void 0 ? void 0 : (_showSuggestions_classNames2 = showSuggestions.classNames) === null || _showSuggestions_classNames2 === void 0 ? void 0 : _showSuggestions_classNames2.header),
|
|
225
|
+
item: cx('ais-AutocompleteSuggestionsItem', showSuggestions === null || showSuggestions === void 0 ? void 0 : (_showSuggestions_classNames3 = showSuggestions.classNames) === null || _showSuggestions_classNames3 === void 0 ? void 0 : _showSuggestions_classNames3.item)
|
|
226
|
+
},
|
|
227
|
+
getQuery: function getQuery(item) {
|
|
228
|
+
return item.query;
|
|
229
|
+
},
|
|
230
|
+
getURL: showSuggestions.getURL
|
|
231
|
+
});
|
|
259
232
|
}
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
key: index.indexName,
|
|
269
|
-
indexName: index.indexName
|
|
270
|
-
}, /*#__PURE__*/React.createElement(Configure, index.searchParameters));
|
|
271
|
-
}), /*#__PURE__*/React.createElement(InnerAutocomplete, _extends({}, props, {
|
|
272
|
-
indicesConfig: indicesConfig,
|
|
273
|
-
refineSearchBox: refine,
|
|
274
|
-
isSearchStalled: isSearchStalled,
|
|
275
|
-
indexUiState: indexUiState,
|
|
276
|
-
isSearchPage: isSearchPage,
|
|
277
|
-
showRecent: showRecent,
|
|
278
|
-
recentSearchConfig: recentSearchConfig,
|
|
279
|
-
showSuggestions: showSuggestions,
|
|
280
|
-
detachedMediaQuery: detachedMediaQuery,
|
|
281
|
-
translations: translations
|
|
282
|
-
}))));
|
|
283
|
-
}
|
|
284
|
-
function InnerAutocomplete(_ref3) {
|
|
285
|
-
var indicesConfig = _ref3.indicesConfig,
|
|
286
|
-
refineSearchBox = _ref3.refineSearchBox,
|
|
287
|
-
isSearchStalled = _ref3.isSearchStalled,
|
|
288
|
-
getSearchPageURL = _ref3.getSearchPageURL,
|
|
289
|
-
userOnSelect = _ref3.onSelect,
|
|
290
|
-
indexUiState = _ref3.indexUiState,
|
|
291
|
-
isSearchPage = _ref3.isSearchPage,
|
|
292
|
-
PanelComponent = _ref3.panelComponent,
|
|
293
|
-
showRecent = _ref3.showRecent,
|
|
294
|
-
recentSearchConfig = _ref3.recentSearchConfig,
|
|
295
|
-
showSuggestions = _ref3.showSuggestions,
|
|
296
|
-
transformItems = _ref3.transformItems,
|
|
297
|
-
placeholder = _ref3.placeholder,
|
|
298
|
-
_ref3$detachedMediaQu = _ref3.detachedMediaQuery,
|
|
299
|
-
detachedMediaQuery = _ref3$detachedMediaQu === void 0 ? DEFAULT_DETACHED_MEDIA_QUERY : _ref3$detachedMediaQu,
|
|
300
|
-
translations = _ref3.translations,
|
|
301
|
-
classNames = _ref3.classNames,
|
|
302
|
-
props = _objectWithoutProperties(_ref3, _excluded2);
|
|
303
|
-
var _useAutocomplete = useAutocomplete({
|
|
304
|
-
transformItems: transformItems
|
|
305
|
-
}),
|
|
306
|
-
indices = _useAutocomplete.indices,
|
|
307
|
-
refineAutocomplete = _useAutocomplete.refine,
|
|
308
|
-
currentRefinement = _useAutocomplete.currentRefinement;
|
|
309
|
-
var _useDetachedMode = useDetachedMode(detachedMediaQuery),
|
|
310
|
-
isDetached = _useDetachedMode.isDetached,
|
|
311
|
-
isModalDetached = _useDetachedMode.isModalDetached,
|
|
312
|
-
isModalOpen = _useDetachedMode.isModalOpen,
|
|
313
|
-
setIsModalOpen = _useDetachedMode.setIsModalOpen;
|
|
314
|
-
var previousIsDetachedRef = useRef(isDetached);
|
|
315
|
-
var _useStorage = useStorage({
|
|
316
|
-
showRecent: showRecent,
|
|
317
|
-
query: currentRefinement,
|
|
318
|
-
indices: indices,
|
|
319
|
-
indicesConfig: indicesConfig,
|
|
320
|
-
suggestionsIndexName: showSuggestions === null || showSuggestions === void 0 ? void 0 : showSuggestions.indexName
|
|
321
|
-
}),
|
|
322
|
-
storage = _useStorage.storage,
|
|
323
|
-
storageHits = _useStorage.storageHits,
|
|
324
|
-
indicesForPropGetters = _useStorage.indicesForPropGetters,
|
|
325
|
-
indicesConfigForPropGetters = _useStorage.indicesConfigForPropGetters;
|
|
326
|
-
var _usePropGetters = usePropGetters({
|
|
327
|
-
indices: indicesForPropGetters,
|
|
328
|
-
indicesConfig: indicesConfigForPropGetters,
|
|
329
|
-
onRefine: function onRefine(query) {
|
|
330
|
-
refineAutocomplete(query);
|
|
331
|
-
refineSearchBox(query);
|
|
332
|
-
storage.onAdd(query);
|
|
333
|
-
},
|
|
334
|
-
onApply: function onApply(query) {
|
|
335
|
-
refineAutocomplete(query);
|
|
336
|
-
},
|
|
337
|
-
onSelect: userOnSelect !== null && userOnSelect !== void 0 ? userOnSelect : function (_ref4) {
|
|
338
|
-
var query = _ref4.query,
|
|
339
|
-
setQuery = _ref4.setQuery,
|
|
340
|
-
url = _ref4.url;
|
|
341
|
-
if (url) {
|
|
342
|
-
window.location.href = url;
|
|
343
|
-
return;
|
|
233
|
+
var recentSearchConfig = showRecent ? {
|
|
234
|
+
headerComponent: (typeof showRecent === "undefined" ? "undefined" : _$3(showRecent)) === 'object' ? showRecent.headerComponent : undefined,
|
|
235
|
+
itemComponent: (typeof showRecent === "undefined" ? "undefined" : _$3(showRecent)) === 'object' && showRecent.itemComponent ? showRecent.itemComponent : AutocompleteRecentSearch,
|
|
236
|
+
classNames: {
|
|
237
|
+
root: cx('ais-AutocompleteRecentSearches', (typeof showRecent === "undefined" ? "undefined" : _$3(showRecent)) === 'object' ? (_showRecent_classNames = showRecent.classNames) === null || _showRecent_classNames === void 0 ? void 0 : _showRecent_classNames.root : undefined),
|
|
238
|
+
list: cx('ais-AutocompleteRecentSearchesList', (typeof showRecent === "undefined" ? "undefined" : _$3(showRecent)) === 'object' ? (_showRecent_classNames1 = showRecent.classNames) === null || _showRecent_classNames1 === void 0 ? void 0 : _showRecent_classNames1.list : undefined),
|
|
239
|
+
header: cx('ais-AutocompleteRecentSearchesHeader', (typeof showRecent === "undefined" ? "undefined" : _$3(showRecent)) === 'object' ? (_showRecent_classNames2 = showRecent.classNames) === null || _showRecent_classNames2 === void 0 ? void 0 : _showRecent_classNames2.header : undefined),
|
|
240
|
+
item: cx('ais-AutocompleteRecentSearchesItem', (typeof showRecent === "undefined" ? "undefined" : _$3(showRecent)) === 'object' ? (_showRecent_classNames3 = showRecent.classNames) === null || _showRecent_classNames3 === void 0 ? void 0 : _showRecent_classNames3.item : undefined)
|
|
344
241
|
}
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
242
|
+
} : undefined;
|
|
243
|
+
var isSearchPage = useMemo(function() {
|
|
244
|
+
return typeof indexRenderState.hits !== 'undefined' || typeof indexRenderState.infiniteHits !== 'undefined';
|
|
245
|
+
}, [
|
|
246
|
+
indexRenderState
|
|
247
|
+
]);
|
|
248
|
+
return /*#__PURE__*/ React.createElement(Fragment, null, /*#__PURE__*/ React.createElement(Index, {
|
|
249
|
+
EXPERIMENTAL_isolated: true
|
|
250
|
+
}, /*#__PURE__*/ React.createElement(Configure, searchParameters), indicesConfig.map(function(index) {
|
|
251
|
+
return /*#__PURE__*/ React.createElement(Index, {
|
|
252
|
+
key: index.indexName,
|
|
253
|
+
indexName: index.indexName
|
|
254
|
+
}, /*#__PURE__*/ React.createElement(Configure, index.searchParameters));
|
|
255
|
+
}), /*#__PURE__*/ React.createElement(InnerAutocomplete, _$4(_$1({}, props), {
|
|
256
|
+
indicesConfig: indicesConfig,
|
|
257
|
+
refineSearchBox: refine,
|
|
258
|
+
isSearchStalled: isSearchStalled,
|
|
259
|
+
indexUiState: indexUiState,
|
|
260
|
+
isSearchPage: isSearchPage,
|
|
261
|
+
showRecent: showRecent,
|
|
262
|
+
recentSearchConfig: recentSearchConfig,
|
|
263
|
+
showSuggestions: showSuggestions,
|
|
264
|
+
detachedMediaQuery: detachedMediaQuery,
|
|
265
|
+
translations: translations
|
|
266
|
+
}))));
|
|
267
|
+
}
|
|
268
|
+
function InnerAutocomplete(_0) {
|
|
269
|
+
var indicesConfig = _0.indicesConfig, refineSearchBox = _0.refineSearchBox, isSearchStalled = _0.isSearchStalled, getSearchPageURL = _0.getSearchPageURL, userOnSelect = _0.onSelect, indexUiState = _0.indexUiState, isSearchPage = _0.isSearchPage, PanelComponent = _0.panelComponent, showRecent = _0.showRecent, recentSearchConfig = _0.recentSearchConfig, showSuggestions = _0.showSuggestions, transformItems = _0.transformItems, placeholder = _0.placeholder, _0_detachedMediaQuery = _0.detachedMediaQuery, detachedMediaQuery = _0_detachedMediaQuery === void 0 ? DEFAULT_DETACHED_MEDIA_QUERY : _0_detachedMediaQuery, translations = _0.translations, classNames = _0.classNames, props = _(_0, [
|
|
270
|
+
"indicesConfig",
|
|
271
|
+
"refineSearchBox",
|
|
272
|
+
"isSearchStalled",
|
|
273
|
+
"getSearchPageURL",
|
|
274
|
+
"onSelect",
|
|
275
|
+
"indexUiState",
|
|
276
|
+
"isSearchPage",
|
|
277
|
+
"panelComponent",
|
|
278
|
+
"showRecent",
|
|
279
|
+
"recentSearchConfig",
|
|
280
|
+
"showSuggestions",
|
|
281
|
+
"transformItems",
|
|
282
|
+
"placeholder",
|
|
283
|
+
"detachedMediaQuery",
|
|
284
|
+
"translations",
|
|
285
|
+
"classNames"
|
|
286
|
+
]);
|
|
287
|
+
var _useAutocomplete = useAutocomplete({
|
|
288
|
+
transformItems: transformItems
|
|
289
|
+
}), indices = _useAutocomplete.indices, refineAutocomplete = _useAutocomplete.refine, currentRefinement = _useAutocomplete.currentRefinement;
|
|
290
|
+
var _useDetachedMode = useDetachedMode(detachedMediaQuery), isDetached = _useDetachedMode.isDetached, isModalDetached = _useDetachedMode.isModalDetached, isModalOpen = _useDetachedMode.isModalOpen, setIsModalOpen = _useDetachedMode.setIsModalOpen;
|
|
291
|
+
var previousIsDetachedRef = useRef(isDetached);
|
|
292
|
+
var _useStorage = useStorage({
|
|
293
|
+
showRecent: showRecent,
|
|
294
|
+
query: currentRefinement,
|
|
295
|
+
indices: indices,
|
|
296
|
+
indicesConfig: indicesConfig,
|
|
297
|
+
suggestionsIndexName: showSuggestions === null || showSuggestions === void 0 ? void 0 : showSuggestions.indexName
|
|
298
|
+
}), storage = _useStorage.storage, storageHits = _useStorage.storageHits, indicesForPropGetters = _useStorage.indicesForPropGetters, indicesConfigForPropGetters = _useStorage.indicesConfigForPropGetters;
|
|
299
|
+
var _usePropGetters = usePropGetters({
|
|
300
|
+
indices: indicesForPropGetters,
|
|
301
|
+
indicesConfig: indicesConfigForPropGetters,
|
|
302
|
+
onRefine: function onRefine(query) {
|
|
303
|
+
refineAutocomplete(query);
|
|
304
|
+
refineSearchBox(query);
|
|
305
|
+
storage.onAdd(query);
|
|
306
|
+
},
|
|
307
|
+
onApply: function onApply(query) {
|
|
308
|
+
refineAutocomplete(query);
|
|
309
|
+
},
|
|
310
|
+
onSelect: userOnSelect !== null && userOnSelect !== void 0 ? userOnSelect : function(param) {
|
|
311
|
+
var query = param.query, setQuery = param.setQuery, url = param.url;
|
|
312
|
+
if (url) {
|
|
313
|
+
window.location.href = url;
|
|
314
|
+
return;
|
|
315
|
+
}
|
|
316
|
+
if (!isSearchPage && typeof getSearchPageURL !== 'undefined') {
|
|
317
|
+
window.location.href = getSearchPageURL(_$4(_$1({}, indexUiState), {
|
|
318
|
+
query: query
|
|
319
|
+
}));
|
|
320
|
+
return;
|
|
321
|
+
}
|
|
322
|
+
setQuery(query);
|
|
323
|
+
},
|
|
324
|
+
onSubmit: function onSubmit() {
|
|
325
|
+
// Close the detached modal when form is submitted
|
|
326
|
+
if (isDetached) {
|
|
327
|
+
setIsModalOpen(false);
|
|
328
|
+
}
|
|
329
|
+
},
|
|
330
|
+
placeholder: placeholder,
|
|
331
|
+
isDetached: isDetached
|
|
332
|
+
}), getInputProps = _usePropGetters.getInputProps, getItemProps = _usePropGetters.getItemProps, getPanelProps = _usePropGetters.getPanelProps, getRootProps = _usePropGetters.getRootProps, isOpen = _usePropGetters.isOpen, setIsOpen = _usePropGetters.setIsOpen, focusInput = _usePropGetters.focusInput;
|
|
333
|
+
// Open panel and focus input when modal opens
|
|
334
|
+
useEffect(function() {
|
|
335
|
+
if (isDetached && isModalOpen) {
|
|
336
|
+
setIsOpen(true);
|
|
337
|
+
// Focus input to show the keyboard on mobile
|
|
338
|
+
focusInput();
|
|
350
339
|
}
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
340
|
+
}, [
|
|
341
|
+
isDetached,
|
|
342
|
+
isModalOpen,
|
|
343
|
+
setIsOpen,
|
|
344
|
+
focusInput
|
|
345
|
+
]);
|
|
346
|
+
// Keep the modal open if the panel was open before switching to detached
|
|
347
|
+
useEffect(function() {
|
|
348
|
+
var wasDetached = previousIsDetachedRef.current;
|
|
349
|
+
var switchedToDetached = !wasDetached && isDetached;
|
|
350
|
+
if (switchedToDetached && isOpen) {
|
|
351
|
+
setIsModalOpen(true);
|
|
357
352
|
}
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
353
|
+
previousIsDetachedRef.current = isDetached;
|
|
354
|
+
}, [
|
|
355
|
+
isDetached,
|
|
356
|
+
isOpen,
|
|
357
|
+
setIsModalOpen
|
|
358
|
+
]);
|
|
359
|
+
var elements = {};
|
|
360
|
+
if (showRecent && recentSearchConfig) {
|
|
361
|
+
var RecentSearchItemComponent = recentSearchConfig.itemComponent;
|
|
362
|
+
elements.recent = /*#__PURE__*/ React.createElement(AutocompleteIndex, {
|
|
363
|
+
HeaderComponent: recentSearchConfig.headerComponent,
|
|
364
|
+
// @ts-ignore - there seems to be problems with React.ComponentType and this, but it's actually correct
|
|
365
|
+
ItemComponent: function ItemComponent(param) {
|
|
366
|
+
var item = param.item, onSelect = param.onSelect, onApply = param.onApply;
|
|
367
|
+
return /*#__PURE__*/ React.createElement(RecentSearchItemComponent, {
|
|
368
|
+
item: item,
|
|
369
|
+
onSelect: onSelect,
|
|
370
|
+
onRemoveRecentSearch: function onRemoveRecentSearch() {
|
|
371
|
+
return storage.onRemove(item.query);
|
|
372
|
+
},
|
|
373
|
+
onApply: onApply
|
|
374
|
+
}, /*#__PURE__*/ React.createElement(ConditionalReverseHighlight, {
|
|
375
|
+
item: item
|
|
376
|
+
}));
|
|
377
|
+
},
|
|
378
|
+
classNames: recentSearchConfig.classNames,
|
|
379
|
+
items: storageHits,
|
|
380
|
+
getItemProps: getItemProps,
|
|
381
|
+
key: "recentSearches"
|
|
382
|
+
});
|
|
385
383
|
}
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
384
|
+
indices.forEach(function(param) {
|
|
385
|
+
var indexId = param.indexId, indexName = param.indexName, hits = param.hits;
|
|
386
|
+
var elementId = indexName === (showSuggestions === null || showSuggestions === void 0 ? void 0 : showSuggestions.indexName) ? 'suggestions' : indexName;
|
|
387
|
+
var filteredHits = elementId === 'suggestions' && showRecent ? hits.filter(function(suggestionHit) {
|
|
388
|
+
return !storageHits.find(function(storageHit) {
|
|
389
|
+
return storageHit.query === suggestionHit.query;
|
|
390
|
+
});
|
|
391
|
+
}) : hits;
|
|
392
|
+
var currentIndexConfig = indicesConfig.find(function(config) {
|
|
393
|
+
return config.indexName === indexName;
|
|
394
|
+
});
|
|
395
|
+
if (!currentIndexConfig) {
|
|
396
|
+
return;
|
|
397
|
+
}
|
|
398
|
+
elements[elementId] = /*#__PURE__*/ React.createElement(AutocompleteIndex, {
|
|
399
|
+
key: indexId,
|
|
400
|
+
// @ts-expect-error - there seems to be problems with React.ComponentType and this, but it's actually correct
|
|
401
|
+
HeaderComponent: currentIndexConfig.headerComponent,
|
|
402
|
+
// @ts-expect-error - there seems to be problems with React.ComponentType and this, but it's actually correct
|
|
403
|
+
ItemComponent: currentIndexConfig.itemComponent,
|
|
404
|
+
items: filteredHits.map(function(item) {
|
|
405
|
+
return _$4(_$1({}, item), {
|
|
406
|
+
__indexName: indexId
|
|
407
|
+
});
|
|
408
|
+
}),
|
|
409
|
+
getItemProps: getItemProps,
|
|
410
|
+
classNames: currentIndexConfig.classNames
|
|
411
|
+
});
|
|
414
412
|
});
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
return config.indexName === indexName;
|
|
413
|
+
var searchBoxContent = /*#__PURE__*/ React.createElement(AutocompleteSearch, {
|
|
414
|
+
inputProps: getInputProps(),
|
|
415
|
+
clearQuery: function clearQuery() {
|
|
416
|
+
refineSearchBox('');
|
|
417
|
+
refineAutocomplete('');
|
|
418
|
+
},
|
|
419
|
+
onQueryChange: function onQueryChange(query) {
|
|
420
|
+
refineAutocomplete(query);
|
|
421
|
+
},
|
|
422
|
+
query: currentRefinement || indexUiState.query || '',
|
|
423
|
+
refine: refineSearchBox,
|
|
424
|
+
isSearchStalled: isSearchStalled
|
|
428
425
|
});
|
|
429
|
-
|
|
430
|
-
|
|
426
|
+
var panelContent = /*#__PURE__*/ React.createElement(AutocompletePanel, getPanelProps(), PanelComponent ? /*#__PURE__*/ React.createElement(PanelComponent, {
|
|
427
|
+
elements: elements,
|
|
428
|
+
indices: indices
|
|
429
|
+
}) : Object.keys(elements).map(function(elementId) {
|
|
430
|
+
return elements[elementId];
|
|
431
|
+
}));
|
|
432
|
+
var detachedContainerClassNames = isModalDetached ? _$4(_$1({}, classNames), {
|
|
433
|
+
detachedContainer: cx('ais-AutocompleteDetachedContainer--modal', classNames === null || classNames === void 0 ? void 0 : classNames.detachedContainer)
|
|
434
|
+
}) : classNames;
|
|
435
|
+
if (isDetached) {
|
|
436
|
+
return /*#__PURE__*/ React.createElement(Autocomplete, _$4(_$1({}, props, getRootProps()), {
|
|
437
|
+
classNames: classNames
|
|
438
|
+
}), /*#__PURE__*/ React.createElement(AutocompleteDetachedSearchButton, {
|
|
439
|
+
query: currentRefinement || indexUiState.query || '',
|
|
440
|
+
placeholder: placeholder,
|
|
441
|
+
classNames: classNames,
|
|
442
|
+
onClick: function onClick() {
|
|
443
|
+
setIsModalOpen(true);
|
|
444
|
+
setIsOpen(true);
|
|
445
|
+
},
|
|
446
|
+
onClear: function onClear() {
|
|
447
|
+
refineSearchBox('');
|
|
448
|
+
refineAutocomplete('');
|
|
449
|
+
},
|
|
450
|
+
translations: translations
|
|
451
|
+
}), isModalOpen && /*#__PURE__*/ React.createElement(AutocompleteDetachedOverlay, {
|
|
452
|
+
classNames: classNames,
|
|
453
|
+
onClose: function onClose() {
|
|
454
|
+
setIsModalOpen(false);
|
|
455
|
+
setIsOpen(false);
|
|
456
|
+
}
|
|
457
|
+
}, /*#__PURE__*/ React.createElement(AutocompleteDetachedContainer, {
|
|
458
|
+
classNames: detachedContainerClassNames
|
|
459
|
+
}, /*#__PURE__*/ React.createElement(AutocompleteDetachedFormContainer, {
|
|
460
|
+
classNames: classNames,
|
|
461
|
+
onCancel: function onCancel() {
|
|
462
|
+
setIsModalOpen(false);
|
|
463
|
+
setIsOpen(false);
|
|
464
|
+
},
|
|
465
|
+
translations: translations
|
|
466
|
+
}, searchBoxContent), panelContent)));
|
|
431
467
|
}
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
468
|
+
// Normal (non-detached) rendering
|
|
469
|
+
return /*#__PURE__*/ React.createElement(Autocomplete, _$4(_$1({}, props, getRootProps()), {
|
|
470
|
+
classNames: classNames
|
|
471
|
+
}), searchBoxContent, panelContent);
|
|
472
|
+
}
|
|
473
|
+
function ConditionalReverseHighlight(param) {
|
|
474
|
+
var item = param.item;
|
|
475
|
+
var _item__highlightResult;
|
|
476
|
+
if (!((_item__highlightResult = item._highlightResult) === null || _item__highlightResult === void 0 ? void 0 : _item__highlightResult.query) || // @ts-expect-error - we should not have matchLevel as arrays here
|
|
477
|
+
item._highlightResult.query.matchLevel === 'none') {
|
|
478
|
+
return item.query;
|
|
479
|
+
}
|
|
480
|
+
return /*#__PURE__*/ React.createElement(ReverseHighlight, {
|
|
481
|
+
attribute: "query",
|
|
482
|
+
hit: item
|
|
447
483
|
});
|
|
448
|
-
});
|
|
449
|
-
var searchBoxContent = /*#__PURE__*/React.createElement(AutocompleteSearch, {
|
|
450
|
-
inputProps: getInputProps(),
|
|
451
|
-
clearQuery: function clearQuery() {
|
|
452
|
-
refineSearchBox('');
|
|
453
|
-
refineAutocomplete('');
|
|
454
|
-
},
|
|
455
|
-
onQueryChange: function onQueryChange(query) {
|
|
456
|
-
refineAutocomplete(query);
|
|
457
|
-
},
|
|
458
|
-
query: currentRefinement || indexUiState.query || '',
|
|
459
|
-
refine: refineSearchBox,
|
|
460
|
-
isSearchStalled: isSearchStalled
|
|
461
|
-
});
|
|
462
|
-
var panelContent = /*#__PURE__*/React.createElement(AutocompletePanel, getPanelProps(), PanelComponent ? /*#__PURE__*/React.createElement(PanelComponent, {
|
|
463
|
-
elements: elements,
|
|
464
|
-
indices: indices
|
|
465
|
-
}) : Object.keys(elements).map(function (elementId) {
|
|
466
|
-
return elements[elementId];
|
|
467
|
-
}));
|
|
468
|
-
var detachedContainerClassNames = isModalDetached ? _objectSpread(_objectSpread({}, classNames), {}, {
|
|
469
|
-
detachedContainer: cx('ais-AutocompleteDetachedContainer--modal', classNames === null || classNames === void 0 ? void 0 : classNames.detachedContainer)
|
|
470
|
-
}) : classNames;
|
|
471
|
-
if (isDetached) {
|
|
472
|
-
return /*#__PURE__*/React.createElement(Autocomplete, _extends({}, props, getRootProps(), {
|
|
473
|
-
classNames: classNames
|
|
474
|
-
}), /*#__PURE__*/React.createElement(AutocompleteDetachedSearchButton, {
|
|
475
|
-
query: currentRefinement || indexUiState.query || '',
|
|
476
|
-
placeholder: placeholder,
|
|
477
|
-
classNames: classNames,
|
|
478
|
-
onClick: function onClick() {
|
|
479
|
-
setIsModalOpen(true);
|
|
480
|
-
setIsOpen(true);
|
|
481
|
-
},
|
|
482
|
-
onClear: function onClear() {
|
|
483
|
-
refineSearchBox('');
|
|
484
|
-
refineAutocomplete('');
|
|
485
|
-
},
|
|
486
|
-
translations: translations
|
|
487
|
-
}), isModalOpen && /*#__PURE__*/React.createElement(AutocompleteDetachedOverlay, {
|
|
488
|
-
classNames: classNames,
|
|
489
|
-
onClose: function onClose() {
|
|
490
|
-
setIsModalOpen(false);
|
|
491
|
-
setIsOpen(false);
|
|
492
|
-
}
|
|
493
|
-
}, /*#__PURE__*/React.createElement(AutocompleteDetachedContainer, {
|
|
494
|
-
classNames: detachedContainerClassNames
|
|
495
|
-
}, /*#__PURE__*/React.createElement(AutocompleteDetachedFormContainer, {
|
|
496
|
-
classNames: classNames,
|
|
497
|
-
onCancel: function onCancel() {
|
|
498
|
-
setIsModalOpen(false);
|
|
499
|
-
setIsOpen(false);
|
|
500
|
-
},
|
|
501
|
-
translations: translations
|
|
502
|
-
}, searchBoxContent), panelContent)));
|
|
503
|
-
}
|
|
504
|
-
|
|
505
|
-
// Normal (non-detached) rendering
|
|
506
|
-
return /*#__PURE__*/React.createElement(Autocomplete, _extends({}, props, getRootProps(), {
|
|
507
|
-
classNames: classNames
|
|
508
|
-
}), searchBoxContent, panelContent);
|
|
509
484
|
}
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
var item = _ref7.item;
|
|
513
|
-
if (!((_item$_highlightResul = item._highlightResult) !== null && _item$_highlightResul !== void 0 && _item$_highlightResul.query) ||
|
|
514
|
-
// @ts-expect-error - we should not have matchLevel as arrays here
|
|
515
|
-
item._highlightResult.query.matchLevel === 'none') {
|
|
516
|
-
return item.query;
|
|
517
|
-
}
|
|
518
|
-
return /*#__PURE__*/React.createElement(ReverseHighlight, {
|
|
519
|
-
attribute: "query",
|
|
520
|
-
hit: item
|
|
521
|
-
});
|
|
522
|
-
}
|
|
485
|
+
|
|
486
|
+
export { EXPERIMENTAL_Autocomplete };
|