instantsearch.js 4.66.0 → 4.67.0

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.
@@ -1,4 +1,4 @@
1
- /*! InstantSearch.js 4.66.0 | © Algolia, Inc. and contributors; MIT License | https://github.com/algolia/instantsearch */
1
+ /*! InstantSearch.js 4.67.0 | © Algolia, Inc. and contributors; MIT License | https://github.com/algolia/instantsearch */
2
2
  (function (global, factory) {
3
3
  typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
4
4
  typeof define === 'function' && define.amd ? define(factory) :
@@ -2726,6 +2726,8 @@
2726
2726
  if (!escapeHTML) {
2727
2727
  return state;
2728
2728
  }
2729
+
2730
+ // @MAJOR: set this globally, not in the Hits widget to allow Hits to be conditionally used
2729
2731
  return state.setQueryParameters(TAG_PLACEHOLDER);
2730
2732
  }
2731
2733
  };
@@ -3314,6 +3316,7 @@
3314
3316
  var uiState = _ref10.uiState;
3315
3317
  var widgetSearchParameters = searchParameters;
3316
3318
  if (escapeHTML) {
3319
+ // @MAJOR: set this globally, not in the InfiniteHits widget to allow InfiniteHits to be conditionally used
3317
3320
  widgetSearchParameters = searchParameters.setQueryParameters(TAG_PLACEHOLDER);
3318
3321
  }
3319
3322
 
@@ -6098,12 +6101,15 @@
6098
6101
  * This event contains a {@link SearchResults} object and the
6099
6102
  * {@link SearchParameters} corresponding to this answer.
6100
6103
  * @param {AlgoliaSearchHelper} mainHelper the main helper
6101
- * @param {function} fn the function to create the derived state
6104
+ * @param {function} fn the function to create the derived state for search
6105
+ * @param {function} recommendFn the function to create the derived state for recommendations
6102
6106
  */
6103
- function DerivedHelper(mainHelper, fn) {
6107
+ function DerivedHelper(mainHelper, fn, recommendFn) {
6104
6108
  this.main = mainHelper;
6105
6109
  this.fn = fn;
6110
+ this.recommendFn = recommendFn;
6106
6111
  this.lastResults = null;
6112
+ this.lastRecommendResults = null;
6107
6113
  }
6108
6114
 
6109
6115
  inherits_1(DerivedHelper, events);
@@ -6122,6 +6128,10 @@
6122
6128
  return this.fn(parameters);
6123
6129
  };
6124
6130
 
6131
+ DerivedHelper.prototype.getModifiedRecommendState = function (parameters) {
6132
+ return this.recommendFn(parameters);
6133
+ };
6134
+
6125
6135
  var DerivedHelper_1 = DerivedHelper;
6126
6136
 
