@tanstack/form-core 0.21.1 → 0.23.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.
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ function formOptions(defaultOpts) {
4
+ return defaultOpts;
5
+ }
6
+ exports.formOptions = formOptions;
7
+ //# sourceMappingURL=formOptions.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"formOptions.cjs","sources":["../../src/formOptions.ts"],"sourcesContent":["import type { Validator } from './types'\nimport type { FormOptions } from './FormApi'\n\nexport function formOptions<\n TFormData,\n TFormValidator extends Validator<TFormData, unknown> | undefined = undefined,\n>(defaultOpts?: FormOptions<TFormData, TFormValidator>) {\n return defaultOpts\n}\n"],"names":[],"mappings":";;AAGO,SAAS,YAGd,aAAsD;AAC/C,SAAA;AACT;;"}
@@ -0,0 +1,4 @@
1
+ import { Validator } from './types.cjs';
2
+ import { FormOptions } from './FormApi.cjs';
3
+
4
+ export declare function formOptions<TFormData, TFormValidator extends Validator<TFormData, unknown> | undefined = undefined>(defaultOpts?: FormOptions<TFormData, TFormValidator>): FormOptions<TFormData, TFormValidator> | undefined;
@@ -4,6 +4,7 @@ const FormApi = require("./FormApi.cjs");
4
4
  const FieldApi = require("./FieldApi.cjs");
5
5
  const utils = require("./utils.cjs");
6
6
  const mergeForm = require("./mergeForm.cjs");
7
+ const formOptions = require("./formOptions.cjs");
7
8
  exports.FormApi = FormApi.FormApi;
8
9
  exports.FieldApi = FieldApi.FieldApi;
9
10
  exports.deleteBy = utils.deleteBy;
@@ -16,4 +17,5 @@ exports.makePathArray = utils.makePathArray;
16
17
  exports.setBy = utils.setBy;
17
18
  exports.mergeForm = mergeForm.mergeForm;
18
19
  exports.mutateMergeDeep = mergeForm.mutateMergeDeep;
20
+ exports.formOptions = formOptions.formOptions;
19
21
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;"}
@@ -4,3 +4,4 @@ export * from './utils.cjs';
4
4
  export * from './util-types.cjs';
5
5
  export * from './types.cjs';
6
6
  export * from './mergeForm.cjs';
