@tanstack/vue-table 9.0.0-alpha.10 → 9.0.0-alpha.26

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 (45) hide show
  1. package/README.md +117 -0
  2. package/dist/FlexRender.cjs +73 -0
  3. package/dist/FlexRender.cjs.map +1 -0
  4. package/dist/FlexRender.d.cts +46 -0
  5. package/dist/FlexRender.d.ts +46 -0
  6. package/dist/FlexRender.js +72 -0
  7. package/dist/FlexRender.js.map +1 -0
  8. package/dist/createTableHook.cjs +216 -0
  9. package/dist/createTableHook.cjs.map +1 -0
  10. package/dist/createTableHook.d.cts +121 -0
  11. package/dist/createTableHook.d.ts +121 -0
  12. package/dist/createTableHook.js +215 -0
  13. package/dist/createTableHook.js.map +1 -0
  14. package/dist/index.cjs +17 -0
  15. package/dist/index.d.cts +5 -0
  16. package/dist/index.d.ts +5 -0
  17. package/dist/index.js +7 -0
  18. package/dist/merge-proxy.cjs +57 -0
  19. package/dist/merge-proxy.cjs.map +1 -0
  20. package/dist/merge-proxy.js +56 -0
  21. package/dist/merge-proxy.js.map +1 -0
  22. package/dist/useTable.cjs +55 -0
  23. package/dist/useTable.cjs.map +1 -0
  24. package/dist/useTable.d.cts +40 -0
  25. package/dist/useTable.d.ts +40 -0
  26. package/dist/useTable.js +55 -0
  27. package/dist/useTable.js.map +1 -0
  28. package/package.json +19 -17
  29. package/src/FlexRender.ts +109 -0
  30. package/src/createTableHook.ts +576 -0
  31. package/src/index.ts +3 -74
  32. package/src/merge-proxy.ts +10 -10
  33. package/src/useTable.ts +172 -0
  34. package/dist/cjs/index.cjs +0 -68
  35. package/dist/cjs/index.cjs.map +0 -1
  36. package/dist/cjs/index.d.cts +0 -14
  37. package/dist/cjs/merge-proxy.cjs +0 -61
  38. package/dist/cjs/merge-proxy.cjs.map +0 -1
  39. package/dist/cjs/merge-proxy.d.cts +0 -11
  40. package/dist/esm/index.d.ts +0 -14
  41. package/dist/esm/index.js +0 -63
  42. package/dist/esm/index.js.map +0 -1
  43. package/dist/esm/merge-proxy.d.ts +0 -11
  44. package/dist/esm/merge-proxy.js +0 -61
  45. package/dist/esm/merge-proxy.js.map +0 -1
