instantsearch.js 4.61.0 → 4.63.0

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 (33) hide show
  1. package/cjs/components/SearchBox/SearchBox.js +13 -7
  2. package/cjs/connectors/breadcrumb/connectBreadcrumb.js +10 -14
  3. package/cjs/connectors/hierarchical-menu/connectHierarchicalMenu.js +11 -13
  4. package/cjs/connectors/menu/connectMenu.js +11 -14
  5. package/cjs/connectors/numeric-menu/connectNumericMenu.js +10 -14
  6. package/cjs/connectors/rating-menu/connectRatingMenu.js +10 -14
  7. package/cjs/connectors/refinement-list/connectRefinementList.js +11 -13
  8. package/cjs/lib/InstantSearch.js +5 -2
  9. package/cjs/lib/routers/history.js +17 -4
  10. package/cjs/lib/version.js +1 -1
  11. package/cjs/middlewares/createInsightsMiddleware.js +16 -4
  12. package/dist/instantsearch.development.d.ts +20 -2
  13. package/dist/instantsearch.development.js +196 -155
  14. package/dist/instantsearch.development.js.map +1 -1
  15. package/dist/instantsearch.production.d.ts +20 -2
  16. package/dist/instantsearch.production.min.d.ts +20 -2
  17. package/dist/instantsearch.production.min.js +2 -2
  18. package/dist/instantsearch.production.min.js.map +1 -1
  19. package/es/components/SearchBox/SearchBox.js +13 -7
  20. package/es/connectors/breadcrumb/connectBreadcrumb.js +10 -14
  21. package/es/connectors/hierarchical-menu/connectHierarchicalMenu.js +11 -13
  22. package/es/connectors/menu/connectMenu.js +11 -14
  23. package/es/connectors/numeric-menu/connectNumericMenu.js +10 -14
  24. package/es/connectors/rating-menu/connectRatingMenu.js +10 -14
  25. package/es/connectors/refinement-list/connectRefinementList.js +11 -13
  26. package/es/lib/InstantSearch.d.ts +10 -0
  27. package/es/lib/InstantSearch.js +5 -2
  28. package/es/lib/routers/history.d.ts +10 -2
  29. package/es/lib/routers/history.js +18 -5
  30. package/es/lib/version.d.ts +1 -1
  31. package/es/lib/version.js +1 -1
  32. package/es/middlewares/createInsightsMiddleware.js +16 -4
  33. package/package.json +10 -10
@@ -51,13 +51,15 @@ var SearchBox = /*#__PURE__*/function (_Component) {
51
51
  refine = _this$props.refine,
52
52
  onChange = _this$props.onChange;
53
53
  var query = event.target.value;
54
- if (searchAsYouType) {
55
- refine(query);
54
+ if (event.type === 'compositionend' || !event.isComposing) {
55
+ if (searchAsYouType) {
56
+ refine(query);
57
+ }
58
+ _this.setState({
59
+ query: query
60
+ });
61
+ onChange(event);
56
62
  }
57
- _this.setState({
58
- query: query
59
- });
60
- onChange(event);
61
63
  });
62
64
  _defineProperty(_assertThisInitialized(_this), "onSubmit", function (event) {
63
65
  var _this$props2 = _this.props,
@@ -167,7 +169,11 @@ var SearchBox = /*#__PURE__*/function (_Component) {
167
169
  ,
168
170
  spellCheck: "false",
169
171
  maxLength: 512,
170
- onInput: this.onInput,
172
+ onInput: this.onInput
173
+ // see: https://github.com/preactjs/preact/issues/1978
174
+ // eslint-disable-next-line react/no-unknown-property
175
+ ,
176
+ oncompositionend: this.onInput,
171
177
  onBlur: this.onBlur,
172
178
  onFocus: this.onFocus,
173
179
  "aria-label": ariaLabel
@@ -1,7 +1,4 @@
1
1
  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); }
2
- var _excluded = ["hierarchicalMenu"];
3
- 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; }
4
- 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; }
5
2
  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; }
6
3
  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; }
7
4
  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; }
