@tanstack/vue-form 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.
@@ -1,10 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const formCore = require("@tanstack/form-core");
4
- const createFormFactory = require("./createFormFactory.cjs");
5
4
  const useField = require("./useField.cjs");
6
5
  const useForm = require("./useForm.cjs");
7
- exports.createFormFactory = createFormFactory.createFormFactory;
8
6
  exports.Field = useField.Field;
9
7
  exports.useField = useField.useField;
10
8
  exports.useForm = useForm.useForm;
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;"}
@@ -1,4 +1,3 @@
1
1
  export * from '@tanstack/form-core';
2
- export * from './createFormFactory.cjs';
3
2
  export * from './useField.cjs';
4
3
  export * from './useForm.cjs';
@@ -1,4 +1,3 @@
1
1
  export * from '@tanstack/form-core';
2
- export * from './createFormFactory.js';
3
2
  export * from './useField.js';
4
3
  export * from './useForm.js';
package/dist/esm/index.js CHANGED
@@ -1,10 +1,8 @@
1
1
  export * from "@tanstack/form-core";
2
- import { createFormFactory } from "./createFormFactory.js";
3
2
  import { Field, useField } from "./useField.js";
4
3
  import { useForm } from "./useForm.js";
5
4
  export {
6
5
  Field,
7
- createFormFactory,
8
6
  useField,
9
7
  useForm
10
8
  };
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;"}
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/vue-form",
3
- "version": "0.21.1",
3
+ "version": "0.23.0",
4
4
  "description": "Powerful, type-safe forms for Vue.",
5
5
  "author": "tannerlinsley",
6
6
  "license": "MIT",
@@ -34,7 +34,7 @@
34
34
  ],
35
35
  "dependencies": {
36
36
  "@tanstack/vue-store": "^0.4.1",
37
- "@tanstack/form-core": "0.21.1"
37
+ "@tanstack/form-core": "0.23.0"
38
38
  },
