@algolia/autocomplete-js 1.18.1 → 1.19.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.
@@ -1,4 +1,4 @@
1
- /*! @algolia/autocomplete-js 1.18.1 | MIT License | © Algolia, Inc. and contributors | https://github.com/algolia/autocomplete */
1
+ /*! @algolia/autocomplete-js 1.19.1 | 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) :
@@ -118,13 +118,13 @@
118
118
  return target;
119
119
  }
120
120
  function _slicedToArray$2(arr, i) {
121
- return _arrayWithHoles$2(arr) || _iterableToArrayLimit$2(arr, i) || _unsupportedIterableToArray$9(arr, i) || _nonIterableRest$2();
121
+ return _arrayWithHoles$2(arr) || _iterableToArrayLimit$2(arr, i) || _unsupportedIterableToArray$a(arr, i) || _nonIterableRest$2();
122
122
  }
123
123
  function _toConsumableArray$7(arr) {
124
- return _arrayWithoutHoles$7(arr) || _iterableToArray$7(arr) || _unsupportedIterableToArray$9(arr) || _nonIterableSpread$7();
124
+ return _arrayWithoutHoles$7(arr) || _iterableToArray$7(arr) || _unsupportedIterableToArray$a(arr) || _nonIterableSpread$7();
125
125
  }
126
126
  function _arrayWithoutHoles$7(arr) {
127
- if (Array.isArray(arr)) return _arrayLikeToArray$9(arr);
127
+ if (Array.isArray(arr)) return _arrayLikeToArray$a(arr);
128
128
  }
129
129
  function _arrayWithHoles$2(arr) {
130
130
  if (Array.isArray(arr)) return arr;
@@ -132,15 +132,15 @@
132
132
  function _iterableToArray$7(iter) {
133
133
  if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
134
134
  }
135
- function _unsupportedIterableToArray$9(o, minLen) {
135
+ function _unsupportedIterableToArray$a(o, minLen) {
136
136
  if (!o) return;
137
- if (typeof o === "string") return _arrayLikeToArray$9(o, minLen);
137
+ if (typeof o === "string") return _arrayLikeToArray$a(o, minLen);
138
138
  var n = Object.prototype.toString.call(o).slice(8, -1);
139
139
  if (n === "Object" && o.constructor) n = o.constructor.name;
140
140
  if (n === "Map" || n === "Set") return Array.from(o);
141
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray$9(o, minLen);
141
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray$a(o, minLen);
142
142
  }
143
- function _arrayLikeToArray$9(arr, len) {
143
+ function _arrayLikeToArray$a(arr, len) {
144
144
  if (len == null || len > arr.length) len = arr.length;
145
145
  for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
146
146
  return arr2;
@@ -188,20 +188,20 @@
188
188
  }
189
189
 
190
190
  function _slicedToArray$1(arr, i) {
191
- return _arrayWithHoles$1(arr) || _iterableToArrayLimit$1(arr, i) || _unsupportedIterableToArray$8(arr, i) || _nonIterableRest$1();
191
+ return _arrayWithHoles$1(arr) || _iterableToArrayLimit$1(arr, i) || _unsupportedIterableToArray$9(arr, i) || _nonIterableRest$1();
192
192
  }
193
193
  function _nonIterableRest$1() {
194
194
  throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
195
195
  }
196
- function _unsupportedIterableToArray$8(o, minLen) {
196
+ function _unsupportedIterableToArray$9(o, minLen) {
197
197
  if (!o) return;
198
- if (typeof o === "string") return _arrayLikeToArray$8(o, minLen);
198
+ if (typeof o === "string") return _arrayLikeToArray$9(o, minLen);
199
199
  var n = Object.prototype.toString.call(o).slice(8, -1);
200
200
  if (n === "Object" && o.constructor) n = o.constructor.name;
201
201
  if (n === "Map" || n === "Set") return Array.from(o);
202
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray$8(o, minLen);
202
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray$9(o, minLen);
203
203
  }
204
- function _arrayLikeToArray$8(arr, len) {
204
+ function _arrayLikeToArray$9(arr, len) {
205
205
  if (len == null || len > arr.length) len = arr.length;
206
206
  for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
207
207
  return arr2;
@@ -347,7 +347,7 @@
347
347
  return undefined;
348
348
  }
349
349
 
350
- var version = '1.18.1';
350
+ var version = '1.19.1';
351
351
 
352
352
  var userAgents$1 = [{
353
353
  segment: 'autocomplete-core',
@@ -392,20 +392,20 @@
392
392
  }
393
393
 
394
394
  function _slicedToArray(arr, i) {
395
- return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray$7(arr, i) || _nonIterableRest();
395
+ return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray$8(arr, i) || _nonIterableRest();
396
396
  }
397
397
  function _nonIterableRest() {
398
398
  throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
399
399
  }
400
- function _unsupportedIterableToArray$7(o, minLen) {
400
+ function _unsupportedIterableToArray$8(o, minLen) {
401
401
  if (!o) return;
402
- if (typeof o === "string") return _arrayLikeToArray$7(o, minLen);
402
+ if (typeof o === "string") return _arrayLikeToArray$8(o, minLen);
403
403
  var n = Object.prototype.toString.call(o).slice(8, -1);
404
404
  if (n === "Object" && o.constructor) n = o.constructor.name;
405
405
  if (n === "Map" || n === "Set") return Array.from(o);
406
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray$7(o, minLen);
406
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray$8(o, minLen);
407
407
  }
408
- function _arrayLikeToArray$7(arr, len) {
408
+ function _arrayLikeToArray$8(arr, len) {
409
409
  if (len == null || len > arr.length) len = arr.length;
410
410
  for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
411
411
  return arr2;
@@ -470,26 +470,26 @@
470
470
  }, _typeof$g(obj);
471
471
  }
472
472
  function _toConsumableArray$6(arr) {
473
- return _arrayWithoutHoles$6(arr) || _iterableToArray$6(arr) || _unsupportedIterableToArray$6(arr) || _nonIterableSpread$6();
473
+ return _arrayWithoutHoles$6(arr) || _iterableToArray$6(arr) || _unsupportedIterableToArray$7(arr) || _nonIterableSpread$6();
474
474
  }
475
475
  function _nonIterableSpread$6() {
476
476
  throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
477
477
  }
478
- function _unsupportedIterableToArray$6(o, minLen) {
478
+ function _unsupportedIterableToArray$7(o, minLen) {
479
479
  if (!o) return;
480
- if (typeof o === "string") return _arrayLikeToArray$6(o, minLen);
480
+ if (typeof o === "string") return _arrayLikeToArray$7(o, minLen);
481
481
  var n = Object.prototype.toString.call(o).slice(8, -1);
482
482
  if (n === "Object" && o.constructor) n = o.constructor.name;
483
483
  if (n === "Map" || n === "Set") return Array.from(o);
484
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray$6(o, minLen);
484
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray$7(o, minLen);
485
485
  }
486
486
  function _iterableToArray$6(iter) {
487
487
  if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
488
488
  }
489
489
  function _arrayWithoutHoles$6(arr) {
490
- if (Array.isArray(arr)) return _arrayLikeToArray$6(arr);
490
+ if (Array.isArray(arr)) return _arrayLikeToArray$7(arr);
491
491
  }
492
- function _arrayLikeToArray$6(arr, len) {
492
+ function _arrayLikeToArray$7(arr, len) {
493
493
  if (len == null || len > arr.length) len = arr.length;
494
494
  for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
495
495
  return arr2;
@@ -791,26 +791,26 @@
791
791
  }, _typeof$f(obj);
792
792
  }
793
793
  function _toConsumableArray$5(arr) {
794
- return _arrayWithoutHoles$5(arr) || _iterableToArray$5(arr) || _unsupportedIterableToArray$5(arr) || _nonIterableSpread$5();
794
+ return _arrayWithoutHoles$5(arr) || _iterableToArray$5(arr) || _unsupportedIterableToArray$6(arr) || _nonIterableSpread$5();
795
795
  }
796
796
  function _nonIterableSpread$5() {
797
797
  throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
798
798
  }
799
- function _unsupportedIterableToArray$5(o, minLen) {
799
+ function _unsupportedIterableToArray$6(o, minLen) {
800
800
  if (!o) return;
801
- if (typeof o === "string") return _arrayLikeToArray$5(o, minLen);
801
+ if (typeof o === "string") return _arrayLikeToArray$6(o, minLen);
802
802
  var n = Object.prototype.toString.call(o).slice(8, -1);
803
803
  if (n === "Object" && o.constructor) n = o.constructor.name;
804
804
  if (n === "Map" || n === "Set") return Array.from(o);
805
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray$5(o, minLen);
805
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray$6(o, minLen);
806
806
  }
807
807
  function _iterableToArray$5(iter) {
808
808
  if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
809
809
  }
810
810
  function _arrayWithoutHoles$5(arr) {
811
- if (Array.isArray(arr)) return _arrayLikeToArray$5(arr);
811
+ if (Array.isArray(arr)) return _arrayLikeToArray$6(arr);
812
812
  }
813
- function _arrayLikeToArray$5(arr, len) {
813
+ function _arrayLikeToArray$6(arr, len) {
814
814
  if (len == null || len > arr.length) len = arr.length;
815
815
  for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
816
816
  return arr2;
@@ -1146,6 +1146,9 @@
1146
1146
  };
1147
1147
  }
1148
1148
 
1149
+ // Ensures multiple callers sync to the same promise.
1150
+ var _hasWaitPromiseResolved = true;
1151
+ var _waitPromise;
1149
1152
  function createCancelablePromiseList() {
1150
1153
  var list = [];
1151
1154
  return {
@@ -1164,6 +1167,22 @@
1164
1167
  },
1165
1168
  isEmpty: function isEmpty() {
1166
1169
  return list.length === 0;
1170
+ },
1171
+ wait: function wait(timeout) {
1172
+ // Reuse promise if already exists. Keeps multiple callers subscribed to the same promise.
1173
+ if (!_hasWaitPromiseResolved) {
1174
+ return _waitPromise;
1175
+ }
1176
+
1177
+ // Creates a promise which either resolves after all pending requests complete
1178
+ // or the timeout is reached (if provided). Whichever comes first.
1179
+ _hasWaitPromiseResolved = false;
1180
+ _waitPromise = !timeout ? Promise.all(list) : Promise.race([Promise.all(list), new Promise(function (resolve) {
1181
+ return setTimeout(resolve, timeout);
1182
+ })]);
1183
+ return _waitPromise.then(function () {
1184
+ _hasWaitPromiseResolved = true;
1185
+ });
1167
1186
  }
1168
1187
  };
1169
1188
  }
@@ -1335,6 +1354,105 @@
1335
1354
  });
1336
1355
  }
1337
1356
 
1357
+ function _createForOfIteratorHelper(o, allowArrayLike) {
1358
+ var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
1359
+ if (!it) {
1360
+ if (Array.isArray(o) || (it = _unsupportedIterableToArray$5(o)) || allowArrayLike && o && typeof o.length === "number") {
1361
+ if (it) o = it;
1362
+ var i = 0;
1363
+ var F = function F() {};
1364
+ return {
1365
+ s: F,
1366
+ n: function n() {
1367
+ if (i >= o.length) return {
1368
+ done: true
1369
+ };
1370
+ return {
1371
+ done: false,
1372
+ value: o[i++]
1373
+ };
1374
+ },
1375
+ e: function e(_e) {
1376
+ throw _e;
1377
+ },
1378
+ f: F
1379
+ };
1380
+ }
1381
+ throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
1382
+ }
1383
+ var normalCompletion = true,
1384
+ didErr = false,
1385
+ err;
1386
+ return {
1387
+ s: function s() {
1388
+ it = it.call(o);
1389
+ },
1390
+ n: function n() {
1391
+ var step = it.next();
1392
+ normalCompletion = step.done;
1393
+ return step;
1394
+ },
1395
+ e: function e(_e2) {
1396
+ didErr = true;
1397
+ err = _e2;
1398
+ },
1399
+ f: function f() {
1400
+ try {
1401
+ if (!normalCompletion && it.return != null) it.return();
1402
+ } finally {
1403
+ if (didErr) throw err;
1404
+ }
1405
+ }
1406
+ };
1407
+ }
1408
+ function _unsupportedIterableToArray$5(o, minLen) {
1409
+ if (!o) return;
1410
+ if (typeof o === "string") return _arrayLikeToArray$5(o, minLen);
1411
+ var n = Object.prototype.toString.call(o).slice(8, -1);
1412
+ if (n === "Object" && o.constructor) n = o.constructor.name;
1413
+ if (n === "Map" || n === "Set") return Array.from(o);
1414
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray$5(o, minLen);
1415
+ }
1416
+ function _arrayLikeToArray$5(arr, len) {
1417
+ if (len == null || len > arr.length) len = arr.length;
1418
+ for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
1419
+ return arr2;
1420
+ }
1421
+ /**
1422
+ * If a plugin is configured to await a submit event, this returns a promise
1423
+ * for either the max timeout value found or until it completes.
1424
+ * Otherwise, return undefined.
1425
+ */
1426
+ var getPluginSubmitPromise = function getPluginSubmitPromise(plugins, pendingRequests) {
1427
+ var waitUntilComplete = false;
1428
+ var timeouts = [];
1429
+ var _iterator = _createForOfIteratorHelper(plugins),
1430
+ _step;
1431
+ try {
1432
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
1433
+ var _plugin$__autocomplet, _plugin$__autocomplet2, _plugin$__autocomplet3;
1434
+ var plugin = _step.value;
1435
+ var value = (_plugin$__autocomplet = plugin.__autocomplete_pluginOptions) === null || _plugin$__autocomplet === void 0 ? void 0 : (_plugin$__autocomplet2 = (_plugin$__autocomplet3 = _plugin$__autocomplet).awaitSubmit) === null || _plugin$__autocomplet2 === void 0 ? void 0 : _plugin$__autocomplet2.call(_plugin$__autocomplet3);
1436
+ if (typeof value === 'number') {
1437
+ timeouts.push(value);
1438
+ } else if (value === true) {
1439
+ waitUntilComplete = true;
1440
+ break; // break loop as bool overrides num array below
1441
+ }
1442
+ }
1443
+ } catch (err) {
1444
+ _iterator.e(err);
1445
+ } finally {
1446
+ _iterator.f();
1447
+ }
1448
+ if (waitUntilComplete) {
1449
+ return pendingRequests.wait();
1450
+ } else if (timeouts.length > 0) {
1451
+ return pendingRequests.wait(Math.max.apply(Math, timeouts));
1452
+ }
1453
+ return undefined;
1454
+ };
1455
+
1338
1456
  // We don't have access to the autocomplete source when we call `onKeyDown`