@@ -120,7 +117,7 @@ var connectBreadcrumb = function connectBreadcrumb(renderFn) {
120
117
  var path = searchParameters.getHierarchicalFacetBreadcrumb(hierarchicalFacetName);
121
118
  return removeEmptyRefinementsFromUiState(_objectSpread(_objectSpread({}, uiState), {}, {
122
119
  hierarchicalMenu: _objectSpread(_objectSpread({}, uiState.hierarchicalMenu), {}, _defineProperty({}, hierarchicalFacetName, path))
123
- }));
120
+ }), hierarchicalFacetName);
124
121
  },
125
122
  getWidgetSearchParameters: function getWidgetSearchParameters(searchParameters, _ref4) {
126
123
  var uiState = _ref4.uiState;
@@ -171,17 +168,16 @@ function shiftItemsValues(array) {
171
168
  };
172
169
  });
173
170
  }
174
- function removeEmptyRefinementsFromUiState(indexUiState) {
175
- var hierarchicalMenu = indexUiState.hierarchicalMenu,
176
- indexUiStateBase = _objectWithoutProperties(indexUiState, _excluded);
177
- if (!hierarchicalMenu) {
171
+ function removeEmptyRefinementsFromUiState(indexUiState, attribute) {
172
+ if (!indexUiState.hierarchicalMenu) {
178
173
  return indexUiState;
179
174
  }
180
- var connectorUiState = Object.keys(hierarchicalMenu).reduce(function (acc, key) {
181
- return _objectSpread(_objectSpread({}, acc), hierarchicalMenu[key].length > 0 ? _defineProperty({}, key, hierarchicalMenu[key]) : {});
182
- }, {});
183
- return _objectSpread(_objectSpread({}, indexUiStateBase), Object.keys(connectorUiState).length > 0 ? {
184
- hierarchicalMenu: connectorUiState
185
- } : {});
175
+ if (!indexUiState.hierarchicalMenu[attribute] || !indexUiState.hierarchicalMenu[attribute].length) {
176
+ delete indexUiState.hierarchicalMenu[attribute];
177
+ }
178
+ if (Object.keys(indexUiState.hierarchicalMenu).length === 0) {
179
+ delete indexUiState.hierarchicalMenu;
180
+ }
181
+ return indexUiState;
186
182
  }
187
183
  export default connectBreadcrumb;
@@ -1,6 +1,5 @@
1
1
  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); }
2
- var _excluded = ["name", "escapedValue", "data", "path"],
3
- _excluded2 = ["hierarchicalMenu"];
2
+ var _excluded = ["name", "escapedValue", "data", "path"];
4
3
  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; }
5
4
  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; }
6
5
  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; }
@@ -202,7 +201,7 @@ var connectHierarchicalMenu = function connectHierarchicalMenu(renderFn) {
202
201
  var path = searchParameters.getHierarchicalFacetBreadcrumb(hierarchicalFacetName);
203
202
  return removeEmptyRefinementsFromUiState(_objectSpread(_objectSpread({}, uiState), {}, {
204
203
  hierarchicalMenu: _objectSpread(_objectSpread({}, uiState.hierarchicalMenu), {}, _defineProperty({}, hierarchicalFacetName, path))
205
- }));
204
+ }), hierarchicalFacetName);
206
205
  },
207
206
  getWidgetSearchParameters: function getWidgetSearchParameters(searchParameters, _ref6) {
208
207
  var uiState = _ref6.uiState;
@@ -235,17 +234,16 @@ var connectHierarchicalMenu = function connectHierarchicalMenu(renderFn) {
235
234
  };
236
235
  };
237
236
  };
