tmo-ui-components 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +117 -0
- package/dist/components/Button/Button.d.ts +4 -0
- package/dist/components/Button/Button.types.d.ts +10 -0
- package/dist/components/Button/index.d.ts +2 -0
- package/dist/components/Card/Card.d.ts +7 -0
- package/dist/components/Card/Card.types.d.ts +17 -0
- package/dist/components/Card/index.d.ts +2 -0
- package/dist/components/DataTable/DataTable.d.ts +71 -0
- package/dist/components/DataTable/index.d.ts +2 -0
- package/dist/components/Input/Input.d.ts +4 -0
- package/dist/components/Input/Input.types.d.ts +9 -0
- package/dist/components/Input/index.d.ts +2 -0
- package/dist/components/index.d.ts +4 -0
- package/dist/index.d.ts +119 -0
- package/dist/index.esm.js +3648 -0
- package/dist/index.esm.js.map +1 -0
- package/dist/index.js +3675 -0
- package/dist/index.js.map +1 -0
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/theme.d.ts +50 -0
- package/dist/utils/view-size-calculator.d.ts +7 -0
- package/package.json +55 -0
|
@@ -0,0 +1,3648 @@
|
|
|
1
|
+
import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import { useState, useRef, useMemo, useCallback, useLayoutEffect, useEffect } from 'react';
|
|
4
|
+
|
|
5
|
+
const variantStyles$1 = {
|
|
6
|
+
primary: {
|
|
7
|
+
backgroundColor: '#e20074',
|
|
8
|
+
color: '#ffffff',
|
|
9
|
+
border: 'none',
|
|
10
|
+
},
|
|
11
|
+
secondary: {
|
|
12
|
+
backgroundColor: '#6c757d',
|
|
13
|
+
color: '#ffffff',
|
|
14
|
+
border: 'none',
|
|
15
|
+
},
|
|
16
|
+
outline: {
|
|
17
|
+
backgroundColor: 'transparent',
|
|
18
|
+
color: '#e20074',
|
|
19
|
+
border: '2px solid #e20074',
|
|
20
|
+
},
|
|
21
|
+
ghost: {
|
|
22
|
+
backgroundColor: 'transparent',
|
|
23
|
+
color: '#e20074',
|
|
24
|
+
border: 'none',
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
const sizeStyles$1 = {
|
|
28
|
+
sm: {
|
|
29
|
+
padding: '8px 16px',
|
|
30
|
+
fontSize: '14px',
|
|
31
|
+
},
|
|
32
|
+
md: {
|
|
33
|
+
padding: '12px 24px',
|
|
34
|
+
fontSize: '16px',
|
|
35
|
+
},
|
|
36
|
+
lg: {
|
|
37
|
+
padding: '16px 32px',
|
|
38
|
+
fontSize: '18px',
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
const Button = ({ children, variant = 'primary', size = 'md', isLoading = false, fullWidth = false, disabled, style, ...props }) => {
|
|
42
|
+
const baseStyles = {
|
|
43
|
+
borderRadius: '8px',
|
|
44
|
+
fontWeight: 600,
|
|
45
|
+
cursor: disabled || isLoading ? 'not-allowed' : 'pointer',
|
|
46
|
+
opacity: disabled || isLoading ? 0.6 : 1,
|
|
47
|
+
transition: 'all 0.2s ease-in-out',
|
|
48
|
+
display: 'inline-flex',
|
|
49
|
+
alignItems: 'center',
|
|
50
|
+
justifyContent: 'center',
|
|
51
|
+
gap: '8px',
|
|
52
|
+
width: fullWidth ? '100%' : 'auto',
|
|
53
|
+
...variantStyles$1[variant],
|
|
54
|
+
...sizeStyles$1[size],
|
|
55
|
+
...style,
|
|
56
|
+
};
|
|
57
|
+
return (jsxs("button", { style: baseStyles, disabled: disabled || isLoading, ...props, children: [isLoading && (jsx("span", { style: {
|
|
58
|
+
width: '16px',
|
|
59
|
+
height: '16px',
|
|
60
|
+
border: '2px solid currentColor',
|
|
61
|
+
borderTopColor: 'transparent',
|
|
62
|
+
borderRadius: '50%',
|
|
63
|
+
animation: 'spin 1s linear infinite',
|
|
64
|
+
} })), children] }));
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
const variantStyles = {
|
|
68
|
+
elevated: {
|
|
69
|
+
backgroundColor: '#ffffff',
|
|
70
|
+
boxShadow: '0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06)',
|
|
71
|
+
border: 'none',
|
|
72
|
+
},
|
|
73
|
+
outlined: {
|
|
74
|
+
backgroundColor: '#ffffff',
|
|
75
|
+
boxShadow: 'none',
|
|
76
|
+
border: '1px solid #e5e7eb',
|
|
77
|
+
},
|
|
78
|
+
filled: {
|
|
79
|
+
backgroundColor: '#f9fafb',
|
|
80
|
+
boxShadow: 'none',
|
|
81
|
+
border: 'none',
|
|
82
|
+
},
|
|
83
|
+
};
|
|
84
|
+
const paddingStyles = {
|
|
85
|
+
none: '0',
|
|
86
|
+
sm: '12px',
|
|
87
|
+
md: '16px',
|
|
88
|
+
lg: '24px',
|
|
89
|
+
};
|
|
90
|
+
const Card = ({ children, variant = 'elevated', padding = 'md', hoverable = false, style, ...props }) => {
|
|
91
|
+
const baseStyles = {
|
|
92
|
+
borderRadius: '12px',
|
|
93
|
+
overflow: 'hidden',
|
|
94
|
+
transition: 'all 0.2s ease-in-out',
|
|
95
|
+
padding: paddingStyles[padding],
|
|
96
|
+
...variantStyles[variant],
|
|
97
|
+
...style,
|
|
98
|
+
};
|
|
99
|
+
const hoverStyles = hoverable ? {
|
|
100
|
+
cursor: 'pointer',
|
|
101
|
+
} : {};
|
|
102
|
+
return (jsx("div", { style: { ...baseStyles, ...hoverStyles }, ...props, children: children }));
|
|
103
|
+
};
|
|
104
|
+
const CardHeader = ({ children, style, ...props }) => {
|
|
105
|
+
const headerStyles = {
|
|
106
|
+
paddingBottom: '12px',
|
|
107
|
+
borderBottom: '1px solid #e5e7eb',
|
|
108
|
+
marginBottom: '12px',
|
|
109
|
+
fontWeight: 600,
|
|
110
|
+
fontSize: '18px',
|
|
111
|
+
color: '#111827',
|
|
112
|
+
...style,
|
|
113
|
+
};
|
|
114
|
+
return (jsx("div", { style: headerStyles, ...props, children: children }));
|
|
115
|
+
};
|
|
116
|
+
const CardBody = ({ children, style, ...props }) => {
|
|
117
|
+
const bodyStyles = {
|
|
118
|
+
color: '#4b5563',
|
|
119
|
+
fontSize: '14px',
|
|
120
|
+
lineHeight: '1.6',
|
|
121
|
+
...style,
|
|
122
|
+
};
|
|
123
|
+
return (jsx("div", { style: bodyStyles, ...props, children: children }));
|
|
124
|
+
};
|
|
125
|
+
const CardFooter = ({ children, style, ...props }) => {
|
|
126
|
+
const footerStyles = {
|
|
127
|
+
paddingTop: '12px',
|
|
128
|
+
borderTop: '1px solid #e5e7eb',
|
|
129
|
+
marginTop: '12px',
|
|
130
|
+
display: 'flex',
|
|
131
|
+
justifyContent: 'flex-end',
|
|
132
|
+
gap: '8px',
|
|
133
|
+
...style,
|
|
134
|
+
};
|
|
135
|
+
return (jsx("div", { style: footerStyles, ...props, children: children }));
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
const sizeStyles = {
|
|
139
|
+
sm: {
|
|
140
|
+
padding: '8px 12px',
|
|
141
|
+
fontSize: '14px',
|
|
142
|
+
},
|
|
143
|
+
md: {
|
|
144
|
+
padding: '12px 16px',
|
|
145
|
+
fontSize: '16px',
|
|
146
|
+
},
|
|
147
|
+
lg: {
|
|
148
|
+
padding: '16px 20px',
|
|
149
|
+
fontSize: '18px',
|
|
150
|
+
},
|
|
151
|
+
};
|
|
152
|
+
const Input = ({ label, error, helperText, size = 'md', fullWidth = false, disabled, style, id, ...props }) => {
|
|
153
|
+
const inputId = id || `input-${Math.random().toString(36).substr(2, 9)}`;
|
|
154
|
+
const containerStyles = {
|
|
155
|
+
display: 'flex',
|
|
156
|
+
flexDirection: 'column',
|
|
157
|
+
gap: '4px',
|
|
158
|
+
width: fullWidth ? '100%' : 'auto',
|
|
159
|
+
};
|
|
160
|
+
const labelStyles = {
|
|
161
|
+
fontSize: '14px',
|
|
162
|
+
fontWeight: 500,
|
|
163
|
+
color: '#374151',
|
|
164
|
+
marginBottom: '4px',
|
|
165
|
+
};
|
|
166
|
+
const inputStyles = {
|
|
167
|
+
borderRadius: '8px',
|
|
168
|
+
border: `2px solid ${error ? '#ef4444' : '#d1d5db'}`,
|
|
169
|
+
outline: 'none',
|
|
170
|
+
transition: 'all 0.2s ease-in-out',
|
|
171
|
+
backgroundColor: disabled ? '#f3f4f6' : '#ffffff',
|
|
172
|
+
color: '#111827',
|
|
173
|
+
width: fullWidth ? '100%' : 'auto',
|
|
174
|
+
boxSizing: 'border-box',
|
|
175
|
+
...sizeStyles[size],
|
|
176
|
+
...style,
|
|
177
|
+
};
|
|
178
|
+
const helperStyles = {
|
|
179
|
+
fontSize: '12px',
|
|
180
|
+
color: error ? '#ef4444' : '#6b7280',
|
|
181
|
+
marginTop: '4px',
|
|
182
|
+
};
|
|
183
|
+
return (jsxs("div", { style: containerStyles, children: [label && (jsx("label", { htmlFor: inputId, style: labelStyles, children: label })), jsx("input", { id: inputId, style: inputStyles, disabled: disabled, ...props }), (error || helperText) && (jsx("span", { style: helperStyles, children: error || helperText }))] }));
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* table-core
|
|
188
|
+
*
|
|
189
|
+
* Copyright (c) TanStack
|
|
190
|
+
*
|
|
191
|
+
* This source code is licensed under the MIT license found in the
|
|
192
|
+
* LICENSE.md file in the root directory of this source tree.
|
|
193
|
+
*
|
|
194
|
+
* @license MIT
|
|
195
|
+
*/
|
|
196
|
+
// type Person = {
|
|
197
|
+
// firstName: string
|
|
198
|
+
// lastName: string
|
|
199
|
+
// age: number
|
|
200
|
+
// visits: number
|
|
201
|
+
// status: string
|
|
202
|
+
// progress: number
|
|
203
|
+
// createdAt: Date
|
|
204
|
+
// nested: {
|
|
205
|
+
// foo: [
|
|
206
|
+
// {
|
|
207
|
+
// bar: 'bar'
|
|
208
|
+
// }
|
|
209
|
+
// ]
|
|
210
|
+
// bar: { subBar: boolean }[]
|
|
211
|
+
// baz: {
|
|
212
|
+
// foo: 'foo'
|
|
213
|
+
// bar: {
|
|
214
|
+
// baz: 'baz'
|
|
215
|
+
// }
|
|
216
|
+
// }
|
|
217
|
+
// }
|
|
218
|
+
// }
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
// Is this type a tuple?
|
|
222
|
+
|
|
223
|
+
// If this type is a tuple, what indices are allowed?
|
|
224
|
+
|
|
225
|
+
///
|
|
226
|
+
|
|
227
|
+
function functionalUpdate(updater, input) {
|
|
228
|
+
return typeof updater === 'function' ? updater(input) : updater;
|
|
229
|
+
}
|
|
230
|
+
function makeStateUpdater(key, instance) {
|
|
231
|
+
return updater => {
|
|
232
|
+
instance.setState(old => {
|
|
233
|
+
return {
|
|
234
|
+
...old,
|
|
235
|
+
[key]: functionalUpdate(updater, old[key])
|
|
236
|
+
};
|
|
237
|
+
});
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
function isFunction(d) {
|
|
241
|
+
return d instanceof Function;
|
|
242
|
+
}
|
|
243
|
+
function isNumberArray(d) {
|
|
244
|
+
return Array.isArray(d) && d.every(val => typeof val === 'number');
|
|
245
|
+
}
|
|
246
|
+
function flattenBy(arr, getChildren) {
|
|
247
|
+
const flat = [];
|
|
248
|
+
const recurse = subArr => {
|
|
249
|
+
subArr.forEach(item => {
|
|
250
|
+
flat.push(item);
|
|
251
|
+
const children = getChildren(item);
|
|
252
|
+
if (children != null && children.length) {
|
|
253
|
+
recurse(children);
|
|
254
|
+
}
|
|
255
|
+
});
|
|
256
|
+
};
|
|
257
|
+
recurse(arr);
|
|
258
|
+
return flat;
|
|
259
|
+
}
|
|
260
|
+
function memo(getDeps, fn, opts) {
|
|
261
|
+
let deps = [];
|
|
262
|
+
let result;
|
|
263
|
+
return depArgs => {
|
|
264
|
+
let depTime;
|
|
265
|
+
if (opts.key && opts.debug) depTime = Date.now();
|
|
266
|
+
const newDeps = getDeps(depArgs);
|
|
267
|
+
const depsChanged = newDeps.length !== deps.length || newDeps.some((dep, index) => deps[index] !== dep);
|
|
268
|
+
if (!depsChanged) {
|
|
269
|
+
return result;
|
|
270
|
+
}
|
|
271
|
+
deps = newDeps;
|
|
272
|
+
let resultTime;
|
|
273
|
+
if (opts.key && opts.debug) resultTime = Date.now();
|
|
274
|
+
result = fn(...newDeps);
|
|
275
|
+
opts == null || opts.onChange == null || opts.onChange(result);
|
|
276
|
+
if (opts.key && opts.debug) {
|
|
277
|
+
if (opts != null && opts.debug()) {
|
|
278
|
+
const depEndTime = Math.round((Date.now() - depTime) * 100) / 100;
|
|
279
|
+
const resultEndTime = Math.round((Date.now() - resultTime) * 100) / 100;
|
|
280
|
+
const resultFpsPercentage = resultEndTime / 16;
|
|
281
|
+
const pad = (str, num) => {
|
|
282
|
+
str = String(str);
|
|
283
|
+
while (str.length < num) {
|
|
284
|
+
str = ' ' + str;
|
|
285
|
+
}
|
|
286
|
+
return str;
|
|
287
|
+
};
|
|
288
|
+
console.info(`%c⏱ ${pad(resultEndTime, 5)} /${pad(depEndTime, 5)} ms`, `
|
|
289
|
+
font-size: .6rem;
|
|
290
|
+
font-weight: bold;
|
|
291
|
+
color: hsl(${Math.max(0, Math.min(120 - 120 * resultFpsPercentage, 120))}deg 100% 31%);`, opts == null ? void 0 : opts.key);
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
return result;
|
|
295
|
+
};
|
|
296
|
+
}
|
|
297
|
+
function getMemoOptions(tableOptions, debugLevel, key, onChange) {
|
|
298
|
+
return {
|
|
299
|
+
debug: () => {
|
|
300
|
+
var _tableOptions$debugAl;
|
|
301
|
+
return (_tableOptions$debugAl = tableOptions == null ? void 0 : tableOptions.debugAll) != null ? _tableOptions$debugAl : tableOptions[debugLevel];
|
|
302
|
+
},
|
|
303
|
+
key: process.env.NODE_ENV === 'development' && key,
|
|
304
|
+
onChange
|
|
305
|
+
};
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
function createCell(table, row, column, columnId) {
|
|
309
|
+
const getRenderValue = () => {
|
|
310
|
+
var _cell$getValue;
|
|
311
|
+
return (_cell$getValue = cell.getValue()) != null ? _cell$getValue : table.options.renderFallbackValue;
|
|
312
|
+
};
|
|
313
|
+
const cell = {
|
|
314
|
+
id: `${row.id}_${column.id}`,
|
|
315
|
+
row,
|
|
316
|
+
column,
|
|
317
|
+
getValue: () => row.getValue(columnId),
|
|
318
|
+
renderValue: getRenderValue,
|
|
319
|
+
getContext: memo(() => [table, column, row, cell], (table, column, row, cell) => ({
|
|
320
|
+
table,
|
|
321
|
+
column,
|
|
322
|
+
row,
|
|
323
|
+
cell: cell,
|
|
324
|
+
getValue: cell.getValue,
|
|
325
|
+
renderValue: cell.renderValue
|
|
326
|
+
}), getMemoOptions(table.options, 'debugCells', 'cell.getContext'))
|
|
327
|
+
};
|
|
328
|
+
table._features.forEach(feature => {
|
|
329
|
+
feature.createCell == null || feature.createCell(cell, column, row, table);
|
|
330
|
+
}, {});
|
|
331
|
+
return cell;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
function createColumn(table, columnDef, depth, parent) {
|
|
335
|
+
var _ref, _resolvedColumnDef$id;
|
|
336
|
+
const defaultColumn = table._getDefaultColumnDef();
|
|
337
|
+
const resolvedColumnDef = {
|
|
338
|
+
...defaultColumn,
|
|
339
|
+
...columnDef
|
|
340
|
+
};
|
|
341
|
+
const accessorKey = resolvedColumnDef.accessorKey;
|
|
342
|
+
let id = (_ref = (_resolvedColumnDef$id = resolvedColumnDef.id) != null ? _resolvedColumnDef$id : accessorKey ? typeof String.prototype.replaceAll === 'function' ? accessorKey.replaceAll('.', '_') : accessorKey.replace(/\./g, '_') : undefined) != null ? _ref : typeof resolvedColumnDef.header === 'string' ? resolvedColumnDef.header : undefined;
|
|
343
|
+
let accessorFn;
|
|
344
|
+
if (resolvedColumnDef.accessorFn) {
|
|
345
|
+
accessorFn = resolvedColumnDef.accessorFn;
|
|
346
|
+
} else if (accessorKey) {
|
|
347
|
+
// Support deep accessor keys
|
|
348
|
+
if (accessorKey.includes('.')) {
|
|
349
|
+
accessorFn = originalRow => {
|
|
350
|
+
let result = originalRow;
|
|
351
|
+
for (const key of accessorKey.split('.')) {
|
|
352
|
+
var _result;
|
|
353
|
+
result = (_result = result) == null ? void 0 : _result[key];
|
|
354
|
+
if (process.env.NODE_ENV !== 'production' && result === undefined) {
|
|
355
|
+
console.warn(`"${key}" in deeply nested key "${accessorKey}" returned undefined.`);
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
return result;
|
|
359
|
+
};
|
|
360
|
+
} else {
|
|
361
|
+
accessorFn = originalRow => originalRow[resolvedColumnDef.accessorKey];
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
if (!id) {
|
|
365
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
366
|
+
throw new Error(resolvedColumnDef.accessorFn ? `Columns require an id when using an accessorFn` : `Columns require an id when using a non-string header`);
|
|
367
|
+
}
|
|
368
|
+
throw new Error();
|
|
369
|
+
}
|
|
370
|
+
let column = {
|
|
371
|
+
id: `${String(id)}`,
|
|
372
|
+
accessorFn,
|
|
373
|
+
parent: parent,
|
|
374
|
+
depth,
|
|
375
|
+
columnDef: resolvedColumnDef,
|
|
376
|
+
columns: [],
|
|
377
|
+
getFlatColumns: memo(() => [true], () => {
|
|
378
|
+
var _column$columns;
|
|
379
|
+
return [column, ...((_column$columns = column.columns) == null ? void 0 : _column$columns.flatMap(d => d.getFlatColumns()))];
|
|
380
|
+
}, getMemoOptions(table.options, 'debugColumns', 'column.getFlatColumns')),
|
|
381
|
+
getLeafColumns: memo(() => [table._getOrderColumnsFn()], orderColumns => {
|
|
382
|
+
var _column$columns2;
|
|
383
|
+
if ((_column$columns2 = column.columns) != null && _column$columns2.length) {
|
|
384
|
+
let leafColumns = column.columns.flatMap(column => column.getLeafColumns());
|
|
385
|
+
return orderColumns(leafColumns);
|
|
386
|
+
}
|
|
387
|
+
return [column];
|
|
388
|
+
}, getMemoOptions(table.options, 'debugColumns', 'column.getLeafColumns'))
|
|
389
|
+
};
|
|
390
|
+
for (const feature of table._features) {
|
|
391
|
+
feature.createColumn == null || feature.createColumn(column, table);
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
// Yes, we have to convert table to unknown, because we know more than the compiler here.
|
|
395
|
+
return column;
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
const debug = 'debugHeaders';
|
|
399
|
+
//
|
|
400
|
+
|
|
401
|
+
function createHeader(table, column, options) {
|
|
402
|
+
var _options$id;
|
|
403
|
+
const id = (_options$id = options.id) != null ? _options$id : column.id;
|
|
404
|
+
let header = {
|
|
405
|
+
id,
|
|
406
|
+
column,
|
|
407
|
+
index: options.index,
|
|
408
|
+
isPlaceholder: !!options.isPlaceholder,
|
|
409
|
+
placeholderId: options.placeholderId,
|
|
410
|
+
depth: options.depth,
|
|
411
|
+
subHeaders: [],
|
|
412
|
+
colSpan: 0,
|
|
413
|
+
rowSpan: 0,
|
|
414
|
+
headerGroup: null,
|
|
415
|
+
getLeafHeaders: () => {
|
|
416
|
+
const leafHeaders = [];
|
|
417
|
+
const recurseHeader = h => {
|
|
418
|
+
if (h.subHeaders && h.subHeaders.length) {
|
|
419
|
+
h.subHeaders.map(recurseHeader);
|
|
420
|
+
}
|
|
421
|
+
leafHeaders.push(h);
|
|
422
|
+
};
|
|
423
|
+
recurseHeader(header);
|
|
424
|
+
return leafHeaders;
|
|
425
|
+
},
|
|
426
|
+
getContext: () => ({
|
|
427
|
+
table,
|
|
428
|
+
header: header,
|
|
429
|
+
column
|
|
430
|
+
})
|
|
431
|
+
};
|
|
432
|
+
table._features.forEach(feature => {
|
|
433
|
+
feature.createHeader == null || feature.createHeader(header, table);
|
|
434
|
+
});
|
|
435
|
+
return header;
|
|
436
|
+
}
|
|
437
|
+
const Headers = {
|
|
438
|
+
createTable: table => {
|
|
439
|
+
// Header Groups
|
|
440
|
+
|
|
441
|
+
table.getHeaderGroups = memo(() => [table.getAllColumns(), table.getVisibleLeafColumns(), table.getState().columnPinning.left, table.getState().columnPinning.right], (allColumns, leafColumns, left, right) => {
|
|
442
|
+
var _left$map$filter, _right$map$filter;
|
|
443
|
+
const leftColumns = (_left$map$filter = left == null ? void 0 : left.map(columnId => leafColumns.find(d => d.id === columnId)).filter(Boolean)) != null ? _left$map$filter : [];
|
|
444
|
+
const rightColumns = (_right$map$filter = right == null ? void 0 : right.map(columnId => leafColumns.find(d => d.id === columnId)).filter(Boolean)) != null ? _right$map$filter : [];
|
|
445
|
+
const centerColumns = leafColumns.filter(column => !(left != null && left.includes(column.id)) && !(right != null && right.includes(column.id)));
|
|
446
|
+
const headerGroups = buildHeaderGroups(allColumns, [...leftColumns, ...centerColumns, ...rightColumns], table);
|
|
447
|
+
return headerGroups;
|
|
448
|
+
}, getMemoOptions(table.options, debug, 'getHeaderGroups'));
|
|
449
|
+
table.getCenterHeaderGroups = memo(() => [table.getAllColumns(), table.getVisibleLeafColumns(), table.getState().columnPinning.left, table.getState().columnPinning.right], (allColumns, leafColumns, left, right) => {
|
|
450
|
+
leafColumns = leafColumns.filter(column => !(left != null && left.includes(column.id)) && !(right != null && right.includes(column.id)));
|
|
451
|
+
return buildHeaderGroups(allColumns, leafColumns, table, 'center');
|
|
452
|
+
}, getMemoOptions(table.options, debug, 'getCenterHeaderGroups'));
|
|
453
|
+
table.getLeftHeaderGroups = memo(() => [table.getAllColumns(), table.getVisibleLeafColumns(), table.getState().columnPinning.left], (allColumns, leafColumns, left) => {
|
|
454
|
+
var _left$map$filter2;
|
|
455
|
+
const orderedLeafColumns = (_left$map$filter2 = left == null ? void 0 : left.map(columnId => leafColumns.find(d => d.id === columnId)).filter(Boolean)) != null ? _left$map$filter2 : [];
|
|
456
|
+
return buildHeaderGroups(allColumns, orderedLeafColumns, table, 'left');
|
|
457
|
+
}, getMemoOptions(table.options, debug, 'getLeftHeaderGroups'));
|
|
458
|
+
table.getRightHeaderGroups = memo(() => [table.getAllColumns(), table.getVisibleLeafColumns(), table.getState().columnPinning.right], (allColumns, leafColumns, right) => {
|
|
459
|
+
var _right$map$filter2;
|
|
460
|
+
const orderedLeafColumns = (_right$map$filter2 = right == null ? void 0 : right.map(columnId => leafColumns.find(d => d.id === columnId)).filter(Boolean)) != null ? _right$map$filter2 : [];
|
|
461
|
+
return buildHeaderGroups(allColumns, orderedLeafColumns, table, 'right');
|
|
462
|
+
}, getMemoOptions(table.options, debug, 'getRightHeaderGroups'));
|
|
463
|
+
|
|
464
|
+
// Footer Groups
|
|
465
|
+
|
|
466
|
+
table.getFooterGroups = memo(() => [table.getHeaderGroups()], headerGroups => {
|
|
467
|
+
return [...headerGroups].reverse();
|
|
468
|
+
}, getMemoOptions(table.options, debug, 'getFooterGroups'));
|
|
469
|
+
table.getLeftFooterGroups = memo(() => [table.getLeftHeaderGroups()], headerGroups => {
|
|
470
|
+
return [...headerGroups].reverse();
|
|
471
|
+
}, getMemoOptions(table.options, debug, 'getLeftFooterGroups'));
|
|
472
|
+
table.getCenterFooterGroups = memo(() => [table.getCenterHeaderGroups()], headerGroups => {
|
|
473
|
+
return [...headerGroups].reverse();
|
|
474
|
+
}, getMemoOptions(table.options, debug, 'getCenterFooterGroups'));
|
|
475
|
+
table.getRightFooterGroups = memo(() => [table.getRightHeaderGroups()], headerGroups => {
|
|
476
|
+
return [...headerGroups].reverse();
|
|
477
|
+
}, getMemoOptions(table.options, debug, 'getRightFooterGroups'));
|
|
478
|
+
|
|
479
|
+
// Flat Headers
|
|
480
|
+
|
|
481
|
+
table.getFlatHeaders = memo(() => [table.getHeaderGroups()], headerGroups => {
|
|
482
|
+
return headerGroups.map(headerGroup => {
|
|
483
|
+
return headerGroup.headers;
|
|
484
|
+
}).flat();
|
|
485
|
+
}, getMemoOptions(table.options, debug, 'getFlatHeaders'));
|
|
486
|
+
table.getLeftFlatHeaders = memo(() => [table.getLeftHeaderGroups()], left => {
|
|
487
|
+
return left.map(headerGroup => {
|
|
488
|
+
return headerGroup.headers;
|
|
489
|
+
}).flat();
|
|
490
|
+
}, getMemoOptions(table.options, debug, 'getLeftFlatHeaders'));
|
|
491
|
+
table.getCenterFlatHeaders = memo(() => [table.getCenterHeaderGroups()], left => {
|
|
492
|
+
return left.map(headerGroup => {
|
|
493
|
+
return headerGroup.headers;
|
|
494
|
+
}).flat();
|
|
495
|
+
}, getMemoOptions(table.options, debug, 'getCenterFlatHeaders'));
|
|
496
|
+
table.getRightFlatHeaders = memo(() => [table.getRightHeaderGroups()], left => {
|
|
497
|
+
return left.map(headerGroup => {
|
|
498
|
+
return headerGroup.headers;
|
|
499
|
+
}).flat();
|
|
500
|
+
}, getMemoOptions(table.options, debug, 'getRightFlatHeaders'));
|
|
501
|
+
|
|
502
|
+
// Leaf Headers
|
|
503
|
+
|
|
504
|
+
table.getCenterLeafHeaders = memo(() => [table.getCenterFlatHeaders()], flatHeaders => {
|
|
505
|
+
return flatHeaders.filter(header => {
|
|
506
|
+
var _header$subHeaders;
|
|
507
|
+
return !((_header$subHeaders = header.subHeaders) != null && _header$subHeaders.length);
|
|
508
|
+
});
|
|
509
|
+
}, getMemoOptions(table.options, debug, 'getCenterLeafHeaders'));
|
|
510
|
+
table.getLeftLeafHeaders = memo(() => [table.getLeftFlatHeaders()], flatHeaders => {
|
|
511
|
+
return flatHeaders.filter(header => {
|
|
512
|
+
var _header$subHeaders2;
|
|
513
|
+
return !((_header$subHeaders2 = header.subHeaders) != null && _header$subHeaders2.length);
|
|
514
|
+
});
|
|
515
|
+
}, getMemoOptions(table.options, debug, 'getLeftLeafHeaders'));
|
|
516
|
+
table.getRightLeafHeaders = memo(() => [table.getRightFlatHeaders()], flatHeaders => {
|
|
517
|
+
return flatHeaders.filter(header => {
|
|
518
|
+
var _header$subHeaders3;
|
|
519
|
+
return !((_header$subHeaders3 = header.subHeaders) != null && _header$subHeaders3.length);
|
|
520
|
+
});
|
|
521
|
+
}, getMemoOptions(table.options, debug, 'getRightLeafHeaders'));
|
|
522
|
+
table.getLeafHeaders = memo(() => [table.getLeftHeaderGroups(), table.getCenterHeaderGroups(), table.getRightHeaderGroups()], (left, center, right) => {
|
|
523
|
+
var _left$0$headers, _left$, _center$0$headers, _center$, _right$0$headers, _right$;
|
|
524
|
+
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 => {
|
|
525
|
+
return header.getLeafHeaders();
|
|
526
|
+
}).flat();
|
|
527
|
+
}, getMemoOptions(table.options, debug, 'getLeafHeaders'));
|
|
528
|
+
}
|
|
529
|
+
};
|
|
530
|
+
function buildHeaderGroups(allColumns, columnsToGroup, table, headerFamily) {
|
|
531
|
+
var _headerGroups$0$heade, _headerGroups$;
|
|
532
|
+
// Find the max depth of the columns:
|
|
533
|
+
// build the leaf column row
|
|
534
|
+
// build each buffer row going up
|
|
535
|
+
// placeholder for non-existent level
|
|
536
|
+
// real column for existing level
|
|
537
|
+
|
|
538
|
+
let maxDepth = 0;
|
|
539
|
+
const findMaxDepth = function (columns, depth) {
|
|
540
|
+
if (depth === void 0) {
|
|
541
|
+
depth = 1;
|
|
542
|
+
}
|
|
543
|
+
maxDepth = Math.max(maxDepth, depth);
|
|
544
|
+
columns.filter(column => column.getIsVisible()).forEach(column => {
|
|
545
|
+
var _column$columns;
|
|
546
|
+
if ((_column$columns = column.columns) != null && _column$columns.length) {
|
|
547
|
+
findMaxDepth(column.columns, depth + 1);
|
|
548
|
+
}
|
|
549
|
+
}, 0);
|
|
550
|
+
};
|
|
551
|
+
findMaxDepth(allColumns);
|
|
552
|
+
let headerGroups = [];
|
|
553
|
+
const createHeaderGroup = (headersToGroup, depth) => {
|
|
554
|
+
// The header group we are creating
|
|
555
|
+
const headerGroup = {
|
|
556
|
+
depth,
|
|
557
|
+
id: [headerFamily, `${depth}`].filter(Boolean).join('_'),
|
|
558
|
+
headers: []
|
|
559
|
+
};
|
|
560
|
+
|
|
561
|
+
// The parent columns we're going to scan next
|
|
562
|
+
const pendingParentHeaders = [];
|
|
563
|
+
|
|
564
|
+
// Scan each column for parents
|
|
565
|
+
headersToGroup.forEach(headerToGroup => {
|
|
566
|
+
// What is the latest (last) parent column?
|
|
567
|
+
|
|
568
|
+
const latestPendingParentHeader = [...pendingParentHeaders].reverse()[0];
|
|
569
|
+
const isLeafHeader = headerToGroup.column.depth === headerGroup.depth;
|
|
570
|
+
let column;
|
|
571
|
+
let isPlaceholder = false;
|
|
572
|
+
if (isLeafHeader && headerToGroup.column.parent) {
|
|
573
|
+
// The parent header is new
|
|
574
|
+
column = headerToGroup.column.parent;
|
|
575
|
+
} else {
|
|
576
|
+
// The parent header is repeated
|
|
577
|
+
column = headerToGroup.column;
|
|
578
|
+
isPlaceholder = true;
|
|
579
|
+
}
|
|
580
|
+
if (latestPendingParentHeader && (latestPendingParentHeader == null ? void 0 : latestPendingParentHeader.column) === column) {
|
|
581
|
+
// This column is repeated. Add it as a sub header to the next batch
|
|
582
|
+
latestPendingParentHeader.subHeaders.push(headerToGroup);
|
|
583
|
+
} else {
|
|
584
|
+
// This is a new header. Let's create it
|
|
585
|
+
const header = createHeader(table, column, {
|
|
586
|
+
id: [headerFamily, depth, column.id, headerToGroup == null ? void 0 : headerToGroup.id].filter(Boolean).join('_'),
|
|
587
|
+
isPlaceholder,
|
|
588
|
+
placeholderId: isPlaceholder ? `${pendingParentHeaders.filter(d => d.column === column).length}` : undefined,
|
|
589
|
+
depth,
|
|
590
|
+
index: pendingParentHeaders.length
|
|
591
|
+
});
|
|
592
|
+
|
|
593
|
+
// Add the headerToGroup as a subHeader of the new header
|
|
594
|
+
header.subHeaders.push(headerToGroup);
|
|
595
|
+
// Add the new header to the pendingParentHeaders to get grouped
|
|
596
|
+
// in the next batch
|
|
597
|
+
pendingParentHeaders.push(header);
|
|
598
|
+
}
|
|
599
|
+
headerGroup.headers.push(headerToGroup);
|
|
600
|
+
headerToGroup.headerGroup = headerGroup;
|
|
601
|
+
});
|
|
602
|
+
headerGroups.push(headerGroup);
|
|
603
|
+
if (depth > 0) {
|
|
604
|
+
createHeaderGroup(pendingParentHeaders, depth - 1);
|
|
605
|
+
}
|
|
606
|
+
};
|
|
607
|
+
const bottomHeaders = columnsToGroup.map((column, index) => createHeader(table, column, {
|
|
608
|
+
depth: maxDepth,
|
|
609
|
+
index
|
|
610
|
+
}));
|
|
611
|
+
createHeaderGroup(bottomHeaders, maxDepth - 1);
|
|
612
|
+
headerGroups.reverse();
|
|
613
|
+
|
|
614
|
+
// headerGroups = headerGroups.filter(headerGroup => {
|
|
615
|
+
// return !headerGroup.headers.every(header => header.isPlaceholder)
|
|
616
|
+
// })
|
|
617
|
+
|
|
618
|
+
const recurseHeadersForSpans = headers => {
|
|
619
|
+
const filteredHeaders = headers.filter(header => header.column.getIsVisible());
|
|
620
|
+
return filteredHeaders.map(header => {
|
|
621
|
+
let colSpan = 0;
|
|
622
|
+
let rowSpan = 0;
|
|
623
|
+
let childRowSpans = [0];
|
|
624
|
+
if (header.subHeaders && header.subHeaders.length) {
|
|
625
|
+
childRowSpans = [];
|
|
626
|
+
recurseHeadersForSpans(header.subHeaders).forEach(_ref => {
|
|
627
|
+
let {
|
|
628
|
+
colSpan: childColSpan,
|
|
629
|
+
rowSpan: childRowSpan
|
|
630
|
+
} = _ref;
|
|
631
|
+
colSpan += childColSpan;
|
|
632
|
+
childRowSpans.push(childRowSpan);
|
|
633
|
+
});
|
|
634
|
+
} else {
|
|
635
|
+
colSpan = 1;
|
|
636
|
+
}
|
|
637
|
+
const minChildRowSpan = Math.min(...childRowSpans);
|
|
638
|
+
rowSpan = rowSpan + minChildRowSpan;
|
|
639
|
+
header.colSpan = colSpan;
|
|
640
|
+
header.rowSpan = rowSpan;
|
|
641
|
+
return {
|
|
642
|
+
colSpan,
|
|
643
|
+
rowSpan
|
|
644
|
+
};
|
|
645
|
+
});
|
|
646
|
+
};
|
|
647
|
+
recurseHeadersForSpans((_headerGroups$0$heade = (_headerGroups$ = headerGroups[0]) == null ? void 0 : _headerGroups$.headers) != null ? _headerGroups$0$heade : []);
|
|
648
|
+
return headerGroups;
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
const createRow = (table, id, original, rowIndex, depth, subRows, parentId) => {
|
|
652
|
+
let row = {
|
|
653
|
+
id,
|
|
654
|
+
index: rowIndex,
|
|
655
|
+
original,
|
|
656
|
+
depth,
|
|
657
|
+
parentId,
|
|
658
|
+
_valuesCache: {},
|
|
659
|
+
_uniqueValuesCache: {},
|
|
660
|
+
getValue: columnId => {
|
|
661
|
+
if (row._valuesCache.hasOwnProperty(columnId)) {
|
|
662
|
+
return row._valuesCache[columnId];
|
|
663
|
+
}
|
|
664
|
+
const column = table.getColumn(columnId);
|
|
665
|
+
if (!(column != null && column.accessorFn)) {
|
|
666
|
+
return undefined;
|
|
667
|
+
}
|
|
668
|
+
row._valuesCache[columnId] = column.accessorFn(row.original, rowIndex);
|
|
669
|
+
return row._valuesCache[columnId];
|
|
670
|
+
},
|
|
671
|
+
getUniqueValues: columnId => {
|
|
672
|
+
if (row._uniqueValuesCache.hasOwnProperty(columnId)) {
|
|
673
|
+
return row._uniqueValuesCache[columnId];
|
|
674
|
+
}
|
|
675
|
+
const column = table.getColumn(columnId);
|
|
676
|
+
if (!(column != null && column.accessorFn)) {
|
|
677
|
+
return undefined;
|
|
678
|
+
}
|
|
679
|
+
if (!column.columnDef.getUniqueValues) {
|
|
680
|
+
row._uniqueValuesCache[columnId] = [row.getValue(columnId)];
|
|
681
|
+
return row._uniqueValuesCache[columnId];
|
|
682
|
+
}
|
|
683
|
+
row._uniqueValuesCache[columnId] = column.columnDef.getUniqueValues(row.original, rowIndex);
|
|
684
|
+
return row._uniqueValuesCache[columnId];
|
|
685
|
+
},
|
|
686
|
+
renderValue: columnId => {
|
|
687
|
+
var _row$getValue;
|
|
688
|
+
return (_row$getValue = row.getValue(columnId)) != null ? _row$getValue : table.options.renderFallbackValue;
|
|
689
|
+
},
|
|
690
|
+
subRows: [],
|
|
691
|
+
getLeafRows: () => flattenBy(row.subRows, d => d.subRows),
|
|
692
|
+
getParentRow: () => row.parentId ? table.getRow(row.parentId, true) : undefined,
|
|
693
|
+
getParentRows: () => {
|
|
694
|
+
let parentRows = [];
|
|
695
|
+
let currentRow = row;
|
|
696
|
+
while (true) {
|
|
697
|
+
const parentRow = currentRow.getParentRow();
|
|
698
|
+
if (!parentRow) break;
|
|
699
|
+
parentRows.push(parentRow);
|
|
700
|
+
currentRow = parentRow;
|
|
701
|
+
}
|
|
702
|
+
return parentRows.reverse();
|
|
703
|
+
},
|
|
704
|
+
getAllCells: memo(() => [table.getAllLeafColumns()], leafColumns => {
|
|
705
|
+
return leafColumns.map(column => {
|
|
706
|
+
return createCell(table, row, column, column.id);
|
|
707
|
+
});
|
|
708
|
+
}, getMemoOptions(table.options, 'debugRows', 'getAllCells')),
|
|
709
|
+
_getAllCellsByColumnId: memo(() => [row.getAllCells()], allCells => {
|
|
710
|
+
return allCells.reduce((acc, cell) => {
|
|
711
|
+
acc[cell.column.id] = cell;
|
|
712
|
+
return acc;
|
|
713
|
+
}, {});
|
|
714
|
+
}, getMemoOptions(table.options, 'debugRows', 'getAllCellsByColumnId'))
|
|
715
|
+
};
|
|
716
|
+
for (let i = 0; i < table._features.length; i++) {
|
|
717
|
+
const feature = table._features[i];
|
|
718
|
+
feature == null || feature.createRow == null || feature.createRow(row, table);
|
|
719
|
+
}
|
|
720
|
+
return row;
|
|
721
|
+
};
|
|
722
|
+
|
|
723
|
+
//
|
|
724
|
+
|
|
725
|
+
const ColumnFaceting = {
|
|
726
|
+
createColumn: (column, table) => {
|
|
727
|
+
column._getFacetedRowModel = table.options.getFacetedRowModel && table.options.getFacetedRowModel(table, column.id);
|
|
728
|
+
column.getFacetedRowModel = () => {
|
|
729
|
+
if (!column._getFacetedRowModel) {
|
|
730
|
+
return table.getPreFilteredRowModel();
|
|
731
|
+
}
|
|
732
|
+
return column._getFacetedRowModel();
|
|
733
|
+
};
|
|
734
|
+
column._getFacetedUniqueValues = table.options.getFacetedUniqueValues && table.options.getFacetedUniqueValues(table, column.id);
|
|
735
|
+
column.getFacetedUniqueValues = () => {
|
|
736
|
+
if (!column._getFacetedUniqueValues) {
|
|
737
|
+
return new Map();
|
|
738
|
+
}
|
|
739
|
+
return column._getFacetedUniqueValues();
|
|
740
|
+
};
|
|
741
|
+
column._getFacetedMinMaxValues = table.options.getFacetedMinMaxValues && table.options.getFacetedMinMaxValues(table, column.id);
|
|
742
|
+
column.getFacetedMinMaxValues = () => {
|
|
743
|
+
if (!column._getFacetedMinMaxValues) {
|
|
744
|
+
return undefined;
|
|
745
|
+
}
|
|
746
|
+
return column._getFacetedMinMaxValues();
|
|
747
|
+
};
|
|
748
|
+
}
|
|
749
|
+
};
|
|
750
|
+
|
|
751
|
+
const includesString = (row, columnId, filterValue) => {
|
|
752
|
+
var _filterValue$toString, _row$getValue;
|
|
753
|
+
const search = filterValue == null || (_filterValue$toString = filterValue.toString()) == null ? void 0 : _filterValue$toString.toLowerCase();
|
|
754
|
+
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));
|
|
755
|
+
};
|
|
756
|
+
includesString.autoRemove = val => testFalsey(val);
|
|
757
|
+
const includesStringSensitive = (row, columnId, filterValue) => {
|
|
758
|
+
var _row$getValue2;
|
|
759
|
+
return Boolean((_row$getValue2 = row.getValue(columnId)) == null || (_row$getValue2 = _row$getValue2.toString()) == null ? void 0 : _row$getValue2.includes(filterValue));
|
|
760
|
+
};
|
|
761
|
+
includesStringSensitive.autoRemove = val => testFalsey(val);
|
|
762
|
+
const equalsString = (row, columnId, filterValue) => {
|
|
763
|
+
var _row$getValue3;
|
|
764
|
+
return ((_row$getValue3 = row.getValue(columnId)) == null || (_row$getValue3 = _row$getValue3.toString()) == null ? void 0 : _row$getValue3.toLowerCase()) === (filterValue == null ? void 0 : filterValue.toLowerCase());
|
|
765
|
+
};
|
|
766
|
+
equalsString.autoRemove = val => testFalsey(val);
|
|
767
|
+
const arrIncludes = (row, columnId, filterValue) => {
|
|
768
|
+
var _row$getValue4;
|
|
769
|
+
return (_row$getValue4 = row.getValue(columnId)) == null ? void 0 : _row$getValue4.includes(filterValue);
|
|
770
|
+
};
|
|
771
|
+
arrIncludes.autoRemove = val => testFalsey(val);
|
|
772
|
+
const arrIncludesAll = (row, columnId, filterValue) => {
|
|
773
|
+
return !filterValue.some(val => {
|
|
774
|
+
var _row$getValue5;
|
|
775
|
+
return !((_row$getValue5 = row.getValue(columnId)) != null && _row$getValue5.includes(val));
|
|
776
|
+
});
|
|
777
|
+
};
|
|
778
|
+
arrIncludesAll.autoRemove = val => testFalsey(val) || !(val != null && val.length);
|
|
779
|
+
const arrIncludesSome = (row, columnId, filterValue) => {
|
|
780
|
+
return filterValue.some(val => {
|
|
781
|
+
var _row$getValue6;
|
|
782
|
+
return (_row$getValue6 = row.getValue(columnId)) == null ? void 0 : _row$getValue6.includes(val);
|
|
783
|
+
});
|
|
784
|
+
};
|
|
785
|
+
arrIncludesSome.autoRemove = val => testFalsey(val) || !(val != null && val.length);
|
|
786
|
+
const equals = (row, columnId, filterValue) => {
|
|
787
|
+
return row.getValue(columnId) === filterValue;
|
|
788
|
+
};
|
|
789
|
+
equals.autoRemove = val => testFalsey(val);
|
|
790
|
+
const weakEquals = (row, columnId, filterValue) => {
|
|
791
|
+
return row.getValue(columnId) == filterValue;
|
|
792
|
+
};
|
|
793
|
+
weakEquals.autoRemove = val => testFalsey(val);
|
|
794
|
+
const inNumberRange = (row, columnId, filterValue) => {
|
|
795
|
+
let [min, max] = filterValue;
|
|
796
|
+
const rowValue = row.getValue(columnId);
|
|
797
|
+
return rowValue >= min && rowValue <= max;
|
|
798
|
+
};
|
|
799
|
+
inNumberRange.resolveFilterValue = val => {
|
|
800
|
+
let [unsafeMin, unsafeMax] = val;
|
|
801
|
+
let parsedMin = typeof unsafeMin !== 'number' ? parseFloat(unsafeMin) : unsafeMin;
|
|
802
|
+
let parsedMax = typeof unsafeMax !== 'number' ? parseFloat(unsafeMax) : unsafeMax;
|
|
803
|
+
let min = unsafeMin === null || Number.isNaN(parsedMin) ? -Infinity : parsedMin;
|
|
804
|
+
let max = unsafeMax === null || Number.isNaN(parsedMax) ? Infinity : parsedMax;
|
|
805
|
+
if (min > max) {
|
|
806
|
+
const temp = min;
|
|
807
|
+
min = max;
|
|
808
|
+
max = temp;
|
|
809
|
+
}
|
|
810
|
+
return [min, max];
|
|
811
|
+
};
|
|
812
|
+
inNumberRange.autoRemove = val => testFalsey(val) || testFalsey(val[0]) && testFalsey(val[1]);
|
|
813
|
+
|
|
814
|
+
// Export
|
|
815
|
+
|
|
816
|
+
const filterFns = {
|
|
817
|
+
includesString,
|
|
818
|
+
includesStringSensitive,
|
|
819
|
+
equalsString,
|
|
820
|
+
arrIncludes,
|
|
821
|
+
arrIncludesAll,
|
|
822
|
+
arrIncludesSome,
|
|
823
|
+
equals,
|
|
824
|
+
weakEquals,
|
|
825
|
+
inNumberRange
|
|
826
|
+
};
|
|
827
|
+
// Utils
|
|
828
|
+
|
|
829
|
+
function testFalsey(val) {
|
|
830
|
+
return val === undefined || val === null || val === '';
|
|
831
|
+
}
|
|
832
|
+
|
|
833
|
+
//
|
|
834
|
+
|
|
835
|
+
const ColumnFiltering = {
|
|
836
|
+
getDefaultColumnDef: () => {
|
|
837
|
+
return {
|
|
838
|
+
filterFn: 'auto'
|
|
839
|
+
};
|
|
840
|
+
},
|
|
841
|
+
getInitialState: state => {
|
|
842
|
+
return {
|
|
843
|
+
columnFilters: [],
|
|
844
|
+
...state
|
|
845
|
+
};
|
|
846
|
+
},
|
|
847
|
+
getDefaultOptions: table => {
|
|
848
|
+
return {
|
|
849
|
+
onColumnFiltersChange: makeStateUpdater('columnFilters', table),
|
|
850
|
+
filterFromLeafRows: false,
|
|
851
|
+
maxLeafRowFilterDepth: 100
|
|
852
|
+
};
|
|
853
|
+
},
|
|
854
|
+
createColumn: (column, table) => {
|
|
855
|
+
column.getAutoFilterFn = () => {
|
|
856
|
+
const firstRow = table.getCoreRowModel().flatRows[0];
|
|
857
|
+
const value = firstRow == null ? void 0 : firstRow.getValue(column.id);
|
|
858
|
+
if (typeof value === 'string') {
|
|
859
|
+
return filterFns.includesString;
|
|
860
|
+
}
|
|
861
|
+
if (typeof value === 'number') {
|
|
862
|
+
return filterFns.inNumberRange;
|
|
863
|
+
}
|
|
864
|
+
if (typeof value === 'boolean') {
|
|
865
|
+
return filterFns.equals;
|
|
866
|
+
}
|
|
867
|
+
if (value !== null && typeof value === 'object') {
|
|
868
|
+
return filterFns.equals;
|
|
869
|
+
}
|
|
870
|
+
if (Array.isArray(value)) {
|
|
871
|
+
return filterFns.arrIncludes;
|
|
872
|
+
}
|
|
873
|
+
return filterFns.weakEquals;
|
|
874
|
+
};
|
|
875
|
+
column.getFilterFn = () => {
|
|
876
|
+
var _table$options$filter, _table$options$filter2;
|
|
877
|
+
return isFunction(column.columnDef.filterFn) ? column.columnDef.filterFn : column.columnDef.filterFn === 'auto' ? column.getAutoFilterFn() : // @ts-ignore
|
|
878
|
+
(_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];
|
|
879
|
+
};
|
|
880
|
+
column.getCanFilter = () => {
|
|
881
|
+
var _column$columnDef$ena, _table$options$enable, _table$options$enable2;
|
|
882
|
+
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;
|
|
883
|
+
};
|
|
884
|
+
column.getIsFiltered = () => column.getFilterIndex() > -1;
|
|
885
|
+
column.getFilterValue = () => {
|
|
886
|
+
var _table$getState$colum;
|
|
887
|
+
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;
|
|
888
|
+
};
|
|
889
|
+
column.getFilterIndex = () => {
|
|
890
|
+
var _table$getState$colum2, _table$getState$colum3;
|
|
891
|
+
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;
|
|
892
|
+
};
|
|
893
|
+
column.setFilterValue = value => {
|
|
894
|
+
table.setColumnFilters(old => {
|
|
895
|
+
const filterFn = column.getFilterFn();
|
|
896
|
+
const previousFilter = old == null ? void 0 : old.find(d => d.id === column.id);
|
|
897
|
+
const newFilter = functionalUpdate(value, previousFilter ? previousFilter.value : undefined);
|
|
898
|
+
|
|
899
|
+
//
|
|
900
|
+
if (shouldAutoRemoveFilter(filterFn, newFilter, column)) {
|
|
901
|
+
var _old$filter;
|
|
902
|
+
return (_old$filter = old == null ? void 0 : old.filter(d => d.id !== column.id)) != null ? _old$filter : [];
|
|
903
|
+
}
|
|
904
|
+
const newFilterObj = {
|
|
905
|
+
id: column.id,
|
|
906
|
+
value: newFilter
|
|
907
|
+
};
|
|
908
|
+
if (previousFilter) {
|
|
909
|
+
var _old$map;
|
|
910
|
+
return (_old$map = old == null ? void 0 : old.map(d => {
|
|
911
|
+
if (d.id === column.id) {
|
|
912
|
+
return newFilterObj;
|
|
913
|
+
}
|
|
914
|
+
return d;
|
|
915
|
+
})) != null ? _old$map : [];
|
|
916
|
+
}
|
|
917
|
+
if (old != null && old.length) {
|
|
918
|
+
return [...old, newFilterObj];
|
|
919
|
+
}
|
|
920
|
+
return [newFilterObj];
|
|
921
|
+
});
|
|
922
|
+
};
|
|
923
|
+
},
|
|
924
|
+
createRow: (row, _table) => {
|
|
925
|
+
row.columnFilters = {};
|
|
926
|
+
row.columnFiltersMeta = {};
|
|
927
|
+
},
|
|
928
|
+
createTable: table => {
|
|
929
|
+
table.setColumnFilters = updater => {
|
|
930
|
+
const leafColumns = table.getAllLeafColumns();
|
|
931
|
+
const updateFn = old => {
|
|
932
|
+
var _functionalUpdate;
|
|
933
|
+
return (_functionalUpdate = functionalUpdate(updater, old)) == null ? void 0 : _functionalUpdate.filter(filter => {
|
|
934
|
+
const column = leafColumns.find(d => d.id === filter.id);
|
|
935
|
+
if (column) {
|
|
936
|
+
const filterFn = column.getFilterFn();
|
|
937
|
+
if (shouldAutoRemoveFilter(filterFn, filter.value, column)) {
|
|
938
|
+
return false;
|
|
939
|
+
}
|
|
940
|
+
}
|
|
941
|
+
return true;
|
|
942
|
+
});
|
|
943
|
+
};
|
|
944
|
+
table.options.onColumnFiltersChange == null || table.options.onColumnFiltersChange(updateFn);
|
|
945
|
+
};
|
|
946
|
+
table.resetColumnFilters = defaultState => {
|
|
947
|
+
var _table$initialState$c, _table$initialState;
|
|
948
|
+
table.setColumnFilters(defaultState ? [] : (_table$initialState$c = (_table$initialState = table.initialState) == null ? void 0 : _table$initialState.columnFilters) != null ? _table$initialState$c : []);
|
|
949
|
+
};
|
|
950
|
+
table.getPreFilteredRowModel = () => table.getCoreRowModel();
|
|
951
|
+
table.getFilteredRowModel = () => {
|
|
952
|
+
if (!table._getFilteredRowModel && table.options.getFilteredRowModel) {
|
|
953
|
+
table._getFilteredRowModel = table.options.getFilteredRowModel(table);
|
|
954
|
+
}
|
|
955
|
+
if (table.options.manualFiltering || !table._getFilteredRowModel) {
|
|
956
|
+
return table.getPreFilteredRowModel();
|
|
957
|
+
}
|
|
958
|
+
return table._getFilteredRowModel();
|
|
959
|
+
};
|
|
960
|
+
}
|
|
961
|
+
};
|
|
962
|
+
function shouldAutoRemoveFilter(filterFn, value, column) {
|
|
963
|
+
return (filterFn && filterFn.autoRemove ? filterFn.autoRemove(value, column) : false) || typeof value === 'undefined' || typeof value === 'string' && !value;
|
|
964
|
+
}
|
|
965
|
+
|
|
966
|
+
const sum = (columnId, _leafRows, childRows) => {
|
|
967
|
+
// It's faster to just add the aggregations together instead of
|
|
968
|
+
// process leaf nodes individually
|
|
969
|
+
return childRows.reduce((sum, next) => {
|
|
970
|
+
const nextValue = next.getValue(columnId);
|
|
971
|
+
return sum + (typeof nextValue === 'number' ? nextValue : 0);
|
|
972
|
+
}, 0);
|
|
973
|
+
};
|
|
974
|
+
const min = (columnId, _leafRows, childRows) => {
|
|
975
|
+
let min;
|
|
976
|
+
childRows.forEach(row => {
|
|
977
|
+
const value = row.getValue(columnId);
|
|
978
|
+
if (value != null && (min > value || min === undefined && value >= value)) {
|
|
979
|
+
min = value;
|
|
980
|
+
}
|
|
981
|
+
});
|
|
982
|
+
return min;
|
|
983
|
+
};
|
|
984
|
+
const max = (columnId, _leafRows, childRows) => {
|
|
985
|
+
let max;
|
|
986
|
+
childRows.forEach(row => {
|
|
987
|
+
const value = row.getValue(columnId);
|
|
988
|
+
if (value != null && (max < value || max === undefined && value >= value)) {
|
|
989
|
+
max = value;
|
|
990
|
+
}
|
|
991
|
+
});
|
|
992
|
+
return max;
|
|
993
|
+
};
|
|
994
|
+
const extent = (columnId, _leafRows, childRows) => {
|
|
995
|
+
let min;
|
|
996
|
+
let max;
|
|
997
|
+
childRows.forEach(row => {
|
|
998
|
+
const value = row.getValue(columnId);
|
|
999
|
+
if (value != null) {
|
|
1000
|
+
if (min === undefined) {
|
|
1001
|
+
if (value >= value) min = max = value;
|
|
1002
|
+
} else {
|
|
1003
|
+
if (min > value) min = value;
|
|
1004
|
+
if (max < value) max = value;
|
|
1005
|
+
}
|
|
1006
|
+
}
|
|
1007
|
+
});
|
|
1008
|
+
return [min, max];
|
|
1009
|
+
};
|
|
1010
|
+
const mean = (columnId, leafRows) => {
|
|
1011
|
+
let count = 0;
|
|
1012
|
+
let sum = 0;
|
|
1013
|
+
leafRows.forEach(row => {
|
|
1014
|
+
let value = row.getValue(columnId);
|
|
1015
|
+
if (value != null && (value = +value) >= value) {
|
|
1016
|
+
++count, sum += value;
|
|
1017
|
+
}
|
|
1018
|
+
});
|
|
1019
|
+
if (count) return sum / count;
|
|
1020
|
+
return;
|
|
1021
|
+
};
|
|
1022
|
+
const median = (columnId, leafRows) => {
|
|
1023
|
+
if (!leafRows.length) {
|
|
1024
|
+
return;
|
|
1025
|
+
}
|
|
1026
|
+
const values = leafRows.map(row => row.getValue(columnId));
|
|
1027
|
+
if (!isNumberArray(values)) {
|
|
1028
|
+
return;
|
|
1029
|
+
}
|
|
1030
|
+
if (values.length === 1) {
|
|
1031
|
+
return values[0];
|
|
1032
|
+
}
|
|
1033
|
+
const mid = Math.floor(values.length / 2);
|
|
1034
|
+
const nums = values.sort((a, b) => a - b);
|
|
1035
|
+
return values.length % 2 !== 0 ? nums[mid] : (nums[mid - 1] + nums[mid]) / 2;
|
|
1036
|
+
};
|
|
1037
|
+
const unique = (columnId, leafRows) => {
|
|
1038
|
+
return Array.from(new Set(leafRows.map(d => d.getValue(columnId))).values());
|
|
1039
|
+
};
|
|
1040
|
+
const uniqueCount = (columnId, leafRows) => {
|
|
1041
|
+
return new Set(leafRows.map(d => d.getValue(columnId))).size;
|
|
1042
|
+
};
|
|
1043
|
+
const count = (_columnId, leafRows) => {
|
|
1044
|
+
return leafRows.length;
|
|
1045
|
+
};
|
|
1046
|
+
const aggregationFns = {
|
|
1047
|
+
sum,
|
|
1048
|
+
min,
|
|
1049
|
+
max,
|
|
1050
|
+
extent,
|
|
1051
|
+
mean,
|
|
1052
|
+
median,
|
|
1053
|
+
unique,
|
|
1054
|
+
uniqueCount,
|
|
1055
|
+
count
|
|
1056
|
+
};
|
|
1057
|
+
|
|
1058
|
+
//
|
|
1059
|
+
|
|
1060
|
+
const ColumnGrouping = {
|
|
1061
|
+
getDefaultColumnDef: () => {
|
|
1062
|
+
return {
|
|
1063
|
+
aggregatedCell: props => {
|
|
1064
|
+
var _toString, _props$getValue;
|
|
1065
|
+
return (_toString = (_props$getValue = props.getValue()) == null || _props$getValue.toString == null ? void 0 : _props$getValue.toString()) != null ? _toString : null;
|
|
1066
|
+
},
|
|
1067
|
+
aggregationFn: 'auto'
|
|
1068
|
+
};
|
|
1069
|
+
},
|
|
1070
|
+
getInitialState: state => {
|
|
1071
|
+
return {
|
|
1072
|
+
grouping: [],
|
|
1073
|
+
...state
|
|
1074
|
+
};
|
|
1075
|
+
},
|
|
1076
|
+
getDefaultOptions: table => {
|
|
1077
|
+
return {
|
|
1078
|
+
onGroupingChange: makeStateUpdater('grouping', table),
|
|
1079
|
+
groupedColumnMode: 'reorder'
|
|
1080
|
+
};
|
|
1081
|
+
},
|
|
1082
|
+
createColumn: (column, table) => {
|
|
1083
|
+
column.toggleGrouping = () => {
|
|
1084
|
+
table.setGrouping(old => {
|
|
1085
|
+
// Find any existing grouping for this column
|
|
1086
|
+
if (old != null && old.includes(column.id)) {
|
|
1087
|
+
return old.filter(d => d !== column.id);
|
|
1088
|
+
}
|
|
1089
|
+
return [...(old != null ? old : []), column.id];
|
|
1090
|
+
});
|
|
1091
|
+
};
|
|
1092
|
+
column.getCanGroup = () => {
|
|
1093
|
+
var _column$columnDef$ena, _table$options$enable;
|
|
1094
|
+
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);
|
|
1095
|
+
};
|
|
1096
|
+
column.getIsGrouped = () => {
|
|
1097
|
+
var _table$getState$group;
|
|
1098
|
+
return (_table$getState$group = table.getState().grouping) == null ? void 0 : _table$getState$group.includes(column.id);
|
|
1099
|
+
};
|
|
1100
|
+
column.getGroupedIndex = () => {
|
|
1101
|
+
var _table$getState$group2;
|
|
1102
|
+
return (_table$getState$group2 = table.getState().grouping) == null ? void 0 : _table$getState$group2.indexOf(column.id);
|
|
1103
|
+
};
|
|
1104
|
+
column.getToggleGroupingHandler = () => {
|
|
1105
|
+
const canGroup = column.getCanGroup();
|
|
1106
|
+
return () => {
|
|
1107
|
+
if (!canGroup) return;
|
|
1108
|
+
column.toggleGrouping();
|
|
1109
|
+
};
|
|
1110
|
+
};
|
|
1111
|
+
column.getAutoAggregationFn = () => {
|
|
1112
|
+
const firstRow = table.getCoreRowModel().flatRows[0];
|
|
1113
|
+
const value = firstRow == null ? void 0 : firstRow.getValue(column.id);
|
|
1114
|
+
if (typeof value === 'number') {
|
|
1115
|
+
return aggregationFns.sum;
|
|
1116
|
+
}
|
|
1117
|
+
if (Object.prototype.toString.call(value) === '[object Date]') {
|
|
1118
|
+
return aggregationFns.extent;
|
|
1119
|
+
}
|
|
1120
|
+
};
|
|
1121
|
+
column.getAggregationFn = () => {
|
|
1122
|
+
var _table$options$aggreg, _table$options$aggreg2;
|
|
1123
|
+
if (!column) {
|
|
1124
|
+
throw new Error();
|
|
1125
|
+
}
|
|
1126
|
+
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];
|
|
1127
|
+
};
|
|
1128
|
+
},
|
|
1129
|
+
createTable: table => {
|
|
1130
|
+
table.setGrouping = updater => table.options.onGroupingChange == null ? void 0 : table.options.onGroupingChange(updater);
|
|
1131
|
+
table.resetGrouping = defaultState => {
|
|
1132
|
+
var _table$initialState$g, _table$initialState;
|
|
1133
|
+
table.setGrouping(defaultState ? [] : (_table$initialState$g = (_table$initialState = table.initialState) == null ? void 0 : _table$initialState.grouping) != null ? _table$initialState$g : []);
|
|
1134
|
+
};
|
|
1135
|
+
table.getPreGroupedRowModel = () => table.getFilteredRowModel();
|
|
1136
|
+
table.getGroupedRowModel = () => {
|
|
1137
|
+
if (!table._getGroupedRowModel && table.options.getGroupedRowModel) {
|
|
1138
|
+
table._getGroupedRowModel = table.options.getGroupedRowModel(table);
|
|
1139
|
+
}
|
|
1140
|
+
if (table.options.manualGrouping || !table._getGroupedRowModel) {
|
|
1141
|
+
return table.getPreGroupedRowModel();
|
|
1142
|
+
}
|
|
1143
|
+
return table._getGroupedRowModel();
|
|
1144
|
+
};
|
|
1145
|
+
},
|
|
1146
|
+
createRow: (row, table) => {
|
|
1147
|
+
row.getIsGrouped = () => !!row.groupingColumnId;
|
|
1148
|
+
row.getGroupingValue = columnId => {
|
|
1149
|
+
if (row._groupingValuesCache.hasOwnProperty(columnId)) {
|
|
1150
|
+
return row._groupingValuesCache[columnId];
|
|
1151
|
+
}
|
|
1152
|
+
const column = table.getColumn(columnId);
|
|
1153
|
+
if (!(column != null && column.columnDef.getGroupingValue)) {
|
|
1154
|
+
return row.getValue(columnId);
|
|
1155
|
+
}
|
|
1156
|
+
row._groupingValuesCache[columnId] = column.columnDef.getGroupingValue(row.original);
|
|
1157
|
+
return row._groupingValuesCache[columnId];
|
|
1158
|
+
};
|
|
1159
|
+
row._groupingValuesCache = {};
|
|
1160
|
+
},
|
|
1161
|
+
createCell: (cell, column, row, table) => {
|
|
1162
|
+
cell.getIsGrouped = () => column.getIsGrouped() && column.id === row.groupingColumnId;
|
|
1163
|
+
cell.getIsPlaceholder = () => !cell.getIsGrouped() && column.getIsGrouped();
|
|
1164
|
+
cell.getIsAggregated = () => {
|
|
1165
|
+
var _row$subRows;
|
|
1166
|
+
return !cell.getIsGrouped() && !cell.getIsPlaceholder() && !!((_row$subRows = row.subRows) != null && _row$subRows.length);
|
|
1167
|
+
};
|
|
1168
|
+
}
|
|
1169
|
+
};
|
|
1170
|
+
function orderColumns(leafColumns, grouping, groupedColumnMode) {
|
|
1171
|
+
if (!(grouping != null && grouping.length) || !groupedColumnMode) {
|
|
1172
|
+
return leafColumns;
|
|
1173
|
+
}
|
|
1174
|
+
const nonGroupingColumns = leafColumns.filter(col => !grouping.includes(col.id));
|
|
1175
|
+
if (groupedColumnMode === 'remove') {
|
|
1176
|
+
return nonGroupingColumns;
|
|
1177
|
+
}
|
|
1178
|
+
const groupingColumns = grouping.map(g => leafColumns.find(col => col.id === g)).filter(Boolean);
|
|
1179
|
+
return [...groupingColumns, ...nonGroupingColumns];
|
|
1180
|
+
}
|
|
1181
|
+
|
|
1182
|
+
//
|
|
1183
|
+
|
|
1184
|
+
const ColumnOrdering = {
|
|
1185
|
+
getInitialState: state => {
|
|
1186
|
+
return {
|
|
1187
|
+
columnOrder: [],
|
|
1188
|
+
...state
|
|
1189
|
+
};
|
|
1190
|
+
},
|
|
1191
|
+
getDefaultOptions: table => {
|
|
1192
|
+
return {
|
|
1193
|
+
onColumnOrderChange: makeStateUpdater('columnOrder', table)
|
|
1194
|
+
};
|
|
1195
|
+
},
|
|
1196
|
+
createColumn: (column, table) => {
|
|
1197
|
+
column.getIndex = memo(position => [_getVisibleLeafColumns(table, position)], columns => columns.findIndex(d => d.id === column.id), getMemoOptions(table.options, 'debugColumns', 'getIndex'));
|
|
1198
|
+
column.getIsFirstColumn = position => {
|
|
1199
|
+
var _columns$;
|
|
1200
|
+
const columns = _getVisibleLeafColumns(table, position);
|
|
1201
|
+
return ((_columns$ = columns[0]) == null ? void 0 : _columns$.id) === column.id;
|
|
1202
|
+
};
|
|
1203
|
+
column.getIsLastColumn = position => {
|
|
1204
|
+
var _columns;
|
|
1205
|
+
const columns = _getVisibleLeafColumns(table, position);
|
|
1206
|
+
return ((_columns = columns[columns.length - 1]) == null ? void 0 : _columns.id) === column.id;
|
|
1207
|
+
};
|
|
1208
|
+
},
|
|
1209
|
+
createTable: table => {
|
|
1210
|
+
table.setColumnOrder = updater => table.options.onColumnOrderChange == null ? void 0 : table.options.onColumnOrderChange(updater);
|
|
1211
|
+
table.resetColumnOrder = defaultState => {
|
|
1212
|
+
var _table$initialState$c;
|
|
1213
|
+
table.setColumnOrder(defaultState ? [] : (_table$initialState$c = table.initialState.columnOrder) != null ? _table$initialState$c : []);
|
|
1214
|
+
};
|
|
1215
|
+
table._getOrderColumnsFn = memo(() => [table.getState().columnOrder, table.getState().grouping, table.options.groupedColumnMode], (columnOrder, grouping, groupedColumnMode) => columns => {
|
|
1216
|
+
// Sort grouped columns to the start of the column list
|
|
1217
|
+
// before the headers are built
|
|
1218
|
+
let orderedColumns = [];
|
|
1219
|
+
|
|
1220
|
+
// If there is no order, return the normal columns
|
|
1221
|
+
if (!(columnOrder != null && columnOrder.length)) {
|
|
1222
|
+
orderedColumns = columns;
|
|
1223
|
+
} else {
|
|
1224
|
+
const columnOrderCopy = [...columnOrder];
|
|
1225
|
+
|
|
1226
|
+
// If there is an order, make a copy of the columns
|
|
1227
|
+
const columnsCopy = [...columns];
|
|
1228
|
+
|
|
1229
|
+
// And make a new ordered array of the columns
|
|
1230
|
+
|
|
1231
|
+
// Loop over the columns and place them in order into the new array
|
|
1232
|
+
while (columnsCopy.length && columnOrderCopy.length) {
|
|
1233
|
+
const targetColumnId = columnOrderCopy.shift();
|
|
1234
|
+
const foundIndex = columnsCopy.findIndex(d => d.id === targetColumnId);
|
|
1235
|
+
if (foundIndex > -1) {
|
|
1236
|
+
orderedColumns.push(columnsCopy.splice(foundIndex, 1)[0]);
|
|
1237
|
+
}
|
|
1238
|
+
}
|
|
1239
|
+
|
|
1240
|
+
// If there are any columns left, add them to the end
|
|
1241
|
+
orderedColumns = [...orderedColumns, ...columnsCopy];
|
|
1242
|
+
}
|
|
1243
|
+
return orderColumns(orderedColumns, grouping, groupedColumnMode);
|
|
1244
|
+
}, getMemoOptions(table.options, 'debugTable', '_getOrderColumnsFn'));
|
|
1245
|
+
}
|
|
1246
|
+
};
|
|
1247
|
+
|
|
1248
|
+
//
|
|
1249
|
+
|
|
1250
|
+
const getDefaultColumnPinningState = () => ({
|
|
1251
|
+
left: [],
|
|
1252
|
+
right: []
|
|
1253
|
+
});
|
|
1254
|
+
const ColumnPinning = {
|
|
1255
|
+
getInitialState: state => {
|
|
1256
|
+
return {
|
|
1257
|
+
columnPinning: getDefaultColumnPinningState(),
|
|
1258
|
+
...state
|
|
1259
|
+
};
|
|
1260
|
+
},
|
|
1261
|
+
getDefaultOptions: table => {
|
|
1262
|
+
return {
|
|
1263
|
+
onColumnPinningChange: makeStateUpdater('columnPinning', table)
|
|
1264
|
+
};
|
|
1265
|
+
},
|
|
1266
|
+
createColumn: (column, table) => {
|
|
1267
|
+
column.pin = position => {
|
|
1268
|
+
const columnIds = column.getLeafColumns().map(d => d.id).filter(Boolean);
|
|
1269
|
+
table.setColumnPinning(old => {
|
|
1270
|
+
var _old$left3, _old$right3;
|
|
1271
|
+
if (position === 'right') {
|
|
1272
|
+
var _old$left, _old$right;
|
|
1273
|
+
return {
|
|
1274
|
+
left: ((_old$left = old == null ? void 0 : old.left) != null ? _old$left : []).filter(d => !(columnIds != null && columnIds.includes(d))),
|
|
1275
|
+
right: [...((_old$right = old == null ? void 0 : old.right) != null ? _old$right : []).filter(d => !(columnIds != null && columnIds.includes(d))), ...columnIds]
|
|
1276
|
+
};
|
|
1277
|
+
}
|
|
1278
|
+
if (position === 'left') {
|
|
1279
|
+
var _old$left2, _old$right2;
|
|
1280
|
+
return {
|
|
1281
|
+
left: [...((_old$left2 = old == null ? void 0 : old.left) != null ? _old$left2 : []).filter(d => !(columnIds != null && columnIds.includes(d))), ...columnIds],
|
|
1282
|
+
right: ((_old$right2 = old == null ? void 0 : old.right) != null ? _old$right2 : []).filter(d => !(columnIds != null && columnIds.includes(d)))
|
|
1283
|
+
};
|
|
1284
|
+
}
|
|
1285
|
+
return {
|
|
1286
|
+
left: ((_old$left3 = old == null ? void 0 : old.left) != null ? _old$left3 : []).filter(d => !(columnIds != null && columnIds.includes(d))),
|
|
1287
|
+
right: ((_old$right3 = old == null ? void 0 : old.right) != null ? _old$right3 : []).filter(d => !(columnIds != null && columnIds.includes(d)))
|
|
1288
|
+
};
|
|
1289
|
+
});
|
|
1290
|
+
};
|
|
1291
|
+
column.getCanPin = () => {
|
|
1292
|
+
const leafColumns = column.getLeafColumns();
|
|
1293
|
+
return leafColumns.some(d => {
|
|
1294
|
+
var _d$columnDef$enablePi, _ref, _table$options$enable;
|
|
1295
|
+
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);
|
|
1296
|
+
});
|
|
1297
|
+
};
|
|
1298
|
+
column.getIsPinned = () => {
|
|
1299
|
+
const leafColumnIds = column.getLeafColumns().map(d => d.id);
|
|
1300
|
+
const {
|
|
1301
|
+
left,
|
|
1302
|
+
right
|
|
1303
|
+
} = table.getState().columnPinning;
|
|
1304
|
+
const isLeft = leafColumnIds.some(d => left == null ? void 0 : left.includes(d));
|
|
1305
|
+
const isRight = leafColumnIds.some(d => right == null ? void 0 : right.includes(d));
|
|
1306
|
+
return isLeft ? 'left' : isRight ? 'right' : false;
|
|
1307
|
+
};
|
|
1308
|
+
column.getPinnedIndex = () => {
|
|
1309
|
+
var _table$getState$colum, _table$getState$colum2;
|
|
1310
|
+
const position = column.getIsPinned();
|
|
1311
|
+
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;
|
|
1312
|
+
};
|
|
1313
|
+
},
|
|
1314
|
+
createRow: (row, table) => {
|
|
1315
|
+
row.getCenterVisibleCells = memo(() => [row._getAllVisibleCells(), table.getState().columnPinning.left, table.getState().columnPinning.right], (allCells, left, right) => {
|
|
1316
|
+
const leftAndRight = [...(left != null ? left : []), ...(right != null ? right : [])];
|
|
1317
|
+
return allCells.filter(d => !leftAndRight.includes(d.column.id));
|
|
1318
|
+
}, getMemoOptions(table.options, 'debugRows', 'getCenterVisibleCells'));
|
|
1319
|
+
row.getLeftVisibleCells = memo(() => [row._getAllVisibleCells(), table.getState().columnPinning.left], (allCells, left) => {
|
|
1320
|
+
const cells = (left != null ? left : []).map(columnId => allCells.find(cell => cell.column.id === columnId)).filter(Boolean).map(d => ({
|
|
1321
|
+
...d,
|
|
1322
|
+
position: 'left'
|
|
1323
|
+
}));
|
|
1324
|
+
return cells;
|
|
1325
|
+
}, getMemoOptions(table.options, 'debugRows', 'getLeftVisibleCells'));
|
|
1326
|
+
row.getRightVisibleCells = memo(() => [row._getAllVisibleCells(), table.getState().columnPinning.right], (allCells, right) => {
|
|
1327
|
+
const cells = (right != null ? right : []).map(columnId => allCells.find(cell => cell.column.id === columnId)).filter(Boolean).map(d => ({
|
|
1328
|
+
...d,
|
|
1329
|
+
position: 'right'
|
|
1330
|
+
}));
|
|
1331
|
+
return cells;
|
|
1332
|
+
}, getMemoOptions(table.options, 'debugRows', 'getRightVisibleCells'));
|
|
1333
|
+
},
|
|
1334
|
+
createTable: table => {
|
|
1335
|
+
table.setColumnPinning = updater => table.options.onColumnPinningChange == null ? void 0 : table.options.onColumnPinningChange(updater);
|
|
1336
|
+
table.resetColumnPinning = defaultState => {
|
|
1337
|
+
var _table$initialState$c, _table$initialState;
|
|
1338
|
+
return table.setColumnPinning(defaultState ? getDefaultColumnPinningState() : (_table$initialState$c = (_table$initialState = table.initialState) == null ? void 0 : _table$initialState.columnPinning) != null ? _table$initialState$c : getDefaultColumnPinningState());
|
|
1339
|
+
};
|
|
1340
|
+
table.getIsSomeColumnsPinned = position => {
|
|
1341
|
+
var _pinningState$positio;
|
|
1342
|
+
const pinningState = table.getState().columnPinning;
|
|
1343
|
+
if (!position) {
|
|
1344
|
+
var _pinningState$left, _pinningState$right;
|
|
1345
|
+
return Boolean(((_pinningState$left = pinningState.left) == null ? void 0 : _pinningState$left.length) || ((_pinningState$right = pinningState.right) == null ? void 0 : _pinningState$right.length));
|
|
1346
|
+
}
|
|
1347
|
+
return Boolean((_pinningState$positio = pinningState[position]) == null ? void 0 : _pinningState$positio.length);
|
|
1348
|
+
};
|
|
1349
|
+
table.getLeftLeafColumns = memo(() => [table.getAllLeafColumns(), table.getState().columnPinning.left], (allColumns, left) => {
|
|
1350
|
+
return (left != null ? left : []).map(columnId => allColumns.find(column => column.id === columnId)).filter(Boolean);
|
|
1351
|
+
}, getMemoOptions(table.options, 'debugColumns', 'getLeftLeafColumns'));
|
|
1352
|
+
table.getRightLeafColumns = memo(() => [table.getAllLeafColumns(), table.getState().columnPinning.right], (allColumns, right) => {
|
|
1353
|
+
return (right != null ? right : []).map(columnId => allColumns.find(column => column.id === columnId)).filter(Boolean);
|
|
1354
|
+
}, getMemoOptions(table.options, 'debugColumns', 'getRightLeafColumns'));
|
|
1355
|
+
table.getCenterLeafColumns = memo(() => [table.getAllLeafColumns(), table.getState().columnPinning.left, table.getState().columnPinning.right], (allColumns, left, right) => {
|
|
1356
|
+
const leftAndRight = [...(left != null ? left : []), ...(right != null ? right : [])];
|
|
1357
|
+
return allColumns.filter(d => !leftAndRight.includes(d.id));
|
|
1358
|
+
}, getMemoOptions(table.options, 'debugColumns', 'getCenterLeafColumns'));
|
|
1359
|
+
}
|
|
1360
|
+
};
|
|
1361
|
+
|
|
1362
|
+
function safelyAccessDocument(_document) {
|
|
1363
|
+
return _document || (typeof document !== 'undefined' ? document : null);
|
|
1364
|
+
}
|
|
1365
|
+
|
|
1366
|
+
//
|
|
1367
|
+
|
|
1368
|
+
//
|
|
1369
|
+
|
|
1370
|
+
const defaultColumnSizing = {
|
|
1371
|
+
size: 150,
|
|
1372
|
+
minSize: 20,
|
|
1373
|
+
maxSize: Number.MAX_SAFE_INTEGER
|
|
1374
|
+
};
|
|
1375
|
+
const getDefaultColumnSizingInfoState = () => ({
|
|
1376
|
+
startOffset: null,
|
|
1377
|
+
startSize: null,
|
|
1378
|
+
deltaOffset: null,
|
|
1379
|
+
deltaPercentage: null,
|
|
1380
|
+
isResizingColumn: false,
|
|
1381
|
+
columnSizingStart: []
|
|
1382
|
+
});
|
|
1383
|
+
const ColumnSizing = {
|
|
1384
|
+
getDefaultColumnDef: () => {
|
|
1385
|
+
return defaultColumnSizing;
|
|
1386
|
+
},
|
|
1387
|
+
getInitialState: state => {
|
|
1388
|
+
return {
|
|
1389
|
+
columnSizing: {},
|
|
1390
|
+
columnSizingInfo: getDefaultColumnSizingInfoState(),
|
|
1391
|
+
...state
|
|
1392
|
+
};
|
|
1393
|
+
},
|
|
1394
|
+
getDefaultOptions: table => {
|
|
1395
|
+
return {
|
|
1396
|
+
columnResizeMode: 'onEnd',
|
|
1397
|
+
columnResizeDirection: 'ltr',
|
|
1398
|
+
onColumnSizingChange: makeStateUpdater('columnSizing', table),
|
|
1399
|
+
onColumnSizingInfoChange: makeStateUpdater('columnSizingInfo', table)
|
|
1400
|
+
};
|
|
1401
|
+
},
|
|
1402
|
+
createColumn: (column, table) => {
|
|
1403
|
+
column.getSize = () => {
|
|
1404
|
+
var _column$columnDef$min, _ref, _column$columnDef$max;
|
|
1405
|
+
const columnSize = table.getState().columnSizing[column.id];
|
|
1406
|
+
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);
|
|
1407
|
+
};
|
|
1408
|
+
column.getStart = memo(position => [position, _getVisibleLeafColumns(table, position), table.getState().columnSizing], (position, columns) => columns.slice(0, column.getIndex(position)).reduce((sum, column) => sum + column.getSize(), 0), getMemoOptions(table.options, 'debugColumns', 'getStart'));
|
|
1409
|
+
column.getAfter = memo(position => [position, _getVisibleLeafColumns(table, position), table.getState().columnSizing], (position, columns) => columns.slice(column.getIndex(position) + 1).reduce((sum, column) => sum + column.getSize(), 0), getMemoOptions(table.options, 'debugColumns', 'getAfter'));
|
|
1410
|
+
column.resetSize = () => {
|
|
1411
|
+
table.setColumnSizing(_ref2 => {
|
|
1412
|
+
let {
|
|
1413
|
+
[column.id]: _,
|
|
1414
|
+
...rest
|
|
1415
|
+
} = _ref2;
|
|
1416
|
+
return rest;
|
|
1417
|
+
});
|
|
1418
|
+
};
|
|
1419
|
+
column.getCanResize = () => {
|
|
1420
|
+
var _column$columnDef$ena, _table$options$enable;
|
|
1421
|
+
return ((_column$columnDef$ena = column.columnDef.enableResizing) != null ? _column$columnDef$ena : true) && ((_table$options$enable = table.options.enableColumnResizing) != null ? _table$options$enable : true);
|
|
1422
|
+
};
|
|
1423
|
+
column.getIsResizing = () => {
|
|
1424
|
+
return table.getState().columnSizingInfo.isResizingColumn === column.id;
|
|
1425
|
+
};
|
|
1426
|
+
},
|
|
1427
|
+
createHeader: (header, table) => {
|
|
1428
|
+
header.getSize = () => {
|
|
1429
|
+
let sum = 0;
|
|
1430
|
+
const recurse = header => {
|
|
1431
|
+
if (header.subHeaders.length) {
|
|
1432
|
+
header.subHeaders.forEach(recurse);
|
|
1433
|
+
} else {
|
|
1434
|
+
var _header$column$getSiz;
|
|
1435
|
+
sum += (_header$column$getSiz = header.column.getSize()) != null ? _header$column$getSiz : 0;
|
|
1436
|
+
}
|
|
1437
|
+
};
|
|
1438
|
+
recurse(header);
|
|
1439
|
+
return sum;
|
|
1440
|
+
};
|
|
1441
|
+
header.getStart = () => {
|
|
1442
|
+
if (header.index > 0) {
|
|
1443
|
+
const prevSiblingHeader = header.headerGroup.headers[header.index - 1];
|
|
1444
|
+
return prevSiblingHeader.getStart() + prevSiblingHeader.getSize();
|
|
1445
|
+
}
|
|
1446
|
+
return 0;
|
|
1447
|
+
};
|
|
1448
|
+
header.getResizeHandler = _contextDocument => {
|
|
1449
|
+
const column = table.getColumn(header.column.id);
|
|
1450
|
+
const canResize = column == null ? void 0 : column.getCanResize();
|
|
1451
|
+
return e => {
|
|
1452
|
+
if (!column || !canResize) {
|
|
1453
|
+
return;
|
|
1454
|
+
}
|
|
1455
|
+
e.persist == null || e.persist();
|
|
1456
|
+
if (isTouchStartEvent(e)) {
|
|
1457
|
+
// lets not respond to multiple touches (e.g. 2 or 3 fingers)
|
|
1458
|
+
if (e.touches && e.touches.length > 1) {
|
|
1459
|
+
return;
|
|
1460
|
+
}
|
|
1461
|
+
}
|
|
1462
|
+
const startSize = header.getSize();
|
|
1463
|
+
const columnSizingStart = header ? header.getLeafHeaders().map(d => [d.column.id, d.column.getSize()]) : [[column.id, column.getSize()]];
|
|
1464
|
+
const clientX = isTouchStartEvent(e) ? Math.round(e.touches[0].clientX) : e.clientX;
|
|
1465
|
+
const newColumnSizing = {};
|
|
1466
|
+
const updateOffset = (eventType, clientXPos) => {
|
|
1467
|
+
if (typeof clientXPos !== 'number') {
|
|
1468
|
+
return;
|
|
1469
|
+
}
|
|
1470
|
+
table.setColumnSizingInfo(old => {
|
|
1471
|
+
var _old$startOffset, _old$startSize;
|
|
1472
|
+
const deltaDirection = table.options.columnResizeDirection === 'rtl' ? -1 : 1;
|
|
1473
|
+
const deltaOffset = (clientXPos - ((_old$startOffset = old == null ? void 0 : old.startOffset) != null ? _old$startOffset : 0)) * deltaDirection;
|
|
1474
|
+
const deltaPercentage = Math.max(deltaOffset / ((_old$startSize = old == null ? void 0 : old.startSize) != null ? _old$startSize : 0), -0.999999);
|
|
1475
|
+
old.columnSizingStart.forEach(_ref3 => {
|
|
1476
|
+
let [columnId, headerSize] = _ref3;
|
|
1477
|
+
newColumnSizing[columnId] = Math.round(Math.max(headerSize + headerSize * deltaPercentage, 0) * 100) / 100;
|
|
1478
|
+
});
|
|
1479
|
+
return {
|
|
1480
|
+
...old,
|
|
1481
|
+
deltaOffset,
|
|
1482
|
+
deltaPercentage
|
|
1483
|
+
};
|
|
1484
|
+
});
|
|
1485
|
+
if (table.options.columnResizeMode === 'onChange' || eventType === 'end') {
|
|
1486
|
+
table.setColumnSizing(old => ({
|
|
1487
|
+
...old,
|
|
1488
|
+
...newColumnSizing
|
|
1489
|
+
}));
|
|
1490
|
+
}
|
|
1491
|
+
};
|
|
1492
|
+
const onMove = clientXPos => updateOffset('move', clientXPos);
|
|
1493
|
+
const onEnd = clientXPos => {
|
|
1494
|
+
updateOffset('end', clientXPos);
|
|
1495
|
+
table.setColumnSizingInfo(old => ({
|
|
1496
|
+
...old,
|
|
1497
|
+
isResizingColumn: false,
|
|
1498
|
+
startOffset: null,
|
|
1499
|
+
startSize: null,
|
|
1500
|
+
deltaOffset: null,
|
|
1501
|
+
deltaPercentage: null,
|
|
1502
|
+
columnSizingStart: []
|
|
1503
|
+
}));
|
|
1504
|
+
};
|
|
1505
|
+
const contextDocument = safelyAccessDocument(_contextDocument);
|
|
1506
|
+
const mouseEvents = {
|
|
1507
|
+
moveHandler: e => onMove(e.clientX),
|
|
1508
|
+
upHandler: e => {
|
|
1509
|
+
contextDocument == null || contextDocument.removeEventListener('mousemove', mouseEvents.moveHandler);
|
|
1510
|
+
contextDocument == null || contextDocument.removeEventListener('mouseup', mouseEvents.upHandler);
|
|
1511
|
+
onEnd(e.clientX);
|
|
1512
|
+
}
|
|
1513
|
+
};
|
|
1514
|
+
const touchEvents = {
|
|
1515
|
+
moveHandler: e => {
|
|
1516
|
+
if (e.cancelable) {
|
|
1517
|
+
e.preventDefault();
|
|
1518
|
+
e.stopPropagation();
|
|
1519
|
+
}
|
|
1520
|
+
onMove(e.touches[0].clientX);
|
|
1521
|
+
return false;
|
|
1522
|
+
},
|
|
1523
|
+
upHandler: e => {
|
|
1524
|
+
var _e$touches$;
|
|
1525
|
+
contextDocument == null || contextDocument.removeEventListener('touchmove', touchEvents.moveHandler);
|
|
1526
|
+
contextDocument == null || contextDocument.removeEventListener('touchend', touchEvents.upHandler);
|
|
1527
|
+
if (e.cancelable) {
|
|
1528
|
+
e.preventDefault();
|
|
1529
|
+
e.stopPropagation();
|
|
1530
|
+
}
|
|
1531
|
+
onEnd((_e$touches$ = e.touches[0]) == null ? void 0 : _e$touches$.clientX);
|
|
1532
|
+
}
|
|
1533
|
+
};
|
|
1534
|
+
const passiveIfSupported = passiveEventSupported() ? {
|
|
1535
|
+
passive: false
|
|
1536
|
+
} : false;
|
|
1537
|
+
if (isTouchStartEvent(e)) {
|
|
1538
|
+
contextDocument == null || contextDocument.addEventListener('touchmove', touchEvents.moveHandler, passiveIfSupported);
|
|
1539
|
+
contextDocument == null || contextDocument.addEventListener('touchend', touchEvents.upHandler, passiveIfSupported);
|
|
1540
|
+
} else {
|
|
1541
|
+
contextDocument == null || contextDocument.addEventListener('mousemove', mouseEvents.moveHandler, passiveIfSupported);
|
|
1542
|
+
contextDocument == null || contextDocument.addEventListener('mouseup', mouseEvents.upHandler, passiveIfSupported);
|
|
1543
|
+
}
|
|
1544
|
+
table.setColumnSizingInfo(old => ({
|
|
1545
|
+
...old,
|
|
1546
|
+
startOffset: clientX,
|
|
1547
|
+
startSize,
|
|
1548
|
+
deltaOffset: 0,
|
|
1549
|
+
deltaPercentage: 0,
|
|
1550
|
+
columnSizingStart,
|
|
1551
|
+
isResizingColumn: column.id
|
|
1552
|
+
}));
|
|
1553
|
+
};
|
|
1554
|
+
};
|
|
1555
|
+
},
|
|
1556
|
+
createTable: table => {
|
|
1557
|
+
table.setColumnSizing = updater => table.options.onColumnSizingChange == null ? void 0 : table.options.onColumnSizingChange(updater);
|
|
1558
|
+
table.setColumnSizingInfo = updater => table.options.onColumnSizingInfoChange == null ? void 0 : table.options.onColumnSizingInfoChange(updater);
|
|
1559
|
+
table.resetColumnSizing = defaultState => {
|
|
1560
|
+
var _table$initialState$c;
|
|
1561
|
+
table.setColumnSizing(defaultState ? {} : (_table$initialState$c = table.initialState.columnSizing) != null ? _table$initialState$c : {});
|
|
1562
|
+
};
|
|
1563
|
+
table.resetHeaderSizeInfo = defaultState => {
|
|
1564
|
+
var _table$initialState$c2;
|
|
1565
|
+
table.setColumnSizingInfo(defaultState ? getDefaultColumnSizingInfoState() : (_table$initialState$c2 = table.initialState.columnSizingInfo) != null ? _table$initialState$c2 : getDefaultColumnSizingInfoState());
|
|
1566
|
+
};
|
|
1567
|
+
table.getTotalSize = () => {
|
|
1568
|
+
var _table$getHeaderGroup, _table$getHeaderGroup2;
|
|
1569
|
+
return (_table$getHeaderGroup = (_table$getHeaderGroup2 = table.getHeaderGroups()[0]) == null ? void 0 : _table$getHeaderGroup2.headers.reduce((sum, header) => {
|
|
1570
|
+
return sum + header.getSize();
|
|
1571
|
+
}, 0)) != null ? _table$getHeaderGroup : 0;
|
|
1572
|
+
};
|
|
1573
|
+
table.getLeftTotalSize = () => {
|
|
1574
|
+
var _table$getLeftHeaderG, _table$getLeftHeaderG2;
|
|
1575
|
+
return (_table$getLeftHeaderG = (_table$getLeftHeaderG2 = table.getLeftHeaderGroups()[0]) == null ? void 0 : _table$getLeftHeaderG2.headers.reduce((sum, header) => {
|
|
1576
|
+
return sum + header.getSize();
|
|
1577
|
+
}, 0)) != null ? _table$getLeftHeaderG : 0;
|
|
1578
|
+
};
|
|
1579
|
+
table.getCenterTotalSize = () => {
|
|
1580
|
+
var _table$getCenterHeade, _table$getCenterHeade2;
|
|
1581
|
+
return (_table$getCenterHeade = (_table$getCenterHeade2 = table.getCenterHeaderGroups()[0]) == null ? void 0 : _table$getCenterHeade2.headers.reduce((sum, header) => {
|
|
1582
|
+
return sum + header.getSize();
|
|
1583
|
+
}, 0)) != null ? _table$getCenterHeade : 0;
|
|
1584
|
+
};
|
|
1585
|
+
table.getRightTotalSize = () => {
|
|
1586
|
+
var _table$getRightHeader, _table$getRightHeader2;
|
|
1587
|
+
return (_table$getRightHeader = (_table$getRightHeader2 = table.getRightHeaderGroups()[0]) == null ? void 0 : _table$getRightHeader2.headers.reduce((sum, header) => {
|
|
1588
|
+
return sum + header.getSize();
|
|
1589
|
+
}, 0)) != null ? _table$getRightHeader : 0;
|
|
1590
|
+
};
|
|
1591
|
+
}
|
|
1592
|
+
};
|
|
1593
|
+
let passiveSupported = null;
|
|
1594
|
+
function passiveEventSupported() {
|
|
1595
|
+
if (typeof passiveSupported === 'boolean') return passiveSupported;
|
|
1596
|
+
let supported = false;
|
|
1597
|
+
try {
|
|
1598
|
+
const options = {
|
|
1599
|
+
get passive() {
|
|
1600
|
+
supported = true;
|
|
1601
|
+
return false;
|
|
1602
|
+
}
|
|
1603
|
+
};
|
|
1604
|
+
const noop = () => {};
|
|
1605
|
+
window.addEventListener('test', noop, options);
|
|
1606
|
+
window.removeEventListener('test', noop);
|
|
1607
|
+
} catch (err) {
|
|
1608
|
+
supported = false;
|
|
1609
|
+
}
|
|
1610
|
+
passiveSupported = supported;
|
|
1611
|
+
return passiveSupported;
|
|
1612
|
+
}
|
|
1613
|
+
function isTouchStartEvent(e) {
|
|
1614
|
+
return e.type === 'touchstart';
|
|
1615
|
+
}
|
|
1616
|
+
|
|
1617
|
+
//
|
|
1618
|
+
|
|
1619
|
+
const ColumnVisibility = {
|
|
1620
|
+
getInitialState: state => {
|
|
1621
|
+
return {
|
|
1622
|
+
columnVisibility: {},
|
|
1623
|
+
...state
|
|
1624
|
+
};
|
|
1625
|
+
},
|
|
1626
|
+
getDefaultOptions: table => {
|
|
1627
|
+
return {
|
|
1628
|
+
onColumnVisibilityChange: makeStateUpdater('columnVisibility', table)
|
|
1629
|
+
};
|
|
1630
|
+
},
|
|
1631
|
+
createColumn: (column, table) => {
|
|
1632
|
+
column.toggleVisibility = value => {
|
|
1633
|
+
if (column.getCanHide()) {
|
|
1634
|
+
table.setColumnVisibility(old => ({
|
|
1635
|
+
...old,
|
|
1636
|
+
[column.id]: value != null ? value : !column.getIsVisible()
|
|
1637
|
+
}));
|
|
1638
|
+
}
|
|
1639
|
+
};
|
|
1640
|
+
column.getIsVisible = () => {
|
|
1641
|
+
var _ref, _table$getState$colum;
|
|
1642
|
+
const childColumns = column.columns;
|
|
1643
|
+
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;
|
|
1644
|
+
};
|
|
1645
|
+
column.getCanHide = () => {
|
|
1646
|
+
var _column$columnDef$ena, _table$options$enable;
|
|
1647
|
+
return ((_column$columnDef$ena = column.columnDef.enableHiding) != null ? _column$columnDef$ena : true) && ((_table$options$enable = table.options.enableHiding) != null ? _table$options$enable : true);
|
|
1648
|
+
};
|
|
1649
|
+
column.getToggleVisibilityHandler = () => {
|
|
1650
|
+
return e => {
|
|
1651
|
+
column.toggleVisibility == null || column.toggleVisibility(e.target.checked);
|
|
1652
|
+
};
|
|
1653
|
+
};
|
|
1654
|
+
},
|
|
1655
|
+
createRow: (row, table) => {
|
|
1656
|
+
row._getAllVisibleCells = memo(() => [row.getAllCells(), table.getState().columnVisibility], cells => {
|
|
1657
|
+
return cells.filter(cell => cell.column.getIsVisible());
|
|
1658
|
+
}, getMemoOptions(table.options, 'debugRows', '_getAllVisibleCells'));
|
|
1659
|
+
row.getVisibleCells = memo(() => [row.getLeftVisibleCells(), row.getCenterVisibleCells(), row.getRightVisibleCells()], (left, center, right) => [...left, ...center, ...right], getMemoOptions(table.options, 'debugRows', 'getVisibleCells'));
|
|
1660
|
+
},
|
|
1661
|
+
createTable: table => {
|
|
1662
|
+
const makeVisibleColumnsMethod = (key, getColumns) => {
|
|
1663
|
+
return memo(() => [getColumns(), getColumns().filter(d => d.getIsVisible()).map(d => d.id).join('_')], columns => {
|
|
1664
|
+
return columns.filter(d => d.getIsVisible == null ? void 0 : d.getIsVisible());
|
|
1665
|
+
}, getMemoOptions(table.options, 'debugColumns', key));
|
|
1666
|
+
};
|
|
1667
|
+
table.getVisibleFlatColumns = makeVisibleColumnsMethod('getVisibleFlatColumns', () => table.getAllFlatColumns());
|
|
1668
|
+
table.getVisibleLeafColumns = makeVisibleColumnsMethod('getVisibleLeafColumns', () => table.getAllLeafColumns());
|
|
1669
|
+
table.getLeftVisibleLeafColumns = makeVisibleColumnsMethod('getLeftVisibleLeafColumns', () => table.getLeftLeafColumns());
|
|
1670
|
+
table.getRightVisibleLeafColumns = makeVisibleColumnsMethod('getRightVisibleLeafColumns', () => table.getRightLeafColumns());
|
|
1671
|
+
table.getCenterVisibleLeafColumns = makeVisibleColumnsMethod('getCenterVisibleLeafColumns', () => table.getCenterLeafColumns());
|
|
1672
|
+
table.setColumnVisibility = updater => table.options.onColumnVisibilityChange == null ? void 0 : table.options.onColumnVisibilityChange(updater);
|
|
1673
|
+
table.resetColumnVisibility = defaultState => {
|
|
1674
|
+
var _table$initialState$c;
|
|
1675
|
+
table.setColumnVisibility(defaultState ? {} : (_table$initialState$c = table.initialState.columnVisibility) != null ? _table$initialState$c : {});
|
|
1676
|
+
};
|
|
1677
|
+
table.toggleAllColumnsVisible = value => {
|
|
1678
|
+
var _value;
|
|
1679
|
+
value = (_value = value) != null ? _value : !table.getIsAllColumnsVisible();
|
|
1680
|
+
table.setColumnVisibility(table.getAllLeafColumns().reduce((obj, column) => ({
|
|
1681
|
+
...obj,
|
|
1682
|
+
[column.id]: !value ? !(column.getCanHide != null && column.getCanHide()) : value
|
|
1683
|
+
}), {}));
|
|
1684
|
+
};
|
|
1685
|
+
table.getIsAllColumnsVisible = () => !table.getAllLeafColumns().some(column => !(column.getIsVisible != null && column.getIsVisible()));
|
|
1686
|
+
table.getIsSomeColumnsVisible = () => table.getAllLeafColumns().some(column => column.getIsVisible == null ? void 0 : column.getIsVisible());
|
|
1687
|
+
table.getToggleAllColumnsVisibilityHandler = () => {
|
|
1688
|
+
return e => {
|
|
1689
|
+
var _target;
|
|
1690
|
+
table.toggleAllColumnsVisible((_target = e.target) == null ? void 0 : _target.checked);
|
|
1691
|
+
};
|
|
1692
|
+
};
|
|
1693
|
+
}
|
|
1694
|
+
};
|
|
1695
|
+
function _getVisibleLeafColumns(table, position) {
|
|
1696
|
+
return !position ? table.getVisibleLeafColumns() : position === 'center' ? table.getCenterVisibleLeafColumns() : position === 'left' ? table.getLeftVisibleLeafColumns() : table.getRightVisibleLeafColumns();
|
|
1697
|
+
}
|
|
1698
|
+
|
|
1699
|
+
//
|
|
1700
|
+
|
|
1701
|
+
const GlobalFaceting = {
|
|
1702
|
+
createTable: table => {
|
|
1703
|
+
table._getGlobalFacetedRowModel = table.options.getFacetedRowModel && table.options.getFacetedRowModel(table, '__global__');
|
|
1704
|
+
table.getGlobalFacetedRowModel = () => {
|
|
1705
|
+
if (table.options.manualFiltering || !table._getGlobalFacetedRowModel) {
|
|
1706
|
+
return table.getPreFilteredRowModel();
|
|
1707
|
+
}
|
|
1708
|
+
return table._getGlobalFacetedRowModel();
|
|
1709
|
+
};
|
|
1710
|
+
table._getGlobalFacetedUniqueValues = table.options.getFacetedUniqueValues && table.options.getFacetedUniqueValues(table, '__global__');
|
|
1711
|
+
table.getGlobalFacetedUniqueValues = () => {
|
|
1712
|
+
if (!table._getGlobalFacetedUniqueValues) {
|
|
1713
|
+
return new Map();
|
|
1714
|
+
}
|
|
1715
|
+
return table._getGlobalFacetedUniqueValues();
|
|
1716
|
+
};
|
|
1717
|
+
table._getGlobalFacetedMinMaxValues = table.options.getFacetedMinMaxValues && table.options.getFacetedMinMaxValues(table, '__global__');
|
|
1718
|
+
table.getGlobalFacetedMinMaxValues = () => {
|
|
1719
|
+
if (!table._getGlobalFacetedMinMaxValues) {
|
|
1720
|
+
return;
|
|
1721
|
+
}
|
|
1722
|
+
return table._getGlobalFacetedMinMaxValues();
|
|
1723
|
+
};
|
|
1724
|
+
}
|
|
1725
|
+
};
|
|
1726
|
+
|
|
1727
|
+
//
|
|
1728
|
+
|
|
1729
|
+
const GlobalFiltering = {
|
|
1730
|
+
getInitialState: state => {
|
|
1731
|
+
return {
|
|
1732
|
+
globalFilter: undefined,
|
|
1733
|
+
...state
|
|
1734
|
+
};
|
|
1735
|
+
},
|
|
1736
|
+
getDefaultOptions: table => {
|
|
1737
|
+
return {
|
|
1738
|
+
onGlobalFilterChange: makeStateUpdater('globalFilter', table),
|
|
1739
|
+
globalFilterFn: 'auto',
|
|
1740
|
+
getColumnCanGlobalFilter: column => {
|
|
1741
|
+
var _table$getCoreRowMode;
|
|
1742
|
+
const value = (_table$getCoreRowMode = table.getCoreRowModel().flatRows[0]) == null || (_table$getCoreRowMode = _table$getCoreRowMode._getAllCellsByColumnId()[column.id]) == null ? void 0 : _table$getCoreRowMode.getValue();
|
|
1743
|
+
return typeof value === 'string' || typeof value === 'number';
|
|
1744
|
+
}
|
|
1745
|
+
};
|
|
1746
|
+
},
|
|
1747
|
+
createColumn: (column, table) => {
|
|
1748
|
+
column.getCanGlobalFilter = () => {
|
|
1749
|
+
var _column$columnDef$ena, _table$options$enable, _table$options$enable2, _table$options$getCol;
|
|
1750
|
+
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;
|
|
1751
|
+
};
|
|
1752
|
+
},
|
|
1753
|
+
createTable: table => {
|
|
1754
|
+
table.getGlobalAutoFilterFn = () => {
|
|
1755
|
+
return filterFns.includesString;
|
|
1756
|
+
};
|
|
1757
|
+
table.getGlobalFilterFn = () => {
|
|
1758
|
+
var _table$options$filter, _table$options$filter2;
|
|
1759
|
+
const {
|
|
1760
|
+
globalFilterFn: globalFilterFn
|
|
1761
|
+
} = table.options;
|
|
1762
|
+
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];
|
|
1763
|
+
};
|
|
1764
|
+
table.setGlobalFilter = updater => {
|
|
1765
|
+
table.options.onGlobalFilterChange == null || table.options.onGlobalFilterChange(updater);
|
|
1766
|
+
};
|
|
1767
|
+
table.resetGlobalFilter = defaultState => {
|
|
1768
|
+
table.setGlobalFilter(defaultState ? undefined : table.initialState.globalFilter);
|
|
1769
|
+
};
|
|
1770
|
+
}
|
|
1771
|
+
};
|
|
1772
|
+
|
|
1773
|
+
//
|
|
1774
|
+
|
|
1775
|
+
const RowExpanding = {
|
|
1776
|
+
getInitialState: state => {
|
|
1777
|
+
return {
|
|
1778
|
+
expanded: {},
|
|
1779
|
+
...state
|
|
1780
|
+
};
|
|
1781
|
+
},
|
|
1782
|
+
getDefaultOptions: table => {
|
|
1783
|
+
return {
|
|
1784
|
+
onExpandedChange: makeStateUpdater('expanded', table),
|
|
1785
|
+
paginateExpandedRows: true
|
|
1786
|
+
};
|
|
1787
|
+
},
|
|
1788
|
+
createTable: table => {
|
|
1789
|
+
let registered = false;
|
|
1790
|
+
let queued = false;
|
|
1791
|
+
table._autoResetExpanded = () => {
|
|
1792
|
+
var _ref, _table$options$autoRe;
|
|
1793
|
+
if (!registered) {
|
|
1794
|
+
table._queue(() => {
|
|
1795
|
+
registered = true;
|
|
1796
|
+
});
|
|
1797
|
+
return;
|
|
1798
|
+
}
|
|
1799
|
+
if ((_ref = (_table$options$autoRe = table.options.autoResetAll) != null ? _table$options$autoRe : table.options.autoResetExpanded) != null ? _ref : !table.options.manualExpanding) {
|
|
1800
|
+
if (queued) return;
|
|
1801
|
+
queued = true;
|
|
1802
|
+
table._queue(() => {
|
|
1803
|
+
table.resetExpanded();
|
|
1804
|
+
queued = false;
|
|
1805
|
+
});
|
|
1806
|
+
}
|
|
1807
|
+
};
|
|
1808
|
+
table.setExpanded = updater => table.options.onExpandedChange == null ? void 0 : table.options.onExpandedChange(updater);
|
|
1809
|
+
table.toggleAllRowsExpanded = expanded => {
|
|
1810
|
+
if (expanded != null ? expanded : !table.getIsAllRowsExpanded()) {
|
|
1811
|
+
table.setExpanded(true);
|
|
1812
|
+
} else {
|
|
1813
|
+
table.setExpanded({});
|
|
1814
|
+
}
|
|
1815
|
+
};
|
|
1816
|
+
table.resetExpanded = defaultState => {
|
|
1817
|
+
var _table$initialState$e, _table$initialState;
|
|
1818
|
+
table.setExpanded(defaultState ? {} : (_table$initialState$e = (_table$initialState = table.initialState) == null ? void 0 : _table$initialState.expanded) != null ? _table$initialState$e : {});
|
|
1819
|
+
};
|
|
1820
|
+
table.getCanSomeRowsExpand = () => {
|
|
1821
|
+
return table.getPrePaginationRowModel().flatRows.some(row => row.getCanExpand());
|
|
1822
|
+
};
|
|
1823
|
+
table.getToggleAllRowsExpandedHandler = () => {
|
|
1824
|
+
return e => {
|
|
1825
|
+
e.persist == null || e.persist();
|
|
1826
|
+
table.toggleAllRowsExpanded();
|
|
1827
|
+
};
|
|
1828
|
+
};
|
|
1829
|
+
table.getIsSomeRowsExpanded = () => {
|
|
1830
|
+
const expanded = table.getState().expanded;
|
|
1831
|
+
return expanded === true || Object.values(expanded).some(Boolean);
|
|
1832
|
+
};
|
|
1833
|
+
table.getIsAllRowsExpanded = () => {
|
|
1834
|
+
const expanded = table.getState().expanded;
|
|
1835
|
+
|
|
1836
|
+
// If expanded is true, save some cycles and return true
|
|
1837
|
+
if (typeof expanded === 'boolean') {
|
|
1838
|
+
return expanded === true;
|
|
1839
|
+
}
|
|
1840
|
+
if (!Object.keys(expanded).length) {
|
|
1841
|
+
return false;
|
|
1842
|
+
}
|
|
1843
|
+
|
|
1844
|
+
// If any row is not expanded, return false
|
|
1845
|
+
if (table.getRowModel().flatRows.some(row => !row.getIsExpanded())) {
|
|
1846
|
+
return false;
|
|
1847
|
+
}
|
|
1848
|
+
|
|
1849
|
+
// They must all be expanded :shrug:
|
|
1850
|
+
return true;
|
|
1851
|
+
};
|
|
1852
|
+
table.getExpandedDepth = () => {
|
|
1853
|
+
let maxDepth = 0;
|
|
1854
|
+
const rowIds = table.getState().expanded === true ? Object.keys(table.getRowModel().rowsById) : Object.keys(table.getState().expanded);
|
|
1855
|
+
rowIds.forEach(id => {
|
|
1856
|
+
const splitId = id.split('.');
|
|
1857
|
+
maxDepth = Math.max(maxDepth, splitId.length);
|
|
1858
|
+
});
|
|
1859
|
+
return maxDepth;
|
|
1860
|
+
};
|
|
1861
|
+
table.getPreExpandedRowModel = () => table.getSortedRowModel();
|
|
1862
|
+
table.getExpandedRowModel = () => {
|
|
1863
|
+
if (!table._getExpandedRowModel && table.options.getExpandedRowModel) {
|
|
1864
|
+
table._getExpandedRowModel = table.options.getExpandedRowModel(table);
|
|
1865
|
+
}
|
|
1866
|
+
if (table.options.manualExpanding || !table._getExpandedRowModel) {
|
|
1867
|
+
return table.getPreExpandedRowModel();
|
|
1868
|
+
}
|
|
1869
|
+
return table._getExpandedRowModel();
|
|
1870
|
+
};
|
|
1871
|
+
},
|
|
1872
|
+
createRow: (row, table) => {
|
|
1873
|
+
row.toggleExpanded = expanded => {
|
|
1874
|
+
table.setExpanded(old => {
|
|
1875
|
+
var _expanded;
|
|
1876
|
+
const exists = old === true ? true : !!(old != null && old[row.id]);
|
|
1877
|
+
let oldExpanded = {};
|
|
1878
|
+
if (old === true) {
|
|
1879
|
+
Object.keys(table.getRowModel().rowsById).forEach(rowId => {
|
|
1880
|
+
oldExpanded[rowId] = true;
|
|
1881
|
+
});
|
|
1882
|
+
} else {
|
|
1883
|
+
oldExpanded = old;
|
|
1884
|
+
}
|
|
1885
|
+
expanded = (_expanded = expanded) != null ? _expanded : !exists;
|
|
1886
|
+
if (!exists && expanded) {
|
|
1887
|
+
return {
|
|
1888
|
+
...oldExpanded,
|
|
1889
|
+
[row.id]: true
|
|
1890
|
+
};
|
|
1891
|
+
}
|
|
1892
|
+
if (exists && !expanded) {
|
|
1893
|
+
const {
|
|
1894
|
+
[row.id]: _,
|
|
1895
|
+
...rest
|
|
1896
|
+
} = oldExpanded;
|
|
1897
|
+
return rest;
|
|
1898
|
+
}
|
|
1899
|
+
return old;
|
|
1900
|
+
});
|
|
1901
|
+
};
|
|
1902
|
+
row.getIsExpanded = () => {
|
|
1903
|
+
var _table$options$getIsR;
|
|
1904
|
+
const expanded = table.getState().expanded;
|
|
1905
|
+
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]));
|
|
1906
|
+
};
|
|
1907
|
+
row.getCanExpand = () => {
|
|
1908
|
+
var _table$options$getRow, _table$options$enable, _row$subRows;
|
|
1909
|
+
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);
|
|
1910
|
+
};
|
|
1911
|
+
row.getIsAllParentsExpanded = () => {
|
|
1912
|
+
let isFullyExpanded = true;
|
|
1913
|
+
let currentRow = row;
|
|
1914
|
+
while (isFullyExpanded && currentRow.parentId) {
|
|
1915
|
+
currentRow = table.getRow(currentRow.parentId, true);
|
|
1916
|
+
isFullyExpanded = currentRow.getIsExpanded();
|
|
1917
|
+
}
|
|
1918
|
+
return isFullyExpanded;
|
|
1919
|
+
};
|
|
1920
|
+
row.getToggleExpandedHandler = () => {
|
|
1921
|
+
const canExpand = row.getCanExpand();
|
|
1922
|
+
return () => {
|
|
1923
|
+
if (!canExpand) return;
|
|
1924
|
+
row.toggleExpanded();
|
|
1925
|
+
};
|
|
1926
|
+
};
|
|
1927
|
+
}
|
|
1928
|
+
};
|
|
1929
|
+
|
|
1930
|
+
//
|
|
1931
|
+
|
|
1932
|
+
const defaultPageIndex = 0;
|
|
1933
|
+
const defaultPageSize = 10;
|
|
1934
|
+
const getDefaultPaginationState = () => ({
|
|
1935
|
+
pageIndex: defaultPageIndex,
|
|
1936
|
+
pageSize: defaultPageSize
|
|
1937
|
+
});
|
|
1938
|
+
const RowPagination = {
|
|
1939
|
+
getInitialState: state => {
|
|
1940
|
+
return {
|
|
1941
|
+
...state,
|
|
1942
|
+
pagination: {
|
|
1943
|
+
...getDefaultPaginationState(),
|
|
1944
|
+
...(state == null ? void 0 : state.pagination)
|
|
1945
|
+
}
|
|
1946
|
+
};
|
|
1947
|
+
},
|
|
1948
|
+
getDefaultOptions: table => {
|
|
1949
|
+
return {
|
|
1950
|
+
onPaginationChange: makeStateUpdater('pagination', table)
|
|
1951
|
+
};
|
|
1952
|
+
},
|
|
1953
|
+
createTable: table => {
|
|
1954
|
+
let registered = false;
|
|
1955
|
+
let queued = false;
|
|
1956
|
+
table._autoResetPageIndex = () => {
|
|
1957
|
+
var _ref, _table$options$autoRe;
|
|
1958
|
+
if (!registered) {
|
|
1959
|
+
table._queue(() => {
|
|
1960
|
+
registered = true;
|
|
1961
|
+
});
|
|
1962
|
+
return;
|
|
1963
|
+
}
|
|
1964
|
+
if ((_ref = (_table$options$autoRe = table.options.autoResetAll) != null ? _table$options$autoRe : table.options.autoResetPageIndex) != null ? _ref : !table.options.manualPagination) {
|
|
1965
|
+
if (queued) return;
|
|
1966
|
+
queued = true;
|
|
1967
|
+
table._queue(() => {
|
|
1968
|
+
table.resetPageIndex();
|
|
1969
|
+
queued = false;
|
|
1970
|
+
});
|
|
1971
|
+
}
|
|
1972
|
+
};
|
|
1973
|
+
table.setPagination = updater => {
|
|
1974
|
+
const safeUpdater = old => {
|
|
1975
|
+
let newState = functionalUpdate(updater, old);
|
|
1976
|
+
return newState;
|
|
1977
|
+
};
|
|
1978
|
+
return table.options.onPaginationChange == null ? void 0 : table.options.onPaginationChange(safeUpdater);
|
|
1979
|
+
};
|
|
1980
|
+
table.resetPagination = defaultState => {
|
|
1981
|
+
var _table$initialState$p;
|
|
1982
|
+
table.setPagination(defaultState ? getDefaultPaginationState() : (_table$initialState$p = table.initialState.pagination) != null ? _table$initialState$p : getDefaultPaginationState());
|
|
1983
|
+
};
|
|
1984
|
+
table.setPageIndex = updater => {
|
|
1985
|
+
table.setPagination(old => {
|
|
1986
|
+
let pageIndex = functionalUpdate(updater, old.pageIndex);
|
|
1987
|
+
const maxPageIndex = typeof table.options.pageCount === 'undefined' || table.options.pageCount === -1 ? Number.MAX_SAFE_INTEGER : table.options.pageCount - 1;
|
|
1988
|
+
pageIndex = Math.max(0, Math.min(pageIndex, maxPageIndex));
|
|
1989
|
+
return {
|
|
1990
|
+
...old,
|
|
1991
|
+
pageIndex
|
|
1992
|
+
};
|
|
1993
|
+
});
|
|
1994
|
+
};
|
|
1995
|
+
table.resetPageIndex = defaultState => {
|
|
1996
|
+
var _table$initialState$p2, _table$initialState;
|
|
1997
|
+
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);
|
|
1998
|
+
};
|
|
1999
|
+
table.resetPageSize = defaultState => {
|
|
2000
|
+
var _table$initialState$p3, _table$initialState2;
|
|
2001
|
+
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);
|
|
2002
|
+
};
|
|
2003
|
+
table.setPageSize = updater => {
|
|
2004
|
+
table.setPagination(old => {
|
|
2005
|
+
const pageSize = Math.max(1, functionalUpdate(updater, old.pageSize));
|
|
2006
|
+
const topRowIndex = old.pageSize * old.pageIndex;
|
|
2007
|
+
const pageIndex = Math.floor(topRowIndex / pageSize);
|
|
2008
|
+
return {
|
|
2009
|
+
...old,
|
|
2010
|
+
pageIndex,
|
|
2011
|
+
pageSize
|
|
2012
|
+
};
|
|
2013
|
+
});
|
|
2014
|
+
};
|
|
2015
|
+
//deprecated
|
|
2016
|
+
table.setPageCount = updater => table.setPagination(old => {
|
|
2017
|
+
var _table$options$pageCo;
|
|
2018
|
+
let newPageCount = functionalUpdate(updater, (_table$options$pageCo = table.options.pageCount) != null ? _table$options$pageCo : -1);
|
|
2019
|
+
if (typeof newPageCount === 'number') {
|
|
2020
|
+
newPageCount = Math.max(-1, newPageCount);
|
|
2021
|
+
}
|
|
2022
|
+
return {
|
|
2023
|
+
...old,
|
|
2024
|
+
pageCount: newPageCount
|
|
2025
|
+
};
|
|
2026
|
+
});
|
|
2027
|
+
table.getPageOptions = memo(() => [table.getPageCount()], pageCount => {
|
|
2028
|
+
let pageOptions = [];
|
|
2029
|
+
if (pageCount && pageCount > 0) {
|
|
2030
|
+
pageOptions = [...new Array(pageCount)].fill(null).map((_, i) => i);
|
|
2031
|
+
}
|
|
2032
|
+
return pageOptions;
|
|
2033
|
+
}, getMemoOptions(table.options, 'debugTable', 'getPageOptions'));
|
|
2034
|
+
table.getCanPreviousPage = () => table.getState().pagination.pageIndex > 0;
|
|
2035
|
+
table.getCanNextPage = () => {
|
|
2036
|
+
const {
|
|
2037
|
+
pageIndex
|
|
2038
|
+
} = table.getState().pagination;
|
|
2039
|
+
const pageCount = table.getPageCount();
|
|
2040
|
+
if (pageCount === -1) {
|
|
2041
|
+
return true;
|
|
2042
|
+
}
|
|
2043
|
+
if (pageCount === 0) {
|
|
2044
|
+
return false;
|
|
2045
|
+
}
|
|
2046
|
+
return pageIndex < pageCount - 1;
|
|
2047
|
+
};
|
|
2048
|
+
table.previousPage = () => {
|
|
2049
|
+
return table.setPageIndex(old => old - 1);
|
|
2050
|
+
};
|
|
2051
|
+
table.nextPage = () => {
|
|
2052
|
+
return table.setPageIndex(old => {
|
|
2053
|
+
return old + 1;
|
|
2054
|
+
});
|
|
2055
|
+
};
|
|
2056
|
+
table.firstPage = () => {
|
|
2057
|
+
return table.setPageIndex(0);
|
|
2058
|
+
};
|
|
2059
|
+
table.lastPage = () => {
|
|
2060
|
+
return table.setPageIndex(table.getPageCount() - 1);
|
|
2061
|
+
};
|
|
2062
|
+
table.getPrePaginationRowModel = () => table.getExpandedRowModel();
|
|
2063
|
+
table.getPaginationRowModel = () => {
|
|
2064
|
+
if (!table._getPaginationRowModel && table.options.getPaginationRowModel) {
|
|
2065
|
+
table._getPaginationRowModel = table.options.getPaginationRowModel(table);
|
|
2066
|
+
}
|
|
2067
|
+
if (table.options.manualPagination || !table._getPaginationRowModel) {
|
|
2068
|
+
return table.getPrePaginationRowModel();
|
|
2069
|
+
}
|
|
2070
|
+
return table._getPaginationRowModel();
|
|
2071
|
+
};
|
|
2072
|
+
table.getPageCount = () => {
|
|
2073
|
+
var _table$options$pageCo2;
|
|
2074
|
+
return (_table$options$pageCo2 = table.options.pageCount) != null ? _table$options$pageCo2 : Math.ceil(table.getRowCount() / table.getState().pagination.pageSize);
|
|
2075
|
+
};
|
|
2076
|
+
table.getRowCount = () => {
|
|
2077
|
+
var _table$options$rowCou;
|
|
2078
|
+
return (_table$options$rowCou = table.options.rowCount) != null ? _table$options$rowCou : table.getPrePaginationRowModel().rows.length;
|
|
2079
|
+
};
|
|
2080
|
+
}
|
|
2081
|
+
};
|
|
2082
|
+
|
|
2083
|
+
//
|
|
2084
|
+
|
|
2085
|
+
const getDefaultRowPinningState = () => ({
|
|
2086
|
+
top: [],
|
|
2087
|
+
bottom: []
|
|
2088
|
+
});
|
|
2089
|
+
const RowPinning = {
|
|
2090
|
+
getInitialState: state => {
|
|
2091
|
+
return {
|
|
2092
|
+
rowPinning: getDefaultRowPinningState(),
|
|
2093
|
+
...state
|
|
2094
|
+
};
|
|
2095
|
+
},
|
|
2096
|
+
getDefaultOptions: table => {
|
|
2097
|
+
return {
|
|
2098
|
+
onRowPinningChange: makeStateUpdater('rowPinning', table)
|
|
2099
|
+
};
|
|
2100
|
+
},
|
|
2101
|
+
createRow: (row, table) => {
|
|
2102
|
+
row.pin = (position, includeLeafRows, includeParentRows) => {
|
|
2103
|
+
const leafRowIds = includeLeafRows ? row.getLeafRows().map(_ref => {
|
|
2104
|
+
let {
|
|
2105
|
+
id
|
|
2106
|
+
} = _ref;
|
|
2107
|
+
return id;
|
|
2108
|
+
}) : [];
|
|
2109
|
+
const parentRowIds = includeParentRows ? row.getParentRows().map(_ref2 => {
|
|
2110
|
+
let {
|
|
2111
|
+
id
|
|
2112
|
+
} = _ref2;
|
|
2113
|
+
return id;
|
|
2114
|
+
}) : [];
|
|
2115
|
+
const rowIds = new Set([...parentRowIds, row.id, ...leafRowIds]);
|
|
2116
|
+
table.setRowPinning(old => {
|
|
2117
|
+
var _old$top3, _old$bottom3;
|
|
2118
|
+
if (position === 'bottom') {
|
|
2119
|
+
var _old$top, _old$bottom;
|
|
2120
|
+
return {
|
|
2121
|
+
top: ((_old$top = old == null ? void 0 : old.top) != null ? _old$top : []).filter(d => !(rowIds != null && rowIds.has(d))),
|
|
2122
|
+
bottom: [...((_old$bottom = old == null ? void 0 : old.bottom) != null ? _old$bottom : []).filter(d => !(rowIds != null && rowIds.has(d))), ...Array.from(rowIds)]
|
|
2123
|
+
};
|
|
2124
|
+
}
|
|
2125
|
+
if (position === 'top') {
|
|
2126
|
+
var _old$top2, _old$bottom2;
|
|
2127
|
+
return {
|
|
2128
|
+
top: [...((_old$top2 = old == null ? void 0 : old.top) != null ? _old$top2 : []).filter(d => !(rowIds != null && rowIds.has(d))), ...Array.from(rowIds)],
|
|
2129
|
+
bottom: ((_old$bottom2 = old == null ? void 0 : old.bottom) != null ? _old$bottom2 : []).filter(d => !(rowIds != null && rowIds.has(d)))
|
|
2130
|
+
};
|
|
2131
|
+
}
|
|
2132
|
+
return {
|
|
2133
|
+
top: ((_old$top3 = old == null ? void 0 : old.top) != null ? _old$top3 : []).filter(d => !(rowIds != null && rowIds.has(d))),
|
|
2134
|
+
bottom: ((_old$bottom3 = old == null ? void 0 : old.bottom) != null ? _old$bottom3 : []).filter(d => !(rowIds != null && rowIds.has(d)))
|
|
2135
|
+
};
|
|
2136
|
+
});
|
|
2137
|
+
};
|
|
2138
|
+
row.getCanPin = () => {
|
|
2139
|
+
var _ref3;
|
|
2140
|
+
const {
|
|
2141
|
+
enableRowPinning,
|
|
2142
|
+
enablePinning
|
|
2143
|
+
} = table.options;
|
|
2144
|
+
if (typeof enableRowPinning === 'function') {
|
|
2145
|
+
return enableRowPinning(row);
|
|
2146
|
+
}
|
|
2147
|
+
return (_ref3 = enableRowPinning != null ? enableRowPinning : enablePinning) != null ? _ref3 : true;
|
|
2148
|
+
};
|
|
2149
|
+
row.getIsPinned = () => {
|
|
2150
|
+
const rowIds = [row.id];
|
|
2151
|
+
const {
|
|
2152
|
+
top,
|
|
2153
|
+
bottom
|
|
2154
|
+
} = table.getState().rowPinning;
|
|
2155
|
+
const isTop = rowIds.some(d => top == null ? void 0 : top.includes(d));
|
|
2156
|
+
const isBottom = rowIds.some(d => bottom == null ? void 0 : bottom.includes(d));
|
|
2157
|
+
return isTop ? 'top' : isBottom ? 'bottom' : false;
|
|
2158
|
+
};
|
|
2159
|
+
row.getPinnedIndex = () => {
|
|
2160
|
+
var _ref4, _visiblePinnedRowIds$;
|
|
2161
|
+
const position = row.getIsPinned();
|
|
2162
|
+
if (!position) return -1;
|
|
2163
|
+
const visiblePinnedRowIds = (_ref4 = position === 'top' ? table.getTopRows() : table.getBottomRows()) == null ? void 0 : _ref4.map(_ref5 => {
|
|
2164
|
+
let {
|
|
2165
|
+
id
|
|
2166
|
+
} = _ref5;
|
|
2167
|
+
return id;
|
|
2168
|
+
});
|
|
2169
|
+
return (_visiblePinnedRowIds$ = visiblePinnedRowIds == null ? void 0 : visiblePinnedRowIds.indexOf(row.id)) != null ? _visiblePinnedRowIds$ : -1;
|
|
2170
|
+
};
|
|
2171
|
+
},
|
|
2172
|
+
createTable: table => {
|
|
2173
|
+
table.setRowPinning = updater => table.options.onRowPinningChange == null ? void 0 : table.options.onRowPinningChange(updater);
|
|
2174
|
+
table.resetRowPinning = defaultState => {
|
|
2175
|
+
var _table$initialState$r, _table$initialState;
|
|
2176
|
+
return table.setRowPinning(defaultState ? getDefaultRowPinningState() : (_table$initialState$r = (_table$initialState = table.initialState) == null ? void 0 : _table$initialState.rowPinning) != null ? _table$initialState$r : getDefaultRowPinningState());
|
|
2177
|
+
};
|
|
2178
|
+
table.getIsSomeRowsPinned = position => {
|
|
2179
|
+
var _pinningState$positio;
|
|
2180
|
+
const pinningState = table.getState().rowPinning;
|
|
2181
|
+
if (!position) {
|
|
2182
|
+
var _pinningState$top, _pinningState$bottom;
|
|
2183
|
+
return Boolean(((_pinningState$top = pinningState.top) == null ? void 0 : _pinningState$top.length) || ((_pinningState$bottom = pinningState.bottom) == null ? void 0 : _pinningState$bottom.length));
|
|
2184
|
+
}
|
|
2185
|
+
return Boolean((_pinningState$positio = pinningState[position]) == null ? void 0 : _pinningState$positio.length);
|
|
2186
|
+
};
|
|
2187
|
+
table._getPinnedRows = (visibleRows, pinnedRowIds, position) => {
|
|
2188
|
+
var _table$options$keepPi;
|
|
2189
|
+
const rows = ((_table$options$keepPi = table.options.keepPinnedRows) != null ? _table$options$keepPi : true) ?
|
|
2190
|
+
//get all rows that are pinned even if they would not be otherwise visible
|
|
2191
|
+
//account for expanded parent rows, but not pagination or filtering
|
|
2192
|
+
(pinnedRowIds != null ? pinnedRowIds : []).map(rowId => {
|
|
2193
|
+
const row = table.getRow(rowId, true);
|
|
2194
|
+
return row.getIsAllParentsExpanded() ? row : null;
|
|
2195
|
+
}) :
|
|
2196
|
+
//else get only visible rows that are pinned
|
|
2197
|
+
(pinnedRowIds != null ? pinnedRowIds : []).map(rowId => visibleRows.find(row => row.id === rowId));
|
|
2198
|
+
return rows.filter(Boolean).map(d => ({
|
|
2199
|
+
...d,
|
|
2200
|
+
position
|
|
2201
|
+
}));
|
|
2202
|
+
};
|
|
2203
|
+
table.getTopRows = memo(() => [table.getRowModel().rows, table.getState().rowPinning.top], (allRows, topPinnedRowIds) => table._getPinnedRows(allRows, topPinnedRowIds, 'top'), getMemoOptions(table.options, 'debugRows', 'getTopRows'));
|
|
2204
|
+
table.getBottomRows = memo(() => [table.getRowModel().rows, table.getState().rowPinning.bottom], (allRows, bottomPinnedRowIds) => table._getPinnedRows(allRows, bottomPinnedRowIds, 'bottom'), getMemoOptions(table.options, 'debugRows', 'getBottomRows'));
|
|
2205
|
+
table.getCenterRows = memo(() => [table.getRowModel().rows, table.getState().rowPinning.top, table.getState().rowPinning.bottom], (allRows, top, bottom) => {
|
|
2206
|
+
const topAndBottom = new Set([...(top != null ? top : []), ...(bottom != null ? bottom : [])]);
|
|
2207
|
+
return allRows.filter(d => !topAndBottom.has(d.id));
|
|
2208
|
+
}, getMemoOptions(table.options, 'debugRows', 'getCenterRows'));
|
|
2209
|
+
}
|
|
2210
|
+
};
|
|
2211
|
+
|
|
2212
|
+
//
|
|
2213
|
+
|
|
2214
|
+
const RowSelection = {
|
|
2215
|
+
getInitialState: state => {
|
|
2216
|
+
return {
|
|
2217
|
+
rowSelection: {},
|
|
2218
|
+
...state
|
|
2219
|
+
};
|
|
2220
|
+
},
|
|
2221
|
+
getDefaultOptions: table => {
|
|
2222
|
+
return {
|
|
2223
|
+
onRowSelectionChange: makeStateUpdater('rowSelection', table),
|
|
2224
|
+
enableRowSelection: true,
|
|
2225
|
+
enableMultiRowSelection: true,
|
|
2226
|
+
enableSubRowSelection: true
|
|
2227
|
+
// enableGroupingRowSelection: false,
|
|
2228
|
+
// isAdditiveSelectEvent: (e: unknown) => !!e.metaKey,
|
|
2229
|
+
// isInclusiveSelectEvent: (e: unknown) => !!e.shiftKey,
|
|
2230
|
+
};
|
|
2231
|
+
},
|
|
2232
|
+
createTable: table => {
|
|
2233
|
+
table.setRowSelection = updater => table.options.onRowSelectionChange == null ? void 0 : table.options.onRowSelectionChange(updater);
|
|
2234
|
+
table.resetRowSelection = defaultState => {
|
|
2235
|
+
var _table$initialState$r;
|
|
2236
|
+
return table.setRowSelection(defaultState ? {} : (_table$initialState$r = table.initialState.rowSelection) != null ? _table$initialState$r : {});
|
|
2237
|
+
};
|
|
2238
|
+
table.toggleAllRowsSelected = value => {
|
|
2239
|
+
table.setRowSelection(old => {
|
|
2240
|
+
value = typeof value !== 'undefined' ? value : !table.getIsAllRowsSelected();
|
|
2241
|
+
const rowSelection = {
|
|
2242
|
+
...old
|
|
2243
|
+
};
|
|
2244
|
+
const preGroupedFlatRows = table.getPreGroupedRowModel().flatRows;
|
|
2245
|
+
|
|
2246
|
+
// We don't use `mutateRowIsSelected` here for performance reasons.
|
|
2247
|
+
// All of the rows are flat already, so it wouldn't be worth it
|
|
2248
|
+
if (value) {
|
|
2249
|
+
preGroupedFlatRows.forEach(row => {
|
|
2250
|
+
if (!row.getCanSelect()) {
|
|
2251
|
+
return;
|
|
2252
|
+
}
|
|
2253
|
+
rowSelection[row.id] = true;
|
|
2254
|
+
});
|
|
2255
|
+
} else {
|
|
2256
|
+
preGroupedFlatRows.forEach(row => {
|
|
2257
|
+
delete rowSelection[row.id];
|
|
2258
|
+
});
|
|
2259
|
+
}
|
|
2260
|
+
return rowSelection;
|
|
2261
|
+
});
|
|
2262
|
+
};
|
|
2263
|
+
table.toggleAllPageRowsSelected = value => table.setRowSelection(old => {
|
|
2264
|
+
const resolvedValue = typeof value !== 'undefined' ? value : !table.getIsAllPageRowsSelected();
|
|
2265
|
+
const rowSelection = {
|
|
2266
|
+
...old
|
|
2267
|
+
};
|
|
2268
|
+
table.getRowModel().rows.forEach(row => {
|
|
2269
|
+
mutateRowIsSelected(rowSelection, row.id, resolvedValue, true, table);
|
|
2270
|
+
});
|
|
2271
|
+
return rowSelection;
|
|
2272
|
+
});
|
|
2273
|
+
|
|
2274
|
+
// addRowSelectionRange: rowId => {
|
|
2275
|
+
// const {
|
|
2276
|
+
// rows,
|
|
2277
|
+
// rowsById,
|
|
2278
|
+
// options: { selectGroupingRows, selectSubRows },
|
|
2279
|
+
// } = table
|
|
2280
|
+
|
|
2281
|
+
// const findSelectedRow = (rows: Row[]) => {
|
|
2282
|
+
// let found
|
|
2283
|
+
// rows.find(d => {
|
|
2284
|
+
// if (d.getIsSelected()) {
|
|
2285
|
+
// found = d
|
|
2286
|
+
// return true
|
|
2287
|
+
// }
|
|
2288
|
+
// const subFound = findSelectedRow(d.subRows || [])
|
|
2289
|
+
// if (subFound) {
|
|
2290
|
+
// found = subFound
|
|
2291
|
+
// return true
|
|
2292
|
+
// }
|
|
2293
|
+
// return false
|
|
2294
|
+
// })
|
|
2295
|
+
// return found
|
|
2296
|
+
// }
|
|
2297
|
+
|
|
2298
|
+
// const firstRow = findSelectedRow(rows) || rows[0]
|
|
2299
|
+
// const lastRow = rowsById[rowId]
|
|
2300
|
+
|
|
2301
|
+
// let include = false
|
|
2302
|
+
// const selectedRowIds = {}
|
|
2303
|
+
|
|
2304
|
+
// const addRow = (row: Row) => {
|
|
2305
|
+
// mutateRowIsSelected(selectedRowIds, row.id, true, {
|
|
2306
|
+
// rowsById,
|
|
2307
|
+
// selectGroupingRows: selectGroupingRows!,
|
|
2308
|
+
// selectSubRows: selectSubRows!,
|
|
2309
|
+
// })
|
|
2310
|
+
// }
|
|
2311
|
+
|
|
2312
|
+
// table.rows.forEach(row => {
|
|
2313
|
+
// const isFirstRow = row.id === firstRow.id
|
|
2314
|
+
// const isLastRow = row.id === lastRow.id
|
|
2315
|
+
|
|
2316
|
+
// if (isFirstRow || isLastRow) {
|
|
2317
|
+
// if (!include) {
|
|
2318
|
+
// include = true
|
|
2319
|
+
// } else if (include) {
|
|
2320
|
+
// addRow(row)
|
|
2321
|
+
// include = false
|
|
2322
|
+
// }
|
|
2323
|
+
// }
|
|
2324
|
+
|
|
2325
|
+
// if (include) {
|
|
2326
|
+
// addRow(row)
|
|
2327
|
+
// }
|
|
2328
|
+
// })
|
|
2329
|
+
|
|
2330
|
+
// table.setRowSelection(selectedRowIds)
|
|
2331
|
+
// },
|
|
2332
|
+
table.getPreSelectedRowModel = () => table.getCoreRowModel();
|
|
2333
|
+
table.getSelectedRowModel = memo(() => [table.getState().rowSelection, table.getCoreRowModel()], (rowSelection, rowModel) => {
|
|
2334
|
+
if (!Object.keys(rowSelection).length) {
|
|
2335
|
+
return {
|
|
2336
|
+
rows: [],
|
|
2337
|
+
flatRows: [],
|
|
2338
|
+
rowsById: {}
|
|
2339
|
+
};
|
|
2340
|
+
}
|
|
2341
|
+
return selectRowsFn(table, rowModel);
|
|
2342
|
+
}, getMemoOptions(table.options, 'debugTable', 'getSelectedRowModel'));
|
|
2343
|
+
table.getFilteredSelectedRowModel = memo(() => [table.getState().rowSelection, table.getFilteredRowModel()], (rowSelection, rowModel) => {
|
|
2344
|
+
if (!Object.keys(rowSelection).length) {
|
|
2345
|
+
return {
|
|
2346
|
+
rows: [],
|
|
2347
|
+
flatRows: [],
|
|
2348
|
+
rowsById: {}
|
|
2349
|
+
};
|
|
2350
|
+
}
|
|
2351
|
+
return selectRowsFn(table, rowModel);
|
|
2352
|
+
}, getMemoOptions(table.options, 'debugTable', 'getFilteredSelectedRowModel'));
|
|
2353
|
+
table.getGroupedSelectedRowModel = memo(() => [table.getState().rowSelection, table.getSortedRowModel()], (rowSelection, rowModel) => {
|
|
2354
|
+
if (!Object.keys(rowSelection).length) {
|
|
2355
|
+
return {
|
|
2356
|
+
rows: [],
|
|
2357
|
+
flatRows: [],
|
|
2358
|
+
rowsById: {}
|
|
2359
|
+
};
|
|
2360
|
+
}
|
|
2361
|
+
return selectRowsFn(table, rowModel);
|
|
2362
|
+
}, getMemoOptions(table.options, 'debugTable', 'getGroupedSelectedRowModel'));
|
|
2363
|
+
|
|
2364
|
+
///
|
|
2365
|
+
|
|
2366
|
+
// getGroupingRowCanSelect: rowId => {
|
|
2367
|
+
// const row = table.getRow(rowId)
|
|
2368
|
+
|
|
2369
|
+
// if (!row) {
|
|
2370
|
+
// throw new Error()
|
|
2371
|
+
// }
|
|
2372
|
+
|
|
2373
|
+
// if (typeof table.options.enableGroupingRowSelection === 'function') {
|
|
2374
|
+
// return table.options.enableGroupingRowSelection(row)
|
|
2375
|
+
// }
|
|
2376
|
+
|
|
2377
|
+
// return table.options.enableGroupingRowSelection ?? false
|
|
2378
|
+
// },
|
|
2379
|
+
|
|
2380
|
+
table.getIsAllRowsSelected = () => {
|
|
2381
|
+
const preGroupedFlatRows = table.getFilteredRowModel().flatRows;
|
|
2382
|
+
const {
|
|
2383
|
+
rowSelection
|
|
2384
|
+
} = table.getState();
|
|
2385
|
+
let isAllRowsSelected = Boolean(preGroupedFlatRows.length && Object.keys(rowSelection).length);
|
|
2386
|
+
if (isAllRowsSelected) {
|
|
2387
|
+
if (preGroupedFlatRows.some(row => row.getCanSelect() && !rowSelection[row.id])) {
|
|
2388
|
+
isAllRowsSelected = false;
|
|
2389
|
+
}
|
|
2390
|
+
}
|
|
2391
|
+
return isAllRowsSelected;
|
|
2392
|
+
};
|
|
2393
|
+
table.getIsAllPageRowsSelected = () => {
|
|
2394
|
+
const paginationFlatRows = table.getPaginationRowModel().flatRows.filter(row => row.getCanSelect());
|
|
2395
|
+
const {
|
|
2396
|
+
rowSelection
|
|
2397
|
+
} = table.getState();
|
|
2398
|
+
let isAllPageRowsSelected = !!paginationFlatRows.length;
|
|
2399
|
+
if (isAllPageRowsSelected && paginationFlatRows.some(row => !rowSelection[row.id])) {
|
|
2400
|
+
isAllPageRowsSelected = false;
|
|
2401
|
+
}
|
|
2402
|
+
return isAllPageRowsSelected;
|
|
2403
|
+
};
|
|
2404
|
+
table.getIsSomeRowsSelected = () => {
|
|
2405
|
+
var _table$getState$rowSe;
|
|
2406
|
+
const totalSelected = Object.keys((_table$getState$rowSe = table.getState().rowSelection) != null ? _table$getState$rowSe : {}).length;
|
|
2407
|
+
return totalSelected > 0 && totalSelected < table.getFilteredRowModel().flatRows.length;
|
|
2408
|
+
};
|
|
2409
|
+
table.getIsSomePageRowsSelected = () => {
|
|
2410
|
+
const paginationFlatRows = table.getPaginationRowModel().flatRows;
|
|
2411
|
+
return table.getIsAllPageRowsSelected() ? false : paginationFlatRows.filter(row => row.getCanSelect()).some(d => d.getIsSelected() || d.getIsSomeSelected());
|
|
2412
|
+
};
|
|
2413
|
+
table.getToggleAllRowsSelectedHandler = () => {
|
|
2414
|
+
return e => {
|
|
2415
|
+
table.toggleAllRowsSelected(e.target.checked);
|
|
2416
|
+
};
|
|
2417
|
+
};
|
|
2418
|
+
table.getToggleAllPageRowsSelectedHandler = () => {
|
|
2419
|
+
return e => {
|
|
2420
|
+
table.toggleAllPageRowsSelected(e.target.checked);
|
|
2421
|
+
};
|
|
2422
|
+
};
|
|
2423
|
+
},
|
|
2424
|
+
createRow: (row, table) => {
|
|
2425
|
+
row.toggleSelected = (value, opts) => {
|
|
2426
|
+
const isSelected = row.getIsSelected();
|
|
2427
|
+
table.setRowSelection(old => {
|
|
2428
|
+
var _opts$selectChildren;
|
|
2429
|
+
value = typeof value !== 'undefined' ? value : !isSelected;
|
|
2430
|
+
if (row.getCanSelect() && isSelected === value) {
|
|
2431
|
+
return old;
|
|
2432
|
+
}
|
|
2433
|
+
const selectedRowIds = {
|
|
2434
|
+
...old
|
|
2435
|
+
};
|
|
2436
|
+
mutateRowIsSelected(selectedRowIds, row.id, value, (_opts$selectChildren = opts == null ? void 0 : opts.selectChildren) != null ? _opts$selectChildren : true, table);
|
|
2437
|
+
return selectedRowIds;
|
|
2438
|
+
});
|
|
2439
|
+
};
|
|
2440
|
+
row.getIsSelected = () => {
|
|
2441
|
+
const {
|
|
2442
|
+
rowSelection
|
|
2443
|
+
} = table.getState();
|
|
2444
|
+
return isRowSelected(row, rowSelection);
|
|
2445
|
+
};
|
|
2446
|
+
row.getIsSomeSelected = () => {
|
|
2447
|
+
const {
|
|
2448
|
+
rowSelection
|
|
2449
|
+
} = table.getState();
|
|
2450
|
+
return isSubRowSelected(row, rowSelection) === 'some';
|
|
2451
|
+
};
|
|
2452
|
+
row.getIsAllSubRowsSelected = () => {
|
|
2453
|
+
const {
|
|
2454
|
+
rowSelection
|
|
2455
|
+
} = table.getState();
|
|
2456
|
+
return isSubRowSelected(row, rowSelection) === 'all';
|
|
2457
|
+
};
|
|
2458
|
+
row.getCanSelect = () => {
|
|
2459
|
+
var _table$options$enable;
|
|
2460
|
+
if (typeof table.options.enableRowSelection === 'function') {
|
|
2461
|
+
return table.options.enableRowSelection(row);
|
|
2462
|
+
}
|
|
2463
|
+
return (_table$options$enable = table.options.enableRowSelection) != null ? _table$options$enable : true;
|
|
2464
|
+
};
|
|
2465
|
+
row.getCanSelectSubRows = () => {
|
|
2466
|
+
var _table$options$enable2;
|
|
2467
|
+
if (typeof table.options.enableSubRowSelection === 'function') {
|
|
2468
|
+
return table.options.enableSubRowSelection(row);
|
|
2469
|
+
}
|
|
2470
|
+
return (_table$options$enable2 = table.options.enableSubRowSelection) != null ? _table$options$enable2 : true;
|
|
2471
|
+
};
|
|
2472
|
+
row.getCanMultiSelect = () => {
|
|
2473
|
+
var _table$options$enable3;
|
|
2474
|
+
if (typeof table.options.enableMultiRowSelection === 'function') {
|
|
2475
|
+
return table.options.enableMultiRowSelection(row);
|
|
2476
|
+
}
|
|
2477
|
+
return (_table$options$enable3 = table.options.enableMultiRowSelection) != null ? _table$options$enable3 : true;
|
|
2478
|
+
};
|
|
2479
|
+
row.getToggleSelectedHandler = () => {
|
|
2480
|
+
const canSelect = row.getCanSelect();
|
|
2481
|
+
return e => {
|
|
2482
|
+
var _target;
|
|
2483
|
+
if (!canSelect) return;
|
|
2484
|
+
row.toggleSelected((_target = e.target) == null ? void 0 : _target.checked);
|
|
2485
|
+
};
|
|
2486
|
+
};
|
|
2487
|
+
}
|
|
2488
|
+
};
|
|
2489
|
+
const mutateRowIsSelected = (selectedRowIds, id, value, includeChildren, table) => {
|
|
2490
|
+
var _row$subRows;
|
|
2491
|
+
const row = table.getRow(id, true);
|
|
2492
|
+
|
|
2493
|
+
// const isGrouped = row.getIsGrouped()
|
|
2494
|
+
|
|
2495
|
+
// if ( // TODO: enforce grouping row selection rules
|
|
2496
|
+
// !isGrouped ||
|
|
2497
|
+
// (isGrouped && table.options.enableGroupingRowSelection)
|
|
2498
|
+
// ) {
|
|
2499
|
+
if (value) {
|
|
2500
|
+
if (!row.getCanMultiSelect()) {
|
|
2501
|
+
Object.keys(selectedRowIds).forEach(key => delete selectedRowIds[key]);
|
|
2502
|
+
}
|
|
2503
|
+
if (row.getCanSelect()) {
|
|
2504
|
+
selectedRowIds[id] = true;
|
|
2505
|
+
}
|
|
2506
|
+
} else {
|
|
2507
|
+
delete selectedRowIds[id];
|
|
2508
|
+
}
|
|
2509
|
+
// }
|
|
2510
|
+
|
|
2511
|
+
if (includeChildren && (_row$subRows = row.subRows) != null && _row$subRows.length && row.getCanSelectSubRows()) {
|
|
2512
|
+
row.subRows.forEach(row => mutateRowIsSelected(selectedRowIds, row.id, value, includeChildren, table));
|
|
2513
|
+
}
|
|
2514
|
+
};
|
|
2515
|
+
function selectRowsFn(table, rowModel) {
|
|
2516
|
+
const rowSelection = table.getState().rowSelection;
|
|
2517
|
+
const newSelectedFlatRows = [];
|
|
2518
|
+
const newSelectedRowsById = {};
|
|
2519
|
+
|
|
2520
|
+
// Filters top level and nested rows
|
|
2521
|
+
const recurseRows = function (rows, depth) {
|
|
2522
|
+
return rows.map(row => {
|
|
2523
|
+
var _row$subRows2;
|
|
2524
|
+
const isSelected = isRowSelected(row, rowSelection);
|
|
2525
|
+
if (isSelected) {
|
|
2526
|
+
newSelectedFlatRows.push(row);
|
|
2527
|
+
newSelectedRowsById[row.id] = row;
|
|
2528
|
+
}
|
|
2529
|
+
if ((_row$subRows2 = row.subRows) != null && _row$subRows2.length) {
|
|
2530
|
+
row = {
|
|
2531
|
+
...row,
|
|
2532
|
+
subRows: recurseRows(row.subRows)
|
|
2533
|
+
};
|
|
2534
|
+
}
|
|
2535
|
+
if (isSelected) {
|
|
2536
|
+
return row;
|
|
2537
|
+
}
|
|
2538
|
+
}).filter(Boolean);
|
|
2539
|
+
};
|
|
2540
|
+
return {
|
|
2541
|
+
rows: recurseRows(rowModel.rows),
|
|
2542
|
+
flatRows: newSelectedFlatRows,
|
|
2543
|
+
rowsById: newSelectedRowsById
|
|
2544
|
+
};
|
|
2545
|
+
}
|
|
2546
|
+
function isRowSelected(row, selection) {
|
|
2547
|
+
var _selection$row$id;
|
|
2548
|
+
return (_selection$row$id = selection[row.id]) != null ? _selection$row$id : false;
|
|
2549
|
+
}
|
|
2550
|
+
function isSubRowSelected(row, selection, table) {
|
|
2551
|
+
var _row$subRows3;
|
|
2552
|
+
if (!((_row$subRows3 = row.subRows) != null && _row$subRows3.length)) return false;
|
|
2553
|
+
let allChildrenSelected = true;
|
|
2554
|
+
let someSelected = false;
|
|
2555
|
+
row.subRows.forEach(subRow => {
|
|
2556
|
+
// Bail out early if we know both of these
|
|
2557
|
+
if (someSelected && !allChildrenSelected) {
|
|
2558
|
+
return;
|
|
2559
|
+
}
|
|
2560
|
+
if (subRow.getCanSelect()) {
|
|
2561
|
+
if (isRowSelected(subRow, selection)) {
|
|
2562
|
+
someSelected = true;
|
|
2563
|
+
} else {
|
|
2564
|
+
allChildrenSelected = false;
|
|
2565
|
+
}
|
|
2566
|
+
}
|
|
2567
|
+
|
|
2568
|
+
// Check row selection of nested subrows
|
|
2569
|
+
if (subRow.subRows && subRow.subRows.length) {
|
|
2570
|
+
const subRowChildrenSelected = isSubRowSelected(subRow, selection);
|
|
2571
|
+
if (subRowChildrenSelected === 'all') {
|
|
2572
|
+
someSelected = true;
|
|
2573
|
+
} else if (subRowChildrenSelected === 'some') {
|
|
2574
|
+
someSelected = true;
|
|
2575
|
+
allChildrenSelected = false;
|
|
2576
|
+
} else {
|
|
2577
|
+
allChildrenSelected = false;
|
|
2578
|
+
}
|
|
2579
|
+
}
|
|
2580
|
+
});
|
|
2581
|
+
return allChildrenSelected ? 'all' : someSelected ? 'some' : false;
|
|
2582
|
+
}
|
|
2583
|
+
|
|
2584
|
+
const reSplitAlphaNumeric = /([0-9]+)/gm;
|
|
2585
|
+
const alphanumeric = (rowA, rowB, columnId) => {
|
|
2586
|
+
return compareAlphanumeric(toString(rowA.getValue(columnId)).toLowerCase(), toString(rowB.getValue(columnId)).toLowerCase());
|
|
2587
|
+
};
|
|
2588
|
+
const alphanumericCaseSensitive = (rowA, rowB, columnId) => {
|
|
2589
|
+
return compareAlphanumeric(toString(rowA.getValue(columnId)), toString(rowB.getValue(columnId)));
|
|
2590
|
+
};
|
|
2591
|
+
|
|
2592
|
+
// The text filter is more basic (less numeric support)
|
|
2593
|
+
// but is much faster
|
|
2594
|
+
const text = (rowA, rowB, columnId) => {
|
|
2595
|
+
return compareBasic(toString(rowA.getValue(columnId)).toLowerCase(), toString(rowB.getValue(columnId)).toLowerCase());
|
|
2596
|
+
};
|
|
2597
|
+
|
|
2598
|
+
// The text filter is more basic (less numeric support)
|
|
2599
|
+
// but is much faster
|
|
2600
|
+
const textCaseSensitive = (rowA, rowB, columnId) => {
|
|
2601
|
+
return compareBasic(toString(rowA.getValue(columnId)), toString(rowB.getValue(columnId)));
|
|
2602
|
+
};
|
|
2603
|
+
const datetime = (rowA, rowB, columnId) => {
|
|
2604
|
+
const a = rowA.getValue(columnId);
|
|
2605
|
+
const b = rowB.getValue(columnId);
|
|
2606
|
+
|
|
2607
|
+
// Can handle nullish values
|
|
2608
|
+
// Use > and < because == (and ===) doesn't work with
|
|
2609
|
+
// Date objects (would require calling getTime()).
|
|
2610
|
+
return a > b ? 1 : a < b ? -1 : 0;
|
|
2611
|
+
};
|
|
2612
|
+
const basic = (rowA, rowB, columnId) => {
|
|
2613
|
+
return compareBasic(rowA.getValue(columnId), rowB.getValue(columnId));
|
|
2614
|
+
};
|
|
2615
|
+
|
|
2616
|
+
// Utils
|
|
2617
|
+
|
|
2618
|
+
function compareBasic(a, b) {
|
|
2619
|
+
return a === b ? 0 : a > b ? 1 : -1;
|
|
2620
|
+
}
|
|
2621
|
+
function toString(a) {
|
|
2622
|
+
if (typeof a === 'number') {
|
|
2623
|
+
if (isNaN(a) || a === Infinity || a === -Infinity) {
|
|
2624
|
+
return '';
|
|
2625
|
+
}
|
|
2626
|
+
return String(a);
|
|
2627
|
+
}
|
|
2628
|
+
if (typeof a === 'string') {
|
|
2629
|
+
return a;
|
|
2630
|
+
}
|
|
2631
|
+
return '';
|
|
2632
|
+
}
|
|
2633
|
+
|
|
2634
|
+
// Mixed sorting is slow, but very inclusive of many edge cases.
|
|
2635
|
+
// It handles numbers, mixed alphanumeric combinations, and even
|
|
2636
|
+
// null, undefined, and Infinity
|
|
2637
|
+
function compareAlphanumeric(aStr, bStr) {
|
|
2638
|
+
// Split on number groups, but keep the delimiter
|
|
2639
|
+
// Then remove falsey split values
|
|
2640
|
+
const a = aStr.split(reSplitAlphaNumeric).filter(Boolean);
|
|
2641
|
+
const b = bStr.split(reSplitAlphaNumeric).filter(Boolean);
|
|
2642
|
+
|
|
2643
|
+
// While
|
|
2644
|
+
while (a.length && b.length) {
|
|
2645
|
+
const aa = a.shift();
|
|
2646
|
+
const bb = b.shift();
|
|
2647
|
+
const an = parseInt(aa, 10);
|
|
2648
|
+
const bn = parseInt(bb, 10);
|
|
2649
|
+
const combo = [an, bn].sort();
|
|
2650
|
+
|
|
2651
|
+
// Both are string
|
|
2652
|
+
if (isNaN(combo[0])) {
|
|
2653
|
+
if (aa > bb) {
|
|
2654
|
+
return 1;
|
|
2655
|
+
}
|
|
2656
|
+
if (bb > aa) {
|
|
2657
|
+
return -1;
|
|
2658
|
+
}
|
|
2659
|
+
continue;
|
|
2660
|
+
}
|
|
2661
|
+
|
|
2662
|
+
// One is a string, one is a number
|
|
2663
|
+
if (isNaN(combo[1])) {
|
|
2664
|
+
return isNaN(an) ? -1 : 1;
|
|
2665
|
+
}
|
|
2666
|
+
|
|
2667
|
+
// Both are numbers
|
|
2668
|
+
if (an > bn) {
|
|
2669
|
+
return 1;
|
|
2670
|
+
}
|
|
2671
|
+
if (bn > an) {
|
|
2672
|
+
return -1;
|
|
2673
|
+
}
|
|
2674
|
+
}
|
|
2675
|
+
return a.length - b.length;
|
|
2676
|
+
}
|
|
2677
|
+
|
|
2678
|
+
// Exports
|
|
2679
|
+
|
|
2680
|
+
const sortingFns = {
|
|
2681
|
+
alphanumeric,
|
|
2682
|
+
alphanumericCaseSensitive,
|
|
2683
|
+
text,
|
|
2684
|
+
textCaseSensitive,
|
|
2685
|
+
datetime,
|
|
2686
|
+
basic
|
|
2687
|
+
};
|
|
2688
|
+
|
|
2689
|
+
//
|
|
2690
|
+
|
|
2691
|
+
const RowSorting = {
|
|
2692
|
+
getInitialState: state => {
|
|
2693
|
+
return {
|
|
2694
|
+
sorting: [],
|
|
2695
|
+
...state
|
|
2696
|
+
};
|
|
2697
|
+
},
|
|
2698
|
+
getDefaultColumnDef: () => {
|
|
2699
|
+
return {
|
|
2700
|
+
sortingFn: 'auto',
|
|
2701
|
+
sortUndefined: 1
|
|
2702
|
+
};
|
|
2703
|
+
},
|
|
2704
|
+
getDefaultOptions: table => {
|
|
2705
|
+
return {
|
|
2706
|
+
onSortingChange: makeStateUpdater('sorting', table),
|
|
2707
|
+
isMultiSortEvent: e => {
|
|
2708
|
+
return e.shiftKey;
|
|
2709
|
+
}
|
|
2710
|
+
};
|
|
2711
|
+
},
|
|
2712
|
+
createColumn: (column, table) => {
|
|
2713
|
+
column.getAutoSortingFn = () => {
|
|
2714
|
+
const firstRows = table.getFilteredRowModel().flatRows.slice(10);
|
|
2715
|
+
let isString = false;
|
|
2716
|
+
for (const row of firstRows) {
|
|
2717
|
+
const value = row == null ? void 0 : row.getValue(column.id);
|
|
2718
|
+
if (Object.prototype.toString.call(value) === '[object Date]') {
|
|
2719
|
+
return sortingFns.datetime;
|
|
2720
|
+
}
|
|
2721
|
+
if (typeof value === 'string') {
|
|
2722
|
+
isString = true;
|
|
2723
|
+
if (value.split(reSplitAlphaNumeric).length > 1) {
|
|
2724
|
+
return sortingFns.alphanumeric;
|
|
2725
|
+
}
|
|
2726
|
+
}
|
|
2727
|
+
}
|
|
2728
|
+
if (isString) {
|
|
2729
|
+
return sortingFns.text;
|
|
2730
|
+
}
|
|
2731
|
+
return sortingFns.basic;
|
|
2732
|
+
};
|
|
2733
|
+
column.getAutoSortDir = () => {
|
|
2734
|
+
const firstRow = table.getFilteredRowModel().flatRows[0];
|
|
2735
|
+
const value = firstRow == null ? void 0 : firstRow.getValue(column.id);
|
|
2736
|
+
if (typeof value === 'string') {
|
|
2737
|
+
return 'asc';
|
|
2738
|
+
}
|
|
2739
|
+
return 'desc';
|
|
2740
|
+
};
|
|
2741
|
+
column.getSortingFn = () => {
|
|
2742
|
+
var _table$options$sortin, _table$options$sortin2;
|
|
2743
|
+
if (!column) {
|
|
2744
|
+
throw new Error();
|
|
2745
|
+
}
|
|
2746
|
+
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];
|
|
2747
|
+
};
|
|
2748
|
+
column.toggleSorting = (desc, multi) => {
|
|
2749
|
+
// if (column.columns.length) {
|
|
2750
|
+
// column.columns.forEach((c, i) => {
|
|
2751
|
+
// if (c.id) {
|
|
2752
|
+
// table.toggleColumnSorting(c.id, undefined, multi || !!i)
|
|
2753
|
+
// }
|
|
2754
|
+
// })
|
|
2755
|
+
// return
|
|
2756
|
+
// }
|
|
2757
|
+
|
|
2758
|
+
// this needs to be outside of table.setSorting to be in sync with rerender
|
|
2759
|
+
const nextSortingOrder = column.getNextSortingOrder();
|
|
2760
|
+
const hasManualValue = typeof desc !== 'undefined' && desc !== null;
|
|
2761
|
+
table.setSorting(old => {
|
|
2762
|
+
// Find any existing sorting for this column
|
|
2763
|
+
const existingSorting = old == null ? void 0 : old.find(d => d.id === column.id);
|
|
2764
|
+
const existingIndex = old == null ? void 0 : old.findIndex(d => d.id === column.id);
|
|
2765
|
+
let newSorting = [];
|
|
2766
|
+
|
|
2767
|
+
// What should we do with this sort action?
|
|
2768
|
+
let sortAction;
|
|
2769
|
+
let nextDesc = hasManualValue ? desc : nextSortingOrder === 'desc';
|
|
2770
|
+
|
|
2771
|
+
// Multi-mode
|
|
2772
|
+
if (old != null && old.length && column.getCanMultiSort() && multi) {
|
|
2773
|
+
if (existingSorting) {
|
|
2774
|
+
sortAction = 'toggle';
|
|
2775
|
+
} else {
|
|
2776
|
+
sortAction = 'add';
|
|
2777
|
+
}
|
|
2778
|
+
} else {
|
|
2779
|
+
// Normal mode
|
|
2780
|
+
if (old != null && old.length && existingIndex !== old.length - 1) {
|
|
2781
|
+
sortAction = 'replace';
|
|
2782
|
+
} else if (existingSorting) {
|
|
2783
|
+
sortAction = 'toggle';
|
|
2784
|
+
} else {
|
|
2785
|
+
sortAction = 'replace';
|
|
2786
|
+
}
|
|
2787
|
+
}
|
|
2788
|
+
|
|
2789
|
+
// Handle toggle states that will remove the sorting
|
|
2790
|
+
if (sortAction === 'toggle') {
|
|
2791
|
+
// If we are "actually" toggling (not a manual set value), should we remove the sorting?
|
|
2792
|
+
if (!hasManualValue) {
|
|
2793
|
+
// Is our intention to remove?
|
|
2794
|
+
if (!nextSortingOrder) {
|
|
2795
|
+
sortAction = 'remove';
|
|
2796
|
+
}
|
|
2797
|
+
}
|
|
2798
|
+
}
|
|
2799
|
+
if (sortAction === 'add') {
|
|
2800
|
+
var _table$options$maxMul;
|
|
2801
|
+
newSorting = [...old, {
|
|
2802
|
+
id: column.id,
|
|
2803
|
+
desc: nextDesc
|
|
2804
|
+
}];
|
|
2805
|
+
// Take latest n columns
|
|
2806
|
+
newSorting.splice(0, newSorting.length - ((_table$options$maxMul = table.options.maxMultiSortColCount) != null ? _table$options$maxMul : Number.MAX_SAFE_INTEGER));
|
|
2807
|
+
} else if (sortAction === 'toggle') {
|
|
2808
|
+
// This flips (or sets) the
|
|
2809
|
+
newSorting = old.map(d => {
|
|
2810
|
+
if (d.id === column.id) {
|
|
2811
|
+
return {
|
|
2812
|
+
...d,
|
|
2813
|
+
desc: nextDesc
|
|
2814
|
+
};
|
|
2815
|
+
}
|
|
2816
|
+
return d;
|
|
2817
|
+
});
|
|
2818
|
+
} else if (sortAction === 'remove') {
|
|
2819
|
+
newSorting = old.filter(d => d.id !== column.id);
|
|
2820
|
+
} else {
|
|
2821
|
+
newSorting = [{
|
|
2822
|
+
id: column.id,
|
|
2823
|
+
desc: nextDesc
|
|
2824
|
+
}];
|
|
2825
|
+
}
|
|
2826
|
+
return newSorting;
|
|
2827
|
+
});
|
|
2828
|
+
};
|
|
2829
|
+
column.getFirstSortDir = () => {
|
|
2830
|
+
var _ref, _column$columnDef$sor;
|
|
2831
|
+
const sortDescFirst = (_ref = (_column$columnDef$sor = column.columnDef.sortDescFirst) != null ? _column$columnDef$sor : table.options.sortDescFirst) != null ? _ref : column.getAutoSortDir() === 'desc';
|
|
2832
|
+
return sortDescFirst ? 'desc' : 'asc';
|
|
2833
|
+
};
|
|
2834
|
+
column.getNextSortingOrder = multi => {
|
|
2835
|
+
var _table$options$enable, _table$options$enable2;
|
|
2836
|
+
const firstSortDirection = column.getFirstSortDir();
|
|
2837
|
+
const isSorted = column.getIsSorted();
|
|
2838
|
+
if (!isSorted) {
|
|
2839
|
+
return firstSortDirection;
|
|
2840
|
+
}
|
|
2841
|
+
if (isSorted !== firstSortDirection && ((_table$options$enable = table.options.enableSortingRemoval) != null ? _table$options$enable : true) && (
|
|
2842
|
+
// If enableSortRemove, enable in general
|
|
2843
|
+
multi ? (_table$options$enable2 = table.options.enableMultiRemove) != null ? _table$options$enable2 : true : true) // If multi, don't allow if enableMultiRemove))
|
|
2844
|
+
) {
|
|
2845
|
+
return false;
|
|
2846
|
+
}
|
|
2847
|
+
return isSorted === 'desc' ? 'asc' : 'desc';
|
|
2848
|
+
};
|
|
2849
|
+
column.getCanSort = () => {
|
|
2850
|
+
var _column$columnDef$ena, _table$options$enable3;
|
|
2851
|
+
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;
|
|
2852
|
+
};
|
|
2853
|
+
column.getCanMultiSort = () => {
|
|
2854
|
+
var _ref2, _column$columnDef$ena2;
|
|
2855
|
+
return (_ref2 = (_column$columnDef$ena2 = column.columnDef.enableMultiSort) != null ? _column$columnDef$ena2 : table.options.enableMultiSort) != null ? _ref2 : !!column.accessorFn;
|
|
2856
|
+
};
|
|
2857
|
+
column.getIsSorted = () => {
|
|
2858
|
+
var _table$getState$sorti;
|
|
2859
|
+
const columnSort = (_table$getState$sorti = table.getState().sorting) == null ? void 0 : _table$getState$sorti.find(d => d.id === column.id);
|
|
2860
|
+
return !columnSort ? false : columnSort.desc ? 'desc' : 'asc';
|
|
2861
|
+
};
|
|
2862
|
+
column.getSortIndex = () => {
|
|
2863
|
+
var _table$getState$sorti2, _table$getState$sorti3;
|
|
2864
|
+
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;
|
|
2865
|
+
};
|
|
2866
|
+
column.clearSorting = () => {
|
|
2867
|
+
//clear sorting for just 1 column
|
|
2868
|
+
table.setSorting(old => old != null && old.length ? old.filter(d => d.id !== column.id) : []);
|
|
2869
|
+
};
|
|
2870
|
+
column.getToggleSortingHandler = () => {
|
|
2871
|
+
const canSort = column.getCanSort();
|
|
2872
|
+
return e => {
|
|
2873
|
+
if (!canSort) return;
|
|
2874
|
+
e.persist == null || e.persist();
|
|
2875
|
+
column.toggleSorting == null || column.toggleSorting(undefined, column.getCanMultiSort() ? table.options.isMultiSortEvent == null ? void 0 : table.options.isMultiSortEvent(e) : false);
|
|
2876
|
+
};
|
|
2877
|
+
};
|
|
2878
|
+
},
|
|
2879
|
+
createTable: table => {
|
|
2880
|
+
table.setSorting = updater => table.options.onSortingChange == null ? void 0 : table.options.onSortingChange(updater);
|
|
2881
|
+
table.resetSorting = defaultState => {
|
|
2882
|
+
var _table$initialState$s, _table$initialState;
|
|
2883
|
+
table.setSorting(defaultState ? [] : (_table$initialState$s = (_table$initialState = table.initialState) == null ? void 0 : _table$initialState.sorting) != null ? _table$initialState$s : []);
|
|
2884
|
+
};
|
|
2885
|
+
table.getPreSortedRowModel = () => table.getGroupedRowModel();
|
|
2886
|
+
table.getSortedRowModel = () => {
|
|
2887
|
+
if (!table._getSortedRowModel && table.options.getSortedRowModel) {
|
|
2888
|
+
table._getSortedRowModel = table.options.getSortedRowModel(table);
|
|
2889
|
+
}
|
|
2890
|
+
if (table.options.manualSorting || !table._getSortedRowModel) {
|
|
2891
|
+
return table.getPreSortedRowModel();
|
|
2892
|
+
}
|
|
2893
|
+
return table._getSortedRowModel();
|
|
2894
|
+
};
|
|
2895
|
+
}
|
|
2896
|
+
};
|
|
2897
|
+
|
|
2898
|
+
const builtInFeatures = [Headers, ColumnVisibility, ColumnOrdering, ColumnPinning, ColumnFaceting, ColumnFiltering, GlobalFaceting,
|
|
2899
|
+
//depends on ColumnFaceting
|
|
2900
|
+
GlobalFiltering,
|
|
2901
|
+
//depends on ColumnFiltering
|
|
2902
|
+
RowSorting, ColumnGrouping,
|
|
2903
|
+
//depends on RowSorting
|
|
2904
|
+
RowExpanding, RowPagination, RowPinning, RowSelection, ColumnSizing];
|
|
2905
|
+
|
|
2906
|
+
//
|
|
2907
|
+
|
|
2908
|
+
function createTable(options) {
|
|
2909
|
+
var _options$_features, _options$initialState;
|
|
2910
|
+
if (process.env.NODE_ENV !== 'production' && (options.debugAll || options.debugTable)) {
|
|
2911
|
+
console.info('Creating Table Instance...');
|
|
2912
|
+
}
|
|
2913
|
+
const _features = [...builtInFeatures, ...((_options$_features = options._features) != null ? _options$_features : [])];
|
|
2914
|
+
let table = {
|
|
2915
|
+
_features
|
|
2916
|
+
};
|
|
2917
|
+
const defaultOptions = table._features.reduce((obj, feature) => {
|
|
2918
|
+
return Object.assign(obj, feature.getDefaultOptions == null ? void 0 : feature.getDefaultOptions(table));
|
|
2919
|
+
}, {});
|
|
2920
|
+
const mergeOptions = options => {
|
|
2921
|
+
if (table.options.mergeOptions) {
|
|
2922
|
+
return table.options.mergeOptions(defaultOptions, options);
|
|
2923
|
+
}
|
|
2924
|
+
return {
|
|
2925
|
+
...defaultOptions,
|
|
2926
|
+
...options
|
|
2927
|
+
};
|
|
2928
|
+
};
|
|
2929
|
+
const coreInitialState = {};
|
|
2930
|
+
let initialState = {
|
|
2931
|
+
...coreInitialState,
|
|
2932
|
+
...((_options$initialState = options.initialState) != null ? _options$initialState : {})
|
|
2933
|
+
};
|
|
2934
|
+
table._features.forEach(feature => {
|
|
2935
|
+
var _feature$getInitialSt;
|
|
2936
|
+
initialState = (_feature$getInitialSt = feature.getInitialState == null ? void 0 : feature.getInitialState(initialState)) != null ? _feature$getInitialSt : initialState;
|
|
2937
|
+
});
|
|
2938
|
+
const queued = [];
|
|
2939
|
+
let queuedTimeout = false;
|
|
2940
|
+
const coreInstance = {
|
|
2941
|
+
_features,
|
|
2942
|
+
options: {
|
|
2943
|
+
...defaultOptions,
|
|
2944
|
+
...options
|
|
2945
|
+
},
|
|
2946
|
+
initialState,
|
|
2947
|
+
_queue: cb => {
|
|
2948
|
+
queued.push(cb);
|
|
2949
|
+
if (!queuedTimeout) {
|
|
2950
|
+
queuedTimeout = true;
|
|
2951
|
+
|
|
2952
|
+
// Schedule a microtask to run the queued callbacks after
|
|
2953
|
+
// the current call stack (render, etc) has finished.
|
|
2954
|
+
Promise.resolve().then(() => {
|
|
2955
|
+
while (queued.length) {
|
|
2956
|
+
queued.shift()();
|
|
2957
|
+
}
|
|
2958
|
+
queuedTimeout = false;
|
|
2959
|
+
}).catch(error => setTimeout(() => {
|
|
2960
|
+
throw error;
|
|
2961
|
+
}));
|
|
2962
|
+
}
|
|
2963
|
+
},
|
|
2964
|
+
reset: () => {
|
|
2965
|
+
table.setState(table.initialState);
|
|
2966
|
+
},
|
|
2967
|
+
setOptions: updater => {
|
|
2968
|
+
const newOptions = functionalUpdate(updater, table.options);
|
|
2969
|
+
table.options = mergeOptions(newOptions);
|
|
2970
|
+
},
|
|
2971
|
+
getState: () => {
|
|
2972
|
+
return table.options.state;
|
|
2973
|
+
},
|
|
2974
|
+
setState: updater => {
|
|
2975
|
+
table.options.onStateChange == null || table.options.onStateChange(updater);
|
|
2976
|
+
},
|
|
2977
|
+
_getRowId: (row, index, parent) => {
|
|
2978
|
+
var _table$options$getRow;
|
|
2979
|
+
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}`;
|
|
2980
|
+
},
|
|
2981
|
+
getCoreRowModel: () => {
|
|
2982
|
+
if (!table._getCoreRowModel) {
|
|
2983
|
+
table._getCoreRowModel = table.options.getCoreRowModel(table);
|
|
2984
|
+
}
|
|
2985
|
+
return table._getCoreRowModel();
|
|
2986
|
+
},
|
|
2987
|
+
// The final calls start at the bottom of the model,
|
|
2988
|
+
// expanded rows, which then work their way up
|
|
2989
|
+
|
|
2990
|
+
getRowModel: () => {
|
|
2991
|
+
return table.getPaginationRowModel();
|
|
2992
|
+
},
|
|
2993
|
+
//in next version, we should just pass in the row model as the optional 2nd arg
|
|
2994
|
+
getRow: (id, searchAll) => {
|
|
2995
|
+
let row = (searchAll ? table.getPrePaginationRowModel() : table.getRowModel()).rowsById[id];
|
|
2996
|
+
if (!row) {
|
|
2997
|
+
row = table.getCoreRowModel().rowsById[id];
|
|
2998
|
+
if (!row) {
|
|
2999
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
3000
|
+
throw new Error(`getRow could not find row with ID: ${id}`);
|
|
3001
|
+
}
|
|
3002
|
+
throw new Error();
|
|
3003
|
+
}
|
|
3004
|
+
}
|
|
3005
|
+
return row;
|
|
3006
|
+
},
|
|
3007
|
+
_getDefaultColumnDef: memo(() => [table.options.defaultColumn], defaultColumn => {
|
|
3008
|
+
var _defaultColumn;
|
|
3009
|
+
defaultColumn = (_defaultColumn = defaultColumn) != null ? _defaultColumn : {};
|
|
3010
|
+
return {
|
|
3011
|
+
header: props => {
|
|
3012
|
+
const resolvedColumnDef = props.header.column.columnDef;
|
|
3013
|
+
if (resolvedColumnDef.accessorKey) {
|
|
3014
|
+
return resolvedColumnDef.accessorKey;
|
|
3015
|
+
}
|
|
3016
|
+
if (resolvedColumnDef.accessorFn) {
|
|
3017
|
+
return resolvedColumnDef.id;
|
|
3018
|
+
}
|
|
3019
|
+
return null;
|
|
3020
|
+
},
|
|
3021
|
+
// footer: props => props.header.column.id,
|
|
3022
|
+
cell: props => {
|
|
3023
|
+
var _props$renderValue$to, _props$renderValue;
|
|
3024
|
+
return (_props$renderValue$to = (_props$renderValue = props.renderValue()) == null || _props$renderValue.toString == null ? void 0 : _props$renderValue.toString()) != null ? _props$renderValue$to : null;
|
|
3025
|
+
},
|
|
3026
|
+
...table._features.reduce((obj, feature) => {
|
|
3027
|
+
return Object.assign(obj, feature.getDefaultColumnDef == null ? void 0 : feature.getDefaultColumnDef());
|
|
3028
|
+
}, {}),
|
|
3029
|
+
...defaultColumn
|
|
3030
|
+
};
|
|
3031
|
+
}, getMemoOptions(options, 'debugColumns', '_getDefaultColumnDef')),
|
|
3032
|
+
_getColumnDefs: () => table.options.columns,
|
|
3033
|
+
getAllColumns: memo(() => [table._getColumnDefs()], columnDefs => {
|
|
3034
|
+
const recurseColumns = function (columnDefs, parent, depth) {
|
|
3035
|
+
if (depth === void 0) {
|
|
3036
|
+
depth = 0;
|
|
3037
|
+
}
|
|
3038
|
+
return columnDefs.map(columnDef => {
|
|
3039
|
+
const column = createColumn(table, columnDef, depth, parent);
|
|
3040
|
+
const groupingColumnDef = columnDef;
|
|
3041
|
+
column.columns = groupingColumnDef.columns ? recurseColumns(groupingColumnDef.columns, column, depth + 1) : [];
|
|
3042
|
+
return column;
|
|
3043
|
+
});
|
|
3044
|
+
};
|
|
3045
|
+
return recurseColumns(columnDefs);
|
|
3046
|
+
}, getMemoOptions(options, 'debugColumns', 'getAllColumns')),
|
|
3047
|
+
getAllFlatColumns: memo(() => [table.getAllColumns()], allColumns => {
|
|
3048
|
+
return allColumns.flatMap(column => {
|
|
3049
|
+
return column.getFlatColumns();
|
|
3050
|
+
});
|
|
3051
|
+
}, getMemoOptions(options, 'debugColumns', 'getAllFlatColumns')),
|
|
3052
|
+
_getAllFlatColumnsById: memo(() => [table.getAllFlatColumns()], flatColumns => {
|
|
3053
|
+
return flatColumns.reduce((acc, column) => {
|
|
3054
|
+
acc[column.id] = column;
|
|
3055
|
+
return acc;
|
|
3056
|
+
}, {});
|
|
3057
|
+
}, getMemoOptions(options, 'debugColumns', 'getAllFlatColumnsById')),
|
|
3058
|
+
getAllLeafColumns: memo(() => [table.getAllColumns(), table._getOrderColumnsFn()], (allColumns, orderColumns) => {
|
|
3059
|
+
let leafColumns = allColumns.flatMap(column => column.getLeafColumns());
|
|
3060
|
+
return orderColumns(leafColumns);
|
|
3061
|
+
}, getMemoOptions(options, 'debugColumns', 'getAllLeafColumns')),
|
|
3062
|
+
getColumn: columnId => {
|
|
3063
|
+
const column = table._getAllFlatColumnsById()[columnId];
|
|
3064
|
+
if (process.env.NODE_ENV !== 'production' && !column) {
|
|
3065
|
+
console.error(`[Table] Column with id '${columnId}' does not exist.`);
|
|
3066
|
+
}
|
|
3067
|
+
return column;
|
|
3068
|
+
}
|
|
3069
|
+
};
|
|
3070
|
+
Object.assign(table, coreInstance);
|
|
3071
|
+
for (let index = 0; index < table._features.length; index++) {
|
|
3072
|
+
const feature = table._features[index];
|
|
3073
|
+
feature == null || feature.createTable == null || feature.createTable(table);
|
|
3074
|
+
}
|
|
3075
|
+
return table;
|
|
3076
|
+
}
|
|
3077
|
+
|
|
3078
|
+
function getCoreRowModel() {
|
|
3079
|
+
return table => memo(() => [table.options.data], data => {
|
|
3080
|
+
const rowModel = {
|
|
3081
|
+
rows: [],
|
|
3082
|
+
flatRows: [],
|
|
3083
|
+
rowsById: {}
|
|
3084
|
+
};
|
|
3085
|
+
const accessRows = function (originalRows, depth, parentRow) {
|
|
3086
|
+
if (depth === void 0) {
|
|
3087
|
+
depth = 0;
|
|
3088
|
+
}
|
|
3089
|
+
const rows = [];
|
|
3090
|
+
for (let i = 0; i < originalRows.length; i++) {
|
|
3091
|
+
// This could be an expensive check at scale, so we should move it somewhere else, but where?
|
|
3092
|
+
// if (!id) {
|
|
3093
|
+
// if (process.env.NODE_ENV !== 'production') {
|
|
3094
|
+
// throw new Error(`getRowId expected an ID, but got ${id}`)
|
|
3095
|
+
// }
|
|
3096
|
+
// }
|
|
3097
|
+
|
|
3098
|
+
// Make the row
|
|
3099
|
+
const row = createRow(table, table._getRowId(originalRows[i], i, parentRow), originalRows[i], i, depth, undefined, parentRow == null ? void 0 : parentRow.id);
|
|
3100
|
+
|
|
3101
|
+
// Keep track of every row in a flat array
|
|
3102
|
+
rowModel.flatRows.push(row);
|
|
3103
|
+
// Also keep track of every row by its ID
|
|
3104
|
+
rowModel.rowsById[row.id] = row;
|
|
3105
|
+
// Push table row into parent
|
|
3106
|
+
rows.push(row);
|
|
3107
|
+
|
|
3108
|
+
// Get the original subrows
|
|
3109
|
+
if (table.options.getSubRows) {
|
|
3110
|
+
var _row$originalSubRows;
|
|
3111
|
+
row.originalSubRows = table.options.getSubRows(originalRows[i], i);
|
|
3112
|
+
|
|
3113
|
+
// Then recursively access them
|
|
3114
|
+
if ((_row$originalSubRows = row.originalSubRows) != null && _row$originalSubRows.length) {
|
|
3115
|
+
row.subRows = accessRows(row.originalSubRows, depth + 1, row);
|
|
3116
|
+
}
|
|
3117
|
+
}
|
|
3118
|
+
}
|
|
3119
|
+
return rows;
|
|
3120
|
+
};
|
|
3121
|
+
rowModel.rows = accessRows(data);
|
|
3122
|
+
return rowModel;
|
|
3123
|
+
}, getMemoOptions(table.options, 'debugTable', 'getRowModel', () => table._autoResetPageIndex()));
|
|
3124
|
+
}
|
|
3125
|
+
|
|
3126
|
+
/**
|
|
3127
|
+
* react-table
|
|
3128
|
+
*
|
|
3129
|
+
* Copyright (c) TanStack
|
|
3130
|
+
*
|
|
3131
|
+
* This source code is licensed under the MIT license found in the
|
|
3132
|
+
* LICENSE.md file in the root directory of this source tree.
|
|
3133
|
+
*
|
|
3134
|
+
* @license MIT
|
|
3135
|
+
*/
|
|
3136
|
+
|
|
3137
|
+
//
|
|
3138
|
+
|
|
3139
|
+
/**
|
|
3140
|
+
* If rendering headers, cells, or footers with custom markup, use flexRender instead of `cell.getValue()` or `cell.renderValue()`.
|
|
3141
|
+
*/
|
|
3142
|
+
function flexRender(Comp, props) {
|
|
3143
|
+
return !Comp ? null : isReactComponent(Comp) ? /*#__PURE__*/React.createElement(Comp, props) : Comp;
|
|
3144
|
+
}
|
|
3145
|
+
function isReactComponent(component) {
|
|
3146
|
+
return isClassComponent(component) || typeof component === 'function' || isExoticComponent(component);
|
|
3147
|
+
}
|
|
3148
|
+
function isClassComponent(component) {
|
|
3149
|
+
return typeof component === 'function' && (() => {
|
|
3150
|
+
const proto = Object.getPrototypeOf(component);
|
|
3151
|
+
return proto.prototype && proto.prototype.isReactComponent;
|
|
3152
|
+
})();
|
|
3153
|
+
}
|
|
3154
|
+
function isExoticComponent(component) {
|
|
3155
|
+
return typeof component === 'object' && typeof component.$$typeof === 'symbol' && ['react.memo', 'react.forward_ref'].includes(component.$$typeof.description);
|
|
3156
|
+
}
|
|
3157
|
+
function useReactTable(options) {
|
|
3158
|
+
// Compose in the generic options to the user options
|
|
3159
|
+
const resolvedOptions = {
|
|
3160
|
+
state: {},
|
|
3161
|
+
// Dummy state
|
|
3162
|
+
onStateChange: () => {},
|
|
3163
|
+
// noop
|
|
3164
|
+
renderFallbackValue: null,
|
|
3165
|
+
...options
|
|
3166
|
+
};
|
|
3167
|
+
|
|
3168
|
+
// Create a new table and store it in state
|
|
3169
|
+
const [tableRef] = React.useState(() => ({
|
|
3170
|
+
current: createTable(resolvedOptions)
|
|
3171
|
+
}));
|
|
3172
|
+
|
|
3173
|
+
// By default, manage table state here using the table's initial state
|
|
3174
|
+
const [state, setState] = React.useState(() => tableRef.current.initialState);
|
|
3175
|
+
|
|
3176
|
+
// Compose the default state above with any user state. This will allow the user
|
|
3177
|
+
// to only control a subset of the state if desired.
|
|
3178
|
+
tableRef.current.setOptions(prev => ({
|
|
3179
|
+
...prev,
|
|
3180
|
+
...options,
|
|
3181
|
+
state: {
|
|
3182
|
+
...state,
|
|
3183
|
+
...options.state
|
|
3184
|
+
},
|
|
3185
|
+
// Similarly, we'll maintain both our internal state and any user-provided
|
|
3186
|
+
// state.
|
|
3187
|
+
onStateChange: updater => {
|
|
3188
|
+
setState(updater);
|
|
3189
|
+
options.onStateChange == null || options.onStateChange(updater);
|
|
3190
|
+
}
|
|
3191
|
+
}));
|
|
3192
|
+
return tableRef.current;
|
|
3193
|
+
}
|
|
3194
|
+
|
|
3195
|
+
// Theme colors
|
|
3196
|
+
const brand = { primary: '#e20074' };
|
|
3197
|
+
const gray = {
|
|
3198
|
+
500: '#6b7280',
|
|
3199
|
+
600: '#4b5563',
|
|
3200
|
+
800: '#1f2937',
|
|
3201
|
+
};
|
|
3202
|
+
// Icons
|
|
3203
|
+
const DownArrowIcon = ({ size = 7, fill = gray[600] }) => (jsx("svg", { width: size, height: size / 1.75, viewBox: "0 0 7 4", fill: fill, xmlns: "http://www.w3.org/2000/svg", children: jsx("path", { fillRule: "evenodd", clipRule: "evenodd", d: "M0.571637 0C0.458634 2.40803e-05 0.348175 0.0335519 0.254223 0.0963447C0.160272 0.159138 0.0870471 0.248377 0.0438056 0.35278C0.000564098 0.457183 -0.0107522 0.572062 0.0112872 0.682896C0.0333261 0.79373 0.0877309 0.89554 0.167624 0.975458L3.02486 3.83269C3.13202 3.93982 3.27734 4 3.42887 4C3.58039 4 3.72572 3.93982 3.83288 3.83269L6.69011 0.975458C6.77 0.89554 6.82441 0.79373 6.84645 0.682896C6.86849 0.572062 6.85717 0.457183 6.81393 0.35278C6.77069 0.248377 6.69746 0.159138 6.60351 0.0963447C6.50956 0.0335519 6.3991 2.40803e-05 6.2861 0H0.571637Z", fill: fill ?? gray[600] }) }));
|
|
3204
|
+
const DragHandleIcon = ({ size = 16, color = gray[500] }) => (jsx("svg", { width: size, height: size, viewBox: "0 0 20 20", fill: "none", xmlns: "http://www.w3.org/2000/svg", style: { flexShrink: 0 }, children: jsx("path", { d: "M12.8125 5.625C12.6271 5.625 12.4458 5.57002 12.2917 5.467C12.1375 5.36399 12.0173 5.21757 11.9464 5.04627C11.8754 4.87496 11.8568 4.68646 11.893 4.5046C11.9292 4.32275 12.0185 4.1557 12.1496 4.02459C12.2807 3.89348 12.4477 3.80419 12.6296 3.76801C12.8115 3.73184 13 3.75041 13.1713 3.82136C13.3426 3.89232 13.489 4.01248 13.592 4.16665C13.695 4.32082 13.75 4.50208 13.75 4.6875C13.75 4.93614 13.6512 5.1746 13.4754 5.35041C13.2996 5.52623 13.0611 5.625 12.8125 5.625ZM13.75 10C13.75 9.81458 13.695 9.63333 13.592 9.47915C13.489 9.32498 13.3426 9.20482 13.1713 9.13386C13 9.06291 12.8115 9.04434 12.6296 9.08051C12.4477 9.11669 12.2807 9.20598 12.1496 9.33709C12.0185 9.4682 11.9292 9.63525 11.893 9.8171C11.8568 9.99896 11.8754 10.1875 11.9464 10.3588C12.0173 10.5301 12.1375 10.6765 12.2917 10.7795C12.4458 10.8825 12.6271 10.9375 12.8125 10.9375C13.0611 10.9375 13.2996 10.8387 13.4754 10.6629C13.6512 10.4871 13.75 10.2486 13.75 10ZM11.875 15.3125C11.875 15.4979 11.93 15.6792 12.033 15.8333C12.136 15.9875 12.2824 16.1077 12.4537 16.1786C12.625 16.2496 12.8135 16.2682 12.9954 16.232C13.1773 16.1958 13.3443 16.1065 13.4754 15.9754C13.6065 15.8443 13.6958 15.6773 13.732 15.4954C13.7682 15.3135 13.7496 15.125 13.6786 14.9537C13.6077 14.7824 13.4875 14.636 13.3333 14.533C13.1792 14.43 12.9979 14.375 12.8125 14.375C12.5639 14.375 12.3254 14.4738 12.1496 14.6496C11.9738 14.8254 11.875 15.0639 11.875 15.3125ZM8.125 4.6875C8.125 4.50208 8.07002 4.32082 7.967 4.16665C7.86399 4.01248 7.71757 3.89232 7.54626 3.82136C7.37496 3.75041 7.18646 3.73184 7.0046 3.76801C6.82275 3.80419 6.6557 3.89348 6.52459 4.02459C6.39348 4.1557 6.30419 4.32275 6.26801 4.5046C6.23184 4.68646 6.25041 4.87496 6.32136 5.04627C6.39232 5.21757 6.51248 5.36399 6.66665 5.467C6.82082 5.57002 7.00208 5.625 7.1875 5.625C7.43614 5.625 7.6746 5.52623 7.85041 5.35041C8.02623 5.1746 8.125 4.93614 8.125 4.6875ZM8.125 10C8.125 9.81458 8.07002 9.63333 7.967 9.47915C7.86399 9.32498 7.71757 9.20482 7.54626 9.13386C7.37496 9.06291 7.18646 9.04434 7.0046 9.08051C6.82275 9.11669 6.6557 9.20598 6.52459 9.33709C6.39348 9.4682 6.30419 9.63525 6.26801 9.8171C6.23184 9.99896 6.25041 10.1875 6.32136 10.3588C6.39232 10.5301 6.51248 10.6765 6.66665 10.7795C6.82082 10.8825 7.00208 10.9375 7.1875 10.9375C7.43614 10.9375 7.6746 10.8387 7.85041 10.6629C8.02623 10.4871 8.125 10.2486 8.125 10ZM8.125 15.3125C8.125 15.1271 8.07002 14.9458 7.967 14.7917C7.86399 14.6375 7.71757 14.5173 7.54626 14.4464C7.37496 14.3754 7.18646 14.3568 7.0046 14.393C6.82275 14.4292 6.6557 14.5185 6.52459 14.6496C6.39348 14.7807 6.30419 14.9477 6.26801 15.1296C6.23184 15.3115 6.25041 15.5 6.32136 15.6713C6.39232 15.8426 6.51248 15.989 6.66665 16.092C6.82082 16.195 7.00208 16.25 7.1875 16.25C7.43614 16.25 7.6746 16.1512 7.85041 15.9754C8.02623 15.7996 8.125 15.5611 8.125 15.3125Z", fill: color }) }));
|
|
3205
|
+
const AscSortIcon = ({ size = 16, isActive = false }) => (jsx("svg", { width: size, height: size, viewBox: "0 0 13 12", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: jsx("path", { d: "M0.5 3.1665L3.16667 0.499838M3.16667 0.499838L5.83333 3.1665M3.16667 0.499838V11.1665M5.83333 11.1665H12.5M5.83333 8.49984H10.5M5.83333 5.83317H8.5", stroke: isActive ? brand.primary : gray[800], strokeLinecap: "round", strokeLinejoin: "round" }) }));
|
|
3206
|
+
const DescSortIcon = ({ size = 16, isActive = false }) => (jsx("svg", { width: size, height: size, viewBox: "0 0 13 12", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: jsx("path", { d: "M0.5 8.5L3.16667 11.1667M3.16667 11.1667L5.83333 8.5M3.16667 11.1667V0.5M5.83333 0.5H12.5M5.83333 3.16667H10.5M5.83333 5.83333H8.5", stroke: isActive ? brand.primary : gray[800], strokeLinecap: "round", strokeLinejoin: "round" }) }));
|
|
3207
|
+
const SearchIcon = ({ size = 16 }) => (jsxs("svg", { width: size, height: size, viewBox: "0 0 16 16", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: [jsx("circle", { cx: "7", cy: "7", r: "5.5", stroke: gray[800], strokeWidth: "1.5" }), jsx("path", { d: "M11 11L14 14", stroke: gray[800], strokeWidth: "1.5", strokeLinecap: "round" })] }));
|
|
3208
|
+
const BackArrow = ({ size = 6, fill = '#666' }) => (jsx("svg", { width: size, height: size * 1.5, viewBox: "0 0 6 10", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: jsx("path", { d: "M5 1L1 5L5 9", stroke: fill, strokeWidth: "1.5", strokeLinecap: "round", strokeLinejoin: "round" }) }));
|
|
3209
|
+
const RightArrow = ({ size = 6, fill = '#666' }) => (jsx("svg", { width: size, height: size * 1.5, viewBox: "0 0 6 10", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: jsx("path", { d: "M1 1L5 5L1 9", stroke: fill, strokeWidth: "1.5", strokeLinecap: "round", strokeLinejoin: "round" }) }));
|
|
3210
|
+
const FirstPageIcon = ({ size = 10, fill = '#666' }) => (jsxs("svg", { width: size, height: size, viewBox: "0 0 12 12", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: [jsx("path", { d: "M10 1L5 6L10 11", stroke: fill, strokeWidth: "1.5", strokeLinecap: "round", strokeLinejoin: "round" }), jsx("path", { d: "M2 1V11", stroke: fill, strokeWidth: "1.5", strokeLinecap: "round" })] }));
|
|
3211
|
+
const LastPageIcon = ({ size = 10, fill = '#666' }) => (jsxs("svg", { width: size, height: size, viewBox: "0 0 12 12", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: [jsx("path", { d: "M2 1L7 6L2 11", stroke: fill, strokeWidth: "1.5", strokeLinecap: "round", strokeLinejoin: "round" }), jsx("path", { d: "M10 1V11", stroke: fill, strokeWidth: "1.5", strokeLinecap: "round" })] }));
|
|
3212
|
+
// Inline Styles
|
|
3213
|
+
const styles = {
|
|
3214
|
+
container: {
|
|
3215
|
+
width: '100%',
|
|
3216
|
+
display: 'flex',
|
|
3217
|
+
flexDirection: 'column',
|
|
3218
|
+
flex: 1,
|
|
3219
|
+
minHeight: 0,
|
|
3220
|
+
fontFamily: "'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif",
|
|
3221
|
+
},
|
|
3222
|
+
table: {
|
|
3223
|
+
width: '100%',
|
|
3224
|
+
minWidth: 'max-content',
|
|
3225
|
+
borderCollapse: 'collapse',
|
|
3226
|
+
borderSpacing: 0,
|
|
3227
|
+
fontSize: 14,
|
|
3228
|
+
background: 'transparent',
|
|
3229
|
+
tableLayout: 'fixed',
|
|
3230
|
+
},
|
|
3231
|
+
tableHead: {
|
|
3232
|
+
background: '#f5f5f5',
|
|
3233
|
+
position: 'sticky',
|
|
3234
|
+
top: 0,
|
|
3235
|
+
zIndex: 10,
|
|
3236
|
+
},
|
|
3237
|
+
tableRow: (borderBottom, focused) => ({
|
|
3238
|
+
borderBottom: borderBottom ? '1px solid #ebebeb' : 'none',
|
|
3239
|
+
cursor: 'pointer',
|
|
3240
|
+
background: focused ? '#f8f9fa' : 'transparent',
|
|
3241
|
+
}),
|
|
3242
|
+
tableHeaderCell: {
|
|
3243
|
+
color: '#707070',
|
|
3244
|
+
height: 40,
|
|
3245
|
+
textAlign: 'start',
|
|
3246
|
+
overflow: 'visible',
|
|
3247
|
+
whiteSpace: 'nowrap',
|
|
3248
|
+
padding: '0 25px',
|
|
3249
|
+
fontSize: 14,
|
|
3250
|
+
fontWeight: 400,
|
|
3251
|
+
position: 'relative',
|
|
3252
|
+
},
|
|
3253
|
+
tableCell: {
|
|
3254
|
+
color: '#333333',
|
|
3255
|
+
height: 40,
|
|
3256
|
+
textAlign: 'start',
|
|
3257
|
+
overflow: 'hidden',
|
|
3258
|
+
textOverflow: 'ellipsis',
|
|
3259
|
+
whiteSpace: 'nowrap',
|
|
3260
|
+
padding: '0 25px',
|
|
3261
|
+
fontSize: 13,
|
|
3262
|
+
},
|
|
3263
|
+
dropdownPanel: {
|
|
3264
|
+
position: 'fixed',
|
|
3265
|
+
width: 260,
|
|
3266
|
+
maxHeight: 390,
|
|
3267
|
+
background: '#ffffff',
|
|
3268
|
+
borderRadius: 16,
|
|
3269
|
+
boxShadow: '0 4px 20px rgba(0, 0, 0, 0.15)',
|
|
3270
|
+
padding: '12px 8px',
|
|
3271
|
+
zIndex: 9999,
|
|
3272
|
+
display: 'flex',
|
|
3273
|
+
flexDirection: 'column',
|
|
3274
|
+
overflow: 'hidden',
|
|
3275
|
+
},
|
|
3276
|
+
filterOption: (isHeader) => ({
|
|
3277
|
+
display: 'flex',
|
|
3278
|
+
alignItems: 'center',
|
|
3279
|
+
width: 244,
|
|
3280
|
+
height: isHeader ? 52 : 48,
|
|
3281
|
+
padding: isHeader ? '16px 16px 12px 16px' : '12px 16px',
|
|
3282
|
+
gap: 12,
|
|
3283
|
+
cursor: 'pointer',
|
|
3284
|
+
transition: 'background 0.15s ease',
|
|
3285
|
+
}),
|
|
3286
|
+
button: (variant) => ({
|
|
3287
|
+
background: variant === 'primary' ? '#e20074' : '#ffffff',
|
|
3288
|
+
border: `1px solid ${variant === 'primary' ? '#e20074' : '#8f8f8f'}`,
|
|
3289
|
+
borderRadius: 12,
|
|
3290
|
+
padding: '8px 16px',
|
|
3291
|
+
fontSize: 14,
|
|
3292
|
+
fontWeight: 600,
|
|
3293
|
+
color: variant === 'primary' ? '#ffffff' : '#333333',
|
|
3294
|
+
cursor: 'pointer',
|
|
3295
|
+
minWidth: 78,
|
|
3296
|
+
display: 'inline-flex',
|
|
3297
|
+
alignItems: 'center',
|
|
3298
|
+
justifyContent: 'center',
|
|
3299
|
+
}),
|
|
3300
|
+
paginationWrapper: {
|
|
3301
|
+
display: 'flex',
|
|
3302
|
+
gap: 12,
|
|
3303
|
+
alignItems: 'center',
|
|
3304
|
+
justifyContent: 'flex-end',
|
|
3305
|
+
marginTop: 10,
|
|
3306
|
+
},
|
|
3307
|
+
pageControls: {
|
|
3308
|
+
display: 'flex',
|
|
3309
|
+
alignItems: 'center',
|
|
3310
|
+
gap: 4,
|
|
3311
|
+
height: 35,
|
|
3312
|
+
padding: '4.5px 8px',
|
|
3313
|
+
borderRadius: 12,
|
|
3314
|
+
border: '1px solid #E0E0E0',
|
|
3315
|
+
background: '#fff',
|
|
3316
|
+
fontSize: 12,
|
|
3317
|
+
color: '#333',
|
|
3318
|
+
minWidth: 190,
|
|
3319
|
+
justifyContent: 'space-between',
|
|
3320
|
+
},
|
|
3321
|
+
iconBtn: (disabled) => ({
|
|
3322
|
+
display: 'flex',
|
|
3323
|
+
alignItems: 'center',
|
|
3324
|
+
justifyContent: 'center',
|
|
3325
|
+
background: 'transparent',
|
|
3326
|
+
border: 'none',
|
|
3327
|
+
cursor: disabled ? 'not-allowed' : 'pointer',
|
|
3328
|
+
padding: 4,
|
|
3329
|
+
color: disabled ? '#ccc' : '#666',
|
|
3330
|
+
}),
|
|
3331
|
+
};
|
|
3332
|
+
const CustomCheckbox = ({ checked, indeterminate, onClick }) => (jsxs("div", { onClick: onClick, style: {
|
|
3333
|
+
width: 16,
|
|
3334
|
+
height: 16,
|
|
3335
|
+
cursor: 'pointer',
|
|
3336
|
+
borderRadius: 4,
|
|
3337
|
+
flexShrink: 0,
|
|
3338
|
+
border: '1px solid #D6D6D6',
|
|
3339
|
+
backgroundColor: checked || indeterminate ? '#e20074' : 'white',
|
|
3340
|
+
display: 'flex',
|
|
3341
|
+
alignItems: 'center',
|
|
3342
|
+
justifyContent: 'center',
|
|
3343
|
+
}, children: [checked && (jsx("svg", { width: "10", height: "8", viewBox: "0 0 10 8", fill: "none", children: jsx("path", { d: "M1 4L3.5 6.5L9 1", stroke: "white", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round" }) })), indeterminate && !checked && (jsx("svg", { width: "8", height: "2", viewBox: "0 0 8 2", fill: "none", children: jsx("path", { d: "M1 1H7", stroke: "white", strokeWidth: "2", strokeLinecap: "round" }) }))] }));
|
|
3344
|
+
const FilterDropdown = ({ columnKey, columnHeader, data, filterOptions, currentFilter, onApply, filterLabel, isOpen, onToggle, onClose, enableSorting = false, enableFilter = true, currentSortOrder, onSort, }) => {
|
|
3345
|
+
const containerRef = useRef(null);
|
|
3346
|
+
const dropdownRef = useRef(null);
|
|
3347
|
+
const [tempSelection, setTempSelection] = useState(new Set(currentFilter?.selectedValues || []));
|
|
3348
|
+
const [searchQuery, setSearchQuery] = useState('');
|
|
3349
|
+
const [dropdownPosition, setDropdownPosition] = useState(null);
|
|
3350
|
+
const uniqueValues = useMemo(() => {
|
|
3351
|
+
if (filterOptions && filterOptions.length > 0) {
|
|
3352
|
+
return Array.from(new Set(filterOptions)).sort();
|
|
3353
|
+
}
|
|
3354
|
+
const values = new Set();
|
|
3355
|
+
data.forEach((row) => {
|
|
3356
|
+
const value = row[columnKey];
|
|
3357
|
+
if (value !== undefined && value !== null && value !== '') {
|
|
3358
|
+
values.add(String(value));
|
|
3359
|
+
}
|
|
3360
|
+
});
|
|
3361
|
+
return Array.from(values).sort();
|
|
3362
|
+
}, [data, columnKey, filterOptions]);
|
|
3363
|
+
useLayoutEffect(() => {
|
|
3364
|
+
if (!isOpen || !containerRef.current)
|
|
3365
|
+
return;
|
|
3366
|
+
const rect = containerRef.current.getBoundingClientRect();
|
|
3367
|
+
setDropdownPosition({
|
|
3368
|
+
top: rect.bottom + 4,
|
|
3369
|
+
left: Math.max(8, rect.right - 260),
|
|
3370
|
+
});
|
|
3371
|
+
}, [isOpen]);
|
|
3372
|
+
useEffect(() => {
|
|
3373
|
+
if (isOpen) {
|
|
3374
|
+
setTempSelection(new Set(currentFilter?.selectedValues || []));
|
|
3375
|
+
setSearchQuery('');
|
|
3376
|
+
}
|
|
3377
|
+
}, [isOpen, currentFilter]);
|
|
3378
|
+
useEffect(() => {
|
|
3379
|
+
const handleClickOutside = (event) => {
|
|
3380
|
+
if (containerRef.current && !containerRef.current.contains(event.target) &&
|
|
3381
|
+
dropdownRef.current && !dropdownRef.current.contains(event.target)) {
|
|
3382
|
+
onClose();
|
|
3383
|
+
}
|
|
3384
|
+
};
|
|
3385
|
+
const handleKeyDown = (event) => {
|
|
3386
|
+
if (event.key === 'Escape')
|
|
3387
|
+
onClose();
|
|
3388
|
+
};
|
|
3389
|
+
if (isOpen) {
|
|
3390
|
+
document.addEventListener('mousedown', handleClickOutside);
|
|
3391
|
+
document.addEventListener('keydown', handleKeyDown);
|
|
3392
|
+
}
|
|
3393
|
+
return () => {
|
|
3394
|
+
document.removeEventListener('mousedown', handleClickOutside);
|
|
3395
|
+
document.removeEventListener('keydown', handleKeyDown);
|
|
3396
|
+
};
|
|
3397
|
+
}, [isOpen, onClose]);
|
|
3398
|
+
const filteredValues = useMemo(() => {
|
|
3399
|
+
if (!searchQuery.trim())
|
|
3400
|
+
return uniqueValues;
|
|
3401
|
+
const query = searchQuery.toLowerCase();
|
|
3402
|
+
return uniqueValues.filter((value) => String(value).toLowerCase().includes(query));
|
|
3403
|
+
}, [uniqueValues, searchQuery]);
|
|
3404
|
+
const allFilteredSelected = filteredValues.length > 0 && filteredValues.every((value) => tempSelection.has(value));
|
|
3405
|
+
const someFilteredSelected = filteredValues.some((value) => tempSelection.has(value)) && !allFilteredSelected;
|
|
3406
|
+
const handleToggleAll = () => {
|
|
3407
|
+
if (allFilteredSelected) {
|
|
3408
|
+
setTempSelection((prev) => {
|
|
3409
|
+
const newSet = new Set(prev);
|
|
3410
|
+
filteredValues.forEach((value) => newSet.delete(value));
|
|
3411
|
+
return newSet;
|
|
3412
|
+
});
|
|
3413
|
+
}
|
|
3414
|
+
else {
|
|
3415
|
+
setTempSelection((prev) => {
|
|
3416
|
+
const newSet = new Set(prev);
|
|
3417
|
+
filteredValues.forEach((value) => newSet.add(value));
|
|
3418
|
+
return newSet;
|
|
3419
|
+
});
|
|
3420
|
+
}
|
|
3421
|
+
};
|
|
3422
|
+
const handleToggleValue = (value) => {
|
|
3423
|
+
setTempSelection((prev) => {
|
|
3424
|
+
const newSet = new Set(prev);
|
|
3425
|
+
if (newSet.has(value))
|
|
3426
|
+
newSet.delete(value);
|
|
3427
|
+
else
|
|
3428
|
+
newSet.add(value);
|
|
3429
|
+
return newSet;
|
|
3430
|
+
});
|
|
3431
|
+
};
|
|
3432
|
+
const handleClearAll = () => {
|
|
3433
|
+
onApply(columnKey, new Set());
|
|
3434
|
+
onClose();
|
|
3435
|
+
};
|
|
3436
|
+
const handleApply = () => {
|
|
3437
|
+
onApply(columnKey, tempSelection);
|
|
3438
|
+
onClose();
|
|
3439
|
+
};
|
|
3440
|
+
const hasActiveFilter = currentFilter && currentFilter.selectedValues.size > 0;
|
|
3441
|
+
const isActive = isOpen || hasActiveFilter || !!currentSortOrder;
|
|
3442
|
+
return (jsxs("div", { ref: containerRef, style: { position: 'relative', display: 'inline-flex', alignItems: 'center' }, children: [jsx("button", { onClick: (e) => { e.stopPropagation(); onToggle(); }, type: "button", style: { display: 'flex', alignItems: 'center', justifyContent: 'center', background: 'transparent', border: 'none', padding: 2, cursor: 'pointer', borderRadius: 4 }, children: jsx("div", { style: { display: 'flex', alignItems: 'center', justifyContent: 'center', transition: 'transform 0.2s ease', transform: isOpen ? 'rotate(180deg)' : 'rotate(0deg)' }, children: jsx(DownArrowIcon, { size: 8, fill: isActive ? brand.primary : gray[600] }) }) }), isOpen && dropdownPosition && (jsxs("div", { ref: dropdownRef, onClick: (e) => e.stopPropagation(), style: { ...styles.dropdownPanel, top: dropdownPosition.top, left: dropdownPosition.left }, children: [enableSorting && onSort && (jsxs("div", { style: { display: 'flex', alignItems: 'center', justifyContent: 'space-between', padding: 6 }, children: [jsx("span", { style: { fontSize: 16, fontWeight: 500, color: '#333333' }, children: "Sort" }), jsxs("div", { style: { display: 'flex', gap: 8 }, children: [jsxs("button", { type: "button", onClick: (e) => { e.stopPropagation(); onSort('ASC'); }, style: { display: 'flex', alignItems: 'center', justifyContent: 'center', width: 69, gap: 4, padding: 6, borderRadius: 8, border: 'none', background: currentSortOrder === 'ASC' ? 'rgba(226, 0, 116, 0.05)' : 'transparent', cursor: 'pointer', fontSize: 13, color: currentSortOrder === 'ASC' ? '#e20074' : '#707070' }, children: [jsx(AscSortIcon, { size: 12, isActive: currentSortOrder === 'ASC' }), jsx("span", { children: "A to Z" })] }), jsxs("button", { type: "button", onClick: (e) => { e.stopPropagation(); onSort('DESC'); }, style: { display: 'flex', alignItems: 'center', justifyContent: 'center', width: 69, gap: 4, padding: 6, borderRadius: 8, border: 'none', background: currentSortOrder === 'DESC' ? 'rgba(226, 0, 116, 0.05)' : 'transparent', cursor: 'pointer', fontSize: 13, color: currentSortOrder === 'DESC' ? '#e20074' : '#707070' }, children: [jsx(DescSortIcon, { size: 12, isActive: currentSortOrder === 'DESC' }), jsx("span", { children: "Z to A" })] })] })] })), enableFilter && (jsxs(Fragment, { children: [jsx("div", { style: { padding: '8px 4px' }, children: jsxs("div", { style: { display: 'flex', alignItems: 'center', width: 236, height: 34, gap: 10, padding: '12px 10px', borderRadius: 12, border: '1px solid #e8e8e8', background: '#ffffff' }, children: [jsx(SearchIcon, { size: 16 }), jsx("input", { type: "text", placeholder: "Search", value: searchQuery, onChange: (e) => setSearchQuery(e.target.value), onClick: (e) => e.stopPropagation(), style: { flex: 1, border: 'none', outline: 'none', background: 'transparent', fontSize: 13, color: '#333333' } })] }) }), filteredValues.length > 0 && (jsxs("div", { style: styles.filterOption(true), onClick: (e) => { e.stopPropagation(); handleToggleAll(); }, children: [jsx(CustomCheckbox, { checked: allFilteredSelected, indeterminate: someFilteredSelected, onClick: (e) => { e.stopPropagation(); handleToggleAll(); } }), jsxs("span", { style: { fontSize: 13, color: '#333333', flex: 1, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }, children: ["All ", columnHeader || columnKey] })] })), jsxs("div", { style: { flex: 1, overflowY: 'auto', maxHeight: 250 }, children: [filteredValues.filter((value) => value !== '' && value !== null && value !== undefined).map((value) => (jsxs("div", { style: styles.filterOption(false), onClick: (e) => { e.stopPropagation(); handleToggleValue(value); }, children: [jsx(CustomCheckbox, { checked: tempSelection.has(value), onClick: (e) => { e.stopPropagation(); handleToggleValue(value); } }), jsx("span", { title: filterLabel ? filterLabel(value) : value, style: { fontSize: 13, color: '#333333', flex: 1, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }, children: filterLabel ? filterLabel(value) : value })] }, value))), filteredValues.length === 0 && jsx("div", { style: { padding: 16, color: '#8f8f8f', fontSize: 13, textAlign: 'center' }, children: "No values found" })] }), jsxs("div", { style: { display: 'flex', justifyContent: 'flex-end', alignItems: 'center', gap: 10, padding: '10px 12px', paddingBottom: 0 }, children: [jsx("button", { style: styles.button('secondary'), onClick: (e) => { e.stopPropagation(); handleClearAll(); }, disabled: tempSelection.size === 0 && (!currentFilter || currentFilter.selectedValues.size === 0), children: "Reset" }), jsx("button", { style: styles.button('primary'), onClick: (e) => { e.stopPropagation(); handleApply(); }, children: "Apply" })] })] }))] }))] }));
|
|
3443
|
+
};
|
|
3444
|
+
// Pagination Component
|
|
3445
|
+
const PAGE_SIZE_OPTIONS = [10, 20, 30, 40, 50];
|
|
3446
|
+
const Pagination = ({ page, pageSize, total, onPageChange, onPageSizeChange }) => {
|
|
3447
|
+
const [isDropdownOpen, setIsDropdownOpen] = useState(false);
|
|
3448
|
+
const dropdownRef = useRef(null);
|
|
3449
|
+
const start = total === 0 ? 0 : (page - 1) * pageSize + 1;
|
|
3450
|
+
const end = Math.min(page * pageSize, total);
|
|
3451
|
+
const totalPages = Math.max(1, Math.ceil(total / pageSize));
|
|
3452
|
+
useEffect(() => {
|
|
3453
|
+
const handleClickOutside = (event) => {
|
|
3454
|
+
if (dropdownRef.current && !dropdownRef.current.contains(event.target)) {
|
|
3455
|
+
setIsDropdownOpen(false);
|
|
3456
|
+
}
|
|
3457
|
+
};
|
|
3458
|
+
document.addEventListener('mousedown', handleClickOutside);
|
|
3459
|
+
return () => document.removeEventListener('mousedown', handleClickOutside);
|
|
3460
|
+
}, []);
|
|
3461
|
+
return (jsxs("div", { style: styles.paginationWrapper, children: [jsxs("div", { ref: dropdownRef, style: { position: 'relative', display: 'flex', alignItems: 'center' }, children: [jsxs("div", { onClick: () => setIsDropdownOpen(!isDropdownOpen), style: { display: 'flex', alignItems: 'center', gap: 10, height: 35, padding: '10px 12px', borderRadius: 12, border: `1px solid ${isDropdownOpen ? '#e20074' : '#E0E0E0'}`, fontSize: 12, color: '#333', background: '#fff', cursor: 'pointer', userSelect: 'none' }, children: [jsxs("span", { style: { whiteSpace: 'nowrap' }, children: [pageSize, " Rows/Pg"] }), jsx("span", { style: { display: 'flex', alignItems: 'center', justifyContent: 'center', transition: 'transform 0.2s ease', transform: isDropdownOpen ? 'rotate(180deg)' : 'rotate(0deg)' }, children: jsx(DownArrowIcon, { size: 8 }) })] }), isDropdownOpen && (jsx("div", { style: { position: 'absolute', top: 'calc(100% + 4px)', left: 0, minWidth: '100%', background: '#fff', border: '1px solid #E0E0E0', borderRadius: 12, boxShadow: '0 4px 12px rgba(0, 0, 0, 0.1)', zIndex: 1000, overflow: 'hidden' }, children: PAGE_SIZE_OPTIONS.map((size) => (jsxs("div", { onClick: () => { onPageSizeChange(size); setIsDropdownOpen(false); }, style: { padding: '10px 16px', fontSize: 12, color: size === pageSize ? '#e20074' : '#333', background: size === pageSize ? 'rgba(226, 0, 116, 0.05)' : 'transparent', cursor: 'pointer', whiteSpace: 'nowrap' }, children: [size, " Rows/Pg"] }, size))) }))] }), jsxs("div", { style: styles.pageControls, children: [jsx("button", { style: styles.iconBtn(page === 1), disabled: page === 1, onClick: () => onPageChange(1), title: "First page", children: jsx(FirstPageIcon, { size: 10, fill: page === 1 ? '#ccc' : '#666' }) }), jsx("button", { style: styles.iconBtn(page === 1), disabled: page === 1, onClick: () => onPageChange(page - 1), title: "Previous page", children: jsx(BackArrow, { size: 7, fill: page === 1 ? '#ccc' : '#666' }) }), jsxs("span", { style: { padding: '0 8px', fontSize: 12, color: '#333', whiteSpace: 'nowrap', flex: 1, textAlign: 'center' }, children: [start, "-", end, " of ", total.toLocaleString()] }), jsx("button", { style: styles.iconBtn(page >= totalPages), disabled: page >= totalPages, onClick: () => onPageChange(page + 1), title: "Next page", children: jsx(RightArrow, { size: 7, fill: page >= totalPages ? '#ccc' : '#666' }) }), jsx("button", { style: styles.iconBtn(page >= totalPages), disabled: page >= totalPages, onClick: () => onPageChange(totalPages), title: "Last page", children: jsx(LastPageIcon, { size: 10, fill: page >= totalPages ? '#ccc' : '#666' }) })] })] }));
|
|
3462
|
+
};
|
|
3463
|
+
// Main DataTable Component
|
|
3464
|
+
const DataTable = ({ data, columns, loading = false, onSort, config = {}, onRowClick, pagination, onPageChange, onPageSizeChange, headerStyle, checkboxSelection, filterState, onFilterChange, enableColumnReorder, columnOrder, onColumnOrderChange, sortingState: controlledSortingState, customHeaderComponent, }) => {
|
|
3465
|
+
const { height = 0, rowHeight = 40 } = config;
|
|
3466
|
+
const [internalSortingState, setInternalSortingState] = useState({});
|
|
3467
|
+
const sortingState = controlledSortingState ?? internalSortingState;
|
|
3468
|
+
const [openFilterColumn, setOpenFilterColumn] = useState(null);
|
|
3469
|
+
const tableWrapperRef = useRef(null);
|
|
3470
|
+
// Drag and drop state
|
|
3471
|
+
const [draggedColumn, setDraggedColumn] = useState(null);
|
|
3472
|
+
const [hoveredColumn, setHoveredColumn] = useState(null);
|
|
3473
|
+
const [dropIndicator, setDropIndicator] = useState(null);
|
|
3474
|
+
const columnHeaderRefs = useRef(new Map());
|
|
3475
|
+
const dropIndicatorRef = useRef(null);
|
|
3476
|
+
const draggedColumnRef = useRef(null);
|
|
3477
|
+
// Apply client-side filtering
|
|
3478
|
+
const filteredData = useMemo(() => {
|
|
3479
|
+
if (!data || !filterState)
|
|
3480
|
+
return data;
|
|
3481
|
+
const activeFilters = Object.entries(filterState).filter(([, filter]) => filter.selectedValues.size > 0);
|
|
3482
|
+
if (activeFilters.length === 0)
|
|
3483
|
+
return data;
|
|
3484
|
+
return data.filter((row) => {
|
|
3485
|
+
return activeFilters.every(([columnKey, filter]) => {
|
|
3486
|
+
const column = columns.find((col) => col.accessorKey === columnKey);
|
|
3487
|
+
const rowValue = row[columnKey];
|
|
3488
|
+
if (column?.filterFn)
|
|
3489
|
+
return column.filterFn(rowValue, filter.selectedValues);
|
|
3490
|
+
if (rowValue === undefined || rowValue === null)
|
|
3491
|
+
return false;
|
|
3492
|
+
return filter.selectedValues.has(String(rowValue));
|
|
3493
|
+
});
|
|
3494
|
+
});
|
|
3495
|
+
}, [data, filterState, columns]);
|
|
3496
|
+
const handleFilterApply = useCallback((columnKey, selectedValues) => {
|
|
3497
|
+
onFilterChange?.(columnKey, selectedValues);
|
|
3498
|
+
}, [onFilterChange]);
|
|
3499
|
+
// Reorder columns based on columnOrder prop
|
|
3500
|
+
const orderedColumns = useMemo(() => {
|
|
3501
|
+
if (!columnOrder || columnOrder.length === 0)
|
|
3502
|
+
return columns;
|
|
3503
|
+
const columnMap = new Map(columns.map((col) => [col.accessorKey, col]));
|
|
3504
|
+
const ordered = [];
|
|
3505
|
+
for (const key of columnOrder) {
|
|
3506
|
+
const col = columnMap.get(key);
|
|
3507
|
+
if (col) {
|
|
3508
|
+
ordered.push(col);
|
|
3509
|
+
columnMap.delete(key);
|
|
3510
|
+
}
|
|
3511
|
+
}
|
|
3512
|
+
for (const col of columnMap.values()) {
|
|
3513
|
+
ordered.push(col);
|
|
3514
|
+
}
|
|
3515
|
+
return ordered;
|
|
3516
|
+
}, [columns, columnOrder]);
|
|
3517
|
+
// Drag and drop handlers
|
|
3518
|
+
const handleDragStart = useCallback((e, columnKey, isDraggable) => {
|
|
3519
|
+
if (!enableColumnReorder || !isDraggable) {
|
|
3520
|
+
e.preventDefault();
|
|
3521
|
+
return;
|
|
3522
|
+
}
|
|
3523
|
+
setDraggedColumn(columnKey);
|
|
3524
|
+
draggedColumnRef.current = columnKey;
|
|
3525
|
+
e.dataTransfer.effectAllowed = 'move';
|
|
3526
|
+
e.dataTransfer.setData('text/plain', columnKey);
|
|
3527
|
+
}, [enableColumnReorder]);
|
|
3528
|
+
const handleDragOver = useCallback((e, columnKey, isDraggable) => {
|
|
3529
|
+
if (!enableColumnReorder || !draggedColumn || !onColumnOrderChange)
|
|
3530
|
+
return;
|
|
3531
|
+
e.preventDefault();
|
|
3532
|
+
e.dataTransfer.dropEffect = 'move';
|
|
3533
|
+
if (columnKey && columnKey !== draggedColumn) {
|
|
3534
|
+
const headerElement = columnHeaderRefs.current.get(columnKey);
|
|
3535
|
+
let dropPosition = 'before';
|
|
3536
|
+
if (headerElement) {
|
|
3537
|
+
const rect = headerElement.getBoundingClientRect();
|
|
3538
|
+
const mouseX = e.clientX;
|
|
3539
|
+
const elementCenter = rect.left + rect.width / 2;
|
|
3540
|
+
dropPosition = mouseX < elementCenter ? 'before' : 'after';
|
|
3541
|
+
}
|
|
3542
|
+
if (isDraggable) {
|
|
3543
|
+
const indicator = { columnKey, position: dropPosition };
|
|
3544
|
+
setDropIndicator(indicator);
|
|
3545
|
+
dropIndicatorRef.current = indicator;
|
|
3546
|
+
}
|
|
3547
|
+
else {
|
|
3548
|
+
dropIndicatorRef.current = { columnKey, position: dropPosition };
|
|
3549
|
+
}
|
|
3550
|
+
}
|
|
3551
|
+
else if (columnKey === draggedColumn) {
|
|
3552
|
+
setDropIndicator(null);
|
|
3553
|
+
dropIndicatorRef.current = null;
|
|
3554
|
+
}
|
|
3555
|
+
}, [enableColumnReorder, draggedColumn, onColumnOrderChange]);
|
|
3556
|
+
const handleDrop = useCallback((e, targetColumnKey) => {
|
|
3557
|
+
e.preventDefault();
|
|
3558
|
+
const currentDropIndicator = dropIndicatorRef.current;
|
|
3559
|
+
const currentDraggedColumn = draggedColumnRef.current;
|
|
3560
|
+
if (currentDraggedColumn && targetColumnKey && targetColumnKey !== currentDraggedColumn && onColumnOrderChange && currentDropIndicator) {
|
|
3561
|
+
const visibleColumnKeys = orderedColumns.map((col) => col.accessorKey ?? '').filter(Boolean);
|
|
3562
|
+
let currentOrder = columnOrder && columnOrder.length > 0 ? columnOrder.filter((key) => visibleColumnKeys.includes(key)) : visibleColumnKeys;
|
|
3563
|
+
visibleColumnKeys.forEach((key) => { if (!currentOrder.includes(key))
|
|
3564
|
+
currentOrder.push(key); });
|
|
3565
|
+
const draggedIndex = currentOrder.indexOf(currentDraggedColumn);
|
|
3566
|
+
const targetIndex = currentOrder.indexOf(targetColumnKey);
|
|
3567
|
+
if (draggedIndex !== -1 && targetIndex !== -1 && draggedIndex !== targetIndex) {
|
|
3568
|
+
const newOrder = [...currentOrder];
|
|
3569
|
+
newOrder.splice(draggedIndex, 1);
|
|
3570
|
+
let insertIndex;
|
|
3571
|
+
if (draggedIndex < targetIndex) {
|
|
3572
|
+
const adjustedTargetIndex = targetIndex - 1;
|
|
3573
|
+
insertIndex = currentDropIndicator.position === 'after' ? adjustedTargetIndex + 1 : adjustedTargetIndex;
|
|
3574
|
+
}
|
|
3575
|
+
else {
|
|
3576
|
+
insertIndex = currentDropIndicator.position === 'after' ? targetIndex + 1 : targetIndex;
|
|
3577
|
+
}
|
|
3578
|
+
newOrder.splice(insertIndex, 0, currentDraggedColumn);
|
|
3579
|
+
onColumnOrderChange(newOrder.filter(Boolean));
|
|
3580
|
+
}
|
|
3581
|
+
}
|
|
3582
|
+
setDraggedColumn(null);
|
|
3583
|
+
setDropIndicator(null);
|
|
3584
|
+
dropIndicatorRef.current = null;
|
|
3585
|
+
draggedColumnRef.current = null;
|
|
3586
|
+
}, [onColumnOrderChange, columnOrder, orderedColumns]);
|
|
3587
|
+
const handleDragEnd = useCallback(() => {
|
|
3588
|
+
setDraggedColumn(null);
|
|
3589
|
+
setDropIndicator(null);
|
|
3590
|
+
dropIndicatorRef.current = null;
|
|
3591
|
+
draggedColumnRef.current = null;
|
|
3592
|
+
}, []);
|
|
3593
|
+
const tableData = filteredData ?? [];
|
|
3594
|
+
const table = useReactTable({
|
|
3595
|
+
data: tableData,
|
|
3596
|
+
columns: orderedColumns,
|
|
3597
|
+
getCoreRowModel: getCoreRowModel(),
|
|
3598
|
+
});
|
|
3599
|
+
const { getHeaderGroups, getRowModel } = table;
|
|
3600
|
+
const rows = getRowModel().rows;
|
|
3601
|
+
const headerGroup = getHeaderGroups();
|
|
3602
|
+
return (jsxs("div", { style: { ...styles.container, position: 'relative', height: height > 0 ? height : '100%' }, children: [customHeaderComponent, jsx("div", { style: { position: 'relative', flex: 1, minHeight: 0, display: 'flex', flexDirection: 'column' }, children: jsx("div", { ref: tableWrapperRef, style: { overflowX: 'auto', overflowY: 'auto', flex: 1, minHeight: 0, maxHeight: height > 0 ? height - 50 : undefined, ...(draggedColumn && { cursor: 'grabbing' }) }, children: jsxs("table", { style: styles.table, children: [jsx("thead", { style: styles.tableHead, children: headerGroup.map((hg) => (jsx("tr", { children: hg.headers.map((header, idx) => {
|
|
3603
|
+
const columnDef = header.column.columnDef;
|
|
3604
|
+
const columnKey = columnDef.accessorKey ?? '';
|
|
3605
|
+
const isDraggable = !!(enableColumnReorder && !columnDef.disableDrag && !columnDef.isPrimary && columnKey);
|
|
3606
|
+
const isDragging = draggedColumn === columnKey;
|
|
3607
|
+
const isHovered = hoveredColumn === columnKey;
|
|
3608
|
+
typeof columnDef.header === 'string' ? columnDef.header : columnKey;
|
|
3609
|
+
const showDropIndicatorBefore = dropIndicator?.columnKey === columnKey && dropIndicator?.position === 'before';
|
|
3610
|
+
const showDropIndicatorAfter = dropIndicator?.columnKey === columnKey && dropIndicator?.position === 'after';
|
|
3611
|
+
return (jsxs("th", { ref: (el) => { if (el && columnKey)
|
|
3612
|
+
columnHeaderRefs.current.set(columnKey, el); }, onDragOver: (e) => handleDragOver(e, columnKey, isDraggable), onDrop: (e) => handleDrop(e, columnKey), onMouseEnter: () => isDraggable && setHoveredColumn(columnKey), onMouseLeave: () => setHoveredColumn(null), style: {
|
|
3613
|
+
...styles.tableHeaderCell,
|
|
3614
|
+
...headerStyle,
|
|
3615
|
+
...(idx === 0 && { paddingLeft: 12.5, borderTopLeftRadius: 12, borderBottomLeftRadius: 12 }),
|
|
3616
|
+
...(idx === hg.headers.length - 1 && { borderTopRightRadius: 12, borderBottomRightRadius: 12 }),
|
|
3617
|
+
...(isDragging && { opacity: 0.5 }),
|
|
3618
|
+
}, children: [showDropIndicatorBefore && jsx("div", { style: { position: 'absolute', left: 0, top: 0, bottom: 0, width: 3, background: '#FFADD5', zIndex: 10 } }), showDropIndicatorAfter && jsx("div", { style: { position: 'absolute', right: 0, top: 0, bottom: 0, width: 3, background: '#FFADD5', zIndex: 10 } }), (() => {
|
|
3619
|
+
const isColumnSortable = columnDef.enableSorting === true;
|
|
3620
|
+
const showSorting = isColumnSortable;
|
|
3621
|
+
const showCheckbox = columnDef.enableCheckbox && checkboxSelection;
|
|
3622
|
+
const showFilter = columnDef.enableFilter && columnDef.accessorKey && onFilterChange;
|
|
3623
|
+
const showDropdown = (showSorting || showFilter) && columnDef.accessorKey;
|
|
3624
|
+
const currentSortOrder = columnDef.accessorKey ? sortingState[columnDef.accessorKey] : undefined;
|
|
3625
|
+
const columnFilter = columnDef.accessorKey ? filterState?.[columnDef.accessorKey] : undefined;
|
|
3626
|
+
const hasActiveFilter = !!(columnFilter && columnFilter.selectedValues && columnFilter.selectedValues.size > 0);
|
|
3627
|
+
const isColumnActive = !!currentSortOrder || hasActiveFilter;
|
|
3628
|
+
return (jsxs("div", { style: { display: 'flex', alignItems: 'center', gap: showCheckbox ? 8 : showDropdown ? 4 : 2, cursor: showDropdown ? 'pointer' : 'default', justifyContent: 'flex-start' }, onClick: () => { if (showDropdown && columnDef.accessorKey)
|
|
3629
|
+
setOpenFilterColumn(openFilterColumn === columnDef.accessorKey ? null : columnDef.accessorKey); }, children: [showCheckbox && (jsx(CustomCheckbox, { checked: checkboxSelection.isAllSelected, indeterminate: checkboxSelection.isPartiallySelected, onClick: (e) => { e.stopPropagation(); checkboxSelection.onSelectAll(); } })), jsx("span", { style: { color: isColumnActive ? brand.primary : 'inherit' }, children: flexRender(header.column.columnDef.header, header.getContext()) }), showDropdown && columnDef.accessorKey && (jsx(FilterDropdown, { columnKey: columnDef.accessorKey, columnHeader: typeof columnDef.header === 'string' ? columnDef.header : undefined, data: data ?? [], filterOptions: columnDef.filterOptions, currentFilter: filterState?.[columnDef.accessorKey], onApply: handleFilterApply, filterLabel: columnDef.filterLabel, isOpen: openFilterColumn === columnDef.accessorKey, onToggle: () => setOpenFilterColumn(openFilterColumn === columnDef.accessorKey ? null : columnDef.accessorKey ?? null), onClose: () => setOpenFilterColumn(null), enableSorting: showSorting, enableFilter: !!showFilter, currentSortOrder: currentSortOrder ?? null, onSort: (order) => {
|
|
3630
|
+
if (columnDef.accessorKey) {
|
|
3631
|
+
if (!controlledSortingState)
|
|
3632
|
+
setInternalSortingState({ [columnDef.accessorKey]: order });
|
|
3633
|
+
onSort?.(columnDef.accessorKey, order);
|
|
3634
|
+
}
|
|
3635
|
+
} })), isDraggable && (jsx("div", { draggable: true, onDragStart: (e) => { e.stopPropagation(); handleDragStart(e, columnKey, isDraggable); }, onDragEnd: handleDragEnd, style: { display: 'flex', alignItems: 'center', justifyContent: 'center', cursor: 'grab', padding: 2, marginLeft: 'auto', opacity: isHovered || isDragging ? 1 : 0, transition: 'opacity 0.15s ease' }, onClick: (e) => e.stopPropagation(), children: jsx(DragHandleIcon, { size: 16, color: isDragging ? brand.primary : gray[500] }) }))] }));
|
|
3636
|
+
})()] }, header.id));
|
|
3637
|
+
}) }, hg.id))) }), loading ? (jsx("tbody", { children: jsx("tr", { children: jsx("td", { colSpan: orderedColumns.length, style: { textAlign: 'center', verticalAlign: 'middle', padding: '70px 20px', height: 400 }, children: jsx("div", { style: { fontSize: 18, color: 'rgb(108, 114, 128)', display: 'flex', justifyContent: 'center' }, children: "Loading..." }) }) }) })) : rows.length ? (jsx("tbody", { children: rows.map((row, idx) => (jsx("tr", { style: styles.tableRow(idx !== rows.length - 1, false), ...(onRowClick ? { onClick: () => onRowClick(row.original) } : {}), onMouseEnter: (e) => (e.currentTarget.style.background = '#f8f9fa'), onMouseLeave: (e) => (e.currentTarget.style.background = 'transparent'), children: row.getVisibleCells().map((cell, cellIdx) => {
|
|
3638
|
+
const columnDef = cell.column.columnDef;
|
|
3639
|
+
const showCheckbox = columnDef.enableCheckbox && checkboxSelection;
|
|
3640
|
+
const rowId = showCheckbox ? checkboxSelection.getRowId(row.original) : '';
|
|
3641
|
+
const isRowSelected = showCheckbox ? checkboxSelection.selectedRows.has(rowId) : false;
|
|
3642
|
+
const isDragging = draggedColumn === columnDef.accessorKey;
|
|
3643
|
+
return (jsx("td", { style: { ...styles.tableCell, height: rowHeight, ...(cellIdx === 0 && { paddingLeft: 12.5 }), ...(isDragging && { opacity: 1, background: '#fafafa' }) }, children: jsxs("div", { style: { display: 'flex', alignItems: 'center', gap: showCheckbox ? 16 : 0, overflow: 'hidden', minWidth: 0 }, children: [showCheckbox && jsx(CustomCheckbox, { checked: isRowSelected, onClick: (e) => checkboxSelection.onRowSelect(rowId, e) }), columnDef.truncate ? (jsx("span", { style: { overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap', minWidth: 0, flex: 1, display: 'block' }, children: flexRender(cell.column.columnDef.cell, cell.getContext()) })) : (flexRender(cell.column.columnDef.cell, cell.getContext()))] }) }, cell.id));
|
|
3644
|
+
}) }, row.id))) })) : (jsx("tbody", { children: jsx("tr", { children: jsx("td", { colSpan: orderedColumns.length, style: { textAlign: 'center', verticalAlign: 'middle', padding: '70px 20px' }, children: jsx("div", { style: { fontSize: 18, color: 'rgb(108, 114, 128)', display: 'flex', justifyContent: 'center' }, children: "No data" }) }) }) }))] }) }) }), pagination && onPageChange && onPageSizeChange && (jsx(Pagination, { page: pagination.page, pageSize: pagination.pageSize, total: pagination.totalRecords, onPageChange: onPageChange, onPageSizeChange: onPageSizeChange }))] }));
|
|
3645
|
+
};
|
|
3646
|
+
|
|
3647
|
+
export { Button, Card, CardBody, CardFooter, CardHeader, CustomCheckbox, DataTable, Input };
|
|
3648
|
+
//# sourceMappingURL=index.esm.js.map
|