@tanstack/vue-table 9.0.0-alpha.4 → 9.0.0-alpha.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/README.md +117 -0
- package/dist/FlexRender.cjs +80 -0
- package/dist/FlexRender.cjs.map +1 -0
- package/dist/FlexRender.d.cts +46 -0
- package/dist/FlexRender.d.ts +46 -0
- package/dist/FlexRender.js +79 -0
- package/dist/FlexRender.js.map +1 -0
- package/dist/createTableHook.cjs +216 -0
- package/dist/createTableHook.cjs.map +1 -0
- package/dist/createTableHook.d.cts +121 -0
- package/dist/createTableHook.d.ts +121 -0
- package/dist/createTableHook.js +215 -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 +17 -0
- package/dist/index.d.cts +5 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +7 -0
- package/dist/merge-proxy.cjs +64 -0
- package/dist/merge-proxy.cjs.map +1 -0
- package/dist/merge-proxy.js +63 -0
- package/dist/merge-proxy.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/useTable.cjs +73 -0
- package/dist/useTable.cjs.map +1 -0
- package/dist/useTable.d.cts +42 -0
- package/dist/useTable.d.ts +42 -0
- package/dist/useTable.js +73 -0
- package/dist/useTable.js.map +1 -0
- package/package.json +27 -17
- package/src/FlexRender.ts +123 -0
- package/src/createTableHook.ts +576 -0
- package/src/flex-render.ts +1 -0
- package/src/index.ts +3 -76
- package/src/merge-proxy.ts +31 -14
- package/src/static-functions.ts +1 -0
- package/src/useTable.ts +240 -0
- package/dist/cjs/index.cjs +0 -69
- package/dist/cjs/index.cjs.map +0 -1
- package/dist/cjs/index.d.cts +0 -14
- package/dist/cjs/merge-proxy.cjs +0 -64
- package/dist/cjs/merge-proxy.cjs.map +0 -1
- package/dist/cjs/merge-proxy.d.cts +0 -11
- package/dist/esm/index.d.ts +0 -14
- package/dist/esm/index.js +0 -63
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/merge-proxy.d.ts +0 -11
- package/dist/esm/merge-proxy.js +0 -64
- package/dist/esm/merge-proxy.js.map +0 -1
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
//#region src/merge-proxy.ts
|
|
2
|
+
function trueFn() {
|
|
3
|
+
return true;
|
|
4
|
+
}
|
|
5
|
+
const $PROXY = Symbol("merge-proxy");
|
|
6
|
+
const $SOURCES = Symbol("merge-proxy-sources");
|
|
7
|
+
const propTraps = {
|
|
8
|
+
get(_, property, receiver) {
|
|
9
|
+
if (property === $PROXY) return receiver;
|
|
10
|
+
if (property === $SOURCES) return _.sources;
|
|
11
|
+
return _.get(property);
|
|
12
|
+
},
|
|
13
|
+
has(_, property) {
|
|
14
|
+
return _.has(property);
|
|
15
|
+
},
|
|
16
|
+
set: trueFn,
|
|
17
|
+
deleteProperty: trueFn,
|
|
18
|
+
getOwnPropertyDescriptor(_, property) {
|
|
19
|
+
return {
|
|
20
|
+
configurable: true,
|
|
21
|
+
enumerable: true,
|
|
22
|
+
get() {
|
|
23
|
+
return _.get(property);
|
|
24
|
+
},
|
|
25
|
+
set: trueFn,
|
|
26
|
+
deleteProperty: trueFn
|
|
27
|
+
};
|
|
28
|
+
},
|
|
29
|
+
ownKeys(_) {
|
|
30
|
+
return _.keys();
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
function resolveSource(s) {
|
|
34
|
+
return "value" in s ? s.value : s;
|
|
35
|
+
}
|
|
36
|
+
function mergeProxy(...sources) {
|
|
37
|
+
const flattenedSources = sources.flatMap((source) => {
|
|
38
|
+
if (typeof source === "object" && source !== null && $SOURCES in source && Array.isArray(source[$SOURCES])) return source[$SOURCES];
|
|
39
|
+
return [source];
|
|
40
|
+
});
|
|
41
|
+
return new Proxy({
|
|
42
|
+
sources: flattenedSources,
|
|
43
|
+
get(property) {
|
|
44
|
+
for (let i = flattenedSources.length - 1; i >= 0; i--) {
|
|
45
|
+
const v = resolveSource(flattenedSources[i])[property];
|
|
46
|
+
if (v !== void 0) return v;
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
has(property) {
|
|
50
|
+
for (let i = flattenedSources.length - 1; i >= 0; i--) if (property in resolveSource(flattenedSources[i])) return true;
|
|
51
|
+
return false;
|
|
52
|
+
},
|
|
53
|
+
keys() {
|
|
54
|
+
const keys = [];
|
|
55
|
+
for (const source of flattenedSources) keys.push(...Object.keys(resolveSource(source)));
|
|
56
|
+
return [...Array.from(new Set(keys))];
|
|
57
|
+
}
|
|
58
|
+
}, propTraps);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
//#endregion
|
|
62
|
+
export { mergeProxy };
|
|
63
|
+
//# 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')\nconst $SOURCES = Symbol('merge-proxy-sources')\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 sources: Array<any>\n}> = {\n get(_, property, receiver) {\n if (property === $PROXY) return receiver\n if (property === $SOURCES) return _.sources\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 const flattenedSources = sources.flatMap((source: any) => {\n if (\n typeof source === 'object' &&\n source !== null &&\n $SOURCES in source &&\n Array.isArray(source[$SOURCES])\n ) {\n return source[$SOURCES]\n }\n\n return [source]\n })\n\n return new Proxy(\n {\n sources: flattenedSources,\n get(property: string | number | symbol) {\n for (let i = flattenedSources.length - 1; i >= 0; i--) {\n const v = resolveSource(flattenedSources[i])[property]\n if (v !== undefined) return v\n }\n },\n has(property: string | number | symbol) {\n for (let i = flattenedSources.length - 1; i >= 0; i--) {\n if (property in resolveSource(flattenedSources[i])) return true\n }\n return false\n },\n keys() {\n const keys = []\n for (const source of flattenedSources)\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;AACpC,MAAM,WAAW,OAAO,sBAAsB;AAG9C,MAAM,YAKD;CACH,IAAI,GAAG,UAAU,UAAU;AACzB,MAAI,aAAa,OAAQ,QAAO;AAChC,MAAI,aAAa,SAAU,QAAO,EAAE;AACpC,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;CAC/C,MAAM,mBAAmB,QAAQ,SAAS,WAAgB;AACxD,MACE,OAAO,WAAW,YAClB,WAAW,QACX,YAAY,UACZ,MAAM,QAAQ,OAAO,UAAU,CAE/B,QAAO,OAAO;AAGhB,SAAO,CAAC,OAAO;GACf;AAEF,QAAO,IAAI,MACT;EACE,SAAS;EACT,IAAI,UAAoC;AACtC,QAAK,IAAI,IAAI,iBAAiB,SAAS,GAAG,KAAK,GAAG,KAAK;IACrD,MAAM,IAAI,cAAc,iBAAiB,GAAG,CAAC;AAC7C,QAAI,MAAM,OAAW,QAAO;;;EAGhC,IAAI,UAAoC;AACtC,QAAK,IAAI,IAAI,iBAAiB,SAAS,GAAG,KAAK,GAAG,IAChD,KAAI,YAAY,cAAc,iBAAiB,GAAG,CAAE,QAAO;AAE7D,UAAO;;EAET,OAAO;GACL,MAAM,OAAO,EAAE;AACf,QAAK,MAAM,UAAU,iBACnB,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,9 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
var _tanstack_table_core_static_functions = require("@tanstack/table-core/static-functions");
|
|
4
|
+
Object.keys(_tanstack_table_core_static_functions).forEach(function (k) {
|
|
5
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function () { return _tanstack_table_core_static_functions[k]; }
|
|
8
|
+
});
|
|
9
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "@tanstack/table-core/static-functions";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "@tanstack/table-core/static-functions";
|
|
@@ -0,0 +1,73 @@
|
|
|
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 getOptionsWithReactiveValues(options) {
|
|
8
|
+
const resolvedOptions = {};
|
|
9
|
+
for (const key of Object.keys(options)) resolvedOptions[key] = (0, vue.unref)(options[key]);
|
|
10
|
+
return require_merge_proxy.mergeProxy(options, resolvedOptions);
|
|
11
|
+
}
|
|
12
|
+
function getReactiveOptionDeps(options) {
|
|
13
|
+
return Object.keys(options).map((key) => (0, vue.unref)(options[key]));
|
|
14
|
+
}
|
|
15
|
+
function useTable(tableOptions, selector = () => ({})) {
|
|
16
|
+
const notifier = (0, vue.ref)(0);
|
|
17
|
+
const syncTableOptions = (table, options) => {
|
|
18
|
+
table.setOptions(() => getOptionsWithReactiveValues(options));
|
|
19
|
+
};
|
|
20
|
+
const vueReactivityFeature = (0, _tanstack_table_core.constructReactivityFeature)({
|
|
21
|
+
stateNotifier: () => notifier.value,
|
|
22
|
+
optionsNotifier: () => notifier.value
|
|
23
|
+
});
|
|
24
|
+
const mergedOptions = {
|
|
25
|
+
...tableOptions,
|
|
26
|
+
_features: {
|
|
27
|
+
...tableOptions._features,
|
|
28
|
+
vueReactivityFeature
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
const table = (0, _tanstack_table_core.constructTable)(require_merge_proxy.mergeProxy(getOptionsWithReactiveValues(mergedOptions), { mergeOptions: (defaultOptions, newOptions) => {
|
|
32
|
+
return require_merge_proxy.mergeProxy(defaultOptions, newOptions);
|
|
33
|
+
} }));
|
|
34
|
+
const allState = (0, _tanstack_vue_store.useSelector)(table.store, (state) => state);
|
|
35
|
+
const allOptions = (0, _tanstack_vue_store.useSelector)(table.optionsStore, (state) => state);
|
|
36
|
+
(0, vue.watchEffect)(() => {
|
|
37
|
+
allState.value;
|
|
38
|
+
allOptions.value;
|
|
39
|
+
notifier.value++;
|
|
40
|
+
});
|
|
41
|
+
(0, vue.watch)(() => getReactiveOptionDeps(mergedOptions), () => {
|
|
42
|
+
syncTableOptions(table, mergedOptions);
|
|
43
|
+
}, { immediate: true });
|
|
44
|
+
(0, vue.watch)(() => {
|
|
45
|
+
const controlledState = (0, vue.unref)(tableOptions.state);
|
|
46
|
+
const controlledAtoms = (0, vue.unref)(tableOptions.atoms);
|
|
47
|
+
if (!controlledState) return [];
|
|
48
|
+
const controlledValues = [];
|
|
49
|
+
for (const key of Object.keys(table.initialState)) {
|
|
50
|
+
if (!(key in controlledState) || (controlledAtoms === null || controlledAtoms === void 0 ? void 0 : controlledAtoms[key]) !== void 0) continue;
|
|
51
|
+
controlledValues.push(controlledState[key]);
|
|
52
|
+
}
|
|
53
|
+
return controlledValues;
|
|
54
|
+
}, (controlledValues) => {
|
|
55
|
+
if (controlledValues.length > 0) syncTableOptions(table, mergedOptions);
|
|
56
|
+
}, { immediate: true });
|
|
57
|
+
table.Subscribe = ((props) => {
|
|
58
|
+
const selected = (0, _tanstack_vue_store.useSelector)(props.source !== void 0 ? props.source : table.store, props.source !== void 0 ? props.selector ?? ((x) => x) : props.selector, { compare: _tanstack_vue_store.shallow });
|
|
59
|
+
if (typeof props.children === "function") return props.children(selected.value);
|
|
60
|
+
return props.children;
|
|
61
|
+
});
|
|
62
|
+
const stateStore = (0, _tanstack_vue_store.useSelector)(table.store, selector);
|
|
63
|
+
return {
|
|
64
|
+
...table,
|
|
65
|
+
get state() {
|
|
66
|
+
return stateStore.value;
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
//#endregion
|
|
72
|
+
exports.useTable = useTable;
|
|
73
|
+
//# sourceMappingURL=useTable.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useTable.cjs","names":["mergeProxy","shallow"],"sources":["../src/useTable.ts"],"sourcesContent":["import { isRef, ref, unref, watch, watchEffect } from 'vue'\nimport {\n constructReactivityFeature,\n constructTable,\n} from '@tanstack/table-core'\nimport { shallow, useSelector } from '@tanstack/vue-store'\nimport { mergeProxy } from './merge-proxy'\nimport type { Atom, ReadonlyAtom } 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 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 = {},\n> = Table<TFeatures, TData> & {\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: Atom<TSourceValue> | ReadonlyAtom<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: Atom<TSourceValue> | ReadonlyAtom<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 `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:\n | TableOptions<TFeatures, TData>\n | 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 syncTableOptions = (\n table: Table<TFeatures, TData>,\n options: TableOptionsWithReactiveData<TFeatures, TData>,\n ) => {\n table.setOptions(\n () =>\n getOptionsWithReactiveValues(options) as TableOptions<TFeatures, TData>,\n )\n }\n\n const vueReactivityFeature = constructReactivityFeature({\n stateNotifier: () => notifier.value,\n optionsNotifier: () => notifier.value,\n })\n\n const mergedOptions = {\n ...tableOptions,\n _features: {\n ...tableOptions._features,\n vueReactivityFeature,\n },\n }\n\n const resolvedOptions = mergeProxy(\n getOptionsWithReactiveValues(\n mergedOptions as TableOptionsWithReactiveData<TFeatures, TData>,\n ),\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 = useSelector(table.store, (state) => state)\n const allOptions = useSelector(table.optionsStore, (state) => state)\n\n watchEffect(() => {\n allState.value\n allOptions.value\n notifier.value++\n })\n\n watch(\n () =>\n getReactiveOptionDeps(\n mergedOptions as TableOptionsWithReactiveData<TFeatures, TData>,\n ),\n () => {\n syncTableOptions(table, 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(table, mergedOptions)\n }\n },\n { immediate: true },\n )\n\n table.Subscribe = ((props: {\n source?: Atom<unknown> | ReadonlyAtom<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 !== undefined ? props.source : table.store\n const selectFn =\n props.source !== undefined\n ? (props.selector ?? ((x: unknown) => x))\n : props.selector\n const selected = useSelector(source as never, selectFn 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":";;;;;;AA2BA,SAAS,6BAGP,SAAyD;CACzD,MAAM,kBAA2C,EAAE;AAEnD,MAAK,MAAM,OAAO,OAAO,KAAK,QAAQ,CACpC,iBAAgB,sBACd,QAAQ,KACT;AAGH,QAAOA,+BAAW,SAAS,gBAAgB;;AAG7C,SAAS,sBAGP,SAAyD;AACzD,QAAO,OAAO,KAAK,QAAQ,CAAC,KAAK,uBACzB,QAAQ,KAA6D,CAC5E;;AAiDH,SAAgB,SAKd,cAGA,kBACG,EAAE,GACkC;CACvC,MAAM,wBAAuB,EAAE;CAE/B,MAAM,oBACJ,OACA,YACG;AACH,QAAM,iBAEF,6BAA6B,QAAQ,CACxC;;CAGH,MAAM,4EAAkD;EACtD,qBAAqB,SAAS;EAC9B,uBAAuB,SAAS;EACjC,CAAC;CAEF,MAAM,gBAAgB;EACpB,GAAG;EACH,WAAW;GACT,GAAG,aAAa;GAChB;GACD;EACF;CAiBD,MAAM,iDAfkBA,+BACtB,6BACE,cACD,EACD,EAEE,eACE,gBACA,eACG;AACH,SAAOA,+BAAW,gBAAgB,WAAW;IAEhD,CAGyC,CAAC;CAM7C,MAAM,gDAAuB,MAAM,QAAQ,UAAU,MAAM;CAC3D,MAAM,kDAAyB,MAAM,eAAe,UAAU,MAAM;AAEpE,4BAAkB;AAChB,WAAS;AACT,aAAW;AACX,WAAS;GACT;AAEF,sBAEI,sBACE,cACD,QACG;AACJ,mBAAiB,OAAO,cAAc;IAExC,EAAE,WAAW,MAAM,CACpB;AAED,sBACQ;EACJ,MAAM,iCAAwB,aAAa,MAAM;EAGjD,MAAM,iCAAwB,aAAa,MAAM;AAIjD,MAAI,CAAC,gBACH,QAAO,EAAE;EAGX,MAAM,mBAAmC,EAAE;AAE3C,OAAK,MAAM,OAAO,OAAO,KAAK,MAAM,aAAa,EAAE;AACjD,OAAI,EAAE,OAAO,uFAAoB,gBAAkB,UAAS,OAC1D;AAKF,oBAAiB,KAAK,gBAAgB,KAAK;;AAG7C,SAAO;KAER,qBAAqB;AACpB,MAAI,iBAAiB,SAAS,EAC5B,kBAAiB,OAAO,cAAc;IAG1C,EAAE,WAAW,MAAM,CACpB;AAED,OAAM,cAAc,UAOd;EAMJ,MAAM,gDALS,MAAM,WAAW,SAAY,MAAM,SAAS,MAAM,OAE/D,MAAM,WAAW,SACZ,MAAM,cAAc,MAAe,KACpC,MAAM,UACqD,EAC/D,SAASC,6BACV,CAAC;AACF,MAAI,OAAO,MAAM,aAAa,WAC5B,QAAO,MAAM,SAAS,SAAS,MAA2B;AAE5D,SAAO,MAAM;;CAGf,MAAM,kDAAyB,MAAM,OAAO,SAAS;AAErD,QAAO;EACL,GAAG;EACH,IAAI,QAAQ;AACV,UAAO,WAAW;;EAErB"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { MaybeRef, VNode } from "vue";
|
|
2
|
+
import { NoInfer, RowData, Table, TableFeatures, TableOptions, TableState } from "@tanstack/table-core";
|
|
3
|
+
import { Atom, ReadonlyAtom } from "@tanstack/vue-store";
|
|
4
|
+
|
|
5
|
+
//#region src/useTable.d.ts
|
|
6
|
+
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]> };
|
|
7
|
+
type VueTable<TFeatures extends TableFeatures, TData extends RowData, TSelected = {}> = Table<TFeatures, TData> & {
|
|
8
|
+
/**
|
|
9
|
+
* Store mode: `selector` required. Source mode: pass `source` (atom or store); omit
|
|
10
|
+
* `selector` for the whole value (identity), or pass `selector` to project. Split
|
|
11
|
+
* overloads so source-only infers `TSourceValue` for `children` (see React `Subscribe`).
|
|
12
|
+
*/
|
|
13
|
+
Subscribe: {
|
|
14
|
+
<TSourceValue>(props: {
|
|
15
|
+
source: Atom<TSourceValue> | ReadonlyAtom<TSourceValue>;
|
|
16
|
+
selector?: undefined;
|
|
17
|
+
children: ((state: Readonly<TSourceValue>) => VNode | Array<VNode>) | VNode | Array<VNode>;
|
|
18
|
+
}): VNode | Array<VNode>;
|
|
19
|
+
<TSourceValue, TSubSelected>(props: {
|
|
20
|
+
source: Atom<TSourceValue> | ReadonlyAtom<TSourceValue>;
|
|
21
|
+
selector: (state: TSourceValue) => TSubSelected;
|
|
22
|
+
children: ((state: Readonly<TSubSelected>) => VNode | Array<VNode>) | VNode | Array<VNode>;
|
|
23
|
+
}): VNode | Array<VNode>;
|
|
24
|
+
<TSubSelected>(props: {
|
|
25
|
+
selector: (state: NoInfer<TableState<TFeatures>>) => TSubSelected;
|
|
26
|
+
children: ((state: Readonly<TSubSelected>) => VNode | Array<VNode>) | VNode | Array<VNode>;
|
|
27
|
+
}): VNode | Array<VNode>;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* 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`.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* const table = useTable(options, (state) => ({ globalFilter: state.globalFilter })) // only globalFilter is part of the selected state
|
|
34
|
+
*
|
|
35
|
+
* console.log(table.state.globalFilter)
|
|
36
|
+
*/
|
|
37
|
+
readonly state: Readonly<TSelected>;
|
|
38
|
+
};
|
|
39
|
+
declare function useTable<TFeatures extends TableFeatures, TData extends RowData, TSelected = {}>(tableOptions: TableOptions<TFeatures, TData> | TableOptionsWithReactiveData<TFeatures, TData>, selector?: (state: TableState<TFeatures>) => TSelected): VueTable<TFeatures, TData, TSelected>;
|
|
40
|
+
//#endregion
|
|
41
|
+
export { TableOptionsWithReactiveData, VueTable, useTable };
|
|
42
|
+
//# sourceMappingURL=useTable.d.cts.map
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { MaybeRef, VNode } from "vue";
|
|
2
|
+
import { NoInfer, RowData, Table, TableFeatures, TableOptions, TableState } from "@tanstack/table-core";
|
|
3
|
+
import { Atom, ReadonlyAtom } from "@tanstack/vue-store";
|
|
4
|
+
|
|
5
|
+
//#region src/useTable.d.ts
|
|
6
|
+
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]> };
|
|
7
|
+
type VueTable<TFeatures extends TableFeatures, TData extends RowData, TSelected = {}> = Table<TFeatures, TData> & {
|
|
8
|
+
/**
|
|
9
|
+
* Store mode: `selector` required. Source mode: pass `source` (atom or store); omit
|
|
10
|
+
* `selector` for the whole value (identity), or pass `selector` to project. Split
|
|
11
|
+
* overloads so source-only infers `TSourceValue` for `children` (see React `Subscribe`).
|
|
12
|
+
*/
|
|
13
|
+
Subscribe: {
|
|
14
|
+
<TSourceValue>(props: {
|
|
15
|
+
source: Atom<TSourceValue> | ReadonlyAtom<TSourceValue>;
|
|
16
|
+
selector?: undefined;
|
|
17
|
+
children: ((state: Readonly<TSourceValue>) => VNode | Array<VNode>) | VNode | Array<VNode>;
|
|
18
|
+
}): VNode | Array<VNode>;
|
|
19
|
+
<TSourceValue, TSubSelected>(props: {
|
|
20
|
+
source: Atom<TSourceValue> | ReadonlyAtom<TSourceValue>;
|
|
21
|
+
selector: (state: TSourceValue) => TSubSelected;
|
|
22
|
+
children: ((state: Readonly<TSubSelected>) => VNode | Array<VNode>) | VNode | Array<VNode>;
|
|
23
|
+
}): VNode | Array<VNode>;
|
|
24
|
+
<TSubSelected>(props: {
|
|
25
|
+
selector: (state: NoInfer<TableState<TFeatures>>) => TSubSelected;
|
|
26
|
+
children: ((state: Readonly<TSubSelected>) => VNode | Array<VNode>) | VNode | Array<VNode>;
|
|
27
|
+
}): VNode | Array<VNode>;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* 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`.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* const table = useTable(options, (state) => ({ globalFilter: state.globalFilter })) // only globalFilter is part of the selected state
|
|
34
|
+
*
|
|
35
|
+
* console.log(table.state.globalFilter)
|
|
36
|
+
*/
|
|
37
|
+
readonly state: Readonly<TSelected>;
|
|
38
|
+
};
|
|
39
|
+
declare function useTable<TFeatures extends TableFeatures, TData extends RowData, TSelected = {}>(tableOptions: TableOptions<TFeatures, TData> | TableOptionsWithReactiveData<TFeatures, TData>, selector?: (state: TableState<TFeatures>) => TSelected): VueTable<TFeatures, TData, TSelected>;
|
|
40
|
+
//#endregion
|
|
41
|
+
export { TableOptionsWithReactiveData, VueTable, useTable };
|
|
42
|
+
//# sourceMappingURL=useTable.d.ts.map
|
package/dist/useTable.js
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { mergeProxy } from "./merge-proxy.js";
|
|
2
|
+
import { ref, unref, watch, watchEffect } from "vue";
|
|
3
|
+
import { constructReactivityFeature, constructTable } from "@tanstack/table-core";
|
|
4
|
+
import { shallow, useSelector } from "@tanstack/vue-store";
|
|
5
|
+
|
|
6
|
+
//#region src/useTable.ts
|
|
7
|
+
function getOptionsWithReactiveValues(options) {
|
|
8
|
+
const resolvedOptions = {};
|
|
9
|
+
for (const key of Object.keys(options)) resolvedOptions[key] = unref(options[key]);
|
|
10
|
+
return mergeProxy(options, resolvedOptions);
|
|
11
|
+
}
|
|
12
|
+
function getReactiveOptionDeps(options) {
|
|
13
|
+
return Object.keys(options).map((key) => unref(options[key]));
|
|
14
|
+
}
|
|
15
|
+
function useTable(tableOptions, selector = () => ({})) {
|
|
16
|
+
const notifier = ref(0);
|
|
17
|
+
const syncTableOptions = (table, options) => {
|
|
18
|
+
table.setOptions(() => getOptionsWithReactiveValues(options));
|
|
19
|
+
};
|
|
20
|
+
const vueReactivityFeature = constructReactivityFeature({
|
|
21
|
+
stateNotifier: () => notifier.value,
|
|
22
|
+
optionsNotifier: () => notifier.value
|
|
23
|
+
});
|
|
24
|
+
const mergedOptions = {
|
|
25
|
+
...tableOptions,
|
|
26
|
+
_features: {
|
|
27
|
+
...tableOptions._features,
|
|
28
|
+
vueReactivityFeature
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
const table = constructTable(mergeProxy(getOptionsWithReactiveValues(mergedOptions), { mergeOptions: (defaultOptions, newOptions) => {
|
|
32
|
+
return mergeProxy(defaultOptions, newOptions);
|
|
33
|
+
} }));
|
|
34
|
+
const allState = useSelector(table.store, (state) => state);
|
|
35
|
+
const allOptions = useSelector(table.optionsStore, (state) => state);
|
|
36
|
+
watchEffect(() => {
|
|
37
|
+
allState.value;
|
|
38
|
+
allOptions.value;
|
|
39
|
+
notifier.value++;
|
|
40
|
+
});
|
|
41
|
+
watch(() => getReactiveOptionDeps(mergedOptions), () => {
|
|
42
|
+
syncTableOptions(table, mergedOptions);
|
|
43
|
+
}, { immediate: true });
|
|
44
|
+
watch(() => {
|
|
45
|
+
const controlledState = unref(tableOptions.state);
|
|
46
|
+
const controlledAtoms = unref(tableOptions.atoms);
|
|
47
|
+
if (!controlledState) return [];
|
|
48
|
+
const controlledValues = [];
|
|
49
|
+
for (const key of Object.keys(table.initialState)) {
|
|
50
|
+
if (!(key in controlledState) || (controlledAtoms === null || controlledAtoms === void 0 ? void 0 : controlledAtoms[key]) !== void 0) continue;
|
|
51
|
+
controlledValues.push(controlledState[key]);
|
|
52
|
+
}
|
|
53
|
+
return controlledValues;
|
|
54
|
+
}, (controlledValues) => {
|
|
55
|
+
if (controlledValues.length > 0) syncTableOptions(table, mergedOptions);
|
|
56
|
+
}, { immediate: true });
|
|
57
|
+
table.Subscribe = ((props) => {
|
|
58
|
+
const selected = useSelector(props.source !== void 0 ? props.source : table.store, props.source !== void 0 ? props.selector ?? ((x) => x) : props.selector, { compare: shallow });
|
|
59
|
+
if (typeof props.children === "function") return props.children(selected.value);
|
|
60
|
+
return props.children;
|
|
61
|
+
});
|
|
62
|
+
const stateStore = useSelector(table.store, selector);
|
|
63
|
+
return {
|
|
64
|
+
...table,
|
|
65
|
+
get state() {
|
|
66
|
+
return stateStore.value;
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
//#endregion
|
|
72
|
+
export { useTable };
|
|
73
|
+
//# 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 { shallow, useSelector } from '@tanstack/vue-store'\nimport { mergeProxy } from './merge-proxy'\nimport type { Atom, ReadonlyAtom } 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 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 = {},\n> = Table<TFeatures, TData> & {\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: Atom<TSourceValue> | ReadonlyAtom<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: Atom<TSourceValue> | ReadonlyAtom<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 `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:\n | TableOptions<TFeatures, TData>\n | 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 syncTableOptions = (\n table: Table<TFeatures, TData>,\n options: TableOptionsWithReactiveData<TFeatures, TData>,\n ) => {\n table.setOptions(\n () =>\n getOptionsWithReactiveValues(options) as TableOptions<TFeatures, TData>,\n )\n }\n\n const vueReactivityFeature = constructReactivityFeature({\n stateNotifier: () => notifier.value,\n optionsNotifier: () => notifier.value,\n })\n\n const mergedOptions = {\n ...tableOptions,\n _features: {\n ...tableOptions._features,\n vueReactivityFeature,\n },\n }\n\n const resolvedOptions = mergeProxy(\n getOptionsWithReactiveValues(\n mergedOptions as TableOptionsWithReactiveData<TFeatures, TData>,\n ),\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 = useSelector(table.store, (state) => state)\n const allOptions = useSelector(table.optionsStore, (state) => state)\n\n watchEffect(() => {\n allState.value\n allOptions.value\n notifier.value++\n })\n\n watch(\n () =>\n getReactiveOptionDeps(\n mergedOptions as TableOptionsWithReactiveData<TFeatures, TData>,\n ),\n () => {\n syncTableOptions(table, 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(table, mergedOptions)\n }\n },\n { immediate: true },\n )\n\n table.Subscribe = ((props: {\n source?: Atom<unknown> | ReadonlyAtom<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 !== undefined ? props.source : table.store\n const selectFn =\n props.source !== undefined\n ? (props.selector ?? ((x: unknown) => x))\n : props.selector\n const selected = useSelector(source as never, selectFn 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":";;;;;;AA2BA,SAAS,6BAGP,SAAyD;CACzD,MAAM,kBAA2C,EAAE;AAEnD,MAAK,MAAM,OAAO,OAAO,KAAK,QAAQ,CACpC,iBAAgB,OAAO,MACrB,QAAQ,KACT;AAGH,QAAO,WAAW,SAAS,gBAAgB;;AAG7C,SAAS,sBAGP,SAAyD;AACzD,QAAO,OAAO,KAAK,QAAQ,CAAC,KAAK,QAC/B,MAAM,QAAQ,KAA6D,CAC5E;;AAiDH,SAAgB,SAKd,cAGA,kBACG,EAAE,GACkC;CACvC,MAAM,WAAW,IAAY,EAAE;CAE/B,MAAM,oBACJ,OACA,YACG;AACH,QAAM,iBAEF,6BAA6B,QAAQ,CACxC;;CAGH,MAAM,uBAAuB,2BAA2B;EACtD,qBAAqB,SAAS;EAC9B,uBAAuB,SAAS;EACjC,CAAC;CAEF,MAAM,gBAAgB;EACpB,GAAG;EACH,WAAW;GACT,GAAG,aAAa;GAChB;GACD;EACF;CAiBD,MAAM,QAAQ,eAfU,WACtB,6BACE,cACD,EACD,EAEE,eACE,gBACA,eACG;AACH,SAAO,WAAW,gBAAgB,WAAW;IAEhD,CAGyC,CAAC;CAM7C,MAAM,WAAW,YAAY,MAAM,QAAQ,UAAU,MAAM;CAC3D,MAAM,aAAa,YAAY,MAAM,eAAe,UAAU,MAAM;AAEpE,mBAAkB;AAChB,WAAS;AACT,aAAW;AACX,WAAS;GACT;AAEF,aAEI,sBACE,cACD,QACG;AACJ,mBAAiB,OAAO,cAAc;IAExC,EAAE,WAAW,MAAM,CACpB;AAED,aACQ;EACJ,MAAM,kBAAkB,MAAM,aAAa,MAAM;EAGjD,MAAM,kBAAkB,MAAM,aAAa,MAAM;AAIjD,MAAI,CAAC,gBACH,QAAO,EAAE;EAGX,MAAM,mBAAmC,EAAE;AAE3C,OAAK,MAAM,OAAO,OAAO,KAAK,MAAM,aAAa,EAAE;AACjD,OAAI,EAAE,OAAO,uFAAoB,gBAAkB,UAAS,OAC1D;AAKF,oBAAiB,KAAK,gBAAgB,KAAK;;AAG7C,SAAO;KAER,qBAAqB;AACpB,MAAI,iBAAiB,SAAS,EAC5B,kBAAiB,OAAO,cAAc;IAG1C,EAAE,WAAW,MAAM,CACpB;AAED,OAAM,cAAc,UAOd;EAMJ,MAAM,WAAW,YALF,MAAM,WAAW,SAAY,MAAM,SAAS,MAAM,OAE/D,MAAM,WAAW,SACZ,MAAM,cAAc,MAAe,KACpC,MAAM,UACqD,EAC/D,SAAS,SACV,CAAC;AACF,MAAI,OAAO,MAAM,aAAa,WAC5B,QAAO,MAAM,SAAS,SAAS,MAA2B;AAE5D,SAAO,MAAM;;CAGf,MAAM,aAAa,YAAY,MAAM,OAAO,SAAS;AAErD,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.
|
|
3
|
+
"version": "9.0.0-alpha.41",
|
|
4
4
|
"description": "Headless UI for building powerful tables & datagrids for Vue.",
|
|
5
5
|
"author": "Tanner Linsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -21,39 +21,49 @@
|
|
|
21
21
|
"datagrid"
|
|
22
22
|
],
|
|
23
23
|
"type": "module",
|
|
24
|
-
"types": "dist/
|
|
25
|
-
"main": "dist/
|
|
26
|
-
"module": "dist/
|
|
24
|
+
"types": "./dist/index.d.cts",
|
|
25
|
+
"main": "./dist/index.cjs",
|
|
26
|
+
"module": "./dist/index.js",
|
|
27
27
|
"exports": {
|
|
28
28
|
".": {
|
|
29
|
-
"import":
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
"
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
29
|
+
"import": "./dist/index.js",
|
|
30
|
+
"require": "./dist/index.cjs"
|
|
31
|
+
},
|
|
32
|
+
"./flex-render": {
|
|
33
|
+
"import": "./dist/flex-render.js",
|
|
34
|
+
"require": "./dist/flex-render.cjs"
|
|
35
|
+
},
|
|
36
|
+
"./static-functions": {
|
|
37
|
+
"import": "./dist/static-functions.js",
|
|
38
|
+
"require": "./dist/static-functions.cjs"
|
|
37
39
|
},
|
|
38
40
|
"./package.json": "./package.json"
|
|
39
41
|
},
|
|
40
42
|
"sideEffects": false,
|
|
41
43
|
"engines": {
|
|
42
|
-
"node": ">=
|
|
44
|
+
"node": ">=16"
|
|
43
45
|
},
|
|
44
46
|
"files": [
|
|
45
47
|
"dist",
|
|
46
48
|
"src"
|
|
47
49
|
],
|
|
48
50
|
"dependencies": {
|
|
49
|
-
"@tanstack/
|
|
51
|
+
"@tanstack/vue-store": "^0.11.0",
|
|
52
|
+
"@tanstack/table-core": "9.0.0-alpha.41"
|
|
50
53
|
},
|
|
51
54
|
"devDependencies": {
|
|
52
|
-
"@vitejs/plugin-vue": "^
|
|
53
|
-
"vue": "^
|
|
55
|
+
"@vitejs/plugin-vue": "^6.0.6",
|
|
56
|
+
"eslint-plugin-vue": "^10.9.0",
|
|
57
|
+
"vue": "^3.5.33"
|
|
54
58
|
},
|
|
55
59
|
"peerDependencies": {
|
|
56
60
|
"vue": ">=3.2"
|
|
57
61
|
},
|
|
58
|
-
"scripts": {
|
|
62
|
+
"scripts": {
|
|
63
|
+
"clean": "rimraf ./build && rimraf ./dist",
|
|
64
|
+
"test:eslint": "eslint ./src",
|
|
65
|
+
"test:types": "tsc",
|
|
66
|
+
"test:build": "publint --strict",
|
|
67
|
+
"build": "tsdown"
|
|
68
|
+
}
|
|
59
69
|
}
|
|
@@ -0,0 +1,123 @@
|
|
|
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
|
+
const cell = props.cell
|
|
86
|
+
const def = cell.column.columnDef
|
|
87
|
+
// When the column-grouping feature is registered, a cell can be in
|
|
88
|
+
// one of three special modes that should not render `columnDef.cell`
|
|
89
|
+
// directly:
|
|
90
|
+
// - aggregated: render `columnDef.aggregatedCell` (falling back to
|
|
91
|
+
// `columnDef.cell` if the column did not define one)
|
|
92
|
+
// - placeholder: a duplicate value within a group — render nothing
|
|
93
|
+
// - grouped: fall through to `columnDef.cell`; consumers that want
|
|
94
|
+
// a custom group header typically branch on `cell.getIsGrouped()`
|
|
95
|
+
// themselves first
|
|
96
|
+
if (cell.getIsAggregated?.()) {
|
|
97
|
+
return flexRender(def.aggregatedCell ?? def.cell, cell.getContext())
|
|
98
|
+
}
|
|
99
|
+
if (cell.getIsPlaceholder?.()) {
|
|
100
|
+
return null
|
|
101
|
+
}
|
|
102
|
+
return flexRender(def.cell, cell.getContext())
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
if (props.header) {
|
|
106
|
+
return flexRender(
|
|
107
|
+
props.header.column.columnDef.header,
|
|
108
|
+
props.header.getContext(),
|
|
109
|
+
)
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
if (props.footer) {
|
|
113
|
+
return flexRender(
|
|
114
|
+
props.footer.column.columnDef.footer,
|
|
115
|
+
props.footer.getContext(),
|
|
116
|
+
)
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// Legacy pattern: use render and props directly
|
|
120
|
+
return flexRender(props.render, props.props)
|
|
121
|
+
}
|
|
122
|
+
},
|
|
123
|
+
})
|