material-react-table 1.4.0-beta.1 → 1.4.0-beta.2

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/cjs/index.js CHANGED
@@ -71,7 +71,6 @@ var TableHead = require('@mui/material/TableHead');
71
71
  var TableRow = require('@mui/material/TableRow');
72
72
  var TableCell = require('@mui/material/TableCell');
73
73
  var TableSortLabel = require('@mui/material/TableSortLabel');
74
- var reactVirtual = require('react-virtual');
75
74
  var TableBody = require('@mui/material/TableBody');
76
75
  var Skeleton = require('@mui/material/Skeleton');
77
76
  var TableFooter = require('@mui/material/TableFooter');
@@ -82,7 +81,26 @@ var Stack = require('@mui/material/Stack');
82
81
 
83
82
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
84
83
 
84
+ function _interopNamespace(e) {
85
+ if (e && e.__esModule) return e;
86
+ var n = Object.create(null);
87
+ if (e) {
88
+ Object.keys(e).forEach(function (k) {
89
+ if (k !== 'default') {
90
+ var d = Object.getOwnPropertyDescriptor(e, k);
91
+ Object.defineProperty(n, k, d.get ? d : {
92
+ enumerable: true,
93
+ get: function () { return e[k]; }
94
+ });
95
+ }
96
+ });
97
+ }
98
+ n["default"] = e;
99
+ return Object.freeze(n);
100
+ }
101
+
85
102
  var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
103
+ var React__namespace = /*#__PURE__*/_interopNamespace(React);
86
104
  var ArrowDownwardIcon__default = /*#__PURE__*/_interopDefaultLegacy(ArrowDownwardIcon);
87
105
  var ArrowRightIcon__default = /*#__PURE__*/_interopDefaultLegacy(ArrowRightIcon);
88
106
  var CancelIcon__default = /*#__PURE__*/_interopDefaultLegacy(CancelIcon);
@@ -2064,6 +2082,569 @@ const MRT_TableHead = ({ table }) => {
2064
2082
  : tableHeadProps === null || tableHeadProps === void 0 ? void 0 : tableHeadProps.sx))) }), getHeaderGroups().map((headerGroup) => (React__default["default"].createElement(MRT_TableHeadRow, { headerGroup: headerGroup, key: headerGroup.id, table: table })))));
2065
2083
  };
2066
2084
 
