@tanstack/table-core 9.0.0-beta.19 → 9.0.0-beta.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. package/dist/core/cells/constructCell.d.cts +1 -1
  2. package/dist/core/cells/constructCell.d.ts +1 -1
  3. package/dist/core/cells/coreCellsFeature.types.d.cts +1 -1
  4. package/dist/core/cells/coreCellsFeature.types.d.ts +1 -1
  5. package/dist/core/cells/coreCellsFeature.utils.d.cts +1 -1
  6. package/dist/core/cells/coreCellsFeature.utils.d.ts +1 -1
  7. package/dist/core/columns/constructColumn.cjs +5 -0
  8. package/dist/core/columns/constructColumn.cjs.map +1 -1
  9. package/dist/core/columns/constructColumn.d.cts +2 -2
  10. package/dist/core/columns/constructColumn.d.ts +2 -2
  11. package/dist/core/columns/constructColumn.js +5 -0
  12. package/dist/core/columns/constructColumn.js.map +1 -1
  13. package/dist/core/columns/coreColumnsFeature.types.d.cts +2 -2
  14. package/dist/core/columns/coreColumnsFeature.types.d.ts +2 -2
  15. package/dist/core/columns/coreColumnsFeature.utils.d.cts +2 -2
  16. package/dist/core/columns/coreColumnsFeature.utils.d.ts +2 -2
  17. package/dist/core/headers/buildHeaderGroups.d.cts +1 -1
  18. package/dist/core/headers/buildHeaderGroups.d.ts +1 -1
  19. package/dist/core/headers/constructHeader.d.cts +1 -1
  20. package/dist/core/headers/constructHeader.d.ts +1 -1
  21. package/dist/core/headers/coreHeadersFeature.types.d.cts +1 -1
  22. package/dist/core/headers/coreHeadersFeature.types.d.ts +1 -1
  23. package/dist/core/headers/coreHeadersFeature.utils.d.cts +1 -1
  24. package/dist/core/headers/coreHeadersFeature.utils.d.ts +1 -1
  25. package/dist/core/row-models/coreRowModelsFeature.types.d.cts +1 -1
  26. package/dist/core/row-models/coreRowModelsFeature.types.d.ts +1 -1
  27. package/dist/features/column-faceting/columnFacetingFeature.utils.d.cts +1 -1
  28. package/dist/features/column-faceting/columnFacetingFeature.utils.d.ts +1 -1
  29. package/dist/features/column-filtering/columnFilteringFeature.types.d.cts +1 -1
  30. package/dist/features/column-filtering/columnFilteringFeature.types.d.ts +1 -1
  31. package/dist/features/column-filtering/columnFilteringFeature.utils.d.cts +1 -1
  32. package/dist/features/column-filtering/columnFilteringFeature.utils.d.ts +1 -1
  33. package/dist/features/column-grouping/columnGroupingFeature.utils.d.cts +1 -1
  34. package/dist/features/column-grouping/columnGroupingFeature.utils.d.ts +1 -1
  35. package/dist/features/column-ordering/columnOrderingFeature.utils.d.cts +1 -1
  36. package/dist/features/column-ordering/columnOrderingFeature.utils.d.ts +1 -1
  37. package/dist/features/column-pinning/columnPinningFeature.utils.d.cts +1 -1
  38. package/dist/features/column-pinning/columnPinningFeature.utils.d.ts +1 -1
  39. package/dist/features/column-resizing/columnResizingFeature.utils.d.cts +1 -1
  40. package/dist/features/column-resizing/columnResizingFeature.utils.d.ts +1 -1
  41. package/dist/features/column-sizing/columnSizingFeature.utils.d.cts +1 -1
  42. package/dist/features/column-sizing/columnSizingFeature.utils.d.ts +1 -1
  43. package/dist/features/column-visibility/columnVisibilityFeature.utils.d.cts +1 -1
  44. package/dist/features/column-visibility/columnVisibilityFeature.utils.d.ts +1 -1
  45. package/dist/features/global-filtering/globalFilteringFeature.types.d.cts +1 -1
  46. package/dist/features/global-filtering/globalFilteringFeature.types.d.ts +1 -1
  47. package/dist/features/global-filtering/globalFilteringFeature.utils.d.cts +1 -1
  48. package/dist/features/global-filtering/globalFilteringFeature.utils.d.ts +1 -1
  49. package/dist/features/row-pinning/rowPinningFeature.utils.cjs +2 -2
  50. package/dist/features/row-pinning/rowPinningFeature.utils.cjs.map +1 -1
  51. package/dist/features/row-pinning/rowPinningFeature.utils.js +2 -2
  52. package/dist/features/row-pinning/rowPinningFeature.utils.js.map +1 -1
  53. package/dist/features/row-sorting/rowSortingFeature.types.d.cts +1 -1
  54. package/dist/features/row-sorting/rowSortingFeature.types.d.ts +1 -1
  55. package/dist/features/row-sorting/rowSortingFeature.utils.d.cts +1 -1
  56. package/dist/features/row-sorting/rowSortingFeature.utils.d.ts +1 -1
  57. package/dist/index.d.cts +9 -9
  58. package/dist/index.d.ts +9 -9
  59. package/dist/types/Column.d.cts +4 -4
  60. package/dist/types/Column.d.ts +4 -4
  61. package/dist/types/ColumnDef.d.cts +3 -3
  62. package/dist/types/ColumnDef.d.ts +3 -3
  63. package/dist/types/Row.d.cts +1 -1
  64. package/dist/types/Row.d.ts +1 -1
  65. package/dist/types/RowModel.d.cts +1 -1
  66. package/dist/types/RowModel.d.ts +1 -1
  67. package/dist/types/RowModelFns.d.cts +1 -1
  68. package/dist/types/RowModelFns.d.ts +1 -1
  69. package/dist/types/Table.d.cts +5 -5
  70. package/dist/types/Table.d.ts +5 -5
  71. package/dist/types/TableFeatures.d.cts +154 -15
  72. package/dist/types/TableFeatures.d.ts +154 -15
  73. package/dist/types/TableOptions.d.cts +6 -6
  74. package/dist/types/TableOptions.d.ts +6 -6
  75. package/dist/types/TableState.d.cts +4 -4
  76. package/dist/types/TableState.d.ts +4 -4
  77. package/package.json +1 -1
  78. package/src/core/columns/constructColumn.ts +6 -0
  79. package/src/types/TableFeatures.ts +161 -15
