react-instantsearch-core 7.15.8 → 7.16.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,15 +1,17 @@
1
1
  "use strict";
2
2
 
3
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
3
4
  Object.defineProperty(exports, "__esModule", {
4
5
  value: true
5
6
  });
6
7
  exports.InstantSearch = InstantSearch;
7
- var _react = _interopRequireDefault(require("react"));
8
+ var _react = _interopRequireWildcard(require("react"));
8
9
  var _IndexContext = require("../lib/IndexContext");
9
10
  var _InstantSearchContext = require("../lib/InstantSearchContext");
10
11
  var _useInstantSearchApi = require("../lib/useInstantSearchApi");
11
12
  var _excluded = ["children"];
12
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
14
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
13
15
  function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
14
16
  function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
15
17
  function InstantSearch(_ref) {
@@ -23,5 +25,16 @@ function InstantSearch(_ref) {
23
25
  value: search
24
26
  }, /*#__PURE__*/_react.default.createElement(_IndexContext.IndexContext.Provider, {
25
27
  value: search.mainIndex
26
- }, children));
28
+ }, children, /*#__PURE__*/_react.default.createElement(ResetScheduleSearch, {
29
+ search: search
30
+ })));
31
+ }
32
+ function ResetScheduleSearch(_ref2) {
33
+ var search = _ref2.search;
34
+ (0, _react.useEffect)(function () {
35
+ if (search._resetScheduleSearch) {
36
+ search._resetScheduleSearch();
37
+ }
38
+ }, [search]);
39
+ return null;
27
40
  }
@@ -67,6 +67,10 @@ function useInstantSearchApi(props) {
67
67
  // an additional network request. (This is equivalent to monkey-patching
68
68
  // `scheduleSearch` to a noop.)
69
69
  search._initialResults = initialResults || {};
70
+ // We don't rely on the `defer` to reset the schedule search, but will call
71
+ // `search._resetScheduleSearch()` manually in the effect after children
72
+ // mount in `InstantSearch`.
73
+ search._manuallyResetScheduleSearch = true;
70
74
  }
71
75
  addAlgoliaAgents(props.searchClient, [].concat(defaultUserAgents, [serverContext && serverUserAgent, nextUserAgent(getNextVersion())]));
72
76
 
@@ -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 = '7.15.8';
7
+ var _default = exports.default = '7.16.0';
@@ -1,7 +1,7 @@
1
1
  var _excluded = ["children"];
2
2
  function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
3
3
  function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
4
- import React from 'react';
4
+ import React, { useEffect } from 'react';
5
5
  import { IndexContext } from "../lib/IndexContext.js";
6
6
  import { InstantSearchContext } from "../lib/InstantSearchContext.js";
7
7
  import { useInstantSearchApi } from "../lib/useInstantSearchApi.js";
@@ -16,5 +16,16 @@ export function InstantSearch(_ref) {
16
16
  value: search
17
17
  }, /*#__PURE__*/React.createElement(IndexContext.Provider, {
18
18
  value: search.mainIndex
19
- }, children));
19
+ }, children, /*#__PURE__*/React.createElement(ResetScheduleSearch, {
20
+ search: search
21
+ })));
22
+ }
23
+ function ResetScheduleSearch(_ref2) {
24
+ var search = _ref2.search;
25
+ useEffect(function () {
26
+ if (search._resetScheduleSearch) {
27
+ search._resetScheduleSearch();
28
+ }
29
+ }, [search]);
30
+ return null;
20
31
  }
@@ -58,6 +58,10 @@ export function useInstantSearchApi(props) {
58
58
  // an additional network request. (This is equivalent to monkey-patching
59
59
  // `scheduleSearch` to a noop.)
60
60
  search._initialResults = initialResults || {};
61
+ // We don't rely on the `defer` to reset the schedule search, but will call
62
+ // `search._resetScheduleSearch()` manually in the effect after children
63
+ // mount in `InstantSearch`.
64
+ search._manuallyResetScheduleSearch = true;
61
65
  }
62
66
  addAlgoliaAgents(props.searchClient, [].concat(defaultUserAgents, [serverContext && serverUserAgent, nextUserAgent(getNextVersion())]));
63
67
 
@@ -1,2 +1,2 @@
1
- declare const _default: "7.15.8";
1
+ declare const _default: "7.16.0";
2
2
  export default _default;
