@tanstack/svelte-table 8.6.0 → 8.7.0

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