react-instantsearch-core 7.24.0 → 7.26.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (140) hide show
  1. package/dist/cjs/components/Configure.js +11 -17
  2. package/dist/cjs/components/DynamicWidgets.js +46 -53
  3. package/dist/cjs/components/Index.js +19 -22
  4. package/dist/cjs/components/InstantSearch.js +34 -36
  5. package/dist/cjs/components/InstantSearchSSRProvider.js +31 -41
  6. package/dist/cjs/components/InstantSearchServerContext.js +6 -10
  7. package/dist/cjs/connectors/useAutocomplete.js +8 -10
  8. package/dist/cjs/connectors/useBreadcrumb.js +8 -10
  9. package/dist/cjs/connectors/useChat.js +8 -10
  10. package/dist/cjs/connectors/useClearRefinements.js +8 -10
  11. package/dist/cjs/connectors/useConfigure.js +10 -12
  12. package/dist/cjs/connectors/useCurrentRefinements.js +8 -10
  13. package/dist/cjs/connectors/useDynamicWidgets.js +14 -20
  14. package/dist/cjs/connectors/useFilterSuggestions.js +8 -10
  15. package/dist/cjs/connectors/useFrequentlyBoughtTogether.js +8 -10
  16. package/dist/cjs/connectors/useGeoSearch.js +8 -10
  17. package/dist/cjs/connectors/useHierarchicalMenu.js +8 -10
  18. package/dist/cjs/connectors/useHits.js +8 -10
  19. package/dist/cjs/connectors/useHitsPerPage.js +8 -10
  20. package/dist/cjs/connectors/useInfiniteHits.js +8 -10
  21. package/dist/cjs/connectors/useLookingSimilar.js +8 -10
  22. package/dist/cjs/connectors/useMenu.js +8 -10
  23. package/dist/cjs/connectors/useNumericMenu.js +8 -10
  24. package/dist/cjs/connectors/usePagination.js +8 -10
  25. package/dist/cjs/connectors/usePoweredBy.js +18 -19
  26. package/dist/cjs/connectors/useQueryRules.js +8 -10
  27. package/dist/cjs/connectors/useRange.js +8 -10
  28. package/dist/cjs/connectors/useRefinementList.js +8 -10
  29. package/dist/cjs/connectors/useRelatedProducts.js +8 -10
  30. package/dist/cjs/connectors/useSearchBox.js +8 -10
  31. package/dist/cjs/connectors/useSortBy.js +8 -10
  32. package/dist/cjs/connectors/useStats.js +8 -10
  33. package/dist/cjs/connectors/useToggleRefinement.js +8 -10
  34. package/dist/cjs/connectors/useTrendingItems.js +8 -10
  35. package/dist/cjs/hooks/useConnector.js +123 -139
  36. package/dist/cjs/hooks/useInstantSearch.js +59 -59
  37. package/dist/cjs/index.js +90 -519
  38. package/dist/cjs/lib/IndexContext.js +6 -10
  39. package/dist/cjs/lib/InstantSearchContext.js +6 -10
  40. package/dist/cjs/lib/InstantSearchRSCContext.js +11 -12
  41. package/dist/cjs/lib/InstantSearchSSRContext.js +6 -10
  42. package/dist/cjs/lib/createSearchResults.js +24 -25
  43. package/dist/cjs/lib/dequal.js +33 -40
  44. package/dist/cjs/lib/getIndexSearchResults.js +23 -30
  45. package/dist/cjs/lib/invariant.js +11 -17
  46. package/dist/cjs/lib/noop.js +8 -6
  47. package/dist/cjs/lib/use.js +26 -11
  48. package/dist/cjs/lib/useAppIdAndApiKey.js +10 -12
  49. package/dist/cjs/lib/useForceUpdate.js +12 -21
  50. package/dist/cjs/lib/useIndex.js +40 -37
  51. package/dist/cjs/lib/useIndexContext.js +11 -12
  52. package/dist/cjs/lib/useInstantSearchApi.js +174 -197
  53. package/dist/cjs/lib/useInstantSearchContext.js +11 -12
  54. package/dist/cjs/lib/useInstantSearchSSRContext.js +8 -9
  55. package/dist/cjs/lib/useInstantSearchServerContext.js +8 -9
  56. package/dist/cjs/lib/useIsomorphicLayoutEffect.js +6 -8
  57. package/dist/cjs/lib/useRSCContext.js +8 -9
  58. package/dist/cjs/lib/useSearchResults.js +54 -62
  59. package/dist/cjs/lib/useSearchState.js +53 -60
  60. package/dist/cjs/lib/useStableValue.js +15 -24
  61. package/dist/cjs/lib/useWidget.js +99 -95
  62. package/dist/cjs/lib/warn.js +11 -35
  63. package/dist/cjs/lib/wrapPromiseWithState.js +23 -26
  64. package/dist/cjs/package.json +4 -1
  65. package/dist/cjs/server/getServerState.js +81 -91
  66. package/dist/cjs/server/index.js +6 -15
  67. package/dist/cjs/version.js +6 -6
  68. package/dist/es/components/Configure.js +11 -13
  69. package/dist/es/components/DynamicWidgets.js +45 -47
  70. package/dist/es/components/Index.js +19 -17
  71. package/dist/es/components/InstantSearch.js +33 -29
  72. package/dist/es/components/InstantSearchSSRProvider.js +30 -35
  73. package/dist/es/components/InstantSearchServerContext.js +4 -4
  74. package/dist/es/connectors/useAutocomplete.js +8 -5
  75. package/dist/es/connectors/useBreadcrumb.js +8 -5
  76. package/dist/es/connectors/useChat.js +8 -5
  77. package/dist/es/connectors/useClearRefinements.js +8 -5
  78. package/dist/es/connectors/useConfigure.js +10 -7
  79. package/dist/es/connectors/useCurrentRefinements.js +8 -5
  80. package/dist/es/connectors/useDynamicWidgets.js +14 -15
  81. package/dist/es/connectors/useFilterSuggestions.js +8 -5
  82. package/dist/es/connectors/useFrequentlyBoughtTogether.js +8 -5
  83. package/dist/es/connectors/useGeoSearch.js +8 -5
  84. package/dist/es/connectors/useHierarchicalMenu.js +8 -5
  85. package/dist/es/connectors/useHits.js +8 -5
  86. package/dist/es/connectors/useHitsPerPage.js +8 -5
  87. package/dist/es/connectors/useInfiniteHits.js +8 -5
  88. package/dist/es/connectors/useLookingSimilar.js +8 -5
  89. package/dist/es/connectors/useMenu.js +8 -5
  90. package/dist/es/connectors/useNumericMenu.js +8 -5
  91. package/dist/es/connectors/usePagination.js +8 -5
  92. package/dist/es/connectors/usePoweredBy.js +18 -15
  93. package/dist/es/connectors/useQueryRules.js +8 -5
  94. package/dist/es/connectors/useRange.js +8 -5
  95. package/dist/es/connectors/useRefinementList.js +8 -5
  96. package/dist/es/connectors/useRelatedProducts.js +8 -5
  97. package/dist/es/connectors/useSearchBox.js +8 -5
  98. package/dist/es/connectors/useSortBy.js +8 -5
  99. package/dist/es/connectors/useStats.js +8 -5
  100. package/dist/es/connectors/useToggleRefinement.js +8 -5
  101. package/dist/es/connectors/useTrendingItems.js +8 -5
  102. package/dist/es/hooks/useConnector.js +122 -134
  103. package/dist/es/hooks/useInstantSearch.js +58 -54
  104. package/dist/es/index.js +43 -43
  105. package/dist/es/lib/IndexContext.js +4 -4
  106. package/dist/es/lib/InstantSearchContext.js +4 -4
  107. package/dist/es/lib/InstantSearchRSCContext.js +10 -7
  108. package/dist/es/lib/InstantSearchSSRContext.js +4 -4
  109. package/dist/es/lib/createSearchResults.js +23 -19
  110. package/dist/es/lib/dequal.js +33 -36
  111. package/dist/es/lib/getIndexSearchResults.js +23 -26
  112. package/dist/es/lib/invariant.js +10 -12
  113. package/dist/es/lib/noop.js +7 -1
  114. package/dist/es/lib/use.js +4 -2
  115. package/dist/es/lib/useAppIdAndApiKey.js +9 -7
  116. package/dist/es/lib/useForceUpdate.js +9 -15
  117. package/dist/es/lib/useIndex.js +39 -31
  118. package/dist/es/lib/useIndexContext.js +10 -7
  119. package/dist/es/lib/useInstantSearchApi.js +174 -191
  120. package/dist/es/lib/useInstantSearchContext.js +10 -7
  121. package/dist/es/lib/useInstantSearchSSRContext.js +7 -4
  122. package/dist/es/lib/useInstantSearchServerContext.js +7 -4
  123. package/dist/es/lib/useIsomorphicLayoutEffect.js +4 -3
  124. package/dist/es/lib/useRSCContext.js +7 -4
  125. package/dist/es/lib/useSearchResults.js +53 -57
  126. package/dist/es/lib/useSearchState.js +52 -55
  127. package/dist/es/lib/useStableValue.js +14 -19
  128. package/dist/es/lib/useWidget.js +98 -90
  129. package/dist/es/lib/warn.js +9 -29
  130. package/dist/es/lib/wrapPromiseWithState.js +23 -22
  131. package/dist/es/package.json +4 -0
  132. package/dist/es/server/getServerState.js +80 -85
  133. package/dist/es/server/index.js +1 -1
  134. package/dist/es/version.d.ts +1 -1
  135. package/dist/es/version.js +3 -1
  136. package/dist/umd/ReactInstantSearchCore.js +17488 -22329
  137. package/dist/umd/ReactInstantSearchCore.min.js +3 -3
  138. package/package.json +7 -11
  139. package/dist/umd/ReactInstantSearchCore.js.map +0 -1
  140. package/dist/umd/ReactInstantSearchCore.min.js.map +0 -1
