react-instantsearch-core 6.38.1 → 6.38.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.
Files changed (100) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +9 -1
  3. package/dist/cjs/connectors/connectAutoComplete.js +14 -33
  4. package/dist/cjs/connectors/connectBreadcrumb.js +9 -22
  5. package/dist/cjs/connectors/connectConfigure.js +17 -26
  6. package/dist/cjs/connectors/connectConfigureRelatedItems.js +20 -33
  7. package/dist/cjs/connectors/connectCurrentRefinements.js +6 -13
  8. package/dist/cjs/connectors/connectDynamicWidgets.js +2 -13
  9. package/dist/cjs/connectors/connectGeoSearch.js +15 -34
  10. package/dist/cjs/connectors/connectHierarchicalMenu.js +22 -48
  11. package/dist/cjs/connectors/connectHighlight.js +8 -14
  12. package/dist/cjs/connectors/connectHitInsights.js +8 -20
  13. package/dist/cjs/connectors/connectHits.js +2 -11
  14. package/dist/cjs/connectors/connectHitsPerPage.js +8 -18
  15. package/dist/cjs/connectors/connectInfiniteHits.js +25 -43
  16. package/dist/cjs/connectors/connectMenu.js +14 -33
  17. package/dist/cjs/connectors/connectNumericMenu.js +24 -49
  18. package/dist/cjs/connectors/connectPagination.js +7 -17
  19. package/dist/cjs/connectors/connectPoweredBy.js +1 -5
  20. package/dist/cjs/connectors/connectQueryRules.js +11 -29
  21. package/dist/cjs/connectors/connectRange.js +33 -75
  22. package/dist/cjs/connectors/connectRefinementList.js +16 -34
  23. package/dist/cjs/connectors/connectRelevantSort.js +6 -13
  24. package/dist/cjs/connectors/connectScrollTo.js +6 -14
  25. package/dist/cjs/connectors/connectSearchBox.js +7 -17
  26. package/dist/cjs/connectors/connectSortBy.js +8 -18
  27. package/dist/cjs/connectors/connectStateResults.js +1 -6
  28. package/dist/cjs/connectors/connectStats.js +2 -8
  29. package/dist/cjs/connectors/connectToggleRefinement.js +14 -29
  30. package/dist/cjs/connectors/connectVoiceSearch.js +7 -24
  31. package/dist/cjs/core/context.js +3 -7
  32. package/dist/cjs/core/createConnector.js +60 -114
  33. package/dist/cjs/core/createInstantSearchManager.d.js +1 -0
  34. package/dist/cjs/core/createInstantSearchManager.js +67 -116
  35. package/dist/cjs/core/createStore.js +0 -1
  36. package/dist/cjs/core/createWidgetsManager.js +4 -7
  37. package/dist/cjs/core/highlight.js +11 -20
  38. package/dist/cjs/core/indexUtils.js +34 -77
  39. package/dist/cjs/core/metadata.js +7 -15
  40. package/dist/cjs/core/translatable.js +19 -46
  41. package/dist/cjs/core/utils.js +14 -52
  42. package/dist/cjs/core/version.js +1 -1
  43. package/dist/cjs/index.js +9 -44
  44. package/dist/cjs/types/index.js +0 -2
  45. package/dist/cjs/widgets/Configure.js +1 -5
  46. package/dist/cjs/widgets/ConfigureRelatedItems.js +1 -8
  47. package/dist/cjs/widgets/DynamicWidgets.js +12 -33
  48. package/dist/cjs/widgets/Index.js +26 -52
  49. package/dist/cjs/widgets/InstantSearch.js +28 -67
  50. package/dist/cjs/widgets/QueryRuleContext.js +1 -5
  51. package/dist/es/connectors/connectAutoComplete.js +11 -25
  52. package/dist/es/connectors/connectBreadcrumb.js +7 -13
  53. package/dist/es/connectors/connectConfigure.js +13 -22
  54. package/dist/es/connectors/connectConfigureRelatedItems.js +17 -25
  55. package/dist/es/connectors/connectCurrentRefinements.js +5 -7
  56. package/dist/es/connectors/connectDynamicWidgets.js +1 -6
  57. package/dist/es/connectors/connectGeoSearch.js +14 -27
  58. package/dist/es/connectors/connectHierarchicalMenu.js +19 -38
  59. package/dist/es/connectors/connectHighlight.js +7 -9
  60. package/dist/es/connectors/connectHitInsights.js +7 -14
  61. package/dist/es/connectors/connectHits.js +2 -5
  62. package/dist/es/connectors/connectHitsPerPage.js +5 -12
  63. package/dist/es/connectors/connectInfiniteHits.js +21 -31
  64. package/dist/es/connectors/connectMenu.js +12 -25
  65. package/dist/es/connectors/connectNumericMenu.js +22 -40
  66. package/dist/es/connectors/connectPagination.js +5 -12
  67. package/dist/es/connectors/connectPoweredBy.js +1 -1
  68. package/dist/es/connectors/connectQueryRules.js +9 -20
  69. package/dist/es/connectors/connectRange.js +31 -68
  70. package/dist/es/connectors/connectRefinementList.js +14 -24
  71. package/dist/es/connectors/connectRelevantSort.js +7 -8
  72. package/dist/es/connectors/connectScrollTo.js +6 -7
  73. package/dist/es/connectors/connectSearchBox.js +5 -11
  74. package/dist/es/connectors/connectSortBy.js +5 -12
  75. package/dist/es/connectors/connectStateResults.js +1 -1
  76. package/dist/es/connectors/connectStats.js +2 -3
  77. package/dist/es/connectors/connectToggleRefinement.js +12 -22
  78. package/dist/es/connectors/connectVoiceSearch.js +4 -16
  79. package/dist/es/core/context.js +3 -5
  80. package/dist/es/core/createConnector.js +33 -86
  81. package/dist/es/core/createInstantSearchManager.d.js +0 -0
  82. package/dist/es/core/createInstantSearchManager.js +59 -100
  83. package/dist/es/core/createWidgetsManager.js +4 -5
  84. package/dist/es/core/highlight.js +11 -17
  85. package/dist/es/core/indexUtils.js +27 -62
  86. package/dist/es/core/metadata.js +6 -8
  87. package/dist/es/core/translatable.js +13 -29
  88. package/dist/es/core/utils.js +12 -29
  89. package/dist/es/core/version.js +1 -1
  90. package/dist/es/index.js +39 -6
  91. package/dist/es/widgets/Configure.js +1 -0
  92. package/dist/es/widgets/ConfigureRelatedItems.js +0 -2
  93. package/dist/es/widgets/DynamicWidgets.js +9 -18
  94. package/dist/es/widgets/Index.js +13 -31
  95. package/dist/es/widgets/InstantSearch.js +13 -42
  96. package/dist/umd/ReactInstantSearchCore.js +507 -1078
  97. package/dist/umd/ReactInstantSearchCore.js.map +1 -1
  98. package/dist/umd/ReactInstantSearchCore.min.js +2 -2
  99. package/dist/umd/ReactInstantSearchCore.min.js.map +1 -1
  100. package/package.json +7 -5
