react-instantsearch-core 6.40.4 → 7.0.0
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,146 +0,0 @@
|
|
|
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
|
-
var _excluded = ["page"];
|
|
3
|
-
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
4
|
-
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
5
|
-
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
6
|
-
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
7
|
-
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
8
|
-
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
9
|
-
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
10
|
-
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
11
|
-
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
12
|
-
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
13
|
-
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
14
|
-
import isEqual from 'react-fast-compare';
|
|
15
|
-
import createConnector from "../core/createConnector.js";
|
|
16
|
-
import { getCurrentRefinementValue, refineValue, getResults } from "../core/indexUtils.js";
|
|
17
|
-
import { addAbsolutePositions, addQueryID } from "../core/utils.js";
|
|
18
|
-
function getId() {
|
|
19
|
-
return 'page';
|
|
20
|
-
}
|
|
21
|
-
function getCurrentRefinement(props, searchState, context) {
|
|
22
|
-
var id = getId();
|
|
23
|
-
var page = 1;
|
|
24
|
-
var currentRefinement = getCurrentRefinementValue(props, searchState, context, id, page);
|
|
25
|
-
if (typeof currentRefinement === 'string') {
|
|
26
|
-
return parseInt(currentRefinement, 10);
|
|
27
|
-
}
|
|
28
|
-
return currentRefinement;
|
|
29
|
-
}
|
|
30
|
-
function getStateWithoutPage(state) {
|
|
31
|
-
var _ref = state || {},
|
|
32
|
-
page = _ref.page,
|
|
33
|
-
rest = _objectWithoutProperties(_ref, _excluded);
|
|
34
|
-
return rest;
|
|
35
|
-
}
|
|
36
|
-
function getInMemoryCache() {
|
|
37
|
-
var cachedHits = undefined;
|
|
38
|
-
var cachedState = undefined;
|
|
39
|
-
return {
|
|
40
|
-
read: function read(_ref2) {
|
|
41
|
-
var state = _ref2.state;
|
|
42
|
-
return isEqual(cachedState, getStateWithoutPage(state)) ? cachedHits : null;
|
|
43
|
-
},
|
|
44
|
-
write: function write(_ref3) {
|
|
45
|
-
var state = _ref3.state,
|
|
46
|
-
hits = _ref3.hits;
|
|
47
|
-
cachedState = getStateWithoutPage(state);
|
|
48
|
-
cachedHits = hits;
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
function extractHitsFromCachedHits(cachedHits) {
|
|
53
|
-
return Object.keys(cachedHits).map(Number).sort(function (a, b) {
|
|
54
|
-
return a - b;
|
|
55
|
-
}).reduce(function (acc, page) {
|
|
56
|
-
return acc.concat(cachedHits[page]);
|
|
57
|
-
}, []);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* InfiniteHits connector provides the logic to create connected
|
|
62
|
-
* components that will render an continuous list of results retrieved from
|
|
63
|
-
* Algolia. This connector provides a function to load more results.
|
|
64
|
-
* @name connectInfiniteHits
|
|
65
|
-
* @kind connector
|
|
66
|
-
* @providedPropType {array.<object>} hits - the records that matched the search state
|
|
67
|
-
* @providedPropType {boolean} hasMore - indicates if there are more pages to load
|
|
68
|
-
* @providedPropType {function} refine - call to load more results
|
|
69
|
-
*/
|
|
70
|
-
export default createConnector({
|
|
71
|
-
displayName: 'AlgoliaInfiniteHits',
|
|
72
|
-
$$type: 'ais.infiniteHits',
|
|
73
|
-
getProvidedProps: function getProvidedProps(props, searchState, searchResults) {
|
|
74
|
-
var _this = this;
|
|
75
|
-
var results = getResults(searchResults, {
|
|
76
|
-
ais: props.contextValue,
|
|
77
|
-
multiIndexContext: props.indexContextValue
|
|
78
|
-
});
|
|
79
|
-
if (!results) {
|
|
80
|
-
return {
|
|
81
|
-
hits: [],
|
|
82
|
-
hasPrevious: false,
|
|
83
|
-
hasMore: false,
|
|
84
|
-
refine: function refine() {},
|
|
85
|
-
refinePrevious: function refinePrevious() {},
|
|
86
|
-
refineNext: function refineNext() {}
|
|
87
|
-
};
|
|
88
|
-
}
|
|
89
|
-
var page = results.page,
|
|
90
|
-
hits = results.hits,
|
|
91
|
-
hitsPerPage = results.hitsPerPage,
|
|
92
|
-
nbPages = results.nbPages,
|
|
93
|
-
state = results._state;
|
|
94
|
-
this._cache = props.cache ? props.cache : this._cache || getInMemoryCache();
|
|
95
|
-
var cachedHits = this._cache.read({
|
|
96
|
-
state: state
|
|
97
|
-
}) || {};
|
|
98
|
-
var hitsWithPositions = addAbsolutePositions(hits, hitsPerPage, page);
|
|
99
|
-
var hitsWithPositionsAndQueryID = addQueryID(hitsWithPositions, results.queryID);
|
|
100
|
-
cachedHits[page] = hitsWithPositionsAndQueryID;
|
|
101
|
-
this._cache.write({
|
|
102
|
-
state: state,
|
|
103
|
-
hits: cachedHits
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
/*
|
|
107
|
-
Math.min() and Math.max() returns Infinity or -Infinity when no argument is given.
|
|
108
|
-
But there is always something in this point because of `cachedHits[page]`.
|
|
109
|
-
*/
|
|
110
|
-
var firstReceivedPage = Math.min.apply(Math, _toConsumableArray(Object.keys(cachedHits).map(Number)));
|
|
111
|
-
var lastReceivedPage = Math.max.apply(Math, _toConsumableArray(Object.keys(cachedHits).map(Number)));
|
|
112
|
-
var hasPrevious = firstReceivedPage > 0;
|
|
113
|
-
var lastPageIndex = nbPages - 1;
|
|
114
|
-
var hasMore = lastReceivedPage < lastPageIndex;
|
|
115
|
-
var refinePrevious = function refinePrevious(event) {
|
|
116
|
-
return _this.refine(event, firstReceivedPage - 1);
|
|
117
|
-
};
|
|
118
|
-
var refineNext = function refineNext(event) {
|
|
119
|
-
return _this.refine(event, lastReceivedPage + 1);
|
|
120
|
-
};
|
|
121
|
-
return {
|
|
122
|
-
hits: extractHitsFromCachedHits(cachedHits),
|
|
123
|
-
hasPrevious: hasPrevious,
|
|
124
|
-
hasMore: hasMore,
|
|
125
|
-
refinePrevious: refinePrevious,
|
|
126
|
-
refineNext: refineNext
|
|
127
|
-
};
|
|
128
|
-
},
|
|
129
|
-
getSearchParameters: function getSearchParameters(searchParameters, props, searchState) {
|
|
130
|
-
return searchParameters.setQueryParameters({
|
|
131
|
-
page: getCurrentRefinement(props, searchState, {
|
|
132
|
-
ais: props.contextValue,
|
|
133
|
-
multiIndexContext: props.indexContextValue
|
|
134
|
-
}) - 1
|
|
135
|
-
});
|
|
136
|
-
},
|
|
137
|
-
refine: function refine(props, searchState, event, index) {
|
|
138
|
-
var id = getId();
|
|
139
|
-
var nextValue = _defineProperty({}, id, index + 1);
|
|
140
|
-
var resetPage = false;
|
|
141
|
-
return refineValue(searchState, nextValue, {
|
|
142
|
-
ais: props.contextValue,
|
|
143
|
-
multiIndexContext: props.indexContextValue
|
|
144
|
-
}, resetPage);
|
|
145
|
-
}
|
|
146
|
-
});
|
|
@@ -1,213 +0,0 @@
|
|
|
1
|
-
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
2
|
-
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
3
|
-
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
4
|
-
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
5
|
-
import PropTypes from 'prop-types';
|
|
6
|
-
import createConnector from "../core/createConnector.js";
|
|
7
|
-
import { getIndexId, cleanUpValue, refineValue, getCurrentRefinementValue, getResults } from "../core/indexUtils.js";
|
|
8
|
-
import { unescapeFacetValue } from "../core/utils.js";
|
|
9
|
-
var namespace = 'menu';
|
|
10
|
-
function getId(props) {
|
|
11
|
-
return props.attribute;
|
|
12
|
-
}
|
|
13
|
-
function getCurrentRefinement(props, searchState, context) {
|
|
14
|
-
var currentRefinement = getCurrentRefinementValue(props, searchState, context, "".concat(namespace, ".").concat(getId(props)), null);
|
|
15
|
-
if (currentRefinement === '') {
|
|
16
|
-
return null;
|
|
17
|
-
}
|
|
18
|
-
return currentRefinement;
|
|
19
|
-
}
|
|
20
|
-
function getValue(value, props, searchState, context) {
|
|
21
|
-
var currentRefinement = getCurrentRefinement(props, searchState, context);
|
|
22
|
-
return value === currentRefinement ? '' : value;
|
|
23
|
-
}
|
|
24
|
-
function getLimit(_ref) {
|
|
25
|
-
var showMore = _ref.showMore,
|
|
26
|
-
limit = _ref.limit,
|
|
27
|
-
showMoreLimit = _ref.showMoreLimit;
|
|
28
|
-
return showMore ? showMoreLimit : limit;
|
|
29
|
-
}
|
|
30
|
-
function _refine(props, searchState, nextRefinement, context) {
|
|
31
|
-
var id = getId(props);
|
|
32
|
-
var nextValue = _defineProperty({}, id, nextRefinement ? nextRefinement : '');
|
|
33
|
-
var resetPage = true;
|
|
34
|
-
return refineValue(searchState, nextValue, context, resetPage, namespace);
|
|
35
|
-
}
|
|
36
|
-
function _cleanUp(props, searchState, context) {
|
|
37
|
-
return cleanUpValue(searchState, context, "".concat(namespace, ".").concat(getId(props)));
|
|
38
|
-
}
|
|
39
|
-
var defaultSortBy = ['count:desc', 'name:asc'];
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* connectMenu connector provides the logic to build a widget that will
|
|
43
|
-
* give the user the ability to choose a single value for a specific facet.
|
|
44
|
-
* @name connectMenu
|
|
45
|
-
* @requirements The attribute passed to the `attribute` prop must be present in "attributes for faceting"
|
|
46
|
-
* on the Algolia dashboard or configured as `attributesForFaceting` via a set settings call to the Algolia API.
|
|
47
|
-
* @kind connector
|
|
48
|
-
* @propType {string} attribute - the name of the attribute in the record
|
|
49
|
-
* @propType {boolean} [showMore=false] - true if the component should display a button that will expand the number of items
|
|
50
|
-
* @propType {number} [limit=10] - the minimum number of diplayed items
|
|
51
|
-
* @propType {number} [showMoreLimit=20] - the maximun number of displayed items. Only used when showMore is set to `true`
|
|
52
|
-
* @propType {string} [defaultRefinement] - the value of the item selected by default
|
|
53
|
-
* @propType {boolean} [searchable=false] - allow search inside values
|
|
54
|
-
* @providedPropType {function} refine - a function to toggle a refinement
|
|
55
|
-
* @providedPropType {function} createURL - a function to generate a URL for the corresponding search state
|
|
56
|
-
* @providedPropType {string} currentRefinement - the refinement currently applied
|
|
57
|
-
* @providedPropType {array.<{count: number, isRefined: boolean, label: string, value: string}>} items - the list of items the Menu can display.
|
|
58
|
-
* @providedPropType {function} searchForItems - a function to toggle a search inside items values
|
|
59
|
-
* @providedPropType {boolean} isFromSearch - a boolean that says if the `items` props contains facet values from the global search or from the search inside items.
|
|
60
|
-
*/
|
|
61
|
-
export default createConnector({
|
|
62
|
-
displayName: 'AlgoliaMenu',
|
|
63
|
-
$$type: 'ais.menu',
|
|
64
|
-
propTypes: {
|
|
65
|
-
attribute: PropTypes.string.isRequired,
|
|
66
|
-
showMore: PropTypes.bool,
|
|
67
|
-
limit: PropTypes.number,
|
|
68
|
-
showMoreLimit: PropTypes.number,
|
|
69
|
-
defaultRefinement: PropTypes.string,
|
|
70
|
-
transformItems: PropTypes.func,
|
|
71
|
-
searchable: PropTypes.bool,
|
|
72
|
-
facetOrdering: PropTypes.bool
|
|
73
|
-
},
|
|
74
|
-
defaultProps: {
|
|
75
|
-
showMore: false,
|
|
76
|
-
limit: 10,
|
|
77
|
-
showMoreLimit: 20,
|
|
78
|
-
facetOrdering: true
|
|
79
|
-
},
|
|
80
|
-
getProvidedProps: function getProvidedProps(props, searchState, searchResults, meta, searchForFacetValuesResults) {
|
|
81
|
-
var attribute = props.attribute,
|
|
82
|
-
searchable = props.searchable,
|
|
83
|
-
indexContextValue = props.indexContextValue,
|
|
84
|
-
facetOrdering = props.facetOrdering;
|
|
85
|
-
var results = getResults(searchResults, {
|
|
86
|
-
ais: props.contextValue,
|
|
87
|
-
multiIndexContext: props.indexContextValue
|
|
88
|
-
});
|
|
89
|
-
var canRefine = Boolean(results) && Boolean(results.getFacetByName(attribute));
|
|
90
|
-
var isFromSearch = Boolean(searchForFacetValuesResults && searchForFacetValuesResults[attribute] && searchForFacetValuesResults.query !== '');
|
|
91
|
-
|
|
92
|
-
// Search For Facet Values is not available with derived helper (used for multi index search)
|
|
93
|
-
if (searchable && indexContextValue) {
|
|
94
|
-
throw new Error('react-instantsearch: searching in *List is not available when used inside a' + ' multi index context');
|
|
95
|
-
}
|
|
96
|
-
if (!canRefine) {
|
|
97
|
-
return {
|
|
98
|
-
items: [],
|
|
99
|
-
currentRefinement: getCurrentRefinement(props, searchState, {
|
|
100
|
-
ais: props.contextValue,
|
|
101
|
-
multiIndexContext: props.indexContextValue
|
|
102
|
-
}),
|
|
103
|
-
isFromSearch: isFromSearch,
|
|
104
|
-
searchable: searchable,
|
|
105
|
-
canRefine: canRefine
|
|
106
|
-
};
|
|
107
|
-
}
|
|
108
|
-
var items;
|
|
109
|
-
if (isFromSearch) {
|
|
110
|
-
items = searchForFacetValuesResults[attribute].map(function (v) {
|
|
111
|
-
return {
|
|
112
|
-
label: v.value,
|
|
113
|
-
value: getValue(v.escapedValue, props, searchState, {
|
|
114
|
-
ais: props.contextValue,
|
|
115
|
-
multiIndexContext: props.indexContextValue
|
|
116
|
-
}),
|
|
117
|
-
_highlightResult: {
|
|
118
|
-
label: {
|
|
119
|
-
value: v.highlighted
|
|
120
|
-
}
|
|
121
|
-
},
|
|
122
|
-
count: v.count,
|
|
123
|
-
isRefined: v.isRefined
|
|
124
|
-
};
|
|
125
|
-
});
|
|
126
|
-
} else {
|
|
127
|
-
items = results.getFacetValues(attribute, {
|
|
128
|
-
sortBy: searchable ? undefined : defaultSortBy,
|
|
129
|
-
facetOrdering: facetOrdering
|
|
130
|
-
}).map(function (v) {
|
|
131
|
-
return {
|
|
132
|
-
label: v.name,
|
|
133
|
-
value: getValue(v.escapedValue, props, searchState, {
|
|
134
|
-
ais: props.contextValue,
|
|
135
|
-
multiIndexContext: props.indexContextValue
|
|
136
|
-
}),
|
|
137
|
-
count: v.count,
|
|
138
|
-
isRefined: v.isRefined
|
|
139
|
-
};
|
|
140
|
-
});
|
|
141
|
-
}
|
|
142
|
-
var transformedItems = props.transformItems ? props.transformItems(items) : items;
|
|
143
|
-
return {
|
|
144
|
-
items: transformedItems.slice(0, getLimit(props)),
|
|
145
|
-
currentRefinement: getCurrentRefinement(props, searchState, {
|
|
146
|
-
ais: props.contextValue,
|
|
147
|
-
multiIndexContext: props.indexContextValue
|
|
148
|
-
}),
|
|
149
|
-
isFromSearch: isFromSearch,
|
|
150
|
-
searchable: searchable,
|
|
151
|
-
canRefine: transformedItems.length > 0
|
|
152
|
-
};
|
|
153
|
-
},
|
|
154
|
-
refine: function refine(props, searchState, nextRefinement) {
|
|
155
|
-
return _refine(props, searchState, nextRefinement, {
|
|
156
|
-
ais: props.contextValue,
|
|
157
|
-
multiIndexContext: props.indexContextValue
|
|
158
|
-
});
|
|
159
|
-
},
|
|
160
|
-
searchForFacetValues: function searchForFacetValues(props, searchState, nextRefinement) {
|
|
161
|
-
return {
|
|
162
|
-
facetName: props.attribute,
|
|
163
|
-
query: nextRefinement,
|
|
164
|
-
maxFacetHits: getLimit(props)
|
|
165
|
-
};
|
|
166
|
-
},
|
|
167
|
-
cleanUp: function cleanUp(props, searchState) {
|
|
168
|
-
return _cleanUp(props, searchState, {
|
|
169
|
-
ais: props.contextValue,
|
|
170
|
-
multiIndexContext: props.indexContextValue
|
|
171
|
-
});
|
|
172
|
-
},
|
|
173
|
-
getSearchParameters: function getSearchParameters(searchParameters, props, searchState) {
|
|
174
|
-
var attribute = props.attribute;
|
|
175
|
-
searchParameters = searchParameters.setQueryParameters({
|
|
176
|
-
maxValuesPerFacet: Math.max(searchParameters.maxValuesPerFacet || 0, getLimit(props))
|
|
177
|
-
});
|
|
178
|
-
searchParameters = searchParameters.addDisjunctiveFacet(attribute);
|
|
179
|
-
var currentRefinement = getCurrentRefinement(props, searchState, {
|
|
180
|
-
ais: props.contextValue,
|
|
181
|
-
multiIndexContext: props.indexContextValue
|
|
182
|
-
});
|
|
183
|
-
if (currentRefinement !== null) {
|
|
184
|
-
searchParameters = searchParameters.addDisjunctiveFacetRefinement(attribute, currentRefinement);
|
|
185
|
-
}
|
|
186
|
-
return searchParameters;
|
|
187
|
-
},
|
|
188
|
-
getMetadata: function getMetadata(props, searchState) {
|
|
189
|
-
var id = getId(props);
|
|
190
|
-
var currentRefinement = getCurrentRefinement(props, searchState, {
|
|
191
|
-
ais: props.contextValue,
|
|
192
|
-
multiIndexContext: props.indexContextValue
|
|
193
|
-
});
|
|
194
|
-
return {
|
|
195
|
-
id: id,
|
|
196
|
-
index: getIndexId({
|
|
197
|
-
ais: props.contextValue,
|
|
198
|
-
multiIndexContext: props.indexContextValue
|
|
199
|
-
}),
|
|
200
|
-
items: currentRefinement === null ? [] : [{
|
|
201
|
-
label: "".concat(props.attribute, ": ").concat(unescapeFacetValue(currentRefinement)),
|
|
202
|
-
attribute: props.attribute,
|
|
203
|
-
value: function value(nextState) {
|
|
204
|
-
return _refine(props, nextState, '', {
|
|
205
|
-
ais: props.contextValue,
|
|
206
|
-
multiIndexContext: props.indexContextValue
|
|
207
|
-
});
|
|
208
|
-
},
|
|
209
|
-
currentRefinement: currentRefinement
|
|
210
|
-
}]
|
|
211
|
-
};
|
|
212
|
-
}
|
|
213
|
-
});
|
|
@@ -1,207 +0,0 @@
|
|
|
1
|
-
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
2
|
-
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
3
|
-
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
4
|
-
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
5
|
-
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
6
|
-
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
7
|
-
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
8
|
-
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
9
|
-
function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
|
|
10
|
-
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
11
|
-
import PropTypes from 'prop-types';
|
|
12
|
-
import createConnector from "../core/createConnector.js";
|
|
13
|
-
import { cleanUpValue, refineValue, getCurrentRefinementValue, getResults, getIndexId } from "../core/indexUtils.js";
|
|
14
|
-
import { find } from "../core/utils.js";
|
|
15
|
-
function stringifyItem(item) {
|
|
16
|
-
if (typeof item.start === 'undefined' && typeof item.end === 'undefined') {
|
|
17
|
-
return '';
|
|
18
|
-
}
|
|
19
|
-
var start = typeof item.start !== 'undefined' ? item.start : '';
|
|
20
|
-
var end = typeof item.end !== 'undefined' ? item.end : '';
|
|
21
|
-
return "".concat(start, ":").concat(end);
|
|
22
|
-
}
|
|
23
|
-
function parseItem(value) {
|
|
24
|
-
if (value.length === 0) {
|
|
25
|
-
return {
|
|
26
|
-
start: null,
|
|
27
|
-
end: null
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
var _value$split = value.split(':'),
|
|
31
|
-
_value$split2 = _slicedToArray(_value$split, 2),
|
|
32
|
-
startStr = _value$split2[0],
|
|
33
|
-
endStr = _value$split2[1];
|
|
34
|
-
return {
|
|
35
|
-
start: startStr.length > 0 ? parseFloat(startStr) : null,
|
|
36
|
-
end: endStr.length > 0 ? parseFloat(endStr) : null
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
var namespace = 'multiRange';
|
|
40
|
-
function getId(props) {
|
|
41
|
-
return props.attribute;
|
|
42
|
-
}
|
|
43
|
-
function getCurrentRefinement(props, searchState, context) {
|
|
44
|
-
return getCurrentRefinementValue(props, searchState, context, "".concat(namespace, ".").concat(getId(props)), '', function (currentRefinement) {
|
|
45
|
-
if (currentRefinement === '') {
|
|
46
|
-
return '';
|
|
47
|
-
}
|
|
48
|
-
return currentRefinement;
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
function isRefinementsRangeIncludesInsideItemRange(stats, start, end) {
|
|
52
|
-
return stats.min >= start && stats.min <= end || stats.max >= start && stats.max <= end;
|
|
53
|
-
}
|
|
54
|
-
function isItemRangeIncludedInsideRefinementsRange(stats, start, end) {
|
|
55
|
-
return start >= stats.min && start <= stats.max || end >= stats.min && end <= stats.max;
|
|
56
|
-
}
|
|
57
|
-
function itemHasRefinement(attribute, results, value) {
|
|
58
|
-
var stats = results.getFacetByName(attribute) ? results.getFacetStats(attribute) : null;
|
|
59
|
-
var range = value.split(':');
|
|
60
|
-
var start = Number(range[0]) === 0 || value === '' ? Number.NEGATIVE_INFINITY : Number(range[0]);
|
|
61
|
-
var end = Number(range[1]) === 0 || value === '' ? Number.POSITIVE_INFINITY : Number(range[1]);
|
|
62
|
-
return !(Boolean(stats) && (isRefinementsRangeIncludesInsideItemRange(stats, start, end) || isItemRangeIncludedInsideRefinementsRange(stats, start, end)));
|
|
63
|
-
}
|
|
64
|
-
function _refine(props, searchState, nextRefinement, context) {
|
|
65
|
-
var nextValue = _defineProperty({}, getId(props, searchState), nextRefinement);
|
|
66
|
-
var resetPage = true;
|
|
67
|
-
return refineValue(searchState, nextValue, context, resetPage, namespace);
|
|
68
|
-
}
|
|
69
|
-
function _cleanUp(props, searchState, context) {
|
|
70
|
-
return cleanUpValue(searchState, context, "".concat(namespace, ".").concat(getId(props)));
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* connectNumericMenu connector provides the logic to build a widget that will
|
|
75
|
-
* give the user the ability to select a range value for a numeric attribute.
|
|
76
|
-
* Ranges are defined statically.
|
|
77
|
-
* @name connectNumericMenu
|
|
78
|
-
* @requirements The attribute passed to the `attribute` prop must be holding numerical values.
|
|
79
|
-
* @kind connector
|
|
80
|
-
* @propType {string} attribute - the name of the attribute in the records
|
|
81
|
-
* @propType {{label: string, start: number, end: number}[]} items - List of options. With a text label, and upper and lower bounds.
|
|
82
|
-
* @propType {string} [defaultRefinement] - the value of the item selected by default, follow the shape of a `string` with a pattern of `'{start}:{end}'`.
|
|
83
|
-
* @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.
|
|
84
|
-
* @providedPropType {function} refine - a function to select a range.
|
|
85
|
-
* @providedPropType {function} createURL - a function to generate a URL for the corresponding search state
|
|
86
|
-
* @providedPropType {string} currentRefinement - the refinement currently applied. follow the shape of a `string` with a pattern of `'{start}:{end}'` which corresponds to the current selected item. For instance, when the selected item is `{start: 10, end: 20}`, the searchState of the widget is `'10:20'`. When `start` isn't defined, the searchState of the widget is `':{end}'`, and the same way around when `end` isn't defined. However, when neither `start` nor `end` are defined, the searchState is an empty string.
|
|
87
|
-
* @providedPropType {array.<{isRefined: boolean, label: string, value: string, isRefined: boolean, noRefinement: boolean}>} items - the list of ranges the NumericMenu can display.
|
|
88
|
-
*/
|
|
89
|
-
export default createConnector({
|
|
90
|
-
displayName: 'AlgoliaNumericMenu',
|
|
91
|
-
$$type: 'ais.numericMenu',
|
|
92
|
-
propTypes: {
|
|
93
|
-
id: PropTypes.string,
|
|
94
|
-
attribute: PropTypes.string.isRequired,
|
|
95
|
-
items: PropTypes.arrayOf(PropTypes.shape({
|
|
96
|
-
label: PropTypes.node,
|
|
97
|
-
start: PropTypes.number,
|
|
98
|
-
end: PropTypes.number
|
|
99
|
-
})).isRequired,
|
|
100
|
-
transformItems: PropTypes.func
|
|
101
|
-
},
|
|
102
|
-
getProvidedProps: function getProvidedProps(props, searchState, searchResults) {
|
|
103
|
-
var attribute = props.attribute;
|
|
104
|
-
var currentRefinement = getCurrentRefinement(props, searchState, {
|
|
105
|
-
ais: props.contextValue,
|
|
106
|
-
multiIndexContext: props.indexContextValue
|
|
107
|
-
});
|
|
108
|
-
var results = getResults(searchResults, {
|
|
109
|
-
ais: props.contextValue,
|
|
110
|
-
multiIndexContext: props.indexContextValue
|
|
111
|
-
});
|
|
112
|
-
var items = props.items.map(function (item) {
|
|
113
|
-
var value = stringifyItem(item);
|
|
114
|
-
return {
|
|
115
|
-
label: item.label,
|
|
116
|
-
value: value,
|
|
117
|
-
isRefined: value === currentRefinement,
|
|
118
|
-
noRefinement: results ? itemHasRefinement(getId(props), results, value) : false
|
|
119
|
-
};
|
|
120
|
-
});
|
|
121
|
-
var stats = results && results.getFacetByName(attribute) ? results.getFacetStats(attribute) : null;
|
|
122
|
-
var refinedItem = find(items, function (item) {
|
|
123
|
-
return item.isRefined === true;
|
|
124
|
-
});
|
|
125
|
-
if (!items.some(function (item) {
|
|
126
|
-
return item.value === '';
|
|
127
|
-
})) {
|
|
128
|
-
items.push({
|
|
129
|
-
value: '',
|
|
130
|
-
isRefined: refinedItem === undefined,
|
|
131
|
-
noRefinement: !stats,
|
|
132
|
-
label: 'All'
|
|
133
|
-
});
|
|
134
|
-
}
|
|
135
|
-
var transformedItems = props.transformItems ? props.transformItems(items) : items;
|
|
136
|
-
return {
|
|
137
|
-
items: transformedItems,
|
|
138
|
-
currentRefinement: currentRefinement,
|
|
139
|
-
canRefine: transformedItems.length > 0 && transformedItems.some(function (item) {
|
|
140
|
-
return item.noRefinement === false;
|
|
141
|
-
})
|
|
142
|
-
};
|
|
143
|
-
},
|
|
144
|
-
refine: function refine(props, searchState, nextRefinement) {
|
|
145
|
-
return _refine(props, searchState, nextRefinement, {
|
|
146
|
-
ais: props.contextValue,
|
|
147
|
-
multiIndexContext: props.indexContextValue
|
|
148
|
-
});
|
|
149
|
-
},
|
|
150
|
-
cleanUp: function cleanUp(props, searchState) {
|
|
151
|
-
return _cleanUp(props, searchState, {
|
|
152
|
-
ais: props.contextValue,
|
|
153
|
-
multiIndexContext: props.indexContextValue
|
|
154
|
-
});
|
|
155
|
-
},
|
|
156
|
-
getSearchParameters: function getSearchParameters(searchParameters, props, searchState) {
|
|
157
|
-
var attribute = props.attribute;
|
|
158
|
-
var _parseItem = parseItem(getCurrentRefinement(props, searchState, {
|
|
159
|
-
ais: props.contextValue,
|
|
160
|
-
multiIndexContext: props.indexContextValue
|
|
161
|
-
})),
|
|
162
|
-
start = _parseItem.start,
|
|
163
|
-
end = _parseItem.end;
|
|
164
|
-
searchParameters = searchParameters.addDisjunctiveFacet(attribute);
|
|
165
|
-
if (typeof start === 'number') {
|
|
166
|
-
searchParameters = searchParameters.addNumericRefinement(attribute, '>=', start);
|
|
167
|
-
}
|
|
168
|
-
if (typeof end === 'number') {
|
|
169
|
-
searchParameters = searchParameters.addNumericRefinement(attribute, '<=', end);
|
|
170
|
-
}
|
|
171
|
-
return searchParameters;
|
|
172
|
-
},
|
|
173
|
-
getMetadata: function getMetadata(props, searchState) {
|
|
174
|
-
var id = getId(props);
|
|
175
|
-
var value = getCurrentRefinement(props, searchState, {
|
|
176
|
-
ais: props.contextValue,
|
|
177
|
-
multiIndexContext: props.indexContextValue
|
|
178
|
-
});
|
|
179
|
-
var items = [];
|
|
180
|
-
var index = getIndexId({
|
|
181
|
-
ais: props.contextValue,
|
|
182
|
-
multiIndexContext: props.indexContextValue
|
|
183
|
-
});
|
|
184
|
-
if (value !== '') {
|
|
185
|
-
var _find = find(props.items, function (item) {
|
|
186
|
-
return stringifyItem(item) === value;
|
|
187
|
-
}),
|
|
188
|
-
label = _find.label;
|
|
189
|
-
items.push({
|
|
190
|
-
label: "".concat(props.attribute, ": ").concat(label),
|
|
191
|
-
attribute: props.attribute,
|
|
192
|
-
currentRefinement: label,
|
|
193
|
-
value: function value(nextState) {
|
|
194
|
-
return _refine(props, nextState, '', {
|
|
195
|
-
ais: props.contextValue,
|
|
196
|
-
multiIndexContext: props.indexContextValue
|
|
197
|
-
});
|
|
198
|
-
}
|
|
199
|
-
});
|
|
200
|
-
}
|
|
201
|
-
return {
|
|
202
|
-
id: id,
|
|
203
|
-
index: index,
|
|
204
|
-
items: items
|
|
205
|
-
};
|
|
206
|
-
}
|
|
207
|
-
});
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
2
|
-
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
3
|
-
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
4
|
-
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
5
|
-
import createConnector from "../core/createConnector.js";
|
|
6
|
-
import { cleanUpValue, refineValue, getCurrentRefinementValue, getResults } from "../core/indexUtils.js";
|
|
7
|
-
function getId() {
|
|
8
|
-
return 'page';
|
|
9
|
-
}
|
|
10
|
-
function getCurrentRefinement(props, searchState, context) {
|
|
11
|
-
var id = getId();
|
|
12
|
-
var page = 1;
|
|
13
|
-
var currentRefinement = getCurrentRefinementValue(props, searchState, context, id, page);
|
|
14
|
-
if (typeof currentRefinement === 'string') {
|
|
15
|
-
return parseInt(currentRefinement, 10);
|
|
16
|
-
}
|
|
17
|
-
return currentRefinement;
|
|
18
|
-
}
|
|
19
|
-
function _refine(props, searchState, nextPage, context) {
|
|
20
|
-
var id = getId();
|
|
21
|
-
var nextValue = _defineProperty({}, id, nextPage);
|
|
22
|
-
var resetPage = false;
|
|
23
|
-
return refineValue(searchState, nextValue, context, resetPage);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* connectPagination connector provides the logic to build a widget that will
|
|
28
|
-
* let the user displays hits corresponding to a certain page.
|
|
29
|
-
* @name connectPagination
|
|
30
|
-
* @kind connector
|
|
31
|
-
* @propType {boolean} [showFirst=true] - Display the first page link.
|
|
32
|
-
* @propType {boolean} [showLast=false] - Display the last page link.
|
|
33
|
-
* @propType {boolean} [showPrevious=true] - Display the previous page link.
|
|
34
|
-
* @propType {boolean} [showNext=true] - Display the next page link.
|
|
35
|
-
* @propType {number} [padding=3] - How many page links to display around the current page.
|
|
36
|
-
* @propType {number} [totalPages=Infinity] - Maximum number of pages to display.
|
|
37
|
-
* @providedPropType {function} refine - a function to remove a single filter
|
|
38
|
-
* @providedPropType {function} createURL - a function to generate a URL for the corresponding search state
|
|
39
|
-
* @providedPropType {number} nbPages - the total of existing pages
|
|
40
|
-
* @providedPropType {number} currentRefinement - the page refinement currently applied
|
|
41
|
-
*/
|
|
42
|
-
export default createConnector({
|
|
43
|
-
displayName: 'AlgoliaPagination',
|
|
44
|
-
$$type: 'ais.pagination',
|
|
45
|
-
getProvidedProps: function getProvidedProps(props, searchState, searchResults) {
|
|
46
|
-
var results = getResults(searchResults, {
|
|
47
|
-
ais: props.contextValue,
|
|
48
|
-
multiIndexContext: props.indexContextValue
|
|
49
|
-
});
|
|
50
|
-
if (!results) {
|
|
51
|
-
return null;
|
|
52
|
-
}
|
|
53
|
-
var nbPages = results.nbPages;
|
|
54
|
-
return {
|
|
55
|
-
nbPages: nbPages,
|
|
56
|
-
currentRefinement: getCurrentRefinement(props, searchState, {
|
|
57
|
-
ais: props.contextValue,
|
|
58
|
-
multiIndexContext: props.indexContextValue
|
|
59
|
-
}),
|
|
60
|
-
canRefine: nbPages > 1
|
|
61
|
-
};
|
|
62
|
-
},
|
|
63
|
-
refine: function refine(props, searchState, nextPage) {
|
|
64
|
-
return _refine(props, searchState, nextPage, {
|
|
65
|
-
ais: props.contextValue,
|
|
66
|
-
multiIndexContext: props.indexContextValue
|
|
67
|
-
});
|
|
68
|
-
},
|
|
69
|
-
cleanUp: function cleanUp(props, searchState) {
|
|
70
|
-
return cleanUpValue(searchState, {
|
|
71
|
-
ais: props.contextValue,
|
|
72
|
-
multiIndexContext: props.indexContextValue
|
|
73
|
-
}, getId());
|
|
74
|
-
},
|
|
75
|
-
getSearchParameters: function getSearchParameters(searchParameters, props, searchState) {
|
|
76
|
-
return searchParameters.setPage(getCurrentRefinement(props, searchState, {
|
|
77
|
-
ais: props.contextValue,
|
|
78
|
-
multiIndexContext: props.indexContextValue
|
|
79
|
-
}) - 1);
|
|
80
|
-
},
|
|
81
|
-
getMetadata: function getMetadata() {
|
|
82
|
-
return {
|
|
83
|
-
id: getId()
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
|
-
});
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import createConnector from "../core/createConnector.js";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* connectPoweredBy connector provides the logic to build a widget that
|
|
5
|
-
* will display a link to algolia.
|
|
6
|
-
* @name connectPoweredBy
|
|
7
|
-
* @kind connector
|
|
8
|
-
* @providedPropType {string} url - the url to redirect to algolia
|
|
9
|
-
*/
|
|
10
|
-
export default createConnector({
|
|
11
|
-
displayName: 'AlgoliaPoweredBy',
|
|
12
|
-
$$type: 'ais.poweredBy',
|
|
13
|
-
getProvidedProps: function getProvidedProps() {
|
|
14
|
-
var hostname = typeof window === 'undefined' || typeof window.location === 'undefined' ? '' : window.location.hostname;
|
|
15
|
-
var url = 'https://www.algolia.com/?' + 'utm_source=react-instantsearch&' + 'utm_medium=website&' + "utm_content=".concat(hostname, "&") + 'utm_campaign=poweredby';
|
|
16
|
-
return {
|
|
17
|
-
url: url
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
});
|