instantsearch.js 4.66.1 → 4.67.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/lib/InstantSearch.js +1 -1
- package/cjs/lib/version.js +1 -1
- package/cjs/widgets/index/index.js +68 -13
- package/dist/instantsearch.development.d.ts +25 -2
- package/dist/instantsearch.development.js +485 -30
- package/dist/instantsearch.development.js.map +1 -1
- package/dist/instantsearch.production.d.ts +25 -2
- package/dist/instantsearch.production.min.d.ts +25 -2
- package/dist/instantsearch.production.min.js +2 -2
- package/dist/instantsearch.production.min.js.map +1 -1
- package/es/lib/InstantSearch.js +1 -1
- package/es/lib/version.d.ts +1 -1
- package/es/lib/version.js +1 -1
- package/es/types/widget.d.ts +21 -2
- package/es/widgets/index/index.js +68 -13
- package/es/widgets/panel/panel.d.ts +1 -1
- package/package.json +7 -7
package/cjs/lib/InstantSearch.js
CHANGED
|
@@ -392,7 +392,7 @@ var InstantSearch = /*#__PURE__*/function (_EventEmitter) {
|
|
|
392
392
|
// under the hood, we have a different implementation. It should be
|
|
393
393
|
// completely transparent for the rest of the codebase. Only this module
|
|
394
394
|
// is impacted.
|
|
395
|
-
return mainHelper.searchOnlyWithDerivedHelpers();
|
|
395
|
+
return mainHelper.searchOnlyWithDerivedHelpers() && mainHelper.recommend();
|
|
396
396
|
};
|
|
397
397
|
if (this._searchFunction) {
|
|
398
398
|
// this client isn't used to actually search, but required for the helper
|
package/cjs/lib/version.js
CHANGED
|
@@ -7,7 +7,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
exports.default = void 0;
|
|
8
8
|
var _algoliasearchHelper = _interopRequireDefault(require("algoliasearch-helper"));
|
|
9
9
|
var _utils = require("../../lib/utils");
|
|
10
|
-
var _excluded = ["initialSearchParameters"]
|
|
10
|
+
var _excluded = ["initialSearchParameters"],
|
|
11
|
+
_excluded2 = ["initialRecommendParameters"];
|
|
11
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
12
13
|
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; }
|
|
13
14
|
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; }
|
|
@@ -32,6 +33,7 @@ var withUsage = (0, _utils.createDocumentationMessageGenerator)({
|
|
|
32
33
|
*/
|
|
33
34
|
function privateHelperSetState(helper, _ref) {
|
|
34
35
|
var state = _ref.state,
|
|
36
|
+
recommendState = _ref.recommendState,
|
|
35
37
|
isPageReset = _ref.isPageReset,
|
|
36
38
|
_uiState = _ref._uiState;
|
|
37
39
|
if (state !== helper.state) {
|
|
@@ -43,7 +45,14 @@ function privateHelperSetState(helper, _ref) {
|
|
|
43
45
|
_uiState: _uiState
|
|
44
46
|
});
|
|
45
47
|
}
|
|
48
|
+
if (recommendState !== helper.recommendState) {
|
|
49
|
+
helper.recommendState = recommendState;
|
|
50
|
+
|
|
51
|
+
// eslint-disable-next-line no-warning-comments
|
|
52
|
+
// TODO: emit "change" event when events for Recommend are implemented
|
|
53
|
+
}
|
|
46
54
|
}
|
|
55
|
+
|
|
47
56
|
function getLocalWidgetsUiState(widgets, widgetStateOptions) {
|
|
48
57
|
var initialUiState = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
49
58
|
return widgets.reduce(function (uiState, widget) {
|
|
@@ -62,15 +71,26 @@ function getLocalWidgetsUiState(widgets, widgetStateOptions) {
|
|
|
62
71
|
function getLocalWidgetsSearchParameters(widgets, widgetSearchParametersOptions) {
|
|
63
72
|
var initialSearchParameters = widgetSearchParametersOptions.initialSearchParameters,
|
|
64
73
|
rest = _objectWithoutProperties(widgetSearchParametersOptions, _excluded);
|
|
65
|
-
return widgets.
|
|
66
|
-
|
|
67
|
-
}).reduce(function (state, widget) {
|
|
68
|
-
if (!widget.getWidgetSearchParameters) {
|
|
74
|
+
return widgets.reduce(function (state, widget) {
|
|
75
|
+
if (!widget.getWidgetSearchParameters || (0, _utils.isIndexWidget)(widget)) {
|
|
69
76
|
return state;
|
|
70
77
|
}
|
|
78
|
+
if (widget.dependsOn === 'search' && widget.getWidgetParameters) {
|
|
79
|
+
return widget.getWidgetParameters(state, rest);
|
|
80
|
+
}
|
|
71
81
|
return widget.getWidgetSearchParameters(state, rest);
|
|
72
82
|
}, initialSearchParameters);
|
|
73
83
|
}
|
|
84
|
+
function getLocalWidgetsRecommendParameters(widgets, widgetRecommendParametersOptions) {
|
|
85
|
+
var initialRecommendParameters = widgetRecommendParametersOptions.initialRecommendParameters,
|
|
86
|
+
rest = _objectWithoutProperties(widgetRecommendParametersOptions, _excluded2);
|
|
87
|
+
return widgets.reduce(function (state, widget) {
|
|
88
|
+
if (!(0, _utils.isIndexWidget)(widget) && widget.dependsOn === 'recommend' && widget.getWidgetParameters) {
|
|
89
|
+
return widget.getWidgetParameters(state, rest);
|
|
90
|
+
}
|
|
91
|
+
return state;
|
|
92
|
+
}, initialRecommendParameters);
|
|
93
|
+
}
|
|
74
94
|
function resetPageFromWidgets(widgets) {
|
|
75
95
|
var indexWidgets = widgets.filter(_utils.isIndexWidget);
|
|
76
96
|
if (indexWidgets.length === 0) {
|
|
@@ -80,6 +100,7 @@ function resetPageFromWidgets(widgets) {
|
|
|
80
100
|
var widgetHelper = widget.getHelper();
|
|
81
101
|
privateHelperSetState(widgetHelper, {
|
|
82
102
|
state: widgetHelper.state.resetPage(),
|
|
103
|
+
recommendState: widgetHelper.recommendState,
|
|
83
104
|
isPageReset: true
|
|
84
105
|
});
|
|
85
106
|
resetPageFromWidgets(widget.getWidgets());
|
|
@@ -175,6 +196,10 @@ var index = function index(widgetParams) {
|
|
|
175
196
|
uiState: localUiState,
|
|
176
197
|
initialSearchParameters: helper.state
|
|
177
198
|
}),
|
|
199
|
+
recommendState: getLocalWidgetsRecommendParameters(localWidgets, {
|
|
200
|
+
uiState: localUiState,
|
|
201
|
+
initialRecommendParameters: helper.recommendState
|
|
202
|
+
}),
|
|
178
203
|
_uiState: localUiState
|
|
179
204
|
});
|
|
180
205
|
|
|
@@ -271,11 +296,16 @@ var index = function index(widgetParams) {
|
|
|
271
296
|
index: indexName
|
|
272
297
|
})
|
|
273
298
|
});
|
|
299
|
+
var recommendParameters = getLocalWidgetsRecommendParameters(localWidgets, {
|
|
300
|
+
uiState: localUiState,
|
|
301
|
+
initialRecommendParameters: new _algoliasearchHelper.default.RecommendParameters()
|
|
302
|
+
});
|
|
274
303
|
|
|
275
304
|
// This Helper is only used for state management we do not care about the
|
|
276
305
|
// `searchClient`. Only the "main" Helper created at the `InstantSearch`
|
|
277
306
|
// level is aware of the client.
|
|
278
307
|
helper = (0, _algoliasearchHelper.default)({}, parameters.index, parameters);
|
|
308
|
+
helper.recommendState = recommendParameters;
|
|
279
309
|
|
|
280
310
|
// We forward the call to `search` to the "main" instance of the Helper
|
|
281
311
|
// which is responsible for managing the queries (it's the only one that is
|
|
@@ -306,6 +336,8 @@ var index = function index(widgetParams) {
|
|
|
306
336
|
};
|
|
307
337
|
derivedHelper = mainHelper.derive(function () {
|
|
308
338
|
return _utils.mergeSearchParameters.apply(void 0, [mainHelper.state].concat(_toConsumableArray((0, _utils.resolveSearchParameters)(_this3))));
|
|
339
|
+
}, function () {
|
|
340
|
+
return _this3.getHelper().recommendState;
|
|
309
341
|
});
|
|
310
342
|
var indexInitialResults = (_instantSearchInstanc = instantSearchInstance._initialResults) === null || _instantSearchInstanc === void 0 ? void 0 : _instantSearchInstanc[this.getIndexId()];
|
|
311
343
|
if (indexInitialResults) {
|
|
@@ -354,6 +386,21 @@ var index = function index(widgetParams) {
|
|
|
354
386
|
lastValidSearchParameters = results === null || results === void 0 ? void 0 : results._state;
|
|
355
387
|
});
|
|
356
388
|
|
|
389
|
+
// eslint-disable-next-line no-warning-comments
|
|
390
|
+
// TODO: listen to "result" event when events for Recommend are implemented
|
|
391
|
+
derivedHelper.on('recommend:result', function (_ref5) {
|
|
392
|
+
var recommend = _ref5.recommend;
|
|
393
|
+
// The index does not render the results it schedules a new render
|
|
394
|
+
// to let all the other indices emit their own results. It allows us to
|
|
395
|
+
// run the render process in one pass.
|
|
396
|
+
instantSearchInstance.scheduleRender();
|
|
397
|
+
|
|
398
|
+
// the derived helper is the one which actually searches, but the helper
|
|
399
|
+
// which is exposed e.g. via instance.helper, doesn't search, and thus
|
|
400
|
+
// does not have access to lastRecommendResults.
|
|
401
|
+
helper.lastRecommendResults = recommend.results;
|
|
402
|
+
});
|
|
403
|
+
|
|
357
404
|
// We compute the render state before calling `init` in a separate loop
|
|
358
405
|
// to construct the whole render state object that is then passed to
|
|
359
406
|
// `init`.
|
|
@@ -404,9 +451,9 @@ var index = function index(widgetParams) {
|
|
|
404
451
|
instantSearchInstance.scheduleRender();
|
|
405
452
|
}
|
|
406
453
|
},
|
|
407
|
-
render: function render(
|
|
454
|
+
render: function render(_ref6) {
|
|
408
455
|
var _this4 = this;
|
|
409
|
-
var instantSearchInstance =
|
|
456
|
+
var instantSearchInstance = _ref6.instantSearchInstance;
|
|
410
457
|
// we can't attach a listener to the error event of search, as the error
|
|
411
458
|
// then would no longer be thrown for global handlers.
|
|
412
459
|
if (instantSearchInstance.status === 'error' && !instantSearchInstance.mainHelper.hasPendingRequests() && lastValidSearchParameters) {
|
|
@@ -416,6 +463,14 @@ var index = function index(widgetParams) {
|
|
|
416
463
|
// We only render index widgets if there are no results.
|
|
417
464
|
// This makes sure `render` is never called with `results` being `null`.
|
|
418
465
|
var widgetsToRender = this.getResults() ? localWidgets : localWidgets.filter(_utils.isIndexWidget);
|
|
466
|
+
widgetsToRender = widgetsToRender.filter(function (widget) {
|
|
467
|
+
if (!widget.shouldRender) {
|
|
468
|
+
return true;
|
|
469
|
+
}
|
|
470
|
+
return widget.shouldRender({
|
|
471
|
+
instantSearchInstance: instantSearchInstance
|
|
472
|
+
});
|
|
473
|
+
});
|
|
419
474
|
widgetsToRender.forEach(function (widget) {
|
|
420
475
|
if (widget.getRenderState) {
|
|
421
476
|
var renderState = widget.getRenderState(instantSearchInstance.renderState[_this4.getIndexId()] || {}, (0, _utils.createRenderArgs)(instantSearchInstance, _this4));
|
|
@@ -474,8 +529,8 @@ var index = function index(widgetParams) {
|
|
|
474
529
|
process.env.NODE_ENV === 'development' ? (0, _utils.warning)(false, 'The `getWidgetState` method is renamed `getWidgetUiState` and will no longer exist under that name in InstantSearch.js 5.x. Please use `getWidgetUiState` instead.') : void 0;
|
|
475
530
|
return this.getWidgetUiState(uiState);
|
|
476
531
|
},
|
|
477
|
-
getWidgetSearchParameters: function getWidgetSearchParameters(searchParameters,
|
|
478
|
-
var uiState =
|
|
532
|
+
getWidgetSearchParameters: function getWidgetSearchParameters(searchParameters, _ref7) {
|
|
533
|
+
var uiState = _ref7.uiState;
|
|
479
534
|
return getLocalWidgetsSearchParameters(localWidgets, {
|
|
480
535
|
uiState: uiState,
|
|
481
536
|
initialSearchParameters: searchParameters
|
|
@@ -497,10 +552,10 @@ var index = function index(widgetParams) {
|
|
|
497
552
|
};
|
|
498
553
|
var _default = index;
|
|
499
554
|
exports.default = _default;
|
|
500
|
-
function storeRenderState(
|
|
501
|
-
var renderState =
|
|
502
|
-
instantSearchInstance =
|
|
503
|
-
parent =
|
|
555
|
+
function storeRenderState(_ref8) {
|
|
556
|
+
var renderState = _ref8.renderState,
|
|
557
|
+
instantSearchInstance = _ref8.instantSearchInstance,
|
|
558
|
+
parent = _ref8.parent;
|
|
504
559
|
var parentIndexName = parent ? parent.getIndexId() : instantSearchInstance.mainIndex.getIndexId();
|
|
505
560
|
instantSearchInstance.renderState = _objectSpread(_objectSpread({}, instantSearchInstance.renderState), {}, _defineProperty({}, parentIndexName, _objectSpread(_objectSpread({}, instantSearchInstance.renderState[parentIndexName]), renderState)));
|
|
506
561
|
}
|
|
@@ -15,6 +15,7 @@ import type { InsightsMethodMap as InsightsMethodMap_2 } from 'search-insights';
|
|
|
15
15
|
import type * as Places from 'places.js';
|
|
16
16
|
import type { PlainSearchParameters } from 'algoliasearch-helper';
|
|
17
17
|
import { default as qs_2 } from 'qs';
|
|
18
|
+
import type { RecommendParameters } from 'algoliasearch-helper';
|
|
18
19
|
import { SearchClient } from 'algoliasearch-helper/types/algoliasearch.js';
|
|
19
20
|
import { SearchOptions } from 'algoliasearch-helper/types/algoliasearch.js';
|
|
20
21
|
import type { SearchParameters } from 'algoliasearch-helper';
|
|
@@ -242,7 +243,7 @@ declare type AtLeastOne<TTarget, TMapped = {
|
|
|
242
243
|
[Key in keyof TTarget]: Pick<TTarget, Key>;
|
|
243
244
|
}> = Partial<TTarget> & TMapped[keyof TMapped];
|
|
244
245
|
|
|
245
|
-
declare type AugmentedWidget<TWidgetFactory extends AnyWidgetFactory, TOverriddenKeys extends keyof Widget = 'init' | 'render' | 'dispose'> = Omit<ReturnType<TWidgetFactory>, TOverriddenKeys> & Pick<Required<Widget>, TOverriddenKeys>;
|
|
246
|
+
declare type AugmentedWidget<TWidgetFactory extends AnyWidgetFactory, TOverriddenKeys extends keyof Widget = 'init' | 'render' | 'dispose'> = Omit<ReturnType<TWidgetFactory>, TOverriddenKeys | 'dependsOn' | 'getWidgetParameters'> & Pick<Required<Widget>, TOverriddenKeys>;
|
|
246
247
|
|
|
247
248
|
declare type AutocompleteConnector = Connector<AutocompleteWidgetDescription, AutocompleteConnectorParams>;
|
|
248
249
|
|
|
@@ -4007,6 +4008,13 @@ declare type Read<THit extends BaseHit> = ({ state, }: {
|
|
|
4007
4008
|
state: PlainSearchParameters;
|
|
4008
4009
|
}) => InfiniteHitsCachedHits<THit> | null;
|
|
4009
4010
|
|
|
4011
|
+
declare type RecommendWidgetLifeCycle<TWidgetDescription extends WidgetDescription> = {
|
|
4012
|
+
dependsOn?: 'recommend';
|
|
4013
|
+
getWidgetParameters: (state: RecommendParameters, widgetParametersOptions: {
|
|
4014
|
+
uiState: Expand<Partial<TWidgetDescription['indexUiState'] & IndexUiState>>;
|
|
4015
|
+
}) => RecommendParameters;
|
|
4016
|
+
};
|
|
4017
|
+
|
|
4010
4018
|
declare type ReconfigurableOptions = Places.ReconfigurableOptions;
|
|
4011
4019
|
|
|
4012
4020
|
/**
|
|
@@ -4517,7 +4525,7 @@ declare type RequiredUiStateLifeCycle<TWidgetDescription extends WidgetDescripti
|
|
|
4517
4525
|
getWidgetSearchParameters: (state: SearchParameters, widgetSearchParametersOptions: {
|
|
4518
4526
|
uiState: Expand<Partial<TWidgetDescription['indexUiState'] & IndexUiState>>;
|
|
4519
4527
|
}) => SearchParameters;
|
|
4520
|
-
};
|
|
4528
|
+
} & (SearchWidgetLifeCycle<TWidgetDescription> | RecommendWidgetLifeCycle<TWidgetDescription>);
|
|
4521
4529
|
|
|
4522
4530
|
declare type RequiredWidgetLifeCycle<TWidgetDescription extends WidgetDescription> = {
|
|
4523
4531
|
/**
|
|
@@ -4528,6 +4536,10 @@ declare type RequiredWidgetLifeCycle<TWidgetDescription extends WidgetDescriptio
|
|
|
4528
4536
|
* Called once before the first search.
|
|
4529
4537
|
*/
|
|
4530
4538
|
init?: (options: InitOptions) => void;
|
|
4539
|
+
/**
|
|
4540
|
+
* Whether `render` should be called
|
|
4541
|
+
*/
|
|
4542
|
+
shouldRender?: (options: ShouldRenderOptions) => boolean;
|
|
4531
4543
|
/**
|
|
4532
4544
|
* Called after each search response has been received.
|
|
4533
4545
|
*/
|
|
@@ -4843,6 +4855,13 @@ declare type SearchBoxWidgetParams = {
|
|
|
4843
4855
|
queryHook?: (query: string, hook: (value: string) => void) => void;
|
|
4844
4856
|
};
|
|
4845
4857
|
|
|
4858
|
+
declare type SearchWidgetLifeCycle<TWidgetDescription extends WidgetDescription> = {
|
|
4859
|
+
dependsOn?: 'search';
|
|
4860
|
+
getWidgetParameters?: (state: SearchParameters, widgetParametersOptions: {
|
|
4861
|
+
uiState: Expand<Partial<TWidgetDescription['indexUiState'] & IndexUiState>>;
|
|
4862
|
+
}) => SearchParameters;
|
|
4863
|
+
};
|
|
4864
|
+
|
|
4846
4865
|
declare type SendEvent = (...args: [InsightsEvent] | [string, string, string?]) => void;
|
|
4847
4866
|
|
|
4848
4867
|
declare type SendEventForFacet = BuiltInSendEventForFacet & CustomSendEventForFacet;
|
|
@@ -4869,6 +4888,10 @@ declare type SharedRenderOptions = {
|
|
|
4869
4888
|
createURL: (nextState: SearchParameters | ((state: IndexUiState) => IndexUiState)) => string;
|
|
4870
4889
|
};
|
|
4871
4890
|
|
|
4891
|
+
declare type ShouldRenderOptions = {
|
|
4892
|
+
instantSearchInstance: InstantSearch;
|
|
4893
|
+
};
|
|
4894
|
+
|
|
4872
4895
|
declare function simpleStateMapping<TUiState extends UiState = UiState>(): StateMapping<TUiState, TUiState>;
|
|
4873
4896
|
|
|
4874
4897
|
declare function singleIndexStateMapping<TUiState extends UiState = UiState>(indexName: keyof TUiState): StateMapping<TUiState, TUiState[typeof indexName]>;
|