@tanstack/vue-table 9.0.0-alpha.52 → 9.0.0-alpha.53
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/dist/merge-proxy.cjs +14 -1
- package/dist/merge-proxy.cjs.map +1 -1
- package/dist/merge-proxy.js +14 -2
- package/dist/merge-proxy.js.map +1 -1
- package/dist/reactivity.cjs +7 -0
- package/dist/reactivity.cjs.map +1 -1
- package/dist/reactivity.js +7 -0
- package/dist/reactivity.js.map +1 -1
- package/dist/useTable.cjs +2 -2
- package/dist/useTable.cjs.map +1 -1
- package/dist/useTable.js +3 -3
- package/dist/useTable.js.map +1 -1
- package/package.json +2 -2
- package/src/merge-proxy.ts +35 -1
- package/src/reactivity.ts +11 -0
- package/src/useTable.ts +4 -5
package/dist/merge-proxy.cjs
CHANGED
|
@@ -32,7 +32,7 @@ const propTraps = {
|
|
|
32
32
|
}
|
|
33
33
|
};
|
|
34
34
|
function resolveSource(s) {
|
|
35
|
-
return "value" in s ? s.value : s;
|
|
35
|
+
return s && typeof s === "object" && "value" in s ? s.value : s;
|
|
36
36
|
}
|
|
37
37
|
function mergeProxy(...sources) {
|
|
38
38
|
const flattenedSources = sources.flatMap((source) => {
|
|
@@ -58,7 +58,20 @@ function mergeProxy(...sources) {
|
|
|
58
58
|
}
|
|
59
59
|
}, propTraps);
|
|
60
60
|
}
|
|
61
|
+
function flatMerge(...sources) {
|
|
62
|
+
const result = {};
|
|
63
|
+
for (let source of sources) {
|
|
64
|
+
source = resolveSource(source);
|
|
65
|
+
if (!source) continue;
|
|
66
|
+
for (const key of Reflect.ownKeys(source)) {
|
|
67
|
+
const value = source[key];
|
|
68
|
+
if (value !== void 0) result[key] = value;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return result;
|
|
72
|
+
}
|
|
61
73
|
|
|
62
74
|
//#endregion
|
|
75
|
+
exports.flatMerge = flatMerge;
|
|
63
76
|
exports.mergeProxy = mergeProxy;
|
|
64
77
|
//# sourceMappingURL=merge-proxy.cjs.map
|
package/dist/merge-proxy.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"merge-proxy.cjs","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;CAChB,OAAO;AACT;AAEA,MAAM,SAAS,OAAO,aAAa;AACnC,MAAM,WAAW,OAAO,qBAAqB;AAG7C,MAAM,YAKD;CACH,IAAI,GAAG,UAAU,UAAU;EACzB,IAAI,aAAa,QAAQ,OAAO;EAChC,IAAI,aAAa,UAAU,OAAO,EAAE;EACpC,OAAO,EAAE,IAAI,QAAQ;CACvB;CACA,IAAI,GAAG,UAAU;EACf,OAAO,EAAE,IAAI,QAAQ;CACvB;CACA,KAAK;CACL,gBAAgB;CAChB,yBAAyB,GAAG,UAAU;EACpC,OAAO;GACL,cAAc;GACd,YAAY;GACZ,MAAM;IACJ,OAAO,EAAE,IAAI,QAAQ;GACvB;GACA,KAAK;GACL,gBAAgB;EAClB;CACF;CACA,QAAQ,GAAG;EACT,OAAO,EAAE,KAAK;CAChB;AACF;AAgBA,SAAS,cAAc,GAAQ;CAC7B,OAAO,WAAW,IAAI,EAAE,QAAQ;
|
|
1
|
+
{"version":3,"file":"merge-proxy.cjs","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 s && typeof s === 'object' && '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\n/**\n * Merges objects together by eagerly resolving all values into a flat object.\n *\n * Unlike `mergeProxy`, this does not preserve lazy proxy getters. Use this for\n * repeated option update paths so each merge produces a plain object instead\n * of accumulating a longer source list over time.\n */\nexport function flatMerge<T>(source: T): T\nexport function flatMerge<T, U>(source: T, source1: U): T & U\nexport function flatMerge<T, U, V>(source: T, source1: U, source2: V): T & U & V\nexport function flatMerge<T, U, V, W>(\n source: T,\n source1: U,\n source2: V,\n source3: W,\n): T & U & V & W\nexport function flatMerge(...sources: any): any {\n const result: Record<PropertyKey, unknown> = {}\n\n for (let source of sources) {\n source = resolveSource(source)\n if (!source) continue\n\n for (const key of Reflect.ownKeys(source)) {\n const value = (source as Record<PropertyKey, unknown>)[key]\n if (value !== undefined) {\n result[key] = value\n }\n }\n }\n\n return result\n}\n"],"mappings":";;AAAA,SAAS,SAAS;CAChB,OAAO;AACT;AAEA,MAAM,SAAS,OAAO,aAAa;AACnC,MAAM,WAAW,OAAO,qBAAqB;AAG7C,MAAM,YAKD;CACH,IAAI,GAAG,UAAU,UAAU;EACzB,IAAI,aAAa,QAAQ,OAAO;EAChC,IAAI,aAAa,UAAU,OAAO,EAAE;EACpC,OAAO,EAAE,IAAI,QAAQ;CACvB;CACA,IAAI,GAAG,UAAU;EACf,OAAO,EAAE,IAAI,QAAQ;CACvB;CACA,KAAK;CACL,gBAAgB;CAChB,yBAAyB,GAAG,UAAU;EACpC,OAAO;GACL,cAAc;GACd,YAAY;GACZ,MAAM;IACJ,OAAO,EAAE,IAAI,QAAQ;GACvB;GACA,KAAK;GACL,gBAAgB;EAClB;CACF;CACA,QAAQ,GAAG;EACT,OAAO,EAAE,KAAK;CAChB;AACF;AAgBA,SAAS,cAAc,GAAQ;CAC7B,OAAO,KAAK,OAAO,MAAM,YAAY,WAAW,IAAI,EAAE,QAAQ;AAChE;AAGA,SAAgB,WAAW,GAAG,SAAmB;CAC/C,MAAM,mBAAmB,QAAQ,SAAS,WAAgB;EACxD,IACE,OAAO,WAAW,YAClB,WAAW,QACX,YAAY,UACZ,MAAM,QAAQ,OAAO,SAAS,GAE9B,OAAO,OAAO;EAGhB,OAAO,CAAC,MAAM;CAChB,CAAC;CAED,OAAO,IAAI,MACT;EACE,SAAS;EACT,IAAI,UAAoC;GACtC,KAAK,IAAI,IAAI,iBAAiB,SAAS,GAAG,KAAK,GAAG,KAAK;IACrD,MAAM,IAAI,cAAc,iBAAiB,EAAE,EAAE;IAC7C,IAAI,MAAM,QAAW,OAAO;GAC9B;EACF;EACA,IAAI,UAAoC;GACtC,KAAK,IAAI,IAAI,iBAAiB,SAAS,GAAG,KAAK,GAAG,KAChD,IAAI,YAAY,cAAc,iBAAiB,EAAE,GAAG,OAAO;GAE7D,OAAO;EACT;EACA,OAAO;GACL,MAAM,OAAO,CAAC;GACd,KAAK,MAAM,UAAU,kBACnB,KAAK,KAAK,GAAG,OAAO,KAAK,cAAc,MAAM,CAAC,CAAC;GACjD,OAAO,CAAC,GAAG,MAAM,KAAK,IAAI,IAAI,IAAI,CAAC,CAAC;EACtC;CACF,GACA,SACF;AACF;AAkBA,SAAgB,UAAU,GAAG,SAAmB;CAC9C,MAAM,SAAuC,CAAC;CAE9C,KAAK,IAAI,UAAU,SAAS;EAC1B,SAAS,cAAc,MAAM;EAC7B,IAAI,CAAC,QAAQ;EAEb,KAAK,MAAM,OAAO,QAAQ,QAAQ,MAAM,GAAG;GACzC,MAAM,QAAS,OAAwC;GACvD,IAAI,UAAU,QACZ,OAAO,OAAO;EAElB;CACF;CAEA,OAAO;AACT"}
|
package/dist/merge-proxy.js
CHANGED
|
@@ -31,7 +31,7 @@ const propTraps = {
|
|
|
31
31
|
}
|
|
32
32
|
};
|
|
33
33
|
function resolveSource(s) {
|
|
34
|
-
return "value" in s ? s.value : s;
|
|
34
|
+
return s && typeof s === "object" && "value" in s ? s.value : s;
|
|
35
35
|
}
|
|
36
36
|
function mergeProxy(...sources) {
|
|
37
37
|
const flattenedSources = sources.flatMap((source) => {
|
|
@@ -57,7 +57,19 @@ function mergeProxy(...sources) {
|
|
|
57
57
|
}
|
|
58
58
|
}, propTraps);
|
|
59
59
|
}
|
|
60
|
+
function flatMerge(...sources) {
|
|
61
|
+
const result = {};
|
|
62
|
+
for (let source of sources) {
|
|
63
|
+
source = resolveSource(source);
|
|
64
|
+
if (!source) continue;
|
|
65
|
+
for (const key of Reflect.ownKeys(source)) {
|
|
66
|
+
const value = source[key];
|
|
67
|
+
if (value !== void 0) result[key] = value;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return result;
|
|
71
|
+
}
|
|
60
72
|
|
|
61
73
|
//#endregion
|
|
62
|
-
export { mergeProxy };
|
|
74
|
+
export { flatMerge, mergeProxy };
|
|
63
75
|
//# sourceMappingURL=merge-proxy.js.map
|
package/dist/merge-proxy.js.map
CHANGED
|
@@ -1 +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;CAChB,OAAO;AACT;AAEA,MAAM,SAAS,OAAO,aAAa;AACnC,MAAM,WAAW,OAAO,qBAAqB;AAG7C,MAAM,YAKD;CACH,IAAI,GAAG,UAAU,UAAU;EACzB,IAAI,aAAa,QAAQ,OAAO;EAChC,IAAI,aAAa,UAAU,OAAO,EAAE;EACpC,OAAO,EAAE,IAAI,QAAQ;CACvB;CACA,IAAI,GAAG,UAAU;EACf,OAAO,EAAE,IAAI,QAAQ;CACvB;CACA,KAAK;CACL,gBAAgB;CAChB,yBAAyB,GAAG,UAAU;EACpC,OAAO;GACL,cAAc;GACd,YAAY;GACZ,MAAM;IACJ,OAAO,EAAE,IAAI,QAAQ;GACvB;GACA,KAAK;GACL,gBAAgB;EAClB;CACF;CACA,QAAQ,GAAG;EACT,OAAO,EAAE,KAAK;CAChB;AACF;AAgBA,SAAS,cAAc,GAAQ;CAC7B,OAAO,WAAW,IAAI,EAAE,QAAQ;
|
|
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 s && typeof s === 'object' && '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\n/**\n * Merges objects together by eagerly resolving all values into a flat object.\n *\n * Unlike `mergeProxy`, this does not preserve lazy proxy getters. Use this for\n * repeated option update paths so each merge produces a plain object instead\n * of accumulating a longer source list over time.\n */\nexport function flatMerge<T>(source: T): T\nexport function flatMerge<T, U>(source: T, source1: U): T & U\nexport function flatMerge<T, U, V>(source: T, source1: U, source2: V): T & U & V\nexport function flatMerge<T, U, V, W>(\n source: T,\n source1: U,\n source2: V,\n source3: W,\n): T & U & V & W\nexport function flatMerge(...sources: any): any {\n const result: Record<PropertyKey, unknown> = {}\n\n for (let source of sources) {\n source = resolveSource(source)\n if (!source) continue\n\n for (const key of Reflect.ownKeys(source)) {\n const value = (source as Record<PropertyKey, unknown>)[key]\n if (value !== undefined) {\n result[key] = value\n }\n }\n }\n\n return result\n}\n"],"mappings":";AAAA,SAAS,SAAS;CAChB,OAAO;AACT;AAEA,MAAM,SAAS,OAAO,aAAa;AACnC,MAAM,WAAW,OAAO,qBAAqB;AAG7C,MAAM,YAKD;CACH,IAAI,GAAG,UAAU,UAAU;EACzB,IAAI,aAAa,QAAQ,OAAO;EAChC,IAAI,aAAa,UAAU,OAAO,EAAE;EACpC,OAAO,EAAE,IAAI,QAAQ;CACvB;CACA,IAAI,GAAG,UAAU;EACf,OAAO,EAAE,IAAI,QAAQ;CACvB;CACA,KAAK;CACL,gBAAgB;CAChB,yBAAyB,GAAG,UAAU;EACpC,OAAO;GACL,cAAc;GACd,YAAY;GACZ,MAAM;IACJ,OAAO,EAAE,IAAI,QAAQ;GACvB;GACA,KAAK;GACL,gBAAgB;EAClB;CACF;CACA,QAAQ,GAAG;EACT,OAAO,EAAE,KAAK;CAChB;AACF;AAgBA,SAAS,cAAc,GAAQ;CAC7B,OAAO,KAAK,OAAO,MAAM,YAAY,WAAW,IAAI,EAAE,QAAQ;AAChE;AAGA,SAAgB,WAAW,GAAG,SAAmB;CAC/C,MAAM,mBAAmB,QAAQ,SAAS,WAAgB;EACxD,IACE,OAAO,WAAW,YAClB,WAAW,QACX,YAAY,UACZ,MAAM,QAAQ,OAAO,SAAS,GAE9B,OAAO,OAAO;EAGhB,OAAO,CAAC,MAAM;CAChB,CAAC;CAED,OAAO,IAAI,MACT;EACE,SAAS;EACT,IAAI,UAAoC;GACtC,KAAK,IAAI,IAAI,iBAAiB,SAAS,GAAG,KAAK,GAAG,KAAK;IACrD,MAAM,IAAI,cAAc,iBAAiB,EAAE,EAAE;IAC7C,IAAI,MAAM,QAAW,OAAO;GAC9B;EACF;EACA,IAAI,UAAoC;GACtC,KAAK,IAAI,IAAI,iBAAiB,SAAS,GAAG,KAAK,GAAG,KAChD,IAAI,YAAY,cAAc,iBAAiB,EAAE,GAAG,OAAO;GAE7D,OAAO;EACT;EACA,OAAO;GACL,MAAM,OAAO,CAAC;GACd,KAAK,MAAM,UAAU,kBACnB,KAAK,KAAK,GAAG,OAAO,KAAK,cAAc,MAAM,CAAC,CAAC;GACjD,OAAO,CAAC,GAAG,MAAM,KAAK,IAAI,IAAI,IAAI,CAAC,CAAC;EACtC;CACF,GACA,SACF;AACF;AAkBA,SAAgB,UAAU,GAAG,SAAmB;CAC9C,MAAM,SAAuC,CAAC;CAE9C,KAAK,IAAI,UAAU,SAAS;EAC1B,SAAS,cAAc,MAAM;EAC7B,IAAI,CAAC,QAAQ;EAEb,KAAK,MAAM,OAAO,QAAQ,QAAQ,MAAM,GAAG;GACzC,MAAM,QAAS,OAAwC;GACvD,IAAI,UAAU,QACZ,OAAO,OAAO;EAElB;CACF;CAEA,OAAO;AACT"}
|
package/dist/reactivity.cjs
CHANGED
|
@@ -39,6 +39,13 @@ function refToWritableAtom(source) {
|
|
|
39
39
|
function vueReactivity() {
|
|
40
40
|
return {
|
|
41
41
|
createOptionsStore: true,
|
|
42
|
+
wrapExternalAtoms: false,
|
|
43
|
+
addSubscription: () => {
|
|
44
|
+
throw new Error("Feature not supported in current reactivity implementation");
|
|
45
|
+
},
|
|
46
|
+
unmount: () => {
|
|
47
|
+
throw new Error("Feature not supported in current reactivity implementation");
|
|
48
|
+
},
|
|
42
49
|
schedule: (fn) => queueMicrotask(() => fn()),
|
|
43
50
|
createReadonlyAtom: (fn, _options) => {
|
|
44
51
|
const storeAtom = (0, _tanstack_vue_store.createAtom)(() => fn(), { compare: _options === null || _options === void 0 ? void 0 : _options.compare });
|
package/dist/reactivity.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reactivity.cjs","names":[],"sources":["../src/reactivity.ts"],"sourcesContent":["import {\n computed,\n getCurrentScope,\n onScopeDispose,\n shallowRef,\n watch,\n} from 'vue'\nimport { batch, createAtom } from '@tanstack/vue-store'\nimport type {\n TableAtomOptions,\n TableReactivityBindings,\n} from '@tanstack/table-core/reactivity'\nimport type { Atom, Observer, ReadonlyAtom } from '@tanstack/vue-store'\nimport type { ComputedRef, ShallowRef } from 'vue'\n\nconst optionsStoreDebugName = 'table/optionsStore'\n\nfunction observerToCallback<T>(\n observerOrNext: Observer<T> | ((value: T) => void),\n): (value: T) => void {\n return typeof observerOrNext === 'function'\n ? observerOrNext\n : (value) => observerOrNext.next?.(value)\n}\n\nfunction refToReadonlyAtom<T>(\n source: ComputedRef<T> | ShallowRef<T>,\n): ReadonlyAtom<T> {\n return Object.assign(source, {\n get: () => source.value,\n subscribe: ((observerOrNext: Observer<T> | ((value: T) => void)) => {\n const stop = watch(source, observerToCallback(observerOrNext), {\n flush: 'sync',\n })\n return { unsubscribe: stop }\n }) as ReadonlyAtom<T>['subscribe'],\n })\n}\n\nfunction refToWritableAtom<T>(source: ShallowRef<T>): Atom<T> {\n return Object.assign(source, {\n set: (updater: T | ((prevVal: T) => T)) => {\n source.value =\n typeof updater === 'function'\n ? (updater as (prevVal: T) => T)(source.value)\n : updater\n },\n get: () => source.value,\n subscribe: ((observerOrNext: Observer<T> | ((value: T) => void)) => {\n const stop = watch(source, observerToCallback(observerOrNext), {\n flush: 'sync',\n })\n return { unsubscribe: stop }\n }) as Atom<T>['subscribe'],\n })\n}\n\n/**\n * Creates the table-core reactivity bindings used by the Vue adapter.\n *\n * Table state atoms are backed by TanStack Store atoms. The options store stays\n * framework-native because row-model APIs read `table.options` directly during\n * render. Readonly table atoms bridge Store dependency tracking into Vue computed\n * refs.\n */\nexport function vueReactivity(): TableReactivityBindings {\n return {\n createOptionsStore: true,\n schedule: (fn) => queueMicrotask(() => fn()),\n createReadonlyAtom: <T>(fn: () => T, _options?: TableAtomOptions<T>) => {\n const storeAtom = createAtom(() => fn(), {\n compare: _options?.compare,\n })\n const version = shallowRef(0)\n const subscription = storeAtom.subscribe(() => {\n version.value += 1\n })\n if (getCurrentScope()) {\n onScopeDispose(() => subscription.unsubscribe())\n }\n\n return refToReadonlyAtom(\n computed(() => {\n version.value\n return storeAtom.get()\n }),\n )\n },\n createWritableAtom: <T>(\n value: T,\n _options?: TableAtomOptions<T>,\n ): Atom<T> => {\n if (_options?.debugName === optionsStoreDebugName) {\n return refToWritableAtom(shallowRef(value) as ShallowRef<T>)\n }\n\n return createAtom(value, {\n compare: _options?.compare,\n })\n },\n untrack: (fn) => fn(),\n batch,\n }\n}\n"],"mappings":";;;;AAeA,MAAM,wBAAwB;AAE9B,SAAS,mBACP,gBACoB;CACpB,OAAO,OAAO,mBAAmB,aAC7B,kBACC,UAAU;;gDAAe,uGAAO,KAAK;;AAC5C;AAEA,SAAS,kBACP,QACiB;CACjB,OAAO,OAAO,OAAO,QAAQ;EAC3B,WAAW,OAAO;EAClB,aAAa,mBAAuD;GAIlE,OAAO,EAAE,4BAHU,QAAQ,mBAAmB,cAAc,GAAG,EAC7D,OAAO,OACT,CACyB,EAAE;EAC7B;CACF,CAAC;AACH;AAEA,SAAS,kBAAqB,QAAgC;CAC5D,OAAO,OAAO,OAAO,QAAQ;EAC3B,MAAM,YAAqC;GACzC,OAAO,QACL,OAAO,YAAY,aACd,QAA8B,OAAO,KAAK,IAC3C;EACR;EACA,WAAW,OAAO;EAClB,aAAa,mBAAuD;GAIlE,OAAO,EAAE,4BAHU,QAAQ,mBAAmB,cAAc,GAAG,EAC7D,OAAO,OACT,CACyB,EAAE;EAC7B;CACF,CAAC;AACH;;;;;;;;;AAUA,SAAgB,gBAAyC;CACvD,OAAO;EACL,oBAAoB;EACpB,WAAW,OAAO,qBAAqB,GAAG,CAAC;EAC3C,qBAAwB,IAAa,aAAmC;GACtE,MAAM,sDAA6B,GAAG,GAAG,EACvC,6DAAS,SAAU,QACrB,CAAC;GACD,MAAM,8BAAqB,CAAC;GAC5B,MAAM,eAAe,UAAU,gBAAgB;IAC7C,QAAQ,SAAS;GACnB,CAAC;GACD,6BAAoB,GAClB,8BAAqB,aAAa,YAAY,CAAC;GAGjD,OAAO,0CACU;IACb,QAAQ;IACR,OAAO,UAAU,IAAI;GACvB,CAAC,CACH;EACF;EACA,qBACE,OACA,aACY;GACZ,yDAAI,SAAU,eAAc,uBAC1B,OAAO,sCAA6B,KAAK,CAAkB;GAG7D,2CAAkB,OAAO,EACvB,6DAAS,SAAU,QACrB,CAAC;EACH;EACA,UAAU,OAAO,GAAG;EACpB;CACF;AACF"}
|
|
1
|
+
{"version":3,"file":"reactivity.cjs","names":[],"sources":["../src/reactivity.ts"],"sourcesContent":["import {\n computed,\n getCurrentScope,\n onScopeDispose,\n shallowRef,\n watch,\n} from 'vue'\nimport { batch, createAtom } from '@tanstack/vue-store'\nimport type {\n TableAtomOptions,\n TableReactivityBindings,\n} from '@tanstack/table-core/reactivity'\nimport type { Atom, Observer, ReadonlyAtom } from '@tanstack/vue-store'\nimport type { ComputedRef, ShallowRef } from 'vue'\n\nconst optionsStoreDebugName = 'table/optionsStore'\n\nfunction observerToCallback<T>(\n observerOrNext: Observer<T> | ((value: T) => void),\n): (value: T) => void {\n return typeof observerOrNext === 'function'\n ? observerOrNext\n : (value) => observerOrNext.next?.(value)\n}\n\nfunction refToReadonlyAtom<T>(\n source: ComputedRef<T> | ShallowRef<T>,\n): ReadonlyAtom<T> {\n return Object.assign(source, {\n get: () => source.value,\n subscribe: ((observerOrNext: Observer<T> | ((value: T) => void)) => {\n const stop = watch(source, observerToCallback(observerOrNext), {\n flush: 'sync',\n })\n return { unsubscribe: stop }\n }) as ReadonlyAtom<T>['subscribe'],\n })\n}\n\nfunction refToWritableAtom<T>(source: ShallowRef<T>): Atom<T> {\n return Object.assign(source, {\n set: (updater: T | ((prevVal: T) => T)) => {\n source.value =\n typeof updater === 'function'\n ? (updater as (prevVal: T) => T)(source.value)\n : updater\n },\n get: () => source.value,\n subscribe: ((observerOrNext: Observer<T> | ((value: T) => void)) => {\n const stop = watch(source, observerToCallback(observerOrNext), {\n flush: 'sync',\n })\n return { unsubscribe: stop }\n }) as Atom<T>['subscribe'],\n })\n}\n\n/**\n * Creates the table-core reactivity bindings used by the Vue adapter.\n *\n * Table state atoms are backed by TanStack Store atoms. The options store stays\n * framework-native because row-model APIs read `table.options` directly during\n * render. Readonly table atoms bridge Store dependency tracking into Vue computed\n * refs.\n */\nexport function vueReactivity(): TableReactivityBindings {\n return {\n createOptionsStore: true,\n wrapExternalAtoms: false,\n addSubscription: () => {\n throw new Error(\n 'Feature not supported in current reactivity implementation',\n )\n },\n unmount: () => {\n throw new Error(\n 'Feature not supported in current reactivity implementation',\n )\n },\n schedule: (fn) => queueMicrotask(() => fn()),\n createReadonlyAtom: <T>(fn: () => T, _options?: TableAtomOptions<T>) => {\n const storeAtom = createAtom(() => fn(), {\n compare: _options?.compare,\n })\n const version = shallowRef(0)\n const subscription = storeAtom.subscribe(() => {\n version.value += 1\n })\n if (getCurrentScope()) {\n onScopeDispose(() => subscription.unsubscribe())\n }\n\n return refToReadonlyAtom(\n computed(() => {\n version.value\n return storeAtom.get()\n }),\n )\n },\n createWritableAtom: <T>(\n value: T,\n _options?: TableAtomOptions<T>,\n ): Atom<T> => {\n if (_options?.debugName === optionsStoreDebugName) {\n return refToWritableAtom(shallowRef(value) as ShallowRef<T>)\n }\n\n return createAtom(value, {\n compare: _options?.compare,\n })\n },\n untrack: (fn) => fn(),\n batch,\n }\n}\n"],"mappings":";;;;AAeA,MAAM,wBAAwB;AAE9B,SAAS,mBACP,gBACoB;CACpB,OAAO,OAAO,mBAAmB,aAC7B,kBACC,UAAU;;gDAAe,uGAAO,KAAK;;AAC5C;AAEA,SAAS,kBACP,QACiB;CACjB,OAAO,OAAO,OAAO,QAAQ;EAC3B,WAAW,OAAO;EAClB,aAAa,mBAAuD;GAIlE,OAAO,EAAE,4BAHU,QAAQ,mBAAmB,cAAc,GAAG,EAC7D,OAAO,OACT,CACyB,EAAE;EAC7B;CACF,CAAC;AACH;AAEA,SAAS,kBAAqB,QAAgC;CAC5D,OAAO,OAAO,OAAO,QAAQ;EAC3B,MAAM,YAAqC;GACzC,OAAO,QACL,OAAO,YAAY,aACd,QAA8B,OAAO,KAAK,IAC3C;EACR;EACA,WAAW,OAAO;EAClB,aAAa,mBAAuD;GAIlE,OAAO,EAAE,4BAHU,QAAQ,mBAAmB,cAAc,GAAG,EAC7D,OAAO,OACT,CACyB,EAAE;EAC7B;CACF,CAAC;AACH;;;;;;;;;AAUA,SAAgB,gBAAyC;CACvD,OAAO;EACL,oBAAoB;EACpB,mBAAmB;EACnB,uBAAuB;GACrB,MAAM,IAAI,MACR,4DACF;EACF;EACA,eAAe;GACb,MAAM,IAAI,MACR,4DACF;EACF;EACA,WAAW,OAAO,qBAAqB,GAAG,CAAC;EAC3C,qBAAwB,IAAa,aAAmC;GACtE,MAAM,sDAA6B,GAAG,GAAG,EACvC,6DAAS,SAAU,QACrB,CAAC;GACD,MAAM,8BAAqB,CAAC;GAC5B,MAAM,eAAe,UAAU,gBAAgB;IAC7C,QAAQ,SAAS;GACnB,CAAC;GACD,6BAAoB,GAClB,8BAAqB,aAAa,YAAY,CAAC;GAGjD,OAAO,0CACU;IACb,QAAQ;IACR,OAAO,UAAU,IAAI;GACvB,CAAC,CACH;EACF;EACA,qBACE,OACA,aACY;GACZ,yDAAI,SAAU,eAAc,uBAC1B,OAAO,sCAA6B,KAAK,CAAkB;GAG7D,2CAAkB,OAAO,EACvB,6DAAS,SAAU,QACrB,CAAC;EACH;EACA,UAAU,OAAO,GAAG;EACpB;CACF;AACF"}
|
package/dist/reactivity.js
CHANGED
|
@@ -39,6 +39,13 @@ function refToWritableAtom(source) {
|
|
|
39
39
|
function vueReactivity() {
|
|
40
40
|
return {
|
|
41
41
|
createOptionsStore: true,
|
|
42
|
+
wrapExternalAtoms: false,
|
|
43
|
+
addSubscription: () => {
|
|
44
|
+
throw new Error("Feature not supported in current reactivity implementation");
|
|
45
|
+
},
|
|
46
|
+
unmount: () => {
|
|
47
|
+
throw new Error("Feature not supported in current reactivity implementation");
|
|
48
|
+
},
|
|
42
49
|
schedule: (fn) => queueMicrotask(() => fn()),
|
|
43
50
|
createReadonlyAtom: (fn, _options) => {
|
|
44
51
|
const storeAtom = createAtom(() => fn(), { compare: _options === null || _options === void 0 ? void 0 : _options.compare });
|
package/dist/reactivity.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reactivity.js","names":[],"sources":["../src/reactivity.ts"],"sourcesContent":["import {\n computed,\n getCurrentScope,\n onScopeDispose,\n shallowRef,\n watch,\n} from 'vue'\nimport { batch, createAtom } from '@tanstack/vue-store'\nimport type {\n TableAtomOptions,\n TableReactivityBindings,\n} from '@tanstack/table-core/reactivity'\nimport type { Atom, Observer, ReadonlyAtom } from '@tanstack/vue-store'\nimport type { ComputedRef, ShallowRef } from 'vue'\n\nconst optionsStoreDebugName = 'table/optionsStore'\n\nfunction observerToCallback<T>(\n observerOrNext: Observer<T> | ((value: T) => void),\n): (value: T) => void {\n return typeof observerOrNext === 'function'\n ? observerOrNext\n : (value) => observerOrNext.next?.(value)\n}\n\nfunction refToReadonlyAtom<T>(\n source: ComputedRef<T> | ShallowRef<T>,\n): ReadonlyAtom<T> {\n return Object.assign(source, {\n get: () => source.value,\n subscribe: ((observerOrNext: Observer<T> | ((value: T) => void)) => {\n const stop = watch(source, observerToCallback(observerOrNext), {\n flush: 'sync',\n })\n return { unsubscribe: stop }\n }) as ReadonlyAtom<T>['subscribe'],\n })\n}\n\nfunction refToWritableAtom<T>(source: ShallowRef<T>): Atom<T> {\n return Object.assign(source, {\n set: (updater: T | ((prevVal: T) => T)) => {\n source.value =\n typeof updater === 'function'\n ? (updater as (prevVal: T) => T)(source.value)\n : updater\n },\n get: () => source.value,\n subscribe: ((observerOrNext: Observer<T> | ((value: T) => void)) => {\n const stop = watch(source, observerToCallback(observerOrNext), {\n flush: 'sync',\n })\n return { unsubscribe: stop }\n }) as Atom<T>['subscribe'],\n })\n}\n\n/**\n * Creates the table-core reactivity bindings used by the Vue adapter.\n *\n * Table state atoms are backed by TanStack Store atoms. The options store stays\n * framework-native because row-model APIs read `table.options` directly during\n * render. Readonly table atoms bridge Store dependency tracking into Vue computed\n * refs.\n */\nexport function vueReactivity(): TableReactivityBindings {\n return {\n createOptionsStore: true,\n schedule: (fn) => queueMicrotask(() => fn()),\n createReadonlyAtom: <T>(fn: () => T, _options?: TableAtomOptions<T>) => {\n const storeAtom = createAtom(() => fn(), {\n compare: _options?.compare,\n })\n const version = shallowRef(0)\n const subscription = storeAtom.subscribe(() => {\n version.value += 1\n })\n if (getCurrentScope()) {\n onScopeDispose(() => subscription.unsubscribe())\n }\n\n return refToReadonlyAtom(\n computed(() => {\n version.value\n return storeAtom.get()\n }),\n )\n },\n createWritableAtom: <T>(\n value: T,\n _options?: TableAtomOptions<T>,\n ): Atom<T> => {\n if (_options?.debugName === optionsStoreDebugName) {\n return refToWritableAtom(shallowRef(value) as ShallowRef<T>)\n }\n\n return createAtom(value, {\n compare: _options?.compare,\n })\n },\n untrack: (fn) => fn(),\n batch,\n }\n}\n"],"mappings":";;;;AAeA,MAAM,wBAAwB;AAE9B,SAAS,mBACP,gBACoB;CACpB,OAAO,OAAO,mBAAmB,aAC7B,kBACC,UAAU;;gDAAe,uGAAO,KAAK;;AAC5C;AAEA,SAAS,kBACP,QACiB;CACjB,OAAO,OAAO,OAAO,QAAQ;EAC3B,WAAW,OAAO;EAClB,aAAa,mBAAuD;GAIlE,OAAO,EAAE,aAHI,MAAM,QAAQ,mBAAmB,cAAc,GAAG,EAC7D,OAAO,OACT,CACyB,EAAE;EAC7B;CACF,CAAC;AACH;AAEA,SAAS,kBAAqB,QAAgC;CAC5D,OAAO,OAAO,OAAO,QAAQ;EAC3B,MAAM,YAAqC;GACzC,OAAO,QACL,OAAO,YAAY,aACd,QAA8B,OAAO,KAAK,IAC3C;EACR;EACA,WAAW,OAAO;EAClB,aAAa,mBAAuD;GAIlE,OAAO,EAAE,aAHI,MAAM,QAAQ,mBAAmB,cAAc,GAAG,EAC7D,OAAO,OACT,CACyB,EAAE;EAC7B;CACF,CAAC;AACH;;;;;;;;;AAUA,SAAgB,gBAAyC;CACvD,OAAO;EACL,oBAAoB;EACpB,WAAW,OAAO,qBAAqB,GAAG,CAAC;EAC3C,qBAAwB,IAAa,aAAmC;GACtE,MAAM,YAAY,iBAAiB,GAAG,GAAG,EACvC,6DAAS,SAAU,QACrB,CAAC;GACD,MAAM,UAAU,WAAW,CAAC;GAC5B,MAAM,eAAe,UAAU,gBAAgB;IAC7C,QAAQ,SAAS;GACnB,CAAC;GACD,IAAI,gBAAgB,GAClB,qBAAqB,aAAa,YAAY,CAAC;GAGjD,OAAO,kBACL,eAAe;IACb,QAAQ;IACR,OAAO,UAAU,IAAI;GACvB,CAAC,CACH;EACF;EACA,qBACE,OACA,aACY;GACZ,yDAAI,SAAU,eAAc,uBAC1B,OAAO,kBAAkB,WAAW,KAAK,CAAkB;GAG7D,OAAO,WAAW,OAAO,EACvB,6DAAS,SAAU,QACrB,CAAC;EACH;EACA,UAAU,OAAO,GAAG;EACpB;CACF;AACF"}
|
|
1
|
+
{"version":3,"file":"reactivity.js","names":[],"sources":["../src/reactivity.ts"],"sourcesContent":["import {\n computed,\n getCurrentScope,\n onScopeDispose,\n shallowRef,\n watch,\n} from 'vue'\nimport { batch, createAtom } from '@tanstack/vue-store'\nimport type {\n TableAtomOptions,\n TableReactivityBindings,\n} from '@tanstack/table-core/reactivity'\nimport type { Atom, Observer, ReadonlyAtom } from '@tanstack/vue-store'\nimport type { ComputedRef, ShallowRef } from 'vue'\n\nconst optionsStoreDebugName = 'table/optionsStore'\n\nfunction observerToCallback<T>(\n observerOrNext: Observer<T> | ((value: T) => void),\n): (value: T) => void {\n return typeof observerOrNext === 'function'\n ? observerOrNext\n : (value) => observerOrNext.next?.(value)\n}\n\nfunction refToReadonlyAtom<T>(\n source: ComputedRef<T> | ShallowRef<T>,\n): ReadonlyAtom<T> {\n return Object.assign(source, {\n get: () => source.value,\n subscribe: ((observerOrNext: Observer<T> | ((value: T) => void)) => {\n const stop = watch(source, observerToCallback(observerOrNext), {\n flush: 'sync',\n })\n return { unsubscribe: stop }\n }) as ReadonlyAtom<T>['subscribe'],\n })\n}\n\nfunction refToWritableAtom<T>(source: ShallowRef<T>): Atom<T> {\n return Object.assign(source, {\n set: (updater: T | ((prevVal: T) => T)) => {\n source.value =\n typeof updater === 'function'\n ? (updater as (prevVal: T) => T)(source.value)\n : updater\n },\n get: () => source.value,\n subscribe: ((observerOrNext: Observer<T> | ((value: T) => void)) => {\n const stop = watch(source, observerToCallback(observerOrNext), {\n flush: 'sync',\n })\n return { unsubscribe: stop }\n }) as Atom<T>['subscribe'],\n })\n}\n\n/**\n * Creates the table-core reactivity bindings used by the Vue adapter.\n *\n * Table state atoms are backed by TanStack Store atoms. The options store stays\n * framework-native because row-model APIs read `table.options` directly during\n * render. Readonly table atoms bridge Store dependency tracking into Vue computed\n * refs.\n */\nexport function vueReactivity(): TableReactivityBindings {\n return {\n createOptionsStore: true,\n wrapExternalAtoms: false,\n addSubscription: () => {\n throw new Error(\n 'Feature not supported in current reactivity implementation',\n )\n },\n unmount: () => {\n throw new Error(\n 'Feature not supported in current reactivity implementation',\n )\n },\n schedule: (fn) => queueMicrotask(() => fn()),\n createReadonlyAtom: <T>(fn: () => T, _options?: TableAtomOptions<T>) => {\n const storeAtom = createAtom(() => fn(), {\n compare: _options?.compare,\n })\n const version = shallowRef(0)\n const subscription = storeAtom.subscribe(() => {\n version.value += 1\n })\n if (getCurrentScope()) {\n onScopeDispose(() => subscription.unsubscribe())\n }\n\n return refToReadonlyAtom(\n computed(() => {\n version.value\n return storeAtom.get()\n }),\n )\n },\n createWritableAtom: <T>(\n value: T,\n _options?: TableAtomOptions<T>,\n ): Atom<T> => {\n if (_options?.debugName === optionsStoreDebugName) {\n return refToWritableAtom(shallowRef(value) as ShallowRef<T>)\n }\n\n return createAtom(value, {\n compare: _options?.compare,\n })\n },\n untrack: (fn) => fn(),\n batch,\n }\n}\n"],"mappings":";;;;AAeA,MAAM,wBAAwB;AAE9B,SAAS,mBACP,gBACoB;CACpB,OAAO,OAAO,mBAAmB,aAC7B,kBACC,UAAU;;gDAAe,uGAAO,KAAK;;AAC5C;AAEA,SAAS,kBACP,QACiB;CACjB,OAAO,OAAO,OAAO,QAAQ;EAC3B,WAAW,OAAO;EAClB,aAAa,mBAAuD;GAIlE,OAAO,EAAE,aAHI,MAAM,QAAQ,mBAAmB,cAAc,GAAG,EAC7D,OAAO,OACT,CACyB,EAAE;EAC7B;CACF,CAAC;AACH;AAEA,SAAS,kBAAqB,QAAgC;CAC5D,OAAO,OAAO,OAAO,QAAQ;EAC3B,MAAM,YAAqC;GACzC,OAAO,QACL,OAAO,YAAY,aACd,QAA8B,OAAO,KAAK,IAC3C;EACR;EACA,WAAW,OAAO;EAClB,aAAa,mBAAuD;GAIlE,OAAO,EAAE,aAHI,MAAM,QAAQ,mBAAmB,cAAc,GAAG,EAC7D,OAAO,OACT,CACyB,EAAE;EAC7B;CACF,CAAC;AACH;;;;;;;;;AAUA,SAAgB,gBAAyC;CACvD,OAAO;EACL,oBAAoB;EACpB,mBAAmB;EACnB,uBAAuB;GACrB,MAAM,IAAI,MACR,4DACF;EACF;EACA,eAAe;GACb,MAAM,IAAI,MACR,4DACF;EACF;EACA,WAAW,OAAO,qBAAqB,GAAG,CAAC;EAC3C,qBAAwB,IAAa,aAAmC;GACtE,MAAM,YAAY,iBAAiB,GAAG,GAAG,EACvC,6DAAS,SAAU,QACrB,CAAC;GACD,MAAM,UAAU,WAAW,CAAC;GAC5B,MAAM,eAAe,UAAU,gBAAgB;IAC7C,QAAQ,SAAS;GACnB,CAAC;GACD,IAAI,gBAAgB,GAClB,qBAAqB,aAAa,YAAY,CAAC;GAGjD,OAAO,kBACL,eAAe;IACb,QAAQ;IACR,OAAO,UAAU,IAAI;GACvB,CAAC,CACH;EACF;EACA,qBACE,OACA,aACY;GACZ,yDAAI,SAAU,eAAc,uBAC1B,OAAO,kBAAkB,WAAW,KAAK,CAAkB;GAG7D,OAAO,WAAW,OAAO,EACvB,6DAAS,SAAU,QACrB,CAAC;EACH;EACA,UAAU,OAAO,GAAG;EACpB;CACF;AACF"}
|
package/dist/useTable.cjs
CHANGED
|
@@ -38,14 +38,14 @@ function getReactiveOptionDeps(options) {
|
|
|
38
38
|
*/
|
|
39
39
|
function useTable(tableOptions, selector) {
|
|
40
40
|
const syncTableOptions = (table, options) => {
|
|
41
|
-
table.setOptions(() => getOptionsWithReactiveValues(options));
|
|
41
|
+
table.setOptions((prev) => require_merge_proxy.flatMerge(prev, getOptionsWithReactiveValues(options)));
|
|
42
42
|
};
|
|
43
43
|
const mergedOptions = require_merge_proxy.mergeProxy(tableOptions, { _features: {
|
|
44
44
|
coreReativityFeature: require_reactivity.vueReactivity(),
|
|
45
45
|
...(0, vue.unref)(tableOptions._features) ?? {}
|
|
46
46
|
} });
|
|
47
47
|
const coreTable = (0, _tanstack_table_core.constructTable)(require_merge_proxy.mergeProxy(getOptionsWithReactiveValues(mergedOptions), { mergeOptions: (defaultOptions, newOptions) => {
|
|
48
|
-
return require_merge_proxy.
|
|
48
|
+
return require_merge_proxy.flatMerge(defaultOptions, newOptions);
|
|
49
49
|
} }));
|
|
50
50
|
const table = coreTable;
|
|
51
51
|
(0, vue.watch)(() => getReactiveOptionDeps(mergedOptions), () => {
|
package/dist/useTable.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useTable.cjs","names":["mergeProxy","vueReactivity","shallow"],"sources":["../src/useTable.ts"],"sourcesContent":["import { unref, watch } from 'vue'\nimport { constructTable } from '@tanstack/table-core'\nimport { shallow, useSelector } from '@tanstack/vue-store'\nimport { 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(
|
|
1
|
+
{"version":3,"file":"useTable.cjs","names":["mergeProxy","flatMerge","vueReactivity","shallow"],"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,sBACd,QAAQ,IACV;CAGF,OAAOA,+BAAW,SAAS,eAAe;AAC5C;AAEA,SAAS,sBAGP,SAAyD;CACzD,OAAO,OAAO,KAAK,OAAO,EAAE,KAAK,uBACzB,QAAQ,IAA4D,CAC5E;AACF;;;;;;;;;;;;;;;;;;;;;;;;AAiFA,SAAgB,SAKd,cAGA,UACuC;CACvC,MAAM,oBACJ,OACA,YACG;EACH,MAAM,YAAY,SAChBC,8BAAU,MAAM,6BAA6B,OAAO,CAAC,CACvD;CACF;CAEA,MAAM,gBAAgBD,+BAAW,cAAc,EAC7C,WAAW;EACT,sBAAsBE,iCAAc;EACpC,kBAAU,aAAa,SAAS,KAAK,CAAC;CACxC,EACF,CAAC;CAeD,MAAM,qDAbkBF,+BACtB,6BAA6B,aAAa,GAC1C,EAEE,eACE,gBACA,eACG;EACH,OAAOC,8BAAU,gBAAgB,UAAU;CAC7C,EACF,CAG6C,CAAC;CAChD,MAAM,QAAQ;CAEd,qBACQ,sBAAsB,aAAa,SACnC;EACJ,iBAAiB,WAAW,aAAa;CAC3C,GACA,EAAE,WAAW,KAAK,CACpB;CAEA,qBACQ;EACJ,MAAM,iCAAwB,aAAa,KAAK;EAGhD,MAAM,iCAAwB,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,gDADS,MAAM,UAAU,MAAM,OACS,MAAM,UAAmB,EACrE,SAASE,4BACX,CAAC;EACD,IAAI,OAAO,MAAM,aAAa,YAC5B,OAAO,MAAM,SAAS,SAAS,KAA0B;EAE3D,OAAO,MAAM;CACf;CAEA,MAAM,kDAAyB,MAAM,OAAO,QAAQ;CAEpD,OAAO;EACL,GAAG;EACH,IAAI,QAAQ;GACV,OAAO,WAAW;EACpB;CACF;AACF"}
|
package/dist/useTable.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { mergeProxy } from "./merge-proxy.js";
|
|
1
|
+
import { flatMerge, mergeProxy } from "./merge-proxy.js";
|
|
2
2
|
import { vueReactivity } from "./reactivity.js";
|
|
3
3
|
import { unref, watch } from "vue";
|
|
4
4
|
import { constructTable } from "@tanstack/table-core";
|
|
@@ -38,14 +38,14 @@ function getReactiveOptionDeps(options) {
|
|
|
38
38
|
*/
|
|
39
39
|
function useTable(tableOptions, selector) {
|
|
40
40
|
const syncTableOptions = (table, options) => {
|
|
41
|
-
table.setOptions(() => getOptionsWithReactiveValues(options));
|
|
41
|
+
table.setOptions((prev) => flatMerge(prev, getOptionsWithReactiveValues(options)));
|
|
42
42
|
};
|
|
43
43
|
const mergedOptions = mergeProxy(tableOptions, { _features: {
|
|
44
44
|
coreReativityFeature: vueReactivity(),
|
|
45
45
|
...unref(tableOptions._features) ?? {}
|
|
46
46
|
} });
|
|
47
47
|
const coreTable = constructTable(mergeProxy(getOptionsWithReactiveValues(mergedOptions), { mergeOptions: (defaultOptions, newOptions) => {
|
|
48
|
-
return
|
|
48
|
+
return flatMerge(defaultOptions, newOptions);
|
|
49
49
|
} }));
|
|
50
50
|
const table = coreTable;
|
|
51
51
|
watch(() => getReactiveOptionDeps(mergedOptions), () => {
|
package/dist/useTable.js.map
CHANGED
|
@@ -1 +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 { 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(
|
|
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,EAAE,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,WAAW;EACT,sBAAsB,cAAc;EACpC,GAAI,MAAM,aAAa,SAAS,KAAK,CAAC;CACxC,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.
|
|
3
|
+
"version": "9.0.0-alpha.53",
|
|
4
4
|
"description": "Headless UI for building powerful tables & datagrids for Vue.",
|
|
5
5
|
"author": "Tanner Linsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
],
|
|
52
52
|
"dependencies": {
|
|
53
53
|
"@tanstack/vue-store": "^0.11.0",
|
|
54
|
-
"@tanstack/table-core": "9.0.0-alpha.
|
|
54
|
+
"@tanstack/table-core": "9.0.0-alpha.53"
|
|
55
55
|
},
|
|
56
56
|
"devDependencies": {
|
|
57
57
|
"@vitejs/plugin-vue": "^6.0.7",
|
package/src/merge-proxy.ts
CHANGED
|
@@ -53,7 +53,7 @@ type MergeProxy<T extends Array<any>> = UnboxIntersection<
|
|
|
53
53
|
>
|
|
54
54
|
|
|
55
55
|
function resolveSource(s: any) {
|
|
56
|
-
return 'value' in s ? s.value : s
|
|
56
|
+
return s && typeof s === 'object' && 'value' in s ? s.value : s
|
|
57
57
|
}
|
|
58
58
|
|
|
59
59
|
export function mergeProxy<T extends Array<any>>(...sources: T): MergeProxy<T>
|
|
@@ -96,3 +96,37 @@ export function mergeProxy(...sources: any): any {
|
|
|
96
96
|
propTraps,
|
|
97
97
|
)
|
|
98
98
|
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Merges objects together by eagerly resolving all values into a flat object.
|
|
102
|
+
*
|
|
103
|
+
* Unlike `mergeProxy`, this does not preserve lazy proxy getters. Use this for
|
|
104
|
+
* repeated option update paths so each merge produces a plain object instead
|
|
105
|
+
* of accumulating a longer source list over time.
|
|
106
|
+
*/
|
|
107
|
+
export function flatMerge<T>(source: T): T
|
|
108
|
+
export function flatMerge<T, U>(source: T, source1: U): T & U
|
|
109
|
+
export function flatMerge<T, U, V>(source: T, source1: U, source2: V): T & U & V
|
|
110
|
+
export function flatMerge<T, U, V, W>(
|
|
111
|
+
source: T,
|
|
112
|
+
source1: U,
|
|
113
|
+
source2: V,
|
|
114
|
+
source3: W,
|
|
115
|
+
): T & U & V & W
|
|
116
|
+
export function flatMerge(...sources: any): any {
|
|
117
|
+
const result: Record<PropertyKey, unknown> = {}
|
|
118
|
+
|
|
119
|
+
for (let source of sources) {
|
|
120
|
+
source = resolveSource(source)
|
|
121
|
+
if (!source) continue
|
|
122
|
+
|
|
123
|
+
for (const key of Reflect.ownKeys(source)) {
|
|
124
|
+
const value = (source as Record<PropertyKey, unknown>)[key]
|
|
125
|
+
if (value !== undefined) {
|
|
126
|
+
result[key] = value
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
return result
|
|
132
|
+
}
|
package/src/reactivity.ts
CHANGED
|
@@ -66,6 +66,17 @@ function refToWritableAtom<T>(source: ShallowRef<T>): Atom<T> {
|
|
|
66
66
|
export function vueReactivity(): TableReactivityBindings {
|
|
67
67
|
return {
|
|
68
68
|
createOptionsStore: true,
|
|
69
|
+
wrapExternalAtoms: false,
|
|
70
|
+
addSubscription: () => {
|
|
71
|
+
throw new Error(
|
|
72
|
+
'Feature not supported in current reactivity implementation',
|
|
73
|
+
)
|
|
74
|
+
},
|
|
75
|
+
unmount: () => {
|
|
76
|
+
throw new Error(
|
|
77
|
+
'Feature not supported in current reactivity implementation',
|
|
78
|
+
)
|
|
79
|
+
},
|
|
69
80
|
schedule: (fn) => queueMicrotask(() => fn()),
|
|
70
81
|
createReadonlyAtom: <T>(fn: () => T, _options?: TableAtomOptions<T>) => {
|
|
71
82
|
const storeAtom = createAtom(() => fn(), {
|
package/src/useTable.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { unref, watch } from 'vue'
|
|
2
2
|
import { constructTable } from '@tanstack/table-core'
|
|
3
3
|
import { shallow, useSelector } from '@tanstack/vue-store'
|
|
4
|
-
import { mergeProxy } from './merge-proxy'
|
|
4
|
+
import { flatMerge, mergeProxy } from './merge-proxy'
|
|
5
5
|
import { vueReactivity } from './reactivity'
|
|
6
6
|
import type {
|
|
7
7
|
Atom,
|
|
@@ -151,9 +151,8 @@ export function useTable<
|
|
|
151
151
|
table: Table<TFeatures, TData>,
|
|
152
152
|
options: TableOptionsWithReactiveData<TFeatures, TData>,
|
|
153
153
|
) => {
|
|
154
|
-
table.setOptions(
|
|
155
|
-
()
|
|
156
|
-
getOptionsWithReactiveValues(options) as TableOptions<TFeatures, TData>,
|
|
154
|
+
table.setOptions((prev) =>
|
|
155
|
+
flatMerge(prev, getOptionsWithReactiveValues(options)),
|
|
157
156
|
)
|
|
158
157
|
}
|
|
159
158
|
|
|
@@ -172,7 +171,7 @@ export function useTable<
|
|
|
172
171
|
defaultOptions: TableOptions<TFeatures, TData>,
|
|
173
172
|
newOptions: Partial<TableOptions<TFeatures, TData>>,
|
|
174
173
|
) => {
|
|
175
|
-
return
|
|
174
|
+
return flatMerge(defaultOptions, newOptions)
|
|
176
175
|
},
|
|
177
176
|
},
|
|
178
177
|
) as TableOptions<TFeatures, TData>
|