@vuehookform/core 0.4.2 → 0.4.4
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/README.md +53 -9
- package/package.json +7 -1
- package/dist/context.d.ts +0 -37
- package/dist/core/domSync.d.ts +0 -27
- package/dist/core/fieldState.d.ts +0 -53
- package/dist/core/formContext.d.ts +0 -117
- package/dist/core/useFieldArray.d.ts +0 -8
- package/dist/core/useFieldRegistration.d.ts +0 -9
- package/dist/core/useValidation.d.ts +0 -8
- package/dist/index.d.ts +0 -24
- package/dist/types.d.ts +0 -889
- package/dist/useController.d.ts +0 -63
- package/dist/useForm.d.ts +0 -20
- package/dist/useFormState.d.ts +0 -39
- package/dist/useWatch.d.ts +0 -46
- package/dist/utils/clone.d.ts +0 -19
- package/dist/utils/devWarnings.d.ts +0 -55
- package/dist/utils/hash.d.ts +0 -9
- package/dist/utils/modeChecks.d.ts +0 -22
- package/dist/utils/paths.d.ts +0 -53
- package/dist/utils/schemaExtract.d.ts +0 -42
- package/dist/vuehookform.cjs +0 -1823
- package/dist/vuehookform.js +0 -1809
package/dist/useController.d.ts
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { ComputedRef, Ref } from 'vue';
|
|
2
|
-
import { ZodType } from 'zod';
|
|
3
|
-
import { UseFormReturn, Path, PathValue, InferSchema, FieldState } from './types';
|
|
4
|
-
/**
|
|
5
|
-
* Options for useController composable
|
|
6
|
-
*/
|
|
7
|
-
export interface UseControllerOptions<TSchema extends ZodType, TPath extends Path<InferSchema<TSchema>>> {
|
|
8
|
-
/** Field name/path */
|
|
9
|
-
name: TPath;
|
|
10
|
-
/** Form control from useForm (uses context if not provided) */
|
|
11
|
-
control?: UseFormReturn<TSchema>;
|
|
12
|
-
/** Default value for the field */
|
|
13
|
-
defaultValue?: PathValue<InferSchema<TSchema>, TPath>;
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Field props returned by useController
|
|
17
|
-
*/
|
|
18
|
-
export interface ControllerFieldProps<TValue> {
|
|
19
|
-
/** Current field value */
|
|
20
|
-
value: Ref<TValue>;
|
|
21
|
-
/** Field name */
|
|
22
|
-
name: string;
|
|
23
|
-
/** Change handler - call with new value */
|
|
24
|
-
onChange: (value: TValue) => void;
|
|
25
|
-
/** Blur handler */
|
|
26
|
-
onBlur: () => void;
|
|
27
|
-
/** Ref callback for the input element */
|
|
28
|
-
ref: (el: HTMLElement | null) => void;
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Return value from useController
|
|
32
|
-
*/
|
|
33
|
-
export interface UseControllerReturn<TValue> {
|
|
34
|
-
/** Field props for binding to input components */
|
|
35
|
-
field: ControllerFieldProps<TValue>;
|
|
36
|
-
/** Current field state (errors, dirty, touched) */
|
|
37
|
-
fieldState: ComputedRef<FieldState>;
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Hook for controlled components that need fine-grained control over field state
|
|
41
|
-
*
|
|
42
|
-
* This composable is useful for integrating with custom input components or
|
|
43
|
-
* third-party UI libraries that don't work with the standard register() approach.
|
|
44
|
-
*
|
|
45
|
-
* @example
|
|
46
|
-
* ```ts
|
|
47
|
-
* // Basic usage with context
|
|
48
|
-
* const { field, fieldState } = useController({ name: 'email' })
|
|
49
|
-
*
|
|
50
|
-
* // With explicit control
|
|
51
|
-
* const { control } = useForm({ schema })
|
|
52
|
-
* const { field, fieldState } = useController({ control, name: 'email' })
|
|
53
|
-
*
|
|
54
|
-
* // In template:
|
|
55
|
-
* // <CustomInput
|
|
56
|
-
* // :value="field.value.value"
|
|
57
|
-
* // @update:modelValue="field.onChange"
|
|
58
|
-
* // @blur="field.onBlur"
|
|
59
|
-
* // />
|
|
60
|
-
* // <span v-if="fieldState.value.error">{{ fieldState.value.error }}</span>
|
|
61
|
-
* ```
|
|
62
|
-
*/
|
|
63
|
-
export declare function useController<TSchema extends ZodType, TPath extends Path<InferSchema<TSchema>>>(options: UseControllerOptions<TSchema, TPath>): UseControllerReturn<PathValue<InferSchema<TSchema>, TPath>>;
|
package/dist/useForm.d.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { ZodType } from 'zod';
|
|
2
|
-
import { UseFormOptions, UseFormReturn } from './types';
|
|
3
|
-
/**
|
|
4
|
-
* Main form management composable
|
|
5
|
-
*
|
|
6
|
-
* @example
|
|
7
|
-
* ```ts
|
|
8
|
-
* const schema = z.object({
|
|
9
|
-
* email: z.email(),
|
|
10
|
-
* name: z.string().min(2)
|
|
11
|
-
* })
|
|
12
|
-
*
|
|
13
|
-
* const { register, handleSubmit, formState } = useForm({ schema })
|
|
14
|
-
*
|
|
15
|
-
* const onSubmit = (data) => {
|
|
16
|
-
* console.log(data) // { email: '...', name: '...' }
|
|
17
|
-
* }
|
|
18
|
-
* ```
|
|
19
|
-
*/
|
|
20
|
-
export declare function useForm<TSchema extends ZodType>(options: UseFormOptions<TSchema>): UseFormReturn<TSchema>;
|
package/dist/useFormState.d.ts
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { ComputedRef } from 'vue';
|
|
2
|
-
import { ZodType } from 'zod';
|
|
3
|
-
import { UseFormReturn, FormState, InferSchema } from './types';
|
|
4
|
-
/**
|
|
5
|
-
* Keys of FormState that can be subscribed to
|
|
6
|
-
*/
|
|
7
|
-
export type FormStateKey = keyof FormState<unknown>;
|
|
8
|
-
/**
|
|
9
|
-
* Options for useFormState composable
|
|
10
|
-
*/
|
|
11
|
-
export interface UseFormStateOptions<TSchema extends ZodType> {
|
|
12
|
-
/** Form control from useForm (uses context if not provided) */
|
|
13
|
-
control?: UseFormReturn<TSchema>;
|
|
14
|
-
/** Specific state keys to subscribe to (subscribes to all if not provided) */
|
|
15
|
-
name?: FormStateKey | FormStateKey[];
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* Subscribe to specific form state properties
|
|
19
|
-
*
|
|
20
|
-
* This composable allows you to efficiently subscribe to only the form state
|
|
21
|
-
* properties you need, reducing unnecessary re-renders.
|
|
22
|
-
*
|
|
23
|
-
* @example
|
|
24
|
-
* ```ts
|
|
25
|
-
* // Subscribe to all form state
|
|
26
|
-
* const formState = useFormState({})
|
|
27
|
-
*
|
|
28
|
-
* // Subscribe to specific properties
|
|
29
|
-
* const { isSubmitting, errors } = useFormState({ name: ['isSubmitting', 'errors'] })
|
|
30
|
-
*
|
|
31
|
-
* // Subscribe to single property
|
|
32
|
-
* const isDirty = useFormState({ name: 'isDirty' })
|
|
33
|
-
*
|
|
34
|
-
* // With explicit control
|
|
35
|
-
* const { control } = useForm({ schema })
|
|
36
|
-
* const formState = useFormState({ control })
|
|
37
|
-
* ```
|
|
38
|
-
*/
|
|
39
|
-
export declare function useFormState<TSchema extends ZodType>(options?: UseFormStateOptions<TSchema>): ComputedRef<Partial<FormState<InferSchema<TSchema>>>>;
|
package/dist/useWatch.d.ts
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { ComputedRef } from 'vue';
|
|
2
|
-
import { ZodType } from 'zod';
|
|
3
|
-
import { UseFormReturn, Path, PathValue, InferSchema } from './types';
|
|
4
|
-
/**
|
|
5
|
-
* Options for useWatch composable
|
|
6
|
-
*/
|
|
7
|
-
export interface UseWatchOptions<TSchema extends ZodType, TPath extends Path<InferSchema<TSchema>>> {
|
|
8
|
-
/** Form control from useForm (uses context if not provided) */
|
|
9
|
-
control?: UseFormReturn<TSchema>;
|
|
10
|
-
/** Field path or array of paths to watch (watches all if not provided) */
|
|
11
|
-
name?: TPath | TPath[];
|
|
12
|
-
/** Default value when field is undefined */
|
|
13
|
-
defaultValue?: unknown;
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Watch form field values reactively without the full form instance
|
|
17
|
-
*
|
|
18
|
-
* This composable allows you to subscribe to form value changes from any component
|
|
19
|
-
* in the tree, as long as the form context is provided via provideForm().
|
|
20
|
-
*
|
|
21
|
-
* @example
|
|
22
|
-
* ```ts
|
|
23
|
-
* // Watch a single field
|
|
24
|
-
* const email = useWatch({ name: 'email' })
|
|
25
|
-
*
|
|
26
|
-
* // Watch multiple fields
|
|
27
|
-
* const fields = useWatch({ name: ['firstName', 'lastName'] })
|
|
28
|
-
*
|
|
29
|
-
* // Watch all form values
|
|
30
|
-
* const allValues = useWatch({})
|
|
31
|
-
*
|
|
32
|
-
* // With explicit control
|
|
33
|
-
* const { control } = useForm({ schema })
|
|
34
|
-
* const email = useWatch({ control, name: 'email' })
|
|
35
|
-
*
|
|
36
|
-
* // With default value
|
|
37
|
-
* const status = useWatch({ name: 'status', defaultValue: 'pending' })
|
|
38
|
-
* ```
|
|
39
|
-
*/
|
|
40
|
-
export declare function useWatch<TSchema extends ZodType>(options?: Omit<UseWatchOptions<TSchema, Path<InferSchema<TSchema>>>, 'name'>): ComputedRef<InferSchema<TSchema>>;
|
|
41
|
-
export declare function useWatch<TSchema extends ZodType, TPath extends Path<InferSchema<TSchema>>>(options: UseWatchOptions<TSchema, TPath> & {
|
|
42
|
-
name: TPath;
|
|
43
|
-
}): ComputedRef<PathValue<InferSchema<TSchema>, TPath>>;
|
|
44
|
-
export declare function useWatch<TSchema extends ZodType, TPath extends Path<InferSchema<TSchema>>>(options: UseWatchOptions<TSchema, TPath> & {
|
|
45
|
-
name: TPath[];
|
|
46
|
-
}): ComputedRef<Partial<InferSchema<TSchema>>>;
|
package/dist/utils/clone.d.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Deep clone utility for form values.
|
|
3
|
-
* Handles common types without JSON.parse/stringify overhead.
|
|
4
|
-
*
|
|
5
|
-
* Properly handles:
|
|
6
|
-
* - Primitives (pass-through)
|
|
7
|
-
* - Plain objects (recursive clone)
|
|
8
|
-
* - Arrays (recursive clone)
|
|
9
|
-
* - Date objects (new Date instance)
|
|
10
|
-
* - null/undefined (pass-through)
|
|
11
|
-
* - Circular references (recreates the circular structure in the clone)
|
|
12
|
-
*
|
|
13
|
-
* Does NOT handle (by design, not needed for form data):
|
|
14
|
-
* - Map/Set/WeakMap/WeakSet
|
|
15
|
-
* - Functions
|
|
16
|
-
* - Symbols
|
|
17
|
-
* - Class instances (cloned as plain objects)
|
|
18
|
-
*/
|
|
19
|
-
export declare function deepClone<T>(obj: T, seen?: Map<object, unknown>): T;
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { ZodType } from 'zod';
|
|
2
|
-
export declare const __DEV__: boolean;
|
|
3
|
-
/**
|
|
4
|
-
* Warn once per unique message (prevents spam on re-renders)
|
|
5
|
-
*/
|
|
6
|
-
export declare function warnOnce(message: string, key?: string): void;
|
|
7
|
-
/**
|
|
8
|
-
* Warn every time (for errors that should always be shown)
|
|
9
|
-
*/
|
|
10
|
-
export declare function warn(message: string): void;
|
|
11
|
-
/**
|
|
12
|
-
* Clear warning cache (useful for testing)
|
|
13
|
-
*/
|
|
14
|
-
export declare function clearWarningCache(): void;
|
|
15
|
-
/**
|
|
16
|
-
* Validate a dot-notation path string for common syntax errors
|
|
17
|
-
* @returns Error message or null if valid
|
|
18
|
-
*/
|
|
19
|
-
export declare function validatePathSyntax(path: string): string | null;
|
|
20
|
-
/**
|
|
21
|
-
* Check if a path exists in a Zod schema
|
|
22
|
-
* This is a runtime check to validate paths against the schema structure
|
|
23
|
-
*/
|
|
24
|
-
export declare function validatePathAgainstSchema(schema: ZodType, path: string): {
|
|
25
|
-
valid: boolean;
|
|
26
|
-
reason?: string;
|
|
27
|
-
availableFields?: string[];
|
|
28
|
-
};
|
|
29
|
-
/**
|
|
30
|
-
* Check if a path points to an array field in the schema
|
|
31
|
-
*/
|
|
32
|
-
export declare function isArrayFieldInSchema(schema: ZodType, path: string): boolean | null;
|
|
33
|
-
/**
|
|
34
|
-
* Warn about registering an invalid path with fix suggestion
|
|
35
|
-
*/
|
|
36
|
-
export declare function warnInvalidPath(fnName: string, path: string, reason: string): void;
|
|
37
|
-
/**
|
|
38
|
-
* Warn about path not in schema with suggestions
|
|
39
|
-
*/
|
|
40
|
-
export declare function warnPathNotInSchema(fnName: string, path: string, availableFields?: string[]): void;
|
|
41
|
-
/**
|
|
42
|
-
* Warn about calling fields() on non-array path
|
|
43
|
-
*/
|
|
44
|
-
export declare function warnFieldsOnNonArray(path: string): void;
|
|
45
|
-
/**
|
|
46
|
-
* Warn about silent field array operation failures
|
|
47
|
-
*/
|
|
48
|
-
export declare function warnArrayOperationRejected(operation: string, path: string, reason: 'maxLength' | 'minLength', details?: {
|
|
49
|
-
current: number;
|
|
50
|
-
limit: number;
|
|
51
|
-
}): void;
|
|
52
|
-
/**
|
|
53
|
-
* Warn about array operation with out of bounds index
|
|
54
|
-
*/
|
|
55
|
-
export declare function warnArrayIndexOutOfBounds(operation: string, path: string, index: number, length: number): void;
|
package/dist/utils/hash.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Fast value hashing for validation cache.
|
|
3
|
-
* Uses JSON.stringify for objects/arrays, direct conversion for primitives.
|
|
4
|
-
* Returns a string that can be compared for equality.
|
|
5
|
-
*
|
|
6
|
-
* Handles circular references by assigning stable IDs via WeakMap,
|
|
7
|
-
* ensuring the same object always produces the same hash.
|
|
8
|
-
*/
|
|
9
|
-
export declare function hashValue(value: unknown): string;
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { ValidationMode } from '../types';
|
|
2
|
-
/**
|
|
3
|
-
* Determines if validation should occur on change event.
|
|
4
|
-
* Used by useController and register for consistent mode handling.
|
|
5
|
-
*
|
|
6
|
-
* @param mode - The form's validation mode
|
|
7
|
-
* @param isTouched - Whether the field has been touched
|
|
8
|
-
* @param reValidateMode - The form's reValidateMode (used after first submit)
|
|
9
|
-
* @param hasSubmitted - Whether the form has been submitted at least once (optional, for reValidateMode)
|
|
10
|
-
* @returns true if validation should be triggered
|
|
11
|
-
*/
|
|
12
|
-
export declare function shouldValidateOnChange(mode: ValidationMode, isTouched: boolean, reValidateMode?: ValidationMode, hasSubmitted?: boolean): boolean;
|
|
13
|
-
/**
|
|
14
|
-
* Determines if validation should occur on blur event.
|
|
15
|
-
* Used by useController and register for consistent mode handling.
|
|
16
|
-
*
|
|
17
|
-
* @param mode - The form's validation mode
|
|
18
|
-
* @param hasSubmitted - Whether the form has been submitted at least once
|
|
19
|
-
* @param reValidateMode - The form's reValidateMode (used after first submit)
|
|
20
|
-
* @returns true if validation should be triggered
|
|
21
|
-
*/
|
|
22
|
-
export declare function shouldValidateOnBlur(mode: ValidationMode, hasSubmitted: boolean, reValidateMode?: ValidationMode): boolean;
|
package/dist/utils/paths.d.ts
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Clear the path segment cache.
|
|
3
|
-
* Call this between SSR requests to prevent memory accumulation,
|
|
4
|
-
* or in tests to reset state.
|
|
5
|
-
*
|
|
6
|
-
* The cache is bounded to 256 entries, so clearing is optional
|
|
7
|
-
* for client-side only applications.
|
|
8
|
-
*/
|
|
9
|
-
export declare function clearPathCache(): void;
|
|
10
|
-
/**
|
|
11
|
-
* Get value from object using dot notation path
|
|
12
|
-
* @example get({ user: { name: 'John' } }, 'user.name') => 'John'
|
|
13
|
-
*/
|
|
14
|
-
export declare function get(obj: unknown, path: string): unknown;
|
|
15
|
-
/**
|
|
16
|
-
* Set value in object using dot notation path
|
|
17
|
-
* @example set({}, 'user.name', 'John') => { user: { name: 'John' } }
|
|
18
|
-
*/
|
|
19
|
-
export declare function set(obj: Record<string, unknown>, path: string, value: unknown): void;
|
|
20
|
-
/**
|
|
21
|
-
* Delete value from object using dot notation path
|
|
22
|
-
* @example unset({ user: { name: 'John' } }, 'user.name') => { user: {} }
|
|
23
|
-
*/
|
|
24
|
-
export declare function unset(obj: Record<string, unknown>, path: string): void;
|
|
25
|
-
/**
|
|
26
|
-
* Check if path exists in object.
|
|
27
|
-
* Unlike `get(obj, path) !== undefined`, this properly distinguishes between
|
|
28
|
-
* a missing path and a path that exists with an `undefined` value.
|
|
29
|
-
*
|
|
30
|
-
* @example
|
|
31
|
-
* has({ name: undefined }, 'name') // true - path exists
|
|
32
|
-
* has({ }, 'name') // false - path doesn't exist
|
|
33
|
-
* has({ user: { name: 'John' } }, 'user.name') // true
|
|
34
|
-
* has({ user: { name: 'John' } }, 'user.age') // false
|
|
35
|
-
*/
|
|
36
|
-
export declare function has(obj: Record<string, unknown>, path: string): boolean;
|
|
37
|
-
export declare function generateId(): string;
|
|
38
|
-
/**
|
|
39
|
-
* Check if a path represents an array index
|
|
40
|
-
* @example isArrayPath('users.0') => true
|
|
41
|
-
* @example isArrayPath('users.name') => false
|
|
42
|
-
*/
|
|
43
|
-
export declare function isArrayPath(path: string): boolean;
|
|
44
|
-
/**
|
|
45
|
-
* Get parent path
|
|
46
|
-
* @example getParentPath('user.addresses.0.street') => 'user.addresses.0'
|
|
47
|
-
*/
|
|
48
|
-
export declare function getParentPath(path: string): string | undefined;
|
|
49
|
-
/**
|
|
50
|
-
* Get field name from path
|
|
51
|
-
* @example getFieldName('user.addresses.0.street') => 'street'
|
|
52
|
-
*/
|
|
53
|
-
export declare function getFieldName(path: string): string;
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { ZodType } from 'zod';
|
|
2
|
-
interface SchemaPathAnalysis {
|
|
3
|
-
canPartialValidate: boolean;
|
|
4
|
-
subSchema?: ZodType;
|
|
5
|
-
reason?: 'root-checks' | 'path-checks' | 'unsupported-type' | 'invalid-path';
|
|
6
|
-
}
|
|
7
|
-
/**
|
|
8
|
-
* Check if the root schema has refinements/checks
|
|
9
|
-
* Root-level checks may depend on multiple fields, requiring full validation
|
|
10
|
-
*/
|
|
11
|
-
export declare function hasRootEffects(schema: ZodType): boolean;
|
|
12
|
-
/**
|
|
13
|
-
* Extract sub-schema for a given path
|
|
14
|
-
*
|
|
15
|
-
* Returns the sub-schema and whether any checks/refinements were encountered.
|
|
16
|
-
* If checks are found at object level, partial validation isn't safe because
|
|
17
|
-
* the refinement may depend on other fields.
|
|
18
|
-
*
|
|
19
|
-
* @param schema - Root form schema
|
|
20
|
-
* @param path - Dot-notation field path (e.g., "user.address.city")
|
|
21
|
-
* @returns Sub-schema and effects flag, or null if path invalid
|
|
22
|
-
*/
|
|
23
|
-
export declare function extractSubSchema(schema: ZodType, path: string): {
|
|
24
|
-
schema: ZodType;
|
|
25
|
-
hasEffects: boolean;
|
|
26
|
-
} | null;
|
|
27
|
-
/**
|
|
28
|
-
* Analyze if a path can be validated in isolation
|
|
29
|
-
*
|
|
30
|
-
* This is the main entry point for determining partial validation eligibility.
|
|
31
|
-
* Results are cached per-schema for performance.
|
|
32
|
-
*
|
|
33
|
-
* @param schema - Root form schema
|
|
34
|
-
* @param path - Dot-notation field path
|
|
35
|
-
* @returns Analysis result with eligibility and reason
|
|
36
|
-
*/
|
|
37
|
-
export declare function analyzeSchemaPath(schema: ZodType, path: string): SchemaPathAnalysis;
|
|
38
|
-
/**
|
|
39
|
-
* Clear the analysis cache (useful for testing)
|
|
40
|
-
*/
|
|
41
|
-
export declare function clearAnalysisCache(): void;
|
|
42
|
-
export {};
|