@osdk/react-components 0.1.0-beta.1 → 0.1.0-beta.3

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 (131) hide show
  1. package/CHANGELOG.md +33 -0
  2. package/README.md +51 -1
  3. package/build/browser/base-components/checkbox/Checkbox.js +40 -0
  4. package/build/browser/base-components/checkbox/Checkbox.js.map +1 -0
  5. package/build/browser/base-components/checkbox/Checkbox.module.css +71 -0
  6. package/build/browser/css-modules.d.ts +20 -0
  7. package/build/browser/object-table/CellContextMenu.js +48 -0
  8. package/build/browser/object-table/CellContextMenu.js.map +1 -0
  9. package/build/browser/object-table/ObjectTable.js +53 -9
  10. package/build/browser/object-table/ObjectTable.js.map +1 -1
  11. package/build/browser/object-table/ObjectTableApi.js.map +1 -1
  12. package/build/browser/object-table/SelectionCells.js +45 -0
  13. package/build/browser/object-table/SelectionCells.js.map +1 -0
  14. package/build/browser/object-table/Table.js +8 -4
  15. package/build/browser/object-table/Table.js.map +1 -1
  16. package/build/browser/object-table/TableBody.js +3 -1
  17. package/build/browser/object-table/TableBody.js.map +1 -1
  18. package/build/browser/object-table/TableCell.js +51 -0
  19. package/build/browser/object-table/TableCell.js.map +1 -0
  20. package/build/browser/object-table/TableHeader.js +20 -4
  21. package/build/browser/object-table/TableHeader.js.map +1 -1
  22. package/build/browser/object-table/TableRow.js +7 -9
  23. package/build/browser/object-table/TableRow.js.map +1 -1
  24. package/build/browser/object-table/hooks/__tests__/useCellContextMenu.test.js +147 -0
  25. package/build/browser/object-table/hooks/__tests__/useCellContextMenu.test.js.map +1 -0
  26. package/build/browser/object-table/hooks/__tests__/useObjectTableData.test.js +12 -0
  27. package/build/browser/object-table/hooks/__tests__/useObjectTableData.test.js.map +1 -1
  28. package/build/browser/object-table/hooks/__tests__/useRowSelection.test.js +548 -0
  29. package/build/browser/object-table/hooks/__tests__/useRowSelection.test.js.map +1 -0
  30. package/build/browser/object-table/hooks/__tests__/useSelectionColumn.test.js +274 -0
  31. package/build/browser/object-table/hooks/__tests__/useSelectionColumn.test.js.map +1 -0
  32. package/build/browser/object-table/hooks/useCellContextMenu.js +48 -0
  33. package/build/browser/object-table/hooks/useCellContextMenu.js.map +1 -0
  34. package/build/browser/object-table/hooks/useColumnDefs.js.map +1 -1
  35. package/build/browser/object-table/hooks/useObjectTableData.js +3 -2
  36. package/build/browser/object-table/hooks/useObjectTableData.js.map +1 -1
  37. package/build/browser/object-table/hooks/useRowSelection.js +180 -0
  38. package/build/browser/object-table/hooks/useRowSelection.js.map +1 -0
  39. package/build/browser/object-table/hooks/useSelectionColumn.js +51 -0
  40. package/build/browser/object-table/hooks/useSelectionColumn.js.map +1 -0
  41. package/build/browser/object-table/utils/getRowId.js +21 -0
  42. package/build/browser/object-table/utils/getRowId.js.map +1 -0
  43. package/build/browser/public/experimental.js +1 -0
  44. package/build/browser/public/experimental.js.map +1 -1
  45. package/build/cjs/public/experimental.cjs +424 -3611
  46. package/build/cjs/public/experimental.cjs.map +1 -1
  47. package/build/cjs/public/experimental.css +48 -0
  48. package/build/cjs/public/experimental.css.map +1 -0
  49. package/build/cjs/public/experimental.d.cts +6 -11
  50. package/build/esm/base-components/checkbox/Checkbox.js +40 -0
  51. package/build/esm/base-components/checkbox/Checkbox.js.map +1 -0
  52. package/build/esm/base-components/checkbox/Checkbox.module.css +71 -0
  53. package/build/esm/css-modules.d.ts +20 -0
  54. package/build/esm/object-table/CellContextMenu.js +48 -0
  55. package/build/esm/object-table/CellContextMenu.js.map +1 -0
  56. package/build/esm/object-table/ObjectTable.js +53 -9
  57. package/build/esm/object-table/ObjectTable.js.map +1 -1
  58. package/build/esm/object-table/ObjectTableApi.js.map +1 -1
  59. package/build/esm/object-table/SelectionCells.js +45 -0
  60. package/build/esm/object-table/SelectionCells.js.map +1 -0
  61. package/build/esm/object-table/Table.js +8 -4
  62. package/build/esm/object-table/Table.js.map +1 -1
  63. package/build/esm/object-table/TableBody.js +3 -1
  64. package/build/esm/object-table/TableBody.js.map +1 -1
  65. package/build/esm/object-table/TableCell.js +51 -0
  66. package/build/esm/object-table/TableCell.js.map +1 -0
  67. package/build/esm/object-table/TableHeader.js +20 -4
  68. package/build/esm/object-table/TableHeader.js.map +1 -1
  69. package/build/esm/object-table/TableRow.js +7 -9
  70. package/build/esm/object-table/TableRow.js.map +1 -1
  71. package/build/esm/object-table/hooks/__tests__/useCellContextMenu.test.js +147 -0
  72. package/build/esm/object-table/hooks/__tests__/useCellContextMenu.test.js.map +1 -0
  73. package/build/esm/object-table/hooks/__tests__/useObjectTableData.test.js +12 -0
  74. package/build/esm/object-table/hooks/__tests__/useObjectTableData.test.js.map +1 -1
  75. package/build/esm/object-table/hooks/__tests__/useRowSelection.test.js +548 -0
  76. package/build/esm/object-table/hooks/__tests__/useRowSelection.test.js.map +1 -0
  77. package/build/esm/object-table/hooks/__tests__/useSelectionColumn.test.js +274 -0
  78. package/build/esm/object-table/hooks/__tests__/useSelectionColumn.test.js.map +1 -0
  79. package/build/esm/object-table/hooks/useCellContextMenu.js +48 -0
  80. package/build/esm/object-table/hooks/useCellContextMenu.js.map +1 -0
  81. package/build/esm/object-table/hooks/useColumnDefs.js.map +1 -1
  82. package/build/esm/object-table/hooks/useObjectTableData.js +3 -2
  83. package/build/esm/object-table/hooks/useObjectTableData.js.map +1 -1
  84. package/build/esm/object-table/hooks/useRowSelection.js +180 -0
  85. package/build/esm/object-table/hooks/useRowSelection.js.map +1 -0
  86. package/build/esm/object-table/hooks/useSelectionColumn.js +51 -0
  87. package/build/esm/object-table/hooks/useSelectionColumn.js.map +1 -0
  88. package/build/esm/object-table/utils/getRowId.js +21 -0
  89. package/build/esm/object-table/utils/getRowId.js.map +1 -0
  90. package/build/esm/public/experimental.js +1 -0
  91. package/build/esm/public/experimental.js.map +1 -1
  92. package/build/types/base-components/checkbox/Checkbox.d.ts +10 -0
  93. package/build/types/base-components/checkbox/Checkbox.d.ts.map +1 -0
  94. package/build/types/css-modules.d.d.ts +6 -0
  95. package/build/types/css-modules.d.d.ts.map +1 -0
  96. package/build/types/object-table/CellContextMenu.d.ts +11 -0
  97. package/build/types/object-table/CellContextMenu.d.ts.map +1 -0
  98. package/build/types/object-table/ObjectTable.d.ts +1 -1
  99. package/build/types/object-table/ObjectTable.d.ts.map +1 -1
  100. package/build/types/object-table/ObjectTableApi.d.ts +5 -10
  101. package/build/types/object-table/ObjectTableApi.d.ts.map +1 -1
  102. package/build/types/object-table/SelectionCells.d.ts +14 -0
  103. package/build/types/object-table/SelectionCells.d.ts.map +1 -0
  104. package/build/types/object-table/Table.d.ts +4 -3
  105. package/build/types/object-table/Table.d.ts.map +1 -1
  106. package/build/types/object-table/TableBody.d.ts +3 -2
  107. package/build/types/object-table/TableBody.d.ts.map +1 -1
  108. package/build/types/object-table/TableCell.d.ts +8 -0
  109. package/build/types/object-table/TableCell.d.ts.map +1 -0
  110. package/build/types/object-table/TableHeader.d.ts +3 -3
  111. package/build/types/object-table/TableHeader.d.ts.map +1 -1
  112. package/build/types/object-table/TableRow.d.ts +3 -2
  113. package/build/types/object-table/TableRow.d.ts.map +1 -1
  114. package/build/types/object-table/hooks/__tests__/useCellContextMenu.test.d.ts +1 -0
  115. package/build/types/object-table/hooks/__tests__/useCellContextMenu.test.d.ts.map +1 -0
  116. package/build/types/object-table/hooks/__tests__/useRowSelection.test.d.ts +1 -0
  117. package/build/types/object-table/hooks/__tests__/useRowSelection.test.d.ts.map +1 -0
  118. package/build/types/object-table/hooks/__tests__/useSelectionColumn.test.d.ts +1 -0
  119. package/build/types/object-table/hooks/__tests__/useSelectionColumn.test.d.ts.map +1 -0
  120. package/build/types/object-table/hooks/useCellContextMenu.d.ts +17 -0
  121. package/build/types/object-table/hooks/useCellContextMenu.d.ts.map +1 -0
  122. package/build/types/object-table/hooks/useObjectTableData.d.ts +2 -2
  123. package/build/types/object-table/hooks/useObjectTableData.d.ts.map +1 -1
  124. package/build/types/object-table/hooks/useRowSelection.d.ts +22 -0
  125. package/build/types/object-table/hooks/useRowSelection.d.ts.map +1 -0
  126. package/build/types/object-table/hooks/useSelectionColumn.d.ts +15 -0
  127. package/build/types/object-table/hooks/useSelectionColumn.d.ts.map +1 -0
  128. package/build/types/object-table/utils/getRowId.d.ts +6 -0
  129. package/build/types/object-table/utils/getRowId.d.ts.map +1 -0
  130. package/build/types/public/experimental.d.ts.map +1 -1
  131. package/package.json +13 -6
@@ -1,2706 +1,28 @@
1
1
  'use strict';
2
2
 
3
- var React2 = require('react');
3
+ var reactTable = require('@tanstack/react-table');
4
+ var React = require('react');
4
5
  var react = require('@osdk/react');
5
6
  var experimental = require('@osdk/react/experimental');
7
+ var checkbox = require('@base-ui/react/checkbox');
8
+ var icons = require('@blueprintjs/icons');
9
+ var classnames = require('classnames');
10
+ var reactVirtual = require('@tanstack/react-virtual');
6
11
  var reactDom = require('react-dom');
7
12
 
