notform 2.2.0 → 2.2.2
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/index.d.ts +57 -29
- package/package.json +12 -12
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Component, ComputedRef, MaybeRefOrGetter, Raw, Ref } from "vue";
|
|
2
2
|
import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
3
3
|
import { Get, PartialDeep, Paths as Paths$1 } from "type-fest";
|
|
4
|
-
|
|
5
4
|
//#region src/types/shared.d.ts
|
|
6
5
|
/**
|
|
7
6
|
* The validation mode determines when validation occurs.
|
|
@@ -97,9 +96,13 @@ interface UseNotFormConfig<TSchema extends ObjectSchema> {
|
|
|
97
96
|
* @template TSchema The form schema.
|
|
98
97
|
*/
|
|
99
98
|
type NotFormInstance<TSchema extends ObjectSchema> = Raw<{
|
|
100
|
-
/** The values the form was initialised or last reset with. */
|
|
101
|
-
readonly
|
|
102
|
-
|
|
99
|
+
/** The values the form was initialised or last reset with. */
|
|
100
|
+
readonly initialValues: UseNotFormConfig<TSchema>['initialValues'];
|
|
101
|
+
/** The errors the form was initialised or last reset with. */
|
|
102
|
+
readonly initialErrors: UseNotFormConfig<TSchema>['initialErrors'];
|
|
103
|
+
/** The resolved validation triggers for this form. */
|
|
104
|
+
readonly validateOn: Required<NonNullable<UseNotFormConfig<TSchema>['validateOn']>>;
|
|
105
|
+
/** The resolved validation mode for this form. */
|
|
103
106
|
readonly validationMode: Required<NonNullable<UseNotFormConfig<TSchema>['validationMode']>>;
|
|
104
107
|
/**
|
|
105
108
|
* Deeply reactive object of field values.
|
|
@@ -134,20 +137,24 @@ type NotFormInstance<TSchema extends ObjectSchema> = Raw<{
|
|
|
134
137
|
* The set of field paths the user has interacted with.
|
|
135
138
|
* Populated for all paths when the form is submitted.
|
|
136
139
|
*/
|
|
137
|
-
touchedFields: Set<Paths<StandardSchemaV1.InferInput<TSchema>>>;
|
|
140
|
+
touchedFields: Set<Paths<StandardSchemaV1.InferInput<TSchema>>>;
|
|
141
|
+
/** Whether any field has been touched. */
|
|
138
142
|
isTouched: ComputedRef<boolean>;
|
|
139
143
|
/**
|
|
140
144
|
* Marks a field as touched.
|
|
141
145
|
* Called automatically by the field's `onBlur` handler.
|
|
142
146
|
*/
|
|
143
|
-
touchField: (path: Paths<StandardSchemaV1.InferInput<TSchema>>) => void;
|
|
144
|
-
|
|
147
|
+
touchField: (path: Paths<StandardSchemaV1.InferInput<TSchema>>) => void;
|
|
148
|
+
/** The set of field paths whose current value differs from the initial value. */
|
|
149
|
+
dirtyFields: Set<Paths<StandardSchemaV1.InferInput<TSchema>>>;
|
|
150
|
+
/** Whether any field value differs from its initial value. */
|
|
145
151
|
isDirty: ComputedRef<boolean>;
|
|
146
152
|
/**
|
|
147
153
|
* Marks a field as dirty.
|
|
148
154
|
* Called automatically when a field value changes.
|
|
149
155
|
*/
|
|
150
|
-
dirtyField: (path: Paths<StandardSchemaV1.InferInput<TSchema>>) => void;
|
|
156
|
+
dirtyField: (path: Paths<StandardSchemaV1.InferInput<TSchema>>) => void;
|
|
157
|
+
/** The raw validation issues produced by the last validation run. */
|
|
151
158
|
errors: Array<StandardSchemaV1.Issue>;
|
|
152
159
|
/**
|
|
153
160
|
* A flat map of field path to its first error message.
|
|
@@ -165,8 +172,10 @@ type NotFormInstance<TSchema extends ObjectSchema> = Raw<{
|
|
|
165
172
|
* Replaces an existing error for the same path, or appends it if none exists.
|
|
166
173
|
* Useful for setting server-side errors after submission.
|
|
167
174
|
*/
|
|
168
|
-
setError: (error: StandardSchemaV1.Issue) => void;
|
|
169
|
-
|
|
175
|
+
setError: (error: StandardSchemaV1.Issue) => void;
|
|
176
|
+
/** Replaces all current errors with the provided issues. */
|
|
177
|
+
setErrors: (errors: Array<StandardSchemaV1.Issue>) => void;
|
|
178
|
+
/** Removes all active validation errors. */
|
|
170
179
|
clearErrors: () => void;
|
|
171
180
|
/**
|
|
172
181
|
* Returns all validation issues for a specific field path.
|
|
@@ -175,7 +184,8 @@ type NotFormInstance<TSchema extends ObjectSchema> = Raw<{
|
|
|
175
184
|
* form.getFieldErrors('address.city')
|
|
176
185
|
* ```
|
|
177
186
|
*/
|
|
178
|
-
getFieldErrors: (path: Paths<StandardSchemaV1.InferInput<TSchema>>) => Array<StandardSchemaV1.Issue>;
|
|
187
|
+
getFieldErrors: (path: Paths<StandardSchemaV1.InferInput<TSchema>>) => Array<StandardSchemaV1.Issue>;
|
|
188
|
+
/** Whether a validation run is currently in progress. */
|
|
179
189
|
isValidating: Ref<boolean>;
|
|
180
190
|
/**
|
|
181
191
|
* Validates the entire form against the schema.
|
|
@@ -186,8 +196,10 @@ type NotFormInstance<TSchema extends ObjectSchema> = Raw<{
|
|
|
186
196
|
* Validates a single field against the schema.
|
|
187
197
|
* Only replaces errors for that field — all other fields are left untouched.
|
|
188
198
|
*/
|
|
189
|
-
validateField: (path: Paths<StandardSchemaV1.InferInput<TSchema>>) => Promise<StandardSchemaV1.Result<StandardSchemaV1.InferOutput<TSchema>>>;
|
|
190
|
-
|
|
199
|
+
validateField: (path: Paths<StandardSchemaV1.InferInput<TSchema>>) => Promise<StandardSchemaV1.Result<StandardSchemaV1.InferOutput<TSchema>>>;
|
|
200
|
+
/** Whether the form currently has no validation errors. */
|
|
201
|
+
isValid: ComputedRef<boolean>;
|
|
202
|
+
/** Whether the form is currently running its submit handler. */
|
|
191
203
|
isSubmitting: Ref<boolean>;
|
|
192
204
|
/**
|
|
193
205
|
* Validates the form and runs `onSubmit` if it passes.
|
|
@@ -294,9 +306,13 @@ interface NotArrayFieldItem {
|
|
|
294
306
|
interface NotArrayFieldSlots<TSchema extends ObjectSchema, TItem = any> {
|
|
295
307
|
/** The default slot receives the full array state and manipulation methods. */
|
|
296
308
|
default: (props: {
|
|
297
|
-
/** The dot-separated path to this array field. */
|
|
298
|
-
|
|
299
|
-
|
|
309
|
+
/** The dot-separated path to this array field. */
|
|
310
|
+
path: string;
|
|
311
|
+
/** The array items with stable keys and paths for use with `v-for`. */
|
|
312
|
+
items: Array<NotArrayFieldItem>;
|
|
313
|
+
/** All validation issues for this array field from the last validation run. */
|
|
314
|
+
errors: Array<StandardSchemaV1.Issue>;
|
|
315
|
+
/** Whether this array field currently has no validation errors. */
|
|
300
316
|
isValid: boolean;
|
|
301
317
|
/**
|
|
302
318
|
* Whether any item in this array has been touched.
|
|
@@ -307,7 +323,8 @@ interface NotArrayFieldSlots<TSchema extends ObjectSchema, TItem = any> {
|
|
|
307
323
|
* Whether any item in this array differs from its initial value.
|
|
308
324
|
* Derived from the form's `dirtyFields` set.
|
|
309
325
|
*/
|
|
310
|
-
isDirty: boolean;
|
|
326
|
+
isDirty: boolean;
|
|
327
|
+
/** Whether validation is currently running for this array field. */
|
|
311
328
|
isValidating: boolean;
|
|
312
329
|
/**
|
|
313
330
|
* Manually triggers validation for this array field.
|
|
@@ -369,7 +386,7 @@ declare const __VLS_export$3: <TSchema extends ObjectSchema, TItemSchema extends
|
|
|
369
386
|
__ctx?: NonNullable<Awaited<typeof __VLS_setup>>;
|
|
370
387
|
};
|
|
371
388
|
declare const _default: typeof __VLS_export$3;
|
|
372
|
-
type __VLS_PrettifyLocal$1<T> = (T extends any ? { [K in keyof T]: T[K] } : { [K in keyof T as K]: T[K] }) & {};
|
|
389
|
+
type __VLS_PrettifyLocal$1<T> = (T extends any ? { [K in keyof T]: T[K]; } : { [K in keyof T as K]: T[K]; }) & {};
|
|
373
390
|
//#endregion
|
|
374
391
|
//#region src/types/not-field.d.ts
|
|
375
392
|
/** Props for the `NotField` component. */
|
|
@@ -433,17 +450,23 @@ interface NotFieldProps {
|
|
|
433
450
|
interface NotFieldSlots<TSchema extends ObjectSchema> {
|
|
434
451
|
/** The default slot receives the full field state and event handlers. */
|
|
435
452
|
default?: (props: {
|
|
436
|
-
/** The dot-separated path to this field. */
|
|
453
|
+
/** The dot-separated path to this field. */
|
|
454
|
+
path: string;
|
|
437
455
|
/**
|
|
438
456
|
* The current value of this field — read-only snapshot for display purposes.
|
|
439
457
|
* Do not mutate directly or use with `v-model`.
|
|
440
458
|
* For two-way binding use `v-model="form.values.fieldName"` instead.
|
|
441
459
|
*/
|
|
442
|
-
value: any;
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
460
|
+
value: any;
|
|
461
|
+
/** All validation issues for this field from the last validation run. */
|
|
462
|
+
errors: Array<StandardSchemaV1.Issue>;
|
|
463
|
+
/** Whether this field currently has no validation errors. */
|
|
464
|
+
isValid: boolean;
|
|
465
|
+
/** Whether the user has interacted with this field, or the form has been submitted. */
|
|
466
|
+
isTouched: boolean;
|
|
467
|
+
/** Whether this field's current value differs from its initial value. */
|
|
468
|
+
isDirty: boolean;
|
|
469
|
+
/** Whether an async validator is currently running for this field. */
|
|
447
470
|
isValidating: boolean;
|
|
448
471
|
/**
|
|
449
472
|
* Manually triggers validation for this field.
|
|
@@ -465,9 +488,13 @@ interface NotFieldSlots<TSchema extends ObjectSchema> {
|
|
|
465
488
|
* ```
|
|
466
489
|
*/
|
|
467
490
|
events: {
|
|
468
|
-
/** Triggered when the field loses focus. */
|
|
469
|
-
|
|
470
|
-
|
|
491
|
+
/** Triggered when the field loses focus. */
|
|
492
|
+
onBlur: () => void;
|
|
493
|
+
/** Triggered on every keystroke or value change. */
|
|
494
|
+
onInput: () => void;
|
|
495
|
+
/** Triggered when the field value is committed. */
|
|
496
|
+
onChange: () => void;
|
|
497
|
+
/** Triggered when the field gains focus. */
|
|
471
498
|
onFocus: () => void;
|
|
472
499
|
};
|
|
473
500
|
}) => any;
|
|
@@ -486,7 +513,7 @@ declare const __VLS_export$2: <TSchema extends ObjectSchema>(__VLS_props: NonNul
|
|
|
486
513
|
__ctx?: NonNullable<Awaited<typeof __VLS_setup>>;
|
|
487
514
|
};
|
|
488
515
|
declare const _default$1: typeof __VLS_export$2;
|
|
489
|
-
type __VLS_PrettifyLocal<T> = (T extends any ? { [K in keyof T]: T[K] } : { [K in keyof T as K]: T[K] }) & {};
|
|
516
|
+
type __VLS_PrettifyLocal<T> = (T extends any ? { [K in keyof T]: T[K]; } : { [K in keyof T as K]: T[K]; }) & {};
|
|
490
517
|
//#endregion
|
|
491
518
|
//#region src/components/not-form.vue.d.ts
|
|
492
519
|
type __VLS_Slots$1 = NotFormSlots;
|
|
@@ -526,7 +553,8 @@ interface NotMessageProps {
|
|
|
526
553
|
interface NotMessageSlots {
|
|
527
554
|
/** The default slot receives the error message context for custom rendering */
|
|
528
555
|
default?: (props: {
|
|
529
|
-
/** The first active validation error message for the specified field */
|
|
556
|
+
/** The first active validation error message for the specified field */
|
|
557
|
+
message?: string;
|
|
530
558
|
}) => any;
|
|
531
559
|
}
|
|
532
560
|
//#endregion
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "notform",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "2.2.
|
|
4
|
+
"version": "2.2.2",
|
|
5
5
|
"private": false,
|
|
6
6
|
"description": "Vue Forms Without the Friction",
|
|
7
7
|
"author": "Favour Emeka <favorodera@gmail.com>",
|
|
@@ -45,22 +45,22 @@
|
|
|
45
45
|
"dependencies": {
|
|
46
46
|
"@standard-schema/spec": "^1.1.0",
|
|
47
47
|
"dequal": "^2.0.3",
|
|
48
|
-
"dot-prop": "^10.
|
|
48
|
+
"dot-prop": "^10.2.0",
|
|
49
49
|
"klona": "^2.0.6"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
|
-
"@favorodera/eslint-config": "^1.0.
|
|
53
|
-
"@types/node": "^26.
|
|
54
|
-
"@vitejs/plugin-vue": "^6.0.
|
|
55
|
-
"@vitest/ui": "^4.1.
|
|
52
|
+
"@favorodera/eslint-config": "^1.0.4",
|
|
53
|
+
"@types/node": "^26.2.0",
|
|
54
|
+
"@vitejs/plugin-vue": "^6.0.8",
|
|
55
|
+
"@vitest/ui": "^4.1.10",
|
|
56
56
|
"@vue/test-utils": "^2.4.11",
|
|
57
|
-
"happy-dom": "^20.
|
|
58
|
-
"tsdown": "^0.22.
|
|
57
|
+
"happy-dom": "^20.11.2",
|
|
58
|
+
"tsdown": "^0.22.14",
|
|
59
59
|
"type-fest": "^5.7.0",
|
|
60
|
-
"vite": "^8.1
|
|
61
|
-
"vitest": "^4.1.
|
|
62
|
-
"vue": "^3.
|
|
63
|
-
"vue-tsc": "^3.3.
|
|
60
|
+
"vite": "^8.2.1",
|
|
61
|
+
"vitest": "^4.1.10",
|
|
62
|
+
"vue": "^3.0.0",
|
|
63
|
+
"vue-tsc": "^3.3.9"
|
|
64
64
|
},
|
|
65
65
|
"scripts": {
|
|
66
66
|
"build": "tsdown",
|