@tanstack/svelte-table 8.0.0-alpha.67 → 8.0.0-alpha.70

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