@economic/taco 2.48.4 → 2.49.0-dataloader.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (90) hide show
  1. package/dist/components/Report/Report.d.ts +1 -1
  2. package/dist/components/SearchInput2/SearchInput2.d.ts +2 -0
  3. package/dist/components/Table3/features/useEditingState.d.ts +13 -13
  4. package/dist/components/Table3/features/useTableEditing.d.ts +15 -15
  5. package/dist/components/Table3/types.d.ts +2 -0
  6. package/dist/esm/packages/taco/src/charts/components/Donut/Legend.js +1 -0
  7. package/dist/esm/packages/taco/src/charts/components/Donut/Legend.js.map +1 -1
  8. package/dist/esm/packages/taco/src/charts/components/Legend.js +1 -0
  9. package/dist/esm/packages/taco/src/charts/components/Legend.js.map +1 -1
  10. package/dist/esm/packages/taco/src/components/SearchInput2/SearchInput2.js +6 -3
  11. package/dist/esm/packages/taco/src/components/SearchInput2/SearchInput2.js.map +1 -1
  12. package/dist/esm/packages/taco/src/components/Table/hooks/plugins/useRowActions.js +1 -1
  13. package/dist/esm/packages/taco/src/components/Table3/components/Columns/Cell/EditingControlCell.js +1 -1
  14. package/dist/esm/packages/taco/src/components/Table3/components/Columns/Cell/EditingControlCell.js.map +1 -1
  15. package/dist/esm/packages/taco/src/components/Table3/components/Editing/Alert.js +15 -9
  16. package/dist/esm/packages/taco/src/components/Table3/components/Editing/Alert.js.map +1 -1
  17. package/dist/esm/packages/taco/src/components/Table3/components/Row/Editing/CreateNewRow.js +4 -2
  18. package/dist/esm/packages/taco/src/components/Table3/components/Row/Editing/CreateNewRow.js.map +1 -1
  19. package/dist/esm/packages/taco/src/components/Table3/components/Row/Editing/TemporaryRow.js +3 -2
  20. package/dist/esm/packages/taco/src/components/Table3/components/Row/Editing/TemporaryRow.js.map +1 -1
  21. package/dist/esm/packages/taco/src/components/Table3/features/useEditingState.js +61 -69
  22. package/dist/esm/packages/taco/src/components/Table3/features/useEditingState.js.map +1 -1
  23. package/dist/esm/packages/taco/src/components/Table3/features/useTableEditing.js +13 -6
  24. package/dist/esm/packages/taco/src/components/Table3/features/useTableEditing.js.map +1 -1
  25. package/dist/esm/packages/taco/src/components/Table3/listeners/useTableEditingListener.js +15 -12
  26. package/dist/esm/packages/taco/src/components/Table3/listeners/useTableEditingListener.js.map +1 -1
  27. package/dist/esm/packages/taco/src/components/Table3/useTable3.js +1 -1
  28. package/dist/esm/packages/taco/src/components/Table3/useTable3.js.map +1 -1
  29. package/dist/esm/packages/taco/src/index.js +1 -0
  30. package/dist/esm/packages/taco/src/index.js.map +1 -1
  31. package/dist/esm/packages/taco/src/primitives/Table/Core/components/Columns/Internal/Selection.js +7 -4
  32. package/dist/esm/packages/taco/src/primitives/Table/Core/components/Columns/Internal/Selection.js.map +1 -1
  33. package/dist/esm/packages/taco/src/primitives/Table/Core/components/Footer/Summary.js +7 -6
  34. package/dist/esm/packages/taco/src/primitives/Table/Core/components/Footer/Summary.js.map +1 -1
  35. package/dist/esm/packages/taco/src/primitives/Table/Core/components/Row/BuiltIns/SkeletonRow.js +24 -22
  36. package/dist/esm/packages/taco/src/primitives/Table/Core/components/Row/BuiltIns/SkeletonRow.js.map +1 -1
  37. package/dist/esm/packages/taco/src/primitives/Table/Core/components/Row/Row.js +41 -4
  38. package/dist/esm/packages/taco/src/primitives/Table/Core/components/Row/Row.js.map +1 -1
  39. package/dist/esm/packages/taco/src/primitives/Table/Core/components/Toolbar/components/Print/Print.js +3 -1
  40. package/dist/esm/packages/taco/src/primitives/Table/Core/components/Toolbar/components/Print/Print.js.map +1 -1
  41. package/dist/esm/packages/taco/src/primitives/Table/Core/components/Toolbar/components/Search/Search.js +26 -3
  42. package/dist/esm/packages/taco/src/primitives/Table/Core/components/Toolbar/components/Search/Search.js.map +1 -1
  43. package/dist/esm/packages/taco/src/primitives/Table/Core/features/useTableGlobalShortcuts.js +2 -2
  44. package/dist/esm/packages/taco/src/primitives/Table/Core/features/useTableGlobalShortcuts.js.map +1 -1
  45. package/dist/esm/packages/taco/src/primitives/Table/Core/features/useTableRenderer.js +40 -13
  46. package/dist/esm/packages/taco/src/primitives/Table/Core/features/useTableRenderer.js.map +1 -1
  47. package/dist/esm/packages/taco/src/primitives/Table/Core/useTable.js +1 -1
  48. package/dist/esm/packages/taco/src/primitives/Table/Core/useTable.js.map +1 -1
  49. package/dist/esm/packages/taco/src/primitives/Table/types.js.map +1 -1
  50. package/dist/esm/packages/taco/src/primitives/Table/useTableDataLoader.js +13 -12
  51. package/dist/esm/packages/taco/src/primitives/Table/useTableDataLoader.js.map +1 -1
  52. package/dist/esm/packages/taco/src/primitives/Table/useTableDataLoader2.js +223 -0
  53. package/dist/esm/packages/taco/src/primitives/Table/useTableDataLoader2.js.map +1 -0
  54. package/dist/esm/packages/taco/src/primitives/Table/useTableManager/features/useTableRowActive.js +1 -1
  55. package/dist/esm/packages/taco/src/primitives/Table/useTableManager/features/useTableRowActive.js.map +1 -1
  56. package/dist/esm/packages/taco/src/primitives/Table/useTableManager/features/useTableSearch.js +3 -2
  57. package/dist/esm/packages/taco/src/primitives/Table/useTableManager/features/useTableSearch.js.map +1 -1
  58. package/dist/esm/packages/taco/src/primitives/Table/useTableManager/features/useTableServerLoading.js +8 -3
  59. package/dist/esm/packages/taco/src/primitives/Table/useTableManager/features/useTableServerLoading.js.map +1 -1
  60. package/dist/esm/packages/taco/src/primitives/Table/useTableManager/listeners/useTableFilterListener.js +3 -1
  61. package/dist/esm/packages/taco/src/primitives/Table/useTableManager/listeners/useTableFilterListener.js.map +1 -1
  62. package/dist/esm/packages/taco/src/primitives/Table/useTableManager/listeners/useTableRowSelectionListener.js +4 -4
  63. package/dist/esm/packages/taco/src/primitives/Table/useTableManager/listeners/useTableRowSelectionListener.js.map +1 -1
  64. package/dist/esm/packages/taco/src/primitives/Table/useTableManager/listeners/useTableSearchListener.js +14 -13
  65. package/dist/esm/packages/taco/src/primitives/Table/useTableManager/listeners/useTableSearchListener.js.map +1 -1
  66. package/dist/esm/packages/taco/src/primitives/Table/useTableManager/listeners/useTableServerLoadingListener.js +7 -3
  67. package/dist/esm/packages/taco/src/primitives/Table/useTableManager/listeners/useTableServerLoadingListener.js.map +1 -1
  68. package/dist/esm/packages/taco/src/primitives/Table/useTableManager/useTableManager.js +3 -3
  69. package/dist/esm/packages/taco/src/primitives/Table/useTableManager/useTableManager.js.map +1 -1
  70. package/dist/esm/packages/taco/src/primitives/Table/useTableManager/util/columns.js +4 -1
  71. package/dist/esm/packages/taco/src/primitives/Table/useTableManager/util/columns.js.map +1 -1
  72. package/dist/esm/packages/taco/src/primitives/Table/useTableManager/util/setup.js +8 -1
  73. package/dist/esm/packages/taco/src/primitives/Table/useTableManager/util/setup.js.map +1 -1
  74. package/dist/hooks/useLazyDebouncedEffect.d.ts +2 -0
  75. package/dist/index.d.ts +1 -0
  76. package/dist/primitives/Table/Core/components/Row/BuiltIns/SkeletonRow.d.ts +2 -2
  77. package/dist/primitives/Table/Core/components/Row/Row.d.ts +2 -0
  78. package/dist/primitives/Table/Core/features/useTableRenderer.d.ts +1 -1
  79. package/dist/primitives/Table/types.d.ts +10 -6
  80. package/dist/primitives/Table/useTableDataLoader.d.ts +2 -2
  81. package/dist/primitives/Table/useTableDataLoader2.d.ts +23 -0
  82. package/dist/primitives/Table/useTableManager/features/useTableSearch.d.ts +4 -2
  83. package/dist/primitives/Table/useTableManager/features/useTableServerLoading.d.ts +4 -1
  84. package/dist/primitives/Table/useTableManager/listeners/useTableSearchListener.d.ts +1 -2
  85. package/dist/primitives/Table/useTableManager/util/columns.d.ts +2 -1
  86. package/dist/taco.cjs.development.js +577 -233
  87. package/dist/taco.cjs.development.js.map +1 -1
  88. package/dist/taco.cjs.production.min.js +1 -1
  89. package/dist/taco.cjs.production.min.js.map +1 -1
  90. package/package.json +2 -2
@@ -31,12 +31,12 @@ var reactPortal = require('@radix-ui/react-portal');
31
31
  var reactTable = require('@tanstack/react-table');
32
32
  var get = _interopDefault(require('lodash/get'));
33
33
  var reactVirtual = require('@tanstack/react-virtual');
34
- var reactIntersectionObserver = require('react-intersection-observer');
35
34
  var core = require('@dnd-kit/core');
36
35
  var modifiers = require('@dnd-kit/modifiers');
37
36
  var SortablePrimitive = require('@dnd-kit/sortable');
38
37
  var utilities = require('@dnd-kit/utilities');
39
38
  var reactTable$1 = require('react-table');
39
+ var reactIntersectionObserver = require('react-intersection-observer');
40
40
  var reactWindow = require('react-window');
41
41
  var InfiniteLoader = _interopDefault(require('react-window-infinite-loader'));
42
42
  var set = _interopDefault(require('lodash/set'));
