@tanstack/vue-table 9.0.0-alpha.9 → 9.0.0-beta.2

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 (70) hide show
  1. package/README.md +127 -0
  2. package/dist/FlexRender.cjs +80 -0
  3. package/dist/FlexRender.cjs.map +1 -0
  4. package/dist/FlexRender.d.cts +45 -0
  5. package/dist/FlexRender.d.ts +45 -0
  6. package/dist/FlexRender.js +79 -0
  7. package/dist/FlexRender.js.map +1 -0
  8. package/dist/createTableHook.cjs +234 -0
  9. package/dist/createTableHook.cjs.map +1 -0
  10. package/dist/createTableHook.d.cts +138 -0
  11. package/dist/createTableHook.d.ts +138 -0
  12. package/dist/createTableHook.js +233 -0
  13. package/dist/createTableHook.js.map +1 -0
  14. package/dist/flex-render.cjs +5 -0
  15. package/dist/flex-render.d.cts +2 -0
  16. package/dist/flex-render.d.ts +2 -0
  17. package/dist/flex-render.js +3 -0
  18. package/dist/index.cjs +17 -0
  19. package/dist/index.d.cts +5 -0
  20. package/dist/index.d.ts +5 -0
  21. package/dist/index.js +7 -0
  22. package/dist/merge-proxy.cjs +77 -0
  23. package/dist/merge-proxy.cjs.map +1 -0
  24. package/dist/merge-proxy.js +75 -0
  25. package/dist/merge-proxy.js.map +1 -0
  26. package/dist/reactivity.cjs +73 -0
  27. package/dist/reactivity.cjs.map +1 -0
  28. package/dist/reactivity.js +73 -0
  29. package/dist/reactivity.js.map +1 -0
  30. package/dist/static-functions.cjs +9 -0
  31. package/dist/static-functions.d.cts +1 -0
  32. package/dist/static-functions.d.ts +1 -0
  33. package/dist/static-functions.js +3 -0
  34. package/dist/useTable.cjs +83 -0
  35. package/dist/useTable.cjs.map +1 -0
  36. package/dist/useTable.d.cts +76 -0
  37. package/dist/useTable.d.ts +76 -0
  38. package/dist/useTable.js +83 -0
  39. package/dist/useTable.js.map +1 -0
  40. package/package.json +31 -19
  41. package/skills/vue/client-to-server/SKILL.md +365 -0
  42. package/skills/vue/compose-with-tanstack-form/SKILL.md +369 -0
  43. package/skills/vue/compose-with-tanstack-pacer/SKILL.md +318 -0
  44. package/skills/vue/compose-with-tanstack-query/SKILL.md +385 -0
  45. package/skills/vue/compose-with-tanstack-store/SKILL.md +301 -0
  46. package/skills/vue/compose-with-tanstack-virtual/SKILL.md +340 -0
  47. package/skills/vue/getting-started/SKILL.md +409 -0
  48. package/skills/vue/migrate-v8-to-v9/SKILL.md +375 -0
  49. package/skills/vue/production-readiness/SKILL.md +271 -0
  50. package/skills/vue/table-state/SKILL.md +403 -0
  51. package/src/FlexRender.ts +123 -0
  52. package/src/createTableHook.ts +597 -0
  53. package/src/flex-render.ts +1 -0
  54. package/src/index.ts +3 -74
  55. package/src/merge-proxy.ts +66 -15
  56. package/src/reactivity.ts +115 -0
  57. package/src/static-functions.ts +1 -0
  58. package/src/useTable.ts +251 -0
  59. package/dist/cjs/index.cjs +0 -68
  60. package/dist/cjs/index.cjs.map +0 -1
  61. package/dist/cjs/index.d.cts +0 -14
  62. package/dist/cjs/merge-proxy.cjs +0 -61
  63. package/dist/cjs/merge-proxy.cjs.map +0 -1
  64. package/dist/cjs/merge-proxy.d.cts +0 -11
  65. package/dist/esm/index.d.ts +0 -14
  66. package/dist/esm/index.js +0 -63
  67. package/dist/esm/index.js.map +0 -1
  68. package/dist/esm/merge-proxy.d.ts +0 -11
  69. package/dist/esm/merge-proxy.js +0 -61
  70. package/dist/esm/merge-proxy.js.map +0 -1
