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

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