downshift 6.1.5 → 6.1.8

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,10 +2,6 @@
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
7
  var computeScrollIntoView = require('compute-scroll-into-view');
@@ -14,14 +10,10 @@ 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
13
  var computeScrollIntoView__default = /*#__PURE__*/_interopDefaultLegacy(computeScrollIntoView);
22
14
  var PropTypes__default = /*#__PURE__*/_interopDefaultLegacy(PropTypes);
23
15
 
24
- var idCounter = 0;
16
+ let idCounter = 0;
25
17
  /**
26
18
  * Accepts a parameter and returns it if it's a function
27
19
  * or a noop function if it's not. This allows us to
@@ -48,15 +40,17 @@ function scrollIntoView(node, menuNode) {
48
40
  return;
49
41
  }
50
42
 
51
- var actions = computeScrollIntoView__default['default'](node, {
43
+ const actions = computeScrollIntoView__default["default"](node, {
52
44
  boundary: menuNode,
53
45
  block: 'nearest',
54
46
  scrollMode: 'if-needed'
55
47
  });
56
- actions.forEach(function (_ref) {
57
- var el = _ref.el,
58
- top = _ref.top,
59
- left = _ref.left;
48
+ actions.forEach(_ref => {
49
+ let {
50
+ el,
51
+ top,
52
+ left
53
+ } = _ref;
60
54
  el.scrollTop = top;
61
55
  el.scrollLeft = left;
62
56
  });
@@ -70,7 +64,7 @@ function scrollIntoView(node, menuNode) {
70
64
 
71
65
 
72
66
  function isOrContainsNode(parent, child, environment) {
73
- var result = parent === child || child instanceof environment.Node && parent.contains && parent.contains(child);
67
+ const result = parent === child || child instanceof environment.Node && parent.contains && parent.contains(child);
74
68
  return result;
75
69
  }
76
70
  /**
@@ -84,7 +78,7 @@ function isOrContainsNode(parent, child, environment) {
84
78
 
85
79
 
86
80
  function debounce(fn, time) {
87
- var timeoutId;
81
+ let timeoutId;
88
82
 
89
83
  function cancel() {
90
84
  if (timeoutId) {
@@ -98,9 +92,9 @@ function debounce(fn, time) {
98
92
  }
99
93
 
100
94
  cancel();
101
- timeoutId = setTimeout(function () {
95
+ timeoutId = setTimeout(() => {
102
96
  timeoutId = null;
103
- fn.apply(void 0, args);
97
+ fn(...args);
104
98
  }, time);
105
99
  }
106
100
 
@@ -126,9 +120,9 @@ function callAllEventHandlers() {
126
120
  args[_key3 - 1] = arguments[_key3];
127
121
  }
128
122
 
129
- return fns.some(function (fn) {
123
+ return fns.some(fn => {
130
124
  if (fn) {
131
- fn.apply(void 0, [event].concat(args));
125
+ fn(event, ...args);
132
126
  }
133
127
 
134
128
  return event.preventDownshiftDefault || event.hasOwnProperty('nativeEvent') && event.nativeEvent.preventDownshiftDefault;
@@ -141,8 +135,8 @@ function handleRefs() {
141
135
  refs[_key4] = arguments[_key4];
142
136
  }
143
137
 
144
- return function (node) {
145
- refs.forEach(function (ref) {
138
+ return node => {
139
+ refs.forEach(ref => {
146
140
  if (typeof ref === 'function') {
147
141
  ref(node);
148
142
  } else if (ref) {
@@ -179,9 +173,11 @@ function resetIdCounter() {
179
173
 
180
174
 
181
175
  function getA11yStatusMessage$1(_ref2) {
182
- var isOpen = _ref2.isOpen,
183
- resultCount = _ref2.resultCount,
184
- previousResultCount = _ref2.previousResultCount;
176
+ let {
177
+ isOpen,
178
+ resultCount,
179
+ previousResultCount
180
+ } = _ref2;
185
181
 
186
182
  if (!isOpen) {
187
183
  return '';
@@ -257,7 +253,7 @@ function requiredProp(fnName, propName) {
257
253
  console.error("The property \"" + propName + "\" is required in \"" + fnName + "\"");
258
254
  }
259
255
 
260
- var stateKeys = ['highlightedIndex', 'inputValue', 'isOpen', 'selectedItem', 'type'];
256
+ const stateKeys = ['highlightedIndex', 'inputValue', 'isOpen', 'selectedItem', 'type'];
261
257
  /**
262
258
  * @param {Object} state the state object
263
259
  * @return {Object} state that is relevant to downshift
@@ -268,8 +264,8 @@ function pickState(state) {
268
264
  state = {};
269
265
  }
270
266
 
271
- var result = {};
272
- stateKeys.forEach(function (k) {
267
+ const result = {};
268
+ stateKeys.forEach(k => {
273
269
  if (state.hasOwnProperty(k)) {
274
270
  result[k] = state[k];
275
271
  }
@@ -290,7 +286,7 @@ function pickState(state) {
290
286
 
291
287
 
292
288
  function getState(state, props) {
293
- return Object.keys(state).reduce(function (prevState, key) {
289
+ return Object.keys(state).reduce((prevState, key) => {
294
290
  prevState[key] = isControlledProp(props, key) ? props[key] : state[key];
295
291
  return prevState;
296
292
  }, {});
@@ -317,8 +313,10 @@ function isControlledProp(props, key) {
317
313
 
318
314
 
319
315
  function normalizeArrowKey(event) {
320
- var key = event.key,
321
- keyCode = event.keyCode;
316
+ const {
317
+ key,
318
+ keyCode
319
+ } = event;
322
320
  /* istanbul ignore next (ie) */
323
321
 