39
39
  "devDependencies": {
40
40
  "@vitejs/plugin-vue": "^5.0.4",
package/src/index.ts CHANGED
@@ -1,4 +1,3 @@
1
1
  export * from '@tanstack/form-core'
2
- export * from './createFormFactory'
3
2
  export * from './useField'
4
3
  export * from './useForm'
@@ -3,7 +3,7 @@ import { defineComponent, h } from 'vue'
3
3
  import { render, waitFor } from '@testing-library/vue'
4
4
  import '@testing-library/jest-dom/vitest'
5
5
  import userEvent from '@testing-library/user-event'
6
- import { createFormFactory, useForm } from '../index'
6
+ import { useForm } from '../index'
7
7
  import { sleep } from './utils'
8
8
  import type { FieldApi } from '../index'
9
9
 
@@ -16,10 +16,8 @@ describe('useField', () => {
16
16
  lastName: string
17
17
  }
18
18
 
19
- const formFactory = createFormFactory<Person>()
20
-
21
19
  const Comp = defineComponent(() => {
22
- const form = formFactory.useForm()
20
+ const form = useForm<Person>()
23
21
 
24
22
  return () => (
25
23
  <form.Field name="firstName" defaultValue="FirstName">
@@ -53,10 +51,8 @@ describe('useField', () => {
53
51
  }
54
52
  const error = 'Please enter a different value'
55
53
 
56
- const formFactory = createFormFactory<Person>()
57
-
58
54
  const Comp = defineComponent(() => {
59
- const form = formFactory.useForm()
55
+ const form = useForm<Person>()
60
56
 
61
57
  return () => (
62
58
  <form.Field
@@ -100,10 +96,8 @@ describe('useField', () => {
100
96
  }
101
97
  const error = 'Please enter a different value'
102
98
 
103
- const formFactory = createFormFactory<Person>()
104
-
105
99
  const Comp = defineComponent(() => {
106
- const form = formFactory.useForm()
100
+ const form = useForm<Person>()
107
101
 
108
102
  return () => (
109
103
  <form.Field
@@ -148,10 +142,8 @@ describe('useField', () => {
148
142
  }
149
143
  const error = 'Please enter a different value'
150
144
 
151
- const formFactory = createFormFactory<Person>()
152
-
153
145
  const Comp = defineComponent(() => {
154
- const form = formFactory.useForm()
146
+ const form = useForm<Person>()
155
147
 
156
148
  return () => (
157
149
  <form.Field
@@ -202,10 +194,9 @@ describe('useField', () => {
202
194
 
203
195
  const mockFn = vi.fn()
204
196
  const error = 'Please enter a different value'
205
- const formFactory = createFormFactory<Person>()
206
197
 
207
198
  const Comp = defineComponent(() => {
208
- const form = formFactory.useForm()
199
+ const form = useForm<Person>()
209
200
 
210
201
  return () => (
211
202
  <form.Field
@@ -2,7 +2,7 @@ import { describe, expect, it, vi } from 'vitest'
2
2
  import userEvent from '@testing-library/user-event'
3
3
  import { render, waitFor } from '@testing-library/vue'
4
4
  import { defineComponent, h, ref } from 'vue'
5
- import { createFormFactory, useForm } from '../index'
5
+ import { useForm } from '../index'
6
6
  import { sleep } from './utils'
7
7
 
8
8
  import type { FieldApi, ValidationErrorMap } from '../index'
@@ -16,10 +16,8 @@ type Person = {
16
16
 
17
17
  describe('useForm', () => {
18
18
  it('preserved field state', async () => {
19
- const formFactory = createFormFactory<Person>()
20
-
21
19
  const Comp = defineComponent(() => {
22
- const form = formFactory.useForm()
20
+ const form = useForm<Person>()
23
21
 
24
22
  return () => (
25
23
  <form.Field name="firstName" defaultValue="">
@@ -49,14 +47,12 @@ describe('useForm', () => {
49
47
  })
50
48
 
51
49
  it('should allow default values to be set', async () => {
52
- const formFactory = createFormFactory<Person>()
53
-
54
50
  const Comp = defineComponent(() => {
55
- const form = formFactory.useForm({
51
+ const form = useForm({
56
52
  defaultValues: {
57
53
  firstName: 'FirstName',
58
54
  lastName: 'LastName',
59
- },
55
+ } as Person,
60
56
  })
61
57
 
62
58
  return () => (
@@ -161,10 +157,8 @@ describe('useForm', () => {
161
157
  it('should validate async on change for the form', async () => {
162
158
  const error = 'Please enter a different value'
163
159
 
164
- const formFactory = createFormFactory<Person>()
165
-
166
160
  const Comp = defineComponent(() => {
167
- const form = formFactory.useForm({
161
+ const form = useForm<Person>({
168
162
  validators: {
169
163
  onChange() {
170
164
  return error
@@ -208,10 +202,8 @@ describe('useForm', () => {
208
202
  it('should not validate on change if isTouched is false', async () => {
209
203
  const error = 'Please enter a different value'
210
204
 
211
- const formFactory = createFormFactory<Person>()
212
-
213
205
  const Comp = defineComponent(() => {
214
- const form = formFactory.useForm({
206
+ const form = useForm<Person>({
215
207
  validators: {
216
208
  onChange: ({ value }) =>
217
209
  value.firstName === 'other' ? error : undefined,
@@ -255,10 +247,8 @@ describe('useForm', () => {
255
247
  it('should validate on change if isTouched is true', async () => {
256
248
  const error = 'Please enter a different value'
257
249
 
258
- const formFactory = createFormFactory<Person>()
259
-
260
250
  const Comp = defineComponent(() => {
261
- const form = formFactory.useForm({
251
+ const form = useForm<Person>({
262
252
  validators: {
263
253
  onChange: ({ value }) =>
264
254
  value.firstName === 'other' ? error : undefined,
@@ -362,10 +352,8 @@ describe('useForm', () => {
362
352
  it('should validate async on change', async () => {
363
353
  const error = 'Please enter a different value'
364
354
 
365
- const formFactory = createFormFactory<Person>()
366
-
367
355
  const Comp = defineComponent(() => {
368
- const form = formFactory.useForm({
356
+ const form = useForm<Person>({
369
357
  validators: {
370
358
  onChangeAsync: async () => {
371
359
  await sleep(10)
@@ -414,10 +402,8 @@ describe('useForm', () => {
414
402
  const onChangeError = 'Please enter a different value (onChangeError)'
415
403
  const onBlurError = 'Please enter a different value (onBlurError)'
416
404
 
417
- const formFactory = createFormFactory<Person>()
418
-
419
405
  const Comp = defineComponent(() => {
420
- const form = formFactory.useForm({
406
+ const form = useForm<Person>({
421
407
  validators: {
422
408
  onChangeAsync: async () => {
423
409
  await sleep(10)
@@ -474,10 +460,9 @@ describe('useForm', () => {
474
460
  it('should validate async on change with debounce', async () => {
475
461
  const mockFn = vi.fn()
476
462
  const error = 'Please enter a different value'
477
- const formFactory = createFormFactory<Person>()
478
463
 
479
464
  const Comp = defineComponent(() => {
480
- const form = formFactory.useForm({
465
+ const form = useForm<Person>({
481
466
  validators: {
482
467
  onChangeAsyncDebounceMs: 100,
483
468
  onChangeAsync: async () => {
@@ -1,16 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const useField = require("./useField.cjs");
4
- const useForm = require("./useForm.cjs");
5
- function createFormFactory(defaultOpts) {
6
- return {
7
- useForm: (opts) => {
8
- const formOptions = Object.assign({}, defaultOpts, opts);
9
- return useForm.useForm(formOptions);
10
- },
11
- useField: useField.useField,
12
- Field: useField.Field
13
- };
14
- }
15
- exports.createFormFactory = createFormFactory;
16
- //# sourceMappingURL=createFormFactory.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"createFormFactory.cjs","sources":["../../src/createFormFactory.ts"],"sourcesContent":["import { Field, useField } from './useField'\nimport { useForm } from './useForm'\nimport type { FormApi, FormOptions, Validator } from '@tanstack/form-core'\nimport type { FieldComponent, UseField } from './useField'\n\nexport type FormFactory<\n TFormData,\n TFormValidator extends Validator<TFormData, unknown> | undefined = undefined,\n> = {\n useForm: (\n opts?: FormOptions<TFormData, TFormValidator>,\n ) => FormApi<TFormData, TFormValidator>\n useField: typeof useField\n Field: typeof Field\n}\n\nexport function createFormFactory<\n TFormData,\n TFormValidator extends Validator<TFormData, unknown> | undefined = undefined,\n>(\n defaultOpts?: FormOptions<TFormData, TFormValidator>,\n): FormFactory<TFormData, TFormValidator> {\n return {\n useForm: (opts) => {\n const formOptions = Object.assign({}, defaultOpts, opts)\n return useForm<TFormData, TFormValidator>(formOptions)\n },\n useField: useField,\n Field: Field,\n }\n}\n"],"names":["useForm","useField","Field"],"mappings":";;;;AAgBO,SAAS,kBAId,aACwC;AACjC,SAAA;AAAA,IACL,SAAS,CAAC,SAAS;AACjB,YAAM,cAAc,OAAO,OAAO,CAAA,GAAI,aAAa,IAAI;AACvD,aAAOA,QAAAA,QAAmC,WAAW;AAAA,IACvD;AAAA,IAAA,UACAC,SAAA;AAAA,IAAA,OACAC,SAAA;AAAA,EAAA;AAEJ;;"}
@@ -1,9 +0,0 @@
1
- import { Field, useField } from './useField.cjs';
2
- import { FormApi, FormOptions, Validator } from '@tanstack/form-core';
3
-
4
- export type FormFactory<TFormData, TFormValidator extends Validator<TFormData, unknown> | undefined = undefined> = {
5
- useForm: (opts?: FormOptions<TFormData, TFormValidator>) => FormApi<TFormData, TFormValidator>;
6
- useField: typeof useField;
7
- Field: typeof Field;
8
- };
9
- export declare function createFormFactory<TFormData, TFormValidator extends Validator<TFormData, unknown> | undefined = undefined>(defaultOpts?: FormOptions<TFormData, TFormValidator>): FormFactory<TFormData, TFormValidator>;
@@ -1,9 +0,0 @@
1
- import { Field, useField } from './useField.js';
2
- import { FormApi, FormOptions, Validator } from '@tanstack/form-core';
3
-
4
- export type FormFactory<TFormData, TFormValidator extends Validator<TFormData, unknown> | undefined = undefined> = {
5
- useForm: (opts?: FormOptions<TFormData, TFormValidator>) => FormApi<TFormData, TFormValidator>;
6
- useField: typeof useField;
7
- Field: typeof Field;
8
- };
9
- export declare function createFormFactory<TFormData, TFormValidator extends Validator<TFormData, unknown> | undefined = undefined>(defaultOpts?: FormOptions<TFormData, TFormValidator>): FormFactory<TFormData, TFormValidator>;
@@ -1,16 +0,0 @@
1
- import { useField, Field } from "./useField.js";
2
- import { useForm } from "./useForm.js";
3
- function createFormFactory(defaultOpts) {
4
- return {
5
- useForm: (opts) => {
6
- const formOptions = Object.assign({}, defaultOpts, opts);
7
- return useForm(formOptions);
8
- },
9
- useField,
10
- Field
11
- };
12
- }
13
- export {
14
- createFormFactory
15
- };
16
- //# sourceMappingURL=createFormFactory.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"createFormFactory.js","sources":["../../src/createFormFactory.ts"],"sourcesContent":["import { Field, useField } from './useField'\nimport { useForm } from './useForm'\nimport type { FormApi, FormOptions, Validator } from '@tanstack/form-core'\nimport type { FieldComponent, UseField } from './useField'\n\nexport type FormFactory<\n TFormData,\n TFormValidator extends Validator<TFormData, unknown> | undefined = undefined,\n> = {\n useForm: (\n opts?: FormOptions<TFormData, TFormValidator>,\n ) => FormApi<TFormData, TFormValidator>\n useField: typeof useField\n Field: typeof Field\n}\n\nexport function createFormFactory<\n TFormData,\n TFormValidator extends Validator<TFormData, unknown> | undefined = undefined,\n>(\n defaultOpts?: FormOptions<TFormData, TFormValidator>,\n): FormFactory<TFormData, TFormValidator> {\n return {\n useForm: (opts) => {\n const formOptions = Object.assign({}, defaultOpts, opts)\n return useForm<TFormData, TFormValidator>(formOptions)\n },\n useField: useField,\n Field: Field,\n }\n}\n"],"names":[],"mappings":";;AAgBO,SAAS,kBAId,aACwC;AACjC,SAAA;AAAA,IACL,SAAS,CAAC,SAAS;AACjB,YAAM,cAAc,OAAO,OAAO,CAAA,GAAI,aAAa,IAAI;AACvD,aAAO,QAAmC,WAAW;AAAA,IACvD;AAAA,IACA;AAAA,IACA;AAAA,EAAA;AAEJ;"}
@@ -1,31 +0,0 @@
1
- import { Field, useField } from './useField'
2
- import { useForm } from './useForm'
3
- import type { FormApi, FormOptions, Validator } from '@tanstack/form-core'
4
- import type { FieldComponent, UseField } from './useField'
5
-
6
- export type FormFactory<
7
- TFormData,
8
- TFormValidator extends Validator<TFormData, unknown> | undefined = undefined,
9
- > = {
10
- useForm: (
11
- opts?: FormOptions<TFormData, TFormValidator>,
12
- ) => FormApi<TFormData, TFormValidator>
13
- useField: typeof useField
14
- Field: typeof Field
15
- }
16
-
17
- export function createFormFactory<
18
- TFormData,
19
- TFormValidator extends Validator<TFormData, unknown> | undefined = undefined,
20
- >(
21
- defaultOpts?: FormOptions<TFormData, TFormValidator>,
22
- ): FormFactory<TFormData, TFormValidator> {
23
- return {
24
- useForm: (opts) => {
25
- const formOptions = Object.assign({}, defaultOpts, opts)
26
- return useForm<TFormData, TFormValidator>(formOptions)
27
- },
28
- useField: useField,
29
- Field: Field,
30
- }
31
- }