@tanstack/react-table 8.0.0-alpha.64 → 8.0.0-alpha.68

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