downshift 7.1.2 → 7.1.3-alpha.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.
@@ -2,26 +2,18 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var _objectWithoutPropertiesLoose = require('@babel/runtime/helpers/objectWithoutPropertiesLoose');
6
- var _extends = require('@babel/runtime/helpers/extends');
7
- var _assertThisInitialized = require('@babel/runtime/helpers/assertThisInitialized');
8
- var _inheritsLoose = require('@babel/runtime/helpers/inheritsLoose');
9
5
  var preact = require('preact');
10
6
  var reactIs = require('react-is');
11
- var computeScrollIntoView = require('compute-scroll-into-view');
7
+ var compute = require('compute-scroll-into-view');
12
8
  var tslib = require('tslib');
13
9
  var PropTypes = require('prop-types');
14
10
 
15
11
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
16
12
 
17
- var _objectWithoutPropertiesLoose__default = /*#__PURE__*/_interopDefaultLegacy(_objectWithoutPropertiesLoose);
18
- var _extends__default = /*#__PURE__*/_interopDefaultLegacy(_extends);
19
- var _assertThisInitialized__default = /*#__PURE__*/_interopDefaultLegacy(_assertThisInitialized);
20
- var _inheritsLoose__default = /*#__PURE__*/_interopDefaultLegacy(_inheritsLoose);
21
- var computeScrollIntoView__default = /*#__PURE__*/_interopDefaultLegacy(computeScrollIntoView);
13
+ var compute__default = /*#__PURE__*/_interopDefaultLegacy(compute);
22
14
  var PropTypes__default = /*#__PURE__*/_interopDefaultLegacy(PropTypes);
23
15
 
24
- var idCounter = 0;
16
+ let idCounter = 0;
25
17
 
26
18
  /**
27
19
  * Accepts a parameter and returns it if it's a function
@@ -45,15 +37,17 @@ function scrollIntoView(node, menuNode) {
45
37
  if (!node) {
46
38
  return;
47
39
  }
48
- var actions = computeScrollIntoView__default["default"](node, {
40
+ const actions = compute__default["default"](node, {
49
41
  boundary: menuNode,
50
42
  block: 'nearest',
51
43
  scrollMode: 'if-needed'
52
44
  });
53
- actions.forEach(function (_ref) {
54
- var el = _ref.el,
55
- top = _ref.top,
56
- left = _ref.left;
45
+ actions.forEach(_ref => {
46
+ let {
47
+ el,
48
+ top,
49
+ left
50
+ } = _ref;
57
51
  el.scrollTop = top;
58
52
  el.scrollLeft = left;
59
53
  });
@@ -66,7 +60,7 @@ function scrollIntoView(node, menuNode) {
66
60
  * @return {Boolean} whether the parent is the child or the child is in the parent
67
61
  */
68
62
  function isOrContainsNode(parent, child, environment) {
69
- var result = parent === child || child instanceof environment.Node && parent.contains && parent.contains(child);
63
+ const result = parent === child || child instanceof environment.Node && parent.contains && parent.contains(child);
70
64
  return result;
71
65
  }
72
66
 
