instantsearch.js 4.78.2 → 4.79.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.
@@ -181,6 +181,9 @@ var RefinementList = /*#__PURE__*/function (_Component) {
181
181
  }, {
182
182
  key: "refineFirstValue",
183
183
  value: function refineFirstValue() {
184
+ if (this.props.searchableSelectOnSubmit === false) {
185
+ return;
186
+ }
184
187
  var firstValue = this.props.facetValues && this.props.facetValues[0];
185
188
  if (firstValue) {
186
189
  var actualValue = firstValue.value;
@@ -85,9 +85,7 @@ var connectBreadcrumb = function connectBreadcrumb(renderFn) {
85
85
  if (!results || state.hierarchicalFacets.length === 0) {
86
86
  return [];
87
87
  }
88
- var _state$hierarchicalFa = _slicedToArray(state.hierarchicalFacets, 1),
89
- facetName = _state$hierarchicalFa[0].name;
90
- var facetValues = results.getFacetValues(facetName, {});
88
+ var facetValues = results.getFacetValues(hierarchicalFacetName, {});
91
89
  var facetItems = facetValues && !Array.isArray(facetValues) && facetValues.data ? facetValues.data : [];
92
90
  var items = transformItems(shiftItemsValues(prepareItems(facetItems)), {
93
91
  results: results
@@ -157,9 +157,11 @@ var connectInfiniteHits = exports.default = function connectInfiniteHits(renderF
157
157
  state: normalizeState(state)
158
158
  }) || {};
159
159
  var banner = results === null || results === void 0 ? void 0 : (_results$renderingCon = results.renderingContent) === null || _results$renderingCon === void 0 ? void 0 : (_results$renderingCon2 = _results$renderingCon.widgets) === null || _results$renderingCon2 === void 0 ? void 0 : (_results$renderingCon3 = _results$renderingCon2.banners) === null || _results$renderingCon3 === void 0 ? void 0 : _results$renderingCon3[0];
160
- if (!results) {
160
+ if (!showPrevious) {
161
161
  showPrevious = getShowPrevious(helper);
162
162
  showMore = getShowMore(helper);
163
+ }
164
+ if (!sendEvent) {
163
165
  sendEvent = (0, _utils.createSendEventForHits)({
164
166
  instantSearchInstance: instantSearchInstance,
165
167
  helper: helper,
@@ -170,6 +172,8 @@ var connectInfiniteHits = exports.default = function connectInfiniteHits(renderF
170
172
  widgetType: this.$$type,
171
173
  instantSearchInstance: instantSearchInstance
172
174
  });
175
+ }
176
+ if (!results) {
173
177
  isFirstPage = state.page === undefined || getFirstReceivedPage(state, cachedHits) === 0;
174
178
  } else {
175
179
  var _state$disjunctiveFac, _state$hierarchicalFa;
@@ -81,6 +81,8 @@ var InstantSearch = /*#__PURE__*/function (_EventEmitter) {
81
81
  _defineProperty(_assertThisInitialized(_this), "_searchStalledTimer", void 0);
82
82
  _defineProperty(_assertThisInitialized(_this), "_initialUiState", void 0);
83
83
  _defineProperty(_assertThisInitialized(_this), "_initialResults", void 0);
84
+ _defineProperty(_assertThisInitialized(_this), "_manuallyResetScheduleSearch", false);
85
+ _defineProperty(_assertThisInitialized(_this), "_resetScheduleSearch", void 0);
84
86
  _defineProperty(_assertThisInitialized(_this), "_createURL", void 0);
85
87
  _defineProperty(_assertThisInitialized(_this), "_searchFunction", void 0);
86
88
  _defineProperty(_assertThisInitialized(_this), "_mainHelperSearch", void 0);
@@ -489,14 +491,25 @@ var InstantSearch = /*#__PURE__*/function (_EventEmitter) {
489
491
  // because we already have the results to render. This skips the initial
490
492
  // network request on the browser on `start`.
491
493
  this.scheduleSearch = (0, _utils.defer)(_utils.noop);
492
- // We also skip the initial network request when widgets are dynamically
493
- // added in the first tick (that's the case in all the framework-based flavors).
494
- // When we add a widget to `index`, it calls `scheduleSearch`. We can rely
495
- // on our `defer` util to restore the original `scheduleSearch` value once
496
- // widgets are added to hook back to the regular lifecycle.
497
- (0, _utils.defer)(function () {
498
- _this3.scheduleSearch = originalScheduleSearch;
499
- })();
494
+ if (this._manuallyResetScheduleSearch) {
495
+ // If `_manuallyResetScheduleSearch` is passed, it means that we don't
496
+ // want to rely on a single `defer` to reset the `scheduleSearch`.
497
+ // Instead, the consumer will call `_resetScheduleSearch` to restore
498
+ // the original `scheduleSearch` function.
499
+ // This happens in the React flavour after rendering.
500
+ this._resetScheduleSearch = function () {
501
+ _this3.scheduleSearch = originalScheduleSearch;
502
+ };
503
+ } else {
504
+ // We also skip the initial network request when widgets are dynamically
505
+ // added in the first tick (that's the case in all the framework-based flavors).
506
+ // When we add a widget to `index`, it calls `scheduleSearch`. We can rely
507
+ // on our `defer` util to restore the original `scheduleSearch` value once
508
+ // widgets are added to hook back to the regular lifecycle.
509
+ (0, _utils.defer)(function () {
510
+ _this3.scheduleSearch = originalScheduleSearch;
511
+ })();
512
+ }
500
513
  }
501
514
  // We only schedule a search when widgets have been added before `start()`
502
515
  // because there are listeners that can use these results.
@@ -4,4 +4,4 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
- var _default = exports.default = '4.78.2';
7
+ var _default = exports.default = '4.79.0';
@@ -262,10 +262,14 @@ function createInsightsMiddleware() {
262
262
  var insightsClientWithLocalCredentials = insightsClient;
263
263
  if (isModernInsightsClient(insightsClient)) {
264
264
  insightsClientWithLocalCredentials = function insightsClientWithLocalCredentials(method, payload) {
265
+ var _getAppIdAndApiKey3 = (0, _utils.getAppIdAndApiKey)(instantSearchInstance.client),
266
+ _getAppIdAndApiKey4 = _slicedToArray(_getAppIdAndApiKey3, 2),
267
+ latestAppId = _getAppIdAndApiKey4[0],
268
+ latestApiKey = _getAppIdAndApiKey4[1];
265
269
  var extraParams = {
266
270
  headers: {
267
- 'X-Algolia-Application-Id': appId,
268
- 'X-Algolia-API-Key': apiKey
271
+ 'X-Algolia-Application-Id': latestAppId,
272
+ 'X-Algolia-API-Key': latestApiKey
269
273
  }
270
274
  };
271
275
 
@@ -34,7 +34,8 @@ var renderer = function renderer(_ref) {
34
34
  showMore = _ref.showMore,
35
35
  searchable = _ref.searchable,
36
36
  searchablePlaceholder = _ref.searchablePlaceholder,
37
- searchableIsAlwaysActive = _ref.searchableIsAlwaysActive;
37
+ searchableIsAlwaysActive = _ref.searchableIsAlwaysActive,
38
+ searchableSelectOnSubmit = _ref.searchableSelectOnSubmit;
38
39
  return function (_ref2, isFirstRendering) {
39
40
  var refine = _ref2.refine,
40
41
  items = _ref2.items,
@@ -74,7 +75,8 @@ var renderer = function renderer(_ref) {
74
75
  toggleShowMore: toggleShowMore,
75
76
  isShowingMore: isShowingMore,
76
77
  hasExhaustiveItems: hasExhaustiveItems,
77
- canToggleShowMore: canToggleShowMore
78
+ canToggleShowMore: canToggleShowMore,
79
+ searchableSelectOnSubmit: searchableSelectOnSubmit
78
80
  }), containerNode);
79
81
  };
80
82
  };
@@ -114,6 +116,8 @@ var refinementList = function refinementList(widgetParams) {
114
116
  searchableEscapeFacetValues = _ref3$searchableEscap === void 0 ? true : _ref3$searchableEscap,
115
117
  _ref3$searchableIsAlw = _ref3.searchableIsAlwaysActive,
116
118
  searchableIsAlwaysActive = _ref3$searchableIsAlw === void 0 ? true : _ref3$searchableIsAlw,
119
+ _ref3$searchableSelec = _ref3.searchableSelectOnSubmit,
120
+ searchableSelectOnSubmit = _ref3$searchableSelec === void 0 ? true : _ref3$searchableSelec,
117
121
  _ref3$cssClasses = _ref3.cssClasses,
118
122
  userCssClasses = _ref3$cssClasses === void 0 ? {} : _ref3$cssClasses,
119
123
  _ref3$templates = _ref3.templates,
@@ -205,6 +209,7 @@ var refinementList = function refinementList(widgetParams) {
205
209
  searchable: searchable,
206
210
  searchablePlaceholder: searchablePlaceholder,
207
211
  searchableIsAlwaysActive: searchableIsAlwaysActive,
212
+ searchableSelectOnSubmit: searchableSelectOnSubmit,
208
213
  showMore: showMore
209
214
  });
210
215
  var makeWidget = (0, _connectRefinementList.default)(specializedRenderer, function () {
@@ -5076,6 +5076,8 @@ declare class InstantSearch<TUiState extends UiState = UiState, TRouteState = TU
5076
5076
  _searchStalledTimer: any;
5077
5077
  _initialUiState: TUiState;
5078
5078
  _initialResults: InitialResults | null;
5079
+ _manuallyResetScheduleSearch: boolean;
5080
+ _resetScheduleSearch?: () => void;
5079
5081
  _createURL: CreateURL<TUiState>;
5080
5082
  _searchFunction?: InstantSearchOptions['searchFunction'];
5081
5083
  _mainHelperSearch?: AlgoliaSearchHelper['search'];
@@ -7148,6 +7150,11 @@ declare type RefinementListWidgetParams = {
7148
7150
  * In this case, the surrounding tags will always be `<mark></mark>`.
7149
7151
  */
7150
7152
  searchableEscapeFacetValues?: boolean;
7153
+ /**
7154
+ * When activated, submitting the search box will select the first item in the list.
7155
+ * @default true
7156
+ */
7157
+ searchableSelectOnSubmit?: boolean;
7151
7158
  /**
7152
7159
  * Templates to use for the widget.
7153
7160
  */
@@ -1,4 +1,4 @@
1
- /*! InstantSearch.js 4.78.2 | © Algolia, Inc. and contributors; MIT License | https://github.com/algolia/instantsearch */
1
+ /*! InstantSearch.js 4.79.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) :
@@ -6598,7 +6598,7 @@
6598
6598
 
6599
6599
  var sortAndMergeRecommendations_1 = sortAndMergeRecommendations;
6600
6600
 
6601
- var version = '3.25.0';
6601
+ var version = '3.26.0';
6602
6602
 
6603
6603
  var escapeFacetValue$4 = escapeFacetValue_1.escapeFacetValue;
6604
6604
 
@@ -7034,6 +7034,16 @@
7034
7034
  query: query,
7035
7035
  });
7036
7036
 
7037
+ var hide =
7038
+ (this.lastResults &&
7039
+ this.lastResults.index === state.index &&
7040
+ this.lastResults.renderingContent &&
7041
+ this.lastResults.renderingContent.facetOrdering &&
7042
+ this.lastResults.renderingContent.facetOrdering.values &&
7043
+ this.lastResults.renderingContent.facetOrdering.values[facet] &&
7044
+ this.lastResults.renderingContent.facetOrdering.values[facet].hide) ||
7045
+ [];
7046
+
7037
7047
  return searchForFacetValuesPromise.then(
7038
7048
  function addIsRefined(content) {
7039
7049
  self._currentNbQueries--;
@@ -7041,7 +7051,11 @@
7041
7051
 
7042
7052
  content = Array.isArray(content) ? content[0] : content;
7043
7053
 
7044
- content.facetHits.forEach(function (f) {
7054
+ content.facetHits.forEach(function (f, i) {
7055
+ if (hide.indexOf(f.value) > -1) {
7056
+ content.facetHits.splice(i, 1);
7057
+ return;
7058
+ }
7045
7059
  f.escapedValue = escapeFacetValue$4(f.value);
7046
7060
  f.isRefined = isDisjunctive
7047
7061
  ? state.isDisjunctiveFacetRefined(facet, f.escapedValue)
@@ -10280,9 +10294,11 @@
10280
10294
  state: normalizeState(state)
10281
10295
  }) || {};
10282
10296
  var banner = results === null || results === void 0 ? void 0 : (_results$renderingCon = results.renderingContent) === null || _results$renderingCon === void 0 ? void 0 : (_results$renderingCon2 = _results$renderingCon.widgets) === null || _results$renderingCon2 === void 0 ? void 0 : (_results$renderingCon3 = _results$renderingCon2.banners) === null || _results$renderingCon3 === void 0 ? void 0 : _results$renderingCon3[0];
10283
- if (!results) {
10297
+ if (!showPrevious) {
10284
10298
  showPrevious = getShowPrevious(helper);
10285
10299
  showMore = getShowMore(helper);
10300
+ }
10301
+ if (!sendEvent) {
10286
10302
  sendEvent = createSendEventForHits({
10287
10303
  instantSearchInstance: instantSearchInstance,
10288
10304
  helper: helper,
@@ -10293,6 +10309,8 @@
10293
10309
  widgetType: this.$$type,
10294
10310
  instantSearchInstance: instantSearchInstance
10295
10311
  });
10312
+ }
10313
+ if (!results) {
10296
10314
  isFirstPage = state.page === undefined || getFirstReceivedPage(state, cachedHits) === 0;
10297
10315
  } else {
10298
10316
  var _state$disjunctiveFac, _state$hierarchicalFa;
@@ -12674,9 +12692,7 @@
12674
12692
  if (!results || state.hierarchicalFacets.length === 0) {
12675
12693
  return [];
12676
12694
  }
12677
- var _state$hierarchicalFa = _slicedToArray(state.hierarchicalFacets, 1),
12678
- facetName = _state$hierarchicalFa[0].name;
12679
- var facetValues = results.getFacetValues(facetName, {});
12695
+ var facetValues = results.getFacetValues(hierarchicalFacetName, {});
12680
12696
  var facetItems = facetValues && !Array.isArray(facetValues) && facetValues.data ? facetValues.data : [];
12681
12697
  var items = transformItems(shiftItemsValues(prepareItems(facetItems)), {
12682
12698
  results: results
@@ -14306,10 +14322,14 @@
14306
14322
  var insightsClientWithLocalCredentials = insightsClient;
14307
14323
  if (isModernInsightsClient(insightsClient)) {
14308
14324
  insightsClientWithLocalCredentials = function insightsClientWithLocalCredentials(method, payload) {
14325
+ var _getAppIdAndApiKey3 = getAppIdAndApiKey(instantSearchInstance.client),
14326
+ _getAppIdAndApiKey4 = _slicedToArray(_getAppIdAndApiKey3, 2),
14327
+ latestAppId = _getAppIdAndApiKey4[0],
14328
+ latestApiKey = _getAppIdAndApiKey4[1];
14309
14329
  var extraParams = {
14310
14330
  headers: {
14311
- 'X-Algolia-Application-Id': appId,
14312
- 'X-Algolia-API-Key': apiKey
14331
+ 'X-Algolia-Application-Id': latestAppId,
14332
+ 'X-Algolia-API-Key': latestApiKey
14313
14333
  }
14314
14334
  };
14315
14335
 
@@ -16414,7 +16434,7 @@
16414
16434
  };
16415
16435
  }
16416
16436
 
16417
- var version$1 = '4.78.2';
16437
+ var version$1 = '4.79.0';
16418
16438
 
16419
16439
  var withUsage$v = createDocumentationMessageGenerator({
16420
16440
  name: 'instantsearch'
@@ -16467,6 +16487,8 @@
16467
16487
  _defineProperty(_assertThisInitialized(_this), "_searchStalledTimer", void 0);
16468
16488
  _defineProperty(_assertThisInitialized(_this), "_initialUiState", void 0);
16469
16489
  _defineProperty(_assertThisInitialized(_this), "_initialResults", void 0);
16490
+ _defineProperty(_assertThisInitialized(_this), "_manuallyResetScheduleSearch", false);
16491
+ _defineProperty(_assertThisInitialized(_this), "_resetScheduleSearch", void 0);
16470
16492
  _defineProperty(_assertThisInitialized(_this), "_createURL", void 0);
16471
16493
  _defineProperty(_assertThisInitialized(_this), "_searchFunction", void 0);
16472
16494
  _defineProperty(_assertThisInitialized(_this), "_mainHelperSearch", void 0);
@@ -16875,14 +16897,25 @@
16875
16897
  // because we already have the results to render. This skips the initial
16876
16898
  // network request on the browser on `start`.
16877
16899
  this.scheduleSearch = defer(noop);
16878
- // We also skip the initial network request when widgets are dynamically
16879
- // added in the first tick (that's the case in all the framework-based flavors).
16880
- // When we add a widget to `index`, it calls `scheduleSearch`. We can rely
16881
- // on our `defer` util to restore the original `scheduleSearch` value once
16882
- // widgets are added to hook back to the regular lifecycle.
16883
- defer(function () {
16884
- _this3.scheduleSearch = originalScheduleSearch;
16885
- })();
16900
+ if (this._manuallyResetScheduleSearch) {
16901
+ // If `_manuallyResetScheduleSearch` is passed, it means that we don't
16902
+ // want to rely on a single `defer` to reset the `scheduleSearch`.
16903
+ // Instead, the consumer will call `_resetScheduleSearch` to restore
16904
+ // the original `scheduleSearch` function.
16905
+ // This happens in the React flavour after rendering.
16906
+ this._resetScheduleSearch = function () {
16907
+ _this3.scheduleSearch = originalScheduleSearch;
16908
+ };
16909
+ } else {
16910
+ // We also skip the initial network request when widgets are dynamically
16911
+ // added in the first tick (that's the case in all the framework-based flavors).
16912
+ // When we add a widget to `index`, it calls `scheduleSearch`. We can rely
16913
+ // on our `defer` util to restore the original `scheduleSearch` value once
16914
+ // widgets are added to hook back to the regular lifecycle.
16915
+ defer(function () {
16916
+ _this3.scheduleSearch = originalScheduleSearch;
16917
+ })();
16918
+ }
16886
16919
  }
16887
16920
  // We only schedule a search when widgets have been added before `start()`
16888
16921
  // because there are listeners that can use these results.
@@ -20810,6 +20843,9 @@
20810
20843
  }, {
20811
20844
  key: "refineFirstValue",
20812
20845
  value: function refineFirstValue() {
20846
+ if (this.props.searchableSelectOnSubmit === false) {
20847
+ return;
20848
+ }
20813
20849
  var firstValue = this.props.facetValues && this.props.facetValues[0];
20814
20850
  if (firstValue) {
20815
20851
  var actualValue = firstValue.value;
@@ -24119,7 +24155,8 @@
24119
24155
  showMore = _ref.showMore,
24120
24156
  searchable = _ref.searchable,
24121
24157
  searchablePlaceholder = _ref.searchablePlaceholder,
24122
- searchableIsAlwaysActive = _ref.searchableIsAlwaysActive;
24158
+ searchableIsAlwaysActive = _ref.searchableIsAlwaysActive,
24159
+ searchableSelectOnSubmit = _ref.searchableSelectOnSubmit;
24123
24160
  return function (_ref2, isFirstRendering) {
24124
24161
  var refine = _ref2.refine,
24125
24162
  items = _ref2.items,
@@ -24159,7 +24196,8 @@
24159
24196
  toggleShowMore: toggleShowMore,
24160
24197
  isShowingMore: isShowingMore,
24161
24198
  hasExhaustiveItems: hasExhaustiveItems,
24162
- canToggleShowMore: canToggleShowMore
24199
+ canToggleShowMore: canToggleShowMore,
24200
+ searchableSelectOnSubmit: searchableSelectOnSubmit
24163
24201
  }), containerNode);
24164
24202
  };
24165
24203
  };
@@ -24199,6 +24237,8 @@
24199
24237
  searchableEscapeFacetValues = _ref3$searchableEscap === void 0 ? true : _ref3$searchableEscap,
24200
24238
  _ref3$searchableIsAlw = _ref3.searchableIsAlwaysActive,
24201
24239
  searchableIsAlwaysActive = _ref3$searchableIsAlw === void 0 ? true : _ref3$searchableIsAlw,
24240
+ _ref3$searchableSelec = _ref3.searchableSelectOnSubmit,
24241
+ searchableSelectOnSubmit = _ref3$searchableSelec === void 0 ? true : _ref3$searchableSelec,
24202
24242
  _ref3$cssClasses = _ref3.cssClasses,
24203
24243
  userCssClasses = _ref3$cssClasses === void 0 ? {} : _ref3$cssClasses,
24204
24244
  _ref3$templates = _ref3.templates,
@@ -24290,6 +24330,7 @@
24290
24330
  searchable: searchable,
24291
24331
  searchablePlaceholder: searchablePlaceholder,
24292
24332
  searchableIsAlwaysActive: searchableIsAlwaysActive,
24333
+ searchableSelectOnSubmit: searchableSelectOnSubmit,
24293
24334
  showMore: showMore
24294
24335
  });
24295
24336
  var makeWidget = connectRefinementList(specializedRenderer, function () {