@para-ui/core 4.0.21 → 4.0.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. package/Cascader/index.js +2 -2
  2. package/ComboSelect/index.js +1 -1
  3. package/DynamicMultiBox/index.js +1 -1
  4. package/Form/index.js +2 -2
  5. package/FormItem/index.js +2 -2
  6. package/Pagination/index.js +2 -2
  7. package/README.md +4 -0
  8. package/Tree/index.js +2 -2
  9. package/_verture/{index-f59b0bc0.js → index-066d47d4.js} +594 -591
  10. package/_verture/{index-c77ccb98.js → index-b892f976.js} +5 -1
  11. package/index.js +3 -3
  12. package/package.json +1 -1
  13. package/umd/AutoBox.js +2 -2
  14. package/umd/AutoTips.js +4 -4
  15. package/umd/Breadcrumbs.js +4 -4
  16. package/umd/Button.js +4 -4
  17. package/umd/ButtonGroup.js +4 -4
  18. package/umd/Cascader.js +3 -3
  19. package/umd/Checkbox.js +2 -2
  20. package/umd/CheckboxGroup.js +2 -2
  21. package/umd/Collapse.js +2 -2
  22. package/umd/CollapseBox.js +1 -1
  23. package/umd/ComboSelect.js +3 -3
  24. package/umd/CopyText.js +4 -4
  25. package/umd/CycleSelector.js +2 -2
  26. package/umd/DatePicker.js +4 -4
  27. package/umd/Descriptions.js +2 -2
  28. package/umd/Desktop.js +2 -2
  29. package/umd/Drawer.js +2 -2
  30. package/umd/Dropdown.js +2 -2
  31. package/umd/DynamicMultiBox.js +3 -3
  32. package/umd/Form.js +3 -3
  33. package/umd/FormItem.js +3 -3
  34. package/umd/FunctionModal.js +5 -5
  35. package/umd/Help.js +2 -2
  36. package/umd/InputLang.js +4 -4
  37. package/umd/InputNumber.js +2 -2
  38. package/umd/Label.js +2 -2
  39. package/umd/Menu.js +2 -2
  40. package/umd/Modal.js +6 -6
  41. package/umd/MultiBox.js +2 -2
  42. package/umd/Notification.js +1 -1
  43. package/umd/OperateBtn.js +2 -2
  44. package/umd/PageHeader.js +2 -2
  45. package/umd/Pagination.js +2 -2
  46. package/umd/PopConfirm.js +2 -2
  47. package/umd/PopMenu.js +2 -2
  48. package/umd/Popover.js +2 -2
  49. package/umd/Progress.js +1 -1
  50. package/umd/QuickReply.js +2 -2
  51. package/umd/Radio.js +2 -2
  52. package/umd/RadioGroup.js +2 -2
  53. package/umd/Search.js +2 -2
  54. package/umd/Select.js +2 -2
  55. package/umd/SelectInput.js +2 -2
  56. package/umd/Selector.js +2 -2
  57. package/umd/SelectorPicker.js +2 -2
  58. package/umd/SingleBox.js +2 -2
  59. package/umd/Slider.js +2 -2
  60. package/umd/Stepper.js +2 -2
  61. package/umd/Switch.js +2 -2
  62. package/umd/Table.js +2 -2
  63. package/umd/Tabs.js +2 -2
  64. package/umd/Tag.js +2 -2
  65. package/umd/TextEditor.js +17 -17
  66. package/umd/TextField.js +2 -2
  67. package/umd/TimePicker.js +4 -4
  68. package/umd/Title.js +6 -6
  69. package/umd/ToggleButton.js +4 -4
  70. package/umd/Tooltip.js +2 -2
  71. package/umd/Transfer.js +2 -2
  72. package/umd/Tree.js +2 -2
  73. package/umd/Upload.js +2 -2
  74. /package/_verture/{index-fa1ee687.js → index-4b965dd7.js} +0 -0
@@ -65,12 +65,11 @@ function _objectSpread2(e) {
65
65
  function _objectWithoutPropertiesLoose(source, excluded) {
66
66
  if (source == null) return {};
67
67
  var target = {};
68
- var sourceKeys = Object.keys(source);
69
- var key, i;
70
- for (i = 0; i < sourceKeys.length; i++) {
71
- key = sourceKeys[i];
72
- if (excluded.indexOf(key) >= 0) continue;
73
- target[key] = source[key];
68
+ for (var key in source) {
69
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
70
+ if (excluded.indexOf(key) >= 0) continue;
71
+ target[key] = source[key];
72
+ }
74
73
  }
75
74
  return target;
76
75
  }
@@ -1187,24 +1186,22 @@ function useMemo(getValue, condition, shouldUpdate) {
1187
1186
  return cacheRef.current.value;
1188
1187
  }
1189
1188
 
1190
- function fillRef(ref, node) {
1189
+ var fillRef = function fillRef(ref, node) {
1191
1190
  if (typeof ref === 'function') {
1192
1191
  ref(node);
1193
1192
  } else if (_typeof$1(ref) === 'object' && ref && 'current' in ref) {
1194
1193
  ref.current = node;
1195
1194
  }
1196
- }
1195
+ };
1197
1196
 
1198
1197
  /**
1199
1198
  * Merge refs into one ref function to support ref passing.
1200
1199
  */
1201
- function composeRef() {
1200
+ var composeRef = function composeRef() {
1202
1201
  for (var _len = arguments.length, refs = new Array(_len), _key = 0; _key < _len; _key++) {
1203
1202
  refs[_key] = arguments[_key];
1204
1203
  }
1205
- var refList = refs.filter(function (ref) {
1206
- return ref;
1207
- });
1204
+ var refList = refs.filter(Boolean);
1208
1205
  if (refList.length <= 1) {
1209
1206
  return refList[0];
1210
1207
  }
@@ -1213,8 +1210,8 @@ function composeRef() {
1213
1210
  fillRef(ref, node);
1214
1211
  });
1215
1212
  };
1216
- }
1217
- function useComposeRef() {
1213
+ };
1214
+ var useComposeRef = function useComposeRef() {
1218
1215
  for (var _len2 = arguments.length, refs = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
1219
1216
  refs[_key2] = arguments[_key2];
1220
1217
  }
@@ -1225,8 +1222,8 @@ function useComposeRef() {
1225
1222
  return ref !== next[i];
1226
1223
  });
1227
1224
  });
1228
- }
1229
- function supportRef(nodeOrComponent) {
1225
+ };
1226
+ var supportRef = function supportRef(nodeOrComponent) {
1230
1227
  var _type$prototype, _nodeOrComponent$prot;
1231
1228
  var type = reactIs.exports.isMemo(nodeOrComponent) ? nodeOrComponent.type.type : nodeOrComponent.type;
1232
1229
 
@@ -1240,8 +1237,7 @@ function supportRef(nodeOrComponent) {
1240
1237
  return false;
1241
1238
  }
1242
1239
  return true;
1243
- }
1244
- /* eslint-enable */
1240
+ };
1245
1241
 
