react-instantsearch-core 6.38.1 → 6.38.2

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 (100) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +9 -1
  3. package/dist/cjs/connectors/connectAutoComplete.js +14 -33
  4. package/dist/cjs/connectors/connectBreadcrumb.js +9 -22
  5. package/dist/cjs/connectors/connectConfigure.js +17 -26
  6. package/dist/cjs/connectors/connectConfigureRelatedItems.js +20 -33
  7. package/dist/cjs/connectors/connectCurrentRefinements.js +6 -13
  8. package/dist/cjs/connectors/connectDynamicWidgets.js +2 -13
  9. package/dist/cjs/connectors/connectGeoSearch.js +15 -34
  10. package/dist/cjs/connectors/connectHierarchicalMenu.js +22 -48
  11. package/dist/cjs/connectors/connectHighlight.js +8 -14
  12. package/dist/cjs/connectors/connectHitInsights.js +8 -20
  13. package/dist/cjs/connectors/connectHits.js +2 -11
  14. package/dist/cjs/connectors/connectHitsPerPage.js +8 -18
  15. package/dist/cjs/connectors/connectInfiniteHits.js +25 -43
  16. package/dist/cjs/connectors/connectMenu.js +14 -33
  17. package/dist/cjs/connectors/connectNumericMenu.js +24 -49
  18. package/dist/cjs/connectors/connectPagination.js +7 -17
  19. package/dist/cjs/connectors/connectPoweredBy.js +1 -5
  20. package/dist/cjs/connectors/connectQueryRules.js +11 -29
  21. package/dist/cjs/connectors/connectRange.js +33 -75
  22. package/dist/cjs/connectors/connectRefinementList.js +16 -34
  23. package/dist/cjs/connectors/connectRelevantSort.js +6 -13
  24. package/dist/cjs/connectors/connectScrollTo.js +6 -14
  25. package/dist/cjs/connectors/connectSearchBox.js +7 -17
  26. package/dist/cjs/connectors/connectSortBy.js +8 -18
  27. package/dist/cjs/connectors/connectStateResults.js +1 -6
  28. package/dist/cjs/connectors/connectStats.js +2 -8
  29. package/dist/cjs/connectors/connectToggleRefinement.js +14 -29
  30. package/dist/cjs/connectors/connectVoiceSearch.js +7 -24
  31. package/dist/cjs/core/context.js +3 -7
  32. package/dist/cjs/core/createConnector.js +60 -114
  33. package/dist/cjs/core/createInstantSearchManager.d.js +1 -0
  34. package/dist/cjs/core/createInstantSearchManager.js +67 -116
  35. package/dist/cjs/core/createStore.js +0 -1
  36. package/dist/cjs/core/createWidgetsManager.js +4 -7
  37. package/dist/cjs/core/highlight.js +11 -20
  38. package/dist/cjs/core/indexUtils.js +34 -77
  39. package/dist/cjs/core/metadata.js +7 -15
  40. package/dist/cjs/core/translatable.js +19 -46
  41. package/dist/cjs/core/utils.js +14 -52
  42. package/dist/cjs/core/version.js +1 -1
  43. package/dist/cjs/index.js +9 -44
  44. package/dist/cjs/types/index.js +0 -2
  45. package/dist/cjs/widgets/Configure.js +1 -5
  46. package/dist/cjs/widgets/ConfigureRelatedItems.js +1 -8
  47. package/dist/cjs/widgets/DynamicWidgets.js +12 -33
  48. package/dist/cjs/widgets/Index.js +26 -52
  49. package/dist/cjs/widgets/InstantSearch.js +28 -67
  50. package/dist/cjs/widgets/QueryRuleContext.js +1 -5
  51. package/dist/es/connectors/connectAutoComplete.js +11 -25
  52. package/dist/es/connectors/connectBreadcrumb.js +7 -13
  53. package/dist/es/connectors/connectConfigure.js +13 -22
  54. package/dist/es/connectors/connectConfigureRelatedItems.js +17 -25
  55. package/dist/es/connectors/connectCurrentRefinements.js +5 -7
  56. package/dist/es/connectors/connectDynamicWidgets.js +1 -6
  57. package/dist/es/connectors/connectGeoSearch.js +14 -27
  58. package/dist/es/connectors/connectHierarchicalMenu.js +19 -38
  59. package/dist/es/connectors/connectHighlight.js +7 -9
  60. package/dist/es/connectors/connectHitInsights.js +7 -14
  61. package/dist/es/connectors/connectHits.js +2 -5
  62. package/dist/es/connectors/connectHitsPerPage.js +5 -12
  63. package/dist/es/connectors/connectInfiniteHits.js +21 -31
  64. package/dist/es/connectors/connectMenu.js +12 -25
  65. package/dist/es/connectors/connectNumericMenu.js +22 -40
  66. package/dist/es/connectors/connectPagination.js +5 -12
  67. package/dist/es/connectors/connectPoweredBy.js +1 -1
  68. package/dist/es/connectors/connectQueryRules.js +9 -20
  69. package/dist/es/connectors/connectRange.js +31 -68
  70. package/dist/es/connectors/connectRefinementList.js +14 -24
  71. package/dist/es/connectors/connectRelevantSort.js +7 -8
  72. package/dist/es/connectors/connectScrollTo.js +6 -7
  73. package/dist/es/connectors/connectSearchBox.js +5 -11
  74. package/dist/es/connectors/connectSortBy.js +5 -12
  75. package/dist/es/connectors/connectStateResults.js +1 -1
  76. package/dist/es/connectors/connectStats.js +2 -3
  77. package/dist/es/connectors/connectToggleRefinement.js +12 -22
  78. package/dist/es/connectors/connectVoiceSearch.js +4 -16
  79. package/dist/es/core/context.js +3 -5
  80. package/dist/es/core/createConnector.js +33 -86
  81. package/dist/es/core/createInstantSearchManager.d.js +0 -0
  82. package/dist/es/core/createInstantSearchManager.js +59 -100
  83. package/dist/es/core/createWidgetsManager.js +4 -5
  84. package/dist/es/core/highlight.js +11 -17
  85. package/dist/es/core/indexUtils.js +27 -62
  86. package/dist/es/core/metadata.js +6 -8
  87. package/dist/es/core/translatable.js +13 -29
  88. package/dist/es/core/utils.js +12 -29
  89. package/dist/es/core/version.js +1 -1
  90. package/dist/es/index.js +39 -6
  91. package/dist/es/widgets/Configure.js +1 -0
  92. package/dist/es/widgets/ConfigureRelatedItems.js +0 -2
  93. package/dist/es/widgets/DynamicWidgets.js +9 -18
  94. package/dist/es/widgets/Index.js +13 -31
  95. package/dist/es/widgets/InstantSearch.js +13 -42
  96. package/dist/umd/ReactInstantSearchCore.js +507 -1078
  97. package/dist/umd/ReactInstantSearchCore.js.map +1 -1
  98. package/dist/umd/ReactInstantSearchCore.min.js +2 -2
  99. package/dist/umd/ReactInstantSearchCore.min.js.map +1 -1
  100. package/package.json +7 -5
