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