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