@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.
@@ -97,337 +97,459 @@ function memo(getDeps, fn, opts) {
97
97
  };
98
98
  }
99
99
 
100
+ function createColumn(instance, columnDef, depth, parent) {
101
+ var _ref, _columnDef$id;
102
+
103
+ const defaultColumn = instance._getDefaultColumnDef();
104
+
105
+ columnDef = { ...defaultColumn,
106
+ ...columnDef
107
+ };
108
+ let id = (_ref = (_columnDef$id = columnDef.id) != null ? _columnDef$id : columnDef.accessorKey) != null ? _ref : typeof columnDef.header === 'string' ? columnDef.header : undefined;
109
+ let accessorFn;
110
+
111
+ if (columnDef.accessorFn) {
112
+ accessorFn = columnDef.accessorFn;
113
+ } else if (columnDef.accessorKey) {
114
+ accessorFn = originalRow => originalRow[columnDef.accessorKey];
115
+ }
116
+
117
+ if (!id) {
118
+ if (process.env.NODE_ENV !== 'production') {
119
+ throw new Error(columnDef.accessorFn ? "Columns require an id when using an accessorFn" : "Columns require an id when using a non-string header");
120
+ }
121
+
122
+ throw new Error();
123
+ }
124
+
125
+ let column = { ...columnDef,
126
+ id: "" + id,
127
+ accessorFn,
128
+ parent: parent,
129
+ depth,
130
+ columnDef,
131
+ columnDefType: columnDef.columnDefType,
132
+ columns: [],
133
+ getFlatColumns: memo(() => [true], () => {
134
+ var _column$columns;
135
+
136
+ return [column, ...((_column$columns = column.columns) == null ? void 0 : _column$columns.flatMap(d => d.getFlatColumns()))];
137
+ }, {
138
+ key: process.env.NODE_ENV === 'production' && 'column.getFlatColumns',
139
+ debug: () => {
140
+ var _instance$options$deb;
141
+
142
+ return (_instance$options$deb = instance.options.debugAll) != null ? _instance$options$deb : instance.options.debugColumns;
143
+ }
144
+ }),
145
+ getLeafColumns: memo(() => [instance._getOrderColumnsFn()], orderColumns => {
146
+ var _column$columns2;
147
+
148
+ if ((_column$columns2 = column.columns) != null && _column$columns2.length) {
149
+ let leafColumns = column.columns.flatMap(column => column.getLeafColumns());
150
+ return orderColumns(leafColumns);
151
+ }
152
+
153
+ return [column];
154
+ }, {
155
+ key: process.env.NODE_ENV === 'production' && 'column.getLeafColumns',
156
+ debug: () => {
157
+ var _instance$options$deb2;
158
+
159
+ return (_instance$options$deb2 = instance.options.debugAll) != null ? _instance$options$deb2 : instance.options.debugColumns;
160
+ }
161
+ })
162
+ };
163
+ column = instance._features.reduce((obj, feature) => {
164
+ return Object.assign(obj, feature.createColumn == null ? void 0 : feature.createColumn(column, instance));
165
+ }, column); // Yes, we have to convert instance to uknown, because we know more than the compiler here.
166
+
167
+ return column;
168
+ }
169
+
100
170
  //