@@ -79,7 +73,7 @@ function isOrContainsNode(parent, child, environment) {
79
73
  * @return {Function} the debounced function
80
74
  */
81
75
  function debounce(fn, time) {
82
- var timeoutId;
76
+ let timeoutId;
83
77
  function cancel() {
84
78
  if (timeoutId) {
85
79
  clearTimeout(timeoutId);
@@ -90,9 +84,9 @@ function debounce(fn, time) {
90
84
  args[_key] = arguments[_key];
91
85
  }
92
86
  cancel();
93
- timeoutId = setTimeout(function () {
87
+ timeoutId = setTimeout(() => {
94
88
  timeoutId = null;
95
- fn.apply(void 0, args);
89
+ fn(...args);
96
90
  }, time);
97
91
  }
98
92
  wrapper.cancel = cancel;
@@ -114,9 +108,9 @@ function callAllEventHandlers() {
114
108
  for (var _len3 = arguments.length, args = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) {
115
109
  args[_key3 - 1] = arguments[_key3];
116
110
  }
117
- return fns.some(function (fn) {
111
+ return fns.some(fn => {
118
112
  if (fn) {
119
- fn.apply(void 0, [event].concat(args));
113
+ fn(event, ...args);
120
114
  }
121
115
  return event.preventDownshiftDefault || event.hasOwnProperty('nativeEvent') && event.nativeEvent.preventDownshiftDefault;
122
116
  });
@@ -126,8 +120,8 @@ function handleRefs() {
126
120
  for (var _len4 = arguments.length, refs = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
127
121
  refs[_key4] = arguments[_key4];
128
122
  }
129
- return function (node) {
130
- refs.forEach(function (ref) {
123
+ return node => {
124
+ refs.forEach(ref => {
131
125
  if (typeof ref === 'function') {
132
126
  ref(node);
133
127
  } else if (ref) {
@@ -161,9 +155,11 @@ function resetIdCounter() {
161
155
  * @return {String} the a11y status message
162
156
  */
163
157
  function getA11yStatusMessage$1(_ref2) {
164
- var isOpen = _ref2.isOpen,
165
- resultCount = _ref2.resultCount,
166
- previousResultCount = _ref2.previousResultCount;
158
+ let {
159
+ isOpen,
160
+ resultCount,
161
+ previousResultCount
162
+ } = _ref2;
167
163
  if (!isOpen) {
168
164
  return '';
169
165
  }
@@ -171,7 +167,7 @@ function getA11yStatusMessage$1(_ref2) {
171
167
  return 'No results are available.';
172
168
  }
173
169
  if (resultCount !== previousResultCount) {
174
- return resultCount + " result" + (resultCount === 1 ? ' is' : 's are') + " available, use up and down arrow keys to navigate. Press Enter key to select.";
170
+ return `${resultCount} result${resultCount === 1 ? ' is' : 's are'} available, use up and down arrow keys to navigate. Press Enter key to select.`;
175
171
  }
176
172
  return '';
177
173
  }
@@ -225,9 +221,9 @@ function getElementProps(element) {
225
221
  */
226
222
  function requiredProp(fnName, propName) {
227
223
  // eslint-disable-next-line no-console
228
- console.error("The property \"" + propName + "\" is required in \"" + fnName + "\"");
224
+ console.error(`The property "${propName}" is required in "${fnName}"`);
229
225
  }
230
- var stateKeys = ['highlightedIndex', 'inputValue', 'isOpen', 'selectedItem', 'type'];
226
+ const stateKeys = ['highlightedIndex', 'inputValue', 'isOpen', 'selectedItem', 'type'];
231
227
  /**
232
228
  * @param {Object} state the state object
233
229
  * @return {Object} state that is relevant to downshift
@@ -236,8 +232,8 @@ function pickState(state) {
236
232
  if (state === void 0) {
237
233
  state = {};
238
234
  }
239
- var result = {};
240
- stateKeys.forEach(function (k) {
235
+ const result = {};
236
+ stateKeys.forEach(k => {
241
237
  if (state.hasOwnProperty(k)) {
242
238
  result[k] = state[k];
243
239
  }
@@ -257,7 +253,7 @@ function pickState(state) {
257
253
  * @returns {Object} The merged controlled state.
258
254
  */
259
255
  function getState(state, props) {
260
- return Object.keys(state).reduce(function (prevState, key) {
256
+ return Object.keys(state).reduce((prevState, key) => {
261
257
  prevState[key] = isControlledProp(props, key) ? props[key] : state[key];
262
258
  return prevState;
263
259
  }, {});
@@ -282,11 +278,13 @@ function isControlledProp(props, key) {
282
278
  * @return {String} keyboard key
283
279
  */
284
280
  function normalizeArrowKey(event) {
285
- var key = event.key,
286
- keyCode = event.keyCode;
281
+ const {
282
+ key,
283
+ keyCode
284
+ } = event;
287
285
  /* istanbul ignore next (ie) */
288
286
  if (keyCode >= 37 && keyCode <= 40 && key.indexOf('Arrow') !== 0) {
289
- return "Arrow" + key;
287
+ return `Arrow${key}`;
290
288
  }
291
289
  return key;
292
290
  }
@@ -318,17 +316,17 @@ function getNextWrappingIndex(moveAmount, baseIndex, itemCount, getItemNodeFromI
318
316
  if (itemCount === 0) {
319
317
  return -1;
320
318
  }
321
- var itemsLastIndex = itemCount - 1;
319
+ const itemsLastIndex = itemCount - 1;
322
320
  if (typeof baseIndex !== 'number' || baseIndex < 0 || baseIndex >= itemCount) {
323
321
  baseIndex = moveAmount > 0 ? -1 : itemsLastIndex + 1;
324
322
  }
325
- var newIndex = baseIndex + moveAmount;
323
+ let newIndex = baseIndex + moveAmount;
326
324
  if (newIndex < 0) {
327
325
  newIndex = circular ? itemsLastIndex : 0;
328
326
  } else if (newIndex > itemsLastIndex) {
329
327
  newIndex = circular ? 0 : itemsLastIndex;
330
328
  }
331
- var nonDisabledNewIndex = getNextNonDisabledIndex(moveAmount, newIndex, itemCount, getItemNodeFromIndex, circular);
329
+ const nonDisabledNewIndex = getNextNonDisabledIndex(moveAmount, newIndex, itemCount, getItemNodeFromIndex, circular);
332
330
  if (nonDisabledNewIndex === -1) {
333
331
  return baseIndex >= itemCount ? -1 : baseIndex;
334
332
  }
@@ -346,20 +344,20 @@ function getNextWrappingIndex(moveAmount, baseIndex, itemCount, getItemNodeFromI
346
344
  * @returns {number} The new index. Returns baseIndex if item is not disabled. Returns next non-disabled item otherwise. If no non-disabled found it will return -1.
347
345
  */
348
346
  function getNextNonDisabledIndex(moveAmount, baseIndex, itemCount, getItemNodeFromIndex, circular) {
349
- var currentElementNode = getItemNodeFromIndex(baseIndex);
347
+ const currentElementNode = getItemNodeFromIndex(baseIndex);
350
348
  if (!currentElementNode || !currentElementNode.hasAttribute('disabled')) {
351
349
  return baseIndex;
352
350
  }
353
351
  if (moveAmount > 0) {
354
- for (var index = baseIndex + 1; index < itemCount; index++) {
352
+ for (let index = baseIndex + 1; index < itemCount; index++) {
355
353
  if (!getItemNodeFromIndex(index).hasAttribute('disabled')) {
356
354
  return index;
357
355
  }
358
356
  }
359
357
  } else {
360
- for (var _index = baseIndex - 1; _index >= 0; _index--) {
361
- if (!getItemNodeFromIndex(_index).hasAttribute('disabled')) {
362
- return _index;
358
+ for (let index = baseIndex - 1; index >= 0; index--) {
359
+ if (!getItemNodeFromIndex(index).hasAttribute('disabled')) {
360
+ return index;
363
361
  }
364
362
  }
365
363
  }
@@ -383,30 +381,28 @@ function targetWithinDownshift(target, downshiftElements, environment, checkActi
383
381
  if (checkActiveElement === void 0) {
384
382
  checkActiveElement = true;
385
383
  }
386
- return downshiftElements.some(function (contextNode) {
387
- return contextNode && (isOrContainsNode(contextNode, target, environment) || checkActiveElement && isOrContainsNode(contextNode, environment.document.activeElement, environment));
388
- });
384
+ return downshiftElements.some(contextNode => contextNode && (isOrContainsNode(contextNode, target, environment) || checkActiveElement && isOrContainsNode(contextNode, environment.document.activeElement, environment)));
389
385
  }
390
386
 
391
387
  // eslint-disable-next-line import/no-mutable-exports
392
- var validateControlledUnchanged = noop;
388
+ let validateControlledUnchanged = noop;
393
389
  /* istanbul ignore next */
394
390
  if (process.env.NODE_ENV !== 'production') {
395
- validateControlledUnchanged = function validateControlledUnchanged(state, prevProps, nextProps) {
396
- var warningDescription = "This prop should not switch from controlled to uncontrolled (or vice versa). Decide between using a controlled or uncontrolled Downshift element for the lifetime of the component. More info: https://github.com/downshift-js/downshift#control-props";
397
- Object.keys(state).forEach(function (propKey) {
391
+ validateControlledUnchanged = (state, prevProps, nextProps) => {
392
+ const warningDescription = `This prop should not switch from controlled to uncontrolled (or vice versa). Decide between using a controlled or uncontrolled Downshift element for the lifetime of the component. More info: https://github.com/downshift-js/downshift#control-props`;
393
+ Object.keys(state).forEach(propKey => {
398
394
  if (prevProps[propKey] !== undefined && nextProps[propKey] === undefined) {
399
395
  // eslint-disable-next-line no-console
400
- console.error("downshift: A component has changed the controlled prop \"" + propKey + "\" to be uncontrolled. " + warningDescription);
396
+ console.error(`downshift: A component has changed the controlled prop "${propKey}" to be uncontrolled. ${warningDescription}`);
401
397
  } else if (prevProps[propKey] === undefined && nextProps[propKey] !== undefined) {
402
398
  // eslint-disable-next-line no-console
403
- console.error("downshift: A component has changed the uncontrolled prop \"" + propKey + "\" to be controlled. " + warningDescription);
399
+ console.error(`downshift: A component has changed the uncontrolled prop "${propKey}" to be controlled. ${warningDescription}`);
404
400
  }
405
401
  });
406
402
  };
407
403
  }
408
404
 
409
- var cleanupStatus = debounce(function (documentProp) {
405
+ const cleanupStatus = debounce(documentProp => {
410
406
  getStatusDiv(documentProp).textContent = '';
411
407
  }, 500);
412
408
 
@@ -415,7 +411,7 @@ var cleanupStatus = debounce(function (documentProp) {
415
411
  * @param {Object} documentProp document passed by the user.
416
412
  */
417
413
  function setStatus(status, documentProp) {
418
- var div = getStatusDiv(documentProp);
414
+ const div = getStatusDiv(documentProp);
419
415
  if (!status) {
420
416
  return;
421
417
  }
@@ -432,7 +428,7 @@ function getStatusDiv(documentProp) {
432
428
  if (documentProp === void 0) {
433
429
  documentProp = document;
434
430
  }
435
- var statusDiv = documentProp.getElementById('a11y-status-message');
431
+ let statusDiv = documentProp.getElementById('a11y-status-message');
436
432
  if (statusDiv) {
437
433
  return statusDiv;
438
434
  }
@@ -455,23 +451,23 @@ function getStatusDiv(documentProp) {
455
451
  return statusDiv;
456
452
  }
457
453
 
458
- var unknown = process.env.NODE_ENV !== "production" ? '__autocomplete_unknown__' : 0;
459
- var mouseUp = process.env.NODE_ENV !== "production" ? '__autocomplete_mouseup__' : 1;
460
- var itemMouseEnter = process.env.NODE_ENV !== "production" ? '__autocomplete_item_mouseenter__' : 2;
461
- var keyDownArrowUp = process.env.NODE_ENV !== "production" ? '__autocomplete_keydown_arrow_up__' : 3;
462
- var keyDownArrowDown = process.env.NODE_ENV !== "production" ? '__autocomplete_keydown_arrow_down__' : 4;
463
- var keyDownEscape = process.env.NODE_ENV !== "production" ? '__autocomplete_keydown_escape__' : 5;
464
- var keyDownEnter = process.env.NODE_ENV !== "production" ? '__autocomplete_keydown_enter__' : 6;
465
- var keyDownHome = process.env.NODE_ENV !== "production" ? '__autocomplete_keydown_home__' : 7;
466
- var keyDownEnd = process.env.NODE_ENV !== "production" ? '__autocomplete_keydown_end__' : 8;
467
- var clickItem = process.env.NODE_ENV !== "production" ? '__autocomplete_click_item__' : 9;
468
- var blurInput = process.env.NODE_ENV !== "production" ? '__autocomplete_blur_input__' : 10;
469
- var changeInput = process.env.NODE_ENV !== "production" ? '__autocomplete_change_input__' : 11;
470
- var keyDownSpaceButton = process.env.NODE_ENV !== "production" ? '__autocomplete_keydown_space_button__' : 12;
471
- var clickButton = process.env.NODE_ENV !== "production" ? '__autocomplete_click_button__' : 13;
472
- var blurButton = process.env.NODE_ENV !== "production" ? '__autocomplete_blur_button__' : 14;
473
- var controlledPropUpdatedSelectedItem = process.env.NODE_ENV !== "production" ? '__autocomplete_controlled_prop_updated_selected_item__' : 15;
474
- var touchEnd = process.env.NODE_ENV !== "production" ? '__autocomplete_touchend__' : 16;
454
+ const unknown = process.env.NODE_ENV !== "production" ? '__autocomplete_unknown__' : 0;
455
+ const mouseUp = process.env.NODE_ENV !== "production" ? '__autocomplete_mouseup__' : 1;
456
+ const itemMouseEnter = process.env.NODE_ENV !== "production" ? '__autocomplete_item_mouseenter__' : 2;
457
+ const keyDownArrowUp = process.env.NODE_ENV !== "production" ? '__autocomplete_keydown_arrow_up__' : 3;
458
+ const keyDownArrowDown = process.env.NODE_ENV !== "production" ? '__autocomplete_keydown_arrow_down__' : 4;
459
+ const keyDownEscape = process.env.NODE_ENV !== "production" ? '__autocomplete_keydown_escape__' : 5;
460
+ const keyDownEnter = process.env.NODE_ENV !== "production" ? '__autocomplete_keydown_enter__' : 6;
461
+ const keyDownHome = process.env.NODE_ENV !== "production" ? '__autocomplete_keydown_home__' : 7;
462
+ const keyDownEnd = process.env.NODE_ENV !== "production" ? '__autocomplete_keydown_end__' : 8;
463
+ const clickItem = process.env.NODE_ENV !== "production" ? '__autocomplete_click_item__' : 9;
464
+ const blurInput = process.env.NODE_ENV !== "production" ? '__autocomplete_blur_input__' : 10;
465
+ const changeInput = process.env.NODE_ENV !== "production" ? '__autocomplete_change_input__' : 11;
466
+ const keyDownSpaceButton = process.env.NODE_ENV !== "production" ? '__autocomplete_keydown_space_button__' : 12;
467
+ const clickButton = process.env.NODE_ENV !== "production" ? '__autocomplete_click_button__' : 13;
468
+ const blurButton = process.env.NODE_ENV !== "production" ? '__autocomplete_blur_button__' : 14;
469
+ const controlledPropUpdatedSelectedItem = process.env.NODE_ENV !== "production" ? '__autocomplete_controlled_prop_updated_selected_item__' : 15;
470
+ const touchEnd = process.env.NODE_ENV !== "production" ? '__autocomplete_touchend__' : 16;
475
471
 
476
472
  var stateChangeTypes$3 = /*#__PURE__*/Object.freeze({
477
473
  __proto__: null,
@@ -494,48 +490,37 @@ var stateChangeTypes$3 = /*#__PURE__*/Object.freeze({
494
490
  touchEnd: touchEnd
495
491
  });
496
492
 
497
- var _excluded$4 = ["refKey", "ref"],
498
- _excluded2$3 = ["onClick", "onPress", "onKeyDown", "onKeyUp", "onBlur"],
499
- _excluded3$2 = ["onKeyDown", "onBlur", "onChange", "onInput", "onChangeText"],
500
- _excluded4$1 = ["refKey", "ref"],
501
- _excluded5 = ["onMouseMove", "onMouseDown", "onClick", "onPress", "index", "item"];
502
- var Downshift = /*#__PURE__*/function () {
503
- var Downshift = /*#__PURE__*/function (_Component) {
504
- _inheritsLoose__default["default"](Downshift, _Component);
505
- function Downshift(_props) {
493
+ /* eslint camelcase:0 */
494
+ const Downshift = /*#__PURE__*/(() => {
495
+ class Downshift extends preact.Component {
496
+ constructor(_props) {
506
497
  var _this;
507
- _this = _Component.call(this, _props) || this;
508
- // fancy destructuring + defaults + aliases
509
- // this basically says each value of state should either be set to
510
- // the initial value or the default value if the initial value is not provided
511
- _this.id = _this.props.id || "downshift-" + generateId();
512
- _this.menuId = _this.props.menuId || _this.id + "-menu";
513
- _this.labelId = _this.props.labelId || _this.id + "-label";
514
- _this.inputId = _this.props.inputId || _this.id + "-input";
515
- _this.getItemId = _this.props.getItemId || function (index) {
516
- return _this.id + "-item-" + index;
517
- };
518
- _this.input = null;
519
- _this.items = [];
520
- _this.itemCount = null;
521
- _this.previousResultCount = 0;
522
- _this.timeoutIds = [];
523
- _this.internalSetTimeout = function (fn, time) {
524
- var id = setTimeout(function () {
525
- _this.timeoutIds = _this.timeoutIds.filter(function (i) {
526
- return i !== id;
527
- });
498
+ super(_props);
499
+ _this = this;
500
+ this.id = this.props.id || `downshift-${generateId()}`;
501
+ this.menuId = this.props.menuId || `${this.id}-menu`;
502
+ this.labelId = this.props.labelId || `${this.id}-label`;
503
+ this.inputId = this.props.inputId || `${this.id}-input`;
504
+ this.getItemId = this.props.getItemId || (index => `${this.id}-item-${index}`);
505
+ this.input = null;
506
+ this.items = [];
507
+ this.itemCount = null;
508
+ this.previousResultCount = 0;
509
+ this.timeoutIds = [];
510
+ this.internalSetTimeout = (fn, time) => {
511
+ const id = setTimeout(() => {
512
+ this.timeoutIds = this.timeoutIds.filter(i => i !== id);
528
513
  fn();
529
514
  }, time);
530
- _this.timeoutIds.push(id);
515
+ this.timeoutIds.push(id);
531
516
  };
532
- _this.setItemCount = function (count) {
533
- _this.itemCount = count;
517
+ this.setItemCount = count => {
518
+ this.itemCount = count;
534
519
  };
535
- _this.unsetItemCount = function () {
536
- _this.itemCount = null;
520
+ this.unsetItemCount = () => {
521
+ this.itemCount = null;
537
522
  };
538
- _this.setHighlightedIndex = function (highlightedIndex, otherStateToSet) {
523
+ this.setHighlightedIndex = function (highlightedIndex, otherStateToSet) {
539
524
  if (highlightedIndex === void 0) {
540
525
  highlightedIndex = _this.props.defaultHighlightedIndex;
541
526
  }
@@ -543,41 +528,43 @@ var Downshift = /*#__PURE__*/function () {
543
528
  otherStateToSet = {};
544
529
  }
545
530
  otherStateToSet = pickState(otherStateToSet);
546
- _this.internalSetState(_extends__default["default"]({
547
- highlightedIndex: highlightedIndex
548
- }, otherStateToSet));
549
- };
550
- _this.clearSelection = function (cb) {
551
531
  _this.internalSetState({
532
+ highlightedIndex,
533
+ ...otherStateToSet
534
+ });
535
+ };
536
+ this.clearSelection = cb => {
537
+ this.internalSetState({
552
538
  selectedItem: null,
553
539
  inputValue: '',
554
- highlightedIndex: _this.props.defaultHighlightedIndex,
555
- isOpen: _this.props.defaultIsOpen
540
+ highlightedIndex: this.props.defaultHighlightedIndex,
541
+ isOpen: this.props.defaultIsOpen
556
542
  }, cb);
557
543
  };
558
- _this.selectItem = function (item, otherStateToSet, cb) {
544
+ this.selectItem = (item, otherStateToSet, cb) => {
559
545
  otherStateToSet = pickState(otherStateToSet);
560
- _this.internalSetState(_extends__default["default"]({
561
- isOpen: _this.props.defaultIsOpen,
562
- highlightedIndex: _this.props.defaultHighlightedIndex,
546
+ this.internalSetState({
547
+ isOpen: this.props.defaultIsOpen,
548
+ highlightedIndex: this.props.defaultHighlightedIndex,
563
549
  selectedItem: item,
564
- inputValue: _this.props.itemToString(item)
565
- }, otherStateToSet), cb);
550
+ inputValue: this.props.itemToString(item),
551
+ ...otherStateToSet
552
+ }, cb);
566
553
  };
567
- _this.selectItemAtIndex = function (itemIndex, otherStateToSet, cb) {
568
- var item = _this.items[itemIndex];
554
+ this.selectItemAtIndex = (itemIndex, otherStateToSet, cb) => {
555
+ const item = this.items[itemIndex];
569
556
  if (item == null) {
570
557
  return;
571
558
  }
572
- _this.selectItem(item, otherStateToSet, cb);
559
+ this.selectItem(item, otherStateToSet, cb);
573
560
  };
574
- _this.selectHighlightedItem = function (otherStateToSet, cb) {
575
- return _this.selectItemAtIndex(_this.getState().highlightedIndex, otherStateToSet, cb);
561
+ this.selectHighlightedItem = (otherStateToSet, cb) => {
562
+ return this.selectItemAtIndex(this.getState().highlightedIndex, otherStateToSet, cb);
576
563
  };
577
- _this.internalSetState = function (stateToSet, cb) {
578
- var isItemSelected, onChangeArg;
579
- var onStateChangeArg = {};
580
- var isStateToSetFunction = typeof stateToSet === 'function';
564
+ this.internalSetState = (stateToSet, cb) => {
565
+ let isItemSelected, onChangeArg;
566
+ const onStateChangeArg = {};
567
+ const isStateToSetFunction = typeof stateToSet === 'function';
581
568
 
582
569
  // we want to call `onInputValueChange` before the `setState` call
583
570
  // so someone controlling the `inputValue` state gets notified of
@@ -585,21 +572,24 @@ var Downshift = /*#__PURE__*/function () {
585
572
  // preserving the cursor position.
586
573
  // See https://github.com/downshift-js/downshift/issues/217 for more info.
587
574
  if (!isStateToSetFunction && stateToSet.hasOwnProperty('inputValue')) {
588
- _this.props.onInputValueChange(stateToSet.inputValue, _extends__default["default"]({}, _this.getStateAndHelpers(), stateToSet));
575
+ this.props.onInputValueChange(stateToSet.inputValue, {
576
+ ...this.getStateAndHelpers(),
577
+ ...stateToSet
578
+ });
589
579
  }
590
- return _this.setState(function (state) {
591
- state = _this.getState(state);
592
- var newStateToSet = isStateToSetFunction ? stateToSet(state) : stateToSet;
580
+ return this.setState(state => {
581
+ state = this.getState(state);
582
+ let newStateToSet = isStateToSetFunction ? stateToSet(state) : stateToSet;
593
583
 
594
584
  // Your own function that could modify the state that will be set.
595
- newStateToSet = _this.props.stateReducer(state, newStateToSet);
585
+ newStateToSet = this.props.stateReducer(state, newStateToSet);
596
586
 
597
587
  // checks if an item is selected, regardless of if it's different from
598
588
  // what was selected before
599
589
  // used to determine if onSelect and onChange callbacks should be called
600
590
  isItemSelected = newStateToSet.hasOwnProperty('selectedItem');
601
591
  // this keeps track of the object we want to call with setState
602
- var nextState = {};
592
+ const nextState = {};
603
593
  // we need to call on change if the outside world is controlling any of our state
604
594
  // and we're trying to update that state. OR if the selection has changed and we're
605
595
  // trying to update the selection
@@ -607,7 +597,7 @@ var Downshift = /*#__PURE__*/function () {
607
597
  onChangeArg = newStateToSet.selectedItem;
608
598
  }
609
599
  newStateToSet.type = newStateToSet.type || unknown;
610
- Object.keys(newStateToSet).forEach(function (key) {
600
+ Object.keys(newStateToSet).forEach(key => {
611
601
  // onStateChangeArg should only have the state that is
612
602
  // actually changing
613
603
  if (state[key] !== newStateToSet[key]) {
@@ -624,7 +614,7 @@ var Downshift = /*#__PURE__*/function () {
624
614
  }
625
615
  newStateToSet[key];
626
616
  // if it's coming from props, then we don't care to set it internally
627
- if (!isControlledProp(_this.props, key)) {
617
+ if (!isControlledProp(this.props, key)) {
628
618
  nextState[key] = newStateToSet[key];
629
619
  }
630
620
  });
@@ -632,58 +622,66 @@ var Downshift = /*#__PURE__*/function () {
632
622
  // if stateToSet is a function, then we weren't able to call onInputValueChange
633
623
  // earlier, so we'll call it now that we know what the inputValue state will be.
634
624
  if (isStateToSetFunction && newStateToSet.hasOwnProperty('inputValue')) {
635
- _this.props.onInputValueChange(newStateToSet.inputValue, _extends__default["default"]({}, _this.getStateAndHelpers(), newStateToSet));
625
+ this.props.onInputValueChange(newStateToSet.inputValue, {
626
+ ...this.getStateAndHelpers(),
627
+ ...newStateToSet
628
+ });
636
629
  }
637
630
  return nextState;
638
- }, function () {
631
+ }, () => {
639
632
  // call the provided callback if it's a function
640
633
  cbToCb(cb)();
641
634
 
642
635
  // only call the onStateChange and onChange callbacks if
643
636
  // we have relevant information to pass them.
644
- var hasMoreStateThanType = Object.keys(onStateChangeArg).length > 1;
637
+ const hasMoreStateThanType = Object.keys(onStateChangeArg).length > 1;
645
638
  if (hasMoreStateThanType) {
646
- _this.props.onStateChange(onStateChangeArg, _this.getStateAndHelpers());
639
+ this.props.onStateChange(onStateChangeArg, this.getStateAndHelpers());
647
640
  }
648
641
  if (isItemSelected) {
649
- _this.props.onSelect(stateToSet.selectedItem, _this.getStateAndHelpers());
642
+ this.props.onSelect(stateToSet.selectedItem, this.getStateAndHelpers());
650
643
  }
651
644
  if (onChangeArg !== undefined) {
652
- _this.props.onChange(onChangeArg, _this.getStateAndHelpers());
645
+ this.props.onChange(onChangeArg, this.getStateAndHelpers());
653
646
  }
654
647
  // this is currently undocumented and therefore subject to change
655
648
  // We'll try to not break it, but just be warned.
656
- _this.props.onUserAction(onStateChangeArg, _this.getStateAndHelpers());
649
+ this.props.onUserAction(onStateChangeArg, this.getStateAndHelpers());
657
650
  });
658
651
  };
659
- _this.rootRef = function (node) {
660
- return _this._rootNode = node;
661
- };
662
- _this.getRootProps = function (_temp, _temp2) {
663
- var _extends2;
664
- var _ref = _temp === void 0 ? {} : _temp,
665
- _ref$refKey = _ref.refKey,
666
- refKey = _ref$refKey === void 0 ? 'ref' : _ref$refKey,
667
- ref = _ref.ref,
668
- rest = _objectWithoutPropertiesLoose__default["default"](_ref, _excluded$4);
669
- var _ref2 = _temp2 === void 0 ? {} : _temp2,
670
- _ref2$suppressRefErro = _ref2.suppressRefError,
671
- suppressRefError = _ref2$suppressRefErro === void 0 ? false : _ref2$suppressRefErro;
652
+ this.rootRef = node => this._rootNode = node;
653
+ this.getRootProps = function (_temp, _temp2) {
654
+ let {
655
+ refKey = 'ref',
656
+ ref,
657
+ ...rest
658
+ } = _temp === void 0 ? {} : _temp;
659
+ let {
660
+ suppressRefError = false
661
+ } = _temp2 === void 0 ? {} : _temp2;
672
662
  // this is used in the render to know whether the user has called getRootProps.
673
663
  // It uses that to know whether to apply the props automatically
674
664
  _this.getRootProps.called = true;
675
665
  _this.getRootProps.refKey = refKey;
676
666
  _this.getRootProps.suppressRefError = suppressRefError;
677
- var _this$getState = _this.getState(),
678
- isOpen = _this$getState.isOpen;
679
- return _extends__default["default"]((_extends2 = {}, _extends2[refKey] = handleRefs(ref, _this.rootRef), _extends2.role = 'combobox', _extends2['aria-expanded'] = isOpen, _extends2['aria-haspopup'] = 'listbox', _extends2['aria-owns'] = isOpen ? _this.menuId : null, _extends2['aria-labelledby'] = _this.labelId, _extends2), rest);
667
+ const {
668
+ isOpen
669
+ } = _this.getState();
670
+ return {
671
+ [refKey]: handleRefs(ref, _this.rootRef),
672
+ role: 'combobox',
673
+ 'aria-expanded': isOpen,
674
+ 'aria-haspopup': 'listbox',
675
+ 'aria-owns': isOpen ? _this.menuId : null,
676
+ 'aria-labelledby': _this.labelId,
677
+ ...rest
678
+ };
680
679
  };
681
- _this.keyDownHandlers = {
682
- ArrowDown: function ArrowDown(event) {
683
- var _this2 = this;
680
+ this.keyDownHandlers = {
681
+ ArrowDown(event) {
684
682
  event.preventDefault();
685
683
  if (this.getState().isOpen) {
686
- var amount = event.shiftKey ? 5 : 1;
684
+ const amount = event.shiftKey ? 5 : 1;
687
685
  this.moveHighlightedIndex(amount, {
688
686
  type: keyDownArrowDown
689
687
  });
@@ -691,26 +689,24 @@ var Downshift = /*#__PURE__*/function () {
691
689
  this.internalSetState({
692
690
  isOpen: true,
693
691
  type: keyDownArrowDown
694
- }, function () {
695
- var itemCount = _this2.getItemCount();
692
+ }, () => {
693
+ const itemCount = this.getItemCount();
696
694
  if (itemCount > 0) {
697
- var _this2$getState = _this2.getState(),
698
- highlightedIndex = _this2$getState.highlightedIndex;
699
- var nextHighlightedIndex = getNextWrappingIndex(1, highlightedIndex, itemCount, function (index) {
700
- return _this2.getItemNodeFromIndex(index);
701
- });
702
- _this2.setHighlightedIndex(nextHighlightedIndex, {
695
+ const {
696
+ highlightedIndex
697
+ } = this.getState();
698
+ const nextHighlightedIndex = getNextWrappingIndex(1, highlightedIndex, itemCount, index => this.getItemNodeFromIndex(index));
699
+ this.setHighlightedIndex(nextHighlightedIndex, {
703
700
  type: keyDownArrowDown
704
701
  });
705
702
  }
706
703
  });
707
704
  }
708
705
  },
709
- ArrowUp: function ArrowUp(event) {
710
- var _this3 = this;
706
+ ArrowUp(event) {
711
707
  event.preventDefault();
712
708
  if (this.getState().isOpen) {
713
- var amount = event.shiftKey ? -5 : -1;
709
+ const amount = event.shiftKey ? -5 : -1;
714
710
  this.moveHighlightedIndex(amount, {
715
711
  type: keyDownArrowUp
716
712
  });
@@ -718,32 +714,32 @@ var Downshift = /*#__PURE__*/function () {
718
714
  this.internalSetState({
719
715
  isOpen: true,
720
716
  type: keyDownArrowUp
721
- }, function () {
722
- var itemCount = _this3.getItemCount();
717
+ }, () => {
718
+ const itemCount = this.getItemCount();
723
719
  if (itemCount > 0) {
724
- var _this3$getState = _this3.getState(),
725
- highlightedIndex = _this3$getState.highlightedIndex;
726
- var nextHighlightedIndex = getNextWrappingIndex(-1, highlightedIndex, itemCount, function (index) {
727
- return _this3.getItemNodeFromIndex(index);
728
- });
729
- _this3.setHighlightedIndex(nextHighlightedIndex, {
720
+ const {
721
+ highlightedIndex
722
+ } = this.getState();
723
+ const nextHighlightedIndex = getNextWrappingIndex(-1, highlightedIndex, itemCount, index => this.getItemNodeFromIndex(index));
724
+ this.setHighlightedIndex(nextHighlightedIndex, {
730
725
  type: keyDownArrowUp
731
726
  });
732
727
  }
733
728
  });
734
729
  }
735
730
  },
736
- Enter: function Enter(event) {
731
+ Enter(event) {
737
732
  if (event.which === 229) {
738
733
  return;
739
734
  }
740
- var _this$getState2 = this.getState(),
741
- isOpen = _this$getState2.isOpen,
742
- highlightedIndex = _this$getState2.highlightedIndex;
735
+ const {
736
+ isOpen,
737
+ highlightedIndex
738
+ } = this.getState();
743
739
  if (isOpen && highlightedIndex != null) {
744
740
  event.preventDefault();
745
- var item = this.items[highlightedIndex];
746
- var itemNode = this.getItemNodeFromIndex(highlightedIndex);
741
+ const item = this.items[highlightedIndex];
742
+ const itemNode = this.getItemNodeFromIndex(highlightedIndex);
747
743
  if (item == null || itemNode && itemNode.hasAttribute('disabled')) {
748
744
  return;
749
745
  }
@@ -752,169 +748,176 @@ var Downshift = /*#__PURE__*/function () {
752
748
  });
753
749
  }
754
750
  },
755
- Escape: function Escape(event) {
751
+ Escape(event) {
756
752
  event.preventDefault();
757
- this.reset(_extends__default["default"]({
758
- type: keyDownEscape
759
- }, !this.state.isOpen && {
760
- selectedItem: null,
761
- inputValue: ''
762
- }));
753
+ this.reset({
754
+ type: keyDownEscape,
755
+ ...(!this.state.isOpen && {
756
+ selectedItem: null,
757
+ inputValue: ''
758
+ })
759
+ });
763
760
  }
764
761
  };
765
- _this.buttonKeyDownHandlers = _extends__default["default"]({}, _this.keyDownHandlers, {
766
- ' ': function _(event) {
762
+ this.buttonKeyDownHandlers = {
763
+ ...this.keyDownHandlers,
764
+ ' '(event) {
767
765
  event.preventDefault();
768
766
  this.toggleMenu({
769
767
  type: keyDownSpaceButton
770
768
  });
771
769
  }
772
- });
773
- _this.inputKeyDownHandlers = _extends__default["default"]({}, _this.keyDownHandlers, {
774
- Home: function Home(event) {
775
- var _this4 = this;
776
- var _this$getState3 = this.getState(),
777
- isOpen = _this$getState3.isOpen;
770
+ };
771
+ this.inputKeyDownHandlers = {
772
+ ...this.keyDownHandlers,
773
+ Home(event) {
774
+ const {
775
+ isOpen
776
+ } = this.getState();
778
777
  if (!isOpen) {
779
778
  return;
780
779
  }
781
780
  event.preventDefault();
782
- var itemCount = this.getItemCount();
781
+ const itemCount = this.getItemCount();
783
782
  if (itemCount <= 0 || !isOpen) {
784
783
  return;
785
784
  }
786
785
 
787
786
  // get next non-disabled starting downwards from 0 if that's disabled.
788
- var newHighlightedIndex = getNextNonDisabledIndex(1, 0, itemCount, function (index) {
789
- return _this4.getItemNodeFromIndex(index);
790
- }, false);
787
+ const newHighlightedIndex = getNextNonDisabledIndex(1, 0, itemCount, index => this.getItemNodeFromIndex(index), false);
791
788
  this.setHighlightedIndex(newHighlightedIndex, {
792
789
  type: keyDownHome
793
790
  });
794
791
  },
795
- End: function End(event) {
796
- var _this5 = this;
797
- var _this$getState4 = this.getState(),
798
- isOpen = _this$getState4.isOpen;
792
+ End(event) {
793
+ const {
794
+ isOpen
795
+ } = this.getState();
799
796
  if (!isOpen) {
800
797
  return;
801
798
  }
802
799
  event.preventDefault();
803
- var itemCount = this.getItemCount();
800
+ const itemCount = this.getItemCount();
804
801
  if (itemCount <= 0 || !isOpen) {
805
802
  return;
806
803
  }
807
804
 
808
805
  // get next non-disabled starting upwards from last index if that's disabled.
809
- var newHighlightedIndex = getNextNonDisabledIndex(-1, itemCount - 1, itemCount, function (index) {
810
- return _this5.getItemNodeFromIndex(index);
811
- }, false);
806
+ const newHighlightedIndex = getNextNonDisabledIndex(-1, itemCount - 1, itemCount, index => this.getItemNodeFromIndex(index), false);
812
807
  this.setHighlightedIndex(newHighlightedIndex, {
813
808
  type: keyDownEnd
814
809
  });
815
810
  }
816
- });
817
- _this.getToggleButtonProps = function (_temp3) {
818
- var _ref3 = _temp3 === void 0 ? {} : _temp3,
819
- onClick = _ref3.onClick;
820
- _ref3.onPress;
821
- var onKeyDown = _ref3.onKeyDown,
822
- onKeyUp = _ref3.onKeyUp,
823
- onBlur = _ref3.onBlur,
824
- rest = _objectWithoutPropertiesLoose__default["default"](_ref3, _excluded2$3);
825
- var _this$getState5 = _this.getState(),
826
- isOpen = _this$getState5.isOpen;
827
- var enabledEventHandlers = {
811
+ };
812
+ this.getToggleButtonProps = function (_temp3) {
813
+ let {
814
+ onClick,
815
+ onPress,
816
+ onKeyDown,
817
+ onKeyUp,
818
+ onBlur,
819
+ ...rest
820
+ } = _temp3 === void 0 ? {} : _temp3;
821
+ const {
822
+ isOpen
823
+ } = _this.getState();
824
+ const enabledEventHandlers = {
828
825
  onClick: callAllEventHandlers(onClick, _this.buttonHandleClick),
829
826
  onKeyDown: callAllEventHandlers(onKeyDown, _this.buttonHandleKeyDown),
830
827
  onKeyUp: callAllEventHandlers(onKeyUp, _this.buttonHandleKeyUp),
831
828
  onBlur: callAllEventHandlers(onBlur, _this.buttonHandleBlur)
832
829
  };
833
- var eventHandlers = rest.disabled ? {} : enabledEventHandlers;
834
- return _extends__default["default"]({
830
+ const eventHandlers = rest.disabled ? {} : enabledEventHandlers;
831
+ return {
835
832
  type: 'button',
836
833
  role: 'button',
837
834
  'aria-label': isOpen ? 'close menu' : 'open menu',
838
835
  'aria-haspopup': true,
839
- 'data-toggle': true
840
- }, eventHandlers, rest);
836
+ 'data-toggle': true,
837
+ ...eventHandlers,
838
+ ...rest
839
+ };
841
840
  };
842
- _this.buttonHandleKeyUp = function (event) {
841
+ this.buttonHandleKeyUp = event => {
843
842
  // Prevent click event from emitting in Firefox
844
843
  event.preventDefault();
845
844
  };
846
- _this.buttonHandleKeyDown = function (event) {
847
- var key = normalizeArrowKey(event);
848
- if (_this.buttonKeyDownHandlers[key]) {
849
- _this.buttonKeyDownHandlers[key].call(_assertThisInitialized__default["default"](_this), event);
845
+ this.buttonHandleKeyDown = event => {
846
+ const key = normalizeArrowKey(event);
847
+ if (this.buttonKeyDownHandlers[key]) {
848
+ this.buttonKeyDownHandlers[key].call(this, event);
850
849
  }
851
850
  };
852
- _this.buttonHandleClick = function (event) {
851
+ this.buttonHandleClick = event => {
853
852
  event.preventDefault();
854
853
  // handle odd case for Safari and Firefox which
855
854
  // don't give the button the focus properly.
856
855
  /* istanbul ignore if (can't reasonably test this) */
857
- if (_this.props.environment.document.activeElement === _this.props.environment.document.body) {
856
+ if (this.props.environment.document.activeElement === this.props.environment.document.body) {
858
857
  event.target.focus();
859
858
  }
860
859
  // to simplify testing components that use downshift, we'll not wrap this in a setTimeout
861
860
  // if the NODE_ENV is test. With the proper build system, this should be dead code eliminated
862
861
  // when building for production and should therefore have no impact on production code.
863
862
  if (process.env.NODE_ENV === 'test') {
864
- _this.toggleMenu({
863
+ this.toggleMenu({
865
864
  type: clickButton
866
865
  });
867
866
  } else {
868
867
  // Ensure that toggle of menu occurs after the potential blur event in iOS
869
- _this.internalSetTimeout(function () {
870
- return _this.toggleMenu({
871
- type: clickButton
872
- });
873
- });
868
+ this.internalSetTimeout(() => this.toggleMenu({
869
+ type: clickButton
870
+ }));
874
871
  }
875
872
  };
876
- _this.buttonHandleBlur = function (event) {
877
- var blurTarget = event.target; // Save blur target for comparison with activeElement later
873
+ this.buttonHandleBlur = event => {
874
+ const blurTarget = event.target; // Save blur target for comparison with activeElement later
878
875
  // Need setTimeout, so that when the user presses Tab, the activeElement is the next focused element, not body element
879
- _this.internalSetTimeout(function () {
880
- if (!_this.isMouseDown && (_this.props.environment.document.activeElement == null || _this.props.environment.document.activeElement.id !== _this.inputId) && _this.props.environment.document.activeElement !== blurTarget // Do nothing if we refocus the same element again (to solve issue in Safari on iOS)
876
+ this.internalSetTimeout(() => {
877
+ if (!this.isMouseDown && (this.props.environment.document.activeElement == null || this.props.environment.document.activeElement.id !== this.inputId) && this.props.environment.document.activeElement !== blurTarget // Do nothing if we refocus the same element again (to solve issue in Safari on iOS)
881
878
  ) {
882
- _this.reset({
879
+ this.reset({
883
880
  type: blurButton
884
881
  });
885
882
  }
886
883
  });
887
884
  };
888
- _this.getLabelProps = function (props) {
889
- return _extends__default["default"]({
890
- htmlFor: _this.inputId,
891
- id: _this.labelId
892
- }, props);
893
- };
894
- _this.getInputProps = function (_temp4) {
895
- var _ref4 = _temp4 === void 0 ? {} : _temp4,
896
- onKeyDown = _ref4.onKeyDown,
897
- onBlur = _ref4.onBlur,
898
- onChange = _ref4.onChange,
899
- onInput = _ref4.onInput;
900
- _ref4.onChangeText;
901
- var rest = _objectWithoutPropertiesLoose__default["default"](_ref4, _excluded3$2);
902
- var onChangeKey;
903
- var eventHandlers = {};
885
+ this.getLabelProps = props => {
886
+ return {
887
+ htmlFor: this.inputId,
888
+ id: this.labelId,
889
+ ...props
890
+ };
891
+ };
892
+ this.getInputProps = function (_temp4) {
893
+ let {
894
+ onKeyDown,
895
+ onBlur,
896
+ onChange,
897
+ onInput,
898
+ onChangeText,
899
+ ...rest
900
+ } = _temp4 === void 0 ? {} : _temp4;
901
+ let onChangeKey;
902
+ let eventHandlers = {};
904
903
 
905
904
  /* istanbul ignore next (preact) */
906
905
  {
907
906
  onChangeKey = 'onInput';
908
907
  }
909
- var _this$getState6 = _this.getState(),
910
- inputValue = _this$getState6.inputValue,
911
- isOpen = _this$getState6.isOpen,
912
- highlightedIndex = _this$getState6.highlightedIndex;
908
+ const {
909
+ inputValue,
910
+ isOpen,
911
+ highlightedIndex
912
+ } = _this.getState();
913
913
  if (!rest.disabled) {
914
- var _eventHandlers;
915
- eventHandlers = (_eventHandlers = {}, _eventHandlers[onChangeKey] = callAllEventHandlers(onChange, onInput, _this.inputHandleChange), _eventHandlers.onKeyDown = callAllEventHandlers(onKeyDown, _this.inputHandleKeyDown), _eventHandlers.onBlur = callAllEventHandlers(onBlur, _this.inputHandleBlur), _eventHandlers);
914
+ eventHandlers = {
915
+ [onChangeKey]: callAllEventHandlers(onChange, onInput, _this.inputHandleChange),
916
+ onKeyDown: callAllEventHandlers(onKeyDown, _this.inputHandleKeyDown),
917
+ onBlur: callAllEventHandlers(onBlur, _this.inputHandleBlur)
918
+ };
916
919
  }
917
- return _extends__default["default"]({
920
+ return {
918
921
  'aria-autocomplete': 'list',
919
922
  'aria-activedescendant': isOpen && typeof highlightedIndex === 'number' && highlightedIndex >= 0 ? _this.getItemId(highlightedIndex) : null,
920
923
  'aria-controls': isOpen ? _this.menuId : null,
@@ -923,76 +926,82 @@ var Downshift = /*#__PURE__*/function () {
923
926
  // revert back since autocomplete="nope" is ignored on latest Chrome and Opera
924
927
  autoComplete: 'off',
925
928
  value: inputValue,
926
- id: _this.inputId
927
- }, eventHandlers, rest);
929
+ id: _this.inputId,
930
+ ...eventHandlers,
931
+ ...rest
932
+ };
928
933
  };
929
- _this.inputHandleKeyDown = function (event) {
930
- var key = normalizeArrowKey(event);
931
- if (key && _this.inputKeyDownHandlers[key]) {
932
- _this.inputKeyDownHandlers[key].call(_assertThisInitialized__default["default"](_this), event);
934
+ this.inputHandleKeyDown = event => {
935
+ const key = normalizeArrowKey(event);
936
+ if (key && this.inputKeyDownHandlers[key]) {
937
+ this.inputKeyDownHandlers[key].call(this, event);
933
938
  }
934
939
  };
935
- _this.inputHandleChange = function (event) {
936
- _this.internalSetState({
940
+ this.inputHandleChange = event => {
941
+ this.internalSetState({
937
942
  type: changeInput,
938
943
  isOpen: true,
939
944
  inputValue: event.target.value,
940
- highlightedIndex: _this.props.defaultHighlightedIndex
945
+ highlightedIndex: this.props.defaultHighlightedIndex
941
946
  });
942
947
  };
943
- _this.inputHandleBlur = function () {
948
+ this.inputHandleBlur = () => {
944
949
  // Need setTimeout, so that when the user presses Tab, the activeElement is the next focused element, not the body element
945
- _this.internalSetTimeout(function () {
946
- var downshiftButtonIsActive = _this.props.environment.document && !!_this.props.environment.document.activeElement && !!_this.props.environment.document.activeElement.dataset && _this.props.environment.document.activeElement.dataset.toggle && _this._rootNode && _this._rootNode.contains(_this.props.environment.document.activeElement);
947
- if (!_this.isMouseDown && !downshiftButtonIsActive) {
948
- _this.reset({
950
+ this.internalSetTimeout(() => {
951
+ const downshiftButtonIsActive = this.props.environment.document && !!this.props.environment.document.activeElement && !!this.props.environment.document.activeElement.dataset && this.props.environment.document.activeElement.dataset.toggle && this._rootNode && this._rootNode.contains(this.props.environment.document.activeElement);
952
+ if (!this.isMouseDown && !downshiftButtonIsActive) {
953
+ this.reset({
949
954
  type: blurInput
950
955
  });
951
956
  }
952
957
  });
953
958
  };
954
- _this.menuRef = function (node) {
955
- _this._menuNode = node;
956
- };
957
- _this.getMenuProps = function (_temp5, _temp6) {
958
- var _extends3;
959
- var _ref5 = _temp5 === void 0 ? {} : _temp5,
960
- _ref5$refKey = _ref5.refKey,
961
- refKey = _ref5$refKey === void 0 ? 'ref' : _ref5$refKey,
962
- ref = _ref5.ref,
963
- props = _objectWithoutPropertiesLoose__default["default"](_ref5, _excluded4$1);
964
- var _ref6 = _temp6 === void 0 ? {} : _temp6,
965
- _ref6$suppressRefErro = _ref6.suppressRefError,
966
- suppressRefError = _ref6$suppressRefErro === void 0 ? false : _ref6$suppressRefErro;
959
+ this.menuRef = node => {
960
+ this._menuNode = node;
961
+ };
962
+ this.getMenuProps = function (_temp5, _temp6) {
963
+ let {
964
+ refKey = 'ref',
965
+ ref,
966
+ ...props
967
+ } = _temp5 === void 0 ? {} : _temp5;
968
+ let {
969
+ suppressRefError = false
970
+ } = _temp6 === void 0 ? {} : _temp6;
967
971
  _this.getMenuProps.called = true;
968
972
  _this.getMenuProps.refKey = refKey;
969
973
  _this.getMenuProps.suppressRefError = suppressRefError;
970
- return _extends__default["default"]((_extends3 = {}, _extends3[refKey] = handleRefs(ref, _this.menuRef), _extends3.role = 'listbox', _extends3['aria-labelledby'] = props && props['aria-label'] ? null : _this.labelId, _extends3.id = _this.menuId, _extends3), props);
971
- };
972
- _this.getItemProps = function (_temp7) {
973
- var _enabledEventHandlers;
974
- var _ref7 = _temp7 === void 0 ? {} : _temp7,
975
- onMouseMove = _ref7.onMouseMove,
976
- onMouseDown = _ref7.onMouseDown,
977
- onClick = _ref7.onClick;
978
- _ref7.onPress;
979
- var index = _ref7.index,
980
- _ref7$item = _ref7.item,
981
- item = _ref7$item === void 0 ? process.env.NODE_ENV === 'production' ? /* istanbul ignore next */undefined : requiredProp('getItemProps', 'item') : _ref7$item,
982
- rest = _objectWithoutPropertiesLoose__default["default"](_ref7, _excluded5);
974
+ return {
975
+ [refKey]: handleRefs(ref, _this.menuRef),
976
+ role: 'listbox',
977
+ 'aria-labelledby': props && props['aria-label'] ? null : _this.labelId,
978
+ id: _this.menuId,
979
+ ...props
980
+ };
981
+ };
982
+ this.getItemProps = function (_temp7) {
983
+ let {
984
+ onMouseMove,
985
+ onMouseDown,
986
+ onClick,
987
+ onPress,
988
+ index,
989
+ item = process.env.NODE_ENV === 'production' ? /* istanbul ignore next */undefined : requiredProp('getItemProps', 'item'),
990
+ ...rest
991
+ } = _temp7 === void 0 ? {} : _temp7;
983
992
  if (index === undefined) {
984
993
  _this.items.push(item);
985
994
  index = _this.items.indexOf(item);
986
995
  } else {
987
996
  _this.items[index] = item;
988
997
  }
989
- var onSelectKey = 'onClick';
990
- var customClickHandler = onClick;
991
- var enabledEventHandlers = (_enabledEventHandlers = {
998
+ const onSelectKey = 'onClick';
999
+ const customClickHandler = onClick;
1000
+ const enabledEventHandlers = {
992
1001
  // onMouseMove is used over onMouseEnter here. onMouseMove
993
1002
  // is only triggered on actual mouse movement while onMouseEnter
994
1003
  // can fire on DOM changes, interrupting keyboard navigation
995
- onMouseMove: callAllEventHandlers(onMouseMove, function () {
1004
+ onMouseMove: callAllEventHandlers(onMouseMove, () => {
996
1005
  if (index === _this.getState().highlightedIndex) {
997
1006
  return;
998
1007
  }
@@ -1005,66 +1014,75 @@ var Downshift = /*#__PURE__*/function () {
1005
1014
  // from under the user which is currently scrolling/moving the
1006
1015
  // cursor
1007
1016
  _this.avoidScrolling = true;
1008
- _this.internalSetTimeout(function () {
1009
- return _this.avoidScrolling = false;
1010
- }, 250);
1017
+ _this.internalSetTimeout(() => _this.avoidScrolling = false, 250);
1011
1018
  }),
1012
- onMouseDown: callAllEventHandlers(onMouseDown, function (event) {
1019
+ onMouseDown: callAllEventHandlers(onMouseDown, event => {
1013
1020
  // This prevents the activeElement from being changed
1014
1021
  // to the item so it can remain with the current activeElement
1015
1022
  // which is a more common use case.
1016
1023
  event.preventDefault();
1024
+ }),
1025
+ [onSelectKey]: callAllEventHandlers(customClickHandler, () => {
1026
+ _this.selectItemAtIndex(index, {
1027
+ type: clickItem
1028
+ });
1017
1029
  })
1018
- }, _enabledEventHandlers[onSelectKey] = callAllEventHandlers(customClickHandler, function () {
1019
- _this.selectItemAtIndex(index, {
1020
- type: clickItem
1021
- });
1022
- }), _enabledEventHandlers);
1030
+ };
1023
1031
 
1024
1032
  // Passing down the onMouseDown handler to prevent redirect
1025
1033
  // of the activeElement if clicking on disabled items
1026
- var eventHandlers = rest.disabled ? {
1034
+ const eventHandlers = rest.disabled ? {
1027
1035
  onMouseDown: enabledEventHandlers.onMouseDown
1028
1036
  } : enabledEventHandlers;
1029
- return _extends__default["default"]({
1037
+ return {
1030
1038
  id: _this.getItemId(index),
1031
1039
  role: 'option',
1032
- 'aria-selected': _this.getState().highlightedIndex === index
1033
- }, eventHandlers, rest);
1040
+ 'aria-selected': _this.getState().highlightedIndex === index,
1041
+ ...eventHandlers,
1042
+ ...rest
1043
+ };
1034
1044
  };
1035
- _this.clearItems = function () {
1036
- _this.items = [];
1045
+ this.clearItems = () => {
1046
+ this.items = [];
1037
1047
  };
1038
- _this.reset = function (otherStateToSet, cb) {
1048
+ this.reset = function (otherStateToSet, cb) {
1039
1049
  if (otherStateToSet === void 0) {
1040
1050
  otherStateToSet = {};
1041
1051
  }
1042
1052
  otherStateToSet = pickState(otherStateToSet);
1043
- _this.internalSetState(function (_ref8) {
1044
- var selectedItem = _ref8.selectedItem;
1045
- return _extends__default["default"]({
1053
+ _this.internalSetState(_ref => {
1054
+ let {
1055
+ selectedItem
1056
+ } = _ref;
1057
+ return {
1046
1058
  isOpen: _this.props.defaultIsOpen,
1047
1059
  highlightedIndex: _this.props.defaultHighlightedIndex,
1048
- inputValue: _this.props.itemToString(selectedItem)
1049
- }, otherStateToSet);
1060
+ inputValue: _this.props.itemToString(selectedItem),
1061
+ ...otherStateToSet
1062
+ };
1050
1063
  }, cb);
1051
1064
  };
1052
- _this.toggleMenu = function (otherStateToSet, cb) {
1065
+ this.toggleMenu = function (otherStateToSet, cb) {
1053
1066
  if (otherStateToSet === void 0) {
1054
1067
  otherStateToSet = {};
1055
1068
  }
1056
1069
  otherStateToSet = pickState(otherStateToSet);
1057
- _this.internalSetState(function (_ref9) {
1058
- var isOpen = _ref9.isOpen;
1059
- return _extends__default["default"]({
1060
- isOpen: !isOpen
1061
- }, isOpen && {
1062
- highlightedIndex: _this.props.defaultHighlightedIndex
1063
- }, otherStateToSet);
1064
- }, function () {
1065
- var _this$getState7 = _this.getState(),
1066
- isOpen = _this$getState7.isOpen,
1067
- highlightedIndex = _this$getState7.highlightedIndex;
1070
+ _this.internalSetState(_ref2 => {
1071
+ let {
1072
+ isOpen
1073
+ } = _ref2;
1074
+ return {
1075
+ isOpen: !isOpen,
1076
+ ...(isOpen && {
1077
+ highlightedIndex: _this.props.defaultHighlightedIndex
1078
+ }),
1079
+ ...otherStateToSet
1080
+ };
1081
+ }, () => {
1082
+ const {
1083
+ isOpen,
1084
+ highlightedIndex
1085
+ } = _this.getState();
1068
1086
  if (isOpen) {
1069
1087
  if (_this.getItemCount() > 0 && typeof highlightedIndex === 'number') {
1070
1088
  _this.setHighlightedIndex(highlightedIndex, otherStateToSet);
@@ -1073,58 +1091,57 @@ var Downshift = /*#__PURE__*/function () {
1073
1091
  cbToCb(cb)();
1074
1092
  });
1075
1093
  };
1076
- _this.openMenu = function (cb) {
1077
- _this.internalSetState({
1094
+ this.openMenu = cb => {
1095
+ this.internalSetState({
1078
1096
  isOpen: true
1079
1097
  }, cb);
1080
1098
  };
1081
- _this.closeMenu = function (cb) {
1082
- _this.internalSetState({
1099
+ this.closeMenu = cb => {
1100
+ this.internalSetState({
1083
1101
  isOpen: false
1084
1102
  }, cb);
1085
1103
  };
1086
- _this.updateStatus = debounce(function () {
1087
- var state = _this.getState();
1088
- var item = _this.items[state.highlightedIndex];
1089
- var resultCount = _this.getItemCount();
1090
- var status = _this.props.getA11yStatusMessage(_extends__default["default"]({
1091
- itemToString: _this.props.itemToString,
1092
- previousResultCount: _this.previousResultCount,
1093
- resultCount: resultCount,
1094
- highlightedItem: item
1095
- }, state));
1096
- _this.previousResultCount = resultCount;
1097
- setStatus(status, _this.props.environment.document);
1104
+ this.updateStatus = debounce(() => {
1105
+ const state = this.getState();
1106
+ const item = this.items[state.highlightedIndex];
1107
+ const resultCount = this.getItemCount();
1108
+ const status = this.props.getA11yStatusMessage({
1109
+ itemToString: this.props.itemToString,
1110
+ previousResultCount: this.previousResultCount,
1111
+ resultCount,
1112
+ highlightedItem: item,
1113
+ ...state
1114
+ });
1115
+ this.previousResultCount = resultCount;
1116
+ setStatus(status, this.props.environment.document);
1098
1117
  }, 200);
1099
- var _this$props = _this.props,
1100
- defaultHighlightedIndex = _this$props.defaultHighlightedIndex,
1101
- _this$props$initialHi = _this$props.initialHighlightedIndex,
1102
- _highlightedIndex = _this$props$initialHi === void 0 ? defaultHighlightedIndex : _this$props$initialHi,
1103
- defaultIsOpen = _this$props.defaultIsOpen,
1104
- _this$props$initialIs = _this$props.initialIsOpen,
1105
- _isOpen = _this$props$initialIs === void 0 ? defaultIsOpen : _this$props$initialIs,
1106
- _this$props$initialIn = _this$props.initialInputValue,
1107
- _inputValue = _this$props$initialIn === void 0 ? '' : _this$props$initialIn,
1108
- _this$props$initialSe = _this$props.initialSelectedItem,
1109
- _selectedItem = _this$props$initialSe === void 0 ? null : _this$props$initialSe;
1110
- var _state = _this.getState({
1118
+ // fancy destructuring + defaults + aliases
1119
+ // this basically says each value of state should either be set to
1120
+ // the initial value or the default value if the initial value is not provided
1121
+ const {
1122
+ defaultHighlightedIndex,
1123
+ initialHighlightedIndex: _highlightedIndex = defaultHighlightedIndex,
1124
+ defaultIsOpen,
1125
+ initialIsOpen: _isOpen = defaultIsOpen,
1126
+ initialInputValue: _inputValue = '',
1127
+ initialSelectedItem: _selectedItem = null
1128
+ } = this.props;
1129
+ const _state = this.getState({
1111
1130
  highlightedIndex: _highlightedIndex,
1112
1131
  isOpen: _isOpen,
1113
1132
  inputValue: _inputValue,
1114
1133
  selectedItem: _selectedItem
1115
1134
  });
1116
- if (_state.selectedItem != null && _this.props.initialInputValue === undefined) {
1117
- _state.inputValue = _this.props.itemToString(_state.selectedItem);
1135
+ if (_state.selectedItem != null && this.props.initialInputValue === undefined) {
1136
+ _state.inputValue = this.props.itemToString(_state.selectedItem);
1118
1137
  }
1119
- _this.state = _state;
1120
- return _this;
1138
+ this.state = _state;
1121
1139
  }
1122
- var _proto = Downshift.prototype;
1123
1140
  /**
1124
1141
  * Clear all running timeouts
1125
1142
  */
1126
- _proto.internalClearTimeouts = function internalClearTimeouts() {
1127
- this.timeoutIds.forEach(function (id) {
1143
+ internalClearTimeouts() {
1144
+ this.timeoutIds.forEach(id => {
1128
1145
  clearTimeout(id);
1129
1146
  });
1130
1147
  this.timeoutIds = [];
@@ -1138,113 +1155,117 @@ var Downshift = /*#__PURE__*/function () {
1138
1155
  *
1139
1156
  * @param {Object} stateToMerge defaults to this.state
1140
1157
  * @return {Object} the state
1141
- */;
1142
- _proto.getState = function getState$1(stateToMerge) {
1158
+ */
1159
+ getState(stateToMerge) {
1143
1160
  if (stateToMerge === void 0) {
1144
1161
  stateToMerge = this.state;
1145
1162
  }
1146
1163
  return getState(stateToMerge, this.props);
1147
- };
1148
- _proto.getItemCount = function getItemCount() {
1164
+ }
1165
+ getItemCount() {
1149
1166
  // things read better this way. They're in priority order:
1150
1167
  // 1. `this.itemCount`
1151
1168
  // 2. `this.props.itemCount`
1152
1169
  // 3. `this.items.length`
1153
- var itemCount = this.items.length;
1170
+ let itemCount = this.items.length;
1154
1171
  if (this.itemCount != null) {
1155
1172
  itemCount = this.itemCount;
1156
1173
  } else if (this.props.itemCount !== undefined) {
1157
1174
  itemCount = this.props.itemCount;
1158
1175
  }
1159
1176
  return itemCount;
1160
- };
1161
- _proto.getItemNodeFromIndex = function getItemNodeFromIndex(index) {
1177
+ }
1178
+ getItemNodeFromIndex(index) {
1162
1179
  return this.props.environment.document.getElementById(this.getItemId(index));
1163
- };
1164
- _proto.scrollHighlightedItemIntoView = function scrollHighlightedItemIntoView() {
1180
+ }
1181
+ scrollHighlightedItemIntoView() {
1165
1182
  /* istanbul ignore else (react-native) */
1166
1183
  {
1167
- var node = this.getItemNodeFromIndex(this.getState().highlightedIndex);
1184
+ const node = this.getItemNodeFromIndex(this.getState().highlightedIndex);
1168
1185
  this.props.scrollIntoView(node, this._menuNode);
1169
1186
  }
1170
- };
1171
- _proto.moveHighlightedIndex = function moveHighlightedIndex(amount, otherStateToSet) {
1172
- var _this6 = this;
1173
- var itemCount = this.getItemCount();
1174
- var _this$getState8 = this.getState(),
1175
- highlightedIndex = _this$getState8.highlightedIndex;
1187
+ }
1188
+ moveHighlightedIndex(amount, otherStateToSet) {
1189
+ const itemCount = this.getItemCount();
1190
+ const {
1191
+ highlightedIndex
1192
+ } = this.getState();
1176
1193
  if (itemCount > 0) {
1177
- var nextHighlightedIndex = getNextWrappingIndex(amount, highlightedIndex, itemCount, function (index) {
1178
- return _this6.getItemNodeFromIndex(index);
1179
- });
1194
+ const nextHighlightedIndex = getNextWrappingIndex(amount, highlightedIndex, itemCount, index => this.getItemNodeFromIndex(index));
1180
1195
  this.setHighlightedIndex(nextHighlightedIndex, otherStateToSet);
1181
1196
  }
1182
- };
1183
- _proto.getStateAndHelpers = function getStateAndHelpers() {
1184
- var _this$getState9 = this.getState(),
1185
- highlightedIndex = _this$getState9.highlightedIndex,
1186
- inputValue = _this$getState9.inputValue,
1187
- selectedItem = _this$getState9.selectedItem,
1188
- isOpen = _this$getState9.isOpen;
1189
- var itemToString = this.props.itemToString;
1190
- var id = this.id;
1191
- var getRootProps = this.getRootProps,
1192
- getToggleButtonProps = this.getToggleButtonProps,
1193
- getLabelProps = this.getLabelProps,
1194
- getMenuProps = this.getMenuProps,
1195
- getInputProps = this.getInputProps,
1196
- getItemProps = this.getItemProps,
1197
- openMenu = this.openMenu,
1198
- closeMenu = this.closeMenu,
1199
- toggleMenu = this.toggleMenu,
1200
- selectItem = this.selectItem,
1201
- selectItemAtIndex = this.selectItemAtIndex,
1202
- selectHighlightedItem = this.selectHighlightedItem,
1203
- setHighlightedIndex = this.setHighlightedIndex,
1204
- clearSelection = this.clearSelection,
1205
- clearItems = this.clearItems,
1206
- reset = this.reset,
1207
- setItemCount = this.setItemCount,
1208
- unsetItemCount = this.unsetItemCount,
1209
- setState = this.internalSetState;
1197
+ }
1198
+ getStateAndHelpers() {
1199
+ const {
1200
+ highlightedIndex,
1201
+ inputValue,
1202
+ selectedItem,
1203
+ isOpen
1204
+ } = this.getState();
1205
+ const {
1206
+ itemToString
1207
+ } = this.props;
1208
+ const {
1209
+ id
1210
+ } = this;
1211
+ const {
1212
+ getRootProps,
1213
+ getToggleButtonProps,
1214
+ getLabelProps,
1215
+ getMenuProps,
1216
+ getInputProps,
1217
+ getItemProps,
1218
+ openMenu,
1219
+ closeMenu,
1220
+ toggleMenu,
1221
+ selectItem,
1222
+ selectItemAtIndex,
1223
+ selectHighlightedItem,
1224
+ setHighlightedIndex,
1225
+ clearSelection,
1226
+ clearItems,
1227
+ reset,
1228
+ setItemCount,
1229
+ unsetItemCount,
1230
+ internalSetState: setState
1231
+ } = this;
1210
1232
  return {
1211
1233
  // prop getters
1212
- getRootProps: getRootProps,
1213
- getToggleButtonProps: getToggleButtonProps,
1214
- getLabelProps: getLabelProps,
1215
- getMenuProps: getMenuProps,
1216
- getInputProps: getInputProps,
1217
- getItemProps: getItemProps,
1234
+ getRootProps,
1235
+ getToggleButtonProps,
1236
+ getLabelProps,
1237
+ getMenuProps,
1238
+ getInputProps,
1239
+ getItemProps,
1218
1240
  // actions
1219
- reset: reset,
1220
- openMenu: openMenu,
1221
- closeMenu: closeMenu,
1222
- toggleMenu: toggleMenu,
1223
- selectItem: selectItem,
1224
- selectItemAtIndex: selectItemAtIndex,
1225
- selectHighlightedItem: selectHighlightedItem,
1226
- setHighlightedIndex: setHighlightedIndex,
1227
- clearSelection: clearSelection,
1228
- clearItems: clearItems,
1229
- setItemCount: setItemCount,
1230
- unsetItemCount: unsetItemCount,
1231
- setState: setState,
1241
+ reset,
1242
+ openMenu,
1243
+ closeMenu,
1244
+ toggleMenu,
1245
+ selectItem,
1246
+ selectItemAtIndex,
1247
+ selectHighlightedItem,
1248
+ setHighlightedIndex,
1249
+ clearSelection,
1250
+ clearItems,
1251
+ setItemCount,
1252
+ unsetItemCount,
1253
+ setState,
1232
1254
  // props
1233
- itemToString: itemToString,
1255
+ itemToString,
1234
1256
  // derived
1235
- id: id,
1257
+ id,
1236
1258
  // state
1237
- highlightedIndex: highlightedIndex,
1238
- inputValue: inputValue,
1239
- isOpen: isOpen,
1240
- selectedItem: selectedItem
1259
+ highlightedIndex,
1260
+ inputValue,
1261
+ isOpen,
1262
+ selectedItem
1241
1263
  };
1242
1264
  }
1243
1265
 
1244
1266
  //////////////////////////// ROOT
1245
- ;
1246
- _proto.componentDidMount = function componentDidMount() {
1247
- var _this7 = this;
1267
+
1268
+ componentDidMount() {
1248
1269
  /* istanbul ignore if (react-native) */
1249
1270
  if (process.env.NODE_ENV !== 'production' && !false && this.getMenuProps.called && !this.getMenuProps.suppressRefError) {
1250
1271
  validateGetMenuPropsCalledCorrectly(this._menuNode, this.getMenuProps);
@@ -1257,20 +1278,18 @@ var Downshift = /*#__PURE__*/function () {
1257
1278
  // down long enough for the list to disappear (because the blur event fires on the input)
1258
1279
  // this.isMouseDown is used in the blur handler on the input to determine whether the blur event should
1259
1280
  // trigger hiding the menu.
1260
- var onMouseDown = function onMouseDown() {
1261
- _this7.isMouseDown = true;
1281
+ const onMouseDown = () => {
1282
+ this.isMouseDown = true;
1262
1283
  };
1263
- var onMouseUp = function onMouseUp(event) {
1264
- _this7.isMouseDown = false;
1284
+ const onMouseUp = event => {
1285
+ this.isMouseDown = false;
1265
1286
  // if the target element or the activeElement is within a downshift node
1266
1287
  // then we don't want to reset downshift
1267
- var contextWithinDownshift = targetWithinDownshift(event.target, [_this7._rootNode, _this7._menuNode], _this7.props.environment);
1268
- if (!contextWithinDownshift && _this7.getState().isOpen) {
1269
- _this7.reset({
1288
+ const contextWithinDownshift = targetWithinDownshift(event.target, [this._rootNode, this._menuNode], this.props.environment);
1289
+ if (!contextWithinDownshift && this.getState().isOpen) {
1290
+ this.reset({
1270
1291
  type: mouseUp
1271
- }, function () {
1272
- return _this7.props.onOuterClick(_this7.getStateAndHelpers());
1273
- });
1292
+ }, () => this.props.onOuterClick(this.getStateAndHelpers()));
1274
1293
  }
1275
1294
  };
1276
1295
  // Touching an element in iOS gives focus and hover states, but touching out of
@@ -1279,31 +1298,31 @@ var Downshift = /*#__PURE__*/function () {
1279
1298
  // this.isTouchMove helps us track whether the user is tapping or swiping on a touch screen.
1280
1299
  // If the user taps outside of Downshift, the component should be reset,
1281
1300
  // but not if the user is swiping
1282
- var onTouchStart = function onTouchStart() {
1283
- _this7.isTouchMove = false;
1301
+ const onTouchStart = () => {
1302
+ this.isTouchMove = false;
1284
1303
  };
1285
- var onTouchMove = function onTouchMove() {
1286
- _this7.isTouchMove = true;
1304
+ const onTouchMove = () => {
1305
+ this.isTouchMove = true;
1287
1306
  };
1288
- var onTouchEnd = function onTouchEnd(event) {
1289
- var contextWithinDownshift = targetWithinDownshift(event.target, [_this7._rootNode, _this7._menuNode], _this7.props.environment, false);
1290
- if (!_this7.isTouchMove && !contextWithinDownshift && _this7.getState().isOpen) {
1291
- _this7.reset({
1307
+ const onTouchEnd = event => {
1308
+ const contextWithinDownshift = targetWithinDownshift(event.target, [this._rootNode, this._menuNode], this.props.environment, false);
1309
+ if (!this.isTouchMove && !contextWithinDownshift && this.getState().isOpen) {
1310
+ this.reset({
1292
1311
  type: touchEnd
1293
- }, function () {
1294
- return _this7.props.onOuterClick(_this7.getStateAndHelpers());
1295
- });
1312
+ }, () => this.props.onOuterClick(this.getStateAndHelpers()));
1296
1313
  }
1297
1314
  };
1298
- var environment = this.props.environment;
1315
+ const {
1316
+ environment
1317
+ } = this.props;
1299
1318
  environment.addEventListener('mousedown', onMouseDown);
1300
1319
  environment.addEventListener('mouseup', onMouseUp);
1301
1320
  environment.addEventListener('touchstart', onTouchStart);
1302
1321
  environment.addEventListener('touchmove', onTouchMove);
1303
1322
  environment.addEventListener('touchend', onTouchEnd);
1304
- this.cleanup = function () {
1305
- _this7.internalClearTimeouts();
1306
- _this7.updateStatus.cancel();
1323
+ this.cleanup = () => {
1324
+ this.internalClearTimeouts();
1325
+ this.updateStatus.cancel();
1307
1326
  environment.removeEventListener('mousedown', onMouseDown);
1308
1327
  environment.removeEventListener('mouseup', onMouseUp);
1309
1328
  environment.removeEventListener('touchstart', onTouchStart);
@@ -1311,17 +1330,19 @@ var Downshift = /*#__PURE__*/function () {
1311
1330
  environment.removeEventListener('touchend', onTouchEnd);
1312
1331
  };
1313
1332
  }
1314
- };
1315
- _proto.shouldScroll = function shouldScroll(prevState, prevProps) {
1316
- var _ref10 = this.props.highlightedIndex === undefined ? this.getState() : this.props,
1317
- currentHighlightedIndex = _ref10.highlightedIndex;
1318
- var _ref11 = prevProps.highlightedIndex === undefined ? prevState : prevProps,
1319
- prevHighlightedIndex = _ref11.highlightedIndex;
1320
- var scrollWhenOpen = currentHighlightedIndex && this.getState().isOpen && !prevState.isOpen;
1321
- var scrollWhenNavigating = currentHighlightedIndex !== prevHighlightedIndex;
1333
+ }
1334
+ shouldScroll(prevState, prevProps) {
1335
+ const {
1336
+ highlightedIndex: currentHighlightedIndex
1337
+ } = this.props.highlightedIndex === undefined ? this.getState() : this.props;
1338
+ const {
1339
+ highlightedIndex: prevHighlightedIndex
1340
+ } = prevProps.highlightedIndex === undefined ? prevState : prevProps;
1341
+ const scrollWhenOpen = currentHighlightedIndex && this.getState().isOpen && !prevState.isOpen;
1342
+ const scrollWhenNavigating = currentHighlightedIndex !== prevHighlightedIndex;
1322
1343
  return scrollWhenOpen || scrollWhenNavigating;
1323
- };
1324
- _proto.componentDidUpdate = function componentDidUpdate(prevProps, prevState) {
1344
+ }
1345
+ componentDidUpdate(prevProps, prevState) {
1325
1346
  if (process.env.NODE_ENV !== 'production') {
1326
1347
  validateControlledUnchanged(this.state, prevProps, this.props);
1327
1348
  /* istanbul ignore if (react-native) */
@@ -1343,12 +1364,13 @@ var Downshift = /*#__PURE__*/function () {
1343
1364
  {
1344
1365
  this.updateStatus();
1345
1366
  }
1346
- };
1347
- _proto.componentWillUnmount = function componentWillUnmount() {
1367
+ }
1368
+ componentWillUnmount() {
1348
1369
  this.cleanup(); // avoids memory leak
1349
- };
1350
- _proto.render = function render() {
1351
- var children = unwrapArray(this.props.children, noop);
1370
+ }
1371
+
1372
+ render() {
1373
+ const children = unwrapArray(this.props.children, noop);
1352
1374
  // because the items are rerendered every time we call the children
1353
1375
  // we clear this out each render and it will be populated again as
1354
1376
  // getItemProps is called.
@@ -1368,7 +1390,7 @@ var Downshift = /*#__PURE__*/function () {
1368
1390
  this.getLabelProps.called = false;
1369
1391
  // and something similar for getInputProps
1370
1392
  this.getInputProps.called = false;
1371
- var element = unwrapArray(children(this.getStateAndHelpers()));
1393
+ const element = unwrapArray(children(this.getStateAndHelpers()));
1372
1394
  if (!element) {
1373
1395
  return null;
1374
1396
  }
@@ -1393,14 +1415,13 @@ var Downshift = /*#__PURE__*/function () {
1393
1415
 
1394
1416
  /* istanbul ignore next */
1395
1417
  return undefined;
1396
- };
1397
- return Downshift;
1398
- }(preact.Component);
1418
+ }
1419
+ }
1399
1420
  Downshift.defaultProps = {
1400
1421
  defaultHighlightedIndex: null,
1401
1422
  defaultIsOpen: false,
1402
1423
  getA11yStatusMessage: getA11yStatusMessage$1,
1403
- itemToString: function itemToString(i) {
1424
+ itemToString: i => {
1404
1425
  if (i == null) {
1405
1426
  return '';
1406
1427
  }
@@ -1416,76 +1437,81 @@ var Downshift = /*#__PURE__*/function () {
1416
1437
  onChange: noop,
1417
1438
  onSelect: noop,
1418
1439
  onOuterClick: noop,
1419
- selectedItemChanged: function selectedItemChanged(prevItem, item) {
1420
- return prevItem !== item;
1421
- },
1440
+ selectedItemChanged: (prevItem, item) => prevItem !== item,
1422
1441
  environment: /* istanbul ignore next (ssr) */
1423
1442
  typeof window === 'undefined' ? {} : window,
1424
- stateReducer: function stateReducer(state, stateToSet) {
1425
- return stateToSet;
1426
- },
1443
+ stateReducer: (state, stateToSet) => stateToSet,
1427
1444
  suppressRefError: false,
1428
- scrollIntoView: scrollIntoView
1445
+ scrollIntoView
1429
1446
  };
1430
1447
  Downshift.stateChangeTypes = stateChangeTypes$3;
1431
1448
  return Downshift;
1432
- }();
1449
+ })();
1433
1450
  var Downshift$1 = Downshift;
1434
- function validateGetMenuPropsCalledCorrectly(node, _ref12) {
1435
- var refKey = _ref12.refKey;
1451
+ function validateGetMenuPropsCalledCorrectly(node, _ref3) {
1452
+ let {
1453
+ refKey
1454
+ } = _ref3;
1436
1455
  if (!node) {
1437
1456
  // eslint-disable-next-line no-console
1438
- console.error("downshift: The ref prop \"" + refKey + "\" from getMenuProps was not applied correctly on your menu element.");
1457
+ console.error(`downshift: The ref prop "${refKey}" from getMenuProps was not applied correctly on your menu element.`);
1439
1458
  }
1440
1459
  }
1441
- function validateGetRootPropsCalledCorrectly(element, _ref13) {
1442
- var refKey = _ref13.refKey;
1443
- var refKeySpecified = refKey !== 'ref';
1444
- var isComposite = !isDOMElement(element);
1460
+ function validateGetRootPropsCalledCorrectly(element, _ref4) {
1461
+ let {
1462
+ refKey
1463
+ } = _ref4;
1464
+ const refKeySpecified = refKey !== 'ref';
1465
+ const isComposite = !isDOMElement(element);
1445
1466
  if (isComposite && !refKeySpecified && !reactIs.isForwardRef(element)) {
1446
1467
  // eslint-disable-next-line no-console
1447
1468
  console.error('downshift: You returned a non-DOM element. You must specify a refKey in getRootProps');
1448
1469
  } else if (!isComposite && refKeySpecified) {
1449
1470
  // eslint-disable-next-line no-console
1450
- console.error("downshift: You returned a DOM element. You should not specify a refKey in getRootProps. You specified \"" + refKey + "\"");
1471
+ console.error(`downshift: You returned a DOM element. You should not specify a refKey in getRootProps. You specified "${refKey}"`);
1451
1472
  }
1452
1473
  if (!reactIs.isForwardRef(element) && !getElementProps(element)[refKey]) {
1453
1474
  // eslint-disable-next-line no-console
1454
- console.error("downshift: You must apply the ref prop \"" + refKey + "\" from getRootProps onto your root element.");
1475
+ console.error(`downshift: You must apply the ref prop "${refKey}" from getRootProps onto your root element.`);
1455
1476
  }
1456
1477
  }
1457
1478
 
1458
- var _excluded$3 = ["isInitialMount", "highlightedIndex", "items", "environment"];
1459
- var dropdownDefaultStateValues = {
1479
+ const dropdownDefaultStateValues = {
1460
1480
  highlightedIndex: -1,
1461
1481
  isOpen: false,
1462
1482
  selectedItem: null,
1463
1483
  inputValue: ''
1464
1484
  };
1465
1485
  function callOnChangeProps(action, state, newState) {
1466
- var props = action.props,
1467
- type = action.type;
1468
- var changes = {};
1469
- Object.keys(state).forEach(function (key) {
1486
+ const {
1487
+ props,
1488
+ type
1489
+ } = action;
1490
+ const changes = {};
1491
+ Object.keys(state).forEach(key => {
1470
1492
  invokeOnChangeHandler(key, action, state, newState);
1471
1493
  if (newState[key] !== state[key]) {
1472
1494
  changes[key] = newState[key];
1473
1495
  }
1474
1496
  });
1475
1497
  if (props.onStateChange && Object.keys(changes).length) {
1476
- props.onStateChange(_extends__default["default"]({
1477
- type: type
1478
- }, changes));
1498
+ props.onStateChange({
1499
+ type,
1500
+ ...changes
1501
+ });
1479
1502
  }
1480
1503
  }
1481
1504
  function invokeOnChangeHandler(key, action, state, newState) {
1482
- var props = action.props,
1483
- type = action.type;
1484
- var handler = "on" + capitalizeString(key) + "Change";
1505
+ const {
1506
+ props,
1507
+ type
1508
+ } = action;
1509
+ const handler = `on${capitalizeString(key)}Change`;
1485
1510
  if (props[handler] && newState[key] !== undefined && newState[key] !== state[key]) {
1486
- props[handler](_extends__default["default"]({
1487
- type: type
1488
- }, newState));
1511
+ props[handler]({
1512
+ type,
1513
+ ...newState
1514
+ });
1489
1515
  }
1490
1516
  }
1491
1517
 
@@ -1507,36 +1533,37 @@ function stateReducer(s, a) {
1507
1533
  * @returns {string} The a11y message.
1508
1534
  */
1509
1535
  function getA11ySelectionMessage(selectionParameters) {
1510
- var selectedItem = selectionParameters.selectedItem,
1511
- itemToStringLocal = selectionParameters.itemToString;
1512
- return selectedItem ? itemToStringLocal(selectedItem) + " has been selected." : '';
1536
+ const {
1537
+ selectedItem,
1538
+ itemToString: itemToStringLocal
1539
+ } = selectionParameters;
1540
+ return selectedItem ? `${itemToStringLocal(selectedItem)} has been selected.` : '';
1513
1541
  }
1514
1542
 
1515
1543
  /**
1516
1544
  * Debounced call for updating the a11y message.
1517
1545
  */
1518
- var updateA11yStatus = debounce(function (getA11yMessage, document) {
1546
+ const updateA11yStatus = debounce((getA11yMessage, document) => {
1519
1547
  setStatus(getA11yMessage(), document);
1520
1548
  }, 200);
1521
1549
 
1522
1550
  // istanbul ignore next
1523
- var useIsomorphicLayoutEffect = typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined' ? preact.useLayoutEffect : preact.useEffect;
1551
+ const useIsomorphicLayoutEffect = typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined' ? preact.useLayoutEffect : preact.useEffect;
1524
1552
  function useElementIds(_ref) {
1525
- var _ref$id = _ref.id,
1526
- id = _ref$id === void 0 ? "downshift-" + generateId() : _ref$id,
1527
- labelId = _ref.labelId,
1528
- menuId = _ref.menuId,
1529
- getItemId = _ref.getItemId,
1530
- toggleButtonId = _ref.toggleButtonId,
1531
- inputId = _ref.inputId;
1532
- var elementIdsRef = preact.useRef({
1533
- labelId: labelId || id + "-label",
1534
- menuId: menuId || id + "-menu",
1535
- getItemId: getItemId || function (index) {
1536
- return id + "-item-" + index;
1537
- },
1538
- toggleButtonId: toggleButtonId || id + "-toggle-button",
1539
- inputId: inputId || id + "-input"
1553
+ let {
1554
+ id = `downshift-${generateId()}`,
1555
+ labelId,
1556
+ menuId,
1557
+ getItemId,
1558
+ toggleButtonId,
1559
+ inputId
1560
+ } = _ref;
1561
+ const elementIdsRef = preact.useRef({
1562
+ labelId: labelId || `${id}-label`,
1563
+ menuId: menuId || `${id}-menu`,
1564
+ getItemId: getItemId || (index => `${id}-item-${index}`),
1565
+ toggleButtonId: toggleButtonId || `${id}-toggle-button`,
1566
+ inputId: inputId || `${id}-input`
1540
1567
  });
1541
1568
  return elementIdsRef.current;
1542
1569
  }
@@ -1556,10 +1583,10 @@ function isAcceptedCharacterKey(key) {
1556
1583
  return /^\S{1}$/.test(key);
1557
1584
  }
1558
1585
  function capitalizeString(string) {
1559
- return "" + string.slice(0, 1).toUpperCase() + string.slice(1);
1586
+ return `${string.slice(0, 1).toUpperCase()}${string.slice(1)}`;
1560
1587
  }
1561
1588
  function useLatestRef(val) {
1562
- var ref = preact.useRef(val);
1589
+ const ref = preact.useRef(val);
1563
1590
  // technically this is not "concurrent mode safe" because we're manipulating
1564
1591
  // the value during render (so it's not idempotent). However, the places this
1565
1592
  // hook is used is to support memoizing callbacks which will be called
@@ -1580,28 +1607,26 @@ function useLatestRef(val) {
1580
1607
  * @returns {Array} An array with the state and an action dispatcher.
1581
1608
  */
1582
1609
  function useEnhancedReducer(reducer, initialState, props) {
1583
- var prevStateRef = preact.useRef();
1584
- var actionRef = preact.useRef();
1585
- var enhancedReducer = preact.useCallback(function (state, action) {
1610
+ const prevStateRef = preact.useRef();
1611
+ const actionRef = preact.useRef();
1612
+ const enhancedReducer = preact.useCallback((state, action) => {
1586
1613
  actionRef.current = action;
1587
1614
  state = getState(state, action.props);
1588
- var changes = reducer(state, action);
1589
- var newState = action.props.stateReducer(state, _extends__default["default"]({}, action, {
1590
- changes: changes
1591
- }));
1615
+ const changes = reducer(state, action);
1616
+ const newState = action.props.stateReducer(state, {
1617
+ ...action,
1618
+ changes
1619
+ });
1592
1620
  return newState;
1593
1621
  }, [reducer]);
1594
- var _useReducer = preact.useReducer(enhancedReducer, initialState),
1595
- state = _useReducer[0],
1596
- dispatch = _useReducer[1];
1597
- var propsRef = useLatestRef(props);
1598
- var dispatchWithProps = preact.useCallback(function (action) {
1599
- return dispatch(_extends__default["default"]({
1600
- props: propsRef.current
1601
- }, action));
1602
- }, [propsRef]);
1603
- var action = actionRef.current;
1604
- preact.useEffect(function () {
1622
+ const [state, dispatch] = preact.useReducer(enhancedReducer, initialState);
1623
+ const propsRef = useLatestRef(props);
1624
+ const dispatchWithProps = preact.useCallback(action => dispatch({
1625
+ props: propsRef.current,
1626
+ ...action
1627
+ }), [propsRef]);
1628
+ const action = actionRef.current;
1629
+ preact.useEffect(() => {
1605
1630
  if (action && prevStateRef.current && prevStateRef.current !== state) {
1606
1631
  callOnChangeProps(action, getState(prevStateRef.current, action.props), state);
1607
1632
  }
@@ -1620,16 +1645,14 @@ function useEnhancedReducer(reducer, initialState, props) {
1620
1645
  * @returns {Array} An array with the state and an action dispatcher.
1621
1646
  */
1622
1647
  function useControlledReducer$1(reducer, initialState, props) {
1623
- var _useEnhancedReducer = useEnhancedReducer(reducer, initialState, props),
1624
- state = _useEnhancedReducer[0],
1625
- dispatch = _useEnhancedReducer[1];
1648
+ const [state, dispatch] = useEnhancedReducer(reducer, initialState, props);
1626
1649
  return [getState(state, props), dispatch];
1627
1650
  }
1628
- var defaultProps$3 = {
1629
- itemToString: itemToString,
1630
- stateReducer: stateReducer,
1631
- getA11ySelectionMessage: getA11ySelectionMessage,
1632
- scrollIntoView: scrollIntoView,
1651
+ const defaultProps$3 = {
1652
+ itemToString,
1653
+ stateReducer,
1654
+ getA11ySelectionMessage,
1655
+ scrollIntoView,
1633
1656
  environment: /* istanbul ignore next (ssr) */
1634
1657
  typeof window === 'undefined' ? {} : window
1635
1658
  };
@@ -1637,7 +1660,7 @@ function getDefaultValue$1(props, propKey, defaultStateValues) {
1637
1660
  if (defaultStateValues === void 0) {
1638
1661
  defaultStateValues = dropdownDefaultStateValues;
1639
1662
  }
1640
- var defaultValue = props["default" + capitalizeString(propKey)];
1663
+ const defaultValue = props[`default${capitalizeString(propKey)}`];
1641
1664
  if (defaultValue !== undefined) {
1642
1665
  return defaultValue;
1643
1666
  }
@@ -1647,34 +1670,38 @@ function getInitialValue$1(props, propKey, defaultStateValues) {
1647
1670
  if (defaultStateValues === void 0) {
1648
1671
  defaultStateValues = dropdownDefaultStateValues;
1649
1672
  }
1650
- var value = props[propKey];
1673
+ const value = props[propKey];
1651
1674
  if (value !== undefined) {
1652
1675
  return value;
1653
1676
  }
1654
- var initialValue = props["initial" + capitalizeString(propKey)];
1677
+ const initialValue = props[`initial${capitalizeString(propKey)}`];
1655
1678
  if (initialValue !== undefined) {
1656
1679
  return initialValue;
1657
1680
  }
1658
1681
  return getDefaultValue$1(props, propKey, defaultStateValues);
1659
1682
  }
1660
1683
  function getInitialState$2(props) {
1661
- var selectedItem = getInitialValue$1(props, 'selectedItem');
1662
- var isOpen = getInitialValue$1(props, 'isOpen');
1663
- var highlightedIndex = getInitialValue$1(props, 'highlightedIndex');
1664
- var inputValue = getInitialValue$1(props, 'inputValue');
1684
+ const selectedItem = getInitialValue$1(props, 'selectedItem');
1685
+ const isOpen = getInitialValue$1(props, 'isOpen');
1686
+ const highlightedIndex = getInitialValue$1(props, 'highlightedIndex');
1687
+ const inputValue = getInitialValue$1(props, 'inputValue');
1665
1688
  return {
1666
1689
  highlightedIndex: highlightedIndex < 0 && selectedItem && isOpen ? props.items.indexOf(selectedItem) : highlightedIndex,
1667
- isOpen: isOpen,
1668
- selectedItem: selectedItem,
1669
- inputValue: inputValue
1690
+ isOpen,
1691
+ selectedItem,
1692
+ inputValue
1670
1693
  };
1671
1694
  }
1672
1695
  function getHighlightedIndexOnOpen(props, state, offset) {
1673
- var items = props.items,
1674
- initialHighlightedIndex = props.initialHighlightedIndex,
1675
- defaultHighlightedIndex = props.defaultHighlightedIndex;
1676
- var selectedItem = state.selectedItem,
1677
- highlightedIndex = state.highlightedIndex;
1696
+ const {
1697
+ items,
1698
+ initialHighlightedIndex,
1699
+ defaultHighlightedIndex
1700
+ } = props;
1701
+ const {
1702
+ selectedItem,
1703
+ highlightedIndex
1704
+ } = state;
1678
1705
  if (items.length === 0) {
1679
1706
  return -1;
1680
1707
  }
@@ -1705,34 +1732,30 @@ function getHighlightedIndexOnOpen(props, state, offset) {
1705
1732
  * @returns {Object} Ref containing whether mouseDown or touchMove event is happening
1706
1733
  */
1707
1734
  function useMouseAndTouchTracker(isOpen, downshiftElementRefs, environment, handleBlur) {
1708
- var mouseAndTouchTrackersRef = preact.useRef({
1735
+ const mouseAndTouchTrackersRef = preact.useRef({
1709
1736
  isMouseDown: false,
1710
1737
  isTouchMove: false
1711
1738
  });
1712
- preact.useEffect(function () {
1739
+ preact.useEffect(() => {
1713
1740
  // The same strategy for checking if a click occurred inside or outside downsift
1714
1741
  // as in downshift.js.
1715
- var onMouseDown = function onMouseDown() {
1742
+ const onMouseDown = () => {
1716
1743
  mouseAndTouchTrackersRef.current.isMouseDown = true;
1717
1744
  };
1718
- var onMouseUp = function onMouseUp(event) {
1745
+ const onMouseUp = event => {
1719
1746
  mouseAndTouchTrackersRef.current.isMouseDown = false;
1720
- if (isOpen && !targetWithinDownshift(event.target, downshiftElementRefs.map(function (ref) {
1721
- return ref.current;
1722
- }), environment)) {
1747
+ if (isOpen && !targetWithinDownshift(event.target, downshiftElementRefs.map(ref => ref.current), environment)) {
1723
1748
  handleBlur();
1724
1749
  }
1725
1750
  };
1726
- var onTouchStart = function onTouchStart() {
1751
+ const onTouchStart = () => {
1727
1752
  mouseAndTouchTrackersRef.current.isTouchMove = false;
1728
1753
  };
1729
- var onTouchMove = function onTouchMove() {
1754
+ const onTouchMove = () => {
1730
1755
  mouseAndTouchTrackersRef.current.isTouchMove = true;
1731
1756
  };
1732
- var onTouchEnd = function onTouchEnd(event) {
1733
- if (isOpen && !mouseAndTouchTrackersRef.current.isTouchMove && !targetWithinDownshift(event.target, downshiftElementRefs.map(function (ref) {
1734
- return ref.current;
1735
- }), environment, false)) {
1757
+ const onTouchEnd = event => {
1758
+ if (isOpen && !mouseAndTouchTrackersRef.current.isTouchMove && !targetWithinDownshift(event.target, downshiftElementRefs.map(ref => ref.current), environment, false)) {
1736
1759
  handleBlur();
1737
1760
  }
1738
1761
  };
@@ -1755,9 +1778,7 @@ function useMouseAndTouchTracker(isOpen, downshiftElementRefs, environment, hand
1755
1778
 
1756
1779
  /* istanbul ignore next */
1757
1780
  // eslint-disable-next-line import/no-mutable-exports
1758
- var useGetterPropsCalledChecker = function useGetterPropsCalledChecker() {
1759
- return noop;
1760
- };
1781
+ let useGetterPropsCalledChecker = () => noop;
1761
1782
  /**
1762
1783
  * Custom hook that checks if getter props are called correctly.
1763
1784
  *
@@ -1766,77 +1787,82 @@ var useGetterPropsCalledChecker = function useGetterPropsCalledChecker() {
1766
1787
  */
1767
1788
  /* istanbul ignore next */
1768
1789
  if (process.env.NODE_ENV !== 'production') {
1769
- useGetterPropsCalledChecker = function useGetterPropsCalledChecker() {
1770
- var isInitialMountRef = preact.useRef(true);
1790
+ useGetterPropsCalledChecker = function () {
1791
+ const isInitialMountRef = preact.useRef(true);
1771
1792
  for (var _len = arguments.length, propKeys = new Array(_len), _key = 0; _key < _len; _key++) {
1772
1793
  propKeys[_key] = arguments[_key];
1773
1794
  }
1774
- var getterPropsCalledRef = preact.useRef(propKeys.reduce(function (acc, propKey) {
1795
+ const getterPropsCalledRef = preact.useRef(propKeys.reduce((acc, propKey) => {
1775
1796
  acc[propKey] = {};
1776
1797
  return acc;
1777
1798
  }, {}));
1778
- preact.useEffect(function () {
1779
- Object.keys(getterPropsCalledRef.current).forEach(function (propKey) {
1780
- var propCallInfo = getterPropsCalledRef.current[propKey];
1799
+ preact.useEffect(() => {
1800
+ Object.keys(getterPropsCalledRef.current).forEach(propKey => {
1801
+ const propCallInfo = getterPropsCalledRef.current[propKey];
1781
1802
  if (isInitialMountRef.current) {
1782
1803
  if (!Object.keys(propCallInfo).length) {
1783
1804
  // eslint-disable-next-line no-console
1784
- console.error("downshift: You forgot to call the " + propKey + " getter function on your component / element.");
1805
+ console.error(`downshift: You forgot to call the ${propKey} getter function on your component / element.`);
1785
1806
  return;
1786
1807
  }
1787
1808
  }
1788
- var suppressRefError = propCallInfo.suppressRefError,
1789
- refKey = propCallInfo.refKey,
1790
- elementRef = propCallInfo.elementRef;
1809
+ const {
1810
+ suppressRefError,
1811
+ refKey,
1812
+ elementRef
1813
+ } = propCallInfo;
1791
1814
  if ((!elementRef || !elementRef.current) && !suppressRefError) {
1792
1815
  // eslint-disable-next-line no-console
1793
- console.error("downshift: The ref prop \"" + refKey + "\" from " + propKey + " was not applied correctly on your element.");
1816
+ console.error(`downshift: The ref prop "${refKey}" from ${propKey} was not applied correctly on your element.`);
1794
1817
  }
1795
1818
  });
1796
1819
  isInitialMountRef.current = false;
1797
1820
  });
1798
- var setGetterPropCallInfo = preact.useCallback(function (propKey, suppressRefError, refKey, elementRef) {
1821
+ const setGetterPropCallInfo = preact.useCallback((propKey, suppressRefError, refKey, elementRef) => {
1799
1822
  getterPropsCalledRef.current[propKey] = {
1800
- suppressRefError: suppressRefError,
1801
- refKey: refKey,
1802
- elementRef: elementRef
1823
+ suppressRefError,
1824
+ refKey,
1825
+ elementRef
1803
1826
  };
1804
1827
  }, []);
1805
1828
  return setGetterPropCallInfo;
1806
1829
  };
1807
1830
  }
1808
1831
  function useA11yMessageSetter(getA11yMessage, dependencyArray, _ref2) {
1809
- var isInitialMount = _ref2.isInitialMount,
1810
- highlightedIndex = _ref2.highlightedIndex,
1811
- items = _ref2.items,
1812
- environment = _ref2.environment,
1813
- rest = _objectWithoutPropertiesLoose__default["default"](_ref2, _excluded$3);
1832
+ let {
1833
+ isInitialMount,
1834
+ highlightedIndex,
1835
+ items,
1836
+ environment,
1837
+ ...rest
1838
+ } = _ref2;
1814
1839
  // Sets a11y status message on changes in state.
1815
- preact.useEffect(function () {
1840
+ preact.useEffect(() => {
1816
1841
  if (isInitialMount || false) {
1817
1842
  return;
1818
1843
  }
1819
- updateA11yStatus(function () {
1820
- return getA11yMessage(_extends__default["default"]({
1821
- highlightedIndex: highlightedIndex,
1822
- highlightedItem: items[highlightedIndex],
1823
- resultCount: items.length
1824
- }, rest));
1825
- }, environment.document);
1844
+ updateA11yStatus(() => getA11yMessage({
1845
+ highlightedIndex,
1846
+ highlightedItem: items[highlightedIndex],
1847
+ resultCount: items.length,
1848
+ ...rest
1849
+ }), environment.document);
1826
1850
  // eslint-disable-next-line react-hooks/exhaustive-deps
1827
1851
  }, dependencyArray);
1828
1852
  }
1829
1853
  function useScrollIntoView(_ref3) {
1830
- var highlightedIndex = _ref3.highlightedIndex,
1831
- isOpen = _ref3.isOpen,
1832
- itemRefs = _ref3.itemRefs,
1833
- getItemNodeFromIndex = _ref3.getItemNodeFromIndex,
1834
- menuElement = _ref3.menuElement,
1835
- scrollIntoViewProp = _ref3.scrollIntoView;
1854
+ let {
1855
+ highlightedIndex,
1856
+ isOpen,
1857
+ itemRefs,
1858
+ getItemNodeFromIndex,
1859
+ menuElement,
1860
+ scrollIntoView: scrollIntoViewProp
1861
+ } = _ref3;
1836
1862
  // used not to scroll on highlight by mouse.
1837
- var shouldScrollRef = preact.useRef(true);
1863
+ const shouldScrollRef = preact.useRef(true);
1838
1864
  // Scroll on highlighted item if change comes from keyboard.
1839
- useIsomorphicLayoutEffect(function () {
1865
+ useIsomorphicLayoutEffect(() => {
1840
1866
  if (highlightedIndex < 0 || !isOpen || !Object.keys(itemRefs.current).length) {
1841
1867
  return;
1842
1868
  }
@@ -1851,16 +1877,18 @@ function useScrollIntoView(_ref3) {
1851
1877
  }
1852
1878
 
1853
1879
  // eslint-disable-next-line import/no-mutable-exports
1854
- var useControlPropsValidator = noop;
1880
+ let useControlPropsValidator = noop;
1855
1881
  /* istanbul ignore next */
1856
1882
  if (process.env.NODE_ENV !== 'production') {
1857
- useControlPropsValidator = function useControlPropsValidator(_ref4) {
1858
- var isInitialMount = _ref4.isInitialMount,
1859
- props = _ref4.props,
1860
- state = _ref4.state;
1883
+ useControlPropsValidator = _ref4 => {
1884
+ let {
1885
+ isInitialMount,
1886
+ props,
1887
+ state
1888
+ } = _ref4;
1861
1889
  // used for checking when props are moving from controlled to uncontrolled.
1862
- var prevPropsRef = preact.useRef(props);
1863
- preact.useEffect(function () {
1890
+ const prevPropsRef = preact.useRef(props);
1891
+ preact.useEffect(() => {
1864
1892
  if (isInitialMount) {
1865
1893
  return;
1866
1894
  }
@@ -1871,9 +1899,11 @@ if (process.env.NODE_ENV !== 'production') {
1871
1899
  }
1872
1900
 
1873
1901
  function downshiftCommonReducer(state, action, stateChangeTypes) {
1874
- var type = action.type,
1875
- props = action.props;
1876
- var changes;
1902
+ const {
1903
+ type,
1904
+ props
1905
+ } = action;
1906
+ let changes;
1877
1907
  switch (type) {
1878
1908
  case stateChangeTypes.ItemMouseMove:
1879
1909
  changes = {
@@ -1924,7 +1954,10 @@ function downshiftCommonReducer(state, action, stateChangeTypes) {
1924
1954
  default:
1925
1955
  throw new Error('Reducer called without proper action type.');
1926
1956
  }
1927
- return _extends__default["default"]({}, state, changes);
1957
+ return {
1958
+ ...state,
1959
+ ...changes
1960
+ };
1928
1961
  }
1929
1962
  /* eslint-enable complexity */
1930
1963
 
@@ -2010,28 +2043,28 @@ if (process.env.NODE_ENV !== 'production') {
2010
2043
  };
2011
2044
  }
2012
2045
 
2013
- var ToggleButtonClick$1 = process.env.NODE_ENV !== "production" ? '__togglebutton_click__' : 0;
2014
- var ToggleButtonKeyDownArrowDown = process.env.NODE_ENV !== "production" ? '__togglebutton_keydown_arrow_down__' : 1;
2015
- var ToggleButtonKeyDownArrowUp = process.env.NODE_ENV !== "production" ? '__togglebutton_keydown_arrow_up__' : 2;
2016
- var ToggleButtonKeyDownCharacter = process.env.NODE_ENV !== "production" ? '__togglebutton_keydown_character__' : 3;
2017
- var ToggleButtonKeyDownEscape = process.env.NODE_ENV !== "production" ? '__togglebutton_keydown_escape__' : 4;
2018
- var ToggleButtonKeyDownHome = process.env.NODE_ENV !== "production" ? '__togglebutton_keydown_home__' : 5;
2019
- var ToggleButtonKeyDownEnd = process.env.NODE_ENV !== "production" ? '__togglebutton_keydown_end__' : 6;
2020
- var ToggleButtonKeyDownEnter = process.env.NODE_ENV !== "production" ? '__togglebutton_keydown_enter__' : 7;
2021
- var ToggleButtonKeyDownSpaceButton = process.env.NODE_ENV !== "production" ? '__togglebutton_keydown_space_button__' : 8;
2022
- var ToggleButtonKeyDownPageUp = process.env.NODE_ENV !== "production" ? '__togglebutton_keydown_page_up__' : 9;
2023
- var ToggleButtonKeyDownPageDown = process.env.NODE_ENV !== "production" ? '__togglebutton_keydown_page_down__' : 10;
2024
- var ToggleButtonBlur = process.env.NODE_ENV !== "production" ? '__togglebutton_blur__' : 11;
2025
- var MenuMouseLeave$1 = process.env.NODE_ENV !== "production" ? '__menu_mouse_leave__' : 12;
2026
- var ItemMouseMove$1 = process.env.NODE_ENV !== "production" ? '__item_mouse_move__' : 13;
2027
- var ItemClick$1 = process.env.NODE_ENV !== "production" ? '__item_click__' : 14;
2028
- var FunctionToggleMenu$1 = process.env.NODE_ENV !== "production" ? '__function_toggle_menu__' : 15;
2029
- var FunctionOpenMenu$1 = process.env.NODE_ENV !== "production" ? '__function_open_menu__' : 16;
2030
- var FunctionCloseMenu$1 = process.env.NODE_ENV !== "production" ? '__function_close_menu__' : 17;
2031
- var FunctionSetHighlightedIndex$1 = process.env.NODE_ENV !== "production" ? '__function_set_highlighted_index__' : 18;
2032
- var FunctionSelectItem$1 = process.env.NODE_ENV !== "production" ? '__function_select_item__' : 19;
2033
- var FunctionSetInputValue$1 = process.env.NODE_ENV !== "production" ? '__function_set_input_value__' : 20;
2034
- var FunctionReset$2 = process.env.NODE_ENV !== "production" ? '__function_reset__' : 21;
2046
+ const ToggleButtonClick$1 = process.env.NODE_ENV !== "production" ? '__togglebutton_click__' : 0;
2047
+ const ToggleButtonKeyDownArrowDown = process.env.NODE_ENV !== "production" ? '__togglebutton_keydown_arrow_down__' : 1;
2048
+ const ToggleButtonKeyDownArrowUp = process.env.NODE_ENV !== "production" ? '__togglebutton_keydown_arrow_up__' : 2;
2049
+ const ToggleButtonKeyDownCharacter = process.env.NODE_ENV !== "production" ? '__togglebutton_keydown_character__' : 3;
2050
+ const ToggleButtonKeyDownEscape = process.env.NODE_ENV !== "production" ? '__togglebutton_keydown_escape__' : 4;
2051
+ const ToggleButtonKeyDownHome = process.env.NODE_ENV !== "production" ? '__togglebutton_keydown_home__' : 5;
2052
+ const ToggleButtonKeyDownEnd = process.env.NODE_ENV !== "production" ? '__togglebutton_keydown_end__' : 6;
2053
+ const ToggleButtonKeyDownEnter = process.env.NODE_ENV !== "production" ? '__togglebutton_keydown_enter__' : 7;
2054
+ const ToggleButtonKeyDownSpaceButton = process.env.NODE_ENV !== "production" ? '__togglebutton_keydown_space_button__' : 8;
2055
+ const ToggleButtonKeyDownPageUp = process.env.NODE_ENV !== "production" ? '__togglebutton_keydown_page_up__' : 9;
2056
+ const ToggleButtonKeyDownPageDown = process.env.NODE_ENV !== "production" ? '__togglebutton_keydown_page_down__' : 10;
2057
+ const ToggleButtonBlur = process.env.NODE_ENV !== "production" ? '__togglebutton_blur__' : 11;
2058
+ const MenuMouseLeave$1 = process.env.NODE_ENV !== "production" ? '__menu_mouse_leave__' : 12;
2059
+ const ItemMouseMove$1 = process.env.NODE_ENV !== "production" ? '__item_mouse_move__' : 13;
2060
+ const ItemClick$1 = process.env.NODE_ENV !== "production" ? '__item_click__' : 14;
2061
+ const FunctionToggleMenu$1 = process.env.NODE_ENV !== "production" ? '__function_toggle_menu__' : 15;
2062
+ const FunctionOpenMenu$1 = process.env.NODE_ENV !== "production" ? '__function_open_menu__' : 16;
2063
+ const FunctionCloseMenu$1 = process.env.NODE_ENV !== "production" ? '__function_close_menu__' : 17;
2064
+ const FunctionSetHighlightedIndex$1 = process.env.NODE_ENV !== "production" ? '__function_set_highlighted_index__' : 18;
2065
+ const FunctionSelectItem$1 = process.env.NODE_ENV !== "production" ? '__function_select_item__' : 19;
2066
+ const FunctionSetInputValue$1 = process.env.NODE_ENV !== "production" ? '__function_set_input_value__' : 20;
2067
+ const FunctionReset$2 = process.env.NODE_ENV !== "production" ? '__function_reset__' : 21;
2035
2068
 
2036
2069
  var stateChangeTypes$2 = /*#__PURE__*/Object.freeze({
2037
2070
  __proto__: null,
@@ -2061,10 +2094,12 @@ var stateChangeTypes$2 = /*#__PURE__*/Object.freeze({
2061
2094
 
2062
2095
  /* eslint-disable complexity */
2063
2096
  function downshiftSelectReducer(state, action) {
2064
- var type = action.type,
2065
- props = action.props,
2066
- altKey = action.altKey;
2067
- var changes;
2097
+ const {
2098
+ type,
2099
+ props,
2100
+ altKey
2101
+ } = action;
2102
+ let changes;
2068
2103
  switch (type) {
2069
2104
  case ItemClick$1:
2070
2105
  changes = {
@@ -2075,10 +2110,10 @@ function downshiftSelectReducer(state, action) {
2075
2110
  break;
2076
2111
  case ToggleButtonKeyDownCharacter:
2077
2112
  {
2078
- var lowercasedKey = action.key;
2079
- var inputValue = "" + state.inputValue + lowercasedKey;
2080
- var prevHighlightedIndex = !state.isOpen && state.selectedItem ? props.items.indexOf(state.selectedItem) : state.highlightedIndex;
2081
- var highlightedIndex = getItemIndexByCharacterKey({
2113
+ const lowercasedKey = action.key;
2114
+ const inputValue = `${state.inputValue}${lowercasedKey}`;
2115
+ const prevHighlightedIndex = !state.isOpen && state.selectedItem ? props.items.indexOf(state.selectedItem) : state.highlightedIndex;
2116
+ const highlightedIndex = getItemIndexByCharacterKey({
2082
2117
  keysSoFar: inputValue,
2083
2118
  highlightedIndex: prevHighlightedIndex,
2084
2119
  items: props.items,
@@ -2086,33 +2121,34 @@ function downshiftSelectReducer(state, action) {
2086
2121
  getItemNodeFromIndex: action.getItemNodeFromIndex
2087
2122
  });
2088
2123
  changes = {
2089
- inputValue: inputValue,
2090
- highlightedIndex: highlightedIndex,
2124
+ inputValue,
2125
+ highlightedIndex,
2091
2126
  isOpen: true
2092
2127
  };
2093
2128
  }
2094
2129
  break;
2095
2130
  case ToggleButtonKeyDownArrowDown:
2096
2131
  {
2097
- var _highlightedIndex = state.isOpen ? getNextWrappingIndex(1, state.highlightedIndex, props.items.length, action.getItemNodeFromIndex, false) : altKey && state.selectedItem == null ? -1 : getHighlightedIndexOnOpen(props, state, 1);
2132
+ const highlightedIndex = state.isOpen ? getNextWrappingIndex(1, state.highlightedIndex, props.items.length, action.getItemNodeFromIndex, false) : altKey && state.selectedItem == null ? -1 : getHighlightedIndexOnOpen(props, state, 1);
2098
2133
  changes = {
2099
- highlightedIndex: _highlightedIndex,
2134
+ highlightedIndex,
2100
2135
  isOpen: true
2101
2136
  };
2102
2137
  }
2103
2138
  break;
2104
2139
  case ToggleButtonKeyDownArrowUp:
2105
2140
  if (state.isOpen && altKey) {
2106
- changes = _extends__default["default"]({
2141
+ changes = {
2107
2142
  isOpen: getDefaultValue$1(props, 'isOpen'),
2108
- highlightedIndex: getDefaultValue$1(props, 'highlightedIndex')
2109
- }, state.highlightedIndex >= 0 && {
2110
- selectedItem: props.items[state.highlightedIndex]
2111
- });
2143
+ highlightedIndex: getDefaultValue$1(props, 'highlightedIndex'),
2144
+ ...(state.highlightedIndex >= 0 && {
2145
+ selectedItem: props.items[state.highlightedIndex]
2146
+ })
2147
+ };
2112
2148
  } else {
2113
- var _highlightedIndex2 = state.isOpen ? getNextWrappingIndex(-1, state.highlightedIndex, props.items.length, action.getItemNodeFromIndex, false) : getHighlightedIndexOnOpen(props, state, -1);
2149
+ const highlightedIndex = state.isOpen ? getNextWrappingIndex(-1, state.highlightedIndex, props.items.length, action.getItemNodeFromIndex, false) : getHighlightedIndexOnOpen(props, state, -1);
2114
2150
  changes = {
2115
- highlightedIndex: _highlightedIndex2,
2151
+ highlightedIndex,
2116
2152
  isOpen: true
2117
2153
  };
2118
2154
  }
@@ -2120,12 +2156,13 @@ function downshiftSelectReducer(state, action) {
2120
2156
  // only triggered when menu is open.
2121
2157
  case ToggleButtonKeyDownEnter:
2122
2158
  case ToggleButtonKeyDownSpaceButton:
2123
- changes = _extends__default["default"]({
2159
+ changes = {
2124
2160
  isOpen: getDefaultValue$1(props, 'isOpen'),
2125
- highlightedIndex: getDefaultValue$1(props, 'highlightedIndex')
2126
- }, state.highlightedIndex >= 0 && {
2127
- selectedItem: props.items[state.highlightedIndex]
2128
- });
2161
+ highlightedIndex: getDefaultValue$1(props, 'highlightedIndex'),
2162
+ ...(state.highlightedIndex >= 0 && {
2163
+ selectedItem: props.items[state.highlightedIndex]
2164
+ })
2165
+ };
2129
2166
  break;
2130
2167
  case ToggleButtonKeyDownHome:
2131
2168
  changes = {
@@ -2156,12 +2193,13 @@ function downshiftSelectReducer(state, action) {
2156
2193
  };
2157
2194
  break;
2158
2195
  case ToggleButtonBlur:
2159
- changes = _extends__default["default"]({
2196
+ changes = {
2160
2197
  isOpen: false,
2161
- highlightedIndex: -1
2162
- }, state.highlightedIndex >= 0 && {
2163
- selectedItem: props.items[state.highlightedIndex]
2164
- });
2198
+ highlightedIndex: -1,
2199
+ ...(state.highlightedIndex >= 0 && {
2200
+ selectedItem: props.items[state.highlightedIndex]
2201
+ })
2202
+ };
2165
2203
  break;
2166
2204
  case FunctionSelectItem$1:
2167
2205
  changes = {
@@ -2171,13 +2209,13 @@ function downshiftSelectReducer(state, action) {
2171
2209
  default:
2172
2210
  return downshiftCommonReducer(state, action, stateChangeTypes$2);
2173
2211
  }
2174
- return _extends__default["default"]({}, state, changes);
2212
+ return {
2213
+ ...state,
2214
+ ...changes
2215
+ };
2175
2216
  }
2176
2217
  /* eslint-enable complexity */
2177
2218
 
2178
- var _excluded$2 = ["onMouseLeave", "refKey", "onKeyDown", "onBlur", "ref"],
2179
- _excluded2$2 = ["onBlur", "onClick", "onKeyDown", "refKey", "ref"],
2180
- _excluded3$1 = ["item", "index", "onMouseMove", "onClick", "refKey", "ref", "disabled"];
2181
2219
  useSelect.stateChangeTypes = stateChangeTypes$2;
2182
2220
  function useSelect(userProps) {
2183
2221
  if (userProps === void 0) {
@@ -2185,76 +2223,81 @@ function useSelect(userProps) {
2185
2223
  }
2186
2224
  validatePropTypes$2(userProps, useSelect);
2187
2225
  // Props defaults and destructuring.
2188
- var props = _extends__default["default"]({}, defaultProps$2, userProps);
2189
- var items = props.items,
2190
- scrollIntoView = props.scrollIntoView,
2191
- environment = props.environment,
2192
- itemToString = props.itemToString,
2193
- getA11ySelectionMessage = props.getA11ySelectionMessage,
2194
- getA11yStatusMessage = props.getA11yStatusMessage;
2226
+ const props = {
2227
+ ...defaultProps$2,
2228
+ ...userProps
2229
+ };
2230
+ const {
2231
+ items,
2232
+ scrollIntoView,
2233
+ environment,
2234
+ itemToString,
2235
+ getA11ySelectionMessage,
2236
+ getA11yStatusMessage
2237
+ } = props;
2195
2238
  // Initial state depending on controlled props.
2196
- var initialState = getInitialState$2(props);
2197
- var _useControlledReducer = useControlledReducer$1(downshiftSelectReducer, initialState, props),
2198
- state = _useControlledReducer[0],
2199
- dispatch = _useControlledReducer[1];
2200
- var isOpen = state.isOpen,
2201
- highlightedIndex = state.highlightedIndex,
2202
- selectedItem = state.selectedItem,
2203
- inputValue = state.inputValue;
2239
+ const initialState = getInitialState$2(props);
2240
+ const [state, dispatch] = useControlledReducer$1(downshiftSelectReducer, initialState, props);
2241
+ const {
2242
+ isOpen,
2243
+ highlightedIndex,
2244
+ selectedItem,
2245
+ inputValue
2246
+ } = state;
2204
2247
 
2205
2248
  // Element efs.
2206
- var toggleButtonRef = preact.useRef(null);
2207
- var menuRef = preact.useRef(null);
2208
- var itemRefs = preact.useRef({});
2249
+ const toggleButtonRef = preact.useRef(null);
2250
+ const menuRef = preact.useRef(null);
2251
+ const itemRefs = preact.useRef({});
2209
2252
  // used to keep the inputValue clearTimeout object between renders.
2210
- var clearTimeoutRef = preact.useRef(null);
2253
+ const clearTimeoutRef = preact.useRef(null);
2211
2254
  // prevent id re-generation between renders.
2212
- var elementIds = useElementIds(props);
2255
+ const elementIds = useElementIds(props);
2213
2256
  // used to keep track of how many items we had on previous cycle.
2214
- var previousResultCountRef = preact.useRef();
2215
- var isInitialMountRef = preact.useRef(true);
2257
+ const previousResultCountRef = preact.useRef();
2258
+ const isInitialMountRef = preact.useRef(true);
2216
2259
  // utility callback to get item element.
2217
- var latest = useLatestRef({
2218
- state: state,
2219
- props: props
2260
+ const latest = useLatestRef({
2261
+ state,
2262
+ props
2220
2263
  });
2221
2264
 
2222
2265
  // Some utils.
2223
- var getItemNodeFromIndex = preact.useCallback(function (index) {
2224
- return itemRefs.current[elementIds.getItemId(index)];
2225
- }, [elementIds]);
2266
+ const getItemNodeFromIndex = preact.useCallback(index => itemRefs.current[elementIds.getItemId(index)], [elementIds]);
2226
2267
 
2227
2268
  // Effects.
2228
2269
  // Sets a11y status message on changes in state.
2229
- useA11yMessageSetter(getA11yStatusMessage, [isOpen, highlightedIndex, inputValue, items], _extends__default["default"]({
2270
+ useA11yMessageSetter(getA11yStatusMessage, [isOpen, highlightedIndex, inputValue, items], {
2230
2271
  isInitialMount: isInitialMountRef.current,
2231
2272
  previousResultCount: previousResultCountRef.current,
2232
- items: items,
2233
- environment: environment,
2234
- itemToString: itemToString
2235
- }, state));
2273
+ items,
2274
+ environment,
2275
+ itemToString,
2276
+ ...state
2277
+ });
2236
2278
  // Sets a11y status message on changes in selectedItem.
2237
- useA11yMessageSetter(getA11ySelectionMessage, [selectedItem], _extends__default["default"]({
2279
+ useA11yMessageSetter(getA11ySelectionMessage, [selectedItem], {
2238
2280
  isInitialMount: isInitialMountRef.current,
2239
2281
  previousResultCount: previousResultCountRef.current,
2240
- items: items,
2241
- environment: environment,
2242
- itemToString: itemToString
2243
- }, state));
2282
+ items,
2283
+ environment,
2284
+ itemToString,
2285
+ ...state
2286
+ });
2244
2287
  // Scroll on highlighted item if change comes from keyboard.
2245
- var shouldScrollRef = useScrollIntoView({
2288
+ const shouldScrollRef = useScrollIntoView({
2246
2289
  menuElement: menuRef.current,
2247
- highlightedIndex: highlightedIndex,
2248
- isOpen: isOpen,
2249
- itemRefs: itemRefs,
2250
- scrollIntoView: scrollIntoView,
2251
- getItemNodeFromIndex: getItemNodeFromIndex
2290
+ highlightedIndex,
2291
+ isOpen,
2292
+ itemRefs,
2293
+ scrollIntoView,
2294
+ getItemNodeFromIndex
2252
2295
  });
2253
2296
 
2254
2297
  // Sets cleanup for the keysSoFar callback, debounded after 500ms.
2255
- preact.useEffect(function () {
2298
+ preact.useEffect(() => {
2256
2299
  // init the clean function here as we need access to dispatch.
2257
- clearTimeoutRef.current = debounce(function (outerDispatch) {
2300
+ clearTimeoutRef.current = debounce(outerDispatch => {
2258
2301
  outerDispatch({
2259
2302
  type: FunctionSetInputValue$1,
2260
2303
  inputValue: ''
@@ -2262,13 +2305,13 @@ function useSelect(userProps) {
2262
2305
  }, 500);
2263
2306
 
2264
2307
  // Cancel any pending debounced calls on mount
2265
- return function () {
2308
+ return () => {
2266
2309
  clearTimeoutRef.current.cancel();
2267
2310
  };
2268
2311
  }, []);
2269
2312
 
2270
2313
  // Invokes the keysSoFar callback set up above.
2271
- preact.useEffect(function () {
2314
+ preact.useEffect(() => {
2272
2315
  if (!inputValue) {
2273
2316
  return;
2274
2317
  }
@@ -2276,234 +2319,249 @@ function useSelect(userProps) {
2276
2319
  }, [dispatch, inputValue]);
2277
2320
  useControlPropsValidator({
2278
2321
  isInitialMount: isInitialMountRef.current,
2279
- props: props,
2280
- state: state
2322
+ props,
2323
+ state
2281
2324
  });
2282
- preact.useEffect(function () {
2325
+ preact.useEffect(() => {
2283
2326
  if (isInitialMountRef.current) {
2284
2327
  return;
2285
2328
  }
2286
2329
  previousResultCountRef.current = items.length;
2287
2330
  });
2288
2331
  // Add mouse/touch events to document.
2289
- var mouseAndTouchTrackersRef = useMouseAndTouchTracker(isOpen, [menuRef, toggleButtonRef], environment, function () {
2332
+ const mouseAndTouchTrackersRef = useMouseAndTouchTracker(isOpen, [menuRef, toggleButtonRef], environment, () => {
2290
2333
  dispatch({
2291
2334
  type: ToggleButtonBlur
2292
2335
  });
2293
2336
  });
2294
- var setGetterPropCallInfo = useGetterPropsCalledChecker('getMenuProps', 'getToggleButtonProps');
2337
+ const setGetterPropCallInfo = useGetterPropsCalledChecker('getMenuProps', 'getToggleButtonProps');
2295
2338
  // Make initial ref false.
2296
- preact.useEffect(function () {
2339
+ preact.useEffect(() => {
2297
2340
  isInitialMountRef.current = false;
2298
- return function () {
2341
+ return () => {
2299
2342
  isInitialMountRef.current = true;
2300
2343
  };
2301
2344
  }, []);
2302
2345
  // Reset itemRefs on close.
2303
- preact.useEffect(function () {
2346
+ preact.useEffect(() => {
2304
2347
  if (!isOpen) {
2305
2348
  itemRefs.current = {};
2306
2349
  }
2307
2350
  }, [isOpen]);
2308
2351
 
2309
2352
  // Event handler functions.
2310
- var toggleButtonKeyDownHandlers = preact.useMemo(function () {
2311
- return {
2312
- ArrowDown: function ArrowDown(event) {
2313
- event.preventDefault();
2353
+ const toggleButtonKeyDownHandlers = preact.useMemo(() => ({
2354
+ ArrowDown(event) {
2355
+ event.preventDefault();
2356
+ dispatch({
2357
+ type: ToggleButtonKeyDownArrowDown,
2358
+ getItemNodeFromIndex,
2359
+ altKey: event.altKey
2360
+ });
2361
+ },
2362
+ ArrowUp(event) {
2363
+ event.preventDefault();
2364
+ dispatch({
2365
+ type: ToggleButtonKeyDownArrowUp,
2366
+ getItemNodeFromIndex,
2367
+ altKey: event.altKey
2368
+ });
2369
+ },
2370
+ Home(event) {
2371
+ event.preventDefault();
2372
+ dispatch({
2373
+ type: ToggleButtonKeyDownHome,
2374
+ getItemNodeFromIndex
2375
+ });
2376
+ },
2377
+ End(event) {
2378
+ event.preventDefault();
2379
+ dispatch({
2380
+ type: ToggleButtonKeyDownEnd,
2381
+ getItemNodeFromIndex
2382
+ });
2383
+ },
2384
+ Escape() {
2385
+ if (latest.current.state.isOpen) {
2314
2386
  dispatch({
2315
- type: ToggleButtonKeyDownArrowDown,
2316
- getItemNodeFromIndex: getItemNodeFromIndex,
2317
- altKey: event.altKey
2387
+ type: ToggleButtonKeyDownEscape
2318
2388
  });
2319
- },
2320
- ArrowUp: function ArrowUp(event) {
2389
+ }
2390
+ },
2391
+ Enter(event) {
2392
+ event.preventDefault();
2393
+ dispatch({
2394
+ type: latest.current.state.isOpen ? ToggleButtonKeyDownEnter : ToggleButtonClick$1
2395
+ });
2396
+ },
2397
+ PageUp(event) {
2398
+ if (latest.current.state.isOpen) {
2321
2399
  event.preventDefault();
2322
2400
  dispatch({
2323
- type: ToggleButtonKeyDownArrowUp,
2324
- getItemNodeFromIndex: getItemNodeFromIndex,
2325
- altKey: event.altKey
2401
+ type: ToggleButtonKeyDownPageUp,
2402
+ getItemNodeFromIndex
2326
2403
  });
2327
- },
2328
- Home: function Home(event) {
2404
+ }
2405
+ },
2406
+ PageDown(event) {
2407
+ if (latest.current.state.isOpen) {
2329
2408
  event.preventDefault();
2330
2409
  dispatch({
2331
- type: ToggleButtonKeyDownHome,
2332
- getItemNodeFromIndex: getItemNodeFromIndex
2410
+ type: ToggleButtonKeyDownPageDown,
2411
+ getItemNodeFromIndex
2333
2412
  });
2334
- },
2335
- End: function End(event) {
2336
- event.preventDefault();
2413
+ }
2414
+ },
2415
+ ' '(event) {
2416
+ event.preventDefault();
2417
+ const currentState = latest.current.state;
2418
+ if (!currentState.isOpen) {
2337
2419
  dispatch({
2338
- type: ToggleButtonKeyDownEnd,
2339
- getItemNodeFromIndex: getItemNodeFromIndex
2420
+ type: ToggleButtonClick$1
2340
2421
  });
2341
- },
2342
- Escape: function Escape() {
2343
- if (latest.current.state.isOpen) {
2344
- dispatch({
2345
- type: ToggleButtonKeyDownEscape
2346
- });
2347
- }
2348
- },
2349
- Enter: function Enter(event) {
2350
- event.preventDefault();
2422
+ return;
2423
+ }
2424
+ if (currentState.inputValue) {
2351
2425
  dispatch({
2352
- type: latest.current.state.isOpen ? ToggleButtonKeyDownEnter : ToggleButtonClick$1
2426
+ type: ToggleButtonKeyDownCharacter,
2427
+ key: ' ',
2428
+ getItemNodeFromIndex
2429
+ });
2430
+ } else {
2431
+ dispatch({
2432
+ type: ToggleButtonKeyDownSpaceButton
2353
2433
  });
2354
- },
2355
- PageUp: function PageUp(event) {
2356
- if (latest.current.state.isOpen) {
2357
- event.preventDefault();
2358
- dispatch({
2359
- type: ToggleButtonKeyDownPageUp,
2360
- getItemNodeFromIndex: getItemNodeFromIndex
2361
- });
2362
- }
2363
- },
2364
- PageDown: function PageDown(event) {
2365
- if (latest.current.state.isOpen) {
2366
- event.preventDefault();
2367
- dispatch({
2368
- type: ToggleButtonKeyDownPageDown,
2369
- getItemNodeFromIndex: getItemNodeFromIndex
2370
- });
2371
- }
2372
- },
2373
- ' ': function _(event) {
2374
- event.preventDefault();
2375
- var currentState = latest.current.state;
2376
- if (!currentState.isOpen) {
2377
- dispatch({
2378
- type: ToggleButtonClick$1
2379
- });
2380
- return;
2381
- }
2382
- if (currentState.inputValue) {
2383
- dispatch({
2384
- type: ToggleButtonKeyDownCharacter,
2385
- key: ' ',
2386
- getItemNodeFromIndex: getItemNodeFromIndex
2387
- });
2388
- } else {
2389
- dispatch({
2390
- type: ToggleButtonKeyDownSpaceButton
2391
- });
2392
- }
2393
2434
  }
2394
- };
2395
- }, [dispatch, getItemNodeFromIndex, latest]);
2435
+ }
2436
+ }), [dispatch, getItemNodeFromIndex, latest]);
2396
2437
 
2397
2438
  // Action functions.
2398
- var toggleMenu = preact.useCallback(function () {
2439
+ const toggleMenu = preact.useCallback(() => {
2399
2440
  dispatch({
2400
2441
  type: FunctionToggleMenu$1
2401
2442
  });
2402
2443
  }, [dispatch]);
2403
- var closeMenu = preact.useCallback(function () {
2444
+ const closeMenu = preact.useCallback(() => {
2404
2445
  dispatch({
2405
2446
  type: FunctionCloseMenu$1
2406
2447
  });
2407
2448
  }, [dispatch]);
2408
- var openMenu = preact.useCallback(function () {
2449
+ const openMenu = preact.useCallback(() => {
2409
2450
  dispatch({
2410
2451
  type: FunctionOpenMenu$1
2411
2452
  });
2412
2453
  }, [dispatch]);
2413
- var setHighlightedIndex = preact.useCallback(function (newHighlightedIndex) {
2454
+ const setHighlightedIndex = preact.useCallback(newHighlightedIndex => {
2414
2455
  dispatch({
2415
2456
  type: FunctionSetHighlightedIndex$1,
2416
2457
  highlightedIndex: newHighlightedIndex
2417
2458
  });
2418
2459
  }, [dispatch]);
2419
- var selectItem = preact.useCallback(function (newSelectedItem) {
2460
+ const selectItem = preact.useCallback(newSelectedItem => {
2420
2461
  dispatch({
2421
2462
  type: FunctionSelectItem$1,
2422
2463
  selectedItem: newSelectedItem
2423
2464
  });
2424
2465
  }, [dispatch]);
2425
- var reset = preact.useCallback(function () {
2466
+ const reset = preact.useCallback(() => {
2426
2467
  dispatch({
2427
2468
  type: FunctionReset$2
2428
2469
  });
2429
2470
  }, [dispatch]);
2430
- var setInputValue = preact.useCallback(function (newInputValue) {
2471
+ const setInputValue = preact.useCallback(newInputValue => {
2431
2472
  dispatch({
2432
2473
  type: FunctionSetInputValue$1,
2433
2474
  inputValue: newInputValue
2434
2475
  });
2435
2476
  }, [dispatch]);
2436
2477
  // Getter functions.
2437
- var getLabelProps = preact.useCallback(function (labelProps) {
2438
- return _extends__default["default"]({
2439
- id: elementIds.labelId,
2440
- htmlFor: elementIds.toggleButtonId
2441
- }, labelProps);
2442
- }, [elementIds]);
2443
- var getMenuProps = preact.useCallback(function (_temp, _temp2) {
2444
- var _extends2;
2445
- var _ref = _temp === void 0 ? {} : _temp,
2446
- onMouseLeave = _ref.onMouseLeave,
2447
- _ref$refKey = _ref.refKey,
2448
- refKey = _ref$refKey === void 0 ? 'ref' : _ref$refKey;
2449
- _ref.onKeyDown;
2450
- _ref.onBlur;
2451
- var ref = _ref.ref,
2452
- rest = _objectWithoutPropertiesLoose__default["default"](_ref, _excluded$2);
2453
- var _ref2 = _temp2 === void 0 ? {} : _temp2,
2454
- _ref2$suppressRefErro = _ref2.suppressRefError,
2455
- suppressRefError = _ref2$suppressRefErro === void 0 ? false : _ref2$suppressRefErro;
2456
- var menuHandleMouseLeave = function menuHandleMouseLeave() {
2478
+ const getLabelProps = preact.useCallback(labelProps => ({
2479
+ id: elementIds.labelId,
2480
+ htmlFor: elementIds.toggleButtonId,
2481
+ ...labelProps
2482
+ }), [elementIds]);
2483
+ const getMenuProps = preact.useCallback(function (_temp, _temp2) {
2484
+ let {
2485
+ onMouseLeave,
2486
+ refKey = 'ref',
2487
+ onKeyDown,
2488
+ onBlur,
2489
+ ref,
2490
+ ...rest
2491
+ } = _temp === void 0 ? {} : _temp;
2492
+ let {
2493
+ suppressRefError = false
2494
+ } = _temp2 === void 0 ? {} : _temp2;
2495
+ const menuHandleMouseLeave = () => {
2457
2496
  dispatch({
2458
2497
  type: MenuMouseLeave$1
2459
2498
  });
2460
2499
  };
2461
2500
  setGetterPropCallInfo('getMenuProps', suppressRefError, refKey, menuRef);
2462
- return _extends__default["default"]((_extends2 = {}, _extends2[refKey] = handleRefs(ref, function (menuNode) {
2463
- menuRef.current = menuNode;
2464
- }), _extends2.id = elementIds.menuId, _extends2.role = 'listbox', _extends2['aria-labelledby'] = elementIds.labelId, _extends2.tabIndex = -1, _extends2.onMouseLeave = callAllEventHandlers(onMouseLeave, menuHandleMouseLeave), _extends2), rest);
2501
+ return {
2502
+ [refKey]: handleRefs(ref, menuNode => {
2503
+ menuRef.current = menuNode;
2504
+ }),
2505
+ id: elementIds.menuId,
2506
+ role: 'listbox',
2507
+ 'aria-labelledby': elementIds.labelId,
2508
+ tabIndex: -1,
2509
+ onMouseLeave: callAllEventHandlers(onMouseLeave, menuHandleMouseLeave),
2510
+ ...rest
2511
+ };
2465
2512
  }, [dispatch, setGetterPropCallInfo, elementIds]);
2466
- var getToggleButtonProps = preact.useCallback(function (_temp3, _temp4) {
2467
- var _extends3;
2468
- var _ref3 = _temp3 === void 0 ? {} : _temp3,
2469
- onBlur = _ref3.onBlur,
2470
- onClick = _ref3.onClick,
2471
- onKeyDown = _ref3.onKeyDown,
2472
- _ref3$refKey = _ref3.refKey,
2473
- refKey = _ref3$refKey === void 0 ? 'ref' : _ref3$refKey,
2474
- ref = _ref3.ref,
2475
- rest = _objectWithoutPropertiesLoose__default["default"](_ref3, _excluded2$2);
2476
- var _ref4 = _temp4 === void 0 ? {} : _temp4,
2477
- _ref4$suppressRefErro = _ref4.suppressRefError,
2478
- suppressRefError = _ref4$suppressRefErro === void 0 ? false : _ref4$suppressRefErro;
2479
- var latestState = latest.current.state;
2480
- var toggleButtonHandleClick = function toggleButtonHandleClick() {
2513
+ const getToggleButtonProps = preact.useCallback(function (_temp3, _temp4) {
2514
+ let {
2515
+ onBlur,
2516
+ onClick,
2517
+ onKeyDown,
2518
+ refKey = 'ref',
2519
+ ref,
2520
+ ...rest
2521
+ } = _temp3 === void 0 ? {} : _temp3;
2522
+ let {
2523
+ suppressRefError = false
2524
+ } = _temp4 === void 0 ? {} : _temp4;
2525
+ const latestState = latest.current.state;
2526
+ const toggleButtonHandleClick = () => {
2481
2527
  dispatch({
2482
2528
  type: ToggleButtonClick$1
2483
2529
  });
2484
2530
  };
2485
- var toggleButtonHandleBlur = function toggleButtonHandleBlur() {
2531
+ const toggleButtonHandleBlur = () => {
2486
2532
  if (latestState.isOpen && !mouseAndTouchTrackersRef.current.isMouseDown) {
2487
2533
  dispatch({
2488
2534
  type: ToggleButtonBlur
2489
2535
  });
2490
2536
  }
2491
2537
  };
2492
- var toggleButtonHandleKeyDown = function toggleButtonHandleKeyDown(event) {
2493
- var key = normalizeArrowKey(event);
2538
+ const toggleButtonHandleKeyDown = event => {
2539
+ const key = normalizeArrowKey(event);
2494
2540
  if (key && toggleButtonKeyDownHandlers[key]) {
2495
2541
  toggleButtonKeyDownHandlers[key](event);
2496
2542
  } else if (isAcceptedCharacterKey(key)) {
2497
2543
  dispatch({
2498
2544
  type: ToggleButtonKeyDownCharacter,
2499
- key: key,
2500
- getItemNodeFromIndex: getItemNodeFromIndex
2545
+ key,
2546
+ getItemNodeFromIndex
2501
2547
  });
2502
2548
  }
2503
2549
  };
2504
- var toggleProps = _extends__default["default"]((_extends3 = {}, _extends3[refKey] = handleRefs(ref, function (toggleButtonNode) {
2505
- toggleButtonRef.current = toggleButtonNode;
2506
- }), _extends3['aria-activedescendant'] = latestState.isOpen && latestState.highlightedIndex > -1 ? elementIds.getItemId(latestState.highlightedIndex) : '', _extends3['aria-controls'] = elementIds.menuId, _extends3['aria-expanded'] = latest.current.state.isOpen, _extends3['aria-haspopup'] = 'listbox', _extends3['aria-labelledby'] = "" + elementIds.labelId, _extends3.id = elementIds.toggleButtonId, _extends3.role = 'combobox', _extends3.tabIndex = 0, _extends3.onBlur = callAllEventHandlers(onBlur, toggleButtonHandleBlur), _extends3), rest);
2550
+ const toggleProps = {
2551
+ [refKey]: handleRefs(ref, toggleButtonNode => {
2552
+ toggleButtonRef.current = toggleButtonNode;
2553
+ }),
2554
+ 'aria-activedescendant': latestState.isOpen && latestState.highlightedIndex > -1 ? elementIds.getItemId(latestState.highlightedIndex) : '',
2555
+ 'aria-controls': elementIds.menuId,
2556
+ 'aria-expanded': latest.current.state.isOpen,
2557
+ 'aria-haspopup': 'listbox',
2558
+ 'aria-labelledby': `${elementIds.labelId}`,
2559
+ id: elementIds.toggleButtonId,
2560
+ role: 'combobox',
2561
+ tabIndex: 0,
2562
+ onBlur: callAllEventHandlers(onBlur, toggleButtonHandleBlur),
2563
+ ...rest
2564
+ };
2507
2565
  if (!rest.disabled) {
2508
2566
  toggleProps.onClick = callAllEventHandlers(onClick, toggleButtonHandleClick);
2509
2567
  toggleProps.onKeyDown = callAllEventHandlers(onKeyDown, toggleButtonHandleKeyDown);
@@ -2511,54 +2569,56 @@ function useSelect(userProps) {
2511
2569
  setGetterPropCallInfo('getToggleButtonProps', suppressRefError, refKey, toggleButtonRef);
2512
2570
  return toggleProps;
2513
2571
  }, [latest, elementIds, setGetterPropCallInfo, dispatch, mouseAndTouchTrackersRef, toggleButtonKeyDownHandlers, getItemNodeFromIndex]);
2514
- var getItemProps = preact.useCallback(function (_temp5) {
2515
- var _extends4;
2516
- var _ref5 = _temp5 === void 0 ? {} : _temp5,
2517
- itemProp = _ref5.item,
2518
- indexProp = _ref5.index,
2519
- onMouseMove = _ref5.onMouseMove,
2520
- onClick = _ref5.onClick,
2521
- _ref5$refKey = _ref5.refKey,
2522
- refKey = _ref5$refKey === void 0 ? 'ref' : _ref5$refKey,
2523
- ref = _ref5.ref,
2524
- disabled = _ref5.disabled,
2525
- rest = _objectWithoutPropertiesLoose__default["default"](_ref5, _excluded3$1);
2526
- var _latest$current = latest.current,
2527
- latestState = _latest$current.state,
2528
- latestProps = _latest$current.props;
2529
- var item = itemProp != null ? itemProp : items[indexProp];
2530
- var index = getItemIndex(indexProp, item, latestProps.items);
2531
- var itemHandleMouseMove = function itemHandleMouseMove() {
2572
+ const getItemProps = preact.useCallback(function (_temp5) {
2573
+ let {
2574
+ item: itemProp,
2575
+ index: indexProp,
2576
+ onMouseMove,
2577
+ onClick,
2578
+ refKey = 'ref',
2579
+ ref,
2580
+ disabled,
2581
+ ...rest
2582
+ } = _temp5 === void 0 ? {} : _temp5;
2583
+ const {
2584
+ state: latestState,
2585
+ props: latestProps
2586
+ } = latest.current;
2587
+ const item = itemProp ?? items[indexProp];
2588
+ const index = getItemIndex(indexProp, item, latestProps.items);
2589
+ const itemHandleMouseMove = () => {
2532
2590
  if (index === latestState.highlightedIndex) {
2533
2591
  return;
2534
2592
  }
2535
2593
  shouldScrollRef.current = false;
2536
2594
  dispatch({
2537
2595
  type: ItemMouseMove$1,
2538
- index: index,
2539
- disabled: disabled
2596
+ index,
2597
+ disabled
2540
2598
  });
2541
2599
  };
2542
- var itemHandleClick = function itemHandleClick() {
2600
+ const itemHandleClick = () => {
2543
2601
  dispatch({
2544
2602
  type: ItemClick$1,
2545
- index: index
2603
+ index
2546
2604
  });
2547
2605
  };
2548
- var itemIndex = getItemIndex(index, item, latestProps.items);
2606
+ const itemIndex = getItemIndex(index, item, latestProps.items);
2549
2607
  if (itemIndex < 0) {
2550
2608
  throw new Error('Pass either item or item index in getItemProps!');
2551
2609
  }
2552
- var itemProps = _extends__default["default"]((_extends4 = {
2553
- disabled: disabled,
2610
+ const itemProps = {
2611
+ disabled,
2554
2612
  role: 'option',
2555
- 'aria-selected': "" + (item === selectedItem),
2556
- id: elementIds.getItemId(itemIndex)
2557
- }, _extends4[refKey] = handleRefs(ref, function (itemNode) {
2558
- if (itemNode) {
2559
- itemRefs.current[elementIds.getItemId(itemIndex)] = itemNode;
2560
- }
2561
- }), _extends4), rest);
2613
+ 'aria-selected': `${item === selectedItem}`,
2614
+ id: elementIds.getItemId(itemIndex),
2615
+ [refKey]: handleRefs(ref, itemNode => {
2616
+ if (itemNode) {
2617
+ itemRefs.current[elementIds.getItemId(itemIndex)] = itemNode;
2618
+ }
2619
+ }),
2620
+ ...rest
2621
+ };
2562
2622
  if (!disabled) {
2563
2623
  itemProps.onClick = callAllEventHandlers(onClick, itemHandleClick);
2564
2624
  }
@@ -2567,49 +2627,49 @@ function useSelect(userProps) {
2567
2627
  }, [latest, items, selectedItem, elementIds, shouldScrollRef, dispatch]);
2568
2628
  return {
2569
2629
  // prop getters.
2570
- getToggleButtonProps: getToggleButtonProps,
2571
- getLabelProps: getLabelProps,
2572
- getMenuProps: getMenuProps,
2573
- getItemProps: getItemProps,
2630
+ getToggleButtonProps,
2631
+ getLabelProps,
2632
+ getMenuProps,
2633
+ getItemProps,
2574
2634
  // actions.
2575
- toggleMenu: toggleMenu,
2576
- openMenu: openMenu,
2577
- closeMenu: closeMenu,
2578
- setHighlightedIndex: setHighlightedIndex,
2579
- selectItem: selectItem,
2580
- reset: reset,
2581
- setInputValue: setInputValue,
2635
+ toggleMenu,
2636
+ openMenu,
2637
+ closeMenu,
2638
+ setHighlightedIndex,
2639
+ selectItem,
2640
+ reset,
2641
+ setInputValue,
2582
2642
  // state.
2583
- highlightedIndex: highlightedIndex,
2584
- isOpen: isOpen,
2585
- selectedItem: selectedItem,
2586
- inputValue: inputValue
2643
+ highlightedIndex,
2644
+ isOpen,
2645
+ selectedItem,
2646
+ inputValue
2587
2647
  };
2588
2648
  }
2589
2649
 
2590
- var InputKeyDownArrowDown = process.env.NODE_ENV !== "production" ? '__input_keydown_arrow_down__' : 0;
2591
- var InputKeyDownArrowUp = process.env.NODE_ENV !== "production" ? '__input_keydown_arrow_up__' : 1;
2592
- var InputKeyDownEscape = process.env.NODE_ENV !== "production" ? '__input_keydown_escape__' : 2;
2593
- var InputKeyDownHome = process.env.NODE_ENV !== "production" ? '__input_keydown_home__' : 3;
2594
- var InputKeyDownEnd = process.env.NODE_ENV !== "production" ? '__input_keydown_end__' : 4;
2595
- var InputKeyDownPageUp = process.env.NODE_ENV !== "production" ? '__input_keydown_page_up__' : 5;
2596
- var InputKeyDownPageDown = process.env.NODE_ENV !== "production" ? '__input_keydown_page_down__' : 6;
2597
- var InputKeyDownEnter = process.env.NODE_ENV !== "production" ? '__input_keydown_enter__' : 7;
2598
- var InputChange = process.env.NODE_ENV !== "production" ? '__input_change__' : 8;
2599
- var InputBlur = process.env.NODE_ENV !== "production" ? '__input_blur__' : 9;
2600
- var InputFocus = process.env.NODE_ENV !== "production" ? '__input_focus__' : 10;
2601
- var MenuMouseLeave = process.env.NODE_ENV !== "production" ? '__menu_mouse_leave__' : 11;
2602
- var ItemMouseMove = process.env.NODE_ENV !== "production" ? '__item_mouse_move__' : 12;
2603
- var ItemClick = process.env.NODE_ENV !== "production" ? '__item_click__' : 13;
2604
- var ToggleButtonClick = process.env.NODE_ENV !== "production" ? '__togglebutton_click__' : 14;
2605
- var FunctionToggleMenu = process.env.NODE_ENV !== "production" ? '__function_toggle_menu__' : 15;
2606
- var FunctionOpenMenu = process.env.NODE_ENV !== "production" ? '__function_open_menu__' : 16;
2607
- var FunctionCloseMenu = process.env.NODE_ENV !== "production" ? '__function_close_menu__' : 17;
2608
- var FunctionSetHighlightedIndex = process.env.NODE_ENV !== "production" ? '__function_set_highlighted_index__' : 18;
2609
- var FunctionSelectItem = process.env.NODE_ENV !== "production" ? '__function_select_item__' : 19;
2610
- var FunctionSetInputValue = process.env.NODE_ENV !== "production" ? '__function_set_input_value__' : 20;
2611
- var FunctionReset$1 = process.env.NODE_ENV !== "production" ? '__function_reset__' : 21;
2612
- var ControlledPropUpdatedSelectedItem = process.env.NODE_ENV !== "production" ? '__controlled_prop_updated_selected_item__' : 22;
2650
+ const InputKeyDownArrowDown = process.env.NODE_ENV !== "production" ? '__input_keydown_arrow_down__' : 0;
2651
+ const InputKeyDownArrowUp = process.env.NODE_ENV !== "production" ? '__input_keydown_arrow_up__' : 1;
2652
+ const InputKeyDownEscape = process.env.NODE_ENV !== "production" ? '__input_keydown_escape__' : 2;
2653
+ const InputKeyDownHome = process.env.NODE_ENV !== "production" ? '__input_keydown_home__' : 3;
2654
+ const InputKeyDownEnd = process.env.NODE_ENV !== "production" ? '__input_keydown_end__' : 4;
2655
+ const InputKeyDownPageUp = process.env.NODE_ENV !== "production" ? '__input_keydown_page_up__' : 5;
2656
+ const InputKeyDownPageDown = process.env.NODE_ENV !== "production" ? '__input_keydown_page_down__' : 6;
2657
+ const InputKeyDownEnter = process.env.NODE_ENV !== "production" ? '__input_keydown_enter__' : 7;
2658
+ const InputChange = process.env.NODE_ENV !== "production" ? '__input_change__' : 8;
2659
+ const InputBlur = process.env.NODE_ENV !== "production" ? '__input_blur__' : 9;
2660
+ const InputFocus = process.env.NODE_ENV !== "production" ? '__input_focus__' : 10;
2661
+ const MenuMouseLeave = process.env.NODE_ENV !== "production" ? '__menu_mouse_leave__' : 11;
2662
+ const ItemMouseMove = process.env.NODE_ENV !== "production" ? '__item_mouse_move__' : 12;
2663
+ const ItemClick = process.env.NODE_ENV !== "production" ? '__item_click__' : 13;
2664
+ const ToggleButtonClick = process.env.NODE_ENV !== "production" ? '__togglebutton_click__' : 14;
2665
+ const FunctionToggleMenu = process.env.NODE_ENV !== "production" ? '__function_toggle_menu__' : 15;
2666
+ const FunctionOpenMenu = process.env.NODE_ENV !== "production" ? '__function_open_menu__' : 16;
2667
+ const FunctionCloseMenu = process.env.NODE_ENV !== "production" ? '__function_close_menu__' : 17;
2668
+ const FunctionSetHighlightedIndex = process.env.NODE_ENV !== "production" ? '__function_set_highlighted_index__' : 18;
2669
+ const FunctionSelectItem = process.env.NODE_ENV !== "production" ? '__function_select_item__' : 19;
2670
+ const FunctionSetInputValue = process.env.NODE_ENV !== "production" ? '__function_set_input_value__' : 20;
2671
+ const FunctionReset$1 = process.env.NODE_ENV !== "production" ? '__function_reset__' : 21;
2672
+ const ControlledPropUpdatedSelectedItem = process.env.NODE_ENV !== "production" ? '__controlled_prop_updated_selected_item__' : 22;
2613
2673
 
2614
2674
  var stateChangeTypes$1 = /*#__PURE__*/Object.freeze({
2615
2675
  __proto__: null,
@@ -2639,17 +2699,22 @@ var stateChangeTypes$1 = /*#__PURE__*/Object.freeze({
2639
2699
  });
2640
2700
 
2641
2701
  function getInitialState$1(props) {
2642
- var initialState = getInitialState$2(props);
2643
- var selectedItem = initialState.selectedItem;
2644
- var inputValue = initialState.inputValue;
2702
+ const initialState = getInitialState$2(props);
2703
+ const {
2704
+ selectedItem
2705
+ } = initialState;
2706
+ let {
2707
+ inputValue
2708
+ } = initialState;
2645
2709
  if (inputValue === '' && selectedItem && props.defaultInputValue === undefined && props.initialInputValue === undefined && props.inputValue === undefined) {
2646
2710
  inputValue = props.itemToString(selectedItem);
2647
2711
  }
2648
- return _extends__default["default"]({}, initialState, {
2649
- inputValue: inputValue
2650
- });
2712
+ return {
2713
+ ...initialState,
2714
+ inputValue
2715
+ };
2651
2716
  }
2652
- var propTypes$1 = {
2717
+ const propTypes$1 = {
2653
2718
  items: PropTypes__default["default"].array.isRequired,
2654
2719
  itemToString: PropTypes__default["default"].func,
2655
2720
  getA11yStatusMessage: PropTypes__default["default"].func,
@@ -2702,13 +2767,11 @@ var propTypes$1 = {
2702
2767
  * @returns {Array} An array with the state and an action dispatcher.
2703
2768
  */
2704
2769
  function useControlledReducer(reducer, initialState, props) {
2705
- var previousSelectedItemRef = preact.useRef();
2706
- var _useEnhancedReducer = useEnhancedReducer(reducer, initialState, props),
2707
- state = _useEnhancedReducer[0],
2708
- dispatch = _useEnhancedReducer[1];
2770
+ const previousSelectedItemRef = preact.useRef();
2771
+ const [state, dispatch] = useEnhancedReducer(reducer, initialState, props);
2709
2772
 
2710
2773
  // ToDo: if needed, make same approach as selectedItemChanged from Downshift.
2711
- preact.useEffect(function () {
2774
+ preact.useEffect(() => {
2712
2775
  if (isControlledProp(props, 'selectedItem')) {
2713
2776
  if (previousSelectedItemRef.current !== props.selectedItem) {
2714
2777
  dispatch({
@@ -2723,23 +2786,26 @@ function useControlledReducer(reducer, initialState, props) {
2723
2786
  }
2724
2787
 
2725
2788
  // eslint-disable-next-line import/no-mutable-exports
2726
- var validatePropTypes$1 = noop;
2789
+ let validatePropTypes$1 = noop;
2727
2790
  /* istanbul ignore next */
2728
2791
  if (process.env.NODE_ENV !== 'production') {
2729
- validatePropTypes$1 = function validatePropTypes(options, caller) {
2792
+ validatePropTypes$1 = (options, caller) => {
2730
2793
  PropTypes__default["default"].checkPropTypes(propTypes$1, options, 'prop', caller.name);
2731
2794
  };
2732
2795
  }
2733
- var defaultProps$1 = _extends__default["default"]({}, defaultProps$3, {
2796
+ const defaultProps$1 = {
2797
+ ...defaultProps$3,
2734
2798
  getA11yStatusMessage: getA11yStatusMessage$1
2735
- });
2799
+ };
2736
2800
 
2737
2801
  /* eslint-disable complexity */
2738
2802
  function downshiftUseComboboxReducer(state, action) {
2739
- var type = action.type,
2740
- props = action.props,
2741
- altKey = action.altKey;
2742
- var changes;
2803
+ const {
2804
+ type,
2805
+ props,
2806
+ altKey
2807
+ } = action;
2808
+ let changes;
2743
2809
  switch (type) {
2744
2810
  case ItemClick:
2745
2811
  changes = {
@@ -2764,13 +2830,14 @@ function downshiftUseComboboxReducer(state, action) {
2764
2830
  case InputKeyDownArrowUp:
2765
2831
  if (state.isOpen) {
2766
2832
  if (altKey) {
2767
- changes = _extends__default["default"]({
2833
+ changes = {
2768
2834
  isOpen: getDefaultValue$1(props, 'isOpen'),
2769
- highlightedIndex: getDefaultValue$1(props, 'highlightedIndex')
2770
- }, state.highlightedIndex >= 0 && {
2771
- selectedItem: props.items[state.highlightedIndex],
2772
- inputValue: props.itemToString(props.items[state.highlightedIndex])
2773
- });
2835
+ highlightedIndex: getDefaultValue$1(props, 'highlightedIndex'),
2836
+ ...(state.highlightedIndex >= 0 && {
2837
+ selectedItem: props.items[state.highlightedIndex],
2838
+ inputValue: props.itemToString(props.items[state.highlightedIndex])
2839
+ })
2840
+ };
2774
2841
  } else {
2775
2842
  changes = {
2776
2843
  highlightedIndex: getNextWrappingIndex(-1, state.highlightedIndex, props.items.length, action.getItemNodeFromIndex, true)
@@ -2784,22 +2851,24 @@ function downshiftUseComboboxReducer(state, action) {
2784
2851
  }
2785
2852
  break;
2786
2853
  case InputKeyDownEnter:
2787
- changes = _extends__default["default"]({
2854
+ changes = {
2788
2855
  isOpen: getDefaultValue$1(props, 'isOpen'),
2789
- highlightedIndex: getDefaultValue$1(props, 'highlightedIndex')
2790
- }, state.highlightedIndex >= 0 && {
2791
- selectedItem: props.items[state.highlightedIndex],
2792
- inputValue: props.itemToString(props.items[state.highlightedIndex])
2793
- });
2856
+ highlightedIndex: getDefaultValue$1(props, 'highlightedIndex'),
2857
+ ...(state.highlightedIndex >= 0 && {
2858
+ selectedItem: props.items[state.highlightedIndex],
2859
+ inputValue: props.itemToString(props.items[state.highlightedIndex])
2860
+ })
2861
+ };
2794
2862
  break;
2795
2863
  case InputKeyDownEscape:
2796
- changes = _extends__default["default"]({
2864
+ changes = {
2797
2865
  isOpen: false,
2798
- highlightedIndex: -1
2799
- }, !state.isOpen && {
2800
- selectedItem: null,
2801
- inputValue: ''
2802
- });
2866
+ highlightedIndex: -1,
2867
+ ...(!state.isOpen && {
2868
+ selectedItem: null,
2869
+ inputValue: ''
2870
+ })
2871
+ };
2803
2872
  break;
2804
2873
  case InputKeyDownPageUp:
2805
2874
  changes = {
@@ -2822,13 +2891,14 @@ function downshiftUseComboboxReducer(state, action) {
2822
2891
  };
2823
2892
  break;
2824
2893
  case InputBlur:
2825
- changes = _extends__default["default"]({
2894
+ changes = {
2826
2895
  isOpen: false,
2827
- highlightedIndex: -1
2828
- }, state.highlightedIndex >= 0 && action.selectItem && {
2829
- selectedItem: props.items[state.highlightedIndex],
2830
- inputValue: props.itemToString(props.items[state.highlightedIndex])
2831
- });
2896
+ highlightedIndex: -1,
2897
+ ...(state.highlightedIndex >= 0 && action.selectItem && {
2898
+ selectedItem: props.items[state.highlightedIndex],
2899
+ inputValue: props.itemToString(props.items[state.highlightedIndex])
2900
+ })
2901
+ };
2832
2902
  break;
2833
2903
  case InputChange:
2834
2904
  changes = {
@@ -2857,14 +2927,14 @@ function downshiftUseComboboxReducer(state, action) {
2857
2927
  default:
2858
2928
  return downshiftCommonReducer(state, action, stateChangeTypes$1);
2859
2929
  }
2860
- return _extends__default["default"]({}, state, changes);
2930
+ return {
2931
+ ...state,
2932
+ ...changes
2933
+ };
2861
2934
  }
2862
2935
  /* eslint-enable complexity */
2863
2936
 
2864
- var _excluded$1 = ["onMouseLeave", "refKey", "ref"],
2865
- _excluded2$1 = ["item", "index", "refKey", "ref", "onMouseMove", "onMouseDown", "onClick", "onPress", "disabled"],
2866
- _excluded3 = ["onClick", "onPress", "refKey", "ref"],
2867
- _excluded4 = ["onKeyDown", "onChange", "onInput", "onFocus", "onBlur", "onChangeText", "refKey", "ref"];
2937
+ /* eslint-disable max-statements */
2868
2938
  useCombobox.stateChangeTypes = stateChangeTypes$1;
2869
2939
  function useCombobox(userProps) {
2870
2940
  if (userProps === void 0) {
@@ -2872,327 +2942,349 @@ function useCombobox(userProps) {
2872
2942
  }
2873
2943
  validatePropTypes$1(userProps, useCombobox);
2874
2944
  // Props defaults and destructuring.
2875
- var props = _extends__default["default"]({}, defaultProps$1, userProps);
2876
- var initialIsOpen = props.initialIsOpen,
2877
- defaultIsOpen = props.defaultIsOpen,
2878
- items = props.items,
2879
- scrollIntoView = props.scrollIntoView,
2880
- environment = props.environment,
2881
- getA11yStatusMessage = props.getA11yStatusMessage,
2882
- getA11ySelectionMessage = props.getA11ySelectionMessage,
2883
- itemToString = props.itemToString;
2945
+ const props = {
2946
+ ...defaultProps$1,
2947
+ ...userProps
2948
+ };
2949
+ const {
2950
+ initialIsOpen,
2951
+ defaultIsOpen,
2952
+ items,
2953
+ scrollIntoView,
2954
+ environment,
2955
+ getA11yStatusMessage,
2956
+ getA11ySelectionMessage,
2957
+ itemToString
2958
+ } = props;
2884
2959
  // Initial state depending on controlled props.
2885
- var initialState = getInitialState$1(props);
2886
- var _useControlledReducer = useControlledReducer(downshiftUseComboboxReducer, initialState, props),
2887
- state = _useControlledReducer[0],
2888
- dispatch = _useControlledReducer[1];
2889
- var isOpen = state.isOpen,
2890
- highlightedIndex = state.highlightedIndex,
2891
- selectedItem = state.selectedItem,
2892
- inputValue = state.inputValue;
2960
+ const initialState = getInitialState$1(props);
2961
+ const [state, dispatch] = useControlledReducer(downshiftUseComboboxReducer, initialState, props);
2962
+ const {
2963
+ isOpen,
2964
+ highlightedIndex,
2965
+ selectedItem,
2966
+ inputValue
2967
+ } = state;
2893
2968
 
2894
2969
  // Element refs.
2895
- var menuRef = preact.useRef(null);
2896
- var itemRefs = preact.useRef({});
2897
- var inputRef = preact.useRef(null);
2898
- var toggleButtonRef = preact.useRef(null);
2899
- var isInitialMountRef = preact.useRef(true);
2970
+ const menuRef = preact.useRef(null);
2971
+ const itemRefs = preact.useRef({});
2972
+ const inputRef = preact.useRef(null);
2973
+ const toggleButtonRef = preact.useRef(null);
2974
+ const isInitialMountRef = preact.useRef(true);
2900
2975
  // prevent id re-generation between renders.
2901
- var elementIds = useElementIds(props);
2976
+ const elementIds = useElementIds(props);
2902
2977
  // used to keep track of how many items we had on previous cycle.
2903
- var previousResultCountRef = preact.useRef();
2978
+ const previousResultCountRef = preact.useRef();
2904
2979
  // utility callback to get item element.
2905
- var latest = useLatestRef({
2906
- state: state,
2907
- props: props
2980
+ const latest = useLatestRef({
2981
+ state,
2982
+ props
2908
2983
  });
2909
- var getItemNodeFromIndex = preact.useCallback(function (index) {
2910
- return itemRefs.current[elementIds.getItemId(index)];
2911
- }, [elementIds]);
2984
+ const getItemNodeFromIndex = preact.useCallback(index => itemRefs.current[elementIds.getItemId(index)], [elementIds]);
2912
2985
 
2913
2986
  // Effects.
2914
2987
  // Sets a11y status message on changes in state.
2915
- useA11yMessageSetter(getA11yStatusMessage, [isOpen, highlightedIndex, inputValue, items], _extends__default["default"]({
2988
+ useA11yMessageSetter(getA11yStatusMessage, [isOpen, highlightedIndex, inputValue, items], {
2916
2989
  isInitialMount: isInitialMountRef.current,
2917
2990
  previousResultCount: previousResultCountRef.current,
2918
- items: items,
2919
- environment: environment,
2920
- itemToString: itemToString
2921
- }, state));
2991
+ items,
2992
+ environment,
2993
+ itemToString,
2994
+ ...state
2995
+ });
2922
2996
  // Sets a11y status message on changes in selectedItem.
2923
- useA11yMessageSetter(getA11ySelectionMessage, [selectedItem], _extends__default["default"]({
2997
+ useA11yMessageSetter(getA11ySelectionMessage, [selectedItem], {
2924
2998
  isInitialMount: isInitialMountRef.current,
2925
2999
  previousResultCount: previousResultCountRef.current,
2926
- items: items,
2927
- environment: environment,
2928
- itemToString: itemToString
2929
- }, state));
3000
+ items,
3001
+ environment,
3002
+ itemToString,
3003
+ ...state
3004
+ });
2930
3005
  // Scroll on highlighted item if change comes from keyboard.
2931
- var shouldScrollRef = useScrollIntoView({
3006
+ const shouldScrollRef = useScrollIntoView({
2932
3007
  menuElement: menuRef.current,
2933
- highlightedIndex: highlightedIndex,
2934
- isOpen: isOpen,
2935
- itemRefs: itemRefs,
2936
- scrollIntoView: scrollIntoView,
2937
- getItemNodeFromIndex: getItemNodeFromIndex
3008
+ highlightedIndex,
3009
+ isOpen,
3010
+ itemRefs,
3011
+ scrollIntoView,
3012
+ getItemNodeFromIndex
2938
3013
  });
2939
3014
  useControlPropsValidator({
2940
3015
  isInitialMount: isInitialMountRef.current,
2941
- props: props,
2942
- state: state
3016
+ props,
3017
+ state
2943
3018
  });
2944
3019
  // Focus the input on first render if required.
2945
- preact.useEffect(function () {
2946
- var focusOnOpen = initialIsOpen || defaultIsOpen || isOpen;
3020
+ preact.useEffect(() => {
3021
+ const focusOnOpen = initialIsOpen || defaultIsOpen || isOpen;
2947
3022
  if (focusOnOpen && inputRef.current) {
2948
3023
  inputRef.current.focus();
2949
3024
  }
2950
3025
  // eslint-disable-next-line react-hooks/exhaustive-deps
2951
3026
  }, []);
2952
- preact.useEffect(function () {
3027
+ preact.useEffect(() => {
2953
3028
  if (isInitialMountRef.current) {
2954
3029
  return;
2955
3030
  }
2956
3031
  previousResultCountRef.current = items.length;
2957
3032
  });
2958
3033
  // Add mouse/touch events to document.
2959
- var mouseAndTouchTrackersRef = useMouseAndTouchTracker(isOpen, [inputRef, menuRef, toggleButtonRef], environment, function () {
3034
+ const mouseAndTouchTrackersRef = useMouseAndTouchTracker(isOpen, [inputRef, menuRef, toggleButtonRef], environment, () => {
2960
3035
  dispatch({
2961
3036
  type: InputBlur,
2962
3037
  selectItem: false
2963
3038
  });
2964
3039
  });
2965
- var setGetterPropCallInfo = useGetterPropsCalledChecker('getInputProps', 'getMenuProps');
3040
+ const setGetterPropCallInfo = useGetterPropsCalledChecker('getInputProps', 'getMenuProps');
2966
3041
  // Make initial ref false.
2967
- preact.useEffect(function () {
3042
+ preact.useEffect(() => {
2968
3043
  isInitialMountRef.current = false;
2969
- return function () {
3044
+ return () => {
2970
3045
  isInitialMountRef.current = true;
2971
3046
  };
2972
3047
  }, []);
2973
3048
  // Reset itemRefs on close.
2974
- preact.useEffect(function () {
3049
+ preact.useEffect(() => {
2975
3050
  if (!isOpen) {
2976
3051
  itemRefs.current = {};
2977
3052
  } else if (document.activeElement !== inputRef.current) {
2978
- var _inputRef$current;
2979
- inputRef == null ? void 0 : (_inputRef$current = inputRef.current) == null ? void 0 : _inputRef$current.focus();
3053
+ inputRef?.current?.focus();
2980
3054
  }
2981
3055
  }, [isOpen]);
2982
3056
 
2983
3057
  /* Event handler functions */
2984
- var inputKeyDownHandlers = preact.useMemo(function () {
2985
- return {
2986
- ArrowDown: function ArrowDown(event) {
2987
- event.preventDefault();
2988
- dispatch({
2989
- type: InputKeyDownArrowDown,
2990
- altKey: event.altKey,
2991
- getItemNodeFromIndex: getItemNodeFromIndex
2992
- });
2993
- },
2994
- ArrowUp: function ArrowUp(event) {
2995
- event.preventDefault();
2996
- dispatch({
2997
- type: InputKeyDownArrowUp,
2998
- altKey: event.altKey,
2999
- getItemNodeFromIndex: getItemNodeFromIndex
3000
- });
3001
- },
3002
- Home: function Home(event) {
3003
- if (!latest.current.state.isOpen) {
3004
- return;
3005
- }
3058
+ const inputKeyDownHandlers = preact.useMemo(() => ({
3059
+ ArrowDown(event) {
3060
+ event.preventDefault();
3061
+ dispatch({
3062
+ type: InputKeyDownArrowDown,
3063
+ altKey: event.altKey,
3064
+ getItemNodeFromIndex
3065
+ });
3066
+ },
3067
+ ArrowUp(event) {
3068
+ event.preventDefault();
3069
+ dispatch({
3070
+ type: InputKeyDownArrowUp,
3071
+ altKey: event.altKey,
3072
+ getItemNodeFromIndex
3073
+ });
3074
+ },
3075
+ Home(event) {
3076
+ if (!latest.current.state.isOpen) {
3077
+ return;
3078
+ }
3079
+ event.preventDefault();
3080
+ dispatch({
3081
+ type: InputKeyDownHome,
3082
+ getItemNodeFromIndex
3083
+ });
3084
+ },
3085
+ End(event) {
3086
+ if (!latest.current.state.isOpen) {
3087
+ return;
3088
+ }
3089
+ event.preventDefault();
3090
+ dispatch({
3091
+ type: InputKeyDownEnd,
3092
+ getItemNodeFromIndex
3093
+ });
3094
+ },
3095
+ Escape(event) {
3096
+ const latestState = latest.current.state;
3097
+ if (latestState.isOpen || latestState.inputValue || latestState.selectedItem || latestState.highlightedIndex > -1) {
3006
3098
  event.preventDefault();
3007
3099
  dispatch({
3008
- type: InputKeyDownHome,
3009
- getItemNodeFromIndex: getItemNodeFromIndex
3100
+ type: InputKeyDownEscape
3010
3101
  });
3011
- },
3012
- End: function End(event) {
3013
- if (!latest.current.state.isOpen) {
3014
- return;
3015
- }
3102
+ }
3103
+ },
3104
+ Enter(event) {
3105
+ const latestState = latest.current.state;
3106
+ // if closed or no highlighted index, do nothing.
3107
+ if (!latestState.isOpen || event.which === 229 // if IME composing, wait for next Enter keydown event.
3108
+ ) {
3109
+ return;
3110
+ }
3111
+ event.preventDefault();
3112
+ dispatch({
3113
+ type: InputKeyDownEnter,
3114
+ getItemNodeFromIndex
3115
+ });
3116
+ },
3117
+ PageUp(event) {
3118
+ if (latest.current.state.isOpen) {
3016
3119
  event.preventDefault();
3017
3120
  dispatch({
3018
- type: InputKeyDownEnd,
3019
- getItemNodeFromIndex: getItemNodeFromIndex
3121
+ type: InputKeyDownPageUp,
3122
+ getItemNodeFromIndex
3020
3123
  });
3021
- },
3022
- Escape: function Escape(event) {
3023
- var latestState = latest.current.state;
3024
- if (latestState.isOpen || latestState.inputValue || latestState.selectedItem || latestState.highlightedIndex > -1) {
3025
- event.preventDefault();
3026
- dispatch({
3027
- type: InputKeyDownEscape
3028
- });
3029
- }
3030
- },
3031
- Enter: function Enter(event) {
3032
- var latestState = latest.current.state;
3033
- // if closed or no highlighted index, do nothing.
3034
- if (!latestState.isOpen || event.which === 229 // if IME composing, wait for next Enter keydown event.
3035
- ) {
3036
- return;
3037
- }
3124
+ }
3125
+ },
3126
+ PageDown(event) {
3127
+ if (latest.current.state.isOpen) {
3038
3128
  event.preventDefault();
3039
3129
  dispatch({
3040
- type: InputKeyDownEnter,
3041
- getItemNodeFromIndex: getItemNodeFromIndex
3130
+ type: InputKeyDownPageDown,
3131
+ getItemNodeFromIndex
3042
3132
  });
3043
- },
3044
- PageUp: function PageUp(event) {
3045
- if (latest.current.state.isOpen) {
3046
- event.preventDefault();
3047
- dispatch({
3048
- type: InputKeyDownPageUp,
3049
- getItemNodeFromIndex: getItemNodeFromIndex
3050
- });
3051
- }
3052
- },
3053
- PageDown: function PageDown(event) {
3054
- if (latest.current.state.isOpen) {
3055
- event.preventDefault();
3056
- dispatch({
3057
- type: InputKeyDownPageDown,
3058
- getItemNodeFromIndex: getItemNodeFromIndex
3059
- });
3060
- }
3061
3133
  }
3062
- };
3063
- }, [dispatch, latest, getItemNodeFromIndex]);
3134
+ }
3135
+ }), [dispatch, latest, getItemNodeFromIndex]);
3064
3136
 
3065
3137
  // Getter props.
3066
- var getLabelProps = preact.useCallback(function (labelProps) {
3067
- return _extends__default["default"]({
3068
- id: elementIds.labelId,
3069
- htmlFor: elementIds.inputId
3070
- }, labelProps);
3071
- }, [elementIds]);
3072
- var getMenuProps = preact.useCallback(function (_temp, _temp2) {
3073
- var _extends2;
3074
- var _ref = _temp === void 0 ? {} : _temp,
3075
- onMouseLeave = _ref.onMouseLeave,
3076
- _ref$refKey = _ref.refKey,
3077
- refKey = _ref$refKey === void 0 ? 'ref' : _ref$refKey,
3078
- ref = _ref.ref,
3079
- rest = _objectWithoutPropertiesLoose__default["default"](_ref, _excluded$1);
3080
- var _ref2 = _temp2 === void 0 ? {} : _temp2,
3081
- _ref2$suppressRefErro = _ref2.suppressRefError,
3082
- suppressRefError = _ref2$suppressRefErro === void 0 ? false : _ref2$suppressRefErro;
3138
+ const getLabelProps = preact.useCallback(labelProps => ({
3139
+ id: elementIds.labelId,
3140
+ htmlFor: elementIds.inputId,
3141
+ ...labelProps
3142
+ }), [elementIds]);
3143
+ const getMenuProps = preact.useCallback(function (_temp, _temp2) {
3144
+ let {
3145
+ onMouseLeave,
3146
+ refKey = 'ref',
3147
+ ref,
3148
+ ...rest
3149
+ } = _temp === void 0 ? {} : _temp;
3150
+ let {
3151
+ suppressRefError = false
3152
+ } = _temp2 === void 0 ? {} : _temp2;
3083
3153
  setGetterPropCallInfo('getMenuProps', suppressRefError, refKey, menuRef);
3084
- return _extends__default["default"]((_extends2 = {}, _extends2[refKey] = handleRefs(ref, function (menuNode) {
3085
- menuRef.current = menuNode;
3086
- }), _extends2.id = elementIds.menuId, _extends2.role = 'listbox', _extends2['aria-labelledby'] = elementIds.labelId, _extends2.onMouseLeave = callAllEventHandlers(onMouseLeave, function () {
3087
- dispatch({
3088
- type: MenuMouseLeave
3089
- });
3090
- }), _extends2), rest);
3154
+ return {
3155
+ [refKey]: handleRefs(ref, menuNode => {
3156
+ menuRef.current = menuNode;
3157
+ }),
3158
+ id: elementIds.menuId,
3159
+ role: 'listbox',
3160
+ 'aria-labelledby': elementIds.labelId,
3161
+ onMouseLeave: callAllEventHandlers(onMouseLeave, () => {
3162
+ dispatch({
3163
+ type: MenuMouseLeave
3164
+ });
3165
+ }),
3166
+ ...rest
3167
+ };
3091
3168
  }, [dispatch, setGetterPropCallInfo, elementIds]);
3092
- var getItemProps = preact.useCallback(function (_temp3) {
3093
- var _extends3, _ref4;
3094
- var _ref3 = _temp3 === void 0 ? {} : _temp3,
3095
- item = _ref3.item,
3096
- index = _ref3.index,
3097
- _ref3$refKey = _ref3.refKey,
3098
- refKey = _ref3$refKey === void 0 ? 'ref' : _ref3$refKey,
3099
- ref = _ref3.ref,
3100
- onMouseMove = _ref3.onMouseMove,
3101
- onMouseDown = _ref3.onMouseDown,
3102
- onClick = _ref3.onClick;
3103
- _ref3.onPress;
3104
- var disabled = _ref3.disabled,
3105
- rest = _objectWithoutPropertiesLoose__default["default"](_ref3, _excluded2$1);
3106
- var _latest$current = latest.current,
3107
- latestProps = _latest$current.props,
3108
- latestState = _latest$current.state;
3109
- var itemIndex = getItemIndex(index, item, latestProps.items);
3169
+ const getItemProps = preact.useCallback(function (_temp3) {
3170
+ let {
3171
+ item,
3172
+ index,
3173
+ refKey = 'ref',
3174
+ ref,
3175
+ onMouseMove,
3176
+ onMouseDown,
3177
+ onClick,
3178
+ onPress,
3179
+ disabled,
3180
+ ...rest
3181
+ } = _temp3 === void 0 ? {} : _temp3;
3182
+ const {
3183
+ props: latestProps,
3184
+ state: latestState
3185
+ } = latest.current;
3186
+ const itemIndex = getItemIndex(index, item, latestProps.items);
3110
3187
  if (itemIndex < 0) {
3111
3188
  throw new Error('Pass either item or item index in getItemProps!');
3112
3189
  }
3113
- var onSelectKey = 'onClick';
3114
- var customClickHandler = onClick;
3115
- var itemHandleMouseMove = function itemHandleMouseMove() {
3190
+ const onSelectKey = 'onClick';
3191
+ const customClickHandler = onClick;
3192
+ const itemHandleMouseMove = () => {
3116
3193
  if (index === latestState.highlightedIndex) {
3117
3194
  return;
3118
3195
  }
3119
3196
  shouldScrollRef.current = false;
3120
3197
  dispatch({
3121
3198
  type: ItemMouseMove,
3122
- index: index,
3123
- disabled: disabled
3199
+ index,
3200
+ disabled
3124
3201
  });
3125
3202
  };
3126
- var itemHandleClick = function itemHandleClick() {
3203
+ const itemHandleClick = () => {
3127
3204
  dispatch({
3128
3205
  type: ItemClick,
3129
- index: index
3206
+ index
3130
3207
  });
3131
3208
  };
3132
- var itemHandleMouseDown = function itemHandleMouseDown(e) {
3133
- return e.preventDefault();
3134
- };
3135
- return _extends__default["default"]((_extends3 = {}, _extends3[refKey] = handleRefs(ref, function (itemNode) {
3136
- if (itemNode) {
3137
- itemRefs.current[elementIds.getItemId(itemIndex)] = itemNode;
3138
- }
3139
- }), _extends3.disabled = disabled, _extends3.role = 'option', _extends3['aria-selected'] = "" + (itemIndex === latestState.highlightedIndex), _extends3.id = elementIds.getItemId(itemIndex), _extends3), !disabled && (_ref4 = {}, _ref4[onSelectKey] = callAllEventHandlers(customClickHandler, itemHandleClick), _ref4), {
3209
+ const itemHandleMouseDown = e => e.preventDefault();
3210
+ return {
3211
+ [refKey]: handleRefs(ref, itemNode => {
3212
+ if (itemNode) {
3213
+ itemRefs.current[elementIds.getItemId(itemIndex)] = itemNode;
3214
+ }
3215
+ }),
3216
+ disabled,
3217
+ role: 'option',
3218
+ 'aria-selected': `${itemIndex === latestState.highlightedIndex}`,
3219
+ id: elementIds.getItemId(itemIndex),
3220
+ ...(!disabled && {
3221
+ [onSelectKey]: callAllEventHandlers(customClickHandler, itemHandleClick)
3222
+ }),
3140
3223
  onMouseMove: callAllEventHandlers(onMouseMove, itemHandleMouseMove),
3141
- onMouseDown: callAllEventHandlers(onMouseDown, itemHandleMouseDown)
3142
- }, rest);
3224
+ onMouseDown: callAllEventHandlers(onMouseDown, itemHandleMouseDown),
3225
+ ...rest
3226
+ };
3143
3227
  }, [dispatch, latest, shouldScrollRef, elementIds]);
3144
- var getToggleButtonProps = preact.useCallback(function (_temp4) {
3145
- var _extends4;
3146
- var _ref5 = _temp4 === void 0 ? {} : _temp4,
3147
- onClick = _ref5.onClick;
3148
- _ref5.onPress;
3149
- var _ref5$refKey = _ref5.refKey,
3150
- refKey = _ref5$refKey === void 0 ? 'ref' : _ref5$refKey,
3151
- ref = _ref5.ref,
3152
- rest = _objectWithoutPropertiesLoose__default["default"](_ref5, _excluded3);
3153
- var latestState = latest.current.state;
3154
- var toggleButtonHandleClick = function toggleButtonHandleClick() {
3228
+ const getToggleButtonProps = preact.useCallback(function (_temp4) {
3229
+ let {
3230
+ onClick,
3231
+ onPress,
3232
+ refKey = 'ref',
3233
+ ref,
3234
+ ...rest
3235
+ } = _temp4 === void 0 ? {} : _temp4;
3236
+ const latestState = latest.current.state;
3237
+ const toggleButtonHandleClick = () => {
3155
3238
  dispatch({
3156
3239
  type: ToggleButtonClick
3157
3240
  });
3158
3241
  };
3159
- return _extends__default["default"]((_extends4 = {}, _extends4[refKey] = handleRefs(ref, function (toggleButtonNode) {
3160
- toggleButtonRef.current = toggleButtonNode;
3161
- }), _extends4['aria-controls'] = elementIds.menuId, _extends4['aria-expanded'] = latestState.isOpen, _extends4.id = elementIds.toggleButtonId, _extends4.tabIndex = -1, _extends4), !rest.disabled && _extends__default["default"]({}, {
3162
- onClick: callAllEventHandlers(onClick, toggleButtonHandleClick)
3163
- }), rest);
3242
+ return {
3243
+ [refKey]: handleRefs(ref, toggleButtonNode => {
3244
+ toggleButtonRef.current = toggleButtonNode;
3245
+ }),
3246
+ 'aria-controls': elementIds.menuId,
3247
+ 'aria-expanded': latestState.isOpen,
3248
+ id: elementIds.toggleButtonId,
3249
+ tabIndex: -1,
3250
+ ...(!rest.disabled && {
3251
+ ...({
3252
+ onClick: callAllEventHandlers(onClick, toggleButtonHandleClick)
3253
+ })
3254
+ }),
3255
+ ...rest
3256
+ };
3164
3257
  }, [dispatch, latest, elementIds]);
3165
- var getInputProps = preact.useCallback(function (_temp5, _temp6) {
3166
- var _extends5;
3167
- var _ref6 = _temp5 === void 0 ? {} : _temp5,
3168
- onKeyDown = _ref6.onKeyDown,
3169
- onChange = _ref6.onChange,
3170
- onInput = _ref6.onInput,
3171
- onFocus = _ref6.onFocus,
3172
- onBlur = _ref6.onBlur;
3173
- _ref6.onChangeText;
3174
- var _ref6$refKey = _ref6.refKey,
3175
- refKey = _ref6$refKey === void 0 ? 'ref' : _ref6$refKey,
3176
- ref = _ref6.ref,
3177
- rest = _objectWithoutPropertiesLoose__default["default"](_ref6, _excluded4);
3178
- var _ref7 = _temp6 === void 0 ? {} : _temp6,
3179
- _ref7$suppressRefErro = _ref7.suppressRefError,
3180
- suppressRefError = _ref7$suppressRefErro === void 0 ? false : _ref7$suppressRefErro;
3258
+ const getInputProps = preact.useCallback(function (_temp5, _temp6) {
3259
+ let {
3260
+ onKeyDown,
3261
+ onChange,
3262
+ onInput,
3263
+ onFocus,
3264
+ onBlur,
3265
+ onChangeText,
3266
+ refKey = 'ref',
3267
+ ref,
3268
+ ...rest
3269
+ } = _temp5 === void 0 ? {} : _temp5;
3270
+ let {
3271
+ suppressRefError = false
3272
+ } = _temp6 === void 0 ? {} : _temp6;
3181
3273
  setGetterPropCallInfo('getInputProps', suppressRefError, refKey, inputRef);
3182
- var latestState = latest.current.state;
3183
- var inputHandleKeyDown = function inputHandleKeyDown(event) {
3184
- var key = normalizeArrowKey(event);
3274
+ const latestState = latest.current.state;
3275
+ const inputHandleKeyDown = event => {
3276
+ const key = normalizeArrowKey(event);
3185
3277
  if (key && inputKeyDownHandlers[key]) {
3186
3278
  inputKeyDownHandlers[key](event);
3187
3279
  }
3188
3280
  };
3189
- var inputHandleChange = function inputHandleChange(event) {
3281
+ const inputHandleChange = event => {
3190
3282
  dispatch({
3191
3283
  type: InputChange,
3192
3284
  inputValue: event.target.value
3193
3285
  });
3194
3286
  };
3195
- var inputHandleBlur = function inputHandleBlur() {
3287
+ const inputHandleBlur = () => {
3196
3288
  /* istanbul ignore else */
3197
3289
  if (latestState.isOpen && !mouseAndTouchTrackersRef.current.isMouseDown) {
3198
3290
  dispatch({
@@ -3201,7 +3293,7 @@ function useCombobox(userProps) {
3201
3293
  });
3202
3294
  }
3203
3295
  };
3204
- var inputHandleFocus = function inputHandleFocus() {
3296
+ const inputHandleFocus = () => {
3205
3297
  if (!latestState.isOpen) {
3206
3298
  dispatch({
3207
3299
  type: InputFocus
@@ -3210,80 +3302,99 @@ function useCombobox(userProps) {
3210
3302
  };
3211
3303
 
3212
3304
  /* istanbul ignore next (preact) */
3213
- var onChangeKey = 'onInput' ;
3214
- var eventHandlers = {};
3305
+ const onChangeKey = 'onInput' ;
3306
+ let eventHandlers = {};
3215
3307
  if (!rest.disabled) {
3216
- var _eventHandlers;
3217
- eventHandlers = (_eventHandlers = {}, _eventHandlers[onChangeKey] = callAllEventHandlers(onChange, onInput, inputHandleChange), _eventHandlers.onKeyDown = callAllEventHandlers(onKeyDown, inputHandleKeyDown), _eventHandlers.onBlur = callAllEventHandlers(onBlur, inputHandleBlur), _eventHandlers.onFocus = callAllEventHandlers(onFocus, inputHandleFocus), _eventHandlers);
3308
+ eventHandlers = {
3309
+ [onChangeKey]: callAllEventHandlers(onChange, onInput, inputHandleChange),
3310
+ onKeyDown: callAllEventHandlers(onKeyDown, inputHandleKeyDown),
3311
+ onBlur: callAllEventHandlers(onBlur, inputHandleBlur),
3312
+ onFocus: callAllEventHandlers(onFocus, inputHandleFocus)
3313
+ };
3218
3314
  }
3219
- return _extends__default["default"]((_extends5 = {}, _extends5[refKey] = handleRefs(ref, function (inputNode) {
3220
- inputRef.current = inputNode;
3221
- }), _extends5['aria-activedescendant'] = latestState.isOpen && latestState.highlightedIndex > -1 ? elementIds.getItemId(latestState.highlightedIndex) : '', _extends5['aria-autocomplete'] = 'list', _extends5['aria-controls'] = elementIds.menuId, _extends5['aria-expanded'] = latestState.isOpen, _extends5['aria-labelledby'] = elementIds.labelId, _extends5.autoComplete = 'off', _extends5.id = elementIds.inputId, _extends5.role = 'combobox', _extends5.value = latestState.inputValue, _extends5), eventHandlers, rest);
3315
+ return {
3316
+ [refKey]: handleRefs(ref, inputNode => {
3317
+ inputRef.current = inputNode;
3318
+ }),
3319
+ 'aria-activedescendant': latestState.isOpen && latestState.highlightedIndex > -1 ? elementIds.getItemId(latestState.highlightedIndex) : '',
3320
+ 'aria-autocomplete': 'list',
3321
+ 'aria-controls': elementIds.menuId,
3322
+ 'aria-expanded': latestState.isOpen,
3323
+ 'aria-labelledby': elementIds.labelId,
3324
+ // https://developer.mozilla.org/en-US/docs/Web/Security/Securing_your_site/Turning_off_form_autocompletion
3325
+ // revert back since autocomplete="nope" is ignored on latest Chrome and Opera
3326
+ autoComplete: 'off',
3327
+ id: elementIds.inputId,
3328
+ role: 'combobox',
3329
+ value: latestState.inputValue,
3330
+ ...eventHandlers,
3331
+ ...rest
3332
+ };
3222
3333
  }, [dispatch, inputKeyDownHandlers, latest, mouseAndTouchTrackersRef, setGetterPropCallInfo, elementIds]);
3223
3334
 
3224
3335
  // returns
3225
- var toggleMenu = preact.useCallback(function () {
3336
+ const toggleMenu = preact.useCallback(() => {
3226
3337
  dispatch({
3227
3338
  type: FunctionToggleMenu
3228
3339
  });
3229
3340
  }, [dispatch]);
3230
- var closeMenu = preact.useCallback(function () {
3341
+ const closeMenu = preact.useCallback(() => {
3231
3342
  dispatch({
3232
3343
  type: FunctionCloseMenu
3233
3344
  });
3234
3345
  }, [dispatch]);
3235
- var openMenu = preact.useCallback(function () {
3346
+ const openMenu = preact.useCallback(() => {
3236
3347
  dispatch({
3237
3348
  type: FunctionOpenMenu
3238
3349
  });
3239
3350
  }, [dispatch]);
3240
- var setHighlightedIndex = preact.useCallback(function (newHighlightedIndex) {
3351
+ const setHighlightedIndex = preact.useCallback(newHighlightedIndex => {
3241
3352
  dispatch({
3242
3353
  type: FunctionSetHighlightedIndex,
3243
3354
  highlightedIndex: newHighlightedIndex
3244
3355
  });
3245
3356
  }, [dispatch]);
3246
- var selectItem = preact.useCallback(function (newSelectedItem) {
3357
+ const selectItem = preact.useCallback(newSelectedItem => {
3247
3358
  dispatch({
3248
3359
  type: FunctionSelectItem,
3249
3360
  selectedItem: newSelectedItem
3250
3361
  });
3251
3362
  }, [dispatch]);
3252
- var setInputValue = preact.useCallback(function (newInputValue) {
3363
+ const setInputValue = preact.useCallback(newInputValue => {
3253
3364
  dispatch({
3254
3365
  type: FunctionSetInputValue,
3255
3366
  inputValue: newInputValue
3256
3367
  });
3257
3368
  }, [dispatch]);
3258
- var reset = preact.useCallback(function () {
3369
+ const reset = preact.useCallback(() => {
3259
3370
  dispatch({
3260
3371
  type: FunctionReset$1
3261
3372
  });
3262
3373
  }, [dispatch]);
3263
3374
  return {
3264
3375
  // prop getters.
3265
- getItemProps: getItemProps,
3266
- getLabelProps: getLabelProps,
3267
- getMenuProps: getMenuProps,
3268
- getInputProps: getInputProps,
3269
- getToggleButtonProps: getToggleButtonProps,
3376
+ getItemProps,
3377
+ getLabelProps,
3378
+ getMenuProps,
3379
+ getInputProps,
3380
+ getToggleButtonProps,
3270
3381
  // actions.
3271
- toggleMenu: toggleMenu,
3272
- openMenu: openMenu,
3273
- closeMenu: closeMenu,
3274
- setHighlightedIndex: setHighlightedIndex,
3275
- setInputValue: setInputValue,
3276
- selectItem: selectItem,
3277
- reset: reset,
3382
+ toggleMenu,
3383
+ openMenu,
3384
+ closeMenu,
3385
+ setHighlightedIndex,
3386
+ setInputValue,
3387
+ selectItem,
3388
+ reset,
3278
3389
  // state.
3279
- highlightedIndex: highlightedIndex,
3280
- isOpen: isOpen,
3281
- selectedItem: selectedItem,
3282
- inputValue: inputValue
3390
+ highlightedIndex,
3391
+ isOpen,
3392
+ selectedItem,
3393
+ inputValue
3283
3394
  };
3284
3395
  }
3285
3396
 
3286
- var defaultStateValues = {
3397
+ const defaultStateValues = {
3287
3398
  activeIndex: -1,
3288
3399
  selectedItems: []
3289
3400
  };
@@ -3321,11 +3432,11 @@ function getDefaultValue(props, propKey) {
3321
3432
  * @returns {Object} The initial state.
3322
3433
  */
3323
3434
  function getInitialState(props) {
3324
- var activeIndex = getInitialValue(props, 'activeIndex');
3325
- var selectedItems = getInitialValue(props, 'selectedItems');
3435
+ const activeIndex = getInitialValue(props, 'activeIndex');
3436
+ const selectedItems = getInitialValue(props, 'selectedItems');
3326
3437
  return {
3327
- activeIndex: activeIndex,
3328
- selectedItems: selectedItems
3438
+ activeIndex,
3439
+ selectedItems
3329
3440
  };
3330
3441
  }
3331
3442
 
@@ -3342,7 +3453,7 @@ function isKeyDownOperationPermitted(event) {
3342
3453
  if (event.shiftKey || event.metaKey || event.ctrlKey || event.altKey) {
3343
3454
  return false;
3344
3455
  }
3345
- var element = event.target;
3456
+ const element = event.target;
3346
3457
  if (element instanceof HTMLInputElement &&
3347
3458
  // if element is a text input
3348
3459
  element.value !== '' && (
@@ -3361,11 +3472,13 @@ function isKeyDownOperationPermitted(event) {
3361
3472
  * @returns {string} The a11y message.
3362
3473
  */
3363
3474
  function getA11yRemovalMessage(selectionParameters) {
3364
- var removedSelectedItem = selectionParameters.removedSelectedItem,
3365
- itemToStringLocal = selectionParameters.itemToString;
3366
- return itemToStringLocal(removedSelectedItem) + " has been removed.";
3475
+ const {
3476
+ removedSelectedItem,
3477
+ itemToString: itemToStringLocal
3478
+ } = selectionParameters;
3479
+ return `${itemToStringLocal(removedSelectedItem)} has been removed.`;
3367
3480
  }
3368
- var propTypes = {
3481
+ const propTypes = {
3369
3482
  selectedItems: PropTypes__default["default"].array,
3370
3483
  initialSelectedItems: PropTypes__default["default"].array,
3371
3484
  defaultSelectedItems: PropTypes__default["default"].array,
@@ -3389,37 +3502,37 @@ var propTypes = {
3389
3502
  })
3390
3503
  })
3391
3504
  };
3392
- var defaultProps = {
3505
+ const defaultProps = {
3393
3506
  itemToString: defaultProps$3.itemToString,
3394
3507
  stateReducer: defaultProps$3.stateReducer,
3395
3508
  environment: defaultProps$3.environment,
3396
- getA11yRemovalMessage: getA11yRemovalMessage,
3509
+ getA11yRemovalMessage,
3397
3510
  keyNavigationNext: 'ArrowRight',
3398
3511
  keyNavigationPrevious: 'ArrowLeft'
3399
3512
  };
3400
3513
 
3401
3514
  // eslint-disable-next-line import/no-mutable-exports
3402
- var validatePropTypes = noop;
3515
+ let validatePropTypes = noop;
3403
3516
  /* istanbul ignore next */
3404
3517
  if (process.env.NODE_ENV !== 'production') {
3405
- validatePropTypes = function validatePropTypes(options, caller) {
3518
+ validatePropTypes = (options, caller) => {
3406
3519
  PropTypes__default["default"].checkPropTypes(propTypes, options, 'prop', caller.name);
3407
3520
  };
3408
3521
  }
3409
3522
 
3410
- var SelectedItemClick = process.env.NODE_ENV !== "production" ? '__selected_item_click__' : 0;
3411
- var SelectedItemKeyDownDelete = process.env.NODE_ENV !== "production" ? '__selected_item_keydown_delete__' : 1;
3412
- var SelectedItemKeyDownBackspace = process.env.NODE_ENV !== "production" ? '__selected_item_keydown_backspace__' : 2;
3413
- var SelectedItemKeyDownNavigationNext = process.env.NODE_ENV !== "production" ? '__selected_item_keydown_navigation_next__' : 3;
3414
- var SelectedItemKeyDownNavigationPrevious = process.env.NODE_ENV !== "production" ? '__selected_item_keydown_navigation_previous__' : 4;
3415
- var DropdownKeyDownNavigationPrevious = process.env.NODE_ENV !== "production" ? '__dropdown_keydown_navigation_previous__' : 5;
3416
- var DropdownKeyDownBackspace = process.env.NODE_ENV !== "production" ? '__dropdown_keydown_backspace__' : 6;
3417
- var DropdownClick = process.env.NODE_ENV !== "production" ? '__dropdown_click__' : 7;
3418
- var FunctionAddSelectedItem = process.env.NODE_ENV !== "production" ? '__function_add_selected_item__' : 8;
3419
- var FunctionRemoveSelectedItem = process.env.NODE_ENV !== "production" ? '__function_remove_selected_item__' : 9;
3420
- var FunctionSetSelectedItems = process.env.NODE_ENV !== "production" ? '__function_set_selected_items__' : 10;
3421
- var FunctionSetActiveIndex = process.env.NODE_ENV !== "production" ? '__function_set_active_index__' : 11;
3422
- var FunctionReset = process.env.NODE_ENV !== "production" ? '__function_reset__' : 12;
3523
+ const SelectedItemClick = process.env.NODE_ENV !== "production" ? '__selected_item_click__' : 0;
3524
+ const SelectedItemKeyDownDelete = process.env.NODE_ENV !== "production" ? '__selected_item_keydown_delete__' : 1;
3525
+ const SelectedItemKeyDownBackspace = process.env.NODE_ENV !== "production" ? '__selected_item_keydown_backspace__' : 2;
3526
+ const SelectedItemKeyDownNavigationNext = process.env.NODE_ENV !== "production" ? '__selected_item_keydown_navigation_next__' : 3;
3527
+ const SelectedItemKeyDownNavigationPrevious = process.env.NODE_ENV !== "production" ? '__selected_item_keydown_navigation_previous__' : 4;
3528
+ const DropdownKeyDownNavigationPrevious = process.env.NODE_ENV !== "production" ? '__dropdown_keydown_navigation_previous__' : 5;
3529
+ const DropdownKeyDownBackspace = process.env.NODE_ENV !== "production" ? '__dropdown_keydown_backspace__' : 6;
3530
+ const DropdownClick = process.env.NODE_ENV !== "production" ? '__dropdown_click__' : 7;
3531
+ const FunctionAddSelectedItem = process.env.NODE_ENV !== "production" ? '__function_add_selected_item__' : 8;
3532
+ const FunctionRemoveSelectedItem = process.env.NODE_ENV !== "production" ? '__function_remove_selected_item__' : 9;
3533
+ const FunctionSetSelectedItems = process.env.NODE_ENV !== "production" ? '__function_set_selected_items__' : 10;
3534
+ const FunctionSetActiveIndex = process.env.NODE_ENV !== "production" ? '__function_set_active_index__' : 11;
3535
+ const FunctionReset = process.env.NODE_ENV !== "production" ? '__function_reset__' : 12;
3423
3536
 
3424
3537
  var stateChangeTypes = /*#__PURE__*/Object.freeze({
3425
3538
  __proto__: null,
@@ -3440,13 +3553,17 @@ var stateChangeTypes = /*#__PURE__*/Object.freeze({
3440
3553
 
3441
3554
  /* eslint-disable complexity */
3442
3555
  function downshiftMultipleSelectionReducer(state, action) {
3443
- var type = action.type,
3444
- index = action.index,
3445
- props = action.props,
3446
- selectedItem = action.selectedItem;
3447
- var activeIndex = state.activeIndex,
3448
- selectedItems = state.selectedItems;
3449
- var changes;
3556
+ const {
3557
+ type,
3558
+ index,
3559
+ props,
3560
+ selectedItem
3561
+ } = action;
3562
+ const {
3563
+ activeIndex,
3564
+ selectedItems
3565
+ } = state;
3566
+ let changes;
3450
3567
  switch (type) {
3451
3568
  case SelectedItemClick:
3452
3569
  changes = {
@@ -3469,17 +3586,18 @@ function downshiftMultipleSelectionReducer(state, action) {
3469
3586
  if (activeIndex < 0) {
3470
3587
  break;
3471
3588
  }
3472
- var newActiveIndex = activeIndex;
3589
+ let newActiveIndex = activeIndex;
3473
3590
  if (selectedItems.length === 1) {
3474
3591
  newActiveIndex = -1;
3475
3592
  } else if (activeIndex === selectedItems.length - 1) {
3476
3593
  newActiveIndex = selectedItems.length - 2;
3477
3594
  }
3478
- changes = _extends__default["default"]({
3479
- selectedItems: [].concat(selectedItems.slice(0, activeIndex), selectedItems.slice(activeIndex + 1))
3480
- }, {
3481
- activeIndex: newActiveIndex
3482
- });
3595
+ changes = {
3596
+ selectedItems: [...selectedItems.slice(0, activeIndex), ...selectedItems.slice(activeIndex + 1)],
3597
+ ...{
3598
+ activeIndex: newActiveIndex
3599
+ }
3600
+ };
3483
3601
  break;
3484
3602
  }
3485
3603
  case DropdownKeyDownNavigationPrevious:
@@ -3494,7 +3612,7 @@ function downshiftMultipleSelectionReducer(state, action) {
3494
3612
  break;
3495
3613
  case FunctionAddSelectedItem:
3496
3614
  changes = {
3497
- selectedItems: [].concat(selectedItems, [selectedItem])
3615
+ selectedItems: [...selectedItems, selectedItem]
3498
3616
  };
3499
3617
  break;
3500
3618
  case DropdownClick:
@@ -3504,25 +3622,27 @@ function downshiftMultipleSelectionReducer(state, action) {
3504
3622
  break;
3505
3623
  case FunctionRemoveSelectedItem:
3506
3624
  {
3507
- var _newActiveIndex = activeIndex;
3508
- var selectedItemIndex = selectedItems.indexOf(selectedItem);
3625
+ let newActiveIndex = activeIndex;
3626
+ const selectedItemIndex = selectedItems.indexOf(selectedItem);
3509
3627
  if (selectedItemIndex < 0) {
3510
3628
  break;
3511
3629
  }
3512
3630
  if (selectedItems.length === 1) {
3513
- _newActiveIndex = -1;
3631
+ newActiveIndex = -1;
3514
3632
  } else if (selectedItemIndex === selectedItems.length - 1) {
3515
- _newActiveIndex = selectedItems.length - 2;
3633
+ newActiveIndex = selectedItems.length - 2;
3516
3634
  }
3517
3635
  changes = {
3518
- selectedItems: [].concat(selectedItems.slice(0, selectedItemIndex), selectedItems.slice(selectedItemIndex + 1)),
3519
- activeIndex: _newActiveIndex
3636
+ selectedItems: [...selectedItems.slice(0, selectedItemIndex), ...selectedItems.slice(selectedItemIndex + 1)],
3637
+ activeIndex: newActiveIndex
3520
3638
  };
3521
3639
  break;
3522
3640
  }
3523
3641
  case FunctionSetSelectedItems:
3524
3642
  {
3525
- var newSelectedItems = action.selectedItems;
3643
+ const {
3644
+ selectedItems: newSelectedItems
3645
+ } = action;
3526
3646
  changes = {
3527
3647
  selectedItems: newSelectedItems
3528
3648
  };
@@ -3530,9 +3650,11 @@ function downshiftMultipleSelectionReducer(state, action) {
3530
3650
  }
3531
3651
  case FunctionSetActiveIndex:
3532
3652
  {
3533
- var _newActiveIndex2 = action.activeIndex;
3653
+ const {
3654
+ activeIndex: newActiveIndex
3655
+ } = action;
3534
3656
  changes = {
3535
- activeIndex: _newActiveIndex2
3657
+ activeIndex: newActiveIndex
3536
3658
  };
3537
3659
  break;
3538
3660
  }
@@ -3545,11 +3667,12 @@ function downshiftMultipleSelectionReducer(state, action) {
3545
3667
  default:
3546
3668
  throw new Error('Reducer called without proper action type.');
3547
3669
  }
3548
- return _extends__default["default"]({}, state, changes);
3670
+ return {
3671
+ ...state,
3672
+ ...changes
3673
+ };
3549
3674
  }
3550
3675
 
3551
- var _excluded = ["refKey", "ref", "onClick", "onKeyDown", "selectedItem", "index"],
3552
- _excluded2 = ["refKey", "ref", "onKeyDown", "onClick", "preventKeyAction"];
3553
3676
  useMultipleSelection.stateChangeTypes = stateChangeTypes;
3554
3677
  function useMultipleSelection(userProps) {
3555
3678
  if (userProps === void 0) {
@@ -3557,46 +3680,49 @@ function useMultipleSelection(userProps) {
3557
3680
  }
3558
3681
  validatePropTypes(userProps, useMultipleSelection);
3559
3682
  // Props defaults and destructuring.
3560
- var props = _extends__default["default"]({}, defaultProps, userProps);
3561
- var getA11yRemovalMessage = props.getA11yRemovalMessage,
3562
- itemToString = props.itemToString,
3563
- environment = props.environment,
3564
- keyNavigationNext = props.keyNavigationNext,
3565
- keyNavigationPrevious = props.keyNavigationPrevious;
3683
+ const props = {
3684
+ ...defaultProps,
3685
+ ...userProps
3686
+ };
3687
+ const {
3688
+ getA11yRemovalMessage,
3689
+ itemToString,
3690
+ environment,
3691
+ keyNavigationNext,
3692
+ keyNavigationPrevious
3693
+ } = props;
3566
3694
 
3567
3695
  // Reducer init.
3568
- var _useControlledReducer = useControlledReducer$1(downshiftMultipleSelectionReducer, getInitialState(props), props),
3569
- state = _useControlledReducer[0],
3570
- dispatch = _useControlledReducer[1];
3571
- var activeIndex = state.activeIndex,
3572
- selectedItems = state.selectedItems;
3696
+ const [state, dispatch] = useControlledReducer$1(downshiftMultipleSelectionReducer, getInitialState(props), props);
3697
+ const {
3698
+ activeIndex,
3699
+ selectedItems
3700
+ } = state;
3573
3701
 
3574
3702
  // Refs.
3575
- var isInitialMountRef = preact.useRef(true);
3576
- var dropdownRef = preact.useRef(null);
3577
- var previousSelectedItemsRef = preact.useRef(selectedItems);
3578
- var selectedItemRefs = preact.useRef();
3703
+ const isInitialMountRef = preact.useRef(true);
3704
+ const dropdownRef = preact.useRef(null);
3705
+ const previousSelectedItemsRef = preact.useRef(selectedItems);
3706
+ const selectedItemRefs = preact.useRef();
3579
3707
  selectedItemRefs.current = [];
3580
- var latest = useLatestRef({
3581
- state: state,
3582
- props: props
3708
+ const latest = useLatestRef({
3709
+ state,
3710
+ props
3583
3711
  });
3584
3712
 
3585
3713
  // Effects.
3586
3714
  /* Sets a11y status message on changes in selectedItem. */
3587
- preact.useEffect(function () {
3715
+ preact.useEffect(() => {
3588
3716
  if (isInitialMountRef.current) {
3589
3717
  return;
3590
3718
  }
3591
3719
  if (selectedItems.length < previousSelectedItemsRef.current.length) {
3592
- var removedSelectedItem = previousSelectedItemsRef.current.find(function (item) {
3593
- return selectedItems.indexOf(item) < 0;
3594
- });
3720
+ const removedSelectedItem = previousSelectedItemsRef.current.find(item => selectedItems.indexOf(item) < 0);
3595
3721
  setStatus(getA11yRemovalMessage({
3596
- itemToString: itemToString,
3722
+ itemToString,
3597
3723
  resultCount: selectedItems.length,
3598
- removedSelectedItem: removedSelectedItem,
3599
- activeIndex: activeIndex,
3724
+ removedSelectedItem,
3725
+ activeIndex,
3600
3726
  activeSelectedItem: selectedItems[activeIndex]
3601
3727
  }), environment.document);
3602
3728
  }
@@ -3605,7 +3731,7 @@ function useMultipleSelection(userProps) {
3605
3731
  // eslint-disable-next-line react-hooks/exhaustive-deps
3606
3732
  }, [selectedItems.length]);
3607
3733
  // Sets focus on active item.
3608
- preact.useEffect(function () {
3734
+ preact.useEffect(() => {
3609
3735
  if (isInitialMountRef.current) {
3610
3736
  return;
3611
3737
  }
@@ -3617,167 +3743,178 @@ function useMultipleSelection(userProps) {
3617
3743
  }, [activeIndex]);
3618
3744
  useControlPropsValidator({
3619
3745
  isInitialMount: isInitialMountRef.current,
3620
- props: props,
3621
- state: state
3746
+ props,
3747
+ state
3622
3748
  });
3623
- var setGetterPropCallInfo = useGetterPropsCalledChecker('getDropdownProps');
3749
+ const setGetterPropCallInfo = useGetterPropsCalledChecker('getDropdownProps');
3624
3750
  // Make initial ref false.
3625
- preact.useEffect(function () {
3751
+ preact.useEffect(() => {
3626
3752
  isInitialMountRef.current = false;
3627
- return function () {
3753
+ return () => {
3628
3754
  isInitialMountRef.current = true;
3629
3755
  };
3630
3756
  }, []);
3631
3757
 
3632
3758
  // Event handler functions.
3633
- var selectedItemKeyDownHandlers = preact.useMemo(function () {
3634
- var _ref;
3635
- return _ref = {}, _ref[keyNavigationPrevious] = function () {
3759
+ const selectedItemKeyDownHandlers = preact.useMemo(() => ({
3760
+ [keyNavigationPrevious]() {
3636
3761
  dispatch({
3637
3762
  type: SelectedItemKeyDownNavigationPrevious
3638
3763
  });
3639
- }, _ref[keyNavigationNext] = function () {
3764
+ },
3765
+ [keyNavigationNext]() {
3640
3766
  dispatch({
3641
3767
  type: SelectedItemKeyDownNavigationNext
3642
3768
  });
3643
- }, _ref.Delete = function Delete() {
3769
+ },
3770
+ Delete() {
3644
3771
  dispatch({
3645
3772
  type: SelectedItemKeyDownDelete
3646
3773
  });
3647
- }, _ref.Backspace = function Backspace() {
3774
+ },
3775
+ Backspace() {
3648
3776
  dispatch({
3649
3777
  type: SelectedItemKeyDownBackspace
3650
3778
  });
3651
- }, _ref;
3652
- }, [dispatch, keyNavigationNext, keyNavigationPrevious]);
3653
- var dropdownKeyDownHandlers = preact.useMemo(function () {
3654
- var _ref2;
3655
- return _ref2 = {}, _ref2[keyNavigationPrevious] = function (event) {
3779
+ }
3780
+ }), [dispatch, keyNavigationNext, keyNavigationPrevious]);
3781
+ const dropdownKeyDownHandlers = preact.useMemo(() => ({
3782
+ [keyNavigationPrevious](event) {
3656
3783
  if (isKeyDownOperationPermitted(event)) {
3657
3784
  dispatch({
3658
3785
  type: DropdownKeyDownNavigationPrevious
3659
3786
  });
3660
3787
  }
3661
- }, _ref2.Backspace = function Backspace(event) {
3788
+ },
3789
+ Backspace(event) {
3662
3790
  if (isKeyDownOperationPermitted(event)) {
3663
3791
  dispatch({
3664
3792
  type: DropdownKeyDownBackspace
3665
3793
  });
3666
3794
  }
3667
- }, _ref2;
3668
- }, [dispatch, keyNavigationPrevious]);
3795
+ }
3796
+ }), [dispatch, keyNavigationPrevious]);
3669
3797
 
3670
3798
  // Getter props.
3671
- var getSelectedItemProps = preact.useCallback(function (_temp) {
3672
- var _extends2;
3673
- var _ref3 = _temp === void 0 ? {} : _temp,
3674
- _ref3$refKey = _ref3.refKey,
3675
- refKey = _ref3$refKey === void 0 ? 'ref' : _ref3$refKey,
3676
- ref = _ref3.ref,
3677
- onClick = _ref3.onClick,
3678
- onKeyDown = _ref3.onKeyDown,
3679
- selectedItem = _ref3.selectedItem,
3680
- index = _ref3.index,
3681
- rest = _objectWithoutPropertiesLoose__default["default"](_ref3, _excluded);
3682
- var latestState = latest.current.state;
3683
- var itemIndex = getItemIndex(index, selectedItem, latestState.selectedItems);
3799
+ const getSelectedItemProps = preact.useCallback(function (_temp) {
3800
+ let {
3801
+ refKey = 'ref',
3802
+ ref,
3803
+ onClick,
3804
+ onKeyDown,
3805
+ selectedItem,
3806
+ index,
3807
+ ...rest
3808
+ } = _temp === void 0 ? {} : _temp;
3809
+ const {
3810
+ state: latestState
3811
+ } = latest.current;
3812
+ const itemIndex = getItemIndex(index, selectedItem, latestState.selectedItems);
3684
3813
  if (itemIndex < 0) {
3685
3814
  throw new Error('Pass either selectedItem or index in getSelectedItemProps!');
3686
3815
  }
3687
- var selectedItemHandleClick = function selectedItemHandleClick() {
3816
+ const selectedItemHandleClick = () => {
3688
3817
  dispatch({
3689
3818
  type: SelectedItemClick,
3690
- index: index
3819
+ index
3691
3820
  });
3692
3821
  };
3693
- var selectedItemHandleKeyDown = function selectedItemHandleKeyDown(event) {
3694
- var key = normalizeArrowKey(event);
3822
+ const selectedItemHandleKeyDown = event => {
3823
+ const key = normalizeArrowKey(event);
3695
3824
  if (key && selectedItemKeyDownHandlers[key]) {
3696
3825
  selectedItemKeyDownHandlers[key](event);
3697
3826
  }
3698
3827
  };
3699
- return _extends__default["default"]((_extends2 = {}, _extends2[refKey] = handleRefs(ref, function (selectedItemNode) {
3700
- if (selectedItemNode) {
3701
- selectedItemRefs.current.push(selectedItemNode);
3702
- }
3703
- }), _extends2.tabIndex = index === latestState.activeIndex ? 0 : -1, _extends2.onClick = callAllEventHandlers(onClick, selectedItemHandleClick), _extends2.onKeyDown = callAllEventHandlers(onKeyDown, selectedItemHandleKeyDown), _extends2), rest);
3828
+ return {
3829
+ [refKey]: handleRefs(ref, selectedItemNode => {
3830
+ if (selectedItemNode) {
3831
+ selectedItemRefs.current.push(selectedItemNode);
3832
+ }
3833
+ }),
3834
+ tabIndex: index === latestState.activeIndex ? 0 : -1,
3835
+ onClick: callAllEventHandlers(onClick, selectedItemHandleClick),
3836
+ onKeyDown: callAllEventHandlers(onKeyDown, selectedItemHandleKeyDown),
3837
+ ...rest
3838
+ };
3704
3839
  }, [dispatch, latest, selectedItemKeyDownHandlers]);
3705
- var getDropdownProps = preact.useCallback(function (_temp2, _temp3) {
3706
- var _extends3;
3707
- var _ref4 = _temp2 === void 0 ? {} : _temp2,
3708
- _ref4$refKey = _ref4.refKey,
3709
- refKey = _ref4$refKey === void 0 ? 'ref' : _ref4$refKey,
3710
- ref = _ref4.ref,
3711
- onKeyDown = _ref4.onKeyDown,
3712
- onClick = _ref4.onClick,
3713
- _ref4$preventKeyActio = _ref4.preventKeyAction,
3714
- preventKeyAction = _ref4$preventKeyActio === void 0 ? false : _ref4$preventKeyActio,
3715
- rest = _objectWithoutPropertiesLoose__default["default"](_ref4, _excluded2);
3716
- var _ref5 = _temp3 === void 0 ? {} : _temp3,
3717
- _ref5$suppressRefErro = _ref5.suppressRefError,
3718
- suppressRefError = _ref5$suppressRefErro === void 0 ? false : _ref5$suppressRefErro;
3840
+ const getDropdownProps = preact.useCallback(function (_temp2, _temp3) {
3841
+ let {
3842
+ refKey = 'ref',
3843
+ ref,
3844
+ onKeyDown,
3845
+ onClick,
3846
+ preventKeyAction = false,
3847
+ ...rest
3848
+ } = _temp2 === void 0 ? {} : _temp2;
3849
+ let {
3850
+ suppressRefError = false
3851
+ } = _temp3 === void 0 ? {} : _temp3;
3719
3852
  setGetterPropCallInfo('getDropdownProps', suppressRefError, refKey, dropdownRef);
3720
- var dropdownHandleKeyDown = function dropdownHandleKeyDown(event) {
3721
- var key = normalizeArrowKey(event);
3853
+ const dropdownHandleKeyDown = event => {
3854
+ const key = normalizeArrowKey(event);
3722
3855
  if (key && dropdownKeyDownHandlers[key]) {
3723
3856
  dropdownKeyDownHandlers[key](event);
3724
3857
  }
3725
3858
  };
3726
- var dropdownHandleClick = function dropdownHandleClick() {
3859
+ const dropdownHandleClick = () => {
3727
3860
  dispatch({
3728
3861
  type: DropdownClick
3729
3862
  });
3730
3863
  };
3731
- return _extends__default["default"]((_extends3 = {}, _extends3[refKey] = handleRefs(ref, function (dropdownNode) {
3732
- if (dropdownNode) {
3733
- dropdownRef.current = dropdownNode;
3734
- }
3735
- }), _extends3), !preventKeyAction && {
3736
- onKeyDown: callAllEventHandlers(onKeyDown, dropdownHandleKeyDown),
3737
- onClick: callAllEventHandlers(onClick, dropdownHandleClick)
3738
- }, rest);
3864
+ return {
3865
+ [refKey]: handleRefs(ref, dropdownNode => {
3866
+ if (dropdownNode) {
3867
+ dropdownRef.current = dropdownNode;
3868
+ }
3869
+ }),
3870
+ ...(!preventKeyAction && {
3871
+ onKeyDown: callAllEventHandlers(onKeyDown, dropdownHandleKeyDown),
3872
+ onClick: callAllEventHandlers(onClick, dropdownHandleClick)
3873
+ }),
3874
+ ...rest
3875
+ };
3739
3876
  }, [dispatch, dropdownKeyDownHandlers, setGetterPropCallInfo]);
3740
3877
 
3741
3878
  // returns
3742
- var addSelectedItem = preact.useCallback(function (selectedItem) {
3879
+ const addSelectedItem = preact.useCallback(selectedItem => {
3743
3880
  dispatch({
3744
3881
  type: FunctionAddSelectedItem,
3745
- selectedItem: selectedItem
3882
+ selectedItem
3746
3883
  });
3747
3884
  }, [dispatch]);
3748
- var removeSelectedItem = preact.useCallback(function (selectedItem) {
3885
+ const removeSelectedItem = preact.useCallback(selectedItem => {
3749
3886
  dispatch({
3750
3887
  type: FunctionRemoveSelectedItem,
3751
- selectedItem: selectedItem
3888
+ selectedItem
3752
3889
  });
3753
3890
  }, [dispatch]);
3754
- var setSelectedItems = preact.useCallback(function (newSelectedItems) {
3891
+ const setSelectedItems = preact.useCallback(newSelectedItems => {
3755
3892
  dispatch({
3756
3893
  type: FunctionSetSelectedItems,
3757
3894
  selectedItems: newSelectedItems
3758
3895
  });
3759
3896
  }, [dispatch]);
3760
- var setActiveIndex = preact.useCallback(function (newActiveIndex) {
3897
+ const setActiveIndex = preact.useCallback(newActiveIndex => {
3761
3898
  dispatch({
3762
3899
  type: FunctionSetActiveIndex,
3763
3900
  activeIndex: newActiveIndex
3764
3901
  });
3765
3902
  }, [dispatch]);
3766
- var reset = preact.useCallback(function () {
3903
+ const reset = preact.useCallback(() => {
3767
3904
  dispatch({
3768
3905
  type: FunctionReset
3769
3906
  });
3770
3907
  }, [dispatch]);
3771
3908
  return {
3772
- getSelectedItemProps: getSelectedItemProps,
3773
- getDropdownProps: getDropdownProps,
3774
- addSelectedItem: addSelectedItem,
3775
- removeSelectedItem: removeSelectedItem,
3776
- setSelectedItems: setSelectedItems,
3777
- setActiveIndex: setActiveIndex,
3778
- reset: reset,
3779
- selectedItems: selectedItems,
3780
- activeIndex: activeIndex
3909
+ getSelectedItemProps,
3910
+ getDropdownProps,
3911
+ addSelectedItem,
3912
+ removeSelectedItem,
3913
+ setSelectedItems,
3914
+ setActiveIndex,
3915
+ reset,
3916
+ selectedItems,
3917
+ activeIndex
3781
3918
  };
3782
3919
  }
3783
3920