react-instantsearch-core 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
@@ -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());
@@ -9181,6 +9602,10 @@
9181
9602
  uiState: localUiState,
9182
9603
  initialSearchParameters: helper.state
9183
9604
  }),
9605
+ recommendState: getLocalWidgetsRecommendParameters(localWidgets, {
9606
+ uiState: localUiState,
9607
+ initialRecommendParameters: helper.recommendState
9608
+ }),
9184
9609
  _uiState: localUiState
9185
9610
  });
9186
9611
 
@@ -9277,11 +9702,16 @@
9277
9702
  index: indexName
9278
9703
  })
9279
9704
  });
9705
+ var recommendParameters = getLocalWidgetsRecommendParameters(localWidgets, {
9706
+ uiState: localUiState,
9707
+ initialRecommendParameters: new algoliasearchHelper_1.RecommendParameters()
9708
+ });
9280
9709
 
9281
9710
  // This Helper is only used for state management we do not care about the
9282
9711
  // `searchClient`. Only the "main" Helper created at the `InstantSearch`
9283
9712
  // level is aware of the client.
9284
9713
  helper = algoliasearchHelper_1({}, parameters.index, parameters);
9714
+ helper.recommendState = recommendParameters;
9285
9715
 
9286
9716
  // We forward the call to `search` to the "main" instance of the Helper
9287
9717
  // which is responsible for managing the queries (it's the only one that is
@@ -9312,6 +9742,8 @@
9312
9742
  };
9313
9743
  derivedHelper = mainHelper.derive(function () {
9314
9744
  return mergeSearchParameters.apply(void 0, [mainHelper.state].concat(_toConsumableArray$1(resolveSearchParameters(_this3))));
9745
+ }, function () {
9746
+ return _this3.getHelper().recommendState;
9315
9747
  });
9316
9748
  var indexInitialResults = (_instantSearchInstanc = instantSearchInstance._initialResults) === null || _instantSearchInstanc === void 0 ? void 0 : _instantSearchInstanc[this.getIndexId()];
9317
9749
  if (indexInitialResults) {
@@ -9354,6 +9786,21 @@
9354
9786
  lastValidSearchParameters = results === null || results === void 0 ? void 0 : results._state;
9355
9787
  });
9356
9788
 
9789
+ // eslint-disable-next-line no-warning-comments
9790
+ // TODO: listen to "result" event when events for Recommend are implemented
9791
+ derivedHelper.on('recommend:result', function (_ref5) {
9792
+ var recommend = _ref5.recommend;
9793
+ // The index does not render the results it schedules a new render
9794
+ // to let all the other indices emit their own results. It allows us to
9795
+ // run the render process in one pass.
9796
+ instantSearchInstance.scheduleRender();
9797
+
9798
+ // the derived helper is the one which actually searches, but the helper
9799
+ // which is exposed e.g. via instance.helper, doesn't search, and thus
9800
+ // does not have access to lastRecommendResults.
9801
+ helper.lastRecommendResults = recommend.results;
9802
+ });
9803
+
9357
9804
  // We compute the render state before calling `init` in a separate loop
9358
9805
  // to construct the whole render state object that is then passed to
9359
9806
  // `init`.
@@ -9400,9 +9847,9 @@
9400
9847
  instantSearchInstance.scheduleRender();
9401
9848
  }
9402
9849
  },
