7f45bd2e884eb5fe6d05419d54adb6dc.json
11 KB
{"ast":null,"code":"function _typeof(obj) {\n \"@babel/helpers - typeof\";\n\n if (typeof Symbol === \"function\" && typeof Symbol.iterator === \"symbol\") {\n _typeof = function _typeof(obj) {\n return typeof obj;\n };\n } else {\n _typeof = function _typeof(obj) {\n return obj && typeof Symbol === \"function\" && obj.constructor === Symbol && obj !== Symbol.prototype ? \"symbol\" : typeof obj;\n };\n }\n\n return _typeof(obj);\n}\n/* eslint-disable no-param-reassign */\n\n\nimport * as React from 'react';\nimport raf from \"rc-util/es/raf\";\nexport default function useScrollTo(containerRef, data, heights, itemHeight, getKey, collectHeight, syncScrollTop, triggerFlash) {\n var scrollRef = React.useRef();\n return function (arg) {\n // When not argument provided, we think dev may want to show the scrollbar\n if (arg === null || arg === undefined) {\n triggerFlash();\n return;\n } // Normal scroll logic\n\n\n raf.cancel(scrollRef.current);\n\n if (typeof arg === 'number') {\n syncScrollTop(arg);\n } else if (arg && _typeof(arg) === 'object') {\n var index;\n var align = arg.align;\n\n if ('index' in arg) {\n index = arg.index;\n } else {\n index = data.findIndex(function (item) {\n return getKey(item) === arg.key;\n });\n }\n\n var _arg$offset = arg.offset,\n offset = _arg$offset === void 0 ? 0 : _arg$offset; // We will retry 3 times in case dynamic height shaking\n\n var syncScroll = function syncScroll(times, targetAlign) {\n if (times < 0 || !containerRef.current) return;\n var height = containerRef.current.clientHeight;\n var needCollectHeight = false;\n var newTargetAlign = targetAlign; // Go to next frame if height not exist\n\n if (height) {\n var mergedAlign = targetAlign || align; // Get top & bottom\n\n var stackTop = 0;\n var itemTop = 0;\n var itemBottom = 0;\n var maxLen = Math.min(data.length, index);\n\n for (var i = 0; i <= maxLen; i += 1) {\n var key = getKey(data[i]);\n itemTop = stackTop;\n var cacheHeight = heights.get(key);\n itemBottom = itemTop + (cacheHeight === undefined ? itemHeight : cacheHeight);\n stackTop = itemBottom;\n\n if (i === index && cacheHeight === undefined) {\n needCollectHeight = true;\n }\n } // Scroll to\n\n\n var targetTop = null;\n\n switch (mergedAlign) {\n case 'top':\n targetTop = itemTop - offset;\n break;\n\n case 'bottom':\n targetTop = itemBottom - height + offset;\n break;\n\n default:\n {\n var scrollTop = containerRef.current.scrollTop;\n var scrollBottom = scrollTop + height;\n\n if (itemTop < scrollTop) {\n newTargetAlign = 'top';\n } else if (itemBottom > scrollBottom) {\n newTargetAlign = 'bottom';\n }\n }\n }\n\n if (targetTop !== null && targetTop !== containerRef.current.scrollTop) {\n syncScrollTop(targetTop);\n }\n } // We will retry since element may not sync height as it described\n\n\n scrollRef.current = raf(function () {\n if (needCollectHeight) {\n collectHeight();\n }\n\n syncScroll(times - 1, newTargetAlign);\n });\n };\n\n syncScroll(3);\n }\n };\n}","map":{"version":3,"sources":["C:/Users/kkwan_000/Desktop/git/2017110269/minsung/node_modules/rc-virtual-list/es/hooks/useScrollTo.js"],"names":["_typeof","obj","Symbol","iterator","constructor","prototype","React","raf","useScrollTo","containerRef","data","heights","itemHeight","getKey","collectHeight","syncScrollTop","triggerFlash","scrollRef","useRef","arg","undefined","cancel","current","index","align","findIndex","item","key","_arg$offset","offset","syncScroll","times","targetAlign","height","clientHeight","needCollectHeight","newTargetAlign","mergedAlign","stackTop","itemTop","itemBottom","maxLen","Math","min","length","i","cacheHeight","get","targetTop","scrollTop","scrollBottom"],"mappings":"AAAA,SAASA,OAAT,CAAiBC,GAAjB,EAAsB;AAAE;;AAA2B,MAAI,OAAOC,MAAP,KAAkB,UAAlB,IAAgC,OAAOA,MAAM,CAACC,QAAd,KAA2B,QAA/D,EAAyE;AAAEH,IAAAA,OAAO,GAAG,SAASA,OAAT,CAAiBC,GAAjB,EAAsB;AAAE,aAAO,OAAOA,GAAd;AAAoB,KAAtD;AAAyD,GAApI,MAA0I;AAAED,IAAAA,OAAO,GAAG,SAASA,OAAT,CAAiBC,GAAjB,EAAsB;AAAE,aAAOA,GAAG,IAAI,OAAOC,MAAP,KAAkB,UAAzB,IAAuCD,GAAG,CAACG,WAA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ACE,iBAAK,KAAL;AACEW,cAAAA,SAAS,GAAGT,OAAO,GAAGV,MAAtB;AACA;;AAEF,iBAAK,QAAL;AACEmB,cAAAA,SAAS,GAAGR,UAAU,GAAGP,MAAb,GAAsBJ,MAAlC;AACA;;AAEF;AACE;AACE,oBAAIoB,SAAS,GAAGxC,YAAY,CAACa,OAAb,CAAqB2B,SAArC;AACA,oBAAIC,YAAY,GAAGD,SAAS,GAAGhB,MAA/B;;AAEA,oBAAIM,OAAO,GAAGU,SAAd,EAAyB;AACvBb,kBAAAA,cAAc,GAAG,KAAjB;AACD,iBAFD,MAEO,IAAII,UAAU,GAAGU,YAAjB,EAA+B;AACpCd,kBAAAA,cAAc,GAAG,QAAjB;AACD;AACF;AAnBL;;AAsBA,cAAIY,SAAS,KAAK,IAAd,IAAsBA,SAAS,KAAKvC,YAAY,CAACa,OAAb,CAAqB2B,SAA7D,EAAwE;AACtElC,YAAAA,aAAa,CAACiC,SAAD,CAAb;AACD;AACF,SAtDsD,CAsDrD;;;AAGF/B,QAAAA,SAAS,CAACK,OAAV,GAAoBf,GAAG,CAAC,YAAY;AAClC,cAAI4B,iBAAJ,EAAuB;AACrBrB,YAAAA,aAAa;AACd;;AAEDgB,UAAAA,UAAU,CAACC,KAAK,GAAG,CAAT,EAAYK,cAAZ,CAAV;AACD,SANsB,CAAvB;AAOD,OAhED;;AAkEAN,MAAAA,UAAU,CAAC,CAAD,CAAV;AACD;AACF,GA/FD;AAgGD","sourcesContent":["function _typeof(obj) { \"@babel/helpers - typeof\"; if (typeof Symbol === \"function\" && typeof Symbol.iterator === \"symbol\") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === \"function\" && obj.constructor === Symbol && obj !== Symbol.prototype ? \"symbol\" : typeof obj; }; } return _typeof(obj); }\n\n/* eslint-disable no-param-reassign */\nimport * as React from 'react';\nimport raf from \"rc-util/es/raf\";\nexport default function useScrollTo(containerRef, data, heights, itemHeight, getKey, collectHeight, syncScrollTop, triggerFlash) {\n var scrollRef = React.useRef();\n return function (arg) {\n // When not argument provided, we think dev may want to show the scrollbar\n if (arg === null || arg === undefined) {\n triggerFlash();\n return;\n } // Normal scroll logic\n\n\n raf.cancel(scrollRef.current);\n\n if (typeof arg === 'number') {\n syncScrollTop(arg);\n } else if (arg && _typeof(arg) === 'object') {\n var index;\n var align = arg.align;\n\n if ('index' in arg) {\n index = arg.index;\n } else {\n index = data.findIndex(function (item) {\n return getKey(item) === arg.key;\n });\n }\n\n var _arg$offset = arg.offset,\n offset = _arg$offset === void 0 ? 0 : _arg$offset; // We will retry 3 times in case dynamic height shaking\n\n var syncScroll = function syncScroll(times, targetAlign) {\n if (times < 0 || !containerRef.current) return;\n var height = containerRef.current.clientHeight;\n var needCollectHeight = false;\n var newTargetAlign = targetAlign; // Go to next frame if height not exist\n\n if (height) {\n var mergedAlign = targetAlign || align; // Get top & bottom\n\n var stackTop = 0;\n var itemTop = 0;\n var itemBottom = 0;\n var maxLen = Math.min(data.length, index);\n\n for (var i = 0; i <= maxLen; i += 1) {\n var key = getKey(data[i]);\n itemTop = stackTop;\n var cacheHeight = heights.get(key);\n itemBottom = itemTop + (cacheHeight === undefined ? itemHeight : cacheHeight);\n stackTop = itemBottom;\n\n if (i === index && cacheHeight === undefined) {\n needCollectHeight = true;\n }\n } // Scroll to\n\n\n var targetTop = null;\n\n switch (mergedAlign) {\n case 'top':\n targetTop = itemTop - offset;\n break;\n\n case 'bottom':\n targetTop = itemBottom - height + offset;\n break;\n\n default:\n {\n var scrollTop = containerRef.current.scrollTop;\n var scrollBottom = scrollTop + height;\n\n if (itemTop < scrollTop) {\n newTargetAlign = 'top';\n } else if (itemBottom > scrollBottom) {\n newTargetAlign = 'bottom';\n }\n }\n }\n\n if (targetTop !== null && targetTop !== containerRef.current.scrollTop) {\n syncScrollTop(targetTop);\n }\n } // We will retry since element may not sync height as it described\n\n\n scrollRef.current = raf(function () {\n if (needCollectHeight) {\n collectHeight();\n }\n\n syncScroll(times - 1, newTargetAlign);\n });\n };\n\n syncScroll(3);\n }\n };\n}"]},"metadata":{},"sourceType":"module"}