@tanstack/table-core 8.0.0-alpha.10

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 (112) hide show
  1. package/build/cjs/_virtual/_rollupPluginBabelHelpers.js +112 -0
  2. package/build/cjs/_virtual/_rollupPluginBabelHelpers.js.map +1 -0
  3. package/build/cjs/aggregationTypes.js +130 -0
  4. package/build/cjs/aggregationTypes.js.map +1 -0
  5. package/build/cjs/core.js +545 -0
  6. package/build/cjs/core.js.map +1 -0
  7. package/build/cjs/createTable.js +65 -0
  8. package/build/cjs/createTable.js.map +1 -0
  9. package/build/cjs/features/ColumnSizing.js +316 -0
  10. package/build/cjs/features/ColumnSizing.js.map +1 -0
  11. package/build/cjs/features/Expanding.js +238 -0
  12. package/build/cjs/features/Expanding.js.map +1 -0
  13. package/build/cjs/features/Filters.js +413 -0
  14. package/build/cjs/features/Filters.js.map +1 -0
  15. package/build/cjs/features/Grouping.js +227 -0
  16. package/build/cjs/features/Grouping.js.map +1 -0
  17. package/build/cjs/features/Headers.js +630 -0
  18. package/build/cjs/features/Headers.js.map +1 -0
  19. package/build/cjs/features/Ordering.js +86 -0
  20. package/build/cjs/features/Ordering.js.map +1 -0
  21. package/build/cjs/features/Pagination.js +193 -0
  22. package/build/cjs/features/Pagination.js.map +1 -0
  23. package/build/cjs/features/Pinning.js +148 -0
  24. package/build/cjs/features/Pinning.js.map +1 -0
  25. package/build/cjs/features/RowSelection.js +525 -0
  26. package/build/cjs/features/RowSelection.js.map +1 -0
  27. package/build/cjs/features/Sorting.js +313 -0
  28. package/build/cjs/features/Sorting.js.map +1 -0
  29. package/build/cjs/features/Visibility.js +172 -0
  30. package/build/cjs/features/Visibility.js.map +1 -0
  31. package/build/cjs/filterTypes.js +172 -0
  32. package/build/cjs/filterTypes.js.map +1 -0
  33. package/build/cjs/index.js +75 -0
  34. package/build/cjs/index.js.map +1 -0
  35. package/build/cjs/sortTypes.js +122 -0
  36. package/build/cjs/sortTypes.js.map +1 -0
  37. package/build/cjs/types.js +22 -0
  38. package/build/cjs/types.js.map +1 -0
  39. package/build/cjs/utils/columnFilterRowsFn.js +131 -0
  40. package/build/cjs/utils/columnFilterRowsFn.js.map +1 -0
  41. package/build/cjs/utils/expandRowsFn.js +38 -0
  42. package/build/cjs/utils/expandRowsFn.js.map +1 -0
  43. package/build/cjs/utils/globalFilterRowsFn.js +101 -0
  44. package/build/cjs/utils/globalFilterRowsFn.js.map +1 -0
  45. package/build/cjs/utils/groupRowsFn.js +155 -0
  46. package/build/cjs/utils/groupRowsFn.js.map +1 -0
  47. package/build/cjs/utils/paginateRowsFn.js +44 -0
  48. package/build/cjs/utils/paginateRowsFn.js.map +1 -0
  49. package/build/cjs/utils/sortRowsFn.js +94 -0
  50. package/build/cjs/utils/sortRowsFn.js.map +1 -0
  51. package/build/cjs/utils.js +167 -0
  52. package/build/cjs/utils.js.map +1 -0
  53. package/build/esm/index.js +4689 -0
  54. package/build/esm/index.js.map +1 -0
  55. package/build/stats-html.html +2689 -0
  56. package/build/stats-react.json +939 -0
  57. package/build/types/aggregationTypes.d.ts +22 -0
  58. package/build/types/core.d.ts +105 -0
  59. package/build/types/createTable.d.ts +42 -0
  60. package/build/types/features/ColumnSizing.d.ts +75 -0
  61. package/build/types/features/Expanding.d.ts +50 -0
  62. package/build/types/features/Filters.d.ts +92 -0
  63. package/build/types/features/Grouping.d.ts +85 -0
  64. package/build/types/features/Headers.d.ts +43 -0
  65. package/build/types/features/Ordering.d.ts +21 -0
  66. package/build/types/features/Pagination.d.ts +41 -0
  67. package/build/types/features/Pinning.d.ts +41 -0
  68. package/build/types/features/RowSelection.d.ts +60 -0
  69. package/build/types/features/Sorting.d.ts +81 -0
  70. package/build/types/features/Visibility.d.ts +49 -0
  71. package/build/types/filterTypes.d.ts +50 -0
  72. package/build/types/index.d.ts +23 -0
  73. package/build/types/sortTypes.d.ts +18 -0
  74. package/build/types/types.d.ts +138 -0
  75. package/build/types/utils/columnFilterRowsFn.d.ts +2 -0
  76. package/build/types/utils/expandRowsFn.d.ts +2 -0
  77. package/build/types/utils/globalFilterRowsFn.d.ts +2 -0
  78. package/build/types/utils/groupRowsFn.d.ts +2 -0
  79. package/build/types/utils/paginateRowsFn.d.ts +2 -0
  80. package/build/types/utils/sortRowsFn.d.ts +2 -0
  81. package/build/types/utils.d.ts +23 -0
  82. package/build/umd/index.development.js +4728 -0
  83. package/build/umd/index.development.js.map +1 -0
  84. package/build/umd/index.production.js +12 -0
  85. package/build/umd/index.production.js.map +1 -0
  86. package/package.json +40 -0
  87. package/src/.DS_Store +0 -0
  88. package/src/aggregationTypes.ts +115 -0
  89. package/src/core.tsx +763 -0
  90. package/src/createTable.tsx +137 -0
  91. package/src/features/ColumnSizing.ts +432 -0
  92. package/src/features/Expanding.ts +320 -0
  93. package/src/features/Filters.ts +567 -0
  94. package/src/features/Grouping.ts +363 -0
  95. package/src/features/Headers.ts +747 -0
  96. package/src/features/Ordering.ts +112 -0
  97. package/src/features/Pagination.ts +252 -0
  98. package/src/features/Pinning.ts +177 -0
  99. package/src/features/RowSelection.ts +655 -0
  100. package/src/features/Sorting.ts +460 -0
  101. package/src/features/Visibility.ts +242 -0
  102. package/src/filterTypes.ts +188 -0
  103. package/src/index.tsx +23 -0
  104. package/src/sortTypes.ts +147 -0
  105. package/src/types.ts +311 -0
  106. package/src/utils/columnFilterRowsFn.ts +113 -0
  107. package/src/utils/expandRowsFn.ts +30 -0
  108. package/src/utils/globalFilterRowsFn.ts +89 -0
  109. package/src/utils/groupRowsFn.ts +170 -0
  110. package/src/utils/paginateRowsFn.ts +28 -0
  111. package/src/utils/sortRowsFn.ts +95 -0
  112. package/src/utils.tsx +221 -0