6127
6137
  /**
@@ -6260,6 +6270,92 @@
6260
6270
 
6261
6271
  var omit$1 = _objectWithoutPropertiesLoose$1;
6262
6272
 
6273
+ /**
6274
+ * RecommendParameters is the data structure that contains all the information
6275
+ * usable for getting recommendations from the Algolia API. It doesn't do the
6276
+ * search itself, nor does it contains logic about the parameters.
6277
+ * It is an immutable object, therefore it has been created in a way that each
6278
+ * changes does not change the object itself but returns a copy with the
6279
+ * modification.
6280
+ * This object should probably not be instantiated outside of the helper. It
6281
+ * will be provided when needed.
6282
+ * @constructor
6283
+ * @classdesc contains all the parameters for recommendations
6284
+ * @param {RecommendParametersOptions} opts the options to create the object
6285
+ */
6286
+ function RecommendParameters(opts) {
6287
+ opts = opts || {};
6288
+ this.params = opts.params || [];
6289
+ }
6290
+
6291
+ RecommendParameters.prototype = {
6292
+ constructor: RecommendParameters,
6293
+
6294
+ addParams: function (params) {
6295
+ var newParams = this.params.slice();
6296
+ var existingParamsIndex = this.params.findIndex(function (currentParams) {
6297
+ return currentParams.$$id === params.$$id;
6298
+ });
6299
+
6300
+ if (existingParamsIndex !== -1) {
6301
+ newParams.splice(existingParamsIndex, 1, params);
6302
+ } else {
6303
+ newParams.push(params);
6304
+ }
6305
+
6306
+ return new RecommendParameters({ params: newParams });
6307
+ },
6308
+
6309
+ removeParams: function (id) {
6310
+ return new RecommendParameters({
6311
+ params: this.params.filter(function (param) {
6312
+ return param.$$id !== id;
6313
+ }),
6314
+ });
6315
+ },
6316
+
6317
+ addFrequentlyBoughtTogether: function (params) {
6318
+ return this.addParams(
6319
+ Object.assign({}, params, { model: 'bought-together' })
6320
+ );
6321
+ },
6322
+
6323
+ addRelatedProducts: function (params) {
6324
+ return this.addParams(
6325
+ Object.assign({}, params, { model: 'related-products' })
6326
+ );
6327
+ },
6328
+
6329
+ addTrendingItems: function (params) {
6330
+ return this.addParams(
6331
+ Object.assign({}, params, { model: 'trending-items' })
6332
+ );
6333
+ },
6334
+
6335
+ addTrendingFacets: function (params) {
6336
+ return this.addParams(
6337
+ Object.assign({}, params, { model: 'trending-facets' })
6338
+ );
6339
+ },
6340
+
6341
+ addLookingSimilar: function (params) {
6342
+ return this.addParams(
6343
+ Object.assign({}, params, { model: 'looking-similar' })
6344
+ );
6345
+ },
6346
+
6347
+ _buildQueries: function (indexName) {
6348
+ return this.params.map(function (params) {
6349
+ var query = Object.assign({}, params, { indexName: indexName });
6350
+ delete query.$$id;
6351
+
6352
+ return query;
6353
+ });
6354
+ },
6355
+ };
6356
+
6357
+ var RecommendParameters_1 = RecommendParameters;
6358
+
6263
6359
  function sortObject(obj) {
6264
6360
  return Object.keys(obj)
6265
6361
  .sort()
@@ -10107,7 +10203,7 @@
10107
10203
 
10108
10204
  var SearchResults_1 = SearchResults;
10109
10205
 
10110
- var version = '3.16.3';
10206
+ var version = '3.18.0';
10111
10207
 
10112
10208
  var escapeFacetValue$4 = escapeFacetValue_1.escapeFacetValue;
10113
10209
 
@@ -10119,6 +10215,7 @@
10119
10215
 
10120
10216
 
10121
10217
 
10218
+
10122
10219
  /**
10123
10220
  * Event triggered when a parameter is set or updated
10124
10221
  * @event AlgoliaSearchHelper#event:change
@@ -10232,11 +10329,18 @@
10232
10329
  var opts = options || {};
10233
10330
  opts.index = index;
10234
10331
  this.state = SearchParameters_1.make(opts);
10332
+ this.recommendState = new RecommendParameters_1({
10333
+ params: opts.recommendState,
10334
+ });
10235
10335
  this.lastResults = null;
10336
+ this.lastRecommendResults = null;
10236
10337
  this._queryId = 0;
10338
+ this._recommendQueryId = 0;
10237
10339
  this._lastQueryIdReceived = -1;
10340
+ this._lastRecommendQueryIdReceived = -1;
10238
10341
  this.derivedHelpers = [];
10239
10342
  this._currentNbQueries = 0;
10343
+ this._currentNbRecommendQueries = 0;
10240
10344
  this._searchResultsOptions = searchResultsOptions;
10241
10345
  }
10242
10346
 
@@ -10263,6 +10367,21 @@
10263
10367
  return this;
10264
10368
  };
10265
10369
 
10370
+ /**
10371
+ * Sends the recommendation queries set in the state. When the method is
10372
+ * called, it triggers a `fetch` event. The results will be available through
10373
+ * the `result` event. If an error occurs, an `error` will be fired instead.
10374
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
10375
+ * @fires fetch
10376
+ * @fires result
10377
+ * @fires error
10378
+ * @chainable
10379
+ */
10380
+ AlgoliaSearchHelper.prototype.recommend = function () {
10381
+ this._recommend();
10382
+ return this;
10383
+ };
10384
+
10266
10385
  /**
10267
10386
  * Gets the search query parameters that would be sent to the Algolia Client
10268
10387
  * for the hits
@@ -10759,6 +10878,86 @@
10759
10878
  return this;
10760
10879
  };
10761
10880
 
10881
+ /**
10882
+ * Adds a "frequently bought together" recommendation query.
10883
+ *
10884
+ * @param {FrequentlyBoughtTogetherQuery} params the parameters for the recommendation
10885
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
10886
+ * @fires change
10887
+ * @chainable
10888
+ */
10889
+ AlgoliaSearchHelper.prototype.addFrequentlyBoughtTogether = function (params) {
10890
+ this._recommendChange({
10891
+ state: this.recommendState.addFrequentlyBoughtTogether(params),
10892
+ });
10893
+
10894
+ return this;
10895
+ };
10896
+
10897
+ /**
10898
+ * Adds a "related products" recommendation query.
10899
+ *
10900
+ * @param {RelatedProductsQuery} params the parameters for the recommendation
10901
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
10902
+ * @fires change
10903
+ * @chainable
10904
+ */
10905
+ AlgoliaSearchHelper.prototype.addRelatedProducts = function (params) {
10906
+ this._recommendChange({
10907
+ state: this.recommendState.addRelatedProducts(params),
10908
+ });
10909
+
10910
+ return this;
10911
+ };
10912
+
10913
+ /**
10914
+ * Adds a "trending items" recommendation query.
10915
+ *
10916
+ * @param {TrendingItemsQuery} params the parameters for the recommendation
10917
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
10918
+ * @fires change
10919
+ * @chainable
10920
+ */
10921
+ AlgoliaSearchHelper.prototype.addTrendingItems = function (params) {
10922
+ this._recommendChange({
10923
+ state: this.recommendState.addTrendingItems(params),
10924
+ });
10925
+
10926
+ return this;
10927
+ };
10928
+
10929
+ /**
10930
+ * Adds a "trending facets" recommendation query.
10931
+ *
10932
+ * @param {TrendingFacetsQuery} params the parameters for the recommendation
10933
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
10934
+ * @fires change
10935
+ * @chainable
10936
+ */
10937
+ AlgoliaSearchHelper.prototype.addTrendingFacets = function (params) {
10938
+ this._recommendChange({
10939
+ state: this.recommendState.addTrendingFacets(params),
10940
+ });
10941
+
10942
+ return this;
10943
+ };
10944
+
10945
+ /**
10946
+ * Adds a "looking similar" recommendation query.
10947
+ *
10948
+ * @param {LookingSimilarQuery} params the parameters for the recommendation
10949
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
10950
+ * @fires change
10951
+ * @chainable
10952
+ */
10953
+ AlgoliaSearchHelper.prototype.addLookingSimilar = function (params) {
10954
+ this._recommendChange({
10955
+ state: this.recommendState.addLookingSimilar(params),
10956
+ });
10957
+
10958
+ return this;
10959
+ };
10960
+
10762
10961
  /**
10763
10962
  * Removes an numeric filter to an attribute with the `operator` and `value` provided. If the
10764
10963
  * filter is not set, it doesn't change the filters.
@@ -10928,6 +11127,86 @@
10928
11127
  return this;
10929
11128
  };
10930
11129
 
11130
+ /**
11131
+ * Removes a "frequently bought together" recommendation query.
11132
+ *
11133
+ * @param {string} id identifier of the recommendation widget
11134
+ * @returns {AlgoliaSearchHelper} Method is chainable, it returns itself
11135
+ * @fires change
11136
+ * @chainable
11137
+ */
11138
+ AlgoliaSearchHelper.prototype.removeFrequentlyBoughtTogether = function (id) {
11139
+ this._recommendChange({
11140
+ state: this.recommendState.removeParams(id),
11141
+ });
11142
+
11143
+ return this;
11144
+ };
11145
+
11146
+ /**
11147
+ * Removes a "related products" recommendation query.
11148
+ *
11149
+ * @param {string} id identifier of the recommendation widget
11150
+ * @returns {AlgoliaSearchHelper} Method is chainable, it returns itself
11151
+ * @fires change
11152
+ * @chainable
11153
+ */
11154
+ AlgoliaSearchHelper.prototype.removeRelatedProducts = function (id) {
11155
+ this._recommendChange({
11156
+ state: this.recommendState.removeParams(id),
11157
+ });
11158
+
11159
+ return this;
11160
+ };
11161
+
11162
+ /**
11163
+ * Removes a "trending items" recommendation query.
11164
+ *
11165
+ * @param {string} id identifier of the recommendation widget
11166
+ * @returns {AlgoliaSearchHelper} Method is chainable, it returns itself
11167
+ * @fires change
11168
+ * @chainable
11169
+ */
11170
+ AlgoliaSearchHelper.prototype.removeTrendingItems = function (id) {
11171
+ this._recommendChange({
11172
+ state: this.recommendState.removeParams(id),
11173
+ });
11174
+
11175
+ return this;
11176
+ };
11177
+
11178
+ /**
11179
+ * Removes a "trending facets" recommendation query.
11180
+ *
11181
+ * @param {string} id identifier of the recommendation widget
11182
+ * @returns {AlgoliaSearchHelper} Method is chainable, it returns itself
11183
+ * @fires change
11184
+ * @chainable
11185
+ */
11186
+ AlgoliaSearchHelper.prototype.removeTrendingFacets = function (id) {
11187
+ this._recommendChange({
11188
+ state: this.recommendState.removeParams(id),
11189
+ });
11190
+
11191
+ return this;
11192
+ };
11193
+
11194
+ /**
11195
+ * Removes a "looking similar" recommendation query.
11196
+ *
11197
+ * @param {string} id identifier of the recommendation widget
11198
+ * @returns {AlgoliaSearchHelper} Method is chainable, it returns itself
11199
+ * @fires change
11200
+ * @chainable
11201
+ */
11202
+ AlgoliaSearchHelper.prototype.removeLookingSimilar = function (id) {
11203
+ this._recommendChange({
11204
+ state: this.recommendState.removeParams(id),
11205
+ });
11206
+
11207
+ return this;
11208
+ };
11209
+
10931
11210
  /**
10932
11211
  * Adds or removes an exclusion filter to a faceted attribute with the `value` provided. If
10933
11212
  * the value is set then it removes it, otherwise it adds the filter.
@@ -11495,6 +11774,85 @@
11495
11774
  return undefined;
11496
11775
  };
11497
11776
 
11777
+ AlgoliaSearchHelper.prototype._recommend = function () {
11778
+ var searchState = this.state;
11779
+ var recommendState = this.recommendState;
11780
+ var index = this.getIndex();
11781
+ var states = [{ state: recommendState, index: index, helper: this }];
11782
+
11783
+ this.emit('fetch', {
11784
+ recommend: {
11785
+ state: recommendState,
11786
+ results: this.lastRecommendResults,
11787
+ },
11788
+ });
11789
+
11790
+ var derivedQueries = this.derivedHelpers.map(function (derivedHelper) {
11791
+ var derivedIndex = derivedHelper.getModifiedState(searchState).index;
11792
+ if (!derivedIndex) {
11793
+ return [];
11794
+ }
11795
+
11796
+ // Contrary to what is done when deriving the search state, we don't want to
11797
+ // provide the current recommend state to the derived helper, as it would
11798
+ // inherit unwanted queries. We instead provide an empty recommend state.
11799
+ var derivedState = derivedHelper.getModifiedRecommendState(
11800
+ new RecommendParameters_1()
11801
+ );
11802
+ states.push({
11803
+ state: derivedState,
11804
+ index: derivedIndex,
11805
+ helper: derivedHelper,
11806
+ });
11807
+
11808
+ derivedHelper.emit('fetch', {
11809
+ recommend: {
11810
+ state: derivedState,
11811
+ results: derivedHelper.lastRecommendResults,
11812
+ },
11813
+ });
11814
+
11815
+ return derivedState._buildQueries(derivedIndex);
11816
+ });
11817
+
11818
+ var queries = Array.prototype.concat.apply(
11819
+ this.recommendState._buildQueries(index),
11820
+ derivedQueries
11821
+ );
11822
+
11823
+ if (queries.length === 0) {
11824
+ return;
11825
+ }
11826
+
11827
+ if (
11828
+ queries.length > 0 &&
11829
+ typeof this.client.getRecommendations === 'undefined'
11830
+ ) {
11831
+ // eslint-disable-next-line no-console
11832
+ console.warn(
11833
+ 'Please update algoliasearch/lite to the latest version in order to use recommendations widgets.'
11834
+ );
11835
+ return;
11836
+ }
11837
+
11838
+ var queryId = this._recommendQueryId++;
11839
+ this._currentNbRecommendQueries++;
11840
+
11841
+ try {
11842
+ this.client
11843
+ .getRecommendations(queries)
11844
+ .then(this._dispatchRecommendResponse.bind(this, queryId, states))
11845
+ .catch(this._dispatchRecommendError.bind(this, queryId));
11846
+ } catch (error) {
11847
+ // If we reach this part, we're in an internal error state
11848
+ this.emit('error', {
11849
+ error: error,
11850
+ });
11851
+ }
11852
+
11853
+ return;
11854
+ };
11855
+
11498
11856
  /**
11499
11857
  * Transform the responses as sent by the server and transform them into a user
11500
11858
  * usable object that merge the results of all the batch requests. It will dispatch
@@ -11554,6 +11912,53 @@
11554
11912
  });
11555
11913
  };
11556
11914
 
11915
+ AlgoliaSearchHelper.prototype._dispatchRecommendResponse = function (
11916
+ queryId,
11917
+ states,
11918
+ content
11919
+ ) {
11920
+ // @TODO remove the number of outdated queries discarded instead of just one
11921
+
11922
+ if (queryId < this._lastRecommendQueryIdReceived) {
11923
+ // Outdated answer
11924
+ return;
11925
+ }
11926
+
11927
+ this._currentNbRecommendQueries -=
11928
+ queryId - this._lastRecommendQueryIdReceived;
11929
+ this._lastRecommendQueryIdReceived = queryId;
11930
+
11931
+ if (this._currentNbRecommendQueries === 0) this.emit('recommendQueueEmpty');
11932
+
11933
+ var results = content.results.slice();
11934
+
11935
+ states.forEach(function (s) {
11936
+ var state = s.state;
11937
+ var helper = s.helper;
11938
+
11939
+ if (!s.index) {
11940
+ // eslint-disable-next-line no-warning-comments
11941
+ // TODO: emit "result" event when events for Recommend are implemented
11942
+ helper.emit('recommend:result', {
11943
+ results: null,
11944
+ state: state,
11945
+ });
11946
+ return;
11947
+ }
11948
+
11949
+ helper.lastRecommendResults = results;
11950
+
11951
+ // eslint-disable-next-line no-warning-comments
11952
+ // TODO: emit "result" event when events for Recommend are implemented
11953
+ helper.emit('recommend:result', {
11954
+ recommend: {
11955
+ results: helper.lastRecommendResults,
11956
+ state: state,
11957
+ },
11958
+ });
11959
+ });
11960
+ };
11961
+
11557
11962
  AlgoliaSearchHelper.prototype._dispatchAlgoliaError = function (
11558
11963
  queryId,
11559
11964
  error
@@ -11573,6 +11978,26 @@
11573
11978
  if (this._currentNbQueries === 0) this.emit('searchQueueEmpty');
11574
11979
  };
11575
11980
 
11981
+ AlgoliaSearchHelper.prototype._dispatchRecommendError = function (
11982
+ queryId,
11983
+ error
11984
+ ) {
11985
+ if (queryId < this._lastRecommendQueryIdReceived) {
11986
+ // Outdated answer
11987
+ return;
11988
+ }
11989
+
11990
+ this._currentNbRecommendQueries -=
11991
+ queryId - this._lastRecommendQueryIdReceived;
11992
+ this._lastRecommendQueryIdReceived = queryId;
11993
+
11994
+ this.emit('error', {
11995
+ error: error,
11996
+ });
11997
+
11998
+ if (this._currentNbRecommendQueries === 0) this.emit('recommendQueueEmpty');
11999
+ };
12000
+
11576
12001
  AlgoliaSearchHelper.prototype.containsRefinement = function (
11577
12002
  query,
11578
12003
  facetFilters,
@@ -11615,6 +12040,27 @@
11615
12040
  }
11616
12041
  };
11617
12042
 
12043
+ AlgoliaSearchHelper.prototype._recommendChange = function (event) {
12044
+ var state = event.state;
12045
+
12046
+ if (state !== this.recommendState) {
12047
+ this.recommendState = state;
12048
+
12049
+ // eslint-disable-next-line no-warning-comments
12050
+ // TODO: emit "change" event when events for Recommend are implemented
12051
+ this.emit('recommend:change', {
12052
+ search: {
12053
+ results: this.lastResults,
12054
+ state: this.state,
12055
+ },
12056
+ recommend: {
12057
+ results: this.lastRecommendResults,
12058
+ state: this.recommendState,
12059
+ },
12060
+ });
12061
+ }
12062
+ };
12063
+
11618
12064
  /**
11619
12065
  * Clears the cache of the underlying Algolia client.
11620
12066
  * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
@@ -11666,10 +12112,11 @@
11666
12112
  * and the SearchParameters that is returned by the call of the
11667
12113
  * parameter function.
11668
12114
  * @param {function} fn SearchParameters -> SearchParameters
12115
+ * @param {function} recommendFn RecommendParameters -> RecommendParameters
11669
12116
  * @return {DerivedHelper} a new DerivedHelper
11670
12117
  */
11671
- AlgoliaSearchHelper.prototype.derive = function (fn) {
11672
- var derivedHelper = new DerivedHelper_1(this, fn);
12118
+ AlgoliaSearchHelper.prototype.derive = function (fn, recommendFn) {
12119
+ var derivedHelper = new DerivedHelper_1(this, fn, recommendFn);
11673
12120
  this.derivedHelpers.push(derivedHelper);
11674
12121
  return derivedHelper;
11675
12122
  };
@@ -11771,6 +12218,13 @@
11771
12218
  */
11772
12219
  algoliasearchHelper.SearchParameters = SearchParameters_1;
11773
12220
 
12221
+ /**
12222
+ * Constructor for the object containing all the parameters for Recommend.
12223
+ * @member module:algoliasearchHelper.RecommendParameters
12224
+ * @type {RecommendParameters}
12225
+ */
12226
+ algoliasearchHelper.RecommendParameters = RecommendParameters_1;
12227
+
11774
12228
  /**
11775
12229
  * Constructor for the object containing the results of the search.
11776
12230
  * @member module:algoliasearchHelper.SearchResults
@@ -14359,7 +14813,8 @@
14359
14813
  };
14360
14814
  };
14361
14815
 
14362
- var _excluded$7 = ["initialSearchParameters"];
14816
+ var _excluded$7 = ["initialSearchParameters"],
14817
+ _excluded2$2 = ["initialRecommendParameters"];
14363
14818
  var withUsage$q = createDocumentationMessageGenerator({
14364
14819
  name: 'index-widget'
14365
14820
  });
@@ -14370,6 +14825,7 @@
14370
14825
  */
14371
14826
  function privateHelperSetState(helper, _ref) {
14372
14827
  var state = _ref.state,
14828
+ recommendState = _ref.recommendState,
14373
14829
  isPageReset = _ref.isPageReset,
14374
14830
  _uiState = _ref._uiState;
14375
14831
  if (state !== helper.state) {
@@ -14381,7 +14837,14 @@
14381
14837
  _uiState: _uiState
14382
14838
  });
14383
14839
  }
14840
+ if (recommendState !== helper.recommendState) {
14841
+ helper.recommendState = recommendState;
14842
+
14843
+ // eslint-disable-next-line no-warning-comments
14844
+ // TODO: emit "change" event when events for Recommend are implemented
14845
+ }
14384
14846
  }
