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

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 (109) hide show
  1. package/build/cjs/_virtual/_rollupPluginBabelHelpers.js +0 -78
  2. package/build/cjs/_virtual/_rollupPluginBabelHelpers.js.map +1 -1
  3. package/build/cjs/index.js +98 -17
  4. package/build/cjs/index.js.map +1 -1
  5. package/build/esm/index.js +46 -4715
  6. package/build/esm/index.js.map +1 -1
  7. package/build/stats-html.html +1 -1
  8. package/build/stats-react.json +29 -779
  9. package/build/types/index.d.ts +16 -8
  10. package/build/umd/index.development.js +55 -4718
  11. package/build/umd/index.development.js.map +1 -1
  12. package/build/umd/index.production.js +1 -1
  13. package/build/umd/index.production.js.map +1 -1
  14. package/package.json +4 -1
  15. package/src/index.tsx +115 -8
  16. package/build/cjs/aggregationTypes.js +0 -130
  17. package/build/cjs/aggregationTypes.js.map +0 -1
  18. package/build/cjs/core.js +0 -552
  19. package/build/cjs/core.js.map +0 -1
  20. package/build/cjs/createTable.js +0 -108
  21. package/build/cjs/createTable.js.map +0 -1
  22. package/build/cjs/features/ColumnSizing.js +0 -317
  23. package/build/cjs/features/ColumnSizing.js.map +0 -1
  24. package/build/cjs/features/Expanding.js +0 -251
  25. package/build/cjs/features/Expanding.js.map +0 -1
  26. package/build/cjs/features/Filters.js +0 -445
  27. package/build/cjs/features/Filters.js.map +0 -1
  28. package/build/cjs/features/Grouping.js +0 -249
  29. package/build/cjs/features/Grouping.js.map +0 -1
  30. package/build/cjs/features/Headers.js +0 -549
  31. package/build/cjs/features/Headers.js.map +0 -1
  32. package/build/cjs/features/Ordering.js +0 -86
  33. package/build/cjs/features/Ordering.js.map +0 -1
  34. package/build/cjs/features/Pagination.js +0 -198
  35. package/build/cjs/features/Pagination.js.map +0 -1
  36. package/build/cjs/features/Pinning.js +0 -149
  37. package/build/cjs/features/Pinning.js.map +0 -1
  38. package/build/cjs/features/RowSelection.js +0 -541
  39. package/build/cjs/features/RowSelection.js.map +0 -1
  40. package/build/cjs/features/Sorting.js +0 -327
  41. package/build/cjs/features/Sorting.js.map +0 -1
  42. package/build/cjs/features/Visibility.js +0 -166
  43. package/build/cjs/features/Visibility.js.map +0 -1
  44. package/build/cjs/filterTypes.js +0 -172
  45. package/build/cjs/filterTypes.js.map +0 -1
  46. package/build/cjs/sortTypes.js +0 -122
  47. package/build/cjs/sortTypes.js.map +0 -1
  48. package/build/cjs/utils/columnFilterRowsFn.js +0 -131
  49. package/build/cjs/utils/columnFilterRowsFn.js.map +0 -1
  50. package/build/cjs/utils/expandRowsFn.js +0 -38
  51. package/build/cjs/utils/expandRowsFn.js.map +0 -1
  52. package/build/cjs/utils/globalFilterRowsFn.js +0 -101
  53. package/build/cjs/utils/globalFilterRowsFn.js.map +0 -1
  54. package/build/cjs/utils/groupRowsFn.js +0 -155
  55. package/build/cjs/utils/groupRowsFn.js.map +0 -1
  56. package/build/cjs/utils/paginateRowsFn.js +0 -44
  57. package/build/cjs/utils/paginateRowsFn.js.map +0 -1
  58. package/build/cjs/utils/sortRowsFn.js +0 -94
  59. package/build/cjs/utils/sortRowsFn.js.map +0 -1
  60. package/build/cjs/utils.js +0 -141
  61. package/build/cjs/utils.js.map +0 -1
  62. package/build/types/aggregationTypes.d.ts +0 -22
  63. package/build/types/core.d.ts +0 -109
  64. package/build/types/createTable.d.ts +0 -52
  65. package/build/types/features/ColumnSizing.d.ts +0 -67
  66. package/build/types/features/Expanding.d.ts +0 -53
  67. package/build/types/features/Filters.d.ts +0 -98
  68. package/build/types/features/Grouping.d.ts +0 -82
  69. package/build/types/features/Headers.d.ts +0 -41
  70. package/build/types/features/Ordering.d.ts +0 -19
  71. package/build/types/features/Pagination.d.ts +0 -44
  72. package/build/types/features/Pinning.d.ts +0 -39
  73. package/build/types/features/RowSelection.d.ts +0 -66
  74. package/build/types/features/Sorting.d.ts +0 -78
  75. package/build/types/features/Visibility.d.ts +0 -47
  76. package/build/types/filterTypes.d.ts +0 -50
  77. package/build/types/sortTypes.d.ts +0 -18
  78. package/build/types/types.d.ts +0 -127
  79. package/build/types/utils/columnFilterRowsFn.d.ts +0 -2
  80. package/build/types/utils/expandRowsFn.d.ts +0 -2
  81. package/build/types/utils/globalFilterRowsFn.d.ts +0 -2
  82. package/build/types/utils/groupRowsFn.d.ts +0 -2
  83. package/build/types/utils/paginateRowsFn.d.ts +0 -2
  84. package/build/types/utils/sortRowsFn.d.ts +0 -2
  85. package/build/types/utils.d.ts +0 -24
  86. package/src/aggregationTypes.ts +0 -115
  87. package/src/core.tsx +0 -1091
  88. package/src/createTable.tsx +0 -241
  89. package/src/features/ColumnSizing.ts +0 -453
  90. package/src/features/Expanding.ts +0 -406
  91. package/src/features/Filters.ts +0 -762
  92. package/src/features/Grouping.ts +0 -466
  93. package/src/features/Headers.ts +0 -912
  94. package/src/features/Ordering.ts +0 -133
  95. package/src/features/Pagination.ts +0 -325
  96. package/src/features/Pinning.ts +0 -198
  97. package/src/features/RowSelection.ts +0 -831
  98. package/src/features/Sorting.ts +0 -547
  99. package/src/features/Visibility.ts +0 -279
  100. package/src/filterTypes.ts +0 -251
  101. package/src/sortTypes.ts +0 -159
  102. package/src/types.ts +0 -331
  103. package/src/utils/columnFilterRowsFn.ts +0 -155
  104. package/src/utils/expandRowsFn.ts +0 -50
  105. package/src/utils/globalFilterRowsFn.ts +0 -122
  106. package/src/utils/groupRowsFn.ts +0 -194
  107. package/src/utils/paginateRowsFn.ts +0 -34
  108. package/src/utils/sortRowsFn.ts +0 -115
  109. package/src/utils.tsx +0 -195
