@are-visual/virtual-table 0.10.2 → 0.11.0
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.
- package/README.md +24 -10
- package/index.d.ts +12 -6
- package/index.esm.js +249 -301
- package/index.esm.js.map +1 -1
- package/middleware/column-resize/index.d.ts +2 -0
- package/middleware/column-resize/index.js +6 -6
- package/middleware/column-resize/index.js.map +1 -1
- package/middleware/expandable/index.d.ts +1 -1
- package/middleware/expandable/index.js.map +1 -1
- package/middleware/horizontal-scroll-bar/index.js +3 -26
- package/middleware/horizontal-scroll-bar/index.js.map +1 -1
- package/middleware/selection/index.d.ts +1 -1
- package/middleware/summary/index.d.ts +1 -0
- package/middleware/summary/index.js +13 -29
- package/middleware/summary/index.js.map +1 -1
- package/package.json +1 -1
package/index.esm.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx, jsxs, Fragment as Fragment$1 } from 'react/jsx-runtime';
|
|
2
2
|
import clsx from 'clsx';
|
|
3
|
-
import { useRef, createContext, useContext, useMemo, memo,
|
|
3
|
+
import { useRef, createContext, useContext, useMemo, memo, useEffect, useState, useCallback, useLayoutEffect, Fragment, createElement, forwardRef } from 'react';
|
|
4
4
|
|
|
5
5
|
function _arrayLikeToArray(r, a) {
|
|
6
6
|
(null == a || a > r.length) && (a = r.length);
|
|
@@ -322,125 +322,14 @@ function Cell(props) {
|
|
|
322
322
|
}
|
|
323
323
|
var Cell$1 = /*#__PURE__*/memo(Cell);
|
|
324
324
|
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
if (!(node instanceof Node)) {
|
|
328
|
-
return false;
|
|
329
|
-
}
|
|
330
|
-
var ELEMENT_NODE_TYPE = 1;
|
|
331
|
-
return node.nodeType === ELEMENT_NODE_TYPE;
|
|
332
|
-
}
|
|
333
|
-
function getScrollParent(el, root) {
|
|
334
|
-
var _el$ownerDocument$def;
|
|
335
|
-
if (root === void 0) {
|
|
336
|
-
root = window;
|
|
337
|
-
}
|
|
338
|
-
var node = el;
|
|
339
|
-
while (node !== root && isElement(node)) {
|
|
340
|
-
if (node === document.body) {
|
|
341
|
-
return root;
|
|
342
|
-
}
|
|
343
|
-
var _window$getComputedSt = window.getComputedStyle(node),
|
|
344
|
-
overflow = _window$getComputedSt.overflow,
|
|
345
|
-
overflowY = _window$getComputedSt.overflowY,
|
|
346
|
-
overflowX = _window$getComputedSt.overflowX;
|
|
347
|
-
if (overflowStylePatterns.test(overflow + overflowY + overflowX)) {
|
|
348
|
-
return node;
|
|
349
|
-
}
|
|
350
|
-
node = node.parentNode;
|
|
351
|
-
}
|
|
352
|
-
return (_el$ownerDocument$def = el.ownerDocument.defaultView) != null ? _el$ownerDocument$def : window;
|
|
353
|
-
}
|
|
354
|
-
function isWindow(arg) {
|
|
355
|
-
return Object.prototype.toString.call(arg) === '[object Window]';
|
|
356
|
-
}
|
|
357
|
-
function isDocument(arg) {
|
|
358
|
-
return Object.prototype.toString.call(arg) === '[object HTMLDocument]';
|
|
359
|
-
}
|
|
360
|
-
function isRoot(arg) {
|
|
361
|
-
return Object.prototype.toString.call(arg) === '[object HTMLHtmlElement]';
|
|
362
|
-
}
|
|
363
|
-
function getScrollElement(el) {
|
|
364
|
-
if (isDocument(el)) {
|
|
365
|
-
return el.scrollingElement;
|
|
366
|
-
}
|
|
367
|
-
if (isElement(el)) {
|
|
368
|
-
return el;
|
|
369
|
-
}
|
|
370
|
-
return document.scrollingElement;
|
|
371
|
-
}
|
|
372
|
-
function getScrollTop(node) {
|
|
373
|
-
var result = 0;
|
|
374
|
-
if (isWindow(node) || isRoot(node)) {
|
|
375
|
-
result = window.scrollY;
|
|
376
|
-
} else {
|
|
377
|
-
var element = getScrollElement(node);
|
|
378
|
-
result = element.scrollTop;
|
|
379
|
-
}
|
|
380
|
-
return result;
|
|
381
|
-
}
|
|
382
|
-
function getRelativeOffsetTop(el, ancestor) {
|
|
383
|
-
var elRect = el.getBoundingClientRect();
|
|
384
|
-
var ancestorRect = ancestor.getBoundingClientRect();
|
|
385
|
-
var ancestorBorderTop = Number.parseFloat(window.getComputedStyle(ancestor).borderTopWidth) || 0;
|
|
386
|
-
var ancestorScrollTop = ancestor.scrollTop;
|
|
387
|
-
return elRect.top - ancestorRect.top - ancestorBorderTop + ancestorScrollTop;
|
|
388
|
-
}
|
|
389
|
-
|
|
390
|
-
function onResize(target, callback) {
|
|
391
|
-
if (isWindow(target)) {
|
|
392
|
-
var listener = function listener() {
|
|
393
|
-
callback({
|
|
394
|
-
width: window.innerWidth,
|
|
395
|
-
height: window.innerHeight
|
|
396
|
-
});
|
|
397
|
-
};
|
|
398
|
-
listener();
|
|
399
|
-
window.addEventListener('resize', listener);
|
|
400
|
-
return function () {
|
|
401
|
-
window.removeEventListener('resize', listener);
|
|
402
|
-
};
|
|
403
|
-
} else {
|
|
404
|
-
var observer = new ResizeObserver(function (entries) {
|
|
405
|
-
var rect = entries[0].contentRect;
|
|
406
|
-
callback({
|
|
407
|
-
width: rect.width,
|
|
408
|
-
height: rect.height
|
|
409
|
-
});
|
|
410
|
-
});
|
|
411
|
-
observer.observe(target);
|
|
412
|
-
return function () {
|
|
413
|
-
observer.disconnect();
|
|
414
|
-
};
|
|
415
|
-
}
|
|
325
|
+
function getColumnWidth(column, defaultColumnWidth) {
|
|
326
|
+
return Number.isFinite(column.width) ? column.width : defaultColumnWidth;
|
|
416
327
|
}
|
|
417
328
|
|
|
418
329
|
var Colgroup = function Colgroup(props) {
|
|
419
330
|
var columns = props.columns,
|
|
420
|
-
|
|
421
|
-
var enableMeasure = onColumnSizesMeasure != null;
|
|
422
|
-
var columnSizes = new Map();
|
|
423
|
-
var prevColumnSizes = useRef(new Map());
|
|
424
|
-
var node = useRef(null);
|
|
425
|
-
useLayoutEffect(function () {
|
|
426
|
-
if (!enableMeasure) return;
|
|
427
|
-
var colgroupNode = node.current;
|
|
428
|
-
if (colgroupNode == null) return;
|
|
429
|
-
return onResize(colgroupNode, function (_ref) {
|
|
430
|
-
var width = _ref.width;
|
|
431
|
-
if (width === 0) return;
|
|
432
|
-
var sizes = new Map();
|
|
433
|
-
columnSizes.forEach(function (item, key) {
|
|
434
|
-
sizes.set(key, item());
|
|
435
|
-
});
|
|
436
|
-
if (!isShallowEqual(sizes, prevColumnSizes.current)) {
|
|
437
|
-
onColumnSizesMeasure(sizes);
|
|
438
|
-
prevColumnSizes.current = sizes;
|
|
439
|
-
}
|
|
440
|
-
});
|
|
441
|
-
});
|
|
331
|
+
defaultColumnWidth = props.defaultColumnWidth;
|
|
442
332
|
return jsx("colgroup", {
|
|
443
|
-
ref: node,
|
|
444
333
|
children: columns.map(function (item) {
|
|
445
334
|
var key = item.key;
|
|
446
335
|
if (item.type === 'blank') {
|
|
@@ -452,18 +341,11 @@ var Colgroup = function Colgroup(props) {
|
|
|
452
341
|
}, key);
|
|
453
342
|
}
|
|
454
343
|
var column = item.column;
|
|
344
|
+
var width = getColumnWidth(column, defaultColumnWidth);
|
|
455
345
|
return jsx("col", {
|
|
456
|
-
ref: function ref(node) {
|
|
457
|
-
if (node == null || !enableMeasure) return;
|
|
458
|
-
// eslint-disable-next-line react-compiler/react-compiler
|
|
459
|
-
columnSizes.set(key, function () {
|
|
460
|
-
return node.offsetWidth;
|
|
461
|
-
});
|
|
462
|
-
},
|
|
463
346
|
"data-col-key": key,
|
|
464
347
|
style: {
|
|
465
|
-
width:
|
|
466
|
-
minWidth: column.minWidth
|
|
348
|
+
width: width
|
|
467
349
|
}
|
|
468
350
|
}, key);
|
|
469
351
|
})
|
|
@@ -471,93 +353,7 @@ var Colgroup = function Colgroup(props) {
|
|
|
471
353
|
};
|
|
472
354
|
var Colgroup$1 = /*#__PURE__*/memo(Colgroup);
|
|
473
355
|
|
|
474
|
-
function useCalcSize(options) {
|
|
475
|
-
var getScroller = options.getScroller,
|
|
476
|
-
root = options.root;
|
|
477
|
-
var _useState = useState(0),
|
|
478
|
-
scrollContainerWidth = _useState[0],
|
|
479
|
-
setScrollContainerWidth = _useState[1];
|
|
480
|
-
var _useState2 = useState(0),
|
|
481
|
-
scrollContainerHeight = _useState2[0],
|
|
482
|
-
setScrollContainerHeight = _useState2[1];
|
|
483
|
-
var _useState3 = useState(0),
|
|
484
|
-
tableWidth = _useState3[0],
|
|
485
|
-
setTableWidth = _useState3[1];
|
|
486
|
-
var _useState4 = useState(0),
|
|
487
|
-
tableHeight = _useState4[0],
|
|
488
|
-
setTableHeight = _useState4[1];
|
|
489
|
-
var scrollerContainerRef = useRef(null);
|
|
490
|
-
useLayoutEffect(function () {
|
|
491
|
-
var scrollerContainer = getScroller();
|
|
492
|
-
if (scrollerContainer == null) return;
|
|
493
|
-
var scroller;
|
|
494
|
-
if (isWindow(scrollerContainer)) {
|
|
495
|
-
scroller = document.scrollingElement;
|
|
496
|
-
} else {
|
|
497
|
-
scroller = scrollerContainer;
|
|
498
|
-
}
|
|
499
|
-
scrollerContainerRef.current = scroller;
|
|
500
|
-
var observer = new ResizeObserver(function (entries) {
|
|
501
|
-
var _entries$0$contentRec = entries[0].contentRect,
|
|
502
|
-
width = _entries$0$contentRec.width,
|
|
503
|
-
height = _entries$0$contentRec.height;
|
|
504
|
-
setScrollContainerWidth(width);
|
|
505
|
-
setScrollContainerHeight(height);
|
|
506
|
-
});
|
|
507
|
-
observer.observe(scroller);
|
|
508
|
-
return function () {
|
|
509
|
-
observer.disconnect();
|
|
510
|
-
};
|
|
511
|
-
}, [getScroller]);
|
|
512
|
-
useLayoutEffect(function () {
|
|
513
|
-
var node = root.current;
|
|
514
|
-
if (node == null) return;
|
|
515
|
-
var observer = new ResizeObserver(function (entries) {
|
|
516
|
-
var _entries$0$contentRec2 = entries[0].contentRect,
|
|
517
|
-
width = _entries$0$contentRec2.width,
|
|
518
|
-
height = _entries$0$contentRec2.height;
|
|
519
|
-
setTableWidth(width);
|
|
520
|
-
setTableHeight(height);
|
|
521
|
-
});
|
|
522
|
-
observer.observe(node);
|
|
523
|
-
return function () {
|
|
524
|
-
observer.disconnect();
|
|
525
|
-
};
|
|
526
|
-
}, [root]);
|
|
527
|
-
return {
|
|
528
|
-
scrollContainerWidth: scrollContainerWidth,
|
|
529
|
-
scrollContainerHeight: scrollContainerHeight,
|
|
530
|
-
tableWidth: tableWidth,
|
|
531
|
-
tableHeight: tableHeight
|
|
532
|
-
};
|
|
533
|
-
}
|
|
534
|
-
|
|
535
356
|
var ContainerSize = /*#__PURE__*/createContext(null);
|
|
536
|
-
function ContainerSizeContext(props) {
|
|
537
|
-
var getScroller = props.getScroller,
|
|
538
|
-
root = props.root,
|
|
539
|
-
children = props.children;
|
|
540
|
-
var _useCalcSize = useCalcSize({
|
|
541
|
-
getScroller: getScroller,
|
|
542
|
-
root: root
|
|
543
|
-
}),
|
|
544
|
-
scrollContainerHeight = _useCalcSize.scrollContainerHeight,
|
|
545
|
-
scrollContainerWidth = _useCalcSize.scrollContainerWidth,
|
|
546
|
-
tableHeight = _useCalcSize.tableHeight,
|
|
547
|
-
tableWidth = _useCalcSize.tableWidth;
|
|
548
|
-
var state = useMemo(function () {
|
|
549
|
-
return {
|
|
550
|
-
scrollContainerWidth: scrollContainerWidth,
|
|
551
|
-
scrollContainerHeight: scrollContainerHeight,
|
|
552
|
-
tableWidth: tableWidth,
|
|
553
|
-
tableHeight: tableHeight
|
|
554
|
-
};
|
|
555
|
-
}, [scrollContainerWidth, scrollContainerHeight, tableWidth, tableHeight]);
|
|
556
|
-
return jsx(ContainerSize.Provider, {
|
|
557
|
-
value: state,
|
|
558
|
-
children: children
|
|
559
|
-
});
|
|
560
|
-
}
|
|
561
357
|
function useContainerSize() {
|
|
562
358
|
var context = useContext(ContainerSize);
|
|
563
359
|
if (context == null) {
|
|
@@ -619,6 +415,43 @@ function useHorizontalScrollContext() {
|
|
|
619
415
|
}
|
|
620
416
|
return context;
|
|
621
417
|
}
|
|
418
|
+
function useScrollSynchronize(key) {
|
|
419
|
+
var _useHorizontalScrollC = useHorizontalScrollContext(),
|
|
420
|
+
listen = _useHorizontalScrollC.listen,
|
|
421
|
+
notify = _useHorizontalScrollC.notify;
|
|
422
|
+
var nodeRef = useRef(null);
|
|
423
|
+
useEffect(function () {
|
|
424
|
+
var node = nodeRef.current;
|
|
425
|
+
if (node == null) return;
|
|
426
|
+
var onScroll = function onScroll() {
|
|
427
|
+
notify(key, {
|
|
428
|
+
scrollLeft: function scrollLeft() {
|
|
429
|
+
return node.scrollLeft;
|
|
430
|
+
},
|
|
431
|
+
node: node
|
|
432
|
+
});
|
|
433
|
+
};
|
|
434
|
+
var addEvent = function addEvent() {
|
|
435
|
+
// eslint-disable-next-line @eslint-react/web-api/no-leaked-event-listener
|
|
436
|
+
node.addEventListener('scroll', onScroll, {
|
|
437
|
+
passive: true
|
|
438
|
+
});
|
|
439
|
+
};
|
|
440
|
+
var removeEvent = function removeEvent() {
|
|
441
|
+
node.removeEventListener('scroll', onScroll);
|
|
442
|
+
};
|
|
443
|
+
var dispose = listen(key, function (scrollLeft) {
|
|
444
|
+
node.style.willChange = 'scroll-position';
|
|
445
|
+
node.scrollLeft = scrollLeft;
|
|
446
|
+
});
|
|
447
|
+
addEvent();
|
|
448
|
+
return function () {
|
|
449
|
+
removeEvent();
|
|
450
|
+
dispose();
|
|
451
|
+
};
|
|
452
|
+
}, [key, listen, notify]);
|
|
453
|
+
return nodeRef;
|
|
454
|
+
}
|
|
622
455
|
|
|
623
456
|
var TableRowManager = /*#__PURE__*/createContext(null);
|
|
624
457
|
if (process.env.NODE_ENV === 'development') {
|
|
@@ -632,6 +465,99 @@ function useTableRowManager() {
|
|
|
632
465
|
return context;
|
|
633
466
|
}
|
|
634
467
|
|
|
468
|
+
var overflowStylePatterns = /auto|scroll|overlay|hidden/;
|
|
469
|
+
function isElement(node) {
|
|
470
|
+
if (!(node instanceof Node)) {
|
|
471
|
+
return false;
|
|
472
|
+
}
|
|
473
|
+
var ELEMENT_NODE_TYPE = 1;
|
|
474
|
+
return node.nodeType === ELEMENT_NODE_TYPE;
|
|
475
|
+
}
|
|
476
|
+
function getScrollParent(el, root) {
|
|
477
|
+
var _el$ownerDocument$def;
|
|
478
|
+
if (root === void 0) {
|
|
479
|
+
root = window;
|
|
480
|
+
}
|
|
481
|
+
var node = el;
|
|
482
|
+
while (node !== root && isElement(node)) {
|
|
483
|
+
if (node === document.body) {
|
|
484
|
+
return root;
|
|
485
|
+
}
|
|
486
|
+
var _window$getComputedSt = window.getComputedStyle(node),
|
|
487
|
+
overflow = _window$getComputedSt.overflow,
|
|
488
|
+
overflowY = _window$getComputedSt.overflowY,
|
|
489
|
+
overflowX = _window$getComputedSt.overflowX;
|
|
490
|
+
if (overflowStylePatterns.test(overflow + overflowY + overflowX)) {
|
|
491
|
+
return node;
|
|
492
|
+
}
|
|
493
|
+
node = node.parentNode;
|
|
494
|
+
}
|
|
495
|
+
return (_el$ownerDocument$def = el.ownerDocument.defaultView) != null ? _el$ownerDocument$def : window;
|
|
496
|
+
}
|
|
497
|
+
function isWindow(arg) {
|
|
498
|
+
return Object.prototype.toString.call(arg) === '[object Window]';
|
|
499
|
+
}
|
|
500
|
+
function isDocument(arg) {
|
|
501
|
+
return Object.prototype.toString.call(arg) === '[object HTMLDocument]';
|
|
502
|
+
}
|
|
503
|
+
function isRoot(arg) {
|
|
504
|
+
return Object.prototype.toString.call(arg) === '[object HTMLHtmlElement]';
|
|
505
|
+
}
|
|
506
|
+
function getScrollElement(el) {
|
|
507
|
+
if (isDocument(el)) {
|
|
508
|
+
return el.scrollingElement;
|
|
509
|
+
}
|
|
510
|
+
if (isElement(el)) {
|
|
511
|
+
return el;
|
|
512
|
+
}
|
|
513
|
+
return document.scrollingElement;
|
|
514
|
+
}
|
|
515
|
+
function getScrollTop(node) {
|
|
516
|
+
var result = 0;
|
|
517
|
+
if (isWindow(node) || isRoot(node)) {
|
|
518
|
+
result = window.scrollY;
|
|
519
|
+
} else {
|
|
520
|
+
var element = getScrollElement(node);
|
|
521
|
+
result = element.scrollTop;
|
|
522
|
+
}
|
|
523
|
+
return result;
|
|
524
|
+
}
|
|
525
|
+
function getRelativeOffsetTop(el, ancestor) {
|
|
526
|
+
var elRect = el.getBoundingClientRect();
|
|
527
|
+
var ancestorRect = ancestor.getBoundingClientRect();
|
|
528
|
+
var ancestorBorderTop = Number.parseFloat(window.getComputedStyle(ancestor).borderTopWidth) || 0;
|
|
529
|
+
var ancestorScrollTop = ancestor.scrollTop;
|
|
530
|
+
return elRect.top - ancestorRect.top - ancestorBorderTop + ancestorScrollTop;
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
function onResize(target, callback) {
|
|
534
|
+
if (isWindow(target)) {
|
|
535
|
+
var listener = function listener() {
|
|
536
|
+
callback({
|
|
537
|
+
width: window.innerWidth,
|
|
538
|
+
height: window.innerHeight
|
|
539
|
+
});
|
|
540
|
+
};
|
|
541
|
+
listener();
|
|
542
|
+
window.addEventListener('resize', listener);
|
|
543
|
+
return function () {
|
|
544
|
+
window.removeEventListener('resize', listener);
|
|
545
|
+
};
|
|
546
|
+
} else {
|
|
547
|
+
var observer = new ResizeObserver(function (entries) {
|
|
548
|
+
var rect = entries[0].contentRect;
|
|
549
|
+
callback({
|
|
550
|
+
width: rect.width,
|
|
551
|
+
height: rect.height
|
|
552
|
+
});
|
|
553
|
+
});
|
|
554
|
+
observer.observe(target);
|
|
555
|
+
return function () {
|
|
556
|
+
observer.disconnect();
|
|
557
|
+
};
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
|
|
635
561
|
function anchorQuery$1(rects, scrollTop) {
|
|
636
562
|
var left = 0;
|
|
637
563
|
var right = rects.length - 1;
|
|
@@ -1207,6 +1133,7 @@ function TableBody(props) {
|
|
|
1207
1133
|
bodyRef = props.bodyRef,
|
|
1208
1134
|
className = props.className,
|
|
1209
1135
|
style = props.style,
|
|
1136
|
+
defaultColumnWidth = props.defaultColumnWidth,
|
|
1210
1137
|
rawData = props.dataSource,
|
|
1211
1138
|
columnDescriptor = props.columns,
|
|
1212
1139
|
rowKey = props.rowKey,
|
|
@@ -1297,8 +1224,6 @@ function TableBody(props) {
|
|
|
1297
1224
|
columnDescriptor: descriptor,
|
|
1298
1225
|
startRowIndex: startIndex
|
|
1299
1226
|
});
|
|
1300
|
-
var _useColumnSizes = useColumnSizes(),
|
|
1301
|
-
setWidthList = _useColumnSizes.setWidthList;
|
|
1302
1227
|
var tableNode = pipelineRender(jsxs("table", {
|
|
1303
1228
|
className: clsx(className, 'virtual-table-body'),
|
|
1304
1229
|
style: _extends({}, style, {
|
|
@@ -1308,38 +1233,14 @@ function TableBody(props) {
|
|
|
1308
1233
|
ref: bodyRootRef,
|
|
1309
1234
|
children: [jsx(Colgroup$1, {
|
|
1310
1235
|
columns: descriptor,
|
|
1311
|
-
|
|
1236
|
+
defaultColumnWidth: defaultColumnWidth
|
|
1312
1237
|
}), bodyNode]
|
|
1313
1238
|
}), renderBodyRoot, {
|
|
1314
1239
|
columns: columns,
|
|
1315
1240
|
columnDescriptor: descriptor,
|
|
1316
1241
|
startRowIndex: startIndex
|
|
1317
1242
|
});
|
|
1318
|
-
var
|
|
1319
|
-
listen = _useHorizontalScrollC.listen,
|
|
1320
|
-
notify = _useHorizontalScrollC.notify;
|
|
1321
|
-
var wrapperRef = useRef(null);
|
|
1322
|
-
useEffect(function () {
|
|
1323
|
-
var node = wrapperRef.current;
|
|
1324
|
-
if (node == null) return;
|
|
1325
|
-
var key = 'virtual-table-body';
|
|
1326
|
-
var onScroll = function onScroll() {
|
|
1327
|
-
notify(key, {
|
|
1328
|
-
scrollLeft: function scrollLeft() {
|
|
1329
|
-
return node.scrollLeft;
|
|
1330
|
-
},
|
|
1331
|
-
node: node
|
|
1332
|
-
});
|
|
1333
|
-
};
|
|
1334
|
-
var dispose = listen(key, function (scrollLeft) {
|
|
1335
|
-
node.scrollLeft = scrollLeft;
|
|
1336
|
-
});
|
|
1337
|
-
node.addEventListener('scroll', onScroll);
|
|
1338
|
-
return function () {
|
|
1339
|
-
node.removeEventListener('scroll', onScroll);
|
|
1340
|
-
dispose();
|
|
1341
|
-
};
|
|
1342
|
-
}, [listen, notify]);
|
|
1243
|
+
var wrapperRef = useScrollSynchronize('virtual-table-body');
|
|
1343
1244
|
var mergedRef = useMergedRef(wrapperRef, bodyWrapperRef);
|
|
1344
1245
|
// 滚动到指定行。注意:如果 estimatedRowHeight 不够准确时,不一定能准确滚动到目标位置
|
|
1345
1246
|
instance.extend({
|
|
@@ -1398,6 +1299,7 @@ var _excluded = ["className", "style"];
|
|
|
1398
1299
|
var TableHeader = function TableHeader(props) {
|
|
1399
1300
|
var className = props.className,
|
|
1400
1301
|
style = props.style,
|
|
1302
|
+
defaultColumnWidth = props.defaultColumnWidth,
|
|
1401
1303
|
wrapperRef = props.wrapperRef,
|
|
1402
1304
|
columnDescriptor = props.columns,
|
|
1403
1305
|
stickyHeader = props.stickyHeader,
|
|
@@ -1425,31 +1327,7 @@ var TableHeader = function TableHeader(props) {
|
|
|
1425
1327
|
}
|
|
1426
1328
|
return isValidFixedRight(x.column.fixed);
|
|
1427
1329
|
});
|
|
1428
|
-
var
|
|
1429
|
-
listen = _useHorizontalScrollC.listen,
|
|
1430
|
-
notify = _useHorizontalScrollC.notify;
|
|
1431
|
-
var headerWrapperRef = useRef(null);
|
|
1432
|
-
useEffect(function () {
|
|
1433
|
-
var node = headerWrapperRef.current;
|
|
1434
|
-
if (node == null) return;
|
|
1435
|
-
var key = 'virtual-table-header';
|
|
1436
|
-
var onScroll = function onScroll() {
|
|
1437
|
-
notify(key, {
|
|
1438
|
-
scrollLeft: function scrollLeft() {
|
|
1439
|
-
return node.scrollLeft;
|
|
1440
|
-
},
|
|
1441
|
-
node: node
|
|
1442
|
-
});
|
|
1443
|
-
};
|
|
1444
|
-
var dispose = listen(key, function (scrollLeft) {
|
|
1445
|
-
node.scrollLeft = scrollLeft;
|
|
1446
|
-
});
|
|
1447
|
-
node.addEventListener('scroll', onScroll);
|
|
1448
|
-
return function () {
|
|
1449
|
-
node.removeEventListener('scroll', onScroll);
|
|
1450
|
-
dispose();
|
|
1451
|
-
};
|
|
1452
|
-
}, [listen, notify]);
|
|
1330
|
+
var headerWrapperRef = useScrollSynchronize('virtual-table-header');
|
|
1453
1331
|
var row = pipelineRender(jsx("tr", {
|
|
1454
1332
|
children: descriptor.map(function (item, index) {
|
|
1455
1333
|
var _column$onHeaderCell;
|
|
@@ -1500,7 +1378,8 @@ var TableHeader = function TableHeader(props) {
|
|
|
1500
1378
|
var tableNode = pipelineRender(jsxs("table", {
|
|
1501
1379
|
style: style,
|
|
1502
1380
|
children: [jsx(Colgroup$1, {
|
|
1503
|
-
columns: descriptor
|
|
1381
|
+
columns: descriptor,
|
|
1382
|
+
defaultColumnWidth: defaultColumnWidth
|
|
1504
1383
|
}), theadNode]
|
|
1505
1384
|
}), renderHeaderRoot, {
|
|
1506
1385
|
columns: columns,
|
|
@@ -1523,6 +1402,83 @@ var TableHeader = function TableHeader(props) {
|
|
|
1523
1402
|
};
|
|
1524
1403
|
var TableHeader$1 = /*#__PURE__*/memo(TableHeader);
|
|
1525
1404
|
|
|
1405
|
+
function useCalcSize(options) {
|
|
1406
|
+
var getScroller = options.getScroller,
|
|
1407
|
+
root = options.root;
|
|
1408
|
+
var _useState = useState(0),
|
|
1409
|
+
scrollContainerWidth = _useState[0],
|
|
1410
|
+
setScrollContainerWidth = _useState[1];
|
|
1411
|
+
var _useState2 = useState(0),
|
|
1412
|
+
scrollContainerHeight = _useState2[0],
|
|
1413
|
+
setScrollContainerHeight = _useState2[1];
|
|
1414
|
+
var _useState3 = useState(800),
|
|
1415
|
+
tableWidth = _useState3[0],
|
|
1416
|
+
setTableWidth = _useState3[1]; // 设置一个默认值(因为这两个默认值很快就会被覆盖)
|
|
1417
|
+
var _useState4 = useState(600),
|
|
1418
|
+
tableHeight = _useState4[0],
|
|
1419
|
+
setTableHeight = _useState4[1]; // 设置一个默认值(因为这两个默认值很快就会被覆盖)
|
|
1420
|
+
var scrollerContainerRef = useRef(null);
|
|
1421
|
+
useLayoutEffect(function () {
|
|
1422
|
+
var scrollerContainer = getScroller();
|
|
1423
|
+
if (scrollerContainer == null) return;
|
|
1424
|
+
var scroller;
|
|
1425
|
+
if (isWindow(scrollerContainer)) {
|
|
1426
|
+
scroller = document.scrollingElement;
|
|
1427
|
+
} else {
|
|
1428
|
+
scroller = scrollerContainer;
|
|
1429
|
+
}
|
|
1430
|
+
scrollerContainerRef.current = scroller;
|
|
1431
|
+
var observer = new ResizeObserver(function (entries) {
|
|
1432
|
+
var _entries$0$contentRec = entries[0].contentRect,
|
|
1433
|
+
width = _entries$0$contentRec.width,
|
|
1434
|
+
height = _entries$0$contentRec.height;
|
|
1435
|
+
setScrollContainerWidth(width);
|
|
1436
|
+
setScrollContainerHeight(height);
|
|
1437
|
+
});
|
|
1438
|
+
observer.observe(scroller);
|
|
1439
|
+
return function () {
|
|
1440
|
+
observer.disconnect();
|
|
1441
|
+
};
|
|
1442
|
+
}, [getScroller]);
|
|
1443
|
+
useLayoutEffect(function () {
|
|
1444
|
+
var node = root.current;
|
|
1445
|
+
if (node == null) return;
|
|
1446
|
+
var observer = new ResizeObserver(function (entries) {
|
|
1447
|
+
var _entries$0$contentRec2 = entries[0].contentRect,
|
|
1448
|
+
width = _entries$0$contentRec2.width,
|
|
1449
|
+
height = _entries$0$contentRec2.height;
|
|
1450
|
+
setTableWidth(width);
|
|
1451
|
+
setTableHeight(height);
|
|
1452
|
+
});
|
|
1453
|
+
observer.observe(node);
|
|
1454
|
+
return function () {
|
|
1455
|
+
observer.disconnect();
|
|
1456
|
+
};
|
|
1457
|
+
}, [root]);
|
|
1458
|
+
var state = useMemo(function () {
|
|
1459
|
+
return {
|
|
1460
|
+
scrollContainerWidth: scrollContainerWidth,
|
|
1461
|
+
scrollContainerHeight: scrollContainerHeight,
|
|
1462
|
+
tableWidth: tableWidth,
|
|
1463
|
+
tableHeight: tableHeight
|
|
1464
|
+
};
|
|
1465
|
+
}, [scrollContainerWidth, scrollContainerHeight, tableWidth, tableHeight]);
|
|
1466
|
+
return state;
|
|
1467
|
+
}
|
|
1468
|
+
|
|
1469
|
+
function useCollectColumnWidth(columns, defaultColumnWidth) {
|
|
1470
|
+
var widths = useMemo(function () {
|
|
1471
|
+
return columns.reduce(function (result, column) {
|
|
1472
|
+
var width = getColumnWidth(column, defaultColumnWidth);
|
|
1473
|
+
result.set(getKey(column), width);
|
|
1474
|
+
return result;
|
|
1475
|
+
}, new Map());
|
|
1476
|
+
}, [columns, defaultColumnWidth]);
|
|
1477
|
+
return useShallowMemo(function () {
|
|
1478
|
+
return widths;
|
|
1479
|
+
});
|
|
1480
|
+
}
|
|
1481
|
+
|
|
1526
1482
|
function anchorQuery(rects, scrollLeft) {
|
|
1527
1483
|
var left = 0;
|
|
1528
1484
|
var right = rects.length - 1;
|
|
@@ -1563,8 +1519,8 @@ function useColumnVirtualize(options) {
|
|
|
1563
1519
|
defaultColumnWidth = options.defaultColumnWidth,
|
|
1564
1520
|
overscan = options.overscan,
|
|
1565
1521
|
rawColumns = options.columns,
|
|
1522
|
+
containerWidth = options.containerWidth,
|
|
1566
1523
|
bodyWrapper = options.bodyWrapper,
|
|
1567
|
-
columnWidths = options.columnWidths,
|
|
1568
1524
|
_options$disabled = options.disabled,
|
|
1569
1525
|
disabled = _options$disabled === void 0 ? false : _options$disabled;
|
|
1570
1526
|
var lastFixedLeftIndex = findLastFixedLeftIndex(rawColumns);
|
|
@@ -1583,9 +1539,7 @@ function useColumnVirtualize(options) {
|
|
|
1583
1539
|
}
|
|
1584
1540
|
var left = 0;
|
|
1585
1541
|
return rawColumns.map(function (column, index) {
|
|
1586
|
-
var
|
|
1587
|
-
var key = getKey(column);
|
|
1588
|
-
var width = (_columnWidths$get = columnWidths.get(key)) != null ? _columnWidths$get : estimateSize;
|
|
1542
|
+
var width = getColumnWidth(column, defaultColumnWidth);
|
|
1589
1543
|
var right = left + width;
|
|
1590
1544
|
var rect = {
|
|
1591
1545
|
index: index,
|
|
@@ -1596,7 +1550,7 @@ function useColumnVirtualize(options) {
|
|
|
1596
1550
|
left = right;
|
|
1597
1551
|
return rect;
|
|
1598
1552
|
});
|
|
1599
|
-
}, [
|
|
1553
|
+
}, [disabled, rawColumns, defaultColumnWidth]);
|
|
1600
1554
|
// 锚点元素
|
|
1601
1555
|
var anchorRef = useRef({
|
|
1602
1556
|
index: 0,
|
|
@@ -1621,7 +1575,6 @@ function useColumnVirtualize(options) {
|
|
|
1621
1575
|
if (disabled) return;
|
|
1622
1576
|
var scrollContainer = bodyWrapper.current;
|
|
1623
1577
|
if (scrollContainer == null) return;
|
|
1624
|
-
var containerWidth = scrollContainer.offsetWidth;
|
|
1625
1578
|
var count = Math.ceil(containerWidth / estimateSize);
|
|
1626
1579
|
var onScroll = function onScroll() {
|
|
1627
1580
|
var scrollLeft = scrollContainer.scrollLeft;
|
|
@@ -1654,7 +1607,7 @@ function useColumnVirtualize(options) {
|
|
|
1654
1607
|
scrollContainer.removeEventListener('scroll', onScroll);
|
|
1655
1608
|
stop();
|
|
1656
1609
|
};
|
|
1657
|
-
}, [bodyWrapper, estimateSize, updateBoundary, overscan, findAnchorRef, disabled]);
|
|
1610
|
+
}, [containerWidth, bodyWrapper, estimateSize, updateBoundary, overscan, findAnchorRef, disabled]);
|
|
1658
1611
|
var sum = function sum(startIndex, endIndex) {
|
|
1659
1612
|
return rects.slice(startIndex, endIndex).reduce(function (a, b) {
|
|
1660
1613
|
return a + b.width;
|
|
@@ -1838,7 +1791,12 @@ function VirtualTableCore(props, ref) {
|
|
|
1838
1791
|
var instance = useTableInstance(rawInstance);
|
|
1839
1792
|
instance.extend({
|
|
1840
1793
|
getCurrentProps: function getCurrentProps() {
|
|
1841
|
-
return
|
|
1794
|
+
return _extends({
|
|
1795
|
+
estimatedRowHeight: estimatedRowHeight,
|
|
1796
|
+
overscanRows: overscanRows,
|
|
1797
|
+
overscanColumns: overscanColumns,
|
|
1798
|
+
defaultColumnWidth: defaultColumnWidth
|
|
1799
|
+
}, props);
|
|
1842
1800
|
}
|
|
1843
1801
|
});
|
|
1844
1802
|
var rootNode = useRef(null);
|
|
@@ -1867,6 +1825,10 @@ function VirtualTableCore(props, ref) {
|
|
|
1867
1825
|
}
|
|
1868
1826
|
return getRelativeOffsetTop(root, scrollContainer);
|
|
1869
1827
|
}, [getOffsetTopImpl, getScroller]);
|
|
1828
|
+
var containerSize = useCalcSize({
|
|
1829
|
+
getScroller: getScroller,
|
|
1830
|
+
root: rootNode
|
|
1831
|
+
});
|
|
1870
1832
|
var _pipeline$use = pipeline.use({
|
|
1871
1833
|
dataSource: rawData,
|
|
1872
1834
|
rowKey: rawRowKey,
|
|
@@ -1908,41 +1870,27 @@ function VirtualTableCore(props, ref) {
|
|
|
1908
1870
|
return dataSource;
|
|
1909
1871
|
}
|
|
1910
1872
|
});
|
|
1911
|
-
var
|
|
1912
|
-
return new Map();
|
|
1913
|
-
}),
|
|
1914
|
-
columnWidths = _useState[0],
|
|
1915
|
-
setColumnWidths = _useState[1];
|
|
1916
|
-
var columnWidthsRef = useRef(columnWidths);
|
|
1917
|
-
var updateColumnWidths = useCallback(function (value) {
|
|
1918
|
-
var result = new Map(columnWidthsRef.current);
|
|
1919
|
-
value.forEach(function (width, key) {
|
|
1920
|
-
result.set(key, width);
|
|
1921
|
-
});
|
|
1922
|
-
columnWidthsRef.current = result;
|
|
1923
|
-
setColumnWidths(result);
|
|
1924
|
-
}, []);
|
|
1873
|
+
var columnWidths = useCollectColumnWidth(pipelineColumns, defaultColumnWidth);
|
|
1925
1874
|
instance.extend({
|
|
1926
1875
|
getColumnWidths: function getColumnWidths() {
|
|
1927
|
-
return
|
|
1876
|
+
return columnWidths;
|
|
1928
1877
|
},
|
|
1929
1878
|
getColumnWidthByKey: function getColumnWidthByKey(columnKey) {
|
|
1930
|
-
return
|
|
1879
|
+
return columnWidths.get(columnKey);
|
|
1931
1880
|
}
|
|
1932
1881
|
});
|
|
1933
1882
|
var tableColumnsContext = useMemo(function () {
|
|
1934
1883
|
return {
|
|
1935
|
-
widthList: columnWidths
|
|
1936
|
-
setWidthList: updateColumnWidths
|
|
1884
|
+
widthList: columnWidths
|
|
1937
1885
|
};
|
|
1938
|
-
}, [columnWidths
|
|
1886
|
+
}, [columnWidths]);
|
|
1939
1887
|
var _useColumnVirtualize = useColumnVirtualize({
|
|
1940
1888
|
estimateSize: estimatedColumnWidth != null ? estimatedColumnWidth : defaultColumnWidth,
|
|
1941
1889
|
defaultColumnWidth: defaultColumnWidth,
|
|
1942
1890
|
overscan: overscanColumns,
|
|
1943
1891
|
columns: pipelineColumns,
|
|
1892
|
+
containerWidth: containerSize.tableWidth,
|
|
1944
1893
|
bodyWrapper: bodyWrapperRef,
|
|
1945
|
-
columnWidths: columnWidths,
|
|
1946
1894
|
disabled: estimatedColumnWidth == null
|
|
1947
1895
|
}),
|
|
1948
1896
|
columns = _useColumnVirtualize.columns;
|
|
@@ -2014,11 +1962,10 @@ function VirtualTableCore(props, ref) {
|
|
|
2014
1962
|
// pipelineColumns 是一个经过中间件处理的 columns
|
|
2015
1963
|
// 因为中间件可能会处理 columns,比如:添加、删除、排序 columns
|
|
2016
1964
|
for (var _iterator = _createForOfIteratorHelperLoose(pipelineColumns), _step; !(_step = _iterator()).done;) {
|
|
2017
|
-
var
|
|
2018
|
-
var
|
|
2019
|
-
var
|
|
2020
|
-
|
|
2021
|
-
if (isValidFixedLeft(element.fixed)) {
|
|
1965
|
+
var column = _step.value;
|
|
1966
|
+
var columnKey = getKey(column);
|
|
1967
|
+
var width = getColumnWidth(column, defaultColumnWidth);
|
|
1968
|
+
if (isValidFixedLeft(column.fixed)) {
|
|
2022
1969
|
leftFixedWidth += width;
|
|
2023
1970
|
}
|
|
2024
1971
|
if (columnKey === key) {
|
|
@@ -2052,6 +1999,7 @@ function VirtualTableCore(props, ref) {
|
|
|
2052
1999
|
var contentNode = pipelineRender(jsxs(Fragment$1, {
|
|
2053
2000
|
children: [jsx(TableHeader$1, {
|
|
2054
2001
|
wrapperRef: headerWrapperRef,
|
|
2002
|
+
defaultColumnWidth: defaultColumnWidth,
|
|
2055
2003
|
columns: headerColumns,
|
|
2056
2004
|
stickyHeader: stickyHeader,
|
|
2057
2005
|
renderHeaderWrapper: renderHeaderWrapper,
|
|
@@ -2066,6 +2014,7 @@ function VirtualTableCore(props, ref) {
|
|
|
2066
2014
|
bodyRef: bodyRef,
|
|
2067
2015
|
className: tableBodyClassName,
|
|
2068
2016
|
style: tableBodyStyle,
|
|
2017
|
+
defaultColumnWidth: defaultColumnWidth,
|
|
2069
2018
|
columns: columns,
|
|
2070
2019
|
rowKey: rowKey,
|
|
2071
2020
|
dataSource: dataSource,
|
|
@@ -2104,9 +2053,8 @@ function VirtualTableCore(props, ref) {
|
|
|
2104
2053
|
value: tableColumnsContext,
|
|
2105
2054
|
children: jsx(StickyContext, {
|
|
2106
2055
|
columns: pipelineColumns,
|
|
2107
|
-
children: jsx(
|
|
2108
|
-
|
|
2109
|
-
root: rootNode,
|
|
2056
|
+
children: jsx(ContainerSize.Provider, {
|
|
2057
|
+
value: containerSize,
|
|
2110
2058
|
children: jsx(HorizontalScrollContext, {
|
|
2111
2059
|
children: table
|
|
2112
2060
|
})
|
|
@@ -2119,5 +2067,5 @@ if (process.env.NODE_ENV === 'development') {
|
|
|
2119
2067
|
}
|
|
2120
2068
|
var table = /*#__PURE__*/memo(/*#__PURE__*/forwardRef(VirtualTableCore));
|
|
2121
2069
|
|
|
2122
|
-
export { Colgroup$1 as Colgroup, NormalRowHeightKey, table as VirtualTable, Cell$1 as VirtualTableCell, Row$1 as VirtualTableRow, createMiddleware, findLastIndex, getKey, getRelativeOffsetTop, getRowKey, getScrollElement, getScrollParent, getScrollTop, isDocument, isRoot, isValidFixed, isValidFixedLeft, isValidFixedRight, isWindow, mergeRefs, onResize, useColumnSizes, useContainerSize, useHorizontalScrollContext, useMergedRef, useShallowMemo, useStableFn, useTableInstance, useTablePipeline, useTableRowManager, useTableSticky };
|
|
2070
|
+
export { Colgroup$1 as Colgroup, NormalRowHeightKey, table as VirtualTable, Cell$1 as VirtualTableCell, Row$1 as VirtualTableRow, createMiddleware, findLastIndex, getColumnWidth, getKey, getRelativeOffsetTop, getRowKey, getScrollElement, getScrollParent, getScrollTop, isDocument, isRoot, isValidFixed, isValidFixedLeft, isValidFixedRight, isWindow, mergeRefs, onResize, useColumnSizes, useContainerSize, useHorizontalScrollContext, useMergedRef, useScrollSynchronize, useShallowMemo, useStableFn, useTableInstance, useTablePipeline, useTableRowManager, useTableSticky };
|
|
2123
2071
|
//# sourceMappingURL=index.esm.js.map
|