instantsearch.js 4.50.3 → 4.51.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -87,8 +87,8 @@ var connectBreadcrumb = function connectBreadcrumb(renderFn) {
87
87
  var _state$hierarchicalFa = _slicedToArray(state.hierarchicalFacets, 1),
88
88
  facetName = _state$hierarchicalFa[0].name;
89
89
  var facetValues = results.getFacetValues(facetName, {});
90
- var data = Array.isArray(facetValues.data) ? facetValues.data : [];
91
- var items = transformItems(shiftItemsValues(prepareItems(data)), {
90
+ var facetItems = facetValues && !Array.isArray(facetValues) && facetValues.data ? facetValues.data : [];
91
+ var items = transformItems(shiftItemsValues(prepareItems(facetItems)), {
92
92
  results: results
93
93
  });
94
94
  return items;
@@ -33,7 +33,10 @@ var BrowserHistory = /*#__PURE__*/function () {
33
33
  writeDelay = _ref$writeDelay === void 0 ? 400 : _ref$writeDelay,
34
34
  createURL = _ref.createURL,
35
35
  parseURL = _ref.parseURL,
36
- getLocation = _ref.getLocation;
36
+ getLocation = _ref.getLocation,
37
+ start = _ref.start,
38
+ dispose = _ref.dispose,
39
+ push = _ref.push;
37
40
  _classCallCheck(this, BrowserHistory);
38
41
  _defineProperty(this, "windowTitle", void 0);
39
42
  _defineProperty(this, "writeDelay", void 0);
@@ -44,12 +47,18 @@ var BrowserHistory = /*#__PURE__*/function () {
44
47
  _defineProperty(this, "inPopState", false);
45
48
  _defineProperty(this, "isDisposed", false);
46
49
  _defineProperty(this, "latestAcknowledgedHistory", 0);
50
+ _defineProperty(this, "_start", void 0);
51
+ _defineProperty(this, "_dispose", void 0);
52
+ _defineProperty(this, "_push", void 0);
47
53
  this.windowTitle = windowTitle;
48
54
  this.writeTimer = undefined;
49
55
  this.writeDelay = writeDelay;
50
56
  this._createURL = createURL;
51
57
  this.parseURL = parseURL;
52
58
  this.getLocation = getLocation;
59
+ this._start = start;
60
+ this._dispose = dispose;
61
+ this._push = push;
53
62
  (0, _utils.safelyRunOnBrowser)(function (_ref2) {
54
63
  var window = _ref2.window;
55
64
  var title = _this.windowTitle && _this.windowTitle(_this.read());
@@ -87,7 +96,11 @@ var BrowserHistory = /*#__PURE__*/function () {
87
96
  _this2.writeTimer = setTimeout(function () {
88
97
  setWindowTitle(title);
89
98
  if (_this2.shouldWrite(url)) {
90
- window.history.pushState(routeState, title || '', url);
99
+ if (_this2._push) {
100
+ _this2._push(url);
101
+ } else {
102
+ window.history.pushState(routeState, title || '', url);
103
+ }
91
104
  _this2.latestAcknowledgedHistory = window.history.length;
92
105
  }
93
106
  _this2.inPopState = false;
@@ -104,6 +117,11 @@ var BrowserHistory = /*#__PURE__*/function () {
104
117
  key: "onUpdate",
105
118
  value: function onUpdate(callback) {
106
119
  var _this3 = this;
120
+ if (this._start) {
121
+ this._start(function () {
122
+ callback(_this3.read());
123
+ });
124
+ }
107
125
  this._onPopState = function () {
108
126
  if (_this3.writeTimer) {
109
127
  clearTimeout(_this3.writeTimer);
@@ -145,6 +163,9 @@ var BrowserHistory = /*#__PURE__*/function () {
145
163
  key: "dispose",
146
164
  value: function dispose() {
147
165
  var _this4 = this;
166
+ if (this._dispose) {
167
+ this._dispose();
168
+ }
148
169
  this.isDisposed = true;
149
170
  (0, _utils.safelyRunOnBrowser)(function (_ref5) {
150
171
  var window = _ref5.window;
@@ -236,12 +257,18 @@ function historyRouter() {
236
257
  throw new Error('You need to provide `getLocation` to the `history` router in environments where `window` does not exist.');
237
258
  }
238
259
  });
239
- } : _ref7$getLocation;
260
+ } : _ref7$getLocation,
261
+ start = _ref7.start,
262
+ dispose = _ref7.dispose,
263
+ push = _ref7.push;
240
264
  return new BrowserHistory({
241
265
  createURL: createURL,
242
266
  parseURL: parseURL,
243
267
  writeDelay: writeDelay,
244
268
  windowTitle: windowTitle,
245
- getLocation: getLocation
269
+ getLocation: getLocation,
270
+ start: start,
271
+ dispose: dispose,
272
+ push: push
246
273
  });
247
274
  }
@@ -4,5 +4,5 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
- var _default = '4.50.3';
7
+ var _default = '4.51.1';
8
8
  exports.default = _default;
@@ -482,11 +482,14 @@ declare class BrowserHistory<TRouteState> implements Router<TRouteState> {
482
482
  * and thus to prevent the `write` method from calling `pushState`.
483
483
  */
484
484
  private latestAcknowledgedHistory;
485
+ private _start?;
486
+ private _dispose?;
487
+ private _push?;
485
488
  /**
486
489
  * Initializes a new storage provider that syncs the search state to the URL
487
490
  * using web APIs (`window.location.pushState` and `onpopstate` event).
488
491
  */
489
- constructor({ windowTitle, writeDelay, createURL, parseURL, getLocation, }: BrowserHistoryArgs<TRouteState>);
492
+ constructor({ windowTitle, writeDelay, createURL, parseURL, getLocation, start, dispose, push, }: BrowserHistoryArgs<TRouteState>);
490
493
  /**
491
494
  * Reads the URL and returns a syncable UI search state.
492
495
  */
@@ -521,6 +524,9 @@ declare type BrowserHistoryArgs<TRouteState> = {
521
524
  createURL: CreateURL_2<TRouteState>;
522
525
  parseURL: ParseURL<TRouteState>;
523
526
  getLocation(): Location;
527
+ start?: (onUpdate: () => void) => void;
528
+ dispose?: () => void;
529
+ push?: (url: string) => void;
524
530
  };
525
531
 
526
532
  declare type BuiltInBindEventForHits = (eventType: string, hits: Hit | Hit[], eventName?: string) => string;
@@ -1786,7 +1792,7 @@ declare type HighlightProps_2 = Omit<HighlightProps_3, 'classNames'> & {
1786
1792
  classNames?: Partial<HighlightClassNames>;
1787
1793
  };
1788
1794
 
1789
- declare function historyRouter<TRouteState = UiState>({ createURL, parseURL, writeDelay, windowTitle, getLocation, }?: Partial<BrowserHistoryArgs<TRouteState>>): BrowserHistory<TRouteState>;
1795
+ declare function historyRouter<TRouteState = UiState>({ createURL, parseURL, writeDelay, windowTitle, getLocation, start, dispose, push, }?: Partial<BrowserHistoryArgs<TRouteState>>): BrowserHistory<TRouteState>;
1790
1796
 
1791
1797
  declare type Hit<THit extends BaseHit = Record<string, any>> = {
1792
1798
  __position: number;
@@ -1,4 +1,4 @@
1
- /*! InstantSearch.js 4.50.3 | © Algolia, Inc. and contributors; MIT License | https://github.com/algolia/instantsearch.js */
1
+ /*! InstantSearch.js 4.51.1 | © Algolia, Inc. and contributors; MIT License | https://github.com/algolia/instantsearch.js */
2
2
  (function (global, factory) {
3
3
  typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
4
4
  typeof define === 'function' && define.amd ? define(factory) :
@@ -7620,7 +7620,7 @@
7620
7620
  instantSearchInstance.renderState = _objectSpread2(_objectSpread2({}, instantSearchInstance.renderState), {}, _defineProperty({}, parentIndexName, _objectSpread2(_objectSpread2({}, instantSearchInstance.renderState[parentIndexName]), renderState)));
7621
7621
  }
7622
7622
 
7623
- var version$1 = '4.50.3';
7623
+ var version$1 = '4.51.1';
7624
7624
 
7625
7625
  var NAMESPACE = 'ais';
7626
7626
  var component = function component(componentName) {
@@ -8720,7 +8720,10 @@
8720
8720
  writeDelay = _ref$writeDelay === void 0 ? 400 : _ref$writeDelay,
8721
8721
  createURL = _ref.createURL,
8722
8722
  parseURL = _ref.parseURL,
8723
- getLocation = _ref.getLocation;
8723
+ getLocation = _ref.getLocation,
8724
+ start = _ref.start,
8725
+ dispose = _ref.dispose,
8726
+ push = _ref.push;
8724
8727
  _classCallCheck(this, BrowserHistory);
8725
8728
  _defineProperty(this, "windowTitle", void 0);
8726
8729
  _defineProperty(this, "writeDelay", void 0);
@@ -8731,12 +8734,18 @@
8731
8734
  _defineProperty(this, "inPopState", false);
8732
8735
  _defineProperty(this, "isDisposed", false);
8733
8736
  _defineProperty(this, "latestAcknowledgedHistory", 0);
8737
+ _defineProperty(this, "_start", void 0);
8738
+ _defineProperty(this, "_dispose", void 0);
8739
+ _defineProperty(this, "_push", void 0);
8734
8740
  this.windowTitle = windowTitle;
8735
8741
  this.writeTimer = undefined;
8736
8742
  this.writeDelay = writeDelay;
8737
8743
  this._createURL = createURL;
8738
8744
  this.parseURL = parseURL;
8739
8745
  this.getLocation = getLocation;
8746
+ this._start = start;
8747
+ this._dispose = dispose;
8748
+ this._push = push;
8740
8749
  safelyRunOnBrowser(function (_ref2) {
8741
8750
  var window = _ref2.window;
8742
8751
  var title = _this.windowTitle && _this.windowTitle(_this.read());
@@ -8774,7 +8783,11 @@
8774
8783
  _this2.writeTimer = setTimeout(function () {
8775
8784
  setWindowTitle(title);
8776
8785
  if (_this2.shouldWrite(url)) {
8777
- window.history.pushState(routeState, title || '', url);
8786
+ if (_this2._push) {
8787
+ _this2._push(url);
8788
+ } else {
8789
+ window.history.pushState(routeState, title || '', url);
8790
+ }
8778
8791
  _this2.latestAcknowledgedHistory = window.history.length;
8779
8792
  }
8780
8793
  _this2.inPopState = false;
@@ -8791,6 +8804,11 @@
8791
8804
  key: "onUpdate",
8792
8805
  value: function onUpdate(callback) {
8793
8806
  var _this3 = this;
8807
+ if (this._start) {
8808
+ this._start(function () {
8809
+ callback(_this3.read());
8810
+ });
8811
+ }
8794
8812
  this._onPopState = function () {
8795
8813
  if (_this3.writeTimer) {
8796
8814
  clearTimeout(_this3.writeTimer);
@@ -8832,6 +8850,9 @@
8832
8850
  key: "dispose",
8833
8851
  value: function dispose() {
8834
8852
  var _this4 = this;
8853
+ if (this._dispose) {
8854
+ this._dispose();
8855
+ }
8835
8856
  this.isDisposed = true;
8836
8857
  safelyRunOnBrowser(function (_ref5) {
8837
8858
  var window = _ref5.window;
@@ -8923,13 +8944,19 @@
8923
8944
  throw new Error('You need to provide `getLocation` to the `history` router in environments where `window` does not exist.');
8924
8945
  }
8925
8946
  });
8926
- } : _ref7$getLocation;
8947
+ } : _ref7$getLocation,
8948
+ start = _ref7.start,
8949
+ dispose = _ref7.dispose,
8950
+ push = _ref7.push;
8927
8951
  return new BrowserHistory({
8928
8952
  createURL: createURL,
8929
8953
  parseURL: parseURL,
8930
8954
  writeDelay: writeDelay,
8931
8955
  windowTitle: windowTitle,
8932
- getLocation: getLocation
8956
+ getLocation: getLocation,
8957
+ start: start,
8958
+ dispose: dispose,
8959
+ push: push
8933
8960
  });
8934
8961
  }
8935
8962
 
@@ -12704,8 +12731,8 @@
12704
12731
  var _state$hierarchicalFa = _slicedToArray(state.hierarchicalFacets, 1),
12705
12732
  facetName = _state$hierarchicalFa[0].name;
12706
12733
  var facetValues = results.getFacetValues(facetName, {});
12707
- var data = Array.isArray(facetValues.data) ? facetValues.data : [];
12708
- var items = transformItems(shiftItemsValues(prepareItems(data)), {
12734
+ var facetItems = facetValues && !Array.isArray(facetValues) && facetValues.data ? facetValues.data : [];
12735
+ var items = transformItems(shiftItemsValues(prepareItems(facetItems)), {
12709
12736
  results: results
12710
12737
  });
12711
12738
  return items;