@tanstack/react-table 8.0.0-alpha.8 → 8.0.0-alpha.83

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 (113) hide show
  1. package/build/cjs/react-table/src/index.js +138 -0
  2. package/build/cjs/react-table/src/index.js.map +1 -0
  3. package/build/cjs/table-core/build/esm/index.js +3982 -0
  4. package/build/cjs/table-core/build/esm/index.js.map +1 -0
  5. package/build/esm/index.js +3269 -4049
  6. package/build/esm/index.js.map +1 -1
  7. package/build/stats-html.html +1 -1
  8. package/build/stats-react.json +24 -797
  9. package/build/types/index.d.ts +16 -8
  10. package/build/umd/index.development.js +3375 -4119
  11. package/build/umd/index.development.js.map +1 -1
  12. package/build/umd/index.production.js +11 -1
  13. package/build/umd/index.production.js.map +1 -1
  14. package/package.json +7 -9
  15. package/src/index.tsx +111 -8
  16. package/build/cjs/_virtual/_rollupPluginBabelHelpers.js +0 -112
  17. package/build/cjs/_virtual/_rollupPluginBabelHelpers.js.map +0 -1
  18. package/build/cjs/aggregationTypes.js +0 -130
  19. package/build/cjs/aggregationTypes.js.map +0 -1
  20. package/build/cjs/core.js +0 -560
  21. package/build/cjs/core.js.map +0 -1
  22. package/build/cjs/createTable.js +0 -108
  23. package/build/cjs/createTable.js.map +0 -1
  24. package/build/cjs/features/ColumnSizing.js +0 -317
  25. package/build/cjs/features/ColumnSizing.js.map +0 -1
  26. package/build/cjs/features/Expanding.js +0 -251
  27. package/build/cjs/features/Expanding.js.map +0 -1
  28. package/build/cjs/features/Filters.js +0 -445
  29. package/build/cjs/features/Filters.js.map +0 -1
  30. package/build/cjs/features/Grouping.js +0 -249
  31. package/build/cjs/features/Grouping.js.map +0 -1
  32. package/build/cjs/features/Headers.js +0 -549
  33. package/build/cjs/features/Headers.js.map +0 -1
  34. package/build/cjs/features/Ordering.js +0 -86
  35. package/build/cjs/features/Ordering.js.map +0 -1
  36. package/build/cjs/features/Pagination.js +0 -198
  37. package/build/cjs/features/Pagination.js.map +0 -1
  38. package/build/cjs/features/Pinning.js +0 -149
  39. package/build/cjs/features/Pinning.js.map +0 -1
  40. package/build/cjs/features/RowSelection.js +0 -541
  41. package/build/cjs/features/RowSelection.js.map +0 -1
  42. package/build/cjs/features/Sorting.js +0 -327
  43. package/build/cjs/features/Sorting.js.map +0 -1
  44. package/build/cjs/features/Visibility.js +0 -166
  45. package/build/cjs/features/Visibility.js.map +0 -1
  46. package/build/cjs/filterTypes.js +0 -172
  47. package/build/cjs/filterTypes.js.map +0 -1
  48. package/build/cjs/index.js +0 -32
  49. package/build/cjs/index.js.map +0 -1
  50. package/build/cjs/sortTypes.js +0 -122
  51. package/build/cjs/sortTypes.js.map +0 -1
  52. package/build/cjs/utils/columnFilterRowsFn.js +0 -131
  53. package/build/cjs/utils/columnFilterRowsFn.js.map +0 -1
  54. package/build/cjs/utils/expandRowsFn.js +0 -38
  55. package/build/cjs/utils/expandRowsFn.js.map +0 -1
  56. package/build/cjs/utils/globalFilterRowsFn.js +0 -101
  57. package/build/cjs/utils/globalFilterRowsFn.js.map +0 -1
  58. package/build/cjs/utils/groupRowsFn.js +0 -155
  59. package/build/cjs/utils/groupRowsFn.js.map +0 -1
  60. package/build/cjs/utils/paginateRowsFn.js +0 -44
  61. package/build/cjs/utils/paginateRowsFn.js.map +0 -1
  62. package/build/cjs/utils/sortRowsFn.js +0 -94
  63. package/build/cjs/utils/sortRowsFn.js.map +0 -1
  64. package/build/cjs/utils.js +0 -141
  65. package/build/cjs/utils.js.map +0 -1
  66. package/build/types/aggregationTypes.d.ts +0 -22
  67. package/build/types/core.d.ts +0 -110
  68. package/build/types/createTable.d.ts +0 -52
  69. package/build/types/features/ColumnSizing.d.ts +0 -67
  70. package/build/types/features/Expanding.d.ts +0 -53
  71. package/build/types/features/Filters.d.ts +0 -98
  72. package/build/types/features/Grouping.d.ts +0 -82
  73. package/build/types/features/Headers.d.ts +0 -41
  74. package/build/types/features/Ordering.d.ts +0 -19
  75. package/build/types/features/Pagination.d.ts +0 -44
  76. package/build/types/features/Pinning.d.ts +0 -39
  77. package/build/types/features/RowSelection.d.ts +0 -66
  78. package/build/types/features/Sorting.d.ts +0 -78
  79. package/build/types/features/Visibility.d.ts +0 -47
  80. package/build/types/filterTypes.d.ts +0 -50
  81. package/build/types/sortTypes.d.ts +0 -18
  82. package/build/types/types.d.ts +0 -127
  83. package/build/types/utils/columnFilterRowsFn.d.ts +0 -2
  84. package/build/types/utils/expandRowsFn.d.ts +0 -2
  85. package/build/types/utils/globalFilterRowsFn.d.ts +0 -2
  86. package/build/types/utils/groupRowsFn.d.ts +0 -2
  87. package/build/types/utils/paginateRowsFn.d.ts +0 -2
  88. package/build/types/utils/sortRowsFn.d.ts +0 -2
  89. package/build/types/utils.d.ts +0 -24
  90. package/src/aggregationTypes.ts +0 -115
  91. package/src/core.tsx +0 -1096
  92. package/src/createTable.tsx +0 -244
  93. package/src/features/ColumnSizing.ts +0 -453
  94. package/src/features/Expanding.ts +0 -406
  95. package/src/features/Filters.ts +0 -762
  96. package/src/features/Grouping.ts +0 -466
  97. package/src/features/Headers.ts +0 -912
  98. package/src/features/Ordering.ts +0 -133
  99. package/src/features/Pagination.ts +0 -325
  100. package/src/features/Pinning.ts +0 -198
  101. package/src/features/RowSelection.ts +0 -831
  102. package/src/features/Sorting.ts +0 -547
  103. package/src/features/Visibility.ts +0 -279
  104. package/src/filterTypes.ts +0 -251
  105. package/src/sortTypes.ts +0 -159
  106. package/src/types.ts +0 -331
  107. package/src/utils/columnFilterRowsFn.ts +0 -155
  108. package/src/utils/expandRowsFn.ts +0 -50
  109. package/src/utils/globalFilterRowsFn.ts +0 -122
  110. package/src/utils/groupRowsFn.ts +0 -194
  111. package/src/utils/paginateRowsFn.ts +0 -34
  112. package/src/utils/sortRowsFn.ts +0 -115
  113. package/src/utils.tsx +0 -195