101
- const Columns = {
171
+ function createHeader(instance, column, options) {
172
+ var _options$id;
173
+
174
+ const id = (_options$id = options.id) != null ? _options$id : column.id;
175
+ let header = {
176
+ id,
177
+ column,
178
+ index: options.index,
179
+ isPlaceholder: !!options.isPlaceholder,
180
+ placeholderId: options.placeholderId,
181
+ depth: options.depth,
182
+ subHeaders: [],
183
+ colSpan: 0,
184
+ rowSpan: 0,
185
+ headerGroup: null,
186
+ getLeafHeaders: () => {
187
+ const leafHeaders = [];
188
+
189
+ const recurseHeader = h => {
190
+ if (h.subHeaders && h.subHeaders.length) {
191
+ h.subHeaders.map(recurseHeader);
192
+ }
193
+
194
+ leafHeaders.push(h);
195
+ };
196
+
197
+ recurseHeader(header);
198
+ return leafHeaders;
199
+ },
200
+ renderHeader: () => column.columnDef.header ? instance._render(column.columnDef.header, {
201
+ instance,
202
+ header: header,
203
+ column
204
+ }) : null,
205
+ renderFooter: () => column.columnDef.footer ? instance._render(column.columnDef.footer, {
206
+ instance,
207
+ header: header,
208
+ column
209
+ }) : null
210
+ };
211
+
212
+ instance._features.forEach(feature => {
213
+ Object.assign(header, feature.createHeader == null ? void 0 : feature.createHeader(header, instance));
214
+ });
215
+
216
+ return header;
217
+ }
218
+
219
+ const Headers = {
102
220
  createInstance: instance => {
103
221
  return {
104
- getDefaultColumnDef: memo(() => [instance.options.defaultColumnDef], defaultColumn => {
105
- var _defaultColumn;
106
-
107
- defaultColumn = (_defaultColumn = defaultColumn) != null ? _defaultColumn : {};
108
- return {
109
- header: props => props.header.column.id,
110
- footer: props => props.header.column.id,
111
- cell: props => {
112
- var _props$getValue$toStr, _props$getValue$toStr2, _props$getValue;
113
-
114
- 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;
115
- },
116
- ...instance._features.reduce((obj, feature) => {
117
- return Object.assign(obj, feature.getDefaultColumnDef == null ? void 0 : feature.getDefaultColumnDef());
118
- }, {}),
119
- ...defaultColumn
120
- };
222
+ // Header Groups
223
+ getHeaderGroups: memo(() => [instance.getAllColumns(), instance.getVisibleLeafColumns(), instance.getState().columnPinning.left, instance.getState().columnPinning.right], (allColumns, leafColumns, left, right) => {
224
+ var _left$map$filter, _right$map$filter;
225
+
226
+ const leftColumns = (_left$map$filter = left == null ? void 0 : left.map(columnId => leafColumns.find(d => d.id === columnId)).filter(Boolean)) != null ? _left$map$filter : [];
227
+ const rightColumns = (_right$map$filter = right == null ? void 0 : right.map(columnId => leafColumns.find(d => d.id === columnId)).filter(Boolean)) != null ? _right$map$filter : [];
228
+ const centerColumns = leafColumns.filter(column => !(left != null && left.includes(column.id)) && !(right != null && right.includes(column.id)));
229
+ const headerGroups = buildHeaderGroups(allColumns, [...leftColumns, ...centerColumns, ...rightColumns], instance);
230
+ return headerGroups;
121
231
  }, {
232
+ key: process.env.NODE_ENV === 'development' && 'getHeaderGroups',
122
233
  debug: () => {
123
234
  var _instance$options$deb;
124
235
 
125
- return (_instance$options$deb = instance.options.debugAll) != null ? _instance$options$deb : instance.options.debugColumns;
126
- },
127
- key: process.env.NODE_ENV === 'development' && 'getDefaultColumnDef'
236
+ return (_instance$options$deb = instance.options.debugAll) != null ? _instance$options$deb : instance.options.debugHeaders;
237
+ }
128
238
  }),
129
- getColumnDefs: () => instance.options.columns,
130
- createColumn: (columnDef, depth, parent) => {
131
- var _ref, _columnDef$id;
132
-
133
- const defaultColumnDef = instance.getDefaultColumnDef();
134
- columnDef = { ...defaultColumnDef,
135
- ...columnDef
136
- };
137
- let id = (_ref = (_columnDef$id = columnDef.id) != null ? _columnDef$id : columnDef.accessorKey) != null ? _ref : typeof columnDef.header === 'string' ? columnDef.header : undefined;
138
- let accessorFn;
239
+ getCenterHeaderGroups: memo(() => [instance.getAllColumns(), instance.getVisibleLeafColumns(), instance.getState().columnPinning.left, instance.getState().columnPinning.right], (allColumns, leafColumns, left, right) => {
240
+ leafColumns = leafColumns.filter(column => !(left != null && left.includes(column.id)) && !(right != null && right.includes(column.id)));
241
+ return buildHeaderGroups(allColumns, leafColumns, instance, 'center');
242
+ }, {
243
+ key: process.env.NODE_ENV === 'development' && 'getCenterHeaderGroups',
244
+ debug: () => {
245
+ var _instance$options$deb2;
139
246
 
140
- if (columnDef.accessorFn) {
141
- accessorFn = columnDef.accessorFn;
142
- } else if (columnDef.accessorKey) {
143
- accessorFn = originalRow => originalRow[columnDef.accessorKey];
247
+ return (_instance$options$deb2 = instance.options.debugAll) != null ? _instance$options$deb2 : instance.options.debugHeaders;
144
248
  }
249
+ }),
250
+ getLeftHeaderGroups: memo(() => [instance.getAllColumns(), instance.getVisibleLeafColumns(), instance.getState().columnPinning.left], (allColumns, leafColumns, left) => {
251
+ var _left$map$filter2;
145
252
 
146
- if (!id) {
147
- if (process.env.NODE_ENV !== 'production') {
148
- throw new Error(columnDef.accessorFn ? "Columns require an id when using an accessorFn" : "Columns require an id when using a non-string header");
149
- }
253
+ const orderedLeafColumns = (_left$map$filter2 = left == null ? void 0 : left.map(columnId => leafColumns.find(d => d.id === columnId)).filter(Boolean)) != null ? _left$map$filter2 : [];
254
+ return buildHeaderGroups(allColumns, orderedLeafColumns, instance, 'left');
255
+ }, {
256
+ key: process.env.NODE_ENV === 'development' && 'getLeftHeaderGroups',
257
+ debug: () => {
258
+ var _instance$options$deb3;
150
259
 
151
- throw new Error();
260
+ return (_instance$options$deb3 = instance.options.debugAll) != null ? _instance$options$deb3 : instance.options.debugHeaders;
152
261
  }
262
+ }),
263
+ getRightHeaderGroups: memo(() => [instance.getAllColumns(), instance.getVisibleLeafColumns(), instance.getState().columnPinning.right], (allColumns, leafColumns, right) => {
264
+ var _right$map$filter2;
153
265
 
154
- let column = { ...columnDef,
155
- id: "" + id,
156
- accessorFn,
157
- parent: parent,
158
- depth,
159
- columnDef,
160
- columnDefType: columnDef.columnDefType,
161
- columns: [],
162
- getFlatColumns: memo(() => [true], () => {
163
- var _column$columns;
164
-
165
- return [column, ...((_column$columns = column.columns) == null ? void 0 : _column$columns.flatMap(d => d.getFlatColumns()))];
166
- }, {
167
- key: process.env.NODE_ENV === 'production' && 'column.getFlatColumns',
168
- debug: () => {
169
- var _instance$options$deb2;
170
-
171
- return (_instance$options$deb2 = instance.options.debugAll) != null ? _instance$options$deb2 : instance.options.debugColumns;
172
- }
173
- }),
174
- getLeafColumns: memo(() => [instance._getOrderColumnsFn()], orderColumns => {
175
- var _column$columns2;
176
-
177
- if ((_column$columns2 = column.columns) != null && _column$columns2.length) {
178
- let leafColumns = column.columns.flatMap(column => column.getLeafColumns());
179
- return orderColumns(leafColumns);
180
- }
181
-
182
- return [column];
183
- }, {
184
- key: process.env.NODE_ENV === 'production' && 'column.getLeafColumns',
185
- debug: () => {
186
- var _instance$options$deb3;
187
-
188
- return (_instance$options$deb3 = instance.options.debugAll) != null ? _instance$options$deb3 : instance.options.debugColumns;
189
- }
190
- })
191
- };
192
- column = instance._features.reduce((obj, feature) => {
193
- return Object.assign(obj, feature.createColumn == null ? void 0 : feature.createColumn(column, instance));
194
- }, column); // Yes, we have to convert instance to uknown, because we know more than the compiler here.
195
-
196
- return column;
197
- },
198
- getAllColumns: memo(() => [instance.getColumnDefs()], columnDefs => {
199
- const recurseColumns = function (columnDefs, parent, depth) {
200
- if (depth === void 0) {
201
- depth = 0;
202
- }
203
-
204
- return columnDefs.map(columnDef => {
205
- const column = instance.createColumn(columnDef, depth, parent);
206
- column.columns = columnDef.columns ? recurseColumns(columnDef.columns, column, depth + 1) : [];
207
- return column;
208
- });
209
- };
210
-
211
- return recurseColumns(columnDefs);
266
+ const orderedLeafColumns = (_right$map$filter2 = right == null ? void 0 : right.map(columnId => leafColumns.find(d => d.id === columnId)).filter(Boolean)) != null ? _right$map$filter2 : [];
267
+ return buildHeaderGroups(allColumns, orderedLeafColumns, instance, 'right');
212
268
  }, {
213
- key: process.env.NODE_ENV === 'development' && 'getAllColumns',
269
+ key: process.env.NODE_ENV === 'development' && 'getRightHeaderGroups',
214
270
  debug: () => {
215
271
  var _instance$options$deb4;
216
272
 
217
- return (_instance$options$deb4 = instance.options.debugAll) != null ? _instance$options$deb4 : instance.options.debugColumns;
273
+ return (_instance$options$deb4 = instance.options.debugAll) != null ? _instance$options$deb4 : instance.options.debugHeaders;
218
274
  }
219
275
  }),
220
- getAllFlatColumns: memo(() => [instance.getAllColumns()], allColumns => {
221
- return allColumns.flatMap(column => {
222
- return column.getFlatColumns();
223
- });
276
+ // Footer Groups
277
+ getFooterGroups: memo(() => [instance.getHeaderGroups()], headerGroups => {
278
+ return [...headerGroups].reverse();
224
279
  }, {
225
- key: process.env.NODE_ENV === 'development' && 'getAllFlatColumns',
280
+ key: process.env.NODE_ENV === 'development' && 'getFooterGroups',
226
281
  debug: () => {
227
282
  var _instance$options$deb5;
228
283
 
229
- return (_instance$options$deb5 = instance.options.debugAll) != null ? _instance$options$deb5 : instance.options.debugColumns;
284
+ return (_instance$options$deb5 = instance.options.debugAll) != null ? _instance$options$deb5 : instance.options.debugHeaders;
230
285
  }
231
286
  }),
232
- getAllFlatColumnsById: memo(() => [instance.getAllFlatColumns()], flatColumns => {
233
- return flatColumns.reduce((acc, column) => {
234
- acc[column.id] = column;
235
- return acc;
236
- }, {});
287
+ getLeftFooterGroups: memo(() => [instance.getLeftHeaderGroups()], headerGroups => {
288
+ return [...headerGroups].reverse();
237
289
  }, {
238
- key: process.env.NODE_ENV === 'development' && 'getAllFlatColumnsById',
290
+ key: process.env.NODE_ENV === 'development' && 'getLeftFooterGroups',
239
291
  debug: () => {
240
292
  var _instance$options$deb6;
241
293
 
242
- return (_instance$options$deb6 = instance.options.debugAll) != null ? _instance$options$deb6 : instance.options.debugColumns;
294
+ return (_instance$options$deb6 = instance.options.debugAll) != null ? _instance$options$deb6 : instance.options.debugHeaders;
243
295
  }
244
296
  }),
245
- getAllLeafColumns: memo(() => [instance.getAllColumns(), instance._getOrderColumnsFn()], (allColumns, orderColumns) => {
246
- let leafColumns = allColumns.flatMap(column => column.getLeafColumns());
247
- return orderColumns(leafColumns);
297
+ getCenterFooterGroups: memo(() => [instance.getCenterHeaderGroups()], headerGroups => {
298
+ return [...headerGroups].reverse();
248
299
  }, {
249
- key: process.env.NODE_ENV === 'development' && 'getAllLeafColumns',
300
+ key: process.env.NODE_ENV === 'development' && 'getCenterFooterGroups',
250
301
  debug: () => {
251
302
  var _instance$options$deb7;
252
303
 
253
- return (_instance$options$deb7 = instance.options.debugAll) != null ? _instance$options$deb7 : instance.options.debugColumns;
304
+ return (_instance$options$deb7 = instance.options.debugAll) != null ? _instance$options$deb7 : instance.options.debugHeaders;
254
305
  }
255
306
  }),
256
- getColumn: columnId => {
257
- const column = instance.getAllFlatColumnsById()[columnId];
258
-
259
- if (!column) {
260
- if (process.env.NODE_ENV !== 'production') {
261
- console.warn("[Table] Column with id " + columnId + " does not exist.");
262
- }
307
+ getRightFooterGroups: memo(() => [instance.getRightHeaderGroups()], headerGroups => {
308
+ return [...headerGroups].reverse();
309
+ }, {
310
+ key: process.env.NODE_ENV === 'development' && 'getRightFooterGroups',
311
+ debug: () => {
312
+ var _instance$options$deb8;
263
313
 
264
- throw new Error();
314
+ return (_instance$options$deb8 = instance.options.debugAll) != null ? _instance$options$deb8 : instance.options.debugHeaders;
265
315
  }
316
+ }),
317
+ // Flat Headers
318
+ getFlatHeaders: memo(() => [instance.getHeaderGroups()], headerGroups => {
319
+ return headerGroups.map(headerGroup => {
320
+ return headerGroup.headers;
321
+ }).flat();
322
+ }, {
323
+ key: process.env.NODE_ENV === 'development' && 'getFlatHeaders',
324
+ debug: () => {
325
+ var _instance$options$deb9;
266
326
 
267
- return column;
268
- }
269
- };
270
- }
271
- };
272
-
273
- //
274
- const Rows = {
275
- // createRow: <TGenerics extends TableGenerics>(
276
- // row: Row<TGenerics>,
277
- // instance: TableInstance<TGenerics>
278
- // ): CellsRow<TGenerics> => {
279
- // return {}
280
- // },
281
- createInstance: instance => {
282
- return {
283
- getRowId: (row, index, parent) => {
284
- var _instance$options$get;
285
-
286
- 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);
287
- },
288
- createRow: (id, original, rowIndex, depth, subRows) => {
289
- let row = {
290
- id,
291
- index: rowIndex,
292
- original,
293
- depth,
294
- valuesCache: {},
295
- getValue: columnId => {
296
- if (row.valuesCache.hasOwnProperty(columnId)) {
297
- return row.valuesCache[columnId];
298
- }
299
-
300
- const column = instance.getColumn(columnId);
301
-
302
- if (!column.accessorFn) {
303
- return undefined;
304
- }
305
-
306
- row.valuesCache[columnId] = column.accessorFn(row.original, rowIndex);
307
- return row.valuesCache[columnId];
308
- },
309
- subRows: subRows != null ? subRows : [],
310
- getLeafRows: () => flattenBy(row.subRows, d => d.subRows)
311
- };
327
+ return (_instance$options$deb9 = instance.options.debugAll) != null ? _instance$options$deb9 : instance.options.debugHeaders;
328
+ }
329
+ }),
330
+ getLeftFlatHeaders: memo(() => [instance.getLeftHeaderGroups()], left => {
331
+ return left.map(headerGroup => {
332
+ return headerGroup.headers;
333
+ }).flat();
334
+ }, {
335
+ key: process.env.NODE_ENV === 'development' && 'getLeftFlatHeaders',
336
+ debug: () => {
337
+ var _instance$options$deb10;
312
338
 
313
- for (let i = 0; i < instance._features.length; i++) {
314
- const feature = instance._features[i];
315
- Object.assign(row, feature == null ? void 0 : feature.createRow == null ? void 0 : feature.createRow(row, instance));
339
+ return (_instance$options$deb10 = instance.options.debugAll) != null ? _instance$options$deb10 : instance.options.debugHeaders;
316
340
  }
341
+ }),
342
+ getCenterFlatHeaders: memo(() => [instance.getCenterHeaderGroups()], left => {
343
+ return left.map(headerGroup => {
344
+ return headerGroup.headers;
345
+ }).flat();
346
+ }, {
347
+ key: process.env.NODE_ENV === 'development' && 'getCenterFlatHeaders',
348
+ debug: () => {
349
+ var _instance$options$deb11;
317
350
 
318
- return row;
319
- },
320
- getCoreRowModel: () => {
321
- if (!instance._getCoreRowModel) {
322
- instance._getCoreRowModel = instance.options.getCoreRowModel(instance);
351
+ return (_instance$options$deb11 = instance.options.debugAll) != null ? _instance$options$deb11 : instance.options.debugHeaders;
323
352
  }
353
+ }),
354
+ getRightFlatHeaders: memo(() => [instance.getRightHeaderGroups()], left => {
355
+ return left.map(headerGroup => {
356
+ return headerGroup.headers;
357
+ }).flat();
358
+ }, {
359
+ key: process.env.NODE_ENV === 'development' && 'getRightFlatHeaders',
360
+ debug: () => {
361
+ var _instance$options$deb12;
324
362
 
325
- return instance._getCoreRowModel();
326
- },
327
- // The final calls start at the bottom of the model,
328
- // expanded rows, which then work their way up
329
- getRowModel: () => {
330
- return instance.getPaginationRowModel();
331
- },
332
- getRow: id => {
333
- const row = instance.getRowModel().rowsById[id];
363
+ return (_instance$options$deb12 = instance.options.debugAll) != null ? _instance$options$deb12 : instance.options.debugHeaders;
364
+ }
365
+ }),
366
+ // Leaf Headers
367
+ getCenterLeafHeaders: memo(() => [instance.getCenterFlatHeaders()], flatHeaders => {
368
+ return flatHeaders.filter(header => {
369
+ var _header$subHeaders;
334
370
 
335
- if (!row) {
336
- if (process.env.NODE_ENV !== 'production') {
337
- throw new Error("getRow expected an ID, but got " + id);
338
- }
371
+ return !((_header$subHeaders = header.subHeaders) != null && _header$subHeaders.length);
372
+ });
373
+ }, {
374
+ key: process.env.NODE_ENV === 'development' && 'getCenterLeafHeaders',
375
+ debug: () => {
376
+ var _instance$options$deb13;
339
377
 
340
- throw new Error();
378
+ return (_instance$options$deb13 = instance.options.debugAll) != null ? _instance$options$deb13 : instance.options.debugHeaders;
341
379
  }
380
+ }),
381
+ getLeftLeafHeaders: memo(() => [instance.getLeftFlatHeaders()], flatHeaders => {
382
+ return flatHeaders.filter(header => {
383
+ var _header$subHeaders2;
342
384
 
343
- return row;
344
- }
345
- };
346
- }
347
- };
385
+ return !((_header$subHeaders2 = header.subHeaders) != null && _header$subHeaders2.length);
386
+ });
387
+ }, {
388
+ key: process.env.NODE_ENV === 'development' && 'getLeftLeafHeaders',
389
+ debug: () => {
390
+ var _instance$options$deb14;
348
391
 
349
- //
350
- const Cells = {
351
- createRow: (row, instance) => {
352
- return {
353
- getAllCells: memo(() => [instance.getAllLeafColumns()], leafColumns => {
354
- return leafColumns.map(column => {
355
- return instance.createCell(row, column, column.id);
392
+ return (_instance$options$deb14 = instance.options.debugAll) != null ? _instance$options$deb14 : instance.options.debugHeaders;
393
+ }
394
+ }),
395
+ getRightLeafHeaders: memo(() => [instance.getRightFlatHeaders()], flatHeaders => {
396
+ return flatHeaders.filter(header => {
397
+ var _header$subHeaders3;
398
+
399
+ return !((_header$subHeaders3 = header.subHeaders) != null && _header$subHeaders3.length);
356
400
  });
357
401
  }, {
358
- key: process.env.NODE_ENV === 'development' && 'row.getAllCells',
402
+ key: process.env.NODE_ENV === 'development' && 'getRightLeafHeaders',
359
403
  debug: () => {
360
- var _instance$options$deb;
404
+ var _instance$options$deb15;
361
405
 
362
- return (_instance$options$deb = instance.options.debugAll) != null ? _instance$options$deb : instance.options.debugRows;
406
+ return (_instance$options$deb15 = instance.options.debugAll) != null ? _instance$options$deb15 : instance.options.debugHeaders;
363
407
  }
364
408
  }),
365
- getAllCellsByColumnId: memo(() => [row.getAllCells()], allCells => {
366
- return allCells.reduce((acc, cell) => {
367
- acc[cell.columnId] = cell;
368
- return acc;
369
- }, {});
409
+ getLeafHeaders: memo(() => [instance.getLeftHeaderGroups(), instance.getCenterHeaderGroups(), instance.getRightHeaderGroups()], (left, center, right) => {
410
+ var _left$0$headers, _left$, _center$0$headers, _center$, _right$0$headers, _right$;
411
+
412
+ 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 => {
413
+ return header.getLeafHeaders();
414
+ }).flat();
370
415
  }, {
371
- key: process.env.NODE_ENV === 'production' && 'row.getAllCellsByColumnId',
416
+ key: process.env.NODE_ENV === 'development' && 'getLeafHeaders',
372
417
  debug: () => {
373
- var _instance$options$deb2;
418
+ var _instance$options$deb16;
374
419
 
375
- return (_instance$options$deb2 = instance.options.debugAll) != null ? _instance$options$deb2 : instance.options.debugRows;
420
+ return (_instance$options$deb16 = instance.options.debugAll) != null ? _instance$options$deb16 : instance.options.debugHeaders;
376
421
  }
377
422
  })
378
423
  };
379
- },
380
- createInstance: instance => {
381
- return {
382
- createCell: (row, column, columnId) => {
383
- const cell = {
384
- id: row.id + "_" + column.id,
385
- rowId: row.id,
386
- columnId,
387
- row,
388
- column,
389
- getValue: () => row.getValue(columnId),
390
- renderCell: () => column.columnDef.cell ? instance._render(column.columnDef.cell, {
391
- instance,
392
- column,
393
- row,
394
- cell: cell,
395
- getValue: cell.getValue
396
- }) : null
397
- };
424
+ }
425
+ };
426
+ function buildHeaderGroups(allColumns, columnsToGroup, instance, headerFamily) {
427
+ var _headerGroups$0$heade, _headerGroups$;
398
428
 
399
- instance._features.forEach(feature => {
400
- Object.assign(cell, feature.createCell == null ? void 0 : feature.createCell(cell, column, row, instance));
401
- }, {});
429
+ // Find the max depth of the columns:
430
+ // build the leaf column row
431
+ // build each buffer row going up
432
+ // placeholder for non-existent level
433
+ // real column for existing level
434
+ let maxDepth = 0;
402
435
 
403
- return cell;
404
- },
405
- getCell: (rowId, columnId) => {
406
- const row = instance.getRow(rowId);
436
+ const findMaxDepth = function (columns, depth) {
437
+ if (depth === void 0) {
438
+ depth = 1;
439
+ }
407
440
 
408
- if (!row) {
409
- if (process.env.NODE_ENV !== 'production') {
410
- throw new Error("[Table] could not find row with id " + rowId);
411
- }
441
+ maxDepth = Math.max(maxDepth, depth);
442
+ columns.filter(column => column.getIsVisible()).forEach(column => {
443
+ var _column$columns;
412
444
 
413
- throw new Error();
414
- }
445
+ if ((_column$columns = column.columns) != null && _column$columns.length) {
446
+ findMaxDepth(column.columns, depth + 1);
447
+ }
448
+ }, 0);
449
+ };
415
450
 
416
- const cell = row.getAllCellsByColumnId()[columnId];
451
+ findMaxDepth(allColumns);
452
+ let headerGroups = [];
417
453
 
418
- if (!cell) {
419
- if (process.env.NODE_ENV !== 'production') {
420
- throw new Error("[Table] could not find cell " + columnId + " in row " + rowId);
421
- }
454
+ const createHeaderGroup = (headersToGroup, depth) => {
455
+ // The header group we are creating
456
+ const headerGroup = {
457
+ depth,
458
+ id: [headerFamily, "" + depth].filter(Boolean).join('_'),
459
+ headers: []
460
+ }; // The parent columns we're going to scan next
422
461
 
423
- throw new Error();
424
- }
462
+ const pendingParentHeaders = []; // Scan each column for parents
463
+
464
+ headersToGroup.forEach(headerToGroup => {
465
+ // What is the latest (last) parent column?
466
+ const latestPendingParentHeader = [...pendingParentHeaders].reverse()[0];
467
+ const isLeafHeader = headerToGroup.column.depth === headerGroup.depth;
468
+ let column;
469
+ let isPlaceholder = false;
425
470
 
426
- return cell;
471
+ if (isLeafHeader && headerToGroup.column.parent) {
472
+ // The parent header is new
473
+ column = headerToGroup.column.parent;
474
+ } else {
475
+ // The parent header is repeated
476
+ column = headerToGroup.column;
477
+ isPlaceholder = true;
427
478
  }
428
- };
429
- }
430
- };
479
+
480
+ if ((latestPendingParentHeader == null ? void 0 : latestPendingParentHeader.column) === column) {
481
+ // This column is repeated. Add it as a sub header to the next batch
482
+ latestPendingParentHeader.subHeaders.push(headerToGroup);
483
+ } else {
484
+ // This is a new header. Let's create it
485
+ const header = createHeader(instance, column, {
486
+ id: [headerFamily, depth, column.id, headerToGroup == null ? void 0 : headerToGroup.id].filter(Boolean).join('_'),
487
+ isPlaceholder,
488
+ placeholderId: isPlaceholder ? "" + pendingParentHeaders.filter(d => d.column === column).length : undefined,
489
+ depth,
490
+ index: pendingParentHeaders.length
491
+ }); // Add the headerToGroup as a subHeader of the new header
492
+
493
+ header.subHeaders.push(headerToGroup); // Add the new header to the pendingParentHeaders to get grouped
494
+ // in the next batch
495
+
496
+ pendingParentHeaders.push(header);
497
+ }
498
+
499
+ headerGroup.headers.push(headerToGroup);
500
+ headerToGroup.headerGroup = headerGroup;
501
+ });
502
+ headerGroups.push(headerGroup);
503
+
504
+ if (depth > 0) {
505
+ createHeaderGroup(pendingParentHeaders, depth - 1);
506
+ }
507
+ };
508
+
509
+ const bottomHeaders = columnsToGroup.map((column, index) => createHeader(instance, column, {
510
+ depth: maxDepth,
511
+ index
512
+ }));
513
+ createHeaderGroup(bottomHeaders, maxDepth - 1);
514
+ headerGroups.reverse(); // headerGroups = headerGroups.filter(headerGroup => {
515
+ // return !headerGroup.headers.every(header => header.isPlaceholder)
516
+ // })
517
+
518
+ const recurseHeadersForSpans = headers => {
519
+ const filteredHeaders = headers.filter(header => header.column.getIsVisible());
520
+ return filteredHeaders.map(header => {
521
+ let colSpan = 0;
522
+ let rowSpan = 0;
523
+ let childRowSpans = [0];
524
+
525
+ if (header.subHeaders && header.subHeaders.length) {
526
+ childRowSpans = [];
527
+ recurseHeadersForSpans(header.subHeaders).forEach(_ref => {
528
+ let {
529
+ colSpan: childColSpan,
530
+ rowSpan: childRowSpan
531
+ } = _ref;
532
+ colSpan += childColSpan;
533
+ childRowSpans.push(childRowSpan);
534
+ });
535
+ } else {
536
+ colSpan = 1;
537
+ }
538
+
539
+ const minChildRowSpan = Math.min(...childRowSpans);
540
+ rowSpan = rowSpan + minChildRowSpan;
541
+ header.colSpan = colSpan;
542
+ header.rowSpan = rowSpan;
543
+ return {
544
+ colSpan,
545
+ rowSpan
546
+ };
547
+ });
548
+ };
549
+
550
+ recurseHeadersForSpans((_headerGroups$0$heade = (_headerGroups$ = headerGroups[0]) == null ? void 0 : _headerGroups$.headers) != null ? _headerGroups$0$heade : []);
551
+ return headerGroups;
552
+ }
431
553
 
432
554
  //
433
555
  const defaultColumnSizing = {
@@ -705,7 +827,6 @@ const Expanding = {
705
827
  return {
706
828
  onExpandedChange: makeStateUpdater('expanded', instance),
707
829
  autoResetExpanded: true,
708
- expandSubRows: true,
709
830
  paginateExpandedRows: true
710
831
  };
711
832
  },
@@ -974,7 +1095,7 @@ const Filters = {
974
1095
  getColumnCanGlobalFilter: column => {
975
1096
  var _instance$getCoreRowM, _instance$getCoreRowM2;
976
1097
 
977
- const value = (_instance$getCoreRowM = instance.getCoreRowModel().flatRows[0]) == null ? void 0 : (_instance$getCoreRowM2 = _instance$getCoreRowM.getAllCellsByColumnId()[column.id]) == null ? void 0 : _instance$getCoreRowM2.getValue();
1098
+ const value = (_instance$getCoreRowM = instance.getCoreRowModel().flatRows[0]) == null ? void 0 : (_instance$getCoreRowM2 = _instance$getCoreRowM._getAllCellsByColumnId()[column.id]) == null ? void 0 : _instance$getCoreRowM2.getValue();
978
1099
  return typeof value === 'string';
979
1100
  }
980
1101
  };
@@ -1102,8 +1223,7 @@ const Filters = {
1102
1223
  createRow: (row, instance) => {
1103
1224
  return {
1104
1225
  columnFilters: {},
1105
- columnFiltersMeta: {},
1106
- subRowsByFacetId: {}
1226
+ columnFiltersMeta: {}
1107
1227
  };
1108
1228
  },
1109
1229
  createInstance: instance => {
@@ -1194,53 +1314,42 @@ function shouldAutoRemoveFilter(filterFn, value, column) {
1194
1314
  return (filterFn && filterFn.autoRemove ? filterFn.autoRemove(value, column) : false) || typeof value === 'undefined' || typeof value === 'string' && !value;
1195
1315
  }
1196
1316
 
1197
- const aggregationFns = {
1198
- sum,
1199
- min,
1200
- max,
1201
- extent,
1202
- mean,
1203
- median,
1204
- unique,
1205
- uniqueCount,
1206
- count
1207
- };
1208
-
1209
- function sum(_getLeafValues, getChildValues) {
1317
+ const sum = (columnId, _leafRows, childRows) => {
1210
1318
  // It's faster to just add the aggregations together instead of
1211
1319
  // process leaf nodes individually
1212
- return getChildValues().reduce((sum, next) => sum + (typeof next === 'number' ? next : 0), 0);
1213
- }
1320
+ return childRows.reduce((sum, next) => sum + (typeof next === 'number' ? next : 0), 0);
1321
+ };
1214
1322
 
1215
- function min(_getLeafValues, getChildValues) {
1323
+ const min = (columnId, _leafRows, childRows) => {
1216
1324
  let min;
1325
+ childRows.forEach(row => {
1326
+ const value = row.getValue(columnId);
1217
1327
 
1218
- for (const value of getChildValues()) {
1219
1328
  if (value != null && (min > value || min === undefined && value >= value)) {
1220
1329
  min = value;
1221
1330
  }
1222
- }
1223
-
1331
+ });
1224
1332
  return min;
1225
- }
1333
+ };
1226
1334
 
1227
- function max(_getLeafValues, getChildValues) {
1335
+ const max = (columnId, _leafRows, childRows) => {
1228
1336
  let max;
1337
+ childRows.forEach(row => {
1338
+ const value = row.getValue(columnId);
1229
1339
 
1230
- for (const value of getChildValues()) {
1231
1340
  if (value != null && (max < value || max === undefined && value >= value)) {
1232
1341
  max = value;
1233
1342
  }
1234
- }
1235
-
1343
+ });
1236
1344
  return max;
1237
- }
1345
+ };
1238
1346
 
1239
- function extent(_getLeafValues, getChildValues) {
1347
+ const extent = (columnId, _leafRows, childRows) => {
1240
1348
  let min;
1241
1349
  let max;
1350
+ childRows.forEach(row => {
1351
+ const value = row.getValue(columnId);
1242
1352
 
1243
- for (const value of getChildValues()) {
1244
1353
  if (value != null) {
1245
1354
  if (min === undefined) {
1246
1355
  if (value >= value) min = max = value;
@@ -1249,54 +1358,65 @@ function extent(_getLeafValues, getChildValues) {
1249
1358
  if (max < value) max = value;
1250
1359
  }
1251
1360
  }
1252
- }
1253
-
1361
+ });
1254
1362
  return [min, max];
1255
- }
1363
+ };
1256
1364
 
1257
- function mean(getLeafValues) {
1365
+ const mean = (columnId, leafRows) => {
1258
1366
  let count = 0;
1259
1367
  let sum = 0;
1368
+ leafRows.forEach(row => {
1369
+ let value = row.getValue(columnId);
1260
1370
 
1261
- for (let value of getLeafValues()) {
1262
1371
  if (value != null && (value = +value) >= value) {
1263
1372
  ++count, sum += value;
1264
1373
  }
1265
- }
1266
-
1374
+ });
1267
1375
  if (count) return sum / count;
1268
1376
  return;
1269
- }
1270
-
1271
- function median(getLeafValues) {
1272
- const leafValues = getLeafValues();
1377
+ };
1273
1378
 
1274
- if (!leafValues.length) {
1379
+ const median = (columnId, leafRows) => {
1380
+ if (!leafRows.length) {
1275
1381
  return;
1276
1382
  }
1277
1383
 
1278
1384
  let min = 0;
1279
1385
  let max = 0;
1280
- leafValues.forEach(value => {
1386
+ leafRows.forEach(row => {
1387
+ let value = row.getValue(columnId);
1388
+
1281
1389
  if (typeof value === 'number') {
1282
1390
  min = Math.min(min, value);
1283
1391
  max = Math.max(max, value);
1284
1392
  }
1285
1393
  });
1286
1394
  return (min + max) / 2;
1287
- }
1395
+ };
1288
1396
 
1289
- function unique(getLeafValues) {
1290
- return Array.from(new Set(getLeafValues()).values());
1291
- }
1397
+ const unique = (columnId, leafRows) => {
1398
+ return Array.from(new Set(leafRows.map(d => d.getValue(columnId))).values());
1399
+ };
1292
1400
 
1293
- function uniqueCount(getLeafValues) {
1294
- return new Set(getLeafValues()).size;
1295
- }
1401
+ const uniqueCount = (columnId, leafRows) => {
1402
+ return new Set(leafRows.map(d => d.getValue(columnId))).size;
1403
+ };
1296
1404
 
1297
- function count(getLeafValues) {
1298
- return getLeafValues().length;
1299
- }
1405
+ const count = (_columnId, leafRows) => {
1406
+ return leafRows.length;
1407
+ };
1408
+
1409
+ const aggregationFns = {
1410
+ sum,
1411
+ min,
1412
+ max,
1413
+ extent,
1414
+ mean,
1415
+ median,
1416
+ unique,
1417
+ uniqueCount,
1418
+ count
1419
+ };
1300
1420
 
1301
1421
  //
1302
1422
  const Grouping = {
@@ -1351,7 +1471,7 @@ const Grouping = {
1351
1471
  column.toggleGrouping();
1352
1472
  };
1353
1473
  },
1354
- getColumnAutoAggregationFn: () => {
1474
+ getAutoAggregationFn: () => {
1355
1475
  const firstRow = instance.getCoreRowModel().flatRows[0];
1356
1476
  const value = firstRow == null ? void 0 : firstRow.getValue(column.id);
1357
1477
 
@@ -1365,7 +1485,7 @@ const Grouping = {
1365
1485
 
1366
1486
  return aggregationFns.count;
1367
1487
  },
1368
- getColumnAggregationFn: () => {
1488
+ getAggregationFn: () => {
1369
1489
  var _ref4;
1370
1490
 
1371
1491
  const userAggregationFns = instance.options.aggregationFns;
@@ -1374,7 +1494,7 @@ const Grouping = {
1374
1494
  throw new Error();
1375
1495
  }
1376
1496
 
1377
- return isFunction(column.aggregationFn) ? column.aggregationFn : column.aggregationFn === 'auto' ? column.getColumnAutoAggregationFn() : (_ref4 = userAggregationFns == null ? void 0 : userAggregationFns[column.aggregationFn]) != null ? _ref4 : aggregationFns[column.aggregationFn];
1497
+ return isFunction(column.aggregationFn) ? column.aggregationFn : column.aggregationFn === 'auto' ? column.getAutoAggregationFn() : (_ref4 = userAggregationFns == null ? void 0 : userAggregationFns[column.aggregationFn]) != null ? _ref4 : aggregationFns[column.aggregationFn];
1378
1498
  }
1379
1499
  };
1380
1500
  },
@@ -1400,10 +1520,10 @@ const Grouping = {
1400
1520
  }
1401
1521
  };
1402
1522
  },
1403
- createRow: (row, instance) => {
1523
+ createRow: row => {
1404
1524
  return {
1405
1525
  getIsGrouped: () => !!row.groupingColumnId,
1406
- groupingValuesCache: {}
1526
+ _groupingValuesCache: {}
1407
1527
  };
1408
1528
  },
1409
1529
  createCell: (cell, column, row, instance) => {
@@ -1752,7 +1872,7 @@ const Pinning = {
1752
1872
  return {
1753
1873
  getCenterVisibleCells: memo(() => [row._getAllVisibleCells(), instance.getState().columnPinning.left, instance.getState().columnPinning.right], (allCells, left, right) => {
1754
1874
  const leftAndRight = [...(left != null ? left : []), ...(right != null ? right : [])];
1755
- return allCells.filter(d => !leftAndRight.includes(d.columnId));
1875
+ return allCells.filter(d => !leftAndRight.includes(d.column.id));
1756
1876
  }, {
1757
1877
  key: process.env.NODE_ENV === 'production' && 'row.getCenterVisibleCells',
1758
1878
  debug: () => {
@@ -1762,7 +1882,7 @@ const Pinning = {
1762
1882
  }
1763
1883
  }),
1764
1884
  getLeftVisibleCells: memo(() => [row._getAllVisibleCells(), instance.getState().columnPinning.left,,], (allCells, left) => {
1765
- const cells = (left != null ? left : []).map(columnId => allCells.find(cell => cell.columnId === columnId)).filter(Boolean).map(d => ({ ...d,
1885
+ const cells = (left != null ? left : []).map(columnId => allCells.find(cell => cell.column.id === columnId)).filter(Boolean).map(d => ({ ...d,
1766
1886
  position: 'left'
1767
1887
  }));
1768
1888
  return cells;
@@ -1775,7 +1895,7 @@ const Pinning = {
1775
1895
  }
1776
1896
  }),
1777
1897
  getRightVisibleCells: memo(() => [row._getAllVisibleCells(), instance.getState().columnPinning.right], (allCells, right) => {
1778
- const cells = (right != null ? right : []).map(columnId => allCells.find(cell => cell.columnId === columnId)).filter(Boolean).map(d => ({ ...d,
1898
+ const cells = (right != null ? right : []).map(columnId => allCells.find(cell => cell.column.id === columnId)).filter(Boolean).map(d => ({ ...d,
1779
1899
  position: 'left'
1780
1900
  }));
1781
1901
  return cells;
@@ -2548,11 +2668,6 @@ const Visibility = {
2548
2668
  onColumnVisibilityChange: makeStateUpdater('columnVisibility', instance)
2549
2669
  };
2550
2670
  },
2551
- getDefaultColumnDef: () => {
2552
- return {
2553
- defaultIsVisible: true
2554
- };
2555
- },
2556
2671
  createColumn: (column, instance) => {
2557
2672
  return {
2558
2673
  toggleVisibility: value => {
@@ -2584,477 +2699,72 @@ const Visibility = {
2584
2699
  _getAllVisibleCells: memo(() => [row.getAllCells().filter(cell => cell.column.getIsVisible()).map(d => d.id).join('_')], _ => {
2585
2700
  return row.getAllCells().filter(cell => cell.column.getIsVisible());
2586
2701
  }, {
2587
- key: process.env.NODE_ENV === 'production' && 'row._getAllVisibleCells',
2588
- debug: () => {
2589
- var _instance$options$deb;
2590
-
2591
- return (_instance$options$deb = instance.options.debugAll) != null ? _instance$options$deb : instance.options.debugRows;
2592
- }
2593
- }),
2594
- getVisibleCells: memo(() => [row.getLeftVisibleCells(), row.getCenterVisibleCells(), row.getRightVisibleCells()], (left, center, right) => [...left, ...center, ...right], {
2595
- key: process.env.NODE_ENV === 'development' && 'row.getVisibleCells',
2596
- debug: () => {
2597
- var _instance$options$deb2;
2598
-
2599
- return (_instance$options$deb2 = instance.options.debugAll) != null ? _instance$options$deb2 : instance.options.debugRows;
2600
- }
2601
- })
2602
- };
2603
- },
2604
- createInstance: instance => {
2605
- const makeVisibleColumnsMethod = (key, getColumns) => {
2606
- return memo(() => [getColumns(), getColumns().filter(d => d.getIsVisible()).map(d => d.id).join('_')], columns => {
2607
- return columns.filter(d => d.getIsVisible == null ? void 0 : d.getIsVisible());
2608
- }, {
2609
- key,
2610
- debug: () => {
2611
- var _instance$options$deb3;
2612
-
2613
- return (_instance$options$deb3 = instance.options.debugAll) != null ? _instance$options$deb3 : instance.options.debugColumns;
2614
- }
2615
- });
2616
- };
2617
-
2618
- return {
2619
- getVisibleFlatColumns: makeVisibleColumnsMethod('getVisibleFlatColumns', () => instance.getAllFlatColumns()),
2620
- getVisibleLeafColumns: makeVisibleColumnsMethod('getVisibleLeafColumns', () => instance.getAllLeafColumns()),
2621
- getLeftVisibleLeafColumns: makeVisibleColumnsMethod('getLeftVisibleLeafColumns', () => instance.getLeftLeafColumns()),
2622
- getRightVisibleLeafColumns: makeVisibleColumnsMethod('getRightVisibleLeafColumns', () => instance.getRightLeafColumns()),
2623
- getCenterVisibleLeafColumns: makeVisibleColumnsMethod('getCenterVisibleLeafColumns', () => instance.getCenterLeafColumns()),
2624
- setColumnVisibility: updater => instance.options.onColumnVisibilityChange == null ? void 0 : instance.options.onColumnVisibilityChange(updater),
2625
- resetColumnVisibility: defaultState => {
2626
- var _instance$initialStat;
2627
-
2628
- instance.setColumnVisibility(defaultState ? {} : (_instance$initialStat = instance.initialState.columnVisibility) != null ? _instance$initialStat : {});
2629
- },
2630
- toggleAllColumnsVisible: value => {
2631
- var _value;
2632
-
2633
- value = (_value = value) != null ? _value : !instance.getIsAllColumnsVisible();
2634
- instance.setColumnVisibility(instance.getAllLeafColumns().reduce((obj, column) => ({ ...obj,
2635
- [column.id]: !value ? !(column.getCanHide != null && column.getCanHide()) : value
2636
- }), {}));
2637
- },
2638
- getIsAllColumnsVisible: () => !instance.getAllLeafColumns().some(column => !(column.getIsVisible != null && column.getIsVisible())),
2639
- getIsSomeColumnsVisible: () => instance.getAllLeafColumns().some(column => column.getIsVisible == null ? void 0 : column.getIsVisible()),
2640
- getToggleAllColumnsVisibilityHandler: () => {
2641
- return e => {
2642
- var _target;
2643
-
2644
- instance.toggleAllColumnsVisible((_target = e.target) == null ? void 0 : _target.checked);
2645
- };
2646
- }
2647
- };
2648
- }
2649
- };
2650
-
2651
- //
2652
- const Headers = {
2653
- createInstance: instance => {
2654
- return {
2655
- createHeader: (column, options) => {
2656
- var _options$id;
2657
-
2658
- const id = (_options$id = options.id) != null ? _options$id : column.id;
2659
- let header = {
2660
- id,
2661
- column,
2662
- index: options.index,
2663
- isPlaceholder: options.isPlaceholder,
2664
- placeholderId: options.placeholderId,
2665
- depth: options.depth,
2666
- subHeaders: [],
2667
- colSpan: 0,
2668
- rowSpan: 0,
2669
- headerGroup: null,
2670
- getLeafHeaders: () => {
2671
- const leafHeaders = [];
2672
-
2673
- const recurseHeader = h => {
2674
- if (h.subHeaders && h.subHeaders.length) {
2675
- h.subHeaders.map(recurseHeader);
2676
- }
2677
-
2678
- leafHeaders.push(h);
2679
- };
2680
-
2681
- recurseHeader(header);
2682
- return leafHeaders;
2683
- },
2684
- renderHeader: () => column.columnDef.header ? instance._render(column.columnDef.header, {
2685
- instance,
2686
- header: header,
2687
- column
2688
- }) : null,
2689
- renderFooter: () => column.columnDef.footer ? instance._render(column.columnDef.footer, {
2690
- instance,
2691
- header: header,
2692
- column
2693
- }) : null
2694
- };
2695
-
2696
- instance._features.forEach(feature => {
2697
- Object.assign(header, feature.createHeader == null ? void 0 : feature.createHeader(header, instance));
2698
- });
2699
-
2700
- return header;
2701
- },
2702
- // Header Groups
2703
- getHeaderGroups: memo(() => [instance.getAllColumns(), instance.getVisibleLeafColumns(), instance.getState().columnPinning.left, instance.getState().columnPinning.right], (allColumns, leafColumns, left, right) => {
2704
- var _left$map$filter, _right$map$filter;
2705
-
2706
- const leftColumns = (_left$map$filter = left == null ? void 0 : left.map(columnId => leafColumns.find(d => d.id === columnId)).filter(Boolean)) != null ? _left$map$filter : [];
2707
- const rightColumns = (_right$map$filter = right == null ? void 0 : right.map(columnId => leafColumns.find(d => d.id === columnId)).filter(Boolean)) != null ? _right$map$filter : [];
2708
- const centerColumns = leafColumns.filter(column => !(left != null && left.includes(column.id)) && !(right != null && right.includes(column.id)));
2709
- const headerGroups = buildHeaderGroups(allColumns, [...leftColumns, ...centerColumns, ...rightColumns], instance);
2710
- return headerGroups;
2711
- }, {
2712
- key: process.env.NODE_ENV === 'development' && 'getHeaderGroups',
2713
- debug: () => {
2714
- var _instance$options$deb;
2715
-
2716
- return (_instance$options$deb = instance.options.debugAll) != null ? _instance$options$deb : instance.options.debugHeaders;
2717
- }
2718
- }),
2719
- getCenterHeaderGroups: memo(() => [instance.getAllColumns(), instance.getVisibleLeafColumns(), instance.getState().columnPinning.left, instance.getState().columnPinning.right], (allColumns, leafColumns, left, right) => {
2720
- leafColumns = leafColumns.filter(column => !(left != null && left.includes(column.id)) && !(right != null && right.includes(column.id)));
2721
- return buildHeaderGroups(allColumns, leafColumns, instance, 'center');
2722
- }, {
2723
- key: process.env.NODE_ENV === 'development' && 'getCenterHeaderGroups',
2724
- debug: () => {
2725
- var _instance$options$deb2;
2726
-
2727
- return (_instance$options$deb2 = instance.options.debugAll) != null ? _instance$options$deb2 : instance.options.debugHeaders;
2728
- }
2729
- }),
2730
- getLeftHeaderGroups: memo(() => [instance.getAllColumns(), instance.getVisibleLeafColumns(), instance.getState().columnPinning.left], (allColumns, leafColumns, left) => {
2731
- var _left$map$filter2;
2732
-
2733
- const orderedLeafColumns = (_left$map$filter2 = left == null ? void 0 : left.map(columnId => leafColumns.find(d => d.id === columnId)).filter(Boolean)) != null ? _left$map$filter2 : [];
2734
- return buildHeaderGroups(allColumns, orderedLeafColumns, instance, 'left');
2735
- }, {
2736
- key: process.env.NODE_ENV === 'development' && 'getLeftHeaderGroups',
2737
- debug: () => {
2738
- var _instance$options$deb3;
2739
-
2740
- return (_instance$options$deb3 = instance.options.debugAll) != null ? _instance$options$deb3 : instance.options.debugHeaders;
2741
- }
2742
- }),
2743
- getRightHeaderGroups: memo(() => [instance.getAllColumns(), instance.getVisibleLeafColumns(), instance.getState().columnPinning.right], (allColumns, leafColumns, right) => {
2744
- var _right$map$filter2;
2745
-
2746
- const orderedLeafColumns = (_right$map$filter2 = right == null ? void 0 : right.map(columnId => leafColumns.find(d => d.id === columnId)).filter(Boolean)) != null ? _right$map$filter2 : [];
2747
- return buildHeaderGroups(allColumns, orderedLeafColumns, instance, 'right');
2748
- }, {
2749
- key: process.env.NODE_ENV === 'development' && 'getRightHeaderGroups',
2750
- debug: () => {
2751
- var _instance$options$deb4;
2752
-
2753
- return (_instance$options$deb4 = instance.options.debugAll) != null ? _instance$options$deb4 : instance.options.debugHeaders;
2754
- }
2755
- }),
2756
- // Footer Groups
2757
- getFooterGroups: memo(() => [instance.getHeaderGroups()], headerGroups => {
2758
- return [...headerGroups].reverse();
2759
- }, {
2760
- key: process.env.NODE_ENV === 'development' && 'getFooterGroups',
2761
- debug: () => {
2762
- var _instance$options$deb5;
2763
-
2764
- return (_instance$options$deb5 = instance.options.debugAll) != null ? _instance$options$deb5 : instance.options.debugHeaders;
2765
- }
2766
- }),
2767
- getLeftFooterGroups: memo(() => [instance.getLeftHeaderGroups()], headerGroups => {
2768
- return [...headerGroups].reverse();
2769
- }, {
2770
- key: process.env.NODE_ENV === 'development' && 'getLeftFooterGroups',
2771
- debug: () => {
2772
- var _instance$options$deb6;
2773
-
2774
- return (_instance$options$deb6 = instance.options.debugAll) != null ? _instance$options$deb6 : instance.options.debugHeaders;
2775
- }
2776
- }),
2777
- getCenterFooterGroups: memo(() => [instance.getCenterHeaderGroups()], headerGroups => {
2778
- return [...headerGroups].reverse();
2779
- }, {
2780
- key: process.env.NODE_ENV === 'development' && 'getCenterFooterGroups',
2781
- debug: () => {
2782
- var _instance$options$deb7;
2783
-
2784
- return (_instance$options$deb7 = instance.options.debugAll) != null ? _instance$options$deb7 : instance.options.debugHeaders;
2785
- }
2786
- }),
2787
- getRightFooterGroups: memo(() => [instance.getRightHeaderGroups()], headerGroups => {
2788
- return [...headerGroups].reverse();
2789
- }, {
2790
- key: process.env.NODE_ENV === 'development' && 'getRightFooterGroups',
2791
- debug: () => {
2792
- var _instance$options$deb8;
2793
-
2794
- return (_instance$options$deb8 = instance.options.debugAll) != null ? _instance$options$deb8 : instance.options.debugHeaders;
2795
- }
2796
- }),
2797
- // Flat Headers
2798
- getFlatHeaders: memo(() => [instance.getHeaderGroups()], headerGroups => {
2799
- return headerGroups.map(headerGroup => {
2800
- return headerGroup.headers;
2801
- }).flat();
2802
- }, {
2803
- key: process.env.NODE_ENV === 'development' && 'getFlatHeaders',
2804
- debug: () => {
2805
- var _instance$options$deb9;
2806
-
2807
- return (_instance$options$deb9 = instance.options.debugAll) != null ? _instance$options$deb9 : instance.options.debugHeaders;
2808
- }
2809
- }),
2810
- getLeftFlatHeaders: memo(() => [instance.getLeftHeaderGroups()], left => {
2811
- return left.map(headerGroup => {
2812
- return headerGroup.headers;
2813
- }).flat();
2814
- }, {
2815
- key: process.env.NODE_ENV === 'development' && 'getLeftFlatHeaders',
2816
- debug: () => {
2817
- var _instance$options$deb10;
2818
-
2819
- return (_instance$options$deb10 = instance.options.debugAll) != null ? _instance$options$deb10 : instance.options.debugHeaders;
2820
- }
2821
- }),
2822
- getCenterFlatHeaders: memo(() => [instance.getCenterHeaderGroups()], left => {
2823
- return left.map(headerGroup => {
2824
- return headerGroup.headers;
2825
- }).flat();
2826
- }, {
2827
- key: process.env.NODE_ENV === 'development' && 'getCenterFlatHeaders',
2828
- debug: () => {
2829
- var _instance$options$deb11;
2830
-
2831
- return (_instance$options$deb11 = instance.options.debugAll) != null ? _instance$options$deb11 : instance.options.debugHeaders;
2832
- }
2833
- }),
2834
- getRightFlatHeaders: memo(() => [instance.getRightHeaderGroups()], left => {
2835
- return left.map(headerGroup => {
2836
- return headerGroup.headers;
2837
- }).flat();
2838
- }, {
2839
- key: process.env.NODE_ENV === 'development' && 'getRightFlatHeaders',
2840
- debug: () => {
2841
- var _instance$options$deb12;
2842
-
2843
- return (_instance$options$deb12 = instance.options.debugAll) != null ? _instance$options$deb12 : instance.options.debugHeaders;
2844
- }
2845
- }),
2846
- // Leaf Headers
2847
- getCenterLeafHeaders: memo(() => [instance.getCenterFlatHeaders()], flatHeaders => {
2848
- return flatHeaders.filter(header => {
2849
- var _header$subHeaders;
2850
-
2851
- return !((_header$subHeaders = header.subHeaders) != null && _header$subHeaders.length);
2852
- });
2853
- }, {
2854
- key: process.env.NODE_ENV === 'development' && 'getCenterLeafHeaders',
2855
- debug: () => {
2856
- var _instance$options$deb13;
2857
-
2858
- return (_instance$options$deb13 = instance.options.debugAll) != null ? _instance$options$deb13 : instance.options.debugHeaders;
2859
- }
2860
- }),
2861
- getLeftLeafHeaders: memo(() => [instance.getLeftFlatHeaders()], flatHeaders => {
2862
- return flatHeaders.filter(header => {
2863
- var _header$subHeaders2;
2864
-
2865
- return !((_header$subHeaders2 = header.subHeaders) != null && _header$subHeaders2.length);
2866
- });
2867
- }, {
2868
- key: process.env.NODE_ENV === 'development' && 'getLeftLeafHeaders',
2869
- debug: () => {
2870
- var _instance$options$deb14;
2871
-
2872
- return (_instance$options$deb14 = instance.options.debugAll) != null ? _instance$options$deb14 : instance.options.debugHeaders;
2873
- }
2874
- }),
2875
- getRightLeafHeaders: memo(() => [instance.getRightFlatHeaders()], flatHeaders => {
2876
- return flatHeaders.filter(header => {
2877
- var _header$subHeaders3;
2878
-
2879
- return !((_header$subHeaders3 = header.subHeaders) != null && _header$subHeaders3.length);
2880
- });
2881
- }, {
2882
- key: process.env.NODE_ENV === 'development' && 'getRightLeafHeaders',
2702
+ key: process.env.NODE_ENV === 'production' && 'row._getAllVisibleCells',
2883
2703
  debug: () => {
2884
- var _instance$options$deb15;
2704
+ var _instance$options$deb;
2885
2705
 
2886
- return (_instance$options$deb15 = instance.options.debugAll) != null ? _instance$options$deb15 : instance.options.debugHeaders;
2706
+ return (_instance$options$deb = instance.options.debugAll) != null ? _instance$options$deb : instance.options.debugRows;
2887
2707
  }
2888
2708
  }),
2889
- getLeafHeaders: memo(() => [instance.getLeftHeaderGroups(), instance.getCenterHeaderGroups(), instance.getRightHeaderGroups()], (left, center, right) => {
2890
- var _left$0$headers, _left$, _center$0$headers, _center$, _right$0$headers, _right$;
2709
+ getVisibleCells: memo(() => [row.getLeftVisibleCells(), row.getCenterVisibleCells(), row.getRightVisibleCells()], (left, center, right) => [...left, ...center, ...right], {
2710
+ key: process.env.NODE_ENV === 'development' && 'row.getVisibleCells',
2711
+ debug: () => {
2712
+ var _instance$options$deb2;
2891
2713
 
2892
- 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 => {
2893
- return header.getLeafHeaders();
2894
- }).flat();
2714
+ return (_instance$options$deb2 = instance.options.debugAll) != null ? _instance$options$deb2 : instance.options.debugRows;
2715
+ }
2716
+ })
2717
+ };
2718
+ },
2719
+ createInstance: instance => {
2720
+ const makeVisibleColumnsMethod = (key, getColumns) => {
2721
+ return memo(() => [getColumns(), getColumns().filter(d => d.getIsVisible()).map(d => d.id).join('_')], columns => {
2722
+ return columns.filter(d => d.getIsVisible == null ? void 0 : d.getIsVisible());
2895
2723
  }, {
2896
- key: process.env.NODE_ENV === 'development' && 'getLeafHeaders',
2724
+ key,
2897
2725
  debug: () => {
2898
- var _instance$options$deb16;
2726
+ var _instance$options$deb3;
2899
2727
 
2900
- return (_instance$options$deb16 = instance.options.debugAll) != null ? _instance$options$deb16 : instance.options.debugHeaders;
2728
+ return (_instance$options$deb3 = instance.options.debugAll) != null ? _instance$options$deb3 : instance.options.debugColumns;
2901
2729
  }
2902
- }),
2903
- getHeader: id => {
2904
- const header = [...instance.getFlatHeaders(), ...instance.getCenterFlatHeaders(), ...instance.getLeftFlatHeaders(), ...instance.getRightFlatHeaders()].find(d => d.id === id);
2730
+ });
2731
+ };
2905
2732
 
2906
- if (!header) {
2907
- if (process.env.NODE_ENV !== 'production') {
2908
- console.warn("Could not find header with id: " + id);
2909
- }
2733
+ return {
2734
+ getVisibleFlatColumns: makeVisibleColumnsMethod('getVisibleFlatColumns', () => instance.getAllFlatColumns()),
2735
+ getVisibleLeafColumns: makeVisibleColumnsMethod('getVisibleLeafColumns', () => instance.getAllLeafColumns()),
2736
+ getLeftVisibleLeafColumns: makeVisibleColumnsMethod('getLeftVisibleLeafColumns', () => instance.getLeftLeafColumns()),
2737
+ getRightVisibleLeafColumns: makeVisibleColumnsMethod('getRightVisibleLeafColumns', () => instance.getRightLeafColumns()),
2738
+ getCenterVisibleLeafColumns: makeVisibleColumnsMethod('getCenterVisibleLeafColumns', () => instance.getCenterLeafColumns()),
2739
+ setColumnVisibility: updater => instance.options.onColumnVisibilityChange == null ? void 0 : instance.options.onColumnVisibilityChange(updater),
2740
+ resetColumnVisibility: defaultState => {
2741
+ var _instance$initialStat;
2910
2742
 
2911
- throw new Error();
2912
- }
2743
+ instance.setColumnVisibility(defaultState ? {} : (_instance$initialStat = instance.initialState.columnVisibility) != null ? _instance$initialStat : {});
2744
+ },
2745
+ toggleAllColumnsVisible: value => {
2746
+ var _value;
2913
2747
 
2914
- return header;
2748
+ value = (_value = value) != null ? _value : !instance.getIsAllColumnsVisible();
2749
+ instance.setColumnVisibility(instance.getAllLeafColumns().reduce((obj, column) => ({ ...obj,
2750
+ [column.id]: !value ? !(column.getCanHide != null && column.getCanHide()) : value
2751
+ }), {}));
2752
+ },
2753
+ getIsAllColumnsVisible: () => !instance.getAllLeafColumns().some(column => !(column.getIsVisible != null && column.getIsVisible())),
2754
+ getIsSomeColumnsVisible: () => instance.getAllLeafColumns().some(column => column.getIsVisible == null ? void 0 : column.getIsVisible()),
2755
+ getToggleAllColumnsVisibilityHandler: () => {
2756
+ return e => {
2757
+ var _target;
2758
+
2759
+ instance.toggleAllColumnsVisible((_target = e.target) == null ? void 0 : _target.checked);
2760
+ };
2915
2761
  }
2916
2762
  };
2917
2763
  }
2918
2764
  };
2919
- function buildHeaderGroups(allColumns, columnsToGroup, instance, headerFamily) {
2920
- var _headerGroups$0$heade, _headerGroups$;
2921
-
2922
- // Find the max depth of the columns:
2923
- // build the leaf column row
2924
- // build each buffer row going up
2925
- // placeholder for non-existent level
2926
- // real column for existing level
2927
- let maxDepth = 0;
2928
-
2929
- const findMaxDepth = function (columns, depth) {
2930
- if (depth === void 0) {
2931
- depth = 1;
2932
- }
2933
-
2934
- maxDepth = Math.max(maxDepth, depth);
2935
- columns.filter(column => column.getIsVisible()).forEach(column => {
2936
- var _column$columns;
2937
-
2938
- if ((_column$columns = column.columns) != null && _column$columns.length) {
2939
- findMaxDepth(column.columns, depth + 1);
2940
- }
2941
- }, 0);
2942
- };
2943
-
2944
- findMaxDepth(allColumns);
2945
- let headerGroups = [];
2946
-
2947
- const createHeaderGroup = (headersToGroup, depth) => {
2948
- // The header group we are creating
2949
- const headerGroup = {
2950
- depth,
2951
- id: [headerFamily, "" + depth].filter(Boolean).join('_'),
2952
- headers: []
2953
- }; // The parent columns we're going to scan next
2954
-
2955
- const pendingParentHeaders = []; // Scan each column for parents
2956
-
2957
- headersToGroup.forEach(headerToGroup => {
2958
- // What is the latest (last) parent column?
2959
- const latestPendingParentHeader = [...pendingParentHeaders].reverse()[0];
2960
- const isLeafHeader = headerToGroup.column.depth === headerGroup.depth;
2961
- let column;
2962
- let isPlaceholder = false;
2963
-
2964
- if (isLeafHeader && headerToGroup.column.parent) {
2965
- // The parent header is new
2966
- column = headerToGroup.column.parent;
2967
- } else {
2968
- // The parent header is repeated
2969
- column = headerToGroup.column;
2970
- isPlaceholder = true;
2971
- }
2972
-
2973
- if ((latestPendingParentHeader == null ? void 0 : latestPendingParentHeader.column) === column) {
2974
- // This column is repeated. Add it as a sub header to the next batch
2975
- latestPendingParentHeader.subHeaders.push(headerToGroup);
2976
- } else {
2977
- // This is a new header. Let's create it
2978
- const header = instance.createHeader(column, {
2979
- id: [headerFamily, depth, column.id, headerToGroup == null ? void 0 : headerToGroup.id].filter(Boolean).join('_'),
2980
- isPlaceholder,
2981
- placeholderId: isPlaceholder ? "" + pendingParentHeaders.filter(d => d.column === column).length : undefined,
2982
- depth,
2983
- index: pendingParentHeaders.length
2984
- }); // Add the headerToGroup as a subHeader of the new header
2985
-
2986
- header.subHeaders.push(headerToGroup); // Add the new header to the pendingParentHeaders to get grouped
2987
- // in the next batch
2988
-
2989
- pendingParentHeaders.push(header);
2990
- }
2991
-
2992
- headerGroup.headers.push(headerToGroup);
2993
- headerToGroup.headerGroup = headerGroup;
2994
- });
2995
- headerGroups.push(headerGroup);
2996
-
2997
- if (depth > 0) {
2998
- createHeaderGroup(pendingParentHeaders, depth - 1);
2999
- }
3000
- };
3001
-
3002
- const bottomHeaders = columnsToGroup.map((column, index) => instance.createHeader(column, {
3003
- depth: maxDepth,
3004
- index
3005
- }));
3006
- createHeaderGroup(bottomHeaders, maxDepth - 1);
3007
- headerGroups.reverse(); // headerGroups = headerGroups.filter(headerGroup => {
3008
- // return !headerGroup.headers.every(header => header.isPlaceholder)
3009
- // })
3010
-
3011
- const recurseHeadersForSpans = headers => {
3012
- const filteredHeaders = headers.filter(header => header.column.getIsVisible());
3013
- return filteredHeaders.map(header => {
3014
- let colSpan = 0;
3015
- let rowSpan = 0;
3016
- let childRowSpans = [0];
3017
-
3018
- if (header.subHeaders && header.subHeaders.length) {
3019
- childRowSpans = [];
3020
- recurseHeadersForSpans(header.subHeaders).forEach(_ref => {
3021
- let {
3022
- colSpan: childColSpan,
3023
- rowSpan: childRowSpan
3024
- } = _ref;
3025
- colSpan += childColSpan;
3026
- childRowSpans.push(childRowSpan);
3027
- });
3028
- } else {
3029
- colSpan = 1;
3030
- }
3031
-
3032
- const minChildRowSpan = Math.min(...childRowSpans);
3033
- rowSpan = rowSpan + minChildRowSpan;
3034
- header.colSpan = colSpan > 0 ? colSpan : undefined;
3035
- header.rowSpan = rowSpan > 0 ? rowSpan : undefined;
3036
- return {
3037
- colSpan,
3038
- rowSpan
3039
- };
3040
- });
3041
- };
3042
2765
 
3043
- recurseHeadersForSpans((_headerGroups$0$heade = (_headerGroups$ = headerGroups[0]) == null ? void 0 : _headerGroups$.headers) != null ? _headerGroups$0$heade : []);
3044
- return headerGroups;
3045
- }
2766
+ const features = [Headers, Visibility, Ordering, Pinning, Filters, Sorting, Grouping, Expanding, Pagination, RowSelection, ColumnSizing]; //
3046
2767
 
3047
- // export type Batch = {
3048
- // id: number
3049
- // priority: keyof CoreBatches
3050
- // tasks: (() => void)[]
3051
- // schedule: (cb: () => void) => void
3052
- // cancel: () => void
3053
- // }
3054
- // type CoreBatches = {
3055
- // data: Batch[]
3056
- // facets: Batch[]
3057
- // }
3058
2768
  function createTableInstance(options) {
3059
2769
  var _options$initialState;
3060
2770
 
@@ -3063,7 +2773,7 @@ function createTableInstance(options) {
3063
2773
  }
3064
2774
 
3065
2775
  let instance = {
3066
- _features: [Columns, Rows, Cells, Headers, Visibility, Ordering, Pinning, Filters, Sorting, Grouping, Expanding, Pagination, RowSelection, ColumnSizing]
2776
+ _features: features
3067
2777
  };
3068
2778
 
3069
2779
  const defaultOptions = instance._features.reduce((obj, feature) => {
@@ -3080,8 +2790,7 @@ function createTableInstance(options) {
3080
2790
  };
3081
2791
  };
3082
2792
 
3083
- const coreInitialState = {// coreProgress: 1,
3084
- };
2793
+ const coreInitialState = {};
3085
2794
  let initialState = { ...coreInitialState,
3086
2795
  ...((_options$initialState = options.initialState) != null ? _options$initialState : {})
3087
2796
  };
@@ -3094,16 +2803,8 @@ function createTableInstance(options) {
3094
2803
 
3095
2804
  const queued = [];
3096
2805
  let queuedTimeout = false;
3097
- const midInstance = { ...instance,
3098
- // init: () => {
3099
- // startWork()
3100
- // },
3101
- // willUpdate: () => {
3102
- // startWork()
3103
- // },
3104
- // destroy: () => {
3105
- // stopWork()
3106
- // },
2806
+ const coreInstance = {
2807
+ _features: features,
3107
2808
  options: { ...defaultOptions,
3108
2809
  ...options
3109
2810
  },
@@ -3149,29 +2850,136 @@ function createTableInstance(options) {
3149
2850
  },
3150
2851
  setState: updater => {
3151
2852
  instance.options.onStateChange == null ? void 0 : instance.options.onStateChange(updater);
3152
- } // getOverallProgress: () => {
3153
- // const { coreProgress, filtersProgress, facetProgress } =
3154
- // instance.getState()
3155
- // return mean(() =>
3156
- // [coreProgress, filtersProgress].filter(d => d < 1)
3157
- // ) as number
3158
- // },
3159
- // getProgressStage: () => {
3160
- // const { coreProgress, filtersProgress, facetProgress } =
3161
- // instance.getState()
3162
- // if (coreProgress < 1) {
3163
- // return 'coreRowModel'
3164
- // }
3165
- // if (filtersProgress < 1) {
3166
- // return 'filteredRowModel'
3167
- // }
3168
- // if (Object.values(facetProgress).some(d => d < 1)) {
3169
- // return 'facetedRowModel'
3170
- // }
3171
- // },
2853
+ },
2854
+ _getRowId: (row, index, parent) => {
2855
+ var _instance$options$get;
2856
+
2857
+ 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);
2858
+ },
2859
+ getCoreRowModel: () => {
2860
+ if (!instance._getCoreRowModel) {
2861
+ instance._getCoreRowModel = instance.options.getCoreRowModel(instance);
2862
+ }
2863
+
2864
+ return instance._getCoreRowModel();
2865
+ },
2866
+ // The final calls start at the bottom of the model,
2867
+ // expanded rows, which then work their way up
2868
+ getRowModel: () => {
2869
+ return instance.getPaginationRowModel();
2870
+ },
2871
+ getRow: id => {
2872
+ const row = instance.getRowModel().rowsById[id];
2873
+
2874
+ if (!row) {
2875
+ if (process.env.NODE_ENV !== 'production') {
2876
+ throw new Error("getRow expected an ID, but got " + id);
2877
+ }
2878
+
2879
+ throw new Error();
2880
+ }
2881
+
2882
+ return row;
2883
+ },
2884
+ _getDefaultColumnDef: memo(() => [instance.options.defaultColumn], defaultColumn => {
2885
+ var _defaultColumn;
2886
+
2887
+ defaultColumn = (_defaultColumn = defaultColumn) != null ? _defaultColumn : {};
2888
+ return {
2889
+ header: props => props.header.column.id,
2890
+ footer: props => props.header.column.id,
2891
+ cell: props => {
2892
+ var _props$getValue$toStr, _props$getValue$toStr2, _props$getValue;
2893
+
2894
+ 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;
2895
+ },
2896
+ ...instance._features.reduce((obj, feature) => {
2897
+ return Object.assign(obj, feature.getDefaultColumnDef == null ? void 0 : feature.getDefaultColumnDef());
2898
+ }, {}),
2899
+ ...defaultColumn
2900
+ };
2901
+ }, {
2902
+ debug: () => {
2903
+ var _instance$options$deb;
2904
+
2905
+ return (_instance$options$deb = instance.options.debugAll) != null ? _instance$options$deb : instance.options.debugColumns;
2906
+ },
2907
+ key: process.env.NODE_ENV === 'development' && 'getDefaultColumnDef'
2908
+ }),
2909
+ _getColumnDefs: () => instance.options.columns,
2910
+ getAllColumns: memo(() => [instance._getColumnDefs()], columnDefs => {
2911
+ const recurseColumns = function (columnDefs, parent, depth) {
2912
+ if (depth === void 0) {
2913
+ depth = 0;
2914
+ }
2915
+
2916
+ return columnDefs.map(columnDef => {
2917
+ const column = createColumn(instance, columnDef, depth, parent);
2918
+ column.columns = columnDef.columns ? recurseColumns(columnDef.columns, column, depth + 1) : [];
2919
+ return column;
2920
+ });
2921
+ };
2922
+
2923
+ return recurseColumns(columnDefs);
2924
+ }, {
2925
+ key: process.env.NODE_ENV === 'development' && 'getAllColumns',
2926
+ debug: () => {
2927
+ var _instance$options$deb2;
2928
+
2929
+ return (_instance$options$deb2 = instance.options.debugAll) != null ? _instance$options$deb2 : instance.options.debugColumns;
2930
+ }
2931
+ }),
2932
+ getAllFlatColumns: memo(() => [instance.getAllColumns()], allColumns => {
2933
+ return allColumns.flatMap(column => {
2934
+ return column.getFlatColumns();
2935
+ });
2936
+ }, {
2937
+ key: process.env.NODE_ENV === 'development' && 'getAllFlatColumns',
2938
+ debug: () => {
2939
+ var _instance$options$deb3;
2940
+
2941
+ return (_instance$options$deb3 = instance.options.debugAll) != null ? _instance$options$deb3 : instance.options.debugColumns;
2942
+ }
2943
+ }),
2944
+ _getAllFlatColumnsById: memo(() => [instance.getAllFlatColumns()], flatColumns => {
2945
+ return flatColumns.reduce((acc, column) => {
2946
+ acc[column.id] = column;
2947
+ return acc;
2948
+ }, {});
2949
+ }, {
2950
+ key: process.env.NODE_ENV === 'development' && 'getAllFlatColumnsById',
2951
+ debug: () => {
2952
+ var _instance$options$deb4;
2953
+
2954
+ return (_instance$options$deb4 = instance.options.debugAll) != null ? _instance$options$deb4 : instance.options.debugColumns;
2955
+ }
2956
+ }),
2957
+ getAllLeafColumns: memo(() => [instance.getAllColumns(), instance._getOrderColumnsFn()], (allColumns, orderColumns) => {
2958
+ let leafColumns = allColumns.flatMap(column => column.getLeafColumns());
2959
+ return orderColumns(leafColumns);
2960
+ }, {
2961
+ key: process.env.NODE_ENV === 'development' && 'getAllLeafColumns',
2962
+ debug: () => {
2963
+ var _instance$options$deb5;
2964
+
2965
+ return (_instance$options$deb5 = instance.options.debugAll) != null ? _instance$options$deb5 : instance.options.debugColumns;
2966
+ }
2967
+ }),
2968
+ getColumn: columnId => {
2969
+ const column = instance._getAllFlatColumnsById()[columnId];
2970
+
2971
+ if (!column) {
2972
+ if (process.env.NODE_ENV !== 'production') {
2973
+ console.warn("[Table] Column with id " + columnId + " does not exist.");
2974
+ }
2975
+
2976
+ throw new Error();
2977
+ }
3172
2978
 
2979
+ return column;
2980
+ }
3173
2981
  };
3174
- instance = Object.assign(instance, midInstance);
2982
+ Object.assign(instance, coreInstance);
3175
2983
 
3176
2984
  instance._features.forEach(feature => {
3177
2985
  return Object.assign(instance, feature.createInstance == null ? void 0 : feature.createInstance(instance));
@@ -3236,6 +3044,86 @@ function createTable$1(_, __, options) {
3236
3044
  return table;
3237
3045
  }
3238
3046
 
3047
+ function createCell(instance, row, column, columnId) {
3048
+ const cell = {
3049
+ id: row.id + "_" + column.id,
3050
+ row,
3051
+ column,
3052
+ getValue: () => row.getValue(columnId),
3053
+ renderCell: () => column.columnDef.cell ? instance._render(column.columnDef.cell, {
3054
+ instance,
3055
+ column,
3056
+ row,
3057
+ cell: cell,
3058
+ getValue: cell.getValue
3059
+ }) : null
3060
+ };
3061
+
3062
+ instance._features.forEach(feature => {
3063
+ Object.assign(cell, feature.createCell == null ? void 0 : feature.createCell(cell, column, row, instance));
3064
+ }, {});
3065
+
3066
+ return cell;
3067
+ }
3068
+
3069
+ const createRow = (instance, id, original, rowIndex, depth, subRows) => {
3070
+ let row = {
3071
+ id,
3072
+ index: rowIndex,
3073
+ original,
3074
+ depth,
3075
+ _valuesCache: {},
3076
+ getValue: columnId => {
3077
+ if (row._valuesCache.hasOwnProperty(columnId)) {
3078
+ return row._valuesCache[columnId];
3079
+ }
3080
+
3081
+ const column = instance.getColumn(columnId);
3082
+
3083
+ if (!column.accessorFn) {
3084
+ return undefined;
3085
+ }
3086
+
3087
+ row._valuesCache[columnId] = column.accessorFn(row.original, rowIndex);
3088
+ return row._valuesCache[columnId];
3089
+ },
3090
+ subRows: subRows != null ? subRows : [],
3091
+ getLeafRows: () => flattenBy(row.subRows, d => d.subRows),
3092
+ getAllCells: memo(() => [instance.getAllLeafColumns()], leafColumns => {
3093
+ return leafColumns.map(column => {
3094
+ return createCell(instance, row, column, column.id);
3095
+ });
3096
+ }, {
3097
+ key: process.env.NODE_ENV === 'development' && 'row.getAllCells',
3098
+ debug: () => {
3099
+ var _instance$options$deb;
3100
+
3101
+ return (_instance$options$deb = instance.options.debugAll) != null ? _instance$options$deb : instance.options.debugRows;
3102
+ }
3103
+ }),
3104
+ _getAllCellsByColumnId: memo(() => [row.getAllCells()], allCells => {
3105
+ return allCells.reduce((acc, cell) => {
3106
+ acc[cell.column.id] = cell;
3107
+ return acc;
3108
+ }, {});
3109
+ }, {
3110
+ key: process.env.NODE_ENV === 'production' && 'row.getAllCellsByColumnId',
3111
+ debug: () => {
3112
+ var _instance$options$deb2;
3113
+
3114
+ return (_instance$options$deb2 = instance.options.debugAll) != null ? _instance$options$deb2 : instance.options.debugRows;
3115
+ }
3116
+ })
3117
+ };
3118
+
3119
+ for (let i = 0; i < instance._features.length; i++) {
3120
+ const feature = instance._features[i];
3121
+ Object.assign(row, feature == null ? void 0 : feature.createRow == null ? void 0 : feature.createRow(row, instance));
3122
+ }
3123
+
3124
+ return row;
3125
+ };
3126
+
3239
3127
  function getCoreRowModel() {
3240
3128
  return instance => memo(() => [instance.options.data], data => {
3241
3129
  const rowModel = {
@@ -3263,7 +3151,7 @@ function getCoreRowModel() {
3263
3151
  // }
3264
3152
  // Make the row
3265
3153
 
3266
- row = instance.createRow(instance.getRowId(originalRow, i, parent), originalRow, i, depth); // Keep track of every row in a flat array
3154
+ row = createRow(instance, instance._getRowId(originalRow, i, parent), originalRow, i, depth); // Keep track of every row in a flat array
3267
3155
 
3268
3156
  rowModel.flatRows.push(row); // Also keep track of every row by its ID
3269
3157
 
@@ -3326,7 +3214,7 @@ function filterRowModelFromLeafs(rowsToFilter, filterRow, instance) {
3326
3214
  row = rowsToFilter[i];
3327
3215
 
3328
3216
  if ((_row$subRows = row.subRows) != null && _row$subRows.length) {
3329
- newRow = instance.createRow(row.id, row.original, row.index, row.depth);
3217
+ newRow = createRow(instance, row.id, row.original, row.index, row.depth);
3330
3218
  newRow.columnFilters = row.columnFilters;
3331
3219
  newRow.subRows = recurseFilterRows(row.subRows, depth + 1);
3332
3220
 
@@ -3376,7 +3264,7 @@ function filterRowModelFromRoot(rowsToFilter, filterRow, instance) {
3376
3264
  var _row$subRows2;
3377
3265
 
3378
3266
  if ((_row$subRows2 = row.subRows) != null && _row$subRows2.length) {
3379
- newRow = instance.createRow(row.id, row.original, row.index, row.depth);
3267
+ newRow = createRow(instance, row.id, row.original, row.index, row.depth);
3380
3268
  newRow.subRows = recurseFilterRows(row.subRows, depth + 1);
3381
3269
  row = newRow;
3382
3270
  }
@@ -3743,7 +3631,7 @@ function getGroupedRowModel() {
3743
3631
  const subRows = groupUpRecursively(groupedRows, depth + 1, id); // Flatten the leaf rows of the rows in this group
3744
3632
 
3745
3633
  const leafRows = depth ? flattenBy(groupedRows, row => row.subRows) : groupedRows;
3746
- const row = instance.createRow(id, undefined, index, depth);
3634
+ const row = createRow(instance, id, undefined, index, depth);
3747
3635
  Object.assign(row, {
3748
3636
  groupingColumnId: columnId,
3749
3637
  groupingValue,
@@ -3752,38 +3640,30 @@ function getGroupedRowModel() {
3752
3640
  getValue: columnId => {
3753
3641
  // Don't aggregate columns that are in the grouping
3754
3642
  if (existingGrouping.includes(columnId)) {
3755
- if (row.valuesCache.hasOwnProperty(columnId)) {
3756
- return row.valuesCache[columnId];
3643
+ if (row._valuesCache.hasOwnProperty(columnId)) {
3644
+ return row._valuesCache[columnId];
3757
3645
  }
3758
3646
 
3759
3647
  if (groupedRows[0]) {
3760
3648
  var _groupedRows$0$getVal;
3761
3649
 
3762
- row.valuesCache[columnId] = (_groupedRows$0$getVal = groupedRows[0].getValue(columnId)) != null ? _groupedRows$0$getVal : undefined;
3650
+ row._valuesCache[columnId] = (_groupedRows$0$getVal = groupedRows[0].getValue(columnId)) != null ? _groupedRows$0$getVal : undefined;
3763
3651
  }
3764
3652
 
3765
- return row.valuesCache[columnId];
3653
+ return row._valuesCache[columnId];
3766
3654
  }
3767
3655
 
3768
- if (row.groupingValuesCache.hasOwnProperty(columnId)) {
3769
- return row.groupingValuesCache[columnId];
3656
+ if (row._groupingValuesCache.hasOwnProperty(columnId)) {
3657
+ return row._groupingValuesCache[columnId];
3770
3658
  } // Aggregate the values
3771
3659
 
3772
3660
 
3773
3661
  const column = instance.getColumn(columnId);
3774
- const aggregateFn = column.getColumnAggregationFn();
3662
+ const aggregateFn = column.getAggregationFn();
3775
3663
 
3776
3664
  if (aggregateFn) {
3777
- row.groupingValuesCache[columnId] = aggregateFn(() => leafRows.map(row => {
3778
- let columnValue = row.getValue(columnId);
3779
-
3780
- if (!depth && column.columnDef.aggregateValue) {
3781
- columnValue = column.columnDef.aggregateValue(columnValue);
3782
- }
3783
-
3784
- return columnValue;
3785
- }), () => groupedRows.map(row => row.getValue(columnId)));
3786
- return row.groupingValuesCache[columnId];
3665
+ row._groupingValuesCache[columnId] = aggregateFn(columnId, leafRows, groupedRows);
3666
+ return row._groupingValuesCache[columnId];
3787
3667
  } else if (column.aggregationFn) {
3788
3668
  console.info({
3789
3669
  column
@@ -3863,7 +3743,7 @@ function getExpandedRowModel() {
3863
3743
  return rowModel;
3864
3744
  }
3865
3745
 
3866
- return expandRows(rowModel, instance);
3746
+ return expandRows(rowModel);
3867
3747
  }, {
3868
3748
  key: process.env.NODE_ENV === 'development' && 'getExpandedRowModel',
3869
3749
  debug: () => {
@@ -3881,7 +3761,7 @@ function expandRows(rowModel, instance) {
3881
3761
 
3882
3762
  expandedRows.push(row);
3883
3763
 
3884
- if (instance.options.expandSubRows && (_row$subRows = row.subRows) != null && _row$subRows.length && row.getIsExpanded()) {
3764
+ if ((_row$subRows = row.subRows) != null && _row$subRows.length && row.getIsExpanded()) {
3885
3765
  row.subRows.forEach(handleRow);
3886
3766
  }
3887
3767
  };
@@ -3918,7 +3798,7 @@ function getPaginationRowModel(opts) {
3918
3798
  rows,
3919
3799
  flatRows,
3920
3800
  rowsById
3921
- }, instance);
3801
+ });
3922
3802
  }
3923
3803
 
3924
3804
  return {
@@ -3992,5 +3872,5 @@ function useTableInstance(table, options) {
3992
3872
  return instanceRef.current;
3993
3873
  }
3994
3874
 
3995
- export { ColumnSizing, Expanding, Filters, Grouping, Headers, Ordering, Pagination, Pinning, RowSelection, Sorting, Visibility, aggregationFns, buildHeaderGroups, createTable, createTableFactory, createTableInstance, defaultColumnSizing, expandRows, filterFns, flattenBy, functionalUpdate, getCoreRowModel, getExpandedRowModel, getFacetedMinMaxValues, getFacetedRowModel, getFacetedUniqueValues, getFilteredRowModel, getGroupedRowModel, getPaginationRowModel, getSortedRowModel, isFunction, isRowSelected, makeStateUpdater, mean, memo, noop, orderColumns, passiveEventSupported, reSplitAlphaNumeric, render, selectRowsFn, shouldAutoRemoveFilter, sortingFns, useTableInstance };
3875
+ export { ColumnSizing, Expanding, Filters, Grouping, Headers, Ordering, Pagination, Pinning, RowSelection, Sorting, Visibility, aggregationFns, buildHeaderGroups, createColumn, createRow, createTable, createTableFactory, createTableInstance, defaultColumnSizing, expandRows, filterFns, flattenBy, functionalUpdate, getCoreRowModel, getExpandedRowModel, getFacetedMinMaxValues, getFacetedRowModel, getFacetedUniqueValues, getFilteredRowModel, getGroupedRowModel, getPaginationRowModel, getSortedRowModel, isFunction, isRowSelected, makeStateUpdater, memo, noop, orderColumns, passiveEventSupported, reSplitAlphaNumeric, render, selectRowsFn, shouldAutoRemoveFilter, sortingFns, useTableInstance };
3996
3876
  //# sourceMappingURL=index.js.map