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