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,53 +1,44 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
3
|
Object.defineProperty(exports, "__esModule", {
|
|
6
4
|
value: true
|
|
7
5
|
});
|
|
8
6
|
exports.default = void 0;
|
|
9
|
-
|
|
10
|
-
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
11
|
-
|
|
12
7
|
var _createConnector = _interopRequireDefault(require("../core/createConnector"));
|
|
13
|
-
|
|
14
8
|
var _indexUtils = require("../core/indexUtils");
|
|
15
|
-
|
|
9
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
10
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
11
|
+
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."); }
|
|
12
|
+
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); }
|
|
13
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
14
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
15
|
+
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; }
|
|
16
16
|
// A context rule must consist only of alphanumeric characters, hyphens, and underscores.
|
|
17
17
|
// See https://www.algolia.com/doc/guides/managing-results/refine-results/merchandising-and-promoting/in-depth/implementing-query-rules/#context
|
|
18
18
|
function escapeRuleContext(ruleName) {
|
|
19
19
|
return ruleName.replace(/[^a-z0-9-_]+/gi, '_');
|
|
20
20
|
}
|
|
21
|
-
|
|
22
21
|
function getWidgetRefinements(attribute, widgetKey, searchState) {
|
|
23
22
|
var widgetState = searchState[widgetKey];
|
|
24
|
-
|
|
25
23
|
switch (widgetKey) {
|
|
26
24
|
case 'range':
|
|
27
25
|
return Object.keys(widgetState[attribute]).map(function (rangeKey) {
|
|
28
26
|
return widgetState[attribute][rangeKey];
|
|
29
27
|
});
|
|
30
|
-
|
|
31
28
|
case 'refinementList':
|
|
32
29
|
return widgetState[attribute];
|
|
33
|
-
|
|
34
30
|
case 'hierarchicalMenu':
|
|
35
31
|
return [widgetState[attribute]];
|
|
36
|
-
|
|
37
32
|
case 'menu':
|
|
38
33
|
return [widgetState[attribute]];
|
|
39
|
-
|
|
40
34
|
case 'multiRange':
|
|
41
35
|
return widgetState[attribute].split(':');
|
|
42
|
-
|
|
43
36
|
case 'toggle':
|
|
44
37
|
return [widgetState[attribute]];
|
|
45
|
-
|
|
46
38
|
default:
|
|
47
39
|
return [];
|
|
48
40
|
}
|
|
49
41
|
}
|
|
50
|
-
|
|
51
42
|
function getRefinements(attribute) {
|
|
52
43
|
var searchState = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
53
44
|
var refinements = Object.keys(searchState).filter(function (widgetKey) {
|
|
@@ -60,15 +51,14 @@ function getRefinements(attribute) {
|
|
|
60
51
|
|
|
61
52
|
return refinements;
|
|
62
53
|
}
|
|
63
|
-
|
|
64
54
|
function getRuleContextsFromTrackedFilters(_ref) {
|
|
65
55
|
var searchState = _ref.searchState,
|
|
66
|
-
|
|
56
|
+
trackedFilters = _ref.trackedFilters;
|
|
67
57
|
var ruleContexts = Object.keys(trackedFilters).reduce(function (facets, facetName) {
|
|
68
58
|
var facetRefinements = getRefinements(facetName, searchState);
|
|
69
59
|
var getTrackedFacetValues = trackedFilters[facetName];
|
|
70
60
|
var trackedFacetValues = getTrackedFacetValues(facetRefinements);
|
|
71
|
-
return [].concat((
|
|
61
|
+
return [].concat(_toConsumableArray(facets), _toConsumableArray(facetRefinements.filter(function (facetRefinement) {
|
|
72
62
|
return trackedFacetValues.includes(facetRefinement);
|
|
73
63
|
}).map(function (facetValue) {
|
|
74
64
|
return escapeRuleContext("ais-".concat(facetName, "-").concat(facetValue));
|
|
@@ -76,7 +66,6 @@ function getRuleContextsFromTrackedFilters(_ref) {
|
|
|
76
66
|
}, []);
|
|
77
67
|
return ruleContexts;
|
|
78
68
|
}
|
|
79
|
-
|
|
80
69
|
var defaultProps = {
|
|
81
70
|
transformItems: function transformItems(items) {
|
|
82
71
|
return items;
|
|
@@ -86,7 +75,6 @@ var defaultProps = {
|
|
|
86
75
|
},
|
|
87
76
|
trackedFilters: {}
|
|
88
77
|
};
|
|
89
|
-
|
|
90
78
|
var _default = (0, _createConnector.default)({
|
|
91
79
|
displayName: 'AlgoliaQueryRules',
|
|
92
80
|
$$type: 'ais.queryRules',
|
|
@@ -96,16 +84,14 @@ var _default = (0, _createConnector.default)({
|
|
|
96
84
|
ais: props.contextValue,
|
|
97
85
|
multiIndexContext: props.indexContextValue
|
|
98
86
|
});
|
|
99
|
-
|
|
100
87
|
if (results === null) {
|
|
101
88
|
return {
|
|
102
89
|
items: [],
|
|
103
90
|
canRefine: false
|
|
104
91
|
};
|
|
105
92
|
}
|
|
106
|
-
|
|
107
93
|
var _results$userData = results.userData,
|
|
108
|
-
|
|
94
|
+
userData = _results$userData === void 0 ? [] : _results$userData;
|
|
109
95
|
var transformItems = props.transformItems;
|
|
110
96
|
var transformedItems = transformItems(userData);
|
|
111
97
|
return {
|
|
@@ -117,7 +103,6 @@ var _default = (0, _createConnector.default)({
|
|
|
117
103
|
if (Object.keys(props.trackedFilters).length === 0) {
|
|
118
104
|
return searchParameters;
|
|
119
105
|
}
|
|
120
|
-
|
|
121
106
|
var indexSearchState = (0, _indexUtils.hasMultipleIndices)({
|
|
122
107
|
ais: props.contextValue,
|
|
123
108
|
multiIndexContext: props.indexContextValue
|
|
@@ -130,18 +115,15 @@ var _default = (0, _createConnector.default)({
|
|
|
130
115
|
trackedFilters: props.trackedFilters
|
|
131
116
|
});
|
|
132
117
|
var initialRuleContexts = searchParameters.ruleContexts || [];
|
|
133
|
-
var nextRuleContexts = [].concat((
|
|
134
|
-
|
|
118
|
+
var nextRuleContexts = [].concat(_toConsumableArray(initialRuleContexts), _toConsumableArray(newRuleContexts));
|
|
135
119
|
if (process.env.NODE_ENV === 'development') {
|
|
136
120
|
if (nextRuleContexts.length > 10) {
|
|
137
121
|
// eslint-disable-next-line no-console
|
|
138
122
|
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.");
|
|
139
123
|
}
|
|
140
124
|
}
|
|
141
|
-
|
|
142
125
|
var ruleContexts = props.transformRuleContexts(nextRuleContexts).slice(0, 10);
|
|
143
126
|
return searchParameters.setQueryParameter('ruleContexts', ruleContexts);
|
|
144
127
|
}
|
|
145
128
|
});
|
|
146
|
-
|
|
147
129
|
exports.default = _default;
|
|
@@ -1,20 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
3
|
Object.defineProperty(exports, "__esModule", {
|
|
6
4
|
value: true
|
|
7
5
|
});
|
|
8
6
|
exports.default = void 0;
|
|
9
|
-
|
|
10
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
-
|
|
12
7
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
13
|
-
|
|
14
8
|
var _createConnector = _interopRequireDefault(require("../core/createConnector"));
|
|
15
|
-
|
|
16
9
|
var _indexUtils = require("../core/indexUtils");
|
|
17
|
-
|
|
10
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
+
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); }
|
|
12
|
+
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; }
|
|
13
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
14
|
+
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); }
|
|
18
15
|
/**
|
|
19
16
|
* connectRange connector provides the logic to create connected
|
|
20
17
|
* components that will give the ability for a user to refine results using
|
|
@@ -36,16 +33,14 @@ var _indexUtils = require("../core/indexUtils");
|
|
|
36
33
|
* @providedPropType {number} max - the maximum value available.
|
|
37
34
|
* @providedPropType {number} precision - Number of digits after decimal point to use.
|
|
38
35
|
*/
|
|
36
|
+
|
|
39
37
|
function getId(props) {
|
|
40
38
|
return props.attribute;
|
|
41
39
|
}
|
|
42
|
-
|
|
43
40
|
var namespace = 'range';
|
|
44
|
-
|
|
45
41
|
function getCurrentRange(boundaries, stats, precision) {
|
|
46
42
|
var pow = Math.pow(10, precision);
|
|
47
43
|
var min;
|
|
48
|
-
|
|
49
44
|
if (typeof boundaries.min === 'number' && isFinite(boundaries.min)) {
|
|
50
45
|
min = boundaries.min;
|
|
51
46
|
} else if (typeof stats.min === 'number' && isFinite(stats.min)) {
|
|
@@ -53,9 +48,7 @@ function getCurrentRange(boundaries, stats, precision) {
|
|
|
53
48
|
} else {
|
|
54
49
|
min = undefined;
|
|
55
50
|
}
|
|
56
|
-
|
|
57
51
|
var max;
|
|
58
|
-
|
|
59
52
|
if (typeof boundaries.max === 'number' && isFinite(boundaries.max)) {
|
|
60
53
|
max = boundaries.max;
|
|
61
54
|
} else if (typeof stats.max === 'number' && isFinite(stats.max)) {
|
|
@@ -63,31 +56,24 @@ function getCurrentRange(boundaries, stats, precision) {
|
|
|
63
56
|
} else {
|
|
64
57
|
max = undefined;
|
|
65
58
|
}
|
|
66
|
-
|
|
67
59
|
return {
|
|
68
60
|
min: min !== undefined ? Math.floor(min * pow) / pow : min,
|
|
69
61
|
max: max !== undefined ? Math.ceil(max * pow) / pow : max
|
|
70
62
|
};
|
|
71
63
|
}
|
|
72
|
-
|
|
73
64
|
function getCurrentRefinement(props, searchState, currentRange, context) {
|
|
74
65
|
var _getCurrentRefinement = (0, _indexUtils.getCurrentRefinementValue)(props, searchState, context, "".concat(namespace, ".").concat(getId(props)), {}),
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
66
|
+
min = _getCurrentRefinement.min,
|
|
67
|
+
max = _getCurrentRefinement.max;
|
|
78
68
|
var isFloatPrecision = Boolean(props.precision);
|
|
79
69
|
var nextMin = min;
|
|
80
|
-
|
|
81
70
|
if (typeof nextMin === 'string') {
|
|
82
71
|
nextMin = isFloatPrecision ? parseFloat(nextMin) : parseInt(nextMin, 10);
|
|
83
72
|
}
|
|
84
|
-
|
|
85
73
|
var nextMax = max;
|
|
86
|
-
|
|
87
74
|
if (typeof nextMax === 'string') {
|
|
88
75
|
nextMax = isFloatPrecision ? parseFloat(nextMax) : parseInt(nextMax, 10);
|
|
89
76
|
}
|
|
90
|
-
|
|
91
77
|
var refinement = {
|
|
92
78
|
min: nextMin,
|
|
93
79
|
max: nextMax
|
|
@@ -96,36 +82,28 @@ function getCurrentRefinement(props, searchState, currentRange, context) {
|
|
|
96
82
|
var hasMaxBound = props.max !== undefined;
|
|
97
83
|
var hasMinRefinment = refinement.min !== undefined;
|
|
98
84
|
var hasMaxRefinment = refinement.max !== undefined;
|
|
99
|
-
|
|
100
85
|
if (hasMinBound && hasMinRefinment && refinement.min < currentRange.min) {
|
|
101
86
|
throw Error("You can't provide min value lower than range.");
|
|
102
87
|
}
|
|
103
|
-
|
|
104
88
|
if (hasMaxBound && hasMaxRefinment && refinement.max > currentRange.max) {
|
|
105
89
|
throw Error("You can't provide max value greater than range.");
|
|
106
90
|
}
|
|
107
|
-
|
|
108
91
|
if (hasMinBound && !hasMinRefinment) {
|
|
109
92
|
refinement.min = currentRange.min;
|
|
110
93
|
}
|
|
111
|
-
|
|
112
94
|
if (hasMaxBound && !hasMaxRefinment) {
|
|
113
95
|
refinement.max = currentRange.max;
|
|
114
96
|
}
|
|
115
|
-
|
|
116
97
|
return refinement;
|
|
117
98
|
}
|
|
118
|
-
|
|
119
99
|
function getCurrentRefinementWithRange(refinement, range) {
|
|
120
100
|
return {
|
|
121
101
|
min: refinement.min !== undefined ? refinement.min : range.min,
|
|
122
102
|
max: refinement.max !== undefined ? refinement.max : range.max
|
|
123
103
|
};
|
|
124
104
|
}
|
|
125
|
-
|
|
126
105
|
function nextValueForRefinement(hasBound, isReset, range, value) {
|
|
127
106
|
var next;
|
|
128
|
-
|
|
129
107
|
if (!hasBound && range === value) {
|
|
130
108
|
next = undefined;
|
|
131
109
|
} else if (hasBound && isReset) {
|
|
@@ -133,47 +111,39 @@ function nextValueForRefinement(hasBound, isReset, range, value) {
|
|
|
133
111
|
} else {
|
|
134
112
|
next = value;
|
|
135
113
|
}
|
|
136
|
-
|
|
137
114
|
return next;
|
|
138
115
|
}
|
|
139
|
-
|
|
140
116
|
function _refine(props, searchState, nextRefinement, currentRange, context) {
|
|
141
117
|
var nextMin = nextRefinement.min,
|
|
142
|
-
|
|
118
|
+
nextMax = nextRefinement.max;
|
|
143
119
|
var currentMinRange = currentRange.min,
|
|
144
|
-
|
|
120
|
+
currentMaxRange = currentRange.max;
|
|
145
121
|
var isMinReset = nextMin === undefined || nextMin === '';
|
|
146
122
|
var isMaxReset = nextMax === undefined || nextMax === '';
|
|
147
123
|
var nextMinAsNumber = !isMinReset ? parseFloat(nextMin) : undefined;
|
|
148
124
|
var nextMaxAsNumber = !isMaxReset ? parseFloat(nextMax) : undefined;
|
|
149
125
|
var isNextMinValid = isMinReset || isFinite(nextMinAsNumber);
|
|
150
126
|
var isNextMaxValid = isMaxReset || isFinite(nextMaxAsNumber);
|
|
151
|
-
|
|
152
127
|
if (!isNextMinValid || !isNextMaxValid) {
|
|
153
128
|
throw Error("You can't provide non finite values to the range connector.");
|
|
154
129
|
}
|
|
155
|
-
|
|
156
130
|
if (nextMinAsNumber < currentMinRange) {
|
|
157
131
|
throw Error("You can't provide min value lower than range.");
|
|
158
132
|
}
|
|
159
|
-
|
|
160
133
|
if (nextMaxAsNumber > currentMaxRange) {
|
|
161
134
|
throw Error("You can't provide max value greater than range.");
|
|
162
135
|
}
|
|
163
|
-
|
|
164
136
|
var id = getId(props);
|
|
165
137
|
var resetPage = true;
|
|
166
|
-
var nextValue = (
|
|
138
|
+
var nextValue = _defineProperty({}, id, {
|
|
167
139
|
min: nextValueForRefinement(props.min !== undefined, isMinReset, currentMinRange, nextMinAsNumber),
|
|
168
140
|
max: nextValueForRefinement(props.max !== undefined, isMaxReset, currentMaxRange, nextMaxAsNumber)
|
|
169
141
|
});
|
|
170
142
|
return (0, _indexUtils.refineValue)(searchState, nextValue, context, resetPage, namespace);
|
|
171
143
|
}
|
|
172
|
-
|
|
173
144
|
function _cleanUp(props, searchState, context) {
|
|
174
145
|
return (0, _indexUtils.cleanUpValue)(searchState, context, "".concat(namespace, ".").concat(getId(props)));
|
|
175
146
|
}
|
|
176
|
-
|
|
177
147
|
var _default = (0, _createConnector.default)({
|
|
178
148
|
displayName: 'AlgoliaRange',
|
|
179
149
|
$$type: 'ais.range',
|
|
@@ -195,9 +165,9 @@ var _default = (0, _createConnector.default)({
|
|
|
195
165
|
},
|
|
196
166
|
getProvidedProps: function getProvidedProps(props, searchState, searchResults) {
|
|
197
167
|
var attribute = props.attribute,
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
168
|
+
precision = props.precision,
|
|
169
|
+
minBound = props.min,
|
|
170
|
+
maxBound = props.max;
|
|
201
171
|
var results = (0, _indexUtils.getResults)(searchResults, {
|
|
202
172
|
ais: props.contextValue,
|
|
203
173
|
multiIndexContext: props.indexContextValue
|
|
@@ -211,18 +181,17 @@ var _default = (0, _createConnector.default)({
|
|
|
211
181
|
count: v.count
|
|
212
182
|
};
|
|
213
183
|
});
|
|
214
|
-
|
|
215
184
|
var _getCurrentRange = getCurrentRange({
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
185
|
+
min: minBound,
|
|
186
|
+
max: maxBound
|
|
187
|
+
}, stats, precision),
|
|
188
|
+
rangeMin = _getCurrentRange.min,
|
|
189
|
+
rangeMax = _getCurrentRange.max;
|
|
190
|
+
|
|
191
|
+
// The searchState is not always in sync with the helper state. For example
|
|
221
192
|
// when we set boundaries on the first render the searchState don't have
|
|
222
193
|
// the correct refinement. If this behavior change in the upcoming version
|
|
223
194
|
// we could store the range inside the searchState instead of rely on `this`.
|
|
224
|
-
|
|
225
|
-
|
|
226
195
|
this._currentRange = {
|
|
227
196
|
min: rangeMin,
|
|
228
197
|
max: rangeMax
|
|
@@ -254,46 +223,37 @@ var _default = (0, _createConnector.default)({
|
|
|
254
223
|
},
|
|
255
224
|
getSearchParameters: function getSearchParameters(params, props, searchState) {
|
|
256
225
|
var attribute = props.attribute;
|
|
257
|
-
|
|
258
226
|
var _getCurrentRefinement2 = getCurrentRefinement(props, searchState, this._currentRange, {
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
227
|
+
ais: props.contextValue,
|
|
228
|
+
multiIndexContext: props.indexContextValue
|
|
229
|
+
}),
|
|
230
|
+
min = _getCurrentRefinement2.min,
|
|
231
|
+
max = _getCurrentRefinement2.max;
|
|
265
232
|
params = params.addDisjunctiveFacet(attribute);
|
|
266
|
-
|
|
267
233
|
if (min !== undefined) {
|
|
268
234
|
params = params.addNumericRefinement(attribute, '>=', min);
|
|
269
235
|
}
|
|
270
|
-
|
|
271
236
|
if (max !== undefined) {
|
|
272
237
|
params = params.addNumericRefinement(attribute, '<=', max);
|
|
273
238
|
}
|
|
274
|
-
|
|
275
239
|
return params;
|
|
276
240
|
},
|
|
277
241
|
getMetadata: function getMetadata(props, searchState) {
|
|
278
242
|
var _this = this;
|
|
279
|
-
|
|
280
243
|
var _this$_currentRange = this._currentRange,
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
244
|
+
minRange = _this$_currentRange.min,
|
|
245
|
+
maxRange = _this$_currentRange.max;
|
|
284
246
|
var _getCurrentRefinement3 = getCurrentRefinement(props, searchState, this._currentRange, {
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
247
|
+
ais: props.contextValue,
|
|
248
|
+
multiIndexContext: props.indexContextValue
|
|
249
|
+
}),
|
|
250
|
+
minValue = _getCurrentRefinement3.min,
|
|
251
|
+
maxValue = _getCurrentRefinement3.max;
|
|
291
252
|
var items = [];
|
|
292
253
|
var hasMin = minValue !== undefined;
|
|
293
254
|
var hasMax = maxValue !== undefined;
|
|
294
255
|
var shouldDisplayMinLabel = hasMin && minValue !== minRange;
|
|
295
256
|
var shouldDisplayMaxLabel = hasMax && maxValue !== maxRange;
|
|
296
|
-
|
|
297
257
|
if (shouldDisplayMinLabel || shouldDisplayMaxLabel) {
|
|
298
258
|
var fragments = [hasMin ? "".concat(minValue, " <= ") : '', props.attribute, hasMax ? " <= ".concat(maxValue) : ''];
|
|
299
259
|
items.push({
|
|
@@ -314,7 +274,6 @@ var _default = (0, _createConnector.default)({
|
|
|
314
274
|
})
|
|
315
275
|
});
|
|
316
276
|
}
|
|
317
|
-
|
|
318
277
|
return {
|
|
319
278
|
id: getId(props),
|
|
320
279
|
index: (0, _indexUtils.getIndexId)({
|
|
@@ -325,5 +284,4 @@ var _default = (0, _createConnector.default)({
|
|
|
325
284
|
};
|
|
326
285
|
}
|
|
327
286
|
});
|
|
328
|
-
|
|
329
287
|
exports.default = _default;
|
|
@@ -1,42 +1,32 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
3
|
Object.defineProperty(exports, "__esModule", {
|
|
6
4
|
value: true
|
|
7
5
|
});
|
|
8
6
|
exports.default = void 0;
|
|
9
|
-
|
|
10
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
-
|
|
12
7
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
13
|
-
|
|
14
8
|
var _createConnector = _interopRequireDefault(require("../core/createConnector"));
|
|
15
|
-
|
|
16
9
|
var _indexUtils = require("../core/indexUtils");
|
|
17
|
-
|
|
18
10
|
var _utils = require("../core/utils");
|
|
19
|
-
|
|
11
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
12
|
+
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); }
|
|
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); }
|
|
20
16
|
var namespace = 'refinementList';
|
|
21
|
-
|
|
22
17
|
function getId(props) {
|
|
23
18
|
return props.attribute;
|
|
24
19
|
}
|
|
25
|
-
|
|
26
20
|
function getCurrentRefinement(props, searchState, context) {
|
|
27
21
|
var currentRefinement = (0, _indexUtils.getCurrentRefinementValue)(props, searchState, context, "".concat(namespace, ".").concat(getId(props)), []);
|
|
28
|
-
|
|
29
22
|
if (typeof currentRefinement !== 'string') {
|
|
30
23
|
return currentRefinement;
|
|
31
24
|
}
|
|
32
|
-
|
|
33
25
|
if (currentRefinement) {
|
|
34
26
|
return [currentRefinement];
|
|
35
27
|
}
|
|
36
|
-
|
|
37
28
|
return [];
|
|
38
29
|
}
|
|
39
|
-
|
|
40
30
|
function getValue(value, props, searchState, context) {
|
|
41
31
|
var currentRefinement = getCurrentRefinement(props, searchState, context);
|
|
42
32
|
var isAnewValue = currentRefinement.indexOf(value) === -1;
|
|
@@ -44,31 +34,27 @@ function getValue(value, props, searchState, context) {
|
|
|
44
34
|
: currentRefinement.filter(function (selectedValue) {
|
|
45
35
|
return selectedValue !== value;
|
|
46
36
|
}); // cannot use .splice(), it mutates
|
|
47
|
-
|
|
48
37
|
return nextRefinement;
|
|
49
38
|
}
|
|
50
|
-
|
|
51
39
|
function getLimit(_ref) {
|
|
52
40
|
var showMore = _ref.showMore,
|
|
53
|
-
|
|
54
|
-
|
|
41
|
+
limit = _ref.limit,
|
|
42
|
+
showMoreLimit = _ref.showMoreLimit;
|
|
55
43
|
return showMore ? showMoreLimit : limit;
|
|
56
44
|
}
|
|
57
|
-
|
|
58
45
|
function _refine(props, searchState, nextRefinement, context) {
|
|
59
|
-
var id = getId(props);
|
|
46
|
+
var id = getId(props);
|
|
47
|
+
// Setting the value to an empty string ensures that it is persisted in
|
|
60
48
|
// the URL as an empty value.
|
|
61
49
|
// This is necessary in the case where `defaultRefinement` contains one
|
|
62
50
|
// item and we try to deselect it. `nextSelected` would be an empty array,
|
|
63
51
|
// which would not be persisted to the URL.
|
|
64
52
|
// {foo: ['bar']} => "foo[0]=bar"
|
|
65
53
|
// {foo: []} => ""
|
|
66
|
-
|
|
67
|
-
var nextValue = (0, _defineProperty2.default)({}, id, nextRefinement.length > 0 ? nextRefinement : '');
|
|
54
|
+
var nextValue = _defineProperty({}, id, nextRefinement.length > 0 ? nextRefinement : '');
|
|
68
55
|
var resetPage = true;
|
|
69
56
|
return (0, _indexUtils.refineValue)(searchState, nextValue, context, resetPage, namespace);
|
|
70
57
|
}
|
|
71
|
-
|
|
72
58
|
function _cleanUp(props, searchState, context) {
|
|
73
59
|
return (0, _indexUtils.cleanUpValue)(searchState, context, "".concat(namespace, ".").concat(getId(props)));
|
|
74
60
|
}
|
|
@@ -96,9 +82,7 @@ function _cleanUp(props, searchState, context) {
|
|
|
96
82
|
* @providedPropType {boolean} canRefine - a boolean that says whether you can refine
|
|
97
83
|
*/
|
|
98
84
|
|
|
99
|
-
|
|
100
85
|
var sortBy = ['isRefined', 'count:desc', 'name:asc'];
|
|
101
|
-
|
|
102
86
|
var _default = (0, _createConnector.default)({
|
|
103
87
|
displayName: 'AlgoliaRefinementList',
|
|
104
88
|
$$type: 'ais.refinementList',
|
|
@@ -123,20 +107,20 @@ var _default = (0, _createConnector.default)({
|
|
|
123
107
|
},
|
|
124
108
|
getProvidedProps: function getProvidedProps(props, searchState, searchResults, metadata, searchForFacetValuesResults) {
|
|
125
109
|
var attribute = props.attribute,
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
110
|
+
searchable = props.searchable,
|
|
111
|
+
indexContextValue = props.indexContextValue,
|
|
112
|
+
facetOrdering = props.facetOrdering;
|
|
129
113
|
var results = (0, _indexUtils.getResults)(searchResults, {
|
|
130
114
|
ais: props.contextValue,
|
|
131
115
|
multiIndexContext: props.indexContextValue
|
|
132
116
|
});
|
|
133
117
|
var canRefine = Boolean(results) && Boolean(results.getFacetByName(attribute));
|
|
134
|
-
var isFromSearch = Boolean(searchForFacetValuesResults && searchForFacetValuesResults[attribute] && searchForFacetValuesResults.query !== '');
|
|
118
|
+
var isFromSearch = Boolean(searchForFacetValuesResults && searchForFacetValuesResults[attribute] && searchForFacetValuesResults.query !== '');
|
|
135
119
|
|
|
120
|
+
// Search For Facet Values is not available with derived helper (used for multi index search)
|
|
136
121
|
if (searchable && indexContextValue) {
|
|
137
122
|
throw new Error('react-instantsearch: searching in *List is not available when used inside a' + ' multi index context');
|
|
138
123
|
}
|
|
139
|
-
|
|
140
124
|
if (!canRefine) {
|
|
141
125
|
return {
|
|
142
126
|
items: [],
|
|
@@ -149,7 +133,6 @@ var _default = (0, _createConnector.default)({
|
|
|
149
133
|
searchable: searchable
|
|
150
134
|
};
|
|
151
135
|
}
|
|
152
|
-
|
|
153
136
|
var items = isFromSearch ? searchForFacetValuesResults[attribute].map(function (v) {
|
|
154
137
|
return {
|
|
155
138
|
label: v.value,
|
|
@@ -212,7 +195,7 @@ var _default = (0, _createConnector.default)({
|
|
|
212
195
|
},
|
|
213
196
|
getSearchParameters: function getSearchParameters(searchParameters, props, searchState) {
|
|
214
197
|
var attribute = props.attribute,
|
|
215
|
-
|
|
198
|
+
operator = props.operator;
|
|
216
199
|
var addKey = operator === 'and' ? 'addFacet' : 'addDisjunctiveFacet';
|
|
217
200
|
var addRefinementKey = "".concat(addKey, "Refinement");
|
|
218
201
|
searchParameters = searchParameters.setQueryParameters({
|
|
@@ -257,5 +240,4 @@ var _default = (0, _createConnector.default)({
|
|
|
257
240
|
};
|
|
258
241
|
}
|
|
259
242
|
});
|
|
260
|
-
|
|
261
243
|
exports.default = _default;
|
|
@@ -1,28 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
3
|
Object.defineProperty(exports, "__esModule", {
|
|
6
4
|
value: true
|
|
7
5
|
});
|
|
8
6
|
exports.default = void 0;
|
|
9
|
-
|
|
10
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
-
|
|
12
7
|
var _createConnector = _interopRequireDefault(require("../core/createConnector"));
|
|
13
|
-
|
|
14
8
|
var _indexUtils = require("../core/indexUtils");
|
|
15
|
-
|
|
9
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
10
|
+
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); }
|
|
11
|
+
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; }
|
|
12
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
13
|
+
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); }
|
|
16
14
|
function getId() {
|
|
17
15
|
return 'relevancyStrictness';
|
|
18
16
|
}
|
|
19
|
-
|
|
20
17
|
function getCurrentRefinement(props, searchState, context) {
|
|
21
18
|
var id = getId();
|
|
22
19
|
var currentRefinement = (0, _indexUtils.getCurrentRefinementValue)(props, searchState, context, id);
|
|
23
20
|
return currentRefinement;
|
|
24
21
|
}
|
|
25
|
-
|
|
26
22
|
var _default = (0, _createConnector.default)({
|
|
27
23
|
displayName: 'AlgoliaRelevantSort',
|
|
28
24
|
$$type: 'ais.relevantSort',
|
|
@@ -31,14 +27,12 @@ var _default = (0, _createConnector.default)({
|
|
|
31
27
|
ais: props.contextValue,
|
|
32
28
|
multiIndexContext: props.indexContextValue
|
|
33
29
|
});
|
|
34
|
-
|
|
35
30
|
if (!results) {
|
|
36
31
|
return {
|
|
37
32
|
isVirtualReplica: false,
|
|
38
33
|
isRelevantSorted: false
|
|
39
34
|
};
|
|
40
35
|
}
|
|
41
|
-
|
|
42
36
|
return {
|
|
43
37
|
isVirtualReplica: results.appliedRelevancyStrictness !== undefined,
|
|
44
38
|
isRelevantSorted: results.appliedRelevancyStrictness !== undefined && results.appliedRelevancyStrictness > 0
|
|
@@ -51,7 +45,7 @@ var _default = (0, _createConnector.default)({
|
|
|
51
45
|
}));
|
|
52
46
|
},
|
|
53
47
|
refine: function refine(props, searchState, nextRefinement) {
|
|
54
|
-
var nextValue = (
|
|
48
|
+
var nextValue = _defineProperty({}, getId(), nextRefinement);
|
|
55
49
|
var resetPage = true;
|
|
56
50
|
return (0, _indexUtils.refineValue)(searchState, nextValue, {
|
|
57
51
|
ais: props.contextValue,
|
|
@@ -59,5 +53,4 @@ var _default = (0, _createConnector.default)({
|
|
|
59
53
|
}, resetPage);
|
|
60
54
|
}
|
|
61
55
|
});
|
|
62
|
-
|
|
63
56
|
exports.default = _default;
|