@@ -1,36 +1,38 @@
1
- import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
2
- import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
3
- import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
1
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
4
2
  var _excluded = ["page"];
3
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
4
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
5
+ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
6
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
7
+ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
8
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
9
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
10
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
11
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
12
+ 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; }
13
+ 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; }
5
14
  import isEqual from 'react-fast-compare';
6
15
  import createConnector from "../core/createConnector.js";
7
16
  import { getCurrentRefinementValue, refineValue, getResults } from "../core/indexUtils.js";
8
17
  import { addAbsolutePositions, addQueryID } from "../core/utils.js";
9
-
10
18
  function getId() {
11
19
  return 'page';
12
20
  }
13
-
14
21
  function getCurrentRefinement(props, searchState, context) {
15
22
  var id = getId();
16
23
  var page = 1;
17
24
  var currentRefinement = getCurrentRefinementValue(props, searchState, context, id, page);
18
-
19
25
  if (typeof currentRefinement === 'string') {
20
26
  return parseInt(currentRefinement, 10);
21
27
  }
22
-
23
28
  return currentRefinement;
24
29
  }
25
-
26
30
  function getStateWithoutPage(state) {
27
31
  var _ref = state || {},
28
- page = _ref.page,
29
- rest = _objectWithoutProperties(_ref, _excluded);
30
-
32
+ page = _ref.page,
33
+ rest = _objectWithoutProperties(_ref, _excluded);
31
34
  return rest;
32
35
  }
