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.
- package/LICENSE +21 -0
- package/README.md +9 -1
- package/dist/cjs/connectors/connectAutoComplete.js +14 -33
- package/dist/cjs/connectors/connectBreadcrumb.js +9 -22
- package/dist/cjs/connectors/connectConfigure.js +17 -26
- package/dist/cjs/connectors/connectConfigureRelatedItems.js +20 -33
- package/dist/cjs/connectors/connectCurrentRefinements.js +6 -13
- package/dist/cjs/connectors/connectDynamicWidgets.js +2 -13
- package/dist/cjs/connectors/connectGeoSearch.js +15 -34
- package/dist/cjs/connectors/connectHierarchicalMenu.js +22 -48
- package/dist/cjs/connectors/connectHighlight.js +8 -14
- package/dist/cjs/connectors/connectHitInsights.js +8 -20
- package/dist/cjs/connectors/connectHits.js +2 -11
- package/dist/cjs/connectors/connectHitsPerPage.js +8 -18
- package/dist/cjs/connectors/connectInfiniteHits.js +25 -43
- package/dist/cjs/connectors/connectMenu.js +14 -33
- package/dist/cjs/connectors/connectNumericMenu.js +24 -49
- package/dist/cjs/connectors/connectPagination.js +7 -17
- package/dist/cjs/connectors/connectPoweredBy.js +1 -5
- package/dist/cjs/connectors/connectQueryRules.js +11 -29
- package/dist/cjs/connectors/connectRange.js +33 -75
- package/dist/cjs/connectors/connectRefinementList.js +16 -34
- package/dist/cjs/connectors/connectRelevantSort.js +6 -13
- package/dist/cjs/connectors/connectScrollTo.js +6 -14
- package/dist/cjs/connectors/connectSearchBox.js +7 -17
- package/dist/cjs/connectors/connectSortBy.js +8 -18
- package/dist/cjs/connectors/connectStateResults.js +1 -6
- package/dist/cjs/connectors/connectStats.js +2 -8
- package/dist/cjs/connectors/connectToggleRefinement.js +14 -29
- package/dist/cjs/connectors/connectVoiceSearch.js +7 -24
- package/dist/cjs/core/context.js +3 -7
- package/dist/cjs/core/createConnector.js +60 -114
- package/dist/cjs/core/createInstantSearchManager.d.js +1 -0
- package/dist/cjs/core/createInstantSearchManager.js +67 -116
- package/dist/cjs/core/createStore.js +0 -1
- package/dist/cjs/core/createWidgetsManager.js +4 -7
- package/dist/cjs/core/highlight.js +11 -20
- package/dist/cjs/core/indexUtils.js +34 -77
- package/dist/cjs/core/metadata.js +7 -15
- package/dist/cjs/core/translatable.js +19 -46
- package/dist/cjs/core/utils.js +14 -52
- package/dist/cjs/core/version.js +1 -1
- package/dist/cjs/index.js +9 -44
- package/dist/cjs/types/index.js +0 -2
- package/dist/cjs/widgets/Configure.js +1 -5
- package/dist/cjs/widgets/ConfigureRelatedItems.js +1 -8
- package/dist/cjs/widgets/DynamicWidgets.js +12 -33
- package/dist/cjs/widgets/Index.js +26 -52
- package/dist/cjs/widgets/InstantSearch.js +28 -67
- package/dist/cjs/widgets/QueryRuleContext.js +1 -5
- package/dist/es/connectors/connectAutoComplete.js +11 -25
- package/dist/es/connectors/connectBreadcrumb.js +7 -13
- package/dist/es/connectors/connectConfigure.js +13 -22
- package/dist/es/connectors/connectConfigureRelatedItems.js +17 -25
- package/dist/es/connectors/connectCurrentRefinements.js +5 -7
- package/dist/es/connectors/connectDynamicWidgets.js +1 -6
- package/dist/es/connectors/connectGeoSearch.js +14 -27
- package/dist/es/connectors/connectHierarchicalMenu.js +19 -38
- package/dist/es/connectors/connectHighlight.js +7 -9
- package/dist/es/connectors/connectHitInsights.js +7 -14
- package/dist/es/connectors/connectHits.js +2 -5
- package/dist/es/connectors/connectHitsPerPage.js +5 -12
- package/dist/es/connectors/connectInfiniteHits.js +21 -31
- package/dist/es/connectors/connectMenu.js +12 -25
- package/dist/es/connectors/connectNumericMenu.js +22 -40
- package/dist/es/connectors/connectPagination.js +5 -12
- package/dist/es/connectors/connectPoweredBy.js +1 -1
- package/dist/es/connectors/connectQueryRules.js +9 -20
- package/dist/es/connectors/connectRange.js +31 -68
- package/dist/es/connectors/connectRefinementList.js +14 -24
- package/dist/es/connectors/connectRelevantSort.js +7 -8
- package/dist/es/connectors/connectScrollTo.js +6 -7
- package/dist/es/connectors/connectSearchBox.js +5 -11
- package/dist/es/connectors/connectSortBy.js +5 -12
- package/dist/es/connectors/connectStateResults.js +1 -1
- package/dist/es/connectors/connectStats.js +2 -3
- package/dist/es/connectors/connectToggleRefinement.js +12 -22
- package/dist/es/connectors/connectVoiceSearch.js +4 -16
- package/dist/es/core/context.js +3 -5
- package/dist/es/core/createConnector.js +33 -86
- package/dist/es/core/createInstantSearchManager.d.js +0 -0
- package/dist/es/core/createInstantSearchManager.js +59 -100
- package/dist/es/core/createWidgetsManager.js +4 -5
- package/dist/es/core/highlight.js +11 -17
- package/dist/es/core/indexUtils.js +27 -62
- package/dist/es/core/metadata.js +6 -8
- package/dist/es/core/translatable.js +13 -29
- package/dist/es/core/utils.js +12 -29
- package/dist/es/core/version.js +1 -1
- package/dist/es/index.js +39 -6
- package/dist/es/widgets/Configure.js +1 -0
- package/dist/es/widgets/ConfigureRelatedItems.js +0 -2
- package/dist/es/widgets/DynamicWidgets.js +9 -18
- package/dist/es/widgets/Index.js +13 -31
- package/dist/es/widgets/InstantSearch.js +13 -42
- package/dist/umd/ReactInstantSearchCore.js +507 -1078
- package/dist/umd/ReactInstantSearchCore.js.map +1 -1
- package/dist/umd/ReactInstantSearchCore.min.js +2 -2
- package/dist/umd/ReactInstantSearchCore.min.js.map +1 -1
- package/package.json +7 -5
|
@@ -1,51 +1,43 @@
|
|
|
1
|
-
|
|
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
2
|
import React, { Fragment } from 'react';
|
|
3
3
|
import { getDisplayName } from "../core/utils.js";
|
|
4
4
|
import connectDynamicWidgets from "../connectors/connectDynamicWidgets.js";
|
|
5
|
-
|
|
6
5
|
function isReactElement(element) {
|
|
7
6
|
return _typeof(element) === 'object' && element.props;
|
|
8
7
|
}
|
|
9
|
-
|
|
10
8
|
function getAttribute(element) {
|
|
11
9
|
if (!isReactElement(element)) {
|
|
12
10
|
return undefined;
|
|
13
11
|
}
|
|
14
|
-
|
|
15
12
|
if (element.props.attribute) {
|
|
16
13
|
return element.props.attribute;
|
|
17
14
|
}
|
|
18
|
-
|
|
19
15
|
if (Array.isArray(element.props.attributes)) {
|
|
20
16
|
return element.props.attributes[0];
|
|
21
17
|
}
|
|
22
|
-
|
|
23
18
|
if (element.props.children) {
|
|
24
19
|
return getAttribute(React.Children.only(element.props.children));
|
|
25
20
|
}
|
|
26
|
-
|
|
27
21
|
return undefined;
|
|
28
22
|
}
|
|
29
|
-
|
|
30
23
|
function DynamicWidgets(_ref) {
|
|
31
24
|
var children = _ref.children,
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
25
|
+
attributesToRender = _ref.attributesToRender,
|
|
26
|
+
_ref$fallbackComponen = _ref.fallbackComponent,
|
|
27
|
+
Fallback = _ref$fallbackComponen === void 0 ? function () {
|
|
28
|
+
return null;
|
|
29
|
+
} : _ref$fallbackComponen;
|
|
37
30
|
var widgets = new Map();
|
|
38
31
|
React.Children.forEach(children, function (child) {
|
|
39
32
|
var attribute = getAttribute(child);
|
|
40
|
-
|
|
41
33
|
if (!attribute) {
|
|
42
34
|
throw new Error("Could not find \"attribute\" prop for ".concat(getDisplayName(child), "."));
|
|
43
35
|
}
|
|
44
|
-
|
|
45
36
|
widgets.set(attribute, child);
|
|
46
|
-
});
|
|
47
|
-
// search state for unmounted components in place, so routing works.
|
|
37
|
+
});
|
|
48
38
|
|
|
39
|
+
// on initial render this will be empty, but React InstantSearch keeps
|
|
40
|
+
// search state for unmounted components in place, so routing works.
|
|
49
41
|
return /*#__PURE__*/React.createElement(React.Fragment, null, attributesToRender.map(function (attribute) {
|
|
50
42
|
return /*#__PURE__*/React.createElement(Fragment, {
|
|
51
43
|
key: attribute
|
|
@@ -54,7 +46,6 @@ function DynamicWidgets(_ref) {
|
|
|
54
46
|
}));
|
|
55
47
|
}));
|
|
56
48
|
}
|
|
57
|
-
|
|
58
49
|
export default connectDynamicWidgets(DynamicWidgets, {
|
|
59
50
|
$$widgetType: 'ais.dynamicWidgets'
|
|
60
51
|
});
|
package/dist/es/widgets/Index.js
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
9
|
-
|
|
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 _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); }
|
|
3
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
4
|
+
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); } }
|
|
5
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
6
|
+
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); }
|
|
7
|
+
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
10
8
|
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); }; }
|
|
11
|
-
|
|
9
|
+
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); }
|
|
10
|
+
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
12
11
|
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; } }
|
|
13
|
-
|
|
12
|
+
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
13
|
+
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; }
|
|
14
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
15
|
+
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); }
|
|
14
16
|
import React, { Component, Children } from 'react';
|
|
15
17
|
import PropTypes from 'prop-types';
|
|
16
18
|
import { InstantSearchConsumer, IndexProvider } from "../core/context.js";
|
|
17
|
-
|
|
18
19
|
function getIndexContext(props) {
|
|
19
20
|
return {
|
|
20
21
|
targetedIndex: props.indexId
|
|
21
22
|
};
|
|
22
23
|
}
|
|
23
|
-
|
|
24
24
|
/**
|
|
25
25
|
* The component that allows you to apply widgets to a dedicated index. It's
|
|
26
26
|
* useful if you want to build an interface that targets multiple indices.
|
|
@@ -53,30 +53,21 @@ function getIndexContext(props) {
|
|
|
53
53
|
*/
|
|
54
54
|
var Index = /*#__PURE__*/function (_Component) {
|
|
55
55
|
_inherits(Index, _Component);
|
|
56
|
-
|
|
57
56
|
var _super = _createSuper(Index);
|
|
58
|
-
|
|
59
57
|
function Index(props) {
|
|
60
58
|
var _this;
|
|
61
|
-
|
|
62
59
|
_classCallCheck(this, Index);
|
|
63
|
-
|
|
64
60
|
_this = _super.call(this, props);
|
|
65
|
-
|
|
66
61
|
_defineProperty(_assertThisInitialized(_this), "state", {
|
|
67
62
|
indexContext: getIndexContext(_this.props)
|
|
68
63
|
});
|
|
69
|
-
|
|
70
64
|
_defineProperty(_assertThisInitialized(_this), "unregisterWidget", void 0);
|
|
71
|
-
|
|
72
65
|
_this.props.contextValue.onSearchParameters(_this.getSearchParameters.bind(_assertThisInitialized(_this)), {
|
|
73
66
|
ais: _this.props.contextValue,
|
|
74
67
|
multiIndexContext: _this.state.indexContext
|
|
75
68
|
}, _this.props, undefined, Index.displayName);
|
|
76
|
-
|
|
77
69
|
return _this;
|
|
78
70
|
}
|
|
79
|
-
|
|
80
71
|
_createClass(Index, [{
|
|
81
72
|
key: "componentDidMount",
|
|
82
73
|
value: function componentDidMount() {
|
|
@@ -105,11 +96,9 @@ var Index = /*#__PURE__*/function (_Component) {
|
|
|
105
96
|
key: "render",
|
|
106
97
|
value: function render() {
|
|
107
98
|
var childrenCount = Children.count(this.props.children);
|
|
108
|
-
|
|
109
99
|
if (childrenCount === 0) {
|
|
110
100
|
return null;
|
|
111
101
|
}
|
|
112
|
-
|
|
113
102
|
return /*#__PURE__*/React.createElement(IndexProvider, {
|
|
114
103
|
value: this.state.indexContext
|
|
115
104
|
}, this.props.children);
|
|
@@ -122,22 +111,16 @@ var Index = /*#__PURE__*/function (_Component) {
|
|
|
122
111
|
};
|
|
123
112
|
}
|
|
124
113
|
}]);
|
|
125
|
-
|
|
126
114
|
return Index;
|
|
127
115
|
}(Component);
|
|
128
|
-
|
|
129
116
|
_defineProperty(Index, "propTypes", {
|
|
130
117
|
indexName: PropTypes.string.isRequired,
|
|
131
118
|
indexId: PropTypes.string.isRequired,
|
|
132
119
|
children: PropTypes.node
|
|
133
120
|
});
|
|
134
|
-
|
|
135
121
|
_defineProperty(Index, "displayName", 'AlgoliaIndex');
|
|
136
|
-
|
|
137
122
|
_defineProperty(Index, "$$type", 'ais.index');
|
|
138
|
-
|
|
139
123
|
_defineProperty(Index, "$$widgetType", 'ais.index');
|
|
140
|
-
|
|
141
124
|
var IndexWrapper = function IndexWrapper(props) {
|
|
142
125
|
var inferredIndexId = props.indexName;
|
|
143
126
|
return /*#__PURE__*/React.createElement(InstantSearchConsumer, null, function (contextValue) {
|
|
@@ -147,7 +130,6 @@ var IndexWrapper = function IndexWrapper(props) {
|
|
|
147
130
|
}, props));
|
|
148
131
|
});
|
|
149
132
|
};
|
|
150
|
-
|
|
151
133
|
IndexWrapper.propTypes = {
|
|
152
134
|
indexName: PropTypes.string.isRequired,
|
|
153
135
|
indexId: PropTypes.string
|
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
|
|
2
|
-
import _createClass from "@babel/runtime/helpers/esm/createClass";
|
|
3
|
-
import _assertThisInitialized from "@babel/runtime/helpers/esm/assertThisInitialized";
|
|
4
|
-
import _inherits from "@babel/runtime/helpers/esm/inherits";
|
|
5
|
-
import _possibleConstructorReturn from "@babel/runtime/helpers/esm/possibleConstructorReturn";
|
|
6
|
-
import _getPrototypeOf from "@babel/runtime/helpers/esm/getPrototypeOf";
|
|
7
|
-
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
8
|
-
|
|
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); }
|
|
9
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; }
|
|
10
|
-
|
|
11
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; }
|
|
12
|
-
|
|
4
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
5
|
+
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); } }
|
|
6
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
7
|
+
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); }
|
|
8
|
+
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
13
9
|
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); }; }
|
|
14
|
-
|
|
10
|
+
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); }
|
|
11
|
+
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
15
12
|
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; } }
|
|
16
|
-
|
|
13
|
+
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
14
|
+
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; }
|
|
15
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
16
|
+
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); }
|
|
17
17
|
import React, { Component, Children } from 'react';
|
|
18
18
|
import isEqual from 'react-fast-compare';
|
|
19
19
|
import PropTypes from 'prop-types';
|
|
20
20
|
import createInstantSearchManager from "../core/createInstantSearchManager.js";
|
|
21
21
|
import { InstantSearchProvider } from "../core/context.js";
|
|
22
22
|
import { isMetadataEnabled, injectMetadata } from "../core/metadata.js";
|
|
23
|
-
|
|
24
23
|
function isControlled(props) {
|
|
25
24
|
return Boolean(props.searchState);
|
|
26
25
|
}
|
|
26
|
+
|
|
27
27
|
/**
|
|
28
28
|
* @description
|
|
29
29
|
* `<InstantSearch>` is the root component of all React InstantSearch implementations.
|
|
@@ -62,24 +62,15 @@ function isControlled(props) {
|
|
|
62
62
|
* </InstantSearch>
|
|
63
63
|
* );
|
|
64
64
|
*/
|
|
65
|
-
|
|
66
|
-
|
|
67
65
|
var InstantSearch = /*#__PURE__*/function (_Component) {
|
|
68
66
|
_inherits(InstantSearch, _Component);
|
|
69
|
-
|
|
70
67
|
var _super = _createSuper(InstantSearch);
|
|
71
|
-
|
|
72
68
|
function InstantSearch(props) {
|
|
73
69
|
var _this;
|
|
74
|
-
|
|
75
70
|
_classCallCheck(this, InstantSearch);
|
|
76
|
-
|
|
77
71
|
_this = _super.call(this, props);
|
|
78
|
-
|
|
79
72
|
_defineProperty(_assertThisInitialized(_this), "cleanupTimerRef", null);
|
|
80
|
-
|
|
81
73
|
_defineProperty(_assertThisInitialized(_this), "isUnmounting", false);
|
|
82
|
-
|
|
83
74
|
var instantSearchManager = createInstantSearchManager({
|
|
84
75
|
indexName: _this.props.indexName,
|
|
85
76
|
searchClient: _this.props.searchClient,
|
|
@@ -104,28 +95,22 @@ var InstantSearch = /*#__PURE__*/function (_Component) {
|
|
|
104
95
|
};
|
|
105
96
|
return _this;
|
|
106
97
|
}
|
|
107
|
-
|
|
108
98
|
_createClass(InstantSearch, [{
|
|
109
99
|
key: "componentDidUpdate",
|
|
110
100
|
value: function componentDidUpdate(prevProps) {
|
|
111
101
|
var prevIsControlled = isControlled(prevProps);
|
|
112
|
-
|
|
113
102
|
if (prevIsControlled && !this.state.isControlled) {
|
|
114
103
|
throw new Error("You can't switch <InstantSearch> from being controlled to uncontrolled");
|
|
115
104
|
}
|
|
116
|
-
|
|
117
105
|
if (!prevIsControlled && this.state.isControlled) {
|
|
118
106
|
throw new Error("You can't switch <InstantSearch> from being uncontrolled to controlled");
|
|
119
107
|
}
|
|
120
|
-
|
|
121
108
|
if (this.props.refresh !== prevProps.refresh && this.props.refresh) {
|
|
122
109
|
this.state.instantSearchManager.clearCache();
|
|
123
110
|
}
|
|
124
|
-
|
|
125
111
|
if (prevProps.indexName !== this.props.indexName) {
|
|
126
112
|
this.state.instantSearchManager.updateIndex(this.props.indexName);
|
|
127
113
|
}
|
|
128
|
-
|
|
129
114
|
if (prevProps.searchClient !== this.props.searchClient) {
|
|
130
115
|
this.state.instantSearchManager.updateClient(this.props.searchClient);
|
|
131
116
|
}
|
|
@@ -137,7 +122,6 @@ var InstantSearch = /*#__PURE__*/function (_Component) {
|
|
|
137
122
|
clearTimeout(this.cleanupTimerRef);
|
|
138
123
|
this.cleanupTimerRef = null;
|
|
139
124
|
}
|
|
140
|
-
|
|
141
125
|
if (isMetadataEnabled()) {
|
|
142
126
|
injectMetadata(this.state.instantSearchManager.widgetsManager.getWidgets(), this.props.searchClient);
|
|
143
127
|
}
|
|
@@ -146,10 +130,8 @@ var InstantSearch = /*#__PURE__*/function (_Component) {
|
|
|
146
130
|
key: "componentWillUnmount",
|
|
147
131
|
value: function componentWillUnmount() {
|
|
148
132
|
var _this2 = this;
|
|
149
|
-
|
|
150
133
|
this.cleanupTimerRef = setTimeout(function () {
|
|
151
134
|
_this2.isUnmounting = true;
|
|
152
|
-
|
|
153
135
|
_this2.state.instantSearchManager.skipSearch();
|
|
154
136
|
});
|
|
155
137
|
}
|
|
@@ -164,7 +146,6 @@ var InstantSearch = /*#__PURE__*/function (_Component) {
|
|
|
164
146
|
value: function onWidgetsInternalStateUpdate(searchState) {
|
|
165
147
|
searchState = this.state.instantSearchManager.transitionState(searchState);
|
|
166
148
|
this.onSearchStateChange(searchState);
|
|
167
|
-
|
|
168
149
|
if (!this.state.isControlled) {
|
|
169
150
|
this.state.instantSearchManager.onExternalStateUpdate(searchState);
|
|
170
151
|
}
|
|
@@ -181,13 +162,10 @@ var InstantSearch = /*#__PURE__*/function (_Component) {
|
|
|
181
162
|
value: function onSearchParameters(getSearchParameters, context, props, getMetadata, displayName) {
|
|
182
163
|
if (this.props.onSearchParameters) {
|
|
183
164
|
var _searchState = this.props.searchState ? this.props.searchState : {};
|
|
184
|
-
|
|
185
165
|
this.props.onSearchParameters(getSearchParameters, context, props, _searchState);
|
|
186
166
|
}
|
|
187
|
-
|
|
188
167
|
if (this.props.widgetsCollector) {
|
|
189
168
|
var _searchState2 = this.props.searchState ? this.props.searchState : {};
|
|
190
|
-
|
|
191
169
|
this.props.widgetsCollector({
|
|
192
170
|
getSearchParameters: getSearchParameters,
|
|
193
171
|
getMetadata: getMetadata,
|
|
@@ -214,7 +192,6 @@ var InstantSearch = /*#__PURE__*/function (_Component) {
|
|
|
214
192
|
if (Children.count(this.props.children) === 0) {
|
|
215
193
|
return null;
|
|
216
194
|
}
|
|
217
|
-
|
|
218
195
|
return /*#__PURE__*/React.createElement(InstantSearchProvider, {
|
|
219
196
|
value: this.state.contextValue
|
|
220
197
|
}, this.props.children);
|
|
@@ -225,11 +202,9 @@ var InstantSearch = /*#__PURE__*/function (_Component) {
|
|
|
225
202
|
var nextIsControlled = isControlled(nextProps);
|
|
226
203
|
var previousSearchState = prevState.instantSearchManager.store.getState().widgets;
|
|
227
204
|
var nextSearchState = nextProps.searchState;
|
|
228
|
-
|
|
229
205
|
if (nextIsControlled && !isEqual(previousSearchState, nextSearchState)) {
|
|
230
206
|
prevState.instantSearchManager.onExternalStateUpdate(nextProps.searchState);
|
|
231
207
|
}
|
|
232
|
-
|
|
233
208
|
return {
|
|
234
209
|
isControlled: nextIsControlled,
|
|
235
210
|
contextValue: _objectSpread(_objectSpread({}, prevState.contextValue), {}, {
|
|
@@ -238,15 +213,12 @@ var InstantSearch = /*#__PURE__*/function (_Component) {
|
|
|
238
213
|
};
|
|
239
214
|
}
|
|
240
215
|
}]);
|
|
241
|
-
|
|
242
216
|
return InstantSearch;
|
|
243
217
|
}(Component);
|
|
244
|
-
|
|
245
218
|
_defineProperty(InstantSearch, "defaultProps", {
|
|
246
219
|
stalledSearchDelay: 200,
|
|
247
220
|
refresh: false
|
|
248
221
|
});
|
|
249
|
-
|
|
250
222
|
_defineProperty(InstantSearch, "propTypes", {
|
|
251
223
|
// @TODO: These props are currently constant.
|
|
252
224
|
indexName: PropTypes.string.isRequired,
|
|
@@ -266,5 +238,4 @@ _defineProperty(InstantSearch, "propTypes", {
|
|
|
266
238
|
children: PropTypes.node,
|
|
267
239
|
stalledSearchDelay: PropTypes.number
|
|
268
240
|
});
|
|
269
|
-
|
|
270
241
|
export default InstantSearch;
|