@tanstack/preact-table 9.0.0-alpha.21 → 9.0.0-alpha.23
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.
- package/dist/FlexRender.cjs +50 -0
- package/dist/FlexRender.cjs.map +1 -0
- package/dist/FlexRender.d.cts +51 -0
- package/dist/{esm/FlexRender.d.ts → FlexRender.d.ts} +20 -15
- package/dist/FlexRender.js +49 -0
- package/dist/FlexRender.js.map +1 -0
- package/dist/Subscribe.cjs +36 -0
- package/dist/Subscribe.cjs.map +1 -0
- package/dist/Subscribe.d.cts +49 -0
- package/dist/Subscribe.d.ts +49 -0
- package/dist/Subscribe.js +36 -0
- package/dist/Subscribe.js.map +1 -0
- package/dist/createTableHook.cjs +334 -0
- package/dist/createTableHook.cjs.map +1 -0
- package/dist/createTableHook.d.cts +358 -0
- package/dist/createTableHook.d.ts +358 -0
- package/dist/createTableHook.js +334 -0
- package/dist/createTableHook.js.map +1 -0
- package/dist/index.cjs +18 -0
- package/dist/index.d.cts +6 -0
- package/dist/index.d.ts +6 -0
- package/dist/{esm/index.js → index.js} +5 -10
- package/dist/useTable.cjs +38 -0
- package/dist/useTable.cjs.map +1 -0
- package/dist/useTable.d.cts +60 -0
- package/dist/useTable.d.ts +60 -0
- package/dist/useTable.js +38 -0
- package/dist/useTable.js.map +1 -0
- package/package.json +11 -13
- package/src/useTable.ts +14 -19
- package/dist/esm/FlexRender.js +0 -41
- package/dist/esm/FlexRender.js.map +0 -1
- package/dist/esm/Subscribe.d.ts +0 -44
- package/dist/esm/Subscribe.js +0 -9
- package/dist/esm/Subscribe.js.map +0 -1
- package/dist/esm/createTableHook.d.ts +0 -349
- package/dist/esm/createTableHook.js +0 -133
- package/dist/esm/createTableHook.js.map +0 -1
- package/dist/esm/index.d.ts +0 -5
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/useTable.d.ts +0 -52
- package/dist/esm/useTable.js +0 -46
- package/dist/esm/useTable.js.map +0 -1
|
@@ -0,0 +1,358 @@
|
|
|
1
|
+
import { PreactTable } from "./useTable.cjs";
|
|
2
|
+
import { AccessorFn, AccessorFnColumnDef, AccessorKeyColumnDef, Cell, CellContext, CellData, Column, ColumnDef, DeepKeys, DeepValue, DisplayColumnDef, GroupColumnDef, Header, IdentifiedColumnDef, NoInfer, Row, RowData, Table, TableFeatures, TableOptions, TableState } from "@tanstack/table-core";
|
|
3
|
+
import { ComponentChildren, ComponentType } from "preact";
|
|
4
|
+
|
|
5
|
+
//#region src/createTableHook.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* Enhanced CellContext with pre-bound cell components.
|
|
8
|
+
* The `cell` property includes the registered cellComponents.
|
|
9
|
+
*/
|
|
10
|
+
type AppCellContext<TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData, TCellComponents extends Record<string, ComponentType<any>>> = {
|
|
11
|
+
cell: Cell<TFeatures, TData, TValue> & TCellComponents & {
|
|
12
|
+
FlexRender: () => ComponentChildren;
|
|
13
|
+
};
|
|
14
|
+
column: Column<TFeatures, TData, TValue>;
|
|
15
|
+
getValue: CellContext<TFeatures, TData, TValue>['getValue'];
|
|
16
|
+
renderValue: CellContext<TFeatures, TData, TValue>['renderValue'];
|
|
17
|
+
row: Row<TFeatures, TData>;
|
|
18
|
+
table: Table<TFeatures, TData>;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Enhanced HeaderContext with pre-bound header components.
|
|
22
|
+
* The `header` property includes the registered headerComponents.
|
|
23
|
+
*/
|
|
24
|
+
type AppHeaderContext<TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData, THeaderComponents extends Record<string, ComponentType<any>>> = {
|
|
25
|
+
column: Column<TFeatures, TData, TValue>;
|
|
26
|
+
header: Header<TFeatures, TData, TValue> & THeaderComponents & {
|
|
27
|
+
FlexRender: () => ComponentChildren;
|
|
28
|
+
};
|
|
29
|
+
table: Table<TFeatures, TData>;
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Template type for column definitions that can be a string or a function.
|
|
33
|
+
*/
|
|
34
|
+
type AppColumnDefTemplate<TProps extends object> = string | ((props: TProps) => any);
|
|
35
|
+
/**
|
|
36
|
+
* Enhanced column definition base with pre-bound components in cell/header/footer contexts.
|
|
37
|
+
*/
|
|
38
|
+
type AppColumnDefBase<TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData, TCellComponents extends Record<string, ComponentType<any>>, THeaderComponents extends Record<string, ComponentType<any>>> = Omit<IdentifiedColumnDef<TFeatures, TData, TValue>, 'cell' | 'header' | 'footer'> & {
|
|
39
|
+
cell?: AppColumnDefTemplate<AppCellContext<TFeatures, TData, TValue, TCellComponents>>;
|
|
40
|
+
header?: AppColumnDefTemplate<AppHeaderContext<TFeatures, TData, TValue, THeaderComponents>>;
|
|
41
|
+
footer?: AppColumnDefTemplate<AppHeaderContext<TFeatures, TData, TValue, THeaderComponents>>;
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Enhanced display column definition with pre-bound components.
|
|
45
|
+
*/
|
|
46
|
+
type AppDisplayColumnDef<TFeatures extends TableFeatures, TData extends RowData, TCellComponents extends Record<string, ComponentType<any>>, THeaderComponents extends Record<string, ComponentType<any>>> = Omit<DisplayColumnDef<TFeatures, TData, unknown>, 'cell' | 'header' | 'footer'> & {
|
|
47
|
+
cell?: AppColumnDefTemplate<AppCellContext<TFeatures, TData, unknown, TCellComponents>>;
|
|
48
|
+
header?: AppColumnDefTemplate<AppHeaderContext<TFeatures, TData, unknown, THeaderComponents>>;
|
|
49
|
+
footer?: AppColumnDefTemplate<AppHeaderContext<TFeatures, TData, unknown, THeaderComponents>>;
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* Enhanced group column definition with pre-bound components.
|
|
53
|
+
*/
|
|
54
|
+
type AppGroupColumnDef<TFeatures extends TableFeatures, TData extends RowData, TCellComponents extends Record<string, ComponentType<any>>, THeaderComponents extends Record<string, ComponentType<any>>> = Omit<GroupColumnDef<TFeatures, TData, unknown>, 'cell' | 'header' | 'footer' | 'columns'> & {
|
|
55
|
+
cell?: AppColumnDefTemplate<AppCellContext<TFeatures, TData, unknown, TCellComponents>>;
|
|
56
|
+
header?: AppColumnDefTemplate<AppHeaderContext<TFeatures, TData, unknown, THeaderComponents>>;
|
|
57
|
+
footer?: AppColumnDefTemplate<AppHeaderContext<TFeatures, TData, unknown, THeaderComponents>>;
|
|
58
|
+
columns?: Array<ColumnDef<TFeatures, TData, unknown>>;
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* Enhanced column helper with pre-bound components in cell/header/footer contexts.
|
|
62
|
+
* This enables TypeScript to know about the registered components when defining columns.
|
|
63
|
+
*/
|
|
64
|
+
type AppColumnHelper<TFeatures extends TableFeatures, TData extends RowData, TCellComponents extends Record<string, ComponentType<any>>, THeaderComponents extends Record<string, ComponentType<any>>> = {
|
|
65
|
+
/**
|
|
66
|
+
* Creates a data column definition with an accessor key or function.
|
|
67
|
+
* The cell, header, and footer contexts include pre-bound components.
|
|
68
|
+
*/
|
|
69
|
+
accessor: <TAccessor extends AccessorFn<TData> | DeepKeys<TData>, TValue extends (TAccessor extends AccessorFn<TData, infer TReturn> ? TReturn : TAccessor extends DeepKeys<TData> ? DeepValue<TData, TAccessor> : never)>(accessor: TAccessor, column: TAccessor extends AccessorFn<TData> ? AppColumnDefBase<TFeatures, TData, TValue, TCellComponents, THeaderComponents> & {
|
|
70
|
+
id: string;
|
|
71
|
+
} : AppColumnDefBase<TFeatures, TData, TValue, TCellComponents, THeaderComponents>) => TAccessor extends AccessorFn<TData> ? AccessorFnColumnDef<TFeatures, TData, TValue> : AccessorKeyColumnDef<TFeatures, TData, TValue>;
|
|
72
|
+
/**
|
|
73
|
+
* Wraps an array of column definitions to preserve each column's individual TValue type.
|
|
74
|
+
*/
|
|
75
|
+
columns: <TColumns extends ReadonlyArray<ColumnDef<TFeatures, TData, any>>>(columns: [...TColumns]) => Array<ColumnDef<TFeatures, TData, any>> & [...TColumns];
|
|
76
|
+
/**
|
|
77
|
+
* Creates a display column definition for non-data columns.
|
|
78
|
+
* The cell, header, and footer contexts include pre-bound components.
|
|
79
|
+
*/
|
|
80
|
+
display: (column: AppDisplayColumnDef<TFeatures, TData, TCellComponents, THeaderComponents>) => DisplayColumnDef<TFeatures, TData, unknown>;
|
|
81
|
+
/**
|
|
82
|
+
* Creates a group column definition with nested child columns.
|
|
83
|
+
* The cell, header, and footer contexts include pre-bound components.
|
|
84
|
+
*/
|
|
85
|
+
group: (column: AppGroupColumnDef<TFeatures, TData, TCellComponents, THeaderComponents>) => GroupColumnDef<TFeatures, TData, unknown>;
|
|
86
|
+
};
|
|
87
|
+
/**
|
|
88
|
+
* Options for creating a table hook with pre-bound components and default table options.
|
|
89
|
+
* Extends all TableOptions except 'columns' | 'data' | 'store' | 'state' | 'initialState'.
|
|
90
|
+
*/
|
|
91
|
+
type CreateTableHookOptions<TFeatures extends TableFeatures, TTableComponents extends Record<string, ComponentType<any>>, TCellComponents extends Record<string, ComponentType<any>>, THeaderComponents extends Record<string, ComponentType<any>>> = Omit<TableOptions<TFeatures, any>, 'columns' | 'data' | 'store' | 'state' | 'initialState'> & {
|
|
92
|
+
/**
|
|
93
|
+
* Table-level components that need access to the table instance.
|
|
94
|
+
* These are available directly on the table object returned by useAppTable.
|
|
95
|
+
* Use `useTableContext()` inside these components.
|
|
96
|
+
* @example { PaginationControls, GlobalFilter, RowCount }
|
|
97
|
+
*/
|
|
98
|
+
tableComponents?: TTableComponents;
|
|
99
|
+
/**
|
|
100
|
+
* Cell-level components that need access to the cell instance.
|
|
101
|
+
* These are available on the cell object passed to AppCell's children.
|
|
102
|
+
* Use `useCellContext()` inside these components.
|
|
103
|
+
* @example { TextCell, NumberCell, DateCell, CurrencyCell }
|
|
104
|
+
*/
|
|
105
|
+
cellComponents?: TCellComponents;
|
|
106
|
+
/**
|
|
107
|
+
* Header-level components that need access to the header instance.
|
|
108
|
+
* These are available on the header object passed to AppHeader/AppFooter's children.
|
|
109
|
+
* Use `useHeaderContext()` inside these components.
|
|
110
|
+
* @example { SortIndicator, ColumnFilter, ResizeHandle }
|
|
111
|
+
*/
|
|
112
|
+
headerComponents?: THeaderComponents;
|
|
113
|
+
};
|
|
114
|
+
/**
|
|
115
|
+
* Props for AppTable component - without selector
|
|
116
|
+
*/
|
|
117
|
+
interface AppTablePropsWithoutSelector {
|
|
118
|
+
children: ComponentChildren;
|
|
119
|
+
selector?: never;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Props for AppTable component - with selector
|
|
123
|
+
*/
|
|
124
|
+
interface AppTablePropsWithSelector<TFeatures extends TableFeatures, TSelected> {
|
|
125
|
+
children: (state: TSelected) => ComponentChildren;
|
|
126
|
+
selector: (state: TableState<TFeatures>) => TSelected;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Props for AppCell component - without selector
|
|
130
|
+
*/
|
|
131
|
+
interface AppCellPropsWithoutSelector<TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData, TCellComponents extends Record<string, ComponentType<any>>> {
|
|
132
|
+
cell: Cell<TFeatures, TData, TValue>;
|
|
133
|
+
children: (cell: Cell<TFeatures, TData, TValue> & TCellComponents & {
|
|
134
|
+
FlexRender: () => ComponentChildren;
|
|
135
|
+
}) => ComponentChildren;
|
|
136
|
+
selector?: never;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Props for AppCell component - with selector
|
|
140
|
+
*/
|
|
141
|
+
interface AppCellPropsWithSelector<TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData, TCellComponents extends Record<string, ComponentType<any>>, TSelected> {
|
|
142
|
+
cell: Cell<TFeatures, TData, TValue>;
|
|
143
|
+
children: (cell: Cell<TFeatures, TData, TValue> & TCellComponents & {
|
|
144
|
+
FlexRender: () => ComponentChildren;
|
|
145
|
+
}, state: TSelected) => ComponentChildren;
|
|
146
|
+
selector: (state: TableState<TFeatures>) => TSelected;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Props for AppHeader/AppFooter component - without selector
|
|
150
|
+
*/
|
|
151
|
+
interface AppHeaderPropsWithoutSelector<TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData, THeaderComponents extends Record<string, ComponentType<any>>> {
|
|
152
|
+
header: Header<TFeatures, TData, TValue>;
|
|
153
|
+
children: (header: Header<TFeatures, TData, TValue> & THeaderComponents & {
|
|
154
|
+
FlexRender: () => ComponentChildren;
|
|
155
|
+
}) => ComponentChildren;
|
|
156
|
+
selector?: never;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Props for AppHeader/AppFooter component - with selector
|
|
160
|
+
*/
|
|
161
|
+
interface AppHeaderPropsWithSelector<TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData, THeaderComponents extends Record<string, ComponentType<any>>, TSelected> {
|
|
162
|
+
header: Header<TFeatures, TData, TValue>;
|
|
163
|
+
children: (header: Header<TFeatures, TData, TValue> & THeaderComponents & {
|
|
164
|
+
FlexRender: () => ComponentChildren;
|
|
165
|
+
}, state: TSelected) => ComponentChildren;
|
|
166
|
+
selector: (state: TableState<TFeatures>) => TSelected;
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Component type for AppCell - wraps a cell and provides cell context with optional Subscribe
|
|
170
|
+
*/
|
|
171
|
+
interface AppCellComponent<TFeatures extends TableFeatures, TData extends RowData, TCellComponents extends Record<string, ComponentType<any>>> {
|
|
172
|
+
<TValue extends CellData = CellData>(props: AppCellPropsWithoutSelector<TFeatures, TData, TValue, TCellComponents>): ComponentChildren;
|
|
173
|
+
<TValue extends CellData = CellData, TSelected = unknown>(props: AppCellPropsWithSelector<TFeatures, TData, TValue, TCellComponents, TSelected>): ComponentChildren;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Component type for AppHeader/AppFooter - wraps a header and provides header context with optional Subscribe
|
|
177
|
+
*/
|
|
178
|
+
interface AppHeaderComponent<TFeatures extends TableFeatures, TData extends RowData, THeaderComponents extends Record<string, ComponentType<any>>> {
|
|
179
|
+
<TValue extends CellData = CellData>(props: AppHeaderPropsWithoutSelector<TFeatures, TData, TValue, THeaderComponents>): ComponentChildren;
|
|
180
|
+
<TValue extends CellData = CellData, TSelected = unknown>(props: AppHeaderPropsWithSelector<TFeatures, TData, TValue, THeaderComponents, TSelected>): ComponentChildren;
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Component type for AppTable - root wrapper with optional Subscribe
|
|
184
|
+
*/
|
|
185
|
+
interface AppTableComponent<TFeatures extends TableFeatures> {
|
|
186
|
+
(props: AppTablePropsWithoutSelector): ComponentChildren;
|
|
187
|
+
<TSelected>(props: AppTablePropsWithSelector<TFeatures, TSelected>): ComponentChildren;
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Extended table API returned by useAppTable with all App wrapper components
|
|
191
|
+
*/
|
|
192
|
+
type AppPreactTable<TFeatures extends TableFeatures, TData extends RowData, TSelected, TTableComponents extends Record<string, ComponentType<any>>, TCellComponents extends Record<string, ComponentType<any>>, THeaderComponents extends Record<string, ComponentType<any>>> = PreactTable<TFeatures, TData, TSelected> & NoInfer<TTableComponents> & {
|
|
193
|
+
/**
|
|
194
|
+
* Root wrapper component that provides table context with optional Subscribe.
|
|
195
|
+
* @example
|
|
196
|
+
* ```tsx
|
|
197
|
+
* // Without selector - children is ComponentChildren
|
|
198
|
+
* <table.AppTable>
|
|
199
|
+
* <table>...</table>
|
|
200
|
+
* </table.AppTable>
|
|
201
|
+
*
|
|
202
|
+
* // With selector - children receives selected state
|
|
203
|
+
* <table.AppTable selector={(s) => s.pagination}>
|
|
204
|
+
* {(pagination) => <div>Page {pagination.pageIndex}</div>}
|
|
205
|
+
* </table.AppTable>
|
|
206
|
+
* ```
|
|
207
|
+
*/
|
|
208
|
+
AppTable: AppTableComponent<TFeatures>;
|
|
209
|
+
/**
|
|
210
|
+
* Wraps a cell and provides cell context with pre-bound cellComponents.
|
|
211
|
+
* Optionally accepts a selector for Subscribe functionality.
|
|
212
|
+
* @example
|
|
213
|
+
* ```tsx
|
|
214
|
+
* // Without selector
|
|
215
|
+
* <table.AppCell cell={cell}>
|
|
216
|
+
* {(c) => <td><c.TextCell /></td>}
|
|
217
|
+
* </table.AppCell>
|
|
218
|
+
*
|
|
219
|
+
* // With selector - children receives cell and selected state
|
|
220
|
+
* <table.AppCell cell={cell} selector={(s) => s.columnFilters}>
|
|
221
|
+
* {(c, filters) => <td>{filters.length}</td>}
|
|
222
|
+
* </table.AppCell>
|
|
223
|
+
* ```
|
|
224
|
+
*/
|
|
225
|
+
AppCell: AppCellComponent<TFeatures, TData, NoInfer<TCellComponents>>;
|
|
226
|
+
/**
|
|
227
|
+
* Wraps a header and provides header context with pre-bound headerComponents.
|
|
228
|
+
* Optionally accepts a selector for Subscribe functionality.
|
|
229
|
+
* @example
|
|
230
|
+
* ```tsx
|
|
231
|
+
* // Without selector
|
|
232
|
+
* <table.AppHeader header={header}>
|
|
233
|
+
* {(h) => <th><h.SortIndicator /></th>}
|
|
234
|
+
* </table.AppHeader>
|
|
235
|
+
*
|
|
236
|
+
* // With selector
|
|
237
|
+
* <table.AppHeader header={header} selector={(s) => s.sorting}>
|
|
238
|
+
* {(h, sorting) => <th>{sorting.length} sorted</th>}
|
|
239
|
+
* </table.AppHeader>
|
|
240
|
+
* ```
|
|
241
|
+
*/
|
|
242
|
+
AppHeader: AppHeaderComponent<TFeatures, TData, NoInfer<THeaderComponents>>;
|
|
243
|
+
/**
|
|
244
|
+
* Wraps a footer and provides header context with pre-bound headerComponents.
|
|
245
|
+
* Optionally accepts a selector for Subscribe functionality.
|
|
246
|
+
* @example
|
|
247
|
+
* ```tsx
|
|
248
|
+
* <table.AppFooter header={footer}>
|
|
249
|
+
* {(f) => <td><table.FlexRender footer={footer} /></td>}
|
|
250
|
+
* </table.AppFooter>
|
|
251
|
+
* ```
|
|
252
|
+
*/
|
|
253
|
+
AppFooter: AppHeaderComponent<TFeatures, TData, NoInfer<THeaderComponents>>;
|
|
254
|
+
};
|
|
255
|
+
/**
|
|
256
|
+
* Creates a custom table hook with pre-bound components for composition.
|
|
257
|
+
*
|
|
258
|
+
* This is the table equivalent of TanStack Form's `createFormHook`. It allows you to:
|
|
259
|
+
* - Define features, row models, and default options once, shared across all tables
|
|
260
|
+
* - Register reusable table, cell, and header components
|
|
261
|
+
* - Access table/cell/header instances via context in those components
|
|
262
|
+
* - Get a `useAppTable` hook that returns an extended table with App wrapper components
|
|
263
|
+
* - Get a `createAppColumnHelper` function pre-bound to your features
|
|
264
|
+
*
|
|
265
|
+
* @example
|
|
266
|
+
* ```tsx
|
|
267
|
+
* // hooks/table.ts
|
|
268
|
+
* export const {
|
|
269
|
+
* useAppTable,
|
|
270
|
+
* createAppColumnHelper,
|
|
271
|
+
* useTableContext,
|
|
272
|
+
* useCellContext,
|
|
273
|
+
* useHeaderContext,
|
|
274
|
+
* } = createTableHook({
|
|
275
|
+
* _features: tableFeatures({
|
|
276
|
+
* rowPaginationFeature,
|
|
277
|
+
* rowSortingFeature,
|
|
278
|
+
* columnFilteringFeature,
|
|
279
|
+
* }),
|
|
280
|
+
* _rowModels: {
|
|
281
|
+
* paginatedRowModel: createPaginatedRowModel(),
|
|
282
|
+
* sortedRowModel: createSortedRowModel(sortFns),
|
|
283
|
+
* filteredRowModel: createFilteredRowModel(filterFns),
|
|
284
|
+
* },
|
|
285
|
+
* tableComponents: { PaginationControls, RowCount },
|
|
286
|
+
* cellComponents: { TextCell, NumberCell },
|
|
287
|
+
* headerComponents: { SortIndicator, ColumnFilter },
|
|
288
|
+
* })
|
|
289
|
+
*
|
|
290
|
+
* // Create column helper with TFeatures already bound
|
|
291
|
+
* const columnHelper = createAppColumnHelper<Person>()
|
|
292
|
+
*
|
|
293
|
+
* // components/table-components.tsx
|
|
294
|
+
* function PaginationControls() {
|
|
295
|
+
* const table = useTableContext() // TFeatures already known!
|
|
296
|
+
* return <table.Subscribe selector={(s) => s.pagination}>...</table.Subscribe>
|
|
297
|
+
* }
|
|
298
|
+
*
|
|
299
|
+
* // features/users.tsx
|
|
300
|
+
* function UsersTable({ data }: { data: Person[] }) {
|
|
301
|
+
* const table = useAppTable({
|
|
302
|
+
* columns,
|
|
303
|
+
* data, // TData inferred from Person[]
|
|
304
|
+
* })
|
|
305
|
+
*
|
|
306
|
+
* return (
|
|
307
|
+
* <table.AppTable>
|
|
308
|
+
* <table>
|
|
309
|
+
* <thead>
|
|
310
|
+
* {table.getHeaderGroups().map(headerGroup => (
|
|
311
|
+
* <tr key={headerGroup.id}>
|
|
312
|
+
* {headerGroup.headers.map(h => (
|
|
313
|
+
* <table.AppHeader header={h} key={h.id}>
|
|
314
|
+
* {(header) => (
|
|
315
|
+
* <th>
|
|
316
|
+
* <table.FlexRender header={h} />
|
|
317
|
+
* <header.SortIndicator />
|
|
318
|
+
* </th>
|
|
319
|
+
* )}
|
|
320
|
+
* </table.AppHeader>
|
|
321
|
+
* ))}
|
|
322
|
+
* </tr>
|
|
323
|
+
* ))}
|
|
324
|
+
* </thead>
|
|
325
|
+
* <tbody>
|
|
326
|
+
* {table.getRowModel().rows.map(row => (
|
|
327
|
+
* <tr key={row.id}>
|
|
328
|
+
* {row.getAllCells().map(c => (
|
|
329
|
+
* <table.AppCell cell={c} key={c.id}>
|
|
330
|
+
* {(cell) => <td><cell.TextCell /></td>}
|
|
331
|
+
* </table.AppCell>
|
|
332
|
+
* ))}
|
|
333
|
+
* </tr>
|
|
334
|
+
* ))}
|
|
335
|
+
* </tbody>
|
|
336
|
+
* </table>
|
|
337
|
+
* <table.PaginationControls />
|
|
338
|
+
* </table.AppTable>
|
|
339
|
+
* )
|
|
340
|
+
* }
|
|
341
|
+
* ```
|
|
342
|
+
*/
|
|
343
|
+
declare function createTableHook<TFeatures extends TableFeatures, const TTableComponents extends Record<string, ComponentType<any>>, const TCellComponents extends Record<string, ComponentType<any>>, const THeaderComponents extends Record<string, ComponentType<any>>>({
|
|
344
|
+
tableComponents,
|
|
345
|
+
cellComponents,
|
|
346
|
+
headerComponents,
|
|
347
|
+
...defaultTableOptions
|
|
348
|
+
}: CreateTableHookOptions<TFeatures, TTableComponents, TCellComponents, THeaderComponents>): {
|
|
349
|
+
appFeatures: TFeatures;
|
|
350
|
+
createAppColumnHelper: <TData extends RowData>() => AppColumnHelper<TFeatures, TData, TCellComponents, THeaderComponents>;
|
|
351
|
+
useAppTable: <TData extends RowData, TSelected = {}>(tableOptions: Omit<TableOptions<TFeatures, TData>, "_features" | "_rowModels">, selector?: (state: TableState<TFeatures>) => TSelected) => AppPreactTable<TFeatures, TData, TSelected, TTableComponents, TCellComponents, THeaderComponents>;
|
|
352
|
+
useTableContext: <TData extends RowData = RowData>() => PreactTable<TFeatures, TData>;
|
|
353
|
+
useCellContext: <TValue extends CellData = unknown>() => Cell<TFeatures, any, TValue>;
|
|
354
|
+
useHeaderContext: <TValue extends CellData = unknown>() => Header<TFeatures, any, TValue>;
|
|
355
|
+
};
|
|
356
|
+
//#endregion
|
|
357
|
+
export { AppCellComponent, AppCellContext, AppCellPropsWithSelector, AppCellPropsWithoutSelector, AppColumnHelper, AppHeaderComponent, AppHeaderContext, AppHeaderPropsWithSelector, AppHeaderPropsWithoutSelector, AppPreactTable, AppTableComponent, AppTablePropsWithSelector, AppTablePropsWithoutSelector, CreateTableHookOptions, createTableHook };
|
|
358
|
+
//# sourceMappingURL=createTableHook.d.cts.map
|