@mui/utils 5.10.9 → 5.10.14
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 +574 -214
- package/ClassNameGenerator/ClassNameGenerator.d.ts +6 -6
- package/ClassNameGenerator/ClassNameGenerator.js +0 -6
- package/ClassNameGenerator/index.d.ts +1 -1
- package/ClassNameGenerator/index.js +0 -2
- package/HTMLElementType.d.ts +3 -3
- package/HTMLElementType.js +0 -5
- package/capitalize.js +0 -4
- package/chainPropTypes.d.ts +2 -2
- package/chainPropTypes.js +0 -2
- package/composeClasses/composeClasses.d.ts +1 -1
- package/composeClasses/composeClasses.js +2 -4
- package/composeClasses/index.d.ts +1 -1
- package/composeClasses/index.js +0 -2
- package/createChainedFunction.d.ts +7 -7
- package/createChainedFunction.js +0 -2
- package/debounce.js +0 -5
- package/deepmerge.d.ts +5 -5
- package/deepmerge.js +0 -7
- package/deprecatedPropType.js +0 -4
- package/elementAcceptingRef.d.ts +3 -3
- package/elementAcceptingRef.js +2 -12
- package/elementTypeAcceptingRef.d.ts +3 -3
- 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.d.ts +2 -2
- package/exactProp.js +1 -7
- package/formatMuiErrorMessage.d.ts +6 -6
- package/formatMuiErrorMessage.js +0 -4
- package/generateUtilityClass/generateUtilityClass.d.ts +2 -2
- package/generateUtilityClass/generateUtilityClass.js +0 -4
- package/generateUtilityClass/index.d.ts +2 -2
- package/generateUtilityClass/index.js +0 -4
- package/generateUtilityClasses/generateUtilityClasses.d.ts +1 -1
- package/generateUtilityClasses/generateUtilityClasses.js +0 -3
- package/generateUtilityClasses/index.d.ts +1 -1
- package/generateUtilityClasses/index.js +0 -2
- package/getDisplayName.d.ts +8 -8
- package/getDisplayName.js +3 -14
- package/getScrollbarSize.d.ts +1 -1
- package/getScrollbarSize.js +0 -1
- package/index.d.ts +38 -38
- package/index.js +1 -41
- package/integerPropType.d.ts +7 -7
- package/integerPropType.js +2 -21
- package/isMuiElement.d.ts +1 -1
- 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.d.ts +1 -1
- package/ownerDocument.js +0 -1
- package/ownerWindow.d.ts +1 -1
- package/ownerWindow.js +0 -3
- package/package.json +2 -2
- package/ponyfillGlobal.d.ts +2 -2
- package/ponyfillGlobal.js +0 -2
- package/refType.d.ts +3 -3
- package/refType.js +0 -4
- package/requirePropFactory.js +2 -11
- package/resolveProps.d.ts +9 -9
- package/resolveProps.js +0 -3
- package/scrollLeft.js +5 -12
- package/setRef.d.ts +15 -15
- package/setRef.js +0 -1
- package/unsupportedProp.js +0 -4
- package/useControlled.js +1 -6
- package/useEnhancedEffect.js +0 -4
- package/useEventCallback.d.ts +4 -4
- package/useEventCallback.js +2 -7
- package/useEventCallback.spec.d.ts +1 -1
- package/useForkRef.d.ts +2 -2
- package/useForkRef.js +2 -8
- package/useId.d.ts +7 -7
- package/useId.js +4 -11
- package/useIsFocusVisible.d.ts +9 -9
- package/useIsFocusVisible.js +11 -30
- package/usePreviousProps.d.ts +2 -2
- package/usePreviousProps.js +0 -5
- package/visuallyHidden.d.ts +2 -2
package/modern/scrollLeft.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// Source from https://github.com/alitaheri/normalize-scroll-left
|
|
2
2
|
let 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 @@ let 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
|
const dummy = document.createElement('div');
|
|
29
28
|
const 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
|
-
const scrollLeft = element.scrollLeft;
|
|
55
|
+
const 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
|
const 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
|
const propFullNameSafe = propFullName || propName;
|
|
7
|
-
|
|
8
6
|
if (typeof props[propName] !== 'undefined') {
|
|
9
7
|
return new Error(`The prop \`${propFullNameSafe}\` is not supported. Please remove it.`);
|
|
10
8
|
}
|
|
11
|
-
|
|
12
9
|
return null;
|
|
13
10
|
}
|
package/modern/useControlled.js
CHANGED
|
@@ -12,7 +12,6 @@ export default function useControlled({
|
|
|
12
12
|
} = React.useRef(controlled !== undefined);
|
|
13
13
|
const [valueState, setValue] = React.useState(defaultProp);
|
|
14
14
|
const value = isControlled ? controlled : valueState;
|
|
15
|
-
|
|
16
15
|
if (process.env.NODE_ENV !== 'production') {
|
|
17
16
|
React.useEffect(() => {
|
|
18
17
|
if (isControlled !== (controlled !== undefined)) {
|
|
@@ -28,7 +27,6 @@ export default function useControlled({
|
|
|
28
27
|
}
|
|
29
28
|
}, [JSON.stringify(defaultProp)]);
|
|
30
29
|
}
|
|
31
|
-
|
|
32
30
|
const setValueIfUncontrolled = React.useCallback(newValue => {
|
|
33
31
|
if (!isControlled) {
|
|
34
32
|
setValue(newValue);
|
|
@@ -1,15 +1,16 @@
|
|
|
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
|
const ref = React.useRef(fn);
|
|
9
9
|
useEnhancedEffect(() => {
|
|
10
10
|
ref.current = fn;
|
|
11
11
|
});
|
|
12
|
-
return React.useCallback((...args) =>
|
|
12
|
+
return React.useCallback((...args) =>
|
|
13
|
+
// @ts-expect-error hide `this`
|
|
13
14
|
// tslint:disable-next-line:ban-comma-operator
|
|
14
15
|
(0, ref.current)(...args), []);
|
|
15
16
|
}
|
package/modern/useForkRef.js
CHANGED
|
@@ -10,11 +10,11 @@ export default function useForkRef(...refs) {
|
|
|
10
10
|
if (refs.every(ref => ref == null)) {
|
|
11
11
|
return null;
|
|
12
12
|
}
|
|
13
|
-
|
|
14
13
|
return instance => {
|
|
15
14
|
refs.forEach(ref => {
|
|
16
15
|
setRef(ref, instance);
|
|
17
16
|
});
|
|
18
|
-
};
|
|
17
|
+
};
|
|
18
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
19
19
|
}, refs);
|
|
20
20
|
}
|
package/modern/useId.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
let globalId = 0;
|
|
3
|
-
|
|
4
3
|
function useGlobalId(idOverride) {
|
|
5
4
|
const [defaultId, setDefaultId] = React.useState(idOverride);
|
|
6
5
|
const id = idOverride || defaultId;
|
|
@@ -15,9 +14,9 @@ function useGlobalId(idOverride) {
|
|
|
15
14
|
}
|
|
16
15
|
}, [defaultId]);
|
|
17
16
|
return id;
|
|
18
|
-
}
|
|
19
|
-
|
|
17
|
+
}
|
|
20
18
|
|
|
19
|
+
// eslint-disable-next-line no-useless-concat -- Workaround for https://github.com/webpack/webpack/issues/14814
|
|
21
20
|
const maybeReactUseId = React['useId' + ''];
|
|
22
21
|
/**
|
|
23
22
|
*
|
|
@@ -25,13 +24,11 @@ const maybeReactUseId = React['useId' + ''];
|
|
|
25
24
|
* @param idOverride
|
|
26
25
|
* @returns {string}
|
|
27
26
|
*/
|
|
28
|
-
|
|
29
27
|
export default function useId(idOverride) {
|
|
30
28
|
if (maybeReactUseId !== undefined) {
|
|
31
29
|
const reactId = maybeReactUseId();
|
|
32
30
|
return idOverride ?? reactId;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
|
|
31
|
+
}
|
|
32
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks -- `React.useId` is invariant at runtime.
|
|
36
33
|
return useGlobalId(idOverride);
|
|
37
34
|
}
|
|
@@ -18,6 +18,7 @@ const 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,27 +26,23 @@ const inputTypesWhitelist = {
|
|
|
25
26
|
* @param {Element} node
|
|
26
27
|
* @returns {boolean}
|
|
27
28
|
*/
|
|
28
|
-
|
|
29
29
|
function focusTriggersKeyboardModality(node) {
|
|
30
30
|
const {
|
|
31
31
|
type,
|
|
32
32
|
tagName
|
|
33
33
|
} = node;
|
|
34
|
-
|
|
35
34
|
if (tagName === 'INPUT' && inputTypesWhitelist[type] && !node.readOnly) {
|
|
36
35
|
return true;
|
|
37
36
|
}
|
|
38
|
-
|
|
39
37
|
if (tagName === 'TEXTAREA' && !node.readOnly) {
|
|
40
38
|
return true;
|
|
41
39
|
}
|
|
42
|
-
|
|
43
40
|
if (node.isContentEditable) {
|
|
44
41
|
return true;
|
|
45
42
|
}
|
|
46
|
-
|
|
47
43
|
return false;
|
|
48
44
|
}
|
|
45
|
+
|
|
49
46
|
/**
|
|
50
47
|
* Keep track of our keyboard modality state with `hadKeyboardEvent`.
|
|
51
48
|
* If the most recent user interaction was via the keyboard;
|
|
@@ -53,15 +50,13 @@ function focusTriggersKeyboardModality(node) {
|
|
|
53
50
|
* then the modality is keyboard. Otherwise, the modality is not keyboard.
|
|
54
51
|
* @param {KeyboardEvent} event
|
|
55
52
|
*/
|
|
56
|
-
|
|
57
|
-
|
|
58
53
|
function handleKeyDown(event) {
|
|
59
54
|
if (event.metaKey || event.altKey || event.ctrlKey) {
|
|
60
55
|
return;
|
|
61
56
|
}
|
|
62
|
-
|
|
63
57
|
hadKeyboardEvent = true;
|
|
64
58
|
}
|
|
59
|
+
|
|
65
60
|
/**
|
|
66
61
|
* If at any point a user clicks with a pointing device, ensure that we change
|
|
67
62
|
* the modality away from keyboard.
|
|
@@ -69,12 +64,9 @@ function handleKeyDown(event) {
|
|
|
69
64
|
* element, and then clicks on a different element, focusing it with a
|
|
70
65
|
* pointing device, while we still think we're in keyboard modality.
|
|
71
66
|
*/
|
|
72
|
-
|
|
73
|
-
|
|
74
67
|
function handlePointerDown() {
|
|
75
68
|
hadKeyboardEvent = false;
|
|
76
69
|
}
|
|
77
|
-
|
|
78
70
|
function handleVisibilityChange() {
|
|
79
71
|
if (this.visibilityState === 'hidden') {
|
|
80
72
|
// If the tab becomes active again, the browser will handle calling focus
|
|
@@ -86,7 +78,6 @@ function handleVisibilityChange() {
|
|
|
86
78
|
}
|
|
87
79
|
}
|
|
88
80
|
}
|
|
89
|
-
|
|
90
81
|
function prepare(doc) {
|
|
91
82
|
doc.addEventListener('keydown', handleKeyDown, true);
|
|
92
83
|
doc.addEventListener('mousedown', handlePointerDown, true);
|
|
@@ -94,7 +85,6 @@ function prepare(doc) {
|
|
|
94
85
|
doc.addEventListener('touchstart', handlePointerDown, true);
|
|
95
86
|
doc.addEventListener('visibilitychange', handleVisibilityChange, true);
|
|
96
87
|
}
|
|
97
|
-
|
|
98
88
|
export function teardown(doc) {
|
|
99
89
|
doc.removeEventListener('keydown', handleKeyDown, true);
|
|
100
90
|
doc.removeEventListener('mousedown', handlePointerDown, true);
|
|
@@ -102,25 +92,23 @@ export function teardown(doc) {
|
|
|
102
92
|
doc.removeEventListener('touchstart', handlePointerDown, true);
|
|
103
93
|
doc.removeEventListener('visibilitychange', handleVisibilityChange, true);
|
|
104
94
|
}
|
|
105
|
-
|
|
106
95
|
function isFocusVisible(event) {
|
|
107
96
|
const {
|
|
108
97
|
target
|
|
109
98
|
} = event;
|
|
110
|
-
|
|
111
99
|
try {
|
|
112
100
|
return target.matches(':focus-visible');
|
|
113
|
-
} catch (error) {
|
|
101
|
+
} catch (error) {
|
|
102
|
+
// Browsers not implementing :focus-visible will throw a SyntaxError.
|
|
114
103
|
// We use our own heuristic for those browsers.
|
|
115
104
|
// Rethrow might be better if it's not the expected error but do we really
|
|
116
105
|
// want to crash if focus-visible malfunctioned?
|
|
117
|
-
}
|
|
118
|
-
// focusable events only.
|
|
119
|
-
|
|
106
|
+
}
|
|
120
107
|
|
|
108
|
+
// No need for validFocusTarget check. The user does that by attaching it to
|
|
109
|
+
// focusable events only.
|
|
121
110
|
return hadKeyboardEvent || focusTriggersKeyboardModality(target);
|
|
122
111
|
}
|
|
123
|
-
|
|
124
112
|
export default function useIsFocusVisible() {
|
|
125
113
|
const ref = React.useCallback(node => {
|
|
126
114
|
if (node != null) {
|
|
@@ -128,10 +116,10 @@ export default function useIsFocusVisible() {
|
|
|
128
116
|
}
|
|
129
117
|
}, []);
|
|
130
118
|
const isFocusVisibleRef = React.useRef(false);
|
|
119
|
+
|
|
131
120
|
/**
|
|
132
121
|
* Should be called if a blur event is fired
|
|
133
122
|
*/
|
|
134
|
-
|
|
135
123
|
function handleBlurVisible() {
|
|
136
124
|
// checking against potential state variable does not suffice if we focus and blur synchronously.
|
|
137
125
|
// React wouldn't have time to trigger a re-render so `focusVisible` would be stale.
|
|
@@ -151,23 +139,19 @@ export default function useIsFocusVisible() {
|
|
|
151
139
|
isFocusVisibleRef.current = false;
|
|
152
140
|
return true;
|
|
153
141
|
}
|
|
154
|
-
|
|
155
142
|
return false;
|
|
156
143
|
}
|
|
144
|
+
|
|
157
145
|
/**
|
|
158
146
|
* Should be called if a blur event is fired
|
|
159
147
|
*/
|
|
160
|
-
|
|
161
|
-
|
|
162
148
|
function handleFocusVisible(event) {
|
|
163
149
|
if (isFocusVisible(event)) {
|
|
164
150
|
isFocusVisibleRef.current = true;
|
|
165
151
|
return true;
|
|
166
152
|
}
|
|
167
|
-
|
|
168
153
|
return false;
|
|
169
154
|
}
|
|
170
|
-
|
|
171
155
|
return {
|
|
172
156
|
isFocusVisibleRef,
|
|
173
157
|
onFocus: handleFocusVisible,
|
package/ownerDocument.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export default function ownerDocument(node: Node | null | undefined): Document;
|
|
1
|
+
export default function ownerDocument(node: Node | null | undefined): Document;
|
package/ownerDocument.js
CHANGED
package/ownerWindow.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export default function ownerWindow(node: Node | undefined): Window;
|
|
1
|
+
export default function ownerWindow(node: Node | undefined): Window;
|
package/ownerWindow.js
CHANGED
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.default = ownerWindow;
|
|
9
|
-
|
|
10
8
|
var _ownerDocument = _interopRequireDefault(require("./ownerDocument"));
|
|
11
|
-
|
|
12
9
|
function ownerWindow(node) {
|
|
13
10
|
const doc = (0, _ownerDocument.default)(node);
|
|
14
11
|
return doc.defaultView || window;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mui/utils",
|
|
3
|
-
"version": "5.10.
|
|
3
|
+
"version": "5.10.14",
|
|
4
4
|
"private": false,
|
|
5
5
|
"author": "MUI Team",
|
|
6
6
|
"description": "Utility functions for React components.",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"react": "^17.0.0 || ^18.0.0"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@babel/runtime": "^7.
|
|
32
|
+
"@babel/runtime": "^7.20.1",
|
|
33
33
|
"@types/prop-types": "^15.7.5",
|
|
34
34
|
"@types/react-is": "^16.7.1 || ^17.0.0",
|
|
35
35
|
"prop-types": "^15.8.1",
|
package/ponyfillGlobal.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default: any;
|
|
2
|
-
export default _default;
|
|
1
|
+
declare const _default: any;
|
|
2
|
+
export default _default;
|
package/ponyfillGlobal.js
CHANGED
|
@@ -4,9 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
/* eslint-disable */
|
|
9
8
|
// https://github.com/zloirock/core-js/issues/86#issuecomment-115759028
|
|
10
9
|
var _default = typeof window != 'undefined' && window.Math == Math ? window : typeof self != 'undefined' && self.Math == Math ? self : Function('return this')();
|
|
11
|
-
|
|
12
10
|
exports.default = _default;
|
package/refType.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import PropTypes from 'prop-types';
|
|
2
|
-
declare const refType: PropTypes.Requireable<object>;
|
|
3
|
-
export default refType;
|
|
1
|
+
import PropTypes from 'prop-types';
|
|
2
|
+
declare const refType: PropTypes.Requireable<object>;
|
|
3
|
+
export default refType;
|
package/refType.js
CHANGED
|
@@ -1,15 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.default = void 0;
|
|
9
|
-
|
|
10
8
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
11
|
-
|
|
12
9
|
const refType = _propTypes.default.oneOfType([_propTypes.default.func, _propTypes.default.object]);
|
|
13
|
-
|
|
14
10
|
var _default = refType;
|
|
15
11
|
exports.default = _default;
|
package/requirePropFactory.js
CHANGED
|
@@ -1,40 +1,31 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.default = requirePropFactory;
|
|
9
|
-
|
|
10
8
|
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
11
|
-
|
|
12
9
|
function requirePropFactory(componentNameInError, Component) {
|
|
13
10
|
if (process.env.NODE_ENV === 'production') {
|
|
14
11
|
return () => null;
|
|
15
|
-
}
|
|
16
|
-
|
|
12
|
+
}
|
|
17
13
|
|
|
14
|
+
// eslint-disable-next-line react/forbid-foreign-prop-types
|
|
18
15
|
const prevPropTypes = Component ? (0, _extends2.default)({}, Component.propTypes) : null;
|
|
19
|
-
|
|
20
16
|
const requireProp = requiredProp => (props, propName, componentName, location, propFullName, ...args) => {
|
|
21
17
|
const propFullNameSafe = propFullName || propName;
|
|
22
18
|
const defaultTypeChecker = prevPropTypes == null ? void 0 : prevPropTypes[propFullNameSafe];
|
|
23
|
-
|
|
24
19
|
if (defaultTypeChecker) {
|
|
25
20
|
const typeCheckerResult = defaultTypeChecker(props, propName, componentName, location, propFullName, ...args);
|
|
26
|
-
|
|
27
21
|
if (typeCheckerResult) {
|
|
28
22
|
return typeCheckerResult;
|
|
29
23
|
}
|
|
30
24
|
}
|
|
31
|
-
|
|
32
25
|
if (typeof props[propName] !== 'undefined' && !props[requiredProp]) {
|
|
33
26
|
return new Error(`The prop \`${propFullNameSafe}\` of ` + `\`${componentNameInError}\` can only be used together with the \`${requiredProp}\` prop.`);
|
|
34
27
|
}
|
|
35
|
-
|
|
36
28
|
return null;
|
|
37
29
|
};
|
|
38
|
-
|
|
39
30
|
return requireProp;
|
|
40
31
|
}
|
package/resolveProps.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Add keys, values of `defaultProps` that does not exist in `props`
|
|
3
|
-
* @param {object} defaultProps
|
|
4
|
-
* @param {object} props
|
|
5
|
-
* @returns {object} resolved props
|
|
6
|
-
*/
|
|
7
|
-
export default function resolveProps<T extends {
|
|
8
|
-
className?: string;
|
|
9
|
-
} & Record<string, unknown>>(defaultProps: T, props: T): T;
|
|
1
|
+
/**
|
|
2
|
+
* Add keys, values of `defaultProps` that does not exist in `props`
|
|
3
|
+
* @param {object} defaultProps
|
|
4
|
+
* @param {object} props
|
|
5
|
+
* @returns {object} resolved props
|
|
6
|
+
*/
|
|
7
|
+
export default function resolveProps<T extends {
|
|
8
|
+
className?: string;
|
|
9
|
+
} & Record<string, unknown>>(defaultProps: T, props: T): T;
|
package/resolveProps.js
CHANGED
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.default = resolveProps;
|
|
9
|
-
|
|
10
8
|
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
11
|
-
|
|
12
9
|
/**
|
|
13
10
|
* Add keys, values of `defaultProps` that does not exist in `props`
|
|
14
11
|
* @param {object} defaultProps
|
package/scrollLeft.js
CHANGED
|
@@ -7,6 +7,7 @@ exports.detectScrollType = detectScrollType;
|
|
|
7
7
|
exports.getNormalizedScrollLeft = getNormalizedScrollLeft;
|
|
8
8
|
// Source from https://github.com/alitaheri/normalize-scroll-left
|
|
9
9
|
let cachedType;
|
|
10
|
+
|
|
10
11
|
/**
|
|
11
12
|
* Based on the jquery plugin https://github.com/othree/jquery.rtl-scroll-type
|
|
12
13
|
*
|
|
@@ -26,12 +27,10 @@ let cachedType;
|
|
|
26
27
|
*
|
|
27
28
|
* spec* https://drafts.csswg.org/cssom-view/#dom-window-scroll
|
|
28
29
|
*/
|
|
29
|
-
|
|
30
30
|
function detectScrollType() {
|
|
31
31
|
if (cachedType) {
|
|
32
32
|
return cachedType;
|
|
33
33
|
}
|
|
34
|
-
|
|
35
34
|
const dummy = document.createElement('div');
|
|
36
35
|
const container = document.createElement('div');
|
|
37
36
|
container.style.width = '10px';
|
|
@@ -46,38 +45,32 @@ function detectScrollType() {
|
|
|
46
45
|
dummy.style.overflow = 'scroll';
|
|
47
46
|
document.body.appendChild(dummy);
|
|
48
47
|
cachedType = 'reverse';
|
|
49
|
-
|
|
50
48
|
if (dummy.scrollLeft > 0) {
|
|
51
49
|
cachedType = 'default';
|
|
52
50
|
} else {
|
|
53
51
|
dummy.scrollLeft = 1;
|
|
54
|
-
|
|
55
52
|
if (dummy.scrollLeft === 0) {
|
|
56
53
|
cachedType = 'negative';
|
|
57
54
|
}
|
|
58
55
|
}
|
|
59
|
-
|
|
60
56
|
document.body.removeChild(dummy);
|
|
61
57
|
return cachedType;
|
|
62
|
-
}
|
|
63
|
-
|
|
58
|
+
}
|
|
64
59
|
|
|
60
|
+
// Based on https://stackoverflow.com/a/24394376
|
|
65
61
|
function getNormalizedScrollLeft(element, direction) {
|
|
66
|
-
const scrollLeft = element.scrollLeft;
|
|
62
|
+
const scrollLeft = element.scrollLeft;
|
|
67
63
|
|
|
64
|
+
// Perform the calculations only when direction is rtl to avoid messing up the ltr behavior
|
|
68
65
|
if (direction !== 'rtl') {
|
|
69
66
|
return scrollLeft;
|
|
70
67
|
}
|
|
71
|
-
|
|
72
68
|
const type = detectScrollType();
|
|
73
|
-
|
|
74
69
|
switch (type) {
|
|
75
70
|
case 'negative':
|
|
76
71
|
return element.scrollWidth - element.clientWidth + scrollLeft;
|
|
77
|
-
|
|
78
72
|
case 'reverse':
|
|
79
73
|
return element.scrollWidth - element.clientWidth - scrollLeft;
|
|
80
|
-
|
|
81
74
|
default:
|
|
82
75
|
return scrollLeft;
|
|
83
76
|
}
|
package/setRef.d.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
/**
|
|
3
|
-
* TODO v5: consider making it private
|
|
4
|
-
*
|
|
5
|
-
* passes {value} to {ref}
|
|
6
|
-
*
|
|
7
|
-
* WARNING: Be sure to only call this inside a callback that is passed as a ref.
|
|
8
|
-
* Otherwise, make sure to cleanup the previous {ref} if it changes. See
|
|
9
|
-
* https://github.com/mui/material-ui/issues/13539
|
|
10
|
-
*
|
|
11
|
-
* Useful if you want to expose the ref of an inner component to the public API
|
|
12
|
-
* while still using it inside the component.
|
|
13
|
-
* @param ref A ref callback or ref object. If anything falsy, this is a no-op.
|
|
14
|
-
*/
|
|
15
|
-
export default function setRef<T>(ref: React.MutableRefObject<T | null> | ((instance: T | null) => void) | null | undefined, value: T | null): void;
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* TODO v5: consider making it private
|
|
4
|
+
*
|
|
5
|
+
* passes {value} to {ref}
|
|
6
|
+
*
|
|
7
|
+
* WARNING: Be sure to only call this inside a callback that is passed as a ref.
|
|
8
|
+
* Otherwise, make sure to cleanup the previous {ref} if it changes. See
|
|
9
|
+
* https://github.com/mui/material-ui/issues/13539
|
|
10
|
+
*
|
|
11
|
+
* Useful if you want to expose the ref of an inner component to the public API
|
|
12
|
+
* while still using it inside the component.
|
|
13
|
+
* @param ref A ref callback or ref object. If anything falsy, this is a no-op.
|
|
14
|
+
*/
|
|
15
|
+
export default function setRef<T>(ref: React.MutableRefObject<T | null> | ((instance: T | null) => void) | null | undefined, value: T | null): void;
|
package/setRef.js
CHANGED
package/unsupportedProp.js
CHANGED
|
@@ -4,17 +4,13 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = unsupportedProp;
|
|
7
|
-
|
|
8
7
|
function unsupportedProp(props, propName, componentName, location, propFullName) {
|
|
9
8
|
if (process.env.NODE_ENV === 'production') {
|
|
10
9
|
return null;
|
|
11
10
|
}
|
|
12
|
-
|
|
13
11
|
const propFullNameSafe = propFullName || propName;
|
|
14
|
-
|
|
15
12
|
if (typeof props[propName] !== 'undefined') {
|
|
16
13
|
return new Error(`The prop \`${propFullNameSafe}\` is not supported. Please remove it.`);
|
|
17
14
|
}
|
|
18
|
-
|
|
19
15
|
return null;
|
|
20
16
|
}
|
package/useControlled.js
CHANGED
|
@@ -4,14 +4,11 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = useControlled;
|
|
7
|
-
|
|
8
7
|
var React = _interopRequireWildcard(require("react"));
|
|
9
|
-
|
|
10
8
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
11
|
-
|
|
12
9
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
13
|
-
|
|
14
10
|
/* eslint-disable react-hooks/rules-of-hooks, react-hooks/exhaustive-deps */
|
|
11
|
+
|
|
15
12
|
function useControlled({
|
|
16
13
|
controlled,
|
|
17
14
|
default: defaultProp,
|
|
@@ -24,7 +21,6 @@ function useControlled({
|
|
|
24
21
|
} = React.useRef(controlled !== undefined);
|
|
25
22
|
const [valueState, setValue] = React.useState(defaultProp);
|
|
26
23
|
const value = isControlled ? controlled : valueState;
|
|
27
|
-
|
|
28
24
|
if (process.env.NODE_ENV !== 'production') {
|
|
29
25
|
React.useEffect(() => {
|
|
30
26
|
if (isControlled !== (controlled !== undefined)) {
|
|
@@ -40,7 +36,6 @@ function useControlled({
|
|
|
40
36
|
}
|
|
41
37
|
}, [JSON.stringify(defaultProp)]);
|
|
42
38
|
}
|
|
43
|
-
|
|
44
39
|
const setValueIfUncontrolled = React.useCallback(newValue => {
|
|
45
40
|
if (!isControlled) {
|
|
46
41
|
setValue(newValue);
|
package/useEnhancedEffect.js
CHANGED
|
@@ -4,13 +4,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
var React = _interopRequireWildcard(require("react"));
|
|
9
|
-
|
|
10
8
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
11
|
-
|
|
12
9
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
13
|
-
|
|
14
10
|
const useEnhancedEffect = typeof window !== 'undefined' ? React.useLayoutEffect : React.useEffect;
|
|
15
11
|
var _default = useEnhancedEffect;
|
|
16
12
|
exports.default = _default;
|