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,38 +1,33 @@
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 { find } from "../core/utils.js";
4
7
  import createConnector from "../core/createConnector.js";
5
8
  import { cleanUpValue, getIndexId, getResults, refineValue, getCurrentRefinementValue } from "../core/indexUtils.js";
6
-
7
9
  function getId(props) {
8
10
  return props.attribute;
9
11
  }
10
-
11
12
  var namespace = 'toggle';
12
13
  var falsyStrings = ['0', 'false', 'null', 'undefined'];
13
-
14
14
  function getCurrentRefinement(props, searchState, context) {
15
15
  var currentRefinement = getCurrentRefinementValue(props, searchState, context, "".concat(namespace, ".").concat(getId(props)), false);
16
-
17
16
  if (falsyStrings.indexOf(currentRefinement) !== -1) {
18
17
  return false;
19
18
  }
20
-
21
19
  return Boolean(currentRefinement);
22
20
  }
23
-
24
21
  function _refine(props, searchState, nextRefinement, context) {
25
22
  var id = getId(props);
26
-
27
23
  var nextValue = _defineProperty({}, id, nextRefinement ? nextRefinement : false);
28
-
29
24
  var resetPage = true;
30
25
  return refineValue(searchState, nextValue, context, resetPage, namespace);
31
26
  }
32
-
33
27
  function _cleanUp(props, searchState, context) {
34
28
  return cleanUpValue(searchState, context, "".concat(namespace, ".").concat(getId(props)));
35
29
  }
30
+
36
31
  /**
37
32
  * connectToggleRefinement connector provides the logic to build a widget that will
38
33
  * provides an on/off filtering feature based on an attribute value.
@@ -52,8 +47,6 @@ function _cleanUp(props, searchState, context) {
52
47
  * @providedPropType {function} refine - a function to toggle a refinement
53
48
  * @providedPropType {function} createURL - a function to generate a URL for the corresponding search state
54
49
  */
