downshift 5.0.3 → 5.0.4

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/README.md CHANGED
@@ -1388,6 +1388,8 @@ Thanks goes to these people ([emoji key][emojis]):
1388
1388
  <tr>
1389
1389
  <td align="center"><a href="https://kubajastrz.com"><img src="https://avatars0.githubusercontent.com/u/6443113?v=4" width="100px;" alt=""/><br /><sub><b>Jakub Jastrzębski</b></sub></a><br /><a href="https://github.com/downshift-js/downshift/commits?author=KubaJastrz" title="Code">💻</a></td>
1390
1390
  <td align="center"><a href="https://github.com/mufasa71"><img src="https://avatars1.githubusercontent.com/u/626420?v=4" width="100px;" alt=""/><br /><sub><b>Shukhrat Mukimov</b></sub></a><br /><a href="https://github.com/downshift-js/downshift/commits?author=mufasa71" title="Code">💻</a></td>
1391
+ <td align="center"><a href="http://jhonnymoreira.dev"><img src="https://avatars0.githubusercontent.com/u/2177742?v=4" width="100px;" alt=""/><br /><sub><b>Jhonny Moreira</b></sub></a><br /><a href="https://github.com/downshift-js/downshift/commits?author=jhonnymoreira" title="Code">💻</a></td>
1392
+ <td align="center"><a href="https://github.com/stefanprobst"><img src="https://avatars0.githubusercontent.com/u/20753323?v=4" width="100px;" alt=""/><br /><sub><b>stefanprobst</b></sub></a><br /><a href="https://github.com/downshift-js/downshift/commits?author=stefanprobst" title="Code">💻</a> <a href="https://github.com/downshift-js/downshift/commits?author=stefanprobst" title="Tests">⚠️</a></td>
1391
1393
  </tr>
1392
1394
  </table>
1393
1395
 
@@ -1750,21 +1750,30 @@ function capitalizeString(string) {
1750
1750
  return "" + string.slice(0, 1).toUpperCase() + string.slice(1);
1751
1751
  }
1752
1752
 