14847
+
14385
14848
  function getLocalWidgetsUiState(widgets, widgetStateOptions) {
14386
14849
  var initialUiState = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
14387
14850
  return widgets.reduce(function (uiState, widget) {
@@ -14400,15 +14863,26 @@
14400
14863
  function getLocalWidgetsSearchParameters(widgets, widgetSearchParametersOptions) {
14401
14864
  var initialSearchParameters = widgetSearchParametersOptions.initialSearchParameters,
14402
14865
  rest = _objectWithoutProperties(widgetSearchParametersOptions, _excluded$7);
14403
- return widgets.filter(function (widget) {
14404
- return !isIndexWidget(widget);
14405
- }).reduce(function (state, widget) {
14406
- if (!widget.getWidgetSearchParameters) {
14866
+ return widgets.reduce(function (state, widget) {
14867
+ if (!widget.getWidgetSearchParameters || isIndexWidget(widget)) {
14407
14868
  return state;
14408
14869
  }
14870
+ if (widget.dependsOn === 'search' && widget.getWidgetParameters) {
14871
+ return widget.getWidgetParameters(state, rest);
14872
+ }
14409
14873
  return widget.getWidgetSearchParameters(state, rest);
14410
14874
  }, initialSearchParameters);
14411
14875
  }
14876
+ function getLocalWidgetsRecommendParameters(widgets, widgetRecommendParametersOptions) {
14877
+ var initialRecommendParameters = widgetRecommendParametersOptions.initialRecommendParameters,
14878
+ rest = _objectWithoutProperties(widgetRecommendParametersOptions, _excluded2$2);
14879
+ return widgets.reduce(function (state, widget) {
14880
+ if (!isIndexWidget(widget) && widget.dependsOn === 'recommend' && widget.getWidgetParameters) {
14881
+ return widget.getWidgetParameters(state, rest);
14882
+ }
14883
+ return state;
14884
+ }, initialRecommendParameters);
14885
+ }
14412
14886
  function resetPageFromWidgets(widgets) {
14413
14887
  var indexWidgets = widgets.filter(isIndexWidget);
14414
14888
  if (indexWidgets.length === 0) {
@@ -14418,6 +14892,7 @@
14418
14892
  var widgetHelper = widget.getHelper();
14419
14893
  privateHelperSetState(widgetHelper, {
14420
14894
  state: widgetHelper.state.resetPage(),
14895
+ recommendState: widgetHelper.recommendState,
14421
14896
  isPageReset: true
14422
14897
  });
14423
14898
  resetPageFromWidgets(widget.getWidgets());
@@ -14513,6 +14988,10 @@
14513
14988
  uiState: localUiState,
14514
14989
  initialSearchParameters: helper.state
14515
14990
  }),
14991
+ recommendState: getLocalWidgetsRecommendParameters(localWidgets, {
14992
+ uiState: localUiState,
14993
+ initialRecommendParameters: helper.recommendState
14994
+ }),
14516
14995
  _uiState: localUiState
14517
14996
  });
14518
14997
 
@@ -14609,11 +15088,16 @@
14609
15088
  index: indexName
14610
15089
  })
14611
15090
  });
