react-instantsearch 7.7.1 → 7.7.2

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.2';
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.18.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
@@ -9347,7 +9747,8 @@
9347
9747
  return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
9348
9748
  }, _typeof$g(obj);
9349
9749
  }
9350
- var _excluded$3 = ["initialSearchParameters"];
9750
+ var _excluded$3 = ["initialSearchParameters"],
9751
+ _excluded2$1 = ["initialRecommendParameters"];
9351
9752
  function ownKeys$d(object, enumerableOnly) {
9352
9753
  var keys = Object.keys(object);
9353
9754
  if (Object.getOwnPropertySymbols) {
@@ -9459,6 +9860,7 @@
9459
9860
  */
9460
9861
  function privateHelperSetState(helper, _ref) {
9461
9862
  var state = _ref.state,
9863
+ recommendState = _ref.recommendState,
9462
9864
  isPageReset = _ref.isPageReset,
9463
9865
  _uiState = _ref._uiState;
9464
9866
  if (state !== helper.state) {
@@ -9470,7 +9872,14 @@
9470
9872
  _uiState: _uiState
9471
9873
  });
9472
9874
  }
9875
+ if (recommendState !== helper.recommendState) {
9876
+ helper.recommendState = recommendState;
9877
+
9878
+ // eslint-disable-next-line no-warning-comments
9879
+ // TODO: emit "change" event when events for Recommend are implemented
9880
+ }
9473
9881
  }
9882
+
9474
9883
  function getLocalWidgetsUiState(widgets, widgetStateOptions) {
9475
9884
  var initialUiState = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
9476
9885
  return widgets.reduce(function (uiState, widget) {
@@ -9489,15 +9898,26 @@
9489
9898
  function getLocalWidgetsSearchParameters(widgets, widgetSearchParametersOptions) {
9490
9899
  var initialSearchParameters = widgetSearchParametersOptions.initialSearchParameters,
9491
9900
  rest = _objectWithoutProperties$3(widgetSearchParametersOptions, _excluded$3);
9492
- return widgets.filter(function (widget) {
9493
- return !isIndexWidget(widget);
9494
- }).reduce(function (state, widget) {
9495
- if (!widget.getWidgetSearchParameters) {
9901
+ return widgets.reduce(function (state, widget) {
9902
+ if (!widget.getWidgetSearchParameters || isIndexWidget(widget)) {
9496
9903
  return state;
9497
9904
  }
9905
+ if (widget.dependsOn === 'search' && widget.getWidgetParameters) {
9906
+ return widget.getWidgetParameters(state, rest);
9907
+ }
9498
9908
  return widget.getWidgetSearchParameters(state, rest);
9499
9909
  }, initialSearchParameters);
9500
9910
  }
9911
+ function getLocalWidgetsRecommendParameters(widgets, widgetRecommendParametersOptions) {
9912
+ var initialRecommendParameters = widgetRecommendParametersOptions.initialRecommendParameters,
9913
+ rest = _objectWithoutProperties$3(widgetRecommendParametersOptions, _excluded2$1);
9914
+ return widgets.reduce(function (state, widget) {
9915
+ if (!isIndexWidget(widget) && widget.dependsOn === 'recommend' && widget.getWidgetParameters) {
9916
+ return widget.getWidgetParameters(state, rest);
9917
+ }
9918
+ return state;
9919
+ }, initialRecommendParameters);
9920
+ }
9501
9921
  function resetPageFromWidgets(widgets) {
9502
9922
  var indexWidgets = widgets.filter(isIndexWidget);
9503
9923
  if (indexWidgets.length === 0) {
@@ -9507,6 +9927,7 @@
9507
9927
  var widgetHelper = widget.getHelper();
9508
9928
  privateHelperSetState(widgetHelper, {
9509
9929
  state: widgetHelper.state.resetPage(),
9930
+ recommendState: widgetHelper.recommendState,
9510
9931
  isPageReset: true
9511
9932
  });
9512
9933
  resetPageFromWidgets(widget.getWidgets());
@@ -9602,6 +10023,10 @@
9602
10023
  uiState: localUiState,
9603
10024
  initialSearchParameters: helper.state
9604
10025
  }),
10026
+ recommendState: getLocalWidgetsRecommendParameters(localWidgets, {
10027
+ uiState: localUiState,
10028
+ initialRecommendParameters: helper.recommendState
10029
+ }),
9605
10030
  _uiState: localUiState
9606
10031
  });
9607
10032
 
@@ -9698,11 +10123,16 @@
9698
10123
  index: indexName
9699
10124
  })
9700
10125
  });
