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,534 +0,0 @@
|
|
|
1
|
-
var _excluded = ["resultsFacetValues"],
|
|
2
|
-
_excluded2 = ["resultsFacetValues"],
|
|
3
|
-
_excluded3 = ["resultsFacetValues"];
|
|
4
|
-
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); }
|
|
5
|
-
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; }
|
|
6
|
-
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; }
|
|
7
|
-
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; }
|
|
8
|
-
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; }
|
|
9
|
-
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; }
|
|
10
|
-
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
11
|
-
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); }
|
|
12
|
-
import algoliasearchHelper from 'algoliasearch-helper';
|
|
13
|
-
import { version as ReactVersion } from 'react';
|
|
14
|
-
import createStore from "./createStore.js";
|
|
15
|
-
import createWidgetsManager from "./createWidgetsManager.js";
|
|
16
|
-
import { HIGHLIGHT_TAGS } from "./highlight.js";
|
|
17
|
-
import { hasMultipleIndices } from "./indexUtils.js";
|
|
18
|
-
import version from "./version.js";
|
|
19
|
-
function addAlgoliaAgents(searchClient) {
|
|
20
|
-
if (typeof searchClient.addAlgoliaAgent === 'function') {
|
|
21
|
-
searchClient.addAlgoliaAgent("react (".concat(ReactVersion, ")"));
|
|
22
|
-
searchClient.addAlgoliaAgent("react-instantsearch (".concat(version, ")"));
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
var isMultiIndexContext = function isMultiIndexContext(widget) {
|
|
26
|
-
return hasMultipleIndices({
|
|
27
|
-
ais: widget.props.contextValue,
|
|
28
|
-
multiIndexContext: widget.props.indexContextValue
|
|
29
|
-
});
|
|
30
|
-
};
|
|
31
|
-
var isTargetedIndexEqualIndex = function isTargetedIndexEqualIndex(widget, indexId) {
|
|
32
|
-
return widget.props.indexContextValue.targetedIndex === indexId;
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
// Relying on the `indexId` is a bit brittle to detect the `Index` widget.
|
|
36
|
-
// Since it's a class we could rely on `instanceof` or similar. We never
|
|
37
|
-
// had an issue though. Works for now.
|
|
38
|
-
var isIndexWidget = function isIndexWidget(widget) {
|
|
39
|
-
return Boolean(widget.props.indexId);
|
|
40
|
-
};
|
|
41
|
-
var isIndexWidgetEqualIndex = function isIndexWidgetEqualIndex(widget, indexId) {
|
|
42
|
-
return widget.props.indexId === indexId;
|
|
43
|
-
};
|
|
44
|
-
var sortIndexWidgetsFirst = function sortIndexWidgetsFirst(firstWidget, secondWidget) {
|
|
45
|
-
var isFirstWidgetIndex = isIndexWidget(firstWidget);
|
|
46
|
-
var isSecondWidgetIndex = isIndexWidget(secondWidget);
|
|
47
|
-
if (isFirstWidgetIndex && !isSecondWidgetIndex) {
|
|
48
|
-
return -1;
|
|
49
|
-
}
|
|
50
|
-
if (!isFirstWidgetIndex && isSecondWidgetIndex) {
|
|
51
|
-
return 1;
|
|
52
|
-
}
|
|
53
|
-
return 0;
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
// This function is copied from the algoliasearch v4 API Client. If modified,
|
|
57
|
-
// consider updating it also in `serializeQueryParameters` from `@algolia/transporter`.
|
|
58
|
-
function serializeQueryParameters(parameters) {
|
|
59
|
-
var isObjectOrArray = function isObjectOrArray(value) {
|
|
60
|
-
return Object.prototype.toString.call(value) === '[object Object]' || Object.prototype.toString.call(value) === '[object Array]';
|
|
61
|
-
};
|
|
62
|
-
var encode = function encode(format) {
|
|
63
|
-
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
64
|
-
args[_key - 1] = arguments[_key];
|
|
65
|
-
}
|
|
66
|
-
var i = 0;
|
|
67
|
-
return format.replace(/%s/g, function () {
|
|
68
|
-
return encodeURIComponent(args[i++]);
|
|
69
|
-
});
|
|
70
|
-
};
|
|
71
|
-
return Object.keys(parameters).map(function (key) {
|
|
72
|
-
return encode('%s=%s', key, isObjectOrArray(parameters[key]) ? JSON.stringify(parameters[key]) : parameters[key]);
|
|
73
|
-
}).join('&');
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* Creates a new instance of the InstantSearchManager which controls the widgets and
|
|
78
|
-
* trigger the search when the widgets are updated.
|
|
79
|
-
* @param {string} indexName - the main index name
|
|
80
|
-
* @param {object} initialState - initial widget state
|
|
81
|
-
* @param {object} SearchParameters - optional additional parameters to send to the algolia API
|
|
82
|
-
* @param {number} stalledSearchDelay - time (in ms) after the search is stalled
|
|
83
|
-
* @return {InstantSearchManager} a new instance of InstantSearchManager
|
|
84
|
-
*/
|
|
85
|
-
export default function createInstantSearchManager(_ref) {
|
|
86
|
-
var indexName = _ref.indexName,
|
|
87
|
-
_ref$initialState = _ref.initialState,
|
|
88
|
-
initialState = _ref$initialState === void 0 ? {} : _ref$initialState,
|
|
89
|
-
searchClient = _ref.searchClient,
|
|
90
|
-
resultsState = _ref.resultsState,
|
|
91
|
-
stalledSearchDelay = _ref.stalledSearchDelay;
|
|
92
|
-
var helper = algoliasearchHelper(searchClient, indexName, _objectSpread({}, HIGHLIGHT_TAGS));
|
|
93
|
-
addAlgoliaAgents(searchClient);
|
|
94
|
-
helper.on('search', handleNewSearch).on('result', handleSearchSuccess({
|
|
95
|
-
indexId: indexName
|
|
96
|
-
})).on('error', handleSearchError);
|
|
97
|
-
var skip = false;
|
|
98
|
-
var stalledSearchTimer = null;
|
|
99
|
-
var initialSearchParameters = helper.state;
|
|
100
|
-
var searchCounter;
|
|
101
|
-
var widgetsManager = createWidgetsManager(onWidgetsUpdate);
|
|
102
|
-
hydrateSearchClient(searchClient, resultsState);
|
|
103
|
-
var store = createStore({
|
|
104
|
-
widgets: initialState,
|
|
105
|
-
metadata: hydrateMetadata(resultsState),
|
|
106
|
-
results: hydrateResultsState(resultsState),
|
|
107
|
-
error: null,
|
|
108
|
-
searching: false,
|
|
109
|
-
isSearchStalled: true,
|
|
110
|
-
searchingForFacetValues: false
|
|
111
|
-
});
|
|
112
|
-
function skipSearch() {
|
|
113
|
-
skip = true;
|
|
114
|
-
}
|
|
115
|
-
function updateClient(client) {
|
|
116
|
-
addAlgoliaAgents(client);
|
|
117
|
-
helper.setClient(client);
|
|
118
|
-
search();
|
|
119
|
-
}
|
|
120
|
-
function clearCache() {
|
|
121
|
-
helper.clearCache();
|
|
122
|
-
search();
|
|
123
|
-
}
|
|
124
|
-
function getMetadata(state) {
|
|
125
|
-
return widgetsManager.getWidgets().filter(function (widget) {
|
|
126
|
-
return Boolean(widget.getMetadata);
|
|
127
|
-
}).map(function (widget) {
|
|
128
|
-
return widget.getMetadata(state);
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
function getSearchParameters() {
|
|
132
|
-
var sharedParameters = widgetsManager.getWidgets().filter(function (widget) {
|
|
133
|
-
return Boolean(widget.getSearchParameters);
|
|
134
|
-
}).filter(function (widget) {
|
|
135
|
-
return !isMultiIndexContext(widget) && !isIndexWidget(widget);
|
|
136
|
-
}).reduce(function (res, widget) {
|
|
137
|
-
return widget.getSearchParameters(res);
|
|
138
|
-
}, initialSearchParameters);
|
|
139
|
-
var mainParameters = widgetsManager.getWidgets().filter(function (widget) {
|
|
140
|
-
return Boolean(widget.getSearchParameters);
|
|
141
|
-
}).filter(function (widget) {
|
|
142
|
-
var targetedIndexEqualMainIndex = isMultiIndexContext(widget) && isTargetedIndexEqualIndex(widget, indexName);
|
|
143
|
-
var subIndexEqualMainIndex = isIndexWidget(widget) && isIndexWidgetEqualIndex(widget, indexName);
|
|
144
|
-
return targetedIndexEqualMainIndex || subIndexEqualMainIndex;
|
|
145
|
-
})
|
|
146
|
-
// We have to sort the `Index` widgets first so the `index` parameter
|
|
147
|
-
// is correctly set in the `reduce` function for the following widgets
|
|
148
|
-
.sort(sortIndexWidgetsFirst).reduce(function (res, widget) {
|
|
149
|
-
return widget.getSearchParameters(res);
|
|
150
|
-
}, sharedParameters);
|
|
151
|
-
var derivedIndices = widgetsManager.getWidgets().filter(function (widget) {
|
|
152
|
-
return Boolean(widget.getSearchParameters);
|
|
153
|
-
}).filter(function (widget) {
|
|
154
|
-
var targetedIndexNotEqualMainIndex = isMultiIndexContext(widget) && !isTargetedIndexEqualIndex(widget, indexName);
|
|
155
|
-
var subIndexNotEqualMainIndex = isIndexWidget(widget) && !isIndexWidgetEqualIndex(widget, indexName);
|
|
156
|
-
return targetedIndexNotEqualMainIndex || subIndexNotEqualMainIndex;
|
|
157
|
-
})
|
|
158
|
-
// We have to sort the `Index` widgets first so the `index` parameter
|
|
159
|
-
// is correctly set in the `reduce` function for the following widgets
|
|
160
|
-
.sort(sortIndexWidgetsFirst).reduce(function (indices, widget) {
|
|
161
|
-
var indexId = isMultiIndexContext(widget) ? widget.props.indexContextValue.targetedIndex : widget.props.indexId;
|
|
162
|
-
var widgets = indices[indexId] || [];
|
|
163
|
-
return _objectSpread(_objectSpread({}, indices), {}, _defineProperty({}, indexId, widgets.concat(widget)));
|
|
164
|
-
}, {});
|
|
165
|
-
var derivedParameters = Object.keys(derivedIndices).map(function (indexId) {
|
|
166
|
-
return {
|
|
167
|
-
parameters: derivedIndices[indexId].reduce(function (res, widget) {
|
|
168
|
-
return widget.getSearchParameters(res);
|
|
169
|
-
}, sharedParameters),
|
|
170
|
-
indexId: indexId
|
|
171
|
-
};
|
|
172
|
-
});
|
|
173
|
-
return {
|
|
174
|
-
mainParameters: mainParameters,
|
|
175
|
-
derivedParameters: derivedParameters
|
|
176
|
-
};
|
|
177
|
-
}
|
|
178
|
-
function search() {
|
|
179
|
-
if (!skip) {
|
|
180
|
-
var _getSearchParameters = getSearchParameters(helper.state),
|
|
181
|
-
mainParameters = _getSearchParameters.mainParameters,
|
|
182
|
-
derivedParameters = _getSearchParameters.derivedParameters;
|
|
183
|
-
searchCounter = derivedParameters.length + 1;
|
|
184
|
-
|
|
185
|
-
// We have to call `slice` because the method `detach` on the derived
|
|
186
|
-
// helpers mutates the value `derivedHelpers`. The `forEach` loop does
|
|
187
|
-
// not iterate on each value and we're not able to correctly clear the
|
|
188
|
-
// previous derived helpers (memory leak + useless requests).
|
|
189
|
-
helper.derivedHelpers.slice().forEach(function (derivedHelper) {
|
|
190
|
-
// Since we detach the derived helpers on **every** new search they
|
|
191
|
-
// won't receive intermediate results in case of a stalled search.
|
|
192
|
-
// Only the last result is dispatched by the derived helper because
|
|
193
|
-
// they are not detached yet:
|
|
194
|
-
//
|
|
195
|
-
// - a -> main helper receives results
|
|
196
|
-
// - ap -> main helper receives results
|
|
197
|
-
// - app -> main helper + derived helpers receive results
|
|
198
|
-
//
|
|
199
|
-
// The quick fix is to avoid to detach them on search but only once they
|
|
200
|
-
// received the results. But it means that in case of a stalled search
|
|
201
|
-
// all the derived helpers not detached yet register a new search inside
|
|
202
|
-
// the helper. The number grows fast in case of a bad network and it's
|
|
203
|
-
// not deterministic.
|
|
204
|
-
derivedHelper.detach();
|
|
205
|
-
});
|
|
206
|
-
derivedParameters.forEach(function (_ref2) {
|
|
207
|
-
var indexId = _ref2.indexId,
|
|
208
|
-
parameters = _ref2.parameters;
|
|
209
|
-
var derivedHelper = helper.derive(function () {
|
|
210
|
-
return parameters;
|
|
211
|
-
});
|
|
212
|
-
derivedHelper.on('result', handleSearchSuccess({
|
|
213
|
-
indexId: indexId
|
|
214
|
-
})).on('error', handleSearchError);
|
|
215
|
-
});
|
|
216
|
-
helper.setState(mainParameters);
|
|
217
|
-
helper.search();
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
function handleSearchSuccess(_ref3) {
|
|
221
|
-
var indexId = _ref3.indexId;
|
|
222
|
-
return function (event) {
|
|
223
|
-
searchCounter--;
|
|
224
|
-
var state = store.getState();
|
|
225
|
-
var isDerivedHelpersEmpty = !helper.derivedHelpers.length;
|
|
226
|
-
var results = state.results ? state.results : {};
|
|
227
|
-
|
|
228
|
-
// Switching from mono index to multi index and vice versa must reset the
|
|
229
|
-
// results to an empty object, otherwise we keep reference of stalled and
|
|
230
|
-
// unused results.
|
|
231
|
-
results = !isDerivedHelpersEmpty && results.getFacetByName ? {} : results;
|
|
232
|
-
if (!isDerivedHelpersEmpty) {
|
|
233
|
-
results = _objectSpread(_objectSpread({}, results), {}, _defineProperty({}, indexId, event.results));
|
|
234
|
-
} else {
|
|
235
|
-
results = event.results;
|
|
236
|
-
}
|
|
237
|
-
var currentState = store.getState();
|
|
238
|
-
var nextIsSearchStalled = currentState.isSearchStalled;
|
|
239
|
-
if (!helper.hasPendingRequests()) {
|
|
240
|
-
clearTimeout(stalledSearchTimer);
|
|
241
|
-
stalledSearchTimer = null;
|
|
242
|
-
nextIsSearchStalled = false;
|
|
243
|
-
}
|
|
244
|
-
var resultsFacetValues = currentState.resultsFacetValues,
|
|
245
|
-
partialState = _objectWithoutProperties(currentState, _excluded);
|
|
246
|
-
store.setState(_objectSpread(_objectSpread({}, partialState), {}, {
|
|
247
|
-
results: results,
|
|
248
|
-
isSearchStalled: nextIsSearchStalled,
|
|
249
|
-
searching: searchCounter > 0,
|
|
250
|
-
error: null
|
|
251
|
-
}));
|
|
252
|
-
};
|
|
253
|
-
}
|
|
254
|
-
function handleSearchError(_ref4) {
|
|
255
|
-
var error = _ref4.error;
|
|
256
|
-
var currentState = store.getState();
|
|
257
|
-
var nextIsSearchStalled = currentState.isSearchStalled;
|
|
258
|
-
if (!helper.hasPendingRequests()) {
|
|
259
|
-
clearTimeout(stalledSearchTimer);
|
|
260
|
-
nextIsSearchStalled = false;
|
|
261
|
-
}
|
|
262
|
-
var resultsFacetValues = currentState.resultsFacetValues,
|
|
263
|
-
partialState = _objectWithoutProperties(currentState, _excluded2);
|
|
264
|
-
store.setState(_objectSpread(_objectSpread({}, partialState), {}, {
|
|
265
|
-
isSearchStalled: nextIsSearchStalled,
|
|
266
|
-
error: error,
|
|
267
|
-
searching: false
|
|
268
|
-
}));
|
|
269
|
-
}
|
|
270
|
-
function handleNewSearch() {
|
|
271
|
-
if (!stalledSearchTimer) {
|
|
272
|
-
stalledSearchTimer = setTimeout(function () {
|
|
273
|
-
var _store$getState = store.getState(),
|
|
274
|
-
resultsFacetValues = _store$getState.resultsFacetValues,
|
|
275
|
-
partialState = _objectWithoutProperties(_store$getState, _excluded3);
|
|
276
|
-
store.setState(_objectSpread(_objectSpread({}, partialState), {}, {
|
|
277
|
-
isSearchStalled: true
|
|
278
|
-
}));
|
|
279
|
-
}, stalledSearchDelay);
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
function hydrateSearchClient(client, results) {
|
|
283
|
-
if (!results) {
|
|
284
|
-
return;
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
// Disable cache hydration on:
|
|
288
|
-
// - Algoliasearch API Client < v4 with cache disabled
|
|
289
|
-
// - Third party clients (detected by the `addAlgoliaAgent` function missing)
|
|
290
|
-
|
|
291
|
-
if ((!client.transporter || client._cacheHydrated) && (!client._useCache || typeof client.addAlgoliaAgent !== 'function')) {
|
|
292
|
-
return;
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
// Algoliasearch API Client >= v4
|
|
296
|
-
// To hydrate the client we need to populate the cache with the data from
|
|
297
|
-
// the server (done in `hydrateSearchClientWithMultiIndexRequest` or
|
|
298
|
-
// `hydrateSearchClientWithSingleIndexRequest`). But since there is no way
|
|
299
|
-
// for us to compute the key the same way as `algoliasearch-client` we need
|
|
300
|
-
// to populate it on a custom key and override the `search` method to
|
|
301
|
-
// search on it first.
|
|
302
|
-
if (client.transporter && !client._cacheHydrated) {
|
|
303
|
-
client._cacheHydrated = true;
|
|
304
|
-
var baseMethod = client.search;
|
|
305
|
-
client.search = function (requests) {
|
|
306
|
-
for (var _len2 = arguments.length, methodArgs = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
|
|
307
|
-
methodArgs[_key2 - 1] = arguments[_key2];
|
|
308
|
-
}
|
|
309
|
-
var requestsWithSerializedParams = requests.map(function (request) {
|
|
310
|
-
return _objectSpread(_objectSpread({}, request), {}, {
|
|
311
|
-
params: serializeQueryParameters(request.params)
|
|
312
|
-
});
|
|
313
|
-
});
|
|
314
|
-
return client.transporter.responsesCache.get({
|
|
315
|
-
method: 'search',
|
|
316
|
-
args: [requestsWithSerializedParams].concat(methodArgs)
|
|
317
|
-
}, function () {
|
|
318
|
-
return baseMethod.apply(void 0, [requests].concat(methodArgs));
|
|
319
|
-
});
|
|
320
|
-
};
|
|
321
|
-
}
|
|
322
|
-
if (Array.isArray(results.results)) {
|
|
323
|
-
hydrateSearchClientWithMultiIndexRequest(client, results.results);
|
|
324
|
-
return;
|
|
325
|
-
}
|
|
326
|
-
hydrateSearchClientWithSingleIndexRequest(client, results);
|
|
327
|
-
}
|
|
328
|
-
function hydrateSearchClientWithMultiIndexRequest(client, results) {
|
|
329
|
-
// Algoliasearch API Client >= v4
|
|
330
|
-
// Populate the cache with the data from the server
|
|
331
|
-
if (client.transporter) {
|
|
332
|
-
client.transporter.responsesCache.set({
|
|
333
|
-
method: 'search',
|
|
334
|
-
args: [results.reduce(function (acc, result) {
|
|
335
|
-
return acc.concat(result.rawResults.map(function (request) {
|
|
336
|
-
return {
|
|
337
|
-
indexName: request.index,
|
|
338
|
-
params: request.params
|
|
339
|
-
};
|
|
340
|
-
}));
|
|
341
|
-
}, [])]
|
|
342
|
-
}, {
|
|
343
|
-
results: results.reduce(function (acc, result) {
|
|
344
|
-
return acc.concat(result.rawResults);
|
|
345
|
-
}, [])
|
|
346
|
-
});
|
|
347
|
-
return;
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
// Algoliasearch API Client < v4
|
|
351
|
-
// Prior to client v4 we didn't have a proper API to hydrate the client
|
|
352
|
-
// cache from the outside. The following code populates the cache with
|
|
353
|
-
// a single-index result. You can find more information about the
|
|
354
|
-
// computation of the key inside the client (see link below).
|
|
355
|
-
// https://github.com/algolia/algoliasearch-client-javascript/blob/c27e89ff92b2a854ae6f40dc524bffe0f0cbc169/src/AlgoliaSearchCore.js#L232-L240
|
|
356
|
-
var key = "/1/indexes/*/queries_body_".concat(JSON.stringify({
|
|
357
|
-
requests: results.reduce(function (acc, result) {
|
|
358
|
-
return acc.concat(result.rawResults.map(function (request) {
|
|
359
|
-
return {
|
|
360
|
-
indexName: request.index,
|
|
361
|
-
params: request.params
|
|
362
|
-
};
|
|
363
|
-
}));
|
|
364
|
-
}, [])
|
|
365
|
-
}));
|
|
366
|
-
client.cache = _objectSpread(_objectSpread({}, client.cache), {}, _defineProperty({}, key, JSON.stringify({
|
|
367
|
-
results: results.reduce(function (acc, result) {
|
|
368
|
-
return acc.concat(result.rawResults);
|
|
369
|
-
}, [])
|
|
370
|
-
})));
|
|
371
|
-
}
|
|
372
|
-
function hydrateSearchClientWithSingleIndexRequest(client, results) {
|
|
373
|
-
// Algoliasearch API Client >= v4
|
|
374
|
-
// Populate the cache with the data from the server
|
|
375
|
-
if (client.transporter) {
|
|
376
|
-
client.transporter.responsesCache.set({
|
|
377
|
-
method: 'search',
|
|
378
|
-
args: [results.rawResults.map(function (request) {
|
|
379
|
-
return {
|
|
380
|
-
indexName: request.index,
|
|
381
|
-
params: request.params
|
|
382
|
-
};
|
|
383
|
-
})]
|
|
384
|
-
}, {
|
|
385
|
-
results: results.rawResults
|
|
386
|
-
});
|
|
387
|
-
return;
|
|
388
|
-
}
|
|
389
|
-
// Algoliasearch API Client < v4
|
|
390
|
-
// Prior to client v4 we didn't have a proper API to hydrate the client
|
|
391
|
-
// cache from the outside. The following code populates the cache with
|
|
392
|
-
// a single-index result. You can find more information about the
|
|
393
|
-
// computation of the key inside the client (see link below).
|
|
394
|
-
// https://github.com/algolia/algoliasearch-client-javascript/blob/c27e89ff92b2a854ae6f40dc524bffe0f0cbc169/src/AlgoliaSearchCore.js#L232-L240
|
|
395
|
-
var key = "/1/indexes/*/queries_body_".concat(JSON.stringify({
|
|
396
|
-
requests: results.rawResults.map(function (request) {
|
|
397
|
-
return {
|
|
398
|
-
indexName: request.index,
|
|
399
|
-
params: request.params
|
|
400
|
-
};
|
|
401
|
-
})
|
|
402
|
-
}));
|
|
403
|
-
client.cache = _objectSpread(_objectSpread({}, client.cache), {}, _defineProperty({}, key, JSON.stringify({
|
|
404
|
-
results: results.rawResults
|
|
405
|
-
})));
|
|
406
|
-
}
|
|
407
|
-
function hydrateResultsState(results) {
|
|
408
|
-
if (!results) {
|
|
409
|
-
return null;
|
|
410
|
-
}
|
|
411
|
-
if (Array.isArray(results.results)) {
|
|
412
|
-
return results.results.reduce(function (acc, result) {
|
|
413
|
-
return _objectSpread(_objectSpread({}, acc), {}, _defineProperty({}, result._internalIndexId, new algoliasearchHelper.SearchResults(new algoliasearchHelper.SearchParameters(result.state), result.rawResults)));
|
|
414
|
-
}, {});
|
|
415
|
-
}
|
|
416
|
-
return new algoliasearchHelper.SearchResults(new algoliasearchHelper.SearchParameters(results.state), results.rawResults);
|
|
417
|
-
}
|
|
418
|
-
|
|
419
|
-
// Called whenever a widget has been rendered with new props.
|
|
420
|
-
function onWidgetsUpdate() {
|
|
421
|
-
var metadata = getMetadata(store.getState().widgets);
|
|
422
|
-
store.setState(_objectSpread(_objectSpread({}, store.getState()), {}, {
|
|
423
|
-
metadata: metadata,
|
|
424
|
-
searching: true
|
|
425
|
-
}));
|
|
426
|
-
|
|
427
|
-
// Since the `getSearchParameters` method of widgets also depends on props,
|
|
428
|
-
// the result search parameters might have changed.
|
|
429
|
-
search();
|
|
430
|
-
}
|
|
431
|
-
function transitionState(nextSearchState) {
|
|
432
|
-
var searchState = store.getState().widgets;
|
|
433
|
-
return widgetsManager.getWidgets().filter(function (widget) {
|
|
434
|
-
return Boolean(widget.transitionState);
|
|
435
|
-
}).reduce(function (res, widget) {
|
|
436
|
-
return widget.transitionState(searchState, res);
|
|
437
|
-
}, nextSearchState);
|
|
438
|
-
}
|
|
439
|
-
function onExternalStateUpdate(nextSearchState) {
|
|
440
|
-
var metadata = getMetadata(nextSearchState);
|
|
441
|
-
store.setState(_objectSpread(_objectSpread({}, store.getState()), {}, {
|
|
442
|
-
widgets: nextSearchState,
|
|
443
|
-
metadata: metadata,
|
|
444
|
-
searching: true
|
|
445
|
-
}));
|
|
446
|
-
search();
|
|
447
|
-
}
|
|
448
|
-
function onSearchForFacetValues(_ref5) {
|
|
449
|
-
var facetName = _ref5.facetName,
|
|
450
|
-
query = _ref5.query,
|
|
451
|
-
_ref5$maxFacetHits = _ref5.maxFacetHits,
|
|
452
|
-
maxFacetHits = _ref5$maxFacetHits === void 0 ? 10 : _ref5$maxFacetHits;
|
|
453
|
-
// The values 1, 100 are the min / max values that the engine accepts.
|
|
454
|
-
// see: https://www.algolia.com/doc/api-reference/api-parameters/maxFacetHits
|
|
455
|
-
var maxFacetHitsWithinRange = Math.max(1, Math.min(maxFacetHits, 100));
|
|
456
|
-
store.setState(_objectSpread(_objectSpread({}, store.getState()), {}, {
|
|
457
|
-
searchingForFacetValues: true
|
|
458
|
-
}));
|
|
459
|
-
helper.searchForFacetValues(facetName, query, maxFacetHitsWithinRange).then(function (content) {
|
|
460
|
-
var _objectSpread7;
|
|
461
|
-
store.setState(_objectSpread(_objectSpread({}, store.getState()), {}, {
|
|
462
|
-
error: null,
|
|
463
|
-
searchingForFacetValues: false,
|
|
464
|
-
resultsFacetValues: _objectSpread(_objectSpread({}, store.getState().resultsFacetValues), {}, (_objectSpread7 = {}, _defineProperty(_objectSpread7, facetName, content.facetHits), _defineProperty(_objectSpread7, "query", query), _objectSpread7))
|
|
465
|
-
}));
|
|
466
|
-
}, function (error) {
|
|
467
|
-
store.setState(_objectSpread(_objectSpread({}, store.getState()), {}, {
|
|
468
|
-
searchingForFacetValues: false,
|
|
469
|
-
error: error
|
|
470
|
-
}));
|
|
471
|
-
}).catch(function (error) {
|
|
472
|
-
// Since setState is synchronous, any error that occurs in the render of a
|
|
473
|
-
// component will be swallowed by this promise.
|
|
474
|
-
// This is a trick to make the error show up correctly in the console.
|
|
475
|
-
// See http://stackoverflow.com/a/30741722/969302
|
|
476
|
-
setTimeout(function () {
|
|
477
|
-
throw error;
|
|
478
|
-
});
|
|
479
|
-
});
|
|
480
|
-
}
|
|
481
|
-
function updateIndex(newIndex) {
|
|
482
|
-
initialSearchParameters = initialSearchParameters.setIndex(newIndex);
|
|
483
|
-
// No need to trigger a new search here as the widgets will also update and trigger it if needed.
|
|
484
|
-
}
|
|
485
|
-
|
|
486
|
-
function getWidgetsIds() {
|
|
487
|
-
return store.getState().metadata.reduce(function (res, meta) {
|
|
488
|
-
return typeof meta.id !== 'undefined' ? res.concat(meta.id) : res;
|
|
489
|
-
}, []);
|
|
490
|
-
}
|
|
491
|
-
return {
|
|
492
|
-
store: store,
|
|
493
|
-
widgetsManager: widgetsManager,
|
|
494
|
-
getWidgetsIds: getWidgetsIds,
|
|
495
|
-
getSearchParameters: getSearchParameters,
|
|
496
|
-
onSearchForFacetValues: onSearchForFacetValues,
|
|
497
|
-
onExternalStateUpdate: onExternalStateUpdate,
|
|
498
|
-
transitionState: transitionState,
|
|
499
|
-
updateClient: updateClient,
|
|
500
|
-
updateIndex: updateIndex,
|
|
501
|
-
clearCache: clearCache,
|
|
502
|
-
skipSearch: skipSearch
|
|
503
|
-
};
|
|
504
|
-
}
|
|
505
|
-
function hydrateMetadata(resultsState) {
|
|
506
|
-
if (!resultsState) {
|
|
507
|
-
return [];
|
|
508
|
-
}
|
|
509
|
-
|
|
510
|
-
// add a value noop, which gets replaced once the widgets are mounted
|
|
511
|
-
return resultsState.metadata.map(function (datum) {
|
|
512
|
-
return _objectSpread(_objectSpread({
|
|
513
|
-
value: function value() {
|
|
514
|
-
return {};
|
|
515
|
-
}
|
|
516
|
-
}, datum), {}, {
|
|
517
|
-
items: datum.items && datum.items.map(function (item) {
|
|
518
|
-
return _objectSpread(_objectSpread({
|
|
519
|
-
value: function value() {
|
|
520
|
-
return {};
|
|
521
|
-
}
|
|
522
|
-
}, item), {}, {
|
|
523
|
-
items: item.items && item.items.map(function (nestedItem) {
|
|
524
|
-
return _objectSpread({
|
|
525
|
-
value: function value() {
|
|
526
|
-
return {};
|
|
527
|
-
}
|
|
528
|
-
}, nestedItem);
|
|
529
|
-
})
|
|
530
|
-
});
|
|
531
|
-
})
|
|
532
|
-
});
|
|
533
|
-
});
|
|
534
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
export default function createStore(initialState) {
|
|
2
|
-
var state = initialState;
|
|
3
|
-
var listeners = [];
|
|
4
|
-
return {
|
|
5
|
-
getState: function getState() {
|
|
6
|
-
return state;
|
|
7
|
-
},
|
|
8
|
-
setState: function setState(nextState) {
|
|
9
|
-
state = nextState;
|
|
10
|
-
listeners.forEach(function (listener) {
|
|
11
|
-
return listener();
|
|
12
|
-
});
|
|
13
|
-
},
|
|
14
|
-
subscribe: function subscribe(listener) {
|
|
15
|
-
listeners.push(listener);
|
|
16
|
-
return function unsubscribe() {
|
|
17
|
-
listeners.splice(listeners.indexOf(listener), 1);
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
};
|
|
21
|
-
}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { defer } from "./utils.js";
|
|
2
|
-
export default function createWidgetsManager(onWidgetsUpdate) {
|
|
3
|
-
var widgets = [];
|
|
4
|
-
// Is an update scheduled?
|
|
5
|
-
var scheduled = false;
|
|
6
|
-
|
|
7
|
-
// The state manager's updates need to be batched since more than one
|
|
8
|
-
// component can register or unregister widgets during the same tick.
|
|
9
|
-
function scheduleUpdate() {
|
|
10
|
-
if (scheduled) {
|
|
11
|
-
return;
|
|
12
|
-
}
|
|
13
|
-
scheduled = true;
|
|
14
|
-
defer(function () {
|
|
15
|
-
scheduled = false;
|
|
16
|
-
onWidgetsUpdate();
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
return {
|
|
20
|
-
registerWidget: function registerWidget(widget) {
|
|
21
|
-
widgets.push(widget);
|
|
22
|
-
scheduleUpdate();
|
|
23
|
-
return function unregisterWidget() {
|
|
24
|
-
widgets.splice(widgets.indexOf(widget), 1);
|
|
25
|
-
scheduleUpdate();
|
|
26
|
-
};
|
|
27
|
-
},
|
|
28
|
-
update: scheduleUpdate,
|
|
29
|
-
getWidgets: function getWidgets() {
|
|
30
|
-
return widgets;
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
}
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
import { getPropertyByPath } from "./utils.js";
|
|
2
|
-
export var HIGHLIGHT_TAGS = {
|
|
3
|
-
highlightPreTag: "<ais-highlight-0000000000>",
|
|
4
|
-
highlightPostTag: "</ais-highlight-0000000000>"
|
|
5
|
-
};
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Parses an highlighted attribute into an array of objects with the string value, and
|
|
9
|
-
* a boolean that indicated if this part is highlighted.
|
|
10
|
-
*
|
|
11
|
-
* @param {string} preTag - string used to identify the start of an highlighted value
|
|
12
|
-
* @param {string} postTag - string used to identify the end of an highlighted value
|
|
13
|
-
* @param {string} highlightedValue - highlighted attribute as returned by Algolia highlight feature
|
|
14
|
-
* @return {object[]} - An array of {value: string, isHighlighted: boolean}.
|
|
15
|
-
*/
|
|
16
|
-
function parseHighlightedAttribute(_ref) {
|
|
17
|
-
var preTag = _ref.preTag,
|
|
18
|
-
postTag = _ref.postTag,
|
|
19
|
-
_ref$highlightedValue = _ref.highlightedValue,
|
|
20
|
-
highlightedValue = _ref$highlightedValue === void 0 ? '' : _ref$highlightedValue;
|
|
21
|
-
var splitByPreTag = highlightedValue.split(preTag);
|
|
22
|
-
var firstValue = splitByPreTag.shift();
|
|
23
|
-
var elements = firstValue === '' ? [] : [{
|
|
24
|
-
value: firstValue,
|
|
25
|
-
isHighlighted: false
|
|
26
|
-
}];
|
|
27
|
-
if (postTag === preTag) {
|
|
28
|
-
var isHighlighted = true;
|
|
29
|
-
splitByPreTag.forEach(function (split) {
|
|
30
|
-
elements.push({
|
|
31
|
-
value: split,
|
|
32
|
-
isHighlighted: isHighlighted
|
|
33
|
-
});
|
|
34
|
-
isHighlighted = !isHighlighted;
|
|
35
|
-
});
|
|
36
|
-
} else {
|
|
37
|
-
splitByPreTag.forEach(function (split) {
|
|
38
|
-
var splitByPostTag = split.split(postTag);
|
|
39
|
-
elements.push({
|
|
40
|
-
value: splitByPostTag[0],
|
|
41
|
-
isHighlighted: true
|
|
42
|
-
});
|
|
43
|
-
if (splitByPostTag[1] !== '') {
|
|
44
|
-
elements.push({
|
|
45
|
-
value: splitByPostTag[1],
|
|
46
|
-
isHighlighted: false
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
return elements;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* Find an highlighted attribute given an `attribute` and an `highlightProperty`, parses it,
|
|
56
|
-
* and provided an array of objects with the string value and a boolean if this
|
|
57
|
-
* value is highlighted.
|
|
58
|
-
*
|
|
59
|
-
* In order to use this feature, highlight must be activated in the configuration of
|
|
60
|
-
* the index. The `preTag` and `postTag` attributes are respectively highlightPreTag and
|
|
61
|
-
* highlightPostTag in Algolia configuration.
|
|
62
|
-
*
|
|
63
|
-
* @param {string} preTag - string used to identify the start of an highlighted value
|
|
64
|
-
* @param {string} postTag - string used to identify the end of an highlighted value
|
|
65
|
-
* @param {string} highlightProperty - the property that contains the highlight structure in the results
|
|
66
|
-
* @param {string} attribute - the highlighted attribute to look for
|
|
67
|
-
* @param {object} hit - the actual hit returned by Algolia.
|
|
68
|
-
* @return {object[]} - An array of {value: string, isHighlighted: boolean}.
|
|
69
|
-
*/
|
|
70
|
-
export function parseAlgoliaHit(_ref2) {
|
|
71
|
-
var _ref2$preTag = _ref2.preTag,
|
|
72
|
-
preTag = _ref2$preTag === void 0 ? '<em>' : _ref2$preTag,
|
|
73
|
-
_ref2$postTag = _ref2.postTag,
|
|
74
|
-
postTag = _ref2$postTag === void 0 ? '</em>' : _ref2$postTag,
|
|
75
|
-
highlightProperty = _ref2.highlightProperty,
|
|
76
|
-
attribute = _ref2.attribute,
|
|
77
|
-
hit = _ref2.hit;
|
|
78
|
-
if (!hit) throw new Error('`hit`, the matching record, must be provided');
|
|
79
|
-
var highlightObject = getPropertyByPath(hit[highlightProperty], attribute) || {};
|
|
80
|
-
if (Array.isArray(highlightObject)) {
|
|
81
|
-
return highlightObject.map(function (item) {
|
|
82
|
-
return parseHighlightedAttribute({
|
|
83
|
-
preTag: preTag,
|
|
84
|
-
postTag: postTag,
|
|
85
|
-
highlightedValue: item.value
|
|
86
|
-
});
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
return parseHighlightedAttribute({
|
|
90
|
-
preTag: preTag,
|
|
91
|
-
postTag: postTag,
|
|
92
|
-
highlightedValue: highlightObject.value
|
|
93
|
-
});
|
|
94
|
-
}
|