@mui/utils 5.10.9 → 5.10.15
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/CHANGELOG.md +636 -214
- package/ClassNameGenerator/ClassNameGenerator.js +0 -6
- package/ClassNameGenerator/index.js +0 -2
- package/HTMLElementType.js +0 -5
- package/capitalize.js +0 -4
- package/chainPropTypes.js +0 -2
- package/composeClasses/composeClasses.js +2 -4
- package/composeClasses/index.js +0 -2
- package/createChainedFunction.js +0 -2
- package/debounce.js +0 -5
- package/deepmerge.js +0 -7
- package/deprecatedPropType.js +0 -4
- package/elementAcceptingRef.js +2 -12
- package/elementTypeAcceptingRef.js +3 -13
- package/esm/ClassNameGenerator/ClassNameGenerator.js +0 -5
- package/esm/HTMLElementType.js +0 -4
- package/esm/capitalize.js +0 -1
- package/esm/chainPropTypes.js +0 -1
- package/esm/composeClasses/composeClasses.js +2 -3
- package/esm/createChainedFunction.js +0 -1
- package/esm/debounce.js +0 -4
- package/esm/deepmerge.js +0 -3
- package/esm/deprecatedPropType.js +0 -3
- package/esm/elementAcceptingRef.js +2 -9
- package/esm/elementTypeAcceptingRef.js +3 -9
- package/esm/exactProp.js +1 -3
- package/esm/formatMuiErrorMessage.js +0 -3
- package/esm/getDisplayName.js +6 -13
- package/esm/integerPropType.js +2 -17
- package/esm/requirePropFactory.js +2 -8
- package/esm/resolveProps.js +0 -2
- package/esm/scrollLeft.js +5 -11
- package/esm/unsupportedProp.js +0 -3
- package/esm/useControlled.js +0 -2
- package/esm/useEventCallback.js +3 -2
- package/esm/useForkRef.js +2 -2
- package/esm/useId.js +4 -7
- package/esm/useIsFocusVisible.js +10 -26
- package/esm/usePreviousProps.js +0 -2
- package/exactProp.js +1 -7
- package/formatMuiErrorMessage.js +0 -4
- package/generateUtilityClass/generateUtilityClass.js +0 -4
- package/generateUtilityClass/index.js +0 -4
- package/generateUtilityClasses/generateUtilityClasses.js +0 -3
- package/generateUtilityClasses/index.js +0 -2
- package/getDisplayName.js +3 -14
- package/getScrollbarSize.js +0 -1
- package/index.js +1 -41
- package/integerPropType.js +2 -21
- package/isMuiElement.js +0 -4
- package/legacy/ClassNameGenerator/ClassNameGenerator.js +0 -2
- package/legacy/HTMLElementType.js +0 -4
- package/legacy/capitalize.js +0 -1
- package/legacy/chainPropTypes.js +0 -1
- package/legacy/composeClasses/composeClasses.js +2 -3
- package/legacy/createChainedFunction.js +0 -3
- package/legacy/debounce.js +0 -6
- package/legacy/deepmerge.js +0 -3
- package/legacy/deprecatedPropType.js +0 -3
- package/legacy/elementAcceptingRef.js +3 -10
- package/legacy/elementTypeAcceptingRef.js +4 -10
- package/legacy/exactProp.js +1 -3
- package/legacy/formatMuiErrorMessage.js +0 -3
- package/legacy/getDisplayName.js +6 -13
- package/legacy/index.js +1 -1
- package/legacy/integerPropType.js +2 -18
- package/legacy/requirePropFactory.js +2 -9
- package/legacy/resolveProps.js +0 -2
- package/legacy/scrollLeft.js +5 -11
- package/legacy/unsupportedProp.js +0 -3
- package/legacy/useControlled.js +8 -15
- package/legacy/useEventCallback.js +3 -2
- package/legacy/useForkRef.js +2 -3
- package/legacy/useId.js +6 -10
- package/legacy/useIsFocusVisible.js +12 -28
- package/legacy/usePreviousProps.js +0 -2
- package/modern/ClassNameGenerator/ClassNameGenerator.js +0 -5
- package/modern/HTMLElementType.js +0 -4
- package/modern/capitalize.js +0 -1
- package/modern/chainPropTypes.js +0 -1
- package/modern/composeClasses/composeClasses.js +2 -3
- package/modern/createChainedFunction.js +0 -1
- package/modern/debounce.js +0 -4
- package/modern/deepmerge.js +0 -3
- package/modern/deprecatedPropType.js +0 -3
- package/modern/elementAcceptingRef.js +2 -9
- package/modern/elementTypeAcceptingRef.js +3 -9
- package/modern/exactProp.js +1 -3
- package/modern/formatMuiErrorMessage.js +0 -3
- package/modern/getDisplayName.js +6 -13
- package/modern/index.js +1 -1
- package/modern/integerPropType.js +2 -17
- package/modern/requirePropFactory.js +2 -8
- package/modern/resolveProps.js +0 -2
- package/modern/scrollLeft.js +5 -11
- package/modern/unsupportedProp.js +0 -3
- package/modern/useControlled.js +0 -2
- package/modern/useEventCallback.js +3 -2
- package/modern/useForkRef.js +2 -2
- package/modern/useId.js +4 -7
- package/modern/useIsFocusVisible.js +10 -26
- package/modern/usePreviousProps.js +0 -2
- package/ownerDocument.js +0 -1
- package/ownerWindow.js +0 -3
- package/package.json +2 -2
- package/ponyfillGlobal.js +0 -2
- package/refType.js +0 -4
- package/requirePropFactory.js +2 -11
- package/resolveProps.js +0 -3
- package/scrollLeft.js +5 -12
- package/setRef.js +0 -1
- package/unsupportedProp.js +0 -4
- package/useControlled.js +1 -6
- package/useEnhancedEffect.js +0 -4
- package/useEventCallback.js +2 -7
- package/useForkRef.js +2 -8
- package/useId.js +4 -11
- package/useIsFocusVisible.js +11 -30
- package/usePreviousProps.js +0 -5
|
@@ -1,71 +1,55 @@
|
|
|
1
1
|
import _typeof from "@babel/runtime/helpers/esm/typeof";
|
|
2
2
|
export function getTypeByValue(value) {
|
|
3
3
|
var valueType = _typeof(value);
|
|
4
|
-
|
|
5
4
|
switch (valueType) {
|
|
6
5
|
case 'number':
|
|
7
6
|
if (Number.isNaN(value)) {
|
|
8
7
|
return 'NaN';
|
|
9
8
|
}
|
|
10
|
-
|
|
11
9
|
if (!Number.isFinite(value)) {
|
|
12
10
|
return 'Infinity';
|
|
13
11
|
}
|
|
14
|
-
|
|
15
12
|
if (value !== Math.floor(value)) {
|
|
16
13
|
return 'float';
|
|
17
14
|
}
|
|
18
|
-
|
|
19
15
|
return 'number';
|
|
20
|
-
|
|
21
16
|
case 'object':
|
|
22
17
|
if (value === null) {
|
|
23
18
|
return 'null';
|
|
24
19
|
}
|
|
25
|
-
|
|
26
20
|
return value.constructor.name;
|
|
27
|
-
|
|
28
21
|
default:
|
|
29
22
|
return valueType;
|
|
30
23
|
}
|
|
31
|
-
}
|
|
24
|
+
}
|
|
32
25
|
|
|
26
|
+
// IE 11 support
|
|
33
27
|
function ponyfillIsInteger(x) {
|
|
34
28
|
// eslint-disable-next-line no-restricted-globals
|
|
35
29
|
return typeof x === 'number' && isFinite(x) && Math.floor(x) === x;
|
|
36
30
|
}
|
|
37
|
-
|
|
38
31
|
var isInteger = Number.isInteger || ponyfillIsInteger;
|
|
39
|
-
|
|
40
32
|
function requiredInteger(props, propName, componentName, location) {
|
|
41
33
|
var propValue = props[propName];
|
|
42
|
-
|
|
43
34
|
if (propValue == null || !isInteger(propValue)) {
|
|
44
35
|
var propType = getTypeByValue(propValue);
|
|
45
36
|
return new RangeError("Invalid ".concat(location, " `").concat(propName, "` of type `").concat(propType, "` supplied to `").concat(componentName, "`, expected `integer`."));
|
|
46
37
|
}
|
|
47
|
-
|
|
48
38
|
return null;
|
|
49
39
|
}
|
|
50
|
-
|
|
51
40
|
function validator(props, propName) {
|
|
52
41
|
var propValue = props[propName];
|
|
53
|
-
|
|
54
42
|
if (propValue === undefined) {
|
|
55
43
|
return null;
|
|
56
44
|
}
|
|
57
|
-
|
|
58
45
|
for (var _len = arguments.length, other = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
|
|
59
46
|
other[_key - 2] = arguments[_key];
|
|
60
47
|
}
|
|
61
|
-
|
|
62
48
|
return requiredInteger.apply(void 0, [props, propName].concat(other));
|
|
63
49
|
}
|
|
64
|
-
|
|
65
50
|
function validatorNoop() {
|
|
66
51
|
return null;
|
|
67
52
|
}
|
|
68
|
-
|
|
69
53
|
validator.isRequired = requiredInteger;
|
|
70
54
|
validatorNoop.isRequired = validatorNoop;
|
|
71
55
|
export default process.env.NODE_ENV === 'production' ? validatorNoop : validator;
|
|
@@ -4,35 +4,28 @@ export default function requirePropFactory(componentNameInError, Component) {
|
|
|
4
4
|
return function () {
|
|
5
5
|
return null;
|
|
6
6
|
};
|
|
7
|
-
}
|
|
8
|
-
|
|
7
|
+
}
|
|
9
8
|
|
|
9
|
+
// eslint-disable-next-line react/forbid-foreign-prop-types
|
|
10
10
|
var prevPropTypes = Component ? _extends({}, Component.propTypes) : null;
|
|
11
|
-
|
|
12
11
|
var requireProp = function requireProp(requiredProp) {
|
|
13
12
|
return function (props, propName, componentName, location, propFullName) {
|
|
14
13
|
var propFullNameSafe = propFullName || propName;
|
|
15
14
|
var defaultTypeChecker = prevPropTypes == null ? void 0 : prevPropTypes[propFullNameSafe];
|
|
16
|
-
|
|
17
15
|
if (defaultTypeChecker) {
|
|
18
16
|
for (var _len = arguments.length, args = new Array(_len > 5 ? _len - 5 : 0), _key = 5; _key < _len; _key++) {
|
|
19
17
|
args[_key - 5] = arguments[_key];
|
|
20
18
|
}
|
|
21
|
-
|
|
22
19
|
var typeCheckerResult = defaultTypeChecker.apply(void 0, [props, propName, componentName, location, propFullName].concat(args));
|
|
23
|
-
|
|
24
20
|
if (typeCheckerResult) {
|
|
25
21
|
return typeCheckerResult;
|
|
26
22
|
}
|
|
27
23
|
}
|
|
28
|
-
|
|
29
24
|
if (typeof props[propName] !== 'undefined' && !props[requiredProp]) {
|
|
30
25
|
return new Error("The prop `".concat(propFullNameSafe, "` of ") + "`".concat(componentNameInError, "` can only be used together with the `").concat(requiredProp, "` prop."));
|
|
31
26
|
}
|
|
32
|
-
|
|
33
27
|
return null;
|
|
34
28
|
};
|
|
35
29
|
};
|
|
36
|
-
|
|
37
30
|
return requireProp;
|
|
38
31
|
}
|
package/legacy/resolveProps.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
-
|
|
3
2
|
/**
|
|
4
3
|
* Add keys, values of `defaultProps` that does not exist in `props`
|
|
5
4
|
* @param {object} defaultProps
|
|
@@ -8,7 +7,6 @@ import _extends from "@babel/runtime/helpers/esm/extends";
|
|
|
8
7
|
*/
|
|
9
8
|
export default function resolveProps(defaultProps, props) {
|
|
10
9
|
var output = _extends({}, props);
|
|
11
|
-
|
|
12
10
|
Object.keys(defaultProps).forEach(function (propName) {
|
|
13
11
|
if (output[propName] === undefined) {
|
|
14
12
|
output[propName] = defaultProps[propName];
|
package/legacy/scrollLeft.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// Source from https://github.com/alitaheri/normalize-scroll-left
|
|
2
2
|
var cachedType;
|
|
3
|
+
|
|
3
4
|
/**
|
|
4
5
|
* Based on the jquery plugin https://github.com/othree/jquery.rtl-scroll-type
|
|
5
6
|
*
|
|
@@ -19,12 +20,10 @@ var cachedType;
|
|
|
19
20
|
*
|
|
20
21
|
* spec* https://drafts.csswg.org/cssom-view/#dom-window-scroll
|
|
21
22
|
*/
|
|
22
|
-
|
|
23
23
|
export function detectScrollType() {
|
|
24
24
|
if (cachedType) {
|
|
25
25
|
return cachedType;
|
|
26
26
|
}
|
|
27
|
-
|
|
28
27
|
var dummy = document.createElement('div');
|
|
29
28
|
var container = document.createElement('div');
|
|
30
29
|
container.style.width = '10px';
|
|
@@ -39,37 +38,32 @@ export function detectScrollType() {
|
|
|
39
38
|
dummy.style.overflow = 'scroll';
|
|
40
39
|
document.body.appendChild(dummy);
|
|
41
40
|
cachedType = 'reverse';
|
|
42
|
-
|
|
43
41
|
if (dummy.scrollLeft > 0) {
|
|
44
42
|
cachedType = 'default';
|
|
45
43
|
} else {
|
|
46
44
|
dummy.scrollLeft = 1;
|
|
47
|
-
|
|
48
45
|
if (dummy.scrollLeft === 0) {
|
|
49
46
|
cachedType = 'negative';
|
|
50
47
|
}
|
|
51
48
|
}
|
|
52
|
-
|
|
53
49
|
document.body.removeChild(dummy);
|
|
54
50
|
return cachedType;
|
|
55
|
-
}
|
|
51
|
+
}
|
|
56
52
|
|
|
53
|
+
// Based on https://stackoverflow.com/a/24394376
|
|
57
54
|
export function getNormalizedScrollLeft(element, direction) {
|
|
58
|
-
var scrollLeft = element.scrollLeft;
|
|
55
|
+
var scrollLeft = element.scrollLeft;
|
|
59
56
|
|
|
57
|
+
// Perform the calculations only when direction is rtl to avoid messing up the ltr behavior
|
|
60
58
|
if (direction !== 'rtl') {
|
|
61
59
|
return scrollLeft;
|
|
62
60
|
}
|
|
63
|
-
|
|
64
61
|
var type = detectScrollType();
|
|
65
|
-
|
|
66
62
|
switch (type) {
|
|
67
63
|
case 'negative':
|
|
68
64
|
return element.scrollWidth - element.clientWidth + scrollLeft;
|
|
69
|
-
|
|
70
65
|
case 'reverse':
|
|
71
66
|
return element.scrollWidth - element.clientWidth - scrollLeft;
|
|
72
|
-
|
|
73
67
|
default:
|
|
74
68
|
return scrollLeft;
|
|
75
69
|
}
|
|
@@ -2,12 +2,9 @@ export default function unsupportedProp(props, propName, componentName, location
|
|
|
2
2
|
if (process.env.NODE_ENV === 'production') {
|
|
3
3
|
return null;
|
|
4
4
|
}
|
|
5
|
-
|
|
6
5
|
var propFullNameSafe = propFullName || propName;
|
|
7
|
-
|
|
8
6
|
if (typeof props[propName] !== 'undefined') {
|
|
9
7
|
return new Error("The prop `".concat(propFullNameSafe, "` is not supported. Please remove it."));
|
|
10
8
|
}
|
|
11
|
-
|
|
12
9
|
return null;
|
|
13
10
|
}
|
package/legacy/useControlled.js
CHANGED
|
@@ -2,38 +2,31 @@
|
|
|
2
2
|
import * as React from 'react';
|
|
3
3
|
export default function useControlled(_ref) {
|
|
4
4
|
var controlled = _ref.controlled,
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
defaultProp = _ref.default,
|
|
6
|
+
name = _ref.name,
|
|
7
|
+
_ref$state = _ref.state,
|
|
8
|
+
state = _ref$state === void 0 ? 'value' : _ref$state;
|
|
10
9
|
// isControlled is ignored in the hook dependency lists as it should never change.
|
|
11
10
|
var _React$useRef = React.useRef(controlled !== undefined),
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
isControlled = _React$useRef.current;
|
|
14
12
|
var _React$useState = React.useState(defaultProp),
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
13
|
+
valueState = _React$useState[0],
|
|
14
|
+
setValue = _React$useState[1];
|
|
18
15
|
var value = isControlled ? controlled : valueState;
|
|
19
|
-
|
|
20
16
|
if (process.env.NODE_ENV !== 'production') {
|
|
21
17
|
React.useEffect(function () {
|
|
22
18
|
if (isControlled !== (controlled !== undefined)) {
|
|
23
19
|
console.error(["MUI: A component is changing the ".concat(isControlled ? '' : 'un', "controlled ").concat(state, " state of ").concat(name, " to be ").concat(isControlled ? 'un' : '', "controlled."), 'Elements should not switch from uncontrolled to controlled (or vice versa).', "Decide between using a controlled or uncontrolled ".concat(name, " ") + 'element for the lifetime of the component.', "The nature of the state is determined during the first render. It's considered controlled if the value is not `undefined`.", 'More info: https://fb.me/react-controlled-components'].join('\n'));
|
|
24
20
|
}
|
|
25
21
|
}, [state, name, controlled]);
|
|
26
|
-
|
|
27
22
|
var _React$useRef2 = React.useRef(defaultProp),
|
|
28
|
-
|
|
29
|
-
|
|
23
|
+
defaultValue = _React$useRef2.current;
|
|
30
24
|
React.useEffect(function () {
|
|
31
25
|
if (!isControlled && defaultValue !== defaultProp) {
|
|
32
26
|
console.error(["MUI: A component is changing the default ".concat(state, " state of an uncontrolled ").concat(name, " after being initialized. ") + "To suppress this warning opt to use a controlled ".concat(name, ".")].join('\n'));
|
|
33
27
|
}
|
|
34
28
|
}, [JSON.stringify(defaultProp)]);
|
|
35
29
|
}
|
|
36
|
-
|
|
37
30
|
var setValueIfUncontrolled = React.useCallback(function (newValue) {
|
|
38
31
|
if (!isControlled) {
|
|
39
32
|
setValue(newValue);
|
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import useEnhancedEffect from './useEnhancedEffect';
|
|
3
|
+
|
|
3
4
|
/**
|
|
4
5
|
* https://github.com/facebook/react/issues/14099#issuecomment-440013892
|
|
5
6
|
*/
|
|
6
|
-
|
|
7
7
|
export default function useEventCallback(fn) {
|
|
8
8
|
var ref = React.useRef(fn);
|
|
9
9
|
useEnhancedEffect(function () {
|
|
10
10
|
ref.current = fn;
|
|
11
11
|
});
|
|
12
12
|
return React.useCallback(function () {
|
|
13
|
-
return (
|
|
13
|
+
return (
|
|
14
|
+
// @ts-expect-error hide `this`
|
|
14
15
|
// tslint:disable-next-line:ban-comma-operator
|
|
15
16
|
(0, ref.current).apply(void 0, arguments)
|
|
16
17
|
);
|
package/legacy/useForkRef.js
CHANGED
|
@@ -4,7 +4,6 @@ export default function useForkRef() {
|
|
|
4
4
|
for (var _len = arguments.length, refs = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
5
5
|
refs[_key] = arguments[_key];
|
|
6
6
|
}
|
|
7
|
-
|
|
8
7
|
/**
|
|
9
8
|
* This will create a new function if the refs passed to this hook change and are all defined.
|
|
10
9
|
* This means react will call the old forkRef with `null` and the new forkRef
|
|
@@ -16,11 +15,11 @@ export default function useForkRef() {
|
|
|
16
15
|
})) {
|
|
17
16
|
return null;
|
|
18
17
|
}
|
|
19
|
-
|
|
20
18
|
return function (instance) {
|
|
21
19
|
refs.forEach(function (ref) {
|
|
22
20
|
setRef(ref, instance);
|
|
23
21
|
});
|
|
24
|
-
};
|
|
22
|
+
};
|
|
23
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
25
24
|
}, refs);
|
|
26
25
|
}
|
package/legacy/useId.js
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
var globalId = 0;
|
|
3
|
-
|
|
4
3
|
function useGlobalId(idOverride) {
|
|
5
4
|
var _React$useState = React.useState(idOverride),
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
defaultId = _React$useState[0],
|
|
6
|
+
setDefaultId = _React$useState[1];
|
|
9
7
|
var id = idOverride || defaultId;
|
|
10
8
|
React.useEffect(function () {
|
|
11
9
|
if (defaultId == null) {
|
|
@@ -18,9 +16,9 @@ function useGlobalId(idOverride) {
|
|
|
18
16
|
}
|
|
19
17
|
}, [defaultId]);
|
|
20
18
|
return id;
|
|
21
|
-
}
|
|
22
|
-
|
|
19
|
+
}
|
|
23
20
|
|
|
21
|
+
// eslint-disable-next-line no-useless-concat -- Workaround for https://github.com/webpack/webpack/issues/14814
|
|
24
22
|
var maybeReactUseId = React['useId' + ''];
|
|
25
23
|
/**
|
|
26
24
|
*
|
|
@@ -28,13 +26,11 @@ var maybeReactUseId = React['useId' + ''];
|
|
|
28
26
|
* @param idOverride
|
|
29
27
|
* @returns {string}
|
|
30
28
|
*/
|
|
31
|
-
|
|
32
29
|
export default function useId(idOverride) {
|
|
33
30
|
if (maybeReactUseId !== undefined) {
|
|
34
31
|
var reactId = maybeReactUseId();
|
|
35
32
|
return idOverride != null ? idOverride : reactId;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
|
|
33
|
+
}
|
|
34
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks -- `React.useId` is invariant at runtime.
|
|
39
35
|
return useGlobalId(idOverride);
|
|
40
36
|
}
|
|
@@ -18,6 +18,7 @@ var inputTypesWhitelist = {
|
|
|
18
18
|
datetime: true,
|
|
19
19
|
'datetime-local': true
|
|
20
20
|
};
|
|
21
|
+
|
|
21
22
|
/**
|
|
22
23
|
* Computes whether the given element should automatically trigger the
|
|
23
24
|
* `focus-visible` class being added, i.e. whether it should always match
|
|
@@ -25,26 +26,22 @@ var inputTypesWhitelist = {
|
|
|
25
26
|
* @param {Element} node
|
|
26
27
|
* @returns {boolean}
|
|
27
28
|
*/
|
|
28
|
-
|
|
29
29
|
function focusTriggersKeyboardModality(node) {
|
|
30
30
|
var _ref = node,
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
type = _ref.type,
|
|
32
|
+
tagName = _ref.tagName;
|
|
34
33
|
if (tagName === 'INPUT' && inputTypesWhitelist[type] && !node.readOnly) {
|
|
35
34
|
return true;
|
|
36
35
|
}
|
|
37
|
-
|
|
38
36
|
if (tagName === 'TEXTAREA' && !node.readOnly) {
|
|
39
37
|
return true;
|
|
40
38
|
}
|
|
41
|
-
|
|
42
39
|
if (node.isContentEditable) {
|
|
43
40
|
return true;
|
|
44
41
|
}
|
|
45
|
-
|
|
46
42
|
return false;
|
|
47
43
|
}
|
|
44
|
+
|
|
48
45
|
/**
|
|
49
46
|
* Keep track of our keyboard modality state with `hadKeyboardEvent`.
|
|
50
47
|
* If the most recent user interaction was via the keyboard;
|
|
@@ -52,15 +49,13 @@ function focusTriggersKeyboardModality(node) {
|
|
|
52
49
|
* then the modality is keyboard. Otherwise, the modality is not keyboard.
|
|
53
50
|
* @param {KeyboardEvent} event
|
|
54
51
|
*/
|
|
55
|
-
|
|
56
|
-
|
|
57
52
|
function handleKeyDown(event) {
|
|
58
53
|
if (event.metaKey || event.altKey || event.ctrlKey) {
|
|
59
54
|
return;
|
|
60
55
|
}
|
|
61
|
-
|
|
62
56
|
hadKeyboardEvent = true;
|
|
63
57
|
}
|
|
58
|
+
|
|
64
59
|
/**
|
|
65
60
|
* If at any point a user clicks with a pointing device, ensure that we change
|
|
66
61
|
* the modality away from keyboard.
|
|
@@ -68,12 +63,9 @@ function handleKeyDown(event) {
|
|
|
68
63
|
* element, and then clicks on a different element, focusing it with a
|
|
69
64
|
* pointing device, while we still think we're in keyboard modality.
|
|
70
65
|
*/
|
|
71
|
-
|
|
72
|
-
|
|
73
66
|
function handlePointerDown() {
|
|
74
67
|
hadKeyboardEvent = false;
|
|
75
68
|
}
|
|
76
|
-
|
|
77
69
|
function handleVisibilityChange() {
|
|
78
70
|
if (this.visibilityState === 'hidden') {
|
|
79
71
|
// If the tab becomes active again, the browser will handle calling focus
|
|
@@ -85,7 +77,6 @@ function handleVisibilityChange() {
|
|
|
85
77
|
}
|
|
86
78
|
}
|
|
87
79
|
}
|
|
88
|
-
|
|
89
80
|
function prepare(doc) {
|
|
90
81
|
doc.addEventListener('keydown', handleKeyDown, true);
|
|
91
82
|
doc.addEventListener('mousedown', handlePointerDown, true);
|
|
@@ -93,7 +84,6 @@ function prepare(doc) {
|
|
|
93
84
|
doc.addEventListener('touchstart', handlePointerDown, true);
|
|
94
85
|
doc.addEventListener('visibilitychange', handleVisibilityChange, true);
|
|
95
86
|
}
|
|
96
|
-
|
|
97
87
|
export function teardown(doc) {
|
|
98
88
|
doc.removeEventListener('keydown', handleKeyDown, true);
|
|
99
89
|
doc.removeEventListener('mousedown', handlePointerDown, true);
|
|
@@ -101,23 +91,21 @@ export function teardown(doc) {
|
|
|
101
91
|
doc.removeEventListener('touchstart', handlePointerDown, true);
|
|
102
92
|
doc.removeEventListener('visibilitychange', handleVisibilityChange, true);
|
|
103
93
|
}
|
|
104
|
-
|
|
105
94
|
function isFocusVisible(event) {
|
|
106
95
|
var target = event.target;
|
|
107
|
-
|
|
108
96
|
try {
|
|
109
97
|
return target.matches(':focus-visible');
|
|
110
|
-
} catch (error) {
|
|
98
|
+
} catch (error) {
|
|
99
|
+
// Browsers not implementing :focus-visible will throw a SyntaxError.
|
|
111
100
|
// We use our own heuristic for those browsers.
|
|
112
101
|
// Rethrow might be better if it's not the expected error but do we really
|
|
113
102
|
// want to crash if focus-visible malfunctioned?
|
|
114
|
-
}
|
|
115
|
-
// focusable events only.
|
|
116
|
-
|
|
103
|
+
}
|
|
117
104
|
|
|
105
|
+
// No need for validFocusTarget check. The user does that by attaching it to
|
|
106
|
+
// focusable events only.
|
|
118
107
|
return hadKeyboardEvent || focusTriggersKeyboardModality(target);
|
|
119
108
|
}
|
|
120
|
-
|
|
121
109
|
export default function useIsFocusVisible() {
|
|
122
110
|
var ref = React.useCallback(function (node) {
|
|
123
111
|
if (node != null) {
|
|
@@ -125,10 +113,10 @@ export default function useIsFocusVisible() {
|
|
|
125
113
|
}
|
|
126
114
|
}, []);
|
|
127
115
|
var isFocusVisibleRef = React.useRef(false);
|
|
116
|
+
|
|
128
117
|
/**
|
|
129
118
|
* Should be called if a blur event is fired
|
|
130
119
|
*/
|
|
131
|
-
|
|
132
120
|
function handleBlurVisible() {
|
|
133
121
|
// checking against potential state variable does not suffice if we focus and blur synchronously.
|
|
134
122
|
// React wouldn't have time to trigger a re-render so `focusVisible` would be stale.
|
|
@@ -148,23 +136,19 @@ export default function useIsFocusVisible() {
|
|
|
148
136
|
isFocusVisibleRef.current = false;
|
|
149
137
|
return true;
|
|
150
138
|
}
|
|
151
|
-
|
|
152
139
|
return false;
|
|
153
140
|
}
|
|
141
|
+
|
|
154
142
|
/**
|
|
155
143
|
* Should be called if a blur event is fired
|
|
156
144
|
*/
|
|
157
|
-
|
|
158
|
-
|
|
159
145
|
function handleFocusVisible(event) {
|
|
160
146
|
if (isFocusVisible(event)) {
|
|
161
147
|
isFocusVisibleRef.current = true;
|
|
162
148
|
return true;
|
|
163
149
|
}
|
|
164
|
-
|
|
165
150
|
return false;
|
|
166
151
|
}
|
|
167
|
-
|
|
168
152
|
return {
|
|
169
153
|
isFocusVisibleRef: isFocusVisibleRef,
|
|
170
154
|
onFocus: handleFocusVisible,
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
|
|
3
2
|
var usePreviousProps = function usePreviousProps(value) {
|
|
4
3
|
var ref = React.useRef({});
|
|
5
4
|
React.useEffect(function () {
|
|
@@ -7,5 +6,4 @@ var usePreviousProps = function usePreviousProps(value) {
|
|
|
7
6
|
});
|
|
8
7
|
return ref.current;
|
|
9
8
|
};
|
|
10
|
-
|
|
11
9
|
export default usePreviousProps;
|
|
@@ -1,22 +1,17 @@
|
|
|
1
1
|
const defaultGenerator = componentName => componentName;
|
|
2
|
-
|
|
3
2
|
const createClassNameGenerator = () => {
|
|
4
3
|
let generate = defaultGenerator;
|
|
5
4
|
return {
|
|
6
5
|
configure(generator) {
|
|
7
6
|
generate = generator;
|
|
8
7
|
},
|
|
9
|
-
|
|
10
8
|
generate(componentName) {
|
|
11
9
|
return generate(componentName);
|
|
12
10
|
},
|
|
13
|
-
|
|
14
11
|
reset() {
|
|
15
12
|
generate = defaultGenerator;
|
|
16
13
|
}
|
|
17
|
-
|
|
18
14
|
};
|
|
19
15
|
};
|
|
20
|
-
|
|
21
16
|
const ClassNameGenerator = createClassNameGenerator();
|
|
22
17
|
export default ClassNameGenerator;
|
|
@@ -2,17 +2,13 @@ export default function HTMLElementType(props, propName, componentName, location
|
|
|
2
2
|
if (process.env.NODE_ENV === 'production') {
|
|
3
3
|
return null;
|
|
4
4
|
}
|
|
5
|
-
|
|
6
5
|
const propValue = props[propName];
|
|
7
6
|
const safePropName = propFullName || propName;
|
|
8
|
-
|
|
9
7
|
if (propValue == null) {
|
|
10
8
|
return null;
|
|
11
9
|
}
|
|
12
|
-
|
|
13
10
|
if (propValue && propValue.nodeType !== 1) {
|
|
14
11
|
return new Error(`Invalid ${location} \`${safePropName}\` supplied to \`${componentName}\`. ` + `Expected an HTMLElement.`);
|
|
15
12
|
}
|
|
16
|
-
|
|
17
13
|
return null;
|
|
18
14
|
}
|
package/modern/capitalize.js
CHANGED
|
@@ -7,6 +7,5 @@ export default function capitalize(string) {
|
|
|
7
7
|
if (typeof string !== 'string') {
|
|
8
8
|
throw new Error(process.env.NODE_ENV !== "production" ? `MUI: \`capitalize(string)\` expects a string argument.` : _formatMuiErrorMessage(7));
|
|
9
9
|
}
|
|
10
|
-
|
|
11
10
|
return string.charAt(0).toUpperCase() + string.slice(1);
|
|
12
11
|
}
|
package/modern/chainPropTypes.js
CHANGED
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
export default function composeClasses(slots, getUtilityClass, classes) {
|
|
2
2
|
const output = {};
|
|
3
|
-
Object.keys(slots).forEach(
|
|
3
|
+
Object.keys(slots).forEach(
|
|
4
|
+
// `Objet.keys(slots)` can't be wider than `T` because we infer `T` from `slots`.
|
|
4
5
|
// @ts-expect-error https://github.com/microsoft/TypeScript/pull/12253#issuecomment-263132208
|
|
5
6
|
slot => {
|
|
6
7
|
output[slot] = slots[slot].reduce((acc, key) => {
|
|
7
8
|
if (key) {
|
|
8
9
|
acc.push(getUtilityClass(key));
|
|
9
|
-
|
|
10
10
|
if (classes && classes[key]) {
|
|
11
11
|
acc.push(classes[key]);
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
|
-
|
|
15
14
|
return acc;
|
|
16
15
|
}, []).join(' ');
|
|
17
16
|
});
|
package/modern/debounce.js
CHANGED
|
@@ -2,19 +2,15 @@
|
|
|
2
2
|
// A few bytes payload overhead when lodash/debounce is ~3 kB and debounce ~300 B.
|
|
3
3
|
export default function debounce(func, wait = 166) {
|
|
4
4
|
let timeout;
|
|
5
|
-
|
|
6
5
|
function debounced(...args) {
|
|
7
6
|
const later = () => {
|
|
8
7
|
func.apply(this, args);
|
|
9
8
|
};
|
|
10
|
-
|
|
11
9
|
clearTimeout(timeout);
|
|
12
10
|
timeout = setTimeout(later, wait);
|
|
13
11
|
}
|
|
14
|
-
|
|
15
12
|
debounced.clear = () => {
|
|
16
13
|
clearTimeout(timeout);
|
|
17
14
|
};
|
|
18
|
-
|
|
19
15
|
return debounced;
|
|
20
16
|
}
|
package/modern/deepmerge.js
CHANGED
|
@@ -6,14 +6,12 @@ export default function deepmerge(target, source, options = {
|
|
|
6
6
|
clone: true
|
|
7
7
|
}) {
|
|
8
8
|
const output = options.clone ? _extends({}, target) : target;
|
|
9
|
-
|
|
10
9
|
if (isPlainObject(target) && isPlainObject(source)) {
|
|
11
10
|
Object.keys(source).forEach(key => {
|
|
12
11
|
// Avoid prototype pollution
|
|
13
12
|
if (key === '__proto__') {
|
|
14
13
|
return;
|
|
15
14
|
}
|
|
16
|
-
|
|
17
15
|
if (isPlainObject(source[key]) && key in target && isPlainObject(target[key])) {
|
|
18
16
|
// Since `output` is a clone of `target` and we have narrowed `target` in this block we can cast to the same type.
|
|
19
17
|
output[key] = deepmerge(target[key], source[key], options);
|
|
@@ -22,6 +20,5 @@ export default function deepmerge(target, source, options = {
|
|
|
22
20
|
}
|
|
23
21
|
});
|
|
24
22
|
}
|
|
25
|
-
|
|
26
23
|
return output;
|
|
27
24
|
}
|
|
@@ -2,15 +2,12 @@ export default function deprecatedPropType(validator, reason) {
|
|
|
2
2
|
if (process.env.NODE_ENV === 'production') {
|
|
3
3
|
return () => null;
|
|
4
4
|
}
|
|
5
|
-
|
|
6
5
|
return (props, propName, componentName, location, propFullName) => {
|
|
7
6
|
const componentNameSafe = componentName || '<<anonymous>>';
|
|
8
7
|
const propFullNameSafe = propFullName || propName;
|
|
9
|
-
|
|
10
8
|
if (typeof props[propName] !== 'undefined') {
|
|
11
9
|
return new Error(`The ${location} \`${propFullNameSafe}\` of ` + `\`${componentNameSafe}\` is deprecated. ${reason}`);
|
|
12
10
|
}
|
|
13
|
-
|
|
14
11
|
return null;
|
|
15
12
|
};
|
|
16
13
|
}
|