@@ -1,22 +1,46 @@
1
1
  import { CellData, RowData, UnionToIntersection } from "./type-utils.cjs";
2
2
  import { CoreFeatures } from "../core/coreFeatures.cjs";
3
- import { SortFn } from "../features/row-sorting/rowSortingFeature.types.cjs";
4
3
  import { Row } from "./Row.cjs";
5
4
  import { FilterFn } from "../features/column-filtering/columnFilteringFeature.types.cjs";
5
+ import { SortFn } from "../features/row-sorting/rowSortingFeature.types.cjs";
6
6
  import { TableState_All } from "./TableState.cjs";
7
+ import { ColumnDefBase_All } from "./ColumnDef.cjs";
7
8
  import { TableOptions_All } from "./TableOptions.cjs";
8
9
  import { Table } from "./Table.cjs";
9
- import { ColumnDefBase_All } from "./ColumnDef.cjs";
10
+ import { Column } from "./Column.cjs";
10
11
  import { StockFeatures } from "../features/stockFeatures.cjs";
11
12
  import { RowModel } from "../core/row-models/coreRowModelsFeature.types.cjs";
12
13
  import { AggregationFn } from "../features/column-grouping/columnGroupingFeature.types.cjs";
13
14
 
14
15
  //#region src/types/TableFeatures.d.ts
16
+ /**
17
+ * Detects whether a type is `any`.
18
+ *
19
+ * Several feature-map helpers need a separate `any` path so broad generic
20
+ * usage still exposes all known feature APIs instead of narrowing to no keys.
21
+ */
15
22
  type IsAny<T> = 0 extends 1 & T ? true : false;
23
+ /**
24
+ * Converts a union to an intersection, returning `{}` for `never`.
25
+ *
26
+ * This keeps empty feature-map lookups usable as an intersection member.
27
+ */
16
28
  type UnionToIntersectionOrEmpty<T> = [T] extends [never] ? {} : UnionToIntersection<T> & {};
29
+ /**
30
+ * Extracts the API/types contributed by the features present in `TFeatures`.
31
+ *
32
+ * `TFeatureMap` maps feature keys to the types they contribute. When
33
+ * `TFeatures` is `any`, all feature-map entries are included to preserve the
34
+ * permissive behavior expected by broad table types. Otherwise, only entries
35
+ * whose keys are present in `TFeatures` are intersected together.
36
+ */
17
37
  type ExtractFeatureMapTypes<TFeatures extends TableFeatures, TFeatureMap extends object> = IsAny<TFeatures> extends true ? UnionToIntersection<TFeatureMap[keyof TFeatureMap]> : UnionToIntersectionOrEmpty<TFeatureMap[Extract<keyof TFeatures, keyof TFeatureMap>]>;
18
38
  /**
19
- * This is an interface that you can delcaration-merge into to allow for custom plugins to be added to the table.
39
+ * Declaration-merge target for custom table features.
40
+ *
41
+ * Add custom feature keys here so `TableFeatures` can accept them in the
42
+ * `features` option and use the same feature-map extraction system as built-in
43
+ * features.
20
44
  */
21
45
  interface Plugins {}
22
46
  /**
@@ -36,19 +60,61 @@ type NonFeatureKeys = 'aggregationFns' | 'columnMeta' | 'coreRowModel' | 'expand
36
60
  * interface to get the same validation from `tableFeatures()`.
37
61
  */