1339
1457
  // or `onClick` because those are native browser events.
1340
1458
  // However, we can get the source from the suggestion index.
@@ -2516,11 +2634,14 @@
2516
2634
  if (store.getState().activeItemId === null || store.getState().collections.every(function (collection) {
2517
2635
  return collection.items.length === 0;
2518
2636
  })) {
2519
- // If requests are still pending when the panel closes, they could reopen
2520
- // the panel once they resolve.
2521
- // We want to prevent any subsequent query from reopening the panel
2522
- // because it would result in an unsolicited UI behavior.
2523
- if (!props.debug) {
2637
+ var waitForSubmit = getPluginSubmitPromise(props.plugins, store.pendingRequests);
2638
+ if (waitForSubmit !== undefined) {
2639
+ waitForSubmit.then(store.pendingRequests.cancelAll); // Cancel the rest if timeout number is provided
2640
+ } else if (!props.debug) {
2641
+ // If requests are still pending when the panel closes, they could reopen
2642
+ // the panel once they resolve.
2643
+ // We want to prevent any subsequent query from reopening the panel
2644
+ // because it would result in an unsolicited UI behavior.
2524
2645
  store.pendingRequests.cancelAll();
2525
2646
  }
2526
2647
  return;
@@ -2779,20 +2900,30 @@
2779
2900
  var getFormProps = function getFormProps(providedProps) {
2780
2901
  providedProps.inputElement;
2781
2902
  var rest = _objectWithoutProperties$1(providedProps, _excluded3);
2903
+ var handleSubmit = function handleSubmit(event) {
2904
+ var _providedProps$inputE;
2905
+ props.onSubmit(_objectSpread$6({
2906
+ event: event,
2907
+ refresh: refresh,
2908
+ state: store.getState()
2909
+ }, setters));
2910
+ store.dispatch('submit', null);
2911
+ (_providedProps$inputE = providedProps.inputElement) === null || _providedProps$inputE === void 0 ? void 0 : _providedProps$inputE.blur();
2912
+ };
2782
2913
  return _objectSpread$6({
2783
2914
  action: '',
2784
2915
  noValidate: true,
2785
2916
  role: 'search',
2786
2917
  onSubmit: function onSubmit(event) {
2787
- var _providedProps$inputE;
2788
2918
  event.preventDefault();
2789
- props.onSubmit(_objectSpread$6({
2790
- event: event,
2791
- refresh: refresh,
2792
- state: store.getState()
2793
- }, setters));
2794
- store.dispatch('submit', null);
2795
- (_providedProps$inputE = providedProps.inputElement) === null || _providedProps$inputE === void 0 ? void 0 : _providedProps$inputE.blur();
2919
+ var waitForSubmit = getPluginSubmitPromise(props.plugins, store.pendingRequests);
2920
+ if (waitForSubmit !== undefined) {
2921
+ waitForSubmit.then(function () {
2922
+ return handleSubmit(event);
2923
+ });
2924
+ } else {
2925
+ handleSubmit(event);
2926
+ }
2796
2927
  },
2797
2928
  onReset: function onReset(event) {
2798
2929
  var _providedProps$inputE2;