algolia-experiences 1.5.13 → 1.5.15
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.
|
@@ -12439,12 +12439,18 @@
|
|
|
12439
12439
|
}, []);
|
|
12440
12440
|
}
|
|
12441
12441
|
var index = function index(widgetParams) {
|
|
12442
|
-
if (widgetParams === undefined || widgetParams.indexName === undefined) {
|
|
12442
|
+
if (widgetParams === undefined || widgetParams.indexName === undefined && !widgetParams.EXPERIMENTAL_isolated) {
|
|
12443
12443
|
throw new Error(withUsage('The `indexName` option is required.'));
|
|
12444
12444
|
}
|
|
12445
|
-
|
|
12445
|
+
|
|
12446
|
+
// When isolated=true, we use an empty string as the default indexName.
|
|
12447
|
+
// This is intentional: isolated indices do not require a real index name.
|
|
12448
|
+
var _widgetParams$indexNa = widgetParams.indexName,
|
|
12449
|
+
indexName = _widgetParams$indexNa === void 0 ? '' : _widgetParams$indexNa,
|
|
12446
12450
|
_widgetParams$indexId = widgetParams.indexId,
|
|
12447
|
-
indexId = _widgetParams$indexId === void 0 ? indexName : _widgetParams$indexId
|
|
12451
|
+
indexId = _widgetParams$indexId === void 0 ? indexName : _widgetParams$indexId,
|
|
12452
|
+
_widgetParams$EXPERIM = widgetParams.EXPERIMENTAL_isolated,
|
|
12453
|
+
isolated = _widgetParams$EXPERIM === void 0 ? false : _widgetParams$EXPERIM;
|
|
12448
12454
|
var localWidgets = [];
|
|
12449
12455
|
var localUiState = {};
|
|
12450
12456
|
var localInstantSearchInstance = null;
|
|
@@ -12457,6 +12463,7 @@
|
|
|
12457
12463
|
return {
|
|
12458
12464
|
$$type: 'ais.index',
|
|
12459
12465
|
$$widgetType: 'ais.index',
|
|
12466
|
+
_isolated: isolated,
|
|
12460
12467
|
getIndexName: function getIndexName() {
|
|
12461
12468
|
return indexName;
|
|
12462
12469
|
},
|
|
@@ -12508,7 +12515,7 @@
|
|
|
12508
12515
|
return resolveScopedResultsFromWidgets(widgetSiblings);
|
|
12509
12516
|
},
|
|
12510
12517
|
getParent: function getParent() {
|
|
12511
|
-
return localParent;
|
|
12518
|
+
return isolated ? null : localParent;
|
|
12512
12519
|
},
|
|
12513
12520
|
createURL: function createURL(nextState) {
|
|
12514
12521
|
if (typeof nextState === 'function') {
|
|
@@ -12527,12 +12534,15 @@
|
|
|
12527
12534
|
if (!Array.isArray(widgets)) {
|
|
12528
12535
|
throw new Error(withUsage('The `addWidgets` method expects an array of widgets.'));
|
|
12529
12536
|
}
|
|
12530
|
-
|
|
12537
|
+
var flatWidgets = widgets.reduce(function (acc, w) {
|
|
12538
|
+
return acc.concat(Array.isArray(w) ? w : [w]);
|
|
12539
|
+
}, []);
|
|
12540
|
+
if (flatWidgets.some(function (widget) {
|
|
12531
12541
|
return typeof widget.init !== 'function' && typeof widget.render !== 'function';
|
|
12532
12542
|
})) {
|
|
12533
12543
|
throw new Error(withUsage('The widget definition expects a `render` and/or an `init` method.'));
|
|
12534
12544
|
}
|
|
12535
|
-
|
|
12545
|
+
flatWidgets.forEach(function (widget) {
|
|
12536
12546
|
if (isIndexWidget(widget)) {
|
|
12537
12547
|
return;
|
|
12538
12548
|
}
|
|
@@ -12547,8 +12557,8 @@
|
|
|
12547
12557
|
}
|
|
12548
12558
|
addWidgetId(widget);
|
|
12549
12559
|
});
|
|
12550
|
-
localWidgets = localWidgets.concat(
|
|
12551
|
-
if (localInstantSearchInstance && Boolean(
|
|
12560
|
+
localWidgets = localWidgets.concat(flatWidgets);
|
|
12561
|
+
if (localInstantSearchInstance && Boolean(flatWidgets.length)) {
|
|
12552
12562
|
privateHelperSetState(helper, {
|
|
12553
12563
|
state: getLocalWidgetsSearchParameters(localWidgets, {
|
|
12554
12564
|
uiState: localUiState,
|
|
@@ -12564,7 +12574,7 @@
|
|
|
12564
12574
|
// We compute the render state before calling `init` in a separate loop
|
|
12565
12575
|
// to construct the whole render state object that is then passed to
|
|
12566
12576
|
// `init`.
|
|
12567
|
-
|
|
12577
|
+
flatWidgets.forEach(function (widget) {
|
|
12568
12578
|
if (widget.getRenderState) {
|
|
12569
12579
|
var renderState = widget.getRenderState(localInstantSearchInstance.renderState[_this.getIndexId()] || {}, createInitArgs(localInstantSearchInstance, _this, localInstantSearchInstance._initialUiState));
|
|
12570
12580
|
storeRenderState({
|
|
@@ -12574,12 +12584,17 @@
|
|
|
12574
12584
|
});
|
|
12575
12585
|
}
|
|
12576
12586
|
});
|
|
12577
|
-
|
|
12587
|
+
flatWidgets.forEach(function (widget) {
|
|
12578
12588
|
if (widget.init) {
|
|
12579
12589
|
widget.init(createInitArgs(localInstantSearchInstance, _this, localInstantSearchInstance._initialUiState));
|
|
12580
12590
|
}
|
|
12581
12591
|
});
|
|
12582
|
-
|
|
12592
|
+
if (isolated) {
|
|
12593
|
+
var _helper2;
|
|
12594
|
+
(_helper2 = helper) === null || _helper2 === void 0 ? void 0 : _helper2.search();
|
|
12595
|
+
} else {
|
|
12596
|
+
localInstantSearchInstance.scheduleSearch();
|
|
12597
|
+
}
|
|
12583
12598
|
}
|
|
12584
12599
|
return this;
|
|
12585
12600
|
},
|
|
@@ -12588,13 +12603,16 @@
|
|
|
12588
12603
|
if (!Array.isArray(widgets)) {
|
|
12589
12604
|
throw new Error(withUsage('The `removeWidgets` method expects an array of widgets.'));
|
|
12590
12605
|
}
|
|
12591
|
-
|
|
12606
|
+
var flatWidgets = widgets.reduce(function (acc, w) {
|
|
12607
|
+
return acc.concat(Array.isArray(w) ? w : [w]);
|
|
12608
|
+
}, []);
|
|
12609
|
+
if (flatWidgets.some(function (widget) {
|
|
12592
12610
|
return typeof widget.dispose !== 'function';
|
|
12593
12611
|
})) {
|
|
12594
12612
|
throw new Error(withUsage('The widget definition expects a `dispose` method.'));
|
|
12595
12613
|
}
|
|
12596
12614
|
localWidgets = localWidgets.filter(function (widget) {
|
|
12597
|
-
return
|
|
12615
|
+
return flatWidgets.indexOf(widget) === -1;
|
|
12598
12616
|
});
|
|
12599
12617
|
localWidgets.forEach(function (widget) {
|
|
12600
12618
|
if (isIndexWidget(widget)) {
|
|
@@ -12610,8 +12628,8 @@
|
|
|
12610
12628
|
hasSearchWidget = true;
|
|
12611
12629
|
}
|
|
12612
12630
|
});
|
|
12613
|
-
if (localInstantSearchInstance && Boolean(
|
|
12614
|
-
var
|
|
12631
|
+
if (localInstantSearchInstance && Boolean(flatWidgets.length)) {
|
|
12632
|
+
var _flatWidgets$reduce = flatWidgets.reduce(function (states, widget) {
|
|
12615
12633
|
// the `dispose` method exists at this point we already assert it
|
|
12616
12634
|
var next = widget.dispose({
|
|
12617
12635
|
helper: helper,
|
|
@@ -12629,8 +12647,8 @@
|
|
|
12629
12647
|
cleanedSearchState: helper.state,
|
|
12630
12648
|
cleanedRecommendState: helper.recommendState
|
|
12631
12649
|
}),
|
|
12632
|
-
cleanedSearchState =
|
|
12633
|
-
cleanedRecommendState =
|
|
12650
|
+
cleanedSearchState = _flatWidgets$reduce.cleanedSearchState,
|
|
12651
|
+
cleanedRecommendState = _flatWidgets$reduce.cleanedRecommendState;
|
|
12634
12652
|
var newState = localInstantSearchInstance.future.preserveSharedStateOnUnmount ? getLocalWidgetsSearchParameters(localWidgets, {
|
|
12635
12653
|
uiState: localUiState,
|
|
12636
12654
|
initialSearchParameters: new algoliasearchHelper_1.SearchParameters({
|
|
@@ -12650,7 +12668,12 @@
|
|
|
12650
12668
|
helper.setState(newState);
|
|
12651
12669
|
helper.recommendState = cleanedRecommendState;
|
|
12652
12670
|
if (localWidgets.length) {
|
|
12653
|
-
|
|
12671
|
+
if (isolated) {
|
|
12672
|
+
var _helper3;
|
|
12673
|
+
(_helper3 = helper) === null || _helper3 === void 0 ? void 0 : _helper3.search();
|
|
12674
|
+
} else {
|
|
12675
|
+
localInstantSearchInstance.scheduleSearch();
|
|
12676
|
+
}
|
|
12654
12677
|
}
|
|
12655
12678
|
}
|
|
12656
12679
|
return this;
|
|
@@ -12688,13 +12711,20 @@
|
|
|
12688
12711
|
// This Helper is only used for state management we do not care about the
|
|
12689
12712
|
// `searchClient`. Only the "main" Helper created at the `InstantSearch`
|
|
12690
12713
|
// level is aware of the client.
|
|
12691
|
-
helper = algoliasearchHelper_1(
|
|
12714
|
+
helper = algoliasearchHelper_1(mainHelper.getClient(), parameters.index, parameters);
|
|
12692
12715
|
helper.recommendState = recommendParameters;
|
|
12693
12716
|
|
|
12694
12717
|
// We forward the call to `search` to the "main" instance of the Helper
|
|
12695
12718
|
// which is responsible for managing the queries (it's the only one that is
|
|
12696
12719
|
// aware of the `searchClient`).
|
|
12697
12720
|
helper.search = function () {
|
|
12721
|
+
if (isolated) {
|
|
12722
|
+
instantSearchInstance.status = 'loading';
|
|
12723
|
+
_this3.render({
|
|
12724
|
+
instantSearchInstance: instantSearchInstance
|
|
12725
|
+
});
|
|
12726
|
+
return instantSearchInstance.compositionID ? helper.searchWithComposition() : helper.searchOnlyWithDerivedHelpers();
|
|
12727
|
+
}
|
|
12698
12728
|
if (instantSearchInstance.onStateChange) {
|
|
12699
12729
|
instantSearchInstance.onStateChange({
|
|
12700
12730
|
uiState: instantSearchInstance.mainIndex.getWidgetUiState({}),
|
|
@@ -12718,7 +12748,9 @@
|
|
|
12718
12748
|
var state = helper.state.setQueryParameters(userState);
|
|
12719
12749
|
return mainHelper.searchForFacetValues(facetName, facetValue, maxFacetHits, state);
|
|
12720
12750
|
};
|
|
12721
|
-
|
|
12751
|
+
var isolatedHelper = indexName ? helper : algoliasearchHelper_1({}, '__empty_index__', {});
|
|
12752
|
+
var derivingHelper = isolated ? isolatedHelper : nearestIsolatedHelper(parent, mainHelper);
|
|
12753
|
+
derivedHelper = derivingHelper.derive(function () {
|
|
12722
12754
|
return mergeSearchParameters.apply(void 0, [mainHelper.state].concat(_toConsumableArray$2(resolveSearchParameters(_this3))));
|
|
12723
12755
|
}, function () {
|
|
12724
12756
|
return _this3.getHelper().recommendState;
|
|
@@ -12850,7 +12882,9 @@
|
|
|
12850
12882
|
|
|
12851
12883
|
// We only render index widgets if there are no results.
|
|
12852
12884
|
// This makes sure `render` is never called with `results` being `null`.
|
|
12853
|
-
|
|
12885
|
+
// If it's an isolated index without an index name, we render all widgets,
|
|
12886
|
+
// as there are no results to display for the isolated index itself.
|
|
12887
|
+
var widgetsToRender = this.getResults() || (_derivedHelper2 = derivedHelper) !== null && _derivedHelper2 !== void 0 && _derivedHelper2.lastRecommendResults || isolated && !indexName ? localWidgets : localWidgets.filter(isIndexWidget);
|
|
12854
12888
|
widgetsToRender = widgetsToRender.filter(function (widget) {
|
|
12855
12889
|
if (!widget.shouldRender) {
|
|
12856
12890
|
return true;
|
|
@@ -12884,7 +12918,7 @@
|
|
|
12884
12918
|
},
|
|
12885
12919
|
dispose: function dispose() {
|
|
12886
12920
|
var _this5 = this,
|
|
12887
|
-
|
|
12921
|
+
_helper4,
|
|
12888
12922
|
_derivedHelper3;
|
|
12889
12923
|
localWidgets.forEach(function (widget) {
|
|
12890
12924
|
if (widget.dispose && helper) {
|
|
@@ -12904,13 +12938,15 @@
|
|
|
12904
12938
|
});
|
|
12905
12939
|
localInstantSearchInstance = null;
|
|
12906
12940
|
localParent = null;
|
|
12907
|
-
(
|
|
12941
|
+
(_helper4 = helper) === null || _helper4 === void 0 ? void 0 : _helper4.removeAllListeners();
|
|
12908
12942
|
helper = null;
|
|
12909
12943
|
(_derivedHelper3 = derivedHelper) === null || _derivedHelper3 === void 0 ? void 0 : _derivedHelper3.detach();
|
|
12910
12944
|
derivedHelper = null;
|
|
12911
12945
|
},
|
|
12912
12946
|
getWidgetUiState: function getWidgetUiState(uiState) {
|
|
12913
|
-
return localWidgets.filter(isIndexWidget).
|
|
12947
|
+
return localWidgets.filter(isIndexWidget).filter(function (w) {
|
|
12948
|
+
return !w._isolated;
|
|
12949
|
+
}).reduce(function (previousUiState, innerIndex) {
|
|
12914
12950
|
return innerIndex.getWidgetUiState(previousUiState);
|
|
12915
12951
|
}, _objectSpread$c(_objectSpread$c({}, uiState), {}, _defineProperty$f({}, indexId, _objectSpread$c(_objectSpread$c({}, uiState[indexId]), localUiState))));
|
|
12916
12952
|
},
|
|
@@ -12946,6 +12982,19 @@
|
|
|
12946
12982
|
instantSearchInstance.renderState = _objectSpread$c(_objectSpread$c({}, instantSearchInstance.renderState), {}, _defineProperty$f({}, parentIndexName, _objectSpread$c(_objectSpread$c({}, instantSearchInstance.renderState[parentIndexName]), renderState)));
|
|
12947
12983
|
}
|
|
12948
12984
|
|
|
12985
|
+
/**
|
|
12986
|
+
* Walk up the parent chain to find the closest isolated index, or fall back to mainHelper
|
|
12987
|
+
*/
|
|
12988
|
+
function nearestIsolatedHelper(current, mainHelper) {
|
|
12989
|
+
while (current) {
|
|
12990
|
+
if (current._isolated) {
|
|
12991
|
+
return current.getHelper();
|
|
12992
|
+
}
|
|
12993
|
+
current = current.getParent();
|
|
12994
|
+
}
|
|
12995
|
+
return mainHelper;
|
|
12996
|
+
}
|
|
12997
|
+
|
|
12949
12998
|
function formatNumber(value, numberLocale) {
|
|
12950
12999
|
return value.toLocaleString(numberLocale);
|
|
12951
13000
|
}
|
|
@@ -13069,7 +13118,7 @@
|
|
|
13069
13118
|
};
|
|
13070
13119
|
}
|
|
13071
13120
|
|
|
13072
|
-
var version$1 = '4.
|
|
13121
|
+
var version$1 = '4.80.0';
|
|
13073
13122
|
|
|
13074
13123
|
function _typeof$j(o) {
|
|
13075
13124
|
"@babel/helpers - typeof";
|
|
@@ -13503,12 +13552,9 @@
|
|
|
13503
13552
|
if (!Array.isArray(widgets)) {
|
|
13504
13553
|
throw new Error(withUsage$1('The `addWidgets` method expects an array of widgets. Please use `addWidget`.'));
|
|
13505
13554
|
}
|
|
13506
|
-
if (widgets.some(function (
|
|
13507
|
-
return
|
|
13555
|
+
if (this.compositionID && widgets.some(function (w) {
|
|
13556
|
+
return !Array.isArray(w) && isIndexWidget(w) && !w._isolated;
|
|
13508
13557
|
})) {
|
|
13509
|
-
throw new Error(withUsage$1('The widget definition expects a `render` and/or an `init` method.'));
|
|
13510
|
-
}
|
|
13511
|
-
if (this.compositionID && widgets.some(isIndexWidget)) {
|
|
13512
13558
|
throw new Error(withUsage$1('The `index` widget cannot be used with a composition-based InstantSearch implementation.'));
|
|
13513
13559
|
}
|
|
13514
13560
|
this.mainIndex.addWidgets(widgets);
|
|
@@ -13540,11 +13586,6 @@
|
|
|
13540
13586
|
if (!Array.isArray(widgets)) {
|
|
13541
13587
|
throw new Error(withUsage$1('The `removeWidgets` method expects an array of widgets. Please use `removeWidget`.'));
|
|
13542
13588
|
}
|
|
13543
|
-
if (widgets.some(function (widget) {
|
|
13544
|
-
return typeof widget.dispose !== 'function';
|
|
13545
|
-
})) {
|
|
13546
|
-
throw new Error(withUsage$1('The widget definition expects a `dispose` method.'));
|
|
13547
|
-
}
|
|
13548
13589
|
this.mainIndex.removeWidgets(widgets);
|
|
13549
13590
|
return this;
|
|
13550
13591
|
}
|
|
@@ -16672,7 +16713,7 @@
|
|
|
16672
16713
|
});
|
|
16673
16714
|
// if there is one TextNode first and one TextNode last, the
|
|
16674
16715
|
// last one's nodeValue will be assigned to the first.
|
|
16675
|
-
if (this.nodes[0].nodeValue) {
|
|
16716
|
+
if (this.nodes[0] && this.nodes[0].nodeValue) {
|
|
16676
16717
|
this.nodes[0].nodeValue = '';
|
|
16677
16718
|
}
|
|
16678
16719
|
}
|
|
@@ -21060,22 +21101,20 @@
|
|
|
21060
21101
|
return Math.max.apply(Math, [page].concat(_toConsumableArray$8(pages)));
|
|
21061
21102
|
}
|
|
21062
21103
|
};
|
|
21063
|
-
var getShowPrevious = function getShowPrevious(helper) {
|
|
21104
|
+
var getShowPrevious = function getShowPrevious(helper, getCachedHits) {
|
|
21064
21105
|
return function () {
|
|
21106
|
+
var cachedHits = getCachedHits();
|
|
21065
21107
|
// Using the helper's `overrideStateWithoutTriggeringChangeEvent` method
|
|
21066
21108
|
// avoid updating the browser URL when the user displays the previous page.
|
|
21067
21109
|
helper.overrideStateWithoutTriggeringChangeEvent(_objectSpread$G(_objectSpread$G({}, helper.state), {}, {
|
|
21068
|
-
page: getFirstReceivedPage(helper.state,
|
|
21069
|
-
state: normalizeState(helper.state)
|
|
21070
|
-
}) || {}) - 1
|
|
21110
|
+
page: getFirstReceivedPage(helper.state, cachedHits) - 1
|
|
21071
21111
|
})).searchWithoutTriggeringOnStateChange();
|
|
21072
21112
|
};
|
|
21073
21113
|
};
|
|
21074
|
-
var getShowMore = function getShowMore(helper) {
|
|
21114
|
+
var getShowMore = function getShowMore(helper, getCachedHits) {
|
|
21075
21115
|
return function () {
|
|
21076
|
-
|
|
21077
|
-
|
|
21078
|
-
}) || {}) + 1).search();
|
|
21116
|
+
var cachedHits = getCachedHits();
|
|
21117
|
+
helper.setPage(getLastReceivedPage(helper.state, cachedHits) + 1).search();
|
|
21079
21118
|
};
|
|
21080
21119
|
};
|
|
21081
21120
|
return {
|
|
@@ -21107,6 +21146,12 @@
|
|
|
21107
21146
|
parent = _ref6.parent,
|
|
21108
21147
|
existingState = _ref6.state,
|
|
21109
21148
|
instantSearchInstance = _ref6.instantSearchInstance;
|
|
21149
|
+
var getCacheHits = function getCacheHits() {
|
|
21150
|
+
var state = parent.getPreviousState() || existingState;
|
|
21151
|
+
return cache.read({
|
|
21152
|
+
state: normalizeState(state)
|
|
21153
|
+
}) || {};
|
|
21154
|
+
};
|
|
21110
21155
|
var isFirstPage;
|
|
21111
21156
|
var currentPageHits = [];
|
|
21112
21157
|
/**
|
|
@@ -21115,13 +21160,15 @@
|
|
|
21115
21160
|
* is loading.
|
|
21116
21161
|
*/
|
|
21117
21162
|
var state = parent.getPreviousState() || existingState;
|
|
21118
|
-
var cachedHits =
|
|
21119
|
-
state: normalizeState(state)
|
|
21120
|
-
}) || {};
|
|
21163
|
+
var cachedHits = getCacheHits();
|
|
21121
21164
|
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];
|
|
21122
21165
|
if (!showPrevious) {
|
|
21123
|
-
showPrevious =
|
|
21124
|
-
|
|
21166
|
+
showPrevious = function showPrevious() {
|
|
21167
|
+
return getShowPrevious(helper, getCacheHits)();
|
|
21168
|
+
};
|
|
21169
|
+
showMore = function showMore() {
|
|
21170
|
+
return getShowMore(helper, getCacheHits)();
|
|
21171
|
+
};
|
|
21125
21172
|
}
|
|
21126
21173
|
if (!sendEvent) {
|
|
21127
21174
|
sendEvent = createSendEventForHits({
|