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

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