1 line
15 KiB
JSON
1 line
15 KiB
JSON
|
{"ast":null,"code":"import _objectSpread from \"@babel/runtime/helpers/esm/objectSpread2\";\nimport _slicedToArray from \"@babel/runtime/helpers/esm/slicedToArray\";\nimport Portal from '@rc-component/portal';\nimport useLayoutEffect from \"rc-util/es/hooks/useLayoutEffect\";\nimport * as React from 'react';\nimport { RefContext } from \"./context\";\nimport DrawerPopup from \"./DrawerPopup\";\nimport { warnCheck } from \"./util\";\nvar Drawer = function Drawer(props) {\n var _props$open = props.open,\n open = _props$open === void 0 ? false : _props$open,\n _props$prefixCls = props.prefixCls,\n prefixCls = _props$prefixCls === void 0 ? 'rc-drawer' : _props$prefixCls,\n _props$placement = props.placement,\n placement = _props$placement === void 0 ? 'right' : _props$placement,\n _props$autoFocus = props.autoFocus,\n autoFocus = _props$autoFocus === void 0 ? true : _props$autoFocus,\n _props$keyboard = props.keyboard,\n keyboard = _props$keyboard === void 0 ? true : _props$keyboard,\n _props$width = props.width,\n width = _props$width === void 0 ? 378 : _props$width,\n _props$mask = props.mask,\n mask = _props$mask === void 0 ? true : _props$mask,\n _props$maskClosable = props.maskClosable,\n maskClosable = _props$maskClosable === void 0 ? true : _props$maskClosable,\n getContainer = props.getContainer,\n forceRender = props.forceRender,\n afterOpenChange = props.afterOpenChange,\n destroyOnClose = props.destroyOnClose,\n onMouseEnter = props.onMouseEnter,\n onMouseOver = props.onMouseOver,\n onMouseLeave = props.onMouseLeave,\n onClick = props.onClick,\n onKeyDown = props.onKeyDown,\n onKeyUp = props.onKeyUp,\n panelRef = props.panelRef;\n var _React$useState = React.useState(false),\n _React$useState2 = _slicedToArray(_React$useState, 2),\n animatedVisible = _React$useState2[0],\n setAnimatedVisible = _React$useState2[1];\n\n // ============================= Warn =============================\n if (process.env.NODE_ENV !== 'production') {\n warnCheck(props);\n }\n\n // ============================= Open =============================\n var _React$useState3 = React.useState(false),\n _React$useState4 = _slicedToArray(_React$useState3, 2),\n mounted = _React$useState4[0],\n setMounted = _React$useState4[1];\n useLayoutEffect(function () {\n setMounted(true);\n }, []);\n var mergedOpen = mounted ? open : false;\n\n // ============================ Focus =============================\n var popupRef = React.useRef();\n var lastActiveRef = React.useRef();\n useLayoutEffect(function () {\n if (mergedOpen) {\n lastActiveRef.current = document.activeElement;\n }\n }, [mergedOpen]);\n\n // ============================= Open =============================\n var internalAfterOpenChange = function internalAfterOpenChange(nextVisible) {\n var _popupRef$current;\n setAnimatedVisible(nextVisible);\n afterOpenChange === null || afterOpenChange === void 0 || afterOpenChange(nextVisible);\n if (!nextVisible && lastActiveRef.current && !((_popupRef$current = popupRef.current) !== null && _popupRef$current !== void 0 && _popupRef$current.contains(lastActiveRef.current))) {\n var _lastActiveRef$curren;\n (_lastActiveRef$curren = lastActiveRef.current) === null || _lastActiveRef$curren === void 0 || _lastActiveRef$curren.focus({\n preventScroll: true\n });\n }\n };\n\n // =========================== Context ============================\n var refContext = React.useMemo(function () {\n return {\n panel: panelRef\n };\n }, [panelRef]);\n\n // ============================ Render ============================\n if (!forceRender && !animatedVisible && !mergedOpen && destroyOnClose) {\n return null;\n }\n var eventHandlers = {\n onMouseEnter: onMouseEnter,\n onMouseOver: onMouseOver,\n onMouseLeave: onMouseLeave,\n onClick: onClick,\n onKeyDown: onKeyDown,\n onKeyUp: onKeyUp\n };\n var drawerPopupProps = _objectSpread(_objectSpread({}, props), {}, {
|