38
62
  interface FeatureSlotPrereqs {
63
+ /**
64
+ * Named aggregation functions are only meaningful when grouping is enabled.
65
+ */
39
66
  aggregationFns: 'columnGroupingFeature';
67
+ /**
68
+ * Column resizing builds on the column sizing state and APIs.
69
+ */
40
70
  columnResizingFeature: 'columnSizingFeature';
71
+ /**
72
+ * Expanded row-model factories require row expanding APIs and state.
73
+ */
41
74
  expandedRowModel: 'rowExpandingFeature';
75
+ /**
76
+ * Faceted min/max factories require column faceting APIs.
77
+ */
42
78
  facetedMinMaxValues: 'columnFacetingFeature';
79
+ /**
80
+ * Faceted row-model factories require column faceting APIs.
81
+ */
43
82
  facetedRowModel: 'columnFacetingFeature';
83
+ /**
84
+ * Faceted unique-value factories require column faceting APIs.
85
+ */
44
86
  facetedUniqueValues: 'columnFacetingFeature';
87
+ /**
88
+ * Filtered row-model factories require column filtering APIs and state.
89
+ */
45
90
  filteredRowModel: 'columnFilteringFeature';
91
+ /**
92
+ * Named filter functions are only meaningful when column filtering is enabled.
93
+ */
46
94
  filterFns: 'columnFilteringFeature';
95
+ /**
96
+ * Filter metadata types are only read and written by filtering features.
97
+ */
47
98
  filterMeta: 'columnFilteringFeature';
99
+ /**
100
+ * Global filtering builds on column filtering state and filter functions.
101
+ */
48
102
  globalFilteringFeature: 'columnFilteringFeature';
103
+ /**
104
+ * Grouped row-model factories require column grouping APIs and state.
105
+ */
49
106
  groupedRowModel: 'columnGroupingFeature';
107
+ /**
108
+ * Paginated row-model factories require row pagination APIs and state.
109
+ */
50
110
  paginatedRowModel: 'rowPaginationFeature';
111
+ /**
112
+ * Sorted row-model factories require row sorting APIs and state.
113
+ */
51
114
  sortedRowModel: 'rowSortingFeature';
115
+ /**
116
+ * Named sorting functions are only meaningful when row sorting is enabled.
117
+ */
52
118
  sortFns: 'rowSortingFeature';
53
119
  }
54
120
  /**
@@ -60,6 +126,15 @@ interface FeatureSlotPrereqs {
60
126
  * naming the feature that needs to be added.
61
127
  */
62
128
  type ValidateFeatureSlots<TFeatures extends TableFeatures> = IsAny<TFeatures> extends true ? {} : { [K in keyof TFeatures as K extends keyof FeatureSlotPrereqs ? K : never]: K extends keyof FeatureSlotPrereqs ? [Extract<FeatureSlotPrereqs[K], keyof TFeatures>] extends [never] ? `Error: '${K & string}' requires '${FeatureSlotPrereqs[K] & string}' to be included in this table's features.` : TFeatures[K] : never };
129
+ /**
130
+ * Complete feature registry for a table.
131
+ *
132
+ * This type combines core features, stock features, declaration-merged custom
133
+ * plugins, row-model factory slots, function registries, and type-only meta
134
+ * slots. The concrete `features` object passed to `tableFeatures()` determines
135
+ * which feature APIs are included throughout table, row, column, cell, header,
136
+ * options, and state types.
137
+ */
63
138
  interface TableFeatures extends Partial<CoreFeatures>, Partial<StockFeatures>, Partial<Plugins> {
64
139
  /**
65
140
  * Registry of aggregation functions available to this table by name.
@@ -174,38 +249,102 @@ interface TableFeatures extends Partial<CoreFeatures>, Partial<StockFeatures>, P
174
249
  */
175
250
  tableMeta?: object;
176
251
  }