@@ -1 +1 @@
1
- export default '7.15.8';
1
+ export default '7.16.0';
@@ -7,7 +7,7 @@
7
7
 
8
8
  var React__default = 'default' in React ? React['default'] : React;
9
9
 
10
- var version = '7.15.8';
10
+ var version = '7.16.0';
11
11
 
12
12
  function _iterableToArrayLimit(r, l) {
13
13
  var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
@@ -4769,7 +4769,7 @@
4769
4769
 
4770
4770
  var sortAndMergeRecommendations_1 = sortAndMergeRecommendations;
4771
4771
 
4772
- var version$1 = '3.25.0';
4772
+ var version$1 = '3.26.0';
4773
4773
 
4774
4774
  var escapeFacetValue$3 = escapeFacetValue_1.escapeFacetValue;
4775
4775
 
@@ -5205,6 +5205,16 @@
5205
5205
  query: query,
5206
5206
  });
5207
5207
 
5208
+ var hide =
5209
+ (this.lastResults &&
5210
+ this.lastResults.index === state.index &&
5211
+ this.lastResults.renderingContent &&
5212
+ this.lastResults.renderingContent.facetOrdering &&
5213
+ this.lastResults.renderingContent.facetOrdering.values &&
5214
+ this.lastResults.renderingContent.facetOrdering.values[facet] &&
5215
+ this.lastResults.renderingContent.facetOrdering.values[facet].hide) ||
5216
+ [];
5217
+
5208
5218
  return searchForFacetValuesPromise.then(
5209
5219
  function addIsRefined(content) {
5210
5220
  self._currentNbQueries--;
@@ -5212,7 +5222,11 @@
5212
5222
 
5213
5223
  content = Array.isArray(content) ? content[0] : content;
5214
5224
 
5215
- content.facetHits.forEach(function (f) {
5225
+ content.facetHits.forEach(function (f, i) {
5226
+ if (hide.indexOf(f.value) > -1) {
5227
+ content.facetHits.splice(i, 1);
5228
+ return;
5229
+ }
5216
5230
  f.escapedValue = escapeFacetValue$3(f.value);
5217
5231
  f.isRefined = isDisjunctive
5218
5232
  ? state.isDisjunctiveFacetRefined(facet, f.escapedValue)
@@ -12881,7 +12895,7 @@
12881
12895
  };
12882
12896
  }
12883
12897
 
12884
- var version$2 = '4.78.3';
12898
+ var version$2 = '4.79.0';
12885
12899
 
12886
12900
  function _typeof$l(o) {
12887
12901
  "@babel/helpers - typeof";
@@ -13081,6 +13095,8 @@
13081
13095
  _defineProperty$i(_assertThisInitialized(_this), "_searchStalledTimer", void 0);
13082
13096
  _defineProperty$i(_assertThisInitialized(_this), "_initialUiState", void 0);
13083
13097
  _defineProperty$i(_assertThisInitialized(_this), "_initialResults", void 0);
13098
+ _defineProperty$i(_assertThisInitialized(_this), "_manuallyResetScheduleSearch", false);
13099
+ _defineProperty$i(_assertThisInitialized(_this), "_resetScheduleSearch", void 0);
13084
13100
  _defineProperty$i(_assertThisInitialized(_this), "_createURL", void 0);
13085
13101
  _defineProperty$i(_assertThisInitialized(_this), "_searchFunction", void 0);
13086
13102
  _defineProperty$i(_assertThisInitialized(_this), "_mainHelperSearch", void 0);
@@ -13473,14 +13489,25 @@
13473
13489
  // because we already have the results to render. This skips the initial
13474
13490
  // network request on the browser on `start`.
13475
13491
  this.scheduleSearch = defer(noop);
13476
- // We also skip the initial network request when widgets are dynamically
13477
- // added in the first tick (that's the case in all the framework-based flavors).
13478
- // When we add a widget to `index`, it calls `scheduleSearch`. We can rely
13479
- // on our `defer` util to restore the original `scheduleSearch` value once
13480
- // widgets are added to hook back to the regular lifecycle.
13481
- defer(function () {
13482
- _this3.scheduleSearch = originalScheduleSearch;
13483
- })();
13492
+ if (this._manuallyResetScheduleSearch) {
13493
+ // If `_manuallyResetScheduleSearch` is passed, it means that we don't
13494
+ // want to rely on a single `defer` to reset the `scheduleSearch`.
13495
+ // Instead, the consumer will call `_resetScheduleSearch` to restore
13496
+ // the original `scheduleSearch` function.
13497
+ // This happens in the React flavour after rendering.
13498
+ this._resetScheduleSearch = function () {
13499
+ _this3.scheduleSearch = originalScheduleSearch;
13500
+ };
13501
+ } else {
13502
+ // We also skip the initial network request when widgets are dynamically
13503
+ // added in the first tick (that's the case in all the framework-based flavors).
13504
+ // When we add a widget to `index`, it calls `scheduleSearch`. We can rely
13505
+ // on our `defer` util to restore the original `scheduleSearch` value once
13506
+ // widgets are added to hook back to the regular lifecycle.
13507
+ defer(function () {
13508
+ _this3.scheduleSearch = originalScheduleSearch;
13509
+ })();
13510
+ }
13484
13511
  }
13485
13512
  // We only schedule a search when widgets have been added before `start()`
13486
13513
  // because there are listeners that can use these results.
@@ -13697,6 +13724,10 @@
13697
13724
  // an additional network request. (This is equivalent to monkey-patching
13698
13725
  // `scheduleSearch` to a noop.)
13699
13726
  search._initialResults = initialResults || {};
13727
+ // We don't rely on the `defer` to reset the schedule search, but will call
13728
+ // `search._resetScheduleSearch()` manually in the effect after children
13729
+ // mount in `InstantSearch`.
13730
+ search._manuallyResetScheduleSearch = true;
13700
13731
  }
13701
13732
  addAlgoliaAgents(props.searchClient, [].concat(defaultUserAgents, [serverContext && serverUserAgent, nextUserAgent(getNextVersion())]));
13702
13733
 
@@ -13836,7 +13867,18 @@
13836
13867
  value: search
13837
13868
  }, /*#__PURE__*/React__default.createElement(IndexContext.Provider, {
13838
13869
  value: search.mainIndex
13839
- }, children));
13870
+ }, children, /*#__PURE__*/React__default.createElement(ResetScheduleSearch, {
13871
+ search: search
13872
+ })));
13873
+ }
13874
+ function ResetScheduleSearch(_ref2) {
13875
+ var search = _ref2.search;
13876
+ React.useEffect(function () {
13877
+ if (search._resetScheduleSearch) {
13878
+ search._resetScheduleSearch();
13879
+ }
13880
+ }, [search]);
13881
+ return null;
13840
13882
  }