15091
+ var recommendParameters = getLocalWidgetsRecommendParameters(localWidgets, {
15092
+ uiState: localUiState,
15093
+ initialRecommendParameters: new algoliasearchHelper_1.RecommendParameters()
15094
+ });
14612
15095
 
14613
15096
  // This Helper is only used for state management we do not care about the
14614
15097
  // `searchClient`. Only the "main" Helper created at the `InstantSearch`
14615
15098
  // level is aware of the client.
14616
15099
  helper = algoliasearchHelper_1({}, parameters.index, parameters);
15100
+ helper.recommendState = recommendParameters;
14617
15101
 
14618
15102
  // We forward the call to `search` to the "main" instance of the Helper
14619
15103
  // which is responsible for managing the queries (it's the only one that is
@@ -14644,6 +15128,8 @@
14644
15128
  };
14645
15129
  derivedHelper = mainHelper.derive(function () {
14646
15130
  return mergeSearchParameters.apply(void 0, [mainHelper.state].concat(_toConsumableArray(resolveSearchParameters(_this3))));
15131
+ }, function () {
15132
+ return _this3.getHelper().recommendState;
14647
15133
  });
14648
15134
  var indexInitialResults = (_instantSearchInstanc = instantSearchInstance._initialResults) === null || _instantSearchInstanc === void 0 ? void 0 : _instantSearchInstanc[this.getIndexId()];