252
+ /**
253
+ * Lifecycle hooks and defaults contributed by a table feature.
254
+ *
255
+ * Feature objects are registered in the table's `features` option. They can
256
+ * contribute default state/options, default column definitions, table APIs,
257
+ * shared prototype APIs for rows/columns/headers/cells, and per-instance row
258
+ * or column data.
259
+ */
177
260
  interface TableFeature {
178
261
  /**
179
- * Assigns Cell APIs to the cell prototype for memory-efficient method sharing.
180
- * This is called once per table to build a shared prototype for all cells.
262
+ * Adds feature methods to the shared cell prototype for a table.
263
+ *
264
+ * This runs lazily the first time a cell is constructed for a table. Methods
265
+ * assigned here are shared by every cell instance created by that table, so
266
+ * this hook should be used for APIs and memoized methods rather than
267
+ * per-cell mutable data.
181
268
  */
182
269
  assignCellPrototype?: <TFeatures extends TableFeatures, TData extends RowData>(prototype: Record<string, any>, table: Table<TFeatures, TData>) => void;
183
270
  /**
184
- * Assigns Column APIs to the column prototype for memory-efficient method sharing.
185
- * This is called once per table to build a shared prototype for all columns.
271
+ * Adds feature methods to the shared column prototype for a table.
272
+ *
273
+ * This runs lazily the first time a column is constructed for a table.
274
+ * Methods assigned here are shared by every column instance created by that
275
+ * table, so this hook should be used for APIs and memoized methods rather
276
+ * than per-column mutable data.
186
277
  */
187
278
  assignColumnPrototype?: <TFeatures extends TableFeatures, TData extends RowData>(prototype: Record<string, any>, table: Table<TFeatures, TData>) => void;
188
279
  /**
189
- * Assigns Header APIs to the header prototype for memory-efficient method sharing.
190
- * This is called once per table to build a shared prototype for all headers.
280
+ * Adds feature methods to the shared header prototype for a table.
281
+ *
282
+ * This runs lazily the first time a header is constructed for a table.
283
+ * Methods assigned here are shared by every header instance created by that
284
+ * table, so this hook should be used for APIs and memoized methods rather
285
+ * than per-header mutable data.
191
286
  */
192
287
  assignHeaderPrototype?: <TFeatures extends TableFeatures, TData extends RowData>(prototype: Record<string, any>, table: Table<TFeatures, TData>) => void;
193
288
  /**
194
- * Assigns Row APIs to the row prototype for memory-efficient method sharing.
195
- * This is called once per table to build a shared prototype for all rows.
289
+ * Adds feature methods to the shared row prototype for a table.
290
+ *
291
+ * This runs lazily the first time a row is constructed for a table. Methods
292
+ * assigned here are shared by every row instance created by that table, so
293
+ * this hook should be used for APIs and memoized methods rather than per-row
294
+ * mutable data.
196
295
  */
197
296
  assignRowPrototype?: <TFeatures extends TableFeatures, TData extends RowData>(prototype: Record<string, any>, table: Table<TFeatures, TData>) => void;
198
297
  /**
199
- * Assigns Table APIs to the table instance.
200
- * Unlike row/cell/column/header, the table is a singleton so methods are assigned directly.
298
+ * Adds feature APIs directly to the table instance.
299
+ *
300
+ * The table is a singleton, unlike rows, columns, headers, and cells, so
301
+ * table APIs are assigned directly instead of through a shared prototype.
302
+ * This runs while the table is being constructed, after options and initial
303
+ * state have been resolved.
201
304
  */
202
305
  constructTableAPIs?: <TFeatures extends TableFeatures, TData extends RowData>(table: Table<TFeatures, TData>) => void;
306
+ /**
307
+ * Returns default column definition options contributed by this feature.
308
+ *
309
+ * These defaults are merged into the table's default column definition before
310
+ * `options.defaultColumn` and before each user-supplied column definition is
311
+ * resolved, so users can override values supplied here.
312
+ */
203
313
  getDefaultColumnDef?: <TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData>() => ColumnDefBase_All<TFeatures, TData, TValue>;
314
+ /**
315
+ * Returns default table options contributed by this feature.
316
+ *
317
+ * This runs while table options are being resolved. Use it for option
318
+ * defaults such as feature enablement flags and default state-updater
319
+ * callbacks. User-supplied table options take precedence over values returned
320
+ * here.
321
+ */
204
322
  getDefaultTableOptions?: <TFeatures extends TableFeatures, TData extends RowData>(table: Table<TFeatures, TData>) => Partial<TableOptions_All<TFeatures, TData>>;
323
+ /**
324
+ * Returns this feature's initial table state.
325
+ *
326
+ * The incoming `initialState` contains state accumulated from earlier
327
+ * features and user-provided initial state. Return a complete state object
328
+ * for this feature, preserving `initialState` so user-provided values can
329
+ * override feature defaults.
330
+ */
205
331
  getInitialState?: (initialState: Partial<TableState_All>) => TableState_All;
206
332
  /**
207
- * Initializes instance-specific data on each row (e.g., caches).
208
- * Methods should be assigned via assignRowPrototype instead.
333
+ * Initializes instance-specific data on each column.
334
+ *
335
+ * This runs for every constructed column after core column fields such as
336
+ * `id`, `depth`, `parent`, `columnDef`, and `columns` have been assigned.
337
+ * Use this for per-column mutable data, caches, or annotations. Shared
338
+ * methods should be assigned via `assignColumnPrototype` instead.
339
+ */
340
+ initColumnInstanceData?: <TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData>(column: Column<TFeatures, TData, TValue>) => void;
341
+ /**
342
+ * Initializes instance-specific data on each row.
343
+ *
344
+ * This runs for every constructed row after core row fields such as `id`,
345
+ * `index`, `depth`, `original`, `parentId`, and `subRows` have been assigned.
346
+ * Use this for per-row mutable data, caches, or annotations. Shared methods
347
+ * should be assigned via `assignRowPrototype` instead.
209
348
  */
210
349
  initRowInstanceData?: <TFeatures extends TableFeatures, TData extends RowData>(row: Row<TFeatures, TData>) => void;
211
350
  }
@@ -1,22 +1,46 @@
1
1
  import { CellData, RowData, UnionToIntersection } from "./type-utils.js";
2
2
  import { CoreFeatures } from "../core/coreFeatures.js";
3
- import { SortFn } from "../features/row-sorting/rowSortingFeature.types.js";
4
3
  import { Row } from "./Row.js";
5
4
  import { FilterFn } from "../features/column-filtering/columnFilteringFeature.types.js";
5
+ import { SortFn } from "../features/row-sorting/rowSortingFeature.types.js";
6
6
  import { TableState_All } from "./TableState.js";
7
+ import { ColumnDefBase_All } from "./ColumnDef.js";
7
8
  import { TableOptions_All } from "./TableOptions.js";
8
9
  import { Table } from "./Table.js";
9
- import { ColumnDefBase_All } from "./ColumnDef.js";
10
+ import { Column } from "./Column.js";
10
11
  import { StockFeatures } from "../features/stockFeatures.js";
11
12
  import { RowModel } from "../core/row-models/coreRowModelsFeature.types.js";
12
13
  import { AggregationFn } from "../features/column-grouping/columnGroupingFeature.types.js";
13
14
 
14
15
  //#region src/types/TableFeatures.d.ts
16
+ /**
17
+ * Detects whether a type is `any`.
18
+ *
19
+ * Several feature-map helpers need a separate `any` path so broad generic
20
+ * usage still exposes all known feature APIs instead of narrowing to no keys.
21
+ */
15
22
  type IsAny<T> = 0 extends 1 & T ? true : false;
23
+ /**
24
+ * Converts a union to an intersection, returning `{}` for `never`.
25
+ *
26
+ * This keeps empty feature-map lookups usable as an intersection member.
27
+ */
16
28
  type UnionToIntersectionOrEmpty<T> = [T] extends [never] ? {} : UnionToIntersection<T> & {};