@@ -0,0 +1,76 @@
1
+ import { MaybeRef, VNode } from "vue";
2
+ import { NoInfer, RowData, Table, TableFeatures, TableOptions, TableState } from "@tanstack/table-core";
3
+ import { Atom, ReadonlyAtom, ReadonlyStore, Store } from "@tanstack/vue-store";
4
+
5
+ //#region src/useTable.d.ts
6
+ type SubscribeSource<TValue> = Atom<TValue> | ReadonlyAtom<TValue> | Store<TValue> | ReadonlyStore<TValue>;
7
+ type TableOptionsWithReactiveData<TFeatures extends TableFeatures, TData extends RowData> = { [K in keyof TableOptions<TFeatures, TData>]: K extends 'data' ? MaybeRef<ReadonlyArray<TData>> : MaybeRef<TableOptions<TFeatures, TData>[K]> };
8
+ type VueTable<TFeatures extends TableFeatures, TData extends RowData, TSelected = TableState<TFeatures>> = Omit<Table<TFeatures, TData>, 'store'> & {
9
+ /**
10
+ * @deprecated Prefer `table.state` for render reads,
11
+ * `table.atoms.<slice>.get()` for slice snapshots, or
12
+ * `table.Subscribe` / `useSelector(table.store, selector)` for explicit
13
+ * subscriptions. `table.store.state` is a current-value snapshot and is easy
14
+ * to misuse in render code.
15
+ */
16
+ readonly store: Table<TFeatures, TData>['store'];
17
+ /**
18
+ * Store mode: `selector` required. Source mode: pass `source` (atom or store); omit
19
+ * `selector` for the whole value (identity), or pass `selector` to project. Split
20
+ * overloads so source-only infers `TSourceValue` for `children` (see React `Subscribe`).
21
+ */
22
+ Subscribe: {
23
+ <TSourceValue>(props: {
24
+ source: SubscribeSource<TSourceValue>;
25
+ selector?: undefined;
26
+ children: ((state: Readonly<TSourceValue>) => VNode | Array<VNode>) | VNode | Array<VNode>;
27
+ }): VNode | Array<VNode>;
28
+ <TSourceValue, TSubSelected>(props: {
29
+ source: SubscribeSource<TSourceValue>;
30
+ selector: (state: TSourceValue) => TSubSelected;
31
+ children: ((state: Readonly<TSubSelected>) => VNode | Array<VNode>) | VNode | Array<VNode>;
32
+ }): VNode | Array<VNode>;
33
+ <TSubSelected>(props: {
34
+ selector: (state: NoInfer<TableState<TFeatures>>) => TSubSelected;
35
+ children: ((state: Readonly<TSubSelected>) => VNode | Array<VNode>) | VNode | Array<VNode>;
36
+ }): VNode | Array<VNode>;
37
+ };
38
+ /**
39
+ * The selected state of the table. This state may not match the structure of
40
+ * the full table state because it is selected by the selector function that
41
+ * you pass as the 2nd argument to `useTable`.
42
+ *
43
+ * @example
44
+ * const table = useTable(options, (state) => ({ globalFilter: state.globalFilter })) // only globalFilter is part of the selected state
45
+ *
46
+ * console.log(table.state.globalFilter)
47
+ */
48
+ readonly state: Readonly<TSelected>;
49
+ };
50
+ /**
51
+ * Creates a Vue table instance backed by Vue-aware TanStack Store atoms.
52
+ *
53
+ * Table options may contain Vue refs or computed values. The adapter unwraps
54
+ * those reactive inputs, watches them with synchronous flushing, and keeps the
55
+ * table options in sync. The optional selector projects from `table.store` and
56
+ * exposes the selected value on `table.state`.
57
+ *
58
+ * @example
59
+ * ```ts
60
+ * const table = useTable(
61
+ * {
62
+ * features,
63
+ * rowModels: {},
64
+ * columns,
65
+ * data,
66
+ * },
67
+ * (state) => ({ pagination: state.pagination }),
68
+ * )
69
+ *
70
+ * table.state.pagination
71
+ * ```
72
+ */
73
+ declare function useTable<TFeatures extends TableFeatures, TData extends RowData, TSelected = TableState<TFeatures>>(tableOptions: TableOptions<TFeatures, TData> | TableOptionsWithReactiveData<TFeatures, TData>, selector?: (state: TableState<TFeatures>) => TSelected): VueTable<TFeatures, TData, TSelected>;
74
+ //#endregion
75
+ export { SubscribeSource, TableOptionsWithReactiveData, VueTable, useTable };
76
+ //# sourceMappingURL=useTable.d.ts.map
@@ -0,0 +1,83 @@
1
+ import { flatMerge, mergeProxy } from "./merge-proxy.js";
2
+ import { vueReactivity } from "./reactivity.js";
3
+ import { unref, watch } from "vue";
4
+ import { constructTable } from "@tanstack/table-core";
5
+ import { shallow, useSelector } from "@tanstack/vue-store";
6
+
7
+ //#region src/useTable.ts
8
+ function getOptionsWithReactiveValues(options) {
9
+ const resolvedOptions = {};
10
+ for (const key of Object.keys(options)) resolvedOptions[key] = unref(options[key]);
11
+ return mergeProxy(options, resolvedOptions);
12
+ }
13
+ function getReactiveOptionDeps(options) {
14
+ return Object.keys(options).map((key) => unref(options[key]));
15
+ }
16
+ /**
17
+ * Creates a Vue table instance backed by Vue-aware TanStack Store atoms.
18
+ *
19
+ * Table options may contain Vue refs or computed values. The adapter unwraps
20
+ * those reactive inputs, watches them with synchronous flushing, and keeps the
21
+ * table options in sync. The optional selector projects from `table.store` and
22
+ * exposes the selected value on `table.state`.
23
+ *
24
+ * @example
25
+ * ```ts
26
+ * const table = useTable(
27
+ * {
28
+ * features,
29
+ * rowModels: {},
30
+ * columns,
31
+ * data,
32
+ * },
33
+ * (state) => ({ pagination: state.pagination }),
34
+ * )
35
+ *
36
+ * table.state.pagination
37
+ * ```
38
+ */
39
+ function useTable(tableOptions, selector) {
40
+ const syncTableOptions = (table, options) => {
41
+ table.setOptions((prev) => flatMerge(prev, getOptionsWithReactiveValues(options)));
42
+ };
43
+ const mergedOptions = mergeProxy(tableOptions, { features: {
44
+ coreReativityFeature: vueReactivity(),
45
+ ...unref(tableOptions.features) ?? {}
46
+ } });
47
+ const coreTable = constructTable(mergeProxy(getOptionsWithReactiveValues(mergedOptions), { mergeOptions: (defaultOptions, newOptions) => {
48
+ return flatMerge(defaultOptions, newOptions);
49
+ } }));
50
+ const table = coreTable;
51
+ watch(() => getReactiveOptionDeps(mergedOptions), () => {
52
+ syncTableOptions(coreTable, mergedOptions);
53
+ }, { immediate: true });
54
+ watch(() => {
55
+ const controlledState = unref(tableOptions.state);
56
+ const controlledAtoms = unref(tableOptions.atoms);
57
+ if (!controlledState) return [];
58
+ const controlledValues = [];
59
+ for (const key of Object.keys(table.initialState)) {
60
+ if (!(key in controlledState) || (controlledAtoms === null || controlledAtoms === void 0 ? void 0 : controlledAtoms[key]) !== void 0) continue;
61
+ controlledValues.push(controlledState[key]);
62
+ }
63
+ return controlledValues;
64
+ }, (controlledValues) => {
65
+ if (controlledValues.length > 0) syncTableOptions(coreTable, mergedOptions);
66
+ }, { immediate: true });
67
+ table.Subscribe = ((props) => {
68
+ const selected = useSelector(props.source ?? table.store, props.selector, { compare: shallow });
69
+ if (typeof props.children === "function") return props.children(selected.value);
70
+ return props.children;
71
+ });
72
+ const stateStore = useSelector(table.store, selector);
73
+ return {
74
+ ...table,
75
+ get state() {
76
+ return stateStore.value;
77
+ }
78
+ };
79
+ }
80
+
81
+ //#endregion
82
+ export { useTable };
83
+ //# sourceMappingURL=useTable.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useTable.js","names":[],"sources":["../src/useTable.ts"],"sourcesContent":["import { unref, watch } from 'vue'\nimport { constructTable } from '@tanstack/table-core'\nimport { shallow, useSelector } from '@tanstack/vue-store'\nimport { flatMerge, mergeProxy } from './merge-proxy'\nimport { vueReactivity } from './reactivity'\nimport type {\n Atom,\n ReadonlyAtom,\n ReadonlyStore,\n Store,\n} from '@tanstack/vue-store'\nimport type {\n NoInfer,\n RowData,\n Table,\n TableFeatures,\n TableOptions,\n TableState,\n} from '@tanstack/table-core'\nimport type { MaybeRef, VNode } from 'vue'\n\nexport type SubscribeSource<TValue> =\n | Atom<TValue>\n | ReadonlyAtom<TValue>\n | Store<TValue>\n | ReadonlyStore<TValue>\n\nexport type TableOptionsWithReactiveData<\n TFeatures extends TableFeatures,\n TData extends RowData,\n> = {\n [K in keyof TableOptions<TFeatures, TData>]: K extends 'data'\n ? MaybeRef<ReadonlyArray<TData>>\n : MaybeRef<TableOptions<TFeatures, TData>[K]>\n}\n\nfunction getOptionsWithReactiveValues<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(options: TableOptionsWithReactiveData<TFeatures, TData>) {\n const resolvedOptions: Record<string, unknown> = {}\n\n for (const key of Object.keys(options)) {\n resolvedOptions[key] = unref(\n options[key as keyof TableOptionsWithReactiveData<TFeatures, TData>],\n )\n }\n\n return mergeProxy(options, resolvedOptions)\n}\n\nfunction getReactiveOptionDeps<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(options: TableOptionsWithReactiveData<TFeatures, TData>) {\n return Object.keys(options).map((key) =>\n unref(options[key as keyof TableOptionsWithReactiveData<TFeatures, TData>]),\n )\n}\n\nexport type VueTable<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TSelected = TableState<TFeatures>,\n> = Omit<Table<TFeatures, TData>, 'store'> & {\n /**\n * @deprecated Prefer `table.state` for render reads,\n * `table.atoms.<slice>.get()` for slice snapshots, or\n * `table.Subscribe` / `useSelector(table.store, selector)` for explicit\n * subscriptions. `table.store.state` is a current-value snapshot and is easy\n * to misuse in render code.\n */\n readonly store: Table<TFeatures, TData>['store']\n /**\n * Store mode: `selector` required. Source mode: pass `source` (atom or store); omit\n * `selector` for the whole value (identity), or pass `selector` to project. Split\n * overloads so source-only infers `TSourceValue` for `children` (see React `Subscribe`).\n */\n Subscribe: {\n <TSourceValue>(props: {\n source: SubscribeSource<TSourceValue>\n selector?: undefined\n children:\n | ((state: Readonly<TSourceValue>) => VNode | Array<VNode>)\n | VNode\n | Array<VNode>\n }): VNode | Array<VNode>\n <TSourceValue, TSubSelected>(props: {\n source: SubscribeSource<TSourceValue>\n selector: (state: TSourceValue) => TSubSelected\n children:\n | ((state: Readonly<TSubSelected>) => VNode | Array<VNode>)\n | VNode\n | Array<VNode>\n }): VNode | Array<VNode>\n <TSubSelected>(props: {\n selector: (state: NoInfer<TableState<TFeatures>>) => TSubSelected\n children:\n | ((state: Readonly<TSubSelected>) => VNode | Array<VNode>)\n | VNode\n | Array<VNode>\n }): VNode | Array<VNode>\n }\n /**\n * The selected state of the table. This state may not match the structure of\n * the full table state because it is selected by the selector function that\n * you pass as the 2nd argument to `useTable`.\n *\n * @example\n * const table = useTable(options, (state) => ({ globalFilter: state.globalFilter })) // only globalFilter is part of the selected state\n *\n * console.log(table.state.globalFilter)\n */\n readonly state: Readonly<TSelected>\n}\n\n/**\n * Creates a Vue table instance backed by Vue-aware TanStack Store atoms.\n *\n * Table options may contain Vue refs or computed values. The adapter unwraps\n * those reactive inputs, watches them with synchronous flushing, and keeps the\n * table options in sync. The optional selector projects from `table.store` and\n * exposes the selected value on `table.state`.\n *\n * @example\n * ```ts\n * const table = useTable(\n * {\n * features,\n * rowModels: {},\n * columns,\n * data,\n * },\n * (state) => ({ pagination: state.pagination }),\n * )\n *\n * table.state.pagination\n * ```\n */\nexport function useTable<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TSelected = TableState<TFeatures>,\n>(\n tableOptions:\n | TableOptions<TFeatures, TData>\n | TableOptionsWithReactiveData<TFeatures, TData>,\n selector?: (state: TableState<TFeatures>) => TSelected,\n): VueTable<TFeatures, TData, TSelected> {\n const syncTableOptions = (\n table: Table<TFeatures, TData>,\n options: TableOptionsWithReactiveData<TFeatures, TData>,\n ) => {\n table.setOptions((prev) =>\n flatMerge(prev, getOptionsWithReactiveValues(options)),\n )\n }\n\n const mergedOptions = mergeProxy(tableOptions, {\n features: {\n coreReativityFeature: vueReactivity(),\n ...(unref(tableOptions.features) ?? {}),\n },\n }) as TableOptionsWithReactiveData<TFeatures, TData>\n\n const resolvedOptions = mergeProxy(\n getOptionsWithReactiveValues(mergedOptions),\n {\n // Remove state and onStateChange - store handles it internally\n mergeOptions: (\n defaultOptions: TableOptions<TFeatures, TData>,\n newOptions: Partial<TableOptions<TFeatures, TData>>,\n ) => {\n return flatMerge(defaultOptions, newOptions)\n },\n },\n ) as TableOptions<TFeatures, TData>\n\n const coreTable = constructTable(resolvedOptions)\n const table = coreTable as unknown as VueTable<TFeatures, TData, TSelected>\n\n watch(\n () => getReactiveOptionDeps(mergedOptions),\n () => {\n syncTableOptions(coreTable, mergedOptions)\n },\n { immediate: true },\n )\n\n watch(\n () => {\n const controlledState = unref(tableOptions.state) as\n | Record<string, unknown>\n | undefined\n const controlledAtoms = unref(tableOptions.atoms) as\n | Record<string, unknown>\n | undefined\n\n if (!controlledState) {\n return []\n }\n\n const controlledValues: Array<unknown> = []\n\n for (const key of Object.keys(table.initialState)) {\n if (!(key in controlledState) || controlledAtoms?.[key] !== undefined) {\n continue\n }\n\n // Reading only controlled state slices here lets Vue subscribe to\n // getters/computed values that are passed through `options.state`.\n controlledValues.push(controlledState[key])\n }\n\n return controlledValues\n },\n (controlledValues) => {\n if (controlledValues.length > 0) {\n syncTableOptions(coreTable, mergedOptions)\n }\n },\n { immediate: true },\n )\n\n table.Subscribe = ((props: {\n source?: SubscribeSource<unknown>\n selector?: ((state: unknown) => unknown) | undefined\n children:\n | ((state: Readonly<unknown>) => VNode | Array<VNode>)\n | VNode\n | Array<VNode>\n }) => {\n const source = props.source ?? table.store\n const selected = useSelector(source as never, props.selector as never, {\n compare: shallow,\n })\n if (typeof props.children === 'function') {\n return props.children(selected.value as Readonly<unknown>)\n }\n return props.children\n }) as VueTable<TFeatures, TData, TSelected>['Subscribe']\n\n const stateStore = useSelector(table.store, selector)\n\n return {\n ...table,\n get state() {\n return stateStore.value\n },\n }\n}\n"],"mappings":";;;;;;;AAoCA,SAAS,6BAGP,SAAyD;CACzD,MAAM,kBAA2C,CAAC;CAElD,KAAK,MAAM,OAAO,OAAO,KAAK,OAAO,GACnC,gBAAgB,OAAO,MACrB,QAAQ,IACV;CAGF,OAAO,WAAW,SAAS,eAAe;AAC5C;AAEA,SAAS,sBAGP,SAAyD;CACzD,OAAO,OAAO,KAAK,OAAO,CAAC,CAAC,KAAK,QAC/B,MAAM,QAAQ,IAA4D,CAC5E;AACF;;;;;;;;;;;;;;;;;;;;;;;;AAiFA,SAAgB,SAKd,cAGA,UACuC;CACvC,MAAM,oBACJ,OACA,YACG;EACH,MAAM,YAAY,SAChB,UAAU,MAAM,6BAA6B,OAAO,CAAC,CACvD;CACF;CAEA,MAAM,gBAAgB,WAAW,cAAc,EAC7C,UAAU;EACR,sBAAsB,cAAc;EACpC,GAAI,MAAM,aAAa,QAAQ,KAAK,CAAC;CACvC,EACF,CAAC;CAeD,MAAM,YAAY,eAbM,WACtB,6BAA6B,aAAa,GAC1C,EAEE,eACE,gBACA,eACG;EACH,OAAO,UAAU,gBAAgB,UAAU;CAC7C,EACF,CAG6C,CAAC;CAChD,MAAM,QAAQ;CAEd,YACQ,sBAAsB,aAAa,SACnC;EACJ,iBAAiB,WAAW,aAAa;CAC3C,GACA,EAAE,WAAW,KAAK,CACpB;CAEA,YACQ;EACJ,MAAM,kBAAkB,MAAM,aAAa,KAAK;EAGhD,MAAM,kBAAkB,MAAM,aAAa,KAAK;EAIhD,IAAI,CAAC,iBACH,OAAO,CAAC;EAGV,MAAM,mBAAmC,CAAC;EAE1C,KAAK,MAAM,OAAO,OAAO,KAAK,MAAM,YAAY,GAAG;GACjD,IAAI,EAAE,OAAO,uFAAoB,gBAAkB,UAAS,QAC1D;GAKF,iBAAiB,KAAK,gBAAgB,IAAI;EAC5C;EAEA,OAAO;CACT,IACC,qBAAqB;EACpB,IAAI,iBAAiB,SAAS,GAC5B,iBAAiB,WAAW,aAAa;CAE7C,GACA,EAAE,WAAW,KAAK,CACpB;CAEA,MAAM,cAAc,UAOd;EAEJ,MAAM,WAAW,YADF,MAAM,UAAU,MAAM,OACS,MAAM,UAAmB,EACrE,SAAS,QACX,CAAC;EACD,IAAI,OAAO,MAAM,aAAa,YAC5B,OAAO,MAAM,SAAS,SAAS,KAA0B;EAE3D,OAAO,MAAM;CACf;CAEA,MAAM,aAAa,YAAY,MAAM,OAAO,QAAQ;CAEpD,OAAO;EACL,GAAG;EACH,IAAI,QAAQ;GACV,OAAO,WAAW;EACpB;CACF;AACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/vue-table",
3
- "version": "9.0.0-alpha.9",
3
+ "version": "9.0.0-beta.2",
4
4
  "description": "Headless UI for building powerful tables & datagrids for Vue.",
