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