324
322
  if (keyCode >= 37 && keyCode <= 40 && key.indexOf('Arrow') !== 0) {
@@ -359,13 +357,13 @@ function getNextWrappingIndex(moveAmount, baseIndex, itemCount, getItemNodeFromI
359
357
  return -1;
360
358
  }
361
359
 
362
- var itemsLastIndex = itemCount - 1;
360
+ const itemsLastIndex = itemCount - 1;
363
361
 
364
362
  if (typeof baseIndex !== 'number' || baseIndex < 0 || baseIndex >= itemCount) {
365
363
  baseIndex = moveAmount > 0 ? -1 : itemsLastIndex + 1;
366
364
  }
367
365
 
368
- var newIndex = baseIndex + moveAmount;
366
+ let newIndex = baseIndex + moveAmount;
369
367
 
370
368
  if (newIndex < 0) {
371
369
  newIndex = circular ? itemsLastIndex : 0;
@@ -373,7 +371,7 @@ function getNextWrappingIndex(moveAmount, baseIndex, itemCount, getItemNodeFromI
373
371
  newIndex = circular ? 0 : itemsLastIndex;
374
372
  }
375
373
 
376
- var nonDisabledNewIndex = getNextNonDisabledIndex(moveAmount, newIndex, itemCount, getItemNodeFromIndex, circular);
374
+ const nonDisabledNewIndex = getNextNonDisabledIndex(moveAmount, newIndex, itemCount, getItemNodeFromIndex, circular);
377
375
 
378
376
  if (nonDisabledNewIndex === -1) {
379
377
  return baseIndex >= itemCount ? -1 : baseIndex;
@@ -394,22 +392,22 @@ function getNextWrappingIndex(moveAmount, baseIndex, itemCount, getItemNodeFromI
394
392
 
395
393
 
396
394
  function getNextNonDisabledIndex(moveAmount, baseIndex, itemCount, getItemNodeFromIndex, circular) {
397
- var currentElementNode = getItemNodeFromIndex(baseIndex);
395
+ const currentElementNode = getItemNodeFromIndex(baseIndex);
398
396
 
399
397
  if (!currentElementNode || !currentElementNode.hasAttribute('disabled')) {
400
398
  return baseIndex;
401
399
  }
402
400
 
403
401
  if (moveAmount > 0) {
404
- for (var index = baseIndex + 1; index < itemCount; index++) {
402
+ for (let index = baseIndex + 1; index < itemCount; index++) {
405
403
  if (!getItemNodeFromIndex(index).hasAttribute('disabled')) {
406
404
  return index;
407
405
  }
408
406
  }
409
407
  } else {
410
- for (var _index = baseIndex - 1; _index >= 0; _index--) {
411
- if (!getItemNodeFromIndex(_index).hasAttribute('disabled')) {
412
- return _index;
408
+ for (let index = baseIndex - 1; index >= 0; index--) {
409
+ if (!getItemNodeFromIndex(index).hasAttribute('disabled')) {
410
+ return index;
413
411
  }
414
412
  }
415
413
  }
@@ -437,19 +435,17 @@ function targetWithinDownshift(target, downshiftElements, environment, checkActi
437
435
  checkActiveElement = true;
438
436
  }
439
437
 
440
- return downshiftElements.some(function (contextNode) {
441
- return contextNode && (isOrContainsNode(contextNode, target, environment) || checkActiveElement && isOrContainsNode(contextNode, environment.document.activeElement, environment));
442
- });
438
+ return downshiftElements.some(contextNode => contextNode && (isOrContainsNode(contextNode, target, environment) || checkActiveElement && isOrContainsNode(contextNode, environment.document.activeElement, environment)));
443
439
  } // eslint-disable-next-line import/no-mutable-exports
444
440
 
445
441
 
446
- var validateControlledUnchanged = noop;
442
+ let validateControlledUnchanged = noop;
447
443
  /* istanbul ignore next */
448
444
 
449
445
  if (process.env.NODE_ENV !== 'production') {
450
- validateControlledUnchanged = function validateControlledUnchanged(state, prevProps, nextProps) {
451
- 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";
452
- Object.keys(state).forEach(function (propKey) {
446
+ validateControlledUnchanged = (state, prevProps, nextProps) => {
447
+ 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";
448
+ Object.keys(state).forEach(propKey => {
453
449
  if (prevProps[propKey] !== undefined && nextProps[propKey] === undefined) {
454
450
  // eslint-disable-next-line no-console
455
451
  console.error("downshift: A component has changed the controlled prop \"" + propKey + "\" to be uncontrolled. " + warningDescription);
@@ -461,7 +457,7 @@ if (process.env.NODE_ENV !== 'production') {
461
457
  };
462
458
  }
463
459
 
464
- var cleanupStatus = debounce(function (documentProp) {
460
+ const cleanupStatus = debounce(documentProp => {
465
461
  getStatusDiv(documentProp).textContent = '';
466
462
  }, 500);
467
463
  /**
@@ -470,7 +466,7 @@ var cleanupStatus = debounce(function (documentProp) {
470
466
  */
471
467
 
472
468
  function setStatus(status, documentProp) {
473
- var div = getStatusDiv(documentProp);
469
+ const div = getStatusDiv(documentProp);
474
470
 
475
471
  if (!status) {
476
472
  return;
@@ -491,7 +487,7 @@ function getStatusDiv(documentProp) {
491
487
  documentProp = document;
492
488
  }
493
489
 
494
- var statusDiv = documentProp.getElementById('a11y-status-message');
490
+ let statusDiv = documentProp.getElementById('a11y-status-message');
495
491
 
496
492
  if (statusDiv) {
497
493
  return statusDiv;
@@ -516,23 +512,23 @@ function getStatusDiv(documentProp) {
516
512
  return statusDiv;
517
513
  }
518
514
 
519
- var unknown = process.env.NODE_ENV !== "production" ? '__autocomplete_unknown__' : 0;
520
- var mouseUp = process.env.NODE_ENV !== "production" ? '__autocomplete_mouseup__' : 1;
521
- var itemMouseEnter = process.env.NODE_ENV !== "production" ? '__autocomplete_item_mouseenter__' : 2;
522
- var keyDownArrowUp = process.env.NODE_ENV !== "production" ? '__autocomplete_keydown_arrow_up__' : 3;
523
- var keyDownArrowDown = process.env.NODE_ENV !== "production" ? '__autocomplete_keydown_arrow_down__' : 4;
524
- var keyDownEscape = process.env.NODE_ENV !== "production" ? '__autocomplete_keydown_escape__' : 5;
525
- var keyDownEnter = process.env.NODE_ENV !== "production" ? '__autocomplete_keydown_enter__' : 6;
526
- var keyDownHome = process.env.NODE_ENV !== "production" ? '__autocomplete_keydown_home__' : 7;
527
- var keyDownEnd = process.env.NODE_ENV !== "production" ? '__autocomplete_keydown_end__' : 8;
528
- var clickItem = process.env.NODE_ENV !== "production" ? '__autocomplete_click_item__' : 9;
529
- var blurInput = process.env.NODE_ENV !== "production" ? '__autocomplete_blur_input__' : 10;
530
- var changeInput = process.env.NODE_ENV !== "production" ? '__autocomplete_change_input__' : 11;
531
- var keyDownSpaceButton = process.env.NODE_ENV !== "production" ? '__autocomplete_keydown_space_button__' : 12;
532
- var clickButton = process.env.NODE_ENV !== "production" ? '__autocomplete_click_button__' : 13;
533
- var blurButton = process.env.NODE_ENV !== "production" ? '__autocomplete_blur_button__' : 14;
534
- var controlledPropUpdatedSelectedItem = process.env.NODE_ENV !== "production" ? '__autocomplete_controlled_prop_updated_selected_item__' : 15;
535
- var touchEnd = process.env.NODE_ENV !== "production" ? '__autocomplete_touchend__' : 16;
515
+ const unknown = process.env.NODE_ENV !== "production" ? '__autocomplete_unknown__' : 0;
516
+ const mouseUp = process.env.NODE_ENV !== "production" ? '__autocomplete_mouseup__' : 1;
517
+ const itemMouseEnter = process.env.NODE_ENV !== "production" ? '__autocomplete_item_mouseenter__' : 2;
518
+ const keyDownArrowUp = process.env.NODE_ENV !== "production" ? '__autocomplete_keydown_arrow_up__' : 3;
519
+ const keyDownArrowDown = process.env.NODE_ENV !== "production" ? '__autocomplete_keydown_arrow_down__' : 4;
520
+ const keyDownEscape = process.env.NODE_ENV !== "production" ? '__autocomplete_keydown_escape__' : 5;
521
+ const keyDownEnter = process.env.NODE_ENV !== "production" ? '__autocomplete_keydown_enter__' : 6;
522
+ const keyDownHome = process.env.NODE_ENV !== "production" ? '__autocomplete_keydown_home__' : 7;
523
+ const keyDownEnd = process.env.NODE_ENV !== "production" ? '__autocomplete_keydown_end__' : 8;
524
+ const clickItem = process.env.NODE_ENV !== "production" ? '__autocomplete_click_item__' : 9;
525
+ const blurInput = process.env.NODE_ENV !== "production" ? '__autocomplete_blur_input__' : 10;
526
+ const changeInput = process.env.NODE_ENV !== "production" ? '__autocomplete_change_input__' : 11;
527
+ const keyDownSpaceButton = process.env.NODE_ENV !== "production" ? '__autocomplete_keydown_space_button__' : 12;
528
+ const clickButton = process.env.NODE_ENV !== "production" ? '__autocomplete_click_button__' : 13;
529
+ const blurButton = process.env.NODE_ENV !== "production" ? '__autocomplete_blur_button__' : 14;
530
+ const controlledPropUpdatedSelectedItem = process.env.NODE_ENV !== "production" ? '__autocomplete_controlled_prop_updated_selected_item__' : 15;
531
+ const touchEnd = process.env.NODE_ENV !== "production" ? '__autocomplete_touchend__' : 16;
536
532
 
537
533
  var stateChangeTypes$3 = /*#__PURE__*/Object.freeze({
538
534
  __proto__: null,
@@ -555,58 +551,45 @@ var stateChangeTypes$3 = /*#__PURE__*/Object.freeze({
555
551
  touchEnd: touchEnd
556
552
  });
557
553
 
558
- var _excluded$4 = ["refKey", "ref"],
559
- _excluded2$3 = ["onClick", "onPress", "onKeyDown", "onKeyUp", "onBlur"],
560
- _excluded3$2 = ["onKeyDown", "onBlur", "onChange", "onInput", "onChangeText"],
561
- _excluded4$1 = ["refKey", "ref"],
562
- _excluded5$1 = ["onMouseMove", "onMouseDown", "onClick", "onPress", "index", "item"];
554
+ /* eslint camelcase:0 */
563
555
 
564
- var Downshift = /*#__PURE__*/function () {
565
- var Downshift = /*#__PURE__*/function (_Component) {
566
- _inheritsLoose__default['default'](Downshift, _Component);
567
-
568
- function Downshift(_props) {
556
+ const Downshift = /*#__PURE__*/(() => {
557
+ class Downshift extends preact.Component {
558
+ constructor(_props) {
569
559
  var _this;
570
560
 
571
- _this = _Component.call(this, _props) || this; // fancy destructuring + defaults + aliases
572
- // this basically says each value of state should either be set to
573
- // the initial value or the default value if the initial value is not provided
574
-
575
- _this.id = _this.props.id || "downshift-" + generateId();
576
- _this.menuId = _this.props.menuId || _this.id + "-menu";
577
- _this.labelId = _this.props.labelId || _this.id + "-label";
578
- _this.inputId = _this.props.inputId || _this.id + "-input";
561
+ super(_props);
562
+ _this = this;
563
+ this.id = this.props.id || "downshift-" + generateId();
564
+ this.menuId = this.props.menuId || this.id + "-menu";
565
+ this.labelId = this.props.labelId || this.id + "-label";
566
+ this.inputId = this.props.inputId || this.id + "-input";
579
567
 
580
- _this.getItemId = _this.props.getItemId || function (index) {
581
- return _this.id + "-item-" + index;
582
- };
568
+ this.getItemId = this.props.getItemId || (index => this.id + "-item-" + index);
583
569
 
584
- _this.input = null;
585
- _this.items = [];
586
- _this.itemCount = null;
587
- _this.previousResultCount = 0;
588
- _this.timeoutIds = [];
570
+ this.input = null;
571
+ this.items = [];
572
+ this.itemCount = null;
573
+ this.previousResultCount = 0;
574
+ this.timeoutIds = [];
589
575
 
590
- _this.internalSetTimeout = function (fn, time) {
591
- var id = setTimeout(function () {
592
- _this.timeoutIds = _this.timeoutIds.filter(function (i) {
593
- return i !== id;
594
- });
576
+ this.internalSetTimeout = (fn, time) => {
577
+ const id = setTimeout(() => {
578
+ this.timeoutIds = this.timeoutIds.filter(i => i !== id);
595
579
  fn();
596
580
  }, time);
597
-
598
- _this.timeoutIds.push(id);
581
+ this.timeoutIds.push(id);
599
582
  };
600
583
 
601
- _this.setItemCount = function (count) {
602
- _this.itemCount = count;
584
+ this.setItemCount = count => {
585
+ this.itemCount = count;
603
586
  };
604
587
 
605
- _this.unsetItemCount = function () {
606
- _this.itemCount = null;
588
+ this.unsetItemCount = () => {
589
+ this.itemCount = null;
607
590
  };
608
591
 
609
- _this.setHighlightedIndex = function (highlightedIndex, otherStateToSet) {
592
+ this.setHighlightedIndex = function (highlightedIndex, otherStateToSet) {
610
593
  if (highlightedIndex === void 0) {
611
594
  highlightedIndex = _this.props.defaultHighlightedIndex;
612
595
  }
@@ -617,71 +600,72 @@ var Downshift = /*#__PURE__*/function () {
617
600
 
618
601
  otherStateToSet = pickState(otherStateToSet);
619
602
 
620
- _this.internalSetState(_extends__default['default']({
621
- highlightedIndex: highlightedIndex
622
- }, otherStateToSet));
603
+ _this.internalSetState({
604
+ highlightedIndex,
605
+ ...otherStateToSet
606
+ });
623
607
  };
624
608
 
625
- _this.clearSelection = function (cb) {
626
- _this.internalSetState({
609
+ this.clearSelection = cb => {
610
+ this.internalSetState({
627
611
  selectedItem: null,
628
612
  inputValue: '',
629
- highlightedIndex: _this.props.defaultHighlightedIndex,
630
- isOpen: _this.props.defaultIsOpen
613
+ highlightedIndex: this.props.defaultHighlightedIndex,
614
+ isOpen: this.props.defaultIsOpen
631
615
  }, cb);
632
616
  };
633
617
 
634
- _this.selectItem = function (item, otherStateToSet, cb) {
618
+ this.selectItem = (item, otherStateToSet, cb) => {
635
619
  otherStateToSet = pickState(otherStateToSet);
636
-
637
- _this.internalSetState(_extends__default['default']({
638
- isOpen: _this.props.defaultIsOpen,
639
- highlightedIndex: _this.props.defaultHighlightedIndex,
620
+ this.internalSetState({
621
+ isOpen: this.props.defaultIsOpen,
622
+ highlightedIndex: this.props.defaultHighlightedIndex,
640
623
  selectedItem: item,
641
- inputValue: _this.props.itemToString(item)
642
- }, otherStateToSet), cb);
624
+ inputValue: this.props.itemToString(item),
625
+ ...otherStateToSet
626
+ }, cb);
643
627
  };
644
628
 
645
- _this.selectItemAtIndex = function (itemIndex, otherStateToSet, cb) {
646
- var item = _this.items[itemIndex];
629
+ this.selectItemAtIndex = (itemIndex, otherStateToSet, cb) => {
630
+ const item = this.items[itemIndex];
647
631
 
648
632
  if (item == null) {
649
633
  return;
650
634
  }
651
635
 
652
- _this.selectItem(item, otherStateToSet, cb);
636
+ this.selectItem(item, otherStateToSet, cb);
653
637
  };
654
638
 
655
- _this.selectHighlightedItem = function (otherStateToSet, cb) {
656
- return _this.selectItemAtIndex(_this.getState().highlightedIndex, otherStateToSet, cb);
639
+ this.selectHighlightedItem = (otherStateToSet, cb) => {
640
+ return this.selectItemAtIndex(this.getState().highlightedIndex, otherStateToSet, cb);
657
641
  };
658
642
 
659
- _this.internalSetState = function (stateToSet, cb) {
660
- var isItemSelected, onChangeArg;
661
- var onStateChangeArg = {};
662
- var isStateToSetFunction = typeof stateToSet === 'function'; // we want to call `onInputValueChange` before the `setState` call
643
+ this.internalSetState = (stateToSet, cb) => {
644
+ let isItemSelected, onChangeArg;
645
+ const onStateChangeArg = {};
646
+ const isStateToSetFunction = typeof stateToSet === 'function'; // we want to call `onInputValueChange` before the `setState` call
663
647
  // so someone controlling the `inputValue` state gets notified of
664
648
  // the input change as soon as possible. This avoids issues with
665
649
  // preserving the cursor position.
666
650
  // See https://github.com/downshift-js/downshift/issues/217 for more info.
667
651
 
668
652
  if (!isStateToSetFunction && stateToSet.hasOwnProperty('inputValue')) {
669
- _this.props.onInputValueChange(stateToSet.inputValue, _extends__default['default']({}, _this.getStateAndHelpers(), stateToSet));
653
+ this.props.onInputValueChange(stateToSet.inputValue, { ...this.getStateAndHelpers(),
654
+ ...stateToSet
655
+ });
670
656
  }
671
657
 
672
- return _this.setState(function (state) {
673
- state = _this.getState(state);
674
- var newStateToSet = isStateToSetFunction ? stateToSet(state) : stateToSet; // Your own function that could modify the state that will be set.
658
+ return this.setState(state => {
659
+ state = this.getState(state);
660
+ let newStateToSet = isStateToSetFunction ? stateToSet(state) : stateToSet; // Your own function that could modify the state that will be set.
675
661
 
676
- newStateToSet = _this.props.stateReducer(state, newStateToSet); // checks if an item is selected, regardless of if it's different from
662
+ newStateToSet = this.props.stateReducer(state, newStateToSet); // checks if an item is selected, regardless of if it's different from
677
663
  // what was selected before
678
664
  // used to determine if onSelect and onChange callbacks should be called
679
665
 
680
666
  isItemSelected = newStateToSet.hasOwnProperty('selectedItem'); // this keeps track of the object we want to call with setState
681
667
 
682
- var nextState = {}; // this is just used to tell whether the state changed
683
-
684
- var nextFullState = {}; // we need to call on change if the outside world is controlling any of our state
668
+ const nextState = {}; // this is just used to tell whether the state changed
685
669
  // and we're trying to update that state. OR if the selection has changed and we're
686
670
  // trying to update the selection
687
671
 
@@ -690,7 +674,7 @@ var Downshift = /*#__PURE__*/function () {
690
674
  }
691
675
 
692
676
  newStateToSet.type = newStateToSet.type || unknown;
693
- Object.keys(newStateToSet).forEach(function (key) {
677
+ Object.keys(newStateToSet).forEach(key => {
694
678
  // onStateChangeArg should only have the state that is
695
679
  // actually changing
696
680
  if (state[key] !== newStateToSet[key]) {
@@ -707,81 +691,84 @@ var Downshift = /*#__PURE__*/function () {
707
691
  return;
708
692
  }
709
693
 
710
- nextFullState[key] = newStateToSet[key]; // if it's coming from props, then we don't care to set it internally
694
+ newStateToSet[key]; // if it's coming from props, then we don't care to set it internally
711
695
 
712
- if (!isControlledProp(_this.props, key)) {
696
+ if (!isControlledProp(this.props, key)) {
713
697
  nextState[key] = newStateToSet[key];
714
698
  }
715
699
  }); // if stateToSet is a function, then we weren't able to call onInputValueChange
716
700
  // earlier, so we'll call it now that we know what the inputValue state will be.
717
701
 
718
702
  if (isStateToSetFunction && newStateToSet.hasOwnProperty('inputValue')) {
719
- _this.props.onInputValueChange(newStateToSet.inputValue, _extends__default['default']({}, _this.getStateAndHelpers(), newStateToSet));
703
+ this.props.onInputValueChange(newStateToSet.inputValue, { ...this.getStateAndHelpers(),
704
+ ...newStateToSet
705
+ });
720
706
  }
721
707
 
722
708
  return nextState;
723
- }, function () {
709
+ }, () => {
724
710
  // call the provided callback if it's a function
725
711
  cbToCb(cb)(); // only call the onStateChange and onChange callbacks if
726
712
  // we have relevant information to pass them.
727
713
 
728
- var hasMoreStateThanType = Object.keys(onStateChangeArg).length > 1;
714
+ const hasMoreStateThanType = Object.keys(onStateChangeArg).length > 1;
729
715
 
730
716
  if (hasMoreStateThanType) {
731
- _this.props.onStateChange(onStateChangeArg, _this.getStateAndHelpers());
717
+ this.props.onStateChange(onStateChangeArg, this.getStateAndHelpers());
732
718
  }
733
719
 
734
720
  if (isItemSelected) {
735
- _this.props.onSelect(stateToSet.selectedItem, _this.getStateAndHelpers());
721
+ this.props.onSelect(stateToSet.selectedItem, this.getStateAndHelpers());
736
722
  }
737
723
 
738
724
  if (onChangeArg !== undefined) {
739
- _this.props.onChange(onChangeArg, _this.getStateAndHelpers());
725
+ this.props.onChange(onChangeArg, this.getStateAndHelpers());
740
726
  } // this is currently undocumented and therefore subject to change
741
727
  // We'll try to not break it, but just be warned.
742
728
 
743
729
 
744
- _this.props.onUserAction(onStateChangeArg, _this.getStateAndHelpers());
730
+ this.props.onUserAction(onStateChangeArg, this.getStateAndHelpers());
745
731
  });
746
732
  };
747
733
 
748
- _this.rootRef = function (node) {
749
- return _this._rootNode = node;
750
- };
751
-
752
- _this.getRootProps = function (_temp, _temp2) {
753
- var _extends2;
754
-
755
- var _ref = _temp === void 0 ? {} : _temp,
756
- _ref$refKey = _ref.refKey,
757
- refKey = _ref$refKey === void 0 ? 'ref' : _ref$refKey,
758
- ref = _ref.ref,
759
- rest = _objectWithoutPropertiesLoose__default['default'](_ref, _excluded$4);
760
-
761
- var _ref2 = _temp2 === void 0 ? {} : _temp2,
762
- _ref2$suppressRefErro = _ref2.suppressRefError,
763
- suppressRefError = _ref2$suppressRefErro === void 0 ? false : _ref2$suppressRefErro;
764
-
734
+ this.rootRef = node => this._rootNode = node;
735
+
736
+ this.getRootProps = function (_temp, _temp2) {
737
+ let {
738
+ refKey = 'ref',
739
+ ref,
740
+ ...rest
741
+ } = _temp === void 0 ? {} : _temp;
742
+ let {
743
+ suppressRefError = false
744
+ } = _temp2 === void 0 ? {} : _temp2;
765
745
  // this is used in the render to know whether the user has called getRootProps.
766
746
  // It uses that to know whether to apply the props automatically
767
747
  _this.getRootProps.called = true;
768
748
  _this.getRootProps.refKey = refKey;
769
749
  _this.getRootProps.suppressRefError = suppressRefError;
770
750
 
771
- var _this$getState = _this.getState(),
772
- isOpen = _this$getState.isOpen;
751
+ const {
752
+ isOpen
753
+ } = _this.getState();
773
754
 
774
- 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);
755
+ return {
756
+ [refKey]: handleRefs(ref, _this.rootRef),
757
+ role: 'combobox',
758
+ 'aria-expanded': isOpen,
759
+ 'aria-haspopup': 'listbox',
760
+ 'aria-owns': isOpen ? _this.menuId : null,
761
+ 'aria-labelledby': _this.labelId,
762
+ ...rest
763
+ };
775
764
  };
776
765
 
777
- _this.keyDownHandlers = {
778
- ArrowDown: function ArrowDown(event) {
779
- var _this2 = this;
780
-
766
+ this.keyDownHandlers = {
767
+ ArrowDown(event) {
781
768
  event.preventDefault();
782
769
 
783
770
  if (this.getState().isOpen) {
784
- var amount = event.shiftKey ? 5 : 1;
771
+ const amount = event.shiftKey ? 5 : 1;
785
772
  this.moveHighlightedIndex(amount, {
786
773
  type: keyDownArrowDown
787
774
  });
@@ -789,31 +776,27 @@ var Downshift = /*#__PURE__*/function () {
789
776
  this.internalSetState({
790
777
  isOpen: true,
791
778
  type: keyDownArrowDown
792
- }, function () {
793
- var itemCount = _this2.getItemCount();
779
+ }, () => {
780
+ const itemCount = this.getItemCount();
794
781
 
795
782
  if (itemCount > 0) {
796
- var _this2$getState = _this2.getState(),
797
- highlightedIndex = _this2$getState.highlightedIndex;
798
-
799
- var nextHighlightedIndex = getNextWrappingIndex(1, highlightedIndex, itemCount, function (index) {
800
- return _this2.getItemNodeFromIndex(index);
801
- });
802
-
803
- _this2.setHighlightedIndex(nextHighlightedIndex, {
783
+ const {
784
+ highlightedIndex
785
+ } = this.getState();
786
+ const nextHighlightedIndex = getNextWrappingIndex(1, highlightedIndex, itemCount, index => this.getItemNodeFromIndex(index));
787
+ this.setHighlightedIndex(nextHighlightedIndex, {
804
788
  type: keyDownArrowDown
805
789
  });
806
790
  }
807
791
  });
808
792
  }
809
793
  },
810
- ArrowUp: function ArrowUp(event) {
811
- var _this3 = this;
812
794
 
795
+ ArrowUp(event) {
813
796
  event.preventDefault();
814
797
 
815
798
  if (this.getState().isOpen) {
816
- var amount = event.shiftKey ? -5 : -1;
799
+ const amount = event.shiftKey ? -5 : -1;
817
800
  this.moveHighlightedIndex(amount, {
818
801
  type: keyDownArrowUp
819
802
  });
@@ -821,37 +804,36 @@ var Downshift = /*#__PURE__*/function () {
821
804
  this.internalSetState({
822
805
  isOpen: true,
823
806
  type: keyDownArrowUp
824
- }, function () {
825
- var itemCount = _this3.getItemCount();
807
+ }, () => {
808
+ const itemCount = this.getItemCount();
826
809
 
827
810
  if (itemCount > 0) {
828
- var _this3$getState = _this3.getState(),
829
- highlightedIndex = _this3$getState.highlightedIndex;
830
-
831
- var nextHighlightedIndex = getNextWrappingIndex(-1, highlightedIndex, itemCount, function (index) {
832
- return _this3.getItemNodeFromIndex(index);
833
- });
834
-
835
- _this3.setHighlightedIndex(nextHighlightedIndex, {
811
+ const {
812
+ highlightedIndex
813
+ } = this.getState();
814
+ const nextHighlightedIndex = getNextWrappingIndex(-1, highlightedIndex, itemCount, index => this.getItemNodeFromIndex(index));
815
+ this.setHighlightedIndex(nextHighlightedIndex, {
836
816
  type: keyDownArrowUp
837
817
  });
838
818
  }
839
819
  });
840
820
  }
841
821
  },
842
- Enter: function Enter(event) {
822
+
823
+ Enter(event) {
843
824
  if (event.which === 229) {
844
825
  return;
845
826
  }
846
827
 
847
- var _this$getState2 = this.getState(),
848
- isOpen = _this$getState2.isOpen,
849
- highlightedIndex = _this$getState2.highlightedIndex;
828
+ const {
829
+ isOpen,
830
+ highlightedIndex
831
+ } = this.getState();
850
832
 
851
833
  if (isOpen && highlightedIndex != null) {
852
834
  event.preventDefault();
853
- var item = this.items[highlightedIndex];
854
- var itemNode = this.getItemNodeFromIndex(highlightedIndex);
835
+ const item = this.items[highlightedIndex];
836
+ const itemNode = this.getItemNodeFromIndex(highlightedIndex);
855
837
 
856
838
  if (item == null || itemNode && itemNode.hasAttribute('disabled')) {
857
839
  return;
@@ -862,125 +844,131 @@ var Downshift = /*#__PURE__*/function () {
862
844
  });
863
845
  }
864
846
  },
865
- Escape: function Escape(event) {
847
+
848
+ Escape(event) {
866
849
  event.preventDefault();
867
- this.reset(_extends__default['default']({
868
- type: keyDownEscape
869
- }, !this.state.isOpen && {
870
- selectedItem: null,
871
- inputValue: ''
872
- }));
850
+ this.reset({
851
+ type: keyDownEscape,
852
+ ...(!this.state.isOpen && {
853
+ selectedItem: null,
854
+ inputValue: ''
855
+ })
856
+ });
873
857
  }
858
+
874
859
  };
875
- _this.buttonKeyDownHandlers = _extends__default['default']({}, _this.keyDownHandlers, {
876
- ' ': function _(event) {
860
+ this.buttonKeyDownHandlers = { ...this.keyDownHandlers,
861
+
862
+ ' '(event) {
877
863
  event.preventDefault();
878
864
  this.toggleMenu({
879
865
  type: keyDownSpaceButton
880
866
  });
881
867
  }
882
- });
883
- _this.inputKeyDownHandlers = _extends__default['default']({}, _this.keyDownHandlers, {
884
- Home: function Home(event) {
885
- var _this4 = this;
886
868
 
887
- var _this$getState3 = this.getState(),
888
- isOpen = _this$getState3.isOpen;
869
+ };
870
+ this.inputKeyDownHandlers = { ...this.keyDownHandlers,
871
+
872
+ Home(event) {
873
+ const {
874
+ isOpen
875
+ } = this.getState();
889
876
 
890
877
  if (!isOpen) {
891
878
  return;
892
879
  }
893
880
 
894
881
  event.preventDefault();
895
- var itemCount = this.getItemCount();
882
+ const itemCount = this.getItemCount();
896
883
 
897
884
  if (itemCount <= 0 || !isOpen) {
898
885
  return;
899
886
  } // get next non-disabled starting downwards from 0 if that's disabled.
900
887
 
901
888
 
902
- var newHighlightedIndex = getNextNonDisabledIndex(1, 0, itemCount, function (index) {
903
- return _this4.getItemNodeFromIndex(index);
904
- }, false);
889
+ const newHighlightedIndex = getNextNonDisabledIndex(1, 0, itemCount, index => this.getItemNodeFromIndex(index), false);
905
890
  this.setHighlightedIndex(newHighlightedIndex, {
906
891
  type: keyDownHome
907
892
  });
908
893
  },
909
- End: function End(event) {
910
- var _this5 = this;
911
894
 
912
- var _this$getState4 = this.getState(),
913
- isOpen = _this$getState4.isOpen;
895
+ End(event) {
896
+ const {
897
+ isOpen
898
+ } = this.getState();
914
899
 
915
900
  if (!isOpen) {
916
901
  return;
917
902
  }
918
903
 
919
904
  event.preventDefault();
920
- var itemCount = this.getItemCount();
905
+ const itemCount = this.getItemCount();
921
906
 
922
907
  if (itemCount <= 0 || !isOpen) {
923
908
  return;
924
909
  } // get next non-disabled starting upwards from last index if that's disabled.
925
910
 
926
911
 
927
- var newHighlightedIndex = getNextNonDisabledIndex(-1, itemCount - 1, itemCount, function (index) {
928
- return _this5.getItemNodeFromIndex(index);
929
- }, false);
912
+ const newHighlightedIndex = getNextNonDisabledIndex(-1, itemCount - 1, itemCount, index => this.getItemNodeFromIndex(index), false);
930
913
  this.setHighlightedIndex(newHighlightedIndex, {
931
914
  type: keyDownEnd
932
915
  });
933
916
  }
934
- });
935
917
 
936
- _this.getToggleButtonProps = function (_temp3) {
937
- var _ref3 = _temp3 === void 0 ? {} : _temp3,
938
- onClick = _ref3.onClick;
939
- _ref3.onPress;
940
- var onKeyDown = _ref3.onKeyDown,
941
- onKeyUp = _ref3.onKeyUp,
942
- onBlur = _ref3.onBlur,
943
- rest = _objectWithoutPropertiesLoose__default['default'](_ref3, _excluded2$3);
944
-
945
- var _this$getState5 = _this.getState(),
946
- isOpen = _this$getState5.isOpen;
918
+ };
947
919
 
948
- var enabledEventHandlers = {
920
+ this.getToggleButtonProps = function (_temp3) {
921
+ let {
922
+ onClick,
923
+ onPress,
924
+ onKeyDown,
925
+ onKeyUp,
926
+ onBlur,
927
+ ...rest
928
+ } = _temp3 === void 0 ? {} : _temp3;
929
+
930
+ const {
931
+ isOpen
932
+ } = _this.getState();
933
+
934
+ const enabledEventHandlers = {
949
935
  onClick: callAllEventHandlers(onClick, _this.buttonHandleClick),
950
936
  onKeyDown: callAllEventHandlers(onKeyDown, _this.buttonHandleKeyDown),
951
937
  onKeyUp: callAllEventHandlers(onKeyUp, _this.buttonHandleKeyUp),
952
938
  onBlur: callAllEventHandlers(onBlur, _this.buttonHandleBlur)
953
939
  };
954
- var eventHandlers = rest.disabled ? {} : enabledEventHandlers;
955
- return _extends__default['default']({
940
+ const eventHandlers = rest.disabled ? {} : enabledEventHandlers;
941
+ return {
956
942
  type: 'button',
957
943
  role: 'button',
958
944
  'aria-label': isOpen ? 'close menu' : 'open menu',
959
945
  'aria-haspopup': true,
960
- 'data-toggle': true
961
- }, eventHandlers, rest);
946
+ 'data-toggle': true,
947
+ ...eventHandlers,
948
+ ...rest
949
+ };
962
950
  };
963
951
 
964
- _this.buttonHandleKeyUp = function (event) {
952
+ this.buttonHandleKeyUp = event => {
965
953
  // Prevent click event from emitting in Firefox
966
954
  event.preventDefault();
967
955
  };
968
956
 
969
- _this.buttonHandleKeyDown = function (event) {
970
- var key = normalizeArrowKey(event);
957
+ this.buttonHandleKeyDown = event => {
958
+ const key = normalizeArrowKey(event);
971
959
 
972
- if (_this.buttonKeyDownHandlers[key]) {
973
- _this.buttonKeyDownHandlers[key].call(_assertThisInitialized__default['default'](_this), event);
960
+ if (this.buttonKeyDownHandlers[key]) {
961
+ this.buttonKeyDownHandlers[key].call(this, event);
974
962
  }
975
963
  };
976
964
 
977
- _this.buttonHandleClick = function (event) {
965
+ this.buttonHandleClick = event => {
978
966
  event.preventDefault(); // handle odd case for Safari and Firefox which
979
967
  // don't give the button the focus properly.
980
968
 
981
969
  /* istanbul ignore if (can't reasonably test this) */
982
970
 
983
- if (_this.props.environment.document.activeElement === _this.props.environment.document.body) {
971
+ if (this.props.environment.document.activeElement === this.props.environment.document.body) {
984
972
  event.target.focus();
985
973
  } // to simplify testing components that use downshift, we'll not wrap this in a setTimeout
986
974
  // if the NODE_ENV is test. With the proper build system, this should be dead code eliminated
@@ -988,69 +976,71 @@ var Downshift = /*#__PURE__*/function () {
988
976
 
989
977
 
990
978
  if (process.env.NODE_ENV === 'test') {
991
- _this.toggleMenu({
979
+ this.toggleMenu({
992
980
  type: clickButton
993
981
  });
994
982
  } else {
995
983
  // Ensure that toggle of menu occurs after the potential blur event in iOS
996
- _this.internalSetTimeout(function () {
997
- return _this.toggleMenu({
998
- type: clickButton
999
- });
1000
- });
984
+ this.internalSetTimeout(() => this.toggleMenu({
985
+ type: clickButton
986
+ }));
1001
987
  }
1002
988
  };
1003
989
 
1004
- _this.buttonHandleBlur = function (event) {
1005
- var blurTarget = event.target; // Save blur target for comparison with activeElement later
990
+ this.buttonHandleBlur = event => {
991
+ const blurTarget = event.target; // Save blur target for comparison with activeElement later
1006
992
  // Need setTimeout, so that when the user presses Tab, the activeElement is the next focused element, not body element
1007
993
 
1008
- _this.internalSetTimeout(function () {
1009
- 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)
994
+ this.internalSetTimeout(() => {
995
+ 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)
1010
996
  ) {
1011
- _this.reset({
997
+ this.reset({
1012
998
  type: blurButton
1013
999
  });
1014
1000
  }
1015
1001
  });
1016
1002
  };
1017
1003
 
1018
- _this.getLabelProps = function (props) {
1019
- return _extends__default['default']({
1020
- htmlFor: _this.inputId,
1021
- id: _this.labelId
1022
- }, props);
1004
+ this.getLabelProps = props => {
1005
+ return {
1006
+ htmlFor: this.inputId,
1007
+ id: this.labelId,
1008
+ ...props
1009
+ };
1023
1010
  };
1024
1011
 
1025
- _this.getInputProps = function (_temp4) {
1026
- var _ref4 = _temp4 === void 0 ? {} : _temp4,
1027
- onKeyDown = _ref4.onKeyDown,
1028
- onBlur = _ref4.onBlur,
1029
- onChange = _ref4.onChange,
1030
- onInput = _ref4.onInput;
1031
- _ref4.onChangeText;
1032
- var rest = _objectWithoutPropertiesLoose__default['default'](_ref4, _excluded3$2);
1033
-
1034
- var onChangeKey;
1035
- var eventHandlers = {};
1012
+ this.getInputProps = function (_temp4) {
1013
+ let {
1014
+ onKeyDown,
1015
+ onBlur,
1016
+ onChange,
1017
+ onInput,
1018
+ onChangeText,
1019
+ ...rest
1020
+ } = _temp4 === void 0 ? {} : _temp4;
1021
+ let onChangeKey;
1022
+ let eventHandlers = {};
1036
1023
  /* istanbul ignore next (preact) */
1037
1024
 
1038
1025
  {
1039
1026
  onChangeKey = 'onInput';
1040
1027
  }
1041
1028
 
1042
- var _this$getState6 = _this.getState(),
1043
- inputValue = _this$getState6.inputValue,
1044
- isOpen = _this$getState6.isOpen,
1045
- highlightedIndex = _this$getState6.highlightedIndex;
1029
+ const {
1030
+ inputValue,
1031
+ isOpen,
1032
+ highlightedIndex
1033
+ } = _this.getState();
1046
1034
 
1047
1035
  if (!rest.disabled) {
1048
- var _eventHandlers;
1049
-
1050
- eventHandlers = (_eventHandlers = {}, _eventHandlers[onChangeKey] = callAllEventHandlers(onChange, onInput, _this.inputHandleChange), _eventHandlers.onKeyDown = callAllEventHandlers(onKeyDown, _this.inputHandleKeyDown), _eventHandlers.onBlur = callAllEventHandlers(onBlur, _this.inputHandleBlur), _eventHandlers);
1036
+ eventHandlers = {
1037
+ [onChangeKey]: callAllEventHandlers(onChange, onInput, _this.inputHandleChange),
1038
+ onKeyDown: callAllEventHandlers(onKeyDown, _this.inputHandleKeyDown),
1039
+ onBlur: callAllEventHandlers(onBlur, _this.inputHandleBlur)
1040
+ };
1051
1041
  }
1052
1042
 
1053
- return _extends__default['default']({
1043
+ return {
1054
1044
  'aria-autocomplete': 'list',
1055
1045
  'aria-activedescendant': isOpen && typeof highlightedIndex === 'number' && highlightedIndex >= 0 ? _this.getItemId(highlightedIndex) : null,
1056
1046
  'aria-controls': isOpen ? _this.menuId : null,
@@ -1059,77 +1049,79 @@ var Downshift = /*#__PURE__*/function () {
1059
1049
  // revert back since autocomplete="nope" is ignored on latest Chrome and Opera
1060
1050
  autoComplete: 'off',
1061
1051
  value: inputValue,
1062
- id: _this.inputId
1063
- }, eventHandlers, rest);
1052
+ id: _this.inputId,
1053
+ ...eventHandlers,
1054
+ ...rest
1055
+ };
1064
1056
  };
1065
1057
 
1066
- _this.inputHandleKeyDown = function (event) {
1067
- var key = normalizeArrowKey(event);
1058
+ this.inputHandleKeyDown = event => {
1059
+ const key = normalizeArrowKey(event);
1068
1060
 
1069
- if (key && _this.inputKeyDownHandlers[key]) {
1070
- _this.inputKeyDownHandlers[key].call(_assertThisInitialized__default['default'](_this), event);
1061
+ if (key && this.inputKeyDownHandlers[key]) {
1062
+ this.inputKeyDownHandlers[key].call(this, event);
1071
1063
  }
1072
1064
  };
1073
1065
 
1074
- _this.inputHandleChange = function (event) {
1075
- _this.internalSetState({
1066
+ this.inputHandleChange = event => {
1067
+ this.internalSetState({
1076
1068
  type: changeInput,
1077
1069
  isOpen: true,
1078
1070
  inputValue: event.target.value,
1079
- highlightedIndex: _this.props.defaultHighlightedIndex
1071
+ highlightedIndex: this.props.defaultHighlightedIndex
1080
1072
  });
1081
1073
  };
1082
1074
 
1083
- _this.inputHandleBlur = function () {
1075
+ this.inputHandleBlur = () => {
1084
1076
  // Need setTimeout, so that when the user presses Tab, the activeElement is the next focused element, not the body element
1085
- _this.internalSetTimeout(function () {
1086
- 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);
1077
+ this.internalSetTimeout(() => {
1078
+ 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);
1087
1079
 
1088
- if (!_this.isMouseDown && !downshiftButtonIsActive) {
1089
- _this.reset({
1080
+ if (!this.isMouseDown && !downshiftButtonIsActive) {
1081
+ this.reset({
1090
1082
  type: blurInput
1091
1083
  });
1092
1084
  }
1093
1085
  });
1094
1086
  };
1095
1087
 
1096
- _this.menuRef = function (node) {
1097
- _this._menuNode = node;
1088
+ this.menuRef = node => {
1089
+ this._menuNode = node;
1098
1090
  };
1099
1091
 
1100
- _this.getMenuProps = function (_temp5, _temp6) {
1101
- var _extends3;
1102
-
1103
- var _ref5 = _temp5 === void 0 ? {} : _temp5,
1104
- _ref5$refKey = _ref5.refKey,
1105
- refKey = _ref5$refKey === void 0 ? 'ref' : _ref5$refKey,
1106
- ref = _ref5.ref,
1107
- props = _objectWithoutPropertiesLoose__default['default'](_ref5, _excluded4$1);
1108
-
1109
- var _ref6 = _temp6 === void 0 ? {} : _temp6,
1110
- _ref6$suppressRefErro = _ref6.suppressRefError,
1111
- suppressRefError = _ref6$suppressRefErro === void 0 ? false : _ref6$suppressRefErro;
1112
-
1092
+ this.getMenuProps = function (_temp5, _temp6) {
1093
+ let {
1094
+ refKey = 'ref',
1095
+ ref,
1096
+ ...props
1097
+ } = _temp5 === void 0 ? {} : _temp5;
1098
+ let {
1099
+ suppressRefError = false
1100
+ } = _temp6 === void 0 ? {} : _temp6;
1113
1101
  _this.getMenuProps.called = true;
1114
1102
  _this.getMenuProps.refKey = refKey;
1115
1103
  _this.getMenuProps.suppressRefError = suppressRefError;
1116
- 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);
1104
+ return {
1105
+ [refKey]: handleRefs(ref, _this.menuRef),
1106
+ role: 'listbox',
1107
+ 'aria-labelledby': props && props['aria-label'] ? null : _this.labelId,
1108
+ id: _this.menuId,
1109
+ ...props
1110
+ };
1117
1111
  };
1118
1112
 
1119
- _this.getItemProps = function (_temp7) {
1120
- var _enabledEventHandlers;
1121
-
1122
- var _ref7 = _temp7 === void 0 ? {} : _temp7,
1123
- onMouseMove = _ref7.onMouseMove,
1124
- onMouseDown = _ref7.onMouseDown,
1125
- onClick = _ref7.onClick;
1126
- _ref7.onPress;
1127
- var index = _ref7.index,
1128
- _ref7$item = _ref7.item,
1129
- item = _ref7$item === void 0 ? process.env.NODE_ENV === 'production' ?
1130
- /* istanbul ignore next */
1131
- undefined : requiredProp('getItemProps', 'item') : _ref7$item,
1132
- rest = _objectWithoutPropertiesLoose__default['default'](_ref7, _excluded5$1);
1113
+ this.getItemProps = function (_temp7) {
1114
+ let {
1115
+ onMouseMove,
1116
+ onMouseDown,
1117
+ onClick,
1118
+ onPress,
1119
+ index,
1120
+ item = process.env.NODE_ENV === 'production' ?
1121
+ /* istanbul ignore next */
1122
+ undefined : requiredProp('getItemProps', 'item'),
1123
+ ...rest
1124
+ } = _temp7 === void 0 ? {} : _temp7;
1133
1125
 
1134
1126
  if (index === undefined) {
1135
1127
  _this.items.push(item);
@@ -1139,13 +1131,13 @@ var Downshift = /*#__PURE__*/function () {
1139
1131
  _this.items[index] = item;
1140
1132
  }
1141
1133
 
1142
- var onSelectKey = 'onClick';
1143
- var customClickHandler = onClick;
1144
- var enabledEventHandlers = (_enabledEventHandlers = {
1134
+ const onSelectKey = 'onClick';
1135
+ const customClickHandler = onClick;
1136
+ const enabledEventHandlers = {
1145
1137
  // onMouseMove is used over onMouseEnter here. onMouseMove
1146
1138
  // is only triggered on actual mouse movement while onMouseEnter
1147
1139
  // can fire on DOM changes, interrupting keyboard navigation
1148
- onMouseMove: callAllEventHandlers(onMouseMove, function () {
1140
+ onMouseMove: callAllEventHandlers(onMouseMove, () => {
1149
1141
  if (index === _this.getState().highlightedIndex) {
1150
1142
  return;
1151
1143
  }
@@ -1160,72 +1152,81 @@ var Downshift = /*#__PURE__*/function () {
1160
1152
 
1161
1153
  _this.avoidScrolling = true;
1162
1154
 
1163
- _this.internalSetTimeout(function () {
1164
- return _this.avoidScrolling = false;
1165
- }, 250);
1155
+ _this.internalSetTimeout(() => _this.avoidScrolling = false, 250);
1166
1156
  }),
1167
- onMouseDown: callAllEventHandlers(onMouseDown, function (event) {
1157
+ onMouseDown: callAllEventHandlers(onMouseDown, event => {
1168
1158
  // This prevents the activeElement from being changed
1169
1159
  // to the item so it can remain with the current activeElement
1170
1160
  // which is a more common use case.
1171
1161
  event.preventDefault();
1162
+ }),
1163
+ [onSelectKey]: callAllEventHandlers(customClickHandler, () => {
1164
+ _this.selectItemAtIndex(index, {
1165
+ type: clickItem
1166
+ });
1172
1167
  })
1173
- }, _enabledEventHandlers[onSelectKey] = callAllEventHandlers(customClickHandler, function () {
1174
- _this.selectItemAtIndex(index, {
1175
- type: clickItem
1176
- });
1177
- }), _enabledEventHandlers); // Passing down the onMouseDown handler to prevent redirect
1168
+ }; // Passing down the onMouseDown handler to prevent redirect
1178
1169
  // of the activeElement if clicking on disabled items
1179
1170
 
1180
- var eventHandlers = rest.disabled ? {
1171
+ const eventHandlers = rest.disabled ? {
1181
1172
  onMouseDown: enabledEventHandlers.onMouseDown
1182
1173
  } : enabledEventHandlers;
1183
- return _extends__default['default']({
1174
+ return {
1184
1175
  id: _this.getItemId(index),
1185
1176
  role: 'option',
1186
- 'aria-selected': _this.getState().highlightedIndex === index
1187
- }, eventHandlers, rest);
1177
+ 'aria-selected': _this.getState().highlightedIndex === index,
1178
+ ...eventHandlers,
1179
+ ...rest
1180
+ };
1188
1181
  };
1189
1182
 
1190
- _this.clearItems = function () {
1191
- _this.items = [];
1183
+ this.clearItems = () => {
1184
+ this.items = [];
1192
1185
  };
1193
1186
 
1194
- _this.reset = function (otherStateToSet, cb) {
1187
+ this.reset = function (otherStateToSet, cb) {
1195
1188
  if (otherStateToSet === void 0) {
1196
1189
  otherStateToSet = {};
1197
1190
  }
1198
1191
 
1199
1192
  otherStateToSet = pickState(otherStateToSet);
1200
1193
 
1201
- _this.internalSetState(function (_ref8) {
1202
- var selectedItem = _ref8.selectedItem;
1203
- return _extends__default['default']({
1194
+ _this.internalSetState(_ref => {
1195
+ let {
1196
+ selectedItem
1197
+ } = _ref;
1198
+ return {
1204
1199
  isOpen: _this.props.defaultIsOpen,
1205
1200
  highlightedIndex: _this.props.defaultHighlightedIndex,
1206
- inputValue: _this.props.itemToString(selectedItem)
1207
- }, otherStateToSet);
1201
+ inputValue: _this.props.itemToString(selectedItem),
1202
+ ...otherStateToSet
1203
+ };
1208
1204
  }, cb);
1209
1205
  };
1210
1206
 
1211
- _this.toggleMenu = function (otherStateToSet, cb) {
1207
+ this.toggleMenu = function (otherStateToSet, cb) {
1212
1208
  if (otherStateToSet === void 0) {
1213
1209
  otherStateToSet = {};
1214
1210
  }
1215
1211
 
1216
1212
  otherStateToSet = pickState(otherStateToSet);
1217
1213
 
1218
- _this.internalSetState(function (_ref9) {
1219
- var isOpen = _ref9.isOpen;
1220
- return _extends__default['default']({
1221
- isOpen: !isOpen
1222
- }, isOpen && {
1223
- highlightedIndex: _this.props.defaultHighlightedIndex
1224
- }, otherStateToSet);
1225
- }, function () {
1226
- var _this$getState7 = _this.getState(),
1227
- isOpen = _this$getState7.isOpen,
1228
- highlightedIndex = _this$getState7.highlightedIndex;
1214
+ _this.internalSetState(_ref2 => {
1215
+ let {
1216
+ isOpen
1217
+ } = _ref2;
1218
+ return {
1219
+ isOpen: !isOpen,
1220
+ ...(isOpen && {
1221
+ highlightedIndex: _this.props.defaultHighlightedIndex
1222
+ }),
1223
+ ...otherStateToSet
1224
+ };
1225
+ }, () => {
1226
+ const {
1227
+ isOpen,
1228
+ highlightedIndex
1229
+ } = _this.getState();
1229
1230
 
1230
1231
  if (isOpen) {
1231
1232
  if (_this.getItemCount() > 0 && typeof highlightedIndex === 'number') {
@@ -1237,70 +1238,63 @@ var Downshift = /*#__PURE__*/function () {
1237
1238
  });
1238
1239
  };
1239
1240
 
1240
- _this.openMenu = function (cb) {
1241
- _this.internalSetState({
1241
+ this.openMenu = cb => {
1242
+ this.internalSetState({
1242
1243
  isOpen: true
1243
1244
  }, cb);
1244
1245
  };
1245
1246
 
1246
- _this.closeMenu = function (cb) {
1247
- _this.internalSetState({
1247
+ this.closeMenu = cb => {
1248
+ this.internalSetState({
1248
1249
  isOpen: false
1249
1250
  }, cb);
1250
1251
  };
1251
1252
 
1252
- _this.updateStatus = debounce(function () {
1253
- var state = _this.getState();
1254
-
1255
- var item = _this.items[state.highlightedIndex];
1256
-
1257
- var resultCount = _this.getItemCount();
1258
-
1259
- var status = _this.props.getA11yStatusMessage(_extends__default['default']({
1260
- itemToString: _this.props.itemToString,
1261
- previousResultCount: _this.previousResultCount,
1262
- resultCount: resultCount,
1263
- highlightedItem: item
1264
- }, state));
1265
-
1266
- _this.previousResultCount = resultCount;
1267
- setStatus(status, _this.props.environment.document);
1253
+ this.updateStatus = debounce(() => {
1254
+ const state = this.getState();
1255
+ const item = this.items[state.highlightedIndex];
1256
+ const resultCount = this.getItemCount();
1257
+ const status = this.props.getA11yStatusMessage({
1258
+ itemToString: this.props.itemToString,
1259
+ previousResultCount: this.previousResultCount,
1260
+ resultCount,
1261
+ highlightedItem: item,
1262
+ ...state
1263
+ });
1264
+ this.previousResultCount = resultCount;
1265
+ setStatus(status, this.props.environment.document);
1268
1266
  }, 200);
1269
-
1270
- var _this$props = _this.props,
1271
- defaultHighlightedIndex = _this$props.defaultHighlightedIndex,
1272
- _this$props$initialHi = _this$props.initialHighlightedIndex,
1273
- _highlightedIndex = _this$props$initialHi === void 0 ? defaultHighlightedIndex : _this$props$initialHi,
1274
- defaultIsOpen = _this$props.defaultIsOpen,
1275
- _this$props$initialIs = _this$props.initialIsOpen,
1276
- _isOpen = _this$props$initialIs === void 0 ? defaultIsOpen : _this$props$initialIs,
1277
- _this$props$initialIn = _this$props.initialInputValue,
1278
- _inputValue = _this$props$initialIn === void 0 ? '' : _this$props$initialIn,
1279
- _this$props$initialSe = _this$props.initialSelectedItem,
1280
- _selectedItem = _this$props$initialSe === void 0 ? null : _this$props$initialSe;
1281
-
1282
- var _state = _this.getState({
1267
+ // fancy destructuring + defaults + aliases
1268
+ // this basically says each value of state should either be set to
1269
+ // the initial value or the default value if the initial value is not provided
1270
+ const {
1271
+ defaultHighlightedIndex,
1272
+ initialHighlightedIndex: _highlightedIndex = defaultHighlightedIndex,
1273
+ defaultIsOpen,
1274
+ initialIsOpen: _isOpen = defaultIsOpen,
1275
+ initialInputValue: _inputValue = '',
1276
+ initialSelectedItem: _selectedItem = null
1277
+ } = this.props;
1278
+
1279
+ const _state = this.getState({
1283
1280
  highlightedIndex: _highlightedIndex,
1284
1281
  isOpen: _isOpen,
1285
1282
  inputValue: _inputValue,
1286
1283
  selectedItem: _selectedItem
1287
1284
  });
1288
1285
 
1289
- if (_state.selectedItem != null && _this.props.initialInputValue === undefined) {
1290
- _state.inputValue = _this.props.itemToString(_state.selectedItem);
1286
+ if (_state.selectedItem != null && this.props.initialInputValue === undefined) {
1287
+ _state.inputValue = this.props.itemToString(_state.selectedItem);
1291
1288
  }
1292
1289
 
1293
- _this.state = _state;
1294
- return _this;
1290
+ this.state = _state;
1295
1291
  }
1296
1292
 
1297
- var _proto = Downshift.prototype;
1298
-
1299
1293
  /**
1300
1294
  * Clear all running timeouts
1301
1295
  */
1302
- _proto.internalClearTimeouts = function internalClearTimeouts() {
1303
- this.timeoutIds.forEach(function (id) {
1296
+ internalClearTimeouts() {
1297
+ this.timeoutIds.forEach(id => {
1304
1298
  clearTimeout(id);
1305
1299
  });
1306
1300
  this.timeoutIds = [];
@@ -1314,22 +1308,22 @@ var Downshift = /*#__PURE__*/function () {
1314
1308
  * @param {Object} stateToMerge defaults to this.state
1315
1309
  * @return {Object} the state
1316
1310
  */
1317
- ;
1318
1311
 
1319
- _proto.getState = function getState$1(stateToMerge) {
1312
+
1313
+ getState(stateToMerge) {
1320
1314
  if (stateToMerge === void 0) {
1321
1315
  stateToMerge = this.state;
1322
1316
  }
1323
1317
 
1324
1318
  return getState(stateToMerge, this.props);
1325
- };
1319
+ }
1326
1320
 
1327
- _proto.getItemCount = function getItemCount() {
1321
+ getItemCount() {
1328
1322
  // things read better this way. They're in priority order:
1329
1323
  // 1. `this.itemCount`
1330
1324
  // 2. `this.props.itemCount`
1331
1325
  // 3. `this.items.length`
1332
- var itemCount = this.items.length;
1326
+ let itemCount = this.items.length;
1333
1327
 
1334
1328
  if (this.itemCount != null) {
1335
1329
  itemCount = this.itemCount;
@@ -1338,102 +1332,102 @@ var Downshift = /*#__PURE__*/function () {
1338
1332
  }
1339
1333
 
1340
1334
  return itemCount;
1341
- };
1335
+ }
1342
1336
 
1343
- _proto.getItemNodeFromIndex = function getItemNodeFromIndex(index) {
1337
+ getItemNodeFromIndex(index) {
1344
1338
  return this.props.environment.document.getElementById(this.getItemId(index));
1345
- };
1339
+ }
1346
1340
 
1347
- _proto.scrollHighlightedItemIntoView = function scrollHighlightedItemIntoView() {
1341
+ scrollHighlightedItemIntoView() {
1348
1342
  /* istanbul ignore else (react-native) */
1349
1343
  {
1350
- var node = this.getItemNodeFromIndex(this.getState().highlightedIndex);
1344
+ const node = this.getItemNodeFromIndex(this.getState().highlightedIndex);
1351
1345
  this.props.scrollIntoView(node, this._menuNode);
1352
1346
  }
1353
- };
1354
-
1355
- _proto.moveHighlightedIndex = function moveHighlightedIndex(amount, otherStateToSet) {
1356
- var _this6 = this;
1357
-
1358
- var itemCount = this.getItemCount();
1347
+ }
1359
1348
 
1360
- var _this$getState8 = this.getState(),
1361
- highlightedIndex = _this$getState8.highlightedIndex;
1349
+ moveHighlightedIndex(amount, otherStateToSet) {
1350
+ const itemCount = this.getItemCount();
1351
+ const {
1352
+ highlightedIndex
1353
+ } = this.getState();
1362
1354
 
1363
1355
  if (itemCount > 0) {
1364
- var nextHighlightedIndex = getNextWrappingIndex(amount, highlightedIndex, itemCount, function (index) {
1365
- return _this6.getItemNodeFromIndex(index);
1366
- });
1356
+ const nextHighlightedIndex = getNextWrappingIndex(amount, highlightedIndex, itemCount, index => this.getItemNodeFromIndex(index));
1367
1357
  this.setHighlightedIndex(nextHighlightedIndex, otherStateToSet);
1368
1358
  }
1369
- };
1359
+ }
1370
1360
 
1371
- _proto.getStateAndHelpers = function getStateAndHelpers() {
1372
- var _this$getState9 = this.getState(),
1373
- highlightedIndex = _this$getState9.highlightedIndex,
1374
- inputValue = _this$getState9.inputValue,
1375
- selectedItem = _this$getState9.selectedItem,
1376
- isOpen = _this$getState9.isOpen;
1377
-
1378
- var itemToString = this.props.itemToString;
1379
- var id = this.id;
1380
- var getRootProps = this.getRootProps,
1381
- getToggleButtonProps = this.getToggleButtonProps,
1382
- getLabelProps = this.getLabelProps,
1383
- getMenuProps = this.getMenuProps,
1384
- getInputProps = this.getInputProps,
1385
- getItemProps = this.getItemProps,
1386
- openMenu = this.openMenu,
1387
- closeMenu = this.closeMenu,
1388
- toggleMenu = this.toggleMenu,
1389
- selectItem = this.selectItem,
1390
- selectItemAtIndex = this.selectItemAtIndex,
1391
- selectHighlightedItem = this.selectHighlightedItem,
1392
- setHighlightedIndex = this.setHighlightedIndex,
1393
- clearSelection = this.clearSelection,
1394
- clearItems = this.clearItems,
1395
- reset = this.reset,
1396
- setItemCount = this.setItemCount,
1397
- unsetItemCount = this.unsetItemCount,
1398
- setState = this.internalSetState;
1361
+ getStateAndHelpers() {
1362
+ const {
1363
+ highlightedIndex,
1364
+ inputValue,
1365
+ selectedItem,
1366
+ isOpen
1367
+ } = this.getState();
1368
+ const {
1369
+ itemToString
1370
+ } = this.props;
1371
+ const {
1372
+ id
1373
+ } = this;
1374
+ const {
1375
+ getRootProps,
1376
+ getToggleButtonProps,
1377
+ getLabelProps,
1378
+ getMenuProps,
1379
+ getInputProps,
1380
+ getItemProps,
1381
+ openMenu,
1382
+ closeMenu,
1383
+ toggleMenu,
1384
+ selectItem,
1385
+ selectItemAtIndex,
1386
+ selectHighlightedItem,
1387
+ setHighlightedIndex,
1388
+ clearSelection,
1389
+ clearItems,
1390
+ reset,
1391
+ setItemCount,
1392
+ unsetItemCount,
1393
+ internalSetState: setState
1394
+ } = this;
1399
1395
  return {
1400
1396
  // prop getters
1401
- getRootProps: getRootProps,
1402
- getToggleButtonProps: getToggleButtonProps,
1403
- getLabelProps: getLabelProps,
1404
- getMenuProps: getMenuProps,
1405
- getInputProps: getInputProps,
1406
- getItemProps: getItemProps,
1397
+ getRootProps,
1398
+ getToggleButtonProps,
1399
+ getLabelProps,
1400
+ getMenuProps,
1401
+ getInputProps,
1402
+ getItemProps,
1407
1403
  // actions
1408
- reset: reset,
1409
- openMenu: openMenu,
1410
- closeMenu: closeMenu,
1411
- toggleMenu: toggleMenu,
1412
- selectItem: selectItem,
1413
- selectItemAtIndex: selectItemAtIndex,
1414
- selectHighlightedItem: selectHighlightedItem,
1415
- setHighlightedIndex: setHighlightedIndex,
1416
- clearSelection: clearSelection,
1417
- clearItems: clearItems,
1418
- setItemCount: setItemCount,
1419
- unsetItemCount: unsetItemCount,
1420
- setState: setState,
1404
+ reset,
1405
+ openMenu,
1406
+ closeMenu,
1407
+ toggleMenu,
1408
+ selectItem,
1409
+ selectItemAtIndex,
1410
+ selectHighlightedItem,
1411
+ setHighlightedIndex,
1412
+ clearSelection,
1413
+ clearItems,
1414
+ setItemCount,
1415
+ unsetItemCount,
1416
+ setState,
1421
1417
  // props
1422
- itemToString: itemToString,
1418
+ itemToString,
1423
1419
  // derived
1424
- id: id,
1420
+ id,
1425
1421
  // state
1426
- highlightedIndex: highlightedIndex,
1427
- inputValue: inputValue,
1428
- isOpen: isOpen,
1429
- selectedItem: selectedItem
1422
+ highlightedIndex,
1423
+ inputValue,
1424
+ isOpen,
1425
+ selectedItem
1430
1426
  };
1431
1427
  } //////////////////////////// ROOT
1432
- ;
1433
1428
 
1434
- _proto.componentDidMount = function componentDidMount() {
1435
- var _this7 = this;
1436
1429
 
1430
+ componentDidMount() {
1437
1431
  /* istanbul ignore if (react-native) */
1438
1432
  if (process.env.NODE_ENV !== 'production' && !false && this.getMenuProps.called && !this.getMenuProps.suppressRefError) {
1439
1433
  validateGetMenuPropsCalledCorrectly(this._menuNode, this.getMenuProps);
@@ -1447,22 +1441,20 @@ var Downshift = /*#__PURE__*/function () {
1447
1441
  // down long enough for the list to disappear (because the blur event fires on the input)
1448
1442
  // this.isMouseDown is used in the blur handler on the input to determine whether the blur event should
1449
1443
  // trigger hiding the menu.
1450
- var onMouseDown = function onMouseDown() {
1451
- _this7.isMouseDown = true;
1444
+ const onMouseDown = () => {
1445
+ this.isMouseDown = true;
1452
1446
  };
1453
1447
 
1454
- var onMouseUp = function onMouseUp(event) {
1455
- _this7.isMouseDown = false; // if the target element or the activeElement is within a downshift node
1448
+ const onMouseUp = event => {
1449
+ this.isMouseDown = false; // if the target element or the activeElement is within a downshift node
1456
1450
  // then we don't want to reset downshift
1457
1451
 
1458
- var contextWithinDownshift = targetWithinDownshift(event.target, [_this7._rootNode, _this7._menuNode], _this7.props.environment);
1452
+ const contextWithinDownshift = targetWithinDownshift(event.target, [this._rootNode, this._menuNode], this.props.environment);
1459
1453
 
1460
- if (!contextWithinDownshift && _this7.getState().isOpen) {
1461
- _this7.reset({
1454
+ if (!contextWithinDownshift && this.getState().isOpen) {
1455
+ this.reset({
1462
1456
  type: mouseUp
1463
- }, function () {
1464
- return _this7.props.onOuterClick(_this7.getStateAndHelpers());
1465
- });
1457
+ }, () => this.props.onOuterClick(this.getStateAndHelpers()));
1466
1458
  }
1467
1459
  }; // Touching an element in iOS gives focus and hover states, but touching out of
1468
1460
  // the element will remove hover, and persist the focus state, resulting in the
@@ -1472,38 +1464,36 @@ var Downshift = /*#__PURE__*/function () {
1472
1464
  // but not if the user is swiping
1473
1465
 
1474
1466
 
1475
- var onTouchStart = function onTouchStart() {
1476
- _this7.isTouchMove = false;
1467
+ const onTouchStart = () => {
1468
+ this.isTouchMove = false;
1477
1469
  };
1478
1470
 
1479
- var onTouchMove = function onTouchMove() {
1480
- _this7.isTouchMove = true;
1471
+ const onTouchMove = () => {
1472
+ this.isTouchMove = true;
1481
1473
  };
1482
1474
 
1483
- var onTouchEnd = function onTouchEnd(event) {
1484
- var contextWithinDownshift = targetWithinDownshift(event.target, [_this7._rootNode, _this7._menuNode], _this7.props.environment, false);
1475
+ const onTouchEnd = event => {
1476
+ const contextWithinDownshift = targetWithinDownshift(event.target, [this._rootNode, this._menuNode], this.props.environment, false);
1485
1477
 
1486
- if (!_this7.isTouchMove && !contextWithinDownshift && _this7.getState().isOpen) {
1487
- _this7.reset({
1478
+ if (!this.isTouchMove && !contextWithinDownshift && this.getState().isOpen) {
1479
+ this.reset({
1488
1480
  type: touchEnd
1489
- }, function () {
1490
- return _this7.props.onOuterClick(_this7.getStateAndHelpers());
1491
- });
1481
+ }, () => this.props.onOuterClick(this.getStateAndHelpers()));
1492
1482
  }
1493
1483
  };
1494
1484
 
1495
- var environment = this.props.environment;
1485
+ const {
1486
+ environment
1487
+ } = this.props;
1496
1488
  environment.addEventListener('mousedown', onMouseDown);
1497
1489
  environment.addEventListener('mouseup', onMouseUp);
1498
1490
  environment.addEventListener('touchstart', onTouchStart);
1499
1491
  environment.addEventListener('touchmove', onTouchMove);
1500
1492
  environment.addEventListener('touchend', onTouchEnd);
1501
1493
 
1502
- this.cleanup = function () {
1503
- _this7.internalClearTimeouts();
1504
-
1505
- _this7.updateStatus.cancel();
1506
-
1494
+ this.cleanup = () => {
1495
+ this.internalClearTimeouts();
1496
+ this.updateStatus.cancel();
1507
1497
  environment.removeEventListener('mousedown', onMouseDown);
1508
1498
  environment.removeEventListener('mouseup', onMouseUp);
1509
1499
  environment.removeEventListener('touchstart', onTouchStart);
@@ -1511,21 +1501,21 @@ var Downshift = /*#__PURE__*/function () {
1511
1501
  environment.removeEventListener('touchend', onTouchEnd);
1512
1502
  };
1513
1503
  }
1514
- };
1515
-
1516
- _proto.shouldScroll = function shouldScroll(prevState, prevProps) {
1517
- var _ref10 = this.props.highlightedIndex === undefined ? this.getState() : this.props,
1518
- currentHighlightedIndex = _ref10.highlightedIndex;
1519
-
1520
- var _ref11 = prevProps.highlightedIndex === undefined ? prevState : prevProps,
1521
- prevHighlightedIndex = _ref11.highlightedIndex;
1504
+ }
1522
1505
 
1523
- var scrollWhenOpen = currentHighlightedIndex && this.getState().isOpen && !prevState.isOpen;
1524
- var scrollWhenNavigating = currentHighlightedIndex !== prevHighlightedIndex;
1506
+ shouldScroll(prevState, prevProps) {
1507
+ const {
1508
+ highlightedIndex: currentHighlightedIndex
1509
+ } = this.props.highlightedIndex === undefined ? this.getState() : this.props;
1510
+ const {
1511
+ highlightedIndex: prevHighlightedIndex
1512
+ } = prevProps.highlightedIndex === undefined ? prevState : prevProps;
1513
+ const scrollWhenOpen = currentHighlightedIndex && this.getState().isOpen && !prevState.isOpen;
1514
+ const scrollWhenNavigating = currentHighlightedIndex !== prevHighlightedIndex;
1525
1515
  return scrollWhenOpen || scrollWhenNavigating;
1526
- };
1516
+ }
1527
1517
 
1528
- _proto.componentDidUpdate = function componentDidUpdate(prevProps, prevState) {
1518
+ componentDidUpdate(prevProps, prevState) {
1529
1519
  if (process.env.NODE_ENV !== 'production') {
1530
1520
  validateControlledUnchanged(this.state, prevProps, this.props);
1531
1521
  /* istanbul ignore if (react-native) */
@@ -1551,14 +1541,14 @@ var Downshift = /*#__PURE__*/function () {
1551
1541
  {
1552
1542
  this.updateStatus();
1553
1543
  }
1554
- };
1544
+ }
1555
1545
 
1556
- _proto.componentWillUnmount = function componentWillUnmount() {
1546
+ componentWillUnmount() {
1557
1547
  this.cleanup(); // avoids memory leak
1558
- };
1548
+ }
1559
1549
 
1560
- _proto.render = function render() {
1561
- var children = unwrapArray(this.props.children, noop); // because the items are rerendered every time we call the children
1550
+ render() {
1551
+ const children = unwrapArray(this.props.children, noop); // because the items are rerendered every time we call the children
1562
1552
  // we clear this out each render and it will be populated again as
1563
1553
  // getItemProps is called.
1564
1554
 
@@ -1578,7 +1568,7 @@ var Downshift = /*#__PURE__*/function () {
1578
1568
  this.getLabelProps.called = false; // and something similar for getInputProps
1579
1569
 
1580
1570
  this.getInputProps.called = false;
1581
- var element = unwrapArray(children(this.getStateAndHelpers()));
1571
+ const element = unwrapArray(children(this.getStateAndHelpers()));
1582
1572
 
1583
1573
  if (!element) {
1584
1574
  return null;
@@ -1607,16 +1597,15 @@ var Downshift = /*#__PURE__*/function () {
1607
1597
 
1608
1598
 
1609
1599
  return undefined;
1610
- };
1600
+ }
1611
1601
 
1612
- return Downshift;
1613
- }(preact.Component);
1602
+ }
1614
1603
 
1615
1604
  Downshift.defaultProps = {
1616
1605
  defaultHighlightedIndex: null,
1617
1606
  defaultIsOpen: false,
1618
1607
  getA11yStatusMessage: getA11yStatusMessage$1,
1619
- itemToString: function itemToString(i) {
1608
+ itemToString: i => {
1620
1609
  if (i == null) {
1621
1610
  return '';
1622
1611
  }
@@ -1634,26 +1623,24 @@ var Downshift = /*#__PURE__*/function () {
1634
1623
  onChange: noop,
1635
1624
  onSelect: noop,
1636
1625
  onOuterClick: noop,
1637
- selectedItemChanged: function selectedItemChanged(prevItem, item) {
1638
- return prevItem !== item;
1639
- },
1626
+ selectedItemChanged: (prevItem, item) => prevItem !== item,
1640
1627
  environment:
1641
1628
  /* istanbul ignore next (ssr) */
1642
1629
  typeof window === 'undefined' ? {} : window,
1643
- stateReducer: function stateReducer(state, stateToSet) {
1644
- return stateToSet;
1645
- },
1630
+ stateReducer: (state, stateToSet) => stateToSet,
1646
1631
  suppressRefError: false,
1647
- scrollIntoView: scrollIntoView
1632
+ scrollIntoView
1648
1633
  };
1649
1634
  Downshift.stateChangeTypes = stateChangeTypes$3;
1650
1635
  return Downshift;
1651
- }();
1636
+ })();
1652
1637
 
1653
1638
  var Downshift$1 = Downshift;
1654
1639
 
1655
- function validateGetMenuPropsCalledCorrectly(node, _ref12) {
1656
- var refKey = _ref12.refKey;
1640
+ function validateGetMenuPropsCalledCorrectly(node, _ref3) {
1641
+ let {
1642
+ refKey
1643
+ } = _ref3;
1657
1644
 
1658
1645
  if (!node) {
1659
1646
  // eslint-disable-next-line no-console
@@ -1661,10 +1648,12 @@ function validateGetMenuPropsCalledCorrectly(node, _ref12) {
1661
1648
  }
1662
1649
  }
1663
1650
 
1664
- function validateGetRootPropsCalledCorrectly(element, _ref13) {
1665
- var refKey = _ref13.refKey;
1666
- var refKeySpecified = refKey !== 'ref';
1667
- var isComposite = !isDOMElement(element);
1651
+ function validateGetRootPropsCalledCorrectly(element, _ref4) {
1652
+ let {
1653
+ refKey
1654
+ } = _ref4;
1655
+ const refKeySpecified = refKey !== 'ref';
1656
+ const isComposite = !isDOMElement(element);
1668
1657
 
1669
1658
  if (isComposite && !refKeySpecified && !reactIs.isForwardRef(element)) {
1670
1659
  // eslint-disable-next-line no-console
@@ -1680,8 +1669,7 @@ function validateGetRootPropsCalledCorrectly(element, _ref13) {
1680
1669
  }
1681
1670
  }
1682
1671
 
1683
- var _excluded$3 = ["isInitialMount", "highlightedIndex", "items", "environment"];
1684
- var dropdownDefaultStateValues = {
1672
+ const dropdownDefaultStateValues = {
1685
1673
  highlightedIndex: -1,
1686
1674
  isOpen: false,
1687
1675
  selectedItem: null,
@@ -1689,10 +1677,12 @@ var dropdownDefaultStateValues = {
1689
1677
  };
1690
1678
 
1691
1679
  function callOnChangeProps(action, state, newState) {
1692
- var props = action.props,
1693
- type = action.type;
1694
- var changes = {};
1695
- Object.keys(state).forEach(function (key) {
1680
+ const {
1681
+ props,
1682
+ type
1683
+ } = action;
1684
+ const changes = {};
1685
+ Object.keys(state).forEach(key => {
1696
1686
  invokeOnChangeHandler(key, action, state, newState);
1697
1687
 
1698
1688
  if (newState[key] !== state[key]) {
@@ -1701,21 +1691,25 @@ function callOnChangeProps(action, state, newState) {
1701
1691
  });
1702
1692
 
1703
1693
  if (props.onStateChange && Object.keys(changes).length) {
1704
- props.onStateChange(_extends__default['default']({
1705
- type: type
1706
- }, changes));
1694
+ props.onStateChange({
1695
+ type,
1696
+ ...changes
1697
+ });
1707
1698
  }
1708
1699
  }
1709
1700
 
1710
1701
  function invokeOnChangeHandler(key, action, state, newState) {
1711
- var props = action.props,
1712
- type = action.type;
1713
- var handler = "on" + capitalizeString(key) + "Change";
1702
+ const {
1703
+ props,
1704
+ type
1705
+ } = action;
1706
+ const handler = "on" + capitalizeString(key) + "Change";
1714
1707
 
1715
1708
  if (props[handler] && newState[key] !== undefined && newState[key] !== state[key]) {
1716
- props[handler](_extends__default['default']({
1717
- type: type
1718
- }, newState));
1709
+ props[handler]({
1710
+ type,
1711
+ ...newState
1712
+ });
1719
1713
  }
1720
1714
  }
1721
1715
  /**
@@ -1739,8 +1733,10 @@ function stateReducer(s, a) {
1739
1733
 
1740
1734
 
1741
1735
  function getA11ySelectionMessage(selectionParameters) {
1742
- var selectedItem = selectionParameters.selectedItem,
1743
- itemToStringLocal = selectionParameters.itemToString;
1736
+ const {
1737
+ selectedItem,
1738
+ itemToString: itemToStringLocal
1739
+ } = selectionParameters;
1744
1740
  return selectedItem ? itemToStringLocal(selectedItem) + " has been selected." : '';
1745
1741
  }
1746
1742
  /**
@@ -1748,26 +1744,25 @@ function getA11ySelectionMessage(selectionParameters) {
1748
1744
  */
1749
1745
 
1750
1746
 
1751
- var updateA11yStatus = debounce(function (getA11yMessage, document) {
1747
+ const updateA11yStatus = debounce((getA11yMessage, document) => {
1752
1748
  setStatus(getA11yMessage(), document);
1753
1749
  }, 200); // istanbul ignore next
1754
1750
 
1755
- var useIsomorphicLayoutEffect = typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined' ? preact.useLayoutEffect : preact.useEffect;
1751
+ const useIsomorphicLayoutEffect = typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined' ? preact.useLayoutEffect : preact.useEffect;
1756
1752
 
1757
1753
  function useElementIds(_ref) {
1758
- var _ref$id = _ref.id,
1759
- id = _ref$id === void 0 ? "downshift-" + generateId() : _ref$id,
1760
- labelId = _ref.labelId,
1761
- menuId = _ref.menuId,
1762
- getItemId = _ref.getItemId,
1763
- toggleButtonId = _ref.toggleButtonId,
1764
- inputId = _ref.inputId;
1765
- var elementIdsRef = preact.useRef({
1754
+ let {
1755
+ id = "downshift-" + generateId(),
1756
+ labelId,
1757
+ menuId,
1758
+ getItemId,
1759
+ toggleButtonId,
1760
+ inputId
1761
+ } = _ref;
1762
+ const elementIdsRef = preact.useRef({
1766
1763
  labelId: labelId || id + "-label",
1767
1764
  menuId: menuId || id + "-menu",
1768
- getItemId: getItemId || function (index) {
1769
- return id + "-item-" + index;
1770
- },
1765
+ getItemId: getItemId || (index => id + "-item-" + index),
1771
1766
  toggleButtonId: toggleButtonId || id + "-toggle-button",
1772
1767
  inputId: inputId || id + "-input"
1773
1768
  });
@@ -1799,7 +1794,7 @@ function capitalizeString(string) {
1799
1794
  }
1800
1795
 
1801
1796
  function useLatestRef(val) {
1802
- var ref = preact.useRef(val); // technically this is not "concurrent mode safe" because we're manipulating
1797
+ const ref = preact.useRef(val); // technically this is not "concurrent mode safe" because we're manipulating
1803
1798
  // the value during render (so it's not idempotent). However, the places this
1804
1799
  // hook is used is to support memoizing callbacks which will be called
1805
1800
  // *during* render, so we need the latest values *during* render.
@@ -1821,30 +1816,25 @@ function useLatestRef(val) {
1821
1816
 
1822
1817
 
1823
1818
  function useEnhancedReducer(reducer, initialState, props) {
1824
- var prevStateRef = preact.useRef();
1825
- var actionRef = preact.useRef();
1826
- var enhancedReducer = preact.useCallback(function (state, action) {
1819
+ const prevStateRef = preact.useRef();
1820
+ const actionRef = preact.useRef();
1821
+ const enhancedReducer = preact.useCallback((state, action) => {
1827
1822
  actionRef.current = action;
1828
1823
  state = getState(state, action.props);
1829
- var changes = reducer(state, action);
1830
- var newState = action.props.stateReducer(state, _extends__default['default']({}, action, {
1831
- changes: changes
1832
- }));
1824
+ const changes = reducer(state, action);
1825
+ const newState = action.props.stateReducer(state, { ...action,
1826
+ changes
1827
+ });
1833
1828
  return newState;
1834
1829
  }, [reducer]);
1835
-
1836
- var _useReducer = preact.useReducer(enhancedReducer, initialState),
1837
- state = _useReducer[0],
1838
- dispatch = _useReducer[1];
1839
-
1840
- var propsRef = useLatestRef(props);
1841
- var dispatchWithProps = preact.useCallback(function (action) {
1842
- return dispatch(_extends__default['default']({
1843
- props: propsRef.current
1844
- }, action));
1845
- }, [propsRef]);
1846
- var action = actionRef.current;
1847
- preact.useEffect(function () {
1830
+ const [state, dispatch] = preact.useReducer(enhancedReducer, initialState);
1831
+ const propsRef = useLatestRef(props);
1832
+ const dispatchWithProps = preact.useCallback(action => dispatch({
1833
+ props: propsRef.current,
1834
+ ...action
1835
+ }), [propsRef]);
1836
+ const action = actionRef.current;
1837
+ preact.useEffect(() => {
1848
1838
  if (action && prevStateRef.current && prevStateRef.current !== state) {
1849
1839
  callOnChangeProps(action, getState(prevStateRef.current, action.props), state);
1850
1840
  }
@@ -1865,18 +1855,15 @@ function useEnhancedReducer(reducer, initialState, props) {
1865
1855
 
1866
1856
 
1867
1857
  function useControlledReducer$1(reducer, initialState, props) {
1868
- var _useEnhancedReducer = useEnhancedReducer(reducer, initialState, props),
1869
- state = _useEnhancedReducer[0],
1870
- dispatch = _useEnhancedReducer[1];
1871
-
1858
+ const [state, dispatch] = useEnhancedReducer(reducer, initialState, props);
1872
1859
  return [getState(state, props), dispatch];
1873
1860
  }
1874
1861
 
1875
- var defaultProps$3 = {
1876
- itemToString: itemToString,
1877
- stateReducer: stateReducer,
1878
- getA11ySelectionMessage: getA11ySelectionMessage,
1879
- scrollIntoView: scrollIntoView,
1862
+ const defaultProps$3 = {
1863
+ itemToString,
1864
+ stateReducer,
1865
+ getA11ySelectionMessage,
1866
+ scrollIntoView,
1880
1867
  circularNavigation: false,
1881
1868
  environment:
1882
1869
  /* istanbul ignore next (ssr) */
@@ -1888,7 +1875,7 @@ function getDefaultValue$1(props, propKey, defaultStateValues) {
1888
1875
  defaultStateValues = dropdownDefaultStateValues;
1889
1876
  }
1890
1877
 
1891
- var defaultPropKey = "default" + capitalizeString(propKey);
1878
+ const defaultPropKey = "default" + capitalizeString(propKey);
1892
1879
 
1893
1880
  if (defaultPropKey in props) {
1894
1881
  return props[defaultPropKey];
@@ -1906,7 +1893,7 @@ function getInitialValue$1(props, propKey, defaultStateValues) {
1906
1893
  return props[propKey];
1907
1894
  }
1908
1895
 
1909
- var initialPropKey = "initial" + capitalizeString(propKey);
1896
+ const initialPropKey = "initial" + capitalizeString(propKey);
1910
1897
 
1911
1898
  if (initialPropKey in props) {
1912
1899
  return props[initialPropKey];
@@ -1916,24 +1903,28 @@ function getInitialValue$1(props, propKey, defaultStateValues) {
1916
1903
  }
1917
1904
 
1918
1905
  function getInitialState$2(props) {
1919
- var selectedItem = getInitialValue$1(props, 'selectedItem');
1920
- var isOpen = getInitialValue$1(props, 'isOpen');
1921
- var highlightedIndex = getInitialValue$1(props, 'highlightedIndex');
1922
- var inputValue = getInitialValue$1(props, 'inputValue');
1906
+ const selectedItem = getInitialValue$1(props, 'selectedItem');
1907
+ const isOpen = getInitialValue$1(props, 'isOpen');
1908
+ const highlightedIndex = getInitialValue$1(props, 'highlightedIndex');
1909
+ const inputValue = getInitialValue$1(props, 'inputValue');
1923
1910
  return {
1924
1911
  highlightedIndex: highlightedIndex < 0 && selectedItem && isOpen ? props.items.indexOf(selectedItem) : highlightedIndex,
1925
- isOpen: isOpen,
1926
- selectedItem: selectedItem,
1927
- inputValue: inputValue
1912
+ isOpen,
1913
+ selectedItem,
1914
+ inputValue
1928
1915
  };
1929
1916
  }
1930
1917
 
1931
1918
  function getHighlightedIndexOnOpen(props, state, offset, getItemNodeFromIndex) {
1932
- var items = props.items,
1933
- initialHighlightedIndex = props.initialHighlightedIndex,
1934
- defaultHighlightedIndex = props.defaultHighlightedIndex;
1935
- var selectedItem = state.selectedItem,
1936
- highlightedIndex = state.highlightedIndex;
1919
+ const {
1920
+ items,
1921
+ initialHighlightedIndex,
1922
+ defaultHighlightedIndex
1923
+ } = props;
1924
+ const {
1925
+ selectedItem,
1926
+ highlightedIndex
1927
+ } = state;
1937
1928
 
1938
1929
  if (items.length === 0) {
1939
1930
  return -1;
@@ -1974,39 +1965,35 @@ function getHighlightedIndexOnOpen(props, state, offset, getItemNodeFromIndex) {
1974
1965
 
1975
1966
 
1976
1967
  function useMouseAndTouchTracker(isOpen, downshiftElementRefs, environment, handleBlur) {
1977
- var mouseAndTouchTrackersRef = preact.useRef({
1968
+ const mouseAndTouchTrackersRef = preact.useRef({
1978
1969
  isMouseDown: false,
1979
1970
  isTouchMove: false
1980
1971
  });
1981
- preact.useEffect(function () {
1972
+ preact.useEffect(() => {
1982
1973
  // The same strategy for checking if a click occurred inside or outside downsift
1983
1974
  // as in downshift.js.
1984
- var onMouseDown = function onMouseDown() {
1975
+ const onMouseDown = () => {
1985
1976
  mouseAndTouchTrackersRef.current.isMouseDown = true;
1986
1977
  };
1987
1978
 
1988
- var onMouseUp = function onMouseUp(event) {
1979
+ const onMouseUp = event => {
1989
1980
  mouseAndTouchTrackersRef.current.isMouseDown = false;
1990
1981
 
1991
- if (isOpen && !targetWithinDownshift(event.target, downshiftElementRefs.map(function (ref) {
1992
- return ref.current;
1993
- }), environment)) {
1982
+ if (isOpen && !targetWithinDownshift(event.target, downshiftElementRefs.map(ref => ref.current), environment)) {
1994
1983
  handleBlur();
1995
1984
  }
1996
1985
  };
1997
1986
 
1998
- var onTouchStart = function onTouchStart() {
1987
+ const onTouchStart = () => {
1999
1988
  mouseAndTouchTrackersRef.current.isTouchMove = false;
2000
1989
  };
2001
1990
 
2002
- var onTouchMove = function onTouchMove() {
1991
+ const onTouchMove = () => {
2003
1992
  mouseAndTouchTrackersRef.current.isTouchMove = true;
2004
1993
  };
2005
1994
 
2006
- var onTouchEnd = function onTouchEnd(event) {
2007
- if (isOpen && !mouseAndTouchTrackersRef.current.isTouchMove && !targetWithinDownshift(event.target, downshiftElementRefs.map(function (ref) {
2008
- return ref.current;
2009
- }), environment, false)) {
1995
+ const onTouchEnd = event => {
1996
+ if (isOpen && !mouseAndTouchTrackersRef.current.isTouchMove && !targetWithinDownshift(event.target, downshiftElementRefs.map(ref => ref.current), environment, false)) {
2010
1997
  handleBlur();
2011
1998
  }
2012
1999
  };
@@ -2030,9 +2017,7 @@ function useMouseAndTouchTracker(isOpen, downshiftElementRefs, environment, hand
2030
2017
  // eslint-disable-next-line import/no-mutable-exports
2031
2018
 
2032
2019
 
2033
- var useGetterPropsCalledChecker = function useGetterPropsCalledChecker() {
2034
- return noop;
2035
- };
2020
+ let useGetterPropsCalledChecker = () => noop;
2036
2021
  /**
2037
2022
  * Custom hook that checks if getter props are called correctly.
2038
2023
  *
@@ -2044,20 +2029,20 @@ var useGetterPropsCalledChecker = function useGetterPropsCalledChecker() {
2044
2029
 
2045
2030
 
2046
2031
  if (process.env.NODE_ENV !== 'production') {
2047
- useGetterPropsCalledChecker = function useGetterPropsCalledChecker() {
2048
- var isInitialMountRef = preact.useRef(true);
2032
+ useGetterPropsCalledChecker = function () {
2033
+ const isInitialMountRef = preact.useRef(true);
2049
2034
 
2050
2035
  for (var _len = arguments.length, propKeys = new Array(_len), _key = 0; _key < _len; _key++) {
2051
2036
  propKeys[_key] = arguments[_key];
2052
2037
  }
2053
2038
 
2054
- var getterPropsCalledRef = preact.useRef(propKeys.reduce(function (acc, propKey) {
2039
+ const getterPropsCalledRef = preact.useRef(propKeys.reduce((acc, propKey) => {
2055
2040
  acc[propKey] = {};
2056
2041
  return acc;
2057
2042
  }, {}));
2058
- preact.useEffect(function () {
2059
- Object.keys(getterPropsCalledRef.current).forEach(function (propKey) {
2060
- var propCallInfo = getterPropsCalledRef.current[propKey];
2043
+ preact.useEffect(() => {
2044
+ Object.keys(getterPropsCalledRef.current).forEach(propKey => {
2045
+ const propCallInfo = getterPropsCalledRef.current[propKey];
2061
2046
 
2062
2047
  if (isInitialMountRef.current) {
2063
2048
  if (!Object.keys(propCallInfo).length) {
@@ -2067,9 +2052,11 @@ if (process.env.NODE_ENV !== 'production') {
2067
2052
  }
2068
2053
  }
2069
2054
 
2070
- var suppressRefError = propCallInfo.suppressRefError,
2071
- refKey = propCallInfo.refKey,
2072
- elementRef = propCallInfo.elementRef;
2055
+ const {
2056
+ suppressRefError,
2057
+ refKey,
2058
+ elementRef
2059
+ } = propCallInfo;
2073
2060
 
2074
2061
  if ((!elementRef || !elementRef.current) && !suppressRefError) {
2075
2062
  // eslint-disable-next-line no-console
@@ -2078,11 +2065,11 @@ if (process.env.NODE_ENV !== 'production') {
2078
2065
  });
2079
2066
  isInitialMountRef.current = false;
2080
2067
  });
2081
- var setGetterPropCallInfo = preact.useCallback(function (propKey, suppressRefError, refKey, elementRef) {
2068
+ const setGetterPropCallInfo = preact.useCallback((propKey, suppressRefError, refKey, elementRef) => {
2082
2069
  getterPropsCalledRef.current[propKey] = {
2083
- suppressRefError: suppressRefError,
2084
- refKey: refKey,
2085
- elementRef: elementRef
2070
+ suppressRefError,
2071
+ refKey,
2072
+ elementRef
2086
2073
  };
2087
2074
  }, []);
2088
2075
  return setGetterPropCallInfo;
@@ -2090,39 +2077,41 @@ if (process.env.NODE_ENV !== 'production') {
2090
2077
  }
2091
2078
 
2092
2079
  function useA11yMessageSetter(getA11yMessage, dependencyArray, _ref2) {
2093
- var isInitialMount = _ref2.isInitialMount,
2094
- highlightedIndex = _ref2.highlightedIndex,
2095
- items = _ref2.items,
2096
- environment = _ref2.environment,
2097
- rest = _objectWithoutPropertiesLoose__default['default'](_ref2, _excluded$3);
2098
-
2080
+ let {
2081
+ isInitialMount,
2082
+ highlightedIndex,
2083
+ items,
2084
+ environment,
2085
+ ...rest
2086
+ } = _ref2;
2099
2087
  // Sets a11y status message on changes in state.
2100
- preact.useEffect(function () {
2088
+ preact.useEffect(() => {
2101
2089
  if (isInitialMount || false) {
2102
2090
  return;
2103
2091
  }
2104
2092
 
2105
- updateA11yStatus(function () {
2106
- return getA11yMessage(_extends__default['default']({
2107
- highlightedIndex: highlightedIndex,
2108
- highlightedItem: items[highlightedIndex],
2109
- resultCount: items.length
2110
- }, rest));
2111
- }, environment.document); // eslint-disable-next-line react-hooks/exhaustive-deps
2093
+ updateA11yStatus(() => getA11yMessage({
2094
+ highlightedIndex,
2095
+ highlightedItem: items[highlightedIndex],
2096
+ resultCount: items.length,
2097
+ ...rest
2098
+ }), environment.document); // eslint-disable-next-line react-hooks/exhaustive-deps
2112
2099
  }, dependencyArray);
2113
2100
  }
2114
2101
 
2115
2102
  function useScrollIntoView(_ref3) {
2116
- var highlightedIndex = _ref3.highlightedIndex,
2117
- isOpen = _ref3.isOpen,
2118
- itemRefs = _ref3.itemRefs,
2119
- getItemNodeFromIndex = _ref3.getItemNodeFromIndex,
2120
- menuElement = _ref3.menuElement,
2121
- scrollIntoViewProp = _ref3.scrollIntoView;
2103
+ let {
2104
+ highlightedIndex,
2105
+ isOpen,
2106
+ itemRefs,
2107
+ getItemNodeFromIndex,
2108
+ menuElement,
2109
+ scrollIntoView: scrollIntoViewProp
2110
+ } = _ref3;
2122
2111
  // used not to scroll on highlight by mouse.
2123
- var shouldScrollRef = preact.useRef(true); // Scroll on highlighted item if change comes from keyboard.
2112
+ const shouldScrollRef = preact.useRef(true); // Scroll on highlighted item if change comes from keyboard.
2124
2113
 
2125
- useIsomorphicLayoutEffect(function () {
2114
+ useIsomorphicLayoutEffect(() => {
2126
2115
  if (highlightedIndex < 0 || !isOpen || !Object.keys(itemRefs.current).length) {
2127
2116
  return;
2128
2117
  }
@@ -2138,17 +2127,19 @@ function useScrollIntoView(_ref3) {
2138
2127
  } // eslint-disable-next-line import/no-mutable-exports
2139
2128
 
2140
2129
 
2141
- var useControlPropsValidator = noop;
2130
+ let useControlPropsValidator = noop;
2142
2131
  /* istanbul ignore next */
2143
2132
 
2144
2133
  if (process.env.NODE_ENV !== 'production') {
2145
- useControlPropsValidator = function useControlPropsValidator(_ref4) {
2146
- var isInitialMount = _ref4.isInitialMount,
2147
- props = _ref4.props,
2148
- state = _ref4.state;
2134
+ useControlPropsValidator = _ref4 => {
2135
+ let {
2136
+ isInitialMount,
2137
+ props,
2138
+ state
2139
+ } = _ref4;
2149
2140
  // used for checking when props are moving from controlled to uncontrolled.
2150
- var prevPropsRef = preact.useRef(props);
2151
- preact.useEffect(function () {
2141
+ const prevPropsRef = preact.useRef(props);
2142
+ preact.useEffect(() => {
2152
2143
  if (isInitialMount) {
2153
2144
  return;
2154
2145
  }
@@ -2162,9 +2153,11 @@ if (process.env.NODE_ENV !== 'production') {
2162
2153
  /* eslint-disable complexity */
2163
2154
 
2164
2155
  function downshiftCommonReducer(state, action, stateChangeTypes) {
2165
- var type = action.type,
2166
- props = action.props;
2167
- var changes;
2156
+ const {
2157
+ type,
2158
+ props
2159
+ } = action;
2160
+ let changes;
2168
2161
 
2169
2162
  switch (type) {
2170
2163
  case stateChangeTypes.ItemMouseMove:
@@ -2225,7 +2218,9 @@ function downshiftCommonReducer(state, action, stateChangeTypes) {
2225
2218
  throw new Error('Reducer called without proper action type.');
2226
2219
  }
2227
2220
 
2228
- return _extends__default['default']({}, state, changes);
2221
+ return { ...state,
2222
+ ...changes
2223
+ };
2229
2224
  }
2230
2225
  /* eslint-enable complexity */
2231
2226
 
@@ -2248,37 +2243,37 @@ function getItemIndexByCharacterKey(_a) {
2248
2243
  return highlightedIndex;
2249
2244
  }
2250
2245
  var propTypes$2 = {
2251
- items: PropTypes__default['default'].array.isRequired,
2252
- itemToString: PropTypes__default['default'].func,
2253
- getA11yStatusMessage: PropTypes__default['default'].func,
2254
- getA11ySelectionMessage: PropTypes__default['default'].func,
2255
- circularNavigation: PropTypes__default['default'].bool,
2256
- highlightedIndex: PropTypes__default['default'].number,
2257
- defaultHighlightedIndex: PropTypes__default['default'].number,
2258
- initialHighlightedIndex: PropTypes__default['default'].number,
2259
- isOpen: PropTypes__default['default'].bool,
2260
- defaultIsOpen: PropTypes__default['default'].bool,
2261
- initialIsOpen: PropTypes__default['default'].bool,
2262
- selectedItem: PropTypes__default['default'].any,
2263
- initialSelectedItem: PropTypes__default['default'].any,
2264
- defaultSelectedItem: PropTypes__default['default'].any,
2265
- id: PropTypes__default['default'].string,
2266
- labelId: PropTypes__default['default'].string,
2267
- menuId: PropTypes__default['default'].string,
2268
- getItemId: PropTypes__default['default'].func,
2269
- toggleButtonId: PropTypes__default['default'].string,
2270
- stateReducer: PropTypes__default['default'].func,
2271
- onSelectedItemChange: PropTypes__default['default'].func,
2272
- onHighlightedIndexChange: PropTypes__default['default'].func,
2273
- onStateChange: PropTypes__default['default'].func,
2274
- onIsOpenChange: PropTypes__default['default'].func,
2275
- environment: PropTypes__default['default'].shape({
2276
- addEventListener: PropTypes__default['default'].func,
2277
- removeEventListener: PropTypes__default['default'].func,
2278
- document: PropTypes__default['default'].shape({
2279
- getElementById: PropTypes__default['default'].func,
2280
- activeElement: PropTypes__default['default'].any,
2281
- body: PropTypes__default['default'].any
2246
+ items: PropTypes__default["default"].array.isRequired,
2247
+ itemToString: PropTypes__default["default"].func,
2248
+ getA11yStatusMessage: PropTypes__default["default"].func,
2249
+ getA11ySelectionMessage: PropTypes__default["default"].func,
2250
+ circularNavigation: PropTypes__default["default"].bool,
2251
+ highlightedIndex: PropTypes__default["default"].number,
2252
+ defaultHighlightedIndex: PropTypes__default["default"].number,
2253
+ initialHighlightedIndex: PropTypes__default["default"].number,
2254
+ isOpen: PropTypes__default["default"].bool,
2255
+ defaultIsOpen: PropTypes__default["default"].bool,
2256
+ initialIsOpen: PropTypes__default["default"].bool,
2257
+ selectedItem: PropTypes__default["default"].any,
2258
+ initialSelectedItem: PropTypes__default["default"].any,
2259
+ defaultSelectedItem: PropTypes__default["default"].any,
2260
+ id: PropTypes__default["default"].string,
2261
+ labelId: PropTypes__default["default"].string,
2262
+ menuId: PropTypes__default["default"].string,
2263
+ getItemId: PropTypes__default["default"].func,
2264
+ toggleButtonId: PropTypes__default["default"].string,
2265
+ stateReducer: PropTypes__default["default"].func,
2266
+ onSelectedItemChange: PropTypes__default["default"].func,
2267
+ onHighlightedIndexChange: PropTypes__default["default"].func,
2268
+ onStateChange: PropTypes__default["default"].func,
2269
+ onIsOpenChange: PropTypes__default["default"].func,
2270
+ environment: PropTypes__default["default"].shape({
2271
+ addEventListener: PropTypes__default["default"].func,
2272
+ removeEventListener: PropTypes__default["default"].func,
2273
+ document: PropTypes__default["default"].shape({
2274
+ getElementById: PropTypes__default["default"].func,
2275
+ activeElement: PropTypes__default["default"].any,
2276
+ body: PropTypes__default["default"].any
2282
2277
  })
2283
2278
  })
2284
2279
  };
@@ -2299,7 +2294,7 @@ function getA11yStatusMessage(_a) {
2299
2294
  return 'No results are available.';
2300
2295
  }
2301
2296
  if (resultCount !== previousResultCount) {
2302
- return resultCount + " result" + (resultCount === 1 ? ' is' : 's are') + " available, use up and down arrow keys to navigate. Press Enter or Space Bar keys to select.";
2297
+ return "".concat(resultCount, " result").concat(resultCount === 1 ? ' is' : 's are', " available, use up and down arrow keys to navigate. Press Enter or Space Bar keys to select.");
2303
2298
  }
2304
2299
  return '';
2305
2300
  }
@@ -2309,33 +2304,33 @@ var validatePropTypes$2 = noop;
2309
2304
  /* istanbul ignore next */
2310
2305
  if (process.env.NODE_ENV !== 'production') {
2311
2306
  validatePropTypes$2 = function (options, caller) {
2312
- PropTypes__default['default'].checkPropTypes(propTypes$2, options, 'prop', caller.name);
2307
+ PropTypes__default["default"].checkPropTypes(propTypes$2, options, 'prop', caller.name);
2313
2308
  };
2314
2309
  }
2315
2310
 
2316
- var MenuKeyDownArrowDown = process.env.NODE_ENV !== "production" ? '__menu_keydown_arrow_down__' : 0;
2317
- var MenuKeyDownArrowUp = process.env.NODE_ENV !== "production" ? '__menu_keydown_arrow_up__' : 1;
2318
- var MenuKeyDownEscape = process.env.NODE_ENV !== "production" ? '__menu_keydown_escape__' : 2;
2319
- var MenuKeyDownHome = process.env.NODE_ENV !== "production" ? '__menu_keydown_home__' : 3;
2320
- var MenuKeyDownEnd = process.env.NODE_ENV !== "production" ? '__menu_keydown_end__' : 4;
2321
- var MenuKeyDownEnter = process.env.NODE_ENV !== "production" ? '__menu_keydown_enter__' : 5;
2322
- var MenuKeyDownSpaceButton = process.env.NODE_ENV !== "production" ? '__menu_keydown_space_button__' : 6;
2323
- var MenuKeyDownCharacter = process.env.NODE_ENV !== "production" ? '__menu_keydown_character__' : 7;
2324
- var MenuBlur = process.env.NODE_ENV !== "production" ? '__menu_blur__' : 8;
2325
- var MenuMouseLeave$1 = process.env.NODE_ENV !== "production" ? '__menu_mouse_leave__' : 9;
2326
- var ItemMouseMove$1 = process.env.NODE_ENV !== "production" ? '__item_mouse_move__' : 10;
2327
- var ItemClick$1 = process.env.NODE_ENV !== "production" ? '__item_click__' : 11;
2328
- var ToggleButtonClick$1 = process.env.NODE_ENV !== "production" ? '__togglebutton_click__' : 12;
2329
- var ToggleButtonKeyDownArrowDown = process.env.NODE_ENV !== "production" ? '__togglebutton_keydown_arrow_down__' : 13;
2330
- var ToggleButtonKeyDownArrowUp = process.env.NODE_ENV !== "production" ? '__togglebutton_keydown_arrow_up__' : 14;
2331
- var ToggleButtonKeyDownCharacter = process.env.NODE_ENV !== "production" ? '__togglebutton_keydown_character__' : 15;
2332
- var FunctionToggleMenu$1 = process.env.NODE_ENV !== "production" ? '__function_toggle_menu__' : 16;
2333
- var FunctionOpenMenu$1 = process.env.NODE_ENV !== "production" ? '__function_open_menu__' : 17;
2334
- var FunctionCloseMenu$1 = process.env.NODE_ENV !== "production" ? '__function_close_menu__' : 18;
2335
- var FunctionSetHighlightedIndex$1 = process.env.NODE_ENV !== "production" ? '__function_set_highlighted_index__' : 19;
2336
- var FunctionSelectItem$1 = process.env.NODE_ENV !== "production" ? '__function_select_item__' : 20;
2337
- var FunctionSetInputValue$1 = process.env.NODE_ENV !== "production" ? '__function_set_input_value__' : 21;
2338
- var FunctionReset$2 = process.env.NODE_ENV !== "production" ? '__function_reset__' : 22;
2311
+ const MenuKeyDownArrowDown = process.env.NODE_ENV !== "production" ? '__menu_keydown_arrow_down__' : 0;
2312
+ const MenuKeyDownArrowUp = process.env.NODE_ENV !== "production" ? '__menu_keydown_arrow_up__' : 1;
2313
+ const MenuKeyDownEscape = process.env.NODE_ENV !== "production" ? '__menu_keydown_escape__' : 2;
2314
+ const MenuKeyDownHome = process.env.NODE_ENV !== "production" ? '__menu_keydown_home__' : 3;
2315
+ const MenuKeyDownEnd = process.env.NODE_ENV !== "production" ? '__menu_keydown_end__' : 4;
2316
+ const MenuKeyDownEnter = process.env.NODE_ENV !== "production" ? '__menu_keydown_enter__' : 5;
2317
+ const MenuKeyDownSpaceButton = process.env.NODE_ENV !== "production" ? '__menu_keydown_space_button__' : 6;
2318
+ const MenuKeyDownCharacter = process.env.NODE_ENV !== "production" ? '__menu_keydown_character__' : 7;
2319
+ const MenuBlur = process.env.NODE_ENV !== "production" ? '__menu_blur__' : 8;
2320
+ const MenuMouseLeave$1 = process.env.NODE_ENV !== "production" ? '__menu_mouse_leave__' : 9;
2321
+ const ItemMouseMove$1 = process.env.NODE_ENV !== "production" ? '__item_mouse_move__' : 10;
2322
+ const ItemClick$1 = process.env.NODE_ENV !== "production" ? '__item_click__' : 11;
2323
+ const ToggleButtonClick$1 = process.env.NODE_ENV !== "production" ? '__togglebutton_click__' : 12;
2324
+ const ToggleButtonKeyDownArrowDown = process.env.NODE_ENV !== "production" ? '__togglebutton_keydown_arrow_down__' : 13;
2325
+ const ToggleButtonKeyDownArrowUp = process.env.NODE_ENV !== "production" ? '__togglebutton_keydown_arrow_up__' : 14;
2326
+ const ToggleButtonKeyDownCharacter = process.env.NODE_ENV !== "production" ? '__togglebutton_keydown_character__' : 15;
2327
+ const FunctionToggleMenu$1 = process.env.NODE_ENV !== "production" ? '__function_toggle_menu__' : 16;
2328
+ const FunctionOpenMenu$1 = process.env.NODE_ENV !== "production" ? '__function_open_menu__' : 17;
2329
+ const FunctionCloseMenu$1 = process.env.NODE_ENV !== "production" ? '__function_close_menu__' : 18;
2330
+ const FunctionSetHighlightedIndex$1 = process.env.NODE_ENV !== "production" ? '__function_set_highlighted_index__' : 19;
2331
+ const FunctionSelectItem$1 = process.env.NODE_ENV !== "production" ? '__function_select_item__' : 20;
2332
+ const FunctionSetInputValue$1 = process.env.NODE_ENV !== "production" ? '__function_set_input_value__' : 21;
2333
+ const FunctionReset$2 = process.env.NODE_ENV !== "production" ? '__function_reset__' : 22;
2339
2334
 
2340
2335
  var stateChangeTypes$2 = /*#__PURE__*/Object.freeze({
2341
2336
  __proto__: null,
@@ -2367,10 +2362,12 @@ var stateChangeTypes$2 = /*#__PURE__*/Object.freeze({
2367
2362
  /* eslint-disable complexity */
2368
2363
 
2369
2364
  function downshiftSelectReducer(state, action) {
2370
- var type = action.type,
2371
- props = action.props,
2372
- shiftKey = action.shiftKey;
2373
- var changes;
2365
+ const {
2366
+ type,
2367
+ props,
2368
+ shiftKey
2369
+ } = action;
2370
+ let changes;
2374
2371
 
2375
2372
  switch (type) {
2376
2373
  case ItemClick$1:
@@ -2383,20 +2380,21 @@ function downshiftSelectReducer(state, action) {
2383
2380
 
2384
2381
  case ToggleButtonKeyDownCharacter:
2385
2382
  {
2386
- var lowercasedKey = action.key;
2387
- var inputValue = "" + state.inputValue + lowercasedKey;
2388
- var itemIndex = getItemIndexByCharacterKey({
2383
+ const lowercasedKey = action.key;
2384
+ const inputValue = "" + state.inputValue + lowercasedKey;
2385
+ const itemIndex = getItemIndexByCharacterKey({
2389
2386
  keysSoFar: inputValue,
2390
2387
  highlightedIndex: state.selectedItem ? props.items.indexOf(state.selectedItem) : -1,
2391
2388
  items: props.items,
2392
2389
  itemToString: props.itemToString,
2393
2390
  getItemNodeFromIndex: action.getItemNodeFromIndex
2394
2391
  });
2395
- changes = _extends__default['default']({
2396
- inputValue: inputValue
2397
- }, itemIndex >= 0 && {
2398
- selectedItem: props.items[itemIndex]
2399
- });
2392
+ changes = {
2393
+ inputValue,
2394
+ ...(itemIndex >= 0 && {
2395
+ selectedItem: props.items[itemIndex]
2396
+ })
2397
+ };
2400
2398
  }
2401
2399
  break;
2402
2400
 
@@ -2416,12 +2414,13 @@ function downshiftSelectReducer(state, action) {
2416
2414
 
2417
2415
  case MenuKeyDownEnter:
2418
2416
  case MenuKeyDownSpaceButton:
2419
- changes = _extends__default['default']({
2417
+ changes = {
2420
2418
  isOpen: getDefaultValue$1(props, 'isOpen'),
2421
- highlightedIndex: getDefaultValue$1(props, 'highlightedIndex')
2422
- }, state.highlightedIndex >= 0 && {
2423
- selectedItem: props.items[state.highlightedIndex]
2424
- });
2419
+ highlightedIndex: getDefaultValue$1(props, 'highlightedIndex'),
2420
+ ...(state.highlightedIndex >= 0 && {
2421
+ selectedItem: props.items[state.highlightedIndex]
2422
+ })
2423
+ };
2425
2424
  break;
2426
2425
 
2427
2426
  case MenuKeyDownHome:
@@ -2452,22 +2451,21 @@ function downshiftSelectReducer(state, action) {
2452
2451
 
2453
2452
  case MenuKeyDownCharacter:
2454
2453
  {
2455
- var _lowercasedKey = action.key;
2456
-
2457
- var _inputValue = "" + state.inputValue + _lowercasedKey;
2458
-
2459
- var highlightedIndex = getItemIndexByCharacterKey({
2460
- keysSoFar: _inputValue,
2454
+ const lowercasedKey = action.key;
2455
+ const inputValue = "" + state.inputValue + lowercasedKey;
2456
+ const highlightedIndex = getItemIndexByCharacterKey({
2457
+ keysSoFar: inputValue,
2461
2458
  highlightedIndex: state.highlightedIndex,
2462
2459
  items: props.items,
2463
2460
  itemToString: props.itemToString,
2464
2461
  getItemNodeFromIndex: action.getItemNodeFromIndex
2465
2462
  });
2466
- changes = _extends__default['default']({
2467
- inputValue: _inputValue
2468
- }, highlightedIndex >= 0 && {
2469
- highlightedIndex: highlightedIndex
2470
- });
2463
+ changes = {
2464
+ inputValue,
2465
+ ...(highlightedIndex >= 0 && {
2466
+ highlightedIndex
2467
+ })
2468
+ };
2471
2469
  }
2472
2470
  break;
2473
2471
 
@@ -2493,13 +2491,13 @@ function downshiftSelectReducer(state, action) {
2493
2491
  return downshiftCommonReducer(state, action, stateChangeTypes$2);
2494
2492
  }
2495
2493
 
2496
- return _extends__default['default']({}, state, changes);
2494
+ return { ...state,
2495
+ ...changes
2496
+ };
2497
2497
  }
2498
2498
  /* eslint-enable complexity */
2499
2499
 
2500
- var _excluded$2 = ["onMouseLeave", "refKey", "onKeyDown", "onBlur", "ref"],
2501
- _excluded2$2 = ["onClick", "onKeyDown", "refKey", "ref"],
2502
- _excluded3$1 = ["item", "index", "onMouseMove", "onClick", "refKey", "ref"];
2500
+ /* eslint-disable max-statements */
2503
2501
  useSelect.stateChangeTypes = stateChangeTypes$2;
2504
2502
 
2505
2503
  function useSelect(userProps) {
@@ -2509,91 +2507,92 @@ function useSelect(userProps) {
2509
2507
 
2510
2508
  validatePropTypes$2(userProps, useSelect); // Props defaults and destructuring.
2511
2509
 
2512
- var props = _extends__default['default']({}, defaultProps$2, userProps);
2513
-
2514
- var items = props.items,
2515
- scrollIntoView = props.scrollIntoView,
2516
- environment = props.environment,
2517
- initialIsOpen = props.initialIsOpen,
2518
- defaultIsOpen = props.defaultIsOpen,
2519
- itemToString = props.itemToString,
2520
- getA11ySelectionMessage = props.getA11ySelectionMessage,
2521
- getA11yStatusMessage = props.getA11yStatusMessage; // Initial state depending on controlled props.
2522
-
2523
- var initialState = getInitialState$2(props);
2524
-
2525
- var _useControlledReducer = useControlledReducer$1(downshiftSelectReducer, initialState, props),
2526
- state = _useControlledReducer[0],
2527
- dispatch = _useControlledReducer[1];
2528
-
2529
- var isOpen = state.isOpen,
2530
- highlightedIndex = state.highlightedIndex,
2531
- selectedItem = state.selectedItem,
2532
- inputValue = state.inputValue; // Element efs.
2533
-
2534
- var toggleButtonRef = preact.useRef(null);
2535
- var menuRef = preact.useRef(null);
2536
- var itemRefs = preact.useRef({}); // used not to trigger menu blur action in some scenarios.
2537
-
2538
- var shouldBlurRef = preact.useRef(true); // used to keep the inputValue clearTimeout object between renders.
2539
-
2540
- var clearTimeoutRef = preact.useRef(null); // prevent id re-generation between renders.
2541
-
2542
- var elementIds = useElementIds(props); // used to keep track of how many items we had on previous cycle.
2543
-
2544
- var previousResultCountRef = preact.useRef();
2545
- var isInitialMountRef = preact.useRef(true); // utility callback to get item element.
2546
-
2547
- var latest = useLatestRef({
2548
- state: state,
2549
- props: props
2510
+ const props = { ...defaultProps$2,
2511
+ ...userProps
2512
+ };
2513
+ const {
2514
+ items,
2515
+ scrollIntoView,
2516
+ environment,
2517
+ initialIsOpen,
2518
+ defaultIsOpen,
2519
+ itemToString,
2520
+ getA11ySelectionMessage,
2521
+ getA11yStatusMessage
2522
+ } = props; // Initial state depending on controlled props.
2523
+
2524
+ const initialState = getInitialState$2(props);
2525
+ const [state, dispatch] = useControlledReducer$1(downshiftSelectReducer, initialState, props);
2526
+ const {
2527
+ isOpen,
2528
+ highlightedIndex,
2529
+ selectedItem,
2530
+ inputValue
2531
+ } = state; // Element efs.
2532
+
2533
+ const toggleButtonRef = preact.useRef(null);
2534
+ const menuRef = preact.useRef(null);
2535
+ const itemRefs = preact.useRef({}); // used not to trigger menu blur action in some scenarios.
2536
+
2537
+ const shouldBlurRef = preact.useRef(true); // used to keep the inputValue clearTimeout object between renders.
2538
+
2539
+ const clearTimeoutRef = preact.useRef(null); // prevent id re-generation between renders.
2540
+
2541
+ const elementIds = useElementIds(props); // used to keep track of how many items we had on previous cycle.
2542
+
2543
+ const previousResultCountRef = preact.useRef();
2544
+ const isInitialMountRef = preact.useRef(true); // utility callback to get item element.
2545
+
2546
+ const latest = useLatestRef({
2547
+ state,
2548
+ props
2550
2549
  }); // Some utils.
2551
2550
 
2552
- var getItemNodeFromIndex = preact.useCallback(function (index) {
2553
- return itemRefs.current[elementIds.getItemId(index)];
2554
- }, [elementIds]); // Effects.
2551
+ const getItemNodeFromIndex = preact.useCallback(index => itemRefs.current[elementIds.getItemId(index)], [elementIds]); // Effects.
2555
2552
  // Sets a11y status message on changes in state.
2556
2553
 
2557
- useA11yMessageSetter(getA11yStatusMessage, [isOpen, highlightedIndex, inputValue, items], _extends__default['default']({
2554
+ useA11yMessageSetter(getA11yStatusMessage, [isOpen, highlightedIndex, inputValue, items], {
2558
2555
  isInitialMount: isInitialMountRef.current,
2559
2556
  previousResultCount: previousResultCountRef.current,
2560
- items: items,
2561
- environment: environment,
2562
- itemToString: itemToString
2563
- }, state)); // Sets a11y status message on changes in selectedItem.
2557
+ items,
2558
+ environment,
2559
+ itemToString,
2560
+ ...state
2561
+ }); // Sets a11y status message on changes in selectedItem.
2564
2562
 
2565
- useA11yMessageSetter(getA11ySelectionMessage, [selectedItem], _extends__default['default']({
2563
+ useA11yMessageSetter(getA11ySelectionMessage, [selectedItem], {
2566
2564
  isInitialMount: isInitialMountRef.current,
2567
2565
  previousResultCount: previousResultCountRef.current,
2568
- items: items,
2569
- environment: environment,
2570
- itemToString: itemToString
2571
- }, state)); // Scroll on highlighted item if change comes from keyboard.
2566
+ items,
2567
+ environment,
2568
+ itemToString,
2569
+ ...state
2570
+ }); // Scroll on highlighted item if change comes from keyboard.
2572
2571
 
2573
- var shouldScrollRef = useScrollIntoView({
2572
+ const shouldScrollRef = useScrollIntoView({
2574
2573
  menuElement: menuRef.current,
2575
- highlightedIndex: highlightedIndex,
2576
- isOpen: isOpen,
2577
- itemRefs: itemRefs,
2578
- scrollIntoView: scrollIntoView,
2579
- getItemNodeFromIndex: getItemNodeFromIndex
2574
+ highlightedIndex,
2575
+ isOpen,
2576
+ itemRefs,
2577
+ scrollIntoView,
2578
+ getItemNodeFromIndex
2580
2579
  }); // Sets cleanup for the keysSoFar callback, debounded after 500ms.
2581
2580
 
2582
- preact.useEffect(function () {
2581
+ preact.useEffect(() => {
2583
2582
  // init the clean function here as we need access to dispatch.
2584
- clearTimeoutRef.current = debounce(function (outerDispatch) {
2583
+ clearTimeoutRef.current = debounce(outerDispatch => {
2585
2584
  outerDispatch({
2586
2585
  type: FunctionSetInputValue$1,
2587
2586
  inputValue: ''
2588
2587
  });
2589
2588
  }, 500); // Cancel any pending debounced calls on mount
2590
2589
 
2591
- return function () {
2590
+ return () => {
2592
2591
  clearTimeoutRef.current.cancel();
2593
2592
  };
2594
2593
  }, []); // Invokes the keysSoFar callback set up above.
2595
2594
 
2596
- preact.useEffect(function () {
2595
+ preact.useEffect(() => {
2597
2596
  if (!inputValue) {
2598
2597
  return;
2599
2598
  }
@@ -2602,12 +2601,12 @@ function useSelect(userProps) {
2602
2601
  }, [dispatch, inputValue]);
2603
2602
  useControlPropsValidator({
2604
2603
  isInitialMount: isInitialMountRef.current,
2605
- props: props,
2606
- state: state
2604
+ props,
2605
+ state
2607
2606
  });
2608
2607
  /* Controls the focus on the menu or the toggle button. */
2609
2608
 
2610
- preact.useEffect(function () {
2609
+ preact.useEffect(() => {
2611
2610
  // Don't focus menu on first render.
2612
2611
  if (isInitialMountRef.current) {
2613
2612
  // Unless it was initialised as open.
@@ -2638,7 +2637,7 @@ function useSelect(userProps) {
2638
2637
  } // eslint-disable-next-line react-hooks/exhaustive-deps
2639
2638
 
2640
2639
  }, [isOpen]);
2641
- preact.useEffect(function () {
2640
+ preact.useEffect(() => {
2642
2641
  if (isInitialMountRef.current) {
2643
2642
  return;
2644
2643
  }
@@ -2646,180 +2645,180 @@ function useSelect(userProps) {
2646
2645
  previousResultCountRef.current = items.length;
2647
2646
  }); // Add mouse/touch events to document.
2648
2647
 
2649
- var mouseAndTouchTrackersRef = useMouseAndTouchTracker(isOpen, [menuRef, toggleButtonRef], environment, function () {
2648
+ const mouseAndTouchTrackersRef = useMouseAndTouchTracker(isOpen, [menuRef, toggleButtonRef], environment, () => {
2650
2649
  dispatch({
2651
2650
  type: MenuBlur
2652
2651
  });
2653
2652
  });
2654
- var setGetterPropCallInfo = useGetterPropsCalledChecker('getMenuProps', 'getToggleButtonProps'); // Make initial ref false.
2653
+ const setGetterPropCallInfo = useGetterPropsCalledChecker('getMenuProps', 'getToggleButtonProps'); // Make initial ref false.
2655
2654
 
2656
- preact.useEffect(function () {
2655
+ preact.useEffect(() => {
2657
2656
  isInitialMountRef.current = false;
2658
2657
  }, []); // Reset itemRefs on close.
2659
2658
 
2660
- preact.useEffect(function () {
2659
+ preact.useEffect(() => {
2661
2660
  if (!isOpen) {
2662
2661
  itemRefs.current = {};
2663
2662
  }
2664
2663
  }, [isOpen]); // Event handler functions.
2665
2664
 
2666
- var toggleButtonKeyDownHandlers = preact.useMemo(function () {
2667
- return {
2668
- ArrowDown: function ArrowDown(event) {
2669
- event.preventDefault();
2670
- dispatch({
2671
- type: ToggleButtonKeyDownArrowDown,
2672
- getItemNodeFromIndex: getItemNodeFromIndex,
2673
- shiftKey: event.shiftKey
2674
- });
2675
- },
2676
- ArrowUp: function ArrowUp(event) {
2677
- event.preventDefault();
2678
- dispatch({
2679
- type: ToggleButtonKeyDownArrowUp,
2680
- getItemNodeFromIndex: getItemNodeFromIndex,
2681
- shiftKey: event.shiftKey
2682
- });
2683
- }
2684
- };
2685
- }, [dispatch, getItemNodeFromIndex]);
2686
- var menuKeyDownHandlers = preact.useMemo(function () {
2687
- return {
2688
- ArrowDown: function ArrowDown(event) {
2689
- event.preventDefault();
2690
- dispatch({
2691
- type: MenuKeyDownArrowDown,
2692
- getItemNodeFromIndex: getItemNodeFromIndex,
2693
- shiftKey: event.shiftKey
2694
- });
2695
- },
2696
- ArrowUp: function ArrowUp(event) {
2697
- event.preventDefault();
2698
- dispatch({
2699
- type: MenuKeyDownArrowUp,
2700
- getItemNodeFromIndex: getItemNodeFromIndex,
2701
- shiftKey: event.shiftKey
2702
- });
2703
- },
2704
- Home: function Home(event) {
2705
- event.preventDefault();
2706
- dispatch({
2707
- type: MenuKeyDownHome,
2708
- getItemNodeFromIndex: getItemNodeFromIndex
2709
- });
2710
- },
2711
- End: function End(event) {
2712
- event.preventDefault();
2713
- dispatch({
2714
- type: MenuKeyDownEnd,
2715
- getItemNodeFromIndex: getItemNodeFromIndex
2716
- });
2717
- },
2718
- Escape: function Escape() {
2719
- dispatch({
2720
- type: MenuKeyDownEscape
2721
- });
2722
- },
2723
- Enter: function Enter(event) {
2724
- event.preventDefault();
2725
- dispatch({
2726
- type: MenuKeyDownEnter
2727
- });
2728
- },
2729
- ' ': function _(event) {
2730
- event.preventDefault();
2731
- dispatch({
2732
- type: MenuKeyDownSpaceButton
2733
- });
2734
- }
2735
- };
2736
- }, [dispatch, getItemNodeFromIndex]); // Action functions.
2665
+ const toggleButtonKeyDownHandlers = preact.useMemo(() => ({
2666
+ ArrowDown(event) {
2667
+ event.preventDefault();
2668
+ dispatch({
2669
+ type: ToggleButtonKeyDownArrowDown,
2670
+ getItemNodeFromIndex,
2671
+ shiftKey: event.shiftKey
2672
+ });
2673
+ },
2737
2674
 
2738
- var toggleMenu = preact.useCallback(function () {
2675
+ ArrowUp(event) {
2676
+ event.preventDefault();
2677
+ dispatch({
2678
+ type: ToggleButtonKeyDownArrowUp,
2679
+ getItemNodeFromIndex,
2680
+ shiftKey: event.shiftKey
2681
+ });
2682
+ }
2683
+
2684
+ }), [dispatch, getItemNodeFromIndex]);
2685
+ const menuKeyDownHandlers = preact.useMemo(() => ({
2686
+ ArrowDown(event) {
2687
+ event.preventDefault();
2688
+ dispatch({
2689
+ type: MenuKeyDownArrowDown,
2690
+ getItemNodeFromIndex,
2691
+ shiftKey: event.shiftKey
2692
+ });
2693
+ },
2694
+
2695
+ ArrowUp(event) {
2696
+ event.preventDefault();
2697
+ dispatch({
2698
+ type: MenuKeyDownArrowUp,
2699
+ getItemNodeFromIndex,
2700
+ shiftKey: event.shiftKey
2701
+ });
2702
+ },
2703
+
2704
+ Home(event) {
2705
+ event.preventDefault();
2706
+ dispatch({
2707
+ type: MenuKeyDownHome,
2708
+ getItemNodeFromIndex
2709
+ });
2710
+ },
2711
+
2712
+ End(event) {
2713
+ event.preventDefault();
2714
+ dispatch({
2715
+ type: MenuKeyDownEnd,
2716
+ getItemNodeFromIndex
2717
+ });
2718
+ },
2719
+
2720
+ Escape() {
2721
+ dispatch({
2722
+ type: MenuKeyDownEscape
2723
+ });
2724
+ },
2725
+
2726
+ Enter(event) {
2727
+ event.preventDefault();
2728
+ dispatch({
2729
+ type: MenuKeyDownEnter
2730
+ });
2731
+ },
2732
+
2733
+ ' '(event) {
2734
+ event.preventDefault();
2735
+ dispatch({
2736
+ type: MenuKeyDownSpaceButton
2737
+ });
2738
+ }
2739
+
2740
+ }), [dispatch, getItemNodeFromIndex]); // Action functions.
2741
+
2742
+ const toggleMenu = preact.useCallback(() => {
2739
2743
  dispatch({
2740
2744
  type: FunctionToggleMenu$1
2741
2745
  });
2742
2746
  }, [dispatch]);
2743
- var closeMenu = preact.useCallback(function () {
2747
+ const closeMenu = preact.useCallback(() => {
2744
2748
  dispatch({
2745
2749
  type: FunctionCloseMenu$1
2746
2750
  });
2747
2751
  }, [dispatch]);
2748
- var openMenu = preact.useCallback(function () {
2752
+ const openMenu = preact.useCallback(() => {
2749
2753
  dispatch({
2750
2754
  type: FunctionOpenMenu$1
2751
2755
  });
2752
2756
  }, [dispatch]);
2753
- var setHighlightedIndex = preact.useCallback(function (newHighlightedIndex) {
2757
+ const setHighlightedIndex = preact.useCallback(newHighlightedIndex => {
2754
2758
  dispatch({
2755
2759
  type: FunctionSetHighlightedIndex$1,
2756
2760
  highlightedIndex: newHighlightedIndex
2757
2761
  });
2758
2762
  }, [dispatch]);
2759
- var selectItem = preact.useCallback(function (newSelectedItem) {
2763
+ const selectItem = preact.useCallback(newSelectedItem => {
2760
2764
  dispatch({
2761
2765
  type: FunctionSelectItem$1,
2762
2766
  selectedItem: newSelectedItem
2763
2767
  });
2764
2768
  }, [dispatch]);
2765
- var reset = preact.useCallback(function () {
2769
+ const reset = preact.useCallback(() => {
2766
2770
  dispatch({
2767
2771
  type: FunctionReset$2
2768
2772
  });
2769
2773
  }, [dispatch]);
2770
- var setInputValue = preact.useCallback(function (newInputValue) {
2774
+ const setInputValue = preact.useCallback(newInputValue => {
2771
2775
  dispatch({
2772
2776
  type: FunctionSetInputValue$1,
2773
2777
  inputValue: newInputValue
2774
2778
  });
2775
2779
  }, [dispatch]); // Getter functions.
2776
2780
 
2777
- var getLabelProps = preact.useCallback(function (labelProps) {
2778
- return _extends__default['default']({
2779
- id: elementIds.labelId,
2780
- htmlFor: elementIds.toggleButtonId
2781
- }, labelProps);
2782
- }, [elementIds]);
2783
- var getMenuProps = preact.useCallback(function (_temp, _temp2) {
2784
- var _extends2;
2785
-
2786
- var _ref = _temp === void 0 ? {} : _temp,
2787
- onMouseLeave = _ref.onMouseLeave,
2788
- _ref$refKey = _ref.refKey,
2789
- refKey = _ref$refKey === void 0 ? 'ref' : _ref$refKey,
2790
- onKeyDown = _ref.onKeyDown,
2791
- onBlur = _ref.onBlur,
2792
- ref = _ref.ref,
2793
- rest = _objectWithoutPropertiesLoose__default['default'](_ref, _excluded$2);
2794
-
2795
- var _ref2 = _temp2 === void 0 ? {} : _temp2,
2796
- _ref2$suppressRefErro = _ref2.suppressRefError,
2797
- suppressRefError = _ref2$suppressRefErro === void 0 ? false : _ref2$suppressRefErro;
2798
-
2799
- var latestState = latest.current.state;
2800
-
2801
- var menuHandleKeyDown = function menuHandleKeyDown(event) {
2802
- var key = normalizeArrowKey(event);
2781
+ const getLabelProps = preact.useCallback(labelProps => ({
2782
+ id: elementIds.labelId,
2783
+ htmlFor: elementIds.toggleButtonId,
2784
+ ...labelProps
2785
+ }), [elementIds]);
2786
+ const getMenuProps = preact.useCallback(function (_temp, _temp2) {
2787
+ let {
2788
+ onMouseLeave,
2789
+ refKey = 'ref',
2790
+ onKeyDown,
2791
+ onBlur,
2792
+ ref,
2793
+ ...rest
2794
+ } = _temp === void 0 ? {} : _temp;
2795
+ let {
2796
+ suppressRefError = false
2797
+ } = _temp2 === void 0 ? {} : _temp2;
2798
+ const latestState = latest.current.state;
2799
+
2800
+ const menuHandleKeyDown = event => {
2801
+ const key = normalizeArrowKey(event);
2803
2802
 
2804
2803
  if (key && menuKeyDownHandlers[key]) {
2805
2804
  menuKeyDownHandlers[key](event);
2806
2805
  } else if (isAcceptedCharacterKey(key)) {
2807
2806
  dispatch({
2808
2807
  type: MenuKeyDownCharacter,
2809
- key: key,
2810
- getItemNodeFromIndex: getItemNodeFromIndex
2808
+ key,
2809
+ getItemNodeFromIndex
2811
2810
  });
2812
2811
  }
2813
2812
  };
2814
2813
 
2815
- var menuHandleBlur = function menuHandleBlur() {
2814
+ const menuHandleBlur = () => {
2816
2815
  // if the blur was a result of selection, we don't trigger this action.
2817
2816
  if (shouldBlurRef.current === false) {
2818
2817
  shouldBlurRef.current = true;
2819
2818
  return;
2820
2819
  }
2821
2820
 
2822
- var shouldBlur = !mouseAndTouchTrackersRef.current.isMouseDown;
2821
+ const shouldBlur = !mouseAndTouchTrackersRef.current.isMouseDown;
2823
2822
  /* istanbul ignore else */
2824
2823
 
2825
2824
  if (shouldBlur) {
@@ -2829,61 +2828,72 @@ function useSelect(userProps) {
2829
2828
  }
2830
2829
  };
2831
2830
 
2832
- var menuHandleMouseLeave = function menuHandleMouseLeave() {
2831
+ const menuHandleMouseLeave = () => {
2833
2832
  dispatch({
2834
2833
  type: MenuMouseLeave$1
2835
2834
  });
2836
2835
  };
2837
2836
 
2838
2837
  setGetterPropCallInfo('getMenuProps', suppressRefError, refKey, menuRef);
2839
- return _extends__default['default']((_extends2 = {}, _extends2[refKey] = handleRefs(ref, function (menuNode) {
2840
- menuRef.current = menuNode;
2841
- }), _extends2.id = elementIds.menuId, _extends2.role = 'listbox', _extends2['aria-labelledby'] = elementIds.labelId, _extends2.tabIndex = -1, _extends2), latestState.isOpen && latestState.highlightedIndex > -1 && {
2842
- 'aria-activedescendant': elementIds.getItemId(latestState.highlightedIndex)
2843
- }, {
2838
+ return {
2839
+ [refKey]: handleRefs(ref, menuNode => {
2840
+ menuRef.current = menuNode;
2841
+ }),
2842
+ id: elementIds.menuId,
2843
+ role: 'listbox',
2844
+ 'aria-labelledby': elementIds.labelId,
2845
+ tabIndex: -1,
2846
+ ...(latestState.isOpen && latestState.highlightedIndex > -1 && {
2847
+ 'aria-activedescendant': elementIds.getItemId(latestState.highlightedIndex)
2848
+ }),
2844
2849
  onMouseLeave: callAllEventHandlers(onMouseLeave, menuHandleMouseLeave),
2845
2850
  onKeyDown: callAllEventHandlers(onKeyDown, menuHandleKeyDown),
2846
- onBlur: callAllEventHandlers(onBlur, menuHandleBlur)
2847
- }, rest);
2851
+ onBlur: callAllEventHandlers(onBlur, menuHandleBlur),
2852
+ ...rest
2853
+ };
2848
2854
  }, [dispatch, latest, menuKeyDownHandlers, mouseAndTouchTrackersRef, setGetterPropCallInfo, elementIds, getItemNodeFromIndex]);
2849
- var getToggleButtonProps = preact.useCallback(function (_temp3, _temp4) {
2850
- var _extends3;
2851
-
2852
- var _ref3 = _temp3 === void 0 ? {} : _temp3,
2853
- onClick = _ref3.onClick,
2854
- onKeyDown = _ref3.onKeyDown,
2855
- _ref3$refKey = _ref3.refKey,
2856
- refKey = _ref3$refKey === void 0 ? 'ref' : _ref3$refKey,
2857
- ref = _ref3.ref,
2858
- rest = _objectWithoutPropertiesLoose__default['default'](_ref3, _excluded2$2);
2859
-
2860
- var _ref4 = _temp4 === void 0 ? {} : _temp4,
2861
- _ref4$suppressRefErro = _ref4.suppressRefError,
2862
- suppressRefError = _ref4$suppressRefErro === void 0 ? false : _ref4$suppressRefErro;
2863
-
2864
- var toggleButtonHandleClick = function toggleButtonHandleClick() {
2855
+ const getToggleButtonProps = preact.useCallback(function (_temp3, _temp4) {
2856
+ let {
2857
+ onClick,
2858
+ onKeyDown,
2859
+ refKey = 'ref',
2860
+ ref,
2861
+ ...rest
2862
+ } = _temp3 === void 0 ? {} : _temp3;
2863
+ let {
2864
+ suppressRefError = false
2865
+ } = _temp4 === void 0 ? {} : _temp4;
2866
+
2867
+ const toggleButtonHandleClick = () => {
2865
2868
  dispatch({
2866
2869
  type: ToggleButtonClick$1
2867
2870
  });
2868
2871
  };
2869
2872
 
2870
- var toggleButtonHandleKeyDown = function toggleButtonHandleKeyDown(event) {
2871
- var key = normalizeArrowKey(event);
2873
+ const toggleButtonHandleKeyDown = event => {
2874
+ const key = normalizeArrowKey(event);
2872
2875
 
2873
2876
  if (key && toggleButtonKeyDownHandlers[key]) {
2874
2877
  toggleButtonKeyDownHandlers[key](event);
2875
2878
  } else if (isAcceptedCharacterKey(key)) {
2876
2879
  dispatch({
2877
2880
  type: ToggleButtonKeyDownCharacter,
2878
- key: key,
2879
- getItemNodeFromIndex: getItemNodeFromIndex
2881
+ key,
2882
+ getItemNodeFromIndex
2880
2883
  });
2881
2884
  }
2882
2885
  };
2883
2886
 
2884
- var toggleProps = _extends__default['default']((_extends3 = {}, _extends3[refKey] = handleRefs(ref, function (toggleButtonNode) {
2885
- toggleButtonRef.current = toggleButtonNode;
2886
- }), _extends3.id = elementIds.toggleButtonId, _extends3['aria-haspopup'] = 'listbox', _extends3['aria-expanded'] = latest.current.state.isOpen, _extends3['aria-labelledby'] = elementIds.labelId + " " + elementIds.toggleButtonId, _extends3), rest);
2887
+ const toggleProps = {
2888
+ [refKey]: handleRefs(ref, toggleButtonNode => {
2889
+ toggleButtonRef.current = toggleButtonNode;
2890
+ }),
2891
+ id: elementIds.toggleButtonId,
2892
+ 'aria-haspopup': 'listbox',
2893
+ 'aria-expanded': latest.current.state.isOpen,
2894
+ 'aria-labelledby': elementIds.labelId + " " + elementIds.toggleButtonId,
2895
+ ...rest
2896
+ };
2887
2897
 
2888
2898
  if (!rest.disabled) {
2889
2899
  toggleProps.onClick = callAllEventHandlers(onClick, toggleButtonHandleClick);
@@ -2893,24 +2903,22 @@ function useSelect(userProps) {
2893
2903
  setGetterPropCallInfo('getToggleButtonProps', suppressRefError, refKey, toggleButtonRef);
2894
2904
  return toggleProps;
2895
2905
  }, [dispatch, latest, toggleButtonKeyDownHandlers, setGetterPropCallInfo, elementIds, getItemNodeFromIndex]);
2896
- var getItemProps = preact.useCallback(function (_temp5) {
2897
- var _extends4;
2898
-
2899
- var _ref5 = _temp5 === void 0 ? {} : _temp5,
2900
- item = _ref5.item,
2901
- index = _ref5.index,
2902
- onMouseMove = _ref5.onMouseMove,
2903
- onClick = _ref5.onClick,
2904
- _ref5$refKey = _ref5.refKey,
2905
- refKey = _ref5$refKey === void 0 ? 'ref' : _ref5$refKey,
2906
- ref = _ref5.ref,
2907
- rest = _objectWithoutPropertiesLoose__default['default'](_ref5, _excluded3$1);
2908
-
2909
- var _latest$current = latest.current,
2910
- latestState = _latest$current.state,
2911
- latestProps = _latest$current.props;
2912
-
2913
- var itemHandleMouseMove = function itemHandleMouseMove() {
2906
+ const getItemProps = preact.useCallback(function (_temp5) {
2907
+ let {
2908
+ item,
2909
+ index,
2910
+ onMouseMove,
2911
+ onClick,
2912
+ refKey = 'ref',
2913
+ ref,
2914
+ ...rest
2915
+ } = _temp5 === void 0 ? {} : _temp5;
2916
+ const {
2917
+ state: latestState,
2918
+ props: latestProps
2919
+ } = latest.current;
2920
+
2921
+ const itemHandleMouseMove = () => {
2914
2922
  if (index === latestState.highlightedIndex) {
2915
2923
  return;
2916
2924
  }
@@ -2918,32 +2926,34 @@ function useSelect(userProps) {
2918
2926
  shouldScrollRef.current = false;
2919
2927
  dispatch({
2920
2928
  type: ItemMouseMove$1,
2921
- index: index
2929
+ index
2922
2930
  });
2923
2931
  };
2924
2932
 
2925
- var itemHandleClick = function itemHandleClick() {
2933
+ const itemHandleClick = () => {
2926
2934
  dispatch({
2927
2935
  type: ItemClick$1,
2928
- index: index
2936
+ index
2929
2937
  });
2930
2938
  };
2931
2939
 
2932
- var itemIndex = getItemIndex(index, item, latestProps.items);
2940
+ const itemIndex = getItemIndex(index, item, latestProps.items);
2933
2941
 
2934
2942
  if (itemIndex < 0) {
2935
2943
  throw new Error('Pass either item or item index in getItemProps!');
2936
2944
  }
2937
2945
 
2938
- var itemProps = _extends__default['default']((_extends4 = {
2946
+ const itemProps = {
2939
2947
  role: 'option',
2940
2948
  'aria-selected': "" + (itemIndex === latestState.highlightedIndex),
2941
- id: elementIds.getItemId(itemIndex)
2942
- }, _extends4[refKey] = handleRefs(ref, function (itemNode) {
2943
- if (itemNode) {
2944
- itemRefs.current[elementIds.getItemId(itemIndex)] = itemNode;
2945
- }
2946
- }), _extends4), rest);
2949
+ id: elementIds.getItemId(itemIndex),
2950
+ [refKey]: handleRefs(ref, itemNode => {
2951
+ if (itemNode) {
2952
+ itemRefs.current[elementIds.getItemId(itemIndex)] = itemNode;
2953
+ }
2954
+ }),
2955
+ ...rest
2956
+ };
2947
2957
 
2948
2958
  if (!rest.disabled) {
2949
2959
  itemProps.onMouseMove = callAllEventHandlers(onMouseMove, itemHandleMouseMove);
@@ -2954,46 +2964,46 @@ function useSelect(userProps) {
2954
2964
  }, [dispatch, latest, shouldScrollRef, elementIds]);
2955
2965
  return {
2956
2966
  // prop getters.
2957
- getToggleButtonProps: getToggleButtonProps,
2958
- getLabelProps: getLabelProps,
2959
- getMenuProps: getMenuProps,
2960
- getItemProps: getItemProps,
2967
+ getToggleButtonProps,
2968
+ getLabelProps,
2969
+ getMenuProps,
2970
+ getItemProps,
2961
2971
  // actions.
2962
- toggleMenu: toggleMenu,
2963
- openMenu: openMenu,
2964
- closeMenu: closeMenu,
2965
- setHighlightedIndex: setHighlightedIndex,
2966
- selectItem: selectItem,
2967
- reset: reset,
2968
- setInputValue: setInputValue,
2972
+ toggleMenu,
2973
+ openMenu,
2974
+ closeMenu,
2975
+ setHighlightedIndex,
2976
+ selectItem,
2977
+ reset,
2978
+ setInputValue,
2969
2979
  // state.
2970
- highlightedIndex: highlightedIndex,
2971
- isOpen: isOpen,
2972
- selectedItem: selectedItem,
2973
- inputValue: inputValue
2980
+ highlightedIndex,
2981
+ isOpen,
2982
+ selectedItem,
2983
+ inputValue
2974
2984
  };
2975
2985
  }
2976
2986
 
2977
- var InputKeyDownArrowDown = process.env.NODE_ENV !== "production" ? '__input_keydown_arrow_down__' : 0;
2978
- var InputKeyDownArrowUp = process.env.NODE_ENV !== "production" ? '__input_keydown_arrow_up__' : 1;
2979
- var InputKeyDownEscape = process.env.NODE_ENV !== "production" ? '__input_keydown_escape__' : 2;
2980
- var InputKeyDownHome = process.env.NODE_ENV !== "production" ? '__input_keydown_home__' : 3;
2981
- var InputKeyDownEnd = process.env.NODE_ENV !== "production" ? '__input_keydown_end__' : 4;
2982
- var InputKeyDownEnter = process.env.NODE_ENV !== "production" ? '__input_keydown_enter__' : 5;
2983
- var InputChange = process.env.NODE_ENV !== "production" ? '__input_change__' : 6;
2984
- var InputBlur = process.env.NODE_ENV !== "production" ? '__input_blur__' : 7;
2985
- var MenuMouseLeave = process.env.NODE_ENV !== "production" ? '__menu_mouse_leave__' : 8;
2986
- var ItemMouseMove = process.env.NODE_ENV !== "production" ? '__item_mouse_move__' : 9;
2987
- var ItemClick = process.env.NODE_ENV !== "production" ? '__item_click__' : 10;
2988
- var ToggleButtonClick = process.env.NODE_ENV !== "production" ? '__togglebutton_click__' : 11;
2989
- var FunctionToggleMenu = process.env.NODE_ENV !== "production" ? '__function_toggle_menu__' : 12;
2990
- var FunctionOpenMenu = process.env.NODE_ENV !== "production" ? '__function_open_menu__' : 13;
2991
- var FunctionCloseMenu = process.env.NODE_ENV !== "production" ? '__function_close_menu__' : 14;
2992
- var FunctionSetHighlightedIndex = process.env.NODE_ENV !== "production" ? '__function_set_highlighted_index__' : 15;
2993
- var FunctionSelectItem = process.env.NODE_ENV !== "production" ? '__function_select_item__' : 16;
2994
- var FunctionSetInputValue = process.env.NODE_ENV !== "production" ? '__function_set_input_value__' : 17;
2995
- var FunctionReset$1 = process.env.NODE_ENV !== "production" ? '__function_reset__' : 18;
2996
- var ControlledPropUpdatedSelectedItem = process.env.NODE_ENV !== "production" ? '__controlled_prop_updated_selected_item__' : 19;
2987
+ const InputKeyDownArrowDown = process.env.NODE_ENV !== "production" ? '__input_keydown_arrow_down__' : 0;
2988
+ const InputKeyDownArrowUp = process.env.NODE_ENV !== "production" ? '__input_keydown_arrow_up__' : 1;
2989
+ const InputKeyDownEscape = process.env.NODE_ENV !== "production" ? '__input_keydown_escape__' : 2;
2990
+ const InputKeyDownHome = process.env.NODE_ENV !== "production" ? '__input_keydown_home__' : 3;
2991
+ const InputKeyDownEnd = process.env.NODE_ENV !== "production" ? '__input_keydown_end__' : 4;
2992
+ const InputKeyDownEnter = process.env.NODE_ENV !== "production" ? '__input_keydown_enter__' : 5;
2993
+ const InputChange = process.env.NODE_ENV !== "production" ? '__input_change__' : 6;
2994
+ const InputBlur = process.env.NODE_ENV !== "production" ? '__input_blur__' : 7;
2995
+ const MenuMouseLeave = process.env.NODE_ENV !== "production" ? '__menu_mouse_leave__' : 8;
2996
+ const ItemMouseMove = process.env.NODE_ENV !== "production" ? '__item_mouse_move__' : 9;
2997
+ const ItemClick = process.env.NODE_ENV !== "production" ? '__item_click__' : 10;
2998
+ const ToggleButtonClick = process.env.NODE_ENV !== "production" ? '__togglebutton_click__' : 11;
2999
+ const FunctionToggleMenu = process.env.NODE_ENV !== "production" ? '__function_toggle_menu__' : 12;
3000
+ const FunctionOpenMenu = process.env.NODE_ENV !== "production" ? '__function_open_menu__' : 13;
3001
+ const FunctionCloseMenu = process.env.NODE_ENV !== "production" ? '__function_close_menu__' : 14;
3002
+ const FunctionSetHighlightedIndex = process.env.NODE_ENV !== "production" ? '__function_set_highlighted_index__' : 15;
3003
+ const FunctionSelectItem = process.env.NODE_ENV !== "production" ? '__function_select_item__' : 16;
3004
+ const FunctionSetInputValue = process.env.NODE_ENV !== "production" ? '__function_set_input_value__' : 17;
3005
+ const FunctionReset$1 = process.env.NODE_ENV !== "production" ? '__function_reset__' : 18;
3006
+ const ControlledPropUpdatedSelectedItem = process.env.NODE_ENV !== "production" ? '__controlled_prop_updated_selected_item__' : 19;
2997
3007
 
2998
3008
  var stateChangeTypes$1 = /*#__PURE__*/Object.freeze({
2999
3009
  __proto__: null,
@@ -3020,56 +3030,60 @@ var stateChangeTypes$1 = /*#__PURE__*/Object.freeze({
3020
3030
  });
3021
3031
 
3022
3032
  function getInitialState$1(props) {
3023
- var initialState = getInitialState$2(props);
3024
- var selectedItem = initialState.selectedItem;
3025
- var inputValue = initialState.inputValue;
3033
+ const initialState = getInitialState$2(props);
3034
+ const {
3035
+ selectedItem
3036
+ } = initialState;
3037
+ let {
3038
+ inputValue
3039
+ } = initialState;
3026
3040
 
3027
3041
  if (inputValue === '' && selectedItem && props.defaultInputValue === undefined && props.initialInputValue === undefined && props.inputValue === undefined) {
3028
3042
  inputValue = props.itemToString(selectedItem);
3029
3043
  }
3030
3044
 
3031
- return _extends__default['default']({}, initialState, {
3032
- inputValue: inputValue
3033
- });
3045
+ return { ...initialState,
3046
+ inputValue
3047
+ };
3034
3048
  }
3035
3049
 
3036
- var propTypes$1 = {
3037
- items: PropTypes__default['default'].array.isRequired,
3038
- itemToString: PropTypes__default['default'].func,
3039
- getA11yStatusMessage: PropTypes__default['default'].func,
3040
- getA11ySelectionMessage: PropTypes__default['default'].func,
3041
- circularNavigation: PropTypes__default['default'].bool,
3042
- highlightedIndex: PropTypes__default['default'].number,
3043
- defaultHighlightedIndex: PropTypes__default['default'].number,
3044
- initialHighlightedIndex: PropTypes__default['default'].number,
3045
- isOpen: PropTypes__default['default'].bool,
3046
- defaultIsOpen: PropTypes__default['default'].bool,
3047
- initialIsOpen: PropTypes__default['default'].bool,
3048
- selectedItem: PropTypes__default['default'].any,
3049
- initialSelectedItem: PropTypes__default['default'].any,
3050
- defaultSelectedItem: PropTypes__default['default'].any,
3051
- inputValue: PropTypes__default['default'].string,
3052
- defaultInputValue: PropTypes__default['default'].string,
3053
- initialInputValue: PropTypes__default['default'].string,
3054
- id: PropTypes__default['default'].string,
3055
- labelId: PropTypes__default['default'].string,
3056
- menuId: PropTypes__default['default'].string,
3057
- getItemId: PropTypes__default['default'].func,
3058
- inputId: PropTypes__default['default'].string,
3059
- toggleButtonId: PropTypes__default['default'].string,
3060
- stateReducer: PropTypes__default['default'].func,
3061
- onSelectedItemChange: PropTypes__default['default'].func,
3062
- onHighlightedIndexChange: PropTypes__default['default'].func,
3063
- onStateChange: PropTypes__default['default'].func,
3064
- onIsOpenChange: PropTypes__default['default'].func,
3065
- onInputValueChange: PropTypes__default['default'].func,
3066
- environment: PropTypes__default['default'].shape({
3067
- addEventListener: PropTypes__default['default'].func,
3068
- removeEventListener: PropTypes__default['default'].func,
3069
- document: PropTypes__default['default'].shape({
3070
- getElementById: PropTypes__default['default'].func,
3071
- activeElement: PropTypes__default['default'].any,
3072
- body: PropTypes__default['default'].any
3050
+ const propTypes$1 = {
3051
+ items: PropTypes__default["default"].array.isRequired,
3052
+ itemToString: PropTypes__default["default"].func,
3053
+ getA11yStatusMessage: PropTypes__default["default"].func,
3054
+ getA11ySelectionMessage: PropTypes__default["default"].func,
3055
+ circularNavigation: PropTypes__default["default"].bool,
3056
+ highlightedIndex: PropTypes__default["default"].number,
3057
+ defaultHighlightedIndex: PropTypes__default["default"].number,
3058
+ initialHighlightedIndex: PropTypes__default["default"].number,
3059
+ isOpen: PropTypes__default["default"].bool,
3060
+ defaultIsOpen: PropTypes__default["default"].bool,
3061
+ initialIsOpen: PropTypes__default["default"].bool,
3062
+ selectedItem: PropTypes__default["default"].any,
3063
+ initialSelectedItem: PropTypes__default["default"].any,
3064
+ defaultSelectedItem: PropTypes__default["default"].any,
3065
+ inputValue: PropTypes__default["default"].string,
3066
+ defaultInputValue: PropTypes__default["default"].string,
3067
+ initialInputValue: PropTypes__default["default"].string,
3068
+ id: PropTypes__default["default"].string,
3069
+ labelId: PropTypes__default["default"].string,
3070
+ menuId: PropTypes__default["default"].string,
3071
+ getItemId: PropTypes__default["default"].func,
3072
+ inputId: PropTypes__default["default"].string,
3073
+ toggleButtonId: PropTypes__default["default"].string,
3074
+ stateReducer: PropTypes__default["default"].func,
3075
+ onSelectedItemChange: PropTypes__default["default"].func,
3076
+ onHighlightedIndexChange: PropTypes__default["default"].func,
3077
+ onStateChange: PropTypes__default["default"].func,
3078
+ onIsOpenChange: PropTypes__default["default"].func,
3079
+ onInputValueChange: PropTypes__default["default"].func,
3080
+ environment: PropTypes__default["default"].shape({
3081
+ addEventListener: PropTypes__default["default"].func,
3082
+ removeEventListener: PropTypes__default["default"].func,
3083
+ document: PropTypes__default["default"].shape({
3084
+ getElementById: PropTypes__default["default"].func,
3085
+ activeElement: PropTypes__default["default"].any,
3086
+ body: PropTypes__default["default"].any
3073
3087
  })
3074
3088
  })
3075
3089
  };
@@ -3087,14 +3101,10 @@ var propTypes$1 = {
3087
3101
  */
3088
3102
 
3089
3103
  function useControlledReducer(reducer, initialState, props) {
3090
- var previousSelectedItemRef = preact.useRef();
3091
-
3092
- var _useEnhancedReducer = useEnhancedReducer(reducer, initialState, props),
3093
- state = _useEnhancedReducer[0],
3094
- dispatch = _useEnhancedReducer[1]; // ToDo: if needed, make same approach as selectedItemChanged from Downshift.
3095
-
3104
+ const previousSelectedItemRef = preact.useRef();
3105
+ const [state, dispatch] = useEnhancedReducer(reducer, initialState, props); // ToDo: if needed, make same approach as selectedItemChanged from Downshift.
3096
3106
 
3097
- preact.useEffect(function () {
3107
+ preact.useEffect(() => {
3098
3108
  if (isControlledProp(props, 'selectedItem')) {
3099
3109
  if (previousSelectedItemRef.current !== props.selectedItem) {
3100
3110
  dispatch({
@@ -3110,27 +3120,29 @@ function useControlledReducer(reducer, initialState, props) {
3110
3120
  } // eslint-disable-next-line import/no-mutable-exports
3111
3121
 
3112
3122
 
3113
- var validatePropTypes$1 = noop;
3123
+ let validatePropTypes$1 = noop;
3114
3124
  /* istanbul ignore next */
3115
3125
 
3116
3126
  if (process.env.NODE_ENV !== 'production') {
3117
- validatePropTypes$1 = function validatePropTypes(options, caller) {
3118
- PropTypes__default['default'].checkPropTypes(propTypes$1, options, 'prop', caller.name);
3127
+ validatePropTypes$1 = (options, caller) => {
3128
+ PropTypes__default["default"].checkPropTypes(propTypes$1, options, 'prop', caller.name);
3119
3129
  };
3120
3130
  }
3121
3131
 
3122
- var defaultProps$1 = _extends__default['default']({}, defaultProps$3, {
3132
+ const defaultProps$1 = { ...defaultProps$3,
3123
3133
  getA11yStatusMessage: getA11yStatusMessage$1,
3124
3134
  circularNavigation: true
3125
- });
3135
+ };
3126
3136
 
3127
3137
  /* eslint-disable complexity */
3128
3138
 
3129
3139
  function downshiftUseComboboxReducer(state, action) {
3130
- var type = action.type,
3131
- props = action.props,
3132
- shiftKey = action.shiftKey;
3133
- var changes;
3140
+ const {
3141
+ type,
3142
+ props,
3143
+ shiftKey
3144
+ } = action;
3145
+ let changes;
3134
3146
 
3135
3147
  switch (type) {
3136
3148
  case ItemClick:
@@ -3171,22 +3183,24 @@ function downshiftUseComboboxReducer(state, action) {
3171
3183
  break;
3172
3184
 
3173
3185
  case InputKeyDownEnter:
3174
- changes = _extends__default['default']({}, state.isOpen && state.highlightedIndex >= 0 && {
3175
- selectedItem: props.items[state.highlightedIndex],
3176
- isOpen: getDefaultValue$1(props, 'isOpen'),
3177
- highlightedIndex: getDefaultValue$1(props, 'highlightedIndex'),
3178
- inputValue: props.itemToString(props.items[state.highlightedIndex])
3179
- });
3186
+ changes = { ...(state.isOpen && state.highlightedIndex >= 0 && {
3187
+ selectedItem: props.items[state.highlightedIndex],
3188
+ isOpen: getDefaultValue$1(props, 'isOpen'),
3189
+ highlightedIndex: getDefaultValue$1(props, 'highlightedIndex'),
3190
+ inputValue: props.itemToString(props.items[state.highlightedIndex])
3191
+ })
3192
+ };
3180
3193
  break;
3181
3194
 
3182
3195
  case InputKeyDownEscape:
3183
- changes = _extends__default['default']({
3196
+ changes = {
3184
3197
  isOpen: false,
3185
- highlightedIndex: -1
3186
- }, !state.isOpen && {
3187
- selectedItem: null,
3188
- inputValue: ''
3189
- });
3198
+ highlightedIndex: -1,
3199
+ ...(!state.isOpen && {
3200
+ selectedItem: null,
3201
+ inputValue: ''
3202
+ })
3203
+ };
3190
3204
  break;
3191
3205
 
3192
3206
  case InputKeyDownHome:
@@ -3202,13 +3216,14 @@ function downshiftUseComboboxReducer(state, action) {
3202
3216
  break;
3203
3217
 
3204
3218
  case InputBlur:
3205
- changes = _extends__default['default']({
3219
+ changes = {
3206
3220
  isOpen: false,
3207
- highlightedIndex: -1
3208
- }, state.highlightedIndex >= 0 && action.selectItem && {
3209
- selectedItem: props.items[state.highlightedIndex],
3210
- inputValue: props.itemToString(props.items[state.highlightedIndex])
3211
- });
3221
+ highlightedIndex: -1,
3222
+ ...(state.highlightedIndex >= 0 && action.selectItem && {
3223
+ selectedItem: props.items[state.highlightedIndex],
3224
+ inputValue: props.itemToString(props.items[state.highlightedIndex])
3225
+ })
3226
+ };
3212
3227
  break;
3213
3228
 
3214
3229
  case InputChange:
@@ -3236,15 +3251,13 @@ function downshiftUseComboboxReducer(state, action) {
3236
3251
  return downshiftCommonReducer(state, action, stateChangeTypes$1);
3237
3252
  }
3238
3253
 
3239
- return _extends__default['default']({}, state, changes);
3254
+ return { ...state,
3255
+ ...changes
3256
+ };
3240
3257
  }
3241
3258
  /* eslint-enable complexity */
3242
3259
 
3243
- var _excluded$1 = ["onMouseLeave", "refKey", "ref"],
3244
- _excluded2$1 = ["item", "index", "refKey", "ref", "onMouseMove", "onClick", "onPress"],
3245
- _excluded3 = ["onClick", "onPress", "refKey", "ref"],
3246
- _excluded4 = ["onKeyDown", "onChange", "onInput", "onBlur", "onChangeText", "refKey", "ref"],
3247
- _excluded5 = ["refKey", "ref"];
3260
+ /* eslint-disable max-statements */
3248
3261
  useCombobox.stateChangeTypes = stateChangeTypes$1;
3249
3262
 
3250
3263
  function useCombobox(userProps) {
@@ -3254,87 +3267,88 @@ function useCombobox(userProps) {
3254
3267
 
3255
3268
  validatePropTypes$1(userProps, useCombobox); // Props defaults and destructuring.
3256
3269
 
3257
- var props = _extends__default['default']({}, defaultProps$1, userProps);
3258
-
3259
- var initialIsOpen = props.initialIsOpen,
3260
- defaultIsOpen = props.defaultIsOpen,
3261
- items = props.items,
3262
- scrollIntoView = props.scrollIntoView,
3263
- environment = props.environment,
3264
- getA11yStatusMessage = props.getA11yStatusMessage,
3265
- getA11ySelectionMessage = props.getA11ySelectionMessage,
3266
- itemToString = props.itemToString; // Initial state depending on controlled props.
3267
-
3268
- var initialState = getInitialState$1(props);
3269
-
3270
- var _useControlledReducer = useControlledReducer(downshiftUseComboboxReducer, initialState, props),
3271
- state = _useControlledReducer[0],
3272
- dispatch = _useControlledReducer[1];
3273
-
3274
- var isOpen = state.isOpen,
3275
- highlightedIndex = state.highlightedIndex,
3276
- selectedItem = state.selectedItem,
3277
- inputValue = state.inputValue; // Element refs.
3278
-
3279
- var menuRef = preact.useRef(null);
3280
- var itemRefs = preact.useRef({});
3281
- var inputRef = preact.useRef(null);
3282
- var toggleButtonRef = preact.useRef(null);
3283
- var comboboxRef = preact.useRef(null);
3284
- var isInitialMountRef = preact.useRef(true); // prevent id re-generation between renders.
3285
-
3286
- var elementIds = useElementIds(props); // used to keep track of how many items we had on previous cycle.
3287
-
3288
- var previousResultCountRef = preact.useRef(); // utility callback to get item element.
3289
-
3290
- var latest = useLatestRef({
3291
- state: state,
3292
- props: props
3270
+ const props = { ...defaultProps$1,
3271
+ ...userProps
3272
+ };
3273
+ const {
3274
+ initialIsOpen,
3275
+ defaultIsOpen,
3276
+ items,
3277
+ scrollIntoView,
3278
+ environment,
3279
+ getA11yStatusMessage,
3280
+ getA11ySelectionMessage,
3281
+ itemToString
3282
+ } = props; // Initial state depending on controlled props.
3283
+
3284
+ const initialState = getInitialState$1(props);
3285
+ const [state, dispatch] = useControlledReducer(downshiftUseComboboxReducer, initialState, props);
3286
+ const {
3287
+ isOpen,
3288
+ highlightedIndex,
3289
+ selectedItem,
3290
+ inputValue
3291
+ } = state; // Element refs.
3292
+
3293
+ const menuRef = preact.useRef(null);
3294
+ const itemRefs = preact.useRef({});
3295
+ const inputRef = preact.useRef(null);
3296
+ const toggleButtonRef = preact.useRef(null);
3297
+ const comboboxRef = preact.useRef(null);
3298
+ const isInitialMountRef = preact.useRef(true); // prevent id re-generation between renders.
3299
+
3300
+ const elementIds = useElementIds(props); // used to keep track of how many items we had on previous cycle.
3301
+
3302
+ const previousResultCountRef = preact.useRef(); // utility callback to get item element.
3303
+
3304
+ const latest = useLatestRef({
3305
+ state,
3306
+ props
3293
3307
  });
3294
- var getItemNodeFromIndex = preact.useCallback(function (index) {
3295
- return itemRefs.current[elementIds.getItemId(index)];
3296
- }, [elementIds]); // Effects.
3308
+ const getItemNodeFromIndex = preact.useCallback(index => itemRefs.current[elementIds.getItemId(index)], [elementIds]); // Effects.
3297
3309
  // Sets a11y status message on changes in state.
3298
3310
 
3299
- useA11yMessageSetter(getA11yStatusMessage, [isOpen, highlightedIndex, inputValue, items], _extends__default['default']({
3311
+ useA11yMessageSetter(getA11yStatusMessage, [isOpen, highlightedIndex, inputValue, items], {
3300
3312
  isInitialMount: isInitialMountRef.current,
3301
3313
  previousResultCount: previousResultCountRef.current,
3302
- items: items,
3303
- environment: environment,
3304
- itemToString: itemToString
3305
- }, state)); // Sets a11y status message on changes in selectedItem.
3314
+ items,
3315
+ environment,
3316
+ itemToString,
3317
+ ...state
3318
+ }); // Sets a11y status message on changes in selectedItem.
3306
3319
 
3307
- useA11yMessageSetter(getA11ySelectionMessage, [selectedItem], _extends__default['default']({
3320
+ useA11yMessageSetter(getA11ySelectionMessage, [selectedItem], {
3308
3321
  isInitialMount: isInitialMountRef.current,
3309
3322
  previousResultCount: previousResultCountRef.current,
3310
- items: items,
3311
- environment: environment,
3312
- itemToString: itemToString
3313
- }, state)); // Scroll on highlighted item if change comes from keyboard.
3323
+ items,
3324
+ environment,
3325
+ itemToString,
3326
+ ...state
3327
+ }); // Scroll on highlighted item if change comes from keyboard.
3314
3328
 
3315
- var shouldScrollRef = useScrollIntoView({
3329
+ const shouldScrollRef = useScrollIntoView({
3316
3330
  menuElement: menuRef.current,
3317
- highlightedIndex: highlightedIndex,
3318
- isOpen: isOpen,
3319
- itemRefs: itemRefs,
3320
- scrollIntoView: scrollIntoView,
3321
- getItemNodeFromIndex: getItemNodeFromIndex
3331
+ highlightedIndex,
3332
+ isOpen,
3333
+ itemRefs,
3334
+ scrollIntoView,
3335
+ getItemNodeFromIndex
3322
3336
  });
3323
3337
  useControlPropsValidator({
3324
3338
  isInitialMount: isInitialMountRef.current,
3325
- props: props,
3326
- state: state
3339
+ props,
3340
+ state
3327
3341
  }); // Focus the input on first render if required.
3328
3342
 
3329
- preact.useEffect(function () {
3330
- var focusOnOpen = initialIsOpen || defaultIsOpen || isOpen;
3343
+ preact.useEffect(() => {
3344
+ const focusOnOpen = initialIsOpen || defaultIsOpen || isOpen;
3331
3345
 
3332
3346
  if (focusOnOpen && inputRef.current) {
3333
3347
  inputRef.current.focus();
3334
3348
  } // eslint-disable-next-line react-hooks/exhaustive-deps
3335
3349
 
3336
3350
  }, []);
3337
- preact.useEffect(function () {
3351
+ preact.useEffect(() => {
3338
3352
  if (isInitialMountRef.current) {
3339
3353
  return;
3340
3354
  }
@@ -3342,147 +3356,151 @@ function useCombobox(userProps) {
3342
3356
  previousResultCountRef.current = items.length;
3343
3357
  }); // Add mouse/touch events to document.
3344
3358
 
3345
- var mouseAndTouchTrackersRef = useMouseAndTouchTracker(isOpen, [comboboxRef, menuRef, toggleButtonRef], environment, function () {
3359
+ const mouseAndTouchTrackersRef = useMouseAndTouchTracker(isOpen, [comboboxRef, menuRef, toggleButtonRef], environment, () => {
3346
3360
  dispatch({
3347
3361
  type: InputBlur,
3348
3362
  selectItem: false
3349
3363
  });
3350
3364
  });
3351
- var setGetterPropCallInfo = useGetterPropsCalledChecker('getInputProps', 'getComboboxProps', 'getMenuProps'); // Make initial ref false.
3365
+ const setGetterPropCallInfo = useGetterPropsCalledChecker('getInputProps', 'getComboboxProps', 'getMenuProps'); // Make initial ref false.
3352
3366
 
3353
- preact.useEffect(function () {
3367
+ preact.useEffect(() => {
3354
3368
  isInitialMountRef.current = false;
3355
3369
  }, []); // Reset itemRefs on close.
3356
3370
 
3357
- preact.useEffect(function () {
3371
+ preact.useEffect(() => {
3358
3372
  if (!isOpen) {
3359
3373
  itemRefs.current = {};
3360
3374
  }
3361
3375
  }, [isOpen]);
3362
3376
  /* Event handler functions */
3363
3377
 
3364
- var inputKeyDownHandlers = preact.useMemo(function () {
3365
- return {
3366
- ArrowDown: function ArrowDown(event) {
3367
- event.preventDefault();
3368
- dispatch({
3369
- type: InputKeyDownArrowDown,
3370
- shiftKey: event.shiftKey,
3371
- getItemNodeFromIndex: getItemNodeFromIndex
3372
- });
3373
- },
3374
- ArrowUp: function ArrowUp(event) {
3375
- event.preventDefault();
3376
- dispatch({
3377
- type: InputKeyDownArrowUp,
3378
- shiftKey: event.shiftKey,
3379
- getItemNodeFromIndex: getItemNodeFromIndex
3380
- });
3381
- },
3382
- Home: function Home(event) {
3383
- if (!latest.current.state.isOpen) {
3384
- return;
3385
- }
3378
+ const inputKeyDownHandlers = preact.useMemo(() => ({
3379
+ ArrowDown(event) {
3380
+ event.preventDefault();
3381
+ dispatch({
3382
+ type: InputKeyDownArrowDown,
3383
+ shiftKey: event.shiftKey,
3384
+ getItemNodeFromIndex
3385
+ });
3386
+ },
3386
3387
 
3387
- event.preventDefault();
3388
- dispatch({
3389
- type: InputKeyDownHome,
3390
- getItemNodeFromIndex: getItemNodeFromIndex
3391
- });
3392
- },
3393
- End: function End(event) {
3394
- if (!latest.current.state.isOpen) {
3395
- return;
3396
- }
3388
+ ArrowUp(event) {
3389
+ event.preventDefault();
3390
+ dispatch({
3391
+ type: InputKeyDownArrowUp,
3392
+ shiftKey: event.shiftKey,
3393
+ getItemNodeFromIndex
3394
+ });
3395
+ },
3397
3396
 
3398
- event.preventDefault();
3399
- dispatch({
3400
- type: InputKeyDownEnd,
3401
- getItemNodeFromIndex: getItemNodeFromIndex
3402
- });
3403
- },
3404
- Escape: function Escape() {
3405
- var latestState = latest.current.state;
3397
+ Home(event) {
3398
+ if (!latest.current.state.isOpen) {
3399
+ return;
3400
+ }
3406
3401
 
3407
- if (latestState.isOpen || latestState.inputValue || latestState.selectedItem || latestState.highlightedIndex > -1) {
3408
- dispatch({
3409
- type: InputKeyDownEscape
3410
- });
3411
- }
3412
- },
3413
- Enter: function Enter(event) {
3414
- var latestState = latest.current.state; // if closed or no highlighted index, do nothing.
3402
+ event.preventDefault();
3403
+ dispatch({
3404
+ type: InputKeyDownHome,
3405
+ getItemNodeFromIndex
3406
+ });
3407
+ },
3415
3408
 
3416
- if (!latestState.isOpen || latestState.highlightedIndex < 0 || event.which === 229 // if IME composing, wait for next Enter keydown event.
3417
- ) {
3418
- return;
3419
- }
3409
+ End(event) {
3410
+ if (!latest.current.state.isOpen) {
3411
+ return;
3412
+ }
3420
3413
 
3421
- event.preventDefault();
3414
+ event.preventDefault();
3415
+ dispatch({
3416
+ type: InputKeyDownEnd,
3417
+ getItemNodeFromIndex
3418
+ });
3419
+ },
3420
+
3421
+ Escape() {
3422
+ const latestState = latest.current.state;
3423
+
3424
+ if (latestState.isOpen || latestState.inputValue || latestState.selectedItem || latestState.highlightedIndex > -1) {
3422
3425
  dispatch({
3423
- type: InputKeyDownEnter,
3424
- getItemNodeFromIndex: getItemNodeFromIndex
3426
+ type: InputKeyDownEscape
3425
3427
  });
3426
3428
  }
3427
- };
3428
- }, [dispatch, latest, getItemNodeFromIndex]); // Getter props.
3429
-
3430
- var getLabelProps = preact.useCallback(function (labelProps) {
3431
- return _extends__default['default']({
3432
- id: elementIds.labelId,
3433
- htmlFor: elementIds.inputId
3434
- }, labelProps);
3435
- }, [elementIds]);
3436
- var getMenuProps = preact.useCallback(function (_temp, _temp2) {
3437
- var _extends2;
3438
-
3439
- var _ref = _temp === void 0 ? {} : _temp,
3440
- onMouseLeave = _ref.onMouseLeave,
3441
- _ref$refKey = _ref.refKey,
3442
- refKey = _ref$refKey === void 0 ? 'ref' : _ref$refKey,
3443
- ref = _ref.ref,
3444
- rest = _objectWithoutPropertiesLoose__default['default'](_ref, _excluded$1);
3445
-
3446
- var _ref2 = _temp2 === void 0 ? {} : _temp2,
3447
- _ref2$suppressRefErro = _ref2.suppressRefError,
3448
- suppressRefError = _ref2$suppressRefErro === void 0 ? false : _ref2$suppressRefErro;
3429
+ },
3449
3430
 
3450
- setGetterPropCallInfo('getMenuProps', suppressRefError, refKey, menuRef);
3451
- return _extends__default['default']((_extends2 = {}, _extends2[refKey] = handleRefs(ref, function (menuNode) {
3452
- menuRef.current = menuNode;
3453
- }), _extends2.id = elementIds.menuId, _extends2.role = 'listbox', _extends2['aria-labelledby'] = elementIds.labelId, _extends2.onMouseLeave = callAllEventHandlers(onMouseLeave, function () {
3431
+ Enter(event) {
3432
+ const latestState = latest.current.state; // if closed or no highlighted index, do nothing.
3433
+
3434
+ if (!latestState.isOpen || latestState.highlightedIndex < 0 || event.which === 229 // if IME composing, wait for next Enter keydown event.
3435
+ ) {
3436
+ return;
3437
+ }
3438
+
3439
+ event.preventDefault();
3454
3440
  dispatch({
3455
- type: MenuMouseLeave
3441
+ type: InputKeyDownEnter,
3442
+ getItemNodeFromIndex
3456
3443
  });
3457
- }), _extends2), rest);
3444
+ }
3445
+
3446
+ }), [dispatch, latest, getItemNodeFromIndex]); // Getter props.
3447
+
3448
+ const getLabelProps = preact.useCallback(labelProps => ({
3449
+ id: elementIds.labelId,
3450
+ htmlFor: elementIds.inputId,
3451
+ ...labelProps
3452
+ }), [elementIds]);
3453
+ const getMenuProps = preact.useCallback(function (_temp, _temp2) {
3454
+ let {
3455
+ onMouseLeave,
3456
+ refKey = 'ref',
3457
+ ref,
3458
+ ...rest
3459
+ } = _temp === void 0 ? {} : _temp;
3460
+ let {
3461
+ suppressRefError = false
3462
+ } = _temp2 === void 0 ? {} : _temp2;
3463
+ setGetterPropCallInfo('getMenuProps', suppressRefError, refKey, menuRef);
3464
+ return {
3465
+ [refKey]: handleRefs(ref, menuNode => {
3466
+ menuRef.current = menuNode;
3467
+ }),
3468
+ id: elementIds.menuId,
3469
+ role: 'listbox',
3470
+ 'aria-labelledby': elementIds.labelId,
3471
+ onMouseLeave: callAllEventHandlers(onMouseLeave, () => {
3472
+ dispatch({
3473
+ type: MenuMouseLeave
3474
+ });
3475
+ }),
3476
+ ...rest
3477
+ };
3458
3478
  }, [dispatch, setGetterPropCallInfo, elementIds]);
3459
- var getItemProps = preact.useCallback(function (_temp3) {
3460
- var _extends3, _ref4;
3461
-
3462
- var _ref3 = _temp3 === void 0 ? {} : _temp3,
3463
- item = _ref3.item,
3464
- index = _ref3.index,
3465
- _ref3$refKey = _ref3.refKey,
3466
- refKey = _ref3$refKey === void 0 ? 'ref' : _ref3$refKey,
3467
- ref = _ref3.ref,
3468
- onMouseMove = _ref3.onMouseMove,
3469
- onClick = _ref3.onClick;
3470
- _ref3.onPress;
3471
- var rest = _objectWithoutPropertiesLoose__default['default'](_ref3, _excluded2$1);
3472
-
3473
- var _latest$current = latest.current,
3474
- latestProps = _latest$current.props,
3475
- latestState = _latest$current.state;
3476
- var itemIndex = getItemIndex(index, item, latestProps.items);
3479
+ const getItemProps = preact.useCallback(function (_temp3) {
3480
+ let {
3481
+ item,
3482
+ index,
3483
+ refKey = 'ref',
3484
+ ref,
3485
+ onMouseMove,
3486
+ onClick,
3487
+ onPress,
3488
+ ...rest
3489
+ } = _temp3 === void 0 ? {} : _temp3;
3490
+ const {
3491
+ props: latestProps,
3492
+ state: latestState
3493
+ } = latest.current;
3494
+ const itemIndex = getItemIndex(index, item, latestProps.items);
3477
3495
 
3478
3496
  if (itemIndex < 0) {
3479
3497
  throw new Error('Pass either item or item index in getItemProps!');
3480
3498
  }
3481
3499
 
3482
- var onSelectKey = 'onClick';
3483
- var customClickHandler = onClick;
3500
+ const onSelectKey = 'onClick';
3501
+ const customClickHandler = onClick;
3484
3502
 
3485
- var itemHandleMouseMove = function itemHandleMouseMove() {
3503
+ const itemHandleMouseMove = () => {
3486
3504
  if (index === latestState.highlightedIndex) {
3487
3505
  return;
3488
3506
  }
@@ -3490,14 +3508,14 @@ function useCombobox(userProps) {
3490
3508
  shouldScrollRef.current = false;
3491
3509
  dispatch({
3492
3510
  type: ItemMouseMove,
3493
- index: index
3511
+ index
3494
3512
  });
3495
3513
  };
3496
3514
 
3497
- var itemHandleClick = function itemHandleClick() {
3515
+ const itemHandleClick = () => {
3498
3516
  dispatch({
3499
3517
  type: ItemClick,
3500
- index: index
3518
+ index
3501
3519
  });
3502
3520
 
3503
3521
  if (inputRef.current) {
@@ -3505,26 +3523,32 @@ function useCombobox(userProps) {
3505
3523
  }
3506
3524
  };
3507
3525
 
3508
- return _extends__default['default']((_extends3 = {}, _extends3[refKey] = handleRefs(ref, function (itemNode) {
3509
- if (itemNode) {
3510
- itemRefs.current[elementIds.getItemId(itemIndex)] = itemNode;
3511
- }
3512
- }), _extends3.role = 'option', _extends3['aria-selected'] = "" + (itemIndex === latestState.highlightedIndex), _extends3.id = elementIds.getItemId(itemIndex), _extends3), !rest.disabled && (_ref4 = {
3513
- onMouseMove: callAllEventHandlers(onMouseMove, itemHandleMouseMove)
3514
- }, _ref4[onSelectKey] = callAllEventHandlers(customClickHandler, itemHandleClick), _ref4), rest);
3526
+ return {
3527
+ [refKey]: handleRefs(ref, itemNode => {
3528
+ if (itemNode) {
3529
+ itemRefs.current[elementIds.getItemId(itemIndex)] = itemNode;
3530
+ }
3531
+ }),
3532
+ role: 'option',
3533
+ 'aria-selected': "" + (itemIndex === latestState.highlightedIndex),
3534
+ id: elementIds.getItemId(itemIndex),
3535
+ ...(!rest.disabled && {
3536
+ onMouseMove: callAllEventHandlers(onMouseMove, itemHandleMouseMove),
3537
+ [onSelectKey]: callAllEventHandlers(customClickHandler, itemHandleClick)
3538
+ }),
3539
+ ...rest
3540
+ };
3515
3541
  }, [dispatch, latest, shouldScrollRef, elementIds]);
3516
- var getToggleButtonProps = preact.useCallback(function (_temp4) {
3517
- var _extends4;
3518
-
3519
- var _ref5 = _temp4 === void 0 ? {} : _temp4,
3520
- onClick = _ref5.onClick;
3521
- _ref5.onPress;
3522
- var _ref5$refKey = _ref5.refKey,
3523
- refKey = _ref5$refKey === void 0 ? 'ref' : _ref5$refKey,
3524
- ref = _ref5.ref,
3525
- rest = _objectWithoutPropertiesLoose__default['default'](_ref5, _excluded3);
3526
-
3527
- var toggleButtonHandleClick = function toggleButtonHandleClick() {
3542
+ const getToggleButtonProps = preact.useCallback(function (_temp4) {
3543
+ let {
3544
+ onClick,
3545
+ onPress,
3546
+ refKey = 'ref',
3547
+ ref,
3548
+ ...rest
3549
+ } = _temp4 === void 0 ? {} : _temp4;
3550
+
3551
+ const toggleButtonHandleClick = () => {
3528
3552
  dispatch({
3529
3553
  type: ToggleButtonClick
3530
3554
  });
@@ -3534,49 +3558,52 @@ function useCombobox(userProps) {
3534
3558
  }
3535
3559
  };
3536
3560
 
3537
- return _extends__default['default']((_extends4 = {}, _extends4[refKey] = handleRefs(ref, function (toggleButtonNode) {
3538
- toggleButtonRef.current = toggleButtonNode;
3539
- }), _extends4.id = elementIds.toggleButtonId, _extends4.tabIndex = -1, _extends4), !rest.disabled && _extends__default['default']({}, {
3540
- onClick: callAllEventHandlers(onClick, toggleButtonHandleClick)
3541
- }), rest);
3561
+ return {
3562
+ [refKey]: handleRefs(ref, toggleButtonNode => {
3563
+ toggleButtonRef.current = toggleButtonNode;
3564
+ }),
3565
+ id: elementIds.toggleButtonId,
3566
+ tabIndex: -1,
3567
+ ...(!rest.disabled && { ...({
3568
+ onClick: callAllEventHandlers(onClick, toggleButtonHandleClick)
3569
+ })
3570
+ }),
3571
+ ...rest
3572
+ };
3542
3573
  }, [dispatch, latest, elementIds]);
3543
- var getInputProps = preact.useCallback(function (_temp5, _temp6) {
3544
- var _extends5;
3545
-
3546
- var _ref6 = _temp5 === void 0 ? {} : _temp5,
3547
- onKeyDown = _ref6.onKeyDown,
3548
- onChange = _ref6.onChange,
3549
- onInput = _ref6.onInput,
3550
- onBlur = _ref6.onBlur;
3551
- _ref6.onChangeText;
3552
- var _ref6$refKey = _ref6.refKey,
3553
- refKey = _ref6$refKey === void 0 ? 'ref' : _ref6$refKey,
3554
- ref = _ref6.ref,
3555
- rest = _objectWithoutPropertiesLoose__default['default'](_ref6, _excluded4);
3556
-
3557
- var _ref7 = _temp6 === void 0 ? {} : _temp6,
3558
- _ref7$suppressRefErro = _ref7.suppressRefError,
3559
- suppressRefError = _ref7$suppressRefErro === void 0 ? false : _ref7$suppressRefErro;
3560
-
3574
+ const getInputProps = preact.useCallback(function (_temp5, _temp6) {
3575
+ let {
3576
+ onKeyDown,
3577
+ onChange,
3578
+ onInput,
3579
+ onBlur,
3580
+ onChangeText,
3581
+ refKey = 'ref',
3582
+ ref,
3583
+ ...rest
3584
+ } = _temp5 === void 0 ? {} : _temp5;
3585
+ let {
3586
+ suppressRefError = false
3587
+ } = _temp6 === void 0 ? {} : _temp6;
3561
3588
  setGetterPropCallInfo('getInputProps', suppressRefError, refKey, inputRef);
3562
- var latestState = latest.current.state;
3589
+ const latestState = latest.current.state;
3563
3590
 
3564
- var inputHandleKeyDown = function inputHandleKeyDown(event) {
3565
- var key = normalizeArrowKey(event);
3591
+ const inputHandleKeyDown = event => {
3592
+ const key = normalizeArrowKey(event);
3566
3593
 
3567
3594
  if (key && inputKeyDownHandlers[key]) {
3568
3595
  inputKeyDownHandlers[key](event);
3569
3596
  }
3570
3597
  };
3571
3598
 
3572
- var inputHandleChange = function inputHandleChange(event) {
3599
+ const inputHandleChange = event => {
3573
3600
  dispatch({
3574
3601
  type: InputChange,
3575
3602
  inputValue: event.target.value
3576
3603
  });
3577
3604
  };
3578
3605
 
3579
- var inputHandleBlur = function inputHandleBlur() {
3606
+ const inputHandleBlur = () => {
3580
3607
  /* istanbul ignore else */
3581
3608
  if (latestState.isOpen && !mouseAndTouchTrackersRef.current.isMouseDown) {
3582
3609
  dispatch({
@@ -3588,109 +3615,121 @@ function useCombobox(userProps) {
3588
3615
  /* istanbul ignore next (preact) */
3589
3616
 
3590
3617
 
3591
- var onChangeKey = 'onInput' ;
3592
- var eventHandlers = {};
3618
+ const onChangeKey = 'onInput' ;
3619
+ let eventHandlers = {};
3593
3620
 
3594
3621
  if (!rest.disabled) {
3595
- var _eventHandlers;
3596
-
3597
- eventHandlers = (_eventHandlers = {}, _eventHandlers[onChangeKey] = callAllEventHandlers(onChange, onInput, inputHandleChange), _eventHandlers.onKeyDown = callAllEventHandlers(onKeyDown, inputHandleKeyDown), _eventHandlers.onBlur = callAllEventHandlers(onBlur, inputHandleBlur), _eventHandlers);
3622
+ eventHandlers = {
3623
+ [onChangeKey]: callAllEventHandlers(onChange, onInput, inputHandleChange),
3624
+ onKeyDown: callAllEventHandlers(onKeyDown, inputHandleKeyDown),
3625
+ onBlur: callAllEventHandlers(onBlur, inputHandleBlur)
3626
+ };
3598
3627
  }
3599
3628
 
3600
- return _extends__default['default']((_extends5 = {}, _extends5[refKey] = handleRefs(ref, function (inputNode) {
3601
- inputRef.current = inputNode;
3602
- }), _extends5.id = elementIds.inputId, _extends5['aria-autocomplete'] = 'list', _extends5['aria-controls'] = elementIds.menuId, _extends5), latestState.isOpen && latestState.highlightedIndex > -1 && {
3603
- 'aria-activedescendant': elementIds.getItemId(latestState.highlightedIndex)
3604
- }, {
3629
+ return {
3630
+ [refKey]: handleRefs(ref, inputNode => {
3631
+ inputRef.current = inputNode;
3632
+ }),
3633
+ id: elementIds.inputId,
3634
+ 'aria-autocomplete': 'list',
3635
+ 'aria-controls': elementIds.menuId,
3636
+ ...(latestState.isOpen && latestState.highlightedIndex > -1 && {
3637
+ 'aria-activedescendant': elementIds.getItemId(latestState.highlightedIndex)
3638
+ }),
3605
3639
  'aria-labelledby': elementIds.labelId,
3606
3640
  // https://developer.mozilla.org/en-US/docs/Web/Security/Securing_your_site/Turning_off_form_autocompletion
3607
3641
  // revert back since autocomplete="nope" is ignored on latest Chrome and Opera
3608
3642
  autoComplete: 'off',
3609
- value: latestState.inputValue
3610
- }, eventHandlers, rest);
3643
+ value: latestState.inputValue,
3644
+ ...eventHandlers,
3645
+ ...rest
3646
+ };
3611
3647
  }, [dispatch, inputKeyDownHandlers, latest, mouseAndTouchTrackersRef, setGetterPropCallInfo, elementIds]);
3612
- var getComboboxProps = preact.useCallback(function (_temp7, _temp8) {
3613
- var _extends6;
3614
-
3615
- var _ref8 = _temp7 === void 0 ? {} : _temp7,
3616
- _ref8$refKey = _ref8.refKey,
3617
- refKey = _ref8$refKey === void 0 ? 'ref' : _ref8$refKey,
3618
- ref = _ref8.ref,
3619
- rest = _objectWithoutPropertiesLoose__default['default'](_ref8, _excluded5);
3620
-
3621
- var _ref9 = _temp8 === void 0 ? {} : _temp8,
3622
- _ref9$suppressRefErro = _ref9.suppressRefError,
3623
- suppressRefError = _ref9$suppressRefErro === void 0 ? false : _ref9$suppressRefErro;
3624
-
3648
+ const getComboboxProps = preact.useCallback(function (_temp7, _temp8) {
3649
+ let {
3650
+ refKey = 'ref',
3651
+ ref,
3652
+ ...rest
3653
+ } = _temp7 === void 0 ? {} : _temp7;
3654
+ let {
3655
+ suppressRefError = false
3656
+ } = _temp8 === void 0 ? {} : _temp8;
3625
3657
  setGetterPropCallInfo('getComboboxProps', suppressRefError, refKey, comboboxRef);
3626
- return _extends__default['default']((_extends6 = {}, _extends6[refKey] = handleRefs(ref, function (comboboxNode) {
3627
- comboboxRef.current = comboboxNode;
3628
- }), _extends6.role = 'combobox', _extends6['aria-haspopup'] = 'listbox', _extends6['aria-owns'] = elementIds.menuId, _extends6['aria-expanded'] = latest.current.state.isOpen, _extends6), rest);
3658
+ return {
3659
+ [refKey]: handleRefs(ref, comboboxNode => {
3660
+ comboboxRef.current = comboboxNode;
3661
+ }),
3662
+ role: 'combobox',
3663
+ 'aria-haspopup': 'listbox',
3664
+ 'aria-owns': elementIds.menuId,
3665
+ 'aria-expanded': latest.current.state.isOpen,
3666
+ ...rest
3667
+ };
3629
3668
  }, [latest, setGetterPropCallInfo, elementIds]); // returns
3630
3669
 
3631
- var toggleMenu = preact.useCallback(function () {
3670
+ const toggleMenu = preact.useCallback(() => {
3632
3671
  dispatch({
3633
3672
  type: FunctionToggleMenu
3634
3673
  });
3635
3674
  }, [dispatch]);
3636
- var closeMenu = preact.useCallback(function () {
3675
+ const closeMenu = preact.useCallback(() => {
3637
3676
  dispatch({
3638
3677
  type: FunctionCloseMenu
3639
3678
  });
3640
3679
  }, [dispatch]);
3641
- var openMenu = preact.useCallback(function () {
3680
+ const openMenu = preact.useCallback(() => {
3642
3681
  dispatch({
3643
3682
  type: FunctionOpenMenu
3644
3683
  });
3645
3684
  }, [dispatch]);
3646
- var setHighlightedIndex = preact.useCallback(function (newHighlightedIndex) {
3685
+ const setHighlightedIndex = preact.useCallback(newHighlightedIndex => {
3647
3686
  dispatch({
3648
3687
  type: FunctionSetHighlightedIndex,
3649
3688
  highlightedIndex: newHighlightedIndex
3650
3689
  });
3651
3690
  }, [dispatch]);
3652
- var selectItem = preact.useCallback(function (newSelectedItem) {
3691
+ const selectItem = preact.useCallback(newSelectedItem => {
3653
3692
  dispatch({
3654
3693
  type: FunctionSelectItem,
3655
3694
  selectedItem: newSelectedItem
3656
3695
  });
3657
3696
  }, [dispatch]);
3658
- var setInputValue = preact.useCallback(function (newInputValue) {
3697
+ const setInputValue = preact.useCallback(newInputValue => {
3659
3698
  dispatch({
3660
3699
  type: FunctionSetInputValue,
3661
3700
  inputValue: newInputValue
3662
3701
  });
3663
3702
  }, [dispatch]);
3664
- var reset = preact.useCallback(function () {
3703
+ const reset = preact.useCallback(() => {
3665
3704
  dispatch({
3666
3705
  type: FunctionReset$1
3667
3706
  });
3668
3707
  }, [dispatch]);
3669
3708
  return {
3670
3709
  // prop getters.
3671
- getItemProps: getItemProps,
3672
- getLabelProps: getLabelProps,
3673
- getMenuProps: getMenuProps,
3674
- getInputProps: getInputProps,
3675
- getComboboxProps: getComboboxProps,
3676
- getToggleButtonProps: getToggleButtonProps,
3710
+ getItemProps,
3711
+ getLabelProps,
3712
+ getMenuProps,
3713
+ getInputProps,
3714
+ getComboboxProps,
3715
+ getToggleButtonProps,
3677
3716
  // actions.
3678
- toggleMenu: toggleMenu,
3679
- openMenu: openMenu,
3680
- closeMenu: closeMenu,
3681
- setHighlightedIndex: setHighlightedIndex,
3682
- setInputValue: setInputValue,
3683
- selectItem: selectItem,
3684
- reset: reset,
3717
+ toggleMenu,
3718
+ openMenu,
3719
+ closeMenu,
3720
+ setHighlightedIndex,
3721
+ setInputValue,
3722
+ selectItem,
3723
+ reset,
3685
3724
  // state.
3686
- highlightedIndex: highlightedIndex,
3687
- isOpen: isOpen,
3688
- selectedItem: selectedItem,
3689
- inputValue: inputValue
3725
+ highlightedIndex,
3726
+ isOpen,
3727
+ selectedItem,
3728
+ inputValue
3690
3729
  };
3691
3730
  }
3692
3731
 
3693
- var defaultStateValues = {
3732
+ const defaultStateValues = {
3694
3733
  activeIndex: -1,
3695
3734
  selectedItems: []
3696
3735
  };
@@ -3730,11 +3769,11 @@ function getDefaultValue(props, propKey) {
3730
3769
 
3731
3770
 
3732
3771
  function getInitialState(props) {
3733
- var activeIndex = getInitialValue(props, 'activeIndex');
3734
- var selectedItems = getInitialValue(props, 'selectedItems');
3772
+ const activeIndex = getInitialValue(props, 'activeIndex');
3773
+ const selectedItems = getInitialValue(props, 'selectedItems');
3735
3774
  return {
3736
- activeIndex: activeIndex,
3737
- selectedItems: selectedItems
3775
+ activeIndex,
3776
+ selectedItems
3738
3777
  };
3739
3778
  }
3740
3779
  /**
@@ -3753,10 +3792,12 @@ function isKeyDownOperationPermitted(event) {
3753
3792
  return false;
3754
3793
  }
3755
3794
 
3756
- var element = event.target;
3795
+ const element = event.target;
3757
3796
 
3758
3797
  if (element instanceof HTMLInputElement && // if element is a text input
3759
- element.value !== '' && (element.selectionStart !== 0 || element.selectionEnd !== 0)) {
3798
+ element.value !== '' && ( // and we have text in it
3799
+ // and cursor is either not at the start or is currently highlighting text.
3800
+ element.selectionStart !== 0 || element.selectionEnd !== 0)) {
3760
3801
  return false;
3761
3802
  }
3762
3803
 
@@ -3771,66 +3812,68 @@ function isKeyDownOperationPermitted(event) {
3771
3812
 
3772
3813
 
3773
3814
  function getA11yRemovalMessage(selectionParameters) {
3774
- var removedSelectedItem = selectionParameters.removedSelectedItem,
3775
- itemToStringLocal = selectionParameters.itemToString;
3815
+ const {
3816
+ removedSelectedItem,
3817
+ itemToString: itemToStringLocal
3818
+ } = selectionParameters;
3776
3819
  return itemToStringLocal(removedSelectedItem) + " has been removed.";
3777
3820
  }
3778
3821
 
3779
- var propTypes = {
3780
- selectedItems: PropTypes__default['default'].array,
3781
- initialSelectedItems: PropTypes__default['default'].array,
3782
- defaultSelectedItems: PropTypes__default['default'].array,
3783
- itemToString: PropTypes__default['default'].func,
3784
- getA11yRemovalMessage: PropTypes__default['default'].func,
3785
- stateReducer: PropTypes__default['default'].func,
3786
- activeIndex: PropTypes__default['default'].number,
3787
- initialActiveIndex: PropTypes__default['default'].number,
3788
- defaultActiveIndex: PropTypes__default['default'].number,
3789
- onActiveIndexChange: PropTypes__default['default'].func,
3790
- onSelectedItemsChange: PropTypes__default['default'].func,
3791
- keyNavigationNext: PropTypes__default['default'].string,
3792
- keyNavigationPrevious: PropTypes__default['default'].string,
3793
- environment: PropTypes__default['default'].shape({
3794
- addEventListener: PropTypes__default['default'].func,
3795
- removeEventListener: PropTypes__default['default'].func,
3796
- document: PropTypes__default['default'].shape({
3797
- getElementById: PropTypes__default['default'].func,
3798
- activeElement: PropTypes__default['default'].any,
3799
- body: PropTypes__default['default'].any
3822
+ const propTypes = {
3823
+ selectedItems: PropTypes__default["default"].array,
3824
+ initialSelectedItems: PropTypes__default["default"].array,
3825
+ defaultSelectedItems: PropTypes__default["default"].array,
3826
+ itemToString: PropTypes__default["default"].func,
3827
+ getA11yRemovalMessage: PropTypes__default["default"].func,
3828
+ stateReducer: PropTypes__default["default"].func,
3829
+ activeIndex: PropTypes__default["default"].number,
3830
+ initialActiveIndex: PropTypes__default["default"].number,
3831
+ defaultActiveIndex: PropTypes__default["default"].number,
3832
+ onActiveIndexChange: PropTypes__default["default"].func,
3833
+ onSelectedItemsChange: PropTypes__default["default"].func,
3834
+ keyNavigationNext: PropTypes__default["default"].string,
3835
+ keyNavigationPrevious: PropTypes__default["default"].string,
3836
+ environment: PropTypes__default["default"].shape({
3837
+ addEventListener: PropTypes__default["default"].func,
3838
+ removeEventListener: PropTypes__default["default"].func,
3839
+ document: PropTypes__default["default"].shape({
3840
+ getElementById: PropTypes__default["default"].func,
3841
+ activeElement: PropTypes__default["default"].any,
3842
+ body: PropTypes__default["default"].any
3800
3843
  })
3801
3844
  })
3802
3845
  };
3803
- var defaultProps = {
3846
+ const defaultProps = {
3804
3847
  itemToString: defaultProps$3.itemToString,
3805
3848
  stateReducer: defaultProps$3.stateReducer,
3806
3849
  environment: defaultProps$3.environment,
3807
- getA11yRemovalMessage: getA11yRemovalMessage,
3850
+ getA11yRemovalMessage,
3808
3851
  keyNavigationNext: 'ArrowRight',
3809
3852
  keyNavigationPrevious: 'ArrowLeft'
3810
3853
  }; // eslint-disable-next-line import/no-mutable-exports
3811
3854
 
3812
- var validatePropTypes = noop;
3855
+ let validatePropTypes = noop;
3813
3856
  /* istanbul ignore next */
3814
3857
 
3815
3858
  if (process.env.NODE_ENV !== 'production') {
3816
- validatePropTypes = function validatePropTypes(options, caller) {
3817
- PropTypes__default['default'].checkPropTypes(propTypes, options, 'prop', caller.name);
3859
+ validatePropTypes = (options, caller) => {
3860
+ PropTypes__default["default"].checkPropTypes(propTypes, options, 'prop', caller.name);
3818
3861
  };
3819
3862
  }
3820
3863
 
3821
- var SelectedItemClick = process.env.NODE_ENV !== "production" ? '__selected_item_click__' : 0;
3822
- var SelectedItemKeyDownDelete = process.env.NODE_ENV !== "production" ? '__selected_item_keydown_delete__' : 1;
3823
- var SelectedItemKeyDownBackspace = process.env.NODE_ENV !== "production" ? '__selected_item_keydown_backspace__' : 2;
3824
- var SelectedItemKeyDownNavigationNext = process.env.NODE_ENV !== "production" ? '__selected_item_keydown_navigation_next__' : 3;
3825
- var SelectedItemKeyDownNavigationPrevious = process.env.NODE_ENV !== "production" ? '__selected_item_keydown_navigation_previous__' : 4;
3826
- var DropdownKeyDownNavigationPrevious = process.env.NODE_ENV !== "production" ? '__dropdown_keydown_navigation_previous__' : 5;
3827
- var DropdownKeyDownBackspace = process.env.NODE_ENV !== "production" ? '__dropdown_keydown_backspace__' : 6;
3828
- var DropdownClick = process.env.NODE_ENV !== "production" ? '__dropdown_click__' : 7;
3829
- var FunctionAddSelectedItem = process.env.NODE_ENV !== "production" ? '__function_add_selected_item__' : 8;
3830
- var FunctionRemoveSelectedItem = process.env.NODE_ENV !== "production" ? '__function_remove_selected_item__' : 9;
3831
- var FunctionSetSelectedItems = process.env.NODE_ENV !== "production" ? '__function_set_selected_items__' : 10;
3832
- var FunctionSetActiveIndex = process.env.NODE_ENV !== "production" ? '__function_set_active_index__' : 11;
3833
- var FunctionReset = process.env.NODE_ENV !== "production" ? '__function_reset__' : 12;
3864
+ const SelectedItemClick = process.env.NODE_ENV !== "production" ? '__selected_item_click__' : 0;
3865
+ const SelectedItemKeyDownDelete = process.env.NODE_ENV !== "production" ? '__selected_item_keydown_delete__' : 1;
3866
+ const SelectedItemKeyDownBackspace = process.env.NODE_ENV !== "production" ? '__selected_item_keydown_backspace__' : 2;
3867
+ const SelectedItemKeyDownNavigationNext = process.env.NODE_ENV !== "production" ? '__selected_item_keydown_navigation_next__' : 3;
3868
+ const SelectedItemKeyDownNavigationPrevious = process.env.NODE_ENV !== "production" ? '__selected_item_keydown_navigation_previous__' : 4;
3869
+ const DropdownKeyDownNavigationPrevious = process.env.NODE_ENV !== "production" ? '__dropdown_keydown_navigation_previous__' : 5;
3870
+ const DropdownKeyDownBackspace = process.env.NODE_ENV !== "production" ? '__dropdown_keydown_backspace__' : 6;
3871
+ const DropdownClick = process.env.NODE_ENV !== "production" ? '__dropdown_click__' : 7;
3872
+ const FunctionAddSelectedItem = process.env.NODE_ENV !== "production" ? '__function_add_selected_item__' : 8;
3873
+ const FunctionRemoveSelectedItem = process.env.NODE_ENV !== "production" ? '__function_remove_selected_item__' : 9;
3874
+ const FunctionSetSelectedItems = process.env.NODE_ENV !== "production" ? '__function_set_selected_items__' : 10;
3875
+ const FunctionSetActiveIndex = process.env.NODE_ENV !== "production" ? '__function_set_active_index__' : 11;
3876
+ const FunctionReset = process.env.NODE_ENV !== "production" ? '__function_reset__' : 12;
3834
3877
 
3835
3878
  var stateChangeTypes = /*#__PURE__*/Object.freeze({
3836
3879
  __proto__: null,
@@ -3852,13 +3895,17 @@ var stateChangeTypes = /*#__PURE__*/Object.freeze({
3852
3895
  /* eslint-disable complexity */
3853
3896
 
3854
3897
  function downshiftMultipleSelectionReducer(state, action) {
3855
- var type = action.type,
3856
- index = action.index,
3857
- props = action.props,
3858
- selectedItem = action.selectedItem;
3859
- var activeIndex = state.activeIndex,
3860
- selectedItems = state.selectedItems;
3861
- var changes;
3898
+ const {
3899
+ type,
3900
+ index,
3901
+ props,
3902
+ selectedItem
3903
+ } = action;
3904
+ const {
3905
+ activeIndex,
3906
+ selectedItems
3907
+ } = state;
3908
+ let changes;
3862
3909
 
3863
3910
  switch (type) {
3864
3911
  case SelectedItemClick:
@@ -3882,7 +3929,7 @@ function downshiftMultipleSelectionReducer(state, action) {
3882
3929
  case SelectedItemKeyDownBackspace:
3883
3930
  case SelectedItemKeyDownDelete:
3884
3931
  {
3885
- var newActiveIndex = activeIndex;
3932
+ let newActiveIndex = activeIndex;
3886
3933
 
3887
3934
  if (selectedItems.length === 1) {
3888
3935
  newActiveIndex = -1;
@@ -3890,11 +3937,12 @@ function downshiftMultipleSelectionReducer(state, action) {
3890
3937
  newActiveIndex = selectedItems.length - 2;
3891
3938
  }
3892
3939
 
3893
- changes = _extends__default['default']({
3894
- selectedItems: [].concat(selectedItems.slice(0, activeIndex), selectedItems.slice(activeIndex + 1))
3895
- }, {
3896
- activeIndex: newActiveIndex
3897
- });
3940
+ changes = {
3941
+ selectedItems: [...selectedItems.slice(0, activeIndex), ...selectedItems.slice(activeIndex + 1)],
3942
+ ...{
3943
+ activeIndex: newActiveIndex
3944
+ }
3945
+ };
3898
3946
  break;
3899
3947
  }
3900
3948
 
@@ -3912,7 +3960,7 @@ function downshiftMultipleSelectionReducer(state, action) {
3912
3960
 
3913
3961
  case FunctionAddSelectedItem:
3914
3962
  changes = {
3915
- selectedItems: [].concat(selectedItems, [selectedItem])
3963
+ selectedItems: [...selectedItems, selectedItem]
3916
3964
  };
3917
3965
  break;
3918
3966
 
@@ -3924,26 +3972,30 @@ function downshiftMultipleSelectionReducer(state, action) {
3924
3972
 
3925
3973
  case FunctionRemoveSelectedItem:
3926
3974
  {
3927
- var _newActiveIndex = activeIndex;
3928
- var selectedItemIndex = selectedItems.indexOf(selectedItem);
3975
+ let newActiveIndex = activeIndex;
3976
+ const selectedItemIndex = selectedItems.indexOf(selectedItem);
3977
+
3978
+ if (selectedItemIndex >= 0) {
3979
+ if (selectedItems.length === 1) {
3980
+ newActiveIndex = -1;
3981
+ } else if (selectedItemIndex === selectedItems.length - 1) {
3982
+ newActiveIndex = selectedItems.length - 2;
3983
+ }
3929
3984
 
3930
- if (selectedItems.length === 1) {
3931
- _newActiveIndex = -1;
3932
- } else if (selectedItemIndex === selectedItems.length - 1) {
3933
- _newActiveIndex = selectedItems.length - 2;
3985
+ changes = {
3986
+ selectedItems: [...selectedItems.slice(0, selectedItemIndex), ...selectedItems.slice(selectedItemIndex + 1)],
3987
+ activeIndex: newActiveIndex
3988
+ };
3934
3989
  }
3935
3990
 
3936
- changes = _extends__default['default']({
3937
- selectedItems: [].concat(selectedItems.slice(0, selectedItemIndex), selectedItems.slice(selectedItemIndex + 1))
3938
- }, {
3939
- activeIndex: _newActiveIndex
3940
- });
3941
3991
  break;
3942
3992
  }
3943
3993
 
3944
3994
  case FunctionSetSelectedItems:
3945
3995
  {
3946
- var newSelectedItems = action.selectedItems;
3996
+ const {
3997
+ selectedItems: newSelectedItems
3998
+ } = action;
3947
3999
  changes = {
3948
4000
  selectedItems: newSelectedItems
3949
4001
  };
@@ -3952,9 +4004,11 @@ function downshiftMultipleSelectionReducer(state, action) {
3952
4004
 
3953
4005
  case FunctionSetActiveIndex:
3954
4006
  {
3955
- var _newActiveIndex2 = action.activeIndex;
4007
+ const {
4008
+ activeIndex: newActiveIndex
4009
+ } = action;
3956
4010
  changes = {
3957
- activeIndex: _newActiveIndex2
4011
+ activeIndex: newActiveIndex
3958
4012
  };
3959
4013
  break;
3960
4014
  }
@@ -3970,11 +4024,11 @@ function downshiftMultipleSelectionReducer(state, action) {
3970
4024
  throw new Error('Reducer called without proper action type.');
3971
4025
  }
3972
4026
 
3973
- return _extends__default['default']({}, state, changes);
4027
+ return { ...state,
4028
+ ...changes
4029
+ };
3974
4030
  }
3975
4031
 
3976
- var _excluded = ["refKey", "ref", "onClick", "onKeyDown", "selectedItem", "index"],
3977
- _excluded2 = ["refKey", "ref", "onKeyDown", "onClick", "preventKeyAction"];
3978
4032
  useMultipleSelection.stateChangeTypes = stateChangeTypes;
3979
4033
 
3980
4034
  function useMultipleSelection(userProps) {
@@ -3984,47 +4038,47 @@ function useMultipleSelection(userProps) {
3984
4038
 
3985
4039
  validatePropTypes(userProps, useMultipleSelection); // Props defaults and destructuring.
3986
4040
 
3987
- var props = _extends__default['default']({}, defaultProps, userProps);
3988
-
3989
- var getA11yRemovalMessage = props.getA11yRemovalMessage,
3990
- itemToString = props.itemToString,
3991
- environment = props.environment,
3992
- keyNavigationNext = props.keyNavigationNext,
3993
- keyNavigationPrevious = props.keyNavigationPrevious; // Reducer init.
3994
-
3995
- var _useControlledReducer = useControlledReducer$1(downshiftMultipleSelectionReducer, getInitialState(props), props),
3996
- state = _useControlledReducer[0],
3997
- dispatch = _useControlledReducer[1];
3998
-
3999
- var activeIndex = state.activeIndex,
4000
- selectedItems = state.selectedItems; // Refs.
4001
-
4002
- var isInitialMountRef = preact.useRef(true);
4003
- var dropdownRef = preact.useRef(null);
4004
- var previousSelectedItemsRef = preact.useRef(selectedItems);
4005
- var selectedItemRefs = preact.useRef();
4041
+ const props = { ...defaultProps,
4042
+ ...userProps
4043
+ };
4044
+ const {
4045
+ getA11yRemovalMessage,
4046
+ itemToString,
4047
+ environment,
4048
+ keyNavigationNext,
4049
+ keyNavigationPrevious
4050
+ } = props; // Reducer init.
4051
+
4052
+ const [state, dispatch] = useControlledReducer$1(downshiftMultipleSelectionReducer, getInitialState(props), props);
4053
+ const {
4054
+ activeIndex,
4055
+ selectedItems
4056
+ } = state; // Refs.
4057
+
4058
+ const isInitialMountRef = preact.useRef(true);
4059
+ const dropdownRef = preact.useRef(null);
4060
+ const previousSelectedItemsRef = preact.useRef(selectedItems);
4061
+ const selectedItemRefs = preact.useRef();
4006
4062
  selectedItemRefs.current = [];
4007
- var latest = useLatestRef({
4008
- state: state,
4009
- props: props
4063
+ const latest = useLatestRef({
4064
+ state,
4065
+ props
4010
4066
  }); // Effects.
4011
4067
 
4012
4068
  /* Sets a11y status message on changes in selectedItem. */
4013
4069
 
4014
- preact.useEffect(function () {
4070
+ preact.useEffect(() => {
4015
4071
  if (isInitialMountRef.current) {
4016
4072
  return;
4017
4073
  }
4018
4074
 
4019
4075
  if (selectedItems.length < previousSelectedItemsRef.current.length) {
4020
- var removedSelectedItem = previousSelectedItemsRef.current.find(function (item) {
4021
- return selectedItems.indexOf(item) < 0;
4022
- });
4076
+ const removedSelectedItem = previousSelectedItemsRef.current.find(item => selectedItems.indexOf(item) < 0);
4023
4077
  setStatus(getA11yRemovalMessage({
4024
- itemToString: itemToString,
4078
+ itemToString,
4025
4079
  resultCount: selectedItems.length,
4026
- removedSelectedItem: removedSelectedItem,
4027
- activeIndex: activeIndex,
4080
+ removedSelectedItem,
4081
+ activeIndex,
4028
4082
  activeSelectedItem: selectedItems[activeIndex]
4029
4083
  }), environment.document);
4030
4084
  }
@@ -4032,7 +4086,7 @@ function useMultipleSelection(userProps) {
4032
4086
  previousSelectedItemsRef.current = selectedItems; // eslint-disable-next-line react-hooks/exhaustive-deps
4033
4087
  }, [selectedItems.length]); // Sets focus on active item.
4034
4088
 
4035
- preact.useEffect(function () {
4089
+ preact.useEffect(() => {
4036
4090
  if (isInitialMountRef.current) {
4037
4091
  return;
4038
4092
  }
@@ -4045,181 +4099,191 @@ function useMultipleSelection(userProps) {
4045
4099
  }, [activeIndex]);
4046
4100
  useControlPropsValidator({
4047
4101
  isInitialMount: isInitialMountRef.current,
4048
- props: props,
4049
- state: state
4102
+ props,
4103
+ state
4050
4104
  });
4051
- var setGetterPropCallInfo = useGetterPropsCalledChecker('getDropdownProps'); // Make initial ref false.
4105
+ const setGetterPropCallInfo = useGetterPropsCalledChecker('getDropdownProps'); // Make initial ref false.
4052
4106
 
4053
- preact.useEffect(function () {
4107
+ preact.useEffect(() => {
4054
4108
  isInitialMountRef.current = false;
4055
4109
  }, []); // Event handler functions.
4056
4110
 
4057
- var selectedItemKeyDownHandlers = preact.useMemo(function () {
4058
- var _ref;
4059
-
4060
- return _ref = {}, _ref[keyNavigationPrevious] = function () {
4111
+ const selectedItemKeyDownHandlers = preact.useMemo(() => ({
4112
+ [keyNavigationPrevious]() {
4061
4113
  dispatch({
4062
4114
  type: SelectedItemKeyDownNavigationPrevious
4063
4115
  });
4064
- }, _ref[keyNavigationNext] = function () {
4116
+ },
4117
+
4118
+ [keyNavigationNext]() {
4065
4119
  dispatch({
4066
4120
  type: SelectedItemKeyDownNavigationNext
4067
4121
  });
4068
- }, _ref.Delete = function Delete() {
4122
+ },
4123
+
4124
+ Delete() {
4069
4125
  dispatch({
4070
4126
  type: SelectedItemKeyDownDelete
4071
4127
  });
4072
- }, _ref.Backspace = function Backspace() {
4128
+ },
4129
+
4130
+ Backspace() {
4073
4131
  dispatch({
4074
4132
  type: SelectedItemKeyDownBackspace
4075
4133
  });
4076
- }, _ref;
4077
- }, [dispatch, keyNavigationNext, keyNavigationPrevious]);
4078
- var dropdownKeyDownHandlers = preact.useMemo(function () {
4079
- var _ref2;
4134
+ }
4080
4135
 
4081
- return _ref2 = {}, _ref2[keyNavigationPrevious] = function (event) {
4136
+ }), [dispatch, keyNavigationNext, keyNavigationPrevious]);
4137
+ const dropdownKeyDownHandlers = preact.useMemo(() => ({
4138
+ [keyNavigationPrevious](event) {
4082
4139
  if (isKeyDownOperationPermitted(event)) {
4083
4140
  dispatch({
4084
4141
  type: DropdownKeyDownNavigationPrevious
4085
4142
  });
4086
4143
  }
4087
- }, _ref2.Backspace = function Backspace(event) {
4144
+ },
4145
+
4146
+ Backspace(event) {
4088
4147
  if (isKeyDownOperationPermitted(event)) {
4089
4148
  dispatch({
4090
4149
  type: DropdownKeyDownBackspace
4091
4150
  });
4092
4151
  }
4093
- }, _ref2;
4094
- }, [dispatch, keyNavigationPrevious]); // Getter props.
4095
-
4096
- var getSelectedItemProps = preact.useCallback(function (_temp) {
4097
- var _extends2;
4098
-
4099
- var _ref3 = _temp === void 0 ? {} : _temp,
4100
- _ref3$refKey = _ref3.refKey,
4101
- refKey = _ref3$refKey === void 0 ? 'ref' : _ref3$refKey,
4102
- ref = _ref3.ref,
4103
- onClick = _ref3.onClick,
4104
- onKeyDown = _ref3.onKeyDown,
4105
- selectedItem = _ref3.selectedItem,
4106
- index = _ref3.index,
4107
- rest = _objectWithoutPropertiesLoose__default['default'](_ref3, _excluded);
4152
+ }
4108
4153
 
4109
- var latestState = latest.current.state;
4110
- var itemIndex = getItemIndex(index, selectedItem, latestState.selectedItems);
4154
+ }), [dispatch, keyNavigationPrevious]); // Getter props.
4155
+
4156
+ const getSelectedItemProps = preact.useCallback(function (_temp) {
4157
+ let {
4158
+ refKey = 'ref',
4159
+ ref,
4160
+ onClick,
4161
+ onKeyDown,
4162
+ selectedItem,
4163
+ index,
4164
+ ...rest
4165
+ } = _temp === void 0 ? {} : _temp;
4166
+ const {
4167
+ state: latestState
4168
+ } = latest.current;
4169
+ const itemIndex = getItemIndex(index, selectedItem, latestState.selectedItems);
4111
4170
 
4112
4171
  if (itemIndex < 0) {
4113
4172
  throw new Error('Pass either selectedItem or index in getSelectedItemProps!');
4114
4173
  }
4115
4174
 
4116
- var selectedItemHandleClick = function selectedItemHandleClick() {
4175
+ const selectedItemHandleClick = () => {
4117
4176
  dispatch({
4118
4177
  type: SelectedItemClick,
4119
- index: index
4178
+ index
4120
4179
  });
4121
4180
  };
4122
4181
 
4123
- var selectedItemHandleKeyDown = function selectedItemHandleKeyDown(event) {
4124
- var key = normalizeArrowKey(event);
4182
+ const selectedItemHandleKeyDown = event => {
4183
+ const key = normalizeArrowKey(event);
4125
4184
 
4126
4185
  if (key && selectedItemKeyDownHandlers[key]) {
4127
4186
  selectedItemKeyDownHandlers[key](event);
4128
4187
  }
4129
4188
  };
4130
4189
 
4131
- return _extends__default['default']((_extends2 = {}, _extends2[refKey] = handleRefs(ref, function (selectedItemNode) {
4132
- if (selectedItemNode) {
4133
- selectedItemRefs.current.push(selectedItemNode);
4134
- }
4135
- }), _extends2.tabIndex = index === latestState.activeIndex ? 0 : -1, _extends2.onClick = callAllEventHandlers(onClick, selectedItemHandleClick), _extends2.onKeyDown = callAllEventHandlers(onKeyDown, selectedItemHandleKeyDown), _extends2), rest);
4190
+ return {
4191
+ [refKey]: handleRefs(ref, selectedItemNode => {
4192
+ if (selectedItemNode) {
4193
+ selectedItemRefs.current.push(selectedItemNode);
4194
+ }
4195
+ }),
4196
+ tabIndex: index === latestState.activeIndex ? 0 : -1,
4197
+ onClick: callAllEventHandlers(onClick, selectedItemHandleClick),
4198
+ onKeyDown: callAllEventHandlers(onKeyDown, selectedItemHandleKeyDown),
4199
+ ...rest
4200
+ };
4136
4201
  }, [dispatch, latest, selectedItemKeyDownHandlers]);
4137
- var getDropdownProps = preact.useCallback(function (_temp2, _temp3) {
4138
- var _extends3;
4139
-
4140
- var _ref4 = _temp2 === void 0 ? {} : _temp2,
4141
- _ref4$refKey = _ref4.refKey,
4142
- refKey = _ref4$refKey === void 0 ? 'ref' : _ref4$refKey,
4143
- ref = _ref4.ref,
4144
- onKeyDown = _ref4.onKeyDown,
4145
- onClick = _ref4.onClick,
4146
- _ref4$preventKeyActio = _ref4.preventKeyAction,
4147
- preventKeyAction = _ref4$preventKeyActio === void 0 ? false : _ref4$preventKeyActio,
4148
- rest = _objectWithoutPropertiesLoose__default['default'](_ref4, _excluded2);
4149
-
4150
- var _ref5 = _temp3 === void 0 ? {} : _temp3,
4151
- _ref5$suppressRefErro = _ref5.suppressRefError,
4152
- suppressRefError = _ref5$suppressRefErro === void 0 ? false : _ref5$suppressRefErro;
4153
-
4202
+ const getDropdownProps = preact.useCallback(function (_temp2, _temp3) {
4203
+ let {
4204
+ refKey = 'ref',
4205
+ ref,
4206
+ onKeyDown,
4207
+ onClick,
4208
+ preventKeyAction = false,
4209
+ ...rest
4210
+ } = _temp2 === void 0 ? {} : _temp2;
4211
+ let {
4212
+ suppressRefError = false
4213
+ } = _temp3 === void 0 ? {} : _temp3;
4154
4214
  setGetterPropCallInfo('getDropdownProps', suppressRefError, refKey, dropdownRef);
4155
4215
 
4156
- var dropdownHandleKeyDown = function dropdownHandleKeyDown(event) {
4157
- var key = normalizeArrowKey(event);
4216
+ const dropdownHandleKeyDown = event => {
4217
+ const key = normalizeArrowKey(event);
4158
4218
 
4159
4219
  if (key && dropdownKeyDownHandlers[key]) {
4160
4220
  dropdownKeyDownHandlers[key](event);
4161
4221
  }
4162
4222
  };
4163
4223
 
4164
- var dropdownHandleClick = function dropdownHandleClick() {
4224
+ const dropdownHandleClick = () => {
4165
4225
  dispatch({
4166
4226
  type: DropdownClick
4167
4227
  });
4168
4228
  };
4169
4229
 
4170
- return _extends__default['default']((_extends3 = {}, _extends3[refKey] = handleRefs(ref, function (dropdownNode) {
4171
- if (dropdownNode) {
4172
- dropdownRef.current = dropdownNode;
4173
- }
4174
- }), _extends3), !preventKeyAction && {
4175
- onKeyDown: callAllEventHandlers(onKeyDown, dropdownHandleKeyDown),
4176
- onClick: callAllEventHandlers(onClick, dropdownHandleClick)
4177
- }, rest);
4230
+ return {
4231
+ [refKey]: handleRefs(ref, dropdownNode => {
4232
+ if (dropdownNode) {
4233
+ dropdownRef.current = dropdownNode;
4234
+ }
4235
+ }),
4236
+ ...(!preventKeyAction && {
4237
+ onKeyDown: callAllEventHandlers(onKeyDown, dropdownHandleKeyDown),
4238
+ onClick: callAllEventHandlers(onClick, dropdownHandleClick)
4239
+ }),
4240
+ ...rest
4241
+ };
4178
4242
  }, [dispatch, dropdownKeyDownHandlers, setGetterPropCallInfo]); // returns
4179
4243
 
4180
- var addSelectedItem = preact.useCallback(function (selectedItem) {
4244
+ const addSelectedItem = preact.useCallback(selectedItem => {
4181
4245
  dispatch({
4182
4246
  type: FunctionAddSelectedItem,
4183
- selectedItem: selectedItem
4247
+ selectedItem
4184
4248
  });
4185
4249
  }, [dispatch]);
4186
- var removeSelectedItem = preact.useCallback(function (selectedItem) {
4250
+ const removeSelectedItem = preact.useCallback(selectedItem => {
4187
4251
  dispatch({
4188
4252
  type: FunctionRemoveSelectedItem,
4189
- selectedItem: selectedItem
4253
+ selectedItem
4190
4254
  });
4191
4255
  }, [dispatch]);
4192
- var setSelectedItems = preact.useCallback(function (newSelectedItems) {
4256
+ const setSelectedItems = preact.useCallback(newSelectedItems => {
4193
4257
  dispatch({
4194
4258
  type: FunctionSetSelectedItems,
4195
4259
  selectedItems: newSelectedItems
4196
4260
  });
4197
4261
  }, [dispatch]);
4198
- var setActiveIndex = preact.useCallback(function (newActiveIndex) {
4262
+ const setActiveIndex = preact.useCallback(newActiveIndex => {
4199
4263
  dispatch({
4200
4264
  type: FunctionSetActiveIndex,
4201
4265
  activeIndex: newActiveIndex
4202
4266
  });
4203
4267
  }, [dispatch]);
4204
- var reset = preact.useCallback(function () {
4268
+ const reset = preact.useCallback(() => {
4205
4269
  dispatch({
4206
4270
  type: FunctionReset
4207
4271
  });
4208
4272
  }, [dispatch]);
4209
4273
  return {
4210
- getSelectedItemProps: getSelectedItemProps,
4211
- getDropdownProps: getDropdownProps,
4212
- addSelectedItem: addSelectedItem,
4213
- removeSelectedItem: removeSelectedItem,
4214
- setSelectedItems: setSelectedItems,
4215
- setActiveIndex: setActiveIndex,
4216
- reset: reset,
4217
- selectedItems: selectedItems,
4218
- activeIndex: activeIndex
4274
+ getSelectedItemProps,
4275
+ getDropdownProps,
4276
+ addSelectedItem,
4277
+ removeSelectedItem,
4278
+ setSelectedItems,
4279
+ setActiveIndex,
4280
+ reset,
4281
+ selectedItems,
4282
+ activeIndex
4219
4283
  };
4220
4284
  }
4221
4285
 
4222
- exports['default'] = Downshift$1;
4286
+ exports["default"] = Downshift$1;
4223
4287
  exports.resetIdCounter = resetIdCounter;
4224
4288
  exports.useCombobox = useCombobox;
4225
4289
  exports.useMultipleSelection = useMultipleSelection;