29
+ /**
30
+ * Extracts the API/types contributed by the features present in `TFeatures`.
31
+ *
32
+ * `TFeatureMap` maps feature keys to the types they contribute. When
33
+ * `TFeatures` is `any`, all feature-map entries are included to preserve the
34
+ * permissive behavior expected by broad table types. Otherwise, only entries
35
+ * whose keys are present in `TFeatures` are intersected together.
36
+ */
17
37
  type ExtractFeatureMapTypes<TFeatures extends TableFeatures, TFeatureMap extends object> = IsAny<TFeatures> extends true ? UnionToIntersection<TFeatureMap[keyof TFeatureMap]> : UnionToIntersectionOrEmpty<TFeatureMap[Extract<keyof TFeatures, keyof TFeatureMap>]>;
18
38
  /**
19
- * This is an interface that you can delcaration-merge into to allow for custom plugins to be added to the table.
39
+ * Declaration-merge target for custom table features.
40
+ *
41
+ * Add custom feature keys here so `TableFeatures` can accept them in the
42
+ * `features` option and use the same feature-map extraction system as built-in
43
+ * features.
20
44
  */
21
45
  interface Plugins {}
22
46
  /**
@@ -36,19 +60,61 @@ type NonFeatureKeys = 'aggregationFns' | 'columnMeta' | 'coreRowModel' | 'expand
36
60
  * interface to get the same validation from `tableFeatures()`.
37
61
  */
38
62
  interface FeatureSlotPrereqs {
63
+ /**
64
+ * Named aggregation functions are only meaningful when grouping is enabled.
65
+ */
39
66
  aggregationFns: 'columnGroupingFeature';
67
+ /**
68
+ * Column resizing builds on the column sizing state and APIs.
69
+ */
40
70
  columnResizingFeature: 'columnSizingFeature';
71
+ /**
72
+ * Expanded row-model factories require row expanding APIs and state.
73
+ */
41
74
  expandedRowModel: 'rowExpandingFeature';
75
+ /**
76
+ * Faceted min/max factories require column faceting APIs.
77
+ */
42
78
  facetedMinMaxValues: 'columnFacetingFeature';
79
+ /**
80
+ * Faceted row-model factories require column faceting APIs.
81
+ */
43
82
  facetedRowModel: 'columnFacetingFeature';
83
+ /**
84
+ * Faceted unique-value factories require column faceting APIs.
85
+ */
44
86
  facetedUniqueValues: 'columnFacetingFeature';
87
+ /**
88
+ * Filtered row-model factories require column filtering APIs and state.
89
+ */
45
90
  filteredRowModel: 'columnFilteringFeature';
91
+ /**
92
+ * Named filter functions are only meaningful when column filtering is enabled.
93
+ */
46
94
  filterFns: 'columnFilteringFeature';
95
+ /**
96
+ * Filter metadata types are only read and written by filtering features.
97
+ */
47
98
  filterMeta: 'columnFilteringFeature';
99
+ /**
100
+ * Global filtering builds on column filtering state and filter functions.
101
+ */
48
102
  globalFilteringFeature: 'columnFilteringFeature';
103
+ /**
104
+ * Grouped row-model factories require column grouping APIs and state.
105
+ */
49
106
  groupedRowModel: 'columnGroupingFeature';
107
+ /**
108
+ * Paginated row-model factories require row pagination APIs and state.
109
+ */
50
110
  paginatedRowModel: 'rowPaginationFeature';
111
+ /**
112
+ * Sorted row-model factories require row sorting APIs and state.
113
+ */
51
114
  sortedRowModel: 'rowSortingFeature';
115
+ /**
116
+ * Named sorting functions are only meaningful when row sorting is enabled.
117
+ */
52
118
  sortFns: 'rowSortingFeature';
53
119
  }
54
120
  /**
@@ -60,6 +126,15 @@ interface FeatureSlotPrereqs {
60
126
  * naming the feature that needs to be added.
61
127
  */
62
128
  type ValidateFeatureSlots<TFeatures extends TableFeatures> = IsAny<TFeatures> extends true ? {} : { [K in keyof TFeatures as K extends keyof FeatureSlotPrereqs ? K : never]: K extends keyof FeatureSlotPrereqs ? [Extract<FeatureSlotPrereqs[K], keyof TFeatures>] extends [never] ? `Error: '${K & string}' requires '${FeatureSlotPrereqs[K] & string}' to be included in this table's features.` : TFeatures[K] : never };
129
+ /**
130
+ * Complete feature registry for a table.
131
+ *
132
+ * This type combines core features, stock features, declaration-merged custom
133
+ * plugins, row-model factory slots, function registries, and type-only meta
134
+ * slots. The concrete `features` object passed to `tableFeatures()` determines
135
+ * which feature APIs are included throughout table, row, column, cell, header,
136
+ * options, and state types.
137
+ */
63
138
  interface TableFeatures extends Partial<CoreFeatures>, Partial<StockFeatures>, Partial<Plugins> {
64
139
  /**
65
140
  * Registry of aggregation functions available to this table by name.
@@ -174,38 +249,102 @@ interface TableFeatures extends Partial<CoreFeatures>, Partial<StockFeatures>, P
174
249
  */
175
250
  tableMeta?: object;
176
251
  }
