@tanstack/table-core 8.0.0-beta.7 → 8.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,7 +3,6 @@ import { OnChangeFn, TableGenerics, TableInstance, RowModel, Updater } from '../
3
3
  export declare type PaginationState = {
4
4
  pageIndex: number;
5
5
  pageSize: number;
6
- pageCount?: number;
7
6
  };
8
7
  export declare type PaginationTableState = {
9
8
  pagination: PaginationState;
@@ -12,6 +11,7 @@ export declare type PaginationInitialTableState = {
12
11
  pagination?: Partial<PaginationState>;
13
12
  };
14
13
  export declare type PaginationOptions<TGenerics extends TableGenerics> = {
14
+ pageCount?: number;
15
15
  manualPagination?: boolean;
16
16
  onPaginationChange?: OnChangeFn<PaginationState>;
17
17
  autoResetPageIndex?: boolean;
@@ -973,38 +973,54 @@
973
973
  };
974
974
 
975
975
  const includesString = (row, columnId, filterValue) => {
976
+ var _row$getValue;
977
+
976
978
  const search = filterValue.toLowerCase();
977
- return row.getValue(columnId).toLowerCase().includes(search);
979
+ return (_row$getValue = row.getValue(columnId)) == null ? void 0 : _row$getValue.toLowerCase().includes(search);
978
980
  };
979
981
 
980
982
  includesString.autoRemove = val => testFalsey(val);
981
983
 
982
984
  const includesStringSensitive = (row, columnId, filterValue) => {
983
- return row.getValue(columnId).includes(filterValue);
985
+ var _row$getValue2;
986
+
987
+ return (_row$getValue2 = row.getValue(columnId)) == null ? void 0 : _row$getValue2.includes(filterValue);
984
988
  };
985
989
 
986
990
  includesStringSensitive.autoRemove = val => testFalsey(val);
987
991
 
988
992
  const equalsString = (row, columnId, filterValue) => {
989
- return row.getValue(columnId).toLowerCase() === filterValue.toLowerCase();
993
+ var _row$getValue3;
994
+
995
+ return ((_row$getValue3 = row.getValue(columnId)) == null ? void 0 : _row$getValue3.toLowerCase()) === filterValue.toLowerCase();
990
996
  };
991
997
 
992
998
  equalsString.autoRemove = val => testFalsey(val);
993
999
 
994
1000
  const arrIncludes = (row, columnId, filterValue) => {
995
- return row.getValue(columnId).includes(filterValue);
1001
+ var _row$getValue4;
1002
+
1003
+ return (_row$getValue4 = row.getValue(columnId)) == null ? void 0 : _row$getValue4.includes(filterValue);
996
1004
  };
997
1005
 
998
1006
  arrIncludes.autoRemove = val => testFalsey(val) || !(val != null && val.length);
999
1007
 
1000
1008
  const arrIncludesAll = (row, columnId, filterValue) => {
1001
- return !filterValue.some(val => !row.getValue(columnId).includes(val));
1009
+ return !filterValue.some(val => {
1010
+ var _row$getValue5;
1011
+
1012
+ return !((_row$getValue5 = row.getValue(columnId)) != null && _row$getValue5.includes(val));
1013
+ });
1002
1014
  };
1003
1015
 
1004
1016
  arrIncludesAll.autoRemove = val => testFalsey(val) || !(val != null && val.length);
1005
1017
 
1006
1018
  const arrIncludesSome = (row, columnId, filterValue) => {
1007
- return filterValue.some(val => row.getValue(columnId).includes(val));
1019
+ return filterValue.some(val => {
1020
+ var _row$getValue6;
1021
+
1022
+ return (_row$getValue6 = row.getValue(columnId)) == null ? void 0 : _row$getValue6.includes(val);
1023
+ });
1008
1024
  };
1009
1025
 
1010
1026
  arrIncludesSome.autoRemove = val => testFalsey(val) || !(val != null && val.length);
@@ -1689,7 +1705,7 @@
1689
1705
  setPageIndex: updater => {
1690
1706
  instance.setPagination(old => {
1691
1707
  let pageIndex = functionalUpdate(updater, old.pageIndex);
1692
- const maxPageIndex = typeof old.pageCount !== 'undefined' ? old.pageCount - 1 : Number.MAX_SAFE_INTEGER;
1708
+ const maxPageIndex = typeof instance.options.pageCount === 'undefined' || instance.options.pageCount === -1 ? Number.MAX_SAFE_INTEGER : instance.options.pageCount - 1;
1693
1709
  pageIndex = Math.min(Math.max(0, pageIndex), maxPageIndex);
1694
1710
  return { ...old,
1695
1711
  pageIndex
@@ -1718,9 +1734,9 @@
1718
1734
  });
1719
1735
  },
1720
1736
  setPageCount: updater => instance.setPagination(old => {
1721
- var _old$pageCount;
1737
+ var _instance$options$pag;
1722
1738
 
1723
- let newPageCount = functionalUpdate(updater, (_old$pageCount = old.pageCount) != null ? _old$pageCount : -1);
1739
+ let newPageCount = functionalUpdate(updater, (_instance$options$pag = instance.options.pageCount) != null ? _instance$options$pag : -1);
1724
1740
 
1725
1741
  if (typeof newPageCount === 'number') {
1726
1742
  newPageCount = Math.max(-1, newPageCount);
@@ -1730,7 +1746,7 @@
1730
1746
  pageCount: newPageCount
1731
1747
  };
1732
1748
  }),
1733
- getPageOptions: memo(() => [instance.getState().pagination.pageSize, instance.getState().pagination.pageCount], (pageSize, pageCount) => {
1749
+ getPageOptions: memo(() => [instance.getPageCount()], pageCount => {
1734
1750
  let pageOptions = [];
1735
1751
 
1736
1752
  if (pageCount && pageCount > 0) {
@@ -1784,15 +1800,9 @@
1784
1800
  return instance._getPaginationRowModel();
1785
1801
  },
1786
1802
  getPageCount: () => {
1787
- const {
1788
- pageCount
1789
- } = instance.getState().pagination;
1803
+ var _instance$options$pag2;
1790
1804
 
1791
- if (typeof pageCount !== 'undefined') {
1792
- return pageCount;
1793
- }
1794
-
1795
- return Math.ceil(instance.getPrePaginationRowModel().rows.length / instance.getState().pagination.pageSize);
1805
+ return (_instance$options$pag2 = instance.options.pageCount) != null ? _instance$options$pag2 : Math.ceil(instance.getPrePaginationRowModel().rows.length / instance.getState().pagination.pageSize);
1796
1806
  }
1797
1807
  };
1798
1808
  }
@@ -3225,8 +3235,6 @@
3225
3235
  function filterRowModelFromLeafs(rowsToFilter, filterRow, instance) {
3226
3236
  const newFilteredFlatRows = [];
3227
3237
  const newFilteredRowsById = {};
3228
- let row;
3229
- let newRow;
3230
3238
 
3231
3239
  const recurseFilterRows = function (rowsToFilter, depth) {
3232
3240
  if (depth === void 0) {
@@ -3238,10 +3246,10 @@
3238
3246
  for (let i = 0; i < rowsToFilter.length; i++) {
3239
3247
  var _row$subRows;
3240
3248
 
3241
- row = rowsToFilter[i];
3249
+ let row = rowsToFilter[i];
3242
3250
 
3243
3251
  if ((_row$subRows = row.subRows) != null && _row$subRows.length) {
3244
- newRow = createRow(instance, row.id, row.original, row.index, row.depth);
3252
+ const newRow = createRow(instance, row.id, row.original, row.index, row.depth);
3245
3253
  newRow.columnFilters = row.columnFilters;
3246
3254
  newRow.subRows = recurseFilterRows(row.subRows, depth + 1);
3247
3255
 
@@ -3270,10 +3278,7 @@
3270
3278
  }
3271
3279
  function filterRowModelFromRoot(rowsToFilter, filterRow, instance) {
3272
3280
  const newFilteredFlatRows = [];
3273
- const newFilteredRowsById = {};
3274
- let rows;
3275
- let row;
3276
- let newRow; // Filters top level and nested rows
3281
+ const newFilteredRowsById = {}; // Filters top level and nested rows
3277
3282
 
3278
3283
  const recurseFilterRows = function (rowsToFilter, depth) {
3279
3284
  if (depth === void 0) {
@@ -3281,17 +3286,17 @@
3281
3286
  }
3282
3287
 
3283
3288
  // Filter from parents downward first
3284
- rows = []; // Apply the filter to any subRows
3289
+ const rows = []; // Apply the filter to any subRows
3285
3290
 
3286
3291
  for (let i = 0; i < rowsToFilter.length; i++) {
3287
- row = rowsToFilter[i];
3292
+ let row = rowsToFilter[i];
3288
3293
  const pass = filterRow(row);
3289
3294
 
3290
3295
  if (pass) {
3291
3296
  var _row$subRows2;
3292
3297
 
3293
3298
  if ((_row$subRows2 = row.subRows) != null && _row$subRows2.length) {
3294
- newRow = createRow(instance, row.id, row.original, row.index, row.depth);
3299
+ const newRow = createRow(instance, row.id, row.original, row.index, row.depth);
3295
3300
  newRow.subRows = recurseFilterRows(row.subRows, depth + 1);
3296
3301
  row = newRow;
3297
3302
  }