238
- function removeEmptyRefinementsFromUiState(indexUiState) {
239
- var hierarchicalMenu = indexUiState.hierarchicalMenu,
240
- indexUiStateBase = _objectWithoutProperties(indexUiState, _excluded2);
241
- if (!hierarchicalMenu) {
237
+ function removeEmptyRefinementsFromUiState(indexUiState, attribute) {
238
+ if (!indexUiState.hierarchicalMenu) {
242
239
  return indexUiState;
243
240
  }
244
- var connectorUiState = Object.keys(hierarchicalMenu).reduce(function (acc, key) {
245
- return _objectSpread(_objectSpread({}, acc), hierarchicalMenu[key].length > 0 ? _defineProperty({}, key, hierarchicalMenu[key]) : {});
246
- }, {});
247
- return _objectSpread(_objectSpread({}, indexUiStateBase), Object.keys(connectorUiState).length > 0 ? {
248
- hierarchicalMenu: connectorUiState
249
- } : {});
241
+ if (!indexUiState.hierarchicalMenu[attribute] || indexUiState.hierarchicalMenu[attribute].length === 0) {
242
+ delete indexUiState.hierarchicalMenu[attribute];
243
+ }
244
+ if (Object.keys(indexUiState.hierarchicalMenu).length === 0) {
245
+ delete indexUiState.hierarchicalMenu;
246
+ }
247
+ return indexUiState;
250
248
  }
251
249
  export default connectHierarchicalMenu;
@@ -1,5 +1,4 @@
1
- var _excluded = ["name", "escapedValue", "path"],
2
- _excluded2 = ["menu"];
1
+ var _excluded = ["name", "escapedValue", "path"];
3
2
  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); }
4
3
  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; }
5
4
  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; }
@@ -174,7 +173,7 @@ var connectMenu = function connectMenu(renderFn) {
174
173
  value = _searchParameters$get2[0];
175
174
  return removeEmptyRefinementsFromUiState(_objectSpread(_objectSpread({}, uiState), {}, {
176
175
  menu: _objectSpread(_objectSpread({}, uiState.menu), {}, _defineProperty({}, attribute, value))
177
- }));
176
+ }), attribute);
178
177
  },
179
178
  getWidgetSearchParameters: function getWidgetSearchParameters(searchParameters, _ref5) {
180
179
  var uiState = _ref5.uiState;
@@ -200,18 +199,16 @@ var connectMenu = function connectMenu(renderFn) {
200
199
  };
201
200
  };
202
201
  };
203
- function removeEmptyRefinementsFromUiState(indexUiState) {
204
- var menu = indexUiState.menu,
205
- indexUiStateBase = _objectWithoutProperties(indexUiState, _excluded2);
206
- if (!menu) {
202
+ function removeEmptyRefinementsFromUiState(indexUiState, attribute) {
203
+ if (!indexUiState.menu) {
207
204
  return indexUiState;
208
205
  }
209
- var connectorUiState = Object.keys(menu).reduce(function (acc, key) {
210
- var _menu$key;
211
- return _objectSpread(_objectSpread({}, acc), ((_menu$key = menu[key]) === null || _menu$key === void 0 ? void 0 : _menu$key.length) > 0 ? _defineProperty({}, key, menu[key]) : {});
212
- }, {});
213
- return _objectSpread(_objectSpread({}, indexUiStateBase), Object.keys(connectorUiState).length > 0 ? {
214
- menu: connectorUiState
215
- } : {});
206
+ if (indexUiState.menu[attribute] === undefined) {
207
+ delete indexUiState.menu[attribute];
208
+ }
209
+ if (Object.keys(indexUiState.menu).length === 0) {
210
+ delete indexUiState.menu;
211
+ }
212
+ return indexUiState;
216
213
  }
217
214
  export default connectMenu;
@@ -1,7 +1,4 @@
1
- var _excluded = ["numericMenu"];
2
1
  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); }
3
- 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; }
4
- 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; }
5
2
  function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e2) { throw _e2; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e3) { didErr = true; err = _e3; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
6
3
  function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
7
4
  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."); }
@@ -100,7 +97,7 @@ var connectNumericMenu = function connectNumericMenu(renderFn) {
100
97
  var max = values['<='] && values['<='][0] || '';
101
98
  return removeEmptyRefinementsFromUiState(_objectSpread(_objectSpread({}, uiState), {}, {
102
99
  numericMenu: _objectSpread(_objectSpread({}, uiState.numericMenu), {}, _defineProperty({}, attribute, "".concat(min, ":").concat(max)))
103
- }));
100
+ }), attribute);
104
101
  },
