@teamnovu/kit-vue-forms 0.2.1 → 0.2.3
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.
|
@@ -3,16 +3,14 @@ import { z } from 'zod';
|
|
|
3
3
|
import { Form, FormDataDefault } from '../types/form';
|
|
4
4
|
import { ValidationStrategy } from '../types/validation';
|
|
5
5
|
import { ValidationOptions } from './useValidation';
|
|
6
|
-
import { DeepPartial } from '../utils/type-helpers';
|
|
7
6
|
export interface UseFormOptions<T extends FormDataDefault, TOut = T> extends ValidationOptions<T, TOut> {
|
|
8
7
|
initialData: MaybeRefOrGetter<T>;
|
|
9
8
|
validationStrategy?: MaybeRef<ValidationStrategy>;
|
|
10
9
|
keepValuesOnUnmount?: MaybeRef<boolean>;
|
|
11
10
|
}
|
|
12
|
-
export declare function useForm<
|
|
13
|
-
schema:
|
|
14
|
-
|
|
15
|
-
}): Form<z.input<TSchema>, z.output<TSchema>>;
|
|
11
|
+
export declare function useForm<T extends FormDataDefault, TOut = T>(options: UseFormOptions<T, TOut> & {
|
|
12
|
+
schema: z.ZodType<TOut, T>;
|
|
13
|
+
}): Form<T, TOut>;
|
|
16
14
|
export declare function useForm<T extends FormDataDefault>(options: Omit<UseFormOptions<T, T>, 'schema'> & {
|
|
17
15
|
schema?: undefined;
|
|
18
16
|
}): Form<T, T>;
|
package/package.json
CHANGED
|
@@ -19,7 +19,6 @@ import { useFieldRegistry } from './useFieldRegistry'
|
|
|
19
19
|
import { useFormState } from './useFormState'
|
|
20
20
|
import { createSubformInterface } from './useSubform'
|
|
21
21
|
import { useValidation, type ValidationOptions } from './useValidation'
|
|
22
|
-
import type { DeepPartial } from '../utils/type-helpers'
|
|
23
22
|
|
|
24
23
|
export interface UseFormOptions<T extends FormDataDefault, TOut = T>
|
|
25
24
|
extends ValidationOptions<T, TOut> {
|
|
@@ -31,12 +30,10 @@ export interface UseFormOptions<T extends FormDataDefault, TOut = T>
|
|
|
31
30
|
/* eslint-disable no-redeclare */
|
|
32
31
|
// Overload: with schema - infer types from schema
|
|
33
32
|
// initialData can be partial, but provided fields must match schema types
|
|
34
|
-
export function useForm<
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
},
|
|
39
|
-
): Form<z.input<TSchema>, z.output<TSchema>>
|
|
33
|
+
export function useForm<
|
|
34
|
+
T extends FormDataDefault,
|
|
35
|
+
TOut = T,
|
|
36
|
+
>(options: UseFormOptions<T, TOut> & { schema: z.ZodType<TOut, T> }): Form<T, TOut>
|
|
40
37
|
|
|
41
38
|
// Overload: without schema - infer types from initialData
|
|
42
39
|
export function useForm<T extends FormDataDefault>(
|
package/tests/nestedPath.test.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { nextTick } from 'vue'
|
|
|
3
3
|
import { z } from 'zod'
|
|
4
4
|
import { useForm } from '../src/composables/useForm'
|
|
5
5
|
import { isValidResult } from '../src/utils/validation'
|
|
6
|
+
import { FormField } from '../src'
|
|
6
7
|
|
|
7
8
|
describe('Nested Path Handling', () => {
|
|
8
9
|
interface TestFormData {
|
|
@@ -556,7 +557,7 @@ describe('Nested Path Handling', () => {
|
|
|
556
557
|
it('should handle large numbers of nested fields', () => {
|
|
557
558
|
const form = useForm({ initialData })
|
|
558
559
|
|
|
559
|
-
const fields = []
|
|
560
|
+
const fields: FormField<string, string>[] = []
|
|
560
561
|
|
|
561
562
|
// Create many nested fields
|
|
562
563
|
for (let i = 0; i < 100; i++) {
|
package/tests/useField.test.ts
CHANGED
package/tests/useForm.test.ts
CHANGED
|
@@ -4,8 +4,6 @@ import { z } from 'zod'
|
|
|
4
4
|
import { useForm } from '../src/composables/useForm'
|
|
5
5
|
import { isValidResult } from '../src/utils/validation'
|
|
6
6
|
|
|
7
|
-
const scope = effectScope()
|
|
8
|
-
|
|
9
7
|
describe('useForm', () => {
|
|
10
8
|
it('should initialize form with initial data', () => {
|
|
11
9
|
const initialData = {
|
|
@@ -481,7 +479,7 @@ describe('useForm', () => {
|
|
|
481
479
|
{ timeout: 500 },
|
|
482
480
|
async () => {
|
|
483
481
|
const initialData = ref({
|
|
484
|
-
name:
|
|
482
|
+
name: undefined as undefined | number,
|
|
485
483
|
})
|
|
486
484
|
|
|
487
485
|
const schema = z.object({
|
|
@@ -307,10 +307,14 @@ describe('useValidation', () => {
|
|
|
307
307
|
it('should not validate other fields than the blurred one', async () => {
|
|
308
308
|
const schema = z.object({
|
|
309
309
|
name: z.string().min(2),
|
|
310
|
-
email: z.
|
|
310
|
+
email: z.email(),
|
|
311
311
|
})
|
|
312
312
|
|
|
313
|
-
const initialData = {
|
|
313
|
+
const initialData = {
|
|
314
|
+
name: 'A',
|
|
315
|
+
email: 'invalid-email',
|
|
316
|
+
}
|
|
317
|
+
|
|
314
318
|
const form = useForm({
|
|
315
319
|
initialData,
|
|
316
320
|
schema,
|