5
5
  "author": "Tanner Linsley",
6
6
  "license": "MIT",
@@ -18,42 +18,54 @@
18
18
  "vue",
19
19
  "table",
20
20
  "vue-table",
21
- "datagrid"
21
+ "datagrid",
22
+ "tanstack-intent"
22
23
  ],
23
24
  "type": "module",
24
- "types": "dist/esm/index.d.ts",
25
- "main": "dist/cjs/index.cjs",
26
- "module": "dist/esm/index.js",
25
+ "types": "./dist/index.d.cts",
26
+ "main": "./dist/index.cjs",
27
+ "module": "./dist/index.js",
27
28
  "exports": {
28
29
  ".": {
29
- "import": {
30
- "types": "./dist/esm/index.d.ts",
31
- "default": "./dist/esm/index.js"
32
- },
33
- "require": {
34
- "types": "./dist/cjs/index.d.cts",
35
- "default": "./dist/cjs/index.cjs"
36
- }
30
+ "import": "./dist/index.js",
31
+ "require": "./dist/index.cjs"
32
+ },
33
+ "./flex-render": {
34
+ "import": "./dist/flex-render.js",
35
+ "require": "./dist/flex-render.cjs"
36
+ },
37
+ "./static-functions": {
38
+ "import": "./dist/static-functions.js",
39
+ "require": "./dist/static-functions.cjs"
37
40
  },
38
41
  "./package.json": "./package.json"
39
42
  },
