@tanstack/react-table 9.0.0-alpha.9 → 9.0.0-beta.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/README.md +127 -0
- package/dist/FlexRender.cjs +61 -0
- package/dist/FlexRender.cjs.map +1 -0
- package/dist/FlexRender.d.cts +51 -0
- package/dist/FlexRender.d.ts +51 -0
- package/dist/FlexRender.js +58 -0
- package/dist/FlexRender.js.map +1 -0
- package/dist/Subscribe.cjs +13 -0
- package/dist/Subscribe.cjs.map +1 -0
- package/dist/Subscribe.d.cts +101 -0
- package/dist/Subscribe.d.ts +101 -0
- package/dist/Subscribe.js +13 -0
- package/dist/Subscribe.js.map +1 -0
- package/dist/_virtual/_rolldown/runtime.cjs +29 -0
- package/dist/createTableHook.cjs +313 -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 +311 -0
- package/dist/createTableHook.js.map +1 -0
- package/dist/flex-render.cjs +5 -0
- package/dist/flex-render.d.cts +2 -0
- package/dist/flex-render.d.ts +2 -0
- package/dist/flex-render.js +3 -0
- package/dist/index.cjs +18 -0
- package/dist/index.d.cts +6 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +8 -0
- package/dist/legacy.cjs +14 -0
- package/dist/legacy.d.cts +2 -0
- package/dist/legacy.d.ts +2 -0
- package/dist/legacy.js +3 -0
- package/dist/reactivity.cjs +34 -0
- package/dist/reactivity.cjs.map +1 -0
- package/dist/reactivity.js +34 -0
- package/dist/reactivity.js.map +1 -0
- package/dist/static-functions.cjs +9 -0
- package/dist/static-functions.d.cts +1 -0
- package/dist/static-functions.d.ts +1 -0
- package/dist/static-functions.js +3 -0
- package/dist/useLegacyTable.cjs +191 -0
- package/dist/useLegacyTable.cjs.map +1 -0
- package/dist/useLegacyTable.d.cts +233 -0
- package/dist/useLegacyTable.d.ts +233 -0
- package/dist/useLegacyTable.js +181 -0
- package/dist/useLegacyTable.js.map +1 -0
- package/dist/useTable.cjs +72 -0
- package/dist/useTable.cjs.map +1 -0
- package/dist/useTable.d.cts +122 -0
- package/dist/useTable.d.ts +122 -0
- package/dist/useTable.js +72 -0
- package/dist/useTable.js.map +1 -0
- package/package.json +41 -22
- package/skills/react/client-to-server/SKILL.md +377 -0
- package/skills/react/compose-with-tanstack-form/SKILL.md +363 -0
- package/skills/react/compose-with-tanstack-pacer/SKILL.md +287 -0
- package/skills/react/compose-with-tanstack-query/SKILL.md +467 -0
- package/skills/react/compose-with-tanstack-store/SKILL.md +347 -0
- package/skills/react/compose-with-tanstack-virtual/SKILL.md +388 -0
- package/skills/react/compose-with-tanstack-virtual/references/column-virtualization-and-infinite-scroll.md +136 -0
- package/skills/react/getting-started/SKILL.md +388 -0
- package/skills/react/migrate-v8-to-v9/SKILL.md +488 -0
- package/skills/react/production-readiness/SKILL.md +341 -0
- package/skills/react/react-subscribe-compiler-compat/SKILL.md +269 -0
- package/skills/react/table-state/SKILL.md +432 -0
- package/src/FlexRender.tsx +136 -0
- package/src/Subscribe.ts +153 -0
- package/src/createTableHook.tsx +1121 -0
- package/src/flex-render.ts +1 -0
- package/src/index.ts +6 -0
- package/src/legacy.ts +3 -0
- package/src/reactivity.ts +41 -0
- package/src/static-functions.ts +1 -0
- package/src/useLegacyTable.ts +487 -0
- package/src/useTable.ts +191 -0
- package/dist/cjs/index.cjs +0 -77
- package/dist/cjs/index.cjs.map +0 -1
- package/dist/cjs/index.d.cts +0 -9
- package/dist/esm/index.d.ts +0 -9
- package/dist/esm/index.js +0 -55
- package/dist/esm/index.js.map +0 -1
- package/src/index.tsx +0 -92
package/src/Subscribe.ts
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import { shallow, useSelector } from '@tanstack/react-store'
|
|
4
|
+
import type {
|
|
5
|
+
Atom,
|
|
6
|
+
ReadonlyAtom,
|
|
7
|
+
ReadonlyStore,
|
|
8
|
+
Store,
|
|
9
|
+
} from '@tanstack/react-store'
|
|
10
|
+
import type { TableFeatures, TableState } from '@tanstack/table-core'
|
|
11
|
+
import type { FunctionComponent, ReactNode } from 'react'
|
|
12
|
+
|
|
13
|
+
export type SubscribeSource<TValue> =
|
|
14
|
+
| Atom<TValue>
|
|
15
|
+
| ReadonlyAtom<TValue>
|
|
16
|
+
| Store<TValue>
|
|
17
|
+
| ReadonlyStore<TValue>
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Subscribe to `table.store` (full table state). The selector receives the full
|
|
21
|
+
* {@link TableState}.
|
|
22
|
+
*/
|
|
23
|
+
export type SubscribePropsWithStore<
|
|
24
|
+
TFeatures extends TableFeatures,
|
|
25
|
+
TSelected,
|
|
26
|
+
> = {
|
|
27
|
+
source: SubscribeSource<TableState<TFeatures>>
|
|
28
|
+
/**
|
|
29
|
+
* Select from full table state. Re-renders when the selected value changes
|
|
30
|
+
* (shallow compare).
|
|
31
|
+
*
|
|
32
|
+
* Required in store mode so you never accidentally subscribe to the whole
|
|
33
|
+
* store without an explicit projection.
|
|
34
|
+
*/
|
|
35
|
+
selector: (state: TableState<TFeatures>) => TSelected
|
|
36
|
+
children: ((state: TSelected) => ReactNode) | ReactNode
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Subscribe to the full value of a source (e.g. `table.atoms.rowSelection` or
|
|
41
|
+
* `table.optionsStore`). Omitting `selector` is equivalent to the identity
|
|
42
|
+
* selector — children receive `TSourceValue`.
|
|
43
|
+
*/
|
|
44
|
+
export type SubscribePropsWithSourceIdentity<TSourceValue> = {
|
|
45
|
+
source: SubscribeSource<TSourceValue>
|
|
46
|
+
selector?: undefined
|
|
47
|
+
children: ((state: TSourceValue) => ReactNode) | ReactNode
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Subscribe to a projected value from a source (atom or store). The selector
|
|
52
|
+
* receives the source value; children receive the projected `TSelected`.
|
|
53
|
+
*/
|
|
54
|
+
export type SubscribePropsWithSourceWithSelector<TSourceValue, TSelected> = {
|
|
55
|
+
source: SubscribeSource<TSourceValue>
|
|
56
|
+
selector: (state: TSourceValue) => TSelected
|
|
57
|
+
children: ((state: TSelected) => ReactNode) | ReactNode
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Subscribe to a single source — atom or store (identity or projected). Prefer
|
|
62
|
+
* {@link SubscribePropsWithSourceIdentity} or {@link SubscribePropsWithSourceWithSelector}
|
|
63
|
+
* for clearer inference when `selector` is omitted.
|
|
64
|
+
*/
|
|
65
|
+
export type SubscribePropsWithSource<TSourceValue, TSelected = TSourceValue> =
|
|
66
|
+
| SubscribePropsWithSourceIdentity<TSourceValue>
|
|
67
|
+
| SubscribePropsWithSourceWithSelector<TSourceValue, TSelected>
|
|
68
|
+
|
|
69
|
+
export type SubscribeProps<
|
|
70
|
+
TFeatures extends TableFeatures,
|
|
71
|
+
TSelected = unknown,
|
|
72
|
+
TSourceValue = unknown,
|
|
73
|
+
> =
|
|
74
|
+
| SubscribePropsWithStore<TFeatures, TSelected>
|
|
75
|
+
| SubscribePropsWithSourceIdentity<TSourceValue>
|
|
76
|
+
| SubscribePropsWithSourceWithSelector<TSourceValue, TSelected>
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* A React component that allows you to subscribe to the table state.
|
|
80
|
+
*
|
|
81
|
+
* This is useful for opting into state re-renders for specific parts of the table state.
|
|
82
|
+
*
|
|
83
|
+
* For `table.Subscribe` from `useTable`, prefer that API — it uses overloads so JSX
|
|
84
|
+
* contextual typing works. This standalone component uses a union `props` type.
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* ```tsx
|
|
88
|
+
* // As a standalone component — full store
|
|
89
|
+
* <Subscribe source={table.store} selector={(state) => ({ rowSelection: state.rowSelection })}>
|
|
90
|
+
* {({ rowSelection }) => (
|
|
91
|
+
* <div>Selected rows: {Object.keys(rowSelection).length}</div>
|
|
92
|
+
* )}
|
|
93
|
+
* </Subscribe>
|
|
94
|
+
* ```
|
|
95
|
+
*
|
|
96
|
+
* @example
|
|
97
|
+
* ```tsx
|
|
98
|
+
* // Entire source (atom or store) — no selector
|
|
99
|
+
* <Subscribe source={table.atoms.rowSelection}>
|
|
100
|
+
* {(rowSelection) => <div>...</div>}
|
|
101
|
+
* </Subscribe>
|
|
102
|
+
* ```
|
|
103
|
+
*
|
|
104
|
+
* @example
|
|
105
|
+
* ```tsx
|
|
106
|
+
* // Project source value (e.g. one row’s selection)
|
|
107
|
+
* <Subscribe
|
|
108
|
+
* source={table.atoms.rowSelection}
|
|
109
|
+
* selector={(rowSelection) => rowSelection?.[row.id]}
|
|
110
|
+
* >
|
|
111
|
+
* {(selected) => <tr data-selected={!!selected}>...</tr>}
|
|
112
|
+
* </Subscribe>
|
|
113
|
+
* ```
|
|
114
|
+
*
|
|
115
|
+
* @example
|
|
116
|
+
* ```tsx
|
|
117
|
+
* // As table.Subscribe (table instance method)
|
|
118
|
+
* <table.Subscribe selector={(state) => ({ rowSelection: state.rowSelection })}>
|
|
119
|
+
* {({ rowSelection }) => (
|
|
120
|
+
* <div>Selected rows: {Object.keys(rowSelection).length}</div>
|
|
121
|
+
* )}
|
|
122
|
+
* </table.Subscribe>
|
|
123
|
+
* ```
|
|
124
|
+
*/
|
|
125
|
+
export function Subscribe<TSourceValue>(
|
|
126
|
+
props: SubscribePropsWithSourceIdentity<TSourceValue>,
|
|
127
|
+
): ReturnType<FunctionComponent>
|
|
128
|
+
export function Subscribe<TSourceValue, TSelected>(
|
|
129
|
+
props: SubscribePropsWithSourceWithSelector<TSourceValue, TSelected>,
|
|
130
|
+
): ReturnType<FunctionComponent>
|
|
131
|
+
export function Subscribe<TFeatures extends TableFeatures, TSelected>(
|
|
132
|
+
props: SubscribePropsWithStore<TFeatures, TSelected>,
|
|
133
|
+
): ReturnType<FunctionComponent>
|
|
134
|
+
export function Subscribe<
|
|
135
|
+
TFeatures extends TableFeatures,
|
|
136
|
+
TSelected,
|
|
137
|
+
TSourceValue,
|
|
138
|
+
>(
|
|
139
|
+
props: SubscribeProps<TFeatures, TSelected, TSourceValue>,
|
|
140
|
+
): ReturnType<FunctionComponent> {
|
|
141
|
+
const selected = useSelector(
|
|
142
|
+
// Atom and store share the same selection protocol; union args need a widen for TS.
|
|
143
|
+
props.source,
|
|
144
|
+
props.selector as Parameters<typeof useSelector>[1],
|
|
145
|
+
{
|
|
146
|
+
compare: shallow,
|
|
147
|
+
},
|
|
148
|
+
) as TSelected
|
|
149
|
+
|
|
150
|
+
return typeof props.children === 'function'
|
|
151
|
+
? (props.children as (state: TSelected) => ReactNode)(selected)
|
|
152
|
+
: props.children
|
|
153
|
+
}
|