material-react-table 0.20.0 → 0.21.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/dist/MaterialReactTable.d.ts +2 -1
- package/dist/material-react-table.cjs.development.js +348 -398
- package/dist/material-react-table.cjs.development.js.map +1 -1
- package/dist/material-react-table.cjs.production.min.js +1 -1
- package/dist/material-react-table.cjs.production.min.js.map +1 -1
- package/dist/material-react-table.esm.js +8 -12
- package/dist/material-react-table.esm.js.map +1 -1
- package/package.json +3 -3
- package/src/MaterialReactTable.tsx +2 -2
- package/src/body/MRT_TableBody.tsx +9 -10
@@ -6365,28 +6365,40 @@ var MRT_TableHead = function MRT_TableHead(_ref) {
|
|
6365
6365
|
}));
|
6366
6366
|
};
|
6367
6367
|
|
6368
|
-
|
6369
|
-
|
6370
|
-
|
6371
|
-
|
6372
|
-
*
|
6373
|
-
* This source code is licensed under the MIT license found in the
|
6374
|
-
* LICENSE.md file in the root directory of this source tree.
|
6375
|
-
*
|
6376
|
-
* @license MIT
|
6377
|
-
*/
|
6368
|
+
function _extends$1() {
|
6369
|
+
_extends$1 = Object.assign || function (target) {
|
6370
|
+
for (var i = 1; i < arguments.length; i++) {
|
6371
|
+
var source = arguments[i];
|
6378
6372
|
|
6379
|
-
|
6380
|
-
|
6381
|
-
|
6382
|
-
|
6383
|
-
|
6384
|
-
|
6385
|
-
|
6386
|
-
|
6387
|
-
|
6388
|
-
|
6389
|
-
|
6373
|
+
for (var key in source) {
|
6374
|
+
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
6375
|
+
target[key] = source[key];
|
6376
|
+
}
|
6377
|
+
}
|
6378
|
+
}
|
6379
|
+
|
6380
|
+
return target;
|
6381
|
+
};
|
6382
|
+
|
6383
|
+
return _extends$1.apply(this, arguments);
|
6384
|
+
}
|
6385
|
+
|
6386
|
+
function _objectWithoutPropertiesLoose$2(source, excluded) {
|
6387
|
+
if (source == null) return {};
|
6388
|
+
var target = {};
|
6389
|
+
var sourceKeys = Object.keys(source);
|
6390
|
+
var key, i;
|
6391
|
+
|
6392
|
+
for (i = 0; i < sourceKeys.length; i++) {
|
6393
|
+
key = sourceKeys[i];
|
6394
|
+
if (excluded.indexOf(key) >= 0) continue;
|
6395
|
+
target[key] = source[key];
|
6396
|
+
}
|
6397
|
+
|
6398
|
+
return target;
|
6399
|
+
}
|
6400
|
+
|
6401
|
+
var props = ['bottom', 'height', 'left', 'right', 'top', 'width'];
|
6390
6402
|
|
6391
6403
|
var rectChanged = function rectChanged(a, b) {
|
6392
6404
|
if (a === void 0) {
|
@@ -6456,383 +6468,355 @@ function observeRect(node, cb) {
|
|
6456
6468
|
};
|
6457
6469
|
}
|
6458
6470
|
|
6459
|
-
|
6460
|
-
let deps = [];
|
6461
|
-
let result;
|
6462
|
-
return () => {
|
6463
|
-
let depTime;
|
6464
|
-
if (opts.key && opts.debug != null && opts.debug()) depTime = Date.now();
|
6465
|
-
const newDeps = getDeps();
|
6466
|
-
const depsChanged = newDeps.length !== deps.length || newDeps.some((dep, index) => deps[index] !== dep);
|
6471
|
+
var useIsomorphicLayoutEffect$1 = typeof window !== 'undefined' ? React__default.useLayoutEffect : React__default.useEffect;
|
6467
6472
|
|
6468
|
-
|
6469
|
-
|
6470
|
-
|
6471
|
-
|
6472
|
-
|
6473
|
-
|
6474
|
-
|
6475
|
-
result = fn(...newDeps);
|
6476
|
-
opts == null ? void 0 : opts.onChange == null ? void 0 : opts.onChange(result);
|
6473
|
+
function useRect(nodeRef, initialRect) {
|
6474
|
+
if (initialRect === void 0) {
|
6475
|
+
initialRect = {
|
6476
|
+
width: 0,
|
6477
|
+
height: 0
|
6478
|
+
};
|
6479
|
+
}
|
6477
6480
|
|
6478
|
-
|
6479
|
-
|
6480
|
-
|
6481
|
-
const resultFpsPercentage = resultEndTime / 16;
|
6481
|
+
var _React$useState = React__default.useState(nodeRef.current),
|
6482
|
+
element = _React$useState[0],
|
6483
|
+
setElement = _React$useState[1];
|
6482
6484
|
|
6483
|
-
|
6484
|
-
|
6485
|
+
var _React$useReducer = React__default.useReducer(rectReducer, initialRect),
|
6486
|
+
rect = _React$useReducer[0],
|
6487
|
+
dispatch = _React$useReducer[1];
|
6485
6488
|
|
6486
|
-
|
6487
|
-
|
6488
|
-
|
6489
|
+
var initialRectSet = React__default.useRef(false);
|
6490
|
+
useIsomorphicLayoutEffect$1(function () {
|
6491
|
+
if (nodeRef.current !== element) {
|
6492
|
+
setElement(nodeRef.current);
|
6493
|
+
}
|
6494
|
+
});
|
6495
|
+
useIsomorphicLayoutEffect$1(function () {
|
6496
|
+
if (element && !initialRectSet.current) {
|
6497
|
+
initialRectSet.current = true;
|
6489
6498
|
|
6490
|
-
|
6491
|
-
};
|
6499
|
+
var _rect = element.getBoundingClientRect();
|
6492
6500
|
|
6493
|
-
|
6501
|
+
dispatch({
|
6502
|
+
rect: _rect
|
6503
|
+
});
|
6504
|
+
}
|
6505
|
+
}, [element]);
|
6506
|
+
React__default.useEffect(function () {
|
6507
|
+
if (!element) {
|
6508
|
+
return;
|
6494
6509
|
}
|
6495
6510
|
|
6496
|
-
|
6497
|
-
|
6511
|
+
var observer = observeRect(element, function (rect) {
|
6512
|
+
dispatch({
|
6513
|
+
rect: rect
|
6514
|
+
});
|
6515
|
+
});
|
6516
|
+
observer.observe();
|
6517
|
+
return function () {
|
6518
|
+
observer.unobserve();
|
6519
|
+
};
|
6520
|
+
}, [element]);
|
6521
|
+
return rect;
|
6498
6522
|
}
|
6499
6523
|
|
6500
|
-
|
6501
|
-
|
6502
|
-
const defaultRangeExtractor = range => {
|
6503
|
-
const start = Math.max(range.startIndex - range.overscan, 0);
|
6504
|
-
const end = Math.min(range.endIndex + range.overscan, range.count - 1);
|
6505
|
-
const arr = [];
|
6524
|
+
function rectReducer(state, action) {
|
6525
|
+
var rect = action.rect;
|
6506
6526
|
|
6507
|
-
|
6508
|
-
|
6527
|
+
if (state.height !== rect.height || state.width !== rect.width) {
|
6528
|
+
return rect;
|
6509
6529
|
}
|
6510
6530
|
|
6511
|
-
return
|
6531
|
+
return state;
|
6532
|
+
}
|
6533
|
+
|
6534
|
+
var defaultEstimateSize = function defaultEstimateSize() {
|
6535
|
+
return 50;
|
6512
6536
|
};
|
6513
|
-
const observeElementRect = (instance, cb) => {
|
6514
|
-
const observer = observeRect(instance.scrollElement, rect => {
|
6515
|
-
cb(rect);
|
6516
|
-
});
|
6517
6537
|
|
6518
|
-
|
6519
|
-
|
6520
|
-
|
6538
|
+
var defaultKeyExtractor = function defaultKeyExtractor(index) {
|
6539
|
+
return index;
|
6540
|
+
};
|
6521
6541
|
|
6522
|
-
|
6523
|
-
|
6524
|
-
return
|
6525
|
-
observer.unobserve();
|
6526
|
-
};
|
6542
|
+
var defaultMeasureSize = function defaultMeasureSize(el, horizontal) {
|
6543
|
+
var key = horizontal ? 'offsetWidth' : 'offsetHeight';
|
6544
|
+
return el[key];
|
6527
6545
|
};
|
6528
|
-
const observeElementOffset = (instance, cb) => {
|
6529
|
-
const onScroll = () => cb(instance.scrollElement[instance.options.horizontal ? 'scrollLeft' : 'scrollTop']);
|
6530
6546
|
|
6531
|
-
|
6532
|
-
|
6547
|
+
var defaultRangeExtractor = function defaultRangeExtractor(range) {
|
6548
|
+
var start = Math.max(range.start - range.overscan, 0);
|
6549
|
+
var end = Math.min(range.end + range.overscan, range.size - 1);
|
6550
|
+
var arr = [];
|
6551
|
+
|
6552
|
+
for (var i = start; i <= end; i++) {
|
6553
|
+
arr.push(i);
|
6533
6554
|
}
|
6534
6555
|
|
6535
|
-
|
6536
|
-
instance.scrollElement.addEventListener('scroll', onScroll, {
|
6537
|
-
capture: false,
|
6538
|
-
passive: true
|
6539
|
-
});
|
6540
|
-
return () => {
|
6541
|
-
instance.scrollElement.removeEventListener('scroll', onScroll);
|
6542
|
-
};
|
6543
|
-
};
|
6544
|
-
const measureElement = (element, instance) => {
|
6545
|
-
return element.getBoundingClientRect()[instance.options.horizontal ? 'width' : 'height'];
|
6556
|
+
return arr;
|
6546
6557
|
};
|
6547
|
-
|
6548
|
-
var
|
6549
|
-
|
6550
|
-
|
6551
|
-
|
6558
|
+
function useVirtual(_ref) {
|
6559
|
+
var _measurements;
|
6560
|
+
|
6561
|
+
var _ref$size = _ref.size,
|
6562
|
+
size = _ref$size === void 0 ? 0 : _ref$size,
|
6563
|
+
_ref$estimateSize = _ref.estimateSize,
|
6564
|
+
estimateSize = _ref$estimateSize === void 0 ? defaultEstimateSize : _ref$estimateSize,
|
6565
|
+
_ref$overscan = _ref.overscan,
|
6566
|
+
overscan = _ref$overscan === void 0 ? 1 : _ref$overscan,
|
6567
|
+
_ref$paddingStart = _ref.paddingStart,
|
6568
|
+
paddingStart = _ref$paddingStart === void 0 ? 0 : _ref$paddingStart,
|
6569
|
+
_ref$paddingEnd = _ref.paddingEnd,
|
6570
|
+
paddingEnd = _ref$paddingEnd === void 0 ? 0 : _ref$paddingEnd,
|
6571
|
+
parentRef = _ref.parentRef,
|
6572
|
+
horizontal = _ref.horizontal,
|
6573
|
+
scrollToFn = _ref.scrollToFn,
|
6574
|
+
useObserver = _ref.useObserver,
|
6575
|
+
initialRect = _ref.initialRect,
|
6576
|
+
onScrollElement = _ref.onScrollElement,
|
6577
|
+
scrollOffsetFn = _ref.scrollOffsetFn,
|
6578
|
+
_ref$keyExtractor = _ref.keyExtractor,
|
6579
|
+
keyExtractor = _ref$keyExtractor === void 0 ? defaultKeyExtractor : _ref$keyExtractor,
|
6580
|
+
_ref$measureSize = _ref.measureSize,
|
6581
|
+
measureSize = _ref$measureSize === void 0 ? defaultMeasureSize : _ref$measureSize,
|
6582
|
+
_ref$rangeExtractor = _ref.rangeExtractor,
|
6583
|
+
rangeExtractor = _ref$rangeExtractor === void 0 ? defaultRangeExtractor : _ref$rangeExtractor;
|
6584
|
+
var sizeKey = horizontal ? 'width' : 'height';
|
6585
|
+
var scrollKey = horizontal ? 'scrollLeft' : 'scrollTop';
|
6586
|
+
var latestRef = React__default.useRef({
|
6587
|
+
scrollOffset: 0,
|
6588
|
+
measurements: []
|
6552
6589
|
});
|
6553
|
-
};
|
6554
|
-
class Virtualizer {
|
6555
|
-
constructor(_opts) {
|
6556
|
-
var _this = this;
|
6557
|
-
|
6558
|
-
this.unsubs = [];
|
6559
|
-
this.scrollElement = null;
|
6560
|
-
this.measurementsCache = [];
|
6561
|
-
this.itemMeasurementsCache = {};
|
6562
|
-
this.pendingMeasuredCacheIndexes = [];
|
6563
|
-
|
6564
|
-
this.setOptions = opts => {
|
6565
|
-
Object.entries(opts).forEach(_ref => {
|
6566
|
-
let [key, value] = _ref;
|
6567
|
-
if (typeof value === 'undefined') delete opts[key];
|
6568
|
-
});
|
6569
|
-
this.options = {
|
6570
|
-
debug: false,
|
6571
|
-
initialOffset: 0,
|
6572
|
-
overscan: 1,
|
6573
|
-
paddingStart: 0,
|
6574
|
-
paddingEnd: 0,
|
6575
|
-
scrollPaddingStart: 0,
|
6576
|
-
scrollPaddingEnd: 0,
|
6577
|
-
horizontal: false,
|
6578
|
-
getItemKey: defaultKeyExtractor,
|
6579
|
-
rangeExtractor: defaultRangeExtractor,
|
6580
|
-
enableSmoothScroll: true,
|
6581
|
-
onChange: () => {},
|
6582
|
-
measureElement,
|
6583
|
-
initialRect: {
|
6584
|
-
width: 0,
|
6585
|
-
height: 0
|
6586
|
-
},
|
6587
|
-
...opts
|
6588
|
-
};
|
6589
|
-
};
|
6590
6590
|
|
6591
|
-
|
6592
|
-
|
6591
|
+
var _React$useState = React__default.useState(0),
|
6592
|
+
scrollOffset = _React$useState[0],
|
6593
|
+
setScrollOffset = _React$useState[1];
|
6593
6594
|
|
6594
|
-
|
6595
|
-
|
6595
|
+
latestRef.current.scrollOffset = scrollOffset;
|
6596
|
+
var useMeasureParent = useObserver || useRect;
|
6596
6597
|
|
6597
|
-
|
6598
|
-
|
6599
|
-
this.unsubs = [];
|
6600
|
-
};
|
6598
|
+
var _useMeasureParent = useMeasureParent(parentRef, initialRect),
|
6599
|
+
outerSize = _useMeasureParent[sizeKey];
|
6601
6600
|
|
6602
|
-
|
6603
|
-
|
6604
|
-
|
6605
|
-
|
6606
|
-
}
|
6601
|
+
latestRef.current.outerSize = outerSize;
|
6602
|
+
var defaultScrollToFn = React__default.useCallback(function (offset) {
|
6603
|
+
if (parentRef.current) {
|
6604
|
+
parentRef.current[scrollKey] = offset;
|
6605
|
+
}
|
6606
|
+
}, [parentRef, scrollKey]);
|
6607
|
+
var resolvedScrollToFn = scrollToFn || defaultScrollToFn;
|
6608
|
+
scrollToFn = React__default.useCallback(function (offset) {
|
6609
|
+
resolvedScrollToFn(offset, defaultScrollToFn);
|
6610
|
+
}, [defaultScrollToFn, resolvedScrollToFn]);
|
6607
6611
|
|
6608
|
-
|
6609
|
-
|
6610
|
-
|
6611
|
-
if (this.scrollElement !== scrollElement) {
|
6612
|
-
this.cleanup();
|
6613
|
-
this.scrollElement = scrollElement;
|
6614
|
-
this.unsubs.push(this.options.observeElementRect(this, rect => {
|
6615
|
-
this.scrollRect = rect;
|
6616
|
-
this.notify();
|
6617
|
-
}));
|
6618
|
-
this.unsubs.push(this.options.observeElementOffset(this, offset => {
|
6619
|
-
this.scrollOffset = offset;
|
6620
|
-
this.notify();
|
6621
|
-
}));
|
6622
|
-
}
|
6623
|
-
};
|
6612
|
+
var _React$useState2 = React__default.useState({}),
|
6613
|
+
measuredCache = _React$useState2[0],
|
6614
|
+
setMeasuredCache = _React$useState2[1];
|
6624
6615
|
|
6625
|
-
|
6626
|
-
|
6627
|
-
|
6628
|
-
|
6629
|
-
|
6630
|
-
|
6631
|
-
|
6632
|
-
|
6633
|
-
|
6634
|
-
for (let i = min; i < count; i++) {
|
6635
|
-
const key = getItemKey(i);
|
6636
|
-
const measuredSize = measurementsCache[key];
|
6637
|
-
const start = measurements[i - 1] ? measurements[i - 1].end : paddingStart;
|
6638
|
-
const size = typeof measuredSize === 'number' ? measuredSize : this.options.estimateSize(i);
|
6639
|
-
const end = start + size;
|
6640
|
-
measurements[i] = {
|
6641
|
-
index: i,
|
6642
|
-
start,
|
6643
|
-
size,
|
6644
|
-
end,
|
6645
|
-
key
|
6646
|
-
};
|
6647
|
-
}
|
6616
|
+
var measure = React__default.useCallback(function () {
|
6617
|
+
return setMeasuredCache({});
|
6618
|
+
}, []);
|
6619
|
+
var pendingMeasuredCacheIndexesRef = React__default.useRef([]);
|
6620
|
+
var measurements = React__default.useMemo(function () {
|
6621
|
+
var min = pendingMeasuredCacheIndexesRef.current.length > 0 ? Math.min.apply(Math, pendingMeasuredCacheIndexesRef.current) : 0;
|
6622
|
+
pendingMeasuredCacheIndexesRef.current = [];
|
6623
|
+
var measurements = latestRef.current.measurements.slice(0, min);
|
6648
6624
|
|
6649
|
-
|
6650
|
-
|
6651
|
-
|
6652
|
-
key: 'getMeasurements',
|
6653
|
-
debug: () => this.options.debug
|
6654
|
-
});
|
6655
|
-
this.calculateRange = memo(() => [this.getMeasurements(), this.getSize(), this.scrollOffset], (measurements, outerSize, scrollOffset) => {
|
6656
|
-
return calculateRange({
|
6657
|
-
measurements,
|
6658
|
-
outerSize,
|
6659
|
-
scrollOffset
|
6660
|
-
});
|
6661
|
-
}, {
|
6662
|
-
key: 'calculateRange',
|
6663
|
-
debug: () => this.options.debug
|
6664
|
-
});
|
6665
|
-
this.getIndexes = memo(() => [this.options.rangeExtractor, this.calculateRange(), this.options.overscan, this.options.count], (rangeExtractor, range, overscan, count) => {
|
6666
|
-
return rangeExtractor({ ...range,
|
6667
|
-
overscan,
|
6668
|
-
count: count
|
6669
|
-
});
|
6670
|
-
}, {
|
6671
|
-
key: 'getIndexes'
|
6672
|
-
});
|
6673
|
-
this.getVirtualItems = memo(() => [this.getIndexes(), this.getMeasurements(), this.options.measureElement], (indexes, measurements, measureElement) => {
|
6674
|
-
const virtualItems = [];
|
6675
|
-
|
6676
|
-
for (let k = 0, len = indexes.length; k < len; k++) {
|
6677
|
-
const i = indexes[k];
|
6678
|
-
const measurement = measurements[i];
|
6679
|
-
const item = { ...measurement,
|
6680
|
-
measureElement: measurableItem => {
|
6681
|
-
if (measurableItem) {
|
6682
|
-
const measuredItemSize = measureElement(measurableItem, this);
|
6683
|
-
|
6684
|
-
if (measuredItemSize !== item.size) {
|
6685
|
-
if (item.start < this.scrollOffset) {
|
6686
|
-
if ( this.options.debug) console.info('correction', measuredItemSize - item.size);
|
6687
|
-
|
6688
|
-
if (!this.destinationOffset) {
|
6689
|
-
this._scrollToOffset(this.scrollOffset + (measuredItemSize - item.size), false);
|
6690
|
-
}
|
6691
|
-
}
|
6625
|
+
for (var i = min; i < size; i++) {
|
6626
|
+
var key = keyExtractor(i);
|
6627
|
+
var measuredSize = measuredCache[key];
|
6692
6628
|
|
6693
|
-
|
6694
|
-
this.itemMeasurementsCache = { ...this.itemMeasurementsCache,
|
6695
|
-
[item.key]: measuredItemSize
|
6696
|
-
};
|
6697
|
-
this.notify();
|
6698
|
-
}
|
6699
|
-
}
|
6700
|
-
}
|
6701
|
-
};
|
6702
|
-
virtualItems.push(item);
|
6703
|
-
}
|
6629
|
+
var _start = measurements[i - 1] ? measurements[i - 1].end : paddingStart;
|
6704
6630
|
|
6705
|
-
|
6706
|
-
}, {
|
6707
|
-
key: 'getIndexes'
|
6708
|
-
});
|
6631
|
+
var _size = typeof measuredSize === 'number' ? measuredSize : estimateSize(i);
|
6709
6632
|
|
6710
|
-
|
6711
|
-
let {
|
6712
|
-
align
|
6713
|
-
} = _temp === void 0 ? {
|
6714
|
-
align: 'start'
|
6715
|
-
} : _temp;
|
6716
|
-
|
6717
|
-
const attempt = () => {
|
6718
|
-
const offset = _this.scrollOffset;
|
6719
|
-
|
6720
|
-
const size = _this.getSize();
|
6721
|
-
|
6722
|
-
if (align === 'auto') {
|
6723
|
-
if (toOffset <= offset) {
|
6724
|
-
align = 'start';
|
6725
|
-
} else if (toOffset >= offset + size) {
|
6726
|
-
align = 'end';
|
6727
|
-
} else {
|
6728
|
-
align = 'start';
|
6729
|
-
}
|
6730
|
-
}
|
6633
|
+
var _end = _start + _size;
|
6731
6634
|
|
6732
|
-
|
6733
|
-
|
6734
|
-
|
6735
|
-
|
6736
|
-
|
6737
|
-
|
6738
|
-
}
|
6635
|
+
measurements[i] = {
|
6636
|
+
index: i,
|
6637
|
+
start: _start,
|
6638
|
+
size: _size,
|
6639
|
+
end: _end,
|
6640
|
+
key: key
|
6739
6641
|
};
|
6642
|
+
}
|
6740
6643
|
|
6741
|
-
|
6742
|
-
|
6743
|
-
|
6744
|
-
|
6745
|
-
|
6746
|
-
|
6747
|
-
|
6748
|
-
|
6749
|
-
|
6750
|
-
|
6751
|
-
|
6752
|
-
|
6753
|
-
|
6754
|
-
|
6755
|
-
const measurements = _this.getMeasurements();
|
6756
|
-
|
6757
|
-
const offset = _this.scrollOffset;
|
6644
|
+
return measurements;
|
6645
|
+
}, [estimateSize, measuredCache, paddingStart, size, keyExtractor]);
|
6646
|
+
var totalSize = (((_measurements = measurements[size - 1]) == null ? void 0 : _measurements.end) || paddingStart) + paddingEnd;
|
6647
|
+
latestRef.current.measurements = measurements;
|
6648
|
+
latestRef.current.totalSize = totalSize;
|
6649
|
+
var element = onScrollElement ? onScrollElement.current : parentRef.current;
|
6650
|
+
var scrollOffsetFnRef = React__default.useRef(scrollOffsetFn);
|
6651
|
+
scrollOffsetFnRef.current = scrollOffsetFn;
|
6652
|
+
useIsomorphicLayoutEffect$1(function () {
|
6653
|
+
if (!element) {
|
6654
|
+
setScrollOffset(0);
|
6655
|
+
return;
|
6656
|
+
}
|
6758
6657
|
|
6759
|
-
|
6658
|
+
var onScroll = function onScroll(event) {
|
6659
|
+
var offset = scrollOffsetFnRef.current ? scrollOffsetFnRef.current(event) : element[scrollKey];
|
6660
|
+
setScrollOffset(offset);
|
6661
|
+
};
|
6760
6662
|
|
6761
|
-
|
6762
|
-
|
6763
|
-
|
6764
|
-
|
6663
|
+
onScroll();
|
6664
|
+
element.addEventListener('scroll', onScroll, {
|
6665
|
+
capture: false,
|
6666
|
+
passive: true
|
6667
|
+
});
|
6668
|
+
return function () {
|
6669
|
+
element.removeEventListener('scroll', onScroll);
|
6670
|
+
};
|
6671
|
+
}, [element, scrollKey]);
|
6672
|
+
|
6673
|
+
var _calculateRange = calculateRange(latestRef.current),
|
6674
|
+
start = _calculateRange.start,
|
6675
|
+
end = _calculateRange.end;
|
6676
|
+
|
6677
|
+
var indexes = React__default.useMemo(function () {
|
6678
|
+
return rangeExtractor({
|
6679
|
+
start: start,
|
6680
|
+
end: end,
|
6681
|
+
overscan: overscan,
|
6682
|
+
size: measurements.length
|
6683
|
+
});
|
6684
|
+
}, [start, end, overscan, measurements.length, rangeExtractor]);
|
6685
|
+
var measureSizeRef = React__default.useRef(measureSize);
|
6686
|
+
measureSizeRef.current = measureSize;
|
6687
|
+
var virtualItems = React__default.useMemo(function () {
|
6688
|
+
var virtualItems = [];
|
6689
|
+
|
6690
|
+
var _loop = function _loop(k, len) {
|
6691
|
+
var i = indexes[k];
|
6692
|
+
var measurement = measurements[i];
|
6693
|
+
|
6694
|
+
var item = _extends$1(_extends$1({}, measurement), {}, {
|
6695
|
+
measureRef: function measureRef(el) {
|
6696
|
+
if (el) {
|
6697
|
+
var measuredSize = measureSizeRef.current(el, horizontal);
|
6698
|
+
|
6699
|
+
if (measuredSize !== item.size) {
|
6700
|
+
var _scrollOffset = latestRef.current.scrollOffset;
|
6701
|
+
|
6702
|
+
if (item.start < _scrollOffset) {
|
6703
|
+
defaultScrollToFn(_scrollOffset + (measuredSize - item.size));
|
6704
|
+
}
|
6765
6705
|
|
6766
|
-
|
6767
|
-
|
6768
|
-
|
6706
|
+
pendingMeasuredCacheIndexesRef.current.push(i);
|
6707
|
+
setMeasuredCache(function (old) {
|
6708
|
+
var _extends2;
|
6769
6709
|
|
6770
|
-
|
6771
|
-
|
6772
|
-
|
6773
|
-
|
6774
|
-
align = 'start';
|
6775
|
-
} else {
|
6776
|
-
return;
|
6710
|
+
return _extends$1(_extends$1({}, old), {}, (_extends2 = {}, _extends2[item.key] = measuredSize, _extends2));
|
6711
|
+
});
|
6712
|
+
}
|
6713
|
+
}
|
6777
6714
|
}
|
6778
|
-
}
|
6779
|
-
|
6780
|
-
const toOffset = align === 'end' ? measurement.end + _this.options.scrollPaddingEnd : measurement.start - _this.options.scrollPaddingStart;
|
6781
|
-
|
6782
|
-
_this.scrollToOffset(toOffset, {
|
6783
|
-
align,
|
6784
|
-
...rest
|
6785
6715
|
});
|
6716
|
+
|
6717
|
+
virtualItems.push(item);
|
6786
6718
|
};
|
6787
6719
|
|
6788
|
-
|
6789
|
-
|
6720
|
+
for (var k = 0, len = indexes.length; k < len; k++) {
|
6721
|
+
_loop(k);
|
6722
|
+
}
|
6790
6723
|
|
6791
|
-
|
6792
|
-
|
6724
|
+
return virtualItems;
|
6725
|
+
}, [indexes, defaultScrollToFn, horizontal, measurements]);
|
6726
|
+
var mountedRef = React__default.useRef(false);
|
6727
|
+
useIsomorphicLayoutEffect$1(function () {
|
6728
|
+
if (mountedRef.current) {
|
6729
|
+
setMeasuredCache({});
|
6730
|
+
}
|
6793
6731
|
|
6794
|
-
|
6795
|
-
|
6796
|
-
|
6797
|
-
|
6798
|
-
|
6732
|
+
mountedRef.current = true;
|
6733
|
+
}, [estimateSize]);
|
6734
|
+
var scrollToOffset = React__default.useCallback(function (toOffset, _temp) {
|
6735
|
+
var _ref2 = _temp === void 0 ? {} : _temp,
|
6736
|
+
_ref2$align = _ref2.align,
|
6737
|
+
align = _ref2$align === void 0 ? 'start' : _ref2$align;
|
6799
6738
|
|
6800
|
-
|
6801
|
-
|
6802
|
-
|
6803
|
-
if (this.scrollCheckFrame !== scrollCheckFrame) {
|
6804
|
-
return;
|
6805
|
-
}
|
6739
|
+
var _latestRef$current = latestRef.current,
|
6740
|
+
scrollOffset = _latestRef$current.scrollOffset,
|
6741
|
+
outerSize = _latestRef$current.outerSize;
|
6806
6742
|
|
6807
|
-
|
6808
|
-
|
6809
|
-
|
6810
|
-
|
6743
|
+
if (align === 'auto') {
|
6744
|
+
if (toOffset <= scrollOffset) {
|
6745
|
+
align = 'start';
|
6746
|
+
} else if (toOffset >= scrollOffset + outerSize) {
|
6747
|
+
align = 'end';
|
6748
|
+
} else {
|
6749
|
+
align = 'start';
|
6750
|
+
}
|
6751
|
+
}
|
6811
6752
|
|
6812
|
-
|
6813
|
-
|
6814
|
-
|
6815
|
-
|
6753
|
+
if (align === 'start') {
|
6754
|
+
scrollToFn(toOffset);
|
6755
|
+
} else if (align === 'end') {
|
6756
|
+
scrollToFn(toOffset - outerSize);
|
6757
|
+
} else if (align === 'center') {
|
6758
|
+
scrollToFn(toOffset - outerSize / 2);
|
6759
|
+
}
|
6760
|
+
}, [scrollToFn]);
|
6761
|
+
var tryScrollToIndex = React__default.useCallback(function (index, _temp2) {
|
6762
|
+
var _ref3 = _temp2 === void 0 ? {} : _temp2,
|
6763
|
+
_ref3$align = _ref3.align,
|
6764
|
+
align = _ref3$align === void 0 ? 'auto' : _ref3$align,
|
6765
|
+
rest = _objectWithoutPropertiesLoose$2(_ref3, ["align"]);
|
6816
6766
|
|
6817
|
-
|
6818
|
-
|
6767
|
+
var _latestRef$current2 = latestRef.current,
|
6768
|
+
measurements = _latestRef$current2.measurements,
|
6769
|
+
scrollOffset = _latestRef$current2.scrollOffset,
|
6770
|
+
outerSize = _latestRef$current2.outerSize;
|
6771
|
+
var measurement = measurements[Math.max(0, Math.min(index, size - 1))];
|
6819
6772
|
|
6820
|
-
|
6821
|
-
|
6822
|
-
|
6823
|
-
};
|
6773
|
+
if (!measurement) {
|
6774
|
+
return;
|
6775
|
+
}
|
6824
6776
|
|
6825
|
-
|
6826
|
-
|
6827
|
-
|
6828
|
-
|
6777
|
+
if (align === 'auto') {
|
6778
|
+
if (measurement.end >= scrollOffset + outerSize) {
|
6779
|
+
align = 'end';
|
6780
|
+
} else if (measurement.start <= scrollOffset) {
|
6781
|
+
align = 'start';
|
6782
|
+
} else {
|
6783
|
+
return;
|
6784
|
+
}
|
6785
|
+
}
|
6829
6786
|
|
6787
|
+
var toOffset = align === 'center' ? measurement.start + measurement.size / 2 : align === 'end' ? measurement.end : measurement.start;
|
6788
|
+
scrollToOffset(toOffset, _extends$1({
|
6789
|
+
align: align
|
6790
|
+
}, rest));
|
6791
|
+
}, [scrollToOffset, size]);
|
6792
|
+
var scrollToIndex = React__default.useCallback(function () {
|
6793
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
6794
|
+
args[_key] = arguments[_key];
|
6795
|
+
}
|
6796
|
+
|
6797
|
+
// We do a double request here because of
|
6798
|
+
// dynamic sizes which can cause offset shift
|
6799
|
+
// and end up in the wrong spot. Unfortunately,
|
6800
|
+
// we can't know about those dynamic sizes until
|
6801
|
+
// we try and render them. So double down!
|
6802
|
+
tryScrollToIndex.apply(void 0, args);
|
6803
|
+
requestAnimationFrame(function () {
|
6804
|
+
tryScrollToIndex.apply(void 0, args);
|
6805
|
+
});
|
6806
|
+
}, [tryScrollToIndex]);
|
6807
|
+
return {
|
6808
|
+
virtualItems: virtualItems,
|
6809
|
+
totalSize: totalSize,
|
6810
|
+
scrollToOffset: scrollToOffset,
|
6811
|
+
scrollToIndex: scrollToIndex,
|
6812
|
+
measure: measure
|
6813
|
+
};
|
6830
6814
|
}
|
6831
6815
|
|
6832
|
-
|
6816
|
+
var findNearestBinarySearch = function findNearestBinarySearch(low, high, getCurrentValue, value) {
|
6833
6817
|
while (low <= high) {
|
6834
|
-
|
6835
|
-
|
6818
|
+
var middle = (low + high) / 2 | 0;
|
6819
|
+
var currentValue = getCurrentValue(middle);
|
6836
6820
|
|
6837
6821
|
if (currentValue < value) {
|
6838
6822
|
low = middle + 1;
|
@@ -6850,57 +6834,27 @@ const findNearestBinarySearch = (low, high, getCurrentValue, value) => {
|
|
6850
6834
|
}
|
6851
6835
|
};
|
6852
6836
|
|
6853
|
-
function calculateRange(
|
6854
|
-
|
6855
|
-
|
6856
|
-
|
6857
|
-
|
6858
|
-
} = _ref2;
|
6859
|
-
const count = measurements.length - 1;
|
6837
|
+
function calculateRange(_ref4) {
|
6838
|
+
var measurements = _ref4.measurements,
|
6839
|
+
outerSize = _ref4.outerSize,
|
6840
|
+
scrollOffset = _ref4.scrollOffset;
|
6841
|
+
var size = measurements.length - 1;
|
6860
6842
|
|
6861
|
-
|
6843
|
+
var getOffset = function getOffset(index) {
|
6844
|
+
return measurements[index].start;
|
6845
|
+
};
|
6862
6846
|
|
6863
|
-
|
6864
|
-
|
6847
|
+
var start = findNearestBinarySearch(0, size, getOffset, scrollOffset);
|
6848
|
+
var end = start;
|
6865
6849
|
|
6866
|
-
while (
|
6867
|
-
|
6850
|
+
while (end < size && measurements[end].end < scrollOffset + outerSize) {
|
6851
|
+
end++;
|
6868
6852
|
}
|
6869
6853
|
|
6870
6854
|
return {
|
6871
|
-
|
6872
|
-
|
6873
|
-
};
|
6874
|
-
}
|
6875
|
-
|
6876
|
-
const useIsomorphicLayoutEffect$1 = typeof window !== 'undefined' ? React.useLayoutEffect : React.useEffect;
|
6877
|
-
|
6878
|
-
function useVirtualizerBase(options) {
|
6879
|
-
const rerender = React.useReducer(() => ({}), {})[1];
|
6880
|
-
const resolvedOptions = { ...options,
|
6881
|
-
onChange: instance => {
|
6882
|
-
rerender();
|
6883
|
-
options.onChange == null ? void 0 : options.onChange(instance);
|
6884
|
-
}
|
6855
|
+
start: start,
|
6856
|
+
end: end
|
6885
6857
|
};
|
6886
|
-
const [instance] = React.useState(() => new Virtualizer(resolvedOptions));
|
6887
|
-
instance.setOptions(resolvedOptions);
|
6888
|
-
React.useEffect(() => {
|
6889
|
-
return instance._didMount();
|
6890
|
-
}, []);
|
6891
|
-
useIsomorphicLayoutEffect$1(() => {
|
6892
|
-
return instance._willUpdate();
|
6893
|
-
});
|
6894
|
-
return instance;
|
6895
|
-
}
|
6896
|
-
|
6897
|
-
function useVirtualizer(options) {
|
6898
|
-
return useVirtualizerBase({
|
6899
|
-
observeElementRect: observeElementRect,
|
6900
|
-
observeElementOffset: observeElementOffset,
|
6901
|
-
scrollToFn: elementScroll,
|
6902
|
-
...options
|
6903
|
-
});
|
6904
6858
|
}
|
6905
6859
|
|
6906
6860
|
var MRT_EditCellTextField = function MRT_EditCellTextField(_ref) {
|
@@ -7308,23 +7262,19 @@ var MRT_TableBody = function MRT_TableBody(_ref) {
|
|
7308
7262
|
|
7309
7263
|
return enablePagination ? getRowModel().rows : getPrePaginationRowModel().rows;
|
7310
7264
|
}, [enableGlobalFilterRankedResults, enableGlobalFilterRankedResults && globalFilter || !enablePagination ? getPrePaginationRowModel().rows : getRowModel().rows, globalFilter]);
|
7311
|
-
var rowVirtualizer = enableRowVirtualization ?
|
7312
|
-
|
7313
|
-
|
7314
|
-
|
7315
|
-
|
7316
|
-
getScrollElement: function getScrollElement() {
|
7317
|
-
return tableContainerRef.current;
|
7318
|
-
},
|
7319
|
-
overscan: density === 'compact' ? 30 : 10
|
7265
|
+
var rowVirtualizer = enableRowVirtualization ? useVirtual(_extends({
|
7266
|
+
// estimateSize: () => (density === 'compact' ? 25 : 50),
|
7267
|
+
overscan: density === 'compact' ? 30 : 10,
|
7268
|
+
parentRef: tableContainerRef,
|
7269
|
+
size: rows.length
|
7320
7270
|
}, virtualizerProps)) : {};
|
7321
|
-
var virtualRows = enableRowVirtualization ? rowVirtualizer.
|
7271
|
+
var virtualRows = enableRowVirtualization ? rowVirtualizer.virtualItems : [];
|
7322
7272
|
var paddingTop = 0;
|
7323
7273
|
var paddingBottom = 0;
|
7324
7274
|
|
7325
7275
|
if (enableRowVirtualization) {
|
7326
7276
|
paddingTop = virtualRows.length > 0 ? virtualRows[0].start : 0;
|
7327
|
-
paddingBottom = virtualRows.length > 0 ? rowVirtualizer.
|
7277
|
+
paddingBottom = virtualRows.length > 0 ? rowVirtualizer.totalSize - virtualRows[virtualRows.length - 1].end : 0;
|
7328
7278
|
}
|
7329
7279
|
|
7330
7280
|
return React__default.createElement(material.TableBody, Object.assign({}, tableBodyProps), enableRowVirtualization && paddingTop > 0 && React__default.createElement("tr", null, React__default.createElement("td", {
|