@tanstack/react-table 8.0.0-alpha.83 → 8.0.0-alpha.86

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.
@@ -121,329 +121,457 @@
121
121
  };
122
122
  }
123
123
 
124
+ function createColumn(instance, columnDef, depth, parent) {
125
+ var _ref, _columnDef$id;
126
+
127
+ const defaultColumn = instance._getDefaultColumnDef();
128
+
129
+ columnDef = { ...defaultColumn,
130
+ ...columnDef
131
+ };
132
+ let id = (_ref = (_columnDef$id = columnDef.id) != null ? _columnDef$id : columnDef.accessorKey) != null ? _ref : typeof columnDef.header === 'string' ? columnDef.header : undefined;
133
+ let accessorFn;
134
+
135
+ if (columnDef.accessorFn) {
136
+ accessorFn = columnDef.accessorFn;
137
+ } else if (columnDef.accessorKey) {
138
+ accessorFn = originalRow => originalRow[columnDef.accessorKey];
139
+ }
140
+
141
+ if (!id) {
142
+ {
143
+ throw new Error(columnDef.accessorFn ? "Columns require an id when using an accessorFn" : "Columns require an id when using a non-string header");
144
+ }
145
+ }
146
+
147
+ let column = { ...columnDef,
148
+ id: "" + id,
149
+ accessorFn,
150
+ parent: parent,
151
+ depth,
152
+ columnDef,
153
+ columnDefType: columnDef.columnDefType,
154
+ columns: [],
155
+ getFlatColumns: memo(() => [true], () => {
156
+ var _column$columns;
157
+
158
+ return [column, ...((_column$columns = column.columns) == null ? void 0 : _column$columns.flatMap(d => d.getFlatColumns()))];
159
+ }, {
160
+ key: "development" === 'production' ,
161
+ debug: () => {
162
+ var _instance$options$deb;
163
+
164
+ return (_instance$options$deb = instance.options.debugAll) != null ? _instance$options$deb : instance.options.debugColumns;
165
+ }
166
+ }),
167
+ getLeafColumns: memo(() => [instance._getOrderColumnsFn()], orderColumns => {
168
+ var _column$columns2;
169
+
170
+ if ((_column$columns2 = column.columns) != null && _column$columns2.length) {
171
+ let leafColumns = column.columns.flatMap(column => column.getLeafColumns());
172
+ return orderColumns(leafColumns);
173
+ }
174
+
175
+ return [column];
176
+ }, {
177
+ key: "development" === 'production' ,
178
+ debug: () => {
179
+ var _instance$options$deb2;
180
+
181
+ return (_instance$options$deb2 = instance.options.debugAll) != null ? _instance$options$deb2 : instance.options.debugColumns;
182
+ }
183
+ })
184
+ };
185
+ column = instance._features.reduce((obj, feature) => {
186
+ return Object.assign(obj, feature.createColumn == null ? void 0 : feature.createColumn(column, instance));
187
+ }, column); // Yes, we have to convert instance to uknown, because we know more than the compiler here.
188
+
189
+ return column;
190
+ }
191
+
124
192
  //
