@are-visual/virtual-table 0.11.3 → 0.11.5-beta.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/index.d.ts +4 -2
- package/index.esm.js +236 -118
- package/index.esm.js.map +1 -1
- package/middleware/expandable/index.js +4 -2
- package/middleware/expandable/index.js.map +1 -1
- package/middleware/loading/index.js +2 -10
- package/middleware/loading/index.js.map +1 -1
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -30,6 +30,7 @@ interface RowProps<T> extends Omit<NativeProps$1, 'children'> {
|
|
|
30
30
|
declare const _default$3: <T>(props: RowProps<T>) => ReactElement;
|
|
31
31
|
|
|
32
32
|
interface TableBodyProps<T> extends Omit<NecessaryProps<T>, 'columns'>, Pick<RowProps<T>, 'onRow' | 'renderRow' | 'renderCell'> {
|
|
33
|
+
debugKey?: string;
|
|
33
34
|
className?: string;
|
|
34
35
|
style?: CSSProperties;
|
|
35
36
|
defaultColumnWidth: number;
|
|
@@ -69,6 +70,7 @@ interface UseTablePipelineOptions<T = any> {
|
|
|
69
70
|
declare function useTablePipeline<T = any>(options: UseTablePipelineOptions<T>): TablePipeline<T>;
|
|
70
71
|
|
|
71
72
|
interface VirtualTableCoreProps<T> extends NecessaryProps<T>, Pick<TableBodyProps<T>, 'rowClassName' | 'onRow'> {
|
|
73
|
+
debugKey?: string;
|
|
72
74
|
bodyRootRef?: Ref<HTMLTableElement>;
|
|
73
75
|
instance?: TableInstance;
|
|
74
76
|
className?: string;
|
|
@@ -361,9 +363,9 @@ interface TableRowManagerContextType {
|
|
|
361
363
|
/**
|
|
362
364
|
* @param rowKey
|
|
363
365
|
* @param key 唯一的 key,用于去重
|
|
364
|
-
* @param
|
|
366
|
+
* @param getHeight 行高
|
|
365
367
|
*/
|
|
366
|
-
setRowHeightByRowKey: (rowKey: Key, key: Key,
|
|
368
|
+
setRowHeightByRowKey: (rowKey: Key, key: Key, getHeight: () => number | undefined) => void;
|
|
367
369
|
}
|
|
368
370
|
declare function useTableRowManager(): TableRowManagerContextType;
|
|
369
371
|
|
package/index.esm.js
CHANGED
|
@@ -558,60 +558,66 @@ function onResize(target, callback) {
|
|
|
558
558
|
}
|
|
559
559
|
}
|
|
560
560
|
|
|
561
|
-
function
|
|
562
|
-
var
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
while (left <= right) {
|
|
566
|
-
var mid = Math.floor((left + right) / 2);
|
|
567
|
-
if (rects[mid].bottom > scrollTop) {
|
|
568
|
-
index = mid;
|
|
569
|
-
right = mid - 1;
|
|
570
|
-
} else {
|
|
571
|
-
left = mid + 1;
|
|
572
|
-
}
|
|
561
|
+
function useLazyRef(initial) {
|
|
562
|
+
var ref = useRef();
|
|
563
|
+
if (ref.current == null) {
|
|
564
|
+
ref.current = initial();
|
|
573
565
|
}
|
|
574
|
-
|
|
575
|
-
return undefined;
|
|
576
|
-
}
|
|
577
|
-
return rects[index];
|
|
566
|
+
return ref;
|
|
578
567
|
}
|
|
568
|
+
|
|
579
569
|
var NormalRowHeightKey = 'NormalRow';
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
570
|
+
/**
|
|
571
|
+
* 记录的所有行高信息
|
|
572
|
+
* 一个 Row 可能有多个行高。例如:默认情况下,只有一个行高,展开后,展开面板的高度也被认为是同一个 Row 的
|
|
573
|
+
* 所以可展开时,行高有多个,所有行高之和,则为 Row 的高度
|
|
574
|
+
* 行高之间使用唯一的 key 作为区分
|
|
575
|
+
* Record<rowKey, Map<key, height>>
|
|
576
|
+
*/
|
|
577
|
+
function useRowHeightMap(initial) {
|
|
578
|
+
var heightMap = useRef(null);
|
|
579
|
+
if (heightMap.current == null) {
|
|
580
|
+
var result = new Map();
|
|
581
|
+
heightMap.current = initial(result);
|
|
582
|
+
} else {
|
|
583
|
+
heightMap.current = initial(heightMap.current);
|
|
584
|
+
}
|
|
585
|
+
return heightMap;
|
|
586
|
+
}
|
|
587
|
+
function useRowHeight(options) {
|
|
588
|
+
var debugKey = options.debugKey,
|
|
585
589
|
estimateSize = options.estimateSize,
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
590
|
+
dataSource = options.dataSource,
|
|
591
|
+
rowKey = options.rowKey,
|
|
592
|
+
nodeHeightValid = options.nodeHeightValid;
|
|
593
|
+
var _useState = useState(function () {
|
|
594
|
+
return new Map();
|
|
595
|
+
}),
|
|
596
|
+
rowHeightByRowKey = _useState[0],
|
|
597
|
+
setRowHeightByRowKey = _useState[1];
|
|
598
|
+
var rowHeightByRowKeyRef = useRowHeightMap(function (state) {
|
|
599
|
+
// 行高信息(先填充预估高度,DOM渲染后再更新成实际高度)
|
|
600
|
+
if (dataSource.length === 0) {
|
|
601
|
+
state.clear();
|
|
602
|
+
return state;
|
|
603
|
+
}
|
|
604
|
+
dataSource.forEach(function (item) {
|
|
605
|
+
var _state$get;
|
|
606
|
+
var key = getRowKey(item, rowKey);
|
|
607
|
+
var row = (_state$get = state.get(key)) != null ? _state$get : new Map();
|
|
608
|
+
var target = row.get(NormalRowHeightKey);
|
|
609
|
+
if (target == null) {
|
|
610
|
+
row.set(NormalRowHeightKey, estimateSize);
|
|
611
|
+
}
|
|
612
|
+
state.set(key, row);
|
|
613
|
+
});
|
|
614
|
+
return state;
|
|
615
|
+
});
|
|
616
|
+
var calcRowHeights = function calcRowHeights() {
|
|
611
617
|
var heights = [];
|
|
612
|
-
|
|
618
|
+
dataSource.forEach(function (item) {
|
|
613
619
|
var key = getRowKey(item, rowKey);
|
|
614
|
-
var row =
|
|
620
|
+
var row = rowHeightByRowKeyRef.current.get(key);
|
|
615
621
|
if (row == null) {
|
|
616
622
|
heights.push(estimateSize);
|
|
617
623
|
} else {
|
|
@@ -624,41 +630,16 @@ function useRowVirtualize(options) {
|
|
|
624
630
|
});
|
|
625
631
|
return heights;
|
|
626
632
|
};
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
rowHeightByRowKey.current.clear();
|
|
631
|
-
return;
|
|
632
|
-
}
|
|
633
|
-
rawData.forEach(function (item) {
|
|
634
|
-
var _rowHeightByRowKey$cu2;
|
|
635
|
-
var key = getRowKey(item, rowKey);
|
|
636
|
-
var row = (_rowHeightByRowKey$cu2 = rowHeightByRowKey.current.get(key)) != null ? _rowHeightByRowKey$cu2 : new Map();
|
|
637
|
-
var target = row.get(NormalRowHeightKey);
|
|
638
|
-
if (target == null) {
|
|
639
|
-
row.set(NormalRowHeightKey, estimateSize);
|
|
640
|
-
}
|
|
641
|
-
rowHeightByRowKey.current.set(key, row);
|
|
642
|
-
});
|
|
643
|
-
};
|
|
644
|
-
fillRowHeights();
|
|
645
|
-
// 强制设置类型为 number[],在后面会初始化,只是为了减少 getAllRowHeights 的调用
|
|
646
|
-
var rowHeights = useRef();
|
|
647
|
-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
648
|
-
if (rowHeights.current == null) {
|
|
649
|
-
rowHeights.current = getAllRowHeights();
|
|
650
|
-
} else if (rawData.length !== rowHeights.current.length) {
|
|
651
|
-
// 这个判断条件主要是为了处理:空数据切换为有数据时 tbody 上 padding 缺失的问题
|
|
652
|
-
rowHeights.current = getAllRowHeights();
|
|
653
|
-
}
|
|
633
|
+
var _useState2 = useState(calcRowHeights),
|
|
634
|
+
rowHeights = _useState2[0],
|
|
635
|
+
setRowHeights = _useState2[1];
|
|
654
636
|
// 布局信息(也就是锚点元素需要的信息,top,bottom,height,index)
|
|
655
|
-
var
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
var _rowHeightByRowKey$cu3;
|
|
637
|
+
var calcRowRects = function calcRowRects() {
|
|
638
|
+
var _dataSource$reduce = dataSource.reduce(function (result, rowData, index) {
|
|
639
|
+
var _rowHeightByRowKeyRef;
|
|
659
640
|
var key = getRowKey(rowData, rowKey);
|
|
660
641
|
var height = 0;
|
|
661
|
-
(
|
|
642
|
+
(_rowHeightByRowKeyRef = rowHeightByRowKeyRef.current.get(key)) == null || _rowHeightByRowKeyRef.forEach(function (item) {
|
|
662
643
|
height += item;
|
|
663
644
|
});
|
|
664
645
|
var nextTop = result.top + height;
|
|
@@ -674,19 +655,131 @@ function useRowVirtualize(options) {
|
|
|
674
655
|
top: 0,
|
|
675
656
|
rects: []
|
|
676
657
|
}),
|
|
677
|
-
rects =
|
|
678
|
-
|
|
658
|
+
rects = _dataSource$reduce.rects;
|
|
659
|
+
return rects;
|
|
679
660
|
};
|
|
680
|
-
|
|
681
|
-
var
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
661
|
+
var rowRectsRef = useLazyRef(calcRowRects);
|
|
662
|
+
var measureTask = useRef(new Map());
|
|
663
|
+
var measureRowHeightByRowKey = useCallback(function (rowKey, key, height) {
|
|
664
|
+
var _measureTask$current$;
|
|
665
|
+
var row = (_measureTask$current$ = measureTask.current.get(rowKey)) != null ? _measureTask$current$ : new Map();
|
|
666
|
+
row.set(key, height);
|
|
667
|
+
measureTask.current.set(rowKey, row);
|
|
668
|
+
}, []);
|
|
669
|
+
useLayoutEffect(function () {
|
|
670
|
+
if (!nodeHeightValid()) return;
|
|
671
|
+
var needRender = false;
|
|
672
|
+
measureTask.current.forEach(function (currentRow, rowKey) {
|
|
673
|
+
var _rowHeightByRowKeyRef2;
|
|
674
|
+
var row = (_rowHeightByRowKeyRef2 = rowHeightByRowKeyRef.current.get(rowKey)) != null ? _rowHeightByRowKeyRef2 : new Map();
|
|
675
|
+
currentRow.forEach(function (getHeight, key) {
|
|
676
|
+
var height = getHeight();
|
|
677
|
+
if (debugKey === 'demo1') {
|
|
678
|
+
if (height === 0) {
|
|
679
|
+
// console.log('demo1.row.0', rowKey, key, height)
|
|
680
|
+
debugger;
|
|
681
|
+
getHeight();
|
|
682
|
+
}
|
|
683
|
+
}
|
|
684
|
+
var oldHeight = row.get(key);
|
|
685
|
+
if (height != null && (oldHeight == null || oldHeight !== height)) {
|
|
686
|
+
needRender = true;
|
|
687
|
+
row.set(key, height);
|
|
688
|
+
if (debugKey === 'demo1') {
|
|
689
|
+
if (height === 0) {
|
|
690
|
+
debugger;
|
|
691
|
+
}
|
|
692
|
+
// console.log(rowKey, key, oldHeight, height)
|
|
693
|
+
}
|
|
694
|
+
}
|
|
695
|
+
rowHeightByRowKeyRef.current.set(rowKey, row);
|
|
696
|
+
});
|
|
688
697
|
});
|
|
698
|
+
measureTask.current.clear();
|
|
699
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
700
|
+
if (needRender || dataSource.length !== rowHeights.length) {
|
|
701
|
+
needRender = false;
|
|
702
|
+
setRowHeightByRowKey(new Map(rowHeightByRowKeyRef.current));
|
|
703
|
+
setRowHeights(calcRowHeights());
|
|
704
|
+
rowRectsRef.current = calcRowRects();
|
|
705
|
+
}
|
|
706
|
+
});
|
|
707
|
+
return {
|
|
708
|
+
rowHeightByRowKey: rowHeightByRowKey,
|
|
709
|
+
rowHeightByRowKeyRef: rowHeightByRowKeyRef,
|
|
710
|
+
setRowHeightByRowKey: measureRowHeightByRowKey,
|
|
711
|
+
rowHeights: rowHeights,
|
|
712
|
+
rowRectsRef: rowRectsRef
|
|
689
713
|
};
|
|
714
|
+
}
|
|
715
|
+
|
|
716
|
+
function anchorQuery$1(rects, scrollTop) {
|
|
717
|
+
var left = 0;
|
|
718
|
+
var right = rects.length - 1;
|
|
719
|
+
var index = -1;
|
|
720
|
+
while (left <= right) {
|
|
721
|
+
var mid = Math.floor((left + right) / 2);
|
|
722
|
+
if (rects[mid].bottom > scrollTop) {
|
|
723
|
+
index = mid;
|
|
724
|
+
right = mid - 1;
|
|
725
|
+
} else {
|
|
726
|
+
left = mid + 1;
|
|
727
|
+
}
|
|
728
|
+
}
|
|
729
|
+
if (index === -1) {
|
|
730
|
+
return undefined;
|
|
731
|
+
}
|
|
732
|
+
return rects[index];
|
|
733
|
+
}
|
|
734
|
+
function useRowVirtualize(options) {
|
|
735
|
+
var debugKey = options.debugKey,
|
|
736
|
+
nodeHeightValid = options.nodeHeightValid,
|
|
737
|
+
getOffsetTop = options.getOffsetTop,
|
|
738
|
+
rowKey = options.rowKey,
|
|
739
|
+
rawData = options.dataSource,
|
|
740
|
+
getScroller = options.getScroller,
|
|
741
|
+
estimateSize = options.estimateSize,
|
|
742
|
+
overscan = options.overscan;
|
|
743
|
+
var _useRowHeight = useRowHeight({
|
|
744
|
+
dataSource: rawData,
|
|
745
|
+
rowKey: rowKey,
|
|
746
|
+
debugKey: debugKey,
|
|
747
|
+
estimateSize: estimateSize,
|
|
748
|
+
nodeHeightValid: nodeHeightValid
|
|
749
|
+
}),
|
|
750
|
+
rowHeightByRowKeyRef = _useRowHeight.rowHeightByRowKeyRef,
|
|
751
|
+
setRowHeightByRowKey = _useRowHeight.setRowHeightByRowKey,
|
|
752
|
+
rowRectsRef = _useRowHeight.rowRectsRef,
|
|
753
|
+
rowHeights = _useRowHeight.rowHeights;
|
|
754
|
+
var _useState = useState(0),
|
|
755
|
+
startIndex = _useState[0],
|
|
756
|
+
setStartIndex = _useState[1];
|
|
757
|
+
var _useState2 = useState(0),
|
|
758
|
+
endIndex = _useState2[0],
|
|
759
|
+
setEndIndex = _useState2[1];
|
|
760
|
+
// 解决 PR #5 的问题
|
|
761
|
+
// 在 scroll 事件中获取到当前的 node 高度为 0 就认为节点不可见,
|
|
762
|
+
// 就不需要触发 updateBoundary
|
|
763
|
+
// 把它推迟到下一次渲染检测 node 高度不为 0 的时候
|
|
764
|
+
// 场景:
|
|
765
|
+
// <Tabs /> 组件展示两个 Tab
|
|
766
|
+
// tab1 是以 window 为滚动容器的 table
|
|
767
|
+
// tab2 仅展示一行文字
|
|
768
|
+
// 滚动 tab1 让 startIndex 变化(假设是100),再切换到 tab2,此时由于内容变了
|
|
769
|
+
// 滚动条被重置为 0,再切换回 tab1 的时候,需要重新计算 startIndex,
|
|
770
|
+
// 否则 startIndex 还停留在上一次的 100,造成白屏
|
|
771
|
+
var reUpdateBoundary = useRef();
|
|
772
|
+
useLayoutEffect(function () {
|
|
773
|
+
var reUpdate = reUpdateBoundary.current;
|
|
774
|
+
if (reUpdate == null) return;
|
|
775
|
+
if (nodeHeightValid()) {
|
|
776
|
+
reUpdate();
|
|
777
|
+
reUpdateBoundary.current = undefined;
|
|
778
|
+
}
|
|
779
|
+
});
|
|
780
|
+
var dataSlice = useMemo(function () {
|
|
781
|
+
return rawData.slice(startIndex, endIndex);
|
|
782
|
+
}, [rawData, startIndex, endIndex]);
|
|
690
783
|
// 锚点元素,当前虚拟列表中,最接近滚动容器顶部的元素
|
|
691
784
|
var anchorRef = useRef({
|
|
692
785
|
index: 0,
|
|
@@ -726,7 +819,7 @@ function useRowVirtualize(options) {
|
|
|
726
819
|
};
|
|
727
820
|
};
|
|
728
821
|
var updateBoundary = function updateBoundary(scrollTop) {
|
|
729
|
-
var anchor = anchorQuery$1(
|
|
822
|
+
var anchor = anchorQuery$1(rowRectsRef.current, scrollTop);
|
|
730
823
|
if (anchor != null) {
|
|
731
824
|
anchorRef.current = anchor;
|
|
732
825
|
setStartIndex(Math.max(0, anchor.index - overscan));
|
|
@@ -742,18 +835,33 @@ function useRowVirtualize(options) {
|
|
|
742
835
|
if (isScrollDown) {
|
|
743
836
|
// 如果滚动距离比较小,没有超出锚点元素的边界,就不需要计算 startIndex、endIndex 了
|
|
744
837
|
if (scrollTop > anchorRef.current.bottom) {
|
|
745
|
-
|
|
838
|
+
if (!nodeHeightValid()) {
|
|
839
|
+
reUpdateBoundary.current = function () {
|
|
840
|
+
return updateBoundary(scrollTop);
|
|
841
|
+
};
|
|
842
|
+
} else {
|
|
843
|
+
updateBoundary(scrollTop);
|
|
844
|
+
}
|
|
746
845
|
}
|
|
747
846
|
} else {
|
|
748
847
|
if (scrollTop < anchorRef.current.top) {
|
|
749
|
-
|
|
848
|
+
if (!nodeHeightValid()) {
|
|
849
|
+
reUpdateBoundary.current = function () {
|
|
850
|
+
return updateBoundary(scrollTop);
|
|
851
|
+
};
|
|
852
|
+
} else {
|
|
853
|
+
updateBoundary(scrollTop);
|
|
854
|
+
}
|
|
750
855
|
}
|
|
751
856
|
}
|
|
752
857
|
scrollTopRef.current = scrollTop;
|
|
753
858
|
};
|
|
754
859
|
var prevHeight = 0;
|
|
755
860
|
var stopListen = onResize(container, function (rect) {
|
|
756
|
-
//
|
|
861
|
+
// 使用 div 作为滚动容器时,并且放置在 <Tabs> 组件内,当前 tab 切换到非激活状态时,
|
|
862
|
+
// 父元素会被设置 display:none,导致容器高度变为 0,导致调用 updateBoundary
|
|
863
|
+
// 来回切换会发现每一次都会往下移动几个 row
|
|
864
|
+
// 这里加一个判断,rect.height 为0时,不处理本次的 resize 事件(这就是 display:none)
|
|
757
865
|
if (rect.height === prevHeight || rect.height === 0) {
|
|
758
866
|
return;
|
|
759
867
|
}
|
|
@@ -779,9 +887,9 @@ function useRowVirtualize(options) {
|
|
|
779
887
|
stopListen();
|
|
780
888
|
container.removeEventListener('scroll', onScroll);
|
|
781
889
|
};
|
|
782
|
-
}, [estimateSize, getOffsetTop, getScroller, overscan, updateBoundaryFlagDep]);
|
|
890
|
+
}, [estimateSize, getOffsetTop, getScroller, overscan, updateBoundaryFlagDep, nodeHeightValid, rowRectsRef]);
|
|
783
891
|
var sum = function sum(startIndex, endIndex) {
|
|
784
|
-
return rowHeights.
|
|
892
|
+
return rowHeights.slice(startIndex, endIndex).reduce(function (a, b) {
|
|
785
893
|
return a + b;
|
|
786
894
|
}, 0);
|
|
787
895
|
};
|
|
@@ -792,8 +900,7 @@ function useRowVirtualize(options) {
|
|
|
792
900
|
startIndex: startIndex,
|
|
793
901
|
endIndex: endIndex,
|
|
794
902
|
rowHeightList: rowHeights,
|
|
795
|
-
|
|
796
|
-
rowHeightByRowKey: rowHeightByRowKey,
|
|
903
|
+
rowHeightByRowKeyRef: rowHeightByRowKeyRef,
|
|
797
904
|
setRowHeightByRowKey: setRowHeightByRowKey,
|
|
798
905
|
topBlank: topBlank,
|
|
799
906
|
bottomBlank: bottomBlank,
|
|
@@ -1133,8 +1240,19 @@ function useMergedRef() {
|
|
|
1133
1240
|
return useCallback(mergeRefs.apply(void 0, refs), refs);
|
|
1134
1241
|
}
|
|
1135
1242
|
|
|
1243
|
+
function useNodeHeight() {
|
|
1244
|
+
var nodeRef = useRef(null);
|
|
1245
|
+
var getIsVisible = useStableFn(function () {
|
|
1246
|
+
var node = nodeRef.current;
|
|
1247
|
+
if (node == null) return false;
|
|
1248
|
+
return node.offsetHeight > 0;
|
|
1249
|
+
});
|
|
1250
|
+
return [nodeRef, getIsVisible];
|
|
1251
|
+
}
|
|
1252
|
+
|
|
1136
1253
|
function TableBody(props) {
|
|
1137
|
-
var
|
|
1254
|
+
var debugKey = props.debugKey,
|
|
1255
|
+
bodyWrapperRef = props.bodyWrapperRef,
|
|
1138
1256
|
bodyRootRef = props.bodyRootRef,
|
|
1139
1257
|
bodyRef = props.bodyRef,
|
|
1140
1258
|
className = props.className,
|
|
@@ -1156,7 +1274,12 @@ function TableBody(props) {
|
|
|
1156
1274
|
renderBodyContent = props.renderBodyContent,
|
|
1157
1275
|
renderRow = props.renderRow,
|
|
1158
1276
|
renderCell = props.renderCell;
|
|
1277
|
+
var _useNodeHeight = useNodeHeight(),
|
|
1278
|
+
tbodyNode = _useNodeHeight[0],
|
|
1279
|
+
nodeHeightValid = _useNodeHeight[1];
|
|
1159
1280
|
var _useRowVirtualize = useRowVirtualize({
|
|
1281
|
+
debugKey: debugKey,
|
|
1282
|
+
nodeHeightValid: nodeHeightValid,
|
|
1160
1283
|
getOffsetTop: getOffsetTop,
|
|
1161
1284
|
rowKey: rowKey,
|
|
1162
1285
|
dataSource: rawData,
|
|
@@ -1167,9 +1290,8 @@ function TableBody(props) {
|
|
|
1167
1290
|
startIndex = _useRowVirtualize.startIndex,
|
|
1168
1291
|
endIndex = _useRowVirtualize.endIndex,
|
|
1169
1292
|
dataSource = _useRowVirtualize.dataSlice,
|
|
1170
|
-
|
|
1293
|
+
rowHeightByRowKeyRef = _useRowVirtualize.rowHeightByRowKeyRef,
|
|
1171
1294
|
setRowHeightByRowKey = _useRowVirtualize.setRowHeightByRowKey,
|
|
1172
|
-
flushLayout = _useRowVirtualize.flushLayout,
|
|
1173
1295
|
rowHeightList = _useRowVirtualize.rowHeightList,
|
|
1174
1296
|
topBlank = _useRowVirtualize.topBlank,
|
|
1175
1297
|
bottomBlank = _useRowVirtualize.bottomBlank;
|
|
@@ -1183,24 +1305,18 @@ function TableBody(props) {
|
|
|
1183
1305
|
};
|
|
1184
1306
|
},
|
|
1185
1307
|
getRowHeightMap: function getRowHeightMap() {
|
|
1186
|
-
return
|
|
1308
|
+
return rowHeightByRowKeyRef.current;
|
|
1187
1309
|
}
|
|
1188
1310
|
});
|
|
1189
|
-
var tbodyRef = useMergedRef(bodyRef,
|
|
1190
|
-
if (elm == null) return;
|
|
1191
|
-
var bodyHeight = elm.offsetHeight;
|
|
1192
|
-
if (bodyHeight === 0) return;
|
|
1193
|
-
// body 的 ref 回调函数中,说明 body 渲染完成,也就意味着所有的 tr 也已经渲染完成,
|
|
1194
|
-
// 现在可以记录所有 tr 的高度
|
|
1195
|
-
flushLayout();
|
|
1196
|
-
});
|
|
1311
|
+
var tbodyRef = useMergedRef(bodyRef, tbodyNode);
|
|
1197
1312
|
// 测量行高
|
|
1198
1313
|
var onMeasureRowHeight = useCallback(function (args) {
|
|
1199
1314
|
var node = args.node,
|
|
1200
1315
|
rowKey = args.rowKey;
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1316
|
+
setRowHeightByRowKey(rowKey, NormalRowHeightKey, function () {
|
|
1317
|
+
if (node == null) return;
|
|
1318
|
+
return node.offsetHeight;
|
|
1319
|
+
});
|
|
1204
1320
|
}, [setRowHeightByRowKey]);
|
|
1205
1321
|
var columns = columnDescriptor.columns,
|
|
1206
1322
|
descriptor = columnDescriptor.descriptor;
|
|
@@ -1267,7 +1383,7 @@ function TableBody(props) {
|
|
|
1267
1383
|
} else {
|
|
1268
1384
|
offset = Number.isFinite(stickyHeader) ? stickyHeader * -1 : 0;
|
|
1269
1385
|
}
|
|
1270
|
-
var targetScrollTop = rowHeightList.
|
|
1386
|
+
var targetScrollTop = rowHeightList.slice(0, index).reduce(function (a, b) {
|
|
1271
1387
|
return a + b;
|
|
1272
1388
|
}, 0);
|
|
1273
1389
|
return targetScrollTop + getOffsetTop() + offset;
|
|
@@ -1281,10 +1397,10 @@ function TableBody(props) {
|
|
|
1281
1397
|
});
|
|
1282
1398
|
var rowManageState = useMemo(function () {
|
|
1283
1399
|
return {
|
|
1284
|
-
setRowHeightByRowKey: setRowHeightByRowKey,
|
|
1285
1400
|
getRowHeightList: function getRowHeightList() {
|
|
1286
|
-
return rowHeightList
|
|
1287
|
-
}
|
|
1401
|
+
return rowHeightList;
|
|
1402
|
+
},
|
|
1403
|
+
setRowHeightByRowKey: setRowHeightByRowKey
|
|
1288
1404
|
};
|
|
1289
1405
|
}, [rowHeightList, setRowHeightByRowKey]);
|
|
1290
1406
|
return jsx(TableRowManager.Provider, {
|
|
@@ -1775,7 +1891,8 @@ function TableRoot(props, ref) {
|
|
|
1775
1891
|
var TableRoot$1 = /*#__PURE__*/forwardRef(TableRoot);
|
|
1776
1892
|
|
|
1777
1893
|
function VirtualTableCore(props, ref) {
|
|
1778
|
-
var
|
|
1894
|
+
var debugKey = props.debugKey,
|
|
1895
|
+
bodyRootRef = props.bodyRootRef,
|
|
1779
1896
|
rawInstance = props.instance,
|
|
1780
1897
|
className = props.className,
|
|
1781
1898
|
style = props.style,
|
|
@@ -2022,6 +2139,7 @@ function VirtualTableCore(props, ref) {
|
|
|
2022
2139
|
renderHeaderRow: renderHeaderRow,
|
|
2023
2140
|
renderHeaderCell: renderHeaderCell
|
|
2024
2141
|
}), jsx(TableBody, {
|
|
2142
|
+
debugKey: debugKey,
|
|
2025
2143
|
instance: instance,
|
|
2026
2144
|
bodyWrapperRef: bodyWrapperRef,
|
|
2027
2145
|
bodyRootRef: mergedBodyRootRef,
|