1 line
12 KiB
JSON
1 line
12 KiB
JSON
|
{"ast":null,"code":"import _slicedToArray from \"@babel/runtime/helpers/esm/slicedToArray\";\nimport * as React from 'react';\nimport { createPortal } from 'react-dom';\nimport canUseDom from \"rc-util/es/Dom/canUseDom\";\nimport warning from \"rc-util/es/warning\";\nimport { supportRef, useComposeRef } from \"rc-util/es/ref\";\nimport OrderContext from \"./Context\";\nimport useDom from \"./useDom\";\nimport useScrollLocker from \"./useScrollLocker\";\nimport { inlineMock } from \"./mock\";\nvar getPortalContainer = function getPortalContainer(getContainer) {\n if (getContainer === false) {\n return false;\n }\n if (!canUseDom() || !getContainer) {\n return null;\n }\n if (typeof getContainer === 'string') {\n return document.querySelector(getContainer);\n }\n if (typeof getContainer === 'function') {\n return getContainer();\n }\n return getContainer;\n};\nvar Portal = /*#__PURE__*/React.forwardRef(function (props, ref) {\n var open = props.open,\n autoLock = props.autoLock,\n getContainer = props.getContainer,\n debug = props.debug,\n _props$autoDestroy = props.autoDestroy,\n autoDestroy = _props$autoDestroy === void 0 ? true : _props$autoDestroy,\n children = props.children;\n var _React$useState = React.useState(open),\n _React$useState2 = _slicedToArray(_React$useState, 2),\n shouldRender = _React$useState2[0],\n setShouldRender = _React$useState2[1];\n var mergedRender = shouldRender || open;\n\n // ========================= Warning =========================\n if (process.env.NODE_ENV !== 'production') {\n warning(canUseDom() || !open, \"Portal only work in client side. Please call 'useEffect' to show Portal instead default render in SSR.\");\n }\n\n // ====================== Should Render ======================\n React.useEffect(function () {\n if (autoDestroy || open) {\n setShouldRender(open);\n }\n }, [open, autoDestroy]);\n\n // ======================== Container ========================\n var _React$useState3 = React.useState(function () {\n return getPortalContainer(getContainer);\n }),\n _React$useState4 = _slicedToArray(_React$useState3, 2),\n innerContainer = _React$useState4[0],\n setInnerContainer = _React$useState4[1];\n React.useEffect(function () {\n var customizeContainer = getPortalContainer(getContainer);\n\n // Tell component that we check this in effect which is safe to be `null`\n setInnerContainer(customizeContainer !== null && customizeContainer !== void 0 ? customizeContainer : null);\n });\n var _useDom = useDom(mergedRender && !innerContainer, debug),\n _useDom2 = _slicedToArray(_useDom, 2),\n defaultContainer = _useDom2[0],\n queueCreate = _useDom2[1];\n var mergedContainer = innerContainer !== null && innerContainer !== void 0 ? innerContainer : defaultContainer;\n\n // ========================= Locker ==========================\n useScrollLocker(autoLock && open && canUseDom() && (mergedContainer === defaultContainer || mergedContainer === document.body));\n\n // =========================== Ref ===========================\n var childRef = null;\n if (children && supportRef(children) && ref) {\n var _ref = children;\n childRef = _ref.ref;\n }\n var mergedRef = useComposeRef(childRef, ref);\n\n // ========================= Render ==========================\n // Do not render when nothing need render\n // When innerContainer is `undefined`, it may not ready since user use ref in the same render\n if (!mergedRender || !canUseDom() || innerContainer === undefined) {\n return null;\n }\n\n // Render inline\n var renderInline = mergedContainer === false || inlineMock();\n var reffedChildren = children;\n if (ref) {\n reffedChildren = /*#__PURE__*/React.cloneElement(children, {\n ref: mergedRef\n });\n }\n return /*#__PURE__*/React.createElement(OrderContext.Provider, {\n value: queueCreate\n }, renderInline ? reffedChildren : /*#__PURE__*/createPortal(reffedChildren, mergedContainer));\n});\nif (process.env.NODE_ENV !== 'production') {\n P
|