instantsearch.js 4.79.1 → 4.80.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/components/Template/Template.js +1 -1
- package/cjs/connectors/infinite-hits/connectInfiniteHits.js +19 -13
- package/cjs/lib/InstantSearch.js +2 -10
- package/cjs/lib/version.js +1 -1
- package/cjs/widgets/index/index.js +73 -24
- package/dist/instantsearch.development.d.ts +48 -4
- package/dist/instantsearch.development.js +97 -50
- package/dist/instantsearch.development.js.map +1 -1
- package/dist/instantsearch.production.d.ts +48 -4
- package/dist/instantsearch.production.min.d.ts +48 -4
- package/dist/instantsearch.production.min.js +2 -2
- package/dist/instantsearch.production.min.js.map +1 -1
- package/es/components/Template/Template.js +1 -1
- package/es/connectors/infinite-hits/connectInfiniteHits.js +19 -13
- package/es/lib/InstantSearch.d.ts +2 -2
- package/es/lib/InstantSearch.js +2 -10
- package/es/lib/version.d.ts +1 -1
- package/es/lib/version.js +1 -1
- package/es/widgets/index/index.d.ts +46 -2
- package/es/widgets/index/index.js +73 -24
- package/package.json +5 -5
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! InstantSearch.js 4.
|
|
1
|
+
/*! InstantSearch.js 4.80.0 | © Algolia, Inc. and contributors; MIT License | https://github.com/algolia/instantsearch */
|
|
2
2
|
(function (global, factory) {
|
|
3
3
|
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
|
|
4
4
|
typeof define === 'function' && define.amd ? define(factory) :
|
|
@@ -10235,22 +10235,20 @@
|
|
|
10235
10235
|
return Math.max.apply(Math, [page].concat(_toConsumableArray(pages)));
|
|
10236
10236
|
}
|
|
10237
10237
|
};
|
|
10238
|
-
var getShowPrevious = function getShowPrevious(helper) {
|
|
10238
|
+
var getShowPrevious = function getShowPrevious(helper, getCachedHits) {
|
|
10239
10239
|
return function () {
|
|
10240
|
+
var cachedHits = getCachedHits();
|
|
10240
10241
|
// Using the helper's `overrideStateWithoutTriggeringChangeEvent` method
|
|
10241
10242
|
// avoid updating the browser URL when the user displays the previous page.
|
|
10242
10243
|
helper.overrideStateWithoutTriggeringChangeEvent(_objectSpread2(_objectSpread2({}, helper.state), {}, {
|
|
10243
|
-
page: getFirstReceivedPage(helper.state,
|
|
10244
|
-
state: normalizeState(helper.state)
|
|
10245
|
-
}) || {}) - 1
|
|
10244
|
+
page: getFirstReceivedPage(helper.state, cachedHits) - 1
|
|
10246
10245
|
})).searchWithoutTriggeringOnStateChange();
|
|
10247
10246
|
};
|
|
10248
10247
|
};
|
|
10249
|
-
var getShowMore = function getShowMore(helper) {
|
|
10248
|
+
var getShowMore = function getShowMore(helper, getCachedHits) {
|
|
10250
10249
|
return function () {
|
|
10251
|
-
|
|
10252
|
-
|
|
10253
|
-
}) || {}) + 1).search();
|
|
10250
|
+
var cachedHits = getCachedHits();
|
|
10251
|
+
helper.setPage(getLastReceivedPage(helper.state, cachedHits) + 1).search();
|
|
10254
10252
|
};
|
|
10255
10253
|
};
|
|
10256
10254
|
return {
|
|
@@ -10282,6 +10280,12 @@
|
|
|
10282
10280
|
parent = _ref6.parent,
|
|
10283
10281
|
existingState = _ref6.state,
|
|
10284
10282
|
instantSearchInstance = _ref6.instantSearchInstance;
|
|
10283
|
+
var getCacheHits = function getCacheHits() {
|
|
10284
|
+
var state = parent.getPreviousState() || existingState;
|
|
10285
|
+
return cache.read({
|
|
10286
|
+
state: normalizeState(state)
|
|
10287
|
+
}) || {};
|
|
10288
|
+
};
|
|
10285
10289
|
var isFirstPage;
|
|
10286
10290
|
var currentPageHits = [];
|
|
10287
10291
|
/**
|
|
@@ -10290,13 +10294,15 @@
|
|
|
10290
10294
|
* is loading.
|
|
10291
10295
|
*/
|
|
10292
10296
|
var state = parent.getPreviousState() || existingState;
|
|
10293
|
-
var cachedHits =
|
|
10294
|
-
state: normalizeState(state)
|
|
10295
|
-
}) || {};
|
|
10297
|
+
var cachedHits = getCacheHits();
|
|
10296
10298
|
var banner = results === null || results === void 0 ? void 0 : (_results$renderingCon = results.renderingContent) === null || _results$renderingCon === void 0 ? void 0 : (_results$renderingCon2 = _results$renderingCon.widgets) === null || _results$renderingCon2 === void 0 ? void 0 : (_results$renderingCon3 = _results$renderingCon2.banners) === null || _results$renderingCon3 === void 0 ? void 0 : _results$renderingCon3[0];
|
|
10297
10299
|
if (!showPrevious) {
|
|
10298
|
-
showPrevious =
|
|
10299
|
-
|
|
10300
|
+
showPrevious = function showPrevious() {
|
|
10301
|
+
return getShowPrevious(helper, getCacheHits)();
|
|
10302
|
+
};
|
|
10303
|
+
showMore = function showMore() {
|
|
10304
|
+
return getShowMore(helper, getCacheHits)();
|
|
10305
|
+
};
|
|
10300
10306
|
}
|
|
10301
10307
|
if (!sendEvent) {
|
|
10302
10308
|
sendEvent = createSendEventForHits({
|
|
@@ -15851,12 +15857,18 @@
|
|
|
15851
15857
|
}, []);
|
|
15852
15858
|
}
|
|
15853
15859
|
var index = function index(widgetParams) {
|
|
15854
|
-
if (widgetParams === undefined || widgetParams.indexName === undefined) {
|
|
15860
|
+
if (widgetParams === undefined || widgetParams.indexName === undefined && !widgetParams.EXPERIMENTAL_isolated) {
|
|
15855
15861
|
throw new Error(withUsage$u('The `indexName` option is required.'));
|
|
15856
15862
|
}
|
|
15857
|
-
|
|
15863
|
+
|
|
15864
|
+
// When isolated=true, we use an empty string as the default indexName.
|
|
15865
|
+
// This is intentional: isolated indices do not require a real index name.
|
|
15866
|
+
var _widgetParams$indexNa = widgetParams.indexName,
|
|
15867
|
+
indexName = _widgetParams$indexNa === void 0 ? '' : _widgetParams$indexNa,
|
|
15858
15868
|
_widgetParams$indexId = widgetParams.indexId,
|
|
15859
|
-
indexId = _widgetParams$indexId === void 0 ? indexName : _widgetParams$indexId
|
|
15869
|
+
indexId = _widgetParams$indexId === void 0 ? indexName : _widgetParams$indexId,
|
|
15870
|
+
_widgetParams$EXPERIM = widgetParams.EXPERIMENTAL_isolated,
|
|
15871
|
+
isolated = _widgetParams$EXPERIM === void 0 ? false : _widgetParams$EXPERIM;
|
|
15860
15872
|
var localWidgets = [];
|
|
15861
15873
|
var localUiState = {};
|
|
15862
15874
|
var localInstantSearchInstance = null;
|
|
@@ -15869,6 +15881,7 @@
|
|
|
15869
15881
|
return {
|
|
15870
15882
|
$$type: 'ais.index',
|
|
15871
15883
|
$$widgetType: 'ais.index',
|
|
15884
|
+
_isolated: isolated,
|
|
15872
15885
|
getIndexName: function getIndexName() {
|
|
15873
15886
|
return indexName;
|
|
15874
15887
|
},
|
|
@@ -15920,7 +15933,7 @@
|
|
|
15920
15933
|
return resolveScopedResultsFromWidgets(widgetSiblings);
|
|
15921
15934
|
},
|
|
15922
15935
|
getParent: function getParent() {
|
|
15923
|
-
return localParent;
|
|
15936
|
+
return isolated ? null : localParent;
|
|
15924
15937
|
},
|
|
15925
15938
|
createURL: function createURL(nextState) {
|
|
15926
15939
|
if (typeof nextState === 'function') {
|
|
@@ -15939,12 +15952,15 @@
|
|
|
15939
15952
|
if (!Array.isArray(widgets)) {
|
|
15940
15953
|
throw new Error(withUsage$u('The `addWidgets` method expects an array of widgets.'));
|
|
15941
15954
|
}
|
|
15942
|
-
|
|
15955
|
+
var flatWidgets = widgets.reduce(function (acc, w) {
|
|
15956
|
+
return acc.concat(Array.isArray(w) ? w : [w]);
|
|
15957
|
+
}, []);
|
|
15958
|
+
if (flatWidgets.some(function (widget) {
|
|
15943
15959
|
return typeof widget.init !== 'function' && typeof widget.render !== 'function';
|
|
15944
15960
|
})) {
|
|
15945
15961
|
throw new Error(withUsage$u('The widget definition expects a `render` and/or an `init` method.'));
|
|
15946
15962
|
}
|
|
15947
|
-
|
|
15963
|
+
flatWidgets.forEach(function (widget) {
|
|
15948
15964
|
if (isIndexWidget(widget)) {
|
|
15949
15965
|
return;
|
|
15950
15966
|
}
|
|
@@ -15959,8 +15975,8 @@
|
|
|
15959
15975
|
}
|
|
15960
15976
|
addWidgetId(widget);
|
|
15961
15977
|
});
|
|
15962
|
-
localWidgets = localWidgets.concat(
|
|
15963
|
-
if (localInstantSearchInstance && Boolean(
|
|
15978
|
+
localWidgets = localWidgets.concat(flatWidgets);
|
|
15979
|
+
if (localInstantSearchInstance && Boolean(flatWidgets.length)) {
|
|
15964
15980
|
privateHelperSetState(helper, {
|
|
15965
15981
|
state: getLocalWidgetsSearchParameters(localWidgets, {
|
|
15966
15982
|
uiState: localUiState,
|
|
@@ -15976,7 +15992,7 @@
|
|
|
15976
15992
|
// We compute the render state before calling `init` in a separate loop
|
|
15977
15993
|
// to construct the whole render state object that is then passed to
|
|
15978
15994
|
// `init`.
|
|
15979
|
-
|
|
15995
|
+
flatWidgets.forEach(function (widget) {
|
|
15980
15996
|
if (widget.getRenderState) {
|
|
15981
15997
|
var renderState = widget.getRenderState(localInstantSearchInstance.renderState[_this.getIndexId()] || {}, createInitArgs(localInstantSearchInstance, _this, localInstantSearchInstance._initialUiState));
|
|
15982
15998
|
storeRenderState({
|
|
@@ -15986,12 +16002,17 @@
|
|
|
15986
16002
|
});
|
|
15987
16003
|
}
|
|
15988
16004
|
});
|
|
15989
|
-
|
|
16005
|
+
flatWidgets.forEach(function (widget) {
|
|
15990
16006
|
if (widget.init) {
|
|
15991
16007
|
widget.init(createInitArgs(localInstantSearchInstance, _this, localInstantSearchInstance._initialUiState));
|
|
15992
16008
|
}
|
|
15993
16009
|
});
|
|
15994
|
-
|
|
16010
|
+
if (isolated) {
|
|
16011
|
+
var _helper2;
|
|
16012
|
+
(_helper2 = helper) === null || _helper2 === void 0 ? void 0 : _helper2.search();
|
|
16013
|
+
} else {
|
|
16014
|
+
localInstantSearchInstance.scheduleSearch();
|
|
16015
|
+
}
|
|
15995
16016
|
}
|
|
15996
16017
|
return this;
|
|
15997
16018
|
},
|
|
@@ -16000,13 +16021,16 @@
|
|
|
16000
16021
|
if (!Array.isArray(widgets)) {
|
|
16001
16022
|
throw new Error(withUsage$u('The `removeWidgets` method expects an array of widgets.'));
|
|
16002
16023
|
}
|
|
16003
|
-
|
|
16024
|
+
var flatWidgets = widgets.reduce(function (acc, w) {
|
|
16025
|
+
return acc.concat(Array.isArray(w) ? w : [w]);
|
|
16026
|
+
}, []);
|
|
16027
|
+
if (flatWidgets.some(function (widget) {
|
|
16004
16028
|
return typeof widget.dispose !== 'function';
|
|
16005
16029
|
})) {
|
|
16006
16030
|
throw new Error(withUsage$u('The widget definition expects a `dispose` method.'));
|
|
16007
16031
|
}
|
|
16008
16032
|
localWidgets = localWidgets.filter(function (widget) {
|
|
16009
|
-
return
|
|
16033
|
+
return flatWidgets.indexOf(widget) === -1;
|
|
16010
16034
|
});
|
|
16011
16035
|
localWidgets.forEach(function (widget) {
|
|
16012
16036
|
if (isIndexWidget(widget)) {
|
|
@@ -16022,8 +16046,8 @@
|
|
|
16022
16046
|
hasSearchWidget = true;
|
|
16023
16047
|
}
|
|
16024
16048
|
});
|
|
16025
|
-
if (localInstantSearchInstance && Boolean(
|
|
16026
|
-
var
|
|
16049
|
+
if (localInstantSearchInstance && Boolean(flatWidgets.length)) {
|
|
16050
|
+
var _flatWidgets$reduce = flatWidgets.reduce(function (states, widget) {
|
|
16027
16051
|
// the `dispose` method exists at this point we already assert it
|
|
16028
16052
|
var next = widget.dispose({
|
|
16029
16053
|
helper: helper,
|
|
@@ -16041,8 +16065,8 @@
|
|
|
16041
16065
|
cleanedSearchState: helper.state,
|
|
16042
16066
|
cleanedRecommendState: helper.recommendState
|
|
16043
16067
|
}),
|
|
16044
|
-
cleanedSearchState =
|
|
16045
|
-
cleanedRecommendState =
|
|
16068
|
+
cleanedSearchState = _flatWidgets$reduce.cleanedSearchState,
|
|
16069
|
+
cleanedRecommendState = _flatWidgets$reduce.cleanedRecommendState;
|
|
16046
16070
|
var newState = localInstantSearchInstance.future.preserveSharedStateOnUnmount ? getLocalWidgetsSearchParameters(localWidgets, {
|
|
16047
16071
|
uiState: localUiState,
|
|
16048
16072
|
initialSearchParameters: new algoliasearchHelper_1.SearchParameters({
|
|
@@ -16062,7 +16086,12 @@
|
|
|
16062
16086
|
helper.setState(newState);
|
|
16063
16087
|
helper.recommendState = cleanedRecommendState;
|
|
16064
16088
|
if (localWidgets.length) {
|
|
16065
|
-
|
|
16089
|
+
if (isolated) {
|
|
16090
|
+
var _helper3;
|
|
16091
|
+
(_helper3 = helper) === null || _helper3 === void 0 ? void 0 : _helper3.search();
|
|
16092
|
+
} else {
|
|
16093
|
+
localInstantSearchInstance.scheduleSearch();
|
|
16094
|
+
}
|
|
16066
16095
|
}
|
|
16067
16096
|
}
|
|
16068
16097
|
return this;
|
|
@@ -16100,13 +16129,20 @@
|
|
|
16100
16129
|
// This Helper is only used for state management we do not care about the
|
|
16101
16130
|
// `searchClient`. Only the "main" Helper created at the `InstantSearch`
|
|
16102
16131
|
// level is aware of the client.
|
|
16103
|
-
helper = algoliasearchHelper_1(
|
|
16132
|
+
helper = algoliasearchHelper_1(mainHelper.getClient(), parameters.index, parameters);
|
|
16104
16133
|
helper.recommendState = recommendParameters;
|
|
16105
16134
|
|
|
16106
16135
|
// We forward the call to `search` to the "main" instance of the Helper
|
|
16107
16136
|
// which is responsible for managing the queries (it's the only one that is
|
|
16108
16137
|
// aware of the `searchClient`).
|
|
16109
16138
|
helper.search = function () {
|
|
16139
|
+
if (isolated) {
|
|
16140
|
+
instantSearchInstance.status = 'loading';
|
|
16141
|
+
_this3.render({
|
|
16142
|
+
instantSearchInstance: instantSearchInstance
|
|
16143
|
+
});
|
|
16144
|
+
return instantSearchInstance.compositionID ? helper.searchWithComposition() : helper.searchOnlyWithDerivedHelpers();
|
|
16145
|
+
}
|
|
16110
16146
|
if (instantSearchInstance.onStateChange) {
|
|
16111
16147
|
instantSearchInstance.onStateChange({
|
|
16112
16148
|
uiState: instantSearchInstance.mainIndex.getWidgetUiState({}),
|
|
@@ -16130,7 +16166,9 @@
|
|
|
16130
16166
|
var state = helper.state.setQueryParameters(userState);
|
|
16131
16167
|
return mainHelper.searchForFacetValues(facetName, facetValue, maxFacetHits, state);
|
|
16132
16168
|
};
|
|
16133
|
-
|
|
16169
|
+
var isolatedHelper = indexName ? helper : algoliasearchHelper_1({}, '__empty_index__', {});
|
|
16170
|
+
var derivingHelper = isolated ? isolatedHelper : nearestIsolatedHelper(parent, mainHelper);
|
|
16171
|
+
derivedHelper = derivingHelper.derive(function () {
|
|
16134
16172
|
return mergeSearchParameters.apply(void 0, [mainHelper.state].concat(_toConsumableArray(resolveSearchParameters(_this3))));
|
|
16135
16173
|
}, function () {
|
|
16136
16174
|
return _this3.getHelper().recommendState;
|
|
@@ -16272,7 +16310,9 @@
|
|
|
16272
16310
|
|
|
16273
16311
|
// We only render index widgets if there are no results.
|
|
16274
16312
|
// This makes sure `render` is never called with `results` being `null`.
|
|
16275
|
-
|
|
16313
|
+
// If it's an isolated index without an index name, we render all widgets,
|
|
16314
|
+
// as there are no results to display for the isolated index itself.
|
|
16315
|
+
var widgetsToRender = this.getResults() || (_derivedHelper2 = derivedHelper) !== null && _derivedHelper2 !== void 0 && _derivedHelper2.lastRecommendResults || isolated && !indexName ? localWidgets : localWidgets.filter(isIndexWidget);
|
|
16276
16316
|
widgetsToRender = widgetsToRender.filter(function (widget) {
|
|
16277
16317
|
if (!widget.shouldRender) {
|
|
16278
16318
|
return true;
|
|
@@ -16306,7 +16346,7 @@
|
|
|
16306
16346
|
},
|
|
16307
16347
|
dispose: function dispose() {
|
|
16308
16348
|
var _this5 = this,
|
|
16309
|
-
|
|
16349
|
+
_helper4,
|
|
16310
16350
|
_derivedHelper3;
|
|
16311
16351
|
localWidgets.forEach(function (widget) {
|
|
16312
16352
|
if (widget.dispose && helper) {
|
|
@@ -16326,13 +16366,15 @@
|
|
|
16326
16366
|
});
|
|
16327
16367
|
localInstantSearchInstance = null;
|
|
16328
16368
|
localParent = null;
|
|
16329
|
-
(
|
|
16369
|
+
(_helper4 = helper) === null || _helper4 === void 0 ? void 0 : _helper4.removeAllListeners();
|
|
16330
16370
|
helper = null;
|
|
16331
16371
|
(_derivedHelper3 = derivedHelper) === null || _derivedHelper3 === void 0 ? void 0 : _derivedHelper3.detach();
|
|
16332
16372
|
derivedHelper = null;
|
|
16333
16373
|
},
|
|
16334
16374
|
getWidgetUiState: function getWidgetUiState(uiState) {
|
|
16335
|
-
return localWidgets.filter(isIndexWidget).
|
|
16375
|
+
return localWidgets.filter(isIndexWidget).filter(function (w) {
|
|
16376
|
+
return !w._isolated;
|
|
16377
|
+
}).reduce(function (previousUiState, innerIndex) {
|
|
16336
16378
|
return innerIndex.getWidgetUiState(previousUiState);
|
|
16337
16379
|
}, _objectSpread2(_objectSpread2({}, uiState), {}, _defineProperty({}, indexId, _objectSpread2(_objectSpread2({}, uiState[indexId]), localUiState))));
|
|
16338
16380
|
},
|
|
@@ -16369,6 +16411,19 @@
|
|
|
16369
16411
|
instantSearchInstance.renderState = _objectSpread2(_objectSpread2({}, instantSearchInstance.renderState), {}, _defineProperty({}, parentIndexName, _objectSpread2(_objectSpread2({}, instantSearchInstance.renderState[parentIndexName]), renderState)));
|
|
16370
16412
|
}
|
|
16371
16413
|
|
|
16414
|
+
/**
|
|
16415
|
+
* Walk up the parent chain to find the closest isolated index, or fall back to mainHelper
|
|
16416
|
+
*/
|
|
16417
|
+
function nearestIsolatedHelper(current, mainHelper) {
|
|
16418
|
+
while (current) {
|
|
16419
|
+
if (current._isolated) {
|
|
16420
|
+
return current.getHelper();
|
|
16421
|
+
}
|
|
16422
|
+
current = current.getParent();
|
|
16423
|
+
}
|
|
16424
|
+
return mainHelper;
|
|
16425
|
+
}
|
|
16426
|
+
|
|
16372
16427
|
function formatNumber(value, numberLocale) {
|
|
16373
16428
|
return value.toLocaleString(numberLocale);
|
|
16374
16429
|
}
|
|
@@ -16434,7 +16489,7 @@
|
|
|
16434
16489
|
};
|
|
16435
16490
|
}
|
|
16436
16491
|
|
|
16437
|
-
var version$1 = '4.
|
|
16492
|
+
var version$1 = '4.80.0';
|
|
16438
16493
|
|
|
16439
16494
|
var withUsage$v = createDocumentationMessageGenerator({
|
|
16440
16495
|
name: 'instantsearch'
|
|
@@ -16735,12 +16790,9 @@
|
|
|
16735
16790
|
if (!Array.isArray(widgets)) {
|
|
16736
16791
|
throw new Error(withUsage$v('The `addWidgets` method expects an array of widgets. Please use `addWidget`.'));
|
|
16737
16792
|
}
|
|
16738
|
-
if (widgets.some(function (
|
|
16739
|
-
return
|
|
16793
|
+
if (this.compositionID && widgets.some(function (w) {
|
|
16794
|
+
return !Array.isArray(w) && isIndexWidget(w) && !w._isolated;
|
|
16740
16795
|
})) {
|
|
16741
|
-
throw new Error(withUsage$v('The widget definition expects a `render` and/or an `init` method.'));
|
|
16742
|
-
}
|
|
16743
|
-
if (this.compositionID && widgets.some(isIndexWidget)) {
|
|
16744
16796
|
throw new Error(withUsage$v('The `index` widget cannot be used with a composition-based InstantSearch implementation.'));
|
|
16745
16797
|
}
|
|
16746
16798
|
this.mainIndex.addWidgets(widgets);
|
|
@@ -16773,11 +16825,6 @@
|
|
|
16773
16825
|
if (!Array.isArray(widgets)) {
|
|
16774
16826
|
throw new Error(withUsage$v('The `removeWidgets` method expects an array of widgets. Please use `removeWidget`.'));
|
|
16775
16827
|
}
|
|
16776
|
-
if (widgets.some(function (widget) {
|
|
16777
|
-
return typeof widget.dispose !== 'function';
|
|
16778
|
-
})) {
|
|
16779
|
-
throw new Error(withUsage$v('The widget definition expects a `dispose` method.'));
|
|
16780
|
-
}
|
|
16781
16828
|
this.mainIndex.removeWidgets(widgets);
|
|
16782
16829
|
return this;
|
|
16783
16830
|
}
|
|
@@ -19062,7 +19109,7 @@
|
|
|
19062
19109
|
});
|
|
19063
19110
|
// if there is one TextNode first and one TextNode last, the
|
|
19064
19111
|
// last one's nodeValue will be assigned to the first.
|
|
19065
|
-
if (this.nodes[0].nodeValue) {
|
|
19112
|
+
if (this.nodes[0] && this.nodes[0].nodeValue) {
|
|
19066
19113
|
this.nodes[0].nodeValue = '';
|
|
19067
19114
|
}
|
|
19068
19115
|
}
|