rc-virtual-list
Advanced tools
Comparing version 3.4.10 to 3.4.11
@@ -1,7 +0,3 @@ | ||
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; } | ||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; } | ||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty"; | ||
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2"; | ||
import * as React from 'react'; | ||
@@ -13,9 +9,8 @@ import ResizeObserver from 'rc-resize-observer'; | ||
*/ | ||
var Filler = /*#__PURE__*/React.forwardRef(function (_ref, ref) { | ||
var height = _ref.height, | ||
offset = _ref.offset, | ||
children = _ref.children, | ||
prefixCls = _ref.prefixCls, | ||
onInnerResize = _ref.onInnerResize; | ||
offset = _ref.offset, | ||
children = _ref.children, | ||
prefixCls = _ref.prefixCls, | ||
onInnerResize = _ref.onInnerResize; | ||
var outerStyle = {}; | ||
@@ -26,3 +21,2 @@ var innerStyle = { | ||
}; | ||
if (offset !== undefined) { | ||
@@ -42,3 +36,2 @@ outerStyle = { | ||
} | ||
return /*#__PURE__*/React.createElement("div", { | ||
@@ -49,3 +42,2 @@ style: outerStyle | ||
var offsetHeight = _ref2.offsetHeight; | ||
if (offsetHeight && onInnerResize) { | ||
@@ -52,0 +44,0 @@ onInnerResize(); |
@@ -0,2 +1,3 @@ | ||
/// <reference types="react" /> | ||
import type { SharedConfig, RenderFunc } from '../interface'; | ||
export default function useChildren<T>(list: T[], startIndex: number, endIndex: number, setNodeRef: (item: T, element: HTMLElement) => void, renderFunc: RenderFunc<T>, { getKey }: SharedConfig<T>): JSX.Element[]; |
@@ -7,3 +7,4 @@ import * as React from 'react'; | ||
var eleIndex = startIndex + index; | ||
var node = renderFunc(item, eleIndex, {// style: status === 'MEASURE_START' ? { visibility: 'hidden' } : {}, | ||
var node = renderFunc(item, eleIndex, { | ||
// style: status === 'MEASURE_START' ? { visibility: 'hidden' } : {}, | ||
}); | ||
@@ -10,0 +11,0 @@ var key = getKey(item); |
@@ -1,13 +0,2 @@ | ||
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); } | ||
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } | ||
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } | ||
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } | ||
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } | ||
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } | ||
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray"; | ||
import * as React from 'react'; | ||
@@ -17,14 +6,11 @@ import { findListDiffIndex } from '../utils/algorithmUtil'; | ||
var _React$useState = React.useState(data), | ||
_React$useState2 = _slicedToArray(_React$useState, 2), | ||
prevData = _React$useState2[0], | ||
setPrevData = _React$useState2[1]; | ||
_React$useState2 = _slicedToArray(_React$useState, 2), | ||
prevData = _React$useState2[0], | ||
setPrevData = _React$useState2[1]; | ||
var _React$useState3 = React.useState(null), | ||
_React$useState4 = _slicedToArray(_React$useState3, 2), | ||
diffItem = _React$useState4[0], | ||
setDiffItem = _React$useState4[1]; | ||
_React$useState4 = _slicedToArray(_React$useState3, 2), | ||
diffItem = _React$useState4[0], | ||
setDiffItem = _React$useState4[1]; | ||
React.useEffect(function () { | ||
var diff = findListDiffIndex(prevData || [], data || [], getKey); | ||
if ((diff === null || diff === void 0 ? void 0 : diff.index) !== undefined) { | ||
@@ -34,3 +20,2 @@ onDiff === null || onDiff === void 0 ? void 0 : onDiff(diff.index); | ||
} | ||
setPrevData(data); | ||
@@ -37,0 +22,0 @@ }, [data]); |
@@ -7,9 +7,8 @@ import { useRef } from 'react'; | ||
var offsetRef = useRef(0); | ||
var nextFrameRef = useRef(null); // Firefox patch | ||
var nextFrameRef = useRef(null); | ||
// Firefox patch | ||
var wheelValueRef = useRef(null); | ||
var isMouseScrollRef = useRef(false); // Scroll status sync | ||
var isMouseScrollRef = useRef(false); | ||
// Scroll status sync | ||
var originScroll = useOriginScroll(isScrollAtTop, isScrollAtBottom); | ||
function onWheel(event) { | ||
@@ -20,10 +19,9 @@ if (!inVirtual) return; | ||
offsetRef.current += deltaY; | ||
wheelValueRef.current = deltaY; // Do nothing when scroll at the edge, Skip check when is in scroll | ||
if (originScroll(deltaY)) return; // Proxy of scroll events | ||
wheelValueRef.current = deltaY; | ||
// Do nothing when scroll at the edge, Skip check when is in scroll | ||
if (originScroll(deltaY)) return; | ||
// Proxy of scroll events | ||
if (!isFF) { | ||
event.preventDefault(); | ||
} | ||
nextFrameRef.current = raf(function () { | ||
@@ -36,5 +34,4 @@ // Patch a multiple for Firefox to fix wheel number too small | ||
}); | ||
} // A patch for firefox | ||
} | ||
// A patch for firefox | ||
function onFireFoxScroll(event) { | ||
@@ -44,4 +41,3 @@ if (!inVirtual) return; | ||
} | ||
return [onWheel, onFireFoxScroll]; | ||
} |
@@ -1,13 +0,2 @@ | ||
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); } | ||
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } | ||
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } | ||
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } | ||
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } | ||
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } | ||
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray"; | ||
import * as React from 'react'; | ||
@@ -20,14 +9,11 @@ import { useRef, useEffect } from 'react'; | ||
var _React$useState = React.useState(0), | ||
_React$useState2 = _slicedToArray(_React$useState, 2), | ||
updatedMark = _React$useState2[0], | ||
setUpdatedMark = _React$useState2[1]; | ||
_React$useState2 = _slicedToArray(_React$useState, 2), | ||
updatedMark = _React$useState2[0], | ||
setUpdatedMark = _React$useState2[1]; | ||
var instanceRef = useRef(new Map()); | ||
var heightsRef = useRef(new CacheMap()); | ||
var collectRafRef = useRef(); | ||
function cancelRaf() { | ||
raf.cancel(collectRafRef.current); | ||
} | ||
function collectHeight() { | ||
@@ -40,3 +26,2 @@ cancelRaf(); | ||
var offsetHeight = htmlElement.offsetHeight; | ||
if (heightsRef.current.get(key) !== offsetHeight) { | ||
@@ -46,4 +31,4 @@ heightsRef.current.set(key, htmlElement.offsetHeight); | ||
} | ||
}); // Always trigger update mark to tell parent that should re-calculate heights when resized | ||
}); | ||
// Always trigger update mark to tell parent that should re-calculate heights when resized | ||
setUpdatedMark(function (c) { | ||
@@ -54,7 +39,5 @@ return c + 1; | ||
} | ||
function setInstanceRef(item, instance) { | ||
var key = getKey(item); | ||
var origin = instanceRef.current.get(key); | ||
if (instance) { | ||
@@ -65,5 +48,4 @@ instanceRef.current.set(key, instance); | ||
instanceRef.current.delete(key); | ||
} // Instance changed | ||
} | ||
// Instance changed | ||
if (!origin !== !instance) { | ||
@@ -77,3 +59,2 @@ if (instance) { | ||
} | ||
useEffect(function () { | ||
@@ -80,0 +61,0 @@ return cancelRaf; |
@@ -7,9 +7,7 @@ import { useRef } from 'react'; | ||
var touchYRef = useRef(0); | ||
var elementRef = useRef(null); // Smooth scroll | ||
var elementRef = useRef(null); | ||
// Smooth scroll | ||
var intervalRef = useRef(null); | ||
/* eslint-disable prefer-const */ | ||
var cleanUpEvents; | ||
var onTouchMove = function onTouchMove(e) { | ||
@@ -20,12 +18,9 @@ if (touchedRef.current) { | ||
touchYRef.current = currentY; | ||
if (callback(offsetY)) { | ||
e.preventDefault(); | ||
} // Smooth interval | ||
} | ||
// Smooth interval | ||
clearInterval(intervalRef.current); | ||
intervalRef.current = setInterval(function () { | ||
offsetY *= SMOOTH_PTG; | ||
if (!callback(offsetY, true) || Math.abs(offsetY) <= 0.1) { | ||
@@ -37,3 +32,2 @@ clearInterval(intervalRef.current); | ||
}; | ||
var onTouchEnd = function onTouchEnd() { | ||
@@ -43,6 +37,4 @@ touchedRef.current = false; | ||
}; | ||
var onTouchStart = function onTouchStart(e) { | ||
cleanUpEvents(); | ||
if (e.touches.length === 1 && !touchedRef.current) { | ||
@@ -56,3 +48,2 @@ touchedRef.current = true; | ||
}; | ||
cleanUpEvents = function cleanUpEvents() { | ||
@@ -64,3 +55,2 @@ if (elementRef.current) { | ||
}; | ||
useLayoutEffect(function () { | ||
@@ -70,6 +60,4 @@ if (inVirtual) { | ||
} | ||
return function () { | ||
var _listRef$current; | ||
(_listRef$current = listRef.current) === null || _listRef$current === void 0 ? void 0 : _listRef$current.removeEventListener('touchstart', onTouchStart); | ||
@@ -76,0 +64,0 @@ cleanUpEvents(); |
@@ -6,3 +6,2 @@ import { useRef } from 'react'; | ||
var lockTimeoutRef = useRef(null); | ||
function lockScroll() { | ||
@@ -14,5 +13,4 @@ clearTimeout(lockTimeoutRef.current); | ||
}, 50); | ||
} // Pass to ref since global add is in closure | ||
} | ||
// Pass to ref since global add is in closure | ||
var scrollPingRef = useRef({ | ||
@@ -26,6 +24,7 @@ top: isScrollAtTop, | ||
var smoothOffset = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; | ||
var originScroll = // Pass origin wheel when on the top | ||
deltaY < 0 && scrollPingRef.current.top || // Pass origin wheel when on the bottom | ||
var originScroll = | ||
// Pass origin wheel when on the top | ||
deltaY < 0 && scrollPingRef.current.top || | ||
// Pass origin wheel when on the bottom | ||
deltaY > 0 && scrollPingRef.current.bottom; | ||
if (smoothOffset && originScroll) { | ||
@@ -38,5 +37,4 @@ // No need lock anymore when it's smooth offset from touchMove interval | ||
} | ||
return !lockRef.current && originScroll; | ||
}; | ||
}); |
@@ -1,3 +0,2 @@ | ||
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); } | ||
import _typeof from "@babel/runtime/helpers/esm/typeof"; | ||
/* eslint-disable no-param-reassign */ | ||
@@ -13,7 +12,5 @@ import * as React from 'react'; | ||
return; | ||
} // Normal scroll logic | ||
} | ||
// Normal scroll logic | ||
raf.cancel(scrollRef.current); | ||
if (typeof arg === 'number') { | ||
@@ -24,3 +21,2 @@ syncScrollTop(arg); | ||
var align = arg.align; | ||
if ('index' in arg) { | ||
@@ -33,6 +29,5 @@ index = arg.index; | ||
} | ||
var _arg$offset = arg.offset, | ||
offset = _arg$offset === void 0 ? 0 : _arg$offset; // We will retry 3 times in case dynamic height shaking | ||
offset = _arg$offset === void 0 ? 0 : _arg$offset; | ||
// We will retry 3 times in case dynamic height shaking | ||
var syncScroll = function syncScroll(times, targetAlign) { | ||
@@ -42,7 +37,7 @@ if (times < 0 || !containerRef.current) return; | ||
var needCollectHeight = false; | ||
var newTargetAlign = targetAlign; // Go to next frame if height not exist | ||
var newTargetAlign = targetAlign; | ||
// Go to next frame if height not exist | ||
if (height) { | ||
var mergedAlign = targetAlign || align; // Get top & bottom | ||
var mergedAlign = targetAlign || align; | ||
// Get top & bottom | ||
var stackTop = 0; | ||
@@ -52,3 +47,2 @@ var itemTop = 0; | ||
var maxLen = Math.min(data.length, index); | ||
for (var i = 0; i <= maxLen; i += 1) { | ||
@@ -60,11 +54,8 @@ var key = getKey(data[i]); | ||
stackTop = itemBottom; | ||
if (i === index && cacheHeight === undefined) { | ||
needCollectHeight = true; | ||
} | ||
} // Scroll to | ||
} | ||
// Scroll to | ||
var targetTop = null; | ||
switch (mergedAlign) { | ||
@@ -74,7 +65,5 @@ case 'top': | ||
break; | ||
case 'bottom': | ||
targetTop = itemBottom - height + offset; | ||
break; | ||
default: | ||
@@ -84,3 +73,2 @@ { | ||
var scrollBottom = scrollTop + height; | ||
if (itemTop < scrollTop) { | ||
@@ -93,9 +81,7 @@ newTargetAlign = 'top'; | ||
} | ||
if (targetTop !== null && targetTop !== containerRef.current.scrollTop) { | ||
syncScrollTop(targetTop); | ||
} | ||
} // We will retry since element may not sync height as it described | ||
} | ||
// We will retry since element may not sync height as it described | ||
scrollRef.current = raf(function () { | ||
@@ -105,7 +91,5 @@ if (needCollectHeight) { | ||
} | ||
syncScroll(times - 1, newTargetAlign); | ||
}); | ||
}; | ||
syncScroll(3); | ||
@@ -112,0 +96,0 @@ } |
import * as React from 'react'; | ||
export function Item(_ref) { | ||
var children = _ref.children, | ||
setRef = _ref.setRef; | ||
setRef = _ref.setRef; | ||
var refFunc = React.useCallback(function (node) { | ||
@@ -6,0 +6,0 @@ setRef(node); |
316
es/List.js
@@ -0,27 +1,7 @@ | ||
import _extends from "@babel/runtime/helpers/esm/extends"; | ||
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty"; | ||
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2"; | ||
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray"; | ||
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties"; | ||
var _excluded = ["prefixCls", "className", "height", "itemHeight", "fullHeight", "style", "data", "children", "itemKey", "virtual", "component", "onScroll", "onVisibleChange"]; | ||
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } | ||
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; } | ||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; } | ||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); } | ||
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } | ||
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } | ||
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } | ||
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } | ||
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } | ||
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; } | ||
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; } | ||
import * as React from 'react'; | ||
@@ -47,33 +27,29 @@ import { useRef, useState } from 'react'; | ||
var _props$prefixCls = props.prefixCls, | ||
prefixCls = _props$prefixCls === void 0 ? 'rc-virtual-list' : _props$prefixCls, | ||
className = props.className, | ||
height = props.height, | ||
itemHeight = props.itemHeight, | ||
_props$fullHeight = props.fullHeight, | ||
fullHeight = _props$fullHeight === void 0 ? true : _props$fullHeight, | ||
style = props.style, | ||
data = props.data, | ||
children = props.children, | ||
itemKey = props.itemKey, | ||
virtual = props.virtual, | ||
_props$component = props.component, | ||
Component = _props$component === void 0 ? 'div' : _props$component, | ||
onScroll = props.onScroll, | ||
onVisibleChange = props.onVisibleChange, | ||
restProps = _objectWithoutProperties(props, _excluded); // ================================= MISC ================================= | ||
prefixCls = _props$prefixCls === void 0 ? 'rc-virtual-list' : _props$prefixCls, | ||
className = props.className, | ||
height = props.height, | ||
itemHeight = props.itemHeight, | ||
_props$fullHeight = props.fullHeight, | ||
fullHeight = _props$fullHeight === void 0 ? true : _props$fullHeight, | ||
style = props.style, | ||
data = props.data, | ||
children = props.children, | ||
itemKey = props.itemKey, | ||
virtual = props.virtual, | ||
_props$component = props.component, | ||
Component = _props$component === void 0 ? 'div' : _props$component, | ||
onScroll = props.onScroll, | ||
onVisibleChange = props.onVisibleChange, | ||
restProps = _objectWithoutProperties(props, _excluded); | ||
// ================================= MISC ================================= | ||
var useVirtual = !!(virtual !== false && height && itemHeight); | ||
var inVirtual = useVirtual && data && itemHeight * data.length > height; | ||
var _useState = useState(0), | ||
_useState2 = _slicedToArray(_useState, 2), | ||
scrollTop = _useState2[0], | ||
setScrollTop = _useState2[1]; | ||
_useState2 = _slicedToArray(_useState, 2), | ||
scrollTop = _useState2[0], | ||
setScrollTop = _useState2[1]; | ||
var _useState3 = useState(false), | ||
_useState4 = _slicedToArray(_useState3, 2), | ||
scrollMoving = _useState4[0], | ||
setScrollMoving = _useState4[1]; | ||
_useState4 = _slicedToArray(_useState3, 2), | ||
scrollMoving = _useState4[0], | ||
setScrollMoving = _useState4[1]; | ||
var mergedClassName = classNames(prefixCls, className); | ||
@@ -85,3 +61,2 @@ var mergedData = data || EMPTY_DATA; | ||
// =============================== Item Key =============================== | ||
var getKey = React.useCallback(function (item) { | ||
@@ -91,3 +66,2 @@ if (typeof itemKey === 'function') { | ||
} | ||
return item === null || item === void 0 ? void 0 : item[itemKey]; | ||
@@ -97,8 +71,7 @@ }, [itemKey]); | ||
getKey: getKey | ||
}; // ================================ Scroll ================================ | ||
}; | ||
// ================================ Scroll ================================ | ||
function syncScrollTop(newTop) { | ||
setScrollTop(function (origin) { | ||
var value; | ||
if (typeof newTop === 'function') { | ||
@@ -109,3 +82,2 @@ value = newTop(origin); | ||
} | ||
var alignedTop = keepInRange(value); | ||
@@ -115,6 +87,5 @@ componentRef.current.scrollTop = alignedTop; | ||
}); | ||
} // ================================ Legacy ================================ | ||
} | ||
// ================================ Legacy ================================ | ||
// Put ref here since the range is generate by follow | ||
var rangeRef = useRef({ | ||
@@ -125,145 +96,118 @@ start: 0, | ||
var diffItemRef = useRef(); | ||
var _useDiffItem = useDiffItem(mergedData, getKey), | ||
_useDiffItem2 = _slicedToArray(_useDiffItem, 1), | ||
diffItem = _useDiffItem2[0]; | ||
diffItemRef.current = diffItem; // ================================ Height ================================ | ||
_useDiffItem2 = _slicedToArray(_useDiffItem, 1), | ||
diffItem = _useDiffItem2[0]; | ||
diffItemRef.current = diffItem; | ||
// ================================ Height ================================ | ||
var _useHeights = useHeights(getKey, null, null), | ||
_useHeights2 = _slicedToArray(_useHeights, 4), | ||
setInstanceRef = _useHeights2[0], | ||
collectHeight = _useHeights2[1], | ||
heights = _useHeights2[2], | ||
heightUpdatedMark = _useHeights2[3]; // ========================== Visible Calculation ========================= | ||
_useHeights2 = _slicedToArray(_useHeights, 4), | ||
setInstanceRef = _useHeights2[0], | ||
collectHeight = _useHeights2[1], | ||
heights = _useHeights2[2], | ||
heightUpdatedMark = _useHeights2[3]; | ||
// ========================== Visible Calculation ========================= | ||
var _React$useMemo = React.useMemo(function () { | ||
if (!useVirtual) { | ||
if (!useVirtual) { | ||
return { | ||
scrollHeight: undefined, | ||
start: 0, | ||
end: mergedData.length - 1, | ||
offset: undefined | ||
}; | ||
} | ||
// Always use virtual scroll bar in avoid shaking | ||
if (!inVirtual) { | ||
var _fillerInnerRef$curre; | ||
return { | ||
scrollHeight: ((_fillerInnerRef$curre = fillerInnerRef.current) === null || _fillerInnerRef$curre === void 0 ? void 0 : _fillerInnerRef$curre.offsetHeight) || 0, | ||
start: 0, | ||
end: mergedData.length - 1, | ||
offset: undefined | ||
}; | ||
} | ||
var itemTop = 0; | ||
var startIndex; | ||
var startOffset; | ||
var endIndex; | ||
var dataLen = mergedData.length; | ||
for (var i = 0; i < dataLen; i += 1) { | ||
var item = mergedData[i]; | ||
var key = getKey(item); | ||
var cacheHeight = heights.get(key); | ||
var currentItemBottom = itemTop + (cacheHeight === undefined ? itemHeight : cacheHeight); | ||
// Check item top in the range | ||
if (currentItemBottom >= scrollTop && startIndex === undefined) { | ||
startIndex = i; | ||
startOffset = itemTop; | ||
} | ||
// Check item bottom in the range. We will render additional one item for motion usage | ||
if (currentItemBottom > scrollTop + height && endIndex === undefined) { | ||
endIndex = i; | ||
} | ||
itemTop = currentItemBottom; | ||
} | ||
// When scrollTop at the end but data cut to small count will reach this | ||
if (startIndex === undefined) { | ||
startIndex = 0; | ||
startOffset = 0; | ||
endIndex = Math.ceil(height / itemHeight); | ||
} | ||
if (endIndex === undefined) { | ||
endIndex = mergedData.length - 1; | ||
} | ||
// Give cache to improve scroll experience | ||
endIndex = Math.min(endIndex + 1, mergedData.length); | ||
return { | ||
scrollHeight: undefined, | ||
start: 0, | ||
end: mergedData.length - 1, | ||
offset: undefined | ||
scrollHeight: itemTop, | ||
start: startIndex, | ||
end: endIndex, | ||
offset: startOffset | ||
}; | ||
} // Always use virtual scroll bar in avoid shaking | ||
// Always use virtual scroll bar in avoid shaking | ||
if (!inVirtual) { | ||
var _fillerInnerRef$curre; | ||
return { | ||
scrollHeight: ((_fillerInnerRef$curre = fillerInnerRef.current) === null || _fillerInnerRef$curre === void 0 ? void 0 : _fillerInnerRef$curre.offsetHeight) || 0, | ||
start: 0, | ||
end: mergedData.length - 1, | ||
offset: undefined | ||
}; | ||
} | ||
var itemTop = 0; | ||
var startIndex; | ||
var startOffset; | ||
var endIndex; | ||
var dataLen = mergedData.length; | ||
for (var i = 0; i < dataLen; i += 1) { | ||
var item = mergedData[i]; | ||
var key = getKey(item); | ||
var cacheHeight = heights.get(key); | ||
var currentItemBottom = itemTop + (cacheHeight === undefined ? itemHeight : cacheHeight); // Check item top in the range | ||
// Check item top in the range | ||
if (currentItemBottom >= scrollTop && startIndex === undefined) { | ||
startIndex = i; | ||
startOffset = itemTop; | ||
} // Check item bottom in the range. We will render additional one item for motion usage | ||
// Check item bottom in the range. We will render additional one item for motion usage | ||
if (currentItemBottom > scrollTop + height && endIndex === undefined) { | ||
endIndex = i; | ||
} | ||
itemTop = currentItemBottom; | ||
} // When scrollTop at the end but data cut to small count will reach this | ||
// When scrollTop at the end but data cut to small count will reach this | ||
if (startIndex === undefined) { | ||
startIndex = 0; | ||
startOffset = 0; | ||
endIndex = Math.ceil(height / itemHeight); | ||
} | ||
if (endIndex === undefined) { | ||
endIndex = mergedData.length - 1; | ||
} // Give cache to improve scroll experience | ||
// Give cache to improve scroll experience | ||
endIndex = Math.min(endIndex + 1, mergedData.length); | ||
return { | ||
scrollHeight: itemTop, | ||
start: startIndex, | ||
end: endIndex, | ||
offset: startOffset | ||
}; | ||
}, [inVirtual, useVirtual, scrollTop, mergedData, heightUpdatedMark, height]), | ||
scrollHeight = _React$useMemo.scrollHeight, | ||
start = _React$useMemo.start, | ||
end = _React$useMemo.end, | ||
offset = _React$useMemo.offset; | ||
}, [inVirtual, useVirtual, scrollTop, mergedData, heightUpdatedMark, height]), | ||
scrollHeight = _React$useMemo.scrollHeight, | ||
start = _React$useMemo.start, | ||
end = _React$useMemo.end, | ||
offset = _React$useMemo.offset; | ||
rangeRef.current.start = start; | ||
rangeRef.current.end = end; // =============================== In Range =============================== | ||
rangeRef.current.end = end; | ||
// =============================== In Range =============================== | ||
var maxScrollHeight = scrollHeight - height; | ||
var maxScrollHeightRef = useRef(maxScrollHeight); | ||
maxScrollHeightRef.current = maxScrollHeight; | ||
function keepInRange(newScrollTop) { | ||
var newTop = newScrollTop; | ||
if (!Number.isNaN(maxScrollHeightRef.current)) { | ||
newTop = Math.min(newTop, maxScrollHeightRef.current); | ||
} | ||
newTop = Math.max(newTop, 0); | ||
return newTop; | ||
} | ||
var isScrollAtTop = scrollTop <= 0; | ||
var isScrollAtBottom = scrollTop >= maxScrollHeight; | ||
var originScroll = useOriginScroll(isScrollAtTop, isScrollAtBottom); // ================================ Scroll ================================ | ||
var originScroll = useOriginScroll(isScrollAtTop, isScrollAtBottom); | ||
// ================================ Scroll ================================ | ||
function onScrollBar(newScrollTop) { | ||
var newTop = newScrollTop; | ||
syncScrollTop(newTop); | ||
} // When data size reduce. It may trigger native scroll event back to fit scroll position | ||
} | ||
// When data size reduce. It may trigger native scroll event back to fit scroll position | ||
function onFallbackScroll(e) { | ||
var newScrollTop = e.currentTarget.scrollTop; | ||
if (newScrollTop !== scrollTop) { | ||
syncScrollTop(newScrollTop); | ||
} // Trigger origin onScroll | ||
} | ||
// Trigger origin onScroll | ||
onScroll === null || onScroll === void 0 ? void 0 : onScroll(e); | ||
} // Since this added in global,should use ref to keep update | ||
} | ||
// Since this added in global,should use ref to keep update | ||
var _useFrameWheel = useFrameWheel(useVirtual, isScrollAtTop, isScrollAtBottom, function (offsetY) { | ||
syncScrollTop(function (top) { | ||
var newTop = top + offsetY; | ||
return newTop; | ||
}); | ||
}), | ||
_useFrameWheel2 = _slicedToArray(_useFrameWheel, 2), | ||
onRawWheel = _useFrameWheel2[0], | ||
onFireFoxScroll = _useFrameWheel2[1]; // Mobile touch move | ||
syncScrollTop(function (top) { | ||
var newTop = top + offsetY; | ||
return newTop; | ||
}); | ||
}), | ||
_useFrameWheel2 = _slicedToArray(_useFrameWheel, 2), | ||
onRawWheel = _useFrameWheel2[0], | ||
onFireFoxScroll = _useFrameWheel2[1]; | ||
// Mobile touch move | ||
useMobileTouchMove(useVirtual, componentRef, function (deltaY, smoothOffset) { | ||
@@ -273,3 +217,2 @@ if (originScroll(deltaY, smoothOffset)) { | ||
} | ||
onRawWheel({ | ||
@@ -288,3 +231,2 @@ preventDefault: function preventDefault() {}, | ||
} | ||
componentRef.current.addEventListener('wheel', onRawWheel); | ||
@@ -300,7 +242,6 @@ componentRef.current.addEventListener('DOMMouseScroll', onFireFoxScroll); | ||
}; | ||
}, [useVirtual]); // ================================= Ref ================================== | ||
}, [useVirtual]); | ||
// ================================= Ref ================================== | ||
var scrollTo = useScrollTo(componentRef, mergedData, heights, itemHeight, getKey, collectHeight, syncScrollTop, function () { | ||
var _scrollBarRef$current; | ||
(_scrollBarRef$current = scrollBarRef.current) === null || _scrollBarRef$current === void 0 ? void 0 : _scrollBarRef$current.delayHidden(); | ||
@@ -312,6 +253,5 @@ }); | ||
}; | ||
}); // ================================ Effect ================================ | ||
}); | ||
// ================================ Effect ================================ | ||
/** We need told outside that some list not rendered */ | ||
useLayoutEffect(function () { | ||
@@ -322,13 +262,10 @@ if (onVisibleChange) { | ||
} | ||
}, [start, end, mergedData]); // ================================ Render ================================ | ||
}, [start, end, mergedData]); | ||
// ================================ Render ================================ | ||
var listChildren = useChildren(mergedData, start, end, setInstanceRef, children, sharedConfig); | ||
var componentStyle = null; | ||
if (height) { | ||
componentStyle = _objectSpread(_defineProperty({}, fullHeight ? 'height' : 'maxHeight', height), ScrollStyle); | ||
if (useVirtual) { | ||
componentStyle.overflowY = 'hidden'; | ||
if (scrollMoving) { | ||
@@ -339,3 +276,2 @@ componentStyle.pointerEvents = 'none'; | ||
} | ||
return /*#__PURE__*/React.createElement("div", _extends({ | ||
@@ -342,0 +278,0 @@ style: _objectSpread(_objectSpread({}, style), {}, { |
@@ -1,7 +0,2 @@ | ||
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; } | ||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; } | ||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2"; | ||
import * as React from 'react'; | ||
@@ -8,0 +3,0 @@ import { RawList } from './List'; |
@@ -1,25 +0,6 @@ | ||
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); } | ||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } | ||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); } | ||
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } | ||
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } | ||
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); } | ||
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } | ||
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } | ||
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } | ||
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty"; | ||
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck"; | ||
import _createClass from "@babel/runtime/helpers/esm/createClass"; | ||
import _inherits from "@babel/runtime/helpers/esm/inherits"; | ||
import _createSuper from "@babel/runtime/helpers/esm/createSuper"; | ||
import * as React from 'react'; | ||
@@ -29,21 +10,14 @@ import classNames from 'classnames'; | ||
var MIN_SIZE = 20; | ||
function getPageY(e) { | ||
return 'touches' in e ? e.touches[0].pageY : e.pageY; | ||
} | ||
var ScrollBar = /*#__PURE__*/function (_React$Component) { | ||
_inherits(ScrollBar, _React$Component); | ||
var _super = _createSuper(ScrollBar); | ||
function ScrollBar() { | ||
var _this; | ||
_classCallCheck(this, ScrollBar); | ||
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
_this = _super.call.apply(_super, [this].concat(args)); | ||
@@ -60,10 +34,7 @@ _this.moveRaf = null; | ||
}; | ||
_this.delayHidden = function () { | ||
clearTimeout(_this.visibleTimeout); | ||
_this.setState({ | ||
visible: true | ||
}); | ||
_this.visibleTimeout = setTimeout(function () { | ||
@@ -75,7 +46,5 @@ _this.setState({ | ||
}; | ||
_this.onScrollbarTouchStart = function (e) { | ||
e.preventDefault(); | ||
}; | ||
_this.onContainerMouseDown = function (e) { | ||
@@ -85,33 +54,22 @@ e.stopPropagation(); | ||
}; | ||
_this.patchEvents = function () { | ||
window.addEventListener('mousemove', _this.onMouseMove); | ||
window.addEventListener('mouseup', _this.onMouseUp); | ||
_this.thumbRef.current.addEventListener('touchmove', _this.onMouseMove); | ||
_this.thumbRef.current.addEventListener('touchend', _this.onMouseUp); | ||
}; | ||
_this.removeEvents = function () { | ||
var _this$scrollbarRef$cu; | ||
window.removeEventListener('mousemove', _this.onMouseMove); | ||
window.removeEventListener('mouseup', _this.onMouseUp); | ||
(_this$scrollbarRef$cu = _this.scrollbarRef.current) === null || _this$scrollbarRef$cu === void 0 ? void 0 : _this$scrollbarRef$cu.removeEventListener('touchstart', _this.onScrollbarTouchStart); | ||
if (_this.thumbRef.current) { | ||
_this.thumbRef.current.removeEventListener('touchstart', _this.onMouseDown); | ||
_this.thumbRef.current.removeEventListener('touchmove', _this.onMouseMove); | ||
_this.thumbRef.current.removeEventListener('touchend', _this.onMouseUp); | ||
} | ||
raf.cancel(_this.moveRaf); | ||
}; | ||
_this.onMouseDown = function (e) { | ||
var onStartMove = _this.props.onStartMove; | ||
_this.setState({ | ||
@@ -122,27 +80,19 @@ dragging: true, | ||
}); | ||
onStartMove(); | ||
_this.patchEvents(); | ||
e.stopPropagation(); | ||
e.preventDefault(); | ||
}; | ||
_this.onMouseMove = function (e) { | ||
var _this$state = _this.state, | ||
dragging = _this$state.dragging, | ||
pageY = _this$state.pageY, | ||
startTop = _this$state.startTop; | ||
dragging = _this$state.dragging, | ||
pageY = _this$state.pageY, | ||
startTop = _this$state.startTop; | ||
var onScroll = _this.props.onScroll; | ||
raf.cancel(_this.moveRaf); | ||
if (dragging) { | ||
var offsetY = getPageY(e) - pageY; | ||
var newTop = startTop + offsetY; | ||
var enableScrollRange = _this.getEnableScrollRange(); | ||
var enableHeightRange = _this.getEnableHeightRange(); | ||
var ptg = enableHeightRange ? newTop / enableHeightRange : 0; | ||
@@ -155,19 +105,14 @@ var newScrollTop = Math.ceil(ptg * enableScrollRange); | ||
}; | ||
_this.onMouseUp = function () { | ||
var onStopMove = _this.props.onStopMove; | ||
_this.setState({ | ||
dragging: false | ||
}); | ||
onStopMove(); | ||
_this.removeEvents(); | ||
}; | ||
_this.getSpinHeight = function () { | ||
var _this$props = _this.props, | ||
height = _this$props.height, | ||
count = _this$props.count; | ||
height = _this$props.height, | ||
count = _this$props.count; | ||
var baseHeight = height / count * 10; | ||
@@ -178,43 +123,31 @@ baseHeight = Math.max(baseHeight, MIN_SIZE); | ||
}; | ||
_this.getEnableScrollRange = function () { | ||
var _this$props2 = _this.props, | ||
scrollHeight = _this$props2.scrollHeight, | ||
height = _this$props2.height; | ||
scrollHeight = _this$props2.scrollHeight, | ||
height = _this$props2.height; | ||
return scrollHeight - height || 0; | ||
}; | ||
_this.getEnableHeightRange = function () { | ||
var height = _this.props.height; | ||
var spinHeight = _this.getSpinHeight(); | ||
return height - spinHeight || 0; | ||
}; | ||
_this.getTop = function () { | ||
var scrollTop = _this.props.scrollTop; | ||
var enableScrollRange = _this.getEnableScrollRange(); | ||
var enableHeightRange = _this.getEnableHeightRange(); | ||
if (scrollTop === 0 || enableScrollRange === 0) { | ||
return 0; | ||
} | ||
var ptg = scrollTop / enableScrollRange; | ||
return ptg * enableHeightRange; | ||
}; | ||
_this.showScroll = function () { | ||
var _this$props3 = _this.props, | ||
height = _this$props3.height, | ||
scrollHeight = _this$props3.scrollHeight; | ||
height = _this$props3.height, | ||
scrollHeight = _this$props3.scrollHeight; | ||
return scrollHeight > height; | ||
}; | ||
return _this; | ||
} | ||
_createClass(ScrollBar, [{ | ||
@@ -241,7 +174,8 @@ key: "componentDidMount", | ||
key: "render", | ||
value: // ====================== Render ======================= | ||
value: | ||
// ====================== Render ======================= | ||
function render() { | ||
var _this$state2 = this.state, | ||
dragging = _this$state2.dragging, | ||
visible = _this$state2.visible; | ||
dragging = _this$state2.dragging, | ||
visible = _this$state2.visible; | ||
var prefixCls = this.props.prefixCls; | ||
@@ -283,6 +217,4 @@ var spinHeight = this.getSpinHeight(); | ||
}]); | ||
return ScrollBar; | ||
}(React.Component); | ||
export { ScrollBar as default }; |
@@ -17,19 +17,15 @@ /** | ||
var afterCount = max - start; | ||
var balanceCount = Math.min(beforeCount, afterCount) * 2; // Balance | ||
var balanceCount = Math.min(beforeCount, afterCount) * 2; | ||
// Balance | ||
if (index <= balanceCount) { | ||
var stepIndex = Math.floor(index / 2); | ||
if (index % 2) { | ||
return start + stepIndex + 1; | ||
} | ||
return start - stepIndex; | ||
} // One is out of range | ||
} | ||
// One is out of range | ||
if (beforeCount > afterCount) { | ||
return start - (index - afterCount); | ||
} | ||
return start + (index - beforeCount); | ||
@@ -41,3 +37,2 @@ } | ||
*/ | ||
export function findListDiffIndex(originList, targetList, getKey) { | ||
@@ -48,7 +43,5 @@ var originLen = originList.length; | ||
var longList; | ||
if (originLen === 0 && targetLen === 0) { | ||
return null; | ||
} | ||
if (originLen < targetLen) { | ||
@@ -61,7 +54,5 @@ shortList = originList; | ||
} | ||
var notExistKey = { | ||
__EMPTY_ITEM__: true | ||
}; | ||
function getItemKey(item) { | ||
@@ -71,14 +62,10 @@ if (item !== undefined) { | ||
} | ||
return notExistKey; | ||
} // Loop to find diff one | ||
} | ||
// Loop to find diff one | ||
var diffIndex = null; | ||
var multiple = Math.abs(originLen - targetLen) !== 1; | ||
for (var i = 0; i < longList.length; i += 1) { | ||
var shortKey = getItemKey(shortList[i]); | ||
var longKey = getItemKey(longList[i]); | ||
if (shortKey !== longKey) { | ||
@@ -90,3 +77,2 @@ diffIndex = i; | ||
} | ||
return diffIndex === null ? null : { | ||
@@ -93,0 +79,0 @@ index: diffIndex, |
@@ -1,7 +0,3 @@ | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } | ||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } | ||
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck"; | ||
import _createClass from "@babel/runtime/helpers/esm/createClass"; | ||
// Firefox has low performance of map. | ||
@@ -11,7 +7,5 @@ var CacheMap = /*#__PURE__*/function () { | ||
_classCallCheck(this, CacheMap); | ||
this.maps = void 0; | ||
this.maps = Object.create(null); | ||
} | ||
_createClass(CacheMap, [{ | ||
@@ -28,6 +22,4 @@ key: "set", | ||
}]); | ||
return CacheMap; | ||
}(); | ||
export default CacheMap; |
@@ -1,4 +0,3 @@ | ||
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); } | ||
import _typeof from "@babel/runtime/helpers/esm/typeof"; | ||
var isFF = (typeof navigator === "undefined" ? "undefined" : _typeof(navigator)) === 'object' && /Firefox/i.test(navigator.userAgent); | ||
export default isFF; |
"use strict"; | ||
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); } | ||
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default; | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -9,21 +9,7 @@ value: true | ||
exports.default = void 0; | ||
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); | ||
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2")); | ||
var React = _interopRequireWildcard(require("react")); | ||
var _rcResizeObserver = _interopRequireDefault(require("rc-resize-observer")); | ||
var _classnames = _interopRequireDefault(require("classnames")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } | ||
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } | ||
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; } | ||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; } | ||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
/** | ||
@@ -34,6 +20,6 @@ * Fill component to provided the scroll content real height. | ||
var height = _ref.height, | ||
offset = _ref.offset, | ||
children = _ref.children, | ||
prefixCls = _ref.prefixCls, | ||
onInnerResize = _ref.onInnerResize; | ||
offset = _ref.offset, | ||
children = _ref.children, | ||
prefixCls = _ref.prefixCls, | ||
onInnerResize = _ref.onInnerResize; | ||
var outerStyle = {}; | ||
@@ -44,3 +30,2 @@ var innerStyle = { | ||
}; | ||
if (offset !== undefined) { | ||
@@ -52,3 +37,3 @@ outerStyle = { | ||
}; | ||
innerStyle = _objectSpread(_objectSpread({}, innerStyle), {}, { | ||
innerStyle = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, innerStyle), {}, { | ||
transform: "translateY(".concat(offset, "px)"), | ||
@@ -61,3 +46,2 @@ position: 'absolute', | ||
} | ||
return /*#__PURE__*/React.createElement("div", { | ||
@@ -68,3 +52,2 @@ style: outerStyle | ||
var offsetHeight = _ref2.offsetHeight; | ||
if (offsetHeight && onInnerResize) { | ||
@@ -76,3 +59,3 @@ onInnerResize(); | ||
style: innerStyle, | ||
className: (0, _classnames.default)(_defineProperty({}, "".concat(prefixCls, "-holder-inner"), prefixCls)), | ||
className: (0, _classnames.default)((0, _defineProperty2.default)({}, "".concat(prefixCls, "-holder-inner"), prefixCls)), | ||
ref: ref | ||
@@ -79,0 +62,0 @@ }, children))); |
@@ -0,2 +1,3 @@ | ||
/// <reference types="react" /> | ||
import type { SharedConfig, RenderFunc } from '../interface'; | ||
export default function useChildren<T>(list: T[], startIndex: number, endIndex: number, setNodeRef: (item: T, element: HTMLElement) => void, renderFunc: RenderFunc<T>, { getKey }: SharedConfig<T>): JSX.Element[]; |
"use strict"; | ||
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); } | ||
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default; | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -9,11 +8,4 @@ value: true | ||
exports.default = useChildren; | ||
var React = _interopRequireWildcard(require("react")); | ||
var _Item = require("../Item"); | ||
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } | ||
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } | ||
function useChildren(list, startIndex, endIndex, setNodeRef, renderFunc, _ref) { | ||
@@ -23,3 +15,4 @@ var getKey = _ref.getKey; | ||
var eleIndex = startIndex + index; | ||
var node = renderFunc(item, eleIndex, {// style: status === 'MEASURE_START' ? { visibility: 'hidden' } : {}, | ||
var node = renderFunc(item, eleIndex, { | ||
// style: status === 'MEASURE_START' ? { visibility: 'hidden' } : {}, | ||
}); | ||
@@ -26,0 +19,0 @@ var key = getKey(item); |
"use strict"; | ||
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); } | ||
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default; | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -9,37 +9,16 @@ value: true | ||
exports.default = useDiffItem; | ||
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray")); | ||
var React = _interopRequireWildcard(require("react")); | ||
var _algorithmUtil = require("../utils/algorithmUtil"); | ||
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } | ||
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } | ||
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); } | ||
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } | ||
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } | ||
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } | ||
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } | ||
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } | ||
function useDiffItem(data, getKey, onDiff) { | ||
var _React$useState = React.useState(data), | ||
_React$useState2 = _slicedToArray(_React$useState, 2), | ||
prevData = _React$useState2[0], | ||
setPrevData = _React$useState2[1]; | ||
_React$useState2 = (0, _slicedToArray2.default)(_React$useState, 2), | ||
prevData = _React$useState2[0], | ||
setPrevData = _React$useState2[1]; | ||
var _React$useState3 = React.useState(null), | ||
_React$useState4 = _slicedToArray(_React$useState3, 2), | ||
diffItem = _React$useState4[0], | ||
setDiffItem = _React$useState4[1]; | ||
_React$useState4 = (0, _slicedToArray2.default)(_React$useState3, 2), | ||
diffItem = _React$useState4[0], | ||
setDiffItem = _React$useState4[1]; | ||
React.useEffect(function () { | ||
var diff = (0, _algorithmUtil.findListDiffIndex)(prevData || [], data || [], getKey); | ||
if ((diff === null || diff === void 0 ? void 0 : diff.index) !== undefined) { | ||
@@ -49,3 +28,2 @@ onDiff === null || onDiff === void 0 ? void 0 : onDiff(diff.index); | ||
} | ||
setPrevData(data); | ||
@@ -52,0 +30,0 @@ }, [data]); |
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default; | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -7,37 +8,26 @@ value: true | ||
exports.default = useFrameWheel; | ||
var _react = require("react"); | ||
var _raf = _interopRequireDefault(require("rc-util/lib/raf")); | ||
var _isFirefox = _interopRequireDefault(require("../utils/isFirefox")); | ||
var _useOriginScroll = _interopRequireDefault(require("./useOriginScroll")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function useFrameWheel(inVirtual, isScrollAtTop, isScrollAtBottom, onWheelDelta) { | ||
var offsetRef = (0, _react.useRef)(0); | ||
var nextFrameRef = (0, _react.useRef)(null); // Firefox patch | ||
var nextFrameRef = (0, _react.useRef)(null); | ||
// Firefox patch | ||
var wheelValueRef = (0, _react.useRef)(null); | ||
var isMouseScrollRef = (0, _react.useRef)(false); // Scroll status sync | ||
var isMouseScrollRef = (0, _react.useRef)(false); | ||
// Scroll status sync | ||
var originScroll = (0, _useOriginScroll.default)(isScrollAtTop, isScrollAtBottom); | ||
function onWheel(event) { | ||
if (!inVirtual) return; | ||
_raf.default.cancel(nextFrameRef.current); | ||
var deltaY = event.deltaY; | ||
offsetRef.current += deltaY; | ||
wheelValueRef.current = deltaY; // Do nothing when scroll at the edge, Skip check when is in scroll | ||
if (originScroll(deltaY)) return; // Proxy of scroll events | ||
wheelValueRef.current = deltaY; | ||
// Do nothing when scroll at the edge, Skip check when is in scroll | ||
if (originScroll(deltaY)) return; | ||
// Proxy of scroll events | ||
if (!_isFirefox.default) { | ||
event.preventDefault(); | ||
} | ||
nextFrameRef.current = (0, _raf.default)(function () { | ||
@@ -50,5 +40,4 @@ // Patch a multiple for Firefox to fix wheel number too small | ||
}); | ||
} // A patch for firefox | ||
} | ||
// A patch for firefox | ||
function onFireFoxScroll(event) { | ||
@@ -58,4 +47,3 @@ if (!inVirtual) return; | ||
} | ||
return [onWheel, onFireFoxScroll]; | ||
} |
"use strict"; | ||
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); } | ||
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default; | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -9,43 +9,18 @@ value: true | ||
exports.default = useHeights; | ||
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray")); | ||
var React = _interopRequireWildcard(require("react")); | ||
var _findDOMNode = _interopRequireDefault(require("rc-util/lib/Dom/findDOMNode")); | ||
var _raf = _interopRequireDefault(require("rc-util/lib/raf")); | ||
var _CacheMap = _interopRequireDefault(require("../utils/CacheMap")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } | ||
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } | ||
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); } | ||
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } | ||
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } | ||
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } | ||
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } | ||
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } | ||
function useHeights(getKey, onItemAdd, onItemRemove) { | ||
var _React$useState = React.useState(0), | ||
_React$useState2 = _slicedToArray(_React$useState, 2), | ||
updatedMark = _React$useState2[0], | ||
setUpdatedMark = _React$useState2[1]; | ||
_React$useState2 = (0, _slicedToArray2.default)(_React$useState, 2), | ||
updatedMark = _React$useState2[0], | ||
setUpdatedMark = _React$useState2[1]; | ||
var instanceRef = (0, React.useRef)(new Map()); | ||
var heightsRef = (0, React.useRef)(new _CacheMap.default()); | ||
var collectRafRef = (0, React.useRef)(); | ||
function cancelRaf() { | ||
_raf.default.cancel(collectRafRef.current); | ||
} | ||
function collectHeight() { | ||
@@ -58,3 +33,2 @@ cancelRaf(); | ||
var offsetHeight = htmlElement.offsetHeight; | ||
if (heightsRef.current.get(key) !== offsetHeight) { | ||
@@ -64,4 +38,4 @@ heightsRef.current.set(key, htmlElement.offsetHeight); | ||
} | ||
}); // Always trigger update mark to tell parent that should re-calculate heights when resized | ||
}); | ||
// Always trigger update mark to tell parent that should re-calculate heights when resized | ||
setUpdatedMark(function (c) { | ||
@@ -72,7 +46,5 @@ return c + 1; | ||
} | ||
function setInstanceRef(item, instance) { | ||
var key = getKey(item); | ||
var origin = instanceRef.current.get(key); | ||
if (instance) { | ||
@@ -83,5 +55,4 @@ instanceRef.current.set(key, instance); | ||
instanceRef.current.delete(key); | ||
} // Instance changed | ||
} | ||
// Instance changed | ||
if (!origin !== !instance) { | ||
@@ -95,3 +66,2 @@ if (instance) { | ||
} | ||
(0, React.useEffect)(function () { | ||
@@ -98,0 +68,0 @@ return cancelRaf; |
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default; | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -7,21 +8,13 @@ value: true | ||
exports.default = useMobileTouchMove; | ||
var _react = require("react"); | ||
var _useLayoutEffect = _interopRequireDefault(require("rc-util/lib/hooks/useLayoutEffect")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var SMOOTH_PTG = 14 / 15; | ||
function useMobileTouchMove(inVirtual, listRef, callback) { | ||
var touchedRef = (0, _react.useRef)(false); | ||
var touchYRef = (0, _react.useRef)(0); | ||
var elementRef = (0, _react.useRef)(null); // Smooth scroll | ||
var elementRef = (0, _react.useRef)(null); | ||
// Smooth scroll | ||
var intervalRef = (0, _react.useRef)(null); | ||
/* eslint-disable prefer-const */ | ||
var cleanUpEvents; | ||
var onTouchMove = function onTouchMove(e) { | ||
@@ -32,12 +25,9 @@ if (touchedRef.current) { | ||
touchYRef.current = currentY; | ||
if (callback(offsetY)) { | ||
e.preventDefault(); | ||
} // Smooth interval | ||
} | ||
// Smooth interval | ||
clearInterval(intervalRef.current); | ||
intervalRef.current = setInterval(function () { | ||
offsetY *= SMOOTH_PTG; | ||
if (!callback(offsetY, true) || Math.abs(offsetY) <= 0.1) { | ||
@@ -49,3 +39,2 @@ clearInterval(intervalRef.current); | ||
}; | ||
var onTouchEnd = function onTouchEnd() { | ||
@@ -55,6 +44,4 @@ touchedRef.current = false; | ||
}; | ||
var onTouchStart = function onTouchStart(e) { | ||
cleanUpEvents(); | ||
if (e.touches.length === 1 && !touchedRef.current) { | ||
@@ -68,3 +55,2 @@ touchedRef.current = true; | ||
}; | ||
cleanUpEvents = function cleanUpEvents() { | ||
@@ -76,3 +62,2 @@ if (elementRef.current) { | ||
}; | ||
(0, _useLayoutEffect.default)(function () { | ||
@@ -82,6 +67,4 @@ if (inVirtual) { | ||
} | ||
return function () { | ||
var _listRef$current; | ||
(_listRef$current = listRef.current) === null || _listRef$current === void 0 ? void 0 : _listRef$current.removeEventListener('touchstart', onTouchStart); | ||
@@ -88,0 +71,0 @@ cleanUpEvents(); |
@@ -7,5 +7,3 @@ "use strict"; | ||
exports.default = void 0; | ||
var _react = require("react"); | ||
var _default = function _default(isScrollAtTop, isScrollAtBottom) { | ||
@@ -15,3 +13,2 @@ // Do lock for a wheel when scrolling | ||
var lockTimeoutRef = (0, _react.useRef)(null); | ||
function lockScroll() { | ||
@@ -23,5 +20,4 @@ clearTimeout(lockTimeoutRef.current); | ||
}, 50); | ||
} // Pass to ref since global add is in closure | ||
} | ||
// Pass to ref since global add is in closure | ||
var scrollPingRef = (0, _react.useRef)({ | ||
@@ -35,6 +31,7 @@ top: isScrollAtTop, | ||
var smoothOffset = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; | ||
var originScroll = // Pass origin wheel when on the top | ||
deltaY < 0 && scrollPingRef.current.top || // Pass origin wheel when on the bottom | ||
var originScroll = | ||
// Pass origin wheel when on the top | ||
deltaY < 0 && scrollPingRef.current.top || | ||
// Pass origin wheel when on the bottom | ||
deltaY > 0 && scrollPingRef.current.bottom; | ||
if (smoothOffset && originScroll) { | ||
@@ -47,7 +44,5 @@ // No need lock anymore when it's smooth offset from touchMove interval | ||
} | ||
return !lockRef.current && originScroll; | ||
}; | ||
}; | ||
exports.default = _default; |
"use strict"; | ||
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default; | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -7,15 +9,7 @@ value: true | ||
exports.default = useScrollTo; | ||
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof")); | ||
var React = _interopRequireWildcard(require("react")); | ||
var _raf = _interopRequireDefault(require("rc-util/lib/raf")); | ||
/* eslint-disable no-param-reassign */ | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } | ||
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } | ||
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); } | ||
function useScrollTo(containerRef, data, heights, itemHeight, getKey, collectHeight, syncScrollTop, triggerFlash) { | ||
@@ -28,13 +22,10 @@ var scrollRef = React.useRef(); | ||
return; | ||
} // Normal scroll logic | ||
} | ||
// Normal scroll logic | ||
_raf.default.cancel(scrollRef.current); | ||
if (typeof arg === 'number') { | ||
syncScrollTop(arg); | ||
} else if (arg && _typeof(arg) === 'object') { | ||
} else if (arg && (0, _typeof2.default)(arg) === 'object') { | ||
var index; | ||
var align = arg.align; | ||
if ('index' in arg) { | ||
@@ -47,6 +38,5 @@ index = arg.index; | ||
} | ||
var _arg$offset = arg.offset, | ||
offset = _arg$offset === void 0 ? 0 : _arg$offset; // We will retry 3 times in case dynamic height shaking | ||
offset = _arg$offset === void 0 ? 0 : _arg$offset; | ||
// We will retry 3 times in case dynamic height shaking | ||
var syncScroll = function syncScroll(times, targetAlign) { | ||
@@ -56,7 +46,7 @@ if (times < 0 || !containerRef.current) return; | ||
var needCollectHeight = false; | ||
var newTargetAlign = targetAlign; // Go to next frame if height not exist | ||
var newTargetAlign = targetAlign; | ||
// Go to next frame if height not exist | ||
if (height) { | ||
var mergedAlign = targetAlign || align; // Get top & bottom | ||
var mergedAlign = targetAlign || align; | ||
// Get top & bottom | ||
var stackTop = 0; | ||
@@ -66,3 +56,2 @@ var itemTop = 0; | ||
var maxLen = Math.min(data.length, index); | ||
for (var i = 0; i <= maxLen; i += 1) { | ||
@@ -74,11 +63,8 @@ var key = getKey(data[i]); | ||
stackTop = itemBottom; | ||
if (i === index && cacheHeight === undefined) { | ||
needCollectHeight = true; | ||
} | ||
} // Scroll to | ||
} | ||
// Scroll to | ||
var targetTop = null; | ||
switch (mergedAlign) { | ||
@@ -88,7 +74,5 @@ case 'top': | ||
break; | ||
case 'bottom': | ||
targetTop = itemBottom - height + offset; | ||
break; | ||
default: | ||
@@ -98,3 +82,2 @@ { | ||
var scrollBottom = scrollTop + height; | ||
if (itemTop < scrollTop) { | ||
@@ -107,9 +90,7 @@ newTargetAlign = 'top'; | ||
} | ||
if (targetTop !== null && targetTop !== containerRef.current.scrollTop) { | ||
syncScrollTop(targetTop); | ||
} | ||
} // We will retry since element may not sync height as it described | ||
} | ||
// We will retry since element may not sync height as it described | ||
scrollRef.current = (0, _raf.default)(function () { | ||
@@ -119,7 +100,5 @@ if (needCollectHeight) { | ||
} | ||
syncScroll(times - 1, newTargetAlign); | ||
}); | ||
}; | ||
syncScroll(3); | ||
@@ -126,0 +105,0 @@ } |
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default; | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -7,8 +8,4 @@ value: true | ||
exports.default = void 0; | ||
var _List = _interopRequireDefault(require("./List")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var _default = _List.default; | ||
exports.default = _default; |
"use strict"; | ||
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); } | ||
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default; | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -9,12 +8,6 @@ value: true | ||
exports.Item = Item; | ||
var React = _interopRequireWildcard(require("react")); | ||
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } | ||
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } | ||
function Item(_ref) { | ||
var children = _ref.children, | ||
setRef = _ref.setRef; | ||
setRef = _ref.setRef; | ||
var refFunc = React.useCallback(function (node) { | ||
@@ -21,0 +14,0 @@ setRef(node); |
347
lib/List.js
"use strict"; | ||
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); } | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default; | ||
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default; | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -10,59 +10,20 @@ value: true | ||
exports.default = void 0; | ||
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")); | ||
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); | ||
var _objectSpread3 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2")); | ||
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray")); | ||
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties")); | ||
var React = _interopRequireWildcard(require("react")); | ||
var _classnames = _interopRequireDefault(require("classnames")); | ||
var _Filler = _interopRequireDefault(require("./Filler")); | ||
var _ScrollBar = _interopRequireDefault(require("./ScrollBar")); | ||
var _useChildren = _interopRequireDefault(require("./hooks/useChildren")); | ||
var _useHeights3 = _interopRequireDefault(require("./hooks/useHeights")); | ||
var _useScrollTo = _interopRequireDefault(require("./hooks/useScrollTo")); | ||
var _useDiffItem3 = _interopRequireDefault(require("./hooks/useDiffItem")); | ||
var _useFrameWheel3 = _interopRequireDefault(require("./hooks/useFrameWheel")); | ||
var _useMobileTouchMove = _interopRequireDefault(require("./hooks/useMobileTouchMove")); | ||
var _useOriginScroll = _interopRequireDefault(require("./hooks/useOriginScroll")); | ||
var _useLayoutEffect = _interopRequireDefault(require("rc-util/lib/hooks/useLayoutEffect")); | ||
var _excluded = ["prefixCls", "className", "height", "itemHeight", "fullHeight", "style", "data", "children", "itemKey", "virtual", "component", "onScroll", "onVisibleChange"]; | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } | ||
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } | ||
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } | ||
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; } | ||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; } | ||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); } | ||
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } | ||
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } | ||
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } | ||
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } | ||
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } | ||
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; } | ||
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; } | ||
var EMPTY_DATA = []; | ||
@@ -73,36 +34,31 @@ var ScrollStyle = { | ||
}; | ||
function RawList(props, ref) { | ||
var _props$prefixCls = props.prefixCls, | ||
prefixCls = _props$prefixCls === void 0 ? 'rc-virtual-list' : _props$prefixCls, | ||
className = props.className, | ||
height = props.height, | ||
itemHeight = props.itemHeight, | ||
_props$fullHeight = props.fullHeight, | ||
fullHeight = _props$fullHeight === void 0 ? true : _props$fullHeight, | ||
style = props.style, | ||
data = props.data, | ||
children = props.children, | ||
itemKey = props.itemKey, | ||
virtual = props.virtual, | ||
_props$component = props.component, | ||
Component = _props$component === void 0 ? 'div' : _props$component, | ||
onScroll = props.onScroll, | ||
onVisibleChange = props.onVisibleChange, | ||
restProps = _objectWithoutProperties(props, _excluded); // ================================= MISC ================================= | ||
prefixCls = _props$prefixCls === void 0 ? 'rc-virtual-list' : _props$prefixCls, | ||
className = props.className, | ||
height = props.height, | ||
itemHeight = props.itemHeight, | ||
_props$fullHeight = props.fullHeight, | ||
fullHeight = _props$fullHeight === void 0 ? true : _props$fullHeight, | ||
style = props.style, | ||
data = props.data, | ||
children = props.children, | ||
itemKey = props.itemKey, | ||
virtual = props.virtual, | ||
_props$component = props.component, | ||
Component = _props$component === void 0 ? 'div' : _props$component, | ||
onScroll = props.onScroll, | ||
onVisibleChange = props.onVisibleChange, | ||
restProps = (0, _objectWithoutProperties2.default)(props, _excluded); | ||
// ================================= MISC ================================= | ||
var useVirtual = !!(virtual !== false && height && itemHeight); | ||
var inVirtual = useVirtual && data && itemHeight * data.length > height; | ||
var _useState = (0, React.useState)(0), | ||
_useState2 = _slicedToArray(_useState, 2), | ||
scrollTop = _useState2[0], | ||
setScrollTop = _useState2[1]; | ||
_useState2 = (0, _slicedToArray2.default)(_useState, 2), | ||
scrollTop = _useState2[0], | ||
setScrollTop = _useState2[1]; | ||
var _useState3 = (0, React.useState)(false), | ||
_useState4 = _slicedToArray(_useState3, 2), | ||
scrollMoving = _useState4[0], | ||
setScrollMoving = _useState4[1]; | ||
_useState4 = (0, _slicedToArray2.default)(_useState3, 2), | ||
scrollMoving = _useState4[0], | ||
setScrollMoving = _useState4[1]; | ||
var mergedClassName = (0, _classnames.default)(prefixCls, className); | ||
@@ -114,3 +70,2 @@ var mergedData = data || EMPTY_DATA; | ||
// =============================== Item Key =============================== | ||
var getKey = React.useCallback(function (item) { | ||
@@ -120,3 +75,2 @@ if (typeof itemKey === 'function') { | ||
} | ||
return item === null || item === void 0 ? void 0 : item[itemKey]; | ||
@@ -126,8 +80,7 @@ }, [itemKey]); | ||
getKey: getKey | ||
}; // ================================ Scroll ================================ | ||
}; | ||
// ================================ Scroll ================================ | ||
function syncScrollTop(newTop) { | ||
setScrollTop(function (origin) { | ||
var value; | ||
if (typeof newTop === 'function') { | ||
@@ -138,3 +91,2 @@ value = newTop(origin); | ||
} | ||
var alignedTop = keepInRange(value); | ||
@@ -144,6 +96,5 @@ componentRef.current.scrollTop = alignedTop; | ||
}); | ||
} // ================================ Legacy ================================ | ||
} | ||
// ================================ Legacy ================================ | ||
// Put ref here since the range is generate by follow | ||
var rangeRef = (0, React.useRef)({ | ||
@@ -154,145 +105,118 @@ start: 0, | ||
var diffItemRef = (0, React.useRef)(); | ||
var _useDiffItem = (0, _useDiffItem3.default)(mergedData, getKey), | ||
_useDiffItem2 = _slicedToArray(_useDiffItem, 1), | ||
diffItem = _useDiffItem2[0]; | ||
diffItemRef.current = diffItem; // ================================ Height ================================ | ||
_useDiffItem2 = (0, _slicedToArray2.default)(_useDiffItem, 1), | ||
diffItem = _useDiffItem2[0]; | ||
diffItemRef.current = diffItem; | ||
// ================================ Height ================================ | ||
var _useHeights = (0, _useHeights3.default)(getKey, null, null), | ||
_useHeights2 = _slicedToArray(_useHeights, 4), | ||
setInstanceRef = _useHeights2[0], | ||
collectHeight = _useHeights2[1], | ||
heights = _useHeights2[2], | ||
heightUpdatedMark = _useHeights2[3]; // ========================== Visible Calculation ========================= | ||
_useHeights2 = (0, _slicedToArray2.default)(_useHeights, 4), | ||
setInstanceRef = _useHeights2[0], | ||
collectHeight = _useHeights2[1], | ||
heights = _useHeights2[2], | ||
heightUpdatedMark = _useHeights2[3]; | ||
// ========================== Visible Calculation ========================= | ||
var _React$useMemo = React.useMemo(function () { | ||
if (!useVirtual) { | ||
if (!useVirtual) { | ||
return { | ||
scrollHeight: undefined, | ||
start: 0, | ||
end: mergedData.length - 1, | ||
offset: undefined | ||
}; | ||
} | ||
// Always use virtual scroll bar in avoid shaking | ||
if (!inVirtual) { | ||
var _fillerInnerRef$curre; | ||
return { | ||
scrollHeight: ((_fillerInnerRef$curre = fillerInnerRef.current) === null || _fillerInnerRef$curre === void 0 ? void 0 : _fillerInnerRef$curre.offsetHeight) || 0, | ||
start: 0, | ||
end: mergedData.length - 1, | ||
offset: undefined | ||
}; | ||
} | ||
var itemTop = 0; | ||
var startIndex; | ||
var startOffset; | ||
var endIndex; | ||
var dataLen = mergedData.length; | ||
for (var i = 0; i < dataLen; i += 1) { | ||
var item = mergedData[i]; | ||
var key = getKey(item); | ||
var cacheHeight = heights.get(key); | ||
var currentItemBottom = itemTop + (cacheHeight === undefined ? itemHeight : cacheHeight); | ||
// Check item top in the range | ||
if (currentItemBottom >= scrollTop && startIndex === undefined) { | ||
startIndex = i; | ||
startOffset = itemTop; | ||
} | ||
// Check item bottom in the range. We will render additional one item for motion usage | ||
if (currentItemBottom > scrollTop + height && endIndex === undefined) { | ||
endIndex = i; | ||
} | ||
itemTop = currentItemBottom; | ||
} | ||
// When scrollTop at the end but data cut to small count will reach this | ||
if (startIndex === undefined) { | ||
startIndex = 0; | ||
startOffset = 0; | ||
endIndex = Math.ceil(height / itemHeight); | ||
} | ||
if (endIndex === undefined) { | ||
endIndex = mergedData.length - 1; | ||
} | ||
// Give cache to improve scroll experience | ||
endIndex = Math.min(endIndex + 1, mergedData.length); | ||
return { | ||
scrollHeight: undefined, | ||
start: 0, | ||
end: mergedData.length - 1, | ||
offset: undefined | ||
scrollHeight: itemTop, | ||
start: startIndex, | ||
end: endIndex, | ||
offset: startOffset | ||
}; | ||
} // Always use virtual scroll bar in avoid shaking | ||
// Always use virtual scroll bar in avoid shaking | ||
if (!inVirtual) { | ||
var _fillerInnerRef$curre; | ||
return { | ||
scrollHeight: ((_fillerInnerRef$curre = fillerInnerRef.current) === null || _fillerInnerRef$curre === void 0 ? void 0 : _fillerInnerRef$curre.offsetHeight) || 0, | ||
start: 0, | ||
end: mergedData.length - 1, | ||
offset: undefined | ||
}; | ||
} | ||
var itemTop = 0; | ||
var startIndex; | ||
var startOffset; | ||
var endIndex; | ||
var dataLen = mergedData.length; | ||
for (var i = 0; i < dataLen; i += 1) { | ||
var item = mergedData[i]; | ||
var key = getKey(item); | ||
var cacheHeight = heights.get(key); | ||
var currentItemBottom = itemTop + (cacheHeight === undefined ? itemHeight : cacheHeight); // Check item top in the range | ||
// Check item top in the range | ||
if (currentItemBottom >= scrollTop && startIndex === undefined) { | ||
startIndex = i; | ||
startOffset = itemTop; | ||
} // Check item bottom in the range. We will render additional one item for motion usage | ||
// Check item bottom in the range. We will render additional one item for motion usage | ||
if (currentItemBottom > scrollTop + height && endIndex === undefined) { | ||
endIndex = i; | ||
} | ||
itemTop = currentItemBottom; | ||
} // When scrollTop at the end but data cut to small count will reach this | ||
// When scrollTop at the end but data cut to small count will reach this | ||
if (startIndex === undefined) { | ||
startIndex = 0; | ||
startOffset = 0; | ||
endIndex = Math.ceil(height / itemHeight); | ||
} | ||
if (endIndex === undefined) { | ||
endIndex = mergedData.length - 1; | ||
} // Give cache to improve scroll experience | ||
// Give cache to improve scroll experience | ||
endIndex = Math.min(endIndex + 1, mergedData.length); | ||
return { | ||
scrollHeight: itemTop, | ||
start: startIndex, | ||
end: endIndex, | ||
offset: startOffset | ||
}; | ||
}, [inVirtual, useVirtual, scrollTop, mergedData, heightUpdatedMark, height]), | ||
scrollHeight = _React$useMemo.scrollHeight, | ||
start = _React$useMemo.start, | ||
end = _React$useMemo.end, | ||
offset = _React$useMemo.offset; | ||
}, [inVirtual, useVirtual, scrollTop, mergedData, heightUpdatedMark, height]), | ||
scrollHeight = _React$useMemo.scrollHeight, | ||
start = _React$useMemo.start, | ||
end = _React$useMemo.end, | ||
offset = _React$useMemo.offset; | ||
rangeRef.current.start = start; | ||
rangeRef.current.end = end; // =============================== In Range =============================== | ||
rangeRef.current.end = end; | ||
// =============================== In Range =============================== | ||
var maxScrollHeight = scrollHeight - height; | ||
var maxScrollHeightRef = (0, React.useRef)(maxScrollHeight); | ||
maxScrollHeightRef.current = maxScrollHeight; | ||
function keepInRange(newScrollTop) { | ||
var newTop = newScrollTop; | ||
if (!Number.isNaN(maxScrollHeightRef.current)) { | ||
newTop = Math.min(newTop, maxScrollHeightRef.current); | ||
} | ||
newTop = Math.max(newTop, 0); | ||
return newTop; | ||
} | ||
var isScrollAtTop = scrollTop <= 0; | ||
var isScrollAtBottom = scrollTop >= maxScrollHeight; | ||
var originScroll = (0, _useOriginScroll.default)(isScrollAtTop, isScrollAtBottom); // ================================ Scroll ================================ | ||
var originScroll = (0, _useOriginScroll.default)(isScrollAtTop, isScrollAtBottom); | ||
// ================================ Scroll ================================ | ||
function onScrollBar(newScrollTop) { | ||
var newTop = newScrollTop; | ||
syncScrollTop(newTop); | ||
} // When data size reduce. It may trigger native scroll event back to fit scroll position | ||
} | ||
// When data size reduce. It may trigger native scroll event back to fit scroll position | ||
function onFallbackScroll(e) { | ||
var newScrollTop = e.currentTarget.scrollTop; | ||
if (newScrollTop !== scrollTop) { | ||
syncScrollTop(newScrollTop); | ||
} // Trigger origin onScroll | ||
} | ||
// Trigger origin onScroll | ||
onScroll === null || onScroll === void 0 ? void 0 : onScroll(e); | ||
} // Since this added in global,should use ref to keep update | ||
} | ||
// Since this added in global,should use ref to keep update | ||
var _useFrameWheel = (0, _useFrameWheel3.default)(useVirtual, isScrollAtTop, isScrollAtBottom, function (offsetY) { | ||
syncScrollTop(function (top) { | ||
var newTop = top + offsetY; | ||
return newTop; | ||
}); | ||
}), | ||
_useFrameWheel2 = _slicedToArray(_useFrameWheel, 2), | ||
onRawWheel = _useFrameWheel2[0], | ||
onFireFoxScroll = _useFrameWheel2[1]; // Mobile touch move | ||
syncScrollTop(function (top) { | ||
var newTop = top + offsetY; | ||
return newTop; | ||
}); | ||
}), | ||
_useFrameWheel2 = (0, _slicedToArray2.default)(_useFrameWheel, 2), | ||
onRawWheel = _useFrameWheel2[0], | ||
onFireFoxScroll = _useFrameWheel2[1]; | ||
// Mobile touch move | ||
(0, _useMobileTouchMove.default)(useVirtual, componentRef, function (deltaY, smoothOffset) { | ||
@@ -302,3 +226,2 @@ if (originScroll(deltaY, smoothOffset)) { | ||
} | ||
onRawWheel({ | ||
@@ -317,3 +240,2 @@ preventDefault: function preventDefault() {}, | ||
} | ||
componentRef.current.addEventListener('wheel', onRawWheel); | ||
@@ -329,7 +251,6 @@ componentRef.current.addEventListener('DOMMouseScroll', onFireFoxScroll); | ||
}; | ||
}, [useVirtual]); // ================================= Ref ================================== | ||
}, [useVirtual]); | ||
// ================================= Ref ================================== | ||
var scrollTo = (0, _useScrollTo.default)(componentRef, mergedData, heights, itemHeight, getKey, collectHeight, syncScrollTop, function () { | ||
var _scrollBarRef$current; | ||
(_scrollBarRef$current = scrollBarRef.current) === null || _scrollBarRef$current === void 0 ? void 0 : _scrollBarRef$current.delayHidden(); | ||
@@ -341,6 +262,5 @@ }); | ||
}; | ||
}); // ================================ Effect ================================ | ||
}); | ||
// ================================ Effect ================================ | ||
/** We need told outside that some list not rendered */ | ||
(0, _useLayoutEffect.default)(function () { | ||
@@ -351,13 +271,10 @@ if (onVisibleChange) { | ||
} | ||
}, [start, end, mergedData]); // ================================ Render ================================ | ||
}, [start, end, mergedData]); | ||
// ================================ Render ================================ | ||
var listChildren = (0, _useChildren.default)(mergedData, start, end, setInstanceRef, children, sharedConfig); | ||
var componentStyle = null; | ||
if (height) { | ||
componentStyle = _objectSpread(_defineProperty({}, fullHeight ? 'height' : 'maxHeight', height), ScrollStyle); | ||
componentStyle = (0, _objectSpread3.default)((0, _defineProperty2.default)({}, fullHeight ? 'height' : 'maxHeight', height), ScrollStyle); | ||
if (useVirtual) { | ||
componentStyle.overflowY = 'hidden'; | ||
if (scrollMoving) { | ||
@@ -368,5 +285,4 @@ componentStyle.pointerEvents = 'none'; | ||
} | ||
return /*#__PURE__*/React.createElement("div", _extends({ | ||
style: _objectSpread(_objectSpread({}, style), {}, { | ||
return /*#__PURE__*/React.createElement("div", (0, _extends2.default)({ | ||
style: (0, _objectSpread3.default)((0, _objectSpread3.default)({}, style), {}, { | ||
position: 'relative' | ||
@@ -402,3 +318,2 @@ }), | ||
} | ||
var List = /*#__PURE__*/React.forwardRef(RawList); | ||
@@ -405,0 +320,0 @@ List.displayName = 'List'; |
"use strict"; | ||
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); } | ||
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default; | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -9,19 +9,7 @@ value: true | ||
exports.default = void 0; | ||
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2")); | ||
var React = _interopRequireWildcard(require("react")); | ||
var _List = require("./List"); | ||
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } | ||
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } | ||
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; } | ||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; } | ||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
var List = /*#__PURE__*/React.forwardRef(function (props, ref) { | ||
return (0, _List.RawList)(_objectSpread(_objectSpread({}, props), {}, { | ||
return (0, _List.RawList)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, props), {}, { | ||
virtual: false | ||
@@ -28,0 +16,0 @@ }), ref); |
"use strict"; | ||
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); } | ||
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default; | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -9,57 +9,23 @@ value: true | ||
exports.default = void 0; | ||
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); | ||
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")); | ||
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); | ||
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits")); | ||
var _createSuper2 = _interopRequireDefault(require("@babel/runtime/helpers/createSuper")); | ||
var React = _interopRequireWildcard(require("react")); | ||
var _classnames = _interopRequireDefault(require("classnames")); | ||
var _raf = _interopRequireDefault(require("rc-util/lib/raf")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } | ||
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } | ||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } | ||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); } | ||
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } | ||
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } | ||
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); } | ||
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } | ||
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } | ||
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } | ||
var MIN_SIZE = 20; | ||
function getPageY(e) { | ||
return 'touches' in e ? e.touches[0].pageY : e.pageY; | ||
} | ||
var ScrollBar = /*#__PURE__*/function (_React$Component) { | ||
_inherits(ScrollBar, _React$Component); | ||
var _super = _createSuper(ScrollBar); | ||
(0, _inherits2.default)(ScrollBar, _React$Component); | ||
var _super = (0, _createSuper2.default)(ScrollBar); | ||
function ScrollBar() { | ||
var _this; | ||
_classCallCheck(this, ScrollBar); | ||
(0, _classCallCheck2.default)(this, ScrollBar); | ||
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
_this = _super.call.apply(_super, [this].concat(args)); | ||
@@ -76,10 +42,7 @@ _this.moveRaf = null; | ||
}; | ||
_this.delayHidden = function () { | ||
clearTimeout(_this.visibleTimeout); | ||
_this.setState({ | ||
visible: true | ||
}); | ||
_this.visibleTimeout = setTimeout(function () { | ||
@@ -91,7 +54,5 @@ _this.setState({ | ||
}; | ||
_this.onScrollbarTouchStart = function (e) { | ||
e.preventDefault(); | ||
}; | ||
_this.onContainerMouseDown = function (e) { | ||
@@ -101,33 +62,22 @@ e.stopPropagation(); | ||
}; | ||
_this.patchEvents = function () { | ||
window.addEventListener('mousemove', _this.onMouseMove); | ||
window.addEventListener('mouseup', _this.onMouseUp); | ||
_this.thumbRef.current.addEventListener('touchmove', _this.onMouseMove); | ||
_this.thumbRef.current.addEventListener('touchend', _this.onMouseUp); | ||
}; | ||
_this.removeEvents = function () { | ||
var _this$scrollbarRef$cu; | ||
window.removeEventListener('mousemove', _this.onMouseMove); | ||
window.removeEventListener('mouseup', _this.onMouseUp); | ||
(_this$scrollbarRef$cu = _this.scrollbarRef.current) === null || _this$scrollbarRef$cu === void 0 ? void 0 : _this$scrollbarRef$cu.removeEventListener('touchstart', _this.onScrollbarTouchStart); | ||
if (_this.thumbRef.current) { | ||
_this.thumbRef.current.removeEventListener('touchstart', _this.onMouseDown); | ||
_this.thumbRef.current.removeEventListener('touchmove', _this.onMouseMove); | ||
_this.thumbRef.current.removeEventListener('touchend', _this.onMouseUp); | ||
} | ||
_raf.default.cancel(_this.moveRaf); | ||
}; | ||
_this.onMouseDown = function (e) { | ||
var onStartMove = _this.props.onStartMove; | ||
_this.setState({ | ||
@@ -138,28 +88,19 @@ dragging: true, | ||
}); | ||
onStartMove(); | ||
_this.patchEvents(); | ||
e.stopPropagation(); | ||
e.preventDefault(); | ||
}; | ||
_this.onMouseMove = function (e) { | ||
var _this$state = _this.state, | ||
dragging = _this$state.dragging, | ||
pageY = _this$state.pageY, | ||
startTop = _this$state.startTop; | ||
dragging = _this$state.dragging, | ||
pageY = _this$state.pageY, | ||
startTop = _this$state.startTop; | ||
var onScroll = _this.props.onScroll; | ||
_raf.default.cancel(_this.moveRaf); | ||
if (dragging) { | ||
var offsetY = getPageY(e) - pageY; | ||
var newTop = startTop + offsetY; | ||
var enableScrollRange = _this.getEnableScrollRange(); | ||
var enableHeightRange = _this.getEnableHeightRange(); | ||
var ptg = enableHeightRange ? newTop / enableHeightRange : 0; | ||
@@ -172,19 +113,14 @@ var newScrollTop = Math.ceil(ptg * enableScrollRange); | ||
}; | ||
_this.onMouseUp = function () { | ||
var onStopMove = _this.props.onStopMove; | ||
_this.setState({ | ||
dragging: false | ||
}); | ||
onStopMove(); | ||
_this.removeEvents(); | ||
}; | ||
_this.getSpinHeight = function () { | ||
var _this$props = _this.props, | ||
height = _this$props.height, | ||
count = _this$props.count; | ||
height = _this$props.height, | ||
count = _this$props.count; | ||
var baseHeight = height / count * 10; | ||
@@ -195,44 +131,32 @@ baseHeight = Math.max(baseHeight, MIN_SIZE); | ||
}; | ||
_this.getEnableScrollRange = function () { | ||
var _this$props2 = _this.props, | ||
scrollHeight = _this$props2.scrollHeight, | ||
height = _this$props2.height; | ||
scrollHeight = _this$props2.scrollHeight, | ||
height = _this$props2.height; | ||
return scrollHeight - height || 0; | ||
}; | ||
_this.getEnableHeightRange = function () { | ||
var height = _this.props.height; | ||
var spinHeight = _this.getSpinHeight(); | ||
return height - spinHeight || 0; | ||
}; | ||
_this.getTop = function () { | ||
var scrollTop = _this.props.scrollTop; | ||
var enableScrollRange = _this.getEnableScrollRange(); | ||
var enableHeightRange = _this.getEnableHeightRange(); | ||
if (scrollTop === 0 || enableScrollRange === 0) { | ||
return 0; | ||
} | ||
var ptg = scrollTop / enableScrollRange; | ||
return ptg * enableHeightRange; | ||
}; | ||
_this.showScroll = function () { | ||
var _this$props3 = _this.props, | ||
height = _this$props3.height, | ||
scrollHeight = _this$props3.scrollHeight; | ||
height = _this$props3.height, | ||
scrollHeight = _this$props3.scrollHeight; | ||
return scrollHeight > height; | ||
}; | ||
return _this; | ||
} | ||
_createClass(ScrollBar, [{ | ||
(0, _createClass2.default)(ScrollBar, [{ | ||
key: "componentDidMount", | ||
@@ -258,7 +182,8 @@ value: function componentDidMount() { | ||
key: "render", | ||
value: // ====================== Render ======================= | ||
value: | ||
// ====================== Render ======================= | ||
function render() { | ||
var _this$state2 = this.state, | ||
dragging = _this$state2.dragging, | ||
visible = _this$state2.visible; | ||
dragging = _this$state2.dragging, | ||
visible = _this$state2.visible; | ||
var prefixCls = this.props.prefixCls; | ||
@@ -271,3 +196,3 @@ var spinHeight = this.getSpinHeight(); | ||
ref: this.scrollbarRef, | ||
className: (0, _classnames.default)("".concat(prefixCls, "-scrollbar"), _defineProperty({}, "".concat(prefixCls, "-scrollbar-show"), canScroll)), | ||
className: (0, _classnames.default)("".concat(prefixCls, "-scrollbar"), (0, _defineProperty2.default)({}, "".concat(prefixCls, "-scrollbar-show"), canScroll)), | ||
style: { | ||
@@ -285,3 +210,3 @@ width: 8, | ||
ref: this.thumbRef, | ||
className: (0, _classnames.default)("".concat(prefixCls, "-scrollbar-thumb"), _defineProperty({}, "".concat(prefixCls, "-scrollbar-thumb-moving"), dragging)), | ||
className: (0, _classnames.default)("".concat(prefixCls, "-scrollbar-thumb"), (0, _defineProperty2.default)({}, "".concat(prefixCls, "-scrollbar-thumb-moving"), dragging)), | ||
style: { | ||
@@ -302,6 +227,4 @@ width: '100%', | ||
}]); | ||
return ScrollBar; | ||
}(React.Component); | ||
exports.default = ScrollBar; |
@@ -8,3 +8,2 @@ "use strict"; | ||
exports.getIndexByStartLoc = getIndexByStartLoc; | ||
/** | ||
@@ -26,19 +25,15 @@ * Get index with specific start index one by one. e.g. | ||
var afterCount = max - start; | ||
var balanceCount = Math.min(beforeCount, afterCount) * 2; // Balance | ||
var balanceCount = Math.min(beforeCount, afterCount) * 2; | ||
// Balance | ||
if (index <= balanceCount) { | ||
var stepIndex = Math.floor(index / 2); | ||
if (index % 2) { | ||
return start + stepIndex + 1; | ||
} | ||
return start - stepIndex; | ||
} // One is out of range | ||
} | ||
// One is out of range | ||
if (beforeCount > afterCount) { | ||
return start - (index - afterCount); | ||
} | ||
return start + (index - beforeCount); | ||
@@ -50,4 +45,2 @@ } | ||
*/ | ||
function findListDiffIndex(originList, targetList, getKey) { | ||
@@ -58,7 +51,5 @@ var originLen = originList.length; | ||
var longList; | ||
if (originLen === 0 && targetLen === 0) { | ||
return null; | ||
} | ||
if (originLen < targetLen) { | ||
@@ -71,7 +62,5 @@ shortList = originList; | ||
} | ||
var notExistKey = { | ||
__EMPTY_ITEM__: true | ||
}; | ||
function getItemKey(item) { | ||
@@ -81,14 +70,10 @@ if (item !== undefined) { | ||
} | ||
return notExistKey; | ||
} // Loop to find diff one | ||
} | ||
// Loop to find diff one | ||
var diffIndex = null; | ||
var multiple = Math.abs(originLen - targetLen) !== 1; | ||
for (var i = 0; i < longList.length; i += 1) { | ||
var shortKey = getItemKey(shortList[i]); | ||
var longKey = getItemKey(longList[i]); | ||
if (shortKey !== longKey) { | ||
@@ -100,3 +85,2 @@ diffIndex = i; | ||
} | ||
return diffIndex === null ? null : { | ||
@@ -103,0 +87,0 @@ index: diffIndex, |
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default; | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -7,19 +8,12 @@ value: true | ||
exports.default = void 0; | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } | ||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } | ||
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")); | ||
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); | ||
// Firefox has low performance of map. | ||
var CacheMap = /*#__PURE__*/function () { | ||
function CacheMap() { | ||
_classCallCheck(this, CacheMap); | ||
(0, _classCallCheck2.default)(this, CacheMap); | ||
this.maps = void 0; | ||
this.maps = Object.create(null); | ||
} | ||
_createClass(CacheMap, [{ | ||
(0, _createClass2.default)(CacheMap, [{ | ||
key: "set", | ||
@@ -35,7 +29,5 @@ value: function set(key, value) { | ||
}]); | ||
return CacheMap; | ||
}(); | ||
var _default = CacheMap; | ||
exports.default = _default; |
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default; | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -7,7 +8,5 @@ value: true | ||
exports.default = void 0; | ||
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); } | ||
var isFF = (typeof navigator === "undefined" ? "undefined" : _typeof(navigator)) === 'object' && /Firefox/i.test(navigator.userAgent); | ||
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof")); | ||
var isFF = (typeof navigator === "undefined" ? "undefined" : (0, _typeof2.default)(navigator)) === 'object' && /Firefox/i.test(navigator.userAgent); | ||
var _default = isFF; | ||
exports.default = _default; |
{ | ||
"name": "rc-virtual-list", | ||
"version": "3.4.10", | ||
"version": "3.4.11", | ||
"description": "React Virtual List Component", | ||
@@ -66,2 +66,3 @@ "engines": { | ||
"dependencies": { | ||
"@babel/runtime": "^7.20.0", | ||
"classnames": "^2.2.6", | ||
@@ -68,0 +69,0 @@ "rc-resize-observer": "^1.0.0", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
96529
6
2441
+ Added@babel/runtime@^7.20.0