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