react-instantsearch-core 7.7.1 → 7.7.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.7.1';
10
+ var version = '7.7.3';
11
11
 
12
12
  // Copyright Joyent, Inc. and other Node contributors.
13
13
  //
@@ -335,12 +335,15 @@
335
335
  * This event contains a {@link SearchResults} object and the
336
336
  * {@link SearchParameters} corresponding to this answer.
337
337
  * @param {AlgoliaSearchHelper} mainHelper the main helper
338
- * @param {function} fn the function to create the derived state
338
+ * @param {function} fn the function to create the derived state for search
339
+ * @param {function} recommendFn the function to create the derived state for recommendations
339
340
  */
340
- function DerivedHelper(mainHelper, fn) {
341
+ function DerivedHelper(mainHelper, fn, recommendFn) {
341
342
  this.main = mainHelper;
342
343
  this.fn = fn;
344
+ this.recommendFn = recommendFn;
343
345
  this.lastResults = null;
346
+ this.lastRecommendResults = null;
344
347
  }
345
348
 
346
349
  inherits_1(DerivedHelper, events);
@@ -359,6 +362,10 @@
359
362
  return this.fn(parameters);
360
363
  };
361
364
 
365
+ DerivedHelper.prototype.getModifiedRecommendState = function (parameters) {
366
+ return this.recommendFn(parameters);
367
+ };
368
+
362
369
  var DerivedHelper_1 = DerivedHelper;
363
370
 
