@are-visual/virtual-table 0.0.1

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 (46) hide show
  1. package/README.md +548 -0
  2. package/index.d.ts +311 -0
  3. package/index.esm.js +1771 -0
  4. package/index.esm.js.map +1 -0
  5. package/middleware/column-resize/index.d.ts +19 -0
  6. package/middleware/column-resize/index.js +130 -0
  7. package/middleware/column-resize/index.js.map +1 -0
  8. package/middleware/column-resize/styles.css +8 -0
  9. package/middleware/column-resize/styles.scss +10 -0
  10. package/middleware/empty/index.d.ts +10 -0
  11. package/middleware/empty/index.js +73 -0
  12. package/middleware/empty/index.js.map +1 -0
  13. package/middleware/expandable/index.d.ts +37 -0
  14. package/middleware/expandable/index.js +239 -0
  15. package/middleware/expandable/index.js.map +1 -0
  16. package/middleware/expandable/styles.css +49 -0
  17. package/middleware/expandable/styles.scss +73 -0
  18. package/middleware/horizontal-scroll-bar/index.d.ts +15 -0
  19. package/middleware/horizontal-scroll-bar/index.js +90 -0
  20. package/middleware/horizontal-scroll-bar/index.js.map +1 -0
  21. package/middleware/horizontal-scroll-bar/styles.css +11 -0
  22. package/middleware/horizontal-scroll-bar/styles.scss +13 -0
  23. package/middleware/loading/index.d.ts +7 -0
  24. package/middleware/loading/index.js +73 -0
  25. package/middleware/loading/index.js.map +1 -0
  26. package/middleware/loading/styles.css +17 -0
  27. package/middleware/loading/styles.scss +27 -0
  28. package/middleware/selection/index.d.ts +47 -0
  29. package/middleware/selection/index.js +282 -0
  30. package/middleware/selection/index.js.map +1 -0
  31. package/middleware/selection/styles.css +13 -0
  32. package/middleware/selection/styles.scss +20 -0
  33. package/middleware/summary/index.d.ts +36 -0
  34. package/middleware/summary/index.js +203 -0
  35. package/middleware/summary/index.js.map +1 -0
  36. package/middleware/summary/styles.css +36 -0
  37. package/middleware/summary/styles.scss +45 -0
  38. package/middleware/utils/getScrollbarSize.d.ts +5 -0
  39. package/middleware/utils/getScrollbarSize.js +15 -0
  40. package/middleware/utils/getScrollbarSize.js.map +1 -0
  41. package/middleware/utils/useControllableValue.d.ts +16 -0
  42. package/middleware/utils/useControllableValue.js +28 -0
  43. package/middleware/utils/useControllableValue.js.map +1 -0
  44. package/package.json +34 -0
  45. package/styles/table.css +142 -0
  46. package/styles/table.scss +186 -0
