@kdcloudjs/kdesign 1.6.31 → 1.6.33

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 (64) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/LICENSE +3 -0
  3. package/dist/kdesign.css +1 -1
  4. package/dist/kdesign.css.map +1 -1
  5. package/dist/kdesign.js +2071 -219
  6. package/dist/kdesign.js.map +1 -1
  7. package/dist/kdesign.min.css +1 -1
  8. package/dist/kdesign.min.js +8 -8
  9. package/dist/kdesign.min.js.map +1 -1
  10. package/es/_utils/getStringLength.d.ts +1 -0
  11. package/es/_utils/getStringLength.js +14 -0
  12. package/es/_utils/hooks.d.ts +3 -0
  13. package/es/_utils/hooks.js +50 -1
  14. package/es/_utils/raf.d.ts +3 -0
  15. package/es/_utils/raf.js +35 -0
  16. package/es/_utils/resizeObserver.d.ts +15 -0
  17. package/es/_utils/resizeObserver.js +79 -0
  18. package/es/_utils/usePopper.js +1 -1
  19. package/es/date-picker/date-picker.js +2 -5
  20. package/es/select/interface.d.ts +2 -0
  21. package/es/select/select.js +22 -2
  22. package/es/stepper/stepper.js +2 -1
  23. package/es/table/feature/colGroupExtendable.d.ts +4 -0
  24. package/es/table/feature/colGroupExtendable.js +9 -0
  25. package/es/table/interface.d.ts +2 -1
  26. package/es/table/table.js +5 -1
  27. package/es/virtual-list/Filler.d.ts +9 -0
  28. package/es/virtual-list/Filler.js +38 -0
  29. package/es/virtual-list/index.d.ts +3 -0
  30. package/es/virtual-list/index.js +3 -0
  31. package/es/virtual-list/utils/algorithmUtil.d.ts +19 -0
  32. package/es/virtual-list/utils/algorithmUtil.js +79 -0
  33. package/es/virtual-list/utils/itemUtil.d.ts +75 -0
  34. package/es/virtual-list/utils/itemUtil.js +176 -0
  35. package/es/virtual-list/virtual-list.d.ts +34 -0
  36. package/es/virtual-list/virtual-list.js +589 -0
  37. package/lib/_utils/getStringLength.d.ts +1 -0
  38. package/lib/_utils/getStringLength.js +21 -0
  39. package/lib/_utils/hooks.d.ts +3 -0
  40. package/lib/_utils/hooks.js +56 -0
  41. package/lib/_utils/raf.d.ts +3 -0
  42. package/lib/_utils/raf.js +43 -0
  43. package/lib/_utils/resizeObserver.d.ts +15 -0
  44. package/lib/_utils/resizeObserver.js +95 -0
  45. package/lib/_utils/usePopper.js +1 -1
  46. package/lib/date-picker/date-picker.js +2 -6
  47. package/lib/select/interface.d.ts +2 -0
  48. package/lib/select/select.js +23 -2
  49. package/lib/stepper/stepper.js +3 -1
  50. package/lib/table/feature/colGroupExtendable.d.ts +4 -0
  51. package/lib/table/feature/colGroupExtendable.js +17 -0
  52. package/lib/table/interface.d.ts +2 -1
  53. package/lib/table/table.js +6 -1
  54. package/lib/virtual-list/Filler.d.ts +9 -0
  55. package/lib/virtual-list/Filler.js +59 -0
  56. package/lib/virtual-list/index.d.ts +3 -0
  57. package/lib/virtual-list/index.js +36 -0
  58. package/lib/virtual-list/utils/algorithmUtil.d.ts +19 -0
  59. package/lib/virtual-list/utils/algorithmUtil.js +88 -0
  60. package/lib/virtual-list/utils/itemUtil.d.ts +75 -0
  61. package/lib/virtual-list/utils/itemUtil.js +206 -0
  62. package/lib/virtual-list/virtual-list.d.ts +34 -0
  63. package/lib/virtual-list/virtual-list.js +626 -0
  64. package/package.json +1 -1
