1 line
24 KiB
JSON
1 line
24 KiB
JSON
|
{"ast":null,"code":"\"use client\";\n\nimport React from 'react';\nimport classNames from 'classnames';\nimport ResizeObserver from 'rc-resize-observer';\nimport omit from \"rc-util/es/omit\";\nimport throttleByAnimationFrame from '../_util/throttleByAnimationFrame';\nimport { ConfigContext } from '../config-provider';\nimport useStyle from './style';\nimport { getFixedBottom, getFixedTop, getTargetRect } from './utils';\nconst TRIGGER_EVENTS = ['resize', 'scroll', 'touchstart', 'touchmove', 'touchend', 'pageshow', 'load'];\nfunction getDefaultTarget() {\n return typeof window !== 'undefined' ? window : null;\n}\nconst AFFIX_STATUS_NONE = 0;\nconst AFFIX_STATUS_PREPARE = 1;\nconst Affix = /*#__PURE__*/React.forwardRef((props, ref) => {\n var _a;\n const {\n style,\n offsetTop,\n offsetBottom,\n prefixCls,\n className,\n rootClassName,\n children,\n target,\n onChange\n } = props;\n const {\n getPrefixCls,\n getTargetContainer\n } = React.useContext(ConfigContext);\n const affixPrefixCls = getPrefixCls('affix', prefixCls);\n const [lastAffix, setLastAffix] = React.useState(false);\n const [affixStyle, setAffixStyle] = React.useState();\n const [placeholderStyle, setPlaceholderStyle] = React.useState();\n const status = React.useRef(AFFIX_STATUS_NONE);\n const prevTarget = React.useRef(null);\n const prevListener = React.useRef();\n const placeholderNodeRef = React.useRef(null);\n const fixedNodeRef = React.useRef(null);\n const timer = React.useRef(null);\n const targetFunc = (_a = target !== null && target !== void 0 ? target : getTargetContainer) !== null && _a !== void 0 ? _a : getDefaultTarget;\n const internalOffsetTop = offsetBottom === undefined && offsetTop === undefined ? 0 : offsetTop;\n // =================== Measure ===================\n const measure = () => {\n if (status.current !== AFFIX_STATUS_PREPARE || !fixedNodeRef.current || !placeholderNodeRef.current || !targetFunc) {\n return;\n }\n const targetNode = targetFunc();\n if (targetNode) {\n const newState = {\n status: AFFIX_STATUS_NONE\n };\n const placeholderRect = getTargetRect(placeholderNodeRef.current);\n if (placeholderRect.top === 0 && placeholderRect.left === 0 && placeholderRect.width === 0 && placeholderRect.height === 0) {\n return;\n }\n const targetRect = getTargetRect(targetNode);\n const fixedTop = getFixedTop(placeholderRect, targetRect, internalOffsetTop);\n const fixedBottom = getFixedBottom(placeholderRect, targetRect, offsetBottom);\n if (fixedTop !== undefined) {\n newState.affixStyle = {\n position: 'fixed',\n top: fixedTop,\n width: placeholderRect.width,\n height: placeholderRect.height\n };\n newState.placeholderStyle = {\n width: placeholderRect.width,\n height: placeholderRect.height\n };\n } else if (fixedBottom !== undefined) {\n newState.affixStyle = {\n position: 'fixed',\n bottom: fixedBottom,\n width: placeholderRect.width,\n height: placeholderRect.height\n };\n newState.placeholderStyle = {\n width: placeholderRect.width,\n height: placeholderRect.height\n };\n }\n newState.lastAffix = !!newState.affixStyle;\n if (lastAffix !== newState.lastAffix) {\n onChange === null || onChange === void 0 ? void 0 : onChange(newState.lastAffix);\n }\n status.current = newState.status;\n setAffixStyle(newState.affixStyle);\n setPlaceholderStyle(newState.placeholderStyle);\n setLastAffix(newState.lastAffix);\n }\n };\n const prepareMeasure = () => {\n var _a;\n status.current = AFFIX_STATUS_PREPARE;\n measure();\n if (process.env.NODE_ENV === 'test') {\n (_a = props === null || props === void 0 ? void 0 : props.onTestUpdatePosition) === null || _a === void 0 ? void 0 : _a.call(props);\n }\n };\n const updatePosition = throttleByAnimationFrame(() => {\n prepareMeas
|