@volverjs/form-vue 0.0.10-beta.7 → 0.0.10-beta.9
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 +48 -55
- package/dist/VvForm.d.ts +2 -5
- package/dist/VvFormField.d.ts +11 -2
- package/dist/index.d.ts +32 -11
- package/dist/index.es.js +165 -161
- package/dist/index.umd.js +1 -1
- package/dist/types.d.ts +8 -2
- package/package.json +1 -1
- package/src/VvForm.ts +6 -5
- package/src/VvFormField.ts +8 -4
- package/src/index.ts +27 -7
- package/src/types.d.ts +8 -2
package/README.md
CHANGED
|
@@ -33,11 +33,11 @@ npm install @volverjs/form-vue --save
|
|
|
33
33
|
|
|
34
34
|
## Usage
|
|
35
35
|
|
|
36
|
-
`@volverjs/form-vue` allow you to create a Vue 3 form with [`@volverjs/ui-vue`](https://github.com/volverjs/ui-vue) components from a [Zod Object](https://zod.dev/?id=objects) schema. It provides
|
|
36
|
+
`@volverjs/form-vue` allow you to create a Vue 3 form with [`@volverjs/ui-vue`](https://github.com/volverjs/ui-vue) components from a [Zod Object](https://zod.dev/?id=objects) schema. It provides two functions: `createForm()` and `useForm()`.
|
|
37
37
|
|
|
38
38
|
## Plugin
|
|
39
39
|
|
|
40
|
-
`createForm` defines globally three components `VvForm`, `VvFormWrapper`, and `VvFormField` through a [Vue 3 Plugin](https://vuejs.org/guide/reusability/plugins.html).
|
|
40
|
+
`createForm()` defines globally three components `VvForm`, `VvFormWrapper`, and `VvFormField` through a [Vue 3 Plugin](https://vuejs.org/guide/reusability/plugins.html).
|
|
41
41
|
|
|
42
42
|
```typescript
|
|
43
43
|
import { createApp } from 'vue'
|
|
@@ -62,7 +62,7 @@ app.use(form)
|
|
|
62
62
|
app.mount('#app')
|
|
63
63
|
```
|
|
64
64
|
|
|
65
|
-
|
|
65
|
+
If the schema is omitted, the plugin only share the options to the forms created with the [composable](https://github.com/volverjs/form-vue/#composable).
|
|
66
66
|
|
|
67
67
|
### VvForm
|
|
68
68
|
|
|
@@ -137,8 +137,8 @@ To activate **continuos validation** use the `continuosValidation` option or pro
|
|
|
137
137
|
|
|
138
138
|
## Composable
|
|
139
139
|
|
|
140
|
-
`useForm` can be used to create a form programmatically inside a Vue 3 Component.
|
|
141
|
-
The **default settings** are **inherited** from the plugin (if it
|
|
140
|
+
`useForm()` can be used to create a form programmatically inside a Vue 3 Component.
|
|
141
|
+
The **default settings** are **inherited** from the plugin (if it's installed).
|
|
142
142
|
|
|
143
143
|
```vue
|
|
144
144
|
<script lang="ts" setup>
|
|
@@ -166,6 +166,42 @@ The **default settings** are **inherited** from the plugin (if it was defined).
|
|
|
166
166
|
</template>
|
|
167
167
|
```
|
|
168
168
|
|
|
169
|
+
### Outside a Vue 3 Component
|
|
170
|
+
|
|
171
|
+
`useForm()` can create a form also outside a Vue 3 Component, plugin settings are **not inherited**.
|
|
172
|
+
|
|
173
|
+
```ts
|
|
174
|
+
import { formFactory } from '@volverjs/form-vue'
|
|
175
|
+
import { z } from 'zod'
|
|
176
|
+
|
|
177
|
+
const schema = z.object({
|
|
178
|
+
name: z.string(),
|
|
179
|
+
surname: z.string()
|
|
180
|
+
})
|
|
181
|
+
|
|
182
|
+
const {
|
|
183
|
+
VvForm,
|
|
184
|
+
VvFormWrapper,
|
|
185
|
+
VvFormField,
|
|
186
|
+
VvFormTemplate,
|
|
187
|
+
formData,
|
|
188
|
+
status,
|
|
189
|
+
errors
|
|
190
|
+
} = formFactory(schema, {
|
|
191
|
+
lazyLoad: true
|
|
192
|
+
})
|
|
193
|
+
|
|
194
|
+
export default {
|
|
195
|
+
VvForm,
|
|
196
|
+
VvFormWrapper,
|
|
197
|
+
VvFormField,
|
|
198
|
+
VvFormTemplate,
|
|
199
|
+
formData,
|
|
200
|
+
status,
|
|
201
|
+
errors
|
|
202
|
+
}
|
|
203
|
+
```
|
|
204
|
+
|
|
169
205
|
### VvFormWrapper
|
|
170
206
|
|
|
171
207
|
`VvFormWrapper` gives you the validation status of a part of your form.
|
|
@@ -243,19 +279,20 @@ It automatically bind the form data through the `name` attribute. For nested obj
|
|
|
243
279
|
```
|
|
244
280
|
|
|
245
281
|
To render a [`@volverjs/ui-vue`](https://github.com/volverjs/ui-vue) input component, use the `type` attribute.
|
|
282
|
+
By default UI components must be installed globally, they can be lazy-loaded with `lazyLoad` option or prop.
|
|
246
283
|
|
|
247
284
|
```vue
|
|
248
285
|
<template>
|
|
249
286
|
<VvForm>
|
|
250
|
-
<VvFormField type="text" name="username" label="Username" />
|
|
251
|
-
<VvFormField type="password" name="password" label="Password" />
|
|
287
|
+
<VvFormField type="text" name="username" label="Username" lazy-load />
|
|
288
|
+
<VvFormField type="password" name="password" label="Password" lazy-load />
|
|
252
289
|
</VvForm>
|
|
253
290
|
</template>
|
|
254
291
|
```
|
|
255
292
|
|
|
256
293
|
Check the [`VvFormField`](./docs/VvFormField.md) documentation to learn more about form fields.
|
|
257
294
|
|
|
258
|
-
##
|
|
295
|
+
## VvFormTemplate
|
|
259
296
|
|
|
260
297
|
Forms can also be created using a template. A template is an **array of objects** that describes the form fields. All properties that are **not listed** below are passed to the component **as props**.
|
|
261
298
|
|
|
@@ -329,15 +366,10 @@ Forms can also be created using a template. A template is an **array of objects*
|
|
|
329
366
|
Template items, by default, are rendered as a `VvFormField` component but this can be changed using the `vvIs` property. The `vvIs` property can be a string or a component.
|
|
330
367
|
|
|
331
368
|
`vvName` refers to the name of the field in the schema and can be a nested property using **dot notation**.
|
|
332
|
-
|
|
333
369
|
`vvType` refers to the type of the field and can be any of the supported types.
|
|
334
|
-
|
|
335
370
|
`vvDefaultValue` can be used to set default values for the form item.
|
|
336
|
-
|
|
337
371
|
`vvShowValid` can be used to show the valid state of the form item.
|
|
338
|
-
|
|
339
372
|
`vvSlots` can be used to pass a slots to the template item.
|
|
340
|
-
|
|
341
373
|
`vvChildren` is an array of template items which will be wrapped in the parent item.
|
|
342
374
|
|
|
343
375
|
Conditional rendering can be achieved using the `vvIf` and `vvElseIf` properties.
|
|
@@ -412,7 +444,7 @@ Conditional rendering can be achieved using the `vvIf` and `vvElseIf` properties
|
|
|
412
444
|
|
|
413
445
|
`vvElseIf` can be used multiple times. `vvElseIf: true` is like an `else` statement and will be rendered if all previous `vvIf` and `vvElseIf` conditions are false.
|
|
414
446
|
|
|
415
|
-
`vvIf` and `vvElseIf` can be a string or a function. If it is a string it will be evaluated as a **property** of the form data. If it is a function it will be called with the **form context** as the **first argument
|
|
447
|
+
`vvIf` and `vvElseIf` can be a string or a function. If it is a string it will be evaluated as a **property** of the form data. If it is a function it will be called with the **form context** as the **first argument** and must return a boolean.
|
|
416
448
|
|
|
417
449
|
```ts
|
|
418
450
|
{
|
|
@@ -423,7 +455,8 @@ Conditional rendering can be achieved using the `vvIf` and `vvElseIf` properties
|
|
|
423
455
|
}
|
|
424
456
|
```
|
|
425
457
|
|
|
426
|
-
|
|
458
|
+
Also the template schema and all template items can be a function.
|
|
459
|
+
The function will be called with the **form context** as the **first argument**.
|
|
427
460
|
|
|
428
461
|
```ts
|
|
429
462
|
const templateSchema = (ctx) => [
|
|
@@ -450,46 +483,6 @@ const templateSchema = [
|
|
|
450
483
|
]
|
|
451
484
|
```
|
|
452
485
|
|
|
453
|
-
## Outside a Vue 3 Component
|
|
454
|
-
|
|
455
|
-
`formFactory` can be used to create a form outside a Vue 3 Component.
|
|
456
|
-
No settings are inherited.
|
|
457
|
-
|
|
458
|
-
```ts
|
|
459
|
-
import { formFactory } from '@volverjs/form-vue'
|
|
460
|
-
import { z } from 'zod'
|
|
461
|
-
|
|
462
|
-
const schema = z.object({
|
|
463
|
-
name: z.string(),
|
|
464
|
-
surname: z.string()
|
|
465
|
-
})
|
|
466
|
-
|
|
467
|
-
const {
|
|
468
|
-
VvForm,
|
|
469
|
-
VvFormWrapper,
|
|
470
|
-
VvFormField,
|
|
471
|
-
VvFormTemplate,
|
|
472
|
-
formData,
|
|
473
|
-
status,
|
|
474
|
-
errors
|
|
475
|
-
} = formFactory(schema, {
|
|
476
|
-
// lazyLoad: boolean - default false
|
|
477
|
-
// updateThrottle: number - default 500
|
|
478
|
-
// continuosValidation: boolean - default false
|
|
479
|
-
// sideEffects?: (data: any) => void
|
|
480
|
-
})
|
|
481
|
-
|
|
482
|
-
export default {
|
|
483
|
-
VvForm,
|
|
484
|
-
VvFormWrapper,
|
|
485
|
-
VvFormField,
|
|
486
|
-
VvFormTemplate,
|
|
487
|
-
formData,
|
|
488
|
-
status,
|
|
489
|
-
errors
|
|
490
|
-
}
|
|
491
|
-
```
|
|
492
|
-
|
|
493
486
|
## Default Object by Zod Object Schema
|
|
494
487
|
|
|
495
488
|
`defaultObjectBySchema` creates an object by a [Zod Object Schema](https://zod.dev/?id=objects).
|
package/dist/VvForm.d.ts
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
import { type InjectionKey, type DeepReadonly, type Ref } from 'vue';
|
|
2
2
|
import type { z, TypeOf } from 'zod';
|
|
3
|
-
import type { FormSchema, InjectedFormData } from './types';
|
|
3
|
+
import type { FormComponentOptions, FormSchema, InjectedFormData } from './types';
|
|
4
4
|
import { FormStatus } from './enums';
|
|
5
|
-
export declare const defineForm: <Schema extends FormSchema>(schema: Schema, provideKey: InjectionKey<InjectedFormData<Schema>>, options?: {
|
|
6
|
-
updateThrottle?: number;
|
|
7
|
-
continuosValidation?: boolean;
|
|
8
|
-
}) => {
|
|
5
|
+
export declare const defineForm: <Schema extends FormSchema>(schema: Schema, provideKey: InjectionKey<InjectedFormData<Schema>>, options?: FormComponentOptions) => {
|
|
9
6
|
errors: Ref<z.ZodFormattedError<z.TypeOf<Schema>> | undefined>;
|
|
10
7
|
status: Ref<FormStatus | undefined>;
|
|
11
8
|
formData: Ref<Partial<z.TypeOf<Schema> | undefined>>;
|
package/dist/VvFormField.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { type Component, type InjectionKey, type PropType, type Ref, type ConcreteComponent } from 'vue';
|
|
2
2
|
import type { z } from 'zod';
|
|
3
3
|
import { FormFieldType } from './enums';
|
|
4
|
-
import type { InjectedFormData, InjectedFormWrapperData, InjectedFormFieldData,
|
|
5
|
-
export declare const defineFormField: <Schema extends FormSchema>(formProvideKey: InjectionKey<InjectedFormData<Schema>>, wrapperProvideKey: InjectionKey<InjectedFormWrapperData<Schema>>, formFieldInjectionKey: InjectionKey<InjectedFormFieldData<Schema>>, options?:
|
|
4
|
+
import type { InjectedFormData, InjectedFormWrapperData, InjectedFormFieldData, FormFieldComponentOptions, Path, FormSchema } from './types';
|
|
5
|
+
export declare const defineFormField: <Schema extends FormSchema>(formProvideKey: InjectionKey<InjectedFormData<Schema>>, wrapperProvideKey: InjectionKey<InjectedFormWrapperData<Schema>>, formFieldInjectionKey: InjectionKey<InjectedFormFieldData<Schema>>, options?: FormFieldComponentOptions) => import("vue").DefineComponent<{
|
|
6
6
|
type: {
|
|
7
7
|
type: PropType<"number" | "text" | "email" | "password" | "tel" | "url" | "search" | "date" | "time" | "datetimeLocal" | "month" | "week" | "color" | "select" | "checkbox" | "radio" | "textarea" | "radioGroup" | "checkboxGroup" | "combobox" | "custom">;
|
|
8
8
|
validator: (value: FormFieldType) => boolean;
|
|
@@ -28,6 +28,10 @@ export declare const defineFormField: <Schema extends FormSchema>(formProvideKey
|
|
|
28
28
|
type: (ObjectConstructor | NumberConstructor | BooleanConstructor | StringConstructor | ArrayConstructor)[];
|
|
29
29
|
default: undefined;
|
|
30
30
|
};
|
|
31
|
+
lazyLoad: {
|
|
32
|
+
type: BooleanConstructor;
|
|
33
|
+
default: boolean;
|
|
34
|
+
};
|
|
31
35
|
}, {
|
|
32
36
|
component: import("vue").ComputedRef<{
|
|
33
37
|
new (...args: any[]): any;
|
|
@@ -63,6 +67,10 @@ export declare const defineFormField: <Schema extends FormSchema>(formProvideKey
|
|
|
63
67
|
type: (ObjectConstructor | NumberConstructor | BooleanConstructor | StringConstructor | ArrayConstructor)[];
|
|
64
68
|
default: undefined;
|
|
65
69
|
};
|
|
70
|
+
lazyLoad: {
|
|
71
|
+
type: BooleanConstructor;
|
|
72
|
+
default: boolean;
|
|
73
|
+
};
|
|
66
74
|
}>> & {
|
|
67
75
|
onInvalid?: ((...args: any[]) => any) | undefined;
|
|
68
76
|
onValid?: ((...args: any[]) => any) | undefined;
|
|
@@ -80,4 +88,5 @@ export declare const defineFormField: <Schema extends FormSchema>(formProvideKey
|
|
|
80
88
|
is: Component;
|
|
81
89
|
showValid: boolean;
|
|
82
90
|
defaultValue: string | number | boolean | unknown[] | Record<string, any>;
|
|
91
|
+
lazyLoad: boolean;
|
|
83
92
|
}>;
|
package/dist/index.d.ts
CHANGED
|
@@ -4,7 +4,9 @@ import { defineForm } from './VvForm';
|
|
|
4
4
|
import { defineFormWrapper } from './VvFormWrapper';
|
|
5
5
|
import { defineFormTemplate } from './VvFormTemplate';
|
|
6
6
|
import type { InjectedFormData, InjectedFormWrapperData, InjectedFormFieldData, FormComposableOptions, FormPluginOptions, FormTemplateItem, Path, PathValue, FormSchema } from './types';
|
|
7
|
-
export declare const
|
|
7
|
+
export declare const pluginInjectionKey: InjectionKey<FormPluginOptions>;
|
|
8
|
+
export declare const createForm: (options: FormPluginOptions) => Plugin & Partial<ReturnType<typeof useForm>>;
|
|
9
|
+
export declare const useForm: <Schema extends FormSchema>(schema: Schema, options?: FormComposableOptions) => {
|
|
8
10
|
VvForm: {
|
|
9
11
|
new (...args: any[]): {
|
|
10
12
|
$: import("vue").ComponentInternalInstance;
|
|
@@ -318,6 +320,10 @@ export declare const formFactory: <Schema extends FormSchema>(schema: Schema, op
|
|
|
318
320
|
type: (ObjectConstructor | NumberConstructor | BooleanConstructor | StringConstructor | ArrayConstructor)[];
|
|
319
321
|
default: undefined;
|
|
320
322
|
};
|
|
323
|
+
lazyLoad: {
|
|
324
|
+
type: BooleanConstructor;
|
|
325
|
+
default: boolean;
|
|
326
|
+
};
|
|
321
327
|
}, {
|
|
322
328
|
component: import("vue").ComputedRef<{
|
|
323
329
|
new (...args: any[]): any;
|
|
@@ -353,6 +359,10 @@ export declare const formFactory: <Schema extends FormSchema>(schema: Schema, op
|
|
|
353
359
|
type: (ObjectConstructor | NumberConstructor | BooleanConstructor | StringConstructor | ArrayConstructor)[];
|
|
354
360
|
default: undefined;
|
|
355
361
|
};
|
|
362
|
+
lazyLoad: {
|
|
363
|
+
type: BooleanConstructor;
|
|
364
|
+
default: boolean;
|
|
365
|
+
};
|
|
356
366
|
}>> & {
|
|
357
367
|
onInvalid?: ((...args: any[]) => any) | undefined;
|
|
358
368
|
onValid?: ((...args: any[]) => any) | undefined;
|
|
@@ -370,6 +380,7 @@ export declare const formFactory: <Schema extends FormSchema>(schema: Schema, op
|
|
|
370
380
|
is: import("vue").Component;
|
|
371
381
|
showValid: boolean;
|
|
372
382
|
defaultValue: string | number | boolean | unknown[] | Record<string, any>;
|
|
383
|
+
lazyLoad: boolean;
|
|
373
384
|
}>;
|
|
374
385
|
VvFormTemplate: (import("vue").ComponentOptions<any, any, any, import("vue").ComputedOptions, import("vue").MethodOptions, any, any, any> | {
|
|
375
386
|
new (...args: any[]): any;
|
|
@@ -394,9 +405,17 @@ export declare const formFactory: <Schema extends FormSchema>(schema: Schema, op
|
|
|
394
405
|
status: import("vue").Ref<import("./enums").FormStatus | undefined>;
|
|
395
406
|
formData: import("vue").Ref<Partial<import("zod").TypeOf<Schema> | undefined>>;
|
|
396
407
|
};
|
|
397
|
-
export
|
|
398
|
-
export
|
|
399
|
-
|
|
408
|
+
export { FormFieldType } from './enums';
|
|
409
|
+
export { defaultObjectBySchema } from './utils';
|
|
410
|
+
type FormComponent = ReturnType<typeof defineForm>;
|
|
411
|
+
type FormWrapperComponent = ReturnType<typeof defineFormWrapper>;
|
|
412
|
+
type FormFieldComponent = ReturnType<typeof defineFormField>;
|
|
413
|
+
type FormTemplateComponent = ReturnType<typeof defineFormTemplate>;
|
|
414
|
+
export type { InjectedFormData, InjectedFormWrapperData, InjectedFormFieldData, FormComposableOptions, FormPluginOptions, FormComponent, FormWrapperComponent, FormFieldComponent, FormTemplateComponent, FormTemplateItem, Path, PathValue, };
|
|
415
|
+
/**
|
|
416
|
+
* @deprecated Use `useForm()` instead
|
|
417
|
+
*/
|
|
418
|
+
export declare const formFactory: <Schema extends FormSchema>(schema: Schema, options?: FormComposableOptions) => {
|
|
400
419
|
VvForm: {
|
|
401
420
|
new (...args: any[]): {
|
|
402
421
|
$: import("vue").ComponentInternalInstance;
|
|
@@ -710,6 +729,10 @@ export declare const useForm: <Schema extends FormSchema>(schema: Schema, option
|
|
|
710
729
|
type: (ObjectConstructor | NumberConstructor | BooleanConstructor | StringConstructor | ArrayConstructor)[];
|
|
711
730
|
default: undefined;
|
|
712
731
|
};
|
|
732
|
+
lazyLoad: {
|
|
733
|
+
type: BooleanConstructor;
|
|
734
|
+
default: boolean;
|
|
735
|
+
};
|
|
713
736
|
}, {
|
|
714
737
|
component: import("vue").ComputedRef<{
|
|
715
738
|
new (...args: any[]): any;
|
|
@@ -745,6 +768,10 @@ export declare const useForm: <Schema extends FormSchema>(schema: Schema, option
|
|
|
745
768
|
type: (ObjectConstructor | NumberConstructor | BooleanConstructor | StringConstructor | ArrayConstructor)[];
|
|
746
769
|
default: undefined;
|
|
747
770
|
};
|
|
771
|
+
lazyLoad: {
|
|
772
|
+
type: BooleanConstructor;
|
|
773
|
+
default: boolean;
|
|
774
|
+
};
|
|
748
775
|
}>> & {
|
|
749
776
|
onInvalid?: ((...args: any[]) => any) | undefined;
|
|
750
777
|
onValid?: ((...args: any[]) => any) | undefined;
|
|
@@ -762,6 +789,7 @@ export declare const useForm: <Schema extends FormSchema>(schema: Schema, option
|
|
|
762
789
|
is: import("vue").Component;
|
|
763
790
|
showValid: boolean;
|
|
764
791
|
defaultValue: string | number | boolean | unknown[] | Record<string, any>;
|
|
792
|
+
lazyLoad: boolean;
|
|
765
793
|
}>;
|
|
766
794
|
VvFormTemplate: (import("vue").ComponentOptions<any, any, any, import("vue").ComputedOptions, import("vue").MethodOptions, any, any, any> | {
|
|
767
795
|
new (...args: any[]): any;
|
|
@@ -786,10 +814,3 @@ export declare const useForm: <Schema extends FormSchema>(schema: Schema, option
|
|
|
786
814
|
status: import("vue").Ref<import("./enums").FormStatus | undefined>;
|
|
787
815
|
formData: import("vue").Ref<Partial<import("zod").TypeOf<Schema> | undefined>>;
|
|
788
816
|
};
|
|
789
|
-
export { FormFieldType } from './enums';
|
|
790
|
-
export { defaultObjectBySchema } from './utils';
|
|
791
|
-
type FormComponent = ReturnType<typeof defineForm>;
|
|
792
|
-
type FormWrapperComponent = ReturnType<typeof defineFormWrapper>;
|
|
793
|
-
type FormFieldComponent = ReturnType<typeof defineFormField>;
|
|
794
|
-
type FormTemplateComponent = ReturnType<typeof defineFormTemplate>;
|
|
795
|
-
export type { InjectedFormData, InjectedFormWrapperData, InjectedFormFieldData, FormComposableOptions, FormPluginOptions, FormComponent, FormWrapperComponent, FormFieldComponent, FormTemplateComponent, FormTemplateItem, Path, PathValue, };
|
package/dist/index.es.js
CHANGED
|
@@ -1,71 +1,71 @@
|
|
|
1
|
-
import { defineComponent as
|
|
2
|
-
import { watchThrottled as
|
|
3
|
-
import { ZodObject as
|
|
4
|
-
function
|
|
1
|
+
import { defineComponent as G, computed as V, onMounted as X, onBeforeUnmount as Y, inject as O, toRefs as J, watch as w, provide as z, readonly as k, resolveComponent as g, defineAsyncComponent as R, h as x, ref as E, isProxy as T, toRaw as j, withModifiers as F, unref as C, getCurrentInstance as ee } from "vue";
|
|
2
|
+
import { watchThrottled as re } from "@vueuse/core";
|
|
3
|
+
import { ZodObject as M, ZodDefault as te, ZodNullable as ne, ZodSchema as ae, ZodEffects as oe } from "zod";
|
|
4
|
+
function _(e) {
|
|
5
5
|
return Array.isArray(e);
|
|
6
6
|
}
|
|
7
|
-
function
|
|
7
|
+
function se(e) {
|
|
8
8
|
return typeof e < "u";
|
|
9
9
|
}
|
|
10
|
-
function
|
|
10
|
+
function Z(e) {
|
|
11
11
|
return e === null;
|
|
12
12
|
}
|
|
13
|
-
function
|
|
13
|
+
function U(e) {
|
|
14
14
|
return typeof e == "object";
|
|
15
15
|
}
|
|
16
|
-
function
|
|
16
|
+
function q(e) {
|
|
17
17
|
return typeof e == "string";
|
|
18
18
|
}
|
|
19
|
-
function
|
|
19
|
+
function $(e) {
|
|
20
20
|
return typeof e > "u";
|
|
21
21
|
}
|
|
22
|
-
const
|
|
23
|
-
function
|
|
24
|
-
const
|
|
25
|
-
if (!
|
|
26
|
-
return
|
|
27
|
-
const a =
|
|
22
|
+
const ue = /^[0-9]+$/, le = ["__proto__", "prototype", "constructor"];
|
|
23
|
+
function N(e, n, i) {
|
|
24
|
+
const s = se(i) ? i : void 0;
|
|
25
|
+
if (!U(e) || !q(n))
|
|
26
|
+
return s;
|
|
27
|
+
const a = D(n);
|
|
28
28
|
if (a.length !== 0) {
|
|
29
29
|
for (const r of a) {
|
|
30
30
|
if (r === "*")
|
|
31
31
|
continue;
|
|
32
|
-
const
|
|
33
|
-
return
|
|
32
|
+
const l = function(o) {
|
|
33
|
+
return o.map((u) => $(u) || Z(u) ? u : _(u) ? l(u) : u[r]);
|
|
34
34
|
};
|
|
35
|
-
if (
|
|
35
|
+
if (_(e) && !ue.test(r) ? e = l(e) : e = e[r], $(e) || Z(e))
|
|
36
36
|
break;
|
|
37
37
|
}
|
|
38
|
-
return
|
|
38
|
+
return $(e) ? s : e;
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
|
-
function
|
|
42
|
-
if (!
|
|
41
|
+
function P(e, n, i) {
|
|
42
|
+
if (!U(e) || !q(n))
|
|
43
43
|
return;
|
|
44
|
-
const
|
|
45
|
-
if (
|
|
44
|
+
const s = D(n);
|
|
45
|
+
if (s.length === 0)
|
|
46
46
|
return;
|
|
47
|
-
const a =
|
|
47
|
+
const a = s.length;
|
|
48
48
|
for (let r = 0; r < a; r++) {
|
|
49
|
-
const
|
|
49
|
+
const l = s[r];
|
|
50
50
|
if (r === a - 1) {
|
|
51
|
-
e[
|
|
51
|
+
e[l] = i;
|
|
52
52
|
return;
|
|
53
53
|
}
|
|
54
|
-
if (
|
|
55
|
-
const
|
|
56
|
-
for (const
|
|
57
|
-
|
|
54
|
+
if (l === "*" && _(e)) {
|
|
55
|
+
const o = s.slice(r + 1).join(".");
|
|
56
|
+
for (const u of e)
|
|
57
|
+
P(u, o, i);
|
|
58
58
|
return;
|
|
59
59
|
}
|
|
60
|
-
|
|
60
|
+
$(e[l]) && (e[l] = {}), e = e[l];
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
|
-
function
|
|
64
|
-
const
|
|
65
|
-
return
|
|
63
|
+
function D(e) {
|
|
64
|
+
const n = e.split(/[.]|(?:\[(\d|\*)\])/).filter((i) => !!i);
|
|
65
|
+
return n.some((i) => le.indexOf(i) !== -1) ? [] : n;
|
|
66
66
|
}
|
|
67
|
-
var f = /* @__PURE__ */ ((e) => (e.text = "text", e.number = "number", e.email = "email", e.password = "password", e.tel = "tel", e.url = "url", e.search = "search", e.date = "date", e.time = "time", e.datetimeLocal = "datetimeLocal", e.month = "month", e.week = "week", e.color = "color", e.select = "select", e.checkbox = "checkbox", e.radio = "radio", e.textarea = "textarea", e.radioGroup = "radioGroup", e.checkboxGroup = "checkboxGroup", e.combobox = "combobox", e.custom = "custom", e))(f || {}),
|
|
68
|
-
const ie = (e,
|
|
67
|
+
var f = /* @__PURE__ */ ((e) => (e.text = "text", e.number = "number", e.email = "email", e.password = "password", e.tel = "tel", e.url = "url", e.search = "search", e.date = "date", e.time = "time", e.datetimeLocal = "datetimeLocal", e.month = "month", e.week = "week", e.color = "color", e.select = "select", e.checkbox = "checkbox", e.radio = "radio", e.textarea = "textarea", e.radioGroup = "radioGroup", e.checkboxGroup = "checkboxGroup", e.combobox = "combobox", e.custom = "custom", e))(f || {}), L = /* @__PURE__ */ ((e) => (e.invalid = "invalid", e.valid = "valid", e))(L || {});
|
|
68
|
+
const ie = (e, n, i, s) => G({
|
|
69
69
|
name: "FieldComponent",
|
|
70
70
|
props: {
|
|
71
71
|
type: {
|
|
@@ -92,65 +92,69 @@ const ie = (e, o, i, l = {}) => W({
|
|
|
92
92
|
defaultValue: {
|
|
93
93
|
type: [String, Number, Boolean, Array, Object],
|
|
94
94
|
default: void 0
|
|
95
|
+
},
|
|
96
|
+
lazyLoad: {
|
|
97
|
+
type: Boolean,
|
|
98
|
+
default: !1
|
|
95
99
|
}
|
|
96
100
|
},
|
|
97
101
|
emits: ["invalid", "valid", "update:formData", "update:modelValue"],
|
|
98
102
|
expose: ["invalid", "invalidLabel", "errors"],
|
|
99
|
-
setup(a, { slots: r, emit:
|
|
100
|
-
const
|
|
103
|
+
setup(a, { slots: r, emit: l }) {
|
|
104
|
+
const o = V({
|
|
101
105
|
get() {
|
|
102
106
|
if (t != null && t.formData)
|
|
103
|
-
return
|
|
107
|
+
return N(
|
|
104
108
|
Object(t.formData.value),
|
|
105
109
|
String(a.name)
|
|
106
110
|
);
|
|
107
111
|
},
|
|
108
112
|
set(c) {
|
|
109
|
-
t != null && t.formData && (
|
|
113
|
+
t != null && t.formData && (P(
|
|
110
114
|
Object(t.formData.value),
|
|
111
115
|
String(a.name),
|
|
112
116
|
c
|
|
113
|
-
),
|
|
114
|
-
newValue:
|
|
117
|
+
), l("update:modelValue", {
|
|
118
|
+
newValue: o.value,
|
|
115
119
|
formData: t == null ? void 0 : t.formData
|
|
116
120
|
}));
|
|
117
121
|
}
|
|
118
122
|
});
|
|
119
123
|
X(() => {
|
|
120
|
-
|
|
124
|
+
o.value === void 0 && a.defaultValue !== void 0 && (o.value = a.defaultValue);
|
|
121
125
|
}), Y(() => {
|
|
122
126
|
S(), y();
|
|
123
127
|
});
|
|
124
|
-
const
|
|
125
|
-
|
|
126
|
-
const t = O(e), { props: m, name: p } =
|
|
128
|
+
const u = O(n, void 0);
|
|
129
|
+
u && u.fields.value.add(a.name);
|
|
130
|
+
const t = O(e), { props: m, name: p } = J(a), h = V(() => {
|
|
127
131
|
if (t != null && t.errors.value)
|
|
128
|
-
return
|
|
132
|
+
return N(t.errors.value, String(a.name));
|
|
129
133
|
}), d = V(() => {
|
|
130
134
|
var c;
|
|
131
135
|
return (c = h.value) == null ? void 0 : c._errors;
|
|
132
136
|
}), v = V(() => h.value !== void 0), S = w(v, () => {
|
|
133
|
-
v.value ? (
|
|
137
|
+
v.value ? (l("invalid", d.value), u && u.errors.value.set(
|
|
134
138
|
a.name,
|
|
135
139
|
{
|
|
136
140
|
_errors: d.value
|
|
137
141
|
}
|
|
138
|
-
)) : (
|
|
142
|
+
)) : (l("valid", o.value), u && u.errors.value.delete(
|
|
139
143
|
a.name
|
|
140
144
|
));
|
|
141
145
|
}), y = w(
|
|
142
146
|
() => t == null ? void 0 : t.formData,
|
|
143
147
|
() => {
|
|
144
|
-
|
|
148
|
+
l("update:formData", t == null ? void 0 : t.formData);
|
|
145
149
|
},
|
|
146
150
|
{ deep: !0 }
|
|
147
151
|
), b = (c) => {
|
|
148
|
-
|
|
149
|
-
}, I = V(() => typeof m.value == "function" ? m.value(t == null ? void 0 : t.formData) : m.value),
|
|
152
|
+
o.value = c;
|
|
153
|
+
}, I = V(() => typeof m.value == "function" ? m.value(t == null ? void 0 : t.formData) : m.value), W = V(() => ({
|
|
150
154
|
...I.value,
|
|
151
155
|
name: I.value.name ?? a.name,
|
|
152
156
|
invalid: v.value,
|
|
153
|
-
valid: a.showValid ? !!(!v.value &&
|
|
157
|
+
valid: a.showValid ? !!(!v.value && o.value) : void 0,
|
|
154
158
|
type: ((c) => {
|
|
155
159
|
if ([
|
|
156
160
|
f.text,
|
|
@@ -170,10 +174,10 @@ const ie = (e, o, i, l = {}) => W({
|
|
|
170
174
|
return c;
|
|
171
175
|
})(a.type),
|
|
172
176
|
invalidLabel: d.value,
|
|
173
|
-
modelValue:
|
|
177
|
+
modelValue: o.value,
|
|
174
178
|
"onUpdate:modelValue": b
|
|
175
179
|
}));
|
|
176
|
-
return
|
|
180
|
+
return z(i, {
|
|
177
181
|
name: k(p),
|
|
178
182
|
errors: k(h)
|
|
179
183
|
}), { component: V(() => {
|
|
@@ -182,7 +186,7 @@ const ie = (e, o, i, l = {}) => W({
|
|
|
182
186
|
render() {
|
|
183
187
|
var c;
|
|
184
188
|
return ((c = r.default) == null ? void 0 : c.call(r, {
|
|
185
|
-
modelValue:
|
|
189
|
+
modelValue: o.value,
|
|
186
190
|
onUpdate: b,
|
|
187
191
|
invalid: v.value,
|
|
188
192
|
invalidLabel: d.value,
|
|
@@ -192,7 +196,7 @@ const ie = (e, o, i, l = {}) => W({
|
|
|
192
196
|
})) ?? r.defalut;
|
|
193
197
|
}
|
|
194
198
|
};
|
|
195
|
-
if (!
|
|
199
|
+
if (!((s == null ? void 0 : s.lazyLoad) ?? a.lazyLoad)) {
|
|
196
200
|
let c;
|
|
197
201
|
switch (a.type) {
|
|
198
202
|
case f.select:
|
|
@@ -226,7 +230,7 @@ const ie = (e, o, i, l = {}) => W({
|
|
|
226
230
|
);
|
|
227
231
|
}
|
|
228
232
|
return R(async () => {
|
|
229
|
-
switch (
|
|
233
|
+
switch (s != null && s.sideEffects && await Promise.resolve(s.sideEffects(a.type)), a.type) {
|
|
230
234
|
case f.textarea:
|
|
231
235
|
return import("@volverjs/ui-vue/vv-textarea");
|
|
232
236
|
case f.radio:
|
|
@@ -242,43 +246,43 @@ const ie = (e, o, i, l = {}) => W({
|
|
|
242
246
|
}
|
|
243
247
|
return import("@volverjs/ui-vue/vv-input-text");
|
|
244
248
|
});
|
|
245
|
-
}), hasProps:
|
|
249
|
+
}), hasProps: W, invalid: v };
|
|
246
250
|
},
|
|
247
251
|
render() {
|
|
248
252
|
return this.is ? x(this.is, this.hasProps, this.$slots) : this.type === f.custom ? x(this.component, null, this.$slots) : x(this.component, this.hasProps, this.$slots);
|
|
249
253
|
}
|
|
250
|
-
}),
|
|
254
|
+
}), H = (e, n = {}) => {
|
|
251
255
|
const i = (r) => {
|
|
252
|
-
let
|
|
253
|
-
for (;
|
|
254
|
-
|
|
255
|
-
return
|
|
256
|
-
},
|
|
256
|
+
let l = r;
|
|
257
|
+
for (; l instanceof oe; )
|
|
258
|
+
l = l.innerType();
|
|
259
|
+
return l;
|
|
260
|
+
}, s = i(e);
|
|
257
261
|
return {
|
|
258
|
-
...(
|
|
262
|
+
...(s instanceof M ? s._def.unknownKeys === "passthrough" : !1) ? n : {},
|
|
259
263
|
...Object.fromEntries(
|
|
260
|
-
Object.entries(
|
|
261
|
-
const
|
|
264
|
+
Object.entries(s.shape).map(([r, l]) => {
|
|
265
|
+
const o = n[r], u = i(l);
|
|
262
266
|
let t;
|
|
263
|
-
if (
|
|
264
|
-
return [r,
|
|
265
|
-
if (
|
|
266
|
-
const m =
|
|
267
|
+
if (u instanceof te && (t = u._def.defaultValue()), o === null && u instanceof ne)
|
|
268
|
+
return [r, o];
|
|
269
|
+
if (u instanceof ae) {
|
|
270
|
+
const m = u.safeParse(n[r]);
|
|
267
271
|
if (m.success)
|
|
268
272
|
return [r, m.data ?? t];
|
|
269
273
|
}
|
|
270
|
-
return
|
|
274
|
+
return u instanceof M ? [
|
|
271
275
|
r,
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
276
|
+
H(
|
|
277
|
+
u,
|
|
278
|
+
o && typeof o == "object" ? o : {}
|
|
275
279
|
)
|
|
276
280
|
] : [r, t];
|
|
277
281
|
})
|
|
278
282
|
)
|
|
279
283
|
};
|
|
280
|
-
},
|
|
281
|
-
const
|
|
284
|
+
}, fe = (e, n, i) => {
|
|
285
|
+
const s = E(), a = E(), r = E(), l = G({
|
|
282
286
|
name: "FormComponent",
|
|
283
287
|
props: {
|
|
284
288
|
modelValue: {
|
|
@@ -296,11 +300,11 @@ const ie = (e, o, i, l = {}) => W({
|
|
|
296
300
|
},
|
|
297
301
|
emits: ["invalid", "valid", "submit", "update:modelValue"],
|
|
298
302
|
expose: ["submit", "errors", "status"],
|
|
299
|
-
setup(
|
|
300
|
-
r.value =
|
|
301
|
-
const t = (i == null ? void 0 : i.continuosValidation) ??
|
|
303
|
+
setup(o, { emit: u }) {
|
|
304
|
+
r.value = H(e, o.modelValue);
|
|
305
|
+
const t = (i == null ? void 0 : i.continuosValidation) ?? o.continuosValidation;
|
|
302
306
|
w(
|
|
303
|
-
() =>
|
|
307
|
+
() => o.modelValue,
|
|
304
308
|
(d) => {
|
|
305
309
|
if (d) {
|
|
306
310
|
const v = T(d) ? j(d) : d;
|
|
@@ -308,30 +312,30 @@ const ie = (e, o, i, l = {}) => W({
|
|
|
308
312
|
}
|
|
309
313
|
},
|
|
310
314
|
{ deep: !0 }
|
|
311
|
-
),
|
|
315
|
+
), re(
|
|
312
316
|
r,
|
|
313
317
|
(d) => {
|
|
314
|
-
(
|
|
318
|
+
(s.value || t) && m(), (!d || !o.modelValue || JSON.stringify(d) !== JSON.stringify(o.modelValue)) && u("update:modelValue", d);
|
|
315
319
|
},
|
|
316
320
|
{
|
|
317
321
|
deep: !0,
|
|
318
|
-
throttle: (i == null ? void 0 : i.updateThrottle) ??
|
|
322
|
+
throttle: (i == null ? void 0 : i.updateThrottle) ?? o.updateThrottle
|
|
319
323
|
}
|
|
320
324
|
);
|
|
321
325
|
const m = (d = r.value) => {
|
|
322
326
|
const v = e.safeParse(d);
|
|
323
|
-
return v.success ? (
|
|
324
|
-
}, p = () => m() ? (
|
|
325
|
-
return
|
|
327
|
+
return v.success ? (s.value = void 0, a.value = L.valid, r.value = v.data, u("update:modelValue", r.value), u("valid", v.data), !0) : (s.value = v.error.format(), a.value = L.invalid, u("invalid", s.value), !1);
|
|
328
|
+
}, p = () => m() ? (u("submit", r.value), !0) : !1, h = V(() => a.value === L.invalid);
|
|
329
|
+
return z(n, {
|
|
326
330
|
formData: r,
|
|
327
331
|
submit: p,
|
|
328
|
-
errors: k(
|
|
332
|
+
errors: k(s),
|
|
329
333
|
status: k(a),
|
|
330
334
|
invalid: h
|
|
331
335
|
}), {
|
|
332
336
|
formData: r,
|
|
333
337
|
submit: p,
|
|
334
|
-
errors: k(
|
|
338
|
+
errors: k(s),
|
|
335
339
|
status: k(a),
|
|
336
340
|
invalid: h
|
|
337
341
|
};
|
|
@@ -344,8 +348,8 @@ const ie = (e, o, i, l = {}) => W({
|
|
|
344
348
|
},
|
|
345
349
|
{
|
|
346
350
|
default: () => {
|
|
347
|
-
var
|
|
348
|
-
return ((
|
|
351
|
+
var o, u;
|
|
352
|
+
return ((u = (o = this.$slots) == null ? void 0 : o.default) == null ? void 0 : u.call(o, {
|
|
349
353
|
formData: this.formData,
|
|
350
354
|
submit: this.submit,
|
|
351
355
|
errors: this.errors,
|
|
@@ -358,15 +362,15 @@ const ie = (e, o, i, l = {}) => W({
|
|
|
358
362
|
}
|
|
359
363
|
});
|
|
360
364
|
return {
|
|
361
|
-
errors:
|
|
365
|
+
errors: s,
|
|
362
366
|
status: a,
|
|
363
367
|
formData: r,
|
|
364
368
|
/**
|
|
365
369
|
* An hack to add types to the default slot
|
|
366
370
|
*/
|
|
367
|
-
VvForm:
|
|
371
|
+
VvForm: l
|
|
368
372
|
};
|
|
369
|
-
},
|
|
373
|
+
}, ce = (e, n) => G({
|
|
370
374
|
name: "WrapperComponent",
|
|
371
375
|
props: {
|
|
372
376
|
name: {
|
|
@@ -380,79 +384,79 @@ const ie = (e, o, i, l = {}) => W({
|
|
|
380
384
|
},
|
|
381
385
|
emits: ["invalid", "valid"],
|
|
382
386
|
expose: ["fields", "invalid"],
|
|
383
|
-
setup(
|
|
384
|
-
const r = O(e),
|
|
385
|
-
|
|
387
|
+
setup(s, { emit: a }) {
|
|
388
|
+
const r = O(e), l = O(n, void 0), o = E(/* @__PURE__ */ new Set()), u = E(/* @__PURE__ */ new Map()), { name: t } = J(s);
|
|
389
|
+
z(n, {
|
|
386
390
|
name: k(t),
|
|
387
|
-
errors:
|
|
388
|
-
fields:
|
|
391
|
+
errors: u,
|
|
392
|
+
fields: o
|
|
389
393
|
}), w(
|
|
390
|
-
|
|
394
|
+
o,
|
|
391
395
|
(p) => {
|
|
392
|
-
|
|
393
|
-
|
|
396
|
+
l != null && l.fields && p.forEach((h) => {
|
|
397
|
+
l == null || l.fields.value.add(h);
|
|
394
398
|
});
|
|
395
399
|
},
|
|
396
400
|
{ deep: !0 }
|
|
397
401
|
), w(
|
|
398
|
-
() => new Map(
|
|
402
|
+
() => new Map(u.value),
|
|
399
403
|
(p, h) => {
|
|
400
|
-
|
|
401
|
-
|
|
404
|
+
l != null && l.errors && (Array.from(h.keys()).forEach((d) => {
|
|
405
|
+
l.errors.value.delete(d);
|
|
402
406
|
}), Array.from(p.keys()).forEach((d) => {
|
|
403
407
|
const v = p.get(d);
|
|
404
|
-
v &&
|
|
408
|
+
v && l.errors.value.set(d, v);
|
|
405
409
|
}));
|
|
406
410
|
},
|
|
407
411
|
{ deep: !0 }
|
|
408
412
|
);
|
|
409
|
-
const m = V(() => r != null && r.invalid.value ?
|
|
413
|
+
const m = V(() => r != null && r.invalid.value ? u.value.size > 0 : !1);
|
|
410
414
|
return w(m, () => {
|
|
411
415
|
m.value ? a("invalid") : a("valid");
|
|
412
416
|
}), {
|
|
413
417
|
formData: r == null ? void 0 : r.formData,
|
|
414
418
|
errors: r == null ? void 0 : r.errors,
|
|
415
419
|
invalid: m,
|
|
416
|
-
fields:
|
|
417
|
-
fieldsErrors:
|
|
420
|
+
fields: o,
|
|
421
|
+
fieldsErrors: u
|
|
418
422
|
};
|
|
419
423
|
},
|
|
420
424
|
render() {
|
|
421
|
-
var
|
|
425
|
+
var s, a;
|
|
422
426
|
return this.tag ? x(this.tag, null, {
|
|
423
427
|
default: () => {
|
|
424
|
-
var r,
|
|
425
|
-
return ((
|
|
428
|
+
var r, l;
|
|
429
|
+
return ((l = (r = this.$slots).default) == null ? void 0 : l.call(r, {
|
|
426
430
|
invalid: this.invalid,
|
|
427
431
|
formData: this.formData,
|
|
428
432
|
errors: this.errors,
|
|
429
433
|
fieldsErrors: this.fieldsErrors
|
|
430
434
|
})) ?? this.$slots.defalut;
|
|
431
435
|
}
|
|
432
|
-
}) : ((a = (
|
|
436
|
+
}) : ((a = (s = this.$slots).default) == null ? void 0 : a.call(s, {
|
|
433
437
|
invalid: this.invalid,
|
|
434
438
|
formData: this.formData,
|
|
435
439
|
errors: this.errors,
|
|
436
440
|
fieldsErrors: this.fieldsErrors
|
|
437
441
|
})) ?? this.$slots.defalut;
|
|
438
442
|
}
|
|
439
|
-
}),
|
|
440
|
-
const i =
|
|
443
|
+
}), de = (e, n) => {
|
|
444
|
+
const i = G({
|
|
441
445
|
props: {
|
|
442
446
|
schema: {
|
|
443
447
|
type: [Array, Function],
|
|
444
448
|
required: !0
|
|
445
449
|
}
|
|
446
450
|
},
|
|
447
|
-
setup(
|
|
451
|
+
setup(s, { slots: a }) {
|
|
448
452
|
const r = O(e);
|
|
449
453
|
if (!(r != null && r.formData))
|
|
450
454
|
return;
|
|
451
|
-
const
|
|
452
|
-
let
|
|
455
|
+
const l = typeof s.schema == "function" ? s.schema(r) : s.schema;
|
|
456
|
+
let o;
|
|
453
457
|
return () => {
|
|
454
|
-
var
|
|
455
|
-
return
|
|
458
|
+
var u;
|
|
459
|
+
return l.reduce(
|
|
456
460
|
(t, m) => {
|
|
457
461
|
const p = typeof m == "function" ? m(r) : m, {
|
|
458
462
|
vvIs: h,
|
|
@@ -462,50 +466,50 @@ const ie = (e, o, i, l = {}) => W({
|
|
|
462
466
|
vvIf: y,
|
|
463
467
|
vvElseIf: b,
|
|
464
468
|
vvType: I,
|
|
465
|
-
vvDefaultValue:
|
|
469
|
+
vvDefaultValue: W,
|
|
466
470
|
vvShowValid: K,
|
|
467
471
|
...c
|
|
468
472
|
} = p;
|
|
469
473
|
if (y !== void 0) {
|
|
470
|
-
if (typeof y == "string" ?
|
|
474
|
+
if (typeof y == "string" ? o = !!N(
|
|
471
475
|
Object(r.formData.value),
|
|
472
476
|
y
|
|
473
|
-
) : typeof y == "function" ?
|
|
477
|
+
) : typeof y == "function" ? o = C(y(r)) : o = C(y), !o)
|
|
474
478
|
return t;
|
|
475
|
-
} else if (b !== void 0 &&
|
|
476
|
-
if (
|
|
479
|
+
} else if (b !== void 0 && o !== void 0) {
|
|
480
|
+
if (o || (typeof b == "string" ? o = !!N(
|
|
477
481
|
Object(r.formData.value),
|
|
478
482
|
b
|
|
479
|
-
) : typeof b == "function" ?
|
|
483
|
+
) : typeof b == "function" ? o = C(b(r)) : o = C(b), !o))
|
|
480
484
|
return t;
|
|
481
485
|
} else
|
|
482
|
-
|
|
483
|
-
const
|
|
486
|
+
o = void 0;
|
|
487
|
+
const A = S ? x(i, {
|
|
484
488
|
schema: S
|
|
485
489
|
}) : void 0;
|
|
486
490
|
return d ? (t.push(
|
|
487
491
|
x(
|
|
488
|
-
|
|
492
|
+
n,
|
|
489
493
|
{
|
|
490
494
|
name: d,
|
|
491
495
|
is: h,
|
|
492
496
|
type: I,
|
|
493
|
-
defaultValue:
|
|
497
|
+
defaultValue: W,
|
|
494
498
|
showValid: K,
|
|
495
499
|
props: c
|
|
496
500
|
},
|
|
497
|
-
v ??
|
|
501
|
+
v ?? A
|
|
498
502
|
)
|
|
499
503
|
), t) : h ? (t.push(
|
|
500
504
|
x(
|
|
501
505
|
h,
|
|
502
506
|
c,
|
|
503
|
-
v ??
|
|
507
|
+
v ?? A
|
|
504
508
|
)
|
|
505
|
-
), t) : (S && t.push(
|
|
509
|
+
), t) : (S && t.push(A), t);
|
|
506
510
|
},
|
|
507
511
|
[
|
|
508
|
-
(
|
|
512
|
+
(u = a == null ? void 0 : a.default) == null ? void 0 : u.call(a, {
|
|
509
513
|
formData: r == null ? void 0 : r.formData.value,
|
|
510
514
|
submit: r == null ? void 0 : r.submit,
|
|
511
515
|
errors: r == null ? void 0 : r.errors.value,
|
|
@@ -518,49 +522,49 @@ const ie = (e, o, i, l = {}) => W({
|
|
|
518
522
|
}
|
|
519
523
|
});
|
|
520
524
|
return i;
|
|
521
|
-
},
|
|
522
|
-
const i = Symbol(),
|
|
525
|
+
}, B = (e, n = {}) => {
|
|
526
|
+
const i = Symbol(), s = Symbol(), a = Symbol(), { VvForm: r, errors: l, status: o, formData: u } = fe(
|
|
523
527
|
e,
|
|
524
528
|
i,
|
|
525
|
-
|
|
526
|
-
), t =
|
|
529
|
+
n
|
|
530
|
+
), t = ce(
|
|
527
531
|
i,
|
|
528
|
-
|
|
532
|
+
s
|
|
529
533
|
), m = ie(
|
|
530
534
|
i,
|
|
531
|
-
|
|
535
|
+
s,
|
|
532
536
|
a,
|
|
533
|
-
|
|
534
|
-
), p =
|
|
537
|
+
n
|
|
538
|
+
), p = de(i, m);
|
|
535
539
|
return {
|
|
536
540
|
VvForm: r,
|
|
537
541
|
VvFormWrapper: t,
|
|
538
542
|
VvFormField: m,
|
|
539
543
|
VvFormTemplate: p,
|
|
540
544
|
formInjectionKey: i,
|
|
541
|
-
formWrapperInjectionKey:
|
|
545
|
+
formWrapperInjectionKey: s,
|
|
542
546
|
formFieldInjectionKey: a,
|
|
543
|
-
errors:
|
|
544
|
-
status:
|
|
545
|
-
formData:
|
|
547
|
+
errors: l,
|
|
548
|
+
status: o,
|
|
549
|
+
formData: u
|
|
546
550
|
};
|
|
547
|
-
}, Q = Symbol(),
|
|
548
|
-
let
|
|
549
|
-
return e.schema && (
|
|
550
|
-
...
|
|
551
|
-
install(i, { global:
|
|
552
|
-
i.provide(Q, e),
|
|
551
|
+
}, Q = Symbol(), pe = (e) => {
|
|
552
|
+
let n = {};
|
|
553
|
+
return e.schema && (n = B(e.schema, e)), {
|
|
554
|
+
...n,
|
|
555
|
+
install(i, { global: s = !1 } = {}) {
|
|
556
|
+
i.provide(Q, e), s && (i.config.globalProperties.$vvForm = e, n != null && n.VvForm && i.component("VvForm", n.VvForm), n != null && n.VvFormWrapper && i.component("VvFormWrapper", n.VvFormWrapper), n != null && n.VvFormField && i.component("VvFormField", n.VvFormField), n != null && n.VvFormTemplate && i.component("VvFormTemplate", n.VvFormTemplate));
|
|
553
557
|
}
|
|
554
558
|
};
|
|
555
|
-
},
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
};
|
|
559
|
+
}, be = (e, n = {}) => ee() ? B(e, {
|
|
560
|
+
...O(Q, {}),
|
|
561
|
+
...n
|
|
562
|
+
}) : B(e, n), Ve = (e, n = {}) => B(e, n);
|
|
559
563
|
export {
|
|
560
564
|
f as FormFieldType,
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
565
|
+
pe as createForm,
|
|
566
|
+
H as defaultObjectBySchema,
|
|
567
|
+
Ve as formFactory,
|
|
564
568
|
Q as pluginInjectionKey,
|
|
565
|
-
|
|
569
|
+
be as useForm
|
|
566
570
|
};
|
package/dist/index.umd.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(y,t){typeof exports=="object"&&typeof module<"u"?t(exports,require("vue"),require("@vueuse/core"),require("zod")):typeof define=="function"&&define.amd?define(["exports","vue","@vueuse/core","zod"],t):(y=typeof globalThis<"u"?globalThis:y||self,t(y["@volverjs/form-vue"]={},y.Vue,y.VueUseCore,y.zod))})(this,function(y,t,M,x){"use strict";function E(e){return Array.isArray(e)}function Z(e){return typeof e<"u"}function W(e){return e===null}function A(e){return typeof e=="object"}function L(e){return typeof e=="string"}function k(e){return typeof e>"u"}const U=/^[0-9]+$/,J=["__proto__","prototype","constructor"];function O(e,s,u){const f=Z(u)?u:void 0;if(!A(e)||!L(s))return f;const a=K(s);if(a.length!==0){for(const r of a){if(r==="*")continue;const l=function(o){return o.map(i=>k(i)||W(i)?i:E(i)?l(i):i[r])};if(E(e)&&!U.test(r)?e=l(e):e=e[r],k(e)||W(e))break}return k(e)?f:e}}function _(e,s,u){if(!A(e)||!L(s))return;const f=K(s);if(f.length===0)return;const a=f.length;for(let r=0;r<a;r++){const l=f[r];if(r===a-1){e[l]=u;return}if(l==="*"&&E(e)){const o=f.slice(r+1).join(".");for(const i of e)_(i,o,u);return}k(e[l])&&(e[l]={}),e=e[l]}}function K(e){const s=e.split(/[.]|(?:\[(\d|\*)\])/).filter(u=>!!u);return s.some(u=>J.indexOf(u)!==-1)?[]:s}var c=(e=>(e.text="text",e.number="number",e.email="email",e.password="password",e.tel="tel",e.url="url",e.search="search",e.date="date",e.time="time",e.datetimeLocal="datetimeLocal",e.month="month",e.week="week",e.color="color",e.select="select",e.checkbox="checkbox",e.radio="radio",e.textarea="textarea",e.radioGroup="radioGroup",e.checkboxGroup="checkboxGroup",e.combobox="combobox",e.custom="custom",e))(c||{}),C=(e=>(e.invalid="invalid",e.valid="valid",e))(C||{});const P=(e,s,u,f={})=>t.defineComponent({name:"FieldComponent",props:{type:{type:String,validator:a=>Object.values(c).includes(a),default:c.custom},is:{type:[Object,String],default:void 0},name:{type:[String,Number,Boolean,Symbol],required:!0},props:{type:[Object,Function],default:()=>({})},showValid:{type:Boolean,default:!1},defaultValue:{type:[String,Number,Boolean,Array,Object],default:void 0}},emits:["invalid","valid","update:formData","update:modelValue"],expose:["invalid","invalidLabel","errors"],setup(a,{slots:r,emit:l}){const o=t.computed({get(){if(n!=null&&n.formData)return O(Object(n.formData.value),String(a.name))},set(d){n!=null&&n.formData&&(_(Object(n.formData.value),String(a.name),d),l("update:modelValue",{newValue:o.value,formData:n==null?void 0:n.formData}))}});t.onMounted(()=>{o.value===void 0&&a.defaultValue!==void 0&&(o.value=a.defaultValue)}),t.onBeforeUnmount(()=>{w(),g()});const i=t.inject(s,void 0);i&&i.fields.value.add(a.name);const n=t.inject(e),{props:h,name:b}=t.toRefs(a),p=t.computed(()=>{if(n!=null&&n.errors.value)return O(n.errors.value,String(a.name))}),m=t.computed(()=>{var d;return(d=p.value)==null?void 0:d._errors}),v=t.computed(()=>p.value!==void 0),w=t.watch(v,()=>{v.value?(l("invalid",m.value),i&&i.errors.value.set(a.name,{_errors:m.value})):(l("valid",o.value),i&&i.errors.value.delete(a.name))}),g=t.watch(()=>n==null?void 0:n.formData,()=>{l("update:formData",n==null?void 0:n.formData)},{deep:!0}),V=d=>{o.value=d},S=t.computed(()=>typeof h.value=="function"?h.value(n==null?void 0:n.formData):h.value),B=t.computed(()=>({...S.value,name:S.value.name??a.name,invalid:v.value,valid:a.showValid?!!(!v.value&&o.value):void 0,type:(d=>{if([c.text,c.number,c.email,c.password,c.tel,c.url,c.search,c.date,c.time,c.datetimeLocal,c.month,c.week,c.color].includes(d))return d})(a.type),invalidLabel:m.value,modelValue:o.value,"onUpdate:modelValue":V}));return t.provide(u,{name:t.readonly(b),errors:t.readonly(p)}),{component:t.computed(()=>{if(a.type===c.custom)return{render(){var d;return((d=r.default)==null?void 0:d.call(r,{modelValue:o.value,onUpdate:V,invalid:v.value,invalidLabel:m.value,formData:n==null?void 0:n.formData.value,formErrors:n==null?void 0:n.errors.value,errors:p.value}))??r.defalut}};if(!f.lazyLoad){let d;switch(a.type){case c.select:d=t.resolveComponent("VvSelect");break;case c.checkbox:d=t.resolveComponent("VvCheckbox");break;case c.radio:d=t.resolveComponent("VvRadio");break;case c.textarea:d=t.resolveComponent("VvTextarea");break;case c.radioGroup:d=t.resolveComponent("VvRadioGroup");break;case c.checkboxGroup:d=t.resolveComponent("VvCheckboxGroup");break;case c.combobox:d=t.resolveComponent("VvCombobox");break;default:d=t.resolveComponent("VvInputText")}if(typeof d!="string")return d;console.warn(`[form-vue warn]: ${d} not found, the component will be loaded asynchronously. To avoid this warning, please set "lazyLoad" option.`)}return t.defineAsyncComponent(async()=>{switch(f.sideEffects&&await Promise.resolve(f.sideEffects(a.type)),a.type){case c.textarea:return import("@volverjs/ui-vue/vv-textarea");case c.radio:return import("@volverjs/ui-vue/vv-radio");case c.radioGroup:return import("@volverjs/ui-vue/vv-radio-group");case c.checkbox:return import("@volverjs/ui-vue/vv-checkbox");case c.checkboxGroup:return import("@volverjs/ui-vue/vv-checkbox-group");case c.combobox:return import("@volverjs/ui-vue/vv-combobox")}return import("@volverjs/ui-vue/vv-input-text")})}),hasProps:B,invalid:v}},render(){return this.is?t.h(this.is,this.hasProps,this.$slots):this.type===c.custom?t.h(this.component,null,this.$slots):t.h(this.component,this.hasProps,this.$slots)}}),I=(e,s={})=>{const u=r=>{let l=r;for(;l instanceof x.ZodEffects;)l=l.innerType();return l},f=u(e);return{...(f instanceof x.ZodObject?f._def.unknownKeys==="passthrough":!1)?s:{},...Object.fromEntries(Object.entries(f.shape).map(([r,l])=>{const o=s[r],i=u(l);let n;if(i instanceof x.ZodDefault&&(n=i._def.defaultValue()),o===null&&i instanceof x.ZodNullable)return[r,o];if(i instanceof x.ZodSchema){const h=i.safeParse(s[r]);if(h.success)return[r,h.data??n]}return i instanceof x.ZodObject?[r,I(i,o&&typeof o=="object"?o:{})]:[r,n]}))}},z=(e,s,u)=>{const f=t.ref(),a=t.ref(),r=t.ref(),l=t.defineComponent({name:"FormComponent",props:{modelValue:{type:Object,default:()=>({})},updateThrottle:{type:Number,default:500},continuosValidation:{type:Boolean,default:!1}},emits:["invalid","valid","submit","update:modelValue"],expose:["submit","errors","status"],setup(o,{emit:i}){r.value=I(e,o.modelValue);const n=(u==null?void 0:u.continuosValidation)??o.continuosValidation;t.watch(()=>o.modelValue,m=>{if(m){const v=t.isProxy(m)?t.toRaw(m):m;r.value=typeof(v==null?void 0:v.clone)=="function"?v.clone():JSON.parse(JSON.stringify(v))}},{deep:!0}),M.watchThrottled(r,m=>{(f.value||n)&&h(),(!m||!o.modelValue||JSON.stringify(m)!==JSON.stringify(o.modelValue))&&i("update:modelValue",m)},{deep:!0,throttle:(u==null?void 0:u.updateThrottle)??o.updateThrottle});const h=(m=r.value)=>{const v=e.safeParse(m);return v.success?(f.value=void 0,a.value=C.valid,r.value=v.data,i("update:modelValue",r.value),i("valid",v.data),!0):(f.value=v.error.format(),a.value=C.invalid,i("invalid",f.value),!1)},b=()=>h()?(i("submit",r.value),!0):!1,p=t.computed(()=>a.value===C.invalid);return t.provide(s,{formData:r,submit:b,errors:t.readonly(f),status:t.readonly(a),invalid:p}),{formData:r,submit:b,errors:t.readonly(f),status:t.readonly(a),invalid:p}},render(){return t.h("form",{onSubmit:t.withModifiers(this.submit,["prevent"])},{default:()=>{var o,i;return((i=(o=this.$slots)==null?void 0:o.default)==null?void 0:i.call(o,{formData:this.formData,submit:this.submit,errors:this.errors,status:this.status,invalid:this.invalid}))??this.$slots.default}})}});return{errors:f,status:a,formData:r,VvForm:l}},T=(e,s)=>t.defineComponent({name:"WrapperComponent",props:{name:{type:String,required:!0},tag:{type:String,default:void 0}},emits:["invalid","valid"],expose:["fields","invalid"],setup(f,{emit:a}){const r=t.inject(e),l=t.inject(s,void 0),o=t.ref(new Set),i=t.ref(new Map),{name:n}=t.toRefs(f);t.provide(s,{name:t.readonly(n),errors:i,fields:o}),t.watch(o,b=>{l!=null&&l.fields&&b.forEach(p=>{l==null||l.fields.value.add(p)})},{deep:!0}),t.watch(()=>new Map(i.value),(b,p)=>{l!=null&&l.errors&&(Array.from(p.keys()).forEach(m=>{l.errors.value.delete(m)}),Array.from(b.keys()).forEach(m=>{const v=b.get(m);v&&l.errors.value.set(m,v)}))},{deep:!0});const h=t.computed(()=>r!=null&&r.invalid.value?i.value.size>0:!1);return t.watch(h,()=>{h.value?a("invalid"):a("valid")}),{formData:r==null?void 0:r.formData,errors:r==null?void 0:r.errors,invalid:h,fields:o,fieldsErrors:i}},render(){var f,a;return this.tag?t.h(this.tag,null,{default:()=>{var r,l;return((l=(r=this.$slots).default)==null?void 0:l.call(r,{invalid:this.invalid,formData:this.formData,errors:this.errors,fieldsErrors:this.fieldsErrors}))??this.$slots.defalut}}):((a=(f=this.$slots).default)==null?void 0:a.call(f,{invalid:this.invalid,formData:this.formData,errors:this.errors,fieldsErrors:this.fieldsErrors}))??this.$slots.defalut}}),D=(e,s)=>{const u=t.defineComponent({props:{schema:{type:[Array,Function],required:!0}},setup(f,{slots:a}){const r=t.inject(e);if(!(r!=null&&r.formData))return;const l=typeof f.schema=="function"?f.schema(r):f.schema;let o;return()=>{var i;return l.reduce((n,h)=>{const b=typeof h=="function"?h(r):h,{vvIs:p,vvName:m,vvSlots:v,vvChildren:w,vvIf:g,vvElseIf:V,vvType:S,vvDefaultValue:B,vvShowValid:q,...d}=b;if(g!==void 0){if(typeof g=="string"?o=!!O(Object(r.formData.value),g):typeof g=="function"?o=t.unref(g(r)):o=t.unref(g),!o)return n}else if(V!==void 0&&o!==void 0){if(o||(typeof V=="string"?o=!!O(Object(r.formData.value),V):typeof V=="function"?o=t.unref(V(r)):o=t.unref(V),!o))return n}else o=void 0;const G=w?t.h(u,{schema:w}):void 0;return m?(n.push(t.h(s,{name:m,is:p,type:S,defaultValue:B,showValid:q,props:d},v??G)),n):p?(n.push(t.h(p,d,v??G)),n):(w&&n.push(G),n)},[(i=a==null?void 0:a.default)==null?void 0:i.call(a,{formData:r==null?void 0:r.formData.value,submit:r==null?void 0:r.submit,errors:r==null?void 0:r.errors.value,status:r==null?void 0:r.status.value,invalid:r==null?void 0:r.invalid.value})])}}});return u},$=(e,s={})=>{const u=Symbol(),f=Symbol(),a=Symbol(),{VvForm:r,errors:l,status:o,formData:i}=z(e,u,s),n=T(u,f),h=P(u,f,a,s),b=D(u,h);return{VvForm:r,VvFormWrapper:n,VvFormField:h,VvFormTemplate:b,formInjectionKey:u,formWrapperInjectionKey:f,formFieldInjectionKey:a,errors:l,status:o,formData:i}},N=Symbol(),H=e=>{let s={};return e.schema&&(s=$(e.schema,e)),{...s,install(u,{global:f=!1}={}){u.provide(N,e),f&&(u.config.globalProperties.$vvForm=e,s!=null&&s.VvForm&&u.component("VvForm",s.VvForm),s!=null&&s.VvFormWrapper&&u.component("VvFormWrapper",s.VvFormWrapper),s!=null&&s.VvFormField&&u.component("VvFormField",s.VvFormField),s!=null&&s.VvFormTemplate&&u.component("VvFormTemplate",s.VvFormTemplate))}}},Q=(e,s={})=>{const u={...t.inject(N,{}),...s};return $(e,u)};y.FormFieldType=c,y.createForm=H,y.defaultObjectBySchema=I,y.formFactory=$,y.pluginInjectionKey=N,y.useForm=Q,Object.defineProperty(y,Symbol.toStringTag,{value:"Module"})});
|
|
1
|
+
(function(y,t){typeof exports=="object"&&typeof module<"u"?t(exports,require("vue"),require("@vueuse/core"),require("zod")):typeof define=="function"&&define.amd?define(["exports","vue","@vueuse/core","zod"],t):(y=typeof globalThis<"u"?globalThis:y||self,t(y["@volverjs/form-vue"]={},y.Vue,y.VueUseCore,y.zod))})(this,function(y,t,M,x){"use strict";function I(e){return Array.isArray(e)}function Z(e){return typeof e<"u"}function G(e){return e===null}function W(e){return typeof e=="object"}function A(e){return typeof e=="string"}function k(e){return typeof e>"u"}const z=/^[0-9]+$/,U=["__proto__","prototype","constructor"];function C(e,o,f){const i=Z(f)?f:void 0;if(!W(e)||!A(o))return i;const a=K(o);if(a.length!==0){for(const r of a){if(r==="*")continue;const u=function(s){return s.map(l=>k(l)||G(l)?l:I(l)?u(l):l[r])};if(I(e)&&!z.test(r)?e=u(e):e=e[r],k(e)||G(e))break}return k(e)?i:e}}function _(e,o,f){if(!W(e)||!A(o))return;const i=K(o);if(i.length===0)return;const a=i.length;for(let r=0;r<a;r++){const u=i[r];if(r===a-1){e[u]=f;return}if(u==="*"&&I(e)){const s=i.slice(r+1).join(".");for(const l of e)_(l,s,f);return}k(e[u])&&(e[u]={}),e=e[u]}}function K(e){const o=e.split(/[.]|(?:\[(\d|\*)\])/).filter(f=>!!f);return o.some(f=>U.indexOf(f)!==-1)?[]:o}var c=(e=>(e.text="text",e.number="number",e.email="email",e.password="password",e.tel="tel",e.url="url",e.search="search",e.date="date",e.time="time",e.datetimeLocal="datetimeLocal",e.month="month",e.week="week",e.color="color",e.select="select",e.checkbox="checkbox",e.radio="radio",e.textarea="textarea",e.radioGroup="radioGroup",e.checkboxGroup="checkboxGroup",e.combobox="combobox",e.custom="custom",e))(c||{}),O=(e=>(e.invalid="invalid",e.valid="valid",e))(O||{});const J=(e,o,f,i)=>t.defineComponent({name:"FieldComponent",props:{type:{type:String,validator:a=>Object.values(c).includes(a),default:c.custom},is:{type:[Object,String],default:void 0},name:{type:[String,Number,Boolean,Symbol],required:!0},props:{type:[Object,Function],default:()=>({})},showValid:{type:Boolean,default:!1},defaultValue:{type:[String,Number,Boolean,Array,Object],default:void 0},lazyLoad:{type:Boolean,default:!1}},emits:["invalid","valid","update:formData","update:modelValue"],expose:["invalid","invalidLabel","errors"],setup(a,{slots:r,emit:u}){const s=t.computed({get(){if(n!=null&&n.formData)return C(Object(n.formData.value),String(a.name))},set(d){n!=null&&n.formData&&(_(Object(n.formData.value),String(a.name),d),u("update:modelValue",{newValue:s.value,formData:n==null?void 0:n.formData}))}});t.onMounted(()=>{s.value===void 0&&a.defaultValue!==void 0&&(s.value=a.defaultValue)}),t.onBeforeUnmount(()=>{w(),g()});const l=t.inject(o,void 0);l&&l.fields.value.add(a.name);const n=t.inject(e),{props:h,name:b}=t.toRefs(a),p=t.computed(()=>{if(n!=null&&n.errors.value)return C(n.errors.value,String(a.name))}),m=t.computed(()=>{var d;return(d=p.value)==null?void 0:d._errors}),v=t.computed(()=>p.value!==void 0),w=t.watch(v,()=>{v.value?(u("invalid",m.value),l&&l.errors.value.set(a.name,{_errors:m.value})):(u("valid",s.value),l&&l.errors.value.delete(a.name))}),g=t.watch(()=>n==null?void 0:n.formData,()=>{u("update:formData",n==null?void 0:n.formData)},{deep:!0}),V=d=>{s.value=d},E=t.computed(()=>typeof h.value=="function"?h.value(n==null?void 0:n.formData):h.value),L=t.computed(()=>({...E.value,name:E.value.name??a.name,invalid:v.value,valid:a.showValid?!!(!v.value&&s.value):void 0,type:(d=>{if([c.text,c.number,c.email,c.password,c.tel,c.url,c.search,c.date,c.time,c.datetimeLocal,c.month,c.week,c.color].includes(d))return d})(a.type),invalidLabel:m.value,modelValue:s.value,"onUpdate:modelValue":V}));return t.provide(f,{name:t.readonly(b),errors:t.readonly(p)}),{component:t.computed(()=>{if(a.type===c.custom)return{render(){var d;return((d=r.default)==null?void 0:d.call(r,{modelValue:s.value,onUpdate:V,invalid:v.value,invalidLabel:m.value,formData:n==null?void 0:n.formData.value,formErrors:n==null?void 0:n.errors.value,errors:p.value}))??r.defalut}};if(!((i==null?void 0:i.lazyLoad)??a.lazyLoad)){let d;switch(a.type){case c.select:d=t.resolveComponent("VvSelect");break;case c.checkbox:d=t.resolveComponent("VvCheckbox");break;case c.radio:d=t.resolveComponent("VvRadio");break;case c.textarea:d=t.resolveComponent("VvTextarea");break;case c.radioGroup:d=t.resolveComponent("VvRadioGroup");break;case c.checkboxGroup:d=t.resolveComponent("VvCheckboxGroup");break;case c.combobox:d=t.resolveComponent("VvCombobox");break;default:d=t.resolveComponent("VvInputText")}if(typeof d!="string")return d;console.warn(`[form-vue warn]: ${d} not found, the component will be loaded asynchronously. To avoid this warning, please set "lazyLoad" option.`)}return t.defineAsyncComponent(async()=>{switch(i!=null&&i.sideEffects&&await Promise.resolve(i.sideEffects(a.type)),a.type){case c.textarea:return import("@volverjs/ui-vue/vv-textarea");case c.radio:return import("@volverjs/ui-vue/vv-radio");case c.radioGroup:return import("@volverjs/ui-vue/vv-radio-group");case c.checkbox:return import("@volverjs/ui-vue/vv-checkbox");case c.checkboxGroup:return import("@volverjs/ui-vue/vv-checkbox-group");case c.combobox:return import("@volverjs/ui-vue/vv-combobox")}return import("@volverjs/ui-vue/vv-input-text")})}),hasProps:L,invalid:v}},render(){return this.is?t.h(this.is,this.hasProps,this.$slots):this.type===c.custom?t.h(this.component,null,this.$slots):t.h(this.component,this.hasProps,this.$slots)}}),$=(e,o={})=>{const f=r=>{let u=r;for(;u instanceof x.ZodEffects;)u=u.innerType();return u},i=f(e);return{...(i instanceof x.ZodObject?i._def.unknownKeys==="passthrough":!1)?o:{},...Object.fromEntries(Object.entries(i.shape).map(([r,u])=>{const s=o[r],l=f(u);let n;if(l instanceof x.ZodDefault&&(n=l._def.defaultValue()),s===null&&l instanceof x.ZodNullable)return[r,s];if(l instanceof x.ZodSchema){const h=l.safeParse(o[r]);if(h.success)return[r,h.data??n]}return l instanceof x.ZodObject?[r,$(l,s&&typeof s=="object"?s:{})]:[r,n]}))}},P=(e,o,f)=>{const i=t.ref(),a=t.ref(),r=t.ref(),u=t.defineComponent({name:"FormComponent",props:{modelValue:{type:Object,default:()=>({})},updateThrottle:{type:Number,default:500},continuosValidation:{type:Boolean,default:!1}},emits:["invalid","valid","submit","update:modelValue"],expose:["submit","errors","status"],setup(s,{emit:l}){r.value=$(e,s.modelValue);const n=(f==null?void 0:f.continuosValidation)??s.continuosValidation;t.watch(()=>s.modelValue,m=>{if(m){const v=t.isProxy(m)?t.toRaw(m):m;r.value=typeof(v==null?void 0:v.clone)=="function"?v.clone():JSON.parse(JSON.stringify(v))}},{deep:!0}),M.watchThrottled(r,m=>{(i.value||n)&&h(),(!m||!s.modelValue||JSON.stringify(m)!==JSON.stringify(s.modelValue))&&l("update:modelValue",m)},{deep:!0,throttle:(f==null?void 0:f.updateThrottle)??s.updateThrottle});const h=(m=r.value)=>{const v=e.safeParse(m);return v.success?(i.value=void 0,a.value=O.valid,r.value=v.data,l("update:modelValue",r.value),l("valid",v.data),!0):(i.value=v.error.format(),a.value=O.invalid,l("invalid",i.value),!1)},b=()=>h()?(l("submit",r.value),!0):!1,p=t.computed(()=>a.value===O.invalid);return t.provide(o,{formData:r,submit:b,errors:t.readonly(i),status:t.readonly(a),invalid:p}),{formData:r,submit:b,errors:t.readonly(i),status:t.readonly(a),invalid:p}},render(){return t.h("form",{onSubmit:t.withModifiers(this.submit,["prevent"])},{default:()=>{var s,l;return((l=(s=this.$slots)==null?void 0:s.default)==null?void 0:l.call(s,{formData:this.formData,submit:this.submit,errors:this.errors,status:this.status,invalid:this.invalid}))??this.$slots.default}})}});return{errors:i,status:a,formData:r,VvForm:u}},T=(e,o)=>t.defineComponent({name:"WrapperComponent",props:{name:{type:String,required:!0},tag:{type:String,default:void 0}},emits:["invalid","valid"],expose:["fields","invalid"],setup(i,{emit:a}){const r=t.inject(e),u=t.inject(o,void 0),s=t.ref(new Set),l=t.ref(new Map),{name:n}=t.toRefs(i);t.provide(o,{name:t.readonly(n),errors:l,fields:s}),t.watch(s,b=>{u!=null&&u.fields&&b.forEach(p=>{u==null||u.fields.value.add(p)})},{deep:!0}),t.watch(()=>new Map(l.value),(b,p)=>{u!=null&&u.errors&&(Array.from(p.keys()).forEach(m=>{u.errors.value.delete(m)}),Array.from(b.keys()).forEach(m=>{const v=b.get(m);v&&u.errors.value.set(m,v)}))},{deep:!0});const h=t.computed(()=>r!=null&&r.invalid.value?l.value.size>0:!1);return t.watch(h,()=>{h.value?a("invalid"):a("valid")}),{formData:r==null?void 0:r.formData,errors:r==null?void 0:r.errors,invalid:h,fields:s,fieldsErrors:l}},render(){var i,a;return this.tag?t.h(this.tag,null,{default:()=>{var r,u;return((u=(r=this.$slots).default)==null?void 0:u.call(r,{invalid:this.invalid,formData:this.formData,errors:this.errors,fieldsErrors:this.fieldsErrors}))??this.$slots.defalut}}):((a=(i=this.$slots).default)==null?void 0:a.call(i,{invalid:this.invalid,formData:this.formData,errors:this.errors,fieldsErrors:this.fieldsErrors}))??this.$slots.defalut}}),D=(e,o)=>{const f=t.defineComponent({props:{schema:{type:[Array,Function],required:!0}},setup(i,{slots:a}){const r=t.inject(e);if(!(r!=null&&r.formData))return;const u=typeof i.schema=="function"?i.schema(r):i.schema;let s;return()=>{var l;return u.reduce((n,h)=>{const b=typeof h=="function"?h(r):h,{vvIs:p,vvName:m,vvSlots:v,vvChildren:w,vvIf:g,vvElseIf:V,vvType:E,vvDefaultValue:L,vvShowValid:q,...d}=b;if(g!==void 0){if(typeof g=="string"?s=!!C(Object(r.formData.value),g):typeof g=="function"?s=t.unref(g(r)):s=t.unref(g),!s)return n}else if(V!==void 0&&s!==void 0){if(s||(typeof V=="string"?s=!!C(Object(r.formData.value),V):typeof V=="function"?s=t.unref(V(r)):s=t.unref(V),!s))return n}else s=void 0;const N=w?t.h(f,{schema:w}):void 0;return m?(n.push(t.h(o,{name:m,is:p,type:E,defaultValue:L,showValid:q,props:d},v??N)),n):p?(n.push(t.h(p,d,v??N)),n):(w&&n.push(N),n)},[(l=a==null?void 0:a.default)==null?void 0:l.call(a,{formData:r==null?void 0:r.formData.value,submit:r==null?void 0:r.submit,errors:r==null?void 0:r.errors.value,status:r==null?void 0:r.status.value,invalid:r==null?void 0:r.invalid.value})])}}});return f},S=(e,o={})=>{const f=Symbol(),i=Symbol(),a=Symbol(),{VvForm:r,errors:u,status:s,formData:l}=P(e,f,o),n=T(f,i),h=J(f,i,a,o),b=D(f,h);return{VvForm:r,VvFormWrapper:n,VvFormField:h,VvFormTemplate:b,formInjectionKey:f,formWrapperInjectionKey:i,formFieldInjectionKey:a,errors:u,status:s,formData:l}},B=Symbol(),H=e=>{let o={};return e.schema&&(o=S(e.schema,e)),{...o,install(f,{global:i=!1}={}){f.provide(B,e),i&&(f.config.globalProperties.$vvForm=e,o!=null&&o.VvForm&&f.component("VvForm",o.VvForm),o!=null&&o.VvFormWrapper&&f.component("VvFormWrapper",o.VvFormWrapper),o!=null&&o.VvFormField&&f.component("VvFormField",o.VvFormField),o!=null&&o.VvFormTemplate&&f.component("VvFormTemplate",o.VvFormTemplate))}}},Q=(e,o={})=>t.getCurrentInstance()?S(e,{...t.inject(B,{}),...o}):S(e,o),R=(e,o={})=>S(e,o);y.FormFieldType=c,y.createForm=H,y.defaultObjectBySchema=$,y.formFactory=R,y.pluginInjectionKey=B,y.useForm=Q,Object.defineProperty(y,Symbol.toStringTag,{value:"Module"})});
|
package/dist/types.d.ts
CHANGED
|
@@ -7,13 +7,19 @@ export type FormSchema =
|
|
|
7
7
|
| ZodEffects<AnyZodObject>
|
|
8
8
|
| ZodEffects<ZodEffects<AnyZodObject>>
|
|
9
9
|
|
|
10
|
-
export type
|
|
10
|
+
export type FormFieldComponentOptions = {
|
|
11
11
|
lazyLoad?: boolean
|
|
12
|
+
sideEffects?: (type: `${FormFieldType}`) => Promise | void
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export type FormComponentOptions = {
|
|
12
16
|
updateThrottle?: number
|
|
13
17
|
continuosValidation?: boolean
|
|
14
|
-
sideEffects?: (type: `${FormFieldType}`) => Promise | void
|
|
15
18
|
}
|
|
16
19
|
|
|
20
|
+
export type FormComposableOptions = FormFieldComponentOptions &
|
|
21
|
+
FormComponentOptions
|
|
22
|
+
|
|
17
23
|
export type FormPluginOptions = {
|
|
18
24
|
schema?: ZodSchema
|
|
19
25
|
} & FormComposableOptions
|
package/package.json
CHANGED
package/src/VvForm.ts
CHANGED
|
@@ -15,17 +15,18 @@ import {
|
|
|
15
15
|
} from 'vue'
|
|
16
16
|
import { watchThrottled } from '@vueuse/core'
|
|
17
17
|
import type { z, ZodFormattedError, TypeOf } from 'zod'
|
|
18
|
-
import type {
|
|
18
|
+
import type {
|
|
19
|
+
FormComponentOptions,
|
|
20
|
+
FormSchema,
|
|
21
|
+
InjectedFormData,
|
|
22
|
+
} from './types'
|
|
19
23
|
import { FormStatus } from './enums'
|
|
20
24
|
import { defaultObjectBySchema } from './utils'
|
|
21
25
|
|
|
22
26
|
export const defineForm = <Schema extends FormSchema>(
|
|
23
27
|
schema: Schema,
|
|
24
28
|
provideKey: InjectionKey<InjectedFormData<Schema>>,
|
|
25
|
-
options?:
|
|
26
|
-
updateThrottle?: number
|
|
27
|
-
continuosValidation?: boolean
|
|
28
|
-
},
|
|
29
|
+
options?: FormComponentOptions,
|
|
29
30
|
) => {
|
|
30
31
|
const errors = ref<ZodFormattedError<z.infer<Schema>>>()
|
|
31
32
|
const status = ref<FormStatus | undefined>()
|
package/src/VvFormField.ts
CHANGED
|
@@ -24,7 +24,7 @@ import type {
|
|
|
24
24
|
InjectedFormData,
|
|
25
25
|
InjectedFormWrapperData,
|
|
26
26
|
InjectedFormFieldData,
|
|
27
|
-
|
|
27
|
+
FormFieldComponentOptions,
|
|
28
28
|
Path,
|
|
29
29
|
FormSchema,
|
|
30
30
|
} from './types'
|
|
@@ -33,7 +33,7 @@ export const defineFormField = <Schema extends FormSchema>(
|
|
|
33
33
|
formProvideKey: InjectionKey<InjectedFormData<Schema>>,
|
|
34
34
|
wrapperProvideKey: InjectionKey<InjectedFormWrapperData<Schema>>,
|
|
35
35
|
formFieldInjectionKey: InjectionKey<InjectedFormFieldData<Schema>>,
|
|
36
|
-
options
|
|
36
|
+
options?: FormFieldComponentOptions,
|
|
37
37
|
) => {
|
|
38
38
|
// define component
|
|
39
39
|
return defineComponent({
|
|
@@ -76,6 +76,10 @@ export const defineFormField = <Schema extends FormSchema>(
|
|
|
76
76
|
type: [String, Number, Boolean, Array, Object],
|
|
77
77
|
default: undefined,
|
|
78
78
|
},
|
|
79
|
+
lazyLoad: {
|
|
80
|
+
type: Boolean,
|
|
81
|
+
default: false,
|
|
82
|
+
},
|
|
79
83
|
},
|
|
80
84
|
emits: ['invalid', 'valid', 'update:formData', 'update:modelValue'],
|
|
81
85
|
expose: ['invalid', 'invalidLabel', 'errors'],
|
|
@@ -231,7 +235,7 @@ export const defineFormField = <Schema extends FormSchema>(
|
|
|
231
235
|
},
|
|
232
236
|
}
|
|
233
237
|
}
|
|
234
|
-
if (!options.lazyLoad) {
|
|
238
|
+
if (!(options?.lazyLoad ?? props.lazyLoad)) {
|
|
235
239
|
let component: string | ConcreteComponent
|
|
236
240
|
switch (props.type) {
|
|
237
241
|
case FormFieldType.select:
|
|
@@ -267,7 +271,7 @@ export const defineFormField = <Schema extends FormSchema>(
|
|
|
267
271
|
}
|
|
268
272
|
}
|
|
269
273
|
return defineAsyncComponent(async () => {
|
|
270
|
-
if (options
|
|
274
|
+
if (options?.sideEffects) {
|
|
271
275
|
await Promise.resolve(options.sideEffects(props.type))
|
|
272
276
|
}
|
|
273
277
|
switch (props.type) {
|
package/src/index.ts
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
getCurrentInstance,
|
|
3
|
+
type App,
|
|
4
|
+
inject,
|
|
5
|
+
type InjectionKey,
|
|
6
|
+
type Plugin,
|
|
7
|
+
} from 'vue'
|
|
2
8
|
import { defineFormField } from './VvFormField'
|
|
3
9
|
import { defineForm } from './VvForm'
|
|
4
10
|
import { defineFormWrapper } from './VvFormWrapper'
|
|
@@ -15,16 +21,15 @@ import type {
|
|
|
15
21
|
FormSchema,
|
|
16
22
|
} from './types'
|
|
17
23
|
|
|
18
|
-
|
|
24
|
+
const _formFactory = <Schema extends FormSchema>(
|
|
19
25
|
schema: Schema,
|
|
20
26
|
options: FormComposableOptions = {},
|
|
21
27
|
) => {
|
|
22
|
-
// create injection keys
|
|
28
|
+
// create injection keys
|
|
23
29
|
const formInjectionKey = Symbol() as InjectionKey<InjectedFormData<Schema>>
|
|
24
30
|
const formWrapperInjectionKey = Symbol() as InjectionKey<
|
|
25
31
|
InjectedFormWrapperData<Schema>
|
|
26
32
|
>
|
|
27
|
-
|
|
28
33
|
const formFieldInjectionKey = Symbol() as InjectionKey<
|
|
29
34
|
InjectedFormFieldData<Schema>
|
|
30
35
|
>
|
|
@@ -68,7 +73,7 @@ export const createForm = (
|
|
|
68
73
|
): Plugin & Partial<ReturnType<typeof useForm>> => {
|
|
69
74
|
let toReturn: Partial<ReturnType<typeof useForm>> = {}
|
|
70
75
|
if (options.schema) {
|
|
71
|
-
toReturn =
|
|
76
|
+
toReturn = _formFactory(options.schema, options)
|
|
72
77
|
}
|
|
73
78
|
return {
|
|
74
79
|
...toReturn,
|
|
@@ -99,8 +104,13 @@ export const useForm = <Schema extends FormSchema>(
|
|
|
99
104
|
schema: Schema,
|
|
100
105
|
options: FormComposableOptions = {},
|
|
101
106
|
) => {
|
|
102
|
-
|
|
103
|
-
|
|
107
|
+
if (!getCurrentInstance()) {
|
|
108
|
+
return _formFactory(schema, options)
|
|
109
|
+
}
|
|
110
|
+
return _formFactory(schema, {
|
|
111
|
+
...inject(pluginInjectionKey, {}),
|
|
112
|
+
...options,
|
|
113
|
+
})
|
|
104
114
|
}
|
|
105
115
|
|
|
106
116
|
export { FormFieldType } from './enums'
|
|
@@ -125,3 +135,13 @@ export type {
|
|
|
125
135
|
Path,
|
|
126
136
|
PathValue,
|
|
127
137
|
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* @deprecated Use `useForm()` instead
|
|
141
|
+
*/
|
|
142
|
+
export const formFactory = <Schema extends FormSchema>(
|
|
143
|
+
schema: Schema,
|
|
144
|
+
options: FormComposableOptions = {},
|
|
145
|
+
) => {
|
|
146
|
+
return _formFactory(schema, options)
|
|
147
|
+
}
|
package/src/types.d.ts
CHANGED
|
@@ -7,13 +7,19 @@ export type FormSchema =
|
|
|
7
7
|
| ZodEffects<AnyZodObject>
|
|
8
8
|
| ZodEffects<ZodEffects<AnyZodObject>>
|
|
9
9
|
|
|
10
|
-
export type
|
|
10
|
+
export type FormFieldComponentOptions = {
|
|
11
11
|
lazyLoad?: boolean
|
|
12
|
+
sideEffects?: (type: `${FormFieldType}`) => Promise | void
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export type FormComponentOptions = {
|
|
12
16
|
updateThrottle?: number
|
|
13
17
|
continuosValidation?: boolean
|
|
14
|
-
sideEffects?: (type: `${FormFieldType}`) => Promise | void
|
|
15
18
|
}
|
|
16
19
|
|
|
20
|
+
export type FormComposableOptions = FormFieldComponentOptions &
|
|
21
|
+
FormComponentOptions
|
|
22
|
+
|
|
17
23
|
export type FormPluginOptions = {
|
|
18
24
|
schema?: ZodSchema
|
|
19
25
|
} & FormComposableOptions
|