@tanstack/react-table 8.0.0-alpha.3 → 8.0.0-alpha.6

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.
Files changed (45) hide show
  1. package/build/cjs/core.js +1 -1
  2. package/build/cjs/core.js.map +1 -1
  3. package/build/cjs/createTable.js.map +1 -1
  4. package/build/cjs/features/Expanding.js +5 -9
  5. package/build/cjs/features/Expanding.js.map +1 -1
  6. package/build/cjs/features/Filters.js +3 -3
  7. package/build/cjs/features/Filters.js.map +1 -1
  8. package/build/cjs/features/Grouping.js +2 -2
  9. package/build/cjs/features/Grouping.js.map +1 -1
  10. package/build/cjs/features/Pagination.js +24 -20
  11. package/build/cjs/features/Pagination.js.map +1 -1
  12. package/build/cjs/features/Pinning.js +2 -2
  13. package/build/cjs/features/Pinning.js.map +1 -1
  14. package/build/cjs/features/Sorting.js +2 -2
  15. package/build/cjs/features/Sorting.js.map +1 -1
  16. package/build/cjs/index.js +2 -0
  17. package/build/cjs/index.js.map +1 -1
  18. package/build/cjs/utils/paginateRowsFn.js +44 -0
  19. package/build/cjs/utils/paginateRowsFn.js.map +1 -0
  20. package/build/cjs/utils.js +9 -14
  21. package/build/cjs/utils.js.map +1 -1
  22. package/build/esm/index.js +75 -54
  23. package/build/esm/index.js.map +1 -1
  24. package/build/stats-html.html +1 -1
  25. package/build/stats-react.json +266 -234
  26. package/build/types/core.d.ts +0 -2
  27. package/build/types/createTable.d.ts +1 -2
  28. package/build/types/features/Pagination.d.ts +5 -4
  29. package/build/types/index.d.ts +2 -1
  30. package/build/types/utils.d.ts +0 -4
  31. package/build/umd/index.development.js +75 -53
  32. package/build/umd/index.development.js.map +1 -1
  33. package/build/umd/index.production.js +1 -1
  34. package/build/umd/index.production.js.map +1 -1
  35. package/package.json +1 -1
  36. package/src/core.tsx +1 -92
  37. package/src/createTable.tsx +1 -1
  38. package/src/features/Expanding.ts +5 -3
  39. package/src/features/Filters.ts +4 -4
  40. package/src/features/Grouping.ts +1 -1
  41. package/src/features/Pagination.ts +44 -33
  42. package/src/features/Pinning.ts +1 -3
  43. package/src/features/Sorting.ts +1 -1
  44. package/src/index.tsx +2 -1
  45. package/src/utils.tsx +7 -69
@@ -76,8 +76,6 @@ export declare type CoreColumnDef<TData, TValue, TFilterFns, TSortingFns, TAggre
76
76
  header: Header<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>;
77
77
  column: Column<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>;
78
78
  }>;
