@are-visual/virtual-table 0.11.4 → 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 +197 -122
- 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
|
@@ -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, useEffect, useState,
|
|
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);
|
|
@@ -558,6 +558,161 @@ function onResize(target, callback) {
|
|
|
558
558
|
}
|
|
559
559
|
}
|
|
560
560
|
|
|
561
|
+
function useLazyRef(initial) {
|
|
562
|
+
var ref = useRef();
|
|
563
|
+
if (ref.current == null) {
|
|
564
|
+
ref.current = initial();
|
|
565
|
+
}
|
|
566
|
+
return ref;
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
var NormalRowHeightKey = 'NormalRow';
|
|
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,
|
|
589
|
+
estimateSize = options.estimateSize,
|
|
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() {
|
|
617
|
+
var heights = [];
|
|
618
|
+
dataSource.forEach(function (item) {
|
|
619
|
+
var key = getRowKey(item, rowKey);
|
|
620
|
+
var row = rowHeightByRowKeyRef.current.get(key);
|
|
621
|
+
if (row == null) {
|
|
622
|
+
heights.push(estimateSize);
|
|
623
|
+
} else {
|
|
624
|
+
var height = 0;
|
|
625
|
+
row.forEach(function (x) {
|
|
626
|
+
return height += x;
|
|
627
|
+
});
|
|
628
|
+
heights.push(height);
|
|
629
|
+
}
|
|
630
|
+
});
|
|
631
|
+
return heights;
|
|
632
|
+
};
|
|
633
|
+
var _useState2 = useState(calcRowHeights),
|
|
634
|
+
rowHeights = _useState2[0],
|
|
635
|
+
setRowHeights = _useState2[1];
|
|
636
|
+
// 布局信息(也就是锚点元素需要的信息,top,bottom,height,index)
|
|
637
|
+
var calcRowRects = function calcRowRects() {
|
|
638
|
+
var _dataSource$reduce = dataSource.reduce(function (result, rowData, index) {
|
|
639
|
+
var _rowHeightByRowKeyRef;
|
|
640
|
+
var key = getRowKey(rowData, rowKey);
|
|
641
|
+
var height = 0;
|
|
642
|
+
(_rowHeightByRowKeyRef = rowHeightByRowKeyRef.current.get(key)) == null || _rowHeightByRowKeyRef.forEach(function (item) {
|
|
643
|
+
height += item;
|
|
644
|
+
});
|
|
645
|
+
var nextTop = result.top + height;
|
|
646
|
+
result.rects.push({
|
|
647
|
+
index: index,
|
|
648
|
+
top: result.top,
|
|
649
|
+
height: height,
|
|
650
|
+
bottom: nextTop
|
|
651
|
+
});
|
|
652
|
+
result.top = nextTop;
|
|
653
|
+
return result;
|
|
654
|
+
}, {
|
|
655
|
+
top: 0,
|
|
656
|
+
rects: []
|
|
657
|
+
}),
|
|
658
|
+
rects = _dataSource$reduce.rects;
|
|
659
|
+
return rects;
|
|
660
|
+
};
|
|
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
|
+
});
|
|
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
|
|
713
|
+
};
|
|
714
|
+
}
|
|
715
|
+
|
|
561
716
|
function anchorQuery$1(rects, scrollTop) {
|
|
562
717
|
var left = 0;
|
|
563
718
|
var right = rects.length - 1;
|
|
@@ -576,15 +731,26 @@ function anchorQuery$1(rects, scrollTop) {
|
|
|
576
731
|
}
|
|
577
732
|
return rects[index];
|
|
578
733
|
}
|
|
579
|
-
var NormalRowHeightKey = 'NormalRow';
|
|
580
734
|
function useRowVirtualize(options) {
|
|
581
|
-
var
|
|
735
|
+
var debugKey = options.debugKey,
|
|
736
|
+
nodeHeightValid = options.nodeHeightValid,
|
|
582
737
|
getOffsetTop = options.getOffsetTop,
|
|
583
738
|
rowKey = options.rowKey,
|
|
584
739
|
rawData = options.dataSource,
|
|
585
740
|
getScroller = options.getScroller,
|
|
586
741
|
estimateSize = options.estimateSize,
|
|
587
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;
|
|
588
754
|
var _useState = useState(0),
|
|
589
755
|
startIndex = _useState[0],
|
|
590
756
|
setStartIndex = _useState[1];
|
|
@@ -595,6 +761,13 @@ function useRowVirtualize(options) {
|
|
|
595
761
|
// 在 scroll 事件中获取到当前的 node 高度为 0 就认为节点不可见,
|
|
596
762
|
// 就不需要触发 updateBoundary
|
|
597
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,造成白屏
|
|
598
771
|
var reUpdateBoundary = useRef();
|
|
599
772
|
useLayoutEffect(function () {
|
|
600
773
|
var reUpdate = reUpdateBoundary.current;
|
|
@@ -607,100 +780,6 @@ function useRowVirtualize(options) {
|
|
|
607
780
|
var dataSlice = useMemo(function () {
|
|
608
781
|
return rawData.slice(startIndex, endIndex);
|
|
609
782
|
}, [rawData, startIndex, endIndex]);
|
|
610
|
-
/**
|
|
611
|
-
* 记录的所有行高信息
|
|
612
|
-
* 一个 Row 可能有多个行高。例如:默认情况下,只有一个行高,展开后,展开面板的高度也被认为是同一个 Row 的
|
|
613
|
-
* 所以可展开时,行高有多个,所有行高之和,则为 Row 的高度
|
|
614
|
-
* 行高之间使用唯一的 key 作为区分
|
|
615
|
-
* Record<rowKey, Map<key, height>>
|
|
616
|
-
*/
|
|
617
|
-
var rowHeightByRowKey = useRef(new Map());
|
|
618
|
-
var setRowHeightByRowKey = useCallback(function (rowKey, key, height) {
|
|
619
|
-
var _rowHeightByRowKey$cu;
|
|
620
|
-
var target = (_rowHeightByRowKey$cu = rowHeightByRowKey.current.get(rowKey)) != null ? _rowHeightByRowKey$cu : new Map();
|
|
621
|
-
target.set(key, height);
|
|
622
|
-
rowHeightByRowKey.current.set(rowKey, target);
|
|
623
|
-
}, []);
|
|
624
|
-
var getAllRowHeights = function getAllRowHeights() {
|
|
625
|
-
var heights = [];
|
|
626
|
-
rawData.forEach(function (item) {
|
|
627
|
-
var key = getRowKey(item, rowKey);
|
|
628
|
-
var row = rowHeightByRowKey.current.get(key);
|
|
629
|
-
if (row == null) {
|
|
630
|
-
heights.push(estimateSize);
|
|
631
|
-
} else {
|
|
632
|
-
var height = 0;
|
|
633
|
-
row.forEach(function (x) {
|
|
634
|
-
return height += x;
|
|
635
|
-
});
|
|
636
|
-
heights.push(height);
|
|
637
|
-
}
|
|
638
|
-
});
|
|
639
|
-
return heights;
|
|
640
|
-
};
|
|
641
|
-
// 行高信息(先填充预估高度,DOM渲染后再更新成实际高度)
|
|
642
|
-
var fillRowHeights = function fillRowHeights() {
|
|
643
|
-
if (rawData.length === 0) {
|
|
644
|
-
rowHeightByRowKey.current.clear();
|
|
645
|
-
return;
|
|
646
|
-
}
|
|
647
|
-
rawData.forEach(function (item) {
|
|
648
|
-
var _rowHeightByRowKey$cu2;
|
|
649
|
-
var key = getRowKey(item, rowKey);
|
|
650
|
-
var row = (_rowHeightByRowKey$cu2 = rowHeightByRowKey.current.get(key)) != null ? _rowHeightByRowKey$cu2 : new Map();
|
|
651
|
-
var target = row.get(NormalRowHeightKey);
|
|
652
|
-
if (target == null) {
|
|
653
|
-
row.set(NormalRowHeightKey, estimateSize);
|
|
654
|
-
}
|
|
655
|
-
rowHeightByRowKey.current.set(key, row);
|
|
656
|
-
});
|
|
657
|
-
};
|
|
658
|
-
fillRowHeights();
|
|
659
|
-
// 强制设置类型为 number[],在后面会初始化,只是为了减少 getAllRowHeights 的调用
|
|
660
|
-
var rowHeights = useRef();
|
|
661
|
-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
662
|
-
if (rowHeights.current == null) {
|
|
663
|
-
rowHeights.current = getAllRowHeights();
|
|
664
|
-
} else if (rawData.length !== rowHeights.current.length) {
|
|
665
|
-
// 这个判断条件主要是为了处理:空数据切换为有数据时 tbody 上 padding 缺失的问题
|
|
666
|
-
rowHeights.current = getAllRowHeights();
|
|
667
|
-
}
|
|
668
|
-
// 布局信息(也就是锚点元素需要的信息,top,bottom,height,index)
|
|
669
|
-
var rowRects = useRef([]);
|
|
670
|
-
var updateRowRects = function updateRowRects() {
|
|
671
|
-
var _rawData$reduce = rawData.reduce(function (result, rowData, index) {
|
|
672
|
-
var _rowHeightByRowKey$cu3;
|
|
673
|
-
var key = getRowKey(rowData, rowKey);
|
|
674
|
-
var height = 0;
|
|
675
|
-
(_rowHeightByRowKey$cu3 = rowHeightByRowKey.current.get(key)) == null || _rowHeightByRowKey$cu3.forEach(function (item) {
|
|
676
|
-
height += item;
|
|
677
|
-
});
|
|
678
|
-
var nextTop = result.top + height;
|
|
679
|
-
result.rects.push({
|
|
680
|
-
index: index,
|
|
681
|
-
top: result.top,
|
|
682
|
-
height: height,
|
|
683
|
-
bottom: nextTop
|
|
684
|
-
});
|
|
685
|
-
result.top = nextTop;
|
|
686
|
-
return result;
|
|
687
|
-
}, {
|
|
688
|
-
top: 0,
|
|
689
|
-
rects: []
|
|
690
|
-
}),
|
|
691
|
-
rects = _rawData$reduce.rects;
|
|
692
|
-
rowRects.current = rects;
|
|
693
|
-
};
|
|
694
|
-
/** 刷新布局信息,行高变化的时候调用,要重新组织布局信息(rowRects) */
|
|
695
|
-
var flushLayout = function flushLayout(fn) {
|
|
696
|
-
fn == null || fn();
|
|
697
|
-
updateRowRects();
|
|
698
|
-
// 组件渲染后会触发 flushLayout,表示行高有更新所以需要更新一下 rowHeights
|
|
699
|
-
// 避免展开行之后记录的还是之前的行高信息,否则滚动后底部会出现空白区域
|
|
700
|
-
rowHeights.current = rowRects.current.map(function (x) {
|
|
701
|
-
return x.height;
|
|
702
|
-
});
|
|
703
|
-
};
|
|
704
783
|
// 锚点元素,当前虚拟列表中,最接近滚动容器顶部的元素
|
|
705
784
|
var anchorRef = useRef({
|
|
706
785
|
index: 0,
|
|
@@ -740,7 +819,7 @@ function useRowVirtualize(options) {
|
|
|
740
819
|
};
|
|
741
820
|
};
|
|
742
821
|
var updateBoundary = function updateBoundary(scrollTop) {
|
|
743
|
-
var anchor = anchorQuery$1(
|
|
822
|
+
var anchor = anchorQuery$1(rowRectsRef.current, scrollTop);
|
|
744
823
|
if (anchor != null) {
|
|
745
824
|
anchorRef.current = anchor;
|
|
746
825
|
setStartIndex(Math.max(0, anchor.index - overscan));
|
|
@@ -808,9 +887,9 @@ function useRowVirtualize(options) {
|
|
|
808
887
|
stopListen();
|
|
809
888
|
container.removeEventListener('scroll', onScroll);
|
|
810
889
|
};
|
|
811
|
-
}, [estimateSize, getOffsetTop, getScroller, overscan, updateBoundaryFlagDep, nodeHeightValid]);
|
|
890
|
+
}, [estimateSize, getOffsetTop, getScroller, overscan, updateBoundaryFlagDep, nodeHeightValid, rowRectsRef]);
|
|
812
891
|
var sum = function sum(startIndex, endIndex) {
|
|
813
|
-
return rowHeights.
|
|
892
|
+
return rowHeights.slice(startIndex, endIndex).reduce(function (a, b) {
|
|
814
893
|
return a + b;
|
|
815
894
|
}, 0);
|
|
816
895
|
};
|
|
@@ -821,8 +900,7 @@ function useRowVirtualize(options) {
|
|
|
821
900
|
startIndex: startIndex,
|
|
822
901
|
endIndex: endIndex,
|
|
823
902
|
rowHeightList: rowHeights,
|
|
824
|
-
|
|
825
|
-
rowHeightByRowKey: rowHeightByRowKey,
|
|
903
|
+
rowHeightByRowKeyRef: rowHeightByRowKeyRef,
|
|
826
904
|
setRowHeightByRowKey: setRowHeightByRowKey,
|
|
827
905
|
topBlank: topBlank,
|
|
828
906
|
bottomBlank: bottomBlank,
|
|
@@ -1173,7 +1251,8 @@ function useNodeHeight() {
|
|
|
1173
1251
|
}
|
|
1174
1252
|
|
|
1175
1253
|
function TableBody(props) {
|
|
1176
|
-
var
|
|
1254
|
+
var debugKey = props.debugKey,
|
|
1255
|
+
bodyWrapperRef = props.bodyWrapperRef,
|
|
1177
1256
|
bodyRootRef = props.bodyRootRef,
|
|
1178
1257
|
bodyRef = props.bodyRef,
|
|
1179
1258
|
className = props.className,
|
|
@@ -1199,6 +1278,7 @@ function TableBody(props) {
|
|
|
1199
1278
|
tbodyNode = _useNodeHeight[0],
|
|
1200
1279
|
nodeHeightValid = _useNodeHeight[1];
|
|
1201
1280
|
var _useRowVirtualize = useRowVirtualize({
|
|
1281
|
+
debugKey: debugKey,
|
|
1202
1282
|
nodeHeightValid: nodeHeightValid,
|
|
1203
1283
|
getOffsetTop: getOffsetTop,
|
|
1204
1284
|
rowKey: rowKey,
|
|
@@ -1210,9 +1290,8 @@ function TableBody(props) {
|
|
|
1210
1290
|
startIndex = _useRowVirtualize.startIndex,
|
|
1211
1291
|
endIndex = _useRowVirtualize.endIndex,
|
|
1212
1292
|
dataSource = _useRowVirtualize.dataSlice,
|
|
1213
|
-
|
|
1293
|
+
rowHeightByRowKeyRef = _useRowVirtualize.rowHeightByRowKeyRef,
|
|
1214
1294
|
setRowHeightByRowKey = _useRowVirtualize.setRowHeightByRowKey,
|
|
1215
|
-
flushLayout = _useRowVirtualize.flushLayout,
|
|
1216
1295
|
rowHeightList = _useRowVirtualize.rowHeightList,
|
|
1217
1296
|
topBlank = _useRowVirtualize.topBlank,
|
|
1218
1297
|
bottomBlank = _useRowVirtualize.bottomBlank;
|
|
@@ -1226,24 +1305,18 @@ function TableBody(props) {
|
|
|
1226
1305
|
};
|
|
1227
1306
|
},
|
|
1228
1307
|
getRowHeightMap: function getRowHeightMap() {
|
|
1229
|
-
return
|
|
1308
|
+
return rowHeightByRowKeyRef.current;
|
|
1230
1309
|
}
|
|
1231
1310
|
});
|
|
1232
|
-
var tbodyRef = useMergedRef(bodyRef, tbodyNode
|
|
1233
|
-
if (elm == null) return;
|
|
1234
|
-
var bodyHeight = elm.offsetHeight;
|
|
1235
|
-
if (bodyHeight === 0) return;
|
|
1236
|
-
// body 的 ref 回调函数中,说明 body 渲染完成,也就意味着所有的 tr 也已经渲染完成,
|
|
1237
|
-
// 现在可以记录所有 tr 的高度
|
|
1238
|
-
flushLayout();
|
|
1239
|
-
});
|
|
1311
|
+
var tbodyRef = useMergedRef(bodyRef, tbodyNode);
|
|
1240
1312
|
// 测量行高
|
|
1241
1313
|
var onMeasureRowHeight = useCallback(function (args) {
|
|
1242
1314
|
var node = args.node,
|
|
1243
1315
|
rowKey = args.rowKey;
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1316
|
+
setRowHeightByRowKey(rowKey, NormalRowHeightKey, function () {
|
|
1317
|
+
if (node == null) return;
|
|
1318
|
+
return node.offsetHeight;
|
|
1319
|
+
});
|
|
1247
1320
|
}, [setRowHeightByRowKey]);
|
|
1248
1321
|
var columns = columnDescriptor.columns,
|
|
1249
1322
|
descriptor = columnDescriptor.descriptor;
|
|
@@ -1310,7 +1383,7 @@ function TableBody(props) {
|
|
|
1310
1383
|
} else {
|
|
1311
1384
|
offset = Number.isFinite(stickyHeader) ? stickyHeader * -1 : 0;
|
|
1312
1385
|
}
|
|
1313
|
-
var targetScrollTop = rowHeightList.
|
|
1386
|
+
var targetScrollTop = rowHeightList.slice(0, index).reduce(function (a, b) {
|
|
1314
1387
|
return a + b;
|
|
1315
1388
|
}, 0);
|
|
1316
1389
|
return targetScrollTop + getOffsetTop() + offset;
|
|
@@ -1324,10 +1397,10 @@ function TableBody(props) {
|
|
|
1324
1397
|
});
|
|
1325
1398
|
var rowManageState = useMemo(function () {
|
|
1326
1399
|
return {
|
|
1327
|
-
setRowHeightByRowKey: setRowHeightByRowKey,
|
|
1328
1400
|
getRowHeightList: function getRowHeightList() {
|
|
1329
|
-
return rowHeightList
|
|
1330
|
-
}
|
|
1401
|
+
return rowHeightList;
|
|
1402
|
+
},
|
|
1403
|
+
setRowHeightByRowKey: setRowHeightByRowKey
|
|
1331
1404
|
};
|
|
1332
1405
|
}, [rowHeightList, setRowHeightByRowKey]);
|
|
1333
1406
|
return jsx(TableRowManager.Provider, {
|
|
@@ -1818,7 +1891,8 @@ function TableRoot(props, ref) {
|
|
|
1818
1891
|
var TableRoot$1 = /*#__PURE__*/forwardRef(TableRoot);
|
|
1819
1892
|
|
|
1820
1893
|
function VirtualTableCore(props, ref) {
|
|
1821
|
-
var
|
|
1894
|
+
var debugKey = props.debugKey,
|
|
1895
|
+
bodyRootRef = props.bodyRootRef,
|
|
1822
1896
|
rawInstance = props.instance,
|
|
1823
1897
|
className = props.className,
|
|
1824
1898
|
style = props.style,
|
|
@@ -2065,6 +2139,7 @@ function VirtualTableCore(props, ref) {
|
|
|
2065
2139
|
renderHeaderRow: renderHeaderRow,
|
|
2066
2140
|
renderHeaderCell: renderHeaderCell
|
|
2067
2141
|
}), jsx(TableBody, {
|
|
2142
|
+
debugKey: debugKey,
|
|
2068
2143
|
instance: instance,
|
|
2069
2144
|
bodyWrapperRef: bodyWrapperRef,
|
|
2070
2145
|
bodyRootRef: mergedBodyRootRef,
|