@@ -0,0 +1,4728 @@
1
+ /**
2
+ * table-core
3
+ *
4
+ * Copyright (c) TanStack
5
+ *
6
+ * This source code is licensed under the MIT license found in the
7
+ * LICENSE.md file in the root directory of this source tree.
8
+ *
9
+ * @license MIT
10
+ */
11
+ (function (global, factory) {
12
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react')) :
13
+ typeof define === 'function' && define.amd ? define(['exports', 'react'], factory) :
14
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.TableCore = {}, global.React));
15
+ })(this, (function (exports, React) { 'use strict';
16
+
17
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
18
+
19
+ var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
20
+
21
+ function _extends() {
22
+ _extends = Object.assign || function (target) {
23
+ for (var i = 1; i < arguments.length; i++) {
24
+ var source = arguments[i];
25
+
26
+ for (var key in source) {
27
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
28
+ target[key] = source[key];
29
+ }
30
+ }
31
+ }
32
+
33
+ return target;
34
+ };
35
+
36
+ return _extends.apply(this, arguments);
37
+ }
38
+
39
+ function _objectWithoutPropertiesLoose(source, excluded) {
40
+ if (source == null) return {};
41
+ var target = {};
42
+ var sourceKeys = Object.keys(source);
43
+ var key, i;
44
+
45
+ for (i = 0; i < sourceKeys.length; i++) {
46
+ key = sourceKeys[i];
47
+ if (excluded.indexOf(key) >= 0) continue;
48
+ target[key] = source[key];
49
+ }
50
+
51
+ return target;
52
+ }
53
+
54
+ function _unsupportedIterableToArray(o, minLen) {
55
+ if (!o) return;
56
+ if (typeof o === "string") return _arrayLikeToArray(o, minLen);
57
+ var n = Object.prototype.toString.call(o).slice(8, -1);
58
+ if (n === "Object" && o.constructor) n = o.constructor.name;
59
+ if (n === "Map" || n === "Set") return Array.from(o);
60
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
61
+ }
62
+
63
+ function _arrayLikeToArray(arr, len) {
64
+ if (len == null || len > arr.length) len = arr.length;
65
+
66
+ for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
67
+
68
+ return arr2;
69
+ }
70
+
71
+ function _createForOfIteratorHelperLoose(o, allowArrayLike) {
72
+ var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
73
+ if (it) return (it = it.call(o)).next.bind(it);
74
+
75
+ if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
76
+ if (it) o = it;
77
+ var i = 0;
78
+ return function () {
79
+ if (i >= o.length) return {
80
+ done: true
81
+ };
82
+ return {
83
+ done: false,
84
+ value: o[i++]
85
+ };
86
+ };
87
+ }
88
+
89
+ throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
90
+ }
91
+
92
+ function _toPrimitive(input, hint) {
93
+ if (typeof input !== "object" || input === null) return input;
94
+ var prim = input[Symbol.toPrimitive];
95
+
96
+ if (prim !== undefined) {
97
+ var res = prim.call(input, hint || "default");
98
+ if (typeof res !== "object") return res;
99
+ throw new TypeError("@@toPrimitive must return a primitive value.");
100
+ }
101
+
102
+ return (hint === "string" ? String : Number)(input);
103
+ }
104
+
105
+ function _toPropertyKey(arg) {
106
+ var key = _toPrimitive(arg, "string");
107
+
108
+ return typeof key === "symbol" ? key : String(key);
109
+ }
110
+
111
+ function functionalUpdate(updater, input) {
112
+ return typeof updater === 'function' ? updater(input) : updater;
113
+ }
114
+ function noop() {//
115
+ }
116
+ function makeStateUpdater(key, instance) {
117
+ return function (updater) {
118
+ instance.setState(function (old) {
119
+ var _extends2;
120
+
121
+ return _extends({}, old, (_extends2 = {}, _extends2[key] = functionalUpdate(updater, old[key]), _extends2));
122
+ });
123
+ };
124
+ }
125
+ function isFunction(d) {
126
+ return d instanceof Function;
127
+ }
128
+ function flattenBy(arr, getChildren) {
129
+ var flat = [];
130
+
131
+ var recurse = function recurse(subArr) {
132
+ subArr.forEach(function (item) {
133
+ flat.push(item);
134
+ var children = getChildren(item);
135
+
136
+ if (children != null && children.length) {
137
+ recurse(children);
138
+ }
139
+ });
140
+ };
141
+
142
+ recurse(arr);
143
+ return flat;
144
+ }
145
+ // @ts-ignore // Just rely on the type, not the implementation
146
+ var propGetter = function propGetter(initial, getter) {
147
+ if (isFunction(getter)) {
148
+ return getter(initial);
149
+ }
150
+
151
+ return _extends({}, initial, getter != null ? getter : {});
152
+ };
153
+ function memo(getDeps, fn, opts) {
154
+ var deps = [];
155
+ var result;
156
+ return function () {
157
+ var depTime;
158
+ if (opts.key && opts.debug) depTime = performance.now();
159
+ var newDeps = getDeps();
160
+ var depsChanged = newDeps.length !== deps.length || newDeps.some(function (dep, index) {
161
+ return deps[index] !== dep;
162
+ });
163
+
164
+ if (depsChanged) {
165
+ var oldResult = result;
166
+ var resultTime;
167
+ if (opts.key && opts.debug) resultTime = performance.now();
168
+ result = fn.apply(void 0, newDeps);
169
+ deps = newDeps;
170
+ opts == null ? void 0 : opts.onChange == null ? void 0 : opts.onChange(result, oldResult);
171
+
172
+ if (opts.key && opts.debug) {
173
+ if (opts != null && opts.debug()) {
174
+ var depEndTime = Math.round((performance.now() - depTime) * 100) / 100;
175
+ var resultEndTime = Math.round((performance.now() - resultTime) * 100) / 100;
176
+ var resultFpsPercentage = resultEndTime / 16;
177
+
178
+ var pad = function pad(str, num) {
179
+ str = String(str);
180
+
181
+ while (str.length < num) {
182
+ str = ' ' + str;
183
+ }
184
+
185
+ return str;
186
+ };
187
+
188
+ console.info("%c\u23F1 " + pad(resultEndTime, 5) + " /" + pad(depEndTime, 5) + " ms", "\n font-size: .6rem;\n font-weight: bold;\n color: hsl(" + Math.max(0, Math.min(120 - 120 * resultFpsPercentage, 120)) + "deg 100% 31%);", opts == null ? void 0 : opts.key, _extends({
189
+ length: deps.length + " -> " + newDeps.length
190
+ }, newDeps.map(function (_, index) {
191
+ if (deps[index] !== newDeps[index]) {
192
+ return [index, deps[index], newDeps[index]];
193
+ }
194
+
195
+ return false;
196
+ }).filter(Boolean).reduce(function (accu, _ref) {
197
+ var _extends3;
198
+
199
+ var a = _ref[0],
200
+ b = _ref[1];
201
+ return _extends({}, accu, (_extends3 = {}, _extends3[a] = b, _extends3));
202
+ }, {}), {
203
+ parent: parent
204
+ }));
205
+ }
206
+ }
207
+
208
+ oldResult = undefined;
209
+ }
210
+
211
+ return result;
212
+ };
213
+ }
214
+ function flexRender(Comp, props) {
215
+ return !Comp ? null : isReactComponent(Comp) ? /*#__PURE__*/React__default["default"].createElement(Comp, props) : Comp;
216
+ }
217
+
218
+ function isReactComponent(component) {
219
+ return isClassComponent(component) || typeof component === 'function' || isExoticComponent(component);
220
+ }
221
+
222
+ function isClassComponent(component) {
223
+ return typeof component === 'function' && function () {
224
+ var proto = Object.getPrototypeOf(component);
225
+ return proto.prototype && proto.prototype.isReactComponent;
226
+ }();
227
+ }
228
+
229
+ function isExoticComponent(component) {
230
+ return typeof component === 'object' && typeof component.$$typeof === 'symbol' && ['react.memo', 'react.forward_ref'].includes(component.$$typeof.description);
231
+ } // export function hashString(str: string, seed = 0): string {
232
+ // let h1 = 0xdeadbeef ^ seed,
233
+ // h2 = 0x41c6ce57 ^ seed
234
+ // for (let i = 0, ch; i < str.length; i++) {
235
+ // ch = str.charCodeAt(i)
236
+ // h1 = Math.imul(h1 ^ ch, 2654435761)
237
+ // h2 = Math.imul(h2 ^ ch, 1597334677)
238
+ // }
239
+ // h1 =
240
+ // Math.imul(h1 ^ (h1 >>> 16), 2246822507) ^
241
+ // Math.imul(h2 ^ (h2 >>> 13), 3266489909)
242
+ // h2 =
243
+ // Math.imul(h2 ^ (h2 >>> 16), 2246822507) ^
244
+ // Math.imul(h1 ^ (h1 >>> 13), 3266489909)
245
+ // return (4294967296 * (2097151 & h2) + (h1 >>> 0)).toString()
246
+ // }
247
+
248
+ // declare global {
249
+ // const "development" !== 'production': boolean
250
+ // }
251
+ //
252
+ var Please_use_the_create_table_column_utilities_to_define_columns = Symbol();
253
+
254
+ //
255
+ var Visibility = {
256
+ getInitialState: function getInitialState() {
257
+ return {
258
+ columnVisibility: {}
259
+ };
260
+ },
261
+ getDefaultOptions: function getDefaultOptions(instance) {
262
+ return {
263
+ onColumnVisibilityChange: makeStateUpdater('columnVisibility', instance)
264
+ };
265
+ },
266
+ getDefaultColumn: function getDefaultColumn() {
267
+ return {
268
+ defaultIsVisible: true
269
+ };
270
+ },
271
+ createColumn: function createColumn(column, instance) {
272
+ return {
273
+ getCanHide: function getCanHide() {
274
+ return instance.getColumnCanHide(column.id);
275
+ },
276
+ getIsVisible: function getIsVisible() {
277
+ return instance.getColumnIsVisible(column.id);
278
+ },
279
+ toggleVisibility: function toggleVisibility(value) {
280
+ return instance.toggleColumnVisibility(column.id, value);
281
+ },
282
+ getToggleVisibilityProps: function getToggleVisibilityProps(userProps) {
283
+ var props = {
284
+ type: 'checkbox',
285
+ checked: column.getIsVisible == null ? void 0 : column.getIsVisible(),
286
+ title: 'Toggle Column Visibility',
287
+ onChange: function onChange(e) {
288
+ column.toggleVisibility == null ? void 0 : column.toggleVisibility(e.target.checked);
289
+ }
290
+ };
291
+ return propGetter(props, userProps);
292
+ }
293
+ };
294
+ },
295
+ getInstance: function getInstance(instance) {
296
+ return {
297
+ getVisibleFlatColumns: memo(function () {
298
+ return [instance.getAllFlatColumns(), instance.getAllFlatColumns().filter(function (d) {
299
+ return d.getIsVisible == null ? void 0 : d.getIsVisible();
300
+ }).map(function (d) {
301
+ return d.id;
302
+ }).join('_')];
303
+ }, function (allFlatColumns) {
304
+ return allFlatColumns.filter(function (d) {
305
+ return d.getIsVisible == null ? void 0 : d.getIsVisible();
306
+ });
307
+ }, {
308
+ key: 'getVisibleFlatColumns',
309
+ debug: function debug() {
310
+ var _instance$options$deb;
311
+
312
+ return (_instance$options$deb = instance.options.debugAll) != null ? _instance$options$deb : instance.options.debugColumns;
313
+ }
314
+ }),
315
+ getVisibleLeafColumns: memo(function () {
316
+ return [instance.getAllLeafColumns(), instance.getAllLeafColumns().filter(function (d) {
317
+ return d.getIsVisible == null ? void 0 : d.getIsVisible();
318
+ }).map(function (d) {
319
+ return d.id;
320
+ }).join('_')];
321
+ }, function (allFlatColumns) {
322
+ return allFlatColumns.filter(function (d) {
323
+ return d.getIsVisible == null ? void 0 : d.getIsVisible();
324
+ });
325
+ }, {
326
+ key: 'getVisibleLeafColumns',
327
+ debug: function debug() {
328
+ var _instance$options$deb2;
329
+
330
+ return (_instance$options$deb2 = instance.options.debugAll) != null ? _instance$options$deb2 : instance.options.debugColumns;
331
+ }
332
+ }),
333
+ setColumnVisibility: function setColumnVisibility(updater) {
334
+ return instance.options.onColumnVisibilityChange == null ? void 0 : instance.options.onColumnVisibilityChange(updater, functionalUpdate(updater, instance.getState().columnVisibility));
335
+ },
336
+ toggleColumnVisibility: function toggleColumnVisibility(columnId, value) {
337
+ if (!columnId) return;
338
+
339
+ if (instance.getColumnCanHide(columnId)) {
340
+ instance.setColumnVisibility(function (old) {
341
+ var _extends2;
342
+
343
+ return _extends({}, old, (_extends2 = {}, _extends2[columnId] = value != null ? value : !instance.getColumnIsVisible(columnId), _extends2));
344
+ });
345
+ }
346
+ },
347
+ toggleAllColumnsVisible: function toggleAllColumnsVisible(value) {
348
+ var _value;
349
+
350
+ value = (_value = value) != null ? _value : !instance.getIsAllColumnsVisible();
351
+ instance.setColumnVisibility(instance.getAllLeafColumns().reduce(function (obj, column) {
352
+ var _extends3;
353
+
354
+ return _extends({}, obj, (_extends3 = {}, _extends3[column.id] = !value ? !(column.getCanHide != null && column.getCanHide()) : value, _extends3));
355
+ }, {}));
356
+ },
357
+ getColumnIsVisible: function getColumnIsVisible(columnId) {
358
+ var _ref, _instance$getState$co, _instance$getState$co2;
359
+
360
+ var column = instance.getColumn(columnId);
361
+
362
+ if (!column) {
363
+ throw new Error();
364
+ }
365
+
366
+ return (_ref = (_instance$getState$co = (_instance$getState$co2 = instance.getState().columnVisibility) == null ? void 0 : _instance$getState$co2[columnId]) != null ? _instance$getState$co : column.defaultIsVisible) != null ? _ref : true;
367
+ },
368
+ getColumnCanHide: function getColumnCanHide(columnId) {
369
+ var _ref2, _ref3, _instance$options$ena;
370
+
371
+ var column = instance.getColumn(columnId);
372
+
373
+ if (!column) {
374
+ throw new Error();
375
+ }
376
+
377
+ return (_ref2 = (_ref3 = (_instance$options$ena = instance.options.enableHiding) != null ? _instance$options$ena : column.enableHiding) != null ? _ref3 : column.defaultCanHide) != null ? _ref2 : true;
378
+ },
379
+ getIsAllColumnsVisible: function getIsAllColumnsVisible() {
380
+ return !instance.getAllLeafColumns().some(function (column) {
381
+ return !(column.getIsVisible != null && column.getIsVisible());
382
+ });
383
+ },
384
+ getIsSomeColumnsVisible: function getIsSomeColumnsVisible() {
385
+ return instance.getAllLeafColumns().some(function (column) {
386
+ return column.getIsVisible == null ? void 0 : column.getIsVisible();
387
+ });
388
+ },
389
+ getToggleAllColumnsVisibilityProps: function getToggleAllColumnsVisibilityProps(userProps) {
390
+ var props = {
391
+ onChange: function onChange(e) {
392
+ var _e$target;
393
+
394
+ instance.toggleAllColumnsVisible((_e$target = e.target) == null ? void 0 : _e$target.checked);
395
+ },
396
+ type: 'checkbox',
397
+ title: 'Toggle visibility for all columns',
398
+ checked: instance.getIsAllColumnsVisible(),
399
+ indeterminate: !instance.getIsAllColumnsVisible() && instance.getIsSomeColumnsVisible() ? 'indeterminate' : undefined
400
+ };
401
+ return propGetter(props, userProps);
402
+ }
403
+ };
404
+ }
405
+ };
406
+
407
+ var aggregationTypes = {
408
+ sum: sum,
409
+ min: min,
410
+ max: max,
411
+ extent: extent,
412
+ mean: mean,
413
+ median: median,
414
+ unique: unique,
415
+ uniqueCount: uniqueCount,
416
+ count: count
417
+ };
418
+
419
+ function sum(_leafValues, childValues) {
420
+ // It's faster to just add the aggregations together instead of
421
+ // process leaf nodes individually
422
+ return childValues.reduce(function (sum, next) {
423
+ return sum + (typeof next === 'number' ? next : 0);
424
+ }, 0);
425
+ }
426
+
427
+ function min(_leafValues, childValues) {
428
+ var min;
429
+
430
+ for (var _iterator = _createForOfIteratorHelperLoose(childValues), _step; !(_step = _iterator()).done;) {
431
+ var value = _step.value;
432
+
433
+ if (value != null && (min > value || min === undefined && value >= value)) {
434
+ min = value;
435
+ }
436
+ }
437
+
438
+ return min;
439
+ }
440
+
441
+ function max(_leafValues, childValues) {
442
+ var max;
443
+
444
+ for (var _iterator2 = _createForOfIteratorHelperLoose(childValues), _step2; !(_step2 = _iterator2()).done;) {
445
+ var value = _step2.value;
446
+
447
+ if (value != null && (max < value || max === undefined && value >= value)) {
448
+ max = value;
449
+ }
450
+ }
451
+
452
+ return max;
453
+ }
454
+
455
+ function extent(_leafValues, childValues) {
456
+ var min;
457
+ var max;
458
+
459
+ for (var _iterator3 = _createForOfIteratorHelperLoose(childValues), _step3; !(_step3 = _iterator3()).done;) {
460
+ var value = _step3.value;
461
+
462
+ if (value != null) {
463
+ if (min === undefined) {
464
+ if (value >= value) min = max = value;
465
+ } else {
466
+ if (min > value) min = value;
467
+ if (max < value) max = value;
468
+ }
469
+ }
470
+ }
471
+
472
+ return [min, max];
473
+ }
474
+
475
+ function mean(leafValues) {
476
+ var count = 0;
477
+ var sum = 0;
478
+
479
+ for (var _iterator4 = _createForOfIteratorHelperLoose(leafValues), _step4; !(_step4 = _iterator4()).done;) {
480
+ var value = _step4.value;
481
+
482
+ if (value != null && (value = +value) >= value) {
483
+ ++count, sum += value;
484
+ }
485
+ }
486
+
487
+ if (count) return sum / count;
488
+ return;
489
+ }
490
+
491
+ function median(values) {
492
+ if (!values.length) {
493
+ return;
494
+ }
495
+
496
+ var min = 0;
497
+ var max = 0;
498
+ values.forEach(function (value) {
499
+ if (typeof value === 'number') {
500
+ min = Math.min(min, value);
501
+ max = Math.max(max, value);
502
+ }
503
+ });
504
+ return (min + max) / 2;
505
+ }
506
+
507
+ function unique(values) {
508
+ return Array.from(new Set(values).values());
509
+ }
510
+
511
+ function uniqueCount(values) {
512
+ return new Set(values).size;
513
+ }
514
+
515
+ function count(values) {
516
+ return values.length;
517
+ }
518
+
519
+ //
520
+ var Grouping = {
521
+ getDefaultColumn: function getDefaultColumn() {
522
+ return {
523
+ aggregationType: 'auto'
524
+ };
525
+ },
526
+ getInitialState: function getInitialState() {
527
+ return {
528
+ grouping: []
529
+ };
530
+ },
531
+ getDefaultOptions: function getDefaultOptions(instance) {
532
+ return {
533
+ onGroupingChange: makeStateUpdater('grouping', instance),
534
+ autoResetGrouping: true,
535
+ groupedColumnMode: 'reorder'
536
+ };
537
+ },
538
+ createColumn: function createColumn(column, instance) {
539
+ return {
540
+ aggregationType: column.aggregationType,
541
+ getCanGroup: function getCanGroup() {
542
+ return instance.getColumnCanGroup(column.id);
543
+ },
544
+ getGroupedIndex: function getGroupedIndex() {
545
+ return instance.getColumnGroupedIndex(column.id);
546
+ },
547
+ getIsGrouped: function getIsGrouped() {
548
+ return instance.getColumnIsGrouped(column.id);
549
+ },
550
+ toggleGrouping: function toggleGrouping() {
551
+ return instance.toggleColumnGrouping(column.id);
552
+ },
553
+ getToggleGroupingProps: function getToggleGroupingProps(userProps) {
554
+ return instance.getToggleGroupingProps(column.id, userProps);
555
+ }
556
+ };
557
+ },
558
+ getInstance: function getInstance(instance) {
559
+ var registered = false;
560
+ return {
561
+ _notifyGroupingReset: function _notifyGroupingReset() {
562
+ if (!registered) {
563
+ registered = true;
564
+ return;
565
+ }
566
+
567
+ if (instance.options.autoResetAll === false) {
568
+ return;
569
+ }
570
+
571
+ if (instance.options.autoResetAll === true || instance.options.autoResetGrouping) {
572
+ instance.resetGrouping();
573
+ }
574
+ },
575
+ getColumnAutoAggregationFn: function getColumnAutoAggregationFn(columnId) {
576
+ var firstRow = instance.getCoreRowModel().flatRows[0];
577
+ var value = firstRow == null ? void 0 : firstRow.values[columnId];
578
+
579
+ if (typeof value === 'number') {
580
+ return aggregationTypes.sum;
581
+ }
582
+
583
+ if (Object.prototype.toString.call(value) === '[object Date]') {
584
+ return aggregationTypes.extent;
585
+ }
586
+
587
+ return aggregationTypes.count;
588
+ },
589
+ getColumnAggregationFn: function getColumnAggregationFn(columnId) {
590
+ var _ref;
591
+
592
+ var column = instance.getColumn(columnId);
593
+ var userAggregationTypes = instance.options.aggregationTypes;
594
+
595
+ if (!column) {
596
+ throw new Error();
597
+ }
598
+
599
+ return isFunction(column.aggregationType) ? column.aggregationType : column.aggregationType === 'auto' ? instance.getColumnAutoFilterFn(columnId) : (_ref = userAggregationTypes == null ? void 0 : userAggregationTypes[column.aggregationType]) != null ? _ref : aggregationTypes[column.aggregationType];
600
+ },
601
+ setGrouping: function setGrouping(updater) {
602
+ return instance.options.onGroupingChange == null ? void 0 : instance.options.onGroupingChange(updater, functionalUpdate(updater, instance.getState().grouping));
603
+ },
604
+ toggleColumnGrouping: function toggleColumnGrouping(columnId) {
605
+ instance.setGrouping(function (old) {
606
+ // Find any existing grouping for this column
607
+ if (old != null && old.includes(columnId)) {
608
+ return old.filter(function (d) {
609
+ return d !== columnId;
610
+ });
611
+ }
612
+
613
+ return [].concat(old != null ? old : [], [columnId]);
614
+ });
615
+ },
616
+ getColumnCanGroup: function getColumnCanGroup(columnId) {
617
+ var _ref2, _ref3, _column$enableGroupin;
618
+
619
+ var column = instance.getColumn(columnId);
620
+
621
+ if (!column) {
622
+ throw new Error();
623
+ }
624
+
625
+ return (_ref2 = (_ref3 = (_column$enableGroupin = column.enableGrouping) != null ? _column$enableGroupin : instance.options.enableGrouping) != null ? _ref3 : column.defaultCanGroup) != null ? _ref2 : !!column.accessorFn;
626
+ },
627
+ getColumnIsGrouped: function getColumnIsGrouped(columnId) {
628
+ var _instance$getState$gr;
629
+
630
+ return (_instance$getState$gr = instance.getState().grouping) == null ? void 0 : _instance$getState$gr.includes(columnId);
631
+ },
632
+ getColumnGroupedIndex: function getColumnGroupedIndex(columnId) {
633
+ var _instance$getState$gr2;
634
+
635
+ return (_instance$getState$gr2 = instance.getState().grouping) == null ? void 0 : _instance$getState$gr2.indexOf(columnId);
636
+ },
637
+ resetGrouping: function resetGrouping() {
638
+ var _instance$initialStat, _instance$initialStat2;
639
+
640
+ instance.setGrouping((_instance$initialStat = (_instance$initialStat2 = instance.initialState) == null ? void 0 : _instance$initialStat2.grouping) != null ? _instance$initialStat : []);
641
+ },
642
+ getToggleGroupingProps: function getToggleGroupingProps(columnId, userProps) {
643
+ var column = instance.getColumn(columnId);
644
+ var canGroup = column.getCanGroup();
645
+ var initialProps = {
646
+ title: canGroup ? 'Toggle Grouping' : undefined,
647
+ onClick: canGroup ? function (e) {
648
+ e.persist();
649
+ column.toggleGrouping == null ? void 0 : column.toggleGrouping();
650
+ } : undefined
651
+ };
652
+ return propGetter(initialProps, userProps);
653
+ },
654
+ getRowIsGrouped: function getRowIsGrouped(rowId) {
655
+ var _instance$getRow;
656
+
657
+ return !!((_instance$getRow = instance.getRow(rowId)) != null && _instance$getRow.groupingColumnId);
658
+ },
659
+ getPreGroupedRowModel: function getPreGroupedRowModel() {
660
+ return instance.getSortedRowModel();
661
+ },
662
+ getGroupedRowModel: memo(function () {
663
+ return [instance.getState().grouping, instance.getSortedRowModel(), instance.options.groupRowsFn];
664
+ }, function (grouping, rowModel, groupRowsFn) {
665
+ if (!groupRowsFn || !grouping.length) {
666
+ return rowModel;
667
+ }
668
+
669
+ return groupRowsFn(instance, rowModel);
670
+ }, {
671
+ key: 'getGroupedRowModel',
672
+ debug: function debug() {
673
+ var _instance$options$deb;
674
+
675
+ return (_instance$options$deb = instance.options.debugAll) != null ? _instance$options$deb : instance.options.debugTable;
676
+ },
677
+ onChange: function onChange() {
678
+ return instance._notifyExpandedReset();
679
+ }
680
+ })
681
+ };
682
+ },
683
+ createRow: function createRow(row, instance) {
684
+ return {
685
+ getIsGrouped: function getIsGrouped() {
686
+ return instance.getRowIsGrouped(row.id);
687
+ }
688
+ };
689
+ },
690
+ createCell: function createCell(cell, column, row, _instance) {
691
+ return {
692
+ getIsGrouped: function getIsGrouped() {
693
+ return column.getIsGrouped() && column.id === row.groupingColumnId;
694
+ },
695
+ getIsPlaceholder: function getIsPlaceholder() {
696
+ return !cell.getIsGrouped() && column.getIsGrouped();
697
+ },
698
+ getIsAggregated: function getIsAggregated() {
699
+ var _row$subRows;
700
+
701
+ return !cell.getIsGrouped() && !cell.getIsPlaceholder() && ((_row$subRows = row.subRows) == null ? void 0 : _row$subRows.length) > 1;
702
+ }
703
+ };
704
+ },
705
+ orderColumns: function orderColumns(leafColumns, grouping, groupedColumnMode) {
706
+ if (!(grouping != null && grouping.length) || !groupedColumnMode) {
707
+ return leafColumns;
708
+ }
709
+
710
+ var nonGroupingColumns = leafColumns.filter(function (col) {
711
+ return !grouping.includes(col.id);
712
+ });
713
+
714
+ if (groupedColumnMode === 'remove') {
715
+ return nonGroupingColumns;
716
+ }
717
+
718
+ var groupingColumns = grouping.map(function (g) {
719
+ return leafColumns.find(function (col) {
720
+ return col.id === g;
721
+ });
722
+ }).filter(Boolean);
723
+ return [].concat(groupingColumns, nonGroupingColumns);
724
+ }
725
+ };
726
+
727
+ //
728
+ var Ordering = {
729
+ getInitialState: function getInitialState() {
730
+ return {
731
+ columnOrder: []
732
+ };
733
+ },
734
+ getDefaultOptions: function getDefaultOptions(instance) {
735
+ return {
736
+ onColumnOrderChange: makeStateUpdater('columnOrder', instance)
737
+ };
738
+ },
739
+ getInstance: function getInstance(instance) {
740
+ return {
741
+ setColumnOrder: function setColumnOrder(updater) {
742
+ return instance.options.onColumnOrderChange == null ? void 0 : instance.options.onColumnOrderChange(updater, functionalUpdate(updater, instance.getState().columnOrder));
743
+ },
744
+ resetColumnOrder: function resetColumnOrder() {
745
+ var _instance$initialStat;
746
+
747
+ instance.setColumnOrder((_instance$initialStat = instance.initialState.columnOrder) != null ? _instance$initialStat : []);
748
+ },
749
+ getOrderColumnsFn: memo(function () {
750
+ return [instance.getState().columnOrder, instance.getState().grouping, instance.options.groupedColumnMode];
751
+ }, function (columnOrder, grouping, groupedColumnMode) {
752
+ return function (columns) {
753
+ // Sort grouped columns to the start of the column list
754
+ // before the headers are built
755
+ var orderedColumns = []; // If there is no order, return the normal columns
756
+
757
+ if (!(columnOrder != null && columnOrder.length)) {
758
+ orderedColumns = columns;
759
+ } else {
760
+ var columnOrderCopy = [].concat(columnOrder); // If there is an order, make a copy of the columns
761
+
762
+ var columnsCopy = [].concat(columns); // And make a new ordered array of the columns
763
+ // Loop over the columns and place them in order into the new array
764
+
765
+ var _loop = function _loop() {
766
+ var targetColumnId = columnOrderCopy.shift();
767
+ var foundIndex = columnsCopy.findIndex(function (d) {
768
+ return d.id === targetColumnId;
769
+ });
770
+
771
+ if (foundIndex > -1) {
772
+ orderedColumns.push(columnsCopy.splice(foundIndex, 1)[0]);
773
+ }
774
+ };
775
+
776
+ while (columnsCopy.length && columnOrderCopy.length) {
777
+ _loop();
778
+ } // If there are any columns left, add them to the end
779
+
780
+
781
+ orderedColumns = [].concat(orderedColumns, columnsCopy);
782
+ }
783
+
784
+ return Grouping.orderColumns(orderedColumns, grouping, groupedColumnMode);
785
+ };
786
+ }, {
787
+ key: 'getOrderColumnsFn' // debug: () => instance.options.debugAll ?? instance.options.debugTable,
788
+
789
+ })
790
+ };
791
+ }
792
+ };
793
+
794
+ //
795
+ var Pinning = {
796
+ getInitialState: function getInitialState() {
797
+ return {
798
+ columnPinning: {
799
+ left: [],
800
+ right: []
801
+ }
802
+ };
803
+ },
804
+ getDefaultOptions: function getDefaultOptions(instance) {
805
+ return {
806
+ onColumnPinningChange: makeStateUpdater('columnPinning', instance)
807
+ };
808
+ },
809
+ createColumn: function createColumn(column, instance) {
810
+ return {
811
+ getCanPin: function getCanPin() {
812
+ return instance.getColumnCanPin(column.id);
813
+ },
814
+ getPinnedIndex: function getPinnedIndex() {
815
+ return instance.getColumnPinnedIndex(column.id);
816
+ },
817
+ getIsPinned: function getIsPinned() {
818
+ return instance.getColumnIsPinned(column.id);
819
+ },
820
+ pin: function pin(position) {
821
+ return instance.pinColumn(column.id, position);
822
+ }
823
+ };
824
+ },
825
+ getInstance: function getInstance(instance) {
826
+ return {
827
+ setColumnPinning: function setColumnPinning(updater) {
828
+ return instance.options.onColumnPinningChange == null ? void 0 : instance.options.onColumnPinningChange(updater, functionalUpdate(updater, instance.getState().columnPinning));
829
+ },
830
+ resetColumnPinning: function resetColumnPinning() {
831
+ var _instance$initialStat, _instance$initialStat2;
832
+
833
+ return instance.setColumnPinning((_instance$initialStat = (_instance$initialStat2 = instance.initialState) == null ? void 0 : _instance$initialStat2.columnPinning) != null ? _instance$initialStat : {});
834
+ },
835
+ pinColumn: function pinColumn(columnId, position) {
836
+ var column = instance.getColumn(columnId);
837
+ var columnIds = column == null ? void 0 : column.getLeafColumns().map(function (d) {
838
+ return d.id;
839
+ }).filter(Boolean);
840
+ instance.setColumnPinning(function (old) {
841
+ var _old$left3, _old$right3;
842
+
843
+ if (position === 'right') {
844
+ var _old$left, _old$right;
845
+
846
+ return {
847
+ left: ((_old$left = old == null ? void 0 : old.left) != null ? _old$left : []).filter(function (d) {
848
+ return !(columnIds != null && columnIds.includes(d));
849
+ }),
850
+ right: [].concat(((_old$right = old == null ? void 0 : old.right) != null ? _old$right : []).filter(function (d) {
851
+ return !(columnIds != null && columnIds.includes(d));
852
+ }), columnIds)
853
+ };
854
+ }
855
+
856
+ if (position === 'left') {
857
+ var _old$left2, _old$right2;
858
+
859
+ return {
860
+ left: [].concat(((_old$left2 = old == null ? void 0 : old.left) != null ? _old$left2 : []).filter(function (d) {
861
+ return !(columnIds != null && columnIds.includes(d));
862
+ }), columnIds),
863
+ right: ((_old$right2 = old == null ? void 0 : old.right) != null ? _old$right2 : []).filter(function (d) {
864
+ return !(columnIds != null && columnIds.includes(d));
865
+ })
866
+ };
867
+ }
868
+
869
+ return {
870
+ left: ((_old$left3 = old == null ? void 0 : old.left) != null ? _old$left3 : []).filter(function (d) {
871
+ return !(columnIds != null && columnIds.includes(d));
872
+ }),
873
+ right: ((_old$right3 = old == null ? void 0 : old.right) != null ? _old$right3 : []).filter(function (d) {
874
+ return !(columnIds != null && columnIds.includes(d));
875
+ })
876
+ };
877
+ });
878
+ },
879
+ getColumnCanPin: function getColumnCanPin(columnId) {
880
+ var column = instance.getColumn(columnId);
881
+
882
+ if (!column) {
883
+ throw new Error();
884
+ }
885
+
886
+ var leafColumns = column.getLeafColumns();
887
+ return leafColumns.some(function (d) {
888
+ var _ref, _ref2, _d$enablePinning;
889
+
890
+ return (_ref = (_ref2 = (_d$enablePinning = d.enablePinning) != null ? _d$enablePinning : instance.options.enablePinning) != null ? _ref2 : d.defaultCanPin) != null ? _ref : !!d.accessorFn;
891
+ });
892
+ },
893
+ getColumnIsPinned: function getColumnIsPinned(columnId) {
894
+ var column = instance.getColumn(columnId);
895
+
896
+ if (!column) {
897
+ throw new Error();
898
+ }
899
+
900
+ var leafColumnIds = column.getLeafColumns().map(function (d) {
901
+ return d.id;
902
+ });
903
+ var _instance$getState$co = instance.getState().columnPinning,
904
+ left = _instance$getState$co.left,
905
+ right = _instance$getState$co.right;
906
+ var isLeft = leafColumnIds.some(function (d) {
907
+ return left == null ? void 0 : left.includes(d);
908
+ });
909
+ var isRight = leafColumnIds.some(function (d) {
910
+ return right == null ? void 0 : right.includes(d);
911
+ });
912
+ return isLeft ? 'left' : isRight ? 'right' : false;
913
+ },
914
+ getColumnPinnedIndex: function getColumnPinnedIndex(columnId) {
915
+ var _instance$getState$co2, _instance$getState$co3, _instance$getState$co4;
916
+
917
+ var position = instance.getColumnIsPinned(columnId);
918
+ return position ? (_instance$getState$co2 = (_instance$getState$co3 = instance.getState().columnPinning) == null ? void 0 : (_instance$getState$co4 = _instance$getState$co3[position]) == null ? void 0 : _instance$getState$co4.indexOf(columnId)) != null ? _instance$getState$co2 : -1 : 0;
919
+ }
920
+ };
921
+ }
922
+ };
923
+
924
+ //
925
+ var defaultColumnSizing = {
926
+ width: 150,
927
+ minWidth: 20,
928
+ maxWidth: Number.MAX_SAFE_INTEGER
929
+ };
930
+ var ColumnSizing = {
931
+ getInitialState: function getInitialState() {
932
+ return {
933
+ columnSizing: {},
934
+ columnSizingInfo: {
935
+ startOffset: null,
936
+ startSize: null,
937
+ deltaOffset: null,
938
+ deltaPercentage: null,
939
+ isResizingColumn: false,
940
+ columnSizingStart: []
941
+ }
942
+ };
943
+ },
944
+ getDefaultOptions: function getDefaultOptions(instance) {
945
+ return {
946
+ columnResizeMode: 'onEnd',
947
+ onColumnSizingChange: makeStateUpdater('columnSizing', instance),
948
+ onColumnSizingInfoChange: makeStateUpdater('columnSizingInfo', instance)
949
+ };
950
+ },
951
+ getInstance: function getInstance(instance) {
952
+ return {
953
+ setColumnSizing: function setColumnSizing(updater) {
954
+ return instance.options.onColumnSizingChange == null ? void 0 : instance.options.onColumnSizingChange(updater, functionalUpdate(updater, instance.getState().columnSizing));
955
+ },
956
+ setColumnSizingInfo: function setColumnSizingInfo(updater) {
957
+ return instance.options.onColumnSizingInfoChange == null ? void 0 : instance.options.onColumnSizingInfoChange(updater, functionalUpdate(updater, instance.getState().columnSizingInfo));
958
+ },
959
+ resetColumnSizing: function resetColumnSizing() {
960
+ var _instance$initialStat;
961
+
962
+ instance.setColumnSizing((_instance$initialStat = instance.initialState.columnSizing) != null ? _instance$initialStat : {});
963
+ },
964
+ resetHeaderSizeInfo: function resetHeaderSizeInfo() {
965
+ var _instance$initialStat2;
966
+
967
+ instance.setColumnSizingInfo((_instance$initialStat2 = instance.initialState.columnSizingInfo) != null ? _instance$initialStat2 : {});
968
+ },
969
+ resetColumnSize: function resetColumnSize(columnId) {
970
+ instance.setColumnSizing(function (_ref) {
971
+ _ref[columnId];
972
+ var rest = _objectWithoutPropertiesLoose(_ref, [columnId].map(_toPropertyKey));
973
+
974
+ return rest;
975
+ });
976
+ },
977
+ resetHeaderSize: function resetHeaderSize(headerId) {
978
+ var header = instance.getHeader(headerId);
979
+ return instance.resetColumnSize(header.column.id);
980
+ },
981
+ getHeaderCanResize: function getHeaderCanResize(headerId) {
982
+ var header = instance.getHeader(headerId);
983
+
984
+ if (!header) {
985
+ throw new Error();
986
+ }
987
+
988
+ return instance.getColumnCanResize(header.column.id);
989
+ },
990
+ getColumnCanResize: function getColumnCanResize(columnId) {
991
+ var _ref2, _ref3, _column$enableResizin;
992
+
993
+ var column = instance.getColumn(columnId);
994
+
995
+ if (!column) {
996
+ throw new Error();
997
+ }
998
+
999
+ return (_ref2 = (_ref3 = (_column$enableResizin = column.enableResizing) != null ? _column$enableResizin : instance.options.enableColumnResizing) != null ? _ref3 : column.defaultCanResize) != null ? _ref2 : true;
1000
+ },
1001
+ getColumnIsResizing: function getColumnIsResizing(columnId) {
1002
+ var column = instance.getColumn(columnId);
1003
+
1004
+ if (!column) {
1005
+ throw new Error();
1006
+ }
1007
+
1008
+ return instance.getState().columnSizingInfo.isResizingColumn === columnId;
1009
+ },
1010
+ getHeaderIsResizing: function getHeaderIsResizing(headerId) {
1011
+ var header = instance.getHeader(headerId);
1012
+
1013
+ if (!header) {
1014
+ throw new Error();
1015
+ }
1016
+
1017
+ return instance.getColumnIsResizing(header.column.id);
1018
+ },
1019
+ getHeaderResizerProps: function getHeaderResizerProps(headerId, userProps) {
1020
+ var header = instance.getHeader(headerId);
1021
+ var column = instance.getColumn(header.column.id);
1022
+ var canResize = column.getCanResize();
1023
+
1024
+ var onResizeStart = function onResizeStart(e) {
1025
+ if (isTouchStartEvent(e)) {
1026
+ // lets not respond to multiple touches (e.g. 2 or 3 fingers)
1027
+ if (e.touches && e.touches.length > 1) {
1028
+ return;
1029
+ }
1030
+ }
1031
+
1032
+ var header = headerId ? instance.getHeader(headerId) : undefined;
1033
+ var startSize = header ? header.getWidth() : column.getWidth();
1034
+ var columnSizingStart = header ? header.getLeafHeaders().map(function (d) {
1035
+ return [d.column.id, d.getWidth()];
1036
+ }) : [[column.id, column.getWidth()]];
1037
+ var clientX = isTouchStartEvent(e) ? Math.round(e.touches[0].clientX) : e.clientX;
1038
+
1039
+ var updateOffset = function updateOffset(eventType, clientXPos) {
1040
+ if (typeof clientXPos !== 'number') {
1041
+ return;
1042
+ }
1043
+
1044
+ var newColumnSizing = {};
1045
+ instance.setColumnSizingInfo(function (old) {
1046
+ var _old$startOffset, _old$startSize;
1047
+
1048
+ var deltaOffset = clientXPos - ((_old$startOffset = old == null ? void 0 : old.startOffset) != null ? _old$startOffset : 0);
1049
+ var deltaPercentage = Math.max(deltaOffset / ((_old$startSize = old == null ? void 0 : old.startSize) != null ? _old$startSize : 0), -0.999999);
1050
+ old.columnSizingStart.forEach(function (_ref4) {
1051
+ var columnId = _ref4[0],
1052
+ headerWidth = _ref4[1];
1053
+ newColumnSizing[columnId] = Math.round(Math.max(headerWidth + headerWidth * deltaPercentage, 0) * 100) / 100;
1054
+ });
1055
+ return _extends({}, old, {
1056
+ deltaOffset: deltaOffset,
1057
+ deltaPercentage: deltaPercentage
1058
+ });
1059
+ });
1060
+
1061
+ if (instance.options.columnResizeMode === 'onChange' || eventType === 'end') {
1062
+ instance.setColumnSizing(function (old) {
1063
+ return _extends({}, old, newColumnSizing);
1064
+ });
1065
+ }
1066
+ };
1067
+
1068
+ var onMove = function onMove(clientXPos) {
1069
+ return updateOffset('move', clientXPos);
1070
+ };
1071
+
1072
+ var onEnd = function onEnd(clientXPos) {
1073
+ updateOffset('end', clientXPos);
1074
+ instance.setColumnSizingInfo(function (old) {
1075
+ return _extends({}, old, {
1076
+ isResizingColumn: false,
1077
+ startOffset: null,
1078
+ startSize: null,
1079
+ deltaOffset: null,
1080
+ deltaPercentage: null,
1081
+ columnSizingStart: []
1082
+ });
1083
+ });
1084
+ };
1085
+
1086
+ var mouseEvents = {
1087
+ moveHandler: function moveHandler(e) {
1088
+ return onMove(e.clientX);
1089
+ },
1090
+ upHandler: function upHandler(e) {
1091
+ document.removeEventListener('mousemove', mouseEvents.moveHandler);
1092
+ document.removeEventListener('mouseup', mouseEvents.upHandler);
1093
+ onEnd(e.clientX);
1094
+ }
1095
+ };
1096
+ var touchEvents = {
1097
+ moveHandler: function moveHandler(e) {
1098
+ if (e.cancelable) {
1099
+ e.preventDefault();
1100
+ e.stopPropagation();
1101
+ }
1102
+
1103
+ onMove(e.touches[0].clientX);
1104
+ return false;
1105
+ },
1106
+ upHandler: function upHandler(e) {
1107
+ document.removeEventListener('touchmove', touchEvents.moveHandler);
1108
+ document.removeEventListener('touchend', touchEvents.upHandler);
1109
+
1110
+ if (e.cancelable) {
1111
+ e.preventDefault();
1112
+ e.stopPropagation();
1113
+ }
1114
+
1115
+ onEnd(e.touches[0].clientX);
1116
+ }
1117
+ };
1118
+ var passiveIfSupported = passiveEventSupported() ? {
1119
+ passive: false
1120
+ } : false;
1121
+
1122
+ if (isTouchStartEvent(e)) {
1123
+ document.addEventListener('touchmove', touchEvents.moveHandler, passiveIfSupported);
1124
+ document.addEventListener('touchend', touchEvents.upHandler, passiveIfSupported);
1125
+ } else {
1126
+ document.addEventListener('mousemove', mouseEvents.moveHandler, passiveIfSupported);
1127
+ document.addEventListener('mouseup', mouseEvents.upHandler, passiveIfSupported);
1128
+ }
1129
+
1130
+ instance.setColumnSizingInfo(function (old) {
1131
+ return _extends({}, old, {
1132
+ startOffset: clientX,
1133
+ startSize: startSize,
1134
+ deltaOffset: 0,
1135
+ deltaPercentage: 0,
1136
+ columnSizingStart: columnSizingStart,
1137
+ isResizingColumn: column.id
1138
+ });
1139
+ });
1140
+ };
1141
+
1142
+ var initialProps = canResize ? {
1143
+ title: 'Toggle Grouping',
1144
+ draggable: false,
1145
+ role: 'separator',
1146
+ onMouseDown: function onMouseDown(e) {
1147
+ e.persist();
1148
+ onResizeStart(e);
1149
+ },
1150
+ onTouchStart: function onTouchStart(e) {
1151
+ e.persist();
1152
+ onResizeStart(e);
1153
+ }
1154
+ } : {};
1155
+ return propGetter(initialProps, userProps);
1156
+ }
1157
+ };
1158
+ },
1159
+ createColumn: function createColumn(column, instance) {
1160
+ return {
1161
+ getIsResizing: function getIsResizing() {
1162
+ return instance.getColumnIsResizing(column.id);
1163
+ },
1164
+ getCanResize: function getCanResize() {
1165
+ return instance.getColumnCanResize(column.id);
1166
+ },
1167
+ resetSize: function resetSize() {
1168
+ return instance.resetColumnSize(column.id);
1169
+ }
1170
+ };
1171
+ },
1172
+ createHeader: function createHeader(header, instance) {
1173
+ return {
1174
+ getIsResizing: function getIsResizing() {
1175
+ return instance.getColumnIsResizing(header.column.id);
1176
+ },
1177
+ getCanResize: function getCanResize() {
1178
+ return instance.getColumnCanResize(header.column.id);
1179
+ },
1180
+ resetSize: function resetSize() {
1181
+ return instance.resetColumnSize(header.column.id);
1182
+ },
1183
+ getResizerProps: function getResizerProps(userProps) {
1184
+ return instance.getHeaderResizerProps(header.id, userProps);
1185
+ }
1186
+ };
1187
+ }
1188
+ };
1189
+ var passiveSupported = null;
1190
+ function passiveEventSupported() {
1191
+ if (typeof passiveSupported === 'boolean') return passiveSupported;
1192
+ var supported = false;
1193
+
1194
+ try {
1195
+ var options = {
1196
+ get passive() {
1197
+ supported = true;
1198
+ return false;
1199
+ }
1200
+
1201
+ };
1202
+
1203
+ var noop = function noop() {};
1204
+
1205
+ window.addEventListener('test', noop, options);
1206
+ window.removeEventListener('test', noop);
1207
+ } catch (err) {
1208
+ supported = false;
1209
+ }
1210
+
1211
+ passiveSupported = supported;
1212
+ return passiveSupported;
1213
+ }
1214
+
1215
+ function isTouchStartEvent(e) {
1216
+ return e.type === 'touchstart';
1217
+ }
1218
+
1219
+ //
1220
+ var Headers = {
1221
+ createRow: function createRow(row, instance) {
1222
+ return {
1223
+ _getAllVisibleCells: memo(function () {
1224
+ return [row.getAllCells().filter(function (cell) {
1225
+ return cell.column.getIsVisible();
1226
+ }).map(function (d) {
1227
+ return d.id;
1228
+ }).join('_')];
1229
+ }, function (_) {
1230
+ return row.getAllCells().filter(function (cell) {
1231
+ return cell.column.getIsVisible();
1232
+ });
1233
+ }, {
1234
+ key: 'row._getAllVisibleCells',
1235
+ debug: function debug() {
1236
+ var _instance$options$deb;
1237
+
1238
+ return (_instance$options$deb = instance.options.debugAll) != null ? _instance$options$deb : instance.options.debugRows;
1239
+ }
1240
+ }),
1241
+ getVisibleCells: memo(function () {
1242
+ return [row.getLeftVisibleCells(), row.getCenterVisibleCells(), row.getRightVisibleCells()];
1243
+ }, function (left, center, right) {
1244
+ return [].concat(left, center, right);
1245
+ }, {
1246
+ key: 'row.getVisibleCells',
1247
+ debug: function debug() {
1248
+ var _instance$options$deb2;
1249
+
1250
+ return (_instance$options$deb2 = instance.options.debugAll) != null ? _instance$options$deb2 : instance.options.debugRows;
1251
+ }
1252
+ }),
1253
+ getCenterVisibleCells: memo(function () {
1254
+ return [row._getAllVisibleCells(), instance.getState().columnPinning.left, instance.getState().columnPinning.right];
1255
+ }, function (allCells, left, right) {
1256
+ var leftAndRight = [].concat(left != null ? left : [], right != null ? right : []);
1257
+ return allCells.filter(function (d) {
1258
+ return !leftAndRight.includes(d.columnId);
1259
+ });
1260
+ }, {
1261
+ key: 'row.getCenterVisibleCells',
1262
+ debug: function debug() {
1263
+ var _instance$options$deb3;
1264
+
1265
+ return (_instance$options$deb3 = instance.options.debugAll) != null ? _instance$options$deb3 : instance.options.debugRows;
1266
+ }
1267
+ }),
1268
+ getLeftVisibleCells: memo(function () {
1269
+ return [row._getAllVisibleCells(), instance.getState().columnPinning.left,,];
1270
+ }, function (allCells, left) {
1271
+ var cells = (left != null ? left : []).map(function (columnId) {
1272
+ return allCells.find(function (cell) {
1273
+ return cell.columnId === columnId;
1274
+ });
1275
+ }).filter(Boolean);
1276
+ return cells;
1277
+ }, {
1278
+ key: 'row.getLeftVisibleCells',
1279
+ debug: function debug() {
1280
+ var _instance$options$deb4;
1281
+
1282
+ return (_instance$options$deb4 = instance.options.debugAll) != null ? _instance$options$deb4 : instance.options.debugRows;
1283
+ }
1284
+ }),
1285
+ getRightVisibleCells: memo(function () {
1286
+ return [row._getAllVisibleCells(), instance.getState().columnPinning.right];
1287
+ }, function (allCells, right) {
1288
+ var cells = (right != null ? right : []).map(function (columnId) {
1289
+ return allCells.find(function (cell) {
1290
+ return cell.columnId === columnId;
1291
+ });
1292
+ }).filter(Boolean);
1293
+ return cells;
1294
+ }, {
1295
+ key: 'row.getRightVisibleCells',
1296
+ debug: function debug() {
1297
+ var _instance$options$deb5;
1298
+
1299
+ return (_instance$options$deb5 = instance.options.debugAll) != null ? _instance$options$deb5 : instance.options.debugRows;
1300
+ }
1301
+ })
1302
+ };
1303
+ },
1304
+ getInstance: function getInstance(instance) {
1305
+ return {
1306
+ createHeader: function createHeader(column, options) {
1307
+ var _options$id;
1308
+
1309
+ var id = (_options$id = options.id) != null ? _options$id : column.id;
1310
+ var header = {
1311
+ id: id,
1312
+ column: column,
1313
+ isPlaceholder: options.isPlaceholder,
1314
+ placeholderId: options.placeholderId,
1315
+ depth: options.depth,
1316
+ subHeaders: [],
1317
+ colSpan: 0,
1318
+ rowSpan: 0,
1319
+ getWidth: function getWidth() {
1320
+ var sum = 0;
1321
+
1322
+ var recurse = function recurse(header) {
1323
+ if (header.subHeaders.length) {
1324
+ header.subHeaders.forEach(recurse);
1325
+ } else {
1326
+ var _header$column$getWid;
1327
+
1328
+ sum += (_header$column$getWid = header.column.getWidth()) != null ? _header$column$getWid : 0;
1329
+ }
1330
+ };
1331
+
1332
+ recurse(header);
1333
+ return sum;
1334
+ },
1335
+ getLeafHeaders: function getLeafHeaders() {
1336
+ var leafHeaders = [];
1337
+
1338
+ var recurseHeader = function recurseHeader(h) {
1339
+ if (h.subHeaders && h.subHeaders.length) {
1340
+ h.subHeaders.map(recurseHeader);
1341
+ }
1342
+
1343
+ leafHeaders.push(h);
1344
+ };
1345
+
1346
+ recurseHeader(header);
1347
+ return leafHeaders;
1348
+ },
1349
+ getHeaderProps: function getHeaderProps(userProps) {
1350
+ return instance.getHeaderProps(header.id, userProps);
1351
+ },
1352
+ getFooterProps: function getFooterProps(userProps) {
1353
+ return instance.getFooterProps(header.id, userProps);
1354
+ },
1355
+ renderHeader: function renderHeader() {
1356
+ return flexRender(column.header, {
1357
+ instance: instance,
1358
+ header: header,
1359
+ column: column
1360
+ });
1361
+ },
1362
+ renderFooter: function renderFooter() {
1363
+ return flexRender(column.footer, {
1364
+ instance: instance,
1365
+ header: header,
1366
+ column: column
1367
+ });
1368
+ }
1369
+ }; // Yes, we have to convert instance to unknown, because we know more than the compiler here.
1370
+
1371
+ return Object.assign(header, ColumnSizing.createHeader(header, instance));
1372
+ },
1373
+ // Header Groups
1374
+ getHeaderGroups: memo(function () {
1375
+ return [instance.getAllColumns(), instance.getVisibleLeafColumns(), instance.getState().columnPinning.left, instance.getState().columnPinning.right];
1376
+ }, function (allColumns, leafColumns, left, right) {
1377
+ var leftColumns = leafColumns.filter(function (column) {
1378
+ return left == null ? void 0 : left.includes(column.id);
1379
+ });
1380
+ var rightColumns = leafColumns.filter(function (column) {
1381
+ return right == null ? void 0 : right.includes(column.id);
1382
+ });
1383
+ var centerColumns = leafColumns.filter(function (column) {
1384
+ return !(left != null && left.includes(column.id)) && !(right != null && right.includes(column.id));
1385
+ });
1386
+ var headerGroups = buildHeaderGroups(allColumns, [].concat(leftColumns, centerColumns, rightColumns), instance);
1387
+ return headerGroups;
1388
+ }, {
1389
+ key: 'getHeaderGroups',
1390
+ debug: function debug() {
1391
+ var _instance$options$deb6;
1392
+
1393
+ return (_instance$options$deb6 = instance.options.debugAll) != null ? _instance$options$deb6 : instance.options.debugHeaders;
1394
+ }
1395
+ }),
1396
+ getCenterHeaderGroups: memo(function () {
1397
+ return [instance.getAllColumns(), instance.getVisibleLeafColumns(), instance.getState().columnPinning.left, instance.getState().columnPinning.right];
1398
+ }, function (allColumns, leafColumns, left, right) {
1399
+ leafColumns = leafColumns.filter(function (column) {
1400
+ return !(left != null && left.includes(column.id)) && !(right != null && right.includes(column.id));
1401
+ });
1402
+ return buildHeaderGroups(allColumns, leafColumns, instance, 'center');
1403
+ }, {
1404
+ key: 'getCenterHeaderGroups',
1405
+ debug: function debug() {
1406
+ var _instance$options$deb7;
1407
+
1408
+ return (_instance$options$deb7 = instance.options.debugAll) != null ? _instance$options$deb7 : instance.options.debugHeaders;
1409
+ }
1410
+ }),
1411
+ getLeftHeaderGroups: memo(function () {
1412
+ return [instance.getAllColumns(), instance.getVisibleLeafColumns(), instance.getState().columnPinning.left];
1413
+ }, function (allColumns, leafColumns, left) {
1414
+ leafColumns = leafColumns.filter(function (column) {
1415
+ return left == null ? void 0 : left.includes(column.id);
1416
+ });
1417
+ return buildHeaderGroups(allColumns, leafColumns, instance, 'left');
1418
+ }, {
1419
+ key: 'getLeftHeaderGroups',
1420
+ debug: function debug() {
1421
+ var _instance$options$deb8;
1422
+
1423
+ return (_instance$options$deb8 = instance.options.debugAll) != null ? _instance$options$deb8 : instance.options.debugHeaders;
1424
+ }
1425
+ }),
1426
+ getRightHeaderGroups: memo(function () {
1427
+ return [instance.getAllColumns(), instance.getVisibleLeafColumns(), instance.getState().columnPinning.right];
1428
+ }, function (allColumns, leafColumns, right) {
1429
+ leafColumns = leafColumns.filter(function (column) {
1430
+ return right == null ? void 0 : right.includes(column.id);
1431
+ });
1432
+ return buildHeaderGroups(allColumns, leafColumns, instance, 'right');
1433
+ }, {
1434
+ key: 'getRightHeaderGroups',
1435
+ debug: function debug() {
1436
+ var _instance$options$deb9;
1437
+
1438
+ return (_instance$options$deb9 = instance.options.debugAll) != null ? _instance$options$deb9 : instance.options.debugHeaders;
1439
+ }
1440
+ }),
1441
+ // Footer Groups
1442
+ getFooterGroups: memo(function () {
1443
+ return [instance.getHeaderGroups()];
1444
+ }, function (headerGroups) {
1445
+ return [].concat(headerGroups).reverse();
1446
+ }, {
1447
+ key: 'getFooterGroups',
1448
+ debug: function debug() {
1449
+ var _instance$options$deb10;
1450
+
1451
+ return (_instance$options$deb10 = instance.options.debugAll) != null ? _instance$options$deb10 : instance.options.debugHeaders;
1452
+ }
1453
+ }),
1454
+ getLeftFooterGroups: memo(function () {
1455
+ return [instance.getLeftHeaderGroups()];
1456
+ }, function (headerGroups) {
1457
+ return [].concat(headerGroups).reverse();
1458
+ }, {
1459
+ key: 'getLeftFooterGroups',
1460
+ debug: function debug() {
1461
+ var _instance$options$deb11;
1462
+
1463
+ return (_instance$options$deb11 = instance.options.debugAll) != null ? _instance$options$deb11 : instance.options.debugHeaders;
1464
+ }
1465
+ }),
1466
+ getCenterFooterGroups: memo(function () {
1467
+ return [instance.getCenterHeaderGroups()];
1468
+ }, function (headerGroups) {
1469
+ return [].concat(headerGroups).reverse();
1470
+ }, {
1471
+ key: 'getCenterFooterGroups',
1472
+ debug: function debug() {
1473
+ var _instance$options$deb12;
1474
+
1475
+ return (_instance$options$deb12 = instance.options.debugAll) != null ? _instance$options$deb12 : instance.options.debugHeaders;
1476
+ }
1477
+ }),
1478
+ getRightFooterGroups: memo(function () {
1479
+ return [instance.getRightHeaderGroups()];
1480
+ }, function (headerGroups) {
1481
+ return [].concat(headerGroups).reverse();
1482
+ }, {
1483
+ key: 'getRightFooterGroups',
1484
+ debug: function debug() {
1485
+ var _instance$options$deb13;
1486
+
1487
+ return (_instance$options$deb13 = instance.options.debugAll) != null ? _instance$options$deb13 : instance.options.debugHeaders;
1488
+ }
1489
+ }),
1490
+ // Flat Headers
1491
+ getFlatHeaders: memo(function () {
1492
+ return [instance.getHeaderGroups()];
1493
+ }, function (headerGroups) {
1494
+ return headerGroups.map(function (headerGroup) {
1495
+ return headerGroup.headers;
1496
+ }).flat();
1497
+ }, {
1498
+ key: 'getFlatHeaders',
1499
+ debug: function debug() {
1500
+ var _instance$options$deb14;
1501
+
1502
+ return (_instance$options$deb14 = instance.options.debugAll) != null ? _instance$options$deb14 : instance.options.debugHeaders;
1503
+ }
1504
+ }),
1505
+ getLeftFlatHeaders: memo(function () {
1506
+ return [instance.getLeftHeaderGroups()];
1507
+ }, function (left) {
1508
+ return left.map(function (headerGroup) {
1509
+ return headerGroup.headers;
1510
+ }).flat();
1511
+ }, {
1512
+ key: 'getLeftFlatHeaders',
1513
+ debug: function debug() {
1514
+ var _instance$options$deb15;
1515
+
1516
+ return (_instance$options$deb15 = instance.options.debugAll) != null ? _instance$options$deb15 : instance.options.debugHeaders;
1517
+ }
1518
+ }),
1519
+ getCenterFlatHeaders: memo(function () {
1520
+ return [instance.getCenterHeaderGroups()];
1521
+ }, function (left) {
1522
+ return left.map(function (headerGroup) {
1523
+ return headerGroup.headers;
1524
+ }).flat();
1525
+ }, {
1526
+ key: 'getCenterFlatHeaders',
1527
+ debug: function debug() {
1528
+ var _instance$options$deb16;
1529
+
1530
+ return (_instance$options$deb16 = instance.options.debugAll) != null ? _instance$options$deb16 : instance.options.debugHeaders;
1531
+ }
1532
+ }),
1533
+ getRightFlatHeaders: memo(function () {
1534
+ return [instance.getRightHeaderGroups()];
1535
+ }, function (left) {
1536
+ return left.map(function (headerGroup) {
1537
+ return headerGroup.headers;
1538
+ }).flat();
1539
+ }, {
1540
+ key: 'getRightFlatHeaders',
1541
+ debug: function debug() {
1542
+ var _instance$options$deb17;
1543
+
1544
+ return (_instance$options$deb17 = instance.options.debugAll) != null ? _instance$options$deb17 : instance.options.debugHeaders;
1545
+ }
1546
+ }),
1547
+ // Leaf Headers
1548
+ getCenterLeafHeaders: memo(function () {
1549
+ return [instance.getCenterFlatHeaders()];
1550
+ }, function (flatHeaders) {
1551
+ return flatHeaders.filter(function (header) {
1552
+ var _header$subHeaders;
1553
+
1554
+ return !((_header$subHeaders = header.subHeaders) != null && _header$subHeaders.length);
1555
+ });
1556
+ }, {
1557
+ key: 'getCenterLeafHeaders',
1558
+ debug: function debug() {
1559
+ var _instance$options$deb18;
1560
+
1561
+ return (_instance$options$deb18 = instance.options.debugAll) != null ? _instance$options$deb18 : instance.options.debugHeaders;
1562
+ }
1563
+ }),
1564
+ getLeftLeafHeaders: memo(function () {
1565
+ return [instance.getLeftFlatHeaders()];
1566
+ }, function (flatHeaders) {
1567
+ return flatHeaders.filter(function (header) {
1568
+ var _header$subHeaders2;
1569
+
1570
+ return !((_header$subHeaders2 = header.subHeaders) != null && _header$subHeaders2.length);
1571
+ });
1572
+ }, {
1573
+ key: 'getLeftLeafHeaders',
1574
+ debug: function debug() {
1575
+ var _instance$options$deb19;
1576
+
1577
+ return (_instance$options$deb19 = instance.options.debugAll) != null ? _instance$options$deb19 : instance.options.debugHeaders;
1578
+ }
1579
+ }),
1580
+ getRightLeafHeaders: memo(function () {
1581
+ return [instance.getRightFlatHeaders()];
1582
+ }, function (flatHeaders) {
1583
+ return flatHeaders.filter(function (header) {
1584
+ var _header$subHeaders3;
1585
+
1586
+ return !((_header$subHeaders3 = header.subHeaders) != null && _header$subHeaders3.length);
1587
+ });
1588
+ }, {
1589
+ key: 'getRightLeafHeaders',
1590
+ debug: function debug() {
1591
+ var _instance$options$deb20;
1592
+
1593
+ return (_instance$options$deb20 = instance.options.debugAll) != null ? _instance$options$deb20 : instance.options.debugHeaders;
1594
+ }
1595
+ }),
1596
+ getLeafHeaders: memo(function () {
1597
+ return [instance.getLeftHeaderGroups(), instance.getCenterHeaderGroups(), instance.getRightHeaderGroups()];
1598
+ }, function (left, center, right) {
1599
+ var _left$0$headers, _left$, _center$0$headers, _center$, _right$0$headers, _right$;
1600
+
1601
+ return [].concat((_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(function (header) {
1602
+ return header.getLeafHeaders();
1603
+ }).flat();
1604
+ }, {
1605
+ key: 'getLeafHeaders',
1606
+ debug: function debug() {
1607
+ var _instance$options$deb21;
1608
+
1609
+ return (_instance$options$deb21 = instance.options.debugAll) != null ? _instance$options$deb21 : instance.options.debugHeaders;
1610
+ }
1611
+ }),
1612
+ getHeader: function getHeader(id) {
1613
+ var header = [].concat(instance.getFlatHeaders(), instance.getCenterFlatHeaders(), instance.getLeftFlatHeaders(), instance.getRightFlatHeaders()).find(function (d) {
1614
+ return d.id === id;
1615
+ });
1616
+
1617
+ if (!header) {
1618
+ {
1619
+ console.warn("Could not find header with id: " + id);
1620
+ }
1621
+
1622
+ throw new Error();
1623
+ }
1624
+
1625
+ return header;
1626
+ },
1627
+ getHeaderGroupProps: function getHeaderGroupProps(id, userProps) {
1628
+ var headerGroup = instance.getHeaderGroups().find(function (d) {
1629
+ return d.id === id;
1630
+ });
1631
+
1632
+ if (!headerGroup) {
1633
+ return;
1634
+ }
1635
+
1636
+ return propGetter({
1637
+ key: headerGroup.id,
1638
+ role: 'row'
1639
+ }, userProps);
1640
+ },
1641
+ getFooterGroupProps: function getFooterGroupProps(id, userProps) {
1642
+ var headerGroup = instance.getFooterGroups().find(function (d) {
1643
+ return d.id === id;
1644
+ });
1645
+
1646
+ if (!headerGroup) {
1647
+ return;
1648
+ }
1649
+
1650
+ var initialProps = {
1651
+ key: headerGroup.id,
1652
+ role: 'row'
1653
+ };
1654
+ return propGetter(initialProps, userProps);
1655
+ },
1656
+ getHeaderProps: function getHeaderProps(id, userProps) {
1657
+ var header = instance.getHeader(id);
1658
+
1659
+ if (!header) {
1660
+ throw new Error();
1661
+ }
1662
+
1663
+ var initialProps = {
1664
+ key: header.id,
1665
+ role: 'columnheader',
1666
+ colSpan: header.colSpan,
1667
+ rowSpan: header.rowSpan
1668
+ };
1669
+ return propGetter(initialProps, userProps);
1670
+ },
1671
+ getFooterProps: function getFooterProps(id, userProps) {
1672
+ var header = instance.getHeader(id);
1673
+ var initialProps = {
1674
+ key: header.id,
1675
+ role: 'columnfooter',
1676
+ colSpan: header.colSpan,
1677
+ rowSpan: header.rowSpan
1678
+ };
1679
+ return propGetter(initialProps, userProps);
1680
+ },
1681
+ getTotalWidth: function getTotalWidth() {
1682
+ var width = 0;
1683
+ instance.getVisibleLeafColumns().forEach(function (column) {
1684
+ var _column$getWidth;
1685
+
1686
+ width += (_column$getWidth = column.getWidth()) != null ? _column$getWidth : 0;
1687
+ });
1688
+ return width;
1689
+ }
1690
+ };
1691
+ }
1692
+ };
1693
+ function buildHeaderGroups(allColumns, columnsToGroup, instance, headerFamily) {
1694
+ var _headerGroups$0$heade, _headerGroups$;
1695
+
1696
+ // Find the max depth of the columns:
1697
+ // build the leaf column row
1698
+ // build each buffer row going up
1699
+ // placeholder for non-existent level
1700
+ // real column for existing level
1701
+ var maxDepth = 0;
1702
+
1703
+ var findMaxDepth = function findMaxDepth(columns, depth) {
1704
+ if (depth === void 0) {
1705
+ depth = 1;
1706
+ }
1707
+
1708
+ maxDepth = Math.max(maxDepth, depth);
1709
+ columns.filter(function (column) {
1710
+ return column.getIsVisible();
1711
+ }).forEach(function (column) {
1712
+ var _column$columns;
1713
+
1714
+ if ((_column$columns = column.columns) != null && _column$columns.length) {
1715
+ findMaxDepth(column.columns, depth + 1);
1716
+ }
1717
+ }, 0);
1718
+ };
1719
+
1720
+ findMaxDepth(allColumns);
1721
+ var headerGroups = [];
1722
+
1723
+ var createHeaderGroup = function createHeaderGroup(headersToGroup, depth) {
1724
+ // The header group we are creating
1725
+ var headerGroup = {
1726
+ depth: depth,
1727
+ id: [headerFamily, "" + depth].filter(Boolean).join('_'),
1728
+ headers: [],
1729
+ getHeaderGroupProps: function getHeaderGroupProps(getterValue) {
1730
+ return instance.getHeaderGroupProps("" + depth, getterValue);
1731
+ },
1732
+ getFooterGroupProps: function getFooterGroupProps(getterValue) {
1733
+ return instance.getFooterGroupProps("" + depth, getterValue);
1734
+ }
1735
+ }; // The parent columns we're going to scan next
1736
+
1737
+ var parentHeaders = []; // Scan each column for parents
1738
+
1739
+ headersToGroup.forEach(function (headerToGroup) {
1740
+ // What is the latest (last) parent column?
1741
+ var latestParentHeader = [].concat(parentHeaders).reverse()[0];
1742
+ var isLeafHeader = headerToGroup.column.depth === headerGroup.depth;
1743
+ var column;
1744
+ var isPlaceholder = false;
1745
+
1746
+ if (isLeafHeader && headerToGroup.column.parent) {
1747
+ // The parent header is new
1748
+ column = headerToGroup.column.parent;
1749
+ } else {
1750
+ // The parent header is repeated
1751
+ column = headerToGroup.column;
1752
+ isPlaceholder = true;
1753
+ }
1754
+
1755
+ var header = instance.createHeader(column, {
1756
+ id: [headerFamily, depth, column.id, headerToGroup == null ? void 0 : headerToGroup.id].filter(Boolean).join('_'),
1757
+ isPlaceholder: isPlaceholder,
1758
+ placeholderId: isPlaceholder ? "" + parentHeaders.filter(function (d) {
1759
+ return d.column === column;
1760
+ }).length : undefined,
1761
+ depth: depth
1762
+ });
1763
+
1764
+ if (!latestParentHeader || latestParentHeader.column !== header.column) {
1765
+ header.subHeaders.push(headerToGroup);
1766
+ parentHeaders.push(header);
1767
+ } else {
1768
+ latestParentHeader.subHeaders.push(headerToGroup);
1769
+ } // if (!headerToGroup.isPlaceholder) {
1770
+ // headerToGroup.column.header = headerToGroup;
1771
+ // }
1772
+
1773
+
1774
+ headerGroup.headers.push(headerToGroup);
1775
+ });
1776
+ headerGroups.push(headerGroup);
1777
+
1778
+ if (depth > 0) {
1779
+ createHeaderGroup(parentHeaders, depth - 1);
1780
+ }
1781
+ };
1782
+
1783
+ var bottomHeaders = columnsToGroup.map(function (column) {
1784
+ return instance.createHeader(column, {
1785
+ depth: maxDepth
1786
+ });
1787
+ });
1788
+ createHeaderGroup(bottomHeaders, maxDepth - 1);
1789
+ headerGroups.reverse(); // headerGroups = headerGroups.filter(headerGroup => {
1790
+ // return !headerGroup.headers.every(header => header.isPlaceholder)
1791
+ // })
1792
+
1793
+ var recurseHeadersForSpans = function recurseHeadersForSpans(headers) {
1794
+ var filteredHeaders = headers.filter(function (header) {
1795
+ return header.column.getIsVisible();
1796
+ });
1797
+ return filteredHeaders.map(function (header) {
1798
+ var colSpan = 0;
1799
+ var rowSpan = 0;
1800
+ var childRowSpans = [0];
1801
+
1802
+ if (header.subHeaders && header.subHeaders.length) {
1803
+ childRowSpans = [];
1804
+ recurseHeadersForSpans(header.subHeaders).forEach(function (_ref) {
1805
+ var childColSpan = _ref.colSpan,
1806
+ childRowSpan = _ref.rowSpan;
1807
+ colSpan += childColSpan;
1808
+ childRowSpans.push(childRowSpan);
1809
+ });
1810
+ } else {
1811
+ colSpan = 1;
1812
+ }
1813
+
1814
+ var minChildRowSpan = Math.min.apply(Math, childRowSpans);
1815
+ rowSpan = rowSpan + minChildRowSpan;
1816
+ header.colSpan = colSpan > 0 ? colSpan : undefined;
1817
+ header.rowSpan = rowSpan > 0 ? rowSpan : undefined;
1818
+ return {
1819
+ colSpan: colSpan,
1820
+ rowSpan: rowSpan
1821
+ };
1822
+ });
1823
+ };
1824
+
1825
+ recurseHeadersForSpans((_headerGroups$0$heade = (_headerGroups$ = headerGroups[0]) == null ? void 0 : _headerGroups$.headers) != null ? _headerGroups$0$heade : []);
1826
+ return headerGroups;
1827
+ }
1828
+
1829
+ var filterTypes = {
1830
+ includesString: includesString,
1831
+ includesStringSensitive: includesStringSensitive,
1832
+ equalsString: equalsString,
1833
+ equalsStringSensitive: equalsStringSensitive,
1834
+ arrIncludes: arrIncludes,
1835
+ arrIncludesAll: arrIncludesAll,
1836
+ equals: equals,
1837
+ weakEquals: weakEquals,
1838
+ betweenNumberRange: betweenNumberRange
1839
+ };
1840
+
1841
+ function includesString(rows, columnIds, filterValue) {
1842
+ var search = String(filterValue).toLowerCase();
1843
+ rows = rows.filter(function (row) {
1844
+ return columnIds.some(function (id) {
1845
+ return String(row.values[id]).toLowerCase().includes(search);
1846
+ });
1847
+ });
1848
+ return rows;
1849
+ }
1850
+
1851
+ includesString.autoRemove = function (val) {
1852
+ return testFalsey(val);
1853
+ };
1854
+
1855
+ function includesStringSensitive(rows, columnIds, filterValue) {
1856
+ var search = String(filterValue);
1857
+ rows = rows.filter(function (row) {
1858
+ return columnIds.some(function (id) {
1859
+ return String(row.values[id]).includes(search);
1860
+ });
1861
+ });
1862
+ return rows;
1863
+ }
1864
+
1865
+ includesStringSensitive.autoRemove = function (val) {
1866
+ return testFalsey(val);
1867
+ };
1868
+
1869
+ function equalsString(rows, columnIds, filterValue) {
1870
+ var search = String(filterValue).toLowerCase();
1871
+ return rows.filter(function (row) {
1872
+ return columnIds.some(function (id) {
1873
+ var rowValue = row.values[id];
1874
+ return rowValue !== undefined ? String(rowValue).toLowerCase() === search : true;
1875
+ });
1876
+ });
1877
+ }
1878
+
1879
+ equalsString.autoRemove = function (val) {
1880
+ return testFalsey(val);
1881
+ };
1882
+
1883
+ function equalsStringSensitive(rows, columnIds, filterValue) {
1884
+ var search = String(filterValue);
1885
+ return rows.filter(function (row) {
1886
+ return columnIds.some(function (id) {
1887
+ var rowValue = row.values[id];
1888
+ return rowValue !== undefined ? String(rowValue) === search : true;
1889
+ });
1890
+ });
1891
+ }
1892
+
1893
+ equalsStringSensitive.autoRemove = function (val) {
1894
+ return testFalsey(val);
1895
+ };
1896
+
1897
+ function arrIncludes(rows, columnIds, filterValue) {
1898
+ return rows.filter(function (row) {
1899
+ return columnIds.some(function (id) {
1900
+ var rowValue = row.values[id];
1901
+ return rowValue.includes(filterValue);
1902
+ });
1903
+ });
1904
+ }
1905
+
1906
+ arrIncludes.autoRemove = function (val) {
1907
+ return testFalsey(val) || !(val != null && val.length);
1908
+ };
1909
+
1910
+ function arrIncludesAll(rows, columnIds, filterValue) {
1911
+ return rows.filter(function (row) {
1912
+ return columnIds.some(function (id) {
1913
+ var rowValue = row.values[id];
1914
+ return rowValue && rowValue.length && filterValue.every(function (val) {
1915
+ return rowValue.includes(val);
1916
+ });
1917
+ });
1918
+ });
1919
+ }
1920
+
1921
+ arrIncludesAll.autoRemove = function (val) {
1922
+ return testFalsey(val) || !(val != null && val.length);
1923
+ };
1924
+
1925
+ function equals(rows, columnIds, filterValue) {
1926
+ return rows.filter(function (row) {
1927
+ return columnIds.some(function (id) {
1928
+ var rowValue = row.values[id];
1929
+ return rowValue === filterValue;
1930
+ });
1931
+ });
1932
+ }
1933
+
1934
+ equals.autoRemove = function (val) {
1935
+ return testFalsey(val);
1936
+ };
1937
+
1938
+ function weakEquals(rows, columnIds, filterValue) {
1939
+ return rows.filter(function (row) {
1940
+ return columnIds.some(function (id) {
1941
+ var rowValue = row.values[id]; // eslint-disable-next-line eqeqeq
1942
+
1943
+ return rowValue == filterValue;
1944
+ });
1945
+ });
1946
+ }
1947
+
1948
+ weakEquals.autoRemove = function (val) {
1949
+ return testFalsey(val);
1950
+ };
1951
+
1952
+ function betweenNumberRange(rows, columnIds, filterValue) {
1953
+ var _ref = filterValue || [],
1954
+ unsafeMin = _ref[0],
1955
+ unsafeMax = _ref[1];
1956
+
1957
+ var parsedMin = typeof unsafeMin !== 'number' ? parseFloat(unsafeMin) : unsafeMin;
1958
+ var parsedMax = typeof unsafeMax !== 'number' ? parseFloat(unsafeMax) : unsafeMax;
1959
+ var min = unsafeMin === null || Number.isNaN(parsedMin) ? -Infinity : parsedMin;
1960
+ var max = unsafeMax === null || Number.isNaN(parsedMax) ? Infinity : parsedMax;
1961
+
1962
+ if (min > max) {
1963
+ var temp = min;
1964
+ min = max;
1965
+ max = temp;
1966
+ }
1967
+
1968
+ return rows.filter(function (row) {
1969
+ return columnIds.some(function (id) {
1970
+ var rowValue = row.values[id];
1971
+ return rowValue >= min && rowValue <= max;
1972
+ });
1973
+ });
1974
+ }
1975
+
1976
+ betweenNumberRange.autoRemove = function (val) {
1977
+ return testFalsey(val) || testFalsey(val[0]) && testFalsey(val[1]);
1978
+ }; // Utils
1979
+
1980
+
1981
+ function testFalsey(val) {
1982
+ return val === undefined || val === null || val === '';
1983
+ }
1984
+
1985
+ //
1986
+ function getDefaultColumn() {
1987
+ return {
1988
+ filterType: 'auto'
1989
+ };
1990
+ }
1991
+ var Filters = {
1992
+ getInitialState: function getInitialState() {
1993
+ return {
1994
+ columnFilters: [],
1995
+ globalFilter: undefined
1996
+ };
1997
+ },
1998
+ getDefaultOptions: function getDefaultOptions(instance) {
1999
+ return {
2000
+ onColumnFiltersChange: makeStateUpdater('columnFilters', instance),
2001
+ onGlobalFilterChange: makeStateUpdater('globalFilter', instance),
2002
+ autoResetColumnFilters: true,
2003
+ filterFromChildrenUp: true,
2004
+ autoResetGlobalFilter: true,
2005
+ globalFilterType: 'auto',
2006
+ getColumnCanGlobalFilterFn: function getColumnCanGlobalFilterFn(column) {
2007
+ var _instance$getCoreRowM, _instance$getCoreRowM2;
2008
+
2009
+ var value = (_instance$getCoreRowM = instance.getCoreRowModel().flatRows[0]) == null ? void 0 : (_instance$getCoreRowM2 = _instance$getCoreRowM.getAllCellsByColumnId()[column.id]) == null ? void 0 : _instance$getCoreRowM2.value;
2010
+ return typeof value === 'string';
2011
+ }
2012
+ };
2013
+ },
2014
+ createColumn: function createColumn(column, instance) {
2015
+ var getFacetInfo = memo(function () {
2016
+ return [column.getPreFilteredRows()];
2017
+ }, function (rows) {
2018
+ var _rows$0$values$column, _rows$, _rows$0$values$column2, _rows$2;
2019
+
2020
+ if (rows === void 0) {
2021
+ rows = [];
2022
+ }
2023
+
2024
+ var preFilteredUniqueValues = new Map();
2025
+ var preFilteredMinMaxValues = [(_rows$0$values$column = (_rows$ = rows[0]) == null ? void 0 : _rows$.values[column.id]) != null ? _rows$0$values$column : null, (_rows$0$values$column2 = (_rows$2 = rows[0]) == null ? void 0 : _rows$2.values[column.id]) != null ? _rows$0$values$column2 : null];
2026
+
2027
+ for (var i = 0; i < rows.length; i++) {
2028
+ var _rows$i;
2029
+
2030
+ var _value = (_rows$i = rows[i]) == null ? void 0 : _rows$i.values[column.id];
2031
+
2032
+ if (preFilteredUniqueValues.has(_value)) {
2033
+ var _preFilteredUniqueVal;
2034
+
2035
+ preFilteredUniqueValues.set(_value, ((_preFilteredUniqueVal = preFilteredUniqueValues.get(_value)) != null ? _preFilteredUniqueVal : 0) + 1);
2036
+ } else {
2037
+ preFilteredUniqueValues.set(_value, 1);
2038
+ }
2039
+
2040
+ if (_value < preFilteredMinMaxValues[0]) {
2041
+ preFilteredMinMaxValues[0] = _value;
2042
+ } else if (_value > preFilteredMinMaxValues[1]) {
2043
+ preFilteredMinMaxValues[1] = _value;
2044
+ }
2045
+ }
2046
+
2047
+ return {
2048
+ preFilteredUniqueValues: preFilteredUniqueValues,
2049
+ preFilteredMinMaxValues: preFilteredMinMaxValues
2050
+ };
2051
+ }, {
2052
+ key: 'column.getFacetInfo',
2053
+ debug: function debug() {
2054
+ var _instance$options$deb;
2055
+
2056
+ return (_instance$options$deb = instance.options.debugAll) != null ? _instance$options$deb : instance.options.debugColumns;
2057
+ }
2058
+ });
2059
+ return {
2060
+ filterType: column.filterType,
2061
+ getCanColumnFilter: function getCanColumnFilter() {
2062
+ return instance.getColumnCanColumnFilter(column.id);
2063
+ },
2064
+ getCanGlobalFilter: function getCanGlobalFilter() {
2065
+ return instance.getColumnCanGlobalFilter(column.id);
2066
+ },
2067
+ getColumnFilterIndex: function getColumnFilterIndex() {
2068
+ return instance.getColumnFilterIndex(column.id);
2069
+ },
2070
+ getIsColumnFiltered: function getIsColumnFiltered() {
2071
+ return instance.getColumnIsFiltered(column.id);
2072
+ },
2073
+ getColumnFilterValue: function getColumnFilterValue() {
2074
+ return instance.getColumnFilterValue(column.id);
2075
+ },
2076
+ setColumnFilterValue: function setColumnFilterValue(val) {
2077
+ return instance.setColumnFilterValue(column.id, val);
2078
+ },
2079
+ getPreFilteredUniqueValues: function getPreFilteredUniqueValues() {
2080
+ return getFacetInfo().preFilteredUniqueValues;
2081
+ },
2082
+ getPreFilteredMinMaxValues: function getPreFilteredMinMaxValues() {
2083
+ return getFacetInfo().preFilteredMinMaxValues;
2084
+ },
2085
+ getPreFilteredRows: function getPreFilteredRows() {
2086
+ return undefined;
2087
+ }
2088
+ };
2089
+ },
2090
+ getInstance: function getInstance(instance) {
2091
+ var registered = false;
2092
+ return {
2093
+ _notifyFiltersReset: function _notifyFiltersReset() {
2094
+ if (!registered) {
2095
+ registered = true;
2096
+ return;
2097
+ }
2098
+
2099
+ if (instance.options.autoResetAll === false) {
2100
+ return;
2101
+ }
2102
+
2103
+ if (instance.options.autoResetAll === true) {
2104
+ instance.resetSorting();
2105
+ } else {
2106
+ if (instance.options.autoResetColumnFilters) {
2107
+ instance.resetColumnFilters();
2108
+ }
2109
+
2110
+ if (instance.options.autoResetGlobalFilter) {
2111
+ instance.resetGlobalFilter();
2112
+ }
2113
+ }
2114
+ },
2115
+ getColumnAutoFilterFn: function getColumnAutoFilterFn(columnId) {
2116
+ var firstRow = instance.getCoreRowModel().flatRows[0];
2117
+ var value = firstRow == null ? void 0 : firstRow.values[columnId];
2118
+
2119
+ if (typeof value === 'string') {
2120
+ return filterTypes.includesString;
2121
+ }
2122
+
2123
+ if (typeof value === 'number') {
2124
+ return filterTypes.betweenNumberRange;
2125
+ }
2126
+
2127
+ if (value !== null && typeof value === 'object') {
2128
+ return filterTypes.equals;
2129
+ }
2130
+
2131
+ if (Array.isArray(value)) {
2132
+ return filterTypes.arrIncludes;
2133
+ }
2134
+
2135
+ return filterTypes.weakEquals;
2136
+ },
2137
+ getGlobalAutoFilterFn: function getGlobalAutoFilterFn() {
2138
+ return filterTypes.includesString;
2139
+ },
2140
+ getColumnFilterFn: function getColumnFilterFn(columnId) {
2141
+ var _ref;
2142
+
2143
+ var column = instance.getColumn(columnId);
2144
+ var userFilterTypes = instance.options.filterTypes;
2145
+
2146
+ if (!column) {
2147
+ throw new Error();
2148
+ }
2149
+
2150
+ return isFunction(column.filterType) ? column.filterType : column.filterType === 'auto' ? instance.getColumnAutoFilterFn(columnId) : (_ref = userFilterTypes == null ? void 0 : userFilterTypes[column.filterType]) != null ? _ref : filterTypes[column.filterType];
2151
+ },
2152
+ getGlobalFilterFn: function getGlobalFilterFn() {
2153
+ var _ref2;
2154
+
2155
+ var _instance$options = instance.options,
2156
+ userFilterTypes = _instance$options.filterTypes,
2157
+ globalFilterType = _instance$options.globalFilterType;
2158
+ return isFunction(globalFilterType) ? globalFilterType : globalFilterType === 'auto' ? instance.getGlobalAutoFilterFn() : (_ref2 = userFilterTypes == null ? void 0 : userFilterTypes[globalFilterType]) != null ? _ref2 : filterTypes[globalFilterType];
2159
+ },
2160
+ setColumnFilters: function setColumnFilters(updater) {
2161
+ var leafColumns = instance.getAllLeafColumns();
2162
+
2163
+ var updateFn = function updateFn(old) {
2164
+ var _functionalUpdate;
2165
+
2166
+ return (_functionalUpdate = functionalUpdate(updater, old)) == null ? void 0 : _functionalUpdate.filter(function (filter) {
2167
+ var column = leafColumns.find(function (d) {
2168
+ return d.id === filter.id;
2169
+ });
2170
+
2171
+ if (column) {
2172
+ var filterFn = instance.getColumnFilterFn(column.id);
2173
+
2174
+ if (shouldAutoRemoveFilter(filterFn, filter.value, column)) {
2175
+ return false;
2176
+ }
2177
+ }
2178
+
2179
+ return true;
2180
+ });
2181
+ };
2182
+
2183
+ instance.options.onColumnFiltersChange == null ? void 0 : instance.options.onColumnFiltersChange(updateFn, updateFn(instance.getState().columnFilters));
2184
+ },
2185
+ setGlobalFilter: function setGlobalFilter(updater) {
2186
+ instance.options.onGlobalFilterChange == null ? void 0 : instance.options.onGlobalFilterChange(updater, functionalUpdate(updater, instance.getState().globalFilter));
2187
+ },
2188
+ resetGlobalFilter: function resetGlobalFilter() {
2189
+ instance.setGlobalFilter(undefined);
2190
+ },
2191
+ getColumnCanColumnFilter: function getColumnCanColumnFilter(columnId) {
2192
+ var _ref3, _ref4, _ref5, _ref6, _ref7, _column$enableAllFilt;
2193
+
2194
+ var column = instance.getColumn(columnId);
2195
+
2196
+ if (!column) {
2197
+ throw new Error();
2198
+ }
2199
+
2200
+ return (_ref3 = (_ref4 = (_ref5 = (_ref6 = (_ref7 = (_column$enableAllFilt = column.enableAllFilters) != null ? _column$enableAllFilt : column.enableColumnFilter) != null ? _ref7 : instance.options.enableFilters) != null ? _ref6 : instance.options.enableColumnFilters) != null ? _ref5 : column.defaultCanFilter) != null ? _ref4 : column.defaultCanColumnFilter) != null ? _ref3 : !!column.accessorFn;
2201
+ },
2202
+ getColumnCanGlobalFilter: function getColumnCanGlobalFilter(columnId) {
2203
+ var _ref8, _ref9, _ref10, _ref11, _ref12, _ref13, _instance$options$ena;
2204
+
2205
+ var column = instance.getColumn(columnId);
2206
+
2207
+ if (!column) {
2208
+ throw new Error();
2209
+ }
2210
+
2211
+ return (_ref8 = ((_ref9 = (_ref10 = (_ref11 = (_ref12 = (_ref13 = (_instance$options$ena = instance.options.enableFilters) != null ? _instance$options$ena : instance.options.enableGlobalFilter) != null ? _ref13 : column.enableAllFilters) != null ? _ref12 : column.enableGlobalFilter) != null ? _ref11 : column.defaultCanFilter) != null ? _ref10 : column.defaultCanGlobalFilter) != null ? _ref9 : !!column.accessorFn) && (instance.options.getColumnCanGlobalFilterFn == null ? void 0 : instance.options.getColumnCanGlobalFilterFn(column))) != null ? _ref8 : true;
2212
+ },
2213
+ getColumnIsFiltered: function getColumnIsFiltered(columnId) {
2214
+ return instance.getColumnFilterIndex(columnId) > -1;
2215
+ },
2216
+ getColumnFilterValue: function getColumnFilterValue(columnId) {
2217
+ var _instance$getState$co, _instance$getState$co2;
2218
+
2219
+ return (_instance$getState$co = instance.getState().columnFilters) == null ? void 0 : (_instance$getState$co2 = _instance$getState$co.find(function (d) {
2220
+ return d.id === columnId;
2221
+ })) == null ? void 0 : _instance$getState$co2.value;
2222
+ },
2223
+ getColumnFilterIndex: function getColumnFilterIndex(columnId) {
2224
+ var _instance$getState$co3, _instance$getState$co4;
2225
+
2226
+ return (_instance$getState$co3 = (_instance$getState$co4 = instance.getState().columnFilters) == null ? void 0 : _instance$getState$co4.findIndex(function (d) {
2227
+ return d.id === columnId;
2228
+ })) != null ? _instance$getState$co3 : -1;
2229
+ },
2230
+ setColumnFilterValue: function setColumnFilterValue(columnId, value) {
2231
+ if (!columnId) return;
2232
+ instance.setColumnFilters(function (old) {
2233
+ var column = instance.getColumn(columnId);
2234
+
2235
+ if (!column) {
2236
+ {
2237
+ console.warn("React-Table: Could not find a column with id: " + columnId);
2238
+ }
2239
+
2240
+ throw new Error();
2241
+ }
2242
+
2243
+ var filterFn = instance.getColumnFilterFn(column.id);
2244
+ var previousfilter = old == null ? void 0 : old.find(function (d) {
2245
+ return d.id === columnId;
2246
+ });
2247
+ var newFilter = functionalUpdate(value, previousfilter ? previousfilter.value : undefined); //
2248
+
2249
+ if (shouldAutoRemoveFilter(filterFn, newFilter, column)) {
2250
+ var _old$filter;
2251
+
2252
+ return (_old$filter = old == null ? void 0 : old.filter(function (d) {
2253
+ return d.id !== columnId;
2254
+ })) != null ? _old$filter : [];
2255
+ }
2256
+
2257
+ var newFilterObj = {
2258
+ id: columnId,
2259
+ value: newFilter
2260
+ };
2261
+
2262
+ if (previousfilter) {
2263
+ var _old$map;
2264
+
2265
+ return (_old$map = old == null ? void 0 : old.map(function (d) {
2266
+ if (d.id === columnId) {
2267
+ return newFilterObj;
2268
+ }
2269
+
2270
+ return d;
2271
+ })) != null ? _old$map : [];
2272
+ }
2273
+
2274
+ if (old != null && old.length) {
2275
+ return [].concat(old, [newFilterObj]);
2276
+ }
2277
+
2278
+ return [newFilterObj];
2279
+ });
2280
+ },
2281
+ resetColumnFilters: function resetColumnFilters() {
2282
+ var _instance$initialStat, _instance$initialStat2;
2283
+
2284
+ instance.setColumnFilters((_instance$initialStat = (_instance$initialStat2 = instance.initialState) == null ? void 0 : _instance$initialStat2.columnFilters) != null ? _instance$initialStat : []);
2285
+ },
2286
+ getPreFilteredRowModel: function getPreFilteredRowModel() {
2287
+ return instance.getCoreRowModel();
2288
+ },
2289
+ getPreColumnFilteredRowModel: function getPreColumnFilteredRowModel() {
2290
+ return instance.getCoreRowModel();
2291
+ },
2292
+ getColumnFilteredRowModel: memo(function () {
2293
+ return [instance.getState().columnFilters, instance.getCoreRowModel(), instance.options.columnFilterRowsFn];
2294
+ }, function (columnFilters, rowModel, columnFiltersFn) {
2295
+ var columnFilteredRowModel = function () {
2296
+ if (!(columnFilters != null && columnFilters.length) || !columnFiltersFn) {
2297
+ return rowModel;
2298
+ }
2299
+
2300
+ return columnFiltersFn(instance, rowModel);
2301
+ }(); // Now that each filtered column has it's partially filtered rows,
2302
+ // lets assign the final filtered rows to all of the other columns
2303
+
2304
+
2305
+ var nonFilteredColumns = instance.getAllLeafColumns().filter(function (column) {
2306
+ var _instance$getState$co5;
2307
+
2308
+ return !((_instance$getState$co5 = instance.getState().columnFilters) != null && _instance$getState$co5.find(function (d) {
2309
+ return d.id === column.id;
2310
+ }));
2311
+ }); // This essentially enables faceted filter options to be built easily
2312
+ // using every column's preFilteredRows value
2313
+
2314
+ nonFilteredColumns.forEach(function (column) {
2315
+ column.getPreFilteredRows = function () {
2316
+ return columnFilteredRowModel.rows;
2317
+ };
2318
+ });
2319
+ return columnFilteredRowModel;
2320
+ }, {
2321
+ key: 'getColumnFilteredRowModel',
2322
+ debug: function debug() {
2323
+ var _instance$options$deb2;
2324
+
2325
+ return (_instance$options$deb2 = instance.options.debugAll) != null ? _instance$options$deb2 : instance.options.debugTable;
2326
+ }
2327
+ }),
2328
+ getPreGlobalFilteredRowModel: function getPreGlobalFilteredRowModel() {
2329
+ return instance.getColumnFilteredRowModel();
2330
+ },
2331
+ getGlobalFilteredRowModel: memo(function () {
2332
+ return [instance.getState().globalFilter, instance.getColumnFilteredRowModel(), instance.options.globalFilterRowsFn];
2333
+ }, function (globalFilterValue, columnFilteredRowModel, globalFiltersFn) {
2334
+ var globalFilteredRowModel = function () {
2335
+ if (!globalFiltersFn || !globalFilterValue) {
2336
+ return columnFilteredRowModel;
2337
+ }
2338
+
2339
+ return globalFiltersFn(instance, columnFilteredRowModel);
2340
+ }(); // Now that each filtered column has it's partially filtered rows,
2341
+ // lets assign the final filtered rows to all of the other columns
2342
+
2343
+
2344
+ var nonFilteredColumns = instance.getAllLeafColumns().filter(function (column) {
2345
+ var _instance$getState$co6;
2346
+
2347
+ return !((_instance$getState$co6 = instance.getState().columnFilters) != null && _instance$getState$co6.find(function (d) {
2348
+ return d.id === column.id;
2349
+ }));
2350
+ }); // This essentially enables faceted filter options to be built easily
2351
+ // using every column's preFilteredRows value
2352
+
2353
+ nonFilteredColumns.forEach(function (column) {
2354
+ column.getPreFilteredRows = function () {
2355
+ return globalFilteredRowModel.rows;
2356
+ };
2357
+ });
2358
+ return globalFilteredRowModel;
2359
+ }, {
2360
+ key: 'getGlobalFilteredRowModel',
2361
+ debug: function debug() {
2362
+ var _instance$options$deb3;
2363
+
2364
+ return (_instance$options$deb3 = instance.options.debugAll) != null ? _instance$options$deb3 : instance.options.debugTable;
2365
+ },
2366
+ onChange: function onChange() {
2367
+ instance._notifySortingReset();
2368
+ }
2369
+ })
2370
+ };
2371
+ }
2372
+ };
2373
+ function shouldAutoRemoveFilter(filterFn, value, column) {
2374
+ return (filterFn && filterFn.autoRemove ? filterFn.autoRemove(value, column) : false) || typeof value === 'undefined' || typeof value === 'string' && !value;
2375
+ }
2376
+
2377
+ var reSplitAlphaNumeric = /([0-9]+)/gm;
2378
+ var sortTypes = {
2379
+ alphanumeric: alphanumeric,
2380
+ alphanumericCaseSensitive: alphanumericCaseSensitive,
2381
+ text: text,
2382
+ textCaseSensitive: textCaseSensitive,
2383
+ datetime: datetime,
2384
+ basic: basic
2385
+ };
2386
+
2387
+ function alphanumeric(rowA, rowB, columnId) {
2388
+ return compareAlphanumeric(toString(rowA.values[columnId]).toLowerCase(), toString(rowB.values[columnId]).toLowerCase());
2389
+ }
2390
+
2391
+ function alphanumericCaseSensitive(rowA, rowB, columnId) {
2392
+ return compareAlphanumeric(toString(rowA.values[columnId]), toString(rowB.values[columnId]));
2393
+ } // Mixed sorting is slow, but very inclusive of many edge cases.
2394
+ // It handles numbers, mixed alphanumeric combinations, and even
2395
+ // null, undefined, and Infinity
2396
+
2397
+
2398
+ function compareAlphanumeric(aStr, bStr) {
2399
+ // Split on number groups, but keep the delimiter
2400
+ // Then remove falsey split values
2401
+ var a = aStr.split(reSplitAlphaNumeric).filter(Boolean);
2402
+ var b = bStr.split(reSplitAlphaNumeric).filter(Boolean); // While
2403
+
2404
+ while (a.length && b.length) {
2405
+ var aa = a.shift();
2406
+ var bb = b.shift();
2407
+ var an = parseInt(aa, 10);
2408
+ var bn = parseInt(bb, 10);
2409
+ var combo = [an, bn].sort(); // Both are string
2410
+
2411
+ if (isNaN(combo[0])) {
2412
+ if (aa > bb) {
2413
+ return 1;
2414
+ }
2415
+
2416
+ if (bb > aa) {
2417
+ return -1;
2418
+ }
2419
+
2420
+ continue;
2421
+ } // One is a string, one is a number
2422
+
2423
+
2424
+ if (isNaN(combo[1])) {
2425
+ return isNaN(an) ? -1 : 1;
2426
+ } // Both are numbers
2427
+
2428
+
2429
+ if (an > bn) {
2430
+ return 1;
2431
+ }
2432
+
2433
+ if (bn > an) {
2434
+ return -1;
2435
+ }
2436
+ }
2437
+
2438
+ return a.length - b.length;
2439
+ } // The text filter is more basic (less numeric support)
2440
+ // but is much faster
2441
+
2442
+
2443
+ function text(rowA, rowB, columnId) {
2444
+ return compareBasic(toString(rowA.values[columnId]).toLowerCase(), toString(rowB.values[columnId]).toLowerCase());
2445
+ } // The text filter is more basic (less numeric support)
2446
+ // but is much faster
2447
+
2448
+
2449
+ function textCaseSensitive(rowA, rowB, columnId) {
2450
+ return compareBasic(toString(rowA.values[columnId]), toString(rowB.values[columnId]));
2451
+ }
2452
+
2453
+ function datetime(rowA, rowB, columnId) {
2454
+ return compareBasic(rowA.values[columnId].getTime(), rowB.values[columnId].getTime());
2455
+ }
2456
+
2457
+ function basic(rowA, rowB, columnId) {
2458
+ return compareBasic(rowA.values[columnId], rowB.values[columnId]);
2459
+ } // Utils
2460
+
2461
+
2462
+ function compareBasic(a, b) {
2463
+ return a === b ? 0 : a > b ? 1 : -1;
2464
+ }
2465
+
2466
+ function toString(a) {
2467
+ if (typeof a === 'number') {
2468
+ if (isNaN(a) || a === Infinity || a === -Infinity) {
2469
+ return '';
2470
+ }
2471
+
2472
+ return String(a);
2473
+ }
2474
+
2475
+ if (typeof a === 'string') {
2476
+ return a;
2477
+ }
2478
+
2479
+ return '';
2480
+ }
2481
+
2482
+ //
2483
+ var Sorting = {
2484
+ getDefaultColumn: function getDefaultColumn() {
2485
+ return {
2486
+ sortType: 'auto'
2487
+ };
2488
+ },
2489
+ getInitialState: function getInitialState() {
2490
+ return {
2491
+ sorting: []
2492
+ };
2493
+ },
2494
+ getDefaultOptions: function getDefaultOptions(instance) {
2495
+ return {
2496
+ onSortingChange: makeStateUpdater('sorting', instance),
2497
+ autoResetSorting: true,
2498
+ isMultiSortEvent: function isMultiSortEvent(e) {
2499
+ return e.shiftKey;
2500
+ }
2501
+ };
2502
+ },
2503
+ createColumn: function createColumn(column, instance) {
2504
+ return {
2505
+ sortType: column.sortType,
2506
+ getCanSort: function getCanSort() {
2507
+ return instance.getColumnCanSort(column.id);
2508
+ },
2509
+ getCanMultiSort: function getCanMultiSort() {
2510
+ return instance.getColumnCanMultiSort(column.id);
2511
+ },
2512
+ getSortIndex: function getSortIndex() {
2513
+ return instance.getColumnSortIndex(column.id);
2514
+ },
2515
+ getIsSorted: function getIsSorted() {
2516
+ return instance.getColumnIsSorted(column.id);
2517
+ },
2518
+ toggleSorting: function toggleSorting(desc, isMulti) {
2519
+ return instance.toggleColumnSorting(column.id, desc, isMulti);
2520
+ },
2521
+ getToggleSortingProps: function getToggleSortingProps(userProps) {
2522
+ return instance.getToggleSortingProps(column.id, userProps);
2523
+ }
2524
+ };
2525
+ },
2526
+ getInstance: function getInstance(instance) {
2527
+ var registered = false;
2528
+ return {
2529
+ _notifySortingReset: function _notifySortingReset() {
2530
+ if (!registered) {
2531
+ registered = true;
2532
+ return;
2533
+ }
2534
+
2535
+ if (instance.options.autoResetAll === false) {
2536
+ return;
2537
+ }
2538
+
2539
+ if (instance.options.autoResetAll === true || instance.options.autoResetSorting) {
2540
+ instance.resetSorting();
2541
+ }
2542
+ },
2543
+ getColumnAutoSortingFn: function getColumnAutoSortingFn(columnId) {
2544
+ var firstRows = instance.getGlobalFilteredRowModel().flatRows.slice(100);
2545
+ var isString = false;
2546
+
2547
+ for (var _iterator = _createForOfIteratorHelperLoose(firstRows), _step; !(_step = _iterator()).done;) {
2548
+ var row = _step.value;
2549
+ var value = row == null ? void 0 : row.values[columnId];
2550
+
2551
+ if (Object.prototype.toString.call(value) === '[object Date]') {
2552
+ return sortTypes.datetime;
2553
+ }
2554
+
2555
+ if (typeof value === 'string') {
2556
+ isString = true;
2557
+
2558
+ if (value.split(reSplitAlphaNumeric).length > 1) {
2559
+ return sortTypes.alphanumeric;
2560
+ }
2561
+ }
2562
+ }
2563
+
2564
+ if (isString) {
2565
+ return sortTypes.text;
2566
+ }
2567
+
2568
+ return sortTypes.basic;
2569
+ },
2570
+ getColumnAutoSortDir: function getColumnAutoSortDir(columnId) {
2571
+ var firstRow = instance.getGlobalFilteredRowModel().flatRows[0];
2572
+ var value = firstRow == null ? void 0 : firstRow.values[columnId];
2573
+
2574
+ if (typeof value === 'string') {
2575
+ return 'asc';
2576
+ }
2577
+
2578
+ return 'desc';
2579
+ },
2580
+ getColumnSortingFn: function getColumnSortingFn(columnId) {
2581
+ var _ref;
2582
+
2583
+ var column = instance.getColumn(columnId);
2584
+ var userSortTypes = instance.options.sortTypes;
2585
+
2586
+ if (!column) {
2587
+ throw new Error();
2588
+ }
2589
+
2590
+ return isFunction(column.sortType) ? column.sortType : column.sortType === 'auto' ? instance.getColumnAutoSortingFn(columnId) : (_ref = userSortTypes == null ? void 0 : userSortTypes[column.sortType]) != null ? _ref : sortTypes[column.sortType];
2591
+ },
2592
+ setSorting: function setSorting(updater) {
2593
+ return instance.options.onSortingChange == null ? void 0 : instance.options.onSortingChange(updater, functionalUpdate(updater, instance.getState().sorting));
2594
+ },
2595
+ toggleColumnSorting: function toggleColumnSorting(columnId, desc, multi) {
2596
+ var column = instance.getColumn(columnId);
2597
+
2598
+ if (!column) {
2599
+ throw new Error();
2600
+ } // if (column.columns.length) {
2601
+ // column.columns.forEach((c, i) => {
2602
+ // if (c.id) {
2603
+ // instance.toggleColumnSorting(c.id, undefined, multi || !!i)
2604
+ // }
2605
+ // })
2606
+ // return
2607
+ // }
2608
+
2609
+
2610
+ instance.setSorting(function (old) {
2611
+ var _ref2, _column$sortDescFirst, _instance$options$ena, _instance$options$ena2;
2612
+
2613
+ // Find any existing sorting for this column
2614
+ var existingSorting = old == null ? void 0 : old.find(function (d) {
2615
+ return d.id === columnId;
2616
+ });
2617
+ var existingIndex = old == null ? void 0 : old.findIndex(function (d) {
2618
+ return d.id === columnId;
2619
+ });
2620
+ var hasDescDefined = typeof desc !== 'undefined' && desc !== null;
2621
+ var newSorting = []; // What should we do with this sort action?
2622
+
2623
+ var sortAction;
2624
+
2625
+ if (column.getCanMultiSort() && multi) {
2626
+ if (existingSorting) {
2627
+ sortAction = 'toggle';
2628
+ } else {
2629
+ sortAction = 'add';
2630
+ }
2631
+ } else {
2632
+ // Normal mode
2633
+ if (old != null && old.length && existingIndex !== old.length - 1) {
2634
+ sortAction = 'replace';
2635
+ } else if (existingSorting) {
2636
+ sortAction = 'toggle';
2637
+ } else {
2638
+ sortAction = 'replace';
2639
+ }
2640
+ }
2641
+
2642
+ var sortDescFirst = (_ref2 = (_column$sortDescFirst = column.sortDescFirst) != null ? _column$sortDescFirst : instance.options.sortDescFirst) != null ? _ref2 : instance.getColumnAutoSortDir(columnId) === 'desc'; // Handle toggle states that will remove the sorting
2643
+
2644
+ if (sortAction === 'toggle' && ( // Must be toggling
2645
+ (_instance$options$ena = instance.options.enableSortingRemoval) != null ? _instance$options$ena : true) && // If enableSortRemove, enable in general
2646
+ !hasDescDefined && ( // Must not be setting desc
2647
+ multi ? (_instance$options$ena2 = instance.options.enableMultiRemove) != null ? _instance$options$ena2 : true : true) && ( // If multi, don't allow if enableMultiRemove
2648
+ existingSorting != null && existingSorting.desc // Finally, detect if it should indeed be removed
2649
+ ? !sortDescFirst : sortDescFirst)) {
2650
+ sortAction = 'remove';
2651
+ }
2652
+
2653
+ if (sortAction === 'replace') {
2654
+ newSorting = [{
2655
+ id: columnId,
2656
+ desc: hasDescDefined ? desc : !!sortDescFirst
2657
+ }];
2658
+ } else if (sortAction === 'add' && old != null && old.length) {
2659
+ var _instance$options$max;
2660
+
2661
+ newSorting = [].concat(old, [{
2662
+ id: columnId,
2663
+ desc: hasDescDefined ? desc : !!sortDescFirst
2664
+ }]); // Take latest n columns
2665
+
2666
+ newSorting.splice(0, newSorting.length - ((_instance$options$max = instance.options.maxMultiSortColCount) != null ? _instance$options$max : Number.MAX_SAFE_INTEGER));
2667
+ } else if (sortAction === 'toggle' && old != null && old.length) {
2668
+ // This flips (or sets) the
2669
+ newSorting = old.map(function (d) {
2670
+ if (d.id === columnId) {
2671
+ return _extends({}, d, {
2672
+ desc: hasDescDefined ? desc : !(existingSorting != null && existingSorting.desc)
2673
+ });
2674
+ }
2675
+
2676
+ return d;
2677
+ });
2678
+ } else if (sortAction === 'remove' && old != null && old.length) {
2679
+ newSorting = old.filter(function (d) {
2680
+ return d.id !== columnId;
2681
+ });
2682
+ }
2683
+
2684
+ return newSorting;
2685
+ });
2686
+ },
2687
+ getColumnCanSort: function getColumnCanSort(columnId) {
2688
+ var _ref3, _ref4, _column$enableSorting;
2689
+
2690
+ var column = instance.getColumn(columnId);
2691
+
2692
+ if (!column) {
2693
+ throw new Error();
2694
+ }
2695
+
2696
+ return (_ref3 = (_ref4 = (_column$enableSorting = column.enableSorting) != null ? _column$enableSorting : instance.options.enableSorting) != null ? _ref4 : column.defaultCanSort) != null ? _ref3 : !!column.accessorFn // (!!column.accessorFn ||
2697
+ // column.columns?.some(c => c.id && instance.getColumnCanSort(c.id))) ??
2698
+ // false
2699
+ ;
2700
+ },
2701
+ getColumnCanMultiSort: function getColumnCanMultiSort(columnId) {
2702
+ var _ref5, _column$enableMultiSo;
2703
+
2704
+ var column = instance.getColumn(columnId);
2705
+
2706
+ if (!column) {
2707
+ throw new Error();
2708
+ }
2709
+
2710
+ return (_ref5 = (_column$enableMultiSo = column.enableMultiSort) != null ? _column$enableMultiSo : instance.options.enableMultiSort) != null ? _ref5 : !!column.accessorFn;
2711
+ },
2712
+ getColumnIsSorted: function getColumnIsSorted(columnId) {
2713
+ var _instance$getState$so;
2714
+
2715
+ var columnSort = (_instance$getState$so = instance.getState().sorting) == null ? void 0 : _instance$getState$so.find(function (d) {
2716
+ return d.id === columnId;
2717
+ });
2718
+ return !columnSort ? false : columnSort.desc ? 'desc' : 'asc';
2719
+ },
2720
+ getColumnSortIndex: function getColumnSortIndex(columnId) {
2721
+ var _instance$getState$so2, _instance$getState$so3;
2722
+
2723
+ return (_instance$getState$so2 = (_instance$getState$so3 = instance.getState().sorting) == null ? void 0 : _instance$getState$so3.findIndex(function (d) {
2724
+ return d.id === columnId;
2725
+ })) != null ? _instance$getState$so2 : -1;
2726
+ },
2727
+ resetSorting: function resetSorting() {
2728
+ var _instance$initialStat, _instance$initialStat2;
2729
+
2730
+ instance.setSorting((_instance$initialStat = (_instance$initialStat2 = instance.initialState) == null ? void 0 : _instance$initialStat2.sorting) != null ? _instance$initialStat : []);
2731
+ },
2732
+ getToggleSortingProps: function getToggleSortingProps(columnId, userProps) {
2733
+ var column = instance.getColumn(columnId);
2734
+
2735
+ if (!column) {
2736
+ throw new Error();
2737
+ }
2738
+
2739
+ var canSort = column.getCanSort();
2740
+ var initialProps = {
2741
+ title: canSort ? 'Toggle Sorting' : undefined,
2742
+ onClick: canSort ? function (e) {
2743
+ e.persist();
2744
+ column.toggleSorting == null ? void 0 : column.toggleSorting(undefined, column.getCanMultiSort() ? instance.options.isMultiSortEvent == null ? void 0 : instance.options.isMultiSortEvent(e) : false);
2745
+ } : undefined
2746
+ };
2747
+ return propGetter(initialProps, userProps);
2748
+ },
2749
+ getPreSortedRowModel: function getPreSortedRowModel() {
2750
+ return instance.getGlobalFilteredRowModel();
2751
+ },
2752
+ getSortedRowModel: memo(function () {
2753
+ return [instance.getState().sorting, instance.getGlobalFilteredRowModel(), instance.options.sortRowsFn];
2754
+ }, function (sorting, rowModel, sortingFn) {
2755
+ if (!sortingFn || !(sorting != null && sorting.length)) {
2756
+ return rowModel;
2757
+ }
2758
+
2759
+ return sortingFn(instance, rowModel);
2760
+ }, {
2761
+ key: 'getSortedRowModel',
2762
+ debug: function debug() {
2763
+ var _instance$options$deb;
2764
+
2765
+ return (_instance$options$deb = instance.options.debugAll) != null ? _instance$options$deb : instance.options.debugTable;
2766
+ },
2767
+ onChange: function onChange() {
2768
+ instance._notifyGroupingReset();
2769
+ }
2770
+ })
2771
+ };
2772
+ }
2773
+ };
2774
+
2775
+ //
2776
+ var Expanding = {
2777
+ getInitialState: function getInitialState() {
2778
+ return {
2779
+ expanded: {}
2780
+ };
2781
+ },
2782
+ getDefaultOptions: function getDefaultOptions(instance) {
2783
+ return {
2784
+ onExpandedChange: makeStateUpdater('expanded', instance),
2785
+ autoResetExpanded: true,
2786
+ getIsRowExpanded: function getIsRowExpanded(row) {
2787
+ return !!(row == null ? void 0 : row.original).expanded;
2788
+ },
2789
+ expandSubRows: true,
2790
+ paginateExpandedRows: true
2791
+ };
2792
+ },
2793
+ getInstance: function getInstance(instance) {
2794
+ var registered = false;
2795
+ return {
2796
+ _notifyExpandedReset: function _notifyExpandedReset() {
2797
+ if (!registered) {
2798
+ registered = true;
2799
+ return;
2800
+ }
2801
+
2802
+ if (instance.options.autoResetAll === false) {
2803
+ return;
2804
+ }
2805
+
2806
+ if (instance.options.autoResetAll === true || instance.options.autoResetExpanded) {
2807
+ instance.resetExpanded();
2808
+ }
2809
+ },
2810
+ setExpanded: function setExpanded(updater) {
2811
+ return instance.options.onExpandedChange == null ? void 0 : instance.options.onExpandedChange(updater, functionalUpdate(updater, instance.getState().expanded));
2812
+ },
2813
+ toggleRowExpanded: function toggleRowExpanded(rowId, expanded) {
2814
+ if (!rowId) return;
2815
+ instance.setExpanded(function (old) {
2816
+ var _expanded;
2817
+
2818
+ var exists = old === true ? true : !!(old != null && old[rowId]);
2819
+ var oldExpanded = {};
2820
+
2821
+ if (old === true) {
2822
+ Object.keys(instance.getRowModel().rowsById).forEach(function (rowId) {
2823
+ oldExpanded[rowId] = true;
2824
+ });
2825
+ } else {
2826
+ oldExpanded = old;
2827
+ }
2828
+
2829
+ expanded = (_expanded = expanded) != null ? _expanded : !exists;
2830
+
2831
+ if (!exists && expanded) {
2832
+ var _extends2;
2833
+
2834
+ return _extends({}, oldExpanded, (_extends2 = {}, _extends2[rowId] = true, _extends2));
2835
+ }
2836
+
2837
+ if (exists && !expanded) {
2838
+ var _oldExpanded = oldExpanded;
2839
+ _oldExpanded[rowId];
2840
+ var rest = _objectWithoutPropertiesLoose(_oldExpanded, [rowId].map(_toPropertyKey));
2841
+
2842
+ return rest;
2843
+ }
2844
+
2845
+ return old;
2846
+ });
2847
+ },
2848
+ toggleAllRowsExpanded: function toggleAllRowsExpanded(expanded) {
2849
+ if (expanded != null ? expanded : !instance.getIsAllRowsExpanded()) {
2850
+ instance.setExpanded(true);
2851
+ } else {
2852
+ instance.setExpanded({});
2853
+ }
2854
+ },
2855
+ resetExpanded: function resetExpanded() {
2856
+ var _instance$initialStat, _instance$initialStat2;
2857
+
2858
+ instance.setExpanded((_instance$initialStat = (_instance$initialStat2 = instance.initialState) == null ? void 0 : _instance$initialStat2.expanded) != null ? _instance$initialStat : {});
2859
+ },
2860
+ getIsRowExpanded: function getIsRowExpanded(rowId) {
2861
+ var _instance$options$get;
2862
+
2863
+ var row = instance.getRow(rowId);
2864
+
2865
+ if (!row) {
2866
+ {
2867
+ console.warn("[ReactTable] getIsRowExpanded: no row found with id " + rowId);
2868
+ }
2869
+
2870
+ throw new Error();
2871
+ }
2872
+
2873
+ var expanded = instance.getState().expanded;
2874
+ return !!((_instance$options$get = instance.options.getIsRowExpanded == null ? void 0 : instance.options.getIsRowExpanded(row)) != null ? _instance$options$get : expanded || (expanded == null ? void 0 : expanded[rowId]));
2875
+ },
2876
+ getRowCanExpand: function getRowCanExpand(rowId) {
2877
+ var _ref, _ref2, _instance$options$get2, _row$subRows;
2878
+
2879
+ var row = instance.getRow(rowId);
2880
+
2881
+ if (!row) {
2882
+ {
2883
+ console.warn("[ReactTable] getRowCanExpand: no row found with id " + rowId);
2884
+ }
2885
+
2886
+ throw new Error();
2887
+ }
2888
+
2889
+ return (_ref = (_ref2 = (_instance$options$get2 = instance.options.getRowCanExpand == null ? void 0 : instance.options.getRowCanExpand(row)) != null ? _instance$options$get2 : instance.options.enableExpanded) != null ? _ref2 : instance.options.defaultCanExpand) != null ? _ref : !!((_row$subRows = row.subRows) != null && _row$subRows.length);
2890
+ },
2891
+ getToggleExpandedProps: function getToggleExpandedProps(rowId, userProps) {
2892
+ var row = instance.getRow(rowId);
2893
+
2894
+ if (!row) {
2895
+ return;
2896
+ }
2897
+
2898
+ var canExpand = instance.getRowCanExpand(rowId);
2899
+ var initialProps = {
2900
+ title: canExpand ? 'Toggle Expanded' : undefined,
2901
+ onClick: canExpand ? function (e) {
2902
+ e.persist();
2903
+ instance.toggleRowExpanded(rowId);
2904
+ } : undefined
2905
+ };
2906
+ return propGetter(initialProps, userProps);
2907
+ },
2908
+ getToggleAllRowsExpandedProps: function getToggleAllRowsExpandedProps(userProps) {
2909
+ var initialProps = {
2910
+ title: 'Toggle All Expanded',
2911
+ onClick: function onClick(e) {
2912
+ e.persist();
2913
+ instance.toggleAllRowsExpanded();
2914
+ }
2915
+ };
2916
+ return propGetter(initialProps, userProps);
2917
+ },
2918
+ getIsAllRowsExpanded: function getIsAllRowsExpanded() {
2919
+ var expanded = instance.getState().expanded; // If expanded is true, save some cycles and return true
2920
+
2921
+ if (expanded === true) {
2922
+ return true;
2923
+ } // If any row is not expanded, return false
2924
+
2925
+
2926
+ if (Object.keys(instance.getRowModel().rowsById).some(function (id) {
2927
+ return !instance.getIsRowExpanded(id);
2928
+ })) {
2929
+ return false;
2930
+ } // They must all be expanded :shrug:
2931
+
2932
+
2933
+ return true;
2934
+ },
2935
+ getExpandedDepth: function getExpandedDepth() {
2936
+ var maxDepth = 0;
2937
+ var rowIds = instance.getState().expanded === true ? Object.keys(instance.getRowModel().rowsById) : Object.keys(instance.getState().expanded);
2938
+ rowIds.forEach(function (id) {
2939
+ var splitId = id.split('.');
2940
+ maxDepth = Math.max(maxDepth, splitId.length);
2941
+ });
2942
+ return maxDepth;
2943
+ },
2944
+ getExpandedRowModel: memo(function () {
2945
+ return [instance.getState().expanded, instance.getGroupedRowModel(), instance.options.expandRowsFn, instance.options.paginateExpandedRows];
2946
+ }, function (expanded, rowModel, expandRowsFn, paginateExpandedRows) {
2947
+ if (!expandRowsFn || // Do not expand if rows are not included in pagination
2948
+ !paginateExpandedRows || !Object.keys(expanded != null ? expanded : {}).length) {
2949
+ return rowModel;
2950
+ }
2951
+
2952
+ return expandRowsFn(instance, rowModel);
2953
+ }, {
2954
+ key: 'getExpandedRowModel',
2955
+ debug: function debug() {
2956
+ var _instance$options$deb;
2957
+
2958
+ return (_instance$options$deb = instance.options.debugAll) != null ? _instance$options$deb : instance.options.debugTable;
2959
+ },
2960
+ onChange: function onChange() {
2961
+ instance._notifyPageIndexReset();
2962
+ }
2963
+ }),
2964
+ getPreExpandedRowModel: function getPreExpandedRowModel() {
2965
+ return instance.getGroupedRowModel();
2966
+ }
2967
+ };
2968
+ },
2969
+ createRow: function createRow(row, instance) {
2970
+ return {
2971
+ toggleExpanded: function toggleExpanded(expanded) {
2972
+ return void instance.toggleRowExpanded(row.id, expanded);
2973
+ },
2974
+ getIsExpanded: function getIsExpanded() {
2975
+ return instance.getIsRowExpanded(row.id);
2976
+ },
2977
+ getCanExpand: function getCanExpand() {
2978
+ return row.subRows && !!row.subRows.length;
2979
+ },
2980
+ getToggleExpandedProps: function getToggleExpandedProps(userProps) {
2981
+ var initialProps = {
2982
+ title: 'Toggle Row Expanded',
2983
+ onClick: function onClick(e) {
2984
+ e.stopPropagation();
2985
+ instance.toggleRowExpanded(row.id);
2986
+ }
2987
+ };
2988
+ return propGetter(initialProps, userProps);
2989
+ }
2990
+ };
2991
+ }
2992
+ };
2993
+
2994
+ //
2995
+ var Pagination = {
2996
+ getInitialState: function getInitialState() {
2997
+ return {
2998
+ pagination: {
2999
+ pageCount: -1,
3000
+ pageIndex: 0,
3001
+ pageSize: 10
3002
+ }
3003
+ };
3004
+ },
3005
+ getDefaultOptions: function getDefaultOptions(instance) {
3006
+ return {
3007
+ onPaginationChange: makeStateUpdater('pagination', instance),
3008
+ autoResetPageIndex: true
3009
+ };
3010
+ },
3011
+ getInstance: function getInstance(instance) {
3012
+ var registered = false;
3013
+ return {
3014
+ _notifyPageIndexReset: function _notifyPageIndexReset() {
3015
+ if (!registered) {
3016
+ registered = true;
3017
+ return;
3018
+ }
3019
+
3020
+ if (instance.options.autoResetAll === false) {
3021
+ return;
3022
+ }
3023
+
3024
+ if (instance.options.autoResetAll === true || instance.options.autoResetPageIndex) {
3025
+ instance.resetPageIndex();
3026
+ }
3027
+ },
3028
+ setPagination: function setPagination(updater) {
3029
+ var safeUpdater = function safeUpdater(old) {
3030
+ var newState = functionalUpdate(updater, old);
3031
+ return newState;
3032
+ };
3033
+
3034
+ return instance.options.onPaginationChange == null ? void 0 : instance.options.onPaginationChange(safeUpdater, functionalUpdate(safeUpdater, instance.getState().pagination));
3035
+ },
3036
+ resetPagination: function resetPagination() {
3037
+ var _instance$initialStat;
3038
+
3039
+ instance.setPagination((_instance$initialStat = instance.initialState.pagination) != null ? _instance$initialStat : {
3040
+ pageIndex: 0,
3041
+ pageSize: 10,
3042
+ pageCount: -1
3043
+ });
3044
+ },
3045
+ setPageIndex: function setPageIndex(updater) {
3046
+ instance.setPagination(function (old) {
3047
+ var pageIndex = functionalUpdate(updater, old.pageIndex);
3048
+ var maxPageIndex = old.pageCount && old.pageCount > 0 ? old.pageCount - 1 : Number.MAX_SAFE_INTEGER;
3049
+ pageIndex = Math.min(Math.max(0, pageIndex), maxPageIndex);
3050
+ return _extends({}, old, {
3051
+ pageIndex: pageIndex
3052
+ });
3053
+ });
3054
+ },
3055
+ resetPageIndex: function resetPageIndex() {
3056
+ instance.setPageIndex(0);
3057
+ },
3058
+ resetPageSize: function resetPageSize() {
3059
+ var _instance$initialStat2, _instance$initialStat3, _instance$initialStat4;
3060
+
3061
+ instance.setPageSize((_instance$initialStat2 = (_instance$initialStat3 = instance.initialState) == null ? void 0 : (_instance$initialStat4 = _instance$initialStat3.pagination) == null ? void 0 : _instance$initialStat4.pageSize) != null ? _instance$initialStat2 : 10);
3062
+ },
3063
+ setPageSize: function setPageSize(updater) {
3064
+ instance.setPagination(function (old) {
3065
+ var pageSize = Math.max(1, functionalUpdate(updater, old.pageSize));
3066
+ var topRowIndex = old.pageSize * old.pageIndex;
3067
+ var pageIndex = Math.floor(topRowIndex / pageSize);
3068
+ return _extends({}, old, {
3069
+ pageIndex: pageIndex,
3070
+ pageSize: pageSize
3071
+ });
3072
+ });
3073
+ },
3074
+ setPageCount: function setPageCount(updater) {
3075
+ return instance.setPagination(function (old) {
3076
+ var newPageCount = functionalUpdate(updater, old.pageCount);
3077
+
3078
+ if (typeof newPageCount === 'number') {
3079
+ newPageCount = Math.max(-1, newPageCount);
3080
+ }
3081
+
3082
+ return _extends({}, old, {
3083
+ pageCount: newPageCount
3084
+ });
3085
+ });
3086
+ },
3087
+ getPageOptions: memo(function () {
3088
+ return [instance.getState().pagination.pageSize, instance.getState().pagination.pageCount];
3089
+ }, function (pageSize, pageCount) {
3090
+ var pageOptions = [];
3091
+
3092
+ if (pageCount && pageCount > 0) {
3093
+ pageOptions = [].concat(new Array(pageCount)).fill(null).map(function (_, i) {
3094
+ return i;
3095
+ });
3096
+ }
3097
+
3098
+ return pageOptions;
3099
+ }, {
3100
+ key: 'getPageOptions',
3101
+ debug: function debug() {
3102
+ var _instance$options$deb;
3103
+
3104
+ return (_instance$options$deb = instance.options.debugAll) != null ? _instance$options$deb : instance.options.debugTable;
3105
+ }
3106
+ }),
3107
+ getCanPreviousPage: function getCanPreviousPage() {
3108
+ return instance.getState().pagination.pageIndex > 0;
3109
+ },
3110
+ getCanNextPage: function getCanNextPage() {
3111
+ var _instance$getState$pa = instance.getState().pagination,
3112
+ pageIndex = _instance$getState$pa.pageIndex,
3113
+ pageCount = _instance$getState$pa.pageCount,
3114
+ pageSize = _instance$getState$pa.pageSize;
3115
+
3116
+ if (pageCount === -1) {
3117
+ return true;
3118
+ }
3119
+
3120
+ if (pageCount === 0) {
3121
+ return false;
3122
+ }
3123
+
3124
+ return pageIndex < Math.ceil(instance.getPrePaginationRowModel().rows.length / pageSize) - 1;
3125
+ },
3126
+ previousPage: function previousPage() {
3127
+ return instance.setPageIndex(function (old) {
3128
+ return old - 1;
3129
+ });
3130
+ },
3131
+ nextPage: function nextPage() {
3132
+ return instance.setPageIndex(function (old) {
3133
+ return old + 1;
3134
+ });
3135
+ },
3136
+ getPrePaginationRowModel: function getPrePaginationRowModel() {
3137
+ return instance.getExpandedRowModel();
3138
+ },
3139
+ getPaginationRowModel: memo(function () {
3140
+ return [instance.getState().pagination, instance.getExpandedRowModel(), instance.options.paginateRowsFn];
3141
+ }, function (_pagination, rowModel, paginateRowsFn) {
3142
+ if (!paginateRowsFn || !rowModel.rows.length) {
3143
+ return rowModel;
3144
+ }
3145
+
3146
+ return paginateRowsFn(instance, rowModel);
3147
+ }, {
3148
+ key: 'getPaginationRowModel',
3149
+ debug: function debug() {
3150
+ var _instance$options$deb2;
3151
+
3152
+ return (_instance$options$deb2 = instance.options.debugAll) != null ? _instance$options$deb2 : instance.options.debugTable;
3153
+ }
3154
+ }),
3155
+ getPageCount: function getPageCount() {
3156
+ var pageCount = instance.getState().pagination.pageCount;
3157
+
3158
+ if (pageCount > 0) {
3159
+ return pageCount;
3160
+ }
3161
+
3162
+ return Math.ceil(instance.getPrePaginationRowModel().rows.length / instance.getState().pagination.pageSize);
3163
+ }
3164
+ };
3165
+ }
3166
+ };
3167
+
3168
+ //
3169
+ var RowSelection = {
3170
+ getInitialState: function getInitialState() {
3171
+ return {
3172
+ rowSelection: {}
3173
+ };
3174
+ },
3175
+ getDefaultOptions: function getDefaultOptions(instance) {
3176
+ return {
3177
+ onRowSelectionChange: makeStateUpdater('rowSelection', instance),
3178
+ autoResetRowSelection: true,
3179
+ enableRowSelection: true,
3180
+ enableMultiRowSelection: true,
3181
+ enableSubRowSelection: true // enableGroupingRowSelection: false,
3182
+ // isAdditiveSelectEvent: (e: MouseEvent | TouchEvent) => !!e.metaKey,
3183
+ // isInclusiveSelectEvent: (e: MouseEvent | TouchEvent) => !!e.shiftKey,
3184
+
3185
+ };
3186
+ },
3187
+ getInstance: function getInstance(instance) {
3188
+ var registered = false; // const pageRows = instance.getPageRows()
3189
+
3190
+ return {
3191
+ _notifyRowSelectionReset: function _notifyRowSelectionReset() {
3192
+ if (!registered) {
3193
+ registered = true;
3194
+ return;
3195
+ }
3196
+
3197
+ if (instance.options.autoResetAll === false) {
3198
+ return;
3199
+ }
3200
+
3201
+ if (instance.options.autoResetAll === true || instance.options.autoResetRowSelection) {
3202
+ instance.resetRowSelection();
3203
+ }
3204
+ },
3205
+ setRowSelection: function setRowSelection(updater) {
3206
+ return instance.options.onRowSelectionChange == null ? void 0 : instance.options.onRowSelectionChange(updater, functionalUpdate(updater, instance.getState().rowSelection));
3207
+ },
3208
+ resetRowSelection: function resetRowSelection() {
3209
+ var _instance$initialStat;
3210
+
3211
+ return instance.setRowSelection((_instance$initialStat = instance.initialState.rowSelection) != null ? _instance$initialStat : {});
3212
+ },
3213
+ toggleAllRowsSelected: function toggleAllRowsSelected(value) {
3214
+ instance.setRowSelection(function (old) {
3215
+ value = typeof value !== 'undefined' ? value : !instance.getIsAllRowsSelected(); // Only remove/add the rows that are visible on the screen
3216
+ // Leave all the other rows that are selected alone.
3217
+
3218
+ var rowSelection = Object.assign({}, old);
3219
+ var preGroupedFlatRows = instance.getPreGroupedRowModel().flatRows; // We don't use `mutateRowIsSelected` here for performance reasons.
3220
+ // All of the rows are flat already, so it wouldn't be worth it
3221
+
3222
+ if (value) {
3223
+ preGroupedFlatRows.forEach(function (row) {
3224
+ rowSelection[row.id] = true;
3225
+ });
3226
+ } else {
3227
+ preGroupedFlatRows.forEach(function (row) {
3228
+ delete rowSelection[row.id];
3229
+ });
3230
+ }
3231
+
3232
+ return rowSelection;
3233
+ });
3234
+ },
3235
+ toggleAllPageRowsSelected: function toggleAllPageRowsSelected(value) {
3236
+ return instance.setRowSelection(function (old) {
3237
+ typeof value !== 'undefined' ? value : !instance.getIsAllPageRowsSelected();
3238
+
3239
+ var rowSelection = _extends({}, old);
3240
+
3241
+ instance.getRowModel().rows.forEach(function (row) {
3242
+ mutateRowIsSelected(rowSelection, row.id, value, instance);
3243
+ });
3244
+ return rowSelection;
3245
+ });
3246
+ },
3247
+ toggleRowSelected: function toggleRowSelected(rowId, value) {
3248
+ var row = instance.getRow(rowId);
3249
+ var isSelected = row.getIsSelected();
3250
+ instance.setRowSelection(function (old) {
3251
+ value = typeof value !== 'undefined' ? value : !isSelected;
3252
+
3253
+ if (isSelected === value) {
3254
+ return old;
3255
+ }
3256
+
3257
+ var selectedRowIds = _extends({}, old);
3258
+
3259
+ mutateRowIsSelected(selectedRowIds, rowId, value, instance);
3260
+ return selectedRowIds;
3261
+ });
3262
+ },
3263
+ // addRowSelectionRange: rowId => {
3264
+ // const {
3265
+ // rows,
3266
+ // rowsById,
3267
+ // options: { selectGroupingRows, selectSubRows },
3268
+ // } = instance
3269
+ // const findSelectedRow = (rows: Row[]) => {
3270
+ // let found
3271
+ // rows.find(d => {
3272
+ // if (d.getIsSelected()) {
3273
+ // found = d
3274
+ // return true
3275
+ // }
3276
+ // const subFound = findSelectedRow(d.subRows || [])
3277
+ // if (subFound) {
3278
+ // found = subFound
3279
+ // return true
3280
+ // }
3281
+ // return false
3282
+ // })
3283
+ // return found
3284
+ // }
3285
+ // const firstRow = findSelectedRow(rows) || rows[0]
3286
+ // const lastRow = rowsById[rowId]
3287
+ // let include = false
3288
+ // const selectedRowIds = {}
3289
+ // const addRow = (row: Row) => {
3290
+ // mutateRowIsSelected(selectedRowIds, row.id, true, {
3291
+ // rowsById,
3292
+ // selectGroupingRows: selectGroupingRows!,
3293
+ // selectSubRows: selectSubRows!,
3294
+ // })
3295
+ // }
3296
+ // instance.rows.forEach(row => {
3297
+ // const isFirstRow = row.id === firstRow.id
3298
+ // const isLastRow = row.id === lastRow.id
3299
+ // if (isFirstRow || isLastRow) {
3300
+ // if (!include) {
3301
+ // include = true
3302
+ // } else if (include) {
3303
+ // addRow(row)
3304
+ // include = false
3305
+ // }
3306
+ // }
3307
+ // if (include) {
3308
+ // addRow(row)
3309
+ // }
3310
+ // })
3311
+ // instance.setRowSelection(selectedRowIds)
3312
+ // },
3313
+ getPreSelectedRowModel: function getPreSelectedRowModel() {
3314
+ return instance.getCoreRowModel();
3315
+ },
3316
+ getSelectedRowModel: memo(function () {
3317
+ return [instance.getState().rowSelection, instance.getCoreRowModel()];
3318
+ }, function (rowSelection, rowModel) {
3319
+ if (!Object.keys(rowSelection).length) {
3320
+ return {
3321
+ rows: [],
3322
+ flatRows: [],
3323
+ rowsById: {}
3324
+ };
3325
+ }
3326
+
3327
+ return selectRowsFn(instance, rowModel);
3328
+ }, {
3329
+ key: 'getSelectedRowModel',
3330
+ debug: function debug() {
3331
+ var _instance$options$deb;
3332
+
3333
+ return (_instance$options$deb = instance.options.debugAll) != null ? _instance$options$deb : instance.options.debugTable;
3334
+ },
3335
+ onChange: function onChange() {
3336
+ return instance._notifyExpandedReset();
3337
+ }
3338
+ }),
3339
+ getFilteredSelectedRowModel: memo(function () {
3340
+ return [instance.getState().rowSelection, instance.getGlobalFilteredRowModel()];
3341
+ }, function (rowSelection, rowModel) {
3342
+ if (!Object.keys(rowSelection).length) {
3343
+ return {
3344
+ rows: [],
3345
+ flatRows: [],
3346
+ rowsById: {}
3347
+ };
3348
+ }
3349
+
3350
+ return selectRowsFn(instance, rowModel);
3351
+ }, {
3352
+ key: 'getFilteredSelectedRowModel',
3353
+ debug: function debug() {
3354
+ var _instance$options$deb2;
3355
+
3356
+ return (_instance$options$deb2 = instance.options.debugAll) != null ? _instance$options$deb2 : instance.options.debugTable;
3357
+ },
3358
+ onChange: function onChange() {
3359
+ return instance._notifyExpandedReset();
3360
+ }
3361
+ }),
3362
+ getGroupedSelectedRowModel: memo(function () {
3363
+ return [instance.getState().rowSelection, instance.getGroupedRowModel()];
3364
+ }, function (rowSelection, rowModel) {
3365
+ if (!Object.keys(rowSelection).length) {
3366
+ return {
3367
+ rows: [],
3368
+ flatRows: [],
3369
+ rowsById: {}
3370
+ };
3371
+ }
3372
+
3373
+ return selectRowsFn(instance, rowModel);
3374
+ }, {
3375
+ key: 'getGroupedSelectedRowModel',
3376
+ debug: function debug() {
3377
+ var _instance$options$deb3;
3378
+
3379
+ return (_instance$options$deb3 = instance.options.debugAll) != null ? _instance$options$deb3 : instance.options.debugTable;
3380
+ },
3381
+ onChange: function onChange() {
3382
+ return instance._notifyExpandedReset();
3383
+ }
3384
+ }),
3385
+ ///
3386
+ getRowIsSelected: function getRowIsSelected(rowId) {
3387
+ var _instance$getState = instance.getState(),
3388
+ rowSelection = _instance$getState.rowSelection;
3389
+
3390
+ var row = instance.getRow(rowId);
3391
+
3392
+ if (!row) {
3393
+ throw new Error();
3394
+ }
3395
+
3396
+ return isRowSelected(row, rowSelection) === true;
3397
+ },
3398
+ getRowIsSomeSelected: function getRowIsSomeSelected(rowId) {
3399
+ var _instance$getState2 = instance.getState(),
3400
+ rowSelection = _instance$getState2.rowSelection;
3401
+
3402
+ var row = instance.getRow(rowId);
3403
+
3404
+ if (!row) {
3405
+ throw new Error();
3406
+ }
3407
+
3408
+ return isRowSelected(row, rowSelection) === 'some';
3409
+ },
3410
+ getRowCanSelect: function getRowCanSelect(rowId) {
3411
+ var _instance$options$ena;
3412
+
3413
+ var row = instance.getRow(rowId);
3414
+
3415
+ if (!row) {
3416
+ throw new Error();
3417
+ }
3418
+
3419
+ if (typeof instance.options.enableRowSelection === 'function') {
3420
+ return instance.options.enableRowSelection(row);
3421
+ }
3422
+
3423
+ return (_instance$options$ena = instance.options.enableRowSelection) != null ? _instance$options$ena : true;
3424
+ },
3425
+ getRowCanSelectSubRows: function getRowCanSelectSubRows(rowId) {
3426
+ var _instance$options$ena2;
3427
+
3428
+ var row = instance.getRow(rowId);
3429
+
3430
+ if (!row) {
3431
+ throw new Error();
3432
+ }
3433
+
3434
+ if (typeof instance.options.enableSubRowSelection === 'function') {
3435
+ return instance.options.enableSubRowSelection(row);
3436
+ }
3437
+
3438
+ return (_instance$options$ena2 = instance.options.enableSubRowSelection) != null ? _instance$options$ena2 : true;
3439
+ },
3440
+ getRowCanMultiSelect: function getRowCanMultiSelect(rowId) {
3441
+ var _instance$options$ena3;
3442
+
3443
+ var row = instance.getRow(rowId);
3444
+
3445
+ if (!row) {
3446
+ throw new Error();
3447
+ }
3448
+
3449
+ if (typeof instance.options.enableMultiRowSelection === 'function') {
3450
+ return instance.options.enableMultiRowSelection(row);
3451
+ }
3452
+
3453
+ return (_instance$options$ena3 = instance.options.enableMultiRowSelection) != null ? _instance$options$ena3 : true;
3454
+ },
3455
+ // getGroupingRowCanSelect: rowId => {
3456
+ // const row = instance.getRow(rowId)
3457
+ // if (!row) {
3458
+ // throw new Error()
3459
+ // }
3460
+ // if (typeof instance.options.enableGroupingRowSelection === 'function') {
3461
+ // return instance.options.enableGroupingRowSelection(row)
3462
+ // }
3463
+ // return instance.options.enableGroupingRowSelection ?? false
3464
+ // },
3465
+ getIsAllRowsSelected: function getIsAllRowsSelected() {
3466
+ var preFilteredFlatRows = instance.getPreGlobalFilteredRowModel().flatRows;
3467
+
3468
+ var _instance$getState3 = instance.getState(),
3469
+ rowSelection = _instance$getState3.rowSelection;
3470
+
3471
+ var isAllRowsSelected = Boolean(preFilteredFlatRows.length && Object.keys(rowSelection).length);
3472
+
3473
+ if (isAllRowsSelected) {
3474
+ if (preFilteredFlatRows.some(function (row) {
3475
+ return !rowSelection[row.id];
3476
+ })) {
3477
+ isAllRowsSelected = false;
3478
+ }
3479
+ }
3480
+
3481
+ return isAllRowsSelected;
3482
+ },
3483
+ getIsAllPageRowsSelected: function getIsAllPageRowsSelected() {
3484
+ var paginationFlatRows = instance.getPaginationRowModel().flatRows;
3485
+
3486
+ var _instance$getState4 = instance.getState(),
3487
+ rowSelection = _instance$getState4.rowSelection;
3488
+
3489
+ var isAllPageRowsSelected = !!paginationFlatRows.length;
3490
+
3491
+ if (isAllPageRowsSelected && paginationFlatRows.some(function (row) {
3492
+ return !rowSelection[row.id];
3493
+ })) {
3494
+ isAllPageRowsSelected = false;
3495
+ }
3496
+
3497
+ return isAllPageRowsSelected;
3498
+ },
3499
+ getIsSomeRowsSelected: function getIsSomeRowsSelected() {
3500
+ var _instance$getState$ro;
3501
+
3502
+ return !instance.getIsAllRowsSelected() && !!Object.keys((_instance$getState$ro = instance.getState().rowSelection) != null ? _instance$getState$ro : {}).length;
3503
+ },
3504
+ getIsSomePageRowsSelected: function getIsSomePageRowsSelected() {
3505
+ var paginationFlatRows = instance.getPaginationRowModel().flatRows;
3506
+ return instance.getIsAllPageRowsSelected() ? false : !!(paginationFlatRows != null && paginationFlatRows.length);
3507
+ },
3508
+ getToggleRowSelectedProps: function getToggleRowSelectedProps(rowId, userProps) {
3509
+ var row = instance.getRow(rowId);
3510
+ var isSelected = row.getIsSelected();
3511
+ var isSomeSelected = row.getIsSomeSelected();
3512
+ var canSelect = row.getCanSelect();
3513
+ var initialProps = {
3514
+ onChange: canSelect ? function (e) {
3515
+ row.toggleSelected(e.target.checked);
3516
+ } : undefined,
3517
+ checked: isSelected,
3518
+ title: 'Toggle Row Selected',
3519
+ indeterminate: isSomeSelected // onChange: forInput
3520
+ // ? (e: Event) => e.stopPropagation()
3521
+ // : (e: Event) => {
3522
+ // if (instance.options.isAdditiveSelectEvent(e)) {
3523
+ // row.toggleSelected()
3524
+ // } else if (instance.options.isInclusiveSelectEvent(e)) {
3525
+ // instance.addRowSelectionRange(row.id)
3526
+ // } else {
3527
+ // instance.setRowSelection({})
3528
+ // row.toggleSelected()
3529
+ // }
3530
+ // if (props.onClick) props.onClick(e)
3531
+ // },
3532
+
3533
+ };
3534
+ return propGetter(initialProps, userProps);
3535
+ },
3536
+ getToggleAllRowsSelectedProps: function getToggleAllRowsSelectedProps(userProps) {
3537
+ var isSomeRowsSelected = instance.getIsSomeRowsSelected();
3538
+ var isAllRowsSelected = instance.getIsAllRowsSelected();
3539
+ var initialProps = {
3540
+ onChange: function onChange(e) {
3541
+ instance.toggleAllRowsSelected(e.target.checked);
3542
+ },
3543
+ checked: isAllRowsSelected,
3544
+ title: 'Toggle All Rows Selected',
3545
+ indeterminate: isSomeRowsSelected
3546
+ };
3547
+ return propGetter(initialProps, userProps);
3548
+ },
3549
+ getToggleAllPageRowsSelectedProps: function getToggleAllPageRowsSelectedProps(userProps) {
3550
+ var isSomePageRowsSelected = instance.getIsSomePageRowsSelected();
3551
+ var isAllPageRowsSelected = instance.getIsAllPageRowsSelected();
3552
+ var initialProps = {
3553
+ onChange: function onChange(e) {
3554
+ instance.toggleAllPageRowsSelected(e.target.checked);
3555
+ },
3556
+ checked: isAllPageRowsSelected,
3557
+ title: 'Toggle All Current Page Rows Selected',
3558
+ indeterminate: isSomePageRowsSelected
3559
+ };
3560
+ return propGetter(initialProps, userProps);
3561
+ }
3562
+ };
3563
+ },
3564
+ createRow: function createRow(row, instance) {
3565
+ return {
3566
+ getIsSelected: function getIsSelected() {
3567
+ return instance.getRowIsSelected(row.id);
3568
+ },
3569
+ getIsSomeSelected: function getIsSomeSelected() {
3570
+ return instance.getRowIsSomeSelected(row.id);
3571
+ },
3572
+ toggleSelected: function toggleSelected(value) {
3573
+ return instance.toggleRowSelected(row.id, value);
3574
+ },
3575
+ getToggleSelectedProps: function getToggleSelectedProps(userProps) {
3576
+ return instance.getToggleRowSelectedProps(row.id, userProps);
3577
+ },
3578
+ getCanMultiSelect: function getCanMultiSelect() {
3579
+ return instance.getRowCanMultiSelect(row.id);
3580
+ },
3581
+ getCanSelect: function getCanSelect() {
3582
+ return instance.getRowCanSelect(row.id);
3583
+ }
3584
+ };
3585
+ }
3586
+ };
3587
+
3588
+ var mutateRowIsSelected = function mutateRowIsSelected(selectedRowIds, id, value, instance) {
3589
+ var _row$subRows;
3590
+
3591
+ var row = instance.getRow(id);
3592
+ row.getIsGrouped(); // if ( // TODO: enforce grouping row selection rules
3593
+ // !isGrouped ||
3594
+ // (isGrouped && instance.options.enableGroupingRowSelection)
3595
+ // ) {
3596
+
3597
+ if (value) {
3598
+ selectedRowIds[id] = true;
3599
+ } else {
3600
+ delete selectedRowIds[id];
3601
+ } // }
3602
+
3603
+
3604
+ if ((_row$subRows = row.subRows) != null && _row$subRows.length && instance.getRowCanSelectSubRows(row.id)) {
3605
+ row.subRows.forEach(function (row) {
3606
+ return mutateRowIsSelected(selectedRowIds, row.id, value, instance);
3607
+ });
3608
+ }
3609
+ };
3610
+
3611
+ function selectRowsFn(instance, rowModel) {
3612
+ var rowSelection = instance.getState().rowSelection;
3613
+ var newSelectedFlatRows = [];
3614
+ var newSelectedRowsById = {}; // Filters top level and nested rows
3615
+
3616
+ var recurseRows = function recurseRows(rows, depth) {
3617
+
3618
+ return rows.map(function (row) {
3619
+ var _row$subRows2;
3620
+
3621
+ var isSelected = isRowSelected(row, rowSelection) === true;
3622
+
3623
+ if (isSelected) {
3624
+ newSelectedFlatRows.push(row);
3625
+ newSelectedRowsById[row.id] = row;
3626
+ }
3627
+
3628
+ if ((_row$subRows2 = row.subRows) != null && _row$subRows2.length) {
3629
+ row = _extends({}, row, {
3630
+ subRows: recurseRows(row.subRows)
3631
+ });
3632
+ }
3633
+
3634
+ if (isSelected) {
3635
+ return row;
3636
+ }
3637
+ }).filter(Boolean);
3638
+ };
3639
+
3640
+ return {
3641
+ rows: recurseRows(rowModel.rows),
3642
+ flatRows: newSelectedFlatRows,
3643
+ rowsById: newSelectedRowsById
3644
+ };
3645
+ }
3646
+ function isRowSelected(row, selection, instance) {
3647
+ if (selection[row.id]) {
3648
+ return true;
3649
+ }
3650
+
3651
+ if (row.subRows && row.subRows.length) {
3652
+ var allChildrenSelected = true;
3653
+ var someSelected = false;
3654
+ row.subRows.forEach(function (subRow) {
3655
+ // Bail out early if we know both of these
3656
+ if (someSelected && !allChildrenSelected) {
3657
+ return;
3658
+ }
3659
+
3660
+ if (isRowSelected(subRow, selection)) {
3661
+ someSelected = true;
3662
+ } else {
3663
+ allChildrenSelected = false;
3664
+ }
3665
+ });
3666
+ return allChildrenSelected ? true : someSelected ? 'some' : false;
3667
+ }
3668
+
3669
+ return false;
3670
+ }
3671
+
3672
+ var features = [Visibility, Ordering, Pinning, Headers, Filters, Sorting, Grouping, Expanding, ColumnSizing, Pagination, RowSelection];
3673
+ function createTableInstance(options) {
3674
+ var _options$initialState;
3675
+
3676
+ if (options.debugAll || options.debugTable) {
3677
+ console.info('Creating React Table Instance...');
3678
+ }
3679
+
3680
+ var instance = {};
3681
+ var defaultOptions = features.reduce(function (obj, feature) {
3682
+ return Object.assign(obj, feature.getDefaultOptions == null ? void 0 : feature.getDefaultOptions(instance));
3683
+ }, {});
3684
+
3685
+ var buildOptions = function buildOptions(options) {
3686
+ return _extends({}, defaultOptions, options);
3687
+ };
3688
+
3689
+ instance.options = buildOptions(options);
3690
+
3691
+ var initialState = _extends({}, features.reduce(function (obj, feature) {
3692
+ return Object.assign(obj, feature.getInitialState == null ? void 0 : feature.getInitialState());
3693
+ }, {}), (_options$initialState = options.initialState) != null ? _options$initialState : {});
3694
+
3695
+ var finalInstance = _extends({}, instance, features.reduce(function (obj, feature) {
3696
+ return Object.assign(obj, feature.getInstance == null ? void 0 : feature.getInstance(instance));
3697
+ }, {}), {
3698
+ initialState: initialState,
3699
+ reset: function reset() {
3700
+ instance.setState(instance.initialState);
3701
+ },
3702
+ setOptions: function setOptions(updater) {
3703
+ instance.options = buildOptions(functionalUpdate(updater, instance.options));
3704
+ },
3705
+ getRowId: function getRowId(_, index, parent) {
3706
+ return "" + (parent ? [parent.id, index].join('.') : index);
3707
+ },
3708
+ getState: function getState() {
3709
+ return instance.options.state;
3710
+ },
3711
+ setState: function setState(updater) {
3712
+ instance.options.onStateChange == null ? void 0 : instance.options.onStateChange(updater);
3713
+ },
3714
+ getDefaultColumn: memo(function () {
3715
+ return [instance.options.defaultColumn];
3716
+ }, function (defaultColumn) {
3717
+ var _defaultColumn;
3718
+
3719
+ defaultColumn = (_defaultColumn = defaultColumn) != null ? _defaultColumn : {};
3720
+ return _extends({
3721
+ header: function header(props) {
3722
+ return props.header.column.id;
3723
+ },
3724
+ footer: function footer(props) {
3725
+ return props.header.column.id;
3726
+ },
3727
+ cell: function cell(_ref) {
3728
+ var _ref$value = _ref.value,
3729
+ value = _ref$value === void 0 ? '' : _ref$value;
3730
+ return typeof value === 'boolean' ? value.toString() : value;
3731
+ }
3732
+ }, features.reduce(function (obj, feature) {
3733
+ return Object.assign(obj, feature.getDefaultColumn == null ? void 0 : feature.getDefaultColumn());
3734
+ }, {}), defaultColumn);
3735
+ }, {
3736
+ debug: function debug() {
3737
+ var _instance$options$deb;
3738
+
3739
+ return (_instance$options$deb = instance.options.debugAll) != null ? _instance$options$deb : instance.options.debugColumns;
3740
+ },
3741
+ key: 'getDefaultColumn'
3742
+ }),
3743
+ getColumnDefs: function getColumnDefs() {
3744
+ return instance.options.columns;
3745
+ },
3746
+ createColumn: function createColumn(columnDef, depth, parent) {
3747
+ var _ref2, _columnDef$id;
3748
+
3749
+ var defaultColumn = instance.getDefaultColumn();
3750
+ var id = (_ref2 = (_columnDef$id = columnDef.id) != null ? _columnDef$id : columnDef.accessorKey) != null ? _ref2 : typeof columnDef.header === 'string' ? columnDef.header : undefined;
3751
+ var accessorFn;
3752
+
3753
+ if (columnDef.accessorFn) {
3754
+ accessorFn = columnDef.accessorFn;
3755
+ } else if (columnDef.accessorKey) {
3756
+ accessorFn = function accessorFn(originalRow) {
3757
+ return originalRow[columnDef.accessorKey];
3758
+ };
3759
+ }
3760
+
3761
+ if (!id) {
3762
+ {
3763
+ throw new Error(columnDef.accessorFn ? "Columns require an id when using an accessorFn" : "Columns require an id when using a non-string header");
3764
+ }
3765
+ }
3766
+
3767
+ var column = _extends({}, defaultColumnSizing, defaultColumn, columnDef, {
3768
+ id: "" + id,
3769
+ accessorFn: accessorFn,
3770
+ parent: parent,
3771
+ depth: depth,
3772
+ columnDef: columnDef,
3773
+ columns: [],
3774
+ getWidth: function getWidth() {
3775
+ return instance.getColumnWidth(column.id);
3776
+ },
3777
+ getFlatColumns: memo(function () {
3778
+ return [true];
3779
+ }, function () {
3780
+ var _column$columns;
3781
+
3782
+ return [column].concat((_column$columns = column.columns) == null ? void 0 : _column$columns.flatMap(function (d) {
3783
+ return d.getFlatColumns();
3784
+ }));
3785
+ }, {
3786
+ key: 'column.getFlatColumns',
3787
+ debug: function debug() {
3788
+ var _instance$options$deb2;
3789
+
3790
+ return (_instance$options$deb2 = instance.options.debugAll) != null ? _instance$options$deb2 : instance.options.debugColumns;
3791
+ }
3792
+ }),
3793
+ getLeafColumns: memo(function () {
3794
+ return [instance.getOrderColumnsFn()];
3795
+ }, function (orderColumns) {
3796
+ var _column$columns2;
3797
+
3798
+ if ((_column$columns2 = column.columns) != null && _column$columns2.length) {
3799
+ var leafColumns = column.columns.flatMap(function (column) {
3800
+ return column.getLeafColumns();
3801
+ });
3802
+ return orderColumns(leafColumns);
3803
+ }
3804
+
3805
+ return [column];
3806
+ }, {
3807
+ key: 'column.getLeafColumns',
3808
+ debug: function debug() {
3809
+ var _instance$options$deb3;
3810
+
3811
+ return (_instance$options$deb3 = instance.options.debugAll) != null ? _instance$options$deb3 : instance.options.debugColumns;
3812
+ }
3813
+ })
3814
+ });
3815
+
3816
+ column = features.reduce(function (obj, feature) {
3817
+ return Object.assign(obj, feature.createColumn == null ? void 0 : feature.createColumn(column, instance));
3818
+ }, column); // Yes, we have to convert instance to uknown, because we know more than the compiler here.
3819
+
3820
+ return column;
3821
+ },
3822
+ getAllColumns: memo(function () {
3823
+ return [instance.getColumnDefs()];
3824
+ }, function (columnDefs) {
3825
+ var recurseColumns = function recurseColumns(columnDefs, parent, depth) {
3826
+ if (depth === void 0) {
3827
+ depth = 0;
3828
+ }
3829
+
3830
+ return columnDefs.map(function (columnDef) {
3831
+ var column = instance.createColumn(columnDef, depth, parent);
3832
+ column.columns = columnDef.columns ? recurseColumns(columnDef.columns, column, depth + 1) : [];
3833
+ return column;
3834
+ });
3835
+ };
3836
+
3837
+ return recurseColumns(columnDefs);
3838
+ }, {
3839
+ key: 'getAllColumns',
3840
+ debug: function debug() {
3841
+ var _instance$options$deb4;
3842
+
3843
+ return (_instance$options$deb4 = instance.options.debugAll) != null ? _instance$options$deb4 : instance.options.debugColumns;
3844
+ }
3845
+ }),
3846
+ getAllFlatColumns: memo(function () {
3847
+ return [instance.getAllColumns()];
3848
+ }, function (allColumns) {
3849
+ return allColumns.flatMap(function (column) {
3850
+ return column.getFlatColumns();
3851
+ });
3852
+ }, {
3853
+ key: 'getAllFlatColumns',
3854
+ debug: function debug() {
3855
+ var _instance$options$deb5;
3856
+
3857
+ return (_instance$options$deb5 = instance.options.debugAll) != null ? _instance$options$deb5 : instance.options.debugColumns;
3858
+ }
3859
+ }),
3860
+ getAllFlatColumnsById: memo(function () {
3861
+ return [instance.getAllFlatColumns()];
3862
+ }, function (flatColumns) {
3863
+ return flatColumns.reduce(function (acc, column) {
3864
+ acc[column.id] = column;
3865
+ return acc;
3866
+ }, {});
3867
+ }, {
3868
+ key: 'getAllFlatColumnsById',
3869
+ debug: function debug() {
3870
+ var _instance$options$deb6;
3871
+
3872
+ return (_instance$options$deb6 = instance.options.debugAll) != null ? _instance$options$deb6 : instance.options.debugColumns;
3873
+ }
3874
+ }),
3875
+ getAllLeafColumns: memo(function () {
3876
+ return [instance.getAllColumns(), instance.getOrderColumnsFn()];
3877
+ }, function (allColumns, orderColumns) {
3878
+ var leafColumns = allColumns.flatMap(function (column) {
3879
+ return column.getLeafColumns();
3880
+ });
3881
+ return orderColumns(leafColumns);
3882
+ }, {
3883
+ key: 'getAllLeafColumns',
3884
+ debug: function debug() {
3885
+ var _instance$options$deb7;
3886
+
3887
+ return (_instance$options$deb7 = instance.options.debugAll) != null ? _instance$options$deb7 : instance.options.debugColumns;
3888
+ }
3889
+ }),
3890
+ getColumn: function getColumn(columnId) {
3891
+ var column = instance.getAllFlatColumnsById()[columnId];
3892
+
3893
+ if (!column) {
3894
+ {
3895
+ console.warn("[React Table] Column with id " + columnId + " does not exist.");
3896
+ }
3897
+
3898
+ throw new Error();
3899
+ }
3900
+
3901
+ return column;
3902
+ },
3903
+ getColumnWidth: function getColumnWidth(columnId) {
3904
+ var _column$minWidth, _ref3, _column$maxWidth;
3905
+
3906
+ var column = instance.getColumn(columnId);
3907
+
3908
+ if (!column) {
3909
+ throw new Error();
3910
+ }
3911
+
3912
+ var columnSize = instance.getState().columnSizing[column.id];
3913
+ return Math.min(Math.max((_column$minWidth = column.minWidth) != null ? _column$minWidth : defaultColumnSizing.minWidth, (_ref3 = columnSize != null ? columnSize : column.width) != null ? _ref3 : defaultColumnSizing.width), (_column$maxWidth = column.maxWidth) != null ? _column$maxWidth : defaultColumnSizing.maxWidth);
3914
+ },
3915
+ createCell: function createCell(row, column, value) {
3916
+ var cell = {
3917
+ id: row.id + "_" + column.id,
3918
+ rowId: row.id,
3919
+ columnId: column.id,
3920
+ row: row,
3921
+ column: column,
3922
+ value: value,
3923
+ getCellProps: function getCellProps(userProps) {
3924
+ return instance.getCellProps(row.id, column.id, userProps);
3925
+ },
3926
+ renderCell: function renderCell() {
3927
+ return flexRender(column.cell, {
3928
+ instance: instance,
3929
+ column: column,
3930
+ row: row,
3931
+ cell: cell,
3932
+ value: value
3933
+ });
3934
+ }
3935
+ };
3936
+ features.forEach(function (feature) {
3937
+ Object.assign(cell, feature.createCell == null ? void 0 : feature.createCell(cell, column, row, instance));
3938
+ }, {});
3939
+ return cell;
3940
+ },
3941
+ createRow: function createRow(id, original, rowIndex, depth, values) {
3942
+ var row = {
3943
+ id: id,
3944
+ index: rowIndex,
3945
+ original: original,
3946
+ depth: depth,
3947
+ values: values,
3948
+ subRows: [],
3949
+ leafRows: [],
3950
+ getRowProps: function getRowProps(userProps) {
3951
+ return instance.getRowProps(row.id, userProps);
3952
+ },
3953
+ getAllCells: undefined,
3954
+ getAllCellsByColumnId: undefined
3955
+ };
3956
+ row.getAllCells = memo(function () {
3957
+ return [instance.getAllLeafColumns()];
3958
+ }, function (leafColumns) {
3959
+ return leafColumns.map(function (column) {
3960
+ return instance.createCell(row, column, row.values[column.id]);
3961
+ });
3962
+ }, {
3963
+ key: 'row.getAllCells' ,
3964
+ debug: function debug() {
3965
+ var _instance$options$deb8;
3966
+
3967
+ return (_instance$options$deb8 = instance.options.debugAll) != null ? _instance$options$deb8 : instance.options.debugRows;
3968
+ }
3969
+ });
3970
+ row.getAllCellsByColumnId = memo(function () {
3971
+ return [row.getAllCells()];
3972
+ }, function (allCells) {
3973
+ return allCells.reduce(function (acc, cell) {
3974
+ acc[cell.columnId] = cell;
3975
+ return acc;
3976
+ }, {});
3977
+ }, {
3978
+ key: 'row.getAllCellsByColumnId',
3979
+ debug: function debug() {
3980
+ var _instance$options$deb9;
3981
+
3982
+ return (_instance$options$deb9 = instance.options.debugAll) != null ? _instance$options$deb9 : instance.options.debugRows;
3983
+ }
3984
+ });
3985
+
3986
+ for (var i = 0; i < features.length; i++) {
3987
+ var feature = features[i];
3988
+ Object.assign(row, feature.createRow == null ? void 0 : feature.createRow(row, instance));
3989
+ }
3990
+
3991
+ return row;
3992
+ },
3993
+ getCoreRowModel: memo(function () {
3994
+ return [instance.options.data];
3995
+ }, function (data) {
3996
+ // Access the row model using initial columns
3997
+ var rows = [];
3998
+ var flatRows = [];
3999
+ var rowsById = {};
4000
+ var leafColumns = instance.getAllLeafColumns();
4001
+
4002
+ var accessRow = function accessRow(originalRow, rowIndex, depth, parentRows, parent) {
4003
+ if (depth === void 0) {
4004
+ depth = 0;
4005
+ }
4006
+
4007
+ var id = instance.getRowId(originalRow, rowIndex, parent);
4008
+
4009
+ if (!id) {
4010
+ {
4011
+ throw new Error("getRowId expected an ID, but got " + id);
4012
+ }
4013
+ }
4014
+
4015
+ var values = {};
4016
+
4017
+ for (var i = 0; i < leafColumns.length; i++) {
4018
+ var _column = leafColumns[i];
4019
+
4020
+ if (_column && _column.accessorFn) {
4021
+ values[_column.id] = _column.accessorFn(originalRow, rowIndex);
4022
+ }
4023
+ } // Make the row
4024
+
4025
+
4026
+ var row = instance.createRow(id, originalRow, rowIndex, depth, values); // Push instance row into the parentRows array
4027
+
4028
+ parentRows.push(row); // Keep track of every row in a flat array
4029
+
4030
+ flatRows.push(row); // Also keep track of every row by its ID
4031
+
4032
+ rowsById[id] = row; // Get the original subrows
4033
+
4034
+ if (instance.options.getSubRows) {
4035
+ var originalSubRows = instance.options.getSubRows(originalRow, rowIndex); // Then recursively access them
4036
+
4037
+ if (originalSubRows != null && originalSubRows.length) {
4038
+ row.originalSubRows = originalSubRows;
4039
+ var subRows = [];
4040
+
4041
+ for (var _i = 0; _i < row.originalSubRows.length; _i++) {
4042
+ accessRow(row.originalSubRows[_i], _i, depth + 1, subRows, row);
4043
+ } // Keep the new subRows array on the row
4044
+
4045
+
4046
+ row.subRows = subRows;
4047
+ row.leafRows = flattenBy(subRows, function (d) {
4048
+ return d.leafRows;
4049
+ });
4050
+ }
4051
+ }
4052
+ };
4053
+
4054
+ for (var i = 0; i < data.length; i++) {
4055
+ accessRow(data[i], i, 0, rows);
4056
+ }
4057
+
4058
+ return {
4059
+ rows: rows,
4060
+ flatRows: flatRows,
4061
+ rowsById: rowsById
4062
+ };
4063
+ }, {
4064
+ key: 'getRowModel',
4065
+ debug: function debug() {
4066
+ var _instance$options$deb10;
4067
+
4068
+ return (_instance$options$deb10 = instance.options.debugAll) != null ? _instance$options$deb10 : instance.options.debugTable;
4069
+ },
4070
+ onChange: function onChange() {
4071
+ instance._notifyRowSelectionReset();
4072
+
4073
+ instance._notifyFiltersReset();
4074
+ }
4075
+ }),
4076
+ // The final calls start at the bottom of the model,
4077
+ // expanded rows, which then work their way up
4078
+ getRowModel: function getRowModel() {
4079
+ return instance.getPaginationRowModel();
4080
+ },
4081
+ getRow: function getRow(id) {
4082
+ var row = instance.getRowModel().rowsById[id];
4083
+
4084
+ if (!row) {
4085
+ {
4086
+ throw new Error("getRow expected an ID, but got " + id);
4087
+ }
4088
+ }
4089
+
4090
+ return row;
4091
+ },
4092
+ getCell: function getCell(rowId, columnId) {
4093
+ var row = instance.getRow(rowId);
4094
+
4095
+ if (!row) {
4096
+ {
4097
+ throw new Error("[React Table] could not find row with id " + rowId);
4098
+ }
4099
+ }
4100
+
4101
+ var cell = row.getAllCellsByColumnId()[columnId];
4102
+
4103
+ if (!cell) {
4104
+ {
4105
+ throw new Error("[React Table] could not find cell " + columnId + " in row " + rowId);
4106
+ }
4107
+ }
4108
+
4109
+ return cell;
4110
+ },
4111
+ getTableProps: function getTableProps(userProps) {
4112
+ return propGetter({
4113
+ role: 'table'
4114
+ }, userProps);
4115
+ },
4116
+ getTableBodyProps: function getTableBodyProps(userProps) {
4117
+ return propGetter({
4118
+ role: 'rowgroup'
4119
+ }, userProps);
4120
+ },
4121
+ getRowProps: function getRowProps(rowId, userProps) {
4122
+ var row = instance.getRow(rowId);
4123
+
4124
+ if (!row) {
4125
+ return;
4126
+ }
4127
+
4128
+ return propGetter({
4129
+ key: row.id,
4130
+ role: 'row'
4131
+ }, userProps);
4132
+ },
4133
+ getCellProps: function getCellProps(rowId, columnId, userProps) {
4134
+ var cell = instance.getCell(rowId, columnId);
4135
+
4136
+ if (!cell) {
4137
+ return;
4138
+ }
4139
+
4140
+ return propGetter({
4141
+ key: cell.id,
4142
+ role: 'gridcell'
4143
+ }, userProps);
4144
+ },
4145
+ getTableWidth: function getTableWidth() {
4146
+ var _instance$getHeaderGr, _instance$getHeaderGr2;
4147
+
4148
+ return (_instance$getHeaderGr = (_instance$getHeaderGr2 = instance.getHeaderGroups()[0]) == null ? void 0 : _instance$getHeaderGr2.headers.reduce(function (sum, header) {
4149
+ return sum + header.getWidth();
4150
+ }, 0)) != null ? _instance$getHeaderGr : 0;
4151
+ },
4152
+ getLeftTableWidth: function getLeftTableWidth() {
4153
+ var _instance$getLeftHead, _instance$getLeftHead2;
4154
+
4155
+ return (_instance$getLeftHead = (_instance$getLeftHead2 = instance.getLeftHeaderGroups()[0]) == null ? void 0 : _instance$getLeftHead2.headers.reduce(function (sum, header) {
4156
+ return sum + header.getWidth();
4157
+ }, 0)) != null ? _instance$getLeftHead : 0;
4158
+ },
4159
+ getCenterTableWidth: function getCenterTableWidth() {
4160
+ var _instance$getCenterHe, _instance$getCenterHe2;
4161
+
4162
+ return (_instance$getCenterHe = (_instance$getCenterHe2 = instance.getCenterHeaderGroups()[0]) == null ? void 0 : _instance$getCenterHe2.headers.reduce(function (sum, header) {
4163
+ return sum + header.getWidth();
4164
+ }, 0)) != null ? _instance$getCenterHe : 0;
4165
+ },
4166
+ getRightTableWidth: function getRightTableWidth() {
4167
+ var _instance$getRightHea, _instance$getRightHea2;
4168
+
4169
+ return (_instance$getRightHea = (_instance$getRightHea2 = instance.getRightHeaderGroups()[0]) == null ? void 0 : _instance$getRightHea2.headers.reduce(function (sum, header) {
4170
+ return sum + header.getWidth();
4171
+ }, 0)) != null ? _instance$getRightHea : 0;
4172
+ }
4173
+ });
4174
+
4175
+ instance = Object.assign(instance, finalInstance);
4176
+ return instance;
4177
+ }
4178
+
4179
+ function createTableFactory(opts) {
4180
+ return function () {
4181
+ return _createTable(undefined, undefined, opts);
4182
+ };
4183
+ }
4184
+ function createTable() {
4185
+ return _createTable();
4186
+ }
4187
+
4188
+ function _createTable(_, __, __options) {
4189
+ return {
4190
+ __options: __options || {},
4191
+ createColumns: function createColumns(columns) {
4192
+ return columns;
4193
+ },
4194
+ createDisplayColumn: function createDisplayColumn(column) {
4195
+ return column;
4196
+ },
4197
+ createGroup: function createGroup(column) {
4198
+ return column;
4199
+ },
4200
+ createDataColumn: function createDataColumn(accessor, column) {
4201
+ column = _extends({}, column, {
4202
+ id: column.id
4203
+ });
4204
+
4205
+ if (typeof accessor === 'string') {
4206
+ var _column$id;
4207
+
4208
+ return _extends({}, column, {
4209
+ id: (_column$id = column.id) != null ? _column$id : accessor,
4210
+ accessorKey: accessor
4211
+ });
4212
+ }
4213
+
4214
+ if (typeof accessor === 'function') {
4215
+ return _extends({}, column, {
4216
+ accessorFn: accessor
4217
+ });
4218
+ }
4219
+
4220
+ throw new Error('Invalid accessor');
4221
+ }
4222
+ };
4223
+ }
4224
+
4225
+ function columnFilterRowsFn(instance, rowModel) {
4226
+ var columnFilters = instance.getState().columnFilters;
4227
+ var newFilteredFlatRows = [];
4228
+ var newFilteredRowsById = {};
4229
+ var filterFromChildrenUp = instance.options.filterFromChildrenUp;
4230
+
4231
+ var filterRows = function filterRows(rowsToFilter, depth) {
4232
+ columnFilters.forEach(function (_ref) {
4233
+ var columnId = _ref.id,
4234
+ filterValue = _ref.value;
4235
+ // Find the columnFilters column
4236
+ var column = instance.getColumn(columnId);
4237
+
4238
+ if (!column) {
4239
+ {
4240
+ console.warn("React-Table: Could not find a column with id: " + columnId);
4241
+ }
4242
+
4243
+ throw new Error();
4244
+ }
4245
+
4246
+ if (depth === 0) {
4247
+ var preFilteredRows = [].concat(rowsToFilter);
4248
+
4249
+ column.getPreFilteredRows = function () {
4250
+ return preFilteredRows;
4251
+ };
4252
+ }
4253
+
4254
+ var filterFn = instance.getColumnFilterFn(column.id);
4255
+
4256
+ if (!filterFn) {
4257
+ {
4258
+ console.warn("Could not find a valid 'column.filterType' for column with the ID: " + column.id + ".");
4259
+ }
4260
+
4261
+ return;
4262
+ } // Pass the rows, id, filterValue and column to the filterFn
4263
+ // to get the filtered rows back
4264
+
4265
+
4266
+ rowsToFilter = filterFn(rowsToFilter, [columnId], filterValue);
4267
+ });
4268
+ return rowsToFilter;
4269
+ };
4270
+
4271
+ if (filterFromChildrenUp) {
4272
+ var _recurseFilterRows = function _recurseFilterRows(rowsToFilter, depth) {
4273
+ if (depth === void 0) {
4274
+ depth = 0;
4275
+ }
4276
+
4277
+ // Filter from children up
4278
+ rowsToFilter = rowsToFilter.filter(function (row) {
4279
+ var _row$subRows;
4280
+
4281
+ if (!((_row$subRows = row.subRows) != null && _row$subRows.length)) {
4282
+ return true;
4283
+ }
4284
+
4285
+ row.subRows = _recurseFilterRows(row.subRows, depth + 1);
4286
+ return row.subRows.length;
4287
+ });
4288
+ rowsToFilter = filterRows(rowsToFilter, depth); // Apply the filter to any subRows
4289
+
4290
+ rowsToFilter.forEach(function (row) {
4291
+ newFilteredFlatRows.push(row);
4292
+ newFilteredRowsById[row.id] = row;
4293
+ });
4294
+ return rowsToFilter;
4295
+ };
4296
+
4297
+ return {
4298
+ rows: _recurseFilterRows(rowModel.rows),
4299
+ flatRows: newFilteredFlatRows,
4300
+ rowsById: newFilteredRowsById
4301
+ };
4302
+ } // Filters top level and nested rows
4303
+
4304
+
4305
+ var recurseFilterRows = function recurseFilterRows(rowsToFilter, depth) {
4306
+ if (depth === void 0) {
4307
+ depth = 0;
4308
+ }
4309
+
4310
+ // Filter from parents downward
4311
+ rowsToFilter = filterRows(rowsToFilter, depth); // Apply the filter to any subRows
4312
+ // We technically could do this recursively in the above loop,
4313
+ // but that would severely hinder the API for the user, since they
4314
+ // would be required to do that recursion in some scenarios
4315
+
4316
+ rowsToFilter.forEach(function (row) {
4317
+ newFilteredFlatRows.push(row);
4318
+ newFilteredRowsById[row.id] = row;
4319
+
4320
+ if (!filterFromChildrenUp) {
4321
+ var _row$subRows2;
4322
+
4323
+ if (!((_row$subRows2 = row.subRows) != null && _row$subRows2.length)) {
4324
+ return;
4325
+ }
4326
+
4327
+ row.subRows = recurseFilterRows(row.subRows, depth + 1);
4328
+ }
4329
+ });
4330
+ return rowsToFilter;
4331
+ };
4332
+
4333
+ return {
4334
+ rows: recurseFilterRows(rowModel.rows),
4335
+ flatRows: newFilteredFlatRows,
4336
+ rowsById: newFilteredRowsById
4337
+ };
4338
+ }
4339
+
4340
+ function globalFilterRowsFn(instance, rowModel) {
4341
+ var globalFilter = instance.getState().globalFilter;
4342
+ var newFilteredFlatRows = [];
4343
+ var newFilteredRowsById = {};
4344
+ var filterFromChildrenUp = instance.options.filterFromChildrenUp;
4345
+ var filterFn = instance.getGlobalFilterFn();
4346
+
4347
+ if (!filterFn) {
4348
+ {
4349
+ console.warn("Could not find a valid 'globalFilterType'");
4350
+ }
4351
+
4352
+ return rowModel;
4353
+ }
4354
+
4355
+ var filterableColumns = instance.getAllLeafColumns().filter(function (column) {
4356
+ return column.getCanGlobalFilter();
4357
+ });
4358
+ var filterableColumnIds = filterableColumns.map(function (d) {
4359
+ return d.id;
4360
+ });
4361
+
4362
+ if (filterFromChildrenUp) {
4363
+ var _recurseFilterRows = function _recurseFilterRows(rowsToFilter, depth) {
4364
+
4365
+ // Filter from children up
4366
+ rowsToFilter = rowsToFilter.filter(function (row) {
4367
+ var _row$subRows;
4368
+
4369
+ if (!((_row$subRows = row.subRows) != null && _row$subRows.length)) {
4370
+ return true;
4371
+ }
4372
+
4373
+ row.subRows = _recurseFilterRows(row.subRows);
4374
+ return row.subRows.length;
4375
+ });
4376
+ rowsToFilter = filterFn(rowsToFilter, filterableColumnIds, globalFilter); // Apply the filter to any subRows
4377
+
4378
+ rowsToFilter.forEach(function (row) {
4379
+ newFilteredFlatRows.push(row);
4380
+ newFilteredRowsById[row.id] = row;
4381
+ });
4382
+ return rowsToFilter;
4383
+ };
4384
+
4385
+ return {
4386
+ rows: _recurseFilterRows(rowModel.rows),
4387
+ flatRows: newFilteredFlatRows,
4388
+ rowsById: newFilteredRowsById
4389
+ };
4390
+ } // Filters top level and nested rows
4391
+
4392
+
4393
+ var recurseFilterRows = function recurseFilterRows(rowsToFilter, depth) {
4394
+
4395
+ // Filter from parents downward
4396
+ rowsToFilter = filterFn(rowsToFilter, filterableColumnIds, globalFilter); // Apply the filter to any subRows
4397
+ // We technically could do this recursively in the above loop,
4398
+ // but that would severely hinder the API for the user, since they
4399
+ // would be required to do that recursion in some scenarios
4400
+
4401
+ rowsToFilter.forEach(function (row) {
4402
+ newFilteredFlatRows.push(row);
4403
+ newFilteredRowsById[row.id] = row;
4404
+
4405
+ if (!filterFromChildrenUp) {
4406
+ var _row$subRows2;
4407
+
4408
+ if (!((_row$subRows2 = row.subRows) != null && _row$subRows2.length)) {
4409
+ return;
4410
+ }
4411
+
4412
+ row.subRows = recurseFilterRows(row.subRows);
4413
+ }
4414
+ });
4415
+ return rowsToFilter;
4416
+ };
4417
+
4418
+ return {
4419
+ rows: recurseFilterRows(rowModel.rows),
4420
+ flatRows: newFilteredFlatRows,
4421
+ rowsById: newFilteredRowsById
4422
+ };
4423
+ }
4424
+
4425
+ function sortRowsFn(instance, rowModel) {
4426
+ var sortingState = instance.getState().sorting;
4427
+ var sortedFlatRows = []; // Filter out sortings that correspond to non existing columns
4428
+
4429
+ var availableSorting = sortingState.filter(function (sort) {
4430
+ return instance.getColumnCanSort(sort.id);
4431
+ });
4432
+ var columnInfoById = {};
4433
+ availableSorting.forEach(function (sortEntry) {
4434
+ var column = instance.getColumn(sortEntry.id);
4435
+ columnInfoById[sortEntry.id] = {
4436
+ sortUndefined: column.sortUndefined,
4437
+ invertSorting: column.invertSorting,
4438
+ sortingFn: instance.getColumnSortingFn(sortEntry.id)
4439
+ };
4440
+ });
4441
+
4442
+ var sortData = function sortData(rows) {
4443
+ // This will also perform a stable sorting using the row index
4444
+ // if needed.
4445
+ var sortedData = rows.slice();
4446
+ sortedData.sort(function (rowA, rowB) {
4447
+ for (var i = 0; i < availableSorting.length; i += 1) {
4448
+ var _sortEntry$desc;
4449
+
4450
+ var sortEntry = availableSorting[i];
4451
+ var columnInfo = columnInfoById[sortEntry.id];
4452
+ var isDesc = (_sortEntry$desc = sortEntry == null ? void 0 : sortEntry.desc) != null ? _sortEntry$desc : false;
4453
+
4454
+ if (columnInfo.sortUndefined) {
4455
+ var aValue = rowA.values[sortEntry.id];
4456
+ var bValue = rowB.values[sortEntry.id];
4457
+ var aUndefined = typeof aValue === 'undefined';
4458
+ var bUndefined = typeof bValue === 'undefined';
4459
+
4460
+ if (aUndefined || bUndefined) {
4461
+ return aUndefined && bUndefined ? 0 : aUndefined ? 1 : -1;
4462
+ }
4463
+ } // This function should always return in ascending order
4464
+
4465
+
4466
+ var sortInt = columnInfo.sortingFn(rowA, rowB, sortEntry.id);
4467
+
4468
+ if (sortInt !== 0) {
4469
+ if (isDesc) {
4470
+ sortInt *= -1;
4471
+ }
4472
+
4473
+ if (columnInfo.invertSorting) {
4474
+ sortInt *= -1;
4475
+ }
4476
+
4477
+ return sortInt;
4478
+ }
4479
+ }
4480
+
4481
+ return rowA.index - rowB.index;
4482
+ }); // If there are sub-rows, sort them
4483
+
4484
+ sortedData.forEach(function (row) {
4485
+ sortedFlatRows.push(row);
4486
+
4487
+ if (!row.subRows || row.subRows.length <= 1) {
4488
+ return;
4489
+ }
4490
+
4491
+ row.subRows = sortData(row.subRows);
4492
+ });
4493
+ return sortedData;
4494
+ };
4495
+
4496
+ return {
4497
+ rows: sortData(rowModel.rows),
4498
+ flatRows: sortedFlatRows,
4499
+ rowsById: rowModel.rowsById
4500
+ };
4501
+ }
4502
+
4503
+ function groupRowsFn(instance, sortedRowModel) {
4504
+ var groupingState = instance.getState().grouping; // Filter the grouping list down to columns that exist
4505
+
4506
+ var existingGrouping = groupingState.filter(function (columnId) {
4507
+ return instance.getColumn(columnId);
4508
+ }); // Find the columns that can or are aggregating
4509
+ // Uses each column to aggregate rows into a single value
4510
+
4511
+ var aggregateRowsToValues = function aggregateRowsToValues(leafRows, groupedRows, depth) {
4512
+ var values = {};
4513
+ instance.getAllLeafColumns().forEach(function (column) {
4514
+ // Don't aggregate columns that are in the grouping
4515
+ if (existingGrouping.includes(column.id)) {
4516
+ values[column.id] = groupedRows[0] ? groupedRows[0].values[column.id] : null;
4517
+ return;
4518
+ } // Aggregate the values
4519
+
4520
+
4521
+ var aggregateFn = instance.getColumnAggregationFn(column.id);
4522
+
4523
+ if (aggregateFn) {
4524
+ // Get the columnValues to aggregate
4525
+ var groupedValues = groupedRows.map(function (row) {
4526
+ return row.values[column.id];
4527
+ }); // Get the columnValues to aggregate
4528
+
4529
+ var leafValues = leafRows.map(function (row) {
4530
+ var columnValue = row.values[column.id];
4531
+
4532
+ if (!depth && column.aggregateValue) {
4533
+ columnValue = column.aggregateValue(columnValue);
4534
+ }
4535
+
4536
+ return columnValue;
4537
+ });
4538
+ values[column.id] = aggregateFn(leafValues, groupedValues);
4539
+ } else if (column.aggregationType) {
4540
+ console.info({
4541
+ column: column
4542
+ });
4543
+ throw new Error("React Table: Invalid column.aggregateType option for column listed above" );
4544
+ } else {
4545
+ values[column.id] = null;
4546
+ }
4547
+ });
4548
+ return values;
4549
+ };
4550
+
4551
+ var groupedFlatRows = [];
4552
+ var groupedRowsById = {}; // const onlyGroupedFlatRows: Row[] = [];
4553
+ // const onlyGroupedRowsById: Record<RowId, Row> = {};
4554
+ // const nonGroupedFlatRows: Row[] = [];
4555
+ // const nonGroupedRowsById: Record<RowId, Row> = {};
4556
+ // Recursively group the data
4557
+
4558
+ var groupUpRecursively = function groupUpRecursively(rows, depth, parentId) {
4559
+ if (depth === void 0) {
4560
+ depth = 0;
4561
+ }
4562
+
4563
+ // This is the last level, just return the rows
4564
+ if (depth === existingGrouping.length) {
4565
+ return rows;
4566
+ }
4567
+
4568
+ var columnId = existingGrouping[depth]; // Group the rows together for this level
4569
+
4570
+ var rowGroupsMap = groupBy(rows, columnId); // Peform aggregations for each group
4571
+
4572
+ var aggregatedGroupedRows = Array.from(rowGroupsMap.entries()).map(function (_ref, index) {
4573
+ var groupingValue = _ref[0],
4574
+ groupedRows = _ref[1];
4575
+ var id = columnId + ":" + groupingValue;
4576
+ id = parentId ? parentId + ">" + id : id; // First, Recurse to group sub rows before aggregation
4577
+
4578
+ var subRows = groupUpRecursively(groupedRows, depth + 1, id); // Flatten the leaf rows of the rows in this group
4579
+
4580
+ var leafRows = depth ? flattenBy(groupedRows, function (row) {
4581
+ return row.leafRows;
4582
+ }) : groupedRows;
4583
+ var values = aggregateRowsToValues(leafRows, groupedRows, depth);
4584
+ var row = instance.createRow(id, undefined, index, depth, values);
4585
+ Object.assign(row, {
4586
+ groupingColumnId: columnId,
4587
+ groupingValue: groupingValue,
4588
+ subRows: subRows,
4589
+ leafRows: leafRows
4590
+ });
4591
+ subRows.forEach(function (subRow) {
4592
+ groupedFlatRows.push(subRow);
4593
+ groupedRowsById[subRow.id] = subRow; // if (subRow.getIsGrouped?.()) {
4594
+ // onlyGroupedFlatRows.push(subRow);
4595
+ // onlyGroupedRowsById[subRow.id] = subRow;
4596
+ // } else {
4597
+ // nonGroupedFlatRows.push(subRow);
4598
+ // nonGroupedRowsById[subRow.id] = subRow;
4599
+ // }
4600
+ });
4601
+ return row;
4602
+ });
4603
+ return aggregatedGroupedRows;
4604
+ };
4605
+
4606
+ var groupedRows = groupUpRecursively(sortedRowModel.rows, 0, '');
4607
+ groupedRows.forEach(function (subRow) {
4608
+ groupedFlatRows.push(subRow);
4609
+ groupedRowsById[subRow.id] = subRow; // if (subRow.getIsGrouped?.()) {
4610
+ // onlyGroupedFlatRows.push(subRow);
4611
+ // onlyGroupedRowsById[subRow.id] = subRow;
4612
+ // } else {
4613
+ // nonGroupedFlatRows.push(subRow);
4614
+ // nonGroupedRowsById[subRow.id] = subRow;
4615
+ // }
4616
+ });
4617
+ return {
4618
+ rows: groupedRows,
4619
+ flatRows: groupedFlatRows,
4620
+ rowsById: groupedRowsById
4621
+ };
4622
+ }
4623
+
4624
+ function groupBy(rows, columnId) {
4625
+ var groupMap = new Map();
4626
+ return rows.reduce(function (map, row) {
4627
+ var resKey = "" + row.values[columnId];
4628
+ var previous = map.get(resKey);
4629
+
4630
+ if (!previous) {
4631
+ map.set(resKey, [row]);
4632
+ } else {
4633
+ map.set(resKey, [].concat(previous, [row]));
4634
+ }
4635
+
4636
+ return map;
4637
+ }, groupMap);
4638
+ }
4639
+
4640
+ function expandRowsFn(instance, sortedRowModel) {
4641
+ var expandedRows = [];
4642
+ var expandSubRows = instance.options.expandSubRows;
4643
+
4644
+ var handleRow = function handleRow(row) {
4645
+ var _row$subRows;
4646
+
4647
+ expandedRows.push(row);
4648
+
4649
+ if (expandSubRows && (_row$subRows = row.subRows) != null && _row$subRows.length && instance.getIsRowExpanded(row.id)) {
4650
+ row.subRows.forEach(handleRow);
4651
+ }
4652
+ };
4653
+
4654
+ sortedRowModel.rows.forEach(handleRow);
4655
+ return {
4656
+ rows: expandedRows,
4657
+ flatRows: sortedRowModel.flatRows,
4658
+ rowsById: sortedRowModel.rowsById
4659
+ };
4660
+ }
4661
+
4662
+ function paginateRowsFn(instance, rowModel) {
4663
+ var _instance$getState$pa = instance.getState().pagination,
4664
+ pageSize = _instance$getState$pa.pageSize,
4665
+ pageIndex = _instance$getState$pa.pageIndex;
4666
+ var rows = rowModel.rows,
4667
+ flatRows = rowModel.flatRows,
4668
+ rowsById = rowModel.rowsById;
4669
+ var pageStart = pageSize * pageIndex;
4670
+ var pageEnd = pageStart + pageSize;
4671
+ rows = rows.slice(pageStart, pageEnd);
4672
+
4673
+ if (!instance.options.paginateExpandedRows) {
4674
+ return expandRowsFn(instance, {
4675
+ rows: rows,
4676
+ flatRows: flatRows,
4677
+ rowsById: rowsById
4678
+ });
4679
+ }
4680
+
4681
+ return {
4682
+ rows: rows,
4683
+ flatRows: flatRows,
4684
+ rowsById: rowsById
4685
+ };
4686
+ }
4687
+
4688
+ exports.ColumnSizing = ColumnSizing;
4689
+ exports.Expanding = Expanding;
4690
+ exports.Filters = Filters;
4691
+ exports.Grouping = Grouping;
4692
+ exports.Headers = Headers;
4693
+ exports.Ordering = Ordering;
4694
+ exports.Pagination = Pagination;
4695
+ exports.Pinning = Pinning;
4696
+ exports.Please_use_the_create_table_column_utilities_to_define_columns = Please_use_the_create_table_column_utilities_to_define_columns;
4697
+ exports.RowSelection = RowSelection;
4698
+ exports.Sorting = Sorting;
4699
+ exports.Visibility = Visibility;
4700
+ exports.buildHeaderGroups = buildHeaderGroups;
4701
+ exports.columnFilterRowsFn = columnFilterRowsFn;
4702
+ exports.createTable = createTable;
4703
+ exports.createTableFactory = createTableFactory;
4704
+ exports.createTableInstance = createTableInstance;
4705
+ exports.defaultColumnSizing = defaultColumnSizing;
4706
+ exports.expandRowsFn = expandRowsFn;
4707
+ exports.flattenBy = flattenBy;
4708
+ exports.flexRender = flexRender;
4709
+ exports.functionalUpdate = functionalUpdate;
4710
+ exports.getDefaultColumn = getDefaultColumn;
4711
+ exports.globalFilterRowsFn = globalFilterRowsFn;
4712
+ exports.groupRowsFn = groupRowsFn;
4713
+ exports.isFunction = isFunction;
4714
+ exports.isRowSelected = isRowSelected;
4715
+ exports.makeStateUpdater = makeStateUpdater;
4716
+ exports.memo = memo;
4717
+ exports.noop = noop;
4718
+ exports.paginateRowsFn = paginateRowsFn;
4719
+ exports.passiveEventSupported = passiveEventSupported;
4720
+ exports.propGetter = propGetter;
4721
+ exports.selectRowsFn = selectRowsFn;
4722
+ exports.shouldAutoRemoveFilter = shouldAutoRemoveFilter;
4723
+ exports.sortRowsFn = sortRowsFn;
4724
+
4725
+ Object.defineProperty(exports, '__esModule', { value: true });
4726
+
4727
+ }));
4728
+ //# sourceMappingURL=index.development.js.map