79
- } & // | Renderable<{ // | string // header?: // accessorKey?: never // id: string // accessorFn: AccessorFn<TData> // | {
80
- {
81
79
  __generated: true;
82
80
  width?: number;
83
81
  minWidth?: number;
@@ -1,7 +1,7 @@
1
1
  import { Cell, Column, Row } from '.';
2
2
  import { ReactTable, ColumnDef, AccessorFn, Options, Renderable, Header } from './types';
3
3
  import { Overwrite } from './utils';
4
- declare type TableHelper<TData, TValue, TFilterFns, TSortingFns, TAggregationFns> = {
4
+ export declare type TableHelper<TData, TValue, TFilterFns, TSortingFns, TAggregationFns> = {
5
5
  RowType<TTData>(): TableHelper<TTData, TValue, TFilterFns, TSortingFns, TAggregationFns>;
6
6
  FilterFns: <TTFilterFns>(filterFns: TTFilterFns) => TableHelper<TData, TValue, TTFilterFns, TSortingFns, TAggregationFns>;
7
7
  SortingFns: <TTSortingFns>(sortingFns: TTSortingFns) => TableHelper<TData, TValue, TFilterFns, TTSortingFns, TAggregationFns>;
@@ -50,4 +50,3 @@ declare type TableHelper<TData, TValue, TFilterFns, TSortingFns, TAggregationFns
50
50
  };
51
51
  };
52
52
  export declare function createTable<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>(): TableHelper<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>;
53
- export {};
@@ -1,8 +1,9 @@
1
1
  import { OnChangeFn, ReactTable, Row, RowModel, Updater } from '../types';
2
+ export declare type PageCount = undefined | null | number;
2
3
  export declare type PaginationState = {
3
4
  pageIndex: number;
4
5
  pageSize: number;
5
- pageCount: number;
6
+ pageCount?: PageCount;
6
7
  };
7
8
  export declare type PaginationTableState = {
8
9
  pagination: PaginationState;
@@ -24,12 +25,12 @@ export declare type PaginationInstance<TData, TValue, TFilterFns, TSortingFns, T
24
25
  resetPageIndex: () => void;
25
26
  setPageSize: (updater: Updater<number>) => void;
26
27
  resetPageSize: () => void;
27
- setPageCount: (updater: Updater<number>) => void;
28
+ setPageCount: (updater: Updater<PageCount>) => void;
28
29
  getPageOptions: () => number[];
29
30
  getCanPreviousPage: () => boolean;
30
31
  getCanNextPage: () => boolean;
31
- gotoPreviousPage: () => void;
32
- gotoNextPage: () => void;
32
+ previousPage: () => void;
33
+ nextPage: () => void;
33
34
  getPaginationRowModel: () => RowModel<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>;
34
35
  getPrePaginationRows: () => Row<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>[];
35
36
  getPrePaginationFlatRows: () => Row<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>[];
@@ -4,4 +4,5 @@ export * from './utils/globalFilterRowsFn';
4
4
  export * from './utils/sortRowsFn';
5
5
  export * from './utils/groupRowsFn';
6
6
  export * from './utils/expandRowsFn';
7
- export { createTable } from './createTable';
7
+ export * from './utils/paginateRowsFn';
8
+ export * from './createTable';
@@ -9,9 +9,6 @@ export declare type Updater<TInput, TOutput> = TOutput | DataUpdateFunction<TInp
9
9
  export declare function functionalUpdate<TInput, TOutput = TInput>(updater: Updater<TInput, TOutput>, input: TInput): TOutput;
10
10
  export declare function noop(): void;
11
11
  export declare function makeStateUpdater(key: keyof TableState, instance: unknown): (updater: Updater<any, any>) => void;
12
- export declare const safeUseLayoutEffect: typeof React.useLayoutEffect;
13
- export declare function useMountedLayoutEffect(fn: any, deps: any[]): void;
14
- export declare function useGetLatest<T>(obj: T): () => T;
15
12
  declare type AnyFunction = (...args: any) => any;
16
13
  export declare function isFunction<T extends AnyFunction>(d: any): d is T;
17
14
  export declare function flattenBy<TNode>(arr: TNode[], getChildren: (item: TNode) => TNode[]): TNode[];
@@ -22,7 +19,6 @@ export declare function memo<TDeps extends readonly any[], TResult>(getDeps: ()
22
19
  debug?: boolean;
23
20
  onChange?: (result: TResult, previousResult?: TResult) => void;
24
21
  }): () => TResult;
25
- export declare function isPlainObject(o: any): o is Object;
26
22
  export declare type Render = typeof flexRender;
27
23
  export declare function flexRender<TProps extends {}>(Comp: Renderable<TProps>, props: TProps): React.ReactNode;
28
24
  export {};
@@ -416,9 +416,7 @@
416
416
  return _extends({}, old, (_extends2 = {}, _extends2[key] = functionalUpdate(updater, old[key]), _extends2));
417
417
  });
418
418
  };
419
- } // SSR has issues with useLayoutEffect still, so use useEffect during SSR
420
-
421
- typeof document !== 'undefined' ? React__default["default"].useLayoutEffect : React__default["default"].useEffect;
419
+ }
422
420
  function isFunction(d) {
423
421
  return d instanceof Function;
424
422
  }
@@ -452,19 +450,17 @@
452
450
  var result;
