@mui/utils 5.2.1 → 5.4.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/CHANGELOG.md +758 -60
- package/esm/index.js +2 -1
- package/esm/resolveProps.js +18 -0
- package/esm/setRef.js +1 -1
- package/esm/useId.js +26 -3
- package/esm/useIsFocusVisible.js +1 -1
- package/index.d.ts +1 -0
- package/index.js +9 -1
- package/legacy/index.js +3 -2
- package/legacy/resolveProps.js +18 -0
- package/legacy/setRef.js +1 -1
- package/legacy/useId.js +26 -3
- package/legacy/useIsFocusVisible.js +4 -3
- package/modern/index.js +3 -2
- package/modern/resolveProps.js +18 -0
- package/modern/setRef.js +1 -1
- package/modern/useId.js +26 -3
- package/modern/useIsFocusVisible.js +1 -1
- package/package.json +10 -6
- package/resolveProps.d.ts +9 -0
- package/resolveProps.js +26 -0
- package/setRef.d.ts +1 -1
- package/setRef.js +1 -1
- package/useId.d.ts +6 -0
- package/useId.js +26 -3
- package/useIsFocusVisible.d.ts +8 -7
- package/useIsFocusVisible.js +1 -1
package/esm/index.js
CHANGED
|
@@ -29,4 +29,5 @@ export { default as unstable_getScrollbarSize } from './getScrollbarSize';
|
|
|
29
29
|
export { detectScrollType as unstable_detectScrollType, getNormalizedScrollLeft as unstable_getNormalizedScrollLeft } from './scrollLeft';
|
|
30
30
|
export { default as usePreviousProps } from './usePreviousProps';
|
|
31
31
|
export { default as visuallyHidden } from './visuallyHidden';
|
|
32
|
-
export { default as integerPropType } from './integerPropType';
|
|
32
|
+
export { default as integerPropType } from './integerPropType';
|
|
33
|
+
export { default as internal_resolveProps } from './resolveProps';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Add keys, values of `defaultProps` that does not exist in `props`
|
|
5
|
+
* @param {object} defaultProps
|
|
6
|
+
* @param {object} props
|
|
7
|
+
* @returns {object} resolved props
|
|
8
|
+
*/
|
|
9
|
+
export default function resolveProps(defaultProps, props) {
|
|
10
|
+
const output = _extends({}, props);
|
|
11
|
+
|
|
12
|
+
Object.keys(defaultProps).forEach(propName => {
|
|
13
|
+
if (output[propName] === undefined) {
|
|
14
|
+
output[propName] = defaultProps[propName];
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
return output;
|
|
18
|
+
}
|
package/esm/setRef.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
*
|
|
6
6
|
* WARNING: Be sure to only call this inside a callback that is passed as a ref.
|
|
7
7
|
* Otherwise, make sure to cleanup the previous {ref} if it changes. See
|
|
8
|
-
* https://github.com/mui
|
|
8
|
+
* https://github.com/mui/material-ui/issues/13539
|
|
9
9
|
*
|
|
10
10
|
* Useful if you want to expose the ref of an inner component to the public API
|
|
11
11
|
* while still using it inside the component.
|
package/esm/useId.js
CHANGED
|
@@ -1,14 +1,37 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
|
|
2
|
+
let globalId = 0;
|
|
3
|
+
|
|
4
|
+
function useGlobalId(idOverride) {
|
|
3
5
|
const [defaultId, setDefaultId] = React.useState(idOverride);
|
|
4
6
|
const id = idOverride || defaultId;
|
|
5
7
|
React.useEffect(() => {
|
|
6
8
|
if (defaultId == null) {
|
|
7
9
|
// Fallback to this default id when possible.
|
|
8
|
-
// Use the
|
|
10
|
+
// Use the incrementing value for client-side rendering only.
|
|
9
11
|
// We can't use it server-side.
|
|
10
|
-
|
|
12
|
+
// If you want to use random values please consider the Birthday Problem: https://en.wikipedia.org/wiki/Birthday_problem
|
|
13
|
+
globalId += 1;
|
|
14
|
+
setDefaultId(`mui-${globalId}`);
|
|
11
15
|
}
|
|
12
16
|
}, [defaultId]);
|
|
13
17
|
return id;
|
|
18
|
+
} // eslint-disable-next-line no-useless-concat -- Workaround for https://github.com/webpack/webpack/issues/14814
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
const maybeReactUseId = React['useId' + ''];
|
|
22
|
+
/**
|
|
23
|
+
*
|
|
24
|
+
* @example <div id={useId()} />
|
|
25
|
+
* @param idOverride
|
|
26
|
+
* @returns {string}
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
export default function useId(idOverride) {
|
|
30
|
+
if (maybeReactUseId !== undefined) {
|
|
31
|
+
const reactId = maybeReactUseId();
|
|
32
|
+
return idOverride != null ? idOverride : reactId;
|
|
33
|
+
} // eslint-disable-next-line react-hooks/rules-of-hooks -- `React.useId` is invariant at runtime.
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
return useGlobalId(idOverride);
|
|
14
37
|
}
|
package/esm/useIsFocusVisible.js
CHANGED
package/index.d.ts
CHANGED
|
@@ -30,3 +30,4 @@ export { detectScrollType as unstable_detectScrollType, getNormalizedScrollLeft
|
|
|
30
30
|
export { default as usePreviousProps } from './usePreviousProps';
|
|
31
31
|
export { default as visuallyHidden } from './visuallyHidden';
|
|
32
32
|
export { default as integerPropType } from './integerPropType';
|
|
33
|
+
export { default as internal_resolveProps } from './resolveProps';
|
package/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** @license MUI v5.
|
|
1
|
+
/** @license MUI v5.4.1
|
|
2
2
|
*
|
|
3
3
|
* This source code is licensed under the MIT license found in the
|
|
4
4
|
* LICENSE file in the root directory of this source tree.
|
|
@@ -64,6 +64,12 @@ Object.defineProperty(exports, "integerPropType", {
|
|
|
64
64
|
return _integerPropType.default;
|
|
65
65
|
}
|
|
66
66
|
});
|
|
67
|
+
Object.defineProperty(exports, "internal_resolveProps", {
|
|
68
|
+
enumerable: true,
|
|
69
|
+
get: function () {
|
|
70
|
+
return _resolveProps.default;
|
|
71
|
+
}
|
|
72
|
+
});
|
|
67
73
|
Object.defineProperty(exports, "isPlainObject", {
|
|
68
74
|
enumerable: true,
|
|
69
75
|
get: function () {
|
|
@@ -271,6 +277,8 @@ var _visuallyHidden = _interopRequireDefault(require("./visuallyHidden"));
|
|
|
271
277
|
|
|
272
278
|
var _integerPropType = _interopRequireDefault(require("./integerPropType"));
|
|
273
279
|
|
|
280
|
+
var _resolveProps = _interopRequireDefault(require("./resolveProps"));
|
|
281
|
+
|
|
274
282
|
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); }
|
|
275
283
|
|
|
276
284
|
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; }
|
package/legacy/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** @license MUI v5.
|
|
1
|
+
/** @license MUI v5.4.1
|
|
2
2
|
*
|
|
3
3
|
* This source code is licensed under the MIT license found in the
|
|
4
4
|
* LICENSE file in the root directory of this source tree.
|
|
@@ -34,4 +34,5 @@ export { default as unstable_getScrollbarSize } from './getScrollbarSize';
|
|
|
34
34
|
export { detectScrollType as unstable_detectScrollType, getNormalizedScrollLeft as unstable_getNormalizedScrollLeft } from './scrollLeft';
|
|
35
35
|
export { default as usePreviousProps } from './usePreviousProps';
|
|
36
36
|
export { default as visuallyHidden } from './visuallyHidden';
|
|
37
|
-
export { default as integerPropType } from './integerPropType';
|
|
37
|
+
export { default as integerPropType } from './integerPropType';
|
|
38
|
+
export { default as internal_resolveProps } from './resolveProps';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Add keys, values of `defaultProps` that does not exist in `props`
|
|
5
|
+
* @param {object} defaultProps
|
|
6
|
+
* @param {object} props
|
|
7
|
+
* @returns {object} resolved props
|
|
8
|
+
*/
|
|
9
|
+
export default function resolveProps(defaultProps, props) {
|
|
10
|
+
var output = _extends({}, props);
|
|
11
|
+
|
|
12
|
+
Object.keys(defaultProps).forEach(function (propName) {
|
|
13
|
+
if (output[propName] === undefined) {
|
|
14
|
+
output[propName] = defaultProps[propName];
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
return output;
|
|
18
|
+
}
|
package/legacy/setRef.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
*
|
|
6
6
|
* WARNING: Be sure to only call this inside a callback that is passed as a ref.
|
|
7
7
|
* Otherwise, make sure to cleanup the previous {ref} if it changes. See
|
|
8
|
-
* https://github.com/mui
|
|
8
|
+
* https://github.com/mui/material-ui/issues/13539
|
|
9
9
|
*
|
|
10
10
|
* Useful if you want to expose the ref of an inner component to the public API
|
|
11
11
|
* while still using it inside the component.
|
package/legacy/useId.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
|
|
2
|
+
var globalId = 0;
|
|
3
|
+
|
|
4
|
+
function useGlobalId(idOverride) {
|
|
3
5
|
var _React$useState = React.useState(idOverride),
|
|
4
6
|
defaultId = _React$useState[0],
|
|
5
7
|
setDefaultId = _React$useState[1];
|
|
@@ -8,10 +10,31 @@ export default function useId(idOverride) {
|
|
|
8
10
|
React.useEffect(function () {
|
|
9
11
|
if (defaultId == null) {
|
|
10
12
|
// Fallback to this default id when possible.
|
|
11
|
-
// Use the
|
|
13
|
+
// Use the incrementing value for client-side rendering only.
|
|
12
14
|
// We can't use it server-side.
|
|
13
|
-
|
|
15
|
+
// If you want to use random values please consider the Birthday Problem: https://en.wikipedia.org/wiki/Birthday_problem
|
|
16
|
+
globalId += 1;
|
|
17
|
+
setDefaultId("mui-".concat(globalId));
|
|
14
18
|
}
|
|
15
19
|
}, [defaultId]);
|
|
16
20
|
return id;
|
|
21
|
+
} // eslint-disable-next-line no-useless-concat -- Workaround for https://github.com/webpack/webpack/issues/14814
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
var maybeReactUseId = React['useId' + ''];
|
|
25
|
+
/**
|
|
26
|
+
*
|
|
27
|
+
* @example <div id={useId()} />
|
|
28
|
+
* @param idOverride
|
|
29
|
+
* @returns {string}
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
export default function useId(idOverride) {
|
|
33
|
+
if (maybeReactUseId !== undefined) {
|
|
34
|
+
var reactId = maybeReactUseId();
|
|
35
|
+
return idOverride != null ? idOverride : reactId;
|
|
36
|
+
} // eslint-disable-next-line react-hooks/rules-of-hooks -- `React.useId` is invariant at runtime.
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
return useGlobalId(idOverride);
|
|
17
40
|
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import * as React from 'react';
|
|
3
3
|
var hadKeyboardEvent = true;
|
|
4
4
|
var hadFocusVisibleRecently = false;
|
|
5
|
-
var hadFocusVisibleRecentlyTimeout
|
|
5
|
+
var hadFocusVisibleRecentlyTimeout;
|
|
6
6
|
var inputTypesWhitelist = {
|
|
7
7
|
text: true,
|
|
8
8
|
search: true,
|
|
@@ -27,8 +27,9 @@ var inputTypesWhitelist = {
|
|
|
27
27
|
*/
|
|
28
28
|
|
|
29
29
|
function focusTriggersKeyboardModality(node) {
|
|
30
|
-
var
|
|
31
|
-
|
|
30
|
+
var _ref = node,
|
|
31
|
+
type = _ref.type,
|
|
32
|
+
tagName = _ref.tagName;
|
|
32
33
|
|
|
33
34
|
if (tagName === 'INPUT' && inputTypesWhitelist[type] && !node.readOnly) {
|
|
34
35
|
return true;
|
package/modern/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** @license MUI v5.
|
|
1
|
+
/** @license MUI v5.4.1
|
|
2
2
|
*
|
|
3
3
|
* This source code is licensed under the MIT license found in the
|
|
4
4
|
* LICENSE file in the root directory of this source tree.
|
|
@@ -34,4 +34,5 @@ export { default as unstable_getScrollbarSize } from './getScrollbarSize';
|
|
|
34
34
|
export { detectScrollType as unstable_detectScrollType, getNormalizedScrollLeft as unstable_getNormalizedScrollLeft } from './scrollLeft';
|
|
35
35
|
export { default as usePreviousProps } from './usePreviousProps';
|
|
36
36
|
export { default as visuallyHidden } from './visuallyHidden';
|
|
37
|
-
export { default as integerPropType } from './integerPropType';
|
|
37
|
+
export { default as integerPropType } from './integerPropType';
|
|
38
|
+
export { default as internal_resolveProps } from './resolveProps';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Add keys, values of `defaultProps` that does not exist in `props`
|
|
5
|
+
* @param {object} defaultProps
|
|
6
|
+
* @param {object} props
|
|
7
|
+
* @returns {object} resolved props
|
|
8
|
+
*/
|
|
9
|
+
export default function resolveProps(defaultProps, props) {
|
|
10
|
+
const output = _extends({}, props);
|
|
11
|
+
|
|
12
|
+
Object.keys(defaultProps).forEach(propName => {
|
|
13
|
+
if (output[propName] === undefined) {
|
|
14
|
+
output[propName] = defaultProps[propName];
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
return output;
|
|
18
|
+
}
|
package/modern/setRef.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
*
|
|
6
6
|
* WARNING: Be sure to only call this inside a callback that is passed as a ref.
|
|
7
7
|
* Otherwise, make sure to cleanup the previous {ref} if it changes. See
|
|
8
|
-
* https://github.com/mui
|
|
8
|
+
* https://github.com/mui/material-ui/issues/13539
|
|
9
9
|
*
|
|
10
10
|
* Useful if you want to expose the ref of an inner component to the public API
|
|
11
11
|
* while still using it inside the component.
|
package/modern/useId.js
CHANGED
|
@@ -1,14 +1,37 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
|
|
2
|
+
let globalId = 0;
|
|
3
|
+
|
|
4
|
+
function useGlobalId(idOverride) {
|
|
3
5
|
const [defaultId, setDefaultId] = React.useState(idOverride);
|
|
4
6
|
const id = idOverride || defaultId;
|
|
5
7
|
React.useEffect(() => {
|
|
6
8
|
if (defaultId == null) {
|
|
7
9
|
// Fallback to this default id when possible.
|
|
8
|
-
// Use the
|
|
10
|
+
// Use the incrementing value for client-side rendering only.
|
|
9
11
|
// We can't use it server-side.
|
|
10
|
-
|
|
12
|
+
// If you want to use random values please consider the Birthday Problem: https://en.wikipedia.org/wiki/Birthday_problem
|
|
13
|
+
globalId += 1;
|
|
14
|
+
setDefaultId(`mui-${globalId}`);
|
|
11
15
|
}
|
|
12
16
|
}, [defaultId]);
|
|
13
17
|
return id;
|
|
18
|
+
} // eslint-disable-next-line no-useless-concat -- Workaround for https://github.com/webpack/webpack/issues/14814
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
const maybeReactUseId = React['useId' + ''];
|
|
22
|
+
/**
|
|
23
|
+
*
|
|
24
|
+
* @example <div id={useId()} />
|
|
25
|
+
* @param idOverride
|
|
26
|
+
* @returns {string}
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
export default function useId(idOverride) {
|
|
30
|
+
if (maybeReactUseId !== undefined) {
|
|
31
|
+
const reactId = maybeReactUseId();
|
|
32
|
+
return idOverride ?? reactId;
|
|
33
|
+
} // eslint-disable-next-line react-hooks/rules-of-hooks -- `React.useId` is invariant at runtime.
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
return useGlobalId(idOverride);
|
|
14
37
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mui/utils",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.4.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"author": "MUI Team",
|
|
6
6
|
"description": "Utility functions for React components.",
|
|
@@ -13,19 +13,23 @@
|
|
|
13
13
|
],
|
|
14
14
|
"repository": {
|
|
15
15
|
"type": "git",
|
|
16
|
-
"url": "https://github.com/mui
|
|
16
|
+
"url": "https://github.com/mui/material-ui.git",
|
|
17
17
|
"directory": "packages/mui-utils"
|
|
18
18
|
},
|
|
19
19
|
"license": "MIT",
|
|
20
20
|
"bugs": {
|
|
21
|
-
"url": "https://github.com/mui
|
|
21
|
+
"url": "https://github.com/mui/material-ui/issues"
|
|
22
|
+
},
|
|
23
|
+
"homepage": "https://github.com/mui/material-ui/tree/master/packages/mui-utils",
|
|
24
|
+
"funding": {
|
|
25
|
+
"type": "opencollective",
|
|
26
|
+
"url": "https://opencollective.com/mui"
|
|
22
27
|
},
|
|
23
|
-
"homepage": "https://github.com/mui-org/material-ui/tree/master/packages/mui-utils",
|
|
24
28
|
"peerDependencies": {
|
|
25
|
-
"react": "^17.0.
|
|
29
|
+
"react": "^17.0.0"
|
|
26
30
|
},
|
|
27
31
|
"dependencies": {
|
|
28
|
-
"@babel/runtime": "^7.
|
|
32
|
+
"@babel/runtime": "^7.17.0",
|
|
29
33
|
"@types/prop-types": "^15.7.4",
|
|
30
34
|
"@types/react-is": "^16.7.1 || ^17.0.0",
|
|
31
35
|
"prop-types": "^15.7.2",
|
|
@@ -0,0 +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;
|
package/resolveProps.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.default = resolveProps;
|
|
9
|
+
|
|
10
|
+
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Add keys, values of `defaultProps` that does not exist in `props`
|
|
14
|
+
* @param {object} defaultProps
|
|
15
|
+
* @param {object} props
|
|
16
|
+
* @returns {object} resolved props
|
|
17
|
+
*/
|
|
18
|
+
function resolveProps(defaultProps, props) {
|
|
19
|
+
const output = (0, _extends2.default)({}, props);
|
|
20
|
+
Object.keys(defaultProps).forEach(propName => {
|
|
21
|
+
if (output[propName] === undefined) {
|
|
22
|
+
output[propName] = defaultProps[propName];
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
return output;
|
|
26
|
+
}
|
package/setRef.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ import * as React from 'react';
|
|
|
6
6
|
*
|
|
7
7
|
* WARNING: Be sure to only call this inside a callback that is passed as a ref.
|
|
8
8
|
* Otherwise, make sure to cleanup the previous {ref} if it changes. See
|
|
9
|
-
* https://github.com/mui
|
|
9
|
+
* https://github.com/mui/material-ui/issues/13539
|
|
10
10
|
*
|
|
11
11
|
* Useful if you want to expose the ref of an inner component to the public API
|
|
12
12
|
* while still using it inside the component.
|
package/setRef.js
CHANGED
|
@@ -12,7 +12,7 @@ exports.default = setRef;
|
|
|
12
12
|
*
|
|
13
13
|
* WARNING: Be sure to only call this inside a callback that is passed as a ref.
|
|
14
14
|
* Otherwise, make sure to cleanup the previous {ref} if it changes. See
|
|
15
|
-
* https://github.com/mui
|
|
15
|
+
* https://github.com/mui/material-ui/issues/13539
|
|
16
16
|
*
|
|
17
17
|
* Useful if you want to expose the ref of an inner component to the public API
|
|
18
18
|
* while still using it inside the component.
|
package/useId.d.ts
CHANGED
package/useId.js
CHANGED
|
@@ -11,16 +11,39 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
|
|
|
11
11
|
|
|
12
12
|
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
13
|
|
|
14
|
-
|
|
14
|
+
let globalId = 0;
|
|
15
|
+
|
|
16
|
+
function useGlobalId(idOverride) {
|
|
15
17
|
const [defaultId, setDefaultId] = React.useState(idOverride);
|
|
16
18
|
const id = idOverride || defaultId;
|
|
17
19
|
React.useEffect(() => {
|
|
18
20
|
if (defaultId == null) {
|
|
19
21
|
// Fallback to this default id when possible.
|
|
20
|
-
// Use the
|
|
22
|
+
// Use the incrementing value for client-side rendering only.
|
|
21
23
|
// We can't use it server-side.
|
|
22
|
-
|
|
24
|
+
// If you want to use random values please consider the Birthday Problem: https://en.wikipedia.org/wiki/Birthday_problem
|
|
25
|
+
globalId += 1;
|
|
26
|
+
setDefaultId(`mui-${globalId}`);
|
|
23
27
|
}
|
|
24
28
|
}, [defaultId]);
|
|
25
29
|
return id;
|
|
30
|
+
} // eslint-disable-next-line no-useless-concat -- Workaround for https://github.com/webpack/webpack/issues/14814
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
const maybeReactUseId = React['useId' + ''];
|
|
34
|
+
/**
|
|
35
|
+
*
|
|
36
|
+
* @example <div id={useId()} />
|
|
37
|
+
* @param idOverride
|
|
38
|
+
* @returns {string}
|
|
39
|
+
*/
|
|
40
|
+
|
|
41
|
+
function useId(idOverride) {
|
|
42
|
+
if (maybeReactUseId !== undefined) {
|
|
43
|
+
const reactId = maybeReactUseId();
|
|
44
|
+
return idOverride != null ? idOverride : reactId;
|
|
45
|
+
} // eslint-disable-next-line react-hooks/rules-of-hooks -- `React.useId` is invariant at runtime.
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
return useGlobalId(idOverride);
|
|
26
49
|
}
|
package/useIsFocusVisible.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
}
|
|
2
|
+
export declare function teardown(doc: Document): void;
|
|
3
|
+
export interface UseIsFocusVisibleResult {
|
|
4
|
+
isFocusVisibleRef: React.MutableRefObject<boolean>;
|
|
5
|
+
onBlur: (event: React.FocusEvent<any>) => void;
|
|
6
|
+
onFocus: (event: React.FocusEvent<any>) => void;
|
|
7
|
+
ref: React.Ref<unknown>;
|
|
8
|
+
}
|
|
9
|
+
export default function useIsFocusVisible(): UseIsFocusVisibleResult;
|
package/useIsFocusVisible.js
CHANGED
|
@@ -15,7 +15,7 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
|
|
|
15
15
|
// based on https://github.com/WICG/focus-visible/blob/v4.1.5/src/focus-visible.js
|
|
16
16
|
let hadKeyboardEvent = true;
|
|
17
17
|
let hadFocusVisibleRecently = false;
|
|
18
|
-
let hadFocusVisibleRecentlyTimeout
|
|
18
|
+
let hadFocusVisibleRecentlyTimeout;
|
|
19
19
|
const inputTypesWhitelist = {
|
|
20
20
|
text: true,
|
|
21
21
|
search: true,
|