@tanstack/table-core 8.0.0-alpha.11 → 8.0.0-alpha.14

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 (74) hide show
  1. package/build/cjs/core.js +17 -6
  2. package/build/cjs/core.js.map +1 -1
  3. package/build/cjs/createTable.js +17 -9
  4. package/build/cjs/createTable.js.map +1 -1
  5. package/build/cjs/features/ColumnSizing.js +2 -2
  6. package/build/cjs/features/ColumnSizing.js.map +1 -1
  7. package/build/cjs/features/Expanding.js +2 -2
  8. package/build/cjs/features/Expanding.js.map +1 -1
  9. package/build/cjs/features/Filters.js +1 -1
  10. package/build/cjs/features/Filters.js.map +1 -1
  11. package/build/cjs/features/Grouping.js +13 -2
  12. package/build/cjs/features/Grouping.js.map +1 -1
  13. package/build/cjs/features/Headers.js +4 -4
  14. package/build/cjs/features/Headers.js.map +1 -1
  15. package/build/cjs/features/RowSelection.js.map +1 -1
  16. package/build/cjs/features/Sorting.js +14 -3
  17. package/build/cjs/features/Sorting.js.map +1 -1
  18. package/build/cjs/features/Visibility.js.map +1 -1
  19. package/build/cjs/index.js +1 -3
  20. package/build/cjs/index.js.map +1 -1
  21. package/build/cjs/types.js +0 -3
  22. package/build/cjs/types.js.map +1 -1
  23. package/build/cjs/utils/columnFilterRowsFn.js +1 -1
  24. package/build/cjs/utils/columnFilterRowsFn.js.map +1 -1
  25. package/build/cjs/utils/expandRowsFn.js.map +1 -1
  26. package/build/cjs/utils/globalFilterRowsFn.js.map +1 -1
  27. package/build/cjs/utils/groupRowsFn.js +1 -1
  28. package/build/cjs/utils/groupRowsFn.js.map +1 -1
  29. package/build/cjs/utils/paginateRowsFn.js.map +1 -1
  30. package/build/cjs/utils/sortRowsFn.js.map +1 -1
  31. package/build/cjs/utils.js +0 -24
  32. package/build/cjs/utils.js.map +1 -1
  33. package/build/esm/index.js +72 -53
  34. package/build/esm/index.js.map +1 -1
  35. package/build/stats-html.html +1 -1
  36. package/build/stats-react.json +270 -284
  37. package/build/types/core.d.ts +11 -9
  38. package/build/types/createTable.d.ts +32 -16
  39. package/build/types/features/ColumnSizing.d.ts +2 -3
  40. package/build/types/features/Grouping.d.ts +11 -5
  41. package/build/types/features/RowSelection.d.ts +2 -3
  42. package/build/types/features/Sorting.d.ts +2 -1
  43. package/build/types/features/Visibility.d.ts +1 -0
  44. package/build/types/types.d.ts +14 -7
  45. package/build/types/utils/columnFilterRowsFn.d.ts +2 -2
  46. package/build/types/utils/expandRowsFn.d.ts +2 -2
  47. package/build/types/utils/globalFilterRowsFn.d.ts +2 -2
  48. package/build/types/utils/groupRowsFn.d.ts +2 -2
  49. package/build/types/utils/paginateRowsFn.d.ts +2 -2
  50. package/build/types/utils/sortRowsFn.d.ts +2 -2
  51. package/build/types/utils.d.ts +4 -5
  52. package/build/umd/index.development.js +76 -61
  53. package/build/umd/index.development.js.map +1 -1
  54. package/build/umd/index.production.js +1 -1
  55. package/build/umd/index.production.js.map +1 -1
  56. package/package.json +1 -1
  57. package/src/core.tsx +63 -35
  58. package/src/createTable.tsx +69 -34
  59. package/src/features/ColumnSizing.ts +8 -14
  60. package/src/features/Expanding.ts +2 -2
  61. package/src/features/Filters.ts +1 -1
  62. package/src/features/Grouping.ts +30 -7
  63. package/src/features/Headers.ts +15 -3
  64. package/src/features/RowSelection.ts +2 -2
  65. package/src/features/Sorting.ts +11 -3
  66. package/src/features/Visibility.ts +1 -0
  67. package/src/types.ts +28 -15
  68. package/src/utils/columnFilterRowsFn.ts +3 -5
  69. package/src/utils/expandRowsFn.ts +2 -2
  70. package/src/utils/globalFilterRowsFn.ts +2 -2
  71. package/src/utils/groupRowsFn.ts +4 -4
  72. package/src/utils/paginateRowsFn.ts +2 -2
  73. package/src/utils/sortRowsFn.ts +2 -2
  74. package/src/utils.tsx +6 -45
