@mui/utils 6.0.0-beta.4 → 6.0.0-beta.4-dev.20240802-144226-85a3b55d22
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/esm/getReactNodeRef/getReactNodeRef.js +21 -0
- package/esm/getReactNodeRef/index.js +1 -0
- package/esm/index.js +1 -0
- package/getReactNodeRef/getReactNodeRef.d.ts +9 -0
- package/getReactNodeRef/getReactNodeRef.js +28 -0
- package/getReactNodeRef/index.d.ts +1 -0
- package/getReactNodeRef/index.js +13 -0
- package/getReactNodeRef/package.json +6 -0
- package/index.d.ts +1 -0
- package/index.js +10 -2
- package/modern/getReactNodeRef/getReactNodeRef.js +21 -0
- package/modern/getReactNodeRef/index.js +1 -0
- package/modern/index.js +2 -1
- package/package.json +1 -1
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Returns the ref of a React node handling differences between React 19 and older versions.
|
|
5
|
+
* It will return null if the node is not a valid React element.
|
|
6
|
+
*
|
|
7
|
+
* @param element React.ReactNode
|
|
8
|
+
* @returns React.Ref<any> | null
|
|
9
|
+
*/
|
|
10
|
+
export default function getReactNodeRef(element) {
|
|
11
|
+
if (!element || ! /*#__PURE__*/React.isValidElement(element)) {
|
|
12
|
+
return null;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// 'ref' is passed as prop in React 19, whereas 'ref' is directly attached to children in older versions
|
|
16
|
+
return element.props.propertyIsEnumerable('ref') ? element.props.ref :
|
|
17
|
+
// @ts-expect-error element.ref is not included in the ReactElement type
|
|
18
|
+
// We cannot check for it, but isValidElement is true at this point
|
|
19
|
+
// https://github.com/DefinitelyTyped/DefinitelyTyped/discussions/70189
|
|
20
|
+
element.ref;
|
|
21
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from './getReactNodeRef';
|
package/esm/index.js
CHANGED
|
@@ -44,4 +44,5 @@ export { default as clamp } from './clamp';
|
|
|
44
44
|
export { default as unstable_useSlotProps } from './useSlotProps';
|
|
45
45
|
export { default as unstable_resolveComponentProps } from './resolveComponentProps';
|
|
46
46
|
export { default as unstable_extractEventHandlers } from './extractEventHandlers';
|
|
47
|
+
export { default as unstable_getReactNodeRef } from './getReactNodeRef';
|
|
47
48
|
export * from './types';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* Returns the ref of a React node handling differences between React 19 and older versions.
|
|
4
|
+
* It will return null if the node is not a valid React element.
|
|
5
|
+
*
|
|
6
|
+
* @param element React.ReactNode
|
|
7
|
+
* @returns React.Ref<any> | null
|
|
8
|
+
*/
|
|
9
|
+
export default function getReactNodeRef(element: React.ReactNode): React.Ref<any> | null;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = getReactNodeRef;
|
|
7
|
+
var React = _interopRequireWildcard(require("react"));
|
|
8
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
9
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
10
|
+
/**
|
|
11
|
+
* Returns the ref of a React node handling differences between React 19 and older versions.
|
|
12
|
+
* It will return null if the node is not a valid React element.
|
|
13
|
+
*
|
|
14
|
+
* @param element React.ReactNode
|
|
15
|
+
* @returns React.Ref<any> | null
|
|
16
|
+
*/
|
|
17
|
+
function getReactNodeRef(element) {
|
|
18
|
+
if (!element || ! /*#__PURE__*/React.isValidElement(element)) {
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// 'ref' is passed as prop in React 19, whereas 'ref' is directly attached to children in older versions
|
|
23
|
+
return element.props.propertyIsEnumerable('ref') ? element.props.ref :
|
|
24
|
+
// @ts-expect-error element.ref is not included in the ReactElement type
|
|
25
|
+
// We cannot check for it, but isValidElement is true at this point
|
|
26
|
+
// https://github.com/DefinitelyTyped/DefinitelyTyped/discussions/70189
|
|
27
|
+
element.ref;
|
|
28
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from './getReactNodeRef';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
Object.defineProperty(exports, "default", {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: function () {
|
|
10
|
+
return _getReactNodeRef.default;
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
var _getReactNodeRef = _interopRequireDefault(require("./getReactNodeRef"));
|
package/index.d.ts
CHANGED
|
@@ -45,4 +45,5 @@ export { default as unstable_useSlotProps } from './useSlotProps';
|
|
|
45
45
|
export type { UseSlotPropsParameters, UseSlotPropsResult } from './useSlotProps';
|
|
46
46
|
export { default as unstable_resolveComponentProps } from './resolveComponentProps';
|
|
47
47
|
export { default as unstable_extractEventHandlers } from './extractEventHandlers';
|
|
48
|
+
export { default as unstable_getReactNodeRef } from './getReactNodeRef';
|
|
48
49
|
export * from './types';
|
package/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @mui/utils v6.0.0-beta.4
|
|
2
|
+
* @mui/utils v6.0.0-beta.4-dev.20240802-144226-85a3b55d22
|
|
3
3
|
*
|
|
4
4
|
* @license MIT
|
|
5
5
|
* This source code is licensed under the MIT license found in the
|
|
@@ -57,7 +57,8 @@ var _exportNames = {
|
|
|
57
57
|
clamp: true,
|
|
58
58
|
unstable_useSlotProps: true,
|
|
59
59
|
unstable_resolveComponentProps: true,
|
|
60
|
-
unstable_extractEventHandlers: true
|
|
60
|
+
unstable_extractEventHandlers: true,
|
|
61
|
+
unstable_getReactNodeRef: true
|
|
61
62
|
};
|
|
62
63
|
Object.defineProperty(exports, "HTMLElementType", {
|
|
63
64
|
enumerable: true,
|
|
@@ -209,6 +210,12 @@ Object.defineProperty(exports, "unstable_generateUtilityClasses", {
|
|
|
209
210
|
return _generateUtilityClasses.default;
|
|
210
211
|
}
|
|
211
212
|
});
|
|
213
|
+
Object.defineProperty(exports, "unstable_getReactNodeRef", {
|
|
214
|
+
enumerable: true,
|
|
215
|
+
get: function () {
|
|
216
|
+
return _getReactNodeRef.default;
|
|
217
|
+
}
|
|
218
|
+
});
|
|
212
219
|
Object.defineProperty(exports, "unstable_getScrollbarSize", {
|
|
213
220
|
enumerable: true,
|
|
214
221
|
get: function () {
|
|
@@ -389,6 +396,7 @@ var _clamp = _interopRequireDefault(require("./clamp"));
|
|
|
389
396
|
var _useSlotProps = _interopRequireDefault(require("./useSlotProps"));
|
|
390
397
|
var _resolveComponentProps = _interopRequireDefault(require("./resolveComponentProps"));
|
|
391
398
|
var _extractEventHandlers = _interopRequireDefault(require("./extractEventHandlers"));
|
|
399
|
+
var _getReactNodeRef = _interopRequireDefault(require("./getReactNodeRef"));
|
|
392
400
|
var _types = require("./types");
|
|
393
401
|
Object.keys(_types).forEach(function (key) {
|
|
394
402
|
if (key === "default" || key === "__esModule") return;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Returns the ref of a React node handling differences between React 19 and older versions.
|
|
5
|
+
* It will return null if the node is not a valid React element.
|
|
6
|
+
*
|
|
7
|
+
* @param element React.ReactNode
|
|
8
|
+
* @returns React.Ref<any> | null
|
|
9
|
+
*/
|
|
10
|
+
export default function getReactNodeRef(element) {
|
|
11
|
+
if (!element || ! /*#__PURE__*/React.isValidElement(element)) {
|
|
12
|
+
return null;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// 'ref' is passed as prop in React 19, whereas 'ref' is directly attached to children in older versions
|
|
16
|
+
return element.props.propertyIsEnumerable('ref') ? element.props.ref :
|
|
17
|
+
// @ts-expect-error element.ref is not included in the ReactElement type
|
|
18
|
+
// We cannot check for it, but isValidElement is true at this point
|
|
19
|
+
// https://github.com/DefinitelyTyped/DefinitelyTyped/discussions/70189
|
|
20
|
+
element.ref;
|
|
21
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from './getReactNodeRef';
|
package/modern/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @mui/utils v6.0.0-beta.4
|
|
2
|
+
* @mui/utils v6.0.0-beta.4-dev.20240802-144226-85a3b55d22
|
|
3
3
|
*
|
|
4
4
|
* @license MIT
|
|
5
5
|
* This source code is licensed under the MIT license found in the
|
|
@@ -51,4 +51,5 @@ export { default as clamp } from './clamp';
|
|
|
51
51
|
export { default as unstable_useSlotProps } from './useSlotProps';
|
|
52
52
|
export { default as unstable_resolveComponentProps } from './resolveComponentProps';
|
|
53
53
|
export { default as unstable_extractEventHandlers } from './extractEventHandlers';
|
|
54
|
+
export { default as unstable_getReactNodeRef } from './getReactNodeRef';
|
|
54
55
|
export * from './types';
|