downshift 5.0.1 → 5.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "downshift",
3
- "version": "5.0.1",
3
+ "version": "5.0.5",
4
4
  "description": "A set of primitives to build simple, flexible, WAI-ARIA compliant React autocomplete components",
5
5
  "main": "dist/downshift.cjs.js",
6
6
  "react-native": "dist/downshift.native.cjs.js",
@@ -1693,8 +1693,7 @@ function getPropTypesValidator(caller, propTypes) {
1693
1693
  options = {};
1694
1694
  }
1695
1695
 
1696
- Object.entries(propTypes).forEach(function (_ref2) {
1697
- var key = _ref2[0];
1696
+ Object.keys(propTypes).forEach(function (key) {
1698
1697
  PropTypes.checkPropTypes(propTypes, options, key, caller.name);
1699
1698
  });
1700
1699
  };
@@ -1708,21 +1707,30 @@ function capitalizeString(string) {
1708
1707
  return "" + string.slice(0, 1).toUpperCase() + string.slice(1);
1709
1708
  }
1710
1709
 
1711
- function invokeOnChangeHandler(propKey, props, state, changes) {
1712
- var handler = "on" + capitalizeString(propKey) + "Change";
1710
+ function invokeOnChangeHandler(key, props, state, newState) {
1711
+ var handler = "on" + capitalizeString(key) + "Change";
1713
1712
 
1714
- if (props[handler] && changes[propKey] !== undefined && changes[propKey] !== state[propKey]) {
1715
- props[handler](changes);
1713
+ if (props[handler] && newState[key] !== undefined && newState[key] !== state[key]) {
1714
+ props[handler](newState);
1716
1715
  }
1717
1716
  }
1718
1717
 
1719
- function callOnChangeProps(props, state, changes) {
1720
- Object.keys(state).forEach(function (stateKey) {
1721
- invokeOnChangeHandler(stateKey, props, state, changes);
1718
+ function callOnChangeProps(action, state, newState) {
1719
+ var props = action.props,
1720
+ type = action.type;
1721
+ var changes = {};
1722
+ Object.keys(state).forEach(function (key) {
1723
+ invokeOnChangeHandler(key, props, state, newState);
1724
+
1725
+ if (newState[key] !== state[key]) {
1726
+ changes[key] = newState[key];
1727
+ }
1722
1728
  });
1723
1729
 
1724
- if (props.onStateChange && changes !== undefined) {
1725
- props.onStateChange(changes);
1730
+ if (props.onStateChange && Object.keys(changes).length) {
1731
+ props.onStateChange(_extends({
1732
+ type: type
1733
+ }, changes));
1726
1734
  }
1727
1735
  }
1728
1736
 
@@ -1734,7 +1742,7 @@ function useEnhancedReducer(reducer, initialState, props) {
1734
1742
  var newState = stateReduceLocal(state, _extends({}, action, {
1735
1743
  changes: changes
1736
1744
  }));
1737
- callOnChangeProps(action.props, state, newState);
1745
+ callOnChangeProps(action, state, newState);
1738
1746
  return newState;
1739
1747
  }, [reducer]);
1740
1748
 
@@ -1742,7 +1750,11 @@ function useEnhancedReducer(reducer, initialState, props) {
1742
1750
  state = _useReducer[0],
1743
1751
  dispatch = _useReducer[1];
1744
1752
 
1745
- return [getState(state, props), dispatch];
1753
+ return [getState(state, props), function dispatchWithProps(action) {
1754
+ return dispatch(_extends({
1755
+ props: props
1756
+ }, action));
1757
+ }];
1746
1758
  }
1747
1759
  /**
1748
1760
  * Default state reducer that returns the changes.
@@ -2202,13 +2214,7 @@ function useSelect(userProps) {
2202
2214
  highlightedIndex = _useEnhancedReducer$.highlightedIndex,
2203
2215
  selectedItem = _useEnhancedReducer$.selectedItem,
2204
2216
  inputValue = _useEnhancedReducer$.inputValue,
2205
- dispatchWithoutProps = _useEnhancedReducer[1];
2206
-
2207
- var dispatch = function (action) {
2208
- return dispatchWithoutProps(_extends({
2209
- props: props
2210
- }, action));
2211
- };
2217
+ dispatch = _useEnhancedReducer[1];
2212
2218
  /* Refs */
2213
2219
 
2214
2220
 
@@ -2563,7 +2569,7 @@ function useSelect(userProps) {
2563
2569
 
2564
2570
  return _extends((_extends2 = {}, _extends2[refKey] = handleRefs(ref, function (menuNode) {
2565
2571
  menuRef.current = menuNode;
2566
- }), _extends2.id = elementIds.current.menuId, _extends2.role = 'listbox', _extends2['aria-labelledby'] = elementIds.current.labelId, _extends2.tabIndex = -1, _extends2), highlightedIndex > -1 && {
2572
+ }), _extends2.id = elementIds.current.menuId, _extends2.role = 'listbox', _extends2['aria-labelledby'] = elementIds.current.labelId, _extends2.tabIndex = -1, _extends2), isOpen && highlightedIndex > -1 && {
2567
2573
  'aria-activedescendant': elementIds.current.getItemId(highlightedIndex)
2568
2574
  }, {
2569
2575
  onMouseLeave: callAllEventHandlers(onMouseLeave, menuHandleMouseLeave),
@@ -2966,13 +2972,7 @@ function useCombobox(userProps) {
2966
2972
  highlightedIndex = _useEnhancedReducer$.highlightedIndex,
2967
2973
  selectedItem = _useEnhancedReducer$.selectedItem,
2968
2974
  inputValue = _useEnhancedReducer$.inputValue,
2969
- dispatchWithoutProps = _useEnhancedReducer[1];
2970
-
2971
- var dispatch = function (action) {
2972
- return dispatchWithoutProps(_extends({
2973
- props: props
2974
- }, action));
2975
- };
2975
+ dispatch = _useEnhancedReducer[1];
2976
2976
  /* Refs */
2977
2977
 
2978
2978
 
@@ -3314,7 +3314,7 @@ function useCombobox(userProps) {
3314
3314
 
3315
3315
  return _extends((_extends5 = {}, _extends5[refKey] = handleRefs(ref, function (inputNode) {
3316
3316
  inputRef.current = inputNode;
3317
- }), _extends5.id = elementIds.current.inputId, _extends5['aria-autocomplete'] = 'list', _extends5['aria-controls'] = elementIds.current.menuId, _extends5), highlightedIndex > -1 && {
3317
+ }), _extends5.id = elementIds.current.inputId, _extends5['aria-autocomplete'] = 'list', _extends5['aria-controls'] = elementIds.current.menuId, _extends5), isOpen && highlightedIndex > -1 && {
3318
3318
  'aria-activedescendant': elementIds.current.getItemId(highlightedIndex)
3319
3319
  }, {
3320
3320
  'aria-labelledby': elementIds.current.labelId,
@@ -1687,8 +1687,7 @@ function getPropTypesValidator(caller, propTypes) {
1687
1687
  options = {};
1688
1688
  }
1689
1689
 
1690
- Object.entries(propTypes).forEach(function (_ref2) {
1691
- var key = _ref2[0];
1690
+ Object.keys(propTypes).forEach(function (key) {
1692
1691
  PropTypes.checkPropTypes(propTypes, options, key, caller.name);
1693
1692
  });
1694
1693
  };
@@ -1702,21 +1701,30 @@ function capitalizeString(string) {
1702
1701
  return "" + string.slice(0, 1).toUpperCase() + string.slice(1);
1703
1702
  }
1704
1703
 
1705
- function invokeOnChangeHandler(propKey, props, state, changes) {
1706
- var handler = "on" + capitalizeString(propKey) + "Change";
1704
+ function invokeOnChangeHandler(key, props, state, newState) {
1705
+ var handler = "on" + capitalizeString(key) + "Change";
1707
1706
 
1708
- if (props[handler] && changes[propKey] !== undefined && changes[propKey] !== state[propKey]) {
1709
- props[handler](changes);
1707
+ if (props[handler] && newState[key] !== undefined && newState[key] !== state[key]) {
1708
+ props[handler](newState);
1710
1709
  }
1711
1710
  }
1712
1711
 
1713
- function callOnChangeProps(props, state, changes) {
1714
- Object.keys(state).forEach(function (stateKey) {
1715
- invokeOnChangeHandler(stateKey, props, state, changes);
1712
+ function callOnChangeProps(action, state, newState) {
1713
+ var props = action.props,
1714
+ type = action.type;
1715
+ var changes = {};
1716
+ Object.keys(state).forEach(function (key) {
1717
+ invokeOnChangeHandler(key, props, state, newState);
1718
+
1719
+ if (newState[key] !== state[key]) {
1720
+ changes[key] = newState[key];
1721
+ }
1716
1722
  });
1717
1723
 
1718
- if (props.onStateChange && changes !== undefined) {
1719
- props.onStateChange(changes);
1724
+ if (props.onStateChange && Object.keys(changes).length) {
1725
+ props.onStateChange(_extends({
1726
+ type: type
1727
+ }, changes));
1720
1728
  }
1721
1729
  }
1722
1730
 
@@ -1728,7 +1736,7 @@ function useEnhancedReducer(reducer, initialState, props) {
1728
1736
  var newState = stateReduceLocal(state, _extends({}, action, {
1729
1737
  changes: changes
1730
1738
  }));
1731
- callOnChangeProps(action.props, state, newState);
1739
+ callOnChangeProps(action, state, newState);
1732
1740
  return newState;
1733
1741
  }, [reducer]);
1734
1742
 
@@ -1736,7 +1744,11 @@ function useEnhancedReducer(reducer, initialState, props) {
1736
1744
  state = _useReducer[0],
1737
1745
  dispatch = _useReducer[1];
1738
1746
 
1739
- return [getState(state, props), dispatch];
1747
+ return [getState(state, props), function dispatchWithProps(action) {
1748
+ return dispatch(_extends({
1749
+ props: props
1750
+ }, action));
1751
+ }];
1740
1752
  }
1741
1753
  /**
1742
1754
  * Default state reducer that returns the changes.
@@ -2196,13 +2208,7 @@ function useSelect(userProps) {
2196
2208
  highlightedIndex = _useEnhancedReducer$.highlightedIndex,
2197
2209
  selectedItem = _useEnhancedReducer$.selectedItem,
2198
2210
  inputValue = _useEnhancedReducer$.inputValue,
2199
- dispatchWithoutProps = _useEnhancedReducer[1];
2200
-
2201
- var dispatch = function (action) {
2202
- return dispatchWithoutProps(_extends({
2203
- props: props
2204
- }, action));
2205
- };
2211
+ dispatch = _useEnhancedReducer[1];
2206
2212
  /* Refs */
2207
2213
 
2208
2214
 
@@ -2557,7 +2563,7 @@ function useSelect(userProps) {
2557
2563
 
2558
2564
  return _extends((_extends2 = {}, _extends2[refKey] = handleRefs(ref, function (menuNode) {
2559
2565
  menuRef.current = menuNode;
2560
- }), _extends2.id = elementIds.current.menuId, _extends2.role = 'listbox', _extends2['aria-labelledby'] = elementIds.current.labelId, _extends2.tabIndex = -1, _extends2), highlightedIndex > -1 && {
2566
+ }), _extends2.id = elementIds.current.menuId, _extends2.role = 'listbox', _extends2['aria-labelledby'] = elementIds.current.labelId, _extends2.tabIndex = -1, _extends2), isOpen && highlightedIndex > -1 && {
2561
2567
  'aria-activedescendant': elementIds.current.getItemId(highlightedIndex)
2562
2568
  }, {
2563
2569
  onMouseLeave: callAllEventHandlers(onMouseLeave, menuHandleMouseLeave),
@@ -2960,13 +2966,7 @@ function useCombobox(userProps) {
2960
2966
  highlightedIndex = _useEnhancedReducer$.highlightedIndex,
2961
2967
  selectedItem = _useEnhancedReducer$.selectedItem,
2962
2968
  inputValue = _useEnhancedReducer$.inputValue,
2963
- dispatchWithoutProps = _useEnhancedReducer[1];
2964
-
2965
- var dispatch = function (action) {
2966
- return dispatchWithoutProps(_extends({
2967
- props: props
2968
- }, action));
2969
- };
2969
+ dispatch = _useEnhancedReducer[1];
2970
2970
  /* Refs */
2971
2971
 
2972
2972
 
@@ -3308,7 +3308,7 @@ function useCombobox(userProps) {
3308
3308
 
3309
3309
  return _extends((_extends5 = {}, _extends5[refKey] = handleRefs(ref, function (inputNode) {
3310
3310
  inputRef.current = inputNode;
3311
- }), _extends5.id = elementIds.current.inputId, _extends5['aria-autocomplete'] = 'list', _extends5['aria-controls'] = elementIds.current.menuId, _extends5), highlightedIndex > -1 && {
3311
+ }), _extends5.id = elementIds.current.inputId, _extends5['aria-autocomplete'] = 'list', _extends5['aria-controls'] = elementIds.current.menuId, _extends5), isOpen && highlightedIndex > -1 && {
3312
3312
  'aria-activedescendant': elementIds.current.getItemId(highlightedIndex)
3313
3313
  }, {
3314
3314
  'aria-labelledby': elementIds.current.labelId,
@@ -2359,8 +2359,7 @@
2359
2359
  options = {};
2360
2360
  }
2361
2361
 
2362
- Object.entries(propTypes).forEach(function (_ref2) {
2363
- var key = _ref2[0];
2362
+ Object.keys(propTypes).forEach(function (key) {
2364
2363
  PropTypes.checkPropTypes(propTypes, options, key, caller.name);
2365
2364
  });
2366
2365
  };
@@ -2374,21 +2373,30 @@
2374
2373
  return "" + string.slice(0, 1).toUpperCase() + string.slice(1);
2375
2374
  }
2376
2375
 
2377
- function invokeOnChangeHandler(propKey, props, state, changes) {
2378
- var handler = "on" + capitalizeString(propKey) + "Change";
2376
+ function invokeOnChangeHandler(key, props, state, newState) {
2377
+ var handler = "on" + capitalizeString(key) + "Change";
2379
2378
 
2380
- if (props[handler] && changes[propKey] !== undefined && changes[propKey] !== state[propKey]) {
2381
- props[handler](changes);
2379
+ if (props[handler] && newState[key] !== undefined && newState[key] !== state[key]) {
2380
+ props[handler](newState);
2382
2381
  }
2383
2382
  }
2384
2383
 
2385
- function callOnChangeProps(props, state, changes) {
2386
- Object.keys(state).forEach(function (stateKey) {
2387
- invokeOnChangeHandler(stateKey, props, state, changes);
2384
+ function callOnChangeProps(action, state, newState) {
2385
+ var props = action.props,
2386
+ type = action.type;
2387
+ var changes = {};
2388
+ Object.keys(state).forEach(function (key) {
2389
+ invokeOnChangeHandler(key, props, state, newState);
2390
+
2391
+ if (newState[key] !== state[key]) {
2392
+ changes[key] = newState[key];
2393
+ }
2388
2394
  });
2389
2395
 
2390
- if (props.onStateChange && changes !== undefined) {
2391
- props.onStateChange(changes);
2396
+ if (props.onStateChange && Object.keys(changes).length) {
2397
+ props.onStateChange(_extends({
2398
+ type: type
2399
+ }, changes));
2392
2400
  }
2393
2401
  }
2394
2402
 
@@ -2400,7 +2408,7 @@
2400
2408
  var newState = stateReduceLocal(state, _extends({}, action, {
2401
2409
  changes: changes
2402
2410
  }));
2403
- callOnChangeProps(action.props, state, newState);
2411
+ callOnChangeProps(action, state, newState);
2404
2412
  return newState;
2405
2413
  }, [reducer]);
2406
2414
 
@@ -2408,7 +2416,11 @@
2408
2416
  state = _useReducer[0],
2409
2417
  dispatch = _useReducer[1];
2410
2418
 
2411
- return [getState(state, props), dispatch];
2419
+ return [getState(state, props), function dispatchWithProps(action) {
2420
+ return dispatch(_extends({
2421
+ props: props
2422
+ }, action));
2423
+ }];
2412
2424
  }
2413
2425
  /**
2414
2426
  * Default state reducer that returns the changes.
@@ -2863,13 +2875,7 @@
2863
2875
  highlightedIndex = _useEnhancedReducer$.highlightedIndex,
2864
2876
  selectedItem = _useEnhancedReducer$.selectedItem,
2865
2877
  inputValue = _useEnhancedReducer$.inputValue,
2866
- dispatchWithoutProps = _useEnhancedReducer[1];
2867
-
2868
- var dispatch = function (action) {
2869
- return dispatchWithoutProps(_extends({
2870
- props: props
2871
- }, action));
2872
- };
2878
+ dispatch = _useEnhancedReducer[1];
2873
2879
  /* Refs */
2874
2880
 
2875
2881
 
@@ -3224,7 +3230,7 @@
3224
3230
 
3225
3231
  return _extends((_extends2 = {}, _extends2[refKey] = handleRefs(ref, function (menuNode) {
3226
3232
  menuRef.current = menuNode;
3227
- }), _extends2.id = elementIds.current.menuId, _extends2.role = 'listbox', _extends2['aria-labelledby'] = elementIds.current.labelId, _extends2.tabIndex = -1, _extends2), highlightedIndex > -1 && {
3233
+ }), _extends2.id = elementIds.current.menuId, _extends2.role = 'listbox', _extends2['aria-labelledby'] = elementIds.current.labelId, _extends2.tabIndex = -1, _extends2), isOpen && highlightedIndex > -1 && {
3228
3234
  'aria-activedescendant': elementIds.current.getItemId(highlightedIndex)
3229
3235
  }, {
3230
3236
  onMouseLeave: callAllEventHandlers(onMouseLeave, menuHandleMouseLeave),
@@ -3622,13 +3628,7 @@
3622
3628
  highlightedIndex = _useEnhancedReducer$.highlightedIndex,
3623
3629
  selectedItem = _useEnhancedReducer$.selectedItem,
3624
3630
  inputValue = _useEnhancedReducer$.inputValue,
3625
- dispatchWithoutProps = _useEnhancedReducer[1];
3626
-
3627
- var dispatch = function (action) {
3628
- return dispatchWithoutProps(_extends({
3629
- props: props
3630
- }, action));
3631
- };
3631
+ dispatch = _useEnhancedReducer[1];
3632
3632
  /* Refs */
3633
3633
 
3634
3634
 
@@ -3970,7 +3970,7 @@
3970
3970
 
3971
3971
  return _extends((_extends5 = {}, _extends5[refKey] = handleRefs(ref, function (inputNode) {
3972
3972
  inputRef.current = inputNode;
3973
- }), _extends5.id = elementIds.current.inputId, _extends5['aria-autocomplete'] = 'list', _extends5['aria-controls'] = elementIds.current.menuId, _extends5), highlightedIndex > -1 && {
3973
+ }), _extends5.id = elementIds.current.inputId, _extends5['aria-autocomplete'] = 'list', _extends5['aria-controls'] = elementIds.current.menuId, _extends5), isOpen && highlightedIndex > -1 && {
3974
3974
  'aria-activedescendant': elementIds.current.getItemId(highlightedIndex)
3975
3975
  }, {
3976
3976
  'aria-labelledby': elementIds.current.labelId,