@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.
Files changed (82) hide show
  1. package/README.md +127 -0
  2. package/dist/FlexRender.cjs +61 -0
  3. package/dist/FlexRender.cjs.map +1 -0
  4. package/dist/FlexRender.d.cts +51 -0
  5. package/dist/FlexRender.d.ts +51 -0
  6. package/dist/FlexRender.js +58 -0
  7. package/dist/FlexRender.js.map +1 -0
  8. package/dist/Subscribe.cjs +13 -0
  9. package/dist/Subscribe.cjs.map +1 -0
  10. package/dist/Subscribe.d.cts +101 -0
  11. package/dist/Subscribe.d.ts +101 -0
  12. package/dist/Subscribe.js +13 -0
  13. package/dist/Subscribe.js.map +1 -0
  14. package/dist/_virtual/_rolldown/runtime.cjs +29 -0
  15. package/dist/createTableHook.cjs +313 -0
  16. package/dist/createTableHook.cjs.map +1 -0
  17. package/dist/createTableHook.d.cts +358 -0
  18. package/dist/createTableHook.d.ts +358 -0
  19. package/dist/createTableHook.js +311 -0
  20. package/dist/createTableHook.js.map +1 -0
  21. package/dist/flex-render.cjs +5 -0
  22. package/dist/flex-render.d.cts +2 -0
  23. package/dist/flex-render.d.ts +2 -0
  24. package/dist/flex-render.js +3 -0
  25. package/dist/index.cjs +18 -0
  26. package/dist/index.d.cts +6 -0
  27. package/dist/index.d.ts +6 -0
  28. package/dist/index.js +8 -0
  29. package/dist/legacy.cjs +14 -0
  30. package/dist/legacy.d.cts +2 -0
  31. package/dist/legacy.d.ts +2 -0
  32. package/dist/legacy.js +3 -0
  33. package/dist/reactivity.cjs +34 -0
  34. package/dist/reactivity.cjs.map +1 -0
  35. package/dist/reactivity.js +34 -0
  36. package/dist/reactivity.js.map +1 -0
  37. package/dist/static-functions.cjs +9 -0
  38. package/dist/static-functions.d.cts +1 -0
  39. package/dist/static-functions.d.ts +1 -0
  40. package/dist/static-functions.js +3 -0
  41. package/dist/useLegacyTable.cjs +191 -0
  42. package/dist/useLegacyTable.cjs.map +1 -0
  43. package/dist/useLegacyTable.d.cts +233 -0
  44. package/dist/useLegacyTable.d.ts +233 -0
  45. package/dist/useLegacyTable.js +181 -0
  46. package/dist/useLegacyTable.js.map +1 -0
  47. package/dist/useTable.cjs +72 -0
  48. package/dist/useTable.cjs.map +1 -0
  49. package/dist/useTable.d.cts +122 -0
  50. package/dist/useTable.d.ts +122 -0
  51. package/dist/useTable.js +72 -0
  52. package/dist/useTable.js.map +1 -0
  53. package/package.json +41 -22
  54. package/skills/react/client-to-server/SKILL.md +377 -0
  55. package/skills/react/compose-with-tanstack-form/SKILL.md +363 -0
  56. package/skills/react/compose-with-tanstack-pacer/SKILL.md +287 -0
  57. package/skills/react/compose-with-tanstack-query/SKILL.md +467 -0
  58. package/skills/react/compose-with-tanstack-store/SKILL.md +347 -0
  59. package/skills/react/compose-with-tanstack-virtual/SKILL.md +388 -0
  60. package/skills/react/compose-with-tanstack-virtual/references/column-virtualization-and-infinite-scroll.md +136 -0
  61. package/skills/react/getting-started/SKILL.md +388 -0
  62. package/skills/react/migrate-v8-to-v9/SKILL.md +488 -0
  63. package/skills/react/production-readiness/SKILL.md +341 -0
  64. package/skills/react/react-subscribe-compiler-compat/SKILL.md +269 -0
  65. package/skills/react/table-state/SKILL.md +432 -0
  66. package/src/FlexRender.tsx +136 -0
  67. package/src/Subscribe.ts +153 -0
  68. package/src/createTableHook.tsx +1121 -0
  69. package/src/flex-render.ts +1 -0
  70. package/src/index.ts +6 -0
  71. package/src/legacy.ts +3 -0
  72. package/src/reactivity.ts +41 -0
  73. package/src/static-functions.ts +1 -0
  74. package/src/useLegacyTable.ts +487 -0
  75. package/src/useTable.ts +191 -0
  76. package/dist/cjs/index.cjs +0 -77
  77. package/dist/cjs/index.cjs.map +0 -1
  78. package/dist/cjs/index.d.cts +0 -9
  79. package/dist/esm/index.d.ts +0 -9
  80. package/dist/esm/index.js +0 -55
  81. package/dist/esm/index.js.map +0 -1
  82. package/src/index.tsx +0 -92
@@ -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
+ }