1246
1242
  var TransBtn = function TransBtn(_ref) {
1247
1243
  var className = _ref.className,
@@ -7004,237 +7000,6 @@ var Filler = /*#__PURE__*/React$4.forwardRef(function (_ref, ref) {
7004
7000
  });
7005
7001
  Filler.displayName = 'Filler';
7006
7002
 
7007
- function getPageXY(e, horizontal) {
7008
- var obj = 'touches' in e ? e.touches[0] : e;
7009
- return obj[horizontal ? 'pageX' : 'pageY'];
7010
- }
7011
- var ScrollBar = /*#__PURE__*/React$4.forwardRef(function (props, ref) {
7012
- var prefixCls = props.prefixCls,
7013
- rtl = props.rtl,
7014
- scrollOffset = props.scrollOffset,
7015
- scrollRange = props.scrollRange,
7016
- onStartMove = props.onStartMove,
7017
- onStopMove = props.onStopMove,
7018
- onScroll = props.onScroll,
7019
- horizontal = props.horizontal,
7020
- spinSize = props.spinSize,
7021
- containerSize = props.containerSize,
7022
- style = props.style,
7023
- propsThumbStyle = props.thumbStyle;
7024
- var _React$useState = React$4.useState(false),
7025
- _React$useState2 = _slicedToArray(_React$useState, 2),
7026
- dragging = _React$useState2[0],
7027
- setDragging = _React$useState2[1];
7028
- var _React$useState3 = React$4.useState(null),
7029
- _React$useState4 = _slicedToArray(_React$useState3, 2),
7030
- pageXY = _React$useState4[0],
7031
- setPageXY = _React$useState4[1];
7032
- var _React$useState5 = React$4.useState(null),
7033
- _React$useState6 = _slicedToArray(_React$useState5, 2),
7034
- startTop = _React$useState6[0],
7035
- setStartTop = _React$useState6[1];
7036
- var isLTR = !rtl;
7037
-
7038
- // ========================= Refs =========================
7039
- var scrollbarRef = React$4.useRef();
7040
- var thumbRef = React$4.useRef();
7041
-
7042
- // ======================= Visible ========================
7043
- var _React$useState7 = React$4.useState(false),
7044
- _React$useState8 = _slicedToArray(_React$useState7, 2),
7045
- visible = _React$useState8[0],
7046
- setVisible = _React$useState8[1];
7047
- var visibleTimeoutRef = React$4.useRef();
7048
- var delayHidden = function delayHidden() {
7049
- clearTimeout(visibleTimeoutRef.current);
7050
- setVisible(true);
7051
- visibleTimeoutRef.current = setTimeout(function () {
7052
- setVisible(false);
7053
- }, 3000);
7054
- };
7055
-
7056
- // ======================== Range =========================
7057
- var enableScrollRange = scrollRange - containerSize || 0;
7058
- var enableOffsetRange = containerSize - spinSize || 0;
7059
-
7060
- // ========================= Top ==========================
7061
- var top = React$4.useMemo(function () {
7062
- if (scrollOffset === 0 || enableScrollRange === 0) {
7063
- return 0;
7064
- }
7065
- var ptg = scrollOffset / enableScrollRange;
7066
- return ptg * enableOffsetRange;
7067
- }, [scrollOffset, enableScrollRange, enableOffsetRange]);
7068
-
7069
- // ====================== Container =======================
7070
- var onContainerMouseDown = function onContainerMouseDown(e) {
7071
- e.stopPropagation();
7072
- e.preventDefault();
7073
- };
7074
-
7075
- // ======================== Thumb =========================
7076
- var stateRef = React$4.useRef({
7077
- top: top,
7078
- dragging: dragging,
7079
- pageY: pageXY,
7080
- startTop: startTop
7081
- });
7082
- stateRef.current = {
7083
- top: top,
7084
- dragging: dragging,
7085
- pageY: pageXY,
7086
- startTop: startTop
7087
- };
7088
- var onThumbMouseDown = function onThumbMouseDown(e) {
7089
- setDragging(true);
7090
- setPageXY(getPageXY(e, horizontal));
7091
- setStartTop(stateRef.current.top);
7092
- onStartMove();
7093
- e.stopPropagation();
7094
- e.preventDefault();
7095
- };
7096
-
7097
- // ======================== Effect ========================
7098
-
7099
- // React make event as passive, but we need to preventDefault
7100
- // Add event on dom directly instead.
7101
- // ref: https://github.com/facebook/react/issues/9809
7102
- React$4.useEffect(function () {
7103
- var onScrollbarTouchStart = function onScrollbarTouchStart(e) {
7104
- e.preventDefault();
7105
- };
7106
- var scrollbarEle = scrollbarRef.current;
7107
- var thumbEle = thumbRef.current;
7108
- scrollbarEle.addEventListener('touchstart', onScrollbarTouchStart);
7109
- thumbEle.addEventListener('touchstart', onThumbMouseDown);
7110
- return function () {
7111
- scrollbarEle.removeEventListener('touchstart', onScrollbarTouchStart);
7112
- thumbEle.removeEventListener('touchstart', onThumbMouseDown);
7113
- };
7114
- }, []);
7115
-
7116
- // Pass to effect
7117
- var enableScrollRangeRef = React$4.useRef();
7118
- enableScrollRangeRef.current = enableScrollRange;
7119
- var enableOffsetRangeRef = React$4.useRef();
7120
- enableOffsetRangeRef.current = enableOffsetRange;
7121
- React$4.useEffect(function () {
7122
- if (dragging) {
7123
- var moveRafId;
7124
- var onMouseMove = function onMouseMove(e) {
7125
- var _stateRef$current = stateRef.current,
7126
- stateDragging = _stateRef$current.dragging,
7127
- statePageY = _stateRef$current.pageY,
7128
- stateStartTop = _stateRef$current.startTop;
7129
- wrapperRaf.cancel(moveRafId);
7130
- if (stateDragging) {
7131
- var offset = getPageXY(e, horizontal) - statePageY;
7132
- var newTop = stateStartTop;
7133
- if (!isLTR && horizontal) {
7134
- newTop -= offset;
7135
- } else {
7136
- newTop += offset;
7137
- }
7138
- var tmpEnableScrollRange = enableScrollRangeRef.current;
7139
- var tmpEnableOffsetRange = enableOffsetRangeRef.current;
7140
- var ptg = tmpEnableOffsetRange ? newTop / tmpEnableOffsetRange : 0;
7141
- var newScrollTop = Math.ceil(ptg * tmpEnableScrollRange);
7142
- newScrollTop = Math.max(newScrollTop, 0);
7143
- newScrollTop = Math.min(newScrollTop, tmpEnableScrollRange);
7144
- moveRafId = wrapperRaf(function () {
7145
- onScroll(newScrollTop, horizontal);
7146
- });
7147
- }
7148
- };
7149
- var onMouseUp = function onMouseUp() {
7150
- setDragging(false);
7151
- onStopMove();
7152
- };
7153
- window.addEventListener('mousemove', onMouseMove);
7154
- window.addEventListener('touchmove', onMouseMove);
7155
- window.addEventListener('mouseup', onMouseUp);
7156
- window.addEventListener('touchend', onMouseUp);
7157
- return function () {
7158
- window.removeEventListener('mousemove', onMouseMove);
7159
- window.removeEventListener('touchmove', onMouseMove);
7160
- window.removeEventListener('mouseup', onMouseUp);
7161
- window.removeEventListener('touchend', onMouseUp);
7162
- wrapperRaf.cancel(moveRafId);
7163
- };
7164
- }
7165
- }, [dragging]);
7166
- React$4.useEffect(function () {
7167
- delayHidden();
7168
- }, [scrollOffset]);
7169
-
7170
- // ====================== Imperative ======================
7171
- React$4.useImperativeHandle(ref, function () {
7172
- return {
7173
- delayHidden: delayHidden
7174
- };
7175
- });
7176
-
7177
- // ======================== Render ========================
7178
- var scrollbarPrefixCls = "".concat(prefixCls, "-scrollbar");
7179
- var containerStyle = {
7180
- position: 'absolute',
7181
- visibility: visible ? null : 'hidden'
7182
- };
7183
- var thumbStyle = {
7184
- position: 'absolute',
7185
- background: 'rgba(0, 0, 0, 0.5)',
7186
- borderRadius: 99,
7187
- cursor: 'pointer',
7188
- userSelect: 'none'
7189
- };
7190
- if (horizontal) {
7191
- // Container
7192
- containerStyle.height = 8;
7193
- containerStyle.left = 0;
7194
- containerStyle.right = 0;
7195
- containerStyle.bottom = 0;
7196
-
7197
- // Thumb
7198
- thumbStyle.height = '100%';
7199
- thumbStyle.width = spinSize;
7200
- if (isLTR) {
7201
- thumbStyle.left = top;
7202
- } else {
7203
- thumbStyle.right = top;
7204
- }
7205
- } else {
7206
- // Container
7207
- containerStyle.width = 8;
7208
- containerStyle.top = 0;
7209
- containerStyle.bottom = 0;
7210
- if (isLTR) {
7211
- containerStyle.right = 0;
7212
- } else {
7213
- containerStyle.left = 0;
7214
- }
7215
-
7216
- // Thumb
7217
- thumbStyle.width = '100%';
7218
- thumbStyle.height = spinSize;
7219
- thumbStyle.top = top;
7220
- }
7221
- return /*#__PURE__*/React$4.createElement("div", {
7222
- ref: scrollbarRef,
7223
- className: classNames(scrollbarPrefixCls, _defineProperty(_defineProperty(_defineProperty({}, "".concat(scrollbarPrefixCls, "-horizontal"), horizontal), "".concat(scrollbarPrefixCls, "-vertical"), !horizontal), "".concat(scrollbarPrefixCls, "-visible"), visible)),
7224
- style: _objectSpread2(_objectSpread2({}, containerStyle), style),
7225
- onMouseDown: onContainerMouseDown,
7226
- onMouseMove: delayHidden
7227
- }, /*#__PURE__*/React$4.createElement("div", {
7228
- ref: thumbRef,
7229
- className: classNames("".concat(scrollbarPrefixCls, "-thumb"), _defineProperty({}, "".concat(scrollbarPrefixCls, "-thumb-moving"), dragging)),
7230
- style: _objectSpread2(_objectSpread2({}, thumbStyle), propsThumbStyle),
7231
- onMouseDown: onThumbMouseDown
7232
- }));
7233
- });
7234
- if (process.env.NODE_ENV !== 'production') {
7235
- ScrollBar.displayName = 'ScrollBar';
7236
- }
7237
-
7238
7003
  function Item(_ref) {
7239
7004
  var children = _ref.children,
7240
7005
  setRef = _ref.setRef;
@@ -7265,228 +7030,6 @@ function useChildren(list, startIndex, endIndex, scrollWidth, setNodeRef, render
7265
7030
  });
7266
7031
  }