@@ -9,14 +9,10 @@
9
9
  * @license MIT
10
10
  */
11
11
  (function (global, factory) {
12
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react')) :
13
- typeof define === 'function' && define.amd ? define(['exports', 'react'], factory) :
14
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.TableCore = {}, global.React));
15
- })(this, (function (exports, React) { 'use strict';
16
-
17
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
18
-
19
- var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
12
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
13
+ typeof define === 'function' && define.amd ? define(['exports'], factory) :
14
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.TableCore = {}));
15
+ })(this, (function (exports) { 'use strict';
20
16
 
21
17
  function _extends() {
22
18
  _extends = Object.assign || function (target) {
@@ -210,24 +206,6 @@
210
206
 
211
207
  return result;
212
208
  };
213
- }
214
- function flexRender(Comp, props) {
215
- return !Comp ? null : isReactComponent(Comp) ? /*#__PURE__*/React__default["default"].createElement(Comp, props) : Comp;
216
- }
217
-
218
- function isReactComponent(component) {
219
- return isClassComponent(component) || typeof component === 'function' || isExoticComponent(component);
220
- }
221
-
222
- function isClassComponent(component) {
223
- return typeof component === 'function' && function () {
224
- var proto = Object.getPrototypeOf(component);
225
- return proto.prototype && proto.prototype.isReactComponent;
226
- }();
227
- }
228
-
229
- function isExoticComponent(component) {
230
- return typeof component === 'object' && typeof component.$$typeof === 'symbol' && ['react.memo', 'react.forward_ref'].includes(component.$$typeof.description);
231
209
  } // export function hashString(str: string, seed = 0): string {
232
210
  // let h1 = 0xdeadbeef ^ seed,
233
211
  // h2 = 0x41c6ce57 ^ seed
@@ -245,9 +223,6 @@
245
223
  // return (4294967296 * (2097151 & h2) + (h1 >>> 0)).toString()
246
224
  // }
247
225
 
248
- // declare global {
249
- // const "development" !== 'production': boolean
250
- // }
251
226
  //
252
227
  var Please_use_the_create_table_column_utilities_to_define_columns = Symbol();
253
228
 
@@ -645,7 +620,6 @@
645
620
  var initialProps = {
646
621
  title: canGroup ? 'Toggle Grouping' : undefined,
647
622
  onClick: canGroup ? function (e) {
648
- e.persist();
649
623
  column.toggleGrouping == null ? void 0 : column.toggleGrouping();
650
624
  } : undefined
651
625
  };
@@ -687,7 +661,7 @@
687
661
  }
688
662
  };
689
663
  },
690
- createCell: function createCell(cell, column, row, _instance) {
664
+ createCell: function createCell(cell, column, row, instance) {
691
665
  return {
692
666
  getIsGrouped: function getIsGrouped() {
693
667
  return column.getIsGrouped() && column.id === row.groupingColumnId;
@@ -699,6 +673,18 @@
699
673
  var _row$subRows;
700
674
 
701
675
  return !cell.getIsGrouped() && !cell.getIsPlaceholder() && ((_row$subRows = row.subRows) == null ? void 0 : _row$subRows.length) > 1;
676
+ },
677
+ renderAggregatedCell: function renderAggregatedCell() {
678
+ var _column$aggregatedCel;
679
+
680
+ var template = (_column$aggregatedCel = column.aggregatedCell) != null ? _column$aggregatedCel : column.cell;
681
+ return template ? instance.render(template, {
682
+ instance: instance,
683
+ column: column,
684
+ row: row,
685
+ cell: cell,
686
+ value: cell.value
687
+ }) : null;
702
688
  }
703
689
  };
704
690
  },
@@ -1144,11 +1130,11 @@
1144
1130
  draggable: false,
1145
1131
  role: 'separator',
1146
1132
  onMouseDown: function onMouseDown(e) {
1147
- e.persist();
1133
+ e.persist == null ? void 0 : e.persist();
1148
1134
  onResizeStart(e);
1149
1135
  },
1150
1136
  onTouchStart: function onTouchStart(e) {
1151
- e.persist();
1137
+ e.persist == null ? void 0 : e.persist();
1152
1138
  onResizeStart(e);
1153
1139
  }
1154
1140
  } : {};
@@ -1353,18 +1339,18 @@
1353
1339
  return instance.getFooterProps(header.id, userProps);
1354
1340
  },