453
451
  return function () {
454
452
  var newDeps = getDeps();
455
- var newSerializedDeps = newDeps;
456
- var oldSerializedDeps = deps;
457
- var depsChanged = newSerializedDeps.length !== oldSerializedDeps.length || newSerializedDeps.some(function (dep, index) {
458
- return oldSerializedDeps[index] !== dep;
453
+ var depsChanged = newDeps.length !== deps.length || newDeps.some(function (dep, index) {
454
+ return deps[index] !== dep;
459
455
  });
460
456
 
461
457
  if (depsChanged) {
462
458
  if (opts != null && opts.debug) {
463
459
  console.info(opts == null ? void 0 : opts.key, _extends({
464
- length: oldSerializedDeps.length + " -> " + newSerializedDeps.length
465
- }, newSerializedDeps.map(function (_, index) {
466
- if (oldSerializedDeps[index] !== newSerializedDeps[index]) {
467
- return [index, oldSerializedDeps[index], newSerializedDeps[index]];
460
+ length: deps.length + " -> " + newDeps.length
461
+ }, newDeps.map(function (_, index) {
462
+ if (deps[index] !== newDeps[index]) {
463
+ return [index, deps[index], newDeps[index]];
468
464
  }
469
465
 
470
466
  return false;
@@ -479,15 +475,14 @@
479
475
 
480
476
  var oldResult = result;
481
477
  result = fn.apply(void 0, newDeps);
482
- deps = newSerializedDeps;
478
+ deps = newDeps;
483
479
  opts == null ? void 0 : opts.onChange == null ? void 0 : opts.onChange(result, oldResult);
484
480
  oldResult = undefined;
485
481
  }
486
482
 
487
483
  return result;
488
484
  };
489
- } // Copied from: https://github.com/jonschlinkert/is-plain-object
490
-
485
+ }
491
486
  function flexRender(Comp, props) {
492
487
  return !Comp ? null : isReactComponent(Comp) ? /*#__PURE__*/React__default["default"].createElement(Comp, props) : Comp;
493
488
  }
@@ -681,6 +676,32 @@
681
676
  };
682
677
  }
683
678
 
679
+ function paginateRowsFn(instance, rowModel) {
680
+ var _instance$getState$pa = instance.getState().pagination,
681
+ pageSize = _instance$getState$pa.pageSize,
682
+ pageIndex = _instance$getState$pa.pageIndex;
683
+ var rows = rowModel.rows,
684
+ flatRows = rowModel.flatRows,
685
+ rowsById = rowModel.rowsById;
686
+ var pageStart = pageSize * pageIndex;
687
+ var pageEnd = pageStart + pageSize;
688
+ rows = rows.slice(pageStart, pageEnd);
689
+
690
+ if (!instance.options.paginateExpandedRows) {
691
+ return expandRowsFn(instance, {
692
+ rows: rows,
693
+ flatRows: flatRows,
694
+ rowsById: rowsById
695
+ });
696
+ }
697
+
698
+ return {
699
+ rows: rows,
700
+ flatRows: flatRows,
701
+ rowsById: rowsById
702
+ };
703
+ }
704
+
684
705
  //
685
706
  function getInitialState$9() {
686
707
  return {
@@ -1063,9 +1084,9 @@
1063
1084
  return (_instance$getState$gr2 = instance.getState().grouping) == null ? void 0 : _instance$getState$gr2.indexOf(columnId);
1064
1085
  },
1065
1086
  resetGrouping: function resetGrouping() {
1066
- var _instance$options$ini, _instance$options, _instance$options$ini2;
1087
+ var _instance$initialStat, _instance$initialStat2;
1067
1088
 
1068
- instance.setGrouping((_instance$options$ini = (_instance$options = instance.options) == null ? void 0 : (_instance$options$ini2 = _instance$options.initialState) == null ? void 0 : _instance$options$ini2.grouping) != null ? _instance$options$ini : []);
1089
+ instance.setGrouping((_instance$initialStat = (_instance$initialStat2 = instance.initialState) == null ? void 0 : _instance$initialStat2.grouping) != null ? _instance$initialStat : []);
1069
1090
  },
1070
1091
  getToggleGroupingProps: function getToggleGroupingProps(columnId, userProps) {
1071
1092
  var column = instance.getColumn(columnId);
@@ -1288,9 +1309,9 @@
1288
1309
  return instance.options.onColumnPinningChange == null ? void 0 : instance.options.onColumnPinningChange(updater, functionalUpdate(updater, instance.getState().columnPinning));
1289
1310
  },
1290
1311
  resetColumnPinning: function resetColumnPinning() {
1291
- var _instance$options$ini, _instance$options$ini2;
1312
+ var _instance$initialStat, _instance$initialStat2;
1292
1313
 
1293
- return instance.setColumnPinning((_instance$options$ini = (_instance$options$ini2 = instance.options.initialState) == null ? void 0 : _instance$options$ini2.columnPinning) != null ? _instance$options$ini : {});
1314
+ return instance.setColumnPinning((_instance$initialStat = (_instance$initialStat2 = instance.initialState) == null ? void 0 : _instance$initialStat2.columnPinning) != null ? _instance$initialStat : {});
1294
1315
  },
1295
1316
  pinColumn: function pinColumn(columnId, position) {
1296
1317
  var column = instance.getColumn(columnId);
@@ -2372,9 +2393,9 @@
2372
2393
  });
2373
2394
  },
2374
2395
  resetColumnFilters: function resetColumnFilters() {
2375
- var _instance$options$ini, _instance$options2, _instance$options2$in;
2396
+ var _instance$initialStat, _instance$initialStat2;
2376
2397
 
2377
- instance.setColumnFilters((_instance$options$ini = (_instance$options2 = instance.options) == null ? void 0 : (_instance$options2$in = _instance$options2.initialState) == null ? void 0 : _instance$options2$in.columnFilters) != null ? _instance$options$ini : []);
2398
+ instance.setColumnFilters((_instance$initialStat = (_instance$initialStat2 = instance.initialState) == null ? void 0 : _instance$initialStat2.columnFilters) != null ? _instance$initialStat : []);
2378
2399
  },
2379
2400
  getColumnFilteredRowModel: memo(function () {
2380
2401
  return [instance.getState().columnFilters, instance.getCoreRowModel(), instance.options.columnFilterRowsFn];
@@ -2474,7 +2495,7 @@
2474
2495
  key: 'getGlobalFilteredRowModel',
2475
2496
  debug: instance.options.debug,
2476
2497
  onChange: function onChange() {
2477
- return instance._notifySortingReset();
2498
+ instance._notifySortingReset();
2478
2499
  }
2479
2500
  }),
2480
2501
  getPreGlobalFilteredRows: function getPreGlobalFilteredRows() {
@@ -2861,9 +2882,9 @@
2861
2882
  })) != null ? _instance$getState$so2 : -1;
2862
2883
  },
2863
2884
  resetSorting: function resetSorting() {
2864
- var _instance$options$ini, _instance$options, _instance$options$ini2;
2885
+ var _instance$initialStat, _instance$initialStat2;
2865
2886
 
2866
- instance.setSorting((_instance$options$ini = (_instance$options = instance.options) == null ? void 0 : (_instance$options$ini2 = _instance$options.initialState) == null ? void 0 : _instance$options$ini2.sorting) != null ? _instance$options$ini : []);
2887
+ instance.setSorting((_instance$initialStat = (_instance$initialStat2 = instance.initialState) == null ? void 0 : _instance$initialStat2.sorting) != null ? _instance$initialStat : []);
2867
2888
  },
2868
2889
  getToggleSortingProps: function getToggleSortingProps(columnId, userProps) {
2869
2890
  var column = instance.getColumn(columnId);
@@ -2968,13 +2989,9 @@
2968
2989
  toggleRowExpanded: function toggleRowExpanded(rowId, expanded) {
2969
2990
  if (!rowId) return;
2970
2991
  instance.setExpanded(function (old) {
2971
- var _old, _expanded;
2972
-
2973
- if (old === void 0) {
2974
- old = {};
2975
- }
2992
+ var _expanded;
2976
2993
 
2977
- var exists = old === true ? true : !!((_old = old) != null && _old[rowId]);
2994
+ var exists = old === true ? true : !!(old != null && old[rowId]);
2978
2995
  var oldExpanded = {};
2979
2996
 
2980
2997
  if (old === true) {
@@ -3012,9 +3029,9 @@
3012
3029
  }
3013
3030
  },
3014
3031
  resetExpanded: function resetExpanded() {
3015
- var _instance$options$ini, _instance$options, _instance$options$ini2;
3032
+ var _instance$initialStat, _instance$initialStat2;
3016
3033
 
3017
- instance.setExpanded((_instance$options$ini = (_instance$options = instance.options) == null ? void 0 : (_instance$options$ini2 = _instance$options.initialState) == null ? void 0 : _instance$options$ini2.expanded) != null ? _instance$options$ini : {});
3034
+ instance.setExpanded((_instance$initialStat = (_instance$initialStat2 = instance.initialState) == null ? void 0 : _instance$initialStat2.expanded) != null ? _instance$initialStat : {});
3018
3035
  },
3019
3036
  getIsRowExpanded: function getIsRowExpanded(rowId) {
3020
3037
  var _instance$options$get;
@@ -3114,7 +3131,7 @@
3114
3131
  key: 'getExpandedRowModel',
3115
3132
  debug: instance.options.debug,
3116
3133
  onChange: function onChange() {
3117
- return instance._notifyPageIndexReset();
3134
+ instance._notifyPageIndexReset();
3118
3135
  }
3119
3136
  }),
3120
3137
  getPreExpandedRows: function getPreExpandedRows() {
@@ -3477,8 +3494,7 @@
3477
3494
  return {
3478
3495
  pagination: {
3479
3496
  pageIndex: 0,
3480
- pageSize: 10,
3481
- pageCount: -1
3497
+ pageSize: 10
3482
3498
  }
3483
3499
  };
3484
3500
  }
@@ -3507,17 +3523,15 @@
3507
3523
  },
3508
3524
  setPagination: function setPagination(updater) {
3509
3525
  var safeUpdater = function safeUpdater(old) {
3510
- functionalUpdate(old, updater);
3526
+ var newState = functionalUpdate(updater, old);
3511
3527
 
3512
- if (!instance.options.paginateRowsFn) {
3513
- var _instance$getPreExpan;
3528
+ if (instance.options.paginateRowsFn) {
3529
+ var _instance$getPrePagin;
3514
3530
 
3515
- return _extends({}, old, {
3516
- pageCount: (_instance$getPreExpan = instance.getPreExpandedRows()) != null && _instance$getPreExpan.length ? Math.ceil(instance.getPreExpandedRows().length / instance.getState().pagination.pageSize) : 0
3517
- });
3531
+ newState.pageCount = (_instance$getPrePagin = instance.getPrePaginationRows()) != null && _instance$getPrePagin.length ? Math.ceil(instance.getPrePaginationRows().length / instance.getState().pagination.pageSize) : 0;
3518
3532
  }
3519
3533
 
3520
- return old;
3534
+ return newState;
3521
3535
  };
3522
3536
 
3523
3537
  return instance.options.onPaginationChange == null ? void 0 : instance.options.onPaginationChange(safeUpdater, functionalUpdate(safeUpdater, instance.getState().pagination));
@@ -3533,10 +3547,11 @@
3533
3547
  },
3534
3548
  setPageIndex: function setPageIndex(updater) {
3535
3549
  instance.setPagination(function (old) {
3536
- var newPageIndex = functionalUpdate(updater, old.pageIndex);
3537
- var maxPageIndex = old.pageCount > 0 ? old.pageCount - 1 : Number.MAX_SAFE_INTEGER;
3550
+ var pageIndex = functionalUpdate(updater, old.pageIndex);
3551
+ var maxPageIndex = old.pageCount && old.pageCount > 0 ? old.pageCount - 1 : Number.MAX_SAFE_INTEGER;
3552
+ pageIndex = Math.min(Math.max(0, pageIndex), maxPageIndex);
3538
3553
  return _extends({}, old, {
3539
- pageIndex: Math.min(Math.max(0, newPageIndex), maxPageIndex)
3554
+ pageIndex: pageIndex
3540
3555
  });
3541
3556
  });
3542
3557
  },
@@ -3544,9 +3559,9 @@
3544
3559
  instance.setPageIndex(0);
3545
3560
  },
3546
3561
  resetPageSize: function resetPageSize() {
3547
- var _instance$options$ini, _instance$options$ini2, _instance$options$ini3;
3562
+ var _instance$initialStat2, _instance$initialStat3, _instance$initialStat4;
3548
3563
 
3549
- instance.setPageSize((_instance$options$ini = (_instance$options$ini2 = instance.options.initialState) == null ? void 0 : (_instance$options$ini3 = _instance$options$ini2.pagination) == null ? void 0 : _instance$options$ini3.pageSize) != null ? _instance$options$ini : 10);
3564
+ instance.setPageSize((_instance$initialStat2 = (_instance$initialStat3 = instance.initialState) == null ? void 0 : (_instance$initialStat4 = _instance$initialStat3.pagination) == null ? void 0 : _instance$initialStat4.pageSize) != null ? _instance$initialStat2 : 10);
3550
3565
  },
3551
3566
  setPageSize: function setPageSize(updater) {
3552
3567
  instance.setPagination(function (old) {
@@ -3561,8 +3576,14 @@
3561
3576
  },
3562
3577
  setPageCount: function setPageCount(updater) {
3563
3578
  return instance.setPagination(function (old) {
3579
+ var newPageCount = functionalUpdate(updater, old.pageCount);
3580
+
3581
+ if (typeof newPageCount === 'number') {
3582
+ newPageCount = Math.max(-1, newPageCount);
3583
+ }
3584
+
3564
3585
  return _extends({}, old, {
3565
- pageCount: Math.max(-1, functionalUpdate(updater, old.pageCount))
3586
+ pageCount: newPageCount
3566
3587
  });
3567
3588
  });
3568
3589
  },
@@ -3571,7 +3592,7 @@
3571
3592
  }, function (pageSize, pageCount) {
3572
3593
  var pageOptions = [];
3573
3594
 
3574
- if (pageCount > 0) {
3595
+ if (pageCount && pageCount > 0) {
3575
3596
  pageOptions = [].concat(new Array(pageCount)).fill(null).map(function (_, i) {
3576
3597
  return i;
3577
3598
  });
@@ -3601,13 +3622,13 @@
3601
3622
 
3602
3623
  return pageIndex < Math.ceil(instance.getPrePaginationRows().length / pageSize) - 1;
3603
3624
  },
3604
- gotoPreviousPage: function gotoPreviousPage() {
3605
- return instance.setPageIndex == null ? void 0 : instance.setPageIndex(function (old) {
3625
+ previousPage: function previousPage() {
3626
+ return instance.setPageIndex(function (old) {
3606
3627
  return old - 1;
3607
3628
  });
3608
3629
  },
3609
- gotoNextPage: function gotoNextPage() {
3610
- return instance.setPageIndex == null ? void 0 : instance.setPageIndex(function (old) {
3630
+ nextPage: function nextPage() {
3631
+ return instance.setPageIndex(function (old) {
3611
3632
  return old + 1;
3612
3633
  });
3613
3634
  },
@@ -4579,7 +4600,7 @@
4579
4600
  // The final calls start at the bottom of the model,
4580
4601
  // expanded rows, which then work their way up
4581
4602
  getRowModel: function getRowModel() {
4582
- return instance.getExpandedRowModel();
4603
+ return instance.getPaginationRowModel();
4583
4604
  },
4584
4605
  getRows: function getRows() {
4585
4606
  return instance.getRowModel().rows;
@@ -4766,6 +4787,7 @@
4766
4787
  exports.expandRowsFn = expandRowsFn;
4767
4788
  exports.globalFilterRowsFn = globalFilterRowsFn;
4768
4789
  exports.groupRowsFn = groupRowsFn;
4790
+ exports.paginateRowsFn = paginateRowsFn;
4769
4791
  exports.sortRowsFn = sortRowsFn;
4770
4792
 
4771
4793
  Object.defineProperty(exports, '__esModule', { value: true });