2085
+ /**
2086
+ * virtual-core
2087
+ *
2088
+ * Copyright (c) TanStack
2089
+ *
2090
+ * This source code is licensed under the MIT license found in the
2091
+ * LICENSE.md file in the root directory of this source tree.
2092
+ *
2093
+ * @license MIT
2094
+ */
2095
+ function memo(getDeps, fn, opts) {
2096
+ let deps = [];
2097
+ let result;
2098
+ return () => {
2099
+ let depTime;
2100
+ if (opts.key && opts.debug != null && opts.debug()) depTime = Date.now();
2101
+ const newDeps = getDeps();
2102
+ const depsChanged = newDeps.length !== deps.length || newDeps.some((dep, index) => deps[index] !== dep);
2103
+ if (!depsChanged) {
2104
+ return result;
2105
+ }
2106
+ deps = newDeps;
2107
+ let resultTime;
2108
+ if (opts.key && opts.debug != null && opts.debug()) resultTime = Date.now();
2109
+ result = fn(...newDeps);
2110
+ opts == null ? void 0 : opts.onChange == null ? void 0 : opts.onChange(result);
2111
+ if (opts.key && opts.debug != null && opts.debug()) {
2112
+ const depEndTime = Math.round((Date.now() - depTime) * 100) / 100;
2113
+ const resultEndTime = Math.round((Date.now() - resultTime) * 100) / 100;
2114
+ const resultFpsPercentage = resultEndTime / 16;
2115
+ const pad = (str, num) => {
2116
+ str = String(str);
2117
+ while (str.length < num) {
2118
+ str = ' ' + str;
2119
+ }
2120
+ return str;
2121
+ };
2122
+ console.info(`%c⏱ ${pad(resultEndTime, 5)} /${pad(depEndTime, 5)} ms`, `
2123
+ font-size: .6rem;
2124
+ font-weight: bold;
2125
+ color: hsl(${Math.max(0, Math.min(120 - 120 * resultFpsPercentage, 120))}deg 100% 31%);`, opts == null ? void 0 : opts.key);
2126
+ }
2127
+ return result;
2128
+ };
2129
+ }
2130
+
2131
+ /**
2132
+ * virtual-core
2133
+ *
2134
+ * Copyright (c) TanStack
2135
+ *
2136
+ * This source code is licensed under the MIT license found in the
2137
+ * LICENSE.md file in the root directory of this source tree.
2138
+ *
2139
+ * @license MIT
2140
+ */
2141
+
2142
+ //
2143
+
2144
+ //
2145
+
2146
+ const defaultKeyExtractor = index => index;
2147
+ const defaultRangeExtractor = range => {
2148
+ const start = Math.max(range.startIndex - range.overscan, 0);
2149
+ const end = Math.min(range.endIndex + range.overscan, range.count - 1);
2150
+ const arr = [];
2151
+ for (let i = start; i <= end; i++) {
2152
+ arr.push(i);
2153
+ }
2154
+ return arr;
2155
+ };
2156
+ const observeElementRect = (instance, cb) => {
2157
+ const observer = new ResizeObserver(entries => {
2158
+ var _entries$, _entries$2;
2159
+ cb({
2160
+ width: (_entries$ = entries[0]) == null ? void 0 : _entries$.contentRect.width,
2161
+ height: (_entries$2 = entries[0]) == null ? void 0 : _entries$2.contentRect.height
2162
+ });
2163
+ });
2164
+ if (!instance.scrollElement) {
2165
+ return;
2166
+ }
2167
+ cb(instance.scrollElement.getBoundingClientRect());
2168
+ observer.observe(instance.scrollElement);
2169
+ return () => {
2170
+ observer.unobserve(instance.scrollElement);
2171
+ };
2172
+ };
2173
+ const scrollProps = {
2174
+ element: ['scrollLeft', 'scrollTop'],
2175
+ window: ['scrollX', 'scrollY']
2176
+ };
2177
+ const createOffsetObserver = mode => {
2178
+ return (instance, cb) => {
2179
+ if (!instance.scrollElement) {
2180
+ return;
2181
+ }
2182
+ const propX = scrollProps[mode][0];
2183
+ const propY = scrollProps[mode][1];
2184
+ let prevX = instance.scrollElement[propX];
2185
+ let prevY = instance.scrollElement[propY];
2186
+ const scroll = () => {
2187
+ const offset = instance.scrollElement[instance.options.horizontal ? propX : propY];
2188
+ cb(Math.max(0, offset - instance.options.scrollMargin));
2189
+ };
2190
+ scroll();
2191
+ const onScroll = e => {
2192
+ const target = e.currentTarget;
2193
+ const scrollX = target[propX];
2194
+ const scrollY = target[propY];
2195
+ if (instance.options.horizontal ? prevX - scrollX : prevY - scrollY) {
2196
+ scroll();
2197
+ }
2198
+ prevX = scrollX;
2199
+ prevY = scrollY;
2200
+ };
2201
+ instance.scrollElement.addEventListener('scroll', onScroll, {
2202
+ capture: false,
2203
+ passive: true
2204
+ });
2205
+ return () => {
2206
+ instance.scrollElement.removeEventListener('scroll', onScroll);
2207
+ };
2208
+ };
2209
+ };
2210
+ const observeElementOffset = createOffsetObserver('element');
2211
+ const measureElement = (element, instance) => {
2212
+ return Math.round(element.getBoundingClientRect()[instance.options.horizontal ? 'width' : 'height']);
2213
+ };
2214
+ const elementScroll = (offset, _ref2, instance) => {
2215
+ var _instance$scrollEleme2;
2216
+ let {
2217
+ adjustments,
2218
+ behavior,
2219
+ sync
2220
+ } = _ref2;
2221
+ const toOffset = (sync ? offset : offset + instance.options.scrollMargin) + (adjustments ?? 0);
2222
+ (_instance$scrollEleme2 = instance.scrollElement) == null ? void 0 : _instance$scrollEleme2.scrollTo == null ? void 0 : _instance$scrollEleme2.scrollTo({
2223
+ [instance.options.horizontal ? 'left' : 'top']: toOffset,
2224
+ behavior
2225
+ });
2226
+ };
2227
+ class Virtualizer {
2228
+ constructor(_opts) {
2229
+ var _this = this;
2230
+ this.unsubs = [];
2231
+ this.scrollElement = null;
2232
+ this.isScrolling = false;
2233
+ this.isScrollingTimeoutId = null;
2234
+ this.measurementsCache = [];
2235
+ this.itemMeasurementsCache = {};
2236
+ this.pendingMeasuredCacheIndexes = [];
2237
+ this.scrollAdjustments = 0;
2238
+ this.measureElementCache = {};
2239
+ this.pendingScrollToIndexCallback = null;
2240
+ this.getResizeObserver = (() => {
2241
+ let _ro = null;
2242
+ return () => {
2243
+ if (_ro) {
2244
+ return _ro;
2245
+ } else if (typeof ResizeObserver !== 'undefined') {
2246
+ return _ro = new ResizeObserver(entries => {
2247
+ entries.forEach(entry => {
2248
+ this._measureElement(entry.target, false);
2249
+ });
2250
+ });
2251
+ } else {
2252
+ return null;
2253
+ }
2254
+ };
2255
+ })();
2256
+ this.range = {
2257
+ startIndex: 0,
2258
+ endIndex: 0
2259
+ };
2260
+ this.setOptions = opts => {
2261
+ Object.entries(opts).forEach(_ref3 => {
2262
+ let [key, value] = _ref3;
2263
+ if (typeof value === 'undefined') delete opts[key];
2264
+ });
2265
+ this.options = {
2266
+ debug: false,
2267
+ initialOffset: 0,
2268
+ overscan: 1,
2269
+ paddingStart: 0,
2270
+ paddingEnd: 0,
2271
+ scrollPaddingStart: 0,
2272
+ scrollPaddingEnd: 0,
2273
+ horizontal: false,
2274
+ getItemKey: defaultKeyExtractor,
2275
+ rangeExtractor: defaultRangeExtractor,
2276
+ onChange: () => {},
2277
+ measureElement,
2278
+ initialRect: {
2279
+ width: 0,
2280
+ height: 0
2281
+ },
2282
+ scrollMargin: 0,
2283
+ scrollingDelay: 150,
2284
+ indexAttribute: 'data-index',
2285
+ ...opts
2286
+ };
2287
+ };
2288
+ this.notify = () => {
2289
+ var _this$options$onChang, _this$options;
2290
+ (_this$options$onChang = (_this$options = this.options).onChange) == null ? void 0 : _this$options$onChang.call(_this$options, this);
2291
+ };
2292
+ this.cleanup = () => {
2293
+ this.unsubs.filter(Boolean).forEach(d => d());
2294
+ this.unsubs = [];
2295
+ this.scrollElement = null;
2296
+ };
2297
+ this._didMount = () => {
2298
+ const ro = this.getResizeObserver();
2299
+ Object.values(this.measureElementCache).forEach(node => ro == null ? void 0 : ro.observe(node));
2300
+ return () => {
2301
+ ro == null ? void 0 : ro.disconnect();
2302
+ this.cleanup();
2303
+ };
2304
+ };
2305
+ this._willUpdate = () => {
2306
+ var _this$pendingScrollTo;
2307
+ (_this$pendingScrollTo = this.pendingScrollToIndexCallback) == null ? void 0 : _this$pendingScrollTo.call(this);
2308
+ const scrollElement = this.options.getScrollElement();
2309
+ if (this.scrollElement !== scrollElement) {
2310
+ this.cleanup();
2311
+ this.scrollElement = scrollElement;
2312
+ this._scrollToOffset(this.scrollOffset, {
2313
+ adjustments: undefined,
2314
+ behavior: undefined,
2315
+ sync: true
2316
+ });
2317
+ this.unsubs.push(this.options.observeElementRect(this, rect => {
2318
+ this.scrollRect = rect;
2319
+ this.calculateRange();
2320
+ }));
2321
+ this.unsubs.push(this.options.observeElementOffset(this, offset => {
2322
+ if (this.isScrollingTimeoutId !== null) {
2323
+ clearTimeout(this.isScrollingTimeoutId);
2324
+ this.isScrollingTimeoutId = null;
2325
+ }
2326
+ if (this.scrollOffset !== offset) {
2327
+ this.scrollOffset = offset;
2328
+ this.isScrolling = true;
2329
+ this.scrollAdjustments = 0;
2330
+ this.isScrollingTimeoutId = setTimeout(() => {
2331
+ this.isScrollingTimeoutId = null;
2332
+ this.isScrolling = false;
2333
+ this.notify();
2334
+ }, this.options.scrollingDelay);
2335
+ } else {
2336
+ this.isScrolling = false;
2337
+ this.scrollAdjustments = 0;
2338
+ }
2339
+ this.calculateRange();
2340
+ }));
2341
+ } else if (!this.isScrolling) {
2342
+ this.calculateRange();
2343
+ }
2344
+ };
2345
+ this.getSize = () => {
2346
+ return this.scrollRect[this.options.horizontal ? 'width' : 'height'];
2347
+ };
2348
+ this.getMeasurements = memo(() => [this.options.count, this.options.paddingStart, this.options.getItemKey, this.itemMeasurementsCache], (count, paddingStart, getItemKey, measurementsCache) => {
2349
+ const min = this.pendingMeasuredCacheIndexes.length > 0 ? Math.min(...this.pendingMeasuredCacheIndexes) : 0;
2350
+ this.pendingMeasuredCacheIndexes = [];
2351
+ const measurements = this.measurementsCache.slice(0, min);
2352
+ for (let i = min; i < count; i++) {
2353
+ const key = getItemKey(i);
2354
+ const measuredSize = measurementsCache[key];
2355
+ const start = measurements[i - 1] ? measurements[i - 1].end : paddingStart;
2356
+ const size = typeof measuredSize === 'number' ? measuredSize : this.options.estimateSize(i);
2357
+ const end = start + size;
2358
+ measurements[i] = {
2359
+ index: i,
2360
+ start,
2361
+ size,
2362
+ end,
2363
+ key
2364
+ };
2365
+ }
2366
+ this.measurementsCache = measurements;
2367
+ return measurements;
2368
+ }, {
2369
+ key: process.env.NODE_ENV !== 'production' && 'getMeasurements',
2370
+ debug: () => this.options.debug
2371
+ });
2372
+ this.calculateRange = memo(() => [this.getMeasurements(), this.getSize(), this.scrollOffset], (measurements, outerSize, scrollOffset) => {
2373
+ const range = calculateRange({
2374
+ measurements,
2375
+ outerSize,
2376
+ scrollOffset
2377
+ });
2378
+ if (range.startIndex !== this.range.startIndex || range.endIndex !== this.range.endIndex) {
2379
+ this.range = range;
2380
+ this.notify();
2381
+ }
2382
+ return this.range;
2383
+ }, {
2384
+ key: process.env.NODE_ENV !== 'production' && 'calculateRange',
2385
+ debug: () => this.options.debug
2386
+ });
2387
+ this.getIndexes = memo(() => [this.options.rangeExtractor, this.range, this.options.overscan, this.options.count], (rangeExtractor, range, overscan, count) => {
2388
+ return rangeExtractor({
2389
+ ...range,
2390
+ overscan,
2391
+ count: count
2392
+ });
2393
+ }, {
2394
+ key: process.env.NODE_ENV !== 'production' && 'getIndexes',
2395
+ debug: () => this.options.debug
2396
+ });
2397
+ this.indexFromElement = node => {
2398
+ const attributeName = this.options.indexAttribute;
2399
+ const indexStr = node.getAttribute(attributeName);
2400
+ if (!indexStr) {
2401
+ console.warn(`Missing attribute name '${attributeName}={index}' on measured element.`);
2402
+ return -1;
2403
+ }
2404
+ return parseInt(indexStr, 10);
2405
+ };
2406
+ this._measureElement = (node, _sync) => {
2407
+ const index = this.indexFromElement(node);
2408
+ const item = this.measurementsCache[index];
2409
+ if (!item) {
2410
+ return;
2411
+ }
2412
+ const prevNode = this.measureElementCache[item.key];
2413
+ const ro = this.getResizeObserver();
2414
+ if (!node.isConnected) {
2415
+ if (prevNode) {
2416
+ ro == null ? void 0 : ro.unobserve(prevNode);
2417
+ delete this.measureElementCache[item.key];
2418
+ }
2419
+ return;
2420
+ }
2421
+ if (!prevNode || prevNode !== node) {
2422
+ if (prevNode) {
2423
+ ro == null ? void 0 : ro.unobserve(prevNode);
2424
+ }
2425
+ this.measureElementCache[item.key] = node;
2426
+ ro == null ? void 0 : ro.observe(node);
2427
+ }
2428
+ const measuredItemSize = this.options.measureElement(node, this);
2429
+ const itemSize = this.itemMeasurementsCache[item.key] ?? item.size;
2430
+ const delta = measuredItemSize - itemSize;
2431
+ if (delta !== 0) {
2432
+ if (item.start < this.scrollOffset && this.isScrolling) {
2433
+ if (process.env.NODE_ENV !== 'production' && this.options.debug) {
2434
+ console.info('correction', delta);
2435
+ }
2436
+ this._scrollToOffset(this.scrollOffset, {
2437
+ adjustments: this.scrollAdjustments += delta,
2438
+ behavior: undefined,
2439
+ sync: false
2440
+ });
2441
+ }
2442
+ this.pendingMeasuredCacheIndexes.push(index);
2443
+ this.itemMeasurementsCache = {
2444
+ ...this.itemMeasurementsCache,
2445
+ [item.key]: measuredItemSize
2446
+ };
2447
+ this.notify();
2448
+ }
2449
+ };
2450
+ this.measureElement = node => {
2451
+ if (!node) {
2452
+ return;
2453
+ }
2454
+ this._measureElement(node, true);
2455
+ };
2456
+ this.getVirtualItems = memo(() => [this.getIndexes(), this.getMeasurements()], (indexes, measurements) => {
2457
+ const virtualItems = [];
2458
+ for (let k = 0, len = indexes.length; k < len; k++) {
2459
+ const i = indexes[k];
2460
+ const measurement = measurements[i];
2461
+ virtualItems.push(measurement);
2462
+ }
2463
+ return virtualItems;
2464
+ }, {
2465
+ key: process.env.NODE_ENV !== 'production' && 'getIndexes',
2466
+ debug: () => this.options.debug
2467
+ });
2468
+ this.scrollToOffset = function (toOffset, _temp) {
2469
+ let {
2470
+ align = 'start',
2471
+ behavior
2472
+ } = _temp === void 0 ? {} : _temp;
2473
+ const offset = _this.scrollOffset;
2474
+ const size = _this.getSize();
2475
+ if (align === 'auto') {
2476
+ if (toOffset <= offset) {
2477
+ align = 'start';
2478
+ } else if (toOffset >= offset + size) {
2479
+ align = 'end';
2480
+ } else {
2481
+ align = 'start';
2482
+ }
2483
+ }
2484
+ const options = {
2485
+ adjustments: undefined,
2486
+ behavior,
2487
+ sync: false
2488
+ };
2489
+ if (align === 'start') {
2490
+ _this._scrollToOffset(toOffset, options);
2491
+ } else if (align === 'end') {
2492
+ _this._scrollToOffset(toOffset - size, options);
2493
+ } else if (align === 'center') {
2494
+ _this._scrollToOffset(toOffset - size / 2, options);
2495
+ }
2496
+ };
2497
+ this.scrollToIndex = function (index, _temp2) {
2498
+ let {
2499
+ align = 'auto',
2500
+ ...rest
2501
+ } = _temp2 === void 0 ? {} : _temp2;
2502
+ _this.pendingScrollToIndexCallback = null;
2503
+ const measurements = _this.getMeasurements();
2504
+ const offset = _this.scrollOffset;
2505
+ const size = _this.getSize();
2506
+ const {
2507
+ count
2508
+ } = _this.options;
2509
+ const measurement = measurements[Math.max(0, Math.min(index, count - 1))];
2510
+ if (!measurement) {
2511
+ return;
2512
+ }
2513
+ if (align === 'auto') {
2514
+ if (measurement.end >= offset + size - _this.options.scrollPaddingEnd) {
2515
+ align = 'end';
2516
+ } else if (measurement.start <= offset + _this.options.scrollPaddingStart) {
2517
+ align = 'start';
2518
+ } else {
2519
+ return;
2520
+ }
2521
+ }
2522
+ const toOffset = align === 'end' ? measurement.end + _this.options.scrollPaddingEnd : measurement.start - _this.options.scrollPaddingStart;
2523
+ _this.scrollToOffset(toOffset, {
2524
+ align,
2525
+ ...rest
2526
+ });
2527
+ const isDynamic = Object.keys(_this.measureElementCache).length > 0;
2528
+ if (isDynamic) {
2529
+ const didSeen = () => typeof _this.itemMeasurementsCache[_this.options.getItemKey(index)] === 'number';
2530
+ if (!didSeen()) {
2531
+ _this.pendingScrollToIndexCallback = () => {
2532
+ if (didSeen()) {
2533
+ _this.pendingScrollToIndexCallback = null;
2534
+ _this.scrollToIndex(index, {
2535
+ align,
2536
+ ...rest
2537
+ });
2538
+ }
2539
+ };
2540
+ }
2541
+ }
2542
+ };
2543
+ this.getTotalSize = () => {
2544
+ var _this$getMeasurements;
2545
+ return (((_this$getMeasurements = this.getMeasurements()[this.options.count - 1]) == null ? void 0 : _this$getMeasurements.end) || this.options.paddingStart) + this.options.paddingEnd;
2546
+ };
2547
+ this._scrollToOffset = (offset, _ref4) => {
2548
+ let {
2549
+ adjustments,
2550
+ behavior,
2551
+ sync
2552
+ } = _ref4;
2553
+ this.options.scrollToFn(offset, {
2554
+ behavior,
2555
+ sync,
2556
+ adjustments
2557
+ }, this);
2558
+ };
2559
+ this.measure = () => {
2560
+ this.itemMeasurementsCache = {};
2561
+ this.notify();
2562
+ };
2563
+ this.setOptions(_opts);
2564
+ this.scrollRect = this.options.initialRect;
2565
+ this.scrollOffset = this.options.initialOffset;
2566
+ this.calculateRange();
2567
+ }
2568
+ }
2569
+ const findNearestBinarySearch = (low, high, getCurrentValue, value) => {
2570
+ while (low <= high) {
2571
+ const middle = (low + high) / 2 | 0;
2572
+ const currentValue = getCurrentValue(middle);
2573
+ if (currentValue < value) {
2574
+ low = middle + 1;
2575
+ } else if (currentValue > value) {
2576
+ high = middle - 1;
2577
+ } else {
2578
+ return middle;
2579
+ }
2580
+ }
2581
+ if (low > 0) {
2582
+ return low - 1;
2583
+ } else {
2584
+ return 0;
2585
+ }
2586
+ };
2587
+ function calculateRange(_ref5) {
2588
+ let {
2589
+ measurements,
2590
+ outerSize,
2591
+ scrollOffset
2592
+ } = _ref5;
2593
+ const count = measurements.length - 1;
2594
+ const getOffset = index => measurements[index].start;
2595
+ const startIndex = findNearestBinarySearch(0, count, getOffset, scrollOffset);
2596
+ let endIndex = startIndex;
2597
+ while (endIndex < count && measurements[endIndex].end < scrollOffset + outerSize) {
2598
+ endIndex++;
2599
+ }
2600
+ return {
2601
+ startIndex,
2602
+ endIndex
2603
+ };
2604
+ }
2605
+
2606
+ /**
2607
+ * react-virtual
2608
+ *
2609
+ * Copyright (c) TanStack
2610
+ *
2611
+ * This source code is licensed under the MIT license found in the
2612
+ * LICENSE.md file in the root directory of this source tree.
2613
+ *
2614
+ * @license MIT
2615
+ */
2616
+
2617
+ //
2618
+
2619
+ const useIsomorphicLayoutEffect$1 = typeof window !== 'undefined' ? React__namespace.useLayoutEffect : React__namespace.useEffect;
2620
+ function useVirtualizerBase(options) {
2621
+ const rerender = React__namespace.useReducer(() => ({}), {})[1];
2622
+ const resolvedOptions = {
2623
+ ...options,
2624
+ onChange: instance => {
2625
+ rerender();
2626
+ options.onChange == null ? void 0 : options.onChange(instance);
2627
+ }
2628
+ };
2629
+ const [instance] = React__namespace.useState(() => new Virtualizer(resolvedOptions));
2630
+ instance.setOptions(resolvedOptions);
2631
+ React__namespace.useEffect(() => {
2632
+ return instance._didMount();
2633
+ }, []);
2634
+ useIsomorphicLayoutEffect$1(() => {
2635
+ return instance._willUpdate();
2636
+ });
2637
+ return instance;
2638
+ }
2639
+ function useVirtualizer(options) {
2640
+ return useVirtualizerBase({
2641
+ observeElementRect: observeElementRect,
2642
+ observeElementOffset: observeElementOffset,
2643
+ scrollToFn: elementScroll,
2644
+ ...options
2645
+ });
2646
+ }
2647
+
2067
2648
  const MRT_EditCellTextField = ({ cell, showLabel, table, }) => {
2068
2649
  var _a;
2069
2650
  const { getState, options: { muiTableBodyCellEditTextFieldProps }, refs: { editInputRefs }, setEditingCell, setEditingRow, } = table;
@@ -2331,7 +2912,7 @@ const MRT_TableDetailPanel = ({ row, table }) => {
2331
2912
  : tableCellProps === null || tableCellProps === void 0 ? void 0 : tableCellProps.sx))) }), renderDetailPanel && (React__default["default"].createElement(Collapse__default["default"], { in: row.getIsExpanded(), mountOnEnter: true, unmountOnExit: true }, !isLoading && renderDetailPanel({ row, table }))))));