1355
1341
  renderHeader: function renderHeader() {
1356
- return flexRender(column.header, {
1342
+ return column.header ? instance.render(column.header, {
1357
1343
  instance: instance,
1358
1344
  header: header,
1359
1345
  column: column
1360
- });
1346
+ }) : null;
1361
1347
  },
1362
1348
  renderFooter: function renderFooter() {
1363
- return flexRender(column.footer, {
1349
+ return column.footer ? instance.render(column.footer, {
1364
1350
  instance: instance,
1365
1351
  header: header,
1366
1352
  column: column
1367
- });
1353
+ }) : null;
1368
1354
  }
1369
1355
  }; // Yes, we have to convert instance to unknown, because we know more than the compiler here.
1370
1356
 
@@ -2234,7 +2220,7 @@
2234
2220
 
2235
2221
  if (!column) {
2236
2222
  {
2237
- console.warn("React-Table: Could not find a column with id: " + columnId);
2223
+ console.warn("Table: Could not find a column with id: " + columnId);
2238
2224
  }
2239
2225
 
2240
2226
  throw new Error();
@@ -2515,6 +2501,9 @@
2515
2501
  getIsSorted: function getIsSorted() {
2516
2502
  return instance.getColumnIsSorted(column.id);
2517
2503
  },
2504
+ resetSorting: function resetSorting() {
2505
+ return instance.resetSorting(column.id);
2506
+ },
2518
2507
  toggleSorting: function toggleSorting(desc, isMulti) {
2519
2508
  return instance.toggleColumnSorting(column.id, desc, isMulti);
2520
2509
  },
@@ -2724,10 +2713,18 @@
2724
2713
  return d.id === columnId;
2725
2714
  })) != null ? _instance$getState$so2 : -1;
2726
2715
  },
