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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "downshift",
3
- "version": "5.0.3",
3
+ "version": "5.0.4",
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",
@@ -1708,21 +1708,30 @@ function capitalizeString(string) {
1708
1708
  return "" + string.slice(0, 1).toUpperCase() + string.slice(1);
1709
1709
  }
1710
1710
 
1711
- function invokeOnChangeHandler(propKey, props, state, changes) {
1712
- var handler = "on" + capitalizeString(propKey) + "Change";
1711
+ function invokeOnChangeHandler(key, props, state, newState) {
1712
+ var handler = "on" + capitalizeString(key) + "Change";
1713
1713
 
1714
- if (props[handler] && changes[propKey] !== undefined && changes[propKey] !== state[propKey]) {
1715
- props[handler](changes);
1714
+ if (props[handler] && newState[key] !== undefined && newState[key] !== state[key]) {
1715
+ props[handler](newState);
1716
1716
  }
1717
1717
  }
1718
1718
 
1719
- function callOnChangeProps(props, state, changes) {
1720
- Object.keys(state).forEach(function (stateKey) {
1721
- invokeOnChangeHandler(stateKey, props, state, changes);
1719
+ function callOnChangeProps(action, state, newState) {
1720
+ var props = action.props,
1721
+ type = action.type;
1722
+ var changes = {};
1723
+ Object.keys(state).forEach(function (key) {
1724
+ invokeOnChangeHandler(key, props, state, newState);
1725
+
1726
+ if (newState[key] !== state[key]) {
1727
+ changes[key] = newState[key];
1728
+ }
1722
1729
  });
1723
1730
 
1724
- if (props.onStateChange && changes !== undefined) {
1725
- props.onStateChange(changes);
1731
+ if (props.onStateChange && Object.entries(changes).length) {
1732
+ props.onStateChange(_extends({
1733
+ type: type
1734
+ }, changes));
1726
1735
  }
1727
1736
  }
1728
1737
 
@@ -1734,7 +1743,7 @@ function useEnhancedReducer(reducer, initialState, props) {
1734
1743
  var newState = stateReduceLocal(state, _extends({}, action, {
1735
1744
  changes: changes
1736
1745
  }));
1737
- callOnChangeProps(action.props, state, newState);
1746
+ callOnChangeProps(action, state, newState);
1738
1747
  return newState;
1739
1748
  }, [reducer]);
1740
1749
 
@@ -1742,7 +1751,11 @@ function useEnhancedReducer(reducer, initialState, props) {
1742
1751
  state = _useReducer[0],
1743
1752
  dispatch = _useReducer[1];
1744
1753
 
1745
- return [getState(state, props), dispatch];
1754
+ return [getState(state, props), function dispatchWithProps(action) {
1755
+ return dispatch(_extends({
1756
+ props: props
1757
+ }, action));
1758
+ }];
1746
1759
  }
1747
1760
  /**
1748
1761
  * Default state reducer that returns the changes.
@@ -2202,13 +2215,7 @@ function useSelect(userProps) {
2202
2215
  highlightedIndex = _useEnhancedReducer$.highlightedIndex,
2203
2216
  selectedItem = _useEnhancedReducer$.selectedItem,
2204
2217
  inputValue = _useEnhancedReducer$.inputValue,
2205
- dispatchWithoutProps = _useEnhancedReducer[1];
2206
-
2207
- var dispatch = function (action) {
2208
- return dispatchWithoutProps(_extends({
2209
- props: props
2210
- }, action));
2211
- };
2218
+ dispatch = _useEnhancedReducer[1];
2212
2219
  /* Refs */
2213
2220
 
2214
2221
 
@@ -2966,13 +2973,7 @@ function useCombobox(userProps) {
2966
2973
  highlightedIndex = _useEnhancedReducer$.highlightedIndex,
2967
2974
  selectedItem = _useEnhancedReducer$.selectedItem,
2968
2975
  inputValue = _useEnhancedReducer$.inputValue,
2969
- dispatchWithoutProps = _useEnhancedReducer[1];
2970
-
2971
- var dispatch = function (action) {
2972
- return dispatchWithoutProps(_extends({
2973
- props: props
2974
- }, action));
2975
- };
2976
+ dispatch = _useEnhancedReducer[1];
2976
2977
  /* Refs */
2977
2978
 
2978
2979
 
@@ -1702,21 +1702,30 @@ function capitalizeString(string) {
1702
1702
  return "" + string.slice(0, 1).toUpperCase() + string.slice(1);
1703
1703
  }
1704
1704
 
1705
- function invokeOnChangeHandler(propKey, props, state, changes) {
1706
- var handler = "on" + capitalizeString(propKey) + "Change";
1705
+ function invokeOnChangeHandler(key, props, state, newState) {
1706
+ var handler = "on" + capitalizeString(key) + "Change";
1707
1707
 
1708
- if (props[handler] && changes[propKey] !== undefined && changes[propKey] !== state[propKey]) {
1709
- props[handler](changes);
1708
+ if (props[handler] && newState[key] !== undefined && newState[key] !== state[key]) {
1709
+ props[handler](newState);
1710
1710
  }
1711
1711
  }
1712
1712
 
1713
- function callOnChangeProps(props, state, changes) {
1714
- Object.keys(state).forEach(function (stateKey) {
1715
- invokeOnChangeHandler(stateKey, props, state, changes);
1713
+ function callOnChangeProps(action, state, newState) {
1714
+ var props = action.props,
1715
+ type = action.type;
1716
+ var changes = {};
1717
+ Object.keys(state).forEach(function (key) {
1718
+ invokeOnChangeHandler(key, props, state, newState);
1719
+
1720
+ if (newState[key] !== state[key]) {
1721
+ changes[key] = newState[key];
1722
+ }
1716
1723
  });
1717
1724
 
1718
- if (props.onStateChange && changes !== undefined) {
1719
- props.onStateChange(changes);
1725
+ if (props.onStateChange && Object.entries(changes).length) {
1726
+ props.onStateChange(_extends({
1727
+ type: type
1728
+ }, changes));
1720
1729
  }
1721
1730
  }
1722
1731
 
@@ -1728,7 +1737,7 @@ function useEnhancedReducer(reducer, initialState, props) {
1728
1737
  var newState = stateReduceLocal(state, _extends({}, action, {
1729
1738
  changes: changes
1730
1739
  }));
1731
- callOnChangeProps(action.props, state, newState);
1740
+ callOnChangeProps(action, state, newState);
1732
1741
  return newState;
1733
1742
  }, [reducer]);
1734
1743
 
@@ -1736,7 +1745,11 @@ function useEnhancedReducer(reducer, initialState, props) {
1736
1745
  state = _useReducer[0],
1737
1746
  dispatch = _useReducer[1];
1738
1747
 
1739
- return [getState(state, props), dispatch];
1748
+ return [getState(state, props), function dispatchWithProps(action) {
1749
+ return dispatch(_extends({
1750
+ props: props
1751
+ }, action));
1752
+ }];
1740
1753
  }
1741
1754
  /**
1742
1755
  * Default state reducer that returns the changes.
@@ -2196,13 +2209,7 @@ function useSelect(userProps) {
2196
2209
  highlightedIndex = _useEnhancedReducer$.highlightedIndex,
2197
2210
  selectedItem = _useEnhancedReducer$.selectedItem,
2198
2211
  inputValue = _useEnhancedReducer$.inputValue,
2199
- dispatchWithoutProps = _useEnhancedReducer[1];
2200
-
2201
- var dispatch = function (action) {
2202
- return dispatchWithoutProps(_extends({
2203
- props: props
2204
- }, action));
2205
- };
2212
+ dispatch = _useEnhancedReducer[1];
2206
2213
  /* Refs */
2207
2214
 
2208
2215
 
@@ -2960,13 +2967,7 @@ function useCombobox(userProps) {
2960
2967
  highlightedIndex = _useEnhancedReducer$.highlightedIndex,
2961
2968
  selectedItem = _useEnhancedReducer$.selectedItem,
2962
2969
  inputValue = _useEnhancedReducer$.inputValue,
2963
- dispatchWithoutProps = _useEnhancedReducer[1];
2964
-
2965
- var dispatch = function (action) {
2966
- return dispatchWithoutProps(_extends({
2967
- props: props
2968
- }, action));
2969
- };
2970
+ dispatch = _useEnhancedReducer[1];
2970
2971
  /* Refs */
2971
2972
 
2972
2973
 
@@ -2374,21 +2374,30 @@
2374
2374
  return "" + string.slice(0, 1).toUpperCase() + string.slice(1);
2375
2375
  }
2376
2376
 
2377
- function invokeOnChangeHandler(propKey, props, state, changes) {
2378
- var handler = "on" + capitalizeString(propKey) + "Change";
2377
+ function invokeOnChangeHandler(key, props, state, newState) {
2378
+ var handler = "on" + capitalizeString(key) + "Change";
2379
2379
 
2380
- if (props[handler] && changes[propKey] !== undefined && changes[propKey] !== state[propKey]) {
2381
- props[handler](changes);
2380
+ if (props[handler] && newState[key] !== undefined && newState[key] !== state[key]) {
2381
+ props[handler](newState);
2382
2382
  }
2383
2383
  }
2384
2384
 
2385
- function callOnChangeProps(props, state, changes) {
2386
- Object.keys(state).forEach(function (stateKey) {
2387
- invokeOnChangeHandler(stateKey, props, state, changes);
2385
+ function callOnChangeProps(action, state, newState) {
2386
+ var props = action.props,
2387
+ type = action.type;
2388
+ var changes = {};
2389
+ Object.keys(state).forEach(function (key) {
2390
+ invokeOnChangeHandler(key, props, state, newState);
2391
+
2392
+ if (newState[key] !== state[key]) {
2393
+ changes[key] = newState[key];
2394
+ }
2388
2395
  });
2389
2396
 
2390
- if (props.onStateChange && changes !== undefined) {
2391
- props.onStateChange(changes);
2397
+ if (props.onStateChange && Object.entries(changes).length) {
2398
+ props.onStateChange(_extends({
2399
+ type: type
2400
+ }, changes));
2392
2401
  }
2393
2402
  }
2394
2403
 
@@ -2400,7 +2409,7 @@
2400
2409
  var newState = stateReduceLocal(state, _extends({}, action, {
2401
2410
  changes: changes
2402
2411
  }));
2403
- callOnChangeProps(action.props, state, newState);
2412
+ callOnChangeProps(action, state, newState);
2404
2413
  return newState;
2405
2414
  }, [reducer]);
2406
2415
 
@@ -2408,7 +2417,11 @@
2408
2417
  state = _useReducer[0],
2409
2418
  dispatch = _useReducer[1];
2410
2419
 
2411
- return [getState(state, props), dispatch];
2420
+ return [getState(state, props), function dispatchWithProps(action) {
2421
+ return dispatch(_extends({
2422
+ props: props
2423
+ }, action));
2424
+ }];
2412
2425
  }
2413
2426
  /**
2414
2427
  * Default state reducer that returns the changes.
@@ -2863,13 +2876,7 @@
2863
2876
  highlightedIndex = _useEnhancedReducer$.highlightedIndex,
2864
2877
  selectedItem = _useEnhancedReducer$.selectedItem,
2865
2878
  inputValue = _useEnhancedReducer$.inputValue,
2866
- dispatchWithoutProps = _useEnhancedReducer[1];
2867
-
2868
- var dispatch = function (action) {
2869
- return dispatchWithoutProps(_extends({
2870
- props: props
2871
- }, action));
2872
- };
2879
+ dispatch = _useEnhancedReducer[1];
2873
2880
  /* Refs */
2874
2881
 
2875
2882
 
@@ -3622,13 +3629,7 @@
3622
3629
  highlightedIndex = _useEnhancedReducer$.highlightedIndex,
3623
3630
  selectedItem = _useEnhancedReducer$.selectedItem,
3624
3631
  inputValue = _useEnhancedReducer$.inputValue,
3625
- dispatchWithoutProps = _useEnhancedReducer[1];
3626
-
3627
- var dispatch = function (action) {
3628
- return dispatchWithoutProps(_extends({
3629
- props: props
3630
- }, action));
3631
- };
3632
+ dispatch = _useEnhancedReducer[1];
3632
3633
  /* Refs */
3633
3634
 
3634
3635