@trackunit/react-table 0.0.73 → 0.0.74

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.esm.js CHANGED
@@ -1,11 +1,12 @@
1
1
  import { jsxs, jsx } from 'react/jsx-runtime';
2
2
  import { registerTranslations, useNamespaceTranslation } from '@trackunit/i18n-library-translation';
3
- import { useContainerProps, IconButton, Icon, Text, MoreMenu, MenuList, Button, Card, EmptyState, Tooltip, Popover, PopoverTrigger, PopoverContent } from '@trackunit/react-components';
3
+ import { useContainerProps, IconButton, Icon, Text, MoreMenu, MenuList, Button, Card, EmptyState, Spinner, Tooltip, Popover, PopoverTrigger, PopoverContent } from '@trackunit/react-components';
4
4
  import * as React from 'react';
5
- import React__default, { useState, useEffect, useCallback, useRef, createContext, memo as memo$1, isValidElement, cloneElement, useLayoutEffect, useMemo, useContext } from 'react';
5
+ import { useState, useEffect, useCallback, useRef, createContext, memo as memo$2, isValidElement, cloneElement, useLayoutEffect, useMemo, useContext } from 'react';
6
6
  import { Link } from 'react-router-dom';
7
7
  import { cvaMerge } from '@trackunit/css-class-variance-utilities';
8
8
  import { TableRoot, Thead, Tr, Th, SortIndicator, ResizeHandle, Tbody, Td } from '@trackunit/react-table-base-components';
9
+ import { flushSync } from 'react-dom';
9
10
  import { Toggle, RadioGroup, RadioItem } from '@trackunit/react-form-components';
10
11
  import { SortOrder, validateStringAsAssetSortByProperty } from '@trackunit/react-core-contexts-api';
11
12
 
@@ -204,7 +205,7 @@ function flattenBy(arr, getChildren) {
204
205
  recurse(arr);
205
206
  return flat;
206
207
  }
