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