instantsearch.js 4.85.2 → 4.86.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/connectors/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 +7 -7
|
@@ -18,10 +18,33 @@ var withUsage = (0, _utils.createDocumentationMessageGenerator)({
|
|
|
18
18
|
|
|
19
19
|
/**
|
|
20
20
|
* The **SortBy** connector provides the logic to build a custom widget that will display a
|
|
21
|
-
* list of indices. With Algolia, this is most commonly used for changing
|
|
22
|
-
* a user to change how the hits are being sorted.
|
|
21
|
+
* list of indices or sorting strategies. With Algolia, this is most commonly used for changing
|
|
22
|
+
* ranking strategy. This allows a user to change how the hits are being sorted.
|
|
23
|
+
*
|
|
24
|
+
* This connector supports two sorting modes:
|
|
25
|
+
* 1. **Index-based (traditional)**: Uses the `value` property to switch between different indices.
|
|
26
|
+
* This is the standard behavior for non-composition setups.
|
|
27
|
+
*
|
|
28
|
+
* 2. **Strategy-based (composition mode)**: Uses the `strategy` property to apply sorting strategies
|
|
29
|
+
* via the `sortBy` search parameter. This is only available when using Algolia Compositions.
|
|
30
|
+
*
|
|
31
|
+
* Items can mix both types in the same widget, allowing for flexible sorting options.
|
|
23
32
|
*/
|
|
24
33
|
|
|
34
|
+
function isStrategyItem(item) {
|
|
35
|
+
return 'strategy' in item && item.strategy !== undefined;
|
|
36
|
+
}
|
|
37
|
+
function getItemValue(item) {
|
|
38
|
+
if (isStrategyItem(item)) {
|
|
39
|
+
return item.strategy;
|
|
40
|
+
}
|
|
41
|
+
return item.value;
|
|
42
|
+
}
|
|
43
|
+
function isValidStrategy(itemsLookup, value) {
|
|
44
|
+
if (!value) return false;
|
|
45
|
+
var item = itemsLookup[value];
|
|
46
|
+
return item !== undefined && isStrategyItem(item);
|
|
47
|
+
}
|
|
25
48
|
var connectSortBy = function connectSortBy(renderFn) {
|
|
26
49
|
var unmountFn = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _utils.noop;
|
|
27
50
|
(0, _utils.checkRendering)(renderFn, withUsage());
|
|
@@ -36,14 +59,38 @@ var connectSortBy = function connectSortBy(renderFn) {
|
|
|
36
59
|
if (!Array.isArray(items)) {
|
|
37
60
|
throw new Error(withUsage('The `items` option expects an array of objects.'));
|
|
38
61
|
}
|
|
62
|
+
var itemsLookup = {};
|
|
63
|
+
items.forEach(function (item, index) {
|
|
64
|
+
var hasValue = 'value' in item && item.value !== undefined;
|
|
65
|
+
var hasStrategy = 'strategy' in item && item.strategy !== undefined;
|
|
66
|
+
|
|
67
|
+
// Validate mutual exclusivity
|
|
68
|
+
if (hasValue && hasStrategy) {
|
|
69
|
+
throw new Error(withUsage("Item at index ".concat(index, " cannot have both \"value\" and \"strategy\" properties.")));
|
|
70
|
+
}
|
|
71
|
+
if (!hasValue && !hasStrategy) {
|
|
72
|
+
throw new Error(withUsage("Item at index ".concat(index, " must have either a \"value\" or \"strategy\" property.")));
|
|
73
|
+
}
|
|
74
|
+
var itemValue = getItemValue(item);
|
|
75
|
+
itemsLookup[itemValue] = item;
|
|
76
|
+
});
|
|
77
|
+
connectorState.itemsLookup = itemsLookup;
|
|
39
78
|
return {
|
|
40
79
|
$$type: 'ais.sortBy',
|
|
41
80
|
init: function init(initOptions) {
|
|
42
81
|
var instantSearchInstance = initOptions.instantSearchInstance;
|
|
82
|
+
|
|
83
|
+
// Check if strategies are used outside composition mode
|
|
84
|
+
var hasStrategyItems = items.some(function (item) {
|
|
85
|
+
return 'strategy' in item && item.strategy;
|
|
86
|
+
});
|
|
87
|
+
if (hasStrategyItems && !instantSearchInstance.compositionID) {
|
|
88
|
+
throw new Error(withUsage('Sorting strategies can only be used in composition mode. Please provide a "compositionID" to your InstantSearch instance.'));
|
|
89
|
+
}
|
|
43
90
|
var widgetRenderState = this.getWidgetRenderState(initOptions);
|
|
44
91
|
var currentIndex = widgetRenderState.currentRefinement;
|
|
45
92
|
var isCurrentIndexInItems = (0, _utils.find)(items, function (item) {
|
|
46
|
-
return item
|
|
93
|
+
return getItemValue(item) === currentIndex;
|
|
47
94
|
});
|
|
48
95
|
process.env.NODE_ENV === 'development' ? (0, _utils.warning)(isCurrentIndexInItems !== undefined, "The index named \"".concat(currentIndex, "\" is not listed in the `items` of `sortBy`.")) : void 0;
|
|
49
96
|
renderFn(_objectSpread(_objectSpread({}, widgetRenderState), {}, {
|
|
@@ -59,7 +106,17 @@ var connectSortBy = function connectSortBy(renderFn) {
|
|
|
59
106
|
dispose: function dispose(_ref2) {
|
|
60
107
|
var state = _ref2.state;
|
|
61
108
|
unmountFn();
|
|
62
|
-
|
|
109
|
+
|
|
110
|
+
// Clear sortBy parameter if it was set
|
|
111
|
+
if (connectorState.isUsingComposition && state.sortBy) {
|
|
112
|
+
state = state.setQueryParameter('sortBy', undefined);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// Restore initial index if changed
|
|
116
|
+
if (connectorState.initialValue && state.index !== connectorState.initialValue) {
|
|
117
|
+
return state.setIndex(connectorState.initialValue);
|
|
118
|
+
}
|
|
119
|
+
return state;
|
|
63
120
|
},
|
|
64
121
|
getRenderState: function getRenderState(renderState, renderOptions) {
|
|
65
122
|
return _objectSpread(_objectSpread({}, renderState), {}, {
|
|
@@ -70,22 +127,54 @@ var connectSortBy = function connectSortBy(renderFn) {
|
|
|
70
127
|
var results = _ref3.results,
|
|
71
128
|
helper = _ref3.helper,
|
|
72
129
|
state = _ref3.state,
|
|
73
|
-
parent = _ref3.parent
|
|
74
|
-
|
|
75
|
-
|
|
130
|
+
parent = _ref3.parent,
|
|
131
|
+
instantSearchInstance = _ref3.instantSearchInstance;
|
|
132
|
+
// Capture initial value (composition ID or main index)
|
|
133
|
+
if (!connectorState.initialValue && parent) {
|
|
134
|
+
connectorState.initialValue = parent.getIndexName();
|
|
76
135
|
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
136
|
+
|
|
137
|
+
// Create refine function if not exists
|
|
138
|
+
if (!connectorState.refine) {
|
|
139
|
+
// Cache composition mode status for lifecycle methods that don't have access to instantSearchInstance
|
|
140
|
+
connectorState.isUsingComposition = Boolean(instantSearchInstance === null || instantSearchInstance === void 0 ? void 0 : instantSearchInstance.compositionID);
|
|
141
|
+
connectorState.refine = function (value) {
|
|
142
|
+
// O(1) lookup using the items lookup table
|
|
143
|
+
var item = connectorState.itemsLookup[value];
|
|
144
|
+
if (item && isStrategyItem(item)) {
|
|
145
|
+
// Strategy-based: set sortBy parameter for composition API
|
|
146
|
+
// The composition backend will interpret this and apply the sorting strategy
|
|
147
|
+
helper.setQueryParameter('sortBy', item.strategy).search();
|
|
148
|
+
} else {
|
|
149
|
+
// Index-based: clear any existing sortBy parameter and switch to the new index
|
|
150
|
+
// Clearing sortBy is critical when transitioning from strategy to index-based sorting
|
|
151
|
+
helper.setQueryParameter('sortBy', undefined).setIndex(value).search();
|
|
152
|
+
}
|
|
80
153
|
};
|
|
81
154
|
}
|
|
155
|
+
|
|
156
|
+
// Transform items first (on original structure)
|
|
157
|
+
var transformedItems = transformItems(items, {
|
|
158
|
+
results: results
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
// Normalize items: all get a 'value' property for the render state
|
|
162
|
+
var normalizedItems = transformedItems.map(function (item) {
|
|
163
|
+
return {
|
|
164
|
+
label: item.label,
|
|
165
|
+
value: getItemValue(item)
|
|
166
|
+
};
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
// Determine current refinement
|
|
170
|
+
// In composition mode, prefer sortBy parameter if it corresponds to a valid strategy item
|
|
171
|
+
// Otherwise use the index (for index-based items or when no valid strategy is active)
|
|
172
|
+
var currentRefinement = connectorState.isUsingComposition && isValidStrategy(connectorState.itemsLookup, state.sortBy) ? state.sortBy : state.index;
|
|
82
173
|
var hasNoResults = results ? results.nbHits === 0 : true;
|
|
83
174
|
return {
|
|
84
|
-
currentRefinement:
|
|
85
|
-
options:
|
|
86
|
-
|
|
87
|
-
}),
|
|
88
|
-
refine: connectorState.setIndex,
|
|
175
|
+
currentRefinement: currentRefinement,
|
|
176
|
+
options: normalizedItems,
|
|
177
|
+
refine: connectorState.refine,
|
|
89
178
|
hasNoResults: hasNoResults,
|
|
90
179
|
canRefine: !hasNoResults && items.length > 0,
|
|
91
180
|
widgetParams: widgetParams
|
|
@@ -93,14 +182,25 @@ var connectSortBy = function connectSortBy(renderFn) {
|
|
|
93
182
|
},
|
|
94
183
|
getWidgetUiState: function getWidgetUiState(uiState, _ref4) {
|
|
95
184
|
var searchParameters = _ref4.searchParameters;
|
|
96
|
-
|
|
185
|
+
// In composition mode with an active strategy, use sortBy parameter
|
|
186
|
+
// Otherwise use index-based behavior (traditional mode)
|
|
187
|
+
var currentValue = connectorState.isUsingComposition && isValidStrategy(connectorState.itemsLookup, searchParameters.sortBy) ? searchParameters.sortBy : searchParameters.index;
|
|
97
188
|
return _objectSpread(_objectSpread({}, uiState), {}, {
|
|
98
|
-
sortBy:
|
|
189
|
+
sortBy: currentValue !== connectorState.initialValue ? currentValue : undefined
|
|
99
190
|
});
|
|
100
191
|
},
|
|
101
192
|
getWidgetSearchParameters: function getWidgetSearchParameters(searchParameters, _ref5) {
|
|
102
193
|
var uiState = _ref5.uiState;
|
|
103
|
-
|
|
194
|
+
var sortByValue = uiState.sortBy || connectorState.initialValue || searchParameters.index;
|
|
195
|
+
if (isValidStrategy(connectorState.itemsLookup, sortByValue)) {
|
|
196
|
+
var item = connectorState.itemsLookup[sortByValue];
|
|
197
|
+
// Strategy-based: set the sortBy parameter for composition API
|
|
198
|
+
// The index remains as the compositionID
|
|
199
|
+
return searchParameters.setQueryParameter('sortBy', item.strategy);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
// Index-based: set the index parameter (traditional behavior)
|
|
203
|
+
return searchParameters.setQueryParameter('index', sortByValue);
|
|
104
204
|
}
|
|
105
205
|
};
|
|
106
206
|
};
|
package/cjs/lib/version.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
3
4
|
Object.defineProperty(exports, "__esModule", {
|
|
4
5
|
value: true
|
|
5
6
|
});
|
|
@@ -23,7 +24,6 @@ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r)
|
|
|
23
24
|
function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
|
|
24
25
|
function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
|
|
25
26
|
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
26
|
-
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
27
27
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
28
28
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
29
29
|
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
@@ -80,6 +80,7 @@ var createRenderer = function createRenderer(params) {
|
|
|
80
80
|
return function (connectorParams, isFirstRendering) {
|
|
81
81
|
if (isFirstRendering) {
|
|
82
82
|
var _targetIndex$getHelpe, _targetIndex$getHelpe2;
|
|
83
|
+
var showRecentObj = rendererParams.showRecent;
|
|
83
84
|
var isolatedIndex = connectorParams.instantSearchInstance.mainIndex;
|
|
84
85
|
var targetIndex = connectorParams.instantSearchInstance.mainIndex;
|
|
85
86
|
(0, _utils.walkIndex)(targetIndex, function (childIndex) {
|
|
@@ -88,6 +89,56 @@ var createRenderer = function createRenderer(params) {
|
|
|
88
89
|
targetIndex = childIndex.parent;
|
|
89
90
|
}
|
|
90
91
|
});
|
|
92
|
+
var RecentSearchComponent = function RecentSearchComponent(_ref) {
|
|
93
|
+
var item = _ref.item,
|
|
94
|
+
onSelect = _ref.onSelect,
|
|
95
|
+
onApply = _ref.onApply,
|
|
96
|
+
onRemoveRecentSearch = _ref.onRemoveRecentSearch;
|
|
97
|
+
return (0, _preact.h)(AutocompleteRecentSearch, {
|
|
98
|
+
item: item,
|
|
99
|
+
onSelect: onSelect,
|
|
100
|
+
onApply: onApply,
|
|
101
|
+
onRemoveRecentSearch: onRemoveRecentSearch
|
|
102
|
+
}, (0, _preact.h)(ConditionalReverseHighlight, {
|
|
103
|
+
item: item
|
|
104
|
+
}));
|
|
105
|
+
};
|
|
106
|
+
var recentSearchHeaderComponent = undefined;
|
|
107
|
+
if (showRecentObj && showRecentObj.templates) {
|
|
108
|
+
var recentTemplateProps = (0, _templating.prepareTemplateProps)({
|
|
109
|
+
defaultTemplates: {},
|
|
110
|
+
templatesConfig: connectorParams.instantSearchInstance.templatesConfig,
|
|
111
|
+
templates: showRecentObj.templates
|
|
112
|
+
});
|
|
113
|
+
if (showRecentObj.templates.item) {
|
|
114
|
+
RecentSearchComponent = function RecentSearchComponent(_ref2) {
|
|
115
|
+
var item = _ref2.item,
|
|
116
|
+
onSelect = _ref2.onSelect,
|
|
117
|
+
onRemoveRecentSearch = _ref2.onRemoveRecentSearch;
|
|
118
|
+
return (0, _preact.h)(_Template.default, _extends({}, recentTemplateProps, {
|
|
119
|
+
templateKey: "item",
|
|
120
|
+
rootTagName: "fragment",
|
|
121
|
+
data: {
|
|
122
|
+
item: item,
|
|
123
|
+
onSelect: onSelect,
|
|
124
|
+
onRemoveRecentSearch: onRemoveRecentSearch
|
|
125
|
+
}
|
|
126
|
+
}));
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
if (showRecentObj.templates.header) {
|
|
130
|
+
recentSearchHeaderComponent = function recentSearchHeaderComponent(_ref3) {
|
|
131
|
+
var items = _ref3.items;
|
|
132
|
+
return (0, _preact.h)(_Template.default, _extends({}, recentTemplateProps, {
|
|
133
|
+
templateKey: "header",
|
|
134
|
+
rootTagName: "fragment",
|
|
135
|
+
data: {
|
|
136
|
+
items: items
|
|
137
|
+
}
|
|
138
|
+
}));
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
}
|
|
91
142
|
rendererParams.renderState = {
|
|
92
143
|
indexTemplateProps: [],
|
|
93
144
|
isolatedIndex: isolatedIndex,
|
|
@@ -96,7 +147,9 @@ var createRenderer = function createRenderer(params) {
|
|
|
96
147
|
defaultTemplates: {},
|
|
97
148
|
templatesConfig: connectorParams.instantSearchInstance.templatesConfig,
|
|
98
149
|
templates: rendererParams.templates
|
|
99
|
-
})
|
|
150
|
+
}),
|
|
151
|
+
RecentSearchComponent: RecentSearchComponent,
|
|
152
|
+
recentSearchHeaderComponent: recentSearchHeaderComponent
|
|
100
153
|
};
|
|
101
154
|
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 : '');
|
|
102
155
|
return;
|
|
@@ -104,20 +157,20 @@ var createRenderer = function createRenderer(params) {
|
|
|
104
157
|
(0, _preact.render)((0, _preact.h)(AutocompleteWrapper, _extends({}, rendererParams, connectorParams)), containerNode);
|
|
105
158
|
};
|
|
106
159
|
};
|
|
107
|
-
function AutocompleteWrapper(
|
|
108
|
-
var _isolatedIndex$getHel,
|
|
109
|
-
var indicesConfig =
|
|
110
|
-
indices =
|
|
111
|
-
getSearchPageURL =
|
|
112
|
-
userOnSelect =
|
|
113
|
-
refineAutocomplete =
|
|
114
|
-
cssClasses =
|
|
115
|
-
renderState =
|
|
116
|
-
instantSearchInstance =
|
|
117
|
-
showRecent =
|
|
118
|
-
showSuggestions =
|
|
119
|
-
templates =
|
|
120
|
-
placeholder =
|
|
160
|
+
function AutocompleteWrapper(_ref4) {
|
|
161
|
+
var _isolatedIndex$getHel, _showRecentObj$cssCla, _showRecentObj$cssCla2, _showRecentObj$cssCla3, _showRecentObj$cssCla4, _targetIndex$getWidge;
|
|
162
|
+
var indicesConfig = _ref4.indicesConfig,
|
|
163
|
+
indices = _ref4.indices,
|
|
164
|
+
getSearchPageURL = _ref4.getSearchPageURL,
|
|
165
|
+
userOnSelect = _ref4.onSelect,
|
|
166
|
+
refineAutocomplete = _ref4.refine,
|
|
167
|
+
cssClasses = _ref4.cssClasses,
|
|
168
|
+
renderState = _ref4.renderState,
|
|
169
|
+
instantSearchInstance = _ref4.instantSearchInstance,
|
|
170
|
+
showRecent = _ref4.showRecent,
|
|
171
|
+
showSuggestions = _ref4.showSuggestions,
|
|
172
|
+
templates = _ref4.templates,
|
|
173
|
+
placeholder = _ref4.placeholder;
|
|
121
174
|
var isolatedIndex = renderState.isolatedIndex,
|
|
122
175
|
targetIndex = renderState.targetIndex;
|
|
123
176
|
var searchboxQuery = isolatedIndex === null || isolatedIndex === void 0 ? void 0 : (_isolatedIndex$getHel = isolatedIndex.getHelper()) === null || _isolatedIndex$getHel === void 0 ? void 0 : _isolatedIndex$getHel.state.query;
|
|
@@ -131,8 +184,15 @@ function AutocompleteWrapper(_ref) {
|
|
|
131
184
|
storageHits = _useStorage.storageHits,
|
|
132
185
|
indicesConfigForPropGetters = _useStorage.indicesConfigForPropGetters,
|
|
133
186
|
indicesForPropGetters = _useStorage.indicesForPropGetters;
|
|
134
|
-
var
|
|
135
|
-
|
|
187
|
+
var showRecentObj = showRecent;
|
|
188
|
+
var recentSearchCssClasses = {
|
|
189
|
+
root: (0, _instantsearchUiComponents.cx)('ais-AutocompleteRecentSearches', showRecentObj === null || showRecentObj === void 0 ? void 0 : (_showRecentObj$cssCla = showRecentObj.cssClasses) === null || _showRecentObj$cssCla === void 0 ? void 0 : _showRecentObj$cssCla.root),
|
|
190
|
+
list: (0, _instantsearchUiComponents.cx)('ais-AutocompleteRecentSearchesList', showRecentObj === null || showRecentObj === void 0 ? void 0 : (_showRecentObj$cssCla2 = showRecentObj.cssClasses) === null || _showRecentObj$cssCla2 === void 0 ? void 0 : _showRecentObj$cssCla2.list),
|
|
191
|
+
header: (0, _instantsearchUiComponents.cx)('ais-AutocompleteRecentSearchesHeader', showRecentObj === null || showRecentObj === void 0 ? void 0 : (_showRecentObj$cssCla3 = showRecentObj.cssClasses) === null || _showRecentObj$cssCla3 === void 0 ? void 0 : _showRecentObj$cssCla3.header),
|
|
192
|
+
item: (0, _instantsearchUiComponents.cx)('ais-AutocompleteRecentSearchesItem', showRecentObj === null || showRecentObj === void 0 ? void 0 : (_showRecentObj$cssCla4 = showRecentObj.cssClasses) === null || _showRecentObj$cssCla4 === void 0 ? void 0 : _showRecentObj$cssCla4.item)
|
|
193
|
+
};
|
|
194
|
+
var isSearchPage = (_targetIndex$getWidge = targetIndex === null || targetIndex === void 0 ? void 0 : targetIndex.getWidgets().some(function (_ref5) {
|
|
195
|
+
var $$type = _ref5.$$type;
|
|
136
196
|
return ['ais.hits', 'ais.infiniteHits'].includes($$type);
|
|
137
197
|
})) !== null && _targetIndex$getWidge !== void 0 ? _targetIndex$getWidge : false;
|
|
138
198
|
var onRefine = function onRefine(query) {
|
|
@@ -151,10 +211,10 @@ function AutocompleteWrapper(_ref) {
|
|
|
151
211
|
indices: indicesForPropGetters,
|
|
152
212
|
indicesConfig: indicesConfigForPropGetters,
|
|
153
213
|
onRefine: onRefine,
|
|
154
|
-
onSelect: userOnSelect !== null && userOnSelect !== void 0 ? userOnSelect : function (
|
|
155
|
-
var query =
|
|
156
|
-
setQuery =
|
|
157
|
-
url =
|
|
214
|
+
onSelect: userOnSelect !== null && userOnSelect !== void 0 ? userOnSelect : function (_ref6) {
|
|
215
|
+
var query = _ref6.query,
|
|
216
|
+
setQuery = _ref6.setQuery,
|
|
217
|
+
url = _ref6.url;
|
|
158
218
|
if (url) {
|
|
159
219
|
window.location.href = url;
|
|
160
220
|
return;
|
|
@@ -168,75 +228,44 @@ function AutocompleteWrapper(_ref) {
|
|
|
168
228
|
}
|
|
169
229
|
setQuery(query);
|
|
170
230
|
},
|
|
231
|
+
onApply: function onApply(query) {
|
|
232
|
+
refineAutocomplete(query);
|
|
233
|
+
},
|
|
171
234
|
placeholder: placeholder
|
|
172
235
|
}),
|
|
173
236
|
getInputProps = _usePropGetters.getInputProps,
|
|
174
237
|
getItemProps = _usePropGetters.getItemProps,
|
|
175
238
|
getPanelProps = _usePropGetters.getPanelProps,
|
|
176
239
|
getRootProps = _usePropGetters.getRootProps;
|
|
177
|
-
var AutocompleteRecentSearchComponent = function AutocompleteRecentSearchComponent(_ref4) {
|
|
178
|
-
var item = _ref4.item,
|
|
179
|
-
onSelect = _ref4.onSelect,
|
|
180
|
-
onRemoveRecentSearch = _ref4.onRemoveRecentSearch;
|
|
181
|
-
return (0, _preact.h)(AutocompleteRecentSearch, {
|
|
182
|
-
item: item,
|
|
183
|
-
onSelect: onSelect,
|
|
184
|
-
onRemoveRecentSearch: onRemoveRecentSearch
|
|
185
|
-
}, (0, _preact.h)(ConditionalReverseHighlight, {
|
|
186
|
-
item: item
|
|
187
|
-
}));
|
|
188
|
-
};
|
|
189
|
-
if (_typeof(showRecent) === 'object' && (_showRecent$templates = showRecent.templates) !== null && _showRecent$templates !== void 0 && _showRecent$templates.item) {
|
|
190
|
-
var props = (0, _templating.prepareTemplateProps)({
|
|
191
|
-
defaultTemplates: {},
|
|
192
|
-
templatesConfig: instantSearchInstance.templatesConfig,
|
|
193
|
-
templates: showRecent.templates
|
|
194
|
-
});
|
|
195
|
-
AutocompleteRecentSearchComponent = function AutocompleteRecentSearchComponent(_ref5) {
|
|
196
|
-
var item = _ref5.item,
|
|
197
|
-
onSelect = _ref5.onSelect,
|
|
198
|
-
onRemoveRecentSearch = _ref5.onRemoveRecentSearch;
|
|
199
|
-
return (0, _preact.h)(_Template.default, _extends({}, props, {
|
|
200
|
-
templateKey: "item",
|
|
201
|
-
rootTagName: "fragment",
|
|
202
|
-
data: {
|
|
203
|
-
item: item,
|
|
204
|
-
onSelect: onSelect,
|
|
205
|
-
onRemoveRecentSearch: onRemoveRecentSearch
|
|
206
|
-
}
|
|
207
|
-
}));
|
|
208
|
-
};
|
|
209
|
-
}
|
|
210
240
|
var elements = {};
|
|
211
241
|
if (showRecent) {
|
|
212
|
-
elements.recent = (0, _preact.h)(AutocompleteIndex
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
242
|
+
elements.recent = (0, _preact.h)(AutocompleteIndex, {
|
|
243
|
+
HeaderComponent: renderState.recentSearchHeaderComponent
|
|
244
|
+
// @ts-ignore - there seems to be problems with React.ComponentType and this, but it's actually correct
|
|
245
|
+
,
|
|
246
|
+
ItemComponent: function ItemComponent(_ref7) {
|
|
247
|
+
var item = _ref7.item,
|
|
248
|
+
onSelect = _ref7.onSelect,
|
|
249
|
+
onApply = _ref7.onApply;
|
|
250
|
+
return (0, _preact.h)(renderState.RecentSearchComponent, {
|
|
219
251
|
item: item,
|
|
220
252
|
onSelect: onSelect,
|
|
253
|
+
onApply: onApply,
|
|
221
254
|
onRemoveRecentSearch: function onRemoveRecentSearch() {
|
|
222
255
|
return storage.onRemove(item.query);
|
|
223
256
|
}
|
|
224
257
|
});
|
|
225
258
|
},
|
|
226
|
-
classNames:
|
|
227
|
-
root: 'ais-AutocompleteRecentSearches',
|
|
228
|
-
list: 'ais-AutocompleteRecentSearchesList',
|
|
229
|
-
item: 'ais-AutocompleteRecentSearchesItem'
|
|
230
|
-
},
|
|
259
|
+
classNames: recentSearchCssClasses,
|
|
231
260
|
items: storageHits,
|
|
232
261
|
getItemProps: getItemProps
|
|
233
262
|
});
|
|
234
263
|
}
|
|
235
|
-
indices.forEach(function (
|
|
264
|
+
indices.forEach(function (_ref8, i) {
|
|
236
265
|
var _indicesConfig$i$temp;
|
|
237
|
-
var indexId =
|
|
238
|
-
indexName =
|
|
239
|
-
hits =
|
|
266
|
+
var indexId = _ref8.indexId,
|
|
267
|
+
indexName = _ref8.indexName,
|
|
268
|
+
hits = _ref8.hits;
|
|
240
269
|
if (!renderState.indexTemplateProps[i]) {
|
|
241
270
|
renderState.indexTemplateProps[i] = (0, _templating.prepareTemplateProps)({
|
|
242
271
|
defaultTemplates: {},
|
|
@@ -244,8 +273,8 @@ function AutocompleteWrapper(_ref) {
|
|
|
244
273
|
templates: indicesConfig[i].templates
|
|
245
274
|
});
|
|
246
275
|
}
|
|
247
|
-
var headerComponent = (_indicesConfig$i$temp = indicesConfig[i].templates) !== null && _indicesConfig$i$temp !== void 0 && _indicesConfig$i$temp.header ? function (
|
|
248
|
-
var items =
|
|
276
|
+
var headerComponent = (_indicesConfig$i$temp = indicesConfig[i].templates) !== null && _indicesConfig$i$temp !== void 0 && _indicesConfig$i$temp.header ? function (_ref9) {
|
|
277
|
+
var items = _ref9.items;
|
|
249
278
|
return (0, _preact.h)(_Template.default, _extends({}, renderState.indexTemplateProps[i], {
|
|
250
279
|
templateKey: "header",
|
|
251
280
|
rootTagName: "fragment",
|
|
@@ -254,15 +283,17 @@ function AutocompleteWrapper(_ref) {
|
|
|
254
283
|
}
|
|
255
284
|
}));
|
|
256
285
|
} : undefined;
|
|
257
|
-
var itemComponent = function itemComponent(
|
|
258
|
-
var item =
|
|
259
|
-
onSelect =
|
|
286
|
+
var itemComponent = function itemComponent(_ref0) {
|
|
287
|
+
var item = _ref0.item,
|
|
288
|
+
onSelect = _ref0.onSelect,
|
|
289
|
+
onApply = _ref0.onApply;
|
|
260
290
|
return (0, _preact.h)(_Template.default, _extends({}, renderState.indexTemplateProps[i], {
|
|
261
291
|
templateKey: "item",
|
|
262
292
|
rootTagName: "fragment",
|
|
263
293
|
data: {
|
|
264
294
|
item: item,
|
|
265
|
-
onSelect: onSelect
|
|
295
|
+
onSelect: onSelect,
|
|
296
|
+
onApply: onApply
|
|
266
297
|
}
|
|
267
298
|
}));
|
|
268
299
|
};
|
|
@@ -310,21 +341,21 @@ function AutocompleteWrapper(_ref) {
|
|
|
310
341
|
})));
|
|
311
342
|
}
|
|
312
343
|
function EXPERIMENTAL_autocomplete(widgetParams) {
|
|
313
|
-
var
|
|
314
|
-
container =
|
|
315
|
-
escapeHTML =
|
|
316
|
-
|
|
317
|
-
indices =
|
|
318
|
-
showSuggestions =
|
|
319
|
-
showRecent =
|
|
320
|
-
userSearchParameters =
|
|
321
|
-
getSearchPageURL =
|
|
322
|
-
onSelect =
|
|
323
|
-
|
|
324
|
-
templates =
|
|
325
|
-
|
|
326
|
-
userCssClasses =
|
|
327
|
-
placeholder =
|
|
344
|
+
var _ref1 = widgetParams || {},
|
|
345
|
+
container = _ref1.container,
|
|
346
|
+
escapeHTML = _ref1.escapeHTML,
|
|
347
|
+
_ref1$indices = _ref1.indices,
|
|
348
|
+
indices = _ref1$indices === void 0 ? [] : _ref1$indices,
|
|
349
|
+
showSuggestions = _ref1.showSuggestions,
|
|
350
|
+
showRecent = _ref1.showRecent,
|
|
351
|
+
userSearchParameters = _ref1.searchParameters,
|
|
352
|
+
getSearchPageURL = _ref1.getSearchPageURL,
|
|
353
|
+
onSelect = _ref1.onSelect,
|
|
354
|
+
_ref1$templates = _ref1.templates,
|
|
355
|
+
templates = _ref1$templates === void 0 ? {} : _ref1$templates,
|
|
356
|
+
_ref1$cssClasses = _ref1.cssClasses,
|
|
357
|
+
userCssClasses = _ref1$cssClasses === void 0 ? {} : _ref1$cssClasses,
|
|
358
|
+
placeholder = _ref1.placeholder;
|
|
328
359
|
if (!container) {
|
|
329
360
|
throw new Error(withUsage('The `container` option is required.'));
|
|
330
361
|
}
|
|
@@ -342,12 +373,14 @@ function EXPERIMENTAL_autocomplete(widgetParams) {
|
|
|
342
373
|
indexName: showSuggestions.indexName,
|
|
343
374
|
templates: _objectSpread({
|
|
344
375
|
// @ts-expect-error
|
|
345
|
-
item: function item(
|
|
346
|
-
var _item =
|
|
347
|
-
onSelectItem =
|
|
376
|
+
item: function item(_ref10) {
|
|
377
|
+
var _item = _ref10.item,
|
|
378
|
+
onSelectItem = _ref10.onSelect,
|
|
379
|
+
onApply = _ref10.onApply;
|
|
348
380
|
return (0, _preact.h)(AutocompleteSuggestion, {
|
|
349
381
|
item: _item,
|
|
350
|
-
onSelect: onSelectItem
|
|
382
|
+
onSelect: onSelectItem,
|
|
383
|
+
onApply: onApply
|
|
351
384
|
}, (0, _preact.h)(ConditionalReverseHighlight, {
|
|
352
385
|
item: _item
|
|
353
386
|
}));
|
|
@@ -366,6 +399,8 @@ function EXPERIMENTAL_autocomplete(widgetParams) {
|
|
|
366
399
|
});
|
|
367
400
|
}
|
|
368
401
|
var instanceId = ++autocompleteInstanceId;
|
|
402
|
+
var shouldShowRecent = showRecent || undefined;
|
|
403
|
+
var showRecentOptions = typeof shouldShowRecent === 'boolean' ? {} : shouldShowRecent;
|
|
369
404
|
var specializedRenderer = createRenderer({
|
|
370
405
|
instanceId: instanceId,
|
|
371
406
|
containerNode: containerNode,
|
|
@@ -373,14 +408,16 @@ function EXPERIMENTAL_autocomplete(widgetParams) {
|
|
|
373
408
|
getSearchPageURL: getSearchPageURL,
|
|
374
409
|
onSelect: onSelect,
|
|
375
410
|
cssClasses: cssClasses,
|
|
376
|
-
showRecent:
|
|
411
|
+
showRecent: showRecentOptions,
|
|
377
412
|
showSuggestions: showSuggestions,
|
|
378
413
|
placeholder: placeholder,
|
|
379
414
|
renderState: {
|
|
380
415
|
indexTemplateProps: [],
|
|
381
416
|
isolatedIndex: undefined,
|
|
382
417
|
targetIndex: undefined,
|
|
383
|
-
templateProps: undefined
|
|
418
|
+
templateProps: undefined,
|
|
419
|
+
RecentSearchComponent: AutocompleteRecentSearch,
|
|
420
|
+
recentSearchHeaderComponent: undefined
|
|
384
421
|
},
|
|
385
422
|
templates: templates
|
|
386
423
|
});
|
|
@@ -392,9 +429,9 @@ function EXPERIMENTAL_autocomplete(widgetParams) {
|
|
|
392
429
|
})({}), (0, _index2.default)({
|
|
393
430
|
indexId: "ais-autocomplete-".concat(instanceId),
|
|
394
431
|
EXPERIMENTAL_isolated: true
|
|
395
|
-
}).addWidgets([(0, _configure.default)(searchParameters)].concat(_toConsumableArray(indicesConfig.map(function (
|
|
396
|
-
var indexName =
|
|
397
|
-
indexSearchParameters =
|
|
432
|
+
}).addWidgets([(0, _configure.default)(searchParameters)].concat(_toConsumableArray(indicesConfig.map(function (_ref11) {
|
|
433
|
+
var indexName = _ref11.indexName,
|
|
434
|
+
indexSearchParameters = _ref11.searchParameters;
|
|
398
435
|
return (0, _index2.default)({
|
|
399
436
|
indexName: indexName,
|
|
400
437
|
indexId: indexName
|
|
@@ -405,9 +442,9 @@ function EXPERIMENTAL_autocomplete(widgetParams) {
|
|
|
405
442
|
$$widgetType: 'ais.autocomplete'
|
|
406
443
|
})]))];
|
|
407
444
|
}
|
|
408
|
-
function ConditionalReverseHighlight(
|
|
445
|
+
function ConditionalReverseHighlight(_ref12) {
|
|
409
446
|
var _item$_highlightResul;
|
|
410
|
-
var item =
|
|
447
|
+
var item = _ref12.item;
|
|
411
448
|
if (!((_item$_highlightResul = item._highlightResult) !== null && _item$_highlightResul !== void 0 && _item$_highlightResul.query) ||
|
|
412
449
|
// @ts-expect-error - we should not have matchLevel as arrays here
|
|
413
450
|
item._highlightResult.query.matchLevel === 'none') {
|