@@ -0,0 +1,56 @@
1
+ //#region src/merge-proxy.ts
2
+ function trueFn() {
3
+ return true;
4
+ }
5
+ const $PROXY = Symbol("merge-proxy");
6
+ const propTraps = {
7
+ get(_, property, receiver) {
8
+ if (property === $PROXY) return receiver;
9
+ return _.get(property);
10
+ },
11
+ has(_, property) {
12
+ return _.has(property);
13
+ },
14
+ set: trueFn,
15
+ deleteProperty: trueFn,
16
+ getOwnPropertyDescriptor(_, property) {
17
+ return {
18
+ configurable: true,
19
+ enumerable: true,
20
+ get() {
21
+ return _.get(property);
22
+ },
23
+ set: trueFn,
24
+ deleteProperty: trueFn
25
+ };
26
+ },
27
+ ownKeys(_) {
28
+ return _.keys();
29
+ }
30
+ };
31
+ function resolveSource(s) {
32
+ return "value" in s ? s.value : s;
33
+ }
34
+ function mergeProxy(...sources) {
35
+ return new Proxy({
36
+ get(property) {
37
+ for (let i = sources.length - 1; i >= 0; i--) {
38
+ const v = resolveSource(sources[i])[property];
39
+ if (v !== void 0) return v;
40
+ }
41
+ },
42
+ has(property) {
43
+ for (let i = sources.length - 1; i >= 0; i--) if (property in resolveSource(sources[i])) return true;
44
+ return false;
45
+ },
46
+ keys() {
47
+ const keys = [];
48
+ for (const source of sources) keys.push(...Object.keys(resolveSource(source)));
49
+ return [...Array.from(new Set(keys))];
50
+ }
51
+ }, propTraps);
52
+ }
53
+
54
+ //#endregion
55
+ export { mergeProxy };
56
+ //# sourceMappingURL=merge-proxy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"merge-proxy.js","names":[],"sources":["../src/merge-proxy.ts"],"sourcesContent":["function trueFn() {\n return true\n}\n\nconst $PROXY = Symbol('merge-proxy')\n\n// https://github.com/solidjs/solid/blob/c20ca4fd8c36bc0522fedb2c7f38a110b7ee2663/packages/solid/src/render/component.ts#L51-L118\nconst propTraps: ProxyHandler<{\n get: (k: string | number | symbol) => any\n has: (k: string | number | symbol) => boolean\n keys: () => Array<string>\n}> = {\n get(_, property, receiver) {\n if (property === $PROXY) return receiver\n return _.get(property)\n },\n has(_, property) {\n return _.has(property)\n },\n set: trueFn,\n deleteProperty: trueFn,\n getOwnPropertyDescriptor(_, property) {\n return {\n configurable: true,\n enumerable: true,\n get() {\n return _.get(property)\n },\n set: trueFn,\n deleteProperty: trueFn,\n }\n },\n ownKeys(_) {\n return _.keys()\n },\n}\n\ntype UnboxLazy<T> = T extends () => infer U ? U : T\ntype BoxedTupleTypes<T extends Array<any>> = {\n [P in keyof T]: [UnboxLazy<T[P]>]\n}[Exclude<keyof T, keyof Array<any>>]\ntype UnionToIntersection<T> = (T extends any ? (k: T) => void : never) extends (\n k: infer I,\n) => void\n ? I\n : never\ntype UnboxIntersection<T> = T extends { 0: infer U } ? U : never\ntype MergeProxy<T extends Array<any>> = UnboxIntersection<\n UnionToIntersection<BoxedTupleTypes<T>>\n>\n\nfunction resolveSource(s: any) {\n return 'value' in s ? s.value : s\n}\n\nexport function mergeProxy<T extends Array<any>>(...sources: T): MergeProxy<T>\nexport function mergeProxy(...sources: any): any {\n return new Proxy(\n {\n get(property: string | number | symbol) {\n for (let i = sources.length - 1; i >= 0; i--) {\n const v = resolveSource(sources[i])[property]\n if (v !== undefined) return v\n }\n },\n has(property: string | number | symbol) {\n for (let i = sources.length - 1; i >= 0; i--) {\n if (property in resolveSource(sources[i])) return true\n }\n return false\n },\n keys() {\n const keys = []\n for (const source of sources)\n keys.push(...Object.keys(resolveSource(source)))\n return [...Array.from(new Set(keys))]\n },\n },\n propTraps,\n )\n}\n"],"mappings":";AAAA,SAAS,SAAS;AAChB,QAAO;;AAGT,MAAM,SAAS,OAAO,cAAc;AAGpC,MAAM,YAID;CACH,IAAI,GAAG,UAAU,UAAU;AACzB,MAAI,aAAa,OAAQ,QAAO;AAChC,SAAO,EAAE,IAAI,SAAS;;CAExB,IAAI,GAAG,UAAU;AACf,SAAO,EAAE,IAAI,SAAS;;CAExB,KAAK;CACL,gBAAgB;CAChB,yBAAyB,GAAG,UAAU;AACpC,SAAO;GACL,cAAc;GACd,YAAY;GACZ,MAAM;AACJ,WAAO,EAAE,IAAI,SAAS;;GAExB,KAAK;GACL,gBAAgB;GACjB;;CAEH,QAAQ,GAAG;AACT,SAAO,EAAE,MAAM;;CAElB;AAgBD,SAAS,cAAc,GAAQ;AAC7B,QAAO,WAAW,IAAI,EAAE,QAAQ;;AAIlC,SAAgB,WAAW,GAAG,SAAmB;AAC/C,QAAO,IAAI,MACT;EACE,IAAI,UAAoC;AACtC,QAAK,IAAI,IAAI,QAAQ,SAAS,GAAG,KAAK,GAAG,KAAK;IAC5C,MAAM,IAAI,cAAc,QAAQ,GAAG,CAAC;AACpC,QAAI,MAAM,OAAW,QAAO;;;EAGhC,IAAI,UAAoC;AACtC,QAAK,IAAI,IAAI,QAAQ,SAAS,GAAG,KAAK,GAAG,IACvC,KAAI,YAAY,cAAc,QAAQ,GAAG,CAAE,QAAO;AAEpD,UAAO;;EAET,OAAO;GACL,MAAM,OAAO,EAAE;AACf,QAAK,MAAM,UAAU,QACnB,MAAK,KAAK,GAAG,OAAO,KAAK,cAAc,OAAO,CAAC,CAAC;AAClD,UAAO,CAAC,GAAG,MAAM,KAAK,IAAI,IAAI,KAAK,CAAC,CAAC;;EAExC,EACD,UACD"}
@@ -0,0 +1,55 @@
1
+ const require_merge_proxy = require('./merge-proxy.cjs');
2
+ let vue = require("vue");
3
+ let _tanstack_table_core = require("@tanstack/table-core");
4
+ let _tanstack_vue_store = require("@tanstack/vue-store");
5
+
6
+ //#region src/useTable.ts
7
+ function getOptionsWithReactiveData(options) {
8
+ return require_merge_proxy.mergeProxy(options, { data: (0, vue.unref)(options.data) });
9
+ }
10
+ function useTable(tableOptions, selector = () => ({})) {
11
+ const notifier = (0, vue.ref)(0);
12
+ const vueReactivityFeature = (0, _tanstack_table_core.constructReactivityFeature)({
13
+ stateNotifier: () => notifier.value,
14
+ optionsNotifier: () => notifier.value
15
+ });
16
+ const IS_REACTIVE = (0, vue.isRef)(tableOptions.data);
17
+ const mergedOptions = {
18
+ ...tableOptions,
19
+ _features: {
20
+ ...tableOptions._features,
21
+ vueReactivityFeature
22
+ }
23
+ };
24
+ const table = (0, _tanstack_table_core.constructTable)(require_merge_proxy.mergeProxy(IS_REACTIVE ? getOptionsWithReactiveData(mergedOptions) : mergedOptions, { mergeOptions: (defaultOptions, newOptions) => {
25
+ return require_merge_proxy.mergeProxy(defaultOptions, newOptions);
26
+ } }));
27
+ const allState = (0, _tanstack_vue_store.useStore)(table.store, (state) => state);
28
+ const allOptions = (0, _tanstack_vue_store.useStore)(table.optionsStore, (state) => state);
29
+ (0, vue.watchEffect)(() => {
30
+ allState.value;
31
+ allOptions.value;
32
+ notifier.value++;
33
+ });
34
+ (0, vue.watch)(() => [IS_REACTIVE ? (0, vue.unref)(tableOptions.data) : tableOptions.data, tableOptions], () => {
35
+ table.setOptions((prev) => {
36
+ return require_merge_proxy.mergeProxy(prev, IS_REACTIVE ? getOptionsWithReactiveData(tableOptions) : tableOptions);
37
+ });
38
+ }, { immediate: true });
39
+ table.Subscribe = function Subscribe(props) {
40
+ const selected = (0, _tanstack_vue_store.useStore)(table.store, props.selector);
41
+ if (typeof props.children === "function") return props.children(selected.value);
42
+ return props.children;
43
+ };
44
+ const stateStore = (0, _tanstack_vue_store.useStore)(table.store, selector);
45
+ return {
46
+ ...table,
47
+ get state() {
48
+ return stateStore.value;
49
+ }
50
+ };
51
+ }
52
+
53
+ //#endregion
54
+ exports.useTable = useTable;
55
+ //# sourceMappingURL=useTable.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useTable.cjs","names":["mergeProxy"],"sources":["../src/useTable.ts"],"sourcesContent":["import { isRef, ref, unref, watch, watchEffect } from 'vue'\nimport {\n constructReactivityFeature,\n constructTable,\n} from '@tanstack/table-core'\nimport { useStore } from '@tanstack/vue-store'\nimport { mergeProxy } from './merge-proxy'\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 TableOptionsWithReactiveData<\n TFeatures extends TableFeatures,\n TData extends RowData,\n> = Omit<TableOptions<TFeatures, TData>, 'data'> & {\n data: MaybeRef<ReadonlyArray<TData>>\n}\n\nfunction getOptionsWithReactiveData<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(options: TableOptionsWithReactiveData<TFeatures, TData>) {\n return mergeProxy(options, {\n data: unref(options.data),\n })\n}\n\nexport type VueTable<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TSelected = {},\n> = Table<TFeatures, TData> & {\n /**\n * A Vue component that allows you to subscribe to the table state.\n *\n * This is useful for opting into state subscriptions for specific parts of the table state.\n *\n * @example\n * <table.Subscribe selector={(state) => ({ rowSelection: state.rowSelection })}>\n * {(state) => (\n * <tr>\n * // render the row\n * </tr>\n * )}\n * </table.Subscribe>\n */\n Subscribe: <TSelected>(props: {\n selector: (state: NoInfer<TableState<TFeatures>>) => TSelected\n children:\n | ((state: Readonly<TSelected>) => VNode | Array<VNode>)\n | VNode\n | Array<VNode>\n }) => VNode | Array<VNode>\n /**\n * The selected state of the table. This state may not match the structure of `table.store.state` because it is selected by the `selector` function that 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\nexport function useTable<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TSelected = {},\n>(\n tableOptions: TableOptionsWithReactiveData<TFeatures, TData>,\n selector: (state: TableState<TFeatures>) => TSelected = () =>\n ({}) as TSelected,\n): VueTable<TFeatures, TData, TSelected> {\n const notifier = ref<number>(0)\n\n const vueReactivityFeature = constructReactivityFeature({\n stateNotifier: () => notifier.value,\n optionsNotifier: () => notifier.value,\n })\n\n const IS_REACTIVE = isRef(tableOptions.data)\n\n const mergedOptions = {\n ...tableOptions,\n _features: {\n ...tableOptions._features,\n vueReactivityFeature,\n },\n }\n\n const resolvedOptions = mergeProxy(\n IS_REACTIVE\n ? getOptionsWithReactiveData(\n mergedOptions as TableOptions<TFeatures, TData>,\n )\n : 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 mergeProxy(defaultOptions, newOptions)\n },\n },\n ) as TableOptions<TFeatures, TData>\n\n const table = constructTable(resolvedOptions) as VueTable<\n TFeatures,\n TData,\n TSelected\n >\n\n const allState = useStore(table.store, (state) => state)\n const allOptions = useStore(table.optionsStore, (state) => state)\n\n watchEffect(() => {\n allState.value\n allOptions.value\n notifier.value++\n })\n\n watch(\n () =>\n [\n IS_REACTIVE ? unref(tableOptions.data) : tableOptions.data,\n tableOptions,\n ] as const,\n () => {\n table.setOptions((prev) => {\n return mergeProxy(\n prev,\n IS_REACTIVE\n ? getOptionsWithReactiveData(\n tableOptions as TableOptions<TFeatures, TData>,\n )\n : tableOptions,\n ) as TableOptions<TFeatures, TData>\n })\n },\n { immediate: true },\n )\n\n table.Subscribe = function Subscribe<TSelected>(props: {\n selector: (state: TableState<TFeatures>) => TSelected\n children:\n | ((state: Readonly<TSelected>) => VNode | Array<VNode>)\n | VNode\n | Array<VNode>\n }): VNode | Array<VNode> {\n const selected = useStore(table.store, props.selector)\n if (typeof props.children === 'function') {\n return props.children(selected.value)\n }\n return props.children\n }\n\n const stateStore = useStore(table.store, selector)\n\n return {\n ...table,\n get state() {\n return stateStore.value\n },\n } as VueTable<TFeatures, TData, TSelected>\n}\n"],"mappings":";;;;;;AAwBA,SAAS,2BAGP,SAAyD;AACzD,QAAOA,+BAAW,SAAS,EACzB,qBAAY,QAAQ,KAAK,EAC1B,CAAC;;AAwCJ,SAAgB,SAKd,cACA,kBACG,EAAE,GACkC;CACvC,MAAM,wBAAuB,EAAE;CAE/B,MAAM,4EAAkD;EACtD,qBAAqB,SAAS;EAC9B,uBAAuB,SAAS;EACjC,CAAC;CAEF,MAAM,6BAAoB,aAAa,KAAK;CAE5C,MAAM,gBAAgB;EACpB,GAAG;EACH,WAAW;GACT,GAAG,aAAa;GAChB;GACD;EACF;CAmBD,MAAM,iDAjBkBA,+BACtB,cACI,2BACE,cACD,GACD,eACJ,EAEE,eACE,gBACA,eACG;AACH,SAAOA,+BAAW,gBAAgB,WAAW;IAEhD,CACF,CAE4C;CAM7C,MAAM,6CAAoB,MAAM,QAAQ,UAAU,MAAM;CACxD,MAAM,+CAAsB,MAAM,eAAe,UAAU,MAAM;AAEjE,4BAAkB;AAChB,WAAS;AACT,aAAW;AACX,WAAS;GACT;AAEF,sBAEI,CACE,6BAAoB,aAAa,KAAK,GAAG,aAAa,MACtD,aACD,QACG;AACJ,QAAM,YAAY,SAAS;AACzB,UAAOA,+BACL,MACA,cACI,2BACE,aACD,GACD,aACL;IACD;IAEJ,EAAE,WAAW,MAAM,CACpB;AAED,OAAM,YAAY,SAAS,UAAqB,OAMvB;EACvB,MAAM,6CAAoB,MAAM,OAAO,MAAM,SAAS;AACtD,MAAI,OAAO,MAAM,aAAa,WAC5B,QAAO,MAAM,SAAS,SAAS,MAAM;AAEvC,SAAO,MAAM;;CAGf,MAAM,+CAAsB,MAAM,OAAO,SAAS;AAElD,QAAO;EACL,GAAG;EACH,IAAI,QAAQ;AACV,UAAO,WAAW;;EAErB"}
@@ -0,0 +1,40 @@
1
+ import { MaybeRef, VNode } from "vue";
2
+ import { NoInfer, RowData, Table, TableFeatures, TableOptions, TableState } from "@tanstack/table-core";
3
+
4
+ //#region src/useTable.d.ts
5
+ type TableOptionsWithReactiveData<TFeatures extends TableFeatures, TData extends RowData> = Omit<TableOptions<TFeatures, TData>, 'data'> & {
6
+ data: MaybeRef<ReadonlyArray<TData>>;
7
+ };
8
+ type VueTable<TFeatures extends TableFeatures, TData extends RowData, TSelected = {}> = Table<TFeatures, TData> & {
9
+ /**
10
+ * A Vue component that allows you to subscribe to the table state.
11
+ *
12
+ * This is useful for opting into state subscriptions for specific parts of the table state.
13
+ *
14
+ * @example
15
+ * <table.Subscribe selector={(state) => ({ rowSelection: state.rowSelection })}>
16
+ * {(state) => (
17
+ * <tr>
18
+ * // render the row
19
+ * </tr>
20
+ * )}
21
+ * </table.Subscribe>
22
+ */
23
+ Subscribe: <TSelected>(props: {
24
+ selector: (state: NoInfer<TableState<TFeatures>>) => TSelected;
25
+ children: ((state: Readonly<TSelected>) => VNode | Array<VNode>) | VNode | Array<VNode>;
26
+ }) => VNode | Array<VNode>;
27
+ /**
28
+ * The selected state of the table. This state may not match the structure of `table.store.state` because it is selected by the `selector` function that you pass as the 2nd argument to `useTable`.
29
+ *
30
+ * @example
31
+ * const table = useTable(options, (state) => ({ globalFilter: state.globalFilter })) // only globalFilter is part of the selected state
32
+ *
33
+ * console.log(table.state.globalFilter)
34
+ */
35
+ readonly state: Readonly<TSelected>;
36
+ };
37
+ declare function useTable<TFeatures extends TableFeatures, TData extends RowData, TSelected = {}>(tableOptions: TableOptionsWithReactiveData<TFeatures, TData>, selector?: (state: TableState<TFeatures>) => TSelected): VueTable<TFeatures, TData, TSelected>;
38
+ //#endregion
39
+ export { TableOptionsWithReactiveData, VueTable, useTable };
40
+ //# sourceMappingURL=useTable.d.cts.map
@@ -0,0 +1,40 @@
1
+ import { MaybeRef, VNode } from "vue";
2
+ import { NoInfer, RowData, Table, TableFeatures, TableOptions, TableState } from "@tanstack/table-core";
3
+
4
+ //#region src/useTable.d.ts
5
+ type TableOptionsWithReactiveData<TFeatures extends TableFeatures, TData extends RowData> = Omit<TableOptions<TFeatures, TData>, 'data'> & {
6
+ data: MaybeRef<ReadonlyArray<TData>>;
7
+ };
8
+ type VueTable<TFeatures extends TableFeatures, TData extends RowData, TSelected = {}> = Table<TFeatures, TData> & {
9
+ /**
10
+ * A Vue component that allows you to subscribe to the table state.
11
+ *
12
+ * This is useful for opting into state subscriptions for specific parts of the table state.
13
+ *
14
+ * @example
15
+ * <table.Subscribe selector={(state) => ({ rowSelection: state.rowSelection })}>
16
+ * {(state) => (
17
+ * <tr>
18
+ * // render the row
19
+ * </tr>
20
+ * )}
21
+ * </table.Subscribe>
22
+ */
23
+ Subscribe: <TSelected>(props: {
24
+ selector: (state: NoInfer<TableState<TFeatures>>) => TSelected;
25
+ children: ((state: Readonly<TSelected>) => VNode | Array<VNode>) | VNode | Array<VNode>;
26
+ }) => VNode | Array<VNode>;
27
+ /**
28
+ * The selected state of the table. This state may not match the structure of `table.store.state` because it is selected by the `selector` function that you pass as the 2nd argument to `useTable`.
29
+ *
30
+ * @example
31
+ * const table = useTable(options, (state) => ({ globalFilter: state.globalFilter })) // only globalFilter is part of the selected state
32
+ *
33
+ * console.log(table.state.globalFilter)
34
+ */
35
+ readonly state: Readonly<TSelected>;
36
+ };
37
+ declare function useTable<TFeatures extends TableFeatures, TData extends RowData, TSelected = {}>(tableOptions: TableOptionsWithReactiveData<TFeatures, TData>, selector?: (state: TableState<TFeatures>) => TSelected): VueTable<TFeatures, TData, TSelected>;
38
+ //#endregion
39
+ export { TableOptionsWithReactiveData, VueTable, useTable };
40
+ //# sourceMappingURL=useTable.d.ts.map
@@ -0,0 +1,55 @@
1
+ import { mergeProxy } from "./merge-proxy.js";
2
+ import { isRef, ref, unref, watch, watchEffect } from "vue";
3
+ import { constructReactivityFeature, constructTable } from "@tanstack/table-core";
4
+ import { useStore } from "@tanstack/vue-store";
5
+
6
+ //#region src/useTable.ts
7
+ function getOptionsWithReactiveData(options) {
8
+ return mergeProxy(options, { data: unref(options.data) });
9
+ }
10
+ function useTable(tableOptions, selector = () => ({})) {
11
+ const notifier = ref(0);
12
+ const vueReactivityFeature = constructReactivityFeature({
13
+ stateNotifier: () => notifier.value,
14
+ optionsNotifier: () => notifier.value
15
+ });
16
+ const IS_REACTIVE = isRef(tableOptions.data);
17
+ const mergedOptions = {
18
+ ...tableOptions,
19
+ _features: {
20
+ ...tableOptions._features,
21
+ vueReactivityFeature
22
+ }
23
+ };
24
+ const table = constructTable(mergeProxy(IS_REACTIVE ? getOptionsWithReactiveData(mergedOptions) : mergedOptions, { mergeOptions: (defaultOptions, newOptions) => {
25
+ return mergeProxy(defaultOptions, newOptions);
26
+ } }));
27
+ const allState = useStore(table.store, (state) => state);
28
+ const allOptions = useStore(table.optionsStore, (state) => state);
29
+ watchEffect(() => {
30
+ allState.value;
31
+ allOptions.value;
32
+ notifier.value++;
33
+ });
34
+ watch(() => [IS_REACTIVE ? unref(tableOptions.data) : tableOptions.data, tableOptions], () => {
35
+ table.setOptions((prev) => {
36
+ return mergeProxy(prev, IS_REACTIVE ? getOptionsWithReactiveData(tableOptions) : tableOptions);
37
+ });
38
+ }, { immediate: true });
39
+ table.Subscribe = function Subscribe(props) {
40
+ const selected = useStore(table.store, props.selector);
41
+ if (typeof props.children === "function") return props.children(selected.value);
42
+ return props.children;
43
+ };
44
+ const stateStore = useStore(table.store, selector);
45
+ return {
46
+ ...table,
47
+ get state() {
48
+ return stateStore.value;
49
+ }
50
+ };
51
+ }
52
+
53
+ //#endregion
54
+ export { useTable };
55
+ //# sourceMappingURL=useTable.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useTable.js","names":[],"sources":["../src/useTable.ts"],"sourcesContent":["import { isRef, ref, unref, watch, watchEffect } from 'vue'\nimport {\n constructReactivityFeature,\n constructTable,\n} from '@tanstack/table-core'\nimport { useStore } from '@tanstack/vue-store'\nimport { mergeProxy } from './merge-proxy'\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 TableOptionsWithReactiveData<\n TFeatures extends TableFeatures,\n TData extends RowData,\n> = Omit<TableOptions<TFeatures, TData>, 'data'> & {\n data: MaybeRef<ReadonlyArray<TData>>\n}\n\nfunction getOptionsWithReactiveData<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(options: TableOptionsWithReactiveData<TFeatures, TData>) {\n return mergeProxy(options, {\n data: unref(options.data),\n })\n}\n\nexport type VueTable<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TSelected = {},\n> = Table<TFeatures, TData> & {\n /**\n * A Vue component that allows you to subscribe to the table state.\n *\n * This is useful for opting into state subscriptions for specific parts of the table state.\n *\n * @example\n * <table.Subscribe selector={(state) => ({ rowSelection: state.rowSelection })}>\n * {(state) => (\n * <tr>\n * // render the row\n * </tr>\n * )}\n * </table.Subscribe>\n */\n Subscribe: <TSelected>(props: {\n selector: (state: NoInfer<TableState<TFeatures>>) => TSelected\n children:\n | ((state: Readonly<TSelected>) => VNode | Array<VNode>)\n | VNode\n | Array<VNode>\n }) => VNode | Array<VNode>\n /**\n * The selected state of the table. This state may not match the structure of `table.store.state` because it is selected by the `selector` function that 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\nexport function useTable<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TSelected = {},\n>(\n tableOptions: TableOptionsWithReactiveData<TFeatures, TData>,\n selector: (state: TableState<TFeatures>) => TSelected = () =>\n ({}) as TSelected,\n): VueTable<TFeatures, TData, TSelected> {\n const notifier = ref<number>(0)\n\n const vueReactivityFeature = constructReactivityFeature({\n stateNotifier: () => notifier.value,\n optionsNotifier: () => notifier.value,\n })\n\n const IS_REACTIVE = isRef(tableOptions.data)\n\n const mergedOptions = {\n ...tableOptions,\n _features: {\n ...tableOptions._features,\n vueReactivityFeature,\n },\n }\n\n const resolvedOptions = mergeProxy(\n IS_REACTIVE\n ? getOptionsWithReactiveData(\n mergedOptions as TableOptions<TFeatures, TData>,\n )\n : 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 mergeProxy(defaultOptions, newOptions)\n },\n },\n ) as TableOptions<TFeatures, TData>\n\n const table = constructTable(resolvedOptions) as VueTable<\n TFeatures,\n TData,\n TSelected\n >\n\n const allState = useStore(table.store, (state) => state)\n const allOptions = useStore(table.optionsStore, (state) => state)\n\n watchEffect(() => {\n allState.value\n allOptions.value\n notifier.value++\n })\n\n watch(\n () =>\n [\n IS_REACTIVE ? unref(tableOptions.data) : tableOptions.data,\n tableOptions,\n ] as const,\n () => {\n table.setOptions((prev) => {\n return mergeProxy(\n prev,\n IS_REACTIVE\n ? getOptionsWithReactiveData(\n tableOptions as TableOptions<TFeatures, TData>,\n )\n : tableOptions,\n ) as TableOptions<TFeatures, TData>\n })\n },\n { immediate: true },\n )\n\n table.Subscribe = function Subscribe<TSelected>(props: {\n selector: (state: TableState<TFeatures>) => TSelected\n children:\n | ((state: Readonly<TSelected>) => VNode | Array<VNode>)\n | VNode\n | Array<VNode>\n }): VNode | Array<VNode> {\n const selected = useStore(table.store, props.selector)\n if (typeof props.children === 'function') {\n return props.children(selected.value)\n }\n return props.children\n }\n\n const stateStore = useStore(table.store, selector)\n\n return {\n ...table,\n get state() {\n return stateStore.value\n },\n } as VueTable<TFeatures, TData, TSelected>\n}\n"],"mappings":";;;;;;AAwBA,SAAS,2BAGP,SAAyD;AACzD,QAAO,WAAW,SAAS,EACzB,MAAM,MAAM,QAAQ,KAAK,EAC1B,CAAC;;AAwCJ,SAAgB,SAKd,cACA,kBACG,EAAE,GACkC;CACvC,MAAM,WAAW,IAAY,EAAE;CAE/B,MAAM,uBAAuB,2BAA2B;EACtD,qBAAqB,SAAS;EAC9B,uBAAuB,SAAS;EACjC,CAAC;CAEF,MAAM,cAAc,MAAM,aAAa,KAAK;CAE5C,MAAM,gBAAgB;EACpB,GAAG;EACH,WAAW;GACT,GAAG,aAAa;GAChB;GACD;EACF;CAmBD,MAAM,QAAQ,eAjBU,WACtB,cACI,2BACE,cACD,GACD,eACJ,EAEE,eACE,gBACA,eACG;AACH,SAAO,WAAW,gBAAgB,WAAW;IAEhD,CACF,CAE4C;CAM7C,MAAM,WAAW,SAAS,MAAM,QAAQ,UAAU,MAAM;CACxD,MAAM,aAAa,SAAS,MAAM,eAAe,UAAU,MAAM;AAEjE,mBAAkB;AAChB,WAAS;AACT,aAAW;AACX,WAAS;GACT;AAEF,aAEI,CACE,cAAc,MAAM,aAAa,KAAK,GAAG,aAAa,MACtD,aACD,QACG;AACJ,QAAM,YAAY,SAAS;AACzB,UAAO,WACL,MACA,cACI,2BACE,aACD,GACD,aACL;IACD;IAEJ,EAAE,WAAW,MAAM,CACpB;AAED,OAAM,YAAY,SAAS,UAAqB,OAMvB;EACvB,MAAM,WAAW,SAAS,MAAM,OAAO,MAAM,SAAS;AACtD,MAAI,OAAO,MAAM,aAAa,WAC5B,QAAO,MAAM,SAAS,SAAS,MAAM;AAEvC,SAAO,MAAM;;CAGf,MAAM,aAAa,SAAS,MAAM,OAAO,SAAS;AAElD,QAAO;EACL,GAAG;EACH,IAAI,QAAQ;AACV,UAAO,WAAW;;EAErB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/vue-table",
3
- "version": "9.0.0-alpha.10",
3
+ "version": "9.0.0-alpha.26",
4
4
  "description": "Headless UI for building powerful tables & datagrids for Vue.",
