instantsearch.js 4.85.2 → 4.86.1
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/sort-by/connectSortBy.js +118 -18
- package/cjs/lib/version.js +1 -1
- package/cjs/widgets/autocomplete/autocomplete.js +140 -103
- package/dist/instantsearch.development.d.ts +76 -11
- package/dist/instantsearch.development.js +311 -131
- package/dist/instantsearch.development.js.map +1 -1
- package/dist/instantsearch.production.d.ts +76 -11
- package/dist/instantsearch.production.min.d.ts +76 -11
- package/dist/instantsearch.production.min.js +2 -2
- package/dist/instantsearch.production.min.js.map +1 -1
- package/es/connectors/sort-by/connectSortBy.d.ts +41 -9
- package/es/connectors/sort-by/connectSortBy.js +118 -18
- package/es/lib/version.d.ts +1 -1
- package/es/lib/version.js +1 -1
- package/es/widgets/autocomplete/autocomplete.d.ts +9 -0
- package/es/widgets/autocomplete/autocomplete.js +140 -103
- package/es/widgets/sort-by/sort-by.d.ts +22 -2
- package/package.json +8 -8
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! InstantSearch.js 4.
|
|
1
|
+
/*! InstantSearch.js 4.86.1 | © 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) :
|
|
@@ -6573,7 +6573,7 @@
|
|
|
6573
6573
|
|
|
6574
6574
|
var sortAndMergeRecommendations_1 = sortAndMergeRecommendations;
|
|
6575
6575
|
|
|
6576
|
-
var version = '3.
|
|
6576
|
+
var version = '3.27.0';
|
|
6577
6577
|
|
|
6578
6578
|
var escapeFacetValue$4 = escapeFacetValue_1.escapeFacetValue;
|
|
6579
6579
|
|
|
@@ -11800,10 +11800,33 @@
|
|
|
11800
11800
|
|
|
11801
11801
|
/**
|
|
11802
11802
|
* The **SortBy** connector provides the logic to build a custom widget that will display a
|
|
11803
|
-
* list of indices. With Algolia, this is most commonly used for changing
|
|
11804
|
-
* a user to change how the hits are being sorted.
|
|
11803
|
+
* list of indices or sorting strategies. With Algolia, this is most commonly used for changing
|
|
11804
|
+
* ranking strategy. This allows a user to change how the hits are being sorted.
|
|
11805
|
+
*
|
|
11806
|
+
* This connector supports two sorting modes:
|
|
11807
|
+
* 1. **Index-based (traditional)**: Uses the `value` property to switch between different indices.
|
|
11808
|
+
* This is the standard behavior for non-composition setups.
|
|
11809
|
+
*
|
|
11810
|
+
* 2. **Strategy-based (composition mode)**: Uses the `strategy` property to apply sorting strategies
|
|
11811
|
+
* via the `sortBy` search parameter. This is only available when using Algolia Compositions.
|
|
11812
|
+
*
|
|
11813
|
+
* Items can mix both types in the same widget, allowing for flexible sorting options.
|
|
11805
11814
|
*/
|
|
11806
11815
|
|
|
11816
|
+
function isStrategyItem(item) {
|
|
11817
|
+
return 'strategy' in item && item.strategy !== undefined;
|
|
11818
|
+
}
|
|
11819
|
+
function getItemValue(item) {
|
|
11820
|
+
if (isStrategyItem(item)) {
|
|
11821
|
+
return item.strategy;
|
|
11822
|
+
}
|
|
11823
|
+
return item.value;
|
|
11824
|
+
}
|
|
11825
|
+
function isValidStrategy(itemsLookup, value) {
|
|
11826
|
+
if (!value) return false;
|
|
11827
|
+
var item = itemsLookup[value];
|
|
11828
|
+
return item !== undefined && isStrategyItem(item);
|
|
11829
|
+
}
|
|
11807
11830
|
var connectSortBy = function connectSortBy(renderFn) {
|
|
11808
11831
|
var unmountFn = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : noop;
|
|
11809
11832
|
checkRendering(renderFn, withUsage$h());
|
|
@@ -11818,14 +11841,38 @@
|
|
|
11818
11841
|
if (!Array.isArray(items)) {
|
|
11819
11842
|
throw new Error(withUsage$h('The `items` option expects an array of objects.'));
|
|
11820
11843
|
}
|
|
11844
|
+
var itemsLookup = {};
|
|
11845
|
+
items.forEach(function (item, index) {
|
|
11846
|
+
var hasValue = 'value' in item && item.value !== undefined;
|
|
11847
|
+
var hasStrategy = 'strategy' in item && item.strategy !== undefined;
|
|
11848
|
+
|
|
11849
|
+
// Validate mutual exclusivity
|
|
11850
|
+
if (hasValue && hasStrategy) {
|
|
11851
|
+
throw new Error(withUsage$h("Item at index ".concat(index, " cannot have both \"value\" and \"strategy\" properties.")));
|
|
11852
|
+
}
|
|
11853
|
+
if (!hasValue && !hasStrategy) {
|
|
11854
|
+
throw new Error(withUsage$h("Item at index ".concat(index, " must have either a \"value\" or \"strategy\" property.")));
|
|
11855
|
+
}
|
|
11856
|
+
var itemValue = getItemValue(item);
|
|
11857
|
+
itemsLookup[itemValue] = item;
|
|
11858
|
+
});
|
|
11859
|
+
connectorState.itemsLookup = itemsLookup;
|
|
11821
11860
|
return {
|
|
11822
11861
|
$$type: 'ais.sortBy',
|
|
11823
11862
|
init: function init(initOptions) {
|
|
11824
11863
|
var instantSearchInstance = initOptions.instantSearchInstance;
|
|
11864
|
+
|
|
11865
|
+
// Check if strategies are used outside composition mode
|
|
11866
|
+
var hasStrategyItems = items.some(function (item) {
|
|
11867
|
+
return 'strategy' in item && item.strategy;
|
|
11868
|
+
});
|
|
11869
|
+
if (hasStrategyItems && !instantSearchInstance.compositionID) {
|
|
11870
|
+
throw new Error(withUsage$h('Sorting strategies can only be used in composition mode. Please provide a "compositionID" to your InstantSearch instance.'));
|
|
11871
|
+
}
|
|
11825
11872
|
var widgetRenderState = this.getWidgetRenderState(initOptions);
|
|
11826
11873
|
var currentIndex = widgetRenderState.currentRefinement;
|
|
11827
11874
|
var isCurrentIndexInItems = find(items, function (item) {
|
|
11828
|
-
return item
|
|
11875
|
+
return getItemValue(item) === currentIndex;
|
|
11829
11876
|
});
|
|
11830
11877
|
_warning(isCurrentIndexInItems !== undefined, "The index named \"".concat(currentIndex, "\" is not listed in the `items` of `sortBy`.")) ;
|
|
11831
11878
|
renderFn(_objectSpread2(_objectSpread2({}, widgetRenderState), {}, {
|
|
@@ -11841,7 +11888,17 @@
|
|
|
11841
11888
|
dispose: function dispose(_ref2) {
|
|
11842
11889
|
var state = _ref2.state;
|
|
11843
11890
|
unmountFn();
|
|
11844
|
-
|
|
11891
|
+
|
|
11892
|
+
// Clear sortBy parameter if it was set
|
|
11893
|
+
if (connectorState.isUsingComposition && state.sortBy) {
|
|
11894
|
+
state = state.setQueryParameter('sortBy', undefined);
|
|
11895
|
+
}
|
|
11896
|
+
|
|
11897
|
+
// Restore initial index if changed
|
|
11898
|
+
if (connectorState.initialValue && state.index !== connectorState.initialValue) {
|
|
11899
|
+
return state.setIndex(connectorState.initialValue);
|
|
11900
|
+
}
|
|
11901
|
+
return state;
|
|
11845
11902
|
},
|
|
11846
11903
|
getRenderState: function getRenderState(renderState, renderOptions) {
|
|
11847
11904
|
return _objectSpread2(_objectSpread2({}, renderState), {}, {
|
|
@@ -11852,22 +11909,54 @@
|
|
|
11852
11909
|
var results = _ref3.results,
|
|
11853
11910
|
helper = _ref3.helper,
|
|
11854
11911
|
state = _ref3.state,
|
|
11855
|
-
parent = _ref3.parent
|
|
11856
|
-
|
|
11857
|
-
|
|
11912
|
+
parent = _ref3.parent,
|
|
11913
|
+
instantSearchInstance = _ref3.instantSearchInstance;
|
|
11914
|
+
// Capture initial value (composition ID or main index)
|
|
11915
|
+
if (!connectorState.initialValue && parent) {
|
|
11916
|
+
connectorState.initialValue = parent.getIndexName();
|
|
11858
11917
|
}
|
|
11859
|
-
|
|
11860
|
-
|
|
11861
|
-
|
|
11918
|
+
|
|
11919
|
+
// Create refine function if not exists
|
|
11920
|
+
if (!connectorState.refine) {
|
|
11921
|
+
// Cache composition mode status for lifecycle methods that don't have access to instantSearchInstance
|
|
11922
|
+
connectorState.isUsingComposition = Boolean(instantSearchInstance === null || instantSearchInstance === void 0 ? void 0 : instantSearchInstance.compositionID);
|
|
11923
|
+
connectorState.refine = function (value) {
|
|
11924
|
+
// O(1) lookup using the items lookup table
|
|
11925
|
+
var item = connectorState.itemsLookup[value];
|
|
11926
|
+
if (item && isStrategyItem(item)) {
|
|
11927
|
+
// Strategy-based: set sortBy parameter for composition API
|
|
11928
|
+
// The composition backend will interpret this and apply the sorting strategy
|
|
11929
|
+
helper.setQueryParameter('sortBy', item.strategy).search();
|
|
11930
|
+
} else {
|
|
11931
|
+
// Index-based: clear any existing sortBy parameter and switch to the new index
|
|
11932
|
+
// Clearing sortBy is critical when transitioning from strategy to index-based sorting
|
|
11933
|
+
helper.setQueryParameter('sortBy', undefined).setIndex(value).search();
|
|
11934
|
+
}
|
|
11862
11935
|
};
|
|
11863
11936
|
}
|
|
11937
|
+
|
|
11938
|
+
// Transform items first (on original structure)
|
|
11939
|
+
var transformedItems = transformItems(items, {
|
|
11940
|
+
results: results
|
|
11941
|
+
});
|
|
11942
|
+
|
|
11943
|
+
// Normalize items: all get a 'value' property for the render state
|
|
11944
|
+
var normalizedItems = transformedItems.map(function (item) {
|
|
11945
|
+
return {
|
|
11946
|
+
label: item.label,
|
|
11947
|
+
value: getItemValue(item)
|
|
11948
|
+
};
|
|
11949
|
+
});
|
|
11950
|
+
|
|
11951
|
+
// Determine current refinement
|
|
11952
|
+
// In composition mode, prefer sortBy parameter if it corresponds to a valid strategy item
|
|
11953
|
+
// Otherwise use the index (for index-based items or when no valid strategy is active)
|
|
11954
|
+
var currentRefinement = connectorState.isUsingComposition && isValidStrategy(connectorState.itemsLookup, state.sortBy) ? state.sortBy : state.index;
|
|
11864
11955
|
var hasNoResults = results ? results.nbHits === 0 : true;
|
|
11865
11956
|
return {
|
|
11866
|
-
currentRefinement:
|
|
11867
|
-
options:
|
|
11868
|
-
|
|
11869
|
-
}),
|
|
11870
|
-
refine: connectorState.setIndex,
|
|
11957
|
+
currentRefinement: currentRefinement,
|
|
11958
|
+
options: normalizedItems,
|
|
11959
|
+
refine: connectorState.refine,
|
|
11871
11960
|
hasNoResults: hasNoResults,
|
|
11872
11961
|
canRefine: !hasNoResults && items.length > 0,
|
|
11873
11962
|
widgetParams: widgetParams
|
|
@@ -11875,14 +11964,25 @@
|
|
|
11875
11964
|
},
|
|
11876
11965
|
getWidgetUiState: function getWidgetUiState(uiState, _ref4) {
|
|
11877
11966
|
var searchParameters = _ref4.searchParameters;
|
|
11878
|
-
|
|
11967
|
+
// In composition mode with an active strategy, use sortBy parameter
|
|
11968
|
+
// Otherwise use index-based behavior (traditional mode)
|
|
11969
|
+
var currentValue = connectorState.isUsingComposition && isValidStrategy(connectorState.itemsLookup, searchParameters.sortBy) ? searchParameters.sortBy : searchParameters.index;
|
|
11879
11970
|
return _objectSpread2(_objectSpread2({}, uiState), {}, {
|
|
11880
|
-
sortBy:
|
|
11971
|
+
sortBy: currentValue !== connectorState.initialValue ? currentValue : undefined
|
|
11881
11972
|
});
|
|
11882
11973
|
},
|
|
11883
11974
|
getWidgetSearchParameters: function getWidgetSearchParameters(searchParameters, _ref5) {
|
|
11884
11975
|
var uiState = _ref5.uiState;
|
|
11885
|
-
|
|
11976
|
+
var sortByValue = uiState.sortBy || connectorState.initialValue || searchParameters.index;
|
|
11977
|
+
if (isValidStrategy(connectorState.itemsLookup, sortByValue)) {
|
|
11978
|
+
var item = connectorState.itemsLookup[sortByValue];
|
|
11979
|
+
// Strategy-based: set the sortBy parameter for composition API
|
|
11980
|
+
// The index remains as the compositionID
|
|
11981
|
+
return searchParameters.setQueryParameter('sortBy', item.strategy);
|
|
11982
|
+
}
|
|
11983
|
+
|
|
11984
|
+
// Index-based: set the index parameter (traditional behavior)
|
|
11985
|
+
return searchParameters.setQueryParameter('index', sortByValue);
|
|
11886
11986
|
}
|
|
11887
11987
|
};
|
|
11888
11988
|
};
|
|
@@ -16490,7 +16590,7 @@
|
|
|
16490
16590
|
};
|
|
16491
16591
|
}
|
|
16492
16592
|
|
|
16493
|
-
var version$1 = '4.
|
|
16593
|
+
var version$1 = '4.86.1';
|
|
16494
16594
|
|
|
16495
16595
|
var withUsage$v = createDocumentationMessageGenerator({
|
|
16496
16596
|
name: 'instantsearch'
|
|
@@ -17242,7 +17342,7 @@
|
|
|
17242
17342
|
};
|
|
17243
17343
|
}
|
|
17244
17344
|
|
|
17245
|
-
var _excluded$a = ["className", "onSelect"];
|
|
17345
|
+
var _excluded$a = ["className", "onSelect", "onApply"];
|
|
17246
17346
|
function createAutocompleteIndexComponent(_ref) {
|
|
17247
17347
|
var createElement = _ref.createElement;
|
|
17248
17348
|
return function AutocompleteIndex(userProps) {
|
|
@@ -17264,6 +17364,7 @@
|
|
|
17264
17364
|
var _getItemProps = getItemProps(item, index),
|
|
17265
17365
|
className = _getItemProps.className,
|
|
17266
17366
|
onSelect = _getItemProps.onSelect,
|
|
17367
|
+
onApply = _getItemProps.onApply,
|
|
17267
17368
|
itemProps = _objectWithoutProperties$1(_getItemProps, _excluded$a);
|
|
17268
17369
|
return createElement("li", _extends$1({
|
|
17269
17370
|
key: "".concat(itemProps.id, ":").concat(item.objectID)
|
|
@@ -17271,7 +17372,8 @@
|
|
|
17271
17372
|
className: cx('ais-AutocompleteIndexItem', classNames.item, className)
|
|
17272
17373
|
}), createElement(ItemComponent, {
|
|
17273
17374
|
item: item,
|
|
17274
|
-
onSelect: onSelect
|
|
17375
|
+
onSelect: onSelect,
|
|
17376
|
+
onApply: onApply
|
|
17275
17377
|
}));
|
|
17276
17378
|
})));
|
|
17277
17379
|
};
|
|
@@ -17502,6 +17604,15 @@
|
|
|
17502
17604
|
d: "M18 7v13c0 0.276-0.111 0.525-0.293 0.707s-0.431 0.293-0.707 0.293h-10c-0.276 0-0.525-0.111-0.707-0.293s-0.293-0.431-0.293-0.707v-13zM17 5v-1c0-0.828-0.337-1.58-0.879-2.121s-1.293-0.879-2.121-0.879h-4c-0.828 0-1.58 0.337-2.121 0.879s-0.879 1.293-0.879 2.121v1h-4c-0.552 0-1 0.448-1 1s0.448 1 1 1h1v13c0 0.828 0.337 1.58 0.879 2.121s1.293 0.879 2.121 0.879h10c0.828 0 1.58-0.337 2.121-0.879s0.879-1.293 0.879-2.121v-13h1c0.552 0 1-0.448 1-1s-0.448-1-1-1zM9 5v-1c0-0.276 0.111-0.525 0.293-0.707s0.431-0.293 0.707-0.293h4c0.276 0 0.525 0.111 0.707 0.293s0.293 0.431 0.293 0.707v1zM9 11v6c0 0.552 0.448 1 1 1s1-0.448 1-1v-6c0-0.552-0.448-1-1-1s-1 0.448-1 1zM13 11v6c0 0.552 0.448 1 1 1s1-0.448 1-1v-6c0-0.552-0.448-1-1-1s-1 0.448-1 1z"
|
|
17503
17605
|
}));
|
|
17504
17606
|
}
|
|
17607
|
+
function ApplyIcon(_ref6) {
|
|
17608
|
+
var createElement = _ref6.createElement;
|
|
17609
|
+
return createElement("svg", {
|
|
17610
|
+
viewBox: "0 0 24 24",
|
|
17611
|
+
fill: "currentColor"
|
|
17612
|
+
}, createElement("path", {
|
|
17613
|
+
d: "M8 17v-7.586l8.293 8.293c0.391 0.391 1.024 0.391 1.414 0s0.391-1.024 0-1.414l-8.293-8.293h7.586c0.552 0 1-0.448 1-1s-0.448-1-1-1h-10c-0.552 0-1 0.448-1 1v10c0 0.552 0.448 1 1 1s1-0.448 1-1z"
|
|
17614
|
+
}));
|
|
17615
|
+
}
|
|
17505
17616
|
|
|
17506
17617
|
function createAutocompleteRecentSearchComponent(_ref) {
|
|
17507
17618
|
var createElement = _ref.createElement;
|
|
@@ -17510,6 +17621,7 @@
|
|
|
17510
17621
|
children = userProps.children,
|
|
17511
17622
|
onSelect = userProps.onSelect,
|
|
17512
17623
|
onRemoveRecentSearch = userProps.onRemoveRecentSearch,
|
|
17624
|
+
onApply = userProps.onApply,
|
|
17513
17625
|
_userProps$classNames = userProps.classNames,
|
|
17514
17626
|
classNames = _userProps$classNames === void 0 ? {} : _userProps$classNames;
|
|
17515
17627
|
return createElement("div", {
|
|
@@ -17534,6 +17646,15 @@
|
|
|
17534
17646
|
}
|
|
17535
17647
|
}, createElement(TrashIcon, {
|
|
17536
17648
|
createElement: createElement
|
|
17649
|
+
})), createElement("button", {
|
|
17650
|
+
className: cx('ais-AutocompleteItemActionButton', 'ais-AutocompleteRecentSearchItemApplyButton', classNames.applyButton),
|
|
17651
|
+
title: "Apply ".concat(item.query, " as search"),
|
|
17652
|
+
onClick: function onClick(evt) {
|
|
17653
|
+
evt.stopPropagation();
|
|
17654
|
+
onApply();
|
|
17655
|
+
}
|
|
17656
|
+
}, createElement(ApplyIcon, {
|
|
17657
|
+
createElement: createElement
|
|
17537
17658
|
}))));
|
|
17538
17659
|
};
|
|
17539
17660
|
}
|
|
@@ -17607,8 +17728,10 @@
|
|
|
17607
17728
|
function createAutocompleteSuggestionComponent(_ref) {
|
|
17608
17729
|
var createElement = _ref.createElement;
|
|
17609
17730
|
return function AutocompleteSuggestion(userProps) {
|
|
17610
|
-
var
|
|
17731
|
+
var item = userProps.item,
|
|
17732
|
+
children = userProps.children,
|
|
17611
17733
|
onSelect = userProps.onSelect,
|
|
17734
|
+
onApply = userProps.onApply,
|
|
17612
17735
|
_userProps$classNames = userProps.classNames,
|
|
17613
17736
|
classNames = _userProps$classNames === void 0 ? {} : _userProps$classNames;
|
|
17614
17737
|
return createElement("div", {
|
|
@@ -17622,7 +17745,19 @@
|
|
|
17622
17745
|
createElement: createElement
|
|
17623
17746
|
})), createElement("div", {
|
|
17624
17747
|
className: cx('ais-AutocompleteItemContentBody', 'ais-AutocompleteSuggestionItemContentBody', classNames.content)
|
|
17625
|
-
}, children))
|
|
17748
|
+
}, children)), createElement("div", {
|
|
17749
|
+
className: cx('ais-AutocompleteItemActions', 'ais-AutocompleteSuggestionItemActions', classNames.actions)
|
|
17750
|
+
}, createElement("button", {
|
|
17751
|
+
className: cx('ais-AutocompleteItemActionButton', 'ais-AutocompleteSuggestionItemApplyButton', classNames.applyButton),
|
|
17752
|
+
type: "button",
|
|
17753
|
+
title: "Apply ".concat(item.query, " as search"),
|
|
17754
|
+
onClick: function onClick(evt) {
|
|
17755
|
+
evt.stopPropagation();
|
|
17756
|
+
onApply();
|
|
17757
|
+
}
|
|
17758
|
+
}, createElement(ApplyIcon, {
|
|
17759
|
+
createElement: createElement
|
|
17760
|
+
}))));
|
|
17626
17761
|
};
|
|
17627
17762
|
}
|
|
17628
17763
|
|
|
@@ -17637,6 +17772,7 @@
|
|
|
17637
17772
|
indicesConfig = _ref2.indicesConfig,
|
|
17638
17773
|
onRefine = _ref2.onRefine,
|
|
17639
17774
|
globalOnSelect = _ref2.onSelect,
|
|
17775
|
+
_onApply = _ref2.onApply,
|
|
17640
17776
|
placeholder = _ref2.placeholder;
|
|
17641
17777
|
var getElementId = createGetElementId(useId());
|
|
17642
17778
|
var inputRef = useRef(null);
|
|
@@ -17804,6 +17940,13 @@
|
|
|
17804
17940
|
return submit({
|
|
17805
17941
|
activeDescendant: id
|
|
17806
17942
|
});
|
|
17943
|
+
},
|
|
17944
|
+
onApply: function onApply() {
|
|
17945
|
+
var _getQuery2;
|
|
17946
|
+
var _ref4 = items.get(id),
|
|
17947
|
+
currentItem = _ref4.item,
|
|
17948
|
+
getQuery = _ref4.config.getQuery;
|
|
17949
|
+
_onApply((_getQuery2 = getQuery === null || getQuery === void 0 ? void 0 : getQuery(currentItem)) !== null && _getQuery2 !== void 0 ? _getQuery2 : '');
|
|
17807
17950
|
}
|
|
17808
17951
|
};
|
|
17809
17952
|
},
|
|
@@ -17823,10 +17966,10 @@
|
|
|
17823
17966
|
};
|
|
17824
17967
|
};
|
|
17825
17968
|
}
|
|
17826
|
-
function buildItems(
|
|
17827
|
-
var indices =
|
|
17828
|
-
indicesConfig =
|
|
17829
|
-
getElementId =
|
|
17969
|
+
function buildItems(_ref5) {
|
|
17970
|
+
var indices = _ref5.indices,
|
|
17971
|
+
indicesConfig = _ref5.indicesConfig,
|
|
17972
|
+
getElementId = _ref5.getElementId;
|
|
17830
17973
|
var itemsIds = [];
|
|
17831
17974
|
var items = new Map();
|
|
17832
17975
|
for (var i = 0; i < indicesConfig.length; i++) {
|
|
@@ -20453,6 +20596,7 @@
|
|
|
20453
20596
|
return function (connectorParams, isFirstRendering) {
|
|
20454
20597
|
if (isFirstRendering) {
|
|
20455
20598
|
var _targetIndex$getHelpe, _targetIndex$getHelpe2;
|
|
20599
|
+
var showRecentObj = rendererParams.showRecent;
|
|
20456
20600
|
var isolatedIndex = connectorParams.instantSearchInstance.mainIndex;
|
|
20457
20601
|
var targetIndex = connectorParams.instantSearchInstance.mainIndex;
|
|
20458
20602
|
walkIndex(targetIndex, function (childIndex) {
|
|
@@ -20461,6 +20605,56 @@
|
|
|
20461
20605
|
targetIndex = childIndex.parent;
|
|
20462
20606
|
}
|
|
20463
20607
|
});
|
|
20608
|
+
var RecentSearchComponent = function RecentSearchComponent(_ref) {
|
|
20609
|
+
var item = _ref.item,
|
|
20610
|
+
onSelect = _ref.onSelect,
|
|
20611
|
+
onApply = _ref.onApply,
|
|
20612
|
+
onRemoveRecentSearch = _ref.onRemoveRecentSearch;
|
|
20613
|
+
return h(AutocompleteRecentSearch, {
|
|
20614
|
+
item: item,
|
|
20615
|
+
onSelect: onSelect,
|
|
20616
|
+
onApply: onApply,
|
|
20617
|
+
onRemoveRecentSearch: onRemoveRecentSearch
|
|
20618
|
+
}, h(ConditionalReverseHighlight, {
|
|
20619
|
+
item: item
|
|
20620
|
+
}));
|
|
20621
|
+
};
|
|
20622
|
+
var recentSearchHeaderComponent = undefined;
|
|
20623
|
+
if (showRecentObj && showRecentObj.templates) {
|
|
20624
|
+
var recentTemplateProps = prepareTemplateProps({
|
|
20625
|
+
defaultTemplates: {},
|
|
20626
|
+
templatesConfig: connectorParams.instantSearchInstance.templatesConfig,
|
|
20627
|
+
templates: showRecentObj.templates
|
|
20628
|
+
});
|
|
20629
|
+
if (showRecentObj.templates.item) {
|
|
20630
|
+
RecentSearchComponent = function RecentSearchComponent(_ref2) {
|
|
20631
|
+
var item = _ref2.item,
|
|
20632
|
+
onSelect = _ref2.onSelect,
|
|
20633
|
+
onRemoveRecentSearch = _ref2.onRemoveRecentSearch;
|
|
20634
|
+
return h(Template, _extends({}, recentTemplateProps, {
|
|
20635
|
+
templateKey: "item",
|
|
20636
|
+
rootTagName: "fragment",
|
|
20637
|
+
data: {
|
|
20638
|
+
item: item,
|
|
20639
|
+
onSelect: onSelect,
|
|
20640
|
+
onRemoveRecentSearch: onRemoveRecentSearch
|
|
20641
|
+
}
|
|
20642
|
+
}));
|
|
20643
|
+
};
|
|
20644
|
+
}
|
|
20645
|
+
if (showRecentObj.templates.header) {
|
|
20646
|
+
recentSearchHeaderComponent = function recentSearchHeaderComponent(_ref3) {
|
|
20647
|
+
var items = _ref3.items;
|
|
20648
|
+
return h(Template, _extends({}, recentTemplateProps, {
|
|
20649
|
+
templateKey: "header",
|
|
20650
|
+
rootTagName: "fragment",
|
|
20651
|
+
data: {
|
|
20652
|
+
items: items
|
|
20653
|
+
}
|
|
20654
|
+
}));
|
|
20655
|
+
};
|
|
20656
|
+
}
|
|
20657
|
+
}
|
|
20464
20658
|
rendererParams.renderState = {
|
|
20465
20659
|
indexTemplateProps: [],
|
|
20466
20660
|
isolatedIndex: isolatedIndex,
|
|
@@ -20469,7 +20663,9 @@
|
|
|
20469
20663
|
defaultTemplates: {},
|
|
20470
20664
|
templatesConfig: connectorParams.instantSearchInstance.templatesConfig,
|
|
20471
20665
|
templates: rendererParams.templates
|
|
20472
|
-
})
|
|
20666
|
+
}),
|
|
20667
|
+
RecentSearchComponent: RecentSearchComponent,
|
|
20668
|
+
recentSearchHeaderComponent: recentSearchHeaderComponent
|
|
20473
20669
|
};
|
|
20474
20670
|
connectorParams.refine((_targetIndex$getHelpe = (_targetIndex$getHelpe2 = targetIndex.getHelper()) === null || _targetIndex$getHelpe2 === void 0 ? void 0 : _targetIndex$getHelpe2.state.query) !== null && _targetIndex$getHelpe !== void 0 ? _targetIndex$getHelpe : '');
|
|
20475
20671
|
return;
|
|
@@ -20477,20 +20673,20 @@
|
|
|
20477
20673
|
P(h(AutocompleteWrapper, _extends({}, rendererParams, connectorParams)), containerNode);
|
|
20478
20674
|
};
|
|
20479
20675
|
};
|
|
20480
|
-
function AutocompleteWrapper(
|
|
20481
|
-
var _isolatedIndex$getHel,
|
|
20482
|
-
var indicesConfig =
|
|
20483
|
-
indices =
|
|
20484
|
-
getSearchPageURL =
|
|
20485
|
-
userOnSelect =
|
|
20486
|
-
refineAutocomplete =
|
|
20487
|
-
cssClasses =
|
|
20488
|
-
renderState =
|
|
20489
|
-
instantSearchInstance =
|
|
20490
|
-
showRecent =
|
|
20491
|
-
showSuggestions =
|
|
20492
|
-
templates =
|
|
20493
|
-
placeholder =
|
|
20676
|
+
function AutocompleteWrapper(_ref4) {
|
|
20677
|
+
var _isolatedIndex$getHel, _showRecentObj$cssCla, _showRecentObj$cssCla2, _showRecentObj$cssCla3, _showRecentObj$cssCla4, _targetIndex$getWidge;
|
|
20678
|
+
var indicesConfig = _ref4.indicesConfig,
|
|
20679
|
+
indices = _ref4.indices,
|
|
20680
|
+
getSearchPageURL = _ref4.getSearchPageURL,
|
|
20681
|
+
userOnSelect = _ref4.onSelect,
|
|
20682
|
+
refineAutocomplete = _ref4.refine,
|
|
20683
|
+
cssClasses = _ref4.cssClasses,
|
|
20684
|
+
renderState = _ref4.renderState,
|
|
20685
|
+
instantSearchInstance = _ref4.instantSearchInstance,
|
|
20686
|
+
showRecent = _ref4.showRecent,
|
|
20687
|
+
showSuggestions = _ref4.showSuggestions,
|
|
20688
|
+
templates = _ref4.templates,
|
|
20689
|
+
placeholder = _ref4.placeholder;
|
|
20494
20690
|
var isolatedIndex = renderState.isolatedIndex,
|
|
20495
20691
|
targetIndex = renderState.targetIndex;
|
|
20496
20692
|
var searchboxQuery = isolatedIndex === null || isolatedIndex === void 0 ? void 0 : (_isolatedIndex$getHel = isolatedIndex.getHelper()) === null || _isolatedIndex$getHel === void 0 ? void 0 : _isolatedIndex$getHel.state.query;
|
|
@@ -20504,8 +20700,15 @@
|
|
|
20504
20700
|
storageHits = _useStorage.storageHits,
|
|
20505
20701
|
indicesConfigForPropGetters = _useStorage.indicesConfigForPropGetters,
|
|
20506
20702
|
indicesForPropGetters = _useStorage.indicesForPropGetters;
|
|
20507
|
-
var
|
|
20508
|
-
|
|
20703
|
+
var showRecentObj = showRecent;
|
|
20704
|
+
var recentSearchCssClasses = {
|
|
20705
|
+
root: cx('ais-AutocompleteRecentSearches', showRecentObj === null || showRecentObj === void 0 ? void 0 : (_showRecentObj$cssCla = showRecentObj.cssClasses) === null || _showRecentObj$cssCla === void 0 ? void 0 : _showRecentObj$cssCla.root),
|
|
20706
|
+
list: cx('ais-AutocompleteRecentSearchesList', showRecentObj === null || showRecentObj === void 0 ? void 0 : (_showRecentObj$cssCla2 = showRecentObj.cssClasses) === null || _showRecentObj$cssCla2 === void 0 ? void 0 : _showRecentObj$cssCla2.list),
|
|
20707
|
+
header: cx('ais-AutocompleteRecentSearchesHeader', showRecentObj === null || showRecentObj === void 0 ? void 0 : (_showRecentObj$cssCla3 = showRecentObj.cssClasses) === null || _showRecentObj$cssCla3 === void 0 ? void 0 : _showRecentObj$cssCla3.header),
|
|
20708
|
+
item: cx('ais-AutocompleteRecentSearchesItem', showRecentObj === null || showRecentObj === void 0 ? void 0 : (_showRecentObj$cssCla4 = showRecentObj.cssClasses) === null || _showRecentObj$cssCla4 === void 0 ? void 0 : _showRecentObj$cssCla4.item)
|
|
20709
|
+
};
|
|
20710
|
+
var isSearchPage = (_targetIndex$getWidge = targetIndex === null || targetIndex === void 0 ? void 0 : targetIndex.getWidgets().some(function (_ref5) {
|
|
20711
|
+
var $$type = _ref5.$$type;
|
|
20509
20712
|
return ['ais.hits', 'ais.infiniteHits'].includes($$type);
|
|
20510
20713
|
})) !== null && _targetIndex$getWidge !== void 0 ? _targetIndex$getWidge : false;
|
|
20511
20714
|
var onRefine = function onRefine(query) {
|
|
@@ -20524,10 +20727,10 @@
|
|
|
20524
20727
|
indices: indicesForPropGetters,
|
|
20525
20728
|
indicesConfig: indicesConfigForPropGetters,
|
|
20526
20729
|
onRefine: onRefine,
|
|
20527
|
-
onSelect: userOnSelect !== null && userOnSelect !== void 0 ? userOnSelect : function (
|
|
20528
|
-
var query =
|
|
20529
|
-
setQuery =
|
|
20530
|
-
url =
|
|
20730
|
+
onSelect: userOnSelect !== null && userOnSelect !== void 0 ? userOnSelect : function (_ref6) {
|
|
20731
|
+
var query = _ref6.query,
|
|
20732
|
+
setQuery = _ref6.setQuery,
|
|
20733
|
+
url = _ref6.url;
|
|
20531
20734
|
if (url) {
|
|
20532
20735
|
window.location.href = url;
|
|
20533
20736
|
return;
|
|
@@ -20541,75 +20744,44 @@
|
|
|
20541
20744
|
}
|
|
20542
20745
|
setQuery(query);
|
|
20543
20746
|
},
|
|
20747
|
+
onApply: function onApply(query) {
|
|
20748
|
+
refineAutocomplete(query);
|
|
20749
|
+
},
|
|
20544
20750
|
placeholder: placeholder
|
|
20545
20751
|
}),
|
|
20546
20752
|
getInputProps = _usePropGetters.getInputProps,
|
|
20547
20753
|
getItemProps = _usePropGetters.getItemProps,
|
|
20548
20754
|
getPanelProps = _usePropGetters.getPanelProps,
|
|
20549
20755
|
getRootProps = _usePropGetters.getRootProps;
|
|
20550
|
-
var AutocompleteRecentSearchComponent = function AutocompleteRecentSearchComponent(_ref4) {
|
|
20551
|
-
var item = _ref4.item,
|
|
20552
|
-
onSelect = _ref4.onSelect,
|
|
20553
|
-
onRemoveRecentSearch = _ref4.onRemoveRecentSearch;
|
|
20554
|
-
return h(AutocompleteRecentSearch, {
|
|
20555
|
-
item: item,
|
|
20556
|
-
onSelect: onSelect,
|
|
20557
|
-
onRemoveRecentSearch: onRemoveRecentSearch
|
|
20558
|
-
}, h(ConditionalReverseHighlight, {
|
|
20559
|
-
item: item
|
|
20560
|
-
}));
|
|
20561
|
-
};
|
|
20562
|
-
if (_typeof(showRecent) === 'object' && (_showRecent$templates = showRecent.templates) !== null && _showRecent$templates !== void 0 && _showRecent$templates.item) {
|
|
20563
|
-
var props = prepareTemplateProps({
|
|
20564
|
-
defaultTemplates: {},
|
|
20565
|
-
templatesConfig: instantSearchInstance.templatesConfig,
|
|
20566
|
-
templates: showRecent.templates
|
|
20567
|
-
});
|
|
20568
|
-
AutocompleteRecentSearchComponent = function AutocompleteRecentSearchComponent(_ref5) {
|
|
20569
|
-
var item = _ref5.item,
|
|
20570
|
-
onSelect = _ref5.onSelect,
|
|
20571
|
-
onRemoveRecentSearch = _ref5.onRemoveRecentSearch;
|
|
20572
|
-
return h(Template, _extends({}, props, {
|
|
20573
|
-
templateKey: "item",
|
|
20574
|
-
rootTagName: "fragment",
|
|
20575
|
-
data: {
|
|
20576
|
-
item: item,
|
|
20577
|
-
onSelect: onSelect,
|
|
20578
|
-
onRemoveRecentSearch: onRemoveRecentSearch
|
|
20579
|
-
}
|
|
20580
|
-
}));
|
|
20581
|
-
};
|
|
20582
|
-
}
|
|
20583
20756
|
var elements = {};
|
|
20584
20757
|
if (showRecent) {
|
|
20585
|
-
elements.recent = h(AutocompleteIndex
|
|
20586
|
-
|
|
20587
|
-
|
|
20588
|
-
|
|
20589
|
-
|
|
20590
|
-
|
|
20591
|
-
|
|
20758
|
+
elements.recent = h(AutocompleteIndex, {
|
|
20759
|
+
HeaderComponent: renderState.recentSearchHeaderComponent
|
|
20760
|
+
// @ts-ignore - there seems to be problems with React.ComponentType and this, but it's actually correct
|
|
20761
|
+
,
|
|
20762
|
+
ItemComponent: function ItemComponent(_ref7) {
|
|
20763
|
+
var item = _ref7.item,
|
|
20764
|
+
onSelect = _ref7.onSelect,
|
|
20765
|
+
onApply = _ref7.onApply;
|
|
20766
|
+
return h(renderState.RecentSearchComponent, {
|
|
20592
20767
|
item: item,
|
|
20593
20768
|
onSelect: onSelect,
|
|
20769
|
+
onApply: onApply,
|
|
20594
20770
|
onRemoveRecentSearch: function onRemoveRecentSearch() {
|
|
20595
20771
|
return storage.onRemove(item.query);
|
|
20596
20772
|
}
|
|
20597
20773
|
});
|
|
20598
20774
|
},
|
|
20599
|
-
classNames:
|
|
20600
|
-
root: 'ais-AutocompleteRecentSearches',
|
|
20601
|
-
list: 'ais-AutocompleteRecentSearchesList',
|
|
20602
|
-
item: 'ais-AutocompleteRecentSearchesItem'
|
|
20603
|
-
},
|
|
20775
|
+
classNames: recentSearchCssClasses,
|
|
20604
20776
|
items: storageHits,
|
|
20605
20777
|
getItemProps: getItemProps
|
|
20606
20778
|
});
|
|
20607
20779
|
}
|
|
20608
|
-
indices.forEach(function (
|
|
20780
|
+
indices.forEach(function (_ref8, i) {
|
|
20609
20781
|
var _indicesConfig$i$temp;
|
|
20610
|
-
var indexId =
|
|
20611
|
-
indexName =
|
|
20612
|
-
hits =
|
|
20782
|
+
var indexId = _ref8.indexId,
|
|
20783
|
+
indexName = _ref8.indexName,
|
|
20784
|
+
hits = _ref8.hits;
|
|
20613
20785
|
if (!renderState.indexTemplateProps[i]) {
|
|
20614
20786
|
renderState.indexTemplateProps[i] = prepareTemplateProps({
|
|
20615
20787
|
defaultTemplates: {},
|
|
@@ -20617,8 +20789,8 @@
|
|
|
20617
20789
|
templates: indicesConfig[i].templates
|
|
20618
20790
|
});
|
|
20619
20791
|
}
|
|
20620
|
-
var headerComponent = (_indicesConfig$i$temp = indicesConfig[i].templates) !== null && _indicesConfig$i$temp !== void 0 && _indicesConfig$i$temp.header ? function (
|
|
20621
|
-
var items =
|
|
20792
|
+
var headerComponent = (_indicesConfig$i$temp = indicesConfig[i].templates) !== null && _indicesConfig$i$temp !== void 0 && _indicesConfig$i$temp.header ? function (_ref9) {
|
|
20793
|
+
var items = _ref9.items;
|
|
20622
20794
|
return h(Template, _extends({}, renderState.indexTemplateProps[i], {
|
|
20623
20795
|
templateKey: "header",
|
|
20624
20796
|
rootTagName: "fragment",
|
|
@@ -20627,15 +20799,17 @@
|
|
|
20627
20799
|
}
|
|
20628
20800
|
}));
|
|
20629
20801
|
} : undefined;
|
|
20630
|
-
var itemComponent = function itemComponent(
|
|
20631
|
-
var item =
|
|
20632
|
-
onSelect =
|
|
20802
|
+
var itemComponent = function itemComponent(_ref0) {
|
|
20803
|
+
var item = _ref0.item,
|
|
20804
|
+
onSelect = _ref0.onSelect,
|
|
20805
|
+
onApply = _ref0.onApply;
|
|
20633
20806
|
return h(Template, _extends({}, renderState.indexTemplateProps[i], {
|
|
20634
20807
|
templateKey: "item",
|
|
20635
20808
|
rootTagName: "fragment",
|
|
20636
20809
|
data: {
|
|
20637
20810
|
item: item,
|
|
20638
|
-
onSelect: onSelect
|
|
20811
|
+
onSelect: onSelect,
|
|
20812
|
+
onApply: onApply
|
|
20639
20813
|
}
|
|
20640
20814
|
}));
|
|
20641
20815
|
};
|
|
@@ -20683,21 +20857,21 @@
|
|
|
20683
20857
|
})));
|
|
20684
20858
|
}
|
|
20685
20859
|
function EXPERIMENTAL_autocomplete(widgetParams) {
|
|
20686
|
-
var
|
|
20687
|
-
container =
|
|
20688
|
-
escapeHTML =
|
|
20689
|
-
|
|
20690
|
-
indices =
|
|
20691
|
-
showSuggestions =
|
|
20692
|
-
showRecent =
|
|
20693
|
-
userSearchParameters =
|
|
20694
|
-
getSearchPageURL =
|
|
20695
|
-
onSelect =
|
|
20696
|
-
|
|
20697
|
-
templates =
|
|
20698
|
-
|
|
20699
|
-
userCssClasses =
|
|
20700
|
-
placeholder =
|
|
20860
|
+
var _ref1 = widgetParams || {},
|
|
20861
|
+
container = _ref1.container,
|
|
20862
|
+
escapeHTML = _ref1.escapeHTML,
|
|
20863
|
+
_ref1$indices = _ref1.indices,
|
|
20864
|
+
indices = _ref1$indices === void 0 ? [] : _ref1$indices,
|
|
20865
|
+
showSuggestions = _ref1.showSuggestions,
|
|
20866
|
+
showRecent = _ref1.showRecent,
|
|
20867
|
+
userSearchParameters = _ref1.searchParameters,
|
|
20868
|
+
getSearchPageURL = _ref1.getSearchPageURL,
|
|
20869
|
+
onSelect = _ref1.onSelect,
|
|
20870
|
+
_ref1$templates = _ref1.templates,
|
|
20871
|
+
templates = _ref1$templates === void 0 ? {} : _ref1$templates,
|
|
20872
|
+
_ref1$cssClasses = _ref1.cssClasses,
|
|
20873
|
+
userCssClasses = _ref1$cssClasses === void 0 ? {} : _ref1$cssClasses,
|
|
20874
|
+
placeholder = _ref1.placeholder;
|
|
20701
20875
|
if (!container) {
|
|
20702
20876
|
throw new Error(withUsage$z('The `container` option is required.'));
|
|
20703
20877
|
}
|
|
@@ -20715,12 +20889,14 @@
|
|
|
20715
20889
|
indexName: showSuggestions.indexName,
|
|
20716
20890
|
templates: _objectSpread2({
|
|
20717
20891
|
// @ts-expect-error
|
|
20718
|
-
item: function item(
|
|
20719
|
-
var _item =
|
|
20720
|
-
onSelectItem =
|
|
20892
|
+
item: function item(_ref10) {
|
|
20893
|
+
var _item = _ref10.item,
|
|
20894
|
+
onSelectItem = _ref10.onSelect,
|
|
20895
|
+
onApply = _ref10.onApply;
|
|
20721
20896
|
return h(AutocompleteSuggestion, {
|
|
20722
20897
|
item: _item,
|
|
20723
|
-
onSelect: onSelectItem
|
|
20898
|
+
onSelect: onSelectItem,
|
|
20899
|
+
onApply: onApply
|
|
20724
20900
|
}, h(ConditionalReverseHighlight, {
|
|
20725
20901
|
item: _item
|
|
20726
20902
|
}));
|
|
@@ -20739,6 +20915,8 @@
|
|
|
20739
20915
|
});
|
|
20740
20916
|
}
|
|
20741
20917
|
var instanceId = ++autocompleteInstanceId;
|
|
20918
|
+
var shouldShowRecent = showRecent || undefined;
|
|
20919
|
+
var showRecentOptions = typeof shouldShowRecent === 'boolean' ? {} : shouldShowRecent;
|
|
20742
20920
|
var specializedRenderer = createRenderer({
|
|
20743
20921
|
instanceId: instanceId,
|
|
20744
20922
|
containerNode: containerNode,
|
|
@@ -20746,14 +20924,16 @@
|
|
|
20746
20924
|
getSearchPageURL: getSearchPageURL,
|
|
20747
20925
|
onSelect: onSelect,
|
|
20748
20926
|
cssClasses: cssClasses,
|
|
20749
|
-
showRecent:
|
|
20927
|
+
showRecent: showRecentOptions,
|
|
20750
20928
|
showSuggestions: showSuggestions,
|
|
20751
20929
|
placeholder: placeholder,
|
|
20752
20930
|
renderState: {
|
|
20753
20931
|
indexTemplateProps: [],
|
|
20754
20932
|
isolatedIndex: undefined,
|
|
20755
20933
|
targetIndex: undefined,
|
|
20756
|
-
templateProps: undefined
|
|
20934
|
+
templateProps: undefined,
|
|
20935
|
+
RecentSearchComponent: AutocompleteRecentSearch,
|
|
20936
|
+
recentSearchHeaderComponent: undefined
|
|
20757
20937
|
},
|
|
20758
20938
|
templates: templates
|
|
20759
20939
|
});
|
|
@@ -20765,9 +20945,9 @@
|
|
|
20765
20945
|
})({}), index({
|
|
20766
20946
|
indexId: "ais-autocomplete-".concat(instanceId),
|
|
20767
20947
|
EXPERIMENTAL_isolated: true
|
|
20768
|
-
}).addWidgets([configure(searchParameters)].concat(_toConsumableArray(indicesConfig.map(function (
|
|
20769
|
-
var indexName =
|
|
20770
|
-
indexSearchParameters =
|
|
20948
|
+
}).addWidgets([configure(searchParameters)].concat(_toConsumableArray(indicesConfig.map(function (_ref11) {
|
|
20949
|
+
var indexName = _ref11.indexName,
|
|
20950
|
+
indexSearchParameters = _ref11.searchParameters;
|
|
20771
20951
|
return index({
|
|
20772
20952
|
indexName: indexName,
|
|
20773
20953
|
indexId: indexName
|
|
@@ -20778,9 +20958,9 @@
|
|
|
20778
20958
|
$$widgetType: 'ais.autocomplete'
|
|
20779
20959
|
})]))];
|
|
20780
20960
|
}
|
|
20781
|
-
function ConditionalReverseHighlight(
|
|
20961
|
+
function ConditionalReverseHighlight(_ref12) {
|
|
20782
20962
|
var _item$_highlightResul;
|
|
20783
|
-
var item =
|
|
20963
|
+
var item = _ref12.item;
|
|
20784
20964
|
if (!((_item$_highlightResul = item._highlightResult) !== null && _item$_highlightResul !== void 0 && _item$_highlightResul.query) ||
|
|
20785
20965
|
// @ts-expect-error - we should not have matchLevel as arrays here
|
|
20786
20966
|
item._highlightResult.query.matchLevel === 'none') {
|