@@ -9,12 +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.ReactTable = {}, 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 }; }
12
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react'), require('@tanstack/table-core')) :
13
+ typeof define === 'function' && define.amd ? define(['exports', 'react', '@tanstack/table-core'], factory) :
14
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.ReactTable = {}, global.React, global.TableCore));
15
+ })(this, (function (exports, React, tableCore) { 'use strict';
18
16
 
19
17
  function _interopNamespace(e) {
20
18
  if (e && e.__esModule) return e;
@@ -34,287 +32,8 @@
34
32
  return Object.freeze(n);
35
33
  }
36
34
 
37
- var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
38
35
  var React__namespace = /*#__PURE__*/_interopNamespace(React);
39
36
 
40
- function columnFilterRowsFn(instance, rowModel) {
41
- var columnFilters = instance.getState().columnFilters;
42
- var newFilteredFlatRows = [];
43
- var newFilteredRowsById = {};
44
- var filterFromChildrenUp = instance.options.filterFromChildrenUp;
45
-
46
- var filterRows = function filterRows(rowsToFilter, depth) {
47
- columnFilters.forEach(function (_ref) {
48
- var columnId = _ref.id,
49
- filterValue = _ref.value;
50
- // Find the columnFilters column
51
- var column = instance.getColumn(columnId);
52
-
53
- if (!column) {
54
- {
55
- console.warn("React-Table: Could not find a column with id: " + columnId);
56
- }
57
-
58
- throw new Error();
59
- }
60
-
61
- if (depth === 0) {
62
- var preFilteredRows = [].concat(rowsToFilter);
63
-
64
- column.getPreFilteredRows = function () {
65
- return preFilteredRows;
66
- };
67
- }
68
-
69
- var filterFn = instance.getColumnFilterFn(column.id);
70
-
71
- if (!filterFn) {
72
- {
73
- console.warn("Could not find a valid 'column.filterType' for column with the ID: " + column.id + ".");
74
- }
75
-
76
- return;
77
- } // Pass the rows, id, filterValue and column to the filterFn
78
- // to get the filtered rows back
79
-
80
-
81
- rowsToFilter = filterFn(rowsToFilter, [columnId], filterValue);
82
- });
83
- return rowsToFilter;
84
- };
85
-
86
- if (filterFromChildrenUp) {
87
- var _recurseFilterRows = function _recurseFilterRows(rowsToFilter, depth) {
88
- if (depth === void 0) {
89
- depth = 0;
90
- }
91
-
92
- // Filter from children up
93
- rowsToFilter = rowsToFilter.filter(function (row) {
94
- var _row$subRows;
95
-
96
- if (!((_row$subRows = row.subRows) != null && _row$subRows.length)) {
97
- return true;
98
- }
99
-
100
- row.subRows = _recurseFilterRows(row.subRows, depth + 1);
101
- return row.subRows.length;
102
- });
103
- rowsToFilter = filterRows(rowsToFilter, depth); // Apply the filter to any subRows
104
-
105
- rowsToFilter.forEach(function (row) {
106
- newFilteredFlatRows.push(row);
107
- newFilteredRowsById[row.id] = row;
108
- });
109
- return rowsToFilter;
110
- };
111
-
112
- return {
113
- rows: _recurseFilterRows(rowModel.rows),
114
- flatRows: newFilteredFlatRows,
115
- rowsById: newFilteredRowsById
116
- };
117
- } // Filters top level and nested rows
118
-
119
-
120
- var recurseFilterRows = function recurseFilterRows(rowsToFilter, depth) {
121
- if (depth === void 0) {
122
- depth = 0;
123
- }
124
-
125
- // Filter from parents downward
126
- rowsToFilter = filterRows(rowsToFilter, depth); // Apply the filter to any subRows
127
- // We technically could do this recursively in the above loop,
128
- // but that would severely hinder the API for the user, since they
129
- // would be required to do that recursion in some scenarios
130
-
131
- rowsToFilter.forEach(function (row) {
132
- newFilteredFlatRows.push(row);
133
- newFilteredRowsById[row.id] = row;
134
-
135
- if (!filterFromChildrenUp) {
136
- var _row$subRows2;
137
-
138
- if (!((_row$subRows2 = row.subRows) != null && _row$subRows2.length)) {
139
- return;
140
- }
141
-
142
- row.subRows = recurseFilterRows(row.subRows, depth + 1);
143
- }
144
- });
145
- return rowsToFilter;
146
- };
147
-
148
- return {
149
- rows: recurseFilterRows(rowModel.rows),
150
- flatRows: newFilteredFlatRows,
151
- rowsById: newFilteredRowsById
152
- };
153
- }
154
-
155
- function globalFilterRowsFn(instance, rowModel) {
156
- var globalFilter = instance.getState().globalFilter;
157
- var newFilteredFlatRows = [];
158
- var newFilteredRowsById = {};
159
- var filterFromChildrenUp = instance.options.filterFromChildrenUp;
160
- var filterFn = instance.getGlobalFilterFn();
161
-
162
- if (!filterFn) {
163
- {
164
- console.warn("Could not find a valid 'globalFilterType'");
165
- }
166
-
167
- return rowModel;
168
- }
169
-
170
- var filterableColumns = instance.getAllLeafColumns().filter(function (column) {
171
- return column.getCanGlobalFilter();
172
- });
173
- var filterableColumnIds = filterableColumns.map(function (d) {
174
- return d.id;
175
- });
176
-
177
- if (filterFromChildrenUp) {
178
- var _recurseFilterRows = function _recurseFilterRows(rowsToFilter, depth) {
179
-
180
- // Filter from children up
181
- rowsToFilter = rowsToFilter.filter(function (row) {
182
- var _row$subRows;
183
-
184
- if (!((_row$subRows = row.subRows) != null && _row$subRows.length)) {
185
- return true;
186
- }
187
-
188
- row.subRows = _recurseFilterRows(row.subRows);
189
- return row.subRows.length;
190
- });
191
- rowsToFilter = filterFn(rowsToFilter, filterableColumnIds, globalFilter); // Apply the filter to any subRows
192
-
193
- rowsToFilter.forEach(function (row) {
194
- newFilteredFlatRows.push(row);
195
- newFilteredRowsById[row.id] = row;
196
- });
197
- return rowsToFilter;
198
- };
199
-
200
- return {
201
- rows: _recurseFilterRows(rowModel.rows),
202
- flatRows: newFilteredFlatRows,
203
- rowsById: newFilteredRowsById
204
- };
205
- } // Filters top level and nested rows
206
-
207
-
208
- var recurseFilterRows = function recurseFilterRows(rowsToFilter, depth) {
209
-
210
- // Filter from parents downward
211
- rowsToFilter = filterFn(rowsToFilter, filterableColumnIds, globalFilter); // Apply the filter to any subRows
212
- // We technically could do this recursively in the above loop,
213
- // but that would severely hinder the API for the user, since they
214
- // would be required to do that recursion in some scenarios
215
-
216
- rowsToFilter.forEach(function (row) {
217
- newFilteredFlatRows.push(row);
218
- newFilteredRowsById[row.id] = row;
219
-
220
- if (!filterFromChildrenUp) {
221
- var _row$subRows2;
222
-
223
- if (!((_row$subRows2 = row.subRows) != null && _row$subRows2.length)) {
224
- return;
225
- }
226
-
227
- row.subRows = recurseFilterRows(row.subRows);
228
- }
229
- });
230
- return rowsToFilter;
231
- };
232
-
233
- return {
234
- rows: recurseFilterRows(rowModel.rows),
235
- flatRows: newFilteredFlatRows,
236
- rowsById: newFilteredRowsById
237
- };
238
- }
239
-
240
- function sortRowsFn(instance, rowModel) {
241
- var sortingState = instance.getState().sorting;
242
- var sortedFlatRows = []; // Filter out sortings that correspond to non existing columns
243
-
244
- var availableSorting = sortingState.filter(function (sort) {
245
- return instance.getColumnCanSort(sort.id);
246
- });
247
- var columnInfoById = {};
248
- availableSorting.forEach(function (sortEntry) {
249
- var column = instance.getColumn(sortEntry.id);
250
- columnInfoById[sortEntry.id] = {
251
- sortUndefined: column.sortUndefined,
252
- invertSorting: column.invertSorting,
253
- sortingFn: instance.getColumnSortingFn(sortEntry.id)
254
- };
255
- });
256
-
257
- var sortData = function sortData(rows) {
258
- // This will also perform a stable sorting using the row index
259
- // if needed.
260
- var sortedData = rows.slice();
261
- sortedData.sort(function (rowA, rowB) {
262
- for (var i = 0; i < availableSorting.length; i += 1) {
263
- var _sortEntry$desc;
264
-
265
- var sortEntry = availableSorting[i];
266
- var columnInfo = columnInfoById[sortEntry.id];
267
- var isDesc = (_sortEntry$desc = sortEntry == null ? void 0 : sortEntry.desc) != null ? _sortEntry$desc : false;
268
-
269
- if (columnInfo.sortUndefined) {
270
- var aValue = rowA.values[sortEntry.id];
271
- var bValue = rowB.values[sortEntry.id];
272
- var aUndefined = typeof aValue === 'undefined';
273
- var bUndefined = typeof bValue === 'undefined';
274
-
275
- if (aUndefined || bUndefined) {
276
- return aUndefined && bUndefined ? 0 : aUndefined ? 1 : -1;
277
- }
278
- } // This function should always return in ascending order
279
-
280
-
281
- var sortInt = columnInfo.sortingFn(rowA, rowB, sortEntry.id);
282
-
283
- if (sortInt !== 0) {
284
- if (isDesc) {
285
- sortInt *= -1;
286
- }
287
-
288
- if (columnInfo.invertSorting) {
289
- sortInt *= -1;
290
- }
291
-
292
- return sortInt;
293
- }
294
- }
295
-
296
- return rowA.index - rowB.index;
297
- }); // If there are sub-rows, sort them
298
-
299
- sortedData.forEach(function (row) {
300
- sortedFlatRows.push(row);
301
-
302
- if (!row.subRows || row.subRows.length <= 1) {
303
- return;
304
- }
305
-
306
- row.subRows = sortData(row.subRows);
307
- });
308
- return sortedData;
309
- };
310
-
311
- return {
312
- rows: sortData(rowModel.rows),
313
- flatRows: sortedFlatRows,
314
- rowsById: rowModel.rowsById
315
- };
316
- }
317
-
318
37
  function _extends() {
319
38
  _extends = Object.assign || function (target) {
320
39
  for (var i = 1; i < arguments.length; i++) {
@@ -333,159 +52,10 @@
333
52
  return _extends.apply(this, arguments);
334
53
  }
335
54
 
336
- function _objectWithoutPropertiesLoose(source, excluded) {
337
- if (source == null) return {};
338
- var target = {};
339
- var sourceKeys = Object.keys(source);
340
- var key, i;
341
-
342
- for (i = 0; i < sourceKeys.length; i++) {
343
- key = sourceKeys[i];
344
- if (excluded.indexOf(key) >= 0) continue;
345
- target[key] = source[key];
346
- }
347
-
348
- return target;
349
- }
350
-
351
- function _unsupportedIterableToArray(o, minLen) {
352
- if (!o) return;
353
- if (typeof o === "string") return _arrayLikeToArray(o, minLen);
354
- var n = Object.prototype.toString.call(o).slice(8, -1);
355
- if (n === "Object" && o.constructor) n = o.constructor.name;
356
- if (n === "Map" || n === "Set") return Array.from(o);
357
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
358
- }
359
-
360
- function _arrayLikeToArray(arr, len) {
361
- if (len == null || len > arr.length) len = arr.length;
362
-
363
- for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
364
-
365
- return arr2;
366
- }
367
-
368
- function _createForOfIteratorHelperLoose(o, allowArrayLike) {
369
- var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
370
- if (it) return (it = it.call(o)).next.bind(it);
371
-
372
- if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
373
- if (it) o = it;
374
- var i = 0;
375
- return function () {
376
- if (i >= o.length) return {
377
- done: true
378
- };
379
- return {
380
- done: false,
381
- value: o[i++]
382
- };
383
- };
384
- }
385
-
386
- throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
387
- }
388
-
389
- function _toPrimitive(input, hint) {
390
- if (typeof input !== "object" || input === null) return input;
391
- var prim = input[Symbol.toPrimitive];
392
-
393
- if (prim !== undefined) {
394
- var res = prim.call(input, hint || "default");
395
- if (typeof res !== "object") return res;
396
- throw new TypeError("@@toPrimitive must return a primitive value.");
397
- }
398
-
399
- return (hint === "string" ? String : Number)(input);
400
- }
401
-
402
- function _toPropertyKey(arg) {
403
- var key = _toPrimitive(arg, "string");
404
-
405
- return typeof key === "symbol" ? key : String(key);
406
- }
407
-
408
- function functionalUpdate(updater, input) {
409
- return typeof updater === 'function' ? updater(input) : updater;
410
- }
411
- function makeStateUpdater(key, instance) {
412
- return function (updater) {
413
- instance.setState(function (old) {
414
- var _extends2;
415
-
416
- return _extends({}, old, (_extends2 = {}, _extends2[key] = functionalUpdate(updater, old[key]), _extends2));
417
- });
418
- };
419
- }
420
- function isFunction(d) {
421
- return d instanceof Function;
422
- }
423
- function flattenBy(arr, getChildren) {
424
- var flat = [];
425
-
426
- var recurse = function recurse(subArr) {
427
- subArr.forEach(function (item) {
428
- flat.push(item);
429
- var children = getChildren(item);
430
-
431
- if (children != null && children.length) {
432
- recurse(children);
433
- }
434
- });
435
- };
436
-
437
- recurse(arr);
438
- return flat;
439
- }
440
- // @ts-ignore // Just rely on the type, not the implementation
441
- var propGetter = function propGetter(initial, getter) {
442
- if (isFunction(getter)) {
443
- return getter(initial);
444
- }
445
-
446
- return _extends({}, initial, getter != null ? getter : {});
55
+ //
56
+ var render = function render(Comp, props) {
57
+ return !Comp ? null : isReactComponent(Comp) ? /*#__PURE__*/React__namespace.createElement(Comp, props) : Comp;
447
58
  };
448
- function memo(getDeps, fn, opts) {
449
- var deps = [];
450
- var result;
451
- return function () {
452
- var newDeps = getDeps();
453
- var depsChanged = newDeps.length !== deps.length || newDeps.some(function (dep, index) {
454
- return deps[index] !== dep;
455
- });
456
-
457
- if (depsChanged) {
458
- if (opts != null && opts.debug) {
459
- console.info(opts == null ? void 0 : opts.key, _extends({
460
- length: deps.length + " -> " + newDeps.length
461
- }, newDeps.map(function (_, index) {
462
- if (deps[index] !== newDeps[index]) {
463
- return [index, deps[index], newDeps[index]];
464
- }
465
-
466
- return false;
467
- }).filter(Boolean).reduce(function (accu, curr) {
468
- var _extends3;
469
-
470
- return _extends({}, accu, (_extends3 = {}, _extends3[curr[0]] = curr.slice(1), _extends3));
471
- }, {}), {
472
- parent: parent
473
- }));
474
- }
475
-
476
- var oldResult = result;
477
- result = fn.apply(void 0, newDeps);
478
- deps = newDeps;
479
- opts == null ? void 0 : opts.onChange == null ? void 0 : opts.onChange(result, oldResult);
480
- oldResult = undefined;
481
- }
482
-
483
- return result;
484
- };
485
- }
486
- function flexRender(Comp, props) {
487
- return !Comp ? null : isReactComponent(Comp) ? /*#__PURE__*/React__default["default"].createElement(Comp, props) : Comp;
488
- }
489
59
 
490
60
  function isReactComponent(component) {
491
61
  return isClassComponent(component) || typeof component === 'function' || isExoticComponent(component);
@@ -500,4296 +70,63 @@
500
70
 
501
71
  function isExoticComponent(component) {
502
72
  return typeof component === 'object' && typeof component.$$typeof === 'symbol' && ['react.memo', 'react.forward_ref'].includes(component.$$typeof.description);
503
- } // export function hashString(str: string, seed = 0): string {
504
- // let h1 = 0xdeadbeef ^ seed,
505
- // h2 = 0x41c6ce57 ^ seed
506
- // for (let i = 0, ch; i < str.length; i++) {
507
- // ch = str.charCodeAt(i)
508
- // h1 = Math.imul(h1 ^ ch, 2654435761)
509
- // h2 = Math.imul(h2 ^ ch, 1597334677)
510
- // }
511
- // h1 =
512
- // Math.imul(h1 ^ (h1 >>> 16), 2246822507) ^
513
- // Math.imul(h2 ^ (h2 >>> 13), 3266489909)
514
- // h2 =
515
- // Math.imul(h2 ^ (h2 >>> 16), 2246822507) ^
516
- // Math.imul(h1 ^ (h1 >>> 13), 3266489909)
517
- // return (4294967296 * (2097151 & h2) + (h1 >>> 0)).toString()
518
- // }
519
-
520
- function groupRowsFn(instance, sortedRowModel) {
521
- var groupingState = instance.getState().grouping; // Filter the grouping list down to columns that exist
522
-
523
- var existingGrouping = groupingState.filter(function (columnId) {
524
- return instance.getColumn(columnId);
525
- }); // Find the columns that can or are aggregating
526
- // Uses each column to aggregate rows into a single value
527
-
528
- var aggregateRowsToValues = function aggregateRowsToValues(leafRows, groupedRows, depth) {
529
- var values = {};
530
- instance.getAllLeafColumns().forEach(function (column) {
531
- // Don't aggregate columns that are in the grouping
532
- if (existingGrouping.includes(column.id)) {
533
- values[column.id] = groupedRows[0] ? groupedRows[0].values[column.id] : null;
534
- return;
535
- } // Aggregate the values
536
-
537
-
538
- var aggregateFn = instance.getColumnAggregationFn(column.id);
539
-
540
- if (aggregateFn) {
541
- // Get the columnValues to aggregate
542
- var groupedValues = groupedRows.map(function (row) {
543
- return row.values[column.id];
544
- }); // Get the columnValues to aggregate
545
-
546
- var leafValues = leafRows.map(function (row) {
547
- var columnValue = row.values[column.id];
548
-
549
- if (!depth && column.aggregateValue) {
550
- columnValue = column.aggregateValue(columnValue);
551
- }
552
-
553
- return columnValue;
554
- });
555
- values[column.id] = aggregateFn(leafValues, groupedValues);
556
- } else if (column.aggregationType) {
557
- console.info({
558
- column: column
559
- });
560
- throw new Error("React Table: Invalid column.aggregateType option for column listed above" );
561
- } else {
562
- values[column.id] = null;
563
- }
564
- });
565
- return values;
566
- };
567
-
568
- var groupedFlatRows = [];
569
- var groupedRowsById = {}; // const onlyGroupedFlatRows: Row[] = [];
570
- // const onlyGroupedRowsById: Record<RowId, Row> = {};
571
- // const nonGroupedFlatRows: Row[] = [];
572
- // const nonGroupedRowsById: Record<RowId, Row> = {};
573
- // Recursively group the data
574
-
575
- var groupUpRecursively = function groupUpRecursively(rows, depth, parentId) {
576
- if (depth === void 0) {
577
- depth = 0;
578
- }
579
-
580
- // This is the last level, just return the rows
581
- if (depth === existingGrouping.length) {
582
- return rows;
583
- }
584
-
585
- var columnId = existingGrouping[depth]; // Group the rows together for this level
586
-
587
- var rowGroupsMap = groupBy(rows, columnId); // Peform aggregations for each group
588
-
589
- var aggregatedGroupedRows = Array.from(rowGroupsMap.entries()).map(function (_ref, index) {
590
- var groupingValue = _ref[0],
591
- groupedRows = _ref[1];
592
- var id = columnId + ":" + groupingValue;
593
- id = parentId ? parentId + ">" + id : id; // First, Recurse to group sub rows before aggregation
594
-
595
- var subRows = groupUpRecursively(groupedRows, depth + 1, id); // Flatten the leaf rows of the rows in this group
596
-
597
- var leafRows = depth ? flattenBy(groupedRows, function (row) {
598
- return row.leafRows;
599
- }) : groupedRows;
600
- var values = aggregateRowsToValues(leafRows, groupedRows, depth);
601
- var row = instance.createRow(id, undefined, index, depth, values);
602
- Object.assign(row, {
603
- groupingColumnId: columnId,
604
- groupingValue: groupingValue,
605
- subRows: subRows,
606
- leafRows: leafRows
607
- });
608
- subRows.forEach(function (subRow) {
609
- groupedFlatRows.push(subRow);
610
- groupedRowsById[subRow.id] = subRow; // if (subRow.getIsGrouped?.()) {
611
- // onlyGroupedFlatRows.push(subRow);
612
- // onlyGroupedRowsById[subRow.id] = subRow;
613
- // } else {
614
- // nonGroupedFlatRows.push(subRow);
615
- // nonGroupedRowsById[subRow.id] = subRow;
616
- // }
617
- });
618
- return row;
619
- });
620
- return aggregatedGroupedRows;
621
- };
622
-
623
- var groupedRows = groupUpRecursively(sortedRowModel.rows, 0, '');
624
- groupedRows.forEach(function (subRow) {
625
- groupedFlatRows.push(subRow);
626
- groupedRowsById[subRow.id] = subRow; // if (subRow.getIsGrouped?.()) {
627
- // onlyGroupedFlatRows.push(subRow);
628
- // onlyGroupedRowsById[subRow.id] = subRow;
629
- // } else {
630
- // nonGroupedFlatRows.push(subRow);
631
- // nonGroupedRowsById[subRow.id] = subRow;
632
- // }
633
- });
634
- return {
635
- rows: groupedRows,
636
- flatRows: groupedFlatRows,
637
- rowsById: groupedRowsById
638
- };
639
- }
640
-
641
- function groupBy(rows, columnId) {
642
- var groupMap = new Map();
643
- return rows.reduce(function (map, row) {
644
- var resKey = "" + row.values[columnId];
645
- var previous = map.get(resKey);
646
-
647
- if (!previous) {
648
- map.set(resKey, [row]);
649
- } else {
650
- map.set(resKey, [].concat(previous, [row]));
651
- }
652
-
653
- return map;
654
- }, groupMap);
655
- }
656
-
657
- function expandRowsFn(instance, sortedRowModel) {
658
- var expandedRows = [];
659
- var expandSubRows = instance.options.expandSubRows;
660
-
661
- var handleRow = function handleRow(row) {
662
- var _row$subRows;
663
-
664
- expandedRows.push(row);
665
-
666
- if (expandSubRows && (_row$subRows = row.subRows) != null && _row$subRows.length && instance.getIsRowExpanded(row.id)) {
667
- row.subRows.forEach(handleRow);
668
- }
669
- };
670
-
671
- sortedRowModel.rows.forEach(handleRow);
672
- return {
673
- rows: expandedRows,
674
- flatRows: sortedRowModel.flatRows,
675
- rowsById: sortedRowModel.rowsById
676
- };
677
- }
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
-
705
- //
706
- function getInitialState$9() {
707
- return {
708
- columnVisibility: {}
709
- };
710
- }
711
- function getDefaultOptions$9(instance) {
712
- return {
713
- onColumnVisibilityChange: makeStateUpdater('columnVisibility', instance)
714
- };
715
- }
716
- function getDefaultColumn$3() {
717
- return {
718
- defaultIsVisible: true
719
- };
720
- }
721
- function createColumn$5(column, instance) {
722
- return {
723
- getCanHide: function getCanHide() {
724
- return instance.getColumnCanHide(column.id);
725
- },
726
- getIsVisible: function getIsVisible() {
727
- return instance.getColumnIsVisible(column.id);
728
- },
729
- toggleVisibility: function toggleVisibility(value) {
730
- return instance.toggleColumnVisibility(column.id, value);
731
- },
732
- getToggleVisibilityProps: function getToggleVisibilityProps(userProps) {
733
- var props = {
734
- type: 'checkbox',
735
- checked: column.getIsVisible == null ? void 0 : column.getIsVisible(),
736
- title: 'Toggle Column Visibility',
737
- onChange: function onChange(e) {
738
- column.toggleVisibility == null ? void 0 : column.toggleVisibility(e.target.checked);
739
- }
740
- };
741
- return propGetter(props, userProps);
742
- }
743
- };
744
- }
745
- function getInstance$a(instance) {
746
- return {
747
- getVisibleFlatColumns: memo(function () {
748
- return [instance.getAllFlatColumns(), instance.getAllFlatColumns().filter(function (d) {
749
- return d.getIsVisible == null ? void 0 : d.getIsVisible();
750
- }).map(function (d) {
751
- return d.id;
752
- }).join('_')];
753
- }, function (allFlatColumns) {
754
- return allFlatColumns.filter(function (d) {
755
- return d.getIsVisible == null ? void 0 : d.getIsVisible();
756
- });
757
- }, {
758
- key: 'getVisibleFlatColumns',
759
- debug: instance.options.debug
760
- }),
761
- getVisibleLeafColumns: memo(function () {
762
- return [instance.getAllLeafColumns(), instance.getAllLeafColumns().filter(function (d) {
763
- return d.getIsVisible == null ? void 0 : d.getIsVisible();
764
- }).map(function (d) {
765
- return d.id;
766
- }).join('_')];
767
- }, function (allFlatColumns) {
768
- return allFlatColumns.filter(function (d) {
769
- return d.getIsVisible == null ? void 0 : d.getIsVisible();
770
- });
771
- }, {
772
- key: 'getVisibleLeafColumns',
773
- debug: instance.options.debug
774
- }),
775
- setColumnVisibility: function setColumnVisibility(updater) {
776
- return instance.options.onColumnVisibilityChange == null ? void 0 : instance.options.onColumnVisibilityChange(updater, functionalUpdate(updater, instance.getState().columnVisibility));
777
- },
778
- toggleColumnVisibility: function toggleColumnVisibility(columnId, value) {
779
- if (!columnId) return;
780
-
781
- if (instance.getColumnCanHide(columnId)) {
782
- instance.setColumnVisibility(function (old) {
783
- var _extends2;
784
-
785
- return _extends({}, old, (_extends2 = {}, _extends2[columnId] = value != null ? value : !instance.getColumnIsVisible(columnId), _extends2));
786
- });
787
- }
788
- },
789
- toggleAllColumnsVisible: function toggleAllColumnsVisible(value) {
790
- var _value;
791
-
792
- value = (_value = value) != null ? _value : !instance.getIsAllColumnsVisible();
793
- instance.setColumnVisibility(instance.getAllLeafColumns().reduce(function (obj, column) {
794
- var _extends3;
795
-
796
- return _extends({}, obj, (_extends3 = {}, _extends3[column.id] = !value ? !(column.getCanHide != null && column.getCanHide()) : value, _extends3));
797
- }, {}));
798
- },
799
- getColumnIsVisible: function getColumnIsVisible(columnId) {
800
- var _ref, _instance$getState$co, _instance$getState$co2;
801
-
802
- var column = instance.getColumn(columnId);
803
-
804
- if (!column) {
805
- throw new Error();
806
- }
807
-
808
- return (_ref = (_instance$getState$co = (_instance$getState$co2 = instance.getState().columnVisibility) == null ? void 0 : _instance$getState$co2[columnId]) != null ? _instance$getState$co : column.defaultIsVisible) != null ? _ref : true;
809
- },
810
- getColumnCanHide: function getColumnCanHide(columnId) {
811
- var _ref2, _ref3, _instance$options$ena;
812
-
813
- var column = instance.getColumn(columnId);
814
-
815
- if (!column) {
816
- throw new Error();
817
- }
818
-
819
- return (_ref2 = (_ref3 = (_instance$options$ena = instance.options.enableHiding) != null ? _instance$options$ena : column.enableHiding) != null ? _ref3 : column.defaultCanHide) != null ? _ref2 : true;
820
- },
821
- getIsAllColumnsVisible: function getIsAllColumnsVisible() {
822
- return !instance.getAllLeafColumns().some(function (column) {
823
- return !(column.getIsVisible != null && column.getIsVisible());
824
- });
825
- },
826
- getIsSomeColumnsVisible: function getIsSomeColumnsVisible() {
827
- return instance.getAllLeafColumns().some(function (column) {
828
- return column.getIsVisible == null ? void 0 : column.getIsVisible();
829
- });
830
- },
831
- getToggleAllColumnsVisibilityProps: function getToggleAllColumnsVisibilityProps(userProps) {
832
- var props = {
833
- onChange: function onChange(e) {
834
- var _e$target;
835
-
836
- instance.toggleAllColumnsVisible((_e$target = e.target) == null ? void 0 : _e$target.checked);
837
- },
838
- type: 'checkbox',
839
- title: 'Toggle visibility for all columns',
840
- checked: instance.getIsAllColumnsVisible(),
841
- indeterminate: !instance.getIsAllColumnsVisible() && instance.getIsSomeColumnsVisible() ? 'indeterminate' : undefined
842
- };
843
- return propGetter(props, userProps);
844
- }
845
- };
846
73
  }
847
74
 
848
- var Visibility = /*#__PURE__*/Object.freeze({
849
- __proto__: null,
850
- getInitialState: getInitialState$9,
851
- getDefaultOptions: getDefaultOptions$9,
852
- getDefaultColumn: getDefaultColumn$3,
853
- createColumn: createColumn$5,
854
- getInstance: getInstance$a
75
+ var createTable = tableCore.createTableFactory({
76
+ render: render
855
77
  });
78
+ function useTableInstance(table, options) {
79
+ // Compose in the generic options to the user options
80
+ var resolvedOptions = _extends({}, table.options, {
81
+ state: {},
82
+ // Dummy state
83
+ onStateChange: function onStateChange() {},
84
+ // noop
85
+ render: render
86
+ }, options); // Create a new table instance and store it in state
87
+
88
+
89
+ var _React$useState = React__namespace.useState(function () {
90
+ return tableCore.createTableInstance(resolvedOptions);
91
+ }),
92
+ instance = _React$useState[0]; // By default, manage table state here using the instance's initial state
93
+
94
+
95
+ var _React$useState2 = React__namespace.useState(function () {
96
+ return instance.initialState;
97
+ }),
98
+ state = _React$useState2[0],
99
+ setState = _React$useState2[1]; // Compose the default state above with any user state. This will allow the user
100
+ // to only control a subset of the state if desired.
101
+
102
+
103
+ instance.setOptions(function (prev) {
104
+ return _extends({}, prev, options, {
105
+ state: _extends({}, state, options.state),
106
+ // Similarly, we'll maintain both our internal state and any user-provided
107
+ // state.
108
+ onStateChange: function onStateChange(updater) {
109
+ setState(updater);
110
+ options.onStateChange == null ? void 0 : options.onStateChange(updater);
111
+ }
112
+ });
113
+ }); // useIsomorphicLayoutEffect(() => {
114
+ // instance.willUpdate()
115
+ // })
856
116
 
857
- var aggregationTypes = {
858
- sum: sum,
859
- min: min,
860
- max: max,
861
- extent: extent,
862
- mean: mean,
863
- median: median,
864
- unique: unique,
865
- uniqueCount: uniqueCount,
866
- count: count
867
- };
868
-
869
- function sum(_leafValues, childValues) {
870
- // It's faster to just add the aggregations together instead of
871
- // process leaf nodes individually
872
- return childValues.reduce(function (sum, next) {
873
- return sum + (typeof next === 'number' ? next : 0);
874
- }, 0);
875
- }
876
-
877
- function min(_leafValues, childValues) {
878
- var min;
879
-
880
- for (var _iterator = _createForOfIteratorHelperLoose(childValues), _step; !(_step = _iterator()).done;) {
881
- var value = _step.value;
882
-
883
- if (value != null && (min > value || min === undefined && value >= value)) {
884
- min = value;
885
- }
886
- }
887
-
888
- return min;
889
- }
890
-
891
- function max(_leafValues, childValues) {
892
- var max;
893
-
894
- for (var _iterator2 = _createForOfIteratorHelperLoose(childValues), _step2; !(_step2 = _iterator2()).done;) {
895
- var value = _step2.value;
896
-
897
- if (value != null && (max < value || max === undefined && value >= value)) {
898
- max = value;
899
- }
900
- }
901
-
902
- return max;
903
- }
904
-
905
- function extent(_leafValues, childValues) {
906
- var min;
907
- var max;
908
-
909
- for (var _iterator3 = _createForOfIteratorHelperLoose(childValues), _step3; !(_step3 = _iterator3()).done;) {
910
- var value = _step3.value;
911
-
912
- if (value != null) {
913
- if (min === undefined) {
914
- if (value >= value) min = max = value;
915
- } else {
916
- if (min > value) min = value;
917
- if (max < value) max = value;
918
- }
919
- }
920
- }
921
-
922
- return [min, max];
117
+ return instance;
923
118
  }
924
119
 
925
- function mean(leafValues) {
926
- var count = 0;
927
- var sum = 0;
928
-
929
- for (var _iterator4 = _createForOfIteratorHelperLoose(leafValues), _step4; !(_step4 = _iterator4()).done;) {
930
- var value = _step4.value;
931
-
932
- if (value != null && (value = +value) >= value) {
933
- ++count, sum += value;
934
- }
935
- }
936
-
937
- if (count) return sum / count;
938
- return;
939
- }
940
-
941
- function median(values) {
942
- if (!values.length) {
943
- return;
944
- }
945
-
946
- var min = 0;
947
- var max = 0;
948
- values.forEach(function (value) {
949
- if (typeof value === 'number') {
950
- min = Math.min(min, value);
951
- max = Math.max(max, value);
952
- }
953
- });
954
- return (min + max) / 2;
955
- }
956
-
957
- function unique(values) {
958
- return Array.from(new Set(values).values());
959
- }
960
-
961
- function uniqueCount(values) {
962
- return new Set(values).size;
963
- }
964
-
965
- function count(values) {
966
- return values.length;
967
- }
968
-
969
- //
970
- function getDefaultColumn$2() {
971
- return {
972
- aggregationType: 'auto'
973
- };
974
- }
975
- function getInitialState$8() {
976
- return {
977
- grouping: []
978
- };
979
- }
980
- function getDefaultOptions$8(instance) {
981
- return {
982
- onGroupingChange: makeStateUpdater('grouping', instance),
983
- autoResetGrouping: true,
984
- groupedColumnMode: 'reorder'
985
- };
986
- }
987
- function createColumn$4(column, instance) {
988
- return {
989
- aggregationType: column.aggregationType,
990
- getCanGroup: function getCanGroup() {
991
- return instance.getColumnCanGroup(column.id);
992
- },
993
- getGroupedIndex: function getGroupedIndex() {
994
- return instance.getColumnGroupedIndex(column.id);
995
- },
996
- getIsGrouped: function getIsGrouped() {
997
- return instance.getColumnIsGrouped(column.id);
998
- },
999
- toggleGrouping: function toggleGrouping() {
1000
- return instance.toggleColumnGrouping(column.id);
1001
- },
1002
- getToggleGroupingProps: function getToggleGroupingProps(userProps) {
1003
- return instance.getToggleGroupingProps(column.id, userProps);
1004
- }
1005
- };
1006
- }
1007
- function getInstance$9(instance) {
1008
- var registered = false;
1009
- return {
1010
- _notifyGroupingReset: function _notifyGroupingReset() {
1011
- if (!registered) {
1012
- registered = true;
1013
- return;
1014
- }
1015
-
1016
- if (instance.options.autoResetAll === false) {
1017
- return;
1018
- }
1019
-
1020
- if (instance.options.autoResetAll === true || instance.options.autoResetGrouping) {
1021
- instance.resetGrouping();
1022
- }
1023
- },
1024
- getColumnAutoAggregationFn: function getColumnAutoAggregationFn(columnId) {
1025
- var firstRow = instance.getCoreFlatRows()[0];
1026
- var value = firstRow == null ? void 0 : firstRow.values[columnId];
1027
-
1028
- if (typeof value === 'number') {
1029
- return aggregationTypes.sum;
1030
- }
1031
-
1032
- if (Object.prototype.toString.call(value) === '[object Date]') {
1033
- return aggregationTypes.extent;
1034
- }
1035
-
1036
- return aggregationTypes.count;
1037
- },
1038
- getColumnAggregationFn: function getColumnAggregationFn(columnId) {
1039
- var _ref;
1040
-
1041
- var column = instance.getColumn(columnId);
1042
- var userAggregationTypes = instance.options.aggregationTypes;
1043
-
1044
- if (!column) {
1045
- throw new Error();
1046
- }
1047
-
1048
- return isFunction(column.aggregationType) ? column.aggregationType : column.aggregationType === 'auto' ? instance.getColumnAutoFilterFn(columnId) : (_ref = userAggregationTypes == null ? void 0 : userAggregationTypes[column.aggregationType]) != null ? _ref : aggregationTypes[column.aggregationType];
1049
- },
1050
- setGrouping: function setGrouping(updater) {
1051
- return instance.options.onGroupingChange == null ? void 0 : instance.options.onGroupingChange(updater, functionalUpdate(updater, instance.getState().grouping));
1052
- },
1053
- toggleColumnGrouping: function toggleColumnGrouping(columnId) {
1054
- instance.setGrouping(function (old) {
1055
- // Find any existing grouping for this column
1056
- if (old != null && old.includes(columnId)) {
1057
- return old.filter(function (d) {
1058
- return d !== columnId;
1059
- });
1060
- }
1061
-
1062
- return [].concat(old != null ? old : [], [columnId]);
1063
- });
1064
- },
1065
- getColumnCanGroup: function getColumnCanGroup(columnId) {
1066
- var _ref2, _ref3, _column$enableGroupin;
1067
-
1068
- var column = instance.getColumn(columnId);
1069
-
1070
- if (!column) {
1071
- throw new Error();
1072
- }
1073
-
1074
- return (_ref2 = (_ref3 = (_column$enableGroupin = column.enableGrouping) != null ? _column$enableGroupin : instance.options.enableGrouping) != null ? _ref3 : column.defaultCanGroup) != null ? _ref2 : !!column.accessorFn;
1075
- },
1076
- getColumnIsGrouped: function getColumnIsGrouped(columnId) {
1077
- var _instance$getState$gr;
1078
-
1079
- return (_instance$getState$gr = instance.getState().grouping) == null ? void 0 : _instance$getState$gr.includes(columnId);
1080
- },
1081
- getColumnGroupedIndex: function getColumnGroupedIndex(columnId) {
1082
- var _instance$getState$gr2;
1083
-
1084
- return (_instance$getState$gr2 = instance.getState().grouping) == null ? void 0 : _instance$getState$gr2.indexOf(columnId);
1085
- },
1086
- resetGrouping: function resetGrouping() {
1087
- var _instance$initialStat, _instance$initialStat2;
1088
-
1089
- instance.setGrouping((_instance$initialStat = (_instance$initialStat2 = instance.initialState) == null ? void 0 : _instance$initialStat2.grouping) != null ? _instance$initialStat : []);
1090
- },
1091
- getToggleGroupingProps: function getToggleGroupingProps(columnId, userProps) {
1092
- var column = instance.getColumn(columnId);
1093
-
1094
- if (!column) {
1095
- return;
1096
- }
1097
-
1098
- var canGroup = column.getCanGroup();
1099
- var initialProps = {
1100
- title: canGroup ? 'Toggle Grouping' : undefined,
1101
- onClick: canGroup ? function (e) {
1102
- e.persist();
1103
- column.toggleGrouping == null ? void 0 : column.toggleGrouping();
1104
- } : undefined
1105
- };
1106
- return propGetter(initialProps, userProps);
1107
- },
1108
- getRowIsGrouped: function getRowIsGrouped(rowId) {
1109
- var _instance$getRow;
1110
-
1111
- return !!((_instance$getRow = instance.getRow(rowId)) != null && _instance$getRow.groupingColumnId);
1112
- },
1113
- getGroupedRowModel: memo(function () {
1114
- return [instance.getState().grouping, instance.getSortedRowModel(), instance.options.groupRowsFn];
1115
- }, function (grouping, rowModel, groupRowsFn) {
1116
- if (!groupRowsFn || !grouping.length) {
1117
- return rowModel;
1118
- }
1119
-
1120
- if (instance.options.debug) console.info('Grouping...');
1121
- return groupRowsFn(instance, rowModel);
1122
- }, {
1123
- key: 'getGroupedRowModel',
1124
- debug: instance.options.debug,
1125
- onChange: function onChange() {
1126
- return instance._notifyExpandedReset();
1127
- }
1128
- }),
1129
- getPreGroupedRows: function getPreGroupedRows() {
1130
- return instance.getSortedRowModel().rows;
1131
- },
1132
- getPreGroupedFlatRows: function getPreGroupedFlatRows() {
1133
- return instance.getSortedRowModel().flatRows;
1134
- },
1135
- getPreGroupedRowsById: function getPreGroupedRowsById() {
1136
- return instance.getSortedRowModel().rowsById;
1137
- },
1138
- getGroupedRows: function getGroupedRows() {
1139
- return instance.getGroupedRowModel().rows;
1140
- },
1141
- getGroupedFlatRows: function getGroupedFlatRows() {
1142
- return instance.getGroupedRowModel().flatRows;
1143
- },
1144
- getGroupedRowsById: function getGroupedRowsById() {
1145
- return instance.getGroupedRowModel().rowsById;
1146
- }
1147
- };
1148
- }
1149
- function createRow$3(row, instance) {
1150
- return {
1151
- getIsGrouped: function getIsGrouped() {
1152
- return instance.getRowIsGrouped(row.id);
1153
- }
1154
- };
1155
- }
1156
- function createCell(cell, column, row, _instance) {
1157
- return {
1158
- getIsGrouped: function getIsGrouped() {
1159
- return column.getIsGrouped() && column.id === row.groupingColumnId;
1160
- },
1161
- getIsPlaceholder: function getIsPlaceholder() {
1162
- return !cell.getIsGrouped() && column.getIsGrouped();
1163
- },
1164
- getIsAggregated: function getIsAggregated() {
1165
- var _row$subRows;
1166
-
1167
- return !cell.getIsGrouped() && !cell.getIsPlaceholder() && ((_row$subRows = row.subRows) == null ? void 0 : _row$subRows.length) > 1;
1168
- }
1169
- };
1170
- }
1171
- function orderColumns(leafColumns, grouping, groupedColumnMode) {
1172
- if (!(grouping != null && grouping.length) || !groupedColumnMode) {
1173
- return leafColumns;
1174
- }
1175
-
1176
- var nonGroupingColumns = leafColumns.filter(function (col) {
1177
- return !grouping.includes(col.id);
1178
- });
1179
-
1180
- if (groupedColumnMode === 'remove') {
1181
- return nonGroupingColumns;
1182
- }
1183
-
1184
- var groupingColumns = grouping.map(function (g) {
1185
- return leafColumns.find(function (col) {
1186
- return col.id === g;
1187
- });
1188
- }).filter(Boolean);
1189
- return [].concat(groupingColumns, nonGroupingColumns);
1190
- }
1191
-
1192
- var Grouping = /*#__PURE__*/Object.freeze({
1193
- __proto__: null,
1194
- getDefaultColumn: getDefaultColumn$2,
1195
- getInitialState: getInitialState$8,
1196
- getDefaultOptions: getDefaultOptions$8,
1197
- createColumn: createColumn$4,
1198
- getInstance: getInstance$9,
1199
- createRow: createRow$3,
1200
- createCell: createCell,
1201
- orderColumns: orderColumns
1202
- });
1203
-
1204
- //
1205
- function getInitialState$7() {
1206
- return {
1207
- columnOrder: []
1208
- };
1209
- }
1210
- function getDefaultOptions$7(instance) {
1211
- return {
1212
- onColumnOrderChange: makeStateUpdater('columnOrder', instance)
1213
- };
1214
- }
1215
- function getInstance$8(instance) {
1216
- return {
1217
- setColumnOrder: function setColumnOrder(updater) {
1218
- return instance.options.onColumnOrderChange == null ? void 0 : instance.options.onColumnOrderChange(updater, functionalUpdate(updater, instance.getState().columnOrder));
1219
- },
1220
- resetColumnOrder: function resetColumnOrder() {
1221
- var _instance$initialStat;
1222
-
1223
- instance.setColumnOrder((_instance$initialStat = instance.initialState.columnOrder) != null ? _instance$initialStat : []);
1224
- },
1225
- getOrderColumnsFn: memo(function () {
1226
- return [instance.getState().columnOrder, instance.getState().grouping, instance.options.groupedColumnMode];
1227
- }, function (columnOrder, grouping, groupedColumnMode) {
1228
- return function (columns) {
1229
- // Sort grouped columns to the start of the column list
1230
- // before the headers are built
1231
- var orderedColumns = []; // If there is no order, return the normal columns
1232
-
1233
- if (!(columnOrder != null && columnOrder.length)) {
1234
- orderedColumns = columns;
1235
- } else {
1236
- var columnOrderCopy = [].concat(columnOrder); // If there is an order, make a copy of the columns
1237
-
1238
- var columnsCopy = [].concat(columns); // And make a new ordered array of the columns
1239
- // Loop over the columns and place them in order into the new array
1240
-
1241
- var _loop = function _loop() {
1242
- var targetColumnId = columnOrderCopy.shift();
1243
- var foundIndex = columnsCopy.findIndex(function (d) {
1244
- return d.id === targetColumnId;
1245
- });
1246
-
1247
- if (foundIndex > -1) {
1248
- orderedColumns.push(columnsCopy.splice(foundIndex, 1)[0]);
1249
- }
1250
- };
1251
-
1252
- while (columnsCopy.length && columnOrderCopy.length) {
1253
- _loop();
1254
- } // If there are any columns left, add them to the end
1255
-
1256
-
1257
- orderedColumns = [].concat(orderedColumns, columnsCopy);
1258
- }
1259
-
1260
- return orderColumns(orderedColumns, grouping, groupedColumnMode);
1261
- };
1262
- }, {
1263
- key: 'getOrderColumnsFn',
1264
- debug: instance.options.debug
1265
- })
1266
- };
1267
- }
1268
-
1269
- var Ordering = /*#__PURE__*/Object.freeze({
1270
- __proto__: null,
1271
- getInitialState: getInitialState$7,
1272
- getDefaultOptions: getDefaultOptions$7,
1273
- getInstance: getInstance$8
1274
- });
1275
-
1276
- //
1277
- function getInitialState$6() {
1278
- return {
1279
- columnPinning: {
1280
- left: [],
1281
- right: []
1282
- }
1283
- };
1284
- }
1285
- function getDefaultOptions$6(instance) {
1286
- return {
1287
- onColumnPinningChange: makeStateUpdater('columnPinning', instance)
1288
- };
1289
- }
1290
- function createColumn$3(column, instance) {
1291
- return {
1292
- getCanPin: function getCanPin() {
1293
- return instance.getColumnCanPin(column.id);
1294
- },
1295
- getPinnedIndex: function getPinnedIndex() {
1296
- return instance.getColumnPinnedIndex(column.id);
1297
- },
1298
- getIsPinned: function getIsPinned() {
1299
- return instance.getColumnIsPinned(column.id);
1300
- },
1301
- pin: function pin(position) {
1302
- return instance.pinColumn(column.id, position);
1303
- }
1304
- };
1305
- }
1306
- function getInstance$7(instance) {
1307
- return {
1308
- setColumnPinning: function setColumnPinning(updater) {
1309
- return instance.options.onColumnPinningChange == null ? void 0 : instance.options.onColumnPinningChange(updater, functionalUpdate(updater, instance.getState().columnPinning));
1310
- },
1311
- resetColumnPinning: function resetColumnPinning() {
1312
- var _instance$initialStat, _instance$initialStat2;
1313
-
1314
- return instance.setColumnPinning((_instance$initialStat = (_instance$initialStat2 = instance.initialState) == null ? void 0 : _instance$initialStat2.columnPinning) != null ? _instance$initialStat : {});
1315
- },
1316
- pinColumn: function pinColumn(columnId, position) {
1317
- var column = instance.getColumn(columnId);
1318
- var columnIds = column == null ? void 0 : column.getLeafColumns().map(function (d) {
1319
- return d.id;
1320
- }).filter(Boolean);
1321
- instance.setColumnPinning(function (old) {
1322
- var _old$left3, _old$right3;
1323
-
1324
- if (position === 'right') {
1325
- var _old$left, _old$right;
1326
-
1327
- return {
1328
- left: ((_old$left = old == null ? void 0 : old.left) != null ? _old$left : []).filter(function (d) {
1329
- return !(columnIds != null && columnIds.includes(d));
1330
- }),
1331
- right: [].concat(((_old$right = old == null ? void 0 : old.right) != null ? _old$right : []).filter(function (d) {
1332
- return !(columnIds != null && columnIds.includes(d));
1333
- }), columnIds)
1334
- };
1335
- }
1336
-
1337
- if (position === 'left') {
1338
- var _old$left2, _old$right2;
1339
-
1340
- return {
1341
- left: [].concat(((_old$left2 = old == null ? void 0 : old.left) != null ? _old$left2 : []).filter(function (d) {
1342
- return !(columnIds != null && columnIds.includes(d));
1343
- }), columnIds),
1344
- right: ((_old$right2 = old == null ? void 0 : old.right) != null ? _old$right2 : []).filter(function (d) {
1345
- return !(columnIds != null && columnIds.includes(d));
1346
- })
1347
- };
1348
- }
1349
-
1350
- return {
1351
- left: ((_old$left3 = old == null ? void 0 : old.left) != null ? _old$left3 : []).filter(function (d) {
1352
- return !(columnIds != null && columnIds.includes(d));
1353
- }),
1354
- right: ((_old$right3 = old == null ? void 0 : old.right) != null ? _old$right3 : []).filter(function (d) {
1355
- return !(columnIds != null && columnIds.includes(d));
1356
- })
1357
- };
1358
- });
1359
- },
1360
- getColumnCanPin: function getColumnCanPin(columnId) {
1361
- var column = instance.getColumn(columnId);
1362
-
1363
- if (!column) {
1364
- throw new Error();
1365
- }
1366
-
1367
- var leafColumns = column.getLeafColumns();
1368
- return leafColumns.some(function (d) {
1369
- var _ref, _ref2, _d$enablePinning;
1370
-
1371
- return (_ref = (_ref2 = (_d$enablePinning = d.enablePinning) != null ? _d$enablePinning : instance.options.enablePinning) != null ? _ref2 : d.defaultCanPin) != null ? _ref : !!d.accessorFn;
1372
- });
1373
- },
1374
- getColumnIsPinned: function getColumnIsPinned(columnId) {
1375
- var column = instance.getColumn(columnId);
1376
-
1377
- if (!column) {
1378
- throw new Error();
1379
- }
1380
-
1381
- var leafColumnIds = column.getLeafColumns().map(function (d) {
1382
- return d.id;
1383
- });
1384
- var _instance$getState$co = instance.getState().columnPinning,
1385
- left = _instance$getState$co.left,
1386
- right = _instance$getState$co.right;
1387
- var isLeft = leafColumnIds.some(function (d) {
1388
- return left == null ? void 0 : left.includes(d);
1389
- });
1390
- var isRight = leafColumnIds.some(function (d) {
1391
- return right == null ? void 0 : right.includes(d);
1392
- });
1393
- return isLeft ? 'left' : isRight ? 'right' : false;
1394
- },
1395
- getColumnPinnedIndex: function getColumnPinnedIndex(columnId) {
1396
- var _instance$getState$co2, _instance$getState$co3, _instance$getState$co4;
1397
-
1398
- var position = instance.getColumnIsPinned(columnId);
1399
- return position ? (_instance$getState$co2 = (_instance$getState$co3 = instance.getState().columnPinning) == null ? void 0 : (_instance$getState$co4 = _instance$getState$co3[position]) == null ? void 0 : _instance$getState$co4.indexOf(columnId)) != null ? _instance$getState$co2 : -1 : 0;
1400
- }
1401
- };
1402
- }
1403
-
1404
- var Pinning = /*#__PURE__*/Object.freeze({
1405
- __proto__: null,
1406
- getInitialState: getInitialState$6,
1407
- getDefaultOptions: getDefaultOptions$6,
1408
- createColumn: createColumn$3,
1409
- getInstance: getInstance$7
1410
- });
1411
-
1412
- //
1413
- function createRow$2(row, instance) {
1414
- return {
1415
- _getAllVisibleCells: memo(function () {
1416
- return [row.getAllCells().filter(function (cell) {
1417
- return cell.column.getIsVisible();
1418
- }).map(function (d) {
1419
- return d.id;
1420
- }).join('_')];
1421
- }, function (_) {
1422
- return row.getAllCells().filter(function (cell) {
1423
- return cell.column.getIsVisible();
1424
- });
1425
- }, {
1426
- key: 'row._getAllVisibleCells',
1427
- debug: instance.options.debug
1428
- }),
1429
- getVisibleCells: memo(function () {
1430
- return [row.getLeftVisibleCells(), row.getCenterVisibleCells(), row.getRightVisibleCells()];
1431
- }, function (left, center, right) {
1432
- return [].concat(left, center, right);
1433
- }, {
1434
- key: 'row.getVisibleCells',
1435
- debug: instance.options.debug
1436
- }),
1437
- getCenterVisibleCells: memo(function () {
1438
- return [row._getAllVisibleCells(), instance.getState().columnPinning.left, instance.getState().columnPinning.right];
1439
- }, function (allCells, left, right) {
1440
- var leftAndRight = [].concat(left != null ? left : [], right != null ? right : []);
1441
- return allCells.filter(function (d) {
1442
- return !leftAndRight.includes(d.columnId);
1443
- });
1444
- }, {
1445
- key: 'row.getCenterVisibleCells',
1446
- debug: instance.options.debug
1447
- }),
1448
- getLeftVisibleCells: memo(function () {
1449
- return [row._getAllVisibleCells(), instance.getState().columnPinning.left,,];
1450
- }, function (allCells, left) {
1451
- var cells = (left != null ? left : []).map(function (columnId) {
1452
- return allCells.find(function (cell) {
1453
- return cell.columnId === columnId;
1454
- });
1455
- }).filter(Boolean);
1456
- return cells;
1457
- }, {
1458
- key: 'row.getLeftVisibleCells',
1459
- debug: instance.options.debug
1460
- }),
1461
- getRightVisibleCells: memo(function () {
1462
- return [row._getAllVisibleCells(), instance.getState().columnPinning.right];
1463
- }, function (allCells, right) {
1464
- var cells = (right != null ? right : []).map(function (columnId) {
1465
- return allCells.find(function (cell) {
1466
- return cell.columnId === columnId;
1467
- });
1468
- }).filter(Boolean);
1469
- return cells;
1470
- }, {
1471
- key: 'row.getRightVisibleCells',
1472
- debug: instance.options.debug
1473
- })
1474
- };
1475
- }
1476
- function getInstance$6(instance) {
1477
- return {
1478
- createHeader: function createHeader(column, options) {
1479
- var _options$id;
1480
-
1481
- var id = (_options$id = options.id) != null ? _options$id : column.id;
1482
- var header = {
1483
- id: id,
1484
- column: column,
1485
- isPlaceholder: options.isPlaceholder,
1486
- placeholderId: options.placeholderId,
1487
- depth: options.depth,
1488
- subHeaders: [],
1489
- colSpan: 0,
1490
- rowSpan: 0,
1491
- getWidth: function getWidth() {
1492
- var sum = 0;
1493
-
1494
- var recurse = function recurse(header) {
1495
- if (header.subHeaders.length) {
1496
- header.subHeaders.forEach(recurse);
1497
- } else {
1498
- var _header$column$getWid;
1499
-
1500
- sum += (_header$column$getWid = header.column.getWidth()) != null ? _header$column$getWid : 0;
1501
- }
1502
- };
1503
-
1504
- recurse(header);
1505
- return sum;
1506
- },
1507
- getLeafHeaders: function getLeafHeaders() {
1508
- var leafHeaders = [];
1509
-
1510
- var recurseHeader = function recurseHeader(h) {
1511
- if (h.subHeaders && h.subHeaders.length) {
1512
- h.subHeaders.map(recurseHeader);
1513
- }
1514
-
1515
- leafHeaders.push(h);
1516
- };
1517
-
1518
- recurseHeader(header);
1519
- return leafHeaders;
1520
- },
1521
- getHeaderProps: function getHeaderProps(userProps) {
1522
- return instance.getHeaderProps(header.id, userProps);
1523
- },
1524
- getFooterProps: function getFooterProps(userProps) {
1525
- return instance.getFooterProps(header.id, userProps);
1526
- },
1527
- renderHeader: function renderHeader() {
1528
- return flexRender(column.header, {
1529
- instance: instance,
1530
- header: header,
1531
- column: column
1532
- });
1533
- },
1534
- renderFooter: function renderFooter() {
1535
- return flexRender(column.footer, {
1536
- instance: instance,
1537
- header: header,
1538
- column: column
1539
- });
1540
- }
1541
- }; // Yes, we have to convert instance to uknown, because we know more than the compiler here.
1542
-
1543
- return header;
1544
- },
1545
- // Header Groups
1546
- getHeaderGroups: memo(function () {
1547
- return [instance.getAllColumns(), instance.getVisibleLeafColumns(), instance.getState().columnPinning.left, instance.getState().columnPinning.right];
1548
- }, function (allColumns, leafColumns, left, right) {
1549
- var leftColumns = leafColumns.filter(function (column) {
1550
- return left == null ? void 0 : left.includes(column.id);
1551
- });
1552
- var rightColumns = leafColumns.filter(function (column) {
1553
- return right == null ? void 0 : right.includes(column.id);
1554
- });
1555
- var centerColumns = leafColumns.filter(function (column) {
1556
- return !(left != null && left.includes(column.id)) && !(right != null && right.includes(column.id));
1557
- });
1558
- var headerGroups = buildHeaderGroups(allColumns, [].concat(leftColumns, centerColumns, rightColumns), instance);
1559
- return headerGroups;
1560
- }, {
1561
- key: 'getHeaderGroups',
1562
- debug: instance.options.debug
1563
- }),
1564
- getCenterHeaderGroups: memo(function () {
1565
- return [instance.getAllColumns(), instance.getVisibleLeafColumns(), instance.getState().columnPinning.left, instance.getState().columnPinning.right];
1566
- }, function (allColumns, leafColumns, left, right) {
1567
- leafColumns = leafColumns.filter(function (column) {
1568
- return !(left != null && left.includes(column.id)) && !(right != null && right.includes(column.id));
1569
- });
1570
- return buildHeaderGroups(allColumns, leafColumns, instance, 'center');
1571
- }, {
1572
- key: 'getCenterHeaderGroups',
1573
- debug: instance.options.debug
1574
- }),
1575
- getLeftHeaderGroups: memo(function () {
1576
- return [instance.getAllColumns(), instance.getVisibleLeafColumns(), instance.getState().columnPinning.left];
1577
- }, function (allColumns, leafColumns, left) {
1578
- leafColumns = leafColumns.filter(function (column) {
1579
- return left == null ? void 0 : left.includes(column.id);
1580
- });
1581
- return buildHeaderGroups(allColumns, leafColumns, instance, 'left');
1582
- }, {
1583
- key: 'getLeftHeaderGroups',
1584
- debug: instance.options.debug
1585
- }),
1586
- getRightHeaderGroups: memo(function () {
1587
- return [instance.getAllColumns(), instance.getVisibleLeafColumns(), instance.getState().columnPinning.right];
1588
- }, function (allColumns, leafColumns, right) {
1589
- leafColumns = leafColumns.filter(function (column) {
1590
- return right == null ? void 0 : right.includes(column.id);
1591
- });
1592
- return buildHeaderGroups(allColumns, leafColumns, instance, 'right');
1593
- }, {
1594
- key: 'getRightHeaderGroups',
1595
- debug: instance.options.debug
1596
- }),
1597
- // Footer Groups
1598
- getFooterGroups: memo(function () {
1599
- return [instance.getHeaderGroups()];
1600
- }, function (headerGroups) {
1601
- return [].concat(headerGroups).reverse();
1602
- }, {
1603
- key: 'getFooterGroups',
1604
- debug: instance.options.debug
1605
- }),
1606
- getLeftFooterGroups: memo(function () {
1607
- return [instance.getLeftHeaderGroups()];
1608
- }, function (headerGroups) {
1609
- return [].concat(headerGroups).reverse();
1610
- }, {
1611
- key: 'getLeftFooterGroups',
1612
- debug: instance.options.debug
1613
- }),
1614
- getCenterFooterGroups: memo(function () {
1615
- return [instance.getCenterHeaderGroups()];
1616
- }, function (headerGroups) {
1617
- return [].concat(headerGroups).reverse();
1618
- }, {
1619
- key: 'getCenterFooterGroups',
1620
- debug: instance.options.debug
1621
- }),
1622
- getRightFooterGroups: memo(function () {
1623
- return [instance.getRightHeaderGroups()];
1624
- }, function (headerGroups) {
1625
- return [].concat(headerGroups).reverse();
1626
- }, {
1627
- key: 'getRightFooterGroups',
1628
- debug: instance.options.debug
1629
- }),
1630
- // Flat Headers
1631
- getFlatHeaders: memo(function () {
1632
- return [instance.getHeaderGroups()];
1633
- }, function (headerGroups) {
1634
- return headerGroups.map(function (headerGroup) {
1635
- return headerGroup.headers;
1636
- }).flat();
1637
- }, {
1638
- key: 'getFlatHeaders',
1639
- debug: instance.options.debug
1640
- }),
1641
- getLeftFlatHeaders: memo(function () {
1642
- return [instance.getLeftHeaderGroups()];
1643
- }, function (left) {
1644
- return left.map(function (headerGroup) {
1645
- return headerGroup.headers;
1646
- }).flat();
1647
- }, {
1648
- key: 'getLeftFlatHeaders',
1649
- debug: instance.options.debug
1650
- }),
1651
- getCenterFlatHeaders: memo(function () {
1652
- return [instance.getCenterHeaderGroups()];
1653
- }, function (left) {
1654
- return left.map(function (headerGroup) {
1655
- return headerGroup.headers;
1656
- }).flat();
1657
- }, {
1658
- key: 'getCenterFlatHeaders',
1659
- debug: instance.options.debug
1660
- }),
1661
- getRightFlatHeaders: memo(function () {
1662
- return [instance.getRightHeaderGroups()];
1663
- }, function (left) {
1664
- return left.map(function (headerGroup) {
1665
- return headerGroup.headers;
1666
- }).flat();
1667
- }, {
1668
- key: 'getRightFlatHeaders',
1669
- debug: instance.options.debug
1670
- }),
1671
- // Leaf Headers
1672
- getCenterLeafHeaders: memo(function () {
1673
- return [instance.getCenterFlatHeaders()];
1674
- }, function (flatHeaders) {
1675
- return flatHeaders.filter(function (header) {
1676
- var _header$subHeaders;
1677
-
1678
- return !((_header$subHeaders = header.subHeaders) != null && _header$subHeaders.length);
1679
- });
1680
- }, {
1681
- key: 'getCenterLeafHeaders',
1682
- debug: instance.options.debug
1683
- }),
1684
- getLeftLeafHeaders: memo(function () {
1685
- return [instance.getLeftFlatHeaders()];
1686
- }, function (flatHeaders) {
1687
- return flatHeaders.filter(function (header) {
1688
- var _header$subHeaders2;
1689
-
1690
- return !((_header$subHeaders2 = header.subHeaders) != null && _header$subHeaders2.length);
1691
- });
1692
- }, {
1693
- key: 'getLeftLeafHeaders',
1694
- debug: instance.options.debug
1695
- }),
1696
- getRightLeafHeaders: memo(function () {
1697
- return [instance.getRightFlatHeaders()];
1698
- }, function (flatHeaders) {
1699
- return flatHeaders.filter(function (header) {
1700
- var _header$subHeaders3;
1701
-
1702
- return !((_header$subHeaders3 = header.subHeaders) != null && _header$subHeaders3.length);
1703
- });
1704
- }, {
1705
- key: 'getRightLeafHeaders',
1706
- debug: instance.options.debug
1707
- }),
1708
- getLeafHeaders: memo(function () {
1709
- return [instance.getLeftHeaderGroups(), instance.getCenterHeaderGroups(), instance.getRightHeaderGroups()];
1710
- }, function (left, center, right) {
1711
- var _left$0$headers, _left$, _center$0$headers, _center$, _right$0$headers, _right$;
1712
-
1713
- return [].concat((_left$0$headers = (_left$ = left[0]) == null ? void 0 : _left$.headers) != null ? _left$0$headers : [], (_center$0$headers = (_center$ = center[0]) == null ? void 0 : _center$.headers) != null ? _center$0$headers : [], (_right$0$headers = (_right$ = right[0]) == null ? void 0 : _right$.headers) != null ? _right$0$headers : []).map(function (header) {
1714
- return header.getLeafHeaders();
1715
- }).flat();
1716
- }, {
1717
- key: 'getLeafHeaders',
1718
- debug: instance.options.debug
1719
- }),
1720
- getHeader: function getHeader(id) {
1721
- var header = [].concat(instance.getFlatHeaders(), instance.getCenterFlatHeaders(), instance.getLeftFlatHeaders(), instance.getRightFlatHeaders()).find(function (d) {
1722
- return d.id === id;
1723
- });
1724
-
1725
- if (!header) {
1726
- {
1727
- console.warn("Could not find header with id: " + id);
1728
- }
1729
-
1730
- throw new Error();
1731
- }
1732
-
1733
- return header;
1734
- },
1735
- getHeaderGroupProps: function getHeaderGroupProps(id, userProps) {
1736
- var headerGroup = instance.getHeaderGroups().find(function (d) {
1737
- return d.id === id;
1738
- });
1739
-
1740
- if (!headerGroup) {
1741
- return;
1742
- }
1743
-
1744
- return propGetter({
1745
- key: headerGroup.id,
1746
- role: 'row'
1747
- }, userProps);
1748
- },
1749
- getFooterGroupProps: function getFooterGroupProps(id, userProps) {
1750
- var headerGroup = instance.getFooterGroups().find(function (d) {
1751
- return d.id === id;
1752
- });
1753
-
1754
- if (!headerGroup) {
1755
- return;
1756
- }
1757
-
1758
- var initialProps = {
1759
- key: headerGroup.id,
1760
- role: 'row'
1761
- };
1762
- return propGetter(initialProps, userProps);
1763
- },
1764
- getHeaderProps: function getHeaderProps(id, userProps) {
1765
- var header = instance.getHeader(id);
1766
-
1767
- if (!header) {
1768
- throw new Error();
1769
- }
1770
-
1771
- var initialProps = {
1772
- key: header.id,
1773
- role: 'columnheader',
1774
- colSpan: header.colSpan,
1775
- rowSpan: header.rowSpan
1776
- };
1777
- return propGetter(initialProps, userProps);
1778
- },
1779
- getFooterProps: function getFooterProps(id, userProps) {
1780
- var header = instance.getHeader(id);
1781
-
1782
- if (!header) {
1783
- return;
1784
- }
1785
-
1786
- var initialProps = {
1787
- key: header.id,
1788
- role: 'columnfooter',
1789
- colSpan: header.colSpan,
1790
- rowSpan: header.rowSpan
1791
- };
1792
- return propGetter(initialProps, userProps);
1793
- },
1794
- getTotalWidth: function getTotalWidth() {
1795
- var width = 0;
1796
- instance.getVisibleLeafColumns().forEach(function (column) {
1797
- var _column$getWidth;
1798
-
1799
- width += (_column$getWidth = column.getWidth()) != null ? _column$getWidth : 0;
1800
- });
1801
- return width;
1802
- }
1803
- };
1804
- }
1805
- function buildHeaderGroups(allColumns, columnsToGroup, instance, headerFamily) {
1806
- var _headerGroups$0$heade, _headerGroups$;
1807
-
1808
- // Find the max depth of the columns:
1809
- // build the leaf column row
1810
- // build each buffer row going up
1811
- // placeholder for non-existent level
1812
- // real column for existing level
1813
- var maxDepth = 0;
1814
-
1815
- var findMaxDepth = function findMaxDepth(columns, depth) {
1816
- if (depth === void 0) {
1817
- depth = 1;
1818
- }
1819
-
1820
- maxDepth = Math.max(maxDepth, depth);
1821
- columns.filter(function (column) {
1822
- return column.getIsVisible();
1823
- }).forEach(function (column) {
1824
- var _column$columns;
1825
-
1826
- if ((_column$columns = column.columns) != null && _column$columns.length) {
1827
- findMaxDepth(column.columns, depth + 1);
1828
- }
1829
- }, 0);
1830
- };
1831
-
1832
- findMaxDepth(allColumns);
1833
- var headerGroups = [];
1834
-
1835
- var createHeaderGroup = function createHeaderGroup(headersToGroup, depth) {
1836
- // The header group we are creating
1837
- var headerGroup = {
1838
- depth: depth,
1839
- id: [headerFamily, "" + depth].filter(Boolean).join('_'),
1840
- headers: [],
1841
- getHeaderGroupProps: function getHeaderGroupProps(getterValue) {
1842
- return instance.getHeaderGroupProps("" + depth, getterValue);
1843
- },
1844
- getFooterGroupProps: function getFooterGroupProps(getterValue) {
1845
- return instance.getFooterGroupProps("" + depth, getterValue);
1846
- }
1847
- }; // The parent columns we're going to scan next
1848
-
1849
- var parentHeaders = []; // Scan each column for parents
1850
-
1851
- headersToGroup.forEach(function (headerToGroup) {
1852
- // What is the latest (last) parent column?
1853
- var latestParentHeader = [].concat(parentHeaders).reverse()[0];
1854
- var isLeafHeader = headerToGroup.column.depth === headerGroup.depth;
1855
- var column;
1856
- var isPlaceholder = false;
1857
-
1858
- if (isLeafHeader && headerToGroup.column.parent) {
1859
- // The parent header is new
1860
- column = headerToGroup.column.parent;
1861
- } else {
1862
- // The parent header is repeated
1863
- column = headerToGroup.column;
1864
- isPlaceholder = true;
1865
- }
1866
-
1867
- var header = instance.createHeader(column, {
1868
- id: [headerFamily, depth, column.id, headerToGroup == null ? void 0 : headerToGroup.id].filter(Boolean).join('_'),
1869
- isPlaceholder: isPlaceholder,
1870
- placeholderId: isPlaceholder ? "" + parentHeaders.filter(function (d) {
1871
- return d.column === column;
1872
- }).length : undefined,
1873
- depth: depth
1874
- });
1875
-
1876
- if (!latestParentHeader || latestParentHeader.column !== header.column) {
1877
- header.subHeaders.push(headerToGroup);
1878
- parentHeaders.push(header);
1879
- } else {
1880
- latestParentHeader.subHeaders.push(headerToGroup);
1881
- } // if (!headerToGroup.isPlaceholder) {
1882
- // headerToGroup.column.header = headerToGroup;
1883
- // }
1884
-
1885
-
1886
- headerGroup.headers.push(headerToGroup);
1887
- });
1888
- headerGroups.push(headerGroup);
1889
-
1890
- if (depth > 0) {
1891
- createHeaderGroup(parentHeaders, depth - 1);
1892
- }
1893
- };
1894
-
1895
- var bottomHeaders = columnsToGroup.map(function (column) {
1896
- return instance.createHeader(column, {
1897
- depth: maxDepth
1898
- });
120
+ exports.createTable = createTable;
121
+ exports.render = render;
122
+ exports.useTableInstance = useTableInstance;
123
+ Object.keys(tableCore).forEach(function (k) {
124
+ if (k !== 'default' && !exports.hasOwnProperty(k)) Object.defineProperty(exports, k, {
125
+ enumerable: true,
126
+ get: function () { return tableCore[k]; }
1899
127
  });
1900
- createHeaderGroup(bottomHeaders, maxDepth - 1);
1901
- headerGroups.reverse(); // headerGroups = headerGroups.filter(headerGroup => {
1902
- // return !headerGroup.headers.every(header => header.isPlaceholder)
1903
- // })
1904
-
1905
- var recurseHeadersForSpans = function recurseHeadersForSpans(headers) {
1906
- var filteredHeaders = headers.filter(function (header) {
1907
- return header.column.getIsVisible();
1908
- });
1909
- return filteredHeaders.map(function (header) {
1910
- var colSpan = 0;
1911
- var rowSpan = 0;
1912
- var childRowSpans = [0];
1913
-
1914
- if (header.subHeaders && header.subHeaders.length) {
1915
- childRowSpans = [];
1916
- recurseHeadersForSpans(header.subHeaders).forEach(function (_ref) {
1917
- var childColSpan = _ref.colSpan,
1918
- childRowSpan = _ref.rowSpan;
1919
- colSpan += childColSpan;
1920
- childRowSpans.push(childRowSpan);
1921
- });
1922
- } else {
1923
- colSpan = 1;
1924
- }
1925
-
1926
- var minChildRowSpan = Math.min.apply(Math, childRowSpans);
1927
- rowSpan = rowSpan + minChildRowSpan;
1928
- header.colSpan = colSpan > 0 ? colSpan : undefined;
1929
- header.rowSpan = rowSpan > 0 ? rowSpan : undefined;
1930
- return {
1931
- colSpan: colSpan,
1932
- rowSpan: rowSpan
1933
- };
1934
- });
1935
- };
1936
-
1937
- recurseHeadersForSpans((_headerGroups$0$heade = (_headerGroups$ = headerGroups[0]) == null ? void 0 : _headerGroups$.headers) != null ? _headerGroups$0$heade : []);
1938
- return headerGroups;
1939
- }
1940
-
1941
- var Headers = /*#__PURE__*/Object.freeze({
1942
- __proto__: null,
1943
- createRow: createRow$2,
1944
- getInstance: getInstance$6,
1945
- buildHeaderGroups: buildHeaderGroups
1946
128
  });
1947
129
 
1948
- var filterTypes = {
1949
- includesString: includesString,
1950
- includesStringSensitive: includesStringSensitive,
1951
- equalsString: equalsString,
1952
- equalsStringSensitive: equalsStringSensitive,
1953
- arrIncludes: arrIncludes,
1954
- arrIncludesAll: arrIncludesAll,
1955
- equals: equals,
1956
- weakEquals: weakEquals,
1957
- betweenNumberRange: betweenNumberRange
1958
- };
1959
-
1960
- function includesString(rows, columnIds, filterValue) {
1961
- var search = String(filterValue).toLowerCase();
1962
- rows = rows.filter(function (row) {
1963
- return columnIds.some(function (id) {
1964
- return String(row.values[id]).toLowerCase().includes(search);
1965
- });
1966
- });
1967
- return rows;
1968
- }
1969
-
1970
- includesString.autoRemove = function (val) {
1971
- return testFalsey(val);
1972
- };
1973
-
1974
- function includesStringSensitive(rows, columnIds, filterValue) {
1975
- var search = String(filterValue);
1976
- rows = rows.filter(function (row) {
1977
- return columnIds.some(function (id) {
1978
- return String(row.values[id]).includes(search);
1979
- });
1980
- });
1981
- return rows;
1982
- }
1983
-
1984
- includesStringSensitive.autoRemove = function (val) {
1985
- return testFalsey(val);
1986
- };
1987
-
1988
- function equalsString(rows, columnIds, filterValue) {
1989
- var search = String(filterValue).toLowerCase();
1990
- return rows.filter(function (row) {
1991
- return columnIds.some(function (id) {
1992
- var rowValue = row.values[id];
1993
- return rowValue !== undefined ? String(rowValue).toLowerCase() === search : true;
1994
- });
1995
- });
1996
- }
1997
-
1998
- equalsString.autoRemove = function (val) {
1999
- return testFalsey(val);
2000
- };
2001
-
2002
- function equalsStringSensitive(rows, columnIds, filterValue) {
2003
- var search = String(filterValue);
2004
- return rows.filter(function (row) {
2005
- return columnIds.some(function (id) {
2006
- var rowValue = row.values[id];
2007
- return rowValue !== undefined ? String(rowValue) === search : true;
2008
- });
2009
- });
2010
- }
2011
-
2012
- equalsStringSensitive.autoRemove = function (val) {
2013
- return testFalsey(val);
2014
- };
2015
-
2016
- function arrIncludes(rows, columnIds, filterValue) {
2017
- return rows.filter(function (row) {
2018
- return columnIds.some(function (id) {
2019
- var rowValue = row.values[id];
2020
- return rowValue.includes(filterValue);
2021
- });
2022
- });
2023
- }
2024
-
2025
- arrIncludes.autoRemove = function (val) {
2026
- return testFalsey(val) || !(val != null && val.length);
2027
- };
2028
-
2029
- function arrIncludesAll(rows, columnIds, filterValue) {
2030
- return rows.filter(function (row) {
2031
- return columnIds.some(function (id) {
2032
- var rowValue = row.values[id];
2033
- return rowValue && rowValue.length && filterValue.every(function (val) {
2034
- return rowValue.includes(val);
2035
- });
2036
- });
2037
- });
2038
- }
2039
-
2040
- arrIncludesAll.autoRemove = function (val) {
2041
- return testFalsey(val) || !(val != null && val.length);
2042
- };
2043
-
2044
- function equals(rows, columnIds, filterValue) {
2045
- return rows.filter(function (row) {
2046
- return columnIds.some(function (id) {
2047
- var rowValue = row.values[id];
2048
- return rowValue === filterValue;
2049
- });
2050
- });
2051
- }
2052
-
2053
- equals.autoRemove = function (val) {
2054
- return testFalsey(val);
2055
- };
2056
-
2057
- function weakEquals(rows, columnIds, filterValue) {
2058
- return rows.filter(function (row) {
2059
- return columnIds.some(function (id) {
2060
- var rowValue = row.values[id]; // eslint-disable-next-line eqeqeq
2061
-
2062
- return rowValue == filterValue;
2063
- });
2064
- });
2065
- }
2066
-
2067
- weakEquals.autoRemove = function (val) {
2068
- return testFalsey(val);
2069
- };
2070
-
2071
- function betweenNumberRange(rows, columnIds, filterValue) {
2072
- var _ref = filterValue || [],
2073
- unsafeMin = _ref[0],
2074
- unsafeMax = _ref[1];
2075
-
2076
- var parsedMin = typeof unsafeMin !== 'number' ? parseFloat(unsafeMin) : unsafeMin;
2077
- var parsedMax = typeof unsafeMax !== 'number' ? parseFloat(unsafeMax) : unsafeMax;
2078
- var min = unsafeMin === null || Number.isNaN(parsedMin) ? -Infinity : parsedMin;
2079
- var max = unsafeMax === null || Number.isNaN(parsedMax) ? Infinity : parsedMax;
2080
-
2081
- if (min > max) {
2082
- var temp = min;
2083
- min = max;
2084
- max = temp;
2085
- }
2086
-
2087
- return rows.filter(function (row) {
2088
- return columnIds.some(function (id) {
2089
- var rowValue = row.values[id];
2090
- return rowValue >= min && rowValue <= max;
2091
- });
2092
- });
2093
- }
2094
-
2095
- betweenNumberRange.autoRemove = function (val) {
2096
- return testFalsey(val) || testFalsey(val[0]) && testFalsey(val[1]);
2097
- }; // Utils
2098
-
2099
-
2100
- function testFalsey(val) {
2101
- return val === undefined || val === null || val === '';
2102
- }
2103
-
2104
- //
2105
- function getDefaultColumn$1() {
2106
- return {
2107
- filterType: 'auto'
2108
- };
2109
- }
2110
- function getInitialState$5() {
2111
- return {
2112
- columnFilters: [],
2113
- globalFilter: undefined
2114
- };
2115
- }
2116
- function getDefaultOptions$5(instance) {
2117
- return {
2118
- onColumnFiltersChange: makeStateUpdater('columnFilters', instance),
2119
- onGlobalFilterChange: makeStateUpdater('globalFilter', instance),
2120
- autoResetColumnFilters: true,
2121
- filterFromChildrenUp: true,
2122
- autoResetGlobalFilter: true,
2123
- globalFilterType: 'auto',
2124
- getColumnCanGlobalFilterFn: function getColumnCanGlobalFilterFn(column) {
2125
- var _instance$getCoreFlat, _instance$getCoreFlat2;
2126
-
2127
- var value = (_instance$getCoreFlat = instance.getCoreFlatRows()[0]) == null ? void 0 : (_instance$getCoreFlat2 = _instance$getCoreFlat.getAllCellsByColumnId()[column.id]) == null ? void 0 : _instance$getCoreFlat2.value;
2128
- return typeof value === 'string';
2129
- }
2130
- };
2131
- }
2132
- function createColumn$2(column, instance) {
2133
- var getFacetInfo = memo(function () {
2134
- return [column.getPreFilteredRows()];
2135
- }, function (rows) {
2136
- var _rows$0$values$column, _rows$, _rows$0$values$column2, _rows$2;
2137
-
2138
- if (rows === void 0) {
2139
- rows = [];
2140
- }
2141
-
2142
- var preFilteredUniqueValues = new Map();
2143
- var preFilteredMinMaxValues = [(_rows$0$values$column = (_rows$ = rows[0]) == null ? void 0 : _rows$.values[column.id]) != null ? _rows$0$values$column : null, (_rows$0$values$column2 = (_rows$2 = rows[0]) == null ? void 0 : _rows$2.values[column.id]) != null ? _rows$0$values$column2 : null];
2144
-
2145
- for (var i = 0; i < rows.length; i++) {
2146
- var _rows$i;
2147
-
2148
- var _value = (_rows$i = rows[i]) == null ? void 0 : _rows$i.values[column.id];
2149
-
2150
- if (preFilteredUniqueValues.has(_value)) {
2151
- var _preFilteredUniqueVal;
2152
-
2153
- preFilteredUniqueValues.set(_value, ((_preFilteredUniqueVal = preFilteredUniqueValues.get(_value)) != null ? _preFilteredUniqueVal : 0) + 1);
2154
- } else {
2155
- preFilteredUniqueValues.set(_value, 1);
2156
- }
2157
-
2158
- if (_value < preFilteredMinMaxValues[0]) {
2159
- preFilteredMinMaxValues[0] = _value;
2160
- } else if (_value > preFilteredMinMaxValues[1]) {
2161
- preFilteredMinMaxValues[1] = _value;
2162
- }
2163
- }
2164
-
2165
- return {
2166
- preFilteredUniqueValues: preFilteredUniqueValues,
2167
- preFilteredMinMaxValues: preFilteredMinMaxValues
2168
- };
2169
- }, {
2170
- key: 'column.getFacetInfo',
2171
- debug: instance.options.debug
2172
- });
2173
- return {
2174
- filterType: column.filterType,
2175
- getCanColumnFilter: function getCanColumnFilter() {
2176
- return instance.getColumnCanColumnFilter(column.id);
2177
- },
2178
- getCanGlobalFilter: function getCanGlobalFilter() {
2179
- return instance.getColumnCanGlobalFilter(column.id);
2180
- },
2181
- getColumnFilterIndex: function getColumnFilterIndex() {
2182
- return instance.getColumnFilterIndex(column.id);
2183
- },
2184
- getIsColumnFiltered: function getIsColumnFiltered() {
2185
- return instance.getColumnIsFiltered(column.id);
2186
- },
2187
- getColumnFilterValue: function getColumnFilterValue() {
2188
- return instance.getColumnFilterValue(column.id);
2189
- },
2190
- setColumnFilterValue: function setColumnFilterValue(val) {
2191
- return instance.setColumnFilterValue(column.id, val);
2192
- },
2193
- getPreFilteredUniqueValues: function getPreFilteredUniqueValues() {
2194
- return getFacetInfo().preFilteredUniqueValues;
2195
- },
2196
- getPreFilteredMinMaxValues: function getPreFilteredMinMaxValues() {
2197
- return getFacetInfo().preFilteredMinMaxValues;
2198
- },
2199
- getPreFilteredRows: function getPreFilteredRows() {
2200
- return undefined;
2201
- }
2202
- };
2203
- }
2204
- function getInstance$5(instance) {
2205
- var registered = false;
2206
- return {
2207
- _notifyFiltersReset: function _notifyFiltersReset() {
2208
- if (!registered) {
2209
- registered = true;
2210
- return;
2211
- }
2212
-
2213
- if (instance.options.autoResetAll === false) {
2214
- return;
2215
- }
2216
-
2217
- if (instance.options.autoResetAll === true) {
2218
- instance.resetSorting();
2219
- } else {
2220
- if (instance.options.autoResetColumnFilters) {
2221
- instance.resetColumnFilters();
2222
- }
2223
-
2224
- if (instance.options.autoResetGlobalFilter) {
2225
- instance.resetGlobalFilter();
2226
- }
2227
- }
2228
- },
2229
- getColumnAutoFilterFn: function getColumnAutoFilterFn(columnId) {
2230
- var firstRow = instance.getCoreFlatRows()[0];
2231
- var value = firstRow == null ? void 0 : firstRow.values[columnId];
2232
-
2233
- if (typeof value === 'string') {
2234
- return filterTypes.includesString;
2235
- }
2236
-
2237
- if (typeof value === 'number') {
2238
- return filterTypes.betweenNumberRange;
2239
- }
2240
-
2241
- if (value !== null && typeof value === 'object') {
2242
- return filterTypes.equals;
2243
- }
2244
-
2245
- if (Array.isArray(value)) {
2246
- return filterTypes.arrIncludes;
2247
- }
2248
-
2249
- return filterTypes.weakEquals;
2250
- },
2251
- getGlobalAutoFilterFn: function getGlobalAutoFilterFn() {
2252
- return filterTypes.includesString;
2253
- },
2254
- getColumnFilterFn: function getColumnFilterFn(columnId) {
2255
- var _ref;
2256
-
2257
- var column = instance.getColumn(columnId);
2258
- var userFilterTypes = instance.options.filterTypes;
2259
-
2260
- if (!column) {
2261
- throw new Error();
2262
- }
2263
-
2264
- return isFunction(column.filterType) ? column.filterType : column.filterType === 'auto' ? instance.getColumnAutoFilterFn(columnId) : (_ref = userFilterTypes == null ? void 0 : userFilterTypes[column.filterType]) != null ? _ref : filterTypes[column.filterType];
2265
- },
2266
- getGlobalFilterFn: function getGlobalFilterFn() {
2267
- var _ref2;
2268
-
2269
- var _instance$options = instance.options,
2270
- userFilterTypes = _instance$options.filterTypes,
2271
- globalFilterType = _instance$options.globalFilterType;
2272
- return isFunction(globalFilterType) ? globalFilterType : globalFilterType === 'auto' ? instance.getGlobalAutoFilterFn() : (_ref2 = userFilterTypes == null ? void 0 : userFilterTypes[globalFilterType]) != null ? _ref2 : filterTypes[globalFilterType];
2273
- },
2274
- setColumnFilters: function setColumnFilters(updater) {
2275
- var leafColumns = instance.getAllLeafColumns();
2276
-
2277
- var updateFn = function updateFn(old) {
2278
- var _functionalUpdate;
2279
-
2280
- return (_functionalUpdate = functionalUpdate(updater, old)) == null ? void 0 : _functionalUpdate.filter(function (filter) {
2281
- var column = leafColumns.find(function (d) {
2282
- return d.id === filter.id;
2283
- });
2284
-
2285
- if (column) {
2286
- var filterFn = instance.getColumnFilterFn(column.id);
2287
-
2288
- if (shouldAutoRemoveFilter(filterFn, filter.value, column)) {
2289
- return false;
2290
- }
2291
- }
2292
-
2293
- return true;
2294
- });
2295
- };
2296
-
2297
- instance.options.onColumnFiltersChange == null ? void 0 : instance.options.onColumnFiltersChange(updateFn, updateFn(instance.getState().columnFilters));
2298
- },
2299
- setGlobalFilter: function setGlobalFilter(updater) {
2300
- instance.options.onGlobalFilterChange == null ? void 0 : instance.options.onGlobalFilterChange(updater, functionalUpdate(updater, instance.getState().globalFilter));
2301
- },
2302
- resetGlobalFilter: function resetGlobalFilter() {
2303
- instance.setGlobalFilter(undefined);
2304
- },
2305
- getColumnCanColumnFilter: function getColumnCanColumnFilter(columnId) {
2306
- var _ref3, _ref4, _ref5, _ref6, _ref7, _column$enableAllFilt;
2307
-
2308
- var column = instance.getColumn(columnId);
2309
-
2310
- if (!column) {
2311
- throw new Error();
2312
- }
2313
-
2314
- return (_ref3 = (_ref4 = (_ref5 = (_ref6 = (_ref7 = (_column$enableAllFilt = column.enableAllFilters) != null ? _column$enableAllFilt : column.enableColumnFilter) != null ? _ref7 : instance.options.enableFilters) != null ? _ref6 : instance.options.enableColumnFilters) != null ? _ref5 : column.defaultCanFilter) != null ? _ref4 : column.defaultCanColumnFilter) != null ? _ref3 : !!column.accessorFn;
2315
- },
2316
- getColumnCanGlobalFilter: function getColumnCanGlobalFilter(columnId) {
2317
- var _ref8, _ref9, _ref10, _ref11, _ref12, _ref13, _instance$options$ena;
2318
-
2319
- var column = instance.getColumn(columnId);
2320
-
2321
- if (!column) {
2322
- throw new Error();
2323
- }
2324
-
2325
- return (_ref8 = ((_ref9 = (_ref10 = (_ref11 = (_ref12 = (_ref13 = (_instance$options$ena = instance.options.enableFilters) != null ? _instance$options$ena : instance.options.enableGlobalFilter) != null ? _ref13 : column.enableAllFilters) != null ? _ref12 : column.enableGlobalFilter) != null ? _ref11 : column.defaultCanFilter) != null ? _ref10 : column.defaultCanGlobalFilter) != null ? _ref9 : !!column.accessorFn) && (instance.options.getColumnCanGlobalFilterFn == null ? void 0 : instance.options.getColumnCanGlobalFilterFn(column))) != null ? _ref8 : true;
2326
- },
2327
- getColumnIsFiltered: function getColumnIsFiltered(columnId) {
2328
- return instance.getColumnFilterIndex(columnId) > -1;
2329
- },
2330
- getColumnFilterValue: function getColumnFilterValue(columnId) {
2331
- var _instance$getState$co, _instance$getState$co2;
2332
-
2333
- return (_instance$getState$co = instance.getState().columnFilters) == null ? void 0 : (_instance$getState$co2 = _instance$getState$co.find(function (d) {
2334
- return d.id === columnId;
2335
- })) == null ? void 0 : _instance$getState$co2.value;
2336
- },
2337
- getColumnFilterIndex: function getColumnFilterIndex(columnId) {
2338
- var _instance$getState$co3, _instance$getState$co4;
2339
-
2340
- return (_instance$getState$co3 = (_instance$getState$co4 = instance.getState().columnFilters) == null ? void 0 : _instance$getState$co4.findIndex(function (d) {
2341
- return d.id === columnId;
2342
- })) != null ? _instance$getState$co3 : -1;
2343
- },
2344
- setColumnFilterValue: function setColumnFilterValue(columnId, value) {
2345
- if (!columnId) return;
2346
- instance.setColumnFilters(function (old) {
2347
- var column = instance.getColumn(columnId);
2348
-
2349
- if (!column) {
2350
- {
2351
- console.warn("React-Table: Could not find a column with id: " + columnId);
2352
- }
2353
-
2354
- throw new Error();
2355
- }
2356
-
2357
- var filterFn = instance.getColumnFilterFn(column.id);
2358
- var previousfilter = old == null ? void 0 : old.find(function (d) {
2359
- return d.id === columnId;
2360
- });
2361
- var newFilter = functionalUpdate(value, previousfilter ? previousfilter.value : undefined); //
2362
-
2363
- if (shouldAutoRemoveFilter(filterFn, newFilter, column)) {
2364
- var _old$filter;
2365
-
2366
- return (_old$filter = old == null ? void 0 : old.filter(function (d) {
2367
- return d.id !== columnId;
2368
- })) != null ? _old$filter : [];
2369
- }
2370
-
2371
- var newFilterObj = {
2372
- id: columnId,
2373
- value: newFilter
2374
- };
2375
-
2376
- if (previousfilter) {
2377
- var _old$map;
2378
-
2379
- return (_old$map = old == null ? void 0 : old.map(function (d) {
2380
- if (d.id === columnId) {
2381
- return newFilterObj;
2382
- }
2383
-
2384
- return d;
2385
- })) != null ? _old$map : [];
2386
- }
2387
-
2388
- if (old != null && old.length) {
2389
- return [].concat(old, [newFilterObj]);
2390
- }
2391
-
2392
- return [newFilterObj];
2393
- });
2394
- },
2395
- resetColumnFilters: function resetColumnFilters() {
2396
- var _instance$initialStat, _instance$initialStat2;
2397
-
2398
- instance.setColumnFilters((_instance$initialStat = (_instance$initialStat2 = instance.initialState) == null ? void 0 : _instance$initialStat2.columnFilters) != null ? _instance$initialStat : []);
2399
- },
2400
- getColumnFilteredRowModel: memo(function () {
2401
- return [instance.getState().columnFilters, instance.getCoreRowModel(), instance.options.columnFilterRowsFn];
2402
- }, function (columnFilters, rowModel, columnFiltersFn) {
2403
- var columnFilteredRowModel = function () {
2404
- if (!(columnFilters != null && columnFilters.length) || !columnFiltersFn) {
2405
- return rowModel;
2406
- }
2407
-
2408
- if (instance.options.debug) console.info('Column Filtering...');
2409
- return columnFiltersFn(instance, rowModel);
2410
- }(); // Now that each filtered column has it's partially filtered rows,
2411
- // lets assign the final filtered rows to all of the other columns
2412
-
2413
-
2414
- var nonFilteredColumns = instance.getAllLeafColumns().filter(function (column) {
2415
- var _instance$getState$co5;
2416
-
2417
- return !((_instance$getState$co5 = instance.getState().columnFilters) != null && _instance$getState$co5.find(function (d) {
2418
- return d.id === column.id;
2419
- }));
2420
- }); // This essentially enables faceted filter options to be built easily
2421
- // using every column's preFilteredRows value
2422
-
2423
- nonFilteredColumns.forEach(function (column) {
2424
- column.getPreFilteredRows = function () {
2425
- return columnFilteredRowModel.rows;
2426
- };
2427
- });
2428
- return columnFilteredRowModel;
2429
- }, {
2430
- key: 'getColumnFilteredRowModel',
2431
- debug: instance.options.debug
2432
- }),
2433
- // These might be easier to remember than "column" filtered rows
2434
- getPreFilteredRowModel: function getPreFilteredRowModel() {
2435
- return instance.getCoreRowModel();
2436
- },
2437
- getPreFilteredRows: function getPreFilteredRows() {
2438
- return instance.getCoreRowModel().rows;
2439
- },
2440
- getPreFilteredFlatRows: function getPreFilteredFlatRows() {
2441
- return instance.getCoreRowModel().flatRows;
2442
- },
2443
- getPreFilteredRowsById: function getPreFilteredRowsById() {
2444
- return instance.getCoreRowModel().rowsById;
2445
- },
2446
- // Pre Column Filter
2447
- getPreColumnFilteredRows: function getPreColumnFilteredRows() {
2448
- return instance.getCoreRowModel().rows;
2449
- },
2450
- getPreColumnFilteredFlatRows: function getPreColumnFilteredFlatRows() {
2451
- return instance.getCoreRowModel().flatRows;
2452
- },
2453
- getPreColumnFilteredRowsById: function getPreColumnFilteredRowsById() {
2454
- return instance.getCoreRowModel().rowsById;
2455
- },
2456
- getColumnFilteredRows: function getColumnFilteredRows() {
2457
- return instance.getColumnFilteredRowModel().rows;
2458
- },
2459
- getColumnFilteredFlatRows: function getColumnFilteredFlatRows() {
2460
- return instance.getColumnFilteredRowModel().flatRows;
2461
- },
2462
- getColumnFilteredRowsById: function getColumnFilteredRowsById() {
2463
- return instance.getColumnFilteredRowModel().rowsById;
2464
- },
2465
- getGlobalFilteredRowModel: memo(function () {
2466
- return [instance.getState().globalFilter, instance.getColumnFilteredRowModel(), instance.options.globalFilterRowsFn];
2467
- }, function (globalFilterValue, columnFilteredRowModel, globalFiltersFn) {
2468
- var globalFilteredRowModel = function () {
2469
- if (!globalFiltersFn || !globalFilterValue) {
2470
- return columnFilteredRowModel;
2471
- }
2472
-
2473
- if (instance.options.debug) console.info('Global Filtering...');
2474
- return globalFiltersFn(instance, columnFilteredRowModel);
2475
- }(); // Now that each filtered column has it's partially filtered rows,
2476
- // lets assign the final filtered rows to all of the other columns
2477
-
2478
-
2479
- var nonFilteredColumns = instance.getAllLeafColumns().filter(function (column) {
2480
- var _instance$getState$co6;
2481
-
2482
- return !((_instance$getState$co6 = instance.getState().columnFilters) != null && _instance$getState$co6.find(function (d) {
2483
- return d.id === column.id;
2484
- }));
2485
- }); // This essentially enables faceted filter options to be built easily
2486
- // using every column's preFilteredRows value
2487
-
2488
- nonFilteredColumns.forEach(function (column) {
2489
- column.getPreFilteredRows = function () {
2490
- return globalFilteredRowModel.rows;
2491
- };
2492
- });
2493
- return globalFilteredRowModel;
2494
- }, {
2495
- key: 'getGlobalFilteredRowModel',
2496
- debug: instance.options.debug,
2497
- onChange: function onChange() {
2498
- instance._notifySortingReset();
2499
- }
2500
- }),
2501
- getPreGlobalFilteredRows: function getPreGlobalFilteredRows() {
2502
- return instance.getColumnFilteredRowModel().rows;
2503
- },
2504
- getPreGlobalFilteredFlatRows: function getPreGlobalFilteredFlatRows() {
2505
- return instance.getColumnFilteredRowModel().flatRows;
2506
- },
2507
- getPreGlobalFilteredRowsById: function getPreGlobalFilteredRowsById() {
2508
- return instance.getColumnFilteredRowModel().rowsById;
2509
- },
2510
- getGlobalFilteredRows: function getGlobalFilteredRows() {
2511
- return instance.getGlobalFilteredRowModel().rows;
2512
- },
2513
- getGlobalFilteredFlatRows: function getGlobalFilteredFlatRows() {
2514
- return instance.getGlobalFilteredRowModel().flatRows;
2515
- },
2516
- getGlobalFilteredRowsById: function getGlobalFilteredRowsById() {
2517
- return instance.getGlobalFilteredRowModel().rowsById;
2518
- }
2519
- };
2520
- }
2521
- function shouldAutoRemoveFilter(filterFn, value, column) {
2522
- return (filterFn && filterFn.autoRemove ? filterFn.autoRemove(value, column) : false) || typeof value === 'undefined' || typeof value === 'string' && !value;
2523
- }
2524
-
2525
- var Filters = /*#__PURE__*/Object.freeze({
2526
- __proto__: null,
2527
- getDefaultColumn: getDefaultColumn$1,
2528
- getInitialState: getInitialState$5,
2529
- getDefaultOptions: getDefaultOptions$5,
2530
- createColumn: createColumn$2,
2531
- getInstance: getInstance$5,
2532
- shouldAutoRemoveFilter: shouldAutoRemoveFilter
2533
- });
2534
-
2535
- var reSplitAlphaNumeric = /([0-9]+)/gm;
2536
- var sortTypes = {
2537
- alphanumeric: alphanumeric,
2538
- alphanumericCaseSensitive: alphanumericCaseSensitive,
2539
- text: text,
2540
- textCaseSensitive: textCaseSensitive,
2541
- datetime: datetime,
2542
- basic: basic
2543
- };
2544
-
2545
- function alphanumeric(rowA, rowB, columnId) {
2546
- return compareAlphanumeric(toString(rowA.values[columnId]).toLowerCase(), toString(rowB.values[columnId]).toLowerCase());
2547
- }
2548
-
2549
- function alphanumericCaseSensitive(rowA, rowB, columnId) {
2550
- return compareAlphanumeric(toString(rowA.values[columnId]), toString(rowB.values[columnId]));
2551
- } // Mixed sorting is slow, but very inclusive of many edge cases.
2552
- // It handles numbers, mixed alphanumeric combinations, and even
2553
- // null, undefined, and Infinity
2554
-
2555
-
2556
- function compareAlphanumeric(aStr, bStr) {
2557
- // Split on number groups, but keep the delimiter
2558
- // Then remove falsey split values
2559
- var a = aStr.split(reSplitAlphaNumeric).filter(Boolean);
2560
- var b = bStr.split(reSplitAlphaNumeric).filter(Boolean); // While
2561
-
2562
- while (a.length && b.length) {
2563
- var aa = a.shift();
2564
- var bb = b.shift();
2565
- var an = parseInt(aa, 10);
2566
- var bn = parseInt(bb, 10);
2567
- var combo = [an, bn].sort(); // Both are string
2568
-
2569
- if (isNaN(combo[0])) {
2570
- if (aa > bb) {
2571
- return 1;
2572
- }
2573
-
2574
- if (bb > aa) {
2575
- return -1;
2576
- }
2577
-
2578
- continue;
2579
- } // One is a string, one is a number
2580
-
2581
-
2582
- if (isNaN(combo[1])) {
2583
- return isNaN(an) ? -1 : 1;
2584
- } // Both are numbers
2585
-
2586
-
2587
- if (an > bn) {
2588
- return 1;
2589
- }
2590
-
2591
- if (bn > an) {
2592
- return -1;
2593
- }
2594
- }
2595
-
2596
- return a.length - b.length;
2597
- } // The text filter is more basic (less numeric support)
2598
- // but is much faster
2599
-
2600
-
2601
- function text(rowA, rowB, columnId) {
2602
- return compareBasic(toString(rowA.values[columnId]).toLowerCase(), toString(rowB.values[columnId]).toLowerCase());
2603
- } // The text filter is more basic (less numeric support)
2604
- // but is much faster
2605
-
2606
-
2607
- function textCaseSensitive(rowA, rowB, columnId) {
2608
- return compareBasic(toString(rowA.values[columnId]), toString(rowB.values[columnId]));
2609
- }
2610
-
2611
- function datetime(rowA, rowB, columnId) {
2612
- return compareBasic(rowA.values[columnId].getTime(), rowB.values[columnId].getTime());
2613
- }
2614
-
2615
- function basic(rowA, rowB, columnId) {
2616
- return compareBasic(rowA.values[columnId], rowB.values[columnId]);
2617
- } // Utils
2618
-
2619
-
2620
- function compareBasic(a, b) {
2621
- return a === b ? 0 : a > b ? 1 : -1;
2622
- }
2623
-
2624
- function toString(a) {
2625
- if (typeof a === 'number') {
2626
- if (isNaN(a) || a === Infinity || a === -Infinity) {
2627
- return '';
2628
- }
2629
-
2630
- return String(a);
2631
- }
2632
-
2633
- if (typeof a === 'string') {
2634
- return a;
2635
- }
2636
-
2637
- return '';
2638
- }
2639
-
2640
- //
2641
- function getDefaultColumn() {
2642
- return {
2643
- sortType: 'auto'
2644
- };
2645
- }
2646
- function getInitialState$4() {
2647
- return {
2648
- sorting: []
2649
- };
2650
- }
2651
- function getDefaultOptions$4(instance) {
2652
- return {
2653
- onSortingChange: makeStateUpdater('sorting', instance),
2654
- autoResetSorting: true,
2655
- isMultiSortEvent: function isMultiSortEvent(e) {
2656
- return e.shiftKey;
2657
- }
2658
- };
2659
- }
2660
- function createColumn$1(column, instance) {
2661
- return {
2662
- sortType: column.sortType,
2663
- getCanSort: function getCanSort() {
2664
- return instance.getColumnCanSort(column.id);
2665
- },
2666
- getCanMultiSort: function getCanMultiSort() {
2667
- return instance.getColumnCanMultiSort(column.id);
2668
- },
2669
- getSortIndex: function getSortIndex() {
2670
- return instance.getColumnSortIndex(column.id);
2671
- },
2672
- getIsSorted: function getIsSorted() {
2673
- return instance.getColumnIsSorted(column.id);
2674
- },
2675
- toggleSorting: function toggleSorting(desc, isMulti) {
2676
- return instance.toggleColumnSorting(column.id, desc, isMulti);
2677
- },
2678
- getToggleSortingProps: function getToggleSortingProps(userProps) {
2679
- return instance.getToggleSortingProps(column.id, userProps);
2680
- }
2681
- };
2682
- }
2683
- function getInstance$4(instance) {
2684
- var registered = false;
2685
- return {
2686
- _notifySortingReset: function _notifySortingReset() {
2687
- if (!registered) {
2688
- registered = true;
2689
- return;
2690
- }
2691
-
2692
- if (instance.options.autoResetAll === false) {
2693
- return;
2694
- }
2695
-
2696
- if (instance.options.autoResetAll === true || instance.options.autoResetSorting) {
2697
- instance.resetSorting();
2698
- }
2699
- },
2700
- getColumnAutoSortingFn: function getColumnAutoSortingFn(columnId) {
2701
- var firstRows = instance.getGlobalFilteredRowModel().flatRows.slice(100);
2702
- var isString = false;
2703
-
2704
- for (var _iterator = _createForOfIteratorHelperLoose(firstRows), _step; !(_step = _iterator()).done;) {
2705
- var row = _step.value;
2706
- var value = row == null ? void 0 : row.values[columnId];
2707
-
2708
- if (Object.prototype.toString.call(value) === '[object Date]') {
2709
- return sortTypes.datetime;
2710
- }
2711
-
2712
- if (typeof value === 'string') {
2713
- isString = true;
2714
-
2715
- if (value.split(reSplitAlphaNumeric).length > 1) {
2716
- return sortTypes.alphanumeric;
2717
- }
2718
- }
2719
- }
2720
-
2721
- if (isString) {
2722
- return sortTypes.text;
2723
- }
2724
-
2725
- return sortTypes.basic;
2726
- },
2727
- getColumnAutoSortDir: function getColumnAutoSortDir(columnId) {
2728
- var firstRow = instance.getGlobalFilteredRowModel().flatRows[0];
2729
- var value = firstRow == null ? void 0 : firstRow.values[columnId];
2730
-
2731
- if (typeof value === 'string') {
2732
- return 'asc';
2733
- }
2734
-
2735
- return 'desc';
2736
- },
2737
- getColumnSortingFn: function getColumnSortingFn(columnId) {
2738
- var _ref;
2739
-
2740
- var column = instance.getColumn(columnId);
2741
- var userSortTypes = instance.options.sortTypes;
2742
-
2743
- if (!column) {
2744
- throw new Error();
2745
- }
2746
-
2747
- return isFunction(column.sortType) ? column.sortType : column.sortType === 'auto' ? instance.getColumnAutoSortingFn(columnId) : (_ref = userSortTypes == null ? void 0 : userSortTypes[column.sortType]) != null ? _ref : sortTypes[column.sortType];
2748
- },
2749
- setSorting: function setSorting(updater) {
2750
- return instance.options.onSortingChange == null ? void 0 : instance.options.onSortingChange(updater, functionalUpdate(updater, instance.getState().sorting));
2751
- },
2752
- toggleColumnSorting: function toggleColumnSorting(columnId, desc, multi) {
2753
- var column = instance.getColumn(columnId);
2754
-
2755
- if (!column) {
2756
- throw new Error();
2757
- } // if (column.columns.length) {
2758
- // column.columns.forEach((c, i) => {
2759
- // if (c.id) {
2760
- // instance.toggleColumnSorting(c.id, undefined, multi || !!i)
2761
- // }
2762
- // })
2763
- // return
2764
- // }
2765
-
2766
-
2767
- instance.setSorting(function (old) {
2768
- var _ref2, _column$sortDescFirst, _instance$options$ena, _instance$options$ena2;
2769
-
2770
- // Find any existing sorting for this column
2771
- var existingSorting = old == null ? void 0 : old.find(function (d) {
2772
- return d.id === columnId;
2773
- });
2774
- var existingIndex = old == null ? void 0 : old.findIndex(function (d) {
2775
- return d.id === columnId;
2776
- });
2777
- var hasDescDefined = typeof desc !== 'undefined' && desc !== null;
2778
- var newSorting = []; // What should we do with this sort action?
2779
-
2780
- var sortAction;
2781
-
2782
- if (column.getCanMultiSort() && multi) {
2783
- if (existingSorting) {
2784
- sortAction = 'toggle';
2785
- } else {
2786
- sortAction = 'add';
2787
- }
2788
- } else {
2789
- // Normal mode
2790
- if (old != null && old.length && existingIndex !== old.length - 1) {
2791
- sortAction = 'replace';
2792
- } else if (existingSorting) {
2793
- sortAction = 'toggle';
2794
- } else {
2795
- sortAction = 'replace';
2796
- }
2797
- }
2798
-
2799
- var sortDescFirst = (_ref2 = (_column$sortDescFirst = column.sortDescFirst) != null ? _column$sortDescFirst : instance.options.sortDescFirst) != null ? _ref2 : instance.getColumnAutoSortDir(columnId) === 'desc'; // Handle toggle states that will remove the sorting
2800
-
2801
- if (sortAction === 'toggle' && ( // Must be toggling
2802
- (_instance$options$ena = instance.options.enableSortingRemoval) != null ? _instance$options$ena : true) && // If enableSortRemove, enable in general
2803
- !hasDescDefined && ( // Must not be setting desc
2804
- multi ? (_instance$options$ena2 = instance.options.enableMultiRemove) != null ? _instance$options$ena2 : true : true) && ( // If multi, don't allow if enableMultiRemove
2805
- existingSorting != null && existingSorting.desc // Finally, detect if it should indeed be removed
2806
- ? !sortDescFirst : sortDescFirst)) {
2807
- sortAction = 'remove';
2808
- }
2809
-
2810
- if (sortAction === 'replace') {
2811
- newSorting = [{
2812
- id: columnId,
2813
- desc: hasDescDefined ? desc : !!sortDescFirst
2814
- }];
2815
- } else if (sortAction === 'add' && old != null && old.length) {
2816
- var _instance$options$max;
2817
-
2818
- newSorting = [].concat(old, [{
2819
- id: columnId,
2820
- desc: hasDescDefined ? desc : !!sortDescFirst
2821
- }]); // Take latest n columns
2822
-
2823
- newSorting.splice(0, newSorting.length - ((_instance$options$max = instance.options.maxMultiSortColCount) != null ? _instance$options$max : Number.MAX_SAFE_INTEGER));
2824
- } else if (sortAction === 'toggle' && old != null && old.length) {
2825
- // This flips (or sets) the
2826
- newSorting = old.map(function (d) {
2827
- if (d.id === columnId) {
2828
- return _extends({}, d, {
2829
- desc: hasDescDefined ? desc : !(existingSorting != null && existingSorting.desc)
2830
- });
2831
- }
2832
-
2833
- return d;
2834
- });
2835
- } else if (sortAction === 'remove' && old != null && old.length) {
2836
- newSorting = old.filter(function (d) {
2837
- return d.id !== columnId;
2838
- });
2839
- }
2840
-
2841
- return newSorting;
2842
- });
2843
- },
2844
- getColumnCanSort: function getColumnCanSort(columnId) {
2845
- var _ref3, _ref4, _column$enableSorting;
2846
-
2847
- var column = instance.getColumn(columnId);
2848
-
2849
- if (!column) {
2850
- throw new Error();
2851
- }
2852
-
2853
- return (_ref3 = (_ref4 = (_column$enableSorting = column.enableSorting) != null ? _column$enableSorting : instance.options.enableSorting) != null ? _ref4 : column.defaultCanSort) != null ? _ref3 : !!column.accessorFn // (!!column.accessorFn ||
2854
- // column.columns?.some(c => c.id && instance.getColumnCanSort(c.id))) ??
2855
- // false
2856
- ;
2857
- },
2858
- getColumnCanMultiSort: function getColumnCanMultiSort(columnId) {
2859
- var _ref5, _column$enableMultiSo;
2860
-
2861
- var column = instance.getColumn(columnId);
2862
-
2863
- if (!column) {
2864
- throw new Error();
2865
- }
2866
-
2867
- return (_ref5 = (_column$enableMultiSo = column.enableMultiSort) != null ? _column$enableMultiSo : instance.options.enableMultiSort) != null ? _ref5 : !!column.accessorFn;
2868
- },
2869
- getColumnIsSorted: function getColumnIsSorted(columnId) {
2870
- var _instance$getState$so;
2871
-
2872
- var columnSort = (_instance$getState$so = instance.getState().sorting) == null ? void 0 : _instance$getState$so.find(function (d) {
2873
- return d.id === columnId;
2874
- });
2875
- return !columnSort ? false : columnSort.desc ? 'desc' : 'asc';
2876
- },
2877
- getColumnSortIndex: function getColumnSortIndex(columnId) {
2878
- var _instance$getState$so2, _instance$getState$so3;
2879
-
2880
- return (_instance$getState$so2 = (_instance$getState$so3 = instance.getState().sorting) == null ? void 0 : _instance$getState$so3.findIndex(function (d) {
2881
- return d.id === columnId;
2882
- })) != null ? _instance$getState$so2 : -1;
2883
- },
2884
- resetSorting: function resetSorting() {
2885
- var _instance$initialStat, _instance$initialStat2;
2886
-
2887
- instance.setSorting((_instance$initialStat = (_instance$initialStat2 = instance.initialState) == null ? void 0 : _instance$initialStat2.sorting) != null ? _instance$initialStat : []);
2888
- },
2889
- getToggleSortingProps: function getToggleSortingProps(columnId, userProps) {
2890
- var column = instance.getColumn(columnId);
2891
-
2892
- if (!column) {
2893
- throw new Error();
2894
- }
2895
-
2896
- var canSort = column.getCanSort();
2897
- var initialProps = {
2898
- title: canSort ? 'Toggle Sorting' : undefined,
2899
- onClick: canSort ? function (e) {
2900
- e.persist();
2901
- column.toggleSorting == null ? void 0 : column.toggleSorting(undefined, column.getCanMultiSort() ? instance.options.isMultiSortEvent == null ? void 0 : instance.options.isMultiSortEvent(e) : false);
2902
- } : undefined
2903
- };
2904
- return propGetter(initialProps, userProps);
2905
- },
2906
- getSortedRowModel: memo(function () {
2907
- return [instance.getState().sorting, instance.getGlobalFilteredRowModel(), instance.options.sortRowsFn];
2908
- }, function (sorting, rowModel, sortingFn) {
2909
- if (!sortingFn || !(sorting != null && sorting.length)) {
2910
- return rowModel;
2911
- }
2912
-
2913
- if (instance.options.debug) console.info('Sorting...');
2914
- return sortingFn(instance, rowModel);
2915
- }, {
2916
- key: 'getSortedRowModel',
2917
- debug: instance.options.debug,
2918
- onChange: function onChange() {
2919
- return instance._notifyGroupingReset();
2920
- }
2921
- }),
2922
- getPreSortedRows: function getPreSortedRows() {
2923
- return instance.getGlobalFilteredRowModel().rows;
2924
- },
2925
- getPreSortedFlatRows: function getPreSortedFlatRows() {
2926
- return instance.getGlobalFilteredRowModel().flatRows;
2927
- },
2928
- getPreSortedRowsById: function getPreSortedRowsById() {
2929
- return instance.getGlobalFilteredRowModel().rowsById;
2930
- },
2931
- getSortedRows: function getSortedRows() {
2932
- return instance.getSortedRowModel().rows;
2933
- },
2934
- getSortedFlatRows: function getSortedFlatRows() {
2935
- return instance.getSortedRowModel().flatRows;
2936
- },
2937
- getSortedRowsById: function getSortedRowsById() {
2938
- return instance.getSortedRowModel().rowsById;
2939
- }
2940
- };
2941
- }
2942
-
2943
- var Sorting = /*#__PURE__*/Object.freeze({
2944
- __proto__: null,
2945
- getDefaultColumn: getDefaultColumn,
2946
- getInitialState: getInitialState$4,
2947
- getDefaultOptions: getDefaultOptions$4,
2948
- createColumn: createColumn$1,
2949
- getInstance: getInstance$4
2950
- });
2951
-
2952
- //
2953
- function getInitialState$3() {
2954
- return {
2955
- expanded: {}
2956
- };
2957
- }
2958
- function getDefaultOptions$3(instance) {
2959
- return {
2960
- onExpandedChange: makeStateUpdater('expanded', instance),
2961
- autoResetExpanded: true,
2962
- getIsRowExpanded: function getIsRowExpanded(row) {
2963
- return !!(row == null ? void 0 : row.original).expanded;
2964
- },
2965
- expandSubRows: true,
2966
- paginateExpandedRows: true
2967
- };
2968
- }
2969
- function getInstance$3(instance) {
2970
- var registered = false;
2971
- return {
2972
- _notifyExpandedReset: function _notifyExpandedReset() {
2973
- if (!registered) {
2974
- registered = true;
2975
- return;
2976
- }
2977
-
2978
- if (instance.options.autoResetAll === false) {
2979
- return;
2980
- }
2981
-
2982
- if (instance.options.autoResetAll === true || instance.options.autoResetExpanded) {
2983
- instance.resetExpanded();
2984
- }
2985
- },
2986
- setExpanded: function setExpanded(updater) {
2987
- return instance.options.onExpandedChange == null ? void 0 : instance.options.onExpandedChange(updater, functionalUpdate(updater, instance.getState().expanded));
2988
- },
2989
- toggleRowExpanded: function toggleRowExpanded(rowId, expanded) {
2990
- if (!rowId) return;
2991
- instance.setExpanded(function (old) {
2992
- var _expanded;
2993
-
2994
- var exists = old === true ? true : !!(old != null && old[rowId]);
2995
- var oldExpanded = {};
2996
-
2997
- if (old === true) {
2998
- Object.keys(instance.getRowsById()).forEach(function (rowId) {
2999
- oldExpanded[rowId] = true;
3000
- });
3001
- } else {
3002
- oldExpanded = old;
3003
- }
3004
-
3005
- expanded = (_expanded = expanded) != null ? _expanded : !exists;
3006
-
3007
- if (!exists && expanded) {
3008
- var _extends2;
3009
-
3010
- return _extends({}, oldExpanded, (_extends2 = {}, _extends2[rowId] = true, _extends2));
3011
- }
3012
-
3013
- if (exists && !expanded) {
3014
- var _oldExpanded = oldExpanded;
3015
- _oldExpanded[rowId];
3016
- var rest = _objectWithoutPropertiesLoose(_oldExpanded, [rowId].map(_toPropertyKey));
3017
-
3018
- return rest;
3019
- }
3020
-
3021
- return old;
3022
- });
3023
- },
3024
- toggleAllRowsExpanded: function toggleAllRowsExpanded(expanded) {
3025
- if (expanded != null ? expanded : !instance.getIsAllRowsExpanded()) {
3026
- instance.setExpanded(true);
3027
- } else {
3028
- instance.setExpanded({});
3029
- }
3030
- },
3031
- resetExpanded: function resetExpanded() {
3032
- var _instance$initialStat, _instance$initialStat2;
3033
-
3034
- instance.setExpanded((_instance$initialStat = (_instance$initialStat2 = instance.initialState) == null ? void 0 : _instance$initialStat2.expanded) != null ? _instance$initialStat : {});
3035
- },
3036
- getIsRowExpanded: function getIsRowExpanded(rowId) {
3037
- var _instance$options$get;
3038
-
3039
- var row = instance.getRow(rowId);
3040
-
3041
- if (!row) {
3042
- {
3043
- console.warn("[ReactTable] getIsRowExpanded: no row found with id " + rowId);
3044
- }
3045
-
3046
- throw new Error();
3047
- }
3048
-
3049
- var expanded = instance.getState().expanded;
3050
- return !!((_instance$options$get = instance.options.getIsRowExpanded == null ? void 0 : instance.options.getIsRowExpanded(row)) != null ? _instance$options$get : expanded || (expanded == null ? void 0 : expanded[rowId]));
3051
- },
3052
- getRowCanExpand: function getRowCanExpand(rowId) {
3053
- var _ref, _ref2, _instance$options$get2, _row$subRows;
3054
-
3055
- var row = instance.getRow(rowId);
3056
-
3057
- if (!row) {
3058
- {
3059
- console.warn("[ReactTable] getRowCanExpand: no row found with id " + rowId);
3060
- }
3061
-
3062
- throw new Error();
3063
- }
3064
-
3065
- return (_ref = (_ref2 = (_instance$options$get2 = instance.options.getRowCanExpand == null ? void 0 : instance.options.getRowCanExpand(row)) != null ? _instance$options$get2 : instance.options.enableExpanded) != null ? _ref2 : instance.options.defaultCanExpand) != null ? _ref : !!((_row$subRows = row.subRows) != null && _row$subRows.length);
3066
- },
3067
- getToggleExpandedProps: function getToggleExpandedProps(rowId, userProps) {
3068
- var row = instance.getRow(rowId);
3069
-
3070
- if (!row) {
3071
- return;
3072
- }
3073
-
3074
- var canExpand = instance.getRowCanExpand(rowId);
3075
- var initialProps = {
3076
- title: canExpand ? 'Toggle Expanded' : undefined,
3077
- onClick: canExpand ? function (e) {
3078
- e.persist();
3079
- instance.toggleRowExpanded(rowId);
3080
- } : undefined
3081
- };
3082
- return propGetter(initialProps, userProps);
3083
- },
3084
- getToggleAllRowsExpandedProps: function getToggleAllRowsExpandedProps(userProps) {
3085
- var initialProps = {
3086
- title: 'Toggle All Expanded',
3087
- onClick: function onClick(e) {
3088
- e.persist();
3089
- instance.toggleAllRowsExpanded();
3090
- }
3091
- };
3092
- return propGetter(initialProps, userProps);
3093
- },
3094
- getIsAllRowsExpanded: function getIsAllRowsExpanded() {
3095
- var expanded = instance.getState().expanded; // If expanded is true, save some cycles and return true
3096
-
3097
- if (expanded === true) {
3098
- return true;
3099
- } // If any row is not expanded, return false
3100
-
3101
-
3102
- if (Object.keys(instance.getRowsById()).some(function (id) {
3103
- return !instance.getIsRowExpanded(id);
3104
- })) {
3105
- return false;
3106
- } // They must all be expanded :shrug:
3107
-
3108
-
3109
- return true;
3110
- },
3111
- getExpandedDepth: function getExpandedDepth() {
3112
- var maxDepth = 0;
3113
- var rowIds = instance.getState().expanded === true ? Object.keys(instance.getRowsById()) : Object.keys(instance.getState().expanded);
3114
- rowIds.forEach(function (id) {
3115
- var splitId = id.split('.');
3116
- maxDepth = Math.max(maxDepth, splitId.length);
3117
- });
3118
- return maxDepth;
3119
- },
3120
- getExpandedRowModel: memo(function () {
3121
- return [instance.getState().expanded, instance.getGroupedRowModel(), instance.options.expandRowsFn, instance.options.paginateExpandedRows];
3122
- }, function (expanded, rowModel, expandRowsFn, paginateExpandedRows) {
3123
- if (!expandRowsFn || // Do not expand if rows are not included in pagination
3124
- !paginateExpandedRows || !Object.keys(expanded != null ? expanded : {}).length) {
3125
- return rowModel;
3126
- }
3127
-
3128
- if (instance.options.debug) console.info('Expanding...');
3129
- return expandRowsFn(instance, rowModel);
3130
- }, {
3131
- key: 'getExpandedRowModel',
3132
- debug: instance.options.debug,
3133
- onChange: function onChange() {
3134
- instance._notifyPageIndexReset();
3135
- }
3136
- }),
3137
- getPreExpandedRows: function getPreExpandedRows() {
3138
- return instance.getGroupedRowModel().rows;
3139
- },
3140
- getPreExpandedFlatRows: function getPreExpandedFlatRows() {
3141
- return instance.getGroupedRowModel().flatRows;
3142
- },
3143
- getPreExpandedRowsById: function getPreExpandedRowsById() {
3144
- return instance.getGroupedRowModel().rowsById;
3145
- },
3146
- getExpandedRows: function getExpandedRows() {
3147
- return instance.getExpandedRowModel().rows;
3148
- },
3149
- getExpandedFlatRows: function getExpandedFlatRows() {
3150
- return instance.getExpandedRowModel().flatRows;
3151
- },
3152
- getExpandedRowsById: function getExpandedRowsById() {
3153
- return instance.getExpandedRowModel().rowsById;
3154
- }
3155
- };
3156
- }
3157
- function createRow$1(row, instance) {
3158
- return {
3159
- toggleExpanded: function toggleExpanded(expanded) {
3160
- return void instance.toggleRowExpanded(row.id, expanded);
3161
- },
3162
- getIsExpanded: function getIsExpanded() {
3163
- return instance.getIsRowExpanded(row.id);
3164
- },
3165
- getCanExpand: function getCanExpand() {
3166
- return row.subRows && !!row.subRows.length;
3167
- },
3168
- getToggleExpandedProps: function getToggleExpandedProps(userProps) {
3169
- var initialProps = {
3170
- title: 'Toggle Row Expanded',
3171
- onClick: function onClick(e) {
3172
- e.stopPropagation();
3173
- instance.toggleRowExpanded(row.id);
3174
- }
3175
- };
3176
- return propGetter(initialProps, userProps);
3177
- }
3178
- };
3179
- }
3180
-
3181
- var Expanding = /*#__PURE__*/Object.freeze({
3182
- __proto__: null,
3183
- getInitialState: getInitialState$3,
3184
- getDefaultOptions: getDefaultOptions$3,
3185
- getInstance: getInstance$3,
3186
- createRow: createRow$1
3187
- });
3188
-
3189
- //
3190
- var defaultColumnSizing = {
3191
- width: 150,
3192
- minWidth: 20,
3193
- maxWidth: Number.MAX_SAFE_INTEGER
3194
- };
3195
- function getInitialState$2() {
3196
- return {
3197
- columnSizing: {},
3198
- columnSizingInfo: {
3199
- startOffset: null,
3200
- startSize: null,
3201
- deltaOffset: null,
3202
- deltaPercentage: null,
3203
- isResizingColumn: false,
3204
- columnSizingStart: []
3205
- }
3206
- };
3207
- }
3208
- function getDefaultOptions$2(instance) {
3209
- return {
3210
- columnResizeMode: 'onEnd',
3211
- onColumnSizingChange: makeStateUpdater('columnSizing', instance),
3212
- onColumnSizingInfoChange: makeStateUpdater('columnSizingInfo', instance)
3213
- };
3214
- }
3215
- function getInstance$2(instance) {
3216
- return {
3217
- setColumnSizing: function setColumnSizing(updater) {
3218
- return instance.options.onColumnSizingChange == null ? void 0 : instance.options.onColumnSizingChange(updater, functionalUpdate(updater, instance.getState().columnSizing));
3219
- },
3220
- setColumnSizingInfo: function setColumnSizingInfo(updater) {
3221
- return instance.options.onColumnSizingInfoChange == null ? void 0 : instance.options.onColumnSizingInfoChange(updater, functionalUpdate(updater, instance.getState().columnSizingInfo));
3222
- },
3223
- resetColumnSizing: function resetColumnSizing() {
3224
- var _instance$initialStat;
3225
-
3226
- instance.setColumnSizing((_instance$initialStat = instance.initialState.columnSizing) != null ? _instance$initialStat : {});
3227
- },
3228
- resetHeaderSizeInfo: function resetHeaderSizeInfo() {
3229
- var _instance$initialStat2;
3230
-
3231
- instance.setColumnSizingInfo((_instance$initialStat2 = instance.initialState.columnSizingInfo) != null ? _instance$initialStat2 : {});
3232
- },
3233
- resetColumnSize: function resetColumnSize(columnId) {
3234
- instance.setColumnSizing(function (_ref) {
3235
- _ref[columnId];
3236
- var rest = _objectWithoutPropertiesLoose(_ref, [columnId].map(_toPropertyKey));
3237
-
3238
- return rest;
3239
- });
3240
- },
3241
- resetHeaderSize: function resetHeaderSize(headerId) {
3242
- var header = instance.getHeader(headerId);
3243
-
3244
- if (!header) {
3245
- return;
3246
- }
3247
-
3248
- return instance.resetColumnSize(header.column.id);
3249
- },
3250
- getHeaderCanResize: function getHeaderCanResize(headerId) {
3251
- var header = instance.getHeader(headerId);
3252
-
3253
- if (!header) {
3254
- throw new Error();
3255
- }
3256
-
3257
- return instance.getColumnCanResize(header.column.id);
3258
- },
3259
- getColumnCanResize: function getColumnCanResize(columnId) {
3260
- var _ref2, _ref3, _column$enableResizin;
3261
-
3262
- var column = instance.getColumn(columnId);
3263
-
3264
- if (!column) {
3265
- throw new Error();
3266
- }
3267
-
3268
- return (_ref2 = (_ref3 = (_column$enableResizin = column.enableResizing) != null ? _column$enableResizin : instance.options.enableColumnResizing) != null ? _ref3 : column.defaultCanResize) != null ? _ref2 : true;
3269
- },
3270
- getColumnIsResizing: function getColumnIsResizing(columnId) {
3271
- var column = instance.getColumn(columnId);
3272
-
3273
- if (!column) {
3274
- throw new Error();
3275
- }
3276
-
3277
- return instance.getState().columnSizingInfo.isResizingColumn === columnId;
3278
- },
3279
- getHeaderIsResizing: function getHeaderIsResizing(headerId) {
3280
- var header = instance.getHeader(headerId);
3281
-
3282
- if (!header) {
3283
- throw new Error();
3284
- }
3285
-
3286
- return instance.getColumnIsResizing(header.column.id);
3287
- },
3288
- getColumnResizerProps: function getColumnResizerProps(headerId, userProps) {
3289
- var header = instance.getHeader(headerId);
3290
-
3291
- if (!header) {
3292
- return;
3293
- }
3294
-
3295
- var column = instance.getColumn(header.column.id);
3296
-
3297
- if (!column) {
3298
- return;
3299
- }
3300
-
3301
- var canResize = column.getCanResize();
3302
-
3303
- var onResizeStart = function onResizeStart(e) {
3304
- if (isTouchStartEvent(e)) {
3305
- // lets not respond to multiple touches (e.g. 2 or 3 fingers)
3306
- if (e.touches && e.touches.length > 1) {
3307
- return;
3308
- }
3309
- }
3310
-
3311
- var columnSizingStart = header.getLeafHeaders().map(function (d) {
3312
- return [d.column.id, d.getWidth()];
3313
- });
3314
- var clientX = isTouchStartEvent(e) ? Math.round(e.touches[0].clientX) : e.clientX;
3315
-
3316
- var updateOffset = function updateOffset(eventType, clientXPos) {
3317
- if (typeof clientXPos !== 'number') {
3318
- return;
3319
- }
3320
-
3321
- var newColumnSizing = {};
3322
- instance.setColumnSizingInfo(function (old) {
3323
- var _old$startOffset, _old$startSize;
3324
-
3325
- var deltaOffset = clientXPos - ((_old$startOffset = old == null ? void 0 : old.startOffset) != null ? _old$startOffset : 0);
3326
- var deltaPercentage = Math.max(deltaOffset / ((_old$startSize = old == null ? void 0 : old.startSize) != null ? _old$startSize : 0), -0.999999);
3327
- old.columnSizingStart.forEach(function (_ref4) {
3328
- var columnId = _ref4[0],
3329
- headerWidth = _ref4[1];
3330
- newColumnSizing[columnId] = Math.max(headerWidth + headerWidth * deltaPercentage, 0);
3331
- });
3332
- return _extends({}, old, {
3333
- deltaOffset: deltaOffset,
3334
- deltaPercentage: deltaPercentage
3335
- });
3336
- });
3337
-
3338
- if (instance.options.columnResizeMode === 'onChange' || eventType === 'end') {
3339
- instance.setColumnSizing(function (old) {
3340
- return _extends({}, old, newColumnSizing);
3341
- });
3342
- }
3343
- };
3344
-
3345
- var onMove = function onMove(clientXPos) {
3346
- return updateOffset('move', clientXPos);
3347
- };
3348
-
3349
- var onEnd = function onEnd(clientXPos) {
3350
- updateOffset('end', clientXPos);
3351
- instance.setColumnSizingInfo(function (old) {
3352
- return _extends({}, old, {
3353
- isResizingColumn: false,
3354
- startOffset: null,
3355
- startSize: null,
3356
- deltaOffset: null,
3357
- deltaPercentage: null,
3358
- columnSizingStart: []
3359
- });
3360
- });
3361
- };
3362
-
3363
- var mouseEvents = {
3364
- moveHandler: function moveHandler(e) {
3365
- return onMove(e.clientX);
3366
- },
3367
- upHandler: function upHandler(e) {
3368
- document.removeEventListener('mousemove', mouseEvents.moveHandler);
3369
- document.removeEventListener('mouseup', mouseEvents.upHandler);
3370
- onEnd(e.clientX);
3371
- }
3372
- };
3373
- var touchEvents = {
3374
- moveHandler: function moveHandler(e) {
3375
- if (e.cancelable) {
3376
- e.preventDefault();
3377
- e.stopPropagation();
3378
- }
3379
-
3380
- onMove(e.touches[0].clientX);
3381
- return false;
3382
- },
3383
- upHandler: function upHandler(e) {
3384
- document.removeEventListener('touchmove', touchEvents.moveHandler);
3385
- document.removeEventListener('touchend', touchEvents.upHandler);
3386
-
3387
- if (e.cancelable) {
3388
- e.preventDefault();
3389
- e.stopPropagation();
3390
- }
3391
-
3392
- onEnd(e.touches[0].clientX);
3393
- }
3394
- };
3395
- var passiveIfSupported = passiveEventSupported() ? {
3396
- passive: false
3397
- } : false;
3398
-
3399
- if (isTouchStartEvent(e)) {
3400
- document.addEventListener('touchmove', touchEvents.moveHandler, passiveIfSupported);
3401
- document.addEventListener('touchend', touchEvents.upHandler, passiveIfSupported);
3402
- } else {
3403
- document.addEventListener('mousemove', mouseEvents.moveHandler, passiveIfSupported);
3404
- document.addEventListener('mouseup', mouseEvents.upHandler, passiveIfSupported);
3405
- }
3406
-
3407
- instance.setColumnSizingInfo(function (old) {
3408
- return _extends({}, old, {
3409
- startOffset: clientX,
3410
- startSize: header.getWidth(),
3411
- deltaOffset: 0,
3412
- deltaPercentage: 0,
3413
- columnSizingStart: columnSizingStart,
3414
- isResizingColumn: header.column.id
3415
- });
3416
- });
3417
- };
3418
-
3419
- var initialProps = canResize ? {
3420
- title: 'Toggle Grouping',
3421
- draggable: false,
3422
- role: 'separator',
3423
- onMouseDown: function onMouseDown(e) {
3424
- e.persist();
3425
- onResizeStart(e);
3426
- },
3427
- onTouchStart: function onTouchStart(e) {
3428
- e.persist();
3429
- onResizeStart(e);
3430
- }
3431
- } : {};
3432
- return propGetter(initialProps, userProps);
3433
- }
3434
- };
3435
- }
3436
- function createColumn(column, instance) {
3437
- return {
3438
- getIsResizing: function getIsResizing() {
3439
- return instance.getColumnIsResizing(column.id);
3440
- },
3441
- getCanResize: function getCanResize() {
3442
- return instance.getColumnCanResize(column.id);
3443
- },
3444
- resetSize: function resetSize() {
3445
- return instance.resetColumnSize(column.id);
3446
- },
3447
- getResizerProps: function getResizerProps(userProps) {
3448
- return instance.getColumnResizerProps(column.id, userProps);
3449
- }
3450
- };
3451
- }
3452
- var passiveSupported = null;
3453
- function passiveEventSupported() {
3454
- if (typeof passiveSupported === 'boolean') return passiveSupported;
3455
- var supported = false;
3456
-
3457
- try {
3458
- var options = {
3459
- get passive() {
3460
- supported = true;
3461
- return false;
3462
- }
3463
-
3464
- };
3465
-
3466
- var noop = function noop() {};
3467
-
3468
- window.addEventListener('test', noop, options);
3469
- window.removeEventListener('test', noop);
3470
- } catch (err) {
3471
- supported = false;
3472
- }
3473
-
3474
- passiveSupported = supported;
3475
- return passiveSupported;
3476
- }
3477
-
3478
- function isTouchStartEvent(e) {
3479
- return e.type === 'touchstart';
3480
- }
3481
-
3482
- var ColumnSizing = /*#__PURE__*/Object.freeze({
3483
- __proto__: null,
3484
- defaultColumnSizing: defaultColumnSizing,
3485
- getInitialState: getInitialState$2,
3486
- getDefaultOptions: getDefaultOptions$2,
3487
- getInstance: getInstance$2,
3488
- createColumn: createColumn,
3489
- passiveEventSupported: passiveEventSupported
3490
- });
3491
-
3492
- //
3493
- function getInitialState$1() {
3494
- return {
3495
- pagination: {
3496
- pageIndex: 0,
3497
- pageSize: 10
3498
- }
3499
- };
3500
- }
3501
- function getDefaultOptions$1(instance) {
3502
- return {
3503
- onPaginationChange: makeStateUpdater('pagination', instance),
3504
- autoResetPageIndex: true
3505
- };
3506
- }
3507
- function getInstance$1(instance) {
3508
- var registered = false;
3509
- return {
3510
- _notifyPageIndexReset: function _notifyPageIndexReset() {
3511
- if (!registered) {
3512
- registered = true;
3513
- return;
3514
- }
3515
-
3516
- if (instance.options.autoResetAll === false) {
3517
- return;
3518
- }
3519
-
3520
- if (instance.options.autoResetAll === true || instance.options.autoResetPageIndex) {
3521
- instance.resetPageSize();
3522
- }
3523
- },
3524
- setPagination: function setPagination(updater) {
3525
- var safeUpdater = function safeUpdater(old) {
3526
- var newState = functionalUpdate(updater, old);
3527
-
3528
- if (instance.options.paginateRowsFn) {
3529
- var _instance$getPrePagin;
3530
-
3531
- newState.pageCount = (_instance$getPrePagin = instance.getPrePaginationRows()) != null && _instance$getPrePagin.length ? Math.ceil(instance.getPrePaginationRows().length / instance.getState().pagination.pageSize) : 0;
3532
- }
3533
-
3534
- return newState;
3535
- };
3536
-
3537
- return instance.options.onPaginationChange == null ? void 0 : instance.options.onPaginationChange(safeUpdater, functionalUpdate(safeUpdater, instance.getState().pagination));
3538
- },
3539
- resetPagination: function resetPagination() {
3540
- var _instance$initialStat;
3541
-
3542
- instance.setPagination((_instance$initialStat = instance.initialState.pagination) != null ? _instance$initialStat : {
3543
- pageIndex: 0,
3544
- pageSize: 10,
3545
- pageCount: -1
3546
- });
3547
- },
3548
- setPageIndex: function setPageIndex(updater) {
3549
- instance.setPagination(function (old) {
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);
3553
- return _extends({}, old, {
3554
- pageIndex: pageIndex
3555
- });
3556
- });
3557
- },
3558
- resetPageIndex: function resetPageIndex() {
3559
- instance.setPageIndex(0);
3560
- },
3561
- resetPageSize: function resetPageSize() {
3562
- var _instance$initialStat2, _instance$initialStat3, _instance$initialStat4;
3563
-
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);
3565
- },
3566
- setPageSize: function setPageSize(updater) {
3567
- instance.setPagination(function (old) {
3568
- var pageSize = Math.max(1, functionalUpdate(updater, old.pageSize));
3569
- var topRowIndex = old.pageSize * old.pageIndex;
3570
- var pageIndex = Math.floor(topRowIndex / pageSize);
3571
- return _extends({}, old, {
3572
- pageIndex: pageIndex,
3573
- pageSize: pageSize
3574
- });
3575
- });
3576
- },
3577
- setPageCount: function setPageCount(updater) {
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
-
3585
- return _extends({}, old, {
3586
- pageCount: newPageCount
3587
- });
3588
- });
3589
- },
3590
- getPageOptions: memo(function () {
3591
- return [instance.getState().pagination.pageSize, instance.getState().pagination.pageCount];
3592
- }, function (pageSize, pageCount) {
3593
- var pageOptions = [];
3594
-
3595
- if (pageCount && pageCount > 0) {
3596
- pageOptions = [].concat(new Array(pageCount)).fill(null).map(function (_, i) {
3597
- return i;
3598
- });
3599
- }
3600
-
3601
- return pageOptions;
3602
- }, {
3603
- key: 'getPageOptions',
3604
- debug: instance.options.debug
3605
- }),
3606
- getCanPreviousPage: function getCanPreviousPage() {
3607
- return instance.getState().pagination.pageIndex > 0;
3608
- },
3609
- getCanNextPage: function getCanNextPage() {
3610
- var _instance$getState$pa = instance.getState().pagination,
3611
- pageIndex = _instance$getState$pa.pageIndex,
3612
- pageCount = _instance$getState$pa.pageCount,
3613
- pageSize = _instance$getState$pa.pageSize;
3614
-
3615
- if (pageCount === -1) {
3616
- return true;
3617
- }
3618
-
3619
- if (pageCount === 0) {
3620
- return false;
3621
- }
3622
-
3623
- return pageIndex < Math.ceil(instance.getPrePaginationRows().length / pageSize) - 1;
3624
- },
3625
- previousPage: function previousPage() {
3626
- return instance.setPageIndex(function (old) {
3627
- return old - 1;
3628
- });
3629
- },
3630
- nextPage: function nextPage() {
3631
- return instance.setPageIndex(function (old) {
3632
- return old + 1;
3633
- });
3634
- },
3635
- getPaginationRowModel: memo(function () {
3636
- return [instance.getState().pagination, instance.getExpandedRowModel(), instance.options.paginateRowsFn];
3637
- }, function (_pagination, rowModel, paginateRowsFn) {
3638
- if (!paginateRowsFn || !rowModel.rows.length) {
3639
- return rowModel;
3640
- }
3641
-
3642
- if (instance.options.debug) console.info('Paginating...');
3643
- return paginateRowsFn(instance, rowModel);
3644
- }, {
3645
- key: 'getPaginationRowModel',
3646
- debug: instance.options.debug
3647
- }),
3648
- getPrePaginationRows: function getPrePaginationRows() {
3649
- return instance.getExpandedRowModel().rows;
3650
- },
3651
- getPrePaginationFlatRows: function getPrePaginationFlatRows() {
3652
- return instance.getExpandedRowModel().flatRows;
3653
- },
3654
- getPrePaginationRowsById: function getPrePaginationRowsById() {
3655
- return instance.getExpandedRowModel().rowsById;
3656
- },
3657
- getPaginationRows: function getPaginationRows() {
3658
- return instance.getPaginationRowModel().rows;
3659
- },
3660
- getPaginationFlatRows: function getPaginationFlatRows() {
3661
- return instance.getPaginationRowModel().flatRows;
3662
- },
3663
- getPaginationRowsById: function getPaginationRowsById() {
3664
- return instance.getPaginationRowModel().rowsById;
3665
- }
3666
- };
3667
- }
3668
-
3669
- var Pagination = /*#__PURE__*/Object.freeze({
3670
- __proto__: null,
3671
- getInitialState: getInitialState$1,
3672
- getDefaultOptions: getDefaultOptions$1,
3673
- getInstance: getInstance$1
3674
- });
3675
-
3676
- //
3677
- function getInitialState() {
3678
- return {
3679
- rowSelection: {}
3680
- };
3681
- }
3682
- function getDefaultOptions(instance) {
3683
- return {
3684
- onRowSelectionChange: makeStateUpdater('rowSelection', instance),
3685
- autoResetRowSelection: true,
3686
- enableRowSelection: true,
3687
- enableMultiRowSelection: true,
3688
- enableSubRowSelection: true // enableGroupingRowSelection: false,
3689
- // isAdditiveSelectEvent: (e: MouseEvent | TouchEvent) => !!e.metaKey,
3690
- // isInclusiveSelectEvent: (e: MouseEvent | TouchEvent) => !!e.shiftKey,
3691
-
3692
- };
3693
- }
3694
- function getInstance(instance) {
3695
- var registered = false; // const pageRows = instance.getPageRows()
3696
-
3697
- return {
3698
- _notifyRowSelectionReset: function _notifyRowSelectionReset() {
3699
- if (!registered) {
3700
- registered = true;
3701
- return;
3702
- }
3703
-
3704
- if (instance.options.autoResetAll === false) {
3705
- return;
3706
- }
3707
-
3708
- if (instance.options.autoResetAll === true || instance.options.autoResetRowSelection) {
3709
- instance.resetRowSelection();
3710
- }
3711
- },
3712
- setRowSelection: function setRowSelection(updater) {
3713
- return instance.options.onRowSelectionChange == null ? void 0 : instance.options.onRowSelectionChange(updater, functionalUpdate(updater, instance.getState().rowSelection));
3714
- },
3715
- resetRowSelection: function resetRowSelection() {
3716
- var _getInitialState$rowS;
3717
-
3718
- return instance.setRowSelection((_getInitialState$rowS = getInitialState().rowSelection) != null ? _getInitialState$rowS : {});
3719
- },
3720
- toggleAllRowsSelected: function toggleAllRowsSelected(value) {
3721
- instance.setRowSelection(function (old) {
3722
- value = typeof value !== 'undefined' ? value : !instance.getIsAllRowsSelected(); // Only remove/add the rows that are visible on the screen
3723
- // Leave all the other rows that are selected alone.
3724
-
3725
- var rowSelection = Object.assign({}, old);
3726
- var preGroupedFlatRows = instance.getPreGroupedFlatRows(); // We don't use `mutateRowIsSelected` here for performance reasons.
3727
- // All of the rows are flat already, so it wouldn't be worth it
3728
-
3729
- if (value) {
3730
- preGroupedFlatRows.forEach(function (row) {
3731
- rowSelection[row.id] = true;
3732
- });
3733
- } else {
3734
- preGroupedFlatRows.forEach(function (row) {
3735
- delete rowSelection[row.id];
3736
- });
3737
- }
3738
-
3739
- return rowSelection;
3740
- });
3741
- },
3742
- toggleAllPageRowsSelected: function toggleAllPageRowsSelected(value) {
3743
- return instance.setRowSelection(function (old) {
3744
- typeof value !== 'undefined' ? value : !instance.getIsAllPageRowsSelected();
3745
-
3746
- var rowSelection = _extends({}, old);
3747
-
3748
- instance.getRows().forEach(function (row) {
3749
- mutateRowIsSelected(rowSelection, row.id, value, instance);
3750
- });
3751
- return rowSelection;
3752
- });
3753
- },
3754
- toggleRowSelected: function toggleRowSelected(rowId, value) {
3755
- var row = instance.getRow(rowId);
3756
- var isSelected = row.getIsSelected();
3757
- instance.setRowSelection(function (old) {
3758
- value = typeof value !== 'undefined' ? value : !isSelected;
3759
-
3760
- if (isSelected === value) {
3761
- return old;
3762
- }
3763
-
3764
- var selectedRowIds = _extends({}, old);
3765
-
3766
- mutateRowIsSelected(selectedRowIds, rowId, value, instance);
3767
- return selectedRowIds;
3768
- });
3769
- },
3770
- // addRowSelectionRange: rowId => {
3771
- // const {
3772
- // rows,
3773
- // rowsById,
3774
- // options: { selectGroupingRows, selectSubRows },
3775
- // } = instance
3776
- // const findSelectedRow = (rows: Row[]) => {
3777
- // let found
3778
- // rows.find(d => {
3779
- // if (d.getIsSelected()) {
3780
- // found = d
3781
- // return true
3782
- // }
3783
- // const subFound = findSelectedRow(d.subRows || [])
3784
- // if (subFound) {
3785
- // found = subFound
3786
- // return true
3787
- // }
3788
- // return false
3789
- // })
3790
- // return found
3791
- // }
3792
- // const firstRow = findSelectedRow(rows) || rows[0]
3793
- // const lastRow = rowsById[rowId]
3794
- // let include = false
3795
- // const selectedRowIds = {}
3796
- // const addRow = (row: Row) => {
3797
- // mutateRowIsSelected(selectedRowIds, row.id, true, {
3798
- // rowsById,
3799
- // selectGroupingRows: selectGroupingRows!,
3800
- // selectSubRows: selectSubRows!,
3801
- // })
3802
- // }
3803
- // instance.rows.forEach(row => {
3804
- // const isFirstRow = row.id === firstRow.id
3805
- // const isLastRow = row.id === lastRow.id
3806
- // if (isFirstRow || isLastRow) {
3807
- // if (!include) {
3808
- // include = true
3809
- // } else if (include) {
3810
- // addRow(row)
3811
- // include = false
3812
- // }
3813
- // }
3814
- // if (include) {
3815
- // addRow(row)
3816
- // }
3817
- // })
3818
- // instance.setRowSelection(selectedRowIds)
3819
- // },
3820
- getSelectedRowModel: memo(function () {
3821
- return [instance.getState().rowSelection, instance.getCoreRowModel()];
3822
- }, function (rowSelection, rowModel) {
3823
- if (!Object.keys(rowSelection).length) {
3824
- return {
3825
- rows: [],
3826
- flatRows: [],
3827
- rowsById: {}
3828
- };
3829
- }
3830
-
3831
- if (instance.options.debug) console.info('Selecting...');
3832
- return selectRowsFn(instance, rowModel);
3833
- }, {
3834
- key: 'getSelectedRowModel',
3835
- debug: instance.options.debug,
3836
- onChange: function onChange() {
3837
- return instance._notifyExpandedReset();
3838
- }
3839
- }),
3840
- getSelectedRows: function getSelectedRows() {
3841
- return instance.getSelectedRowModel().rows;
3842
- },
3843
- getSelectedFlatRows: function getSelectedFlatRows() {
3844
- return instance.getSelectedRowModel().flatRows;
3845
- },
3846
- getSelectedRowsById: function getSelectedRowsById() {
3847
- return instance.getSelectedRowModel().rowsById;
3848
- },
3849
- getFilteredSelectedRowModel: memo(function () {
3850
- return [instance.getState().rowSelection, instance.getGlobalFilteredRowModel()];
3851
- }, function (rowSelection, rowModel) {
3852
- if (!Object.keys(rowSelection).length) {
3853
- return {
3854
- rows: [],
3855
- flatRows: [],
3856
- rowsById: {}
3857
- };
3858
- }
3859
-
3860
- if (instance.options.debug) console.info('Selecting...');
3861
- return selectRowsFn(instance, rowModel);
3862
- }, {
3863
- key: 'getFilteredSelectedRowModel',
3864
- debug: instance.options.debug,
3865
- onChange: function onChange() {
3866
- return instance._notifyExpandedReset();
3867
- }
3868
- }),
3869
- getFilteredSelectedRows: function getFilteredSelectedRows() {
3870
- return instance.getFilteredSelectedRowModel().rows;
3871
- },
3872
- getFilteredSelectedFlatRows: function getFilteredSelectedFlatRows() {
3873
- return instance.getFilteredSelectedRowModel().flatRows;
3874
- },
3875
- getFilteredSelectedRowsById: function getFilteredSelectedRowsById() {
3876
- return instance.getFilteredSelectedRowModel().rowsById;
3877
- },
3878
- getGroupedSelectedRowModel: memo(function () {
3879
- return [instance.getState().rowSelection, instance.getGroupedRowModel()];
3880
- }, function (rowSelection, rowModel) {
3881
- if (!Object.keys(rowSelection).length) {
3882
- return {
3883
- rows: [],
3884
- flatRows: [],
3885
- rowsById: {}
3886
- };
3887
- }
3888
-
3889
- if (instance.options.debug) console.info('Selecting...');
3890
- return selectRowsFn(instance, rowModel);
3891
- }, {
3892
- key: 'getGroupedSelectedRowModel',
3893
- debug: instance.options.debug,
3894
- onChange: function onChange() {
3895
- return instance._notifyExpandedReset();
3896
- }
3897
- }),
3898
- getGroupedSelectedRows: function getGroupedSelectedRows() {
3899
- return instance.getGroupedSelectedRowModel().rows;
3900
- },
3901
- getGroupedSelectedFlatRows: function getGroupedSelectedFlatRows() {
3902
- return instance.getGroupedSelectedRowModel().flatRows;
3903
- },
3904
- getGroupedSelectedRowsById: function getGroupedSelectedRowsById() {
3905
- return instance.getGroupedSelectedRowModel().rowsById;
3906
- },
3907
- ///
3908
- getRowIsSelected: function getRowIsSelected(rowId) {
3909
- var _instance$getState = instance.getState(),
3910
- rowSelection = _instance$getState.rowSelection;
3911
-
3912
- var row = instance.getRow(rowId);
3913
-
3914
- if (!row) {
3915
- throw new Error();
3916
- }
3917
-
3918
- return isRowSelected(row, rowSelection) === true;
3919
- },
3920
- getRowIsSomeSelected: function getRowIsSomeSelected(rowId) {
3921
- var _instance$getState2 = instance.getState(),
3922
- rowSelection = _instance$getState2.rowSelection;
3923
-
3924
- var row = instance.getRow(rowId);
3925
-
3926
- if (!row) {
3927
- throw new Error();
3928
- }
3929
-
3930
- return isRowSelected(row, rowSelection) === 'some';
3931
- },
3932
- getRowCanSelect: function getRowCanSelect(rowId) {
3933
- var _instance$options$ena;
3934
-
3935
- var row = instance.getRow(rowId);
3936
-
3937
- if (!row) {
3938
- throw new Error();
3939
- }
3940
-
3941
- if (typeof instance.options.enableRowSelection === 'function') {
3942
- return instance.options.enableRowSelection(row);
3943
- }
3944
-
3945
- return (_instance$options$ena = instance.options.enableRowSelection) != null ? _instance$options$ena : true;
3946
- },
3947
- getRowCanSelectSubRows: function getRowCanSelectSubRows(rowId) {
3948
- var _instance$options$ena2;
3949
-
3950
- var row = instance.getRow(rowId);
3951
-
3952
- if (!row) {
3953
- throw new Error();
3954
- }
3955
-
3956
- if (typeof instance.options.enableSubRowSelection === 'function') {
3957
- return instance.options.enableSubRowSelection(row);
3958
- }
3959
-
3960
- return (_instance$options$ena2 = instance.options.enableSubRowSelection) != null ? _instance$options$ena2 : true;
3961
- },
3962
- getRowCanMultiSelect: function getRowCanMultiSelect(rowId) {
3963
- var _instance$options$ena3;
3964
-
3965
- var row = instance.getRow(rowId);
3966
-
3967
- if (!row) {
3968
- throw new Error();
3969
- }
3970
-
3971
- if (typeof instance.options.enableMultiRowSelection === 'function') {
3972
- return instance.options.enableMultiRowSelection(row);
3973
- }
3974
-
3975
- return (_instance$options$ena3 = instance.options.enableMultiRowSelection) != null ? _instance$options$ena3 : true;
3976
- },
3977
- // getGroupingRowCanSelect: rowId => {
3978
- // const row = instance.getRow(rowId)
3979
- // if (!row) {
3980
- // throw new Error()
3981
- // }
3982
- // if (typeof instance.options.enableGroupingRowSelection === 'function') {
3983
- // return instance.options.enableGroupingRowSelection(row)
3984
- // }
3985
- // return instance.options.enableGroupingRowSelection ?? false
3986
- // },
3987
- getIsAllRowsSelected: function getIsAllRowsSelected() {
3988
- var preFilteredFlatRows = instance.getPreGlobalFilteredFlatRows();
3989
-
3990
- var _instance$getState3 = instance.getState(),
3991
- rowSelection = _instance$getState3.rowSelection;
3992
-
3993
- var isAllRowsSelected = Boolean(preFilteredFlatRows.length && Object.keys(rowSelection).length);
3994
-
3995
- if (isAllRowsSelected) {
3996
- if (preFilteredFlatRows.some(function (row) {
3997
- return !rowSelection[row.id];
3998
- })) {
3999
- isAllRowsSelected = false;
4000
- }
4001
- }
4002
-
4003
- return isAllRowsSelected;
4004
- },
4005
- getIsAllPageRowsSelected: function getIsAllPageRowsSelected() {
4006
- var paginationFlatRows = instance.getPaginationFlatRows();
4007
-
4008
- var _instance$getState4 = instance.getState(),
4009
- rowSelection = _instance$getState4.rowSelection;
4010
-
4011
- var isAllPageRowsSelected = !!paginationFlatRows.length;
4012
-
4013
- if (isAllPageRowsSelected && paginationFlatRows.some(function (row) {
4014
- return !rowSelection[row.id];
4015
- })) {
4016
- isAllPageRowsSelected = false;
4017
- }
4018
-
4019
- return isAllPageRowsSelected;
4020
- },
4021
- getIsSomeRowsSelected: function getIsSomeRowsSelected() {
4022
- var _instance$getState$ro;
4023
-
4024
- return !instance.getIsAllRowsSelected() && !!Object.keys((_instance$getState$ro = instance.getState().rowSelection) != null ? _instance$getState$ro : {}).length;
4025
- },
4026
- getIsSomePageRowsSelected: function getIsSomePageRowsSelected() {
4027
- var paginationFlatRows = instance.getPaginationFlatRows();
4028
- return instance.getIsAllPageRowsSelected() ? false : !!(paginationFlatRows != null && paginationFlatRows.length);
4029
- },
4030
- getToggleRowSelectedProps: function getToggleRowSelectedProps(rowId, userProps) {
4031
- var row = instance.getRow(rowId);
4032
- var isSelected = row.getIsSelected();
4033
- var isSomeSelected = row.getIsSomeSelected();
4034
- var canSelect = row.getCanSelect();
4035
- var initialProps = {
4036
- onChange: canSelect ? function (e) {
4037
- row.toggleSelected(e.target.checked);
4038
- } : undefined,
4039
- checked: isSelected,
4040
- title: 'Toggle Row Selected',
4041
- indeterminate: isSomeSelected // onChange: forInput
4042
- // ? (e: Event) => e.stopPropagation()
4043
- // : (e: Event) => {
4044
- // if (instance.options.isAdditiveSelectEvent(e)) {
4045
- // row.toggleSelected()
4046
- // } else if (instance.options.isInclusiveSelectEvent(e)) {
4047
- // instance.addRowSelectionRange(row.id)
4048
- // } else {
4049
- // instance.setRowSelection({})
4050
- // row.toggleSelected()
4051
- // }
4052
- // if (props.onClick) props.onClick(e)
4053
- // },
4054
-
4055
- };
4056
- return propGetter(initialProps, userProps);
4057
- },
4058
- getToggleAllRowsSelectedProps: function getToggleAllRowsSelectedProps(userProps) {
4059
- var isSomeRowsSelected = instance.getIsSomeRowsSelected();
4060
- var isAllRowsSelected = instance.getIsAllRowsSelected();
4061
- var initialProps = {
4062
- onChange: function onChange(e) {
4063
- instance.toggleAllRowsSelected(e.target.checked);
4064
- },
4065
- checked: isAllRowsSelected,
4066
- title: 'Toggle All Rows Selected',
4067
- indeterminate: isSomeRowsSelected
4068
- };
4069
- return propGetter(initialProps, userProps);
4070
- },
4071
- getToggleAllPageRowsSelectedProps: function getToggleAllPageRowsSelectedProps(userProps) {
4072
- var isSomePageRowsSelected = instance.getIsSomePageRowsSelected();
4073
- var isAllPageRowsSelected = instance.getIsAllPageRowsSelected();
4074
- var initialProps = {
4075
- onChange: function onChange(e) {
4076
- instance.toggleAllPageRowsSelected(e.target.checked);
4077
- },
4078
- checked: isAllPageRowsSelected,
4079
- title: 'Toggle All Current Page Rows Selected',
4080
- indeterminate: isSomePageRowsSelected
4081
- };
4082
- return propGetter(initialProps, userProps);
4083
- }
4084
- };
4085
- }
4086
- function createRow(row, instance) {
4087
- return {
4088
- getIsSelected: function getIsSelected() {
4089
- return instance.getRowIsSelected(row.id);
4090
- },
4091
- getIsSomeSelected: function getIsSomeSelected() {
4092
- return instance.getRowIsSomeSelected(row.id);
4093
- },
4094
- toggleSelected: function toggleSelected(value) {
4095
- return instance.toggleRowSelected(row.id, value);
4096
- },
4097
- getToggleSelectedProps: function getToggleSelectedProps(userProps) {
4098
- return instance.getToggleRowSelectedProps(row.id, userProps);
4099
- },
4100
- getCanMultiSelect: function getCanMultiSelect() {
4101
- return instance.getRowCanMultiSelect(row.id);
4102
- },
4103
- getCanSelect: function getCanSelect() {
4104
- return instance.getRowCanSelect(row.id);
4105
- }
4106
- };
4107
- }
4108
-
4109
- var mutateRowIsSelected = function mutateRowIsSelected(selectedRowIds, id, value, instance) {
4110
- var _row$subRows;
4111
-
4112
- var row = instance.getRow(id);
4113
- row.getIsGrouped(); // if ( // TODO: enforce grouping row selection rules
4114
- // !isGrouped ||
4115
- // (isGrouped && instance.options.enableGroupingRowSelection)
4116
- // ) {
4117
-
4118
- if (value) {
4119
- selectedRowIds[id] = true;
4120
- } else {
4121
- delete selectedRowIds[id];
4122
- } // }
4123
-
4124
-
4125
- if ((_row$subRows = row.subRows) != null && _row$subRows.length && instance.getRowCanSelectSubRows(row.id)) {
4126
- row.subRows.forEach(function (row) {
4127
- return mutateRowIsSelected(selectedRowIds, row.id, value, instance);
4128
- });
4129
- }
4130
- };
4131
-
4132
- function selectRowsFn(instance, rowModel) {
4133
- var rowSelection = instance.getState().rowSelection;
4134
- var newSelectedFlatRows = [];
4135
- var newSelectedRowsById = {}; // Filters top level and nested rows
4136
-
4137
- var recurseRows = function recurseRows(rows, depth) {
4138
-
4139
- return rows.map(function (row) {
4140
- var _row$subRows2;
4141
-
4142
- var isSelected = isRowSelected(row, rowSelection) === true;
4143
-
4144
- if (isSelected) {
4145
- newSelectedFlatRows.push(row);
4146
- newSelectedRowsById[row.id] = row;
4147
- }
4148
-
4149
- if ((_row$subRows2 = row.subRows) != null && _row$subRows2.length) {
4150
- row = _extends({}, row, {
4151
- subRows: recurseRows(row.subRows)
4152
- });
4153
- }
4154
-
4155
- if (isSelected) {
4156
- return row;
4157
- }
4158
- }).filter(Boolean);
4159
- };
4160
-
4161
- return {
4162
- rows: recurseRows(rowModel.rows),
4163
- flatRows: newSelectedFlatRows,
4164
- rowsById: newSelectedRowsById
4165
- };
4166
- }
4167
- function isRowSelected(row, selection, instance) {
4168
- if (selection[row.id]) {
4169
- return true;
4170
- }
4171
-
4172
- if (row.subRows && row.subRows.length) {
4173
- var allChildrenSelected = true;
4174
- var someSelected = false;
4175
- row.subRows.forEach(function (subRow) {
4176
- // Bail out early if we know both of these
4177
- if (someSelected && !allChildrenSelected) {
4178
- return;
4179
- }
4180
-
4181
- if (isRowSelected(subRow, selection)) {
4182
- someSelected = true;
4183
- } else {
4184
- allChildrenSelected = false;
4185
- }
4186
- });
4187
- return allChildrenSelected ? true : someSelected ? 'some' : false;
4188
- }
4189
-
4190
- return false;
4191
- }
4192
-
4193
- var RowSelection = /*#__PURE__*/Object.freeze({
4194
- __proto__: null,
4195
- getInitialState: getInitialState,
4196
- getDefaultOptions: getDefaultOptions,
4197
- getInstance: getInstance,
4198
- createRow: createRow,
4199
- selectRowsFn: selectRowsFn,
4200
- isRowSelected: isRowSelected
4201
- });
4202
-
4203
- var features = [Visibility, Ordering, Pinning, Headers, Filters, Sorting, Grouping, Expanding, ColumnSizing, Pagination, RowSelection];
4204
- function createTableInstance(options, rerender) {
4205
- var _options$initialState;
4206
-
4207
- if (options.debug) {
4208
- console.info('Creating React Table Instance...');
4209
- }
4210
-
4211
- var instance = {};
4212
- var defaultOptions = features.reduce(function (obj, feature) {
4213
- return Object.assign(obj, feature.getDefaultOptions == null ? void 0 : feature.getDefaultOptions(instance));
4214
- }, {});
4215
- var defaultState = {};
4216
-
4217
- var buildOptions = function buildOptions(options) {
4218
- return _extends({
4219
- state: defaultState
4220
- }, defaultOptions, options);
4221
- };
4222
-
4223
- instance.options = buildOptions(options);
4224
-
4225
- var initialState = _extends({}, features.reduce(function (obj, feature) {
4226
- return Object.assign(obj, feature.getInitialState == null ? void 0 : feature.getInitialState());
4227
- }, {}), (_options$initialState = options.initialState) != null ? _options$initialState : {});
4228
-
4229
- var finalInstance = _extends({}, instance, features.reduce(function (obj, feature) {
4230
- return Object.assign(obj, feature.getInstance == null ? void 0 : feature.getInstance(instance));
4231
- }, {}), {
4232
- rerender: rerender,
4233
- initialState: initialState,
4234
- internalState: initialState,
4235
- reset: function reset() {
4236
- instance.setState(instance.initialState);
4237
- },
4238
- updateOptions: function updateOptions(newOptions) {
4239
- instance.options = buildOptions(newOptions);
4240
- },
4241
- getRowId: function getRowId(_, index, parent) {
4242
- return "" + (parent ? [parent.id, index].join('.') : index);
4243
- },
4244
- getState: function getState() {
4245
- var state = _extends({}, instance.internalState, instance.options.state);
4246
-
4247
- return state;
4248
- },
4249
- setState: function setState(updater, shouldRerender) {
4250
- if (shouldRerender === void 0) {
4251
- shouldRerender = true;
4252
- }
4253
-
4254
- var onStateChange = instance.options.onStateChange;
4255
- var internalState = instance.internalState;
4256
- var newState = functionalUpdate(updater, internalState);
4257
- instance.internalState = newState;
4258
-
4259
- if (onStateChange) {
4260
- onStateChange(newState);
4261
- return;
4262
- }
4263
-
4264
- if (shouldRerender) {
4265
- instance.rerender();
4266
- }
4267
- },
4268
- getDefaultColumn: memo(function () {
4269
- return [instance.options.defaultColumn];
4270
- }, function (defaultColumn) {
4271
- var _defaultColumn;
4272
-
4273
- defaultColumn = (_defaultColumn = defaultColumn) != null ? _defaultColumn : {};
4274
- return _extends({
4275
- header: function header(props) {
4276
- return props.header.column.id;
4277
- },
4278
- footer: function footer(props) {
4279
- return props.header.column.id;
4280
- },
4281
- cell: function cell(_ref) {
4282
- var _ref$value = _ref.value,
4283
- value = _ref$value === void 0 ? '' : _ref$value;
4284
- return typeof value === 'boolean' ? value.toString() : value;
4285
- }
4286
- }, features.reduce(function (obj, feature) {
4287
- return Object.assign(obj, feature.getDefaultColumn == null ? void 0 : feature.getDefaultColumn());
4288
- }, {}), defaultColumn);
4289
- }, {
4290
- debug: instance.options.debug,
4291
- key: 'getDefaultColumn'
4292
- }),
4293
- getColumnDefs: function getColumnDefs() {
4294
- return instance.options.columns;
4295
- },
4296
- createColumn: function createColumn(columnDef, depth, parent) {
4297
- var _ref2, _columnDef$id;
4298
-
4299
- var defaultColumn = instance.getDefaultColumn();
4300
- var id = (_ref2 = (_columnDef$id = columnDef.id) != null ? _columnDef$id : columnDef.accessorKey) != null ? _ref2 : typeof columnDef.header === 'string' ? columnDef.header : undefined;
4301
- var accessorFn;
4302
-
4303
- if (columnDef.accessorFn) {
4304
- accessorFn = columnDef.accessorFn;
4305
- } else if (columnDef.accessorKey) {
4306
- accessorFn = function accessorFn(originalRow) {
4307
- return originalRow[columnDef.accessorKey];
4308
- };
4309
- }
4310
-
4311
- if (!id) {
4312
- {
4313
- throw new Error(columnDef.accessorFn ? "Columns require an id when using an accessorFn" : "Columns require an id when using a non-string header");
4314
- }
4315
- }
4316
-
4317
- var column = _extends({}, defaultColumnSizing, defaultColumn, columnDef, {
4318
- id: "" + id,
4319
- accessorFn: accessorFn,
4320
- parent: parent,
4321
- depth: depth,
4322
- columnDef: columnDef,
4323
- columns: [],
4324
- getWidth: function getWidth() {
4325
- return instance.getColumnWidth(column.id);
4326
- },
4327
- getFlatColumns: memo(function () {
4328
- return [true];
4329
- }, function () {
4330
- var _column$columns;
4331
-
4332
- return [column].concat((_column$columns = column.columns) == null ? void 0 : _column$columns.flatMap(function (d) {
4333
- return d.getFlatColumns();
4334
- }));
4335
- }, {
4336
- key: 'column.getFlatColumns',
4337
- debug: instance.options.debug
4338
- }),
4339
- getLeafColumns: memo(function () {
4340
- return [instance.getOrderColumnsFn()];
4341
- }, function (orderColumns) {
4342
- var _column$columns2;
4343
-
4344
- if ((_column$columns2 = column.columns) != null && _column$columns2.length) {
4345
- var leafColumns = column.columns.flatMap(function (column) {
4346
- return column.getLeafColumns();
4347
- });
4348
- return orderColumns(leafColumns);
4349
- }
4350
-
4351
- return [column];
4352
- }, {
4353
- key: 'column.getLeafColumns',
4354
- debug: instance.options.debug
4355
- })
4356
- });
4357
-
4358
- column = features.reduce(function (obj, feature) {
4359
- return Object.assign(obj, feature.createColumn == null ? void 0 : feature.createColumn(column, instance));
4360
- }, column); // Yes, we have to convert instance to uknown, because we know more than the compiler here.
4361
-
4362
- return column;
4363
- },
4364
- getAllColumns: memo(function () {
4365
- return [instance.getColumnDefs()];
4366
- }, function (columnDefs) {
4367
- if (instance.options.debug) console.info('Building Columns...');
4368
-
4369
- var recurseColumns = function recurseColumns(columnDefs, parent, depth) {
4370
- if (depth === void 0) {
4371
- depth = 0;
4372
- }
4373
-
4374
- return columnDefs.map(function (columnDef) {
4375
- var column = instance.createColumn(columnDef, depth, parent);
4376
- column.columns = columnDef.columns ? recurseColumns(columnDef.columns, column, depth + 1) : [];
4377
- return column;
4378
- });
4379
- };
4380
-
4381
- return recurseColumns(columnDefs);
4382
- }, {
4383
- key: 'getAllColumns',
4384
- debug: instance.options.debug
4385
- }),
4386
- getAllFlatColumns: memo(function () {
4387
- return [instance.getAllColumns()];
4388
- }, function (allColumns) {
4389
- return allColumns.flatMap(function (column) {
4390
- return column.getFlatColumns();
4391
- });
4392
- }, {
4393
- key: 'getAllFlatColumns',
4394
- debug: instance.options.debug
4395
- }),
4396
- getAllFlatColumnsById: memo(function () {
4397
- return [instance.getAllFlatColumns()];
4398
- }, function (flatColumns) {
4399
- return flatColumns.reduce(function (acc, column) {
4400
- acc[column.id] = column;
4401
- return acc;
4402
- }, {});
4403
- }, {
4404
- key: 'getAllFlatColumnsById',
4405
- debug: instance.options.debug
4406
- }),
4407
- getAllLeafColumns: memo(function () {
4408
- return [instance.getAllColumns(), instance.getOrderColumnsFn()];
4409
- }, function (allColumns, orderColumns) {
4410
- var leafColumns = allColumns.flatMap(function (column) {
4411
- return column.getLeafColumns();
4412
- });
4413
- return orderColumns(leafColumns);
4414
- }, {
4415
- key: 'getAllLeafColumns',
4416
- debug: instance.options.debug
4417
- }),
4418
- getColumn: function getColumn(columnId) {
4419
- var column = instance.getAllFlatColumnsById()[columnId];
4420
-
4421
- if (!column) {
4422
- {
4423
- console.warn("[React Table] Column with id " + columnId + " does not exist.");
4424
- }
4425
-
4426
- throw new Error();
4427
- }
4428
-
4429
- return column;
4430
- },
4431
- getColumnWidth: function getColumnWidth(columnId) {
4432
- var _column$minWidth, _ref3, _column$maxWidth;
4433
-
4434
- var column = instance.getColumn(columnId);
4435
-
4436
- if (!column) {
4437
- throw new Error();
4438
- }
4439
-
4440
- var columnSize = instance.getState().columnSizing[column.id];
4441
- return Math.min(Math.max((_column$minWidth = column.minWidth) != null ? _column$minWidth : defaultColumnSizing.minWidth, (_ref3 = columnSize != null ? columnSize : column.width) != null ? _ref3 : defaultColumnSizing.width), (_column$maxWidth = column.maxWidth) != null ? _column$maxWidth : defaultColumnSizing.maxWidth);
4442
- },
4443
- createCell: function createCell(row, column, value) {
4444
- var cell = {
4445
- id: row.id + "_" + column.id,
4446
- rowId: row.id,
4447
- columnId: column.id,
4448
- row: row,
4449
- column: column,
4450
- value: value,
4451
- getCellProps: function getCellProps(userProps) {
4452
- return instance.getCellProps(row.id, column.id, userProps);
4453
- },
4454
- renderCell: function renderCell() {
4455
- return flexRender(column.cell, {
4456
- instance: instance,
4457
- column: column,
4458
- row: row,
4459
- cell: cell,
4460
- value: value
4461
- });
4462
- }
4463
- };
4464
- features.forEach(function (feature) {
4465
- Object.assign(cell, feature.createCell == null ? void 0 : feature.createCell(cell, column, row, instance));
4466
- }, {});
4467
- return cell;
4468
- },
4469
- createRow: function createRow(id, original, rowIndex, depth, values) {
4470
- var row = {
4471
- id: id,
4472
- index: rowIndex,
4473
- original: original,
4474
- depth: depth,
4475
- values: values,
4476
- subRows: [],
4477
- leafRows: [],
4478
- getRowProps: function getRowProps(userProps) {
4479
- return instance.getRowProps(row.id, userProps);
4480
- },
4481
- getAllCells: undefined,
4482
- getAllCellsByColumnId: undefined
4483
- };
4484
- row.getAllCells = memo(function () {
4485
- return [instance.getAllLeafColumns()];
4486
- }, function (leafColumns) {
4487
- return leafColumns.map(function (column) {
4488
- return instance.createCell(row, column, row.values[column.id]);
4489
- });
4490
- }, {
4491
- key: 'row.getAllCells' ,
4492
- debug: instance.options.debug
4493
- });
4494
- row.getAllCellsByColumnId = memo(function () {
4495
- return [row.getAllCells()];
4496
- }, function (allCells) {
4497
- return allCells.reduce(function (acc, cell) {
4498
- acc[cell.columnId] = cell;
4499
- return acc;
4500
- }, {});
4501
- }, {
4502
- key: 'row.getAllCellsByColumnId',
4503
- debug: instance.options.debug
4504
- });
4505
- features.forEach(function (feature) {
4506
- Object.assign(row, feature.createRow == null ? void 0 : feature.createRow(row, instance));
4507
- });
4508
- return row;
4509
- },
4510
- getCoreRowModel: memo(function () {
4511
- return [instance.options.data];
4512
- }, function (data) {
4513
- if (instance.options.debug) console.info('Accessing...'); // Access the row model using initial columns
4514
-
4515
- var rows = [];
4516
- var flatRows = [];
4517
- var rowsById = {};
4518
- var leafColumns = instance.getAllLeafColumns();
4519
-
4520
- var accessRow = function accessRow(originalRow, rowIndex, depth, parentRows, parent) {
4521
- if (depth === void 0) {
4522
- depth = 0;
4523
- }
4524
-
4525
- var id = instance.getRowId(originalRow, rowIndex, parent);
4526
-
4527
- if (!id) {
4528
- {
4529
- throw new Error("getRowId expected an ID, but got " + id);
4530
- }
4531
- }
4532
-
4533
- var values = {};
4534
-
4535
- for (var i = 0; i < leafColumns.length; i++) {
4536
- var _column = leafColumns[i];
4537
-
4538
- if (_column && _column.accessorFn) {
4539
- values[_column.id] = _column.accessorFn(originalRow, rowIndex);
4540
- }
4541
- } // Make the row
4542
-
4543
-
4544
- var row = instance.createRow(id, originalRow, rowIndex, depth, values); // Push instance row into the parentRows array
4545
-
4546
- parentRows.push(row); // Keep track of every row in a flat array
4547
-
4548
- flatRows.push(row); // Also keep track of every row by its ID
4549
-
4550
- rowsById[id] = row; // Get the original subrows
4551
-
4552
- if (instance.options.getSubRows) {
4553
- var originalSubRows = instance.options.getSubRows(originalRow, rowIndex); // Then recursively access them
4554
-
4555
- if (originalSubRows != null && originalSubRows.length) {
4556
- row.originalSubRows = originalSubRows;
4557
- var subRows = [];
4558
-
4559
- for (var _i = 0; _i < row.originalSubRows.length; _i++) {
4560
- accessRow(row.originalSubRows[_i], _i, depth + 1, subRows, row);
4561
- } // Keep the new subRows array on the row
4562
-
4563
-
4564
- row.subRows = subRows;
4565
- row.leafRows = flattenBy(subRows, function (d) {
4566
- return d.leafRows;
4567
- });
4568
- }
4569
- }
4570
- };
4571
-
4572
- for (var i = 0; i < data.length; i++) {
4573
- accessRow(data[i], i, 0, rows);
4574
- }
4575
-
4576
- return {
4577
- rows: rows,
4578
- flatRows: flatRows,
4579
- rowsById: rowsById
4580
- };
4581
- }, {
4582
- key: 'getRowModel',
4583
- debug: instance.options.debug,
4584
- onChange: function onChange() {
4585
- instance._notifyRowSelectionReset();
4586
-
4587
- instance._notifyFiltersReset();
4588
- }
4589
- }),
4590
- // The standard
4591
- getCoreRows: function getCoreRows() {
4592
- return instance.getCoreRowModel().rows;
4593
- },
4594
- getCoreFlatRows: function getCoreFlatRows() {
4595
- return instance.getCoreRowModel().flatRows;
4596
- },
4597
- getCoreRowsById: function getCoreRowsById() {
4598
- return instance.getCoreRowModel().rowsById;
4599
- },
4600
- // The final calls start at the bottom of the model,
4601
- // expanded rows, which then work their way up
4602
- getRowModel: function getRowModel() {
4603
- return instance.getPaginationRowModel();
4604
- },
4605
- getRows: function getRows() {
4606
- return instance.getRowModel().rows;
4607
- },
4608
- getFlatRows: function getFlatRows() {
4609
- return instance.getRowModel().flatRows;
4610
- },
4611
- getRowsById: function getRowsById() {
4612
- return instance.getRowModel().rowsById;
4613
- },
4614
- getRow: function getRow(id) {
4615
- var row = instance.getRowsById()[id];
4616
-
4617
- if (!row) {
4618
- {
4619
- throw new Error("getRow expected an ID, but got " + id);
4620
- }
4621
- }
4622
-
4623
- return row;
4624
- },
4625
- getCell: function getCell(rowId, columnId) {
4626
- var row = instance.getRow(rowId);
4627
-
4628
- if (!row) {
4629
- {
4630
- throw new Error("[React Table] could not find row with id " + rowId);
4631
- }
4632
- }
4633
-
4634
- var cell = row.getAllCellsByColumnId()[columnId];
4635
-
4636
- if (!cell) {
4637
- {
4638
- throw new Error("[React Table] could not find cell " + columnId + " in row " + rowId);
4639
- }
4640
- }
4641
-
4642
- return cell;
4643
- },
4644
- getTableProps: function getTableProps(userProps) {
4645
- return propGetter({
4646
- role: 'table'
4647
- }, userProps);
4648
- },
4649
- getTableBodyProps: function getTableBodyProps(userProps) {
4650
- return propGetter({
4651
- role: 'rowgroup'
4652
- }, userProps);
4653
- },
4654
- getRowProps: function getRowProps(rowId, userProps) {
4655
- var row = instance.getRow(rowId);
4656
-
4657
- if (!row) {
4658
- return;
4659
- }
4660
-
4661
- return propGetter({
4662
- key: row.id,
4663
- role: 'row'
4664
- }, userProps);
4665
- },
4666
- getCellProps: function getCellProps(rowId, columnId, userProps) {
4667
- var cell = instance.getCell(rowId, columnId);
4668
-
4669
- if (!cell) {
4670
- return;
4671
- }
4672
-
4673
- return propGetter({
4674
- key: cell.id,
4675
- role: 'gridcell'
4676
- }, userProps);
4677
- },
4678
- getTableWidth: function getTableWidth() {
4679
- var _instance$getHeaderGr, _instance$getHeaderGr2;
4680
-
4681
- return (_instance$getHeaderGr = (_instance$getHeaderGr2 = instance.getHeaderGroups()[0]) == null ? void 0 : _instance$getHeaderGr2.headers.reduce(function (sum, header) {
4682
- return sum + header.getWidth();
4683
- }, 0)) != null ? _instance$getHeaderGr : 0;
4684
- },
4685
- getLeftTableWidth: function getLeftTableWidth() {
4686
- var _instance$getLeftHead, _instance$getLeftHead2;
4687
-
4688
- return (_instance$getLeftHead = (_instance$getLeftHead2 = instance.getLeftHeaderGroups()[0]) == null ? void 0 : _instance$getLeftHead2.headers.reduce(function (sum, header) {
4689
- return sum + header.getWidth();
4690
- }, 0)) != null ? _instance$getLeftHead : 0;
4691
- },
4692
- getCenterTableWidth: function getCenterTableWidth() {
4693
- var _instance$getCenterHe, _instance$getCenterHe2;
4694
-
4695
- return (_instance$getCenterHe = (_instance$getCenterHe2 = instance.getCenterHeaderGroups()[0]) == null ? void 0 : _instance$getCenterHe2.headers.reduce(function (sum, header) {
4696
- return sum + header.getWidth();
4697
- }, 0)) != null ? _instance$getCenterHe : 0;
4698
- },
4699
- getRightTableWidth: function getRightTableWidth() {
4700
- var _instance$getRightHea, _instance$getRightHea2;
4701
-
4702
- return (_instance$getRightHea = (_instance$getRightHea2 = instance.getRightHeaderGroups()[0]) == null ? void 0 : _instance$getRightHea2.headers.reduce(function (sum, header) {
4703
- return sum + header.getWidth();
4704
- }, 0)) != null ? _instance$getRightHea : 0;
4705
- }
4706
- });
4707
-
4708
- instance = Object.assign(instance, finalInstance); // This won't trigger a rerender yet, but it will force
4709
- // pagination derivation to run (particularly pageSize detection)
4710
-
4711
- instance.setPagination(function (d) {
4712
- return d;
4713
- });
4714
- return instance;
4715
- }
4716
-
4717
- function createTable() {
4718
- return {
4719
- RowType: function RowType() {
4720
- return createTable();
4721
- },
4722
- FilterFns: function FilterFns() {
4723
- return createTable();
4724
- },
4725
- SortingFns: function SortingFns() {
4726
- return createTable();
4727
- },
4728
- AggregationFns: function AggregationFns() {
4729
- return createTable();
4730
- },
4731
- createColumns: function createColumns(columns) {
4732
- return columns;
4733
- },
4734
- createDisplayColumn: function createDisplayColumn(column) {
4735
- return _extends({}, column, {
4736
- __generated: true
4737
- });
4738
- },
4739
- createGroup: function createGroup(column) {
4740
- return _extends({}, column, {
4741
- __generated: true
4742
- });
4743
- },
4744
- createDataColumn: function createDataColumn(accessor, column) {
4745
- column = _extends({}, column, {
4746
- id: column.id
4747
- });
4748
-
4749
- if (typeof accessor === 'string') {
4750
- var _column$id;
4751
-
4752
- return _extends({}, column, {
4753
- id: (_column$id = column.id) != null ? _column$id : accessor,
4754
- accessorKey: accessor,
4755
- __generated: true
4756
- });
4757
- }
4758
-
4759
- if (typeof accessor === 'function') {
4760
- return _extends({}, column, {
4761
- accessorFn: accessor,
4762
- __generated: true
4763
- });
4764
- }
4765
-
4766
- throw new Error('Invalid accessor');
4767
- },
4768
- useTable: function useTable(options) {
4769
- var instanceRef = React__namespace.useRef(undefined);
4770
- var rerender = React__namespace.useReducer(function () {
4771
- return {};
4772
- }, {})[1];
4773
-
4774
- if (!instanceRef.current) {
4775
- instanceRef.current = createTableInstance(options, rerender);
4776
- }
4777
-
4778
- instanceRef.current.updateOptions(options);
4779
- return instanceRef.current;
4780
- },
4781
- types: undefined
4782
- };
4783
- }
4784
-
4785
- exports.columnFilterRowsFn = columnFilterRowsFn;
4786
- exports.createTable = createTable;
4787
- exports.expandRowsFn = expandRowsFn;
4788
- exports.globalFilterRowsFn = globalFilterRowsFn;
4789
- exports.groupRowsFn = groupRowsFn;
4790
- exports.paginateRowsFn = paginateRowsFn;
4791
- exports.sortRowsFn = sortRowsFn;
4792
-
4793
130
  Object.defineProperty(exports, '__esModule', { value: true });
4794
131
 
4795
132
  }));