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,189 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
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); }
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.default = void 0;
|
|
8
|
-
var _createConnector = _interopRequireDefault(require("../core/createConnector"));
|
|
9
|
-
var _indexUtils = require("../core/indexUtils");
|
|
10
|
-
var _utils = require("../core/utils");
|
|
11
|
-
var _excluded = ["defaultRefinement"];
|
|
12
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: 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
|
-
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; }
|
|
17
|
-
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; }
|
|
18
|
-
/**
|
|
19
|
-
* The GeoSearch connector provides the logic to build a widget that will display the results on a map.
|
|
20
|
-
* It also provides a way to search for results based on their position. The connector provides function to manage the search experience (search on map interaction).
|
|
21
|
-
* @name connectGeoSearch
|
|
22
|
-
* @kind connector
|
|
23
|
-
* @requirements Note that the GeoSearch connector uses the [geosearch](https://www.algolia.com/doc/guides/searching/geo-search) capabilities of Algolia.
|
|
24
|
-
* Your hits **must** have a `_geoloc` attribute in order to be passed to the rendering function. Currently, the feature is not compatible with multiple values in the `_geoloc` attribute
|
|
25
|
-
* (e.g. a restaurant with multiple locations). In that case you can duplicate your records and use the [distinct](https://www.algolia.com/doc/guides/ranking/distinct) feature of Algolia to only retrieve unique results.
|
|
26
|
-
* @propType {{ northEast: { lat: number, lng: number }, southWest: { lat: number, lng: number } }} [defaultRefinement] - Default search state of the widget containing the bounds for the map
|
|
27
|
-
* @providedPropType {function({ northEast: { lat: number, lng: number }, southWest: { lat: number, lng: number } })} refine - a function to toggle the refinement
|
|
28
|
-
* @providedPropType {function} createURL - a function to generate a URL for the corresponding search state
|
|
29
|
-
* @providedPropType {array.<object>} hits - the records that matched the search
|
|
30
|
-
* @providedPropType {boolean} isRefinedWithMap - true if the current refinement is set with the map bounds
|
|
31
|
-
* @providedPropType {{ northEast: { lat: number, lng: number }, southWest: { lat: number, lng: number } }} [currentRefinement] - the refinement currently applied
|
|
32
|
-
* @providedPropType {{ lat: number, lng: number }} [position] - the position of the search
|
|
33
|
-
*/
|
|
34
|
-
|
|
35
|
-
// To control the map with an external widget the other widget
|
|
36
|
-
// **must** write the value in the attribute `aroundLatLng`
|
|
37
|
-
var getBoundingBoxId = function getBoundingBoxId() {
|
|
38
|
-
return 'boundingBox';
|
|
39
|
-
};
|
|
40
|
-
var getAroundLatLngId = function getAroundLatLngId() {
|
|
41
|
-
return 'aroundLatLng';
|
|
42
|
-
};
|
|
43
|
-
var getConfigureAroundLatLngId = function getConfigureAroundLatLngId() {
|
|
44
|
-
return 'configure.aroundLatLng';
|
|
45
|
-
};
|
|
46
|
-
var currentRefinementToString = function currentRefinementToString(currentRefinement) {
|
|
47
|
-
return [currentRefinement.northEast.lat, currentRefinement.northEast.lng, currentRefinement.southWest.lat, currentRefinement.southWest.lng].join();
|
|
48
|
-
};
|
|
49
|
-
var stringToCurrentRefinement = function stringToCurrentRefinement(value) {
|
|
50
|
-
var values = value.split(',');
|
|
51
|
-
return {
|
|
52
|
-
northEast: {
|
|
53
|
-
lat: parseFloat(values[0]),
|
|
54
|
-
lng: parseFloat(values[1])
|
|
55
|
-
},
|
|
56
|
-
southWest: {
|
|
57
|
-
lat: parseFloat(values[2]),
|
|
58
|
-
lng: parseFloat(values[3])
|
|
59
|
-
}
|
|
60
|
-
};
|
|
61
|
-
};
|
|
62
|
-
var latLngRegExp = /^(-?\d+(?:\.\d+)?),\s*(-?\d+(?:\.\d+)?)$/;
|
|
63
|
-
var stringToPosition = function stringToPosition(value) {
|
|
64
|
-
var pattern = value.match(latLngRegExp);
|
|
65
|
-
return {
|
|
66
|
-
lat: parseFloat(pattern[1]),
|
|
67
|
-
lng: parseFloat(pattern[2])
|
|
68
|
-
};
|
|
69
|
-
};
|
|
70
|
-
var getCurrentRefinement = function getCurrentRefinement(props, searchState, context) {
|
|
71
|
-
var refinement = (0, _indexUtils.getCurrentRefinementValue)(props, searchState, context, getBoundingBoxId(), {});
|
|
72
|
-
if (!(0, _utils.objectHasKeys)(refinement)) {
|
|
73
|
-
return;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
// eslint-disable-next-line consistent-return
|
|
77
|
-
return {
|
|
78
|
-
northEast: {
|
|
79
|
-
lat: parseFloat(refinement.northEast.lat),
|
|
80
|
-
lng: parseFloat(refinement.northEast.lng)
|
|
81
|
-
},
|
|
82
|
-
southWest: {
|
|
83
|
-
lat: parseFloat(refinement.southWest.lat),
|
|
84
|
-
lng: parseFloat(refinement.southWest.lng)
|
|
85
|
-
}
|
|
86
|
-
};
|
|
87
|
-
};
|
|
88
|
-
var getCurrentPosition = function getCurrentPosition(props, searchState, context) {
|
|
89
|
-
var defaultRefinement = props.defaultRefinement,
|
|
90
|
-
propsWithoutDefaultRefinement = _objectWithoutProperties(props, _excluded);
|
|
91
|
-
var aroundLatLng = (0, _indexUtils.getCurrentRefinementValue)(propsWithoutDefaultRefinement, searchState, context, getAroundLatLngId());
|
|
92
|
-
if (!aroundLatLng) {
|
|
93
|
-
// Fallback on `configure.aroundLatLng`
|
|
94
|
-
var configureAroundLatLng = (0, _indexUtils.getCurrentRefinementValue)(propsWithoutDefaultRefinement, searchState, context, getConfigureAroundLatLngId());
|
|
95
|
-
return configureAroundLatLng && stringToPosition(configureAroundLatLng);
|
|
96
|
-
}
|
|
97
|
-
return aroundLatLng;
|
|
98
|
-
};
|
|
99
|
-
var _refine = function refine(searchState, nextValue, context) {
|
|
100
|
-
var resetPage = true;
|
|
101
|
-
var nextRefinement = _defineProperty({}, getBoundingBoxId(), nextValue);
|
|
102
|
-
return (0, _indexUtils.refineValue)(searchState, nextRefinement, context, resetPage);
|
|
103
|
-
};
|
|
104
|
-
var _default = (0, _createConnector.default)({
|
|
105
|
-
displayName: 'AlgoliaGeoSearch',
|
|
106
|
-
$$type: 'ais.geoSearch',
|
|
107
|
-
getProvidedProps: function getProvidedProps(props, searchState, searchResults) {
|
|
108
|
-
var context = {
|
|
109
|
-
ais: props.contextValue,
|
|
110
|
-
multiIndexContext: props.indexContextValue
|
|
111
|
-
};
|
|
112
|
-
var results = (0, _indexUtils.getResults)(searchResults, context);
|
|
113
|
-
|
|
114
|
-
// We read it from both because the SearchParameters & the searchState are not always
|
|
115
|
-
// in sync. When we set the refinement the searchState is used but when we clear the refinement
|
|
116
|
-
// the SearchParameters is used. In the first case when we render, the results are not there
|
|
117
|
-
// so we can't find the value from the results. The most up to date value is the searchState.
|
|
118
|
-
// But when we clear the refinement the searchState is immediately cleared even when the items
|
|
119
|
-
// retrieved are still the one from the previous query with the bounding box. It leads to some
|
|
120
|
-
// issue with the position of the map. We should rely on 1 source of truth or at least always
|
|
121
|
-
// be sync.
|
|
122
|
-
|
|
123
|
-
var currentRefinementFromSearchState = getCurrentRefinement(props, searchState, context);
|
|
124
|
-
var currentRefinementFromSearchParameters = results && results._state.insideBoundingBox && stringToCurrentRefinement(results._state.insideBoundingBox) || undefined;
|
|
125
|
-
var currentPositionFromSearchState = getCurrentPosition(props, searchState, context);
|
|
126
|
-
var currentPositionFromSearchParameters = results && results._state.aroundLatLng && stringToPosition(results._state.aroundLatLng) || undefined;
|
|
127
|
-
var currentRefinement = currentRefinementFromSearchState || currentRefinementFromSearchParameters;
|
|
128
|
-
var position = currentPositionFromSearchState || currentPositionFromSearchParameters;
|
|
129
|
-
return {
|
|
130
|
-
hits: !results ? [] : results.hits.filter(function (_) {
|
|
131
|
-
return Boolean(_._geoloc);
|
|
132
|
-
}),
|
|
133
|
-
isRefinedWithMap: Boolean(currentRefinement),
|
|
134
|
-
currentRefinement: currentRefinement,
|
|
135
|
-
position: position
|
|
136
|
-
};
|
|
137
|
-
},
|
|
138
|
-
refine: function refine(props, searchState, nextValue) {
|
|
139
|
-
return _refine(searchState, nextValue, {
|
|
140
|
-
ais: props.contextValue,
|
|
141
|
-
multiIndexContext: props.indexContextValue
|
|
142
|
-
});
|
|
143
|
-
},
|
|
144
|
-
getSearchParameters: function getSearchParameters(searchParameters, props, searchState) {
|
|
145
|
-
var currentRefinement = getCurrentRefinement(props, searchState, {
|
|
146
|
-
ais: props.contextValue,
|
|
147
|
-
multiIndexContext: props.indexContextValue
|
|
148
|
-
});
|
|
149
|
-
if (!currentRefinement) {
|
|
150
|
-
return searchParameters;
|
|
151
|
-
}
|
|
152
|
-
return searchParameters.setQueryParameter('insideBoundingBox', currentRefinementToString(currentRefinement));
|
|
153
|
-
},
|
|
154
|
-
cleanUp: function cleanUp(props, searchState) {
|
|
155
|
-
return (0, _indexUtils.cleanUpValue)(searchState, {
|
|
156
|
-
ais: props.contextValue,
|
|
157
|
-
multiIndexContext: props.indexContextValue
|
|
158
|
-
}, getBoundingBoxId());
|
|
159
|
-
},
|
|
160
|
-
getMetadata: function getMetadata(props, searchState) {
|
|
161
|
-
var items = [];
|
|
162
|
-
var id = getBoundingBoxId();
|
|
163
|
-
var context = {
|
|
164
|
-
ais: props.contextValue,
|
|
165
|
-
multiIndexContext: props.indexContextValue
|
|
166
|
-
};
|
|
167
|
-
var index = (0, _indexUtils.getIndexId)(context);
|
|
168
|
-
var nextRefinement = {};
|
|
169
|
-
var currentRefinement = getCurrentRefinement(props, searchState, context);
|
|
170
|
-
if (currentRefinement) {
|
|
171
|
-
items.push({
|
|
172
|
-
label: "".concat(id, ": ").concat(currentRefinementToString(currentRefinement)),
|
|
173
|
-
value: function value(nextState) {
|
|
174
|
-
return _refine(nextState, nextRefinement, context);
|
|
175
|
-
},
|
|
176
|
-
currentRefinement: currentRefinement
|
|
177
|
-
});
|
|
178
|
-
}
|
|
179
|
-
return {
|
|
180
|
-
id: id,
|
|
181
|
-
index: index,
|
|
182
|
-
items: items
|
|
183
|
-
};
|
|
184
|
-
},
|
|
185
|
-
shouldComponentUpdate: function shouldComponentUpdate() {
|
|
186
|
-
return true;
|
|
187
|
-
}
|
|
188
|
-
});
|
|
189
|
-
exports.default = _default;
|
|
@@ -1,273 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.getId = exports.default = void 0;
|
|
7
|
-
var _algoliasearchHelper = _interopRequireDefault(require("algoliasearch-helper"));
|
|
8
|
-
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
9
|
-
var _createConnector = _interopRequireDefault(require("../core/createConnector"));
|
|
10
|
-
var _indexUtils = require("../core/indexUtils");
|
|
11
|
-
var _utils = require("../core/utils");
|
|
12
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
-
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); }
|
|
14
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
15
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
16
|
-
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; }
|
|
17
|
-
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
18
|
-
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); }
|
|
19
|
-
var getId = function getId(props) {
|
|
20
|
-
return props.attributes[0];
|
|
21
|
-
};
|
|
22
|
-
exports.getId = getId;
|
|
23
|
-
var namespace = 'hierarchicalMenu';
|
|
24
|
-
function getCurrentRefinement(props, searchState, context) {
|
|
25
|
-
var currentRefinement = (0, _indexUtils.getCurrentRefinementValue)(props, searchState, context, "".concat(namespace, ".").concat(getId(props)), null);
|
|
26
|
-
if (currentRefinement === '') {
|
|
27
|
-
return null;
|
|
28
|
-
}
|
|
29
|
-
return currentRefinement;
|
|
30
|
-
}
|
|
31
|
-
function getValue(value, props, searchState, context) {
|
|
32
|
-
var id = props.id,
|
|
33
|
-
attributes = props.attributes,
|
|
34
|
-
separator = props.separator,
|
|
35
|
-
rootPath = props.rootPath,
|
|
36
|
-
showParentLevel = props.showParentLevel;
|
|
37
|
-
var currentRefinement = getCurrentRefinement(props, searchState, context);
|
|
38
|
-
var nextRefinement;
|
|
39
|
-
if (currentRefinement === null) {
|
|
40
|
-
nextRefinement = value;
|
|
41
|
-
} else {
|
|
42
|
-
var tmpSearchParameters = new _algoliasearchHelper.default.SearchParameters({
|
|
43
|
-
hierarchicalFacets: [{
|
|
44
|
-
name: id,
|
|
45
|
-
attributes: attributes,
|
|
46
|
-
separator: separator,
|
|
47
|
-
rootPath: rootPath,
|
|
48
|
-
showParentLevel: showParentLevel
|
|
49
|
-
}]
|
|
50
|
-
});
|
|
51
|
-
nextRefinement = tmpSearchParameters.toggleHierarchicalFacetRefinement(id, currentRefinement).toggleHierarchicalFacetRefinement(id, value).getHierarchicalRefinement(id)[0];
|
|
52
|
-
}
|
|
53
|
-
return nextRefinement;
|
|
54
|
-
}
|
|
55
|
-
function transformValue(value, props, searchState, context) {
|
|
56
|
-
return value.map(function (v) {
|
|
57
|
-
return {
|
|
58
|
-
label: v.name,
|
|
59
|
-
value: getValue(v.escapedValue, props, searchState, context),
|
|
60
|
-
count: v.count,
|
|
61
|
-
isRefined: v.isRefined,
|
|
62
|
-
items: v.data && transformValue(v.data, props, searchState, context)
|
|
63
|
-
};
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
var truncate = function truncate() {
|
|
67
|
-
var items = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
68
|
-
var limit = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 10;
|
|
69
|
-
return items.slice(0, limit).map(function () {
|
|
70
|
-
var item = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
71
|
-
return Array.isArray(item.items) ? _objectSpread(_objectSpread({}, item), {}, {
|
|
72
|
-
items: truncate(item.items, limit)
|
|
73
|
-
}) : item;
|
|
74
|
-
});
|
|
75
|
-
};
|
|
76
|
-
function _refine(props, searchState, nextRefinement, context) {
|
|
77
|
-
var id = getId(props);
|
|
78
|
-
var nextValue = _defineProperty({}, id, nextRefinement || '');
|
|
79
|
-
var resetPage = true;
|
|
80
|
-
return (0, _indexUtils.refineValue)(searchState, nextValue, context, resetPage, namespace);
|
|
81
|
-
}
|
|
82
|
-
function _cleanUp(props, searchState, context) {
|
|
83
|
-
return (0, _indexUtils.cleanUpValue)(searchState, context, "".concat(namespace, ".").concat(getId(props)));
|
|
84
|
-
}
|
|
85
|
-
var sortBy = ['name:asc'];
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* connectHierarchicalMenu connector provides the logic to build a widget that will
|
|
89
|
-
* give the user the ability to explore a tree-like structure.
|
|
90
|
-
* This is commonly used for multi-level categorization of products on e-commerce
|
|
91
|
-
* websites. From a UX point of view, we suggest not displaying more than two levels deep.
|
|
92
|
-
* @name connectHierarchicalMenu
|
|
93
|
-
* @requirements To use this widget, your attributes must be formatted in a specific way.
|
|
94
|
-
* If you want for example to have a hierarchical menu of categories, objects in your index
|
|
95
|
-
* should be formatted this way:
|
|
96
|
-
*
|
|
97
|
-
* ```json
|
|
98
|
-
* {
|
|
99
|
-
* "categories.lvl0": "products",
|
|
100
|
-
* "categories.lvl1": "products > fruits",
|
|
101
|
-
* "categories.lvl2": "products > fruits > citrus"
|
|
102
|
-
* }
|
|
103
|
-
* ```
|
|
104
|
-
*
|
|
105
|
-
* It's also possible to provide more than one path for each level:
|
|
106
|
-
*
|
|
107
|
-
* ```json
|
|
108
|
-
* {
|
|
109
|
-
* "categories.lvl0": ["products", "goods"],
|
|
110
|
-
* "categories.lvl1": ["products > fruits", "goods > to eat"]
|
|
111
|
-
* }
|
|
112
|
-
* ```
|
|
113
|
-
*
|
|
114
|
-
* All attributes passed to the `attributes` prop must be present in "attributes for faceting"
|
|
115
|
-
* on the Algolia dashboard or configured as `attributesForFaceting` via a set settings call to the Algolia API.
|
|
116
|
-
*
|
|
117
|
-
* @kind connector
|
|
118
|
-
* @propType {array.<string>} attributes - List of attributes to use to generate the hierarchy of the menu. See the example for the convention to follow.
|
|
119
|
-
* @propType {string} [defaultRefinement] - the item value selected by default
|
|
120
|
-
* @propType {boolean} [showMore=false] - Flag to activate the show more button, for toggling the number of items between limit and showMoreLimit.
|
|
121
|
-
* @propType {number} [limit=10] - The maximum number of items displayed.
|
|
122
|
-
* @propType {number} [showMoreLimit=20] - The maximum number of items displayed when the user triggers the show more. Not considered if `showMore` is false.
|
|
123
|
-
* @propType {string} [separator='>'] - Specifies the level separator used in the data.
|
|
124
|
-
* @propType {string} [rootPath=null] - The path to use if the first level is not the root level.
|
|
125
|
-
* @propType {boolean} [showParentLevel=true] - Flag to set if the parent level should be displayed.
|
|
126
|
-
* @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.
|
|
127
|
-
* @providedPropType {function} refine - a function to toggle a refinement
|
|
128
|
-
* @providedPropType {function} createURL - a function to generate a URL for the corresponding search state
|
|
129
|
-
* @providedPropType {string} currentRefinement - the refinement currently applied
|
|
130
|
-
* @providedPropType {array.<{items: object, count: number, isRefined: boolean, label: string, value: string}>} items - the list of items the HierarchicalMenu can display. items has the same shape as parent items.
|
|
131
|
-
*/
|
|
132
|
-
var _default = (0, _createConnector.default)({
|
|
133
|
-
displayName: 'AlgoliaHierarchicalMenu',
|
|
134
|
-
$$type: 'ais.hierarchicalMenu',
|
|
135
|
-
propTypes: {
|
|
136
|
-
attributes: function attributes(props, propName, componentName) {
|
|
137
|
-
var isNotString = function isNotString(val) {
|
|
138
|
-
return typeof val !== 'string';
|
|
139
|
-
};
|
|
140
|
-
if (!Array.isArray(props[propName]) || props[propName].some(isNotString) || props[propName].length < 1) {
|
|
141
|
-
return new Error("Invalid prop ".concat(propName, " supplied to ").concat(componentName, ". Expected an Array of Strings"));
|
|
142
|
-
}
|
|
143
|
-
return undefined;
|
|
144
|
-
},
|
|
145
|
-
separator: _propTypes.default.string,
|
|
146
|
-
rootPath: _propTypes.default.string,
|
|
147
|
-
showParentLevel: _propTypes.default.bool,
|
|
148
|
-
defaultRefinement: _propTypes.default.string,
|
|
149
|
-
showMore: _propTypes.default.bool,
|
|
150
|
-
limit: _propTypes.default.number,
|
|
151
|
-
showMoreLimit: _propTypes.default.number,
|
|
152
|
-
transformItems: _propTypes.default.func,
|
|
153
|
-
facetOrdering: _propTypes.default.bool
|
|
154
|
-
},
|
|
155
|
-
defaultProps: {
|
|
156
|
-
showMore: false,
|
|
157
|
-
limit: 10,
|
|
158
|
-
showMoreLimit: 20,
|
|
159
|
-
separator: ' > ',
|
|
160
|
-
rootPath: null,
|
|
161
|
-
showParentLevel: true,
|
|
162
|
-
facetOrdering: true
|
|
163
|
-
},
|
|
164
|
-
getProvidedProps: function getProvidedProps(props, searchState, searchResults) {
|
|
165
|
-
var showMore = props.showMore,
|
|
166
|
-
limit = props.limit,
|
|
167
|
-
showMoreLimit = props.showMoreLimit,
|
|
168
|
-
facetOrdering = props.facetOrdering;
|
|
169
|
-
var id = getId(props);
|
|
170
|
-
var results = (0, _indexUtils.getResults)(searchResults, {
|
|
171
|
-
ais: props.contextValue,
|
|
172
|
-
multiIndexContext: props.indexContextValue
|
|
173
|
-
});
|
|
174
|
-
var isFacetPresent = Boolean(results) && Boolean(results.getFacetByName(id));
|
|
175
|
-
if (!isFacetPresent) {
|
|
176
|
-
return {
|
|
177
|
-
items: [],
|
|
178
|
-
currentRefinement: getCurrentRefinement(props, searchState, {
|
|
179
|
-
ais: props.contextValue,
|
|
180
|
-
multiIndexContext: props.indexContextValue
|
|
181
|
-
}),
|
|
182
|
-
canRefine: false
|
|
183
|
-
};
|
|
184
|
-
}
|
|
185
|
-
var itemsLimit = showMore ? showMoreLimit : limit;
|
|
186
|
-
var value = results.getFacetValues(id, {
|
|
187
|
-
sortBy: sortBy,
|
|
188
|
-
facetOrdering: facetOrdering
|
|
189
|
-
});
|
|
190
|
-
var items = value.data ? transformValue(value.data, props, searchState, {
|
|
191
|
-
ais: props.contextValue,
|
|
192
|
-
multiIndexContext: props.indexContextValue
|
|
193
|
-
}) : [];
|
|
194
|
-
var transformedItems = props.transformItems ? props.transformItems(items) : items;
|
|
195
|
-
return {
|
|
196
|
-
items: truncate(transformedItems, itemsLimit),
|
|
197
|
-
currentRefinement: getCurrentRefinement(props, searchState, {
|
|
198
|
-
ais: props.contextValue,
|
|
199
|
-
multiIndexContext: props.indexContextValue
|
|
200
|
-
}),
|
|
201
|
-
canRefine: transformedItems.length > 0
|
|
202
|
-
};
|
|
203
|
-
},
|
|
204
|
-
refine: function refine(props, searchState, nextRefinement) {
|
|
205
|
-
return _refine(props, searchState, nextRefinement, {
|
|
206
|
-
ais: props.contextValue,
|
|
207
|
-
multiIndexContext: props.indexContextValue
|
|
208
|
-
});
|
|
209
|
-
},
|
|
210
|
-
cleanUp: function cleanUp(props, searchState) {
|
|
211
|
-
return _cleanUp(props, searchState, {
|
|
212
|
-
ais: props.contextValue,
|
|
213
|
-
multiIndexContext: props.indexContextValue
|
|
214
|
-
});
|
|
215
|
-
},
|
|
216
|
-
getSearchParameters: function getSearchParameters(searchParameters, props, searchState) {
|
|
217
|
-
var attributes = props.attributes,
|
|
218
|
-
separator = props.separator,
|
|
219
|
-
rootPath = props.rootPath,
|
|
220
|
-
showParentLevel = props.showParentLevel,
|
|
221
|
-
showMore = props.showMore,
|
|
222
|
-
limit = props.limit,
|
|
223
|
-
showMoreLimit = props.showMoreLimit,
|
|
224
|
-
contextValue = props.contextValue;
|
|
225
|
-
var id = getId(props);
|
|
226
|
-
var itemsLimit = showMore ? showMoreLimit : limit;
|
|
227
|
-
searchParameters = searchParameters.addHierarchicalFacet({
|
|
228
|
-
name: id,
|
|
229
|
-
attributes: attributes,
|
|
230
|
-
separator: separator,
|
|
231
|
-
rootPath: rootPath,
|
|
232
|
-
showParentLevel: showParentLevel
|
|
233
|
-
}).setQueryParameters({
|
|
234
|
-
maxValuesPerFacet: Math.max(searchParameters.maxValuesPerFacet || 0, itemsLimit)
|
|
235
|
-
});
|
|
236
|
-
var currentRefinement = getCurrentRefinement(props, searchState, {
|
|
237
|
-
ais: contextValue,
|
|
238
|
-
multiIndexContext: props.indexContextValue
|
|
239
|
-
});
|
|
240
|
-
if (currentRefinement !== null) {
|
|
241
|
-
searchParameters = searchParameters.toggleHierarchicalFacetRefinement(id, currentRefinement);
|
|
242
|
-
}
|
|
243
|
-
return searchParameters;
|
|
244
|
-
},
|
|
245
|
-
getMetadata: function getMetadata(props, searchState) {
|
|
246
|
-
var rootAttribute = props.attributes[0];
|
|
247
|
-
var id = getId(props);
|
|
248
|
-
var currentRefinement = getCurrentRefinement(props, searchState, {
|
|
249
|
-
ais: props.contextValue,
|
|
250
|
-
multiIndexContext: props.indexContextValue
|
|
251
|
-
});
|
|
252
|
-
var items = !currentRefinement ? [] : [{
|
|
253
|
-
label: "".concat(rootAttribute, ": ").concat((0, _utils.unescapeFacetValue)(currentRefinement)),
|
|
254
|
-
attribute: rootAttribute,
|
|
255
|
-
value: function value(nextState) {
|
|
256
|
-
return _refine(props, nextState, '', {
|
|
257
|
-
ais: props.contextValue,
|
|
258
|
-
multiIndexContext: props.indexContextValue
|
|
259
|
-
});
|
|
260
|
-
},
|
|
261
|
-
currentRefinement: currentRefinement
|
|
262
|
-
}];
|
|
263
|
-
return {
|
|
264
|
-
id: id,
|
|
265
|
-
index: (0, _indexUtils.getIndexId)({
|
|
266
|
-
ais: props.contextValue,
|
|
267
|
-
multiIndexContext: props.indexContextValue
|
|
268
|
-
}),
|
|
269
|
-
items: items
|
|
270
|
-
};
|
|
271
|
-
}
|
|
272
|
-
});
|
|
273
|
-
exports.default = _default;
|
|
@@ -1,87 +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 _highlight = require("../core/highlight");
|
|
9
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
10
|
-
var highlight = function highlight(_ref) {
|
|
11
|
-
var attribute = _ref.attribute,
|
|
12
|
-
hit = _ref.hit,
|
|
13
|
-
highlightProperty = _ref.highlightProperty,
|
|
14
|
-
_ref$preTag = _ref.preTag,
|
|
15
|
-
preTag = _ref$preTag === void 0 ? _highlight.HIGHLIGHT_TAGS.highlightPreTag : _ref$preTag,
|
|
16
|
-
_ref$postTag = _ref.postTag,
|
|
17
|
-
postTag = _ref$postTag === void 0 ? _highlight.HIGHLIGHT_TAGS.highlightPostTag : _ref$postTag;
|
|
18
|
-
return (0, _highlight.parseAlgoliaHit)({
|
|
19
|
-
attribute: attribute,
|
|
20
|
-
highlightProperty: highlightProperty,
|
|
21
|
-
hit: hit,
|
|
22
|
-
preTag: preTag,
|
|
23
|
-
postTag: postTag
|
|
24
|
-
});
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* connectHighlight connector provides the logic to create an highlighter
|
|
29
|
-
* component that will retrieve, parse and render an highlighted attribute
|
|
30
|
-
* from an Algolia hit.
|
|
31
|
-
* @name connectHighlight
|
|
32
|
-
* @kind connector
|
|
33
|
-
* @category connector
|
|
34
|
-
* @providedPropType {function} highlight - function to retrieve and parse an attribute from a hit. It takes a configuration object with 3 attributes: `highlightProperty` which is the property that contains the highlight structure from the records, `attribute` which is the name of the attribute (it can be either a string or an array of strings) to look for and `hit` which is the hit from Algolia. It returns an array of objects `{value: string, isHighlighted: boolean}`. If the element that corresponds to the attribute is an array of strings, it will return a nested array of objects.
|
|
35
|
-
* @example
|
|
36
|
-
* import React from 'react';
|
|
37
|
-
* import algoliasearch from 'algoliasearch/lite';
|
|
38
|
-
* import { InstantSearch, SearchBox, Hits, connectHighlight } from 'react-instantsearch-dom';
|
|
39
|
-
*
|
|
40
|
-
* const searchClient = algoliasearch(
|
|
41
|
-
* 'latency',
|
|
42
|
-
* '6be0576ff61c053d5f9a3225e2a90f76'
|
|
43
|
-
* );
|
|
44
|
-
*
|
|
45
|
-
* const CustomHighlight = connectHighlight(
|
|
46
|
-
* ({ highlight, attribute, hit, highlightProperty }) => {
|
|
47
|
-
* const highlights = highlight({
|
|
48
|
-
* highlightProperty: '_highlightResult',
|
|
49
|
-
* attribute,
|
|
50
|
-
* hit
|
|
51
|
-
* });
|
|
52
|
-
*
|
|
53
|
-
* return highlights.map(part => part.isHighlighted ? (
|
|
54
|
-
* <mark>{part.value}</mark>
|
|
55
|
-
* ) : (
|
|
56
|
-
* <span>{part.value}</span>
|
|
57
|
-
* ));
|
|
58
|
-
* }
|
|
59
|
-
* );
|
|
60
|
-
*
|
|
61
|
-
* const Hit = ({ hit }) => (
|
|
62
|
-
* <p>
|
|
63
|
-
* <CustomHighlight attribute="name" hit={hit} />
|
|
64
|
-
* </p>
|
|
65
|
-
* );
|
|
66
|
-
*
|
|
67
|
-
* const App = () => (
|
|
68
|
-
* <InstantSearch
|
|
69
|
-
* searchClient={searchClient}
|
|
70
|
-
* indexName="instant_search"
|
|
71
|
-
* >
|
|
72
|
-
* <SearchBox defaultRefinement="pho" />
|
|
73
|
-
* <Hits hitComponent={Hit} />
|
|
74
|
-
* </InstantSearch>
|
|
75
|
-
* );
|
|
76
|
-
*/
|
|
77
|
-
var _default = (0, _createConnector.default)({
|
|
78
|
-
displayName: 'AlgoliaHighlighter',
|
|
79
|
-
$$type: 'ais.highlighter',
|
|
80
|
-
propTypes: {},
|
|
81
|
-
getProvidedProps: function getProvidedProps() {
|
|
82
|
-
return {
|
|
83
|
-
highlight: highlight
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
|
-
});
|
|
87
|
-
exports.default = _default;
|
|
@@ -1,76 +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 ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
12
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
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
|
-
function inferPayload(_ref) {
|
|
17
|
-
var method = _ref.method,
|
|
18
|
-
results = _ref.results,
|
|
19
|
-
currentHit = _ref.currentHit;
|
|
20
|
-
var index = results.index;
|
|
21
|
-
var queryID = currentHit.__queryID;
|
|
22
|
-
var objectIDs = [currentHit.objectID];
|
|
23
|
-
if (!queryID) {
|
|
24
|
-
throw new Error("Could not infer `queryID`. Ensure `clickAnalytics: true` was added with the Configure widget.\nSee: https://alg.li/VpPpLt");
|
|
25
|
-
}
|
|
26
|
-
switch (method) {
|
|
27
|
-
case 'clickedObjectIDsAfterSearch':
|
|
28
|
-
{
|
|
29
|
-
var positions = [currentHit.__position];
|
|
30
|
-
return {
|
|
31
|
-
index: index,
|
|
32
|
-
queryID: queryID,
|
|
33
|
-
objectIDs: objectIDs,
|
|
34
|
-
positions: positions
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
case 'convertedObjectIDsAfterSearch':
|
|
38
|
-
return {
|
|
39
|
-
index: index,
|
|
40
|
-
queryID: queryID,
|
|
41
|
-
objectIDs: objectIDs
|
|
42
|
-
};
|
|
43
|
-
default:
|
|
44
|
-
throw new Error("Unsupported method \"".concat(method, "\" passed to the insights function. The supported methods are: \"clickedObjectIDsAfterSearch\", \"convertedObjectIDsAfterSearch\"."));
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
var wrapInsightsClient = function wrapInsightsClient(aa, results, currentHit) {
|
|
48
|
-
return function (method, payload) {
|
|
49
|
-
if (typeof aa !== 'function') {
|
|
50
|
-
throw new TypeError("Expected insightsClient to be a Function");
|
|
51
|
-
}
|
|
52
|
-
var inferredPayload = inferPayload({
|
|
53
|
-
method: method,
|
|
54
|
-
results: results,
|
|
55
|
-
currentHit: currentHit
|
|
56
|
-
});
|
|
57
|
-
aa(method, _objectSpread(_objectSpread({}, inferredPayload), payload));
|
|
58
|
-
};
|
|
59
|
-
};
|
|
60
|
-
var _default = function _default(insightsClient) {
|
|
61
|
-
return (0, _createConnector.default)({
|
|
62
|
-
displayName: 'AlgoliaInsights',
|
|
63
|
-
$$type: 'ais.insights',
|
|
64
|
-
getProvidedProps: function getProvidedProps(props, _, searchResults) {
|
|
65
|
-
var results = (0, _indexUtils.getResults)(searchResults, {
|
|
66
|
-
ais: props.contextValue,
|
|
67
|
-
multiIndexContext: props.indexContextValue
|
|
68
|
-
});
|
|
69
|
-
var insights = wrapInsightsClient(insightsClient, results, props.hit);
|
|
70
|
-
return {
|
|
71
|
-
insights: insights
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
});
|
|
75
|
-
};
|
|
76
|
-
exports.default = _default;
|