207
- function memo(getDeps, fn, opts) {
208
+ function memo$1(getDeps, fn, opts) {
208
209
  let deps = [];
209
210
  let result;
210
211
  return () => {
@@ -285,7 +286,7 @@ function createColumn(table, columnDef, depth, parent) {
285
286
  depth,
286
287
  columnDef: resolvedColumnDef,
287
288
  columns: [],
288
- getFlatColumns: memo(() => [true], () => {
289
+ getFlatColumns: memo$1(() => [true], () => {
289
290
  var _column$columns;
290
291
  return [column, ...((_column$columns = column.columns) == null ? void 0 : _column$columns.flatMap(d => d.getFlatColumns()))];
291
292
  }, {
@@ -295,7 +296,7 @@ function createColumn(table, columnDef, depth, parent) {
295
296
  return (_table$options$debugA = table.options.debugAll) != null ? _table$options$debugA : table.options.debugColumns;
296
297
  }
297
298
  }),
298
- getLeafColumns: memo(() => [table._getOrderColumnsFn()], orderColumns => {
299
+ getLeafColumns: memo$1(() => [table._getOrderColumnsFn()], orderColumns => {
299
300
  var _column$columns2;
300
301
  if ((_column$columns2 = column.columns) != null && _column$columns2.length) {
301
302
  let leafColumns = column.columns.flatMap(column => column.getLeafColumns());
@@ -361,7 +362,7 @@ const Headers = {
361
362
  return {
362
363
  // Header Groups
363
364
 
364
- getHeaderGroups: memo(() => [table.getAllColumns(), table.getVisibleLeafColumns(), table.getState().columnPinning.left, table.getState().columnPinning.right], (allColumns, leafColumns, left, right) => {
365
+ getHeaderGroups: memo$1(() => [table.getAllColumns(), table.getVisibleLeafColumns(), table.getState().columnPinning.left, table.getState().columnPinning.right], (allColumns, leafColumns, left, right) => {
365
366
  var _left$map$filter, _right$map$filter;
366
367
  const leftColumns = (_left$map$filter = left == null ? void 0 : left.map(columnId => leafColumns.find(d => d.id === columnId)).filter(Boolean)) != null ? _left$map$filter : [];
367
368
  const rightColumns = (_right$map$filter = right == null ? void 0 : right.map(columnId => leafColumns.find(d => d.id === columnId)).filter(Boolean)) != null ? _right$map$filter : [];
@@ -375,7 +376,7 @@ const Headers = {
375
376
  return (_table$options$debugA = table.options.debugAll) != null ? _table$options$debugA : table.options.debugHeaders;
376
377
  }
377
378
  }),
378
- getCenterHeaderGroups: memo(() => [table.getAllColumns(), table.getVisibleLeafColumns(), table.getState().columnPinning.left, table.getState().columnPinning.right], (allColumns, leafColumns, left, right) => {
379
+ getCenterHeaderGroups: memo$1(() => [table.getAllColumns(), table.getVisibleLeafColumns(), table.getState().columnPinning.left, table.getState().columnPinning.right], (allColumns, leafColumns, left, right) => {
379
380
  leafColumns = leafColumns.filter(column => !(left != null && left.includes(column.id)) && !(right != null && right.includes(column.id)));
380
381
  return buildHeaderGroups(allColumns, leafColumns, table, 'center');
381
382
  }, {
@@ -385,7 +386,7 @@ const Headers = {
385
386
  return (_table$options$debugA2 = table.options.debugAll) != null ? _table$options$debugA2 : table.options.debugHeaders;
386
387
  }
387
388
  }),
388
- getLeftHeaderGroups: memo(() => [table.getAllColumns(), table.getVisibleLeafColumns(), table.getState().columnPinning.left], (allColumns, leafColumns, left) => {
389
+ getLeftHeaderGroups: memo$1(() => [table.getAllColumns(), table.getVisibleLeafColumns(), table.getState().columnPinning.left], (allColumns, leafColumns, left) => {
389
390
  var _left$map$filter2;
390
391
  const orderedLeafColumns = (_left$map$filter2 = left == null ? void 0 : left.map(columnId => leafColumns.find(d => d.id === columnId)).filter(Boolean)) != null ? _left$map$filter2 : [];
391
392
  return buildHeaderGroups(allColumns, orderedLeafColumns, table, 'left');
@@ -396,7 +397,7 @@ const Headers = {
396
397
  return (_table$options$debugA3 = table.options.debugAll) != null ? _table$options$debugA3 : table.options.debugHeaders;
397
398
  }
398
399
  }),
399
- getRightHeaderGroups: memo(() => [table.getAllColumns(), table.getVisibleLeafColumns(), table.getState().columnPinning.right], (allColumns, leafColumns, right) => {
400
+ getRightHeaderGroups: memo$1(() => [table.getAllColumns(), table.getVisibleLeafColumns(), table.getState().columnPinning.right], (allColumns, leafColumns, right) => {
400
401
  var _right$map$filter2;
401
402
  const orderedLeafColumns = (_right$map$filter2 = right == null ? void 0 : right.map(columnId => leafColumns.find(d => d.id === columnId)).filter(Boolean)) != null ? _right$map$filter2 : [];
402
403
  return buildHeaderGroups(allColumns, orderedLeafColumns, table, 'right');
@@ -409,7 +410,7 @@ const Headers = {
409
410
  }),
410
411
  // Footer Groups
411
412
 
412
- getFooterGroups: memo(() => [table.getHeaderGroups()], headerGroups => {
413
+ getFooterGroups: memo$1(() => [table.getHeaderGroups()], headerGroups => {
413
414
  return [...headerGroups].reverse();
414
415
  }, {
415
416
  key: process.env.NODE_ENV === 'development' && 'getFooterGroups',
@@ -418,7 +419,7 @@ const Headers = {
418
419
  return (_table$options$debugA5 = table.options.debugAll) != null ? _table$options$debugA5 : table.options.debugHeaders;
419
420
  }
420
421
  }),
421
- getLeftFooterGroups: memo(() => [table.getLeftHeaderGroups()], headerGroups => {
422
+ getLeftFooterGroups: memo$1(() => [table.getLeftHeaderGroups()], headerGroups => {
422
423
  return [...headerGroups].reverse();
423
424
  }, {
424
425
  key: process.env.NODE_ENV === 'development' && 'getLeftFooterGroups',
@@ -427,7 +428,7 @@ const Headers = {
427
428
  return (_table$options$debugA6 = table.options.debugAll) != null ? _table$options$debugA6 : table.options.debugHeaders;
428
429
  }
429
430
  }),
430
- getCenterFooterGroups: memo(() => [table.getCenterHeaderGroups()], headerGroups => {
431
+ getCenterFooterGroups: memo$1(() => [table.getCenterHeaderGroups()], headerGroups => {
431
432
  return [...headerGroups].reverse();
432
433
  }, {
433
434
  key: process.env.NODE_ENV === 'development' && 'getCenterFooterGroups',
@@ -436,7 +437,7 @@ const Headers = {
436
437
  return (_table$options$debugA7 = table.options.debugAll) != null ? _table$options$debugA7 : table.options.debugHeaders;
437
438
  }
438
439
  }),
439
- getRightFooterGroups: memo(() => [table.getRightHeaderGroups()], headerGroups => {
440
+ getRightFooterGroups: memo$1(() => [table.getRightHeaderGroups()], headerGroups => {
440
441
  return [...headerGroups].reverse();
441
442
  }, {
442
443
  key: process.env.NODE_ENV === 'development' && 'getRightFooterGroups',
@@ -447,7 +448,7 @@ const Headers = {
447
448
  }),
448
449
  // Flat Headers
449
450
 
450
- getFlatHeaders: memo(() => [table.getHeaderGroups()], headerGroups => {
451
+ getFlatHeaders: memo$1(() => [table.getHeaderGroups()], headerGroups => {
451
452
  return headerGroups.map(headerGroup => {
452
453
  return headerGroup.headers;
453
454
  }).flat();
@@ -458,7 +459,7 @@ const Headers = {
458
459
  return (_table$options$debugA9 = table.options.debugAll) != null ? _table$options$debugA9 : table.options.debugHeaders;
459
460
  }
460
461
  }),
461
- getLeftFlatHeaders: memo(() => [table.getLeftHeaderGroups()], left => {
462
+ getLeftFlatHeaders: memo$1(() => [table.getLeftHeaderGroups()], left => {
462
463
  return left.map(headerGroup => {
463
464
  return headerGroup.headers;
464
465
  }).flat();
@@ -469,7 +470,7 @@ const Headers = {
469
470
  return (_table$options$debugA10 = table.options.debugAll) != null ? _table$options$debugA10 : table.options.debugHeaders;
470
471
  }
471
472
  }),
472
- getCenterFlatHeaders: memo(() => [table.getCenterHeaderGroups()], left => {
473
+ getCenterFlatHeaders: memo$1(() => [table.getCenterHeaderGroups()], left => {
473
474
  return left.map(headerGroup => {
474
475
  return headerGroup.headers;
475
476
  }).flat();
@@ -480,7 +481,7 @@ const Headers = {
480
481
  return (_table$options$debugA11 = table.options.debugAll) != null ? _table$options$debugA11 : table.options.debugHeaders;
481
482
  }
482
483
  }),
483
- getRightFlatHeaders: memo(() => [table.getRightHeaderGroups()], left => {
484
+ getRightFlatHeaders: memo$1(() => [table.getRightHeaderGroups()], left => {
484
485
  return left.map(headerGroup => {
485
486
  return headerGroup.headers;
486
487
  }).flat();
@@ -493,7 +494,7 @@ const Headers = {
493
494
  }),
494
495
  // Leaf Headers
495
496
 
496
- getCenterLeafHeaders: memo(() => [table.getCenterFlatHeaders()], flatHeaders => {
497
+ getCenterLeafHeaders: memo$1(() => [table.getCenterFlatHeaders()], flatHeaders => {
497
498
  return flatHeaders.filter(header => {
498
499
  var _header$subHeaders;
499
500
  return !((_header$subHeaders = header.subHeaders) != null && _header$subHeaders.length);
@@ -505,7 +506,7 @@ const Headers = {
505
506
  return (_table$options$debugA13 = table.options.debugAll) != null ? _table$options$debugA13 : table.options.debugHeaders;
506
507
  }
507
508
  }),
508
- getLeftLeafHeaders: memo(() => [table.getLeftFlatHeaders()], flatHeaders => {
509
+ getLeftLeafHeaders: memo$1(() => [table.getLeftFlatHeaders()], flatHeaders => {
509
510
  return flatHeaders.filter(header => {
510
511
  var _header$subHeaders2;
511
512
  return !((_header$subHeaders2 = header.subHeaders) != null && _header$subHeaders2.length);
@@ -517,7 +518,7 @@ const Headers = {
517
518
  return (_table$options$debugA14 = table.options.debugAll) != null ? _table$options$debugA14 : table.options.debugHeaders;
518
519
  }
519
520
  }),
520
- getRightLeafHeaders: memo(() => [table.getRightFlatHeaders()], flatHeaders => {
521
+ getRightLeafHeaders: memo$1(() => [table.getRightFlatHeaders()], flatHeaders => {
521
522
  return flatHeaders.filter(header => {
522
523
  var _header$subHeaders3;
523
524
  return !((_header$subHeaders3 = header.subHeaders) != null && _header$subHeaders3.length);
@@ -529,7 +530,7 @@ const Headers = {
529
530
  return (_table$options$debugA15 = table.options.debugAll) != null ? _table$options$debugA15 : table.options.debugHeaders;
530
531
  }
531
532
  }),
532
- getLeafHeaders: memo(() => [table.getLeftHeaderGroups(), table.getCenterHeaderGroups(), table.getRightHeaderGroups()], (left, center, right) => {
533
+ getLeafHeaders: memo$1(() => [table.getLeftHeaderGroups(), table.getCenterHeaderGroups(), table.getRightHeaderGroups()], (left, center, right) => {
533
534
  var _left$0$headers, _left$, _center$0$headers, _center$, _right$0$headers, _right$;
534
535
  return [...((_left$0$headers = (_left$ = left[0]) == null ? void 0 : _left$.headers) != null ? _left$0$headers : []), ...((_center$0$headers = (_center$ = center[0]) == null ? void 0 : _center$.headers) != null ? _center$0$headers : []), ...((_right$0$headers = (_right$ = right[0]) == null ? void 0 : _right$.headers) != null ? _right$0$headers : [])].map(header => {
535
536
  return header.getLeafHeaders();
@@ -1622,7 +1623,7 @@ const Ordering = {
1622
1623
  var _table$initialState$c;
1623
1624
  table.setColumnOrder(defaultState ? [] : (_table$initialState$c = table.initialState.columnOrder) != null ? _table$initialState$c : []);
1624
1625
  },
1625
- _getOrderColumnsFn: memo(() => [table.getState().columnOrder, table.getState().grouping, table.options.groupedColumnMode], (columnOrder, grouping, groupedColumnMode) => columns => {
1626
+ _getOrderColumnsFn: memo$1(() => [table.getState().columnOrder, table.getState().grouping, table.options.groupedColumnMode], (columnOrder, grouping, groupedColumnMode) => columns => {
1626
1627
  // Sort grouped columns to the start of the column list
1627
1628
  // before the headers are built
1628
1629
  let orderedColumns = [];
@@ -1756,7 +1757,7 @@ const Pagination = {
1756
1757
  pageCount: newPageCount
1757
1758
  };
1758
1759
  }),
1759
- getPageOptions: memo(() => [table.getPageCount()], pageCount => {
1760
+ getPageOptions: memo$1(() => [table.getPageCount()], pageCount => {
1760
1761
  let pageOptions = [];
1761
1762
  if (pageCount && pageCount > 0) {
1762
1763
  pageOptions = [...new Array(pageCount)].fill(null).map((_, i) => i);
@@ -1879,7 +1880,7 @@ const Pinning = {
1879
1880
  },
1880
1881
  createRow: (row, table) => {
1881
1882
  return {
1882
- getCenterVisibleCells: memo(() => [row._getAllVisibleCells(), table.getState().columnPinning.left, table.getState().columnPinning.right], (allCells, left, right) => {
1883
+ getCenterVisibleCells: memo$1(() => [row._getAllVisibleCells(), table.getState().columnPinning.left, table.getState().columnPinning.right], (allCells, left, right) => {
1883
1884
  const leftAndRight = [...(left != null ? left : []), ...(right != null ? right : [])];
1884
1885
  return allCells.filter(d => !leftAndRight.includes(d.column.id));
1885
1886
  }, {
@@ -1889,7 +1890,7 @@ const Pinning = {
1889
1890
  return (_table$options$debugA = table.options.debugAll) != null ? _table$options$debugA : table.options.debugRows;
1890
1891
  }
1891
1892
  }),
1892
- getLeftVisibleCells: memo(() => [row._getAllVisibleCells(), table.getState().columnPinning.left,,], (allCells, left) => {
1893
+ getLeftVisibleCells: memo$1(() => [row._getAllVisibleCells(), table.getState().columnPinning.left,,], (allCells, left) => {
1893
1894
  const cells = (left != null ? left : []).map(columnId => allCells.find(cell => cell.column.id === columnId)).filter(Boolean).map(d => ({
1894
1895
  ...d,
1895
1896
  position: 'left'
@@ -1902,7 +1903,7 @@ const Pinning = {
1902
1903
  return (_table$options$debugA2 = table.options.debugAll) != null ? _table$options$debugA2 : table.options.debugRows;
1903
1904
  }
1904
1905
  }),
1905
- getRightVisibleCells: memo(() => [row._getAllVisibleCells(), table.getState().columnPinning.right], (allCells, right) => {
1906
+ getRightVisibleCells: memo$1(() => [row._getAllVisibleCells(), table.getState().columnPinning.right], (allCells, right) => {
1906
1907
  const cells = (right != null ? right : []).map(columnId => allCells.find(cell => cell.column.id === columnId)).filter(Boolean).map(d => ({
1907
1908
  ...d,
1908
1909
  position: 'right'
@@ -1933,7 +1934,7 @@ const Pinning = {
1933
1934
  }
1934
1935
  return Boolean((_pinningState$positio = pinningState[position]) == null ? void 0 : _pinningState$positio.length);
1935
1936
  },
1936
- getLeftLeafColumns: memo(() => [table.getAllLeafColumns(), table.getState().columnPinning.left], (allColumns, left) => {
1937
+ getLeftLeafColumns: memo$1(() => [table.getAllLeafColumns(), table.getState().columnPinning.left], (allColumns, left) => {
1937
1938
  return (left != null ? left : []).map(columnId => allColumns.find(column => column.id === columnId)).filter(Boolean);
1938
1939
  }, {
1939
1940
  key: process.env.NODE_ENV === 'development' && 'getLeftLeafColumns',
@@ -1942,7 +1943,7 @@ const Pinning = {
1942
1943
  return (_table$options$debugA4 = table.options.debugAll) != null ? _table$options$debugA4 : table.options.debugColumns;
1943
1944
  }
1944
1945
  }),
1945
- getRightLeafColumns: memo(() => [table.getAllLeafColumns(), table.getState().columnPinning.right], (allColumns, right) => {
1946
+ getRightLeafColumns: memo$1(() => [table.getAllLeafColumns(), table.getState().columnPinning.right], (allColumns, right) => {
1946
1947
  return (right != null ? right : []).map(columnId => allColumns.find(column => column.id === columnId)).filter(Boolean);
1947
1948
  }, {
1948
1949
  key: process.env.NODE_ENV === 'development' && 'getRightLeafColumns',
@@ -1951,7 +1952,7 @@ const Pinning = {
1951
1952
  return (_table$options$debugA5 = table.options.debugAll) != null ? _table$options$debugA5 : table.options.debugColumns;
1952
1953
  }
1953
1954
  }),
1954
- getCenterLeafColumns: memo(() => [table.getAllLeafColumns(), table.getState().columnPinning.left, table.getState().columnPinning.right], (allColumns, left, right) => {
1955
+ getCenterLeafColumns: memo$1(() => [table.getAllLeafColumns(), table.getState().columnPinning.left, table.getState().columnPinning.right], (allColumns, left, right) => {
1955
1956
  const leftAndRight = [...(left != null ? left : []), ...(right != null ? right : [])];
1956
1957
  return allColumns.filter(d => !leftAndRight.includes(d.id));
1957
1958
  }, {
@@ -2087,7 +2088,7 @@ const RowSelection = {
2087
2088
  // table.setRowSelection(selectedRowIds)
2088
2089
  // },
2089
2090
  getPreSelectedRowModel: () => table.getCoreRowModel(),
2090
- getSelectedRowModel: memo(() => [table.getState().rowSelection, table.getCoreRowModel()], (rowSelection, rowModel) => {
2091
+ getSelectedRowModel: memo$1(() => [table.getState().rowSelection, table.getCoreRowModel()], (rowSelection, rowModel) => {
2091
2092
  if (!Object.keys(rowSelection).length) {
2092
2093
  return {
2093
2094
  rows: [],
@@ -2103,7 +2104,7 @@ const RowSelection = {
2103
2104
  return (_table$options$debugA = table.options.debugAll) != null ? _table$options$debugA : table.options.debugTable;
2104
2105
  }
2105
2106
  }),
2106
- getFilteredSelectedRowModel: memo(() => [table.getState().rowSelection, table.getFilteredRowModel()], (rowSelection, rowModel) => {
2107
+ getFilteredSelectedRowModel: memo$1(() => [table.getState().rowSelection, table.getFilteredRowModel()], (rowSelection, rowModel) => {
2107
2108
  if (!Object.keys(rowSelection).length) {
2108
2109
  return {
2109
2110
  rows: [],
@@ -2119,7 +2120,7 @@ const RowSelection = {
2119
2120
  return (_table$options$debugA2 = table.options.debugAll) != null ? _table$options$debugA2 : table.options.debugTable;
2120
2121
  }
2121
2122
  }),
2122
- getGroupedSelectedRowModel: memo(() => [table.getState().rowSelection, table.getSortedRowModel()], (rowSelection, rowModel) => {
2123
+ getGroupedSelectedRowModel: memo$1(() => [table.getState().rowSelection, table.getSortedRowModel()], (rowSelection, rowModel) => {
2123
2124
  if (!Object.keys(rowSelection).length) {
2124
2125
  return {
2125
2126
  rows: [],
@@ -2702,7 +2703,7 @@ const Visibility = {
2702
2703
  },
2703
2704
  createRow: (row, table) => {
2704
2705
  return {
2705
- _getAllVisibleCells: memo(() => [row.getAllCells(), table.getState().columnVisibility], cells => {
2706
+ _getAllVisibleCells: memo$1(() => [row.getAllCells(), table.getState().columnVisibility], cells => {
2706
2707
  return cells.filter(cell => cell.column.getIsVisible());
2707
2708
  }, {
2708
2709
  key: process.env.NODE_ENV === 'production' && 'row._getAllVisibleCells',
@@ -2711,7 +2712,7 @@ const Visibility = {
2711
2712
  return (_table$options$debugA = table.options.debugAll) != null ? _table$options$debugA : table.options.debugRows;
2712
2713
  }
2713
2714
  }),
2714
- getVisibleCells: memo(() => [row.getLeftVisibleCells(), row.getCenterVisibleCells(), row.getRightVisibleCells()], (left, center, right) => [...left, ...center, ...right], {
2715
+ getVisibleCells: memo$1(() => [row.getLeftVisibleCells(), row.getCenterVisibleCells(), row.getRightVisibleCells()], (left, center, right) => [...left, ...center, ...right], {
2715
2716
  key: process.env.NODE_ENV === 'development' && 'row.getVisibleCells',
2716
2717
  debug: () => {
2717
2718
  var _table$options$debugA2;
@@ -2722,7 +2723,7 @@ const Visibility = {
2722
2723
  },
2723
2724
  createTable: table => {
2724
2725
  const makeVisibleColumnsMethod = (key, getColumns) => {
2725
- return memo(() => [getColumns(), getColumns().filter(d => d.getIsVisible()).map(d => d.id).join('_')], columns => {
2726
+ return memo$1(() => [getColumns(), getColumns().filter(d => d.getIsVisible()).map(d => d.id).join('_')], columns => {
2726
2727
  return columns.filter(d => d.getIsVisible == null ? void 0 : d.getIsVisible());
2727
2728
  }, {
2728
2729
  key,
@@ -2861,7 +2862,7 @@ function createTable(options) {
2861
2862
  }
2862
2863
  return row;
2863
2864
  },
2864
- _getDefaultColumnDef: memo(() => [table.options.defaultColumn], defaultColumn => {
2865
+ _getDefaultColumnDef: memo$1(() => [table.options.defaultColumn], defaultColumn => {
2865
2866
  var _defaultColumn;
2866
2867
  defaultColumn = (_defaultColumn = defaultColumn) != null ? _defaultColumn : {};
2867
2868
  return {
@@ -2893,7 +2894,7 @@ function createTable(options) {
2893
2894
  key: process.env.NODE_ENV === 'development' && 'getDefaultColumnDef'
2894
2895
  }),
2895
2896
  _getColumnDefs: () => table.options.columns,
2896
- getAllColumns: memo(() => [table._getColumnDefs()], columnDefs => {
2897
+ getAllColumns: memo$1(() => [table._getColumnDefs()], columnDefs => {
2897
2898
  const recurseColumns = function (columnDefs, parent, depth) {
2898
2899
  if (depth === void 0) {
2899
2900
  depth = 0;
@@ -2913,7 +2914,7 @@ function createTable(options) {
2913
2914
  return (_table$options$debugA2 = table.options.debugAll) != null ? _table$options$debugA2 : table.options.debugColumns;
2914
2915
  }
2915
2916
  }),
2916
- getAllFlatColumns: memo(() => [table.getAllColumns()], allColumns => {
2917
+ getAllFlatColumns: memo$1(() => [table.getAllColumns()], allColumns => {
2917
2918
  return allColumns.flatMap(column => {
2918
2919
  return column.getFlatColumns();
2919
2920
  });
@@ -2924,7 +2925,7 @@ function createTable(options) {
2924
2925
  return (_table$options$debugA3 = table.options.debugAll) != null ? _table$options$debugA3 : table.options.debugColumns;
2925
2926
  }
2926
2927
  }),
2927
- _getAllFlatColumnsById: memo(() => [table.getAllFlatColumns()], flatColumns => {
2928
+ _getAllFlatColumnsById: memo$1(() => [table.getAllFlatColumns()], flatColumns => {
2928
2929
  return flatColumns.reduce((acc, column) => {
2929
2930
  acc[column.id] = column;
2930
2931
  return acc;
@@ -2936,7 +2937,7 @@ function createTable(options) {
2936
2937
  return (_table$options$debugA4 = table.options.debugAll) != null ? _table$options$debugA4 : table.options.debugColumns;
2937
2938
  }
2938
2939
  }),
2939
- getAllLeafColumns: memo(() => [table.getAllColumns(), table._getOrderColumnsFn()], (allColumns, orderColumns) => {
2940
+ getAllLeafColumns: memo$1(() => [table.getAllColumns(), table._getOrderColumnsFn()], (allColumns, orderColumns) => {
2940
2941
  let leafColumns = allColumns.flatMap(column => column.getLeafColumns());
2941
2942
  return orderColumns(leafColumns);
2942
2943
  }, {
@@ -2972,7 +2973,7 @@ function createCell(table, row, column, columnId) {
2972
2973
  column,
2973
2974
  getValue: () => row.getValue(columnId),
2974
2975
  renderValue: getRenderValue,
2975
- getContext: memo(() => [table, column, row, cell], (table, column, row, cell) => ({
2976
+ getContext: memo$1(() => [table, column, row, cell], (table, column, row, cell) => ({
2976
2977
  table,
2977
2978
  column,
2978
2979
  row,
@@ -3043,7 +3044,7 @@ const createRow = (table, id, original, rowIndex, depth, subRows, parentId) => {
3043
3044
  }
3044
3045
  return parentRows.reverse();
3045
3046
  },
3046
- getAllCells: memo(() => [table.getAllLeafColumns()], leafColumns => {
3047
+ getAllCells: memo$1(() => [table.getAllLeafColumns()], leafColumns => {
3047
3048
  return leafColumns.map(column => {
3048
3049
  return createCell(table, row, column, column.id);
3049
3050
  });
@@ -3054,7 +3055,7 @@ const createRow = (table, id, original, rowIndex, depth, subRows, parentId) => {
3054
3055
  return (_table$options$debugA = table.options.debugAll) != null ? _table$options$debugA : table.options.debugRows;
3055
3056
  }
3056
3057
  }),
3057
- _getAllCellsByColumnId: memo(() => [row.getAllCells()], allCells => {
3058
+ _getAllCellsByColumnId: memo$1(() => [row.getAllCells()], allCells => {
3058
3059
  return allCells.reduce((acc, cell) => {
3059
3060
  acc[cell.column.id] = cell;
3060
3061
  return acc;
@@ -3131,7 +3132,7 @@ function createColumnHelper() {
3131
3132
  }
3132
3133
 
3133
3134
  function getCoreRowModel() {
3134
- return table => memo(() => [table.options.data], data => {
3135
+ return table => memo$1(() => [table.options.data], data => {
3135
3136
  const rowModel = {
3136
3137
  rows: [],
3137
3138
  flatRows: [],
@@ -3188,7 +3189,7 @@ function getCoreRowModel() {
3188
3189
  }
3189
3190
 
3190
3191
  function getSortedRowModel() {
3191
- return table => memo(() => [table.getState().sorting, table.getPreSortedRowModel()], (sorting, rowModel) => {
3192
+ return table => memo$1(() => [table.getState().sorting, table.getPreSortedRowModel()], (sorting, rowModel) => {
3192
3193
  if (!rowModel.rows.length || !(sorting != null && sorting.length)) {
3193
3194
  return rowModel;
3194
3195
  }
@@ -3353,463 +3354,660 @@ function useReactTable(options) {
3353
3354
  *
3354
3355
  * @license MIT
3355
3356
  */
3357
+ function _extends$1() {
3358
+ _extends$1 = Object.assign ? Object.assign.bind() : function (target) {
3359
+ for (var i = 1; i < arguments.length; i++) {
3360
+ var source = arguments[i];
3361
+ for (var key in source) {
3362
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
3363
+ target[key] = source[key];
3364
+ }
3365
+ }
3366
+ }
3367
+ return target;
3368
+ };
3369
+ return _extends$1.apply(this, arguments);
3370
+ }
3356
3371
 
3372
+ /**
3373
+ * virtual-core
3374
+ *
3375
+ * Copyright (c) TanStack
3376
+ *
3377
+ * This source code is licensed under the MIT license found in the
3378
+ * LICENSE.md file in the root directory of this source tree.
3379
+ *
3380
+ * @license MIT
3381
+ */
3357
3382
  function _extends() {
3358
- _extends = Object.assign || function (target) {
3383
+ _extends = Object.assign ? Object.assign.bind() : function (target) {
3359
3384
  for (var i = 1; i < arguments.length; i++) {
3360
3385
  var source = arguments[i];
3361
-
3362
3386
  for (var key in source) {
3363
3387
  if (Object.prototype.hasOwnProperty.call(source, key)) {
3364
3388
  target[key] = source[key];
3365
3389
  }
3366
3390
  }
3367
3391
  }
3368
-
3369
3392
  return target;
3370
3393
  };
3371
-
3372
3394
  return _extends.apply(this, arguments);
3373
3395
  }
3374
3396
 
3375
- function _objectWithoutPropertiesLoose$1(source, excluded) {
3376
- if (source == null) return {};
3377
- var target = {};
3378
- var sourceKeys = Object.keys(source);
3379
- var key, i;
3380
-
3381
- for (i = 0; i < sourceKeys.length; i++) {
3382
- key = sourceKeys[i];
3383
- if (excluded.indexOf(key) >= 0) continue;
3384
- target[key] = source[key];
3385
- }
3386
-
3387
- return target;
3388
- }
3389
-
3390
- var props = ["bottom", "height", "left", "right", "top", "width"];
3391
-
3392
- var rectChanged = function rectChanged(a, b) {
3393
- if (a === void 0) {
3394
- a = {};
3395
- }
3396
-
3397
- if (b === void 0) {
3398
- b = {};
3399
- }
3400
-
3401
- return props.some(function (prop) {
3402
- return a[prop] !== b[prop];
3403
- });
3404
- };
3405
-
3406
- var observedNodes = /*#__PURE__*/new Map();
3407
- var rafId;
3408
-
3409
- var run = function run() {
3410
- var changedStates = [];
3411
- observedNodes.forEach(function (state, node) {
3412
- var newRect = node.getBoundingClientRect();
3413
-
3414
- if (rectChanged(newRect, state.rect)) {
3415
- state.rect = newRect;
3416
- changedStates.push(state);
3417
- }
3418
- });
3419
- changedStates.forEach(function (state) {
3420
- state.callbacks.forEach(function (cb) {
3421
- return cb(state.rect);
3397
+ /**
3398
+ * virtual-core
3399
+ *
3400
+ * Copyright (c) TanStack
3401
+ *
3402
+ * This source code is licensed under the MIT license found in the
3403
+ * LICENSE.md file in the root directory of this source tree.
3404
+ *
3405
+ * @license MIT
3406
+ */
3407
+ function memo(getDeps, fn, opts) {
3408
+ var _opts$initialDeps;
3409
+ var deps = (_opts$initialDeps = opts.initialDeps) != null ? _opts$initialDeps : [];
3410
+ var result;
3411
+ return function () {
3412
+ var depTime;
3413
+ if (opts.key && opts.debug != null && opts.debug()) depTime = Date.now();
3414
+ var newDeps = getDeps();
3415
+ var depsChanged = newDeps.length !== deps.length || newDeps.some(function (dep, index) {
3416
+ return deps[index] !== dep;
3422
3417
  });
3423
- });
3424
- rafId = window.requestAnimationFrame(run);
3425
- };
3426
-
3427
- function observeRect(node, cb) {
3428
- return {
3429
- observe: function observe() {
3430
- var wasEmpty = observedNodes.size === 0;
3431
-
3432
- if (observedNodes.has(node)) {
3433
- observedNodes.get(node).callbacks.push(cb);
3434
- } else {
3435
- observedNodes.set(node, {
3436
- rect: undefined,
3437
- hasRectChanged: false,
3438
- callbacks: [cb]
3439
- });
3440
- }
3441
-
3442
- if (wasEmpty) run();
3443
- },
3444
- unobserve: function unobserve() {
3445
- var state = observedNodes.get(node);
3446
-
3447
- if (state) {
3448
- // Remove the callback
3449
- var index = state.callbacks.indexOf(cb);
3450
- if (index >= 0) state.callbacks.splice(index, 1); // Remove the node reference
3451
-
3452
- if (!state.callbacks.length) observedNodes["delete"](node); // Stop the loop
3453
-
3454
- if (!observedNodes.size) cancelAnimationFrame(rafId);
3455
- }
3418
+ if (!depsChanged) {
3419
+ return result;
3456
3420
  }
3421
+ deps = newDeps;
3422
+ var resultTime;
3423
+ if (opts.key && opts.debug != null && opts.debug()) resultTime = Date.now();
3424
+ result = fn.apply(void 0, newDeps);
3425
+ if (opts.key && opts.debug != null && opts.debug()) {
3426
+ var depEndTime = Math.round((Date.now() - depTime) * 100) / 100;
3427
+ var resultEndTime = Math.round((Date.now() - resultTime) * 100) / 100;
3428
+ var resultFpsPercentage = resultEndTime / 16;
3429
+ var pad = function pad(str, num) {
3430
+ str = String(str);
3431
+ while (str.length < num) {
3432
+ str = ' ' + str;
3433
+ }
3434
+ return str;
3435
+ };
3436
+ console.info("%c\u23F1 " + pad(resultEndTime, 5) + " /" + pad(depEndTime, 5) + " ms", "\n font-size: .6rem;\n font-weight: bold;\n color: hsl(" + Math.max(0, Math.min(120 - 120 * resultFpsPercentage, 120)) + "deg 100% 31%);", opts == null ? void 0 : opts.key);
3437
+ }
3438
+ opts == null ? void 0 : opts.onChange == null ? void 0 : opts.onChange(result);
3439
+ return result;
3457
3440
  };
3458
3441
  }
3459
-
3460
- var useIsomorphicLayoutEffect$1 = typeof window !== 'undefined' ? React.useLayoutEffect : React.useEffect;
3461
-
3462
- function rectReducer(state, action) {
3463
- var rect = action.rect;
3464
-
3465
- if (state.height !== rect.height || state.width !== rect.width) {
3466
- return rect;
3442
+ function notUndefined(value, msg) {
3443
+ if (value === undefined) {
3444
+ throw new Error("Unexpected undefined" + (msg ? ": " + msg : ''));
3445
+ } else {
3446
+ return value;
3467
3447
  }
3468
-
3469
- return state;
3470
3448
  }
3471
-
3472
- var useRect = function useRect(nodeRef, initialRect) {
3473
- if (initialRect === void 0) {
3474
- initialRect = {
3475
- width: 0,
3476
- height: 0
3477
- };
3478
- }
3479
-
3480
- var _React$useState = React__default.useState(nodeRef.current),
3481
- element = _React$useState[0],
3482
- setElement = _React$useState[1];
3483
-
3484
- var _React$useReducer = React__default.useReducer(rectReducer, initialRect),
3485
- rect = _React$useReducer[0],
3486
- dispatch = _React$useReducer[1];
3487
-
3488
- var initialRectSet = React__default.useRef(false);
3489
- useIsomorphicLayoutEffect$1(function () {
3490
- if (nodeRef.current !== element) {
3491
- setElement(nodeRef.current);
3492
- }
3493
- });
3494
- useIsomorphicLayoutEffect$1(function () {
3495
- if (element && !initialRectSet.current) {
3496
- initialRectSet.current = true;
3497
-
3498
- var _rect = element.getBoundingClientRect();
3499
-
3500
- dispatch({
3501
- rect: _rect
3502
- });
3503
- }
3504
- }, [element]);
3505
- React__default.useEffect(function () {
3506
- if (!element) {
3507
- return;
3508
- }
3509
-
3510
- var observer = observeRect(element, function (rect) {
3511
- dispatch({
3512
- rect: rect
3513
- });
3514
- });
3515
- observer.observe();
3516
- return function () {
3517
- observer.unobserve();
3518
- };
3519
- }, [element]);
3520
- return rect;
3449
+ var approxEqual = function approxEqual(a, b) {
3450
+ return Math.abs(a - b) < 1;
3521
3451
  };
3522
3452
 
3523
- var _excluded$1 = ["align"];
3453
+ /**
3454
+ * virtual-core
3455
+ *
3456
+ * Copyright (c) TanStack
3457
+ *
3458
+ * This source code is licensed under the MIT license found in the
3459
+ * LICENSE.md file in the root directory of this source tree.
3460
+ *
3461
+ * @license MIT
3462
+ */
3524
3463
 
3525
- var defaultEstimateSize = function defaultEstimateSize() {
3526
- return 50;
3527
- };
3464
+ //
3465
+
3466
+ //
3528
3467
 
3529
3468
  var defaultKeyExtractor = function defaultKeyExtractor(index) {
3530
3469
  return index;
3531
3470
  };
3532
-
3533
- var defaultMeasureSize = function defaultMeasureSize(el, horizontal) {
3534
- var key = horizontal ? 'offsetWidth' : 'offsetHeight';
3535
- return el[key];
3536
- };
3537
-
3538
3471
  var defaultRangeExtractor = function defaultRangeExtractor(range) {
3539
- var start = Math.max(range.start - range.overscan, 0);
3540
- var end = Math.min(range.end + range.overscan, range.size - 1);
3472
+ var start = Math.max(range.startIndex - range.overscan, 0);
3473
+ var end = Math.min(range.endIndex + range.overscan, range.count - 1);
3541
3474
  var arr = [];
3542
-
3543
3475
  for (var _i = start; _i <= end; _i++) {
3544
3476
  arr.push(_i);
3545
3477
  }
3546
-
3547
3478
  return arr;
3548
3479
  };
3549
- var useVirtual = function useVirtual(_ref) {
3550
- var _measurements;
3551
-
3552
- var _ref$size = _ref.size,
3553
- size = _ref$size === void 0 ? 0 : _ref$size,
3554
- _ref$estimateSize = _ref.estimateSize,
3555
- estimateSize = _ref$estimateSize === void 0 ? defaultEstimateSize : _ref$estimateSize,
3556
- _ref$overscan = _ref.overscan,
3557
- overscan = _ref$overscan === void 0 ? 1 : _ref$overscan,
3558
- _ref$paddingStart = _ref.paddingStart,
3559
- paddingStart = _ref$paddingStart === void 0 ? 0 : _ref$paddingStart,
3560
- _ref$paddingEnd = _ref.paddingEnd,
3561
- paddingEnd = _ref$paddingEnd === void 0 ? 0 : _ref$paddingEnd,
3562
- parentRef = _ref.parentRef,
3563
- _ref$horizontal = _ref.horizontal,
3564
- horizontal = _ref$horizontal === void 0 ? false : _ref$horizontal,
3565
- scrollToFn = _ref.scrollToFn,
3566
- useObserver = _ref.useObserver,
3567
- initialRect = _ref.initialRect,
3568
- onScrollElement = _ref.onScrollElement,
3569
- scrollOffsetFn = _ref.scrollOffsetFn,
3570
- _ref$keyExtractor = _ref.keyExtractor,
3571
- keyExtractor = _ref$keyExtractor === void 0 ? defaultKeyExtractor : _ref$keyExtractor,
3572
- _ref$measureSize = _ref.measureSize,
3573
- measureSize = _ref$measureSize === void 0 ? defaultMeasureSize : _ref$measureSize,
3574
- _ref$rangeExtractor = _ref.rangeExtractor,
3575
- rangeExtractor = _ref$rangeExtractor === void 0 ? defaultRangeExtractor : _ref$rangeExtractor;
3576
- var sizeKey = horizontal ? 'width' : 'height';
3577
- var scrollKey = horizontal ? 'scrollLeft' : 'scrollTop';
3578
- var latestRef = React.useRef({
3579
- outerSize: 0,
3580
- scrollOffset: 0,
3581
- measurements: [],
3582
- totalSize: 0
3480
+ var observeElementRect = function observeElementRect(instance, cb) {
3481
+ var element = instance.scrollElement;
3482
+ if (!element) {
3483
+ return;
3484
+ }
3485
+ var handler = function handler(rect) {
3486
+ var width = rect.width,
3487
+ height = rect.height;
3488
+ cb({
3489
+ width: Math.round(width),
3490
+ height: Math.round(height)
3491
+ });
3492
+ };
3493
+ handler(element.getBoundingClientRect());
3494
+ var observer = new ResizeObserver(function (entries) {
3495
+ var entry = entries[0];
3496
+ if (entry != null && entry.borderBoxSize) {
3497
+ var box = entry.borderBoxSize[0];
3498
+ if (box) {
3499
+ handler({
3500
+ width: box.inlineSize,
3501
+ height: box.blockSize
3502
+ });
3503
+ return;
3504
+ }
3505
+ }
3506
+ handler(element.getBoundingClientRect());
3583
3507
  });
3584
-
3585
- var _React$useState = React.useState(0),
3586
- scrollOffset = _React$useState[0],
3587
- setScrollOffset = _React$useState[1];
3588
-
3589
- latestRef.current.scrollOffset = scrollOffset;
3590
- var useMeasureParent = useObserver || useRect;
3591
-
3592
- var _useMeasureParent = useMeasureParent(parentRef, initialRect),
3593
- outerSize = _useMeasureParent[sizeKey];
3594
-
3595
- latestRef.current.outerSize = outerSize;
3596
- var defaultScrollToFn = React.useCallback(function (offset) {
3597
- if (parentRef.current) {
3598
- parentRef.current[scrollKey] = offset;
3508
+ observer.observe(element, {
3509
+ box: 'border-box'
3510
+ });
3511
+ return function () {
3512
+ observer.unobserve(element);
3513
+ };
3514
+ };
3515
+ var observeElementOffset = function observeElementOffset(instance, cb) {
3516
+ var element = instance.scrollElement;
3517
+ if (!element) {
3518
+ return;
3519
+ }
3520
+ var handler = function handler() {
3521
+ cb(element[instance.options.horizontal ? 'scrollLeft' : 'scrollTop']);
3522
+ };
3523
+ handler();
3524
+ element.addEventListener('scroll', handler, {
3525
+ passive: true
3526
+ });
3527
+ return function () {
3528
+ element.removeEventListener('scroll', handler);
3529
+ };
3530
+ };
3531
+ var measureElement = function measureElement(element, entry, instance) {
3532
+ if (entry != null && entry.borderBoxSize) {
3533
+ var box = entry.borderBoxSize[0];
3534
+ if (box) {
3535
+ var size = Math.round(box[instance.options.horizontal ? 'inlineSize' : 'blockSize']);
3536
+ return size;
3599
3537
  }
3600
- }, [parentRef, scrollKey]);
3601
- var resolvedScrollToFn = scrollToFn || defaultScrollToFn;
3602
- var scrollTo = React.useCallback(function (offset) {
3603
- resolvedScrollToFn(offset, defaultScrollToFn);
3604
- }, [defaultScrollToFn, resolvedScrollToFn]);
3605
-
3606
- var _React$useState2 = React.useState({}),
3607
- measuredCache = _React$useState2[0],
3608
- setMeasuredCache = _React$useState2[1];
3609
-
3610
- var measure = React.useCallback(function () {
3611
- return setMeasuredCache({});
3612
- }, []);
3613
- var pendingMeasuredCacheIndexesRef = React.useRef([]);
3614
- var measurements = React.useMemo(function () {
3615
- var min = pendingMeasuredCacheIndexesRef.current.length > 0 ? Math.min.apply(Math, pendingMeasuredCacheIndexesRef.current) : 0;
3616
- pendingMeasuredCacheIndexesRef.current = [];
3617
- var measurements = latestRef.current.measurements.slice(0, min);
3618
-
3619
- for (var _i2 = min; _i2 < size; _i2++) {
3620
- var key = keyExtractor(_i2);
3621
- var measuredSize = measuredCache[key];
3622
-
3623
- var _start = measurements[_i2 - 1] ? measurements[_i2 - 1].end : paddingStart;
3624
-
3625
- var _size = typeof measuredSize === 'number' ? measuredSize : estimateSize(_i2);
3626
-
3627
- var _end = _start + _size;
3628
-
3538
+ }
3539
+ return Math.round(element.getBoundingClientRect()[instance.options.horizontal ? 'width' : 'height']);
3540
+ };
3541
+ var elementScroll = function elementScroll(offset, _ref2, instance) {
3542
+ var _instance$scrollEleme3, _instance$scrollEleme4;
3543
+ var _ref2$adjustments = _ref2.adjustments,
3544
+ adjustments = _ref2$adjustments === void 0 ? 0 : _ref2$adjustments,
3545
+ behavior = _ref2.behavior;
3546
+ var toOffset = offset + adjustments;
3547
+ (_instance$scrollEleme3 = instance.scrollElement) == null ? void 0 : _instance$scrollEleme3.scrollTo == null ? void 0 : _instance$scrollEleme3.scrollTo((_instance$scrollEleme4 = {}, _instance$scrollEleme4[instance.options.horizontal ? 'left' : 'top'] = toOffset, _instance$scrollEleme4.behavior = behavior, _instance$scrollEleme4));
3548
+ };
3549
+ var Virtualizer = function Virtualizer(_opts) {
3550
+ var _this = this;
3551
+ this.unsubs = [];
3552
+ this.scrollElement = null;
3553
+ this.isScrolling = false;
3554
+ this.isScrollingTimeoutId = null;
3555
+ this.scrollToIndexTimeoutId = null;
3556
+ this.measurementsCache = [];
3557
+ this.itemSizeCache = new Map();
3558
+ this.pendingMeasuredCacheIndexes = [];
3559
+ this.scrollDirection = null;
3560
+ this.scrollAdjustments = 0;
3561
+ this.measureElementCache = new Map();
3562
+ this.observer = function () {
3563
+ var _ro = null;
3564
+ var get = function get() {
3565
+ if (_ro) {
3566
+ return _ro;
3567
+ } else if (typeof ResizeObserver !== 'undefined') {
3568
+ return _ro = new ResizeObserver(function (entries) {
3569
+ entries.forEach(function (entry) {
3570
+ _this._measureElement(entry.target, entry);
3571
+ });
3572
+ });
3573
+ } else {
3574
+ return null;
3575
+ }
3576
+ };
3577
+ return {
3578
+ disconnect: function disconnect() {
3579
+ var _get;
3580
+ return (_get = get()) == null ? void 0 : _get.disconnect();
3581
+ },
3582
+ observe: function observe(target) {
3583
+ var _get2;
3584
+ return (_get2 = get()) == null ? void 0 : _get2.observe(target, {
3585
+ box: 'border-box'
3586
+ });
3587
+ },
3588
+ unobserve: function unobserve(target) {
3589
+ var _get3;
3590
+ return (_get3 = get()) == null ? void 0 : _get3.unobserve(target);
3591
+ }
3592
+ };
3593
+ }();
3594
+ this.range = null;
3595
+ this.setOptions = function (opts) {
3596
+ Object.entries(opts).forEach(function (_ref3) {
3597
+ var key = _ref3[0],
3598
+ value = _ref3[1];
3599
+ if (typeof value === 'undefined') delete opts[key];
3600
+ });
3601
+ _this.options = _extends({
3602
+ debug: false,
3603
+ initialOffset: 0,
3604
+ overscan: 1,
3605
+ paddingStart: 0,
3606
+ paddingEnd: 0,
3607
+ scrollPaddingStart: 0,
3608
+ scrollPaddingEnd: 0,
3609
+ horizontal: false,
3610
+ getItemKey: defaultKeyExtractor,
3611
+ rangeExtractor: defaultRangeExtractor,
3612
+ onChange: function onChange() {},
3613
+ measureElement: measureElement,
3614
+ initialRect: {
3615
+ width: 0,
3616
+ height: 0
3617
+ },
3618
+ scrollMargin: 0,
3619
+ scrollingDelay: 150,
3620
+ indexAttribute: 'data-index',
3621
+ initialMeasurementsCache: [],
3622
+ lanes: 1
3623
+ }, opts);
3624
+ };
3625
+ this.notify = function (sync) {
3626
+ _this.options.onChange == null ? void 0 : _this.options.onChange(_this, sync);
3627
+ };
3628
+ this.maybeNotify = memo(function () {
3629
+ _this.calculateRange();
3630
+ return [_this.isScrolling, _this.range ? _this.range.startIndex : null, _this.range ? _this.range.endIndex : null];
3631
+ }, function (isScrolling) {
3632
+ _this.notify(isScrolling);
3633
+ }, {
3634
+ key: process.env.NODE_ENV !== 'production' && 'maybeNotify',
3635
+ debug: function debug() {
3636
+ return _this.options.debug;
3637
+ },
3638
+ initialDeps: [this.isScrolling, this.range ? this.range.startIndex : null, this.range ? this.range.endIndex : null]
3639
+ });
3640
+ this.cleanup = function () {
3641
+ _this.unsubs.filter(Boolean).forEach(function (d) {
3642
+ return d();
3643
+ });
3644
+ _this.unsubs = [];
3645
+ _this.scrollElement = null;
3646
+ };
3647
+ this._didMount = function () {
3648
+ _this.measureElementCache.forEach(_this.observer.observe);
3649
+ return function () {
3650
+ _this.observer.disconnect();
3651
+ _this.cleanup();
3652
+ };
3653
+ };
3654
+ this._willUpdate = function () {
3655
+ var scrollElement = _this.options.getScrollElement();
3656
+ if (_this.scrollElement !== scrollElement) {
3657
+ _this.cleanup();
3658
+ _this.scrollElement = scrollElement;
3659
+ _this._scrollToOffset(_this.scrollOffset, {
3660
+ adjustments: undefined,
3661
+ behavior: undefined
3662
+ });
3663
+ _this.unsubs.push(_this.options.observeElementRect(_this, function (rect) {
3664
+ _this.scrollRect = rect;
3665
+ _this.maybeNotify();
3666
+ }));
3667
+ _this.unsubs.push(_this.options.observeElementOffset(_this, function (offset) {
3668
+ _this.scrollAdjustments = 0;
3669
+ if (_this.scrollOffset === offset) {
3670
+ return;
3671
+ }
3672
+ if (_this.isScrollingTimeoutId !== null) {
3673
+ clearTimeout(_this.isScrollingTimeoutId);
3674
+ _this.isScrollingTimeoutId = null;
3675
+ }
3676
+ _this.isScrolling = true;
3677
+ _this.scrollDirection = _this.scrollOffset < offset ? 'forward' : 'backward';
3678
+ _this.scrollOffset = offset;
3679
+ _this.maybeNotify();
3680
+ _this.isScrollingTimeoutId = setTimeout(function () {
3681
+ _this.isScrollingTimeoutId = null;
3682
+ _this.isScrolling = false;
3683
+ _this.scrollDirection = null;
3684
+ _this.maybeNotify();
3685
+ }, _this.options.scrollingDelay);
3686
+ }));
3687
+ }
3688
+ };
3689
+ this.getSize = function () {
3690
+ return _this.scrollRect[_this.options.horizontal ? 'width' : 'height'];
3691
+ };
3692
+ this.memoOptions = memo(function () {
3693
+ return [_this.options.count, _this.options.paddingStart, _this.options.scrollMargin, _this.options.getItemKey];
3694
+ }, function (count, paddingStart, scrollMargin, getItemKey) {
3695
+ _this.pendingMeasuredCacheIndexes = [];
3696
+ return {
3697
+ count: count,
3698
+ paddingStart: paddingStart,
3699
+ scrollMargin: scrollMargin,
3700
+ getItemKey: getItemKey
3701
+ };
3702
+ }, {
3703
+ key: false
3704
+ });
3705
+ this.getFurthestMeasurement = function (measurements, index) {
3706
+ var furthestMeasurementsFound = new Map();
3707
+ var furthestMeasurements = new Map();
3708
+ for (var m = index - 1; m >= 0; m--) {
3709
+ var measurement = measurements[m];
3710
+ if (furthestMeasurementsFound.has(measurement.lane)) {
3711
+ continue;
3712
+ }
3713
+ var previousFurthestMeasurement = furthestMeasurements.get(measurement.lane);
3714
+ if (previousFurthestMeasurement == null || measurement.end > previousFurthestMeasurement.end) {
3715
+ furthestMeasurements.set(measurement.lane, measurement);
3716
+ } else if (measurement.end < previousFurthestMeasurement.end) {
3717
+ furthestMeasurementsFound.set(measurement.lane, true);
3718
+ }
3719
+ if (furthestMeasurementsFound.size === _this.options.lanes) {
3720
+ break;
3721
+ }
3722
+ }
3723
+ return furthestMeasurements.size === _this.options.lanes ? Array.from(furthestMeasurements.values()).sort(function (a, b) {
3724
+ return a.end - b.end;
3725
+ })[0] : undefined;
3726
+ };
3727
+ this.getMeasurements = memo(function () {
3728
+ return [_this.memoOptions(), _this.itemSizeCache];
3729
+ }, function (_ref4, itemSizeCache) {
3730
+ var count = _ref4.count,
3731
+ paddingStart = _ref4.paddingStart,
3732
+ scrollMargin = _ref4.scrollMargin,
3733
+ getItemKey = _ref4.getItemKey;
3734
+ var min = _this.pendingMeasuredCacheIndexes.length > 0 ? Math.min.apply(Math, _this.pendingMeasuredCacheIndexes) : 0;
3735
+ _this.pendingMeasuredCacheIndexes = [];
3736
+ var measurements = _this.measurementsCache.slice(0, min);
3737
+ for (var _i2 = min; _i2 < count; _i2++) {
3738
+ var key = getItemKey(_i2);
3739
+ var furthestMeasurement = _this.options.lanes === 1 ? measurements[_i2 - 1] : _this.getFurthestMeasurement(measurements, _i2);
3740
+ var start = furthestMeasurement ? furthestMeasurement.end : paddingStart + scrollMargin;
3741
+ var measuredSize = itemSizeCache.get(key);
3742
+ var size = typeof measuredSize === 'number' ? measuredSize : _this.options.estimateSize(_i2);
3743
+ var end = start + size;
3744
+ var lane = furthestMeasurement ? furthestMeasurement.lane : _i2 % _this.options.lanes;
3629
3745
  measurements[_i2] = {
3630
3746
  index: _i2,
3631
- start: _start,
3632
- size: _size,
3633
- end: _end,
3634
- key: key
3747
+ start: start,
3748
+ size: size,
3749
+ end: end,
3750
+ key: key,
3751
+ lane: lane
3635
3752
  };
3636
3753
  }
3637
-
3754
+ _this.measurementsCache = measurements;
3638
3755
  return measurements;
3639
- }, [estimateSize, measuredCache, paddingStart, size, keyExtractor]);
3640
- var totalSize = (((_measurements = measurements[size - 1]) == null ? void 0 : _measurements.end) || paddingStart) + paddingEnd;
3641
- latestRef.current.measurements = measurements;
3642
- latestRef.current.totalSize = totalSize;
3643
- var element = onScrollElement ? onScrollElement.current : parentRef.current;
3644
- var scrollOffsetFnRef = React.useRef(scrollOffsetFn);
3645
- scrollOffsetFnRef.current = scrollOffsetFn;
3646
- useIsomorphicLayoutEffect$1(function () {
3647
- if (!element) {
3648
- setScrollOffset(0);
3649
- return;
3756
+ }, {
3757
+ key: process.env.NODE_ENV !== 'production' && 'getMeasurements',
3758
+ debug: function debug() {
3759
+ return _this.options.debug;
3650
3760
  }
3651
-
3652
- var onScroll = function onScroll(event) {
3653
- var offset = scrollOffsetFnRef.current ? scrollOffsetFnRef.current(event) : element[scrollKey];
3654
- setScrollOffset(offset);
3655
- };
3656
-
3657
- onScroll();
3658
- element.addEventListener('scroll', onScroll, {
3659
- capture: false,
3660
- passive: true
3661
- });
3662
- return function () {
3663
- element.removeEventListener('scroll', onScroll);
3664
- };
3665
- }, [element, scrollKey]);
3666
-
3667
- var _calculateRange = calculateRange(latestRef.current),
3668
- start = _calculateRange.start,
3669
- end = _calculateRange.end;
3670
-
3671
- var indexes = React.useMemo(function () {
3672
- return rangeExtractor({
3673
- start: start,
3674
- end: end,
3761
+ });
3762
+ this.calculateRange = memo(function () {
3763
+ return [_this.getMeasurements(), _this.getSize(), _this.scrollOffset];
3764
+ }, function (measurements, outerSize, scrollOffset) {
3765
+ return _this.range = measurements.length > 0 && outerSize > 0 ? calculateRange({
3766
+ measurements: measurements,
3767
+ outerSize: outerSize,
3768
+ scrollOffset: scrollOffset
3769
+ }) : null;
3770
+ }, {
3771
+ key: process.env.NODE_ENV !== 'production' && 'calculateRange',
3772
+ debug: function debug() {
3773
+ return _this.options.debug;
3774
+ }
3775
+ });
3776
+ this.getIndexes = memo(function () {
3777
+ return [_this.options.rangeExtractor, _this.calculateRange(), _this.options.overscan, _this.options.count];
3778
+ }, function (rangeExtractor, range, overscan, count) {
3779
+ return range === null ? [] : rangeExtractor(_extends({}, range, {
3675
3780
  overscan: overscan,
3676
- size: measurements.length
3677
- });
3678
- }, [start, end, overscan, measurements.length, rangeExtractor]);
3679
- var measureSizeRef = React.useRef(measureSize);
3680
- measureSizeRef.current = measureSize;
3681
- var virtualItems = React.useMemo(function () {
3682
- var virtualItems = [];
3683
-
3684
- var _loop = function _loop(k, len) {
3685
- var i = indexes[k];
3686
- var measurement = measurements[i];
3687
-
3688
- var item = _extends({}, measurement, {
3689
- measureRef: function measureRef(el) {
3690
- if (el) {
3691
- var measuredSize = measureSizeRef.current(el, horizontal);
3692
-
3693
- if (measuredSize !== item.size) {
3694
- var _scrollOffset = latestRef.current.scrollOffset;
3695
-
3696
- if (item.start < _scrollOffset) {
3697
- defaultScrollToFn(_scrollOffset + (measuredSize - item.size));
3698
- }
3699
-
3700
- pendingMeasuredCacheIndexesRef.current.push(i);
3701
- setMeasuredCache(function (old) {
3702
- var _extends2;
3703
-
3704
- return _extends({}, old, (_extends2 = {}, _extends2[item.key] = measuredSize, _extends2));
3705
- });
3706
- }
3707
- }
3781
+ count: count
3782
+ }));
3783
+ }, {
3784
+ key: process.env.NODE_ENV !== 'production' && 'getIndexes',
3785
+ debug: function debug() {
3786
+ return _this.options.debug;
3787
+ }
3788
+ });
3789
+ this.indexFromElement = function (node) {
3790
+ var attributeName = _this.options.indexAttribute;
3791
+ var indexStr = node.getAttribute(attributeName);
3792
+ if (!indexStr) {
3793
+ console.warn("Missing attribute name '" + attributeName + "={index}' on measured element.");
3794
+ return -1;
3795
+ }
3796
+ return parseInt(indexStr, 10);
3797
+ };
3798
+ this._measureElement = function (node, entry) {
3799
+ var item = _this.measurementsCache[_this.indexFromElement(node)];
3800
+ if (!item || !node.isConnected) {
3801
+ _this.measureElementCache.forEach(function (cached, key) {
3802
+ if (cached === node) {
3803
+ _this.observer.unobserve(node);
3804
+ _this.measureElementCache["delete"](key);
3708
3805
  }
3709
3806
  });
3710
-
3711
- virtualItems.push(item);
3712
- };
3713
-
3807
+ return;
3808
+ }
3809
+ var prevNode = _this.measureElementCache.get(item.key);
3810
+ if (prevNode !== node) {
3811
+ if (prevNode) {
3812
+ _this.observer.unobserve(prevNode);
3813
+ }
3814
+ _this.observer.observe(node);
3815
+ _this.measureElementCache.set(item.key, node);
3816
+ }
3817
+ var measuredItemSize = _this.options.measureElement(node, entry, _this);
3818
+ _this.resizeItem(item, measuredItemSize);
3819
+ };
3820
+ this.resizeItem = function (item, size) {
3821
+ var _this$itemSizeCache$g;
3822
+ var itemSize = (_this$itemSizeCache$g = _this.itemSizeCache.get(item.key)) != null ? _this$itemSizeCache$g : item.size;
3823
+ var delta = size - itemSize;
3824
+ if (delta !== 0) {
3825
+ if (item.start < _this.scrollOffset) {
3826
+ if (process.env.NODE_ENV !== 'production' && _this.options.debug) {
3827
+ console.info('correction', delta);
3828
+ }
3829
+ _this._scrollToOffset(_this.scrollOffset, {
3830
+ adjustments: _this.scrollAdjustments += delta,
3831
+ behavior: undefined
3832
+ });
3833
+ }
3834
+ _this.pendingMeasuredCacheIndexes.push(item.index);
3835
+ _this.itemSizeCache = new Map(_this.itemSizeCache.set(item.key, size));
3836
+ _this.notify(false);
3837
+ }
3838
+ };
3839
+ this.measureElement = function (node) {
3840
+ if (!node) {
3841
+ return;
3842
+ }
3843
+ _this._measureElement(node, undefined);
3844
+ };
3845
+ this.getVirtualItems = memo(function () {
3846
+ return [_this.getIndexes(), _this.getMeasurements()];
3847
+ }, function (indexes, measurements) {
3848
+ var virtualItems = [];
3714
3849
  for (var k = 0, len = indexes.length; k < len; k++) {
3715
- _loop(k);
3850
+ var _i3 = indexes[k];
3851
+ var measurement = measurements[_i3];
3852
+ virtualItems.push(measurement);
3716
3853
  }
3717
-
3718
3854
  return virtualItems;
3719
- }, [indexes, defaultScrollToFn, horizontal, measurements]);
3720
- var mountedRef = React.useRef(false);
3721
- useIsomorphicLayoutEffect$1(function () {
3722
- if (mountedRef.current) {
3723
- setMeasuredCache({});
3855
+ }, {
3856
+ key: process.env.NODE_ENV !== 'production' && 'getIndexes',
3857
+ debug: function debug() {
3858
+ return _this.options.debug;
3724
3859
  }
3725
-
3726
- mountedRef.current = true;
3727
- }, [estimateSize]);
3728
- var scrollToOffset = React.useCallback(function (toOffset, _temp) {
3729
- var _ref2 = _temp === void 0 ? {
3730
- align: 'start'
3731
- } : _temp,
3732
- align = _ref2.align;
3733
-
3734
- var _latestRef$current = latestRef.current,
3735
- scrollOffset = _latestRef$current.scrollOffset,
3736
- outerSize = _latestRef$current.outerSize;
3737
-
3860
+ });
3861
+ this.getVirtualItemForOffset = function (offset) {
3862
+ var measurements = _this.getMeasurements();
3863
+ return notUndefined(measurements[findNearestBinarySearch(0, measurements.length - 1, function (index) {
3864
+ return notUndefined(measurements[index]).start;
3865
+ }, offset)]);
3866
+ };
3867
+ this.getOffsetForAlignment = function (toOffset, align) {
3868
+ var size = _this.getSize();
3738
3869
  if (align === 'auto') {
3739
- if (toOffset <= scrollOffset) {
3870
+ if (toOffset <= _this.scrollOffset) {
3740
3871
  align = 'start';
3741
- } else if (toOffset >= scrollOffset + outerSize) {
3872
+ } else if (toOffset >= _this.scrollOffset + size) {
3742
3873
  align = 'end';
3743
3874
  } else {
3744
3875
  align = 'start';
3745
3876
  }
3746
3877
  }
3747
-
3748
3878
  if (align === 'start') {
3749
- scrollTo(toOffset);
3879
+ toOffset = toOffset;
3750
3880
  } else if (align === 'end') {
3751
- scrollTo(toOffset - outerSize);
3881
+ toOffset = toOffset - size;
3752
3882
  } else if (align === 'center') {
3753
- scrollTo(toOffset - outerSize / 2);
3754
- }
3755
- }, [scrollTo]);
3756
- var tryScrollToIndex = React.useCallback(function (index, _temp2) {
3757
- var _ref3 = _temp2 === void 0 ? {
3758
- align: 'auto'
3759
- } : _temp2,
3760
- align = _ref3.align,
3761
- rest = _objectWithoutPropertiesLoose$1(_ref3, _excluded$1);
3762
-
3763
- var _latestRef$current2 = latestRef.current,
3764
- measurements = _latestRef$current2.measurements,
3765
- scrollOffset = _latestRef$current2.scrollOffset,
3766
- outerSize = _latestRef$current2.outerSize;
3767
- var measurement = measurements[Math.max(0, Math.min(index, size - 1))];
3768
-
3769
- if (!measurement) {
3770
- return;
3883
+ toOffset = toOffset - size / 2;
3771
3884
  }
3772
-
3885
+ var scrollSizeProp = _this.options.horizontal ? 'scrollWidth' : 'scrollHeight';
3886
+ var scrollSize = _this.scrollElement ? 'document' in _this.scrollElement ? _this.scrollElement.document.documentElement[scrollSizeProp] : _this.scrollElement[scrollSizeProp] : 0;
3887
+ var maxOffset = scrollSize - _this.getSize();
3888
+ return Math.max(Math.min(maxOffset, toOffset), 0);
3889
+ };
3890
+ this.getOffsetForIndex = function (index, align) {
3891
+ if (align === void 0) {
3892
+ align = 'auto';
3893
+ }
3894
+ index = Math.max(0, Math.min(index, _this.options.count - 1));
3895
+ var measurement = notUndefined(_this.getMeasurements()[index]);
3773
3896
  if (align === 'auto') {
3774
- if (measurement.end >= scrollOffset + outerSize) {
3897
+ if (measurement.end >= _this.scrollOffset + _this.getSize() - _this.options.scrollPaddingEnd) {
3775
3898
  align = 'end';
3776
- } else if (measurement.start <= scrollOffset) {
3899
+ } else if (measurement.start <= _this.scrollOffset + _this.options.scrollPaddingStart) {
3777
3900
  align = 'start';
3778
3901
  } else {
3779
- return;
3902
+ return [_this.scrollOffset, align];
3780
3903
  }
3781
3904
  }
3782
-
3783
- var toOffset = align === 'center' ? measurement.start + measurement.size / 2 : align === 'end' ? measurement.end : measurement.start;
3784
- scrollToOffset(toOffset, _extends({
3785
- align: align
3786
- }, rest));
3787
- }, [scrollToOffset, size]);
3788
- var scrollToIndex = React.useCallback(function (index, options) {
3789
- // We do a double request here because of
3790
- // dynamic sizes which can cause offset shift
3791
- // and end up in the wrong spot. Unfortunately,
3792
- // we can't know about those dynamic sizes until
3793
- // we try and render them. So double down!
3794
- tryScrollToIndex(index, options);
3795
- requestAnimationFrame(function () {
3796
- tryScrollToIndex(index, options);
3905
+ var toOffset = align === 'end' ? measurement.end + _this.options.scrollPaddingEnd : measurement.start - _this.options.scrollPaddingStart;
3906
+ return [_this.getOffsetForAlignment(toOffset, align), align];
3907
+ };
3908
+ this.isDynamicMode = function () {
3909
+ return _this.measureElementCache.size > 0;
3910
+ };
3911
+ this.cancelScrollToIndex = function () {
3912
+ if (_this.scrollToIndexTimeoutId !== null) {
3913
+ clearTimeout(_this.scrollToIndexTimeoutId);
3914
+ _this.scrollToIndexTimeoutId = null;
3915
+ }
3916
+ };
3917
+ this.scrollToOffset = function (toOffset, _temp) {
3918
+ var _ref5 = _temp === void 0 ? {} : _temp,
3919
+ _ref5$align = _ref5.align,
3920
+ align = _ref5$align === void 0 ? 'start' : _ref5$align,
3921
+ behavior = _ref5.behavior;
3922
+ _this.cancelScrollToIndex();
3923
+ if (behavior === 'smooth' && _this.isDynamicMode()) {
3924
+ console.warn('The `smooth` scroll behavior is not fully supported with dynamic size.');
3925
+ }
3926
+ _this._scrollToOffset(_this.getOffsetForAlignment(toOffset, align), {
3927
+ adjustments: undefined,
3928
+ behavior: behavior
3797
3929
  });
3798
- }, [tryScrollToIndex]);
3799
- return {
3800
- virtualItems: virtualItems,
3801
- totalSize: totalSize,
3802
- scrollToOffset: scrollToOffset,
3803
- scrollToIndex: scrollToIndex,
3804
- measure: measure
3805
3930
  };
3931
+ this.scrollToIndex = function (index, _temp2) {
3932
+ var _ref6 = _temp2 === void 0 ? {} : _temp2,
3933
+ _ref6$align = _ref6.align,
3934
+ initialAlign = _ref6$align === void 0 ? 'auto' : _ref6$align,
3935
+ behavior = _ref6.behavior;
3936
+ index = Math.max(0, Math.min(index, _this.options.count - 1));
3937
+ _this.cancelScrollToIndex();
3938
+ if (behavior === 'smooth' && _this.isDynamicMode()) {
3939
+ console.warn('The `smooth` scroll behavior is not fully supported with dynamic size.');
3940
+ }
3941
+ var _this$getOffsetForInd = _this.getOffsetForIndex(index, initialAlign),
3942
+ toOffset = _this$getOffsetForInd[0],
3943
+ align = _this$getOffsetForInd[1];
3944
+ _this._scrollToOffset(toOffset, {
3945
+ adjustments: undefined,
3946
+ behavior: behavior
3947
+ });
3948
+ if (behavior !== 'smooth' && _this.isDynamicMode()) {
3949
+ _this.scrollToIndexTimeoutId = setTimeout(function () {
3950
+ _this.scrollToIndexTimeoutId = null;
3951
+ var elementInDOM = _this.measureElementCache.has(_this.options.getItemKey(index));
3952
+ if (elementInDOM) {
3953
+ var _this$getOffsetForInd2 = _this.getOffsetForIndex(index, align),
3954
+ _toOffset = _this$getOffsetForInd2[0];
3955
+ if (!approxEqual(_toOffset, _this.scrollOffset)) {
3956
+ _this.scrollToIndex(index, {
3957
+ align: align,
3958
+ behavior: behavior
3959
+ });
3960
+ }
3961
+ } else {
3962
+ _this.scrollToIndex(index, {
3963
+ align: align,
3964
+ behavior: behavior
3965
+ });
3966
+ }
3967
+ });
3968
+ }
3969
+ };
3970
+ this.scrollBy = function (delta, _temp3) {
3971
+ var _ref7 = _temp3 === void 0 ? {} : _temp3,
3972
+ behavior = _ref7.behavior;
3973
+ _this.cancelScrollToIndex();
3974
+ if (behavior === 'smooth' && _this.isDynamicMode()) {
3975
+ console.warn('The `smooth` scroll behavior is not fully supported with dynamic size.');
3976
+ }
3977
+ _this._scrollToOffset(_this.scrollOffset + delta, {
3978
+ adjustments: undefined,
3979
+ behavior: behavior
3980
+ });
3981
+ };
3982
+ this.getTotalSize = function () {
3983
+ var _this$getMeasurements;
3984
+ return (((_this$getMeasurements = _this.getMeasurements()[_this.options.count - 1]) == null ? void 0 : _this$getMeasurements.end) || _this.options.paddingStart) - _this.options.scrollMargin + _this.options.paddingEnd;
3985
+ };
3986
+ this._scrollToOffset = function (offset, _ref8) {
3987
+ var adjustments = _ref8.adjustments,
3988
+ behavior = _ref8.behavior;
3989
+ _this.options.scrollToFn(offset, {
3990
+ behavior: behavior,
3991
+ adjustments: adjustments
3992
+ }, _this);
3993
+ };
3994
+ this.measure = function () {
3995
+ _this.itemSizeCache = new Map();
3996
+ _this.notify(false);
3997
+ };
3998
+ this.setOptions(_opts);
3999
+ this.scrollRect = this.options.initialRect;
4000
+ this.scrollOffset = this.options.initialOffset;
4001
+ this.measurementsCache = this.options.initialMeasurementsCache;
4002
+ this.measurementsCache.forEach(function (item) {
4003
+ _this.itemSizeCache.set(item.key, item.size);
4004
+ });
4005
+ this.maybeNotify();
3806
4006
  };
3807
-
3808
4007
  var findNearestBinarySearch = function findNearestBinarySearch(low, high, getCurrentValue, value) {
3809
4008
  while (low <= high) {
3810
4009
  var middle = (low + high) / 2 | 0;
3811
4010
  var currentValue = getCurrentValue(middle);
3812
-
3813
4011
  if (currentValue < value) {
3814
4012
  low = middle + 1;
3815
4013
  } else if (currentValue > value) {
@@ -3818,37 +4016,80 @@ var findNearestBinarySearch = function findNearestBinarySearch(low, high, getCur
3818
4016
  return middle;
3819
4017
  }
3820
4018
  }
3821
-
3822
4019
  if (low > 0) {
3823
4020
  return low - 1;
3824
4021
  } else {
3825
4022
  return 0;
3826
4023
  }
3827
4024
  };
3828
-
3829
- function calculateRange(_ref4) {
3830
- var measurements = _ref4.measurements,
3831
- outerSize = _ref4.outerSize,
3832
- scrollOffset = _ref4.scrollOffset;
3833
- var size = measurements.length - 1;
3834
-
4025
+ function calculateRange(_ref9) {
4026
+ var measurements = _ref9.measurements,
4027
+ outerSize = _ref9.outerSize,
4028
+ scrollOffset = _ref9.scrollOffset;
4029
+ var count = measurements.length - 1;
3835
4030
  var getOffset = function getOffset(index) {
3836
4031
  return measurements[index].start;
3837
4032
  };
3838
-
3839
- var start = findNearestBinarySearch(0, size, getOffset, scrollOffset);
3840
- var end = start;
3841
-
3842
- while (end < size && measurements[end].end < scrollOffset + outerSize) {
3843
- end++;
4033
+ var startIndex = findNearestBinarySearch(0, count, getOffset, scrollOffset);
4034
+ var endIndex = startIndex;
4035
+ while (endIndex < count && measurements[endIndex].end < scrollOffset + outerSize) {
4036
+ endIndex++;
3844
4037
  }
3845
-
3846
4038
  return {
3847
- start: start,
3848
- end: end
4039
+ startIndex: startIndex,
4040
+ endIndex: endIndex
3849
4041
  };
3850
4042
  }
3851
4043
 
4044
+ /**
4045
+ * react-virtual
4046
+ *
4047
+ * Copyright (c) TanStack
4048
+ *
4049
+ * This source code is licensed under the MIT license found in the
4050
+ * LICENSE.md file in the root directory of this source tree.
4051
+ *
4052
+ * @license MIT
4053
+ */
4054
+
4055
+ //
4056
+
4057
+ var useIsomorphicLayoutEffect$1 = typeof document !== 'undefined' ? React.useLayoutEffect : React.useEffect;
4058
+ function useVirtualizerBase(options) {
4059
+ var rerender = React.useReducer(function () {
4060
+ return {};
4061
+ }, {})[1];
4062
+ var resolvedOptions = _extends$1({}, options, {
4063
+ onChange: function onChange(instance, sync) {
4064
+ if (sync) {
4065
+ flushSync(rerender);
4066
+ } else {
4067
+ rerender();
4068
+ }
4069
+ options.onChange == null ? void 0 : options.onChange(instance, sync);
4070
+ }
4071
+ });
4072
+ var _React$useState = React.useState(function () {
4073
+ return new Virtualizer(resolvedOptions);
4074
+ }),
4075
+ instance = _React$useState[0];
4076
+ instance.setOptions(resolvedOptions);
4077
+ React.useEffect(function () {
4078
+ return instance._didMount();
4079
+ }, []);
4080
+ useIsomorphicLayoutEffect$1(function () {
4081
+ return instance._willUpdate();
4082
+ });
4083
+ return instance;
4084
+ }
4085
+ function useVirtualizer(options) {
4086
+ return useVirtualizerBase(_extends$1({
4087
+ observeElementRect: observeElementRect,
4088
+ observeElementOffset: observeElementOffset,
4089
+ scrollToFn: elementScroll
4090
+ }, options));
4091
+ }
4092
+
3852
4093
  /**
3853
4094
  * Custom hook for implementing infinite scrolling in a table.
3854
4095
  *
@@ -3866,7 +4107,6 @@ function calculateRange(_ref4) {
3866
4107
  * });
3867
4108
  */
3868
4109
  const useInfiniteScroll = (props) => {
3869
- var _a, _b;
3870
4110
  //called on scroll and possibly on mount to fetch more data as the user scrolls and reaches bottom of table
3871
4111
  const fetchMoreOnBottomReached = useCallback((containerRefElement) => {
3872
4112
  var _a;
@@ -3880,21 +4120,23 @@ const useInfiniteScroll = (props) => {
3880
4120
  }
3881
4121
  }
3882
4122
  }, [props.pagination]);
3883
- //Virtualizing is optional, but might be necessary if we are going to potentially have hundreds or thousands of rows
3884
- const rowVirtualizer = useVirtual({
3885
- parentRef: props.containerRef,
3886
- size: props.rowSize,
4123
+ const rowVirtualizer = useVirtualizer({
4124
+ count: props.rowSize,
4125
+ getScrollElement: () => props.containerRef.current,
4126
+ estimateSize: useCallback((i) => props.rowHeight, [props.rowHeight]),
3887
4127
  overscan: 10,
3888
4128
  });
3889
- const { virtualItems: virtualRows, totalSize } = rowVirtualizer;
3890
- const paddingTop = virtualRows.length > 0 ? ((_a = virtualRows === null || virtualRows === void 0 ? void 0 : virtualRows[0]) === null || _a === void 0 ? void 0 : _a.start) || 0 : 0;
3891
- const paddingBottom = virtualRows.length > 0 ? totalSize - (((_b = virtualRows === null || virtualRows === void 0 ? void 0 : virtualRows[virtualRows.length - 1]) === null || _b === void 0 ? void 0 : _b.end) || 0) : 0;
4129
+ useEffect(() => {
4130
+ // this ensures the cache is cleared if the rowHeight changes
4131
+ if (props.rowHeight) {
4132
+ rowVirtualizer.measure();
4133
+ }
4134
+ }, [props.rowHeight, rowVirtualizer]);
4135
+ const { getVirtualItems, getTotalSize } = rowVirtualizer;
3892
4136
  return {
3893
- paddingTop,
3894
- paddingBottom,
3895
4137
  fetchMoreOnBottomReached,
3896
- rowVirtualizer,
3897
- virtualRows,
4138
+ getTotalSize,
4139
+ getVirtualItems,
3898
4140
  };
3899
4141
  };
3900
4142
 
@@ -3905,19 +4147,23 @@ const useInfiniteScroll = (props) => {
3905
4147
  * @returns {JSX.Element} Table component
3906
4148
  */
3907
4149
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
3908
- const Table = (props) => {
3909
- var _a, _b;
4150
+ const Table = (_a) => {
4151
+ var _b, _c;
4152
+ var { rowHeight = 75 } = _a, props = __rest(_a, ["rowHeight"]);
3910
4153
  //we need a reference to the scrolling element for logic down below
3911
4154
  const tableContainerRef = useRef(null);
3912
4155
  const [t] = useTranslation();
3913
- const { fetchMoreOnBottomReached, virtualRows, paddingTop, paddingBottom } = useInfiniteScroll({
4156
+ const { fetchMoreOnBottomReached, getVirtualItems, getTotalSize } = useInfiniteScroll({
3914
4157
  pagination: props.pagination,
3915
4158
  containerRef: tableContainerRef,
3916
4159
  rowSize: props.getRowModel().rows.length || 0,
4160
+ rowHeight,
3917
4161
  });
3918
4162
  const hasResults = props.getRowModel().rows.length > 0;
3919
- return (jsxs(Card, { className: `flex flex-col overflow-hidden ${props.className || ""}`, dataTestId: props.dataTestId, children: [(props.headerLeftActions || props.headerRightActions) && (jsxs("div", { className: "z-default flex justify-between gap-2 p-2", children: [jsx("div", { className: "flex", children: props.headerLeftActions }), jsx("div", { className: "flex", children: props.headerRightActions })] })), jsx("div", { className: "min-h[500px] h-full overflow-x-auto overflow-y-scroll border-b border-t border-gray-300", onScroll: e => fetchMoreOnBottomReached(e.target), ref: tableContainerRef, children: jsxs(TableRoot, { style: {
3920
- width: props.getCenterTotalSize(),
4163
+ return (jsxs(Card, { className: `flex flex-col overflow-hidden ${props.className || ""}`, dataTestId: props.dataTestId, children: [(props.headerLeftActions || props.headerRightActions) && (jsxs("div", { className: "z-default flex justify-between gap-2 p-2", children: [jsx("div", { className: "flex", children: props.headerLeftActions }), jsx("div", { className: "flex", children: props.headerRightActions })] })), jsx("div", { className: "min-h[500px] h-full overflow-x-auto overflow-y-scroll border-b border-t border-gray-300", ref: tableContainerRef, onScroll: e => fetchMoreOnBottomReached(e.target), children: jsxs(TableRoot, { style: {
4164
+ height: getTotalSize(),
4165
+ width: "100%",
4166
+ position: "relative",
3921
4167
  }, children: [jsx(Thead, { className: "z-default", children: props.getHeaderGroups().map(headerGroup => (jsx(Tr, { className: "flex", children: headerGroup.headers.map(header => {
3922
4168
  var _a, _b, _c, _d;
3923
4169
  return (jsxs(Th, { style: {
@@ -3926,25 +4172,28 @@ const Table = (props) => {
3926
4172
  maxWidth: header.column.columnDef.maxSize,
3927
4173
  }, className: "relative", children: [header.isPlaceholder ? null : (jsxs("div", { className: `${header.column.getCanSort() ? "cursor-pointer select-none" : ""} flex items-center gap-2 py-2 overflow-hidden pr-3`,
3928
4174
  onClick: header.column.getToggleSortingHandler(), children: [jsxs("span", { className: "overflow-hidden text-ellipsis whitespace-nowrap", children: [flexRender(header.column.columnDef.header, header.getContext()), ((_b = (_a = header.column.columnDef) === null || _a === void 0 ? void 0 : _a.meta) === null || _b === void 0 ? void 0 : _b.subHeader) ? (jsx(Text, { size: "small", subtle: true, children: (_d = (_c = header.column.columnDef) === null || _c === void 0 ? void 0 : _c.meta) === null || _d === void 0 ? void 0 : _d.subHeader })) : null] }), header.column.getCanSort() ? (jsx(SortIndicator, { sortingState: header.column.getIsSorted() })) : null] })), header.column.getCanResize() ? (jsx(ResizeHandle, { isResizing: header.column.getIsResizing(), onMouseDown: header.getResizeHandler(), onTouchStart: header.getResizeHandler() })) : null] }, header.id));
3929
- }) }, headerGroup.id))) }), hasResults ? (jsxs(Tbody, { className: "text-sm font-normal", children: [paddingTop > 0 && (jsx(Tr, { layout: "flex", children: jsx(Td, { style: { height: `${paddingTop}px` } }) })), virtualRows.map(virtualRow => {
3930
- const row = props.getRowModel().rows[virtualRow.index];
3931
- if (!row) {
3932
- return null;
3933
- }
3934
- else {
3935
- return (jsx(Tr, { layout: "flex", onClick: () => (props.onRowClick ? props.onRowClick(row) : row.getToggleSelectedHandler()), className: `${(props.onRowClick || row.getCanSelect()) && "cursor-pointer"} hover:bg-neutral-100`, dataTestId: `table-body-row-${virtualRow.index}`, children: row === null || row === void 0 ? void 0 : row.getVisibleCells().map(cell => {
3936
- return (jsx(Td, { key: cell.id,
3937
- style: {
3938
- width: cell.column.getSize(),
3939
- minWidth: cell.column.columnDef.minSize,
3940
- maxWidth: cell.column.columnDef.maxSize,
3941
- }, children: jsx("div", { className: "grid h-full items-center", children: flexRender(cell.column.columnDef.cell, cell.getContext()) }) }));
3942
- }) }, row.id));
3943
- }
3944
- }), paddingBottom > 0 && (jsx(Tr, { layout: "flex", children: jsx(Td, { style: { height: `${paddingBottom}px` } }) }))] })) : (jsx("tbody", { children: jsx("tr", { children: jsx("td", { className: "b-0", children: (props === null || props === void 0 ? void 0 : props.noDataMessage) ? (props.noDataMessage) : (jsx(EmptyState, { image: "ROAD_BLOCK", description: t("table.noResults"), className: "absolute inset-0", loading: props === null || props === void 0 ? void 0 : props.loading })) }) }) }))] }) }), jsxs("div", { className: "flex items-center p-2", children: [jsx("div", { className: "whitespace-nowrap text-xs font-medium text-neutral-600", children: t("table.pagination.full", {
4175
+ }) }, headerGroup.id))) }), hasResults ? (jsx(Tbody, { className: "text-sm font-normal", children: getVirtualItems().map((virtualRow, index) => {
4176
+ const row = props.getRowModel().rows[virtualRow.index];
4177
+ if (!row) {
4178
+ return null;
4179
+ }
4180
+ else {
4181
+ return (jsx(Tr, { layout: "flex", style: {
4182
+ height: `${virtualRow.size}px`,
4183
+ transform: `translateY(${virtualRow.start - index * virtualRow.size}px)`,
4184
+ }, onClick: () => (props.onRowClick ? props.onRowClick(row) : row.getToggleSelectedHandler()), className: `${(props.onRowClick || row.getCanSelect()) && "cursor-pointer"} hover:bg-neutral-100`, dataTestId: `table-body-row-${virtualRow.index}`, children: row === null || row === void 0 ? void 0 : row.getVisibleCells().map(cell => {
4185
+ return (jsx(Td, { key: cell.id,
4186
+ style: {
4187
+ width: cell.column.getSize(),
4188
+ minWidth: cell.column.columnDef.minSize,
4189
+ maxWidth: cell.column.columnDef.maxSize,
4190
+ }, children: jsx("div", { className: "grid h-full items-center", children: flexRender(cell.column.columnDef.cell, cell.getContext()) }) }));
4191
+ }) }, row.id));
4192
+ }
4193
+ }) })) : (jsx("tbody", { children: jsx("tr", { children: jsx("td", { className: "b-0", children: (props === null || props === void 0 ? void 0 : props.noDataMessage) ? (props.noDataMessage) : (jsx(EmptyState, { image: "ROAD_BLOCK", description: t("table.noResults"), className: "absolute inset-0", loading: props === null || props === void 0 ? void 0 : props.loading })) }) }) }))] }) }), jsxs("div", { className: "flex items-center p-2", children: [jsx("div", { className: "whitespace-nowrap text-xs font-medium text-neutral-600", children: t("table.pagination.full", {
3945
4194
  count: props.getRowModel().rows.length,
3946
- total: ((_b = (_a = props.pagination) === null || _a === void 0 ? void 0 : _a.pageInfo) === null || _b === void 0 ? void 0 : _b.count) || 0,
3947
- }) }), props.footerRightActions && jsx("div", { className: "flex flex-1 justify-end", children: props.footerRightActions })] })] }));
4195
+ total: ((_c = (_b = props.pagination) === null || _b === void 0 ? void 0 : _b.pageInfo) === null || _c === void 0 ? void 0 : _c.count) || 0,
4196
+ }) }), props.pagination.isLoading ? (jsx("span", { className: "ml-2", children: jsx(Spinner, { size: "small" }) })) : null, props.footerRightActions && jsx("div", { className: "flex flex-1 justify-end", children: props.footerRightActions })] })] }));
3948
4197
  };
3949
4198
 
3950
4199
  function getDefaultExportFromCjs (x) {
@@ -6273,7 +6522,7 @@ var INSTANCE_SYM = Symbol.for('__REACT_DND_CONTEXT_INSTANCE__');
6273
6522
  * A React component that provides the React-DnD context
6274
6523
  */
6275
6524
 
6276
- var DndProvider = memo$1(function DndProvider(_ref) {
6525
+ var DndProvider = memo$2(function DndProvider(_ref) {
6277
6526
  var children = _ref.children,
6278
6527
  props = _objectWithoutProperties(_ref, _excluded);
6279
6528