7
+ export * from './formOptions.cjs';
@@ -1 +1 @@
1
- {"version":3,"file":"mergeForm.cjs","sources":["../../src/mergeForm.ts"],"sourcesContent":["import type { FormApi } from './FormApi'\nimport type { Validator } from './types'\n\nexport function mutateMergeDeep(target: object, source: object): object {\n const targetKeys = Object.keys(target)\n const sourceKeys = Object.keys(source)\n const keySet = new Set([...targetKeys, ...sourceKeys])\n for (const key of keySet) {\n const targetKey = key as never as keyof typeof target\n const sourceKey = key as never as keyof typeof source\n if (Array.isArray(target[targetKey]) && Array.isArray(source[sourceKey])) {\n target[targetKey] = [\n ...(target[targetKey] as []),\n ...(source[sourceKey] as []),\n ] as never\n } else if (\n typeof target[targetKey] === 'object' &&\n typeof source[sourceKey] === 'object'\n ) {\n mutateMergeDeep(target[targetKey] as {}, source[sourceKey] as {})\n } else {\n // Prevent assigning undefined to target, only if undefined is not explicitly set on source\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n if (!(sourceKey in source) && source[sourceKey] === undefined) {\n continue\n }\n target[targetKey] = source[sourceKey] as never\n }\n }\n return target\n}\n\nexport function mergeForm<\n TFormData,\n TFormValidator extends Validator<TFormData, unknown> | undefined = undefined,\n>(\n baseForm: FormApi<TFormData, TFormValidator>,\n state: Partial<FormApi<TFormData, TFormValidator>['state']>,\n) {\n mutateMergeDeep(baseForm.state, state)\n return baseForm\n}\n"],"names":[],"mappings":";;AAGgB,SAAA,gBAAgB,QAAgB,QAAwB;AAChE,QAAA,aAAa,OAAO,KAAK,MAAM;AAC/B,QAAA,aAAa,OAAO,KAAK,MAAM;AAC/B,QAAA,6BAAa,IAAI,CAAC,GAAG,YAAY,GAAG,UAAU,CAAC;AACrD,aAAW,OAAO,QAAQ;AACxB,UAAM,YAAY;AAClB,UAAM,YAAY;AACd,QAAA,MAAM,QAAQ,OAAO,SAAS,CAAC,KAAK,MAAM,QAAQ,OAAO,SAAS,CAAC,GAAG;AACxE,aAAO,SAAS,IAAI;AAAA,QAClB,GAAI,OAAO,SAAS;AAAA,QACpB,GAAI,OAAO,SAAS;AAAA,MAAA;AAAA,IACtB,WAEA,OAAO,OAAO,SAAS,MAAM,YAC7B,OAAO,OAAO,SAAS,MAAM,UAC7B;AACA,sBAAgB,OAAO,SAAS,GAAS,OAAO,SAAS,CAAO;AAAA,IAAA,OAC3D;AAGL,UAAI,EAAE,aAAa,WAAW,OAAO,SAAS,MAAM,QAAW;AAC7D;AAAA,MACF;AACO,aAAA,SAAS,IAAI,OAAO,SAAS;AAAA,IACtC;AAAA,EACF;AACO,SAAA;AACT;AAEgB,SAAA,UAId,UACA,OACA;AACgB,kBAAA,SAAS,OAAO,KAAK;AAC9B,SAAA;AACT;;;"}
1
+ {"version":3,"file":"mergeForm.cjs","sources":["../../src/mergeForm.ts"],"sourcesContent":["import type { FormApi } from './FormApi'\nimport type { Validator } from './types'\nimport type { NoInfer } from './util-types'\n\nexport function mutateMergeDeep(target: object, source: object): object {\n const targetKeys = Object.keys(target)\n const sourceKeys = Object.keys(source)\n const keySet = new Set([...targetKeys, ...sourceKeys])\n for (const key of keySet) {\n const targetKey = key as never as keyof typeof target\n const sourceKey = key as never as keyof typeof source\n if (Array.isArray(target[targetKey]) && Array.isArray(source[sourceKey])) {\n target[targetKey] = [\n ...(target[targetKey] as []),\n ...(source[sourceKey] as []),\n ] as never\n } else if (\n typeof target[targetKey] === 'object' &&\n typeof source[sourceKey] === 'object'\n ) {\n mutateMergeDeep(target[targetKey] as {}, source[sourceKey] as {})\n } else {\n // Prevent assigning undefined to target, only if undefined is not explicitly set on source\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n if (!(sourceKey in source) && source[sourceKey] === undefined) {\n continue\n }\n target[targetKey] = source[sourceKey] as never\n }\n }\n return target\n}\n\nexport function mergeForm<\n TFormData,\n TFormValidator extends Validator<TFormData, unknown> | undefined = undefined,\n>(\n baseForm: FormApi<NoInfer<TFormData>, NoInfer<TFormValidator>>,\n state: Partial<FormApi<TFormData, TFormValidator>['state']>,\n) {\n mutateMergeDeep(baseForm.state, state)\n return baseForm\n}\n"],"names":[],"mappings":";;AAIgB,SAAA,gBAAgB,QAAgB,QAAwB;AAChE,QAAA,aAAa,OAAO,KAAK,MAAM;AAC/B,QAAA,aAAa,OAAO,KAAK,MAAM;AAC/B,QAAA,6BAAa,IAAI,CAAC,GAAG,YAAY,GAAG,UAAU,CAAC;AACrD,aAAW,OAAO,QAAQ;AACxB,UAAM,YAAY;AAClB,UAAM,YAAY;AACd,QAAA,MAAM,QAAQ,OAAO,SAAS,CAAC,KAAK,MAAM,QAAQ,OAAO,SAAS,CAAC,GAAG;AACxE,aAAO,SAAS,IAAI;AAAA,QAClB,GAAI,OAAO,SAAS;AAAA,QACpB,GAAI,OAAO,SAAS;AAAA,MAAA;AAAA,IACtB,WAEA,OAAO,OAAO,SAAS,MAAM,YAC7B,OAAO,OAAO,SAAS,MAAM,UAC7B;AACA,sBAAgB,OAAO,SAAS,GAAS,OAAO,SAAS,CAAO;AAAA,IAAA,OAC3D;AAGL,UAAI,EAAE,aAAa,WAAW,OAAO,SAAS,MAAM,QAAW;AAC7D;AAAA,MACF;AACO,aAAA,SAAS,IAAI,OAAO,SAAS;AAAA,IACtC;AAAA,EACF;AACO,SAAA;AACT;AAEgB,SAAA,UAId,UACA,OACA;AACgB,kBAAA,SAAS,OAAO,KAAK;AAC9B,SAAA;AACT;;;"}
@@ -1,5 +1,6 @@
1
1
  import { FormApi } from './FormApi.cjs';