364
371
  /**
@@ -519,7 +526,18 @@
519
526
  constructor: RecommendParameters,
520
527
 
521
528
  addParams: function (params) {
522
- return new RecommendParameters({ params: this.params.concat(params) });
529
+ var newParams = this.params.slice();
530
+ var existingParamsIndex = this.params.findIndex(function (currentParams) {
531
+ return currentParams.$$id === params.$$id;
532
+ });
533
+
534
+ if (existingParamsIndex !== -1) {
535
+ newParams.splice(existingParamsIndex, 1, params);
536
+ } else {
537
+ newParams.push(params);
538
+ }
539
+
540
+ return new RecommendParameters({ params: newParams });
523
541
  },
524
542
 
525
543
  removeParams: function (id) {
@@ -529,6 +547,45 @@
529
547
  }),
530
548
  });
531
549
  },
550
+
551
+ addFrequentlyBoughtTogether: function (params) {
552
+ return this.addParams(
553
+ Object.assign({}, params, { model: 'bought-together' })
554
+ );
555
+ },
556
+
557
+ addRelatedProducts: function (params) {
558
+ return this.addParams(
559
+ Object.assign({}, params, { model: 'related-products' })
560
+ );
561
+ },
562
+
563
+ addTrendingItems: function (params) {
564
+ return this.addParams(
565
+ Object.assign({}, params, { model: 'trending-items' })
566
+ );
567
+ },
568
+
569
+ addTrendingFacets: function (params) {
570
+ return this.addParams(
571
+ Object.assign({}, params, { model: 'trending-facets' })
572
+ );
573
+ },
574
+
575
+ addLookingSimilar: function (params) {
576
+ return this.addParams(
577
+ Object.assign({}, params, { model: 'looking-similar' })
578
+ );
579
+ },
580
+
581
+ _buildQueries: function (indexName) {
582
+ return this.params.map(function (params) {
583
+ var query = Object.assign({}, params, { indexName: indexName });
584
+ delete query.$$id;
585
+
586
+ return query;
587
+ });
588
+ },
532
589
  };
533
590
 
534
591
  var RecommendParameters_1 = RecommendParameters;
@@ -4380,7 +4437,7 @@
4380
4437
 
4381
4438
  var SearchResults_1 = SearchResults;
4382
4439
 
4383
- var version$1 = '3.17.0';
4440
+ var version$1 = '3.19.0';
4384
4441
 
4385
4442
  var escapeFacetValue$3 = escapeFacetValue_1.escapeFacetValue;
4386
4443
 
@@ -4510,10 +4567,14 @@
4510
4567
  params: opts.recommendState,
4511
4568
  });
4512
4569
  this.lastResults = null;
4570
+ this.lastRecommendResults = null;
4513
4571
  this._queryId = 0;
4572
+ this._recommendQueryId = 0;
4514
4573
  this._lastQueryIdReceived = -1;
4574
+ this._lastRecommendQueryIdReceived = -1;
4515
4575
  this.derivedHelpers = [];
4516
4576
  this._currentNbQueries = 0;
4577
+ this._currentNbRecommendQueries = 0;
4517
4578
  this._searchResultsOptions = searchResultsOptions;
4518
4579
  }
4519
4580
 
@@ -4540,6 +4601,21 @@
4540
4601
  return this;
4541
4602
  };
4542
4603
 
4604
+ /**
4605
+ * Sends the recommendation queries set in the state. When the method is
4606
+ * called, it triggers a `fetch` event. The results will be available through
4607
+ * the `result` event. If an error occurs, an `error` will be fired instead.
4608
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
4609
+ * @fires fetch
4610
+ * @fires result
4611
+ * @fires error
4612
+ * @chainable
4613
+ */
4614
+ AlgoliaSearchHelper.prototype.recommend = function () {
4615
+ this._recommend();
4616
+ return this;
4617
+ };
4618
+
4543
4619
  /**
4544
4620
  * Gets the search query parameters that would be sent to the Algolia Client
4545
4621
  * for the hits
@@ -5036,6 +5112,86 @@
5036
5112
  return this;
5037
5113
  };
5038
5114
 
5115
+ /**
5116
+ * Adds a "frequently bought together" recommendation query.
5117
+ *
5118
+ * @param {FrequentlyBoughtTogetherQuery} params the parameters for the recommendation
5119
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
5120
+ * @fires change
5121
+ * @chainable
5122
+ */
5123
+ AlgoliaSearchHelper.prototype.addFrequentlyBoughtTogether = function (params) {
5124
+ this._recommendChange({
5125
+ state: this.recommendState.addFrequentlyBoughtTogether(params),
5126
+ });
5127
+
5128
+ return this;
5129
+ };
5130
+
5131
+ /**
5132
+ * Adds a "related products" recommendation query.
5133
+ *
5134
+ * @param {RelatedProductsQuery} params the parameters for the recommendation
5135
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
5136
+ * @fires change
5137
+ * @chainable
5138
+ */
5139
+ AlgoliaSearchHelper.prototype.addRelatedProducts = function (params) {
5140
+ this._recommendChange({
5141
+ state: this.recommendState.addRelatedProducts(params),
5142
+ });
5143
+
5144
+ return this;
5145
+ };
5146
+
5147
+ /**
5148
+ * Adds a "trending items" recommendation query.
5149
+ *
5150
+ * @param {TrendingItemsQuery} params the parameters for the recommendation
5151
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
5152
+ * @fires change
5153
+ * @chainable
5154
+ */
5155
+ AlgoliaSearchHelper.prototype.addTrendingItems = function (params) {
5156
+ this._recommendChange({
5157
+ state: this.recommendState.addTrendingItems(params),
5158
+ });
5159
+
5160
+ return this;
5161
+ };
5162
+
5163
+ /**
5164
+ * Adds a "trending facets" recommendation query.
5165
+ *
5166
+ * @param {TrendingFacetsQuery} params the parameters for the recommendation
5167
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
5168
+ * @fires change
5169
+ * @chainable
5170
+ */
5171
+ AlgoliaSearchHelper.prototype.addTrendingFacets = function (params) {
5172
+ this._recommendChange({
5173
+ state: this.recommendState.addTrendingFacets(params),
5174
+ });
5175
+
5176
+ return this;
5177
+ };
5178
+
5179
+ /**
5180
+ * Adds a "looking similar" recommendation query.
5181
+ *
5182
+ * @param {LookingSimilarQuery} params the parameters for the recommendation
5183
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
5184
+ * @fires change
5185
+ * @chainable
5186
+ */
5187
+ AlgoliaSearchHelper.prototype.addLookingSimilar = function (params) {
5188
+ this._recommendChange({
5189
+ state: this.recommendState.addLookingSimilar(params),
5190
+ });
5191
+
5192
+ return this;
5193
+ };
5194
+
5039
5195
  /**
5040
5196
  * Removes an numeric filter to an attribute with the `operator` and `value` provided. If the
5041
5197
  * filter is not set, it doesn't change the filters.
@@ -5205,6 +5361,86 @@
5205
5361
  return this;
5206
5362
  };
5207
5363
 
5364
+ /**
5365
+ * Removes a "frequently bought together" recommendation query.
5366
+ *
5367
+ * @param {string} id identifier of the recommendation widget
5368
+ * @returns {AlgoliaSearchHelper} Method is chainable, it returns itself
5369
+ * @fires change
5370
+ * @chainable
5371
+ */
5372
+ AlgoliaSearchHelper.prototype.removeFrequentlyBoughtTogether = function (id) {
5373
+ this._recommendChange({
5374
+ state: this.recommendState.removeParams(id),
5375
+ });
5376
+
5377
+ return this;
5378
+ };
5379
+
5380
+ /**
5381
+ * Removes a "related products" recommendation query.
5382
+ *
5383
+ * @param {string} id identifier of the recommendation widget
5384
+ * @returns {AlgoliaSearchHelper} Method is chainable, it returns itself
5385
+ * @fires change
5386
+ * @chainable
5387
+ */
5388
+ AlgoliaSearchHelper.prototype.removeRelatedProducts = function (id) {
5389
+ this._recommendChange({
5390
+ state: this.recommendState.removeParams(id),
5391
+ });
5392
+
5393
+ return this;
5394
+ };
5395
+
5396
+ /**
5397
+ * Removes a "trending items" recommendation query.
5398
+ *
5399
+ * @param {string} id identifier of the recommendation widget
5400
+ * @returns {AlgoliaSearchHelper} Method is chainable, it returns itself
5401
+ * @fires change
5402
+ * @chainable
5403
+ */
5404
+ AlgoliaSearchHelper.prototype.removeTrendingItems = function (id) {
5405
+ this._recommendChange({
5406
+ state: this.recommendState.removeParams(id),
5407
+ });
5408
+
5409
+ return this;
5410
+ };
5411
+
5412
+ /**
5413
+ * Removes a "trending facets" recommendation query.
5414
+ *
5415
+ * @param {string} id identifier of the recommendation widget
5416
+ * @returns {AlgoliaSearchHelper} Method is chainable, it returns itself
5417
+ * @fires change
5418
+ * @chainable
5419
+ */
5420
+ AlgoliaSearchHelper.prototype.removeTrendingFacets = function (id) {
5421
+ this._recommendChange({
5422
+ state: this.recommendState.removeParams(id),
5423
+ });
5424
+
5425
+ return this;
5426
+ };
5427
+
5428
+ /**
5429
+ * Removes a "looking similar" recommendation query.
5430
+ *
5431
+ * @param {string} id identifier of the recommendation widget
5432
+ * @returns {AlgoliaSearchHelper} Method is chainable, it returns itself
5433
+ * @fires change
5434
+ * @chainable
5435
+ */
5436
+ AlgoliaSearchHelper.prototype.removeLookingSimilar = function (id) {
5437
+ this._recommendChange({
5438
+ state: this.recommendState.removeParams(id),
5439
+ });
5440
+
5441
+ return this;
5442
+ };
5443
+
5208
5444
  /**
5209
5445
  * Adds or removes an exclusion filter to a faceted attribute with the `value` provided. If
5210
5446
  * the value is set then it removes it, otherwise it adds the filter.
@@ -5772,6 +6008,85 @@
5772
6008
  return undefined;
5773
6009
  };
5774
6010
 
6011
+ AlgoliaSearchHelper.prototype._recommend = function () {
6012
+ var searchState = this.state;
6013
+ var recommendState = this.recommendState;
6014
+ var index = this.getIndex();
6015
+ var states = [{ state: recommendState, index: index, helper: this }];
6016
+
6017
+ this.emit('fetch', {
6018
+ recommend: {
6019
+ state: recommendState,
6020
+ results: this.lastRecommendResults,
6021
+ },
6022
+ });
6023
+
6024
+ var derivedQueries = this.derivedHelpers.map(function (derivedHelper) {
6025
+ var derivedIndex = derivedHelper.getModifiedState(searchState).index;
6026
+ if (!derivedIndex) {
6027
+ return [];
6028
+ }
6029
+
6030
+ // Contrary to what is done when deriving the search state, we don't want to
6031
+ // provide the current recommend state to the derived helper, as it would
6032
+ // inherit unwanted queries. We instead provide an empty recommend state.
6033
+ var derivedState = derivedHelper.getModifiedRecommendState(
6034
+ new RecommendParameters_1()
6035
+ );
6036
+ states.push({
6037
+ state: derivedState,
6038
+ index: derivedIndex,
6039
+ helper: derivedHelper,
6040
+ });
6041
+
6042
+ derivedHelper.emit('fetch', {
6043
+ recommend: {
6044
+ state: derivedState,
6045
+ results: derivedHelper.lastRecommendResults,
6046
+ },
6047
+ });
6048
+
6049
+ return derivedState._buildQueries(derivedIndex);
6050
+ });
6051
+
6052
+ var queries = Array.prototype.concat.apply(
6053
+ this.recommendState._buildQueries(index),
6054
+ derivedQueries
6055
+ );
6056
+
6057
+ if (queries.length === 0) {
6058
+ return;
6059
+ }
6060
+
6061
+ if (
6062
+ queries.length > 0 &&
6063
+ typeof this.client.getRecommendations === 'undefined'
6064
+ ) {
6065
+ // eslint-disable-next-line no-console
6066
+ console.warn(
6067
+ 'Please update algoliasearch/lite to the latest version in order to use recommendations widgets.'
6068
+ );
6069
+ return;
6070
+ }
6071
+
6072
+ var queryId = this._recommendQueryId++;
6073
+ this._currentNbRecommendQueries++;
6074
+
6075
+ try {
6076
+ this.client
6077
+ .getRecommendations(queries)
6078
+ .then(this._dispatchRecommendResponse.bind(this, queryId, states))
6079
+ .catch(this._dispatchRecommendError.bind(this, queryId));
6080
+ } catch (error) {
6081
+ // If we reach this part, we're in an internal error state
6082
+ this.emit('error', {
6083
+ error: error,
6084
+ });
6085
+ }
6086
+
6087
+ return;
6088
+ };
6089
+
5775
6090
  /**
5776
6091
  * Transform the responses as sent by the server and transform them into a user
5777
6092
  * usable object that merge the results of all the batch requests. It will dispatch
@@ -5831,6 +6146,53 @@
5831
6146
  });
5832
6147
  };
5833
6148
 
6149
+ AlgoliaSearchHelper.prototype._dispatchRecommendResponse = function (
6150
+ queryId,
6151
+ states,
6152
+ content
6153
+ ) {
6154
+ // @TODO remove the number of outdated queries discarded instead of just one
6155
+
6156
+ if (queryId < this._lastRecommendQueryIdReceived) {
6157
+ // Outdated answer
6158
+ return;
6159
+ }
6160
+
6161
+ this._currentNbRecommendQueries -=
6162
+ queryId - this._lastRecommendQueryIdReceived;
6163
+ this._lastRecommendQueryIdReceived = queryId;
6164
+
6165
+ if (this._currentNbRecommendQueries === 0) this.emit('recommendQueueEmpty');
6166
+
6167
+ var results = content.results.slice();
6168
+
6169
+ states.forEach(function (s) {
6170
+ var state = s.state;
6171
+ var helper = s.helper;
6172
+
6173
+ if (!s.index) {
6174
+ // eslint-disable-next-line no-warning-comments
6175
+ // TODO: emit "result" event when events for Recommend are implemented
6176
+ helper.emit('recommend:result', {
6177
+ results: null,
6178
+ state: state,
6179
+ });
6180
+ return;
6181
+ }
6182
+
6183
+ helper.lastRecommendResults = results;
6184
+
6185
+ // eslint-disable-next-line no-warning-comments
6186
+ // TODO: emit "result" event when events for Recommend are implemented
6187
+ helper.emit('recommend:result', {
6188
+ recommend: {
6189
+ results: helper.lastRecommendResults,
6190
+ state: state,
6191
+ },
6192
+ });
6193
+ });
6194
+ };
6195
+
5834
6196
  AlgoliaSearchHelper.prototype._dispatchAlgoliaError = function (
5835
6197
  queryId,
5836
6198
  error
@@ -5850,6 +6212,26 @@
5850
6212
  if (this._currentNbQueries === 0) this.emit('searchQueueEmpty');
5851
6213
  };
5852
6214
 
6215
+ AlgoliaSearchHelper.prototype._dispatchRecommendError = function (
6216
+ queryId,
6217
+ error
6218
+ ) {
6219
+ if (queryId < this._lastRecommendQueryIdReceived) {
6220
+ // Outdated answer
6221
+ return;
6222
+ }
6223
+
6224
+ this._currentNbRecommendQueries -=
6225
+ queryId - this._lastRecommendQueryIdReceived;
6226
+ this._lastRecommendQueryIdReceived = queryId;
6227
+
6228
+ this.emit('error', {
6229
+ error: error,
6230
+ });
6231
+
6232
+ if (this._currentNbRecommendQueries === 0) this.emit('recommendQueueEmpty');
6233
+ };
6234
+
5853
6235
  AlgoliaSearchHelper.prototype.containsRefinement = function (
5854
6236
  query,
5855
6237
  facetFilters,
@@ -5900,6 +6282,16 @@
5900
6282
 
5901
6283
  // eslint-disable-next-line no-warning-comments
5902
6284
  // TODO: emit "change" event when events for Recommend are implemented
6285
+ this.emit('recommend:change', {
6286
+ search: {
6287
+ results: this.lastResults,
6288
+ state: this.state,
6289
+ },
6290
+ recommend: {
6291
+ results: this.lastRecommendResults,
6292
+ state: this.recommendState,
6293
+ },
6294
+ });
5903
6295
  }
5904
6296
  };
5905
6297
 
@@ -5954,10 +6346,11 @@
5954
6346
  * and the SearchParameters that is returned by the call of the
5955
6347
  * parameter function.
5956
6348
  * @param {function} fn SearchParameters -> SearchParameters
6349
+ * @param {function} recommendFn RecommendParameters -> RecommendParameters
5957
6350
  * @return {DerivedHelper} a new DerivedHelper
5958
6351
  */