105
102
  getWidgetSearchParameters: function getWidgetSearchParameters(searchParameters, _ref6) {
106
103
  var uiState = _ref6.uiState;
@@ -262,17 +259,16 @@ function getRefinedState(state, attribute, facetValue) {
262
259
  function hasNumericRefinement(currentRefinements, operator, value) {
263
260
  return currentRefinements[operator] !== undefined && currentRefinements[operator].includes(value);
264
261
  }
265
- function removeEmptyRefinementsFromUiState(indexUiState) {
266
- var numericMenu = indexUiState.numericMenu,
267
- indexUiStateBase = _objectWithoutProperties(indexUiState, _excluded);
268
- if (!numericMenu) {
262
+ function removeEmptyRefinementsFromUiState(indexUiState, attribute) {
263
+ if (!indexUiState.numericMenu) {
269
264
  return indexUiState;
270
265
  }
271
- var connectorUiState = Object.keys(numericMenu).reduce(function (acc, key) {
272
- return _objectSpread(_objectSpread({}, acc), numericMenu[key] !== ':' ? _defineProperty({}, key, numericMenu[key]) : {});
273
- }, {});
274
- return _objectSpread(_objectSpread({}, indexUiStateBase), Object.keys(connectorUiState).length > 0 ? {
275
- numericMenu: connectorUiState
276
- } : {});
266
+ if (indexUiState.numericMenu[attribute] === ':') {
267
+ delete indexUiState.numericMenu[attribute];
268
+ }
269
+ if (Object.keys(indexUiState.numericMenu).length === 0) {
270
+ delete indexUiState.numericMenu;
271
+ }
272
+ return indexUiState;
277
273
  }
278
274
  export default connectNumericMenu;
@@ -1,7 +1,4 @@
1
1
  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); }
2
- var _excluded = ["ratingMenu"];
3
- 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; }
4
- 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; }
5
2
  function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
6
3
  function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
7
4
  function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
@@ -261,7 +258,7 @@ var connectRatingMenu = function connectRatingMenu(renderFn) {
261
258
  var value = _getRefinedStar(searchParameters);
262
259
  return removeEmptyRefinementsFromUiState(_objectSpread(_objectSpread({}, uiState), {}, {
263
260
  ratingMenu: _objectSpread(_objectSpread({}, uiState.ratingMenu), {}, _defineProperty({}, attribute, typeof value === 'number' ? value : undefined))
264
- }));
261
+ }), attribute);
265
262
  },
266
263
  getWidgetSearchParameters: function getWidgetSearchParameters(searchParameters, _ref8) {
267
264
  var uiState = _ref8.uiState;
@@ -278,17 +275,16 @@ var connectRatingMenu = function connectRatingMenu(renderFn) {
278
275
  };
279
276
  };
280
277
  };
281
- function removeEmptyRefinementsFromUiState(indexUiState) {
282
- var ratingMenu = indexUiState.ratingMenu,
283
- indexUiStateBase = _objectWithoutProperties(indexUiState, _excluded);
284
- if (!ratingMenu) {
278
+ function removeEmptyRefinementsFromUiState(indexUiState, attribute) {
279
+ if (!indexUiState.ratingMenu) {
285
280
  return indexUiState;
286
281
  }
287
- var connectorUiState = Object.keys(ratingMenu).reduce(function (acc, key) {
288
- return _objectSpread(_objectSpread({}, acc), typeof ratingMenu[key] === 'number' ? _defineProperty({}, key, ratingMenu[key]) : {});
289
- }, {});
290
- return _objectSpread(_objectSpread({}, indexUiStateBase), Object.keys(connectorUiState).length > 0 ? {
291
- ratingMenu: connectorUiState
292
- } : {});
282
+ if (typeof indexUiState.ratingMenu[attribute] !== 'number') {
283
+ delete indexUiState.ratingMenu[attribute];
284
+ }
285
+ if (Object.keys(indexUiState.ratingMenu).length === 0) {
286
+ delete indexUiState.ratingMenu;
287
+ }
288
+ return indexUiState;
293
289
  }
294
290
  export default connectRatingMenu;
@@ -1,7 +1,6 @@
1
1
  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); }
2
2
  var _excluded = ["name", "escapedValue"],
3
- _excluded2 = ["escapedValue", "value"],
4
- _excluded3 = ["refinementList"];
3
+ _excluded2 = ["escapedValue", "value"];
5
4
  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; }
6
5
  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; }
7
6
  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; }