@@ -1,104 +1,85 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
3
  Object.defineProperty(exports, "__esModule", {
6
4
  value: true
7
5
  });
8
6
  exports.default = createInstantSearchManager;
9
-
10
- var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
11
-
12
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
13
-
14
7
  var _algoliasearchHelper = _interopRequireDefault(require("algoliasearch-helper"));
15
-
16
8
  var _createWidgetsManager = _interopRequireDefault(require("./createWidgetsManager"));
17
-
18
9
  var _createStore = _interopRequireDefault(require("./createStore"));
19
-
20
10
  var _highlight = require("./highlight");
21
-
22
11
  var _indexUtils = require("./indexUtils");
23
-
24
12
  var _react = require("react");
25
-
26
13
  var _version = _interopRequireDefault(require("./version"));
27
-
28
14
  var _excluded = ["resultsFacetValues"],
29
- _excluded2 = ["resultsFacetValues"],
30
- _excluded3 = ["resultsFacetValues"];
31
-
15
+ _excluded2 = ["resultsFacetValues"],
16
+ _excluded3 = ["resultsFacetValues"];
17
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
18
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
19
+ function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
20
+ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
32
21
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
33
-
34
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
35
-
22
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
23
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
24
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
25
+ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
36
26
  function addAlgoliaAgents(searchClient) {
37
27
  if (typeof searchClient.addAlgoliaAgent === 'function') {
38
28
  searchClient.addAlgoliaAgent("react (".concat(_react.version, ")"));
39
29
  searchClient.addAlgoliaAgent("react-instantsearch (".concat(_version.default, ")"));
40
30
  }
41
31
  }
42
-
43
32
  var isMultiIndexContext = function isMultiIndexContext(widget) {
44
33
  return (0, _indexUtils.hasMultipleIndices)({
45
34
  ais: widget.props.contextValue,
46
35
  multiIndexContext: widget.props.indexContextValue
47
36
  });
48
37
  };
49
-
50
38
  var isTargetedIndexEqualIndex = function isTargetedIndexEqualIndex(widget, indexId) {
51
39
  return widget.props.indexContextValue.targetedIndex === indexId;
52
- }; // Relying on the `indexId` is a bit brittle to detect the `Index` widget.
40
+ };
41
+
42
+ // Relying on the `indexId` is a bit brittle to detect the `Index` widget.
53
43
  // Since it's a class we could rely on `instanceof` or similar. We never
54
44
  // had an issue though. Works for now.
55
-
56
-
57
45
  var isIndexWidget = function isIndexWidget(widget) {
58
46
  return Boolean(widget.props.indexId);
59
47
  };
