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