2332
2913
  };
2333
2914
 
2334
- const MRT_TableBodyRow = ({ numRows, row, rowIndex, table, virtualRow, }) => {
2915
+ const MRT_TableBodyRow = ({ measureElement, numRows, row, rowIndex, table, virtualRow, }) => {
2335
2916
  const theme = styles.useTheme();
2336
2917
  const { getIsSomeColumnsPinned, getState, options: { enableRowOrdering, layoutMode, memoMode, muiTableBodyRowProps, renderDetailPanel, }, setHoveredRow, } = table;
2337
2918
  const { draggingColumn, draggingRow, editingCell, editingRow, hoveredRow } = getState();
@@ -2355,12 +2936,14 @@ const MRT_TableBodyRow = ({ numRows, row, rowIndex, table, virtualRow, }) => {
2355
2936
  }
2356
2937
  : undefined;
2357
2938
  return (React__default["default"].createElement(React__default["default"].Fragment, null,
2358
- React__default["default"].createElement(TableRow__default["default"], Object.assign({ hover: true, onDragEnter: handleDragEnter, selected: row.getIsSelected(), ref: (node) => {
2359
- rowRef.current = node;
2360
- if (virtualRow === null || virtualRow === void 0 ? void 0 : virtualRow.measureRef) {
2361
- virtualRow.measureRef = node;
2939
+ React__default["default"].createElement(TableRow__default["default"], Object.assign({ "data-index": virtualRow === null || virtualRow === void 0 ? void 0 : virtualRow.index, hover: true, onDragEnter: handleDragEnter, selected: row.getIsSelected(), ref: (node) => {
2940
+ if (node) {
2941
+ rowRef.current = node;
2942
+ measureElement === null || measureElement === void 0 ? void 0 : measureElement(node);
2362
2943
  }
2363
- } }, tableRowProps, { sx: (theme) => (Object.assign(Object.assign({ backgroundColor: styles.lighten(theme.palette.background.default, 0.06), display: layoutMode === 'grid' ? 'flex' : 'table-row', opacity: (draggingRow === null || draggingRow === void 0 ? void 0 : draggingRow.id) === row.id || (hoveredRow === null || hoveredRow === void 0 ? void 0 : hoveredRow.id) === row.id ? 0.5 : 1, transition: 'all 150ms ease-in-out', '&:hover td': {
2944
+ } }, tableRowProps, { sx: (theme) => (Object.assign(Object.assign({ backgroundColor: styles.lighten(theme.palette.background.default, 0.06), display: layoutMode === 'grid' ? 'flex' : 'table-row', opacity: (draggingRow === null || draggingRow === void 0 ? void 0 : draggingRow.id) === row.id || (hoveredRow === null || hoveredRow === void 0 ? void 0 : hoveredRow.id) === row.id ? 0.5 : 1, position: virtualRow ? 'absolute' : undefined, top: virtualRow ? 0 : undefined, transform: virtualRow
2945
+ ? `translateY(${virtualRow === null || virtualRow === void 0 ? void 0 : virtualRow.start}px)`
2946
+ : undefined, transition: virtualRow ? 'none' : 'all 150ms ease-in-out', '&:hover td': {
2364
2947
  backgroundColor: (tableRowProps === null || tableRowProps === void 0 ? void 0 : tableRowProps.hover) !== false && getIsSomeColumnsPinned()
2365
2948
  ? theme.palette.mode === 'dark'
2366
2949
  ? `${styles.lighten(theme.palette.background.default, 0.12)}`
@@ -2392,7 +2975,7 @@ const Memo_MRT_TableBodyRow = React.memo(MRT_TableBodyRow, (prev, next) => prev.
2392
2975
  const MRT_TableBody = ({ table }) => {
2393
2976
  var _a, _b, _c;
2394
2977
  const { getRowModel, getPrePaginationRowModel, getState, options: { enableGlobalFilterRankedResults, enablePagination, enableRowVirtualization, layoutMode, localization, manualFiltering, manualSorting, memoMode, muiTableBodyProps, virtualizerInstanceRef, virtualizerProps, }, refs: { tableContainerRef, tablePaperRef }, } = table;
2395
- const { columnFilters, globalFilter, pagination, sorting } = getState();
2978
+ const { columnFilters, density, globalFilter, pagination, sorting } = getState();
2396
2979
  const tableBodyProps = muiTableBodyProps instanceof Function
2397
2980
  ? muiTableBodyProps({ table })
2398
2981
  : muiTableBodyProps;
@@ -2425,39 +3008,13 @@ const MRT_TableBody = ({ table }) => {
2425
3008
  pagination.pageSize,
2426
3009
  ]);
2427
3010
  const virtualizer = enableRowVirtualization
2428
- ? reactVirtual.useVirtual(Object.assign({ size: rows.length, parentRef: tableContainerRef, overscan: 15 }, vProps))
2429
- : {};
2430
- if (virtualizerInstanceRef) {
3011
+ ? useVirtualizer(Object.assign({ count: rows.length, estimateSize: () => density === 'compact' ? 37 : density === 'comfortable' ? 58 : 73, getScrollElement: () => tableContainerRef.current, measureElement: (element) => element === null || element === void 0 ? void 0 : element.getBoundingClientRect().height, overscan: 10 }, vProps))
3012
+ : undefined;
3013
+ if (virtualizerInstanceRef && virtualizer) {
2431
3014
  virtualizerInstanceRef.current = virtualizer;
2432
3015
  }
2433
- // const virtualizer: Virtualizer = enableRowVirtualization
2434
- // ? useVirtualizer({
2435
- // count: rows.length,
2436
- // estimateSize: () => (density === 'compact' ? 25 : 50),
2437
- // getScrollElement: () => tableContainerRef.current as HTMLDivElement,
2438
- // overscan: 15,
2439
- // ...vProps,
2440
- // })
2441
- // : ({} as any);
2442
- const virtualRows = enableRowVirtualization ? virtualizer.virtualItems : [];
2443
- // const virtualRows = enableRowVirtualization
2444
- // ? virtualizer.getVirtualItems()
2445
- // : [];
2446
- let paddingTop = 0;
2447
- let paddingBottom = 0;
2448
- if (enableRowVirtualization) {
2449
- paddingTop = virtualRows.length ? virtualRows[0].start : 0;
2450
- paddingBottom = virtualRows.length
2451
- ? virtualizer.totalSize - virtualRows[virtualRows.length - 1].end
2452
- : 0;
2453
- }
2454
- // if (enableRowVirtualization) {
2455
- // paddingTop = !!virtualRows.length ? virtualRows[0].start : 0;
2456
- // paddingBottom = !!virtualRows.length
2457
- // ? virtualizer.getTotalSize() - virtualRows[virtualRows.length - 1].end
2458
- // : 0;
2459
- // }
2460
- return (React__default["default"].createElement(TableBody__default["default"], Object.assign({}, tableBodyProps, { sx: (theme) => (Object.assign({ display: layoutMode === 'grid' ? 'grid' : 'table-row-group' }, ((tableBodyProps === null || tableBodyProps === void 0 ? void 0 : tableBodyProps.sx) instanceof Function
3016
+ const virtualRows = virtualizer ? virtualizer.getVirtualItems() : undefined;
3017
+ return (React__default["default"].createElement(TableBody__default["default"], Object.assign({}, tableBodyProps, { sx: (theme) => (Object.assign({ display: layoutMode === 'grid' ? 'grid' : 'table-row-group', height: virtualizer ? `${virtualizer.getTotalSize()}px` : 'inherit', position: 'relative' }, ((tableBodyProps === null || tableBodyProps === void 0 ? void 0 : tableBodyProps.sx) instanceof Function
2461
3018
  ? tableBodyProps === null || tableBodyProps === void 0 ? void 0 : tableBodyProps.sx(theme)
2462
3019
  : tableBodyProps === null || tableBodyProps === void 0 ? void 0 : tableBodyProps.sx))) }), ((_a = tableBodyProps === null || tableBodyProps === void 0 ? void 0 : tableBodyProps.children) !== null && _a !== void 0 ? _a : !rows.length) ? (React__default["default"].createElement("tr", { style: { display: layoutMode === 'grid' ? 'grid' : 'table-row' } },
2463
3020
  React__default["default"].createElement("td", { colSpan: table.getVisibleLeafColumns().length, style: { display: layoutMode === 'grid' ? 'grid' : 'table-cell' } },
@@ -2470,27 +3027,25 @@ const MRT_TableBody = ({ table }) => {
2470
3027
  width: '100%',
2471
3028
  } }, globalFilter || columnFilters.length
2472
3029
  ? localization.noResultsFound
2473
- : localization.noRecordsToDisplay)))) : (React__default["default"].createElement(React__default["default"].Fragment, null,
2474
- enableRowVirtualization && paddingTop > 0 && (React__default["default"].createElement("tr", null,
2475
- React__default["default"].createElement("td", { style: { height: `${paddingTop}px` } }))),
2476
- (enableRowVirtualization ? virtualRows : rows).map((rowOrVirtualRow, rowIndex) => {
2477
- const row = enableRowVirtualization
2478
- ? rows[rowOrVirtualRow.index]
2479
- : rowOrVirtualRow;
2480
- const props = {
2481
- key: row.id,
2482
- numRows: rows.length,
2483
- row,
2484
- rowIndex: enableRowVirtualization
2485
- ? rowOrVirtualRow.index
2486
- : rowIndex,
2487
- table,
2488
- virtualRow: enableRowVirtualization ? rowOrVirtualRow : null,
2489
- };
2490
- return memoMode === 'rows' ? (React__default["default"].createElement(Memo_MRT_TableBodyRow, Object.assign({}, props))) : (React__default["default"].createElement(MRT_TableBodyRow, Object.assign({}, props)));
2491
- }),
2492
- enableRowVirtualization && paddingBottom > 0 && (React__default["default"].createElement("tr", null,
2493
- React__default["default"].createElement("td", { style: { height: `${paddingBottom}px` } })))))));
3030
+ : localization.noRecordsToDisplay)))) : (React__default["default"].createElement(React__default["default"].Fragment, null, (virtualRows !== null && virtualRows !== void 0 ? virtualRows : rows).map((rowOrVirtualRow, rowIndex) => {
3031
+ const row = virtualizer
3032
+ ? rows[rowOrVirtualRow.index]
3033
+ : rowOrVirtualRow;
3034
+ const props = {
3035
+ key: row.id,
3036
+ measureElement: virtualizer
3037
+ ? virtualizer.measureElement
3038
+ : undefined,
3039
+ numRows: rows.length,
3040
+ row,
3041
+ rowIndex: virtualizer ? rowOrVirtualRow.index : rowIndex,
3042
+ table,
3043
+ virtualRow: virtualizer
3044
+ ? rowOrVirtualRow
3045
+ : undefined,
3046
+ };
3047
+ return memoMode === 'rows' ? (React__default["default"].createElement(Memo_MRT_TableBodyRow, Object.assign({}, props))) : (React__default["default"].createElement(MRT_TableBodyRow, Object.assign({}, props)));
3048
+ })))));
2494
3049
  };
2495
3050
  const Memo_MRT_TableBody = React.memo(MRT_TableBody, (prev, next) => prev.table.options.data === next.table.options.data);
2496
3051
 
@@ -2588,11 +3143,13 @@ const MRT_TableContainer = ({ table }) => {
2588
3143
  : 0;
2589
3144
  setTotalToolbarHeight(topToolbarHeight + bottomToolbarHeight);
2590
3145
  });
2591
- return (React__default["default"].createElement(TableContainer__default["default"], Object.assign({}, tableContainerProps, { ref: (ref) => {
2592
- tableContainerRef.current = ref;
2593
- if (tableContainerProps === null || tableContainerProps === void 0 ? void 0 : tableContainerProps.ref) {
2594
- //@ts-ignore
2595
- tableContainerProps.ref.current = ref;
3146
+ return (React__default["default"].createElement(TableContainer__default["default"], Object.assign({}, tableContainerProps, { ref: (node) => {
3147
+ if (node) {
3148
+ tableContainerRef.current = node;
3149
+ if (tableContainerProps === null || tableContainerProps === void 0 ? void 0 : tableContainerProps.ref) {
3150
+ //@ts-ignore
3151
+ tableContainerProps.ref.current = node;
3152
+ }
2596
3153
  }
2597
3154
  }, sx: (theme) => (Object.assign({ maxWidth: '100%', maxHeight: enableStickyHeader || enableRowVirtualization
2598
3155
  ? `clamp(350px, calc(100vh - ${totalToolbarHeight}px), 9999px)`
@@ -2920,6 +3477,8 @@ const MaterialReactTable = (_a) => {
2920
3477
  const _sortingFns = React.useMemo(() => (Object.assign(Object.assign({}, MRT_SortingFns), sortingFns)), []);
2921
3478
  const _defaultColumn = React.useMemo(() => (Object.assign(Object.assign({}, MRT_DefaultColumn), defaultColumn)), []);
2922
3479
  const _defaultDisplayColumn = React.useMemo(() => (Object.assign(Object.assign({}, MRT_DefaultDisplayColumn), defaultDisplayColumn)), []);
3480
+ if (rest.enableRowVirtualization)
3481
+ layoutMode = 'grid';
2923
3482
  return (React__default["default"].createElement(MRT_TableRoot, Object.assign({ aggregationFns: _aggregationFns, autoResetExpanded: autoResetExpanded, columnResizeMode: columnResizeMode, defaultColumn: _defaultColumn, defaultDisplayColumn: _defaultDisplayColumn, editingMode: editingMode, enableBottomToolbar: enableBottomToolbar, enableColumnActions: enableColumnActions, enableColumnFilters: enableColumnFilters, enableColumnOrdering: enableColumnOrdering, enableColumnResizing: enableColumnResizing, enableDensityToggle: enableDensityToggle, enableExpandAll: enableExpandAll, enableFilters: enableFilters, enableFullScreenToggle: enableFullScreenToggle, enableGlobalFilter: enableGlobalFilter, enableGlobalFilterRankedResults: enableGlobalFilterRankedResults, enableGrouping: enableGrouping, enableHiding: enableHiding, enableMultiRowSelection: enableMultiRowSelection, enableMultiSort: enableMultiSort, enablePagination: enablePagination, enablePinning: enablePinning, enableRowSelection: enableRowSelection, enableSelectAll: enableSelectAll, enableSorting: enableSorting, enableStickyHeader: enableStickyHeader, enableTableFooter: enableTableFooter, enableTableHead: enableTableHead, enableToolbarInternalActions: enableToolbarInternalActions, enableTopToolbar: enableTopToolbar, filterFns: _filterFns, icons: _icons, layoutMode: layoutMode, localization: _localization, positionActionsColumn: positionActionsColumn, positionExpandColumn: positionExpandColumn, positionGlobalFilter: positionGlobalFilter, positionPagination: positionPagination, positionToolbarAlertBanner: positionToolbarAlertBanner, positionToolbarDropZone: positionToolbarDropZone, rowNumberMode: rowNumberMode, selectAllMode: selectAllMode, sortingFns: _sortingFns }, rest)));
2924
3483
  };
2925
3484