PromoCursed/node_modules/.cache/babel-loader/e3ce20be236e0eadd6f754a0887d0059066d02076c73750334c761a380639bd4.json

1 line
15 KiB
JSON
Raw Normal View History

2024-08-20 23:25:37 +04:00
{"ast":null,"code":"import _defineProperty from \"@babel/runtime/helpers/esm/defineProperty\";\nimport _toConsumableArray from \"@babel/runtime/helpers/esm/toConsumableArray\";\nimport _slicedToArray from \"@babel/runtime/helpers/esm/slicedToArray\";\nimport classNames from 'classnames';\nimport useLayoutEffect from \"rc-util/es/hooks/useLayoutEffect\";\nimport * as React from 'react';\nimport { usePanelContext } from \"../../context\";\nimport useScrollTo from \"./useScrollTo\";\nvar SCROLL_DELAY = 300;\nexport default function TimeColumn(props) {\n var units = props.units,\n value = props.value,\n optionalValue = props.optionalValue,\n type = props.type,\n onChange = props.onChange,\n onHover = props.onHover,\n onDblClick = props.onDblClick,\n changeOnScroll = props.changeOnScroll;\n var _usePanelContext = usePanelContext(),\n prefixCls = _usePanelContext.prefixCls,\n cellRender = _usePanelContext.cellRender,\n now = _usePanelContext.now,\n locale = _usePanelContext.locale;\n var panelPrefixCls = \"\".concat(prefixCls, \"-time-panel\");\n var cellPrefixCls = \"\".concat(prefixCls, \"-time-panel-cell\");\n\n // ========================== Refs ==========================\n var ulRef = React.useRef(null);\n\n // ========================= Scroll =========================\n var checkDelayRef = React.useRef();\n var clearDelayCheck = function clearDelayCheck() {\n clearTimeout(checkDelayRef.current);\n };\n\n // ========================== Sync ==========================\n var _useScrollTo = useScrollTo(ulRef, value !== null && value !== void 0 ? value : optionalValue),\n _useScrollTo2 = _slicedToArray(_useScrollTo, 3),\n syncScroll = _useScrollTo2[0],\n stopScroll = _useScrollTo2[1],\n isScrolling = _useScrollTo2[2];\n\n // Effect sync value scroll\n useLayoutEffect(function () {\n syncScroll();\n clearDelayCheck();\n return function () {\n stopScroll();\n clearDelayCheck();\n };\n }, [value, optionalValue, units]);\n\n // ========================= Change =========================\n // Scroll event if sync onScroll\n var onInternalScroll = function onInternalScroll(event) {\n clearDelayCheck();\n var target = event.target;\n if (!isScrolling() && changeOnScroll) {\n checkDelayRef.current = setTimeout(function () {\n var ul = ulRef.current;\n var firstLiTop = ul.querySelector(\"li\").offsetTop;\n var liList = Array.from(ul.querySelectorAll(\"li\"));\n var liTopList = liList.map(function (li) {\n return li.offsetTop - firstLiTop;\n });\n var liDistList = liTopList.map(function (top, index) {\n if (units[index].disabled) {\n return Number.MAX_SAFE_INTEGER;\n }\n return Math.abs(top - target.scrollTop);\n });\n\n // Find min distance index\n var minDist = Math.min.apply(Math, _toConsumableArray(liDistList));\n var minDistIndex = liDistList.findIndex(function (dist) {\n return dist === minDist;\n });\n var targetUnit = units[minDistIndex];\n if (targetUnit && !targetUnit.disabled) {\n onChange(targetUnit.value);\n }\n }, SCROLL_DELAY);\n }\n };\n\n // ========================= Render =========================\n var columnPrefixCls = \"\".concat(panelPrefixCls, \"-column\");\n return /*#__PURE__*/React.createElement(\"ul\", {\n className: columnPrefixCls,\n ref: ulRef,\n \"data-type\": type,\n onScroll: onInternalScroll\n }, units.map(function (_ref) {\n var label = _ref.label,\n unitValue = _ref.value,\n disabled = _ref.disabled;\n var inner = /*#__PURE__*/React.createElement(\"div\", {\n className: \"\".concat(cellPrefixCls, \"-inner\")\n }, label);\n return /*#__PURE__*/React.createElement(\"li\", {\n key: unitValue,\n className: classNames(cellPrefixCls, _defineProperty(_defineProperty({}, \"\".concat(cellPrefixCls, \"-selected\"), value === unitValue), \"\".concat(cellPrefixCls, \"-disabled\"), disabled))