2
2
  import { Validator } from './types.cjs';
3
+ import { NoInfer } from './util-types.cjs';
3
4
 
4
5
  export declare function mutateMergeDeep(target: object, source: object): object;
5
- export declare function mergeForm<TFormData, TFormValidator extends Validator<TFormData, unknown> | undefined = undefined>(baseForm: FormApi<TFormData, TFormValidator>, state: Partial<FormApi<TFormData, TFormValidator>['state']>): FormApi<TFormData, TFormValidator>;
6
+ export declare function mergeForm<TFormData, TFormValidator extends Validator<TFormData, unknown> | undefined = undefined>(baseForm: FormApi<NoInfer<TFormData>, NoInfer<TFormValidator>>, state: Partial<FormApi<TFormData, TFormValidator>['state']>): FormApi<NoInfer<TFormData>, NoInfer<TFormValidator>>;
@@ -0,0 +1,4 @@
1
+ import { Validator } from './types.js';
2
+ import { FormOptions } from './FormApi.js';
3
+
4
+ export declare function formOptions<TFormData, TFormValidator extends Validator<TFormData, unknown> | undefined = undefined>(defaultOpts?: FormOptions<TFormData, TFormValidator>): FormOptions<TFormData, TFormValidator> | undefined;
@@ -0,0 +1,7 @@
1
+ function formOptions(defaultOpts) {
2
+ return defaultOpts;
3
+ }
4
+ export {
5
+ formOptions
6
+ };
7
+ //# sourceMappingURL=formOptions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"formOptions.js","sources":["../../src/formOptions.ts"],"sourcesContent":["import type { Validator } from './types'\nimport type { FormOptions } from './FormApi'\n\nexport function formOptions<\n TFormData,\n TFormValidator extends Validator<TFormData, unknown> | undefined = undefined,\n>(defaultOpts?: FormOptions<TFormData, TFormValidator>) {\n return defaultOpts\n}\n"],"names":[],"mappings":"AAGO,SAAS,YAGd,aAAsD;AAC/C,SAAA;AACT;"}
@@ -4,3 +4,4 @@ export * from './utils.js';
4
4
  export * from './util-types.js';
5
5
  export * from './types.js';
6
6
  export * from './mergeForm.js';
7
+ export * from './formOptions.js';
package/dist/esm/index.js CHANGED
@@ -2,10 +2,12 @@ import { FormApi } from "./FormApi.js";
2
2
  import { FieldApi } from "./FieldApi.js";
3
3
  import { deleteBy, functionalUpdate, getAsyncValidatorArray, getBy, getSyncValidatorArray, isNonEmptyArray, makePathArray, setBy } from "./utils.js";
4
4
  import { mergeForm, mutateMergeDeep } from "./mergeForm.js";