252
+ /**
253
+ * Lifecycle hooks and defaults contributed by a table feature.
254
+ *
255
+ * Feature objects are registered in the table's `features` option. They can
256
+ * contribute default state/options, default column definitions, table APIs,
257
+ * shared prototype APIs for rows/columns/headers/cells, and per-instance row
258
+ * or column data.
259
+ */
177
260
  interface TableFeature {
178
261
  /**
179
- * Assigns Cell APIs to the cell prototype for memory-efficient method sharing.
180
- * This is called once per table to build a shared prototype for all cells.
262
+ * Adds feature methods to the shared cell prototype for a table.
263
+ *
264
+ * This runs lazily the first time a cell is constructed for a table. Methods
265
+ * assigned here are shared by every cell instance created by that table, so
266
+ * this hook should be used for APIs and memoized methods rather than
267
+ * per-cell mutable data.
181
268
  */
182
269
  assignCellPrototype?: <TFeatures extends TableFeatures, TData extends RowData>(prototype: Record<string, any>, table: Table<TFeatures, TData>) => void;
183
270
  /**
184
- * Assigns Column APIs to the column prototype for memory-efficient method sharing.
185
- * This is called once per table to build a shared prototype for all columns.
271
+ * Adds feature methods to the shared column prototype for a table.
272
+ *
273
+ * This runs lazily the first time a column is constructed for a table.
274
+ * Methods assigned here are shared by every column instance created by that
275
+ * table, so this hook should be used for APIs and memoized methods rather
276
+ * than per-column mutable data.
186
277
  */
187
278
  assignColumnPrototype?: <TFeatures extends TableFeatures, TData extends RowData>(prototype: Record<string, any>, table: Table<TFeatures, TData>) => void;
188
279
  /**
189
- * Assigns Header APIs to the header prototype for memory-efficient method sharing.
190
- * This is called once per table to build a shared prototype for all headers.
280
+ * Adds feature methods to the shared header prototype for a table.
281
+ *
282
+ * This runs lazily the first time a header is constructed for a table.
283
+ * Methods assigned here are shared by every header instance created by that
284
+ * table, so this hook should be used for APIs and memoized methods rather
285
+ * than per-header mutable data.
191
286
  */
192
287
  assignHeaderPrototype?: <TFeatures extends TableFeatures, TData extends RowData>(prototype: Record<string, any>, table: Table<TFeatures, TData>) => void;
193
288
  /**
194
- * Assigns Row APIs to the row prototype for memory-efficient method sharing.
195
- * This is called once per table to build a shared prototype for all rows.
289
+ * Adds feature methods to the shared row prototype for a table.
290
+ *
291
+ * This runs lazily the first time a row is constructed for a table. Methods
292
+ * assigned here are shared by every row instance created by that table, so
293
+ * this hook should be used for APIs and memoized methods rather than per-row
294
+ * mutable data.
196
295
  */
197
296
  assignRowPrototype?: <TFeatures extends TableFeatures, TData extends RowData>(prototype: Record<string, any>, table: Table<TFeatures, TData>) => void;
198
297
  /**
199
- * Assigns Table APIs to the table instance.
200
- * Unlike row/cell/column/header, the table is a singleton so methods are assigned directly.
298
+ * Adds feature APIs directly to the table instance.
299
+ *
300
+ * The table is a singleton, unlike rows, columns, headers, and cells, so
301
+ * table APIs are assigned directly instead of through a shared prototype.
302
+ * This runs while the table is being constructed, after options and initial
303
+ * state have been resolved.
201
304
  */
202
305
  constructTableAPIs?: <TFeatures extends TableFeatures, TData extends RowData>(table: Table<TFeatures, TData>) => void;
306
+ /**
307
+ * Returns default column definition options contributed by this feature.
308
+ *
309
+ * These defaults are merged into the table's default column definition before
310
+ * `options.defaultColumn` and before each user-supplied column definition is
311
+ * resolved, so users can override values supplied here.
312
+ */
203
313
  getDefaultColumnDef?: <TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData>() => ColumnDefBase_All<TFeatures, TData, TValue>;
314
+ /**
315
+ * Returns default table options contributed by this feature.
316
+ *
317
+ * This runs while table options are being resolved. Use it for option
318
+ * defaults such as feature enablement flags and default state-updater
319
+ * callbacks. User-supplied table options take precedence over values returned
320
+ * here.
321
+ */
204
322
  getDefaultTableOptions?: <TFeatures extends TableFeatures, TData extends RowData>(table: Table<TFeatures, TData>) => Partial<TableOptions_All<TFeatures, TData>>;
323
+ /**
324
+ * Returns this feature's initial table state.
325
+ *
326
+ * The incoming `initialState` contains state accumulated from earlier
327
+ * features and user-provided initial state. Return a complete state object
328
+ * for this feature, preserving `initialState` so user-provided values can
329
+ * override feature defaults.
330
+ */
205
331
  getInitialState?: (initialState: Partial<TableState_All>) => TableState_All;
206
332
  /**
207
- * Initializes instance-specific data on each row (e.g., caches).
208
- * Methods should be assigned via assignRowPrototype instead.
333
+ * Initializes instance-specific data on each column.
334
+ *
335
+ * This runs for every constructed column after core column fields such as
336
+ * `id`, `depth`, `parent`, `columnDef`, and `columns` have been assigned.
337
+ * Use this for per-column mutable data, caches, or annotations. Shared
338
+ * methods should be assigned via `assignColumnPrototype` instead.
339
+ */
340
+ initColumnInstanceData?: <TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData>(column: Column<TFeatures, TData, TValue>) => void;
341
+ /**
342
+ * Initializes instance-specific data on each row.
343
+ *
344
+ * This runs for every constructed row after core row fields such as `id`,
345
+ * `index`, `depth`, `original`, `parentId`, and `subRows` have been assigned.
346
+ * Use this for per-row mutable data, caches, or annotations. Shared methods
347
+ * should be assigned via `assignRowPrototype` instead.
209
348
  */
210
349
  initRowInstanceData?: <TFeatures extends TableFeatures, TData extends RowData>(row: Row<TFeatures, TData>) => void;
211
350
  }