5959
- AlgoliaSearchHelper.prototype.derive = function (fn) {
5960
- var derivedHelper = new DerivedHelper_1(this, fn);
6352
+ AlgoliaSearchHelper.prototype.derive = function (fn, recommendFn) {
6353
+ var derivedHelper = new DerivedHelper_1(this, fn, recommendFn);
5961
6354
  this.derivedHelpers.push(derivedHelper);
5962
6355
  return derivedHelper;
5963
6356
  };
@@ -6059,6 +6452,13 @@
6059
6452
  */
6060
6453
  algoliasearchHelper.SearchParameters = SearchParameters_1;
6061
6454
 
6455
+ /**
6456
+ * Constructor for the object containing all the parameters for Recommend.
6457
+ * @member module:algoliasearchHelper.RecommendParameters
6458
+ * @type {RecommendParameters}
6459
+ */
6460
+ algoliasearchHelper.RecommendParameters = RecommendParameters_1;
6461
+
6062
6462
  /**
6063
6463
  * Constructor for the object containing the results of the search.
6064
6464
  * @member module:algoliasearchHelper.SearchResults
@@ -8926,7 +9326,8 @@
8926
9326
  return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
8927
9327
  }, _typeof$c(obj);
8928
9328
  }
8929
- var _excluded$3 = ["initialSearchParameters"];
9329
+ var _excluded$3 = ["initialSearchParameters"],
9330
+ _excluded2$1 = ["initialRecommendParameters"];
8930
9331
  function ownKeys$b(object, enumerableOnly) {
8931
9332
  var keys = Object.keys(object);
8932
9333
  if (Object.getOwnPropertySymbols) {
@@ -9038,6 +9439,7 @@
9038
9439
  */
9039
9440
  function privateHelperSetState(helper, _ref) {
9040
9441
  var state = _ref.state,
9442
+ recommendState = _ref.recommendState,
9041
9443
  isPageReset = _ref.isPageReset,
9042
9444
  _uiState = _ref._uiState;
9043
9445
  if (state !== helper.state) {
@@ -9049,7 +9451,14 @@
9049
9451
  _uiState: _uiState
9050
9452
  });
9051
9453
  }
