@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.
- package/dist/cjs/index.cjs +0 -2
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +0 -1
- package/dist/esm/index.d.ts +0 -1
- package/dist/esm/index.js +0 -2
- package/dist/esm/index.js.map +1 -1
- package/package.json +2 -2
- package/src/index.ts +0 -1
- package/src/tests/useField.test.tsx +6 -15
- package/src/tests/useForm.test.tsx +10 -25
- package/dist/cjs/createFormFactory.cjs +0 -16
- package/dist/cjs/createFormFactory.cjs.map +0 -1
- package/dist/cjs/createFormFactory.d.cts +0 -9
- package/dist/esm/createFormFactory.d.ts +0 -9
- package/dist/esm/createFormFactory.js +0 -16
- package/dist/esm/createFormFactory.js.map +0 -1
- package/src/createFormFactory.ts +0 -31
package/dist/cjs/index.cjs
CHANGED
@@ -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;
|
package/dist/cjs/index.cjs.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;"}
|
package/dist/cjs/index.d.cts
CHANGED
package/dist/esm/index.d.ts
CHANGED
package/dist/esm/index.js
CHANGED
package/dist/esm/index.js.map
CHANGED
@@ -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.
|
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.
|
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
@@ -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 {
|
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 =
|
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 =
|
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 =
|
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 =
|
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 =
|
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 {
|
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 =
|
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 =
|
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 =
|
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 =
|
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 =
|
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 =
|
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 =
|
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 =
|
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;"}
|
package/src/createFormFactory.ts
DELETED
@@ -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
|
-
}
|