react-instantsearch-core 7.8.1 → 7.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/components/InstantSearchSSRProvider.js +5 -1
- package/dist/cjs/connectors/useFrequentlyBoughtTogether.js +12 -0
- package/dist/cjs/connectors/useLookingSimilar.js +12 -0
- package/dist/cjs/connectors/useRelatedProducts.js +12 -0
- package/dist/cjs/connectors/useTrendingItems.js +12 -0
- package/dist/cjs/hooks/useConnector.js +5 -2
- package/dist/cjs/index.js +48 -0
- package/dist/cjs/lib/getIndexSearchResults.js +2 -1
- package/dist/cjs/lib/useSearchResults.js +6 -1
- package/dist/cjs/server/getServerState.js +7 -3
- package/dist/cjs/version.js +1 -1
- package/dist/es/components/InstantSearchSSRProvider.js +5 -1
- package/dist/es/connectors/useFrequentlyBoughtTogether.d.ts +5 -0
- package/dist/es/connectors/useFrequentlyBoughtTogether.js +5 -0
- package/dist/es/connectors/useLookingSimilar.d.ts +5 -0
- package/dist/es/connectors/useLookingSimilar.js +5 -0
- package/dist/es/connectors/useRelatedProducts.d.ts +5 -0
- package/dist/es/connectors/useRelatedProducts.js +5 -0
- package/dist/es/connectors/useTrendingItems.d.ts +5 -0
- package/dist/es/connectors/useTrendingItems.js +5 -0
- package/dist/es/hooks/useConnector.js +5 -2
- package/dist/es/index.d.ts +4 -0
- package/dist/es/index.js +4 -0
- package/dist/es/lib/InstantSearchSSRContext.d.ts +1 -0
- package/dist/es/lib/getIndexSearchResults.d.ts +1 -0
- package/dist/es/lib/getIndexSearchResults.js +2 -1
- package/dist/es/lib/useSearchResults.js +6 -1
- package/dist/es/server/getServerState.js +8 -4
- package/dist/es/version.d.ts +1 -1
- package/dist/es/version.js +1 -1
- package/dist/umd/ReactInstantSearchCore.js +1794 -891
- 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 +4 -4
|
@@ -27,6 +27,9 @@ function InstantSearchSSRProvider(_ref) {
|
|
|
27
27
|
// `InstantSearch` on mount.
|
|
28
28
|
var ssrSearchRef = _react.default.useRef(null);
|
|
29
29
|
|
|
30
|
+
// This is used to re-map the result index to the requesting widget
|
|
31
|
+
var recommendIdx = _react.default.useRef(0);
|
|
32
|
+
|
|
30
33
|
// When <DynamicWidgets> is mounted, a second provider is used above the user-land
|
|
31
34
|
// <InstantSearchSSRProvider> in `getServerState()`.
|
|
32
35
|
// To avoid the user's provider overriding the context value with an empty object,
|
|
@@ -36,7 +39,8 @@ function InstantSearchSSRProvider(_ref) {
|
|
|
36
39
|
}
|
|
37
40
|
return /*#__PURE__*/_react.default.createElement(_InstantSearchSSRContext.InstantSearchSSRContext.Provider, {
|
|
38
41
|
value: _objectSpread(_objectSpread({}, props), {}, {
|
|
39
|
-
ssrSearchRef: ssrSearchRef
|
|
42
|
+
ssrSearchRef: ssrSearchRef,
|
|
43
|
+
recommendIdx: recommendIdx
|
|
40
44
|
})
|
|
41
45
|
}, children);
|
|
42
46
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.useFrequentlyBoughtTogether = useFrequentlyBoughtTogether;
|
|
7
|
+
var _connectFrequentlyBoughtTogether = _interopRequireDefault(require("instantsearch.js/cjs/connectors/frequently-bought-together/connectFrequentlyBoughtTogether"));
|
|
8
|
+
var _useConnector = require("../hooks/useConnector");
|
|
9
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
10
|
+
function useFrequentlyBoughtTogether(props, additionalWidgetProperties) {
|
|
11
|
+
return (0, _useConnector.useConnector)(_connectFrequentlyBoughtTogether.default, props, additionalWidgetProperties);
|
|
12
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.useLookingSimilar = useLookingSimilar;
|
|
7
|
+
var _connectLookingSimilar = _interopRequireDefault(require("instantsearch.js/cjs/connectors/looking-similar/connectLookingSimilar"));
|
|
8
|
+
var _useConnector = require("../hooks/useConnector");
|
|
9
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
10
|
+
function useLookingSimilar(props, additionalWidgetProperties) {
|
|
11
|
+
return (0, _useConnector.useConnector)(_connectLookingSimilar.default, props, additionalWidgetProperties);
|
|
12
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.useRelatedProducts = useRelatedProducts;
|
|
7
|
+
var _connectRelatedProducts = _interopRequireDefault(require("instantsearch.js/cjs/connectors/related-products/connectRelatedProducts"));
|
|
8
|
+
var _useConnector = require("../hooks/useConnector");
|
|
9
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
10
|
+
function useRelatedProducts(props, additionalWidgetProperties) {
|
|
11
|
+
return (0, _useConnector.useConnector)(_connectRelatedProducts.default, props, additionalWidgetProperties);
|
|
12
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.useTrendingItems = useTrendingItems;
|
|
7
|
+
var _connectTrendingItems = _interopRequireDefault(require("instantsearch.js/cjs/connectors/trending-items/connectTrendingItems"));
|
|
8
|
+
var _useConnector = require("../hooks/useConnector");
|
|
9
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
10
|
+
function useTrendingItems(props, additionalWidgetProperties) {
|
|
11
|
+
return (0, _useConnector.useConnector)(_connectTrendingItems.default, props, additionalWidgetProperties);
|
|
12
|
+
}
|
|
@@ -11,6 +11,7 @@ var _getIndexSearchResults = require("../lib/getIndexSearchResults");
|
|
|
11
11
|
var _useIndexContext = require("../lib/useIndexContext");
|
|
12
12
|
var _useInstantSearchContext = require("../lib/useInstantSearchContext");
|
|
13
13
|
var _useInstantSearchServerContext = require("../lib/useInstantSearchServerContext");
|
|
14
|
+
var _useInstantSearchSSRContext = require("../lib/useInstantSearchSSRContext");
|
|
14
15
|
var _useStableValue = require("../lib/useStableValue");
|
|
15
16
|
var _useWidget = require("../lib/useWidget");
|
|
16
17
|
var _excluded = ["instantSearchInstance", "widgetParams"],
|
|
@@ -32,6 +33,7 @@ function useConnector(connector) {
|
|
|
32
33
|
var props = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
33
34
|
var additionalWidgetProperties = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
34
35
|
var serverContext = (0, _useInstantSearchServerContext.useInstantSearchServerContext)();
|
|
36
|
+
var ssrContext = (0, _useInstantSearchSSRContext.useInstantSearchSSRContext)();
|
|
35
37
|
var search = (0, _useInstantSearchContext.useInstantSearchContext)();
|
|
36
38
|
var parentIndex = (0, _useIndexContext.useIndexContext)();
|
|
37
39
|
var stableProps = (0, _useStableValue.useStableValue)(props);
|
|
@@ -96,7 +98,8 @@ function useConnector(connector) {
|
|
|
96
98
|
})) || helper.state;
|
|
97
99
|
var _getIndexSearchResult = (0, _getIndexSearchResults.getIndexSearchResults)(parentIndex),
|
|
98
100
|
results = _getIndexSearchResult.results,
|
|
99
|
-
scopedResults = _getIndexSearchResult.scopedResults
|
|
101
|
+
scopedResults = _getIndexSearchResult.scopedResults,
|
|
102
|
+
recommendResults = _getIndexSearchResult.recommendResults;
|
|
100
103
|
|
|
101
104
|
// We get the widget render state by providing the same parameters as
|
|
102
105
|
// InstantSearch provides to the widget's `render` method.
|
|
@@ -105,7 +108,7 @@ function useConnector(connector) {
|
|
|
105
108
|
helper: helper,
|
|
106
109
|
parent: parentIndex,
|
|
107
110
|
instantSearchInstance: search,
|
|
108
|
-
results: results,
|
|
111
|
+
results: widget.dependsOn === 'recommend' && recommendResults && ssrContext ? recommendResults[ssrContext.recommendIdx.current++] : results,
|
|
109
112
|
scopedResults: scopedResults,
|
|
110
113
|
state: helper.state,
|
|
111
114
|
renderState: search.renderState,
|
package/dist/cjs/index.js
CHANGED
|
@@ -145,6 +145,18 @@ Object.keys(_useDynamicWidgets).forEach(function (key) {
|
|
|
145
145
|
}
|
|
146
146
|
});
|
|
147
147
|
});
|
|
148
|
+
var _useFrequentlyBoughtTogether = require("./connectors/useFrequentlyBoughtTogether");
|
|
149
|
+
Object.keys(_useFrequentlyBoughtTogether).forEach(function (key) {
|
|
150
|
+
if (key === "default" || key === "__esModule") return;
|
|
151
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
152
|
+
if (key in exports && exports[key] === _useFrequentlyBoughtTogether[key]) return;
|
|
153
|
+
Object.defineProperty(exports, key, {
|
|
154
|
+
enumerable: true,
|
|
155
|
+
get: function get() {
|
|
156
|
+
return _useFrequentlyBoughtTogether[key];
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
});
|
|
148
160
|
var _useGeoSearch = require("./connectors/useGeoSearch");
|
|
149
161
|
Object.keys(_useGeoSearch).forEach(function (key) {
|
|
150
162
|
if (key === "default" || key === "__esModule") return;
|
|
@@ -289,6 +301,18 @@ Object.keys(_useRefinementList).forEach(function (key) {
|
|
|
289
301
|
}
|
|
290
302
|
});
|
|
291
303
|
});
|
|
304
|
+
var _useRelatedProducts = require("./connectors/useRelatedProducts");
|
|
305
|
+
Object.keys(_useRelatedProducts).forEach(function (key) {
|
|
306
|
+
if (key === "default" || key === "__esModule") return;
|
|
307
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
308
|
+
if (key in exports && exports[key] === _useRelatedProducts[key]) return;
|
|
309
|
+
Object.defineProperty(exports, key, {
|
|
310
|
+
enumerable: true,
|
|
311
|
+
get: function get() {
|
|
312
|
+
return _useRelatedProducts[key];
|
|
313
|
+
}
|
|
314
|
+
});
|
|
315
|
+
});
|
|
292
316
|
var _useSearchBox = require("./connectors/useSearchBox");
|
|
293
317
|
Object.keys(_useSearchBox).forEach(function (key) {
|
|
294
318
|
if (key === "default" || key === "__esModule") return;
|
|
@@ -337,6 +361,30 @@ Object.keys(_useToggleRefinement).forEach(function (key) {
|
|
|
337
361
|
}
|
|
338
362
|
});
|
|
339
363
|
});
|
|
364
|
+
var _useTrendingItems = require("./connectors/useTrendingItems");
|
|
365
|
+
Object.keys(_useTrendingItems).forEach(function (key) {
|
|
366
|
+
if (key === "default" || key === "__esModule") return;
|
|
367
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
368
|
+
if (key in exports && exports[key] === _useTrendingItems[key]) return;
|
|
369
|
+
Object.defineProperty(exports, key, {
|
|
370
|
+
enumerable: true,
|
|
371
|
+
get: function get() {
|
|
372
|
+
return _useTrendingItems[key];
|
|
373
|
+
}
|
|
374
|
+
});
|
|
375
|
+
});
|
|
376
|
+
var _useLookingSimilar = require("./connectors/useLookingSimilar");
|
|
377
|
+
Object.keys(_useLookingSimilar).forEach(function (key) {
|
|
378
|
+
if (key === "default" || key === "__esModule") return;
|
|
379
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
380
|
+
if (key in exports && exports[key] === _useLookingSimilar[key]) return;
|
|
381
|
+
Object.defineProperty(exports, key, {
|
|
382
|
+
enumerable: true,
|
|
383
|
+
get: function get() {
|
|
384
|
+
return _useLookingSimilar[key];
|
|
385
|
+
}
|
|
386
|
+
});
|
|
387
|
+
});
|
|
340
388
|
var _useConnector = require("./hooks/useConnector");
|
|
341
389
|
Object.keys(_useConnector).forEach(function (key) {
|
|
342
390
|
if (key === "default" || key === "__esModule") return;
|
|
@@ -19,7 +19,12 @@ function useSearchResults() {
|
|
|
19
19
|
var search = (0, _useInstantSearchContext.useInstantSearchContext)();
|
|
20
20
|
var searchIndex = (0, _useIndexContext.useIndexContext)();
|
|
21
21
|
var _useState = (0, _react.useState)(function () {
|
|
22
|
-
|
|
22
|
+
var indexSearchResults = (0, _getIndexSearchResults.getIndexSearchResults)(searchIndex);
|
|
23
|
+
// We do this not to leak `recommendResults` in the API.
|
|
24
|
+
return {
|
|
25
|
+
results: indexSearchResults.results,
|
|
26
|
+
scopedResults: indexSearchResults.scopedResults
|
|
27
|
+
};
|
|
23
28
|
}),
|
|
24
29
|
_useState2 = _slicedToArray(_useState, 2),
|
|
25
30
|
searchResults = _useState2[0],
|
|
@@ -17,6 +17,7 @@ function getServerState(children, _ref) {
|
|
|
17
17
|
var searchRef = {
|
|
18
18
|
current: undefined
|
|
19
19
|
};
|
|
20
|
+
(0, _utils.resetWidgetId)();
|
|
20
21
|
var createNotifyServer = function createNotifyServer() {
|
|
21
22
|
var hasBeenNotified = false;
|
|
22
23
|
var notifyServer = function notifyServer(_ref2) {
|
|
@@ -45,11 +46,13 @@ function getServerState(children, _ref) {
|
|
|
45
46
|
});
|
|
46
47
|
});
|
|
47
48
|
if (shouldRefetch) {
|
|
49
|
+
(0, _utils.resetWidgetId)();
|
|
48
50
|
return execute({
|
|
49
51
|
children: /*#__PURE__*/_react.default.createElement(_.InstantSearchSSRProvider, serverState, children),
|
|
50
52
|
renderToString: renderToString,
|
|
51
53
|
searchRef: searchRef,
|
|
52
|
-
notifyServer: createNotifyServer()
|
|
54
|
+
notifyServer: createNotifyServer(),
|
|
55
|
+
skipRecommend: true
|
|
53
56
|
});
|
|
54
57
|
}
|
|
55
58
|
return serverState;
|
|
@@ -59,7 +62,8 @@ function execute(_ref3) {
|
|
|
59
62
|
var children = _ref3.children,
|
|
60
63
|
renderToString = _ref3.renderToString,
|
|
61
64
|
notifyServer = _ref3.notifyServer,
|
|
62
|
-
searchRef = _ref3.searchRef
|
|
65
|
+
searchRef = _ref3.searchRef,
|
|
66
|
+
skipRecommend = _ref3.skipRecommend;
|
|
63
67
|
return Promise.resolve().then(function () {
|
|
64
68
|
renderToString( /*#__PURE__*/_react.default.createElement(_.InstantSearchServerContext.Provider, {
|
|
65
69
|
value: {
|
|
@@ -84,7 +88,7 @@ function execute(_ref3) {
|
|
|
84
88
|
if (!searchRef.current) {
|
|
85
89
|
throw new Error("Unable to retrieve InstantSearch's server state in `getServerState()`. Did you mount the <InstantSearch> component?");
|
|
86
90
|
}
|
|
87
|
-
return (0, _server.waitForResults)(searchRef.current);
|
|
91
|
+
return (0, _server.waitForResults)(searchRef.current, skipRecommend);
|
|
88
92
|
}).then(function (requestParamsList) {
|
|
89
93
|
return {
|
|
90
94
|
initialResults: (0, _server.getInitialResults)(searchRef.current.mainIndex, requestParamsList)
|
package/dist/cjs/version.js
CHANGED
|
@@ -20,6 +20,9 @@ export function InstantSearchSSRProvider(_ref) {
|
|
|
20
20
|
// `InstantSearch` on mount.
|
|
21
21
|
var ssrSearchRef = React.useRef(null);
|
|
22
22
|
|
|
23
|
+
// This is used to re-map the result index to the requesting widget
|
|
24
|
+
var recommendIdx = React.useRef(0);
|
|
25
|
+
|
|
23
26
|
// When <DynamicWidgets> is mounted, a second provider is used above the user-land
|
|
24
27
|
// <InstantSearchSSRProvider> in `getServerState()`.
|
|
25
28
|
// To avoid the user's provider overriding the context value with an empty object,
|
|
@@ -29,7 +32,8 @@ export function InstantSearchSSRProvider(_ref) {
|
|
|
29
32
|
}
|
|
30
33
|
return /*#__PURE__*/React.createElement(InstantSearchSSRContext.Provider, {
|
|
31
34
|
value: _objectSpread(_objectSpread({}, props), {}, {
|
|
32
|
-
ssrSearchRef: ssrSearchRef
|
|
35
|
+
ssrSearchRef: ssrSearchRef,
|
|
36
|
+
recommendIdx: recommendIdx
|
|
33
37
|
})
|
|
34
38
|
}, children);
|
|
35
39
|
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { AdditionalWidgetProperties } from '../hooks/useConnector';
|
|
2
|
+
import type { BaseHit } from 'instantsearch.js';
|
|
3
|
+
import type { FrequentlyBoughtTogetherConnectorParams } from 'instantsearch.js/es/connectors/frequently-bought-together/connectFrequentlyBoughtTogether';
|
|
4
|
+
export type UseFrequentlyBoughtTogetherProps<THit extends BaseHit = BaseHit> = FrequentlyBoughtTogetherConnectorParams<THit>;
|
|
5
|
+
export declare function useFrequentlyBoughtTogether<THit extends BaseHit = BaseHit>(props?: UseFrequentlyBoughtTogetherProps<THit>, additionalWidgetProperties?: AdditionalWidgetProperties): import("instantsearch.js/es/connectors/frequently-bought-together/connectFrequentlyBoughtTogether").FrequentlyBoughtTogetherRenderState<THit>;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import connectFrequentlyBoughtTogether from "instantsearch.js/es/connectors/frequently-bought-together/connectFrequentlyBoughtTogether.js";
|
|
2
|
+
import { useConnector } from "../hooks/useConnector.js";
|
|
3
|
+
export function useFrequentlyBoughtTogether(props, additionalWidgetProperties) {
|
|
4
|
+
return useConnector(connectFrequentlyBoughtTogether, props, additionalWidgetProperties);
|
|
5
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { AdditionalWidgetProperties } from '../hooks/useConnector';
|
|
2
|
+
import type { BaseHit } from 'instantsearch.js';
|
|
3
|
+
import type { LookingSimilarConnectorParams } from 'instantsearch.js/es/connectors/looking-similar/connectLookingSimilar';
|
|
4
|
+
export type UseLookingSimilarProps<THit extends BaseHit = BaseHit> = LookingSimilarConnectorParams<THit>;
|
|
5
|
+
export declare function useLookingSimilar<THit extends BaseHit = BaseHit>(props?: UseLookingSimilarProps<THit>, additionalWidgetProperties?: AdditionalWidgetProperties): import("instantsearch.js/es/connectors/looking-similar/connectLookingSimilar").LookingSimilarRenderState<THit>;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import connectLookingSimilar from "instantsearch.js/es/connectors/looking-similar/connectLookingSimilar.js";
|
|
2
|
+
import { useConnector } from "../hooks/useConnector.js";
|
|
3
|
+
export function useLookingSimilar(props, additionalWidgetProperties) {
|
|
4
|
+
return useConnector(connectLookingSimilar, props, additionalWidgetProperties);
|
|
5
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { AdditionalWidgetProperties } from '../hooks/useConnector';
|
|
2
|
+
import type { BaseHit } from 'instantsearch.js';
|
|
3
|
+
import type { RelatedProductsConnectorParams } from 'instantsearch.js/es/connectors/related-products/connectRelatedProducts';
|
|
4
|
+
export type UseRelatedProductsProps<THit extends BaseHit = BaseHit> = RelatedProductsConnectorParams<THit>;
|
|
5
|
+
export declare function useRelatedProducts<THit extends BaseHit = BaseHit>(props: UseRelatedProductsProps<THit>, additionalWidgetProperties?: AdditionalWidgetProperties): import("instantsearch.js/es/connectors/related-products/connectRelatedProducts").RelatedProductsRenderState<THit>;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import connectRelatedProducts from "instantsearch.js/es/connectors/related-products/connectRelatedProducts.js";
|
|
2
|
+
import { useConnector } from "../hooks/useConnector.js";
|
|
3
|
+
export function useRelatedProducts(props, additionalWidgetProperties) {
|
|
4
|
+
return useConnector(connectRelatedProducts, props, additionalWidgetProperties);
|
|
5
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { AdditionalWidgetProperties } from '../hooks/useConnector';
|
|
2
|
+
import type { BaseHit } from 'instantsearch.js';
|
|
3
|
+
import type { TrendingItemsConnectorParams } from 'instantsearch.js/es/connectors/trending-items/connectTrendingItems';
|
|
4
|
+
export type UseTrendingItemsProps<THit extends BaseHit = BaseHit> = TrendingItemsConnectorParams<THit>;
|
|
5
|
+
export declare function useTrendingItems<THit extends BaseHit = BaseHit>(props?: UseTrendingItemsProps<THit>, additionalWidgetProperties?: AdditionalWidgetProperties): import("instantsearch.js/es/connectors/trending-items/connectTrendingItems").TrendingItemsRenderState<THit>;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import connectTrendingItems from "instantsearch.js/es/connectors/trending-items/connectTrendingItems.js";
|
|
2
|
+
import { useConnector } from "../hooks/useConnector.js";
|
|
3
|
+
export function useTrendingItems(props, additionalWidgetProperties) {
|
|
4
|
+
return useConnector(connectTrendingItems, props, additionalWidgetProperties);
|
|
5
|
+
}
|
|
@@ -20,12 +20,14 @@ import { getIndexSearchResults } from "../lib/getIndexSearchResults.js";
|
|
|
20
20
|
import { useIndexContext } from "../lib/useIndexContext.js";
|
|
21
21
|
import { useInstantSearchContext } from "../lib/useInstantSearchContext.js";
|
|
22
22
|
import { useInstantSearchServerContext } from "../lib/useInstantSearchServerContext.js";
|
|
23
|
+
import { useInstantSearchSSRContext } from "../lib/useInstantSearchSSRContext.js";
|
|
23
24
|
import { useStableValue } from "../lib/useStableValue.js";
|
|
24
25
|
import { useWidget } from "../lib/useWidget.js";
|
|
25
26
|
export function useConnector(connector) {
|
|
26
27
|
var props = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
27
28
|
var additionalWidgetProperties = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
28
29
|
var serverContext = useInstantSearchServerContext();
|
|
30
|
+
var ssrContext = useInstantSearchSSRContext();
|
|
29
31
|
var search = useInstantSearchContext();
|
|
30
32
|
var parentIndex = useIndexContext();
|
|
31
33
|
var stableProps = useStableValue(props);
|
|
@@ -90,7 +92,8 @@ export function useConnector(connector) {
|
|
|
90
92
|
})) || helper.state;
|
|
91
93
|
var _getIndexSearchResult = getIndexSearchResults(parentIndex),
|
|
92
94
|
results = _getIndexSearchResult.results,
|
|
93
|
-
scopedResults = _getIndexSearchResult.scopedResults
|
|
95
|
+
scopedResults = _getIndexSearchResult.scopedResults,
|
|
96
|
+
recommendResults = _getIndexSearchResult.recommendResults;
|
|
94
97
|
|
|
95
98
|
// We get the widget render state by providing the same parameters as
|
|
96
99
|
// InstantSearch provides to the widget's `render` method.
|
|
@@ -99,7 +102,7 @@ export function useConnector(connector) {
|
|
|
99
102
|
helper: helper,
|
|
100
103
|
parent: parentIndex,
|
|
101
104
|
instantSearchInstance: search,
|
|
102
|
-
results: results,
|
|
105
|
+
results: widget.dependsOn === 'recommend' && recommendResults && ssrContext ? recommendResults[ssrContext.recommendIdx.current++] : results,
|
|
103
106
|
scopedResults: scopedResults,
|
|
104
107
|
state: helper.state,
|
|
105
108
|
renderState: search.renderState,
|
package/dist/es/index.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ export * from './connectors/useClearRefinements';
|
|
|
10
10
|
export * from './connectors/useConfigure';
|
|
11
11
|
export * from './connectors/useCurrentRefinements';
|
|
12
12
|
export * from './connectors/useDynamicWidgets';
|
|
13
|
+
export * from './connectors/useFrequentlyBoughtTogether';
|
|
13
14
|
export * from './connectors/useGeoSearch';
|
|
14
15
|
export * from './connectors/useHierarchicalMenu';
|
|
15
16
|
export * from './connectors/useHits';
|
|
@@ -22,10 +23,13 @@ export * from './connectors/usePoweredBy';
|
|
|
22
23
|
export * from './connectors/useQueryRules';
|
|
23
24
|
export * from './connectors/useRange';
|
|
24
25
|
export * from './connectors/useRefinementList';
|
|
26
|
+
export * from './connectors/useRelatedProducts';
|
|
25
27
|
export * from './connectors/useSearchBox';
|
|
26
28
|
export * from './connectors/useSortBy';
|
|
27
29
|
export * from './connectors/useStats';
|
|
28
30
|
export * from './connectors/useToggleRefinement';
|
|
31
|
+
export * from './connectors/useTrendingItems';
|
|
32
|
+
export * from './connectors/useLookingSimilar';
|
|
29
33
|
export * from './hooks/useConnector';
|
|
30
34
|
export * from './hooks/useInstantSearch';
|
|
31
35
|
export * from './lib/wrapPromiseWithState';
|
package/dist/es/index.js
CHANGED
|
@@ -10,6 +10,7 @@ export * from "./connectors/useClearRefinements.js";
|
|
|
10
10
|
export * from "./connectors/useConfigure.js";
|
|
11
11
|
export * from "./connectors/useCurrentRefinements.js";
|
|
12
12
|
export * from "./connectors/useDynamicWidgets.js";
|
|
13
|
+
export * from "./connectors/useFrequentlyBoughtTogether.js";
|
|
13
14
|
export * from "./connectors/useGeoSearch.js";
|
|
14
15
|
export * from "./connectors/useHierarchicalMenu.js";
|
|
15
16
|
export * from "./connectors/useHits.js";
|
|
@@ -22,10 +23,13 @@ export * from "./connectors/usePoweredBy.js";
|
|
|
22
23
|
export * from "./connectors/useQueryRules.js";
|
|
23
24
|
export * from "./connectors/useRange.js";
|
|
24
25
|
export * from "./connectors/useRefinementList.js";
|
|
26
|
+
export * from "./connectors/useRelatedProducts.js";
|
|
25
27
|
export * from "./connectors/useSearchBox.js";
|
|
26
28
|
export * from "./connectors/useSortBy.js";
|
|
27
29
|
export * from "./connectors/useStats.js";
|
|
28
30
|
export * from "./connectors/useToggleRefinement.js";
|
|
31
|
+
export * from "./connectors/useTrendingItems.js";
|
|
32
|
+
export * from "./connectors/useLookingSimilar.js";
|
|
29
33
|
export * from "./hooks/useConnector.js";
|
|
30
34
|
export * from "./hooks/useInstantSearch.js";
|
|
31
35
|
export * from "./lib/wrapPromiseWithState.js";
|
|
@@ -4,5 +4,6 @@ import type { UiState } from 'instantsearch.js';
|
|
|
4
4
|
import type { MutableRefObject } from 'react';
|
|
5
5
|
export type InstantSearchSSRContextApi<TUiState extends UiState, TRouteState = TUiState> = InstantSearchServerState & {
|
|
6
6
|
ssrSearchRef: MutableRefObject<InternalInstantSearch<TUiState, TRouteState> | null>;
|
|
7
|
+
recommendIdx: MutableRefObject<number>;
|
|
7
8
|
};
|
|
8
9
|
export declare const InstantSearchSSRContext: import("react").Context<Partial<InstantSearchSSRContextApi<UiState, UiState>> | null>;
|
|
@@ -13,7 +13,12 @@ export function useSearchResults() {
|
|
|
13
13
|
var search = useInstantSearchContext();
|
|
14
14
|
var searchIndex = useIndexContext();
|
|
15
15
|
var _useState = useState(function () {
|
|
16
|
-
|
|
16
|
+
var indexSearchResults = getIndexSearchResults(searchIndex);
|
|
17
|
+
// We do this not to leak `recommendResults` in the API.
|
|
18
|
+
return {
|
|
19
|
+
results: indexSearchResults.results,
|
|
20
|
+
scopedResults: indexSearchResults.scopedResults
|
|
21
|
+
};
|
|
17
22
|
}),
|
|
18
23
|
_useState2 = _slicedToArray(_useState, 2),
|
|
19
24
|
searchResults = _useState2[0],
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { getInitialResults, waitForResults } from "instantsearch.js/es/lib/server.js";
|
|
2
|
-
import { walkIndex } from "instantsearch.js/es/lib/utils/index.js";
|
|
2
|
+
import { walkIndex, resetWidgetId } from "instantsearch.js/es/lib/utils/index.js";
|
|
3
3
|
import React from 'react';
|
|
4
4
|
import { InstantSearchServerContext, InstantSearchSSRProvider } from "../index.js";
|
|
5
5
|
/**
|
|
@@ -10,6 +10,7 @@ export function getServerState(children, _ref) {
|
|
|
10
10
|
var searchRef = {
|
|
11
11
|
current: undefined
|
|
12
12
|
};
|
|
13
|
+
resetWidgetId();
|
|
13
14
|
var createNotifyServer = function createNotifyServer() {
|
|
14
15
|
var hasBeenNotified = false;
|
|
15
16
|
var notifyServer = function notifyServer(_ref2) {
|
|
@@ -38,11 +39,13 @@ export function getServerState(children, _ref) {
|
|
|
38
39
|
});
|
|
39
40
|
});
|
|
40
41
|
if (shouldRefetch) {
|
|
42
|
+
resetWidgetId();
|
|
41
43
|
return execute({
|
|
42
44
|
children: /*#__PURE__*/React.createElement(InstantSearchSSRProvider, serverState, children),
|
|
43
45
|
renderToString: renderToString,
|
|
44
46
|
searchRef: searchRef,
|
|
45
|
-
notifyServer: createNotifyServer()
|
|
47
|
+
notifyServer: createNotifyServer(),
|
|
48
|
+
skipRecommend: true
|
|
46
49
|
});
|
|
47
50
|
}
|
|
48
51
|
return serverState;
|
|
@@ -52,7 +55,8 @@ function execute(_ref3) {
|
|
|
52
55
|
var children = _ref3.children,
|
|
53
56
|
renderToString = _ref3.renderToString,
|
|
54
57
|
notifyServer = _ref3.notifyServer,
|
|
55
|
-
searchRef = _ref3.searchRef
|
|
58
|
+
searchRef = _ref3.searchRef,
|
|
59
|
+
skipRecommend = _ref3.skipRecommend;
|
|
56
60
|
return Promise.resolve().then(function () {
|
|
57
61
|
renderToString( /*#__PURE__*/React.createElement(InstantSearchServerContext.Provider, {
|
|
58
62
|
value: {
|
|
@@ -77,7 +81,7 @@ function execute(_ref3) {
|
|
|
77
81
|
if (!searchRef.current) {
|
|
78
82
|
throw new Error("Unable to retrieve InstantSearch's server state in `getServerState()`. Did you mount the <InstantSearch> component?");
|
|
79
83
|
}
|
|
80
|
-
return waitForResults(searchRef.current);
|
|
84
|
+
return waitForResults(searchRef.current, skipRecommend);
|
|
81
85
|
}).then(function (requestParamsList) {
|
|
82
86
|
return {
|
|
83
87
|
initialResults: getInitialResults(searchRef.current.mainIndex, requestParamsList)
|
package/dist/es/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default: "7.
|
|
1
|
+
declare const _default: "7.10.0";
|
|
2
2
|
export default _default;
|
package/dist/es/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export default '7.
|
|
1
|
+
export default '7.10.0';
|