9454
+ if (recommendState !== helper.recommendState) {
9455
+ helper.recommendState = recommendState;
9456
+
9457
+ // eslint-disable-next-line no-warning-comments
9458
+ // TODO: emit "change" event when events for Recommend are implemented
9459
+ }
9052
9460
  }
9461
+
9053
9462
  function getLocalWidgetsUiState(widgets, widgetStateOptions) {
9054
9463
  var initialUiState = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
9055
9464
  return widgets.reduce(function (uiState, widget) {
@@ -9068,15 +9477,26 @@
9068
9477
  function getLocalWidgetsSearchParameters(widgets, widgetSearchParametersOptions) {
9069
9478
  var initialSearchParameters = widgetSearchParametersOptions.initialSearchParameters,
9070
9479
  rest = _objectWithoutProperties$2(widgetSearchParametersOptions, _excluded$3);
9071
- return widgets.filter(function (widget) {
9072
- return !isIndexWidget(widget);
9073
- }).reduce(function (state, widget) {
9074
- if (!widget.getWidgetSearchParameters) {
9480
+ return widgets.reduce(function (state, widget) {
9481
+ if (!widget.getWidgetSearchParameters || isIndexWidget(widget)) {
9075
9482
  return state;
9076
9483
  }
9484
+ if (widget.dependsOn === 'search' && widget.getWidgetParameters) {
9485
+ return widget.getWidgetParameters(state, rest);
9486
+ }
9077
9487
  return widget.getWidgetSearchParameters(state, rest);
9078
9488
  }, initialSearchParameters);
9079
9489
  }
9490
+ function getLocalWidgetsRecommendParameters(widgets, widgetRecommendParametersOptions) {
9491
+ var initialRecommendParameters = widgetRecommendParametersOptions.initialRecommendParameters,
9492
+ rest = _objectWithoutProperties$2(widgetRecommendParametersOptions, _excluded2$1);
9493
+ return widgets.reduce(function (state, widget) {
9494
+ if (!isIndexWidget(widget) && widget.dependsOn === 'recommend' && widget.getWidgetParameters) {
9495
+ return widget.getWidgetParameters(state, rest);
9496
+ }
9497
+ return state;
9498
+ }, initialRecommendParameters);
9499
+ }
9080
9500
  function resetPageFromWidgets(widgets) {
9081
9501
  var indexWidgets = widgets.filter(isIndexWidget);
9082
9502
  if (indexWidgets.length === 0) {
@@ -9086,6 +9506,7 @@
9086
9506
  var widgetHelper = widget.getHelper();
9087
9507
  privateHelperSetState(widgetHelper, {
9088
9508
  state: widgetHelper.state.resetPage(),
9509
+ recommendState: widgetHelper.recommendState,
9089
9510
  isPageReset: true
9090
9511
  });
9091
9512
  resetPageFromWidgets(widget.getWidgets());
@@ -9144,9 +9565,18 @@
9144
9565
  },
9145
9566
  getScopedResults: function getScopedResults() {
9146
9567
  var widgetParent = this.getParent();
9147
-
9148
- // If the widget is the root, we consider itself as the only sibling.
9149
- var widgetSiblings = widgetParent ? widgetParent.getWidgets() : [this];
9568
+ var widgetSiblings;
9569
+ if (widgetParent) {
9570
+ widgetSiblings = widgetParent.getWidgets();
9571
+ } else if (indexName.length === 0) {
9572
+ // The widget is the root but has no index name:
9573
+ // we resolve results from its children index widgets
9574
+ widgetSiblings = this.getWidgets();
9575
+ } else {
9576
+ // The widget is the root and has an index name:
9577
+ // we consider itself as the only sibling
9578
+ widgetSiblings = [this];
9579
+ }
9150
9580
  return resolveScopedResultsFromWidgets(widgetSiblings);
9151
9581
  },
9152
9582
  getParent: function getParent() {
@@ -9181,6 +9611,10 @@
9181
9611
  uiState: localUiState,
9182
9612
  initialSearchParameters: helper.state
9183
9613
  }),
9614
+ recommendState: getLocalWidgetsRecommendParameters(localWidgets, {
9615
+ uiState: localUiState,
9616
+ initialRecommendParameters: helper.recommendState
9617
+ }),
9184
9618
  _uiState: localUiState
9185
9619
  });
9186
9620
 
@@ -9277,11 +9711,16 @@
9277
9711
  index: indexName
9278
9712
  })
9279
9713
  });
