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