instantsearch.js 4.68.1 → 4.70.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/cjs/connectors/frequently-bought-together/connectFrequentlyBoughtTogether.js +93 -0
- package/cjs/connectors/index.js +28 -0
- package/cjs/connectors/looking-similar/connectLookingSimilar.js +94 -0
- package/cjs/connectors/related-products/connectRelatedProducts.js +94 -0
- package/cjs/connectors/trending-items/connectTrendingItems.js +90 -0
- package/cjs/lib/InstantSearch.js +10 -1
- package/cjs/lib/server.js +28 -9
- package/cjs/lib/utils/addWidgetId.js +17 -0
- package/cjs/lib/utils/hydrateRecommendCache.js +23 -0
- package/cjs/lib/utils/hydrateSearchClient.js +7 -3
- package/cjs/lib/utils/index.js +22 -0
- package/cjs/lib/utils/render-args.js +3 -3
- package/cjs/lib/version.js +1 -1
- package/cjs/widgets/frequently-bought-together/frequently-bought-together.js +120 -0
- package/cjs/widgets/index/index.js +89 -20
- package/cjs/widgets/index.js +28 -0
- package/cjs/widgets/looking-similar/looking-similar.js +122 -0
- package/cjs/widgets/related-products/related-products.js +122 -0
- package/cjs/widgets/trending-items/trending-items.js +126 -0
- package/dist/instantsearch.development.d.ts +411 -12
- package/dist/instantsearch.development.js +1702 -265
- package/dist/instantsearch.development.js.map +1 -1
- package/dist/instantsearch.production.d.ts +411 -12
- package/dist/instantsearch.production.min.d.ts +411 -12
- package/dist/instantsearch.production.min.js +2 -2
- package/dist/instantsearch.production.min.js.map +1 -1
- package/es/connectors/frequently-bought-together/connectFrequentlyBoughtTogether.d.ts +45 -0
- package/es/connectors/frequently-bought-together/connectFrequentlyBoughtTogether.js +86 -0
- package/es/connectors/index.d.ts +4 -0
- package/es/connectors/index.js +5 -1
- package/es/connectors/looking-similar/connectLookingSimilar.d.ts +49 -0
- package/es/connectors/looking-similar/connectLookingSimilar.js +87 -0
- package/es/connectors/related-products/connectRelatedProducts.d.ts +49 -0
- package/es/connectors/related-products/connectRelatedProducts.js +87 -0
- package/es/connectors/trending-items/connectTrendingItems.d.ts +57 -0
- package/es/connectors/trending-items/connectTrendingItems.js +83 -0
- package/es/lib/InstantSearch.d.ts +2 -0
- package/es/lib/InstantSearch.js +11 -2
- package/es/lib/server.d.ts +1 -1
- package/es/lib/server.js +28 -9
- package/es/lib/templating/renderTemplate.d.ts +1 -1
- package/es/lib/utils/addWidgetId.d.ts +3 -0
- package/es/lib/utils/addWidgetId.js +10 -0
- package/es/lib/utils/hydrateRecommendCache.d.ts +3 -0
- package/es/lib/utils/hydrateRecommendCache.js +17 -0
- package/es/lib/utils/hydrateSearchClient.js +7 -3
- package/es/lib/utils/index.d.ts +2 -0
- package/es/lib/utils/index.js +2 -0
- package/es/lib/utils/render-args.d.ts +3 -3
- package/es/lib/utils/render-args.js +3 -3
- package/es/lib/version.d.ts +1 -1
- package/es/lib/version.js +1 -1
- package/es/types/results.d.ts +7 -3
- package/es/types/templates.d.ts +1 -1
- package/es/types/widget.d.ts +16 -9
- package/es/widgets/frequently-bought-together/frequently-bought-together.d.ts +41 -0
- package/es/widgets/frequently-bought-together/frequently-bought-together.js +112 -0
- package/es/widgets/index/index.d.ts +2 -1
- package/es/widgets/index/index.js +89 -20
- package/es/widgets/index.d.ts +4 -0
- package/es/widgets/index.js +5 -1
- package/es/widgets/looking-similar/looking-similar.d.ts +41 -0
- package/es/widgets/looking-similar/looking-similar.js +114 -0
- package/es/widgets/related-products/related-products.d.ts +41 -0
- package/es/widgets/related-products/related-products.js +114 -0
- package/es/widgets/trending-items/trending-items.d.ts +41 -0
- package/es/widgets/trending-items/trending-items.js +118 -0
- package/package.json +7 -7
|
@@ -16,6 +16,7 @@ function _objectWithoutProperties(source, excluded) { if (source == null) return
|
|
|
16
16
|
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
17
17
|
import algoliasearchHelper from 'algoliasearch-helper';
|
|
18
18
|
import { checkIndexUiState, createDocumentationMessageGenerator, resolveSearchParameters, mergeSearchParameters, warning, isIndexWidget, createInitArgs, createRenderArgs } from "../../lib/utils/index.js";
|
|
19
|
+
import { addWidgetId } from "../../lib/utils/addWidgetId.js";
|
|
19
20
|
var withUsage = createDocumentationMessageGenerator({
|
|
20
21
|
name: 'index-widget'
|
|
21
22
|
});
|
|
@@ -123,6 +124,8 @@ var index = function index(widgetParams) {
|
|
|
123
124
|
var helper = null;
|
|
124
125
|
var derivedHelper = null;
|
|
125
126
|
var lastValidSearchParameters = null;
|
|
127
|
+
var hasRecommendWidget = false;
|
|
128
|
+
var hasSearchWidget = false;
|
|
126
129
|
return {
|
|
127
130
|
$$type: 'ais.index',
|
|
128
131
|
$$widgetType: 'ais.index',
|
|
@@ -147,6 +150,16 @@ var index = function index(widgetParams) {
|
|
|
147
150
|
derivedHelper.lastResults._state = helper.state;
|
|
148
151
|
return derivedHelper.lastResults;
|
|
149
152
|
},
|
|
153
|
+
getResultsForWidget: function getResultsForWidget(widget) {
|
|
154
|
+
var _helper;
|
|
155
|
+
if (widget.dependsOn !== 'recommend' || isIndexWidget(widget) || widget.$$id === undefined) {
|
|
156
|
+
return this.getResults();
|
|
157
|
+
}
|
|
158
|
+
if (!((_helper = helper) !== null && _helper !== void 0 && _helper.lastRecommendResults)) {
|
|
159
|
+
return null;
|
|
160
|
+
}
|
|
161
|
+
return helper.lastRecommendResults[widget.$$id];
|
|
162
|
+
},
|
|
150
163
|
getPreviousState: function getPreviousState() {
|
|
151
164
|
return lastValidSearchParameters;
|
|
152
165
|
},
|
|
@@ -191,6 +204,21 @@ var index = function index(widgetParams) {
|
|
|
191
204
|
})) {
|
|
192
205
|
throw new Error(withUsage('The widget definition expects a `render` and/or an `init` method.'));
|
|
193
206
|
}
|
|
207
|
+
widgets.forEach(function (widget) {
|
|
208
|
+
if (isIndexWidget(widget)) {
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
if (localInstantSearchInstance && widget.dependsOn === 'recommend') {
|
|
212
|
+
localInstantSearchInstance._hasRecommendWidget = true;
|
|
213
|
+
} else if (localInstantSearchInstance) {
|
|
214
|
+
localInstantSearchInstance._hasSearchWidget = true;
|
|
215
|
+
} else if (widget.dependsOn === 'recommend') {
|
|
216
|
+
hasRecommendWidget = true;
|
|
217
|
+
} else {
|
|
218
|
+
hasSearchWidget = true;
|
|
219
|
+
}
|
|
220
|
+
addWidgetId(widget);
|
|
221
|
+
});
|
|
194
222
|
localWidgets = localWidgets.concat(widgets);
|
|
195
223
|
if (localInstantSearchInstance && Boolean(widgets.length)) {
|
|
196
224
|
privateHelperSetState(helper, {
|
|
@@ -240,16 +268,41 @@ var index = function index(widgetParams) {
|
|
|
240
268
|
localWidgets = localWidgets.filter(function (widget) {
|
|
241
269
|
return widgets.indexOf(widget) === -1;
|
|
242
270
|
});
|
|
271
|
+
localWidgets.forEach(function (widget) {
|
|
272
|
+
if (isIndexWidget(widget)) {
|
|
273
|
+
return;
|
|
274
|
+
}
|
|
275
|
+
if (localInstantSearchInstance && widget.dependsOn === 'recommend') {
|
|
276
|
+
localInstantSearchInstance._hasRecommendWidget = true;
|
|
277
|
+
} else if (localInstantSearchInstance) {
|
|
278
|
+
localInstantSearchInstance._hasSearchWidget = true;
|
|
279
|
+
} else if (widget.dependsOn === 'recommend') {
|
|
280
|
+
hasRecommendWidget = true;
|
|
281
|
+
} else {
|
|
282
|
+
hasSearchWidget = true;
|
|
283
|
+
}
|
|
284
|
+
});
|
|
243
285
|
if (localInstantSearchInstance && Boolean(widgets.length)) {
|
|
244
|
-
var
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
286
|
+
var _widgets$reduce = widgets.reduce(function (states, widget) {
|
|
287
|
+
// the `dispose` method exists at this point we already assert it
|
|
288
|
+
var next = widget.dispose({
|
|
289
|
+
helper: helper,
|
|
290
|
+
state: states.cleanedSearchState,
|
|
291
|
+
recommendState: states.cleanedRecommendState,
|
|
292
|
+
parent: _this2
|
|
293
|
+
});
|
|
294
|
+
if (next instanceof algoliasearchHelper.RecommendParameters) {
|
|
295
|
+
states.cleanedRecommendState = next;
|
|
296
|
+
} else if (next) {
|
|
297
|
+
states.cleanedSearchState = next;
|
|
298
|
+
}
|
|
299
|
+
return states;
|
|
300
|
+
}, {
|
|
301
|
+
cleanedSearchState: helper.state,
|
|
302
|
+
cleanedRecommendState: helper.recommendState
|
|
303
|
+
}),
|
|
304
|
+
cleanedSearchState = _widgets$reduce.cleanedSearchState,
|
|
305
|
+
cleanedRecommendState = _widgets$reduce.cleanedRecommendState;
|
|
253
306
|
var newState = localInstantSearchInstance.future.preserveSharedStateOnUnmount ? getLocalWidgetsSearchParameters(localWidgets, {
|
|
254
307
|
uiState: localUiState,
|
|
255
308
|
initialSearchParameters: new algoliasearchHelper.SearchParameters({
|
|
@@ -257,16 +310,17 @@ var index = function index(widgetParams) {
|
|
|
257
310
|
})
|
|
258
311
|
}) : getLocalWidgetsSearchParameters(localWidgets, {
|
|
259
312
|
uiState: getLocalWidgetsUiState(localWidgets, {
|
|
260
|
-
searchParameters:
|
|
313
|
+
searchParameters: cleanedSearchState,
|
|
261
314
|
helper: helper
|
|
262
315
|
}),
|
|
263
|
-
initialSearchParameters:
|
|
316
|
+
initialSearchParameters: cleanedSearchState
|
|
264
317
|
});
|
|
265
318
|
localUiState = getLocalWidgetsUiState(localWidgets, {
|
|
266
319
|
searchParameters: newState,
|
|
267
320
|
helper: helper
|
|
268
321
|
});
|
|
269
322
|
helper.setState(newState);
|
|
323
|
+
helper.recommendState = cleanedRecommendState;
|
|
270
324
|
if (localWidgets.length) {
|
|
271
325
|
localInstantSearchInstance.scheduleSearch();
|
|
272
326
|
}
|
|
@@ -342,13 +396,20 @@ var index = function index(widgetParams) {
|
|
|
342
396
|
return _this3.getHelper().recommendState;
|
|
343
397
|
});
|
|
344
398
|
var indexInitialResults = (_instantSearchInstanc = instantSearchInstance._initialResults) === null || _instantSearchInstanc === void 0 ? void 0 : _instantSearchInstanc[this.getIndexId()];
|
|
345
|
-
if (indexInitialResults) {
|
|
399
|
+
if (indexInitialResults !== null && indexInitialResults !== void 0 && indexInitialResults.results) {
|
|
346
400
|
// We restore the shape of the results provided to the instance to respect
|
|
347
401
|
// the helper's structure.
|
|
348
402
|
var results = new algoliasearchHelper.SearchResults(new algoliasearchHelper.SearchParameters(indexInitialResults.state), indexInitialResults.results);
|
|
349
403
|
derivedHelper.lastResults = results;
|
|
350
404
|
helper.lastResults = results;
|
|
351
405
|
}
|
|
406
|
+
if (indexInitialResults !== null && indexInitialResults !== void 0 && indexInitialResults.recommendResults) {
|
|
407
|
+
var recommendResults = new algoliasearchHelper.RecommendResults(new algoliasearchHelper.RecommendParameters({
|
|
408
|
+
params: indexInitialResults.recommendResults.params
|
|
409
|
+
}), indexInitialResults.recommendResults.results);
|
|
410
|
+
derivedHelper.lastRecommendResults = recommendResults;
|
|
411
|
+
helper.lastRecommendResults = recommendResults;
|
|
412
|
+
}
|
|
352
413
|
|
|
353
414
|
// Subscribe to the Helper state changes for the page before widgets
|
|
354
415
|
// are initialized. This behavior mimics the original one of the Helper.
|
|
@@ -452,9 +513,16 @@ var index = function index(widgetParams) {
|
|
|
452
513
|
// schedule a render that will render the results injected on the helper.
|
|
453
514
|
instantSearchInstance.scheduleRender();
|
|
454
515
|
}
|
|
516
|
+
if (hasRecommendWidget) {
|
|
517
|
+
instantSearchInstance._hasRecommendWidget = true;
|
|
518
|
+
}
|
|
519
|
+
if (hasSearchWidget) {
|
|
520
|
+
instantSearchInstance._hasSearchWidget = true;
|
|
521
|
+
}
|
|
455
522
|
},
|
|
456
523
|
render: function render(_ref6) {
|
|
457
|
-
var
|
|
524
|
+
var _derivedHelper2,
|
|
525
|
+
_this4 = this;
|
|
458
526
|
var instantSearchInstance = _ref6.instantSearchInstance;
|
|
459
527
|
// we can't attach a listener to the error event of search, as the error
|
|
460
528
|
// then would no longer be thrown for global handlers.
|
|
@@ -464,7 +532,7 @@ var index = function index(widgetParams) {
|
|
|
464
532
|
|
|
465
533
|
// We only render index widgets if there are no results.
|
|
466
534
|
// This makes sure `render` is never called with `results` being `null`.
|
|
467
|
-
var widgetsToRender = this.getResults() ? localWidgets : localWidgets.filter(isIndexWidget);
|
|
535
|
+
var widgetsToRender = this.getResults() || (_derivedHelper2 = derivedHelper) !== null && _derivedHelper2 !== void 0 && _derivedHelper2.lastRecommendResults ? localWidgets : localWidgets.filter(isIndexWidget);
|
|
468
536
|
widgetsToRender = widgetsToRender.filter(function (widget) {
|
|
469
537
|
if (!widget.shouldRender) {
|
|
470
538
|
return true;
|
|
@@ -475,7 +543,7 @@ var index = function index(widgetParams) {
|
|
|
475
543
|
});
|
|
476
544
|
widgetsToRender.forEach(function (widget) {
|
|
477
545
|
if (widget.getRenderState) {
|
|
478
|
-
var renderState = widget.getRenderState(instantSearchInstance.renderState[_this4.getIndexId()] || {}, createRenderArgs(instantSearchInstance, _this4));
|
|
546
|
+
var renderState = widget.getRenderState(instantSearchInstance.renderState[_this4.getIndexId()] || {}, createRenderArgs(instantSearchInstance, _this4, widget));
|
|
479
547
|
storeRenderState({
|
|
480
548
|
renderState: renderState,
|
|
481
549
|
instantSearchInstance: instantSearchInstance,
|
|
@@ -492,14 +560,14 @@ var index = function index(widgetParams) {
|
|
|
492
560
|
// not have results yet.
|
|
493
561
|
|
|
494
562
|
if (widget.render) {
|
|
495
|
-
widget.render(createRenderArgs(instantSearchInstance, _this4));
|
|
563
|
+
widget.render(createRenderArgs(instantSearchInstance, _this4, widget));
|
|
496
564
|
}
|
|
497
565
|
});
|
|
498
566
|
},
|
|
499
567
|
dispose: function dispose() {
|
|
500
568
|
var _this5 = this,
|
|
501
|
-
|
|
502
|
-
|
|
569
|
+
_helper2,
|
|
570
|
+
_derivedHelper3;
|
|
503
571
|
localWidgets.forEach(function (widget) {
|
|
504
572
|
if (widget.dispose && helper) {
|
|
505
573
|
// The dispose function is always called once the instance is started
|
|
@@ -511,15 +579,16 @@ var index = function index(widgetParams) {
|
|
|
511
579
|
widget.dispose({
|
|
512
580
|
helper: helper,
|
|
513
581
|
state: helper.state,
|
|
582
|
+
recommendState: helper.recommendState,
|
|
514
583
|
parent: _this5
|
|
515
584
|
});
|
|
516
585
|
}
|
|
517
586
|
});
|
|
518
587
|
localInstantSearchInstance = null;
|
|
519
588
|
localParent = null;
|
|
520
|
-
(
|
|
589
|
+
(_helper2 = helper) === null || _helper2 === void 0 ? void 0 : _helper2.removeAllListeners();
|
|
521
590
|
helper = null;
|
|
522
|
-
(
|
|
591
|
+
(_derivedHelper3 = derivedHelper) === null || _derivedHelper3 === void 0 ? void 0 : _derivedHelper3.detach();
|
|
523
592
|
derivedHelper = null;
|
|
524
593
|
},
|
|
525
594
|
getWidgetUiState: function getWidgetUiState(uiState) {
|
package/es/widgets/index.d.ts
CHANGED
|
@@ -25,6 +25,7 @@ export { default as places } from './places/places';
|
|
|
25
25
|
export { default as poweredBy } from './powered-by/powered-by';
|
|
26
26
|
export { default as queryRuleContext } from './query-rule-context/query-rule-context';
|
|
27
27
|
export { default as queryRuleCustomData } from './query-rule-custom-data/query-rule-custom-data';
|
|
28
|
+
export { default as relatedProducts } from './related-products/related-products';
|
|
28
29
|
export { default as rangeInput } from './range-input/range-input';
|
|
29
30
|
export { default as rangeSlider } from './range-slider/range-slider';
|
|
30
31
|
export { default as ratingMenu } from './rating-menu/rating-menu';
|
|
@@ -34,4 +35,7 @@ export { default as searchBox } from './search-box/search-box';
|
|
|
34
35
|
export { default as sortBy } from './sort-by/sort-by';
|
|
35
36
|
export { default as stats } from './stats/stats';
|
|
36
37
|
export { default as toggleRefinement } from './toggle-refinement/toggle-refinement';
|
|
38
|
+
export { default as trendingItems } from './trending-items/trending-items';
|
|
37
39
|
export { default as voiceSearch } from './voice-search/voice-search';
|
|
40
|
+
export { default as frequentlyBoughtTogether } from './frequently-bought-together/frequently-bought-together';
|
|
41
|
+
export { default as lookingSimilar } from './looking-similar/looking-similar';
|
package/es/widgets/index.js
CHANGED
|
@@ -29,6 +29,7 @@ export { default as places } from "./places/places.js";
|
|
|
29
29
|
export { default as poweredBy } from "./powered-by/powered-by.js";
|
|
30
30
|
export { default as queryRuleContext } from "./query-rule-context/query-rule-context.js";
|
|
31
31
|
export { default as queryRuleCustomData } from "./query-rule-custom-data/query-rule-custom-data.js";
|
|
32
|
+
export { default as relatedProducts } from "./related-products/related-products.js";
|
|
32
33
|
export { default as rangeInput } from "./range-input/range-input.js";
|
|
33
34
|
export { default as rangeSlider } from "./range-slider/range-slider.js";
|
|
34
35
|
export { default as ratingMenu } from "./rating-menu/rating-menu.js";
|
|
@@ -38,4 +39,7 @@ export { default as searchBox } from "./search-box/search-box.js";
|
|
|
38
39
|
export { default as sortBy } from "./sort-by/sort-by.js";
|
|
39
40
|
export { default as stats } from "./stats/stats.js";
|
|
40
41
|
export { default as toggleRefinement } from "./toggle-refinement/toggle-refinement.js";
|
|
41
|
-
export { default as
|
|
42
|
+
export { default as trendingItems } from "./trending-items/trending-items.js";
|
|
43
|
+
export { default as voiceSearch } from "./voice-search/voice-search.js";
|
|
44
|
+
export { default as frequentlyBoughtTogether } from "./frequently-bought-together/frequently-bought-together.js";
|
|
45
|
+
export { default as lookingSimilar } from "./looking-similar/looking-similar.js";
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
|
|
2
|
+
import type { LookingSimilarWidgetDescription, LookingSimilarConnectorParams } from '../../connectors/looking-similar/connectLookingSimilar';
|
|
3
|
+
import type { Template, WidgetFactory, Hit } from '../../types';
|
|
4
|
+
import type { RecommendResultItem } from 'algoliasearch-helper';
|
|
5
|
+
import type { RecommendClassNames, LookingSimilarProps as LookingSimilarUiProps } from 'instantsearch-ui-components';
|
|
6
|
+
export type LookingSimilarCSSClasses = Partial<RecommendClassNames>;
|
|
7
|
+
export type LookingSimilarTemplates = Partial<{
|
|
8
|
+
/**
|
|
9
|
+
* Template to use when there are no results.
|
|
10
|
+
*/
|
|
11
|
+
empty: Template<RecommendResultItem>;
|
|
12
|
+
/**
|
|
13
|
+
* Template to use for the header of the widget.
|
|
14
|
+
*/
|
|
15
|
+
header: Template<Pick<Parameters<NonNullable<LookingSimilarUiProps<Hit>['headerComponent']>>[0], 'items'> & {
|
|
16
|
+
cssClasses: RecommendClassNames;
|
|
17
|
+
}>;
|
|
18
|
+
/**
|
|
19
|
+
* Template to use for each result. This template will receive an object containing a single record.
|
|
20
|
+
*/
|
|
21
|
+
item: Template<Hit>;
|
|
22
|
+
}>;
|
|
23
|
+
type LookingSimilarWidgetParams = {
|
|
24
|
+
/**
|
|
25
|
+
* CSS Selector or HTMLElement to insert the widget.
|
|
26
|
+
*/
|
|
27
|
+
container: string | HTMLElement;
|
|
28
|
+
/**
|
|
29
|
+
* Templates to use for the widget.
|
|
30
|
+
*/
|
|
31
|
+
templates?: LookingSimilarTemplates;
|
|
32
|
+
/**
|
|
33
|
+
* CSS classes to add.
|
|
34
|
+
*/
|
|
35
|
+
cssClasses?: LookingSimilarCSSClasses;
|
|
36
|
+
};
|
|
37
|
+
export type LookingSimilarWidget = WidgetFactory<LookingSimilarWidgetDescription & {
|
|
38
|
+
$$widgetType: 'ais.lookingSimilar';
|
|
39
|
+
}, LookingSimilarConnectorParams, LookingSimilarWidgetParams>;
|
|
40
|
+
declare const lookingSimilar: LookingSimilarWidget;
|
|
41
|
+
export default lookingSimilar;
|
|
@@ -0,0 +1,114 @@
|
|
|
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
|
+
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
8
|
+
import { createLookingSimilarComponent } from 'instantsearch-ui-components';
|
|
9
|
+
import { Fragment, h, render } from 'preact';
|
|
10
|
+
import TemplateComponent from "../../components/Template/Template.js";
|
|
11
|
+
import connectLookingSimilar from "../../connectors/looking-similar/connectLookingSimilar.js";
|
|
12
|
+
import { prepareTemplateProps } from "../../lib/templating/index.js";
|
|
13
|
+
import { getContainerNode, createDocumentationMessageGenerator } from "../../lib/utils/index.js";
|
|
14
|
+
var withUsage = createDocumentationMessageGenerator({
|
|
15
|
+
name: 'looking-similar'
|
|
16
|
+
});
|
|
17
|
+
var LookingSimilar = createLookingSimilarComponent({
|
|
18
|
+
createElement: h,
|
|
19
|
+
Fragment: Fragment
|
|
20
|
+
});
|
|
21
|
+
var renderer = function renderer(_ref) {
|
|
22
|
+
var renderState = _ref.renderState,
|
|
23
|
+
cssClasses = _ref.cssClasses,
|
|
24
|
+
containerNode = _ref.containerNode,
|
|
25
|
+
templates = _ref.templates;
|
|
26
|
+
return function (_ref2, isFirstRendering) {
|
|
27
|
+
var items = _ref2.items,
|
|
28
|
+
results = _ref2.results,
|
|
29
|
+
instantSearchInstance = _ref2.instantSearchInstance;
|
|
30
|
+
if (isFirstRendering) {
|
|
31
|
+
renderState.templateProps = prepareTemplateProps({
|
|
32
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
33
|
+
defaultTemplates: {},
|
|
34
|
+
templatesConfig: instantSearchInstance.templatesConfig,
|
|
35
|
+
templates: templates
|
|
36
|
+
});
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
var headerComponent = templates.header ? function (data) {
|
|
40
|
+
return h(TemplateComponent, _extends({}, renderState.templateProps, {
|
|
41
|
+
templateKey: "header",
|
|
42
|
+
rootTagName: "fragment",
|
|
43
|
+
data: {
|
|
44
|
+
cssClasses: data.classNames,
|
|
45
|
+
items: data.items
|
|
46
|
+
}
|
|
47
|
+
}));
|
|
48
|
+
} : undefined;
|
|
49
|
+
var itemComponent = templates.item ? function (_ref3) {
|
|
50
|
+
var item = _ref3.item;
|
|
51
|
+
return h(TemplateComponent, _extends({}, renderState.templateProps, {
|
|
52
|
+
templateKey: "item",
|
|
53
|
+
rootTagName: "fragment",
|
|
54
|
+
data: item
|
|
55
|
+
}));
|
|
56
|
+
} : undefined;
|
|
57
|
+
var emptyComponent = templates.empty ? function () {
|
|
58
|
+
return h(TemplateComponent, _extends({}, renderState.templateProps, {
|
|
59
|
+
templateKey: "empty",
|
|
60
|
+
rootTagName: "fragment",
|
|
61
|
+
data: results
|
|
62
|
+
}));
|
|
63
|
+
} : undefined;
|
|
64
|
+
render(h(LookingSimilar, {
|
|
65
|
+
items: items,
|
|
66
|
+
headerComponent: headerComponent,
|
|
67
|
+
itemComponent: itemComponent,
|
|
68
|
+
sendEvent: function sendEvent() {},
|
|
69
|
+
classNames: cssClasses,
|
|
70
|
+
emptyComponent: emptyComponent,
|
|
71
|
+
status: instantSearchInstance.status
|
|
72
|
+
}), containerNode);
|
|
73
|
+
};
|
|
74
|
+
};
|
|
75
|
+
var lookingSimilar = function lookingSimilar(widgetParams) {
|
|
76
|
+
var _ref4 = widgetParams || {},
|
|
77
|
+
container = _ref4.container,
|
|
78
|
+
objectIDs = _ref4.objectIDs,
|
|
79
|
+
limit = _ref4.limit,
|
|
80
|
+
queryParameters = _ref4.queryParameters,
|
|
81
|
+
fallbackParameters = _ref4.fallbackParameters,
|
|
82
|
+
threshold = _ref4.threshold,
|
|
83
|
+
escapeHTML = _ref4.escapeHTML,
|
|
84
|
+
transformItems = _ref4.transformItems,
|
|
85
|
+
_ref4$templates = _ref4.templates,
|
|
86
|
+
templates = _ref4$templates === void 0 ? {} : _ref4$templates,
|
|
87
|
+
_ref4$cssClasses = _ref4.cssClasses,
|
|
88
|
+
cssClasses = _ref4$cssClasses === void 0 ? {} : _ref4$cssClasses;
|
|
89
|
+
if (!container) {
|
|
90
|
+
throw new Error(withUsage('The `container` option is required.'));
|
|
91
|
+
}
|
|
92
|
+
var containerNode = getContainerNode(container);
|
|
93
|
+
var specializedRenderer = renderer({
|
|
94
|
+
containerNode: containerNode,
|
|
95
|
+
cssClasses: cssClasses,
|
|
96
|
+
renderState: {},
|
|
97
|
+
templates: templates
|
|
98
|
+
});
|
|
99
|
+
var makeWidget = connectLookingSimilar(specializedRenderer, function () {
|
|
100
|
+
return render(null, containerNode);
|
|
101
|
+
});
|
|
102
|
+
return _objectSpread(_objectSpread({}, makeWidget({
|
|
103
|
+
objectIDs: objectIDs,
|
|
104
|
+
limit: limit,
|
|
105
|
+
queryParameters: queryParameters,
|
|
106
|
+
fallbackParameters: fallbackParameters,
|
|
107
|
+
threshold: threshold,
|
|
108
|
+
escapeHTML: escapeHTML,
|
|
109
|
+
transformItems: transformItems
|
|
110
|
+
})), {}, {
|
|
111
|
+
$$widgetType: 'ais.lookingSimilar'
|
|
112
|
+
});
|
|
113
|
+
};
|
|
114
|
+
export default lookingSimilar;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
|
|
2
|
+
import type { RelatedProductsWidgetDescription, RelatedProductsConnectorParams } from '../../connectors/related-products/connectRelatedProducts';
|
|
3
|
+
import type { Template, WidgetFactory, Hit } from '../../types';
|
|
4
|
+
import type { RecommendResultItem } from 'algoliasearch-helper';
|
|
5
|
+
import type { RecommendClassNames, RelatedProductsProps as RelatedProductsUiProps } from 'instantsearch-ui-components';
|
|
6
|
+
export type RelatedProductsCSSClasses = Partial<RecommendClassNames>;
|
|
7
|
+
export type RelatedProductsTemplates = Partial<{
|
|
8
|
+
/**
|
|
9
|
+
* Template to use when there are no results.
|
|
10
|
+
*/
|
|
11
|
+
empty: Template<RecommendResultItem>;
|
|
12
|
+
/**
|
|
13
|
+
* Template to use for the header of the widget.
|
|
14
|
+
*/
|
|
15
|
+
header: Template<Pick<Parameters<NonNullable<RelatedProductsUiProps<Hit>['headerComponent']>>[0], 'items'> & {
|
|
16
|
+
cssClasses: RecommendClassNames;
|
|
17
|
+
}>;
|
|
18
|
+
/**
|
|
19
|
+
* Template to use for each result. This template will receive an object containing a single record.
|
|
20
|
+
*/
|
|
21
|
+
item: Template<Hit>;
|
|
22
|
+
}>;
|
|
23
|
+
type RelatedProductsWidgetParams = {
|
|
24
|
+
/**
|
|
25
|
+
* CSS selector or `HTMLElement` to insert the widget into.
|
|
26
|
+
*/
|
|
27
|
+
container: string | HTMLElement;
|
|
28
|
+
/**
|
|
29
|
+
* Templates to customize the widget.
|
|
30
|
+
*/
|
|
31
|
+
templates?: RelatedProductsTemplates;
|
|
32
|
+
/**
|
|
33
|
+
* CSS classes to add to the widget elements.
|
|
34
|
+
*/
|
|
35
|
+
cssClasses?: RelatedProductsCSSClasses;
|
|
36
|
+
};
|
|
37
|
+
export type RelatedProductsWidget = WidgetFactory<RelatedProductsWidgetDescription & {
|
|
38
|
+
$$widgetType: 'ais.relatedProducts';
|
|
39
|
+
}, RelatedProductsConnectorParams, RelatedProductsWidgetParams>;
|
|
40
|
+
declare const relatedProducts: RelatedProductsWidget;
|
|
41
|
+
export default relatedProducts;
|
|
@@ -0,0 +1,114 @@
|
|
|
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
|
+
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
8
|
+
import { createRelatedProductsComponent } from 'instantsearch-ui-components';
|
|
9
|
+
import { Fragment, h, render } from 'preact';
|
|
10
|
+
import TemplateComponent from "../../components/Template/Template.js";
|
|
11
|
+
import connectRelatedProducts from "../../connectors/related-products/connectRelatedProducts.js";
|
|
12
|
+
import { prepareTemplateProps } from "../../lib/templating/index.js";
|
|
13
|
+
import { getContainerNode, createDocumentationMessageGenerator } from "../../lib/utils/index.js";
|
|
14
|
+
var withUsage = createDocumentationMessageGenerator({
|
|
15
|
+
name: 'related-products'
|
|
16
|
+
});
|
|
17
|
+
var RelatedProducts = createRelatedProductsComponent({
|
|
18
|
+
createElement: h,
|
|
19
|
+
Fragment: Fragment
|
|
20
|
+
});
|
|
21
|
+
function createRenderer(_ref) {
|
|
22
|
+
var renderState = _ref.renderState,
|
|
23
|
+
cssClasses = _ref.cssClasses,
|
|
24
|
+
containerNode = _ref.containerNode,
|
|
25
|
+
templates = _ref.templates;
|
|
26
|
+
return function renderer(_ref2, isFirstRendering) {
|
|
27
|
+
var items = _ref2.items,
|
|
28
|
+
results = _ref2.results,
|
|
29
|
+
instantSearchInstance = _ref2.instantSearchInstance;
|
|
30
|
+
if (isFirstRendering) {
|
|
31
|
+
renderState.templateProps = prepareTemplateProps({
|
|
32
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
33
|
+
defaultTemplates: {},
|
|
34
|
+
templatesConfig: instantSearchInstance.templatesConfig,
|
|
35
|
+
templates: templates
|
|
36
|
+
});
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
var headerComponent = templates.header ? function (data) {
|
|
40
|
+
return h(TemplateComponent, _extends({}, renderState.templateProps, {
|
|
41
|
+
templateKey: "header",
|
|
42
|
+
rootTagName: "fragment",
|
|
43
|
+
data: {
|
|
44
|
+
cssClasses: data.classNames,
|
|
45
|
+
items: data.items
|
|
46
|
+
}
|
|
47
|
+
}));
|
|
48
|
+
} : undefined;
|
|
49
|
+
var itemComponent = templates.item ? function (_ref3) {
|
|
50
|
+
var item = _ref3.item;
|
|
51
|
+
return h(TemplateComponent, _extends({}, renderState.templateProps, {
|
|
52
|
+
templateKey: "item",
|
|
53
|
+
rootTagName: "fragment",
|
|
54
|
+
data: item
|
|
55
|
+
}));
|
|
56
|
+
} : undefined;
|
|
57
|
+
var emptyComponent = templates.empty ? function () {
|
|
58
|
+
return h(TemplateComponent, _extends({}, renderState.templateProps, {
|
|
59
|
+
templateKey: "empty",
|
|
60
|
+
rootTagName: "fragment",
|
|
61
|
+
data: results
|
|
62
|
+
}));
|
|
63
|
+
} : undefined;
|
|
64
|
+
render(h(RelatedProducts, {
|
|
65
|
+
items: items,
|
|
66
|
+
sendEvent: function sendEvent() {},
|
|
67
|
+
classNames: cssClasses,
|
|
68
|
+
headerComponent: headerComponent,
|
|
69
|
+
itemComponent: itemComponent,
|
|
70
|
+
emptyComponent: emptyComponent,
|
|
71
|
+
status: instantSearchInstance.status
|
|
72
|
+
}), containerNode);
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
var relatedProducts = function relatedProducts(widgetParams) {
|
|
76
|
+
var _ref4 = widgetParams || {},
|
|
77
|
+
container = _ref4.container,
|
|
78
|
+
objectIDs = _ref4.objectIDs,
|
|
79
|
+
limit = _ref4.limit,
|
|
80
|
+
queryParameters = _ref4.queryParameters,
|
|
81
|
+
fallbackParameters = _ref4.fallbackParameters,
|
|
82
|
+
threshold = _ref4.threshold,
|
|
83
|
+
escapeHTML = _ref4.escapeHTML,
|
|
84
|
+
transformItems = _ref4.transformItems,
|
|
85
|
+
_ref4$templates = _ref4.templates,
|
|
86
|
+
templates = _ref4$templates === void 0 ? {} : _ref4$templates,
|
|
87
|
+
_ref4$cssClasses = _ref4.cssClasses,
|
|
88
|
+
cssClasses = _ref4$cssClasses === void 0 ? {} : _ref4$cssClasses;
|
|
89
|
+
if (!container) {
|
|
90
|
+
throw new Error(withUsage('The `container` option is required.'));
|
|
91
|
+
}
|
|
92
|
+
var containerNode = getContainerNode(container);
|
|
93
|
+
var specializedRenderer = createRenderer({
|
|
94
|
+
containerNode: containerNode,
|
|
95
|
+
cssClasses: cssClasses,
|
|
96
|
+
renderState: {},
|
|
97
|
+
templates: templates
|
|
98
|
+
});
|
|
99
|
+
var makeWidget = connectRelatedProducts(specializedRenderer, function () {
|
|
100
|
+
return render(null, containerNode);
|
|
101
|
+
});
|
|
102
|
+
return _objectSpread(_objectSpread({}, makeWidget({
|
|
103
|
+
objectIDs: objectIDs,
|
|
104
|
+
limit: limit,
|
|
105
|
+
queryParameters: queryParameters,
|
|
106
|
+
fallbackParameters: fallbackParameters,
|
|
107
|
+
threshold: threshold,
|
|
108
|
+
escapeHTML: escapeHTML,
|
|
109
|
+
transformItems: transformItems
|
|
110
|
+
})), {}, {
|
|
111
|
+
$$widgetType: 'ais.relatedProducts'
|
|
112
|
+
});
|
|
113
|
+
};
|
|
114
|
+
export default relatedProducts;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
|
|
2
|
+
import type { TrendingItemsWidgetDescription, TrendingItemsConnectorParams } from '../../connectors/trending-items/connectTrendingItems';
|
|
3
|
+
import type { Template, WidgetFactory, Hit } from '../../types';
|
|
4
|
+
import type { RecommendResultItem } from 'algoliasearch-helper';
|
|
5
|
+
import type { RecommendClassNames, TrendingItemsProps as TrendingItemsUiProps } from 'instantsearch-ui-components';
|
|
6
|
+
export type TrendingItemsCSSClasses = Partial<RecommendClassNames>;
|
|
7
|
+
export type TrendingItemsTemplates = Partial<{
|
|
8
|
+
/**
|
|
9
|
+
* Template to use when there are no results.
|
|
10
|
+
*/
|
|
11
|
+
empty: Template<RecommendResultItem>;
|
|
12
|
+
/**
|
|
13
|
+
* Template to use for the header of the widget.
|
|
14
|
+
*/
|
|
15
|
+
header: Template<Pick<Parameters<NonNullable<TrendingItemsUiProps<Hit>['headerComponent']>>[0], 'items'> & {
|
|
16
|
+
cssClasses: RecommendClassNames;
|
|
17
|
+
}>;
|
|
18
|
+
/**
|
|
19
|
+
* Template to use for each result. This template will receive an object containing a single record.
|
|
20
|
+
*/
|
|
21
|
+
item: Template<Hit>;
|
|
22
|
+
}>;
|
|
23
|
+
type TrendingItemsWidgetParams = {
|
|
24
|
+
/**
|
|
25
|
+
* CSS selector or `HTMLElement` to insert the widget into.
|
|
26
|
+
*/
|
|
27
|
+
container: string | HTMLElement;
|
|
28
|
+
/**
|
|
29
|
+
* Templates to customize the widget.
|
|
30
|
+
*/
|
|
31
|
+
templates?: TrendingItemsTemplates;
|
|
32
|
+
/**
|
|
33
|
+
* CSS classes to add to the widget elements.
|
|
34
|
+
*/
|
|
35
|
+
cssClasses?: TrendingItemsCSSClasses;
|
|
36
|
+
};
|
|
37
|
+
export type TrendingItemsWidget = WidgetFactory<TrendingItemsWidgetDescription & {
|
|
38
|
+
$$widgetType: 'ais.trendingItems';
|
|
39
|
+
}, TrendingItemsConnectorParams, TrendingItemsWidgetParams>;
|
|
40
|
+
declare const trendingItems: TrendingItemsWidget;
|
|
41
|
+
export default trendingItems;
|