@@ -0,0 +1,626 @@
1
+ "use strict";
2
+
3
+ var _typeof3 = require("@babel/runtime-corejs3/helpers/typeof");
4
+
5
+ var _WeakMap = require("@babel/runtime-corejs3/core-js-stable/weak-map");
6
+
7
+ var _Object$getOwnPropertyDescriptor = require("@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor");
8
+
9
+ var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
10
+
11
+ Object.defineProperty(exports, "__esModule", {
12
+ value: true
13
+ });
14
+ exports.default = void 0;
15
+ exports.isNumber = isNumber;
16
+
17
+ var _typeof2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/typeof"));
18
+
19
+ var _extends2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/extends"));
20
+
21
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/slicedToArray"));
22
+
23
+ var _getOwnPropertySymbols = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols"));
24
+
25
+ var _slice = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/slice"));
26
+
27
+ var _keys = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/object/keys"));
28
+
29
+ var _entries = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/object/entries"));
30
+
31
+ var _findIndex = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/find-index"));
32
+
33
+ var _map = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/map"));
34
+
35
+ var _react = _interopRequireWildcard(require("react"));
36
+
37
+ var _itemUtil = require("./utils/itemUtil");
38
+
39
+ var _raf = require("../_utils/raf");
40
+
41
+ var _hooks = require("../_utils/hooks");
42
+
43
+ var _algorithmUtil = require("./utils/algorithmUtil");
44
+
45
+ var _Filler = _interopRequireDefault(require("./Filler"));
46
+
47
+ var _resizeObserver = _interopRequireDefault(require("../_utils/resizeObserver"));
48
+
49
+ var _context;
50
+
51
+ 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); }
52
+
53
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof3(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; }
54
+
55
+ var __rest = void 0 && (void 0).__rest || function (s, e) {
56
+ var t = {};
57
+
58
+ for (var p in s) {
59
+ if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
60
+ }
61
+
62
+ if (s != null && typeof _getOwnPropertySymbols.default === "function") for (var i = 0, p = (0, _getOwnPropertySymbols.default)(s); i < p.length; i++) {
63
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
64
+ }
65
+ return t;
66
+ }; // Reference: https://github.com/arco-design/arco-design/blob/main/components/_class/VirtualList/index.tsx
67
+
68
+
69
+ function isNumber(obj) {
70
+ return Object.prototype.toString.call(obj) === '[object Number]' && obj === obj; // eslint-disable-line
71
+ }
72
+
73
+ var DEFAULT_VIRTUAL_ITEM_HEIGHT = 32;
74
+ var KEY_VIRTUAL_ITEM_HEIGHT = "__virtual_item_height_".concat((0, _slice.default)(_context = Math.random().toFixed(5)).call(_context, 2));
75
+
76
+ var useComputeVirtualItemHeight = function useComputeVirtualItemHeight(refItemHeightMap) {
77
+ var forceUpdate = (0, _hooks.useForceUpdate)();
78
+ var heightMap = refItemHeightMap.current;
79
+ (0, _react.useEffect)(function () {
80
+ if ((0, _keys.default)(heightMap).length && !heightMap[KEY_VIRTUAL_ITEM_HEIGHT]) {
81
+ heightMap[KEY_VIRTUAL_ITEM_HEIGHT] = (0, _entries.default)(heightMap).reduce(function (sum, _ref, currentIndex, array) {
82
+ var _ref2 = (0, _slicedToArray2.default)(_ref, 2),
83
+ currentHeight = _ref2[1];
84
+
85
+ var nextSum = sum + currentHeight;
86
+ return currentIndex === array.length - 1 ? Math.round(nextSum / array.length) : nextSum;
87
+ }, 0);
88
+ forceUpdate();
89
+ }
90
+ }, [(0, _keys.default)(heightMap).length]);
91
+ };
92
+
93
+ var useCacheChildrenNodes = function useCacheChildrenNodes(children) {
94
+ var refCacheMap = (0, _react.useRef)({});
95
+ var refPrevChildren = (0, _react.useRef)(children);
96
+ (0, _react.useEffect)(function () {
97
+ refPrevChildren.current = children;
98
+ }, [children]);
99
+
100
+ if (children !== refPrevChildren.current) {
101
+ refCacheMap.current = {};
102
+ }
103
+
104
+ return function (item, index, props) {
105
+ // eslint-disable-next-line no-prototype-builtins
106
+ if (!refCacheMap.current.hasOwnProperty(index)) {
107
+ refCacheMap.current[index] = children(item, index, props);
108
+ }
109
+
110
+ return refCacheMap.current[index];
111
+ };
112
+ };
113
+
114
+ var VirtualList = /*#__PURE__*/_react.default.forwardRef(function (props, ref) {
115
+ var style = props.style,
116
+ className = props.className,
117
+ children = props.children,
118
+ _props$data = props.data,
119
+ data = _props$data === void 0 ? [] : _props$data,
120
+ itemKey = props.itemKey,
121
+ _props$threshold = props.threshold,
122
+ threshold = _props$threshold === void 0 ? 100 : _props$threshold,
123
+ _props$wrapper = props.wrapper,
124
+ WrapperTagName = _props$wrapper === void 0 ? 'div' : _props$wrapper,
125
+ _props$height = props.height,
126
+ propHeight = _props$height === void 0 ? 300 : _props$height,
127
+ _props$isStaticItemHe = props.isStaticItemHeight,
128
+ isStaticItemHeight = _props$isStaticItemHe === void 0 ? true : _props$isStaticItemHe,
129
+ propItemHeight = props.itemHeight,
130
+ measureLongestItem = props.measureLongestItem,
131
+ scrollOptions = props.scrollOptions,
132
+ onScroll = props.onScroll,
133
+ _props$needFiller = props.needFiller,
134
+ needFiller = _props$needFiller === void 0 ? true : _props$needFiller,
135
+ outerStyle = props.outerStyle,
136
+ restProps = __rest(props, ["style", "className", "children", "data", "itemKey", "threshold", "wrapper", "height", "isStaticItemHeight", "itemHeight", "measureLongestItem", "scrollOptions", "onScroll", "needFiller", "outerStyle"]);
137
+
138
+ var styleListMaxHeight = style && style.maxHeight || propHeight;
139
+ var refItemHeightMap = (0, _react.useRef)({});
140
+
141
+ var _useState = (0, _react.useState)(200),
142
+ _useState2 = (0, _slicedToArray2.default)(_useState, 2),
143
+ stateHeight = _useState2[0],
144
+ setStateHeight = _useState2[1];
145
+
146
+ var renderChild = useCacheChildrenNodes(children);
147
+ useComputeVirtualItemHeight(refItemHeightMap);
148
+ var itemCount = data.length;
149
+ var itemHeight = propItemHeight || refItemHeightMap.current[KEY_VIRTUAL_ITEM_HEIGHT] || DEFAULT_VIRTUAL_ITEM_HEIGHT;
150
+ var viewportHeight = isNumber(styleListMaxHeight) ? styleListMaxHeight : stateHeight;
151
+ var itemCountVisible = Math.ceil(viewportHeight / itemHeight);
152
+ var itemTotalHeight = itemHeight * itemCount;
153
+ var isVirtual = threshold !== null && itemCount >= threshold && itemTotalHeight > viewportHeight;
154
+ var refList = (0, _react.useRef)(null);
155
+ var refRafId = (0, _react.useRef)(null);
156
+ var refLockScroll = (0, _react.useRef)(false);
157
+ var refIsVirtual = (0, _react.useRef)(isVirtual);
158
+ var scrollListPadding = (0, _react.useMemo)(function () {
159
+ if (refList.current) {
160
+ var getPadding = function getPadding(property) {
161
+ return +window.getComputedStyle(refList.current)[property].replace(/\D/g, '');
162
+ };
163
+
164
+ return {
165
+ top: getPadding('paddingTop'),
166
+ bottom: getPadding('paddingBottom')
167
+ };
168
+ }
169
+
170
+ return {
171
+ top: 0,
172
+ bottom: 0
173
+ };
174
+ }, [refList.current]);
175
+
176
+ var _useStateWithPromise = (0, _hooks.useStateWithPromise)({
177
+ status: 'NONE',
178
+ startIndex: 0,
179
+ endIndex: 0,
180
+ itemIndex: 0,
181
+ itemOffsetPtg: 0,
182
+ startItemTop: 0,
183
+ scrollTop: 0
184
+ }),
185
+ _useStateWithPromise2 = (0, _slicedToArray2.default)(_useStateWithPromise, 2),
186
+ state = _useStateWithPromise2[0],
187
+ setState = _useStateWithPromise2[1];
188
+
189
+ var prevData = (0, _hooks.usePrevious)(data) || [];
190
+ var isFirstRender = (0, _hooks.useIsFirstRender)();
191
+
192
+ var getItemKey = function getItemKey(item, index) {
193
+ return typeof itemKey === 'function' ? itemKey(item, index) : typeof itemKey === 'string' ? item[itemKey] : item.key || index;
194
+ };
195
+
196
+ var getItemKeyByIndex = function getItemKeyByIndex(index) {
197
+ var items = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : data;
198
+
199
+ if (index === items.length) {
200
+ return _itemUtil.GHOST_ITEM_KEY;
201
+ }
202
+
203
+ var item = items[index];
204
+ return item !== undefined ? getItemKey(item, index) : null;
205
+ };
206
+
207
+ var getCachedItemHeight = function getCachedItemHeight(key) {
208
+ return refItemHeightMap.current[key] || itemHeight;
209
+ };
210
+
211
+ var internalScrollTo = function internalScrollTo(relativeScroll) {
212
+ var compareItemIndex = relativeScroll.itemIndex,
213
+ compareItemRelativeTop = relativeScroll.relativeTop;
214
+ if (!refList.current) return;
215
+ var _refList$current = refList.current,
216
+ scrollHeight = _refList$current.scrollHeight,
217
+ clientHeight = _refList$current.clientHeight;
218
+ var originScrollTop = state.scrollTop;
219
+ var maxScrollTop = scrollHeight - clientHeight;
220
+ var bestSimilarity = Number.MAX_VALUE;
221
+ var bestScrollTop = null;
222
+ var bestItemIndex = null;
223
+ var bestItemOffsetPtg = null;
224
+ var bestStartIndex = null;
225
+ var bestEndIndex = null;
226
+ var missSimilarity = 0;
227
+
228
+ for (var i = 0; i < maxScrollTop; i++) {
229
+ var scrollTop = (0, _algorithmUtil.getIndexByStartLoc)(0, maxScrollTop, originScrollTop, i);
230
+ var scrollPtg = (0, _itemUtil.getScrollPercentage)({
231
+ scrollTop: scrollTop,
232
+ scrollHeight: scrollHeight,
233
+ clientHeight: clientHeight
234
+ });
235
+
236
+ var _getRangeIndex = (0, _itemUtil.getRangeIndex)(scrollPtg, itemCount, itemCountVisible),
237
+ itemIndex = _getRangeIndex.itemIndex,
238
+ itemOffsetPtg = _getRangeIndex.itemOffsetPtg,
239
+ startIndex = _getRangeIndex.startIndex,
240
+ endIndex = _getRangeIndex.endIndex;
241
+
242
+ if (startIndex <= compareItemIndex && compareItemIndex <= endIndex) {
243
+ var locatedItemRelativeTop = (0, _itemUtil.getItemRelativeTop)({
244
+ itemHeight: getCachedItemHeight(getItemKeyByIndex(itemIndex)),
245
+ itemOffsetPtg: itemOffsetPtg,
246
+ clientHeight: clientHeight,
247
+ scrollPtg: scrollPtg
248
+ });
249
+ var compareItemTop = (0, _itemUtil.getCompareItemRelativeTop)({
250
+ locatedItemRelativeTop: locatedItemRelativeTop,
251
+ locatedItemIndex: itemIndex,
252
+ compareItemIndex: compareItemIndex,
253
+ startIndex: startIndex,
254
+ endIndex: endIndex,
255
+ itemHeight: itemHeight,
256
+ getItemKey: getItemKeyByIndex,
257
+ itemElementHeights: refItemHeightMap.current
258
+ });
259
+ var similarity = Math.abs(compareItemTop - compareItemRelativeTop);
260
+
261
+ if (similarity < bestSimilarity) {
262
+ bestSimilarity = similarity;
263
+ bestScrollTop = scrollTop;
264
+ bestItemIndex = itemIndex;
265
+ bestItemOffsetPtg = itemOffsetPtg;
266
+ bestStartIndex = startIndex;
267
+ bestEndIndex = endIndex;
268
+ missSimilarity = 0;
269
+ } else {
270
+ missSimilarity += 1;
271
+ }
272
+ }
273
+
274
+ if (missSimilarity > 10) {
275
+ break;
276
+ }
277
+ }
278
+
279
+ if (bestScrollTop !== null) {
280
+ refLockScroll.current = true;
281
+ refList.current.scrollTop = bestScrollTop;
282
+ setState((0, _extends2.default)((0, _extends2.default)({}, state), {
283
+ status: 'MEASURE_START',
284
+ scrollTop: bestScrollTop,
285
+ itemIndex: bestItemIndex,
286
+ itemOffsetPtg: bestItemOffsetPtg,
287
+ startIndex: bestStartIndex,
288
+ endIndex: bestEndIndex
289
+ }));
290
+ }
291
+
292
+ refRafId.current = (0, _raf.raf)(function () {
293
+ refLockScroll.current = false;
294
+ });
295
+ };
296
+
297
+ var rawListScrollHandler = function rawListScrollHandler(event) {
298
+ if (!refList.current) return;
299
+ var _refList$current2 = refList.current,
300
+ rawScrollTop = _refList$current2.scrollTop,
301
+ clientHeight = _refList$current2.clientHeight,
302
+ scrollHeight = _refList$current2.scrollHeight;
303
+ var scrollTop = (0, _itemUtil.getValidScrollTop)(rawScrollTop, scrollHeight - clientHeight);
304
+ var scrollPtg = (0, _itemUtil.getScrollPercentage)({
305
+ scrollTop: scrollTop,
306
+ clientHeight: clientHeight,
307
+ scrollHeight: scrollHeight
308
+ });
309
+
310
+ var _getLocationItem = (0, _itemUtil.getLocationItem)(scrollPtg, itemCount),
311
+ index = _getLocationItem.index,
312
+ offsetPtg = _getLocationItem.offsetPtg;
313
+
314
+ setState((0, _extends2.default)((0, _extends2.default)({}, state), {
315
+ scrollTop: scrollTop,
316
+ itemIndex: index,
317
+ itemOffsetPtg: offsetPtg
318
+ }));
319
+ event && onScroll && onScroll(event);
320
+ };
321
+
322
+ var virtualListScrollHandler = function virtualListScrollHandler(event) {
323
+ var isInit = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
324
+ var scrollHeight = itemTotalHeight;
325
+ if (!refList.current) return;
326
+ var _refList$current3 = refList.current,
327
+ rawScrollTop = _refList$current3.scrollTop,
328
+ clientHeight = _refList$current3.clientHeight;
329
+ var scrollTop = (0, _itemUtil.getValidScrollTop)(rawScrollTop, scrollHeight - clientHeight);
330
+
331
+ if (!isInit && (scrollTop === state.scrollTop || refLockScroll.current)) {
332
+ return;
333
+ }
334
+
335
+ var scrollPtg = (0, _itemUtil.getScrollPercentage)({
336
+ scrollTop: scrollTop,
337
+ clientHeight: clientHeight,
338
+ scrollHeight: scrollHeight
339
+ });
340
+
341
+ var _getRangeIndex2 = (0, _itemUtil.getRangeIndex)(scrollPtg, itemCount, itemCountVisible),
342
+ itemIndex = _getRangeIndex2.itemIndex,
343
+ itemOffsetPtg = _getRangeIndex2.itemOffsetPtg,
344
+ startIndex = _getRangeIndex2.startIndex,
345
+ endIndex = _getRangeIndex2.endIndex;
346
+
347
+ setState((0, _extends2.default)((0, _extends2.default)({}, state), {
348
+ scrollTop: scrollTop,
349
+ itemIndex: itemIndex,
350
+ itemOffsetPtg: itemOffsetPtg,
351
+ startIndex: startIndex,
352
+ endIndex: endIndex,
353
+ status: 'MEASURE_START'
354
+ }));
355
+ event && onScroll && onScroll(event);
356
+ };
357
+
358
+ (0, _react.useEffect)(function () {
359
+ return function () {
360
+ refRafId.current && (0, _raf.caf)(refRafId.current);
361
+ };
362
+ }, []);
363
+ (0, _react.useEffect)(function () {
364
+ if (refList.current) {
365
+ if (isFirstRender) {
366
+ refList.current.scrollTop = 0;
367
+ }
368
+
369
+ virtualListScrollHandler(null, true);
370
+ }
371
+ }, [itemCountVisible]);
372
+ (0, _react.useEffect)(function () {
373
+ var changedItemIndex = null;
374
+ var switchTo = refIsVirtual.current !== isVirtual ? isVirtual ? 'virtual' : 'raw' : '';
375
+ refIsVirtual.current = isVirtual;
376
+
377
+ if (viewportHeight && prevData.length !== data.length) {
378
+ var diff = (0, _algorithmUtil.findListDiffIndex)(prevData, data, getItemKey);
379
+ changedItemIndex = diff ? diff.index : null;
380
+ }
381
+
382
+ if ((switchTo || isVirtual && changedItemIndex) && refList.current) {
383
+ var clientHeight = refList.current.clientHeight;
384
+ var locatedItemRelativeTop = (0, _itemUtil.getItemRelativeTop)({
385
+ itemHeight: getCachedItemHeight(getItemKeyByIndex(state.itemIndex, prevData)),
386
+ itemOffsetPtg: state.itemOffsetPtg,
387
+ scrollPtg: (0, _itemUtil.getScrollPercentage)({
388
+ scrollTop: state.scrollTop,
389
+ scrollHeight: prevData.length * itemHeight,
390
+ clientHeight: clientHeight
391
+ }),
392
+ clientHeight: clientHeight
393
+ });
394
+
395
+ if (switchTo === 'raw') {
396
+ var rawTop = locatedItemRelativeTop;
397
+
398
+ for (var index = 0; index < state.itemIndex; index++) {
399
+ rawTop -= getCachedItemHeight(getItemKeyByIndex(index));
400
+ }
401
+
402
+ refList.current.scrollTop = -rawTop;
403
+ refLockScroll.current = true;
404
+ refRafId.current = (0, _raf.raf)(function () {
405
+ refLockScroll.current = false;
406
+ });
407
+ } else {
408
+ internalScrollTo({
409
+ itemIndex: state.itemIndex,
410
+ relativeTop: locatedItemRelativeTop
411
+ });
412
+ }
413
+ }
414
+ }, [data, isVirtual]);
415
+ (0, _react.useLayoutEffect)(function () {
416
+ if (state.status === 'MEASURE_START' && refList.current) {
417
+ var _refList$current4 = refList.current,
418
+ scrollTop = _refList$current4.scrollTop,
419
+ scrollHeight = _refList$current4.scrollHeight,
420
+ clientHeight = _refList$current4.clientHeight;
421
+ var scrollPtg = (0, _itemUtil.getScrollPercentage)({
422
+ scrollTop: scrollTop,
423
+ scrollHeight: scrollHeight,
424
+ clientHeight: clientHeight
425
+ });
426
+ var startItemTop = (0, _itemUtil.getItemAbsoluteTop)({
427
+ scrollPtg: scrollPtg,
428
+ clientHeight: clientHeight,
429
+ scrollTop: scrollTop - (scrollListPadding.top + scrollListPadding.bottom) * scrollPtg,
430
+ itemHeight: getCachedItemHeight(getItemKeyByIndex(state.itemIndex)),
431
+ itemOffsetPtg: state.itemOffsetPtg
432
+ });
433
+
434
+ for (var index = state.itemIndex - 1; index >= state.startIndex; index--) {
435
+ startItemTop -= getCachedItemHeight(getItemKeyByIndex(index));
436
+ }
437
+
438
+ setState((0, _extends2.default)((0, _extends2.default)({}, state), {
439
+ startItemTop: startItemTop,
440
+ status: 'MEASURE_DONE'
441
+ }));
442
+ }
443
+ }, [state]);
444
+ (0, _react.useImperativeHandle)(ref, function () {
445
+ return {
446
+ dom: refList.current,
447
+ scrollTo: function scrollTo(arg) {
448
+ refRafId.current && (0, _raf.caf)(refRafId.current);
449
+ refRafId.current = (0, _raf.raf)(function () {
450
+ var _a;
451
+
452
+ if (typeof arg === 'number') {
453
+ refList.current.scrollTop = arg;
454
+ return;
455
+ }
456
+
457
+ var index = 'index' in arg ? arg.index : 'key' in arg ? (0, _findIndex.default)(data).call(data, function (item, index) {
458
+ return getItemKey(item, index) === arg.key;
459
+ }) : 0;
460
+ var item = data[index];
461
+
462
+ if (!item) {
463
+ return;
464
+ }
465
+
466
+ var align = (0, _typeof2.default)(arg) === 'object' && ((_a = arg.options) === null || _a === void 0 ? void 0 : _a.block) ? arg.options.block : (scrollOptions === null || scrollOptions === void 0 ? void 0 : scrollOptions.block) || 'nearest';
467
+ var _refList$current5 = refList.current,
468
+ clientHeight = _refList$current5.clientHeight,
469
+ scrollTop = _refList$current5.scrollTop;
470
+
471
+ if (isVirtual && !isStaticItemHeight) {
472
+ if (align === 'nearest') {
473
+ var itemIndex = state.itemIndex,
474
+ itemOffsetPtg = state.itemOffsetPtg;
475
+
476
+ if (Math.abs(itemIndex - index) < itemCountVisible) {
477
+ var itemTop = (0, _itemUtil.getItemRelativeTop)({
478
+ itemHeight: getCachedItemHeight(getItemKeyByIndex(itemIndex)),
479
+ itemOffsetPtg: itemOffsetPtg,
480
+ clientHeight: clientHeight,
481
+ scrollPtg: (0, _itemUtil.getScrollPercentage)(refList.current)
482
+ });
483
+
484
+ if (index < itemIndex) {
485
+ for (var i = index; i < itemIndex; i++) {
486
+ itemTop -= getCachedItemHeight(getItemKeyByIndex(i));
487
+ }
488
+ } else {
489
+ for (var _i = itemIndex; _i < index; _i++) {
490
+ itemTop += getCachedItemHeight(getItemKeyByIndex(_i));
491
+ }
492
+ }
493
+
494
+ if (itemTop < 0 || itemTop > clientHeight) {
495
+ align = itemTop < 0 ? 'start' : 'end';
496
+ } else {
497
+ return;
498
+ }
499
+ } else {
500
+ align = index < itemIndex ? 'start' : 'end';
501
+ }
502
+ }
503
+
504
+ setState((0, _extends2.default)((0, _extends2.default)({}, state), {
505
+ startIndex: Math.max(0, index - itemCountVisible),
506
+ endIndex: Math.min(itemCount - 1, index + itemCountVisible)
507
+ })).then(function () {
508
+ var itemHeight = getCachedItemHeight(getItemKey(item, index));
509
+ internalScrollTo({
510
+ itemIndex: index,
511
+ relativeTop: align === 'start' ? 0 : (clientHeight - itemHeight) / (align === 'center' ? 2 : 1)
512
+ });
513
+ });
514
+ } else {
515
+ var indexItemHeight = getCachedItemHeight(getItemKeyByIndex(index));
516
+ var _itemTop = 0;
517
+
518
+ for (var _i2 = 0; _i2 < index; _i2++) {
519
+ _itemTop += getCachedItemHeight(getItemKeyByIndex(_i2));
520
+ }
521
+
522
+ var itemBottom = _itemTop + indexItemHeight;
523
+ var itemMiddle = _itemTop + indexItemHeight / 2;
524
+
525
+ if (itemMiddle > scrollTop && itemMiddle < clientHeight + scrollTop) {
526
+ return;
527
+ }
528
+
529
+ if (align === 'nearest') {
530
+ if (_itemTop < scrollTop) {
531
+ align = 'start';
532
+ } else if (itemBottom > scrollTop + clientHeight) {
533
+ align = 'end';
534
+ }
535
+ }
536
+
537
+ var _viewportHeight = clientHeight - indexItemHeight;
538
+
539
+ refList.current.scrollTop = _itemTop - (align === 'start' ? 0 : _viewportHeight / (align === 'center' ? 2 : 1));
540
+ }
541
+ });
542
+ }
543
+ };
544
+ }, [data, itemHeight, state]);
545
+
546
+ var renderChildren = function renderChildren(list, startIndex) {
547
+ return (0, _map.default)(list).call(list, function (item, index) {
548
+ var originIndex = startIndex + index;
549
+ var node = renderChild(item, originIndex, {
550
+ style: {}
551
+ });
552
+ var key = getItemKey(item, originIndex);
553
+ return /*#__PURE__*/_react.default.cloneElement(node, {
554
+ key: key,
555
+ ref: function ref(ele) {
556
+ var heightMap = refItemHeightMap.current;
557
+
558
+ if (ele && state.status === 'MEASURE_START' && (!isStaticItemHeight || heightMap[key] === undefined)) {
559
+ if (isStaticItemHeight) {
560
+ if (!heightMap[KEY_VIRTUAL_ITEM_HEIGHT]) {
561
+ heightMap[KEY_VIRTUAL_ITEM_HEIGHT] = (0, _itemUtil.getNodeHeight)(ele, true);
562
+ }
563
+
564
+ heightMap[key] = heightMap[KEY_VIRTUAL_ITEM_HEIGHT];
565
+ } else {
566
+ heightMap[key] = (0, _itemUtil.getNodeHeight)(ele, true);
567
+ }
568
+ }
569
+ }
570
+ });
571
+ });
572
+ };
573
+
574
+ var refLongestItemIndex = (0, _react.useRef)(null);
575
+ (0, _react.useEffect)(function () {
576
+ refLongestItemIndex.current = null;
577
+ }, [data]);
578
+
579
+ var renderLongestItem = function renderLongestItem() {
580
+ if (measureLongestItem) {
581
+ var index = refLongestItemIndex.current === null ? (0, _itemUtil.getLongestItemIndex)(data) : refLongestItemIndex.current;
582
+ var item = data[index];
583
+ refLongestItemIndex.current = index;
584
+ return item ? /*#__PURE__*/_react.default.createElement("div", {
585
+ style: {
586
+ height: 1,
587
+ overflow: 'hidden',
588
+ opacity: 0
589
+ }
590
+ }, renderChild(item, index, {
591
+ style: {}
592
+ })) : null;
593
+ }
594
+
595
+ return null;
596
+ };
597
+
598
+ return /*#__PURE__*/_react.default.createElement(_resizeObserver.default, {
599
+ onResize: function onResize() {
600
+ if (refList.current && !isNumber(styleListMaxHeight)) {
601
+ var clientHeight = refList.current.clientHeight;
602
+ setStateHeight(clientHeight);
603
+ }
604
+ }
605
+ }, /*#__PURE__*/_react.default.createElement(WrapperTagName, (0, _extends2.default)({
606
+ ref: refList,
607
+ style: (0, _extends2.default)((0, _extends2.default)({
608
+ overflowY: 'auto',
609
+ overflowAnchor: 'none'
610
+ }, style), {
611
+ maxHeight: styleListMaxHeight
612
+ }),
613
+ className: className,
614
+ onScroll: isVirtual ? virtualListScrollHandler : rawListScrollHandler
615
+ }, restProps), isVirtual ? /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_Filler.default, {
616
+ height: itemTotalHeight,
617
+ offset: state.status === 'MEASURE_DONE' ? state.startItemTop : 0,
618
+ outerStyle: outerStyle
619
+ }, renderChildren((0, _slice.default)(data).call(data, state.startIndex, state.endIndex + 1), state.startIndex)), renderLongestItem()) : needFiller ? /*#__PURE__*/_react.default.createElement(_Filler.default, {
620
+ height: viewportHeight
621
+ }, renderChildren(data, 0)) : renderChildren(data, 0)));
622
+ });
623
+
624
+ VirtualList.displayName = 'VirtualList';
625
+ var _default = VirtualList;
626
+ exports.default = _default;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kdcloudjs/kdesign",
3
- "version": "1.6.31",
3
+ "version": "1.6.33",
4
4
  "description": "KDesign 金蝶前端react 组件库",
5
5
  "title": "kdesign",
6
6
  "keywords": [