@tanstack/alpine-table 9.0.0-beta.37 → 9.0.0-beta.41
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/alpine-table",
|
|
3
|
-
"version": "9.0.0-beta.
|
|
3
|
+
"version": "9.0.0-beta.41",
|
|
4
4
|
"description": "Headless UI for building powerful tables & datagrids for Alpine.",
|
|
5
5
|
"author": "Tanner Linsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -18,7 +18,8 @@
|
|
|
18
18
|
"alpine",
|
|
19
19
|
"table",
|
|
20
20
|
"alpine-table",
|
|
21
|
-
"datagrid"
|
|
21
|
+
"datagrid",
|
|
22
|
+
"tanstack-intent"
|
|
22
23
|
],
|
|
23
24
|
"type": "module",
|
|
24
25
|
"types": "./dist/index.d.cts",
|
|
@@ -49,11 +50,12 @@
|
|
|
49
50
|
},
|
|
50
51
|
"files": [
|
|
51
52
|
"dist",
|
|
52
|
-
"src"
|
|
53
|
+
"src",
|
|
54
|
+
"skills"
|
|
53
55
|
],
|
|
54
56
|
"dependencies": {
|
|
55
57
|
"@tanstack/store": "^0.11.0",
|
|
56
|
-
"@tanstack/table-core": "9.0.0-beta.
|
|
58
|
+
"@tanstack/table-core": "9.0.0-beta.38"
|
|
57
59
|
},
|
|
58
60
|
"devDependencies": {
|
|
59
61
|
"@types/alpinejs": "^3.13.11",
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: create-table-hook
|
|
3
|
+
description: >
|
|
4
|
+
Share Alpine tableFeatures, defaults, createAppTable, and createAppColumnHelper with createTableHook. Load when multiple Alpine tables repeat infrastructure; unlike JSX adapters, Alpine has no registered table/cell/header component or context registry.
|
|
5
|
+
metadata:
|
|
6
|
+
type: framework
|
|
7
|
+
library: '@tanstack/alpine-table'
|
|
8
|
+
framework: alpine
|
|
9
|
+
library_version: '9.0.0-beta.41'
|
|
10
|
+
requires:
|
|
11
|
+
- '@tanstack/table-core#core'
|
|
12
|
+
- getting-started
|
|
13
|
+
- table-state
|
|
14
|
+
sources:
|
|
15
|
+
- 'TanStack/table:docs/framework/alpine/guide/composable-tables.md'
|
|
16
|
+
- 'TanStack/table:examples/alpine/basic-app-table'
|
|
17
|
+
- 'TanStack/table:packages/alpine-table/src/createTableHook.ts'
|
|
18
|
+
---
|
|
19
|
+
|
|
20
|
+
This skill builds on @tanstack/table-core#core plus this package's getting-started and table-state skills.
|
|
21
|
+
|
|
22
|
+
## Setup
|
|
23
|
+
|
|
24
|
+
```ts
|
|
25
|
+
import Alpine from 'alpinejs'
|
|
26
|
+
import { createTableHook, tableFeatures } from '@tanstack/alpine-table'
|
|
27
|
+
|
|
28
|
+
type Person = { id: string; name: string }
|
|
29
|
+
const { createAppTable, createAppColumnHelper } = createTableHook({
|
|
30
|
+
features: tableFeatures({}),
|
|
31
|
+
getRowId: (row: Person) => row.id,
|
|
32
|
+
})
|
|
33
|
+
const helper = createAppColumnHelper<Person>()
|
|
34
|
+
const columns = helper.columns([helper.accessor('name', { header: 'Name' })])
|
|
35
|
+
|
|
36
|
+
Alpine.data('peopleTable', () => {
|
|
37
|
+
const local = Alpine.reactive({
|
|
38
|
+
data: [{ id: '1', name: 'Ada' }] as Array<Person>,
|
|
39
|
+
})
|
|
40
|
+
const table = createAppTable({
|
|
41
|
+
columns,
|
|
42
|
+
get data() {
|
|
43
|
+
return local.data
|
|
44
|
+
},
|
|
45
|
+
})
|
|
46
|
+
return { table }
|
|
47
|
+
})
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## Core Patterns
|
|
51
|
+
|
|
52
|
+
### Share infrastructure, keep data local
|
|
53
|
+
|
|
54
|
+
Bind features, row models, row IDs, and defaults in the factory. Each Alpine component passes its own columns, reactive data getter, and controlled state.
|
|
55
|
+
|
|
56
|
+
### Reuse markup with Alpine primitives
|
|
57
|
+
|
|
58
|
+
Use real templates and `Alpine.bind` bundles for interactive reuse. `createTableHook` intentionally returns no component registry or context hooks.
|
|
59
|
+
|
|
60
|
+
### Use the helper to retain feature inference
|
|
61
|
+
|
|
62
|
+
Columns from `createAppColumnHelper<TData>()` know the factory's registered features without userland feature generics.
|
|
63
|
+
|
|
64
|
+
## Common Mistakes
|
|
65
|
+
|
|
66
|
+
### HIGH Assuming a JSX component registry
|
|
67
|
+
|
|
68
|
+
Wrong: pass `cellComponents` or `tableComponents` to Alpine `createTableHook`.
|
|
69
|
+
|
|
70
|
+
Correct: share features/defaults with the hook and build reusable interactive markup with Alpine templates or bind bundles.
|
|
71
|
+
|
|
72
|
+
The Alpine hook returns only app features, a column helper, and createAppTable.
|
|
73
|
+
|
|
74
|
+
Source: TanStack/table:packages/alpine-table/src/createTableHook.ts
|
|
75
|
+
|
|
76
|
+
### MEDIUM Abstracting a one-off table
|
|
77
|
+
|
|
78
|
+
Wrong: introduce an app factory for one table with no shared conventions.
|
|
79
|
+
|
|
80
|
+
Correct: use standalone `createTable` until infrastructure repeats.
|
|
81
|
+
|
|
82
|
+
The hook is an application reuse boundary, not required setup.
|
|
83
|
+
|
|
84
|
+
Source: TanStack/table:docs/framework/alpine/guide/composable-tables.md
|
|
85
|
+
|
|
86
|
+
### HIGH Reactive data captured as a snapshot
|
|
87
|
+
|
|
88
|
+
Wrong: `createAppTable({ columns, data: local.data })` when the array will be replaced.
|
|
89
|
+
|
|
90
|
+
Correct: provide a `get data()` option.
|
|
91
|
+
|
|
92
|
+
The app factory delegates to Alpine createTable, whose option effect tracks getters.
|
|
93
|
+
|
|
94
|
+
Source: TanStack/table:packages/alpine-table/src/createTable.ts
|
|
95
|
+
|
|
96
|
+
## API Discovery
|
|
97
|
+
|
|
98
|
+
Inspect `node_modules/@tanstack/alpine-table/src/createTableHook.ts`; do not infer component/context APIs from React, Vue, Solid, Svelte, Angular, or Lit adapters.
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: getting-started
|
|
3
|
+
description: >
|
|
4
|
+
Create an Alpine TanStack Table v9 table with createTable, explicit tableFeatures, Alpine.reactive data getters, x-for rendering, and FlexRender through x-html. Load for first-table setup, reactive options, or when nested Alpine directives rendered by x-html do not initialize.
|
|
5
|
+
metadata:
|
|
6
|
+
type: framework
|
|
7
|
+
library: '@tanstack/alpine-table'
|
|
8
|
+
framework: alpine
|
|
9
|
+
library_version: '9.0.0-beta.41'
|
|
10
|
+
requires:
|
|
11
|
+
- '@tanstack/table-core#core'
|
|
12
|
+
- '@tanstack/table-core#table-features'
|
|
13
|
+
sources:
|
|
14
|
+
- 'TanStack/table:docs/framework/alpine/guide/table-state.md'
|
|
15
|
+
- 'TanStack/table:examples/alpine/basic-create-table'
|
|
16
|
+
- 'TanStack/table:packages/alpine-table/src/index.ts'
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
This skill builds on @tanstack/table-core#core and @tanstack/table-core#table-features.
|
|
20
|
+
|
|
21
|
+
## Setup
|
|
22
|
+
|
|
23
|
+
```ts
|
|
24
|
+
import Alpine from 'alpinejs'
|
|
25
|
+
import {
|
|
26
|
+
FlexRender,
|
|
27
|
+
createTable,
|
|
28
|
+
tableFeatures,
|
|
29
|
+
type ColumnDef,
|
|
30
|
+
} from '@tanstack/alpine-table'
|
|
31
|
+
|
|
32
|
+
type Person = { id: string; name: string }
|
|
33
|
+
const features = tableFeatures({})
|
|
34
|
+
const columns: Array<ColumnDef<typeof features, Person>> = [
|
|
35
|
+
{ accessorKey: 'name', header: 'Name' },
|
|
36
|
+
]
|
|
37
|
+
|
|
38
|
+
Alpine.data('peopleTable', () => {
|
|
39
|
+
const local = Alpine.reactive({
|
|
40
|
+
data: [{ id: '1', name: 'Ada' }] as Array<Person>,
|
|
41
|
+
})
|
|
42
|
+
const table = createTable({
|
|
43
|
+
features,
|
|
44
|
+
columns,
|
|
45
|
+
get data() {
|
|
46
|
+
return local.data
|
|
47
|
+
},
|
|
48
|
+
getRowId: (row) => row.id,
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
return { table, FlexRender }
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
window.Alpine = Alpine
|
|
55
|
+
Alpine.start()
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Render real table structure with `x-for`; use `x-html="FlexRender({ header })"` or `x-html="FlexRender({ cell })"` only for renderer output.
|
|
59
|
+
|
|
60
|
+
## Core Patterns
|
|
61
|
+
|
|
62
|
+
### Pass live options through getters
|
|
63
|
+
|
|
64
|
+
Wrap changing data in an `Alpine.reactive({ data })` object and read `local.data` through `get data()`. The property read gives the adapter's effect a dependency to track before it calls `table.setOptions`.
|
|
65
|
+
|
|
66
|
+
### Read table APIs directly in bindings
|
|
67
|
+
|
|
68
|
+
The adapter returns a reactive proxy. Expressions such as `x-text="table.getRowModel().rows.length"` update without a Subscribe component.
|
|
69
|
+
|
|
70
|
+
### Render interaction controls as real markup
|
|
71
|
+
|
|
72
|
+
Buttons, inputs, and directives belong in the template. Renderer strings are useful for cell content, but `x-html` does not initialize Alpine directives inside the injected HTML.
|
|
73
|
+
|
|
74
|
+
## Common Mistakes
|
|
75
|
+
|
|
76
|
+
### HIGH Passing a data snapshot
|
|
77
|
+
|
|
78
|
+
Wrong: `createTable({ features, columns, data: local.data })` when `local.data` will be replaced.
|
|
79
|
+
|
|
80
|
+
Correct: expose `get data() { return local.data }`.
|
|
81
|
+
|
|
82
|
+
The adapter tracks option getters; a captured array does not follow later replacements.
|
|
83
|
+
|
|
84
|
+
Source: TanStack/table:packages/alpine-table/src/createTable.ts
|
|
85
|
+
|
|
86
|
+
### HIGH Interactive directives hidden in x-html
|
|
87
|
+
|
|
88
|
+
Wrong: return `'<button @click="remove()">Remove</button>'` from a cell renderer.
|
|
89
|
+
|
|
90
|
+
Correct: render the button as real template markup and bind the row action there, or use an `Alpine.bind` bundle.
|
|
91
|
+
|
|
92
|
+
Alpine does not initialize directives inside content inserted by `x-html`.
|
|
93
|
+
|
|
94
|
+
Source: TanStack/table:docs/framework/alpine/guide/composable-tables.md
|
|
95
|
+
|
|
96
|
+
### HIGH Expecting Table styling
|
|
97
|
+
|
|
98
|
+
Wrong: enable sizing or pinning and assume widths/sticky positioning appear.
|
|
99
|
+
|
|
100
|
+
Correct: apply widths, logical offsets, overflow, and sticky CSS in the Alpine template.
|
|
101
|
+
|
|
102
|
+
Table exposes state and geometry; it does not own the renderer.
|
|
103
|
+
|
|
104
|
+
Source: TanStack/table:docs/overview.md
|
|
105
|
+
|
|
106
|
+
## API Discovery
|
|
107
|
+
|
|
108
|
+
Inspect `node_modules/@tanstack/alpine-table/src/index.ts` and `createTable.ts`. Exact core APIs live under `node_modules/@tanstack/table-core/src/`.
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: table-state
|
|
3
|
+
description: >
|
|
4
|
+
Read automatically reactive Alpine table APIs in bindings and own slices with Alpine.reactive getters plus on*Change or external TanStack Store atoms. Load for controlled state, updater callbacks, selector gating, atom precedence, or code incorrectly adding table.Subscribe.
|
|
5
|
+
metadata:
|
|
6
|
+
type: framework
|
|
7
|
+
library: '@tanstack/alpine-table'
|
|
8
|
+
framework: alpine
|
|
9
|
+
library_version: '9.0.0-beta.41'
|
|
10
|
+
requires:
|
|
11
|
+
- '@tanstack/table-core#core'
|
|
12
|
+
- getting-started
|
|
13
|
+
sources:
|
|
14
|
+
- 'TanStack/table:docs/framework/alpine/guide/table-state.md'
|
|
15
|
+
- 'TanStack/table:examples/alpine/basic-create-table'
|
|
16
|
+
- 'TanStack/table:packages/alpine-table/src/createTable.ts'
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
This skill builds on @tanstack/table-core#core and this package's getting-started skill.
|
|
20
|
+
|
|
21
|
+
## State Mental Model
|
|
22
|
+
|
|
23
|
+
TanStack Table is primarily a state coordinator. Keep state internal unless another system needs to read, persist, or drive it. Without `initialState`, `atoms`, `state`, or `on[State]Change`, the table owns all registered slices.
|
|
24
|
+
|
|
25
|
+
- `table.baseAtoms` are internal writable atoms initialized from resolved initial state.
|
|
26
|
+
- `table.atoms` are readonly derived atoms for the active owner of each registered slice.
|
|
27
|
+
- `table.store` combines those atoms into one readonly flat store.
|
|
28
|
+
|
|
29
|
+
The Alpine adapter proxies the table and subscribes it to the store. Reads inside `x-text`, `x-for`, `x-if`, bound attributes, `x-effect`, or Alpine getters are reactive automatically; event handlers read the current value when invoked. State is feature-based, so missing state or methods usually mean the feature was not registered. Keep `features`, `columns`, and source `data` stable; expose changing reactive data through a getter rather than filtering, mapping, or slicing inside table options.
|
|
30
|
+
|
|
31
|
+
## Setup
|
|
32
|
+
|
|
33
|
+
```ts
|
|
34
|
+
import Alpine from 'alpinejs'
|
|
35
|
+
import {
|
|
36
|
+
createTable,
|
|
37
|
+
rowPaginationFeature,
|
|
38
|
+
tableFeatures,
|
|
39
|
+
} from '@tanstack/alpine-table'
|
|
40
|
+
import type { PaginationState } from '@tanstack/alpine-table'
|
|
41
|
+
|
|
42
|
+
const features = tableFeatures({ rowPaginationFeature })
|
|
43
|
+
|
|
44
|
+
Alpine.data('pagedTable', () => {
|
|
45
|
+
const local = Alpine.reactive<{ pagination: PaginationState }>({
|
|
46
|
+
pagination: { pageIndex: 0, pageSize: 10 },
|
|
47
|
+
})
|
|
48
|
+
const table = createTable({
|
|
49
|
+
features,
|
|
50
|
+
columns: [],
|
|
51
|
+
data: [],
|
|
52
|
+
state: {
|
|
53
|
+
get pagination() {
|
|
54
|
+
return local.pagination
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
onPaginationChange: (updater) => {
|
|
58
|
+
local.pagination =
|
|
59
|
+
typeof updater === 'function' ? updater(local.pagination) : updater
|
|
60
|
+
},
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
return { table }
|
|
64
|
+
})
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## Core Patterns
|
|
68
|
+
|
|
69
|
+
### Read narrow atoms in bindings
|
|
70
|
+
|
|
71
|
+
Use `table.atoms.pagination.get().pageIndex` for a narrow state read. The proxy registers the binding as reactive.
|
|
72
|
+
|
|
73
|
+
### Use a selector only to gate broad proxy updates
|
|
74
|
+
|
|
75
|
+
The optional second `createTable` argument shallow-compares selected state. Use `() => ({})` only when explicit atom subscriptions handle high-frequency updates such as resizing.
|
|
76
|
+
|
|
77
|
+
### Choose one owner per slice
|
|
78
|
+
|
|
79
|
+
Use either an external atom through `atoms.pagination` or Alpine-controlled `state.pagination` plus `onPaginationChange`. An external atom wins if both are supplied.
|
|
80
|
+
|
|
81
|
+
## Choose State Ownership
|
|
82
|
+
|
|
83
|
+
- Prefer internal state and feature APIs for table-local interaction.
|
|
84
|
+
- Use `initialState` only for starting/reset values; changing it later does not reset current state.
|
|
85
|
+
- Prefer a stable external atom in `atoms` when state is shared. Feature APIs write it directly, so omit `on[State]Change`.
|
|
86
|
+
- Use an `Alpine.reactive` value exposed through a getter plus its matching callback for simple controlled state. Resolve raw values and updater functions.
|
|
87
|
+
|
|
88
|
+
External atoms take precedence over external `state`, which syncs into the internal base atom. Do not rely on multiple owners. The global v8 `onStateChange` option is gone; subscribe to `table.store` to observe the complete state.
|
|
89
|
+
|
|
90
|
+
## Initialize, Update, and Reset
|
|
91
|
+
|
|
92
|
+
Prefer feature methods such as `setSorting`, `nextPage`, `toggleVisibility`, and `toggleSelected`. Direct `baseAtoms` writes are a rare escape hatch for internal state; write the external atom when it owns a slice.
|
|
93
|
+
|
|
94
|
+
```ts
|
|
95
|
+
table.resetSorting()
|
|
96
|
+
table.resetPagination()
|
|
97
|
+
table.resetPagination(true)
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
Feature resets use `table.initialState` unless `true` requests the feature default and can update external owners. Core `table.reset()` resets internal base atoms only. Use feature-specific types such as `PaginationState`; use `TableState<typeof features>` for the full state inferred from registered features.
|
|
101
|
+
|
|
102
|
+
## Common Mistakes
|
|
103
|
+
|
|
104
|
+
### HIGH Inventing a Subscribe component
|
|
105
|
+
|
|
106
|
+
Wrong: render a nonexistent `table.Subscribe` wrapper.
|
|
107
|
+
|
|
108
|
+
Correct: read the relevant table API directly in an Alpine binding.
|
|
109
|
+
|
|
110
|
+
The Alpine adapter makes proxied table reads reactive; it has no component render boundary.
|
|
111
|
+
|
|
112
|
+
Source: TanStack/table:docs/framework/alpine/guide/table-state.md
|
|
113
|
+
|
|
114
|
+
### HIGH Controlled snapshot never refreshes
|
|
115
|
+
|
|
116
|
+
Wrong: set `state: { pagination: local.pagination }` and later replace `local.pagination`.
|
|
117
|
+
|
|
118
|
+
Correct: define a getter for the controlled slice and apply each updater back to `local.pagination`.
|
|
119
|
+
|
|
120
|
+
The adapter effect must read the current reactive value to reapply options.
|
|
121
|
+
|
|
122
|
+
Source: TanStack/table:packages/alpine-table/src/createTable.ts
|
|
123
|
+
|
|
124
|
+
### MEDIUM State and atom owners conflict
|
|
125
|
+
|
|
126
|
+
Wrong: pass both `state.pagination` and `atoms.pagination` expecting two-way synchronization.
|
|
127
|
+
|
|
128
|
+
Correct: select one ownership mechanism; when an atom owns the slice, write the external atom.
|
|
129
|
+
|
|
130
|
+
The derived table atom reads the external atom before controlled or internal state.
|
|
131
|
+
|
|
132
|
+
Source: TanStack/table:docs/framework/alpine/guide/table-state.md
|
|
133
|
+
|
|
134
|
+
## API Discovery
|
|
135
|
+
|
|
136
|
+
Inspect `node_modules/@tanstack/alpine-table/src/createTable.ts` and `reactivity.ts`. Inspect `node_modules/@tanstack/table-core/src/core/table/constructTable.ts` for state precedence.
|