rc-virtual-list
Advanced tools
Comparing version 3.11.3 to 3.11.4
@@ -26,3 +26,2 @@ import _extends from "@babel/runtime/helpers/esm/extends"; | ||
if (offsetY !== undefined) { | ||
var _objectSpread2; | ||
// Not set `width` since this will break `sticky: right` | ||
@@ -34,5 +33,5 @@ outerStyle = { | ||
}; | ||
innerStyle = _objectSpread(_objectSpread({}, innerStyle), {}, (_objectSpread2 = { | ||
innerStyle = _objectSpread(_objectSpread({}, innerStyle), {}, _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty({ | ||
transform: "translateY(".concat(offsetY, "px)") | ||
}, _defineProperty(_objectSpread2, rtl ? 'marginRight' : 'marginLeft', -offsetX), _defineProperty(_objectSpread2, "position", 'absolute'), _defineProperty(_objectSpread2, "left", 0), _defineProperty(_objectSpread2, "right", 0), _defineProperty(_objectSpread2, "top", 0), _objectSpread2)); | ||
}, rtl ? 'marginRight' : 'marginLeft', -offsetX), "position", 'absolute'), "left", 0), "right", 0), "top", 0)); | ||
} | ||
@@ -39,0 +38,0 @@ return /*#__PURE__*/React.createElement("div", { |
import * as React from 'react'; | ||
import { Item } from '../Item'; | ||
import { Item } from "../Item"; | ||
export default function useChildren(list, startIndex, endIndex, scrollWidth, setNodeRef, renderFunc, _ref) { | ||
@@ -4,0 +4,0 @@ var getKey = _ref.getKey; |
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray"; | ||
import * as React from 'react'; | ||
import { findListDiffIndex } from '../utils/algorithmUtil'; | ||
import { findListDiffIndex } from "../utils/algorithmUtil"; | ||
export default function useDiffItem(data, getKey, onDiff) { | ||
@@ -16,3 +16,3 @@ var _React$useState = React.useState(data), | ||
if ((diff === null || diff === void 0 ? void 0 : diff.index) !== undefined) { | ||
onDiff === null || onDiff === void 0 ? void 0 : onDiff(diff.index); | ||
onDiff === null || onDiff === void 0 || onDiff(diff.index); | ||
setDiffItem(data[diff.index]); | ||
@@ -19,0 +19,0 @@ } |
import { useRef } from 'react'; | ||
import raf from "rc-util/es/raf"; | ||
import isFF from '../utils/isFirefox'; | ||
import useOriginScroll from './useOriginScroll'; | ||
import isFF from "../utils/isFirefox"; | ||
import useOriginScroll from "./useOriginScroll"; | ||
export default function useFrameWheel(inVirtual, isScrollAtTop, isScrollAtBottom, horizontalScroll, | ||
@@ -12,5 +12,7 @@ /*** | ||
var nextFrameRef = useRef(null); | ||
// Firefox patch | ||
var wheelValueRef = useRef(null); | ||
var isMouseScrollRef = useRef(false); | ||
// Scroll status sync | ||
@@ -22,4 +24,6 @@ var originScroll = useOriginScroll(isScrollAtTop, isScrollAtBottom); | ||
wheelValueRef.current = deltaY; | ||
// Do nothing when scroll at the edge, Skip check when is in scroll | ||
if (originScroll(deltaY)) return; | ||
// Proxy of scroll events | ||
@@ -43,2 +47,3 @@ if (!isFF) { | ||
} | ||
// Check for which direction does wheel do. `sx` means `shift + wheel` | ||
@@ -49,2 +54,3 @@ var wheelDirectionRef = useRef(null); | ||
if (!inVirtual) return; | ||
// Wait for 2 frame to clean direction | ||
@@ -76,2 +82,3 @@ raf.cancel(wheelDirectionCleanRef.current); | ||
} | ||
// A patch for firefox | ||
@@ -78,0 +85,0 @@ function onFireFoxScroll(event) { |
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray"; | ||
import * as React from 'react'; | ||
/** | ||
@@ -19,2 +20,3 @@ * Size info need loop query for the `heights` which will has the perf issue. | ||
var endIndex = key2Index.get(endKey); | ||
// Loop to fill the cache | ||
@@ -21,0 +23,0 @@ if (startIndex === undefined || endIndex === undefined) { |
@@ -6,3 +6,3 @@ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray"; | ||
import raf from "rc-util/es/raf"; | ||
import CacheMap from '../utils/CacheMap'; | ||
import CacheMap from "../utils/CacheMap"; | ||
export default function useHeights(getKey, onItemAdd, onItemRemove) { | ||
@@ -32,2 +32,3 @@ var _React$useState = React.useState(0), | ||
}); | ||
// Always trigger update mark to tell parent that should re-calculate heights when resized | ||
@@ -53,8 +54,9 @@ setUpdatedMark(function (c) { | ||
} | ||
// Instance changed | ||
if (!origin !== !instance) { | ||
if (instance) { | ||
onItemAdd === null || onItemAdd === void 0 ? void 0 : onItemAdd(item); | ||
onItemAdd === null || onItemAdd === void 0 || onItemAdd(item); | ||
} else { | ||
onItemRemove === null || onItemRemove === void 0 ? void 0 : onItemRemove(item); | ||
onItemRemove === null || onItemRemove === void 0 || onItemRemove(item); | ||
} | ||
@@ -61,0 +63,0 @@ } |
@@ -8,4 +8,6 @@ import { useRef } from 'react'; | ||
var elementRef = useRef(null); | ||
// Smooth scroll | ||
var intervalRef = useRef(null); | ||
/* eslint-disable prefer-const */ | ||
@@ -16,12 +18,13 @@ var cleanUpEvents; | ||
var currentY = Math.ceil(e.touches[0].pageY); | ||
var offsetY = touchYRef.current - currentY; | ||
var _offsetY = touchYRef.current - currentY; | ||
touchYRef.current = currentY; | ||
if (callback(offsetY)) { | ||
if (callback(_offsetY)) { | ||
e.preventDefault(); | ||
} | ||
// Smooth interval | ||
clearInterval(intervalRef.current); | ||
intervalRef.current = setInterval(function () { | ||
offsetY *= SMOOTH_PTG; | ||
if (!callback(offsetY, true) || Math.abs(offsetY) <= 0.1) { | ||
_offsetY *= SMOOTH_PTG; | ||
if (!callback(_offsetY, true) || Math.abs(_offsetY) <= 0.1) { | ||
clearInterval(intervalRef.current); | ||
@@ -58,3 +61,3 @@ } | ||
var _listRef$current; | ||
(_listRef$current = listRef.current) === null || _listRef$current === void 0 ? void 0 : _listRef$current.removeEventListener('touchstart', onTouchStart); | ||
(_listRef$current = listRef.current) === null || _listRef$current === void 0 || _listRef$current.removeEventListener('touchstart', onTouchStart); | ||
cleanUpEvents(); | ||
@@ -61,0 +64,0 @@ clearInterval(intervalRef.current); |
@@ -13,2 +13,3 @@ import { useRef } from 'react'; | ||
} | ||
// Pass to ref since global add is in closure | ||
@@ -15,0 +16,0 @@ var scrollPingRef = useRef({ |
@@ -16,2 +16,3 @@ import _typeof from "@babel/runtime/helpers/esm/typeof"; | ||
setSyncState = _React$useState2[1]; | ||
// ========================== Sync Scroll ========================== | ||
@@ -36,5 +37,7 @@ useLayoutEffect(function () { | ||
var targetTop = null; | ||
// Go to next frame if height not exist | ||
if (height) { | ||
var mergedAlign = targetAlign || originAlign; | ||
// Get top & bottom | ||
@@ -52,2 +55,3 @@ var stackTop = 0; | ||
} | ||
// Check if need sync height (visible range has item not record height) | ||
@@ -67,2 +71,3 @@ var leftHeight = mergedAlign === 'top' ? offset : height - offset; | ||
} | ||
// Scroll to | ||
@@ -90,2 +95,3 @@ switch (mergedAlign) { | ||
} | ||
// One more time for sync | ||
@@ -96,2 +102,3 @@ if (targetTop !== syncState.lastTop) { | ||
} | ||
// Trigger next effect | ||
@@ -109,2 +116,3 @@ if (needCollectHeight) { | ||
}, [syncState, containerRef.current]); | ||
// =========================== Scroll To =========================== | ||
@@ -117,2 +125,3 @@ return function (arg) { | ||
} | ||
// Normal scroll logic | ||
@@ -119,0 +128,0 @@ raf.cancel(scrollRef.current); |
@@ -1,2 +0,2 @@ | ||
import List from './List'; | ||
import List from "./List"; | ||
export default List; |
@@ -13,15 +13,15 @@ import _extends from "@babel/runtime/helpers/esm/extends"; | ||
import ResizeObserver from 'rc-resize-observer'; | ||
import Filler from './Filler'; | ||
import ScrollBar from './ScrollBar'; | ||
import useChildren from './hooks/useChildren'; | ||
import useHeights from './hooks/useHeights'; | ||
import useScrollTo from './hooks/useScrollTo'; | ||
import useDiffItem from './hooks/useDiffItem'; | ||
import useFrameWheel from './hooks/useFrameWheel'; | ||
import useMobileTouchMove from './hooks/useMobileTouchMove'; | ||
import useOriginScroll from './hooks/useOriginScroll'; | ||
import Filler from "./Filler"; | ||
import ScrollBar from "./ScrollBar"; | ||
import useChildren from "./hooks/useChildren"; | ||
import useHeights from "./hooks/useHeights"; | ||
import useScrollTo from "./hooks/useScrollTo"; | ||
import useDiffItem from "./hooks/useDiffItem"; | ||
import useFrameWheel from "./hooks/useFrameWheel"; | ||
import useMobileTouchMove from "./hooks/useMobileTouchMove"; | ||
import useOriginScroll from "./hooks/useOriginScroll"; | ||
import useLayoutEffect from "rc-util/es/hooks/useLayoutEffect"; | ||
import { getSpinSize } from './utils/scrollbarUtil'; | ||
import { getSpinSize } from "./utils/scrollbarUtil"; | ||
import { useEvent } from 'rc-util'; | ||
import { useGetSize } from './hooks/useGetSize'; | ||
import { useGetSize } from "./hooks/useGetSize"; | ||
var EMPTY_DATA = []; | ||
@@ -56,2 +56,3 @@ var ScrollStyle = { | ||
restProps = _objectWithoutProperties(props, _excluded); | ||
// ================================= MISC ================================= | ||
@@ -65,3 +66,5 @@ var useVirtual = !!(virtual !== false && height && itemHeight); | ||
var fillerInnerRef = useRef(); | ||
// =============================== Item Key =============================== | ||
var _useState = useState(0), | ||
@@ -85,2 +88,3 @@ _useState2 = _slicedToArray(_useState, 2), | ||
}; | ||
// =============================== Item Key =============================== | ||
@@ -96,2 +100,3 @@ var getKey = React.useCallback(function (item) { | ||
}; | ||
// ================================ Scroll ================================ | ||
@@ -111,2 +116,3 @@ function syncScrollTop(newTop) { | ||
} | ||
// ================================ Legacy ================================ | ||
@@ -123,2 +129,3 @@ // Put ref here since the range is generate by follow | ||
diffItemRef.current = diffItem; | ||
// ================================ Height ================================ | ||
@@ -131,2 +138,3 @@ var _useHeights = useHeights(getKey, null, null), | ||
heightUpdatedMark = _useHeights2[3]; | ||
// ========================== Visible Calculation ========================= | ||
@@ -142,2 +150,3 @@ var _React$useMemo = React.useMemo(function () { | ||
} | ||
// Always use virtual scroll bar in avoid shaking | ||
@@ -159,6 +168,7 @@ if (!inVirtual) { | ||
for (var i = 0; i < dataLen; i += 1) { | ||
var item = mergedData[i]; | ||
var key = getKey(item); | ||
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 | ||
@@ -169,2 +179,3 @@ if (currentItemBottom >= offsetTop && startIndex === undefined) { | ||
} | ||
// Check item bottom in the range. We will render additional one item for motion usage | ||
@@ -176,2 +187,3 @@ if (currentItemBottom > offsetTop + height && endIndex === undefined) { | ||
} | ||
// When scrollTop at the end but data cut to small count will reach this | ||
@@ -186,2 +198,3 @@ if (startIndex === undefined) { | ||
} | ||
// Give cache to improve scroll experience | ||
@@ -202,2 +215,3 @@ endIndex = Math.min(endIndex + 1, mergedData.length - 1); | ||
rangeRef.current.end = end; | ||
// ================================= Size ================================= | ||
@@ -217,2 +231,3 @@ var _React$useState = React.useState({ | ||
}; | ||
// Hack on scrollbar to enable flash call | ||
@@ -227,2 +242,3 @@ var verticalScrollBarRef = useRef(); | ||
}, [size.height, scrollHeight]); | ||
// =============================== In Range =============================== | ||
@@ -243,2 +259,3 @@ var maxScrollHeight = scrollHeight - height; | ||
var originScroll = useOriginScroll(isScrollAtTop, isScrollAtBottom); | ||
// ================================ Scroll ================================ | ||
@@ -255,2 +272,3 @@ var getVirtualScrollInfo = function getVirtualScrollInfo() { | ||
var nextInfo = getVirtualScrollInfo(); | ||
// Trigger when offset changed | ||
@@ -274,2 +292,3 @@ if (lastVirtualScrollInfoRef.current.x !== nextInfo.x || lastVirtualScrollInfoRef.current.y !== nextInfo.y) { | ||
} | ||
// When data size reduce. It may trigger native scroll event back to fit scroll position | ||
@@ -281,4 +300,5 @@ function onFallbackScroll(e) { | ||
} | ||
// Trigger origin onScroll | ||
onScroll === null || onScroll === void 0 ? void 0 : onScroll(e); | ||
onScroll === null || onScroll === void 0 || onScroll(e); | ||
triggerScroll(); | ||
@@ -296,2 +316,3 @@ } | ||
// Horizontal scroll no need sync virtual position | ||
flushSync(function () { | ||
@@ -311,2 +332,3 @@ setOffsetLeft(function (left) { | ||
}); | ||
// Since this added in global,should use ref to keep update | ||
@@ -317,2 +339,3 @@ var _useFrameWheel = useFrameWheel(useVirtual, isScrollAtTop, isScrollAtBottom, !!scrollWidth, onWheelDelta), | ||
onFireFoxScroll = _useFrameWheel2[1]; | ||
// Mobile touch move | ||
@@ -346,2 +369,3 @@ useMobileTouchMove(useVirtual, componentRef, function (deltaY, smoothOffset) { | ||
}, [useVirtual]); | ||
// Sync scroll left | ||
@@ -355,7 +379,8 @@ useLayoutEffect(function () { | ||
}, [size.width, scrollWidth]); | ||
// ================================= Ref ================================== | ||
var delayHideScrollBar = function delayHideScrollBar() { | ||
var _verticalScrollBarRef, _horizontalScrollBarR; | ||
(_verticalScrollBarRef = verticalScrollBarRef.current) === null || _verticalScrollBarRef === void 0 ? void 0 : _verticalScrollBarRef.delayHidden(); | ||
(_horizontalScrollBarR = horizontalScrollBarRef.current) === null || _horizontalScrollBarR === void 0 ? void 0 : _horizontalScrollBarR.delayHidden(); | ||
(_verticalScrollBarRef = verticalScrollBarRef.current) === null || _verticalScrollBarRef === void 0 || _verticalScrollBarRef.delayHidden(); | ||
(_horizontalScrollBarR = horizontalScrollBarRef.current) === null || _horizontalScrollBarR === void 0 || _horizontalScrollBarR.delayHidden(); | ||
}; | ||
@@ -377,2 +402,3 @@ var _scrollTo = useScrollTo(componentRef, mergedData, heights, itemHeight, getKey, function () { | ||
} | ||
// Scroll Y | ||
@@ -386,2 +412,3 @@ _scrollTo(config.top); | ||
}); | ||
// ================================ Effect ================================ | ||
@@ -395,2 +422,3 @@ /** We need told outside that some list not rendered */ | ||
}, [start, end, mergedData]); | ||
// ================================ Extra ================================= | ||
@@ -407,2 +435,3 @@ var getSize = useGetSize(mergedData, getKey, heights, itemHeight); | ||
}); | ||
// ================================ Render ================================ | ||
@@ -464,3 +493,3 @@ var listChildren = useChildren(mergedData, start, end, scrollWidth, setInstanceRef, children, sharedConfig); | ||
thumbStyle: styles === null || styles === void 0 ? void 0 : styles.verticalScrollBarThumb | ||
}), inVirtual && scrollWidth && /*#__PURE__*/React.createElement(ScrollBar, { | ||
}), inVirtual && scrollWidth > size.width && /*#__PURE__*/React.createElement(ScrollBar, { | ||
ref: horizontalScrollBarRef, | ||
@@ -467,0 +496,0 @@ prefixCls: prefixCls, |
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2"; | ||
import * as React from 'react'; | ||
import { RawList } from './List'; | ||
import { RawList } from "./List"; | ||
var List = /*#__PURE__*/React.forwardRef(function (props, ref) { | ||
@@ -5,0 +5,0 @@ return RawList(_objectSpread(_objectSpread({}, props), {}, { |
@@ -12,3 +12,2 @@ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2"; | ||
var ScrollBar = /*#__PURE__*/React.forwardRef(function (props, ref) { | ||
var _classNames; | ||
var prefixCls = props.prefixCls, | ||
@@ -39,5 +38,7 @@ rtl = props.rtl, | ||
var isLTR = !rtl; | ||
// ========================= Refs ========================= | ||
var scrollbarRef = React.useRef(); | ||
var thumbRef = React.useRef(); | ||
// ======================= Visible ======================== | ||
@@ -56,7 +57,7 @@ var _React$useState7 = React.useState(false), | ||
}; | ||
// ======================== Range ========================= | ||
var enableScrollRange = scrollRange - containerSize || 0; | ||
var enableOffsetRange = containerSize - spinSize || 0; | ||
// `scrollWidth` < `clientWidth` means no need to show scrollbar | ||
var canScroll = enableScrollRange > 0; | ||
// ========================= Top ========================== | ||
@@ -70,2 +71,3 @@ var top = React.useMemo(function () { | ||
}, [scrollOffset, enableScrollRange, enableOffsetRange]); | ||
// ====================== Container ======================= | ||
@@ -76,2 +78,3 @@ var onContainerMouseDown = function onContainerMouseDown(e) { | ||
}; | ||
// ======================== Thumb ========================= | ||
@@ -98,3 +101,5 @@ var stateRef = React.useRef({ | ||
}; | ||
// ======================== Effect ======================== | ||
// React make event as passive, but we need to preventDefault | ||
@@ -116,2 +121,3 @@ // Add event on dom directly instead. | ||
}, []); | ||
// Pass to effect | ||
@@ -170,2 +176,3 @@ var enableScrollRangeRef = React.useRef(); | ||
}, [scrollOffset]); | ||
// ====================== Imperative ====================== | ||
@@ -177,2 +184,3 @@ React.useImperativeHandle(ref, function () { | ||
}); | ||
// ======================== Render ======================== | ||
@@ -182,3 +190,3 @@ var scrollbarPrefixCls = "".concat(prefixCls, "-scrollbar"); | ||
position: 'absolute', | ||
visibility: visible && canScroll ? null : 'hidden' | ||
visibility: visible ? null : 'hidden' | ||
}; | ||
@@ -198,2 +206,3 @@ var thumbStyle = { | ||
containerStyle.bottom = 0; | ||
// Thumb | ||
@@ -217,2 +226,3 @@ thumbStyle.height = '100%'; | ||
} | ||
// Thumb | ||
@@ -225,3 +235,3 @@ thumbStyle.width = '100%'; | ||
ref: scrollbarRef, | ||
className: classNames(scrollbarPrefixCls, (_classNames = {}, _defineProperty(_classNames, "".concat(scrollbarPrefixCls, "-horizontal"), horizontal), _defineProperty(_classNames, "".concat(scrollbarPrefixCls, "-vertical"), !horizontal), _defineProperty(_classNames, "".concat(scrollbarPrefixCls, "-visible"), visible), _classNames)), | ||
className: classNames(scrollbarPrefixCls, _defineProperty(_defineProperty(_defineProperty({}, "".concat(scrollbarPrefixCls, "-horizontal"), horizontal), "".concat(scrollbarPrefixCls, "-vertical"), !horizontal), "".concat(scrollbarPrefixCls, "-visible"), visible)), | ||
style: _objectSpread(_objectSpread({}, containerStyle), style), | ||
@@ -228,0 +238,0 @@ onMouseDown: onContainerMouseDown, |
@@ -18,2 +18,3 @@ /** | ||
var balanceCount = Math.min(beforeCount, afterCount) * 2; | ||
// Balance | ||
@@ -27,2 +28,3 @@ if (index <= balanceCount) { | ||
} | ||
// One is out of range | ||
@@ -34,2 +36,3 @@ if (beforeCount > afterCount) { | ||
} | ||
/** | ||
@@ -63,2 +66,3 @@ * We assume that 2 list has only 1 item diff and others keeping the order. | ||
} | ||
// Loop to find diff one | ||
@@ -65,0 +69,0 @@ var diffIndex = null; |
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck"; | ||
import _createClass from "@babel/runtime/helpers/esm/createClass"; | ||
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty"; | ||
// Firefox has low performance of map. | ||
@@ -7,6 +8,6 @@ var CacheMap = /*#__PURE__*/function () { | ||
_classCallCheck(this, CacheMap); | ||
this.maps = void 0; | ||
_defineProperty(this, "maps", void 0); | ||
// Used for cache key | ||
// `useMemo` no need to update if `id` not change | ||
this.id = 0; | ||
_defineProperty(this, "id", 0); | ||
this.maps = Object.create(null); | ||
@@ -13,0 +14,0 @@ } |
@@ -5,3 +5,3 @@ var MIN_SIZE = 20; | ||
var scrollRange = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0; | ||
var baseSize = containerSize / scrollRange * 100; | ||
var baseSize = containerSize / scrollRange * containerSize; | ||
if (isNaN(baseSize)) { | ||
@@ -11,4 +11,3 @@ baseSize = 0; | ||
baseSize = Math.max(baseSize, MIN_SIZE); | ||
baseSize = Math.min(baseSize, containerSize / 2); | ||
return Math.floor(baseSize); | ||
} |
@@ -34,3 +34,2 @@ "use strict"; | ||
if (offsetY !== undefined) { | ||
var _objectSpread2; | ||
// Not set `width` since this will break `sticky: right` | ||
@@ -42,5 +41,5 @@ outerStyle = { | ||
}; | ||
innerStyle = (0, _objectSpread3.default)((0, _objectSpread3.default)({}, innerStyle), {}, (_objectSpread2 = { | ||
innerStyle = (0, _objectSpread3.default)((0, _objectSpread3.default)({}, innerStyle), {}, (0, _defineProperty2.default)((0, _defineProperty2.default)((0, _defineProperty2.default)((0, _defineProperty2.default)((0, _defineProperty2.default)({ | ||
transform: "translateY(".concat(offsetY, "px)") | ||
}, (0, _defineProperty2.default)(_objectSpread2, rtl ? 'marginRight' : 'marginLeft', -offsetX), (0, _defineProperty2.default)(_objectSpread2, "position", 'absolute'), (0, _defineProperty2.default)(_objectSpread2, "left", 0), (0, _defineProperty2.default)(_objectSpread2, "right", 0), (0, _defineProperty2.default)(_objectSpread2, "top", 0), _objectSpread2)); | ||
}, rtl ? 'marginRight' : 'marginLeft', -offsetX), "position", 'absolute'), "left", 0), "right", 0), "top", 0)); | ||
} | ||
@@ -47,0 +46,0 @@ return /*#__PURE__*/React.createElement("div", { |
@@ -24,3 +24,3 @@ "use strict"; | ||
if ((diff === null || diff === void 0 ? void 0 : diff.index) !== undefined) { | ||
onDiff === null || onDiff === void 0 ? void 0 : onDiff(diff.index); | ||
onDiff === null || onDiff === void 0 || onDiff(diff.index); | ||
setDiffItem(data[diff.index]); | ||
@@ -27,0 +27,0 @@ } |
@@ -19,5 +19,7 @@ "use strict"; | ||
var nextFrameRef = (0, _react.useRef)(null); | ||
// Firefox patch | ||
var wheelValueRef = (0, _react.useRef)(null); | ||
var isMouseScrollRef = (0, _react.useRef)(false); | ||
// Scroll status sync | ||
@@ -29,4 +31,6 @@ var originScroll = (0, _useOriginScroll.default)(isScrollAtTop, isScrollAtBottom); | ||
wheelValueRef.current = deltaY; | ||
// Do nothing when scroll at the edge, Skip check when is in scroll | ||
if (originScroll(deltaY)) return; | ||
// Proxy of scroll events | ||
@@ -50,2 +54,3 @@ if (!_isFirefox.default) { | ||
} | ||
// Check for which direction does wheel do. `sx` means `shift + wheel` | ||
@@ -56,2 +61,3 @@ var wheelDirectionRef = (0, _react.useRef)(null); | ||
if (!inVirtual) return; | ||
// Wait for 2 frame to clean direction | ||
@@ -83,2 +89,3 @@ _raf.default.cancel(wheelDirectionCleanRef.current); | ||
} | ||
// A patch for firefox | ||
@@ -85,0 +92,0 @@ function onFireFoxScroll(event) { |
@@ -27,2 +27,3 @@ "use strict"; | ||
var endIndex = key2Index.get(endKey); | ||
// Loop to fill the cache | ||
@@ -29,0 +30,0 @@ if (startIndex === undefined || endIndex === undefined) { |
@@ -39,2 +39,3 @@ "use strict"; | ||
}); | ||
// Always trigger update mark to tell parent that should re-calculate heights when resized | ||
@@ -60,8 +61,9 @@ setUpdatedMark(function (c) { | ||
} | ||
// Instance changed | ||
if (!origin !== !instance) { | ||
if (instance) { | ||
onItemAdd === null || onItemAdd === void 0 ? void 0 : onItemAdd(item); | ||
onItemAdd === null || onItemAdd === void 0 || onItemAdd(item); | ||
} else { | ||
onItemRemove === null || onItemRemove === void 0 ? void 0 : onItemRemove(item); | ||
onItemRemove === null || onItemRemove === void 0 || onItemRemove(item); | ||
} | ||
@@ -68,0 +70,0 @@ } |
@@ -15,4 +15,6 @@ "use strict"; | ||
var elementRef = (0, _react.useRef)(null); | ||
// Smooth scroll | ||
var intervalRef = (0, _react.useRef)(null); | ||
/* eslint-disable prefer-const */ | ||
@@ -23,12 +25,13 @@ var cleanUpEvents; | ||
var currentY = Math.ceil(e.touches[0].pageY); | ||
var offsetY = touchYRef.current - currentY; | ||
var _offsetY = touchYRef.current - currentY; | ||
touchYRef.current = currentY; | ||
if (callback(offsetY)) { | ||
if (callback(_offsetY)) { | ||
e.preventDefault(); | ||
} | ||
// Smooth interval | ||
clearInterval(intervalRef.current); | ||
intervalRef.current = setInterval(function () { | ||
offsetY *= SMOOTH_PTG; | ||
if (!callback(offsetY, true) || Math.abs(offsetY) <= 0.1) { | ||
_offsetY *= SMOOTH_PTG; | ||
if (!callback(_offsetY, true) || Math.abs(_offsetY) <= 0.1) { | ||
clearInterval(intervalRef.current); | ||
@@ -65,3 +68,3 @@ } | ||
var _listRef$current; | ||
(_listRef$current = listRef.current) === null || _listRef$current === void 0 ? void 0 : _listRef$current.removeEventListener('touchstart', onTouchStart); | ||
(_listRef$current = listRef.current) === null || _listRef$current === void 0 || _listRef$current.removeEventListener('touchstart', onTouchStart); | ||
cleanUpEvents(); | ||
@@ -68,0 +71,0 @@ clearInterval(intervalRef.current); |
@@ -19,2 +19,3 @@ "use strict"; | ||
} | ||
// Pass to ref since global add is in closure | ||
@@ -21,0 +22,0 @@ var scrollPingRef = (0, _react.useRef)({ |
@@ -25,2 +25,3 @@ "use strict"; | ||
setSyncState = _React$useState2[1]; | ||
// ========================== Sync Scroll ========================== | ||
@@ -45,5 +46,7 @@ (0, _useLayoutEffect.default)(function () { | ||
var targetTop = null; | ||
// Go to next frame if height not exist | ||
if (height) { | ||
var mergedAlign = targetAlign || originAlign; | ||
// Get top & bottom | ||
@@ -61,2 +64,3 @@ var stackTop = 0; | ||
} | ||
// Check if need sync height (visible range has item not record height) | ||
@@ -76,2 +80,3 @@ var leftHeight = mergedAlign === 'top' ? offset : height - offset; | ||
} | ||
// Scroll to | ||
@@ -99,2 +104,3 @@ switch (mergedAlign) { | ||
} | ||
// One more time for sync | ||
@@ -105,2 +111,3 @@ if (targetTop !== syncState.lastTop) { | ||
} | ||
// Trigger next effect | ||
@@ -118,2 +125,3 @@ if (needCollectHeight) { | ||
}, [syncState, containerRef.current]); | ||
// =========================== Scroll To =========================== | ||
@@ -126,2 +134,3 @@ return function (arg) { | ||
} | ||
// Normal scroll logic | ||
@@ -128,0 +137,0 @@ _raf.default.cancel(scrollRef.current); |
@@ -64,2 +64,3 @@ "use strict"; | ||
restProps = (0, _objectWithoutProperties2.default)(props, _excluded); | ||
// ================================= MISC ================================= | ||
@@ -73,3 +74,5 @@ var useVirtual = !!(virtual !== false && height && itemHeight); | ||
var fillerInnerRef = (0, _react.useRef)(); | ||
// =============================== Item Key =============================== | ||
var _useState = (0, _react.useState)(0), | ||
@@ -93,2 +96,3 @@ _useState2 = (0, _slicedToArray2.default)(_useState, 2), | ||
}; | ||
// =============================== Item Key =============================== | ||
@@ -104,2 +108,3 @@ var getKey = React.useCallback(function (item) { | ||
}; | ||
// ================================ Scroll ================================ | ||
@@ -119,2 +124,3 @@ function syncScrollTop(newTop) { | ||
} | ||
// ================================ Legacy ================================ | ||
@@ -131,2 +137,3 @@ // Put ref here since the range is generate by follow | ||
diffItemRef.current = diffItem; | ||
// ================================ Height ================================ | ||
@@ -139,2 +146,3 @@ var _useHeights = (0, _useHeights3.default)(getKey, null, null), | ||
heightUpdatedMark = _useHeights2[3]; | ||
// ========================== Visible Calculation ========================= | ||
@@ -150,2 +158,3 @@ var _React$useMemo = React.useMemo(function () { | ||
} | ||
// Always use virtual scroll bar in avoid shaking | ||
@@ -167,6 +176,7 @@ if (!inVirtual) { | ||
for (var i = 0; i < dataLen; i += 1) { | ||
var item = mergedData[i]; | ||
var key = getKey(item); | ||
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 | ||
@@ -177,2 +187,3 @@ if (currentItemBottom >= offsetTop && startIndex === undefined) { | ||
} | ||
// Check item bottom in the range. We will render additional one item for motion usage | ||
@@ -184,2 +195,3 @@ if (currentItemBottom > offsetTop + height && endIndex === undefined) { | ||
} | ||
// When scrollTop at the end but data cut to small count will reach this | ||
@@ -194,2 +206,3 @@ if (startIndex === undefined) { | ||
} | ||
// Give cache to improve scroll experience | ||
@@ -210,2 +223,3 @@ endIndex = Math.min(endIndex + 1, mergedData.length - 1); | ||
rangeRef.current.end = end; | ||
// ================================= Size ================================= | ||
@@ -225,2 +239,3 @@ var _React$useState = React.useState({ | ||
}; | ||
// Hack on scrollbar to enable flash call | ||
@@ -235,2 +250,3 @@ var verticalScrollBarRef = (0, _react.useRef)(); | ||
}, [size.height, scrollHeight]); | ||
// =============================== In Range =============================== | ||
@@ -251,2 +267,3 @@ var maxScrollHeight = scrollHeight - height; | ||
var originScroll = (0, _useOriginScroll.default)(isScrollAtTop, isScrollAtBottom); | ||
// ================================ Scroll ================================ | ||
@@ -263,2 +280,3 @@ var getVirtualScrollInfo = function getVirtualScrollInfo() { | ||
var nextInfo = getVirtualScrollInfo(); | ||
// Trigger when offset changed | ||
@@ -282,2 +300,3 @@ if (lastVirtualScrollInfoRef.current.x !== nextInfo.x || lastVirtualScrollInfoRef.current.y !== nextInfo.y) { | ||
} | ||
// When data size reduce. It may trigger native scroll event back to fit scroll position | ||
@@ -289,4 +308,5 @@ function onFallbackScroll(e) { | ||
} | ||
// Trigger origin onScroll | ||
onScroll === null || onScroll === void 0 ? void 0 : onScroll(e); | ||
onScroll === null || onScroll === void 0 || onScroll(e); | ||
triggerScroll(); | ||
@@ -304,2 +324,3 @@ } | ||
// Horizontal scroll no need sync virtual position | ||
(0, _reactDom.flushSync)(function () { | ||
@@ -319,2 +340,3 @@ setOffsetLeft(function (left) { | ||
}); | ||
// Since this added in global,should use ref to keep update | ||
@@ -325,2 +347,3 @@ var _useFrameWheel = (0, _useFrameWheel3.default)(useVirtual, isScrollAtTop, isScrollAtBottom, !!scrollWidth, onWheelDelta), | ||
onFireFoxScroll = _useFrameWheel2[1]; | ||
// Mobile touch move | ||
@@ -354,2 +377,3 @@ (0, _useMobileTouchMove.default)(useVirtual, componentRef, function (deltaY, smoothOffset) { | ||
}, [useVirtual]); | ||
// Sync scroll left | ||
@@ -363,7 +387,8 @@ (0, _useLayoutEffect.default)(function () { | ||
}, [size.width, scrollWidth]); | ||
// ================================= Ref ================================== | ||
var delayHideScrollBar = function delayHideScrollBar() { | ||
var _verticalScrollBarRef, _horizontalScrollBarR; | ||
(_verticalScrollBarRef = verticalScrollBarRef.current) === null || _verticalScrollBarRef === void 0 ? void 0 : _verticalScrollBarRef.delayHidden(); | ||
(_horizontalScrollBarR = horizontalScrollBarRef.current) === null || _horizontalScrollBarR === void 0 ? void 0 : _horizontalScrollBarR.delayHidden(); | ||
(_verticalScrollBarRef = verticalScrollBarRef.current) === null || _verticalScrollBarRef === void 0 || _verticalScrollBarRef.delayHidden(); | ||
(_horizontalScrollBarR = horizontalScrollBarRef.current) === null || _horizontalScrollBarR === void 0 || _horizontalScrollBarR.delayHidden(); | ||
}; | ||
@@ -385,2 +410,3 @@ var _scrollTo = (0, _useScrollTo.default)(componentRef, mergedData, heights, itemHeight, getKey, function () { | ||
} | ||
// Scroll Y | ||
@@ -394,2 +420,3 @@ _scrollTo(config.top); | ||
}); | ||
// ================================ Effect ================================ | ||
@@ -403,2 +430,3 @@ /** We need told outside that some list not rendered */ | ||
}, [start, end, mergedData]); | ||
// ================================ Extra ================================= | ||
@@ -415,2 +443,3 @@ var getSize = (0, _useGetSize.useGetSize)(mergedData, getKey, heights, itemHeight); | ||
}); | ||
// ================================ Render ================================ | ||
@@ -472,3 +501,3 @@ var listChildren = (0, _useChildren.default)(mergedData, start, end, scrollWidth, setInstanceRef, children, sharedConfig); | ||
thumbStyle: styles === null || styles === void 0 ? void 0 : styles.verticalScrollBarThumb | ||
}), inVirtual && scrollWidth && /*#__PURE__*/React.createElement(_ScrollBar.default, { | ||
}), inVirtual && scrollWidth > size.width && /*#__PURE__*/React.createElement(_ScrollBar.default, { | ||
ref: horizontalScrollBarRef, | ||
@@ -475,0 +504,0 @@ prefixCls: prefixCls, |
@@ -20,3 +20,2 @@ "use strict"; | ||
var ScrollBar = /*#__PURE__*/React.forwardRef(function (props, ref) { | ||
var _classNames; | ||
var prefixCls = props.prefixCls, | ||
@@ -47,5 +46,7 @@ rtl = props.rtl, | ||
var isLTR = !rtl; | ||
// ========================= Refs ========================= | ||
var scrollbarRef = React.useRef(); | ||
var thumbRef = React.useRef(); | ||
// ======================= Visible ======================== | ||
@@ -64,7 +65,7 @@ var _React$useState7 = React.useState(false), | ||
}; | ||
// ======================== Range ========================= | ||
var enableScrollRange = scrollRange - containerSize || 0; | ||
var enableOffsetRange = containerSize - spinSize || 0; | ||
// `scrollWidth` < `clientWidth` means no need to show scrollbar | ||
var canScroll = enableScrollRange > 0; | ||
// ========================= Top ========================== | ||
@@ -78,2 +79,3 @@ var top = React.useMemo(function () { | ||
}, [scrollOffset, enableScrollRange, enableOffsetRange]); | ||
// ====================== Container ======================= | ||
@@ -84,2 +86,3 @@ var onContainerMouseDown = function onContainerMouseDown(e) { | ||
}; | ||
// ======================== Thumb ========================= | ||
@@ -106,3 +109,5 @@ var stateRef = React.useRef({ | ||
}; | ||
// ======================== Effect ======================== | ||
// React make event as passive, but we need to preventDefault | ||
@@ -124,2 +129,3 @@ // Add event on dom directly instead. | ||
}, []); | ||
// Pass to effect | ||
@@ -178,2 +184,3 @@ var enableScrollRangeRef = React.useRef(); | ||
}, [scrollOffset]); | ||
// ====================== Imperative ====================== | ||
@@ -185,2 +192,3 @@ React.useImperativeHandle(ref, function () { | ||
}); | ||
// ======================== Render ======================== | ||
@@ -190,3 +198,3 @@ var scrollbarPrefixCls = "".concat(prefixCls, "-scrollbar"); | ||
position: 'absolute', | ||
visibility: visible && canScroll ? null : 'hidden' | ||
visibility: visible ? null : 'hidden' | ||
}; | ||
@@ -206,2 +214,3 @@ var thumbStyle = { | ||
containerStyle.bottom = 0; | ||
// Thumb | ||
@@ -225,2 +234,3 @@ thumbStyle.height = '100%'; | ||
} | ||
// Thumb | ||
@@ -233,3 +243,3 @@ thumbStyle.width = '100%'; | ||
ref: scrollbarRef, | ||
className: (0, _classnames.default)(scrollbarPrefixCls, (_classNames = {}, (0, _defineProperty2.default)(_classNames, "".concat(scrollbarPrefixCls, "-horizontal"), horizontal), (0, _defineProperty2.default)(_classNames, "".concat(scrollbarPrefixCls, "-vertical"), !horizontal), (0, _defineProperty2.default)(_classNames, "".concat(scrollbarPrefixCls, "-visible"), visible), _classNames)), | ||
className: (0, _classnames.default)(scrollbarPrefixCls, (0, _defineProperty2.default)((0, _defineProperty2.default)((0, _defineProperty2.default)({}, "".concat(scrollbarPrefixCls, "-horizontal"), horizontal), "".concat(scrollbarPrefixCls, "-vertical"), !horizontal), "".concat(scrollbarPrefixCls, "-visible"), visible)), | ||
style: (0, _objectSpread2.default)((0, _objectSpread2.default)({}, containerStyle), style), | ||
@@ -236,0 +246,0 @@ onMouseDown: onContainerMouseDown, |
@@ -25,2 +25,3 @@ "use strict"; | ||
var balanceCount = Math.min(beforeCount, afterCount) * 2; | ||
// Balance | ||
@@ -34,2 +35,3 @@ if (index <= balanceCount) { | ||
} | ||
// One is out of range | ||
@@ -41,2 +43,3 @@ if (beforeCount > afterCount) { | ||
} | ||
/** | ||
@@ -70,2 +73,3 @@ * We assume that 2 list has only 1 item diff and others keeping the order. | ||
} | ||
// Loop to find diff one | ||
@@ -72,0 +76,0 @@ var diffIndex = null; |
@@ -10,2 +10,3 @@ "use strict"; | ||
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); | ||
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); | ||
// Firefox has low performance of map. | ||
@@ -15,6 +16,6 @@ var CacheMap = /*#__PURE__*/function () { | ||
(0, _classCallCheck2.default)(this, CacheMap); | ||
this.maps = void 0; | ||
(0, _defineProperty2.default)(this, "maps", void 0); | ||
// Used for cache key | ||
// `useMemo` no need to update if `id` not change | ||
this.id = 0; | ||
(0, _defineProperty2.default)(this, "id", 0); | ||
this.maps = Object.create(null); | ||
@@ -21,0 +22,0 @@ } |
@@ -11,3 +11,3 @@ "use strict"; | ||
var scrollRange = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0; | ||
var baseSize = containerSize / scrollRange * 100; | ||
var baseSize = containerSize / scrollRange * containerSize; | ||
if (isNaN(baseSize)) { | ||
@@ -17,4 +17,3 @@ baseSize = 0; | ||
baseSize = Math.max(baseSize, MIN_SIZE); | ||
baseSize = Math.min(baseSize, containerSize / 2); | ||
return Math.floor(baseSize); | ||
} |
{ | ||
"name": "rc-virtual-list", | ||
"version": "3.11.3", | ||
"version": "3.11.4", | ||
"description": "React Virtual List Component", | ||
@@ -25,4 +25,3 @@ "engines": { | ||
"es", | ||
"dist", | ||
"assets/*.css" | ||
"assets" | ||
], | ||
@@ -38,10 +37,11 @@ "license": "MIT", | ||
"lint": "eslint src/ --ext .tsx,.ts", | ||
"test": "father test", | ||
"test": "rc-test", | ||
"now-build": "npm run build" | ||
}, | ||
"peerDependencies": { | ||
"react": "*", | ||
"react-dom": "*" | ||
"react": ">=16.9.0", | ||
"react-dom": ">=16.9.0" | ||
}, | ||
"devDependencies": { | ||
"@rc-component/father-plugin": "^1.0.2", | ||
"@testing-library/jest-dom": "^5.17.0", | ||
@@ -56,11 +56,12 @@ "@testing-library/react": "^12.1.5", | ||
"cross-env": "^5.2.0", | ||
"dumi": "^1.1.12", | ||
"dumi": "^2.2.17", | ||
"enzyme": "^3.1.0", | ||
"enzyme-adapter-react-16": "^1.0.2", | ||
"enzyme-adapter-react-16": "^1.15.6", | ||
"enzyme-to-json": "^3.1.4", | ||
"eslint": "^7.6.0", | ||
"father": "^2.29.10", | ||
"father": "^4.4.0", | ||
"glob": "^7.1.6", | ||
"np": "^5.0.3", | ||
"rc-animate": "^2.9.1", | ||
"rc-test": "^7.0.15", | ||
"react": "^v16.9.0-alpha.0", | ||
@@ -67,0 +68,0 @@ "react-dom": "^v16.9.0-alpha.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
129546
79
23
3205