@@ -0,0 +1,3982 @@
1
+ /**
2
+ * react-table
3
+ *
4
+ * Copyright (c) TanStack
5
+ *
6
+ * This source code is licensed under the MIT license found in the
7
+ * LICENSE.md file in the root directory of this source tree.
8
+ *
9
+ * @license MIT
10
+ */
11
+ 'use strict';
12
+
13
+ Object.defineProperty(exports, '__esModule', { value: true });
14
+
15
+ /**
16
+ * table-core
17
+ *
18
+ * Copyright (c) TanStack
19
+ *
20
+ * This source code is licensed under the MIT license found in the
21
+ * LICENSE.md file in the root directory of this source tree.
22
+ *
23
+ * @license MIT
24
+ */
25
+ function functionalUpdate(updater, input) {
26
+ return typeof updater === 'function' ? updater(input) : updater;
27
+ }
28
+ function noop() {//
29
+ }
30
+ function makeStateUpdater(key, instance) {
31
+ return updater => {
32
+ instance.setState(old => {
33
+ return { ...old,
34
+ [key]: functionalUpdate(updater, old[key])
35
+ };
36
+ });
37
+ };
38
+ }
39
+ function isFunction(d) {
40
+ return d instanceof Function;
41
+ }
42
+ function flattenBy(arr, getChildren) {
43
+ const flat = [];
44
+
45
+ const recurse = subArr => {
46
+ subArr.forEach(item => {
47
+ flat.push(item);
48
+ const children = getChildren(item);
49
+
50
+ if (children != null && children.length) {
51
+ recurse(children);
52
+ }
53
+ });
54
+ };
55
+
56
+ recurse(arr);
57
+ return flat;
58
+ }
59
+ function memo(getDeps, fn, opts) {
60
+ let deps = [];
61
+ let result;
62
+ return () => {
63
+ let depTime;
64
+ if (opts.key && opts.debug) depTime = Date.now();
65
+ const newDeps = getDeps();
66
+ const depsChanged = newDeps.length !== deps.length || newDeps.some((dep, index) => deps[index] !== dep);
67
+
68
+ if (!depsChanged) {
69
+ return result;
70
+ }
71
+
72
+ deps = newDeps;
73
+ let resultTime;
74
+ if (opts.key && opts.debug) resultTime = Date.now();
75
+ result = fn(...newDeps);
76
+ opts == null ? void 0 : opts.onChange == null ? void 0 : opts.onChange(result);
77
+
78
+ if (opts.key && opts.debug) {
79
+ if (opts != null && opts.debug()) {
80
+ const depEndTime = Math.round((Date.now() - depTime) * 100) / 100;
81
+ const resultEndTime = Math.round((Date.now() - resultTime) * 100) / 100;
82
+ const resultFpsPercentage = resultEndTime / 16;
83
+
84
+ const pad = (str, num) => {
85
+ str = String(str);
86
+
87
+ while (str.length < num) {
88
+ str = ' ' + str;
89
+ }
90
+
91
+ return str;
92
+ };
93
+
94
+ console.info("%c\u23F1 " + pad(resultEndTime, 5) + " /" + pad(depEndTime, 5) + " ms", "\n font-size: .6rem;\n font-weight: bold;\n color: hsl(" + Math.max(0, Math.min(120 - 120 * resultFpsPercentage, 120)) + "deg 100% 31%);", opts == null ? void 0 : opts.key);
95
+ }
96
+ }
97
+
98
+ return result;
99
+ };
100
+ }
101
+
102
+ //
103
+ const Columns = {
104
+ createInstance: instance => {
105
+ return {
106
+ getDefaultColumnDef: memo(() => [instance.options.defaultColumnDef], defaultColumn => {
107
+ var _defaultColumn;
108
+
109
+ defaultColumn = (_defaultColumn = defaultColumn) != null ? _defaultColumn : {};
110
+ return {
111
+ header: props => props.header.column.id,
112
+ footer: props => props.header.column.id,
113
+ cell: props => {
114
+ var _props$getValue$toStr, _props$getValue$toStr2, _props$getValue;
115
+
116
+ return (_props$getValue$toStr = (_props$getValue$toStr2 = (_props$getValue = props.getValue()).toString) == null ? void 0 : _props$getValue$toStr2.call(_props$getValue)) != null ? _props$getValue$toStr : null;
117
+ },
118
+ ...instance._features.reduce((obj, feature) => {
119
+ return Object.assign(obj, feature.getDefaultColumnDef == null ? void 0 : feature.getDefaultColumnDef());
120
+ }, {}),
121
+ ...defaultColumn
122
+ };
123
+ }, {
124
+ debug: () => {
125
+ var _instance$options$deb;
126
+
127
+ return (_instance$options$deb = instance.options.debugAll) != null ? _instance$options$deb : instance.options.debugColumns;
128
+ },
129
+ key: process.env.NODE_ENV === 'development' && 'getDefaultColumnDef'
130
+ }),
131
+ getColumnDefs: () => instance.options.columns,
132
+ createColumn: (columnDef, depth, parent) => {
133
+ var _ref, _columnDef$id;
134
+
135
+ const defaultColumnDef = instance.getDefaultColumnDef();
136
+ columnDef = { ...defaultColumnDef,
137
+ ...columnDef
138
+ };
139
+ let id = (_ref = (_columnDef$id = columnDef.id) != null ? _columnDef$id : columnDef.accessorKey) != null ? _ref : typeof columnDef.header === 'string' ? columnDef.header : undefined;
140
+ let accessorFn;
141
+
142
+ if (columnDef.accessorFn) {
143
+ accessorFn = columnDef.accessorFn;
144
+ } else if (columnDef.accessorKey) {
145
+ accessorFn = originalRow => originalRow[columnDef.accessorKey];
146
+ }
147
+
148
+ if (!id) {
149
+ if (process.env.NODE_ENV !== 'production') {
150
+ throw new Error(columnDef.accessorFn ? "Columns require an id when using an accessorFn" : "Columns require an id when using a non-string header");
151
+ }
152
+
153
+ throw new Error();
154
+ }
155
+
156
+ let column = { ...columnDef,
157
+ id: "" + id,
158
+ accessorFn,
159
+ parent: parent,
160
+ depth,
161
+ columnDef,
162
+ columnDefType: columnDef.columnDefType,
163
+ columns: [],
164
+ getFlatColumns: memo(() => [true], () => {
165
+ var _column$columns;
166
+
167
+ return [column, ...((_column$columns = column.columns) == null ? void 0 : _column$columns.flatMap(d => d.getFlatColumns()))];
168
+ }, {
169
+ key: process.env.NODE_ENV === 'production' && 'column.getFlatColumns',
170
+ debug: () => {
171
+ var _instance$options$deb2;
172
+
173
+ return (_instance$options$deb2 = instance.options.debugAll) != null ? _instance$options$deb2 : instance.options.debugColumns;
174
+ }
175
+ }),
176
+ getLeafColumns: memo(() => [instance._getOrderColumnsFn()], orderColumns => {
177
+ var _column$columns2;
178
+
179
+ if ((_column$columns2 = column.columns) != null && _column$columns2.length) {
180
+ let leafColumns = column.columns.flatMap(column => column.getLeafColumns());
181
+ return orderColumns(leafColumns);
182
+ }
183
+
184
+ return [column];
185
+ }, {
186
+ key: process.env.NODE_ENV === 'production' && 'column.getLeafColumns',
187
+ debug: () => {
188
+ var _instance$options$deb3;
189
+
190
+ return (_instance$options$deb3 = instance.options.debugAll) != null ? _instance$options$deb3 : instance.options.debugColumns;
191
+ }
192
+ })
193
+ };
194
+ column = instance._features.reduce((obj, feature) => {
195
+ return Object.assign(obj, feature.createColumn == null ? void 0 : feature.createColumn(column, instance));
196
+ }, column); // Yes, we have to convert instance to uknown, because we know more than the compiler here.
197
+
198
+ return column;
199
+ },
200
+ getAllColumns: memo(() => [instance.getColumnDefs()], columnDefs => {
201
+ const recurseColumns = function (columnDefs, parent, depth) {
202
+ if (depth === void 0) {
203
+ depth = 0;
204
+ }
205
+
206
+ return columnDefs.map(columnDef => {
207
+ const column = instance.createColumn(columnDef, depth, parent);
208
+ column.columns = columnDef.columns ? recurseColumns(columnDef.columns, column, depth + 1) : [];
209
+ return column;
210
+ });
211
+ };
212
+
213
+ return recurseColumns(columnDefs);
214
+ }, {
215
+ key: process.env.NODE_ENV === 'development' && 'getAllColumns',
216
+ debug: () => {
217
+ var _instance$options$deb4;
218
+
219
+ return (_instance$options$deb4 = instance.options.debugAll) != null ? _instance$options$deb4 : instance.options.debugColumns;
220
+ }
221
+ }),
222
+ getAllFlatColumns: memo(() => [instance.getAllColumns()], allColumns => {
223
+ return allColumns.flatMap(column => {
224
+ return column.getFlatColumns();
225
+ });
226
+ }, {
227
+ key: process.env.NODE_ENV === 'development' && 'getAllFlatColumns',
228
+ debug: () => {
229
+ var _instance$options$deb5;
230
+
231
+ return (_instance$options$deb5 = instance.options.debugAll) != null ? _instance$options$deb5 : instance.options.debugColumns;
232
+ }
233
+ }),
234
+ getAllFlatColumnsById: memo(() => [instance.getAllFlatColumns()], flatColumns => {
235
+ return flatColumns.reduce((acc, column) => {
236
+ acc[column.id] = column;
237
+ return acc;
238
+ }, {});
239
+ }, {
240
+ key: process.env.NODE_ENV === 'development' && 'getAllFlatColumnsById',
241
+ debug: () => {
242
+ var _instance$options$deb6;
243
+
244
+ return (_instance$options$deb6 = instance.options.debugAll) != null ? _instance$options$deb6 : instance.options.debugColumns;
245
+ }
246
+ }),
247
+ getAllLeafColumns: memo(() => [instance.getAllColumns(), instance._getOrderColumnsFn()], (allColumns, orderColumns) => {
248
+ let leafColumns = allColumns.flatMap(column => column.getLeafColumns());
249
+ return orderColumns(leafColumns);
250
+ }, {
251
+ key: process.env.NODE_ENV === 'development' && 'getAllLeafColumns',
252
+ debug: () => {
253
+ var _instance$options$deb7;
254
+
255
+ return (_instance$options$deb7 = instance.options.debugAll) != null ? _instance$options$deb7 : instance.options.debugColumns;
256
+ }
257
+ }),
258
+ getColumn: columnId => {
259
+ const column = instance.getAllFlatColumnsById()[columnId];
260
+
261
+ if (!column) {
262
+ if (process.env.NODE_ENV !== 'production') {
263
+ console.warn("[Table] Column with id " + columnId + " does not exist.");
264
+ }
265
+
266
+ throw new Error();
267
+ }
268
+
269
+ return column;
270
+ }
271
+ };
272
+ }
273
+ };
274
+
275
+ //
276
+ const Rows = {
277
+ // createRow: <TGenerics extends TableGenerics>(
278
+ // row: Row<TGenerics>,
279
+ // instance: TableInstance<TGenerics>
280
+ // ): CellsRow<TGenerics> => {
281
+ // return {}
282
+ // },
283
+ createInstance: instance => {
284
+ return {
285
+ getRowId: (row, index, parent) => {
286
+ var _instance$options$get;
287
+
288
+ return (_instance$options$get = instance.options.getRowId == null ? void 0 : instance.options.getRowId(row, index, parent)) != null ? _instance$options$get : "" + (parent ? [parent.id, index].join('.') : index);
289
+ },
290
+ createRow: (id, original, rowIndex, depth, subRows) => {
291
+ let row = {
292
+ id,
293
+ index: rowIndex,
294
+ original,
295
+ depth,
296
+ valuesCache: {},
297
+ getValue: columnId => {
298
+ if (row.valuesCache.hasOwnProperty(columnId)) {
299
+ return row.valuesCache[columnId];
300
+ }
301
+
302
+ const column = instance.getColumn(columnId);
303
+
304
+ if (!column.accessorFn) {
305
+ return undefined;
306
+ }
307
+
308
+ row.valuesCache[columnId] = column.accessorFn(row.original, rowIndex);
309
+ return row.valuesCache[columnId];
310
+ },
311
+ subRows: subRows != null ? subRows : [],
312
+ getLeafRows: () => flattenBy(row.subRows, d => d.subRows)
313
+ };
314
+
315
+ for (let i = 0; i < instance._features.length; i++) {
316
+ const feature = instance._features[i];
317
+ Object.assign(row, feature == null ? void 0 : feature.createRow == null ? void 0 : feature.createRow(row, instance));
318
+ }
319
+
320
+ return row;
321
+ },
322
+ getCoreRowModel: () => {
323
+ if (!instance._getCoreRowModel) {
324
+ instance._getCoreRowModel = instance.options.getCoreRowModel(instance);
325
+ }
326
+
327
+ return instance._getCoreRowModel();
328
+ },
329
+ // The final calls start at the bottom of the model,
330
+ // expanded rows, which then work their way up
331
+ getRowModel: () => {
332
+ return instance.getPaginationRowModel();
333
+ },
334
+ getRow: id => {
335
+ const row = instance.getRowModel().rowsById[id];
336
+
337
+ if (!row) {
338
+ if (process.env.NODE_ENV !== 'production') {
339
+ throw new Error("getRow expected an ID, but got " + id);
340
+ }
341
+
342
+ throw new Error();
343
+ }
344
+
345
+ return row;
346
+ }
347
+ };
348
+ }
349
+ };
350
+
351
+ //
352
+ const Cells = {
353
+ createRow: (row, instance) => {
354
+ return {
355
+ getAllCells: memo(() => [instance.getAllLeafColumns()], leafColumns => {
356
+ return leafColumns.map(column => {
357
+ return instance.createCell(row, column, column.id);
358
+ });
359
+ }, {
360
+ key: process.env.NODE_ENV === 'development' && 'row.getAllCells',
361
+ debug: () => {
362
+ var _instance$options$deb;
363
+
364
+ return (_instance$options$deb = instance.options.debugAll) != null ? _instance$options$deb : instance.options.debugRows;
365
+ }
366
+ }),
367
+ getAllCellsByColumnId: memo(() => [row.getAllCells()], allCells => {
368
+ return allCells.reduce((acc, cell) => {
369
+ acc[cell.columnId] = cell;
370
+ return acc;
371
+ }, {});
372
+ }, {
373
+ key: process.env.NODE_ENV === 'production' && 'row.getAllCellsByColumnId',
374
+ debug: () => {
375
+ var _instance$options$deb2;
376
+
377
+ return (_instance$options$deb2 = instance.options.debugAll) != null ? _instance$options$deb2 : instance.options.debugRows;
378
+ }
379
+ })
380
+ };
381
+ },
382
+ createInstance: instance => {
383
+ return {
384
+ createCell: (row, column, columnId) => {
385
+ const cell = {
386
+ id: row.id + "_" + column.id,
387
+ rowId: row.id,
388
+ columnId,
389
+ row,
390
+ column,
391
+ getValue: () => row.getValue(columnId),
392
+ renderCell: () => column.columnDef.cell ? instance._render(column.columnDef.cell, {
393
+ instance,
394
+ column,
395
+ row,
396
+ cell: cell,
397
+ getValue: cell.getValue
398
+ }) : null
399
+ };
400
+
401
+ instance._features.forEach(feature => {
402
+ Object.assign(cell, feature.createCell == null ? void 0 : feature.createCell(cell, column, row, instance));
403
+ }, {});
404
+
405
+ return cell;
406
+ },
407
+ getCell: (rowId, columnId) => {
408
+ const row = instance.getRow(rowId);
409
+
410
+ if (!row) {
411
+ if (process.env.NODE_ENV !== 'production') {
412
+ throw new Error("[Table] could not find row with id " + rowId);
413
+ }
414
+
415
+ throw new Error();
416
+ }
417
+
418
+ const cell = row.getAllCellsByColumnId()[columnId];
419
+
420
+ if (!cell) {
421
+ if (process.env.NODE_ENV !== 'production') {
422
+ throw new Error("[Table] could not find cell " + columnId + " in row " + rowId);
423
+ }
424
+
425
+ throw new Error();
426
+ }
427
+
428
+ return cell;
429
+ }
430
+ };
431
+ }
432
+ };
433
+
434
+ //
435
+ const defaultColumnSizing = {
436
+ size: 150,
437
+ minSize: 20,
438
+ maxSize: Number.MAX_SAFE_INTEGER
439
+ };
440
+
441
+ const getDefaultColumnSizingInfoState = () => ({
442
+ startOffset: null,
443
+ startSize: null,
444
+ deltaOffset: null,
445
+ deltaPercentage: null,
446
+ isResizingColumn: false,
447
+ columnSizingStart: []
448
+ });
449
+
450
+ const ColumnSizing = {
451
+ getDefaultColumnDef: () => {
452
+ return defaultColumnSizing;
453
+ },
454
+ getInitialState: state => {
455
+ return {
456
+ columnSizing: {},
457
+ columnSizingInfo: getDefaultColumnSizingInfoState(),
458
+ ...state
459
+ };
460
+ },
461
+ getDefaultOptions: instance => {
462
+ return {
463
+ columnResizeMode: 'onEnd',
464
+ onColumnSizingChange: makeStateUpdater('columnSizing', instance),
465
+ onColumnSizingInfoChange: makeStateUpdater('columnSizingInfo', instance)
466
+ };
467
+ },
468
+ createColumn: (column, instance) => {
469
+ return {
470
+ getSize: () => {
471
+ var _column$columnDef$min, _ref, _column$columnDef$max;
472
+
473
+ const columnSize = instance.getState().columnSizing[column.id];
474
+ return Math.min(Math.max((_column$columnDef$min = column.columnDef.minSize) != null ? _column$columnDef$min : defaultColumnSizing.minSize, (_ref = columnSize != null ? columnSize : column.columnDef.size) != null ? _ref : defaultColumnSizing.size), (_column$columnDef$max = column.columnDef.maxSize) != null ? _column$columnDef$max : defaultColumnSizing.maxSize);
475
+ },
476
+ getStart: position => {
477
+ const columns = !position ? instance.getVisibleLeafColumns() : position === 'left' ? instance.getLeftVisibleLeafColumns() : instance.getRightVisibleLeafColumns();
478
+ const index = columns.findIndex(d => d.id === column.id);
479
+
480
+ if (index > 0) {
481
+ const prevSiblingColumn = columns[index - 1];
482
+ return prevSiblingColumn.getStart(position) + prevSiblingColumn.getSize();
483
+ }
484
+
485
+ return 0;
486
+ },
487
+ resetSize: () => {
488
+ instance.setColumnSizing(_ref2 => {
489
+ let {
490
+ [column.id]: _,
491
+ ...rest
492
+ } = _ref2;
493
+ return rest;
494
+ });
495
+ },
496
+ getCanResize: () => {
497
+ var _column$columnDef$ena, _instance$options$ena;
498
+
499
+ return ((_column$columnDef$ena = column.columnDef.enableResizing) != null ? _column$columnDef$ena : true) && ((_instance$options$ena = instance.options.enableColumnResizing) != null ? _instance$options$ena : true);
500
+ },
501
+ getIsResizing: () => {
502
+ return instance.getState().columnSizingInfo.isResizingColumn === column.id;
503
+ }
504
+ };
505
+ },
506
+ createHeader: (header, instance) => {
507
+ return {
508
+ getSize: () => {
509
+ let sum = 0;
510
+
511
+ const recurse = header => {
512
+ if (header.subHeaders.length) {
513
+ header.subHeaders.forEach(recurse);
514
+ } else {
515
+ var _header$column$getSiz;
516
+
517
+ sum += (_header$column$getSiz = header.column.getSize()) != null ? _header$column$getSiz : 0;
518
+ }
519
+ };
520
+
521
+ recurse(header);
522
+ return sum;
523
+ },
524
+ getStart: () => {
525
+ if (header.index > 0) {
526
+ const prevSiblingHeader = header.headerGroup.headers[header.index - 1];
527
+ return prevSiblingHeader.getStart() + prevSiblingHeader.getSize();
528
+ }
529
+
530
+ return 0;
531
+ },
532
+ getResizeHandler: () => {
533
+ const column = instance.getColumn(header.column.id);
534
+ const canResize = column.getCanResize();
535
+ return e => {
536
+ if (!canResize) {
537
+ return;
538
+ }
539
+ e.persist == null ? void 0 : e.persist();
540
+
541
+ if (isTouchStartEvent(e)) {
542
+ // lets not respond to multiple touches (e.g. 2 or 3 fingers)
543
+ if (e.touches && e.touches.length > 1) {
544
+ return;
545
+ }
546
+ }
547
+
548
+ const startSize = header.getSize();
549
+ const columnSizingStart = header ? header.getLeafHeaders().map(d => [d.column.id, d.column.getSize()]) : [[column.id, column.getSize()]];
550
+ const clientX = isTouchStartEvent(e) ? Math.round(e.touches[0].clientX) : e.clientX;
551
+
552
+ const updateOffset = (eventType, clientXPos) => {
553
+ if (typeof clientXPos !== 'number') {
554
+ return;
555
+ }
556
+
557
+ let newColumnSizing = {};
558
+ instance.setColumnSizingInfo(old => {
559
+ var _old$startOffset, _old$startSize;
560
+
561
+ const deltaOffset = clientXPos - ((_old$startOffset = old == null ? void 0 : old.startOffset) != null ? _old$startOffset : 0);
562
+ const deltaPercentage = Math.max(deltaOffset / ((_old$startSize = old == null ? void 0 : old.startSize) != null ? _old$startSize : 0), -0.999999);
563
+ old.columnSizingStart.forEach(_ref3 => {
564
+ let [columnId, headerSize] = _ref3;
565
+ newColumnSizing[columnId] = Math.round(Math.max(headerSize + headerSize * deltaPercentage, 0) * 100) / 100;
566
+ });
567
+ return { ...old,
568
+ deltaOffset,
569
+ deltaPercentage
570
+ };
571
+ });
572
+
573
+ if (instance.options.columnResizeMode === 'onChange' || eventType === 'end') {
574
+ instance.setColumnSizing(old => ({ ...old,
575
+ ...newColumnSizing
576
+ }));
577
+ }
578
+ };
579
+
580
+ const onMove = clientXPos => updateOffset('move', clientXPos);
581
+
582
+ const onEnd = clientXPos => {
583
+ updateOffset('end', clientXPos);
584
+ instance.setColumnSizingInfo(old => ({ ...old,
585
+ isResizingColumn: false,
586
+ startOffset: null,
587
+ startSize: null,
588
+ deltaOffset: null,
589
+ deltaPercentage: null,
590
+ columnSizingStart: []
591
+ }));
592
+ };
593
+
594
+ const mouseEvents = {
595
+ moveHandler: e => onMove(e.clientX),
596
+ upHandler: e => {
597
+ document.removeEventListener('mousemove', mouseEvents.moveHandler);
598
+ document.removeEventListener('mouseup', mouseEvents.upHandler);
599
+ onEnd(e.clientX);
600
+ }
601
+ };
602
+ const passiveIfSupported = passiveEventSupported() ? {
603
+ passive: false
604
+ } : false;
605
+
606
+ if (isTouchStartEvent(e)) ; else {
607
+ document.addEventListener('mousemove', mouseEvents.moveHandler, passiveIfSupported);
608
+ document.addEventListener('mouseup', mouseEvents.upHandler, passiveIfSupported);
609
+ }
610
+
611
+ instance.setColumnSizingInfo(old => ({ ...old,
612
+ startOffset: clientX,
613
+ startSize,
614
+ deltaOffset: 0,
615
+ deltaPercentage: 0,
616
+ columnSizingStart,
617
+ isResizingColumn: column.id
618
+ }));
619
+ };
620
+ }
621
+ };
622
+ },
623
+ createInstance: instance => {
624
+ return {
625
+ setColumnSizing: updater => instance.options.onColumnSizingChange == null ? void 0 : instance.options.onColumnSizingChange(updater),
626
+ setColumnSizingInfo: updater => instance.options.onColumnSizingInfoChange == null ? void 0 : instance.options.onColumnSizingInfoChange(updater),
627
+ resetColumnSizing: defaultState => {
628
+ var _instance$initialStat;
629
+
630
+ instance.setColumnSizing(defaultState ? {} : (_instance$initialStat = instance.initialState.columnSizing) != null ? _instance$initialStat : {});
631
+ },
632
+ resetHeaderSizeInfo: defaultState => {
633
+ var _instance$initialStat2;
634
+
635
+ instance.setColumnSizingInfo(defaultState ? getDefaultColumnSizingInfoState() : (_instance$initialStat2 = instance.initialState.columnSizingInfo) != null ? _instance$initialStat2 : getDefaultColumnSizingInfoState());
636
+ },
637
+ getTotalSize: () => {
638
+ var _instance$getHeaderGr, _instance$getHeaderGr2;
639
+
640
+ return (_instance$getHeaderGr = (_instance$getHeaderGr2 = instance.getHeaderGroups()[0]) == null ? void 0 : _instance$getHeaderGr2.headers.reduce((sum, header) => {
641
+ return sum + header.getSize();
642
+ }, 0)) != null ? _instance$getHeaderGr : 0;
643
+ },
644
+ getLeftTotalSize: () => {
645
+ var _instance$getLeftHead, _instance$getLeftHead2;
646
+
647
+ return (_instance$getLeftHead = (_instance$getLeftHead2 = instance.getLeftHeaderGroups()[0]) == null ? void 0 : _instance$getLeftHead2.headers.reduce((sum, header) => {
648
+ return sum + header.getSize();
649
+ }, 0)) != null ? _instance$getLeftHead : 0;
650
+ },
651
+ getCenterTotalSize: () => {
652
+ var _instance$getCenterHe, _instance$getCenterHe2;
653
+
654
+ return (_instance$getCenterHe = (_instance$getCenterHe2 = instance.getCenterHeaderGroups()[0]) == null ? void 0 : _instance$getCenterHe2.headers.reduce((sum, header) => {
655
+ return sum + header.getSize();
656
+ }, 0)) != null ? _instance$getCenterHe : 0;
657
+ },
658
+ getRightTotalSize: () => {
659
+ var _instance$getRightHea, _instance$getRightHea2;
660
+
661
+ return (_instance$getRightHea = (_instance$getRightHea2 = instance.getRightHeaderGroups()[0]) == null ? void 0 : _instance$getRightHea2.headers.reduce((sum, header) => {
662
+ return sum + header.getSize();
663
+ }, 0)) != null ? _instance$getRightHea : 0;
664
+ }
665
+ };
666
+ }
667
+ };
668
+ let passiveSupported = null;
669
+ function passiveEventSupported() {
670
+ if (typeof passiveSupported === 'boolean') return passiveSupported;
671
+ let supported = false;
672
+
673
+ try {
674
+ const options = {
675
+ get passive() {
676
+ supported = true;
677
+ return false;
678
+ }
679
+
680
+ };
681
+
682
+ const noop = () => {};
683
+
684
+ window.addEventListener('test', noop, options);
685
+ window.removeEventListener('test', noop);
686
+ } catch (err) {
687
+ supported = false;
688
+ }
689
+
690
+ passiveSupported = supported;
691
+ return passiveSupported;
692
+ }
693
+
694
+ function isTouchStartEvent(e) {
695
+ return e.type === 'touchstart';
696
+ }
697
+
698
+ //
699
+ const Expanding = {
700
+ getInitialState: state => {
701
+ return {
702
+ expanded: {},
703
+ ...state
704
+ };
705
+ },
706
+ getDefaultOptions: instance => {
707
+ return {
708
+ onExpandedChange: makeStateUpdater('expanded', instance),
709
+ autoResetExpanded: true,
710
+ expandSubRows: true,
711
+ paginateExpandedRows: true
712
+ };
713
+ },
714
+ createInstance: instance => {
715
+ let registered = false;
716
+ let queued = false;
717
+ return {
718
+ _autoResetExpanded: () => {
719
+ if (!registered) {
720
+ instance._queue(() => {
721
+ registered = true;
722
+ });
723
+
724
+ return;
725
+ }
726
+
727
+ if (instance.options.autoResetAll === false) {
728
+ return;
729
+ }
730
+
731
+ if (instance.options.autoResetAll === true || instance.options.autoResetExpanded) {
732
+ if (queued) return;
733
+ queued = true;
734
+
735
+ instance._queue(() => {
736
+ instance.resetExpanded();
737
+ queued = false;
738
+ });
739
+ }
740
+ },
741
+ setExpanded: updater => instance.options.onExpandedChange == null ? void 0 : instance.options.onExpandedChange(updater),
742
+ toggleAllRowsExpanded: expanded => {
743
+ if (expanded != null ? expanded : !instance.getIsAllRowsExpanded()) {
744
+ instance.setExpanded(true);
745
+ } else {
746
+ instance.setExpanded({});
747
+ }
748
+ },
749
+ resetExpanded: defaultState => {
750
+ var _instance$initialStat, _instance$initialStat2;
751
+
752
+ instance.setExpanded(defaultState ? {} : (_instance$initialStat = (_instance$initialStat2 = instance.initialState) == null ? void 0 : _instance$initialStat2.expanded) != null ? _instance$initialStat : {});
753
+ },
754
+ getCanSomeRowsExpand: () => {
755
+ return instance.getRowModel().flatRows.some(row => row.getCanExpand());
756
+ },
757
+ getToggleAllRowsExpandedHandler: () => {
758
+ return e => {
759
+ e.persist == null ? void 0 : e.persist();
760
+ instance.toggleAllRowsExpanded();
761
+ };
762
+ },
763
+ getIsSomeRowsExpanded: () => {
764
+ const expanded = instance.getState().expanded;
765
+ return expanded === true || Object.values(expanded).some(Boolean);
766
+ },
767
+ getIsAllRowsExpanded: () => {
768
+ const expanded = instance.getState().expanded; // If expanded is true, save some cycles and return true
769
+
770
+ if (expanded === true) {
771
+ return true;
772
+ } // If any row is not expanded, return false
773
+
774
+
775
+ if (instance.getRowModel().flatRows.some(row => row.getIsExpanded())) {
776
+ return false;
777
+ } // They must all be expanded :shrug:
778
+
779
+
780
+ return true;
781
+ },
782
+ getExpandedDepth: () => {
783
+ let maxDepth = 0;
784
+ const rowIds = instance.getState().expanded === true ? Object.keys(instance.getRowModel().rowsById) : Object.keys(instance.getState().expanded);
785
+ rowIds.forEach(id => {
786
+ const splitId = id.split('.');
787
+ maxDepth = Math.max(maxDepth, splitId.length);
788
+ });
789
+ return maxDepth;
790
+ },
791
+ getPreExpandedRowModel: () => instance.getGroupedRowModel(),
792
+ getExpandedRowModel: () => {
793
+ if (!instance._getExpandedRowModel && instance.options.getExpandedRowModel) {
794
+ instance._getExpandedRowModel = instance.options.getExpandedRowModel(instance);
795
+ }
796
+
797
+ if (instance.options.manualExpanding || !instance._getExpandedRowModel) {
798
+ return instance.getPreExpandedRowModel();
799
+ }
800
+
801
+ return instance._getExpandedRowModel();
802
+ }
803
+ };
804
+ },
805
+ createRow: (row, instance) => {
806
+ return {
807
+ toggleExpanded: expanded => {
808
+ instance.setExpanded(old => {
809
+ var _expanded;
810
+
811
+ const exists = old === true ? true : !!(old != null && old[row.id]);
812
+ let oldExpanded = {};
813
+
814
+ if (old === true) {
815
+ Object.keys(instance.getRowModel().rowsById).forEach(rowId => {
816
+ oldExpanded[rowId] = true;
817
+ });
818
+ } else {
819
+ oldExpanded = old;
820
+ }
821
+
822
+ expanded = (_expanded = expanded) != null ? _expanded : !exists;
823
+
824
+ if (!exists && expanded) {
825
+ return { ...oldExpanded,
826
+ [row.id]: true
827
+ };
828
+ }
829
+
830
+ if (exists && !expanded) {
831
+ const {
832
+ [row.id]: _,
833
+ ...rest
834
+ } = oldExpanded;
835
+ return rest;
836
+ }
837
+
838
+ return old;
839
+ });
840
+ },
841
+ getIsExpanded: () => {
842
+ var _instance$options$get;
843
+
844
+ const expanded = instance.getState().expanded;
845
+ return !!((_instance$options$get = instance.options.getIsRowExpanded == null ? void 0 : instance.options.getIsRowExpanded(row)) != null ? _instance$options$get : expanded === true || (expanded == null ? void 0 : expanded[row.id]));
846
+ },
847
+ getCanExpand: () => {
848
+ var _instance$options$get2, _instance$options$ena, _row$subRows;
849
+
850
+ return ((_instance$options$get2 = instance.options.getRowCanExpand == null ? void 0 : instance.options.getRowCanExpand(row)) != null ? _instance$options$get2 : true) && ((_instance$options$ena = instance.options.enableExpanding) != null ? _instance$options$ena : true) && !!((_row$subRows = row.subRows) != null && _row$subRows.length);
851
+ },
852
+ getToggleExpandedHandler: () => {
853
+ const canExpand = row.getCanExpand();
854
+ return () => {
855
+ if (!canExpand) return;
856
+ row.toggleExpanded();
857
+ };
858
+ }
859
+ };
860
+ }
861
+ };
862
+
863
+ const includesString = (row, columnId, filterValue) => {
864
+ const search = filterValue.toLowerCase();
865
+ return row.getValue(columnId).toLowerCase().includes(search);
866
+ };
867
+
868
+ includesString.autoRemove = val => testFalsey(val);
869
+
870
+ const includesStringSensitive = (row, columnId, filterValue) => {
871
+ return row.getValue(columnId).includes(filterValue);
872
+ };
873
+
874
+ includesStringSensitive.autoRemove = val => testFalsey(val);
875
+
876
+ const equalsString = (row, columnId, filterValue) => {
877
+ return row.getValue(columnId).toLowerCase() === filterValue.toLowerCase();
878
+ };
879
+
880
+ equalsString.autoRemove = val => testFalsey(val);
881
+
882
+ const arrIncludes = (row, columnId, filterValue) => {
883
+ return row.getValue(columnId).includes(filterValue);
884
+ };
885
+
886
+ arrIncludes.autoRemove = val => testFalsey(val) || !(val != null && val.length);
887
+
888
+ const arrIncludesAll = (row, columnId, filterValue) => {
889
+ return !filterValue.some(val => !row.getValue(columnId).includes(val));
890
+ };
891
+
892
+ arrIncludesAll.autoRemove = val => testFalsey(val) || !(val != null && val.length);
893
+
894
+ const arrIncludesSome = (row, columnId, filterValue) => {
895
+ return filterValue.some(val => row.getValue(columnId).includes(val));
896
+ };
897
+
898
+ arrIncludesSome.autoRemove = val => testFalsey(val) || !(val != null && val.length);
899
+
900
+ const equals = (row, columnId, filterValue) => {
901
+ return row.getValue(columnId) === filterValue;
902
+ };
903
+
904
+ equals.autoRemove = val => testFalsey(val);
905
+
906
+ const weakEquals = (row, columnId, filterValue) => {
907
+ return row.getValue(columnId) == filterValue;
908
+ };
909
+
910
+ weakEquals.autoRemove = val => testFalsey(val);
911
+
912
+ const inNumberRange = (row, columnId, filterValue) => {
913
+ let [min, max] = filterValue;
914
+ const rowValue = row.getValue(columnId);
915
+ return rowValue >= min && rowValue <= max;
916
+ };
917
+
918
+ inNumberRange.resolveFilterValue = val => {
919
+ let [unsafeMin, unsafeMax] = val;
920
+ let parsedMin = typeof unsafeMin !== 'number' ? parseFloat(unsafeMin) : unsafeMin;
921
+ let parsedMax = typeof unsafeMax !== 'number' ? parseFloat(unsafeMax) : unsafeMax;
922
+ let min = unsafeMin === null || Number.isNaN(parsedMin) ? -Infinity : parsedMin;
923
+ let max = unsafeMax === null || Number.isNaN(parsedMax) ? Infinity : parsedMax;
924
+
925
+ if (min > max) {
926
+ const temp = min;
927
+ min = max;
928
+ max = temp;
929
+ }
930
+
931
+ return [min, max];
932
+ };
933
+
934
+ inNumberRange.autoRemove = val => testFalsey(val) || testFalsey(val[0]) && testFalsey(val[1]); // Export
935
+
936
+
937
+ const filterFns = {
938
+ includesString,
939
+ includesStringSensitive,
940
+ equalsString,
941
+ arrIncludes,
942
+ arrIncludesAll,
943
+ arrIncludesSome,
944
+ equals,
945
+ weakEquals,
946
+ inNumberRange
947
+ };
948
+
949
+ // Utils
950
+ function testFalsey(val) {
951
+ return val === undefined || val === null || val === '';
952
+ }
953
+
954
+ //
955
+ const Filters = {
956
+ getDefaultColumnDef: () => {
957
+ return {
958
+ filterFn: 'auto'
959
+ };
960
+ },
961
+ getInitialState: state => {
962
+ return {
963
+ columnFilters: [],
964
+ globalFilter: undefined,
965
+ // filtersProgress: 1,
966
+ // facetProgress: {},
967
+ ...state
968
+ };
969
+ },
970
+ getDefaultOptions: instance => {
971
+ return {
972
+ onColumnFiltersChange: makeStateUpdater('columnFilters', instance),
973
+ onGlobalFilterChange: makeStateUpdater('globalFilter', instance),
974
+ filterFromLeafRows: false,
975
+ globalFilterFn: 'auto',
976
+ getColumnCanGlobalFilter: column => {
977
+ var _instance$getCoreRowM, _instance$getCoreRowM2;
978
+
979
+ const value = (_instance$getCoreRowM = instance.getCoreRowModel().flatRows[0]) == null ? void 0 : (_instance$getCoreRowM2 = _instance$getCoreRowM.getAllCellsByColumnId()[column.id]) == null ? void 0 : _instance$getCoreRowM2.getValue();
980
+ return typeof value === 'string';
981
+ }
982
+ };
983
+ },
984
+ createColumn: (column, instance) => {
985
+ return {
986
+ filterFn: column.filterFn,
987
+ getAutoFilterFn: () => {
988
+ const firstRow = instance.getCoreRowModel().flatRows[0];
989
+ const value = firstRow == null ? void 0 : firstRow.getValue(column.id);
990
+
991
+ if (typeof value === 'string') {
992
+ return filterFns.includesString;
993
+ }
994
+
995
+ if (typeof value === 'number') {
996
+ return filterFns.inNumberRange;
997
+ }
998
+
999
+ if (typeof value === 'boolean') {
1000
+ return filterFns.equals;
1001
+ }
1002
+
1003
+ if (value !== null && typeof value === 'object') {
1004
+ return filterFns.equals;
1005
+ }
1006
+
1007
+ if (Array.isArray(value)) {
1008
+ return filterFns.arrIncludes;
1009
+ }
1010
+
1011
+ return filterFns.weakEquals;
1012
+ },
1013
+ getFilterFn: () => {
1014
+ var _ref;
1015
+
1016
+ const userFilterFns = instance.options.filterFns;
1017
+ return isFunction(column.filterFn) ? column.filterFn : column.filterFn === 'auto' ? column.getAutoFilterFn() : (_ref = userFilterFns == null ? void 0 : userFilterFns[column.filterFn]) != null ? _ref : filterFns[column.filterFn];
1018
+ },
1019
+ getCanFilter: () => {
1020
+ var _column$columnDef$ena, _instance$options$ena, _instance$options$ena2;
1021
+
1022
+ return ((_column$columnDef$ena = column.columnDef.enableColumnFilter) != null ? _column$columnDef$ena : true) && ((_instance$options$ena = instance.options.enableColumnFilters) != null ? _instance$options$ena : true) && ((_instance$options$ena2 = instance.options.enableFilters) != null ? _instance$options$ena2 : true) && !!column.accessorFn;
1023
+ },
1024
+ getCanGlobalFilter: () => {
1025
+ var _column$columnDef$ena2, _instance$options$ena3, _instance$options$ena4, _instance$options$get;
1026
+
1027
+ return ((_column$columnDef$ena2 = column.columnDef.enableGlobalFilter) != null ? _column$columnDef$ena2 : true) && ((_instance$options$ena3 = instance.options.enableGlobalFilter) != null ? _instance$options$ena3 : true) && ((_instance$options$ena4 = instance.options.enableFilters) != null ? _instance$options$ena4 : true) && ((_instance$options$get = instance.options.getColumnCanGlobalFilter == null ? void 0 : instance.options.getColumnCanGlobalFilter(column)) != null ? _instance$options$get : true) && !!column.accessorFn;
1028
+ },
1029
+ getIsFiltered: () => column.getFilterIndex() > -1,
1030
+ getFilterValue: () => {
1031
+ var _instance$getState$co, _instance$getState$co2;
1032
+
1033
+ return (_instance$getState$co = instance.getState().columnFilters) == null ? void 0 : (_instance$getState$co2 = _instance$getState$co.find(d => d.id === column.id)) == null ? void 0 : _instance$getState$co2.value;
1034
+ },
1035
+ getFilterIndex: () => {
1036
+ var _instance$getState$co3, _instance$getState$co4;
1037
+
1038
+ return (_instance$getState$co3 = (_instance$getState$co4 = instance.getState().columnFilters) == null ? void 0 : _instance$getState$co4.findIndex(d => d.id === column.id)) != null ? _instance$getState$co3 : -1;
1039
+ },
1040
+ setFilterValue: value => {
1041
+ instance.setColumnFilters(old => {
1042
+ const filterFn = column.getFilterFn();
1043
+ const previousfilter = old == null ? void 0 : old.find(d => d.id === column.id);
1044
+ const newFilter = functionalUpdate(value, previousfilter ? previousfilter.value : undefined); //
1045
+
1046
+ if (shouldAutoRemoveFilter(filterFn, newFilter, column)) {
1047
+ var _old$filter;
1048
+
1049
+ return (_old$filter = old == null ? void 0 : old.filter(d => d.id !== column.id)) != null ? _old$filter : [];
1050
+ }
1051
+
1052
+ const newFilterObj = {
1053
+ id: column.id,
1054
+ value: newFilter
1055
+ };
1056
+
1057
+ if (previousfilter) {
1058
+ var _old$map;
1059
+
1060
+ return (_old$map = old == null ? void 0 : old.map(d => {
1061
+ if (d.id === column.id) {
1062
+ return newFilterObj;
1063
+ }
1064
+
1065
+ return d;
1066
+ })) != null ? _old$map : [];
1067
+ }
1068
+
1069
+ if (old != null && old.length) {
1070
+ return [...old, newFilterObj];
1071
+ }
1072
+
1073
+ return [newFilterObj];
1074
+ });
1075
+ },
1076
+ _getFacetedRowModel: instance.options.getFacetedRowModel && instance.options.getFacetedRowModel(instance, column.id),
1077
+ getFacetedRowModel: () => {
1078
+ if (!column._getFacetedRowModel) {
1079
+ return instance.getPreFilteredRowModel();
1080
+ }
1081
+
1082
+ return column._getFacetedRowModel();
1083
+ },
1084
+ _getFacetedUniqueValues: instance.options.getFacetedUniqueValues && instance.options.getFacetedUniqueValues(instance, column.id),
1085
+ getFacetedUniqueValues: () => {
1086
+ if (!column._getFacetedUniqueValues) {
1087
+ return new Map();
1088
+ }
1089
+
1090
+ return column._getFacetedUniqueValues();
1091
+ },
1092
+ _getFacetedMinMaxValues: instance.options.getFacetedMinMaxValues && instance.options.getFacetedMinMaxValues(instance, column.id),
1093
+ getFacetedMinMaxValues: () => {
1094
+ if (!column._getFacetedMinMaxValues) {
1095
+ return undefined;
1096
+ }
1097
+
1098
+ return column._getFacetedMinMaxValues();
1099
+ } // () => [column.getFacetedRowModel()],
1100
+ // facetedRowModel => getRowModelMinMaxValues(facetedRowModel, column.id),
1101
+
1102
+ };
1103
+ },
1104
+ createRow: (row, instance) => {
1105
+ return {
1106
+ columnFilters: {},
1107
+ columnFiltersMeta: {},
1108
+ subRowsByFacetId: {}
1109
+ };
1110
+ },
1111
+ createInstance: instance => {
1112
+ return {
1113
+ getGlobalAutoFilterFn: () => {
1114
+ return filterFns.includesString;
1115
+ },
1116
+ getGlobalFilterFn: () => {
1117
+ var _ref2;
1118
+
1119
+ const {
1120
+ filterFns: userFilterFns,
1121
+ globalFilterFn: globalFilterFn
1122
+ } = instance.options;
1123
+ return isFunction(globalFilterFn) ? globalFilterFn : globalFilterFn === 'auto' ? instance.getGlobalAutoFilterFn() : (_ref2 = userFilterFns == null ? void 0 : userFilterFns[globalFilterFn]) != null ? _ref2 : filterFns[globalFilterFn];
1124
+ },
1125
+ setColumnFilters: updater => {
1126
+ const leafColumns = instance.getAllLeafColumns();
1127
+
1128
+ const updateFn = old => {
1129
+ var _functionalUpdate;
1130
+
1131
+ return (_functionalUpdate = functionalUpdate(updater, old)) == null ? void 0 : _functionalUpdate.filter(filter => {
1132
+ const column = leafColumns.find(d => d.id === filter.id);
1133
+
1134
+ if (column) {
1135
+ const filterFn = column.getFilterFn();
1136
+
1137
+ if (shouldAutoRemoveFilter(filterFn, filter.value, column)) {
1138
+ return false;
1139
+ }
1140
+ }
1141
+
1142
+ return true;
1143
+ });
1144
+ };
1145
+
1146
+ instance.options.onColumnFiltersChange == null ? void 0 : instance.options.onColumnFiltersChange(updateFn);
1147
+ },
1148
+ setGlobalFilter: updater => {
1149
+ instance.options.onGlobalFilterChange == null ? void 0 : instance.options.onGlobalFilterChange(updater);
1150
+ },
1151
+ resetGlobalFilter: defaultState => {
1152
+ instance.setGlobalFilter(defaultState ? undefined : instance.initialState.globalFilter);
1153
+ },
1154
+ resetColumnFilters: defaultState => {
1155
+ var _instance$initialStat, _instance$initialStat2;
1156
+
1157
+ instance.setColumnFilters(defaultState ? [] : (_instance$initialStat = (_instance$initialStat2 = instance.initialState) == null ? void 0 : _instance$initialStat2.columnFilters) != null ? _instance$initialStat : []);
1158
+ },
1159
+ getPreFilteredRowModel: () => instance.getCoreRowModel(),
1160
+ _getFilteredRowModel: instance.options.getFilteredRowModel && instance.options.getFilteredRowModel(instance),
1161
+ getFilteredRowModel: () => {
1162
+ if (instance.options.manualFiltering || !instance._getFilteredRowModel) {
1163
+ return instance.getPreFilteredRowModel();
1164
+ }
1165
+
1166
+ return instance._getFilteredRowModel();
1167
+ },
1168
+ _getGlobalFacetedRowModel: instance.options.getFacetedRowModel && instance.options.getFacetedRowModel(instance, '__global__'),
1169
+ getGlobalFacetedRowModel: () => {
1170
+ if (instance.options.manualFiltering || !instance._getGlobalFacetedRowModel) {
1171
+ return instance.getPreFilteredRowModel();
1172
+ }
1173
+
1174
+ return instance._getGlobalFacetedRowModel();
1175
+ },
1176
+ _getGlobalFacetedUniqueValues: instance.options.getFacetedUniqueValues && instance.options.getFacetedUniqueValues(instance, '__global__'),
1177
+ getGlobalFacetedUniqueValues: () => {
1178
+ if (!instance._getGlobalFacetedUniqueValues) {
1179
+ return new Map();
1180
+ }
1181
+
1182
+ return instance._getGlobalFacetedUniqueValues();
1183
+ },
1184
+ _getGlobalFacetedMinMaxValues: instance.options.getFacetedMinMaxValues && instance.options.getFacetedMinMaxValues(instance, '__global__'),
1185
+ getGlobalFacetedMinMaxValues: () => {
1186
+ if (!instance._getGlobalFacetedMinMaxValues) {
1187
+ return;
1188
+ }
1189
+
1190
+ return instance._getGlobalFacetedMinMaxValues();
1191
+ }
1192
+ };
1193
+ }
1194
+ };
1195
+ function shouldAutoRemoveFilter(filterFn, value, column) {
1196
+ return (filterFn && filterFn.autoRemove ? filterFn.autoRemove(value, column) : false) || typeof value === 'undefined' || typeof value === 'string' && !value;
1197
+ }
1198
+
1199
+ const aggregationFns = {
1200
+ sum,
1201
+ min,
1202
+ max,
1203
+ extent,
1204
+ mean,
1205
+ median,
1206
+ unique,
1207
+ uniqueCount,
1208
+ count
1209
+ };
1210
+
1211
+ function sum(_getLeafValues, getChildValues) {
1212
+ // It's faster to just add the aggregations together instead of
1213
+ // process leaf nodes individually
1214
+ return getChildValues().reduce((sum, next) => sum + (typeof next === 'number' ? next : 0), 0);
1215
+ }
1216
+
1217
+ function min(_getLeafValues, getChildValues) {
1218
+ let min;
1219
+
1220
+ for (const value of getChildValues()) {
1221
+ if (value != null && (min > value || min === undefined && value >= value)) {
1222
+ min = value;
1223
+ }
1224
+ }
1225
+
1226
+ return min;
1227
+ }
1228
+
1229
+ function max(_getLeafValues, getChildValues) {
1230
+ let max;
1231
+
1232
+ for (const value of getChildValues()) {
1233
+ if (value != null && (max < value || max === undefined && value >= value)) {
1234
+ max = value;
1235
+ }
1236
+ }
1237
+
1238
+ return max;
1239
+ }
1240
+
1241
+ function extent(_getLeafValues, getChildValues) {
1242
+ let min;
1243
+ let max;
1244
+
1245
+ for (const value of getChildValues()) {
1246
+ if (value != null) {
1247
+ if (min === undefined) {
1248
+ if (value >= value) min = max = value;
1249
+ } else {
1250
+ if (min > value) min = value;
1251
+ if (max < value) max = value;
1252
+ }
1253
+ }
1254
+ }
1255
+
1256
+ return [min, max];
1257
+ }
1258
+
1259
+ function mean(getLeafValues) {
1260
+ let count = 0;
1261
+ let sum = 0;
1262
+
1263
+ for (let value of getLeafValues()) {
1264
+ if (value != null && (value = +value) >= value) {
1265
+ ++count, sum += value;
1266
+ }
1267
+ }
1268
+
1269
+ if (count) return sum / count;
1270
+ return;
1271
+ }
1272
+
1273
+ function median(getLeafValues) {
1274
+ const leafValues = getLeafValues();
1275
+
1276
+ if (!leafValues.length) {
1277
+ return;
1278
+ }
1279
+
1280
+ let min = 0;
1281
+ let max = 0;
1282
+ leafValues.forEach(value => {
1283
+ if (typeof value === 'number') {
1284
+ min = Math.min(min, value);
1285
+ max = Math.max(max, value);
1286
+ }
1287
+ });
1288
+ return (min + max) / 2;
1289
+ }
1290
+
1291
+ function unique(getLeafValues) {
1292
+ return Array.from(new Set(getLeafValues()).values());
1293
+ }
1294
+
1295
+ function uniqueCount(getLeafValues) {
1296
+ return new Set(getLeafValues()).size;
1297
+ }
1298
+
1299
+ function count(getLeafValues) {
1300
+ return getLeafValues().length;
1301
+ }
1302
+
1303
+ //
1304
+ const Grouping = {
1305
+ getDefaultColumnDef: () => {
1306
+ return {
1307
+ aggregationFn: 'auto'
1308
+ };
1309
+ },
1310
+ getInitialState: state => {
1311
+ return {
1312
+ grouping: [],
1313
+ ...state
1314
+ };
1315
+ },
1316
+ getDefaultOptions: instance => {
1317
+ return {
1318
+ onGroupingChange: makeStateUpdater('grouping', instance),
1319
+ groupedColumnMode: 'reorder'
1320
+ };
1321
+ },
1322
+ createColumn: (column, instance) => {
1323
+ return {
1324
+ toggleGrouping: () => {
1325
+ instance.setGrouping(old => {
1326
+ // Find any existing grouping for this column
1327
+ if (old != null && old.includes(column.id)) {
1328
+ return old.filter(d => d !== column.id);
1329
+ }
1330
+
1331
+ return [...(old != null ? old : []), column.id];
1332
+ });
1333
+ },
1334
+ getCanGroup: () => {
1335
+ var _ref, _ref2, _ref3, _column$columnDef$ena;
1336
+
1337
+ return (_ref = (_ref2 = (_ref3 = (_column$columnDef$ena = column.columnDef.enableGrouping) != null ? _column$columnDef$ena : true) != null ? _ref3 : instance.options.enableGrouping) != null ? _ref2 : true) != null ? _ref : !!column.accessorFn;
1338
+ },
1339
+ getIsGrouped: () => {
1340
+ var _instance$getState$gr;
1341
+
1342
+ return (_instance$getState$gr = instance.getState().grouping) == null ? void 0 : _instance$getState$gr.includes(column.id);
1343
+ },
1344
+ getGroupedIndex: () => {
1345
+ var _instance$getState$gr2;
1346
+
1347
+ return (_instance$getState$gr2 = instance.getState().grouping) == null ? void 0 : _instance$getState$gr2.indexOf(column.id);
1348
+ },
1349
+ getToggleGroupingHandler: () => {
1350
+ const canGroup = column.getCanGroup();
1351
+ return () => {
1352
+ if (!canGroup) return;
1353
+ column.toggleGrouping();
1354
+ };
1355
+ },
1356
+ getColumnAutoAggregationFn: () => {
1357
+ const firstRow = instance.getCoreRowModel().flatRows[0];
1358
+ const value = firstRow == null ? void 0 : firstRow.getValue(column.id);
1359
+
1360
+ if (typeof value === 'number') {
1361
+ return aggregationFns.sum;
1362
+ }
1363
+
1364
+ if (Object.prototype.toString.call(value) === '[object Date]') {
1365
+ return aggregationFns.extent;
1366
+ }
1367
+
1368
+ return aggregationFns.count;
1369
+ },
1370
+ getColumnAggregationFn: () => {
1371
+ var _ref4;
1372
+
1373
+ const userAggregationFns = instance.options.aggregationFns;
1374
+
1375
+ if (!column) {
1376
+ throw new Error();
1377
+ }
1378
+
1379
+ return isFunction(column.aggregationFn) ? column.aggregationFn : column.aggregationFn === 'auto' ? column.getColumnAutoAggregationFn() : (_ref4 = userAggregationFns == null ? void 0 : userAggregationFns[column.aggregationFn]) != null ? _ref4 : aggregationFns[column.aggregationFn];
1380
+ }
1381
+ };
1382
+ },
1383
+ createInstance: instance => {
1384
+ return {
1385
+ setGrouping: updater => instance.options.onGroupingChange == null ? void 0 : instance.options.onGroupingChange(updater),
1386
+ resetGrouping: defaultState => {
1387
+ var _instance$initialStat, _instance$initialStat2;
1388
+
1389
+ instance.setGrouping(defaultState ? [] : (_instance$initialStat = (_instance$initialStat2 = instance.initialState) == null ? void 0 : _instance$initialStat2.grouping) != null ? _instance$initialStat : []);
1390
+ },
1391
+ getPreGroupedRowModel: () => instance.getSortedRowModel(),
1392
+ getGroupedRowModel: () => {
1393
+ if (!instance._getGroupedRowModel && instance.options.getGroupedRowModel) {
1394
+ instance._getGroupedRowModel = instance.options.getGroupedRowModel(instance);
1395
+ }
1396
+
1397
+ if (instance.options.manualGrouping || !instance._getGroupedRowModel) {
1398
+ return instance.getPreGroupedRowModel();
1399
+ }
1400
+
1401
+ return instance._getGroupedRowModel();
1402
+ }
1403
+ };
1404
+ },
1405
+ createRow: (row, instance) => {
1406
+ return {
1407
+ getIsGrouped: () => !!row.groupingColumnId,
1408
+ groupingValuesCache: {}
1409
+ };
1410
+ },
1411
+ createCell: (cell, column, row, instance) => {
1412
+ return {
1413
+ getIsGrouped: () => column.getIsGrouped() && column.id === row.groupingColumnId,
1414
+ getIsPlaceholder: () => !cell.getIsGrouped() && column.getIsGrouped(),
1415
+ getIsAggregated: () => {
1416
+ var _row$subRows;
1417
+
1418
+ return !cell.getIsGrouped() && !cell.getIsPlaceholder() && ((_row$subRows = row.subRows) == null ? void 0 : _row$subRows.length) > 1;
1419
+ },
1420
+ renderAggregatedCell: () => {
1421
+ var _column$columnDef$agg;
1422
+
1423
+ const template = (_column$columnDef$agg = column.columnDef.aggregatedCell) != null ? _column$columnDef$agg : column.columnDef.cell;
1424
+ return template ? instance._render(template, {
1425
+ instance,
1426
+ column,
1427
+ row,
1428
+ cell,
1429
+ getValue: cell.getValue
1430
+ }) : null;
1431
+ }
1432
+ };
1433
+ }
1434
+ };
1435
+ function orderColumns(leafColumns, grouping, groupedColumnMode) {
1436
+ if (!(grouping != null && grouping.length) || !groupedColumnMode) {
1437
+ return leafColumns;
1438
+ }
1439
+
1440
+ const nonGroupingColumns = leafColumns.filter(col => !grouping.includes(col.id));
1441
+
1442
+ if (groupedColumnMode === 'remove') {
1443
+ return nonGroupingColumns;
1444
+ }
1445
+
1446
+ const groupingColumns = grouping.map(g => leafColumns.find(col => col.id === g)).filter(Boolean);
1447
+ return [...groupingColumns, ...nonGroupingColumns];
1448
+ }
1449
+
1450
+ //
1451
+ const Ordering = {
1452
+ getInitialState: state => {
1453
+ return {
1454
+ columnOrder: [],
1455
+ ...state
1456
+ };
1457
+ },
1458
+ getDefaultOptions: instance => {
1459
+ return {
1460
+ onColumnOrderChange: makeStateUpdater('columnOrder', instance)
1461
+ };
1462
+ },
1463
+ createInstance: instance => {
1464
+ return {
1465
+ setColumnOrder: updater => instance.options.onColumnOrderChange == null ? void 0 : instance.options.onColumnOrderChange(updater),
1466
+ resetColumnOrder: defaultState => {
1467
+ var _instance$initialStat;
1468
+
1469
+ instance.setColumnOrder(defaultState ? [] : (_instance$initialStat = instance.initialState.columnOrder) != null ? _instance$initialStat : []);
1470
+ },
1471
+ _getOrderColumnsFn: memo(() => [instance.getState().columnOrder, instance.getState().grouping, instance.options.groupedColumnMode], (columnOrder, grouping, groupedColumnMode) => columns => {
1472
+ // Sort grouped columns to the start of the column list
1473
+ // before the headers are built
1474
+ let orderedColumns = []; // If there is no order, return the normal columns
1475
+
1476
+ if (!(columnOrder != null && columnOrder.length)) {
1477
+ orderedColumns = columns;
1478
+ } else {
1479
+ const columnOrderCopy = [...columnOrder]; // If there is an order, make a copy of the columns
1480
+
1481
+ const columnsCopy = [...columns]; // And make a new ordered array of the columns
1482
+ // Loop over the columns and place them in order into the new array
1483
+
1484
+ while (columnsCopy.length && columnOrderCopy.length) {
1485
+ const targetColumnId = columnOrderCopy.shift();
1486
+ const foundIndex = columnsCopy.findIndex(d => d.id === targetColumnId);
1487
+
1488
+ if (foundIndex > -1) {
1489
+ orderedColumns.push(columnsCopy.splice(foundIndex, 1)[0]);
1490
+ }
1491
+ } // If there are any columns left, add them to the end
1492
+
1493
+
1494
+ orderedColumns = [...orderedColumns, ...columnsCopy];
1495
+ }
1496
+
1497
+ return orderColumns(orderedColumns, grouping, groupedColumnMode);
1498
+ }, {
1499
+ key: process.env.NODE_ENV === 'development' && 'getOrderColumnsFn' // debug: () => instance.options.debugAll ?? instance.options.debugTable,
1500
+
1501
+ })
1502
+ };
1503
+ }
1504
+ };
1505
+
1506
+ //
1507
+ const defaultPageIndex = 0;
1508
+ const defaultPageSize = 10;
1509
+
1510
+ const getDefaultPaginationState = () => ({
1511
+ pageIndex: defaultPageIndex,
1512
+ pageSize: defaultPageSize
1513
+ });
1514
+
1515
+ const Pagination = {
1516
+ getInitialState: state => {
1517
+ return { ...state,
1518
+ pagination: { ...getDefaultPaginationState(),
1519
+ ...(state == null ? void 0 : state.pagination)
1520
+ }
1521
+ };
1522
+ },
1523
+ getDefaultOptions: instance => {
1524
+ return {
1525
+ onPaginationChange: makeStateUpdater('pagination', instance)
1526
+ };
1527
+ },
1528
+ createInstance: instance => {
1529
+ let registered = false;
1530
+ let queued = false;
1531
+ return {
1532
+ _autoResetPageIndex: () => {
1533
+ var _ref, _instance$options$aut;
1534
+
1535
+ if (!registered) {
1536
+ instance._queue(() => {
1537
+ registered = true;
1538
+ });
1539
+
1540
+ return;
1541
+ }
1542
+
1543
+ if ((_ref = (_instance$options$aut = instance.options.autoResetAll) != null ? _instance$options$aut : instance.options.autoResetPageIndex) != null ? _ref : !instance.options.manualPagination) {
1544
+ if (queued) return;
1545
+ queued = true;
1546
+
1547
+ instance._queue(() => {
1548
+ instance.resetPageIndex();
1549
+ queued = false;
1550
+ });
1551
+ }
1552
+ },
1553
+ setPagination: updater => {
1554
+ const safeUpdater = old => {
1555
+ let newState = functionalUpdate(updater, old);
1556
+ return newState;
1557
+ };
1558
+
1559
+ return instance.options.onPaginationChange == null ? void 0 : instance.options.onPaginationChange(safeUpdater);
1560
+ },
1561
+ resetPagination: defaultState => {
1562
+ var _instance$initialStat;
1563
+
1564
+ instance.setPagination(defaultState ? getDefaultPaginationState() : (_instance$initialStat = instance.initialState.pagination) != null ? _instance$initialStat : getDefaultPaginationState());
1565
+ },
1566
+ setPageIndex: updater => {
1567
+ instance.setPagination(old => {
1568
+ let pageIndex = functionalUpdate(updater, old.pageIndex);
1569
+ const maxPageIndex = typeof old.pageCount !== 'undefined' ? old.pageCount - 1 : Number.MAX_SAFE_INTEGER;
1570
+ pageIndex = Math.min(Math.max(0, pageIndex), maxPageIndex);
1571
+ return { ...old,
1572
+ pageIndex
1573
+ };
1574
+ });
1575
+ },
1576
+ resetPageIndex: defaultState => {
1577
+ var _instance$initialStat2, _instance$initialStat3, _instance$initialStat4;
1578
+
1579
+ instance.setPageIndex(defaultState ? defaultPageIndex : (_instance$initialStat2 = (_instance$initialStat3 = instance.initialState) == null ? void 0 : (_instance$initialStat4 = _instance$initialStat3.pagination) == null ? void 0 : _instance$initialStat4.pageIndex) != null ? _instance$initialStat2 : defaultPageIndex);
1580
+ },
1581
+ resetPageSize: defaultState => {
1582
+ var _instance$initialStat5, _instance$initialStat6, _instance$initialStat7;
1583
+
1584
+ instance.setPageSize(defaultState ? defaultPageSize : (_instance$initialStat5 = (_instance$initialStat6 = instance.initialState) == null ? void 0 : (_instance$initialStat7 = _instance$initialStat6.pagination) == null ? void 0 : _instance$initialStat7.pageSize) != null ? _instance$initialStat5 : defaultPageSize);
1585
+ },
1586
+ setPageSize: updater => {
1587
+ instance.setPagination(old => {
1588
+ const pageSize = Math.max(1, functionalUpdate(updater, old.pageSize));
1589
+ const topRowIndex = old.pageSize * old.pageIndex;
1590
+ const pageIndex = Math.floor(topRowIndex / pageSize);
1591
+ return { ...old,
1592
+ pageIndex,
1593
+ pageSize
1594
+ };
1595
+ });
1596
+ },
1597
+ setPageCount: updater => instance.setPagination(old => {
1598
+ var _old$pageCount;
1599
+
1600
+ let newPageCount = functionalUpdate(updater, (_old$pageCount = old.pageCount) != null ? _old$pageCount : -1);
1601
+
1602
+ if (typeof newPageCount === 'number') {
1603
+ newPageCount = Math.max(-1, newPageCount);
1604
+ }
1605
+
1606
+ return { ...old,
1607
+ pageCount: newPageCount
1608
+ };
1609
+ }),
1610
+ getPageOptions: memo(() => [instance.getState().pagination.pageSize, instance.getState().pagination.pageCount], (pageSize, pageCount) => {
1611
+ let pageOptions = [];
1612
+
1613
+ if (pageCount && pageCount > 0) {
1614
+ pageOptions = [...new Array(pageCount)].fill(null).map((_, i) => i);
1615
+ }
1616
+
1617
+ return pageOptions;
1618
+ }, {
1619
+ key: process.env.NODE_ENV === 'development' && 'getPageOptions',
1620
+ debug: () => {
1621
+ var _instance$options$deb;
1622
+
1623
+ return (_instance$options$deb = instance.options.debugAll) != null ? _instance$options$deb : instance.options.debugTable;
1624
+ }
1625
+ }),
1626
+ getCanPreviousPage: () => instance.getState().pagination.pageIndex > 0,
1627
+ getCanNextPage: () => {
1628
+ const {
1629
+ pageIndex
1630
+ } = instance.getState().pagination;
1631
+ const pageCount = instance.getPageCount();
1632
+
1633
+ if (pageCount === -1) {
1634
+ return true;
1635
+ }
1636
+
1637
+ if (pageCount === 0) {
1638
+ return false;
1639
+ }
1640
+
1641
+ return pageIndex < pageCount - 1;
1642
+ },
1643
+ previousPage: () => {
1644
+ return instance.setPageIndex(old => old - 1);
1645
+ },
1646
+ nextPage: () => {
1647
+ return instance.setPageIndex(old => {
1648
+ return old + 1;
1649
+ });
1650
+ },
1651
+ getPrePaginationRowModel: () => instance.getExpandedRowModel(),
1652
+ getPaginationRowModel: () => {
1653
+ if (!instance._getPaginationRowModel && instance.options.getPaginationRowModel) {
1654
+ instance._getPaginationRowModel = instance.options.getPaginationRowModel(instance);
1655
+ }
1656
+
1657
+ if (instance.options.manualPagination || !instance._getPaginationRowModel) {
1658
+ return instance.getPrePaginationRowModel();
1659
+ }
1660
+
1661
+ return instance._getPaginationRowModel();
1662
+ },
1663
+ getPageCount: () => {
1664
+ const {
1665
+ pageCount
1666
+ } = instance.getState().pagination;
1667
+
1668
+ if (typeof pageCount !== 'undefined') {
1669
+ return pageCount;
1670
+ }
1671
+
1672
+ return Math.ceil(instance.getPrePaginationRowModel().rows.length / instance.getState().pagination.pageSize);
1673
+ }
1674
+ };
1675
+ }
1676
+ };
1677
+
1678
+ //
1679
+ const getDefaultPinningState = () => ({
1680
+ left: [],
1681
+ right: []
1682
+ });
1683
+
1684
+ const Pinning = {
1685
+ getInitialState: state => {
1686
+ return {
1687
+ columnPinning: getDefaultPinningState(),
1688
+ ...state
1689
+ };
1690
+ },
1691
+ getDefaultOptions: instance => {
1692
+ return {
1693
+ onColumnPinningChange: makeStateUpdater('columnPinning', instance)
1694
+ };
1695
+ },
1696
+ createColumn: (column, instance) => {
1697
+ return {
1698
+ pin: position => {
1699
+ const columnIds = column.getLeafColumns().map(d => d.id).filter(Boolean);
1700
+ instance.setColumnPinning(old => {
1701
+ var _old$left3, _old$right3;
1702
+
1703
+ if (position === 'right') {
1704
+ var _old$left, _old$right;
1705
+
1706
+ return {
1707
+ left: ((_old$left = old == null ? void 0 : old.left) != null ? _old$left : []).filter(d => !(columnIds != null && columnIds.includes(d))),
1708
+ right: [...((_old$right = old == null ? void 0 : old.right) != null ? _old$right : []).filter(d => !(columnIds != null && columnIds.includes(d))), ...columnIds]
1709
+ };
1710
+ }
1711
+
1712
+ if (position === 'left') {
1713
+ var _old$left2, _old$right2;
1714
+
1715
+ return {
1716
+ left: [...((_old$left2 = old == null ? void 0 : old.left) != null ? _old$left2 : []).filter(d => !(columnIds != null && columnIds.includes(d))), ...columnIds],
1717
+ right: ((_old$right2 = old == null ? void 0 : old.right) != null ? _old$right2 : []).filter(d => !(columnIds != null && columnIds.includes(d)))
1718
+ };
1719
+ }
1720
+
1721
+ return {
1722
+ left: ((_old$left3 = old == null ? void 0 : old.left) != null ? _old$left3 : []).filter(d => !(columnIds != null && columnIds.includes(d))),
1723
+ right: ((_old$right3 = old == null ? void 0 : old.right) != null ? _old$right3 : []).filter(d => !(columnIds != null && columnIds.includes(d)))
1724
+ };
1725
+ });
1726
+ },
1727
+ getCanPin: () => {
1728
+ const leafColumns = column.getLeafColumns();
1729
+ return leafColumns.some(d => {
1730
+ var _d$columnDef$enablePi, _instance$options$ena;
1731
+
1732
+ return ((_d$columnDef$enablePi = d.columnDef.enablePinning) != null ? _d$columnDef$enablePi : true) && ((_instance$options$ena = instance.options.enablePinning) != null ? _instance$options$ena : true);
1733
+ });
1734
+ },
1735
+ getIsPinned: () => {
1736
+ const leafColumnIds = column.getLeafColumns().map(d => d.id);
1737
+ const {
1738
+ left,
1739
+ right
1740
+ } = instance.getState().columnPinning;
1741
+ const isLeft = leafColumnIds.some(d => left == null ? void 0 : left.includes(d));
1742
+ const isRight = leafColumnIds.some(d => right == null ? void 0 : right.includes(d));
1743
+ return isLeft ? 'left' : isRight ? 'right' : false;
1744
+ },
1745
+ getPinnedIndex: () => {
1746
+ var _instance$getState$co, _instance$getState$co2, _instance$getState$co3;
1747
+
1748
+ const position = column.getIsPinned();
1749
+ return position ? (_instance$getState$co = (_instance$getState$co2 = instance.getState().columnPinning) == null ? void 0 : (_instance$getState$co3 = _instance$getState$co2[position]) == null ? void 0 : _instance$getState$co3.indexOf(column.id)) != null ? _instance$getState$co : -1 : 0;
1750
+ }
1751
+ };
1752
+ },
1753
+ createRow: (row, instance) => {
1754
+ return {
1755
+ getCenterVisibleCells: memo(() => [row._getAllVisibleCells(), instance.getState().columnPinning.left, instance.getState().columnPinning.right], (allCells, left, right) => {
1756
+ const leftAndRight = [...(left != null ? left : []), ...(right != null ? right : [])];
1757
+ return allCells.filter(d => !leftAndRight.includes(d.columnId));
1758
+ }, {
1759
+ key: process.env.NODE_ENV === 'production' && 'row.getCenterVisibleCells',
1760
+ debug: () => {
1761
+ var _instance$options$deb;
1762
+
1763
+ return (_instance$options$deb = instance.options.debugAll) != null ? _instance$options$deb : instance.options.debugRows;
1764
+ }
1765
+ }),
1766
+ getLeftVisibleCells: memo(() => [row._getAllVisibleCells(), instance.getState().columnPinning.left,,], (allCells, left) => {
1767
+ const cells = (left != null ? left : []).map(columnId => allCells.find(cell => cell.columnId === columnId)).filter(Boolean).map(d => ({ ...d,
1768
+ position: 'left'
1769
+ }));
1770
+ return cells;
1771
+ }, {
1772
+ key: process.env.NODE_ENV === 'production' && 'row.getLeftVisibleCells',
1773
+ debug: () => {
1774
+ var _instance$options$deb2;
1775
+
1776
+ return (_instance$options$deb2 = instance.options.debugAll) != null ? _instance$options$deb2 : instance.options.debugRows;
1777
+ }
1778
+ }),
1779
+ getRightVisibleCells: memo(() => [row._getAllVisibleCells(), instance.getState().columnPinning.right], (allCells, right) => {
1780
+ const cells = (right != null ? right : []).map(columnId => allCells.find(cell => cell.columnId === columnId)).filter(Boolean).map(d => ({ ...d,
1781
+ position: 'left'
1782
+ }));
1783
+ return cells;
1784
+ }, {
1785
+ key: process.env.NODE_ENV === 'production' && 'row.getRightVisibleCells',
1786
+ debug: () => {
1787
+ var _instance$options$deb3;
1788
+
1789
+ return (_instance$options$deb3 = instance.options.debugAll) != null ? _instance$options$deb3 : instance.options.debugRows;
1790
+ }
1791
+ })
1792
+ };
1793
+ },
1794
+ createInstance: instance => {
1795
+ return {
1796
+ setColumnPinning: updater => instance.options.onColumnPinningChange == null ? void 0 : instance.options.onColumnPinningChange(updater),
1797
+ resetColumnPinning: defaultState => {
1798
+ var _instance$initialStat, _instance$initialStat2;
1799
+
1800
+ return instance.setColumnPinning(defaultState ? getDefaultPinningState() : (_instance$initialStat = (_instance$initialStat2 = instance.initialState) == null ? void 0 : _instance$initialStat2.columnPinning) != null ? _instance$initialStat : getDefaultPinningState());
1801
+ },
1802
+ getIsSomeColumnsPinned: position => {
1803
+ var _pinningState$positio;
1804
+
1805
+ const pinningState = instance.getState().columnPinning;
1806
+
1807
+ if (!position) {
1808
+ var _pinningState$left, _pinningState$right;
1809
+
1810
+ return Boolean(((_pinningState$left = pinningState.left) == null ? void 0 : _pinningState$left.length) || ((_pinningState$right = pinningState.right) == null ? void 0 : _pinningState$right.length));
1811
+ }
1812
+
1813
+ return Boolean((_pinningState$positio = pinningState[position]) == null ? void 0 : _pinningState$positio.length);
1814
+ },
1815
+ getLeftLeafColumns: memo(() => [instance.getAllLeafColumns(), instance.getState().columnPinning.left], (allColumns, left) => {
1816
+ return (left != null ? left : []).map(columnId => allColumns.find(column => column.id === columnId)).filter(Boolean);
1817
+ }, {
1818
+ key: process.env.NODE_ENV === 'development' && 'getLeftLeafColumns',
1819
+ debug: () => {
1820
+ var _instance$options$deb4;
1821
+
1822
+ return (_instance$options$deb4 = instance.options.debugAll) != null ? _instance$options$deb4 : instance.options.debugColumns;
1823
+ }
1824
+ }),
1825
+ getRightLeafColumns: memo(() => [instance.getAllLeafColumns(), instance.getState().columnPinning.right], (allColumns, right) => {
1826
+ return (right != null ? right : []).map(columnId => allColumns.find(column => column.id === columnId)).filter(Boolean);
1827
+ }, {
1828
+ key: process.env.NODE_ENV === 'development' && 'getRightLeafColumns',
1829
+ debug: () => {
1830
+ var _instance$options$deb5;
1831
+
1832
+ return (_instance$options$deb5 = instance.options.debugAll) != null ? _instance$options$deb5 : instance.options.debugColumns;
1833
+ }
1834
+ }),
1835
+ getCenterLeafColumns: memo(() => [instance.getAllLeafColumns(), instance.getState().columnPinning.left, instance.getState().columnPinning.right], (allColumns, left, right) => {
1836
+ const leftAndRight = [...(left != null ? left : []), ...(right != null ? right : [])];
1837
+ return allColumns.filter(d => !leftAndRight.includes(d.id));
1838
+ }, {
1839
+ key: process.env.NODE_ENV === 'development' && 'getCenterLeafColumns',
1840
+ debug: () => {
1841
+ var _instance$options$deb6;
1842
+
1843
+ return (_instance$options$deb6 = instance.options.debugAll) != null ? _instance$options$deb6 : instance.options.debugColumns;
1844
+ }
1845
+ })
1846
+ };
1847
+ }
1848
+ };
1849
+
1850
+ //
1851
+ const RowSelection = {
1852
+ getInitialState: state => {
1853
+ return {
1854
+ rowSelection: {},
1855
+ ...state
1856
+ };
1857
+ },
1858
+ getDefaultOptions: instance => {
1859
+ return {
1860
+ onRowSelectionChange: makeStateUpdater('rowSelection', instance),
1861
+ enableRowSelection: true,
1862
+ enableMultiRowSelection: true,
1863
+ enableSubRowSelection: true // enableGroupingRowSelection: false,
1864
+ // isAdditiveSelectEvent: (e: unknown) => !!e.metaKey,
1865
+ // isInclusiveSelectEvent: (e: unknown) => !!e.shiftKey,
1866
+
1867
+ };
1868
+ },
1869
+ createInstance: instance => {
1870
+ return {
1871
+ setRowSelection: updater => instance.options.onRowSelectionChange == null ? void 0 : instance.options.onRowSelectionChange(updater),
1872
+ resetRowSelection: defaultState => {
1873
+ var _instance$initialStat;
1874
+
1875
+ return instance.setRowSelection(defaultState ? {} : (_instance$initialStat = instance.initialState.rowSelection) != null ? _instance$initialStat : {});
1876
+ },
1877
+ toggleAllRowsSelected: value => {
1878
+ instance.setRowSelection(old => {
1879
+ value = typeof value !== 'undefined' ? value : !instance.getIsAllRowsSelected();
1880
+ const rowSelection = { ...old
1881
+ };
1882
+ const preGroupedFlatRows = instance.getPreGroupedRowModel().flatRows; // We don't use `mutateRowIsSelected` here for performance reasons.
1883
+ // All of the rows are flat already, so it wouldn't be worth it
1884
+
1885
+ if (value) {
1886
+ preGroupedFlatRows.forEach(row => {
1887
+ rowSelection[row.id] = true;
1888
+ });
1889
+ } else {
1890
+ preGroupedFlatRows.forEach(row => {
1891
+ delete rowSelection[row.id];
1892
+ });
1893
+ }
1894
+
1895
+ return rowSelection;
1896
+ });
1897
+ },
1898
+ toggleAllPageRowsSelected: value => instance.setRowSelection(old => {
1899
+ typeof value !== 'undefined' ? value : !instance.getIsAllPageRowsSelected();
1900
+ const rowSelection = { ...old
1901
+ };
1902
+ instance.getRowModel().rows.forEach(row => {
1903
+ mutateRowIsSelected(rowSelection, row.id, value, instance);
1904
+ });
1905
+ return rowSelection;
1906
+ }),
1907
+ // addRowSelectionRange: rowId => {
1908
+ // const {
1909
+ // rows,
1910
+ // rowsById,
1911
+ // options: { selectGroupingRows, selectSubRows },
1912
+ // } = instance
1913
+ // const findSelectedRow = (rows: Row[]) => {
1914
+ // let found
1915
+ // rows.find(d => {
1916
+ // if (d.getIsSelected()) {
1917
+ // found = d
1918
+ // return true
1919
+ // }
1920
+ // const subFound = findSelectedRow(d.subRows || [])
1921
+ // if (subFound) {
1922
+ // found = subFound
1923
+ // return true
1924
+ // }
1925
+ // return false
1926
+ // })
1927
+ // return found
1928
+ // }
1929
+ // const firstRow = findSelectedRow(rows) || rows[0]
1930
+ // const lastRow = rowsById[rowId]
1931
+ // let include = false
1932
+ // const selectedRowIds = {}
1933
+ // const addRow = (row: Row) => {
1934
+ // mutateRowIsSelected(selectedRowIds, row.id, true, {
1935
+ // rowsById,
1936
+ // selectGroupingRows: selectGroupingRows!,
1937
+ // selectSubRows: selectSubRows!,
1938
+ // })
1939
+ // }
1940
+ // instance.rows.forEach(row => {
1941
+ // const isFirstRow = row.id === firstRow.id
1942
+ // const isLastRow = row.id === lastRow.id
1943
+ // if (isFirstRow || isLastRow) {
1944
+ // if (!include) {
1945
+ // include = true
1946
+ // } else if (include) {
1947
+ // addRow(row)
1948
+ // include = false
1949
+ // }
1950
+ // }
1951
+ // if (include) {
1952
+ // addRow(row)
1953
+ // }
1954
+ // })
1955
+ // instance.setRowSelection(selectedRowIds)
1956
+ // },
1957
+ getPreSelectedRowModel: () => instance.getCoreRowModel(),
1958
+ getSelectedRowModel: memo(() => [instance.getState().rowSelection, instance.getCoreRowModel()], (rowSelection, rowModel) => {
1959
+ if (!Object.keys(rowSelection).length) {
1960
+ return {
1961
+ rows: [],
1962
+ flatRows: [],
1963
+ rowsById: {}
1964
+ };
1965
+ }
1966
+
1967
+ return selectRowsFn(instance, rowModel);
1968
+ }, {
1969
+ key: process.env.NODE_ENV === 'development' && 'getSelectedRowModel',
1970
+ debug: () => {
1971
+ var _instance$options$deb;
1972
+
1973
+ return (_instance$options$deb = instance.options.debugAll) != null ? _instance$options$deb : instance.options.debugTable;
1974
+ }
1975
+ }),
1976
+ getFilteredSelectedRowModel: memo(() => [instance.getState().rowSelection, instance.getFilteredRowModel()], (rowSelection, rowModel) => {
1977
+ if (!Object.keys(rowSelection).length) {
1978
+ return {
1979
+ rows: [],
1980
+ flatRows: [],
1981
+ rowsById: {}
1982
+ };
1983
+ }
1984
+
1985
+ return selectRowsFn(instance, rowModel);
1986
+ }, {
1987
+ key: process.env.NODE_ENV === 'production' && 'getFilteredSelectedRowModel',
1988
+ debug: () => {
1989
+ var _instance$options$deb2;
1990
+
1991
+ return (_instance$options$deb2 = instance.options.debugAll) != null ? _instance$options$deb2 : instance.options.debugTable;
1992
+ }
1993
+ }),
1994
+ getGroupedSelectedRowModel: memo(() => [instance.getState().rowSelection, instance.getGroupedRowModel()], (rowSelection, rowModel) => {
1995
+ if (!Object.keys(rowSelection).length) {
1996
+ return {
1997
+ rows: [],
1998
+ flatRows: [],
1999
+ rowsById: {}
2000
+ };
2001
+ }
2002
+
2003
+ return selectRowsFn(instance, rowModel);
2004
+ }, {
2005
+ key: process.env.NODE_ENV === 'production' && 'getGroupedSelectedRowModel',
2006
+ debug: () => {
2007
+ var _instance$options$deb3;
2008
+
2009
+ return (_instance$options$deb3 = instance.options.debugAll) != null ? _instance$options$deb3 : instance.options.debugTable;
2010
+ }
2011
+ }),
2012
+ ///
2013
+ // getGroupingRowCanSelect: rowId => {
2014
+ // const row = instance.getRow(rowId)
2015
+ // if (!row) {
2016
+ // throw new Error()
2017
+ // }
2018
+ // if (typeof instance.options.enableGroupingRowSelection === 'function') {
2019
+ // return instance.options.enableGroupingRowSelection(row)
2020
+ // }
2021
+ // return instance.options.enableGroupingRowSelection ?? false
2022
+ // },
2023
+ getIsAllRowsSelected: () => {
2024
+ const preFilteredFlatRows = instance.getPreFilteredRowModel().flatRows;
2025
+ const {
2026
+ rowSelection
2027
+ } = instance.getState();
2028
+ let isAllRowsSelected = Boolean(preFilteredFlatRows.length && Object.keys(rowSelection).length);
2029
+
2030
+ if (isAllRowsSelected) {
2031
+ if (preFilteredFlatRows.some(row => !rowSelection[row.id])) {
2032
+ isAllRowsSelected = false;
2033
+ }
2034
+ }
2035
+
2036
+ return isAllRowsSelected;
2037
+ },
2038
+ getIsAllPageRowsSelected: () => {
2039
+ const paginationFlatRows = instance.getPaginationRowModel().flatRows;
2040
+ const {
2041
+ rowSelection
2042
+ } = instance.getState();
2043
+ let isAllPageRowsSelected = !!paginationFlatRows.length;
2044
+
2045
+ if (isAllPageRowsSelected && paginationFlatRows.some(row => !rowSelection[row.id])) {
2046
+ isAllPageRowsSelected = false;
2047
+ }
2048
+
2049
+ return isAllPageRowsSelected;
2050
+ },
2051
+ getIsSomeRowsSelected: () => {
2052
+ var _instance$getState$ro;
2053
+
2054
+ return !instance.getIsAllRowsSelected() && !!Object.keys((_instance$getState$ro = instance.getState().rowSelection) != null ? _instance$getState$ro : {}).length;
2055
+ },
2056
+ getIsSomePageRowsSelected: () => {
2057
+ const paginationFlatRows = instance.getPaginationRowModel().flatRows;
2058
+ return instance.getIsAllPageRowsSelected() ? false : !!(paginationFlatRows != null && paginationFlatRows.length);
2059
+ },
2060
+ getToggleAllRowsSelectedHandler: () => {
2061
+ return e => {
2062
+ instance.toggleAllRowsSelected(e.target.checked);
2063
+ };
2064
+ },
2065
+ getToggleAllPageRowsSelectedHandler: () => {
2066
+ return e => {
2067
+ instance.toggleAllPageRowsSelected(e.target.checked);
2068
+ };
2069
+ }
2070
+ };
2071
+ },
2072
+ createRow: (row, instance) => {
2073
+ return {
2074
+ toggleSelected: value => {
2075
+ const isSelected = row.getIsSelected();
2076
+ instance.setRowSelection(old => {
2077
+ value = typeof value !== 'undefined' ? value : !isSelected;
2078
+
2079
+ if (isSelected === value) {
2080
+ return old;
2081
+ }
2082
+
2083
+ const selectedRowIds = { ...old
2084
+ };
2085
+ mutateRowIsSelected(selectedRowIds, row.id, value, instance);
2086
+ return selectedRowIds;
2087
+ });
2088
+ },
2089
+ getIsSelected: () => {
2090
+ const {
2091
+ rowSelection
2092
+ } = instance.getState();
2093
+ return isRowSelected(row, rowSelection) === true;
2094
+ },
2095
+ getIsSomeSelected: () => {
2096
+ const {
2097
+ rowSelection
2098
+ } = instance.getState();
2099
+ return isRowSelected(row, rowSelection) === 'some';
2100
+ },
2101
+ getCanSelect: () => {
2102
+ var _instance$options$ena;
2103
+
2104
+ if (typeof instance.options.enableRowSelection === 'function') {
2105
+ return instance.options.enableRowSelection(row);
2106
+ }
2107
+
2108
+ return (_instance$options$ena = instance.options.enableRowSelection) != null ? _instance$options$ena : true;
2109
+ },
2110
+ getCanSelectSubRows: () => {
2111
+ var _instance$options$ena2;
2112
+
2113
+ if (typeof instance.options.enableSubRowSelection === 'function') {
2114
+ return instance.options.enableSubRowSelection(row);
2115
+ }
2116
+
2117
+ return (_instance$options$ena2 = instance.options.enableSubRowSelection) != null ? _instance$options$ena2 : true;
2118
+ },
2119
+ getCanMultiSelect: () => {
2120
+ var _instance$options$ena3;
2121
+
2122
+ if (typeof instance.options.enableMultiRowSelection === 'function') {
2123
+ return instance.options.enableMultiRowSelection(row);
2124
+ }
2125
+
2126
+ return (_instance$options$ena3 = instance.options.enableMultiRowSelection) != null ? _instance$options$ena3 : true;
2127
+ },
2128
+ getToggleSelectedHandler: () => {
2129
+ const canSelect = row.getCanSelect();
2130
+ return e => {
2131
+ var _target;
2132
+
2133
+ if (!canSelect) return;
2134
+ row.toggleSelected((_target = e.target) == null ? void 0 : _target.checked);
2135
+ };
2136
+ }
2137
+ };
2138
+ }
2139
+ };
2140
+
2141
+ const mutateRowIsSelected = (selectedRowIds, id, value, instance) => {
2142
+ var _row$subRows;
2143
+
2144
+ const row = instance.getRow(id);
2145
+ row.getIsGrouped(); // if ( // TODO: enforce grouping row selection rules
2146
+ // !isGrouped ||
2147
+ // (isGrouped && instance.options.enableGroupingRowSelection)
2148
+ // ) {
2149
+
2150
+ if (value) {
2151
+ selectedRowIds[id] = true;
2152
+ } else {
2153
+ delete selectedRowIds[id];
2154
+ } // }
2155
+
2156
+
2157
+ if ((_row$subRows = row.subRows) != null && _row$subRows.length && row.getCanSelectSubRows()) {
2158
+ row.subRows.forEach(row => mutateRowIsSelected(selectedRowIds, row.id, value, instance));
2159
+ }
2160
+ };
2161
+
2162
+ function selectRowsFn(instance, rowModel) {
2163
+ const rowSelection = instance.getState().rowSelection;
2164
+ const newSelectedFlatRows = [];
2165
+ const newSelectedRowsById = {}; // Filters top level and nested rows
2166
+
2167
+ const recurseRows = function (rows, depth) {
2168
+ if (depth === void 0) {
2169
+ depth = 0;
2170
+ }
2171
+
2172
+ return rows.map(row => {
2173
+ var _row$subRows2;
2174
+
2175
+ const isSelected = isRowSelected(row, rowSelection) === true;
2176
+
2177
+ if (isSelected) {
2178
+ newSelectedFlatRows.push(row);
2179
+ newSelectedRowsById[row.id] = row;
2180
+ }
2181
+
2182
+ if ((_row$subRows2 = row.subRows) != null && _row$subRows2.length) {
2183
+ row = { ...row,
2184
+ subRows: recurseRows(row.subRows, depth + 1)
2185
+ };
2186
+ }
2187
+
2188
+ if (isSelected) {
2189
+ return row;
2190
+ }
2191
+ }).filter(Boolean);
2192
+ };
2193
+
2194
+ return {
2195
+ rows: recurseRows(rowModel.rows),
2196
+ flatRows: newSelectedFlatRows,
2197
+ rowsById: newSelectedRowsById
2198
+ };
2199
+ }
2200
+ function isRowSelected(row, selection, instance) {
2201
+ if (selection[row.id]) {
2202
+ return true;
2203
+ }
2204
+
2205
+ if (row.subRows && row.subRows.length) {
2206
+ let allChildrenSelected = true;
2207
+ let someSelected = false;
2208
+ row.subRows.forEach(subRow => {
2209
+ // Bail out early if we know both of these
2210
+ if (someSelected && !allChildrenSelected) {
2211
+ return;
2212
+ }
2213
+
2214
+ if (isRowSelected(subRow, selection)) {
2215
+ someSelected = true;
2216
+ } else {
2217
+ allChildrenSelected = false;
2218
+ }
2219
+ });
2220
+ return allChildrenSelected ? true : someSelected ? 'some' : false;
2221
+ }
2222
+
2223
+ return false;
2224
+ }
2225
+
2226
+ const reSplitAlphaNumeric = /([0-9]+)/gm;
2227
+ const sortingFns = {
2228
+ alphanumeric,
2229
+ alphanumericCaseSensitive,
2230
+ text,
2231
+ textCaseSensitive,
2232
+ datetime,
2233
+ basic
2234
+ };
2235
+
2236
+ function alphanumeric(rowA, rowB, columnId) {
2237
+ return compareAlphanumeric(toString(rowA.getValue(columnId)).toLowerCase(), toString(rowB.getValue(columnId)).toLowerCase());
2238
+ }
2239
+
2240
+ function alphanumericCaseSensitive(rowA, rowB, columnId) {
2241
+ return compareAlphanumeric(toString(rowA.getValue(columnId)), toString(rowB.getValue(columnId)));
2242
+ } // Mixed sorting is slow, but very inclusive of many edge cases.
2243
+ // It handles numbers, mixed alphanumeric combinations, and even
2244
+ // null, undefined, and Infinity
2245
+
2246
+
2247
+ function compareAlphanumeric(aStr, bStr) {
2248
+ // Split on number groups, but keep the delimiter
2249
+ // Then remove falsey split values
2250
+ const a = aStr.split(reSplitAlphaNumeric).filter(Boolean);
2251
+ const b = bStr.split(reSplitAlphaNumeric).filter(Boolean); // While
2252
+
2253
+ while (a.length && b.length) {
2254
+ const aa = a.shift();
2255
+ const bb = b.shift();
2256
+ const an = parseInt(aa, 10);
2257
+ const bn = parseInt(bb, 10);
2258
+ const combo = [an, bn].sort(); // Both are string
2259
+
2260
+ if (isNaN(combo[0])) {
2261
+ if (aa > bb) {
2262
+ return 1;
2263
+ }
2264
+
2265
+ if (bb > aa) {
2266
+ return -1;
2267
+ }
2268
+
2269
+ continue;
2270
+ } // One is a string, one is a number
2271
+
2272
+
2273
+ if (isNaN(combo[1])) {
2274
+ return isNaN(an) ? -1 : 1;
2275
+ } // Both are numbers
2276
+
2277
+
2278
+ if (an > bn) {
2279
+ return 1;
2280
+ }
2281
+
2282
+ if (bn > an) {
2283
+ return -1;
2284
+ }
2285
+ }
2286
+
2287
+ return a.length - b.length;
2288
+ } // The text filter is more basic (less numeric support)
2289
+ // but is much faster
2290
+
2291
+
2292
+ function text(rowA, rowB, columnId) {
2293
+ return compareBasic(toString(rowA.getValue(columnId)).toLowerCase(), toString(rowB.getValue(columnId)).toLowerCase());
2294
+ } // The text filter is more basic (less numeric support)
2295
+ // but is much faster
2296
+
2297
+
2298
+ function textCaseSensitive(rowA, rowB, columnId) {
2299
+ return compareBasic(toString(rowA.getValue(columnId)), toString(rowB.getValue(columnId)));
2300
+ }
2301
+
2302
+ function datetime(rowA, rowB, columnId) {
2303
+ return compareBasic(rowA.getValue(columnId).getTime(), rowB.getValue(columnId).getTime());
2304
+ }
2305
+
2306
+ function basic(rowA, rowB, columnId) {
2307
+ return compareBasic(rowA.getValue(columnId), rowB.getValue(columnId));
2308
+ } // Utils
2309
+
2310
+
2311
+ function compareBasic(a, b) {
2312
+ return a === b ? 0 : a > b ? 1 : -1;
2313
+ }
2314
+
2315
+ function toString(a) {
2316
+ if (typeof a === 'number') {
2317
+ if (isNaN(a) || a === Infinity || a === -Infinity) {
2318
+ return '';
2319
+ }
2320
+
2321
+ return String(a);
2322
+ }
2323
+
2324
+ if (typeof a === 'string') {
2325
+ return a;
2326
+ }
2327
+
2328
+ return '';
2329
+ }
2330
+
2331
+ //
2332
+ const Sorting = {
2333
+ getInitialState: state => {
2334
+ return {
2335
+ sorting: [],
2336
+ ...state
2337
+ };
2338
+ },
2339
+ getDefaultColumnDef: () => {
2340
+ return {
2341
+ sortingFn: 'auto'
2342
+ };
2343
+ },
2344
+ getDefaultOptions: instance => {
2345
+ return {
2346
+ onSortingChange: makeStateUpdater('sorting', instance),
2347
+ isMultiSortEvent: e => {
2348
+ return e.shiftKey;
2349
+ }
2350
+ };
2351
+ },
2352
+ createColumn: (column, instance) => {
2353
+ return {
2354
+ getAutoSortingFn: () => {
2355
+ const firstRows = instance.getFilteredRowModel().flatRows.slice(10);
2356
+ let isString = false;
2357
+
2358
+ for (const row of firstRows) {
2359
+ const value = row == null ? void 0 : row.getValue(column.id);
2360
+
2361
+ if (Object.prototype.toString.call(value) === '[object Date]') {
2362
+ return sortingFns.datetime;
2363
+ }
2364
+
2365
+ if (typeof value === 'string') {
2366
+ isString = true;
2367
+
2368
+ if (value.split(reSplitAlphaNumeric).length > 1) {
2369
+ return sortingFns.alphanumeric;
2370
+ }
2371
+ }
2372
+ }
2373
+
2374
+ if (isString) {
2375
+ return sortingFns.text;
2376
+ }
2377
+
2378
+ return sortingFns.basic;
2379
+ },
2380
+ getAutoSortDir: () => {
2381
+ const firstRow = instance.getFilteredRowModel().flatRows[0];
2382
+ const value = firstRow == null ? void 0 : firstRow.getValue(column.id);
2383
+
2384
+ if (typeof value === 'string') {
2385
+ return 'asc';
2386
+ }
2387
+
2388
+ return 'desc';
2389
+ },
2390
+ getSortingFn: () => {
2391
+ var _ref;
2392
+
2393
+ const userSortingFn = instance.options.sortingFns;
2394
+
2395
+ if (!column) {
2396
+ throw new Error();
2397
+ }
2398
+
2399
+ return isFunction(column.columnDef.sortingFn) ? column.columnDef.sortingFn : column.columnDef.sortingFn === 'auto' ? column.getAutoSortingFn() : (_ref = userSortingFn == null ? void 0 : userSortingFn[column.columnDef.sortingFn]) != null ? _ref : sortingFns[column.columnDef.sortingFn];
2400
+ },
2401
+ toggleSorting: (desc, multi) => {
2402
+ // if (column.columns.length) {
2403
+ // column.columns.forEach((c, i) => {
2404
+ // if (c.id) {
2405
+ // instance.toggleColumnSorting(c.id, undefined, multi || !!i)
2406
+ // }
2407
+ // })
2408
+ // return
2409
+ // }
2410
+ instance.setSorting(old => {
2411
+ var _ref2, _column$columnDef$sor, _instance$options$ena, _instance$options$ena2;
2412
+
2413
+ // Find any existing sorting for this column
2414
+ const existingSorting = old == null ? void 0 : old.find(d => d.id === column.id);
2415
+ const existingIndex = old == null ? void 0 : old.findIndex(d => d.id === column.id);
2416
+ const hasDescDefined = typeof desc !== 'undefined' && desc !== null;
2417
+ let newSorting = []; // What should we do with this sort action?
2418
+
2419
+ let sortAction;
2420
+
2421
+ if (column.getCanMultiSort() && multi) {
2422
+ if (existingSorting) {
2423
+ sortAction = 'toggle';
2424
+ } else {
2425
+ sortAction = 'add';
2426
+ }
2427
+ } else {
2428
+ // Normal mode
2429
+ if (old != null && old.length && existingIndex !== old.length - 1) {
2430
+ sortAction = 'replace';
2431
+ } else if (existingSorting) {
2432
+ sortAction = 'toggle';
2433
+ } else {
2434
+ sortAction = 'replace';
2435
+ }
2436
+ }
2437
+
2438
+ const sortDescFirst = (_ref2 = (_column$columnDef$sor = column.columnDef.sortDescFirst) != null ? _column$columnDef$sor : instance.options.sortDescFirst) != null ? _ref2 : column.getAutoSortDir() === 'desc'; // Handle toggle states that will remove the sorting
2439
+
2440
+ if (sortAction === 'toggle' && ( // Must be toggling
2441
+ (_instance$options$ena = instance.options.enableSortingRemoval) != null ? _instance$options$ena : true) && // If enableSortRemove, enable in general
2442
+ !hasDescDefined && ( // Must not be setting desc
2443
+ multi ? (_instance$options$ena2 = instance.options.enableMultiRemove) != null ? _instance$options$ena2 : true : true) && ( // If multi, don't allow if enableMultiRemove
2444
+ existingSorting != null && existingSorting.desc // Finally, detect if it should indeed be removed
2445
+ ? !sortDescFirst : sortDescFirst)) {
2446
+ sortAction = 'remove';
2447
+ }
2448
+
2449
+ if (sortAction === 'replace') {
2450
+ newSorting = [{
2451
+ id: column.id,
2452
+ desc: hasDescDefined ? desc : !!sortDescFirst
2453
+ }];
2454
+ } else if (sortAction === 'add' && old != null && old.length) {
2455
+ var _instance$options$max;
2456
+
2457
+ newSorting = [...old, {
2458
+ id: column.id,
2459
+ desc: hasDescDefined ? desc : !!sortDescFirst
2460
+ }]; // Take latest n columns
2461
+
2462
+ newSorting.splice(0, newSorting.length - ((_instance$options$max = instance.options.maxMultiSortColCount) != null ? _instance$options$max : Number.MAX_SAFE_INTEGER));
2463
+ } else if (sortAction === 'toggle' && old != null && old.length) {
2464
+ // This flips (or sets) the
2465
+ newSorting = old.map(d => {
2466
+ if (d.id === column.id) {
2467
+ return { ...d,
2468
+ desc: hasDescDefined ? desc : !(existingSorting != null && existingSorting.desc)
2469
+ };
2470
+ }
2471
+
2472
+ return d;
2473
+ });
2474
+ } else if (sortAction === 'remove' && old != null && old.length) {
2475
+ newSorting = old.filter(d => d.id !== column.id);
2476
+ }
2477
+
2478
+ return newSorting;
2479
+ });
2480
+ },
2481
+ getCanSort: () => {
2482
+ var _column$columnDef$ena, _instance$options$ena3;
2483
+
2484
+ return ((_column$columnDef$ena = column.columnDef.enableSorting) != null ? _column$columnDef$ena : true) && ((_instance$options$ena3 = instance.options.enableSorting) != null ? _instance$options$ena3 : true) && !!column.accessorFn;
2485
+ },
2486
+ getCanMultiSort: () => {
2487
+ var _ref3, _column$columnDef$ena2;
2488
+
2489
+ return (_ref3 = (_column$columnDef$ena2 = column.columnDef.enableMultiSort) != null ? _column$columnDef$ena2 : instance.options.enableMultiSort) != null ? _ref3 : !!column.accessorFn;
2490
+ },
2491
+ getIsSorted: () => {
2492
+ var _instance$getState$so;
2493
+
2494
+ const columnSort = (_instance$getState$so = instance.getState().sorting) == null ? void 0 : _instance$getState$so.find(d => d.id === column.id);
2495
+ return !columnSort ? false : columnSort.desc ? 'desc' : 'asc';
2496
+ },
2497
+ getSortIndex: () => {
2498
+ var _instance$getState$so2, _instance$getState$so3;
2499
+
2500
+ return (_instance$getState$so2 = (_instance$getState$so3 = instance.getState().sorting) == null ? void 0 : _instance$getState$so3.findIndex(d => d.id === column.id)) != null ? _instance$getState$so2 : -1;
2501
+ },
2502
+ clearSorting: () => {
2503
+ //clear sorting for just 1 column
2504
+ instance.setSorting(old => old != null && old.length ? old.filter(d => d.id !== column.id) : []);
2505
+ },
2506
+ getToggleSortingHandler: () => {
2507
+ const canSort = column.getCanSort();
2508
+ return e => {
2509
+ if (!canSort) return;
2510
+ e.persist == null ? void 0 : e.persist();
2511
+ column.toggleSorting == null ? void 0 : column.toggleSorting(undefined, column.getCanMultiSort() ? instance.options.isMultiSortEvent == null ? void 0 : instance.options.isMultiSortEvent(e) : false);
2512
+ };
2513
+ }
2514
+ };
2515
+ },
2516
+ createInstance: instance => {
2517
+ return {
2518
+ setSorting: updater => instance.options.onSortingChange == null ? void 0 : instance.options.onSortingChange(updater),
2519
+ resetSorting: defaultState => {
2520
+ var _instance$initialStat, _instance$initialStat2;
2521
+
2522
+ instance.setSorting(defaultState ? [] : (_instance$initialStat = (_instance$initialStat2 = instance.initialState) == null ? void 0 : _instance$initialStat2.sorting) != null ? _instance$initialStat : []);
2523
+ },
2524
+ getPreSortedRowModel: () => instance.getFilteredRowModel(),
2525
+ getSortedRowModel: () => {
2526
+ if (!instance._getSortedRowModel && instance.options.getSortedRowModel) {
2527
+ instance._getSortedRowModel = instance.options.getSortedRowModel(instance);
2528
+ }
2529
+
2530
+ if (instance.options.manualSorting || !instance._getSortedRowModel) {
2531
+ return instance.getPreSortedRowModel();
2532
+ }
2533
+
2534
+ return instance._getSortedRowModel();
2535
+ }
2536
+ };
2537
+ }
2538
+ };
2539
+
2540
+ //
2541
+ const Visibility = {
2542
+ getInitialState: state => {
2543
+ return {
2544
+ columnVisibility: {},
2545
+ ...state
2546
+ };
2547
+ },
2548
+ getDefaultOptions: instance => {
2549
+ return {
2550
+ onColumnVisibilityChange: makeStateUpdater('columnVisibility', instance)
2551
+ };
2552
+ },
2553
+ getDefaultColumnDef: () => {
2554
+ return {
2555
+ defaultIsVisible: true
2556
+ };
2557
+ },
2558
+ createColumn: (column, instance) => {
2559
+ return {
2560
+ toggleVisibility: value => {
2561
+ if (column.getCanHide()) {
2562
+ instance.setColumnVisibility(old => ({ ...old,
2563
+ [column.id]: value != null ? value : !column.getIsVisible()
2564
+ }));
2565
+ }
2566
+ },
2567
+ getIsVisible: () => {
2568
+ var _instance$getState$co, _instance$getState$co2;
2569
+
2570
+ return (_instance$getState$co = (_instance$getState$co2 = instance.getState().columnVisibility) == null ? void 0 : _instance$getState$co2[column.id]) != null ? _instance$getState$co : true;
2571
+ },
2572
+ getCanHide: () => {
2573
+ var _column$columnDef$ena, _instance$options$ena;
2574
+
2575
+ return ((_column$columnDef$ena = column.columnDef.enableHiding) != null ? _column$columnDef$ena : true) && ((_instance$options$ena = instance.options.enableHiding) != null ? _instance$options$ena : true);
2576
+ },
2577
+ getToggleVisibilityHandler: () => {
2578
+ return e => {
2579
+ column.toggleVisibility == null ? void 0 : column.toggleVisibility(e.target.checked);
2580
+ };
2581
+ }
2582
+ };
2583
+ },
2584
+ createRow: (row, instance) => {
2585
+ return {
2586
+ _getAllVisibleCells: memo(() => [row.getAllCells().filter(cell => cell.column.getIsVisible()).map(d => d.id).join('_')], _ => {
2587
+ return row.getAllCells().filter(cell => cell.column.getIsVisible());
2588
+ }, {
2589
+ key: process.env.NODE_ENV === 'production' && 'row._getAllVisibleCells',
2590
+ debug: () => {
2591
+ var _instance$options$deb;
2592
+
2593
+ return (_instance$options$deb = instance.options.debugAll) != null ? _instance$options$deb : instance.options.debugRows;
2594
+ }
2595
+ }),
2596
+ getVisibleCells: memo(() => [row.getLeftVisibleCells(), row.getCenterVisibleCells(), row.getRightVisibleCells()], (left, center, right) => [...left, ...center, ...right], {
2597
+ key: process.env.NODE_ENV === 'development' && 'row.getVisibleCells',
2598
+ debug: () => {
2599
+ var _instance$options$deb2;
2600
+
2601
+ return (_instance$options$deb2 = instance.options.debugAll) != null ? _instance$options$deb2 : instance.options.debugRows;
2602
+ }
2603
+ })
2604
+ };
2605
+ },
2606
+ createInstance: instance => {
2607
+ const makeVisibleColumnsMethod = (key, getColumns) => {
2608
+ return memo(() => [getColumns(), getColumns().filter(d => d.getIsVisible()).map(d => d.id).join('_')], columns => {
2609
+ return columns.filter(d => d.getIsVisible == null ? void 0 : d.getIsVisible());
2610
+ }, {
2611
+ key,
2612
+ debug: () => {
2613
+ var _instance$options$deb3;
2614
+
2615
+ return (_instance$options$deb3 = instance.options.debugAll) != null ? _instance$options$deb3 : instance.options.debugColumns;
2616
+ }
2617
+ });
2618
+ };
2619
+
2620
+ return {
2621
+ getVisibleFlatColumns: makeVisibleColumnsMethod('getVisibleFlatColumns', () => instance.getAllFlatColumns()),
2622
+ getVisibleLeafColumns: makeVisibleColumnsMethod('getVisibleLeafColumns', () => instance.getAllLeafColumns()),
2623
+ getLeftVisibleLeafColumns: makeVisibleColumnsMethod('getLeftVisibleLeafColumns', () => instance.getLeftLeafColumns()),
2624
+ getRightVisibleLeafColumns: makeVisibleColumnsMethod('getRightVisibleLeafColumns', () => instance.getRightLeafColumns()),
2625
+ getCenterVisibleLeafColumns: makeVisibleColumnsMethod('getCenterVisibleLeafColumns', () => instance.getCenterLeafColumns()),
2626
+ setColumnVisibility: updater => instance.options.onColumnVisibilityChange == null ? void 0 : instance.options.onColumnVisibilityChange(updater),
2627
+ resetColumnVisibility: defaultState => {
2628
+ var _instance$initialStat;
2629
+
2630
+ instance.setColumnVisibility(defaultState ? {} : (_instance$initialStat = instance.initialState.columnVisibility) != null ? _instance$initialStat : {});
2631
+ },
2632
+ toggleAllColumnsVisible: value => {
2633
+ var _value;
2634
+
2635
+ value = (_value = value) != null ? _value : !instance.getIsAllColumnsVisible();
2636
+ instance.setColumnVisibility(instance.getAllLeafColumns().reduce((obj, column) => ({ ...obj,
2637
+ [column.id]: !value ? !(column.getCanHide != null && column.getCanHide()) : value
2638
+ }), {}));
2639
+ },
2640
+ getIsAllColumnsVisible: () => !instance.getAllLeafColumns().some(column => !(column.getIsVisible != null && column.getIsVisible())),
2641
+ getIsSomeColumnsVisible: () => instance.getAllLeafColumns().some(column => column.getIsVisible == null ? void 0 : column.getIsVisible()),
2642
+ getToggleAllColumnsVisibilityHandler: () => {
2643
+ return e => {
2644
+ var _target;
2645
+
2646
+ instance.toggleAllColumnsVisible((_target = e.target) == null ? void 0 : _target.checked);
2647
+ };
2648
+ }
2649
+ };
2650
+ }
2651
+ };
2652
+
2653
+ //
2654
+ const Headers = {
2655
+ createInstance: instance => {
2656
+ return {
2657
+ createHeader: (column, options) => {
2658
+ var _options$id;
2659
+
2660
+ const id = (_options$id = options.id) != null ? _options$id : column.id;
2661
+ let header = {
2662
+ id,
2663
+ column,
2664
+ index: options.index,
2665
+ isPlaceholder: options.isPlaceholder,
2666
+ placeholderId: options.placeholderId,
2667
+ depth: options.depth,
2668
+ subHeaders: [],
2669
+ colSpan: 0,
2670
+ rowSpan: 0,
2671
+ headerGroup: null,
2672
+ getLeafHeaders: () => {
2673
+ const leafHeaders = [];
2674
+
2675
+ const recurseHeader = h => {
2676
+ if (h.subHeaders && h.subHeaders.length) {
2677
+ h.subHeaders.map(recurseHeader);
2678
+ }
2679
+
2680
+ leafHeaders.push(h);
2681
+ };
2682
+
2683
+ recurseHeader(header);
2684
+ return leafHeaders;
2685
+ },
2686
+ renderHeader: () => column.columnDef.header ? instance._render(column.columnDef.header, {
2687
+ instance,
2688
+ header: header,
2689
+ column
2690
+ }) : null,
2691
+ renderFooter: () => column.columnDef.footer ? instance._render(column.columnDef.footer, {
2692
+ instance,
2693
+ header: header,
2694
+ column
2695
+ }) : null
2696
+ };
2697
+
2698
+ instance._features.forEach(feature => {
2699
+ Object.assign(header, feature.createHeader == null ? void 0 : feature.createHeader(header, instance));
2700
+ });
2701
+
2702
+ return header;
2703
+ },
2704
+ // Header Groups
2705
+ getHeaderGroups: memo(() => [instance.getAllColumns(), instance.getVisibleLeafColumns(), instance.getState().columnPinning.left, instance.getState().columnPinning.right], (allColumns, leafColumns, left, right) => {
2706
+ var _left$map$filter, _right$map$filter;
2707
+
2708
+ const leftColumns = (_left$map$filter = left == null ? void 0 : left.map(columnId => leafColumns.find(d => d.id === columnId)).filter(Boolean)) != null ? _left$map$filter : [];
2709
+ const rightColumns = (_right$map$filter = right == null ? void 0 : right.map(columnId => leafColumns.find(d => d.id === columnId)).filter(Boolean)) != null ? _right$map$filter : [];
2710
+ const centerColumns = leafColumns.filter(column => !(left != null && left.includes(column.id)) && !(right != null && right.includes(column.id)));
2711
+ const headerGroups = buildHeaderGroups(allColumns, [...leftColumns, ...centerColumns, ...rightColumns], instance);
2712
+ return headerGroups;
2713
+ }, {
2714
+ key: process.env.NODE_ENV === 'development' && 'getHeaderGroups',
2715
+ debug: () => {
2716
+ var _instance$options$deb;
2717
+
2718
+ return (_instance$options$deb = instance.options.debugAll) != null ? _instance$options$deb : instance.options.debugHeaders;
2719
+ }
2720
+ }),
2721
+ getCenterHeaderGroups: memo(() => [instance.getAllColumns(), instance.getVisibleLeafColumns(), instance.getState().columnPinning.left, instance.getState().columnPinning.right], (allColumns, leafColumns, left, right) => {
2722
+ leafColumns = leafColumns.filter(column => !(left != null && left.includes(column.id)) && !(right != null && right.includes(column.id)));
2723
+ return buildHeaderGroups(allColumns, leafColumns, instance, 'center');
2724
+ }, {
2725
+ key: process.env.NODE_ENV === 'development' && 'getCenterHeaderGroups',
2726
+ debug: () => {
2727
+ var _instance$options$deb2;
2728
+
2729
+ return (_instance$options$deb2 = instance.options.debugAll) != null ? _instance$options$deb2 : instance.options.debugHeaders;
2730
+ }
2731
+ }),
2732
+ getLeftHeaderGroups: memo(() => [instance.getAllColumns(), instance.getVisibleLeafColumns(), instance.getState().columnPinning.left], (allColumns, leafColumns, left) => {
2733
+ var _left$map$filter2;
2734
+
2735
+ const orderedLeafColumns = (_left$map$filter2 = left == null ? void 0 : left.map(columnId => leafColumns.find(d => d.id === columnId)).filter(Boolean)) != null ? _left$map$filter2 : [];
2736
+ return buildHeaderGroups(allColumns, orderedLeafColumns, instance, 'left');
2737
+ }, {
2738
+ key: process.env.NODE_ENV === 'development' && 'getLeftHeaderGroups',
2739
+ debug: () => {
2740
+ var _instance$options$deb3;
2741
+
2742
+ return (_instance$options$deb3 = instance.options.debugAll) != null ? _instance$options$deb3 : instance.options.debugHeaders;
2743
+ }
2744
+ }),
2745
+ getRightHeaderGroups: memo(() => [instance.getAllColumns(), instance.getVisibleLeafColumns(), instance.getState().columnPinning.right], (allColumns, leafColumns, right) => {
2746
+ var _right$map$filter2;
2747
+
2748
+ const orderedLeafColumns = (_right$map$filter2 = right == null ? void 0 : right.map(columnId => leafColumns.find(d => d.id === columnId)).filter(Boolean)) != null ? _right$map$filter2 : [];
2749
+ return buildHeaderGroups(allColumns, orderedLeafColumns, instance, 'right');
2750
+ }, {
2751
+ key: process.env.NODE_ENV === 'development' && 'getRightHeaderGroups',
2752
+ debug: () => {
2753
+ var _instance$options$deb4;
2754
+
2755
+ return (_instance$options$deb4 = instance.options.debugAll) != null ? _instance$options$deb4 : instance.options.debugHeaders;
2756
+ }
2757
+ }),
2758
+ // Footer Groups
2759
+ getFooterGroups: memo(() => [instance.getHeaderGroups()], headerGroups => {
2760
+ return [...headerGroups].reverse();
2761
+ }, {
2762
+ key: process.env.NODE_ENV === 'development' && 'getFooterGroups',
2763
+ debug: () => {
2764
+ var _instance$options$deb5;
2765
+
2766
+ return (_instance$options$deb5 = instance.options.debugAll) != null ? _instance$options$deb5 : instance.options.debugHeaders;
2767
+ }
2768
+ }),
2769
+ getLeftFooterGroups: memo(() => [instance.getLeftHeaderGroups()], headerGroups => {
2770
+ return [...headerGroups].reverse();
2771
+ }, {
2772
+ key: process.env.NODE_ENV === 'development' && 'getLeftFooterGroups',
2773
+ debug: () => {
2774
+ var _instance$options$deb6;
2775
+
2776
+ return (_instance$options$deb6 = instance.options.debugAll) != null ? _instance$options$deb6 : instance.options.debugHeaders;
2777
+ }
2778
+ }),
2779
+ getCenterFooterGroups: memo(() => [instance.getCenterHeaderGroups()], headerGroups => {
2780
+ return [...headerGroups].reverse();
2781
+ }, {
2782
+ key: process.env.NODE_ENV === 'development' && 'getCenterFooterGroups',
2783
+ debug: () => {
2784
+ var _instance$options$deb7;
2785
+
2786
+ return (_instance$options$deb7 = instance.options.debugAll) != null ? _instance$options$deb7 : instance.options.debugHeaders;
2787
+ }
2788
+ }),
2789
+ getRightFooterGroups: memo(() => [instance.getRightHeaderGroups()], headerGroups => {
2790
+ return [...headerGroups].reverse();
2791
+ }, {
2792
+ key: process.env.NODE_ENV === 'development' && 'getRightFooterGroups',
2793
+ debug: () => {
2794
+ var _instance$options$deb8;
2795
+
2796
+ return (_instance$options$deb8 = instance.options.debugAll) != null ? _instance$options$deb8 : instance.options.debugHeaders;
2797
+ }
2798
+ }),
2799
+ // Flat Headers
2800
+ getFlatHeaders: memo(() => [instance.getHeaderGroups()], headerGroups => {
2801
+ return headerGroups.map(headerGroup => {
2802
+ return headerGroup.headers;
2803
+ }).flat();
2804
+ }, {
2805
+ key: process.env.NODE_ENV === 'development' && 'getFlatHeaders',
2806
+ debug: () => {
2807
+ var _instance$options$deb9;
2808
+
2809
+ return (_instance$options$deb9 = instance.options.debugAll) != null ? _instance$options$deb9 : instance.options.debugHeaders;
2810
+ }
2811
+ }),
2812
+ getLeftFlatHeaders: memo(() => [instance.getLeftHeaderGroups()], left => {
2813
+ return left.map(headerGroup => {
2814
+ return headerGroup.headers;
2815
+ }).flat();
2816
+ }, {
2817
+ key: process.env.NODE_ENV === 'development' && 'getLeftFlatHeaders',
2818
+ debug: () => {
2819
+ var _instance$options$deb10;
2820
+
2821
+ return (_instance$options$deb10 = instance.options.debugAll) != null ? _instance$options$deb10 : instance.options.debugHeaders;
2822
+ }
2823
+ }),
2824
+ getCenterFlatHeaders: memo(() => [instance.getCenterHeaderGroups()], left => {
2825
+ return left.map(headerGroup => {
2826
+ return headerGroup.headers;
2827
+ }).flat();
2828
+ }, {
2829
+ key: process.env.NODE_ENV === 'development' && 'getCenterFlatHeaders',
2830
+ debug: () => {
2831
+ var _instance$options$deb11;
2832
+
2833
+ return (_instance$options$deb11 = instance.options.debugAll) != null ? _instance$options$deb11 : instance.options.debugHeaders;
2834
+ }
2835
+ }),
2836
+ getRightFlatHeaders: memo(() => [instance.getRightHeaderGroups()], left => {
2837
+ return left.map(headerGroup => {
2838
+ return headerGroup.headers;
2839
+ }).flat();
2840
+ }, {
2841
+ key: process.env.NODE_ENV === 'development' && 'getRightFlatHeaders',
2842
+ debug: () => {
2843
+ var _instance$options$deb12;
2844
+
2845
+ return (_instance$options$deb12 = instance.options.debugAll) != null ? _instance$options$deb12 : instance.options.debugHeaders;
2846
+ }
2847
+ }),
2848
+ // Leaf Headers
2849
+ getCenterLeafHeaders: memo(() => [instance.getCenterFlatHeaders()], flatHeaders => {
2850
+ return flatHeaders.filter(header => {
2851
+ var _header$subHeaders;
2852
+
2853
+ return !((_header$subHeaders = header.subHeaders) != null && _header$subHeaders.length);
2854
+ });
2855
+ }, {
2856
+ key: process.env.NODE_ENV === 'development' && 'getCenterLeafHeaders',
2857
+ debug: () => {
2858
+ var _instance$options$deb13;
2859
+
2860
+ return (_instance$options$deb13 = instance.options.debugAll) != null ? _instance$options$deb13 : instance.options.debugHeaders;
2861
+ }
2862
+ }),
2863
+ getLeftLeafHeaders: memo(() => [instance.getLeftFlatHeaders()], flatHeaders => {
2864
+ return flatHeaders.filter(header => {
2865
+ var _header$subHeaders2;
2866
+
2867
+ return !((_header$subHeaders2 = header.subHeaders) != null && _header$subHeaders2.length);
2868
+ });
2869
+ }, {
2870
+ key: process.env.NODE_ENV === 'development' && 'getLeftLeafHeaders',
2871
+ debug: () => {
2872
+ var _instance$options$deb14;
2873
+
2874
+ return (_instance$options$deb14 = instance.options.debugAll) != null ? _instance$options$deb14 : instance.options.debugHeaders;
2875
+ }
2876
+ }),
2877
+ getRightLeafHeaders: memo(() => [instance.getRightFlatHeaders()], flatHeaders => {
2878
+ return flatHeaders.filter(header => {
2879
+ var _header$subHeaders3;
2880
+
2881
+ return !((_header$subHeaders3 = header.subHeaders) != null && _header$subHeaders3.length);
2882
+ });
2883
+ }, {
2884
+ key: process.env.NODE_ENV === 'development' && 'getRightLeafHeaders',
2885
+ debug: () => {
2886
+ var _instance$options$deb15;
2887
+
2888
+ return (_instance$options$deb15 = instance.options.debugAll) != null ? _instance$options$deb15 : instance.options.debugHeaders;
2889
+ }
2890
+ }),
2891
+ getLeafHeaders: memo(() => [instance.getLeftHeaderGroups(), instance.getCenterHeaderGroups(), instance.getRightHeaderGroups()], (left, center, right) => {
2892
+ var _left$0$headers, _left$, _center$0$headers, _center$, _right$0$headers, _right$;
2893
+
2894
+ return [...((_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(header => {
2895
+ return header.getLeafHeaders();
2896
+ }).flat();
2897
+ }, {
2898
+ key: process.env.NODE_ENV === 'development' && 'getLeafHeaders',
2899
+ debug: () => {
2900
+ var _instance$options$deb16;
2901
+
2902
+ return (_instance$options$deb16 = instance.options.debugAll) != null ? _instance$options$deb16 : instance.options.debugHeaders;
2903
+ }
2904
+ }),
2905
+ getHeader: id => {
2906
+ const header = [...instance.getFlatHeaders(), ...instance.getCenterFlatHeaders(), ...instance.getLeftFlatHeaders(), ...instance.getRightFlatHeaders()].find(d => d.id === id);
2907
+
2908
+ if (!header) {
2909
+ if (process.env.NODE_ENV !== 'production') {
2910
+ console.warn("Could not find header with id: " + id);
2911
+ }
2912
+
2913
+ throw new Error();
2914
+ }
2915
+
2916
+ return header;
2917
+ }
2918
+ };
2919
+ }
2920
+ };
2921
+ function buildHeaderGroups(allColumns, columnsToGroup, instance, headerFamily) {
2922
+ var _headerGroups$0$heade, _headerGroups$;
2923
+
2924
+ // Find the max depth of the columns:
2925
+ // build the leaf column row
2926
+ // build each buffer row going up
2927
+ // placeholder for non-existent level
2928
+ // real column for existing level
2929
+ let maxDepth = 0;
2930
+
2931
+ const findMaxDepth = function (columns, depth) {
2932
+ if (depth === void 0) {
2933
+ depth = 1;
2934
+ }
2935
+
2936
+ maxDepth = Math.max(maxDepth, depth);
2937
+ columns.filter(column => column.getIsVisible()).forEach(column => {
2938
+ var _column$columns;
2939
+
2940
+ if ((_column$columns = column.columns) != null && _column$columns.length) {
2941
+ findMaxDepth(column.columns, depth + 1);
2942
+ }
2943
+ }, 0);
2944
+ };
2945
+
2946
+ findMaxDepth(allColumns);
2947
+ let headerGroups = [];
2948
+
2949
+ const createHeaderGroup = (headersToGroup, depth) => {
2950
+ // The header group we are creating
2951
+ const headerGroup = {
2952
+ depth,
2953
+ id: [headerFamily, "" + depth].filter(Boolean).join('_'),
2954
+ headers: []
2955
+ }; // The parent columns we're going to scan next
2956
+
2957
+ const pendingParentHeaders = []; // Scan each column for parents
2958
+
2959
+ headersToGroup.forEach(headerToGroup => {
2960
+ // What is the latest (last) parent column?
2961
+ const latestPendingParentHeader = [...pendingParentHeaders].reverse()[0];
2962
+ const isLeafHeader = headerToGroup.column.depth === headerGroup.depth;
2963
+ let column;
2964
+ let isPlaceholder = false;
2965
+
2966
+ if (isLeafHeader && headerToGroup.column.parent) {
2967
+ // The parent header is new
2968
+ column = headerToGroup.column.parent;
2969
+ } else {
2970
+ // The parent header is repeated
2971
+ column = headerToGroup.column;
2972
+ isPlaceholder = true;
2973
+ }
2974
+
2975
+ if ((latestPendingParentHeader == null ? void 0 : latestPendingParentHeader.column) === column) {
2976
+ // This column is repeated. Add it as a sub header to the next batch
2977
+ latestPendingParentHeader.subHeaders.push(headerToGroup);
2978
+ } else {
2979
+ // This is a new header. Let's create it
2980
+ const header = instance.createHeader(column, {
2981
+ id: [headerFamily, depth, column.id, headerToGroup == null ? void 0 : headerToGroup.id].filter(Boolean).join('_'),
2982
+ isPlaceholder,
2983
+ placeholderId: isPlaceholder ? "" + pendingParentHeaders.filter(d => d.column === column).length : undefined,
2984
+ depth,
2985
+ index: pendingParentHeaders.length
2986
+ }); // Add the headerToGroup as a subHeader of the new header
2987
+
2988
+ header.subHeaders.push(headerToGroup); // Add the new header to the pendingParentHeaders to get grouped
2989
+ // in the next batch
2990
+
2991
+ pendingParentHeaders.push(header);
2992
+ }
2993
+
2994
+ headerGroup.headers.push(headerToGroup);
2995
+ headerToGroup.headerGroup = headerGroup;
2996
+ });
2997
+ headerGroups.push(headerGroup);
2998
+
2999
+ if (depth > 0) {
3000
+ createHeaderGroup(pendingParentHeaders, depth - 1);
3001
+ }
3002
+ };
3003
+
3004
+ const bottomHeaders = columnsToGroup.map((column, index) => instance.createHeader(column, {
3005
+ depth: maxDepth,
3006
+ index
3007
+ }));
3008
+ createHeaderGroup(bottomHeaders, maxDepth - 1);
3009
+ headerGroups.reverse(); // headerGroups = headerGroups.filter(headerGroup => {
3010
+ // return !headerGroup.headers.every(header => header.isPlaceholder)
3011
+ // })
3012
+
3013
+ const recurseHeadersForSpans = headers => {
3014
+ const filteredHeaders = headers.filter(header => header.column.getIsVisible());
3015
+ return filteredHeaders.map(header => {
3016
+ let colSpan = 0;
3017
+ let rowSpan = 0;
3018
+ let childRowSpans = [0];
3019
+
3020
+ if (header.subHeaders && header.subHeaders.length) {
3021
+ childRowSpans = [];
3022
+ recurseHeadersForSpans(header.subHeaders).forEach(_ref => {
3023
+ let {
3024
+ colSpan: childColSpan,
3025
+ rowSpan: childRowSpan
3026
+ } = _ref;
3027
+ colSpan += childColSpan;
3028
+ childRowSpans.push(childRowSpan);
3029
+ });
3030
+ } else {
3031
+ colSpan = 1;
3032
+ }
3033
+
3034
+ const minChildRowSpan = Math.min(...childRowSpans);
3035
+ rowSpan = rowSpan + minChildRowSpan;
3036
+ header.colSpan = colSpan > 0 ? colSpan : undefined;
3037
+ header.rowSpan = rowSpan > 0 ? rowSpan : undefined;
3038
+ return {
3039
+ colSpan,
3040
+ rowSpan
3041
+ };
3042
+ });
3043
+ };
3044
+
3045
+ recurseHeadersForSpans((_headerGroups$0$heade = (_headerGroups$ = headerGroups[0]) == null ? void 0 : _headerGroups$.headers) != null ? _headerGroups$0$heade : []);
3046
+ return headerGroups;
3047
+ }
3048
+
3049
+ // export type Batch = {
3050
+ // id: number
3051
+ // priority: keyof CoreBatches
3052
+ // tasks: (() => void)[]
3053
+ // schedule: (cb: () => void) => void
3054
+ // cancel: () => void
3055
+ // }
3056
+ // type CoreBatches = {
3057
+ // data: Batch[]
3058
+ // facets: Batch[]
3059
+ // }
3060
+ function createTableInstance(options) {
3061
+ var _options$initialState;
3062
+
3063
+ if (options.debugAll || options.debugTable) {
3064
+ console.info('Creating Table Instance...');
3065
+ }
3066
+
3067
+ let instance = {
3068
+ _features: [Columns, Rows, Cells, Headers, Visibility, Ordering, Pinning, Filters, Sorting, Grouping, Expanding, Pagination, RowSelection, ColumnSizing]
3069
+ };
3070
+
3071
+ const defaultOptions = instance._features.reduce((obj, feature) => {
3072
+ return Object.assign(obj, feature.getDefaultOptions == null ? void 0 : feature.getDefaultOptions(instance));
3073
+ }, {});
3074
+
3075
+ const mergeOptions = options => {
3076
+ if (instance.options.mergeOptions) {
3077
+ return instance.options.mergeOptions(defaultOptions, options);
3078
+ }
3079
+
3080
+ return { ...defaultOptions,
3081
+ ...options
3082
+ };
3083
+ };
3084
+
3085
+ const coreInitialState = {// coreProgress: 1,
3086
+ };
3087
+ let initialState = { ...coreInitialState,
3088
+ ...((_options$initialState = options.initialState) != null ? _options$initialState : {})
3089
+ };
3090
+
3091
+ instance._features.forEach(feature => {
3092
+ var _feature$getInitialSt;
3093
+
3094
+ initialState = (_feature$getInitialSt = feature.getInitialState == null ? void 0 : feature.getInitialState(initialState)) != null ? _feature$getInitialSt : initialState;
3095
+ });
3096
+
3097
+ const queued = [];
3098
+ let queuedTimeout = false;
3099
+ const midInstance = { ...instance,
3100
+ // init: () => {
3101
+ // startWork()
3102
+ // },
3103
+ // willUpdate: () => {
3104
+ // startWork()
3105
+ // },
3106
+ // destroy: () => {
3107
+ // stopWork()
3108
+ // },
3109
+ options: { ...defaultOptions,
3110
+ ...options
3111
+ },
3112
+ initialState,
3113
+ _queue: cb => {
3114
+ queued.push(cb);
3115
+
3116
+ if (!queuedTimeout) {
3117
+ queuedTimeout = true; // Schedule a microtask to run the queued callbacks after
3118
+ // the current call stack (render, etc) has finished.
3119
+
3120
+ Promise.resolve().then(() => {
3121
+ while (queued.length) {
3122
+ queued.shift()();
3123
+ }
3124
+
3125
+ queuedTimeout = false;
3126
+ }).catch(error => setTimeout(() => {
3127
+ throw error;
3128
+ }));
3129
+ }
3130
+ },
3131
+ reset: () => {
3132
+ instance.setState(instance.initialState);
3133
+ },
3134
+ setOptions: updater => {
3135
+ const newOptions = functionalUpdate(updater, instance.options);
3136
+ instance.options = mergeOptions(newOptions);
3137
+ },
3138
+ _render: (template, props) => {
3139
+ if (typeof instance.options.render === 'function') {
3140
+ return instance.options.render(template, props);
3141
+ }
3142
+
3143
+ if (typeof template === 'function') {
3144
+ return template(props);
3145
+ }
3146
+
3147
+ return template;
3148
+ },
3149
+ getState: () => {
3150
+ return instance.options.state;
3151
+ },
3152
+ setState: updater => {
3153
+ instance.options.onStateChange == null ? void 0 : instance.options.onStateChange(updater);
3154
+ } // getOverallProgress: () => {
3155
+ // const { coreProgress, filtersProgress, facetProgress } =
3156
+ // instance.getState()
3157
+ // return mean(() =>
3158
+ // [coreProgress, filtersProgress].filter(d => d < 1)
3159
+ // ) as number
3160
+ // },
3161
+ // getProgressStage: () => {
3162
+ // const { coreProgress, filtersProgress, facetProgress } =
3163
+ // instance.getState()
3164
+ // if (coreProgress < 1) {
3165
+ // return 'coreRowModel'
3166
+ // }
3167
+ // if (filtersProgress < 1) {
3168
+ // return 'filteredRowModel'
3169
+ // }
3170
+ // if (Object.values(facetProgress).some(d => d < 1)) {
3171
+ // return 'facetedRowModel'
3172
+ // }
3173
+ // },
3174
+
3175
+ };
3176
+ instance = Object.assign(instance, midInstance);
3177
+
3178
+ instance._features.forEach(feature => {
3179
+ return Object.assign(instance, feature.createInstance == null ? void 0 : feature.createInstance(instance));
3180
+ });
3181
+
3182
+ return instance;
3183
+ }
3184
+
3185
+ //
3186
+ function createTableFactory(opts) {
3187
+ return () => createTable(undefined, undefined, opts);
3188
+ } // A lot of returns in here are `as any` for a reason. Unless you
3189
+ // can find a better way to do this, then don't worry about them
3190
+
3191
+ function createTable(_, __, options) {
3192
+ const table = {
3193
+ generics: undefined,
3194
+ options: options != null ? options : {
3195
+ render: (() => {
3196
+ throw new Error('');
3197
+ })()
3198
+ },
3199
+ // setGenerics: () => table as any,
3200
+ setRowType: () => table,
3201
+ setTableMetaType: () => table,
3202
+ setColumnMetaType: () => table,
3203
+ setFilterMetaType: () => table,
3204
+ setOptions: newOptions => createTable(_, __, { ...options,
3205
+ ...newOptions
3206
+ }),
3207
+ createDisplayColumn: column => ({ ...column,
3208
+ columnDefType: 'display'
3209
+ }),
3210
+ createGroup: column => ({ ...column,
3211
+ columnDefType: 'group'
3212
+ }),
3213
+ createDataColumn: (accessor, column) => {
3214
+ column = { ...column,
3215
+ columnDefType: 'data',
3216
+ id: column.id
3217
+ };
3218
+
3219
+ if (typeof accessor === 'string') {
3220
+ var _column$id;
3221
+
3222
+ return { ...column,
3223
+ id: (_column$id = column.id) != null ? _column$id : accessor,
3224
+ accessorKey: accessor
3225
+ };
3226
+ }
3227
+
3228
+ if (typeof accessor === 'function') {
3229
+ return { ...column,
3230
+ accessorFn: accessor
3231
+ };
3232
+ }
3233
+
3234
+ throw new Error('Invalid accessor');
3235
+ },
3236
+ createOptions: options => options
3237
+ };
3238
+ return table;
3239
+ }
3240
+
3241
+ function getCoreRowModel() {
3242
+ return instance => memo(() => [instance.options.data], data => {
3243
+ const rowModel = {
3244
+ rows: [],
3245
+ flatRows: [],
3246
+ rowsById: {}
3247
+ };
3248
+ let rows;
3249
+ let row;
3250
+ let originalRow;
3251
+
3252
+ const accessRows = function (originalRows, depth, parent) {
3253
+ if (depth === void 0) {
3254
+ depth = 0;
3255
+ }
3256
+
3257
+ rows = [];
3258
+
3259
+ for (let i = 0; i < originalRows.length; i++) {
3260
+ originalRow = originalRows[i]; // This could be an expensive check at scale, so we should move it somewhere else, but where?
3261
+ // if (!id) {
3262
+ // if (process.env.NODE_ENV !== 'production') {
3263
+ // throw new Error(`getRowId expected an ID, but got ${id}`)
3264
+ // }
3265
+ // }
3266
+ // Make the row
3267
+
3268
+ row = instance.createRow(instance.getRowId(originalRow, i, parent), originalRow, i, depth); // Keep track of every row in a flat array
3269
+
3270
+ rowModel.flatRows.push(row); // Also keep track of every row by its ID
3271
+
3272
+ rowModel.rowsById[row.id] = row; // Push instance row into parent
3273
+
3274
+ rows.push(row); // Get the original subrows
3275
+
3276
+ if (instance.options.getSubRows) {
3277
+ var _row$originalSubRows;
3278
+
3279
+ row.originalSubRows = instance.options.getSubRows(originalRow, i); // Then recursively access them
3280
+
3281
+ if ((_row$originalSubRows = row.originalSubRows) != null && _row$originalSubRows.length) {
3282
+ row.subRows = accessRows(row.originalSubRows, depth + 1, row);
3283
+ }
3284
+ }
3285
+ }
3286
+
3287
+ return rows;
3288
+ };
3289
+
3290
+ rowModel.rows = accessRows(data);
3291
+ return rowModel;
3292
+ }, {
3293
+ key: process.env.NODE_ENV === 'development' && 'getRowModel',
3294
+ debug: () => {
3295
+ var _instance$options$deb;
3296
+
3297
+ return (_instance$options$deb = instance.options.debugAll) != null ? _instance$options$deb : instance.options.debugTable;
3298
+ },
3299
+ onChange: () => {
3300
+ instance._autoResetPageIndex();
3301
+ }
3302
+ });
3303
+ }
3304
+
3305
+ function filterRows(rows, filterRowImpl, instance) {
3306
+ if (instance.options.filterFromLeafRows) {
3307
+ return filterRowModelFromLeafs(rows, filterRowImpl, instance);
3308
+ }
3309
+
3310
+ return filterRowModelFromRoot(rows, filterRowImpl, instance);
3311
+ }
3312
+ function filterRowModelFromLeafs(rowsToFilter, filterRow, instance) {
3313
+ const newFilteredFlatRows = [];
3314
+ const newFilteredRowsById = {};
3315
+ let row;
3316
+ let newRow;
3317
+
3318
+ const recurseFilterRows = function (rowsToFilter, depth) {
3319
+ if (depth === void 0) {
3320
+ depth = 0;
3321
+ }
3322
+
3323
+ const rows = []; // Filter from children up first
3324
+
3325
+ for (let i = 0; i < rowsToFilter.length; i++) {
3326
+ var _row$subRows;
3327
+
3328
+ row = rowsToFilter[i];
3329
+
3330
+ if ((_row$subRows = row.subRows) != null && _row$subRows.length) {
3331
+ newRow = instance.createRow(row.id, row.original, row.index, row.depth);
3332
+ newRow.columnFilters = row.columnFilters;
3333
+ newRow.subRows = recurseFilterRows(row.subRows, depth + 1);
3334
+
3335
+ if (!newRow.subRows.length) {
3336
+ continue;
3337
+ }
3338
+
3339
+ row = newRow;
3340
+ }
3341
+
3342
+ if (filterRow(row)) {
3343
+ rows.push(row);
3344
+ newFilteredRowsById[row.id] = row;
3345
+ newFilteredRowsById[i] = row;
3346
+ }
3347
+ }
3348
+
3349
+ return rows;
3350
+ };
3351
+
3352
+ return {
3353
+ rows: recurseFilterRows(rowsToFilter),
3354
+ flatRows: newFilteredFlatRows,
3355
+ rowsById: newFilteredRowsById
3356
+ };
3357
+ }
3358
+ function filterRowModelFromRoot(rowsToFilter, filterRow, instance) {
3359
+ const newFilteredFlatRows = [];
3360
+ const newFilteredRowsById = {};
3361
+ let rows;
3362
+ let row;
3363
+ let newRow; // Filters top level and nested rows
3364
+
3365
+ const recurseFilterRows = function (rowsToFilter, depth) {
3366
+ if (depth === void 0) {
3367
+ depth = 0;
3368
+ }
3369
+
3370
+ // Filter from parents downward first
3371
+ rows = []; // Apply the filter to any subRows
3372
+
3373
+ for (let i = 0; i < rowsToFilter.length; i++) {
3374
+ row = rowsToFilter[i];
3375
+ const pass = filterRow(row);
3376
+
3377
+ if (pass) {
3378
+ var _row$subRows2;
3379
+
3380
+ if ((_row$subRows2 = row.subRows) != null && _row$subRows2.length) {
3381
+ newRow = instance.createRow(row.id, row.original, row.index, row.depth);
3382
+ newRow.subRows = recurseFilterRows(row.subRows, depth + 1);
3383
+ row = newRow;
3384
+ }
3385
+
3386
+ rows.push(row);
3387
+ newFilteredFlatRows.push(row);
3388
+ newFilteredRowsById[row.id] = row;
3389
+ }
3390
+ }
3391
+
3392
+ return rows;
3393
+ };
3394
+
3395
+ return {
3396
+ rows: recurseFilterRows(rowsToFilter),
3397
+ flatRows: newFilteredFlatRows,
3398
+ rowsById: newFilteredRowsById
3399
+ };
3400
+ }
3401
+
3402
+ function getFilteredRowModel() {
3403
+ return instance => memo(() => [instance.getPreFilteredRowModel(), instance.getState().columnFilters, instance.getState().globalFilter], (rowModel, columnFilters, globalFilter) => {
3404
+ if (!rowModel.rows.length || !(columnFilters != null && columnFilters.length) && !globalFilter) {
3405
+ for (let i = 0; i < rowModel.flatRows.length; i++) {
3406
+ rowModel.flatRows[i].columnFilters = {};
3407
+ rowModel.flatRows[i].columnFiltersMeta = {};
3408
+ }
3409
+
3410
+ return rowModel;
3411
+ }
3412
+
3413
+ const resolvedColumnFilters = [];
3414
+ const resolvedGlobalFilters = [];
3415
+ (columnFilters != null ? columnFilters : []).forEach(d => {
3416
+ var _filterFn$resolveFilt;
3417
+
3418
+ const column = instance.getColumn(d.id);
3419
+
3420
+ if (!column) {
3421
+ if (process.env.NODE_ENV !== 'production') {
3422
+ console.warn("Table: Could not find a column to filter with columnId: " + d.id);
3423
+ }
3424
+ }
3425
+
3426
+ const filterFn = column.getFilterFn();
3427
+
3428
+ if (!filterFn) {
3429
+ if (process.env.NODE_ENV !== 'production') {
3430
+ console.warn("Could not find a valid 'column.filterFn' for column with the ID: " + column.id + ".");
3431
+ }
3432
+
3433
+ return;
3434
+ }
3435
+
3436
+ resolvedColumnFilters.push({
3437
+ id: d.id,
3438
+ filterFn,
3439
+ resolvedValue: (_filterFn$resolveFilt = filterFn.resolveFilterValue == null ? void 0 : filterFn.resolveFilterValue(d.value)) != null ? _filterFn$resolveFilt : d.value
3440
+ });
3441
+ });
3442
+ const filterableIds = columnFilters.map(d => d.id);
3443
+ const globalFilterFn = instance.getGlobalFilterFn();
3444
+ const globallyFilterableColumns = instance.getAllLeafColumns().filter(column => column.getCanGlobalFilter());
3445
+
3446
+ if (globalFilter && globalFilterFn && globallyFilterableColumns.length) {
3447
+ filterableIds.push('__global__');
3448
+ globallyFilterableColumns.forEach(column => {
3449
+ var _globalFilterFn$resol;
3450
+
3451
+ resolvedGlobalFilters.push({
3452
+ id: column.id,
3453
+ filterFn: globalFilterFn,
3454
+ resolvedValue: (_globalFilterFn$resol = globalFilterFn.resolveFilterValue == null ? void 0 : globalFilterFn.resolveFilterValue(globalFilter)) != null ? _globalFilterFn$resol : globalFilter
3455
+ });
3456
+ });
3457
+ }
3458
+
3459
+ let currentColumnFilter;
3460
+ let currentGlobalFilter; // Flag the prefiltered row model with each filter state
3461
+
3462
+ for (let j = 0; j < rowModel.flatRows.length; j++) {
3463
+ const row = rowModel.flatRows[j];
3464
+ row.columnFilters = {};
3465
+
3466
+ if (resolvedColumnFilters.length) {
3467
+ for (let i = 0; i < resolvedColumnFilters.length; i++) {
3468
+ currentColumnFilter = resolvedColumnFilters[i];
3469
+ const id = currentColumnFilter.id; // Tag the row with the column filter state
3470
+
3471
+ row.columnFilters[id] = currentColumnFilter.filterFn(row, id, currentColumnFilter.resolvedValue, filterMeta => {
3472
+ row.columnFiltersMeta[id] = filterMeta;
3473
+ });
3474
+ }
3475
+ }
3476
+
3477
+ if (resolvedGlobalFilters.length) {
3478
+ for (let i = 0; i < resolvedGlobalFilters.length; i++) {
3479
+ currentGlobalFilter = resolvedGlobalFilters[i];
3480
+ const id = currentGlobalFilter.id; // Tag the row with the first truthy global filter state
3481
+
3482
+ if (currentGlobalFilter.filterFn(row, id, currentGlobalFilter.resolvedValue, filterMeta => {
3483
+ row.columnFiltersMeta[id] = filterMeta;
3484
+ })) {
3485
+ row.columnFilters.__global__ = true;
3486
+ break;
3487
+ }
3488
+ }
3489
+
3490
+ if (row.columnFilters.__global__ !== true) {
3491
+ row.columnFilters.__global__ = false;
3492
+ }
3493
+ }
3494
+ }
3495
+
3496
+ const filterRowsImpl = row => {
3497
+ // Horizontally filter rows through each column
3498
+ for (let i = 0; i < filterableIds.length; i++) {
3499
+ if (row.columnFilters[filterableIds[i]] === false) {
3500
+ return false;
3501
+ }
3502
+ }
3503
+
3504
+ return true;
3505
+ }; // Filter final rows using all of the active filters
3506
+
3507
+
3508
+ return filterRows(rowModel.rows, filterRowsImpl, instance);
3509
+ }, {
3510
+ key: process.env.NODE_ENV === 'development' && 'getFilteredRowModel',
3511
+ debug: () => {
3512
+ var _instance$options$deb;
3513
+
3514
+ return (_instance$options$deb = instance.options.debugAll) != null ? _instance$options$deb : instance.options.debugTable;
3515
+ },
3516
+ onChange: () => {
3517
+ instance._autoResetPageIndex();
3518
+ }
3519
+ });
3520
+ }
3521
+
3522
+ function getFacetedRowModel() {
3523
+ return (instance, columnId) => memo(() => [instance.getPreFilteredRowModel(), instance.getState().columnFilters, instance.getState().globalFilter, instance.getFilteredRowModel()], (preRowModel, columnFilters, globalFilter) => {
3524
+ if (!preRowModel.rows.length || !(columnFilters != null && columnFilters.length) && !globalFilter) {
3525
+ return preRowModel;
3526
+ }
3527
+
3528
+ const filterableIds = [...columnFilters.map(d => d.id).filter(d => d !== columnId), globalFilter ? '__global__' : undefined].filter(Boolean);
3529
+
3530
+ const filterRowsImpl = row => {
3531
+ // Horizontally filter rows through each column
3532
+ for (let i = 0; i < filterableIds.length; i++) {
3533
+ if (row.columnFilters[filterableIds[i]] === false) {
3534
+ return false;
3535
+ }
3536
+ }
3537
+
3538
+ return true;
3539
+ };
3540
+
3541
+ return filterRows(preRowModel.rows, filterRowsImpl, instance);
3542
+ }, {
3543
+ key: process.env.NODE_ENV === 'development' && 'getFacetedRowModel_' + columnId,
3544
+ debug: () => {
3545
+ var _instance$options$deb;
3546
+
3547
+ return (_instance$options$deb = instance.options.debugAll) != null ? _instance$options$deb : instance.options.debugTable;
3548
+ },
3549
+ onChange: () => {}
3550
+ });
3551
+ }
3552
+
3553
+ function getFacetedUniqueValues() {
3554
+ return (instance, columnId) => memo(() => [instance.getColumn(columnId).getFacetedRowModel()], facetedRowModel => {
3555
+ let facetedUniqueValues = new Map();
3556
+
3557
+ for (let i = 0; i < facetedRowModel.flatRows.length; i++) {
3558
+ var _facetedRowModel$flat;
3559
+
3560
+ const value = (_facetedRowModel$flat = facetedRowModel.flatRows[i]) == null ? void 0 : _facetedRowModel$flat.getValue(columnId);
3561
+
3562
+ if (facetedUniqueValues.has(value)) {
3563
+ var _facetedUniqueValues$;
3564
+
3565
+ facetedUniqueValues.set(value, ((_facetedUniqueValues$ = facetedUniqueValues.get(value)) != null ? _facetedUniqueValues$ : 0) + 1);
3566
+ } else {
3567
+ facetedUniqueValues.set(value, 1);
3568
+ }
3569
+ }
3570
+
3571
+ return facetedUniqueValues;
3572
+ }, {
3573
+ key: process.env.NODE_ENV === 'development' && 'getFacetedUniqueValues_' + columnId,
3574
+ debug: () => {
3575
+ var _instance$options$deb;
3576
+
3577
+ return (_instance$options$deb = instance.options.debugAll) != null ? _instance$options$deb : instance.options.debugTable;
3578
+ },
3579
+ onChange: () => {}
3580
+ });
3581
+ }
3582
+
3583
+ function getFacetedMinMaxValues() {
3584
+ return (instance, columnId) => memo(() => [instance.getColumn(columnId).getFacetedRowModel()], facetedRowModel => {
3585
+ var _facetedRowModel$flat;
3586
+
3587
+ const firstValue = (_facetedRowModel$flat = facetedRowModel.flatRows[0]) == null ? void 0 : _facetedRowModel$flat.getValue(columnId);
3588
+
3589
+ if (typeof firstValue === 'undefined') {
3590
+ return undefined;
3591
+ }
3592
+
3593
+ let facetedMinMaxValues = [firstValue, firstValue];
3594
+
3595
+ for (let i = 0; i < facetedRowModel.flatRows.length; i++) {
3596
+ var _facetedRowModel$flat2;
3597
+
3598
+ const value = (_facetedRowModel$flat2 = facetedRowModel.flatRows[i]) == null ? void 0 : _facetedRowModel$flat2.getValue(columnId);
3599
+
3600
+ if (value < facetedMinMaxValues[0]) {
3601
+ facetedMinMaxValues[0] = value;
3602
+ } else if (value > facetedMinMaxValues[1]) {
3603
+ facetedMinMaxValues[1] = value;
3604
+ }
3605
+ }
3606
+
3607
+ return facetedMinMaxValues;
3608
+ }, {
3609
+ key: process.env.NODE_ENV === 'development' && 'getFacetedMinMaxValues_' + columnId,
3610
+ debug: () => {
3611
+ var _instance$options$deb;
3612
+
3613
+ return (_instance$options$deb = instance.options.debugAll) != null ? _instance$options$deb : instance.options.debugTable;
3614
+ },
3615
+ onChange: () => {}
3616
+ });
3617
+ }
3618
+
3619
+ function getSortedRowModel() {
3620
+ return instance => memo(() => [instance.getState().sorting, instance.getPreSortedRowModel()], (sorting, rowModel) => {
3621
+ if (!rowModel.rows.length || !(sorting != null && sorting.length)) {
3622
+ return rowModel;
3623
+ }
3624
+
3625
+ const sortingState = instance.getState().sorting;
3626
+ const sortedFlatRows = []; // Filter out sortings that correspond to non existing columns
3627
+
3628
+ const availableSorting = sortingState.filter(sort => instance.getColumn(sort.id).getCanSort());
3629
+ const columnInfoById = {};
3630
+ availableSorting.forEach(sortEntry => {
3631
+ const column = instance.getColumn(sortEntry.id);
3632
+ columnInfoById[sortEntry.id] = {
3633
+ sortUndefined: column.columnDef.sortUndefined,
3634
+ invertSorting: column.columnDef.invertSorting,
3635
+ sortingFn: column.getSortingFn()
3636
+ };
3637
+ });
3638
+
3639
+ const sortData = rows => {
3640
+ // This will also perform a stable sorting using the row index
3641
+ // if needed.
3642
+ const sortedData = rows.slice();
3643
+ sortedData.sort((rowA, rowB) => {
3644
+ for (let i = 0; i < availableSorting.length; i += 1) {
3645
+ var _sortEntry$desc;
3646
+
3647
+ const sortEntry = availableSorting[i];
3648
+ const columnInfo = columnInfoById[sortEntry.id];
3649
+ const isDesc = (_sortEntry$desc = sortEntry == null ? void 0 : sortEntry.desc) != null ? _sortEntry$desc : false;
3650
+
3651
+ if (columnInfo.sortUndefined) {
3652
+ const aValue = rowA.getValue(sortEntry.id);
3653
+ const bValue = rowB.getValue(sortEntry.id);
3654
+ const aUndefined = typeof aValue === 'undefined';
3655
+ const bUndefined = typeof bValue === 'undefined';
3656
+
3657
+ if (aUndefined || bUndefined) {
3658
+ return aUndefined && bUndefined ? 0 : aUndefined ? columnInfo.sortUndefined : -columnInfo.sortUndefined;
3659
+ }
3660
+ } // This function should always return in ascending order
3661
+
3662
+
3663
+ let sortInt = columnInfo.sortingFn(rowA, rowB, sortEntry.id);
3664
+
3665
+ if (sortInt !== 0) {
3666
+ if (isDesc) {
3667
+ sortInt *= -1;
3668
+ }
3669
+
3670
+ if (columnInfo.invertSorting) {
3671
+ sortInt *= -1;
3672
+ }
3673
+
3674
+ return sortInt;
3675
+ }
3676
+ }
3677
+
3678
+ return rowA.index - rowB.index;
3679
+ }); // If there are sub-rows, sort them
3680
+
3681
+ sortedData.forEach(row => {
3682
+ sortedFlatRows.push(row);
3683
+
3684
+ if (!row.subRows || row.subRows.length <= 1) {
3685
+ return;
3686
+ }
3687
+
3688
+ row.subRows = sortData(row.subRows);
3689
+ });
3690
+ return sortedData;
3691
+ };
3692
+
3693
+ return {
3694
+ rows: sortData(rowModel.rows),
3695
+ flatRows: sortedFlatRows,
3696
+ rowsById: rowModel.rowsById
3697
+ };
3698
+ }, {
3699
+ key: process.env.NODE_ENV === 'development' && 'getSortedRowModel',
3700
+ debug: () => {
3701
+ var _instance$options$deb;
3702
+
3703
+ return (_instance$options$deb = instance.options.debugAll) != null ? _instance$options$deb : instance.options.debugTable;
3704
+ },
3705
+ onChange: () => {
3706
+ instance._autoResetPageIndex();
3707
+ }
3708
+ });
3709
+ }
3710
+
3711
+ function getGroupedRowModel() {
3712
+ return instance => memo(() => [instance.getState().grouping, instance.getPreGroupedRowModel()], (grouping, rowModel) => {
3713
+ if (!rowModel.rows.length || !grouping.length) {
3714
+ return rowModel;
3715
+ } // Filter the grouping list down to columns that exist
3716
+
3717
+
3718
+ const existingGrouping = grouping.filter(columnId => instance.getColumn(columnId));
3719
+ const groupedFlatRows = [];
3720
+ const groupedRowsById = {}; // const onlyGroupedFlatRows: Row[] = [];
3721
+ // const onlyGroupedRowsById: Record<RowId, Row> = {};
3722
+ // const nonGroupedFlatRows: Row[] = [];
3723
+ // const nonGroupedRowsById: Record<RowId, Row> = {};
3724
+ // Recursively group the data
3725
+
3726
+ const groupUpRecursively = function (rows, depth, parentId) {
3727
+ if (depth === void 0) {
3728
+ depth = 0;
3729
+ }
3730
+
3731
+ // This is the last level, just return the rows
3732
+ if (depth === existingGrouping.length) {
3733
+ return rows;
3734
+ }
3735
+
3736
+ const columnId = existingGrouping[depth]; // Group the rows together for this level
3737
+
3738
+ const rowGroupsMap = groupBy(rows, columnId); // Peform aggregations for each group
3739
+
3740
+ const aggregatedGroupedRows = Array.from(rowGroupsMap.entries()).map((_ref, index) => {
3741
+ let [groupingValue, groupedRows] = _ref;
3742
+ let id = columnId + ":" + groupingValue;
3743
+ id = parentId ? parentId + ">" + id : id; // First, Recurse to group sub rows before aggregation
3744
+
3745
+ const subRows = groupUpRecursively(groupedRows, depth + 1, id); // Flatten the leaf rows of the rows in this group
3746
+
3747
+ const leafRows = depth ? flattenBy(groupedRows, row => row.subRows) : groupedRows;
3748
+ const row = instance.createRow(id, undefined, index, depth);
3749
+ Object.assign(row, {
3750
+ groupingColumnId: columnId,
3751
+ groupingValue,
3752
+ subRows,
3753
+ leafRows,
3754
+ getValue: columnId => {
3755
+ // Don't aggregate columns that are in the grouping
3756
+ if (existingGrouping.includes(columnId)) {
3757
+ if (row.valuesCache.hasOwnProperty(columnId)) {
3758
+ return row.valuesCache[columnId];
3759
+ }
3760
+
3761
+ if (groupedRows[0]) {
3762
+ var _groupedRows$0$getVal;
3763
+
3764
+ row.valuesCache[columnId] = (_groupedRows$0$getVal = groupedRows[0].getValue(columnId)) != null ? _groupedRows$0$getVal : undefined;
3765
+ }
3766
+
3767
+ return row.valuesCache[columnId];
3768
+ }
3769
+
3770
+ if (row.groupingValuesCache.hasOwnProperty(columnId)) {
3771
+ return row.groupingValuesCache[columnId];
3772
+ } // Aggregate the values
3773
+
3774
+
3775
+ const column = instance.getColumn(columnId);
3776
+ const aggregateFn = column.getColumnAggregationFn();
3777
+
3778
+ if (aggregateFn) {
3779
+ row.groupingValuesCache[columnId] = aggregateFn(() => leafRows.map(row => {
3780
+ let columnValue = row.getValue(columnId);
3781
+
3782
+ if (!depth && column.columnDef.aggregateValue) {
3783
+ columnValue = column.columnDef.aggregateValue(columnValue);
3784
+ }
3785
+
3786
+ return columnValue;
3787
+ }), () => groupedRows.map(row => row.getValue(columnId)));
3788
+ return row.groupingValuesCache[columnId];
3789
+ } else if (column.aggregationFn) {
3790
+ console.info({
3791
+ column
3792
+ });
3793
+ throw new Error(process.env.NODE_ENV !== 'production' ? "Table: Invalid column.aggregateType option for column listed above" : '');
3794
+ }
3795
+ }
3796
+ });
3797
+ subRows.forEach(subRow => {
3798
+ groupedFlatRows.push(subRow);
3799
+ groupedRowsById[subRow.id] = subRow; // if (subRow.getIsGrouped?.()) {
3800
+ // onlyGroupedFlatRows.push(subRow);
3801
+ // onlyGroupedRowsById[subRow.id] = subRow;
3802
+ // } else {
3803
+ // nonGroupedFlatRows.push(subRow);
3804
+ // nonGroupedRowsById[subRow.id] = subRow;
3805
+ // }
3806
+ });
3807
+ return row;
3808
+ });
3809
+ return aggregatedGroupedRows;
3810
+ };
3811
+
3812
+ const groupedRows = groupUpRecursively(rowModel.rows, 0, '');
3813
+ groupedRows.forEach(subRow => {
3814
+ groupedFlatRows.push(subRow);
3815
+ groupedRowsById[subRow.id] = subRow; // if (subRow.getIsGrouped?.()) {
3816
+ // onlyGroupedFlatRows.push(subRow);
3817
+ // onlyGroupedRowsById[subRow.id] = subRow;
3818
+ // } else {
3819
+ // nonGroupedFlatRows.push(subRow);
3820
+ // nonGroupedRowsById[subRow.id] = subRow;
3821
+ // }
3822
+ });
3823
+ return {
3824
+ rows: groupedRows,
3825
+ flatRows: groupedFlatRows,
3826
+ rowsById: groupedRowsById
3827
+ };
3828
+ }, {
3829
+ key: process.env.NODE_ENV === 'development' && 'getGroupedRowModel',
3830
+ debug: () => {
3831
+ var _instance$options$deb;
3832
+
3833
+ return (_instance$options$deb = instance.options.debugAll) != null ? _instance$options$deb : instance.options.debugTable;
3834
+ },
3835
+ onChange: () => {
3836
+ instance._queue(() => {
3837
+ instance._autoResetExpanded();
3838
+
3839
+ instance._autoResetPageIndex();
3840
+ });
3841
+ }
3842
+ });
3843
+ }
3844
+
3845
+ function groupBy(rows, columnId) {
3846
+ const groupMap = new Map();
3847
+ return rows.reduce((map, row) => {
3848
+ const resKey = "" + row.getValue(columnId);
3849
+ const previous = map.get(resKey);
3850
+
3851
+ if (!previous) {
3852
+ map.set(resKey, [row]);
3853
+ } else {
3854
+ map.set(resKey, [...previous, row]);
3855
+ }
3856
+
3857
+ return map;
3858
+ }, groupMap);
3859
+ }
3860
+
3861
+ function getExpandedRowModel() {
3862
+ return instance => memo(() => [instance.getState().expanded, instance.getPreExpandedRowModel(), instance.options.paginateExpandedRows], (expanded, rowModel, paginateExpandedRows) => {
3863
+ if (!rowModel.rows.length || // Do not expand if rows are not included in pagination
3864
+ !paginateExpandedRows || expanded !== true && !Object.keys(expanded != null ? expanded : {}).length) {
3865
+ return rowModel;
3866
+ }
3867
+
3868
+ return expandRows(rowModel, instance);
3869
+ }, {
3870
+ key: process.env.NODE_ENV === 'development' && 'getExpandedRowModel',
3871
+ debug: () => {
3872
+ var _instance$options$deb;
3873
+
3874
+ return (_instance$options$deb = instance.options.debugAll) != null ? _instance$options$deb : instance.options.debugTable;
3875
+ }
3876
+ });
3877
+ }
3878
+ function expandRows(rowModel, instance) {
3879
+ const expandedRows = [];
3880
+
3881
+ const handleRow = row => {
3882
+ var _row$subRows;
3883
+
3884
+ expandedRows.push(row);
3885
+
3886
+ if (instance.options.expandSubRows && (_row$subRows = row.subRows) != null && _row$subRows.length && row.getIsExpanded()) {
3887
+ row.subRows.forEach(handleRow);
3888
+ }
3889
+ };
3890
+
3891
+ rowModel.rows.forEach(handleRow);
3892
+ return {
3893
+ rows: expandedRows,
3894
+ flatRows: rowModel.flatRows,
3895
+ rowsById: rowModel.rowsById
3896
+ };
3897
+ }
3898
+
3899
+ function getPaginationRowModel(opts) {
3900
+ return instance => memo(() => [instance.getState().pagination, instance.getPrePaginationRowModel()], (pagination, rowModel) => {
3901
+ if (!rowModel.rows.length) {
3902
+ return rowModel;
3903
+ }
3904
+
3905
+ const {
3906
+ pageSize,
3907
+ pageIndex
3908
+ } = pagination;
3909
+ let {
3910
+ rows,
3911
+ flatRows,
3912
+ rowsById
3913
+ } = rowModel;
3914
+ const pageStart = pageSize * pageIndex;
3915
+ const pageEnd = pageStart + pageSize;
3916
+ rows = rows.slice(pageStart, pageEnd);
3917
+
3918
+ if (!instance.options.paginateExpandedRows) {
3919
+ return expandRows({
3920
+ rows,
3921
+ flatRows,
3922
+ rowsById
3923
+ }, instance);
3924
+ }
3925
+
3926
+ return {
3927
+ rows,
3928
+ flatRows,
3929
+ rowsById
3930
+ };
3931
+ }, {
3932
+ key: process.env.NODE_ENV === 'development' && 'getPaginationRowModel',
3933
+ debug: () => {
3934
+ var _instance$options$deb;
3935
+
3936
+ return (_instance$options$deb = instance.options.debugAll) != null ? _instance$options$deb : instance.options.debugTable;
3937
+ }
3938
+ });
3939
+ }
3940
+
3941
+ exports.ColumnSizing = ColumnSizing;
3942
+ exports.Expanding = Expanding;
3943
+ exports.Filters = Filters;
3944
+ exports.Grouping = Grouping;
3945
+ exports.Headers = Headers;
3946
+ exports.Ordering = Ordering;
3947
+ exports.Pagination = Pagination;
3948
+ exports.Pinning = Pinning;
3949
+ exports.RowSelection = RowSelection;
3950
+ exports.Sorting = Sorting;
3951
+ exports.Visibility = Visibility;
3952
+ exports.aggregationFns = aggregationFns;
3953
+ exports.buildHeaderGroups = buildHeaderGroups;
3954
+ exports.createTableFactory = createTableFactory;
3955
+ exports.createTableInstance = createTableInstance;
3956
+ exports.defaultColumnSizing = defaultColumnSizing;
3957
+ exports.expandRows = expandRows;
3958
+ exports.filterFns = filterFns;
3959
+ exports.flattenBy = flattenBy;
3960
+ exports.functionalUpdate = functionalUpdate;
3961
+ exports.getCoreRowModel = getCoreRowModel;
3962
+ exports.getExpandedRowModel = getExpandedRowModel;
3963
+ exports.getFacetedMinMaxValues = getFacetedMinMaxValues;
3964
+ exports.getFacetedRowModel = getFacetedRowModel;
3965
+ exports.getFacetedUniqueValues = getFacetedUniqueValues;
3966
+ exports.getFilteredRowModel = getFilteredRowModel;
3967
+ exports.getGroupedRowModel = getGroupedRowModel;
3968
+ exports.getPaginationRowModel = getPaginationRowModel;
3969
+ exports.getSortedRowModel = getSortedRowModel;
3970
+ exports.isFunction = isFunction;
3971
+ exports.isRowSelected = isRowSelected;
3972
+ exports.makeStateUpdater = makeStateUpdater;
3973
+ exports.mean = mean;
3974
+ exports.memo = memo;
3975
+ exports.noop = noop;
3976
+ exports.orderColumns = orderColumns;
3977
+ exports.passiveEventSupported = passiveEventSupported;
3978
+ exports.reSplitAlphaNumeric = reSplitAlphaNumeric;
3979
+ exports.selectRowsFn = selectRowsFn;
3980
+ exports.shouldAutoRemoveFilter = shouldAutoRemoveFilter;
3981
+ exports.sortingFns = sortingFns;
3982
+ //# sourceMappingURL=index.js.map