@@ -246,7 +245,7 @@ var connectRefinementList = function connectRefinementList(renderFn) {
246
245
  var values = operator === 'or' ? searchParameters.getDisjunctiveRefinements(attribute) : searchParameters.getConjunctiveRefinements(attribute);
247
246
  return removeEmptyRefinementsFromUiState(_objectSpread(_objectSpread({}, uiState), {}, {
248
247
  refinementList: _objectSpread(_objectSpread({}, uiState.refinementList), {}, _defineProperty({}, attribute, values))
249
- }));
248
+ }), attribute);
250
249
  },
251
250
  getWidgetSearchParameters: function getWidgetSearchParameters(searchParameters, _ref6) {
252
251
  var uiState = _ref6.uiState;
@@ -276,17 +275,16 @@ var connectRefinementList = function connectRefinementList(renderFn) {
276
275
  };
277
276
  };
278
277
  };
279
- function removeEmptyRefinementsFromUiState(indexUiState) {
280
- var refinementList = indexUiState.refinementList,
281
- indexUiStateBase = _objectWithoutProperties(indexUiState, _excluded3);
282
- if (!refinementList) {
278
+ function removeEmptyRefinementsFromUiState(indexUiState, attribute) {
279
+ if (!indexUiState.refinementList) {
283
280
  return indexUiState;
284
281
  }
285
- var connectorUiState = Object.keys(refinementList).reduce(function (acc, key) {
286
- return _objectSpread(_objectSpread({}, acc), refinementList[key].length > 0 ? _defineProperty({}, key, refinementList[key]) : {});
287
- }, {});
288
- return _objectSpread(_objectSpread({}, indexUiStateBase), Object.keys(connectorUiState).length > 0 ? {
289
- refinementList: connectorUiState
290
- } : {});
282
+ if (!indexUiState.refinementList[attribute] || indexUiState.refinementList[attribute].length === 0) {
283
+ delete indexUiState.refinementList[attribute];
284
+ }
285
+ if (Object.keys(indexUiState.refinementList).length === 0) {
286
+ delete indexUiState.refinementList;
287
+ }
288
+ return indexUiState;
291
289
  }
292
290
  export default connectRefinementList;
@@ -107,6 +107,16 @@ export type InstantSearchOptions<TUiState extends UiState = UiState, TRouteState
107
107
  * @default false
108
108
  */
109
109
  preserveSharedStateOnUnmount?: boolean;
110
+ /**
111
+ * Changes the way root levels of hierarchical facets have their count displayed.
112
+ *
113
+ * If `false` (by default), the count of the refined root level is updated to match the count of the actively refined parent level.
114
+ *
115
+ * If `true`, the count of the root level stays the same as the count of all children levels.
116
+ *
117
+ * @default false
118
+ */
119
+ persistHierarchicalRootCount?: boolean;
110
120
  };
111
121
  };
112
122
  export type InstantSearchStatus = 'idle' | 'loading' | 'stalled' | 'error';
