1 line
8.8 KiB
JSON
1 line
8.8 KiB
JSON
|
{"ast":null,"code":"import raf from \"rc-util/es/raf\";\nimport { useRef } from 'react';\nimport isFF from \"../utils/isFirefox\";\nimport useOriginScroll from \"./useOriginScroll\";\nexport default function useFrameWheel(inVirtual, isScrollAtTop, isScrollAtBottom, isScrollAtLeft, isScrollAtRight, horizontalScroll,\n/***\n * Return `true` when you need to prevent default event\n */\nonWheelDelta) {\n var offsetRef = useRef(0);\n var nextFrameRef = useRef(null);\n\n // Firefox patch\n var wheelValueRef = useRef(null);\n var isMouseScrollRef = useRef(false);\n\n // Scroll status sync\n var originScroll = useOriginScroll(isScrollAtTop, isScrollAtBottom, isScrollAtLeft, isScrollAtRight);\n function onWheelY(event, deltaY) {\n raf.cancel(nextFrameRef.current);\n offsetRef.current += deltaY;\n wheelValueRef.current = deltaY;\n\n // Do nothing when scroll at the edge, Skip check when is in scroll\n if (originScroll(false, deltaY)) return;\n\n // Proxy of scroll events\n if (!isFF) {\n event.preventDefault();\n }\n nextFrameRef.current = raf(function () {\n // Patch a multiple for Firefox to fix wheel number too small\n // ref: https://github.com/ant-design/ant-design/issues/26372#issuecomment-679460266\n var patchMultiple = isMouseScrollRef.current ? 10 : 1;\n onWheelDelta(offsetRef.current * patchMultiple);\n offsetRef.current = 0;\n });\n }\n function onWheelX(event, deltaX) {\n onWheelDelta(deltaX, true);\n if (!isFF) {\n event.preventDefault();\n }\n }\n\n // Check for which direction does wheel do. `sx` means `shift + wheel`\n var wheelDirectionRef = useRef(null);\n var wheelDirectionCleanRef = useRef(null);\n function onWheel(event) {\n if (!inVirtual) return;\n\n // Wait for 2 frame to clean direction\n raf.cancel(wheelDirectionCleanRef.current);\n wheelDirectionCleanRef.current = raf(function () {\n wheelDirectionRef.current = null;\n }, 2);\n var deltaX = event.deltaX,\n deltaY = event.deltaY,\n shiftKey = event.shiftKey;\n var mergedDeltaX = deltaX;\n var mergedDeltaY = deltaY;\n if (wheelDirectionRef.current === 'sx' || !wheelDirectionRef.current && (shiftKey || false) && deltaY && !deltaX) {\n mergedDeltaX = deltaY;\n mergedDeltaY = 0;\n wheelDirectionRef.current = 'sx';\n }\n var absX = Math.abs(mergedDeltaX);\n var absY = Math.abs(mergedDeltaY);\n if (wheelDirectionRef.current === null) {\n wheelDirectionRef.current = horizontalScroll && absX > absY ? 'x' : 'y';\n }\n if (wheelDirectionRef.current === 'y') {\n onWheelY(event, mergedDeltaY);\n } else {\n onWheelX(event, mergedDeltaX);\n }\n }\n\n // A patch for firefox\n function onFireFoxScroll(event) {\n if (!inVirtual) return;\n isMouseScrollRef.current = event.detail === wheelValueRef.current;\n }\n return [onWheel, onFireFoxScroll];\n}","map":{"version":3,"names":["raf","useRef","isFF","useOriginScroll","useFrameWheel","inVirtual","isScrollAtTop","isScrollAtBottom","isScrollAtLeft","isScrollAtRight","horizontalScroll","onWheelDelta","offsetRef","nextFrameRef","wheelValueRef","isMouseScrollRef","originScroll","onWheelY","event","deltaY","cancel","current","preventDefault","patchMultiple","onWheelX","deltaX","wheelDirectionRef","wheelDirectionCleanRef","onWheel","shiftKey","mergedDeltaX","mergedDeltaY","absX","Math","abs","absY","onFireFoxScroll","detail"],"sources":["C:/Users/Аришина)/Desktop/promo/node_modules/rc-virtual-list/es/hooks/useFrameWheel.js"],"sourcesContent":["import raf from \"rc-util/es/raf\";\nimport { useRef } from 'react';\nimport isFF from \"../utils/isFirefox\";\nimport useOriginScroll from \"./useOriginScroll\";\nexport default function useFrameWheel(inVirtual, isScrollAtTop, isScrollAtBottom, isScrollAtLeft, isScrollAtRight, horizontalScroll,\n/***\n * Return `true` when you need to prevent default event\n */\nonWheelDelta) {\n var offsetRef = useRef(0);\n var nextFrameRef = useRef(null);\n\n // Firefox patch\n var wheelValueRef = useR
|