@@ -1,138 +1,126 @@
1
- function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
- var _excluded = ["skipSuspense"],
3
- _excluded2 = ["instantSearchInstance", "widgetParams"],
4
- _excluded3 = ["widgetParams"];
5
- function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
6
- function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
7
- function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
8
- function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
9
- function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
10
- function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
11
- function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
12
- function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
13
- function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
14
- function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
15
- function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
16
- function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
17
- function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
18
- import { useMemo, useRef, useState } from 'react';
19
- import { dequal } from "../lib/dequal.js";
20
- import { getIndexSearchResults } from "../lib/getIndexSearchResults.js";
21
- import { useIndexContext } from "../lib/useIndexContext.js";
22
- import { useInstantSearchContext } from "../lib/useInstantSearchContext.js";
23
- import { useInstantSearchServerContext } from "../lib/useInstantSearchServerContext.js";
24
- import { useInstantSearchSSRContext } from "../lib/useInstantSearchSSRContext.js";
25
- import { useStableValue } from "../lib/useStableValue.js";
26
- import { useWidget } from "../lib/useWidget.js";
27
- export function useConnector(connector) {
28
- var props = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
29
- var _ref = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {},
30
- _ref$skipSuspense = _ref.skipSuspense,
31
- skipSuspense = _ref$skipSuspense === void 0 ? false : _ref$skipSuspense,
32
- additionalWidgetProperties = _objectWithoutProperties(_ref, _excluded);
33
- var serverContext = useInstantSearchServerContext();
34
- var ssrContext = useInstantSearchSSRContext();
35
- var search = useInstantSearchContext();
36
- var parentIndex = useIndexContext();
37
- var stableProps = useStableValue(props);
38
- var stableAdditionalWidgetProperties = useStableValue(additionalWidgetProperties);
39
- var shouldSetStateRef = useRef(true);
40
- var previousRenderStateRef = useRef(null);
41
- var previousStatusRef = useRef(search.status);
42
- var widget = useMemo(function () {
43
- var createWidget = connector(function (connectorState, isFirstRender) {
44
- // We skip the `init` widget render because:
45
- // - We rely on `getWidgetRenderState` to compute the initial state before
46
- // the InstantSearch.js lifecycle starts.
47
- // - It prevents UI flashes when updating the widget props.
48
- if (isFirstRender) {
49
- shouldSetStateRef.current = true;
50
- return;
51
- }
1
+ import { _ as _$3 } from '@swc/helpers/cjs/_object_spread.cjs';
2
+ import { _ as _$2 } from '@swc/helpers/cjs/_object_without_properties.cjs';
3
+ import { _ as _$1 } from '@swc/helpers/cjs/_sliced_to_array.cjs';
4
+ import { _ } from '@swc/helpers/cjs/_to_array.cjs';
5
+ import { useRef, useMemo, useState } from 'react';
6
+ import { dequal } from '../lib/dequal.js';
7
+ import { getIndexSearchResults } from '../lib/getIndexSearchResults.js';
8
+ import { useIndexContext } from '../lib/useIndexContext.js';
9
+ import { useInstantSearchContext } from '../lib/useInstantSearchContext.js';
10
+ import { useInstantSearchServerContext } from '../lib/useInstantSearchServerContext.js';
11
+ import { useInstantSearchSSRContext } from '../lib/useInstantSearchSSRContext.js';
12
+ import { useStableValue } from '../lib/useStableValue.js';
13
+ import { useWidget } from '../lib/useWidget.js';
52
14
 
53
- // There are situations where InstantSearch.js may render widgets slightly
54
- // after they're removed by React, and thus try to update the React state
55
- // on unmounted components. React 16 and 17 consider them as memory leaks
56
- // and display a warning.
57
- // This happens in <DynamicWidgets> when `attributesToRender` contains a
58
- // value without an attribute previously mounted. React will unmount the
59
- // component controlled by that attribute, but InstantSearch.js will stay
60
- // unaware of this change until the render pass finishes, and therefore
61
- // notifies of a state change.
62
- // This ref lets us track this situation and ignore these state updates.
63
- if (shouldSetStateRef.current) {
64
- var instantSearchInstance = connectorState.instantSearchInstance,
65
- widgetParams = connectorState.widgetParams,
66
- renderState = _objectWithoutProperties(connectorState, _excluded2);
67
-
68
- // We only update the state when a widget render state param changes,
69
- // except for functions. We ignore function reference changes to avoid
70
- // infinite loops. It's safe to omit them because they get updated
71
- // every time another render param changes.
72
- if (!dequal(renderState, previousRenderStateRef.current, function (a, b) {
73
- return (a === null || a === void 0 ? void 0 : a.constructor) === Function && (b === null || b === void 0 ? void 0 : b.constructor) === Function;
74
- }) || instantSearchInstance.status !== previousStatusRef.current) {
75
- // eslint-disable-next-line @typescript-eslint/no-use-before-define
76
- setState(renderState);
77
- previousRenderStateRef.current = renderState;
78
- previousStatusRef.current = instantSearchInstance.status;
15
+ function useConnector(connector) {
16
+ var _1 = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : void 0, _2 = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : void 0;
17
+ var _ref = [
18
+ _1,
19
+ _2
20
+ ], _ref1 = _(_ref), tmp = _ref1[0], props = tmp === void 0 ? {} : tmp, _rest = _ref1.slice(1), _rest1 = _$1(_rest, 1), tmp1 = _rest1[0], _ref2 = tmp1 === void 0 ? {} : tmp1, _ref_skipSuspense = _ref2.skipSuspense, skipSuspense = _ref_skipSuspense === void 0 ? false : _ref_skipSuspense, additionalWidgetProperties = _$2(_ref2, [
21
+ "skipSuspense"
22
+ ]);
23
+ var serverContext = useInstantSearchServerContext();
24
+ var ssrContext = useInstantSearchSSRContext();
25
+ var search = useInstantSearchContext();
26
+ var parentIndex = useIndexContext();
27
+ var stableProps = useStableValue(props);
28
+ var stableAdditionalWidgetProperties = useStableValue(additionalWidgetProperties);
29
+ var shouldSetStateRef = useRef(true);
30
+ var previousRenderStateRef = useRef(null);
31
+ var previousStatusRef = useRef(search.status);
32
+ var widget = useMemo(function() {
33
+ var createWidget = connector(function(connectorState, isFirstRender) {
34
+ // We skip the `init` widget render because:
35
+ // - We rely on `getWidgetRenderState` to compute the initial state before
36
+ // the InstantSearch.js lifecycle starts.
37
+ // - It prevents UI flashes when updating the widget props.
38
+ if (isFirstRender) {
39
+ shouldSetStateRef.current = true;
40
+ return;
41
+ }
42
+ // There are situations where InstantSearch.js may render widgets slightly
43
+ // after they're removed by React, and thus try to update the React state
44
+ // on unmounted components. React 16 and 17 consider them as memory leaks
45
+ // and display a warning.
46
+ // This happens in <DynamicWidgets> when `attributesToRender` contains a
47
+ // value without an attribute previously mounted. React will unmount the
48
+ // component controlled by that attribute, but InstantSearch.js will stay
49
+ // unaware of this change until the render pass finishes, and therefore
50
+ // notifies of a state change.
51
+ // This ref lets us track this situation and ignore these state updates.
52
+ if (shouldSetStateRef.current) {
53
+ var instantSearchInstance = connectorState.instantSearchInstance; connectorState.widgetParams; var renderState = _$2(connectorState, [
54
+ "instantSearchInstance",
55
+ "widgetParams"
56
+ ]);
57
+ // We only update the state when a widget render state param changes,
58
+ // except for functions. We ignore function reference changes to avoid
59
+ // infinite loops. It's safe to omit them because they get updated
60
+ // every time another render param changes.
61
+ if (!dequal(renderState, previousRenderStateRef.current, function(a, b) {
62
+ return (a === null || a === void 0 ? void 0 : a.constructor) === Function && (b === null || b === void 0 ? void 0 : b.constructor) === Function;
63
+ }) || instantSearchInstance.status !== previousStatusRef.current) {
64
+ // eslint-disable-next-line @typescript-eslint/no-use-before-define
65
+ setState(renderState);
66
+ previousRenderStateRef.current = renderState;
67
+ previousStatusRef.current = instantSearchInstance.status;
68
+ }
69
+ }
70
+ }, function() {
71
+ // We'll ignore the next state update until we know for sure that
72
+ // InstantSearch.js re-inits the component.
73
+ shouldSetStateRef.current = false;
74
+ });
75
+ return _$3({}, createWidget(stableProps), stableAdditionalWidgetProperties);
76
+ }, [
77
+ connector,
78
+ stableProps,
79
+ stableAdditionalWidgetProperties
80
+ ]);
81
+ var _useState = _$1(useState(function() {
82
+ if (widget.getWidgetRenderState) {
83
+ var _widget_getWidgetSearchParameters;
84
+ // The helper exists because we've started InstantSearch.
85
+ var helper = parentIndex.getHelper();
86
+ var uiState = parentIndex.getWidgetUiState({})[parentIndex.getIndexId()];
87
+ helper.state = ((_widget_getWidgetSearchParameters = widget.getWidgetSearchParameters) === null || _widget_getWidgetSearchParameters === void 0 ? void 0 : _widget_getWidgetSearchParameters.call(widget, helper.state, {
88
+ uiState: uiState
89
+ })) || helper.state;
90
+ var _getIndexSearchResults = getIndexSearchResults(parentIndex), results = _getIndexSearchResults.results, scopedResults = _getIndexSearchResults.scopedResults, recommendResults = _getIndexSearchResults.recommendResults;
91
+ // We get the widget render state by providing the same parameters as
92
+ // InstantSearch provides to the widget's `render` method.
93
+ // See https://github.com/algolia/instantsearch/blob/019cd18d0de6dd320284aa4890541b7fe2198c65/src/widgets/index/index.ts#L604-L617
94
+ var _widget_getWidgetRenderState = widget.getWidgetRenderState({
95
+ helper: helper,
96
+ parent: parentIndex,
97
+ instantSearchInstance: search,
98
+ results: widget.dependsOn === 'recommend' && recommendResults && ssrContext ? recommendResults[ssrContext.recommendIdx.current++] : results,
99
+ scopedResults: scopedResults,
100
+ state: helper.state,
101
+ renderState: search.renderState,
102
+ templatesConfig: search.templatesConfig,
103
+ createURL: parentIndex.createURL,
104
+ searchMetadata: {
105
+ isSearchStalled: search.status === 'stalled'
106
+ },
107
+ status: search.status,
108
+ error: search.error
109
+ }); _widget_getWidgetRenderState.widgetParams; var renderState = _$2(_widget_getWidgetRenderState, [
110
+ "widgetParams"
111
+ ]);
112
+ return renderState;
79
113
  }
80
- }
81
- }, function () {
82
- // We'll ignore the next state update until we know for sure that
83
- // InstantSearch.js re-inits the component.
84
- shouldSetStateRef.current = false;
114
+ return {};
115
+ }), 2), state = _useState[0], setState = _useState[1];
116
+ useWidget({
117
+ widget: widget,
118
+ parentIndex: parentIndex,
119
+ props: stableProps,
120
+ shouldSsr: Boolean(serverContext),
121
+ skipSuspense: skipSuspense
85
122
  });
86
- return _objectSpread(_objectSpread({}, createWidget(stableProps)), stableAdditionalWidgetProperties);
87
- }, [connector, stableProps, stableAdditionalWidgetProperties]);
88
- var _useState = useState(function () {
89
- if (widget.getWidgetRenderState) {
90
- var _widget$getWidgetSear;
91
- // The helper exists because we've started InstantSearch.
92
- var helper = parentIndex.getHelper();
93
- var uiState = parentIndex.getWidgetUiState({})[parentIndex.getIndexId()];
94
- helper.state = ((_widget$getWidgetSear = widget.getWidgetSearchParameters) === null || _widget$getWidgetSear === void 0 ? void 0 : _widget$getWidgetSear.call(widget, helper.state, {
95
- uiState: uiState
96
- })) || helper.state;
97
- var _getIndexSearchResult = getIndexSearchResults(parentIndex),
98
- results = _getIndexSearchResult.results,
99
- scopedResults = _getIndexSearchResult.scopedResults,
100
- recommendResults = _getIndexSearchResult.recommendResults;
123
+ return state;
124
+ }
101
125
 
102
- // We get the widget render state by providing the same parameters as
103
- // InstantSearch provides to the widget's `render` method.
104
- // See https://github.com/algolia/instantsearch/blob/019cd18d0de6dd320284aa4890541b7fe2198c65/src/widgets/index/index.ts#L604-L617
105
- var _widget$getWidgetRend = widget.getWidgetRenderState({
106
- helper: helper,
107
- parent: parentIndex,
108
- instantSearchInstance: search,
109
- results: widget.dependsOn === 'recommend' && recommendResults && ssrContext ? recommendResults[ssrContext.recommendIdx.current++] : results,
110
- scopedResults: scopedResults,
111
- state: helper.state,
112
- renderState: search.renderState,
113
- templatesConfig: search.templatesConfig,
114
- createURL: parentIndex.createURL,
115
- searchMetadata: {
116
- isSearchStalled: search.status === 'stalled'
117
- },
118
- status: search.status,
119
- error: search.error
120
- }),
121
- widgetParams = _widget$getWidgetRend.widgetParams,
122
- renderState = _objectWithoutProperties(_widget$getWidgetRend, _excluded3);
123
- return renderState;
124
- }
125
- return {};
126
- }),
127
- _useState2 = _slicedToArray(_useState, 2),
128
- state = _useState2[0],
129
- setState = _useState2[1];
130
- useWidget({
131
- widget: widget,
132
- parentIndex: parentIndex,
133
- props: stableProps,
134
- shouldSsr: Boolean(serverContext),
135
- skipSuspense: skipSuspense
136
- });
137
- return state;
138
- }
126
+ export { useConnector };
@@ -1,56 +1,60 @@
1
+ import { _ } from '@swc/helpers/cjs/_to_consumable_array.cjs';
1
2
  import { useCallback } from 'react';
2
- import { useInstantSearchContext } from "../lib/useInstantSearchContext.js";
3
- import { useIsomorphicLayoutEffect } from "../lib/useIsomorphicLayoutEffect.js";
4
- import { useSearchResults } from "../lib/useSearchResults.js";
5
- import { useSearchState } from "../lib/useSearchState.js";
6
- export function useInstantSearch() {
7
- var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
8
- catchError = _ref.catchError;
9
- var search = useInstantSearchContext();
10
- var _useSearchState = useSearchState(),
11
- uiState = _useSearchState.uiState,
12
- setUiState = _useSearchState.setUiState,
13
- indexUiState = _useSearchState.indexUiState,
14
- setIndexUiState = _useSearchState.setIndexUiState,
15
- renderState = _useSearchState.renderState,
16
- indexRenderState = _useSearchState.indexRenderState;
17
- var _useSearchResults = useSearchResults(),
18
- results = _useSearchResults.results,
19
- scopedResults = _useSearchResults.scopedResults;
20
- var addMiddlewares = useCallback(function () {
21
- for (var _len = arguments.length, middlewares = new Array(_len), _key = 0; _key < _len; _key++) {
22
- middlewares[_key] = arguments[_key];
23
- }
24
- search.use.apply(search, middlewares);
25
- return function () {
26
- search.unuse.apply(search, middlewares);
3
+ import { useInstantSearchContext } from '../lib/useInstantSearchContext.js';
4
+ import { useIsomorphicLayoutEffect } from '../lib/useIsomorphicLayoutEffect.js';
5
+ import { useSearchResults } from '../lib/useSearchResults.js';
6
+ import { useSearchState } from '../lib/useSearchState.js';
7
+
8
+ function useInstantSearch() {
9
+ var catchError = (arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {}).catchError;
10
+ var search = useInstantSearchContext();
11
+ var _useSearchState = useSearchState(), uiState = _useSearchState.uiState, setUiState = _useSearchState.setUiState, indexUiState = _useSearchState.indexUiState, setIndexUiState = _useSearchState.setIndexUiState, renderState = _useSearchState.renderState, indexRenderState = _useSearchState.indexRenderState;
12
+ var _useSearchResults = useSearchResults(), results = _useSearchResults.results, scopedResults = _useSearchResults.scopedResults;
13
+ var addMiddlewares = useCallback(function() {
14
+ for(var _len = arguments.length, middlewares = new Array(_len), _key = 0; _key < _len; _key++){
15
+ middlewares[_key] = arguments[_key];
16
+ }
17
+ var _search;
18
+ (_search = search).use.apply(_search, _(middlewares));
19
+ return function() {
20
+ var _search;
21
+ (_search = search).unuse.apply(_search, _(middlewares));
22
+ };
23
+ }, [
24
+ search
25
+ ]);
26
+ var refresh = useCallback(function() {
27
+ search.refresh();
28
+ }, [
29
+ search
30
+ ]);
31
+ useIsomorphicLayoutEffect(function() {
32
+ if (catchError) {
33
+ var onError = function onError() {};
34
+ search.addListener('error', onError);
35
+ return function() {
36
+ return search.removeListener('error', onError);
37
+ };
38
+ }
39
+ return function() {};
40
+ }, [
41
+ search,
42
+ catchError
43
+ ]);
44
+ return {
45
+ results: results,
46
+ scopedResults: scopedResults,
47
+ uiState: uiState,
48
+ setUiState: setUiState,
49
+ indexUiState: indexUiState,
50
+ setIndexUiState: setIndexUiState,
51
+ renderState: renderState,
52
+ indexRenderState: indexRenderState,
53
+ addMiddlewares: addMiddlewares,
54
+ refresh: refresh,
55
+ status: search.status,
56
+ error: search.error
27
57
  };
28
- }, [search]);
29
- var refresh = useCallback(function () {
30
- search.refresh();
31
- }, [search]);
32
- useIsomorphicLayoutEffect(function () {
33
- if (catchError) {
34
- var onError = function onError() {};
35
- search.addListener('error', onError);
36
- return function () {
37
- return search.removeListener('error', onError);
38
- };
39
- }
40
- return function () {};
41
- }, [search, catchError]);
42
- return {
43
- results: results,
44
- scopedResults: scopedResults,
45
- uiState: uiState,
46
- setUiState: setUiState,
47
- indexUiState: indexUiState,
48
- setIndexUiState: setIndexUiState,
49
- renderState: renderState,
50
- indexRenderState: indexRenderState,
51
- addMiddlewares: addMiddlewares,
52
- refresh: refresh,
53
- status: search.status,
54
- error: search.error
55
- };
56
- }
58
+ }
59
+
60
+ export { useInstantSearch };
package/dist/es/index.js CHANGED
@@ -1,43 +1,43 @@
1
- export { default as version } from "./version.js";
2
- export * from "./components/Configure.js";
3
- export * from "./components/DynamicWidgets.js";
4
- export * from "./components/Index.js";
5
- export * from "./components/InstantSearch.js";
6
- export * from "./components/InstantSearchServerContext.js";
7
- export * from "./components/InstantSearchSSRProvider.js";
8
- export * from "./connectors/useAutocomplete.js";
9
- export * from "./connectors/useBreadcrumb.js";
10
- export * from "./connectors/useChat.js";
11
- export * from "./connectors/useClearRefinements.js";
12
- export * from "./connectors/useConfigure.js";
13
- export * from "./connectors/useCurrentRefinements.js";
14
- export * from "./connectors/useDynamicWidgets.js";
15
- export * from "./connectors/useFrequentlyBoughtTogether.js";
16
- export * from "./connectors/useGeoSearch.js";
17
- export * from "./connectors/useHierarchicalMenu.js";
18
- export * from "./connectors/useHits.js";
19
- export * from "./connectors/useHitsPerPage.js";
20
- export * from "./connectors/useInfiniteHits.js";
21
- export * from "./connectors/useMenu.js";
22
- export * from "./connectors/useNumericMenu.js";
23
- export * from "./connectors/usePagination.js";
24
- export * from "./connectors/usePoweredBy.js";
25
- export * from "./connectors/useQueryRules.js";
26
- export * from "./connectors/useRange.js";
27
- export * from "./connectors/useRefinementList.js";
28
- export * from "./connectors/useRelatedProducts.js";
29
- export * from "./connectors/useSearchBox.js";
30
- export * from "./connectors/useSortBy.js";
31
- export * from "./connectors/useStats.js";
32
- export * from "./connectors/useToggleRefinement.js";
33
- export * from "./connectors/useTrendingItems.js";
34
- export * from "./connectors/useLookingSimilar.js";
35
- export * from "./connectors/useFilterSuggestions.js";
36
- export * from "./hooks/useConnector.js";
37
- export * from "./hooks/useInstantSearch.js";
38
- export * from "./lib/wrapPromiseWithState.js";
39
- export * from "./lib/useInstantSearchContext.js";
40
- export * from "./lib/useRSCContext.js";
41
- export * from "./lib/InstantSearchRSCContext.js";
42
- export * from "./lib/InstantSearchSSRContext.js";
43
- export * from "./server/index.js";
1
+ export { default as version } from './version.js';
2
+ export { Configure } from './components/Configure.js';
3
+ export { DynamicWidgets } from './components/DynamicWidgets.js';
4
+ export { Index } from './components/Index.js';
5
+ export { InstantSearch } from './components/InstantSearch.js';
6
+ export { InstantSearchServerContext } from './components/InstantSearchServerContext.js';
7
+ export { InstantSearchSSRProvider } from './components/InstantSearchSSRProvider.js';
8
+ export { useAutocomplete } from './connectors/useAutocomplete.js';
9
+ export { useBreadcrumb } from './connectors/useBreadcrumb.js';
10
+ export { useChat } from './connectors/useChat.js';
11
+ export { useClearRefinements } from './connectors/useClearRefinements.js';
12
+ export { useConfigure } from './connectors/useConfigure.js';
13
+ export { useCurrentRefinements } from './connectors/useCurrentRefinements.js';
14
+ export { useDynamicWidgets } from './connectors/useDynamicWidgets.js';
15
+ export { useFrequentlyBoughtTogether } from './connectors/useFrequentlyBoughtTogether.js';
16
+ export { useGeoSearch } from './connectors/useGeoSearch.js';
17
+ export { useHierarchicalMenu } from './connectors/useHierarchicalMenu.js';
18
+ export { useHits } from './connectors/useHits.js';
19
+ export { useHitsPerPage } from './connectors/useHitsPerPage.js';
20
+ export { useInfiniteHits } from './connectors/useInfiniteHits.js';
21
+ export { useMenu } from './connectors/useMenu.js';
22
+ export { useNumericMenu } from './connectors/useNumericMenu.js';
23
+ export { usePagination } from './connectors/usePagination.js';
24
+ export { usePoweredBy } from './connectors/usePoweredBy.js';
25
+ export { useQueryRules } from './connectors/useQueryRules.js';
26
+ export { useRange } from './connectors/useRange.js';
27
+ export { useRefinementList } from './connectors/useRefinementList.js';
28
+ export { useRelatedProducts } from './connectors/useRelatedProducts.js';
29
+ export { useSearchBox } from './connectors/useSearchBox.js';
30
+ export { useSortBy } from './connectors/useSortBy.js';
31
+ export { useStats } from './connectors/useStats.js';
32
+ export { useToggleRefinement } from './connectors/useToggleRefinement.js';
33
+ export { useTrendingItems } from './connectors/useTrendingItems.js';
34
+ export { useLookingSimilar } from './connectors/useLookingSimilar.js';
35
+ export { useFilterSuggestions } from './connectors/useFilterSuggestions.js';
36
+ export { useConnector } from './hooks/useConnector.js';
37
+ export { useInstantSearch } from './hooks/useInstantSearch.js';
38
+ export { wrapPromiseWithState } from './lib/wrapPromiseWithState.js';
39
+ export { useInstantSearchContext } from './lib/useInstantSearchContext.js';
40
+ export { useRSCContext } from './lib/useRSCContext.js';
41
+ export { InstantSearchRSCContext } from './lib/InstantSearchRSCContext.js';
42
+ export { InstantSearchSSRContext } from './lib/InstantSearchSSRContext.js';
43
+ export { getServerState } from './server/getServerState.js';
@@ -1,5 +1,5 @@
1
1
  import { createContext } from 'react';
2
- export var IndexContext = /*#__PURE__*/createContext(null);
3
- if (process.env.NODE_ENV === 'development') {
4
- IndexContext.displayName = 'Index';
5
- }
2
+
3
+ var IndexContext = createContext(null);
4
+
5
+ export { IndexContext };
@@ -1,5 +1,5 @@
1
1
  import { createContext } from 'react';
2
- export var InstantSearchContext = /*#__PURE__*/createContext(null);
3
- if (process.env.NODE_ENV === 'development') {
4
- InstantSearchContext.displayName = 'InstantSearch';
5
- }
2
+
3
+ var InstantSearchContext = createContext(null);
4
+
5
+ export { InstantSearchContext };
@@ -1,8 +1,11 @@
1
1
  import { createContext } from 'react';
2
- export var InstantSearchRSCContext = /*#__PURE__*/createContext({
3
- countRef: {
4
- current: 0
5
- },
6
- waitForResultsRef: null,
7
- ignoreMultipleHooksWarning: false
8
- });
2
+
3
+ var InstantSearchRSCContext = createContext({
4
+ countRef: {
5
+ current: 0
6
+ },
7
+ waitForResultsRef: null,
8
+ ignoreMultipleHooksWarning: false
9
+ });
10
+
11
+ export { InstantSearchRSCContext };
@@ -1,5 +1,5 @@
1
1
  import { createContext } from 'react';
2
- export var InstantSearchSSRContext = /*#__PURE__*/createContext(null);
3
- if (process.env.NODE_ENV === 'development') {
4
- InstantSearchSSRContext.displayName = 'InstantSearchSSR';
5
- }
2
+
3
+ var InstantSearchSSRContext = createContext(null);
4
+
5
+ export { InstantSearchSSRContext };
@@ -1,20 +1,24 @@
1
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
- }
2
+
3
+ function createSearchResults(state) {
4
+ var _state_query, _state_page, _state_hitsPerPage;
5
+ return new algoliasearchHelper.SearchResults(state, [
6
+ {
7
+ query: (_state_query = state.query) !== null && _state_query !== void 0 ? _state_query : '',
8
+ page: (_state_page = state.page) !== null && _state_page !== void 0 ? _state_page : 0,
9
+ hitsPerPage: (_state_hitsPerPage = state.hitsPerPage) !== null && _state_hitsPerPage !== void 0 ? _state_hitsPerPage : 20,
10
+ hits: [],
11
+ nbHits: 0,
12
+ nbPages: 0,
13
+ params: '',
14
+ exhaustiveNbHits: true,
15
+ exhaustiveFacetsCount: true,
16
+ processingTimeMS: 0,
17
+ index: state.index
18
+ }
19
+ ], {
20
+ /** used by connectors to prevent persisting these results */ __isArtificial: true
21
+ });
22
+ }
23
+
24
+ export { createSearchResults };