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