10126
+ var recommendParameters = getLocalWidgetsRecommendParameters(localWidgets, {
10127
+ uiState: localUiState,
10128
+ initialRecommendParameters: new algoliasearchHelper_1.RecommendParameters()
10129
+ });
9701
10130
 
9702
10131
  // This Helper is only used for state management we do not care about the
9703
10132
  // `searchClient`. Only the "main" Helper created at the `InstantSearch`
9704
10133
  // level is aware of the client.
9705
10134
  helper = algoliasearchHelper_1({}, parameters.index, parameters);
10135
+ helper.recommendState = recommendParameters;
9706
10136
 
9707
10137
  // We forward the call to `search` to the "main" instance of the Helper
9708
10138
  // which is responsible for managing the queries (it's the only one that is
@@ -9733,6 +10163,8 @@
9733
10163
  };
9734
10164
  derivedHelper = mainHelper.derive(function () {
9735
10165
  return mergeSearchParameters.apply(void 0, [mainHelper.state].concat(_toConsumableArray$1(resolveSearchParameters(_this3))));
10166
+ }, function () {
10167
+ return _this3.getHelper().recommendState;
9736
10168
  });
9737
10169
  var indexInitialResults = (_instantSearchInstanc = instantSearchInstance._initialResults) === null || _instantSearchInstanc === void 0 ? void 0 : _instantSearchInstanc[this.getIndexId()];
9738
10170
  if (indexInitialResults) {
@@ -9775,6 +10207,21 @@
9775
10207
  lastValidSearchParameters = results === null || results === void 0 ? void 0 : results._state;
9776
10208
  });
9777
10209
 
10210
+ // eslint-disable-next-line no-warning-comments
10211
+ // TODO: listen to "result" event when events for Recommend are implemented
10212
+ derivedHelper.on('recommend:result', function (_ref5) {
10213
+ var recommend = _ref5.recommend;
10214
+ // The index does not render the results it schedules a new render
10215
+ // to let all the other indices emit their own results. It allows us to
10216
+ // run the render process in one pass.
10217
+ instantSearchInstance.scheduleRender();
10218
+
10219
+ // the derived helper is the one which actually searches, but the helper
10220
+ // which is exposed e.g. via instance.helper, doesn't search, and thus
10221
+ // does not have access to lastRecommendResults.
10222
+ helper.lastRecommendResults = recommend.results;
10223
+ });
10224
+
9778
10225
  // We compute the render state before calling `init` in a separate loop
9779
10226
  // to construct the whole render state object that is then passed to
9780
10227
  // `init`.
@@ -9821,9 +10268,9 @@
9821
10268
  instantSearchInstance.scheduleRender();
9822
10269
  }
9823
10270
  },