@@ -1,21 +1,21 @@
1
1
  import { RowData, UnionToIntersection } from "./type-utils.cjs";
2
2
  import { CoreFeatures } from "../core/coreFeatures.cjs";
3
3
  import { TableOptions_ColumnResizing } from "../features/column-resizing/columnResizingFeature.types.cjs";
4
- import { TableOptions_RowSorting } from "../features/row-sorting/rowSortingFeature.types.cjs";
4
+ import { TableOptions_ColumnVisibility } from "../features/column-visibility/columnVisibilityFeature.types.cjs";
5
5
  import { TableOptions_ColumnSizing } from "../features/column-sizing/columnSizingFeature.types.cjs";
6
6
  import { TableOptions_ColumnPinning } from "../features/column-pinning/columnPinningFeature.types.cjs";
7
- import { TableOptions_ColumnOrdering } from "../features/column-ordering/columnOrderingFeature.types.cjs";
8
- import { TableOptions_GlobalFiltering } from "../features/global-filtering/globalFilteringFeature.types.cjs";
9
- import { TableOptions_Columns } from "../core/columns/coreColumnsFeature.types.cjs";
10
- import { TableOptions_ColumnVisibility } from "../features/column-visibility/columnVisibilityFeature.types.cjs";
11
7
  import { TableOptions_RowExpanding } from "../features/row-expanding/rowExpandingFeature.types.cjs";
12
8
  import { TableOptions_RowPinning } from "../features/row-pinning/rowPinningFeature.types.cjs";
13
9
  import { TableOptions_RowSelection } from "../features/row-selection/rowSelectionFeature.types.cjs";
14
10
  import { TableOptions_Rows } from "../core/rows/coreRowsFeature.types.cjs";
15
11
  import { TableOptions_ColumnFiltering } from "../features/column-filtering/columnFilteringFeature.types.cjs";
12
+ import { TableOptions_ColumnOrdering } from "../features/column-ordering/columnOrderingFeature.types.cjs";
13
+ import { TableOptions_GlobalFiltering } from "../features/global-filtering/globalFilteringFeature.types.cjs";
16
14
  import { TableOptions_RowPagination } from "../features/row-pagination/rowPaginationFeature.types.cjs";
17
- import { TableOptions_Table } from "../core/table/coreTablesFeature.types.cjs";
15
+ import { TableOptions_RowSorting } from "../features/row-sorting/rowSortingFeature.types.cjs";
18
16
  import { TableOptions_Cell } from "../core/cells/coreCellsFeature.types.cjs";
17
+ import { TableOptions_Columns } from "../core/columns/coreColumnsFeature.types.cjs";
18
+ import { TableOptions_Table } from "../core/table/coreTablesFeature.types.cjs";
19
19
  import { ExtractFeatureMapTypes, NonFeatureKeys, TableFeatures } from "./TableFeatures.cjs";
20
20
  import { TableOptions_ColumnGrouping } from "../features/column-grouping/columnGroupingFeature.types.cjs";
21
21
 
@@ -1,21 +1,21 @@
1
1
  import { RowData, UnionToIntersection } from "./type-utils.js";
2
2
  import { CoreFeatures } from "../core/coreFeatures.js";
3
3
  import { TableOptions_ColumnResizing } from "../features/column-resizing/columnResizingFeature.types.js";
4
- import { TableOptions_RowSorting } from "../features/row-sorting/rowSortingFeature.types.js";
4
+ import { TableOptions_ColumnVisibility } from "../features/column-visibility/columnVisibilityFeature.types.js";
5
5
  import { TableOptions_ColumnSizing } from "../features/column-sizing/columnSizingFeature.types.js";
6
6
  import { TableOptions_ColumnPinning } from "../features/column-pinning/columnPinningFeature.types.js";
7
- import { TableOptions_ColumnOrdering } from "../features/column-ordering/columnOrderingFeature.types.js";
8
- import { TableOptions_GlobalFiltering } from "../features/global-filtering/globalFilteringFeature.types.js";
9
- import { TableOptions_Columns } from "../core/columns/coreColumnsFeature.types.js";
10
- import { TableOptions_ColumnVisibility } from "../features/column-visibility/columnVisibilityFeature.types.js";
11
7
  import { TableOptions_RowExpanding } from "../features/row-expanding/rowExpandingFeature.types.js";
12
8
  import { TableOptions_RowPinning } from "../features/row-pinning/rowPinningFeature.types.js";
13
9
  import { TableOptions_RowSelection } from "../features/row-selection/rowSelectionFeature.types.js";
14
10
  import { TableOptions_Rows } from "../core/rows/coreRowsFeature.types.js";
15
11
  import { TableOptions_ColumnFiltering } from "../features/column-filtering/columnFilteringFeature.types.js";
12
+ import { TableOptions_ColumnOrdering } from "../features/column-ordering/columnOrderingFeature.types.js";
13
+ import { TableOptions_GlobalFiltering } from "../features/global-filtering/globalFilteringFeature.types.js";
16
14
  import { TableOptions_RowPagination } from "../features/row-pagination/rowPaginationFeature.types.js";
17
- import { TableOptions_Table } from "../core/table/coreTablesFeature.types.js";
15
+ import { TableOptions_RowSorting } from "../features/row-sorting/rowSortingFeature.types.js";
18
16
  import { TableOptions_Cell } from "../core/cells/coreCellsFeature.types.js";