5
5
  "author": "Tanner Linsley",
6
6
  "license": "MIT",
@@ -21,39 +21,41 @@
21
21
  "datagrid"
22
22
  ],
23
23
  "type": "module",
24
- "types": "dist/esm/index.d.ts",
25
- "main": "dist/cjs/index.cjs",
26
- "module": "dist/esm/index.js",
24
+ "types": "./dist/index.d.cts",
25
+ "main": "./dist/index.cjs",
26
+ "module": "./dist/index.js",
27
27
  "exports": {
28
28
  ".": {
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
- }
29
+ "import": "./dist/index.js",
30
+ "require": "./dist/index.cjs"
37
31
  },
38
32
  "./package.json": "./package.json"
39
33
  },
40
34
  "sideEffects": false,
41
35
  "engines": {
42
- "node": ">=12"
36
+ "node": ">=16"
43
37
  },
44
38
  "files": [
45
39
  "dist",
46
40
  "src"
47
41
  ],
48
42
  "dependencies": {
49
- "@tanstack/table-core": "9.0.0-alpha.10"
43
+ "@tanstack/vue-store": "^0.9.3",
44
+ "@tanstack/table-core": "9.0.0-alpha.23"
50
45
  },
51
46
  "devDependencies": {
52
- "@vitejs/plugin-vue": "^5.0.5",
53
- "vue": "^3.4.31"
47
+ "@vitejs/plugin-vue": "^6.0.5",
48
+ "eslint-plugin-vue": "^10.8.0",
49
+ "vue": "^3.5.32"
54
50
  },