9824
- render: function render(_ref5) {
10271
+ render: function render(_ref6) {
9825
10272
  var _this4 = this;
9826
- var instantSearchInstance = _ref5.instantSearchInstance;
10273
+ var instantSearchInstance = _ref6.instantSearchInstance;
9827
10274
  // we can't attach a listener to the error event of search, as the error
9828
10275
  // then would no longer be thrown for global handlers.
9829
10276
  if (instantSearchInstance.status === 'error' && !instantSearchInstance.mainHelper.hasPendingRequests() && lastValidSearchParameters) {
@@ -9833,6 +10280,14 @@
9833
10280
  // We only render index widgets if there are no results.
9834
10281
  // This makes sure `render` is never called with `results` being `null`.
9835
10282
  var widgetsToRender = this.getResults() ? localWidgets : localWidgets.filter(isIndexWidget);
10283
+ widgetsToRender = widgetsToRender.filter(function (widget) {
10284
+ if (!widget.shouldRender) {
10285
+ return true;
10286
+ }
10287
+ return widget.shouldRender({
10288
+ instantSearchInstance: instantSearchInstance
10289
+ });
10290
+ });
9836
10291
  widgetsToRender.forEach(function (widget) {
9837
10292
  if (widget.getRenderState) {
9838
10293
  var renderState = widget.getRenderState(instantSearchInstance.renderState[_this4.getIndexId()] || {}, createRenderArgs(instantSearchInstance, _this4));
@@ -9890,8 +10345,8 @@
9890
10345
  getWidgetState: function getWidgetState(uiState) {
9891
10346
  return this.getWidgetUiState(uiState);
9892
10347
  },
9893
- getWidgetSearchParameters: function getWidgetSearchParameters(searchParameters, _ref6) {
9894
- var uiState = _ref6.uiState;
10348
+ getWidgetSearchParameters: function getWidgetSearchParameters(searchParameters, _ref7) {
10349
+ var uiState = _ref7.uiState;
9895
10350
  return getLocalWidgetsSearchParameters(localWidgets, {
9896
10351
  uiState: uiState,
9897
10352
  initialSearchParameters: searchParameters
@@ -9911,10 +10366,10 @@
9911
10366
  }
9912
10367
  };
9913
10368
  };
9914
- function storeRenderState(_ref7) {
9915
- var renderState = _ref7.renderState,
9916
- instantSearchInstance = _ref7.instantSearchInstance,
9917
- parent = _ref7.parent;
10369
+ function storeRenderState(_ref8) {
10370
+ var renderState = _ref8.renderState,
10371
+ instantSearchInstance = _ref8.instantSearchInstance,
10372
+ parent = _ref8.parent;
9918
10373
  var parentIndexName = parent ? parent.getIndexId() : instantSearchInstance.mainIndex.getIndexId();
9919
10374
  instantSearchInstance.renderState = _objectSpread$d(_objectSpread$d({}, instantSearchInstance.renderState), {}, _defineProperty$d({}, parentIndexName, _objectSpread$d(_objectSpread$d({}, instantSearchInstance.renderState[parentIndexName]), renderState)));
9920
10375
  }
@@ -12256,7 +12711,7 @@
12256
12711
  };
12257
12712
  }
12258
12713
 
12259
- var version$3 = '4.66.1';
12714
+ var version$3 = '4.67.0';
12260
12715
 
12261
12716
  function _typeof$o(obj) {
12262
12717
  "@babel/helpers - typeof";
@@ -12750,7 +13205,7 @@
12750
13205
  // under the hood, we have a different implementation. It should be
12751
13206
  // completely transparent for the rest of the codebase. Only this module
12752
13207
  // is impacted.
12753
- return mainHelper.searchOnlyWithDerivedHelpers();
13208
+ return mainHelper.searchOnlyWithDerivedHelpers() && mainHelper.recommend();
12754
13209
  };
12755
13210
  if (this._searchFunction) {
12756
13211
  // this client isn't used to actually search, but required for the helper
@@ -15188,7 +15643,7 @@
15188
15643
  }, _typeof$y(obj);
15189
15644
  }
15190
15645
  var _excluded$9 = ["page"],
15191
- _excluded2$1 = ["clickAnalytics", "userToken"];
15646
+ _excluded2$2 = ["clickAnalytics", "userToken"];
15192
15647
  function ownKeys$s(object, enumerableOnly) {
15193
15648
  var keys = Object.keys(object);
15194
15649
  if (Object.getOwnPropertySymbols) {
@@ -15304,7 +15759,7 @@
15304
15759
  var _ref2 = state || {},
15305
15760
  clickAnalytics = _ref2.clickAnalytics,
15306
15761
  userToken = _ref2.userToken,
15307
- rest = _objectWithoutProperties$9(_ref2, _excluded2$1);
15762
+ rest = _objectWithoutProperties$9(_ref2, _excluded2$2);
15308
15763
  return rest;
15309
15764
  }
15310
15765
  function getInMemoryCache() {
@@ -17243,7 +17698,7 @@
17243
17698
  }, _typeof$F(obj);
17244
17699
  }
17245
17700
  var _excluded$b = ["name", "escapedValue"],
17246
- _excluded2$2 = ["escapedValue", "value"];
17701
+ _excluded2$3 = ["escapedValue", "value"];
17247
17702
  function ownKeys$y(object, enumerableOnly) {
17248
17703
  var keys = Object.keys(object);
17249
17704
  if (Object.getOwnPropertySymbols) {
@@ -17428,7 +17883,7 @@
17428
17883
  var normalizedFacetValues = transformItems(facetValues.map(function (_ref3) {
17429
17884
  var escapedValue = _ref3.escapedValue,
17430
17885
  value = _ref3.value,
17431
- item = _objectWithoutProperties$b(_ref3, _excluded2$2);
17886
+ item = _objectWithoutProperties$b(_ref3, _excluded2$3);
17432
17887
  return _objectSpread$y(_objectSpread$y({}, item), {}, {
17433
17888
  value: escapedValue,
17434
17889
  label: value
@@ -19592,7 +20047,7 @@
19592
20047
  }
19593
20048
 
19594
20049
  var _excluded$p = ["escapeHTML", "transformItems", "hitComponent"],
19595
- _excluded2$3 = ["hit", "index"];
20050
+ _excluded2$4 = ["hit", "index"];
19596
20051
  // @MAJOR: Move default hit component back to the UI library
19597
20052
  // once flavour specificities are erased
19598
20053
  function DefaultHitComponent(_ref) {
@@ -19624,7 +20079,7 @@
19624
20079
  var itemComponent = function itemComponent(_ref3) {
19625
20080
  var hit = _ref3.hit,
19626
20081
  index = _ref3.index,
19627
- itemProps = _objectWithoutProperties$c(_ref3, _excluded2$3);
20082
+ itemProps = _objectWithoutProperties$c(_ref3, _excluded2$4);
19628
20083
  return /*#__PURE__*/React__default.createElement("li", _extends$1({
19629
20084
  key: hit.objectID
19630
20085
  }, itemProps), /*#__PURE__*/React__default.createElement(HitComponent, {
@@ -19872,7 +20327,7 @@
19872
20327
  }
19873
20328
 
19874
20329
  var _excluded$w = ["pages", "currentPage", "nbPages", "isFirstPage", "isLastPage", "showFirst", "showPrevious", "showNext", "showLast", "createURL", "onNavigate", "translations", "classNames"],
19875
- _excluded2$4 = ["isDisabled", "className", "classNames", "href", "onClick"];
20330
+ _excluded2$5 = ["isDisabled", "className", "classNames", "href", "onClick"];
19876
20331
  function Pagination(_ref) {
19877
20332
  var pages = _ref.pages,
19878
20333
  currentPage = _ref.currentPage,
@@ -19963,7 +20418,7 @@
19963
20418
  classNames = _ref2.classNames,
19964
20419
  href = _ref2.href,
19965
20420
  _onClick = _ref2.onClick,
19966
- props = _objectWithoutProperties$c(_ref2, _excluded2$4);
20421
+ props = _objectWithoutProperties$c(_ref2, _excluded2$5);
19967
20422
  if (isDisabled) {
19968
20423
  return /*#__PURE__*/React__default.createElement("li", {
19969
20424
  className: cx('ais-Pagination-item', classNames.item, 'ais-Pagination-item--disabled', classNames.disabledItem, className)