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
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import algoliasearchHelper from 'algoliasearch-helper';
|
|
2
|
+
export function createSearchResults(state) {
|
|
3
|
+
var _state$query, _state$page, _state$hitsPerPage;
|
|
4
|
+
return new algoliasearchHelper.SearchResults(state, [{
|
|
5
|
+
query: (_state$query = state.query) !== null && _state$query !== void 0 ? _state$query : '',
|
|
6
|
+
page: (_state$page = state.page) !== null && _state$page !== void 0 ? _state$page : 0,
|
|
7
|
+
hitsPerPage: (_state$hitsPerPage = state.hitsPerPage) !== null && _state$hitsPerPage !== void 0 ? _state$hitsPerPage : 20,
|
|
8
|
+
hits: [],
|
|
9
|
+
nbHits: 0,
|
|
10
|
+
nbPages: 0,
|
|
11
|
+
params: '',
|
|
12
|
+
exhaustiveNbHits: true,
|
|
13
|
+
exhaustiveFacetsCount: true,
|
|
14
|
+
processingTimeMS: 0,
|
|
15
|
+
index: state.index
|
|
16
|
+
}], {
|
|
17
|
+
/** used by connectors to prevent persisting these results */
|
|
18
|
+
__isArtificial: true
|
|
19
|
+
});
|
|
20
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function dequal(foo: any, bar: any, compare?: (a: any, b: any) => boolean): boolean;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
2
|
+
/* eslint-disable complexity */
|
|
3
|
+
|
|
4
|
+
/*
|
|
5
|
+
* Code taken from dequal/lite v2.0.0
|
|
6
|
+
* https://github.com/lukeed/dequal/blob/9aa73181ac7e081cd330cac67d313632ac04bb02/src/lite.js
|
|
7
|
+
*
|
|
8
|
+
* It adds a 3rd argument `compare(a, b)` that lets execute custom logic to
|
|
9
|
+
* compare values.
|
|
10
|
+
* We use it to skip comparing function references.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
14
|
+
var has = Object.prototype.hasOwnProperty;
|
|
15
|
+
export function dequal(foo, bar, compare) {
|
|
16
|
+
// start of custom implementation
|
|
17
|
+
if (compare !== null && compare !== void 0 && compare(foo, bar)) {
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
20
|
+
// end of custom implementation
|
|
21
|
+
|
|
22
|
+
var ctor;
|
|
23
|
+
var len;
|
|
24
|
+
if (foo === bar) return true;
|
|
25
|
+
if (foo && bar && (ctor = foo.constructor) === bar.constructor) {
|
|
26
|
+
if (ctor === Date) return foo.getTime() === bar.getTime();
|
|
27
|
+
if (ctor === RegExp) return foo.toString() === bar.toString();
|
|
28
|
+
if (ctor === Array) {
|
|
29
|
+
if ((len = foo.length) === bar.length) {
|
|
30
|
+
while (len-- && dequal(foo[len], bar[len], compare));
|
|
31
|
+
}
|
|
32
|
+
return len === -1;
|
|
33
|
+
}
|
|
34
|
+
if (!ctor || _typeof(foo) === 'object') {
|
|
35
|
+
len = 0;
|
|
36
|
+
// eslint-disable-next-line guard-for-in, no-restricted-syntax
|
|
37
|
+
for (ctor in foo) {
|
|
38
|
+
if (has.call(foo, ctor) && ++len && !has.call(bar, ctor)) return false;
|
|
39
|
+
if (!(ctor in bar) || !dequal(foo[ctor], bar[ctor], compare)) return false;
|
|
40
|
+
}
|
|
41
|
+
return Object.keys(bar).length === len;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// eslint-disable-next-line no-self-compare
|
|
46
|
+
return foo !== foo && bar !== bar;
|
|
47
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { IndexWidget } from 'instantsearch.js/es/widgets/index/index';
|
|
2
|
+
export declare function getIndexSearchResults(indexWidget: IndexWidget): {
|
|
3
|
+
results: import("algoliasearch-helper").SearchResults<any>;
|
|
4
|
+
scopedResults: {
|
|
5
|
+
results: import("algoliasearch-helper").SearchResults<any>;
|
|
6
|
+
indexId: string;
|
|
7
|
+
helper: import("algoliasearch-helper").AlgoliaSearchHelper;
|
|
8
|
+
}[];
|
|
9
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
2
|
+
function 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; }
|
|
3
|
+
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; }
|
|
4
|
+
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; }
|
|
5
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
6
|
+
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); }
|
|
7
|
+
import { createSearchResults } from "./createSearchResults.js";
|
|
8
|
+
export function getIndexSearchResults(indexWidget) {
|
|
9
|
+
var helper = indexWidget.getHelper();
|
|
10
|
+
var results =
|
|
11
|
+
// On SSR, we get the results injected on the Index.
|
|
12
|
+
indexWidget.getResults() ||
|
|
13
|
+
// On the browser, we create fallback results based on the helper state.
|
|
14
|
+
createSearchResults(helper.state);
|
|
15
|
+
var scopedResults = indexWidget.getScopedResults().map(function (scopedResult) {
|
|
16
|
+
var fallbackResults = scopedResult.indexId === indexWidget.getIndexId() ? results : createSearchResults(scopedResult.helper.state);
|
|
17
|
+
return _objectSpread(_objectSpread({}, scopedResult), {}, {
|
|
18
|
+
// We keep `results` from being `null`.
|
|
19
|
+
results: scopedResult.results || fallbackResults
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
return {
|
|
23
|
+
results: results,
|
|
24
|
+
scopedResults: scopedResults
|
|
25
|
+
};
|
|
26
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Throws an error if the condition is not met.
|
|
3
|
+
*
|
|
4
|
+
* The error is exhaustive in development, and becomes generic in production.
|
|
5
|
+
*
|
|
6
|
+
* This is used to make development a better experience to provide guidance as
|
|
7
|
+
* to where the error comes from.
|
|
8
|
+
*/
|
|
9
|
+
export declare function invariant(condition: boolean, message: string | (() => string)): asserts condition;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Throws an error if the condition is not met.
|
|
3
|
+
*
|
|
4
|
+
* The error is exhaustive in development, and becomes generic in production.
|
|
5
|
+
*
|
|
6
|
+
* This is used to make development a better experience to provide guidance as
|
|
7
|
+
* to where the error comes from.
|
|
8
|
+
*/
|
|
9
|
+
export function invariant(condition, message) {
|
|
10
|
+
if (condition) {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
if (!(process.env.NODE_ENV === 'development')) {
|
|
14
|
+
throw new Error('Invariant failed');
|
|
15
|
+
}
|
|
16
|
+
if (process.env.NODE_ENV === 'development') {
|
|
17
|
+
throw new Error("[InstantSearch] ".concat(typeof message === 'function' ? message() : message));
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const noop: (..._args: any[]) => void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export var noop = function noop() {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
2
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
3
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
4
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
5
|
+
function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
|
|
6
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
7
|
+
import { useReducer } from 'react';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Forces a React update that triggers a rerender.
|
|
11
|
+
* @link https://reactjs.org/docs/hooks-faq.html#is-there-something-like-forceupdate
|
|
12
|
+
*/
|
|
13
|
+
export function useForceUpdate() {
|
|
14
|
+
var _useReducer = useReducer(function (x) {
|
|
15
|
+
return x + 1;
|
|
16
|
+
}, 0),
|
|
17
|
+
_useReducer2 = _slicedToArray(_useReducer, 2),
|
|
18
|
+
forceUpdate = _useReducer2[1];
|
|
19
|
+
return forceUpdate;
|
|
20
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { IndexWidgetParams } from 'instantsearch.js/es/widgets/index/index';
|
|
2
|
+
export type UseIndexProps = IndexWidgetParams;
|
|
3
|
+
export declare function useIndex(props: UseIndexProps): import("instantsearch.js/es/widgets/index/index").IndexWidget<import("instantsearch.js").UiState>;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import index from "instantsearch.js/es/widgets/index/index.js";
|
|
2
|
+
import { useMemo } from 'react';
|
|
3
|
+
import { useIndexContext } from "./useIndexContext.js";
|
|
4
|
+
import { useForceUpdate } from "./useForceUpdate.js";
|
|
5
|
+
import { useInstantSearchServerContext } from "./useInstantSearchServerContext.js";
|
|
6
|
+
import { useInstantSearchSSRContext } from "./useInstantSearchSSRContext.js";
|
|
7
|
+
import { useIsomorphicLayoutEffect } from "./useIsomorphicLayoutEffect.js";
|
|
8
|
+
import { useStableValue } from "./useStableValue.js";
|
|
9
|
+
import { useWidget } from "./useWidget.js";
|
|
10
|
+
export function useIndex(props) {
|
|
11
|
+
var serverContext = useInstantSearchServerContext();
|
|
12
|
+
var ssrContext = useInstantSearchSSRContext();
|
|
13
|
+
var initialResults = ssrContext === null || ssrContext === void 0 ? void 0 : ssrContext.initialResults;
|
|
14
|
+
var parentIndex = useIndexContext();
|
|
15
|
+
var stableProps = useStableValue(props);
|
|
16
|
+
var indexWidget = useMemo(function () {
|
|
17
|
+
return index(stableProps);
|
|
18
|
+
}, [stableProps]);
|
|
19
|
+
var helper = indexWidget.getHelper();
|
|
20
|
+
var forceUpdate = useForceUpdate();
|
|
21
|
+
useIsomorphicLayoutEffect(function () {
|
|
22
|
+
forceUpdate();
|
|
23
|
+
}, [helper, forceUpdate]);
|
|
24
|
+
useWidget({
|
|
25
|
+
widget: indexWidget,
|
|
26
|
+
parentIndex: parentIndex,
|
|
27
|
+
props: stableProps,
|
|
28
|
+
shouldSsr: Boolean(serverContext || initialResults)
|
|
29
|
+
});
|
|
30
|
+
return indexWidget;
|
|
31
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { useContext } from 'react';
|
|
2
|
+
import { invariant } from "./invariant.js";
|
|
3
|
+
import { IndexContext } from "./IndexContext.js";
|
|
4
|
+
export function useIndexContext() {
|
|
5
|
+
var context = useContext(IndexContext);
|
|
6
|
+
invariant(context !== null, 'The <Index> component must be used within <InstantSearch>.');
|
|
7
|
+
return context;
|
|
8
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import InstantSearch from 'instantsearch.js/es/lib/InstantSearch';
|
|
2
|
+
import type { InstantSearchOptions, UiState } from 'instantsearch.js';
|
|
3
|
+
export type UseInstantSearchApiProps<TUiState extends UiState, TRouteState> = InstantSearchOptions<TUiState, TRouteState>;
|
|
4
|
+
export type InternalInstantSearch<TUiState extends UiState, TRouteState = TUiState> = InstantSearch<TUiState, TRouteState> & {
|
|
5
|
+
/**
|
|
6
|
+
* Schedule a function to be called on the next timer tick
|
|
7
|
+
* @private
|
|
8
|
+
*/
|
|
9
|
+
_schedule: {
|
|
10
|
+
(cb: () => void): void;
|
|
11
|
+
queue: Array<() => void>;
|
|
12
|
+
timer: ReturnType<typeof setTimeout> | undefined;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Used inside useWidget, which ensures that removeWidgets is not called.
|
|
16
|
+
* This prevents a search from being triggered when InstantSearch is also unmounted.
|
|
17
|
+
* @private
|
|
18
|
+
*/
|
|
19
|
+
_preventWidgetCleanup?: boolean;
|
|
20
|
+
};
|
|
21
|
+
export declare function useInstantSearchApi<TUiState extends UiState, TRouteState>(props: UseInstantSearchApiProps<TUiState, TRouteState>): InstantSearch<TUiState, TRouteState>;
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import InstantSearch from "instantsearch.js/es/lib/InstantSearch.js";
|
|
2
|
+
import { useCallback, useRef, version as ReactVersion } from 'react';
|
|
3
|
+
import { useSyncExternalStore } from "use-sync-external-store/shim/index.js";
|
|
4
|
+
import { useInstantSearchServerContext } from "./useInstantSearchServerContext.js";
|
|
5
|
+
import { useInstantSearchSSRContext } from "./useInstantSearchSSRContext.js";
|
|
6
|
+
import version from "../version.js";
|
|
7
|
+
import { useForceUpdate } from "./useForceUpdate.js";
|
|
8
|
+
import { warn } from "./warn.js";
|
|
9
|
+
var defaultUserAgents = ["react (".concat(ReactVersion, ")"), "react-instantsearch (".concat(version, ")"), "react-instantsearch-core (".concat(version, ")")];
|
|
10
|
+
var serverUserAgent = "react-instantsearch-server (".concat(version, ")");
|
|
11
|
+
var nextUserAgent = function nextUserAgent(nextVersion) {
|
|
12
|
+
return nextVersion ? "next.js (".concat(nextVersion, ")") : null;
|
|
13
|
+
};
|
|
14
|
+
export function useInstantSearchApi(props) {
|
|
15
|
+
var forceUpdate = useForceUpdate();
|
|
16
|
+
var serverContext = useInstantSearchServerContext();
|
|
17
|
+
var serverState = useInstantSearchSSRContext();
|
|
18
|
+
var initialResults = serverState === null || serverState === void 0 ? void 0 : serverState.initialResults;
|
|
19
|
+
var prevPropsRef = useRef(props);
|
|
20
|
+
var searchRef = useRef(null);
|
|
21
|
+
// As we need to render on mount with SSR, using the local ref above in `StrictMode` will
|
|
22
|
+
// create and start two instances of InstantSearch. To avoid this, we instead discard it and use
|
|
23
|
+
// an upward ref from `InstantSearchSSRContext` as it has already been mounted a second time at this point.
|
|
24
|
+
if (serverState) {
|
|
25
|
+
searchRef = serverState.ssrSearchRef;
|
|
26
|
+
}
|
|
27
|
+
if (searchRef.current === null) {
|
|
28
|
+
// We don't use the `instantsearch()` function because it comes with other
|
|
29
|
+
// top-level APIs that we don't need.
|
|
30
|
+
// See https://github.com/algolia/instantsearch.js/blob/5b529f43d8acc680f85837eaaa41f7fd03a3f833/src/index.es.ts#L63-L86
|
|
31
|
+
var search = new InstantSearch(props);
|
|
32
|
+
search._schedule = function _schedule(cb) {
|
|
33
|
+
search._schedule.queue.push(cb);
|
|
34
|
+
clearTimeout(search._schedule.timer);
|
|
35
|
+
search._schedule.timer = setTimeout(function () {
|
|
36
|
+
search._schedule.queue.forEach(function (callback) {
|
|
37
|
+
callback();
|
|
38
|
+
});
|
|
39
|
+
search._schedule.queue = [];
|
|
40
|
+
}, 0);
|
|
41
|
+
};
|
|
42
|
+
search._schedule.queue = [];
|
|
43
|
+
if (serverContext || initialResults) {
|
|
44
|
+
// InstantSearch.js has a private Initial Results API that lets us inject
|
|
45
|
+
// results on the search instance.
|
|
46
|
+
// On the server, we default the initial results to an empty object so that
|
|
47
|
+
// InstantSearch.js doesn't schedule a search that isn't used, leading to
|
|
48
|
+
// an additional network request. (This is equivalent to monkey-patching
|
|
49
|
+
// `scheduleSearch` to a noop.)
|
|
50
|
+
search._initialResults = initialResults || {};
|
|
51
|
+
}
|
|
52
|
+
addAlgoliaAgents(props.searchClient, [].concat(defaultUserAgents, [serverContext && serverUserAgent, nextUserAgent(getNextVersion())]));
|
|
53
|
+
|
|
54
|
+
// On the server, we start the search early to compute the search parameters.
|
|
55
|
+
// On SSR, we start the search early to directly catch up with the lifecycle
|
|
56
|
+
// and render.
|
|
57
|
+
if (serverContext || initialResults) {
|
|
58
|
+
search.start();
|
|
59
|
+
}
|
|
60
|
+
if (serverContext) {
|
|
61
|
+
// We notify `getServerState()` of the InstantSearch internals to retrieve
|
|
62
|
+
// the server state and pass it to the render on SSR.
|
|
63
|
+
serverContext.notifyServer({
|
|
64
|
+
search: search
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
warnNextRouter(props.routing);
|
|
68
|
+
searchRef.current = search;
|
|
69
|
+
}
|
|
70
|
+
{
|
|
71
|
+
var _search = searchRef.current;
|
|
72
|
+
var prevProps = prevPropsRef.current;
|
|
73
|
+
if (prevProps.indexName !== props.indexName) {
|
|
74
|
+
_search.helper.setIndex(props.indexName || '').search();
|
|
75
|
+
prevPropsRef.current = props;
|
|
76
|
+
}
|
|
77
|
+
if (prevProps.searchClient !== props.searchClient) {
|
|
78
|
+
process.env.NODE_ENV === 'development' ? warn(false, 'The `searchClient` prop of `<InstantSearch>` changed between renders, which may cause more search requests than necessary. If this is an unwanted behavior, please provide a stable reference: https://www.algolia.com/doc/api-reference/widgets/instantsearch/react/#widget-param-searchclient') : void 0;
|
|
79
|
+
addAlgoliaAgents(props.searchClient, [].concat(defaultUserAgents, [serverContext && serverUserAgent]));
|
|
80
|
+
_search.mainHelper.setClient(props.searchClient).search();
|
|
81
|
+
prevPropsRef.current = props;
|
|
82
|
+
}
|
|
83
|
+
if (prevProps.onStateChange !== props.onStateChange) {
|
|
84
|
+
_search.onStateChange = props.onStateChange;
|
|
85
|
+
prevPropsRef.current = props;
|
|
86
|
+
}
|
|
87
|
+
if (prevProps.searchFunction !== props.searchFunction) {
|
|
88
|
+
// Updating the `searchFunction` to `undefined` is not supported by
|
|
89
|
+
// InstantSearch.js, so it will throw an error.
|
|
90
|
+
// This is a fair behavior until we add an update API in InstantSearch.js.
|
|
91
|
+
_search._searchFunction = props.searchFunction;
|
|
92
|
+
prevPropsRef.current = props;
|
|
93
|
+
}
|
|
94
|
+
if (prevProps.stalledSearchDelay !== props.stalledSearchDelay) {
|
|
95
|
+
var _props$stalledSearchD;
|
|
96
|
+
// The default `stalledSearchDelay` in InstantSearch.js is 200ms.
|
|
97
|
+
// We need to reset it when it's undefined to get back to the original value.
|
|
98
|
+
_search._stalledSearchDelay = (_props$stalledSearchD = props.stalledSearchDelay) !== null && _props$stalledSearchD !== void 0 ? _props$stalledSearchD : 200;
|
|
99
|
+
prevPropsRef.current = props;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// Updating the `routing` prop is not supported because InstantSearch.js
|
|
103
|
+
// doesn't let us change it. This might not be a problem though, because `routing`
|
|
104
|
+
// shouldn't need to be dynamic.
|
|
105
|
+
// If we find scenarios where `routing` needs to change, we can always expose
|
|
106
|
+
// it privately on the InstantSearch instance. Another way would be to
|
|
107
|
+
// manually inject the routing middleware in this library, and not rely
|
|
108
|
+
// on the provided `routing` prop.
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
var cleanupTimerRef = useRef(null);
|
|
112
|
+
var store = useSyncExternalStore(useCallback(function () {
|
|
113
|
+
var search = searchRef.current;
|
|
114
|
+
|
|
115
|
+
// Scenario 1: the component mounts.
|
|
116
|
+
if (cleanupTimerRef.current === null) {
|
|
117
|
+
// On SSR, the instance is already started so we don't start it again.
|
|
118
|
+
if (!search.started) {
|
|
119
|
+
search.start();
|
|
120
|
+
forceUpdate();
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
// Scenario 2: the component updates.
|
|
124
|
+
else {
|
|
125
|
+
// We cancel the previous cleanup function because we don't want to
|
|
126
|
+
// dispose the search during an update.
|
|
127
|
+
clearTimeout(cleanupTimerRef.current);
|
|
128
|
+
search._preventWidgetCleanup = false;
|
|
129
|
+
}
|
|
130
|
+
return function () {
|
|
131
|
+
function cleanup() {
|
|
132
|
+
search.dispose();
|
|
133
|
+
}
|
|
134
|
+
clearTimeout(search._schedule.timer);
|
|
135
|
+
// We clean up only when the component that uses this subscription unmounts,
|
|
136
|
+
// but not when it updates, because it would dispose the instance, which
|
|
137
|
+
// would remove all the widgets and break routing.
|
|
138
|
+
// Executing the cleanup function in a `setTimeout()` lets us cancel it
|
|
139
|
+
// in the next effect.
|
|
140
|
+
// (There might be better ways to do this.)
|
|
141
|
+
cleanupTimerRef.current = setTimeout(cleanup);
|
|
142
|
+
|
|
143
|
+
// We need to prevent the `useWidget` cleanup function so that widgets
|
|
144
|
+
// are not removed before the instance is disposed, triggering
|
|
145
|
+
// an unwanted search request.
|
|
146
|
+
search._preventWidgetCleanup = true;
|
|
147
|
+
};
|
|
148
|
+
}, [forceUpdate]), function () {
|
|
149
|
+
return searchRef.current;
|
|
150
|
+
}, function () {
|
|
151
|
+
return searchRef.current;
|
|
152
|
+
});
|
|
153
|
+
return store;
|
|
154
|
+
}
|
|
155
|
+
function addAlgoliaAgents(searchClient, userAgents) {
|
|
156
|
+
if (typeof searchClient.addAlgoliaAgent !== 'function') {
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
userAgents.filter(Boolean).forEach(function (userAgent) {
|
|
160
|
+
searchClient.addAlgoliaAgent(userAgent);
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
function warnNextRouter(routing) {
|
|
164
|
+
if (process.env.NODE_ENV === 'development') {
|
|
165
|
+
var _routing$router;
|
|
166
|
+
if (!routing || typeof window === 'undefined' || !('__NEXT_DATA__' in window)) {
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
var isUsingNextRouter =
|
|
170
|
+
// @ts-expect-error: _isNextRouter is only set on the Next.js router
|
|
171
|
+
routing !== true && (routing === null || routing === void 0 ? void 0 : (_routing$router = routing.router) === null || _routing$router === void 0 ? void 0 : _routing$router._isNextRouter);
|
|
172
|
+
process.env.NODE_ENV === 'development' ? warn(isUsingNextRouter, "\nYou are using Next.js with InstantSearch without the \"react-instantsearch-router-nextjs\" package.\nThis package is recommended to make the routing work correctly with Next.js.\nPlease check its usage instructions: https://github.com/algolia/instantsearch/tree/master/packages/react-instantsearch-router-nextjs\n\nYou can ignore this warning if you are using a custom router that suits your needs, it won't be outputted in production builds.") : void 0;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Gets the version of Next.js if it is available in the `window` object,
|
|
178
|
+
* otherwise it returns the NEXT_RUNTIME environment variable (in SSR),
|
|
179
|
+
* which is either `nodejs` or `edge`.
|
|
180
|
+
*/
|
|
181
|
+
function getNextVersion() {
|
|
182
|
+
var _next, _process$env;
|
|
183
|
+
return typeof window !== 'undefined' && ((_next = window.next) === null || _next === void 0 ? void 0 : _next.version) || (typeof process !== 'undefined' ? (_process$env = process.env) === null || _process$env === void 0 ? void 0 : _process$env.NEXT_RUNTIME : undefined);
|
|
184
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { useContext } from 'react';
|
|
2
|
+
import { invariant } from "./invariant.js";
|
|
3
|
+
import { InstantSearchContext } from "./InstantSearchContext.js";
|
|
4
|
+
export function useInstantSearchContext() {
|
|
5
|
+
var search = useContext(InstantSearchContext);
|
|
6
|
+
invariant(search !== null, 'Hooks must be used inside the <InstantSearch> component.\n\n' + 'They are not compatible with the `react-instantsearch-core@6.x` and `react-instantsearch-dom` packages, so make sure to use the <InstantSearch> component from `react-instantsearch-core@7.x`.');
|
|
7
|
+
return search;
|
|
8
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { InstantSearchSSRContextApi } from './InstantSearchSSRContext';
|
|
2
|
+
import type { UiState } from 'instantsearch.js';
|
|
3
|
+
export declare function useInstantSearchSSRContext<TUiState extends UiState, TRouteState = TUiState>(): InstantSearchSSRContextApi<TUiState, TRouteState> | null;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { InstantSearchServerContextApi } from '../components/InstantSearchServerContext';
|
|
2
|
+
import type { UiState } from 'instantsearch.js';
|
|
3
|
+
export declare function useInstantSearchServerContext<TUiState extends UiState, TRouteState = TUiState>(): InstantSearchServerContextApi<TUiState, TRouteState> | null;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { useLayoutEffect } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* `useLayoutEffect` that doesn't show a warning when server-side rendering.
|
|
4
|
+
*
|
|
5
|
+
* It uses `useEffect` on the server (no-op), and `useLayoutEffect` on the browser.
|
|
6
|
+
*/
|
|
7
|
+
export declare const useIsomorphicLayoutEffect: typeof useLayoutEffect;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { useEffect, useLayoutEffect } from 'react';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* `useLayoutEffect` that doesn't show a warning when server-side rendering.
|
|
5
|
+
*
|
|
6
|
+
* It uses `useEffect` on the server (no-op), and `useLayoutEffect` on the browser.
|
|
7
|
+
*/
|
|
8
|
+
export var useIsomorphicLayoutEffect = typeof window !== 'undefined' ? useLayoutEffect : useEffect;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { SearchResults } from 'algoliasearch-helper';
|
|
2
|
+
import type { ScopedResult } from 'instantsearch.js';
|
|
3
|
+
export type SearchResultsApi = {
|
|
4
|
+
results: SearchResults<any>;
|
|
5
|
+
scopedResults: ScopedResult[];
|
|
6
|
+
};
|
|
7
|
+
export declare function useSearchResults(): SearchResultsApi;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
2
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
3
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
4
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
5
|
+
function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
|
|
6
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
7
|
+
import { useEffect, useState } from 'react';
|
|
8
|
+
import { getIndexSearchResults } from "./getIndexSearchResults.js";
|
|
9
|
+
import { useIndexContext } from "./useIndexContext.js";
|
|
10
|
+
import { useInstantSearchContext } from "./useInstantSearchContext.js";
|
|
11
|
+
export function useSearchResults() {
|
|
12
|
+
var search = useInstantSearchContext();
|
|
13
|
+
var searchIndex = useIndexContext();
|
|
14
|
+
var _useState = useState(function () {
|
|
15
|
+
return getIndexSearchResults(searchIndex);
|
|
16
|
+
}),
|
|
17
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
18
|
+
searchResults = _useState2[0],
|
|
19
|
+
setSearchResults = _useState2[1];
|
|
20
|
+
useEffect(function () {
|
|
21
|
+
function handleRender() {
|
|
22
|
+
var results = searchIndex.getResults();
|
|
23
|
+
|
|
24
|
+
// Results can be `null` when the first search is stalled.
|
|
25
|
+
// In this case, we skip the update.
|
|
26
|
+
// See: https://github.com/algolia/instantsearch.js/blob/20996c7a159988c58e00ff24d2d2dc98af8b980f/src/widgets/index/index.ts#L652-L657
|
|
27
|
+
if (results !== null) {
|
|
28
|
+
setSearchResults({
|
|
29
|
+
results: results,
|
|
30
|
+
scopedResults: searchIndex.getScopedResults()
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
search.addListener('render', handleRender);
|
|
35
|
+
return function () {
|
|
36
|
+
search.removeListener('render', handleRender);
|
|
37
|
+
};
|
|
38
|
+
}, [search, searchIndex]);
|
|
39
|
+
return searchResults;
|
|
40
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { InstantSearch, UiState, IndexWidget } from 'instantsearch.js';
|
|
2
|
+
export type SearchStateApi<TUiState extends UiState> = {
|
|
3
|
+
uiState: TUiState;
|
|
4
|
+
setUiState: InstantSearch<TUiState>['setUiState'];
|
|
5
|
+
indexUiState: TUiState[string];
|
|
6
|
+
setIndexUiState: IndexWidget<TUiState>['setIndexUiState'];
|
|
7
|
+
};
|
|
8
|
+
export declare function useSearchState<TUiState extends UiState>(): SearchStateApi<TUiState>;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
2
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
3
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
4
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
5
|
+
function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
|
|
6
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
7
|
+
import { useCallback, useEffect, useState } from 'react';
|
|
8
|
+
import { useIndexContext } from "./useIndexContext.js";
|
|
9
|
+
import { useInstantSearchContext } from "./useInstantSearchContext.js";
|
|
10
|
+
export function useSearchState() {
|
|
11
|
+
var search = useInstantSearchContext();
|
|
12
|
+
var searchIndex = useIndexContext();
|
|
13
|
+
var indexId = searchIndex.getIndexId();
|
|
14
|
+
var _useState = useState(function () {
|
|
15
|
+
return search.getUiState();
|
|
16
|
+
}),
|
|
17
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
18
|
+
uiState = _useState2[0],
|
|
19
|
+
setLocalUiState = _useState2[1];
|
|
20
|
+
var indexUiState = uiState[indexId];
|
|
21
|
+
var setUiState = useCallback(function (nextUiState) {
|
|
22
|
+
search.setUiState(nextUiState);
|
|
23
|
+
}, [search]);
|
|
24
|
+
var setIndexUiState = useCallback(function (nextIndexUiState) {
|
|
25
|
+
searchIndex.setIndexUiState(nextIndexUiState);
|
|
26
|
+
}, [searchIndex]);
|
|
27
|
+
useEffect(function () {
|
|
28
|
+
function handleRender() {
|
|
29
|
+
setLocalUiState(search.getUiState());
|
|
30
|
+
}
|
|
31
|
+
search.addListener('render', handleRender);
|
|
32
|
+
return function () {
|
|
33
|
+
search.removeListener('render', handleRender);
|
|
34
|
+
};
|
|
35
|
+
}, [search]);
|
|
36
|
+
return {
|
|
37
|
+
uiState: uiState,
|
|
38
|
+
setUiState: setUiState,
|
|
39
|
+
indexUiState: indexUiState,
|
|
40
|
+
setIndexUiState: setIndexUiState
|
|
41
|
+
};
|
|
42
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function useStableValue<TValue>(value: TValue): TValue;
|