msw-dev-tool 1.1.4 → 1.1.5

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