33
-
34
36
  function getInMemoryCache() {
35
37
  var cachedHits = undefined;
36
38
  var cachedState = undefined;
@@ -41,13 +43,12 @@ function getInMemoryCache() {
41
43
  },
42
44
  write: function write(_ref3) {
43
45
  var state = _ref3.state,
44
- hits = _ref3.hits;
46
+ hits = _ref3.hits;
45
47
  cachedState = getStateWithoutPage(state);
46
48
  cachedHits = hits;
47
49
  }
48
50
  };
49
51
  }
50
-
51
52
  function extractHitsFromCachedHits(cachedHits) {
52
53
  return Object.keys(cachedHits).map(Number).sort(function (a, b) {
53
54
  return a - b;
@@ -55,6 +56,7 @@ function extractHitsFromCachedHits(cachedHits) {
55
56
  return acc.concat(cachedHits[page]);
56
57
  }, []);
57
58
  }
59
+
58
60
  /**
59
61
  * InfiniteHits connector provides the logic to create connected
60
62
  * components that will render an continuous list of results retrieved from
@@ -65,19 +67,15 @@ function extractHitsFromCachedHits(cachedHits) {
65
67
  * @providedPropType {boolean} hasMore - indicates if there are more pages to load
66
68
  * @providedPropType {function} refine - call to load more results
67
69
  */
68
-
69
-
70
70
  export default createConnector({
71
71
  displayName: 'AlgoliaInfiniteHits',
72
72
  $$type: 'ais.infiniteHits',
73
73
  getProvidedProps: function getProvidedProps(props, searchState, searchResults) {
74
74
  var _this = this;
75
-
76
75
  var results = getResults(searchResults, {
77
76
  ais: props.contextValue,
78
77
  multiIndexContext: props.indexContextValue
79
78
  });
80
-
81
79
  if (!results) {
82
80
  return {
83
81
  hits: [],
@@ -88,12 +86,11 @@ export default createConnector({
88
86
  refineNext: function refineNext() {}
89
87
  };
90
88
  }
91
-
92
89
  var page = results.page,
93
- hits = results.hits,
94
- hitsPerPage = results.hitsPerPage,
95
- nbPages = results.nbPages,
96
- state = results._state;
90
+ hits = results.hits,
91
+ hitsPerPage = results.hitsPerPage,
92
+ nbPages = results.nbPages,
93
+ state = results._state;
97
94
  this._cache = props.cache ? props.cache : this._cache || getInMemoryCache();
98
95
  var cachedHits = this._cache.read({
99
96
  state: state
@@ -101,31 +98,26 @@ export default createConnector({
101
98
  var hitsWithPositions = addAbsolutePositions(hits, hitsPerPage, page);
102
99
  var hitsWithPositionsAndQueryID = addQueryID(hitsWithPositions, results.queryID);
103
100
  cachedHits[page] = hitsWithPositionsAndQueryID;
104
-
105
101
  this._cache.write({
106
102
  state: state,
107
103
  hits: cachedHits
108
104
  });
105
+
109
106
  /*
110
107
  Math.min() and Math.max() returns Infinity or -Infinity when no argument is given.
111
108
  But there is always something in this point because of `cachedHits[page]`.
112
109
  */
113
-
114
-
115
110
  var firstReceivedPage = Math.min.apply(Math, _toConsumableArray(Object.keys(cachedHits).map(Number)));
116
111
  var lastReceivedPage = Math.max.apply(Math, _toConsumableArray(Object.keys(cachedHits).map(Number)));
117
112
  var hasPrevious = firstReceivedPage > 0;
118
113
  var lastPageIndex = nbPages - 1;
119
114
  var hasMore = lastReceivedPage < lastPageIndex;
120
-
121
115
  var refinePrevious = function refinePrevious(event) {
122
116
  return _this.refine(event, firstReceivedPage - 1);
123
117
  };
124
-
125
118
  var refineNext = function refineNext(event) {
126
119
  return _this.refine(event, lastReceivedPage + 1);
127
120
  };
128
-
129
121
  return {
130
122
  hits: extractHitsFromCachedHits(cachedHits),
131
123
  hasPrevious: hasPrevious,
@@ -144,9 +136,7 @@ export default createConnector({
144
136
  },
145
137
  refine: function refine(props, searchState, event, index) {
146
138
  var id = getId();
147
-
148
139
  var nextValue = _defineProperty({}, id, index + 1);
149
-
150
140
  var resetPage = false;
151
141
  return refineValue(searchState, nextValue, {
152
142
  ais: props.contextValue,
@@ -1,50 +1,43 @@
1
- import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
1
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
2
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
3
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
4
+ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
2
5
  import PropTypes from 'prop-types';
3
6
  import createConnector from "../core/createConnector.js";
4
7
  import { getIndexId, cleanUpValue, refineValue, getCurrentRefinementValue, getResults } from "../core/indexUtils.js";
5
8
  import { unescapeFacetValue } from "../core/utils.js";
6
9
  var namespace = 'menu';
7
-
8
10
  function getId(props) {
9
11
  return props.attribute;
10
12
  }
11
-
12
13
  function getCurrentRefinement(props, searchState, context) {
13
14
  var currentRefinement = getCurrentRefinementValue(props, searchState, context, "".concat(namespace, ".").concat(getId(props)), null);
14
-
15
15
  if (currentRefinement === '') {
16
16
  return null;
17
17
  }
18
-
19
18
  return currentRefinement;
20
19
  }
21
-
22
20
  function getValue(value, props, searchState, context) {
23
21
  var currentRefinement = getCurrentRefinement(props, searchState, context);
24
22
  return value === currentRefinement ? '' : value;
25
23
  }
26
-
27
24
  function getLimit(_ref) {
28
25
  var showMore = _ref.showMore,
29
- limit = _ref.limit,
30
- showMoreLimit = _ref.showMoreLimit;
26
+ limit = _ref.limit,
27
+ showMoreLimit = _ref.showMoreLimit;
31
28
  return showMore ? showMoreLimit : limit;
32
29
  }
33
-
34
30
  function _refine(props, searchState, nextRefinement, context) {
35
31
  var id = getId(props);
36
-
37
32
  var nextValue = _defineProperty({}, id, nextRefinement ? nextRefinement : '');
38
-
39
33
  var resetPage = true;
40
34
  return refineValue(searchState, nextValue, context, resetPage, namespace);
41
35
  }
42
-
43
36
  function _cleanUp(props, searchState, context) {
44
37
  return cleanUpValue(searchState, context, "".concat(namespace, ".").concat(getId(props)));
45
38
  }
46
-
47
39
  var defaultSortBy = ['count:desc', 'name:asc'];
40
+
48
41
  /**
49
42
  * connectMenu connector provides the logic to build a widget that will
50
43
  * give the user the ability to choose a single value for a specific facet.
@@ -65,7 +58,6 @@ var defaultSortBy = ['count:desc', 'name:asc'];
65
58
  * @providedPropType {function} searchForItems - a function to toggle a search inside items values
66
59
  * @providedPropType {boolean} isFromSearch - a boolean that says if the `items` props contains facet values from the global search or from the search inside items.
67
60
  */
68
-
69
61
  export default createConnector({
70
62
  displayName: 'AlgoliaMenu',
71
63
  $$type: 'ais.menu',
@@ -87,20 +79,20 @@ export default createConnector({
87
79
  },
88
80
  getProvidedProps: function getProvidedProps(props, searchState, searchResults, meta, searchForFacetValuesResults) {
89
81
  var attribute = props.attribute,
90
- searchable = props.searchable,
91
- indexContextValue = props.indexContextValue,
92
- facetOrdering = props.facetOrdering;
82
+ searchable = props.searchable,
83
+ indexContextValue = props.indexContextValue,
84
+ facetOrdering = props.facetOrdering;
93
85
  var results = getResults(searchResults, {
94
86
  ais: props.contextValue,
95
87
  multiIndexContext: props.indexContextValue
96
88
  });
97
89
  var canRefine = Boolean(results) && Boolean(results.getFacetByName(attribute));
98
- var isFromSearch = Boolean(searchForFacetValuesResults && searchForFacetValuesResults[attribute] && searchForFacetValuesResults.query !== ''); // Search For Facet Values is not available with derived helper (used for multi index search)
90
+ var isFromSearch = Boolean(searchForFacetValuesResults && searchForFacetValuesResults[attribute] && searchForFacetValuesResults.query !== '');
99
91
 
92
+ // Search For Facet Values is not available with derived helper (used for multi index search)
100
93
  if (searchable && indexContextValue) {
101
94
  throw new Error('react-instantsearch: searching in *List is not available when used inside a' + ' multi index context');
102
95
  }
103
-
104
96
  if (!canRefine) {
105
97
  return {
106
98
  items: [],
@@ -113,9 +105,7 @@ export default createConnector({
113
105
  canRefine: canRefine
114
106
  };
115
107
  }
116
-
117
108
  var items;
118
-
119
109
  if (isFromSearch) {
120
110
  items = searchForFacetValuesResults[attribute].map(function (v) {
121
111
  return {
@@ -149,7 +139,6 @@ export default createConnector({
149
139
  };
150
140
  });
151
141
  }
152
-
153
142
  var transformedItems = props.transformItems ? props.transformItems(items) : items;
154
143
  return {
155
144
  items: transformedItems.slice(0, getLimit(props)),
@@ -191,11 +180,9 @@ export default createConnector({
191
180
  ais: props.contextValue,
192
181
  multiIndexContext: props.indexContextValue
193
182
  });
194
-
195
183
  if (currentRefinement !== null) {
196
184
  searchParameters = searchParameters.addDisjunctiveFacetRefinement(attribute, currentRefinement);
197
185
  }
198
-
199
186
  return searchParameters;
200
187
  },
201
188
  getMetadata: function getMetadata(props, searchState) {
@@ -1,20 +1,25 @@
1
- import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
2
- import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
1
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
2
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
3
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
4
+ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
5
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
6
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
7
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
8
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
9
+ function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
10
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
3
11
  import PropTypes from 'prop-types';
4
12
  import createConnector from "../core/createConnector.js";
5
13
  import { find } from "../core/utils.js";
6
14
  import { cleanUpValue, refineValue, getCurrentRefinementValue, getResults, getIndexId } from "../core/indexUtils.js";
7
-
8
15
  function stringifyItem(item) {
9
16
  if (typeof item.start === 'undefined' && typeof item.end === 'undefined') {
10
17
  return '';
11
18
  }
12
-
13
19
  var start = typeof item.start !== 'undefined' ? item.start : '';
14
20
  var end = typeof item.end !== 'undefined' ? item.end : '';
15
21
  return "".concat(start, ":").concat(end);
16
22
  }
17
-
18
23
  function parseItem(value) {
19
24
  if (value.length === 0) {
20
25
  return {
@@ -22,42 +27,33 @@ function parseItem(value) {
22
27
  end: null
23
28
  };
24
29
  }
25
-
26
30
  var _value$split = value.split(':'),
27
- _value$split2 = _slicedToArray(_value$split, 2),
28
- startStr = _value$split2[0],
29
- endStr = _value$split2[1];
30
-
31
+ _value$split2 = _slicedToArray(_value$split, 2),
32
+ startStr = _value$split2[0],
33
+ endStr = _value$split2[1];
31
34
  return {
32
35
  start: startStr.length > 0 ? parseFloat(startStr) : null,
33
36
  end: endStr.length > 0 ? parseFloat(endStr) : null
34
37
  };
35
38
  }
36
-
37
39
  var namespace = 'multiRange';
38
-
39
40
  function getId(props) {
40
41
  return props.attribute;
41
42
  }
42
-
43
43
  function getCurrentRefinement(props, searchState, context) {
44
44
  return getCurrentRefinementValue(props, searchState, context, "".concat(namespace, ".").concat(getId(props)), '', function (currentRefinement) {
45
45
  if (currentRefinement === '') {
46
46
  return '';
47
47
  }
48
-
49
48
  return currentRefinement;
50
49
  });
51
50
  }
52
-
53
51
  function isRefinementsRangeIncludesInsideItemRange(stats, start, end) {
54
52
  return stats.min >= start && stats.min <= end || stats.max >= start && stats.max <= end;
55
53
  }
56
-
57
54
  function isItemRangeIncludedInsideRefinementsRange(stats, start, end) {
58
55
  return start >= stats.min && start <= stats.max || end >= stats.min && end <= stats.max;
59
56
  }
60
-
61
57
  function itemHasRefinement(attribute, results, value) {
62
58
  var stats = results.getFacetByName(attribute) ? results.getFacetStats(attribute) : null;
63
59
  var range = value.split(':');
@@ -65,17 +61,15 @@ function itemHasRefinement(attribute, results, value) {
65
61
  var end = Number(range[1]) === 0 || value === '' ? Number.POSITIVE_INFINITY : Number(range[1]);
66
62
  return !(Boolean(stats) && (isRefinementsRangeIncludesInsideItemRange(stats, start, end) || isItemRangeIncludedInsideRefinementsRange(stats, start, end)));
67
63
  }
68
-
69
64
  function _refine(props, searchState, nextRefinement, context) {
70
65
  var nextValue = _defineProperty({}, getId(props, searchState), nextRefinement);
71
-
72
66
  var resetPage = true;
73
67
  return refineValue(searchState, nextValue, context, resetPage, namespace);
74
68
  }
75
-
76
69
  function _cleanUp(props, searchState, context) {
77
70
  return cleanUpValue(searchState, context, "".concat(namespace, ".").concat(getId(props)));
78
71
  }
72
+
79
73
  /**
80
74
  * connectNumericMenu connector provides the logic to build a widget that will
81
75
  * give the user the ability to select a range value for a numeric attribute.
@@ -92,8 +86,6 @@ function _cleanUp(props, searchState, context) {
92
86
  * @providedPropType {string} currentRefinement - the refinement currently applied. follow the shape of a `string` with a pattern of `'{start}:{end}'` which corresponds to the current selected item. For instance, when the selected item is `{start: 10, end: 20}`, the searchState of the widget is `'10:20'`. When `start` isn't defined, the searchState of the widget is `':{end}'`, and the same way around when `end` isn't defined. However, when neither `start` nor `end` are defined, the searchState is an empty string.
93
87
  * @providedPropType {array.<{isRefined: boolean, label: string, value: string, isRefined: boolean, noRefinement: boolean}>} items - the list of ranges the NumericMenu can display.
94
88
  */
95
-
96
-
97
89
  export default createConnector({
98
90
  displayName: 'AlgoliaNumericMenu',
99
91
  $$type: 'ais.numericMenu',
@@ -130,7 +122,6 @@ export default createConnector({
130
122
  var refinedItem = find(items, function (item) {
131
123
  return item.isRefined === true;
132
124
  });
133
-
134
125
  if (!items.some(function (item) {
135
126
  return item.value === '';
136
127
  })) {
@@ -141,7 +132,6 @@ export default createConnector({
141
132
  label: 'All'
142
133
  });
143
134
  }
144
-
145
135
  var transformedItems = props.transformItems ? props.transformItems(items) : items;
146
136
  return {
147
137
  items: transformedItems,
@@ -165,24 +155,19 @@ export default createConnector({
165
155
  },
166
156
  getSearchParameters: function getSearchParameters(searchParameters, props, searchState) {
167
157
  var attribute = props.attribute;
168
-
169
158
  var _parseItem = parseItem(getCurrentRefinement(props, searchState, {
170
- ais: props.contextValue,
171
- multiIndexContext: props.indexContextValue
172
- })),
173
- start = _parseItem.start,
174
- end = _parseItem.end;
175
-
159
+ ais: props.contextValue,
160
+ multiIndexContext: props.indexContextValue
161
+ })),
162
+ start = _parseItem.start,
163
+ end = _parseItem.end;
176
164
  searchParameters = searchParameters.addDisjunctiveFacet(attribute);
177
-
178
165
  if (typeof start === 'number') {
179
166
  searchParameters = searchParameters.addNumericRefinement(attribute, '>=', start);
180
167
  }
181
-
182
168
  if (typeof end === 'number') {
183
169
  searchParameters = searchParameters.addNumericRefinement(attribute, '<=', end);
184
170
  }
185
-
186
171
  return searchParameters;
187
172
  },
188
173
  getMetadata: function getMetadata(props, searchState) {
@@ -196,13 +181,11 @@ export default createConnector({
196
181
  ais: props.contextValue,
197
182
  multiIndexContext: props.indexContextValue
198
183
  });
199
-
200
184
  if (value !== '') {
201
185
  var _find = find(props.items, function (item) {
202
- return stringifyItem(item) === value;
203
- }),
204
- label = _find.label;
205
-
186
+ return stringifyItem(item) === value;
187
+ }),
188
+ label = _find.label;
206
189
  items.push({
207
190
  label: "".concat(props.attribute, ": ").concat(label),
208
191
  attribute: props.attribute,
@@ -215,7 +198,6 @@ export default createConnector({
215
198
  }
216
199
  });
217
200
  }
218
-
219
201
  return {
220
202
  id: id,
221
203
  index: index,
@@ -1,31 +1,28 @@
1
- import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
1
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
2
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
3
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
4
+ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
2
5
  import createConnector from "../core/createConnector.js";
3
6
  import { cleanUpValue, refineValue, getCurrentRefinementValue, getResults } from "../core/indexUtils.js";
4
-
5
7
  function getId() {
6
8
  return 'page';
7
9
  }
8
-
9
10
  function getCurrentRefinement(props, searchState, context) {
10
11
  var id = getId();
11
12
  var page = 1;
12
13
  var currentRefinement = getCurrentRefinementValue(props, searchState, context, id, page);
13
-
14
14
  if (typeof currentRefinement === 'string') {
15
15
  return parseInt(currentRefinement, 10);
16
16
  }
17
-
18
17
  return currentRefinement;
19
18
  }
20
-
21
19
  function _refine(props, searchState, nextPage, context) {
22
20
  var id = getId();
23
-
24
21
  var nextValue = _defineProperty({}, id, nextPage);
25
-
26
22
  var resetPage = false;
27
23
  return refineValue(searchState, nextValue, context, resetPage);
28
24
  }
25
+
29
26
  /**
30
27
  * connectPagination connector provides the logic to build a widget that will
31
28
  * let the user displays hits corresponding to a certain page.
@@ -42,8 +39,6 @@ function _refine(props, searchState, nextPage, context) {
42
39
  * @providedPropType {number} nbPages - the total of existing pages
43
40
  * @providedPropType {number} currentRefinement - the page refinement currently applied
44
41
  */
45
-
46
-
47
42
  export default createConnector({
48
43
  displayName: 'AlgoliaPagination',
49
44
  $$type: 'ais.pagination',
@@ -52,11 +47,9 @@ export default createConnector({
52
47
  ais: props.contextValue,
53
48
  multiIndexContext: props.indexContextValue
54
49
  });
55
-
56
50
  if (!results) {
57
51
  return null;
58
52
  }
59
-
60
53
  var nbPages = results.nbPages;
61
54
  return {
62
55
  nbPages: nbPages,
@@ -1,4 +1,5 @@
1
1
  import createConnector from "../core/createConnector.js";
2
+
2
3
  /**
3
4
  * connectPoweredBy connector provides the logic to build a widget that
4
5
  * will display a link to algolia.
@@ -6,7 +7,6 @@ import createConnector from "../core/createConnector.js";
6
7
  * @kind connector
7
8
  * @providedPropType {string} url - the url to redirect to algolia
8
9
  */
9
-
10
10
  export default createConnector({
11
11
  displayName: 'AlgoliaPoweredBy',
12
12
  $$type: 'ais.poweredBy',
@@ -1,42 +1,38 @@
1
- import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
1
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
2
+ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
3
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
4
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
5
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
6
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
2
7
  import createConnector from "../core/createConnector.js";
8
+ // @ts-ignore
3
9
  import { getResults, getIndexId, hasMultipleIndices } from "../core/indexUtils.js";
4
-
5
10
  // A context rule must consist only of alphanumeric characters, hyphens, and underscores.
6
11
  // See https://www.algolia.com/doc/guides/managing-results/refine-results/merchandising-and-promoting/in-depth/implementing-query-rules/#context
7
12
  function escapeRuleContext(ruleName) {
8
13
  return ruleName.replace(/[^a-z0-9-_]+/gi, '_');
9
14
  }
10
-
11
15
  function getWidgetRefinements(attribute, widgetKey, searchState) {
12
16
  var widgetState = searchState[widgetKey];
13
-
14
17
  switch (widgetKey) {
15
18
  case 'range':
16
19
  return Object.keys(widgetState[attribute]).map(function (rangeKey) {
17
20
  return widgetState[attribute][rangeKey];
18
21
  });
19
-
20
22
  case 'refinementList':
21
23
  return widgetState[attribute];
22
-
23
24
  case 'hierarchicalMenu':
24
25
  return [widgetState[attribute]];
25
-
26
26
  case 'menu':
27
27
  return [widgetState[attribute]];
28
-
29
28
  case 'multiRange':
30
29
  return widgetState[attribute].split(':');
31
-
32
30
  case 'toggle':
33
31
  return [widgetState[attribute]];
34
-
35
32
  default:
36
33
  return [];
37
34
  }
38
35
  }
39
-
40
36
  function getRefinements(attribute) {
41
37
  var searchState = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
42
38
  var refinements = Object.keys(searchState).filter(function (widgetKey) {
@@ -49,10 +45,9 @@ function getRefinements(attribute) {
49
45
 
50
46
  return refinements;
51
47
  }
52
-
53
48
  function getRuleContextsFromTrackedFilters(_ref) {
54
49
  var searchState = _ref.searchState,
55
- trackedFilters = _ref.trackedFilters;
50
+ trackedFilters = _ref.trackedFilters;
56
51
  var ruleContexts = Object.keys(trackedFilters).reduce(function (facets, facetName) {
57
52
  var facetRefinements = getRefinements(facetName, searchState);
58
53
  var getTrackedFacetValues = trackedFilters[facetName];
@@ -65,7 +60,6 @@ function getRuleContextsFromTrackedFilters(_ref) {
65
60
  }, []);
66
61
  return ruleContexts;
67
62
  }
68
-
69
63
  var defaultProps = {
70
64
  transformItems: function transformItems(items) {
71
65
  return items;
@@ -84,16 +78,14 @@ export default createConnector({
84
78
  ais: props.contextValue,
85
79
  multiIndexContext: props.indexContextValue
86
80
  });
87
-
88
81
  if (results === null) {
89
82
  return {
90
83
  items: [],
91
84
  canRefine: false
92
85
  };
93
86
  }
94
-
95
87
  var _results$userData = results.userData,
96
- userData = _results$userData === void 0 ? [] : _results$userData;
88
+ userData = _results$userData === void 0 ? [] : _results$userData;
97
89
  var transformItems = props.transformItems;
98
90
  var transformedItems = transformItems(userData);
99
91
  return {
@@ -105,7 +97,6 @@ export default createConnector({
105
97
  if (Object.keys(props.trackedFilters).length === 0) {
106
98
  return searchParameters;
107
99
  }
108
-
109
100
  var indexSearchState = hasMultipleIndices({
110
101
  ais: props.contextValue,
111
102
  multiIndexContext: props.indexContextValue
@@ -119,14 +110,12 @@ export default createConnector({
119
110
  });
120
111
  var initialRuleContexts = searchParameters.ruleContexts || [];
121
112
  var nextRuleContexts = [].concat(_toConsumableArray(initialRuleContexts), _toConsumableArray(newRuleContexts));
122
-
123
113
  if (process.env.NODE_ENV === 'development') {
124
114
  if (nextRuleContexts.length > 10) {
125
115
  // eslint-disable-next-line no-console
126
116
  console.warn("The maximum number of `ruleContexts` is 10. They have been sliced to that limit.\nConsider using `transformRuleContexts` to minimize the number of rules sent to Algolia.");
127
117
  }
128
118
  }
129
-
130
119
  var ruleContexts = props.transformRuleContexts(nextRuleContexts).slice(0, 10);
131
120
  return searchParameters.setQueryParameter('ruleContexts', ruleContexts);
132
121
  }