14649
15135
  if (indexInitialResults) {
@@ -14692,6 +15178,21 @@
14692
15178
  lastValidSearchParameters = results === null || results === void 0 ? void 0 : results._state;
14693
15179
  });
14694
15180
 
15181
+ // eslint-disable-next-line no-warning-comments
15182
+ // TODO: listen to "result" event when events for Recommend are implemented
15183
+ derivedHelper.on('recommend:result', function (_ref5) {
15184
+ var recommend = _ref5.recommend;
15185
+ // The index does not render the results it schedules a new render
15186
+ // to let all the other indices emit their own results. It allows us to
15187
+ // run the render process in one pass.
15188
+ instantSearchInstance.scheduleRender();
15189
+
15190
+ // the derived helper is the one which actually searches, but the helper
15191
+ // which is exposed e.g. via instance.helper, doesn't search, and thus
15192
+ // does not have access to lastRecommendResults.
15193
+ helper.lastRecommendResults = recommend.results;
15194
+ });
15195
+
14695
15196
  // We compute the render state before calling `init` in a separate loop
14696
15197
  // to construct the whole render state object that is then passed to
14697
15198
  // `init`.
@@ -14742,9 +15243,9 @@
14742
15243
  instantSearchInstance.scheduleRender();
14743
15244
  }
