@tanstack/svelte-table 8.5.30 → 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 +398 -179
  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 -3437
  26. package/build/cjs/table-core/build/esm/index.js.map +0 -1
  27. package/build/esm/index.js +0 -3578
  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,3578 +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
- globalFilterFn: 'auto',
971
- getColumnCanGlobalFilter: column => {
972
- var _table$getCoreRowMode, _table$getCoreRowMode2;
973
- const value = (_table$getCoreRowMode = table.getCoreRowModel().flatRows[0]) == null ? void 0 : (_table$getCoreRowMode2 = _table$getCoreRowMode._getAllCellsByColumnId()[column.id]) == null ? void 0 : _table$getCoreRowMode2.getValue();
974
- return typeof value === 'string' || typeof value === 'number';
975
- }
976
- };
977
- },
978
- createColumn: (column, table) => {
979
- return {
980
- getAutoFilterFn: () => {
981
- const firstRow = table.getCoreRowModel().flatRows[0];
982
- const value = firstRow == null ? void 0 : firstRow.getValue(column.id);
983
- if (typeof value === 'string') {
984
- return filterFns.includesString;
985
- }
986
- if (typeof value === 'number') {
987
- return filterFns.inNumberRange;
988
- }
989
- if (typeof value === 'boolean') {
990
- return filterFns.equals;
991
- }
992
- if (value !== null && typeof value === 'object') {
993
- return filterFns.equals;
994
- }
995
- if (Array.isArray(value)) {
996
- return filterFns.arrIncludes;
997
- }
998
- return filterFns.weakEquals;
999
- },
1000
- getFilterFn: () => {
1001
- var _table$options$filter;
1002
- 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];
1003
- },
1004
- getCanFilter: () => {
1005
- return (column.columnDef.enableColumnFilter ?? true) && (table.options.enableColumnFilters ?? true) && (table.options.enableFilters ?? true) && !!column.accessorFn;
1006
- },
1007
- getCanGlobalFilter: () => {
1008
- 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;
1009
- },
1010
- getIsFiltered: () => column.getFilterIndex() > -1,
1011
- getFilterValue: () => {
1012
- var _table$getState$colum, _table$getState$colum2;
1013
- 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;
1014
- },
1015
- getFilterIndex: () => {
1016
- var _table$getState$colum3;
1017
- return ((_table$getState$colum3 = table.getState().columnFilters) == null ? void 0 : _table$getState$colum3.findIndex(d => d.id === column.id)) ?? -1;
1018
- },
1019
- setFilterValue: value => {
1020
- table.setColumnFilters(old => {
1021
- const filterFn = column.getFilterFn();
1022
- const previousfilter = old == null ? void 0 : old.find(d => d.id === column.id);
1023
- const newFilter = functionalUpdate(value, previousfilter ? previousfilter.value : undefined);
1024
-
1025
- //
1026
- if (shouldAutoRemoveFilter(filterFn, newFilter, column)) {
1027
- return (old == null ? void 0 : old.filter(d => d.id !== column.id)) ?? [];
1028
- }
1029
- const newFilterObj = {
1030
- id: column.id,
1031
- value: newFilter
1032
- };
1033
- if (previousfilter) {
1034
- return (old == null ? void 0 : old.map(d => {
1035
- if (d.id === column.id) {
1036
- return newFilterObj;
1037
- }
1038
- return d;
1039
- })) ?? [];
1040
- }
1041
- if (old != null && old.length) {
1042
- return [...old, newFilterObj];
1043
- }
1044
- return [newFilterObj];
1045
- });
1046
- },
1047
- _getFacetedRowModel: table.options.getFacetedRowModel && table.options.getFacetedRowModel(table, column.id),
1048
- getFacetedRowModel: () => {
1049
- if (!column._getFacetedRowModel) {
1050
- return table.getPreFilteredRowModel();
1051
- }
1052
- return column._getFacetedRowModel();
1053
- },
1054
- _getFacetedUniqueValues: table.options.getFacetedUniqueValues && table.options.getFacetedUniqueValues(table, column.id),
1055
- getFacetedUniqueValues: () => {
1056
- if (!column._getFacetedUniqueValues) {
1057
- return new Map();
1058
- }
1059
- return column._getFacetedUniqueValues();
1060
- },
1061
- _getFacetedMinMaxValues: table.options.getFacetedMinMaxValues && table.options.getFacetedMinMaxValues(table, column.id),
1062
- getFacetedMinMaxValues: () => {
1063
- if (!column._getFacetedMinMaxValues) {
1064
- return undefined;
1065
- }
1066
- return column._getFacetedMinMaxValues();
1067
- }
1068
- // () => [column.getFacetedRowModel()],
1069
- // facetedRowModel => getRowModelMinMaxValues(facetedRowModel, column.id),
1070
- };
1071
- },
1072
-
1073
- createRow: (row, table) => {
1074
- return {
1075
- columnFilters: {},
1076
- columnFiltersMeta: {}
1077
- };
1078
- },
1079
- createTable: table => {
1080
- return {
1081
- getGlobalAutoFilterFn: () => {
1082
- return filterFns.includesString;
1083
- },
1084
- getGlobalFilterFn: () => {
1085
- var _table$options$filter2;
1086
- const {
1087
- globalFilterFn: globalFilterFn
1088
- } = table.options;
1089
- return isFunction(globalFilterFn) ? globalFilterFn : globalFilterFn === 'auto' ? table.getGlobalAutoFilterFn() : ((_table$options$filter2 = table.options.filterFns) == null ? void 0 : _table$options$filter2[globalFilterFn]) ?? filterFns[globalFilterFn];
1090
- },
1091
- setColumnFilters: updater => {
1092
- const leafColumns = table.getAllLeafColumns();
1093
- const updateFn = old => {
1094
- var _functionalUpdate;
1095
- return (_functionalUpdate = functionalUpdate(updater, old)) == null ? void 0 : _functionalUpdate.filter(filter => {
1096
- const column = leafColumns.find(d => d.id === filter.id);
1097
- if (column) {
1098
- const filterFn = column.getFilterFn();
1099
- if (shouldAutoRemoveFilter(filterFn, filter.value, column)) {
1100
- return false;
1101
- }
1102
- }
1103
- return true;
1104
- });
1105
- };
1106
- table.options.onColumnFiltersChange == null ? void 0 : table.options.onColumnFiltersChange(updateFn);
1107
- },
1108
- setGlobalFilter: updater => {
1109
- table.options.onGlobalFilterChange == null ? void 0 : table.options.onGlobalFilterChange(updater);
1110
- },
1111
- resetGlobalFilter: defaultState => {
1112
- table.setGlobalFilter(defaultState ? undefined : table.initialState.globalFilter);
1113
- },
1114
- resetColumnFilters: defaultState => {
1115
- var _table$initialState;
1116
- table.setColumnFilters(defaultState ? [] : ((_table$initialState = table.initialState) == null ? void 0 : _table$initialState.columnFilters) ?? []);
1117
- },
1118
- getPreFilteredRowModel: () => table.getCoreRowModel(),
1119
- getFilteredRowModel: () => {
1120
- if (!table._getFilteredRowModel && table.options.getFilteredRowModel) {
1121
- table._getFilteredRowModel = table.options.getFilteredRowModel(table);
1122
- }
1123
- if (table.options.manualFiltering || !table._getFilteredRowModel) {
1124
- return table.getPreFilteredRowModel();
1125
- }
1126
- return table._getFilteredRowModel();
1127
- },
1128
- _getGlobalFacetedRowModel: table.options.getFacetedRowModel && table.options.getFacetedRowModel(table, '__global__'),
1129
- getGlobalFacetedRowModel: () => {
1130
- if (table.options.manualFiltering || !table._getGlobalFacetedRowModel) {
1131
- return table.getPreFilteredRowModel();
1132
- }
1133
- return table._getGlobalFacetedRowModel();
1134
- },
1135
- _getGlobalFacetedUniqueValues: table.options.getFacetedUniqueValues && table.options.getFacetedUniqueValues(table, '__global__'),
1136
- getGlobalFacetedUniqueValues: () => {
1137
- if (!table._getGlobalFacetedUniqueValues) {
1138
- return new Map();
1139
- }
1140
- return table._getGlobalFacetedUniqueValues();
1141
- },
1142
- _getGlobalFacetedMinMaxValues: table.options.getFacetedMinMaxValues && table.options.getFacetedMinMaxValues(table, '__global__'),
1143
- getGlobalFacetedMinMaxValues: () => {
1144
- if (!table._getGlobalFacetedMinMaxValues) {
1145
- return;
1146
- }
1147
- return table._getGlobalFacetedMinMaxValues();
1148
- }
1149
- };
1150
- }
1151
- };
1152
- function shouldAutoRemoveFilter(filterFn, value, column) {
1153
- return (filterFn && filterFn.autoRemove ? filterFn.autoRemove(value, column) : false) || typeof value === 'undefined' || typeof value === 'string' && !value;
1154
- }
1155
-
1156
- const sum = (columnId, _leafRows, childRows) => {
1157
- // It's faster to just add the aggregations together instead of
1158
- // process leaf nodes individually
1159
- return childRows.reduce((sum, next) => {
1160
- const nextValue = next.getValue(columnId);
1161
- return sum + (typeof nextValue === 'number' ? nextValue : 0);
1162
- }, 0);
1163
- };
1164
- const min = (columnId, _leafRows, childRows) => {
1165
- let min;
1166
- childRows.forEach(row => {
1167
- const value = row.getValue(columnId);
1168
- if (value != null && (min > value || min === undefined && value >= value)) {
1169
- min = value;
1170
- }
1171
- });
1172
- return min;
1173
- };
1174
- const max = (columnId, _leafRows, childRows) => {
1175
- let max;
1176
- childRows.forEach(row => {
1177
- const value = row.getValue(columnId);
1178
- if (value != null && (max < value || max === undefined && value >= value)) {
1179
- max = value;
1180
- }
1181
- });
1182
- return max;
1183
- };
1184
- const extent = (columnId, _leafRows, childRows) => {
1185
- let min;
1186
- let max;
1187
- childRows.forEach(row => {
1188
- const value = row.getValue(columnId);
1189
- if (value != null) {
1190
- if (min === undefined) {
1191
- if (value >= value) min = max = value;
1192
- } else {
1193
- if (min > value) min = value;
1194
- if (max < value) max = value;
1195
- }
1196
- }
1197
- });
1198
- return [min, max];
1199
- };
1200
- const mean = (columnId, leafRows) => {
1201
- let count = 0;
1202
- let sum = 0;
1203
- leafRows.forEach(row => {
1204
- let value = row.getValue(columnId);
1205
- if (value != null && (value = +value) >= value) {
1206
- ++count, sum += value;
1207
- }
1208
- });
1209
- if (count) return sum / count;
1210
- return;
1211
- };
1212
- const median = (columnId, leafRows) => {
1213
- if (!leafRows.length) {
1214
- return;
1215
- }
1216
- let min = 0;
1217
- let max = 0;
1218
- leafRows.forEach(row => {
1219
- let value = row.getValue(columnId);
1220
- if (typeof value === 'number') {
1221
- min = Math.min(min, value);
1222
- max = Math.max(max, value);
1223
- }
1224
- });
1225
- return (min + max) / 2;
1226
- };
1227
- const unique = (columnId, leafRows) => {
1228
- return Array.from(new Set(leafRows.map(d => d.getValue(columnId))).values());
1229
- };
1230
- const uniqueCount = (columnId, leafRows) => {
1231
- return new Set(leafRows.map(d => d.getValue(columnId))).size;
1232
- };
1233
- const count = (_columnId, leafRows) => {
1234
- return leafRows.length;
1235
- };
1236
- const aggregationFns = {
1237
- sum,
1238
- min,
1239
- max,
1240
- extent,
1241
- mean,
1242
- median,
1243
- unique,
1244
- uniqueCount,
1245
- count
1246
- };
1247
-
1248
- //
1249
-
1250
- const Grouping = {
1251
- getDefaultColumnDef: () => {
1252
- return {
1253
- aggregatedCell: props => {
1254
- var _props$getValue;
1255
- return ((_props$getValue = props.getValue()) == null ? void 0 : _props$getValue.toString == null ? void 0 : _props$getValue.toString()) ?? null;
1256
- },
1257
- aggregationFn: 'auto'
1258
- };
1259
- },
1260
- getInitialState: state => {
1261
- return {
1262
- grouping: [],
1263
- ...state
1264
- };
1265
- },
1266
- getDefaultOptions: table => {
1267
- return {
1268
- onGroupingChange: makeStateUpdater('grouping', table),
1269
- groupedColumnMode: 'reorder'
1270
- };
1271
- },
1272
- createColumn: (column, table) => {
1273
- return {
1274
- toggleGrouping: () => {
1275
- table.setGrouping(old => {
1276
- // Find any existing grouping for this column
1277
- if (old != null && old.includes(column.id)) {
1278
- return old.filter(d => d !== column.id);
1279
- }
1280
- return [...(old ?? []), column.id];
1281
- });
1282
- },
1283
- getCanGroup: () => {
1284
- return column.columnDef.enableGrouping ?? true ?? table.options.enableGrouping ?? true ?? !!column.accessorFn;
1285
- },
1286
- getIsGrouped: () => {
1287
- var _table$getState$group;
1288
- return (_table$getState$group = table.getState().grouping) == null ? void 0 : _table$getState$group.includes(column.id);
1289
- },
1290
- getGroupedIndex: () => {
1291
- var _table$getState$group2;
1292
- return (_table$getState$group2 = table.getState().grouping) == null ? void 0 : _table$getState$group2.indexOf(column.id);
1293
- },
1294
- getToggleGroupingHandler: () => {
1295
- const canGroup = column.getCanGroup();
1296
- return () => {
1297
- if (!canGroup) return;
1298
- column.toggleGrouping();
1299
- };
1300
- },
1301
- getAutoAggregationFn: () => {
1302
- const firstRow = table.getCoreRowModel().flatRows[0];
1303
- const value = firstRow == null ? void 0 : firstRow.getValue(column.id);
1304
- if (typeof value === 'number') {
1305
- return aggregationFns.sum;
1306
- }
1307
- if (Object.prototype.toString.call(value) === '[object Date]') {
1308
- return aggregationFns.extent;
1309
- }
1310
- },
1311
- getAggregationFn: () => {
1312
- var _table$options$aggreg;
1313
- if (!column) {
1314
- throw new Error();
1315
- }
1316
- 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];
1317
- }
1318
- };
1319
- },
1320
- createTable: table => {
1321
- return {
1322
- setGrouping: updater => table.options.onGroupingChange == null ? void 0 : table.options.onGroupingChange(updater),
1323
- resetGrouping: defaultState => {
1324
- var _table$initialState;
1325
- table.setGrouping(defaultState ? [] : ((_table$initialState = table.initialState) == null ? void 0 : _table$initialState.grouping) ?? []);
1326
- },
1327
- getPreGroupedRowModel: () => table.getFilteredRowModel(),
1328
- getGroupedRowModel: () => {
1329
- if (!table._getGroupedRowModel && table.options.getGroupedRowModel) {
1330
- table._getGroupedRowModel = table.options.getGroupedRowModel(table);
1331
- }
1332
- if (table.options.manualGrouping || !table._getGroupedRowModel) {
1333
- return table.getPreGroupedRowModel();
1334
- }
1335
- return table._getGroupedRowModel();
1336
- }
1337
- };
1338
- },
1339
- createRow: row => {
1340
- return {
1341
- getIsGrouped: () => !!row.groupingColumnId,
1342
- _groupingValuesCache: {}
1343
- };
1344
- },
1345
- createCell: (cell, column, row, table) => {
1346
- return {
1347
- getIsGrouped: () => column.getIsGrouped() && column.id === row.groupingColumnId,
1348
- getIsPlaceholder: () => !cell.getIsGrouped() && column.getIsGrouped(),
1349
- getIsAggregated: () => {
1350
- var _row$subRows;
1351
- return !cell.getIsGrouped() && !cell.getIsPlaceholder() && !!((_row$subRows = row.subRows) != null && _row$subRows.length);
1352
- }
1353
- };
1354
- }
1355
- };
1356
- function orderColumns(leafColumns, grouping, groupedColumnMode) {
1357
- if (!(grouping != null && grouping.length) || !groupedColumnMode) {
1358
- return leafColumns;
1359
- }
1360
- const nonGroupingColumns = leafColumns.filter(col => !grouping.includes(col.id));
1361
- if (groupedColumnMode === 'remove') {
1362
- return nonGroupingColumns;
1363
- }
1364
- const groupingColumns = grouping.map(g => leafColumns.find(col => col.id === g)).filter(Boolean);
1365
- return [...groupingColumns, ...nonGroupingColumns];
1366
- }
1367
-
1368
- //
1369
-
1370
- const Ordering = {
1371
- getInitialState: state => {
1372
- return {
1373
- columnOrder: [],
1374
- ...state
1375
- };
1376
- },
1377
- getDefaultOptions: table => {
1378
- return {
1379
- onColumnOrderChange: makeStateUpdater('columnOrder', table)
1380
- };
1381
- },
1382
- createTable: table => {
1383
- return {
1384
- setColumnOrder: updater => table.options.onColumnOrderChange == null ? void 0 : table.options.onColumnOrderChange(updater),
1385
- resetColumnOrder: defaultState => {
1386
- table.setColumnOrder(defaultState ? [] : table.initialState.columnOrder ?? []);
1387
- },
1388
- _getOrderColumnsFn: memo(() => [table.getState().columnOrder, table.getState().grouping, table.options.groupedColumnMode], (columnOrder, grouping, groupedColumnMode) => columns => {
1389
- // Sort grouped columns to the start of the column list
1390
- // before the headers are built
1391
- let orderedColumns = [];
1392
-
1393
- // If there is no order, return the normal columns
1394
- if (!(columnOrder != null && columnOrder.length)) {
1395
- orderedColumns = columns;
1396
- } else {
1397
- const columnOrderCopy = [...columnOrder];
1398
-
1399
- // If there is an order, make a copy of the columns
1400
- const columnsCopy = [...columns];
1401
-
1402
- // And make a new ordered array of the columns
1403
-
1404
- // Loop over the columns and place them in order into the new array
1405
- while (columnsCopy.length && columnOrderCopy.length) {
1406
- const targetColumnId = columnOrderCopy.shift();
1407
- const foundIndex = columnsCopy.findIndex(d => d.id === targetColumnId);
1408
- if (foundIndex > -1) {
1409
- orderedColumns.push(columnsCopy.splice(foundIndex, 1)[0]);
1410
- }
1411
- }
1412
-
1413
- // If there are any columns left, add them to the end
1414
- orderedColumns = [...orderedColumns, ...columnsCopy];
1415
- }
1416
- return orderColumns(orderedColumns, grouping, groupedColumnMode);
1417
- }, {
1418
- key: process.env.NODE_ENV === 'development' && 'getOrderColumnsFn'
1419
- // debug: () => table.options.debugAll ?? table.options.debugTable,
1420
- })
1421
- };
1422
- }
1423
- };
1424
-
1425
- //
1426
-
1427
- const defaultPageIndex = 0;
1428
- const defaultPageSize = 10;
1429
- const getDefaultPaginationState = () => ({
1430
- pageIndex: defaultPageIndex,
1431
- pageSize: defaultPageSize
1432
- });
1433
- const Pagination = {
1434
- getInitialState: state => {
1435
- return {
1436
- ...state,
1437
- pagination: {
1438
- ...getDefaultPaginationState(),
1439
- ...(state == null ? void 0 : state.pagination)
1440
- }
1441
- };
1442
- },
1443
- getDefaultOptions: table => {
1444
- return {
1445
- onPaginationChange: makeStateUpdater('pagination', table)
1446
- };
1447
- },
1448
- createTable: table => {
1449
- let registered = false;
1450
- let queued = false;
1451
- return {
1452
- _autoResetPageIndex: () => {
1453
- if (!registered) {
1454
- table._queue(() => {
1455
- registered = true;
1456
- });
1457
- return;
1458
- }
1459
- if (table.options.autoResetAll ?? table.options.autoResetPageIndex ?? !table.options.manualPagination) {
1460
- if (queued) return;
1461
- queued = true;
1462
- table._queue(() => {
1463
- table.resetPageIndex();
1464
- queued = false;
1465
- });
1466
- }
1467
- },
1468
- setPagination: updater => {
1469
- const safeUpdater = old => {
1470
- let newState = functionalUpdate(updater, old);
1471
- return newState;
1472
- };
1473
- return table.options.onPaginationChange == null ? void 0 : table.options.onPaginationChange(safeUpdater);
1474
- },
1475
- resetPagination: defaultState => {
1476
- table.setPagination(defaultState ? getDefaultPaginationState() : table.initialState.pagination ?? getDefaultPaginationState());
1477
- },
1478
- setPageIndex: updater => {
1479
- table.setPagination(old => {
1480
- let pageIndex = functionalUpdate(updater, old.pageIndex);
1481
- const maxPageIndex = typeof table.options.pageCount === 'undefined' || table.options.pageCount === -1 ? Number.MAX_SAFE_INTEGER : table.options.pageCount - 1;
1482
- pageIndex = Math.max(0, Math.min(pageIndex, maxPageIndex));
1483
- return {
1484
- ...old,
1485
- pageIndex
1486
- };
1487
- });
1488
- },
1489
- resetPageIndex: defaultState => {
1490
- var _table$initialState, _table$initialState$p;
1491
- 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);
1492
- },
1493
- resetPageSize: defaultState => {
1494
- var _table$initialState2, _table$initialState2$;
1495
- table.setPageSize(defaultState ? defaultPageSize : ((_table$initialState2 = table.initialState) == null ? void 0 : (_table$initialState2$ = _table$initialState2.pagination) == null ? void 0 : _table$initialState2$.pageSize) ?? defaultPageSize);
1496
- },
1497
- setPageSize: updater => {
1498
- table.setPagination(old => {
1499
- const pageSize = Math.max(1, functionalUpdate(updater, old.pageSize));
1500
- const topRowIndex = old.pageSize * old.pageIndex;
1501
- const pageIndex = Math.floor(topRowIndex / pageSize);
1502
- return {
1503
- ...old,
1504
- pageIndex,
1505
- pageSize
1506
- };
1507
- });
1508
- },
1509
- setPageCount: updater => table.setPagination(old => {
1510
- let newPageCount = functionalUpdate(updater, table.options.pageCount ?? -1);
1511
- if (typeof newPageCount === 'number') {
1512
- newPageCount = Math.max(-1, newPageCount);
1513
- }
1514
- return {
1515
- ...old,
1516
- pageCount: newPageCount
1517
- };
1518
- }),
1519
- getPageOptions: memo(() => [table.getPageCount()], pageCount => {
1520
- let pageOptions = [];
1521
- if (pageCount && pageCount > 0) {
1522
- pageOptions = [...new Array(pageCount)].fill(null).map((_, i) => i);
1523
- }
1524
- return pageOptions;
1525
- }, {
1526
- key: process.env.NODE_ENV === 'development' && 'getPageOptions',
1527
- debug: () => table.options.debugAll ?? table.options.debugTable
1528
- }),
1529
- getCanPreviousPage: () => table.getState().pagination.pageIndex > 0,
1530
- getCanNextPage: () => {
1531
- const {
1532
- pageIndex
1533
- } = table.getState().pagination;
1534
- const pageCount = table.getPageCount();
1535
- if (pageCount === -1) {
1536
- return true;
1537
- }
1538
- if (pageCount === 0) {
1539
- return false;
1540
- }
1541
- return pageIndex < pageCount - 1;
1542
- },
1543
- previousPage: () => {
1544
- return table.setPageIndex(old => old - 1);
1545
- },
1546
- nextPage: () => {
1547
- return table.setPageIndex(old => {
1548
- return old + 1;
1549
- });
1550
- },
1551
- getPrePaginationRowModel: () => table.getExpandedRowModel(),
1552
- getPaginationRowModel: () => {
1553
- if (!table._getPaginationRowModel && table.options.getPaginationRowModel) {
1554
- table._getPaginationRowModel = table.options.getPaginationRowModel(table);
1555
- }
1556
- if (table.options.manualPagination || !table._getPaginationRowModel) {
1557
- return table.getPrePaginationRowModel();
1558
- }
1559
- return table._getPaginationRowModel();
1560
- },
1561
- getPageCount: () => {
1562
- return table.options.pageCount ?? Math.ceil(table.getPrePaginationRowModel().rows.length / table.getState().pagination.pageSize);
1563
- }
1564
- };
1565
- }
1566
- };
1567
-
1568
- //
1569
-
1570
- const getDefaultPinningState = () => ({
1571
- left: [],
1572
- right: []
1573
- });
1574
- const Pinning = {
1575
- getInitialState: state => {
1576
- return {
1577
- columnPinning: getDefaultPinningState(),
1578
- ...state
1579
- };
1580
- },
1581
- getDefaultOptions: table => {
1582
- return {
1583
- onColumnPinningChange: makeStateUpdater('columnPinning', table)
1584
- };
1585
- },
1586
- createColumn: (column, table) => {
1587
- return {
1588
- pin: position => {
1589
- const columnIds = column.getLeafColumns().map(d => d.id).filter(Boolean);
1590
- table.setColumnPinning(old => {
1591
- if (position === 'right') {
1592
- return {
1593
- left: ((old == null ? void 0 : old.left) ?? []).filter(d => !(columnIds != null && columnIds.includes(d))),
1594
- right: [...((old == null ? void 0 : old.right) ?? []).filter(d => !(columnIds != null && columnIds.includes(d))), ...columnIds]
1595
- };
1596
- }
1597
- if (position === 'left') {
1598
- return {
1599
- left: [...((old == null ? void 0 : old.left) ?? []).filter(d => !(columnIds != null && columnIds.includes(d))), ...columnIds],
1600
- right: ((old == null ? void 0 : old.right) ?? []).filter(d => !(columnIds != null && columnIds.includes(d)))
1601
- };
1602
- }
1603
- return {
1604
- left: ((old == null ? void 0 : old.left) ?? []).filter(d => !(columnIds != null && columnIds.includes(d))),
1605
- right: ((old == null ? void 0 : old.right) ?? []).filter(d => !(columnIds != null && columnIds.includes(d)))
1606
- };
1607
- });
1608
- },
1609
- getCanPin: () => {
1610
- const leafColumns = column.getLeafColumns();
1611
- return leafColumns.some(d => (d.columnDef.enablePinning ?? true) && (table.options.enablePinning ?? true));
1612
- },
1613
- getIsPinned: () => {
1614
- const leafColumnIds = column.getLeafColumns().map(d => d.id);
1615
- const {
1616
- left,
1617
- right
1618
- } = table.getState().columnPinning;
1619
- const isLeft = leafColumnIds.some(d => left == null ? void 0 : left.includes(d));
1620
- const isRight = leafColumnIds.some(d => right == null ? void 0 : right.includes(d));
1621
- return isLeft ? 'left' : isRight ? 'right' : false;
1622
- },
1623
- getPinnedIndex: () => {
1624
- var _table$getState$colum, _table$getState$colum2;
1625
- const position = column.getIsPinned();
1626
- 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;
1627
- }
1628
- };
1629
- },
1630
- createRow: (row, table) => {
1631
- return {
1632
- getCenterVisibleCells: memo(() => [row._getAllVisibleCells(), table.getState().columnPinning.left, table.getState().columnPinning.right], (allCells, left, right) => {
1633
- const leftAndRight = [...(left ?? []), ...(right ?? [])];
1634
- return allCells.filter(d => !leftAndRight.includes(d.column.id));
1635
- }, {
1636
- key: process.env.NODE_ENV === 'production' && 'row.getCenterVisibleCells',
1637
- debug: () => table.options.debugAll ?? table.options.debugRows
1638
- }),
1639
- getLeftVisibleCells: memo(() => [row._getAllVisibleCells(), table.getState().columnPinning.left,,], (allCells, left) => {
1640
- const cells = (left ?? []).map(columnId => allCells.find(cell => cell.column.id === columnId)).filter(Boolean).map(d => ({
1641
- ...d,
1642
- position: 'left'
1643
- }));
1644
- return cells;
1645
- }, {
1646
- key: process.env.NODE_ENV === 'production' && 'row.getLeftVisibleCells',
1647
- debug: () => table.options.debugAll ?? table.options.debugRows
1648
- }),
1649
- getRightVisibleCells: memo(() => [row._getAllVisibleCells(), table.getState().columnPinning.right], (allCells, right) => {
1650
- const cells = (right ?? []).map(columnId => allCells.find(cell => cell.column.id === columnId)).filter(Boolean).map(d => ({
1651
- ...d,
1652
- position: 'right'
1653
- }));
1654
- return cells;
1655
- }, {
1656
- key: process.env.NODE_ENV === 'production' && 'row.getRightVisibleCells',
1657
- debug: () => table.options.debugAll ?? table.options.debugRows
1658
- })
1659
- };
1660
- },
1661
- createTable: table => {
1662
- return {
1663
- setColumnPinning: updater => table.options.onColumnPinningChange == null ? void 0 : table.options.onColumnPinningChange(updater),
1664
- resetColumnPinning: defaultState => {
1665
- var _table$initialState;
1666
- return table.setColumnPinning(defaultState ? getDefaultPinningState() : ((_table$initialState = table.initialState) == null ? void 0 : _table$initialState.columnPinning) ?? getDefaultPinningState());
1667
- },
1668
- getIsSomeColumnsPinned: position => {
1669
- var _pinningState$positio;
1670
- const pinningState = table.getState().columnPinning;
1671
- if (!position) {
1672
- var _pinningState$left, _pinningState$right;
1673
- return Boolean(((_pinningState$left = pinningState.left) == null ? void 0 : _pinningState$left.length) || ((_pinningState$right = pinningState.right) == null ? void 0 : _pinningState$right.length));
1674
- }
1675
- return Boolean((_pinningState$positio = pinningState[position]) == null ? void 0 : _pinningState$positio.length);
1676
- },
1677
- getLeftLeafColumns: memo(() => [table.getAllLeafColumns(), table.getState().columnPinning.left], (allColumns, left) => {
1678
- return (left ?? []).map(columnId => allColumns.find(column => column.id === columnId)).filter(Boolean);
1679
- }, {
1680
- key: process.env.NODE_ENV === 'development' && 'getLeftLeafColumns',
1681
- debug: () => table.options.debugAll ?? table.options.debugColumns
1682
- }),
1683
- getRightLeafColumns: memo(() => [table.getAllLeafColumns(), table.getState().columnPinning.right], (allColumns, right) => {
1684
- return (right ?? []).map(columnId => allColumns.find(column => column.id === columnId)).filter(Boolean);
1685
- }, {
1686
- key: process.env.NODE_ENV === 'development' && 'getRightLeafColumns',
1687
- debug: () => table.options.debugAll ?? table.options.debugColumns
1688
- }),
1689
- getCenterLeafColumns: memo(() => [table.getAllLeafColumns(), table.getState().columnPinning.left, table.getState().columnPinning.right], (allColumns, left, right) => {
1690
- const leftAndRight = [...(left ?? []), ...(right ?? [])];
1691
- return allColumns.filter(d => !leftAndRight.includes(d.id));
1692
- }, {
1693
- key: process.env.NODE_ENV === 'development' && 'getCenterLeafColumns',
1694
- debug: () => table.options.debugAll ?? table.options.debugColumns
1695
- })
1696
- };
1697
- }
1698
- };
1699
-
1700
- //
1701
-
1702
- const RowSelection = {
1703
- getInitialState: state => {
1704
- return {
1705
- rowSelection: {},
1706
- ...state
1707
- };
1708
- },
1709
- getDefaultOptions: table => {
1710
- return {
1711
- onRowSelectionChange: makeStateUpdater('rowSelection', table),
1712
- enableRowSelection: true,
1713
- enableMultiRowSelection: true,
1714
- enableSubRowSelection: true
1715
- // enableGroupingRowSelection: false,
1716
- // isAdditiveSelectEvent: (e: unknown) => !!e.metaKey,
1717
- // isInclusiveSelectEvent: (e: unknown) => !!e.shiftKey,
1718
- };
1719
- },
1720
-
1721
- createTable: table => {
1722
- return {
1723
- setRowSelection: updater => table.options.onRowSelectionChange == null ? void 0 : table.options.onRowSelectionChange(updater),
1724
- resetRowSelection: defaultState => table.setRowSelection(defaultState ? {} : table.initialState.rowSelection ?? {}),
1725
- toggleAllRowsSelected: value => {
1726
- table.setRowSelection(old => {
1727
- value = typeof value !== 'undefined' ? value : !table.getIsAllRowsSelected();
1728
- const rowSelection = {
1729
- ...old
1730
- };
1731
- const preGroupedFlatRows = table.getPreGroupedRowModel().flatRows;
1732
-
1733
- // We don't use `mutateRowIsSelected` here for performance reasons.
1734
- // All of the rows are flat already, so it wouldn't be worth it
1735
- if (value) {
1736
- preGroupedFlatRows.forEach(row => {
1737
- if (!row.getCanSelect()) {
1738
- return;
1739
- }
1740
- rowSelection[row.id] = true;
1741
- });
1742
- } else {
1743
- preGroupedFlatRows.forEach(row => {
1744
- delete rowSelection[row.id];
1745
- });
1746
- }
1747
- return rowSelection;
1748
- });
1749
- },
1750
- toggleAllPageRowsSelected: value => table.setRowSelection(old => {
1751
- const resolvedValue = typeof value !== 'undefined' ? value : !table.getIsAllPageRowsSelected();
1752
- const rowSelection = {
1753
- ...old
1754
- };
1755
- table.getRowModel().rows.forEach(row => {
1756
- mutateRowIsSelected(rowSelection, row.id, resolvedValue, table);
1757
- });
1758
- return rowSelection;
1759
- }),
1760
- // addRowSelectionRange: rowId => {
1761
- // const {
1762
- // rows,
1763
- // rowsById,
1764
- // options: { selectGroupingRows, selectSubRows },
1765
- // } = table
1766
-
1767
- // const findSelectedRow = (rows: Row[]) => {
1768
- // let found
1769
- // rows.find(d => {
1770
- // if (d.getIsSelected()) {
1771
- // found = d
1772
- // return true
1773
- // }
1774
- // const subFound = findSelectedRow(d.subRows || [])
1775
- // if (subFound) {
1776
- // found = subFound
1777
- // return true
1778
- // }
1779
- // return false
1780
- // })
1781
- // return found
1782
- // }
1783
-
1784
- // const firstRow = findSelectedRow(rows) || rows[0]
1785
- // const lastRow = rowsById[rowId]
1786
-
1787
- // let include = false
1788
- // const selectedRowIds = {}
1789
-
1790
- // const addRow = (row: Row) => {
1791
- // mutateRowIsSelected(selectedRowIds, row.id, true, {
1792
- // rowsById,
1793
- // selectGroupingRows: selectGroupingRows!,
1794
- // selectSubRows: selectSubRows!,
1795
- // })
1796
- // }
1797
-
1798
- // table.rows.forEach(row => {
1799
- // const isFirstRow = row.id === firstRow.id
1800
- // const isLastRow = row.id === lastRow.id
1801
-
1802
- // if (isFirstRow || isLastRow) {
1803
- // if (!include) {
1804
- // include = true
1805
- // } else if (include) {
1806
- // addRow(row)
1807
- // include = false
1808
- // }
1809
- // }
1810
-
1811
- // if (include) {
1812
- // addRow(row)
1813
- // }
1814
- // })
1815
-
1816
- // table.setRowSelection(selectedRowIds)
1817
- // },
1818
- getPreSelectedRowModel: () => table.getCoreRowModel(),
1819
- getSelectedRowModel: memo(() => [table.getState().rowSelection, table.getCoreRowModel()], (rowSelection, rowModel) => {
1820
- if (!Object.keys(rowSelection).length) {
1821
- return {
1822
- rows: [],
1823
- flatRows: [],
1824
- rowsById: {}
1825
- };
1826
- }
1827
- return selectRowsFn(table, rowModel);
1828
- }, {
1829
- key: process.env.NODE_ENV === 'development' && 'getSelectedRowModel',
1830
- debug: () => table.options.debugAll ?? table.options.debugTable
1831
- }),
1832
- getFilteredSelectedRowModel: memo(() => [table.getState().rowSelection, table.getFilteredRowModel()], (rowSelection, rowModel) => {
1833
- if (!Object.keys(rowSelection).length) {
1834
- return {
1835
- rows: [],
1836
- flatRows: [],
1837
- rowsById: {}
1838
- };
1839
- }
1840
- return selectRowsFn(table, rowModel);
1841
- }, {
1842
- key: process.env.NODE_ENV === 'production' && 'getFilteredSelectedRowModel',
1843
- debug: () => table.options.debugAll ?? table.options.debugTable
1844
- }),
1845
- getGroupedSelectedRowModel: memo(() => [table.getState().rowSelection, table.getSortedRowModel()], (rowSelection, rowModel) => {
1846
- if (!Object.keys(rowSelection).length) {
1847
- return {
1848
- rows: [],
1849
- flatRows: [],
1850
- rowsById: {}
1851
- };
1852
- }
1853
- return selectRowsFn(table, rowModel);
1854
- }, {
1855
- key: process.env.NODE_ENV === 'production' && 'getGroupedSelectedRowModel',
1856
- debug: () => table.options.debugAll ?? table.options.debugTable
1857
- }),
1858
- ///
1859
-
1860
- // getGroupingRowCanSelect: rowId => {
1861
- // const row = table.getRow(rowId)
1862
-
1863
- // if (!row) {
1864
- // throw new Error()
1865
- // }
1866
-
1867
- // if (typeof table.options.enableGroupingRowSelection === 'function') {
1868
- // return table.options.enableGroupingRowSelection(row)
1869
- // }
1870
-
1871
- // return table.options.enableGroupingRowSelection ?? false
1872
- // },
1873
-
1874
- getIsAllRowsSelected: () => {
1875
- const preGroupedFlatRows = table.getFilteredRowModel().flatRows;
1876
- const {
1877
- rowSelection
1878
- } = table.getState();
1879
- let isAllRowsSelected = Boolean(preGroupedFlatRows.length && Object.keys(rowSelection).length);
1880
- if (isAllRowsSelected) {
1881
- if (preGroupedFlatRows.some(row => row.getCanSelect() && !rowSelection[row.id])) {
1882
- isAllRowsSelected = false;
1883
- }
1884
- }
1885
- return isAllRowsSelected;
1886
- },
1887
- getIsAllPageRowsSelected: () => {
1888
- const paginationFlatRows = table.getPaginationRowModel().flatRows;
1889
- const {
1890
- rowSelection
1891
- } = table.getState();
1892
- let isAllPageRowsSelected = !!paginationFlatRows.length;
1893
- if (isAllPageRowsSelected && paginationFlatRows.some(row => !rowSelection[row.id])) {
1894
- isAllPageRowsSelected = false;
1895
- }
1896
- return isAllPageRowsSelected;
1897
- },
1898
- getIsSomeRowsSelected: () => {
1899
- const totalSelected = Object.keys(table.getState().rowSelection ?? {}).length;
1900
- return totalSelected > 0 && totalSelected < table.getFilteredRowModel().flatRows.length;
1901
- },
1902
- getIsSomePageRowsSelected: () => {
1903
- const paginationFlatRows = table.getPaginationRowModel().flatRows;
1904
- return table.getIsAllPageRowsSelected() ? false : paginationFlatRows.some(d => d.getIsSelected() || d.getIsSomeSelected());
1905
- },
1906
- getToggleAllRowsSelectedHandler: () => {
1907
- return e => {
1908
- table.toggleAllRowsSelected(e.target.checked);
1909
- };
1910
- },
1911
- getToggleAllPageRowsSelectedHandler: () => {
1912
- return e => {
1913
- table.toggleAllPageRowsSelected(e.target.checked);
1914
- };
1915
- }
1916
- };
1917
- },
1918
- createRow: (row, table) => {
1919
- return {
1920
- toggleSelected: value => {
1921
- const isSelected = row.getIsSelected();
1922
- table.setRowSelection(old => {
1923
- value = typeof value !== 'undefined' ? value : !isSelected;
1924
- if (isSelected === value) {
1925
- return old;
1926
- }
1927
- const selectedRowIds = {
1928
- ...old
1929
- };
1930
- mutateRowIsSelected(selectedRowIds, row.id, value, table);
1931
- return selectedRowIds;
1932
- });
1933
- },
1934
- getIsSelected: () => {
1935
- const {
1936
- rowSelection
1937
- } = table.getState();
1938
- return isRowSelected(row, rowSelection);
1939
- },
1940
- getIsSomeSelected: () => {
1941
- const {
1942
- rowSelection
1943
- } = table.getState();
1944
- return isSubRowSelected(row, rowSelection) === 'some';
1945
- },
1946
- getIsAllSubRowsSelected: () => {
1947
- const {
1948
- rowSelection
1949
- } = table.getState();
1950
- return isSubRowSelected(row, rowSelection) === 'all';
1951
- },
1952
- getCanSelect: () => {
1953
- if (typeof table.options.enableRowSelection === 'function') {
1954
- return table.options.enableRowSelection(row);
1955
- }
1956
- return table.options.enableRowSelection ?? true;
1957
- },
1958
- getCanSelectSubRows: () => {
1959
- if (typeof table.options.enableSubRowSelection === 'function') {
1960
- return table.options.enableSubRowSelection(row);
1961
- }
1962
- return table.options.enableSubRowSelection ?? true;
1963
- },
1964
- getCanMultiSelect: () => {
1965
- if (typeof table.options.enableMultiRowSelection === 'function') {
1966
- return table.options.enableMultiRowSelection(row);
1967
- }
1968
- return table.options.enableMultiRowSelection ?? true;
1969
- },
1970
- getToggleSelectedHandler: () => {
1971
- const canSelect = row.getCanSelect();
1972
- return e => {
1973
- var _target;
1974
- if (!canSelect) return;
1975
- row.toggleSelected((_target = e.target) == null ? void 0 : _target.checked);
1976
- };
1977
- }
1978
- };
1979
- }
1980
- };
1981
- const mutateRowIsSelected = (selectedRowIds, id, value, table) => {
1982
- var _row$subRows;
1983
- const row = table.getRow(id);
1984
-
1985
- // const isGrouped = row.getIsGrouped()
1986
-
1987
- // if ( // TODO: enforce grouping row selection rules
1988
- // !isGrouped ||
1989
- // (isGrouped && table.options.enableGroupingRowSelection)
1990
- // ) {
1991
- if (value) {
1992
- if (!row.getCanMultiSelect()) {
1993
- Object.keys(selectedRowIds).forEach(key => delete selectedRowIds[key]);
1994
- }
1995
- if (row.getCanSelect()) {
1996
- selectedRowIds[id] = true;
1997
- }
1998
- } else {
1999
- delete selectedRowIds[id];
2000
- }
2001
- // }
2002
-
2003
- if ((_row$subRows = row.subRows) != null && _row$subRows.length && row.getCanSelectSubRows()) {
2004
- row.subRows.forEach(row => mutateRowIsSelected(selectedRowIds, row.id, value, table));
2005
- }
2006
- };
2007
- function selectRowsFn(table, rowModel) {
2008
- const rowSelection = table.getState().rowSelection;
2009
- const newSelectedFlatRows = [];
2010
- const newSelectedRowsById = {};
2011
-
2012
- // Filters top level and nested rows
2013
- const recurseRows = function (rows, depth) {
2014
- return rows.map(row => {
2015
- var _row$subRows2;
2016
- const isSelected = isRowSelected(row, rowSelection);
2017
- if (isSelected) {
2018
- newSelectedFlatRows.push(row);
2019
- newSelectedRowsById[row.id] = row;
2020
- }
2021
- if ((_row$subRows2 = row.subRows) != null && _row$subRows2.length) {
2022
- row = {
2023
- ...row,
2024
- subRows: recurseRows(row.subRows)
2025
- };
2026
- }
2027
- if (isSelected) {
2028
- return row;
2029
- }
2030
- }).filter(Boolean);
2031
- };
2032
- return {
2033
- rows: recurseRows(rowModel.rows),
2034
- flatRows: newSelectedFlatRows,
2035
- rowsById: newSelectedRowsById
2036
- };
2037
- }
2038
- function isRowSelected(row, selection) {
2039
- return selection[row.id] ?? false;
2040
- }
2041
- function isSubRowSelected(row, selection, table) {
2042
- if (row.subRows && row.subRows.length) {
2043
- let allChildrenSelected = true;
2044
- let someSelected = false;
2045
- row.subRows.forEach(subRow => {
2046
- // Bail out early if we know both of these
2047
- if (someSelected && !allChildrenSelected) {
2048
- return;
2049
- }
2050
- if (isRowSelected(subRow, selection)) {
2051
- someSelected = true;
2052
- } else {
2053
- allChildrenSelected = false;
2054
- }
2055
- });
2056
- return allChildrenSelected ? 'all' : someSelected ? 'some' : false;
2057
- }
2058
- return false;
2059
- }
2060
-
2061
- const reSplitAlphaNumeric = /([0-9]+)/gm;
2062
- const alphanumeric = (rowA, rowB, columnId) => {
2063
- return compareAlphanumeric(toString(rowA.getValue(columnId)).toLowerCase(), toString(rowB.getValue(columnId)).toLowerCase());
2064
- };
2065
- const alphanumericCaseSensitive = (rowA, rowB, columnId) => {
2066
- return compareAlphanumeric(toString(rowA.getValue(columnId)), toString(rowB.getValue(columnId)));
2067
- };
2068
-
2069
- // The text filter is more basic (less numeric support)
2070
- // but is much faster
2071
- const text = (rowA, rowB, columnId) => {
2072
- return compareBasic(toString(rowA.getValue(columnId)).toLowerCase(), toString(rowB.getValue(columnId)).toLowerCase());
2073
- };
2074
-
2075
- // The text filter is more basic (less numeric support)
2076
- // but is much faster
2077
- const textCaseSensitive = (rowA, rowB, columnId) => {
2078
- return compareBasic(toString(rowA.getValue(columnId)), toString(rowB.getValue(columnId)));
2079
- };
2080
- const datetime = (rowA, rowB, columnId) => {
2081
- const a = rowA.getValue(columnId);
2082
- const b = rowB.getValue(columnId);
2083
-
2084
- // Can handle nullish values
2085
- // Use > and < because == (and ===) doesn't work with
2086
- // Date objects (would require calling getTime()).
2087
- return a > b ? 1 : a < b ? -1 : 0;
2088
- };
2089
- const basic = (rowA, rowB, columnId) => {
2090
- return compareBasic(rowA.getValue(columnId), rowB.getValue(columnId));
2091
- };
2092
-
2093
- // Utils
2094
-
2095
- function compareBasic(a, b) {
2096
- return a === b ? 0 : a > b ? 1 : -1;
2097
- }
2098
- function toString(a) {
2099
- if (typeof a === 'number') {
2100
- if (isNaN(a) || a === Infinity || a === -Infinity) {
2101
- return '';
2102
- }
2103
- return String(a);
2104
- }
2105
- if (typeof a === 'string') {
2106
- return a;
2107
- }
2108
- return '';
2109
- }
2110
-
2111
- // Mixed sorting is slow, but very inclusive of many edge cases.
2112
- // It handles numbers, mixed alphanumeric combinations, and even
2113
- // null, undefined, and Infinity
2114
- function compareAlphanumeric(aStr, bStr) {
2115
- // Split on number groups, but keep the delimiter
2116
- // Then remove falsey split values
2117
- const a = aStr.split(reSplitAlphaNumeric).filter(Boolean);
2118
- const b = bStr.split(reSplitAlphaNumeric).filter(Boolean);
2119
-
2120
- // While
2121
- while (a.length && b.length) {
2122
- const aa = a.shift();
2123
- const bb = b.shift();
2124
- const an = parseInt(aa, 10);
2125
- const bn = parseInt(bb, 10);
2126
- const combo = [an, bn].sort();
2127
-
2128
- // Both are string
2129
- if (isNaN(combo[0])) {
2130
- if (aa > bb) {
2131
- return 1;
2132
- }
2133
- if (bb > aa) {
2134
- return -1;
2135
- }
2136
- continue;
2137
- }
2138
-
2139
- // One is a string, one is a number
2140
- if (isNaN(combo[1])) {
2141
- return isNaN(an) ? -1 : 1;
2142
- }
2143
-
2144
- // Both are numbers
2145
- if (an > bn) {
2146
- return 1;
2147
- }
2148
- if (bn > an) {
2149
- return -1;
2150
- }
2151
- }
2152
- return a.length - b.length;
2153
- }
2154
-
2155
- // Exports
2156
-
2157
- const sortingFns = {
2158
- alphanumeric,
2159
- alphanumericCaseSensitive,
2160
- text,
2161
- textCaseSensitive,
2162
- datetime,
2163
- basic
2164
- };
2165
-
2166
- //
2167
-
2168
- const Sorting = {
2169
- getInitialState: state => {
2170
- return {
2171
- sorting: [],
2172
- ...state
2173
- };
2174
- },
2175
- getDefaultColumnDef: () => {
2176
- return {
2177
- sortingFn: 'auto'
2178
- };
2179
- },
2180
- getDefaultOptions: table => {
2181
- return {
2182
- onSortingChange: makeStateUpdater('sorting', table),
2183
- isMultiSortEvent: e => {
2184
- return e.shiftKey;
2185
- }
2186
- };
2187
- },
2188
- createColumn: (column, table) => {
2189
- return {
2190
- getAutoSortingFn: () => {
2191
- const firstRows = table.getFilteredRowModel().flatRows.slice(10);
2192
- let isString = false;
2193
- for (const row of firstRows) {
2194
- const value = row == null ? void 0 : row.getValue(column.id);
2195
- if (Object.prototype.toString.call(value) === '[object Date]') {
2196
- return sortingFns.datetime;
2197
- }
2198
- if (typeof value === 'string') {
2199
- isString = true;
2200
- if (value.split(reSplitAlphaNumeric).length > 1) {
2201
- return sortingFns.alphanumeric;
2202
- }
2203
- }
2204
- }
2205
- if (isString) {
2206
- return sortingFns.text;
2207
- }
2208
- return sortingFns.basic;
2209
- },
2210
- getAutoSortDir: () => {
2211
- const firstRow = table.getFilteredRowModel().flatRows[0];
2212
- const value = firstRow == null ? void 0 : firstRow.getValue(column.id);
2213
- if (typeof value === 'string') {
2214
- return 'asc';
2215
- }
2216
- return 'desc';
2217
- },
2218
- getSortingFn: () => {
2219
- var _table$options$sortin;
2220
- if (!column) {
2221
- throw new Error();
2222
- }
2223
- 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];
2224
- },
2225
- toggleSorting: (desc, multi) => {
2226
- // if (column.columns.length) {
2227
- // column.columns.forEach((c, i) => {
2228
- // if (c.id) {
2229
- // table.toggleColumnSorting(c.id, undefined, multi || !!i)
2230
- // }
2231
- // })
2232
- // return
2233
- // }
2234
-
2235
- // this needs to be outside of table.setSorting to be in sync with rerender
2236
- const nextSortingOrder = column.getNextSortingOrder();
2237
- const hasManualValue = typeof desc !== 'undefined' && desc !== null;
2238
- table.setSorting(old => {
2239
- // Find any existing sorting for this column
2240
- const existingSorting = old == null ? void 0 : old.find(d => d.id === column.id);
2241
- const existingIndex = old == null ? void 0 : old.findIndex(d => d.id === column.id);
2242
- let newSorting = [];
2243
-
2244
- // What should we do with this sort action?
2245
- let sortAction;
2246
- let nextDesc = hasManualValue ? desc : nextSortingOrder === 'desc';
2247
-
2248
- // Multi-mode
2249
- if (old != null && old.length && column.getCanMultiSort() && multi) {
2250
- if (existingSorting) {
2251
- sortAction = 'toggle';
2252
- } else {
2253
- sortAction = 'add';
2254
- }
2255
- } else {
2256
- // Normal mode
2257
- if (old != null && old.length && existingIndex !== old.length - 1) {
2258
- sortAction = 'replace';
2259
- } else if (existingSorting) {
2260
- sortAction = 'toggle';
2261
- } else {
2262
- sortAction = 'replace';
2263
- }
2264
- }
2265
-
2266
- // Handle toggle states that will remove the sorting
2267
- if (sortAction === 'toggle') {
2268
- // If we are "actually" toggling (not a manual set value), should we remove the sorting?
2269
- if (!hasManualValue) {
2270
- // Is our intention to remove?
2271
- if (!nextSortingOrder) {
2272
- sortAction = 'remove';
2273
- }
2274
- }
2275
- }
2276
- if (sortAction === 'add') {
2277
- newSorting = [...old, {
2278
- id: column.id,
2279
- desc: nextDesc
2280
- }];
2281
- // Take latest n columns
2282
- newSorting.splice(0, newSorting.length - (table.options.maxMultiSortColCount ?? Number.MAX_SAFE_INTEGER));
2283
- } else if (sortAction === 'toggle') {
2284
- // This flips (or sets) the
2285
- newSorting = old.map(d => {
2286
- if (d.id === column.id) {
2287
- return {
2288
- ...d,
2289
- desc: nextDesc
2290
- };
2291
- }
2292
- return d;
2293
- });
2294
- } else if (sortAction === 'remove') {
2295
- newSorting = old.filter(d => d.id !== column.id);
2296
- } else {
2297
- newSorting = [{
2298
- id: column.id,
2299
- desc: nextDesc
2300
- }];
2301
- }
2302
- return newSorting;
2303
- });
2304
- },
2305
- getFirstSortDir: () => {
2306
- const sortDescFirst = column.columnDef.sortDescFirst ?? table.options.sortDescFirst ?? column.getAutoSortDir() === 'desc';
2307
- return sortDescFirst ? 'desc' : 'asc';
2308
- },
2309
- getNextSortingOrder: multi => {
2310
- const firstSortDirection = column.getFirstSortDir();
2311
- const isSorted = column.getIsSorted();
2312
- if (!isSorted) {
2313
- return firstSortDirection;
2314
- }
2315
- if (isSorted !== firstSortDirection && (table.options.enableSortingRemoval ?? true) && (
2316
- // If enableSortRemove, enable in general
2317
- multi ? table.options.enableMultiRemove ?? true : true) // If multi, don't allow if enableMultiRemove))
2318
- ) {
2319
- return false;
2320
- }
2321
- return isSorted === 'desc' ? 'asc' : 'desc';
2322
- },
2323
- getCanSort: () => {
2324
- return (column.columnDef.enableSorting ?? true) && (table.options.enableSorting ?? true) && !!column.accessorFn;
2325
- },
2326
- getCanMultiSort: () => {
2327
- return column.columnDef.enableMultiSort ?? table.options.enableMultiSort ?? !!column.accessorFn;
2328
- },
2329
- getIsSorted: () => {
2330
- var _table$getState$sorti;
2331
- const columnSort = (_table$getState$sorti = table.getState().sorting) == null ? void 0 : _table$getState$sorti.find(d => d.id === column.id);
2332
- return !columnSort ? false : columnSort.desc ? 'desc' : 'asc';
2333
- },
2334
- getSortIndex: () => {
2335
- var _table$getState$sorti2;
2336
- return ((_table$getState$sorti2 = table.getState().sorting) == null ? void 0 : _table$getState$sorti2.findIndex(d => d.id === column.id)) ?? -1;
2337
- },
2338
- clearSorting: () => {
2339
- //clear sorting for just 1 column
2340
- table.setSorting(old => old != null && old.length ? old.filter(d => d.id !== column.id) : []);
2341
- },
2342
- getToggleSortingHandler: () => {
2343
- const canSort = column.getCanSort();
2344
- return e => {
2345
- if (!canSort) return;
2346
- e.persist == null ? void 0 : e.persist();
2347
- column.toggleSorting == null ? void 0 : column.toggleSorting(undefined, column.getCanMultiSort() ? table.options.isMultiSortEvent == null ? void 0 : table.options.isMultiSortEvent(e) : false);
2348
- };
2349
- }
2350
- };
2351
- },
2352
- createTable: table => {
2353
- return {
2354
- setSorting: updater => table.options.onSortingChange == null ? void 0 : table.options.onSortingChange(updater),
2355
- resetSorting: defaultState => {
2356
- var _table$initialState;
2357
- table.setSorting(defaultState ? [] : ((_table$initialState = table.initialState) == null ? void 0 : _table$initialState.sorting) ?? []);
2358
- },
2359
- getPreSortedRowModel: () => table.getGroupedRowModel(),
2360
- getSortedRowModel: () => {
2361
- if (!table._getSortedRowModel && table.options.getSortedRowModel) {
2362
- table._getSortedRowModel = table.options.getSortedRowModel(table);
2363
- }
2364
- if (table.options.manualSorting || !table._getSortedRowModel) {
2365
- return table.getPreSortedRowModel();
2366
- }
2367
- return table._getSortedRowModel();
2368
- }
2369
- };
2370
- }
2371
- };
2372
-
2373
- //
2374
-
2375
- const Visibility = {
2376
- getInitialState: state => {
2377
- return {
2378
- columnVisibility: {},
2379
- ...state
2380
- };
2381
- },
2382
- getDefaultOptions: table => {
2383
- return {
2384
- onColumnVisibilityChange: makeStateUpdater('columnVisibility', table)
2385
- };
2386
- },
2387
- createColumn: (column, table) => {
2388
- return {
2389
- toggleVisibility: value => {
2390
- if (column.getCanHide()) {
2391
- table.setColumnVisibility(old => ({
2392
- ...old,
2393
- [column.id]: value ?? !column.getIsVisible()
2394
- }));
2395
- }
2396
- },
2397
- getIsVisible: () => {
2398
- var _table$getState$colum;
2399
- return ((_table$getState$colum = table.getState().columnVisibility) == null ? void 0 : _table$getState$colum[column.id]) ?? true;
2400
- },
2401
- getCanHide: () => {
2402
- return (column.columnDef.enableHiding ?? true) && (table.options.enableHiding ?? true);
2403
- },
2404
- getToggleVisibilityHandler: () => {
2405
- return e => {
2406
- column.toggleVisibility == null ? void 0 : column.toggleVisibility(e.target.checked);
2407
- };
2408
- }
2409
- };
2410
- },
2411
- createRow: (row, table) => {
2412
- return {
2413
- _getAllVisibleCells: memo(() => [row.getAllCells(), table.getState().columnVisibility], cells => {
2414
- return cells.filter(cell => cell.column.getIsVisible());
2415
- }, {
2416
- key: process.env.NODE_ENV === 'production' && 'row._getAllVisibleCells',
2417
- debug: () => table.options.debugAll ?? table.options.debugRows
2418
- }),
2419
- getVisibleCells: memo(() => [row.getLeftVisibleCells(), row.getCenterVisibleCells(), row.getRightVisibleCells()], (left, center, right) => [...left, ...center, ...right], {
2420
- key: process.env.NODE_ENV === 'development' && 'row.getVisibleCells',
2421
- debug: () => table.options.debugAll ?? table.options.debugRows
2422
- })
2423
- };
2424
- },
2425
- createTable: table => {
2426
- const makeVisibleColumnsMethod = (key, getColumns) => {
2427
- return memo(() => [getColumns(), getColumns().filter(d => d.getIsVisible()).map(d => d.id).join('_')], columns => {
2428
- return columns.filter(d => d.getIsVisible == null ? void 0 : d.getIsVisible());
2429
- }, {
2430
- key,
2431
- debug: () => table.options.debugAll ?? table.options.debugColumns
2432
- });
2433
- };
2434
- return {
2435
- getVisibleFlatColumns: makeVisibleColumnsMethod('getVisibleFlatColumns', () => table.getAllFlatColumns()),
2436
- getVisibleLeafColumns: makeVisibleColumnsMethod('getVisibleLeafColumns', () => table.getAllLeafColumns()),
2437
- getLeftVisibleLeafColumns: makeVisibleColumnsMethod('getLeftVisibleLeafColumns', () => table.getLeftLeafColumns()),
2438
- getRightVisibleLeafColumns: makeVisibleColumnsMethod('getRightVisibleLeafColumns', () => table.getRightLeafColumns()),
2439
- getCenterVisibleLeafColumns: makeVisibleColumnsMethod('getCenterVisibleLeafColumns', () => table.getCenterLeafColumns()),
2440
- setColumnVisibility: updater => table.options.onColumnVisibilityChange == null ? void 0 : table.options.onColumnVisibilityChange(updater),
2441
- resetColumnVisibility: defaultState => {
2442
- table.setColumnVisibility(defaultState ? {} : table.initialState.columnVisibility ?? {});
2443
- },
2444
- toggleAllColumnsVisible: value => {
2445
- value = value ?? !table.getIsAllColumnsVisible();
2446
- table.setColumnVisibility(table.getAllLeafColumns().reduce((obj, column) => ({
2447
- ...obj,
2448
- [column.id]: !value ? !(column.getCanHide != null && column.getCanHide()) : value
2449
- }), {}));
2450
- },
2451
- getIsAllColumnsVisible: () => !table.getAllLeafColumns().some(column => !(column.getIsVisible != null && column.getIsVisible())),
2452
- getIsSomeColumnsVisible: () => table.getAllLeafColumns().some(column => column.getIsVisible == null ? void 0 : column.getIsVisible()),
2453
- getToggleAllColumnsVisibilityHandler: () => {
2454
- return e => {
2455
- var _target;
2456
- table.toggleAllColumnsVisible((_target = e.target) == null ? void 0 : _target.checked);
2457
- };
2458
- }
2459
- };
2460
- }
2461
- };
2462
-
2463
- const features = [Headers, Visibility, Ordering, Pinning, Filters, Sorting, Grouping, Expanding, Pagination, RowSelection, ColumnSizing];
2464
-
2465
- //
2466
-
2467
- function createTable(options) {
2468
- if (options.debugAll || options.debugTable) {
2469
- console.info('Creating Table Instance...');
2470
- }
2471
- let table = {
2472
- _features: features
2473
- };
2474
- const defaultOptions = table._features.reduce((obj, feature) => {
2475
- return Object.assign(obj, feature.getDefaultOptions == null ? void 0 : feature.getDefaultOptions(table));
2476
- }, {});
2477
- const mergeOptions = options => {
2478
- if (table.options.mergeOptions) {
2479
- return table.options.mergeOptions(defaultOptions, options);
2480
- }
2481
- return {
2482
- ...defaultOptions,
2483
- ...options
2484
- };
2485
- };
2486
- const coreInitialState = {};
2487
- let initialState = {
2488
- ...coreInitialState,
2489
- ...(options.initialState ?? {})
2490
- };
2491
- table._features.forEach(feature => {
2492
- initialState = (feature.getInitialState == null ? void 0 : feature.getInitialState(initialState)) ?? initialState;
2493
- });
2494
- const queued = [];
2495
- let queuedTimeout = false;
2496
- const coreInstance = {
2497
- _features: features,
2498
- options: {
2499
- ...defaultOptions,
2500
- ...options
2501
- },
2502
- initialState,
2503
- _queue: cb => {
2504
- queued.push(cb);
2505
- if (!queuedTimeout) {
2506
- queuedTimeout = true;
2507
-
2508
- // Schedule a microtask to run the queued callbacks after
2509
- // the current call stack (render, etc) has finished.
2510
- Promise.resolve().then(() => {
2511
- while (queued.length) {
2512
- queued.shift()();
2513
- }
2514
- queuedTimeout = false;
2515
- }).catch(error => setTimeout(() => {
2516
- throw error;
2517
- }));
2518
- }
2519
- },
2520
- reset: () => {
2521
- table.setState(table.initialState);
2522
- },
2523
- setOptions: updater => {
2524
- const newOptions = functionalUpdate(updater, table.options);
2525
- table.options = mergeOptions(newOptions);
2526
- },
2527
- getState: () => {
2528
- return table.options.state;
2529
- },
2530
- setState: updater => {
2531
- table.options.onStateChange == null ? void 0 : table.options.onStateChange(updater);
2532
- },
2533
- _getRowId: (row, index, parent) => (table.options.getRowId == null ? void 0 : table.options.getRowId(row, index, parent)) ?? `${parent ? [parent.id, index].join('.') : index}`,
2534
- getCoreRowModel: () => {
2535
- if (!table._getCoreRowModel) {
2536
- table._getCoreRowModel = table.options.getCoreRowModel(table);
2537
- }
2538
- return table._getCoreRowModel();
2539
- },
2540
- // The final calls start at the bottom of the model,
2541
- // expanded rows, which then work their way up
2542
-
2543
- getRowModel: () => {
2544
- return table.getPaginationRowModel();
2545
- },
2546
- getRow: id => {
2547
- const row = table.getRowModel().rowsById[id];
2548
- if (!row) {
2549
- if (process.env.NODE_ENV !== 'production') {
2550
- throw new Error(`getRow expected an ID, but got ${id}`);
2551
- }
2552
- throw new Error();
2553
- }
2554
- return row;
2555
- },
2556
- _getDefaultColumnDef: memo(() => [table.options.defaultColumn], defaultColumn => {
2557
- defaultColumn = defaultColumn ?? {};
2558
- return {
2559
- header: props => {
2560
- const resolvedColumnDef = props.header.column.columnDef;
2561
- if (resolvedColumnDef.accessorKey) {
2562
- return resolvedColumnDef.accessorKey;
2563
- }
2564
- if (resolvedColumnDef.accessorFn) {
2565
- return resolvedColumnDef.id;
2566
- }
2567
- return null;
2568
- },
2569
- // footer: props => props.header.column.id,
2570
- cell: props => {
2571
- var _props$renderValue;
2572
- return ((_props$renderValue = props.renderValue()) == null ? void 0 : _props$renderValue.toString == null ? void 0 : _props$renderValue.toString()) ?? null;
2573
- },
2574
- ...table._features.reduce((obj, feature) => {
2575
- return Object.assign(obj, feature.getDefaultColumnDef == null ? void 0 : feature.getDefaultColumnDef());
2576
- }, {}),
2577
- ...defaultColumn
2578
- };
2579
- }, {
2580
- debug: () => table.options.debugAll ?? table.options.debugColumns,
2581
- key: process.env.NODE_ENV === 'development' && 'getDefaultColumnDef'
2582
- }),
2583
- _getColumnDefs: () => table.options.columns,
2584
- getAllColumns: memo(() => [table._getColumnDefs()], columnDefs => {
2585
- const recurseColumns = function (columnDefs, parent, depth) {
2586
- if (depth === void 0) {
2587
- depth = 0;
2588
- }
2589
- return columnDefs.map(columnDef => {
2590
- const column = createColumn(table, columnDef, depth, parent);
2591
- const groupingColumnDef = columnDef;
2592
- column.columns = groupingColumnDef.columns ? recurseColumns(groupingColumnDef.columns, column, depth + 1) : [];
2593
- return column;
2594
- });
2595
- };
2596
- return recurseColumns(columnDefs);
2597
- }, {
2598
- key: process.env.NODE_ENV === 'development' && 'getAllColumns',
2599
- debug: () => table.options.debugAll ?? table.options.debugColumns
2600
- }),
2601
- getAllFlatColumns: memo(() => [table.getAllColumns()], allColumns => {
2602
- return allColumns.flatMap(column => {
2603
- return column.getFlatColumns();
2604
- });
2605
- }, {
2606
- key: process.env.NODE_ENV === 'development' && 'getAllFlatColumns',
2607
- debug: () => table.options.debugAll ?? table.options.debugColumns
2608
- }),
2609
- _getAllFlatColumnsById: memo(() => [table.getAllFlatColumns()], flatColumns => {
2610
- return flatColumns.reduce((acc, column) => {
2611
- acc[column.id] = column;
2612
- return acc;
2613
- }, {});
2614
- }, {
2615
- key: process.env.NODE_ENV === 'development' && 'getAllFlatColumnsById',
2616
- debug: () => table.options.debugAll ?? table.options.debugColumns
2617
- }),
2618
- getAllLeafColumns: memo(() => [table.getAllColumns(), table._getOrderColumnsFn()], (allColumns, orderColumns) => {
2619
- let leafColumns = allColumns.flatMap(column => column.getLeafColumns());
2620
- return orderColumns(leafColumns);
2621
- }, {
2622
- key: process.env.NODE_ENV === 'development' && 'getAllLeafColumns',
2623
- debug: () => table.options.debugAll ?? table.options.debugColumns
2624
- }),
2625
- getColumn: columnId => {
2626
- const column = table._getAllFlatColumnsById()[columnId];
2627
- if (!column) {
2628
- if (process.env.NODE_ENV !== 'production') {
2629
- console.warn(`[Table] Column with id ${columnId} does not exist.`);
2630
- }
2631
- throw new Error();
2632
- }
2633
- return column;
2634
- }
2635
- };
2636
- Object.assign(table, coreInstance);
2637
- table._features.forEach(feature => {
2638
- return Object.assign(table, feature.createTable == null ? void 0 : feature.createTable(table));
2639
- });
2640
- return table;
2641
- }
2642
-
2643
- function createCell(table, row, column, columnId) {
2644
- const getRenderValue = () => cell.getValue() ?? table.options.renderFallbackValue;
2645
- const cell = {
2646
- id: `${row.id}_${column.id}`,
2647
- row,
2648
- column,
2649
- getValue: () => row.getValue(columnId),
2650
- renderValue: getRenderValue,
2651
- getContext: memo(() => [table, column, row, cell], (table, column, row, cell) => ({
2652
- table,
2653
- column,
2654
- row,
2655
- cell: cell,
2656
- getValue: cell.getValue,
2657
- renderValue: cell.renderValue
2658
- }), {
2659
- key: process.env.NODE_ENV === 'development' && 'cell.getContext',
2660
- debug: () => table.options.debugAll
2661
- })
2662
- };
2663
- table._features.forEach(feature => {
2664
- Object.assign(cell, feature.createCell == null ? void 0 : feature.createCell(cell, column, row, table));
2665
- }, {});
2666
- return cell;
2667
- }
2668
-
2669
- const createRow = (table, id, original, rowIndex, depth, subRows) => {
2670
- let row = {
2671
- id,
2672
- index: rowIndex,
2673
- original,
2674
- depth,
2675
- _valuesCache: {},
2676
- _uniqueValuesCache: {},
2677
- getValue: columnId => {
2678
- if (row._valuesCache.hasOwnProperty(columnId)) {
2679
- return row._valuesCache[columnId];
2680
- }
2681
- const column = table.getColumn(columnId);
2682
- if (!column.accessorFn) {
2683
- return undefined;
2684
- }
2685
- row._valuesCache[columnId] = column.accessorFn(row.original, rowIndex);
2686
- return row._valuesCache[columnId];
2687
- },
2688
- getUniqueValues: columnId => {
2689
- if (row._uniqueValuesCache.hasOwnProperty(columnId)) {
2690
- return row._uniqueValuesCache[columnId];
2691
- }
2692
- const column = table.getColumn(columnId);
2693
- if (!column.accessorFn) {
2694
- return undefined;
2695
- }
2696
- if (!column.columnDef.getUniqueValues) {
2697
- row._uniqueValuesCache[columnId] = [row.getValue(columnId)];
2698
- return row._uniqueValuesCache[columnId];
2699
- }
2700
- row._uniqueValuesCache[columnId] = column.columnDef.getUniqueValues(row.original, rowIndex);
2701
- return row._uniqueValuesCache[columnId];
2702
- },
2703
- renderValue: columnId => row.getValue(columnId) ?? table.options.renderFallbackValue,
2704
- subRows: subRows ?? [],
2705
- getLeafRows: () => flattenBy(row.subRows, d => d.subRows),
2706
- getAllCells: memo(() => [table.getAllLeafColumns()], leafColumns => {
2707
- return leafColumns.map(column => {
2708
- return createCell(table, row, column, column.id);
2709
- });
2710
- }, {
2711
- key: process.env.NODE_ENV === 'development' && 'row.getAllCells',
2712
- debug: () => table.options.debugAll ?? table.options.debugRows
2713
- }),
2714
- _getAllCellsByColumnId: memo(() => [row.getAllCells()], allCells => {
2715
- return allCells.reduce((acc, cell) => {
2716
- acc[cell.column.id] = cell;
2717
- return acc;
2718
- }, {});
2719
- }, {
2720
- key: process.env.NODE_ENV === 'production' && 'row.getAllCellsByColumnId',
2721
- debug: () => table.options.debugAll ?? table.options.debugRows
2722
- })
2723
- };
2724
- for (let i = 0; i < table._features.length; i++) {
2725
- const feature = table._features[i];
2726
- Object.assign(row, feature == null ? void 0 : feature.createRow == null ? void 0 : feature.createRow(row, table));
2727
- }
2728
- return row;
2729
- };
2730
-
2731
- // type Person = {
2732
- // firstName: string
2733
- // lastName: string
2734
- // age: number
2735
- // visits: number
2736
- // status: string
2737
- // progress: number
2738
- // createdAt: Date
2739
- // nested: {
2740
- // foo: [
2741
- // {
2742
- // bar: 'bar'
2743
- // }
2744
- // ]
2745
- // bar: { subBar: boolean }[]
2746
- // baz: {
2747
- // foo: 'foo'
2748
- // bar: {
2749
- // baz: 'baz'
2750
- // }
2751
- // }
2752
- // }
2753
- // }
2754
-
2755
- // const test: DeepKeys<Person> = 'nested.foo.0.bar'
2756
- // const test2: DeepKeys<Person> = 'nested.bar'
2757
-
2758
- // const helper = createColumnHelper<Person>()
2759
-
2760
- // helper.accessor('nested.foo', {
2761
- // cell: info => info.getValue(),
2762
- // })
2763
-
2764
- // helper.accessor('nested.foo.0.bar', {
2765
- // cell: info => info.getValue(),
2766
- // })
2767
-
2768
- // helper.accessor('nested.bar', {
2769
- // cell: info => info.getValue(),
2770
- // })
2771
-
2772
- function createColumnHelper() {
2773
- return {
2774
- accessor: (accessor, column) => {
2775
- return typeof accessor === 'function' ? {
2776
- ...column,
2777
- accessorFn: accessor
2778
- } : {
2779
- ...column,
2780
- accessorKey: accessor
2781
- };
2782
- },
2783
- display: column => column,
2784
- group: column => column
2785
- };
2786
- }
2787
-
2788
- function getCoreRowModel() {
2789
- return table => memo(() => [table.options.data], data => {
2790
- const rowModel = {
2791
- rows: [],
2792
- flatRows: [],
2793
- rowsById: {}
2794
- };
2795
- const accessRows = function (originalRows, depth, parent) {
2796
- if (depth === void 0) {
2797
- depth = 0;
2798
- }
2799
- const rows = [];
2800
- for (let i = 0; i < originalRows.length; i++) {
2801
- // This could be an expensive check at scale, so we should move it somewhere else, but where?
2802
- // if (!id) {
2803
- // if (process.env.NODE_ENV !== 'production') {
2804
- // throw new Error(`getRowId expected an ID, but got ${id}`)
2805
- // }
2806
- // }
2807
-
2808
- // Make the row
2809
- const row = createRow(table, table._getRowId(originalRows[i], i, parent), originalRows[i], i, depth);
2810
-
2811
- // Keep track of every row in a flat array
2812
- rowModel.flatRows.push(row);
2813
- // Also keep track of every row by its ID
2814
- rowModel.rowsById[row.id] = row;
2815
- // Push table row into parent
2816
- rows.push(row);
2817
-
2818
- // Get the original subrows
2819
- if (table.options.getSubRows) {
2820
- var _row$originalSubRows;
2821
- row.originalSubRows = table.options.getSubRows(originalRows[i], i);
2822
-
2823
- // Then recursively access them
2824
- if ((_row$originalSubRows = row.originalSubRows) != null && _row$originalSubRows.length) {
2825
- row.subRows = accessRows(row.originalSubRows, depth + 1, row);
2826
- }
2827
- }
2828
- }
2829
- return rows;
2830
- };
2831
- rowModel.rows = accessRows(data);
2832
- return rowModel;
2833
- }, {
2834
- key: process.env.NODE_ENV === 'development' && 'getRowModel',
2835
- debug: () => table.options.debugAll ?? table.options.debugTable,
2836
- onChange: () => {
2837
- table._autoResetPageIndex();
2838
- }
2839
- });
2840
- }
2841
-
2842
- function filterRows(rows, filterRowImpl, table) {
2843
- if (table.options.filterFromLeafRows) {
2844
- return filterRowModelFromLeafs(rows, filterRowImpl, table);
2845
- }
2846
- return filterRowModelFromRoot(rows, filterRowImpl, table);
2847
- }
2848
- function filterRowModelFromLeafs(rowsToFilter, filterRow, table) {
2849
- const newFilteredFlatRows = [];
2850
- const newFilteredRowsById = {};
2851
- const recurseFilterRows = function (rowsToFilter, depth) {
2852
- const rows = [];
2853
-
2854
- // Filter from children up first
2855
- for (let i = 0; i < rowsToFilter.length; i++) {
2856
- var _row$subRows;
2857
- let row = rowsToFilter[i];
2858
- const newRow = createRow(table, row.id, row.original, row.index, row.depth);
2859
- newRow.columnFilters = row.columnFilters;
2860
- if ((_row$subRows = row.subRows) != null && _row$subRows.length) {
2861
- newRow.subRows = recurseFilterRows(row.subRows);
2862
- row = newRow;
2863
- if (filterRow(row) && !newRow.subRows.length) {
2864
- rows.push(row);
2865
- newFilteredRowsById[row.id] = row;
2866
- newFilteredRowsById[i] = row;
2867
- continue;
2868
- }
2869
- if (filterRow(row) || newRow.subRows.length) {
2870
- rows.push(row);
2871
- newFilteredRowsById[row.id] = row;
2872
- newFilteredRowsById[i] = row;
2873
- continue;
2874
- }
2875
- } else {
2876
- row = newRow;
2877
- if (filterRow(row)) {
2878
- rows.push(row);
2879
- newFilteredRowsById[row.id] = row;
2880
- newFilteredRowsById[i] = row;
2881
- }
2882
- }
2883
- }
2884
- return rows;
2885
- };
2886
- return {
2887
- rows: recurseFilterRows(rowsToFilter),
2888
- flatRows: newFilteredFlatRows,
2889
- rowsById: newFilteredRowsById
2890
- };
2891
- }
2892
- function filterRowModelFromRoot(rowsToFilter, filterRow, table) {
2893
- const newFilteredFlatRows = [];
2894
- const newFilteredRowsById = {};
2895
-
2896
- // Filters top level and nested rows
2897
- const recurseFilterRows = function (rowsToFilter, depth) {
2898
- // Filter from parents downward first
2899
-
2900
- const rows = [];
2901
-
2902
- // Apply the filter to any subRows
2903
- for (let i = 0; i < rowsToFilter.length; i++) {
2904
- let row = rowsToFilter[i];
2905
- const pass = filterRow(row);
2906
- if (pass) {
2907
- var _row$subRows2;
2908
- if ((_row$subRows2 = row.subRows) != null && _row$subRows2.length) {
2909
- const newRow = createRow(table, row.id, row.original, row.index, row.depth);
2910
- newRow.subRows = recurseFilterRows(row.subRows);
2911
- row = newRow;
2912
- }
2913
- rows.push(row);
2914
- newFilteredFlatRows.push(row);
2915
- newFilteredRowsById[row.id] = row;
2916
- }
2917
- }
2918
- return rows;
2919
- };
2920
- return {
2921
- rows: recurseFilterRows(rowsToFilter),
2922
- flatRows: newFilteredFlatRows,
2923
- rowsById: newFilteredRowsById
2924
- };
2925
- }
2926
-
2927
- function getFilteredRowModel() {
2928
- return table => memo(() => [table.getPreFilteredRowModel(), table.getState().columnFilters, table.getState().globalFilter], (rowModel, columnFilters, globalFilter) => {
2929
- if (!rowModel.rows.length || !(columnFilters != null && columnFilters.length) && !globalFilter) {
2930
- for (let i = 0; i < rowModel.flatRows.length; i++) {
2931
- rowModel.flatRows[i].columnFilters = {};
2932
- rowModel.flatRows[i].columnFiltersMeta = {};
2933
- }
2934
- return rowModel;
2935
- }
2936
- const resolvedColumnFilters = [];
2937
- const resolvedGlobalFilters = [];
2938
- (columnFilters ?? []).forEach(d => {
2939
- const column = table.getColumn(d.id);
2940
- if (!column) {
2941
- if (process.env.NODE_ENV !== 'production') {
2942
- console.warn(`Table: Could not find a column to filter with columnId: ${d.id}`);
2943
- }
2944
- }
2945
- const filterFn = column.getFilterFn();
2946
- if (!filterFn) {
2947
- if (process.env.NODE_ENV !== 'production') {
2948
- console.warn(`Could not find a valid 'column.filterFn' for column with the ID: ${column.id}.`);
2949
- }
2950
- return;
2951
- }
2952
- resolvedColumnFilters.push({
2953
- id: d.id,
2954
- filterFn,
2955
- resolvedValue: (filterFn.resolveFilterValue == null ? void 0 : filterFn.resolveFilterValue(d.value)) ?? d.value
2956
- });
2957
- });
2958
- const filterableIds = columnFilters.map(d => d.id);
2959
- const globalFilterFn = table.getGlobalFilterFn();
2960
- const globallyFilterableColumns = table.getAllLeafColumns().filter(column => column.getCanGlobalFilter());
2961
- if (globalFilter && globalFilterFn && globallyFilterableColumns.length) {
2962
- filterableIds.push('__global__');
2963
- globallyFilterableColumns.forEach(column => {
2964
- resolvedGlobalFilters.push({
2965
- id: column.id,
2966
- filterFn: globalFilterFn,
2967
- resolvedValue: (globalFilterFn.resolveFilterValue == null ? void 0 : globalFilterFn.resolveFilterValue(globalFilter)) ?? globalFilter
2968
- });
2969
- });
2970
- }
2971
- let currentColumnFilter;
2972
- let currentGlobalFilter;
2973
-
2974
- // Flag the prefiltered row model with each filter state
2975
- for (let j = 0; j < rowModel.flatRows.length; j++) {
2976
- const row = rowModel.flatRows[j];
2977
- row.columnFilters = {};
2978
- if (resolvedColumnFilters.length) {
2979
- for (let i = 0; i < resolvedColumnFilters.length; i++) {
2980
- currentColumnFilter = resolvedColumnFilters[i];
2981
- const id = currentColumnFilter.id;
2982
-
2983
- // Tag the row with the column filter state
2984
- row.columnFilters[id] = currentColumnFilter.filterFn(row, id, currentColumnFilter.resolvedValue, filterMeta => {
2985
- row.columnFiltersMeta[id] = filterMeta;
2986
- });
2987
- }
2988
- }
2989
- if (resolvedGlobalFilters.length) {
2990
- for (let i = 0; i < resolvedGlobalFilters.length; i++) {
2991
- currentGlobalFilter = resolvedGlobalFilters[i];
2992
- const id = currentGlobalFilter.id;
2993
- // Tag the row with the first truthy global filter state
2994
- if (currentGlobalFilter.filterFn(row, id, currentGlobalFilter.resolvedValue, filterMeta => {
2995
- row.columnFiltersMeta[id] = filterMeta;
2996
- })) {
2997
- row.columnFilters.__global__ = true;
2998
- break;
2999
- }
3000
- }
3001
- if (row.columnFilters.__global__ !== true) {
3002
- row.columnFilters.__global__ = false;
3003
- }
3004
- }
3005
- }
3006
- const filterRowsImpl = row => {
3007
- // Horizontally filter rows through each column
3008
- for (let i = 0; i < filterableIds.length; i++) {
3009
- if (row.columnFilters[filterableIds[i]] === false) {
3010
- return false;
3011
- }
3012
- }
3013
- return true;
3014
- };
3015
-
3016
- // Filter final rows using all of the active filters
3017
- return filterRows(rowModel.rows, filterRowsImpl, table);
3018
- }, {
3019
- key: process.env.NODE_ENV === 'development' && 'getFilteredRowModel',
3020
- debug: () => table.options.debugAll ?? table.options.debugTable,
3021
- onChange: () => {
3022
- table._autoResetPageIndex();
3023
- }
3024
- });
3025
- }
3026
-
3027
- function getFacetedRowModel() {
3028
- return (table, columnId) => memo(() => [table.getPreFilteredRowModel(), table.getState().columnFilters, table.getState().globalFilter, table.getFilteredRowModel()], (preRowModel, columnFilters, globalFilter) => {
3029
- if (!preRowModel.rows.length || !(columnFilters != null && columnFilters.length) && !globalFilter) {
3030
- return preRowModel;
3031
- }
3032
- const filterableIds = [...columnFilters.map(d => d.id).filter(d => d !== columnId), globalFilter ? '__global__' : undefined].filter(Boolean);
3033
- const filterRowsImpl = row => {
3034
- // Horizontally filter rows through each column
3035
- for (let i = 0; i < filterableIds.length; i++) {
3036
- if (row.columnFilters[filterableIds[i]] === false) {
3037
- return false;
3038
- }
3039
- }
3040
- return true;
3041
- };
3042
- return filterRows(preRowModel.rows, filterRowsImpl, table);
3043
- }, {
3044
- key: process.env.NODE_ENV === 'development' && 'getFacetedRowModel_' + columnId,
3045
- debug: () => table.options.debugAll ?? table.options.debugTable,
3046
- onChange: () => {}
3047
- });
3048
- }
3049
-
3050
- function getFacetedUniqueValues() {
3051
- return (table, columnId) => memo(() => [table.getColumn(columnId).getFacetedRowModel()], facetedRowModel => {
3052
- let facetedUniqueValues = new Map();
3053
- for (let i = 0; i < facetedRowModel.flatRows.length; i++) {
3054
- const values = facetedRowModel.flatRows[i].getUniqueValues(columnId);
3055
- for (let j = 0; j < values.length; j++) {
3056
- const value = values[j];
3057
- if (facetedUniqueValues.has(value)) {
3058
- facetedUniqueValues.set(value, (facetedUniqueValues.get(value) ?? 0) + 1);
3059
- } else {
3060
- facetedUniqueValues.set(value, 1);
3061
- }
3062
- }
3063
- }
3064
- return facetedUniqueValues;
3065
- }, {
3066
- key: process.env.NODE_ENV === 'development' && 'getFacetedUniqueValues_' + columnId,
3067
- debug: () => table.options.debugAll ?? table.options.debugTable,
3068
- onChange: () => {}
3069
- });
3070
- }
3071
-
3072
- function getFacetedMinMaxValues() {
3073
- return (table, columnId) => memo(() => [table.getColumn(columnId).getFacetedRowModel()], facetedRowModel => {
3074
- var _facetedRowModel$flat;
3075
- const firstValue = (_facetedRowModel$flat = facetedRowModel.flatRows[0]) == null ? void 0 : _facetedRowModel$flat.getUniqueValues(columnId);
3076
- if (typeof firstValue === 'undefined') {
3077
- return undefined;
3078
- }
3079
- let facetedMinMaxValues = [firstValue, firstValue];
3080
- for (let i = 0; i < facetedRowModel.flatRows.length; i++) {
3081
- const values = facetedRowModel.flatRows[i].getUniqueValues(columnId);
3082
- for (let j = 0; j < values.length; j++) {
3083
- const value = values[j];
3084
- if (value < facetedMinMaxValues[0]) {
3085
- facetedMinMaxValues[0] = value;
3086
- } else if (value > facetedMinMaxValues[1]) {
3087
- facetedMinMaxValues[1] = value;
3088
- }
3089
- }
3090
- }
3091
- return facetedMinMaxValues;
3092
- }, {
3093
- key: process.env.NODE_ENV === 'development' && 'getFacetedMinMaxValues_' + columnId,
3094
- debug: () => table.options.debugAll ?? table.options.debugTable,
3095
- onChange: () => {}
3096
- });
3097
- }
3098
-
3099
- function getSortedRowModel() {
3100
- return table => memo(() => [table.getState().sorting, table.getPreSortedRowModel()], (sorting, rowModel) => {
3101
- if (!rowModel.rows.length || !(sorting != null && sorting.length)) {
3102
- return rowModel;
3103
- }
3104
- const sortingState = table.getState().sorting;
3105
- const sortedFlatRows = [];
3106
-
3107
- // Filter out sortings that correspond to non existing columns
3108
- const availableSorting = sortingState.filter(sort => table.getColumn(sort.id).getCanSort());
3109
- const columnInfoById = {};
3110
- availableSorting.forEach(sortEntry => {
3111
- const column = table.getColumn(sortEntry.id);
3112
- columnInfoById[sortEntry.id] = {
3113
- sortUndefined: column.columnDef.sortUndefined,
3114
- invertSorting: column.columnDef.invertSorting,
3115
- sortingFn: column.getSortingFn()
3116
- };
3117
- });
3118
- const sortData = rows => {
3119
- // This will also perform a stable sorting using the row index
3120
- // if needed.
3121
- const sortedData = [...rows];
3122
- sortedData.sort((rowA, rowB) => {
3123
- for (let i = 0; i < availableSorting.length; i += 1) {
3124
- const sortEntry = availableSorting[i];
3125
- const columnInfo = columnInfoById[sortEntry.id];
3126
- const isDesc = (sortEntry == null ? void 0 : sortEntry.desc) ?? false;
3127
- if (columnInfo.sortUndefined) {
3128
- const aValue = rowA.getValue(sortEntry.id);
3129
- const bValue = rowB.getValue(sortEntry.id);
3130
- const aUndefined = typeof aValue === 'undefined';
3131
- const bUndefined = typeof bValue === 'undefined';
3132
- if (aUndefined || bUndefined) {
3133
- return aUndefined && bUndefined ? 0 : aUndefined ? columnInfo.sortUndefined : -columnInfo.sortUndefined;
3134
- }
3135
- }
3136
-
3137
- // This function should always return in ascending order
3138
- let sortInt = columnInfo.sortingFn(rowA, rowB, sortEntry.id);
3139
- if (sortInt !== 0) {
3140
- if (isDesc) {
3141
- sortInt *= -1;
3142
- }
3143
- if (columnInfo.invertSorting) {
3144
- sortInt *= -1;
3145
- }
3146
- return sortInt;
3147
- }
3148
- }
3149
- return rowA.index - rowB.index;
3150
- });
3151
-
3152
- // If there are sub-rows, sort them
3153
- sortedData.forEach(row => {
3154
- var _row$subRows;
3155
- sortedFlatRows.push(row);
3156
- if ((_row$subRows = row.subRows) != null && _row$subRows.length) {
3157
- row.subRows = sortData(row.subRows);
3158
- }
3159
- });
3160
- return sortedData;
3161
- };
3162
- return {
3163
- rows: sortData(rowModel.rows),
3164
- flatRows: sortedFlatRows,
3165
- rowsById: rowModel.rowsById
3166
- };
3167
- }, {
3168
- key: process.env.NODE_ENV === 'development' && 'getSortedRowModel',
3169
- debug: () => table.options.debugAll ?? table.options.debugTable,
3170
- onChange: () => {
3171
- table._autoResetPageIndex();
3172
- }
3173
- });
3174
- }
3175
-
3176
- function getGroupedRowModel() {
3177
- return table => memo(() => [table.getState().grouping, table.getPreGroupedRowModel()], (grouping, rowModel) => {
3178
- if (!rowModel.rows.length || !grouping.length) {
3179
- return rowModel;
3180
- }
3181
-
3182
- // Filter the grouping list down to columns that exist
3183
- const existingGrouping = grouping.filter(columnId => table.getColumn(columnId));
3184
- const groupedFlatRows = [];
3185
- const groupedRowsById = {};
3186
- // const onlyGroupedFlatRows: Row[] = [];
3187
- // const onlyGroupedRowsById: Record<RowId, Row> = {};
3188
- // const nonGroupedFlatRows: Row[] = [];
3189
- // const nonGroupedRowsById: Record<RowId, Row> = {};
3190
-
3191
- // Recursively group the data
3192
- const groupUpRecursively = function (rows, depth, parentId) {
3193
- if (depth === void 0) {
3194
- depth = 0;
3195
- }
3196
- // Grouping depth has been been met
3197
- // Stop grouping and simply rewrite thd depth and row relationships
3198
- if (depth >= existingGrouping.length) {
3199
- return rows.map(row => {
3200
- row.depth = depth;
3201
- groupedFlatRows.push(row);
3202
- groupedRowsById[row.id] = row;
3203
- if (row.subRows) {
3204
- row.subRows = groupUpRecursively(row.subRows, depth + 1);
3205
- }
3206
- return row;
3207
- });
3208
- }
3209
- const columnId = existingGrouping[depth];
3210
-
3211
- // Group the rows together for this level
3212
- const rowGroupsMap = groupBy(rows, columnId);
3213
-
3214
- // Peform aggregations for each group
3215
- const aggregatedGroupedRows = Array.from(rowGroupsMap.entries()).map((_ref, index) => {
3216
- let [groupingValue, groupedRows] = _ref;
3217
- let id = `${columnId}:${groupingValue}`;
3218
- id = parentId ? `${parentId}>${id}` : id;
3219
-
3220
- // First, Recurse to group sub rows before aggregation
3221
- const subRows = groupUpRecursively(groupedRows, depth + 1, id);
3222
-
3223
- // Flatten the leaf rows of the rows in this group
3224
- const leafRows = depth ? flattenBy(groupedRows, row => row.subRows) : groupedRows;
3225
- const row = createRow(table, id, leafRows[0].original, index, depth);
3226
- Object.assign(row, {
3227
- groupingColumnId: columnId,
3228
- groupingValue,
3229
- subRows,
3230
- leafRows,
3231
- getValue: columnId => {
3232
- // Don't aggregate columns that are in the grouping
3233
- if (existingGrouping.includes(columnId)) {
3234
- if (row._valuesCache.hasOwnProperty(columnId)) {
3235
- return row._valuesCache[columnId];
3236
- }
3237
- if (groupedRows[0]) {
3238
- row._valuesCache[columnId] = groupedRows[0].getValue(columnId) ?? undefined;
3239
- }
3240
- return row._valuesCache[columnId];
3241
- }
3242
- if (row._groupingValuesCache.hasOwnProperty(columnId)) {
3243
- return row._groupingValuesCache[columnId];
3244
- }
3245
-
3246
- // Aggregate the values
3247
- const column = table.getColumn(columnId);
3248
- const aggregateFn = column.getAggregationFn();
3249
- if (aggregateFn) {
3250
- row._groupingValuesCache[columnId] = aggregateFn(columnId, leafRows, groupedRows);
3251
- return row._groupingValuesCache[columnId];
3252
- }
3253
- }
3254
- });
3255
- subRows.forEach(subRow => {
3256
- groupedFlatRows.push(subRow);
3257
- groupedRowsById[subRow.id] = subRow;
3258
- // if (subRow.getIsGrouped?.()) {
3259
- // onlyGroupedFlatRows.push(subRow);
3260
- // onlyGroupedRowsById[subRow.id] = subRow;
3261
- // } else {
3262
- // nonGroupedFlatRows.push(subRow);
3263
- // nonGroupedRowsById[subRow.id] = subRow;
3264
- // }
3265
- });
3266
-
3267
- return row;
3268
- });
3269
- return aggregatedGroupedRows;
3270
- };
3271
- const groupedRows = groupUpRecursively(rowModel.rows, 0, '');
3272
- groupedRows.forEach(subRow => {
3273
- groupedFlatRows.push(subRow);
3274
- groupedRowsById[subRow.id] = subRow;
3275
- // if (subRow.getIsGrouped?.()) {
3276
- // onlyGroupedFlatRows.push(subRow);
3277
- // onlyGroupedRowsById[subRow.id] = subRow;
3278
- // } else {
3279
- // nonGroupedFlatRows.push(subRow);
3280
- // nonGroupedRowsById[subRow.id] = subRow;
3281
- // }
3282
- });
3283
-
3284
- return {
3285
- rows: groupedRows,
3286
- flatRows: groupedFlatRows,
3287
- rowsById: groupedRowsById
3288
- };
3289
- }, {
3290
- key: process.env.NODE_ENV === 'development' && 'getGroupedRowModel',
3291
- debug: () => table.options.debugAll ?? table.options.debugTable,
3292
- onChange: () => {
3293
- table._queue(() => {
3294
- table._autoResetExpanded();
3295
- table._autoResetPageIndex();
3296
- });
3297
- }
3298
- });
3299
- }
3300
- function groupBy(rows, columnId) {
3301
- const groupMap = new Map();
3302
- return rows.reduce((map, row) => {
3303
- const resKey = `${row.getValue(columnId)}`;
3304
- const previous = map.get(resKey);
3305
- if (!previous) {
3306
- map.set(resKey, [row]);
3307
- } else {
3308
- previous.push(row);
3309
- }
3310
- return map;
3311
- }, groupMap);
3312
- }
3313
-
3314
- function getExpandedRowModel() {
3315
- return table => memo(() => [table.getState().expanded, table.getPreExpandedRowModel(), table.options.paginateExpandedRows], (expanded, rowModel, paginateExpandedRows) => {
3316
- if (!rowModel.rows.length || expanded !== true && !Object.keys(expanded ?? {}).length) {
3317
- return rowModel;
3318
- }
3319
- if (!paginateExpandedRows) {
3320
- // Only expand rows at this point if they are being paginated
3321
- return rowModel;
3322
- }
3323
- return expandRows(rowModel);
3324
- }, {
3325
- key: process.env.NODE_ENV === 'development' && 'getExpandedRowModel',
3326
- debug: () => table.options.debugAll ?? table.options.debugTable
3327
- });
3328
- }
3329
- function expandRows(rowModel) {
3330
- const expandedRows = [];
3331
- const handleRow = row => {
3332
- var _row$subRows;
3333
- expandedRows.push(row);
3334
- if ((_row$subRows = row.subRows) != null && _row$subRows.length && row.getIsExpanded()) {
3335
- row.subRows.forEach(handleRow);
3336
- }
3337
- };
3338
- rowModel.rows.forEach(handleRow);
3339
- return {
3340
- rows: expandedRows,
3341
- flatRows: rowModel.flatRows,
3342
- rowsById: rowModel.rowsById
3343
- };
3344
- }
3345
-
3346
- function getPaginationRowModel(opts) {
3347
- return table => memo(() => [table.getState().pagination, table.getPrePaginationRowModel(), table.options.paginateExpandedRows ? undefined : table.getState().expanded], (pagination, rowModel) => {
3348
- if (!rowModel.rows.length) {
3349
- return rowModel;
3350
- }
3351
- const {
3352
- pageSize,
3353
- pageIndex
3354
- } = pagination;
3355
- let {
3356
- rows,
3357
- flatRows,
3358
- rowsById
3359
- } = rowModel;
3360
- const pageStart = pageSize * pageIndex;
3361
- const pageEnd = pageStart + pageSize;
3362
- rows = rows.slice(pageStart, pageEnd);
3363
- let paginatedRowModel;
3364
- if (!table.options.paginateExpandedRows) {
3365
- paginatedRowModel = expandRows({
3366
- rows,
3367
- flatRows,
3368
- rowsById
3369
- });
3370
- } else {
3371
- paginatedRowModel = {
3372
- rows,
3373
- flatRows,
3374
- rowsById
3375
- };
3376
- }
3377
- paginatedRowModel.flatRows = [];
3378
- const handleRow = row => {
3379
- paginatedRowModel.flatRows.push(row);
3380
- if (row.subRows.length) {
3381
- row.subRows.forEach(handleRow);
3382
- }
3383
- };
3384
- paginatedRowModel.rows.forEach(handleRow);
3385
- return paginatedRowModel;
3386
- }, {
3387
- key: process.env.NODE_ENV === 'development' && 'getPaginationRowModel',
3388
- debug: () => table.options.debugAll ?? table.options.debugTable
3389
- });
3390
- }
3391
-
3392
- /* packages/svelte-table/src/placeholder.svelte generated by Svelte v3.53.1 */
3393
-
3394
- function create_fragment$1(ctx) {
3395
- let t;
3396
-
3397
- return {
3398
- c() {
3399
- t = text$1(/*content*/ ctx[0]);
3400
- },
3401
- l(nodes) {
3402
- t = claim_text(nodes, /*content*/ ctx[0]);
3403
- },
3404
- m(target, anchor) {
3405
- insert_hydration(target, t, anchor);
3406
- },
3407
- p(ctx, [dirty]) {
3408
- if (dirty & /*content*/ 1) set_data(t, /*content*/ ctx[0]);
3409
- },
3410
- i: noop$1,
3411
- o: noop$1,
3412
- d(detaching) {
3413
- if (detaching) detach(t);
3414
- }
3415
- };
3416
- }
3417
-
3418
- function instance($$self, $$props, $$invalidate) {
3419
- let { content } = $$props;
3420
-
3421
- $$self.$$set = $$props => {
3422
- if ('content' in $$props) $$invalidate(0, content = $$props.content);
3423
- };
3424
-
3425
- return [content];
3426
- }
3427
-
3428
- class Placeholder$1 extends SvelteComponent {
3429
- constructor(options) {
3430
- super();
3431
- init(this, options, instance, create_fragment$1, safe_not_equal, { content: 0 });
3432
- }
3433
- }
3434
-
3435
- const PlaceholderServer = create_ssr_component(($$result, $$props, $$bindings, slots) => {
3436
- return `${escape($$props.content)}`;
3437
- });
3438
- var Placeholder = typeof document === 'undefined' ? PlaceholderServer : Placeholder$1;
3439
-
3440
- function create_fragment(ctx, Comp, props) {
3441
- let c;
3442
- let current;
3443
- c = new Comp({
3444
- props,
3445
- $$inline: true
3446
- });
3447
- return {
3448
- c() {
3449
- create_component(c.$$.fragment);
3450
- },
3451
- l(nodes) {
3452
- claim_component(c.$$.fragment, nodes);
3453
- },
3454
- m(target, anchor) {
3455
- // @ts-ignore
3456
- mount_component(c, target, anchor);
3457
- current = true;
3458
- },
3459
- p: noop$1,
3460
- i(local) {
3461
- if (current) return;
3462
- transition_in(c.$$.fragment, local);
3463
- current = true;
3464
- },
3465
- o(local) {
3466
- transition_out(c.$$.fragment, local);
3467
- current = false;
3468
- },
3469
- d(detaching) {
3470
- destroy_component(c, detaching);
3471
- }
3472
- };
3473
- }
3474
- function renderClient(Comp, props) {
3475
- return class WrapperComp extends SvelteComponent {
3476
- constructor(options) {
3477
- super();
3478
- init(this, options, null, ctx => create_fragment(ctx, Comp, props), safe_not_equal, {}, undefined);
3479
- }
3480
- };
3481
- }
3482
- function renderServer(Comp, props) {
3483
- const WrapperComp = create_ssr_component(($$result, $$props, $$bindings, slots) => {
3484
- return `${validate_component(Comp, 'TableComponent').$$render($$result, props, {}, {})}`;
3485
- });
3486
- return WrapperComp;
3487
- }
3488
- const renderComponent = typeof window === 'undefined' ? renderServer : renderClient;
3489
-
3490
- function isSvelteServerComponent(component) {
3491
- return typeof component === 'object' && typeof component.$$render === 'function' && typeof component.render === 'function';
3492
- }
3493
- function isSvelteClientComponent(component) {
3494
- var _component$name, _component$name2;
3495
- let isHMR = ('__SVELTE_HMR' in window);
3496
- 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('>'));
3497
- }
3498
- function isSvelteComponent(component) {
3499
- if (typeof document === 'undefined') {
3500
- return isSvelteServerComponent(component);
3501
- } else {
3502
- return isSvelteClientComponent(component);
3503
- }
3504
- }
3505
- function wrapInPlaceholder(content) {
3506
- return renderComponent(Placeholder, {
3507
- content
3508
- });
3509
- }
3510
- function flexRender(component, props) {
3511
- if (!component) return null;
3512
- if (isSvelteComponent(component)) {
3513
- return renderComponent(component, props);
3514
- }
3515
- if (typeof component === 'function') {
3516
- const result = component(props);
3517
- if (isSvelteComponent(result)) {
3518
- return result;
3519
- }
3520
- return wrapInPlaceholder(result);
3521
- }
3522
- return wrapInPlaceholder(component);
3523
- }
3524
- function createSvelteTable(options) {
3525
- let optionsStore;
3526
- if ('subscribe' in options) {
3527
- optionsStore = options;
3528
- } else {
3529
- optionsStore = readable(options);
3530
- }
3531
- let resolvedOptions = {
3532
- state: {},
3533
- // Dummy state
3534
- onStateChange: () => {},
3535
- // noop
3536
- renderFallbackValue: null,
3537
- ...get(optionsStore)
3538
- };
3539
- let table = createTable(resolvedOptions);
3540
- let stateStore = writable( /** @type {number} */table.initialState);
3541
- // combine stores
3542
- let stateOptionsStore = derived([stateStore, optionsStore], s => s);
3543
- const tableReadable = readable(table, function start(set) {
3544
- const unsubscribe = stateOptionsStore.subscribe(_ref => {
3545
- let [state, options] = _ref;
3546
- table.setOptions(prev => {
3547
- return {
3548
- ...prev,
3549
- ...options,
3550
- state: {
3551
- ...state,
3552
- ...options.state
3553
- },
3554
- // Similarly, we'll maintain both our internal state and any user-provided
3555
- // state.
3556
- onStateChange: updater => {
3557
- if (updater instanceof Function) {
3558
- stateStore.update(updater);
3559
- } else {
3560
- stateStore.set(updater);
3561
- }
3562
- resolvedOptions.onStateChange == null ? void 0 : resolvedOptions.onStateChange(updater);
3563
- }
3564
- };
3565
- });
3566
-
3567
- // it didn't seem to rerender without setting the table
3568
- set(table);
3569
- });
3570
- return function stop() {
3571
- unsubscribe();
3572
- };
3573
- });
3574
- return tableReadable;
3575
- }
3576
-
3577
- 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 };
3578
- //# sourceMappingURL=index.js.map