1753
- function invokeOnChangeHandler(propKey, props, state, changes) {
1754
- var handler = "on" + capitalizeString(propKey) + "Change";
1753
+ function invokeOnChangeHandler(key, props, state, newState) {
1754
+ var handler = "on" + capitalizeString(key) + "Change";
1755
1755
 
1756
- if (props[handler] && changes[propKey] !== undefined && changes[propKey] !== state[propKey]) {
1757
- props[handler](changes);
1756
+ if (props[handler] && newState[key] !== undefined && newState[key] !== state[key]) {
1757
+ props[handler](newState);
1758
1758
  }
1759
1759
  }
1760
1760
 
1761
- function callOnChangeProps(props, state, changes) {
1762
- Object.keys(state).forEach(function (stateKey) {
1763
- invokeOnChangeHandler(stateKey, props, state, changes);
1761
+ function callOnChangeProps(action, state, newState) {
1762
+ var props = action.props,
1763
+ type = action.type;
1764
+ var changes = {};
1765
+ Object.keys(state).forEach(function (key) {
1766
+ invokeOnChangeHandler(key, props, state, newState);
1767
+
1768
+ if (newState[key] !== state[key]) {
1769
+ changes[key] = newState[key];
1770
+ }
1764
1771
  });
1765
1772
 
1766
- if (props.onStateChange && changes !== undefined) {
1767
- props.onStateChange(changes);
1773
+ if (props.onStateChange && Object.entries(changes).length) {
1774
+ props.onStateChange(_extends({
1775
+ type: type
1776
+ }, changes));
1768
1777
  }
1769
1778
  }
1770
1779
 
@@ -1776,7 +1785,7 @@ function useEnhancedReducer(reducer, initialState, props) {
1776
1785
  var newState = stateReduceLocal(state, _extends({}, action, {
1777
1786
  changes: changes
1778
1787
  }));
1779
- callOnChangeProps(action.props, state, newState);
1788
+ callOnChangeProps(action, state, newState);
1780
1789
  return newState;
1781
1790
  }, [reducer]);
1782
1791
 
@@ -1784,7 +1793,11 @@ function useEnhancedReducer(reducer, initialState, props) {
1784
1793
  state = _useReducer[0],
1785
1794
  dispatch = _useReducer[1];
1786
1795
 
1787
- return [getState(state, props), dispatch];
1796
+ return [getState(state, props), function dispatchWithProps(action) {
1797
+ return dispatch(_extends({
1798
+ props: props
1799
+ }, action));
1800
+ }];
1788
1801
  }
1789
1802
  /**
1790
1803
  * Default state reducer that returns the changes.
@@ -2244,13 +2257,7 @@ function useSelect(userProps) {
2244
2257
  highlightedIndex = _useEnhancedReducer$.highlightedIndex,
2245
2258
  selectedItem = _useEnhancedReducer$.selectedItem,
2246
2259
  inputValue = _useEnhancedReducer$.inputValue,
2247
- dispatchWithoutProps = _useEnhancedReducer[1];
2248
-
2249
- var dispatch = function (action) {
2250
- return dispatchWithoutProps(_extends({
2251
- props: props
2252
- }, action));
2253
- };
2260
+ dispatch = _useEnhancedReducer[1];
2254
2261
  /* Refs */
2255
2262
 
2256
2263
 
@@ -3008,13 +3015,7 @@ function useCombobox(userProps) {
3008
3015
  highlightedIndex = _useEnhancedReducer$.highlightedIndex,
3009
3016
  selectedItem = _useEnhancedReducer$.selectedItem,
3010
3017
  inputValue = _useEnhancedReducer$.inputValue,
3011
- dispatchWithoutProps = _useEnhancedReducer[1];
3012
-
3013
- var dispatch = function (action) {
3014
- return dispatchWithoutProps(_extends({
3015
- props: props
3016
- }, action));
3017
- };
3018
+ dispatch = _useEnhancedReducer[1];
3018
3019
  /* Refs */
3019
3020
 
3020
3021
 
@@ -1744,21 +1744,30 @@ function capitalizeString(string) {
1744
1744
  return "" + string.slice(0, 1).toUpperCase() + string.slice(1);
1745
1745
  }
1746
1746
 
1747
- function invokeOnChangeHandler(propKey, props, state, changes) {
1748
- var handler = "on" + capitalizeString(propKey) + "Change";
1747
+ function invokeOnChangeHandler(key, props, state, newState) {
1748
+ var handler = "on" + capitalizeString(key) + "Change";
1749
1749
 
1750
- if (props[handler] && changes[propKey] !== undefined && changes[propKey] !== state[propKey]) {
1751
- props[handler](changes);
1750
+ if (props[handler] && newState[key] !== undefined && newState[key] !== state[key]) {
1751
+ props[handler](newState);
1752
1752
  }
1753
1753
  }
1754
1754
 
1755
- function callOnChangeProps(props, state, changes) {
1756
- Object.keys(state).forEach(function (stateKey) {
1757
- invokeOnChangeHandler(stateKey, props, state, changes);
1755
+ function callOnChangeProps(action, state, newState) {
1756
+ var props = action.props,
1757
+ type = action.type;
1758
+ var changes = {};
1759
+ Object.keys(state).forEach(function (key) {
1760
+ invokeOnChangeHandler(key, props, state, newState);
1761
+
1762
+ if (newState[key] !== state[key]) {
1763
+ changes[key] = newState[key];
1764
+ }
1758
1765
  });
1759
1766
 
1760
- if (props.onStateChange && changes !== undefined) {
1761
- props.onStateChange(changes);
1767
+ if (props.onStateChange && Object.entries(changes).length) {
1768
+ props.onStateChange(_extends({
1769
+ type: type
1770
+ }, changes));
1762
1771
  }
1763
1772
  }
1764
1773
 
@@ -1770,7 +1779,7 @@ function useEnhancedReducer(reducer, initialState, props) {
1770
1779
  var newState = stateReduceLocal(state, _extends({}, action, {
1771
1780
  changes: changes
1772
1781
  }));
1773
- callOnChangeProps(action.props, state, newState);
1782
+ callOnChangeProps(action, state, newState);
1774
1783
  return newState;
1775
1784
  }, [reducer]);
1776
1785
 
@@ -1778,7 +1787,11 @@ function useEnhancedReducer(reducer, initialState, props) {
1778
1787
  state = _useReducer[0],
1779
1788
  dispatch = _useReducer[1];
1780
1789
 
1781
- return [getState(state, props), dispatch];
1790
+ return [getState(state, props), function dispatchWithProps(action) {
1791
+ return dispatch(_extends({
1792
+ props: props
1793
+ }, action));
1794
+ }];
1782
1795
  }
1783
1796
  /**
1784
1797
  * Default state reducer that returns the changes.
@@ -2238,13 +2251,7 @@ function useSelect(userProps) {
2238
2251
  highlightedIndex = _useEnhancedReducer$.highlightedIndex,
2239
2252
  selectedItem = _useEnhancedReducer$.selectedItem,
2240
2253
  inputValue = _useEnhancedReducer$.inputValue,
2241
- dispatchWithoutProps = _useEnhancedReducer[1];
2242
-
2243
- var dispatch = function (action) {
2244
- return dispatchWithoutProps(_extends({
2245
- props: props
2246
- }, action));
2247
- };
2254
+ dispatch = _useEnhancedReducer[1];
2248
2255
  /* Refs */
2249
2256
 
2250
2257
 
@@ -3002,13 +3009,7 @@ function useCombobox(userProps) {
3002
3009
  highlightedIndex = _useEnhancedReducer$.highlightedIndex,
3003
3010
  selectedItem = _useEnhancedReducer$.selectedItem,
3004
3011
  inputValue = _useEnhancedReducer$.inputValue,
3005
- dispatchWithoutProps = _useEnhancedReducer[1];
3006
-
3007
- var dispatch = function (action) {
3008
- return dispatchWithoutProps(_extends({
3009
- props: props
3010
- }, action));
3011
- };
3012
+ dispatch = _useEnhancedReducer[1];
3012
3013
  /* Refs */
3013
3014
 
3014
3015
 
@@ -1683,21 +1683,30 @@ function capitalizeString(string) {
1683
1683
  return "" + string.slice(0, 1).toUpperCase() + string.slice(1);
1684
1684
  }
1685
1685
 
1686
- function invokeOnChangeHandler(propKey, props, state, changes) {
1687
- var handler = "on" + capitalizeString(propKey) + "Change";
1686
+ function invokeOnChangeHandler(key, props, state, newState) {
1687
+ var handler = "on" + capitalizeString(key) + "Change";
1688
1688
 
1689
- if (props[handler] && changes[propKey] !== undefined && changes[propKey] !== state[propKey]) {
1690
- props[handler](changes);
1689
+ if (props[handler] && newState[key] !== undefined && newState[key] !== state[key]) {
1690
+ props[handler](newState);
1691
1691
  }
1692
1692
  }
1693
1693
 
1694
- function callOnChangeProps(props, state, changes) {
1695
- Object.keys(state).forEach(function (stateKey) {
1696
- invokeOnChangeHandler(stateKey, props, state, changes);
1694
+ function callOnChangeProps(action, state, newState) {
1695
+ var props = action.props,
1696
+ type = action.type;
1697
+ var changes = {};
1698
+ Object.keys(state).forEach(function (key) {
1699
+ invokeOnChangeHandler(key, props, state, newState);
1700
+
1701
+ if (newState[key] !== state[key]) {
1702
+ changes[key] = newState[key];
1703
+ }
1697
1704
  });
1698
1705
 
1699
- if (props.onStateChange && changes !== undefined) {
1700
- props.onStateChange(changes);
1706
+ if (props.onStateChange && Object.entries(changes).length) {
1707
+ props.onStateChange(_extends({
1708
+ type: type
1709
+ }, changes));
1701
1710
  }
1702
1711
  }
1703
1712
 
@@ -1709,7 +1718,7 @@ function useEnhancedReducer(reducer, initialState, props) {
1709
1718
  var newState = stateReduceLocal(state, _extends({}, action, {
1710
1719
  changes: changes
1711
1720
  }));
1712
- callOnChangeProps(action.props, state, newState);
1721
+ callOnChangeProps(action, state, newState);
1713
1722
  return newState;
1714
1723
  }, [reducer]);
1715
1724
 
@@ -1717,7 +1726,11 @@ function useEnhancedReducer(reducer, initialState, props) {
1717
1726
  state = _useReducer[0],
1718
1727
  dispatch = _useReducer[1];
1719
1728
 
1720
- return [getState(state, props), dispatch];
1729
+ return [getState(state, props), function dispatchWithProps(action) {
1730
+ return dispatch(_extends({
1731
+ props: props
1732
+ }, action));
1733
+ }];
1721
1734
  }
1722
1735
  /**
1723
1736
  * Default state reducer that returns the changes.
@@ -2177,13 +2190,7 @@ function useSelect(userProps) {
2177
2190
  highlightedIndex = _useEnhancedReducer$.highlightedIndex,
2178
2191
  selectedItem = _useEnhancedReducer$.selectedItem,
2179
2192
  inputValue = _useEnhancedReducer$.inputValue,
2180
- dispatchWithoutProps = _useEnhancedReducer[1];
2181
-
2182
- var dispatch = function (action) {
2183
- return dispatchWithoutProps(_extends({
2184
- props: props
2185
- }, action));
2186
- };
2193
+ dispatch = _useEnhancedReducer[1];
2187
2194
  /* Refs */
2188
2195
 
2189
2196
 
@@ -2941,13 +2948,7 @@ function useCombobox(userProps) {
2941
2948
  highlightedIndex = _useEnhancedReducer$.highlightedIndex,
2942
2949
  selectedItem = _useEnhancedReducer$.selectedItem,
2943
2950
  inputValue = _useEnhancedReducer$.inputValue,
2944
- dispatchWithoutProps = _useEnhancedReducer[1];
2945
-
2946
- var dispatch = function (action) {
2947
- return dispatchWithoutProps(_extends({
2948
- props: props
2949
- }, action));
2950
- };
2951
+ dispatch = _useEnhancedReducer[1];
2951
2952
  /* Refs */
2952
2953
 
2953
2954
 
@@ -3250,21 +3250,30 @@
3250
3250
  return "" + string.slice(0, 1).toUpperCase() + string.slice(1);
3251
3251
  }
3252
3252
 
3253
- function invokeOnChangeHandler(propKey, props, state, changes) {
3254
- var handler = "on" + capitalizeString(propKey) + "Change";
3253
+ function invokeOnChangeHandler(key, props, state, newState) {
3254
+ var handler = "on" + capitalizeString(key) + "Change";
3255
3255
 
3256
- if (props[handler] && changes[propKey] !== undefined && changes[propKey] !== state[propKey]) {
3257
- props[handler](changes);
3256
+ if (props[handler] && newState[key] !== undefined && newState[key] !== state[key]) {
3257
+ props[handler](newState);
3258
3258
  }
3259
3259
  }
3260
3260
 
3261
- function callOnChangeProps(props, state, changes) {
3262
- Object.keys(state).forEach(function (stateKey) {
3263
- invokeOnChangeHandler(stateKey, props, state, changes);
3261
+ function callOnChangeProps(action, state, newState) {
3262
+ var props = action.props,
3263
+ type = action.type;
3264
+ var changes = {};
3265
+ Object.keys(state).forEach(function (key) {
3266
+ invokeOnChangeHandler(key, props, state, newState);
3267
+
3268
+ if (newState[key] !== state[key]) {
3269
+ changes[key] = newState[key];
3270
+ }
3264
3271
  });
3265
3272
 
3266
- if (props.onStateChange && changes !== undefined) {
3267
- props.onStateChange(changes);
3273
+ if (props.onStateChange && Object.entries(changes).length) {
3274
+ props.onStateChange(_extends({
3275
+ type: type
3276
+ }, changes));
3268
3277
  }
3269
3278
  }
3270
3279
 
@@ -3276,7 +3285,7 @@
3276
3285
  var newState = stateReduceLocal(state, _extends({}, action, {
3277
3286
  changes: changes
3278
3287
  }));
3279
- callOnChangeProps(action.props, state, newState);
3288
+ callOnChangeProps(action, state, newState);
3280
3289
  return newState;
3281
3290
  }, [reducer]);
3282
3291
 
@@ -3284,7 +3293,11 @@
3284
3293
  state = _useReducer[0],
3285
3294
  dispatch = _useReducer[1];
3286
3295
 
3287
- return [getState(state, props), dispatch];
3296
+ return [getState(state, props), function dispatchWithProps(action) {
3297
+ return dispatch(_extends({
3298
+ props: props
3299
+ }, action));
3300
+ }];
3288
3301
  }
3289
3302
  /**
3290
3303
  * Default state reducer that returns the changes.
@@ -3739,13 +3752,7 @@
3739
3752
  highlightedIndex = _useEnhancedReducer$.highlightedIndex,
3740
3753
  selectedItem = _useEnhancedReducer$.selectedItem,
3741
3754
  inputValue = _useEnhancedReducer$.inputValue,
3742
- dispatchWithoutProps = _useEnhancedReducer[1];
3743
-
3744
- var dispatch = function (action) {
3745
- return dispatchWithoutProps(_extends({
3746
- props: props
3747
- }, action));
3748
- };
3755
+ dispatch = _useEnhancedReducer[1];
3749
3756
  /* Refs */
3750
3757
 
3751
3758
 
@@ -4498,13 +4505,7 @@
4498
4505
  highlightedIndex = _useEnhancedReducer$.highlightedIndex,
4499
4506
  selectedItem = _useEnhancedReducer$.selectedItem,
4500
4507
  inputValue = _useEnhancedReducer$.inputValue,
4501
- dispatchWithoutProps = _useEnhancedReducer[1];
4502
-
4503
- var dispatch = function (action) {
4504
- return dispatchWithoutProps(_extends({
4505
- props: props
4506
- }, action));
4507
- };
4508
+ dispatch = _useEnhancedReducer[1];
4508
4509
  /* Refs */
4509
4510
 
4510
4511