9714
+ var recommendParameters = getLocalWidgetsRecommendParameters(localWidgets, {
9715
+ uiState: localUiState,
9716
+ initialRecommendParameters: new algoliasearchHelper_1.RecommendParameters()
9717
+ });
9280
9718
 
9281
9719
  // This Helper is only used for state management we do not care about the
9282
9720
  // `searchClient`. Only the "main" Helper created at the `InstantSearch`
9283
9721
  // level is aware of the client.
9284
9722
  helper = algoliasearchHelper_1({}, parameters.index, parameters);
9723
+ helper.recommendState = recommendParameters;
9285
9724
 
9286
9725
  // We forward the call to `search` to the "main" instance of the Helper
9287
9726
  // which is responsible for managing the queries (it's the only one that is
@@ -9312,6 +9751,8 @@
9312
9751
  };
9313
9752
  derivedHelper = mainHelper.derive(function () {
9314
9753
  return mergeSearchParameters.apply(void 0, [mainHelper.state].concat(_toConsumableArray$1(resolveSearchParameters(_this3))));
9754
+ }, function () {
9755
+ return _this3.getHelper().recommendState;
9315
9756
  });
9316
9757
  var indexInitialResults = (_instantSearchInstanc = instantSearchInstance._initialResults) === null || _instantSearchInstanc === void 0 ? void 0 : _instantSearchInstanc[this.getIndexId()];
