119ac7a8c343399a825cfe451a9b8609.json
20.3 KB
{"ast":null,"code":"import _defineProperty from \"@babel/runtime/helpers/esm/defineProperty\";\nimport _objectSpread from \"@babel/runtime/helpers/esm/objectSpread2\";\nimport _slicedToArray from \"@babel/runtime/helpers/esm/slicedToArray\";\nimport * as React from 'react';\nimport addEventListener from \"rc-util/es/Dom/addEventListener\";\nimport getScrollBarSize from \"rc-util/es/getScrollBarSize\";\nimport classNames from 'classnames';\nimport { getOffset } from \"rc-util/es/Dom/css\";\nimport TableContext from './context/TableContext';\nimport { useLayoutState } from './hooks/useFrame';\n\nvar StickyScrollBar = function StickyScrollBar(_ref, ref) {\n var _scrollBodyRef$curren, _scrollBodyRef$curren2;\n\n var scrollBodyRef = _ref.scrollBodyRef,\n onScroll = _ref.onScroll,\n offsetScroll = _ref.offsetScroll,\n container = _ref.container;\n\n var _React$useContext = React.useContext(TableContext),\n prefixCls = _React$useContext.prefixCls;\n\n var bodyScrollWidth = ((_scrollBodyRef$curren = scrollBodyRef.current) === null || _scrollBodyRef$curren === void 0 ? void 0 : _scrollBodyRef$curren.scrollWidth) || 0;\n var bodyWidth = ((_scrollBodyRef$curren2 = scrollBodyRef.current) === null || _scrollBodyRef$curren2 === void 0 ? void 0 : _scrollBodyRef$curren2.clientWidth) || 0;\n var scrollBarWidth = bodyScrollWidth && bodyWidth * (bodyWidth / bodyScrollWidth);\n var scrollBarRef = React.useRef();\n\n var _useLayoutState = useLayoutState({\n scrollLeft: 0,\n isHiddenScrollBar: false\n }),\n _useLayoutState2 = _slicedToArray(_useLayoutState, 2),\n scrollState = _useLayoutState2[0],\n setScrollState = _useLayoutState2[1];\n\n var refState = React.useRef({\n delta: 0,\n x: 0\n });\n\n var _React$useState = React.useState(false),\n _React$useState2 = _slicedToArray(_React$useState, 2),\n isActive = _React$useState2[0],\n setActive = _React$useState2[1];\n\n var onMouseUp = function onMouseUp() {\n setActive(false);\n };\n\n var onMouseDown = function onMouseDown(event) {\n event.persist();\n refState.current.delta = event.pageX - scrollState.scrollLeft;\n refState.current.x = 0;\n setActive(true);\n event.preventDefault();\n };\n\n var onMouseMove = function onMouseMove(event) {\n var _window; // https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/buttons\n\n\n var _ref2 = event || ((_window = window) === null || _window === void 0 ? void 0 : _window.event),\n buttons = _ref2.buttons;\n\n if (!isActive || buttons === 0) {\n // If out body mouse up, we can set isActive false when mouse move\n if (isActive) {\n setActive(false);\n }\n\n return;\n }\n\n var left = refState.current.x + event.pageX - refState.current.x - refState.current.delta;\n\n if (left <= 0) {\n left = 0;\n }\n\n if (left + scrollBarWidth >= bodyWidth) {\n left = bodyWidth - scrollBarWidth;\n }\n\n onScroll({\n scrollLeft: left / bodyWidth * (bodyScrollWidth + 2)\n });\n refState.current.x = event.pageX;\n };\n\n var onContainerScroll = function onContainerScroll() {\n var tableOffsetTop = getOffset(scrollBodyRef.current).top;\n var tableBottomOffset = tableOffsetTop + scrollBodyRef.current.offsetHeight;\n var currentClientOffset = container === window ? document.documentElement.scrollTop + window.innerHeight : getOffset(container).top + container.clientHeight;\n\n if (tableBottomOffset - getScrollBarSize() <= currentClientOffset || tableOffsetTop >= currentClientOffset - offsetScroll) {\n setScrollState(function (state) {\n return _objectSpread(_objectSpread({}, state), {}, {\n isHiddenScrollBar: true\n });\n });\n } else {\n setScrollState(function (state) {\n return _objectSpread(_objectSpread({}, state), {}, {\n isHiddenScrollBar: false\n });\n });\n }\n };\n\n var setScrollLeft = function setScrollLeft(left) {\n setScrollState(function (state) {\n return _objectSpread(_objectSpread({}, state), {}, {\n scrollLeft: left / bodyScrollWidth * bodyWidth || 0\n });\n });\n };\n\n React.useImperativeHandle(ref, function () {\n return {\n setScrollLeft: setScrollLeft\n };\n });\n React.useEffect(function () {\n var onMouseUpListener = addEventListener(document.body, 'mouseup', onMouseUp, false);\n var onMouseMoveListener = addEventListener(document.body, 'mousemove', onMouseMove, false);\n onContainerScroll();\n return function () {\n onMouseUpListener.remove();\n onMouseMoveListener.remove();\n };\n }, [scrollBarWidth, isActive]);\n React.useEffect(function () {\n var onScrollListener = addEventListener(container, 'scroll', onContainerScroll, false);\n var onResizeListener = addEventListener(window, 'resize', onContainerScroll, false);\n return function () {\n onScrollListener.remove();\n onResizeListener.remove();\n };\n }, [container]);\n React.useEffect(function () {\n if (!scrollState.isHiddenScrollBar) {\n setScrollState(function (state) {\n var _scrollBodyRef$curren3, _scrollBodyRef$curren4;\n\n return _objectSpread(_objectSpread({}, state), {}, {\n scrollLeft: scrollBodyRef.current.scrollLeft / ((_scrollBodyRef$curren3 = scrollBodyRef.current) === null || _scrollBodyRef$curren3 === void 0 ? void 0 : _scrollBodyRef$curren3.scrollWidth) * ((_scrollBodyRef$curren4 = scrollBodyRef.current) === null || _scrollBodyRef$curren4 === void 0 ? void 0 : _scrollBodyRef$curren4.clientWidth)\n });\n });\n }\n }, [scrollState.isHiddenScrollBar]);\n\n if (bodyScrollWidth <= bodyWidth || !scrollBarWidth || scrollState.isHiddenScrollBar) {\n return null;\n }\n\n return React.createElement(\"div\", {\n style: {\n height: getScrollBarSize(),\n width: bodyWidth,\n bottom: offsetScroll\n },\n className: \"\".concat(prefixCls, \"-sticky-scroll\")\n }, React.createElement(\"div\", {\n onMouseDown: onMouseDown,\n ref: scrollBarRef,\n className: classNames(\"\".concat(prefixCls, \"-sticky-scroll-bar\"), _defineProperty({}, \"\".concat(prefixCls, \"-sticky-scroll-bar-active\"), isActive)),\n style: {\n width: \"\".concat(scrollBarWidth, \"px\"),\n transform: \"translate3d(\".concat(scrollState.scrollLeft, \"px, 0, 0)\")\n }\n }));\n};\n\nexport default React.forwardRef(StickyScrollBar);","map":{"version":3,"sources":["C:/Users/kkwan_000/Desktop/git/2017110269/minsung/node_modules/rc-table/es/stickyScrollBar.js"],"names":["_defineProperty","_objectSpread","_slicedToArray","React","addEventListener","getScrollBarSize","classNames","getOffset","TableContext","useLayoutState","StickyScrollBar","_ref","ref","_scrollBodyRef$curren","_scrollBodyRef$curren2","scrollBodyRef","onScroll","offsetScroll","container","_React$useContext","useContext","prefixCls","bodyScrollWidth","current","scrollWidth","bodyWidth","clientWidth","scrollBarWidth","scrollBarRef","useRef","_useLayoutState","scrollLeft","isHiddenScrollBar","_useLayoutState2","scrollState","setScrollState","refState","delta","x","_React$useState","useState","_React$useState2","isActive","setActive","onMouseUp","onMouseDown","event","persist","pageX","preventDefault","onMouseMove","_window","_ref2","window","buttons","left","onContainerScroll","tableOffsetTop","top","tableBottomOffset","offsetHeight","currentClientOffset","document","documentElement","scrollTop","innerHeight","clientHeight","state","setScrollLeft","useImperativeHandle","useEffect","onMouseUpListener","body","onMouseMoveListener","remove","onScrollListener","onResizeListener","_scrollBodyRef$curren3","_scrollBodyRef$curren4","createElement","style","height","width","bottom","className","concat","transform","forwardRef"],"mappings":"AAAA,OAAOA,eAAP,MAA4B,2CAA5B;AACA,OAAOC,aAAP,MAA0B,0CAA1B;AACA,OAAOC,cAAP,MAA2B,0CAA3B;AACA,OAAO,KAAKC,KAAZ,MAAuB,OAAvB;AACA,OAAOC,gBAAP,MAA6B,iCAA7B;AACA,OAAOC,gBAAP,MAA6B,6BAA7B;AACA,OAAOC,UAAP,MAAuB,YAAvB;AACA,SAASC,SAAT,QAA0B,oBAA1B;AACA,OAAOC,YAAP,MAAyB,wBAAzB;AACA,SAASC,cAAT,QAA+B,kBAA/B;;AAEA,IAAIC,eAAe,GAAG,SAASA,eAAT,CAAyBC,IAAzB,EAA+BC,GAA/B,EAAoC;AACxD,MAAIC,qBAAJ,EAA2BC,sBAA3B;;AAEA,MAAIC,aAAa,GAAGJ,IAAI,CAACI,aAAzB;AAAA,MACIC,QAAQ,GAAGL,IAAI,CAACK,QADpB;AAAA,MAEIC,YAAY,GAAGN,IAAI,CAACM,YAFxB;AAAA,MAGIC,SAAS,GAAGP,IAAI,CAACO,SAHrB;;AAKA,MAAIC,iBAAiB,GAAGhB,KAAK,CAACiB,UAAN,CAAiBZ,YAAjB,CAAxB;AAAA,MACIa,S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AAAA,WAAW,EAAEA,WADe;AAE5BjC,IAAAA,GAAG,EAAEgB,YAFuB;AAG5BwD,IAAAA,SAAS,EAAE9E,UAAU,CAAC,GAAG+E,MAAH,CAAUhE,SAAV,EAAqB,oBAArB,CAAD,EAA6CrB,eAAe,CAAC,EAAD,EAAK,GAAGqF,MAAH,CAAUhE,SAAV,EAAqB,2BAArB,CAAL,EAAwDqB,QAAxD,CAA5D,CAHO;AAI5BsC,IAAAA,KAAK,EAAE;AACLE,MAAAA,KAAK,EAAE,GAAGG,MAAH,CAAU1D,cAAV,EAA0B,IAA1B,CADF;AAEL2D,MAAAA,SAAS,EAAE,eAAeD,MAAf,CAAsBnD,WAAW,CAACH,UAAlC,EAA8C,WAA9C;AAFN;AAJqB,GAA3B,CAPI,CAAP;AAgBD,CAhKD;;AAkKA,eAAe5B,KAAK,CAACoF,UAAN,CAAiB7E,eAAjB,CAAf","sourcesContent":["import _defineProperty from \"@babel/runtime/helpers/esm/defineProperty\";\nimport _objectSpread from \"@babel/runtime/helpers/esm/objectSpread2\";\nimport _slicedToArray from \"@babel/runtime/helpers/esm/slicedToArray\";\nimport * as React from 'react';\nimport addEventListener from \"rc-util/es/Dom/addEventListener\";\nimport getScrollBarSize from \"rc-util/es/getScrollBarSize\";\nimport classNames from 'classnames';\nimport { getOffset } from \"rc-util/es/Dom/css\";\nimport TableContext from './context/TableContext';\nimport { useLayoutState } from './hooks/useFrame';\n\nvar StickyScrollBar = function StickyScrollBar(_ref, ref) {\n var _scrollBodyRef$curren, _scrollBodyRef$curren2;\n\n var scrollBodyRef = _ref.scrollBodyRef,\n onScroll = _ref.onScroll,\n offsetScroll = _ref.offsetScroll,\n container = _ref.container;\n\n var _React$useContext = React.useContext(TableContext),\n prefixCls = _React$useContext.prefixCls;\n\n var bodyScrollWidth = ((_scrollBodyRef$curren = scrollBodyRef.current) === null || _scrollBodyRef$curren === void 0 ? void 0 : _scrollBodyRef$curren.scrollWidth) || 0;\n var bodyWidth = ((_scrollBodyRef$curren2 = scrollBodyRef.current) === null || _scrollBodyRef$curren2 === void 0 ? void 0 : _scrollBodyRef$curren2.clientWidth) || 0;\n var scrollBarWidth = bodyScrollWidth && bodyWidth * (bodyWidth / bodyScrollWidth);\n var scrollBarRef = React.useRef();\n\n var _useLayoutState = useLayoutState({\n scrollLeft: 0,\n isHiddenScrollBar: false\n }),\n _useLayoutState2 = _slicedToArray(_useLayoutState, 2),\n scrollState = _useLayoutState2[0],\n setScrollState = _useLayoutState2[1];\n\n var refState = React.useRef({\n delta: 0,\n x: 0\n });\n\n var _React$useState = React.useState(false),\n _React$useState2 = _slicedToArray(_React$useState, 2),\n isActive = _React$useState2[0],\n setActive = _React$useState2[1];\n\n var onMouseUp = function onMouseUp() {\n setActive(false);\n };\n\n var onMouseDown = function onMouseDown(event) {\n event.persist();\n refState.current.delta = event.pageX - scrollState.scrollLeft;\n refState.current.x = 0;\n setActive(true);\n event.preventDefault();\n };\n\n var onMouseMove = function onMouseMove(event) {\n var _window;\n\n // https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/buttons\n var _ref2 = event || ((_window = window) === null || _window === void 0 ? void 0 : _window.event),\n buttons = _ref2.buttons;\n\n if (!isActive || buttons === 0) {\n // If out body mouse up, we can set isActive false when mouse move\n if (isActive) {\n setActive(false);\n }\n\n return;\n }\n\n var left = refState.current.x + event.pageX - refState.current.x - refState.current.delta;\n\n if (left <= 0) {\n left = 0;\n }\n\n if (left + scrollBarWidth >= bodyWidth) {\n left = bodyWidth - scrollBarWidth;\n }\n\n onScroll({\n scrollLeft: left / bodyWidth * (bodyScrollWidth + 2)\n });\n refState.current.x = event.pageX;\n };\n\n var onContainerScroll = function onContainerScroll() {\n var tableOffsetTop = getOffset(scrollBodyRef.current).top;\n var tableBottomOffset = tableOffsetTop + scrollBodyRef.current.offsetHeight;\n var currentClientOffset = container === window ? document.documentElement.scrollTop + window.innerHeight : getOffset(container).top + container.clientHeight;\n\n if (tableBottomOffset - getScrollBarSize() <= currentClientOffset || tableOffsetTop >= currentClientOffset - offsetScroll) {\n setScrollState(function (state) {\n return _objectSpread(_objectSpread({}, state), {}, {\n isHiddenScrollBar: true\n });\n });\n } else {\n setScrollState(function (state) {\n return _objectSpread(_objectSpread({}, state), {}, {\n isHiddenScrollBar: false\n });\n });\n }\n };\n\n var setScrollLeft = function setScrollLeft(left) {\n setScrollState(function (state) {\n return _objectSpread(_objectSpread({}, state), {}, {\n scrollLeft: left / bodyScrollWidth * bodyWidth || 0\n });\n });\n };\n\n React.useImperativeHandle(ref, function () {\n return {\n setScrollLeft: setScrollLeft\n };\n });\n React.useEffect(function () {\n var onMouseUpListener = addEventListener(document.body, 'mouseup', onMouseUp, false);\n var onMouseMoveListener = addEventListener(document.body, 'mousemove', onMouseMove, false);\n onContainerScroll();\n return function () {\n onMouseUpListener.remove();\n onMouseMoveListener.remove();\n };\n }, [scrollBarWidth, isActive]);\n React.useEffect(function () {\n var onScrollListener = addEventListener(container, 'scroll', onContainerScroll, false);\n var onResizeListener = addEventListener(window, 'resize', onContainerScroll, false);\n return function () {\n onScrollListener.remove();\n onResizeListener.remove();\n };\n }, [container]);\n React.useEffect(function () {\n if (!scrollState.isHiddenScrollBar) {\n setScrollState(function (state) {\n var _scrollBodyRef$curren3, _scrollBodyRef$curren4;\n\n return _objectSpread(_objectSpread({}, state), {}, {\n scrollLeft: scrollBodyRef.current.scrollLeft / ((_scrollBodyRef$curren3 = scrollBodyRef.current) === null || _scrollBodyRef$curren3 === void 0 ? void 0 : _scrollBodyRef$curren3.scrollWidth) * ((_scrollBodyRef$curren4 = scrollBodyRef.current) === null || _scrollBodyRef$curren4 === void 0 ? void 0 : _scrollBodyRef$curren4.clientWidth)\n });\n });\n }\n }, [scrollState.isHiddenScrollBar]);\n\n if (bodyScrollWidth <= bodyWidth || !scrollBarWidth || scrollState.isHiddenScrollBar) {\n return null;\n }\n\n return React.createElement(\"div\", {\n style: {\n height: getScrollBarSize(),\n width: bodyWidth,\n bottom: offsetScroll\n },\n className: \"\".concat(prefixCls, \"-sticky-scroll\")\n }, React.createElement(\"div\", {\n onMouseDown: onMouseDown,\n ref: scrollBarRef,\n className: classNames(\"\".concat(prefixCls, \"-sticky-scroll-bar\"), _defineProperty({}, \"\".concat(prefixCls, \"-sticky-scroll-bar-active\"), isActive)),\n style: {\n width: \"\".concat(scrollBarWidth, \"px\"),\n transform: \"translate3d(\".concat(scrollState.scrollLeft, \"px, 0, 0)\")\n }\n }));\n};\n\nexport default React.forwardRef(StickyScrollBar);"]},"metadata":{},"sourceType":"module"}