55
51
  "peerDependencies": {
56
52
  "vue": ">=3.2"
57
53
  },
58
- "scripts": {}
54
+ "scripts": {
55
+ "clean": "rimraf ./build && rimraf ./dist",
56
+ "test:eslint": "eslint ./src",
57
+ "test:types": "tsc",
58
+ "test:build": "publint --strict",
59
+ "build": "tsdown"
60
+ }
59
61
  }
@@ -0,0 +1,109 @@
1
+ import { defineComponent, h, isVNode } from 'vue'
2
+ import type { PropType } from 'vue'
3
+ import type {
4
+ Cell,
5
+ CellData,
6
+ Header,
7
+ RowData,
8
+ TableFeatures,
9
+ } from '@tanstack/table-core'
10
+
11
+ /**
12
+ * If rendering headers, cells, or footers with custom markup, use flexRender instead of `cell.getValue()` or `cell.renderValue()`.
13
+ * @example flexRender(cell.column.columnDef.cell, cell.getContext())
14
+ */
15
+ export function flexRender(render: any, props: any): any {
16
+ if (typeof render === 'function') {
17
+ const rendered = render(props)
18
+
19
+ if (isVNode(rendered)) {
20
+ return rendered
21
+ }
22
+
23
+ if (typeof rendered === 'function' || typeof rendered === 'object') {
24
+ return h(rendered, props)
25
+ }
26
+
27
+ return rendered
28
+ }
29
+
30
+ if (typeof render === 'object') {
31
+ return h(render, props)
32
+ }
33
+
34
+ return render
35
+ }
36
+
37
+ /**
38
+ * Simplified component for rendering headers, cells, or footers.
39
+ *
40
+ * Supports both the new shorthand pattern and the legacy `:render`/`:props` pattern:
41
+ * @example
42
+ * ```vue
43
+ * <!-- New shorthand pattern -->
44
+ * <FlexRender :cell="cell" />
45
+ * <FlexRender :header="header" />
46
+ * <FlexRender :footer="header" />
47
+ *
48
+ * <!-- Legacy pattern (still supported) -->
49
+ * <FlexRender :render="cell.column.columnDef.cell" :props="cell.getContext()" />
50
+ * ```
51
+ */
52
+ export const FlexRender = defineComponent({
53
+ props: {
54
+ render: {
55
+ type: [Function, Object, String] as PropType<any>,
56
+ default: undefined,
57
+ },
58
+ props: {
59
+ type: Object as PropType<any>,
60
+ default: undefined,
61
+ },
62
+ cell: {
63
+ type: Object as PropType<Cell<any, any, any>>,
64
+ default: undefined,
65
+ },
66
+ header: {
67
+ type: Object as PropType<Header<any, any, any>>,
68
+ default: undefined,
69
+ },
70
+ footer: {
71
+ type: Object as PropType<Header<any, any, any>>,
72
+ default: undefined,
73
+ },
74
+ },
75
+ setup: (props: {
76
+ render?: any
77
+ props?: any
78
+ cell?: Cell<any, any, any>
79
+ header?: Header<any, any, any>
80
+ footer?: Header<any, any, any>
81
+ }) => {
82
+ return () => {
83
+ // New shorthand pattern: extract render and props from cell/header/footer
84
+ if (props.cell) {
85
+ return flexRender(
86
+ props.cell.column.columnDef.cell,
87
+ props.cell.getContext(),
88
+ )
89
+ }
90
+
91
+ if (props.header) {
92
+ return flexRender(
93
+ props.header.column.columnDef.header,
94
+ props.header.getContext(),
95
+ )
96
+ }
97
+
98
+ if (props.footer) {
99
+ return flexRender(
100
+ props.footer.column.columnDef.footer,
101
+ props.footer.getContext(),
102
+ )
103
+ }
104
+
105
+ // Legacy pattern: use render and props directly
106
+ return flexRender(props.render, props.props)
107
+ }
108
+ },
109
+ })