55
-
56
-
57
50
  export default createConnector({
58
51
  displayName: 'AlgoliaToggle',
59
52
  $$type: 'ais.toggle',
@@ -66,7 +59,7 @@ export default createConnector({
66
59
  },
67
60
  getProvidedProps: function getProvidedProps(props, searchState, searchResults) {
68
61
  var attribute = props.attribute,
69
- value = props.value;
62
+ value = props.value;
70
63
  var results = getResults(searchResults, {
71
64
  ais: props.contextValue,
72
65
  multiIndexContext: props.indexContextValue
@@ -76,13 +69,15 @@ export default createConnector({
76
69
  multiIndexContext: props.indexContextValue
77
70
  });
78
71
  var allFacetValues = results && results.getFacetByName(attribute) ? results.getFacetValues(attribute) : null;
79
- var facetValue = // Use null to always be consistent with type of the value
72
+ var facetValue =
73
+ // Use null to always be consistent with type of the value
80
74
  // count: number | null
81
75
  allFacetValues && allFacetValues.length ? find(allFacetValues, function (item) {
82
76
  return item.name === value.toString();
83
77
  }) : null;
84
78
  var facetValueCount = facetValue && facetValue.count;
85
- var allFacetValuesCount = // Use null to always be consistent with type of the value
79
+ var allFacetValuesCount =
80
+ // Use null to always be consistent with type of the value
86
81
  // count: number | null
87
82
  allFacetValues && allFacetValues.length ? allFacetValues.reduce(function (acc, item) {
88
83
  return acc + item.count;
@@ -112,22 +107,19 @@ export default createConnector({
112
107
  },
113
108
  getSearchParameters: function getSearchParameters(searchParameters, props, searchState) {
114
109
  var attribute = props.attribute,
115
- value = props.value,
116
- filter = props.filter;
110
+ value = props.value,
111
+ filter = props.filter;
117
112
  var checked = getCurrentRefinement(props, searchState, {
118
113
  ais: props.contextValue,
119
114
  multiIndexContext: props.indexContextValue
120
115
  });
121
116
  var nextSearchParameters = searchParameters.addDisjunctiveFacet(attribute);
122
-
123
117
  if (checked) {
124
118
  nextSearchParameters = nextSearchParameters.addDisjunctiveFacetRefinement(attribute, value);
125
-
126
119
  if (filter) {
127
120
  nextSearchParameters = filter(nextSearchParameters);
128
121
  }
129
122
  }
130
-
131
123
  return nextSearchParameters;
132
124
  },
133
125
  getMetadata: function getMetadata(props, searchState) {
@@ -141,7 +133,6 @@ export default createConnector({
141
133
  ais: props.contextValue,
142
134
  multiIndexContext: props.indexContextValue
143
135
  });
144
-
145
136
  if (checked) {
146
137
  items.push({
147
138
  label: props.label,
@@ -155,7 +146,6 @@ export default createConnector({
155
146
  }
156
147
  });
157
148
  }
158
-
159
149
  return {
160
150
  id: id,
161
151
  index: index,
@@ -1,46 +1,36 @@
1
- import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
2
-
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); }
3
2
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
4
-
5
3
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
6
-
4
+ 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; }
5
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
6
+ 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); }
7
7
  import PropTypes from 'prop-types';
8
8
  import createConnector from "../core/createConnector.js";
9
9
  import { cleanUpValue, refineValue, getCurrentRefinementValue, getIndexId } from "../core/indexUtils.js";
10
-
11
10
  function getId() {
12
11
  return 'query';
13
12
  }
14
-
15
13
  function getAdditionalId() {
16
14
  return 'additionalVoiceParameters';
17
15
  }
18
-
19
16
  function getCurrentRefinementQuery(props, searchState, context) {
20
17
  var id = getId();
21
18
  var currentRefinement = getCurrentRefinementValue(props, searchState, context, id, '');
22
-
23
19
  if (currentRefinement) {
24
20
  return currentRefinement;
25
21
  }
26
-
27
22
  return '';
28
23
  }
29
-
30
24
  function getCurrentRefinementAdditional(props, searchState, context) {
31
25
  var id = getAdditionalId();
32
26
  var currentRefinement = getCurrentRefinementValue(props, searchState, context, id, '');
33
-
34
27
  if (currentRefinement) {
35
28
  return currentRefinement;
36
29
  }
37
-
38
30
  return {};
39
31
  }
40
-
41
32
  function _refine(props, searchState, nextRefinement, context) {
42
33
  var _nextValue;
43
-
44
34
  var id = getId();
45
35
  var voiceParams = getAdditionalId();
46
36
  var queryLanguages = props.language ? {
@@ -57,12 +47,10 @@ function _refine(props, searchState, nextRefinement, context) {
57
47
  var resetPage = true;
58
48
  return refineValue(searchState, nextValue, context, resetPage);
59
49
  }
60
-
61
50
  function _cleanUp(props, searchState, context) {
62
51
  var interimState = cleanUpValue(searchState, context, getId());
63
52
  return cleanUpValue(interimState, context, getAdditionalId());
64
53
  }
65
-
66
54
  export default createConnector({
67
55
  displayName: 'AlgoliaVoiceSearch',
68
56
  $$type: 'ais.voiceSearch',
@@ -20,11 +20,9 @@ export var instantSearchContext = /*#__PURE__*/createContext({
20
20
  mainTargetedIndex: ''
21
21
  });
22
22
  var InstantSearchConsumer = instantSearchContext.Consumer,
23
- InstantSearchProvider = instantSearchContext.Provider;
23
+ InstantSearchProvider = instantSearchContext.Provider;
24
24
  export { InstantSearchConsumer, InstantSearchProvider };
25
-
26
25
  var _createContext = /*#__PURE__*/createContext(undefined),
27
- IndexConsumer = _createContext.Consumer,
28
- IndexProvider = _createContext.Provider;
29
-
26
+ IndexConsumer = _createContext.Consumer,
27
+ IndexProvider = _createContext.Provider;
30
28
  export { IndexConsumer, IndexProvider };
@@ -1,27 +1,27 @@
1
- import _extends from "@babel/runtime/helpers/esm/extends";
2
- import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
3
- import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
4
- import _createClass from "@babel/runtime/helpers/esm/createClass";
5
- import _assertThisInitialized from "@babel/runtime/helpers/esm/assertThisInitialized";
6
- import _inherits from "@babel/runtime/helpers/esm/inherits";
7
- import _possibleConstructorReturn from "@babel/runtime/helpers/esm/possibleConstructorReturn";
8
- import _getPrototypeOf from "@babel/runtime/helpers/esm/getPrototypeOf";
9
- import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
10
1
  var _excluded = ["contextValue"];
11
-
2
+ 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); }
3
+ function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
4
+ 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; }
5
+ 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; }
12
6
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
13
-
14
7
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
15
-
8
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
9
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
10
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
11
+ function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
12
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
16
13
  function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
17
-
14
+ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
15
+ function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
18
16
  function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
19
-
17
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
18
+ 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; }
19
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
20
+ 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); }
20
21
  import React, { Component } from 'react';
21
22
  import isEqual from 'react-fast-compare';
22
23
  import { shallowEqual, getDisplayName, removeEmptyKey } from "./utils.js";
23
24
  import { InstantSearchConsumer, IndexConsumer } from "./context.js";
24
-
25
25
  /**
26
26
  * Connectors are the HOC used to transform React components
27
27
  * into InstantSearch widgets.
@@ -36,88 +36,66 @@ export function createConnectorWithoutContext(connectorDesc) {
36
36
  if (!connectorDesc.displayName) {
37
37
  throw new Error('`createConnector` requires you to provide a `displayName` property.');
38
38
  }
39
-
40
39
  var isWidget = typeof connectorDesc.getSearchParameters === 'function' || typeof connectorDesc.getMetadata === 'function' || typeof connectorDesc.transitionState === 'function';
41
40
  return function (Composed) {
42
41
  var additionalWidgetProperties = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
43
-
44
42
  var Connector = /*#__PURE__*/function (_Component) {
45
43
  _inherits(Connector, _Component);
46
-
47
44
  var _super = _createSuper(Connector);
48
-
49
45
  function Connector(props) {
50
46
  var _this;
51
-
52
47
  _classCallCheck(this, Connector);
53
-
54
48
  _this = _super.call(this, props);
55
-
56
49
  _defineProperty(_assertThisInitialized(_this), "unsubscribe", void 0);
57
-
58
50
  _defineProperty(_assertThisInitialized(_this), "unregisterWidget", void 0);
59
-
60
51
  _defineProperty(_assertThisInitialized(_this), "cleanupTimerRef", null);
61
-
62
52
  _defineProperty(_assertThisInitialized(_this), "isUnmounting", false);
63
-
64
53
  _defineProperty(_assertThisInitialized(_this), "state", {
65
54
  providedProps: _this.getProvidedProps(_this.props)
66
55
  });
67
-
68
56
  _defineProperty(_assertThisInitialized(_this), "refine", function () {
69
57
  var _ref;
70
-
71
58
  for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
72
59
  args[_key] = arguments[_key];
73
60
  }
74
-
75
- _this.props.contextValue.onInternalStateUpdate( // refine will always be defined here because the prop is only given conditionally
61
+ _this.props.contextValue.onInternalStateUpdate(
62
+ // refine will always be defined here because the prop is only given conditionally
76
63
  (_ref = connectorDesc.refine).call.apply(_ref, [_assertThisInitialized(_this), _this.props, _this.props.contextValue.store.getState().widgets].concat(args)));
77
64
  });
78
-
79
65
  _defineProperty(_assertThisInitialized(_this), "createURL", function () {
80
66
  var _ref2;
81
-
82
67
  for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
83
68
  args[_key2] = arguments[_key2];
84
69
  }
85
-
86
- return _this.props.contextValue.createHrefForState( // refine will always be defined here because the prop is only given conditionally
70
+ return _this.props.contextValue.createHrefForState(
71
+ // refine will always be defined here because the prop is only given conditionally
87
72
  (_ref2 = connectorDesc.refine).call.apply(_ref2, [_assertThisInitialized(_this), _this.props, _this.props.contextValue.store.getState().widgets].concat(args)));
88
73
  });
89
-
90
74
  _defineProperty(_assertThisInitialized(_this), "searchForFacetValues", function () {
91
75
  var _ref3;
92
-
93
76
  for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
94
77
  args[_key3] = arguments[_key3];
95
78
  }
96
-
97
- _this.props.contextValue.onSearchForFacetValues( // searchForFacetValues will always be defined here because the prop is only given conditionally
79
+ _this.props.contextValue.onSearchForFacetValues(
80
+ // searchForFacetValues will always be defined here because the prop is only given conditionally
98
81
  (_ref3 = connectorDesc.searchForFacetValues).call.apply(_ref3, [_assertThisInitialized(_this), _this.props, _this.props.contextValue.store.getState().widgets].concat(args)));
99
82
  });
100
-
101
83
  if (connectorDesc.getSearchParameters) {
102
84
  _this.props.contextValue.onSearchParameters(connectorDesc.getSearchParameters.bind(_assertThisInitialized(_this)), {
103
85
  ais: _this.props.contextValue,
104
86
  multiIndexContext: _this.props.indexContextValue
105
87
  }, _this.props, connectorDesc.getMetadata && connectorDesc.getMetadata.bind(_assertThisInitialized(_this)), connectorDesc.displayName);
106
88
  }
107
-
108
89
  return _this;
109
90
  }
110
-
111
91
  _createClass(Connector, [{
112
92
  key: "componentDidMount",
113
93
  value: function componentDidMount() {
114
94
  var _this2 = this;
115
-
116
95
  if (this.cleanupTimerRef) {
117
96
  clearTimeout(this.cleanupTimerRef);
118
97
  this.cleanupTimerRef = null;
119
98
  }
120
-
121
99
  this.unsubscribe = this.props.contextValue.store.subscribe(function () {
122
100
  if (!_this2.isUnmounting) {
123
101
  _this2.setState({
@@ -125,7 +103,6 @@ export function createConnectorWithoutContext(connectorDesc) {
125
103
  });
126
104
  }
127
105
  });
128
-
129
106
  if (isWidget) {
130
107
  this.unregisterWidget = this.props.contextValue.widgetsManager.registerWidget(this);
131
108
  }
@@ -136,17 +113,13 @@ export function createConnectorWithoutContext(connectorDesc) {
136
113
  if (typeof connectorDesc.shouldComponentUpdate === 'function') {
137
114
  return connectorDesc.shouldComponentUpdate.call(this, this.props, nextProps, this.state, nextState);
138
115
  }
139
-
140
116
  var propsEqual = shallowEqual(this.props, nextProps);
141
-
142
117
  if (this.state.providedProps === null || nextState.providedProps === null) {
143
118
  if (this.state.providedProps === nextState.providedProps) {
144
119
  return !propsEqual;
145
120
  }
146
-
147
121
  return true;
148
122
  }
149
-
150
123
  return !propsEqual || !shallowEqual(this.state.providedProps, nextState.providedProps);
151
124
  }
152
125
  }, {
@@ -156,10 +129,8 @@ export function createConnectorWithoutContext(connectorDesc) {
156
129
  this.setState({
157
130
  providedProps: this.getProvidedProps(this.props)
158
131
  });
159
-
160
132
  if (isWidget) {
161
133
  this.props.contextValue.widgetsManager.update();
162
-
163
134
  if (typeof connectorDesc.transitionState === 'function') {
164
135
  this.props.contextValue.onSearchStateChange(connectorDesc.transitionState.call(this, this.props, this.props.contextValue.store.getState().widgets, this.props.contextValue.store.getState().widgets));
165
136
  }
@@ -170,24 +141,18 @@ export function createConnectorWithoutContext(connectorDesc) {
170
141
  key: "componentWillUnmount",
171
142
  value: function componentWillUnmount() {
172
143
  var _this3 = this;
173
-
174
144
  this.cleanupTimerRef = setTimeout(function () {
175
145
  _this3.isUnmounting = true;
176
-
177
146
  if (_this3.unsubscribe) {
178
147
  _this3.unsubscribe();
179
148
  }
180
-
181
149
  if (_this3.unregisterWidget) {
182
150
  _this3.unregisterWidget();
183
-
184
151
  if (typeof connectorDesc.cleanUp === 'function') {
185
152
  var nextState = connectorDesc.cleanUp.call(_this3, _this3.props, _this3.props.contextValue.store.getState().widgets);
186
-
187
153
  _this3.props.contextValue.store.setState(_objectSpread(_objectSpread({}, _this3.props.contextValue.store.getState()), {}, {
188
154
  widgets: nextState
189
155
  }));
190
-
191
156
  _this3.props.contextValue.onSearchStateChange(removeEmptyKey(nextState));
192
157
  }
193
158
  }
@@ -197,15 +162,14 @@ export function createConnectorWithoutContext(connectorDesc) {
197
162
  key: "getProvidedProps",
198
163
  value: function getProvidedProps(props) {
199
164
  var _this$props$contextVa = this.props.contextValue.store.getState(),
200
- widgets = _this$props$contextVa.widgets,
201
- results = _this$props$contextVa.results,
202
- resultsFacetValues = _this$props$contextVa.resultsFacetValues,
203
- searching = _this$props$contextVa.searching,
204
- searchingForFacetValues = _this$props$contextVa.searchingForFacetValues,
205
- isSearchStalled = _this$props$contextVa.isSearchStalled,
206
- metadata = _this$props$contextVa.metadata,
207
- error = _this$props$contextVa.error;
208
-
165
+ widgets = _this$props$contextVa.widgets,
166
+ results = _this$props$contextVa.results,
167
+ resultsFacetValues = _this$props$contextVa.resultsFacetValues,
168
+ searching = _this$props$contextVa.searching,
169
+ searchingForFacetValues = _this$props$contextVa.searchingForFacetValues,
170
+ isSearchStalled = _this$props$contextVa.isSearchStalled,
171
+ metadata = _this$props$contextVa.metadata,
172
+ error = _this$props$contextVa.error;
209
173
  var searchResults = {
210
174
  results: results,
211
175
  searching: searching,
@@ -213,7 +177,8 @@ export function createConnectorWithoutContext(connectorDesc) {
213
177
  isSearchStalled: isSearchStalled,
214
178
  error: error
215
179
  };
216
- return connectorDesc.getProvidedProps.call(this, props, widgets, searchResults, metadata, // @MAJOR: move this attribute on the `searchResults` it doesn't
180
+ return connectorDesc.getProvidedProps.call(this, props, widgets, searchResults, metadata,
181
+ // @MAJOR: move this attribute on the `searchResults` it doesn't
217
182
  // makes sense to have it into a separate argument. The search
218
183
  // flags are on the object why not the results?
219
184
  resultsFacetValues);
@@ -224,7 +189,6 @@ export function createConnectorWithoutContext(connectorDesc) {
224
189
  if (typeof connectorDesc.getSearchParameters === 'function') {
225
190
  return connectorDesc.getSearchParameters.call(this, searchParameters, this.props, this.props.contextValue.store.getState().widgets);
226
191
  }
227
-
228
192
  return null;
229
193
  }
230
194
  }, {
@@ -233,7 +197,6 @@ export function createConnectorWithoutContext(connectorDesc) {
233
197
  if (typeof connectorDesc.getMetadata === 'function') {
234
198
  return connectorDesc.getMetadata.call(this, this.props, nextWidgetsState);
235
199
  }
236
-
237
200
  return {};
238
201
  }
239
202
  }, {
@@ -242,22 +205,18 @@ export function createConnectorWithoutContext(connectorDesc) {
242
205
  if (typeof connectorDesc.transitionState === 'function') {
243
206
  return connectorDesc.transitionState.call(this, this.props, prevWidgetsState, nextWidgetsState);
244
207
  }
245
-
246
208
  return nextWidgetsState;
247
209
  }
248
210
  }, {
249
211
  key: "render",
250
212
  value: function render() {
251
213
  var _this$props = this.props,
252
- contextValue = _this$props.contextValue,
253
- props = _objectWithoutProperties(_this$props, _excluded);
254
-
214
+ contextValue = _this$props.contextValue,
215
+ props = _objectWithoutProperties(_this$props, _excluded);
255
216
  var providedProps = this.state.providedProps;
256
-
257
217
  if (providedProps === null) {
258
218
  return null;
259
219
  }
260
-
261
220
  var refineProps = typeof connectorDesc.refine === 'function' ? {
262
221
  refine: this.refine,
263
222
  createURL: this.createURL
@@ -268,30 +227,20 @@ export function createConnectorWithoutContext(connectorDesc) {
268
227
  return /*#__PURE__*/React.createElement(Composed, _extends({}, props, providedProps, refineProps, searchForFacetValuesProps));
269
228
  }
270
229
  }]);
271
-
272
230
  return Connector;
273
231
  }(Component);
274
-
275
232
  _defineProperty(Connector, "displayName", "".concat(connectorDesc.displayName, "(").concat(getDisplayName(Composed), ")"));
276
-
277
233
  _defineProperty(Connector, "$$type", connectorDesc.$$type);
278
-
279
234
  _defineProperty(Connector, "$$widgetType", additionalWidgetProperties.$$widgetType);
280
-
281
235
  _defineProperty(Connector, "propTypes", connectorDesc.propTypes);
282
-
283
236
  _defineProperty(Connector, "defaultProps", connectorDesc.defaultProps);
284
-
285
237
  _defineProperty(Connector, "_connectorDesc", connectorDesc);
286
-
287
238
  return Connector;
288
239
  };
289
240
  }
290
-
291
241
  var createConnectorWithContext = function createConnectorWithContext(connectorDesc) {
292
242
  return function (Composed, additionalWidgetProperties) {
293
243
  var Connector = createConnectorWithoutContext(connectorDesc)(Composed, additionalWidgetProperties);
294
-
295
244
  var ConnectorWrapper = function ConnectorWrapper(props) {
296
245
  return /*#__PURE__*/React.createElement(InstantSearchConsumer, null, function (contextValue) {
297
246
  return /*#__PURE__*/React.createElement(IndexConsumer, null, function (indexContextValue) {
@@ -302,9 +251,7 @@ var createConnectorWithContext = function createConnectorWithContext(connectorDe
302
251
  });
303
252
  });
304
253
  };
305
-
306
254
  return ConnectorWrapper;
307
255
  };
308
256
  };
309
-
310
257
  export default createConnectorWithContext;
File without changes