package/index.esm.js ADDED
@@ -0,0 +1,1771 @@
1
+ import { jsx, jsxs, Fragment as Fragment$1 } from 'react/jsx-runtime';
2
+ import clsx from 'clsx';
3
+ import { useRef, createContext, useContext, useMemo, memo, useState, useLayoutEffect, useCallback, useEffect, Fragment, createElement, forwardRef } from 'react';
4
+
5
+ function _extends() {
6
+ return _extends = Object.assign ? Object.assign.bind() : function (n) {
7
+ for (var e = 1; e < arguments.length; e++) {
8
+ var t = arguments[e];
9
+ for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
10
+ }
11
+ return n;
12
+ }, _extends.apply(null, arguments);
13
+ }
14
+ function _objectWithoutPropertiesLoose(r, e) {
15
+ if (null == r) return {};
16
+ var t = {};
17
+ for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
18
+ if (e.includes(n)) continue;
19
+ t[n] = r[n];
20
+ }
21
+ return t;
22
+ }
23
+
24
+ function shallowEqualObjects(objA, objB) {
25
+ if (objA === objB) {
26
+ return true;
27
+ }
28
+ if (!objA || !objB) {
29
+ return false;
30
+ }
31
+ var aKeys = Object.keys(objA);
32
+ var bKeys = Object.keys(objB);
33
+ var len = aKeys.length;
34
+ if (bKeys.length !== len) {
35
+ return false;
36
+ }
37
+ for (var i = 0; i < len; i += 1) {
38
+ var key = aKeys[i];
39
+ if (objA[key] !== objB[key] || !Object.prototype.hasOwnProperty.call(objB, key)) {
40
+ return false;
41
+ }
42
+ }
43
+ return true;
44
+ }
45
+ function shallowEqualArrays(arrA, arrB) {
46
+ if (arrA === arrB) {
47
+ return true;
48
+ }
49
+ if (!arrA || !arrB) {
50
+ return false;
51
+ }
52
+ var len = arrA.length;
53
+ if (arrB.length !== len) {
54
+ return false;
55
+ }
56
+ for (var i = 0; i < len; i += 1) {
57
+ if (arrA[i] !== arrB[i]) {
58
+ return false;
59
+ }
60
+ }
61
+ return true;
62
+ }
63
+ function isShallowEqual(value, oldValue) {
64
+ if (Object.is(value, oldValue)) {
65
+ return true;
66
+ }
67
+ if (Array.isArray(value) && Array.isArray(oldValue)) {
68
+ if (shallowEqualArrays(value, oldValue)) {
69
+ return true;
70
+ }
71
+ if (value.length === oldValue.length) {
72
+ var hasObject = value.findIndex(function (x) {
73
+ return typeof x === 'object' && x != null;
74
+ }) > -1;
75
+ if (hasObject) {
76
+ return value.every(function (state, index) {
77
+ if (Array.isArray(state)) {
78
+ return shallowEqualArrays(state, oldValue[index]);
79
+ }
80
+ if (typeof state === 'object' && state != null) {
81
+ return shallowEqualObjects(state, oldValue[index]);
82
+ }
83
+ return Object.is(state, oldValue[index]);
84
+ });
85
+ }
86
+ }
87
+ return false;
88
+ }
89
+ if (value instanceof Map && oldValue instanceof Map) {
90
+ var keys = [].concat(value.keys());
91
+ var oldKeys = [].concat(oldValue.keys());
92
+ if (shallowEqualArrays(keys, oldKeys)) {
93
+ var values = [].concat(value.values());
94
+ var oldValues = [].concat(oldValue.values());
95
+ if (isShallowEqual(values, oldValues)) {
96
+ return true;
97
+ }
98
+ }
99
+ return false;
100
+ }
101
+ if (typeof value === 'object' && value != null) {
102
+ return shallowEqualObjects(value, oldValue);
103
+ }
104
+ return false;
105
+ }
106
+
107
+ /* eslint-disable react-compiler/react-compiler */
108
+ /**
109
+ * 缓存数据(浅比较,如果是数组则对第一层进行浅比较)
110
+ */
111
+ function useShallowMemo(pickData) {
112
+ var nextState = pickData();
113
+ var value = useRef(nextState);
114
+ if (!isShallowEqual(nextState, value.current)) {
115
+ value.current = nextState;
116
+ }
117
+ return value.current;
118
+ }
119
+
120
+ function getKey(column) {
121
+ return 'key' in column ? column.key : column.dataIndex;
122
+ }
123
+
124
+ function isValidFixedLeft(fixed) {
125
+ return fixed === 'left';
126
+ }
127
+ function isValidFixedRight(fixed) {
128
+ return fixed === 'right';
129
+ }
130
+ function isValidFixed(fixed) {
131
+ return isValidFixedLeft(fixed) || isValidFixedRight(fixed);
132
+ }
133
+
134
+ var ColumnSizes = /*#__PURE__*/createContext(null);
135
+ if (process.env.NODE_ENV === 'development') {
136
+ ColumnSizes.displayName = 'VirtualTable.ColumnSizes';
137
+ }
138
+ function useColumnSizes() {
139
+ var context = useContext(ColumnSizes);
140
+ if (context == null) {
141
+ throw new Error('useColumnSizes provider not found');
142
+ }
143
+ return context;
144
+ }
145
+
146
+ var Sticky = /*#__PURE__*/createContext(null);
147
+ if (process.env.NODE_ENV === 'development') {
148
+ Sticky.displayName = 'VirtualTable.Sticky';
149
+ }
150
+ function StickyContext(props) {
151
+ var columns = props.columns,
152
+ children = props.children;
153
+ var _useColumnSizes = useColumnSizes(),
154
+ widthList = _useColumnSizes.widthList;
155
+ var columnsFixedRecord = useMemo(function () {
156
+ return columns.map(function (column) {
157
+ var key = getKey(column);
158
+ return {
159
+ key: key,
160
+ fixed: column.fixed
161
+ };
162
+ });
163
+ }, [columns]);
164
+ var stickySizes = useMemo(function () {
165
+ var left = 0;
166
+ var leftOffset = columnsFixedRecord.reduce(function (res, item, index) {
167
+ var fixed = item.fixed,
168
+ key = item.key;
169
+ if (isValidFixedLeft(fixed)) {
170
+ var _widthList$get;
171
+ res[index] = left;
172
+ // eslint-disable-next-line react-compiler/react-compiler
173
+ left += (_widthList$get = widthList.get(key)) != null ? _widthList$get : 0;
174
+ }
175
+ return res;
176
+ }, []);
177
+ var right = 0;
178
+ var rightOffset = columnsFixedRecord.reduceRight(function (res, item, index) {
179
+ var fixed = item.fixed,
180
+ key = item.key;
181
+ if (isValidFixedRight(fixed)) {
182
+ var _widthList$get2;
183
+ res[index] = right;
184
+ right += (_widthList$get2 = widthList.get(key)) != null ? _widthList$get2 : 0;
185
+ }
186
+ return res;
187
+ }, []);
188
+ return columnsFixedRecord.reduce(function (result, item, index) {
189
+ var key = item.key,
190
+ fixed = item.fixed;
191
+ if (isValidFixedLeft(fixed)) {
192
+ result.set(key, leftOffset[index]);
193
+ return result;
194
+ }
195
+ if (isValidFixedRight(fixed)) {
196
+ result.set(key, rightOffset[index]);
197
+ return result;
198
+ }
199
+ return result;
200
+ }, new Map());
201
+ }, [columnsFixedRecord, widthList]);
202
+ var shallowMemoFixedRecord = useShallowMemo(function () {
203
+ return columnsFixedRecord;
204
+ });
205
+ var shallowMemoStickySizes = useShallowMemo(function () {
206
+ return stickySizes;
207
+ });
208
+ var stickyState = useMemo(function () {
209
+ return {
210
+ size: shallowMemoStickySizes,
211
+ fixed: shallowMemoFixedRecord
212
+ };
213
+ }, [shallowMemoFixedRecord, shallowMemoStickySizes]);
214
+ return jsx(Sticky.Provider, {
215
+ value: stickyState,
216
+ children: children
217
+ });
218
+ }
219
+ function useTableSticky() {
220
+ var context = useContext(Sticky);
221
+ if (context == null) {
222
+ throw new Error('useTableSticky provider not found');
223
+ }
224
+ return context;
225
+ }
226
+
227
+ function pipelineRender(node, render, options) {
228
+ if (typeof render === 'function') {
229
+ // @ts-expect-error: There is no way to declare the type correctly, but it works at runtime.
230
+ return render(node, options);
231
+ }
232
+ return node;
233
+ }
234
+
235
+ var _excluded$3 = ["className", "style", "column", "rowData", "rowIndex", "renderCell"],
236
+ _excluded2$1 = ["className", "style", "colSpan", "rowSpan"];
237
+ function getTableCellContent(index, data, column) {
238
+ var _render;
239
+ var render = column.render;
240
+ var rowData = data;
241
+ if ('dataIndex' in column) {
242
+ var dataIndex = column.dataIndex;
243
+ if (typeof render !== 'function') {
244
+ return rowData[dataIndex];
245
+ }
246
+ return render(rowData[dataIndex], data, index);
247
+ }
248
+ return (_render = render == null ? undefined : render(data, data, index)) != null ? _render : null;
249
+ }
250
+ function Cell(props) {
251
+ var _onCell;
252
+ var className = props.className,
253
+ style = props.style,
254
+ column = props.column,
255
+ rowData = props.rowData,
256
+ rowIndex = props.rowIndex,
257
+ renderCell = props.renderCell,
258
+ restProps = _objectWithoutPropertiesLoose(props, _excluded$3);
259
+ var align = column.align,
260
+ fixed = column.fixed,
261
+ onCell = column.onCell;
262
+ var key = getKey(column);
263
+ var _useTableSticky = useTableSticky(),
264
+ stickySizes = _useTableSticky.size;
265
+ var _ref = (_onCell = onCell == null ? undefined : onCell(rowData, rowIndex)) != null ? _onCell : {},
266
+ extraClassName = _ref.className,
267
+ extraStyle = _ref.style,
268
+ colSpan = _ref.colSpan,
269
+ rowSpan = _ref.rowSpan,
270
+ extraProps = _objectWithoutPropertiesLoose(_ref, _excluded2$1);
271
+ if (colSpan === 0 || rowSpan === 0) {
272
+ return null;
273
+ }
274
+ return pipelineRender(jsx("td", _extends({}, restProps, extraProps, {
275
+ colSpan: colSpan,
276
+ rowSpan: rowSpan,
277
+ className: clsx('virtual-table-cell', align != null && "virtual-table-align-" + align, isValidFixed(fixed) && 'virtual-table-sticky-cell', className, column.className, extraClassName),
278
+ style: _extends({}, style, extraStyle, {
279
+ left: isValidFixedLeft(fixed) ? stickySizes.get(key) : undefined,
280
+ right: isValidFixedRight(fixed) ? stickySizes.get(key) : undefined
281
+ }),
282
+ children: getTableCellContent(rowIndex, rowData, column)
283
+ })), renderCell, {
284
+ column: column
285
+ });
286
+ }
287
+ var Cell$1 = /*#__PURE__*/memo(Cell);
288
+
289
+ var Colgroup = function Colgroup(props) {
290
+ var columns = props.columns,
291
+ colRef = props.colRef;
292
+ return jsx("colgroup", {
293
+ children: columns.map(function (item, index) {
294
+ var key = item.key;
295
+ if (item.type === 'blank') {
296
+ return jsx("col", {
297
+ style: {
298
+ width: item.width
299
+ }
300
+ }, key);
301
+ }
302
+ var column = item.column;
303
+ return jsx("col", {
304
+ ref: typeof colRef === 'function' ? function (instance) {
305
+ colRef(instance, column, index);
306
+ } : colRef,
307
+ style: {
308
+ width: column.width,
309
+ minWidth: column.minWidth
310
+ }
311
+ }, key);
312
+ })
313
+ });
314
+ };
315
+
316
+ var overflowStylePatterns = /auto|scroll|overlay|hidden/;
317
+ function isElement(node) {
318
+ if (!(node instanceof Node)) {
319
+ return false;
320
+ }
321
+ var ELEMENT_NODE_TYPE = 1;
322
+ return node.nodeType === ELEMENT_NODE_TYPE;
323
+ }
324
+ function getScrollParent(el, root) {
325
+ var _el$ownerDocument$def;
326
+ if (root === undefined) {
327
+ root = window;
328
+ }
329
+ var node = el;
330
+ while (node !== root && isElement(node)) {
331
+ if (node === document.body) {
332
+ return root;
333
+ }
334
+ var _window$getComputedSt = window.getComputedStyle(node),
335
+ overflow = _window$getComputedSt.overflow,
336
+ overflowY = _window$getComputedSt.overflowY,
337
+ overflowX = _window$getComputedSt.overflowX;
338
+ if (overflowStylePatterns.test(overflow + overflowY + overflowX)) {
339
+ return node;
340
+ }
341
+ node = node.parentNode;
342
+ }
343
+ return (_el$ownerDocument$def = el.ownerDocument.defaultView) != null ? _el$ownerDocument$def : window;
344
+ }
345
+ function isWindow(arg) {
346
+ return Object.prototype.toString.call(arg) === '[object Window]';
347
+ }
348
+ function isDocument(arg) {
349
+ return Object.prototype.toString.call(arg) === '[object HTMLDocument]';
350
+ }
351
+ function isRoot(arg) {
352
+ return Object.prototype.toString.call(arg) === '[object HTMLHtmlElement]';
353
+ }
354
+ function getScrollElement(el) {
355
+ if (isDocument(el)) {
356
+ return el.scrollingElement;
357
+ }
358
+ if (isElement(el)) {
359
+ return el;
360
+ }
361
+ return document.scrollingElement;
362
+ }
363
+
364
+ function useCalcSize(options) {
365
+ var getScroller = options.getScroller,
366
+ root = options.root;
367
+ var _useState = useState(0),
368
+ scrollContainerWidth = _useState[0],
369
+ setScrollContainerWidth = _useState[1];
370
+ var _useState2 = useState(0),
371
+ scrollContainerHeight = _useState2[0],
372
+ setScrollContainerHeight = _useState2[1];
373
+ var _useState3 = useState(0),
374
+ tableWidth = _useState3[0],
375
+ setTableWidth = _useState3[1];
376
+ var _useState4 = useState(0),
377
+ tableHeight = _useState4[0],
378
+ setTableHeight = _useState4[1];
379
+ var scrollerContainerRef = useRef(null);
380
+ useLayoutEffect(function () {
381
+ var scrollerContainer = getScroller();
382
+ if (scrollerContainer == null) return;
383
+ var scroller;
384
+ if (isWindow(scrollerContainer)) {
385
+ scroller = document.scrollingElement;
386
+ } else {
387
+ scroller = scrollerContainer;
388
+ }
389
+ scrollerContainerRef.current = scroller;
390
+ var observer = new ResizeObserver(function (entries) {
391
+ var _entries$0$contentRec = entries[0].contentRect,
392
+ width = _entries$0$contentRec.width,
393
+ height = _entries$0$contentRec.height;
394
+ setScrollContainerWidth(width);
395
+ setScrollContainerHeight(height);
396
+ });
397
+ observer.observe(scroller);
398
+ return function () {
399
+ observer.disconnect();
400
+ };
401
+ }, [getScroller]);
402
+ useLayoutEffect(function () {
403
+ var node = root.current;
404
+ if (node == null) return;
405
+ var observer = new ResizeObserver(function (entries) {
406
+ var _entries$0$contentRec2 = entries[0].contentRect,
407
+ width = _entries$0$contentRec2.width,
408
+ height = _entries$0$contentRec2.height;
409
+ setTableWidth(width);
410
+ setTableHeight(height);
411
+ });
412
+ observer.observe(node);
413
+ return function () {
414
+ observer.disconnect();
415
+ };
416
+ }, [root]);
417
+ return {
418
+ scrollContainerWidth: scrollContainerWidth,
419
+ scrollContainerHeight: scrollContainerHeight,
420
+ tableWidth: tableWidth,
421
+ tableHeight: tableHeight
422
+ };
423
+ }
424
+
425
+ var ContainerSize = /*#__PURE__*/createContext(null);
426
+ function ContainerSizeContext(props) {
427
+ var getScroller = props.getScroller,
428
+ root = props.root,
429
+ children = props.children;
430
+ var _useCalcSize = useCalcSize({
431
+ getScroller: getScroller,
432
+ root: root
433
+ }),
434
+ scrollContainerHeight = _useCalcSize.scrollContainerHeight,
435
+ scrollContainerWidth = _useCalcSize.scrollContainerWidth,
436
+ tableHeight = _useCalcSize.tableHeight,
437
+ tableWidth = _useCalcSize.tableWidth;
438
+ var state = useMemo(function () {
439
+ return {
440
+ scrollContainerWidth: scrollContainerWidth,
441
+ scrollContainerHeight: scrollContainerHeight,
442
+ tableWidth: tableWidth,
443
+ tableHeight: tableHeight
444
+ };
445
+ }, [scrollContainerWidth, scrollContainerHeight, tableWidth, tableHeight]);
446
+ return jsx(ContainerSize.Provider, {
447
+ value: state,
448
+ children: children
449
+ });
450
+ }
451
+ function useContainerSize() {
452
+ var context = useContext(ContainerSize);
453
+ if (context == null) {
454
+ throw new Error('useContainerSize provider not found');
455
+ }
456
+ return context;
457
+ }
458
+
459
+ var HorizontalScroll = /*#__PURE__*/createContext(null);
460
+ if (process.env.NODE_ENV === 'development') {
461
+ HorizontalScroll.displayName = 'VirtualTable.HorizontalScroll';
462
+ }
463
+ function HorizontalScrollContext(props) {
464
+ var children = props.children;
465
+ var listenerMap = useRef(new Map());
466
+ var context = useMemo(function () {
467
+ return {
468
+ listen: function listen(key, listener) {
469
+ listenerMap.current.set(key, listener);
470
+ return function () {
471
+ listenerMap.current["delete"](key);
472
+ };
473
+ },
474
+ notify: function notify(key, scrollLeft, node) {
475
+ var rAF = window.requestAnimationFrame;
476
+ if (rAF == null) {
477
+ rAF = function rAF(fn) {
478
+ fn();
479
+ };
480
+ }
481
+ rAF(function () {
482
+ listenerMap.current.forEach(function (listener, itemKey) {
483
+ if (itemKey !== key) {
484
+ listener(scrollLeft, node);
485
+ }
486
+ });
487
+ });
488
+ }
489
+ };
490
+ }, []);
491
+ return jsx(HorizontalScroll.Provider, {
492
+ value: context,
493
+ children: children
494
+ });
495
+ }
496
+ function useHorizontalScrollContext() {
497
+ var context = useContext(HorizontalScroll);
498
+ if (context == null) {
499
+ throw new Error('useHorizontalScrollContext provider not found');
500
+ }
501
+ return context;
502
+ }
503
+
504
+ var TableRowManager = /*#__PURE__*/createContext(null);
505
+ if (process.env.NODE_ENV === 'development') {
506
+ TableRowManager.displayName = 'VirtualTable.RowManager';
507
+ }
508
+ function useTableRowManager() {
509
+ var context = useContext(TableRowManager);
510
+ if (context == null) {
511
+ throw new Error('useTableRowManager provider not found');
512
+ }
513
+ return context;
514
+ }
515
+
516
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
517
+ function useStableFn(callback) {
518
+ var fn = useRef(null);
519
+ useLayoutEffect(function () {
520
+ fn.current = callback;
521
+ }, [callback]);
522
+ var stableFn = useCallback(function () {
523
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
524
+ args[_key] = arguments[_key];
525
+ }
526
+ return fn.current == null ? undefined : fn.current.apply(fn, args);
527
+ }, []);
528
+ return stableFn;
529
+ }
530
+
531
+ /**
532
+ * 创建中间件,内部会浅比较 options,只有 options 改变才会返回新的函数。
533
+ */
534
+ function createMiddleware(hook) {
535
+ var cache = {
536
+ current: null,
537
+ options: null
538
+ };
539
+ return function () {
540
+ for (var _len = arguments.length, options = new Array(_len), _key = 0; _key < _len; _key++) {
541
+ options[_key] = arguments[_key];
542
+ }
543
+ var useMiddleware = function useMiddleware(ctx) {
544
+ return hook.apply(undefined, [ctx].concat(options));
545
+ };
546
+ if (isShallowEqual(options, cache.options)) {
547
+ var _cache$current;
548
+ return (_cache$current = cache.current) != null ? _cache$current : useMiddleware;
549
+ }
550
+ cache.options = options;
551
+ cache.current = useMiddleware;
552
+ return useMiddleware;
553
+ };
554
+ }
555
+
556
+ var _excluded$2 = ["render", "renderRoot", "renderContent", "renderHeaderWrapper", "renderHeaderRoot", "renderHeader", "renderHeaderRow", "renderHeaderCell", "renderBodyWrapper", "renderBodyRoot", "renderBody", "renderRow", "renderCell", "rowClassName", "onRow"];
557
+ function shakeUnsafeHooks(hooks) {
558
+ if (Array.isArray(hooks)) {
559
+ return hooks.filter(function (x) {
560
+ return x != null && (typeof x === 'function' || typeof x.hook === 'function');
561
+ }).map(function (hook) {
562
+ if (typeof hook === 'function') {
563
+ return {
564
+ priority: 100,
565
+ hook: hook
566
+ };
567
+ }
568
+ return hook;
569
+ });
570
+ }
571
+ return [];
572
+ }
573
+ var TablePipeline = /*#__PURE__*/function () {
574
+ function TablePipeline() {
575
+ Object.defineProperty(this, "hooks", {
576
+ enumerable: true,
577
+ configurable: true,
578
+ writable: true,
579
+ value: []
580
+ });
581
+ this.use = this.use.bind(this);
582
+ }
583
+ var _proto = TablePipeline.prototype;
584
+ _proto.setHooks = function setHooks(value) {
585
+ this.hooks = value;
586
+ };
587
+ _proto.use = function use(options) {
588
+ if (this.hooks.length === 0) {
589
+ return options;
590
+ }
591
+ var context = {
592
+ current: options
593
+ };
594
+ var renderFunctionMap = {
595
+ render: [],
596
+ renderRoot: [],
597
+ renderContent: [],
598
+ renderHeaderWrapper: [],
599
+ renderHeaderRoot: [],
600
+ renderHeader: [],
601
+ renderHeaderRow: [],
602
+ renderHeaderCell: [],
603
+ renderBodyWrapper: [],
604
+ renderBodyRoot: [],
605
+ renderBody: [],
606
+ renderRow: [],
607
+ renderCell: []
608
+ };
609
+ var rowClassNameFunctions = [];
610
+ var onRowFunctions = [];
611
+ var hooks = this.hooks.slice();
612
+ hooks.sort(function (a, b) {
613
+ return a.priority - b.priority;
614
+ });
615
+ hooks.map(function (x) {
616
+ return x.hook;
617
+ }).forEach(function (hook) {
618
+ var nextCtx = hook(context.current);
619
+ nextCtx.render;
620
+ nextCtx.renderRoot;
621
+ nextCtx.renderContent;
622
+ nextCtx.renderHeaderWrapper;
623
+ nextCtx.renderHeaderRoot;
624
+ nextCtx.renderHeader;
625
+ nextCtx.renderHeaderRow;
626
+ nextCtx.renderHeaderCell;
627
+ nextCtx.renderBodyWrapper;
628
+ nextCtx.renderBodyRoot;
629
+ nextCtx.renderBody;
630
+ nextCtx.renderRow;
631
+ nextCtx.renderCell;
632
+ var rowClassName = nextCtx.rowClassName,
633
+ onRow = nextCtx.onRow,
634
+ rest = _objectWithoutPropertiesLoose(nextCtx, _excluded$2);
635
+ Object.entries(renderFunctionMap).forEach(function (_ref) {
636
+ var key = _ref[0],
637
+ value = _ref[1];
638
+ var target = nextCtx[key];
639
+ if (typeof target === 'function') {
640
+ // @ts-expect-error: There is no way to declare the type correctly, but it works at runtime.
641
+ value.push(target);
642
+ }
643
+ });
644
+ if (typeof rowClassName === 'function') {
645
+ rowClassNameFunctions.push(rowClassName);
646
+ }
647
+ if (typeof onRow === 'function') {
648
+ onRowFunctions.push(onRow);
649
+ }
650
+ context.current = rest;
651
+ });
652
+ Object.entries(renderFunctionMap).forEach(function (_ref2) {
653
+ var key = _ref2[0],
654
+ renders = _ref2[1];
655
+ if (renders.length > 0) {
656
+ context.current[key] = function (children, args) {
657
+ // reduce 把 [render1, render2] 转为 render1(render2(children))
658
+ return renders.reduce(function (node, render) {
659
+ // @ts-expect-error: There is no way to declare the type correctly, but it works at runtime.
660
+ return render(node, args);
661
+ }, children);
662
+ };
663
+ }
664
+ });
665
+ if (rowClassNameFunctions.length > 0) {
666
+ context.current.rowClassName = function (record, index) {
667
+ return clsx.apply(undefined, rowClassNameFunctions.map(function (fn) {
668
+ return fn(record, index);
669
+ }));
670
+ };
671
+ }
672
+ if (onRowFunctions.length > 0) {
673
+ context.current.onRow = function (record, index) {
674
+ return onRowFunctions.reduce(function (result, item) {
675
+ return _extends({}, result, item(record, index));
676
+ }, {});
677
+ };
678
+ }
679
+ return context.current;
680
+ };
681
+ return TablePipeline;
682
+ }();
683
+ Object.defineProperty(TablePipeline, "defaultPipeline", {
684
+ enumerable: true,
685
+ configurable: true,
686
+ writable: true,
687
+ value: new TablePipeline()
688
+ });
689
+
690
+ function useTablePipeline(options) {
691
+ var use = options.use,
692
+ extraPipeline = options.pipeline;
693
+ var cached = useMemo(function () {
694
+ return {
695
+ current: new TablePipeline()
696
+ };
697
+ }, []);
698
+ if (use != null) {
699
+ var _extraPipeline$hooks;
700
+ var nextHooks = shakeUnsafeHooks([].concat(use, (_extraPipeline$hooks = extraPipeline == null ? undefined : extraPipeline.hooks) != null ? _extraPipeline$hooks : []));
701
+ if (!shallowEqualArrays(cached.current.hooks, nextHooks)) {
702
+ var pipeline = new TablePipeline();
703
+ pipeline.setHooks(nextHooks);
704
+ cached.current = pipeline;
705
+ return pipeline;
706
+ }
707
+ }
708
+ return cached.current;
709
+ }
710
+
711
+ function findLastIndex(arr, predicate) {
712
+ var result = -1;
713
+ for (var i = 0; i < arr.length; i += 1) {
714
+ if (predicate(arr[i], i)) {
715
+ result = i;
716
+ }
717
+ }
718
+ return result;
719
+ }
720
+
721
+ var _excluded$1 = ["className", "rowIndex", "rowData", "columns", "onRow", "renderRow", "renderCell"],
722
+ _excluded2 = ["className"];
723
+ function Row(props) {
724
+ var _onRow;
725
+ var className = props.className,
726
+ rowIndex = props.rowIndex,
727
+ rowData = props.rowData,
728
+ columnDescriptor = props.columns,
729
+ onRow = props.onRow,
730
+ renderRow = props.renderRow,
731
+ renderCell = props.renderCell,
732
+ rest = _objectWithoutPropertiesLoose(props, _excluded$1);
733
+ var _useTableRowManager = useTableRowManager(),
734
+ updateRowHeight = _useTableRowManager.updateRowHeight;
735
+ var columns = columnDescriptor.columns,
736
+ descriptor = columnDescriptor.descriptor;
737
+ var lastFixedLeftColumnIndex = findLastIndex(descriptor, function (x) {
738
+ if (x.type === 'blank') {
739
+ return false;
740
+ }
741
+ return isValidFixedLeft(x.column.fixed);
742
+ });
743
+ var firstFixedRightColumnIndex = descriptor.findIndex(function (x) {
744
+ if (x.type === 'blank') {
745
+ return false;
746
+ }
747
+ return isValidFixedRight(x.column.fixed);
748
+ });
749
+ var _ref = (_onRow = onRow == null ? undefined : onRow(rowData, rowIndex)) != null ? _onRow : {},
750
+ extraClassName = _ref.className,
751
+ extraProps = _objectWithoutPropertiesLoose(_ref, _excluded2);
752
+ return pipelineRender(jsx("tr", _extends({}, rest, extraProps, {
753
+ className: clsx('virtual-table-row', className, extraClassName),
754
+ ref: function ref(node) {
755
+ if (node == null) return;
756
+ // 小心陷阱:当 table 父元素为 display: none 时,依然会触发 updateRowHeight 函数,并设置高度为 0
757
+ updateRowHeight(rowIndex, node.offsetHeight);
758
+ },
759
+ children: descriptor.map(function (item, index) {
760
+ var key = item.key;
761
+ if (item.type === 'blank') {
762
+ return jsx("td", {}, key);
763
+ }
764
+ var column = item.column;
765
+ return jsx(Cell$1, {
766
+ className: clsx(lastFixedLeftColumnIndex === index && 'virtual-table-cell-fix-left-last', firstFixedRightColumnIndex === index && 'virtual-table-cell-fix-right-first'),
767
+ column: column,
768
+ rowIndex: rowIndex,
769
+ rowData: rowData,
770
+ renderCell: renderCell
771
+ }, key);
772
+ })
773
+ })), renderRow, {
774
+ columns: columns,
775
+ rowIndex: rowIndex,
776
+ rowData: rowData,
777
+ columnDescriptor: descriptor
778
+ });
779
+ }
780
+ var Row$1 = /*#__PURE__*/memo(Row);
781
+
782
+ function assignRef(ref, value) {
783
+ if (typeof ref === 'function') {
784
+ ref(value);
785
+ } else if (typeof ref === 'object' && ref !== null && 'current' in ref) {
786
+ ref.current = value;
787
+ }
788
+ }
789
+ function mergeRefs() {
790
+ for (var _len = arguments.length, refs = new Array(_len), _key = 0; _key < _len; _key++) {
791
+ refs[_key] = arguments[_key];
792
+ }
793
+ return function (node) {
794
+ refs.forEach(function (ref) {
795
+ return assignRef(ref, node);
796
+ });
797
+ };
798
+ }
799
+ function useMergedRef() {
800
+ for (var _len2 = arguments.length, refs = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
801
+ refs[_key2] = arguments[_key2];
802
+ }
803
+ // eslint-disable-next-line react-compiler/react-compiler
804
+ return useCallback(mergeRefs.apply(undefined, refs), refs);
805
+ }
806
+
807
+ function TableBody(props) {
808
+ var bodyWrapperRef = props.bodyWrapperRef,
809
+ bodyRootRef = props.bodyRootRef,
810
+ bodyRef = props.bodyRef,
811
+ className = props.className,
812
+ style = props.style,
813
+ dataSource = props.dataSource,
814
+ columnDescriptor = props.columns,
815
+ rowKey = props.rowKey,
816
+ startIndex = props.startIndex,
817
+ rowClassName = props.rowClassName,
818
+ onRow = props.onRow,
819
+ renderBodyWrapper = props.renderBodyWrapper,
820
+ renderBodyRoot = props.renderBodyRoot,
821
+ renderBody = props.renderBody,
822
+ renderRow = props.renderRow,
823
+ renderCell = props.renderCell;
824
+ var columns = columnDescriptor.columns,
825
+ descriptor = columnDescriptor.descriptor;
826
+ var _useHorizontalScrollC = useHorizontalScrollContext(),
827
+ listen = _useHorizontalScrollC.listen,
828
+ notify = _useHorizontalScrollC.notify;
829
+ var _useColumnSizes = useColumnSizes(),
830
+ widthList = _useColumnSizes.widthList,
831
+ setWidthList = _useColumnSizes.setWidthList;
832
+ var columnWidthsRef = useRef(new Map());
833
+ useLayoutEffect(function () {
834
+ var snap = widthList;
835
+ if (!isShallowEqual(snap, columnWidthsRef.current)) {
836
+ setWidthList(new Map(columnWidthsRef.current));
837
+ }
838
+ });
839
+ var bodyNode = pipelineRender(jsx("tbody", {
840
+ ref: bodyRef,
841
+ children: dataSource.map(function (e, rowIndex) {
842
+ var _rowKey = e[rowKey];
843
+ return jsx(Row$1, {
844
+ className: clsx(rowClassName == null ? undefined : rowClassName(e, rowIndex)),
845
+ rowIndex: rowIndex + startIndex,
846
+ rowData: e,
847
+ columns: columnDescriptor,
848
+ onRow: onRow,
849
+ renderRow: renderRow,
850
+ renderCell: renderCell
851
+ }, _rowKey);
852
+ })
853
+ }), renderBody, {
854
+ columns: columns,
855
+ columnDescriptor: descriptor
856
+ });
857
+ var tableNode = pipelineRender(jsxs("table", {
858
+ className: clsx(className, 'virtual-table-body'),
859
+ style: style,
860
+ ref: bodyRootRef,
861
+ children: [jsx(Colgroup, {
862
+ columns: descriptor,
863
+ colRef: function colRef(node, column) {
864
+ if (node == null) return;
865
+ var key = getKey(column);
866
+ columnWidthsRef.current.set(key, node.offsetWidth);
867
+ }
868
+ }), bodyNode]
869
+ }), renderBodyRoot, {
870
+ columns: columns,
871
+ columnDescriptor: descriptor
872
+ });
873
+ var wrapperRef = useRef(null);
874
+ useEffect(function () {
875
+ var node = wrapperRef.current;
876
+ if (node == null) return;
877
+ var key = 'virtual-table-body';
878
+ var onScroll = function onScroll() {
879
+ var nextScrollLeft = node.scrollLeft;
880
+ notify(key, nextScrollLeft, node);
881
+ };
882
+ var dispose = listen(key, function (scrollLeft) {
883
+ node.scrollLeft = scrollLeft;
884
+ });
885
+ node.addEventListener('scroll', onScroll);
886
+ return function () {
887
+ node.removeEventListener('scroll', onScroll);
888
+ dispose();
889
+ };
890
+ }, [listen, notify]);
891
+ var mergedRef = useMergedRef(wrapperRef, bodyWrapperRef);
892
+ return pipelineRender(jsx("div", {
893
+ ref: mergedRef,
894
+ className: "virtual-table-body-wrapper",
895
+ children: tableNode
896
+ }), renderBodyWrapper, {
897
+ columns: columns,
898
+ columnDescriptor: descriptor
899
+ });
900
+ }
901
+
902
+ var _excluded = ["className", "style"];
903
+ var TableHeader = function TableHeader(props) {
904
+ var className = props.className,
905
+ style = props.style,
906
+ wrapperRef = props.wrapperRef,
907
+ columnDescriptor = props.columns,
908
+ stickyHeader = props.stickyHeader,
909
+ renderHeaderWrapper = props.renderHeaderWrapper,
910
+ renderHeaderRoot = props.renderHeaderRoot,
911
+ renderHeader = props.renderHeader,
912
+ renderHeaderRow = props.renderHeaderRow,
913
+ renderHeaderCell = props.renderHeaderCell;
914
+ var columns = columnDescriptor.columns,
915
+ descriptor = columnDescriptor.descriptor;
916
+ var _useColumnSizes = useColumnSizes(),
917
+ widthList = _useColumnSizes.widthList;
918
+ var _useTableSticky = useTableSticky(),
919
+ stickySizes = _useTableSticky.size;
920
+ var lastFixedLeftColumnIndex = findLastIndex(descriptor, function (x) {
921
+ if (x.type === 'blank') {
922
+ return false;
923
+ }
924
+ return isValidFixedLeft(x.column.fixed);
925
+ });
926
+ var firstFixedRightColumnIndex = descriptor.findIndex(function (x) {
927
+ if (x.type === 'blank') {
928
+ return false;
929
+ }
930
+ return isValidFixedRight(x.column.fixed);
931
+ });
932
+ var _useHorizontalScrollC = useHorizontalScrollContext(),
933
+ listen = _useHorizontalScrollC.listen,
934
+ notify = _useHorizontalScrollC.notify;
935
+ var headerWrapperRef = useRef(null);
936
+ useEffect(function () {
937
+ var node = headerWrapperRef.current;
938
+ if (node == null) return;
939
+ var key = 'virtual-table-header';
940
+ var onScroll = function onScroll() {
941
+ var nextScrollLeft = node.scrollLeft;
942
+ notify(key, nextScrollLeft, node);
943
+ };
944
+ var dispose = listen(key, function (scrollLeft) {
945
+ node.scrollLeft = scrollLeft;
946
+ });
947
+ node.addEventListener('scroll', onScroll);
948
+ return function () {
949
+ node.removeEventListener('scroll', onScroll);
950
+ dispose();
951
+ };
952
+ }, [listen, notify]);
953
+ var row = pipelineRender(jsx("tr", {
954
+ children: descriptor.map(function (item, index) {
955
+ var _column$onHeaderCell;
956
+ var key = item.key;
957
+ if (item.type === 'blank') {
958
+ return jsx("th", {}, key);
959
+ }
960
+ var column = item.column;
961
+ if (column.colSpan === 0) {
962
+ return null;
963
+ }
964
+ var _ref = (_column$onHeaderCell = column.onHeaderCell == null ? undefined : column.onHeaderCell(column, index)) != null ? _column$onHeaderCell : {},
965
+ thClassName = _ref.className,
966
+ thStyle = _ref.style,
967
+ rest = _objectWithoutPropertiesLoose(_ref, _excluded);
968
+ return jsx(Fragment, {
969
+ children: pipelineRender(/*#__PURE__*/createElement('th', _extends({
970
+ scope: 'col'
971
+ }, rest, {
972
+ colSpan: column.colSpan,
973
+ className: clsx('virtual-table-header-cell', column.align != null && "virtual-table-align-" + column.align, isValidFixed(column.fixed) && 'virtual-table-sticky-cell', lastFixedLeftColumnIndex === index && 'virtual-table-cell-fix-left-last', firstFixedRightColumnIndex === index && 'virtual-table-cell-fix-right-first', column.className, thClassName),
974
+ style: _extends({}, thStyle, {
975
+ left: isValidFixedLeft(column.fixed) ? stickySizes.get(key) : undefined,
976
+ right: isValidFixedRight(column.fixed) ? stickySizes.get(key) : undefined
977
+ })
978
+ }), column.title), renderHeaderCell, {
979
+ column: column,
980
+ columns: columns,
981
+ columnWidths: widthList,
982
+ columnDescriptor: descriptor
983
+ })
984
+ }, key);
985
+ })
986
+ }), renderHeaderRow, {
987
+ columns: columns,
988
+ columnDescriptor: descriptor
989
+ });
990
+ var theadNode = pipelineRender(jsx("thead", {
991
+ className: "virtual-table-thead",
992
+ children: row
993
+ }), renderHeader, {
994
+ columns: columns,
995
+ columnDescriptor: descriptor
996
+ });
997
+ var tableNode = pipelineRender(jsxs("table", {
998
+ style: style,
999
+ children: [jsx(Colgroup, {
1000
+ columns: descriptor
1001
+ }), theadNode]
1002
+ }), renderHeaderRoot, {
1003
+ columns: columns,
1004
+ columnDescriptor: descriptor
1005
+ });
1006
+ var mergedRef = useMergedRef(wrapperRef, headerWrapperRef);
1007
+ return pipelineRender(jsx("div", {
1008
+ ref: mergedRef,
1009
+ className: clsx('virtual-table-header', className, {
1010
+ 'virtual-table-header-sticky': stickyHeader
1011
+ }),
1012
+ style: {
1013
+ top: Number.isFinite(stickyHeader) ? stickyHeader : undefined
1014
+ },
1015
+ children: tableNode
1016
+ }), renderHeaderWrapper, {
1017
+ columns: columns,
1018
+ columnDescriptor: descriptor
1019
+ });
1020
+ };
1021
+
1022
+ function onResize(target, callback) {
1023
+ if (isWindow(target)) {
1024
+ var listener = function listener() {
1025
+ callback({
1026
+ width: window.innerWidth,
1027
+ height: window.innerHeight
1028
+ });
1029
+ };
1030
+ listener();
1031
+ window.addEventListener('resize', listener);
1032
+ return function () {
1033
+ window.removeEventListener('resize', listener);
1034
+ };
1035
+ } else {
1036
+ var observer = new ResizeObserver(function (entries) {
1037
+ var rect = entries[0].contentRect;
1038
+ callback({
1039
+ width: rect.width,
1040
+ height: rect.height
1041
+ });
1042
+ });
1043
+ observer.observe(target);
1044
+ return function () {
1045
+ observer.disconnect();
1046
+ };
1047
+ }
1048
+ }
1049
+
1050
+ function anchorQuery$1(rects, scrollLeft) {
1051
+ var left = 0;
1052
+ var right = rects.length - 1;
1053
+ var index = -1;
1054
+ while (left <= right) {
1055
+ var mid = Math.floor((left + right) / 2);
1056
+ if (rects[mid].right > scrollLeft) {
1057
+ index = mid;
1058
+ right = mid - 1;
1059
+ } else {
1060
+ left = mid + 1;
1061
+ }
1062
+ }
1063
+ if (index === -1) {
1064
+ return undefined;
1065
+ }
1066
+ return rects[index];
1067
+ }
1068
+ function findFirstFixedRightIndex(columns) {
1069
+ var index = -1;
1070
+ for (var i = columns.length - 1; i >= 0; i--) {
1071
+ var column = columns[i];
1072
+ if (isValidFixedRight(column.fixed)) {
1073
+ index = i;
1074
+ } else {
1075
+ break;
1076
+ }
1077
+ }
1078
+ return index;
1079
+ }
1080
+ function findLastFixedLeftIndex(columns) {
1081
+ return findLastIndex(columns, function (x) {
1082
+ return isValidFixedLeft(x.fixed);
1083
+ });
1084
+ }
1085
+ function useColumnVirtualize(options) {
1086
+ var estimateSize = options.estimateSize,
1087
+ overscan = options.overscan,
1088
+ rawColumns = options.columns,
1089
+ bodyWrapper = options.bodyWrapper,
1090
+ columnWidths = options.columnWidths,
1091
+ _options$disabled = options.disabled,
1092
+ disabled = _options$disabled === undefined ? false : _options$disabled;
1093
+ var lastFixedLeftIndex = findLastFixedLeftIndex(rawColumns);
1094
+ var firstFixedRightIndex = findFirstFixedRightIndex(rawColumns);
1095
+ var leftKey = lastFixedLeftIndex > -1 ? getKey(rawColumns[lastFixedLeftIndex]) : null;
1096
+ var rightKey = firstFixedRightIndex > -1 ? getKey(rawColumns[firstFixedRightIndex]) : null;
1097
+ var _useState = useState(0),
1098
+ startIndex = _useState[0],
1099
+ setStartIndex = _useState[1];
1100
+ var _useState2 = useState(0),
1101
+ endIndex = _useState2[0],
1102
+ setEndIndex = _useState2[1];
1103
+ var rects = useMemo(function () {
1104
+ if (disabled) {
1105
+ return [];
1106
+ }
1107
+ var left = 0;
1108
+ return rawColumns.map(function (column, index) {
1109
+ var _columnWidths$get;
1110
+ var key = getKey(column);
1111
+ var width = (_columnWidths$get = columnWidths.get(key)) != null ? _columnWidths$get : estimateSize;
1112
+ var right = left + width;
1113
+ var rect = {
1114
+ index: index,
1115
+ width: width,
1116
+ left: left,
1117
+ right: right
1118
+ };
1119
+ left = right;
1120
+ return rect;
1121
+ });
1122
+ }, [rawColumns, columnWidths, estimateSize, disabled]);
1123
+ // 锚点元素
1124
+ var anchorRef = useRef({
1125
+ index: 0,
1126
+ width: estimateSize,
1127
+ left: 0,
1128
+ right: estimateSize
1129
+ });
1130
+ var findAnchorRef = useStableFn(function (scrollLeft) {
1131
+ return anchorQuery$1(rects, scrollLeft);
1132
+ });
1133
+ var updateBoundary = useStableFn(function (scrollLeft, count) {
1134
+ var anchor = findAnchorRef(scrollLeft);
1135
+ if (anchor != null) {
1136
+ anchorRef.current = anchor;
1137
+ setStartIndex(Math.max(0, anchor.index - overscan));
1138
+ setEndIndex(anchor.index + count + overscan);
1139
+ }
1140
+ });
1141
+ // 用来判断滚动方向
1142
+ var scrollLeftRef = useRef(0);
1143
+ useEffect(function () {
1144
+ if (disabled) return;
1145
+ var scrollContainer = bodyWrapper.current;
1146
+ if (scrollContainer == null) return;
1147
+ var containerWidth = scrollContainer.offsetWidth;
1148
+ var count = Math.ceil(containerWidth / estimateSize);
1149
+ var onScroll = function onScroll() {
1150
+ var scrollLeft = scrollContainer.scrollLeft;
1151
+ // 滚动条向右移动(界面向左运动)
1152
+ var isScrollRight = scrollLeft > scrollLeftRef.current;
1153
+ if (isScrollRight) {
1154
+ if (scrollLeft > anchorRef.current.right) {
1155
+ updateBoundary(scrollLeft, count);
1156
+ }
1157
+ } else {
1158
+ if (scrollLeft < anchorRef.current.left) {
1159
+ updateBoundary(scrollLeft, count);
1160
+ }
1161
+ }
1162
+ scrollLeftRef.current = scrollLeft;
1163
+ };
1164
+ scrollContainer.addEventListener('scroll', onScroll);
1165
+ var prevWidth = 0;
1166
+ var stop = onResize(scrollContainer, function (_ref) {
1167
+ var width = _ref.width;
1168
+ if (width === prevWidth || width === 0) {
1169
+ return;
1170
+ }
1171
+ prevWidth = width;
1172
+ var scrollLeft = scrollContainer.scrollLeft;
1173
+ count = Math.ceil(width / estimateSize);
1174
+ updateBoundary(scrollLeft, count);
1175
+ });
1176
+ return function () {
1177
+ scrollContainer.removeEventListener('scroll', onScroll);
1178
+ stop();
1179
+ };
1180
+ }, [bodyWrapper, estimateSize, updateBoundary, overscan, findAnchorRef, disabled]);
1181
+ var sum = function sum(startIndex, endIndex) {
1182
+ return rects.slice(startIndex, endIndex).reduce(function (a, b) {
1183
+ return a + b.width;
1184
+ }, 0);
1185
+ };
1186
+ var fixedLeftWidth = lastFixedLeftIndex > -1 ? sum(0, lastFixedLeftIndex + 1) : 0;
1187
+ var fixedRightWidth = firstFixedRightIndex > -1 ? sum(firstFixedRightIndex) : 0;
1188
+ // 设置 column.fixed 时,对应列将不会虚拟化,所以 blank 需要去除这些列的宽度
1189
+ var leftBlank = Math.max(0, sum(0, startIndex) - fixedLeftWidth);
1190
+ var rightBlank = Math.max(0, sum(endIndex) - fixedRightWidth);
1191
+ var columnSlice = useMemo(function () {
1192
+ if (disabled) {
1193
+ return rawColumns;
1194
+ }
1195
+ var result = [].concat(rawColumns.slice(0, lastFixedLeftIndex + 1), rawColumns.slice(startIndex, endIndex), rawColumns.slice(firstFixedRightIndex));
1196
+ var unionKey = new Set();
1197
+ return result.filter(function (column) {
1198
+ var key = getKey(column);
1199
+ if (unionKey.has(key)) {
1200
+ return false;
1201
+ }
1202
+ unionKey.add(key);
1203
+ return true;
1204
+ });
1205
+ }, [disabled, rawColumns, startIndex, endIndex, lastFixedLeftIndex, firstFixedRightIndex]);
1206
+ var descriptor = useMemo(function () {
1207
+ return columnSlice.reduce(function (result, column) {
1208
+ var key = getKey(column);
1209
+ if (key === leftKey) {
1210
+ result.push({
1211
+ key: key,
1212
+ type: 'normal',
1213
+ column: column
1214
+ });
1215
+ result.push({
1216
+ key: '_blank_left',
1217
+ type: 'blank',
1218
+ width: leftBlank
1219
+ });
1220
+ } else if (key === rightKey) {
1221
+ result.push({
1222
+ key: '_blank_right',
1223
+ type: 'blank',
1224
+ width: rightBlank
1225
+ });
1226
+ result.push({
1227
+ key: key,
1228
+ type: 'normal',
1229
+ column: column
1230
+ });
1231
+ } else {
1232
+ result.push({
1233
+ key: key,
1234
+ type: 'normal',
1235
+ column: column
1236
+ });
1237
+ }
1238
+ return result;
1239
+ }, []);
1240
+ }, [columnSlice, leftKey, rightKey, leftBlank, rightBlank]);
1241
+ var columns = useMemo(function () {
1242
+ return {
1243
+ columns: columnSlice,
1244
+ descriptor: descriptor
1245
+ };
1246
+ }, [columnSlice, descriptor]);
1247
+ return {
1248
+ columns: columns,
1249
+ columnSlice: columnSlice,
1250
+ lastFixedLeftIndex: lastFixedLeftIndex,
1251
+ firstFixedRightIndex: firstFixedRightIndex
1252
+ };
1253
+ }
1254
+
1255
+ function useRowRectManager(options) {
1256
+ var itemCount = options.itemCount,
1257
+ estimateSize = options.estimateSize,
1258
+ onChange = options.onChange;
1259
+ var rowHeightList = useRef([]);
1260
+ var calc = function calc() {
1261
+ for (var i = 0; i < itemCount; i += 1) {
1262
+ var target = rowHeightList.current[i];
1263
+ if (target == null) {
1264
+ rowHeightList.current[i] = estimateSize;
1265
+ }
1266
+ }
1267
+ rowHeightList.current = rowHeightList.current.slice(0, itemCount);
1268
+ };
1269
+ // eslint-disable-next-line react-compiler/react-compiler
1270
+ calc();
1271
+ // const initialCount = useRef(itemCount)
1272
+ // const [, forceUpdate] = useReducer((x) => !x, false)
1273
+ // useLayoutEffect(() => {
1274
+ // for (let i = 0; i < itemCount; i += 1) {
1275
+ // const target = rowHeightList.current[i]
1276
+ // if (target == null) {
1277
+ // rowHeightList.current[i] = estimatedRowHeight
1278
+ // }
1279
+ // }
1280
+ // // 数据量骤减时如果 row 数量不匹配则会导致容器高度错误
1281
+ // rowHeightList.current = rowHeightList.current.slice(0, itemCount)
1282
+ // // 这里的 useLayoutEffect 是为了在第一次渲染时,根据数据条数预先填充 row 的高度,这样内容足够高,容器才能滚动
1283
+ // // 但是 dataSource 一般是异步获取的,第一次渲染时,length 是空的,所以无法进行填充,这样可能导致容器不能滚动
1284
+ // // 所以 dataSource 有数据后,再填充一次,但是因为 useLayoutEffect 是渲染结束后才调用的,此时填充数据还是导致容器不能滚动,
1285
+ // // 所以,只在第一次 dataSource 不为空时强制触发一次更新
1286
+ // // 可能正因为这一次强制渲染,所以 VirtualTable 内部很多组件可能多次渲染。尝试优化为 calc 函数
1287
+ // if (initialCount.current === 0 && itemCount > 0) {
1288
+ // initialCount.current = itemCount
1289
+ // forceUpdate()
1290
+ // }
1291
+ // }, [itemCount, estimatedRowHeight])
1292
+ var rectList = useRef([]);
1293
+ var updateRectList = function updateRectList() {
1294
+ var result = [];
1295
+ var top = 0;
1296
+ rowHeightList.current.forEach(function (item, index) {
1297
+ if (index !== 0) {
1298
+ top += item;
1299
+ }
1300
+ result.push({
1301
+ index: index,
1302
+ height: item,
1303
+ top: top,
1304
+ bottom: top + item
1305
+ });
1306
+ });
1307
+ rectList.current = result;
1308
+ };
1309
+ // DOM 渲染结束后,进行高度测量,再修改 rowHeightList
1310
+ // 小心陷阱:当 table 父元素为 display: none 时,依然会触发 updateRowHeight 函数,并设置高度为 0
1311
+ var updateRowHeight = useStableFn(function (index, height) {
1312
+ rowHeightList.current[index] = height;
1313
+ updateRectList();
1314
+ onChange == null || onChange(index, height, rectList.current);
1315
+ });
1316
+ var sum = function sum(startIndex, endIndex) {
1317
+ return rowHeightList.current.slice(startIndex, endIndex).reduce(function (a, b) {
1318
+ return a + b;
1319
+ }, 0);
1320
+ };
1321
+ return {
1322
+ rowHeightList: rowHeightList,
1323
+ updateRowHeight: updateRowHeight,
1324
+ sum: sum,
1325
+ rects: useCallback(function () {
1326
+ return rectList.current;
1327
+ }, [])
1328
+ };
1329
+ }
1330
+
1331
+ function anchorQuery(rects, scrollTop) {
1332
+ var left = 0;
1333
+ var right = rects.length - 1;
1334
+ var index = -1;
1335
+ while (left <= right) {
1336
+ var mid = Math.floor((left + right) / 2);
1337
+ if (rects[mid].bottom > scrollTop) {
1338
+ index = mid;
1339
+ right = mid - 1;
1340
+ } else {
1341
+ left = mid + 1;
1342
+ }
1343
+ }
1344
+ if (index === -1) {
1345
+ return undefined;
1346
+ }
1347
+ return rects[index];
1348
+ }
1349
+ function useRowVirtualize(options) {
1350
+ var getOffsetTop = options.getOffsetTop,
1351
+ rawData = options.dataSource,
1352
+ getScroller = options.getScroller,
1353
+ estimateSize = options.estimateSize,
1354
+ overscan = options.overscan;
1355
+ var _useState = useState(0),
1356
+ startIndex = _useState[0],
1357
+ setStartIndex = _useState[1];
1358
+ var _useState2 = useState(0),
1359
+ endIndex = _useState2[0],
1360
+ setEndIndex = _useState2[1];
1361
+ // 锚点元素,当前虚拟列表中,最接近滚动容器顶部的元素
1362
+ var anchorRef = useRef({
1363
+ index: 0,
1364
+ height: estimateSize,
1365
+ top: 0,
1366
+ bottom: estimateSize
1367
+ });
1368
+ var _useRowRectManager = useRowRectManager({
1369
+ itemCount: rawData.length,
1370
+ estimateSize: estimateSize,
1371
+ onChange: function onChange(index, _height, rowRects) {
1372
+ if (anchorRef.current.index === index) {
1373
+ anchorRef.current = rowRects[index];
1374
+ }
1375
+ }
1376
+ }),
1377
+ rowHeightList = _useRowRectManager.rowHeightList,
1378
+ rects = _useRowRectManager.rects,
1379
+ updateRowHeight = _useRowRectManager.updateRowHeight,
1380
+ sum = _useRowRectManager.sum;
1381
+ // 用来判断滚动方向
1382
+ var scrollTopRef = useRef(0);
1383
+ var initial = useRef(false);
1384
+ useEffect(function () {
1385
+ var container = getScroller();
1386
+ if (container == null) return;
1387
+ var count = 0;
1388
+ var getScrollTop = function getScrollTop() {
1389
+ var offsetTop = getOffsetTop();
1390
+ var result = 0;
1391
+ if (isWindow(container) || isRoot(container)) {
1392
+ result = window.scrollY;
1393
+ } else {
1394
+ var element = getScrollElement(container);
1395
+ result = element.scrollTop;
1396
+ }
1397
+ return Math.max(result - offsetTop, 0);
1398
+ };
1399
+ var calcCount = function calcCount(scrollerContainerHeight) {
1400
+ var prevCount = count;
1401
+ count = Math.ceil(scrollerContainerHeight / estimateSize);
1402
+ return {
1403
+ prevCount: prevCount
1404
+ };
1405
+ };
1406
+ var updateBoundary = function updateBoundary(scrollTop) {
1407
+ var anchor = anchorQuery(rects(), scrollTop);
1408
+ if (anchor != null) {
1409
+ anchorRef.current = anchor;
1410
+ setStartIndex(Math.max(0, anchor.index - overscan));
1411
+ setEndIndex(anchor.index + count + overscan);
1412
+ }
1413
+ };
1414
+ var onScroll = function onScroll(e) {
1415
+ var offsetTop = getOffsetTop();
1416
+ var scrollElement = getScrollElement(e.target);
1417
+ var scrollTop = Math.max(0, scrollElement.scrollTop - offsetTop);
1418
+ // 是否为向下滚动
1419
+ var isScrollDown = scrollTop > scrollTopRef.current;
1420
+ if (isScrollDown) {
1421
+ // 如果滚动距离比较小,没有超出锚点元素的边界,就不需要计算 startIndex、endIndex 了
1422
+ if (scrollTop > anchorRef.current.bottom) {
1423
+ updateBoundary(scrollTop);
1424
+ }
1425
+ } else {
1426
+ if (scrollTop < anchorRef.current.top) {
1427
+ updateBoundary(scrollTop);
1428
+ }
1429
+ }
1430
+ scrollTopRef.current = scrollTop;
1431
+ };
1432
+ var prevHeight = 0;
1433
+ var stopListen = onResize(container, function (rect) {
1434
+ // 处理父元素 display:none 容器高度丢失,导致显示 row 不准确
1435
+ if (rect.height === prevHeight || rect.height === 0) {
1436
+ return;
1437
+ }
1438
+ prevHeight = rect.height;
1439
+ calcCount(rect.height);
1440
+ var scrollTop = getScrollTop();
1441
+ if (!initial.current) {
1442
+ initial.current = true;
1443
+ var nextStartIndex = 0;
1444
+ // 判断一下当前滚动位置,计算 startIndex(场景:SPA 页面切换且渲染非异步数据)
1445
+ if (scrollTop >= estimateSize) {
1446
+ nextStartIndex = Math.max(Math.floor(scrollTop / estimateSize) - 1 - overscan, 0);
1447
+ }
1448
+ var nextEndIndex = nextStartIndex + count + overscan;
1449
+ setStartIndex(nextStartIndex);
1450
+ setEndIndex(nextEndIndex);
1451
+ } else {
1452
+ updateBoundary(scrollTop);
1453
+ }
1454
+ });
1455
+ container.addEventListener('scroll', onScroll);
1456
+ return function () {
1457
+ stopListen();
1458
+ container.removeEventListener('scroll', onScroll);
1459
+ };
1460
+ }, [estimateSize, getOffsetTop, getScroller, overscan, rects]);
1461
+ // TODO: React Compiler 测试 topBlank 和 bottomBlank
1462
+ var topBlank = sum(0, startIndex);
1463
+ var bottomBlank = sum(endIndex);
1464
+ var dataSlice = useMemo(function () {
1465
+ return rawData.slice(startIndex, endIndex);
1466
+ }, [rawData, startIndex, endIndex]);
1467
+ return {
1468
+ startIndex: startIndex,
1469
+ endIndex: endIndex,
1470
+ rowHeightList: rowHeightList,
1471
+ updateRowHeight: updateRowHeight,
1472
+ topBlank: topBlank,
1473
+ bottomBlank: bottomBlank,
1474
+ dataSlice: dataSlice
1475
+ };
1476
+ }
1477
+
1478
+ function TableRoot(props, ref) {
1479
+ var className = props.className,
1480
+ style = props.style,
1481
+ children = props.children,
1482
+ hasFixedLeftColumn = props.hasFixedLeftColumn,
1483
+ hasFixedRightColumn = props.hasFixedRightColumn,
1484
+ renderRoot = props.renderRoot,
1485
+ bodyScrollContainer = props.bodyScrollContainer;
1486
+ var rootNode = useRef(null);
1487
+ var _useState = useState(false),
1488
+ hasFixedLeft = _useState[0],
1489
+ setHasFixedLeft = _useState[1];
1490
+ var _useState2 = useState(false),
1491
+ hasFixedRight = _useState2[0],
1492
+ setHasFixedRight = _useState2[1];
1493
+ var _useHorizontalScrollC = useHorizontalScrollContext(),
1494
+ listen = _useHorizontalScrollC.listen;
1495
+ useEffect(function () {
1496
+ if (!hasFixedLeftColumn && !hasFixedRightColumn) {
1497
+ return;
1498
+ }
1499
+ var onCheckHasFixedEdge = function onCheckHasFixedEdge(node) {
1500
+ var scrollLeft = node.scrollLeft,
1501
+ clientWidth = node.clientWidth,
1502
+ scrollWidth = node.scrollWidth;
1503
+ if (hasFixedLeftColumn) {
1504
+ setHasFixedLeft(scrollLeft !== 0);
1505
+ }
1506
+ if (hasFixedRightColumn) {
1507
+ setHasFixedRight(!(scrollLeft + clientWidth >= scrollWidth));
1508
+ }
1509
+ };
1510
+ var node = bodyScrollContainer.current;
1511
+ if (node != null) {
1512
+ onCheckHasFixedEdge(node);
1513
+ }
1514
+ return listen('__root', function (_scrollLeft, node) {
1515
+ onCheckHasFixedEdge(node);
1516
+ });
1517
+ }, [bodyScrollContainer, hasFixedLeftColumn, hasFixedRightColumn, listen]);
1518
+ var mergedRef = useMergedRef(ref, rootNode);
1519
+ return pipelineRender(jsx("div", {
1520
+ ref: mergedRef,
1521
+ className: clsx('virtual-table', hasFixedLeft && 'virtual-table-has-fix-left', hasFixedRight && 'virtual-table-has-fix-right', className),
1522
+ style: style,
1523
+ children: children
1524
+ }), renderRoot, {});
1525
+ }
1526
+ var TableRoot$1 = /*#__PURE__*/forwardRef(TableRoot);
1527
+
1528
+ function VirtualTableCore(props, ref) {
1529
+ var bodyRootRef = props.bodyRootRef,
1530
+ className = props.className,
1531
+ style = props.style,
1532
+ tableBodyClassName = props.tableBodyClassName,
1533
+ tableBodyStyle = props.tableBodyStyle,
1534
+ rawColumns = props.columns,
1535
+ rawData = props.dataSource,
1536
+ _props$rowKey = props.rowKey,
1537
+ rawRowKey = _props$rowKey === undefined ? 'key' : _props$rowKey,
1538
+ _props$estimatedRowHe = props.estimatedRowHeight,
1539
+ estimatedRowHeight = _props$estimatedRowHe === undefined ? 46 : _props$estimatedRowHe,
1540
+ estimatedColumnWidth = props.estimatedColumnWidth,
1541
+ _props$overscanRows = props.overscanRows,
1542
+ overscanRows = _props$overscanRows === undefined ? 5 : _props$overscanRows,
1543
+ _props$overscanColumn = props.overscanColumns,
1544
+ overscanColumns = _props$overscanColumn === undefined ? 3 : _props$overscanColumn,
1545
+ stickyHeader = props.stickyHeader,
1546
+ _props$pipeline = props.pipeline,
1547
+ pipeline = _props$pipeline === undefined ? TablePipeline.defaultPipeline : _props$pipeline,
1548
+ rawRowClassName = props.rowClassName,
1549
+ onRow = props.onRow,
1550
+ getOffsetTopImpl = props.getOffsetTop,
1551
+ _props$virtualHeader = props.virtualHeader,
1552
+ virtualHeader = _props$virtualHeader === undefined ? false : _props$virtualHeader;
1553
+ var rootNode = useRef(null);
1554
+ var headerWrapperRef = useRef(null);
1555
+ var bodyWrapperRef = useRef(null);
1556
+ var bodyRoot = useRef(null);
1557
+ var mergedBodyRootRef = useMergedRef(bodyRoot, bodyRootRef);
1558
+ var bodyRef = useRef(null);
1559
+ var getScroller = useCallback(function () {
1560
+ var root = rootNode.current;
1561
+ if (root == null) return;
1562
+ return getScrollParent(root);
1563
+ }, []);
1564
+ var getOffsetTop = useCallback(function () {
1565
+ var _rootNode$current$off, _rootNode$current2;
1566
+ if (typeof getOffsetTopImpl === 'function') {
1567
+ return getOffsetTopImpl();
1568
+ }
1569
+ var scrollContainer = getScroller();
1570
+ if (scrollContainer === rootNode.current) {
1571
+ return 0;
1572
+ }
1573
+ if (isWindow(scrollContainer) || isRoot(scrollContainer)) {
1574
+ var _rootNode$current$get, _rootNode$current;
1575
+ var top = (_rootNode$current$get = (_rootNode$current = rootNode.current) == null ? undefined : _rootNode$current.getBoundingClientRect().top) != null ? _rootNode$current$get : 0;
1576
+ return window.scrollY + top;
1577
+ }
1578
+ return (_rootNode$current$off = (_rootNode$current2 = rootNode.current) == null ? undefined : _rootNode$current2.offsetTop) != null ? _rootNode$current$off : 0;
1579
+ }, [getOffsetTopImpl, getScroller]);
1580
+ var _pipeline$use = pipeline.use({
1581
+ dataSource: rawData,
1582
+ rowKey: rawRowKey,
1583
+ columns: rawColumns,
1584
+ estimatedRowHeight: estimatedRowHeight,
1585
+ headerWrapperRef: headerWrapperRef,
1586
+ bodyWrapperRef: bodyWrapperRef,
1587
+ bodyRootRef: bodyRoot,
1588
+ bodyRef: bodyRef,
1589
+ rootRef: rootNode,
1590
+ getOffsetTop: getOffsetTop,
1591
+ getScroller: getScroller
1592
+ }),
1593
+ dataSource = _pipeline$use.dataSource,
1594
+ pipelineColumns = _pipeline$use.columns,
1595
+ rowKey = _pipeline$use.rowKey,
1596
+ rowClassName = _pipeline$use.rowClassName,
1597
+ render = _pipeline$use.render,
1598
+ renderRoot = _pipeline$use.renderRoot,
1599
+ renderContent = _pipeline$use.renderContent,
1600
+ renderHeaderWrapper = _pipeline$use.renderHeaderWrapper,
1601
+ renderHeaderRoot = _pipeline$use.renderHeaderRoot,
1602
+ renderHeader = _pipeline$use.renderHeader,
1603
+ renderHeaderRow = _pipeline$use.renderHeaderRow,
1604
+ renderHeaderCell = _pipeline$use.renderHeaderCell,
1605
+ renderBodyWrapper = _pipeline$use.renderBodyWrapper,
1606
+ renderBodyRoot = _pipeline$use.renderBodyRoot,
1607
+ renderBody = _pipeline$use.renderBody,
1608
+ renderRow = _pipeline$use.renderRow,
1609
+ renderCell = _pipeline$use.renderCell,
1610
+ onPipelineRow = _pipeline$use.onRow;
1611
+ var _useState = useState(function () {
1612
+ return new Map();
1613
+ }),
1614
+ columnWidths = _useState[0],
1615
+ setColumnWidths = _useState[1];
1616
+ var columnWidthsRef = useRef(columnWidths);
1617
+ var updateColumnWidths = function updateColumnWidths(value) {
1618
+ columnWidthsRef.current = value;
1619
+ setColumnWidths(value);
1620
+ };
1621
+ var tableColumnsContext = useMemo(function () {
1622
+ return {
1623
+ widthList: columnWidths,
1624
+ setWidthList: updateColumnWidths
1625
+ };
1626
+ }, [columnWidths]);
1627
+ var _useRowVirtualize = useRowVirtualize({
1628
+ getOffsetTop: getOffsetTop,
1629
+ dataSource: dataSource,
1630
+ getScroller: getScroller,
1631
+ estimateSize: estimatedRowHeight,
1632
+ overscan: overscanRows
1633
+ }),
1634
+ startIndex = _useRowVirtualize.startIndex,
1635
+ dataSlice = _useRowVirtualize.dataSlice,
1636
+ updateRowHeight = _useRowVirtualize.updateRowHeight,
1637
+ rowHeightList = _useRowVirtualize.rowHeightList,
1638
+ topBlank = _useRowVirtualize.topBlank,
1639
+ bottomBlank = _useRowVirtualize.bottomBlank;
1640
+ var _useColumnVirtualize = useColumnVirtualize({
1641
+ estimateSize: estimatedColumnWidth != null ? estimatedColumnWidth : 100,
1642
+ overscan: overscanColumns,
1643
+ columns: pipelineColumns,
1644
+ bodyWrapper: bodyWrapperRef,
1645
+ columnWidths: columnWidths,
1646
+ disabled: estimatedColumnWidth == null
1647
+ }),
1648
+ columns = _useColumnVirtualize.columns;
1649
+ if (process.env.NODE_ENV === 'development') {
1650
+ pipelineColumns.forEach(function (column) {
1651
+ if (column.width == null && column.minWidth == null) {
1652
+ console.warn('Missing `width` in column', column);
1653
+ }
1654
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
1655
+ if (getKey(column) == null) {
1656
+ console.error('Missing `dataIndex` or `key` in column', column);
1657
+ }
1658
+ });
1659
+ }
1660
+ var onRowClassName = useCallback(function (record, index) {
1661
+ return clsx(rawRowClassName == null ? undefined : rawRowClassName(record, index), rowClassName == null ? undefined : rowClassName(record, index));
1662
+ }, [rawRowClassName, rowClassName]);
1663
+ var onRowProps = useCallback(function (record, index) {
1664
+ return _extends({}, onRow == null ? undefined : onRow(record, index), onPipelineRow == null ? undefined : onPipelineRow(record, index));
1665
+ }, [onPipelineRow, onRow]);
1666
+ var hasFixedLeftColumn = pipelineColumns.some(function (x) {
1667
+ return isValidFixedLeft(x.fixed);
1668
+ });
1669
+ var hasFixedRightColumn = pipelineColumns.some(function (x) {
1670
+ return isValidFixedRight(x.fixed);
1671
+ });
1672
+ var rowManager = useMemo(function () {
1673
+ return {
1674
+ getRowHeightList: function getRowHeightList() {
1675
+ return rowHeightList.current;
1676
+ },
1677
+ updateRowHeight: updateRowHeight
1678
+ };
1679
+ }, [rowHeightList, updateRowHeight]);
1680
+ var fullHeaderColumns = useMemo(function () {
1681
+ return {
1682
+ columns: pipelineColumns,
1683
+ descriptor: pipelineColumns.map(function (column) {
1684
+ var key = getKey(column);
1685
+ return {
1686
+ key: key,
1687
+ type: 'normal',
1688
+ column: column
1689
+ };
1690
+ })
1691
+ };
1692
+ }, [pipelineColumns]);
1693
+ var headerColumns = useMemo(function () {
1694
+ if (virtualHeader) {
1695
+ return columns;
1696
+ }
1697
+ return fullHeaderColumns;
1698
+ }, [virtualHeader, fullHeaderColumns, columns]);
1699
+ var contentNode = pipelineRender(jsxs(Fragment$1, {
1700
+ children: [jsx(TableHeader, {
1701
+ wrapperRef: headerWrapperRef,
1702
+ columns: headerColumns,
1703
+ stickyHeader: stickyHeader,
1704
+ renderHeaderWrapper: renderHeaderWrapper,
1705
+ renderHeaderRoot: renderHeaderRoot,
1706
+ renderHeader: renderHeader,
1707
+ renderHeaderRow: renderHeaderRow,
1708
+ renderHeaderCell: renderHeaderCell
1709
+ }), jsx(TableBody, {
1710
+ bodyWrapperRef: bodyWrapperRef,
1711
+ bodyRootRef: mergedBodyRootRef,
1712
+ bodyRef: bodyRef,
1713
+ className: tableBodyClassName,
1714
+ style: _extends({}, tableBodyStyle, {
1715
+ paddingBottom: bottomBlank,
1716
+ paddingTop: topBlank
1717
+ }),
1718
+ columns: columns,
1719
+ rowKey: rowKey,
1720
+ dataSource: dataSlice,
1721
+ startIndex: startIndex,
1722
+ rowClassName: onRowClassName,
1723
+ onRow: onRowProps,
1724
+ renderBodyWrapper: renderBodyWrapper,
1725
+ renderBodyRoot: renderBodyRoot,
1726
+ renderBody: renderBody,
1727
+ renderRow: renderRow,
1728
+ renderCell: renderCell
1729
+ })]
1730
+ }), renderContent, {
1731
+ columns: columns.columns,
1732
+ columnDescriptor: columns.descriptor
1733
+ });
1734
+ var rootMergedRef = useMergedRef(rootNode, ref);
1735
+ var table = pipelineRender(jsx(TableRoot$1, {
1736
+ ref: rootMergedRef,
1737
+ className: className,
1738
+ style: style,
1739
+ hasFixedLeftColumn: hasFixedLeftColumn,
1740
+ hasFixedRightColumn: hasFixedRightColumn,
1741
+ renderRoot: renderRoot,
1742
+ bodyScrollContainer: bodyWrapperRef,
1743
+ children: contentNode
1744
+ }), render, {
1745
+ columns: columns.columns,
1746
+ columnDescriptor: columns.descriptor
1747
+ });
1748
+ return jsx(TableRowManager.Provider, {
1749
+ value: rowManager,
1750
+ children: jsx(ColumnSizes.Provider, {
1751
+ value: tableColumnsContext,
1752
+ children: jsx(StickyContext, {
1753
+ columns: pipelineColumns,
1754
+ children: jsx(ContainerSizeContext, {
1755
+ getScroller: getScroller,
1756
+ root: rootNode,
1757
+ children: jsx(HorizontalScrollContext, {
1758
+ children: table
1759
+ })
1760
+ })
1761
+ })
1762
+ })
1763
+ });
1764
+ }
1765
+ if (process.env.NODE_ENV === 'development') {
1766
+ VirtualTableCore.displayName = 'VirtualTable.Core';
1767
+ }
1768
+ var table = /*#__PURE__*/memo(/*#__PURE__*/forwardRef(VirtualTableCore));
1769
+
1770
+ export { Colgroup, table as VirtualTable, Cell$1 as VirtualTableCell, Row$1 as VirtualTableRow, createMiddleware, findLastIndex, getKey, isValidFixed, isValidFixedLeft, isValidFixedRight, mergeRefs, onResize, useColumnSizes, useContainerSize, useHorizontalScrollContext, useMergedRef, useShallowMemo, useStableFn, useTablePipeline, useTableRowManager, useTableSticky };
1771
+ //# sourceMappingURL=index.esm.js.map