60
-
61
48
  var isIndexWidgetEqualIndex = function isIndexWidgetEqualIndex(widget, indexId) {
62
49
  return widget.props.indexId === indexId;
63
50
  };
64
-
65
51
  var sortIndexWidgetsFirst = function sortIndexWidgetsFirst(firstWidget, secondWidget) {
66
52
  var isFirstWidgetIndex = isIndexWidget(firstWidget);
67
53
  var isSecondWidgetIndex = isIndexWidget(secondWidget);
68
-
69
54
  if (isFirstWidgetIndex && !isSecondWidgetIndex) {
70
55
  return -1;
71
56
  }
72
-
73
57
  if (!isFirstWidgetIndex && isSecondWidgetIndex) {
74
58
  return 1;
75
59
  }
76
-
77
60
  return 0;
78
- }; // This function is copied from the algoliasearch v4 API Client. If modified,
79
- // consider updating it also in `serializeQueryParameters` from `@algolia/transporter`.
80
-
61
+ };
81
62
 
63
+ // This function is copied from the algoliasearch v4 API Client. If modified,
64
+ // consider updating it also in `serializeQueryParameters` from `@algolia/transporter`.
82
65
  function serializeQueryParameters(parameters) {
83
66
  var isObjectOrArray = function isObjectOrArray(value) {
84
67
  return Object.prototype.toString.call(value) === '[object Object]' || Object.prototype.toString.call(value) === '[object Array]';
85
68
  };
86
-
87
69
  var encode = function encode(format) {
88
70
  for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
89
71
  args[_key - 1] = arguments[_key];
90
72
  }
91
-
92
73
  var i = 0;
93
74
  return format.replace(/%s/g, function () {
94
75
  return encodeURIComponent(args[i++]);
95
76
  });
96
77
  };
97
-
98
78
  return Object.keys(parameters).map(function (key) {
99
79
  return encode('%s=%s', key, isObjectOrArray(parameters[key]) ? JSON.stringify(parameters[key]) : parameters[key]);
100
80
  }).join('&');
101
81
  }
82
+
102
83
  /**
103
84
  * Creates a new instance of the InstantSearchManager which controls the widgets and
104
85
  * trigger the search when the widgets are updated.
@@ -108,15 +89,13 @@ function serializeQueryParameters(parameters) {
108
89
  * @param {number} stalledSearchDelay - time (in ms) after the search is stalled
109
90
  * @return {InstantSearchManager} a new instance of InstantSearchManager
110
91
  */