5
+ import { formOptions } from "./formOptions.js";
5
6
  export {
6
7
  FieldApi,
7
8
  FormApi,
8
9
  deleteBy,
10
+ formOptions,
9
11
  functionalUpdate,
10
12
  getAsyncValidatorArray,
11
13
  getBy,
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;"}
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;"}
@@ -1,5 +1,6 @@
1
1
  import { FormApi } from './FormApi.js';
2
2
  import { Validator } from './types.js';
3
+ import { NoInfer } from './util-types.js';
3
4
 
4
5
  export declare function mutateMergeDeep(target: object, source: object): object;
5
- export declare function mergeForm<TFormData, TFormValidator extends Validator<TFormData, unknown> | undefined = undefined>(baseForm: FormApi<TFormData, TFormValidator>, state: Partial<FormApi<TFormData, TFormValidator>['state']>): FormApi<TFormData, TFormValidator>;
6
+ export declare function mergeForm<TFormData, TFormValidator extends Validator<TFormData, unknown> | undefined = undefined>(baseForm: FormApi<NoInfer<TFormData>, NoInfer<TFormValidator>>, state: Partial<FormApi<TFormData, TFormValidator>['state']>): FormApi<NoInfer<TFormData>, NoInfer<TFormValidator>>;
@@ -1 +1 @@
1
- {"version":3,"file":"mergeForm.js","sources":["../../src/mergeForm.ts"],"sourcesContent":["import type { FormApi } from './FormApi'\nimport type { Validator } from './types'\n\nexport function mutateMergeDeep(target: object, source: object): object {\n const targetKeys = Object.keys(target)\n const sourceKeys = Object.keys(source)\n const keySet = new Set([...targetKeys, ...sourceKeys])\n for (const key of keySet) {\n const targetKey = key as never as keyof typeof target\n const sourceKey = key as never as keyof typeof source\n if (Array.isArray(target[targetKey]) && Array.isArray(source[sourceKey])) {\n target[targetKey] = [\n ...(target[targetKey] as []),\n ...(source[sourceKey] as []),\n ] as never\n } else if (\n typeof target[targetKey] === 'object' &&\n typeof source[sourceKey] === 'object'\n ) {\n mutateMergeDeep(target[targetKey] as {}, source[sourceKey] as {})\n } else {\n // Prevent assigning undefined to target, only if undefined is not explicitly set on source\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n if (!(sourceKey in source) && source[sourceKey] === undefined) {\n continue\n }\n target[targetKey] = source[sourceKey] as never\n }\n }\n return target\n}\n\nexport function mergeForm<\n TFormData,\n TFormValidator extends Validator<TFormData, unknown> | undefined = undefined,\n>(\n baseForm: FormApi<TFormData, TFormValidator>,\n state: Partial<FormApi<TFormData, TFormValidator>['state']>,\n) {\n mutateMergeDeep(baseForm.state, state)\n return baseForm\n}\n"],"names":[],"mappings":"AAGgB,SAAA,gBAAgB,QAAgB,QAAwB;AAChE,QAAA,aAAa,OAAO,KAAK,MAAM;AAC/B,QAAA,aAAa,OAAO,KAAK,MAAM;AAC/B,QAAA,6BAAa,IAAI,CAAC,GAAG,YAAY,GAAG,UAAU,CAAC;AACrD,aAAW,OAAO,QAAQ;AACxB,UAAM,YAAY;AAClB,UAAM,YAAY;AACd,QAAA,MAAM,QAAQ,OAAO,SAAS,CAAC,KAAK,MAAM,QAAQ,OAAO,SAAS,CAAC,GAAG;AACxE,aAAO,SAAS,IAAI;AAAA,QAClB,GAAI,OAAO,SAAS;AAAA,QACpB,GAAI,OAAO,SAAS;AAAA,MAAA;AAAA,IACtB,WAEA,OAAO,OAAO,SAAS,MAAM,YAC7B,OAAO,OAAO,SAAS,MAAM,UAC7B;AACA,sBAAgB,OAAO,SAAS,GAAS,OAAO,SAAS,CAAO;AAAA,IAAA,OAC3D;AAGL,UAAI,EAAE,aAAa,WAAW,OAAO,SAAS,MAAM,QAAW;AAC7D;AAAA,MACF;AACO,aAAA,SAAS,IAAI,OAAO,SAAS;AAAA,IACtC;AAAA,EACF;AACO,SAAA;AACT;AAEgB,SAAA,UAId,UACA,OACA;AACgB,kBAAA,SAAS,OAAO,KAAK;AAC9B,SAAA;AACT;"}
1
+ {"version":3,"file":"mergeForm.js","sources":["../../src/mergeForm.ts"],"sourcesContent":["import type { FormApi } from './FormApi'\nimport type { Validator } from './types'\nimport type { NoInfer } from './util-types'\n\nexport function mutateMergeDeep(target: object, source: object): object {\n const targetKeys = Object.keys(target)\n const sourceKeys = Object.keys(source)\n const keySet = new Set([...targetKeys, ...sourceKeys])\n for (const key of keySet) {\n const targetKey = key as never as keyof typeof target\n const sourceKey = key as never as keyof typeof source\n if (Array.isArray(target[targetKey]) && Array.isArray(source[sourceKey])) {\n target[targetKey] = [\n ...(target[targetKey] as []),\n ...(source[sourceKey] as []),\n ] as never\n } else if (\n typeof target[targetKey] === 'object' &&\n typeof source[sourceKey] === 'object'\n ) {\n mutateMergeDeep(target[targetKey] as {}, source[sourceKey] as {})\n } else {\n // Prevent assigning undefined to target, only if undefined is not explicitly set on source\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n if (!(sourceKey in source) && source[sourceKey] === undefined) {\n continue\n }\n target[targetKey] = source[sourceKey] as never\n }\n }\n return target\n}\n\nexport function mergeForm<\n TFormData,\n TFormValidator extends Validator<TFormData, unknown> | undefined = undefined,\n>(\n baseForm: FormApi<NoInfer<TFormData>, NoInfer<TFormValidator>>,\n state: Partial<FormApi<TFormData, TFormValidator>['state']>,\n) {\n mutateMergeDeep(baseForm.state, state)\n return baseForm\n}\n"],"names":[],"mappings":"AAIgB,SAAA,gBAAgB,QAAgB,QAAwB;AAChE,QAAA,aAAa,OAAO,KAAK,MAAM;AAC/B,QAAA,aAAa,OAAO,KAAK,MAAM;AAC/B,QAAA,6BAAa,IAAI,CAAC,GAAG,YAAY,GAAG,UAAU,CAAC;AACrD,aAAW,OAAO,QAAQ;AACxB,UAAM,YAAY;AAClB,UAAM,YAAY;AACd,QAAA,MAAM,QAAQ,OAAO,SAAS,CAAC,KAAK,MAAM,QAAQ,OAAO,SAAS,CAAC,GAAG;AACxE,aAAO,SAAS,IAAI;AAAA,QAClB,GAAI,OAAO,SAAS;AAAA,QACpB,GAAI,OAAO,SAAS;AAAA,MAAA;AAAA,IACtB,WAEA,OAAO,OAAO,SAAS,MAAM,YAC7B,OAAO,OAAO,SAAS,MAAM,UAC7B;AACA,sBAAgB,OAAO,SAAS,GAAS,OAAO,SAAS,CAAO;AAAA,IAAA,OAC3D;AAGL,UAAI,EAAE,aAAa,WAAW,OAAO,SAAS,MAAM,QAAW;AAC7D;AAAA,MACF;AACO,aAAA,SAAS,IAAI,OAAO,SAAS;AAAA,IACtC;AAAA,EACF;AACO,SAAA;AACT;AAEgB,SAAA,UAId,UACA,OACA;AACgB,kBAAA,SAAS,OAAO,KAAK;AAC9B,SAAA;AACT;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/form-core",
3
- "version": "0.21.1",
3
+ "version": "0.23.0",
4
4
  "description": "Powerful, type-safe, framework agnostic forms.",
5
5
  "author": "tannerlinsley",
6
6
  "license": "MIT",
@@ -0,0 +1,9 @@
1
+ import type { Validator } from './types'
2
+ import type { FormOptions } from './FormApi'
3
+
4
+ export function formOptions<
5
+ TFormData,
6
+ TFormValidator extends Validator<TFormData, unknown> | undefined = undefined,
7
+ >(defaultOpts?: FormOptions<TFormData, TFormValidator>) {
8
+ return defaultOpts
9
+ }
package/src/index.ts CHANGED
@@ -4,3 +4,4 @@ export * from './utils'
4
4
  export * from './util-types'
5
5
  export * from './types'
6
6
  export * from './mergeForm'
7
+ export * from './formOptions'
package/src/mergeForm.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import type { FormApi } from './FormApi'
2
2
  import type { Validator } from './types'
3
+ import type { NoInfer } from './util-types'
3
4
 
4
5
  export function mutateMergeDeep(target: object, source: object): object {
5
6
  const targetKeys = Object.keys(target)
@@ -34,7 +35,7 @@ export function mergeForm<
34
35
  TFormData,
35
36
  TFormValidator extends Validator<TFormData, unknown> | undefined = undefined,
36
37
  >(
37
- baseForm: FormApi<TFormData, TFormValidator>,
38
+ baseForm: FormApi<NoInfer<TFormData>, NoInfer<TFormValidator>>,
38
39
  state: Partial<FormApi<TFormData, TFormValidator>['state']>,
39
40
  ) {
40
41
  mutateMergeDeep(baseForm.state, state)
@@ -0,0 +1,25 @@
1
+ import { describe, expect, it } from 'vitest'
2
+ import { FormApi, formOptions } from '../index'
3
+
4
+ describe('formOptions', () => {
5
+ it('should allow default values to be set', async () => {
6
+ type Person = {
7
+ firstName: string
8
+ lastName: string
9
+ }
10
+
11
+ const formOpts = formOptions<Person>({
12
+ defaultValues: {
13
+ firstName: 'FirstName',
14
+ lastName: 'LastName',
15
+ },
16
+ })
17
+
18
+ const form = new FormApi({
19
+ ...formOpts,
20
+ })
21
+
22
+ expect(form.state.values['firstName']).toBe('FirstName')
23
+ expect(form.state.values['lastName']).toBe('LastName')
24
+ })
25
+ })