downshift 8.2.3 → 8.2.4-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/downshift.cjs.js +38 -11
- package/dist/downshift.esm.js +38 -11
- package/dist/downshift.native.cjs.js +38 -11
- package/dist/downshift.nativeweb.cjs.js +38 -11
- package/dist/downshift.umd.js +40 -13
- package/dist/downshift.umd.js.map +1 -1
- package/dist/downshift.umd.min.js +1 -1
- package/dist/downshift.umd.min.js.map +1 -1
- package/dist/src/hooks/utils.d.ts +13 -2
- package/package.json +1 -1
- package/preact/dist/downshift.cjs.js +38 -11
- package/preact/dist/downshift.esm.js +38 -11
- package/preact/dist/downshift.umd.js +40 -13
- package/preact/dist/downshift.umd.js.map +1 -1
- package/preact/dist/downshift.umd.min.js +1 -1
- package/preact/dist/downshift.umd.min.js.map +1 -1
package/dist/downshift.umd.js
CHANGED
|
@@ -1379,7 +1379,7 @@
|
|
|
1379
1379
|
|
|
1380
1380
|
var reactIsExports = reactIs.exports;
|
|
1381
1381
|
|
|
1382
|
-
const t=t=>"object"==typeof t&&null!=t&&1===t.nodeType,e=(t,e)=>(!e||"hidden"!==t)&&("visible"!==t&&"clip"!==t),n=(t,n)=>{if(t.clientHeight<t.scrollHeight||t.clientWidth<t.scrollWidth){const o=getComputedStyle(t,null);return e(o.overflowY,n)||e(o.overflowX,n)||(t=>{const e=(t=>{if(!t.ownerDocument||!t.ownerDocument.defaultView)return null;try{return t.ownerDocument.defaultView.frameElement}catch(t){return null}})(t);return !!e&&(e.clientHeight<t.scrollHeight||e.clientWidth<t.scrollWidth)})(t)}return !1},o=(t,e,n,o,l,r,
|
|
1382
|
+
const t=t=>"object"==typeof t&&null!=t&&1===t.nodeType,e=(t,e)=>(!e||"hidden"!==t)&&("visible"!==t&&"clip"!==t),n=(t,n)=>{if(t.clientHeight<t.scrollHeight||t.clientWidth<t.scrollWidth){const o=getComputedStyle(t,null);return e(o.overflowY,n)||e(o.overflowX,n)||(t=>{const e=(t=>{if(!t.ownerDocument||!t.ownerDocument.defaultView)return null;try{return t.ownerDocument.defaultView.frameElement}catch(t){return null}})(t);return !!e&&(e.clientHeight<t.scrollHeight||e.clientWidth<t.scrollWidth)})(t)}return !1},o=(t,e,n,o,i,l,r,d)=>l<t&&r>e||l>t&&r<e?0:l<=t&&d<=n||r>=e&&d>=n?l-t-o:r>e&&d<n||l<t&&d>n?r-e+i:0,i=t=>{const e=t.parentElement;return null==e?t.getRootNode().host||null:e},l=(e,l)=>{var r,d,s,h;if("undefined"==typeof document)return [];const{scrollMode:c,block:f,inline:u,boundary:a,skipOverflowHiddenElements:g}=l,m="function"==typeof a?a:t=>t!==a;if(!t(e))throw new TypeError("Invalid target");const p=document.scrollingElement||document.documentElement,w=[];let W=e;for(;t(W)&&m(W);){if(W=i(W),W===p){w.push(W);break}null!=W&&W===document.body&&n(W)&&!n(document.documentElement)||null!=W&&n(W,g)&&w.push(W);}const H=null!=(d=null==(r=window.visualViewport)?void 0:r.width)?d:innerWidth,b=null!=(h=null==(s=window.visualViewport)?void 0:s.height)?h:innerHeight,{scrollX:v,scrollY:y}=window,{height:E,width:M,top:x,right:I,bottom:C,left:R}=e.getBoundingClientRect();let T="start"===f||"nearest"===f?x:"end"===f?C:x+E/2,V="center"===u?R+M/2:"end"===u?I:R;const k=[];for(let t=0;t<w.length;t++){const e=w[t],{height:n,width:i,top:l,right:r,bottom:d,left:s}=e.getBoundingClientRect();if("if-needed"===c&&x>=0&&R>=0&&C<=b&&I<=H&&x>=l&&C<=d&&R>=s&&I<=r)return k;const h=getComputedStyle(e),a=parseInt(h.borderLeftWidth,10),g=parseInt(h.borderTopWidth,10),m=parseInt(h.borderRightWidth,10),W=parseInt(h.borderBottomWidth,10);let B=0,D=0;const L="offsetWidth"in e?e.offsetWidth-e.clientWidth-a-m:0,S="offsetHeight"in e?e.offsetHeight-e.clientHeight-g-W:0,X="offsetWidth"in e?0===e.offsetWidth?0:i/e.offsetWidth:0,Y="offsetHeight"in e?0===e.offsetHeight?0:n/e.offsetHeight:0;if(p===e)B="start"===f?T:"end"===f?T-b:"nearest"===f?o(y,y+b,b,g,W,y+T,y+T+E,E):T-b/2,D="start"===u?V:"center"===u?V-H/2:"end"===u?V-H:o(v,v+H,H,a,m,v+V,v+V+M,M),B=Math.max(0,B+y),D=Math.max(0,D+v);else {B="start"===f?T-l-g:"end"===f?T-d+W+S:"nearest"===f?o(l,d,n,g,W+S,T,T+E,E):T-(l+n/2)+S/2,D="start"===u?V-s-a:"center"===u?V-(s+i/2)+L/2:"end"===u?V-r+m+L:o(s,r,i,a,m+L,V,V+M,M);const{scrollLeft:t,scrollTop:h}=e;B=Math.max(0,Math.min(h+B/Y,e.scrollHeight-n/Y+S)),D=Math.max(0,Math.min(t+D/X,e.scrollWidth-i/X+L)),T+=h-B,V+=t-D;}k.push({el:e,top:B,left:D});}return k};
|
|
1383
1383
|
|
|
1384
1384
|
var idCounter = 0;
|
|
1385
1385
|
|
|
@@ -1405,7 +1405,7 @@
|
|
|
1405
1405
|
if (!node) {
|
|
1406
1406
|
return;
|
|
1407
1407
|
}
|
|
1408
|
-
var actions =
|
|
1408
|
+
var actions = l(node, {
|
|
1409
1409
|
boundary: menuNode,
|
|
1410
1410
|
block: 'nearest',
|
|
1411
1411
|
scrollMode: 'if-needed'
|
|
@@ -3050,9 +3050,10 @@
|
|
|
3050
3050
|
* @param {Function} reducer Reducer function from downshift.
|
|
3051
3051
|
* @param {Object} props The hook props, also passed to createInitialState.
|
|
3052
3052
|
* @param {Function} createInitialState Function that returns the initial state.
|
|
3053
|
+
* @param {Function} isStateEqual Function that checks if a previous state is equal to the next.
|
|
3053
3054
|
* @returns {Array} An array with the state and an action dispatcher.
|
|
3054
3055
|
*/
|
|
3055
|
-
function useEnhancedReducer(reducer, props, createInitialState) {
|
|
3056
|
+
function useEnhancedReducer(reducer, props, createInitialState, isStateEqual) {
|
|
3056
3057
|
var prevStateRef = React.useRef();
|
|
3057
3058
|
var actionRef = React.useRef();
|
|
3058
3059
|
var enhancedReducer = React.useCallback(function (state, action) {
|
|
@@ -3075,11 +3076,12 @@
|
|
|
3075
3076
|
}, [propsRef]);
|
|
3076
3077
|
var action = actionRef.current;
|
|
3077
3078
|
React.useEffect(function () {
|
|
3078
|
-
|
|
3079
|
+
var stateChanged = prevStateRef.current && !isStateEqual(prevStateRef.current, state);
|
|
3080
|
+
if (action && stateChanged) {
|
|
3079
3081
|
callOnChangeProps(action, getState(prevStateRef.current, action.props), state);
|
|
3080
3082
|
}
|
|
3081
3083
|
prevStateRef.current = state;
|
|
3082
|
-
}, [state, props, action]);
|
|
3084
|
+
}, [state, props, action, isStateEqual]);
|
|
3083
3085
|
return [state, dispatchWithProps];
|
|
3084
3086
|
}
|
|
3085
3087
|
|
|
@@ -3090,10 +3092,11 @@
|
|
|
3090
3092
|
* @param {Function} reducer Reducer function from downshift.
|
|
3091
3093
|
* @param {Object} props The hook props, also passed to createInitialState.
|
|
3092
3094
|
* @param {Function} createInitialState Function that returns the initial state.
|
|
3095
|
+
* @param {Function} isStateEqual Function that checks if a previous state is equal to the next.
|
|
3093
3096
|
* @returns {Array} An array with the state and an action dispatcher.
|
|
3094
3097
|
*/
|
|
3095
|
-
function useControlledReducer$1(reducer, props, createInitialState) {
|
|
3096
|
-
var _useEnhancedReducer = useEnhancedReducer(reducer, props, createInitialState),
|
|
3098
|
+
function useControlledReducer$1(reducer, props, createInitialState, isStateEqual) {
|
|
3099
|
+
var _useEnhancedReducer = useEnhancedReducer(reducer, props, createInitialState, isStateEqual),
|
|
3097
3100
|
state = _useEnhancedReducer[0],
|
|
3098
3101
|
dispatch = _useEnhancedReducer[1];
|
|
3099
3102
|
return [getState(state, props), dispatch];
|
|
@@ -3375,6 +3378,18 @@
|
|
|
3375
3378
|
}));
|
|
3376
3379
|
}
|
|
3377
3380
|
|
|
3381
|
+
/**
|
|
3382
|
+
* Check if a state is equal for dropdowns, by comparing isOpen, inputValue, highlightedIndex and selected item.
|
|
3383
|
+
* Used by useSelect and useCombobox.
|
|
3384
|
+
*
|
|
3385
|
+
* @param {Object} prevState
|
|
3386
|
+
* @param {Object} newState
|
|
3387
|
+
* @returns {boolean} Wheather the states are deeply equal.
|
|
3388
|
+
*/
|
|
3389
|
+
function isDropdownsStateEqual(prevState, newState) {
|
|
3390
|
+
return prevState.isOpen === newState.isOpen && prevState.inputValue === newState.inputValue && prevState.highlightedIndex === newState.highlightedIndex && prevState.selectedItem === newState.selectedItem;
|
|
3391
|
+
}
|
|
3392
|
+
|
|
3378
3393
|
// Shared between all exports.
|
|
3379
3394
|
var commonPropTypes = {
|
|
3380
3395
|
environment: PropTypes.shape({
|
|
@@ -3728,14 +3743,13 @@
|
|
|
3728
3743
|
getA11ySelectionMessage = props.getA11ySelectionMessage,
|
|
3729
3744
|
getA11yStatusMessage = props.getA11yStatusMessage;
|
|
3730
3745
|
// Initial state depending on controlled props.
|
|
3731
|
-
var _useControlledReducer = useControlledReducer$1(downshiftSelectReducer, props, getInitialState$2),
|
|
3746
|
+
var _useControlledReducer = useControlledReducer$1(downshiftSelectReducer, props, getInitialState$2, isDropdownsStateEqual),
|
|
3732
3747
|
state = _useControlledReducer[0],
|
|
3733
3748
|
dispatch = _useControlledReducer[1];
|
|
3734
3749
|
var isOpen = state.isOpen,
|
|
3735
3750
|
highlightedIndex = state.highlightedIndex,
|
|
3736
3751
|
selectedItem = state.selectedItem,
|
|
3737
3752
|
inputValue = state.inputValue;
|
|
3738
|
-
|
|
3739
3753
|
// Element efs.
|
|
3740
3754
|
var toggleButtonRef = React.useRef(null);
|
|
3741
3755
|
var menuRef = React.useRef(null);
|
|
@@ -4213,11 +4227,12 @@
|
|
|
4213
4227
|
* @param {Function} reducer Reducer function from downshift.
|
|
4214
4228
|
* @param {Object} props The hook props, also passed to createInitialState.
|
|
4215
4229
|
* @param {Function} createInitialState Function that returns the initial state.
|
|
4230
|
+
* @param {Function} isStateEqual Function that checks if a previous state is equal to the next.
|
|
4216
4231
|
* @returns {Array} An array with the state and an action dispatcher.
|
|
4217
4232
|
*/
|
|
4218
|
-
function useControlledReducer(reducer, props, createInitialState) {
|
|
4233
|
+
function useControlledReducer(reducer, props, createInitialState, isStateEqual) {
|
|
4219
4234
|
var previousSelectedItemRef = React.useRef();
|
|
4220
|
-
var _useEnhancedReducer = useEnhancedReducer(reducer, props, createInitialState),
|
|
4235
|
+
var _useEnhancedReducer = useEnhancedReducer(reducer, props, createInitialState, isStateEqual),
|
|
4221
4236
|
state = _useEnhancedReducer[0],
|
|
4222
4237
|
dispatch = _useEnhancedReducer[1];
|
|
4223
4238
|
|
|
@@ -4391,7 +4406,7 @@
|
|
|
4391
4406
|
getA11ySelectionMessage = props.getA11ySelectionMessage,
|
|
4392
4407
|
itemToString = props.itemToString;
|
|
4393
4408
|
// Initial state depending on controlled props.
|
|
4394
|
-
var _useControlledReducer = useControlledReducer(downshiftUseComboboxReducer, props, getInitialState$1),
|
|
4409
|
+
var _useControlledReducer = useControlledReducer(downshiftUseComboboxReducer, props, getInitialState$1, isDropdownsStateEqual),
|
|
4395
4410
|
state = _useControlledReducer[0],
|
|
4396
4411
|
dispatch = _useControlledReducer[1];
|
|
4397
4412
|
var isOpen = state.isOpen,
|
|
@@ -4876,6 +4891,18 @@
|
|
|
4876
4891
|
itemToStringLocal = selectionParameters.itemToString;
|
|
4877
4892
|
return itemToStringLocal(removedSelectedItem) + " has been removed.";
|
|
4878
4893
|
}
|
|
4894
|
+
|
|
4895
|
+
/**
|
|
4896
|
+
* Check if a state is equal for taglist, by comparing active index and selected items.
|
|
4897
|
+
* Used by useSelect and useCombobox.
|
|
4898
|
+
*
|
|
4899
|
+
* @param {Object} prevState
|
|
4900
|
+
* @param {Object} newState
|
|
4901
|
+
* @returns {boolean} Wheather the states are deeply equal.
|
|
4902
|
+
*/
|
|
4903
|
+
function isStateEqual(prevState, newState) {
|
|
4904
|
+
return prevState.selectedItems === newState.selectedItems && prevState.activeIndex === newState.activeIndex;
|
|
4905
|
+
}
|
|
4879
4906
|
var propTypes = _extends({}, commonPropTypes, {
|
|
4880
4907
|
selectedItems: PropTypes.array,
|
|
4881
4908
|
initialSelectedItems: PropTypes.array,
|
|
@@ -5065,7 +5092,7 @@
|
|
|
5065
5092
|
keyNavigationPrevious = props.keyNavigationPrevious;
|
|
5066
5093
|
|
|
5067
5094
|
// Reducer init.
|
|
5068
|
-
var _useControlledReducer = useControlledReducer$1(downshiftMultipleSelectionReducer, props, getInitialState),
|
|
5095
|
+
var _useControlledReducer = useControlledReducer$1(downshiftMultipleSelectionReducer, props, getInitialState, isStateEqual),
|
|
5069
5096
|
state = _useControlledReducer[0],
|
|
5070
5097
|
dispatch = _useControlledReducer[1];
|
|
5071
5098
|
var activeIndex = state.activeIndex,
|