1 line
12 KiB
JSON
1 line
12 KiB
JSON
|
{"ast":null,"code":"import _extends from \"@babel/runtime/helpers/esm/extends\";\nimport _defineProperty from \"@babel/runtime/helpers/esm/defineProperty\";\n/* eslint-disable react/no-unknown-property */\nimport * as React from 'react';\nimport classNames from 'classnames';\nimport useMobile from \"rc-util/es/hooks/useMobile\";\nimport raf from \"rc-util/es/raf\";\n\n/**\n * When click and hold on a button - the speed of auto changing the value.\n */\nvar STEP_INTERVAL = 200;\n\n/**\n * When click and hold on a button - the delay before auto changing the value.\n */\nvar STEP_DELAY = 600;\nexport default function StepHandler(_ref) {\n var prefixCls = _ref.prefixCls,\n upNode = _ref.upNode,\n downNode = _ref.downNode,\n upDisabled = _ref.upDisabled,\n downDisabled = _ref.downDisabled,\n onStep = _ref.onStep;\n // ======================== Step ========================\n var stepTimeoutRef = React.useRef();\n var frameIds = React.useRef([]);\n var onStepRef = React.useRef();\n onStepRef.current = onStep;\n var onStopStep = function onStopStep() {\n clearTimeout(stepTimeoutRef.current);\n };\n\n // We will interval update step when hold mouse down\n var onStepMouseDown = function onStepMouseDown(e, up) {\n e.preventDefault();\n onStopStep();\n onStepRef.current(up);\n\n // Loop step for interval\n function loopStep() {\n onStepRef.current(up);\n stepTimeoutRef.current = setTimeout(loopStep, STEP_INTERVAL);\n }\n\n // First time press will wait some time to trigger loop step update\n stepTimeoutRef.current = setTimeout(loopStep, STEP_DELAY);\n };\n React.useEffect(function () {\n return function () {\n onStopStep();\n frameIds.current.forEach(function (id) {\n return raf.cancel(id);\n });\n };\n }, []);\n\n // ======================= Render =======================\n var isMobile = useMobile();\n if (isMobile) {\n return null;\n }\n var handlerClassName = \"\".concat(prefixCls, \"-handler\");\n var upClassName = classNames(handlerClassName, \"\".concat(handlerClassName, \"-up\"), _defineProperty({}, \"\".concat(handlerClassName, \"-up-disabled\"), upDisabled));\n var downClassName = classNames(handlerClassName, \"\".concat(handlerClassName, \"-down\"), _defineProperty({}, \"\".concat(handlerClassName, \"-down-disabled\"), downDisabled));\n\n // fix: https://github.com/ant-design/ant-design/issues/43088\n // In Safari, When we fire onmousedown and onmouseup events in quick succession, \n // there may be a problem that the onmouseup events are executed first, \n // resulting in a disordered program execution.\n // So, we need to use requestAnimationFrame to ensure that the onmouseup event is executed after the onmousedown event.\n var safeOnStopStep = function safeOnStopStep() {\n return frameIds.current.push(raf(onStopStep));\n };\n var sharedHandlerProps = {\n unselectable: 'on',\n role: 'button',\n onMouseUp: safeOnStopStep,\n onMouseLeave: safeOnStopStep\n };\n return /*#__PURE__*/React.createElement(\"div\", {\n className: \"\".concat(handlerClassName, \"-wrap\")\n }, /*#__PURE__*/React.createElement(\"span\", _extends({}, sharedHandlerProps, {\n onMouseDown: function onMouseDown(e) {\n onStepMouseDown(e, true);\n },\n \"aria-label\": \"Increase Value\",\n \"aria-disabled\": upDisabled,\n className: upClassName\n }), upNode || /*#__PURE__*/React.createElement(\"span\", {\n unselectable: \"on\",\n className: \"\".concat(prefixCls, \"-handler-up-inner\")\n })), /*#__PURE__*/React.createElement(\"span\", _extends({}, sharedHandlerProps, {\n onMouseDown: function onMouseDown(e) {\n onStepMouseDown(e, false);\n },\n \"aria-label\": \"Decrease Value\",\n \"aria-disabled\": downDisabled,\n className: downClassName\n }), downNode || /*#__PURE__*/React.createElement(\"span\", {\n unselectable: \"on\",\n className: \"\".concat(prefixCls, \"-handler-down-inner\")\n })));\n}","map":{"version":3,"names":["_extends","_defineProperty","React","classNam
|