notform 2.2.4 → 3.0.0-alpha.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/README.md +77 -67
- package/dist/index.d.ts +402 -413
- package/dist/index.js +719 -644
- package/package.json +14 -13
package/dist/index.d.ts
CHANGED
|
@@ -1,40 +1,50 @@
|
|
|
1
|
-
import { Component,
|
|
1
|
+
import { Component, MaybeRefOrGetter } from "vue";
|
|
2
2
|
import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
3
|
-
import { Get, PartialDeep, Paths
|
|
3
|
+
import { ExcludeStrict, Get, PartialDeep, Paths } from "type-fest";
|
|
4
4
|
//#region src/types/shared.d.ts
|
|
5
|
+
/** Events that can trigger field validation. */
|
|
6
|
+
type ValidationTrigger = 'onBlur' | 'onChange' | 'onInput' | 'onMount';
|
|
5
7
|
/**
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* - `eager`: Validates on blur, then on every change if an error exists.
|
|
9
|
-
*/
|
|
10
|
-
type ValidationMode = 'eager' | 'lazy';
|
|
11
|
-
/**
|
|
12
|
-
* Interaction events that can trigger a validation check for a field.
|
|
13
|
-
* - onBlur: Trigger validation when the field loses focus.
|
|
14
|
-
* - onChange: Trigger validation when the field value is committed.
|
|
15
|
-
* - onInput: Trigger validation on every keystroke.
|
|
16
|
-
* - onMount: Trigger validation when the field is mounted.
|
|
17
|
-
* - onFocus: Trigger validation when the field gains focus.
|
|
18
|
-
*/
|
|
19
|
-
type ValidationTrigger = 'onBlur' | 'onChange' | 'onFocus' | 'onInput' | 'onMount';
|
|
20
|
-
/**
|
|
21
|
-
* Constructs a type where all properties of the input type are optional recursively.
|
|
22
|
-
* @template TData The base data structure to transform.
|
|
8
|
+
* Recursively optional version of `TData`, including array items.
|
|
9
|
+
* @template TData Source data type.
|
|
23
10
|
*/
|
|
24
11
|
type DeepPartial<TData> = PartialDeep<TData, {
|
|
25
12
|
allowUndefinedInNonTupleArrays: true;
|
|
26
13
|
recurseIntoArrays: true;
|
|
27
14
|
}>;
|
|
28
15
|
/**
|
|
29
|
-
*
|
|
30
|
-
* @template
|
|
16
|
+
* Input type accepted by a Standard Schema.
|
|
17
|
+
* @template TSchema Validation schema.
|
|
18
|
+
*/
|
|
19
|
+
type InferInput<TSchema extends StandardSchemaV1> = StandardSchemaV1.InferInput<TSchema>;
|
|
20
|
+
/**
|
|
21
|
+
* Output type produced by a Standard Schema.
|
|
22
|
+
* @template TSchema Validation schema.
|
|
31
23
|
*/
|
|
32
|
-
type
|
|
24
|
+
type InferOutput<TSchema extends StandardSchemaV1> = StandardSchemaV1.InferOutput<TSchema>;
|
|
25
|
+
/** One issue from a Standard Schema validation run. */
|
|
26
|
+
type Issue = StandardSchemaV1.Issue;
|
|
27
|
+
/**
|
|
28
|
+
* Dot-notated field paths derived from a schema's input type.
|
|
29
|
+
*
|
|
30
|
+
* The `| (string & {})` union member is deliberate: it keeps editor
|
|
31
|
+
* autocomplete suggesting the schema's real paths, while still letting any
|
|
32
|
+
* arbitrary string through the type checker — needed because a dynamically
|
|
33
|
+
* built path (e.g. `` `${item.path}.name` ``) can't always be proven to match
|
|
34
|
+
* the literal union `TypeFestPaths` computes.
|
|
35
|
+
* @template TSchema Validation schema.
|
|
36
|
+
*/
|
|
37
|
+
type Paths$1<TSchema extends StandardSchemaV1> = Extract<Paths<InferInput<TSchema>, {
|
|
33
38
|
maxRecursionDepth: 10;
|
|
34
39
|
}>, string> | (string & {});
|
|
35
40
|
/**
|
|
36
|
-
*
|
|
37
|
-
*
|
|
41
|
+
* Standard Schema constrained to object input.
|
|
42
|
+
*
|
|
43
|
+
* The `~standard.types.input` check exists purely at the type level, so that
|
|
44
|
+
* `useNotForm`'s `TSchema` is only inferred when the schema's input type is
|
|
45
|
+
* actually an `object` — this is what makes passing a non-object schema
|
|
46
|
+
* (e.g. `z.string()`) a compile-time error rather than a runtime surprise.
|
|
47
|
+
* @see {@linkcode https://github.com/standard-schema/standard-schema Standard Schema spec}
|
|
38
48
|
*/
|
|
39
49
|
type ObjectSchema = StandardSchemaV1 & {
|
|
40
50
|
'~standard': StandardSchemaV1['~standard'] & {
|
|
@@ -43,529 +53,508 @@ type ObjectSchema = StandardSchemaV1 & {
|
|
|
43
53
|
};
|
|
44
54
|
};
|
|
45
55
|
};
|
|
46
|
-
/**
|
|
47
|
-
* Represents a segment of a validation path.
|
|
48
|
-
* It can be either a string (for object properties) or a number (for array indices).
|
|
49
|
-
*/
|
|
50
|
-
type Segment = PropertyKey | StandardSchemaV1.PathSegment;
|
|
51
|
-
/**
|
|
52
|
-
* Maps the index an array item occupied before a mutation to the index it
|
|
53
|
-
* occupies after that mutation, or to `undefined` when the mutation removed the
|
|
54
|
-
* item entirely.
|
|
55
|
-
*
|
|
56
|
-
* Each array mutation in `NotArrayField` (`prepend`, `remove`, `insert`,
|
|
57
|
-
* `swap`, `move`) builds one of these to describe exactly how it reshuffles
|
|
58
|
-
* indices, then passes it to `remapArrayFieldState`.
|
|
59
|
-
* @param previousIndex The index the item occupied before the mutation.
|
|
60
|
-
* @returns The index the item occupies after the mutation, or `undefined` if the item was removed.
|
|
61
|
-
*/
|
|
62
|
-
type ArrayItemIndexMap = (previousIndex: number) => number | undefined;
|
|
63
56
|
//#endregion
|
|
64
|
-
//#region src/types/
|
|
57
|
+
//#region src/types/not-form-instance.d.ts
|
|
65
58
|
/**
|
|
66
|
-
*
|
|
59
|
+
* Full form instance used by field components. `useNotForm` returns {@linkcode NotFormAPI}.
|
|
67
60
|
* @template TSchema The form schema.
|
|
68
61
|
*/
|
|
69
|
-
interface
|
|
70
|
-
/**
|
|
71
|
-
|
|
72
|
-
/** The initial values of the form */
|
|
73
|
-
initialValues?: DeepPartial<StandardSchemaV1.InferInput<TSchema>>;
|
|
74
|
-
/** The initial errors of the form */
|
|
75
|
-
initialErrors?: Array<StandardSchemaV1.Issue>;
|
|
62
|
+
interface NotFormInstance<TSchema extends ObjectSchema> {
|
|
63
|
+
/** Live field values. */
|
|
64
|
+
values: InferInput<TSchema>;
|
|
76
65
|
/**
|
|
77
|
-
*
|
|
78
|
-
*
|
|
66
|
+
* Sets a field value by path. Does not validate — validation still only
|
|
67
|
+
* runs through a field's own configured triggers, or an explicit
|
|
68
|
+
* {@linkcode validate}/{@linkcode validateField} call.
|
|
69
|
+
* @template TPath Field path.
|
|
70
|
+
* @param path Dot path.
|
|
71
|
+
* @param value Value to assign.
|
|
79
72
|
*/
|
|
80
|
-
|
|
73
|
+
setValue: <TPath extends Paths$1<TSchema>>(path: TPath, value: Get<InferInput<TSchema>, TPath, {
|
|
74
|
+
strict: false;
|
|
75
|
+
}>) => void;
|
|
76
|
+
/** Whether any field is touched. */
|
|
77
|
+
isTouched: boolean;
|
|
81
78
|
/**
|
|
82
|
-
*
|
|
83
|
-
* @
|
|
79
|
+
* Touched field paths.
|
|
80
|
+
* @internal
|
|
84
81
|
*/
|
|
85
|
-
|
|
82
|
+
touchedFields: Set<Paths$1<TSchema>>;
|
|
86
83
|
/**
|
|
87
|
-
*
|
|
88
|
-
* @
|
|
84
|
+
* Marks a field as touched.
|
|
85
|
+
* @internal
|
|
86
|
+
* @param path Dot path.
|
|
89
87
|
*/
|
|
90
|
-
|
|
91
|
-
}
|
|
92
|
-
//#endregion
|
|
93
|
-
//#region src/types/not-form.d.ts
|
|
94
|
-
/**
|
|
95
|
-
* The complete state and API of a form instance returned by `useNotForm`.
|
|
96
|
-
* @template TSchema The form schema.
|
|
97
|
-
*/
|
|
98
|
-
type NotFormInstance<TSchema extends ObjectSchema> = Raw<{
|
|
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. */
|
|
106
|
-
readonly validationMode: Required<NonNullable<UseNotFormConfig<TSchema>['validationMode']>>;
|
|
88
|
+
markFieldAsTouched: (path: Paths$1<TSchema>) => void;
|
|
107
89
|
/**
|
|
108
|
-
*
|
|
109
|
-
*
|
|
110
|
-
*
|
|
111
|
-
*
|
|
112
|
-
*
|
|
113
|
-
* ```
|
|
114
|
-
*
|
|
115
|
-
* - Use with `v-model` for two-way binding:
|
|
116
|
-
* ```vue
|
|
117
|
-
* <template>
|
|
118
|
-
* <input v-model="form.values.email" />
|
|
119
|
-
* </template>
|
|
120
|
-
* ```
|
|
90
|
+
* Marks every current leaf field as touched. "Current" matters for arrays:
|
|
91
|
+
* an empty array contributes no leaf paths, so an item appended afterward
|
|
92
|
+
* (e.g. via `<NotArrayField>`'s `append`) starts untouched even though
|
|
93
|
+
* this was already called.
|
|
94
|
+
* @internal
|
|
121
95
|
*/
|
|
122
|
-
|
|
96
|
+
markAllFieldsAsTouched: () => void;
|
|
123
97
|
/**
|
|
124
|
-
*
|
|
125
|
-
*
|
|
126
|
-
*
|
|
127
|
-
* Does **not** trigger validation — the field's event handlers are responsible for that.
|
|
128
|
-
* @param path The dot-separated path to the field.
|
|
129
|
-
* @param value The value to set.
|
|
130
|
-
* @example
|
|
131
|
-
* ```ts
|
|
132
|
-
* form.setValue('address.city', 'Lagos')
|
|
133
|
-
* ```
|
|
98
|
+
* Clears touched state for one field.
|
|
99
|
+
* @internal
|
|
100
|
+
* @param path Dot path.
|
|
134
101
|
*/
|
|
135
|
-
|
|
136
|
-
strict: false;
|
|
137
|
-
}>) => void;
|
|
102
|
+
unmarkFieldAsTouched: (path: Paths$1<TSchema>) => void;
|
|
138
103
|
/**
|
|
139
|
-
*
|
|
140
|
-
*
|
|
104
|
+
* Clears touched state for all fields.
|
|
105
|
+
* @internal
|
|
141
106
|
*/
|
|
142
|
-
|
|
143
|
-
/** Whether any field has been touched. */
|
|
144
|
-
isTouched: ComputedRef<boolean>;
|
|
107
|
+
unmarkAllFieldsAsTouched: () => void;
|
|
145
108
|
/**
|
|
146
|
-
*
|
|
147
|
-
*
|
|
148
|
-
* @param path The dot-separated path to the field.
|
|
149
|
-
* @example
|
|
150
|
-
* ```ts
|
|
151
|
-
* form.touchField('address.city')
|
|
152
|
-
* ```
|
|
109
|
+
* Paths whose value differs from the baseline.
|
|
110
|
+
* @internal
|
|
153
111
|
*/
|
|
154
|
-
|
|
155
|
-
/**
|
|
156
|
-
|
|
157
|
-
/** Whether any field value differs from its initial value. */
|
|
158
|
-
isDirty: ComputedRef<boolean>;
|
|
112
|
+
dirtyFields: Set<Paths$1<TSchema>>;
|
|
113
|
+
/** Whether any field is dirty. */
|
|
114
|
+
isDirty: boolean;
|
|
159
115
|
/**
|
|
160
|
-
*
|
|
161
|
-
*
|
|
162
|
-
* @param path
|
|
163
|
-
* @example
|
|
164
|
-
* ```ts
|
|
165
|
-
* form.dirtyField('address.city')
|
|
166
|
-
* ```
|
|
116
|
+
* Updates dirty state by comparing current and baseline values.
|
|
117
|
+
* @internal
|
|
118
|
+
* @param path Dot path.
|
|
167
119
|
*/
|
|
168
|
-
|
|
169
|
-
/** The raw validation issues produced by the last validation run. */
|
|
170
|
-
errors: Array<StandardSchemaV1.Issue>;
|
|
120
|
+
syncDirtyState: (path: Paths$1<TSchema>) => void;
|
|
171
121
|
/**
|
|
172
|
-
*
|
|
173
|
-
*
|
|
174
|
-
*
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
*
|
|
179
|
-
*
|
|
180
|
-
*
|
|
122
|
+
* Updates dirty state for every current leaf field. Subject to the same
|
|
123
|
+
* "current shape only" caveat as {@linkcode markAllFieldsAsTouched}.
|
|
124
|
+
* @internal
|
|
125
|
+
*/
|
|
126
|
+
syncAllDirtyStates: () => void;
|
|
127
|
+
/**
|
|
128
|
+
* Forces a field dirty.
|
|
129
|
+
* @internal
|
|
130
|
+
* @param path Dot path.
|
|
131
|
+
*/
|
|
132
|
+
markFieldAsDirty: (path: Paths$1<TSchema>) => void;
|
|
133
|
+
/**
|
|
134
|
+
* Forces every current leaf field dirty. Subject to the same
|
|
135
|
+
* "current shape only" caveat as {@linkcode markAllFieldsAsTouched}.
|
|
136
|
+
* @internal
|
|
137
|
+
*/
|
|
138
|
+
markAllFieldsAsDirty: () => void;
|
|
139
|
+
/**
|
|
140
|
+
* Clears dirty state for one field.
|
|
141
|
+
* @internal
|
|
142
|
+
* @param path Dot path.
|
|
181
143
|
*/
|
|
182
|
-
|
|
144
|
+
unmarkFieldAsDirty: (path: Paths$1<TSchema>) => void;
|
|
183
145
|
/**
|
|
184
|
-
*
|
|
185
|
-
*
|
|
186
|
-
* @param error The validation issue to set.
|
|
187
|
-
* @example
|
|
188
|
-
* ```ts
|
|
189
|
-
* form.setError({ message: 'Invalid email', path: ['email'] })
|
|
190
|
-
* ```
|
|
146
|
+
* Clears dirty state for all fields.
|
|
147
|
+
* @internal
|
|
191
148
|
*/
|
|
192
|
-
|
|
149
|
+
unmarkAllFieldsAsDirty: () => void;
|
|
150
|
+
/** Issues from the last validation that wrote errors. */
|
|
151
|
+
errors: Array<Issue>;
|
|
193
152
|
/**
|
|
194
|
-
*
|
|
195
|
-
* @param
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
*
|
|
200
|
-
*
|
|
201
|
-
*
|
|
202
|
-
|
|
153
|
+
* Upserts an issue at the same path, or appends it.
|
|
154
|
+
* @param error Issue to set.
|
|
155
|
+
*/
|
|
156
|
+
setError: (error: Issue) => void;
|
|
157
|
+
/**
|
|
158
|
+
* Replaces the entire error list.
|
|
159
|
+
* @internal
|
|
160
|
+
* @param errors Replacement issues.
|
|
161
|
+
*/
|
|
162
|
+
replaceErrors: (errors: Array<Issue>) => void;
|
|
163
|
+
/**
|
|
164
|
+
* Removes every issue.
|
|
165
|
+
* @internal
|
|
203
166
|
*/
|
|
204
|
-
setErrors: (errors: Array<StandardSchemaV1.Issue>) => void;
|
|
205
|
-
/** Removes all active validation errors. */
|
|
206
167
|
clearErrors: () => void;
|
|
207
168
|
/**
|
|
208
|
-
*
|
|
209
|
-
*
|
|
210
|
-
*
|
|
211
|
-
*
|
|
212
|
-
*
|
|
213
|
-
*
|
|
214
|
-
*
|
|
169
|
+
* Issues whose path exactly equals `path` — not issues nested underneath it.
|
|
170
|
+
*
|
|
171
|
+
* `getFieldErrors('groups.0')` will not return an issue reported at
|
|
172
|
+
* `groups.0.name`.
|
|
173
|
+
*
|
|
174
|
+
* `<NotArrayField>`'s `isValid`/`isTouched`/`isDirty`/
|
|
175
|
+
* `isValidating` aggregate recursively instead, for exactly this reason.
|
|
176
|
+
* @param path Dot path.
|
|
177
|
+
* @returns Matching issues.
|
|
215
178
|
*/
|
|
216
|
-
getFieldErrors: (path: Paths<
|
|
217
|
-
/** Whether
|
|
218
|
-
isValidating:
|
|
179
|
+
getFieldErrors: (path: Paths$1<TSchema>) => Array<Issue>;
|
|
180
|
+
/** Whether any validation is in flight. */
|
|
181
|
+
isValidating: boolean;
|
|
182
|
+
/** Whether there are zero issues. */
|
|
183
|
+
isValid: boolean;
|
|
219
184
|
/**
|
|
220
|
-
*
|
|
221
|
-
*
|
|
222
|
-
* @returns A promise that resolves to the result of the validation.
|
|
185
|
+
* Paths currently validating.
|
|
186
|
+
* @internal
|
|
223
187
|
*/
|
|
224
|
-
|
|
188
|
+
validatingFields: Set<Paths$1<TSchema>>;
|
|
225
189
|
/**
|
|
226
|
-
* Validates
|
|
227
|
-
*
|
|
228
|
-
*
|
|
229
|
-
*
|
|
230
|
-
*
|
|
231
|
-
*
|
|
232
|
-
*
|
|
233
|
-
* ```
|
|
190
|
+
* Validates the whole form and replaces all errors.
|
|
191
|
+
*
|
|
192
|
+
* Concurrent calls are last-write-wins: each call still resolves with its
|
|
193
|
+
* own result, but only the most recently started call's result is written
|
|
194
|
+
* to `errors` — an older call that resolves later has its result silently
|
|
195
|
+
* discarded from shared state.
|
|
196
|
+
* @returns Standard Schema result.
|
|
234
197
|
*/
|
|
235
|
-
|
|
236
|
-
/** Whether the form currently has no validation errors. */
|
|
237
|
-
isValid: ComputedRef<boolean>;
|
|
238
|
-
/** Whether the form is currently running its submit handler. */
|
|
239
|
-
isSubmitting: Ref<boolean>;
|
|
198
|
+
validate: () => Promise<StandardSchemaV1.Result<InferOutput<TSchema>>>;
|
|
240
199
|
/**
|
|
241
|
-
* Validates the form and
|
|
200
|
+
* Validates the form and writes issues only for `path`.
|
|
201
|
+
*
|
|
202
|
+
* `path` can be any granularity — a leaf field, an entire array field, or
|
|
203
|
+
* a specific item inside one; `<NotField>` and `<NotArrayField>` both call
|
|
204
|
+
* this with their own `path` internally.
|
|
242
205
|
*
|
|
243
|
-
*
|
|
244
|
-
*
|
|
245
|
-
* @
|
|
246
|
-
* @
|
|
206
|
+
* Concurrent calls for the same `path` are last-write-wins, the same as
|
|
207
|
+
* {@linkcode validate}; a call started after this one, or a whole-form
|
|
208
|
+
* {@linkcode validate} call, supersedes it.
|
|
209
|
+
* @param path Dot path.
|
|
210
|
+
* @returns Standard Schema result.
|
|
211
|
+
*/
|
|
212
|
+
validateField: (path: Paths$1<TSchema>) => Promise<StandardSchemaV1.Result<InferOutput<TSchema>>>;
|
|
213
|
+
/** Whether `onSubmit` is running. */
|
|
214
|
+
isSubmitting: boolean;
|
|
215
|
+
/**
|
|
216
|
+
* Touches all fields, validates, then runs `onSubmit` when valid.
|
|
217
|
+
* @param event Optional submit event. When given, `event.preventDefault()`
|
|
218
|
+
* is called immediately, before anything else — including before checking
|
|
219
|
+
* whether a submission is already in flight or whether validation passes.
|
|
247
220
|
*/
|
|
248
|
-
submit: (event
|
|
221
|
+
submit: (event?: SubmitEvent) => Promise<void>;
|
|
249
222
|
/**
|
|
250
|
-
*
|
|
223
|
+
* Restores values/errors to the baseline. Optional arguments become the
|
|
224
|
+
* new baseline, and reset to it immediately.
|
|
251
225
|
*
|
|
252
|
-
*
|
|
253
|
-
* they
|
|
254
|
-
*
|
|
255
|
-
*
|
|
256
|
-
*
|
|
257
|
-
*
|
|
258
|
-
* // Reset to original initial values
|
|
259
|
-
* form.reset()
|
|
226
|
+
* `values`/`errors`, when given, fully replace the previous baseline —
|
|
227
|
+
* they are not merged with it. Any top-level key present in the old
|
|
228
|
+
* baseline but missing from `values` is simply gone afterward, the same
|
|
229
|
+
* way `initialValues`/`initialErrors` passed to `useNotForm` become the
|
|
230
|
+
* literal starting baseline rather than defaults merged with something
|
|
231
|
+
* else.
|
|
260
232
|
*
|
|
261
|
-
*
|
|
262
|
-
*
|
|
263
|
-
*
|
|
264
|
-
*
|
|
265
|
-
*
|
|
266
|
-
* ]
|
|
267
|
-
* )
|
|
268
|
-
* ```
|
|
233
|
+
* Also bumps the internal validation generation, so any `validate()`/
|
|
234
|
+
* `validateField()` call already in flight when this runs will still
|
|
235
|
+
* resolve with its own result, but will not write its issues to `errors`.
|
|
236
|
+
* @param values New baseline values.
|
|
237
|
+
* @param errors New baseline issues.
|
|
269
238
|
*/
|
|
270
|
-
reset: (values?: DeepPartial<
|
|
271
|
-
}>;
|
|
272
|
-
/** Props for the `NotForm` component. */
|
|
273
|
-
interface NotFormProps {
|
|
274
|
-
/** The form instance to provide to all descendant `NotField` components. */
|
|
275
|
-
form: NotFormInstance<any>;
|
|
276
|
-
}
|
|
277
|
-
/** Slots for the `NotForm` component. */
|
|
278
|
-
interface NotFormSlots {
|
|
279
|
-
/** The default slot receives the full form instance */
|
|
280
|
-
default?: () => any;
|
|
239
|
+
reset: (values?: DeepPartial<InferInput<TSchema>>, errors?: Array<Issue>) => void;
|
|
281
240
|
}
|
|
282
241
|
//#endregion
|
|
242
|
+
//#region src/types/not-form-api.d.ts
|
|
243
|
+
/**
|
|
244
|
+
* Public API from `useNotForm`: {@linkcode NotFormInstance} without `@internal` members.
|
|
245
|
+
*
|
|
246
|
+
* The excluded members are the path-set accessors and mutation helpers that
|
|
247
|
+
* `<NotField>` and `<NotArrayField>` use directly — `touchedFields`,
|
|
248
|
+
* `markFieldAsTouched`, `dirtyFields`, `syncDirtyState`, `validatingFields`,
|
|
249
|
+
* `replaceErrors`, `clearErrors`, and their siblings. Application code
|
|
250
|
+
* normally reaches the same information through `isTouched`/`isDirty`/
|
|
251
|
+
* `isValidating`, or through a specific field's own slot props, rather than
|
|
252
|
+
* these lower-level sets and setters directly.
|
|
253
|
+
* @template TSchema The form schema.
|
|
254
|
+
*/
|
|
255
|
+
type NotFormAPI<TSchema extends ObjectSchema> = Pick<NotFormInstance<TSchema>, 'errors' | 'getFieldErrors' | 'isDirty' | 'isSubmitting' | 'isTouched' | 'isValid' | 'isValidating' | 'reset' | 'setError' | 'setValue' | 'submit' | 'validate' | 'validateField' | 'values'>;
|
|
256
|
+
//#endregion
|
|
283
257
|
//#region src/types/not-array-field.d.ts
|
|
284
258
|
/**
|
|
285
|
-
*
|
|
286
|
-
* @template
|
|
259
|
+
* One array item from `<NotArrayField>`'s default slot.
|
|
260
|
+
* @template TSchema The form schema.
|
|
287
261
|
*/
|
|
288
|
-
interface
|
|
289
|
-
/**
|
|
290
|
-
|
|
262
|
+
interface NotArrayFieldItem<TSchema extends ObjectSchema> {
|
|
263
|
+
/** Stable identity for `v-for` `:key`. Independent of the current index. */
|
|
264
|
+
key: string;
|
|
265
|
+
/** Dot path of this item at its **current** index. */
|
|
266
|
+
path: Paths$1<TSchema>;
|
|
267
|
+
/** Current position in the array. */
|
|
268
|
+
index: number;
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* Props for `<NotArrayField>`.
|
|
272
|
+
* @template TSchema The form schema.
|
|
273
|
+
* @template TItemSchema Item schema used only to type mutation helpers.
|
|
274
|
+
*/
|
|
275
|
+
interface NotArrayFieldProps<TSchema extends ObjectSchema, TItemSchema extends StandardSchemaV1 = StandardSchemaV1> {
|
|
276
|
+
/** Dot path of the array field. */
|
|
277
|
+
path: Paths$1<TSchema>;
|
|
291
278
|
/**
|
|
292
|
-
*
|
|
293
|
-
*
|
|
279
|
+
* Item schema for type inference only; never read at runtime. Does not
|
|
280
|
+
* validate items — array items are still validated through the form's
|
|
281
|
+
* own schema, the same as any other field.
|
|
294
282
|
*/
|
|
295
283
|
itemSchema?: TItemSchema;
|
|
296
|
-
/**
|
|
297
|
-
|
|
298
|
-
* Takes priority over the instance provided by a `NotForm` ancestor.
|
|
299
|
-
* Required when using `NotArrayField` outside of a `NotForm`.
|
|
300
|
-
*/
|
|
301
|
-
form?: NotFormInstance<any>;
|
|
302
|
-
/**
|
|
303
|
-
* Per-field validation trigger overrides applied to the array as a whole.
|
|
304
|
-
* Merged over the form-wide `validateOn` — only the keys you specify are overridden.
|
|
305
|
-
*/
|
|
306
|
-
validateOn?: Partial<Record<Extract<ValidationTrigger, 'onChange' | 'onMount'>, boolean>>;
|
|
307
|
-
}
|
|
308
|
-
/** Represents a single item in the array field. */
|
|
309
|
-
interface NotArrayFieldItem {
|
|
310
|
-
/** Stable key used for looping — does not change when items are reordered. */
|
|
311
|
-
key: string;
|
|
312
|
-
/** Current index of this item in the array. */
|
|
313
|
-
index: number;
|
|
314
|
-
/** Full dot-separated path to this item — pass directly to `NotField`. */
|
|
315
|
-
path: string;
|
|
284
|
+
/** Form instance. Overrides `<NotForm>` inject. Required outside `<NotForm>`. */
|
|
285
|
+
form?: NotFormAPI<TSchema>;
|
|
316
286
|
}
|
|
317
287
|
/**
|
|
318
|
-
*
|
|
288
|
+
* Slot props for `<NotArrayField>`.
|
|
319
289
|
* @template TSchema The form schema.
|
|
320
|
-
* @template
|
|
290
|
+
* @template TItemSchema Item schema used only to type mutation helpers.
|
|
321
291
|
*/
|
|
322
|
-
interface NotArrayFieldSlots<TSchema extends ObjectSchema,
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
/** The dot-separated path to this array field. */
|
|
292
|
+
interface NotArrayFieldSlots<TSchema extends ObjectSchema, TItemSchema extends StandardSchemaV1 = StandardSchemaV1> {
|
|
293
|
+
default?: (props: {
|
|
294
|
+
/** Dot path of the array field. */
|
|
326
295
|
path: string;
|
|
327
|
-
/**
|
|
328
|
-
items: Array<NotArrayFieldItem
|
|
329
|
-
/**
|
|
330
|
-
|
|
331
|
-
|
|
296
|
+
/** Current items, each with a stable key and current path. */
|
|
297
|
+
items: Array<NotArrayFieldItem<TSchema>>;
|
|
298
|
+
/**
|
|
299
|
+
* Issues reported exactly at the array field's own path — not issues
|
|
300
|
+
* from individual items.
|
|
301
|
+
*
|
|
302
|
+
* The same exact-match behavior as `<NotField>`'s `errors`.
|
|
303
|
+
*
|
|
304
|
+
* See {@linkcode isValid} for the aggregate that also accounts for item-level issues.
|
|
305
|
+
*/
|
|
306
|
+
errors: Array<Issue>;
|
|
307
|
+
/**
|
|
308
|
+
* Whether the array field's own path, and every path nested underneath
|
|
309
|
+
* it, have no issues — an item's own value, a field inside an object
|
|
310
|
+
* item, or an item inside a nested array, at any depth.
|
|
311
|
+
*
|
|
312
|
+
* Unlike {@linkcode errors}, this recurses.
|
|
313
|
+
*/
|
|
332
314
|
isValid: boolean;
|
|
333
315
|
/**
|
|
334
|
-
* Whether any
|
|
335
|
-
*
|
|
316
|
+
* Whether the array field's own path, or any path nested underneath it, has been touched.
|
|
317
|
+
*
|
|
318
|
+
* Recurses the same way as {@linkcode isValid}.
|
|
336
319
|
*/
|
|
337
320
|
isTouched: boolean;
|
|
338
321
|
/**
|
|
339
|
-
* Whether any
|
|
340
|
-
*
|
|
322
|
+
* Whether the array field's own path, or any path nested underneath it, differs from the baseline.
|
|
323
|
+
*
|
|
324
|
+
* Recurses the same way as {@linkcode isValid}.
|
|
341
325
|
*/
|
|
342
326
|
isDirty: boolean;
|
|
343
|
-
/** Whether validation is currently running for this array field. */
|
|
344
|
-
isValidating: boolean;
|
|
345
327
|
/**
|
|
346
|
-
*
|
|
347
|
-
*
|
|
348
|
-
*
|
|
328
|
+
* Whether the array field's own path, or any path nested underneath it, is currently validating.
|
|
329
|
+
*
|
|
330
|
+
* Recurses the same way as {@linkcode isValid}.
|
|
349
331
|
*/
|
|
350
|
-
|
|
332
|
+
isValidating: boolean;
|
|
351
333
|
/**
|
|
352
|
-
* Appends a
|
|
353
|
-
* @param value
|
|
334
|
+
* Appends a value at the end.
|
|
335
|
+
* @param value Value to append.
|
|
354
336
|
*/
|
|
355
|
-
append: (value:
|
|
337
|
+
append: (value: InferInput<TItemSchema>) => void;
|
|
356
338
|
/**
|
|
357
|
-
*
|
|
358
|
-
*
|
|
339
|
+
* Inserts a value at the start. Shifts every existing item's own
|
|
340
|
+
* state — at any depth underneath it — forward by one position along
|
|
341
|
+
* with it.
|
|
342
|
+
* @param value Value to prepend.
|
|
359
343
|
*/
|
|
360
|
-
prepend: (value:
|
|
344
|
+
prepend: (value: InferInput<TItemSchema>) => void;
|
|
361
345
|
/**
|
|
362
|
-
*
|
|
363
|
-
*
|
|
346
|
+
* Inserts a value at `index`, shifting later items — and their own
|
|
347
|
+
* state, at any depth underneath them — back by one position.
|
|
348
|
+
* @param index Insertion index.
|
|
349
|
+
* @param value Value to insert.
|
|
364
350
|
*/
|
|
365
|
-
|
|
351
|
+
insert: (index: number, value: InferInput<TItemSchema>) => void;
|
|
366
352
|
/**
|
|
367
|
-
*
|
|
368
|
-
*
|
|
369
|
-
*
|
|
353
|
+
* Removes the item at `index`. That item's own state — at any depth
|
|
354
|
+
* underneath it — is discarded along with it; every later item's state
|
|
355
|
+
* shifts back by one position to follow it to its new index.
|
|
356
|
+
* @param index Index to remove.
|
|
370
357
|
*/
|
|
371
|
-
|
|
358
|
+
remove: (index: number) => void;
|
|
372
359
|
/**
|
|
373
|
-
* Replaces the value at
|
|
374
|
-
* @param index
|
|
375
|
-
* @param value
|
|
360
|
+
* Replaces the value at `index` without changing its key.
|
|
361
|
+
* @param index Index to update.
|
|
362
|
+
* @param value New value.
|
|
376
363
|
*/
|
|
377
|
-
update: (index: number, value:
|
|
364
|
+
update: (index: number, value: InferInput<TItemSchema>) => void;
|
|
378
365
|
/**
|
|
379
|
-
* Swaps
|
|
380
|
-
*
|
|
381
|
-
* @param
|
|
366
|
+
* Swaps two items, moving keys and form state — at any depth
|
|
367
|
+
* underneath each item — with them.
|
|
368
|
+
* @param indexA First index.
|
|
369
|
+
* @param indexB Second index.
|
|
382
370
|
*/
|
|
383
371
|
swap: (indexA: number, indexB: number) => void;
|
|
384
372
|
/**
|
|
385
|
-
* Moves an item from
|
|
386
|
-
*
|
|
387
|
-
* @param
|
|
373
|
+
* Moves an item from `from` to `to`, moving keys and form state — at
|
|
374
|
+
* any depth underneath it — with it.
|
|
375
|
+
* @param from Current index.
|
|
376
|
+
* @param to Destination index.
|
|
388
377
|
*/
|
|
389
378
|
move: (from: number, to: number) => void;
|
|
390
|
-
}) =>
|
|
379
|
+
}) => void;
|
|
391
380
|
}
|
|
392
381
|
//#endregion
|
|
393
382
|
//#region src/components/not-array-field.vue.d.ts
|
|
394
|
-
declare const __VLS_export$3: <TSchema extends ObjectSchema, TItemSchema extends StandardSchemaV1 = StandardSchemaV1
|
|
395
|
-
props: import("vue").PublicProps & __VLS_PrettifyLocal$
|
|
383
|
+
declare const __VLS_export$3: <TSchema extends ObjectSchema, TItemSchema extends StandardSchemaV1 = StandardSchemaV1>(__VLS_props: NonNullable<Awaited<typeof __VLS_setup>>["props"], __VLS_ctx?: __VLS_PrettifyLocal$3<Pick<NonNullable<Awaited<typeof __VLS_setup>>, "attrs" | "emit" | "slots">>, __VLS_exposed?: NonNullable<Awaited<typeof __VLS_setup>>["expose"], __VLS_setup?: Promise<{
|
|
384
|
+
props: import("vue").PublicProps & __VLS_PrettifyLocal$3<NotArrayFieldProps<TSchema, TItemSchema>> & (typeof globalThis extends {
|
|
396
385
|
__VLS_PROPS_FALLBACK: infer P;
|
|
397
386
|
} ? P : {});
|
|
398
387
|
expose: (exposed: {}) => void;
|
|
399
388
|
attrs: any;
|
|
400
|
-
slots: NotArrayFieldSlots<TSchema,
|
|
389
|
+
slots: NotArrayFieldSlots<TSchema, TItemSchema>;
|
|
401
390
|
emit: {};
|
|
402
391
|
}>) => import("vue").VNode & {
|
|
403
392
|
__ctx?: NonNullable<Awaited<typeof __VLS_setup>>;
|
|
404
393
|
};
|
|
405
394
|
declare const _default: typeof __VLS_export$3;
|
|
406
|
-
type __VLS_PrettifyLocal$
|
|
395
|
+
type __VLS_PrettifyLocal$3<T> = (T extends any ? { [K in keyof T]: T[K]; } : { [K in keyof T as K]: T[K]; }) & {};
|
|
407
396
|
//#endregion
|
|
408
397
|
//#region src/types/not-field.d.ts
|
|
409
|
-
/**
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
form?: NotFormInstance<any>;
|
|
398
|
+
/**
|
|
399
|
+
* Props for `<NotField>`.
|
|
400
|
+
* @template TSchema The form schema.
|
|
401
|
+
*/
|
|
402
|
+
interface NotFieldProps<TSchema extends ObjectSchema> {
|
|
403
|
+
/** Dot path of this field. */
|
|
404
|
+
path: Paths$1<TSchema>;
|
|
405
|
+
/** Form instance. Overrides `<NotForm>` inject. Required outside `<NotForm>`. */
|
|
406
|
+
form?: NotFormAPI<TSchema>;
|
|
419
407
|
/**
|
|
420
|
-
*
|
|
421
|
-
*
|
|
408
|
+
* Validation triggers merged over `{ onBlur: true, onChange: true }`.
|
|
409
|
+
*
|
|
410
|
+
* `onMount` is also a valid trigger here, even though it has no matching
|
|
411
|
+
* entry in `events` slot prop — there's no DOM event to bind for "the field
|
|
412
|
+
* just appeared," so it runs automatically, once, when the field mounts.
|
|
413
|
+
* @default { onBlur: true, onChange: true }
|
|
422
414
|
*/
|
|
423
415
|
validateOn?: Partial<Record<ValidationTrigger, boolean>>;
|
|
424
416
|
/**
|
|
425
|
-
*
|
|
426
|
-
*
|
|
427
|
-
* When set, validation is deferred until the user stops typing for the given
|
|
428
|
-
* duration. Only the final call within the window runs — earlier ones are
|
|
429
|
-
* cancelled. Useful for async validators (e.g. username availability checks)
|
|
430
|
-
* where firing on every keystroke would cause excessive requests.
|
|
431
|
-
*
|
|
432
|
-
* Blur- and submit-triggered validation always runs immediately, regardless
|
|
433
|
-
* of this setting, so the field never feels unresponsive when the user leaves.
|
|
434
|
-
*
|
|
435
|
-
* Omit or set to `0` to disable debouncing (default behaviour).
|
|
417
|
+
* `lazy` — blur/submit only. `eager` — also revalidate on change/input while invalid.
|
|
418
|
+
* @default 'eager'
|
|
436
419
|
*/
|
|
420
|
+
validationMode?: 'eager' | 'lazy';
|
|
421
|
+
/** Debounce in ms for input/change validation. Blur always runs immediately. */
|
|
437
422
|
debounce?: number;
|
|
438
423
|
}
|
|
439
|
-
/**
|
|
440
|
-
|
|
441
|
-
* @template TSchema The form schema.
|
|
442
|
-
*/
|
|
443
|
-
interface NotFieldSlots<TSchema extends ObjectSchema> {
|
|
444
|
-
/** The default slot receives the full field state and event handlers. */
|
|
424
|
+
/** Slot props for `<NotField>`. */
|
|
425
|
+
interface NotFieldSlots {
|
|
445
426
|
default?: (props: {
|
|
446
|
-
/**
|
|
447
|
-
|
|
427
|
+
/** Issues for this field path. */
|
|
428
|
+
errors: Array<Issue>;
|
|
448
429
|
/**
|
|
449
|
-
*
|
|
450
|
-
*
|
|
451
|
-
* For two-way binding use `v-model="form.values.fieldName"` instead.
|
|
430
|
+
* Handlers to bind to the input. `onMount` is deliberately excluded —
|
|
431
|
+
* see the note on `validateOn` prop for why.
|
|
452
432
|
*/
|
|
453
|
-
|
|
454
|
-
/**
|
|
455
|
-
errors: Array<StandardSchemaV1.Issue>;
|
|
456
|
-
/** Whether this field currently has no validation errors. */
|
|
457
|
-
isValid: boolean;
|
|
458
|
-
/** Whether the user has interacted with this field, or the form has been submitted. */
|
|
459
|
-
isTouched: boolean;
|
|
460
|
-
/** Whether this field's current value differs from its initial value. */
|
|
433
|
+
events: Record<ExcludeStrict<ValidationTrigger, 'onMount'>, () => void>;
|
|
434
|
+
/** Whether the value differs from the baseline. */
|
|
461
435
|
isDirty: boolean;
|
|
462
|
-
/** Whether
|
|
436
|
+
/** Whether the user has interacted with this field. */
|
|
437
|
+
isTouched: boolean;
|
|
438
|
+
/** Whether this field has no issues. */
|
|
439
|
+
isValid: boolean;
|
|
440
|
+
/** Whether this field is currently validating. */
|
|
463
441
|
isValidating: boolean;
|
|
464
|
-
/**
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
* @returns A promise that resolves to the result of the validation.
|
|
468
|
-
*/
|
|
469
|
-
validate: () => ReturnType<NotFormInstance<TSchema>['validateField']>;
|
|
470
|
-
/**
|
|
471
|
-
* Native DOM event handlers exposed by a field.
|
|
472
|
-
* Spread onto a native input or bind individually to custom components.
|
|
473
|
-
* @example
|
|
474
|
-
* ```vue
|
|
475
|
-
* <template>
|
|
476
|
-
* <!-- spread -->
|
|
477
|
-
* <input v-bind="events" />
|
|
478
|
-
*
|
|
479
|
-
* <!-- individual -->
|
|
480
|
-
* <CustomCombobox v-on:focusout="events.onBlur" v-on:pick="events.onChange" />
|
|
481
|
-
* </template>
|
|
482
|
-
* ```
|
|
483
|
-
*/
|
|
484
|
-
events: {
|
|
485
|
-
/** Triggered when the field loses focus. */
|
|
486
|
-
onBlur: () => void;
|
|
487
|
-
/** Triggered on every keystroke or value change. */
|
|
488
|
-
onInput: () => void;
|
|
489
|
-
/** Triggered when the field value is committed. */
|
|
490
|
-
onChange: () => void;
|
|
491
|
-
/** Triggered when the field gains focus. */
|
|
492
|
-
onFocus: () => void;
|
|
493
|
-
};
|
|
494
|
-
}) => any;
|
|
442
|
+
/** Dot path of this field. */
|
|
443
|
+
path: string;
|
|
444
|
+
}) => void;
|
|
495
445
|
}
|
|
496
446
|
//#endregion
|
|
497
447
|
//#region src/components/not-field.vue.d.ts
|
|
498
|
-
declare const __VLS_export$2: <TSchema extends ObjectSchema>(__VLS_props: NonNullable<Awaited<typeof __VLS_setup>>["props"], __VLS_ctx?: __VLS_PrettifyLocal<Pick<NonNullable<Awaited<typeof __VLS_setup>>, "attrs" | "emit" | "slots">>, __VLS_exposed?: NonNullable<Awaited<typeof __VLS_setup>>["expose"], __VLS_setup?: Promise<{
|
|
499
|
-
props: import("vue").PublicProps & __VLS_PrettifyLocal<NotFieldProps
|
|
448
|
+
declare const __VLS_export$2: <TSchema extends ObjectSchema>(__VLS_props: NonNullable<Awaited<typeof __VLS_setup>>["props"], __VLS_ctx?: __VLS_PrettifyLocal$2<Pick<NonNullable<Awaited<typeof __VLS_setup>>, "attrs" | "emit" | "slots">>, __VLS_exposed?: NonNullable<Awaited<typeof __VLS_setup>>["expose"], __VLS_setup?: Promise<{
|
|
449
|
+
props: import("vue").PublicProps & __VLS_PrettifyLocal$2<NotFieldProps<TSchema>> & (typeof globalThis extends {
|
|
500
450
|
__VLS_PROPS_FALLBACK: infer P;
|
|
501
451
|
} ? P : {});
|
|
502
452
|
expose: (exposed: {}) => void;
|
|
503
453
|
attrs: any;
|
|
504
|
-
slots: NotFieldSlots
|
|
454
|
+
slots: NotFieldSlots;
|
|
505
455
|
emit: {};
|
|
506
456
|
}>) => import("vue").VNode & {
|
|
507
457
|
__ctx?: NonNullable<Awaited<typeof __VLS_setup>>;
|
|
508
458
|
};
|
|
509
459
|
declare const _default$1: typeof __VLS_export$2;
|
|
510
|
-
type __VLS_PrettifyLocal<T> = (T extends any ? { [K in keyof T]: T[K]; } : { [K in keyof T as K]: T[K]; }) & {};
|
|
460
|
+
type __VLS_PrettifyLocal$2<T> = (T extends any ? { [K in keyof T]: T[K]; } : { [K in keyof T as K]: T[K]; }) & {};
|
|
461
|
+
//#endregion
|
|
462
|
+
//#region src/types/not-form.d.ts
|
|
463
|
+
/**
|
|
464
|
+
* Props for `<NotForm>`.
|
|
465
|
+
* @template TSchema The form schema.
|
|
466
|
+
*/
|
|
467
|
+
interface NotFormProps<TSchema extends ObjectSchema> {
|
|
468
|
+
/** Form instance provided to descendant field components. */
|
|
469
|
+
form: NotFormAPI<TSchema>;
|
|
470
|
+
}
|
|
471
|
+
/** Slot props for `<NotForm>`. */
|
|
472
|
+
interface NotFormSlots {
|
|
473
|
+
default?: () => void;
|
|
474
|
+
}
|
|
511
475
|
//#endregion
|
|
512
476
|
//#region src/components/not-form.vue.d.ts
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
};
|
|
477
|
+
declare const __VLS_export$1: <TSchema extends ObjectSchema>(__VLS_props: NonNullable<Awaited<typeof __VLS_setup>>["props"], __VLS_ctx?: __VLS_PrettifyLocal$1<Pick<NonNullable<Awaited<typeof __VLS_setup>>, "attrs" | "emit" | "slots">>, __VLS_exposed?: NonNullable<Awaited<typeof __VLS_setup>>["expose"], __VLS_setup?: Promise<{
|
|
478
|
+
props: import("vue").PublicProps & __VLS_PrettifyLocal$1<NotFormProps<TSchema>> & (typeof globalThis extends {
|
|
479
|
+
__VLS_PROPS_FALLBACK: infer P;
|
|
480
|
+
} ? P : {});
|
|
481
|
+
expose: (exposed: {}) => void;
|
|
482
|
+
attrs: any;
|
|
483
|
+
slots: NotFormSlots;
|
|
484
|
+
emit: {};
|
|
485
|
+
}>) => import("vue").VNode & {
|
|
486
|
+
__ctx?: NonNullable<Awaited<typeof __VLS_setup>>;
|
|
521
487
|
};
|
|
488
|
+
declare const _default$2: typeof __VLS_export$1;
|
|
489
|
+
type __VLS_PrettifyLocal$1<T> = (T extends any ? { [K in keyof T]: T[K]; } : { [K in keyof T as K]: T[K]; }) & {};
|
|
522
490
|
//#endregion
|
|
523
491
|
//#region src/types/not-message.d.ts
|
|
524
|
-
/**
|
|
525
|
-
|
|
492
|
+
/**
|
|
493
|
+
* Props for `<NotMessage>`.
|
|
494
|
+
* @template TSchema The form schema.
|
|
495
|
+
*/
|
|
496
|
+
interface NotMessageProps<TSchema extends ObjectSchema> {
|
|
526
497
|
/**
|
|
527
|
-
*
|
|
528
|
-
*
|
|
498
|
+
* Root element or component. When a component is given, the message is
|
|
499
|
+
* passed to it as **default slot content**, not as a prop — a component
|
|
500
|
+
* expecting a `message` prop instead will render with no visible text.
|
|
501
|
+
* @default 'span'
|
|
529
502
|
*/
|
|
530
503
|
as?: Component | string;
|
|
531
|
-
/**
|
|
532
|
-
path:
|
|
533
|
-
/**
|
|
534
|
-
|
|
535
|
-
* Takes priority over the instance provided by a `NotForm` ancestor.
|
|
536
|
-
* Required when using `NotMessage` outside of a `NotForm`.
|
|
537
|
-
*/
|
|
538
|
-
form?: NotFormInstance<any>;
|
|
504
|
+
/** Field path whose first error message is shown. */
|
|
505
|
+
path: Paths$1<TSchema>;
|
|
506
|
+
/** Form instance. Overrides `<NotForm>` inject. Required outside `<NotForm>`. */
|
|
507
|
+
form?: NotFormAPI<TSchema>;
|
|
539
508
|
}
|
|
540
|
-
/**
|
|
509
|
+
/** Slot props for `<NotMessage>`. */
|
|
541
510
|
interface NotMessageSlots {
|
|
542
|
-
/** The default slot receives the error message context for custom rendering */
|
|
543
511
|
default?: (props: {
|
|
544
|
-
/**
|
|
512
|
+
/** First active error message for `path`. */
|
|
545
513
|
message?: string;
|
|
546
|
-
}) =>
|
|
514
|
+
}) => void;
|
|
547
515
|
}
|
|
548
516
|
//#endregion
|
|
549
517
|
//#region src/components/not-message.vue.d.ts
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
}
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
518
|
+
declare const __VLS_export: <TSchema extends ObjectSchema>(__VLS_props: NonNullable<Awaited<typeof __VLS_setup>>["props"], __VLS_ctx?: __VLS_PrettifyLocal<Pick<NonNullable<Awaited<typeof __VLS_setup>>, "attrs" | "emit" | "slots">>, __VLS_exposed?: NonNullable<Awaited<typeof __VLS_setup>>["expose"], __VLS_setup?: Promise<{
|
|
519
|
+
props: import("vue").PublicProps & __VLS_PrettifyLocal<NotMessageProps<TSchema>> & (typeof globalThis extends {
|
|
520
|
+
__VLS_PROPS_FALLBACK: infer P;
|
|
521
|
+
} ? P : {});
|
|
522
|
+
expose: (exposed: {}) => void;
|
|
523
|
+
attrs: any;
|
|
524
|
+
slots: NotMessageSlots;
|
|
525
|
+
emit: {};
|
|
526
|
+
}>) => import("vue").VNode & {
|
|
527
|
+
__ctx?: NonNullable<Awaited<typeof __VLS_setup>>;
|
|
560
528
|
};
|
|
529
|
+
declare const _default$3: typeof __VLS_export;
|
|
530
|
+
type __VLS_PrettifyLocal<T> = (T extends any ? { [K in keyof T]: T[K]; } : { [K in keyof T as K]: T[K]; }) & {};
|
|
531
|
+
//#endregion
|
|
532
|
+
//#region src/types/not-form-config.d.ts
|
|
533
|
+
/**
|
|
534
|
+
* Options passed to `useNotForm`.
|
|
535
|
+
* @template TSchema Validation schema.
|
|
536
|
+
*/
|
|
537
|
+
interface UseNotFormConfig<TSchema extends ObjectSchema> {
|
|
538
|
+
/** Schema used to parse and validate values. */
|
|
539
|
+
schema: MaybeRefOrGetter<TSchema>;
|
|
540
|
+
/** Starting values; deep-cloned before use. */
|
|
541
|
+
initialValues?: DeepPartial<InferInput<TSchema>>;
|
|
542
|
+
/** Issues shown before the first validation run. */
|
|
543
|
+
initialErrors?: Array<Issue>;
|
|
544
|
+
/**
|
|
545
|
+
* Called after a successful submit validation.
|
|
546
|
+
* @param data Validated output.
|
|
547
|
+
*/
|
|
548
|
+
onSubmit?: (data: InferOutput<TSchema>) => Promise<void> | void;
|
|
549
|
+
}
|
|
561
550
|
//#endregion
|
|
562
551
|
//#region src/composables/use-not-form.d.ts
|
|
563
552
|
/**
|
|
564
|
-
* Creates a
|
|
565
|
-
* @template TSchema The
|
|
566
|
-
* @param config
|
|
567
|
-
* @returns
|
|
553
|
+
* Creates a form instance and returns the public {@linkcode NotFormAPI}.
|
|
554
|
+
* @template TSchema The form schema.
|
|
555
|
+
* @param config Schema, initial values/errors, and submit handler.
|
|
556
|
+
* @returns Public form API. Child components still inject the full instance via `<NotForm>`.
|
|
568
557
|
*/
|
|
569
|
-
declare function useNotForm<TSchema extends ObjectSchema>(config: UseNotFormConfig<TSchema>):
|
|
558
|
+
declare function useNotForm<TSchema extends ObjectSchema>(config: UseNotFormConfig<TSchema>): NotFormAPI<TSchema>;
|
|
570
559
|
//#endregion
|
|
571
|
-
export {
|
|
560
|
+
export { _default as NotArrayField, type NotArrayFieldItem, type NotArrayFieldProps, type NotArrayFieldSlots, _default$1 as NotField, type NotFieldProps, type NotFieldSlots, _default$2 as NotForm, type NotFormAPI, type NotFormProps, type NotFormSlots, _default$3 as NotMessage, type NotMessageProps, type NotMessageSlots, type UseNotFormConfig, useNotForm };
|