9317
9758
  if (indexInitialResults) {
@@ -9354,6 +9795,21 @@
9354
9795
  lastValidSearchParameters = results === null || results === void 0 ? void 0 : results._state;
9355
9796
  });
9356
9797
 
9798
+ // eslint-disable-next-line no-warning-comments
9799
+ // TODO: listen to "result" event when events for Recommend are implemented
9800
+ derivedHelper.on('recommend:result', function (_ref5) {
9801
+ var recommend = _ref5.recommend;
9802
+ // The index does not render the results it schedules a new render
9803
+ // to let all the other indices emit their own results. It allows us to
9804
+ // run the render process in one pass.
9805
+ instantSearchInstance.scheduleRender();
9806
+
9807
+ // the derived helper is the one which actually searches, but the helper
9808
+ // which is exposed e.g. via instance.helper, doesn't search, and thus
9809
+ // does not have access to lastRecommendResults.
9810
+ helper.lastRecommendResults = recommend.results;
9811
+ });
9812
+
9357
9813
  // We compute the render state before calling `init` in a separate loop
9358
9814
  // to construct the whole render state object that is then passed to
9359
9815
  // `init`.
@@ -9400,9 +9856,9 @@
9400
9856
  instantSearchInstance.scheduleRender();
9401
9857
  }
