@algolia/autocomplete-js 1.7.3 → 1.8.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/dist/esm/autocomplete.js +2 -1
- package/dist/esm/elements/Input.js +1 -1
- package/dist/esm/render.d.ts +1 -0
- package/dist/esm/render.js +2 -0
- package/dist/umd/index.development.js +103 -53
- package/dist/umd/index.development.js.map +1 -1
- package/dist/umd/index.production.js +2 -2
- package/dist/umd/index.production.js.map +1 -1
- package/package.json +6 -6
package/dist/esm/autocomplete.js
CHANGED
|
@@ -99,7 +99,8 @@ export function autocomplete(options) {
|
|
|
99
99
|
setIsOpen: autocomplete.value.setIsOpen,
|
|
100
100
|
setStatus: autocomplete.value.setStatus,
|
|
101
101
|
setContext: autocomplete.value.setContext,
|
|
102
|
-
refresh: autocomplete.value.refresh
|
|
102
|
+
refresh: autocomplete.value.refresh,
|
|
103
|
+
navigator: autocomplete.value.navigator
|
|
103
104
|
};
|
|
104
105
|
var html = reactive(function () {
|
|
105
106
|
return htm.bind(props.value.renderer.renderer.createElement);
|
|
@@ -33,7 +33,7 @@ export var Input = function Input(_ref) {
|
|
|
33
33
|
}, autocompleteScopeApi));
|
|
34
34
|
setProperties(element, _objectSpread(_objectSpread({}, inputProps), {}, {
|
|
35
35
|
onKeyDown: function onKeyDown(event) {
|
|
36
|
-
// In detached mode we don't want to close the panel when
|
|
36
|
+
// In detached mode we don't want to close the panel when hitting `Tab`.
|
|
37
37
|
if (isDetached && event.key === 'Tab') {
|
|
38
38
|
return;
|
|
39
39
|
}
|
package/dist/esm/render.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/** @jsxRuntime classic */
|
|
1
2
|
/** @jsx renderer.createElement */
|
|
2
3
|
import { AutocompleteApi as AutocompleteCoreApi, AutocompleteScopeApi, BaseItem } from '@algolia/autocomplete-core';
|
|
3
4
|
import { AutocompleteClassNames, AutocompleteComponents, AutocompleteDom, AutocompletePropGetters, AutocompleteRender, AutocompleteRenderer, AutocompleteState, HTMLTemplate } from './types';
|
package/dist/esm/render.js
CHANGED
|
@@ -6,6 +6,8 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
|
6
6
|
|
|
7
7
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
8
8
|
|
|
9
|
+
/** @jsxRuntime classic */
|
|
10
|
+
|
|
9
11
|
/** @jsx renderer.createElement */
|
|
10
12
|
import { setProperties, setPropertiesWithoutEvents } from './utils';
|
|
11
13
|
export function renderSearchBox(_ref) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! @algolia/autocomplete-js 1.
|
|
1
|
+
/*! @algolia/autocomplete-js 1.8.0 | MIT License | © Algolia, Inc. and contributors | https://github.com/algolia/autocomplete */
|
|
2
2
|
(function (global, factory) {
|
|
3
3
|
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
|
|
4
4
|
typeof define === 'function' && define.amd ? define(['exports'], factory) :
|
|
@@ -353,7 +353,7 @@
|
|
|
353
353
|
|
|
354
354
|
var noop = function noop() {};
|
|
355
355
|
|
|
356
|
-
var version = '1.
|
|
356
|
+
var version = '1.8.0';
|
|
357
357
|
|
|
358
358
|
var userAgents$1 = [{
|
|
359
359
|
segment: 'autocomplete-core',
|
|
@@ -605,8 +605,7 @@
|
|
|
605
605
|
}
|
|
606
606
|
|
|
607
607
|
seenSourceIds.push(source.sourceId);
|
|
608
|
-
|
|
609
|
-
var normalizedSource = _objectSpread$f({
|
|
608
|
+
var defaultSource = {
|
|
610
609
|
getItemInputValue: function getItemInputValue(_ref) {
|
|
611
610
|
var state = _ref.state;
|
|
612
611
|
return state.query;
|
|
@@ -618,8 +617,14 @@
|
|
|
618
617
|
var setIsOpen = _ref2.setIsOpen;
|
|
619
618
|
setIsOpen(false);
|
|
620
619
|
},
|
|
621
|
-
onActive: noop
|
|
622
|
-
|
|
620
|
+
onActive: noop,
|
|
621
|
+
onResolve: noop
|
|
622
|
+
};
|
|
623
|
+
Object.keys(defaultSource).forEach(function (key) {
|
|
624
|
+
defaultSource[key].__default = true;
|
|
625
|
+
});
|
|
626
|
+
|
|
627
|
+
var normalizedSource = _objectSpread$f(_objectSpread$f({}, defaultSource), source);
|
|
623
628
|
|
|
624
629
|
return Promise.resolve(normalizedSource);
|
|
625
630
|
}));
|
|
@@ -1122,6 +1127,14 @@
|
|
|
1122
1127
|
|
|
1123
1128
|
return (_x$onActive = x.onActive) === null || _x$onActive === void 0 ? void 0 : _x$onActive.call(x, params);
|
|
1124
1129
|
});
|
|
1130
|
+
},
|
|
1131
|
+
onResolve: function onResolve(params) {
|
|
1132
|
+
source.onResolve(params);
|
|
1133
|
+
pluginSubscribers.forEach(function (x) {
|
|
1134
|
+
var _x$onResolve;
|
|
1135
|
+
|
|
1136
|
+
return (_x$onResolve = x.onResolve) === null || _x$onResolve === void 0 ? void 0 : _x$onResolve.call(x, params);
|
|
1137
|
+
});
|
|
1125
1138
|
}
|
|
1126
1139
|
});
|
|
1127
1140
|
});
|
|
@@ -1191,7 +1204,7 @@
|
|
|
1191
1204
|
state = _ref.state; // Sources are grouped by `sourceId` to conveniently pick them via destructuring.
|
|
1192
1205
|
// Example: `const { recentSearchesPlugin } = sourcesBySourceId`
|
|
1193
1206
|
|
|
1194
|
-
var
|
|
1207
|
+
var originalSourcesBySourceId = collections.reduce(function (acc, collection) {
|
|
1195
1208
|
return _objectSpread$a(_objectSpread$a({}, acc), {}, _defineProperty$a({}, collection.source.sourceId, _objectSpread$a(_objectSpread$a({}, collection.source), {}, {
|
|
1196
1209
|
getItems: function getItems() {
|
|
1197
1210
|
// We provide the resolved items from the collection to the `reshape` prop.
|
|
@@ -1199,9 +1212,22 @@
|
|
|
1199
1212
|
}
|
|
1200
1213
|
})));
|
|
1201
1214
|
}, {});
|
|
1215
|
+
|
|
1216
|
+
var _props$plugins$reduce = props.plugins.reduce(function (acc, plugin) {
|
|
1217
|
+
if (plugin.reshape) {
|
|
1218
|
+
return plugin.reshape(acc);
|
|
1219
|
+
}
|
|
1220
|
+
|
|
1221
|
+
return acc;
|
|
1222
|
+
}, {
|
|
1223
|
+
sourcesBySourceId: originalSourcesBySourceId,
|
|
1224
|
+
state: state
|
|
1225
|
+
}),
|
|
1226
|
+
sourcesBySourceId = _props$plugins$reduce.sourcesBySourceId;
|
|
1227
|
+
|
|
1202
1228
|
var reshapeSources = props.reshape({
|
|
1203
|
-
sources: Object.values(sourcesBySourceId),
|
|
1204
1229
|
sourcesBySourceId: sourcesBySourceId,
|
|
1230
|
+
sources: Object.values(sourcesBySourceId),
|
|
1205
1231
|
state: state
|
|
1206
1232
|
}); // We reconstruct the collections with the items modified by the `reshape` prop.
|
|
1207
1233
|
|
|
@@ -1223,41 +1249,6 @@
|
|
|
1223
1249
|
}, _typeof(obj);
|
|
1224
1250
|
}
|
|
1225
1251
|
|
|
1226
|
-
function _toConsumableArray$3(arr) {
|
|
1227
|
-
return _arrayWithoutHoles$3(arr) || _iterableToArray$3(arr) || _unsupportedIterableToArray$3(arr) || _nonIterableSpread$3();
|
|
1228
|
-
}
|
|
1229
|
-
|
|
1230
|
-
function _nonIterableSpread$3() {
|
|
1231
|
-
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
1232
|
-
}
|
|
1233
|
-
|
|
1234
|
-
function _unsupportedIterableToArray$3(o, minLen) {
|
|
1235
|
-
if (!o) return;
|
|
1236
|
-
if (typeof o === "string") return _arrayLikeToArray$3(o, minLen);
|
|
1237
|
-
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
1238
|
-
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
1239
|
-
if (n === "Map" || n === "Set") return Array.from(o);
|
|
1240
|
-
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray$3(o, minLen);
|
|
1241
|
-
}
|
|
1242
|
-
|
|
1243
|
-
function _iterableToArray$3(iter) {
|
|
1244
|
-
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
|
|
1245
|
-
}
|
|
1246
|
-
|
|
1247
|
-
function _arrayWithoutHoles$3(arr) {
|
|
1248
|
-
if (Array.isArray(arr)) return _arrayLikeToArray$3(arr);
|
|
1249
|
-
}
|
|
1250
|
-
|
|
1251
|
-
function _arrayLikeToArray$3(arr, len) {
|
|
1252
|
-
if (len == null || len > arr.length) len = arr.length;
|
|
1253
|
-
|
|
1254
|
-
for (var i = 0, arr2 = new Array(len); i < len; i++) {
|
|
1255
|
-
arr2[i] = arr[i];
|
|
1256
|
-
}
|
|
1257
|
-
|
|
1258
|
-
return arr2;
|
|
1259
|
-
}
|
|
1260
|
-
|
|
1261
1252
|
function ownKeys$9(object, enumerableOnly) {
|
|
1262
1253
|
var keys = Object.keys(object);
|
|
1263
1254
|
|
|
@@ -1299,6 +1290,41 @@
|
|
|
1299
1290
|
return obj;
|
|
1300
1291
|
}
|
|
1301
1292
|
|
|
1293
|
+
function _toConsumableArray$3(arr) {
|
|
1294
|
+
return _arrayWithoutHoles$3(arr) || _iterableToArray$3(arr) || _unsupportedIterableToArray$3(arr) || _nonIterableSpread$3();
|
|
1295
|
+
}
|
|
1296
|
+
|
|
1297
|
+
function _nonIterableSpread$3() {
|
|
1298
|
+
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
1299
|
+
}
|
|
1300
|
+
|
|
1301
|
+
function _unsupportedIterableToArray$3(o, minLen) {
|
|
1302
|
+
if (!o) return;
|
|
1303
|
+
if (typeof o === "string") return _arrayLikeToArray$3(o, minLen);
|
|
1304
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
1305
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
1306
|
+
if (n === "Map" || n === "Set") return Array.from(o);
|
|
1307
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray$3(o, minLen);
|
|
1308
|
+
}
|
|
1309
|
+
|
|
1310
|
+
function _iterableToArray$3(iter) {
|
|
1311
|
+
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
|
|
1312
|
+
}
|
|
1313
|
+
|
|
1314
|
+
function _arrayWithoutHoles$3(arr) {
|
|
1315
|
+
if (Array.isArray(arr)) return _arrayLikeToArray$3(arr);
|
|
1316
|
+
}
|
|
1317
|
+
|
|
1318
|
+
function _arrayLikeToArray$3(arr, len) {
|
|
1319
|
+
if (len == null || len > arr.length) len = arr.length;
|
|
1320
|
+
|
|
1321
|
+
for (var i = 0, arr2 = new Array(len); i < len; i++) {
|
|
1322
|
+
arr2[i] = arr[i];
|
|
1323
|
+
}
|
|
1324
|
+
|
|
1325
|
+
return arr2;
|
|
1326
|
+
}
|
|
1327
|
+
|
|
1302
1328
|
function isDescription(item) {
|
|
1303
1329
|
return Boolean(item.execute);
|
|
1304
1330
|
}
|
|
@@ -1307,12 +1333,19 @@
|
|
|
1307
1333
|
return Boolean(description === null || description === void 0 ? void 0 : description.execute);
|
|
1308
1334
|
}
|
|
1309
1335
|
|
|
1310
|
-
function preResolve(itemsOrDescription, sourceId) {
|
|
1336
|
+
function preResolve(itemsOrDescription, sourceId, state) {
|
|
1311
1337
|
if (isRequesterDescription(itemsOrDescription)) {
|
|
1338
|
+
var contextParameters = itemsOrDescription.requesterId === 'algolia' ? Object.assign.apply(Object, [{}].concat(_toConsumableArray$3(Object.keys(state.context).map(function (key) {
|
|
1339
|
+
var _state$context$key;
|
|
1340
|
+
|
|
1341
|
+
return (_state$context$key = state.context[key]) === null || _state$context$key === void 0 ? void 0 : _state$context$key.__algoliaSearchParameters;
|
|
1342
|
+
})))) : {};
|
|
1312
1343
|
return _objectSpread$9(_objectSpread$9({}, itemsOrDescription), {}, {
|
|
1313
1344
|
requests: itemsOrDescription.queries.map(function (query) {
|
|
1314
1345
|
return {
|
|
1315
|
-
query: query,
|
|
1346
|
+
query: itemsOrDescription.requesterId === 'algolia' ? _objectSpread$9(_objectSpread$9({}, query), {}, {
|
|
1347
|
+
params: _objectSpread$9(_objectSpread$9({}, contextParameters), query.params)
|
|
1348
|
+
}) : query,
|
|
1316
1349
|
sourceId: sourceId,
|
|
1317
1350
|
transformResponse: itemsOrDescription.transformResponse
|
|
1318
1351
|
};
|
|
@@ -1374,7 +1407,7 @@
|
|
|
1374
1407
|
return flatten(responses);
|
|
1375
1408
|
});
|
|
1376
1409
|
}
|
|
1377
|
-
function postResolve(responses, sources) {
|
|
1410
|
+
function postResolve(responses, sources, store) {
|
|
1378
1411
|
return sources.map(function (source) {
|
|
1379
1412
|
var matches = responses.filter(function (response) {
|
|
1380
1413
|
return response.sourceId === source.sourceId;
|
|
@@ -1385,6 +1418,12 @@
|
|
|
1385
1418
|
});
|
|
1386
1419
|
var transform = matches[0].transformResponse;
|
|
1387
1420
|
var items = transform ? transform(mapToAlgoliaResponse(results)) : results;
|
|
1421
|
+
source.onResolve({
|
|
1422
|
+
source: source,
|
|
1423
|
+
results: results,
|
|
1424
|
+
items: items,
|
|
1425
|
+
state: store.getState()
|
|
1426
|
+
});
|
|
1388
1427
|
invariant(Array.isArray(items), function () {
|
|
1389
1428
|
return "The `getItems` function from source \"".concat(source.sourceId, "\" must return an array of items but returned type ").concat(JSON.stringify(_typeof(items)), ":\n\n").concat(JSON.stringify(decycle(items), null, 2), ".\n\nSee: https://www.algolia.com/doc/ui-libraries/autocomplete/core-concepts/sources/#param-getitems");
|
|
1390
1429
|
});
|
|
@@ -1543,10 +1582,10 @@
|
|
|
1543
1582
|
refresh: refresh,
|
|
1544
1583
|
state: store.getState()
|
|
1545
1584
|
}, setters))).then(function (itemsOrDescription) {
|
|
1546
|
-
return preResolve(itemsOrDescription, source.sourceId);
|
|
1585
|
+
return preResolve(itemsOrDescription, source.sourceId, store.getState());
|
|
1547
1586
|
});
|
|
1548
1587
|
})).then(resolve).then(function (responses) {
|
|
1549
|
-
return postResolve(responses, sources);
|
|
1588
|
+
return postResolve(responses, sources, store);
|
|
1550
1589
|
}).then(function (collections) {
|
|
1551
1590
|
return reshape({
|
|
1552
1591
|
collections: collections,
|
|
@@ -2594,7 +2633,8 @@
|
|
|
2594
2633
|
var propGetters = getPropGetters(_objectSpread$3({
|
|
2595
2634
|
props: props,
|
|
2596
2635
|
refresh: refresh,
|
|
2597
|
-
store: store
|
|
2636
|
+
store: store,
|
|
2637
|
+
navigator: props.navigator
|
|
2598
2638
|
}, setters));
|
|
2599
2639
|
|
|
2600
2640
|
function onStoreStateChange(_ref) {
|
|
@@ -2603,7 +2643,8 @@
|
|
|
2603
2643
|
props.onStateChange(_objectSpread$3({
|
|
2604
2644
|
prevState: prevState,
|
|
2605
2645
|
state: state,
|
|
2606
|
-
refresh: refresh
|
|
2646
|
+
refresh: refresh,
|
|
2647
|
+
navigator: props.navigator
|
|
2607
2648
|
}, setters));
|
|
2608
2649
|
}
|
|
2609
2650
|
|
|
@@ -2614,6 +2655,7 @@
|
|
|
2614
2655
|
isOpen: store.getState().isOpen
|
|
2615
2656
|
},
|
|
2616
2657
|
props: props,
|
|
2658
|
+
navigator: props.navigator,
|
|
2617
2659
|
query: store.getState().query,
|
|
2618
2660
|
refresh: refresh,
|
|
2619
2661
|
store: store
|
|
@@ -2624,6 +2666,7 @@
|
|
|
2624
2666
|
var _plugin$subscribe;
|
|
2625
2667
|
|
|
2626
2668
|
return (_plugin$subscribe = plugin.subscribe) === null || _plugin$subscribe === void 0 ? void 0 : _plugin$subscribe.call(plugin, _objectSpread$3(_objectSpread$3({}, setters), {}, {
|
|
2669
|
+
navigator: props.navigator,
|
|
2627
2670
|
refresh: refresh,
|
|
2628
2671
|
onSelect: function onSelect(fn) {
|
|
2629
2672
|
subscribers.push({
|
|
@@ -2634,6 +2677,11 @@
|
|
|
2634
2677
|
subscribers.push({
|
|
2635
2678
|
onActive: fn
|
|
2636
2679
|
});
|
|
2680
|
+
},
|
|
2681
|
+
onResolve: function onResolve(fn) {
|
|
2682
|
+
subscribers.push({
|
|
2683
|
+
onResolve: fn
|
|
2684
|
+
});
|
|
2637
2685
|
}
|
|
2638
2686
|
}));
|
|
2639
2687
|
});
|
|
@@ -2645,7 +2693,8 @@
|
|
|
2645
2693
|
environment: props.environment
|
|
2646
2694
|
});
|
|
2647
2695
|
return _objectSpread$3(_objectSpread$3({
|
|
2648
|
-
refresh: refresh
|
|
2696
|
+
refresh: refresh,
|
|
2697
|
+
navigator: props.navigator
|
|
2649
2698
|
}, propGetters), setters);
|
|
2650
2699
|
}
|
|
2651
2700
|
|
|
@@ -2883,7 +2932,7 @@
|
|
|
2883
2932
|
}, autocompleteScopeApi));
|
|
2884
2933
|
setProperties(element, _objectSpread2(_objectSpread2({}, inputProps), {}, {
|
|
2885
2934
|
onKeyDown: function onKeyDown(event) {
|
|
2886
|
-
// In detached mode we don't want to close the panel when
|
|
2935
|
+
// In detached mode we don't want to close the panel when hitting `Tab`.
|
|
2887
2936
|
if (isDetached && event.key === 'Tab') {
|
|
2888
2937
|
return;
|
|
2889
2938
|
}
|
|
@@ -4129,7 +4178,8 @@
|
|
|
4129
4178
|
setIsOpen: autocomplete.value.setIsOpen,
|
|
4130
4179
|
setStatus: autocomplete.value.setStatus,
|
|
4131
4180
|
setContext: autocomplete.value.setContext,
|
|
4132
|
-
refresh: autocomplete.value.refresh
|
|
4181
|
+
refresh: autocomplete.value.refresh,
|
|
4182
|
+
navigator: autocomplete.value.navigator
|
|
4133
4183
|
};
|
|
4134
4184
|
var html = reactive(function () {
|
|
4135
4185
|
return htm.bind(props.value.renderer.renderer.createElement);
|