1 | "use strict";
|
2 |
|
3 | var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
4 | Object.defineProperty(exports, "__esModule", {
|
5 | value: true
|
6 | });
|
7 | exports.default = void 0;
|
8 | var React = _interopRequireWildcard(require("react"));
|
9 | var ReactDOM = _interopRequireWildcard(require("react-dom"));
|
10 | var _propTypes = _interopRequireDefault(require("prop-types"));
|
11 | var _utils = require("@mui/utils");
|
12 | var _jsxRuntime = require("react/jsx-runtime");
|
13 | 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); }
|
14 | 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; }
|
15 | function getContainer(container) {
|
16 | return typeof container === 'function' ? container() : container;
|
17 | }
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 | const Portal = React.forwardRef(function Portal(props, forwardedRef) {
|
32 | const {
|
33 | children,
|
34 | container,
|
35 | disablePortal = false
|
36 | } = props;
|
37 | const [mountNode, setMountNode] = React.useState(null);
|
38 |
|
39 | const handleRef = (0, _utils.unstable_useForkRef)( React.isValidElement(children) ? children.ref : null, forwardedRef);
|
40 | (0, _utils.unstable_useEnhancedEffect)(() => {
|
41 | if (!disablePortal) {
|
42 | setMountNode(getContainer(container) || document.body);
|
43 | }
|
44 | }, [container, disablePortal]);
|
45 | (0, _utils.unstable_useEnhancedEffect)(() => {
|
46 | if (mountNode && !disablePortal) {
|
47 | (0, _utils.unstable_setRef)(forwardedRef, mountNode);
|
48 | return () => {
|
49 | (0, _utils.unstable_setRef)(forwardedRef, null);
|
50 | };
|
51 | }
|
52 | return undefined;
|
53 | }, [forwardedRef, mountNode, disablePortal]);
|
54 | if (disablePortal) {
|
55 | if ( React.isValidElement(children)) {
|
56 | const newProps = {
|
57 | ref: handleRef
|
58 | };
|
59 | return React.cloneElement(children, newProps);
|
60 | }
|
61 | return (0, _jsxRuntime.jsx)(React.Fragment, {
|
62 | children: children
|
63 | });
|
64 | }
|
65 | return (0, _jsxRuntime.jsx)(React.Fragment, {
|
66 | children: mountNode ? ReactDOM.createPortal(children, mountNode) : mountNode
|
67 | });
|
68 | });
|
69 | process.env.NODE_ENV !== "production" ? Portal.propTypes = {
|
70 |
|
71 |
|
72 |
|
73 |
|
74 | |
75 |
|
76 |
|
77 | children: _propTypes.default.node,
|
78 | |
79 |
|
80 |
|
81 |
|
82 |
|
83 |
|
84 |
|
85 | container: _propTypes.default .oneOfType([_utils.HTMLElementType, _propTypes.default.func]),
|
86 | |
87 |
|
88 |
|
89 |
|
90 | disablePortal: _propTypes.default.bool
|
91 | } : void 0;
|
92 | if (process.env.NODE_ENV !== 'production') {
|
93 |
|
94 | Portal['propTypes' + ''] = (0, _utils.exactProp)(Portal.propTypes);
|
95 | }
|
96 | var _default = Portal;
|
97 | exports.default = _default; |
\ | No newline at end of file |