notform 1.0.0-alpha.3 → 1.0.0-alpha.5
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/LICENSE +21 -0
- package/dist/index.d.ts +59 -55
- package/dist/index.js +67 -55
- package/package.json +3 -3
- package/README.md +0 -29
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 NotForm
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/index.d.ts
CHANGED
|
@@ -56,12 +56,12 @@ type Paths<TReference> = Paths$1<TReference, {
|
|
|
56
56
|
leavesOnly: false;
|
|
57
57
|
}> | (string & {});
|
|
58
58
|
//#endregion
|
|
59
|
-
//#region src/types/form.d.ts
|
|
59
|
+
//#region src/types/not-form.d.ts
|
|
60
60
|
/**
|
|
61
61
|
* Configuration options for initializing a new form instance.
|
|
62
62
|
* @template TSchema The validation schema type derived from ObjectSchema.
|
|
63
63
|
*/
|
|
64
|
-
type
|
|
64
|
+
type UseNotFormOptions<TSchema extends ObjectSchema> = {
|
|
65
65
|
/** Unique form identifier (autogenerated if omitted) */
|
|
66
66
|
id?: string;
|
|
67
67
|
/** The validation schema used to parse and validate form data */
|
|
@@ -87,12 +87,17 @@ type UseFormOptions<TSchema extends ObjectSchema> = {
|
|
|
87
87
|
* @param errors The list of identified issues.
|
|
88
88
|
*/
|
|
89
89
|
onError?: (errors: StandardSchemaV1$1.Issue[]) => void;
|
|
90
|
+
/**
|
|
91
|
+
* Callback triggered when form validation passes and form is submitted.
|
|
92
|
+
* @param data The validated data from the schema.
|
|
93
|
+
*/
|
|
94
|
+
onSubmit?: (data: StandardSchemaV1$1.InferOutput<TSchema>) => void | Promise<void>;
|
|
90
95
|
};
|
|
91
96
|
/**
|
|
92
97
|
* The core state and methods provided by a form instance.
|
|
93
98
|
* @template TSchema The validation schema type derived from ObjectSchema.
|
|
94
99
|
*/
|
|
95
|
-
type
|
|
100
|
+
type NotFormContext<TSchema extends ObjectSchema> = {
|
|
96
101
|
/** Unique form identifier */
|
|
97
102
|
id: string;
|
|
98
103
|
/** Deeply reactive object of field values */
|
|
@@ -175,39 +180,38 @@ type FormContext<TSchema extends ObjectSchema> = {
|
|
|
175
180
|
/**
|
|
176
181
|
* Validates and then triggers form submission.
|
|
177
182
|
* @param event The original form submission event.
|
|
178
|
-
* @param callback Callback executed only if validation passes.
|
|
179
183
|
*/
|
|
180
|
-
submit: (event
|
|
184
|
+
submit: (event: Event) => Promise<void>;
|
|
181
185
|
};
|
|
182
186
|
/**
|
|
183
|
-
* Properties accepted by the
|
|
187
|
+
* Properties accepted by the NotForm component.
|
|
184
188
|
* @template TSchema The validation schema type derived from ObjectSchema.
|
|
185
189
|
*/
|
|
186
|
-
type
|
|
190
|
+
type NotFormProps<TSchema extends ObjectSchema> = Pick<NotFormContext<TSchema>, 'id'> & /* @vue-ignore */Omit<FormHTMLAttributes, 'id'>;
|
|
187
191
|
/**
|
|
188
|
-
* Slots provided by the
|
|
192
|
+
* Slots provided by the NotForm component.
|
|
189
193
|
* @template TSchema The validation schema type derived from ObjectSchema.
|
|
190
194
|
*/
|
|
191
|
-
type
|
|
195
|
+
type NotFormSlots<TSchema extends ObjectSchema> = {
|
|
192
196
|
/** The default slot receives the form context as its scope */
|
|
193
|
-
default: (props:
|
|
197
|
+
default: (props: NotFormContext<TSchema>) => VNodeChild;
|
|
194
198
|
};
|
|
195
199
|
/**
|
|
196
|
-
* Expected return type for the
|
|
200
|
+
* Expected return type for the useNotForm composable.
|
|
197
201
|
* @template TSchema The validation schema type derived from ObjectSchema.
|
|
198
202
|
*/
|
|
199
|
-
type
|
|
203
|
+
type UseNotFormReturn<TSchema extends ObjectSchema> = NotFormContext<TSchema>;
|
|
200
204
|
//#endregion
|
|
201
|
-
//#region src/types/field.d.ts
|
|
202
|
-
/** Configuration properties for the
|
|
203
|
-
type
|
|
205
|
+
//#region src/types/not-field.d.ts
|
|
206
|
+
/** Configuration properties for the NotField component */
|
|
207
|
+
type NotFieldProps = {
|
|
204
208
|
/** The unique name/path identifying the field within the form state */
|
|
205
209
|
name: string;
|
|
206
210
|
};
|
|
207
211
|
/**
|
|
208
|
-
* State and methods provided to the
|
|
212
|
+
* State and methods provided to the NotField component's scope.
|
|
209
213
|
*/
|
|
210
|
-
type
|
|
214
|
+
type NotFieldContext = {
|
|
211
215
|
/** The name/path of the field */
|
|
212
216
|
name: string;
|
|
213
217
|
/** Array of validation error messages currently active for this field */
|
|
@@ -235,45 +239,45 @@ type FieldContext = {
|
|
|
235
239
|
};
|
|
236
240
|
};
|
|
237
241
|
/**
|
|
238
|
-
* Slots provided by the
|
|
242
|
+
* Slots provided by the NotField component.
|
|
239
243
|
*/
|
|
240
|
-
type
|
|
244
|
+
type NotFieldSlots = {
|
|
241
245
|
/** The default slot receives the field context for use within templates */
|
|
242
|
-
default: (props:
|
|
246
|
+
default: (props: NotFieldContext) => VNodeChild;
|
|
243
247
|
};
|
|
244
248
|
//#endregion
|
|
245
|
-
//#region src/types/message.d.ts
|
|
249
|
+
//#region src/types/not-message.d.ts
|
|
246
250
|
/**
|
|
247
|
-
* Configuration properties for the
|
|
251
|
+
* Configuration properties for the NotMessage component.
|
|
248
252
|
* @template TSchema The validation schema type derived from ObjectSchema.
|
|
249
253
|
*/
|
|
250
|
-
type
|
|
254
|
+
type NotMessageProps<TSchema extends ObjectSchema> = {
|
|
251
255
|
/** The name/path of the field whose error message should be displayed */
|
|
252
256
|
name: Paths$1<StandardSchemaV1$1.InferInput<TSchema>>;
|
|
253
257
|
};
|
|
254
258
|
/**
|
|
255
|
-
* State provided to the
|
|
259
|
+
* State provided to the NotMessage component's scope.
|
|
256
260
|
*/
|
|
257
|
-
type
|
|
261
|
+
type NotMessageContext = {
|
|
258
262
|
/** The first active validation error message for the specified field */
|
|
259
|
-
message:
|
|
263
|
+
message: NotFieldContext['errors'][number];
|
|
260
264
|
};
|
|
261
265
|
/**
|
|
262
|
-
* Slots provided by the
|
|
266
|
+
* Slots provided by the NotMessage component.
|
|
263
267
|
*/
|
|
264
|
-
type
|
|
268
|
+
type NotMessageSlots = {
|
|
265
269
|
/** The default slot receives the error message context for custom rendering */
|
|
266
|
-
default: (props:
|
|
270
|
+
default: (props: NotMessageContext) => VNodeChild;
|
|
267
271
|
};
|
|
268
272
|
//#endregion
|
|
269
|
-
//#region src/components/
|
|
273
|
+
//#region src/components/not-form.vue.d.ts
|
|
270
274
|
declare const __VLS_export$3: <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<{
|
|
271
|
-
props: vue0.PublicProps & __VLS_PrettifyLocal$2<
|
|
275
|
+
props: vue0.PublicProps & __VLS_PrettifyLocal$2<NotFormProps<TSchema>> & (typeof globalThis extends {
|
|
272
276
|
__VLS_PROPS_FALLBACK: infer P;
|
|
273
277
|
} ? P : {});
|
|
274
278
|
expose: (exposed: {}) => void;
|
|
275
279
|
attrs: any;
|
|
276
|
-
slots:
|
|
280
|
+
slots: NotFormSlots<TSchema>;
|
|
277
281
|
emit: {};
|
|
278
282
|
}>) => vue0.VNode & {
|
|
279
283
|
__ctx?: Awaited<typeof __VLS_setup>;
|
|
@@ -281,12 +285,12 @@ declare const __VLS_export$3: <TSchema extends ObjectSchema>(__VLS_props: NonNul
|
|
|
281
285
|
declare const _default$2: typeof __VLS_export$3;
|
|
282
286
|
type __VLS_PrettifyLocal$2<T> = (T extends any ? { [K in keyof T]: T[K] } : { [K in keyof T as K]: T[K] }) & {};
|
|
283
287
|
//#endregion
|
|
284
|
-
//#region src/components/
|
|
288
|
+
//#region src/components/not-field.vue.d.ts
|
|
285
289
|
/**
|
|
286
|
-
* Slots provided by the
|
|
290
|
+
* Slots provided by the NotField component.
|
|
287
291
|
*/
|
|
288
|
-
type __VLS_Slots =
|
|
289
|
-
declare const __VLS_base: vue0.DefineComponent<
|
|
292
|
+
type __VLS_Slots = NotFieldSlots;
|
|
293
|
+
declare const __VLS_base: vue0.DefineComponent<NotFieldProps, {}, {}, {}, {}, vue0.ComponentOptionsMixin, vue0.ComponentOptionsMixin, {}, string, vue0.PublicProps, Readonly<NotFieldProps> & Readonly<{}>, {}, {}, {}, {}, string, vue0.ComponentProvideOptions, false, {}, any>;
|
|
290
294
|
declare const __VLS_export$2: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
|
|
291
295
|
declare const _default$1: typeof __VLS_export$2;
|
|
292
296
|
type __VLS_WithSlots<T, S> = T & {
|
|
@@ -295,14 +299,14 @@ type __VLS_WithSlots<T, S> = T & {
|
|
|
295
299
|
};
|
|
296
300
|
};
|
|
297
301
|
//#endregion
|
|
298
|
-
//#region src/components/
|
|
302
|
+
//#region src/components/not-message.vue.d.ts
|
|
299
303
|
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<{
|
|
300
|
-
props: vue0.PublicProps & __VLS_PrettifyLocal$1<
|
|
304
|
+
props: vue0.PublicProps & __VLS_PrettifyLocal$1<NotMessageProps<TSchema>> & (typeof globalThis extends {
|
|
301
305
|
__VLS_PROPS_FALLBACK: infer P;
|
|
302
306
|
} ? P : {});
|
|
303
307
|
expose: (exposed: {}) => void;
|
|
304
308
|
attrs: any;
|
|
305
|
-
slots:
|
|
309
|
+
slots: NotMessageSlots;
|
|
306
310
|
emit: {};
|
|
307
311
|
}>) => vue0.VNode & {
|
|
308
312
|
__ctx?: Awaited<typeof __VLS_setup>;
|
|
@@ -310,22 +314,22 @@ declare const __VLS_export$1: <TSchema extends ObjectSchema>(__VLS_props: NonNul
|
|
|
310
314
|
declare const _default$3: typeof __VLS_export$1;
|
|
311
315
|
type __VLS_PrettifyLocal$1<T> = (T extends any ? { [K in keyof T]: T[K] } : { [K in keyof T as K]: T[K] }) & {};
|
|
312
316
|
//#endregion
|
|
313
|
-
//#region src/types/array-field.d.ts
|
|
317
|
+
//#region src/types/not-array-field.d.ts
|
|
314
318
|
/**
|
|
315
|
-
* Properties accepted by the
|
|
319
|
+
* Properties accepted by the NotArrayField component.
|
|
316
320
|
* @template TSchema The schema of the array field.
|
|
317
321
|
*/
|
|
318
|
-
type
|
|
322
|
+
type NotArrayFieldProps<TSchema extends ArraySchema> = {
|
|
319
323
|
/** The unique name/path identifying the array field in the form state */
|
|
320
324
|
name: string;
|
|
321
325
|
/** The specific schema instance used to validate the array items */
|
|
322
326
|
schema: TSchema;
|
|
323
327
|
};
|
|
324
328
|
/**
|
|
325
|
-
* The core state and methods provided by an
|
|
329
|
+
* The core state and methods provided by an NotArrayField instance.
|
|
326
330
|
* @template TSchema The schema of the array field.
|
|
327
331
|
*/
|
|
328
|
-
type
|
|
332
|
+
type NotArrayFieldContext<TSchema extends ArraySchema> = {
|
|
329
333
|
/**
|
|
330
334
|
* Array of individual field contexts for each item in the collection.
|
|
331
335
|
* Useful for mapping components to array elements.
|
|
@@ -367,22 +371,22 @@ type ArrayFieldContext<TSchema extends ArraySchema> = {
|
|
|
367
371
|
update: (index: number, data: StandardSchemaV1$1.InferInput<TSchema>[number]) => void;
|
|
368
372
|
};
|
|
369
373
|
/**
|
|
370
|
-
* Slots provided by the
|
|
374
|
+
* Slots provided by the NotArrayField component.
|
|
371
375
|
* @template TSchema The schema of the array field.
|
|
372
376
|
*/
|
|
373
|
-
type
|
|
377
|
+
type NotArrayFieldSlots<TSchema extends ArraySchema> = {
|
|
374
378
|
/** The default slot receives the array field context as its scope */
|
|
375
|
-
default: (props:
|
|
379
|
+
default: (props: NotArrayFieldContext<TSchema>) => VNodeChild;
|
|
376
380
|
};
|
|
377
381
|
//#endregion
|
|
378
|
-
//#region src/components/
|
|
382
|
+
//#region src/components/not-array-field.vue.d.ts
|
|
379
383
|
declare const __VLS_export: <TArraySchema extends ArraySchema, TObjectSchema extends ObjectSchema = 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<{
|
|
380
|
-
props: vue0.PublicProps & __VLS_PrettifyLocal<
|
|
384
|
+
props: vue0.PublicProps & __VLS_PrettifyLocal<NotArrayFieldProps<TArraySchema>> & (typeof globalThis extends {
|
|
381
385
|
__VLS_PROPS_FALLBACK: infer P;
|
|
382
386
|
} ? P : {});
|
|
383
387
|
expose: (exposed: {}) => void;
|
|
384
388
|
attrs: any;
|
|
385
|
-
slots:
|
|
389
|
+
slots: NotArrayFieldSlots<TArraySchema>;
|
|
386
390
|
emit: {};
|
|
387
391
|
}>) => vue0.VNode & {
|
|
388
392
|
__ctx?: Awaited<typeof __VLS_setup>;
|
|
@@ -390,16 +394,16 @@ declare const __VLS_export: <TArraySchema extends ArraySchema, TObjectSchema ext
|
|
|
390
394
|
declare const _default: typeof __VLS_export;
|
|
391
395
|
type __VLS_PrettifyLocal<T> = (T extends any ? { [K in keyof T]: T[K] } : { [K in keyof T as K]: T[K] }) & {};
|
|
392
396
|
//#endregion
|
|
393
|
-
//#region src/composables/use-form.d.ts
|
|
397
|
+
//#region src/composables/use-not-form.d.ts
|
|
394
398
|
/**
|
|
395
399
|
* Initializes a form instance with validation logic, reactive state, and lifecycle methods.
|
|
396
400
|
* @template TSchema The validation schema type derived from ObjectSchema.
|
|
397
401
|
* @param options Configuration object for the form behavior and initial state.
|
|
398
402
|
* @returns The gathered form context object.
|
|
399
403
|
*/
|
|
400
|
-
declare function
|
|
404
|
+
declare function useNotForm<TSchema extends ObjectSchema>(options: UseNotFormOptions<TSchema>): UseNotFormReturn<TSchema>;
|
|
401
405
|
//#endregion
|
|
402
|
-
//#region src/utils/form-context.d.ts
|
|
406
|
+
//#region src/utils/not-form-context.d.ts
|
|
403
407
|
/**
|
|
404
408
|
* Locates and returns the active form context associated with a given ID.
|
|
405
409
|
* @template TSchema The validation schema type derived from ObjectSchema.
|
|
@@ -407,6 +411,6 @@ declare function useForm<TSchema extends ObjectSchema>(options: UseFormOptions<T
|
|
|
407
411
|
* @returns The resolved form context object.
|
|
408
412
|
* @throws Error if the context cannot be found in the current component tree.
|
|
409
413
|
*/
|
|
410
|
-
declare function withContext<TSchema extends ObjectSchema>(id: string):
|
|
414
|
+
declare function withContext<TSchema extends ObjectSchema>(id: string): NotFormContext<TSchema>;
|
|
411
415
|
//#endregion
|
|
412
|
-
export {
|
|
416
|
+
export { ArraySchema, DeepPartial, _default as NotArrayField, _default$1 as NotField, NotFieldContext, NotFieldProps, NotFieldSlots, _default$2 as NotForm, NotFormContext, NotFormProps, NotFormSlots, _default$3 as NotMessage, NotMessageContext, NotMessageProps, NotMessageSlots, ObjectSchema, Paths, type StandardSchemaV1, UseNotFormOptions, UseNotFormReturn, ValidationMode, ValidationTriggers, useNotForm, withContext };
|
package/dist/index.js
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
import { computed, createElementBlock, createElementVNode, defineComponent, guardReactiveProps, inject, mergeProps, nextTick, normalizeProps, onMounted, openBlock, provide, reactive, ref, renderSlot, toDisplayString, toValue, unref, useId, vShow, withDirectives } from "vue";
|
|
2
2
|
import { getProperty, parsePath, setProperty } from "dot-prop";
|
|
3
3
|
|
|
4
|
-
//#region src/utils/form-context.ts
|
|
4
|
+
//#region src/utils/not-form-context.ts
|
|
5
5
|
/** Internal registry mapping form IDs to their injection keys */
|
|
6
|
-
const
|
|
6
|
+
const notFormContextKeys = /* @__PURE__ */ new Map();
|
|
7
7
|
/** Injection key for the unique identifier of the current active form */
|
|
8
|
-
const
|
|
8
|
+
const CURRENT_NOT_FORM_ID_KEY = Symbol("notform:id");
|
|
9
9
|
/**
|
|
10
10
|
* Retrieves an existing injection key or creates a new one for a form ID.
|
|
11
11
|
* @template TSchema The validation schema type derived from ObjectSchema.
|
|
12
12
|
* @param id The unique string identifier for the form.
|
|
13
13
|
* @returns A strictly typed InjectionKey for the form context.
|
|
14
14
|
*/
|
|
15
|
-
function
|
|
16
|
-
if (!
|
|
17
|
-
const key = Symbol(`
|
|
18
|
-
|
|
15
|
+
function getNotFormContextKey(id) {
|
|
16
|
+
if (!notFormContextKeys.has(id)) {
|
|
17
|
+
const key = Symbol(`notform:${id}:context`);
|
|
18
|
+
notFormContextKeys.set(id, key);
|
|
19
19
|
}
|
|
20
|
-
return
|
|
20
|
+
return notFormContextKeys.get(id);
|
|
21
21
|
}
|
|
22
22
|
/**
|
|
23
23
|
* Locates and returns the active form context associated with a given ID.
|
|
@@ -27,20 +27,20 @@ function getFormContextKey(id) {
|
|
|
27
27
|
* @throws Error if the context cannot be found in the current component tree.
|
|
28
28
|
*/
|
|
29
29
|
function withContext(id) {
|
|
30
|
-
const context = inject(
|
|
30
|
+
const context = inject(getNotFormContextKey(id));
|
|
31
31
|
if (!context) throw new Error(`No form context found for form with id "${id}"`);
|
|
32
32
|
return context;
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
//#endregion
|
|
36
|
-
//#region src/components/
|
|
36
|
+
//#region src/components/not-form.vue?vue&type=script&setup=true&lang.ts
|
|
37
37
|
const _hoisted_1 = ["id"];
|
|
38
38
|
/**
|
|
39
39
|
* Provides form context and a structural wrapper for form fields.
|
|
40
40
|
* @template TSchema The validation schema type derived from ObjectSchema.
|
|
41
41
|
*/
|
|
42
|
-
var
|
|
43
|
-
__name: "
|
|
42
|
+
var not_form_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ defineComponent({
|
|
43
|
+
__name: "not-form",
|
|
44
44
|
props: { id: {
|
|
45
45
|
type: String,
|
|
46
46
|
required: true
|
|
@@ -51,7 +51,7 @@ var Form_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ defineCom
|
|
|
51
51
|
* Slots provided by the Form component.
|
|
52
52
|
*/
|
|
53
53
|
const form = withContext(props.id);
|
|
54
|
-
provide(
|
|
54
|
+
provide(CURRENT_NOT_FORM_ID_KEY, props.id);
|
|
55
55
|
return (_ctx, _cache) => {
|
|
56
56
|
return openBlock(), createElementBlock("form", mergeProps(_ctx.$attrs, { id: props.id }), [renderSlot(_ctx.$slots, "default", normalizeProps(guardReactiveProps(unref(form))))], 16, _hoisted_1);
|
|
57
57
|
};
|
|
@@ -59,17 +59,17 @@ var Form_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ defineCom
|
|
|
59
59
|
});
|
|
60
60
|
|
|
61
61
|
//#endregion
|
|
62
|
-
//#region src/components/
|
|
63
|
-
var
|
|
62
|
+
//#region src/components/not-form.vue
|
|
63
|
+
var not_form_default = not_form_vue_vue_type_script_setup_true_lang_default;
|
|
64
64
|
|
|
65
65
|
//#endregion
|
|
66
|
-
//#region src/components/
|
|
66
|
+
//#region src/components/not-field.vue?vue&type=script&setup=true&lang.ts
|
|
67
67
|
/**
|
|
68
68
|
* Component for individual form fields.
|
|
69
69
|
* Manages field-level state, validation triggers, and events.
|
|
70
70
|
*/
|
|
71
|
-
var
|
|
72
|
-
__name: "
|
|
71
|
+
var not_field_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ defineComponent({
|
|
72
|
+
__name: "not-field",
|
|
73
73
|
props: { name: {
|
|
74
74
|
type: String,
|
|
75
75
|
required: true
|
|
@@ -77,10 +77,10 @@ var Field_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ defineCo
|
|
|
77
77
|
setup(__props) {
|
|
78
78
|
const props = __props;
|
|
79
79
|
/**
|
|
80
|
-
* Slots provided by the
|
|
80
|
+
* Slots provided by the NotField component.
|
|
81
81
|
*/
|
|
82
|
-
const formID = inject(
|
|
83
|
-
if (!formID) throw new Error("
|
|
82
|
+
const formID = inject(CURRENT_NOT_FORM_ID_KEY);
|
|
83
|
+
if (!formID) throw new Error("NotField must be used inside a NotForm component");
|
|
84
84
|
const { mode, validateOn, touchedFields, dirtyFields, validateField, getFieldErrors, touchField, dirtyField } = withContext(formID);
|
|
85
85
|
/**
|
|
86
86
|
* Triggers validation for this specific field.
|
|
@@ -129,17 +129,17 @@ var Field_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ defineCo
|
|
|
129
129
|
});
|
|
130
130
|
|
|
131
131
|
//#endregion
|
|
132
|
-
//#region src/components/
|
|
133
|
-
var
|
|
132
|
+
//#region src/components/not-field.vue
|
|
133
|
+
var not_field_default = not_field_vue_vue_type_script_setup_true_lang_default;
|
|
134
134
|
|
|
135
135
|
//#endregion
|
|
136
|
-
//#region src/components/
|
|
136
|
+
//#region src/components/not-message.vue?vue&type=script&setup=true&lang.ts
|
|
137
137
|
/**
|
|
138
138
|
* Displays validation error messages for a specific form field.
|
|
139
139
|
* @template TSchema The validation schema type derived from ObjectSchema.
|
|
140
140
|
*/
|
|
141
|
-
var
|
|
142
|
-
__name: "
|
|
141
|
+
var not_message_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ defineComponent({
|
|
142
|
+
__name: "not-message",
|
|
143
143
|
props: { name: {
|
|
144
144
|
type: null,
|
|
145
145
|
required: true
|
|
@@ -149,8 +149,8 @@ var Message_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ define
|
|
|
149
149
|
/**
|
|
150
150
|
* Slots provided by the Message component.
|
|
151
151
|
*/
|
|
152
|
-
const formID = inject(
|
|
153
|
-
if (!formID) throw new Error("Message must be used inside a
|
|
152
|
+
const formID = inject(CURRENT_NOT_FORM_ID_KEY);
|
|
153
|
+
if (!formID) throw new Error("Message must be used inside a NotForm component");
|
|
154
154
|
const { getFieldErrors } = withContext(formID);
|
|
155
155
|
/**
|
|
156
156
|
* The reactive state provided to the component's slot.
|
|
@@ -163,19 +163,19 @@ var Message_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ define
|
|
|
163
163
|
});
|
|
164
164
|
|
|
165
165
|
//#endregion
|
|
166
|
-
//#region src/components/
|
|
167
|
-
var
|
|
166
|
+
//#region src/components/not-message.vue
|
|
167
|
+
var not_message_default = not_message_vue_vue_type_script_setup_true_lang_default;
|
|
168
168
|
|
|
169
169
|
//#endregion
|
|
170
|
-
//#region src/components/
|
|
170
|
+
//#region src/components/not-array-field.vue?vue&type=script&setup=true&lang.ts
|
|
171
171
|
/**
|
|
172
172
|
* Component for managing array-based form fields.
|
|
173
173
|
* Provides methods for adding, removing, and updating array items.
|
|
174
174
|
* @template TArraySchema Schema for the array field.
|
|
175
175
|
* @template TObjectSchema Parent form object schema.
|
|
176
176
|
*/
|
|
177
|
-
var
|
|
178
|
-
__name: "
|
|
177
|
+
var not_array_field_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ defineComponent({
|
|
178
|
+
__name: "not-array-field",
|
|
179
179
|
props: {
|
|
180
180
|
name: {
|
|
181
181
|
type: String,
|
|
@@ -189,10 +189,10 @@ var ArrayField_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ def
|
|
|
189
189
|
setup(__props) {
|
|
190
190
|
const props = __props;
|
|
191
191
|
/**
|
|
192
|
-
* Slots provided by the
|
|
192
|
+
* Slots provided by the NotArrayField component.
|
|
193
193
|
*/
|
|
194
|
-
const formID = inject(
|
|
195
|
-
if (!formID) throw new Error("
|
|
194
|
+
const formID = inject(CURRENT_NOT_FORM_ID_KEY);
|
|
195
|
+
if (!formID) throw new Error("NotArrayField must be used inside a NotForm component");
|
|
196
196
|
const { state, validateField } = withContext(formID);
|
|
197
197
|
/**
|
|
198
198
|
* Reactive bridge between the form state and the specific array field.
|
|
@@ -265,7 +265,7 @@ var ArrayField_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ def
|
|
|
265
265
|
arrayState.value = newArray;
|
|
266
266
|
}
|
|
267
267
|
/**
|
|
268
|
-
* Reactive context object exposed to the
|
|
268
|
+
* Reactive context object exposed to the NotArrayField slot.
|
|
269
269
|
*/
|
|
270
270
|
const context = reactive({
|
|
271
271
|
fields,
|
|
@@ -283,8 +283,8 @@ var ArrayField_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ def
|
|
|
283
283
|
});
|
|
284
284
|
|
|
285
285
|
//#endregion
|
|
286
|
-
//#region src/components/
|
|
287
|
-
var
|
|
286
|
+
//#region src/components/not-array-field.vue
|
|
287
|
+
var not_array_field_default = not_array_field_vue_vue_type_script_setup_true_lang_default;
|
|
288
288
|
|
|
289
289
|
//#endregion
|
|
290
290
|
//#region src/utils/helpers.ts
|
|
@@ -336,19 +336,19 @@ function getObjectPaths(object, prefix = "") {
|
|
|
336
336
|
}
|
|
337
337
|
|
|
338
338
|
//#endregion
|
|
339
|
-
//#region src/composables/use-form.ts
|
|
339
|
+
//#region src/composables/use-not-form.ts
|
|
340
340
|
/**
|
|
341
341
|
* Initializes a form instance with validation logic, reactive state, and lifecycle methods.
|
|
342
342
|
* @template TSchema The validation schema type derived from ObjectSchema.
|
|
343
343
|
* @param options Configuration object for the form behavior and initial state.
|
|
344
344
|
* @returns The gathered form context object.
|
|
345
345
|
*/
|
|
346
|
-
function
|
|
346
|
+
function useNotForm(options) {
|
|
347
347
|
const { id = useId(), schema: _schema, initialErrors: _initialErrors = [], initialState: _initialState = {}, mode = "eager", validateOn = [
|
|
348
348
|
"blur",
|
|
349
349
|
"input",
|
|
350
350
|
"change"
|
|
351
|
-
], onValidate, onReset, onError } = options;
|
|
351
|
+
], onValidate, onReset, onError, onSubmit } = options;
|
|
352
352
|
/** Active validation schema reference */
|
|
353
353
|
const schema = computed(() => toValue(_schema));
|
|
354
354
|
/** Baseline reactive state at creation */
|
|
@@ -482,23 +482,35 @@ function useForm(options) {
|
|
|
482
482
|
const paths = getObjectPaths(context.state.value);
|
|
483
483
|
context.dirtyFields.value = new Set(paths);
|
|
484
484
|
},
|
|
485
|
-
async submit(event
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
485
|
+
async submit(event) {
|
|
486
|
+
try {
|
|
487
|
+
context.touchAllFields();
|
|
488
|
+
context.dirtyAllFields();
|
|
489
|
+
const result = await context.validate();
|
|
490
|
+
if (result.issues) {
|
|
491
|
+
event.preventDefault();
|
|
492
|
+
const errors = [...result.issues];
|
|
493
|
+
context.errors.value = errors;
|
|
494
|
+
onError?.(errors);
|
|
495
|
+
return;
|
|
496
|
+
}
|
|
497
|
+
if (onSubmit) {
|
|
498
|
+
event.preventDefault();
|
|
499
|
+
await onSubmit(result.value);
|
|
500
|
+
}
|
|
501
|
+
} catch {
|
|
502
|
+
event.preventDefault();
|
|
503
|
+
onError?.([{
|
|
504
|
+
message: "An unexpected error occurred during submission",
|
|
505
|
+
path: []
|
|
506
|
+
}]);
|
|
492
507
|
}
|
|
493
|
-
context.touchAllFields();
|
|
494
|
-
context.dirtyAllFields();
|
|
495
|
-
if (callback) await callback(result.value);
|
|
496
508
|
}
|
|
497
509
|
};
|
|
498
|
-
provide(
|
|
510
|
+
provide(getNotFormContextKey(id), context);
|
|
499
511
|
return context;
|
|
500
512
|
}
|
|
501
|
-
var
|
|
513
|
+
var use_not_form_default = useNotForm;
|
|
502
514
|
|
|
503
515
|
//#endregion
|
|
504
|
-
export {
|
|
516
|
+
export { not_array_field_default as NotArrayField, not_field_default as NotField, not_form_default as NotForm, not_message_default as NotMessage, use_not_form_default as useNotForm, withContext };
|
package/package.json
CHANGED
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
8
|
-
"version": "1.0.0-alpha.
|
|
9
|
-
"description": "
|
|
8
|
+
"version": "1.0.0-alpha.5",
|
|
9
|
+
"description": "Effortless Vue Forms Validation",
|
|
10
10
|
"author": "Favour Emeka <favorodera@gmail.com>",
|
|
11
11
|
"license": "MIT",
|
|
12
12
|
"homepage": "https://github.com/favorodera/notform#readme",
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
49
|
"@stylistic/eslint-plugin": "^5.7.0",
|
|
50
|
-
"@types/node": "^25.0.
|
|
50
|
+
"@types/node": "^25.0.10",
|
|
51
51
|
"@vitejs/plugin-vue": "^6.0.3",
|
|
52
52
|
"@vitest/browser-playwright": "^4.0.16",
|
|
53
53
|
"@vitest/eslint-plugin": "^1.6.6",
|
package/README.md
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
# vue-components-starter
|
|
2
|
-
|
|
3
|
-
A starter for creating a Vue component library.
|
|
4
|
-
|
|
5
|
-
## Development
|
|
6
|
-
|
|
7
|
-
- Install dependencies:
|
|
8
|
-
|
|
9
|
-
```bash
|
|
10
|
-
npm install
|
|
11
|
-
```
|
|
12
|
-
|
|
13
|
-
- Run the playground:
|
|
14
|
-
|
|
15
|
-
```bash
|
|
16
|
-
npm run playground
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
-
- Run the unit tests:
|
|
20
|
-
|
|
21
|
-
```bash
|
|
22
|
-
npm run test
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
- Build the library:
|
|
26
|
-
|
|
27
|
-
```bash
|
|
28
|
-
npm run build
|
|
29
|
-
```
|