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

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