baseui 0.0.0-alpha-2158d09 → 0.0.0-alpha-bcb33da
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/data-table/data-table.js +50 -53
- package/data-table/data-table.js.flow +13 -18
- package/data-table/measure-column-widths.js +121 -83
- package/data-table/measure-column-widths.js.flow +109 -87
- package/es/data-table/data-table.js +16 -18
- package/es/data-table/measure-column-widths.js +86 -75
- package/esm/data-table/data-table.js +50 -53
- package/esm/data-table/measure-column-widths.js +121 -83
- package/package.json +1 -1
- package/es/utils/lcg.js +0 -14
- package/esm/utils/lcg.js +0 -16
- package/utils/lcg.js +0 -24
- package/utils/lcg.js.flow +0 -21
package/data-table/data-table.js
CHANGED
|
@@ -62,12 +62,6 @@ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
|
62
62
|
// consider pulling this out to a prop if useful.
|
|
63
63
|
var HEADER_ROW_HEIGHT = 48;
|
|
64
64
|
|
|
65
|
-
var sum = function sum(ns) {
|
|
66
|
-
return ns.reduce(function (s, n) {
|
|
67
|
-
return s + n;
|
|
68
|
-
}, 0);
|
|
69
|
-
};
|
|
70
|
-
|
|
71
65
|
function CellPlacement(_ref) {
|
|
72
66
|
var columnIndex = _ref.columnIndex,
|
|
73
67
|
rowIndex = _ref.rowIndex,
|
|
@@ -326,7 +320,7 @@ function Header(props) {
|
|
|
326
320
|
}))));
|
|
327
321
|
}
|
|
328
322
|
|
|
329
|
-
function Headers() {
|
|
323
|
+
function Headers(props) {
|
|
330
324
|
var _useStyletron5 = (0, _index2.useStyletron)(),
|
|
331
325
|
_useStyletron6 = _slicedToArray(_useStyletron5, 2),
|
|
332
326
|
css = _useStyletron6[0],
|
|
@@ -345,7 +339,9 @@ function Headers() {
|
|
|
345
339
|
position: 'sticky',
|
|
346
340
|
top: 0,
|
|
347
341
|
left: 0,
|
|
348
|
-
width: "".concat(
|
|
342
|
+
width: "".concat(ctx.widths.reduce(function (sum, w) {
|
|
343
|
+
return sum + w;
|
|
344
|
+
}, 0), "px"),
|
|
349
345
|
height: "".concat(HEADER_ROW_HEIGHT, "px"),
|
|
350
346
|
display: 'flex',
|
|
351
347
|
// this feels bad.. the absolutely positioned children elements
|
|
@@ -568,27 +564,22 @@ function DataTable(_ref2) {
|
|
|
568
564
|
}
|
|
569
565
|
|
|
570
566
|
return rowHeight;
|
|
571
|
-
}, [rowHeight]);
|
|
572
|
-
|
|
567
|
+
}, [rowHeight]);
|
|
568
|
+
var gridRef = React.useRef(null);
|
|
573
569
|
|
|
574
|
-
var _React$useState7 = React.useState(
|
|
570
|
+
var _React$useState7 = React.useState(columns.map(function () {
|
|
571
|
+
return 0;
|
|
572
|
+
})),
|
|
575
573
|
_React$useState8 = _slicedToArray(_React$useState7, 2),
|
|
576
|
-
|
|
577
|
-
|
|
574
|
+
measuredWidths = _React$useState8[0],
|
|
575
|
+
setMeasuredWidths = _React$useState8[1];
|
|
578
576
|
|
|
579
577
|
var _React$useState9 = React.useState(columns.map(function () {
|
|
580
578
|
return 0;
|
|
581
579
|
})),
|
|
582
580
|
_React$useState10 = _slicedToArray(_React$useState9, 2),
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
var _React$useState11 = React.useState(columns.map(function () {
|
|
587
|
-
return 0;
|
|
588
|
-
})),
|
|
589
|
-
_React$useState12 = _slicedToArray(_React$useState11, 2),
|
|
590
|
-
resizeDeltas = _React$useState12[0],
|
|
591
|
-
setResizeDeltas = _React$useState12[1];
|
|
581
|
+
resizeDeltas = _React$useState10[0],
|
|
582
|
+
setResizeDeltas = _React$useState10[1];
|
|
592
583
|
|
|
593
584
|
React.useEffect(function () {
|
|
594
585
|
setMeasuredWidths(function (prev) {
|
|
@@ -603,11 +594,11 @@ function DataTable(_ref2) {
|
|
|
603
594
|
});
|
|
604
595
|
}, [columns]);
|
|
605
596
|
var resetAfterColumnIndex = React.useCallback(function (columnIndex) {
|
|
606
|
-
if (gridRef) {
|
|
597
|
+
if (gridRef.current) {
|
|
607
598
|
// $FlowFixMe trigger react-window to layout the elements again
|
|
608
|
-
gridRef.resetAfterColumnIndex(columnIndex, true);
|
|
599
|
+
gridRef.current.resetAfterColumnIndex(columnIndex, true);
|
|
609
600
|
}
|
|
610
|
-
}, [gridRef]);
|
|
601
|
+
}, [gridRef.current]);
|
|
611
602
|
var handleWidthsChange = React.useCallback(function (nextWidths) {
|
|
612
603
|
setMeasuredWidths(nextWidths);
|
|
613
604
|
resetAfterColumnIndex(0);
|
|
@@ -620,20 +611,20 @@ function DataTable(_ref2) {
|
|
|
620
611
|
resetAfterColumnIndex(columnIndex);
|
|
621
612
|
}, [setResizeDeltas, resetAfterColumnIndex]);
|
|
622
613
|
|
|
623
|
-
var _React$
|
|
614
|
+
var _React$useState11 = React.useState(0),
|
|
615
|
+
_React$useState12 = _slicedToArray(_React$useState11, 2),
|
|
616
|
+
scrollLeft = _React$useState12[0],
|
|
617
|
+
setScrollLeft = _React$useState12[1];
|
|
618
|
+
|
|
619
|
+
var _React$useState13 = React.useState(false),
|
|
624
620
|
_React$useState14 = _slicedToArray(_React$useState13, 2),
|
|
625
|
-
|
|
626
|
-
|
|
621
|
+
isScrollingX = _React$useState14[0],
|
|
622
|
+
setIsScrollingX = _React$useState14[1];
|
|
627
623
|
|
|
628
624
|
var _React$useState15 = React.useState(false),
|
|
629
625
|
_React$useState16 = _slicedToArray(_React$useState15, 2),
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
var _React$useState17 = React.useState(false),
|
|
634
|
-
_React$useState18 = _slicedToArray(_React$useState17, 2),
|
|
635
|
-
recentlyScrolledX = _React$useState18[0],
|
|
636
|
-
setRecentlyScrolledX = _React$useState18[1];
|
|
626
|
+
recentlyScrolledX = _React$useState16[0],
|
|
627
|
+
setRecentlyScrolledX = _React$useState16[1];
|
|
637
628
|
|
|
638
629
|
React.useLayoutEffect(function () {
|
|
639
630
|
if (recentlyScrolledX !== isScrollingX) {
|
|
@@ -755,18 +746,25 @@ function DataTable(_ref2) {
|
|
|
755
746
|
return result;
|
|
756
747
|
}, [sortedIndices, filteredIndices, onIncludedRowsChange, allRows]);
|
|
757
748
|
|
|
758
|
-
var _React$
|
|
759
|
-
_React$
|
|
760
|
-
browserScrollbarWidth = _React$
|
|
761
|
-
setBrowserScrollbarWidth = _React$
|
|
749
|
+
var _React$useState17 = React.useState(0),
|
|
750
|
+
_React$useState18 = _slicedToArray(_React$useState17, 2),
|
|
751
|
+
browserScrollbarWidth = _React$useState18[0],
|
|
752
|
+
setBrowserScrollbarWidth = _React$useState18[1];
|
|
762
753
|
|
|
763
754
|
var normalizedWidths = React.useMemo(function () {
|
|
755
|
+
var sum = function sum(ns) {
|
|
756
|
+
return ns.reduce(function (s, n) {
|
|
757
|
+
return s + n;
|
|
758
|
+
}, 0);
|
|
759
|
+
};
|
|
760
|
+
|
|
764
761
|
var resizedWidths = measuredWidths.map(function (w, i) {
|
|
765
762
|
return Math.floor(w) + Math.floor(resizeDeltas[i]);
|
|
766
763
|
});
|
|
767
764
|
|
|
768
|
-
if (gridRef) {
|
|
769
|
-
|
|
765
|
+
if (gridRef.current) {
|
|
766
|
+
// $FlowFixMe
|
|
767
|
+
var gridProps = gridRef.current.props;
|
|
770
768
|
var isContentTallerThanContainer = false;
|
|
771
769
|
var visibleRowHeight = 0;
|
|
772
770
|
|
|
@@ -803,7 +801,7 @@ function DataTable(_ref2) {
|
|
|
803
801
|
}
|
|
804
802
|
|
|
805
803
|
return resizedWidths;
|
|
806
|
-
}, [
|
|
804
|
+
}, [measuredWidths, resizeDeltas, browserScrollbarWidth, rows.length, columns]);
|
|
807
805
|
var isSelectable = batchActions ? !!batchActions.length : false;
|
|
808
806
|
var isSelectedAll = React.useMemo(function () {
|
|
809
807
|
if (!selectedRowIds) {
|
|
@@ -847,23 +845,23 @@ function DataTable(_ref2) {
|
|
|
847
845
|
}
|
|
848
846
|
}, [onSort]);
|
|
849
847
|
|
|
848
|
+
var _React$useState19 = React.useState(-1),
|
|
849
|
+
_React$useState20 = _slicedToArray(_React$useState19, 2),
|
|
850
|
+
columnHighlightIndex = _React$useState20[0],
|
|
851
|
+
setColumnHighlightIndex = _React$useState20[1];
|
|
852
|
+
|
|
850
853
|
var _React$useState21 = React.useState(-1),
|
|
851
854
|
_React$useState22 = _slicedToArray(_React$useState21, 2),
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
var _React$useState23 = React.useState(-1),
|
|
856
|
-
_React$useState24 = _slicedToArray(_React$useState23, 2),
|
|
857
|
-
rowHighlightIndex = _React$useState24[0],
|
|
858
|
-
setRowHighlightIndex = _React$useState24[1];
|
|
855
|
+
rowHighlightIndex = _React$useState22[0],
|
|
856
|
+
setRowHighlightIndex = _React$useState22[1];
|
|
859
857
|
|
|
860
858
|
function handleRowHighlightIndexChange(nextIndex) {
|
|
861
859
|
setRowHighlightIndex(nextIndex);
|
|
862
860
|
|
|
863
|
-
if (gridRef) {
|
|
861
|
+
if (gridRef.current) {
|
|
864
862
|
if (nextIndex >= 0) {
|
|
865
863
|
// $FlowFixMe - unable to get react-window types
|
|
866
|
-
gridRef.scrollToItem({
|
|
864
|
+
gridRef.current.scrollToItem({
|
|
867
865
|
rowIndex: nextIndex
|
|
868
866
|
});
|
|
869
867
|
}
|
|
@@ -954,9 +952,8 @@ function DataTable(_ref2) {
|
|
|
954
952
|
}
|
|
955
953
|
}, /*#__PURE__*/React.createElement(_reactWindow.VariableSizeGrid // eslint-disable-next-line flowtype/no-weak-types
|
|
956
954
|
, {
|
|
957
|
-
ref:
|
|
955
|
+
ref: gridRef,
|
|
958
956
|
overscanRowCount: 10,
|
|
959
|
-
overscanColumnCount: 5,
|
|
960
957
|
innerElementType: InnerTableElement,
|
|
961
958
|
columnCount: columns.length,
|
|
962
959
|
columnWidth: function columnWidth(columnIndex) {
|
|
@@ -87,8 +87,6 @@ type CellPlacementPropsT = {
|
|
|
87
87
|
},
|
|
88
88
|
};
|
|
89
89
|
|
|
90
|
-
const sum = ns => ns.reduce((s, n) => s + n, 0);
|
|
91
|
-
|
|
92
90
|
function CellPlacement({columnIndex, rowIndex, data, style}) {
|
|
93
91
|
const [css, theme] = useStyletron();
|
|
94
92
|
|
|
@@ -413,7 +411,7 @@ function Header(props: HeaderProps) {
|
|
|
413
411
|
);
|
|
414
412
|
}
|
|
415
413
|
|
|
416
|
-
function Headers() {
|
|
414
|
+
function Headers(props: {||}) {
|
|
417
415
|
const [css, theme] = useStyletron();
|
|
418
416
|
const locale = React.useContext(LocaleContext);
|
|
419
417
|
const ctx = React.useContext(HeaderContext);
|
|
@@ -425,7 +423,7 @@ function Headers() {
|
|
|
425
423
|
position: 'sticky',
|
|
426
424
|
top: 0,
|
|
427
425
|
left: 0,
|
|
428
|
-
width: `${
|
|
426
|
+
width: `${ctx.widths.reduce((sum, w) => sum + w, 0)}px`,
|
|
429
427
|
height: `${HEADER_ROW_HEIGHT}px`,
|
|
430
428
|
display: 'flex',
|
|
431
429
|
// this feels bad.. the absolutely positioned children elements
|
|
@@ -698,10 +696,7 @@ export function DataTable({
|
|
|
698
696
|
},
|
|
699
697
|
[rowHeight],
|
|
700
698
|
);
|
|
701
|
-
|
|
702
|
-
// We use state for our ref, to allow hooks to update when the ref changes.
|
|
703
|
-
// eslint-disable-next-line flowtype/no-weak-types
|
|
704
|
-
const [gridRef, setGridRef] = React.useState<?VariableSizeGrid<any>>(null);
|
|
699
|
+
const gridRef = React.useRef<typeof VariableSizeGrid | null>(null);
|
|
705
700
|
const [measuredWidths, setMeasuredWidths] = React.useState(
|
|
706
701
|
columns.map(() => 0),
|
|
707
702
|
);
|
|
@@ -717,12 +712,12 @@ export function DataTable({
|
|
|
717
712
|
|
|
718
713
|
const resetAfterColumnIndex = React.useCallback(
|
|
719
714
|
columnIndex => {
|
|
720
|
-
if (gridRef) {
|
|
715
|
+
if (gridRef.current) {
|
|
721
716
|
// $FlowFixMe trigger react-window to layout the elements again
|
|
722
|
-
gridRef.resetAfterColumnIndex(columnIndex, true);
|
|
717
|
+
gridRef.current.resetAfterColumnIndex(columnIndex, true);
|
|
723
718
|
}
|
|
724
719
|
},
|
|
725
|
-
[gridRef],
|
|
720
|
+
[gridRef.current],
|
|
726
721
|
);
|
|
727
722
|
const handleWidthsChange = React.useCallback(
|
|
728
723
|
nextWidths => {
|
|
@@ -848,11 +843,13 @@ export function DataTable({
|
|
|
848
843
|
|
|
849
844
|
const [browserScrollbarWidth, setBrowserScrollbarWidth] = React.useState(0);
|
|
850
845
|
const normalizedWidths = React.useMemo(() => {
|
|
846
|
+
const sum = ns => ns.reduce((s, n) => s + n, 0);
|
|
851
847
|
const resizedWidths = measuredWidths.map(
|
|
852
848
|
(w, i) => Math.floor(w) + Math.floor(resizeDeltas[i]),
|
|
853
849
|
);
|
|
854
|
-
if (gridRef) {
|
|
855
|
-
|
|
850
|
+
if (gridRef.current) {
|
|
851
|
+
// $FlowFixMe
|
|
852
|
+
const gridProps = gridRef.current.props;
|
|
856
853
|
|
|
857
854
|
let isContentTallerThanContainer = false;
|
|
858
855
|
let visibleRowHeight = 0;
|
|
@@ -889,7 +886,6 @@ export function DataTable({
|
|
|
889
886
|
}
|
|
890
887
|
return resizedWidths;
|
|
891
888
|
}, [
|
|
892
|
-
gridRef,
|
|
893
889
|
measuredWidths,
|
|
894
890
|
resizeDeltas,
|
|
895
891
|
browserScrollbarWidth,
|
|
@@ -952,10 +948,10 @@ export function DataTable({
|
|
|
952
948
|
|
|
953
949
|
function handleRowHighlightIndexChange(nextIndex) {
|
|
954
950
|
setRowHighlightIndex(nextIndex);
|
|
955
|
-
if (gridRef) {
|
|
951
|
+
if (gridRef.current) {
|
|
956
952
|
if (nextIndex >= 0) {
|
|
957
953
|
// $FlowFixMe - unable to get react-window types
|
|
958
|
-
gridRef.scrollToItem({rowIndex: nextIndex});
|
|
954
|
+
gridRef.current.scrollToItem({rowIndex: nextIndex});
|
|
959
955
|
}
|
|
960
956
|
if (onRowHighlightChange) {
|
|
961
957
|
onRowHighlightChange(nextIndex, rows[nextIndex - 1]);
|
|
@@ -1055,9 +1051,8 @@ export function DataTable({
|
|
|
1055
1051
|
>
|
|
1056
1052
|
<VariableSizeGrid
|
|
1057
1053
|
// eslint-disable-next-line flowtype/no-weak-types
|
|
1058
|
-
ref={(
|
|
1054
|
+
ref={(gridRef: any)}
|
|
1059
1055
|
overscanRowCount={10}
|
|
1060
|
-
overscanColumnCount={5}
|
|
1061
1056
|
innerElementType={InnerTableElement}
|
|
1062
1057
|
columnCount={columns.length}
|
|
1063
1058
|
columnWidth={columnIndex => normalizedWidths[columnIndex]}
|
|
@@ -19,6 +19,14 @@ function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return
|
|
|
19
19
|
|
|
20
20
|
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
21
21
|
|
|
22
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
23
|
+
|
|
24
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
25
|
+
|
|
26
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter); }
|
|
27
|
+
|
|
28
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
29
|
+
|
|
22
30
|
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
23
31
|
|
|
24
32
|
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
@@ -31,61 +39,50 @@ function _iterableToArrayLimit(arr, i) { if (typeof Symbol === "undefined" || !(
|
|
|
31
39
|
|
|
32
40
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
33
41
|
|
|
34
|
-
//
|
|
35
|
-
function
|
|
36
|
-
var
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
isSelectable = _ref.isSelectable,
|
|
41
|
-
onLayout = _ref.onLayout;
|
|
42
|
+
// https://github.com/Swizec/useDimensions
|
|
43
|
+
function useDimensions() {
|
|
44
|
+
var _React$useState = React.useState({}),
|
|
45
|
+
_React$useState2 = _slicedToArray(_React$useState, 2),
|
|
46
|
+
dimensions = _React$useState2[0],
|
|
47
|
+
setDimensions = _React$useState2[1];
|
|
42
48
|
|
|
43
|
-
var
|
|
44
|
-
|
|
45
|
-
|
|
49
|
+
var _React$useState3 = React.useState(null),
|
|
50
|
+
_React$useState4 = _slicedToArray(_React$useState3, 2),
|
|
51
|
+
node = _React$useState4[0],
|
|
52
|
+
setNode = _React$useState4[1];
|
|
46
53
|
|
|
47
|
-
var ref =
|
|
54
|
+
var ref = React.useCallback(function (node) {
|
|
55
|
+
setNode(node);
|
|
56
|
+
}, []);
|
|
48
57
|
React.useEffect(function () {
|
|
49
|
-
if (
|
|
50
|
-
|
|
58
|
+
if (typeof document !== 'undefined') {
|
|
59
|
+
if (node) {
|
|
60
|
+
window.requestAnimationFrame(function () {
|
|
61
|
+
setDimensions(node.getBoundingClientRect());
|
|
62
|
+
});
|
|
63
|
+
}
|
|
51
64
|
}
|
|
52
|
-
}, []);
|
|
53
|
-
return
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
onSort: function onSort(i) {},
|
|
71
|
-
sortable: column.sortable,
|
|
72
|
-
sortDirection: null,
|
|
73
|
-
title: column.title,
|
|
74
|
-
isSelectable: isSelectable
|
|
75
|
-
}), sampleIndexes.map(function (rowIndex, i) {
|
|
76
|
-
var Cell = column.renderCell;
|
|
77
|
-
return /*#__PURE__*/React.createElement(Cell, {
|
|
78
|
-
key: "measure-".concat(i),
|
|
79
|
-
value: column.mapDataToValue(rows[rowIndex].data),
|
|
80
|
-
isSelectable: isSelectable,
|
|
81
|
-
isMeasured: true,
|
|
82
|
-
sortable: column.sortable,
|
|
83
|
-
x: 0,
|
|
84
|
-
y: rowIndex
|
|
85
|
-
});
|
|
86
|
-
}));
|
|
65
|
+
}, [node]);
|
|
66
|
+
return [ref, dimensions];
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function ElementMeasurer(props) {
|
|
70
|
+
var onDimensionsChange = props.onDimensionsChange;
|
|
71
|
+
|
|
72
|
+
var _useDimensions = useDimensions(),
|
|
73
|
+
_useDimensions2 = _slicedToArray(_useDimensions, 2),
|
|
74
|
+
ref = _useDimensions2[0],
|
|
75
|
+
dimensions = _useDimensions2[1];
|
|
76
|
+
|
|
77
|
+
React.useEffect(function () {
|
|
78
|
+
onDimensionsChange(dimensions);
|
|
79
|
+
}, [dimensions, onDimensionsChange]);
|
|
80
|
+
return /*#__PURE__*/React.cloneElement(props.item, {
|
|
81
|
+
ref: ref
|
|
82
|
+
});
|
|
87
83
|
}
|
|
88
84
|
|
|
85
|
+
// sample size could likely be generated based on row count, to have higher confidence
|
|
89
86
|
var MAX_SAMPLE_SIZE = 50;
|
|
90
87
|
|
|
91
88
|
function generateSampleIndices(inputMin, inputMax, maxSamples) {
|
|
@@ -117,46 +114,57 @@ function generateSampleIndices(inputMin, inputMax, maxSamples) {
|
|
|
117
114
|
return indices;
|
|
118
115
|
}
|
|
119
116
|
|
|
120
|
-
function MeasureColumnWidths(
|
|
121
|
-
var columns =
|
|
122
|
-
rows =
|
|
123
|
-
widths =
|
|
124
|
-
isSelectable =
|
|
125
|
-
onWidthsChange =
|
|
117
|
+
function MeasureColumnWidths(_ref) {
|
|
118
|
+
var columns = _ref.columns,
|
|
119
|
+
rows = _ref.rows,
|
|
120
|
+
widths = _ref.widths,
|
|
121
|
+
isSelectable = _ref.isSelectable,
|
|
122
|
+
onWidthsChange = _ref.onWidthsChange;
|
|
126
123
|
|
|
127
|
-
var
|
|
128
|
-
|
|
129
|
-
css =
|
|
124
|
+
var _useStyletron = (0, _index.useStyletron)(),
|
|
125
|
+
_useStyletron2 = _slicedToArray(_useStyletron, 1),
|
|
126
|
+
css = _useStyletron2[0];
|
|
130
127
|
|
|
131
|
-
var
|
|
132
|
-
|
|
133
|
-
}, []);
|
|
128
|
+
var measurementCount = React.useRef(0);
|
|
129
|
+
var dimensionsCache = React.useRef(widths);
|
|
134
130
|
var sampleSize = rows.length < MAX_SAMPLE_SIZE ? rows.length : MAX_SAMPLE_SIZE;
|
|
135
131
|
var finishedMeasurementCount = (sampleSize + 1) * columns.length;
|
|
136
|
-
var
|
|
137
|
-
|
|
132
|
+
var sampleRowIndicesByColumn = React.useMemo(function () {
|
|
133
|
+
measurementCount.current = 0;
|
|
134
|
+
dimensionsCache.current = widths;
|
|
135
|
+
var indices = generateSampleIndices(0, rows.length - 1, sampleSize);
|
|
136
|
+
return columns.map(function () {
|
|
137
|
+
return indices;
|
|
138
|
+
});
|
|
138
139
|
}, [columns, rows, widths, sampleSize]);
|
|
139
|
-
var handleDimensionsChange = React.useCallback(function (columnIndex, dimensions) {
|
|
140
|
-
|
|
140
|
+
var handleDimensionsChange = React.useCallback(function (columnIndex, rowIndex, dimensions) {
|
|
141
|
+
if (dimensions.width === undefined) return;
|
|
141
142
|
|
|
142
|
-
if (
|
|
143
|
-
|
|
143
|
+
if (columns[columnIndex] === undefined || dimensionsCache.current[columnIndex] === undefined) {
|
|
144
|
+
return;
|
|
144
145
|
}
|
|
145
146
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
147
|
+
measurementCount.current += 1;
|
|
148
|
+
var nextWidth = Math.min(Math.max(columns[columnIndex].minWidth || 0, dimensionsCache.current[columnIndex], dimensions.width + 1), columns[columnIndex].maxWidth || Infinity);
|
|
149
|
+
|
|
150
|
+
if (nextWidth !== dimensionsCache.current[columnIndex]) {
|
|
151
|
+
var nextWidths = _toConsumableArray(dimensionsCache.current);
|
|
152
|
+
|
|
153
|
+
nextWidths[columnIndex] = nextWidth;
|
|
154
|
+
dimensionsCache.current = nextWidths;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
if (measurementCount.current >= finishedMeasurementCount) {
|
|
158
|
+
onWidthsChange(dimensionsCache.current);
|
|
151
159
|
}
|
|
152
160
|
}, [columns, finishedMeasurementCount, onWidthsChange]);
|
|
153
161
|
var hiddenStyle = css({
|
|
154
162
|
position: 'absolute',
|
|
155
163
|
overflow: 'hidden',
|
|
156
164
|
height: 0
|
|
157
|
-
});
|
|
165
|
+
});
|
|
158
166
|
|
|
159
|
-
if (
|
|
167
|
+
if (measurementCount.current >= finishedMeasurementCount) {
|
|
160
168
|
return null;
|
|
161
169
|
}
|
|
162
170
|
|
|
@@ -167,15 +175,45 @@ function MeasureColumnWidths(_ref2) {
|
|
|
167
175
|
className: hiddenStyle,
|
|
168
176
|
"aria-hidden": true,
|
|
169
177
|
role: "none"
|
|
170
|
-
},
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
178
|
+
}, sampleRowIndicesByColumn.map(function (rowIndices, columnIndex) {
|
|
179
|
+
var Cell = columns[columnIndex].renderCell;
|
|
180
|
+
return rowIndices.map(function (rowIndex) {
|
|
181
|
+
return /*#__PURE__*/React.createElement(ElementMeasurer, {
|
|
182
|
+
key: "measure-".concat(columnIndex, "-").concat(rowIndex),
|
|
183
|
+
onDimensionsChange: function onDimensionsChange(dimensions) {
|
|
184
|
+
return handleDimensionsChange(columnIndex, rowIndex, dimensions);
|
|
185
|
+
},
|
|
186
|
+
item: /*#__PURE__*/React.createElement(Cell, {
|
|
187
|
+
value: columns[columnIndex].mapDataToValue(rows[rowIndex].data),
|
|
188
|
+
isMeasured: true,
|
|
189
|
+
onSelect: isSelectable && columnIndex === 0 ? function () {} : undefined,
|
|
190
|
+
x: columnIndex,
|
|
191
|
+
y: rowIndex
|
|
192
|
+
})
|
|
193
|
+
});
|
|
194
|
+
});
|
|
195
|
+
}), columns.map(function (column, columnIndex) {
|
|
196
|
+
return /*#__PURE__*/React.createElement(ElementMeasurer, {
|
|
197
|
+
key: "measure-column-".concat(columnIndex),
|
|
198
|
+
onDimensionsChange: function onDimensionsChange(dimensions) {
|
|
199
|
+
return handleDimensionsChange(columnIndex, -1, dimensions);
|
|
200
|
+
},
|
|
201
|
+
item: /*#__PURE__*/React.createElement(_headerCell.default, {
|
|
202
|
+
index: columnIndex,
|
|
203
|
+
isHovered: true,
|
|
204
|
+
isMeasured: true,
|
|
205
|
+
isSelectable: isSelectable && columnIndex === 0,
|
|
206
|
+
isSelectedAll: false,
|
|
207
|
+
isSelectedIndeterminate: false,
|
|
208
|
+
onMouseEnter: function onMouseEnter() {},
|
|
209
|
+
onMouseLeave: function onMouseLeave() {},
|
|
210
|
+
onSelectAll: function onSelectAll() {},
|
|
211
|
+
onSelectNone: function onSelectNone() {},
|
|
212
|
+
onSort: function onSort(i) {},
|
|
213
|
+
sortable: column.sortable,
|
|
214
|
+
sortDirection: null,
|
|
215
|
+
title: column.title
|
|
216
|
+
})
|
|
179
217
|
});
|
|
180
218
|
}))
|
|
181
219
|
);
|