@pyreon/table 0.0.1
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/LICENSE +21 -0
- package/README.md +173 -0
- package/lib/analysis/index.js.html +5406 -0
- package/lib/index.js +94 -0
- package/lib/index.js.map +1 -0
- package/lib/types/index.d.ts +93 -0
- package/lib/types/index.d.ts.map +1 -0
- package/lib/types/index2.d.ts +40 -0
- package/lib/types/index2.d.ts.map +1 -0
- package/package.json +55 -0
- package/src/flex-render.ts +45 -0
- package/src/index.ts +11 -0
- package/src/tests/table.test.ts +388 -0
- package/src/use-table.ts +105 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025-present Vit Bokisch
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
# @pyreon/table
|
|
2
|
+
|
|
3
|
+
Pyreon adapter for TanStack Table. Reactive signal-driven table state with `flexRender` for column templates.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
bun add @pyreon/table @tanstack/table-core
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick Start
|
|
12
|
+
|
|
13
|
+
```tsx
|
|
14
|
+
import { signal } from "@pyreon/reactivity"
|
|
15
|
+
import {
|
|
16
|
+
useTable, flexRender, createColumnHelper,
|
|
17
|
+
getCoreRowModel, getSortedRowModel,
|
|
18
|
+
} from "@pyreon/table"
|
|
19
|
+
|
|
20
|
+
type Person = { name: string; age: number }
|
|
21
|
+
|
|
22
|
+
const columnHelper = createColumnHelper<Person>()
|
|
23
|
+
const columns = [
|
|
24
|
+
columnHelper.accessor("name", { header: "Name" }),
|
|
25
|
+
columnHelper.accessor("age", { header: "Age" }),
|
|
26
|
+
]
|
|
27
|
+
|
|
28
|
+
function UserTable() {
|
|
29
|
+
const data = signal<Person[]>([
|
|
30
|
+
{ name: "Alice", age: 30 },
|
|
31
|
+
{ name: "Bob", age: 25 },
|
|
32
|
+
])
|
|
33
|
+
|
|
34
|
+
const table = useTable(() => ({
|
|
35
|
+
data: data(),
|
|
36
|
+
columns,
|
|
37
|
+
getCoreRowModel: getCoreRowModel(),
|
|
38
|
+
getSortedRowModel: getSortedRowModel(),
|
|
39
|
+
}))
|
|
40
|
+
|
|
41
|
+
return () => (
|
|
42
|
+
<table>
|
|
43
|
+
<thead>
|
|
44
|
+
{table().getHeaderGroups().map((hg) => (
|
|
45
|
+
<tr key={hg.id}>
|
|
46
|
+
{hg.headers.map((header) => (
|
|
47
|
+
<th key={header.id}>
|
|
48
|
+
{flexRender(header.column.columnDef.header, header.getContext())}
|
|
49
|
+
</th>
|
|
50
|
+
))}
|
|
51
|
+
</tr>
|
|
52
|
+
))}
|
|
53
|
+
</thead>
|
|
54
|
+
<tbody>
|
|
55
|
+
{table().getRowModel().rows.map((row) => (
|
|
56
|
+
<tr key={row.id}>
|
|
57
|
+
{row.getVisibleCells().map((cell) => (
|
|
58
|
+
<td key={cell.id}>
|
|
59
|
+
{flexRender(cell.column.columnDef.cell, cell.getContext())}
|
|
60
|
+
</td>
|
|
61
|
+
))}
|
|
62
|
+
</tr>
|
|
63
|
+
))}
|
|
64
|
+
</tbody>
|
|
65
|
+
</table>
|
|
66
|
+
)
|
|
67
|
+
}
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## API
|
|
71
|
+
|
|
72
|
+
### `useTable(options)`
|
|
73
|
+
|
|
74
|
+
Create a reactive TanStack Table instance. Options are passed as a function so reactive signals (data, columns, sorting state) can be read inside, and the table updates automatically when they change.
|
|
75
|
+
|
|
76
|
+
| Parameter | Type | Description |
|
|
77
|
+
| --- | --- | --- |
|
|
78
|
+
| `options` | `() => TableOptions<TData>` | Function returning TanStack Table options |
|
|
79
|
+
|
|
80
|
+
**Returns:** `Computed<Table<TData>>` — a read-only computed signal holding the table instance.
|
|
81
|
+
|
|
82
|
+
The adapter handles internal state synchronization. When the table state changes (e.g. sorting, pagination), a version counter is bumped so the computed signal re-notifies consumers.
|
|
83
|
+
|
|
84
|
+
```ts
|
|
85
|
+
const sorting = signal<SortingState>([])
|
|
86
|
+
const table = useTable(() => ({
|
|
87
|
+
data: data(),
|
|
88
|
+
columns,
|
|
89
|
+
state: { sorting: sorting() },
|
|
90
|
+
onSortingChange: (updater) => {
|
|
91
|
+
sorting.set(typeof updater === "function" ? updater(sorting.peek()) : updater)
|
|
92
|
+
},
|
|
93
|
+
getCoreRowModel: getCoreRowModel(),
|
|
94
|
+
getSortedRowModel: getSortedRowModel(),
|
|
95
|
+
}))
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### `flexRender(component, props)`
|
|
99
|
+
|
|
100
|
+
Render a TanStack Table column definition template. Handles strings, numbers, component functions, and VNodes.
|
|
101
|
+
|
|
102
|
+
| Parameter | Type | Description |
|
|
103
|
+
| --- | --- | --- |
|
|
104
|
+
| `component` | `Function \| string \| number \| VNode \| null` | Column def template (header, cell, or footer) |
|
|
105
|
+
| `props` | `TValue` | Context object from `getContext()` |
|
|
106
|
+
|
|
107
|
+
**Returns:** `unknown` (string, VNode, or null)
|
|
108
|
+
|
|
109
|
+
```ts
|
|
110
|
+
// In a header cell:
|
|
111
|
+
flexRender(header.column.columnDef.header, header.getContext())
|
|
112
|
+
|
|
113
|
+
// In a data cell:
|
|
114
|
+
flexRender(cell.column.columnDef.cell, cell.getContext())
|
|
115
|
+
|
|
116
|
+
// In a footer cell:
|
|
117
|
+
flexRender(footer.column.columnDef.footer, footer.getContext())
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
## Patterns
|
|
121
|
+
|
|
122
|
+
### Controlled State
|
|
123
|
+
|
|
124
|
+
Manage table state externally with signals for full control.
|
|
125
|
+
|
|
126
|
+
```ts
|
|
127
|
+
const sorting = signal<SortingState>([])
|
|
128
|
+
const pagination = signal<PaginationState>({ pageIndex: 0, pageSize: 10 })
|
|
129
|
+
|
|
130
|
+
const table = useTable(() => ({
|
|
131
|
+
data: data(),
|
|
132
|
+
columns,
|
|
133
|
+
state: {
|
|
134
|
+
sorting: sorting(),
|
|
135
|
+
pagination: pagination(),
|
|
136
|
+
},
|
|
137
|
+
onSortingChange: (u) => sorting.set(typeof u === "function" ? u(sorting.peek()) : u),
|
|
138
|
+
onPaginationChange: (u) => pagination.set(typeof u === "function" ? u(pagination.peek()) : u),
|
|
139
|
+
getCoreRowModel: getCoreRowModel(),
|
|
140
|
+
getSortedRowModel: getSortedRowModel(),
|
|
141
|
+
getPaginatedRowModel: getPaginatedRowModel(),
|
|
142
|
+
}))
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
### Custom Cell Renderers
|
|
146
|
+
|
|
147
|
+
Use functions in column definitions to render custom content.
|
|
148
|
+
|
|
149
|
+
```tsx
|
|
150
|
+
const columns = [
|
|
151
|
+
columnHelper.accessor("name", {
|
|
152
|
+
header: "Name",
|
|
153
|
+
cell: (info) => <strong>{info.getValue()}</strong>,
|
|
154
|
+
}),
|
|
155
|
+
columnHelper.accessor("age", {
|
|
156
|
+
header: "Age",
|
|
157
|
+
cell: (info) => `${info.getValue()} years`,
|
|
158
|
+
}),
|
|
159
|
+
]
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
## Re-exports from `@tanstack/table-core`
|
|
163
|
+
|
|
164
|
+
Everything from `@tanstack/table-core` is re-exported. This includes all utilities, types, and built-in row model functions:
|
|
165
|
+
|
|
166
|
+
`createColumnHelper`, `getCoreRowModel`, `getSortedRowModel`, `getFilteredRowModel`, `getPaginatedRowModel`, `getGroupedRowModel`, `getExpandedRowModel`, `getFacetedRowModel`, `getFacetedMinMaxValues`, `getFacetedUniqueValues`, `Table`, `ColumnDef`, `SortingState`, `PaginationState`, `RowData`, and more.
|
|
167
|
+
|
|
168
|
+
## Gotchas
|
|
169
|
+
|
|
170
|
+
- `useTable` returns a `Computed<Table>` — you must call `table()` to access the table instance. This ensures reactive tracking.
|
|
171
|
+
- Options must be a function `() => opts`, not a plain object. Reading signals inside the function auto-tracks dependencies.
|
|
172
|
+
- The table instance is created once and mutated in place. A version counter forces the computed to re-notify even though the reference is the same.
|
|
173
|
+
- The effect that syncs options is automatically disposed on component unmount.
|