@tanstack/form-core 0.1.3 → 0.3.0
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/package.json +23 -12
- package/src/FieldApi.ts +53 -29
- package/src/FormApi.ts +14 -7
- package/src/tests/FieldApi.spec.ts +84 -17
- package/src/utils.ts +4 -0
- package/build/lib/FieldApi.cjs +0 -293
- package/build/lib/FieldApi.cjs.map +0 -1
- package/build/lib/FieldApi.d.ts +0 -95
- package/build/lib/FieldApi.d.ts.map +0 -1
- package/build/lib/FieldApi.js +0 -291
- package/build/lib/FieldApi.js.map +0 -1
- package/build/lib/FieldApi.legacy.cjs +0 -293
- package/build/lib/FieldApi.legacy.cjs.map +0 -1
- package/build/lib/FieldApi.legacy.js +0 -291
- package/build/lib/FieldApi.legacy.js.map +0 -1
- package/build/lib/FormApi.cjs +0 -239
- package/build/lib/FormApi.cjs.map +0 -1
- package/build/lib/FormApi.d.ts +0 -78
- package/build/lib/FormApi.d.ts.map +0 -1
- package/build/lib/FormApi.js +0 -237
- package/build/lib/FormApi.js.map +0 -1
- package/build/lib/FormApi.legacy.cjs +0 -239
- package/build/lib/FormApi.legacy.cjs.map +0 -1
- package/build/lib/FormApi.legacy.js +0 -237
- package/build/lib/FormApi.legacy.js.map +0 -1
- package/build/lib/_virtual/_rollupPluginBabelHelpers.cjs +0 -65
- package/build/lib/_virtual/_rollupPluginBabelHelpers.cjs.map +0 -1
- package/build/lib/_virtual/_rollupPluginBabelHelpers.js +0 -56
- package/build/lib/_virtual/_rollupPluginBabelHelpers.js.map +0 -1
- package/build/lib/_virtual/_rollupPluginBabelHelpers.legacy.cjs +0 -65
- package/build/lib/_virtual/_rollupPluginBabelHelpers.legacy.cjs.map +0 -1
- package/build/lib/_virtual/_rollupPluginBabelHelpers.legacy.js +0 -56
- package/build/lib/_virtual/_rollupPluginBabelHelpers.legacy.js.map +0 -1
- package/build/lib/index.cjs +0 -14
- package/build/lib/index.cjs.map +0 -1
- package/build/lib/index.d.ts +0 -4
- package/build/lib/index.d.ts.map +0 -1
- package/build/lib/index.js +0 -4
- package/build/lib/index.js.map +0 -1
- package/build/lib/index.legacy.cjs +0 -14
- package/build/lib/index.legacy.cjs.map +0 -1
- package/build/lib/index.legacy.js +0 -4
- package/build/lib/index.legacy.js.map +0 -1
- package/build/lib/tests/FieldApi.spec.d.ts +0 -2
- package/build/lib/tests/FieldApi.spec.d.ts.map +0 -1
- package/build/lib/tests/FieldApi.test-d.d.ts +0 -2
- package/build/lib/tests/FieldApi.test-d.d.ts.map +0 -1
- package/build/lib/tests/FormApi.spec.d.ts +0 -2
- package/build/lib/tests/FormApi.spec.d.ts.map +0 -1
- package/build/lib/tests/utils.d.ts +0 -2
- package/build/lib/tests/utils.d.ts.map +0 -1
- package/build/lib/utils.cjs +0 -81
- package/build/lib/utils.cjs.map +0 -1
- package/build/lib/utils.d.ts +0 -32
- package/build/lib/utils.d.ts.map +0 -1
- package/build/lib/utils.js +0 -77
- package/build/lib/utils.js.map +0 -1
- package/build/lib/utils.legacy.cjs +0 -81
- package/build/lib/utils.legacy.cjs.map +0 -1
- package/build/lib/utils.legacy.js +0 -77
- package/build/lib/utils.legacy.js.map +0 -1
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
function functionalUpdate(updater, input) {
|
|
2
|
-
return typeof updater === 'function' ? updater(input) : updater;
|
|
3
|
-
}
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Get a value from an object using a path, including dot notation.
|
|
7
|
-
*/
|
|
8
|
-
function getBy(obj, path) {
|
|
9
|
-
const pathArray = makePathArray(path);
|
|
10
|
-
const pathObj = pathArray;
|
|
11
|
-
return pathObj.reduce((current, pathPart) => {
|
|
12
|
-
if (typeof current !== 'undefined') {
|
|
13
|
-
return current[pathPart];
|
|
14
|
-
}
|
|
15
|
-
return undefined;
|
|
16
|
-
}, obj);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Set a value on an object using a path, including dot notation.
|
|
21
|
-
*/
|
|
22
|
-
function setBy(obj, _path, updater) {
|
|
23
|
-
const path = makePathArray(_path);
|
|
24
|
-
function doSet(parent) {
|
|
25
|
-
if (!path.length) {
|
|
26
|
-
return functionalUpdate(updater, parent);
|
|
27
|
-
}
|
|
28
|
-
const key = path.shift();
|
|
29
|
-
if (typeof key === 'string') {
|
|
30
|
-
if (typeof parent === 'object') {
|
|
31
|
-
return {
|
|
32
|
-
...parent,
|
|
33
|
-
[key]: doSet(parent[key])
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
return {
|
|
37
|
-
[key]: doSet()
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
if (typeof key === 'number') {
|
|
41
|
-
if (Array.isArray(parent)) {
|
|
42
|
-
const prefix = parent.slice(0, key);
|
|
43
|
-
return [...(prefix.length ? prefix : new Array(key)), doSet(parent[key]), ...parent.slice(key + 1)];
|
|
44
|
-
}
|
|
45
|
-
return [...new Array(key), doSet()];
|
|
46
|
-
}
|
|
47
|
-
throw new Error('Uh oh!');
|
|
48
|
-
}
|
|
49
|
-
return doSet(obj);
|
|
50
|
-
}
|
|
51
|
-
const reFindNumbers0 = /^(\d*)$/gm;
|
|
52
|
-
const reFindNumbers1 = /\.(\d*)\./gm;
|
|
53
|
-
const reFindNumbers2 = /^(\d*)\./gm;
|
|
54
|
-
const reFindNumbers3 = /\.(\d*$)/gm;
|
|
55
|
-
const reFindMultiplePeriods = /\.{2,}/gm;
|
|
56
|
-
const intPrefix = '__int__';
|
|
57
|
-
const intReplace = intPrefix + "$1";
|
|
58
|
-
function makePathArray(str) {
|
|
59
|
-
if (typeof str !== 'string') {
|
|
60
|
-
throw new Error('Path must be a string.');
|
|
61
|
-
}
|
|
62
|
-
return str.replace('[', '.').replace(']', '').replace(reFindNumbers0, intReplace).replace(reFindNumbers1, "." + intReplace + ".").replace(reFindNumbers2, intReplace + ".").replace(reFindNumbers3, "." + intReplace).replace(reFindMultiplePeriods, '.').split('.').map(d => {
|
|
63
|
-
if (d.indexOf(intPrefix) === 0) {
|
|
64
|
-
return parseInt(d.substring(intPrefix.length), 10);
|
|
65
|
-
}
|
|
66
|
-
return d;
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
// Is this type a tuple?
|
|
71
|
-
|
|
72
|
-
// If this type is a tuple, what indices are allowed?
|
|
73
|
-
|
|
74
|
-
// Hack to get TypeScript to show simplified types in error messages
|
|
75
|
-
|
|
76
|
-
export { functionalUpdate, getBy, setBy };
|
|
77
|
-
//# sourceMappingURL=utils.legacy.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.legacy.js","sources":["../../src/utils.ts"],"sourcesContent":["export type UpdaterFn<TInput, TOutput = TInput> = (input: TInput) => TOutput\n\nexport type Updater<TInput, TOutput = TInput> =\n | TOutput\n | UpdaterFn<TInput, TOutput>\n\nexport function functionalUpdate<TInput, TOutput = TInput>(\n updater: Updater<TInput, TOutput>,\n input: TInput,\n): TOutput {\n return typeof updater === 'function'\n ? (updater as UpdaterFn<TInput, TOutput>)(input)\n : updater\n}\n\n/**\n * Get a value from an object using a path, including dot notation.\n */\nexport function getBy(obj: any, path: any) {\n const pathArray = makePathArray(path)\n const pathObj = pathArray\n return pathObj.reduce((current: any, pathPart: any) => {\n if (typeof current !== 'undefined') {\n return current[pathPart]\n }\n return undefined\n }, obj)\n}\n\n/**\n * Set a value on an object using a path, including dot notation.\n */\nexport function setBy(obj: any, _path: any, updater: Updater<any>) {\n const path = makePathArray(_path)\n\n function doSet(parent?: any): any {\n if (!path.length) {\n return functionalUpdate(updater, parent)\n }\n\n const key = path.shift()\n\n if (typeof key === 'string') {\n if (typeof parent === 'object') {\n return {\n ...parent,\n [key]: doSet(parent[key]),\n }\n }\n return {\n [key]: doSet(),\n }\n }\n\n if (typeof key === 'number') {\n if (Array.isArray(parent)) {\n const prefix = parent.slice(0, key)\n return [\n ...(prefix.length ? prefix : new Array(key)),\n doSet(parent[key]),\n ...parent.slice(key + 1),\n ]\n }\n return [...new Array(key), doSet()]\n }\n\n throw new Error('Uh oh!')\n }\n\n return doSet(obj)\n}\n\nconst reFindNumbers0 = /^(\\d*)$/gm\nconst reFindNumbers1 = /\\.(\\d*)\\./gm\nconst reFindNumbers2 = /^(\\d*)\\./gm\nconst reFindNumbers3 = /\\.(\\d*$)/gm\nconst reFindMultiplePeriods = /\\.{2,}/gm\n\nconst intPrefix = '__int__'\nconst intReplace = `${intPrefix}$1`\n\nfunction makePathArray(str: string) {\n if (typeof str !== 'string') {\n throw new Error('Path must be a string.')\n }\n\n return str\n .replace('[', '.')\n .replace(']', '')\n .replace(reFindNumbers0, intReplace)\n .replace(reFindNumbers1, `.${intReplace}.`)\n .replace(reFindNumbers2, `${intReplace}.`)\n .replace(reFindNumbers3, `.${intReplace}`)\n .replace(reFindMultiplePeriods, '.')\n .split('.')\n .map((d) => {\n if (d.indexOf(intPrefix) === 0) {\n return parseInt(d.substring(intPrefix.length), 10)\n }\n return d\n })\n}\n\nexport type RequiredByKey<T, K extends keyof T> = Omit<T, K> &\n Required<Pick<T, K>>\n\ntype ComputeRange<\n N extends number,\n Result extends Array<unknown> = [],\n> = Result['length'] extends N\n ? Result\n : ComputeRange<N, [...Result, Result['length']]>\ntype Index40 = ComputeRange<40>[number]\n\n// Is this type a tuple?\ntype IsTuple<T> = T extends readonly any[] & { length: infer Length }\n ? Length extends Index40\n ? T\n : never\n : never\n\n// If this type is a tuple, what indices are allowed?\ntype AllowedIndexes<\n Tuple extends ReadonlyArray<any>,\n Keys extends number = never,\n> = Tuple extends readonly []\n ? Keys\n : Tuple extends readonly [infer _, ...infer Tail]\n ? AllowedIndexes<Tail, Keys | Tail['length']>\n : Keys\n\nexport type DeepKeys<T> = unknown extends T\n ? keyof T\n : object extends T\n ? string\n : T extends readonly any[] & IsTuple<T>\n ? AllowedIndexes<T> | DeepKeysPrefix<T, AllowedIndexes<T>>\n : T extends any[]\n ? DeepKeys<T[number]>\n : T extends Date\n ? never\n : T extends object\n ? (keyof T & string) | DeepKeysPrefix<T, keyof T>\n : never\n\ntype DeepKeysPrefix<T, TPrefix> = TPrefix extends keyof T & (number | string)\n ? `${TPrefix}.${DeepKeys<T[TPrefix]> & string}`\n : never\n\nexport type DeepValue<T, TProp> = T extends Record<string | number, any>\n ? TProp extends `${infer TBranch}.${infer TDeepProp}`\n ? DeepValue<T[TBranch], TDeepProp>\n : T[TProp & string]\n : never\n\ntype Narrowable = string | number | bigint | boolean\n\ntype NarrowRaw<A> =\n | (A extends [] ? [] : never)\n | (A extends Narrowable ? A : never)\n | {\n [K in keyof A]: A[K] extends Function ? A[K] : NarrowRaw<A[K]>\n }\n\nexport type Narrow<A> = Try<A, [], NarrowRaw<A>>\n\ntype Try<A1, A2, Catch = never> = A1 extends A2 ? A1 : Catch\n\n// Hack to get TypeScript to show simplified types in error messages\nexport type Pretty<T> = { [K in keyof T]: T[K] } & {}\n"],"names":["functionalUpdate","updater","input","getBy","obj","path","pathArray","makePathArray","pathObj","reduce","current","pathPart","undefined","setBy","_path","doSet","parent","length","key","shift","Array","isArray","prefix","slice","Error","reFindNumbers0","reFindNumbers1","reFindNumbers2","reFindNumbers3","reFindMultiplePeriods","intPrefix","intReplace","str","replace","split","map","d","indexOf","parseInt","substring"],"mappings":"AAMO,SAASA,gBAAgBA,CAC9BC,OAAiC,EACjCC,KAAa,EACJ;EACT,OAAO,OAAOD,OAAO,KAAK,UAAU,GAC/BA,OAAO,CAAgCC,KAAK,CAAC,GAC9CD,OAAO,CAAA;AACb,CAAA;;AAEA;AACA;AACA;AACO,SAASE,KAAKA,CAACC,GAAQ,EAAEC,IAAS,EAAE;AACzC,EAAA,MAAMC,SAAS,GAAGC,aAAa,CAACF,IAAI,CAAC,CAAA;EACrC,MAAMG,OAAO,GAAGF,SAAS,CAAA;EACzB,OAAOE,OAAO,CAACC,MAAM,CAAC,CAACC,OAAY,EAAEC,QAAa,KAAK;AACrD,IAAA,IAAI,O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