14744
15245
  },
14745
- render: function render(_ref5) {
15246
+ render: function render(_ref6) {
14746
15247
  var _this4 = this;
14747
- var instantSearchInstance = _ref5.instantSearchInstance;
15248
+ var instantSearchInstance = _ref6.instantSearchInstance;
14748
15249
  // we can't attach a listener to the error event of search, as the error
14749
15250
  // then would no longer be thrown for global handlers.
14750
15251
  if (instantSearchInstance.status === 'error' && !instantSearchInstance.mainHelper.hasPendingRequests() && lastValidSearchParameters) {
@@ -14754,6 +15255,14 @@
14754
15255
  // We only render index widgets if there are no results.
14755
15256
  // This makes sure `render` is never called with `results` being `null`.
14756
15257
  var widgetsToRender = this.getResults() ? localWidgets : localWidgets.filter(isIndexWidget);
15258
+ widgetsToRender = widgetsToRender.filter(function (widget) {
15259
+ if (!widget.shouldRender) {
15260
+ return true;
15261
+ }
15262
+ return widget.shouldRender({
15263
+ instantSearchInstance: instantSearchInstance
15264
+ });
15265
+ });
14757
15266
  widgetsToRender.forEach(function (widget) {
14758
15267
  if (widget.getRenderState) {
14759
15268
  var renderState = widget.getRenderState(instantSearchInstance.renderState[_this4.getIndexId()] || {}, createRenderArgs(instantSearchInstance, _this4));
@@ -14812,8 +15321,8 @@
14812
15321
  _warning(false, 'The `getWidgetState` method is renamed `getWidgetUiState` and will no longer exist under that name in InstantSearch.js 5.x. Please use `getWidgetUiState` instead.') ;
14813
15322
  return this.getWidgetUiState(uiState);
14814
15323
  },
14815
- getWidgetSearchParameters: function getWidgetSearchParameters(searchParameters, _ref6) {
14816
- var uiState = _ref6.uiState;
15324
+ getWidgetSearchParameters: function getWidgetSearchParameters(searchParameters, _ref7) {
15325
+ var uiState = _ref7.uiState;
14817
15326
  return getLocalWidgetsSearchParameters(localWidgets, {
14818
15327
  uiState: uiState,
14819
15328
  initialSearchParameters: searchParameters
@@ -14833,10 +15342,10 @@
14833
15342
  }
14834
15343
  };
14835
15344
  };
14836
- function storeRenderState(_ref7) {
14837
- var renderState = _ref7.renderState,
14838
- instantSearchInstance = _ref7.instantSearchInstance,
14839
- parent = _ref7.parent;
15345
+ function storeRenderState(_ref8) {
15346
+ var renderState = _ref8.renderState,
15347
+ instantSearchInstance = _ref8.instantSearchInstance,
15348
+ parent = _ref8.parent;
14840
15349
  var parentIndexName = parent ? parent.getIndexId() : instantSearchInstance.mainIndex.getIndexId();
14841
15350
  instantSearchInstance.renderState = _objectSpread2(_objectSpread2({}, instantSearchInstance.renderState), {}, _defineProperty({}, parentIndexName, _objectSpread2(_objectSpread2({}, instantSearchInstance.renderState[parentIndexName]), renderState)));
14842
15351
  }
@@ -14906,7 +15415,7 @@
14906
15415
  };
14907
15416
  }
14908
15417
 
14909
- var version$1 = '4.66.0';
15418
+ var version$1 = '4.67.0';
14910
15419
 
14911
15420
  var withUsage$r = createDocumentationMessageGenerator({
14912
15421
  name: 'instantsearch'
@@ -15269,7 +15778,7 @@
15269
15778
  // under the hood, we have a different implementation. It should be
15270
15779
  // completely transparent for the rest of the codebase. Only this module
15271
15780
  // is impacted.
15272
- return mainHelper.searchOnlyWithDerivedHelpers();
15781
+ return mainHelper.searchOnlyWithDerivedHelpers() && mainHelper.recommend();
15273
15782
  };
15274
15783
  if (this._searchFunction) {
15275
15784
  // this client isn't used to actually search, but required for the helper
@@ -16582,7 +17091,7 @@
16582
17091
  }
16583
17092
 
16584
17093
  var _excluded$e = ["hit", "attribute", "cssClasses"],
16585
- _excluded2$2 = ["isHighlighted"];
17094
+ _excluded2$3 = ["isHighlighted"];
16586
17095
  function ReverseHighlight$1(_ref) {
16587
17096
  var hit = _ref.hit,
16588
17097
  attribute = _ref.attribute,
@@ -16595,7 +17104,7 @@
16595
17104
  var value = _ref2.value;
16596
17105
  return getHighlightedParts(unescape$1(value || '')).map(function (_ref3) {
16597
17106
  var isHighlighted = _ref3.isHighlighted,
16598
- rest = _objectWithoutProperties(_ref3, _excluded2$2);
17107
+ rest = _objectWithoutProperties(_ref3, _excluded2$3);
16599
17108
  return _objectSpread2(_objectSpread2({}, rest), {}, {
16600
17109
  isHighlighted: !isHighlighted
16601
17110
  });
@@ -16623,7 +17132,7 @@
16623
17132
  }
16624
17133
 
16625
17134
  var _excluded$g = ["hit", "attribute", "cssClasses"],
16626
- _excluded2$3 = ["isHighlighted"];
17135
+ _excluded2$4 = ["isHighlighted"];
16627
17136
  function ReverseSnippet$1(_ref) {
16628
17137
  var hit = _ref.hit,
16629
17138
  attribute = _ref.attribute,
@@ -16636,7 +17145,7 @@
16636
17145
  var value = _ref2.value;
16637
17146
  return getHighlightedParts(unescape$1(value || '')).map(function (_ref3) {
16638
17147
  var isHighlighted = _ref3.isHighlighted,
16639
- rest = _objectWithoutProperties(_ref3, _excluded2$3);
17148
+ rest = _objectWithoutProperties(_ref3, _excluded2$4);
16640
17149
  return _objectSpread2(_objectSpread2({}, rest), {}, {
16641
17150
  isHighlighted: !isHighlighted
16642
17151
  });
@@ -17987,7 +18496,7 @@
17987
18496
  };
17988
18497
 
17989
18498
  var _excluded$k = ["initialZoom", "initialPosition", "templates", "cssClasses", "builtInMarker", "customHTMLMarker", "enableRefine", "enableClearMapRefinement", "enableRefineControl", "container", "googleReference"],
17990
- _excluded2$4 = ["item"],
18499
+ _excluded2$5 = ["item"],
17991
18500
  _excluded3 = ["item"];
17992
18501
  var withUsage$y = createDocumentationMessageGenerator({
17993
18502
  name: 'geo-search'
@@ -18089,7 +18598,7 @@
18089
18598
  var customHTMLMarker = isCustomHTMLMarker && _objectSpread2(_objectSpread2({}, defaultCustomHTMLMarker), userCustomHTMLMarker);
18090
18599
  var createBuiltInMarker = function createBuiltInMarker(_ref2) {
18091
18600
  var item = _ref2.item,
18092
- rest = _objectWithoutProperties(_ref2, _excluded2$4);
18601
+ rest = _objectWithoutProperties(_ref2, _excluded2$5);
18093
18602
  return new googleReference.maps.Marker(_objectSpread2(_objectSpread2(_objectSpread2({}, builtInMarker.createOptions(item)), rest), {}, {
18094
18603
  // @ts-expect-error @types/googlemaps doesn't document this
18095
18604
  __id: item.objectID,
@@ -20029,7 +20538,7 @@
20029
20538
  };
20030
20539
 
20031
20540
  var _excluded$n = ["placesReference", "defaultPosition"],
20032
- _excluded2$5 = ["places"];
20541
+ _excluded2$6 = ["places"];
20033
20542
 
20034
20543
  /* Places.js is an optional dependency, no error should be reported if the package is missing */
20035
20544
  /** @ts-ignore */
@@ -20085,7 +20594,7 @@
20085
20594
  var hasPositionSet = position !== defaultPosition.join(',');
20086
20595
  if (!hasPositionSet && !state.query) {
20087
20596
  var places = uiState.places,
20088
- uiStateWithoutPlaces = _objectWithoutProperties(uiState, _excluded2$5);
20597
+ uiStateWithoutPlaces = _objectWithoutProperties(uiState, _excluded2$6);
20089
20598
  return uiStateWithoutPlaces;
20090
20599
  }
20091
20600
  return _objectSpread2(_objectSpread2({}, uiState), {}, {