2727
- resetSorting: function resetSorting() {
2728
- var _instance$initialStat, _instance$initialStat2;
2716
+ resetSorting: function resetSorting(columnId) {
2717
+ if (columnId) {
2718
+ instance.setSorting(function (old) {
2719
+ return old != null && old.length ? old.filter(function (d) {
2720
+ return d.id !== columnId;
2721
+ }) : [];
2722
+ });
2723
+ } else {
2724
+ var _instance$initialStat, _instance$initialStat2;
2729
2725
 
2730
- instance.setSorting((_instance$initialStat = (_instance$initialStat2 = instance.initialState) == null ? void 0 : _instance$initialStat2.sorting) != null ? _instance$initialStat : []);
2726
+ instance.setSorting((_instance$initialStat = (_instance$initialStat2 = instance.initialState) == null ? void 0 : _instance$initialStat2.sorting) != null ? _instance$initialStat : []);
2727
+ }
2731
2728
  },
2732
2729
  getToggleSortingProps: function getToggleSortingProps(columnId, userProps) {
2733
2730
  var column = instance.getColumn(columnId);
@@ -2864,7 +2861,7 @@
2864
2861
 
2865
2862
  if (!row) {
2866
2863
  {
2867
- console.warn("[ReactTable] getIsRowExpanded: no row found with id " + rowId);
2864
+ console.warn("[Table] getIsRowExpanded: no row found with id " + rowId);
2868
2865
  }
2869
2866
 
2870
2867
  throw new Error();
@@ -2880,7 +2877,7 @@
2880
2877
 
2881
2878
  if (!row) {
2882
2879
  {
2883
- console.warn("[ReactTable] getRowCanExpand: no row found with id " + rowId);
2880
+ console.warn("[Table] getRowCanExpand: no row found with id " + rowId);
2884
2881
  }
2885
2882
 
2886
2883
  throw new Error();
@@ -3674,7 +3671,7 @@
3674
3671
  var _options$initialState;
3675
3672
 
3676
3673
  if (options.debugAll || options.debugTable) {
3677
- console.info('Creating React Table Instance...');
3674
+ console.info('Creating Table Instance...');
3678
3675
  }
3679
3676
 
3680
3677
  var instance = {};
@@ -3702,6 +3699,17 @@
3702
3699
  setOptions: function setOptions(updater) {
3703
3700
  instance.options = buildOptions(functionalUpdate(updater, instance.options));
3704
3701
  },
3702
+ render: function render(template, props) {
3703
+ if (typeof instance.options.render === 'function') {
3704
+ return instance.options.render(template, props);
3705
+ }
3706
+
3707
+ if (typeof template === 'function') {
3708
+ return template(props);
3709
+ }
3710
+
3711
+ return template;
3712
+ },
3705
3713
  getRowId: function getRowId(_, index, parent) {
3706
3714
  return "" + (parent ? [parent.id, index].join('.') : index);
3707
3715
  },
@@ -3892,7 +3900,7 @@
3892
3900
 
3893
3901
  if (!column) {
3894
3902
  {
3895
- console.warn("[React Table] Column with id " + columnId + " does not exist.");
3903
+ console.warn("[Table] Column with id " + columnId + " does not exist.");
3896
3904
  }
3897
3905
 
3898
3906
  throw new Error();
@@ -3924,13 +3932,13 @@
3924
3932
  return instance.getCellProps(row.id, column.id, userProps);
3925
3933
  },
3926
3934
  renderCell: function renderCell() {
3927
- return flexRender(column.cell, {
3935
+ return column.cell ? instance.render(column.cell, {
3928
3936
  instance: instance,
3929
3937
  column: column,
3930
3938
  row: row,
3931
3939
  cell: cell,
3932
3940
  value: value
3933
- });
3941
+ }) : null;
3934
3942
  }
3935
3943
  };
3936
3944
  features.forEach(function (feature) {
@@ -4094,7 +4102,7 @@
4094
4102
 
4095
4103
  if (!row) {
4096
4104
  {
4097
- throw new Error("[React Table] could not find row with id " + rowId);
4105
+ throw new Error("[Table] could not find row with id " + rowId);
4098
4106
  }
4099
4107
  }
4100
4108
 
@@ -4102,7 +4110,7 @@
4102
4110
 
4103
4111
  if (!cell) {
4104
4112
  {
4105
- throw new Error("[React Table] could not find cell " + columnId + " in row " + rowId);
4113
+ throw new Error("[Table] could not find cell " + columnId + " in row " + rowId);
4106
4114
  }
4107
4115
  }
4108
4116
 
@@ -4176,18 +4184,27 @@
4176
4184
  return instance;
4177
4185
  }
4178
4186
 
4179
- function createTableFactory(opts) {
4180
- return function () {
4181
- return _createTable(undefined, undefined, opts);
4187
+ //
4188
+ function init(opts) {
4189
+ return {
4190
+ createTableFactory: function createTableFactory(options) {
4191
+ return function () {
4192
+ return _createTable(undefined, undefined, _extends({}, options, opts));
4193
+ };
4194
+ },
4195
+ createTable: function createTable() {
4196
+ return _createTable(undefined, undefined, opts);
4197
+ }
4182
4198
  };
4183
4199
  }
4184
- function createTable() {
4185
- return _createTable();
4186
- }
4187
4200
 
4188
4201
  function _createTable(_, __, __options) {
4189
4202
  return {
4190
- __options: __options || {},
4203
+ __options: __options != null ? __options : {
4204
+ render: function render() {
4205
+ throw new Error();
4206
+ }
4207
+ },
4191
4208
  createColumns: function createColumns(columns) {
4192
4209
  return columns;
4193
4210
  },
@@ -4237,7 +4254,7 @@
4237
4254
 
4238
4255
  if (!column) {
4239
4256
  {
4240
- console.warn("React-Table: Could not find a column with id: " + columnId);
4257
+ console.warn("Table: Could not find a column with id: " + columnId);
4241
4258
  }
4242
4259
 
4243
4260
  throw new Error();
@@ -4540,7 +4557,7 @@
4540
4557
  console.info({
4541
4558
  column: column
4542
4559
  });
4543
- throw new Error("React Table: Invalid column.aggregateType option for column listed above" );
4560
+ throw new Error("Table: Invalid column.aggregateType option for column listed above" );
4544
4561
  } else {
4545
4562
  values[column.id] = null;
4546
4563
  }
@@ -4699,17 +4716,15 @@
4699
4716
  exports.Visibility = Visibility;
4700
4717
  exports.buildHeaderGroups = buildHeaderGroups;
4701
4718
  exports.columnFilterRowsFn = columnFilterRowsFn;
4702
- exports.createTable = createTable;
4703
- exports.createTableFactory = createTableFactory;
4704
4719
  exports.createTableInstance = createTableInstance;
4705
4720
  exports.defaultColumnSizing = defaultColumnSizing;
4706
4721
  exports.expandRowsFn = expandRowsFn;
4707
4722
  exports.flattenBy = flattenBy;
4708
- exports.flexRender = flexRender;
4709
4723
  exports.functionalUpdate = functionalUpdate;
4710
4724
  exports.getDefaultColumn = getDefaultColumn;
4711
4725
  exports.globalFilterRowsFn = globalFilterRowsFn;
4712
4726
  exports.groupRowsFn = groupRowsFn;
4727
+ exports.init = init;
4713
4728
  exports.isFunction = isFunction;
4714
4729
  exports.isRowSelected = isRowSelected;
4715
4730
  exports.makeStateUpdater = makeStateUpdater;