@algolia/autocomplete-core 1.5.0 → 1.5.3

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,23 +1,18 @@
1
- /*! @algolia/autocomplete-core 1.5.0 | MIT License | © Algolia, Inc. and contributors | https://github.com/algolia/autocomplete */
1
+ /*! @algolia/autocomplete-core 1.5.3 | 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) :
5
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global['@algolia/autocomplete-core'] = {}));
6
- }(this, (function (exports) { 'use strict';
5
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["@algolia/autocomplete-core"] = {}));
6
+ })(this, (function (exports) { 'use strict';
7
7
 
8
8
  function ownKeys(object, enumerableOnly) {
9
9
  var keys = Object.keys(object);
10
10
 
11
11
  if (Object.getOwnPropertySymbols) {
12
12
  var symbols = Object.getOwnPropertySymbols(object);
13
-
14
- if (enumerableOnly) {
15
- symbols = symbols.filter(function (sym) {
16
- return Object.getOwnPropertyDescriptor(object, sym).enumerable;
17
- });
18
- }
19
-
20
- keys.push.apply(keys, symbols);
13
+ enumerableOnly && (symbols = symbols.filter(function (sym) {
14
+ return Object.getOwnPropertyDescriptor(object, sym).enumerable;
15
+ })), keys.push.apply(keys, symbols);
21
16
  }
22
17
 
23
18
  return keys;
@@ -25,38 +20,25 @@
25
20
 
26
21
  function _objectSpread2(target) {
27
22
  for (var i = 1; i < arguments.length; i++) {
28
- var source = arguments[i] != null ? arguments[i] : {};
29
-
30
- if (i % 2) {
31
- ownKeys(Object(source), true).forEach(function (key) {
32
- _defineProperty(target, key, source[key]);
33
- });
34
- } else if (Object.getOwnPropertyDescriptors) {
35
- Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
36
- } else {
37
- ownKeys(Object(source)).forEach(function (key) {
38
- Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
39
- });
40
- }
23
+ var source = null != arguments[i] ? arguments[i] : {};
24
+ i % 2 ? ownKeys(Object(source), !0).forEach(function (key) {
25
+ _defineProperty(target, key, source[key]);
26
+ }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) {
27
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
28
+ });
41
29
  }
42
30
 
43
31
  return target;
44
32
  }
45
33
 
46
- function _typeof(obj) {
34
+ function _typeof$1(obj) {
47
35
  "@babel/helpers - typeof";
48
36
 
49
- if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
50
- _typeof = function (obj) {
51
- return typeof obj;
52
- };
53
- } else {
54
- _typeof = function (obj) {
55
- return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
56
- };
57
- }
58
-
59
- return _typeof(obj);
37
+ return _typeof$1 = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) {
38
+ return typeof obj;
39
+ } : function (obj) {
40
+ return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
41
+ }, _typeof$1(obj);
60
42
  }
61
43
 
62
44
  function _defineProperty(obj, key, value) {
@@ -111,27 +93,27 @@
111
93
  }
112
94
 
113
95
  function _toConsumableArray(arr) {
114
- return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
96
+ return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray$1(arr) || _nonIterableSpread();
115
97
  }
116
98
 
117
99
  function _arrayWithoutHoles(arr) {
118
- if (Array.isArray(arr)) return _arrayLikeToArray(arr);
100
+ if (Array.isArray(arr)) return _arrayLikeToArray$1(arr);
119
101
  }
120
102
 
121
103
  function _iterableToArray(iter) {
122
104
  if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
123
105
  }
124
106
 
125
- function _unsupportedIterableToArray(o, minLen) {
107
+ function _unsupportedIterableToArray$1(o, minLen) {
126
108
  if (!o) return;
127
- if (typeof o === "string") return _arrayLikeToArray(o, minLen);
109
+ if (typeof o === "string") return _arrayLikeToArray$1(o, minLen);
128
110
  var n = Object.prototype.toString.call(o).slice(8, -1);
129
111
  if (n === "Object" && o.constructor) n = o.constructor.name;
130
112
  if (n === "Map" || n === "Set") return Array.from(o);
131
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
113
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray$1(o, minLen);
132
114
  }
133
115
 
134
- function _arrayLikeToArray(arr, len) {
116
+ function _arrayLikeToArray$1(arr, len) {
135
117
  if (len == null || len > arr.length) len = arr.length;
136
118
 
137
119
  for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
@@ -144,23 +126,23 @@
144
126
  }
145
127
 
146
128
  function _slicedToArray(arr, i) {
147
- return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray$1(arr, i) || _nonIterableRest();
129
+ return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
148
130
  }
149
131
 
150
132
  function _nonIterableRest() {
151
133
  throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
152
134
  }
153
135
 
154
- function _unsupportedIterableToArray$1(o, minLen) {
136
+ function _unsupportedIterableToArray(o, minLen) {
155
137
  if (!o) return;
156
- if (typeof o === "string") return _arrayLikeToArray$1(o, minLen);
138
+ if (typeof o === "string") return _arrayLikeToArray(o, minLen);
157
139
  var n = Object.prototype.toString.call(o).slice(8, -1);
158
140
  if (n === "Object" && o.constructor) n = o.constructor.name;
159
141
  if (n === "Map" || n === "Set") return Array.from(o);
160
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray$1(o, minLen);
142
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
161
143
  }
162
144
 
163
- function _arrayLikeToArray$1(arr, len) {
145
+ function _arrayLikeToArray(arr, len) {
164
146
  if (len == null || len > arr.length) len = arr.length;
165
147
 
166
148
  for (var i = 0, arr2 = new Array(len); i < len; i++) {
@@ -204,20 +186,14 @@
204
186
  if (Array.isArray(arr)) return arr;
205
187
  }
206
188
 
207
- function _typeof$1(obj) {
189
+ function _typeof(obj) {
208
190
  "@babel/helpers - typeof";
209
191
 
210
- if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
211
- _typeof$1 = function _typeof(obj) {
212
- return typeof obj;
213
- };
214
- } else {
215
- _typeof$1 = function _typeof(obj) {
216
- return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
217
- };
218
- }
219
-
220
- return _typeof$1(obj);
192
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) {
193
+ return typeof obj;
194
+ } : function (obj) {
195
+ return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
196
+ }, _typeof(obj);
221
197
  }
222
198
  /**
223
199
  * Decycles objects with circular references.
@@ -228,7 +204,7 @@
228
204
  function decycle(obj) {
229
205
  var seen = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : new Set();
230
206
 
231
- if ( !obj || _typeof$1(obj) !== 'object') {
207
+ if (!obj || _typeof(obj) !== 'object') {
232
208
  return obj;
233
209
  }
234
210
 
@@ -288,7 +264,7 @@
288
264
 
289
265
  var noop = function noop() {};
290
266
 
291
- var version = '1.5.0';
267
+ var version = '1.5.3';
292
268
 
293
269
  var userAgents = [{
294
270
  segment: 'autocomplete-core',
@@ -323,74 +299,79 @@
323
299
  "development" !== 'production' ? warn(!options.debug, 'The `debug` option is meant for development debugging and should not be used in production.') : void 0;
324
300
  }
325
301
 
326
- function createStore(reducer, props, onStoreStateChange) {
327
- var state = props.initialState;
302
+ function createInternalCancelablePromise(promise, initialState) {
303
+ var state = initialState;
328
304
  return {
329
- getState: function getState() {
330
- return state;
305
+ then: function then(onfulfilled, onrejected) {
306
+ return createInternalCancelablePromise(promise.then(createCallback(onfulfilled, state, promise), createCallback(onrejected, state, promise)), state);
331
307
  },
332
- dispatch: function dispatch(action, payload) {
333
- var prevState = _objectSpread2({}, state);
308
+ catch: function _catch(onrejected) {
309
+ return createInternalCancelablePromise(promise.catch(createCallback(onrejected, state, promise)), state);
310
+ },
311
+ finally: function _finally(onfinally) {
312
+ if (onfinally) {
313
+ state.onCancelList.push(onfinally);
314
+ }
334
315
 
335
- state = reducer(state, {
336
- type: action,
337
- props: props,
338
- payload: payload
339
- });
340
- onStoreStateChange({
341
- state: state,
342
- prevState: prevState
316
+ return createInternalCancelablePromise(promise.finally(createCallback(onfinally && function () {
317
+ state.onCancelList = [];
318
+ return onfinally();
319
+ }, state, promise)), state);
320
+ },
321
+ cancel: function cancel() {
322
+ state.isCanceled = true;
323
+ var callbacks = state.onCancelList;
324
+ state.onCancelList = [];
325
+ callbacks.forEach(function (callback) {
326
+ callback();
343
327
  });
328
+ },
329
+ isCanceled: function isCanceled() {
330
+ return state.isCanceled === true;
344
331
  }
345
332
  };
346
333
  }
347
334
 
348
- function getAutocompleteSetters(_ref) {
349
- var store = _ref.store;
350
-
351
- var setActiveItemId = function setActiveItemId(value) {
352
- store.dispatch('setActiveItemId', value);
353
- };
354
-
355
- var setQuery = function setQuery(value) {
356
- store.dispatch('setQuery', value);
357
- };
358
-
359
- var setCollections = function setCollections(rawValue) {
360
- var baseItemId = 0;
361
- var value = rawValue.map(function (collection) {
362
- return _objectSpread2(_objectSpread2({}, collection), {}, {
363
- // We flatten the stored items to support calling `getAlgoliaResults`
364
- // from the source itself.
365
- items: flatten(collection.items).map(function (item) {
366
- return _objectSpread2(_objectSpread2({}, item), {}, {
367
- __autocomplete_id: baseItemId++
368
- });
369
- })
370
- });
371
- });
372
- store.dispatch('setCollections', value);
373
- };
335
+ function cancelable(promise) {
336
+ return createInternalCancelablePromise(promise, {
337
+ isCanceled: false,
338
+ onCancelList: []
339
+ });
340
+ }
374
341
 
375
- var setIsOpen = function setIsOpen(value) {
376
- store.dispatch('setIsOpen', value);
377
- };
342
+ function createCallback(onResult, state, fallback) {
343
+ if (!onResult) {
344
+ return fallback;
345
+ }
378
346
 
379
- var setStatus = function setStatus(value) {
380
- store.dispatch('setStatus', value);
381
- };
347
+ return function callback(arg) {
348
+ if (state.isCanceled) {
349
+ return arg;
350
+ }
382
351
 
383
- var setContext = function setContext(value) {
384
- store.dispatch('setContext', value);
352
+ return onResult(arg);
385
353
  };
354
+ }
386
355
 
356
+ function createCancelablePromiseList() {
357
+ var list = [];
387
358
  return {
388
- setActiveItemId: setActiveItemId,
389
- setQuery: setQuery,
390
- setCollections: setCollections,
391
- setIsOpen: setIsOpen,
392
- setStatus: setStatus,
393
- setContext: setContext
359
+ add: function add(cancelablePromise) {
360
+ list.push(cancelablePromise);
361
+ return cancelablePromise.finally(function () {
362
+ list = list.filter(function (item) {
363
+ return item !== cancelablePromise;
364
+ });
365
+ });
366
+ },
367
+ cancelAll: function cancelAll() {
368
+ list.forEach(function (promise) {
369
+ return promise.cancel();
370
+ });
371
+ },
372
+ isEmpty: function isEmpty() {
373
+ return list.length === 0;
374
+ }
394
375
  };
395
376
  }
396
377
 
@@ -470,7 +451,7 @@
470
451
  var seenSourceIds = [];
471
452
  return Promise.resolve(getSources(params)).then(function (sources) {
472
453
  invariant(Array.isArray(sources), function () {
473
- return "The `getSources` function must return an array of sources but returned type ".concat(JSON.stringify(_typeof(sources)), ":\n\n").concat(JSON.stringify(decycle(sources), null, 2));
454
+ return "The `getSources` function must return an array of sources but returned type ".concat(JSON.stringify(_typeof$1(sources)), ":\n\n").concat(JSON.stringify(decycle(sources), null, 2));
474
455
  });
475
456
  return Promise.all(sources // We allow `undefined` and `false` sources to allow users to use
476
457
  // `Boolean(query) && source` (=> `false`).
@@ -634,6 +615,78 @@
634
615
  };
635
616
  }
636
617
 
618
+ function createStore(reducer, props, onStoreStateChange) {
619
+ var state = props.initialState;
620
+ return {
621
+ getState: function getState() {
622
+ return state;
623
+ },
624
+ dispatch: function dispatch(action, payload) {
625
+ var prevState = _objectSpread2({}, state);
626
+
627
+ state = reducer(state, {
628
+ type: action,
629
+ props: props,
630
+ payload: payload
631
+ });
632
+ onStoreStateChange({
633
+ state: state,
634
+ prevState: prevState
635
+ });
636
+ },
637
+ pendingRequests: createCancelablePromiseList()
638
+ };
639
+ }
640
+
641
+ function getAutocompleteSetters(_ref) {
642
+ var store = _ref.store;
643
+
644
+ var setActiveItemId = function setActiveItemId(value) {
645
+ store.dispatch('setActiveItemId', value);
646
+ };
647
+
648
+ var setQuery = function setQuery(value) {
649
+ store.dispatch('setQuery', value);
650
+ };
651
+
652
+ var setCollections = function setCollections(rawValue) {
653
+ var baseItemId = 0;
654
+ var value = rawValue.map(function (collection) {
655
+ return _objectSpread2(_objectSpread2({}, collection), {}, {
656
+ // We flatten the stored items to support calling `getAlgoliaResults`
657
+ // from the source itself.
658
+ items: flatten(collection.items).map(function (item) {
659
+ return _objectSpread2(_objectSpread2({}, item), {}, {
660
+ __autocomplete_id: baseItemId++
661
+ });
662
+ })
663
+ });
664
+ });
665
+ store.dispatch('setCollections', value);
666
+ };
667
+
668
+ var setIsOpen = function setIsOpen(value) {
669
+ store.dispatch('setIsOpen', value);
670
+ };
671
+
672
+ var setStatus = function setStatus(value) {
673
+ store.dispatch('setStatus', value);
674
+ };
675
+
676
+ var setContext = function setContext(value) {
677
+ store.dispatch('setContext', value);
678
+ };
679
+
680
+ return {
681
+ setActiveItemId: setActiveItemId,
682
+ setQuery: setQuery,
683
+ setCollections: setCollections,
684
+ setIsOpen: setIsOpen,
685
+ setStatus: setStatus,
686
+ setContext: setContext
687
+ };
688
+ }
689
+
637
690
  function getDefaultProps(props, pluginSubscribers) {
638
691
  var _props$id;
639
692
 
@@ -814,9 +867,10 @@
814
867
 
815
868
  var searchClient = current.searchClient,
816
869
  execute = current.execute,
870
+ requesterId = current.requesterId,
817
871
  requests = current.requests;
818
872
  var container = acc.find(function (item) {
819
- return isDescription(current) && isDescription(item) && item.searchClient === searchClient && item.execute === execute;
873
+ return isDescription(current) && isDescription(item) && item.searchClient === searchClient && Boolean(requesterId) && item.requesterId === requesterId;
820
874
  });
821
875
 
822
876
  if (container) {
@@ -826,6 +880,7 @@
826
880
  } else {
827
881
  var request = {
828
882
  execute: execute,
883
+ requesterId: requesterId,
829
884
  items: requests,
830
885
  searchClient: searchClient
831
886
  };
@@ -864,7 +919,7 @@
864
919
  var transform = matches[0].transformResponse;
865
920
  var items = transform ? transform(mapToAlgoliaResponse(results)) : results;
866
921
  invariant(Array.isArray(items), function () {
867
- 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");
922
+ return "The `getItems` function from source \"".concat(source.sourceId, "\" must return an array of items but returned type ").concat(JSON.stringify(_typeof$1(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");
868
923
  });
869
924
  invariant(items.every(Boolean), "The `getItems` function from source \"".concat(source.sourceId, "\" must return an array of items but returned ").concat(JSON.stringify(undefined), ".\n\nDid you forget to return items?\n\nSee: https://www.algolia.com/doc/ui-libraries/autocomplete/core-concepts/sources/#param-getitems"));
870
925
  return {
@@ -874,7 +929,7 @@
874
929
  });
875
930
  }
876
931
 
877
- var _excluded = ["event", "nextState", "props", "query", "refresh", "store"];
932
+ var _excluded$2 = ["event", "nextState", "props", "query", "refresh", "store"];
878
933
  var lastStalledId = null;
879
934
  var runConcurrentSafePromise = createConcurrentSafePromise();
880
935
  function onInput(_ref) {
@@ -885,7 +940,7 @@
885
940
  query = _ref.query,
886
941
  refresh = _ref.refresh,
887
942
  store = _ref.store,
888
- setters = _objectWithoutProperties(_ref, _excluded);
943
+ setters = _objectWithoutProperties(_ref, _excluded$2);
889
944
 
890
945
  if (lastStalledId) {
891
946
  props.environment.clearTimeout(lastStalledId);
@@ -916,9 +971,11 @@
916
971
  // updates performed in this code path.
917
972
  // We chain with a void promise to respect `onInput`'s expected return type.
918
973
 
919
- return runConcurrentSafePromise(collections).then(function () {
974
+ var _request = cancelable(runConcurrentSafePromise(collections).then(function () {
920
975
  return Promise.resolve();
921
- });
976
+ }));
977
+
978
+ return store.pendingRequests.add(_request);
922
979
  }
923
980
 
924
981
  setStatus('loading');
@@ -931,7 +988,7 @@
931
988
  // meaning we should only ever manipulate the state once this concurrent-safe
932
989
  // promise is resolved.
933
990
 
934
- return runConcurrentSafePromise(props.getSources(_objectSpread2({
991
+ var request = cancelable(runConcurrentSafePromise(props.getSources(_objectSpread2({
935
992
  query: query,
936
993
  refresh: refresh,
937
994
  state: store.getState()
@@ -953,9 +1010,13 @@
953
1010
  state: store.getState()
954
1011
  });
955
1012
  });
956
- })).then(function (collections) {
1013
+ }))).then(function (collections) {
957
1014
  var _nextState$isOpen2;
958
1015
 
1016
+ // Parameters passed to `onInput` could be stale when the following code
1017
+ // executes, because `onInput` calls may not resolve in order.
1018
+ // If it becomes a problem we'll need to save the last passed parameters.
1019
+ // See: https://codesandbox.io/s/agitated-cookies-y290z
959
1020
  setStatus('idle');
960
1021
  setCollections(collections);
961
1022
  var isPanelOpen = props.shouldPanelOpen({
@@ -980,10 +1041,13 @@
980
1041
  }, setters));
981
1042
  }
982
1043
  }).finally(function () {
1044
+ setStatus('idle');
1045
+
983
1046
  if (lastStalledId) {
984
1047
  props.environment.clearTimeout(lastStalledId);
985
1048
  }
986
1049
  });
1050
+ return store.pendingRequests.add(request);
987
1051
  }
988
1052
 
989
1053
  var _excluded$1 = ["event", "props", "refresh", "store"];
@@ -1061,7 +1125,12 @@
1061
1125
  // from removing the query right away because we first want to close the
1062
1126
  // panel.
1063
1127
  event.preventDefault();
1064
- store.dispatch(event.key, null);
1128
+ store.dispatch(event.key, null); // Hitting the `Escape` key signals the end of a user interaction with the
1129
+ // autocomplete. At this point, we should ignore any requests that are still
1130
+ // pending and could reopen the panel once they resolve, because that would
1131
+ // result in an unsolicited UI behavior.
1132
+
1133
+ store.pendingRequests.cancelAll();
1065
1134
  } else if (event.key === 'Enter') {
1066
1135
  // No active item, so we let the browser handle the native `onSubmit` form
1067
1136
  // event.
@@ -1158,7 +1227,7 @@
1158
1227
  }
1159
1228
  }
1160
1229
 
1161
- var _excluded$2 = ["props", "refresh", "store"],
1230
+ var _excluded = ["props", "refresh", "store"],
1162
1231
  _excluded2 = ["inputElement", "formElement", "panelElement"],
1163
1232
  _excluded3 = ["inputElement"],
1164
1233
  _excluded4 = ["inputElement", "maxLength"],
@@ -1167,7 +1236,7 @@
1167
1236
  var props = _ref.props,
1168
1237
  refresh = _ref.refresh,
1169
1238
  store = _ref.store,
1170
- setters = _objectWithoutProperties(_ref, _excluded$2);
1239
+ setters = _objectWithoutProperties(_ref, _excluded);
1171
1240
 
1172
1241
  var getEnvironmentProps = function getEnvironmentProps(providedProps) {
1173
1242
  var inputElement = providedProps.inputElement,
@@ -1184,7 +1253,15 @@
1184
1253
  // @TODO: support cases where there are multiple Autocomplete instances.
1185
1254
  // Right now, a second instance makes this computation return false.
1186
1255
  onTouchStart: function onTouchStart(event) {
1187
- if (store.getState().isOpen === false || event.target === inputElement) {
1256
+ // The `onTouchStart` event shouldn't trigger the `blur` handler when
1257
+ // it's not an interaction with Autocomplete. We detect it with the
1258
+ // following heuristics:
1259
+ // - the panel is closed AND there are no pending requests
1260
+ // (no interaction with the autocomplete, no future state updates)
1261
+ // - OR the touched target is the input element (should open the panel)
1262
+ var isAutocompleteInteraction = store.getState().isOpen || !store.pendingRequests.isEmpty();
1263
+
1264
+ if (!isAutocompleteInteraction || event.target === inputElement) {
1188
1265
  return;
1189
1266
  }
1190
1267
 
@@ -1193,7 +1270,14 @@
1193
1270
  });
1194
1271
 
1195
1272
  if (isTargetWithinAutocomplete === false) {
1196
- store.dispatch('blur', null);
1273
+ store.dispatch('blur', null); // If requests are still pending when the user closes the panel, they
1274
+ // could reopen the panel once they resolve.
1275
+ // We want to prevent any subsequent query from reopening the panel
1276
+ // because it would result in an unsolicited UI behavior.
1277
+
1278
+ if (!props.debug) {
1279
+ store.pendingRequests.cancelAll();
1280
+ }
1197
1281
  }
1198
1282
  },
1199
1283
  // When scrolling on touch devices (mobiles, tablets, etc.), we want to
@@ -1221,8 +1305,8 @@
1221
1305
  };
1222
1306
 
1223
1307
  var getFormProps = function getFormProps(providedProps) {
1224
- var inputElement = providedProps.inputElement,
1225
- rest = _objectWithoutProperties(providedProps, _excluded3);
1308
+ providedProps.inputElement;
1309
+ var rest = _objectWithoutProperties(providedProps, _excluded3);
1226
1310
 
1227
1311
  return _objectSpread2({
1228
1312
  action: '',
@@ -1274,9 +1358,9 @@
1274
1358
 
1275
1359
  var isTouchDevice = ('ontouchstart' in props.environment);
1276
1360
 
1277
- var _ref2 = providedProps || {},
1278
- inputElement = _ref2.inputElement,
1279
- _ref2$maxLength = _ref2.maxLength,
1361
+ var _ref2 = providedProps || {};
1362
+ _ref2.inputElement;
1363
+ var _ref2$maxLength = _ref2.maxLength,
1280
1364
  maxLength = _ref2$maxLength === void 0 ? 512 : _ref2$maxLength,
1281
1365
  rest = _objectWithoutProperties(_ref2, _excluded4);
1282
1366
 
@@ -1319,7 +1403,14 @@
1319
1403
  // We do rely on the `blur` event on touch devices.
1320
1404
  // See explanation in `onTouchStart`.
1321
1405
  if (!isTouchDevice) {
1322
- store.dispatch('blur', null);
1406
+ store.dispatch('blur', null); // If requests are still pending when the user closes the panel, they
1407
+ // could reopen the panel once they resolve.
1408
+ // We want to prevent any subsequent query from reopening the panel
1409
+ // because it would result in an unsolicited UI behavior.
1410
+
1411
+ if (!props.debug) {
1412
+ store.pendingRequests.cancelAll();
1413
+ }
1323
1414
  }
1324
1415
  },
1325
1416
  onClick: function onClick(event) {
@@ -1730,5 +1821,5 @@
1730
1821
 
1731
1822
  Object.defineProperty(exports, '__esModule', { value: true });
1732
1823
 
1733
- })));
1824
+ }));
1734
1825
  //# sourceMappingURL=index.development.js.map