react-instantsearch-core 7.16.2 → 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.
@@ -4,4 +4,4 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
- var _default = exports.default = '7.16.2';
7
+ var _default = exports.default = '7.16.3';
@@ -1,2 +1,2 @@
1
- declare const _default: "7.16.2";
1
+ declare const _default: "7.16.3";
2
2
  export default _default;
@@ -1 +1 @@
1
- export default '7.16.2';
1
+ export default '7.16.3';
@@ -7,7 +7,7 @@
7
7
 
8
8
  var React__default = 'default' in React ? React['default'] : React;
9
9
 
10
- var version = '7.16.2';
10
+ var version = '7.16.3';
11
11
 
12
12
  function _iterableToArrayLimit(r, l) {
13
13
  var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
@@ -10067,12 +10067,18 @@
10067
10067
  }, []);
10068
10068
  }
10069
10069
  var index = function index(widgetParams) {
10070
- if (widgetParams === undefined || widgetParams.indexName === undefined) {
10070
+ if (widgetParams === undefined || widgetParams.indexName === undefined && !widgetParams.EXPERIMENTAL_isolated) {
10071
10071
  throw new Error(withUsage$2('The `indexName` option is required.'));
10072
10072
  }
10073
- var indexName = widgetParams.indexName,
10073
+
10074
+ // When isolated=true, we use an empty string as the default indexName.
10075
+ // This is intentional: isolated indices do not require a real index name.
10076
+ var _widgetParams$indexNa = widgetParams.indexName,
10077
+ indexName = _widgetParams$indexNa === void 0 ? '' : _widgetParams$indexNa,
10074
10078
  _widgetParams$indexId = widgetParams.indexId,
10075
- indexId = _widgetParams$indexId === void 0 ? indexName : _widgetParams$indexId;
10079
+ indexId = _widgetParams$indexId === void 0 ? indexName : _widgetParams$indexId,
10080
+ _widgetParams$EXPERIM = widgetParams.EXPERIMENTAL_isolated,
10081
+ isolated = _widgetParams$EXPERIM === void 0 ? false : _widgetParams$EXPERIM;
10076
10082
  var localWidgets = [];
10077
10083
  var localUiState = {};
10078
10084
  var localInstantSearchInstance = null;
@@ -10085,6 +10091,7 @@
10085
10091
  return {
10086
10092
  $$type: 'ais.index',
10087
10093
  $$widgetType: 'ais.index',
10094
+ _isolated: isolated,
10088
10095
  getIndexName: function getIndexName() {
10089
10096
  return indexName;
10090
10097
  },
@@ -10136,7 +10143,7 @@
10136
10143
  return resolveScopedResultsFromWidgets(widgetSiblings);
10137
10144
  },
10138
10145
  getParent: function getParent() {
10139
- return localParent;
10146
+ return isolated ? null : localParent;
10140
10147
  },
10141
10148
  createURL: function createURL(nextState) {
10142
10149
  if (typeof nextState === 'function') {
@@ -10155,12 +10162,15 @@
10155
10162
  if (!Array.isArray(widgets)) {
10156
10163
  throw new Error(withUsage$2('The `addWidgets` method expects an array of widgets.'));
10157
10164
  }
10158
- if (widgets.some(function (widget) {
10165
+ var flatWidgets = widgets.reduce(function (acc, w) {
10166
+ return acc.concat(Array.isArray(w) ? w : [w]);
10167
+ }, []);
10168
+ if (flatWidgets.some(function (widget) {
10159
10169
  return typeof widget.init !== 'function' && typeof widget.render !== 'function';
10160
10170
  })) {
10161
10171
  throw new Error(withUsage$2('The widget definition expects a `render` and/or an `init` method.'));
10162
10172
  }
10163
- widgets.forEach(function (widget) {
10173
+ flatWidgets.forEach(function (widget) {
10164
10174
  if (isIndexWidget(widget)) {
10165
10175
  return;
10166
10176
  }
@@ -10175,8 +10185,8 @@
10175
10185
  }
10176
10186
  addWidgetId(widget);
10177
10187
  });
10178
- localWidgets = localWidgets.concat(widgets);
10179
- if (localInstantSearchInstance && Boolean(widgets.length)) {
10188
+ localWidgets = localWidgets.concat(flatWidgets);
10189
+ if (localInstantSearchInstance && Boolean(flatWidgets.length)) {
10180
10190
  privateHelperSetState(helper, {
10181
10191
  state: getLocalWidgetsSearchParameters(localWidgets, {
10182
10192
  uiState: localUiState,
@@ -10192,7 +10202,7 @@
10192
10202
  // We compute the render state before calling `init` in a separate loop
10193
10203
  // to construct the whole render state object that is then passed to
10194
10204
  // `init`.
10195
- widgets.forEach(function (widget) {
10205
+ flatWidgets.forEach(function (widget) {
10196
10206
  if (widget.getRenderState) {
10197
10207
  var renderState = widget.getRenderState(localInstantSearchInstance.renderState[_this.getIndexId()] || {}, createInitArgs(localInstantSearchInstance, _this, localInstantSearchInstance._initialUiState));
10198
10208
  storeRenderState({
@@ -10202,12 +10212,17 @@
10202
10212
  });
10203
10213
  }
10204
10214
  });
10205
- widgets.forEach(function (widget) {
10215
+ flatWidgets.forEach(function (widget) {
10206
10216
  if (widget.init) {
10207
10217
  widget.init(createInitArgs(localInstantSearchInstance, _this, localInstantSearchInstance._initialUiState));
10208
10218
  }
10209
10219
  });
10210
- localInstantSearchInstance.scheduleSearch();
10220
+ if (isolated) {
10221
+ var _helper2;
10222
+ (_helper2 = helper) === null || _helper2 === void 0 ? void 0 : _helper2.search();
10223
+ } else {
10224
+ localInstantSearchInstance.scheduleSearch();
10225
+ }
10211
10226
  }
10212
10227
  return this;
10213
10228
  },
@@ -10216,13 +10231,16 @@
10216
10231
  if (!Array.isArray(widgets)) {
10217
10232
  throw new Error(withUsage$2('The `removeWidgets` method expects an array of widgets.'));
10218
10233
  }
10219
- if (widgets.some(function (widget) {
10234
+ var flatWidgets = widgets.reduce(function (acc, w) {
10235
+ return acc.concat(Array.isArray(w) ? w : [w]);
10236
+ }, []);
10237
+ if (flatWidgets.some(function (widget) {
10220
10238
  return typeof widget.dispose !== 'function';
10221
10239
  })) {
10222
10240
  throw new Error(withUsage$2('The widget definition expects a `dispose` method.'));
10223
10241
  }
10224
10242
  localWidgets = localWidgets.filter(function (widget) {
10225
- return widgets.indexOf(widget) === -1;
10243
+ return flatWidgets.indexOf(widget) === -1;
10226
10244
  });
10227
10245
  localWidgets.forEach(function (widget) {
10228
10246
  if (isIndexWidget(widget)) {
@@ -10238,8 +10256,8 @@
10238
10256
  hasSearchWidget = true;
10239
10257
  }
10240
10258
  });
10241
- if (localInstantSearchInstance && Boolean(widgets.length)) {
10242
- var _widgets$reduce = widgets.reduce(function (states, widget) {
10259
+ if (localInstantSearchInstance && Boolean(flatWidgets.length)) {
10260
+ var _flatWidgets$reduce = flatWidgets.reduce(function (states, widget) {
10243
10261
  // the `dispose` method exists at this point we already assert it
10244
10262
  var next = widget.dispose({
10245
10263
  helper: helper,
@@ -10257,8 +10275,8 @@
10257
10275
  cleanedSearchState: helper.state,
10258
10276
  cleanedRecommendState: helper.recommendState
10259
10277
  }),
10260
- cleanedSearchState = _widgets$reduce.cleanedSearchState,
10261
- cleanedRecommendState = _widgets$reduce.cleanedRecommendState;
10278
+ cleanedSearchState = _flatWidgets$reduce.cleanedSearchState,
10279
+ cleanedRecommendState = _flatWidgets$reduce.cleanedRecommendState;
10262
10280
  var newState = localInstantSearchInstance.future.preserveSharedStateOnUnmount ? getLocalWidgetsSearchParameters(localWidgets, {
10263
10281
  uiState: localUiState,
10264
10282
  initialSearchParameters: new algoliasearchHelper_1.SearchParameters({
@@ -10278,7 +10296,12 @@
10278
10296
  helper.setState(newState);
10279
10297
  helper.recommendState = cleanedRecommendState;
10280
10298
  if (localWidgets.length) {
10281
- localInstantSearchInstance.scheduleSearch();
10299
+ if (isolated) {
10300
+ var _helper3;
10301
+ (_helper3 = helper) === null || _helper3 === void 0 ? void 0 : _helper3.search();
10302
+ } else {
10303
+ localInstantSearchInstance.scheduleSearch();
10304
+ }
10282
10305
  }
10283
10306
  }
10284
10307
  return this;
@@ -10316,13 +10339,20 @@
10316
10339
  // This Helper is only used for state management we do not care about the
10317
10340
  // `searchClient`. Only the "main" Helper created at the `InstantSearch`
10318
10341
  // level is aware of the client.
10319
- helper = algoliasearchHelper_1({}, parameters.index, parameters);
10342
+ helper = algoliasearchHelper_1(mainHelper.getClient(), parameters.index, parameters);
10320
10343
  helper.recommendState = recommendParameters;
10321
10344
 
10322
10345
  // We forward the call to `search` to the "main" instance of the Helper
10323
10346
  // which is responsible for managing the queries (it's the only one that is
10324
10347
  // aware of the `searchClient`).
10325
10348
  helper.search = function () {
10349
+ if (isolated) {
10350
+ instantSearchInstance.status = 'loading';
10351
+ _this3.render({
10352
+ instantSearchInstance: instantSearchInstance
10353
+ });
10354
+ return instantSearchInstance.compositionID ? helper.searchWithComposition() : helper.searchOnlyWithDerivedHelpers();
10355
+ }
10326
10356
  if (instantSearchInstance.onStateChange) {
10327
10357
  instantSearchInstance.onStateChange({
10328
10358
  uiState: instantSearchInstance.mainIndex.getWidgetUiState({}),
@@ -10346,7 +10376,9 @@
10346
10376
  var state = helper.state.setQueryParameters(userState);
10347
10377
  return mainHelper.searchForFacetValues(facetName, facetValue, maxFacetHits, state);
10348
10378
  };
10349
- derivedHelper = mainHelper.derive(function () {
10379
+ var isolatedHelper = indexName ? helper : algoliasearchHelper_1({}, '__empty_index__', {});
10380
+ var derivingHelper = isolated ? isolatedHelper : nearestIsolatedHelper(parent, mainHelper);
10381
+ derivedHelper = derivingHelper.derive(function () {
10350
10382
  return mergeSearchParameters.apply(void 0, [mainHelper.state].concat(_toConsumableArray$1(resolveSearchParameters(_this3))));
10351
10383
  }, function () {
10352
10384
  return _this3.getHelper().recommendState;
@@ -10478,7 +10510,9 @@
10478
10510
 
10479
10511
  // We only render index widgets if there are no results.
10480
10512
  // This makes sure `render` is never called with `results` being `null`.
10481
- var widgetsToRender = this.getResults() || (_derivedHelper2 = derivedHelper) !== null && _derivedHelper2 !== void 0 && _derivedHelper2.lastRecommendResults ? localWidgets : localWidgets.filter(isIndexWidget);
10513
+ // If it's an isolated index without an index name, we render all widgets,
10514
+ // as there are no results to display for the isolated index itself.
10515
+ var widgetsToRender = this.getResults() || (_derivedHelper2 = derivedHelper) !== null && _derivedHelper2 !== void 0 && _derivedHelper2.lastRecommendResults || isolated && !indexName ? localWidgets : localWidgets.filter(isIndexWidget);
10482
10516
  widgetsToRender = widgetsToRender.filter(function (widget) {
10483
10517
  if (!widget.shouldRender) {
10484
10518
  return true;
@@ -10512,7 +10546,7 @@
10512
10546
  },
10513
10547
  dispose: function dispose() {
10514
10548
  var _this5 = this,
10515
- _helper2,
10549
+ _helper4,
10516
10550
  _derivedHelper3;
10517
10551
  localWidgets.forEach(function (widget) {
10518
10552
  if (widget.dispose && helper) {
@@ -10532,13 +10566,15 @@
10532
10566
  });
10533
10567
  localInstantSearchInstance = null;
10534
10568
  localParent = null;
10535
- (_helper2 = helper) === null || _helper2 === void 0 ? void 0 : _helper2.removeAllListeners();
10569
+ (_helper4 = helper) === null || _helper4 === void 0 ? void 0 : _helper4.removeAllListeners();
10536
10570
  helper = null;
10537
10571
  (_derivedHelper3 = derivedHelper) === null || _derivedHelper3 === void 0 ? void 0 : _derivedHelper3.detach();
10538
10572
  derivedHelper = null;
10539
10573
  },
10540
10574
  getWidgetUiState: function getWidgetUiState(uiState) {
10541
- return localWidgets.filter(isIndexWidget).reduce(function (previousUiState, innerIndex) {
10575
+ return localWidgets.filter(isIndexWidget).filter(function (w) {
10576
+ return !w._isolated;
10577
+ }).reduce(function (previousUiState, innerIndex) {
10542
10578
  return innerIndex.getWidgetUiState(previousUiState);
10543
10579
  }, _objectSpread$b(_objectSpread$b({}, uiState), {}, _defineProperty$c({}, indexId, _objectSpread$b(_objectSpread$b({}, uiState[indexId]), localUiState))));
10544
10580
  },
@@ -10574,6 +10610,19 @@
10574
10610
  instantSearchInstance.renderState = _objectSpread$b(_objectSpread$b({}, instantSearchInstance.renderState), {}, _defineProperty$c({}, parentIndexName, _objectSpread$b(_objectSpread$b({}, instantSearchInstance.renderState[parentIndexName]), renderState)));
10575
10611
  }
10576
10612
 
10613
+ /**
10614
+ * Walk up the parent chain to find the closest isolated index, or fall back to mainHelper
10615
+ */
10616
+ function nearestIsolatedHelper(current, mainHelper) {
10617
+ while (current) {
10618
+ if (current._isolated) {
10619
+ return current.getHelper();
10620
+ }
10621
+ current = current.getParent();
10622
+ }
10623
+ return mainHelper;
10624
+ }
10625
+
10577
10626
  /**
10578
10627
  * Forces a React update that triggers a rerender.
10579
10628
  * @link https://reactjs.org/docs/hooks-faq.html#is-there-something-like-forceupdate
@@ -12912,7 +12961,7 @@
12912
12961
  };
12913
12962
  }
12914
12963
 
12915
- var version$2 = '4.79.2';
12964
+ var version$2 = '4.80.0';
12916
12965
 
12917
12966
  function _typeof$l(o) {
12918
12967
  "@babel/helpers - typeof";
@@ -13346,12 +13395,9 @@
13346
13395
  if (!Array.isArray(widgets)) {
13347
13396
  throw new Error(withUsage$3('The `addWidgets` method expects an array of widgets. Please use `addWidget`.'));
13348
13397
  }
13349
- if (widgets.some(function (widget) {
13350
- return typeof widget.init !== 'function' && typeof widget.render !== 'function';
13398
+ if (this.compositionID && widgets.some(function (w) {
13399
+ return !Array.isArray(w) && isIndexWidget(w) && !w._isolated;
13351
13400
  })) {
13352
- throw new Error(withUsage$3('The widget definition expects a `render` and/or an `init` method.'));
13353
- }
13354
- if (this.compositionID && widgets.some(isIndexWidget)) {
13355
13401
  throw new Error(withUsage$3('The `index` widget cannot be used with a composition-based InstantSearch implementation.'));
13356
13402
  }
13357
13403
  this.mainIndex.addWidgets(widgets);
@@ -13383,11 +13429,6 @@
13383
13429
  if (!Array.isArray(widgets)) {
13384
13430
  throw new Error(withUsage$3('The `removeWidgets` method expects an array of widgets. Please use `removeWidget`.'));
13385
13431
  }
13386
- if (widgets.some(function (widget) {
13387
- return typeof widget.dispose !== 'function';
13388
- })) {
13389
- throw new Error(withUsage$3('The widget definition expects a `dispose` method.'));
13390
- }
13391
13432
  this.mainIndex.removeWidgets(widgets);
13392
13433
  return this;
13393
13434
  }