125
- const Columns = {
193
+ function createHeader(instance, column, options) {
194
+ var _options$id;
195
+
196
+ const id = (_options$id = options.id) != null ? _options$id : column.id;
197
+ let header = {
198
+ id,
199
+ column,
200
+ index: options.index,
201
+ isPlaceholder: !!options.isPlaceholder,
202
+ placeholderId: options.placeholderId,
203
+ depth: options.depth,
204
+ subHeaders: [],
205
+ colSpan: 0,
206
+ rowSpan: 0,
207
+ headerGroup: null,
208
+ getLeafHeaders: () => {
209
+ const leafHeaders = [];
210
+
211
+ const recurseHeader = h => {
212
+ if (h.subHeaders && h.subHeaders.length) {
213
+ h.subHeaders.map(recurseHeader);
214
+ }
215
+
216
+ leafHeaders.push(h);
217
+ };
218
+
219
+ recurseHeader(header);
220
+ return leafHeaders;
221
+ },
222
+ renderHeader: () => column.columnDef.header ? instance._render(column.columnDef.header, {
223
+ instance,
224
+ header: header,
225
+ column
226
+ }) : null,
227
+ renderFooter: () => column.columnDef.footer ? instance._render(column.columnDef.footer, {
228
+ instance,
229
+ header: header,
230
+ column
231
+ }) : null
232
+ };
233
+
234
+ instance._features.forEach(feature => {
235
+ Object.assign(header, feature.createHeader == null ? void 0 : feature.createHeader(header, instance));
236
+ });
237
+
238
+ return header;
239
+ }
240
+
241
+ const Headers = {
126
242
  createInstance: instance => {
127
243
  return {
128
- getDefaultColumnDef: memo(() => [instance.options.defaultColumnDef], defaultColumn => {
129
- var _defaultColumn;
130
-
131
- defaultColumn = (_defaultColumn = defaultColumn) != null ? _defaultColumn : {};
132
- return {
133
- header: props => props.header.column.id,
134
- footer: props => props.header.column.id,
135
- cell: props => {
136
- var _props$getValue$toStr, _props$getValue$toStr2, _props$getValue;
137
-
138
- return (_props$getValue$toStr = (_props$getValue$toStr2 = (_props$getValue = props.getValue()).toString) == null ? void 0 : _props$getValue$toStr2.call(_props$getValue)) != null ? _props$getValue$toStr : null;
139
- },
140
- ...instance._features.reduce((obj, feature) => {
141
- return Object.assign(obj, feature.getDefaultColumnDef == null ? void 0 : feature.getDefaultColumnDef());
142
- }, {}),
143
- ...defaultColumn
144
- };
244
+ // Header Groups
245
+ getHeaderGroups: memo(() => [instance.getAllColumns(), instance.getVisibleLeafColumns(), instance.getState().columnPinning.left, instance.getState().columnPinning.right], (allColumns, leafColumns, left, right) => {
246
+ var _left$map$filter, _right$map$filter;
247
+
248
+ const leftColumns = (_left$map$filter = left == null ? void 0 : left.map(columnId => leafColumns.find(d => d.id === columnId)).filter(Boolean)) != null ? _left$map$filter : [];
249
+ const rightColumns = (_right$map$filter = right == null ? void 0 : right.map(columnId => leafColumns.find(d => d.id === columnId)).filter(Boolean)) != null ? _right$map$filter : [];
250
+ const centerColumns = leafColumns.filter(column => !(left != null && left.includes(column.id)) && !(right != null && right.includes(column.id)));
251
+ const headerGroups = buildHeaderGroups(allColumns, [...leftColumns, ...centerColumns, ...rightColumns], instance);
252
+ return headerGroups;
145
253
  }, {
254
+ key: 'getHeaderGroups',
146
255
  debug: () => {
147
256
  var _instance$options$deb;
148
257
 
149
- return (_instance$options$deb = instance.options.debugAll) != null ? _instance$options$deb : instance.options.debugColumns;
150
- },
151
- key: 'getDefaultColumnDef'
152
- }),
153
- getColumnDefs: () => instance.options.columns,
154
- createColumn: (columnDef, depth, parent) => {
155
- var _ref, _columnDef$id;
156
-
157
- const defaultColumnDef = instance.getDefaultColumnDef();
158
- columnDef = { ...defaultColumnDef,
159
- ...columnDef
160
- };
161
- let id = (_ref = (_columnDef$id = columnDef.id) != null ? _columnDef$id : columnDef.accessorKey) != null ? _ref : typeof columnDef.header === 'string' ? columnDef.header : undefined;
162
- let accessorFn;
163
-
164
- if (columnDef.accessorFn) {
165
- accessorFn = columnDef.accessorFn;
166
- } else if (columnDef.accessorKey) {
167
- accessorFn = originalRow => originalRow[columnDef.accessorKey];
258
+ return (_instance$options$deb = instance.options.debugAll) != null ? _instance$options$deb : instance.options.debugHeaders;
168
259
  }
260
+ }),
261
+ getCenterHeaderGroups: memo(() => [instance.getAllColumns(), instance.getVisibleLeafColumns(), instance.getState().columnPinning.left, instance.getState().columnPinning.right], (allColumns, leafColumns, left, right) => {
262
+ leafColumns = leafColumns.filter(column => !(left != null && left.includes(column.id)) && !(right != null && right.includes(column.id)));
263
+ return buildHeaderGroups(allColumns, leafColumns, instance, 'center');
264
+ }, {
265
+ key: 'getCenterHeaderGroups',
266
+ debug: () => {
267
+ var _instance$options$deb2;
169
268
 
170
- if (!id) {
171
- {
172
- throw new Error(columnDef.accessorFn ? "Columns require an id when using an accessorFn" : "Columns require an id when using a non-string header");
173
- }
269
+ return (_instance$options$deb2 = instance.options.debugAll) != null ? _instance$options$deb2 : instance.options.debugHeaders;
174
270
  }
271
+ }),
272
+ getLeftHeaderGroups: memo(() => [instance.getAllColumns(), instance.getVisibleLeafColumns(), instance.getState().columnPinning.left], (allColumns, leafColumns, left) => {
273
+ var _left$map$filter2;
175
274
 
176
- let column = { ...columnDef,
177
- id: "" + id,
178
- accessorFn,
179
- parent: parent,
180
- depth,
181
- columnDef,
182
- columnDefType: columnDef.columnDefType,
183
- columns: [],
184
- getFlatColumns: memo(() => [true], () => {
185
- var _column$columns;
186
-
187
- return [column, ...((_column$columns = column.columns) == null ? void 0 : _column$columns.flatMap(d => d.getFlatColumns()))];
188
- }, {
189
- key: "development" === 'production' ,
190
- debug: () => {
191
- var _instance$options$deb2;
192
-
193
- return (_instance$options$deb2 = instance.options.debugAll) != null ? _instance$options$deb2 : instance.options.debugColumns;
194
- }
195
- }),
196
- getLeafColumns: memo(() => [instance._getOrderColumnsFn()], orderColumns => {
197
- var _column$columns2;
198
-
199
- if ((_column$columns2 = column.columns) != null && _column$columns2.length) {
200
- let leafColumns = column.columns.flatMap(column => column.getLeafColumns());
201
- return orderColumns(leafColumns);
202
- }
203
-
204
- return [column];
205
- }, {
206
- key: "development" === 'production' ,
207
- debug: () => {
208
- var _instance$options$deb3;
209
-
210
- return (_instance$options$deb3 = instance.options.debugAll) != null ? _instance$options$deb3 : instance.options.debugColumns;
211
- }
212
- })
213
- };
214
- column = instance._features.reduce((obj, feature) => {
215
- return Object.assign(obj, feature.createColumn == null ? void 0 : feature.createColumn(column, instance));
216
- }, column); // Yes, we have to convert instance to uknown, because we know more than the compiler here.
217
-
218
- return column;
219
- },
220
- getAllColumns: memo(() => [instance.getColumnDefs()], columnDefs => {
221
- const recurseColumns = function (columnDefs, parent, depth) {
222
- if (depth === void 0) {
223
- depth = 0;
224
- }
275
+ const orderedLeafColumns = (_left$map$filter2 = left == null ? void 0 : left.map(columnId => leafColumns.find(d => d.id === columnId)).filter(Boolean)) != null ? _left$map$filter2 : [];
276
+ return buildHeaderGroups(allColumns, orderedLeafColumns, instance, 'left');
277
+ }, {
278
+ key: 'getLeftHeaderGroups',
279
+ debug: () => {
280
+ var _instance$options$deb3;
225
281
 
226
- return columnDefs.map(columnDef => {
227
- const column = instance.createColumn(columnDef, depth, parent);
228
- column.columns = columnDef.columns ? recurseColumns(columnDef.columns, column, depth + 1) : [];
229
- return column;
230
- });
231
- };
282
+ return (_instance$options$deb3 = instance.options.debugAll) != null ? _instance$options$deb3 : instance.options.debugHeaders;
283
+ }
284
+ }),
285
+ getRightHeaderGroups: memo(() => [instance.getAllColumns(), instance.getVisibleLeafColumns(), instance.getState().columnPinning.right], (allColumns, leafColumns, right) => {
286
+ var _right$map$filter2;
232
287
 
233
- return recurseColumns(columnDefs);
288
+ const orderedLeafColumns = (_right$map$filter2 = right == null ? void 0 : right.map(columnId => leafColumns.find(d => d.id === columnId)).filter(Boolean)) != null ? _right$map$filter2 : [];
289
+ return buildHeaderGroups(allColumns, orderedLeafColumns, instance, 'right');
234
290
  }, {
235
- key: 'getAllColumns',
291
+ key: 'getRightHeaderGroups',
236
292
  debug: () => {
237
293
  var _instance$options$deb4;
238
294
 
239
- return (_instance$options$deb4 = instance.options.debugAll) != null ? _instance$options$deb4 : instance.options.debugColumns;
295
+ return (_instance$options$deb4 = instance.options.debugAll) != null ? _instance$options$deb4 : instance.options.debugHeaders;
240
296
  }
241
297
  }),
242
- getAllFlatColumns: memo(() => [instance.getAllColumns()], allColumns => {
243
- return allColumns.flatMap(column => {
244
- return column.getFlatColumns();
245
- });
298
+ // Footer Groups
299
+ getFooterGroups: memo(() => [instance.getHeaderGroups()], headerGroups => {
300
+ return [...headerGroups].reverse();
246
301
  }, {
247
- key: 'getAllFlatColumns',
302
+ key: 'getFooterGroups',
248
303
  debug: () => {
249
304
  var _instance$options$deb5;
250
305
 
251
- return (_instance$options$deb5 = instance.options.debugAll) != null ? _instance$options$deb5 : instance.options.debugColumns;
306
+ return (_instance$options$deb5 = instance.options.debugAll) != null ? _instance$options$deb5 : instance.options.debugHeaders;
252
307
  }
253
308
  }),
254
- getAllFlatColumnsById: memo(() => [instance.getAllFlatColumns()], flatColumns => {
255
- return flatColumns.reduce((acc, column) => {
256
- acc[column.id] = column;
257
- return acc;
258
- }, {});
309
+ getLeftFooterGroups: memo(() => [instance.getLeftHeaderGroups()], headerGroups => {
310
+ return [...headerGroups].reverse();
259
311
  }, {
260
- key: 'getAllFlatColumnsById',
312
+ key: 'getLeftFooterGroups',
261
313
  debug: () => {
262
314
  var _instance$options$deb6;
263
315
 
264
- return (_instance$options$deb6 = instance.options.debugAll) != null ? _instance$options$deb6 : instance.options.debugColumns;
316
+ return (_instance$options$deb6 = instance.options.debugAll) != null ? _instance$options$deb6 : instance.options.debugHeaders;
265
317
  }
266
318
  }),
267
- getAllLeafColumns: memo(() => [instance.getAllColumns(), instance._getOrderColumnsFn()], (allColumns, orderColumns) => {
268
- let leafColumns = allColumns.flatMap(column => column.getLeafColumns());
269
- return orderColumns(leafColumns);
319
+ getCenterFooterGroups: memo(() => [instance.getCenterHeaderGroups()], headerGroups => {
320
+ return [...headerGroups].reverse();
270
321
  }, {
271
- key: 'getAllLeafColumns',
322
+ key: 'getCenterFooterGroups',
272
323
  debug: () => {
273
324
  var _instance$options$deb7;
274
325
 
275
- return (_instance$options$deb7 = instance.options.debugAll) != null ? _instance$options$deb7 : instance.options.debugColumns;
326
+ return (_instance$options$deb7 = instance.options.debugAll) != null ? _instance$options$deb7 : instance.options.debugHeaders;
276
327
  }
277
328
  }),
278
- getColumn: columnId => {
279
- const column = instance.getAllFlatColumnsById()[columnId];
280
-
281
- if (!column) {
282
- {
283
- console.warn("[Table] Column with id " + columnId + " does not exist.");
284
- }
329
+ getRightFooterGroups: memo(() => [instance.getRightHeaderGroups()], headerGroups => {
330
+ return [...headerGroups].reverse();
331
+ }, {
332
+ key: 'getRightFooterGroups',
333
+ debug: () => {
334
+ var _instance$options$deb8;
285
335
 
286
- throw new Error();
336
+ return (_instance$options$deb8 = instance.options.debugAll) != null ? _instance$options$deb8 : instance.options.debugHeaders;
287
337
  }
338
+ }),
339
+ // Flat Headers
340
+ getFlatHeaders: memo(() => [instance.getHeaderGroups()], headerGroups => {
341
+ return headerGroups.map(headerGroup => {
342
+ return headerGroup.headers;
343
+ }).flat();
344
+ }, {
345
+ key: 'getFlatHeaders',
346
+ debug: () => {
347
+ var _instance$options$deb9;
288
348
 
289
- return column;
290
- }
291
- };
292
- }
293
- };
294
-
295
- //
296
- const Rows = {
297
- // createRow: <TGenerics extends TableGenerics>(
298
- // row: Row<TGenerics>,
299
- // instance: TableInstance<TGenerics>
300
- // ): CellsRow<TGenerics> => {
301
- // return {}
302
- // },
303
- createInstance: instance => {
304
- return {
305
- getRowId: (row, index, parent) => {
306
- var _instance$options$get;
307
-
308
- return (_instance$options$get = instance.options.getRowId == null ? void 0 : instance.options.getRowId(row, index, parent)) != null ? _instance$options$get : "" + (parent ? [parent.id, index].join('.') : index);
309
- },
310
- createRow: (id, original, rowIndex, depth, subRows) => {
311
- let row = {
312
- id,
313
- index: rowIndex,
314
- original,
315
- depth,
316
- valuesCache: {},
317
- getValue: columnId => {
318
- if (row.valuesCache.hasOwnProperty(columnId)) {
319
- return row.valuesCache[columnId];
320
- }
321
-
322
- const column = instance.getColumn(columnId);
323
-
324
- if (!column.accessorFn) {
325
- return undefined;
326
- }
327
-
328
- row.valuesCache[columnId] = column.accessorFn(row.original, rowIndex);
329
- return row.valuesCache[columnId];
330
- },
331
- subRows: subRows != null ? subRows : [],
332
- getLeafRows: () => flattenBy(row.subRows, d => d.subRows)
333
- };
334
-
335
- for (let i = 0; i < instance._features.length; i++) {
336
- const feature = instance._features[i];
337
- Object.assign(row, feature == null ? void 0 : feature.createRow == null ? void 0 : feature.createRow(row, instance));
349
+ return (_instance$options$deb9 = instance.options.debugAll) != null ? _instance$options$deb9 : instance.options.debugHeaders;
338
350
  }
351
+ }),
352
+ getLeftFlatHeaders: memo(() => [instance.getLeftHeaderGroups()], left => {
353
+ return left.map(headerGroup => {
354
+ return headerGroup.headers;
355
+ }).flat();
356
+ }, {
357
+ key: 'getLeftFlatHeaders',
358
+ debug: () => {
359
+ var _instance$options$deb10;
339
360
 
340
- return row;
341
- },
342
- getCoreRowModel: () => {
343
- if (!instance._getCoreRowModel) {
344
- instance._getCoreRowModel = instance.options.getCoreRowModel(instance);
361
+ return (_instance$options$deb10 = instance.options.debugAll) != null ? _instance$options$deb10 : instance.options.debugHeaders;
345
362
  }
363
+ }),
364
+ getCenterFlatHeaders: memo(() => [instance.getCenterHeaderGroups()], left => {
365
+ return left.map(headerGroup => {
366
+ return headerGroup.headers;
367
+ }).flat();
368
+ }, {
369
+ key: 'getCenterFlatHeaders',
370
+ debug: () => {
371
+ var _instance$options$deb11;
346
372
 
347
- return instance._getCoreRowModel();
348
- },
349
- // The final calls start at the bottom of the model,
350
- // expanded rows, which then work their way up
351
- getRowModel: () => {
352
- return instance.getPaginationRowModel();
353
- },
354
- getRow: id => {
355
- const row = instance.getRowModel().rowsById[id];
356
-
357
- if (!row) {
358
- {
359
- throw new Error("getRow expected an ID, but got " + id);
360
- }
373
+ return (_instance$options$deb11 = instance.options.debugAll) != null ? _instance$options$deb11 : instance.options.debugHeaders;
361
374
  }
375
+ }),
376
+ getRightFlatHeaders: memo(() => [instance.getRightHeaderGroups()], left => {
377
+ return left.map(headerGroup => {
378
+ return headerGroup.headers;
379
+ }).flat();
380
+ }, {
381
+ key: 'getRightFlatHeaders',
382
+ debug: () => {
383
+ var _instance$options$deb12;
362
384
 
363
- return row;
364
- }
365
- };
366
- }
367
- };
385
+ return (_instance$options$deb12 = instance.options.debugAll) != null ? _instance$options$deb12 : instance.options.debugHeaders;
386
+ }
387
+ }),
388
+ // Leaf Headers
389
+ getCenterLeafHeaders: memo(() => [instance.getCenterFlatHeaders()], flatHeaders => {
390
+ return flatHeaders.filter(header => {
391
+ var _header$subHeaders;
368
392
 
369
- //
370
- const Cells = {
371
- createRow: (row, instance) => {
372
- return {
373
- getAllCells: memo(() => [instance.getAllLeafColumns()], leafColumns => {
374
- return leafColumns.map(column => {
375
- return instance.createCell(row, column, column.id);
393
+ return !((_header$subHeaders = header.subHeaders) != null && _header$subHeaders.length);
376
394
  });
377
395
  }, {
378
- key: 'row.getAllCells',
396
+ key: 'getCenterLeafHeaders',
379
397
  debug: () => {
380
- var _instance$options$deb;
398
+ var _instance$options$deb13;
381
399
 
382
- return (_instance$options$deb = instance.options.debugAll) != null ? _instance$options$deb : instance.options.debugRows;
400
+ return (_instance$options$deb13 = instance.options.debugAll) != null ? _instance$options$deb13 : instance.options.debugHeaders;
383
401
  }
384
402
  }),
385
- getAllCellsByColumnId: memo(() => [row.getAllCells()], allCells => {
386
- return allCells.reduce((acc, cell) => {
387
- acc[cell.columnId] = cell;
388
- return acc;
389
- }, {});
403
+ getLeftLeafHeaders: memo(() => [instance.getLeftFlatHeaders()], flatHeaders => {
404
+ return flatHeaders.filter(header => {
405
+ var _header$subHeaders2;
406
+
407
+ return !((_header$subHeaders2 = header.subHeaders) != null && _header$subHeaders2.length);
408
+ });
390
409
  }, {
391
- key: "development" === 'production' ,
410
+ key: 'getLeftLeafHeaders',
392
411
  debug: () => {
393
- var _instance$options$deb2;
412
+ var _instance$options$deb14;
394
413
 
395
- return (_instance$options$deb2 = instance.options.debugAll) != null ? _instance$options$deb2 : instance.options.debugRows;
414
+ return (_instance$options$deb14 = instance.options.debugAll) != null ? _instance$options$deb14 : instance.options.debugHeaders;
396
415
  }
397
- })
398
- };
399
- },
400
- createInstance: instance => {
401
- return {
402
- createCell: (row, column, columnId) => {
403
- const cell = {
404
- id: row.id + "_" + column.id,
405
- rowId: row.id,
406
- columnId,
407
- row,
408
- column,
409
- getValue: () => row.getValue(columnId),
410
- renderCell: () => column.columnDef.cell ? instance._render(column.columnDef.cell, {
411
- instance,
412
- column,
413
- row,
414
- cell: cell,
415
- getValue: cell.getValue
416
- }) : null
417
- };
418
-
419
- instance._features.forEach(feature => {
420
- Object.assign(cell, feature.createCell == null ? void 0 : feature.createCell(cell, column, row, instance));
421
- }, {});
416
+ }),
417
+ getRightLeafHeaders: memo(() => [instance.getRightFlatHeaders()], flatHeaders => {
418
+ return flatHeaders.filter(header => {
419
+ var _header$subHeaders3;
422
420
 
423
- return cell;
424
- },
425
- getCell: (rowId, columnId) => {
426
- const row = instance.getRow(rowId);
421
+ return !((_header$subHeaders3 = header.subHeaders) != null && _header$subHeaders3.length);
422
+ });
423
+ }, {
424
+ key: 'getRightLeafHeaders',
425
+ debug: () => {
426
+ var _instance$options$deb15;
427
427
 
428
- if (!row) {
429
- {
430
- throw new Error("[Table] could not find row with id " + rowId);
431
- }
428
+ return (_instance$options$deb15 = instance.options.debugAll) != null ? _instance$options$deb15 : instance.options.debugHeaders;
432
429
  }
430
+ }),
431
+ getLeafHeaders: memo(() => [instance.getLeftHeaderGroups(), instance.getCenterHeaderGroups(), instance.getRightHeaderGroups()], (left, center, right) => {
432
+ var _left$0$headers, _left$, _center$0$headers, _center$, _right$0$headers, _right$;
433
433
 
434
- const cell = row.getAllCellsByColumnId()[columnId];
434
+ return [...((_left$0$headers = (_left$ = left[0]) == null ? void 0 : _left$.headers) != null ? _left$0$headers : []), ...((_center$0$headers = (_center$ = center[0]) == null ? void 0 : _center$.headers) != null ? _center$0$headers : []), ...((_right$0$headers = (_right$ = right[0]) == null ? void 0 : _right$.headers) != null ? _right$0$headers : [])].map(header => {
435
+ return header.getLeafHeaders();
436
+ }).flat();
437
+ }, {
438
+ key: 'getLeafHeaders',
439
+ debug: () => {
440
+ var _instance$options$deb16;
435
441
 
436
- if (!cell) {
437
- {
438
- throw new Error("[Table] could not find cell " + columnId + " in row " + rowId);
439
- }
442
+ return (_instance$options$deb16 = instance.options.debugAll) != null ? _instance$options$deb16 : instance.options.debugHeaders;
440
443
  }
441
-
442
- return cell;
443
- }
444
+ })
444
445
  };
445
446
  }
446
447
  };
448
+ function buildHeaderGroups(allColumns, columnsToGroup, instance, headerFamily) {
449
+ var _headerGroups$0$heade, _headerGroups$;
450
+
451
+ // Find the max depth of the columns:
452
+ // build the leaf column row
453
+ // build each buffer row going up
454
+ // placeholder for non-existent level
455
+ // real column for existing level
456
+ let maxDepth = 0;
457
+
458
+ const findMaxDepth = function (columns, depth) {
459
+ if (depth === void 0) {
460
+ depth = 1;
461
+ }
462
+
463
+ maxDepth = Math.max(maxDepth, depth);
464
+ columns.filter(column => column.getIsVisible()).forEach(column => {
465
+ var _column$columns;
466
+
467
+ if ((_column$columns = column.columns) != null && _column$columns.length) {
468
+ findMaxDepth(column.columns, depth + 1);
469
+ }
470
+ }, 0);
471
+ };
472
+
473
+ findMaxDepth(allColumns);
474
+ let headerGroups = [];
475
+
476
+ const createHeaderGroup = (headersToGroup, depth) => {
477
+ // The header group we are creating
478
+ const headerGroup = {
479
+ depth,
480
+ id: [headerFamily, "" + depth].filter(Boolean).join('_'),
481
+ headers: []
482
+ }; // The parent columns we're going to scan next
483
+
484
+ const pendingParentHeaders = []; // Scan each column for parents
485
+
486
+ headersToGroup.forEach(headerToGroup => {
487
+ // What is the latest (last) parent column?
488
+ const latestPendingParentHeader = [...pendingParentHeaders].reverse()[0];
489
+ const isLeafHeader = headerToGroup.column.depth === headerGroup.depth;
490
+ let column;
491
+ let isPlaceholder = false;
492
+
493
+ if (isLeafHeader && headerToGroup.column.parent) {
494
+ // The parent header is new
495
+ column = headerToGroup.column.parent;
496
+ } else {
497
+ // The parent header is repeated
498
+ column = headerToGroup.column;
499
+ isPlaceholder = true;
500
+ }
501
+
502
+ if ((latestPendingParentHeader == null ? void 0 : latestPendingParentHeader.column) === column) {
503
+ // This column is repeated. Add it as a sub header to the next batch
504
+ latestPendingParentHeader.subHeaders.push(headerToGroup);
505
+ } else {
506
+ // This is a new header. Let's create it
507
+ const header = createHeader(instance, column, {
508
+ id: [headerFamily, depth, column.id, headerToGroup == null ? void 0 : headerToGroup.id].filter(Boolean).join('_'),
509
+ isPlaceholder,
510
+ placeholderId: isPlaceholder ? "" + pendingParentHeaders.filter(d => d.column === column).length : undefined,
511
+ depth,
512
+ index: pendingParentHeaders.length
513
+ }); // Add the headerToGroup as a subHeader of the new header
514
+
515
+ header.subHeaders.push(headerToGroup); // Add the new header to the pendingParentHeaders to get grouped
516
+ // in the next batch
517
+
518
+ pendingParentHeaders.push(header);
519
+ }
520
+
521
+ headerGroup.headers.push(headerToGroup);
522
+ headerToGroup.headerGroup = headerGroup;
523
+ });
524
+ headerGroups.push(headerGroup);
525
+
526
+ if (depth > 0) {
527
+ createHeaderGroup(pendingParentHeaders, depth - 1);
528
+ }
529
+ };
530
+
531
+ const bottomHeaders = columnsToGroup.map((column, index) => createHeader(instance, column, {
532
+ depth: maxDepth,
533
+ index
534
+ }));
535
+ createHeaderGroup(bottomHeaders, maxDepth - 1);
536
+ headerGroups.reverse(); // headerGroups = headerGroups.filter(headerGroup => {
537
+ // return !headerGroup.headers.every(header => header.isPlaceholder)
538
+ // })
539
+
540
+ const recurseHeadersForSpans = headers => {
541
+ const filteredHeaders = headers.filter(header => header.column.getIsVisible());
542
+ return filteredHeaders.map(header => {
543
+ let colSpan = 0;
544
+ let rowSpan = 0;
545
+ let childRowSpans = [0];
546
+
547
+ if (header.subHeaders && header.subHeaders.length) {
548
+ childRowSpans = [];
549
+ recurseHeadersForSpans(header.subHeaders).forEach(_ref => {
550
+ let {
551
+ colSpan: childColSpan,
552
+ rowSpan: childRowSpan
553
+ } = _ref;
554
+ colSpan += childColSpan;
555
+ childRowSpans.push(childRowSpan);
556
+ });
557
+ } else {
558
+ colSpan = 1;
559
+ }
560
+
561
+ const minChildRowSpan = Math.min(...childRowSpans);
562
+ rowSpan = rowSpan + minChildRowSpan;
563
+ header.colSpan = colSpan;
564
+ header.rowSpan = rowSpan;
565
+ return {
566
+ colSpan,
567
+ rowSpan
568
+ };
569
+ });
570
+ };
571
+
572
+ recurseHeadersForSpans((_headerGroups$0$heade = (_headerGroups$ = headerGroups[0]) == null ? void 0 : _headerGroups$.headers) != null ? _headerGroups$0$heade : []);
573
+ return headerGroups;
574
+ }
447
575
 
448
576
  //
449
577
  const defaultColumnSizing = {
@@ -721,7 +849,6 @@
721
849
  return {
722
850
  onExpandedChange: makeStateUpdater('expanded', instance),
723
851
  autoResetExpanded: true,
724
- expandSubRows: true,
725
852
  paginateExpandedRows: true
726
853
  };
727
854
  },
@@ -990,7 +1117,7 @@
990
1117
  getColumnCanGlobalFilter: column => {
991
1118
  var _instance$getCoreRowM, _instance$getCoreRowM2;
992
1119
 
993
- const value = (_instance$getCoreRowM = instance.getCoreRowModel().flatRows[0]) == null ? void 0 : (_instance$getCoreRowM2 = _instance$getCoreRowM.getAllCellsByColumnId()[column.id]) == null ? void 0 : _instance$getCoreRowM2.getValue();
1120
+ const value = (_instance$getCoreRowM = instance.getCoreRowModel().flatRows[0]) == null ? void 0 : (_instance$getCoreRowM2 = _instance$getCoreRowM._getAllCellsByColumnId()[column.id]) == null ? void 0 : _instance$getCoreRowM2.getValue();
994
1121
  return typeof value === 'string';
995
1122
  }
996
1123
  };
@@ -1118,8 +1245,7 @@
1118
1245
  createRow: (row, instance) => {
1119
1246
  return {
1120
1247
  columnFilters: {},
1121
- columnFiltersMeta: {},
1122
- subRowsByFacetId: {}
1248
+ columnFiltersMeta: {}
1123
1249
  };
1124
1250
  },
1125
1251
  createInstance: instance => {
@@ -1210,53 +1336,42 @@
1210
1336
  return (filterFn && filterFn.autoRemove ? filterFn.autoRemove(value, column) : false) || typeof value === 'undefined' || typeof value === 'string' && !value;
1211
1337
  }
1212
1338
 
1213
- const aggregationFns = {
1214
- sum,
1215
- min,
1216
- max,
1217
- extent,
1218
- mean,
1219
- median,
1220
- unique,
1221
- uniqueCount,
1222
- count
1223
- };
1224
-
1225
- function sum(_getLeafValues, getChildValues) {
1339
+ const sum = (columnId, _leafRows, childRows) => {
1226
1340
  // It's faster to just add the aggregations together instead of
1227
1341
  // process leaf nodes individually
1228
- return getChildValues().reduce((sum, next) => sum + (typeof next === 'number' ? next : 0), 0);
1229
- }
1342
+ return childRows.reduce((sum, next) => sum + (typeof next === 'number' ? next : 0), 0);
1343
+ };
1230
1344
 
1231
- function min(_getLeafValues, getChildValues) {
1345
+ const min = (columnId, _leafRows, childRows) => {
1232
1346
  let min;
1347
+ childRows.forEach(row => {
1348
+ const value = row.getValue(columnId);
1233
1349
 
1234
- for (const value of getChildValues()) {
1235
1350
  if (value != null && (min > value || min === undefined && value >= value)) {
1236
1351
  min = value;
1237
1352
  }
1238
- }
1239
-
1353
+ });
1240
1354
  return min;
1241
- }
1355
+ };
1242
1356
 
1243
- function max(_getLeafValues, getChildValues) {
1357
+ const max = (columnId, _leafRows, childRows) => {
1244
1358
  let max;
1359
+ childRows.forEach(row => {
1360
+ const value = row.getValue(columnId);
1245
1361
 
1246
- for (const value of getChildValues()) {
1247
1362
  if (value != null && (max < value || max === undefined && value >= value)) {
1248
1363
  max = value;
1249
1364
  }
1250
- }
1251
-
1365
+ });
1252
1366
  return max;
1253
- }
1367
+ };
1254
1368
 
1255
- function extent(_getLeafValues, getChildValues) {
1369
+ const extent = (columnId, _leafRows, childRows) => {
1256
1370
  let min;
1257
1371
  let max;
1372
+ childRows.forEach(row => {
1373
+ const value = row.getValue(columnId);
1258
1374
 
1259
- for (const value of getChildValues()) {
1260
1375
  if (value != null) {
1261
1376
  if (min === undefined) {
1262
1377
  if (value >= value) min = max = value;
@@ -1265,54 +1380,65 @@
1265
1380
  if (max < value) max = value;
1266
1381
  }
1267
1382
  }
1268
- }
1269
-
1383
+ });
1270
1384
  return [min, max];
1271
- }
1385
+ };
1272
1386
 
1273
- function mean(getLeafValues) {
1387
+ const mean = (columnId, leafRows) => {
1274
1388
  let count = 0;
1275
1389
  let sum = 0;
1390
+ leafRows.forEach(row => {
1391
+ let value = row.getValue(columnId);
1276
1392
 
1277
- for (let value of getLeafValues()) {
1278
1393
  if (value != null && (value = +value) >= value) {
1279
1394
  ++count, sum += value;
1280
1395
  }
1281
- }
1282
-
1396
+ });
1283
1397
  if (count) return sum / count;
1284
1398
  return;
1285
- }
1286
-
1287
- function median(getLeafValues) {
1288
- const leafValues = getLeafValues();
1399
+ };
1289
1400
 
1290
- if (!leafValues.length) {
1401
+ const median = (columnId, leafRows) => {
1402
+ if (!leafRows.length) {
1291
1403
  return;
1292
1404
  }
1293
1405
 
1294
1406
  let min = 0;
1295
1407
  let max = 0;
1296
- leafValues.forEach(value => {
1408
+ leafRows.forEach(row => {
1409
+ let value = row.getValue(columnId);
1410
+
1297
1411
  if (typeof value === 'number') {
1298
1412
  min = Math.min(min, value);
1299
1413
  max = Math.max(max, value);
1300
1414
  }
1301
1415
  });
1302
1416
  return (min + max) / 2;
1303
- }
1417
+ };
1304
1418
 
1305
- function unique(getLeafValues) {
1306
- return Array.from(new Set(getLeafValues()).values());
1307
- }
1419
+ const unique = (columnId, leafRows) => {
1420
+ return Array.from(new Set(leafRows.map(d => d.getValue(columnId))).values());
1421
+ };
1308
1422
 
1309
- function uniqueCount(getLeafValues) {
1310
- return new Set(getLeafValues()).size;
1311
- }
1423
+ const uniqueCount = (columnId, leafRows) => {
1424
+ return new Set(leafRows.map(d => d.getValue(columnId))).size;
1425
+ };
1312
1426
 
1313
- function count(getLeafValues) {
1314
- return getLeafValues().length;
1315
- }
1427
+ const count = (_columnId, leafRows) => {
1428
+ return leafRows.length;
1429
+ };
1430
+
1431
+ const aggregationFns = {
1432
+ sum,
1433
+ min,
1434
+ max,
1435
+ extent,
1436
+ mean,
1437
+ median,
1438
+ unique,
1439
+ uniqueCount,
1440
+ count
1441
+ };
1316
1442
 
1317
1443
  //
1318
1444
  const Grouping = {
@@ -1367,7 +1493,7 @@
1367
1493
  column.toggleGrouping();
1368
1494
  };
1369
1495
  },
1370
- getColumnAutoAggregationFn: () => {
1496
+ getAutoAggregationFn: () => {
1371
1497
  const firstRow = instance.getCoreRowModel().flatRows[0];
1372
1498
  const value = firstRow == null ? void 0 : firstRow.getValue(column.id);
1373
1499
 
@@ -1381,7 +1507,7 @@
1381
1507
 
1382
1508
  return aggregationFns.count;
1383
1509
  },
1384
- getColumnAggregationFn: () => {
1510
+ getAggregationFn: () => {
1385
1511
  var _ref4;
1386
1512
 
1387
1513
  const userAggregationFns = instance.options.aggregationFns;
@@ -1390,7 +1516,7 @@
1390
1516
  throw new Error();
1391
1517
  }
1392
1518
 
1393
- return isFunction(column.aggregationFn) ? column.aggregationFn : column.aggregationFn === 'auto' ? column.getColumnAutoAggregationFn() : (_ref4 = userAggregationFns == null ? void 0 : userAggregationFns[column.aggregationFn]) != null ? _ref4 : aggregationFns[column.aggregationFn];
1519
+ return isFunction(column.aggregationFn) ? column.aggregationFn : column.aggregationFn === 'auto' ? column.getAutoAggregationFn() : (_ref4 = userAggregationFns == null ? void 0 : userAggregationFns[column.aggregationFn]) != null ? _ref4 : aggregationFns[column.aggregationFn];
1394
1520
  }
1395
1521
  };
1396
1522
  },
@@ -1416,10 +1542,10 @@
1416
1542
  }
1417
1543
  };
1418
1544
  },
1419
- createRow: (row, instance) => {
1545
+ createRow: row => {
1420
1546
  return {
1421
1547
  getIsGrouped: () => !!row.groupingColumnId,
1422
- groupingValuesCache: {}
1548
+ _groupingValuesCache: {}
1423
1549
  };
1424
1550
  },
1425
1551
  createCell: (cell, column, row, instance) => {
@@ -1768,7 +1894,7 @@
1768
1894
  return {
1769
1895
  getCenterVisibleCells: memo(() => [row._getAllVisibleCells(), instance.getState().columnPinning.left, instance.getState().columnPinning.right], (allCells, left, right) => {
1770
1896
  const leftAndRight = [...(left != null ? left : []), ...(right != null ? right : [])];
1771
- return allCells.filter(d => !leftAndRight.includes(d.columnId));
1897
+ return allCells.filter(d => !leftAndRight.includes(d.column.id));
1772
1898
  }, {
1773
1899
  key: "development" === 'production' ,
1774
1900
  debug: () => {
@@ -1778,7 +1904,7 @@
1778
1904
  }
1779
1905
  }),
1780
1906
  getLeftVisibleCells: memo(() => [row._getAllVisibleCells(), instance.getState().columnPinning.left,,], (allCells, left) => {
1781
- const cells = (left != null ? left : []).map(columnId => allCells.find(cell => cell.columnId === columnId)).filter(Boolean).map(d => ({ ...d,
1907
+ const cells = (left != null ? left : []).map(columnId => allCells.find(cell => cell.column.id === columnId)).filter(Boolean).map(d => ({ ...d,
1782
1908
  position: 'left'
1783
1909
  }));
1784
1910
  return cells;
@@ -1791,7 +1917,7 @@
1791
1917
  }
1792
1918
  }),
1793
1919
  getRightVisibleCells: memo(() => [row._getAllVisibleCells(), instance.getState().columnPinning.right], (allCells, right) => {
1794
- const cells = (right != null ? right : []).map(columnId => allCells.find(cell => cell.columnId === columnId)).filter(Boolean).map(d => ({ ...d,
1920
+ const cells = (right != null ? right : []).map(columnId => allCells.find(cell => cell.column.id === columnId)).filter(Boolean).map(d => ({ ...d,
1795
1921
  position: 'left'
1796
1922
  }));
1797
1923
  return cells;
@@ -2564,11 +2690,6 @@
2564
2690
  onColumnVisibilityChange: makeStateUpdater('columnVisibility', instance)
2565
2691
  };
2566
2692
  },
2567
- getDefaultColumnDef: () => {
2568
- return {
2569
- defaultIsVisible: true
2570
- };
2571
- },
2572
2693
  createColumn: (column, instance) => {
2573
2694
  return {
2574
2695
  toggleVisibility: value => {
@@ -2600,477 +2721,72 @@
2600
2721
  _getAllVisibleCells: memo(() => [row.getAllCells().filter(cell => cell.column.getIsVisible()).map(d => d.id).join('_')], _ => {
2601
2722
  return row.getAllCells().filter(cell => cell.column.getIsVisible());
2602
2723
  }, {
2603
- key: "development" === 'production' ,
2604
- debug: () => {
2605
- var _instance$options$deb;
2606
-
2607
- return (_instance$options$deb = instance.options.debugAll) != null ? _instance$options$deb : instance.options.debugRows;
2608
- }
2609
- }),
2610
- getVisibleCells: memo(() => [row.getLeftVisibleCells(), row.getCenterVisibleCells(), row.getRightVisibleCells()], (left, center, right) => [...left, ...center, ...right], {
2611
- key: 'row.getVisibleCells',
2612
- debug: () => {
2613
- var _instance$options$deb2;
2614
-
2615
- return (_instance$options$deb2 = instance.options.debugAll) != null ? _instance$options$deb2 : instance.options.debugRows;
2616
- }
2617
- })
2618
- };
2619
- },
2620
- createInstance: instance => {
2621
- const makeVisibleColumnsMethod = (key, getColumns) => {
2622
- return memo(() => [getColumns(), getColumns().filter(d => d.getIsVisible()).map(d => d.id).join('_')], columns => {
2623
- return columns.filter(d => d.getIsVisible == null ? void 0 : d.getIsVisible());
2624
- }, {
2625
- key,
2626
- debug: () => {
2627
- var _instance$options$deb3;
2628
-
2629
- return (_instance$options$deb3 = instance.options.debugAll) != null ? _instance$options$deb3 : instance.options.debugColumns;
2630
- }
2631
- });
2632
- };
2633
-
2634
- return {
2635
- getVisibleFlatColumns: makeVisibleColumnsMethod('getVisibleFlatColumns', () => instance.getAllFlatColumns()),
2636
- getVisibleLeafColumns: makeVisibleColumnsMethod('getVisibleLeafColumns', () => instance.getAllLeafColumns()),
2637
- getLeftVisibleLeafColumns: makeVisibleColumnsMethod('getLeftVisibleLeafColumns', () => instance.getLeftLeafColumns()),
2638
- getRightVisibleLeafColumns: makeVisibleColumnsMethod('getRightVisibleLeafColumns', () => instance.getRightLeafColumns()),
2639
- getCenterVisibleLeafColumns: makeVisibleColumnsMethod('getCenterVisibleLeafColumns', () => instance.getCenterLeafColumns()),
2640
- setColumnVisibility: updater => instance.options.onColumnVisibilityChange == null ? void 0 : instance.options.onColumnVisibilityChange(updater),
2641
- resetColumnVisibility: defaultState => {
2642
- var _instance$initialStat;
2643
-
2644
- instance.setColumnVisibility(defaultState ? {} : (_instance$initialStat = instance.initialState.columnVisibility) != null ? _instance$initialStat : {});
2645
- },
2646
- toggleAllColumnsVisible: value => {
2647
- var _value;
2648
-
2649
- value = (_value = value) != null ? _value : !instance.getIsAllColumnsVisible();
2650
- instance.setColumnVisibility(instance.getAllLeafColumns().reduce((obj, column) => ({ ...obj,
2651
- [column.id]: !value ? !(column.getCanHide != null && column.getCanHide()) : value
2652
- }), {}));
2653
- },
2654
- getIsAllColumnsVisible: () => !instance.getAllLeafColumns().some(column => !(column.getIsVisible != null && column.getIsVisible())),
2655
- getIsSomeColumnsVisible: () => instance.getAllLeafColumns().some(column => column.getIsVisible == null ? void 0 : column.getIsVisible()),
2656
- getToggleAllColumnsVisibilityHandler: () => {
2657
- return e => {
2658
- var _target;
2659
-
2660
- instance.toggleAllColumnsVisible((_target = e.target) == null ? void 0 : _target.checked);
2661
- };
2662
- }
2663
- };
2664
- }
2665
- };
2666
-
2667
- //
2668
- const Headers = {
2669
- createInstance: instance => {
2670
- return {
2671
- createHeader: (column, options) => {
2672
- var _options$id;
2673
-
2674
- const id = (_options$id = options.id) != null ? _options$id : column.id;
2675
- let header = {
2676
- id,
2677
- column,
2678
- index: options.index,
2679
- isPlaceholder: options.isPlaceholder,
2680
- placeholderId: options.placeholderId,
2681
- depth: options.depth,
2682
- subHeaders: [],
2683
- colSpan: 0,
2684
- rowSpan: 0,
2685
- headerGroup: null,
2686
- getLeafHeaders: () => {
2687
- const leafHeaders = [];
2688
-
2689
- const recurseHeader = h => {
2690
- if (h.subHeaders && h.subHeaders.length) {
2691
- h.subHeaders.map(recurseHeader);
2692
- }
2693
-
2694
- leafHeaders.push(h);
2695
- };
2696
-
2697
- recurseHeader(header);
2698
- return leafHeaders;
2699
- },
2700
- renderHeader: () => column.columnDef.header ? instance._render(column.columnDef.header, {
2701
- instance,
2702
- header: header,
2703
- column
2704
- }) : null,
2705
- renderFooter: () => column.columnDef.footer ? instance._render(column.columnDef.footer, {
2706
- instance,
2707
- header: header,
2708
- column
2709
- }) : null
2710
- };
2711
-
2712
- instance._features.forEach(feature => {
2713
- Object.assign(header, feature.createHeader == null ? void 0 : feature.createHeader(header, instance));
2714
- });
2715
-
2716
- return header;
2717
- },
2718
- // Header Groups
2719
- getHeaderGroups: memo(() => [instance.getAllColumns(), instance.getVisibleLeafColumns(), instance.getState().columnPinning.left, instance.getState().columnPinning.right], (allColumns, leafColumns, left, right) => {
2720
- var _left$map$filter, _right$map$filter;
2721
-
2722
- const leftColumns = (_left$map$filter = left == null ? void 0 : left.map(columnId => leafColumns.find(d => d.id === columnId)).filter(Boolean)) != null ? _left$map$filter : [];
2723
- const rightColumns = (_right$map$filter = right == null ? void 0 : right.map(columnId => leafColumns.find(d => d.id === columnId)).filter(Boolean)) != null ? _right$map$filter : [];
2724
- const centerColumns = leafColumns.filter(column => !(left != null && left.includes(column.id)) && !(right != null && right.includes(column.id)));
2725
- const headerGroups = buildHeaderGroups(allColumns, [...leftColumns, ...centerColumns, ...rightColumns], instance);
2726
- return headerGroups;
2727
- }, {
2728
- key: 'getHeaderGroups',
2729
- debug: () => {
2730
- var _instance$options$deb;
2731
-
2732
- return (_instance$options$deb = instance.options.debugAll) != null ? _instance$options$deb : instance.options.debugHeaders;
2733
- }
2734
- }),
2735
- getCenterHeaderGroups: memo(() => [instance.getAllColumns(), instance.getVisibleLeafColumns(), instance.getState().columnPinning.left, instance.getState().columnPinning.right], (allColumns, leafColumns, left, right) => {
2736
- leafColumns = leafColumns.filter(column => !(left != null && left.includes(column.id)) && !(right != null && right.includes(column.id)));
2737
- return buildHeaderGroups(allColumns, leafColumns, instance, 'center');
2738
- }, {
2739
- key: 'getCenterHeaderGroups',
2740
- debug: () => {
2741
- var _instance$options$deb2;
2742
-
2743
- return (_instance$options$deb2 = instance.options.debugAll) != null ? _instance$options$deb2 : instance.options.debugHeaders;
2744
- }
2745
- }),
2746
- getLeftHeaderGroups: memo(() => [instance.getAllColumns(), instance.getVisibleLeafColumns(), instance.getState().columnPinning.left], (allColumns, leafColumns, left) => {
2747
- var _left$map$filter2;
2748
-
2749
- const orderedLeafColumns = (_left$map$filter2 = left == null ? void 0 : left.map(columnId => leafColumns.find(d => d.id === columnId)).filter(Boolean)) != null ? _left$map$filter2 : [];
2750
- return buildHeaderGroups(allColumns, orderedLeafColumns, instance, 'left');
2751
- }, {
2752
- key: 'getLeftHeaderGroups',
2753
- debug: () => {
2754
- var _instance$options$deb3;
2755
-
2756
- return (_instance$options$deb3 = instance.options.debugAll) != null ? _instance$options$deb3 : instance.options.debugHeaders;
2757
- }
2758
- }),
2759
- getRightHeaderGroups: memo(() => [instance.getAllColumns(), instance.getVisibleLeafColumns(), instance.getState().columnPinning.right], (allColumns, leafColumns, right) => {
2760
- var _right$map$filter2;
2761
-
2762
- const orderedLeafColumns = (_right$map$filter2 = right == null ? void 0 : right.map(columnId => leafColumns.find(d => d.id === columnId)).filter(Boolean)) != null ? _right$map$filter2 : [];
2763
- return buildHeaderGroups(allColumns, orderedLeafColumns, instance, 'right');
2764
- }, {
2765
- key: 'getRightHeaderGroups',
2766
- debug: () => {
2767
- var _instance$options$deb4;
2768
-
2769
- return (_instance$options$deb4 = instance.options.debugAll) != null ? _instance$options$deb4 : instance.options.debugHeaders;
2770
- }
2771
- }),
2772
- // Footer Groups
2773
- getFooterGroups: memo(() => [instance.getHeaderGroups()], headerGroups => {
2774
- return [...headerGroups].reverse();
2775
- }, {
2776
- key: 'getFooterGroups',
2777
- debug: () => {
2778
- var _instance$options$deb5;
2779
-
2780
- return (_instance$options$deb5 = instance.options.debugAll) != null ? _instance$options$deb5 : instance.options.debugHeaders;
2781
- }
2782
- }),
2783
- getLeftFooterGroups: memo(() => [instance.getLeftHeaderGroups()], headerGroups => {
2784
- return [...headerGroups].reverse();
2785
- }, {
2786
- key: 'getLeftFooterGroups',
2787
- debug: () => {
2788
- var _instance$options$deb6;
2789
-
2790
- return (_instance$options$deb6 = instance.options.debugAll) != null ? _instance$options$deb6 : instance.options.debugHeaders;
2791
- }
2792
- }),
2793
- getCenterFooterGroups: memo(() => [instance.getCenterHeaderGroups()], headerGroups => {
2794
- return [...headerGroups].reverse();
2795
- }, {
2796
- key: 'getCenterFooterGroups',
2797
- debug: () => {
2798
- var _instance$options$deb7;
2799
-
2800
- return (_instance$options$deb7 = instance.options.debugAll) != null ? _instance$options$deb7 : instance.options.debugHeaders;
2801
- }
2802
- }),
2803
- getRightFooterGroups: memo(() => [instance.getRightHeaderGroups()], headerGroups => {
2804
- return [...headerGroups].reverse();
2805
- }, {
2806
- key: 'getRightFooterGroups',
2807
- debug: () => {
2808
- var _instance$options$deb8;
2809
-
2810
- return (_instance$options$deb8 = instance.options.debugAll) != null ? _instance$options$deb8 : instance.options.debugHeaders;
2811
- }
2812
- }),
2813
- // Flat Headers
2814
- getFlatHeaders: memo(() => [instance.getHeaderGroups()], headerGroups => {
2815
- return headerGroups.map(headerGroup => {
2816
- return headerGroup.headers;
2817
- }).flat();
2818
- }, {
2819
- key: 'getFlatHeaders',
2820
- debug: () => {
2821
- var _instance$options$deb9;
2822
-
2823
- return (_instance$options$deb9 = instance.options.debugAll) != null ? _instance$options$deb9 : instance.options.debugHeaders;
2824
- }
2825
- }),
2826
- getLeftFlatHeaders: memo(() => [instance.getLeftHeaderGroups()], left => {
2827
- return left.map(headerGroup => {
2828
- return headerGroup.headers;
2829
- }).flat();
2830
- }, {
2831
- key: 'getLeftFlatHeaders',
2832
- debug: () => {
2833
- var _instance$options$deb10;
2834
-
2835
- return (_instance$options$deb10 = instance.options.debugAll) != null ? _instance$options$deb10 : instance.options.debugHeaders;
2836
- }
2837
- }),
2838
- getCenterFlatHeaders: memo(() => [instance.getCenterHeaderGroups()], left => {
2839
- return left.map(headerGroup => {
2840
- return headerGroup.headers;
2841
- }).flat();
2842
- }, {
2843
- key: 'getCenterFlatHeaders',
2844
- debug: () => {
2845
- var _instance$options$deb11;
2846
-
2847
- return (_instance$options$deb11 = instance.options.debugAll) != null ? _instance$options$deb11 : instance.options.debugHeaders;
2848
- }
2849
- }),
2850
- getRightFlatHeaders: memo(() => [instance.getRightHeaderGroups()], left => {
2851
- return left.map(headerGroup => {
2852
- return headerGroup.headers;
2853
- }).flat();
2854
- }, {
2855
- key: 'getRightFlatHeaders',
2856
- debug: () => {
2857
- var _instance$options$deb12;
2858
-
2859
- return (_instance$options$deb12 = instance.options.debugAll) != null ? _instance$options$deb12 : instance.options.debugHeaders;
2860
- }
2861
- }),
2862
- // Leaf Headers
2863
- getCenterLeafHeaders: memo(() => [instance.getCenterFlatHeaders()], flatHeaders => {
2864
- return flatHeaders.filter(header => {
2865
- var _header$subHeaders;
2866
-
2867
- return !((_header$subHeaders = header.subHeaders) != null && _header$subHeaders.length);
2868
- });
2869
- }, {
2870
- key: 'getCenterLeafHeaders',
2871
- debug: () => {
2872
- var _instance$options$deb13;
2873
-
2874
- return (_instance$options$deb13 = instance.options.debugAll) != null ? _instance$options$deb13 : instance.options.debugHeaders;
2875
- }
2876
- }),
2877
- getLeftLeafHeaders: memo(() => [instance.getLeftFlatHeaders()], flatHeaders => {
2878
- return flatHeaders.filter(header => {
2879
- var _header$subHeaders2;
2880
-
2881
- return !((_header$subHeaders2 = header.subHeaders) != null && _header$subHeaders2.length);
2882
- });
2883
- }, {
2884
- key: 'getLeftLeafHeaders',
2885
- debug: () => {
2886
- var _instance$options$deb14;
2887
-
2888
- return (_instance$options$deb14 = instance.options.debugAll) != null ? _instance$options$deb14 : instance.options.debugHeaders;
2889
- }
2890
- }),
2891
- getRightLeafHeaders: memo(() => [instance.getRightFlatHeaders()], flatHeaders => {
2892
- return flatHeaders.filter(header => {
2893
- var _header$subHeaders3;
2894
-
2895
- return !((_header$subHeaders3 = header.subHeaders) != null && _header$subHeaders3.length);
2896
- });
2897
- }, {
2898
- key: 'getRightLeafHeaders',
2724
+ key: "development" === 'production' ,
2899
2725
  debug: () => {
2900
- var _instance$options$deb15;
2726
+ var _instance$options$deb;
2901
2727
 
2902
- return (_instance$options$deb15 = instance.options.debugAll) != null ? _instance$options$deb15 : instance.options.debugHeaders;
2728
+ return (_instance$options$deb = instance.options.debugAll) != null ? _instance$options$deb : instance.options.debugRows;
2903
2729
  }
2904
2730
  }),
2905
- getLeafHeaders: memo(() => [instance.getLeftHeaderGroups(), instance.getCenterHeaderGroups(), instance.getRightHeaderGroups()], (left, center, right) => {
2906
- var _left$0$headers, _left$, _center$0$headers, _center$, _right$0$headers, _right$;
2731
+ getVisibleCells: memo(() => [row.getLeftVisibleCells(), row.getCenterVisibleCells(), row.getRightVisibleCells()], (left, center, right) => [...left, ...center, ...right], {
2732
+ key: 'row.getVisibleCells',
2733
+ debug: () => {
2734
+ var _instance$options$deb2;
2907
2735
 
2908
- return [...((_left$0$headers = (_left$ = left[0]) == null ? void 0 : _left$.headers) != null ? _left$0$headers : []), ...((_center$0$headers = (_center$ = center[0]) == null ? void 0 : _center$.headers) != null ? _center$0$headers : []), ...((_right$0$headers = (_right$ = right[0]) == null ? void 0 : _right$.headers) != null ? _right$0$headers : [])].map(header => {
2909
- return header.getLeafHeaders();
2910
- }).flat();
2736
+ return (_instance$options$deb2 = instance.options.debugAll) != null ? _instance$options$deb2 : instance.options.debugRows;
2737
+ }
2738
+ })
2739
+ };
2740
+ },
2741
+ createInstance: instance => {
2742
+ const makeVisibleColumnsMethod = (key, getColumns) => {
2743
+ return memo(() => [getColumns(), getColumns().filter(d => d.getIsVisible()).map(d => d.id).join('_')], columns => {
2744
+ return columns.filter(d => d.getIsVisible == null ? void 0 : d.getIsVisible());
2911
2745
  }, {
2912
- key: 'getLeafHeaders',
2746
+ key,
2913
2747
  debug: () => {
2914
- var _instance$options$deb16;
2748
+ var _instance$options$deb3;
2915
2749
 
2916
- return (_instance$options$deb16 = instance.options.debugAll) != null ? _instance$options$deb16 : instance.options.debugHeaders;
2750
+ return (_instance$options$deb3 = instance.options.debugAll) != null ? _instance$options$deb3 : instance.options.debugColumns;
2917
2751
  }
2918
- }),
2919
- getHeader: id => {
2920
- const header = [...instance.getFlatHeaders(), ...instance.getCenterFlatHeaders(), ...instance.getLeftFlatHeaders(), ...instance.getRightFlatHeaders()].find(d => d.id === id);
2752
+ });
2753
+ };
2921
2754
 
2922
- if (!header) {
2923
- {
2924
- console.warn("Could not find header with id: " + id);
2925
- }
2755
+ return {
2756
+ getVisibleFlatColumns: makeVisibleColumnsMethod('getVisibleFlatColumns', () => instance.getAllFlatColumns()),
2757
+ getVisibleLeafColumns: makeVisibleColumnsMethod('getVisibleLeafColumns', () => instance.getAllLeafColumns()),
2758
+ getLeftVisibleLeafColumns: makeVisibleColumnsMethod('getLeftVisibleLeafColumns', () => instance.getLeftLeafColumns()),
2759
+ getRightVisibleLeafColumns: makeVisibleColumnsMethod('getRightVisibleLeafColumns', () => instance.getRightLeafColumns()),
2760
+ getCenterVisibleLeafColumns: makeVisibleColumnsMethod('getCenterVisibleLeafColumns', () => instance.getCenterLeafColumns()),
2761
+ setColumnVisibility: updater => instance.options.onColumnVisibilityChange == null ? void 0 : instance.options.onColumnVisibilityChange(updater),
2762
+ resetColumnVisibility: defaultState => {
2763
+ var _instance$initialStat;
2926
2764
 
2927
- throw new Error();
2928
- }
2765
+ instance.setColumnVisibility(defaultState ? {} : (_instance$initialStat = instance.initialState.columnVisibility) != null ? _instance$initialStat : {});
2766
+ },
2767
+ toggleAllColumnsVisible: value => {
2768
+ var _value;
2769
+
2770
+ value = (_value = value) != null ? _value : !instance.getIsAllColumnsVisible();
2771
+ instance.setColumnVisibility(instance.getAllLeafColumns().reduce((obj, column) => ({ ...obj,
2772
+ [column.id]: !value ? !(column.getCanHide != null && column.getCanHide()) : value
2773
+ }), {}));
2774
+ },
2775
+ getIsAllColumnsVisible: () => !instance.getAllLeafColumns().some(column => !(column.getIsVisible != null && column.getIsVisible())),
2776
+ getIsSomeColumnsVisible: () => instance.getAllLeafColumns().some(column => column.getIsVisible == null ? void 0 : column.getIsVisible()),
2777
+ getToggleAllColumnsVisibilityHandler: () => {
2778
+ return e => {
2779
+ var _target;
2929
2780
 
2930
- return header;
2781
+ instance.toggleAllColumnsVisible((_target = e.target) == null ? void 0 : _target.checked);
2782
+ };
2931
2783
  }
2932
2784
  };
2933
2785
  }
2934
2786
  };
2935
- function buildHeaderGroups(allColumns, columnsToGroup, instance, headerFamily) {
2936
- var _headerGroups$0$heade, _headerGroups$;
2937
-
2938
- // Find the max depth of the columns:
2939
- // build the leaf column row
2940
- // build each buffer row going up
2941
- // placeholder for non-existent level
2942
- // real column for existing level
2943
- let maxDepth = 0;
2944
-
2945
- const findMaxDepth = function (columns, depth) {
2946
- if (depth === void 0) {
2947
- depth = 1;
2948
- }
2949
-
2950
- maxDepth = Math.max(maxDepth, depth);
2951
- columns.filter(column => column.getIsVisible()).forEach(column => {
2952
- var _column$columns;
2953
-
2954
- if ((_column$columns = column.columns) != null && _column$columns.length) {
2955
- findMaxDepth(column.columns, depth + 1);
2956
- }
2957
- }, 0);
2958
- };
2959
-
2960
- findMaxDepth(allColumns);
2961
- let headerGroups = [];
2962
-
2963
- const createHeaderGroup = (headersToGroup, depth) => {
2964
- // The header group we are creating
2965
- const headerGroup = {
2966
- depth,
2967
- id: [headerFamily, "" + depth].filter(Boolean).join('_'),
2968
- headers: []
2969
- }; // The parent columns we're going to scan next
2970
-
2971
- const pendingParentHeaders = []; // Scan each column for parents
2972
-
2973
- headersToGroup.forEach(headerToGroup => {
2974
- // What is the latest (last) parent column?
2975
- const latestPendingParentHeader = [...pendingParentHeaders].reverse()[0];
2976
- const isLeafHeader = headerToGroup.column.depth === headerGroup.depth;
2977
- let column;
2978
- let isPlaceholder = false;
2979
-
2980
- if (isLeafHeader && headerToGroup.column.parent) {
2981
- // The parent header is new
2982
- column = headerToGroup.column.parent;
2983
- } else {
2984
- // The parent header is repeated
2985
- column = headerToGroup.column;
2986
- isPlaceholder = true;
2987
- }
2988
-
2989
- if ((latestPendingParentHeader == null ? void 0 : latestPendingParentHeader.column) === column) {
2990
- // This column is repeated. Add it as a sub header to the next batch
2991
- latestPendingParentHeader.subHeaders.push(headerToGroup);
2992
- } else {
2993
- // This is a new header. Let's create it
2994
- const header = instance.createHeader(column, {
2995
- id: [headerFamily, depth, column.id, headerToGroup == null ? void 0 : headerToGroup.id].filter(Boolean).join('_'),
2996
- isPlaceholder,
2997
- placeholderId: isPlaceholder ? "" + pendingParentHeaders.filter(d => d.column === column).length : undefined,
2998
- depth,
2999
- index: pendingParentHeaders.length
3000
- }); // Add the headerToGroup as a subHeader of the new header
3001
-
3002
- header.subHeaders.push(headerToGroup); // Add the new header to the pendingParentHeaders to get grouped
3003
- // in the next batch
3004
-
3005
- pendingParentHeaders.push(header);
3006
- }
3007
-
3008
- headerGroup.headers.push(headerToGroup);
3009
- headerToGroup.headerGroup = headerGroup;
3010
- });
3011
- headerGroups.push(headerGroup);
3012
-
3013
- if (depth > 0) {
3014
- createHeaderGroup(pendingParentHeaders, depth - 1);
3015
- }
3016
- };
3017
-
3018
- const bottomHeaders = columnsToGroup.map((column, index) => instance.createHeader(column, {
3019
- depth: maxDepth,
3020
- index
3021
- }));
3022
- createHeaderGroup(bottomHeaders, maxDepth - 1);
3023
- headerGroups.reverse(); // headerGroups = headerGroups.filter(headerGroup => {
3024
- // return !headerGroup.headers.every(header => header.isPlaceholder)
3025
- // })
3026
-
3027
- const recurseHeadersForSpans = headers => {
3028
- const filteredHeaders = headers.filter(header => header.column.getIsVisible());
3029
- return filteredHeaders.map(header => {
3030
- let colSpan = 0;
3031
- let rowSpan = 0;
3032
- let childRowSpans = [0];
3033
-
3034
- if (header.subHeaders && header.subHeaders.length) {
3035
- childRowSpans = [];
3036
- recurseHeadersForSpans(header.subHeaders).forEach(_ref => {
3037
- let {
3038
- colSpan: childColSpan,
3039
- rowSpan: childRowSpan
3040
- } = _ref;
3041
- colSpan += childColSpan;
3042
- childRowSpans.push(childRowSpan);
3043
- });
3044
- } else {
3045
- colSpan = 1;
3046
- }
3047
-
3048
- const minChildRowSpan = Math.min(...childRowSpans);
3049
- rowSpan = rowSpan + minChildRowSpan;
3050
- header.colSpan = colSpan > 0 ? colSpan : undefined;
3051
- header.rowSpan = rowSpan > 0 ? rowSpan : undefined;
3052
- return {
3053
- colSpan,
3054
- rowSpan
3055
- };
3056
- });
3057
- };
3058
2787
 
3059
- recurseHeadersForSpans((_headerGroups$0$heade = (_headerGroups$ = headerGroups[0]) == null ? void 0 : _headerGroups$.headers) != null ? _headerGroups$0$heade : []);
3060
- return headerGroups;
3061
- }
2788
+ const features = [Headers, Visibility, Ordering, Pinning, Filters, Sorting, Grouping, Expanding, Pagination, RowSelection, ColumnSizing]; //
3062
2789
 
3063
- // export type Batch = {
3064
- // id: number
3065
- // priority: keyof CoreBatches
3066
- // tasks: (() => void)[]
3067
- // schedule: (cb: () => void) => void
3068
- // cancel: () => void
3069
- // }
3070
- // type CoreBatches = {
3071
- // data: Batch[]
3072
- // facets: Batch[]
3073
- // }
3074
2790
  function createTableInstance(options) {
3075
2791
  var _options$initialState;
3076
2792
 
@@ -3079,7 +2795,7 @@
3079
2795
  }
3080
2796
 
3081
2797
  let instance = {
3082
- _features: [Columns, Rows, Cells, Headers, Visibility, Ordering, Pinning, Filters, Sorting, Grouping, Expanding, Pagination, RowSelection, ColumnSizing]
2798
+ _features: features
3083
2799
  };
3084
2800
 
3085
2801
  const defaultOptions = instance._features.reduce((obj, feature) => {
@@ -3096,8 +2812,7 @@
3096
2812
  };
3097
2813
  };
3098
2814
 
3099
- const coreInitialState = {// coreProgress: 1,
3100
- };
2815
+ const coreInitialState = {};
3101
2816
  let initialState = { ...coreInitialState,
3102
2817
  ...((_options$initialState = options.initialState) != null ? _options$initialState : {})
3103
2818
  };
@@ -3110,16 +2825,8 @@
3110
2825
 
3111
2826
  const queued = [];
3112
2827
  let queuedTimeout = false;
3113
- const midInstance = { ...instance,
3114
- // init: () => {
3115
- // startWork()
3116
- // },
3117
- // willUpdate: () => {
3118
- // startWork()
3119
- // },
3120
- // destroy: () => {
3121
- // stopWork()
3122
- // },
2828
+ const coreInstance = {
2829
+ _features: features,
3123
2830
  options: { ...defaultOptions,
3124
2831
  ...options
3125
2832
  },
@@ -3165,29 +2872,134 @@
3165
2872
  },
3166
2873
  setState: updater => {
3167
2874
  instance.options.onStateChange == null ? void 0 : instance.options.onStateChange(updater);
3168
- } // getOverallProgress: () => {
3169
- // const { coreProgress, filtersProgress, facetProgress } =
3170
- // instance.getState()
3171
- // return mean(() =>
3172
- // [coreProgress, filtersProgress].filter(d => d < 1)
3173
- // ) as number
3174
- // },
3175
- // getProgressStage: () => {
3176
- // const { coreProgress, filtersProgress, facetProgress } =
3177
- // instance.getState()
3178
- // if (coreProgress < 1) {
3179
- // return 'coreRowModel'
3180
- // }
3181
- // if (filtersProgress < 1) {
3182
- // return 'filteredRowModel'
3183
- // }
3184
- // if (Object.values(facetProgress).some(d => d < 1)) {
3185
- // return 'facetedRowModel'
3186
- // }
3187
- // },
2875
+ },
2876
+ _getRowId: (row, index, parent) => {
2877
+ var _instance$options$get;
2878
+
2879
+ return (_instance$options$get = instance.options.getRowId == null ? void 0 : instance.options.getRowId(row, index, parent)) != null ? _instance$options$get : "" + (parent ? [parent.id, index].join('.') : index);
2880
+ },
2881
+ getCoreRowModel: () => {
2882
+ if (!instance._getCoreRowModel) {
2883
+ instance._getCoreRowModel = instance.options.getCoreRowModel(instance);
2884
+ }
2885
+
2886
+ return instance._getCoreRowModel();
2887
+ },
2888
+ // The final calls start at the bottom of the model,
2889
+ // expanded rows, which then work their way up
2890
+ getRowModel: () => {
2891
+ return instance.getPaginationRowModel();
2892
+ },
2893
+ getRow: id => {
2894
+ const row = instance.getRowModel().rowsById[id];
3188
2895
 
2896
+ if (!row) {
2897
+ {
2898
+ throw new Error("getRow expected an ID, but got " + id);
2899
+ }
2900
+ }
2901
+
2902
+ return row;
2903
+ },
2904
+ _getDefaultColumnDef: memo(() => [instance.options.defaultColumn], defaultColumn => {
2905
+ var _defaultColumn;
2906
+
2907
+ defaultColumn = (_defaultColumn = defaultColumn) != null ? _defaultColumn : {};
2908
+ return {
2909
+ header: props => props.header.column.id,
2910
+ footer: props => props.header.column.id,
2911
+ cell: props => {
2912
+ var _props$getValue$toStr, _props$getValue$toStr2, _props$getValue;
2913
+
2914
+ return (_props$getValue$toStr = (_props$getValue$toStr2 = (_props$getValue = props.getValue()).toString) == null ? void 0 : _props$getValue$toStr2.call(_props$getValue)) != null ? _props$getValue$toStr : null;
2915
+ },
2916
+ ...instance._features.reduce((obj, feature) => {
2917
+ return Object.assign(obj, feature.getDefaultColumnDef == null ? void 0 : feature.getDefaultColumnDef());
2918
+ }, {}),
2919
+ ...defaultColumn
2920
+ };
2921
+ }, {
2922
+ debug: () => {
2923
+ var _instance$options$deb;
2924
+
2925
+ return (_instance$options$deb = instance.options.debugAll) != null ? _instance$options$deb : instance.options.debugColumns;
2926
+ },
2927
+ key: 'getDefaultColumnDef'
2928
+ }),
2929
+ _getColumnDefs: () => instance.options.columns,
2930
+ getAllColumns: memo(() => [instance._getColumnDefs()], columnDefs => {
2931
+ const recurseColumns = function (columnDefs, parent, depth) {
2932
+ if (depth === void 0) {
2933
+ depth = 0;
2934
+ }
2935
+
2936
+ return columnDefs.map(columnDef => {
2937
+ const column = createColumn(instance, columnDef, depth, parent);
2938
+ column.columns = columnDef.columns ? recurseColumns(columnDef.columns, column, depth + 1) : [];
2939
+ return column;
2940
+ });
2941
+ };
2942
+
2943
+ return recurseColumns(columnDefs);
2944
+ }, {
2945
+ key: 'getAllColumns',
2946
+ debug: () => {
2947
+ var _instance$options$deb2;
2948
+
2949
+ return (_instance$options$deb2 = instance.options.debugAll) != null ? _instance$options$deb2 : instance.options.debugColumns;
2950
+ }
2951
+ }),
2952
+ getAllFlatColumns: memo(() => [instance.getAllColumns()], allColumns => {
2953
+ return allColumns.flatMap(column => {
2954
+ return column.getFlatColumns();
2955
+ });
2956
+ }, {
2957
+ key: 'getAllFlatColumns',
2958
+ debug: () => {
2959
+ var _instance$options$deb3;
2960
+
2961
+ return (_instance$options$deb3 = instance.options.debugAll) != null ? _instance$options$deb3 : instance.options.debugColumns;
2962
+ }
2963
+ }),
2964
+ _getAllFlatColumnsById: memo(() => [instance.getAllFlatColumns()], flatColumns => {
2965
+ return flatColumns.reduce((acc, column) => {
2966
+ acc[column.id] = column;
2967
+ return acc;
2968
+ }, {});
2969
+ }, {
2970
+ key: 'getAllFlatColumnsById',
2971
+ debug: () => {
2972
+ var _instance$options$deb4;
2973
+
2974
+ return (_instance$options$deb4 = instance.options.debugAll) != null ? _instance$options$deb4 : instance.options.debugColumns;
2975
+ }
2976
+ }),
2977
+ getAllLeafColumns: memo(() => [instance.getAllColumns(), instance._getOrderColumnsFn()], (allColumns, orderColumns) => {
2978
+ let leafColumns = allColumns.flatMap(column => column.getLeafColumns());
2979
+ return orderColumns(leafColumns);
2980
+ }, {
2981
+ key: 'getAllLeafColumns',
2982
+ debug: () => {
2983
+ var _instance$options$deb5;
2984
+
2985
+ return (_instance$options$deb5 = instance.options.debugAll) != null ? _instance$options$deb5 : instance.options.debugColumns;
2986
+ }
2987
+ }),
2988
+ getColumn: columnId => {
2989
+ const column = instance._getAllFlatColumnsById()[columnId];
2990
+
2991
+ if (!column) {
2992
+ {
2993
+ console.warn("[Table] Column with id " + columnId + " does not exist.");
2994
+ }
2995
+
2996
+ throw new Error();
2997
+ }
2998
+
2999
+ return column;
3000
+ }
3189
3001
  };
3190
- instance = Object.assign(instance, midInstance);
3002
+ Object.assign(instance, coreInstance);
3191
3003
 
3192
3004
  instance._features.forEach(feature => {
3193
3005
  return Object.assign(instance, feature.createInstance == null ? void 0 : feature.createInstance(instance));
@@ -3252,6 +3064,86 @@
3252
3064
  return table;
3253
3065
  }
3254
3066
 
3067
+ function createCell(instance, row, column, columnId) {
3068
+ const cell = {
3069
+ id: row.id + "_" + column.id,
3070
+ row,
3071
+ column,
3072
+ getValue: () => row.getValue(columnId),
3073
+ renderCell: () => column.columnDef.cell ? instance._render(column.columnDef.cell, {
3074
+ instance,
3075
+ column,
3076
+ row,
3077
+ cell: cell,
3078
+ getValue: cell.getValue
3079
+ }) : null
3080
+ };
3081
+
3082
+ instance._features.forEach(feature => {
3083
+ Object.assign(cell, feature.createCell == null ? void 0 : feature.createCell(cell, column, row, instance));
3084
+ }, {});
3085
+
3086
+ return cell;
3087
+ }
3088
+
3089
+ const createRow = (instance, id, original, rowIndex, depth, subRows) => {
3090
+ let row = {
3091
+ id,
3092
+ index: rowIndex,
3093
+ original,
3094
+ depth,
3095
+ _valuesCache: {},
3096
+ getValue: columnId => {
3097
+ if (row._valuesCache.hasOwnProperty(columnId)) {
3098
+ return row._valuesCache[columnId];
3099
+ }
3100
+
3101
+ const column = instance.getColumn(columnId);
3102
+
3103
+ if (!column.accessorFn) {
3104
+ return undefined;
3105
+ }
3106
+
3107
+ row._valuesCache[columnId] = column.accessorFn(row.original, rowIndex);
3108
+ return row._valuesCache[columnId];
3109
+ },
3110
+ subRows: subRows != null ? subRows : [],
3111
+ getLeafRows: () => flattenBy(row.subRows, d => d.subRows),
3112
+ getAllCells: memo(() => [instance.getAllLeafColumns()], leafColumns => {
3113
+ return leafColumns.map(column => {
3114
+ return createCell(instance, row, column, column.id);
3115
+ });
3116
+ }, {
3117
+ key: 'row.getAllCells',
3118
+ debug: () => {
3119
+ var _instance$options$deb;
3120
+
3121
+ return (_instance$options$deb = instance.options.debugAll) != null ? _instance$options$deb : instance.options.debugRows;
3122
+ }
3123
+ }),
3124
+ _getAllCellsByColumnId: memo(() => [row.getAllCells()], allCells => {
3125
+ return allCells.reduce((acc, cell) => {
3126
+ acc[cell.column.id] = cell;
3127
+ return acc;
3128
+ }, {});
3129
+ }, {
3130
+ key: "development" === 'production' ,
3131
+ debug: () => {
3132
+ var _instance$options$deb2;
3133
+
3134
+ return (_instance$options$deb2 = instance.options.debugAll) != null ? _instance$options$deb2 : instance.options.debugRows;
3135
+ }
3136
+ })
3137
+ };
3138
+
3139
+ for (let i = 0; i < instance._features.length; i++) {
3140
+ const feature = instance._features[i];
3141
+ Object.assign(row, feature == null ? void 0 : feature.createRow == null ? void 0 : feature.createRow(row, instance));
3142
+ }
3143
+
3144
+ return row;
3145
+ };
3146
+
3255
3147
  function getCoreRowModel() {
3256
3148
  return instance => memo(() => [instance.options.data], data => {
3257
3149
  const rowModel = {
@@ -3279,7 +3171,7 @@
3279
3171
  // }
3280
3172
  // Make the row
3281
3173
 
3282
- row = instance.createRow(instance.getRowId(originalRow, i, parent), originalRow, i, depth); // Keep track of every row in a flat array
3174
+ row = createRow(instance, instance._getRowId(originalRow, i, parent), originalRow, i, depth); // Keep track of every row in a flat array
3283
3175
 
3284
3176
  rowModel.flatRows.push(row); // Also keep track of every row by its ID
3285
3177
 
@@ -3342,7 +3234,7 @@
3342
3234
  row = rowsToFilter[i];
3343
3235
 
3344
3236
  if ((_row$subRows = row.subRows) != null && _row$subRows.length) {
3345
- newRow = instance.createRow(row.id, row.original, row.index, row.depth);
3237
+ newRow = createRow(instance, row.id, row.original, row.index, row.depth);
3346
3238
  newRow.columnFilters = row.columnFilters;
3347
3239
  newRow.subRows = recurseFilterRows(row.subRows, depth + 1);
3348
3240
 
@@ -3392,7 +3284,7 @@
3392
3284
  var _row$subRows2;
3393
3285
 
3394
3286
  if ((_row$subRows2 = row.subRows) != null && _row$subRows2.length) {
3395
- newRow = instance.createRow(row.id, row.original, row.index, row.depth);
3287
+ newRow = createRow(instance, row.id, row.original, row.index, row.depth);
3396
3288
  newRow.subRows = recurseFilterRows(row.subRows, depth + 1);
3397
3289
  row = newRow;
3398
3290
  }
@@ -3759,7 +3651,7 @@
3759
3651
  const subRows = groupUpRecursively(groupedRows, depth + 1, id); // Flatten the leaf rows of the rows in this group
3760
3652
 
3761
3653
  const leafRows = depth ? flattenBy(groupedRows, row => row.subRows) : groupedRows;
3762
- const row = instance.createRow(id, undefined, index, depth);
3654
+ const row = createRow(instance, id, undefined, index, depth);
3763
3655
  Object.assign(row, {
3764
3656
  groupingColumnId: columnId,
3765
3657
  groupingValue,
@@ -3768,38 +3660,30 @@
3768
3660
  getValue: columnId => {
3769
3661
  // Don't aggregate columns that are in the grouping
3770
3662
  if (existingGrouping.includes(columnId)) {
3771
- if (row.valuesCache.hasOwnProperty(columnId)) {
3772
- return row.valuesCache[columnId];
3663
+ if (row._valuesCache.hasOwnProperty(columnId)) {
3664
+ return row._valuesCache[columnId];
3773
3665
  }
3774
3666
 
3775
3667
  if (groupedRows[0]) {
3776
3668
  var _groupedRows$0$getVal;
3777
3669
 
3778
- row.valuesCache[columnId] = (_groupedRows$0$getVal = groupedRows[0].getValue(columnId)) != null ? _groupedRows$0$getVal : undefined;
3670
+ row._valuesCache[columnId] = (_groupedRows$0$getVal = groupedRows[0].getValue(columnId)) != null ? _groupedRows$0$getVal : undefined;
3779
3671
  }
3780
3672
 
3781
- return row.valuesCache[columnId];
3673
+ return row._valuesCache[columnId];
3782
3674
  }
3783
3675
 
3784
- if (row.groupingValuesCache.hasOwnProperty(columnId)) {
3785
- return row.groupingValuesCache[columnId];
3676
+ if (row._groupingValuesCache.hasOwnProperty(columnId)) {
3677
+ return row._groupingValuesCache[columnId];
3786
3678
  } // Aggregate the values
3787
3679
 
3788
3680
 
3789
3681
  const column = instance.getColumn(columnId);
3790
- const aggregateFn = column.getColumnAggregationFn();
3682
+ const aggregateFn = column.getAggregationFn();
3791
3683
 
3792
3684
  if (aggregateFn) {
3793
- row.groupingValuesCache[columnId] = aggregateFn(() => leafRows.map(row => {
3794
- let columnValue = row.getValue(columnId);
3795
-
3796
- if (!depth && column.columnDef.aggregateValue) {
3797
- columnValue = column.columnDef.aggregateValue(columnValue);
3798
- }
3799
-
3800
- return columnValue;
3801
- }), () => groupedRows.map(row => row.getValue(columnId)));
3802
- return row.groupingValuesCache[columnId];
3685
+ row._groupingValuesCache[columnId] = aggregateFn(columnId, leafRows, groupedRows);
3686
+ return row._groupingValuesCache[columnId];
3803
3687
  } else if (column.aggregationFn) {
3804
3688
  console.info({
3805
3689
  column
@@ -3879,7 +3763,7 @@
3879
3763
  return rowModel;
3880
3764
  }
3881
3765
 
3882
- return expandRows(rowModel, instance);
3766
+ return expandRows(rowModel);
3883
3767
  }, {
3884
3768
  key: 'getExpandedRowModel',
3885
3769
  debug: () => {
@@ -3897,7 +3781,7 @@
3897
3781
 
3898
3782
  expandedRows.push(row);
3899
3783
 
3900
- if (instance.options.expandSubRows && (_row$subRows = row.subRows) != null && _row$subRows.length && row.getIsExpanded()) {
3784
+ if ((_row$subRows = row.subRows) != null && _row$subRows.length && row.getIsExpanded()) {
3901
3785
  row.subRows.forEach(handleRow);
3902
3786
  }
3903
3787
  };
@@ -3934,7 +3818,7 @@
3934
3818
  rows,
3935
3819
  flatRows,
3936
3820
  rowsById
3937
- }, instance);
3821
+ });
3938
3822
  }
3939
3823
 
3940
3824
  return {
@@ -4021,6 +3905,8 @@
4021
3905
  exports.Visibility = Visibility;
4022
3906
  exports.aggregationFns = aggregationFns;
4023
3907
  exports.buildHeaderGroups = buildHeaderGroups;
3908
+ exports.createColumn = createColumn;
3909
+ exports.createRow = createRow;
4024
3910
  exports.createTable = createTable;
4025
3911
  exports.createTableFactory = createTableFactory;
4026
3912
  exports.createTableInstance = createTableInstance;
@@ -4041,7 +3927,6 @@
4041
3927
  exports.isFunction = isFunction;
4042
3928
  exports.isRowSelected = isRowSelected;
4043
3929
  exports.makeStateUpdater = makeStateUpdater;
4044
- exports.mean = mean;
4045
3930
  exports.memo = memo;
4046
3931
  exports.noop = noop;
4047
3932
  exports.orderColumns = orderColumns;