40
43
  "sideEffects": false,
41
44
  "engines": {
42
- "node": ">=12"
45
+ "node": ">=16"
43
46
  },
44
47
  "files": [
45
48
  "dist",
46
- "src"
49
+ "src",
50
+ "skills"
47
51
  ],
48
52
  "dependencies": {
49
- "@tanstack/table-core": "9.0.0-alpha.8"
53
+ "@tanstack/table-core": "9.0.0-beta.1",
54
+ "@tanstack/vue-store": "^0.11.0"
50
55
  },
51
56
  "devDependencies": {
52
- "@vitejs/plugin-vue": "^5.0.5",
53
- "vue": "^3.4.31"
57
+ "@vitejs/plugin-vue": "^6.0.7",
58
+ "eslint-plugin-vue": "^10.9.2",
59
+ "vue": "^3.5.35"
54
60
  },
55
61
  "peerDependencies": {
56
62
  "vue": ">=3.2"
57
63
  },
58
- "scripts": {}
64
+ "scripts": {
65
+ "clean": "rimraf ./build && rimraf ./dist",
66
+ "test:eslint": "eslint ./src",
67
+ "test:types": "tsc",
68
+ "test:build": "publint --strict",
69
+ "build": "tsdown"
70
+ }
59
71
  }
@@ -0,0 +1,365 @@
1
+ ---
2
+ name: vue/client-to-server
3
+ description: >
4
+ Convert a client-side `@tanstack/vue-table` to server-side. Set `manualPagination` /
5
+ `manualSorting` / `manualFiltering` / `manualGrouping` / `manualExpanding` for whichever
6
+ slices the server owns; drop the matching `rowModels` factories (don't ship
7
+ `paginatedRowModel` when the server paginates); supply `rowCount` so `table.getPageCount()`
8
+ works; own the relevant state slices via either external atoms (`@tanstack/vue-store`
9
+ `createAtom` + `options.atoms`) or `state` + `on[State]Change` with getter wrappers. Key any
10
+ data fetch (TanStack Query / fetch / rxResource alternative) on the controlled state and use
11
+ `placeholderData: keepPreviousData` (or equivalent) to avoid a 0-rows flash between pages.
12
+ type: lifecycle
13
+ library: tanstack-table
14
+ framework: vue
15
+ library_version: '9.0.0-alpha.48'
16
+ requires:
17
+ - state-management
18
+ - pagination
19
+ - filtering
20
+ - sorting
21
+ sources:
22
+ - examples/vue/basic-external-atoms/
23
+ - examples/vue/basic-external-state/
24
+ - examples/vue/with-tanstack-query/
25
+ - docs/framework/vue/guide/table-state.md
26
+ ---
27
+
28
+ # Client-to-Server Conversion (Vue)
29
+
30
+ ## Dependencies
31
+
32
+ ```bash
33
+ pnpm add @tanstack/vue-table @tanstack/vue-store
34
+ # Recommended fetch layer:
35
+ pnpm add @tanstack/vue-query
36
+ ```
37
+
38
+ External atoms (`@tanstack/vue-store`) are recommended for server-managed slices. They cut the
39
+ `on[State]Change` plumbing entirely — the table writes to the atom; the query keys on the atom.
40
+
41
+ ## Setup — minimal server-paginated table
42
+
43
+ ```vue
44
+ <script setup lang="ts">
45
+ import { computed, ref, watchEffect } from 'vue'
46
+ import { createAtom, useSelector } from '@tanstack/vue-store'
47
+ import { keepPreviousData, useQuery } from '@tanstack/vue-query'
48
+ import {
49
+ FlexRender,
50
+ createColumnHelper,
51
+ rowPaginationFeature,
52
+ tableFeatures,
53
+ useTable,
54
+ type PaginationState,
55
+ } from '@tanstack/vue-table'
56
+ import { fetchPeople } from './api'
57
+
58
+ type Person = { firstName: string; lastName: string; age: number }
59
+
60
+ const features = tableFeatures({ rowPaginationFeature })
61
+ const columnHelper = createColumnHelper<typeof features, Person>()
62
+ const columns = columnHelper.columns([
63
+ columnHelper.accessor('firstName', { header: 'First' }),
64
+ columnHelper.accessor('lastName', { header: 'Last' }),
65
+ columnHelper.accessor('age', { header: 'Age' }),
66
+ ])
67
+
68
+ // 1) Own pagination in an external atom. Cheap for the table to write through.
69
+ const paginationAtom = createAtom<PaginationState>({
70
+ pageIndex: 0,
71
+ pageSize: 10,
72
+ })
73
+ const pagination = useSelector(paginationAtom)
74
+
75
+ // 2) Key the query on the atom value. table.setPageIndex(...) writes to the atom
76
+ // → useSelector re-evaluates → useQuery refetches.
77
+ const dataQuery = useQuery(() => ({
78
+ queryKey: ['people', pagination.value],
79
+ queryFn: () => fetchPeople(pagination.value),
80
+ placeholderData: keepPreviousData, // avoid "0 rows" flash between pages
81
+ }))
82
+
83
+ const tableData = computed<Person[]>(() => dataQuery.data.value?.rows ?? [])
84
+ const rowCount = ref(0)
85
+ watchEffect(() => {
86
+ const next = dataQuery.data.value?.rowCount
87
+ if (next != null) rowCount.value = next // keep last known total for pager UI
88
+ })
89
+
90
+ // 3) Manual pagination + `rowCount`. NO paginatedRowModel in `rowModels` — server paginates.
91
+ const table = useTable({
92
+ features,
93
+ rowModels: {},
94
+ columns,
95
+ data: tableData,
96
+ rowCount,
97
+ atoms: { pagination: paginationAtom },
98
+ manualPagination: true,
99
+ })
100
+ </script>
101
+ ```
102
+
103
+ Source: `examples/vue/with-tanstack-query/src/App.tsx`, `examples/vue/basic-external-atoms/`.
104
+
105
+ ## Core Patterns
106
+
107
+ ### 1. The `manual*` flag + `rowModels` drop pair
108
+
109
+ Pick which slices live server-side and flip the matching `manual*` flag. **Also drop the
110
+ matching `rowModels` factory** — otherwise the table re-processes server-processed rows.
111
+
112
+ | Server owns | Set | Drop from `rowModels` |
113
+ | ----------- | ------------------------ | --------------------- |
114
+ | Pagination | `manualPagination: true` | `paginatedRowModel` |
115
+ | Sorting | `manualSorting: true` | `sortedRowModel` |
116
+ | Filtering | `manualFiltering: true` | `filteredRowModel` |
117
+ | Grouping | `manualGrouping: true` | `groupedRowModel` |
118
+ | Expanding | `manualExpanding: true` | `expandedRowModel` |
119
+
120
+ Column visibility / ordering / pinning / row selection are client-side state and stay as-is.
121
+
122
+ ### 2. `rowCount` so `getPageCount()` works
123
+
124
+ Without `rowCount`, `getPageCount()` falls back to `Math.ceil(data.length / pageSize)` — i.e.
125
+ `1` if the server already paginated. The pager locks at "Page 1 of 1".
126
+
127
+ ```ts
128
+ useTable({
129
+ features,
130
+ rowModels: {},
131
+ columns,
132
+ data: tableData,
133
+ rowCount: dataQuery.data.value?.rowCount, // or a stable ref/computed
134
+ atoms: { pagination: paginationAtom },
135
+ manualPagination: true,
136
+ })
137
+ ```
138
+
139
+ If `rowCount` isn't immediately available, hold the last known value in a `ref` and update via
140
+ `watchEffect` so the pager doesn't reset to 0 during refetches.
141
+
142
+ ### 3. Two state-ownership shapes (pick one per slice)
143
+
144
+ **External atoms (recommended with Query).** Table writes through to the atom. No
145
+ `on[State]Change` needed.
146
+
147
+ ```ts
148
+ const paginationAtom = createAtom<PaginationState>({
149
+ pageIndex: 0,
150
+ pageSize: 10,
151
+ })
152
+ useTable({
153
+ features,
154
+ rowModels: {},
155
+ columns,
156
+ data,
157
+ rowCount,
158
+ atoms: { pagination: paginationAtom },
159
+ manualPagination: true,
160
+ })
161
+ ```
162
+
163
+ **Classic `state` + `on[State]Change` with getters.** Required when migrating from v8 or
164
+ integrating with existing Vue ref-based state. Each slice must be a getter so Vue tracks
165
+ `.value`.
166
+
167
+ ```ts
168
+ const pagination = ref<PaginationState>({ pageIndex: 0, pageSize: 10 })
169
+
170
+ useTable({
171
+ features,
172
+ rowModels: {},
173
+ columns,
174
+ data,
175
+ rowCount,
176
+ state: {
177
+ get pagination() {
178
+ return pagination.value
179
+ },
180
+ },
181
+ onPaginationChange: (u) => {
182
+ pagination.value = typeof u === 'function' ? u(pagination.value) : u
183
+ },
184
+ manualPagination: true,
185
+ })
186
+ ```
187
+
188
+ **Precedence:** `atoms[slice]` > `state[slice]` > internal `baseAtoms[slice]`. Don't pass the
189
+ same slice through both — the atoms wins silently.
190
+
191
+ ### 4. Cache keys must include controlled state
192
+
193
+ ```ts
194
+ const sortingAtom = createAtom<SortingState>([])
195
+ const paginationAtom = createAtom<PaginationState>({
196
+ pageIndex: 0,
197
+ pageSize: 10,
198
+ })
199
+ const sorting = useSelector(sortingAtom)
200
+ const pagination = useSelector(paginationAtom)
201
+
202
+ const dataQuery = useQuery(() => ({
203
+ queryKey: [
204
+ 'people',
205
+ { sorting: sorting.value, pagination: pagination.value },
206
+ ],
207
+ queryFn: () =>
208
+ fetchPeople({ sorting: sorting.value, pagination: pagination.value }),
209
+ placeholderData: keepPreviousData,
210
+ }))
211
+ ```
212
+
213
+ If pagination/sort/filter aren't in `queryKey`, Query won't refetch when the user clicks a
214
+ pager button — the buttons "do nothing" from the user's POV.
215
+
216
+ ### 5. Mixed client + server features still work
217
+
218
+ Column visibility, ordering, pinning, and row selection are client state — they don't depend
219
+ on the row model and continue to function with `manualPagination`/`manualSorting`/`manualFiltering`.
220
+ You can have a server-paginated table where the user pins or hides columns locally.
221
+
222
+ ## Common Mistakes
223
+
224
+ ### Forgetting `manualPagination` / `manualSorting` / `manualFiltering` (CRITICAL)
225
+
226
+ The table double-processes server-processed rows. If the server returned page 2 of 50,
227
+ the table will paginate that 10-row slice again and show "Page 1 of 1".
228
+
229
+ ```ts
230
+ // ❌
231
+ useTable({
232
+ features,
233
+ rowModels: {},
234
+ columns,
235
+ data: serverPage.rows,
236
+ rowCount,
237
+ atoms: { pagination: paginationAtom },
238
+ // missing: manualPagination: true
239
+ })
240
+ ```
241
+
242
+ ### Leaving `paginatedRowModel` registered when server paginates (CRITICAL)
243
+
244
+ ```ts
245
+ // ❌ Factory ships for nothing AND the table re-paginates server-sliced data.
246
+ rowModels: {
247
+ paginatedRowModel: createPaginatedRowModel()
248
+ }
249
+
250
+ // ✅
251
+ rowModels: {
252
+ }
253
+ ```
254
+
255
+ Same applies to `sortedRowModel`, `filteredRowModel`, `groupedRowModel`, `expandedRowModel`
256
+ when the server owns the slice.
257
+
258
+ ### Omitting `rowCount` (CRITICAL)
259
+
260
+ `getPageCount()` returns `1` if the server already paginated. The pager UI locks at
261
+ "Page 1 of 1" and users can't navigate.
262
+
263
+ ### Passing `state.pagination` without `onPaginationChange` (CRITICAL)
264
+
265
+ ```ts
266
+ // ❌ table.setPageIndex(2) is a no-op — no writeback handler.
267
+ const pagination = ref({ pageIndex: 0, pageSize: 10 })
268
+ useTable({
269
+ features,
270
+ rowModels: {},
271
+ columns,
272
+ data,
273
+ rowCount,
274
+ state: {
275
+ get pagination() {
276
+ return pagination.value
277
+ },
278
+ },
279
+ manualPagination: true,
280
+ })
281
+
282
+ // ✅ Either pair `state` with `on[State]Change`, OR use `atoms`.
283
+ ```
284
+
285
+ ### Mixing `state.pagination` AND `atoms.pagination` for the same slice (HIGH)
286
+
287
+ ```ts
288
+ useTable({
289
+ // ...
290
+ state: {
291
+ get pagination() {
292
+ return localPagination.value
293
+ },
294
+ }, // silently ignored
295
+ onPaginationChange: setLocalPagination, // silently ignored
296
+ atoms: { pagination: paginationAtom }, // wins
297
+ })
298
+ ```
299
+
300
+ Atoms beat `state`; the `state` plumbing is dead but lingering in the code. Pick one mechanism.
301
+
302
+ ### Forgetting to include controlled state in `queryKey` (CRITICAL)
303
+
304
+ ```ts
305
+ // ❌ Never refetches when pagination changes.
306
+ useQuery(() => ({
307
+ queryKey: ['people'],
308
+ queryFn: () => fetchPeople(pagination.value),
309
+ }))
310
+
311
+ // ✅
312
+ useQuery(() => ({
313
+ queryKey: ['people', pagination.value],
314
+ queryFn: () => fetchPeople(pagination.value),
315
+ }))
316
+ ```
317
+
318
+ ### Skipping `placeholderData: keepPreviousData` (HIGH)
319
+
320
+ Between fetches the table collapses to 0 rows, the row container collapses, and scroll
321
+ position jumps. `keepPreviousData` keeps the previous page visible during the refetch.
322
+
323
+ ### Passing a raw `ref` to `state.pagination` without a getter (CRITICAL — Vue-specific)
324
+
325
+ ```ts
326
+ // ❌ Vue can't track .value changes on the captured ref object.
327
+ state: { pagination: pagination }
328
+
329
+ // ✅
330
+ state: { get pagination() { return pagination.value } }
331
+ ```
332
+
333
+ ### Hand-rolling sort/page state instead of using the API (CRITICAL — #1 AI tell)
334
+
335
+ ```ts
336
+ // ❌ Manual state machine.
337
+ const pageIndex = ref(0)
338
+ const next = () => {
339
+ pageIndex.value++
340
+ refetch()
341
+ }
342
+
343
+ // ✅ Built-ins.
344
+ table.nextPage()
345
+ table.setPageIndex(0)
346
+ table.setSorting([{ id: 'age', desc: true }])
347
+ table.setColumnFilters(/* ... */)
348
+ ```
349
+
350
+ ### "API missing" because the feature isn't in `features` (CRITICAL — v9-specific)
351
+
352
+ Server-side pagination still needs `rowPaginationFeature` in `tableFeatures({...})` — that's
353
+ what surfaces `table.setPageIndex`, `table.nextPage`, `table.getPageCount`. The factory in
354
+ `rowModels` is what you drop; the feature stays.
355
+
356
+ ```ts
357
+ const features = tableFeatures({ rowPaginationFeature }) // ✅ even with manualPagination
358
+ ```
359
+
360
+ ## See Also
361
+
362
+ - `tanstack-table/vue/compose-with-tanstack-query` — the Query-specific wiring
363
+ - `tanstack-table/vue/compose-with-tanstack-store` — external atoms in depth
364
+ - `tanstack-table/vue/table-state` — getter rule, atom precedence
365
+ - `tanstack-table/table-core/pagination` — `manualPagination` / `rowCount` semantics