17
+ import { TableOptions_Columns } from "../core/columns/coreColumnsFeature.types.js";
18
+ import { TableOptions_Table } from "../core/table/coreTablesFeature.types.js";
19
19
  import { ExtractFeatureMapTypes, NonFeatureKeys, TableFeatures } from "./TableFeatures.js";
20
20
  import { TableOptions_ColumnGrouping } from "../features/column-grouping/columnGroupingFeature.types.js";
21
21
 
@@ -1,15 +1,15 @@
1
1
  import { TableState_ColumnResizing } from "../features/column-resizing/columnResizingFeature.types.cjs";
2
- import { TableState_RowSorting } from "../features/row-sorting/rowSortingFeature.types.cjs";
2
+ import { TableState_ColumnVisibility } from "../features/column-visibility/columnVisibilityFeature.types.cjs";
3
3
  import { TableState_ColumnSizing } from "../features/column-sizing/columnSizingFeature.types.cjs";
4
4
  import { TableState_ColumnPinning } from "../features/column-pinning/columnPinningFeature.types.cjs";
5
- import { TableState_ColumnOrdering } from "../features/column-ordering/columnOrderingFeature.types.cjs";
6
- import { TableState_GlobalFiltering } from "../features/global-filtering/globalFilteringFeature.types.cjs";
7
- import { TableState_ColumnVisibility } from "../features/column-visibility/columnVisibilityFeature.types.cjs";
8
5
  import { TableState_RowExpanding } from "../features/row-expanding/rowExpandingFeature.types.cjs";
9
6
  import { TableState_RowPinning } from "../features/row-pinning/rowPinningFeature.types.cjs";
10
7
  import { TableState_RowSelection } from "../features/row-selection/rowSelectionFeature.types.cjs";
11
8
  import { TableState_ColumnFiltering } from "../features/column-filtering/columnFilteringFeature.types.cjs";
9
+ import { TableState_ColumnOrdering } from "../features/column-ordering/columnOrderingFeature.types.cjs";
10
+ import { TableState_GlobalFiltering } from "../features/global-filtering/globalFilteringFeature.types.cjs";
12
11
  import { TableState_RowPagination } from "../features/row-pagination/rowPaginationFeature.types.cjs";
12
+ import { TableState_RowSorting } from "../features/row-sorting/rowSortingFeature.types.cjs";
13
13
  import { ExtractFeatureMapTypes, TableFeatures } from "./TableFeatures.cjs";
14
14
  import { TableState_ColumnGrouping } from "../features/column-grouping/columnGroupingFeature.types.cjs";
15
15
 
@@ -1,15 +1,15 @@
1
1
  import { TableState_ColumnResizing } from "../features/column-resizing/columnResizingFeature.types.js";
2
- import { TableState_RowSorting } from "../features/row-sorting/rowSortingFeature.types.js";
2
+ import { TableState_ColumnVisibility } from "../features/column-visibility/columnVisibilityFeature.types.js";
3
3
  import { TableState_ColumnSizing } from "../features/column-sizing/columnSizingFeature.types.js";
4
4
  import { TableState_ColumnPinning } from "../features/column-pinning/columnPinningFeature.types.js";
5
- import { TableState_ColumnOrdering } from "../features/column-ordering/columnOrderingFeature.types.js";
6
- import { TableState_GlobalFiltering } from "../features/global-filtering/globalFilteringFeature.types.js";
7
- import { TableState_ColumnVisibility } from "../features/column-visibility/columnVisibilityFeature.types.js";
8
5
  import { TableState_RowExpanding } from "../features/row-expanding/rowExpandingFeature.types.js";
9
6
  import { TableState_RowPinning } from "../features/row-pinning/rowPinningFeature.types.js";
10
7
  import { TableState_RowSelection } from "../features/row-selection/rowSelectionFeature.types.js";
11
8
  import { TableState_ColumnFiltering } from "../features/column-filtering/columnFilteringFeature.types.js";
9
+ import { TableState_ColumnOrdering } from "../features/column-ordering/columnOrderingFeature.types.js";
10
+ import { TableState_GlobalFiltering } from "../features/global-filtering/globalFilteringFeature.types.js";
12
11
  import { TableState_RowPagination } from "../features/row-pagination/rowPaginationFeature.types.js";
12
+ import { TableState_RowSorting } from "../features/row-sorting/rowSortingFeature.types.js";
13
13
  import { ExtractFeatureMapTypes, TableFeatures } from "./TableFeatures.js";
14
14
  import { TableState_ColumnGrouping } from "../features/column-grouping/columnGroupingFeature.types.js";
15
15
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/table-core",
3
- "version": "9.0.0-beta.19",
3
+ "version": "9.0.0-beta.20",
4
4
  "description": "Headless UI for building powerful tables & datagrids for TS/JS.",
5
5
  "author": "Tanner Linsley",
6
6
  "license": "MIT",
@@ -115,5 +115,11 @@ export function constructColumn<
115
115
  column.id = `${String(id)}`
116
116
  column.parent = parent
117
117
 
118
+ // Initialize instance-specific data for features that need it
119
+ const features = Object.values(table._features)
120
+ for (let i = 0; i < features.length; i++) {
121
+ features[i]!.initColumnInstanceData?.(column)
122
+ }
123
+
118
124
  return column as Column<TFeatures, TData, TValue>
119
125
  }