9403
- render: function render(_ref5) {
9850
+ render: function render(_ref6) {
9404
9851
  var _this4 = this;
9405
- var instantSearchInstance = _ref5.instantSearchInstance;
9852
+ var instantSearchInstance = _ref6.instantSearchInstance;
9406
9853
  // we can't attach a listener to the error event of search, as the error
9407
9854
  // then would no longer be thrown for global handlers.
9408
9855
  if (instantSearchInstance.status === 'error' && !instantSearchInstance.mainHelper.hasPendingRequests() && lastValidSearchParameters) {
@@ -9412,6 +9859,14 @@
9412
9859
  // We only render index widgets if there are no results.
9413
9860
  // This makes sure `render` is never called with `results` being `null`.
9414
9861
  var widgetsToRender = this.getResults() ? localWidgets : localWidgets.filter(isIndexWidget);
9862
+ widgetsToRender = widgetsToRender.filter(function (widget) {
9863
+ if (!widget.shouldRender) {
9864
+ return true;
9865
+ }
9866
+ return widget.shouldRender({
9867
+ instantSearchInstance: instantSearchInstance
9868
+ });
9869
+ });
9415
9870
  widgetsToRender.forEach(function (widget) {
9416
9871
  if (widget.getRenderState) {
9417
9872
  var renderState = widget.getRenderState(instantSearchInstance.renderState[_this4.getIndexId()] || {}, createRenderArgs(instantSearchInstance, _this4));
@@ -9469,8 +9924,8 @@
9469
9924
  getWidgetState: function getWidgetState(uiState) {
9470
9925
  return this.getWidgetUiState(uiState);
9471
9926
  },
9472
- getWidgetSearchParameters: function getWidgetSearchParameters(searchParameters, _ref6) {
9473
- var uiState = _ref6.uiState;
9927
+ getWidgetSearchParameters: function getWidgetSearchParameters(searchParameters, _ref7) {
9928
+ var uiState = _ref7.uiState;
9474
9929
  return getLocalWidgetsSearchParameters(localWidgets, {
9475
9930
  uiState: uiState,
9476
9931
  initialSearchParameters: searchParameters
@@ -9490,10 +9945,10 @@
9490
9945
  }
9491
9946
  };
9492
9947
  };
9493
- function storeRenderState(_ref7) {
9494
- var renderState = _ref7.renderState,
9495
- instantSearchInstance = _ref7.instantSearchInstance,
9496
- parent = _ref7.parent;
9948
+ function storeRenderState(_ref8) {
9949
+ var renderState = _ref8.renderState,
9950
+ instantSearchInstance = _ref8.instantSearchInstance,
9951
+ parent = _ref8.parent;
9497
9952
  var parentIndexName = parent ? parent.getIndexId() : instantSearchInstance.mainIndex.getIndexId();
9498
9953
  instantSearchInstance.renderState = _objectSpread$a(_objectSpread$a({}, instantSearchInstance.renderState), {}, _defineProperty$b({}, parentIndexName, _objectSpread$a(_objectSpread$a({}, instantSearchInstance.renderState[parentIndexName]), renderState)));
9499
9954
  }
@@ -11758,7 +12213,7 @@
11758
12213
  };
11759
12214
  }
11760
12215
 
11761
- var version$2 = '4.66.1';
12216
+ var version$2 = '4.67.0';
11762
12217
 
11763
12218
  function _typeof$k(obj) {
11764
12219
  "@babel/helpers - typeof";
@@ -12252,7 +12707,7 @@
12252
12707
  // under the hood, we have a different implementation. It should be
12253
12708
  // completely transparent for the rest of the codebase. Only this module
12254
12709
  // is impacted.
12255
- return mainHelper.searchOnlyWithDerivedHelpers();
12710
+ return mainHelper.searchOnlyWithDerivedHelpers() && mainHelper.recommend();
12256
12711
  };
12257
12712
  if (this._searchFunction) {
12258
12713
  // this client isn't used to actually search, but required for the helper
@@ -14516,7 +14971,7 @@
14516
14971
  }, _typeof$s(obj);
14517
14972
  }
14518
14973
  var _excluded$9 = ["page"],
14519
- _excluded2$1 = ["clickAnalytics", "userToken"];
14974
+ _excluded2$2 = ["clickAnalytics", "userToken"];
14520
14975
  function ownKeys$o(object, enumerableOnly) {
14521
14976
  var keys = Object.keys(object);
14522
14977
  if (Object.getOwnPropertySymbols) {
@@ -14632,7 +15087,7 @@
14632
15087
  var _ref2 = state || {},
14633
15088
  clickAnalytics = _ref2.clickAnalytics,
14634
15089
  userToken = _ref2.userToken,
14635
- rest = _objectWithoutProperties$5(_ref2, _excluded2$1);
15090
+ rest = _objectWithoutProperties$5(_ref2, _excluded2$2);
14636
15091
  return rest;
14637
15092
  }
14638
15093
  function getInMemoryCache() {
@@ -16571,7 +17026,7 @@
16571
17026
  }, _typeof$z(obj);
16572
17027
  }
16573
17028
  var _excluded$b = ["name", "escapedValue"],
16574
- _excluded2$2 = ["escapedValue", "value"];
17029
+ _excluded2$3 = ["escapedValue", "value"];
16575
17030
  function ownKeys$u(object, enumerableOnly) {
16576
17031
  var keys = Object.keys(object);
16577
17032
  if (Object.getOwnPropertySymbols) {
@@ -16756,7 +17211,7 @@
16756
17211
  var normalizedFacetValues = transformItems(facetValues.map(function (_ref3) {
16757
17212
  var escapedValue = _ref3.escapedValue,
16758
17213
  value = _ref3.value,
16759
- item = _objectWithoutProperties$7(_ref3, _excluded2$2);
17214
+ item = _objectWithoutProperties$7(_ref3, _excluded2$3);
16760
17215
  return _objectSpread$t(_objectSpread$t({}, item), {}, {
16761
17216
  value: escapedValue,
16762
17217
  label: value