13841
13883
 
13842
13884
  var _excluded$7 = ["children"];
@@ -14044,9 +14086,7 @@
14044
14086
  if (!results || state.hierarchicalFacets.length === 0) {
14045
14087
  return [];
14046
14088
  }
14047
- var _state$hierarchicalFa = _slicedToArray$6(state.hierarchicalFacets, 1),
14048
- facetName = _state$hierarchicalFa[0].name;
14049
- var facetValues = results.getFacetValues(facetName, {});
14089
+ var facetValues = results.getFacetValues(hierarchicalFacetName, {});
14050
14090
  var facetItems = facetValues && !Array.isArray(facetValues) && facetValues.data ? facetValues.data : [];
14051
14091
  var items = transformItems(shiftItemsValues(prepareItems(facetItems)), {
14052
14092
  results: results
@@ -16065,9 +16105,11 @@
16065
16105
  state: normalizeState(state)
16066
16106
  }) || {};
16067
16107
  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];
16068
- if (!results) {
16108
+ if (!showPrevious) {
16069
16109
  showPrevious = getShowPrevious(helper);
16070
16110
  showMore = getShowMore(helper);
16111
+ }
16112
+ if (!sendEvent) {
16071
16113
  sendEvent = createSendEventForHits({
16072
16114
  instantSearchInstance: instantSearchInstance,
16073
16115
  helper: helper,
@@ -16078,6 +16120,8 @@
16078
16120
  widgetType: this.$$type,
16079
16121
  instantSearchInstance: instantSearchInstance
16080
16122
  });
16123
+ }
16124
+ if (!results) {
16081
16125
  isFirstPage = state.page === undefined || getFirstReceivedPage(state, cachedHits) === 0;
16082
16126
  } else {
16083
16127
  var _state$disjunctiveFac, _state$hierarchicalFa;