react-instantsearch-core 6.40.4 → 7.0.1
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/README.md +70 -2
- package/dist/cjs/components/Configure.js +13 -0
- package/dist/cjs/components/DynamicWidgets.js +63 -0
- package/dist/cjs/components/Index.js +24 -0
- package/dist/cjs/components/InstantSearch.js +27 -0
- package/dist/cjs/{connectors/connectConfigure.js → components/InstantSearchSSRProvider.js} +27 -63
- package/dist/cjs/components/InstantSearchServerContext.js +12 -0
- package/dist/cjs/connectors/useBreadcrumb.js +12 -0
- package/dist/cjs/connectors/useClearRefinements.js +12 -0
- package/dist/cjs/connectors/useConfigure.js +14 -0
- package/dist/cjs/connectors/useCurrentRefinements.js +12 -0
- package/dist/cjs/connectors/useDynamicWidgets.js +22 -0
- package/dist/cjs/connectors/useGeoSearch.js +12 -0
- package/dist/cjs/connectors/useHierarchicalMenu.js +12 -0
- package/dist/cjs/connectors/useHits.js +12 -0
- package/dist/cjs/connectors/useHitsPerPage.js +12 -0
- package/dist/cjs/connectors/useInfiniteHits.js +12 -0
- package/dist/cjs/connectors/useMenu.js +12 -0
- package/dist/cjs/connectors/useNumericMenu.js +12 -0
- package/dist/cjs/connectors/usePagination.js +12 -0
- package/dist/cjs/connectors/usePoweredBy.js +21 -0
- package/dist/cjs/connectors/useQueryRules.js +12 -0
- package/dist/cjs/connectors/useRange.js +12 -0
- package/dist/cjs/connectors/useRefinementList.js +12 -0
- package/dist/cjs/connectors/useSearchBox.js +12 -0
- package/dist/cjs/connectors/useSortBy.js +12 -0
- package/dist/cjs/connectors/useStats.js +12 -0
- package/dist/cjs/connectors/useToggleRefinement.js +12 -0
- package/dist/cjs/hooks/useConnector.js +136 -0
- package/dist/cjs/hooks/useInstantSearch.js +58 -0
- package/dist/cjs/index.js +328 -320
- package/dist/cjs/lib/IndexContext.js +12 -0
- package/dist/cjs/lib/InstantSearchContext.js +12 -0
- package/dist/cjs/lib/InstantSearchSSRContext.js +12 -0
- package/dist/cjs/lib/createSearchResults.js +27 -0
- package/dist/cjs/lib/dequal.js +53 -0
- package/dist/cjs/lib/getIndexSearchResults.js +32 -0
- package/dist/cjs/lib/invariant.js +25 -0
- package/dist/cjs/lib/noop.js +8 -0
- package/dist/cjs/lib/useForceUpdate.js +25 -0
- package/dist/cjs/lib/useIndex.js +38 -0
- package/dist/cjs/lib/useIndexContext.js +14 -0
- package/dist/cjs/lib/useInstantSearchApi.js +191 -0
- package/dist/cjs/lib/useInstantSearchContext.js +14 -0
- package/dist/cjs/lib/useInstantSearchSSRContext.js +11 -0
- package/dist/cjs/lib/useInstantSearchServerContext.js +11 -0
- package/dist/cjs/lib/useIsomorphicLayoutEffect.js +14 -0
- package/dist/cjs/lib/useSearchResults.js +46 -0
- package/dist/cjs/lib/useSearchState.js +48 -0
- package/dist/cjs/lib/useStableValue.js +26 -0
- package/dist/cjs/lib/useWidget.js +78 -0
- package/dist/cjs/lib/warn.js +41 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/server/getServerState.js +93 -0
- package/dist/cjs/{types → server}/index.js +4 -4
- package/dist/cjs/{core/version.js → version.js} +1 -1
- package/dist/es/components/Configure.d.ts +3 -0
- package/dist/es/components/Configure.js +7 -0
- package/dist/es/components/DynamicWidgets.d.ts +13 -0
- package/dist/es/components/DynamicWidgets.js +55 -0
- package/dist/es/components/Index.d.ts +6 -0
- package/dist/es/components/Index.js +17 -0
- package/dist/es/components/InstantSearch.d.ts +7 -0
- package/dist/es/components/InstantSearch.js +20 -0
- package/dist/es/components/InstantSearchSSRProvider.d.ts +13 -0
- package/dist/es/{connectors/connectConfigure.js → components/InstantSearchSSRProvider.js} +26 -61
- package/dist/es/components/InstantSearchServerContext.d.ts +12 -0
- package/dist/es/components/InstantSearchServerContext.js +5 -0
- package/dist/es/connectors/useBreadcrumb.d.ts +4 -0
- package/dist/es/connectors/useBreadcrumb.js +5 -0
- package/dist/es/connectors/useClearRefinements.d.ts +4 -0
- package/dist/es/connectors/useClearRefinements.js +5 -0
- package/dist/es/connectors/useConfigure.d.ts +4 -0
- package/dist/es/connectors/useConfigure.js +7 -0
- package/dist/es/connectors/useCurrentRefinements.d.ts +4 -0
- package/dist/es/connectors/useCurrentRefinements.js +5 -0
- package/dist/es/connectors/useDynamicWidgets.d.ts +4 -0
- package/dist/es/connectors/useDynamicWidgets.js +15 -0
- package/dist/es/connectors/useGeoSearch.d.ts +6 -0
- package/dist/es/connectors/useGeoSearch.js +5 -0
- package/dist/es/connectors/useHierarchicalMenu.d.ts +4 -0
- package/dist/es/connectors/useHierarchicalMenu.js +5 -0
- package/dist/es/connectors/useHits.d.ts +5 -0
- package/dist/es/connectors/useHits.js +5 -0
- package/dist/es/connectors/useHitsPerPage.d.ts +4 -0
- package/dist/es/connectors/useHitsPerPage.js +5 -0
- package/dist/es/connectors/useInfiniteHits.d.ts +5 -0
- package/dist/es/connectors/useInfiniteHits.js +5 -0
- package/dist/es/connectors/useMenu.d.ts +4 -0
- package/dist/es/connectors/useMenu.js +5 -0
- package/dist/es/connectors/useNumericMenu.d.ts +4 -0
- package/dist/es/connectors/useNumericMenu.js +5 -0
- package/dist/es/connectors/usePagination.d.ts +4 -0
- package/dist/es/connectors/usePagination.js +5 -0
- package/dist/es/connectors/usePoweredBy.d.ts +2 -0
- package/dist/es/connectors/usePoweredBy.js +15 -0
- package/dist/es/connectors/useQueryRules.d.ts +4 -0
- package/dist/es/connectors/useQueryRules.js +5 -0
- package/dist/es/connectors/useRange.d.ts +4 -0
- package/dist/es/connectors/useRange.js +5 -0
- package/dist/es/connectors/useRefinementList.d.ts +4 -0
- package/dist/es/connectors/useRefinementList.js +5 -0
- package/dist/es/connectors/useSearchBox.d.ts +4 -0
- package/dist/es/connectors/useSearchBox.js +5 -0
- package/dist/es/connectors/useSortBy.d.ts +4 -0
- package/dist/es/connectors/useSortBy.js +5 -0
- package/dist/es/connectors/useStats.d.ts +4 -0
- package/dist/es/connectors/useStats.js +5 -0
- package/dist/es/connectors/useToggleRefinement.d.ts +4 -0
- package/dist/es/connectors/useToggleRefinement.js +5 -0
- package/dist/es/hooks/useConnector.d.ts +3 -0
- package/dist/es/hooks/useConnector.js +130 -0
- package/dist/es/hooks/useInstantSearch.d.ts +32 -0
- package/dist/es/hooks/useInstantSearch.js +52 -0
- package/dist/es/index.d.ts +31 -0
- package/dist/es/index.js +31 -87
- package/dist/es/lib/IndexContext.d.ts +3 -0
- package/dist/es/lib/IndexContext.js +5 -0
- package/dist/es/lib/InstantSearchContext.d.ts +3 -0
- package/dist/es/lib/InstantSearchContext.js +5 -0
- package/dist/es/lib/InstantSearchSSRContext.d.ts +8 -0
- package/dist/es/lib/InstantSearchSSRContext.js +5 -0
- package/dist/es/lib/createSearchResults.d.ts +3 -0
- package/dist/es/lib/createSearchResults.js +20 -0
- package/dist/es/lib/dequal.d.ts +1 -0
- package/dist/es/lib/dequal.js +47 -0
- package/dist/es/lib/getIndexSearchResults.d.ts +9 -0
- package/dist/es/lib/getIndexSearchResults.js +26 -0
- package/dist/es/lib/invariant.d.ts +9 -0
- package/dist/es/lib/invariant.js +19 -0
- package/dist/es/lib/noop.d.ts +1 -0
- package/dist/es/lib/noop.js +1 -0
- package/dist/es/lib/useForceUpdate.d.ts +6 -0
- package/dist/es/lib/useForceUpdate.js +20 -0
- package/dist/es/lib/useIndex.d.ts +3 -0
- package/dist/es/lib/useIndex.js +31 -0
- package/dist/es/lib/useIndexContext.d.ts +2 -0
- package/dist/es/lib/useIndexContext.js +8 -0
- package/dist/es/lib/useInstantSearchApi.d.ts +21 -0
- package/dist/es/lib/useInstantSearchApi.js +184 -0
- package/dist/es/lib/useInstantSearchContext.d.ts +3 -0
- package/dist/es/lib/useInstantSearchContext.js +8 -0
- package/dist/es/lib/useInstantSearchSSRContext.d.ts +3 -0
- package/dist/es/lib/useInstantSearchSSRContext.js +5 -0
- package/dist/es/lib/useInstantSearchServerContext.d.ts +3 -0
- package/dist/es/lib/useInstantSearchServerContext.js +5 -0
- package/dist/es/lib/useIsomorphicLayoutEffect.d.ts +7 -0
- package/dist/es/lib/useIsomorphicLayoutEffect.js +8 -0
- package/dist/es/lib/useSearchResults.d.ts +7 -0
- package/dist/es/lib/useSearchResults.js +40 -0
- package/dist/es/lib/useSearchState.d.ts +8 -0
- package/dist/es/lib/useSearchState.js +42 -0
- package/dist/es/lib/useStableValue.d.ts +1 -0
- package/dist/es/lib/useStableValue.js +20 -0
- package/dist/es/lib/useWidget.d.ts +8 -0
- package/dist/es/lib/useWidget.js +72 -0
- package/dist/es/lib/warn.d.ts +10 -0
- package/dist/es/lib/warn.js +33 -0
- package/dist/es/server/getServerState.d.ts +10 -0
- package/dist/es/server/getServerState.js +86 -0
- package/dist/es/server/index.d.ts +1 -0
- package/dist/es/server/index.js +1 -0
- package/dist/es/version.d.ts +2 -0
- package/dist/es/version.js +1 -0
- package/dist/umd/ReactInstantSearchCore.js +14071 -7955
- package/dist/umd/ReactInstantSearchCore.js.map +1 -1
- package/dist/umd/ReactInstantSearchCore.min.js +1 -1
- package/dist/umd/ReactInstantSearchCore.min.js.map +1 -1
- package/package.json +23 -8
- package/dist/cjs/connectors/connectAutoComplete.js +0 -104
- package/dist/cjs/connectors/connectBreadcrumb.js +0 -123
- package/dist/cjs/connectors/connectConfigureRelatedItems.js +0 -127
- package/dist/cjs/connectors/connectCurrentRefinements.js +0 -69
- package/dist/cjs/connectors/connectDynamicWidgets.js +0 -65
- package/dist/cjs/connectors/connectGeoSearch.js +0 -189
- package/dist/cjs/connectors/connectHierarchicalMenu.js +0 -273
- package/dist/cjs/connectors/connectHighlight.js +0 -87
- package/dist/cjs/connectors/connectHitInsights.js +0 -76
- package/dist/cjs/connectors/connectHits.js +0 -88
- package/dist/cjs/connectors/connectHitsPerPage.js +0 -97
- package/dist/cjs/connectors/connectInfiniteHits.js +0 -154
- package/dist/cjs/connectors/connectMenu.js +0 -221
- package/dist/cjs/connectors/connectNumericMenu.js +0 -215
- package/dist/cjs/connectors/connectPagination.js +0 -94
- package/dist/cjs/connectors/connectPoweredBy.js +0 -27
- package/dist/cjs/connectors/connectQueryRules.js +0 -129
- package/dist/cjs/connectors/connectRange.js +0 -287
- package/dist/cjs/connectors/connectRefinementList.js +0 -243
- package/dist/cjs/connectors/connectRelevantSort.js +0 -56
- package/dist/cjs/connectors/connectScrollTo.js +0 -70
- package/dist/cjs/connectors/connectSearchBox.js +0 -104
- package/dist/cjs/connectors/connectSortBy.js +0 -100
- package/dist/cjs/connectors/connectStateResults.js +0 -79
- package/dist/cjs/connectors/connectStats.js +0 -39
- package/dist/cjs/connectors/connectToggleRefinement.js +0 -163
- package/dist/cjs/connectors/connectVoiceSearch.js +0 -124
- package/dist/cjs/core/context.js +0 -37
- package/dist/cjs/core/createConnector.js +0 -268
- package/dist/cjs/core/createInstantSearchManager.d.js +0 -1
- package/dist/cjs/core/createInstantSearchManager.js +0 -541
- package/dist/cjs/core/createStore.js +0 -27
- package/dist/cjs/core/createWidgetsManager.js +0 -39
- package/dist/cjs/core/highlight.js +0 -102
- package/dist/cjs/core/indexUtils.js +0 -214
- package/dist/cjs/core/metadata.js +0 -46
- package/dist/cjs/core/translatable.js +0 -82
- package/dist/cjs/core/utils.js +0 -161
- package/dist/cjs/types/algoliasearch.js +0 -1
- package/dist/cjs/types/translatable.js +0 -1
- package/dist/cjs/widgets/Configure.js +0 -48
- package/dist/cjs/widgets/ConfigureRelatedItems.js +0 -21
- package/dist/cjs/widgets/DynamicWidgets.js +0 -61
- package/dist/cjs/widgets/Index.js +0 -149
- package/dist/cjs/widgets/InstantSearch.js +0 -251
- package/dist/cjs/widgets/QueryRuleContext.js +0 -14
- package/dist/es/connectors/connectAutoComplete.js +0 -96
- package/dist/es/connectors/connectBreadcrumb.js +0 -115
- package/dist/es/connectors/connectConfigureRelatedItems.js +0 -121
- package/dist/es/connectors/connectCurrentRefinements.js +0 -62
- package/dist/es/connectors/connectDynamicWidgets.js +0 -56
- package/dist/es/connectors/connectGeoSearch.js +0 -182
- package/dist/es/connectors/connectHierarchicalMenu.js +0 -264
- package/dist/es/connectors/connectHighlight.js +0 -79
- package/dist/es/connectors/connectHitInsights.js +0 -69
- package/dist/es/connectors/connectHits.js +0 -81
- package/dist/es/connectors/connectHitsPerPage.js +0 -89
- package/dist/es/connectors/connectInfiniteHits.js +0 -146
- package/dist/es/connectors/connectMenu.js +0 -213
- package/dist/es/connectors/connectNumericMenu.js +0 -207
- package/dist/es/connectors/connectPagination.js +0 -86
- package/dist/es/connectors/connectPoweredBy.js +0 -20
- package/dist/es/connectors/connectQueryRules.js +0 -122
- package/dist/es/connectors/connectRange.js +0 -280
- package/dist/es/connectors/connectRefinementList.js +0 -235
- package/dist/es/connectors/connectRelevantSort.js +0 -50
- package/dist/es/connectors/connectScrollTo.js +0 -63
- package/dist/es/connectors/connectSearchBox.js +0 -96
- package/dist/es/connectors/connectSortBy.js +0 -92
- package/dist/es/connectors/connectStateResults.js +0 -72
- package/dist/es/connectors/connectStats.js +0 -32
- package/dist/es/connectors/connectToggleRefinement.js +0 -155
- package/dist/es/connectors/connectVoiceSearch.js +0 -116
- package/dist/es/core/context.js +0 -28
- package/dist/es/core/createConnector.js +0 -257
- package/dist/es/core/createInstantSearchManager.d.js +0 -0
- package/dist/es/core/createInstantSearchManager.js +0 -534
- package/dist/es/core/createStore.js +0 -21
- package/dist/es/core/createWidgetsManager.js +0 -33
- package/dist/es/core/highlight.js +0 -94
- package/dist/es/core/indexUtils.js +0 -203
- package/dist/es/core/metadata.js +0 -38
- package/dist/es/core/translatable.js +0 -74
- package/dist/es/core/utils.js +0 -139
- package/dist/es/core/version.js +0 -1
- package/dist/es/types/algoliasearch.js +0 -1
- package/dist/es/types/index.js +0 -1
- package/dist/es/types/translatable.js +0 -1
- package/dist/es/widgets/Configure.js +0 -42
- package/dist/es/widgets/ConfigureRelatedItems.js +0 -13
- package/dist/es/widgets/DynamicWidgets.js +0 -51
- package/dist/es/widgets/Index.js +0 -138
- package/dist/es/widgets/InstantSearch.js +0 -241
- package/dist/es/widgets/QueryRuleContext.js +0 -6
|
@@ -1,287 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
8
|
-
var _createConnector = _interopRequireDefault(require("../core/createConnector"));
|
|
9
|
-
var _indexUtils = require("../core/indexUtils");
|
|
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); }
|
|
15
|
-
/**
|
|
16
|
-
* connectRange connector provides the logic to create connected
|
|
17
|
-
* components that will give the ability for a user to refine results using
|
|
18
|
-
* a numeric range.
|
|
19
|
-
* @name connectRange
|
|
20
|
-
* @kind connector
|
|
21
|
-
* @requirements The attribute passed to the `attribute` prop must be present in “attributes for faceting”
|
|
22
|
-
* on the Algolia dashboard or configured as `attributesForFaceting` via a set settings call to the Algolia API.
|
|
23
|
-
* The values inside the attribute must be JavaScript numbers (not strings).
|
|
24
|
-
* @propType {string} attribute - Name of the attribute for faceting
|
|
25
|
-
* @propType {{min?: number, max?: number}} [defaultRefinement] - Default searchState of the widget containing the start and the end of the range.
|
|
26
|
-
* @propType {number} [min] - Minimum value. When this isn't set, the minimum value will be automatically computed by Algolia using the data in the index.
|
|
27
|
-
* @propType {number} [max] - Maximum value. When this isn't set, the maximum value will be automatically computed by Algolia using the data in the index.
|
|
28
|
-
* @propType {number} [precision=0] - Number of digits after decimal point to use.
|
|
29
|
-
* @providedPropType {function} refine - a function to select a range.
|
|
30
|
-
* @providedPropType {function} createURL - a function to generate a URL for the corresponding search state
|
|
31
|
-
* @providedPropType {string} currentRefinement - the refinement currently applied
|
|
32
|
-
* @providedPropType {number} min - the minimum value available.
|
|
33
|
-
* @providedPropType {number} max - the maximum value available.
|
|
34
|
-
* @providedPropType {number} precision - Number of digits after decimal point to use.
|
|
35
|
-
*/
|
|
36
|
-
|
|
37
|
-
function getId(props) {
|
|
38
|
-
return props.attribute;
|
|
39
|
-
}
|
|
40
|
-
var namespace = 'range';
|
|
41
|
-
function getCurrentRange(boundaries, stats, precision) {
|
|
42
|
-
var pow = Math.pow(10, precision);
|
|
43
|
-
var min;
|
|
44
|
-
if (typeof boundaries.min === 'number' && isFinite(boundaries.min)) {
|
|
45
|
-
min = boundaries.min;
|
|
46
|
-
} else if (typeof stats.min === 'number' && isFinite(stats.min)) {
|
|
47
|
-
min = stats.min;
|
|
48
|
-
} else {
|
|
49
|
-
min = undefined;
|
|
50
|
-
}
|
|
51
|
-
var max;
|
|
52
|
-
if (typeof boundaries.max === 'number' && isFinite(boundaries.max)) {
|
|
53
|
-
max = boundaries.max;
|
|
54
|
-
} else if (typeof stats.max === 'number' && isFinite(stats.max)) {
|
|
55
|
-
max = stats.max;
|
|
56
|
-
} else {
|
|
57
|
-
max = undefined;
|
|
58
|
-
}
|
|
59
|
-
return {
|
|
60
|
-
min: min !== undefined ? Math.floor(min * pow) / pow : min,
|
|
61
|
-
max: max !== undefined ? Math.ceil(max * pow) / pow : max
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
function getCurrentRefinement(props, searchState, currentRange, context) {
|
|
65
|
-
var _getCurrentRefinement = (0, _indexUtils.getCurrentRefinementValue)(props, searchState, context, "".concat(namespace, ".").concat(getId(props)), {}),
|
|
66
|
-
min = _getCurrentRefinement.min,
|
|
67
|
-
max = _getCurrentRefinement.max;
|
|
68
|
-
var isFloatPrecision = Boolean(props.precision);
|
|
69
|
-
var nextMin = min;
|
|
70
|
-
if (typeof nextMin === 'string') {
|
|
71
|
-
nextMin = isFloatPrecision ? parseFloat(nextMin) : parseInt(nextMin, 10);
|
|
72
|
-
}
|
|
73
|
-
var nextMax = max;
|
|
74
|
-
if (typeof nextMax === 'string') {
|
|
75
|
-
nextMax = isFloatPrecision ? parseFloat(nextMax) : parseInt(nextMax, 10);
|
|
76
|
-
}
|
|
77
|
-
var refinement = {
|
|
78
|
-
min: nextMin,
|
|
79
|
-
max: nextMax
|
|
80
|
-
};
|
|
81
|
-
var hasMinBound = props.min !== undefined;
|
|
82
|
-
var hasMaxBound = props.max !== undefined;
|
|
83
|
-
var hasMinRefinment = refinement.min !== undefined;
|
|
84
|
-
var hasMaxRefinment = refinement.max !== undefined;
|
|
85
|
-
if (hasMinBound && hasMinRefinment && refinement.min < currentRange.min) {
|
|
86
|
-
throw Error("You can't provide min value lower than range.");
|
|
87
|
-
}
|
|
88
|
-
if (hasMaxBound && hasMaxRefinment && refinement.max > currentRange.max) {
|
|
89
|
-
throw Error("You can't provide max value greater than range.");
|
|
90
|
-
}
|
|
91
|
-
if (hasMinBound && !hasMinRefinment) {
|
|
92
|
-
refinement.min = currentRange.min;
|
|
93
|
-
}
|
|
94
|
-
if (hasMaxBound && !hasMaxRefinment) {
|
|
95
|
-
refinement.max = currentRange.max;
|
|
96
|
-
}
|
|
97
|
-
return refinement;
|
|
98
|
-
}
|
|
99
|
-
function getCurrentRefinementWithRange(refinement, range) {
|
|
100
|
-
return {
|
|
101
|
-
min: refinement.min !== undefined ? refinement.min : range.min,
|
|
102
|
-
max: refinement.max !== undefined ? refinement.max : range.max
|
|
103
|
-
};
|
|
104
|
-
}
|
|
105
|
-
function nextValueForRefinement(hasBound, isReset, range, value) {
|
|
106
|
-
var next;
|
|
107
|
-
if (!hasBound && range === value) {
|
|
108
|
-
next = undefined;
|
|
109
|
-
} else if (hasBound && isReset) {
|
|
110
|
-
next = range;
|
|
111
|
-
} else {
|
|
112
|
-
next = value;
|
|
113
|
-
}
|
|
114
|
-
return next;
|
|
115
|
-
}
|
|
116
|
-
function _refine(props, searchState, nextRefinement, currentRange, context) {
|
|
117
|
-
var nextMin = nextRefinement.min,
|
|
118
|
-
nextMax = nextRefinement.max;
|
|
119
|
-
var currentMinRange = currentRange.min,
|
|
120
|
-
currentMaxRange = currentRange.max;
|
|
121
|
-
var isMinReset = nextMin === undefined || nextMin === '';
|
|
122
|
-
var isMaxReset = nextMax === undefined || nextMax === '';
|
|
123
|
-
var nextMinAsNumber = !isMinReset ? parseFloat(nextMin) : undefined;
|
|
124
|
-
var nextMaxAsNumber = !isMaxReset ? parseFloat(nextMax) : undefined;
|
|
125
|
-
var isNextMinValid = isMinReset || isFinite(nextMinAsNumber);
|
|
126
|
-
var isNextMaxValid = isMaxReset || isFinite(nextMaxAsNumber);
|
|
127
|
-
if (!isNextMinValid || !isNextMaxValid) {
|
|
128
|
-
throw Error("You can't provide non finite values to the range connector.");
|
|
129
|
-
}
|
|
130
|
-
if (nextMinAsNumber < currentMinRange) {
|
|
131
|
-
throw Error("You can't provide min value lower than range.");
|
|
132
|
-
}
|
|
133
|
-
if (nextMaxAsNumber > currentMaxRange) {
|
|
134
|
-
throw Error("You can't provide max value greater than range.");
|
|
135
|
-
}
|
|
136
|
-
var id = getId(props);
|
|
137
|
-
var resetPage = true;
|
|
138
|
-
var nextValue = _defineProperty({}, id, {
|
|
139
|
-
min: nextValueForRefinement(props.min !== undefined, isMinReset, currentMinRange, nextMinAsNumber),
|
|
140
|
-
max: nextValueForRefinement(props.max !== undefined, isMaxReset, currentMaxRange, nextMaxAsNumber)
|
|
141
|
-
});
|
|
142
|
-
return (0, _indexUtils.refineValue)(searchState, nextValue, context, resetPage, namespace);
|
|
143
|
-
}
|
|
144
|
-
function _cleanUp(props, searchState, context) {
|
|
145
|
-
return (0, _indexUtils.cleanUpValue)(searchState, context, "".concat(namespace, ".").concat(getId(props)));
|
|
146
|
-
}
|
|
147
|
-
var _default = (0, _createConnector.default)({
|
|
148
|
-
displayName: 'AlgoliaRange',
|
|
149
|
-
$$type: 'ais.range',
|
|
150
|
-
propTypes: {
|
|
151
|
-
id: _propTypes.default.string,
|
|
152
|
-
attribute: _propTypes.default.string.isRequired,
|
|
153
|
-
defaultRefinement: _propTypes.default.shape({
|
|
154
|
-
min: _propTypes.default.number,
|
|
155
|
-
max: _propTypes.default.number
|
|
156
|
-
}),
|
|
157
|
-
min: _propTypes.default.number,
|
|
158
|
-
max: _propTypes.default.number,
|
|
159
|
-
precision: _propTypes.default.number,
|
|
160
|
-
header: _propTypes.default.node,
|
|
161
|
-
footer: _propTypes.default.node
|
|
162
|
-
},
|
|
163
|
-
defaultProps: {
|
|
164
|
-
precision: 0
|
|
165
|
-
},
|
|
166
|
-
getProvidedProps: function getProvidedProps(props, searchState, searchResults) {
|
|
167
|
-
var attribute = props.attribute,
|
|
168
|
-
precision = props.precision,
|
|
169
|
-
minBound = props.min,
|
|
170
|
-
maxBound = props.max;
|
|
171
|
-
var results = (0, _indexUtils.getResults)(searchResults, {
|
|
172
|
-
ais: props.contextValue,
|
|
173
|
-
multiIndexContext: props.indexContextValue
|
|
174
|
-
});
|
|
175
|
-
var hasFacet = results && results.getFacetByName(attribute);
|
|
176
|
-
var stats = hasFacet ? results.getFacetStats(attribute) || {} : {};
|
|
177
|
-
var facetValues = hasFacet ? results.getFacetValues(attribute) : [];
|
|
178
|
-
var count = facetValues.map(function (v) {
|
|
179
|
-
return {
|
|
180
|
-
value: v.name,
|
|
181
|
-
count: v.count
|
|
182
|
-
};
|
|
183
|
-
});
|
|
184
|
-
var _getCurrentRange = getCurrentRange({
|
|
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
|
|
192
|
-
// when we set boundaries on the first render the searchState don't have
|
|
193
|
-
// the correct refinement. If this behavior change in the upcoming version
|
|
194
|
-
// we could store the range inside the searchState instead of rely on `this`.
|
|
195
|
-
this._currentRange = {
|
|
196
|
-
min: rangeMin,
|
|
197
|
-
max: rangeMax
|
|
198
|
-
};
|
|
199
|
-
var currentRefinement = getCurrentRefinement(props, searchState, this._currentRange, {
|
|
200
|
-
ais: props.contextValue,
|
|
201
|
-
multiIndexContext: props.indexContextValue
|
|
202
|
-
});
|
|
203
|
-
return {
|
|
204
|
-
min: rangeMin,
|
|
205
|
-
max: rangeMax,
|
|
206
|
-
canRefine: count.length > 0,
|
|
207
|
-
currentRefinement: getCurrentRefinementWithRange(currentRefinement, this._currentRange),
|
|
208
|
-
count: count,
|
|
209
|
-
precision: precision
|
|
210
|
-
};
|
|
211
|
-
},
|
|
212
|
-
refine: function refine(props, searchState, nextRefinement) {
|
|
213
|
-
return _refine(props, searchState, nextRefinement, this._currentRange, {
|
|
214
|
-
ais: props.contextValue,
|
|
215
|
-
multiIndexContext: props.indexContextValue
|
|
216
|
-
});
|
|
217
|
-
},
|
|
218
|
-
cleanUp: function cleanUp(props, searchState) {
|
|
219
|
-
return _cleanUp(props, searchState, {
|
|
220
|
-
ais: props.contextValue,
|
|
221
|
-
multiIndexContext: props.indexContextValue
|
|
222
|
-
});
|
|
223
|
-
},
|
|
224
|
-
getSearchParameters: function getSearchParameters(params, props, searchState) {
|
|
225
|
-
var attribute = props.attribute;
|
|
226
|
-
var _getCurrentRefinement2 = getCurrentRefinement(props, searchState, this._currentRange, {
|
|
227
|
-
ais: props.contextValue,
|
|
228
|
-
multiIndexContext: props.indexContextValue
|
|
229
|
-
}),
|
|
230
|
-
min = _getCurrentRefinement2.min,
|
|
231
|
-
max = _getCurrentRefinement2.max;
|
|
232
|
-
params = params.addDisjunctiveFacet(attribute);
|
|
233
|
-
if (min !== undefined) {
|
|
234
|
-
params = params.addNumericRefinement(attribute, '>=', min);
|
|
235
|
-
}
|
|
236
|
-
if (max !== undefined) {
|
|
237
|
-
params = params.addNumericRefinement(attribute, '<=', max);
|
|
238
|
-
}
|
|
239
|
-
return params;
|
|
240
|
-
},
|
|
241
|
-
getMetadata: function getMetadata(props, searchState) {
|
|
242
|
-
var _this = this;
|
|
243
|
-
var _this$_currentRange = this._currentRange,
|
|
244
|
-
minRange = _this$_currentRange.min,
|
|
245
|
-
maxRange = _this$_currentRange.max;
|
|
246
|
-
var _getCurrentRefinement3 = getCurrentRefinement(props, searchState, this._currentRange, {
|
|
247
|
-
ais: props.contextValue,
|
|
248
|
-
multiIndexContext: props.indexContextValue
|
|
249
|
-
}),
|
|
250
|
-
minValue = _getCurrentRefinement3.min,
|
|
251
|
-
maxValue = _getCurrentRefinement3.max;
|
|
252
|
-
var items = [];
|
|
253
|
-
var hasMin = minValue !== undefined;
|
|
254
|
-
var hasMax = maxValue !== undefined;
|
|
255
|
-
var shouldDisplayMinLabel = hasMin && minValue !== minRange;
|
|
256
|
-
var shouldDisplayMaxLabel = hasMax && maxValue !== maxRange;
|
|
257
|
-
if (shouldDisplayMinLabel || shouldDisplayMaxLabel) {
|
|
258
|
-
var fragments = [hasMin ? "".concat(minValue, " <= ") : '', props.attribute, hasMax ? " <= ".concat(maxValue) : ''];
|
|
259
|
-
items.push({
|
|
260
|
-
label: fragments.join(''),
|
|
261
|
-
attribute: props.attribute,
|
|
262
|
-
value: function value(nextState) {
|
|
263
|
-
return _refine(props, nextState, {}, _this._currentRange, {
|
|
264
|
-
ais: props.contextValue,
|
|
265
|
-
multiIndexContext: props.indexContextValue
|
|
266
|
-
});
|
|
267
|
-
},
|
|
268
|
-
currentRefinement: getCurrentRefinementWithRange({
|
|
269
|
-
min: minValue,
|
|
270
|
-
max: maxValue
|
|
271
|
-
}, {
|
|
272
|
-
min: minRange,
|
|
273
|
-
max: maxRange
|
|
274
|
-
})
|
|
275
|
-
});
|
|
276
|
-
}
|
|
277
|
-
return {
|
|
278
|
-
id: getId(props),
|
|
279
|
-
index: (0, _indexUtils.getIndexId)({
|
|
280
|
-
ais: props.contextValue,
|
|
281
|
-
multiIndexContext: props.indexContextValue
|
|
282
|
-
}),
|
|
283
|
-
items: items
|
|
284
|
-
};
|
|
285
|
-
}
|
|
286
|
-
});
|
|
287
|
-
exports.default = _default;
|
|
@@ -1,243 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
8
|
-
var _createConnector = _interopRequireDefault(require("../core/createConnector"));
|
|
9
|
-
var _indexUtils = require("../core/indexUtils");
|
|
10
|
-
var _utils = require("../core/utils");
|
|
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); }
|
|
16
|
-
var namespace = 'refinementList';
|
|
17
|
-
function getId(props) {
|
|
18
|
-
return props.attribute;
|
|
19
|
-
}
|
|
20
|
-
function getCurrentRefinement(props, searchState, context) {
|
|
21
|
-
var currentRefinement = (0, _indexUtils.getCurrentRefinementValue)(props, searchState, context, "".concat(namespace, ".").concat(getId(props)), []);
|
|
22
|
-
if (typeof currentRefinement !== 'string') {
|
|
23
|
-
return currentRefinement;
|
|
24
|
-
}
|
|
25
|
-
if (currentRefinement) {
|
|
26
|
-
return [currentRefinement];
|
|
27
|
-
}
|
|
28
|
-
return [];
|
|
29
|
-
}
|
|
30
|
-
function getValue(value, props, searchState, context) {
|
|
31
|
-
var currentRefinement = getCurrentRefinement(props, searchState, context);
|
|
32
|
-
var isAnewValue = currentRefinement.indexOf(value) === -1;
|
|
33
|
-
var nextRefinement = isAnewValue ? currentRefinement.concat([value]) // cannot use .push(), it mutates
|
|
34
|
-
: currentRefinement.filter(function (selectedValue) {
|
|
35
|
-
return selectedValue !== value;
|
|
36
|
-
}); // cannot use .splice(), it mutates
|
|
37
|
-
return nextRefinement;
|
|
38
|
-
}
|
|
39
|
-
function getLimit(_ref) {
|
|
40
|
-
var showMore = _ref.showMore,
|
|
41
|
-
limit = _ref.limit,
|
|
42
|
-
showMoreLimit = _ref.showMoreLimit;
|
|
43
|
-
return showMore ? showMoreLimit : limit;
|
|
44
|
-
}
|
|
45
|
-
function _refine(props, searchState, nextRefinement, context) {
|
|
46
|
-
var id = getId(props);
|
|
47
|
-
// Setting the value to an empty string ensures that it is persisted in
|
|
48
|
-
// the URL as an empty value.
|
|
49
|
-
// This is necessary in the case where `defaultRefinement` contains one
|
|
50
|
-
// item and we try to deselect it. `nextSelected` would be an empty array,
|
|
51
|
-
// which would not be persisted to the URL.
|
|
52
|
-
// {foo: ['bar']} => "foo[0]=bar"
|
|
53
|
-
// {foo: []} => ""
|
|
54
|
-
var nextValue = _defineProperty({}, id, nextRefinement.length > 0 ? nextRefinement : '');
|
|
55
|
-
var resetPage = true;
|
|
56
|
-
return (0, _indexUtils.refineValue)(searchState, nextValue, context, resetPage, namespace);
|
|
57
|
-
}
|
|
58
|
-
function _cleanUp(props, searchState, context) {
|
|
59
|
-
return (0, _indexUtils.cleanUpValue)(searchState, context, "".concat(namespace, ".").concat(getId(props)));
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* connectRefinementList connector provides the logic to build a widget that will
|
|
63
|
-
* give the user the ability to choose multiple values for a specific facet.
|
|
64
|
-
* @name connectRefinementList
|
|
65
|
-
* @kind connector
|
|
66
|
-
* @requirements The attribute passed to the `attribute` prop must be present in "attributes for faceting"
|
|
67
|
-
* on the Algolia dashboard or configured as `attributesForFaceting` via a set settings call to the Algolia API.
|
|
68
|
-
* @propType {string} attribute - the name of the attribute in the record
|
|
69
|
-
* @propType {boolean} [searchable=false] - allow search inside values
|
|
70
|
-
* @propType {string} [operator=or] - How to apply the refinements. Possible values: 'or' or 'and'.
|
|
71
|
-
* @propType {boolean} [showMore=false] - true if the component should display a button that will expand the number of items
|
|
72
|
-
* @propType {number} [limit=10] - the minimum number of displayed items
|
|
73
|
-
* @propType {number} [showMoreLimit=20] - the maximun number of displayed items. Only used when showMore is set to `true`
|
|
74
|
-
* @propType {string[]} defaultRefinement - the values of the items selected by default. The searchState of this widget takes the form of a list of `string`s, which correspond to the values of all selected refinements. However, when there are no refinements selected, the value of the searchState is an empty string.
|
|
75
|
-
* @propType {function} [transformItems] - Function to modify the items being displayed, e.g. for filtering or sorting them. Takes an items as parameter and expects it back in return.
|
|
76
|
-
* @providedPropType {function} refine - a function to toggle a refinement
|
|
77
|
-
* @providedPropType {function} createURL - a function to generate a URL for the corresponding search state
|
|
78
|
-
* @providedPropType {string[]} currentRefinement - the refinement currently applied
|
|
79
|
-
* @providedPropType {array.<{count: number, isRefined: boolean, label: string, value: string}>} items - the list of items the RefinementList can display.
|
|
80
|
-
* @providedPropType {function} searchForItems - a function to toggle a search inside items values
|
|
81
|
-
* @providedPropType {boolean} isFromSearch - a boolean that says if the `items` props contains facet values from the global search or from the search inside items.
|
|
82
|
-
* @providedPropType {boolean} canRefine - a boolean that says whether you can refine
|
|
83
|
-
*/
|
|
84
|
-
|
|
85
|
-
var sortBy = ['isRefined', 'count:desc', 'name:asc'];
|
|
86
|
-
var _default = (0, _createConnector.default)({
|
|
87
|
-
displayName: 'AlgoliaRefinementList',
|
|
88
|
-
$$type: 'ais.refinementList',
|
|
89
|
-
propTypes: {
|
|
90
|
-
id: _propTypes.default.string,
|
|
91
|
-
attribute: _propTypes.default.string.isRequired,
|
|
92
|
-
operator: _propTypes.default.oneOf(['and', 'or']),
|
|
93
|
-
showMore: _propTypes.default.bool,
|
|
94
|
-
limit: _propTypes.default.number,
|
|
95
|
-
showMoreLimit: _propTypes.default.number,
|
|
96
|
-
defaultRefinement: _propTypes.default.arrayOf(_propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.number])),
|
|
97
|
-
searchable: _propTypes.default.bool,
|
|
98
|
-
transformItems: _propTypes.default.func,
|
|
99
|
-
facetOrdering: _propTypes.default.bool
|
|
100
|
-
},
|
|
101
|
-
defaultProps: {
|
|
102
|
-
operator: 'or',
|
|
103
|
-
showMore: false,
|
|
104
|
-
limit: 10,
|
|
105
|
-
showMoreLimit: 20,
|
|
106
|
-
facetOrdering: true
|
|
107
|
-
},
|
|
108
|
-
getProvidedProps: function getProvidedProps(props, searchState, searchResults, metadata, searchForFacetValuesResults) {
|
|
109
|
-
var attribute = props.attribute,
|
|
110
|
-
searchable = props.searchable,
|
|
111
|
-
indexContextValue = props.indexContextValue,
|
|
112
|
-
facetOrdering = props.facetOrdering;
|
|
113
|
-
var results = (0, _indexUtils.getResults)(searchResults, {
|
|
114
|
-
ais: props.contextValue,
|
|
115
|
-
multiIndexContext: props.indexContextValue
|
|
116
|
-
});
|
|
117
|
-
var canRefine = Boolean(results) && Boolean(results.getFacetByName(attribute));
|
|
118
|
-
var isFromSearch = Boolean(searchForFacetValuesResults && searchForFacetValuesResults[attribute] && searchForFacetValuesResults.query !== '');
|
|
119
|
-
|
|
120
|
-
// Search For Facet Values is not available with derived helper (used for multi index search)
|
|
121
|
-
if (searchable && indexContextValue) {
|
|
122
|
-
throw new Error('react-instantsearch: searching in *List is not available when used inside a' + ' multi index context');
|
|
123
|
-
}
|
|
124
|
-
if (!canRefine) {
|
|
125
|
-
return {
|
|
126
|
-
items: [],
|
|
127
|
-
currentRefinement: getCurrentRefinement(props, searchState, {
|
|
128
|
-
ais: props.contextValue,
|
|
129
|
-
multiIndexContext: props.indexContextValue
|
|
130
|
-
}),
|
|
131
|
-
canRefine: canRefine,
|
|
132
|
-
isFromSearch: isFromSearch,
|
|
133
|
-
searchable: searchable
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
|
-
var items = isFromSearch ? searchForFacetValuesResults[attribute].map(function (v) {
|
|
137
|
-
return {
|
|
138
|
-
label: v.value,
|
|
139
|
-
value: getValue(v.escapedValue, props, searchState, {
|
|
140
|
-
ais: props.contextValue,
|
|
141
|
-
multiIndexContext: props.indexContextValue
|
|
142
|
-
}),
|
|
143
|
-
_highlightResult: {
|
|
144
|
-
label: {
|
|
145
|
-
value: v.highlighted
|
|
146
|
-
}
|
|
147
|
-
},
|
|
148
|
-
count: v.count,
|
|
149
|
-
isRefined: v.isRefined
|
|
150
|
-
};
|
|
151
|
-
}) : results.getFacetValues(attribute, {
|
|
152
|
-
sortBy: sortBy,
|
|
153
|
-
facetOrdering: facetOrdering
|
|
154
|
-
}).map(function (v) {
|
|
155
|
-
return {
|
|
156
|
-
label: v.name,
|
|
157
|
-
value: getValue(v.escapedValue, props, searchState, {
|
|
158
|
-
ais: props.contextValue,
|
|
159
|
-
multiIndexContext: props.indexContextValue
|
|
160
|
-
}),
|
|
161
|
-
count: v.count,
|
|
162
|
-
isRefined: v.isRefined
|
|
163
|
-
};
|
|
164
|
-
});
|
|
165
|
-
var transformedItems = props.transformItems ? props.transformItems(items) : items;
|
|
166
|
-
return {
|
|
167
|
-
items: transformedItems.slice(0, getLimit(props)),
|
|
168
|
-
currentRefinement: getCurrentRefinement(props, searchState, {
|
|
169
|
-
ais: props.contextValue,
|
|
170
|
-
multiIndexContext: props.indexContextValue
|
|
171
|
-
}),
|
|
172
|
-
isFromSearch: isFromSearch,
|
|
173
|
-
searchable: searchable,
|
|
174
|
-
canRefine: transformedItems.length > 0
|
|
175
|
-
};
|
|
176
|
-
},
|
|
177
|
-
refine: function refine(props, searchState, nextRefinement) {
|
|
178
|
-
return _refine(props, searchState, nextRefinement, {
|
|
179
|
-
ais: props.contextValue,
|
|
180
|
-
multiIndexContext: props.indexContextValue
|
|
181
|
-
});
|
|
182
|
-
},
|
|
183
|
-
searchForFacetValues: function searchForFacetValues(props, searchState, nextRefinement) {
|
|
184
|
-
return {
|
|
185
|
-
facetName: props.attribute,
|
|
186
|
-
query: nextRefinement,
|
|
187
|
-
maxFacetHits: getLimit(props)
|
|
188
|
-
};
|
|
189
|
-
},
|
|
190
|
-
cleanUp: function cleanUp(props, searchState) {
|
|
191
|
-
return _cleanUp(props, searchState, {
|
|
192
|
-
ais: props.contextValue,
|
|
193
|
-
multiIndexContext: props.indexContextValue
|
|
194
|
-
});
|
|
195
|
-
},
|
|
196
|
-
getSearchParameters: function getSearchParameters(searchParameters, props, searchState) {
|
|
197
|
-
var attribute = props.attribute,
|
|
198
|
-
operator = props.operator;
|
|
199
|
-
var addKey = operator === 'and' ? 'addFacet' : 'addDisjunctiveFacet';
|
|
200
|
-
var addRefinementKey = "".concat(addKey, "Refinement");
|
|
201
|
-
searchParameters = searchParameters.setQueryParameters({
|
|
202
|
-
maxValuesPerFacet: Math.max(searchParameters.maxValuesPerFacet || 0, getLimit(props))
|
|
203
|
-
});
|
|
204
|
-
searchParameters = searchParameters[addKey](attribute);
|
|
205
|
-
return getCurrentRefinement(props, searchState, {
|
|
206
|
-
ais: props.contextValue,
|
|
207
|
-
multiIndexContext: props.indexContextValue
|
|
208
|
-
}).reduce(function (res, val) {
|
|
209
|
-
return res[addRefinementKey](attribute, val);
|
|
210
|
-
}, searchParameters);
|
|
211
|
-
},
|
|
212
|
-
getMetadata: function getMetadata(props, searchState) {
|
|
213
|
-
var id = getId(props);
|
|
214
|
-
var context = {
|
|
215
|
-
ais: props.contextValue,
|
|
216
|
-
multiIndexContext: props.indexContextValue
|
|
217
|
-
};
|
|
218
|
-
return {
|
|
219
|
-
id: id,
|
|
220
|
-
index: (0, _indexUtils.getIndexId)(context),
|
|
221
|
-
items: getCurrentRefinement(props, searchState, context).length > 0 ? [{
|
|
222
|
-
attribute: props.attribute,
|
|
223
|
-
label: "".concat(props.attribute, ": "),
|
|
224
|
-
currentRefinement: getCurrentRefinement(props, searchState, context),
|
|
225
|
-
value: function value(nextState) {
|
|
226
|
-
return _refine(props, nextState, [], context);
|
|
227
|
-
},
|
|
228
|
-
items: getCurrentRefinement(props, searchState, context).map(function (item) {
|
|
229
|
-
return {
|
|
230
|
-
label: (0, _utils.unescapeFacetValue)("".concat(item)),
|
|
231
|
-
value: function value(nextState) {
|
|
232
|
-
var nextSelectedItems = getCurrentRefinement(props, nextState, context).filter(function (other) {
|
|
233
|
-
return other !== item;
|
|
234
|
-
});
|
|
235
|
-
return _refine(props, searchState, nextSelectedItems, context);
|
|
236
|
-
}
|
|
237
|
-
};
|
|
238
|
-
})
|
|
239
|
-
}] : []
|
|
240
|
-
};
|
|
241
|
-
}
|
|
242
|
-
});
|
|
243
|
-
exports.default = _default;
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
var _createConnector = _interopRequireDefault(require("../core/createConnector"));
|
|
8
|
-
var _indexUtils = require("../core/indexUtils");
|
|
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); }
|
|
14
|
-
function getId() {
|
|
15
|
-
return 'relevancyStrictness';
|
|
16
|
-
}
|
|
17
|
-
function getCurrentRefinement(props, searchState, context) {
|
|
18
|
-
var id = getId();
|
|
19
|
-
var currentRefinement = (0, _indexUtils.getCurrentRefinementValue)(props, searchState, context, id);
|
|
20
|
-
return currentRefinement;
|
|
21
|
-
}
|
|
22
|
-
var _default = (0, _createConnector.default)({
|
|
23
|
-
displayName: 'AlgoliaRelevantSort',
|
|
24
|
-
$$type: 'ais.relevantSort',
|
|
25
|
-
getProvidedProps: function getProvidedProps(props, _searchState, searchResults) {
|
|
26
|
-
var results = (0, _indexUtils.getResults)(searchResults, {
|
|
27
|
-
ais: props.contextValue,
|
|
28
|
-
multiIndexContext: props.indexContextValue
|
|
29
|
-
});
|
|
30
|
-
if (!results) {
|
|
31
|
-
return {
|
|
32
|
-
isVirtualReplica: false,
|
|
33
|
-
isRelevantSorted: false
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
return {
|
|
37
|
-
isVirtualReplica: results.appliedRelevancyStrictness !== undefined,
|
|
38
|
-
isRelevantSorted: results.appliedRelevancyStrictness !== undefined && results.appliedRelevancyStrictness > 0
|
|
39
|
-
};
|
|
40
|
-
},
|
|
41
|
-
getSearchParameters: function getSearchParameters(searchParameters, props, searchState) {
|
|
42
|
-
return searchParameters.setQueryParameter('relevancyStrictness', getCurrentRefinement(props, searchState, {
|
|
43
|
-
ais: props.contextValue,
|
|
44
|
-
multiIndexContext: props.indexContextValue
|
|
45
|
-
}));
|
|
46
|
-
},
|
|
47
|
-
refine: function refine(props, searchState, nextRefinement) {
|
|
48
|
-
var nextValue = _defineProperty({}, getId(), nextRefinement);
|
|
49
|
-
var resetPage = true;
|
|
50
|
-
return (0, _indexUtils.refineValue)(searchState, nextValue, {
|
|
51
|
-
ais: props.contextValue,
|
|
52
|
-
multiIndexContext: props.indexContextValue
|
|
53
|
-
}, resetPage);
|
|
54
|
-
}
|
|
55
|
-
});
|
|
56
|
-
exports.default = _default;
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
8
|
-
var _createConnector = _interopRequireDefault(require("../core/createConnector"));
|
|
9
|
-
var _indexUtils = require("../core/indexUtils");
|
|
10
|
-
var _utils = require("../core/utils");
|
|
11
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
12
|
-
/**
|
|
13
|
-
* connectScrollTo connector provides the logic to build a widget that will
|
|
14
|
-
* let the page scroll to a certain point.
|
|
15
|
-
* @name connectScrollTo
|
|
16
|
-
* @kind connector
|
|
17
|
-
* @propType {string} [scrollOn="page"] - Widget searchState key on which to listen for changes, default to the pagination widget.
|
|
18
|
-
* @providedPropType {any} value - the current refinement applied to the widget listened by scrollTo
|
|
19
|
-
* @providedPropType {boolean} hasNotChanged - indicates whether the refinement came from the scrollOn argument (for instance page by default)
|
|
20
|
-
*/
|
|
21
|
-
var _default = (0, _createConnector.default)({
|
|
22
|
-
displayName: 'AlgoliaScrollTo',
|
|
23
|
-
$$type: 'ais.scrollTo',
|
|
24
|
-
propTypes: {
|
|
25
|
-
scrollOn: _propTypes.default.string
|
|
26
|
-
},
|
|
27
|
-
defaultProps: {
|
|
28
|
-
scrollOn: 'page'
|
|
29
|
-
},
|
|
30
|
-
getProvidedProps: function getProvidedProps(props, searchState) {
|
|
31
|
-
var id = props.scrollOn;
|
|
32
|
-
var value = (0, _indexUtils.getCurrentRefinementValue)(props, searchState, {
|
|
33
|
-
ais: props.contextValue,
|
|
34
|
-
multiIndexContext: props.indexContextValue
|
|
35
|
-
}, id, null);
|
|
36
|
-
if (!this._prevSearchState) {
|
|
37
|
-
this._prevSearchState = {};
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
// Get the subpart of the state that interest us
|
|
41
|
-
if ((0, _indexUtils.hasMultipleIndices)({
|
|
42
|
-
ais: props.contextValue,
|
|
43
|
-
multiIndexContext: props.indexContextValue
|
|
44
|
-
})) {
|
|
45
|
-
searchState = searchState.indices ? searchState.indices[(0, _indexUtils.getIndexId)({
|
|
46
|
-
ais: props.contextValue,
|
|
47
|
-
multiIndexContext: props.indexContextValue
|
|
48
|
-
})] : {};
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
// if there is a change in the app that has been triggered by another element
|
|
52
|
-
// than "props.scrollOn (id) or the Configure widget, we need to keep track of
|
|
53
|
-
// the search state to know if there's a change in the app that was not triggered
|
|
54
|
-
// by the props.scrollOn (id) or the Configure widget. This is useful when
|
|
55
|
-
// using ScrollTo in combination of Pagination. As pagination can be change
|
|
56
|
-
// by every widget, we want to scroll only if it cames from the pagination
|
|
57
|
-
// widget itself. We also remove the configure key from the search state to
|
|
58
|
-
// do this comparison because for now configure values are not present in the
|
|
59
|
-
// search state before a first refinement has been made and will false the results.
|
|
60
|
-
// See: https://github.com/algolia/react-instantsearch/issues/164
|
|
61
|
-
var cleanedSearchState = (0, _utils.omit)(searchState, ['configure', id]);
|
|
62
|
-
var hasNotChanged = (0, _utils.shallowEqual)(this._prevSearchState, cleanedSearchState);
|
|
63
|
-
this._prevSearchState = cleanedSearchState;
|
|
64
|
-
return {
|
|
65
|
-
value: value,
|
|
66
|
-
hasNotChanged: hasNotChanged
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
});
|
|
70
|
-
exports.default = _default;
|