@@ -37,7 +37,8 @@ function defaultCreateURL() {
37
37
  * Global options for an InstantSearch instance.
38
38
  */
39
39
  export var INSTANTSEARCH_FUTURE_DEFAULTS = {
40
- preserveSharedStateOnUnmount: false
40
+ preserveSharedStateOnUnmount: false,
41
+ persistHierarchicalRootCount: false
41
42
  };
42
43
 
43
44
  /**
@@ -373,7 +374,9 @@ var InstantSearch = /*#__PURE__*/function (_EventEmitter) {
373
374
  // DerivedHelper scoped into the `index` widgets.
374
375
  // In Vue InstantSearch' hydrate, a main helper gets set before start, so
375
376
  // we need to respect this helper as a way to keep all listeners correct.
376
- var mainHelper = this.mainHelper || algoliasearchHelper(this.client, this.indexName);
377
+ var mainHelper = this.mainHelper || algoliasearchHelper(this.client, this.indexName, undefined, {
378
+ persistHierarchicalRootCount: this.future.persistHierarchicalRootCount
379
+ });
377
380
  mainHelper.search = function () {
378
381
  _this3.status = 'loading';
379
382
  _this3.scheduleRender(false);
@@ -18,6 +18,13 @@ export type BrowserHistoryArgs<TRouteState> = {
18
18
  start?: (onUpdate: () => void) => void;
19
19
  dispose?: () => void;
20
20
  push?: (url: string) => void;
21
+ /**
22
+ * Whether the URL should be cleaned up when the router is disposed.
23
+ * This can be useful when closing a modal containing InstantSearch, to
24
+ * remove active refinements from the URL.
25
+ * @default true
26
+ */
27
+ cleanUrlOnDispose?: boolean;
21
28
  };
22
29
  declare class BrowserHistory<TRouteState> implements Router<TRouteState> {
23
30
  $$type: string;
@@ -68,11 +75,12 @@ declare class BrowserHistory<TRouteState> implements Router<TRouteState> {
68
75
  private _start?;
69
76
  private _dispose?;
70
77
  private _push?;
78
+ private _cleanUrlOnDispose;
71
79
  /**
72
80
  * Initializes a new storage provider that syncs the search state to the URL
73
81
  * using web APIs (`window.location.pushState` and `onpopstate` event).
74
82
  */
75
- constructor({ windowTitle, writeDelay, createURL, parseURL, getLocation, start, dispose, push, }: BrowserHistoryArgs<TRouteState>);
83
+ constructor({ windowTitle, writeDelay, createURL, parseURL, getLocation, start, dispose, push, cleanUrlOnDispose, }: BrowserHistoryArgs<TRouteState>);
76
84
  /**
77
85
  * Reads the URL and returns a syncable UI search state.
78
86
  */
@@ -101,5 +109,5 @@ declare class BrowserHistory<TRouteState> implements Router<TRouteState> {
101
109
  start(): void;
102
110
  private shouldWrite;
103
111
  }
104
- export default function historyRouter<TRouteState = UiState>({ createURL, parseURL, writeDelay, windowTitle, getLocation, start, dispose, push, }?: Partial<BrowserHistoryArgs<TRouteState>>): BrowserHistory<TRouteState>;
112
+ export default function historyRouter<TRouteState = UiState>({ createURL, parseURL, writeDelay, windowTitle, getLocation, start, dispose, push, cleanUrlOnDispose, }?: Partial<BrowserHistoryArgs<TRouteState>>): BrowserHistory<TRouteState>;
105
113
  export {};
@@ -6,7 +6,7 @@ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key i
6
6
  function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
7
7
  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); }
8
8
  import qs from 'qs';
9
- import { safelyRunOnBrowser, warning } from "../utils/index.js";
9
+ import { createDocumentationLink, safelyRunOnBrowser, warning } from "../utils/index.js";
10
10
  var setWindowTitle = function setWindowTitle(title) {
11
11
  if (title) {
12
12
  // This function is only executed on browsers so we can disable this check.
@@ -29,7 +29,8 @@ var BrowserHistory = /*#__PURE__*/function () {
29
29
  getLocation = _ref.getLocation,
30
30
  start = _ref.start,
31
31
  dispose = _ref.dispose,
32
- push = _ref.push;
32
+ push = _ref.push,
33
+ cleanUrlOnDispose = _ref.cleanUrlOnDispose;
33
34
  _classCallCheck(this, BrowserHistory);
34
35
  _defineProperty(this, "$$type", 'ais.browser');
35
36
  /**
@@ -79,6 +80,7 @@ var BrowserHistory = /*#__PURE__*/function () {
79
80
  _defineProperty(this, "_start", void 0);
80
81
  _defineProperty(this, "_dispose", void 0);
81
82
  _defineProperty(this, "_push", void 0);
83
+ _defineProperty(this, "_cleanUrlOnDispose", void 0);
82
84
  this.windowTitle = windowTitle;
83
85
  this.writeTimer = undefined;
84
86
  this.writeDelay = writeDelay;
@@ -88,6 +90,13 @@ var BrowserHistory = /*#__PURE__*/function () {
88
90
  this._start = start;
89
91
  this._dispose = dispose;
90
92
  this._push = push;
93
+ this._cleanUrlOnDispose = typeof cleanUrlOnDispose === 'undefined' ? true : cleanUrlOnDispose;
94
+ if (process.env.NODE_ENV === 'development' && typeof cleanUrlOnDispose === 'undefined') {
95
+ // eslint-disable-next-line no-console
96
+ console.info("Starting from the next major version, InstantSearch will not clean up the URL from active refinements when it is disposed.\n\nWe recommend setting `cleanUrlOnDispose` to false to adopt this change today.\nTo stay with the current behaviour and remove this warning, set the option to true.\n\nSee documentation: ".concat(createDocumentationLink({
97
+ name: 'history-router'
98
+ }), "#widget-param-cleanurlondispose"));
99
+ }
91
100
  safelyRunOnBrowser(function (_ref2) {
92
101
  var window = _ref2.window;
93
102
  var title = _this.windowTitle && _this.windowTitle(_this.read());
@@ -215,7 +224,9 @@ var BrowserHistory = /*#__PURE__*/function () {
215
224
  if (this.writeTimer) {
216
225
  clearTimeout(this.writeTimer);
217
226
  }
218
- this.write({});
227
+ if (this._cleanUrlOnDispose) {
228
+ this.write({});
229
+ }
219
230
  }
220
231
  }, {
221
232
  key: "start",
@@ -304,7 +315,8 @@ export default function historyRouter() {
304
315
  } : _ref7$getLocation,
305
316
  start = _ref7.start,
306
317
  dispose = _ref7.dispose,
307
- push = _ref7.push;
318
+ push = _ref7.push,
319
+ cleanUrlOnDispose = _ref7.cleanUrlOnDispose;
308
320
  return new BrowserHistory({
309
321
  createURL: createURL,
310
322
  parseURL: parseURL,
@@ -313,6 +325,7 @@ export default function historyRouter() {
313
325
  getLocation: getLocation,
314
326
  start: start,
315
327
  dispose: dispose,
316
- push: push
328
+ push: push,
329
+ cleanUrlOnDispose: cleanUrlOnDispose
317
330
  });
318
331
  }
@@ -1,2 +1,2 @@
1
- declare const _default: "4.61.0";
1
+ declare const _default: "4.63.0";
2
2
  export default _default;
package/es/lib/version.js CHANGED
@@ -1 +1 @@
1
- export default '4.61.0';
1
+ export default '4.63.0';
@@ -16,7 +16,7 @@ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToAr
16
16
  function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
17
17
  import { getInsightsAnonymousUserTokenInternal } from "../helpers/index.js";
18
18
  import { warning, noop, getAppIdAndApiKey, find, safelyRunOnBrowser } from "../lib/utils/index.js";
19
- var ALGOLIA_INSIGHTS_VERSION = '2.6.0';
19
+ var ALGOLIA_INSIGHTS_VERSION = '2.13.0';
20
20
  var ALGOLIA_INSIGHTS_SRC = "https://cdn.jsdelivr.net/npm/search-insights@".concat(ALGOLIA_INSIGHTS_VERSION, "/dist/search-insights.min.js");
21
21
  export function createInsightsMiddleware() {
22
22
  var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
@@ -100,7 +100,7 @@ export function createInsightsMiddleware() {
100
100
  // set it later on.
101
101
  //
102
102
  // Otherwise, the `init` call might override it with anonymous user token.
103
- userTokenBeforeInit = userToken;
103
+ userTokenBeforeInit = normalizeUserToken(userToken);
104
104
  });
105
105
 
106
106
  // Only `init` if the `insightsInitParams` option is passed or
@@ -156,13 +156,14 @@ export function createInsightsMiddleware() {
156
156
  }
157
157
  var setUserTokenToSearch = function setUserTokenToSearch(userToken) {
158
158
  var immediate = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
159
- if (!userToken) {
159
+ var normalizedUserToken = normalizeUserToken(userToken);
160
+ if (!normalizedUserToken) {
160
161
  return;
161
162
  }
162
163
  var existingToken = helper.state.userToken;
163
164
  function applyToken() {
164
165
  helper.overrideStateWithoutTriggeringChangeEvent(_objectSpread(_objectSpread({}, helper.state), {}, {
165
- userToken: userToken
166
+ userToken: normalizedUserToken
166
167
  }));
167
168
  if (existingToken && existingToken !== userToken) {
168
169
  instantSearchInstance.scheduleSearch();
@@ -259,4 +260,15 @@ function isModernInsightsClient(client) {
259
260
  /* eslint-enable @typescript-eslint/naming-convention */
260
261
 
261
262
  return v3 || v2_6 || v1_10;
263
+ }
264
+
265
+ /**
266
+ * While `search-insights` supports both string and number user tokens,
267
+ * the Search API only accepts strings. This function normalizes the user token.
268
+ */
269
+ function normalizeUserToken(userToken) {
270
+ if (!userToken) {
271
+ return undefined;
272
+ }
273
+ return typeof userToken === 'number' ? userToken.toString() : userToken;
262
274
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "instantsearch.js",
3
- "version": "4.61.0",
3
+ "version": "4.63.0",
4
4
  "description": "InstantSearch.js is a JavaScript library for building performant and instant search experiences with Algolia.",
5
5
  "homepage": "https://www.algolia.com/doc/guides/building-search-ui/what-is-instantsearch/js/",
6
6
  "types": "es/index.d.ts",
@@ -33,12 +33,12 @@
33
33
  "@types/google.maps": "^3.45.3",
34
34
  "@types/hogan.js": "^3.0.0",
35
35
  "@types/qs": "^6.5.3",
36
- "algoliasearch-helper": "3.15.0",
36
+ "algoliasearch-helper": "3.16.1",
37
37
  "hogan.js": "^3.0.2",
38
38
  "htm": "^3.0.0",
39
39
  "preact": "^10.10.0",
40
40
  "qs": "^6.5.1 < 6.10",
41
- "search-insights": "^2.6.0"
41
+ "search-insights": "^2.13.0"
42
42
  },
43
43
  "peerDependencies": {
44
44
  "algoliasearch": ">= 3.1 < 6"
@@ -49,21 +49,21 @@
49
49
  "build:cjs": "rm -rf cjs && BABEL_ENV=cjs babel --root-mode upward src --extensions '.js,.ts,.tsx' --out-dir cjs/ --ignore 'src/index.es.ts','**/__tests__','**/__mocks__' --quiet",
50
50
  "build:es": "rm -rf es && BABEL_ENV=es babel --root-mode upward src --extensions '.js,.ts,.tsx' --out-dir es/ --ignore 'src/index.es.ts','**/__tests__','**/__mocks__' --quiet && BABEL_ENV=es babel --root-mode upward src/index.es.ts --out-file es/index.js --quiet && echo '{\"type\":\"module\",\"sideEffects\":false}' > es/package.json",
51
51
  "build:types": "scripts/typescript/extract.js",
52
- "storybook": "start-storybook --quiet --port 6006 --ci --static-dir .storybook/static",
53
- "storybook:build": "build-storybook --quiet --output-dir ../../website/stories/js --static-dir .storybook/static",
52
+ "storybook": "NODE_OPTIONS=--openssl-legacy-provider start-storybook --quiet --port 6006 --ci --static-dir .storybook/static",
53
+ "storybook:build": "NODE_OPTIONS=--openssl-legacy-provider build-storybook --quiet --output-dir ../../website/stories/js --static-dir .storybook/static",
54
54
  "test:exports": "node test/module/is-es-module.mjs && node test/module/is-cjs-module.cjs",
55
55
  "version": "./scripts/version/update-version.js"
56
56
  },
57
57
  "devDependencies": {
58
- "@instantsearch/mocks": "1.30.0",
59
- "@instantsearch/tests": "1.30.0",
60
- "@instantsearch/testutils": "1.19.0",
58
+ "@instantsearch/mocks": "1.32.0",
59
+ "@instantsearch/tests": "1.32.0",
60
+ "@instantsearch/testutils": "1.21.0",
61
61
  "@storybook/html": "5.3.9",
62
62
  "@types/scriptjs": "0.0.2",
63
63
  "algoliasearch": "4.14.3",
64
64
  "places.js": "1.17.1",
65
65
  "scriptjs": "2.5.9",
66
- "webpack": "4.41.5"
66
+ "webpack": "4.47.0"
67
67
  },
68
- "gitHead": "0035f4bc5b91cdb4095ec36f5514c6718ea00c29"
68
+ "gitHead": "b90c55a93cd6fe56128d9d6c746c153dbb3c3649"
69
69
  }