@@ -10318,6 +10318,9 @@ function unfreezeAllExternalColumns(leftPinnedState) {
10318
10318
  function freezeUptoExternalColumn(index, columns) {
10319
10319
  return columns.slice(0, index + 1);
10320
10320
  }
10321
+ function getHiddenColumns(columnVisibility = {}) {
10322
+ return Object.keys(columnVisibility).filter(c => columnVisibility[c] === false);
10323
+ }
10321
10324
 
10322
10325
  function getSettings(table) {
10323
10326
  const meta = table.options.meta;
@@ -10582,7 +10585,8 @@ function configureReactTableOptions(options, props, localization) {
10582
10585
  getExpandedRowModel: reactTable.getExpandedRowModel(),
10583
10586
  getGroupedRowModel: reactTable.getGroupedRowModel(),
10584
10587
  getRowId,
10585
- groupedColumnMode: false
10588
+ groupedColumnMode: false,
10589
+ keepPinnedRows: false
10586
10590
  };
10587
10591
  if (tableOptions.enableColumnResizing) {
10588
10592
  tableOptions.columnResizeMode = 'onChange';
@@ -10604,6 +10608,12 @@ function configureReactTableOptions(options, props, localization) {
10604
10608
  var _column$columnDef$met;
10605
10609
  return ((_column$columnDef$met = column.columnDef.meta) === null || _column$columnDef$met === void 0 ? void 0 : _column$columnDef$met.enableSearch) !== false && column.getIsVisible();
10606
10610
  };
10611
+ // enter controlled search mode (controlled could be local state, but usually the server)
10612
+ if (props.onChangeSearch) {
10613
+ if (props._experimentalDataLoader2) {
10614
+ tableOptions.manualFiltering = true;
10615
+ }
10616
+ }
10607
10617
  }
10608
10618
  if (tableOptions.enableSorting) {
10609
10619
  // enter controlled sort mode (controlled could be local state, but usually the server)
@@ -10987,7 +10997,7 @@ function useTableRowActive(isEnabled = false, initialRowActiveIndex) {
10987
10997
  return index;
10988
10998
  });
10989
10999
  }
10990
- }, [rowActiveIndex, length, isEnabled]);
11000
+ }, [rowActiveIndex, isEnabled]);
10991
11001
  return {
10992
11002
  isEnabled,
10993
11003
  rowActiveIndex,
@@ -11103,7 +11113,7 @@ function useTableRowSelection(isEnabled = false) {
11103
11113
  - Highlighting search results, this is custom and only uses the state part of globalFilter (to store the search query)
11104
11114
  - Filtering of results, this is essentially the built in filtering, and relies on enableGlobalFilter being on or off
11105
11115
  */
11106
- function useTableSearch(isEnabled = false, defaultEnableGlobalFilter = false) {
11116
+ function useTableSearch(isEnabled = false, onChangeSearch, defaultEnableGlobalFilter = false) {
11107
11117
  const [enableGlobalFilter, _setEnableGlobalFilter] = React__default.useState(defaultEnableGlobalFilter);
11108
11118
  function setEnableGlobalFilter(enabled, instance) {
11109
11119
  _setEnableGlobalFilter(enabled);
@@ -11128,7 +11138,8 @@ function useTableSearch(isEnabled = false, defaultEnableGlobalFilter = false) {
11128
11138
  highlightedColumnIndexes,
11129
11139
  setHighlightedColumnIndexes,
11130
11140
  currentHighlightColumnIndex,
11131
- setCurrentHighlightColumnIndex
11141
+ setCurrentHighlightColumnIndex,
11142
+ handleSearch: isEnabled && typeof onChangeSearch === 'function' ? onChangeSearch : undefined
11132
11143
  };
11133
11144
  }
11134
11145
 
@@ -11338,9 +11349,10 @@ function useTableDataLoader(fetchPage, fetchAll, options = {
11338
11349
  const _lastUsedSorting = React__default.useRef([]);
11339
11350
  const _lastUsedFilters = React__default.useRef([]);
11340
11351
  const _lastUsedSearch = React__default.useRef();
11352
+ const _lastUsedHiddenColumns = React__default.useRef([]);
11341
11353
  const _lastUsedPageIndex = React__default.useRef();
11342
11354
  const _forceReset = React__default.useRef(false);
11343
- const loadPage = function (pageIndex, sorting, filters) {
11355
+ const loadPage = function (pageIndex, sorting, filters, hiddenColumns) {
11344
11356
  try {
11345
11357
  let reset = false;
11346
11358
  // sorting or filters changed, reset everything
@@ -11362,9 +11374,10 @@ function useTableDataLoader(fetchPage, fetchAll, options = {
11362
11374
  _lastUsedSorting.current = sorting;
11363
11375
  // set the filters so we can track if it changed between loads
11364
11376
  _lastUsedFilters.current = filters;
11377
+ _lastUsedHiddenColumns.current = hiddenColumns;
11365
11378
  const _temp = _finallyRethrows(function () {
11366
11379
  return _catch(function () {
11367
- return Promise.resolve(fetchPage(pageIndex, pageSize, sorting, filters)).then(function (response) {
11380
+ return Promise.resolve(fetchPage(pageIndex, pageSize, sorting, filters, hiddenColumns)).then(function (response) {
11368
11381
  // update state, here we do some "magic" to support "load in place"
11369
11382
  setData(currentData => {
11370
11383
  let nextData;
@@ -11393,14 +11406,15 @@ function useTableDataLoader(fetchPage, fetchAll, options = {
11393
11406
  return Promise.reject(e);
11394
11407
  }
11395
11408
  };
11396
- const loadAll = function (sorting, filters) {
11409
+ const loadAll = function (sorting, filters, hiddenColumns) {
11397
11410
  try {
11398
11411
  // set the sorting so we can track if it changed between loads
11399
11412
  _lastUsedSorting.current = sorting;
11400
11413
  // set the filters so we can track if it changed between loads
11401
11414
  _lastUsedFilters.current = filters;
11415
+ _lastUsedHiddenColumns.current = hiddenColumns;
11402
11416
  const _temp2 = _catch(function () {
11403
- return Promise.resolve(fetchAll(sorting, filters)).then(function (response) {
11417
+ return Promise.resolve(fetchAll(sorting, filters, hiddenColumns)).then(function (response) {
11404
11418
  length.current = response.length;
11405
11419
  setData(() => {
11406
11420
  let nextData;
@@ -11425,11 +11439,11 @@ function useTableDataLoader(fetchPage, fetchAll, options = {
11425
11439
  _forceReset.current = true;
11426
11440
  if (_lastUsedSearch.current) {
11427
11441
  // we're searching, which means we need to refetch all with the correct sorting applied
11428
- return loadAll(_lastUsedSorting.current, _lastUsedFilters.current);
11442
+ return loadAll(_lastUsedSorting.current, _lastUsedFilters.current, _lastUsedHiddenColumns.current);
11429
11443
  } else {
11430
11444
  var _lastUsedPageIndex$cu;
11431
11445
  // load the last page that we scrolled to
11432
- return loadPage((_lastUsedPageIndex$cu = _lastUsedPageIndex.current) !== null && _lastUsedPageIndex$cu !== void 0 ? _lastUsedPageIndex$cu : 0, _lastUsedSorting.current, _lastUsedFilters.current);
11446
+ return loadPage((_lastUsedPageIndex$cu = _lastUsedPageIndex.current) !== null && _lastUsedPageIndex$cu !== void 0 ? _lastUsedPageIndex$cu : 0, _lastUsedSorting.current, _lastUsedFilters.current, _lastUsedHiddenColumns.current);
11433
11447
  }
11434
11448
  } catch (e) {
11435
11449
  return Promise.reject(e);
@@ -11441,13 +11455,12 @@ function useTableDataLoader(fetchPage, fetchAll, options = {
11441
11455
  try {
11442
11456
  if (_lastUsedSearch.current) {
11443
11457
  // we're searching, which means we need to refetch all with the correct sorting applied
11444
- loadAll(sorting, _lastUsedFilters.current);
11458
+ return loadAll(sorting, _lastUsedFilters.current, _lastUsedHiddenColumns.current);
11445
11459
  } else {
11446
11460
  var _lastUsedPageIndex$cu2;
11447
11461
  // load the last page that we scrolled to
11448
- loadPage((_lastUsedPageIndex$cu2 = _lastUsedPageIndex.current) !== null && _lastUsedPageIndex$cu2 !== void 0 ? _lastUsedPageIndex$cu2 : 0, sorting, _lastUsedFilters.current);
11462
+ return loadPage((_lastUsedPageIndex$cu2 = _lastUsedPageIndex.current) !== null && _lastUsedPageIndex$cu2 !== void 0 ? _lastUsedPageIndex$cu2 : 0, sorting, _lastUsedFilters.current, _lastUsedHiddenColumns.current);
11449
11463
  }
11450
- return Promise.resolve();
11451
11464
  } catch (e) {
11452
11465
  return Promise.reject(e);
11453
11466
  }
@@ -11456,13 +11469,12 @@ function useTableDataLoader(fetchPage, fetchAll, options = {
11456
11469
  try {
11457
11470
  if (_lastUsedSearch.current) {
11458
11471
  // we're searching, which means we need to refetch all with the correct sorting applied
11459
- loadAll(_lastUsedSorting.current, filters);
11472
+ return loadAll(_lastUsedSorting.current, filters, _lastUsedHiddenColumns.current);
11460
11473
  } else {
11461
11474
  var _lastUsedPageIndex$cu3;
11462
11475
  // load the last page that we scrolled to
11463
- loadPage((_lastUsedPageIndex$cu3 = _lastUsedPageIndex.current) !== null && _lastUsedPageIndex$cu3 !== void 0 ? _lastUsedPageIndex$cu3 : 0, _lastUsedSorting.current, filters);
11476
+ return loadPage((_lastUsedPageIndex$cu3 = _lastUsedPageIndex.current) !== null && _lastUsedPageIndex$cu3 !== void 0 ? _lastUsedPageIndex$cu3 : 0, _lastUsedSorting.current, filters, _lastUsedHiddenColumns.current);
11464
11477
  }
11465
- return Promise.resolve();
11466
11478
  } catch (e) {
11467
11479
  return Promise.reject(e);
11468
11480
  }
@@ -11490,12 +11502,13 @@ function useTableDataLoader(fetchPage, fetchAll, options = {
11490
11502
  }, invalidate];
11491
11503
  }
11492
11504
 
11493
- function useTableServerLoading(length, data, loadPage, loadAll, pageSize = DEFAULT_PAGE_SIZE) {
11505
+ function useTableServerLoading(length, data, loadPage, loadAll, pages, pageSize = DEFAULT_PAGE_SIZE, _experimentalDataLoader2 = false) {
11494
11506
  const isEnabled = !!loadPage && !!loadAll;
11495
11507
  const [isReady, setReady] = React__default.useState(false);
11496
11508
  const [loading, setLoading] = React__default.useState(false);
11497
11509
  const hasLoadedAll = React__default.useMemo(() => {
11498
- if (data.length !== length || data.some(x => x === undefined)) {
11510
+ var _data$some;
11511
+ if (data.length !== length || !!((_data$some = data.some) !== null && _data$some !== void 0 && _data$some.call(data, x => x === undefined))) {
11499
11512
  return false;
11500
11513
  }
11501
11514
  return true;
@@ -11550,14 +11563,18 @@ function useTableServerLoading(length, data, loadPage, loadAll, pageSize = DEFAU
11550
11563
  }
11551
11564
  };
11552
11565
  }
11566
+ const pageCount = Math.ceil(length / pageSize);
11553
11567
  return {
11568
+ pages,
11554
11569
  isEnabled,
11555
11570
  isReady,
11556
11571
  loadPage: _loadPage,
11557
11572
  loadAll: _loadAll,
11558
11573
  loadAllIfNeeded: _loadAllIfNeeded,
11559
11574
  loading,
11560
- pageSize
11575
+ pageSize,
11576
+ pageCount,
11577
+ _experimentalDataLoader2
11561
11578
  };
11562
11579
  }
11563
11580
 
@@ -11654,7 +11671,8 @@ function useTableFilterListener(table, onFilter) {
11654
11671
  const columnFilters = table.getState().columnFilters;
11655
11672
  useLazyEffect(() => {
11656
11673
  if (table.options.enableColumnFilters && typeof onFilter === 'function') {
11657
- onFilter(columnFilters);
11674
+ const hiddenColumns = getHiddenColumns(table.getState().columnVisibility);
11675
+ onFilter(columnFilters, hiddenColumns);
11658
11676
  if (table.options.enableRowSelection) {
11659
11677
  table.resetRowSelection();
11660
11678
  }
@@ -11713,11 +11731,12 @@ function useTableRowHeightListener(table) {
11713
11731
  }
11714
11732
 
11715
11733
  function useTableRowSelectionListener(table, onRowSelect) {
11734
+ // note that the selected row model may not contain all rows in state when using server loading
11716
11735
  const rows = table.getSelectedRowModel().flatRows;
11717
- const rowSelection = React__default.useMemo(() => rows.map(row => row.original), [rows]);
11736
+ const state = table.getState().rowSelection;
11718
11737
  useLazyEffect(() => {
11719
11738
  if (table.options.enableRowSelection && typeof onRowSelect === 'function') {
11720
- onRowSelect(rowSelection);
11739
+ onRowSelect(rows.map(row => row.original), Object.keys(state));
11721
11740
  }
11722
11741
  /**
11723
11742
  * Casting to a boolean, since enableRowSelection can be a function,
@@ -11725,33 +11744,33 @@ function useTableRowSelectionListener(table, onRowSelect) {
11725
11744
  * we only need to know if selection was enabled or disabled, because enableRowSelection function
11726
11745
  * will be applied directly to particular rows.
11727
11746
  */
11728
- }, [!!table.options.enableRowSelection, JSON.stringify(rowSelection)]);
11747
+ }, [!!table.options.enableRowSelection, JSON.stringify(state)]);
11729
11748
  }
11730
11749
 
11731
- function useTableSearchListener(table, onChangeSearch) {
11750
+ function useTableSearchListener(table) {
11732
11751
  const meta = table.options.meta;
11733
11752
  const localization = useLocalization();
11734
- const visibleColumns = table.getVisibleFlatColumns();
11753
+ const hiddenColumns = getHiddenColumns(table.getState().columnVisibility);
11754
+ const query = table.getState().globalFilter;
11735
11755
  // Need to re-run search when columns are getting shown/hidden.
11736
- React__default.useEffect(() => {
11737
- if (meta.search.isEnabled && visibleColumns.length > 0) {
11738
- const currentFilter = table.getState().globalFilter;
11756
+ useLazyEffect(() => {
11757
+ if (meta.search.isEnabled) {
11758
+ const currentFilter = query;
11739
11759
  requestAnimationFrame(() => {
11740
11760
  table.resetGlobalFilter();
11741
11761
  table.setGlobalFilter(currentFilter);
11742
11762
  });
11763
+ if (meta.search.handleSearch && meta.search.enableGlobalFilter && query) {
11764
+ meta.search.handleSearch(query, hiddenColumns);
11765
+ }
11743
11766
  }
11744
- }, [visibleColumns.length]);
11767
+ }, [hiddenColumns.length]);
11745
11768
  // recalculates highlighted indexes whenever something important changes
11746
- React__default.useEffect(() => {
11769
+ useLazyEffect(() => {
11747
11770
  if (meta.search.isEnabled) {
11748
- const query = table.getState().globalFilter;
11749
11771
  resetHighlightedColumnIndexes(query, table, localization);
11750
- if (typeof onChangeSearch === 'function') {
11751
- onChangeSearch(query);
11752
- }
11753
11772
  }
11754
- }, [meta.server.loading, meta.search.isEnabled, meta.search.enableGlobalFilter, table.getRowModel().rows.length, table.getState().globalFilter, JSON.stringify(table.getState().sorting), onChangeSearch]);
11773
+ }, [meta.server.loading, meta.search.isEnabled, meta.search.enableGlobalFilter, table.getRowModel().rows.length, query, JSON.stringify(table.getState().sorting)]);
11755
11774
  }
11756
11775
 
11757
11776
  function useTableSettingsListener(table, onChangeSettings) {
@@ -11835,12 +11854,15 @@ function useTableSortingListener(table, onSort) {
11835
11854
  }
11836
11855
 
11837
11856
  function useTableServerLoadingListener(table, loadPage) {
11838
- const sorting = table.getState().sorting;
11839
- const columnFilters = table.getState().columnFilters;
11857
+ const meta = table.options.meta;
11840
11858
  // trigger load of the first page on mount
11841
11859
  React__default.useEffect(() => {
11842
11860
  if (loadPage) {
11843
- loadPage(0, sorting, columnFilters);
11861
+ const sorting = table.getState().sorting;
11862
+ const columnFilters = table.getState().columnFilters;
11863
+ const hiddenColumns = getHiddenColumns(table.getState().columnVisibility);
11864
+ const search = meta.search.enableGlobalFilter ? table.getState().globalFilter : undefined;
11865
+ loadPage(0, sorting, columnFilters, hiddenColumns, search);
11844
11866
  }
11845
11867
  }, []);
11846
11868
  }
@@ -11892,8 +11914,8 @@ function useTableManager(props, meta, internalColumns) {
11892
11914
  const rowGroups = useTableRowGroups(props.rowActionsForGroup);
11893
11915
  const rowHeight = useTableRowHeight(options.enableRowHeight, settings.rowHeight);
11894
11916
  const rowSelection = useTableRowSelection(!!options.enableRowSelection);
11895
- const search = useTableSearch(options.enableSearch, settings.excludeUnmatchedRecordsInSearch);
11896
- const server = useTableServerLoading(length, data, props.loadPage, props.loadAll, props.pageSize);
11917
+ const search = useTableSearch(options.enableSearch, props.onChangeSearch, settings.excludeUnmatchedRecordsInSearch);
11918
+ const server = useTableServerLoading(length, data, props.loadPage, props.loadAll, props.pages, props.pageSize, props._experimentalDataLoader2);
11897
11919
  // TODO: memoise
11898
11920
  // convert jsx column components into valid table columns
11899
11921
  const {
@@ -11944,7 +11966,7 @@ function useTableManager(props, meta, internalColumns) {
11944
11966
  useTableFontSizeListener(instance);
11945
11967
  useTableRowHeightListener(instance);
11946
11968
  useTableRowSelectionListener(instance, props.onRowSelect);
11947
- useTableSearchListener(instance, props.onChangeSearch);
11969
+ useTableSearchListener(instance);
11948
11970
  useTableServerLoadingListener(instance, server.loadPage);
11949
11971
  useTableSettingsListener(instance, setSettings);
11950
11972
  useTableShortcutsListener(instance, props.shortcuts);
@@ -12170,7 +12192,7 @@ function useTableGlobalShortcuts(table, tableRef, scrollToIndex) {
12170
12192
  if (isElementInsideOverlay(trigger) && !isSiblingElementInsideSameParentOverlay(trigger, tableRef.current) || isElementInteractive(trigger) && !isElementInsideOrTriggeredFromContainer(trigger, tableRef.current)) {
12171
12193
  return;
12172
12194
  }
12173
- tableMeta.rowActive.handleKeyDown(event, rows.length, scrollToIndex);
12195
+ tableMeta.rowActive.handleKeyDown(event, tableMeta.length, scrollToIndex);
12174
12196
  tableMeta.rowSelection.handleKeyDown(event, table);
12175
12197
  if (tableMeta.rowActive.rowActiveIndex !== undefined) {
12176
12198
  var _rows$tableMeta$rowAc;
@@ -12183,7 +12205,7 @@ function useTableGlobalShortcuts(table, tableRef, scrollToIndex) {
12183
12205
  };
12184
12206
  },
12185
12207
  // scrollToIndex function changes when row count changes, so it is important to update handlers
12186
- [tableRef.current, tableMeta.rowActive.rowActiveIndex, scrollToIndex]);
12208
+ [tableRef.current, tableMeta.length, tableMeta.rowActive.rowActiveIndex, scrollToIndex]);
12187
12209
  }
12188
12210
 
12189
12211
  function useTableRef(table, ref) {
@@ -12206,57 +12228,131 @@ const ROW_HEIGHT_ESTIMATES = {
12206
12228
  'extra-tall': 57
12207
12229
  };
12208
12230
 
12231
+ const RowContext = /*#__PURE__*/React__default.createContext({
12232
+ hideInternalColumns: false,
12233
+ hideRowActions: false,
12234
+ isHovered: false,
12235
+ rowIndex: -1
12236
+ });
12237
+
12238
+ const DELAY_BEFORE_LOAD_MS = 250;
12239
+ /* anonymous functions will break the memoisation on each render, wrap handlers in callbacks */
12240
+ function Row(props) {
12241
+ const {
12242
+ renderer: RowRenderer,
12243
+ cellRenderer: CellRenderer,
12244
+ hideInternalColumns = false,
12245
+ hideRowActions = false,
12246
+ scrollDirection,
12247
+ skipPageLoading = false,
12248
+ ...displayRowProps
12249
+ } = props;
12250
+ const tableMeta = props.table.options.meta;
12251
+ const isHovered = tableMeta.rowActive.rowHoverIndex === props.index;
12252
+ // context - it must be here for cells to read it, since they render alongside the row inside DisplayRow
12253
+ const contextValue = React__default.useMemo(() => ({
12254
+ isHovered,
12255
+ rowIndex: props.index,
12256
+ hideInternalColumns,
12257
+ hideRowActions
12258
+ }), [isHovered, props.index, hideInternalColumns, hideRowActions]);
12259
+ React__default.useEffect(() => {
12260
+ let timeout;
12261
+ if (tableMeta.server.isEnabled && tableMeta.server._experimentalDataLoader2 && !skipPageLoading) {
12262
+ const pageIndex = Math.floor(props.index / tableMeta.server.pageSize) * tableMeta.server.pageSize / tableMeta.server.pageSize;
12263
+ const sorting = props.table.getState().sorting;
12264
+ const filters = props.table.getState().columnFilters;
12265
+ const search = props.table.getState().globalFilter;
12266
+ const hiddenColumns = getHiddenColumns(props.table.getState().columnVisibility);
12267
+ const pageIndexesToFetch = [];
12268
+ // if there's no direction, it means the scroll bar got dropped un unloaded pages,
12269
+ // in that case, load forward and backward pages to prevent skeletons
12270
+ if (scrollDirection === 'backward' || !scrollDirection) {
12271
+ const backIndex = pageIndex - 1;
12272
+ if (backIndex > -1) {
12273
+ pageIndexesToFetch.push(backIndex);
12274
+ }
12275
+ }
12276
+ // always load the next page
12277
+ if ((scrollDirection === 'forward' || !scrollDirection) && pageIndex + 2 < tableMeta.server.pageCount) {
12278
+ pageIndexesToFetch.push(pageIndex + 1);
12279
+ }
12280
+ if (pageIndexesToFetch.length) {
12281
+ // the virtualiser fetches a page ahead, so this won't get called in most cases
12282
+ // but it provides a fallback for some edge cases
12283
+ timeout = setTimeout(() => {
12284
+ pageIndexesToFetch.forEach(index => {
12285
+ var _tableMeta$server$loa, _tableMeta$server;
12286
+ // this can be called by every row within the current page, but loadPage returns early if a pending request exists
12287
+ (_tableMeta$server$loa = (_tableMeta$server = tableMeta.server).loadPage) === null || _tableMeta$server$loa === void 0 ? void 0 : _tableMeta$server$loa.call(_tableMeta$server, index, sorting, filters, hiddenColumns, tableMeta.search.enableGlobalFilter ? search : undefined);
12288
+ });
12289
+ }, DELAY_BEFORE_LOAD_MS);
12290
+ }
12291
+ }
12292
+ return () => {
12293
+ clearTimeout(timeout);
12294
+ };
12295
+ }, [tableMeta.server.pages]);
12296
+ return /*#__PURE__*/React__default.createElement(RowContext.Provider, {
12297
+ value: contextValue
12298
+ }, /*#__PURE__*/React__default.createElement(RowRenderer, Object.assign({}, displayRowProps, {
12299
+ cellRenderer: CellRenderer
12300
+ })));
12301
+ }
12302
+
12303
+ const DELAY_BEFORE_LOAD_MS$1 = 150;
12209
12304
  function SkeletonRow(props) {
12210
12305
  const {
12211
12306
  index,
12212
- row,
12213
12307
  table
12214
12308
  } = props;
12215
12309
  const tableMeta = table.options.meta;
12216
12310
  if (tableMeta.server.isEnabled) {
12217
- return /*#__PURE__*/React__default.createElement(RowWithServerLoading, Object.assign({}, props, {
12218
- index: index
12219
- }));
12311
+ return /*#__PURE__*/React__default.createElement(RowWithServerLoading, Object.assign({}, props));
12220
12312
  }
12221
12313
  return /*#__PURE__*/React__default.createElement(Skeleton, {
12222
- cellsCount: row.getVisibleCells().length
12314
+ cellsCount: table.getVisibleFlatColumns().length,
12315
+ index: index
12223
12316
  });
12224
12317
  }
12225
12318
  function RowWithServerLoading(props) {
12226
12319
  var _table$getState$group, _table$getState;
12227
12320
  const {
12228
12321
  index,
12229
- row,
12230
12322
  table
12231
12323
  } = props;
12232
12324
  const tableMeta = table.options.meta;
12233
12325
  const pageIndex = Math.floor(index / tableMeta.server.pageSize) * tableMeta.server.pageSize / tableMeta.server.pageSize;
12234
- const {
12235
- ref,
12236
- inView
12237
- } = reactIntersectionObserver.useInView({
12238
- threshold: 0,
12239
- triggerOnce: true,
12240
- initialInView: pageIndex === 0
12241
- });
12242
12326
  React__default.useEffect(() => {
12243
- if (inView) {
12244
- var _tableMeta$server$loa, _tableMeta$server;
12245
- (_tableMeta$server$loa = (_tableMeta$server = tableMeta.server).loadPage) === null || _tableMeta$server$loa === void 0 ? void 0 : _tableMeta$server$loa.call(_tableMeta$server, pageIndex, table.getState().sorting, table.getState().columnFilters);
12327
+ let timeout;
12328
+ if (tableMeta.server.isEnabled) {
12329
+ const sorting = props.table.getState().sorting;
12330
+ const filters = props.table.getState().columnFilters;
12331
+ const search = props.table.getState().globalFilter;
12332
+ const hiddenColumns = getHiddenColumns(props.table.getState().columnVisibility);
12333
+ timeout = setTimeout(() => {
12334
+ var _tableMeta$server$loa, _tableMeta$server;
12335
+ (_tableMeta$server$loa = (_tableMeta$server = tableMeta.server).loadPage) === null || _tableMeta$server$loa === void 0 ? void 0 : _tableMeta$server$loa.call(_tableMeta$server, pageIndex, sorting, filters, hiddenColumns, tableMeta.search.enableGlobalFilter ? search : undefined);
12336
+ }, DELAY_BEFORE_LOAD_MS$1);
12246
12337
  }
12247
- }, [inView]);
12338
+ return () => {
12339
+ clearTimeout(timeout);
12340
+ };
12341
+ }, []);
12248
12342
  const groupedCellCount = (_table$getState$group = (_table$getState = table.getState()) === null || _table$getState === void 0 ? void 0 : _table$getState.grouping.length) !== null && _table$getState$group !== void 0 ? _table$getState$group : 0;
12249
- const ungroupedCellCount = row.getVisibleCells().length - groupedCellCount;
12343
+ const ungroupedCellCount = table.getVisibleFlatColumns().length - groupedCellCount;
12250
12344
  return /*#__PURE__*/React__default.createElement(Skeleton, {
12251
12345
  cellsCount: ungroupedCellCount,
12252
- ref: ref
12346
+ index: index
12253
12347
  });
12254
12348
  }
12255
12349
  const Skeleton = /*#__PURE__*/React__default.forwardRef(function Skeleton(props, ref) {
12256
12350
  const {
12257
- cellsCount
12351
+ cellsCount,
12352
+ index
12258
12353
  } = props;
12259
12354
  return /*#__PURE__*/React__default.createElement("tr", {
12355
+ "data-row-index": index,
12260
12356
  ref: ref
12261
12357
  }, Array(cellsCount).fill(null).map((_, index) => (/*#__PURE__*/React__default.createElement("td", {
12262
12358
  key: index
@@ -12265,41 +12361,6 @@ const Skeleton = /*#__PURE__*/React__default.forwardRef(function Skeleton(props,
12265
12361
  })))));
12266
12362
  });
12267
12363
 
12268
- const RowContext = /*#__PURE__*/React__default.createContext({
12269
- hideInternalColumns: false,
12270
- hideRowActions: false,
12271
- isHovered: false,
12272
- rowIndex: -1
12273
- });
12274
-
12275
- /* anonymous functions will break the memoisation on each render, wrap handlers in callbacks */
12276
- function Row(props) {
12277
- const {
12278
- renderer: RowRenderer,
12279
- cellRenderer: CellRenderer,
12280
- hideInternalColumns = false,
12281
- hideRowActions = false,
12282
- ...displayRowProps
12283
- } = props;
12284
- const tableMeta = props.table.options.meta;
12285
- const isHovered = tableMeta.rowActive.rowHoverIndex === props.index;
12286
- // context - it must be here for cells to read it, since they render alongside the row inside DisplayRow
12287
- const contextValue = React__default.useMemo(() => ({
12288
- isHovered,
12289
- rowIndex: props.index,
12290
- hideInternalColumns,
12291
- hideRowActions
12292
- }), [isHovered, props.index, hideInternalColumns, hideRowActions]);
12293
- if (props.row.original === undefined) {
12294
- return /*#__PURE__*/React__default.createElement(SkeletonRow, Object.assign({}, props));
12295
- }
12296
- return /*#__PURE__*/React__default.createElement(RowContext.Provider, {
12297
- value: contextValue
12298
- }, /*#__PURE__*/React__default.createElement(RowRenderer, Object.assign({}, displayRowProps, {
12299
- cellRenderer: CellRenderer
12300
- })));
12301
- }
12302
-
12303
12364
  // scroll padding end is designed to always show half of the next row
12304
12365
  function getScrollPaddingEndOffset(table) {
12305
12366
  const tableMeta = table.options.meta;
@@ -12324,8 +12385,8 @@ function getPaddingEndOffset(table, options) {
12324
12385
  const bottomRows = (_table$getBottomRows = table.getBottomRows()) !== null && _table$getBottomRows !== void 0 ? _table$getBottomRows : [];
12325
12386
  return ROW_HEIGHT_ESTIMATES.medium * ((_options$virtualiserP = options === null || options === void 0 ? void 0 : options.virtualiserPaddingEndOffset) !== null && _options$virtualiserP !== void 0 ? _options$virtualiserP : 1) * bottomRows.length;
12326
12387
  }
12327
- function useTableRenderer(renderers, table, tableRef, defaultRowActiveIndex, options) {
12328
- var _table$getState$group, _table$getCenterRows, _virtualItems$padding, _virtualItems$padding2, _virtualItems$padding3, _ref, _virtualItems;
12388
+ function useTableRenderer(renderers, table, tableRef, length, defaultRowActiveIndex, options) {
12389
+ var _table$getState$group, _table$getCenterRows, _virtualItems$padding, _virtualItems$padding2, _virtualItems$padding3, _virtualItems$end, _virtualItems;
12329
12390
  const tableMeta = table.options.meta;
12330
12391
  const isTableRowGrouped = !!((_table$getState$group = table.getState().grouping) !== null && _table$getState$group !== void 0 && _table$getState$group.length);
12331
12392
  const rows = (_table$getCenterRows = table.getCenterRows()) !== null && _table$getCenterRows !== void 0 ? _table$getCenterRows : [];
@@ -12338,11 +12399,12 @@ function useTableRenderer(renderers, table, tableRef, defaultRowActiveIndex, opt
12338
12399
  const rangeExtractor = useRowGroupVirtualisation(table);
12339
12400
  // account for thead and tfoot in the scroll area - both are always medium row height
12340
12401
  const scrollPaddingStart = ROW_HEIGHT_ESTIMATES.medium;
12402
+ const count = tableMeta.server.isEnabled && tableMeta.server._experimentalDataLoader2 ? length : rows.length;
12341
12403
  const virtualiser = reactVirtual.useVirtualizer({
12342
- count: rows.length,
12404
+ count,
12343
12405
  estimateSize,
12344
12406
  getScrollElement: () => tableRef.current,
12345
- overscan: tableMeta.printing.isPrinting ? rows.length : undefined,
12407
+ overscan: tableMeta.printing.isPrinting ? count : undefined,
12346
12408
  rangeExtractor,
12347
12409
  // correctly sets the scroll padding offset, e.g. when keyboard navigating rows in the list
12348
12410
  scrollPaddingStart,
@@ -12362,19 +12424,19 @@ function useTableRenderer(renderers, table, tableRef, defaultRowActiveIndex, opt
12362
12424
  if (tableRef.current) {
12363
12425
  if (index === 0) {
12364
12426
  virtualiser.scrollToOffset(0, notSmooth);
12365
- } else if (index === rows.length - 1) {
12427
+ } else if (index === count - 1) {
12366
12428
  // sometimes the last row doesn't fully show, so we just force scroll to the bottom
12367
12429
  tableRef.current.scrollTop = tableRef.current.scrollHeight;
12368
12430
  } else {
12369
12431
  virtualiser.scrollToIndex(index, options);
12370
12432
  }
12371
12433
  }
12372
- }, [virtualItems.length, tableRef.current, totalSize, rows.length]);
12434
+ }, [virtualItems.length, tableRef.current, totalSize, count]);
12373
12435
  // use row 1 not 0, because 0 might be sticky in grouped tables and it's start value will always be 0
12374
- const paddingStartIndex = isTableRowGrouped && rows.length > 1 ? 1 : 0;
12436
+ const paddingStartIndex = isTableRowGrouped && count > 1 ? 1 : 0;
12375
12437
  const startValue = isTableRowGrouped ? ((_virtualItems$padding = virtualItems[paddingStartIndex]) === null || _virtualItems$padding === void 0 ? void 0 : _virtualItems$padding.start) - ((_virtualItems$padding2 = virtualItems[paddingStartIndex]) === null || _virtualItems$padding2 === void 0 ? void 0 : _virtualItems$padding2.size) : (_virtualItems$padding3 = virtualItems[paddingStartIndex]) === null || _virtualItems$padding3 === void 0 ? void 0 : _virtualItems$padding3.start;
12376
12438
  // styling for offsetting rows - this "is" the virtualisation
12377
- const [paddingTop, paddingBottom] = virtualItems.length > 0 ? [Math.max(0, startValue !== null && startValue !== void 0 ? startValue : 0), Math.max(0, (_ref = totalSize - ((_virtualItems = virtualItems[virtualItems.length - 1]) === null || _virtualItems === void 0 ? void 0 : _virtualItems.end)) !== null && _ref !== void 0 ? _ref : 0)] : [0, 0];
12439
+ const [paddingTop, paddingBottom] = virtualItems.length > 0 ? [Math.max(0, startValue !== null && startValue !== void 0 ? startValue : 0), Math.max(0, totalSize - ((_virtualItems$end = (_virtualItems = virtualItems[virtualItems.length - 1]) === null || _virtualItems === void 0 ? void 0 : _virtualItems.end) !== null && _virtualItems$end !== void 0 ? _virtualItems$end : 0))] : [0, 0];
12378
12440
  // ensure default active rows are scrolled to
12379
12441
  React__default.useEffect(() => {
12380
12442
  if (defaultRowActiveIndex) {
@@ -12388,26 +12450,51 @@ function useTableRenderer(renderers, table, tableRef, defaultRowActiveIndex, opt
12388
12450
  let style = {};
12389
12451
  let content = null;
12390
12452
  // bottom rows aren't virtualised (they're sticky) but we need to set the height
12391
- if (rows.length || table.getBottomRows().length) {
12453
+ if (count || table.getBottomRows().length) {
12392
12454
  style = {
12393
12455
  height: totalSize,
12394
- paddingBottom,
12395
- paddingTop
12456
+ paddingBottom: isNaN(paddingBottom) ? 0 : paddingBottom,
12457
+ paddingTop: isNaN(paddingTop) ? 0 : paddingTop
12396
12458
  };
12397
12459
  }
12398
12460
  // only render non sticky rows
12399
- if (rows.length) {
12461
+ if (count) {
12400
12462
  content = virtualItems.map(virtualRow => {
12463
+ var _row, _virtualiser$scrollDi2;
12401
12464
  // there appears to be a react-virtual bug where it inserts a single `undefined` item at the end of the row, which crashes here
12402
12465
  if (!virtualRow) {
12403
12466
  return null;
12404
12467
  }
12405
- const row = rows[virtualRow.index];
12468
+ let row;
12469
+ if (tableMeta.server.isEnabled && tableMeta.server._experimentalDataLoader2) {
12470
+ var _tableMeta$server$pag, _tableMeta$server$pag2;
12471
+ const currentPageIndex = Math.floor(virtualRow.index / tableMeta.server.pageSize) * tableMeta.server.pageSize / tableMeta.server.pageSize;
12472
+ const pagePosition = (_tableMeta$server$pag = (_tableMeta$server$pag2 = tableMeta.server.pages) === null || _tableMeta$server$pag2 === void 0 ? void 0 : _tableMeta$server$pag2.indexOf(currentPageIndex)) !== null && _tableMeta$server$pag !== void 0 ? _tableMeta$server$pag : -1;
12473
+ if (pagePosition > -1) {
12474
+ // "flatten" row indexes down into the dataloader2 dataset size
12475
+ // for example, with a page size of 100...
12476
+ // row index 14267 is actually one of index 67, 167, 267 etc within the dataset (depending on number of pages stored)
12477
+ const fakeIndex = pagePosition * tableMeta.server.pageSize + virtualRow.index % tableMeta.server.pageSize;
12478
+ row = rows[fakeIndex];
12479
+ }
12480
+ } else {
12481
+ row = rows[virtualRow.index];
12482
+ }
12483
+ if (!((_row = row) !== null && _row !== void 0 && _row.original)) {
12484
+ var _virtualiser$scrollDi;
12485
+ return /*#__PURE__*/React__default.createElement(SkeletonRow, {
12486
+ key: virtualRow.index,
12487
+ index: virtualRow.index,
12488
+ scrollDirection: (_virtualiser$scrollDi = virtualiser.scrollDirection) !== null && _virtualiser$scrollDi !== void 0 ? _virtualiser$scrollDi : undefined,
12489
+ table: table
12490
+ });
12491
+ }
12406
12492
  const measureRow = createRowMeasurer(virtualiser.resizeItem, virtualRow);
12407
12493
  return /*#__PURE__*/React__default.createElement(Row, {
12408
12494
  key: row.id,
12409
12495
  row: row,
12410
12496
  index: virtualRow.index,
12497
+ scrollDirection: (_virtualiser$scrollDi2 = virtualiser.scrollDirection) !== null && _virtualiser$scrollDi2 !== void 0 ? _virtualiser$scrollDi2 : undefined,
12411
12498
  table: table,
12412
12499
  measureRow: measureRow,
12413
12500
  renderer: renderers.row,
@@ -12714,8 +12801,9 @@ function Header$4(context) {
12714
12801
  }
12715
12802
  const _temp = function () {
12716
12803
  if (tableMeta.server.loadAllIfNeeded) {
12804
+ const hiddenColumns = getHiddenColumns(table.getState().columnVisibility);
12717
12805
  // don't pass the search query because we need all data - not filtered data
12718
- return Promise.resolve(tableMeta.server.loadAllIfNeeded(table.getState().sorting, table.getState().columnFilters)).then(function () {});
12806
+ return Promise.resolve(tableMeta.server.loadAllIfNeeded(table.getState().sorting, table.getState().columnFilters, hiddenColumns, tableMeta.search.enableGlobalFilter ? table.getState().globalFilter : undefined)).then(function () {});
12719
12807
  }
12720
12808
  }();
12721
12809
  // load all data if that is possible
@@ -12774,6 +12862,7 @@ function Cell$3(context) {
12774
12862
  if (event.shiftKey) {
12775
12863
  var _tableMeta$rowSelecti;
12776
12864
  function _temp4() {
12865
+ const selectedRows = table.getRowModel().rows.slice(fromIndex, toIndex + 1);
12777
12866
  table.setRowSelection(currentRowSelection => ({
12778
12867
  ...currentRowSelection,
12779
12868
  ...selectedRows.filter(row => row.getCanSelect()).reduce((state, row) => ({
@@ -12783,11 +12872,11 @@ function Cell$3(context) {
12783
12872
  }));
12784
12873
  }
12785
12874
  const [fromIndex, toIndex] = toggleBetween((_tableMeta$rowSelecti = tableMeta.rowSelection.lastSelectedRowIndex.current) !== null && _tableMeta$rowSelecti !== void 0 ? _tableMeta$rowSelecti : 0, rowIndex);
12786
- const selectedRows = table.getRowModel().rows.slice(fromIndex, toIndex + 1);
12787
12875
  const _temp3 = function () {
12788
- if (tableMeta.server.loadAllIfNeeded && selectedRows.some(row => row.original === undefined)) {
12876
+ if (tableMeta.server.loadAllIfNeeded) {
12877
+ const hiddenColumns = getHiddenColumns(table.getState().columnVisibility);
12789
12878
  // don't pass the search query because we need all data - not filtered data
12790
- return Promise.resolve(tableMeta.server.loadAllIfNeeded(table.getState().sorting, table.getState().columnFilters)).then(function () {});
12879
+ return Promise.resolve(tableMeta.server.loadAllIfNeeded(table.getState().sorting, table.getState().columnFilters, hiddenColumns, tableMeta.search.enableGlobalFilter ? table.getState().globalFilter : undefined)).then(function () {});
12791
12880
  }
12792
12881
  }();
12793
12882
  return _temp3 && _temp3.then ? _temp3.then(_temp4) : _temp4(_temp3);
@@ -12845,7 +12934,7 @@ function useTable(props, externalRef, renderers, meta, options) {
12845
12934
  // configure the table
12846
12935
  const manager = useTableManager(props, meta, INTERNAL_RENDERERS);
12847
12936
  // configure the virtualised renderer
12848
- const renderer = useTableRenderer(renderers, manager.instance, ref, props.defaultRowActiveIndex, options);
12937
+ const renderer = useTableRenderer(renderers, manager.instance, ref, manager.meta.length, props.defaultRowActiveIndex, options);
12849
12938
  // configure dynamic styling
12850
12939
  const {
12851
12940
  style,
@@ -13913,21 +14002,22 @@ function Summary(props) {
13913
14002
  locale,
13914
14003
  texts
13915
14004
  } = useLocalization();
13916
- const length = table.options.meta.length;
14005
+ const tableMeta = table.options.meta;
14006
+ const length = tableMeta.length;
13917
14007
  const currentLength = table.getRowModel().rows.length;
13918
14008
  let label;
13919
14009
  let count;
13920
14010
  // row selection
13921
- const rowsSelectedLength = table.getSelectedRowModel().rows.length;
14011
+ // use table state and not the selected row model because of the way server loading works
14012
+ const rowsSelectedLength = Object.keys(table.getState().rowSelection).length;
13922
14013
  if (rowsSelectedLength > 0) {
13923
14014
  label = texts.table.footer.summary.selected;
13924
14015
  count = /*#__PURE__*/React__default.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement("strong", null, new Intl.NumberFormat(locale).format(rowsSelectedLength)), "\u00A0", texts.table.footer.summary.count, "\u00A0", /*#__PURE__*/React__default.createElement("strong", null, new Intl.NumberFormat(locale).format(length)));
13925
- } else if ((_table$getState$colum = table.getState().columnFilters) !== null && _table$getState$colum !== void 0 && _table$getState$colum.length ||
14016
+ } else if (!tableMeta.server.isEnabled && ((_table$getState$colum = table.getState().columnFilters) !== null && _table$getState$colum !== void 0 && _table$getState$colum.length ||
13926
14017
  // filtered data
13927
- !!table.getState().globalFilter && table.options.enableGlobalFilter // search with hide enabled
13928
- ) {
14018
+ !!table.getState().globalFilter && table.options.enableGlobalFilter)) {
13929
14019
  label = texts.table.footer.summary.records;
13930
- count = /*#__PURE__*/React__default.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement("strong", null, currentLength), "\u00A0", texts.table.footer.summary.count, "\u00A0", /*#__PURE__*/React__default.createElement("strong", null, new Intl.NumberFormat(locale).format(length)));
14020
+ count = /*#__PURE__*/React__default.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement("strong", null, new Intl.NumberFormat(locale).format(currentLength)), "\u00A0", texts.table.footer.summary.count, "\u00A0", /*#__PURE__*/React__default.createElement("strong", null, new Intl.NumberFormat(locale).format(length)));
13931
14021
  } else {
13932
14022
  label = texts.table.footer.summary.records;
13933
14023
  count = /*#__PURE__*/React__default.createElement("strong", null, new Intl.NumberFormat(locale).format(length));
@@ -14034,6 +14124,7 @@ const SearchInput2 = /*#__PURE__*/React__default.forwardRef(function SearchInput
14034
14124
  onClickFindPrevious: handleClickFindPrevious,
14035
14125
  settingsContent,
14036
14126
  shortcut,
14127
+ showTotal = true,
14037
14128
  value,
14038
14129
  ...attributes
14039
14130
  } = props;
@@ -14112,10 +14203,12 @@ const SearchInput2 = /*#__PURE__*/React__default.forwardRef(function SearchInput
14112
14203
  }
14113
14204
  if (hasFind && isActive) {
14114
14205
  postfix = /*#__PURE__*/React__default.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement("span", {
14115
- className: "text-grey-700 flex h-4 items-center border-r border-black/[0.25] pr-2"
14116
- }, loading ? /*#__PURE__*/React__default.createElement(Spinner, {
14206
+ className: "text-grey-700 flex h-4 items-center"
14207
+ }, loading ? (/*#__PURE__*/React__default.createElement(Spinner, {
14117
14208
  className: "h-4 w-4"
14118
- }) : `${findCurrent !== null && findCurrent !== void 0 ? findCurrent : 0}/${findTotal !== null && findTotal !== void 0 ? findTotal : 0}`), findCurrent ? (/*#__PURE__*/React__default.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement(IconButton, {
14209
+ })) : showTotal ? (/*#__PURE__*/React__default.createElement("span", {
14210
+ className: "border-r border-black/[0.25] pr-2"
14211
+ }, `${findCurrent !== null && findCurrent !== void 0 ? findCurrent : 0}/${findTotal !== null && findTotal !== void 0 ? findTotal : 0}`)) : null), findCurrent ? (/*#__PURE__*/React__default.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement(IconButton, {
14119
14212
  "aria-label": texts.searchInput.findPrevious,
14120
14213
  className: "scale-75 !bg-transparent hover:!bg-black/[0.08] [&>svg]:scale-125",
14121
14214
  icon: "chevron-up",
@@ -14219,6 +14312,7 @@ function Search$1(props) {
14219
14312
  const scrollTo = rowIndex => scrollToIndex(rowIndex, {
14220
14313
  align: 'center'
14221
14314
  });
14315
+ const hiddenColumns = getHiddenColumns(table.getState().columnVisibility);
14222
14316
  React__default.useEffect(() => {
14223
14317
  if (tableMeta.search.highlightedColumnIndexes.length) {
14224
14318
  scrollTo(tableMeta.search.highlightedColumnIndexes[0][0]);
@@ -14227,9 +14321,11 @@ function Search$1(props) {
14227
14321
  const handleFocus = function () {
14228
14322
  try {
14229
14323
  const _temp = function () {
14230
- if (tableMeta.server.loadAllIfNeeded) {
14324
+ if (tableMeta.server.loadAllIfNeeded && !tableMeta.server._experimentalDataLoader2) {
14231
14325
  // don't pass the search query because we need all data - not filtered data
14232
- return Promise.resolve(tableMeta.server.loadAllIfNeeded(table.getState().sorting, table.getState().columnFilters)).then(function () {});
14326
+ return Promise.resolve(tableMeta.server.loadAllIfNeeded(table.getState().sorting, table.getState().columnFilters, hiddenColumns,
14327
+ // the old data loader doesn't have server side search
14328
+ undefined)).then(function () {});
14233
14329
  }
14234
14330
  }();
14235
14331
  // load all data if that is possible
@@ -14238,8 +14334,20 @@ function Search$1(props) {
14238
14334
  return Promise.reject(e);
14239
14335
  }
14240
14336
  };
14337
+ const [loading, setLoading] = React__default.useState(false);
14338
+ const searchTimeoutRef = React__default.useRef();
14241
14339
  const handleChange = query => {
14242
14340
  table.setGlobalFilter(String(query !== null && query !== void 0 ? query : ''));
14341
+ if (tableMeta.search.enableGlobalFilter && tableMeta.search.handleSearch) {
14342
+ clearTimeout(searchTimeoutRef.current);
14343
+ searchTimeoutRef.current = setTimeout(() => {
14344
+ var _tableMeta$search$han, _tableMeta$search;
14345
+ setLoading(true);
14346
+ (_tableMeta$search$han = (_tableMeta$search = tableMeta.search).handleSearch) === null || _tableMeta$search$han === void 0 ? void 0 : _tableMeta$search$han.call(_tableMeta$search, query, hiddenColumns).then(() => {
14347
+ setLoading(false);
14348
+ });
14349
+ }, 150);
14350
+ }
14243
14351
  };
14244
14352
  const handleToggleExcludeUnmatchedResults = enabled => {
14245
14353
  tableMeta.search.setEnableGlobalFilter(enabled, table);
@@ -14247,6 +14355,12 @@ function Search$1(props) {
14247
14355
  var _ref$current;
14248
14356
  return (_ref$current = ref.current) === null || _ref$current === void 0 ? void 0 : _ref$current.focus();
14249
14357
  });
14358
+ if (tableMeta.search.handleSearch) {
14359
+ setLoading(true);
14360
+ tableMeta.search.handleSearch(enabled ? query : undefined, hiddenColumns).then(() => {
14361
+ setLoading(false);
14362
+ });
14363
+ }
14250
14364
  };
14251
14365
  const handleNextResult = () => {
14252
14366
  if (!tableMeta.search.highlightedColumnIndexes.length) {
@@ -14290,7 +14404,7 @@ function Search$1(props) {
14290
14404
  return /*#__PURE__*/React__default.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement(SearchInput2, {
14291
14405
  findCurrent: tableMeta.search.currentHighlightColumnIndex !== undefined ? tableMeta.search.currentHighlightColumnIndex + 1 : null,
14292
14406
  findTotal: (_tableMeta$search$hig = (_tableMeta$search$hig2 = tableMeta.search.highlightedColumnIndexes) === null || _tableMeta$search$hig2 === void 0 ? void 0 : _tableMeta$search$hig2.length) !== null && _tableMeta$search$hig !== void 0 ? _tableMeta$search$hig : null,
14293
- loading: tableMeta.server.loading,
14407
+ loading: tableMeta.server._experimentalDataLoader2 ? loading : tableMeta.server.loading,
14294
14408
  name: "table-search",
14295
14409
  onClickFindPrevious: handlePreviousResult,
14296
14410
  onClickFindNext: handleNextResult,
@@ -14305,6 +14419,7 @@ function Search$1(props) {
14305
14419
  meta: true,
14306
14420
  shift: false
14307
14421
  },
14422
+ showTotal: !tableMeta.server._experimentalDataLoader2,
14308
14423
  value: query
14309
14424
  }));
14310
14425
  }
@@ -16391,8 +16506,9 @@ function Print$1(props) {
16391
16506
  const toastRef = toast.loading(texts.table.print.loading);
16392
16507
  const _temp2 = function () {
16393
16508
  if (tableMeta.server.isEnabled && tableMeta.server.loadAllIfNeeded) {
16509
+ const hiddenColumns = getHiddenColumns(table.getState().columnVisibility);
16394
16510
  const _temp = _catch(function () {
16395
- return Promise.resolve(tableMeta.server.loadAllIfNeeded(table.getState().sorting, table.getState().columnFilters)).then(function () {});
16511
+ return Promise.resolve(tableMeta.server.loadAllIfNeeded(table.getState().sorting, table.getState().columnFilters, hiddenColumns, tableMeta.search.enableGlobalFilter ? table.getState().globalFilter : undefined)).then(function () {});
16396
16512
  }, function (error) {
16397
16513
  const errorMessage = `${texts.table.print.error}: ${error}`;
16398
16514
  console.error(errorMessage);
@@ -18758,18 +18874,21 @@ function useTableEditingListener(table, tableRef, scrollToIndex) {
18758
18874
  document.addEventListener('click', onClickOutside);
18759
18875
  return () => document.removeEventListener('click', onClickOutside);
18760
18876
  }, [tableMeta.editing.isEditing, tableMeta.editing.saveChanges]);
18761
- const rows = table.getRowModel().rows;
18762
- // make sure pending changes are removed for rows that no longer exist
18763
- useLazyEffect(() => {
18764
- const pendingChanges = tableMeta.editing.getErrorsShownInAlert();
18765
- pendingChanges.forEach(pendingChange => {
18766
- try {
18767
- table.getRow(pendingChange.rowId);
18768
- } catch {
18769
- tableMeta.editing.discardChanges(pendingChange.rowId, table);
18770
- }
18771
- });
18772
- }, [rows.length]);
18877
+ /*
18878
+ const rows = table.getRowModel().rows;
18879
+ // make sure pending changes are removed for rows that no longer exist
18880
+ useLazyEffect(() => {
18881
+ const pendingChanges = tableMeta.editing.getErrorsShownInAlert();
18882
+ pendingChanges.forEach(pendingChange => {
18883
+ try {
18884
+ table.getRow(pendingChange.rowId);
18885
+ } catch {
18886
+ // TODO: this has the potential to remove changes for "unloaded" rows in server loading
18887
+ //tableMeta.editing.discardChanges(pendingChange.rowId, table);
18888
+ }
18889
+ });
18890
+ }, [rows.length]);
18891
+ */
18773
18892
  // shortcuts
18774
18893
  useGlobalKeyDown(tableMeta.editing.isEnabled ? shortcut : undefined, event => {
18775
18894
  event.preventDefault();
@@ -18797,6 +18916,7 @@ function reducer$2(state, action) {
18797
18916
  {
18798
18917
  const {
18799
18918
  columnId,
18919
+ index,
18800
18920
  row,
18801
18921
  value
18802
18922
  } = payload;
@@ -18806,7 +18926,8 @@ function reducer$2(state, action) {
18806
18926
  ...state.changes,
18807
18927
  rows: setWith(state.changes.rows, `${rowId}.${columnId}`, value, Object),
18808
18928
  originals: setWith(state.changes.originals, rowId, row, Object)
18809
- }
18929
+ },
18930
+ indexes: setWith(state.indexes, rowId, index, Object)
18810
18931
  };
18811
18932
  }
18812
18933
  case 'removeCellValue':
@@ -18840,6 +18961,7 @@ function reducer$2(state, action) {
18840
18961
  {
18841
18962
  const {
18842
18963
  cellErrors,
18964
+ index,
18843
18965
  moveReasons,
18844
18966
  original,
18845
18967
  value
@@ -18854,7 +18976,8 @@ function reducer$2(state, action) {
18854
18976
  moveReasons: setWith(state.changes.moveReasons, rowId, moveReasons !== null && moveReasons !== void 0 ? moveReasons : state.changes.moveReasons[rowId], Object),
18855
18977
  // status can be undefined, so don't use ??
18856
18978
  status: setWith(state.changes.status, rowId, undefined, Object)
18857
- }
18979
+ },
18980
+ indexes: setWith(state.indexes, rowId, index, Object)
18858
18981
  };
18859
18982
  }
18860
18983
  case 'removeRow':
@@ -18872,6 +18995,7 @@ function reducer$2(state, action) {
18872
18995
  originals: omit(state.changes.originals, rowId),
18873
18996
  status: omit(state.changes.status, rowId)
18874
18997
  },
18998
+ indexes: omit(state.indexes, rowId),
18875
18999
  temporaryRows: state.temporaryRows.filter(row => row[rowIdentityAccessor] !== rowId)
18876
19000
  };
18877
19001
  }
@@ -18904,6 +19028,7 @@ function reducer$2(state, action) {
18904
19028
  case 'insertTemporaryRow':
18905
19029
  {
18906
19030
  const {
19031
+ index,
18907
19032
  value
18908
19033
  } = payload;
18909
19034
  return {
@@ -18913,14 +19038,36 @@ function reducer$2(state, action) {
18913
19038
  ...state.changes,
18914
19039
  rows: setWith(state.changes.rows, rowId, value, Object),
18915
19040
  originals: setWith(state.changes.originals, rowId, value, Object)
18916
- }
19041
+ },
19042
+ indexes: setWith(state.indexes, rowId, index, Object)
18917
19043
  };
18918
19044
  }
18919
19045
  default:
18920
19046
  return state;
18921
19047
  }
18922
19048
  }
18923
- function usePendingChangesState(handleSave, handleChange, rowIdentityAccessor, validator) {
19049
+ function usePendingChangesState(handleSave, handleChange, handleDiscard, rowIdentityAccessor, validator) {
19050
+ const discardChanges = function (rowId, table) {
19051
+ try {
19052
+ // remove any new rows from pinned state before discarding them
19053
+ table.resetRowPinning(true);
19054
+ dispatch({
19055
+ type: 'removeRow',
19056
+ rowId,
19057
+ payload: {
19058
+ rowIdentityAccessor
19059
+ }
19060
+ });
19061
+ const _temp8 = function () {
19062
+ if (typeof handleDiscard === 'function') {
19063
+ return Promise.resolve(handleDiscard()).then(function () {});
19064
+ }
19065
+ }();
19066
+ return Promise.resolve(_temp8 && _temp8.then ? _temp8.then(function () {}) : void 0);
19067
+ } catch (e) {
19068
+ return Promise.reject(e);
19069
+ }
19070
+ };
18924
19071
  const saveChanges = function (table, rowId = undefined) {
18925
19072
  try {
18926
19073
  let _exit = false;
@@ -18933,19 +19080,20 @@ function usePendingChangesState(handleSave, handleChange, rowIdentityAccessor, v
18933
19080
  [rowId]: state.changes.rows[rowId]
18934
19081
  } : state.changes.rows;
18935
19082
  let completed = true;
18936
- const _temp9 = _forOf(Object.keys(changes), function (rowId) {
19083
+ const _temp7 = _forOf(Object.keys(changes), function (rowId) {
18937
19084
  const status = getRowStatus(rowId);
18938
19085
  return _catch(function () {
18939
19086
  var _changes$rowId;
18940
- function _temp8(_result) {
19087
+ function _temp6(_result) {
18941
19088
  return _exit ? _result : Promise.resolve(handleSave(changeSet)).then(function () {
18942
19089
  // cleanup changes, we don't need them after saving
18943
- discardChanges(rowId, table);
18944
- // show the saved status, then remove it after a delay
18945
- setRowStatus(rowId, 'saved');
18946
- setTimeout(() => {
18947
- setRowStatus(rowId, undefined);
18948
- }, DELAY_BEFORE_REMOVING_SAVE_STATUS);
19090
+ return Promise.resolve(discardChanges(rowId, table)).then(function () {
19091
+ // show the saved status, then remove it after a delay
19092
+ setRowStatus(rowId, 'saved');
19093
+ setTimeout(() => {
19094
+ setRowStatus(rowId, undefined);
19095
+ }, DELAY_BEFORE_REMOVING_SAVE_STATUS);
19096
+ });
18949
19097
  });
18950
19098
  }
18951
19099
  const rowChanges = (_changes$rowId = changes[rowId]) !== null && _changes$rowId !== void 0 ? _changes$rowId : {};
@@ -18963,7 +19111,7 @@ function usePendingChangesState(handleSave, handleChange, rowIdentityAccessor, v
18963
19111
  delete changeSet[rowIdentityAccessor];
18964
19112
  }
18965
19113
  // re-run validation, maybe a cell is already invalid but has never been blurred
18966
- const _temp7 = function () {
19114
+ const _temp5 = function () {
18967
19115
  if (validator) {
18968
19116
  return Promise.resolve(validator(changeSet)).then(function (errors) {
18969
19117
  if (errors && Object.keys(errors).length) {
@@ -18972,7 +19120,7 @@ function usePendingChangesState(handleSave, handleChange, rowIdentityAccessor, v
18972
19120
  });
18973
19121
  }
18974
19122
  }();
18975
- return _temp7 && _temp7.then ? _temp7.then(_temp8) : _temp8(_temp7); // send new data to the server
19123
+ return _temp5 && _temp5.then ? _temp5.then(_temp6) : _temp6(_temp5); // send new data to the server
18976
19124
  }, function (error) {
18977
19125
  var _error$response;
18978
19126
  if (error instanceof ReferenceError || error instanceof TypeError || (error === null || error === void 0 ? void 0 : (_error$response = error.response) === null || _error$response === void 0 ? void 0 : _error$response.status) >= 500) {
@@ -19012,18 +19160,18 @@ function usePendingChangesState(handleSave, handleChange, rowIdentityAccessor, v
19012
19160
  }, function () {
19013
19161
  return _exit;
19014
19162
  });
19015
- return Promise.resolve(_temp9 && _temp9.then ? _temp9.then(function (_result3) {
19163
+ return Promise.resolve(_temp7 && _temp7.then ? _temp7.then(function (_result3) {
19016
19164
  return _exit ? _result3 : completed;
19017
- }) : _exit ? _temp9 : completed);
19165
+ }) : _exit ? _temp7 : completed);
19018
19166
  } catch (e) {
19019
19167
  return Promise.reject(e);
19020
19168
  }
19021
19169
  };
19022
19170
  const onCellChanged = function (cell, rowIndex, nextValue, shouldRunUpdaters = true) {
19023
19171
  try {
19024
- function _temp6() {
19172
+ function _temp4() {
19025
19173
  var _state$changes$errors11;
19026
- function _temp4() {
19174
+ function _temp2() {
19027
19175
  // only set errors and move reasons for the cells we're currently acting on
19028
19176
  // why? because the UX is not good if we set them for cells the user hasn't touched yet
19029
19177
  const cellsToActOn = [cell.column.id, ...Object.keys(updatesForOtherCells)];
@@ -19054,6 +19202,7 @@ function usePendingChangesState(handleSave, handleChange, rowIdentityAccessor, v
19054
19202
  rowId: cell.row.id,
19055
19203
  payload: {
19056
19204
  cellErrors: nextCellErrors,
19205
+ index: rowIndex,
19057
19206
  moveReasons: nextMoveReasons,
19058
19207
  value: nextChanges
19059
19208
  }
@@ -19072,7 +19221,7 @@ function usePendingChangesState(handleSave, handleChange, rowIdentityAccessor, v
19072
19221
  };
19073
19222
  // run validation - if there are changes, and if there is an original stored
19074
19223
  let validationErrors = {};
19075
- const _temp3 = function () {
19224
+ const _temp = function () {
19076
19225
  if (validator && Object.keys(nextChanges).length && state.changes.originals[cell.row.id]) {
19077
19226
  // merge with the original so we get a full row
19078
19227
  const nextRowValue = {
@@ -19080,12 +19229,12 @@ function usePendingChangesState(handleSave, handleChange, rowIdentityAccessor, v
19080
19229
  ...changes,
19081
19230
  ...updatesForOtherCells
19082
19231
  };
19083
- return Promise.resolve(validator(nextRowValue)).then(function (_validator2) {
19084
- validationErrors = _validator2 !== null && _validator2 !== void 0 ? _validator2 : {};
19232
+ return Promise.resolve(validator(nextRowValue)).then(function (_validator) {
19233
+ validationErrors = _validator !== null && _validator !== void 0 ? _validator : {};
19085
19234
  });
19086
19235
  }
19087
19236
  }();
19088
- return _temp3 && _temp3.then ? _temp3.then(_temp4) : _temp4(_temp3);
19237
+ return _temp && _temp.then ? _temp.then(_temp2) : _temp2(_temp);
19089
19238
  }
19090
19239
  const changes = nextValue !== undefined ? {
19091
19240
  ...state.changes.rows[cell.row.id],
@@ -19098,7 +19247,7 @@ function usePendingChangesState(handleSave, handleChange, rowIdentityAccessor, v
19098
19247
  }
19099
19248
  let updatesForOtherCells = {};
19100
19249
  // run the updater handler if there is one, to see if there are any other cells to update
19101
- const _temp5 = function () {
19250
+ const _temp3 = function () {
19102
19251
  if (typeof handleChange === 'function' && shouldRunUpdaters) {
19103
19252
  const previousRowValue = {
19104
19253
  ...state.changes.originals[cell.row.id]
@@ -19112,42 +19261,11 @@ function usePendingChangesState(handleSave, handleChange, rowIdentityAccessor, v
19112
19261
  });
19113
19262
  }
19114
19263
  }();
19115
- return Promise.resolve(_temp5 && _temp5.then ? _temp5.then(_temp6) : _temp6(_temp5));
19264
+ return Promise.resolve(_temp3 && _temp3.then ? _temp3.then(_temp4) : _temp4(_temp3));
19116
19265
  } catch (e) {
19117
19266
  return Promise.reject(e);
19118
19267
  }
19119
19268
  }; // general
19120
- // rows
19121
- const setRowValue = function (rowId, original, value) {
19122
- try {
19123
- function _temp2() {
19124
- dispatch({
19125
- type: 'updateRow',
19126
- rowId,
19127
- payload: {
19128
- cellErrors,
19129
- original,
19130
- value
19131
- }
19132
- });
19133
- }
19134
- let cellErrors;
19135
- const _temp = function () {
19136
- if (validator) {
19137
- const row = {
19138
- ...original,
19139
- ...value
19140
- };
19141
- return Promise.resolve(validator(row)).then(function (_validator) {
19142
- cellErrors = _validator !== null && _validator !== void 0 ? _validator : {};
19143
- });
19144
- }
19145
- }();
19146
- return Promise.resolve(_temp && _temp.then ? _temp.then(_temp2) : _temp2(_temp));
19147
- } catch (e) {
19148
- return Promise.reject(e);
19149
- }
19150
- };
19151
19269
  const localization = useLocalization();
19152
19270
  const [state, dispatch] = React__default.useReducer(reducer$2, {
19153
19271
  changes: {
@@ -19157,8 +19275,10 @@ function usePendingChangesState(handleSave, handleChange, rowIdentityAccessor, v
19157
19275
  originals: {},
19158
19276
  status: {}
19159
19277
  },
19278
+ indexes: {},
19160
19279
  temporaryRows: []
19161
19280
  });
19281
+ // rows
19162
19282
  function getRowValue(rowId) {
19163
19283
  var _state$changes$rows$r, _state$changes$rows;
19164
19284
  return (_state$changes$rows$r = (_state$changes$rows = state.changes.rows) === null || _state$changes$rows === void 0 ? void 0 : _state$changes$rows[rowId]) !== null && _state$changes$rows$r !== void 0 ? _state$changes$rows$r : undefined;
@@ -19196,7 +19316,7 @@ function usePendingChangesState(handleSave, handleChange, rowIdentityAccessor, v
19196
19316
  }
19197
19317
  });
19198
19318
  }
19199
- function insertTemporaryRow(data) {
19319
+ function insertTemporaryRow(data, rowIndex) {
19200
19320
  const newRowId = `${TEMPORARY_ROW_ID_PREFIX}${uuid.v4()}`;
19201
19321
  const value = {
19202
19322
  ...data,
@@ -19206,13 +19326,14 @@ function usePendingChangesState(handleSave, handleChange, rowIdentityAccessor, v
19206
19326
  type: 'insertTemporaryRow',
19207
19327
  rowId: newRowId,
19208
19328
  payload: {
19329
+ index: rowIndex,
19209
19330
  value
19210
19331
  }
19211
19332
  });
19212
19333
  return newRowId;
19213
19334
  }
19214
19335
  // cells
19215
- function setCellValue(cell, value) {
19336
+ function setCellValue(cell, rowIndex, value) {
19216
19337
  const rowId = cell.row.id;
19217
19338
  const columnId = cell.column.id;
19218
19339
  // update if the change is different to the original value
@@ -19222,6 +19343,7 @@ function usePendingChangesState(handleSave, handleChange, rowIdentityAccessor, v
19222
19343
  rowId,
19223
19344
  payload: {
19224
19345
  columnId,
19346
+ index: rowIndex,
19225
19347
  row: cell.row.original,
19226
19348
  value
19227
19349
  }
@@ -19254,6 +19376,7 @@ function usePendingChangesState(handleSave, handleChange, rowIdentityAccessor, v
19254
19376
  }
19255
19377
  return rowsWithErrors.filter(hasRowErrorsShownInAlert).map(rowId => ({
19256
19378
  rowId,
19379
+ index: state.indexes[rowId],
19257
19380
  changes: state.changes.rows[rowId],
19258
19381
  errors: state.changes.errors[rowId]
19259
19382
  }));
@@ -19264,20 +19387,8 @@ function usePendingChangesState(handleSave, handleChange, rowIdentityAccessor, v
19264
19387
  function hasChanges(rowId) {
19265
19388
  return rowId ? !!state.changes.rows[rowId] : !!Object.keys(state.changes.rows).length;
19266
19389
  }
19267
- function discardChanges(rowId, table) {
19268
- // remove any new rows from pinned state before discarding them
19269
- table.resetRowPinning(true);
19270
- dispatch({
19271
- type: 'removeRow',
19272
- rowId,
19273
- payload: {
19274
- rowIdentityAccessor
19275
- }
19276
- });
19277
- }
19278
19390
  return {
19279
19391
  // row
19280
- setRowValue,
19281
19392
  getRowValue,
19282
19393
  getRowMoveReason,
19283
19394
  hasRowErrors,
@@ -19302,7 +19413,7 @@ function usePendingChangesState(handleSave, handleChange, rowIdentityAccessor, v
19302
19413
  };
19303
19414
  }
19304
19415
 
19305
- function useTableEditing(isEnabled = false, handleSave, handleChange, handleCreate, rowIdentityAccessor, validator) {
19416
+ function useTableEditing(isEnabled = false, handleSave, handleChange, handleCreate, handleDiscard, rowIdentityAccessor, validator) {
19306
19417
  const createRow = function (table, scrollToIndex, row) {
19307
19418
  try {
19308
19419
  let _exit = false;
@@ -19311,17 +19422,24 @@ function useTableEditing(isEnabled = false, handleSave, handleChange, handleCrea
19311
19422
  const changeset = row !== null && row !== void 0 ? row : handleCreate();
19312
19423
  try {
19313
19424
  if (changeset) {
19314
- const newRowId = pendingChangesFns.insertTemporaryRow(changeset);
19315
- // reset before changing row otherwise the cell changes and validation might run
19316
- setLastFocusedCellIndex(undefined);
19317
19425
  // set the active row to the new row before toggling editing on
19318
19426
  const temporaryRows = tableMeta.editing.temporaryRows;
19319
19427
  const nextRowIndex = temporaryRows.length ? tableMeta.length + 1 : tableMeta.length;
19428
+ const newRowId = pendingChangesFns.insertTemporaryRow(changeset, nextRowIndex);
19429
+ // reset before changing row otherwise the cell changes and validation might run
19430
+ setLastFocusedCellIndex(undefined);
19431
+ // set the active row to the new row before toggling editing on
19320
19432
  tableMeta.rowActive.setRowActiveIndex(nextRowIndex);
19321
19433
  // wait until set states have run
19322
19434
  requestAnimationFrame(() => {
19323
19435
  toggleEditing(true, table, scrollToIndex, false);
19324
- table.getRow(newRowId).pin('bottom');
19436
+ table.setRowPinning(currentState => {
19437
+ var _ref, _currentState$bottom;
19438
+ return {
19439
+ ...currentState,
19440
+ bottom: (_ref = (_currentState$bottom = currentState.bottom) !== null && _currentState$bottom !== void 0 ? _currentState$bottom : []) === null || _ref === void 0 ? void 0 : _ref.concat(newRowId)
19441
+ };
19442
+ });
19325
19443
  });
19326
19444
  }
19327
19445
  } catch (error) {
@@ -19355,7 +19473,7 @@ function useTableEditing(isEnabled = false, handleSave, handleChange, handleCrea
19355
19473
  const createRowButtonRef = React__default.useRef(null);
19356
19474
  // store the last focused cell, so that up/down arrow key navigation remains in the same column
19357
19475
  const [lastFocusedCellIndex, setLastFocusedCellIndex] = React__default.useState(undefined);
19358
- const pendingChangesFns = usePendingChangesState(handleSave, handleChange, rowIdentityAccessor, validator);
19476
+ const pendingChangesFns = usePendingChangesState(handleSave, handleChange, handleDiscard, rowIdentityAccessor, validator);
19359
19477
  function toggleEditing(enabled, table, scrollToIndex, doSave = true) {
19360
19478
  const tableMeta = table.options.meta;
19361
19479
  if (enabled) {
@@ -19645,7 +19763,7 @@ function EditingControlCell(props) {
19645
19763
  }, [cellRef.current]);
19646
19764
  const handleChange = React__default.useCallback(nextValue => {
19647
19765
  if (nextValue !== value) {
19648
- tableMeta.editing.setCellValue(cell, nextValue);
19766
+ tableMeta.editing.setCellValue(cell, rowIndex, nextValue);
19649
19767
  if (hasNonTextControl) {
19650
19768
  requestAnimationFrame(() => tableMeta.editing.onCellChanged(cell, rowIndex, nextValue));
19651
19769
  }
@@ -20066,7 +20184,7 @@ const RENDERERS$1 = {
20066
20184
  cell: Cell$5
20067
20185
  };
20068
20186
  function useTable3(props, ref) {
20069
- const editing = useTableEditing(props.enableEditing, props.onEditingSave, props.onEditingChange, props.onEditingCreate, props.rowIdentityAccessor, props.validator);
20187
+ const editing = useTableEditing(props.enableEditing, props.onEditingSave, props.onEditingChange, props.onEditingCreate, props.onEditingDiscard, props.rowIdentityAccessor, props.validator);
20070
20188
  const creationEnabled = editing.isEnabled && !!props.onEditingCreate;
20071
20189
  // this gives me the performance heeby jeebies, but can't think of a better way to internalise the state
20072
20190
  const data = React__default.useMemo(() => {
@@ -20163,20 +20281,22 @@ function Alert$1(props) {
20163
20281
  // table.getColumn(columName) throw error in strict dev mode. Related thread: https://github.com/TanStack/table/discussions/5505
20164
20282
  table.getAllColumns().find(x => x.id === String(tableMeta.rowIdentityAccessor)) : undefined;
20165
20283
  pendingChangesWithErrors.forEach((pendingChangeWithError, index) => {
20284
+ var _row;
20166
20285
  // if appropriate, concatenate the item with the text "and"
20167
20286
  if (pendingChangesWithErrors.length > 1 && index === pendingChangesWithErrors.length - 1) {
20168
20287
  // Add space before and after `messageAnd` text
20169
20288
  links.push(` ${validationTexts.alert.messageAnd} `);
20170
20289
  }
20171
- const rowIndex = table.getRowModel().rows.findIndex(row => row.id === pendingChangeWithError.rowId);
20290
+ // note: if this row click functionality is removed, indexes can be removed from useEditingState
20172
20291
  const handleClick = () => {
20173
20292
  // if row is visible
20174
- if (rowIndex > -1) {
20175
- scrollToRow(rowIndex);
20293
+ if (pendingChangeWithError.index > -1) {
20294
+ scrollToRow(pendingChangeWithError.index);
20295
+ tableMeta.rowActive.setRowActiveIndex(pendingChangeWithError.index);
20176
20296
  }
20177
20297
  // if row is filtered out
20178
20298
  else {
20179
- setShowFilterResetDialog(pendingChangeWithError.rowId);
20299
+ setShowFilterResetDialog(pendingChangeWithError.index);
20180
20300
  }
20181
20301
  };
20182
20302
  let tooltip;
@@ -20188,7 +20308,12 @@ function Alert$1(props) {
20188
20308
  const columnName = (_table$getAllColumns$ = table.getAllColumns().find(column => column.id === firstCellErrorColumnId)) === null || _table$getAllColumns$ === void 0 ? void 0 : (_table$getAllColumns$2 = _table$getAllColumns$.columnDef.meta) === null || _table$getAllColumns$2 === void 0 ? void 0 : _table$getAllColumns$2.header;
20189
20309
  tooltip = `${columnName}: ${pendingChangeWithError.errors.cells[firstCellErrorColumnId]}`;
20190
20310
  }
20191
- const row = table.getRow(pendingChangeWithError.rowId).original;
20311
+ let row;
20312
+ try {
20313
+ row = table.getRow(pendingChangeWithError.rowId).original;
20314
+ } catch {
20315
+ // because of server loading, some rows may not be accessible
20316
+ }
20192
20317
  links.push(/*#__PURE__*/React__default.createElement(Tooltip, {
20193
20318
  key: pendingChangeWithError.rowId,
20194
20319
  title: tooltip
@@ -20196,7 +20321,7 @@ function Alert$1(props) {
20196
20321
  className: "text-blue",
20197
20322
  onClick: handleClick,
20198
20323
  role: "button"
20199
- }, rowIdentityColumn ? row[rowIdentityColumn.id] : rowIndex + 1)));
20324
+ }, rowIdentityColumn ? (_row = row) === null || _row === void 0 ? void 0 : _row[rowIdentityColumn.id] : pendingChangeWithError.index + 1)));
20200
20325
  // if appropriate, concatenate the item with the text ","
20201
20326
  if (pendingChangesWithErrors.length > 2 && index < pendingChangesWithErrors.length - 2) {
20202
20327
  links.push(', ');
@@ -20217,9 +20342,8 @@ function Alert$1(props) {
20217
20342
  table.resetGlobalFilter();
20218
20343
  table.resetColumnFilters();
20219
20344
  requestAnimationFrame(() => {
20220
- const rowIndex = table.getRowModel().rows.findIndex(row => row.id === showFilterResetDialog);
20221
- if (rowIndex > -1) {
20222
- scrollToRow(rowIndex);
20345
+ if (showFilterResetDialog && showFilterResetDialog > -1) {
20346
+ scrollToRow(showFilterResetDialog);
20223
20347
  }
20224
20348
  setShowFilterResetDialog(false);
20225
20349
  });
@@ -20300,7 +20424,9 @@ function CreateNewRow(props) {
20300
20424
  if (isDisabled) {
20301
20425
  return Promise.resolve();
20302
20426
  }
20303
- return Promise.resolve(tableMeta.editing.createRow(table, scrollToIndex)).then(function () {});
20427
+ return Promise.resolve(tableMeta.editing.createRow(table, scrollToIndex)).then(function () {
20428
+ table.resetRowSelection();
20429
+ });
20304
20430
  } catch (e) {
20305
20431
  return Promise.reject(e);
20306
20432
  }
@@ -20319,7 +20445,7 @@ function CreateNewRow(props) {
20319
20445
  keys: shortcut
20320
20446
  });
20321
20447
  }
20322
- const className = cn('group/row border-grey-300 !sticky z-[21]', {
20448
+ const className = cn('group/row border-grey-300 !sticky z-[21] print:hidden', {
20323
20449
  'bottom-10': tableMeta.footer.isEnabled,
20324
20450
  'bottom-0': !tableMeta.footer.isEnabled,
20325
20451
  'border-b': !isScrolled
@@ -20409,7 +20535,7 @@ function TemporaryRow(props) {
20409
20535
  }
20410
20536
  }
20411
20537
  };
20412
- const className = cn('group/row border-grey-300 !sticky z-[22]', {
20538
+ const className = cn('group/row border-grey-300 !sticky z-[22] print:hidden', {
20413
20539
  'bottom-[calc(5rem_+_2px)] data-[row-editing-move]:bottom-[calc(5rem_+_2px)]': tableMeta.footer.isEnabled,
20414
20540
  'bottom-[calc(2.5rem_+_2px)] data-[row-editing-move]:bottom-[calc(2.5rem_+_2px)]': !tableMeta.footer.isEnabled,
20415
20541
  'border-t-2 shadow-[0px_-5px_20px_0px_rgba(0,0,0,0.1)] [&>td]:!border-b-0': isScrolled
@@ -20426,7 +20552,8 @@ function TemporaryRow(props) {
20426
20552
  onKeyDown: handleKeyDown,
20427
20553
  onKeyDownCapture: handleKeyDownCapture,
20428
20554
  hideInternalColumns: true,
20429
- hideRowActions: !tableMeta.editing.isEditing
20555
+ hideRowActions: !tableMeta.editing.isEditing,
20556
+ skipPageLoading: true
20430
20557
  }))));
20431
20558
  }
20432
20559
 
@@ -22215,6 +22342,222 @@ Navigation2.Link = Link$3;
22215
22342
  Navigation2.Section = Section;
22216
22343
  Navigation2.Content = Content$a;
22217
22344
 
22345
+ const DATASET_SIZE_MULTIPLIER = 15;
22346
+ function useTableDataLoader2(fetchPage, fetchAll, options = {
22347
+ pageSize: DEFAULT_PAGE_SIZE
22348
+ }) {
22349
+ const loadPage = function (pageIndex, sorting, filters, hiddenColumns, search, reset = false) {
22350
+ try {
22351
+ // if a request is already pending for this page (and it's not a reset), skip it
22352
+ if (_pendingPageRequests.current[pageIndex] && !reset) {
22353
+ return Promise.resolve();
22354
+ }
22355
+ const hasChangedData = JSON.stringify(sorting) !== JSON.stringify(_lastUsedSorting.current) || JSON.stringify(filters) !== JSON.stringify(_lastUsedFilters.current) || search !== _lastUsedSearch.current;
22356
+ // if the page is already loaded and has actual rows, abort
22357
+ if (data.cache[pageIndex] && data.cache[pageIndex][0] && !hasChangedData && !reset) {
22358
+ return Promise.resolve();
22359
+ }
22360
+ // create an id to track the update
22361
+ const requestId = uuid.v4();
22362
+ // set the page as loading, so that subsequent requests don't retrigger it
22363
+ _pendingPageRequests.current[pageIndex] = true;
22364
+ const _temp2 = _catch(function () {
22365
+ _lastRequestId.current = requestId;
22366
+ return Promise.resolve(fetchPage(pageIndex, pageSize, sorting, filters, hiddenColumns, search)).then(function (response) {
22367
+ length.current = response.length;
22368
+ // update state, here we do some "magic" to support "load in place"
22369
+ setData(currentData => {
22370
+ // if this request wasn't the last one, just return the current state to prevent weird updates
22371
+ if (_lastRequestId.current !== requestId) {
22372
+ return currentData;
22373
+ }
22374
+ const direction = getDirection(pageIndex, currentData.pages);
22375
+ const nextPages = getPages(pageIndex, currentData.lastFetchedPage, reset ? [] : currentData.pages, direction);
22376
+ // set values so we can track if they changed between loads
22377
+ _lastUsedSorting.current = sorting;
22378
+ _lastUsedFilters.current = filters;
22379
+ _lastUsedSearch.current = search;
22380
+ _lastUsedHiddenColumns.current = hiddenColumns;
22381
+ // cache data as an object to prevent any duplicates for pages
22382
+ let nextCache;
22383
+ if (reset || hasChangedData || !direction) {
22384
+ nextCache = nextPages.reduce((acc, p) => ({
22385
+ ...acc,
22386
+ [p]: Array(pageSize).fill(undefined)
22387
+ }), {});
22388
+ } else {
22389
+ nextCache = {
22390
+ ...currentData.cache
22391
+ };
22392
+ }
22393
+ nextCache[pageIndex] = response.data;
22394
+ // cleanup "unloaded" pages
22395
+ if (direction === 'forward' && currentData.rows.length >= DATASET_SIZE) {
22396
+ delete nextCache[currentData.pages[0]];
22397
+ } else if (direction === 'backward' && currentData.rows.length >= DATASET_SIZE) {
22398
+ delete nextCache[currentData.pages[currentData.pages.length - 1]];
22399
+ }
22400
+ // remap rows from the cached data - do it here and not in render to save some performance
22401
+ const rows = Object.values(nextCache).reduce((acc, p) => acc.concat(p), []);
22402
+ return {
22403
+ cache: nextCache,
22404
+ pages: nextPages,
22405
+ rows: rows,
22406
+ lastFetchedPage: pageIndex
22407
+ };
22408
+ });
22409
+ // reset pending requests
22410
+ delete _pendingPageRequests.current[pageIndex];
22411
+ });
22412
+ }, function () {});
22413
+ return Promise.resolve(_temp2 && _temp2.then ? _temp2.then(function () {}) : void 0);
22414
+ } catch (e) {
22415
+ return Promise.reject(e);
22416
+ }
22417
+ };
22418
+ const {
22419
+ pageSize
22420
+ } = options;
22421
+ const DATASET_SIZE = DATASET_SIZE_MULTIPLIER * pageSize;
22422
+ // track the data length, we don't know it until the first request
22423
+ const length = React__default.useRef(0);
22424
+ // data will be filled after the first request
22425
+ const [data, setData] = React__default.useState({
22426
+ rows: [],
22427
+ pages: [],
22428
+ cache: {},
22429
+ lastFetchedPage: undefined
22430
+ });
22431
+ // track which pages have been loaded to dedupe requests
22432
+ const _pendingPageRequests = React__default.useRef({});
22433
+ // it's possible to spam updates, e.g. sort, so we don't set state if the last request wasn't the current oen
22434
+ const _lastRequestId = React__default.useRef();
22435
+ // store last used properties
22436
+ const _lastUsedSorting = React__default.useRef([]);
22437
+ const _lastUsedFilters = React__default.useRef([]);
22438
+ const _lastUsedSearch = React__default.useRef();
22439
+ const _lastUsedHiddenColumns = React__default.useRef([]);
22440
+ const loadAll = function (sorting, filters, hiddenColumns, search) {
22441
+ try {
22442
+ // set values so we can track if they changed between loads
22443
+ _lastUsedSorting.current = sorting;
22444
+ _lastUsedFilters.current = filters;
22445
+ _lastUsedSearch.current = search;
22446
+ _lastUsedHiddenColumns.current = hiddenColumns;
22447
+ const _temp = _finallyRethrows(function () {
22448
+ return _catch(function () {
22449
+ return Promise.resolve(fetchAll(sorting, filters, hiddenColumns, search)).then(function (response) {
22450
+ length.current = response.length;
22451
+ const pages = [];
22452
+ const cache = {};
22453
+ Array.from(Array(response.length / pageSize).keys()).forEach(index => {
22454
+ pages.push(index);
22455
+ const startIndex = index * pageSize;
22456
+ cache[index] = response.data.slice(startIndex, startIndex + pageSize);
22457
+ });
22458
+ setData({
22459
+ cache,
22460
+ pages,
22461
+ rows: response.data,
22462
+ lastFetchedPage: undefined
22463
+ });
22464
+ });
22465
+ }, function () {});
22466
+ }, function (_wasThrown, _result) {
22467
+ // reset pending requests
22468
+ _pendingPageRequests.current = {};
22469
+ if (_wasThrown) throw _result;
22470
+ return _result;
22471
+ });
22472
+ return Promise.resolve(_temp && _temp.then ? _temp.then(function () {}) : void 0);
22473
+ } catch (e) {
22474
+ return Promise.reject(e);
22475
+ }
22476
+ };
22477
+ const invalidate = function () {
22478
+ try {
22479
+ // reset stuff
22480
+ _pendingPageRequests.current = {};
22481
+ // load the current page again
22482
+ return loadPage(getCurrentPage(data.pages), _lastUsedSorting.current, _lastUsedFilters.current, _lastUsedHiddenColumns.current, _lastUsedSearch.current, true);
22483
+ } catch (e) {
22484
+ return Promise.reject(e);
22485
+ }
22486
+ };
22487
+ const handleSort = function (sorting) {
22488
+ try {
22489
+ // reset before loading the current page
22490
+ _pendingPageRequests.current = {};
22491
+ return loadPage(getCurrentPage(data.pages), sorting, _lastUsedFilters.current, _lastUsedHiddenColumns.current, _lastUsedSearch.current, true);
22492
+ } catch (e) {
22493
+ return Promise.reject(e);
22494
+ }
22495
+ };
22496
+ const handleFilter = function (filters, hiddenColumns) {
22497
+ try {
22498
+ // reset before loading the current page
22499
+ _pendingPageRequests.current = {};
22500
+ return loadPage(0, _lastUsedSorting.current, filters, hiddenColumns, _lastUsedSearch.current, true);
22501
+ } catch (e) {
22502
+ return Promise.reject(e);
22503
+ }
22504
+ };
22505
+ const handleSearch = function (search, hiddenColumns) {
22506
+ try {
22507
+ // reset before loading the current page
22508
+ _pendingPageRequests.current = {};
22509
+ return loadPage(0, _lastUsedSorting.current, _lastUsedFilters.current, hiddenColumns, search, true);
22510
+ } catch (e) {
22511
+ return Promise.reject(e);
22512
+ }
22513
+ };
22514
+ return [{
22515
+ data: data.rows,
22516
+ pages: data.pages,
22517
+ length: length.current,
22518
+ loadAll,
22519
+ loadPage,
22520
+ onChangeFilter: handleFilter,
22521
+ onChangeSearch: handleSearch,
22522
+ onChangeSort: handleSort,
22523
+ pageSize,
22524
+ _experimentalDataLoader2: true
22525
+ }, invalidate];
22526
+ }
22527
+ function getCurrentPage(currentPages) {
22528
+ if (currentPages.length <= 2) {
22529
+ return currentPages[0];
22530
+ }
22531
+ // for even page lengths we can't know which is the current visible page - it could even be both
22532
+ // so we load one of them and rely on the "load next/previous page" functionality in row
22533
+ const middle = Math.floor(currentPages.length / 2);
22534
+ return currentPages[middle];
22535
+ }
22536
+ function getDirection(pageIndex, currentPages) {
22537
+ if (currentPages.length) {
22538
+ if (pageIndex === currentPages[currentPages.length - 1] + 1) {
22539
+ return 'forward';
22540
+ } else if (pageIndex === currentPages[0] - 1 || currentPages.length === 2 && currentPages[0] !== 0 && pageIndex === currentPages[0]) {
22541
+ return 'backward';
22542
+ }
22543
+ }
22544
+ return undefined;
22545
+ }
22546
+ function getPages(pageIndex, lastUsedPageIndex, currentPages, direction) {
22547
+ if (currentPages.length && (pageIndex === lastUsedPageIndex || currentPages.includes(pageIndex))) {
22548
+ return currentPages;
22549
+ }
22550
+ if (direction === 'forward') {
22551
+ const nextPages = currentPages.length === DATASET_SIZE_MULTIPLIER ? currentPages.slice(1) : currentPages;
22552
+ return nextPages.concat(pageIndex);
22553
+ }
22554
+ if (direction === 'backward') {
22555
+ const nextPages = currentPages.length === DATASET_SIZE_MULTIPLIER ? currentPages.slice(0, -1) : currentPages;
22556
+ return [pageIndex].concat(nextPages);
22557
+ }
22558
+ return [pageIndex];
22559
+ }
22560
+
22218
22561
  const useBoundaryOverflowDetection = (ref, dependencies = []) => {
22219
22562
  const [boundaryIndex, setBoundaryIndex] = React__default.useState();
22220
22563
  const dimensions = useBoundingClientRectListener(ref, dependencies);
@@ -22354,6 +22697,7 @@ exports.useOnClickOutside = useOnClickOutside;
22354
22697
  exports.usePagination = usePagination;
22355
22698
  exports.useRadioGroup = useRadioGroup;
22356
22699
  exports.useTableDataLoader = useTableDataLoader;
22700
+ exports.useTableDataLoader2 = useTableDataLoader2;
22357
22701
  exports.useTableRowCreation = useTableRowCreation;
22358
22702
  exports.useToast = useToast;
22359
22703
  //# sourceMappingURL=taco.cjs.development.js.map