8
- function _interopNamespace(e) {
9
- if (e && e.__esModule) return e;
10
- var n = Object.create(null);
11
- if (e) {
12
- Object.keys(e).forEach(function (k) {
13
- if (k !== 'default') {
14
- var d = Object.getOwnPropertyDescriptor(e, k);
15
- Object.defineProperty(n, k, d.get ? d : {
16
- enumerable: true,
17
- get: function () { return e[k]; }
18
- });
19
- }
20
- });
21
- }
22
- n.default = e;
23
- return Object.freeze(n);
24
- }
25
-
26
- var React2__namespace = /*#__PURE__*/_interopNamespace(React2);
27
-
28
- // ../../node_modules/.pnpm/@tanstack+react-table@8.21.3_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/@tanstack/react-table/build/lib/index.mjs
29
-
30
- // ../../node_modules/.pnpm/@tanstack+table-core@8.21.3/node_modules/@tanstack/table-core/build/lib/index.mjs
31
- function functionalUpdate(updater, input) {
32
- return typeof updater === "function" ? updater(input) : updater;
33
- }
34
- function makeStateUpdater(key, instance) {
35
- return (updater) => {
36
- instance.setState((old) => {
37
- return {
38
- ...old,
39
- [key]: functionalUpdate(updater, old[key])
40
- };
41
- });
42
- };
43
- }
44
- function isFunction(d) {
45
- return d instanceof Function;
46
- }
47
- function isNumberArray(d) {
48
- return Array.isArray(d) && d.every((val) => typeof val === "number");
49
- }
50
- function flattenBy(arr, getChildren) {
51
- const flat = [];
52
- const recurse = (subArr) => {
53
- subArr.forEach((item) => {
54
- flat.push(item);
55
- const children = getChildren(item);
56
- if (children != null && children.length) {
57
- recurse(children);
58
- }
59
- });
60
- };
61
- recurse(arr);
62
- return flat;
63
- }
64
- function memo(getDeps, fn, opts) {
65
- let deps = [];
66
- let result;
67
- return (depArgs) => {
68
- let depTime;
69
- if (opts.key && opts.debug) depTime = Date.now();
70
- const newDeps = getDeps(depArgs);
71
- const depsChanged = newDeps.length !== deps.length || newDeps.some((dep, index) => deps[index] !== dep);
72
- if (!depsChanged) {
73
- return result;
74
- }
75
- deps = newDeps;
76
- let resultTime;
77
- if (opts.key && opts.debug) resultTime = Date.now();
78
- result = fn(...newDeps);
79
- opts == null || opts.onChange == null || opts.onChange(result);
80
- if (opts.key && opts.debug) {
81
- if (opts != null && opts.debug()) {
82
- const depEndTime = Math.round((Date.now() - depTime) * 100) / 100;
83
- const resultEndTime = Math.round((Date.now() - resultTime) * 100) / 100;
84
- const resultFpsPercentage = resultEndTime / 16;
85
- const pad = (str, num) => {
86
- str = String(str);
87
- while (str.length < num) {
88
- str = " " + str;
89
- }
90
- return str;
91
- };
92
- console.info(`%c\u23F1 ${pad(resultEndTime, 5)} /${pad(depEndTime, 5)} ms`, `
93
- font-size: .6rem;
94
- font-weight: bold;
95
- color: hsl(${Math.max(0, Math.min(120 - 120 * resultFpsPercentage, 120))}deg 100% 31%);`, opts == null ? void 0 : opts.key);
96
- }
97
- }
98
- return result;
99
- };
100
- }
101
- function getMemoOptions(tableOptions, debugLevel, key, onChange) {
102
- return {
103
- debug: () => {
104
- var _tableOptions$debugAl;
105
- return (_tableOptions$debugAl = tableOptions == null ? void 0 : tableOptions.debugAll) != null ? _tableOptions$debugAl : tableOptions[debugLevel];
106
- },
107
- key: process.env.NODE_ENV === "development" && key,
108
- onChange
109
- };
110
- }
111
- function createCell(table, row, column, columnId) {
112
- const getRenderValue = () => {
113
- var _cell$getValue;
114
- return (_cell$getValue = cell.getValue()) != null ? _cell$getValue : table.options.renderFallbackValue;
115
- };
116
- const cell = {
117
- id: `${row.id}_${column.id}`,
118
- row,
119
- column,
120
- getValue: () => row.getValue(columnId),
121
- renderValue: getRenderValue,
122
- getContext: memo(() => [table, column, row, cell], (table2, column2, row2, cell2) => ({
123
- table: table2,
124
- column: column2,
125
- row: row2,
126
- cell: cell2,
127
- getValue: cell2.getValue,
128
- renderValue: cell2.renderValue
129
- }), getMemoOptions(table.options, "debugCells", "cell.getContext"))
130
- };
131
- table._features.forEach((feature) => {
132
- feature.createCell == null || feature.createCell(cell, column, row, table);
133
- }, {});
134
- return cell;
135
- }
136
- function createColumn(table, columnDef, depth, parent) {
137
- var _ref, _resolvedColumnDef$id;
138
- const defaultColumn = table._getDefaultColumnDef();
139
- const resolvedColumnDef = {
140
- ...defaultColumn,
141
- ...columnDef
142
- };
143
- const accessorKey = resolvedColumnDef.accessorKey;
144
- let id = (_ref = (_resolvedColumnDef$id = resolvedColumnDef.id) != null ? _resolvedColumnDef$id : accessorKey ? typeof String.prototype.replaceAll === "function" ? accessorKey.replaceAll(".", "_") : accessorKey.replace(/\./g, "_") : void 0) != null ? _ref : typeof resolvedColumnDef.header === "string" ? resolvedColumnDef.header : void 0;
145
- let accessorFn;
146
- if (resolvedColumnDef.accessorFn) {
147
- accessorFn = resolvedColumnDef.accessorFn;
148
- } else if (accessorKey) {
149
- if (accessorKey.includes(".")) {
150
- accessorFn = (originalRow) => {
151
- let result = originalRow;
152
- for (const key of accessorKey.split(".")) {
153
- var _result;
154
- result = (_result = result) == null ? void 0 : _result[key];
155
- if (process.env.NODE_ENV !== "production" && result === void 0) {
156
- console.warn(`"${key}" in deeply nested key "${accessorKey}" returned undefined.`);
157
- }
158
- }
159
- return result;
160
- };
161
- } else {
162
- accessorFn = (originalRow) => originalRow[resolvedColumnDef.accessorKey];
163
- }
164
- }
165
- if (!id) {
166
- if (process.env.NODE_ENV !== "production") {
167
- throw new Error(resolvedColumnDef.accessorFn ? `Columns require an id when using an accessorFn` : `Columns require an id when using a non-string header`);
168
- }
169
- throw new Error();
170
- }
171
- let column = {
172
- id: `${String(id)}`,
173
- accessorFn,
174
- parent,
175
- depth,
176
- columnDef: resolvedColumnDef,
177
- columns: [],
178
- getFlatColumns: memo(() => [true], () => {
179
- var _column$columns;
180
- return [column, ...(_column$columns = column.columns) == null ? void 0 : _column$columns.flatMap((d) => d.getFlatColumns())];
181
- }, getMemoOptions(table.options, "debugColumns", "column.getFlatColumns")),
182
- getLeafColumns: memo(() => [table._getOrderColumnsFn()], (orderColumns2) => {
183
- var _column$columns2;
184
- if ((_column$columns2 = column.columns) != null && _column$columns2.length) {
185
- let leafColumns = column.columns.flatMap((column2) => column2.getLeafColumns());
186
- return orderColumns2(leafColumns);
187
- }
188
- return [column];
189
- }, getMemoOptions(table.options, "debugColumns", "column.getLeafColumns"))
190
- };
191
- for (const feature of table._features) {
192
- feature.createColumn == null || feature.createColumn(column, table);
193
- }
194
- return column;
195
- }
196
- var debug = "debugHeaders";
197
- function createHeader(table, column, options) {
198
- var _options$id;
199
- const id = (_options$id = options.id) != null ? _options$id : column.id;
200
- let header = {
201
- id,
202
- column,
203
- index: options.index,
204
- isPlaceholder: !!options.isPlaceholder,
205
- placeholderId: options.placeholderId,
206
- depth: options.depth,
207
- subHeaders: [],
208
- colSpan: 0,
209
- rowSpan: 0,
210
- headerGroup: null,
211
- getLeafHeaders: () => {
212
- const leafHeaders = [];
213
- const recurseHeader = (h) => {
214
- if (h.subHeaders && h.subHeaders.length) {
215
- h.subHeaders.map(recurseHeader);
216
- }
217
- leafHeaders.push(h);
218
- };
219
- recurseHeader(header);
220
- return leafHeaders;
221
- },
222
- getContext: () => ({
223
- table,
224
- header,
225
- column
226
- })
227
- };
228
- table._features.forEach((feature) => {
229
- feature.createHeader == null || feature.createHeader(header, table);
230
- });
231
- return header;
232
- }
233
- var Headers = {
234
- createTable: (table) => {
235
- table.getHeaderGroups = memo(() => [table.getAllColumns(), table.getVisibleLeafColumns(), table.getState().columnPinning.left, table.getState().columnPinning.right], (allColumns, leafColumns, left, right) => {
236
- var _left$map$filter, _right$map$filter;
237
- const leftColumns = (_left$map$filter = left == null ? void 0 : left.map((columnId) => leafColumns.find((d) => d.id === columnId)).filter(Boolean)) != null ? _left$map$filter : [];
238
- const rightColumns = (_right$map$filter = right == null ? void 0 : right.map((columnId) => leafColumns.find((d) => d.id === columnId)).filter(Boolean)) != null ? _right$map$filter : [];
239
- const centerColumns = leafColumns.filter((column) => !(left != null && left.includes(column.id)) && !(right != null && right.includes(column.id)));
240
- const headerGroups = buildHeaderGroups(allColumns, [...leftColumns, ...centerColumns, ...rightColumns], table);
241
- return headerGroups;
242
- }, getMemoOptions(table.options, debug, "getHeaderGroups"));
243
- table.getCenterHeaderGroups = memo(() => [table.getAllColumns(), table.getVisibleLeafColumns(), table.getState().columnPinning.left, table.getState().columnPinning.right], (allColumns, leafColumns, left, right) => {
244
- leafColumns = leafColumns.filter((column) => !(left != null && left.includes(column.id)) && !(right != null && right.includes(column.id)));
245
- return buildHeaderGroups(allColumns, leafColumns, table, "center");
246
- }, getMemoOptions(table.options, debug, "getCenterHeaderGroups"));
247
- table.getLeftHeaderGroups = memo(() => [table.getAllColumns(), table.getVisibleLeafColumns(), table.getState().columnPinning.left], (allColumns, leafColumns, left) => {
248
- var _left$map$filter2;
249
- const orderedLeafColumns = (_left$map$filter2 = left == null ? void 0 : left.map((columnId) => leafColumns.find((d) => d.id === columnId)).filter(Boolean)) != null ? _left$map$filter2 : [];
250
- return buildHeaderGroups(allColumns, orderedLeafColumns, table, "left");
251
- }, getMemoOptions(table.options, debug, "getLeftHeaderGroups"));
252
- table.getRightHeaderGroups = memo(() => [table.getAllColumns(), table.getVisibleLeafColumns(), table.getState().columnPinning.right], (allColumns, leafColumns, right) => {
253
- var _right$map$filter2;
254
- const orderedLeafColumns = (_right$map$filter2 = right == null ? void 0 : right.map((columnId) => leafColumns.find((d) => d.id === columnId)).filter(Boolean)) != null ? _right$map$filter2 : [];
255
- return buildHeaderGroups(allColumns, orderedLeafColumns, table, "right");
256
- }, getMemoOptions(table.options, debug, "getRightHeaderGroups"));
257
- table.getFooterGroups = memo(() => [table.getHeaderGroups()], (headerGroups) => {
258
- return [...headerGroups].reverse();
259
- }, getMemoOptions(table.options, debug, "getFooterGroups"));
260
- table.getLeftFooterGroups = memo(() => [table.getLeftHeaderGroups()], (headerGroups) => {
261
- return [...headerGroups].reverse();
262
- }, getMemoOptions(table.options, debug, "getLeftFooterGroups"));
263
- table.getCenterFooterGroups = memo(() => [table.getCenterHeaderGroups()], (headerGroups) => {
264
- return [...headerGroups].reverse();
265
- }, getMemoOptions(table.options, debug, "getCenterFooterGroups"));
266
- table.getRightFooterGroups = memo(() => [table.getRightHeaderGroups()], (headerGroups) => {
267
- return [...headerGroups].reverse();
268
- }, getMemoOptions(table.options, debug, "getRightFooterGroups"));
269
- table.getFlatHeaders = memo(() => [table.getHeaderGroups()], (headerGroups) => {
270
- return headerGroups.map((headerGroup) => {
271
- return headerGroup.headers;
272
- }).flat();
273
- }, getMemoOptions(table.options, debug, "getFlatHeaders"));
274
- table.getLeftFlatHeaders = memo(() => [table.getLeftHeaderGroups()], (left) => {
275
- return left.map((headerGroup) => {
276
- return headerGroup.headers;
277
- }).flat();
278
- }, getMemoOptions(table.options, debug, "getLeftFlatHeaders"));
279
- table.getCenterFlatHeaders = memo(() => [table.getCenterHeaderGroups()], (left) => {
280
- return left.map((headerGroup) => {
281
- return headerGroup.headers;
282
- }).flat();
283
- }, getMemoOptions(table.options, debug, "getCenterFlatHeaders"));
284
- table.getRightFlatHeaders = memo(() => [table.getRightHeaderGroups()], (left) => {
285
- return left.map((headerGroup) => {
286
- return headerGroup.headers;
287
- }).flat();
288
- }, getMemoOptions(table.options, debug, "getRightFlatHeaders"));
289
- table.getCenterLeafHeaders = memo(() => [table.getCenterFlatHeaders()], (flatHeaders) => {
290
- return flatHeaders.filter((header) => {
291
- var _header$subHeaders;
292
- return !((_header$subHeaders = header.subHeaders) != null && _header$subHeaders.length);
293
- });
294
- }, getMemoOptions(table.options, debug, "getCenterLeafHeaders"));
295
- table.getLeftLeafHeaders = memo(() => [table.getLeftFlatHeaders()], (flatHeaders) => {
296
- return flatHeaders.filter((header) => {
297
- var _header$subHeaders2;
298
- return !((_header$subHeaders2 = header.subHeaders) != null && _header$subHeaders2.length);
299
- });
300
- }, getMemoOptions(table.options, debug, "getLeftLeafHeaders"));
301
- table.getRightLeafHeaders = memo(() => [table.getRightFlatHeaders()], (flatHeaders) => {
302
- return flatHeaders.filter((header) => {
303
- var _header$subHeaders3;
304
- return !((_header$subHeaders3 = header.subHeaders) != null && _header$subHeaders3.length);
305
- });
306
- }, getMemoOptions(table.options, debug, "getRightLeafHeaders"));
307
- table.getLeafHeaders = memo(() => [table.getLeftHeaderGroups(), table.getCenterHeaderGroups(), table.getRightHeaderGroups()], (left, center, right) => {
308
- var _left$0$headers, _left$, _center$0$headers, _center$, _right$0$headers, _right$;
309
- 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) => {
310
- return header.getLeafHeaders();
311
- }).flat();
312
- }, getMemoOptions(table.options, debug, "getLeafHeaders"));
313
- }
314
- };
315
- function buildHeaderGroups(allColumns, columnsToGroup, table, headerFamily) {
316
- var _headerGroups$0$heade, _headerGroups$;
317
- let maxDepth = 0;
318
- const findMaxDepth = function(columns, depth) {
319
- if (depth === void 0) {
320
- depth = 1;
321
- }
322
- maxDepth = Math.max(maxDepth, depth);
323
- columns.filter((column) => column.getIsVisible()).forEach((column) => {
324
- var _column$columns;
325
- if ((_column$columns = column.columns) != null && _column$columns.length) {
326
- findMaxDepth(column.columns, depth + 1);
327
- }
328
- }, 0);
329
- };
330
- findMaxDepth(allColumns);
331
- let headerGroups = [];
332
- const createHeaderGroup = (headersToGroup, depth) => {
333
- const headerGroup = {
334
- depth,
335
- id: [headerFamily, `${depth}`].filter(Boolean).join("_"),
336
- headers: []
337
- };
338
- const pendingParentHeaders = [];
339
- headersToGroup.forEach((headerToGroup) => {
340
- const latestPendingParentHeader = [...pendingParentHeaders].reverse()[0];
341
- const isLeafHeader = headerToGroup.column.depth === headerGroup.depth;
342
- let column;
343
- let isPlaceholder = false;
344
- if (isLeafHeader && headerToGroup.column.parent) {
345
- column = headerToGroup.column.parent;
346
- } else {
347
- column = headerToGroup.column;
348
- isPlaceholder = true;
349
- }
350
- if (latestPendingParentHeader && (latestPendingParentHeader == null ? void 0 : latestPendingParentHeader.column) === column) {
351
- latestPendingParentHeader.subHeaders.push(headerToGroup);
352
- } else {
353
- const header = createHeader(table, column, {
354
- id: [headerFamily, depth, column.id, headerToGroup == null ? void 0 : headerToGroup.id].filter(Boolean).join("_"),
355
- isPlaceholder,
356
- placeholderId: isPlaceholder ? `${pendingParentHeaders.filter((d) => d.column === column).length}` : void 0,
357
- depth,
358
- index: pendingParentHeaders.length
359
- });
360
- header.subHeaders.push(headerToGroup);
361
- pendingParentHeaders.push(header);
362
- }
363
- headerGroup.headers.push(headerToGroup);
364
- headerToGroup.headerGroup = headerGroup;
365
- });
366
- headerGroups.push(headerGroup);
367
- if (depth > 0) {
368
- createHeaderGroup(pendingParentHeaders, depth - 1);
369
- }
370
- };
371
- const bottomHeaders = columnsToGroup.map((column, index) => createHeader(table, column, {
372
- depth: maxDepth,
373
- index
374
- }));
375
- createHeaderGroup(bottomHeaders, maxDepth - 1);
376
- headerGroups.reverse();
377
- const recurseHeadersForSpans = (headers) => {
378
- const filteredHeaders = headers.filter((header) => header.column.getIsVisible());
379
- return filteredHeaders.map((header) => {
380
- let colSpan = 0;
381
- let rowSpan = 0;
382
- let childRowSpans = [0];
383
- if (header.subHeaders && header.subHeaders.length) {
384
- childRowSpans = [];
385
- recurseHeadersForSpans(header.subHeaders).forEach((_ref) => {
386
- let {
387
- colSpan: childColSpan,
388
- rowSpan: childRowSpan
389
- } = _ref;
390
- colSpan += childColSpan;
391
- childRowSpans.push(childRowSpan);
392
- });
393
- } else {
394
- colSpan = 1;
395
- }
396
- const minChildRowSpan = Math.min(...childRowSpans);
397
- rowSpan = rowSpan + minChildRowSpan;
398
- header.colSpan = colSpan;
399
- header.rowSpan = rowSpan;
400
- return {
401
- colSpan,
402
- rowSpan
403
- };
404
- });
405
- };
406
- recurseHeadersForSpans((_headerGroups$0$heade = (_headerGroups$ = headerGroups[0]) == null ? void 0 : _headerGroups$.headers) != null ? _headerGroups$0$heade : []);
407
- return headerGroups;
408
- }
409
- var createRow = (table, id, original, rowIndex, depth, subRows, parentId) => {
410
- let row = {
411
- id,
412
- index: rowIndex,
413
- original,
414
- depth,
415
- parentId,
416
- _valuesCache: {},
417
- _uniqueValuesCache: {},
418
- getValue: (columnId) => {
419
- if (row._valuesCache.hasOwnProperty(columnId)) {
420
- return row._valuesCache[columnId];
421
- }
422
- const column = table.getColumn(columnId);
423
- if (!(column != null && column.accessorFn)) {
424
- return void 0;
425
- }
426
- row._valuesCache[columnId] = column.accessorFn(row.original, rowIndex);
427
- return row._valuesCache[columnId];
428
- },
429
- getUniqueValues: (columnId) => {
430
- if (row._uniqueValuesCache.hasOwnProperty(columnId)) {
431
- return row._uniqueValuesCache[columnId];
432
- }
433
- const column = table.getColumn(columnId);
434
- if (!(column != null && column.accessorFn)) {
435
- return void 0;
436
- }
437
- if (!column.columnDef.getUniqueValues) {
438
- row._uniqueValuesCache[columnId] = [row.getValue(columnId)];
439
- return row._uniqueValuesCache[columnId];
440
- }
441
- row._uniqueValuesCache[columnId] = column.columnDef.getUniqueValues(row.original, rowIndex);
442
- return row._uniqueValuesCache[columnId];
443
- },
444
- renderValue: (columnId) => {
445
- var _row$getValue;
446
- return (_row$getValue = row.getValue(columnId)) != null ? _row$getValue : table.options.renderFallbackValue;
447
- },
448
- subRows: [],
449
- getLeafRows: () => flattenBy(row.subRows, (d) => d.subRows),
450
- getParentRow: () => row.parentId ? table.getRow(row.parentId, true) : void 0,
451
- getParentRows: () => {
452
- let parentRows = [];
453
- let currentRow = row;
454
- while (true) {
455
- const parentRow = currentRow.getParentRow();
456
- if (!parentRow) break;
457
- parentRows.push(parentRow);
458
- currentRow = parentRow;
459
- }
460
- return parentRows.reverse();
461
- },
462
- getAllCells: memo(() => [table.getAllLeafColumns()], (leafColumns) => {
463
- return leafColumns.map((column) => {
464
- return createCell(table, row, column, column.id);
465
- });
466
- }, getMemoOptions(table.options, "debugRows", "getAllCells")),
467
- _getAllCellsByColumnId: memo(() => [row.getAllCells()], (allCells) => {
468
- return allCells.reduce((acc, cell) => {
469
- acc[cell.column.id] = cell;
470
- return acc;
471
- }, {});
472
- }, getMemoOptions(table.options, "debugRows", "getAllCellsByColumnId"))
473
- };
474
- for (let i = 0; i < table._features.length; i++) {
475
- const feature = table._features[i];
476
- feature == null || feature.createRow == null || feature.createRow(row, table);
477
- }
478
- return row;
479
- };
480
- var ColumnFaceting = {
481
- createColumn: (column, table) => {
482
- column._getFacetedRowModel = table.options.getFacetedRowModel && table.options.getFacetedRowModel(table, column.id);
483
- column.getFacetedRowModel = () => {
484
- if (!column._getFacetedRowModel) {
485
- return table.getPreFilteredRowModel();
486
- }
487
- return column._getFacetedRowModel();
488
- };
489
- column._getFacetedUniqueValues = table.options.getFacetedUniqueValues && table.options.getFacetedUniqueValues(table, column.id);
490
- column.getFacetedUniqueValues = () => {
491
- if (!column._getFacetedUniqueValues) {
492
- return /* @__PURE__ */ new Map();
493
- }
494
- return column._getFacetedUniqueValues();
495
- };
496
- column._getFacetedMinMaxValues = table.options.getFacetedMinMaxValues && table.options.getFacetedMinMaxValues(table, column.id);
497
- column.getFacetedMinMaxValues = () => {
498
- if (!column._getFacetedMinMaxValues) {
499
- return void 0;
500
- }
501
- return column._getFacetedMinMaxValues();
502
- };
503
- }
504
- };
505
- var includesString = (row, columnId, filterValue) => {
506
- var _filterValue$toString, _row$getValue;
507
- const search = filterValue == null || (_filterValue$toString = filterValue.toString()) == null ? void 0 : _filterValue$toString.toLowerCase();
508
- 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));
509
- };
510
- includesString.autoRemove = (val) => testFalsey(val);
511
- var includesStringSensitive = (row, columnId, filterValue) => {
512
- var _row$getValue2;
513
- return Boolean((_row$getValue2 = row.getValue(columnId)) == null || (_row$getValue2 = _row$getValue2.toString()) == null ? void 0 : _row$getValue2.includes(filterValue));
514
- };
515
- includesStringSensitive.autoRemove = (val) => testFalsey(val);
516
- var equalsString = (row, columnId, filterValue) => {
517
- var _row$getValue3;
518
- return ((_row$getValue3 = row.getValue(columnId)) == null || (_row$getValue3 = _row$getValue3.toString()) == null ? void 0 : _row$getValue3.toLowerCase()) === (filterValue == null ? void 0 : filterValue.toLowerCase());
519
- };
520
- equalsString.autoRemove = (val) => testFalsey(val);
521
- var arrIncludes = (row, columnId, filterValue) => {
522
- var _row$getValue4;
523
- return (_row$getValue4 = row.getValue(columnId)) == null ? void 0 : _row$getValue4.includes(filterValue);
524
- };
525
- arrIncludes.autoRemove = (val) => testFalsey(val);
526
- var arrIncludesAll = (row, columnId, filterValue) => {
527
- return !filterValue.some((val) => {
528
- var _row$getValue5;
529
- return !((_row$getValue5 = row.getValue(columnId)) != null && _row$getValue5.includes(val));
530
- });
531
- };
532
- arrIncludesAll.autoRemove = (val) => testFalsey(val) || !(val != null && val.length);
533
- var arrIncludesSome = (row, columnId, filterValue) => {
534
- return filterValue.some((val) => {
535
- var _row$getValue6;
536
- return (_row$getValue6 = row.getValue(columnId)) == null ? void 0 : _row$getValue6.includes(val);
537
- });
538
- };
539
- arrIncludesSome.autoRemove = (val) => testFalsey(val) || !(val != null && val.length);
540
- var equals = (row, columnId, filterValue) => {
541
- return row.getValue(columnId) === filterValue;
542
- };
543
- equals.autoRemove = (val) => testFalsey(val);
544
- var weakEquals = (row, columnId, filterValue) => {
545
- return row.getValue(columnId) == filterValue;
546
- };
547
- weakEquals.autoRemove = (val) => testFalsey(val);
548
- var inNumberRange = (row, columnId, filterValue) => {
549
- let [min2, max2] = filterValue;
550
- const rowValue = row.getValue(columnId);
551
- return rowValue >= min2 && rowValue <= max2;
552
- };
553
- inNumberRange.resolveFilterValue = (val) => {
554
- let [unsafeMin, unsafeMax] = val;
555
- let parsedMin = typeof unsafeMin !== "number" ? parseFloat(unsafeMin) : unsafeMin;
556
- let parsedMax = typeof unsafeMax !== "number" ? parseFloat(unsafeMax) : unsafeMax;
557
- let min2 = unsafeMin === null || Number.isNaN(parsedMin) ? -Infinity : parsedMin;
558
- let max2 = unsafeMax === null || Number.isNaN(parsedMax) ? Infinity : parsedMax;
559
- if (min2 > max2) {
560
- const temp = min2;
561
- min2 = max2;
562
- max2 = temp;
563
- }
564
- return [min2, max2];
565
- };
566
- inNumberRange.autoRemove = (val) => testFalsey(val) || testFalsey(val[0]) && testFalsey(val[1]);
567
- var filterFns = {
568
- includesString,
569
- includesStringSensitive,
570
- equalsString,
571
- arrIncludes,
572
- arrIncludesAll,
573
- arrIncludesSome,
574
- equals,
575
- weakEquals,
576
- inNumberRange
577
- };
578
- function testFalsey(val) {
579
- return val === void 0 || val === null || val === "";
580
- }
581
- var ColumnFiltering = {
582
- getDefaultColumnDef: () => {
583
- return {
584
- filterFn: "auto"
585
- };
586
- },
587
- getInitialState: (state) => {
588
- return {
589
- columnFilters: [],
590
- ...state
591
- };
592
- },
593
- getDefaultOptions: (table) => {
594
- return {
595
- onColumnFiltersChange: makeStateUpdater("columnFilters", table),
596
- filterFromLeafRows: false,
597
- maxLeafRowFilterDepth: 100
598
- };
599
- },
600
- createColumn: (column, table) => {
601
- column.getAutoFilterFn = () => {
602
- const firstRow = table.getCoreRowModel().flatRows[0];
603
- const value = firstRow == null ? void 0 : firstRow.getValue(column.id);
604
- if (typeof value === "string") {
605
- return filterFns.includesString;
606
- }
607
- if (typeof value === "number") {
608
- return filterFns.inNumberRange;
609
- }
610
- if (typeof value === "boolean") {
611
- return filterFns.equals;
612
- }
613
- if (value !== null && typeof value === "object") {
614
- return filterFns.equals;
615
- }
616
- if (Array.isArray(value)) {
617
- return filterFns.arrIncludes;
618
- }
619
- return filterFns.weakEquals;
620
- };
621
- column.getFilterFn = () => {
622
- var _table$options$filter, _table$options$filter2;
623
- return isFunction(column.columnDef.filterFn) ? column.columnDef.filterFn : column.columnDef.filterFn === "auto" ? column.getAutoFilterFn() : (
624
- // @ts-ignore
625
- (_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]
626
- );
627
- };
628
- column.getCanFilter = () => {
629
- var _column$columnDef$ena, _table$options$enable, _table$options$enable2;
630
- 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;
631
- };
632
- column.getIsFiltered = () => column.getFilterIndex() > -1;
633
- column.getFilterValue = () => {
634
- var _table$getState$colum;
635
- 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;
636
- };
637
- column.getFilterIndex = () => {
638
- var _table$getState$colum2, _table$getState$colum3;
639
- 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;
640
- };
641
- column.setFilterValue = (value) => {
642
- table.setColumnFilters((old) => {
643
- const filterFn = column.getFilterFn();
644
- const previousFilter = old == null ? void 0 : old.find((d) => d.id === column.id);
645
- const newFilter = functionalUpdate(value, previousFilter ? previousFilter.value : void 0);
646
- if (shouldAutoRemoveFilter(filterFn, newFilter, column)) {
647
- var _old$filter;
648
- return (_old$filter = old == null ? void 0 : old.filter((d) => d.id !== column.id)) != null ? _old$filter : [];
649
- }
650
- const newFilterObj = {
651
- id: column.id,
652
- value: newFilter
653
- };
654
- if (previousFilter) {
655
- var _old$map;
656
- return (_old$map = old == null ? void 0 : old.map((d) => {
657
- if (d.id === column.id) {
658
- return newFilterObj;
659
- }
660
- return d;
661
- })) != null ? _old$map : [];
662
- }
663
- if (old != null && old.length) {
664
- return [...old, newFilterObj];
665
- }
666
- return [newFilterObj];
667
- });
668
- };
669
- },
670
- createRow: (row, _table) => {
671
- row.columnFilters = {};
672
- row.columnFiltersMeta = {};
673
- },
674
- createTable: (table) => {
675
- table.setColumnFilters = (updater) => {
676
- const leafColumns = table.getAllLeafColumns();
677
- const updateFn = (old) => {
678
- var _functionalUpdate;
679
- return (_functionalUpdate = functionalUpdate(updater, old)) == null ? void 0 : _functionalUpdate.filter((filter) => {
680
- const column = leafColumns.find((d) => d.id === filter.id);
681
- if (column) {
682
- const filterFn = column.getFilterFn();
683
- if (shouldAutoRemoveFilter(filterFn, filter.value, column)) {
684
- return false;
685
- }
686
- }
687
- return true;
688
- });
689
- };
690
- table.options.onColumnFiltersChange == null || table.options.onColumnFiltersChange(updateFn);
691
- };
692
- table.resetColumnFilters = (defaultState) => {
693
- var _table$initialState$c, _table$initialState;
694
- table.setColumnFilters(defaultState ? [] : (_table$initialState$c = (_table$initialState = table.initialState) == null ? void 0 : _table$initialState.columnFilters) != null ? _table$initialState$c : []);
695
- };
696
- table.getPreFilteredRowModel = () => table.getCoreRowModel();
697
- table.getFilteredRowModel = () => {
698
- if (!table._getFilteredRowModel && table.options.getFilteredRowModel) {
699
- table._getFilteredRowModel = table.options.getFilteredRowModel(table);
700
- }
701
- if (table.options.manualFiltering || !table._getFilteredRowModel) {
702
- return table.getPreFilteredRowModel();
703
- }
704
- return table._getFilteredRowModel();
705
- };
706
- }
707
- };
708
- function shouldAutoRemoveFilter(filterFn, value, column) {
709
- return (filterFn && filterFn.autoRemove ? filterFn.autoRemove(value, column) : false) || typeof value === "undefined" || typeof value === "string" && !value;
710
- }
711
- var sum = (columnId, _leafRows, childRows) => {
712
- return childRows.reduce((sum2, next) => {
713
- const nextValue = next.getValue(columnId);
714
- return sum2 + (typeof nextValue === "number" ? nextValue : 0);
715
- }, 0);
716
- };
717
- var min = (columnId, _leafRows, childRows) => {
718
- let min2;
719
- childRows.forEach((row) => {
720
- const value = row.getValue(columnId);
721
- if (value != null && (min2 > value || min2 === void 0 && value >= value)) {
722
- min2 = value;
723
- }
724
- });
725
- return min2;
726
- };
727
- var max = (columnId, _leafRows, childRows) => {
728
- let max2;
729
- childRows.forEach((row) => {
730
- const value = row.getValue(columnId);
731
- if (value != null && (max2 < value || max2 === void 0 && value >= value)) {
732
- max2 = value;
733
- }
734
- });
735
- return max2;
736
- };
737
- var extent = (columnId, _leafRows, childRows) => {
738
- let min2;
739
- let max2;
740
- childRows.forEach((row) => {
741
- const value = row.getValue(columnId);
742
- if (value != null) {
743
- if (min2 === void 0) {
744
- if (value >= value) min2 = max2 = value;
745
- } else {
746
- if (min2 > value) min2 = value;
747
- if (max2 < value) max2 = value;
748
- }
749
- }
750
- });
751
- return [min2, max2];
752
- };
753
- var mean = (columnId, leafRows) => {
754
- let count2 = 0;
755
- let sum2 = 0;
756
- leafRows.forEach((row) => {
757
- let value = row.getValue(columnId);
758
- if (value != null && (value = +value) >= value) {
759
- ++count2, sum2 += value;
760
- }
761
- });
762
- if (count2) return sum2 / count2;
763
- return;
764
- };
765
- var median = (columnId, leafRows) => {
766
- if (!leafRows.length) {
767
- return;
768
- }
769
- const values = leafRows.map((row) => row.getValue(columnId));
770
- if (!isNumberArray(values)) {
771
- return;
772
- }
773
- if (values.length === 1) {
774
- return values[0];
775
- }
776
- const mid = Math.floor(values.length / 2);
777
- const nums = values.sort((a, b) => a - b);
778
- return values.length % 2 !== 0 ? nums[mid] : (nums[mid - 1] + nums[mid]) / 2;
779
- };
780
- var unique = (columnId, leafRows) => {
781
- return Array.from(new Set(leafRows.map((d) => d.getValue(columnId))).values());
782
- };
783
- var uniqueCount = (columnId, leafRows) => {
784
- return new Set(leafRows.map((d) => d.getValue(columnId))).size;
785
- };
786
- var count = (_columnId, leafRows) => {
787
- return leafRows.length;
788
- };
789
- var aggregationFns = {
790
- sum,
791
- min,
792
- max,
793
- extent,
794
- mean,
795
- median,
796
- unique,
797
- uniqueCount,
798
- count
799
- };
800
- var ColumnGrouping = {
801
- getDefaultColumnDef: () => {
802
- return {
803
- aggregatedCell: (props) => {
804
- var _toString, _props$getValue;
805
- return (_toString = (_props$getValue = props.getValue()) == null || _props$getValue.toString == null ? void 0 : _props$getValue.toString()) != null ? _toString : null;
806
- },
807
- aggregationFn: "auto"
808
- };
809
- },
810
- getInitialState: (state) => {
811
- return {
812
- grouping: [],
813
- ...state
814
- };
815
- },
816
- getDefaultOptions: (table) => {
817
- return {
818
- onGroupingChange: makeStateUpdater("grouping", table),
819
- groupedColumnMode: "reorder"
820
- };
821
- },
822
- createColumn: (column, table) => {
823
- column.toggleGrouping = () => {
824
- table.setGrouping((old) => {
825
- if (old != null && old.includes(column.id)) {
826
- return old.filter((d) => d !== column.id);
827
- }
828
- return [...old != null ? old : [], column.id];
829
- });
830
- };
831
- column.getCanGroup = () => {
832
- var _column$columnDef$ena, _table$options$enable;
833
- 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);
834
- };
835
- column.getIsGrouped = () => {
836
- var _table$getState$group;
837
- return (_table$getState$group = table.getState().grouping) == null ? void 0 : _table$getState$group.includes(column.id);
838
- };
839
- column.getGroupedIndex = () => {
840
- var _table$getState$group2;
841
- return (_table$getState$group2 = table.getState().grouping) == null ? void 0 : _table$getState$group2.indexOf(column.id);
842
- };
843
- column.getToggleGroupingHandler = () => {
844
- const canGroup = column.getCanGroup();
845
- return () => {
846
- if (!canGroup) return;
847
- column.toggleGrouping();
848
- };
849
- };
850
- column.getAutoAggregationFn = () => {
851
- const firstRow = table.getCoreRowModel().flatRows[0];
852
- const value = firstRow == null ? void 0 : firstRow.getValue(column.id);
853
- if (typeof value === "number") {
854
- return aggregationFns.sum;
855
- }
856
- if (Object.prototype.toString.call(value) === "[object Date]") {
857
- return aggregationFns.extent;
858
- }
859
- };
860
- column.getAggregationFn = () => {
861
- var _table$options$aggreg, _table$options$aggreg2;
862
- if (!column) {
863
- throw new Error();
864
- }
865
- 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];
866
- };
867
- },
868
- createTable: (table) => {
869
- table.setGrouping = (updater) => table.options.onGroupingChange == null ? void 0 : table.options.onGroupingChange(updater);
870
- table.resetGrouping = (defaultState) => {
871
- var _table$initialState$g, _table$initialState;
872
- table.setGrouping(defaultState ? [] : (_table$initialState$g = (_table$initialState = table.initialState) == null ? void 0 : _table$initialState.grouping) != null ? _table$initialState$g : []);
873
- };
874
- table.getPreGroupedRowModel = () => table.getFilteredRowModel();
875
- table.getGroupedRowModel = () => {
876
- if (!table._getGroupedRowModel && table.options.getGroupedRowModel) {
877
- table._getGroupedRowModel = table.options.getGroupedRowModel(table);
878
- }
879
- if (table.options.manualGrouping || !table._getGroupedRowModel) {
880
- return table.getPreGroupedRowModel();
881
- }
882
- return table._getGroupedRowModel();
883
- };
884
- },
885
- createRow: (row, table) => {
886
- row.getIsGrouped = () => !!row.groupingColumnId;
887
- row.getGroupingValue = (columnId) => {
888
- if (row._groupingValuesCache.hasOwnProperty(columnId)) {
889
- return row._groupingValuesCache[columnId];
890
- }
891
- const column = table.getColumn(columnId);
892
- if (!(column != null && column.columnDef.getGroupingValue)) {
893
- return row.getValue(columnId);
894
- }
895
- row._groupingValuesCache[columnId] = column.columnDef.getGroupingValue(row.original);
896
- return row._groupingValuesCache[columnId];
897
- };
898
- row._groupingValuesCache = {};
899
- },
900
- createCell: (cell, column, row, table) => {
901
- cell.getIsGrouped = () => column.getIsGrouped() && column.id === row.groupingColumnId;
902
- cell.getIsPlaceholder = () => !cell.getIsGrouped() && column.getIsGrouped();
903
- cell.getIsAggregated = () => {
904
- var _row$subRows;
905
- return !cell.getIsGrouped() && !cell.getIsPlaceholder() && !!((_row$subRows = row.subRows) != null && _row$subRows.length);
906
- };
907
- }
908
- };
909
- function orderColumns(leafColumns, grouping, groupedColumnMode) {
910
- if (!(grouping != null && grouping.length) || !groupedColumnMode) {
911
- return leafColumns;
912
- }
913
- const nonGroupingColumns = leafColumns.filter((col) => !grouping.includes(col.id));
914
- if (groupedColumnMode === "remove") {
915
- return nonGroupingColumns;
916
- }
917
- const groupingColumns = grouping.map((g) => leafColumns.find((col) => col.id === g)).filter(Boolean);
918
- return [...groupingColumns, ...nonGroupingColumns];
919
- }
920
- var ColumnOrdering = {
921
- getInitialState: (state) => {
922
- return {
923
- columnOrder: [],
924
- ...state
925
- };
926
- },
927
- getDefaultOptions: (table) => {
928
- return {
929
- onColumnOrderChange: makeStateUpdater("columnOrder", table)
930
- };
931
- },
932
- createColumn: (column, table) => {
933
- column.getIndex = memo((position) => [_getVisibleLeafColumns(table, position)], (columns) => columns.findIndex((d) => d.id === column.id), getMemoOptions(table.options, "debugColumns", "getIndex"));
934
- column.getIsFirstColumn = (position) => {
935
- var _columns$;
936
- const columns = _getVisibleLeafColumns(table, position);
937
- return ((_columns$ = columns[0]) == null ? void 0 : _columns$.id) === column.id;
938
- };
939
- column.getIsLastColumn = (position) => {
940
- var _columns;
941
- const columns = _getVisibleLeafColumns(table, position);
942
- return ((_columns = columns[columns.length - 1]) == null ? void 0 : _columns.id) === column.id;
943
- };
944
- },
945
- createTable: (table) => {
946
- table.setColumnOrder = (updater) => table.options.onColumnOrderChange == null ? void 0 : table.options.onColumnOrderChange(updater);
947
- table.resetColumnOrder = (defaultState) => {
948
- var _table$initialState$c;
949
- table.setColumnOrder(defaultState ? [] : (_table$initialState$c = table.initialState.columnOrder) != null ? _table$initialState$c : []);
950
- };
951
- table._getOrderColumnsFn = memo(() => [table.getState().columnOrder, table.getState().grouping, table.options.groupedColumnMode], (columnOrder, grouping, groupedColumnMode) => (columns) => {
952
- let orderedColumns = [];
953
- if (!(columnOrder != null && columnOrder.length)) {
954
- orderedColumns = columns;
955
- } else {
956
- const columnOrderCopy = [...columnOrder];
957
- const columnsCopy = [...columns];
958
- while (columnsCopy.length && columnOrderCopy.length) {
959
- const targetColumnId = columnOrderCopy.shift();
960
- const foundIndex = columnsCopy.findIndex((d) => d.id === targetColumnId);
961
- if (foundIndex > -1) {
962
- orderedColumns.push(columnsCopy.splice(foundIndex, 1)[0]);
963
- }
964
- }
965
- orderedColumns = [...orderedColumns, ...columnsCopy];
966
- }
967
- return orderColumns(orderedColumns, grouping, groupedColumnMode);
968
- }, getMemoOptions(table.options, "debugTable", "_getOrderColumnsFn"));
969
- }
970
- };
971
- var getDefaultColumnPinningState = () => ({
972
- left: [],
973
- right: []
974
- });
975
- var ColumnPinning = {
976
- getInitialState: (state) => {
977
- return {
978
- columnPinning: getDefaultColumnPinningState(),
979
- ...state
980
- };
981
- },
982
- getDefaultOptions: (table) => {
983
- return {
984
- onColumnPinningChange: makeStateUpdater("columnPinning", table)
985
- };
986
- },
987
- createColumn: (column, table) => {
988
- column.pin = (position) => {
989
- const columnIds = column.getLeafColumns().map((d) => d.id).filter(Boolean);
990
- table.setColumnPinning((old) => {
991
- var _old$left3, _old$right3;
992
- if (position === "right") {
993
- var _old$left, _old$right;
994
- return {
995
- left: ((_old$left = old == null ? void 0 : old.left) != null ? _old$left : []).filter((d) => !(columnIds != null && columnIds.includes(d))),
996
- right: [...((_old$right = old == null ? void 0 : old.right) != null ? _old$right : []).filter((d) => !(columnIds != null && columnIds.includes(d))), ...columnIds]
997
- };
998
- }
999
- if (position === "left") {
1000
- var _old$left2, _old$right2;
1001
- return {
1002
- left: [...((_old$left2 = old == null ? void 0 : old.left) != null ? _old$left2 : []).filter((d) => !(columnIds != null && columnIds.includes(d))), ...columnIds],
1003
- right: ((_old$right2 = old == null ? void 0 : old.right) != null ? _old$right2 : []).filter((d) => !(columnIds != null && columnIds.includes(d)))
1004
- };
1005
- }
1006
- return {
1007
- left: ((_old$left3 = old == null ? void 0 : old.left) != null ? _old$left3 : []).filter((d) => !(columnIds != null && columnIds.includes(d))),
1008
- right: ((_old$right3 = old == null ? void 0 : old.right) != null ? _old$right3 : []).filter((d) => !(columnIds != null && columnIds.includes(d)))
1009
- };
1010
- });
1011
- };
1012
- column.getCanPin = () => {
1013
- const leafColumns = column.getLeafColumns();
1014
- return leafColumns.some((d) => {
1015
- var _d$columnDef$enablePi, _ref, _table$options$enable;
1016
- 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);
1017
- });
1018
- };
1019
- column.getIsPinned = () => {
1020
- const leafColumnIds = column.getLeafColumns().map((d) => d.id);
1021
- const {
1022
- left,
1023
- right
1024
- } = table.getState().columnPinning;
1025
- const isLeft = leafColumnIds.some((d) => left == null ? void 0 : left.includes(d));
1026
- const isRight = leafColumnIds.some((d) => right == null ? void 0 : right.includes(d));
1027
- return isLeft ? "left" : isRight ? "right" : false;
1028
- };
1029
- column.getPinnedIndex = () => {
1030
- var _table$getState$colum, _table$getState$colum2;
1031
- const position = column.getIsPinned();
1032
- 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;
1033
- };
1034
- },
1035
- createRow: (row, table) => {
1036
- row.getCenterVisibleCells = memo(() => [row._getAllVisibleCells(), table.getState().columnPinning.left, table.getState().columnPinning.right], (allCells, left, right) => {
1037
- const leftAndRight = [...left != null ? left : [], ...right != null ? right : []];
1038
- return allCells.filter((d) => !leftAndRight.includes(d.column.id));
1039
- }, getMemoOptions(table.options, "debugRows", "getCenterVisibleCells"));
1040
- row.getLeftVisibleCells = memo(() => [row._getAllVisibleCells(), table.getState().columnPinning.left], (allCells, left) => {
1041
- const cells = (left != null ? left : []).map((columnId) => allCells.find((cell) => cell.column.id === columnId)).filter(Boolean).map((d) => ({
1042
- ...d,
1043
- position: "left"
1044
- }));
1045
- return cells;
1046
- }, getMemoOptions(table.options, "debugRows", "getLeftVisibleCells"));
1047
- row.getRightVisibleCells = memo(() => [row._getAllVisibleCells(), table.getState().columnPinning.right], (allCells, right) => {
1048
- const cells = (right != null ? right : []).map((columnId) => allCells.find((cell) => cell.column.id === columnId)).filter(Boolean).map((d) => ({
1049
- ...d,
1050
- position: "right"
1051
- }));
1052
- return cells;
1053
- }, getMemoOptions(table.options, "debugRows", "getRightVisibleCells"));
1054
- },
1055
- createTable: (table) => {
1056
- table.setColumnPinning = (updater) => table.options.onColumnPinningChange == null ? void 0 : table.options.onColumnPinningChange(updater);
1057
- table.resetColumnPinning = (defaultState) => {
1058
- var _table$initialState$c, _table$initialState;
1059
- return table.setColumnPinning(defaultState ? getDefaultColumnPinningState() : (_table$initialState$c = (_table$initialState = table.initialState) == null ? void 0 : _table$initialState.columnPinning) != null ? _table$initialState$c : getDefaultColumnPinningState());
1060
- };
1061
- table.getIsSomeColumnsPinned = (position) => {
1062
- var _pinningState$positio;
1063
- const pinningState = table.getState().columnPinning;
1064
- if (!position) {
1065
- var _pinningState$left, _pinningState$right;
1066
- return Boolean(((_pinningState$left = pinningState.left) == null ? void 0 : _pinningState$left.length) || ((_pinningState$right = pinningState.right) == null ? void 0 : _pinningState$right.length));
1067
- }
1068
- return Boolean((_pinningState$positio = pinningState[position]) == null ? void 0 : _pinningState$positio.length);
1069
- };
1070
- table.getLeftLeafColumns = memo(() => [table.getAllLeafColumns(), table.getState().columnPinning.left], (allColumns, left) => {
1071
- return (left != null ? left : []).map((columnId) => allColumns.find((column) => column.id === columnId)).filter(Boolean);
1072
- }, getMemoOptions(table.options, "debugColumns", "getLeftLeafColumns"));
1073
- table.getRightLeafColumns = memo(() => [table.getAllLeafColumns(), table.getState().columnPinning.right], (allColumns, right) => {
1074
- return (right != null ? right : []).map((columnId) => allColumns.find((column) => column.id === columnId)).filter(Boolean);
1075
- }, getMemoOptions(table.options, "debugColumns", "getRightLeafColumns"));
1076
- table.getCenterLeafColumns = memo(() => [table.getAllLeafColumns(), table.getState().columnPinning.left, table.getState().columnPinning.right], (allColumns, left, right) => {
1077
- const leftAndRight = [...left != null ? left : [], ...right != null ? right : []];
1078
- return allColumns.filter((d) => !leftAndRight.includes(d.id));
1079
- }, getMemoOptions(table.options, "debugColumns", "getCenterLeafColumns"));
1080
- }
1081
- };
1082
- function safelyAccessDocument(_document) {
1083
- return _document || (typeof document !== "undefined" ? document : null);
1084
- }
1085
- var defaultColumnSizing = {
1086
- size: 150,
1087
- minSize: 20,
1088
- maxSize: Number.MAX_SAFE_INTEGER
1089
- };
1090
- var getDefaultColumnSizingInfoState = () => ({
1091
- startOffset: null,
1092
- startSize: null,
1093
- deltaOffset: null,
1094
- deltaPercentage: null,
1095
- isResizingColumn: false,
1096
- columnSizingStart: []
1097
- });
1098
- var ColumnSizing = {
1099
- getDefaultColumnDef: () => {
1100
- return defaultColumnSizing;
1101
- },
1102
- getInitialState: (state) => {
1103
- return {
1104
- columnSizing: {},
1105
- columnSizingInfo: getDefaultColumnSizingInfoState(),
1106
- ...state
1107
- };
1108
- },
1109
- getDefaultOptions: (table) => {
1110
- return {
1111
- columnResizeMode: "onEnd",
1112
- columnResizeDirection: "ltr",
1113
- onColumnSizingChange: makeStateUpdater("columnSizing", table),
1114
- onColumnSizingInfoChange: makeStateUpdater("columnSizingInfo", table)
1115
- };
1116
- },
1117
- createColumn: (column, table) => {
1118
- column.getSize = () => {
1119
- var _column$columnDef$min, _ref, _column$columnDef$max;
1120
- const columnSize = table.getState().columnSizing[column.id];
1121
- 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);
1122
- };
1123
- 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"));
1124
- 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"));
1125
- column.resetSize = () => {
1126
- table.setColumnSizing((_ref2) => {
1127
- let {
1128
- [column.id]: _,
1129
- ...rest
1130
- } = _ref2;
1131
- return rest;
1132
- });
1133
- };
1134
- column.getCanResize = () => {
1135
- var _column$columnDef$ena, _table$options$enable;
1136
- return ((_column$columnDef$ena = column.columnDef.enableResizing) != null ? _column$columnDef$ena : true) && ((_table$options$enable = table.options.enableColumnResizing) != null ? _table$options$enable : true);
1137
- };
1138
- column.getIsResizing = () => {
1139
- return table.getState().columnSizingInfo.isResizingColumn === column.id;
1140
- };
1141
- },
1142
- createHeader: (header, table) => {
1143
- header.getSize = () => {
1144
- let sum2 = 0;
1145
- const recurse = (header2) => {
1146
- if (header2.subHeaders.length) {
1147
- header2.subHeaders.forEach(recurse);
1148
- } else {
1149
- var _header$column$getSiz;
1150
- sum2 += (_header$column$getSiz = header2.column.getSize()) != null ? _header$column$getSiz : 0;
1151
- }
1152
- };
1153
- recurse(header);
1154
- return sum2;
1155
- };
1156
- header.getStart = () => {
1157
- if (header.index > 0) {
1158
- const prevSiblingHeader = header.headerGroup.headers[header.index - 1];
1159
- return prevSiblingHeader.getStart() + prevSiblingHeader.getSize();
1160
- }
1161
- return 0;
1162
- };
1163
- header.getResizeHandler = (_contextDocument) => {
1164
- const column = table.getColumn(header.column.id);
1165
- const canResize = column == null ? void 0 : column.getCanResize();
1166
- return (e) => {
1167
- if (!column || !canResize) {
1168
- return;
1169
- }
1170
- e.persist == null || e.persist();
1171
- if (isTouchStartEvent(e)) {
1172
- if (e.touches && e.touches.length > 1) {
1173
- return;
1174
- }
1175
- }
1176
- const startSize = header.getSize();
1177
- const columnSizingStart = header ? header.getLeafHeaders().map((d) => [d.column.id, d.column.getSize()]) : [[column.id, column.getSize()]];
1178
- const clientX = isTouchStartEvent(e) ? Math.round(e.touches[0].clientX) : e.clientX;
1179
- const newColumnSizing = {};
1180
- const updateOffset = (eventType, clientXPos) => {
1181
- if (typeof clientXPos !== "number") {
1182
- return;
1183
- }
1184
- table.setColumnSizingInfo((old) => {
1185
- var _old$startOffset, _old$startSize;
1186
- const deltaDirection = table.options.columnResizeDirection === "rtl" ? -1 : 1;
1187
- const deltaOffset = (clientXPos - ((_old$startOffset = old == null ? void 0 : old.startOffset) != null ? _old$startOffset : 0)) * deltaDirection;
1188
- const deltaPercentage = Math.max(deltaOffset / ((_old$startSize = old == null ? void 0 : old.startSize) != null ? _old$startSize : 0), -0.999999);
1189
- old.columnSizingStart.forEach((_ref3) => {
1190
- let [columnId, headerSize] = _ref3;
1191
- newColumnSizing[columnId] = Math.round(Math.max(headerSize + headerSize * deltaPercentage, 0) * 100) / 100;
1192
- });
1193
- return {
1194
- ...old,
1195
- deltaOffset,
1196
- deltaPercentage
1197
- };
1198
- });
1199
- if (table.options.columnResizeMode === "onChange" || eventType === "end") {
1200
- table.setColumnSizing((old) => ({
1201
- ...old,
1202
- ...newColumnSizing
1203
- }));
1204
- }
1205
- };
1206
- const onMove = (clientXPos) => updateOffset("move", clientXPos);
1207
- const onEnd = (clientXPos) => {
1208
- updateOffset("end", clientXPos);
1209
- table.setColumnSizingInfo((old) => ({
1210
- ...old,
1211
- isResizingColumn: false,
1212
- startOffset: null,
1213
- startSize: null,
1214
- deltaOffset: null,
1215
- deltaPercentage: null,
1216
- columnSizingStart: []
1217
- }));
1218
- };
1219
- const contextDocument = safelyAccessDocument(_contextDocument);
1220
- const mouseEvents = {
1221
- moveHandler: (e2) => onMove(e2.clientX),
1222
- upHandler: (e2) => {
1223
- contextDocument == null || contextDocument.removeEventListener("mousemove", mouseEvents.moveHandler);
1224
- contextDocument == null || contextDocument.removeEventListener("mouseup", mouseEvents.upHandler);
1225
- onEnd(e2.clientX);
1226
- }
1227
- };
1228
- const touchEvents = {
1229
- moveHandler: (e2) => {
1230
- if (e2.cancelable) {
1231
- e2.preventDefault();
1232
- e2.stopPropagation();
1233
- }
1234
- onMove(e2.touches[0].clientX);
1235
- return false;
1236
- },
1237
- upHandler: (e2) => {
1238
- var _e$touches$;
1239
- contextDocument == null || contextDocument.removeEventListener("touchmove", touchEvents.moveHandler);
1240
- contextDocument == null || contextDocument.removeEventListener("touchend", touchEvents.upHandler);
1241
- if (e2.cancelable) {
1242
- e2.preventDefault();
1243
- e2.stopPropagation();
1244
- }
1245
- onEnd((_e$touches$ = e2.touches[0]) == null ? void 0 : _e$touches$.clientX);
1246
- }
1247
- };
1248
- const passiveIfSupported = passiveEventSupported() ? {
1249
- passive: false
1250
- } : false;
1251
- if (isTouchStartEvent(e)) {
1252
- contextDocument == null || contextDocument.addEventListener("touchmove", touchEvents.moveHandler, passiveIfSupported);
1253
- contextDocument == null || contextDocument.addEventListener("touchend", touchEvents.upHandler, passiveIfSupported);
1254
- } else {
1255
- contextDocument == null || contextDocument.addEventListener("mousemove", mouseEvents.moveHandler, passiveIfSupported);
1256
- contextDocument == null || contextDocument.addEventListener("mouseup", mouseEvents.upHandler, passiveIfSupported);
1257
- }
1258
- table.setColumnSizingInfo((old) => ({
1259
- ...old,
1260
- startOffset: clientX,
1261
- startSize,
1262
- deltaOffset: 0,
1263
- deltaPercentage: 0,
1264
- columnSizingStart,
1265
- isResizingColumn: column.id
1266
- }));
1267
- };
1268
- };
1269
- },
1270
- createTable: (table) => {
1271
- table.setColumnSizing = (updater) => table.options.onColumnSizingChange == null ? void 0 : table.options.onColumnSizingChange(updater);
1272
- table.setColumnSizingInfo = (updater) => table.options.onColumnSizingInfoChange == null ? void 0 : table.options.onColumnSizingInfoChange(updater);
1273
- table.resetColumnSizing = (defaultState) => {
1274
- var _table$initialState$c;
1275
- table.setColumnSizing(defaultState ? {} : (_table$initialState$c = table.initialState.columnSizing) != null ? _table$initialState$c : {});
1276
- };
1277
- table.resetHeaderSizeInfo = (defaultState) => {
1278
- var _table$initialState$c2;
1279
- table.setColumnSizingInfo(defaultState ? getDefaultColumnSizingInfoState() : (_table$initialState$c2 = table.initialState.columnSizingInfo) != null ? _table$initialState$c2 : getDefaultColumnSizingInfoState());
1280
- };
1281
- table.getTotalSize = () => {
1282
- var _table$getHeaderGroup, _table$getHeaderGroup2;
1283
- return (_table$getHeaderGroup = (_table$getHeaderGroup2 = table.getHeaderGroups()[0]) == null ? void 0 : _table$getHeaderGroup2.headers.reduce((sum2, header) => {
1284
- return sum2 + header.getSize();
1285
- }, 0)) != null ? _table$getHeaderGroup : 0;
1286
- };
1287
- table.getLeftTotalSize = () => {
1288
- var _table$getLeftHeaderG, _table$getLeftHeaderG2;
1289
- return (_table$getLeftHeaderG = (_table$getLeftHeaderG2 = table.getLeftHeaderGroups()[0]) == null ? void 0 : _table$getLeftHeaderG2.headers.reduce((sum2, header) => {
1290
- return sum2 + header.getSize();
1291
- }, 0)) != null ? _table$getLeftHeaderG : 0;
1292
- };
1293
- table.getCenterTotalSize = () => {
1294
- var _table$getCenterHeade, _table$getCenterHeade2;
1295
- return (_table$getCenterHeade = (_table$getCenterHeade2 = table.getCenterHeaderGroups()[0]) == null ? void 0 : _table$getCenterHeade2.headers.reduce((sum2, header) => {
1296
- return sum2 + header.getSize();
1297
- }, 0)) != null ? _table$getCenterHeade : 0;
1298
- };
1299
- table.getRightTotalSize = () => {
1300
- var _table$getRightHeader, _table$getRightHeader2;
1301
- return (_table$getRightHeader = (_table$getRightHeader2 = table.getRightHeaderGroups()[0]) == null ? void 0 : _table$getRightHeader2.headers.reduce((sum2, header) => {
1302
- return sum2 + header.getSize();
1303
- }, 0)) != null ? _table$getRightHeader : 0;
1304
- };
1305
- }
1306
- };
1307
- var passiveSupported = null;
1308
- function passiveEventSupported() {
1309
- if (typeof passiveSupported === "boolean") return passiveSupported;
1310
- let supported = false;
1311
- try {
1312
- const options = {
1313
- get passive() {
1314
- supported = true;
1315
- return false;
1316
- }
1317
- };
1318
- const noop = () => {
1319
- };
1320
- window.addEventListener("test", noop, options);
1321
- window.removeEventListener("test", noop);
1322
- } catch (err) {
1323
- supported = false;
1324
- }
1325
- passiveSupported = supported;
1326
- return passiveSupported;
1327
- }
1328
- function isTouchStartEvent(e) {
1329
- return e.type === "touchstart";
1330
- }
1331
- var ColumnVisibility = {
1332
- getInitialState: (state) => {
1333
- return {
1334
- columnVisibility: {},
1335
- ...state
1336
- };
1337
- },
1338
- getDefaultOptions: (table) => {
1339
- return {
1340
- onColumnVisibilityChange: makeStateUpdater("columnVisibility", table)
1341
- };
1342
- },
1343
- createColumn: (column, table) => {
1344
- column.toggleVisibility = (value) => {
1345
- if (column.getCanHide()) {
1346
- table.setColumnVisibility((old) => ({
1347
- ...old,
1348
- [column.id]: value != null ? value : !column.getIsVisible()
1349
- }));
1350
- }
1351
- };
1352
- column.getIsVisible = () => {
1353
- var _ref, _table$getState$colum;
1354
- const childColumns = column.columns;
1355
- 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;
1356
- };
1357
- column.getCanHide = () => {
1358
- var _column$columnDef$ena, _table$options$enable;
1359
- return ((_column$columnDef$ena = column.columnDef.enableHiding) != null ? _column$columnDef$ena : true) && ((_table$options$enable = table.options.enableHiding) != null ? _table$options$enable : true);
1360
- };
1361
- column.getToggleVisibilityHandler = () => {
1362
- return (e) => {
1363
- column.toggleVisibility == null || column.toggleVisibility(e.target.checked);
1364
- };
1365
- };
1366
- },
1367
- createRow: (row, table) => {
1368
- row._getAllVisibleCells = memo(() => [row.getAllCells(), table.getState().columnVisibility], (cells) => {
1369
- return cells.filter((cell) => cell.column.getIsVisible());
1370
- }, getMemoOptions(table.options, "debugRows", "_getAllVisibleCells"));
1371
- row.getVisibleCells = memo(() => [row.getLeftVisibleCells(), row.getCenterVisibleCells(), row.getRightVisibleCells()], (left, center, right) => [...left, ...center, ...right], getMemoOptions(table.options, "debugRows", "getVisibleCells"));
1372
- },
1373
- createTable: (table) => {
1374
- const makeVisibleColumnsMethod = (key, getColumns) => {
1375
- return memo(() => [getColumns(), getColumns().filter((d) => d.getIsVisible()).map((d) => d.id).join("_")], (columns) => {
1376
- return columns.filter((d) => d.getIsVisible == null ? void 0 : d.getIsVisible());
1377
- }, getMemoOptions(table.options, "debugColumns", key));
1378
- };
1379
- table.getVisibleFlatColumns = makeVisibleColumnsMethod("getVisibleFlatColumns", () => table.getAllFlatColumns());
1380
- table.getVisibleLeafColumns = makeVisibleColumnsMethod("getVisibleLeafColumns", () => table.getAllLeafColumns());
1381
- table.getLeftVisibleLeafColumns = makeVisibleColumnsMethod("getLeftVisibleLeafColumns", () => table.getLeftLeafColumns());
1382
- table.getRightVisibleLeafColumns = makeVisibleColumnsMethod("getRightVisibleLeafColumns", () => table.getRightLeafColumns());
1383
- table.getCenterVisibleLeafColumns = makeVisibleColumnsMethod("getCenterVisibleLeafColumns", () => table.getCenterLeafColumns());
1384
- table.setColumnVisibility = (updater) => table.options.onColumnVisibilityChange == null ? void 0 : table.options.onColumnVisibilityChange(updater);
1385
- table.resetColumnVisibility = (defaultState) => {
1386
- var _table$initialState$c;
1387
- table.setColumnVisibility(defaultState ? {} : (_table$initialState$c = table.initialState.columnVisibility) != null ? _table$initialState$c : {});
1388
- };
1389
- table.toggleAllColumnsVisible = (value) => {
1390
- var _value;
1391
- value = (_value = value) != null ? _value : !table.getIsAllColumnsVisible();
1392
- table.setColumnVisibility(table.getAllLeafColumns().reduce((obj, column) => ({
1393
- ...obj,
1394
- [column.id]: !value ? !(column.getCanHide != null && column.getCanHide()) : value
1395
- }), {}));
1396
- };
1397
- table.getIsAllColumnsVisible = () => !table.getAllLeafColumns().some((column) => !(column.getIsVisible != null && column.getIsVisible()));
1398
- table.getIsSomeColumnsVisible = () => table.getAllLeafColumns().some((column) => column.getIsVisible == null ? void 0 : column.getIsVisible());
1399
- table.getToggleAllColumnsVisibilityHandler = () => {
1400
- return (e) => {
1401
- var _target;
1402
- table.toggleAllColumnsVisible((_target = e.target) == null ? void 0 : _target.checked);
1403
- };
1404
- };
1405
- }
1406
- };
1407
- function _getVisibleLeafColumns(table, position) {
1408
- return !position ? table.getVisibleLeafColumns() : position === "center" ? table.getCenterVisibleLeafColumns() : position === "left" ? table.getLeftVisibleLeafColumns() : table.getRightVisibleLeafColumns();
1409
- }
1410
- var GlobalFaceting = {
1411
- createTable: (table) => {
1412
- table._getGlobalFacetedRowModel = table.options.getFacetedRowModel && table.options.getFacetedRowModel(table, "__global__");
1413
- table.getGlobalFacetedRowModel = () => {
1414
- if (table.options.manualFiltering || !table._getGlobalFacetedRowModel) {
1415
- return table.getPreFilteredRowModel();
1416
- }
1417
- return table._getGlobalFacetedRowModel();
1418
- };
1419
- table._getGlobalFacetedUniqueValues = table.options.getFacetedUniqueValues && table.options.getFacetedUniqueValues(table, "__global__");
1420
- table.getGlobalFacetedUniqueValues = () => {
1421
- if (!table._getGlobalFacetedUniqueValues) {
1422
- return /* @__PURE__ */ new Map();
1423
- }
1424
- return table._getGlobalFacetedUniqueValues();
1425
- };
1426
- table._getGlobalFacetedMinMaxValues = table.options.getFacetedMinMaxValues && table.options.getFacetedMinMaxValues(table, "__global__");
1427
- table.getGlobalFacetedMinMaxValues = () => {
1428
- if (!table._getGlobalFacetedMinMaxValues) {
1429
- return;
1430
- }
1431
- return table._getGlobalFacetedMinMaxValues();
1432
- };
1433
- }
1434
- };
1435
- var GlobalFiltering = {
1436
- getInitialState: (state) => {
1437
- return {
1438
- globalFilter: void 0,
1439
- ...state
1440
- };
1441
- },
1442
- getDefaultOptions: (table) => {
1443
- return {
1444
- onGlobalFilterChange: makeStateUpdater("globalFilter", table),
1445
- globalFilterFn: "auto",
1446
- getColumnCanGlobalFilter: (column) => {
1447
- var _table$getCoreRowMode;
1448
- const value = (_table$getCoreRowMode = table.getCoreRowModel().flatRows[0]) == null || (_table$getCoreRowMode = _table$getCoreRowMode._getAllCellsByColumnId()[column.id]) == null ? void 0 : _table$getCoreRowMode.getValue();
1449
- return typeof value === "string" || typeof value === "number";
1450
- }
1451
- };
1452
- },
1453
- createColumn: (column, table) => {
1454
- column.getCanGlobalFilter = () => {
1455
- var _column$columnDef$ena, _table$options$enable, _table$options$enable2, _table$options$getCol;
1456
- 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;
1457
- };
1458
- },
1459
- createTable: (table) => {
1460
- table.getGlobalAutoFilterFn = () => {
1461
- return filterFns.includesString;
1462
- };
1463
- table.getGlobalFilterFn = () => {
1464
- var _table$options$filter, _table$options$filter2;
1465
- const {
1466
- globalFilterFn
1467
- } = table.options;
1468
- 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];
1469
- };
1470
- table.setGlobalFilter = (updater) => {
1471
- table.options.onGlobalFilterChange == null || table.options.onGlobalFilterChange(updater);
1472
- };
1473
- table.resetGlobalFilter = (defaultState) => {
1474
- table.setGlobalFilter(defaultState ? void 0 : table.initialState.globalFilter);
1475
- };
1476
- }
1477
- };
1478
- var RowExpanding = {
1479
- getInitialState: (state) => {
1480
- return {
1481
- expanded: {},
1482
- ...state
1483
- };
1484
- },
1485
- getDefaultOptions: (table) => {
1486
- return {
1487
- onExpandedChange: makeStateUpdater("expanded", table),
1488
- paginateExpandedRows: true
1489
- };
1490
- },
1491
- createTable: (table) => {
1492
- let registered = false;
1493
- let queued = false;
1494
- table._autoResetExpanded = () => {
1495
- var _ref, _table$options$autoRe;
1496
- if (!registered) {
1497
- table._queue(() => {
1498
- registered = true;
1499
- });
1500
- return;
1501
- }
1502
- if ((_ref = (_table$options$autoRe = table.options.autoResetAll) != null ? _table$options$autoRe : table.options.autoResetExpanded) != null ? _ref : !table.options.manualExpanding) {
1503
- if (queued) return;
1504
- queued = true;
1505
- table._queue(() => {
1506
- table.resetExpanded();
1507
- queued = false;
1508
- });
1509
- }
1510
- };
1511
- table.setExpanded = (updater) => table.options.onExpandedChange == null ? void 0 : table.options.onExpandedChange(updater);
1512
- table.toggleAllRowsExpanded = (expanded) => {
1513
- if (expanded != null ? expanded : !table.getIsAllRowsExpanded()) {
1514
- table.setExpanded(true);
1515
- } else {
1516
- table.setExpanded({});
1517
- }
1518
- };
1519
- table.resetExpanded = (defaultState) => {
1520
- var _table$initialState$e, _table$initialState;
1521
- table.setExpanded(defaultState ? {} : (_table$initialState$e = (_table$initialState = table.initialState) == null ? void 0 : _table$initialState.expanded) != null ? _table$initialState$e : {});
1522
- };
1523
- table.getCanSomeRowsExpand = () => {
1524
- return table.getPrePaginationRowModel().flatRows.some((row) => row.getCanExpand());
1525
- };
1526
- table.getToggleAllRowsExpandedHandler = () => {
1527
- return (e) => {
1528
- e.persist == null || e.persist();
1529
- table.toggleAllRowsExpanded();
1530
- };
1531
- };
1532
- table.getIsSomeRowsExpanded = () => {
1533
- const expanded = table.getState().expanded;
1534
- return expanded === true || Object.values(expanded).some(Boolean);
1535
- };
1536
- table.getIsAllRowsExpanded = () => {
1537
- const expanded = table.getState().expanded;
1538
- if (typeof expanded === "boolean") {
1539
- return expanded === true;
1540
- }
1541
- if (!Object.keys(expanded).length) {
1542
- return false;
1543
- }
1544
- if (table.getRowModel().flatRows.some((row) => !row.getIsExpanded())) {
1545
- return false;
1546
- }
1547
- return true;
1548
- };
1549
- table.getExpandedDepth = () => {
1550
- let maxDepth = 0;
1551
- const rowIds = table.getState().expanded === true ? Object.keys(table.getRowModel().rowsById) : Object.keys(table.getState().expanded);
1552
- rowIds.forEach((id) => {
1553
- const splitId = id.split(".");
1554
- maxDepth = Math.max(maxDepth, splitId.length);
1555
- });
1556
- return maxDepth;
1557
- };
1558
- table.getPreExpandedRowModel = () => table.getSortedRowModel();
1559
- table.getExpandedRowModel = () => {
1560
- if (!table._getExpandedRowModel && table.options.getExpandedRowModel) {
1561
- table._getExpandedRowModel = table.options.getExpandedRowModel(table);
1562
- }
1563
- if (table.options.manualExpanding || !table._getExpandedRowModel) {
1564
- return table.getPreExpandedRowModel();
1565
- }
1566
- return table._getExpandedRowModel();
1567
- };
1568
- },
1569
- createRow: (row, table) => {
1570
- row.toggleExpanded = (expanded) => {
1571
- table.setExpanded((old) => {
1572
- var _expanded;
1573
- const exists = old === true ? true : !!(old != null && old[row.id]);
1574
- let oldExpanded = {};
1575
- if (old === true) {
1576
- Object.keys(table.getRowModel().rowsById).forEach((rowId) => {
1577
- oldExpanded[rowId] = true;
1578
- });
1579
- } else {
1580
- oldExpanded = old;
1581
- }
1582
- expanded = (_expanded = expanded) != null ? _expanded : !exists;
1583
- if (!exists && expanded) {
1584
- return {
1585
- ...oldExpanded,
1586
- [row.id]: true
1587
- };
1588
- }
1589
- if (exists && !expanded) {
1590
- const {
1591
- [row.id]: _,
1592
- ...rest
1593
- } = oldExpanded;
1594
- return rest;
1595
- }
1596
- return old;
1597
- });
1598
- };
1599
- row.getIsExpanded = () => {
1600
- var _table$options$getIsR;
1601
- const expanded = table.getState().expanded;
1602
- 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]));
1603
- };
1604
- row.getCanExpand = () => {
1605
- var _table$options$getRow, _table$options$enable, _row$subRows;
1606
- 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);
1607
- };
1608
- row.getIsAllParentsExpanded = () => {
1609
- let isFullyExpanded = true;
1610
- let currentRow = row;
1611
- while (isFullyExpanded && currentRow.parentId) {
1612
- currentRow = table.getRow(currentRow.parentId, true);
1613
- isFullyExpanded = currentRow.getIsExpanded();
1614
- }
1615
- return isFullyExpanded;
1616
- };
1617
- row.getToggleExpandedHandler = () => {
1618
- const canExpand = row.getCanExpand();
1619
- return () => {
1620
- if (!canExpand) return;
1621
- row.toggleExpanded();
1622
- };
1623
- };
1624
- }
1625
- };
1626
- var defaultPageIndex = 0;
1627
- var defaultPageSize = 10;
1628
- var getDefaultPaginationState = () => ({
1629
- pageIndex: defaultPageIndex,
1630
- pageSize: defaultPageSize
1631
- });
1632
- var RowPagination = {
1633
- getInitialState: (state) => {
1634
- return {
1635
- ...state,
1636
- pagination: {
1637
- ...getDefaultPaginationState(),
1638
- ...state == null ? void 0 : state.pagination
1639
- }
1640
- };
1641
- },
1642
- getDefaultOptions: (table) => {
1643
- return {
1644
- onPaginationChange: makeStateUpdater("pagination", table)
1645
- };
1646
- },
1647
- createTable: (table) => {
1648
- let registered = false;
1649
- let queued = false;
1650
- table._autoResetPageIndex = () => {
1651
- var _ref, _table$options$autoRe;
1652
- if (!registered) {
1653
- table._queue(() => {
1654
- registered = true;
1655
- });
1656
- return;
1657
- }
1658
- if ((_ref = (_table$options$autoRe = table.options.autoResetAll) != null ? _table$options$autoRe : table.options.autoResetPageIndex) != null ? _ref : !table.options.manualPagination) {
1659
- if (queued) return;
1660
- queued = true;
1661
- table._queue(() => {
1662
- table.resetPageIndex();
1663
- queued = false;
1664
- });
1665
- }
1666
- };
1667
- table.setPagination = (updater) => {
1668
- const safeUpdater = (old) => {
1669
- let newState = functionalUpdate(updater, old);
1670
- return newState;
1671
- };
1672
- return table.options.onPaginationChange == null ? void 0 : table.options.onPaginationChange(safeUpdater);
1673
- };
1674
- table.resetPagination = (defaultState) => {
1675
- var _table$initialState$p;
1676
- table.setPagination(defaultState ? getDefaultPaginationState() : (_table$initialState$p = table.initialState.pagination) != null ? _table$initialState$p : getDefaultPaginationState());
1677
- };
1678
- table.setPageIndex = (updater) => {
1679
- table.setPagination((old) => {
1680
- let pageIndex = functionalUpdate(updater, old.pageIndex);
1681
- const maxPageIndex = typeof table.options.pageCount === "undefined" || table.options.pageCount === -1 ? Number.MAX_SAFE_INTEGER : table.options.pageCount - 1;
1682
- pageIndex = Math.max(0, Math.min(pageIndex, maxPageIndex));
1683
- return {
1684
- ...old,
1685
- pageIndex
1686
- };
1687
- });
1688
- };
1689
- table.resetPageIndex = (defaultState) => {
1690
- var _table$initialState$p2, _table$initialState;
1691
- 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);
1692
- };
1693
- table.resetPageSize = (defaultState) => {
1694
- var _table$initialState$p3, _table$initialState2;
1695
- 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);
1696
- };
1697
- table.setPageSize = (updater) => {
1698
- table.setPagination((old) => {
1699
- const pageSize = Math.max(1, functionalUpdate(updater, old.pageSize));
1700
- const topRowIndex = old.pageSize * old.pageIndex;
1701
- const pageIndex = Math.floor(topRowIndex / pageSize);
1702
- return {
1703
- ...old,
1704
- pageIndex,
1705
- pageSize
1706
- };
1707
- });
1708
- };
1709
- table.setPageCount = (updater) => table.setPagination((old) => {
1710
- var _table$options$pageCo;
1711
- let newPageCount = functionalUpdate(updater, (_table$options$pageCo = table.options.pageCount) != null ? _table$options$pageCo : -1);
1712
- if (typeof newPageCount === "number") {
1713
- newPageCount = Math.max(-1, newPageCount);
1714
- }
1715
- return {
1716
- ...old,
1717
- pageCount: newPageCount
1718
- };
1719
- });
1720
- table.getPageOptions = memo(() => [table.getPageCount()], (pageCount) => {
1721
- let pageOptions = [];
1722
- if (pageCount && pageCount > 0) {
1723
- pageOptions = [...new Array(pageCount)].fill(null).map((_, i) => i);
1724
- }
1725
- return pageOptions;
1726
- }, getMemoOptions(table.options, "debugTable", "getPageOptions"));
1727
- table.getCanPreviousPage = () => table.getState().pagination.pageIndex > 0;
1728
- table.getCanNextPage = () => {
1729
- const {
1730
- pageIndex
1731
- } = table.getState().pagination;
1732
- const pageCount = table.getPageCount();
1733
- if (pageCount === -1) {
1734
- return true;
1735
- }
1736
- if (pageCount === 0) {
1737
- return false;
1738
- }
1739
- return pageIndex < pageCount - 1;
1740
- };
1741
- table.previousPage = () => {
1742
- return table.setPageIndex((old) => old - 1);
1743
- };
1744
- table.nextPage = () => {
1745
- return table.setPageIndex((old) => {
1746
- return old + 1;
1747
- });
1748
- };
1749
- table.firstPage = () => {
1750
- return table.setPageIndex(0);
1751
- };
1752
- table.lastPage = () => {
1753
- return table.setPageIndex(table.getPageCount() - 1);
1754
- };
1755
- table.getPrePaginationRowModel = () => table.getExpandedRowModel();
1756
- table.getPaginationRowModel = () => {
1757
- if (!table._getPaginationRowModel && table.options.getPaginationRowModel) {
1758
- table._getPaginationRowModel = table.options.getPaginationRowModel(table);
1759
- }
1760
- if (table.options.manualPagination || !table._getPaginationRowModel) {
1761
- return table.getPrePaginationRowModel();
1762
- }
1763
- return table._getPaginationRowModel();
1764
- };
1765
- table.getPageCount = () => {
1766
- var _table$options$pageCo2;
1767
- return (_table$options$pageCo2 = table.options.pageCount) != null ? _table$options$pageCo2 : Math.ceil(table.getRowCount() / table.getState().pagination.pageSize);
1768
- };
1769
- table.getRowCount = () => {
1770
- var _table$options$rowCou;
1771
- return (_table$options$rowCou = table.options.rowCount) != null ? _table$options$rowCou : table.getPrePaginationRowModel().rows.length;
1772
- };
1773
- }
1774
- };
1775
- var getDefaultRowPinningState = () => ({
1776
- top: [],
1777
- bottom: []
1778
- });
1779
- var RowPinning = {
1780
- getInitialState: (state) => {
1781
- return {
1782
- rowPinning: getDefaultRowPinningState(),
1783
- ...state
1784
- };
1785
- },
1786
- getDefaultOptions: (table) => {
1787
- return {
1788
- onRowPinningChange: makeStateUpdater("rowPinning", table)
1789
- };
1790
- },
1791
- createRow: (row, table) => {
1792
- row.pin = (position, includeLeafRows, includeParentRows) => {
1793
- const leafRowIds = includeLeafRows ? row.getLeafRows().map((_ref) => {
1794
- let {
1795
- id
1796
- } = _ref;
1797
- return id;
1798
- }) : [];
1799
- const parentRowIds = includeParentRows ? row.getParentRows().map((_ref2) => {
1800
- let {
1801
- id
1802
- } = _ref2;
1803
- return id;
1804
- }) : [];
1805
- const rowIds = /* @__PURE__ */ new Set([...parentRowIds, row.id, ...leafRowIds]);
1806
- table.setRowPinning((old) => {
1807
- var _old$top3, _old$bottom3;
1808
- if (position === "bottom") {
1809
- var _old$top, _old$bottom;
1810
- return {
1811
- top: ((_old$top = old == null ? void 0 : old.top) != null ? _old$top : []).filter((d) => !(rowIds != null && rowIds.has(d))),
1812
- bottom: [...((_old$bottom = old == null ? void 0 : old.bottom) != null ? _old$bottom : []).filter((d) => !(rowIds != null && rowIds.has(d))), ...Array.from(rowIds)]
1813
- };
1814
- }
1815
- if (position === "top") {
1816
- var _old$top2, _old$bottom2;
1817
- return {
1818
- top: [...((_old$top2 = old == null ? void 0 : old.top) != null ? _old$top2 : []).filter((d) => !(rowIds != null && rowIds.has(d))), ...Array.from(rowIds)],
1819
- bottom: ((_old$bottom2 = old == null ? void 0 : old.bottom) != null ? _old$bottom2 : []).filter((d) => !(rowIds != null && rowIds.has(d)))
1820
- };
1821
- }
1822
- return {
1823
- top: ((_old$top3 = old == null ? void 0 : old.top) != null ? _old$top3 : []).filter((d) => !(rowIds != null && rowIds.has(d))),
1824
- bottom: ((_old$bottom3 = old == null ? void 0 : old.bottom) != null ? _old$bottom3 : []).filter((d) => !(rowIds != null && rowIds.has(d)))
1825
- };
1826
- });
1827
- };
1828
- row.getCanPin = () => {
1829
- var _ref3;
1830
- const {
1831
- enableRowPinning,
1832
- enablePinning
1833
- } = table.options;
1834
- if (typeof enableRowPinning === "function") {
1835
- return enableRowPinning(row);
1836
- }
1837
- return (_ref3 = enableRowPinning != null ? enableRowPinning : enablePinning) != null ? _ref3 : true;
1838
- };
1839
- row.getIsPinned = () => {
1840
- const rowIds = [row.id];
1841
- const {
1842
- top,
1843
- bottom
1844
- } = table.getState().rowPinning;
1845
- const isTop = rowIds.some((d) => top == null ? void 0 : top.includes(d));
1846
- const isBottom = rowIds.some((d) => bottom == null ? void 0 : bottom.includes(d));
1847
- return isTop ? "top" : isBottom ? "bottom" : false;
1848
- };
1849
- row.getPinnedIndex = () => {
1850
- var _ref4, _visiblePinnedRowIds$;
1851
- const position = row.getIsPinned();
1852
- if (!position) return -1;
1853
- const visiblePinnedRowIds = (_ref4 = position === "top" ? table.getTopRows() : table.getBottomRows()) == null ? void 0 : _ref4.map((_ref5) => {
1854
- let {
1855
- id
1856
- } = _ref5;
1857
- return id;
1858
- });
1859
- return (_visiblePinnedRowIds$ = visiblePinnedRowIds == null ? void 0 : visiblePinnedRowIds.indexOf(row.id)) != null ? _visiblePinnedRowIds$ : -1;
1860
- };
1861
- },
1862
- createTable: (table) => {
1863
- table.setRowPinning = (updater) => table.options.onRowPinningChange == null ? void 0 : table.options.onRowPinningChange(updater);
1864
- table.resetRowPinning = (defaultState) => {
1865
- var _table$initialState$r, _table$initialState;
1866
- return table.setRowPinning(defaultState ? getDefaultRowPinningState() : (_table$initialState$r = (_table$initialState = table.initialState) == null ? void 0 : _table$initialState.rowPinning) != null ? _table$initialState$r : getDefaultRowPinningState());
1867
- };
1868
- table.getIsSomeRowsPinned = (position) => {
1869
- var _pinningState$positio;
1870
- const pinningState = table.getState().rowPinning;
1871
- if (!position) {
1872
- var _pinningState$top, _pinningState$bottom;
1873
- return Boolean(((_pinningState$top = pinningState.top) == null ? void 0 : _pinningState$top.length) || ((_pinningState$bottom = pinningState.bottom) == null ? void 0 : _pinningState$bottom.length));
1874
- }
1875
- return Boolean((_pinningState$positio = pinningState[position]) == null ? void 0 : _pinningState$positio.length);
1876
- };
1877
- table._getPinnedRows = (visibleRows, pinnedRowIds, position) => {
1878
- var _table$options$keepPi;
1879
- const rows = ((_table$options$keepPi = table.options.keepPinnedRows) != null ? _table$options$keepPi : true) ? (
1880
- //get all rows that are pinned even if they would not be otherwise visible
1881
- //account for expanded parent rows, but not pagination or filtering
1882
- (pinnedRowIds != null ? pinnedRowIds : []).map((rowId) => {
1883
- const row = table.getRow(rowId, true);
1884
- return row.getIsAllParentsExpanded() ? row : null;
1885
- })
1886
- ) : (
1887
- //else get only visible rows that are pinned
1888
- (pinnedRowIds != null ? pinnedRowIds : []).map((rowId) => visibleRows.find((row) => row.id === rowId))
1889
- );
1890
- return rows.filter(Boolean).map((d) => ({
1891
- ...d,
1892
- position
1893
- }));
1894
- };
1895
- table.getTopRows = memo(() => [table.getRowModel().rows, table.getState().rowPinning.top], (allRows, topPinnedRowIds) => table._getPinnedRows(allRows, topPinnedRowIds, "top"), getMemoOptions(table.options, "debugRows", "getTopRows"));
1896
- table.getBottomRows = memo(() => [table.getRowModel().rows, table.getState().rowPinning.bottom], (allRows, bottomPinnedRowIds) => table._getPinnedRows(allRows, bottomPinnedRowIds, "bottom"), getMemoOptions(table.options, "debugRows", "getBottomRows"));
1897
- table.getCenterRows = memo(() => [table.getRowModel().rows, table.getState().rowPinning.top, table.getState().rowPinning.bottom], (allRows, top, bottom) => {
1898
- const topAndBottom = /* @__PURE__ */ new Set([...top != null ? top : [], ...bottom != null ? bottom : []]);
1899
- return allRows.filter((d) => !topAndBottom.has(d.id));
1900
- }, getMemoOptions(table.options, "debugRows", "getCenterRows"));
1901
- }
1902
- };
1903
- var RowSelection = {
1904
- getInitialState: (state) => {
1905
- return {
1906
- rowSelection: {},
1907
- ...state
1908
- };
1909
- },
1910
- getDefaultOptions: (table) => {
1911
- return {
1912
- onRowSelectionChange: makeStateUpdater("rowSelection", table),
1913
- enableRowSelection: true,
1914
- enableMultiRowSelection: true,
1915
- enableSubRowSelection: true
1916
- // enableGroupingRowSelection: false,
1917
- // isAdditiveSelectEvent: (e: unknown) => !!e.metaKey,
1918
- // isInclusiveSelectEvent: (e: unknown) => !!e.shiftKey,
1919
- };
1920
- },
1921
- createTable: (table) => {
1922
- table.setRowSelection = (updater) => table.options.onRowSelectionChange == null ? void 0 : table.options.onRowSelectionChange(updater);
1923
- table.resetRowSelection = (defaultState) => {
1924
- var _table$initialState$r;
1925
- return table.setRowSelection(defaultState ? {} : (_table$initialState$r = table.initialState.rowSelection) != null ? _table$initialState$r : {});
1926
- };
1927
- table.toggleAllRowsSelected = (value) => {
1928
- table.setRowSelection((old) => {
1929
- value = typeof value !== "undefined" ? value : !table.getIsAllRowsSelected();
1930
- const rowSelection = {
1931
- ...old
1932
- };
1933
- const preGroupedFlatRows = table.getPreGroupedRowModel().flatRows;
1934
- if (value) {
1935
- preGroupedFlatRows.forEach((row) => {
1936
- if (!row.getCanSelect()) {
1937
- return;
1938
- }
1939
- rowSelection[row.id] = true;
1940
- });
1941
- } else {
1942
- preGroupedFlatRows.forEach((row) => {
1943
- delete rowSelection[row.id];
1944
- });
1945
- }
1946
- return rowSelection;
1947
- });
1948
- };
1949
- table.toggleAllPageRowsSelected = (value) => table.setRowSelection((old) => {
1950
- const resolvedValue = typeof value !== "undefined" ? value : !table.getIsAllPageRowsSelected();
1951
- const rowSelection = {
1952
- ...old
1953
- };
1954
- table.getRowModel().rows.forEach((row) => {
1955
- mutateRowIsSelected(rowSelection, row.id, resolvedValue, true, table);
1956
- });
1957
- return rowSelection;
1958
- });
1959
- table.getPreSelectedRowModel = () => table.getCoreRowModel();
1960
- table.getSelectedRowModel = memo(() => [table.getState().rowSelection, table.getCoreRowModel()], (rowSelection, rowModel) => {
1961
- if (!Object.keys(rowSelection).length) {
1962
- return {
1963
- rows: [],
1964
- flatRows: [],
1965
- rowsById: {}
1966
- };
1967
- }
1968
- return selectRowsFn(table, rowModel);
1969
- }, getMemoOptions(table.options, "debugTable", "getSelectedRowModel"));
1970
- table.getFilteredSelectedRowModel = memo(() => [table.getState().rowSelection, table.getFilteredRowModel()], (rowSelection, rowModel) => {
1971
- if (!Object.keys(rowSelection).length) {
1972
- return {
1973
- rows: [],
1974
- flatRows: [],
1975
- rowsById: {}
1976
- };
1977
- }
1978
- return selectRowsFn(table, rowModel);
1979
- }, getMemoOptions(table.options, "debugTable", "getFilteredSelectedRowModel"));
1980
- table.getGroupedSelectedRowModel = memo(() => [table.getState().rowSelection, table.getSortedRowModel()], (rowSelection, rowModel) => {
1981
- if (!Object.keys(rowSelection).length) {
1982
- return {
1983
- rows: [],
1984
- flatRows: [],
1985
- rowsById: {}
1986
- };
1987
- }
1988
- return selectRowsFn(table, rowModel);
1989
- }, getMemoOptions(table.options, "debugTable", "getGroupedSelectedRowModel"));
1990
- table.getIsAllRowsSelected = () => {
1991
- const preGroupedFlatRows = table.getFilteredRowModel().flatRows;
1992
- const {
1993
- rowSelection
1994
- } = table.getState();
1995
- let isAllRowsSelected = Boolean(preGroupedFlatRows.length && Object.keys(rowSelection).length);
1996
- if (isAllRowsSelected) {
1997
- if (preGroupedFlatRows.some((row) => row.getCanSelect() && !rowSelection[row.id])) {
1998
- isAllRowsSelected = false;
1999
- }
2000
- }
2001
- return isAllRowsSelected;
2002
- };
2003
- table.getIsAllPageRowsSelected = () => {
2004
- const paginationFlatRows = table.getPaginationRowModel().flatRows.filter((row) => row.getCanSelect());
2005
- const {
2006
- rowSelection
2007
- } = table.getState();
2008
- let isAllPageRowsSelected = !!paginationFlatRows.length;
2009
- if (isAllPageRowsSelected && paginationFlatRows.some((row) => !rowSelection[row.id])) {
2010
- isAllPageRowsSelected = false;
2011
- }
2012
- return isAllPageRowsSelected;
2013
- };
2014
- table.getIsSomeRowsSelected = () => {
2015
- var _table$getState$rowSe;
2016
- const totalSelected = Object.keys((_table$getState$rowSe = table.getState().rowSelection) != null ? _table$getState$rowSe : {}).length;
2017
- return totalSelected > 0 && totalSelected < table.getFilteredRowModel().flatRows.length;
2018
- };
2019
- table.getIsSomePageRowsSelected = () => {
2020
- const paginationFlatRows = table.getPaginationRowModel().flatRows;
2021
- return table.getIsAllPageRowsSelected() ? false : paginationFlatRows.filter((row) => row.getCanSelect()).some((d) => d.getIsSelected() || d.getIsSomeSelected());
2022
- };
2023
- table.getToggleAllRowsSelectedHandler = () => {
2024
- return (e) => {
2025
- table.toggleAllRowsSelected(e.target.checked);
2026
- };
2027
- };
2028
- table.getToggleAllPageRowsSelectedHandler = () => {
2029
- return (e) => {
2030
- table.toggleAllPageRowsSelected(e.target.checked);
2031
- };
2032
- };
2033
- },
2034
- createRow: (row, table) => {
2035
- row.toggleSelected = (value, opts) => {
2036
- const isSelected = row.getIsSelected();
2037
- table.setRowSelection((old) => {
2038
- var _opts$selectChildren;
2039
- value = typeof value !== "undefined" ? value : !isSelected;
2040
- if (row.getCanSelect() && isSelected === value) {
2041
- return old;
2042
- }
2043
- const selectedRowIds = {
2044
- ...old
2045
- };
2046
- mutateRowIsSelected(selectedRowIds, row.id, value, (_opts$selectChildren = opts == null ? void 0 : opts.selectChildren) != null ? _opts$selectChildren : true, table);
2047
- return selectedRowIds;
2048
- });
2049
- };
2050
- row.getIsSelected = () => {
2051
- const {
2052
- rowSelection
2053
- } = table.getState();
2054
- return isRowSelected(row, rowSelection);
2055
- };
2056
- row.getIsSomeSelected = () => {
2057
- const {
2058
- rowSelection
2059
- } = table.getState();
2060
- return isSubRowSelected(row, rowSelection) === "some";
2061
- };
2062
- row.getIsAllSubRowsSelected = () => {
2063
- const {
2064
- rowSelection
2065
- } = table.getState();
2066
- return isSubRowSelected(row, rowSelection) === "all";
2067
- };
2068
- row.getCanSelect = () => {
2069
- var _table$options$enable;
2070
- if (typeof table.options.enableRowSelection === "function") {
2071
- return table.options.enableRowSelection(row);
2072
- }
2073
- return (_table$options$enable = table.options.enableRowSelection) != null ? _table$options$enable : true;
2074
- };
2075
- row.getCanSelectSubRows = () => {
2076
- var _table$options$enable2;
2077
- if (typeof table.options.enableSubRowSelection === "function") {
2078
- return table.options.enableSubRowSelection(row);
2079
- }
2080
- return (_table$options$enable2 = table.options.enableSubRowSelection) != null ? _table$options$enable2 : true;
2081
- };
2082
- row.getCanMultiSelect = () => {
2083
- var _table$options$enable3;
2084
- if (typeof table.options.enableMultiRowSelection === "function") {
2085
- return table.options.enableMultiRowSelection(row);
2086
- }
2087
- return (_table$options$enable3 = table.options.enableMultiRowSelection) != null ? _table$options$enable3 : true;
2088
- };
2089
- row.getToggleSelectedHandler = () => {
2090
- const canSelect = row.getCanSelect();
2091
- return (e) => {
2092
- var _target;
2093
- if (!canSelect) return;
2094
- row.toggleSelected((_target = e.target) == null ? void 0 : _target.checked);
2095
- };
2096
- };
2097
- }
2098
- };
2099
- var mutateRowIsSelected = (selectedRowIds, id, value, includeChildren, table) => {
2100
- var _row$subRows;
2101
- const row = table.getRow(id, true);
2102
- if (value) {
2103
- if (!row.getCanMultiSelect()) {
2104
- Object.keys(selectedRowIds).forEach((key) => delete selectedRowIds[key]);
2105
- }
2106
- if (row.getCanSelect()) {
2107
- selectedRowIds[id] = true;
2108
- }
2109
- } else {
2110
- delete selectedRowIds[id];
2111
- }
2112
- if (includeChildren && (_row$subRows = row.subRows) != null && _row$subRows.length && row.getCanSelectSubRows()) {
2113
- row.subRows.forEach((row2) => mutateRowIsSelected(selectedRowIds, row2.id, value, includeChildren, table));
2114
- }
2115
- };
2116
- function selectRowsFn(table, rowModel) {
2117
- const rowSelection = table.getState().rowSelection;
2118
- const newSelectedFlatRows = [];
2119
- const newSelectedRowsById = {};
2120
- const recurseRows = function(rows, depth) {
2121
- return rows.map((row) => {
2122
- var _row$subRows2;
2123
- const isSelected = isRowSelected(row, rowSelection);
2124
- if (isSelected) {
2125
- newSelectedFlatRows.push(row);
2126
- newSelectedRowsById[row.id] = row;
2127
- }
2128
- if ((_row$subRows2 = row.subRows) != null && _row$subRows2.length) {
2129
- row = {
2130
- ...row,
2131
- subRows: recurseRows(row.subRows)
2132
- };
2133
- }
2134
- if (isSelected) {
2135
- return row;
2136
- }
2137
- }).filter(Boolean);
2138
- };
2139
- return {
2140
- rows: recurseRows(rowModel.rows),
2141
- flatRows: newSelectedFlatRows,
2142
- rowsById: newSelectedRowsById
2143
- };
2144
- }
2145
- function isRowSelected(row, selection) {
2146
- var _selection$row$id;
2147
- return (_selection$row$id = selection[row.id]) != null ? _selection$row$id : false;
2148
- }
2149
- function isSubRowSelected(row, selection, table) {
2150
- var _row$subRows3;
2151
- if (!((_row$subRows3 = row.subRows) != null && _row$subRows3.length)) return false;
2152
- let allChildrenSelected = true;
2153
- let someSelected = false;
2154
- row.subRows.forEach((subRow) => {
2155
- if (someSelected && !allChildrenSelected) {
2156
- return;
2157
- }
2158
- if (subRow.getCanSelect()) {
2159
- if (isRowSelected(subRow, selection)) {
2160
- someSelected = true;
2161
- } else {
2162
- allChildrenSelected = false;
2163
- }
2164
- }
2165
- if (subRow.subRows && subRow.subRows.length) {
2166
- const subRowChildrenSelected = isSubRowSelected(subRow, selection);
2167
- if (subRowChildrenSelected === "all") {
2168
- someSelected = true;
2169
- } else if (subRowChildrenSelected === "some") {
2170
- someSelected = true;
2171
- allChildrenSelected = false;
2172
- } else {
2173
- allChildrenSelected = false;
2174
- }
2175
- }
2176
- });
2177
- return allChildrenSelected ? "all" : someSelected ? "some" : false;
2178
- }
2179
- var reSplitAlphaNumeric = /([0-9]+)/gm;
2180
- var alphanumeric = (rowA, rowB, columnId) => {
2181
- return compareAlphanumeric(toString(rowA.getValue(columnId)).toLowerCase(), toString(rowB.getValue(columnId)).toLowerCase());
2182
- };
2183
- var alphanumericCaseSensitive = (rowA, rowB, columnId) => {
2184
- return compareAlphanumeric(toString(rowA.getValue(columnId)), toString(rowB.getValue(columnId)));
2185
- };
2186
- var text = (rowA, rowB, columnId) => {
2187
- return compareBasic(toString(rowA.getValue(columnId)).toLowerCase(), toString(rowB.getValue(columnId)).toLowerCase());
2188
- };
2189
- var textCaseSensitive = (rowA, rowB, columnId) => {
2190
- return compareBasic(toString(rowA.getValue(columnId)), toString(rowB.getValue(columnId)));
2191
- };
2192
- var datetime = (rowA, rowB, columnId) => {
2193
- const a = rowA.getValue(columnId);
2194
- const b = rowB.getValue(columnId);
2195
- return a > b ? 1 : a < b ? -1 : 0;
2196
- };
2197
- var basic = (rowA, rowB, columnId) => {
2198
- return compareBasic(rowA.getValue(columnId), rowB.getValue(columnId));
2199
- };
2200
- function compareBasic(a, b) {
2201
- return a === b ? 0 : a > b ? 1 : -1;
2202
- }
2203
- function toString(a) {
2204
- if (typeof a === "number") {
2205
- if (isNaN(a) || a === Infinity || a === -Infinity) {
2206
- return "";
2207
- }
2208
- return String(a);
2209
- }
2210
- if (typeof a === "string") {
2211
- return a;
2212
- }
2213
- return "";
2214
- }
2215
- function compareAlphanumeric(aStr, bStr) {
2216
- const a = aStr.split(reSplitAlphaNumeric).filter(Boolean);
2217
- const b = bStr.split(reSplitAlphaNumeric).filter(Boolean);
2218
- while (a.length && b.length) {
2219
- const aa = a.shift();
2220
- const bb = b.shift();
2221
- const an = parseInt(aa, 10);
2222
- const bn = parseInt(bb, 10);
2223
- const combo = [an, bn].sort();
2224
- if (isNaN(combo[0])) {
2225
- if (aa > bb) {
2226
- return 1;
2227
- }
2228
- if (bb > aa) {
2229
- return -1;
2230
- }
2231
- continue;
2232
- }
2233
- if (isNaN(combo[1])) {
2234
- return isNaN(an) ? -1 : 1;
2235
- }
2236
- if (an > bn) {
2237
- return 1;
2238
- }
2239
- if (bn > an) {
2240
- return -1;
2241
- }
2242
- }
2243
- return a.length - b.length;
2244
- }
2245
- var sortingFns = {
2246
- alphanumeric,
2247
- alphanumericCaseSensitive,
2248
- text,
2249
- textCaseSensitive,
2250
- datetime,
2251
- basic
2252
- };
2253
- var RowSorting = {
2254
- getInitialState: (state) => {
2255
- return {
2256
- sorting: [],
2257
- ...state
2258
- };
2259
- },
2260
- getDefaultColumnDef: () => {
2261
- return {
2262
- sortingFn: "auto",
2263
- sortUndefined: 1
2264
- };
2265
- },
2266
- getDefaultOptions: (table) => {
2267
- return {
2268
- onSortingChange: makeStateUpdater("sorting", table),
2269
- isMultiSortEvent: (e) => {
2270
- return e.shiftKey;
2271
- }
2272
- };
2273
- },
2274
- createColumn: (column, table) => {
2275
- column.getAutoSortingFn = () => {
2276
- const firstRows = table.getFilteredRowModel().flatRows.slice(10);
2277
- let isString = false;
2278
- for (const row of firstRows) {
2279
- const value = row == null ? void 0 : row.getValue(column.id);
2280
- if (Object.prototype.toString.call(value) === "[object Date]") {
2281
- return sortingFns.datetime;
2282
- }
2283
- if (typeof value === "string") {
2284
- isString = true;
2285
- if (value.split(reSplitAlphaNumeric).length > 1) {
2286
- return sortingFns.alphanumeric;
2287
- }
2288
- }
2289
- }
2290
- if (isString) {
2291
- return sortingFns.text;
2292
- }
2293
- return sortingFns.basic;
2294
- };
2295
- column.getAutoSortDir = () => {
2296
- const firstRow = table.getFilteredRowModel().flatRows[0];
2297
- const value = firstRow == null ? void 0 : firstRow.getValue(column.id);
2298
- if (typeof value === "string") {
2299
- return "asc";
2300
- }
2301
- return "desc";
2302
- };
2303
- column.getSortingFn = () => {
2304
- var _table$options$sortin, _table$options$sortin2;
2305
- if (!column) {
2306
- throw new Error();
2307
- }
2308
- 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];
2309
- };
2310
- column.toggleSorting = (desc, multi) => {
2311
- const nextSortingOrder = column.getNextSortingOrder();
2312
- const hasManualValue = typeof desc !== "undefined" && desc !== null;
2313
- table.setSorting((old) => {
2314
- const existingSorting = old == null ? void 0 : old.find((d) => d.id === column.id);
2315
- const existingIndex = old == null ? void 0 : old.findIndex((d) => d.id === column.id);
2316
- let newSorting = [];
2317
- let sortAction;
2318
- let nextDesc = hasManualValue ? desc : nextSortingOrder === "desc";
2319
- if (old != null && old.length && column.getCanMultiSort() && multi) {
2320
- if (existingSorting) {
2321
- sortAction = "toggle";
2322
- } else {
2323
- sortAction = "add";
2324
- }
2325
- } else {
2326
- if (old != null && old.length && existingIndex !== old.length - 1) {
2327
- sortAction = "replace";
2328
- } else if (existingSorting) {
2329
- sortAction = "toggle";
2330
- } else {
2331
- sortAction = "replace";
2332
- }
2333
- }
2334
- if (sortAction === "toggle") {
2335
- if (!hasManualValue) {
2336
- if (!nextSortingOrder) {
2337
- sortAction = "remove";
2338
- }
2339
- }
2340
- }
2341
- if (sortAction === "add") {
2342
- var _table$options$maxMul;
2343
- newSorting = [...old, {
2344
- id: column.id,
2345
- desc: nextDesc
2346
- }];
2347
- newSorting.splice(0, newSorting.length - ((_table$options$maxMul = table.options.maxMultiSortColCount) != null ? _table$options$maxMul : Number.MAX_SAFE_INTEGER));
2348
- } else if (sortAction === "toggle") {
2349
- newSorting = old.map((d) => {
2350
- if (d.id === column.id) {
2351
- return {
2352
- ...d,
2353
- desc: nextDesc
2354
- };
2355
- }
2356
- return d;
2357
- });
2358
- } else if (sortAction === "remove") {
2359
- newSorting = old.filter((d) => d.id !== column.id);
2360
- } else {
2361
- newSorting = [{
2362
- id: column.id,
2363
- desc: nextDesc
2364
- }];
2365
- }
2366
- return newSorting;
2367
- });
2368
- };
2369
- column.getFirstSortDir = () => {
2370
- var _ref, _column$columnDef$sor;
2371
- const sortDescFirst = (_ref = (_column$columnDef$sor = column.columnDef.sortDescFirst) != null ? _column$columnDef$sor : table.options.sortDescFirst) != null ? _ref : column.getAutoSortDir() === "desc";
2372
- return sortDescFirst ? "desc" : "asc";
2373
- };
2374
- column.getNextSortingOrder = (multi) => {
2375
- var _table$options$enable, _table$options$enable2;
2376
- const firstSortDirection = column.getFirstSortDir();
2377
- const isSorted = column.getIsSorted();
2378
- if (!isSorted) {
2379
- return firstSortDirection;
2380
- }
2381
- if (isSorted !== firstSortDirection && ((_table$options$enable = table.options.enableSortingRemoval) != null ? _table$options$enable : true) && // If enableSortRemove, enable in general
2382
- (multi ? (_table$options$enable2 = table.options.enableMultiRemove) != null ? _table$options$enable2 : true : true)) {
2383
- return false;
2384
- }
2385
- return isSorted === "desc" ? "asc" : "desc";
2386
- };
2387
- column.getCanSort = () => {
2388
- var _column$columnDef$ena, _table$options$enable3;
2389
- 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;
2390
- };
2391
- column.getCanMultiSort = () => {
2392
- var _ref2, _column$columnDef$ena2;
2393
- return (_ref2 = (_column$columnDef$ena2 = column.columnDef.enableMultiSort) != null ? _column$columnDef$ena2 : table.options.enableMultiSort) != null ? _ref2 : !!column.accessorFn;
2394
- };
2395
- column.getIsSorted = () => {
2396
- var _table$getState$sorti;
2397
- const columnSort = (_table$getState$sorti = table.getState().sorting) == null ? void 0 : _table$getState$sorti.find((d) => d.id === column.id);
2398
- return !columnSort ? false : columnSort.desc ? "desc" : "asc";
2399
- };
2400
- column.getSortIndex = () => {
2401
- var _table$getState$sorti2, _table$getState$sorti3;
2402
- 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;
2403
- };
2404
- column.clearSorting = () => {
2405
- table.setSorting((old) => old != null && old.length ? old.filter((d) => d.id !== column.id) : []);
2406
- };
2407
- column.getToggleSortingHandler = () => {
2408
- const canSort = column.getCanSort();
2409
- return (e) => {
2410
- if (!canSort) return;
2411
- e.persist == null || e.persist();
2412
- column.toggleSorting == null || column.toggleSorting(void 0, column.getCanMultiSort() ? table.options.isMultiSortEvent == null ? void 0 : table.options.isMultiSortEvent(e) : false);
2413
- };
2414
- };
2415
- },
2416
- createTable: (table) => {
2417
- table.setSorting = (updater) => table.options.onSortingChange == null ? void 0 : table.options.onSortingChange(updater);
2418
- table.resetSorting = (defaultState) => {
2419
- var _table$initialState$s, _table$initialState;
2420
- table.setSorting(defaultState ? [] : (_table$initialState$s = (_table$initialState = table.initialState) == null ? void 0 : _table$initialState.sorting) != null ? _table$initialState$s : []);
2421
- };
2422
- table.getPreSortedRowModel = () => table.getGroupedRowModel();
2423
- table.getSortedRowModel = () => {
2424
- if (!table._getSortedRowModel && table.options.getSortedRowModel) {
2425
- table._getSortedRowModel = table.options.getSortedRowModel(table);
2426
- }
2427
- if (table.options.manualSorting || !table._getSortedRowModel) {
2428
- return table.getPreSortedRowModel();
2429
- }
2430
- return table._getSortedRowModel();
2431
- };
2432
- }
2433
- };
2434
- var builtInFeatures = [
2435
- Headers,
2436
- ColumnVisibility,
2437
- ColumnOrdering,
2438
- ColumnPinning,
2439
- ColumnFaceting,
2440
- ColumnFiltering,
2441
- GlobalFaceting,
2442
- //depends on ColumnFaceting
2443
- GlobalFiltering,
2444
- //depends on ColumnFiltering
2445
- RowSorting,
2446
- ColumnGrouping,
2447
- //depends on RowSorting
2448
- RowExpanding,
2449
- RowPagination,
2450
- RowPinning,
2451
- RowSelection,
2452
- ColumnSizing
2453
- ];
2454
- function createTable(options) {
2455
- var _options$_features, _options$initialState;
2456
- if (process.env.NODE_ENV !== "production" && (options.debugAll || options.debugTable)) {
2457
- console.info("Creating Table Instance...");
2458
- }
2459
- const _features = [...builtInFeatures, ...(_options$_features = options._features) != null ? _options$_features : []];
2460
- let table = {
2461
- _features
2462
- };
2463
- const defaultOptions = table._features.reduce((obj, feature) => {
2464
- return Object.assign(obj, feature.getDefaultOptions == null ? void 0 : feature.getDefaultOptions(table));
2465
- }, {});
2466
- const mergeOptions = (options2) => {
2467
- if (table.options.mergeOptions) {
2468
- return table.options.mergeOptions(defaultOptions, options2);
2469
- }
2470
- return {
2471
- ...defaultOptions,
2472
- ...options2
2473
- };
2474
- };
2475
- const coreInitialState = {};
2476
- let initialState = {
2477
- ...coreInitialState,
2478
- ...(_options$initialState = options.initialState) != null ? _options$initialState : {}
2479
- };
2480
- table._features.forEach((feature) => {
2481
- var _feature$getInitialSt;
2482
- initialState = (_feature$getInitialSt = feature.getInitialState == null ? void 0 : feature.getInitialState(initialState)) != null ? _feature$getInitialSt : initialState;
2483
- });
2484
- const queued = [];
2485
- let queuedTimeout = false;
2486
- const coreInstance = {
2487
- _features,
2488
- options: {
2489
- ...defaultOptions,
2490
- ...options
2491
- },
2492
- initialState,
2493
- _queue: (cb) => {
2494
- queued.push(cb);
2495
- if (!queuedTimeout) {
2496
- queuedTimeout = true;
2497
- Promise.resolve().then(() => {
2498
- while (queued.length) {
2499
- queued.shift()();
2500
- }
2501
- queuedTimeout = false;
2502
- }).catch((error) => setTimeout(() => {
2503
- throw error;
2504
- }));
2505
- }
2506
- },
2507
- reset: () => {
2508
- table.setState(table.initialState);
2509
- },
2510
- setOptions: (updater) => {
2511
- const newOptions = functionalUpdate(updater, table.options);
2512
- table.options = mergeOptions(newOptions);
2513
- },
2514
- getState: () => {
2515
- return table.options.state;
2516
- },
2517
- setState: (updater) => {
2518
- table.options.onStateChange == null || table.options.onStateChange(updater);
2519
- },
2520
- _getRowId: (row, index, parent) => {
2521
- var _table$options$getRow;
2522
- 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}`;
2523
- },
2524
- getCoreRowModel: () => {
2525
- if (!table._getCoreRowModel) {
2526
- table._getCoreRowModel = table.options.getCoreRowModel(table);
2527
- }
2528
- return table._getCoreRowModel();
2529
- },
2530
- // The final calls start at the bottom of the model,
2531
- // expanded rows, which then work their way up
2532
- getRowModel: () => {
2533
- return table.getPaginationRowModel();
2534
- },
2535
- //in next version, we should just pass in the row model as the optional 2nd arg
2536
- getRow: (id, searchAll) => {
2537
- let row = (searchAll ? table.getPrePaginationRowModel() : table.getRowModel()).rowsById[id];
2538
- if (!row) {
2539
- row = table.getCoreRowModel().rowsById[id];
2540
- if (!row) {
2541
- if (process.env.NODE_ENV !== "production") {
2542
- throw new Error(`getRow could not find row with ID: ${id}`);
2543
- }
2544
- throw new Error();
2545
- }
2546
- }
2547
- return row;
2548
- },
2549
- _getDefaultColumnDef: memo(() => [table.options.defaultColumn], (defaultColumn) => {
2550
- var _defaultColumn;
2551
- defaultColumn = (_defaultColumn = defaultColumn) != null ? _defaultColumn : {};
2552
- return {
2553
- header: (props) => {
2554
- const resolvedColumnDef = props.header.column.columnDef;
2555
- if (resolvedColumnDef.accessorKey) {
2556
- return resolvedColumnDef.accessorKey;
2557
- }
2558
- if (resolvedColumnDef.accessorFn) {
2559
- return resolvedColumnDef.id;
2560
- }
2561
- return null;
2562
- },
2563
- // footer: props => props.header.column.id,
2564
- cell: (props) => {
2565
- var _props$renderValue$to, _props$renderValue;
2566
- return (_props$renderValue$to = (_props$renderValue = props.renderValue()) == null || _props$renderValue.toString == null ? void 0 : _props$renderValue.toString()) != null ? _props$renderValue$to : null;
2567
- },
2568
- ...table._features.reduce((obj, feature) => {
2569
- return Object.assign(obj, feature.getDefaultColumnDef == null ? void 0 : feature.getDefaultColumnDef());
2570
- }, {}),
2571
- ...defaultColumn
2572
- };
2573
- }, getMemoOptions(options, "debugColumns", "_getDefaultColumnDef")),
2574
- _getColumnDefs: () => table.options.columns,
2575
- getAllColumns: memo(() => [table._getColumnDefs()], (columnDefs) => {
2576
- const recurseColumns = function(columnDefs2, parent, depth) {
2577
- if (depth === void 0) {
2578
- depth = 0;
2579
- }
2580
- return columnDefs2.map((columnDef) => {
2581
- const column = createColumn(table, columnDef, depth, parent);
2582
- const groupingColumnDef = columnDef;
2583
- column.columns = groupingColumnDef.columns ? recurseColumns(groupingColumnDef.columns, column, depth + 1) : [];
2584
- return column;
2585
- });
2586
- };
2587
- return recurseColumns(columnDefs);
2588
- }, getMemoOptions(options, "debugColumns", "getAllColumns")),
2589
- getAllFlatColumns: memo(() => [table.getAllColumns()], (allColumns) => {
2590
- return allColumns.flatMap((column) => {
2591
- return column.getFlatColumns();
2592
- });
2593
- }, getMemoOptions(options, "debugColumns", "getAllFlatColumns")),
2594
- _getAllFlatColumnsById: memo(() => [table.getAllFlatColumns()], (flatColumns) => {
2595
- return flatColumns.reduce((acc, column) => {
2596
- acc[column.id] = column;
2597
- return acc;
2598
- }, {});
2599
- }, getMemoOptions(options, "debugColumns", "getAllFlatColumnsById")),
2600
- getAllLeafColumns: memo(() => [table.getAllColumns(), table._getOrderColumnsFn()], (allColumns, orderColumns2) => {
2601
- let leafColumns = allColumns.flatMap((column) => column.getLeafColumns());
2602
- return orderColumns2(leafColumns);
2603
- }, getMemoOptions(options, "debugColumns", "getAllLeafColumns")),
2604
- getColumn: (columnId) => {
2605
- const column = table._getAllFlatColumnsById()[columnId];
2606
- if (process.env.NODE_ENV !== "production" && !column) {
2607
- console.error(`[Table] Column with id '${columnId}' does not exist.`);
2608
- }
2609
- return column;
2610
- }
2611
- };
2612
- Object.assign(table, coreInstance);
2613
- for (let index = 0; index < table._features.length; index++) {
2614
- const feature = table._features[index];
2615
- feature == null || feature.createTable == null || feature.createTable(table);
2616
- }
2617
- return table;
2618
- }
2619
- function getCoreRowModel() {
2620
- return (table) => memo(() => [table.options.data], (data) => {
2621
- const rowModel = {
2622
- rows: [],
2623
- flatRows: [],
2624
- rowsById: {}
2625
- };
2626
- const accessRows = function(originalRows, depth, parentRow) {
2627
- if (depth === void 0) {
2628
- depth = 0;
2629
- }
2630
- const rows = [];
2631
- for (let i = 0; i < originalRows.length; i++) {
2632
- const row = createRow(table, table._getRowId(originalRows[i], i, parentRow), originalRows[i], i, depth, void 0, parentRow == null ? void 0 : parentRow.id);
2633
- rowModel.flatRows.push(row);
2634
- rowModel.rowsById[row.id] = row;
2635
- rows.push(row);
2636
- if (table.options.getSubRows) {
2637
- var _row$originalSubRows;
2638
- row.originalSubRows = table.options.getSubRows(originalRows[i], i);
2639
- if ((_row$originalSubRows = row.originalSubRows) != null && _row$originalSubRows.length) {
2640
- row.subRows = accessRows(row.originalSubRows, depth + 1, row);
2641
- }
2642
- }
2643
- }
2644
- return rows;
2645
- };
2646
- rowModel.rows = accessRows(data);
2647
- return rowModel;
2648
- }, getMemoOptions(table.options, "debugTable", "getRowModel", () => table._autoResetPageIndex()));
2649
- }
13
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
2650
14
 
2651
- // ../../node_modules/.pnpm/@tanstack+react-table@8.21.3_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/@tanstack/react-table/build/lib/index.mjs
2652
- function flexRender(Comp, props) {
2653
- return !Comp ? null : isReactComponent(Comp) ? /* @__PURE__ */ React2__namespace.createElement(Comp, props) : Comp;
2654
- }
2655
- function isReactComponent(component) {
2656
- return isClassComponent(component) || typeof component === "function" || isExoticComponent(component);
2657
- }
2658
- function isClassComponent(component) {
2659
- return typeof component === "function" && (() => {
2660
- const proto = Object.getPrototypeOf(component);
2661
- return proto.prototype && proto.prototype.isReactComponent;
2662
- })();
2663
- }
2664
- function isExoticComponent(component) {
2665
- return typeof component === "object" && typeof component.$$typeof === "symbol" && ["react.memo", "react.forward_ref"].includes(component.$$typeof.description);
2666
- }
2667
- function useReactTable(options) {
2668
- const resolvedOptions = {
2669
- state: {},
2670
- // Dummy state
2671
- onStateChange: () => {
2672
- },
2673
- // noop
2674
- renderFallbackValue: null,
2675
- ...options
2676
- };
2677
- const [tableRef] = React2__namespace.useState(() => ({
2678
- current: createTable(resolvedOptions)
2679
- }));
2680
- const [state, setState] = React2__namespace.useState(() => tableRef.current.initialState);
2681
- tableRef.current.setOptions((prev) => ({
2682
- ...prev,
2683
- ...options,
2684
- state: {
2685
- ...state,
2686
- ...options.state
2687
- },
2688
- // Similarly, we'll maintain both our internal state and any user-provided
2689
- // state.
2690
- onStateChange: (updater) => {
2691
- setState(updater);
2692
- options.onStateChange == null || options.onStateChange(updater);
2693
- }
2694
- }));
2695
- return tableRef.current;
2696
- }
15
+ var React__default = /*#__PURE__*/_interopDefault(React);
16
+ var classnames__default = /*#__PURE__*/_interopDefault(classnames);
17
+
18
+ // src/object-table/ObjectTable.tsx
2697
19
  function useColumnDefs(objectType, columnDefinitions) {
2698
20
  const {
2699
21
  metadata,
2700
22
  loading,
2701
23
  error
2702
24
  } = react.useOsdkMetadata(objectType);
2703
- const columns = React2.useMemo(() => {
25
+ const columns = React.useMemo(() => {
2704
26
  const objectProperties = metadata?.properties;
2705
27
  if (columnDefinitions) {
2706
28
  return getColumnsFromColumnDefinitions(columnDefinitions, objectProperties);
@@ -2759,7 +81,7 @@ function getDefaultColumns(objectProperties) {
2759
81
  var useDefaultTableStates = ({
2760
82
  columnDefinitions
2761
83
  }) => {
2762
- const columnVisibility = React2.useMemo(() => {
84
+ const columnVisibility = React.useMemo(() => {
2763
85
  if (columnDefinitions) {
2764
86
  const colVisibility = columnDefinitions.reduce((acc, colDef) => {
2765
87
  if (colDef.isVisible !== void 0) {
@@ -2782,8 +104,8 @@ var useDefaultTableStates = ({
2782
104
  };
2783
105
  };
2784
106
  var PAGE_SIZE = 50;
2785
- function useObjectTableData(objectSet, columnDefinitions) {
2786
- const withProperties = React2.useMemo(() => {
107
+ function useObjectTableData(objectSet, columnDefinitions, filter) {
108
+ const withProperties = React.useMemo(() => {
2787
109
  if (!columnDefinitions) {
2788
110
  return;
2789
111
  }
@@ -2799,888 +121,345 @@ function useObjectTableData(objectSet, columnDefinitions) {
2799
121
  }, [columnDefinitions]);
2800
122
  return experimental.useObjectSet(objectSet, {
2801
123
  withProperties,
2802
- pageSize: PAGE_SIZE
124
+ pageSize: PAGE_SIZE,
125
+ where: filter
2803
126
  });
2804
127
  }
2805
128
 
2806
- // ../../node_modules/.pnpm/@tanstack+virtual-core@3.13.17/node_modules/@tanstack/virtual-core/dist/esm/utils.js
2807
- function memo2(getDeps, fn, opts) {
2808
- let deps = opts.initialDeps ?? [];
2809
- let result;
2810
- let isInitial = true;
2811
- function memoizedFunction() {
2812
- var _a, _b, _c;
2813
- let depTime;
2814
- if (opts.key && ((_a = opts.debug) == null ? void 0 : _a.call(opts))) depTime = Date.now();
2815
- const newDeps = getDeps();
2816
- const depsChanged = newDeps.length !== deps.length || newDeps.some((dep, index) => deps[index] !== dep);
2817
- if (!depsChanged) {
2818
- return result;
2819
- }
2820
- deps = newDeps;
2821
- let resultTime;
2822
- if (opts.key && ((_b = opts.debug) == null ? void 0 : _b.call(opts))) resultTime = Date.now();
2823
- result = fn(...newDeps);
2824
- if (opts.key && ((_c = opts.debug) == null ? void 0 : _c.call(opts))) {
2825
- const depEndTime = Math.round((Date.now() - depTime) * 100) / 100;
2826
- const resultEndTime = Math.round((Date.now() - resultTime) * 100) / 100;
2827
- const resultFpsPercentage = resultEndTime / 16;
2828
- const pad = (str, num) => {
2829
- str = String(str);
2830
- while (str.length < num) {
2831
- str = " " + str;
2832
- }
2833
- return str;
2834
- };
2835
- console.info(`%c\u23F1 ${pad(resultEndTime, 5)} /${pad(depEndTime, 5)} ms`, `
2836
- font-size: .6rem;
2837
- font-weight: bold;
2838
- color: hsl(${Math.max(0, Math.min(120 - 120 * resultFpsPercentage, 120))}deg 100% 31%);`, opts == null ? void 0 : opts.key);
2839
- }
2840
- if ((opts == null ? void 0 : opts.onChange) && !(isInitial && opts.skipInitialOnChange)) {
2841
- opts.onChange(result);
2842
- }
2843
- isInitial = false;
2844
- return result;
2845
- }
2846
- memoizedFunction.updateDeps = (newDeps) => {
2847
- deps = newDeps;
2848
- };
2849
- return memoizedFunction;
2850
- }
2851
- function notUndefined(value, msg) {
2852
- if (value === void 0) {
2853
- throw new Error(`Unexpected undefined${""}`);
2854
- } else {
2855
- return value;
2856
- }
2857
- }
2858
- var approxEqual = (a, b) => Math.abs(a - b) < 1.01;
2859
- var debounce = (targetWindow, fn, ms) => {
2860
- let timeoutId;
2861
- return function(...args) {
2862
- targetWindow.clearTimeout(timeoutId);
2863
- timeoutId = targetWindow.setTimeout(() => fn.apply(this, args), ms);
2864
- };
129
+ // src/object-table/utils/getRowId.ts
130
+ var getRowId = (row) => {
131
+ return getRowIdFromPrimaryKey(row.$primaryKey);
2865
132
  };
133
+ var getRowIdFromPrimaryKey = (primaryKey) => primaryKey.toString();
2866
134
 
2867
- // ../../node_modules/.pnpm/@tanstack+virtual-core@3.13.17/node_modules/@tanstack/virtual-core/dist/esm/index.js
2868
- var getRect = (element) => {
2869
- const {
2870
- offsetWidth,
2871
- offsetHeight
2872
- } = element;
2873
- return {
2874
- width: offsetWidth,
2875
- height: offsetHeight
2876
- };
2877
- };
2878
- var defaultKeyExtractor = (index) => index;
2879
- var defaultRangeExtractor = (range) => {
2880
- const start = Math.max(range.startIndex - range.overscan, 0);
2881
- const end = Math.min(range.endIndex + range.overscan, range.count - 1);
2882
- const arr = [];
2883
- for (let i = start; i <= end; i++) {
2884
- arr.push(i);
2885
- }
2886
- return arr;
2887
- };
2888
- var observeElementRect = (instance, cb) => {
2889
- const element = instance.scrollElement;
2890
- if (!element) {
2891
- return;
2892
- }
2893
- const targetWindow = instance.targetWindow;
2894
- if (!targetWindow) {
2895
- return;
2896
- }
2897
- const handler = (rect) => {
2898
- const {
2899
- width,
2900
- height
2901
- } = rect;
2902
- cb({
2903
- width: Math.round(width),
2904
- height: Math.round(height)
2905
- });
2906
- };
2907
- handler(getRect(element));
2908
- if (!targetWindow.ResizeObserver) {
2909
- return () => {
2910
- };
2911
- }
2912
- const observer = new targetWindow.ResizeObserver((entries) => {
2913
- const run = () => {
2914
- const entry = entries[0];
2915
- if (entry == null ? void 0 : entry.borderBoxSize) {
2916
- const box = entry.borderBoxSize[0];
2917
- if (box) {
2918
- handler({
2919
- width: box.inlineSize,
2920
- height: box.blockSize
2921
- });
2922
- return;
2923
- }
2924
- }
2925
- handler(getRect(element));
2926
- };
2927
- instance.options.useAnimationFrameWithResizeObserver ? requestAnimationFrame(run) : run();
2928
- });
2929
- observer.observe(element, {
2930
- box: "border-box"
2931
- });
2932
- return () => {
2933
- observer.unobserve(element);
2934
- };
2935
- };
2936
- var addEventListenerOptions = {
2937
- passive: true
2938
- };
2939
- var supportsScrollend = typeof window == "undefined" ? true : "onscrollend" in window;
2940
- var observeElementOffset = (instance, cb) => {
2941
- const element = instance.scrollElement;
2942
- if (!element) {
2943
- return;
2944
- }
2945
- const targetWindow = instance.targetWindow;
2946
- if (!targetWindow) {
2947
- return;
2948
- }
2949
- let offset = 0;
2950
- const fallback = instance.options.useScrollendEvent && supportsScrollend ? () => void 0 : debounce(targetWindow, () => {
2951
- cb(offset, false);
2952
- }, instance.options.isScrollingResetDelay);
2953
- const createHandler = (isScrolling) => () => {
2954
- const {
2955
- horizontal,
2956
- isRtl
2957
- } = instance.options;
2958
- offset = horizontal ? element["scrollLeft"] * (isRtl && -1 || 1) : element["scrollTop"];
2959
- fallback();
2960
- cb(offset, isScrolling);
2961
- };
2962
- const handler = createHandler(true);
2963
- const endHandler = createHandler(false);
2964
- element.addEventListener("scroll", handler, addEventListenerOptions);
2965
- const registerScrollendEvent = instance.options.useScrollendEvent && supportsScrollend;
2966
- if (registerScrollendEvent) {
2967
- element.addEventListener("scrollend", endHandler, addEventListenerOptions);
2968
- }
2969
- return () => {
2970
- element.removeEventListener("scroll", handler);
2971
- if (registerScrollendEvent) {
2972
- element.removeEventListener("scrollend", endHandler);
2973
- }
2974
- };
2975
- };
2976
- var measureElement = (element, entry, instance) => {
2977
- if (entry == null ? void 0 : entry.borderBoxSize) {
2978
- const box = entry.borderBoxSize[0];
2979
- if (box) {
2980
- const size = Math.round(box[instance.options.horizontal ? "inlineSize" : "blockSize"]);
2981
- return size;
2982
- }
2983
- }
2984
- return element[instance.options.horizontal ? "offsetWidth" : "offsetHeight"];
2985
- };
2986
- var elementScroll = (offset, {
2987
- adjustments = 0,
2988
- behavior
2989
- }, instance) => {
2990
- var _a, _b;
2991
- const toOffset = offset + adjustments;
2992
- (_b = (_a = instance.scrollElement) == null ? void 0 : _a.scrollTo) == null ? void 0 : _b.call(_a, {
2993
- [instance.options.horizontal ? "left" : "top"]: toOffset,
2994
- behavior
2995
- });
2996
- };
2997
- var Virtualizer = class {
2998
- constructor(opts) {
2999
- this.unsubs = [];
3000
- this.scrollElement = null;
3001
- this.targetWindow = null;
3002
- this.isScrolling = false;
3003
- this.currentScrollToIndex = null;
3004
- this.measurementsCache = [];
3005
- this.itemSizeCache = /* @__PURE__ */ new Map();
3006
- this.laneAssignments = /* @__PURE__ */ new Map();
3007
- this.pendingMeasuredCacheIndexes = [];
3008
- this.prevLanes = void 0;
3009
- this.lanesChangedFlag = false;
3010
- this.lanesSettling = false;
3011
- this.scrollRect = null;
3012
- this.scrollOffset = null;
3013
- this.scrollDirection = null;
3014
- this.scrollAdjustments = 0;
3015
- this.elementsCache = /* @__PURE__ */ new Map();
3016
- this.observer = /* @__PURE__ */ (() => {
3017
- let _ro = null;
3018
- const get = () => {
3019
- if (_ro) {
3020
- return _ro;
3021
- }
3022
- if (!this.targetWindow || !this.targetWindow.ResizeObserver) {
3023
- return null;
3024
- }
3025
- return _ro = new this.targetWindow.ResizeObserver((entries) => {
3026
- entries.forEach((entry) => {
3027
- const run = () => {
3028
- this._measureElement(entry.target, entry);
3029
- };
3030
- this.options.useAnimationFrameWithResizeObserver ? requestAnimationFrame(run) : run();
3031
- });
3032
- });
3033
- };
3034
- return {
3035
- disconnect: () => {
3036
- var _a;
3037
- (_a = get()) == null ? void 0 : _a.disconnect();
3038
- _ro = null;
3039
- },
3040
- observe: (target) => {
3041
- var _a;
3042
- return (_a = get()) == null ? void 0 : _a.observe(target, {
3043
- box: "border-box"
3044
- });
3045
- },
3046
- unobserve: (target) => {
3047
- var _a;
3048
- return (_a = get()) == null ? void 0 : _a.unobserve(target);
3049
- }
3050
- };
3051
- })();
3052
- this.range = null;
3053
- this.setOptions = (opts2) => {
3054
- Object.entries(opts2).forEach(([key, value]) => {
3055
- if (typeof value === "undefined") delete opts2[key];
3056
- });
3057
- this.options = {
3058
- debug: false,
3059
- initialOffset: 0,
3060
- overscan: 1,
3061
- paddingStart: 0,
3062
- paddingEnd: 0,
3063
- scrollPaddingStart: 0,
3064
- scrollPaddingEnd: 0,
3065
- horizontal: false,
3066
- getItemKey: defaultKeyExtractor,
3067
- rangeExtractor: defaultRangeExtractor,
3068
- onChange: () => {
3069
- },
3070
- measureElement,
3071
- initialRect: {
3072
- width: 0,
3073
- height: 0
3074
- },
3075
- scrollMargin: 0,
3076
- gap: 0,
3077
- indexAttribute: "data-index",
3078
- initialMeasurementsCache: [],
3079
- lanes: 1,
3080
- isScrollingResetDelay: 150,
3081
- enabled: true,
3082
- isRtl: false,
3083
- useScrollendEvent: false,
3084
- useAnimationFrameWithResizeObserver: false,
3085
- ...opts2
3086
- };
3087
- };
3088
- this.notify = (sync) => {
3089
- var _a, _b;
3090
- (_b = (_a = this.options).onChange) == null ? void 0 : _b.call(_a, this, sync);
3091
- };
3092
- this.maybeNotify = memo2(() => {
3093
- this.calculateRange();
3094
- return [this.isScrolling, this.range ? this.range.startIndex : null, this.range ? this.range.endIndex : null];
3095
- }, (isScrolling) => {
3096
- this.notify(isScrolling);
3097
- }, {
3098
- key: process.env.NODE_ENV !== "production" && "maybeNotify",
3099
- debug: () => this.options.debug,
3100
- initialDeps: [this.isScrolling, this.range ? this.range.startIndex : null, this.range ? this.range.endIndex : null]
3101
- });
3102
- this.cleanup = () => {
3103
- this.unsubs.filter(Boolean).forEach((d) => d());
3104
- this.unsubs = [];
3105
- this.observer.disconnect();
3106
- this.scrollElement = null;
3107
- this.targetWindow = null;
3108
- };
3109
- this._didMount = () => {
3110
- return () => {
3111
- this.cleanup();
3112
- };
3113
- };
3114
- this._willUpdate = () => {
3115
- var _a;
3116
- const scrollElement = this.options.enabled ? this.options.getScrollElement() : null;
3117
- if (this.scrollElement !== scrollElement) {
3118
- this.cleanup();
3119
- if (!scrollElement) {
3120
- this.maybeNotify();
3121
- return;
3122
- }
3123
- this.scrollElement = scrollElement;
3124
- if (this.scrollElement && "ownerDocument" in this.scrollElement) {
3125
- this.targetWindow = this.scrollElement.ownerDocument.defaultView;
3126
- } else {
3127
- this.targetWindow = ((_a = this.scrollElement) == null ? void 0 : _a.window) ?? null;
3128
- }
3129
- this.elementsCache.forEach((cached) => {
3130
- this.observer.observe(cached);
3131
- });
3132
- this.unsubs.push(this.options.observeElementRect(this, (rect) => {
3133
- this.scrollRect = rect;
3134
- this.maybeNotify();
3135
- }));
3136
- this.unsubs.push(this.options.observeElementOffset(this, (offset, isScrolling) => {
3137
- this.scrollAdjustments = 0;
3138
- this.scrollDirection = isScrolling ? this.getScrollOffset() < offset ? "forward" : "backward" : null;
3139
- this.scrollOffset = offset;
3140
- this.isScrolling = isScrolling;
3141
- this.maybeNotify();
3142
- }));
3143
- this._scrollToOffset(this.getScrollOffset(), {
3144
- adjustments: void 0,
3145
- behavior: void 0
3146
- });
3147
- }
3148
- };
3149
- this.getSize = () => {
3150
- if (!this.options.enabled) {
3151
- this.scrollRect = null;
3152
- return 0;
3153
- }
3154
- this.scrollRect = this.scrollRect ?? this.options.initialRect;
3155
- return this.scrollRect[this.options.horizontal ? "width" : "height"];
3156
- };
3157
- this.getScrollOffset = () => {
3158
- if (!this.options.enabled) {
3159
- this.scrollOffset = null;
3160
- return 0;
3161
- }
3162
- this.scrollOffset = this.scrollOffset ?? (typeof this.options.initialOffset === "function" ? this.options.initialOffset() : this.options.initialOffset);
3163
- return this.scrollOffset;
3164
- };
3165
- this.getFurthestMeasurement = (measurements, index) => {
3166
- const furthestMeasurementsFound = /* @__PURE__ */ new Map();
3167
- const furthestMeasurements = /* @__PURE__ */ new Map();
3168
- for (let m = index - 1; m >= 0; m--) {
3169
- const measurement = measurements[m];
3170
- if (furthestMeasurementsFound.has(measurement.lane)) {
3171
- continue;
3172
- }
3173
- const previousFurthestMeasurement = furthestMeasurements.get(measurement.lane);
3174
- if (previousFurthestMeasurement == null || measurement.end > previousFurthestMeasurement.end) {
3175
- furthestMeasurements.set(measurement.lane, measurement);
3176
- } else if (measurement.end < previousFurthestMeasurement.end) {
3177
- furthestMeasurementsFound.set(measurement.lane, true);
3178
- }
3179
- if (furthestMeasurementsFound.size === this.options.lanes) {
3180
- break;
3181
- }
3182
- }
3183
- return furthestMeasurements.size === this.options.lanes ? Array.from(furthestMeasurements.values()).sort((a, b) => {
3184
- if (a.end === b.end) {
3185
- return a.index - b.index;
3186
- }
3187
- return a.end - b.end;
3188
- })[0] : void 0;
3189
- };
3190
- this.getMeasurementOptions = memo2(() => [this.options.count, this.options.paddingStart, this.options.scrollMargin, this.options.getItemKey, this.options.enabled, this.options.lanes], (count2, paddingStart, scrollMargin, getItemKey, enabled, lanes) => {
3191
- const lanesChanged = this.prevLanes !== void 0 && this.prevLanes !== lanes;
3192
- if (lanesChanged) {
3193
- this.lanesChangedFlag = true;
3194
- }
3195
- this.prevLanes = lanes;
3196
- this.pendingMeasuredCacheIndexes = [];
3197
- return {
3198
- count: count2,
3199
- paddingStart,
3200
- scrollMargin,
3201
- getItemKey,
3202
- enabled,
3203
- lanes
3204
- };
3205
- }, {
3206
- key: false,
3207
- skipInitialOnChange: true,
3208
- onChange: () => {
3209
- this.notify(this.isScrolling);
3210
- }
3211
- });
3212
- this.getMeasurements = memo2(() => [this.getMeasurementOptions(), this.itemSizeCache], ({
3213
- count: count2,
3214
- paddingStart,
3215
- scrollMargin,
3216
- getItemKey,
3217
- enabled,
3218
- lanes
3219
- }, itemSizeCache) => {
3220
- if (!enabled) {
3221
- this.measurementsCache = [];
3222
- this.itemSizeCache.clear();
3223
- this.laneAssignments.clear();
3224
- return [];
3225
- }
3226
- if (this.laneAssignments.size > count2) {
3227
- for (const index of this.laneAssignments.keys()) {
3228
- if (index >= count2) {
3229
- this.laneAssignments.delete(index);
3230
- }
3231
- }
3232
- }
3233
- if (this.lanesChangedFlag) {
3234
- this.lanesChangedFlag = false;
3235
- this.lanesSettling = true;
3236
- this.measurementsCache = [];
3237
- this.itemSizeCache.clear();
3238
- this.laneAssignments.clear();
3239
- this.pendingMeasuredCacheIndexes = [];
3240
- }
3241
- if (this.measurementsCache.length === 0 && !this.lanesSettling) {
3242
- this.measurementsCache = this.options.initialMeasurementsCache;
3243
- this.measurementsCache.forEach((item) => {
3244
- this.itemSizeCache.set(item.key, item.size);
3245
- });
3246
- }
3247
- const min2 = this.lanesSettling ? 0 : this.pendingMeasuredCacheIndexes.length > 0 ? Math.min(...this.pendingMeasuredCacheIndexes) : 0;
3248
- this.pendingMeasuredCacheIndexes = [];
3249
- if (this.lanesSettling && this.measurementsCache.length === count2) {
3250
- this.lanesSettling = false;
3251
- }
3252
- const measurements = this.measurementsCache.slice(0, min2);
3253
- const laneLastIndex = new Array(lanes).fill(void 0);
3254
- for (let m = 0; m < min2; m++) {
3255
- const item = measurements[m];
3256
- if (item) {
3257
- laneLastIndex[item.lane] = m;
3258
- }
3259
- }
3260
- for (let i = min2; i < count2; i++) {
3261
- const key = getItemKey(i);
3262
- const cachedLane = this.laneAssignments.get(i);
3263
- let lane;
3264
- let start;
3265
- if (cachedLane !== void 0 && this.options.lanes > 1) {
3266
- lane = cachedLane;
3267
- const prevIndex = laneLastIndex[lane];
3268
- const prevInLane = prevIndex !== void 0 ? measurements[prevIndex] : void 0;
3269
- start = prevInLane ? prevInLane.end + this.options.gap : paddingStart + scrollMargin;
3270
- } else {
3271
- const furthestMeasurement = this.options.lanes === 1 ? measurements[i - 1] : this.getFurthestMeasurement(measurements, i);
3272
- start = furthestMeasurement ? furthestMeasurement.end + this.options.gap : paddingStart + scrollMargin;
3273
- lane = furthestMeasurement ? furthestMeasurement.lane : i % this.options.lanes;
3274
- if (this.options.lanes > 1) {
3275
- this.laneAssignments.set(i, lane);
3276
- }
3277
- }
3278
- const measuredSize = itemSizeCache.get(key);
3279
- const size = typeof measuredSize === "number" ? measuredSize : this.options.estimateSize(i);
3280
- const end = start + size;
3281
- measurements[i] = {
3282
- index: i,
3283
- start,
3284
- size,
3285
- end,
3286
- key,
3287
- lane
3288
- };
3289
- laneLastIndex[lane] = i;
3290
- }
3291
- this.measurementsCache = measurements;
3292
- return measurements;
3293
- }, {
3294
- key: process.env.NODE_ENV !== "production" && "getMeasurements",
3295
- debug: () => this.options.debug
3296
- });
3297
- this.calculateRange = memo2(() => [this.getMeasurements(), this.getSize(), this.getScrollOffset(), this.options.lanes], (measurements, outerSize, scrollOffset, lanes) => {
3298
- return this.range = measurements.length > 0 && outerSize > 0 ? calculateRange({
3299
- measurements,
3300
- outerSize,
3301
- scrollOffset,
3302
- lanes
3303
- }) : null;
3304
- }, {
3305
- key: process.env.NODE_ENV !== "production" && "calculateRange",
3306
- debug: () => this.options.debug
3307
- });
3308
- this.getVirtualIndexes = memo2(() => {
3309
- let startIndex = null;
3310
- let endIndex = null;
3311
- const range = this.calculateRange();
3312
- if (range) {
3313
- startIndex = range.startIndex;
3314
- endIndex = range.endIndex;
3315
- }
3316
- this.maybeNotify.updateDeps([this.isScrolling, startIndex, endIndex]);
3317
- return [this.options.rangeExtractor, this.options.overscan, this.options.count, startIndex, endIndex];
3318
- }, (rangeExtractor, overscan, count2, startIndex, endIndex) => {
3319
- return startIndex === null || endIndex === null ? [] : rangeExtractor({
3320
- startIndex,
3321
- endIndex,
3322
- overscan,
3323
- count: count2
135
+ // src/object-table/hooks/useRowSelection.ts
136
+ function useRowSelection({
137
+ selectionMode = "none",
138
+ selectedRows,
139
+ onRowSelection,
140
+ data
141
+ }) {
142
+ const [internalRowSelection, setInternalRowSelection] = React.useState({});
143
+ const [lastSelectedRowIndex, setLastSelectedRowIndex] = React.useState(null);
144
+ const isControlled = selectedRows !== void 0;
145
+ const isSelectionEnabled = selectionMode !== "none";
146
+ const rowSelectionState = React.useMemo(() => {
147
+ if (!isSelectionEnabled) return {};
148
+ if (isControlled && selectedRows) {
149
+ return getRowSelectionState(selectedRows);
150
+ }
151
+ return internalRowSelection;
152
+ }, [isSelectionEnabled, isControlled, selectedRows, internalRowSelection]);
153
+ const selectedCount = Object.values(rowSelectionState).filter(Boolean).length;
154
+ const totalCount = data?.length ?? 0;
155
+ const isAllSelected = totalCount > 0 && selectedCount === totalCount;
156
+ const hasSelection = selectedCount > 0;
157
+ const onToggleAll = React.useCallback(() => {
158
+ if (!isSelectionEnabled || !data) return;
159
+ const newSelectedRows = isAllSelected ? [] : data.map((item) => item.$primaryKey);
160
+ if (!isControlled) {
161
+ setInternalRowSelection(getRowSelectionState(newSelectedRows));
162
+ }
163
+ onRowSelection?.(newSelectedRows);
164
+ }, [isSelectionEnabled, data, isAllSelected, isControlled, onRowSelection]);
165
+ const onToggleRow = React.useCallback((rowId, rowIndex, isShiftClick = false) => {
166
+ if (!isSelectionEnabled || !data) return;
167
+ let newSelectedRows = [];
168
+ if (selectionMode === "single") {
169
+ newSelectedRows = getSingleSelectionRows({
170
+ rowId,
171
+ rowIndex,
172
+ data,
173
+ rowSelectionState
3324
174
  });
3325
- }, {
3326
- key: process.env.NODE_ENV !== "production" && "getVirtualIndexes",
3327
- debug: () => this.options.debug
3328
- });
3329
- this.indexFromElement = (node) => {
3330
- const attributeName = this.options.indexAttribute;
3331
- const indexStr = node.getAttribute(attributeName);
3332
- if (!indexStr) {
3333
- console.warn(`Missing attribute name '${attributeName}={index}' on measured element.`);
3334
- return -1;
3335
- }
3336
- return parseInt(indexStr, 10);
3337
- };
3338
- this._measureElement = (node, entry) => {
3339
- const index = this.indexFromElement(node);
3340
- const item = this.measurementsCache[index];
3341
- if (!item) {
3342
- return;
3343
- }
3344
- const key = item.key;
3345
- const prevNode = this.elementsCache.get(key);
3346
- if (prevNode !== node) {
3347
- if (prevNode) {
3348
- this.observer.unobserve(prevNode);
3349
- }
3350
- this.observer.observe(node);
3351
- this.elementsCache.set(key, node);
3352
- }
3353
- if (node.isConnected) {
3354
- this.resizeItem(index, this.options.measureElement(node, entry, this));
3355
- }
3356
- };
3357
- this.resizeItem = (index, size) => {
3358
- const item = this.measurementsCache[index];
3359
- if (!item) {
3360
- return;
3361
- }
3362
- const itemSize = this.itemSizeCache.get(item.key) ?? item.size;
3363
- const delta = size - itemSize;
3364
- if (delta !== 0) {
3365
- if (this.shouldAdjustScrollPositionOnItemSizeChange !== void 0 ? this.shouldAdjustScrollPositionOnItemSizeChange(item, delta, this) : item.start < this.getScrollOffset() + this.scrollAdjustments) {
3366
- if (process.env.NODE_ENV !== "production" && this.options.debug) {
3367
- console.info("correction", delta);
3368
- }
3369
- this._scrollToOffset(this.getScrollOffset(), {
3370
- adjustments: this.scrollAdjustments += delta,
3371
- behavior: void 0
3372
- });
3373
- }
3374
- this.pendingMeasuredCacheIndexes.push(item.index);
3375
- this.itemSizeCache = new Map(this.itemSizeCache.set(item.key, size));
3376
- this.notify(false);
3377
- }
3378
- };
3379
- this.measureElement = (node) => {
3380
- if (!node) {
3381
- this.elementsCache.forEach((cached, key) => {
3382
- if (!cached.isConnected) {
3383
- this.observer.unobserve(cached);
3384
- this.elementsCache.delete(key);
3385
- }
175
+ setLastSelectedRowIndex(rowIndex);
176
+ } else {
177
+ if (isShiftClick && lastSelectedRowIndex != null) {
178
+ newSelectedRows = getRangeSelectionRows({
179
+ rowIndex,
180
+ data,
181
+ lastSelectedRowIndex,
182
+ rowSelectionState
3386
183
  });
3387
- return;
3388
- }
3389
- this._measureElement(node, void 0);
3390
- };
3391
- this.getVirtualItems = memo2(() => [this.getVirtualIndexes(), this.getMeasurements()], (indexes, measurements) => {
3392
- const virtualItems = [];
3393
- for (let k = 0, len = indexes.length; k < len; k++) {
3394
- const i = indexes[k];
3395
- const measurement = measurements[i];
3396
- virtualItems.push(measurement);
3397
- }
3398
- return virtualItems;
3399
- }, {
3400
- key: process.env.NODE_ENV !== "production" && "getVirtualItems",
3401
- debug: () => this.options.debug
3402
- });
3403
- this.getVirtualItemForOffset = (offset) => {
3404
- const measurements = this.getMeasurements();
3405
- if (measurements.length === 0) {
3406
- return void 0;
3407
- }
3408
- return notUndefined(measurements[findNearestBinarySearch(0, measurements.length - 1, (index) => notUndefined(measurements[index]).start, offset)]);
3409
- };
3410
- this.getMaxScrollOffset = () => {
3411
- if (!this.scrollElement) return 0;
3412
- if ("scrollHeight" in this.scrollElement) {
3413
- return this.options.horizontal ? this.scrollElement.scrollWidth - this.scrollElement.clientWidth : this.scrollElement.scrollHeight - this.scrollElement.clientHeight;
3414
184
  } else {
3415
- const doc = this.scrollElement.document.documentElement;
3416
- return this.options.horizontal ? doc.scrollWidth - this.scrollElement.innerWidth : doc.scrollHeight - this.scrollElement.innerHeight;
3417
- }
3418
- };
3419
- this.getOffsetForAlignment = (toOffset, align, itemSize = 0) => {
3420
- if (!this.scrollElement) return 0;
3421
- const size = this.getSize();
3422
- const scrollOffset = this.getScrollOffset();
3423
- if (align === "auto") {
3424
- align = toOffset >= scrollOffset + size ? "end" : "start";
3425
- }
3426
- if (align === "center") {
3427
- toOffset += (itemSize - size) / 2;
3428
- } else if (align === "end") {
3429
- toOffset -= size;
3430
- }
3431
- const maxOffset = this.getMaxScrollOffset();
3432
- return Math.max(Math.min(maxOffset, toOffset), 0);
3433
- };
3434
- this.getOffsetForIndex = (index, align = "auto") => {
3435
- index = Math.max(0, Math.min(index, this.options.count - 1));
3436
- const item = this.measurementsCache[index];
3437
- if (!item) {
3438
- return void 0;
3439
- }
3440
- const size = this.getSize();
3441
- const scrollOffset = this.getScrollOffset();
3442
- if (align === "auto") {
3443
- if (item.end >= scrollOffset + size - this.options.scrollPaddingEnd) {
3444
- align = "end";
3445
- } else if (item.start <= scrollOffset + this.options.scrollPaddingStart) {
3446
- align = "start";
3447
- } else {
3448
- return [scrollOffset, align];
3449
- }
3450
- }
3451
- if (align === "end" && index === this.options.count - 1) {
3452
- return [this.getMaxScrollOffset(), align];
3453
- }
3454
- const toOffset = align === "end" ? item.end + this.options.scrollPaddingEnd : item.start - this.options.scrollPaddingStart;
3455
- return [this.getOffsetForAlignment(toOffset, align, item.size), align];
3456
- };
3457
- this.isDynamicMode = () => this.elementsCache.size > 0;
3458
- this.scrollToOffset = (toOffset, {
3459
- align = "start",
3460
- behavior
3461
- } = {}) => {
3462
- if (behavior === "smooth" && this.isDynamicMode()) {
3463
- console.warn("The `smooth` scroll behavior is not fully supported with dynamic size.");
3464
- }
3465
- this._scrollToOffset(this.getOffsetForAlignment(toOffset, align), {
3466
- adjustments: void 0,
3467
- behavior
3468
- });
3469
- };
3470
- this.scrollToIndex = (index, {
3471
- align: initialAlign = "auto",
3472
- behavior
3473
- } = {}) => {
3474
- if (behavior === "smooth" && this.isDynamicMode()) {
3475
- console.warn("The `smooth` scroll behavior is not fully supported with dynamic size.");
3476
- }
3477
- index = Math.max(0, Math.min(index, this.options.count - 1));
3478
- this.currentScrollToIndex = index;
3479
- let attempts = 0;
3480
- const maxAttempts = 10;
3481
- const tryScroll = (currentAlign) => {
3482
- if (!this.targetWindow) return;
3483
- const offsetInfo = this.getOffsetForIndex(index, currentAlign);
3484
- if (!offsetInfo) {
3485
- console.warn("Failed to get offset for index:", index);
3486
- return;
3487
- }
3488
- const [offset, align] = offsetInfo;
3489
- this._scrollToOffset(offset, {
3490
- adjustments: void 0,
3491
- behavior
3492
- });
3493
- this.targetWindow.requestAnimationFrame(() => {
3494
- const verify = () => {
3495
- if (this.currentScrollToIndex !== index) return;
3496
- const currentOffset = this.getScrollOffset();
3497
- const afterInfo = this.getOffsetForIndex(index, align);
3498
- if (!afterInfo) {
3499
- console.warn("Failed to get offset for index:", index);
3500
- return;
3501
- }
3502
- if (!approxEqual(afterInfo[0], currentOffset)) {
3503
- scheduleRetry(align);
3504
- }
3505
- };
3506
- if (this.isDynamicMode()) {
3507
- this.targetWindow.requestAnimationFrame(verify);
3508
- } else {
3509
- verify();
3510
- }
185
+ newSelectedRows = getMultipleSelectionRows({
186
+ rowIndex,
187
+ data,
188
+ rowSelectionState
3511
189
  });
3512
- };
3513
- const scheduleRetry = (align) => {
3514
- if (!this.targetWindow) return;
3515
- if (this.currentScrollToIndex !== index) return;
3516
- attempts++;
3517
- if (attempts < maxAttempts) {
3518
- if (process.env.NODE_ENV !== "production" && this.options.debug) {
3519
- console.info("Schedule retry", attempts, maxAttempts);
3520
- }
3521
- this.targetWindow.requestAnimationFrame(() => tryScroll(align));
3522
- } else {
3523
- console.warn(`Failed to scroll to index ${index} after ${maxAttempts} attempts.`);
3524
- }
3525
- };
3526
- tryScroll(initialAlign);
3527
- };
3528
- this.scrollBy = (delta, {
3529
- behavior
3530
- } = {}) => {
3531
- if (behavior === "smooth" && this.isDynamicMode()) {
3532
- console.warn("The `smooth` scroll behavior is not fully supported with dynamic size.");
3533
190
  }
3534
- this._scrollToOffset(this.getScrollOffset() + delta, {
3535
- adjustments: void 0,
3536
- behavior
3537
- });
3538
- };
3539
- this.getTotalSize = () => {
3540
- var _a;
3541
- const measurements = this.getMeasurements();
3542
- let end;
3543
- if (measurements.length === 0) {
3544
- end = this.options.paddingStart;
3545
- } else if (this.options.lanes === 1) {
3546
- end = ((_a = measurements[measurements.length - 1]) == null ? void 0 : _a.end) ?? 0;
3547
- } else {
3548
- const endByLane = Array(this.options.lanes).fill(null);
3549
- let endIndex = measurements.length - 1;
3550
- while (endIndex >= 0 && endByLane.some((val) => val === null)) {
3551
- const item = measurements[endIndex];
3552
- if (endByLane[item.lane] === null) {
3553
- endByLane[item.lane] = item.end;
3554
- }
3555
- endIndex--;
3556
- }
3557
- end = Math.max(...endByLane.filter((val) => val !== null));
191
+ setLastSelectedRowIndex(rowIndex);
192
+ }
193
+ if (!isControlled) {
194
+ setInternalRowSelection(getRowSelectionState(newSelectedRows));
195
+ }
196
+ onRowSelection?.(newSelectedRows);
197
+ }, [isSelectionEnabled, data, selectionMode, lastSelectedRowIndex, isControlled, rowSelectionState, onRowSelection]);
198
+ return {
199
+ rowSelection: rowSelectionState,
200
+ isAllSelected,
201
+ hasSelection,
202
+ onToggleAll,
203
+ onToggleRow
204
+ };
205
+ }
206
+ function getSingleSelectionRows({
207
+ rowId,
208
+ rowIndex,
209
+ data,
210
+ rowSelectionState
211
+ }) {
212
+ const primaryKey = data[rowIndex].$primaryKey;
213
+ const newSelectedRows = rowSelectionState[rowId] ? [] : [primaryKey];
214
+ return newSelectedRows;
215
+ }
216
+ function getRangeSelectionRows({
217
+ lastSelectedRowIndex,
218
+ rowIndex,
219
+ data,
220
+ rowSelectionState
221
+ }) {
222
+ if (lastSelectedRowIndex != null) {
223
+ const rowsInRange = getRowsInRange(data, lastSelectedRowIndex, rowIndex);
224
+ const primaryKeysInRange = rowsInRange.map((item) => item.$primaryKey);
225
+ const currentlySelected = getSelectedPrimaryKeys(rowSelectionState, data);
226
+ const newSelectedRows = [...currentlySelected];
227
+ primaryKeysInRange.forEach((item) => {
228
+ if (!newSelectedRows.includes(item)) {
229
+ newSelectedRows.push(item);
3558
230
  }
3559
- return Math.max(end - this.options.scrollMargin + this.options.paddingEnd, 0);
3560
- };
3561
- this._scrollToOffset = (offset, {
3562
- adjustments,
3563
- behavior
3564
- }) => {
3565
- this.options.scrollToFn(offset, {
3566
- behavior,
3567
- adjustments
3568
- }, this);
3569
- };
3570
- this.measure = () => {
3571
- this.itemSizeCache = /* @__PURE__ */ new Map();
3572
- this.laneAssignments = /* @__PURE__ */ new Map();
3573
- this.notify(false);
3574
- };
3575
- this.setOptions(opts);
231
+ });
232
+ return newSelectedRows;
3576
233
  }
3577
- };
3578
- var findNearestBinarySearch = (low, high, getCurrentValue, value) => {
3579
- while (low <= high) {
3580
- const middle = (low + high) / 2 | 0;
3581
- const currentValue = getCurrentValue(middle);
3582
- if (currentValue < value) {
3583
- low = middle + 1;
3584
- } else if (currentValue > value) {
3585
- high = middle - 1;
3586
- } else {
3587
- return middle;
234
+ return [];
235
+ }
236
+ function getMultipleSelectionRows({
237
+ rowIndex,
238
+ data,
239
+ rowSelectionState
240
+ }) {
241
+ const primaryKey = data[rowIndex].$primaryKey;
242
+ const currentlySelected = getSelectedPrimaryKeys(rowSelectionState, data);
243
+ const newSelectedRows = currentlySelected.includes(primaryKey) ? currentlySelected.filter((i) => i !== primaryKey) : [...currentlySelected, primaryKey];
244
+ return newSelectedRows;
245
+ }
246
+ function getRowsInRange(data, startIndex, endIndex) {
247
+ const start = Math.min(startIndex, endIndex);
248
+ const end = Math.max(startIndex, endIndex);
249
+ const rows = [];
250
+ for (let i = start; i <= end; i++) {
251
+ const item = data[i];
252
+ if (item) {
253
+ rows.push(item);
3588
254
  }
3589
255
  }
3590
- if (low > 0) {
3591
- return low - 1;
3592
- } else {
3593
- return 0;
3594
- }
3595
- };
3596
- function calculateRange({
3597
- measurements,
3598
- outerSize,
3599
- scrollOffset,
3600
- lanes
256
+ return rows;
257
+ }
258
+ function getRowSelectionState(primaryKeys) {
259
+ return primaryKeys.reduce((acc, primaryKey) => {
260
+ acc[getRowIdFromPrimaryKey(primaryKey)] = true;
261
+ return acc;
262
+ }, {});
263
+ }
264
+ function getSelectedPrimaryKeys(selectionState, data) {
265
+ return data.filter((item) => selectionState[getRowId(item)]).map((item) => item.$primaryKey);
266
+ }
267
+
268
+ // src/base-components/checkbox/Checkbox.module.css
269
+ var Checkbox_default = {};
270
+
271
+ // src/base-components/checkbox/Checkbox.tsx
272
+ function _extends() {
273
+ return _extends = Object.assign ? Object.assign.bind() : function(n) {
274
+ for (var e = 1; e < arguments.length; e++) {
275
+ var t = arguments[e];
276
+ for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
277
+ }
278
+ return n;
279
+ }, _extends.apply(null, arguments);
280
+ }
281
+ function Checkbox({
282
+ indeterminate,
283
+ className,
284
+ indicatorProps,
285
+ ...rest
286
+ }) {
287
+ return /* @__PURE__ */ React__default.default.createElement(checkbox.Checkbox.Root, _extends({
288
+ className: classnames__default.default(Checkbox_default.osdkCheckboxRoot, className),
289
+ indeterminate
290
+ }, rest), /* @__PURE__ */ React__default.default.createElement(checkbox.Checkbox.Indicator, _extends({}, indicatorProps, {
291
+ className: classnames__default.default(Checkbox_default.osdkCheckboxIndicator, indicatorProps?.className)
292
+ }), indeterminate ? /* @__PURE__ */ React__default.default.createElement(icons.Minus, {
293
+ color: "currentColor"
294
+ }) : /* @__PURE__ */ React__default.default.createElement(icons.Tick, {
295
+ color: "currentColor"
296
+ })));
297
+ }
298
+
299
+ // src/object-table/SelectionCells.tsx
300
+ function SelectionHeaderCell({
301
+ isAllSelected,
302
+ hasSelection,
303
+ onToggleAll
3601
304
  }) {
3602
- const lastIndex = measurements.length - 1;
3603
- const getOffset = (index) => measurements[index].start;
3604
- if (measurements.length <= lanes) {
305
+ return /* @__PURE__ */ React__default.default.createElement(Checkbox, {
306
+ indeterminate: hasSelection && !isAllSelected,
307
+ checked: isAllSelected,
308
+ onCheckedChange: onToggleAll,
309
+ "aria-label": "Select all rows"
310
+ });
311
+ }
312
+ function SelectionCell({
313
+ row,
314
+ onToggleRow
315
+ }) {
316
+ const handleClick = React.useCallback((event) => {
317
+ const isShiftClick = event.shiftKey;
318
+ onToggleRow(row.id, row.index, isShiftClick);
319
+ }, [row, onToggleRow]);
320
+ return /* @__PURE__ */ React__default.default.createElement(Checkbox, {
321
+ checked: row.getIsSelected(),
322
+ onClick: handleClick,
323
+ "aria-label": `Select row ${row.index + 1}`
324
+ });
325
+ }
326
+
327
+ // src/object-table/hooks/useSelectionColumn.tsx
328
+ var SELECTION_COLUMN_ID = "__selection__";
329
+ var useSelectionColumn = ({
330
+ selectionMode,
331
+ isAllSelected,
332
+ hasSelection,
333
+ onToggleAll,
334
+ onToggleRow
335
+ }) => {
336
+ const selectionColumn = React.useMemo(() => {
337
+ if (selectionMode === "none") return null;
3605
338
  return {
3606
- startIndex: 0,
3607
- endIndex: lastIndex
339
+ id: SELECTION_COLUMN_ID,
340
+ header: () => selectionMode === "multiple" ? /* @__PURE__ */ React__default.default.createElement(SelectionHeaderCell, {
341
+ isAllSelected,
342
+ hasSelection,
343
+ onToggleAll
344
+ }) : null,
345
+ cell: ({
346
+ row
347
+ }) => /* @__PURE__ */ React__default.default.createElement(SelectionCell, {
348
+ row,
349
+ onToggleRow
350
+ }),
351
+ size: 50,
352
+ minSize: 50,
353
+ maxSize: 50,
354
+ enableSorting: false,
355
+ enableResizing: false
356
+ };
357
+ }, [selectionMode, isAllSelected, hasSelection, onToggleAll, onToggleRow]);
358
+ return selectionColumn;
359
+ };
360
+ function CellContextMenu({
361
+ cell,
362
+ position,
363
+ onClose,
364
+ renderContent
365
+ }) {
366
+ const ref = React.useRef(null);
367
+ React.useEffect(() => {
368
+ const handleClickOutside = (event) => {
369
+ if (ref.current && !ref.current.contains(event.target)) {
370
+ onClose();
371
+ }
3608
372
  };
3609
- }
3610
- let startIndex = findNearestBinarySearch(0, lastIndex, getOffset, scrollOffset);
3611
- let endIndex = startIndex;
3612
- if (lanes === 1) {
3613
- while (endIndex < lastIndex && measurements[endIndex].end < scrollOffset + outerSize) {
3614
- endIndex++;
3615
- }
3616
- } else if (lanes > 1) {
3617
- const endPerLane = Array(lanes).fill(0);
3618
- while (endIndex < lastIndex && endPerLane.some((pos) => pos < scrollOffset + outerSize)) {
3619
- const item = measurements[endIndex];
3620
- endPerLane[item.lane] = item.end;
3621
- endIndex++;
373
+ document.addEventListener("mousedown", handleClickOutside);
374
+ return () => {
375
+ document.removeEventListener("mousedown", handleClickOutside);
376
+ };
377
+ }, [onClose]);
378
+ return /* @__PURE__ */ reactDom.createPortal(/* @__PURE__ */ React__default.default.createElement("div", {
379
+ ref,
380
+ style: {
381
+ position: "fixed",
382
+ zIndex: 9999,
383
+ left: position.left,
384
+ top: position.top,
385
+ minWidth: position.width
3622
386
  }
3623
- const startPerLane = Array(lanes).fill(scrollOffset + outerSize);
3624
- while (startIndex >= 0 && startPerLane.some((pos) => pos >= scrollOffset)) {
3625
- const item = measurements[startIndex];
3626
- startPerLane[item.lane] = item.start;
3627
- startIndex--;
387
+ }, renderContent(cell.row.original, cell)), document.body);
388
+ }
389
+ var useCellContextMenu = ({
390
+ tdRef
391
+ }) => {
392
+ const [popoverPosition, setPopoverPosition] = React.useState(null);
393
+ const [isContextMenuOpen, setIsContextMenuOpen] = React.useState(false);
394
+ const handleOpenContextMenu = React.useCallback((event) => {
395
+ event.preventDefault();
396
+ event.stopPropagation();
397
+ if (tdRef.current) {
398
+ const rect = tdRef.current.getBoundingClientRect();
399
+ const position = {
400
+ left: rect.left,
401
+ top: rect.bottom,
402
+ width: rect.width
403
+ };
404
+ setPopoverPosition(position);
405
+ setIsContextMenuOpen(true);
3628
406
  }
3629
- startIndex = Math.max(0, startIndex - startIndex % lanes);
3630
- endIndex = Math.min(lastIndex, endIndex + (lanes - 1 - endIndex % lanes));
3631
- }
407
+ }, [tdRef]);
408
+ const handleCloseContextMenu = React.useCallback(() => {
409
+ setIsContextMenuOpen(false);
410
+ setPopoverPosition(null);
411
+ }, []);
3632
412
  return {
3633
- startIndex,
3634
- endIndex
413
+ isContextMenuOpen,
414
+ handleOpenContextMenu,
415
+ handleCloseContextMenu,
416
+ popoverPosition
3635
417
  };
3636
- }
418
+ };
3637
419
 
3638
- // ../../node_modules/.pnpm/@tanstack+react-virtual@3.13.17_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/@tanstack/react-virtual/dist/esm/index.js
3639
- var useIsomorphicLayoutEffect = typeof document !== "undefined" ? React2__namespace.useLayoutEffect : React2__namespace.useEffect;
3640
- function useVirtualizerBase({
3641
- useFlushSync = true,
3642
- ...options
420
+ // src/object-table/TableCell.tsx
421
+ function TableCell({
422
+ cell,
423
+ renderCellContextMenu
3643
424
  }) {
3644
- const rerender = React2__namespace.useReducer(() => ({}), {})[1];
3645
- const resolvedOptions = {
3646
- ...options,
3647
- onChange: (instance2, sync) => {
3648
- var _a;
3649
- if (useFlushSync && sync) {
3650
- reactDom.flushSync(rerender);
3651
- } else {
3652
- rerender();
3653
- }
3654
- (_a = options.onChange) == null ? void 0 : _a.call(options, instance2, sync);
3655
- }
3656
- };
3657
- const [instance] = React2__namespace.useState(() => new Virtualizer(resolvedOptions));
3658
- instance.setOptions(resolvedOptions);
3659
- useIsomorphicLayoutEffect(() => {
3660
- return instance._didMount();
3661
- }, []);
3662
- useIsomorphicLayoutEffect(() => {
3663
- return instance._willUpdate();
3664
- });
3665
- return instance;
3666
- }
3667
- function useVirtualizer(options) {
3668
- return useVirtualizerBase({
3669
- observeElementRect,
3670
- observeElementOffset,
3671
- scrollToFn: elementScroll,
3672
- ...options
425
+ const tdRef = React.useRef(null);
426
+ const isSelectColumn = cell.column.id === SELECTION_COLUMN_ID;
427
+ const {
428
+ isContextMenuOpen,
429
+ handleOpenContextMenu,
430
+ handleCloseContextMenu,
431
+ popoverPosition
432
+ } = useCellContextMenu({
433
+ tdRef
3673
434
  });
435
+ const shouldRenderContextMenu = !isSelectColumn && isContextMenuOpen && !!popoverPosition && !!renderCellContextMenu;
436
+ return /* @__PURE__ */ React__default.default.createElement(React__default.default.Fragment, null, /* @__PURE__ */ React__default.default.createElement("td", {
437
+ ref: tdRef,
438
+ style: {
439
+ display: "flex",
440
+ alignItems: "center",
441
+ width: cell.column.getSize()
442
+ },
443
+ onContextMenu: handleOpenContextMenu
444
+ }, reactTable.flexRender(cell.column.columnDef.cell, cell.getContext())), shouldRenderContextMenu && /* @__PURE__ */ React__default.default.createElement(CellContextMenu, {
445
+ cell,
446
+ position: popoverPosition,
447
+ onClose: handleCloseContextMenu,
448
+ renderContent: renderCellContextMenu
449
+ }));
3674
450
  }
451
+
452
+ // src/object-table/TableRow.tsx
3675
453
  function TableRow({
3676
454
  row,
3677
455
  virtualRow,
3678
- onRowClick
456
+ onRowClick,
457
+ renderCellContextMenu
3679
458
  }) {
3680
- const handleClick = React2.useCallback(() => {
459
+ const handleClick = React.useCallback(() => {
3681
460
  onRowClick?.(row.original);
3682
461
  }, [onRowClick, row.original]);
3683
- return /* @__PURE__ */ React2__namespace.default.createElement("tr", {
462
+ return /* @__PURE__ */ React__default.default.createElement("tr", {
3684
463
  style: {
3685
464
  position: "absolute",
3686
465
  height: `${virtualRow.size}px`,
@@ -3688,14 +467,11 @@ function TableRow({
3688
467
  display: "flex"
3689
468
  },
3690
469
  onClick: handleClick
3691
- }, row.getVisibleCells().map((cell) => /* @__PURE__ */ React2__namespace.default.createElement("td", {
470
+ }, row.getVisibleCells().map((cell) => /* @__PURE__ */ React__default.default.createElement(TableCell, {
3692
471
  key: cell.id,
3693
- style: {
3694
- display: "flex",
3695
- alignItems: "center",
3696
- width: cell.column.getSize()
3697
- }
3698
- }, flexRender(cell.column.columnDef.cell, cell.getContext()))));
472
+ cell,
473
+ renderCellContextMenu
474
+ })));
3699
475
  }
3700
476
 
3701
477
  // src/object-table/TableBody.tsx
@@ -3703,18 +479,19 @@ function TableBody({
3703
479
  rows,
3704
480
  tableContainerRef,
3705
481
  onRowClick,
482
+ renderCellContextMenu,
3706
483
  rowHeight = 40
3707
484
  }) {
3708
- const rowVirtualizer = useVirtualizer({
485
+ const rowVirtualizer = reactVirtual.useVirtualizer({
3709
486
  count: rows.length,
3710
487
  estimateSize: () => rowHeight,
3711
488
  getScrollElement: () => tableContainerRef.current,
3712
489
  overscan: 5
3713
490
  });
3714
- React2.useLayoutEffect(() => {
491
+ React.useLayoutEffect(() => {
3715
492
  rowVirtualizer.measure();
3716
493
  }, [rowVirtualizer, rows.length]);
3717
- return /* @__PURE__ */ React2__namespace.default.createElement("tbody", {
494
+ return /* @__PURE__ */ React__default.default.createElement("tbody", {
3718
495
  style: {
3719
496
  display: "grid",
3720
497
  position: "relative",
@@ -3722,40 +499,57 @@ function TableBody({
3722
499
  }
3723
500
  }, rowVirtualizer.getVirtualItems().map((virtualRow) => {
3724
501
  const row = rows[virtualRow.index];
3725
- return /* @__PURE__ */ React2__namespace.default.createElement(TableRow, {
502
+ return /* @__PURE__ */ React__default.default.createElement(TableRow, {
3726
503
  key: row.id,
3727
504
  row,
3728
505
  virtualRow,
3729
- onRowClick
506
+ onRowClick,
507
+ renderCellContextMenu
3730
508
  });
3731
509
  }));
3732
510
  }
3733
511
  function TableHeader({
3734
- headerGroups
512
+ table
3735
513
  }) {
3736
- return /* @__PURE__ */ React2__namespace.default.createElement("thead", {
514
+ return /* @__PURE__ */ React__default.default.createElement("thead", {
3737
515
  style: {
3738
516
  display: "grid",
3739
517
  position: "sticky",
3740
518
  top: 0,
3741
519
  zIndex: 1
3742
520
  }
3743
- }, headerGroups.map((headerGroup) => /* @__PURE__ */ React2__namespace.default.createElement("tr", {
521
+ }, table.getHeaderGroups().map((headerGroup) => /* @__PURE__ */ React__default.default.createElement("tr", {
3744
522
  key: headerGroup.id,
3745
523
  style: {
3746
524
  display: "flex"
3747
525
  }
3748
526
  }, headerGroup.headers.map((header) => (
3749
527
  // TODO: Move inline styling to CSS file
3750
- /* @__PURE__ */ React2__namespace.default.createElement("th", {
528
+ /* @__PURE__ */ React__default.default.createElement("th", {
3751
529
  key: header.id,
3752
530
  style: {
3753
531
  display: "flex",
3754
532
  width: header.getSize(),
3755
533
  justifyContent: "flex-start",
3756
- alignItems: "center"
534
+ alignItems: "center",
535
+ position: "relative"
3757
536
  }
3758
- }, header.isPlaceholder ? null : flexRender(header.column.columnDef.header, header.getContext()))
537
+ }, header.isPlaceholder ? null : reactTable.flexRender(header.column.columnDef.header, header.getContext()), header.column.getCanResize() && /* @__PURE__ */ React__default.default.createElement("div", {
538
+ onDoubleClick: () => header.column.resetSize(),
539
+ onMouseDown: header.getResizeHandler(),
540
+ onTouchStart: header.getResizeHandler(),
541
+ style: {
542
+ position: "absolute",
543
+ right: 0,
544
+ top: 0,
545
+ height: "100%",
546
+ width: "3px",
547
+ cursor: "col-resize",
548
+ touchAction: "none",
549
+ zIndex: 11,
550
+ transform: header.column.getIsResizing() ? `translateX(${table.getState().columnSizingInfo.deltaOffset ?? 0}px)` : ""
551
+ }
552
+ }))
3759
553
  )))));
3760
554
  }
3761
555
 
@@ -3765,11 +559,12 @@ function Table({
3765
559
  isLoading,
3766
560
  fetchNextPage,
3767
561
  onRowClick,
3768
- rowHeight
562
+ rowHeight,
563
+ renderCellContextMenu
3769
564
  }) {
3770
- const tableContainerRef = React2.useRef(null);
3771
- const fetchingRef = React2.useRef(false);
3772
- const fetchMoreOnEndReached = React2.useCallback(async (containerRefElement) => {
565
+ const tableContainerRef = React.useRef(null);
566
+ const fetchingRef = React.useRef(false);
567
+ const fetchMoreOnEndReached = React.useCallback(async (containerRefElement) => {
3773
568
  if (containerRefElement && !fetchingRef.current) {
3774
569
  const {
3775
570
  scrollHeight,
@@ -3786,30 +581,33 @@ function Table({
3786
581
  }
3787
582
  }
3788
583
  }, [fetchNextPage, isLoading]);
3789
- const handleScroll = React2.useCallback(async (e) => {
584
+ const handleScroll = React.useCallback(async (e) => {
3790
585
  await fetchMoreOnEndReached(e.currentTarget);
3791
586
  }, [fetchMoreOnEndReached]);
3792
- return /* @__PURE__ */ React2__namespace.default.createElement("div", {
587
+ return /* @__PURE__ */ React__default.default.createElement("div", {
3793
588
  ref: tableContainerRef,
3794
589
  style: {
3795
590
  position: "relative",
3796
591
  // needed for sticky header
3797
592
  height: "100%",
3798
593
  // needed for scrolling
3799
- overflow: "auto"
594
+ overflow: "auto",
595
+ cursor: table.getState().columnSizingInfo?.isResizingColumn ? "col-resize" : "default",
596
+ userSelect: table.getState().columnSizingInfo?.isResizingColumn ? "none" : "auto"
3800
597
  },
3801
598
  onScroll: handleScroll
3802
- }, /* @__PURE__ */ React2__namespace.default.createElement("table", {
599
+ }, /* @__PURE__ */ React__default.default.createElement("table", {
3803
600
  style: {
3804
601
  display: "grid"
3805
602
  }
3806
- }, /* @__PURE__ */ React2__namespace.default.createElement(TableHeader, {
3807
- headerGroups: table.getHeaderGroups()
3808
- }), /* @__PURE__ */ React2__namespace.default.createElement(TableBody, {
603
+ }, /* @__PURE__ */ React__default.default.createElement(TableHeader, {
604
+ table
605
+ }), /* @__PURE__ */ React__default.default.createElement(TableBody, {
3809
606
  rows: table.getRowModel().rows,
3810
607
  tableContainerRef,
3811
608
  onRowClick,
3812
- rowHeight
609
+ rowHeight,
610
+ renderCellContextMenu
3813
611
  })));
3814
612
  }
3815
613
 
@@ -3818,14 +616,18 @@ function ObjectTable({
3818
616
  objectSet,
3819
617
  objectType,
3820
618
  columnDefinitions,
3821
- onRowClick,
3822
- rowHeight
619
+ filter,
620
+ onRowSelection,
621
+ renderCellContextMenu,
622
+ selectionMode = "none",
623
+ selectedRows,
624
+ ...props
3823
625
  }) {
3824
626
  const {
3825
627
  data,
3826
628
  fetchMore,
3827
629
  isLoading
3828
- } = useObjectTableData(objectSet, columnDefinitions);
630
+ } = useObjectTableData(objectSet, columnDefinitions, filter);
3829
631
  const {
3830
632
  columns,
3831
633
  loading: isColumnsLoading
@@ -3835,49 +637,60 @@ function ObjectTable({
3835
637
  } = useDefaultTableStates({
3836
638
  columnDefinitions
3837
639
  });
3838
- const table = useReactTable({
640
+ const [columnSizing, setColumnSizing] = React.useState({});
641
+ const {
642
+ rowSelection,
643
+ isAllSelected,
644
+ hasSelection,
645
+ onToggleAll,
646
+ onToggleRow
647
+ } = useRowSelection({
648
+ selectionMode,
649
+ selectedRows,
650
+ onRowSelection,
651
+ data
652
+ });
653
+ const selectionColumn = useSelectionColumn({
654
+ selectionMode,
655
+ isAllSelected,
656
+ hasSelection,
657
+ onToggleAll,
658
+ onToggleRow
659
+ });
660
+ const allColumns = React.useMemo(() => {
661
+ return selectionColumn ? [selectionColumn, ...columns] : columns;
662
+ }, [selectionColumn, columns]);
663
+ const table = reactTable.useReactTable({
3839
664
  data: data ?? [],
3840
- columns,
3841
- getCoreRowModel: getCoreRowModel(),
665
+ columns: allColumns,
666
+ getCoreRowModel: reactTable.getCoreRowModel(),
3842
667
  state: {
3843
- columnVisibility
3844
- }
668
+ columnVisibility,
669
+ rowSelection,
670
+ columnSizing
671
+ },
672
+ onColumnSizingChange: setColumnSizing,
673
+ enableRowSelection: selectionMode !== "none",
674
+ columnResizeMode: "onChange",
675
+ columnResizeDirection: "ltr",
676
+ defaultColumn: {
677
+ minSize: 80
678
+ },
679
+ getRowId
3845
680
  });
681
+ const onRenderCellContextMenu = React.useCallback((row, cell) => {
682
+ return renderCellContextMenu?.(row, cell.getValue());
683
+ }, [renderCellContextMenu]);
3846
684
  const isTableLoading = isLoading || isColumnsLoading;
3847
- return /* @__PURE__ */ React2__namespace.default.createElement(Table, {
685
+ return /* @__PURE__ */ React__default.default.createElement(Table, {
3848
686
  table,
3849
687
  isLoading: isTableLoading,
3850
688
  fetchNextPage: fetchMore,
3851
- onRowClick,
3852
- rowHeight
689
+ onRowClick: props.onRowClick,
690
+ rowHeight: props.rowHeight,
691
+ renderCellContextMenu: onRenderCellContextMenu
3853
692
  });
3854
693
  }
3855
- /*! Bundled license information:
3856
-
3857
- @tanstack/table-core/build/lib/index.mjs:
3858
- (**
3859
- * table-core
3860
- *
3861
- * Copyright (c) TanStack
3862
- *
3863
- * This source code is licensed under the MIT license found in the
3864
- * LICENSE.md file in the root directory of this source tree.
3865
- *
3866
- * @license MIT
3867
- *)
3868
-
3869
- @tanstack/react-table/build/lib/index.mjs:
3870
- (**
3871
- * react-table
3872
- *
3873
- * Copyright (c) TanStack
3874
- *
3875
- * This source code is licensed under the MIT license found in the
3876
- * LICENSE.md file in the root directory of this source tree.
3877
- *
3878
- * @license MIT
3879
- *)
3880
- */
3881
694
 
3882
695
  exports.ObjectTable = ObjectTable;
3883
696
  //# sourceMappingURL=experimental.cjs.map