111
-
112
-
113
92
  function createInstantSearchManager(_ref) {
114
93
  var indexName = _ref.indexName,
115
- _ref$initialState = _ref.initialState,
116
- initialState = _ref$initialState === void 0 ? {} : _ref$initialState,
117
- searchClient = _ref.searchClient,
118
- resultsState = _ref.resultsState,
119
- stalledSearchDelay = _ref.stalledSearchDelay;
94
+ _ref$initialState = _ref.initialState,
95
+ initialState = _ref$initialState === void 0 ? {} : _ref$initialState,
96
+ searchClient = _ref.searchClient,
97
+ resultsState = _ref.resultsState,
98
+ stalledSearchDelay = _ref.stalledSearchDelay;
120
99
  var helper = (0, _algoliasearchHelper.default)(searchClient, indexName, _objectSpread({}, _highlight.HIGHLIGHT_TAGS));
121
100
  addAlgoliaAgents(searchClient);
122
101
  helper.on('search', handleNewSearch).on('result', handleSearchSuccess({
@@ -137,22 +116,18 @@ function createInstantSearchManager(_ref) {
137
116
  isSearchStalled: true,
138
117
  searchingForFacetValues: false
139
118
  });
140
-
141
119
  function skipSearch() {
142
120
  skip = true;
143
121
  }
144
-
145
122
  function updateClient(client) {
146
123
  addAlgoliaAgents(client);
147
124
  helper.setClient(client);
148
125
  search();
149
126
  }
150
-
151
127
  function clearCache() {
152
128
  helper.clearCache();
153
129
  search();
154
130
  }
155
-
156
131
  function getMetadata(state) {
157
132
  return widgetsManager.getWidgets().filter(function (widget) {
158
133
  return Boolean(widget.getMetadata);
@@ -160,7 +135,6 @@ function createInstantSearchManager(_ref) {
160
135
  return widget.getMetadata(state);
161
136
  });
162
137
  }
163
-
164
138
  function getSearchParameters() {
165
139
  var sharedParameters = widgetsManager.getWidgets().filter(function (widget) {
166
140
  return Boolean(widget.getSearchParameters);
@@ -175,7 +149,8 @@ function createInstantSearchManager(_ref) {
175
149
  var targetedIndexEqualMainIndex = isMultiIndexContext(widget) && isTargetedIndexEqualIndex(widget, indexName);
176
150
  var subIndexEqualMainIndex = isIndexWidget(widget) && isIndexWidgetEqualIndex(widget, indexName);
177
151
  return targetedIndexEqualMainIndex || subIndexEqualMainIndex;
178
- }) // We have to sort the `Index` widgets first so the `index` parameter
152
+ })
153
+ // We have to sort the `Index` widgets first so the `index` parameter
179
154
  // is correctly set in the `reduce` function for the following widgets
180
155
  .sort(sortIndexWidgetsFirst).reduce(function (res, widget) {
181
156
  return widget.getSearchParameters(res);
@@ -186,12 +161,13 @@ function createInstantSearchManager(_ref) {
186
161
  var targetedIndexNotEqualMainIndex = isMultiIndexContext(widget) && !isTargetedIndexEqualIndex(widget, indexName);
187
162
  var subIndexNotEqualMainIndex = isIndexWidget(widget) && !isIndexWidgetEqualIndex(widget, indexName);
188
163
  return targetedIndexNotEqualMainIndex || subIndexNotEqualMainIndex;
189
- }) // We have to sort the `Index` widgets first so the `index` parameter
164
+ })
165
+ // We have to sort the `Index` widgets first so the `index` parameter
190
166
  // is correctly set in the `reduce` function for the following widgets
191
167
  .sort(sortIndexWidgetsFirst).reduce(function (indices, widget) {
192
168
  var indexId = isMultiIndexContext(widget) ? widget.props.indexContextValue.targetedIndex : widget.props.indexId;
193
169
  var widgets = indices[indexId] || [];
194
- return _objectSpread(_objectSpread({}, indices), {}, (0, _defineProperty2.default)({}, indexId, widgets.concat(widget)));
170
+ return _objectSpread(_objectSpread({}, indices), {}, _defineProperty({}, indexId, widgets.concat(widget)));
195
171
  }, {});
196
172
  var derivedParameters = Object.keys(derivedIndices).map(function (indexId) {
197
173
  return {
@@ -206,18 +182,17 @@ function createInstantSearchManager(_ref) {
206
182
  derivedParameters: derivedParameters
207
183
  };
208
184
  }
209
-
210
185
  function search() {
211
186
  if (!skip) {
212
187
  var _getSearchParameters = getSearchParameters(helper.state),
213
- mainParameters = _getSearchParameters.mainParameters,
214
- derivedParameters = _getSearchParameters.derivedParameters;
188
+ mainParameters = _getSearchParameters.mainParameters,
189
+ derivedParameters = _getSearchParameters.derivedParameters;
190
+ searchCounter = derivedParameters.length + 1;
215
191
 
216
- searchCounter = derivedParameters.length + 1; // We have to call `slice` because the method `detach` on the derived
192
+ // We have to call `slice` because the method `detach` on the derived
217
193
  // helpers mutates the value `derivedHelpers`. The `forEach` loop does
218
194
  // not iterate on each value and we're not able to correctly clear the
219
195
  // previous derived helpers (memory leak + useless requests).
220
-
221
196
  helper.derivedHelpers.slice().forEach(function (derivedHelper) {
222
197
  // Since we detach the derived helpers on **every** new search they
223
198
  // won't receive intermediate results in case of a stalled search.
@@ -237,7 +212,7 @@ function createInstantSearchManager(_ref) {
237
212
  });
238
213
  derivedParameters.forEach(function (_ref2) {
239
214
  var indexId = _ref2.indexId,
240
- parameters = _ref2.parameters;
215
+ parameters = _ref2.parameters;
241
216
  var derivedHelper = helper.derive(function () {
242
217
  return parameters;
243
218
  });
@@ -249,36 +224,32 @@ function createInstantSearchManager(_ref) {
249
224
  helper.search();
250
225
  }
251
226
  }
252
-
253
227
  function handleSearchSuccess(_ref3) {
254
228
  var indexId = _ref3.indexId;
255
229
  return function (event) {
256
230
  searchCounter--;
257
231
  var state = store.getState();
258
232
  var isDerivedHelpersEmpty = !helper.derivedHelpers.length;
259
- var results = state.results ? state.results : {}; // Switching from mono index to multi index and vice versa must reset the
233
+ var results = state.results ? state.results : {};
234
+
235
+ // Switching from mono index to multi index and vice versa must reset the
260
236
  // results to an empty object, otherwise we keep reference of stalled and
261
237
  // unused results.
262
-
263
238
  results = !isDerivedHelpersEmpty && results.getFacetByName ? {} : results;
264
-
265
239
  if (!isDerivedHelpersEmpty) {
266
- results = _objectSpread(_objectSpread({}, results), {}, (0, _defineProperty2.default)({}, indexId, event.results));
240
+ results = _objectSpread(_objectSpread({}, results), {}, _defineProperty({}, indexId, event.results));
267
241
  } else {
268
242
  results = event.results;
269
243
  }
270
-
271
244
  var currentState = store.getState();
272
245
  var nextIsSearchStalled = currentState.isSearchStalled;
273
-
274
246
  if (!helper.hasPendingRequests()) {
275
247
  clearTimeout(stalledSearchTimer);
276
248
  stalledSearchTimer = null;
277
249
  nextIsSearchStalled = false;
278
250
  }
279
-
280
251
  var resultsFacetValues = currentState.resultsFacetValues,
281
- partialState = (0, _objectWithoutProperties2.default)(currentState, _excluded);
252
+ partialState = _objectWithoutProperties(currentState, _excluded);
282
253
  store.setState(_objectSpread(_objectSpread({}, partialState), {}, {
283
254
  results: results,
284
255
  isSearchStalled: nextIsSearchStalled,
@@ -287,68 +258,61 @@ function createInstantSearchManager(_ref) {
287
258
  }));
288
259
  };
289
260
  }
290
-
291
261
  function handleSearchError(_ref4) {
292
262
  var error = _ref4.error;
293
263
  var currentState = store.getState();
294
264
  var nextIsSearchStalled = currentState.isSearchStalled;
295
-
296
265
  if (!helper.hasPendingRequests()) {
297
266
  clearTimeout(stalledSearchTimer);
298
267
  nextIsSearchStalled = false;
299
268
  }
300
-
301
269
  var resultsFacetValues = currentState.resultsFacetValues,
302
- partialState = (0, _objectWithoutProperties2.default)(currentState, _excluded2);
270
+ partialState = _objectWithoutProperties(currentState, _excluded2);
303
271
  store.setState(_objectSpread(_objectSpread({}, partialState), {}, {
304
272
  isSearchStalled: nextIsSearchStalled,
305
273
  error: error,
306
274
  searching: false
307
275
  }));
308
276
  }
309
-
310
277
  function handleNewSearch() {
311
278
  if (!stalledSearchTimer) {
312
279
  stalledSearchTimer = setTimeout(function () {
313
280
  var _store$getState = store.getState(),
314
- resultsFacetValues = _store$getState.resultsFacetValues,
315
- partialState = (0, _objectWithoutProperties2.default)(_store$getState, _excluded3);
316
-
281
+ resultsFacetValues = _store$getState.resultsFacetValues,
282
+ partialState = _objectWithoutProperties(_store$getState, _excluded3);
317
283
  store.setState(_objectSpread(_objectSpread({}, partialState), {}, {
318
284
  isSearchStalled: true
319
285
  }));
320
286
  }, stalledSearchDelay);
321
287
  }
322
288
  }
323
-
324
289
  function hydrateSearchClient(client, results) {
325
290
  if (!results) {
326
291
  return;
327
- } // Disable cache hydration on:
292
+ }
293
+
294
+ // Disable cache hydration on:
328
295
  // - Algoliasearch API Client < v4 with cache disabled
329
296
  // - Third party clients (detected by the `addAlgoliaAgent` function missing)
330
297
 
331
-
332
298
  if ((!client.transporter || client._cacheHydrated) && (!client._useCache || typeof client.addAlgoliaAgent !== 'function')) {
333
299
  return;
334
- } // Algoliasearch API Client >= v4
300
+ }
301
+
302
+ // Algoliasearch API Client >= v4
335
303
  // To hydrate the client we need to populate the cache with the data from
336
304
  // the server (done in `hydrateSearchClientWithMultiIndexRequest` or
337
305
  // `hydrateSearchClientWithSingleIndexRequest`). But since there is no way
338
306
  // for us to compute the key the same way as `algoliasearch-client` we need
339
307
  // to populate it on a custom key and override the `search` method to
340
308
  // search on it first.
341
-
342
-
343
309
  if (client.transporter && !client._cacheHydrated) {
344
310
  client._cacheHydrated = true;
345
311
  var baseMethod = client.search;
346
-
347
312
  client.search = function (requests) {
348
313
  for (var _len2 = arguments.length, methodArgs = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
349
314
  methodArgs[_key2 - 1] = arguments[_key2];
350
315
  }
351
-
352
316
  var requestsWithSerializedParams = requests.map(function (request) {
353
317
  return _objectSpread(_objectSpread({}, request), {}, {
354
318
  params: serializeQueryParameters(request.params)
@@ -362,15 +326,12 @@ function createInstantSearchManager(_ref) {
362
326
  });
363
327
  };
364
328
  }
365
-
366
329
  if (Array.isArray(results.results)) {
367
330
  hydrateSearchClientWithMultiIndexRequest(client, results.results);
368
331
  return;
369
332
  }
370
-
371
333
  hydrateSearchClientWithSingleIndexRequest(client, results);
372
334
  }
373
-
374
335
  function hydrateSearchClientWithMultiIndexRequest(client, results) {
375
336
  // Algoliasearch API Client >= v4
376
337
  // Populate the cache with the data from the server
@@ -391,14 +352,14 @@ function createInstantSearchManager(_ref) {
391
352
  }, [])
392
353
  });
393
354
  return;
394
- } // Algoliasearch API Client < v4
355
+ }
356
+
357
+ // Algoliasearch API Client < v4
395
358
  // Prior to client v4 we didn't have a proper API to hydrate the client
396
359
  // cache from the outside. The following code populates the cache with
397
360
  // a single-index result. You can find more information about the
398
361
  // computation of the key inside the client (see link below).
399
362
  // https://github.com/algolia/algoliasearch-client-javascript/blob/c27e89ff92b2a854ae6f40dc524bffe0f0cbc169/src/AlgoliaSearchCore.js#L232-L240
400
-
401
-
402
363
  var key = "/1/indexes/*/queries_body_".concat(JSON.stringify({
403
364
  requests: results.reduce(function (acc, result) {
404
365
  return acc.concat(result.rawResults.map(function (request) {
@@ -409,13 +370,12 @@ function createInstantSearchManager(_ref) {
409
370
  }));
410
371
  }, [])
411
372
  }));
412
- client.cache = _objectSpread(_objectSpread({}, client.cache), {}, (0, _defineProperty2.default)({}, key, JSON.stringify({
373
+ client.cache = _objectSpread(_objectSpread({}, client.cache), {}, _defineProperty({}, key, JSON.stringify({
413
374
  results: results.reduce(function (acc, result) {
414
375
  return acc.concat(result.rawResults);
415
376
  }, [])
416
377
  })));
417
378
  }
418
-
419
379
  function hydrateSearchClientWithSingleIndexRequest(client, results) {
420
380
  // Algoliasearch API Client >= v4
421
381
  // Populate the cache with the data from the server
@@ -432,14 +392,13 @@ function createInstantSearchManager(_ref) {
432
392
  results: results.rawResults
433
393
  });
434
394
  return;
435
- } // Algoliasearch API Client < v4
395
+ }
396
+ // Algoliasearch API Client < v4
436
397
  // Prior to client v4 we didn't have a proper API to hydrate the client
437
398
  // cache from the outside. The following code populates the cache with
438
399
  // a single-index result. You can find more information about the
439
400
  // computation of the key inside the client (see link below).
440
401
  // https://github.com/algolia/algoliasearch-client-javascript/blob/c27e89ff92b2a854ae6f40dc524bffe0f0cbc169/src/AlgoliaSearchCore.js#L232-L240
441
-
442
-
443
402
  var key = "/1/indexes/*/queries_body_".concat(JSON.stringify({
444
403
  requests: results.rawResults.map(function (request) {
445
404
  return {
@@ -448,37 +407,34 @@ function createInstantSearchManager(_ref) {
448
407
  };
449
408
  })
450
409
  }));
451
- client.cache = _objectSpread(_objectSpread({}, client.cache), {}, (0, _defineProperty2.default)({}, key, JSON.stringify({
410
+ client.cache = _objectSpread(_objectSpread({}, client.cache), {}, _defineProperty({}, key, JSON.stringify({
452
411
  results: results.rawResults
453
412
  })));
454
413
  }
455
-
456
414
  function hydrateResultsState(results) {
457
415
  if (!results) {
458
416
  return null;
459
417
  }
460
-
461
418
  if (Array.isArray(results.results)) {
462
419
  return results.results.reduce(function (acc, result) {
463
- return _objectSpread(_objectSpread({}, acc), {}, (0, _defineProperty2.default)({}, result._internalIndexId, new _algoliasearchHelper.default.SearchResults(new _algoliasearchHelper.default.SearchParameters(result.state), result.rawResults)));
420
+ return _objectSpread(_objectSpread({}, acc), {}, _defineProperty({}, result._internalIndexId, new _algoliasearchHelper.default.SearchResults(new _algoliasearchHelper.default.SearchParameters(result.state), result.rawResults)));
464
421
  }, {});
465
422
  }
466
-
467
423
  return new _algoliasearchHelper.default.SearchResults(new _algoliasearchHelper.default.SearchParameters(results.state), results.rawResults);
468
- } // Called whenever a widget has been rendered with new props.
469
-
424
+ }
470
425
 
426
+ // Called whenever a widget has been rendered with new props.
471
427
  function onWidgetsUpdate() {
472
428
  var metadata = getMetadata(store.getState().widgets);
473
429
  store.setState(_objectSpread(_objectSpread({}, store.getState()), {}, {
474
430
  metadata: metadata,
475
431
  searching: true
476
- })); // Since the `getSearchParameters` method of widgets also depends on props,
477
- // the result search parameters might have changed.
432
+ }));
478
433
 
434
+ // Since the `getSearchParameters` method of widgets also depends on props,
435
+ // the result search parameters might have changed.
479
436
  search();
480
437
  }
481
-
482
438
  function transitionState(nextSearchState) {
483
439
  var searchState = store.getState().widgets;
484
440
  return widgetsManager.getWidgets().filter(function (widget) {
@@ -487,7 +443,6 @@ function createInstantSearchManager(_ref) {
487
443
  return widget.transitionState(searchState, res);
488
444
  }, nextSearchState);
489
445
  }
490
-
491
446
  function onExternalStateUpdate(nextSearchState) {
492
447
  var metadata = getMetadata(nextSearchState);
493
448
  store.setState(_objectSpread(_objectSpread({}, store.getState()), {}, {
@@ -497,12 +452,11 @@ function createInstantSearchManager(_ref) {
497
452
  }));
498
453
  search();
499
454
  }
500
-
501
455
  function onSearchForFacetValues(_ref5) {
502
456
  var facetName = _ref5.facetName,
503
- query = _ref5.query,
504
- _ref5$maxFacetHits = _ref5.maxFacetHits,
505
- maxFacetHits = _ref5$maxFacetHits === void 0 ? 10 : _ref5$maxFacetHits;
457
+ query = _ref5.query,
458
+ _ref5$maxFacetHits = _ref5.maxFacetHits,
459
+ maxFacetHits = _ref5$maxFacetHits === void 0 ? 10 : _ref5$maxFacetHits;
506
460
  // The values 1, 100 are the min / max values that the engine accepts.
507
461
  // see: https://www.algolia.com/doc/api-reference/api-parameters/maxFacetHits
508
462
  var maxFacetHitsWithinRange = Math.max(1, Math.min(maxFacetHits, 100));
@@ -511,11 +465,10 @@ function createInstantSearchManager(_ref) {
511
465
  }));
512
466
  helper.searchForFacetValues(facetName, query, maxFacetHitsWithinRange).then(function (content) {
513
467
  var _objectSpread7;
514
-
515
468
  store.setState(_objectSpread(_objectSpread({}, store.getState()), {}, {
516
469
  error: null,
517
470
  searchingForFacetValues: false,
518
- resultsFacetValues: _objectSpread(_objectSpread({}, store.getState().resultsFacetValues), {}, (_objectSpread7 = {}, (0, _defineProperty2.default)(_objectSpread7, facetName, content.facetHits), (0, _defineProperty2.default)(_objectSpread7, "query", query), _objectSpread7))
471
+ resultsFacetValues: _objectSpread(_objectSpread({}, store.getState().resultsFacetValues), {}, (_objectSpread7 = {}, _defineProperty(_objectSpread7, facetName, content.facetHits), _defineProperty(_objectSpread7, "query", query), _objectSpread7))
519
472
  }));
520
473
  }, function (error) {
521
474
  store.setState(_objectSpread(_objectSpread({}, store.getState()), {}, {
@@ -532,9 +485,9 @@ function createInstantSearchManager(_ref) {
532
485
  });
533
486
  });
534
487
  }
535
-
536
488
  function updateIndex(newIndex) {
537
- initialSearchParameters = initialSearchParameters.setIndex(newIndex); // No need to trigger a new search here as the widgets will also update and trigger it if needed.
489
+ initialSearchParameters = initialSearchParameters.setIndex(newIndex);
490
+ // No need to trigger a new search here as the widgets will also update and trigger it if needed.
538
491
  }
539
492
 
540
493
  function getWidgetsIds() {
@@ -542,7 +495,6 @@ function createInstantSearchManager(_ref) {
542
495
  return typeof meta.id !== 'undefined' ? res.concat(meta.id) : res;
543
496
  }, []);
544
497
  }
545
-
546
498
  return {
547
499
  store: store,
548
500
  widgetsManager: widgetsManager,
@@ -557,13 +509,12 @@ function createInstantSearchManager(_ref) {
557
509
  skipSearch: skipSearch
558
510
  };
559
511
  }
560
-
561
512
  function hydrateMetadata(resultsState) {
562
513
  if (!resultsState) {
563
514
  return [];
564
- } // add a value noop, which gets replaced once the widgets are mounted
565
-
515
+ }
566
516
 
517
+ // add a value noop, which gets replaced once the widgets are mounted
567
518
  return resultsState.metadata.map(function (datum) {
568
519
  return _objectSpread(_objectSpread({
569
520
  value: function value() {
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = createStore;
7
-
8
7
  function createStore(initialState) {
9
8
  var state = initialState;
10
9
  var listeners = [];
@@ -4,27 +4,24 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = createWidgetsManager;
7
-
8
7
  var _utils = require("./utils");
9
-
10
8
  function createWidgetsManager(onWidgetsUpdate) {
11
- var widgets = []; // Is an update scheduled?
9
+ var widgets = [];
10
+ // Is an update scheduled?
11
+ var scheduled = false;
12
12
 
13
- var scheduled = false; // The state manager's updates need to be batched since more than one
13
+ // The state manager's updates need to be batched since more than one
14
14
  // component can register or unregister widgets during the same tick.
15
-
16
15
  function scheduleUpdate() {
17
16
  if (scheduled) {
18
17
  return;
19
18
  }
20
-
21
19
  scheduled = true;
22
20
  (0, _utils.defer)(function () {
23
21
  scheduled = false;
24
22
  onWidgetsUpdate();
25
23
  });
26
24
  }
27
-
28
25
  return {
29
26
  registerWidget: function registerWidget(widget) {
30
27
  widgets.push(widget);
@@ -5,13 +5,12 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.HIGHLIGHT_TAGS = void 0;
7
7
  exports.parseAlgoliaHit = parseAlgoliaHit;
8
-
9
8
  var _utils = require("./utils");
10
-
11
9
  var HIGHLIGHT_TAGS = {
12
10
  highlightPreTag: "<ais-highlight-0000000000>",
13
11
  highlightPostTag: "</ais-highlight-0000000000>"
14
12
  };
13
+
15
14
  /**
16
15
  * Parses an highlighted attribute into an array of objects with the string value, and
17
16
  * a boolean that indicated if this part is highlighted.
@@ -21,21 +20,18 @@ var HIGHLIGHT_TAGS = {
21
20
  * @param {string} highlightedValue - highlighted attribute as returned by Algolia highlight feature
22
21
  * @return {object[]} - An array of {value: string, isHighlighted: boolean}.
23
22
  */
24
-
25
23
  exports.HIGHLIGHT_TAGS = HIGHLIGHT_TAGS;
26
-
27
24
  function parseHighlightedAttribute(_ref) {
28
25
  var preTag = _ref.preTag,
29
- postTag = _ref.postTag,
30
- _ref$highlightedValue = _ref.highlightedValue,
31
- highlightedValue = _ref$highlightedValue === void 0 ? '' : _ref$highlightedValue;
26
+ postTag = _ref.postTag,
27
+ _ref$highlightedValue = _ref.highlightedValue,
28
+ highlightedValue = _ref$highlightedValue === void 0 ? '' : _ref$highlightedValue;
32
29
  var splitByPreTag = highlightedValue.split(preTag);
33
30
  var firstValue = splitByPreTag.shift();
34
31
  var elements = firstValue === '' ? [] : [{
35
32
  value: firstValue,
36
33
  isHighlighted: false
37
34
  }];
38
-
39
35
  if (postTag === preTag) {
40
36
  var isHighlighted = true;
41
37
  splitByPreTag.forEach(function (split) {
@@ -52,7 +48,6 @@ function parseHighlightedAttribute(_ref) {
52
48
  value: splitByPostTag[0],
53
49
  isHighlighted: true
54
50
  });
55
-
56
51
  if (splitByPostTag[1] !== '') {
57
52
  elements.push({
58
53
  value: splitByPostTag[1],
@@ -61,9 +56,9 @@ function parseHighlightedAttribute(_ref) {
61
56
  }
62
57
  });
63
58
  }
64
-
65
59
  return elements;
66
60
  }
61
+
67
62
  /**
68
63
  * Find an highlighted attribute given an `attribute` and an `highlightProperty`, parses it,
69
64
  * and provided an array of objects with the string value and a boolean if this
@@ -80,19 +75,16 @@ function parseHighlightedAttribute(_ref) {
80
75
  * @param {object} hit - the actual hit returned by Algolia.
81
76
  * @return {object[]} - An array of {value: string, isHighlighted: boolean}.
82
77
  */
83
-
84
-
85
78
  function parseAlgoliaHit(_ref2) {
86
79
  var _ref2$preTag = _ref2.preTag,
87
- preTag = _ref2$preTag === void 0 ? '<em>' : _ref2$preTag,
88
- _ref2$postTag = _ref2.postTag,
89
- postTag = _ref2$postTag === void 0 ? '</em>' : _ref2$postTag,
90
- highlightProperty = _ref2.highlightProperty,
91
- attribute = _ref2.attribute,
92
- hit = _ref2.hit;
80
+ preTag = _ref2$preTag === void 0 ? '<em>' : _ref2$preTag,
81
+ _ref2$postTag = _ref2.postTag,
82
+ postTag = _ref2$postTag === void 0 ? '</em>' : _ref2$postTag,
83
+ highlightProperty = _ref2.highlightProperty,
84
+ attribute = _ref2.attribute,
85
+ hit = _ref2.hit;
93
86
  if (!hit) throw new Error('`hit`, the matching record, must be provided');
94
87
  var highlightObject = (0, _utils.getPropertyByPath)(hit[highlightProperty], attribute) || {};
95
-
96
88
  if (Array.isArray(highlightObject)) {
97
89
  return highlightObject.map(function (item) {
98
90
  return parseHighlightedAttribute({
@@ -102,7 +94,6 @@ function parseAlgoliaHit(_ref2) {
102
94
  });
103
95
  });
104
96
  }
105
-
106
97
  return parseHighlightedAttribute({
107
98
  preTag: preTag,
108
99
  postTag: postTag,