9402
9858
  },
9403
- render: function render(_ref5) {
9859
+ render: function render(_ref6) {
9404
9860
  var _this4 = this;
9405
- var instantSearchInstance = _ref5.instantSearchInstance;
9861
+ var instantSearchInstance = _ref6.instantSearchInstance;
9406
9862
  // we can't attach a listener to the error event of search, as the error
9407
9863
  // then would no longer be thrown for global handlers.
9408
9864
  if (instantSearchInstance.status === 'error' && !instantSearchInstance.mainHelper.hasPendingRequests() && lastValidSearchParameters) {
@@ -9412,6 +9868,14 @@
9412
9868
  // We only render index widgets if there are no results.
9413
9869
  // This makes sure `render` is never called with `results` being `null`.
9414
9870
  var widgetsToRender = this.getResults() ? localWidgets : localWidgets.filter(isIndexWidget);
9871
+ widgetsToRender = widgetsToRender.filter(function (widget) {
9872
+ if (!widget.shouldRender) {
9873
+ return true;
9874
+ }
9875
+ return widget.shouldRender({
9876
+ instantSearchInstance: instantSearchInstance
9877
+ });
9878
+ });
9415
9879
  widgetsToRender.forEach(function (widget) {
9416
9880
  if (widget.getRenderState) {
9417
9881
  var renderState = widget.getRenderState(instantSearchInstance.renderState[_this4.getIndexId()] || {}, createRenderArgs(instantSearchInstance, _this4));
@@ -9469,8 +9933,8 @@
9469
9933
  getWidgetState: function getWidgetState(uiState) {
9470
9934
  return this.getWidgetUiState(uiState);
9471
9935
  },
9472
- getWidgetSearchParameters: function getWidgetSearchParameters(searchParameters, _ref6) {
9473
- var uiState = _ref6.uiState;
9936
+ getWidgetSearchParameters: function getWidgetSearchParameters(searchParameters, _ref7) {
9937
+ var uiState = _ref7.uiState;
9474
9938
  return getLocalWidgetsSearchParameters(localWidgets, {
9475
9939
  uiState: uiState,
9476
9940
  initialSearchParameters: searchParameters
@@ -9490,10 +9954,10 @@
9490
9954
  }
9491
9955
  };
9492
9956
  };
9493
- function storeRenderState(_ref7) {
9494
- var renderState = _ref7.renderState,
9495
- instantSearchInstance = _ref7.instantSearchInstance,
9496
- parent = _ref7.parent;
9957
+ function storeRenderState(_ref8) {
9958
+ var renderState = _ref8.renderState,
9959
+ instantSearchInstance = _ref8.instantSearchInstance,
9960
+ parent = _ref8.parent;
9497
9961
  var parentIndexName = parent ? parent.getIndexId() : instantSearchInstance.mainIndex.getIndexId();
9498
9962
  instantSearchInstance.renderState = _objectSpread$a(_objectSpread$a({}, instantSearchInstance.renderState), {}, _defineProperty$b({}, parentIndexName, _objectSpread$a(_objectSpread$a({}, instantSearchInstance.renderState[parentIndexName]), renderState)));
9499
9963
  }
@@ -11758,7 +12222,7 @@
11758
12222
  };
11759
12223
  }
11760
12224
 
11761
- var version$2 = '4.66.1';
12225
+ var version$2 = '4.68.0';
11762
12226
 
11763
12227
  function _typeof$k(obj) {
11764
12228
  "@babel/helpers - typeof";
@@ -12252,7 +12716,7 @@
12252
12716
  // under the hood, we have a different implementation. It should be
12253
12717
  // completely transparent for the rest of the codebase. Only this module
12254
12718
  // is impacted.
12255
- return mainHelper.searchOnlyWithDerivedHelpers();
12719
+ return mainHelper.searchOnlyWithDerivedHelpers() && mainHelper.recommend();
12256
12720
  };
12257
12721
  if (this._searchFunction) {
12258
12722
  // this client isn't used to actually search, but required for the helper
@@ -14212,6 +14676,7 @@
14212
14676
  });
14213
14677
  },
14214
14678
  getWidgetRenderState: function getWidgetRenderState(_ref2) {
14679
+ var _results$renderingCon, _results$renderingCon2, _results$renderingCon3;
14215
14680
  var results = _ref2.results,
14216
14681
  helper = _ref2.helper,
14217
14682
  instantSearchInstance = _ref2.instantSearchInstance;
@@ -14237,6 +14702,7 @@
14237
14702
  return {
14238
14703
  hits: [],
14239
14704
  results: undefined,
14705
+ banner: undefined,
14240
14706
  sendEvent: sendEvent,
14241
14707
  bindEvent: bindEvent,
14242
14708
  widgetParams: widgetParams
@@ -14250,9 +14716,11 @@
14250
14716
  var transformedHits = transformItems(hitsWithAbsolutePositionAndQueryID, {
14251
14717
  results: results
14252
14718
  });
14719
+ var banner = (_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];
14253
14720
  return {
14254
14721
  hits: transformedHits,
14255
14722
  results: results,
14723
+ banner: banner,
14256
14724
  sendEvent: sendEvent,
14257
14725
  bindEvent: bindEvent,
14258
14726
  widgetParams: widgetParams
@@ -14516,7 +14984,7 @@
14516
14984
  }, _typeof$s(obj);
14517
14985
  }
14518
14986
  var _excluded$9 = ["page"],
14519
- _excluded2$1 = ["clickAnalytics", "userToken"];
14987
+ _excluded2$2 = ["clickAnalytics", "userToken"];
14520
14988
  function ownKeys$o(object, enumerableOnly) {
14521
14989
  var keys = Object.keys(object);
14522
14990
  if (Object.getOwnPropertySymbols) {
@@ -14632,7 +15100,7 @@
14632
15100
  var _ref2 = state || {},
14633
15101
  clickAnalytics = _ref2.clickAnalytics,
14634
15102
  userToken = _ref2.userToken,
14635
- rest = _objectWithoutProperties$5(_ref2, _excluded2$1);
15103
+ rest = _objectWithoutProperties$5(_ref2, _excluded2$2);
14636
15104
  return rest;
14637
15105
  }
14638
15106
  function getInMemoryCache() {
@@ -16571,7 +17039,7 @@
16571
17039
  }, _typeof$z(obj);
16572
17040
  }
16573
17041
  var _excluded$b = ["name", "escapedValue"],
16574
- _excluded2$2 = ["escapedValue", "value"];
17042
+ _excluded2$3 = ["escapedValue", "value"];
16575
17043
  function ownKeys$u(object, enumerableOnly) {
16576
17044
  var keys = Object.keys(object);
16577
17045
  if (Object.getOwnPropertySymbols) {
@@ -16756,7 +17224,7 @@
16756
17224
  var normalizedFacetValues = transformItems(facetValues.map(function (_ref3) {
16757
17225
  var escapedValue = _ref3.escapedValue,
16758
17226
  value = _ref3.value,
16759
- item = _objectWithoutProperties$7(_ref3, _excluded2$2);
17227
+ item = _objectWithoutProperties$7(_ref3, _excluded2$3);
16760
17228
  return _objectSpread$t(_objectSpread$t({}, item), {}, {
16761
17229
  value: escapedValue,
16762
17230
  label: value
@@ -17800,6 +18268,14 @@
17800
18268
  results: results,
17801
18269
  scopedResults: searchIndex.getScopedResults()
17802
18270
  });
18271
+ } else if (search.mainIndex.getIndexName().length === 0) {
18272
+ // If the main index has no name, we get the scoped results from
18273
+ // the first child index instead.
18274
+ var childIndex = search.mainIndex.getWidgets().find(isIndexWidget);
18275
+ childIndex && setSearchResults({
18276
+ results: getIndexSearchResults(searchIndex).results,
18277
+ scopedResults: childIndex.getScopedResults()
18278
+ });
17803
18279
  }
17804
18280
  }
17805
18281
  search.addListener('render', handleRender);