7267
7032
 
7268
- // Firefox has low performance of map.
7269
- var CacheMap = /*#__PURE__*/function () {
7270
- function CacheMap() {
7271
- _classCallCheck(this, CacheMap);
7272
- _defineProperty(this, "maps", void 0);
7273
- // Used for cache key
7274
- // `useMemo` no need to update if `id` not change
7275
- _defineProperty(this, "id", 0);
7276
- this.maps = Object.create(null);
7277
- }
7278
- _createClass(CacheMap, [{
7279
- key: "set",
7280
- value: function set(key, value) {
7281
- this.maps[key] = value;
7282
- this.id += 1;
7283
- }
7284
- }, {
7285
- key: "get",
7286
- value: function get(key) {
7287
- return this.maps[key];
7288
- }
7289
- }]);
7290
- return CacheMap;
7291
- }();
7292
-
7293
- function useHeights(getKey, onItemAdd, onItemRemove) {
7294
- var _React$useState = React$4.useState(0),
7295
- _React$useState2 = _slicedToArray(_React$useState, 2),
7296
- updatedMark = _React$useState2[0],
7297
- setUpdatedMark = _React$useState2[1];
7298
- var instanceRef = useRef(new Map());
7299
- var heightsRef = useRef(new CacheMap());
7300
- var collectRafRef = useRef();
7301
- function cancelRaf() {
7302
- wrapperRaf.cancel(collectRafRef.current);
7303
- }
7304
- function collectHeight() {
7305
- var sync = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
7306
- cancelRaf();
7307
- var doCollect = function doCollect() {
7308
- instanceRef.current.forEach(function (element, key) {
7309
- if (element && element.offsetParent) {
7310
- var htmlElement = findDOMNode(element);
7311
- var offsetHeight = htmlElement.offsetHeight;
7312
- if (heightsRef.current.get(key) !== offsetHeight) {
7313
- heightsRef.current.set(key, htmlElement.offsetHeight);
7314
- }
7315
- }
7316
- });
7317
-
7318
- // Always trigger update mark to tell parent that should re-calculate heights when resized
7319
- setUpdatedMark(function (c) {
7320
- return c + 1;
7321
- });
7322
- };
7323
- if (sync) {
7324
- doCollect();
7325
- } else {
7326
- collectRafRef.current = wrapperRaf(doCollect);
7327
- }
7328
- }
7329
- function setInstanceRef(item, instance) {
7330
- var key = getKey(item);
7331
- var origin = instanceRef.current.get(key);
7332
- if (instance) {
7333
- instanceRef.current.set(key, instance);
7334
- collectHeight();
7335
- } else {
7336
- instanceRef.current.delete(key);
7337
- }
7338
-
7339
- // Instance changed
7340
- if (!origin !== !instance) {
7341
- if (instance) {
7342
- onItemAdd === null || onItemAdd === void 0 || onItemAdd(item);
7343
- } else {
7344
- onItemRemove === null || onItemRemove === void 0 || onItemRemove(item);
7345
- }
7346
- }
7347
- }
7348
- useEffect(function () {
7349
- return cancelRaf;
7350
- }, []);
7351
- return [setInstanceRef, collectHeight, heightsRef.current, updatedMark];
7352
- }
7353
-
7354
- var MAX_TIMES = 10;
7355
- function useScrollTo(containerRef, data, heights, itemHeight, getKey, collectHeight, syncScrollTop, triggerFlash) {
7356
- var scrollRef = React$4.useRef();
7357
- var _React$useState = React$4.useState(null),
7358
- _React$useState2 = _slicedToArray(_React$useState, 2),
7359
- syncState = _React$useState2[0],
7360
- setSyncState = _React$useState2[1];
7361
-
7362
- // ========================== Sync Scroll ==========================
7363
- useLayoutEffect$3(function () {
7364
- if (syncState && syncState.times < MAX_TIMES) {
7365
- // Never reach
7366
- if (!containerRef.current) {
7367
- setSyncState(function (ori) {
7368
- return _objectSpread2({}, ori);
7369
- });
7370
- return;
7371
- }
7372
- collectHeight();
7373
- var targetAlign = syncState.targetAlign,
7374
- originAlign = syncState.originAlign,
7375
- index = syncState.index,
7376
- offset = syncState.offset;
7377
- var height = containerRef.current.clientHeight;
7378
- var needCollectHeight = false;
7379
- var newTargetAlign = targetAlign;
7380
- var targetTop = null;
7381
-
7382
- // Go to next frame if height not exist
7383
- if (height) {
7384
- var mergedAlign = targetAlign || originAlign;
7385
-
7386
- // Get top & bottom
7387
- var stackTop = 0;
7388
- var itemTop = 0;
7389
- var itemBottom = 0;
7390
- var maxLen = Math.min(data.length - 1, index);
7391
- for (var i = 0; i <= maxLen; i += 1) {
7392
- var key = getKey(data[i]);
7393
- itemTop = stackTop;
7394
- var cacheHeight = heights.get(key);
7395
- itemBottom = itemTop + (cacheHeight === undefined ? itemHeight : cacheHeight);
7396
- stackTop = itemBottom;
7397
- }
7398
-
7399
- // Check if need sync height (visible range has item not record height)
7400
- var leftHeight = mergedAlign === 'top' ? offset : height - offset;
7401
- for (var _i = maxLen; _i >= 0; _i -= 1) {
7402
- var _key = getKey(data[_i]);
7403
- var _cacheHeight = heights.get(_key);
7404
- if (_cacheHeight === undefined) {
7405
- needCollectHeight = true;
7406
- break;
7407
- }
7408
- leftHeight -= _cacheHeight;
7409
- if (leftHeight <= 0) {
7410
- break;
7411
- }
7412
- }
7413
-
7414
- // Scroll to
7415
- switch (mergedAlign) {
7416
- case 'top':
7417
- targetTop = itemTop - offset;
7418
- break;
7419
- case 'bottom':
7420
- targetTop = itemBottom - height + offset;
7421
- break;
7422
- default:
7423
- {
7424
- var scrollTop = containerRef.current.scrollTop;
7425
- var scrollBottom = scrollTop + height;
7426
- if (itemTop < scrollTop) {
7427
- newTargetAlign = 'top';
7428
- } else if (itemBottom > scrollBottom) {
7429
- newTargetAlign = 'bottom';
7430
- }
7431
- }
7432
- }
7433
- if (targetTop !== null) {
7434
- syncScrollTop(targetTop);
7435
- }
7436
-
7437
- // One more time for sync
7438
- if (targetTop !== syncState.lastTop) {
7439
- needCollectHeight = true;
7440
- }
7441
- }
7442
-
7443
- // Trigger next effect
7444
- if (needCollectHeight) {
7445
- setSyncState(_objectSpread2(_objectSpread2({}, syncState), {}, {
7446
- times: syncState.times + 1,
7447
- targetAlign: newTargetAlign,
7448
- lastTop: targetTop
7449
- }));
7450
- }
7451
- } else if (process.env.NODE_ENV !== 'production' && (syncState === null || syncState === void 0 ? void 0 : syncState.times) === MAX_TIMES) {
7452
- warningOnce(false, 'Seems `scrollTo` with `rc-virtual-list` reach the max limitation. Please fire issue for us. Thanks.');
7453
- }
7454
- }, [syncState, containerRef.current]);
7455
-
7456
- // =========================== Scroll To ===========================
7457
- return function (arg) {
7458
- // When not argument provided, we think dev may want to show the scrollbar
7459
- if (arg === null || arg === undefined) {
7460
- triggerFlash();
7461
- return;
7462
- }
7463
-
7464
- // Normal scroll logic
7465
- wrapperRaf.cancel(scrollRef.current);
7466
- if (typeof arg === 'number') {
7467
- syncScrollTop(arg);
7468
- } else if (arg && _typeof$1(arg) === 'object') {
7469
- var index;
7470
- var align = arg.align;
7471
- if ('index' in arg) {
7472
- index = arg.index;
7473
- } else {
7474
- index = data.findIndex(function (item) {
7475
- return getKey(item) === arg.key;
7476
- });
7477
- }
7478
- var _arg$offset = arg.offset,
7479
- offset = _arg$offset === void 0 ? 0 : _arg$offset;
7480
- setSyncState({
7481
- times: 0,
7482
- index: index,
7483
- offset: offset,
7484
- originAlign: align
7485
- });
7486
- }
7487
- };
7488
- }
7489
-
7490
7033
  /**
7491
7034
  * Get index with specific start index one by one. e.g.
7492
7035
  * min: 3, max: 9, start: 6
@@ -7689,67 +7232,566 @@ onWheelDelta) {
7689
7232
  return [onWheel, onFireFoxScroll];
7690
7233
  }
7691
7234
 
7692
- var SMOOTH_PTG = 14 / 15;
7693
- function useMobileTouchMove(inVirtual, listRef, callback) {
7694
- var touchedRef = useRef(false);
7695
- var touchYRef = useRef(0);
7696
- var elementRef = useRef(null);
7697
-
7698
- // Smooth scroll
7699
- var intervalRef = useRef(null);
7700
-
7701
- /* eslint-disable prefer-const */
7702
- var cleanUpEvents;
7703
- var onTouchMove = function onTouchMove(e) {
7704
- if (touchedRef.current) {
7705
- var currentY = Math.ceil(e.touches[0].pageY);
7706
- var _offsetY = touchYRef.current - currentY;
7707
- touchYRef.current = currentY;
7708
- if (callback(_offsetY)) {
7709
- e.preventDefault();
7710
- }
7235
+ /**
7236
+ * Size info need loop query for the `heights` which will has the perf issue.
7237
+ * Let cache result for each render phase.
7238
+ */
7239
+ function useGetSize(mergedData, getKey, heights, itemHeight) {
7240
+ var _React$useMemo = React$4.useMemo(function () {
7241
+ return [new Map(), []];
7242
+ }, [mergedData, heights.id, itemHeight]),
7243
+ _React$useMemo2 = _slicedToArray(_React$useMemo, 2),
7244
+ key2Index = _React$useMemo2[0],
7245
+ bottomList = _React$useMemo2[1];
7246
+ var getSize = function getSize(startKey) {
7247
+ var endKey = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : startKey;
7248
+ // Get from cache first
7249
+ var startIndex = key2Index.get(startKey);
7250
+ var endIndex = key2Index.get(endKey);
7711
7251
 
7712
- // Smooth interval
7713
- clearInterval(intervalRef.current);
7714
- intervalRef.current = setInterval(function () {
7715
- _offsetY *= SMOOTH_PTG;
7716
- if (!callback(_offsetY, true) || Math.abs(_offsetY) <= 0.1) {
7717
- clearInterval(intervalRef.current);
7718
- }
7719
- }, 16);
7720
- }
7721
- };
7252
+ // Loop to fill the cache
7253
+ if (startIndex === undefined || endIndex === undefined) {
7254
+ var dataLen = mergedData.length;
7255
+ for (var i = bottomList.length; i < dataLen; i += 1) {
7256
+ var _heights$get;
7257
+ var item = mergedData[i];
7258
+ var key = getKey(item);
7259
+ key2Index.set(key, i);
7260
+ var cacheHeight = (_heights$get = heights.get(key)) !== null && _heights$get !== void 0 ? _heights$get : itemHeight;
7261
+ bottomList[i] = (bottomList[i - 1] || 0) + cacheHeight;
7262
+ if (key === startKey) {
7263
+ startIndex = i;
7264
+ }
7265
+ if (key === endKey) {
7266
+ endIndex = i;
7267
+ }
7268
+ if (startIndex !== undefined && endIndex !== undefined) {
7269
+ break;
7270
+ }
7271
+ }
7272
+ }
7273
+ return {
7274
+ top: bottomList[startIndex - 1] || 0,
7275
+ bottom: bottomList[endIndex]
7276
+ };
7277
+ };
7278
+ return getSize;
7279
+ }
7280
+
7281
+ // Firefox has low performance of map.
7282
+ var CacheMap = /*#__PURE__*/function () {
7283
+ function CacheMap() {
7284
+ _classCallCheck(this, CacheMap);
7285
+ _defineProperty(this, "maps", void 0);
7286
+ // Used for cache key
7287
+ // `useMemo` no need to update if `id` not change
7288
+ _defineProperty(this, "id", 0);
7289
+ this.maps = Object.create(null);
7290
+ }
7291
+ _createClass(CacheMap, [{
7292
+ key: "set",
7293
+ value: function set(key, value) {
7294
+ this.maps[key] = value;
7295
+ this.id += 1;
7296
+ }
7297
+ }, {
7298
+ key: "get",
7299
+ value: function get(key) {
7300
+ return this.maps[key];
7301
+ }
7302
+ }]);
7303
+ return CacheMap;
7304
+ }();
7305
+
7306
+ function useHeights(getKey, onItemAdd, onItemRemove) {
7307
+ var _React$useState = React$4.useState(0),
7308
+ _React$useState2 = _slicedToArray(_React$useState, 2),
7309
+ updatedMark = _React$useState2[0],
7310
+ setUpdatedMark = _React$useState2[1];
7311
+ var instanceRef = useRef(new Map());
7312
+ var heightsRef = useRef(new CacheMap());
7313
+ var collectRafRef = useRef();
7314
+ function cancelRaf() {
7315
+ wrapperRaf.cancel(collectRafRef.current);
7316
+ }
7317
+ function collectHeight() {
7318
+ var sync = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
7319
+ cancelRaf();
7320
+ var doCollect = function doCollect() {
7321
+ instanceRef.current.forEach(function (element, key) {
7322
+ if (element && element.offsetParent) {
7323
+ var htmlElement = findDOMNode(element);
7324
+ var offsetHeight = htmlElement.offsetHeight;
7325
+ if (heightsRef.current.get(key) !== offsetHeight) {
7326
+ heightsRef.current.set(key, htmlElement.offsetHeight);
7327
+ }
7328
+ }
7329
+ });
7330
+
7331
+ // Always trigger update mark to tell parent that should re-calculate heights when resized
7332
+ setUpdatedMark(function (c) {
7333
+ return c + 1;
7334
+ });
7335
+ };
7336
+ if (sync) {
7337
+ doCollect();
7338
+ } else {
7339
+ collectRafRef.current = wrapperRaf(doCollect);
7340
+ }
7341
+ }
7342
+ function setInstanceRef(item, instance) {
7343
+ var key = getKey(item);
7344
+ var origin = instanceRef.current.get(key);
7345
+ if (instance) {
7346
+ instanceRef.current.set(key, instance);
7347
+ collectHeight();
7348
+ } else {
7349
+ instanceRef.current.delete(key);
7350
+ }
7351
+
7352
+ // Instance changed
7353
+ if (!origin !== !instance) {
7354
+ if (instance) {
7355
+ onItemAdd === null || onItemAdd === void 0 || onItemAdd(item);
7356
+ } else {
7357
+ onItemRemove === null || onItemRemove === void 0 || onItemRemove(item);
7358
+ }
7359
+ }
7360
+ }
7361
+ useEffect(function () {
7362
+ return cancelRaf;
7363
+ }, []);
7364
+ return [setInstanceRef, collectHeight, heightsRef.current, updatedMark];
7365
+ }
7366
+
7367
+ var SMOOTH_PTG = 14 / 15;
7368
+ function useMobileTouchMove(inVirtual, listRef, callback) {
7369
+ var touchedRef = useRef(false);
7370
+ var touchYRef = useRef(0);
7371
+ var elementRef = useRef(null);
7372
+
7373
+ // Smooth scroll
7374
+ var intervalRef = useRef(null);
7375
+
7376
+ /* eslint-disable prefer-const */
7377
+ var cleanUpEvents;
7378
+ var onTouchMove = function onTouchMove(e) {
7379
+ if (touchedRef.current) {
7380
+ var currentY = Math.ceil(e.touches[0].pageY);
7381
+ var _offsetY = touchYRef.current - currentY;
7382
+ touchYRef.current = currentY;
7383
+ if (callback(_offsetY)) {
7384
+ e.preventDefault();
7385
+ }
7386
+
7387
+ // Smooth interval
7388
+ clearInterval(intervalRef.current);
7389
+ intervalRef.current = setInterval(function () {
7390
+ _offsetY *= SMOOTH_PTG;
7391
+ if (!callback(_offsetY, true) || Math.abs(_offsetY) <= 0.1) {
7392
+ clearInterval(intervalRef.current);
7393
+ }
7394
+ }, 16);
7395
+ }
7396
+ };
7722
7397
  var onTouchEnd = function onTouchEnd() {
7723
7398
  touchedRef.current = false;
7724
7399
  cleanUpEvents();
7725
7400
  };
7726
- var onTouchStart = function onTouchStart(e) {
7727
- cleanUpEvents();
7728
- if (e.touches.length === 1 && !touchedRef.current) {
7729
- touchedRef.current = true;
7730
- touchYRef.current = Math.ceil(e.touches[0].pageY);
7731
- elementRef.current = e.target;
7732
- elementRef.current.addEventListener('touchmove', onTouchMove);
7733
- elementRef.current.addEventListener('touchend', onTouchEnd);
7734
- }
7401
+ var onTouchStart = function onTouchStart(e) {
7402
+ cleanUpEvents();
7403
+ if (e.touches.length === 1 && !touchedRef.current) {
7404
+ touchedRef.current = true;
7405
+ touchYRef.current = Math.ceil(e.touches[0].pageY);
7406
+ elementRef.current = e.target;
7407
+ elementRef.current.addEventListener('touchmove', onTouchMove);
7408
+ elementRef.current.addEventListener('touchend', onTouchEnd);
7409
+ }
7410
+ };
7411
+ cleanUpEvents = function cleanUpEvents() {
7412
+ if (elementRef.current) {
7413
+ elementRef.current.removeEventListener('touchmove', onTouchMove);
7414
+ elementRef.current.removeEventListener('touchend', onTouchEnd);
7415
+ }
7416
+ };
7417
+ useLayoutEffect$3(function () {
7418
+ if (inVirtual) {
7419
+ listRef.current.addEventListener('touchstart', onTouchStart);
7420
+ }
7421
+ return function () {
7422
+ var _listRef$current;
7423
+ (_listRef$current = listRef.current) === null || _listRef$current === void 0 || _listRef$current.removeEventListener('touchstart', onTouchStart);
7424
+ cleanUpEvents();
7425
+ clearInterval(intervalRef.current);
7426
+ };
7427
+ }, [inVirtual]);
7428
+ }
7429
+
7430
+ var MAX_TIMES = 10;
7431
+ function useScrollTo(containerRef, data, heights, itemHeight, getKey, collectHeight, syncScrollTop, triggerFlash) {
7432
+ var scrollRef = React$4.useRef();
7433
+ var _React$useState = React$4.useState(null),
7434
+ _React$useState2 = _slicedToArray(_React$useState, 2),
7435
+ syncState = _React$useState2[0],
7436
+ setSyncState = _React$useState2[1];
7437
+
7438
+ // ========================== Sync Scroll ==========================
7439
+ useLayoutEffect$3(function () {
7440
+ if (syncState && syncState.times < MAX_TIMES) {
7441
+ // Never reach
7442
+ if (!containerRef.current) {
7443
+ setSyncState(function (ori) {
7444
+ return _objectSpread2({}, ori);
7445
+ });
7446
+ return;
7447
+ }
7448
+ collectHeight();
7449
+ var targetAlign = syncState.targetAlign,
7450
+ originAlign = syncState.originAlign,
7451
+ index = syncState.index,
7452
+ offset = syncState.offset;
7453
+ var height = containerRef.current.clientHeight;
7454
+ var needCollectHeight = false;
7455
+ var newTargetAlign = targetAlign;
7456
+ var targetTop = null;
7457
+
7458
+ // Go to next frame if height not exist
7459
+ if (height) {
7460
+ var mergedAlign = targetAlign || originAlign;
7461
+
7462
+ // Get top & bottom
7463
+ var stackTop = 0;
7464
+ var itemTop = 0;
7465
+ var itemBottom = 0;
7466
+ var maxLen = Math.min(data.length - 1, index);
7467
+ for (var i = 0; i <= maxLen; i += 1) {
7468
+ var key = getKey(data[i]);
7469
+ itemTop = stackTop;
7470
+ var cacheHeight = heights.get(key);
7471
+ itemBottom = itemTop + (cacheHeight === undefined ? itemHeight : cacheHeight);
7472
+ stackTop = itemBottom;
7473
+ }
7474
+
7475
+ // Check if need sync height (visible range has item not record height)
7476
+ var leftHeight = mergedAlign === 'top' ? offset : height - offset;
7477
+ for (var _i = maxLen; _i >= 0; _i -= 1) {
7478
+ var _key = getKey(data[_i]);
7479
+ var _cacheHeight = heights.get(_key);
7480
+ if (_cacheHeight === undefined) {
7481
+ needCollectHeight = true;
7482
+ break;
7483
+ }
7484
+ leftHeight -= _cacheHeight;
7485
+ if (leftHeight <= 0) {
7486
+ break;
7487
+ }
7488
+ }
7489
+
7490
+ // Scroll to
7491
+ switch (mergedAlign) {
7492
+ case 'top':
7493
+ targetTop = itemTop - offset;
7494
+ break;
7495
+ case 'bottom':
7496
+ targetTop = itemBottom - height + offset;
7497
+ break;
7498
+ default:
7499
+ {
7500
+ var scrollTop = containerRef.current.scrollTop;
7501
+ var scrollBottom = scrollTop + height;
7502
+ if (itemTop < scrollTop) {
7503
+ newTargetAlign = 'top';
7504
+ } else if (itemBottom > scrollBottom) {
7505
+ newTargetAlign = 'bottom';
7506
+ }
7507
+ }
7508
+ }
7509
+ if (targetTop !== null) {
7510
+ syncScrollTop(targetTop);
7511
+ }
7512
+
7513
+ // One more time for sync
7514
+ if (targetTop !== syncState.lastTop) {
7515
+ needCollectHeight = true;
7516
+ }
7517
+ }
7518
+
7519
+ // Trigger next effect
7520
+ if (needCollectHeight) {
7521
+ setSyncState(_objectSpread2(_objectSpread2({}, syncState), {}, {
7522
+ times: syncState.times + 1,
7523
+ targetAlign: newTargetAlign,
7524
+ lastTop: targetTop
7525
+ }));
7526
+ }
7527
+ } else if (process.env.NODE_ENV !== 'production' && (syncState === null || syncState === void 0 ? void 0 : syncState.times) === MAX_TIMES) {
7528
+ warningOnce(false, 'Seems `scrollTo` with `rc-virtual-list` reach the max limitation. Please fire issue for us. Thanks.');
7529
+ }
7530
+ }, [syncState, containerRef.current]);
7531
+
7532
+ // =========================== Scroll To ===========================
7533
+ return function (arg) {
7534
+ // When not argument provided, we think dev may want to show the scrollbar
7535
+ if (arg === null || arg === undefined) {
7536
+ triggerFlash();
7537
+ return;
7538
+ }
7539
+
7540
+ // Normal scroll logic
7541
+ wrapperRaf.cancel(scrollRef.current);
7542
+ if (typeof arg === 'number') {
7543
+ syncScrollTop(arg);
7544
+ } else if (arg && _typeof$1(arg) === 'object') {
7545
+ var index;
7546
+ var align = arg.align;
7547
+ if ('index' in arg) {
7548
+ index = arg.index;
7549
+ } else {
7550
+ index = data.findIndex(function (item) {
7551
+ return getKey(item) === arg.key;
7552
+ });
7553
+ }
7554
+ var _arg$offset = arg.offset,
7555
+ offset = _arg$offset === void 0 ? 0 : _arg$offset;
7556
+ setSyncState({
7557
+ times: 0,
7558
+ index: index,
7559
+ offset: offset,
7560
+ originAlign: align
7561
+ });
7562
+ }
7563
+ };
7564
+ }
7565
+
7566
+ function getPageXY(e, horizontal) {
7567
+ var obj = 'touches' in e ? e.touches[0] : e;
7568
+ return obj[horizontal ? 'pageX' : 'pageY'];
7569
+ }
7570
+ var ScrollBar = /*#__PURE__*/React$4.forwardRef(function (props, ref) {
7571
+ var prefixCls = props.prefixCls,
7572
+ rtl = props.rtl,
7573
+ scrollOffset = props.scrollOffset,
7574
+ scrollRange = props.scrollRange,
7575
+ onStartMove = props.onStartMove,
7576
+ onStopMove = props.onStopMove,
7577
+ onScroll = props.onScroll,
7578
+ horizontal = props.horizontal,
7579
+ spinSize = props.spinSize,
7580
+ containerSize = props.containerSize,
7581
+ style = props.style,
7582
+ propsThumbStyle = props.thumbStyle;
7583
+ var _React$useState = React$4.useState(false),
7584
+ _React$useState2 = _slicedToArray(_React$useState, 2),
7585
+ dragging = _React$useState2[0],
7586
+ setDragging = _React$useState2[1];
7587
+ var _React$useState3 = React$4.useState(null),
7588
+ _React$useState4 = _slicedToArray(_React$useState3, 2),
7589
+ pageXY = _React$useState4[0],
7590
+ setPageXY = _React$useState4[1];
7591
+ var _React$useState5 = React$4.useState(null),
7592
+ _React$useState6 = _slicedToArray(_React$useState5, 2),
7593
+ startTop = _React$useState6[0],
7594
+ setStartTop = _React$useState6[1];
7595
+ var isLTR = !rtl;
7596
+
7597
+ // ========================= Refs =========================
7598
+ var scrollbarRef = React$4.useRef();
7599
+ var thumbRef = React$4.useRef();
7600
+
7601
+ // ======================= Visible ========================
7602
+ var _React$useState7 = React$4.useState(false),
7603
+ _React$useState8 = _slicedToArray(_React$useState7, 2),
7604
+ visible = _React$useState8[0],
7605
+ setVisible = _React$useState8[1];
7606
+ var visibleTimeoutRef = React$4.useRef();
7607
+ var delayHidden = function delayHidden() {
7608
+ clearTimeout(visibleTimeoutRef.current);
7609
+ setVisible(true);
7610
+ visibleTimeoutRef.current = setTimeout(function () {
7611
+ setVisible(false);
7612
+ }, 3000);
7613
+ };
7614
+
7615
+ // ======================== Range =========================
7616
+ var enableScrollRange = scrollRange - containerSize || 0;
7617
+ var enableOffsetRange = containerSize - spinSize || 0;
7618
+
7619
+ // ========================= Top ==========================
7620
+ var top = React$4.useMemo(function () {
7621
+ if (scrollOffset === 0 || enableScrollRange === 0) {
7622
+ return 0;
7623
+ }
7624
+ var ptg = scrollOffset / enableScrollRange;
7625
+ return ptg * enableOffsetRange;
7626
+ }, [scrollOffset, enableScrollRange, enableOffsetRange]);
7627
+
7628
+ // ====================== Container =======================
7629
+ var onContainerMouseDown = function onContainerMouseDown(e) {
7630
+ e.stopPropagation();
7631
+ e.preventDefault();
7632
+ };
7633
+
7634
+ // ======================== Thumb =========================
7635
+ var stateRef = React$4.useRef({
7636
+ top: top,
7637
+ dragging: dragging,
7638
+ pageY: pageXY,
7639
+ startTop: startTop
7640
+ });
7641
+ stateRef.current = {
7642
+ top: top,
7643
+ dragging: dragging,
7644
+ pageY: pageXY,
7645
+ startTop: startTop
7646
+ };
7647
+ var onThumbMouseDown = function onThumbMouseDown(e) {
7648
+ setDragging(true);
7649
+ setPageXY(getPageXY(e, horizontal));
7650
+ setStartTop(stateRef.current.top);
7651
+ onStartMove();
7652
+ e.stopPropagation();
7653
+ e.preventDefault();
7735
7654
  };
7736
- cleanUpEvents = function cleanUpEvents() {
7737
- if (elementRef.current) {
7738
- elementRef.current.removeEventListener('touchmove', onTouchMove);
7739
- elementRef.current.removeEventListener('touchend', onTouchEnd);
7655
+
7656
+ // ======================== Effect ========================
7657
+
7658
+ // React make event as passive, but we need to preventDefault
7659
+ // Add event on dom directly instead.
7660
+ // ref: https://github.com/facebook/react/issues/9809
7661
+ React$4.useEffect(function () {
7662
+ var onScrollbarTouchStart = function onScrollbarTouchStart(e) {
7663
+ e.preventDefault();
7664
+ };
7665
+ var scrollbarEle = scrollbarRef.current;
7666
+ var thumbEle = thumbRef.current;
7667
+ scrollbarEle.addEventListener('touchstart', onScrollbarTouchStart);
7668
+ thumbEle.addEventListener('touchstart', onThumbMouseDown);
7669
+ return function () {
7670
+ scrollbarEle.removeEventListener('touchstart', onScrollbarTouchStart);
7671
+ thumbEle.removeEventListener('touchstart', onThumbMouseDown);
7672
+ };
7673
+ }, []);
7674
+
7675
+ // Pass to effect
7676
+ var enableScrollRangeRef = React$4.useRef();
7677
+ enableScrollRangeRef.current = enableScrollRange;
7678
+ var enableOffsetRangeRef = React$4.useRef();
7679
+ enableOffsetRangeRef.current = enableOffsetRange;
7680
+ React$4.useEffect(function () {
7681
+ if (dragging) {
7682
+ var moveRafId;
7683
+ var onMouseMove = function onMouseMove(e) {
7684
+ var _stateRef$current = stateRef.current,
7685
+ stateDragging = _stateRef$current.dragging,
7686
+ statePageY = _stateRef$current.pageY,
7687
+ stateStartTop = _stateRef$current.startTop;
7688
+ wrapperRaf.cancel(moveRafId);
7689
+ if (stateDragging) {
7690
+ var offset = getPageXY(e, horizontal) - statePageY;
7691
+ var newTop = stateStartTop;
7692
+ if (!isLTR && horizontal) {
7693
+ newTop -= offset;
7694
+ } else {
7695
+ newTop += offset;
7696
+ }
7697
+ var tmpEnableScrollRange = enableScrollRangeRef.current;
7698
+ var tmpEnableOffsetRange = enableOffsetRangeRef.current;
7699
+ var ptg = tmpEnableOffsetRange ? newTop / tmpEnableOffsetRange : 0;
7700
+ var newScrollTop = Math.ceil(ptg * tmpEnableScrollRange);
7701
+ newScrollTop = Math.max(newScrollTop, 0);
7702
+ newScrollTop = Math.min(newScrollTop, tmpEnableScrollRange);
7703
+ moveRafId = wrapperRaf(function () {
7704
+ onScroll(newScrollTop, horizontal);
7705
+ });
7706
+ }
7707
+ };
7708
+ var onMouseUp = function onMouseUp() {
7709
+ setDragging(false);
7710
+ onStopMove();
7711
+ };
7712
+ window.addEventListener('mousemove', onMouseMove);
7713
+ window.addEventListener('touchmove', onMouseMove);
7714
+ window.addEventListener('mouseup', onMouseUp);
7715
+ window.addEventListener('touchend', onMouseUp);
7716
+ return function () {
7717
+ window.removeEventListener('mousemove', onMouseMove);
7718
+ window.removeEventListener('touchmove', onMouseMove);
7719
+ window.removeEventListener('mouseup', onMouseUp);
7720
+ window.removeEventListener('touchend', onMouseUp);
7721
+ wrapperRaf.cancel(moveRafId);
7722
+ };
7740
7723
  }
7724
+ }, [dragging]);
7725
+ React$4.useEffect(function () {
7726
+ delayHidden();
7727
+ }, [scrollOffset]);
7728
+
7729
+ // ====================== Imperative ======================
7730
+ React$4.useImperativeHandle(ref, function () {
7731
+ return {
7732
+ delayHidden: delayHidden
7733
+ };
7734
+ });
7735
+
7736
+ // ======================== Render ========================
7737
+ var scrollbarPrefixCls = "".concat(prefixCls, "-scrollbar");
7738
+ var containerStyle = {
7739
+ position: 'absolute',
7740
+ visibility: visible ? null : 'hidden'
7741
7741
  };
7742
- useLayoutEffect$3(function () {
7743
- if (inVirtual) {
7744
- listRef.current.addEventListener('touchstart', onTouchStart);
7742
+ var thumbStyle = {
7743
+ position: 'absolute',
7744
+ background: 'rgba(0, 0, 0, 0.5)',
7745
+ borderRadius: 99,
7746
+ cursor: 'pointer',
7747
+ userSelect: 'none'
7748
+ };
7749
+ if (horizontal) {
7750
+ // Container
7751
+ containerStyle.height = 8;
7752
+ containerStyle.left = 0;
7753
+ containerStyle.right = 0;
7754
+ containerStyle.bottom = 0;
7755
+
7756
+ // Thumb
7757
+ thumbStyle.height = '100%';
7758
+ thumbStyle.width = spinSize;
7759
+ if (isLTR) {
7760
+ thumbStyle.left = top;
7761
+ } else {
7762
+ thumbStyle.right = top;
7745
7763
  }
7746
- return function () {
7747
- var _listRef$current;
7748
- (_listRef$current = listRef.current) === null || _listRef$current === void 0 || _listRef$current.removeEventListener('touchstart', onTouchStart);
7749
- cleanUpEvents();
7750
- clearInterval(intervalRef.current);
7751
- };
7752
- }, [inVirtual]);
7764
+ } else {
7765
+ // Container
7766
+ containerStyle.width = 8;
7767
+ containerStyle.top = 0;
7768
+ containerStyle.bottom = 0;
7769
+ if (isLTR) {
7770
+ containerStyle.right = 0;
7771
+ } else {
7772
+ containerStyle.left = 0;
7773
+ }
7774
+
7775
+ // Thumb
7776
+ thumbStyle.width = '100%';
7777
+ thumbStyle.height = spinSize;
7778
+ thumbStyle.top = top;
7779
+ }
7780
+ return /*#__PURE__*/React$4.createElement("div", {
7781
+ ref: scrollbarRef,
7782
+ className: classNames(scrollbarPrefixCls, _defineProperty(_defineProperty(_defineProperty({}, "".concat(scrollbarPrefixCls, "-horizontal"), horizontal), "".concat(scrollbarPrefixCls, "-vertical"), !horizontal), "".concat(scrollbarPrefixCls, "-visible"), visible)),
7783
+ style: _objectSpread2(_objectSpread2({}, containerStyle), style),
7784
+ onMouseDown: onContainerMouseDown,
7785
+ onMouseMove: delayHidden
7786
+ }, /*#__PURE__*/React$4.createElement("div", {
7787
+ ref: thumbRef,
7788
+ className: classNames("".concat(scrollbarPrefixCls, "-thumb"), _defineProperty({}, "".concat(scrollbarPrefixCls, "-thumb-moving"), dragging)),
7789
+ style: _objectSpread2(_objectSpread2({}, thumbStyle), propsThumbStyle),
7790
+ onMouseDown: onThumbMouseDown
7791
+ }));
7792
+ });
7793
+ if (process.env.NODE_ENV !== 'production') {
7794
+ ScrollBar.displayName = 'ScrollBar';
7753
7795
  }
7754
7796
 
7755
7797
  var MIN_SIZE = 20;
@@ -7764,52 +7806,6 @@ function getSpinSize() {
7764
7806
  return Math.floor(baseSize);
7765
7807
  }
7766
7808
 
7767
- /**
7768
- * Size info need loop query for the `heights` which will has the perf issue.
7769
- * Let cache result for each render phase.
7770
- */
7771
- function useGetSize(mergedData, getKey, heights, itemHeight) {
7772
- var _React$useMemo = React$4.useMemo(function () {
7773
- return [new Map(), []];
7774
- }, [mergedData, heights.id, itemHeight]),
7775
- _React$useMemo2 = _slicedToArray(_React$useMemo, 2),
7776
- key2Index = _React$useMemo2[0],
7777
- bottomList = _React$useMemo2[1];
7778
- var getSize = function getSize(startKey) {
7779
- var endKey = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : startKey;
7780
- // Get from cache first
7781
- var startIndex = key2Index.get(startKey);
7782
- var endIndex = key2Index.get(endKey);
7783
-
7784
- // Loop to fill the cache
7785
- if (startIndex === undefined || endIndex === undefined) {
7786
- var dataLen = mergedData.length;
7787
- for (var i = bottomList.length; i < dataLen; i += 1) {
7788
- var _heights$get;
7789
- var item = mergedData[i];
7790
- var key = getKey(item);
7791
- key2Index.set(key, i);
7792
- var cacheHeight = (_heights$get = heights.get(key)) !== null && _heights$get !== void 0 ? _heights$get : itemHeight;
7793
- bottomList[i] = (bottomList[i - 1] || 0) + cacheHeight;
7794
- if (key === startKey) {
7795
- startIndex = i;
7796
- }
7797
- if (key === endKey) {
7798
- endIndex = i;
7799
- }
7800
- if (startIndex !== undefined && endIndex !== undefined) {
7801
- break;
7802
- }
7803
- }
7804
- }
7805
- return {
7806
- top: bottomList[startIndex - 1] || 0,
7807
- bottom: bottomList[endIndex]
7808
- };
7809
- };
7810
- return getSize;
7811
- }
7812
-
7813
7809
  var _excluded$2 = ["prefixCls", "className", "height", "itemHeight", "fullHeight", "style", "data", "children", "itemKey", "virtual", "direction", "scrollWidth", "component", "onScroll", "onVirtualScroll", "onVisibleChange", "innerProps", "extraRender", "styles"];
7814
7810
  var EMPTY_DATA = [];
7815
7811
  var ScrollStyle = {
@@ -7841,9 +7837,30 @@ function RawList(props, ref) {
7841
7837
  styles = props.styles,
7842
7838
  restProps = _objectWithoutProperties(props, _excluded$2);
7843
7839
 
7840
+ // =============================== Item Key ===============================
7841
+ var getKey = React$4.useCallback(function (item) {
7842
+ if (typeof itemKey === 'function') {
7843
+ return itemKey(item);
7844
+ }
7845
+ return item === null || item === void 0 ? void 0 : item[itemKey];
7846
+ }, [itemKey]);
7847
+
7848
+ // ================================ Height ================================
7849
+ var _useHeights = useHeights(getKey, null, null),
7850
+ _useHeights2 = _slicedToArray(_useHeights, 4),
7851
+ setInstanceRef = _useHeights2[0],
7852
+ collectHeight = _useHeights2[1],
7853
+ heights = _useHeights2[2],
7854
+ heightUpdatedMark = _useHeights2[3];
7855
+
7844
7856
  // ================================= MISC =================================
7845
7857
  var useVirtual = !!(virtual !== false && height && itemHeight);
7846
- var inVirtual = useVirtual && data && (itemHeight * data.length > height || !!scrollWidth);
7858
+ var containerHeight = React$4.useMemo(function () {
7859
+ return Object.values(heights.maps).reduce(function (total, curr) {
7860
+ return total + curr;
7861
+ }, 0);
7862
+ }, [heights.id, heights.maps]);
7863
+ var inVirtual = useVirtual && data && (Math.max(itemHeight * data.length, containerHeight) > height || !!scrollWidth);
7847
7864
  var isRTL = direction === 'rtl';
7848
7865
  var mergedClassName = classNames(prefixCls, _defineProperty({}, "".concat(prefixCls, "-rtl"), isRTL), className);
7849
7866
  var mergedData = data || EMPTY_DATA;
@@ -7870,14 +7887,6 @@ function RawList(props, ref) {
7870
7887
  var onScrollbarStopMove = function onScrollbarStopMove() {
7871
7888
  setScrollMoving(false);
7872
7889
  };
7873
-
7874
- // =============================== Item Key ===============================
7875
- var getKey = React$4.useCallback(function (item) {
7876
- if (typeof itemKey === 'function') {
7877
- return itemKey(item);
7878
- }
7879
- return item === null || item === void 0 ? void 0 : item[itemKey];
7880
- }, [itemKey]);
7881
7890
  var sharedConfig = {
7882
7891
  getKey: getKey
7883
7892
  };
@@ -7909,14 +7918,6 @@ function RawList(props, ref) {
7909
7918
  diffItem = _useDiffItem2[0];
7910
7919
  diffItemRef.current = diffItem;
7911
7920
 
7912
- // ================================ Height ================================
7913
- var _useHeights = useHeights(getKey, null, null),
7914
- _useHeights2 = _slicedToArray(_useHeights, 4),
7915
- setInstanceRef = _useHeights2[0],
7916
- collectHeight = _useHeights2[1],
7917
- heights = _useHeights2[2],
7918
- heightUpdatedMark = _useHeights2[3];
7919
-
7920
7921
  // ========================== Visible Calculation =========================
7921
7922
  var _React$useMemo = React$4.useMemo(function () {
7922
7923
  if (!useVirtual) {
@@ -8037,9 +8038,9 @@ function RawList(props, ref) {
8037
8038
  };
8038
8039
  };
8039
8040
  var lastVirtualScrollInfoRef = useRef(getVirtualScrollInfo());
8040
- var triggerScroll = useEvent$2(function () {
8041
+ var triggerScroll = useEvent$2(function (params) {
8041
8042
  if (onVirtualScroll) {
8042
- var nextInfo = getVirtualScrollInfo();
8043
+ var nextInfo = _objectSpread2(_objectSpread2({}, getVirtualScrollInfo()), params);
8043
8044
 
8044
8045
  // Trigger when offset changed
8045
8046
  if (lastVirtualScrollInfoRef.current.x !== nextInfo.x || lastVirtualScrollInfoRef.current.y !== nextInfo.y) {
@@ -8073,7 +8074,7 @@ function RawList(props, ref) {
8073
8074
  }
8074
8075
  var keepInHorizontalRange = function keepInHorizontalRange(nextOffsetLeft) {
8075
8076
  var tmpOffsetLeft = nextOffsetLeft;
8076
- var max = scrollWidth - size.width;
8077
+ var max = !!scrollWidth ? scrollWidth - size.width : 0;
8077
8078
  tmpOffsetLeft = Math.max(tmpOffsetLeft, 0);
8078
8079
  tmpOffsetLeft = Math.min(tmpOffsetLeft, max);
8079
8080
  return tmpOffsetLeft;
@@ -8135,8 +8136,10 @@ function RawList(props, ref) {
8135
8136
  // Sync scroll left
8136
8137
  useLayoutEffect$3(function () {
8137
8138
  if (scrollWidth) {
8138
- setOffsetLeft(function (left) {
8139
- return keepInHorizontalRange(left);
8139
+ var newOffsetLeft = keepInHorizontalRange(offsetLeft);
8140
+ setOffsetLeft(newOffsetLeft);
8141
+ triggerScroll({
8142
+ x: newOffsetLeft
8140
8143
  });
8141
8144
  }
8142
8145
  }, [size.width, scrollWidth]);