react-instantsearch 7.16.1 → 7.16.3

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.
@@ -7,7 +7,7 @@
7
7
 
8
8
  var React__default = 'default' in React ? React['default'] : React;
9
9
 
10
- var version = '7.16.1';
10
+ var version = '7.16.3';
11
11
 
12
12
  // Copyright Joyent, Inc. and other Node contributors.
13
13
  //
@@ -10546,12 +10546,18 @@
10546
10546
  }, []);
10547
10547
  }
10548
10548
  var index = function index(widgetParams) {
10549
- if (widgetParams === undefined || widgetParams.indexName === undefined) {
10549
+ if (widgetParams === undefined || widgetParams.indexName === undefined && !widgetParams.EXPERIMENTAL_isolated) {
10550
10550
  throw new Error(withUsage$2('The `indexName` option is required.'));
10551
10551
  }
10552
- var indexName = widgetParams.indexName,
10552
+
10553
+ // When isolated=true, we use an empty string as the default indexName.
10554
+ // This is intentional: isolated indices do not require a real index name.
10555
+ var _widgetParams$indexNa = widgetParams.indexName,
10556
+ indexName = _widgetParams$indexNa === void 0 ? '' : _widgetParams$indexNa,
10553
10557
  _widgetParams$indexId = widgetParams.indexId,
10554
- indexId = _widgetParams$indexId === void 0 ? indexName : _widgetParams$indexId;
10558
+ indexId = _widgetParams$indexId === void 0 ? indexName : _widgetParams$indexId,
10559
+ _widgetParams$EXPERIM = widgetParams.EXPERIMENTAL_isolated,
10560
+ isolated = _widgetParams$EXPERIM === void 0 ? false : _widgetParams$EXPERIM;
10555
10561
  var localWidgets = [];
10556
10562
  var localUiState = {};
10557
10563
  var localInstantSearchInstance = null;
@@ -10564,6 +10570,7 @@
10564
10570
  return {
10565
10571
  $$type: 'ais.index',
10566
10572
  $$widgetType: 'ais.index',
10573
+ _isolated: isolated,
10567
10574
  getIndexName: function getIndexName() {
10568
10575
  return indexName;
10569
10576
  },
@@ -10615,7 +10622,7 @@
10615
10622
  return resolveScopedResultsFromWidgets(widgetSiblings);
10616
10623
  },
10617
10624
  getParent: function getParent() {
10618
- return localParent;
10625
+ return isolated ? null : localParent;
10619
10626
  },
10620
10627
  createURL: function createURL(nextState) {
10621
10628
  if (typeof nextState === 'function') {
@@ -10634,12 +10641,15 @@
10634
10641
  if (!Array.isArray(widgets)) {
10635
10642
  throw new Error(withUsage$2('The `addWidgets` method expects an array of widgets.'));
10636
10643
  }
10637
- if (widgets.some(function (widget) {
10644
+ var flatWidgets = widgets.reduce(function (acc, w) {
10645
+ return acc.concat(Array.isArray(w) ? w : [w]);
10646
+ }, []);
10647
+ if (flatWidgets.some(function (widget) {
10638
10648
  return typeof widget.init !== 'function' && typeof widget.render !== 'function';
10639
10649
  })) {
10640
10650
  throw new Error(withUsage$2('The widget definition expects a `render` and/or an `init` method.'));
10641
10651
  }
10642
- widgets.forEach(function (widget) {
10652
+ flatWidgets.forEach(function (widget) {
10643
10653
  if (isIndexWidget(widget)) {
10644
10654
  return;
10645
10655
  }
@@ -10654,8 +10664,8 @@
10654
10664
  }
10655
10665
  addWidgetId(widget);
10656
10666
  });
10657
- localWidgets = localWidgets.concat(widgets);
10658
- if (localInstantSearchInstance && Boolean(widgets.length)) {
10667
+ localWidgets = localWidgets.concat(flatWidgets);
10668
+ if (localInstantSearchInstance && Boolean(flatWidgets.length)) {
10659
10669
  privateHelperSetState(helper, {
10660
10670
  state: getLocalWidgetsSearchParameters(localWidgets, {
10661
10671
  uiState: localUiState,
@@ -10671,7 +10681,7 @@
10671
10681
  // We compute the render state before calling `init` in a separate loop
10672
10682
  // to construct the whole render state object that is then passed to
10673
10683
  // `init`.
10674
- widgets.forEach(function (widget) {
10684
+ flatWidgets.forEach(function (widget) {
10675
10685
  if (widget.getRenderState) {
10676
10686
  var renderState = widget.getRenderState(localInstantSearchInstance.renderState[_this.getIndexId()] || {}, createInitArgs(localInstantSearchInstance, _this, localInstantSearchInstance._initialUiState));
10677
10687
  storeRenderState({
@@ -10681,12 +10691,17 @@
10681
10691
  });
10682
10692
  }
10683
10693
  });
10684
- widgets.forEach(function (widget) {
10694
+ flatWidgets.forEach(function (widget) {
10685
10695
  if (widget.init) {
10686
10696
  widget.init(createInitArgs(localInstantSearchInstance, _this, localInstantSearchInstance._initialUiState));
10687
10697
  }
10688
10698
  });
10689
- localInstantSearchInstance.scheduleSearch();
10699
+ if (isolated) {
10700
+ var _helper2;
10701
+ (_helper2 = helper) === null || _helper2 === void 0 ? void 0 : _helper2.search();
10702
+ } else {
10703
+ localInstantSearchInstance.scheduleSearch();
10704
+ }
10690
10705
  }
10691
10706
  return this;
10692
10707
  },
@@ -10695,13 +10710,16 @@
10695
10710
  if (!Array.isArray(widgets)) {
10696
10711
  throw new Error(withUsage$2('The `removeWidgets` method expects an array of widgets.'));
10697
10712
  }
10698
- if (widgets.some(function (widget) {
10713
+ var flatWidgets = widgets.reduce(function (acc, w) {
10714
+ return acc.concat(Array.isArray(w) ? w : [w]);
10715
+ }, []);
10716
+ if (flatWidgets.some(function (widget) {
10699
10717
  return typeof widget.dispose !== 'function';
10700
10718
  })) {
10701
10719
  throw new Error(withUsage$2('The widget definition expects a `dispose` method.'));
10702
10720
  }
10703
10721
  localWidgets = localWidgets.filter(function (widget) {
10704
- return widgets.indexOf(widget) === -1;
10722
+ return flatWidgets.indexOf(widget) === -1;
10705
10723
  });
10706
10724
  localWidgets.forEach(function (widget) {
10707
10725
  if (isIndexWidget(widget)) {
@@ -10717,8 +10735,8 @@
10717
10735
  hasSearchWidget = true;
10718
10736
  }
10719
10737
  });
10720
- if (localInstantSearchInstance && Boolean(widgets.length)) {
10721
- var _widgets$reduce = widgets.reduce(function (states, widget) {
10738
+ if (localInstantSearchInstance && Boolean(flatWidgets.length)) {
10739
+ var _flatWidgets$reduce = flatWidgets.reduce(function (states, widget) {
10722
10740
  // the `dispose` method exists at this point we already assert it
10723
10741
  var next = widget.dispose({
10724
10742
  helper: helper,
@@ -10736,8 +10754,8 @@
10736
10754
  cleanedSearchState: helper.state,
10737
10755
  cleanedRecommendState: helper.recommendState
10738
10756
  }),
10739
- cleanedSearchState = _widgets$reduce.cleanedSearchState,
10740
- cleanedRecommendState = _widgets$reduce.cleanedRecommendState;
10757
+ cleanedSearchState = _flatWidgets$reduce.cleanedSearchState,
10758
+ cleanedRecommendState = _flatWidgets$reduce.cleanedRecommendState;
10741
10759
  var newState = localInstantSearchInstance.future.preserveSharedStateOnUnmount ? getLocalWidgetsSearchParameters(localWidgets, {
10742
10760
  uiState: localUiState,
10743
10761
  initialSearchParameters: new algoliasearchHelper_1.SearchParameters({
@@ -10757,7 +10775,12 @@
10757
10775
  helper.setState(newState);
10758
10776
  helper.recommendState = cleanedRecommendState;
10759
10777
  if (localWidgets.length) {
10760
- localInstantSearchInstance.scheduleSearch();
10778
+ if (isolated) {
10779
+ var _helper3;
10780
+ (_helper3 = helper) === null || _helper3 === void 0 ? void 0 : _helper3.search();
10781
+ } else {
10782
+ localInstantSearchInstance.scheduleSearch();
10783
+ }
10761
10784
  }
10762
10785
  }
10763
10786
  return this;
@@ -10795,13 +10818,20 @@
10795
10818
  // This Helper is only used for state management we do not care about the
10796
10819
  // `searchClient`. Only the "main" Helper created at the `InstantSearch`
10797
10820
  // level is aware of the client.
10798
- helper = algoliasearchHelper_1({}, parameters.index, parameters);
10821
+ helper = algoliasearchHelper_1(mainHelper.getClient(), parameters.index, parameters);
10799
10822
  helper.recommendState = recommendParameters;
10800
10823
 
10801
10824
  // We forward the call to `search` to the "main" instance of the Helper
10802
10825
  // which is responsible for managing the queries (it's the only one that is
10803
10826
  // aware of the `searchClient`).
10804
10827
  helper.search = function () {
10828
+ if (isolated) {
10829
+ instantSearchInstance.status = 'loading';
10830
+ _this3.render({
10831
+ instantSearchInstance: instantSearchInstance
10832
+ });
10833
+ return instantSearchInstance.compositionID ? helper.searchWithComposition() : helper.searchOnlyWithDerivedHelpers();
10834
+ }
10805
10835
  if (instantSearchInstance.onStateChange) {
10806
10836
  instantSearchInstance.onStateChange({
10807
10837
  uiState: instantSearchInstance.mainIndex.getWidgetUiState({}),
@@ -10825,7 +10855,9 @@
10825
10855
  var state = helper.state.setQueryParameters(userState);
10826
10856
  return mainHelper.searchForFacetValues(facetName, facetValue, maxFacetHits, state);
10827
10857
  };
10828
- derivedHelper = mainHelper.derive(function () {
10858
+ var isolatedHelper = indexName ? helper : algoliasearchHelper_1({}, '__empty_index__', {});
10859
+ var derivingHelper = isolated ? isolatedHelper : nearestIsolatedHelper(parent, mainHelper);
10860
+ derivedHelper = derivingHelper.derive(function () {
10829
10861
  return mergeSearchParameters.apply(void 0, [mainHelper.state].concat(_toConsumableArray$1(resolveSearchParameters(_this3))));
10830
10862
  }, function () {
10831
10863
  return _this3.getHelper().recommendState;
@@ -10957,7 +10989,9 @@
10957
10989
 
10958
10990
  // We only render index widgets if there are no results.
10959
10991
  // This makes sure `render` is never called with `results` being `null`.
10960
- var widgetsToRender = this.getResults() || (_derivedHelper2 = derivedHelper) !== null && _derivedHelper2 !== void 0 && _derivedHelper2.lastRecommendResults ? localWidgets : localWidgets.filter(isIndexWidget);
10992
+ // If it's an isolated index without an index name, we render all widgets,
10993
+ // as there are no results to display for the isolated index itself.
10994
+ var widgetsToRender = this.getResults() || (_derivedHelper2 = derivedHelper) !== null && _derivedHelper2 !== void 0 && _derivedHelper2.lastRecommendResults || isolated && !indexName ? localWidgets : localWidgets.filter(isIndexWidget);
10961
10995
  widgetsToRender = widgetsToRender.filter(function (widget) {
10962
10996
  if (!widget.shouldRender) {
10963
10997
  return true;
@@ -10991,7 +11025,7 @@
10991
11025
  },
10992
11026
  dispose: function dispose() {
10993
11027
  var _this5 = this,
10994
- _helper2,
11028
+ _helper4,
10995
11029
  _derivedHelper3;
10996
11030
  localWidgets.forEach(function (widget) {
10997
11031
  if (widget.dispose && helper) {
@@ -11011,13 +11045,15 @@
11011
11045
  });
11012
11046
  localInstantSearchInstance = null;
11013
11047
  localParent = null;
11014
- (_helper2 = helper) === null || _helper2 === void 0 ? void 0 : _helper2.removeAllListeners();
11048
+ (_helper4 = helper) === null || _helper4 === void 0 ? void 0 : _helper4.removeAllListeners();
11015
11049
  helper = null;
11016
11050
  (_derivedHelper3 = derivedHelper) === null || _derivedHelper3 === void 0 ? void 0 : _derivedHelper3.detach();
11017
11051
  derivedHelper = null;
11018
11052
  },
11019
11053
  getWidgetUiState: function getWidgetUiState(uiState) {
11020
- return localWidgets.filter(isIndexWidget).reduce(function (previousUiState, innerIndex) {
11054
+ return localWidgets.filter(isIndexWidget).filter(function (w) {
11055
+ return !w._isolated;
11056
+ }).reduce(function (previousUiState, innerIndex) {
11021
11057
  return innerIndex.getWidgetUiState(previousUiState);
11022
11058
  }, _objectSpread$f(_objectSpread$f({}, uiState), {}, _defineProperty$f({}, indexId, _objectSpread$f(_objectSpread$f({}, uiState[indexId]), localUiState))));
11023
11059
  },
@@ -11053,6 +11089,19 @@
11053
11089
  instantSearchInstance.renderState = _objectSpread$f(_objectSpread$f({}, instantSearchInstance.renderState), {}, _defineProperty$f({}, parentIndexName, _objectSpread$f(_objectSpread$f({}, instantSearchInstance.renderState[parentIndexName]), renderState)));
11054
11090
  }
11055
11091
 
11092
+ /**
11093
+ * Walk up the parent chain to find the closest isolated index, or fall back to mainHelper
11094
+ */
11095
+ function nearestIsolatedHelper(current, mainHelper) {
11096
+ while (current) {
11097
+ if (current._isolated) {
11098
+ return current.getHelper();
11099
+ }
11100
+ current = current.getParent();
11101
+ }
11102
+ return mainHelper;
11103
+ }
11104
+
11056
11105
  function _slicedToArray$6(arr, i) {
11057
11106
  return _arrayWithHoles$6(arr) || _iterableToArrayLimit$6(arr, i) || _unsupportedIterableToArray$8(arr, i) || _nonIterableRest$6();
11058
11107
  }
@@ -13468,7 +13517,7 @@
13468
13517
  };
13469
13518
  }
13470
13519
 
13471
- var version$3 = '4.79.1';
13520
+ var version$3 = '4.80.0';
13472
13521
 
13473
13522
  function _typeof$q(o) {
13474
13523
  "@babel/helpers - typeof";
@@ -13902,12 +13951,9 @@
13902
13951
  if (!Array.isArray(widgets)) {
13903
13952
  throw new Error(withUsage$3('The `addWidgets` method expects an array of widgets. Please use `addWidget`.'));
13904
13953
  }
13905
- if (widgets.some(function (widget) {
13906
- return typeof widget.init !== 'function' && typeof widget.render !== 'function';
13954
+ if (this.compositionID && widgets.some(function (w) {
13955
+ return !Array.isArray(w) && isIndexWidget(w) && !w._isolated;
13907
13956
  })) {
13908
- throw new Error(withUsage$3('The widget definition expects a `render` and/or an `init` method.'));
13909
- }
13910
- if (this.compositionID && widgets.some(isIndexWidget)) {
13911
13957
  throw new Error(withUsage$3('The `index` widget cannot be used with a composition-based InstantSearch implementation.'));
13912
13958
  }
13913
13959
  this.mainIndex.addWidgets(widgets);
@@ -13939,11 +13985,6 @@
13939
13985
  if (!Array.isArray(widgets)) {
13940
13986
  throw new Error(withUsage$3('The `removeWidgets` method expects an array of widgets. Please use `removeWidget`.'));
13941
13987
  }
13942
- if (widgets.some(function (widget) {
13943
- return typeof widget.dispose !== 'function';
13944
- })) {
13945
- throw new Error(withUsage$3('The widget definition expects a `dispose` method.'));
13946
- }
13947
13988
  this.mainIndex.removeWidgets(widgets);
13948
13989
  return this;
13949
13990
  }
@@ -16796,22 +16837,20 @@
16796
16837
  return Math.max.apply(Math, [page].concat(_toConsumableArray$6(pages)));
16797
16838
  }
16798
16839
  };
16799
- var getShowPrevious = function getShowPrevious(helper) {
16840
+ var getShowPrevious = function getShowPrevious(helper, getCachedHits) {
16800
16841
  return function () {
16842
+ var cachedHits = getCachedHits();
16801
16843
  // Using the helper's `overrideStateWithoutTriggeringChangeEvent` method
16802
16844
  // avoid updating the browser URL when the user displays the previous page.
16803
16845
  helper.overrideStateWithoutTriggeringChangeEvent(_objectSpread$v(_objectSpread$v({}, helper.state), {}, {
16804
- page: getFirstReceivedPage(helper.state, cache.read({
16805
- state: normalizeState(helper.state)
16806
- }) || {}) - 1
16846
+ page: getFirstReceivedPage(helper.state, cachedHits) - 1
16807
16847
  })).searchWithoutTriggeringOnStateChange();
16808
16848
  };
16809
16849
  };
16810
- var getShowMore = function getShowMore(helper) {
16850
+ var getShowMore = function getShowMore(helper, getCachedHits) {
16811
16851
  return function () {
16812
- helper.setPage(getLastReceivedPage(helper.state, cache.read({
16813
- state: normalizeState(helper.state)
16814
- }) || {}) + 1).search();
16852
+ var cachedHits = getCachedHits();
16853
+ helper.setPage(getLastReceivedPage(helper.state, cachedHits) + 1).search();
16815
16854
  };
16816
16855
  };
16817
16856
  return {
@@ -16843,6 +16882,12 @@
16843
16882
  parent = _ref6.parent,
16844
16883
  existingState = _ref6.state,
16845
16884
  instantSearchInstance = _ref6.instantSearchInstance;
16885
+ var getCacheHits = function getCacheHits() {
16886
+ var state = parent.getPreviousState() || existingState;
16887
+ return cache.read({
16888
+ state: normalizeState(state)
16889
+ }) || {};
16890
+ };
16846
16891
  var isFirstPage;
16847
16892
  var currentPageHits = [];
16848
16893
  /**
@@ -16851,13 +16896,15 @@
16851
16896
  * is loading.
16852
16897
  */
16853
16898
  var state = parent.getPreviousState() || existingState;
16854
- var cachedHits = cache.read({
16855
- state: normalizeState(state)
16856
- }) || {};
16899
+ var cachedHits = getCacheHits();
16857
16900
  var banner = results === null || results === void 0 ? void 0 : (_results$renderingCon = results.renderingContent) === null || _results$renderingCon === void 0 ? void 0 : (_results$renderingCon2 = _results$renderingCon.widgets) === null || _results$renderingCon2 === void 0 ? void 0 : (_results$renderingCon3 = _results$renderingCon2.banners) === null || _results$renderingCon3 === void 0 ? void 0 : _results$renderingCon3[0];
16858
16901
  if (!showPrevious) {
16859
- showPrevious = getShowPrevious(helper);
16860
- showMore = getShowMore(helper);
16902
+ showPrevious = function showPrevious() {
16903
+ return getShowPrevious(helper, getCacheHits)();
16904
+ };
16905
+ showMore = function showMore() {
16906
+ return getShowMore(helper, getCacheHits)();
16907
+ };
16861
16908
  }
16862
16909
  if (!sendEvent) {
16863
16910
  sendEvent = createSendEventForHits({