@volverjs/form-vue 0.0.10-beta.8 → 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 CHANGED
@@ -279,21 +279,20 @@ It automatically bind the form data through the `name` attribute. For nested obj
279
279
  ```
280
280
 
281
281
  To render a [`@volverjs/ui-vue`](https://github.com/volverjs/ui-vue) input component, use the `type` attribute.
282
-
283
- By default [`@volverjs/ui-vue`](https://github.com/volverjs/ui-vue) components must be defined globally but can be lazy loaded with `lazyLoad` option or prop.
282
+ By default UI components must be installed globally, they can be lazy-loaded with `lazyLoad` option or prop.
284
283
 
285
284
  ```vue
286
285
  <template>
287
286
  <VvForm>
288
- <VvFormField type="text" name="username" label="Username" />
289
- <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 />
290
289
  </VvForm>
291
290
  </template>
292
291
  ```
293
292
 
294
293
  Check the [`VvFormField`](./docs/VvFormField.md) documentation to learn more about form fields.
295
294
 
296
- ## Form Template
295
+ ## VvFormTemplate
297
296
 
298
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**.
299
298
 
@@ -367,15 +366,10 @@ Forms can also be created using a template. A template is an **array of objects*
367
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.
368
367
 
369
368
  `vvName` refers to the name of the field in the schema and can be a nested property using **dot notation**.
370
-
371
369
  `vvType` refers to the type of the field and can be any of the supported types.
372
-
373
370
  `vvDefaultValue` can be used to set default values for the form item.
374
-
375
371
  `vvShowValid` can be used to show the valid state of the form item.
376
-
377
372
  `vvSlots` can be used to pass a slots to the template item.
378
-
379
373
  `vvChildren` is an array of template items which will be wrapped in the parent item.
380
374
 
381
375
  Conditional rendering can be achieved using the `vvIf` and `vvElseIf` properties.
@@ -450,7 +444,7 @@ Conditional rendering can be achieved using the `vvIf` and `vvElseIf` properties
450
444
 
451
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.
452
446
 
453
- `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.
454
448
 
455
449
  ```ts
456
450
  {
@@ -461,7 +455,8 @@ Conditional rendering can be achieved using the `vvIf` and `vvElseIf` properties
461
455
  }
462
456
  ```
463
457
 
464
- The template schema and all template items can be a function. The function will be called with the form context as the first argument.
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**.
465
460
 
466
461
  ```ts
467
462
  const templateSchema = (ctx) => [
@@ -28,7 +28,7 @@ export declare const defineFormField: <Schema extends FormSchema>(formProvideKey
28
28
  type: (ObjectConstructor | NumberConstructor | BooleanConstructor | StringConstructor | ArrayConstructor)[];
29
29
  default: undefined;
30
30
  };
31
- lazyload: {
31
+ lazyLoad: {
32
32
  type: BooleanConstructor;
33
33
  default: boolean;
34
34
  };
@@ -67,7 +67,7 @@ export declare const defineFormField: <Schema extends FormSchema>(formProvideKey
67
67
  type: (ObjectConstructor | NumberConstructor | BooleanConstructor | StringConstructor | ArrayConstructor)[];
68
68
  default: undefined;
69
69
  };
70
- lazyload: {
70
+ lazyLoad: {
71
71
  type: BooleanConstructor;
72
72
  default: boolean;
73
73
  };
@@ -88,5 +88,5 @@ export declare const defineFormField: <Schema extends FormSchema>(formProvideKey
88
88
  is: Component;
89
89
  showValid: boolean;
90
90
  defaultValue: string | number | boolean | unknown[] | Record<string, any>;
91
- lazyload: boolean;
91
+ lazyLoad: boolean;
92
92
  }>;
package/dist/index.d.ts CHANGED
@@ -320,7 +320,7 @@ export declare const useForm: <Schema extends FormSchema>(schema: Schema, option
320
320
  type: (ObjectConstructor | NumberConstructor | BooleanConstructor | StringConstructor | ArrayConstructor)[];
321
321
  default: undefined;
322
322
  };
323
- lazyload: {
323
+ lazyLoad: {
324
324
  type: BooleanConstructor;
325
325
  default: boolean;
326
326
  };
@@ -359,7 +359,7 @@ export declare const useForm: <Schema extends FormSchema>(schema: Schema, option
359
359
  type: (ObjectConstructor | NumberConstructor | BooleanConstructor | StringConstructor | ArrayConstructor)[];
360
360
  default: undefined;
361
361
  };
362
- lazyload: {
362
+ lazyLoad: {
363
363
  type: BooleanConstructor;
364
364
  default: boolean;
365
365
  };
@@ -380,7 +380,7 @@ export declare const useForm: <Schema extends FormSchema>(schema: Schema, option
380
380
  is: import("vue").Component;
381
381
  showValid: boolean;
382
382
  defaultValue: string | number | boolean | unknown[] | Record<string, any>;
383
- lazyload: boolean;
383
+ lazyLoad: boolean;
384
384
  }>;
385
385
  VvFormTemplate: (import("vue").ComponentOptions<any, any, any, import("vue").ComputedOptions, import("vue").MethodOptions, any, any, any> | {
386
386
  new (...args: any[]): any;
@@ -729,7 +729,7 @@ export declare const formFactory: <Schema extends FormSchema>(schema: Schema, op
729
729
  type: (ObjectConstructor | NumberConstructor | BooleanConstructor | StringConstructor | ArrayConstructor)[];
730
730
  default: undefined;
731
731
  };
732
- lazyload: {
732
+ lazyLoad: {
733
733
  type: BooleanConstructor;
734
734
  default: boolean;
735
735
  };
@@ -768,7 +768,7 @@ export declare const formFactory: <Schema extends FormSchema>(schema: Schema, op
768
768
  type: (ObjectConstructor | NumberConstructor | BooleanConstructor | StringConstructor | ArrayConstructor)[];
769
769
  default: undefined;
770
770
  };
771
- lazyload: {
771
+ lazyLoad: {
772
772
  type: BooleanConstructor;
773
773
  default: boolean;
774
774
  };
@@ -789,7 +789,7 @@ export declare const formFactory: <Schema extends FormSchema>(schema: Schema, op
789
789
  is: import("vue").Component;
790
790
  showValid: boolean;
791
791
  defaultValue: string | number | boolean | unknown[] | Record<string, any>;
792
- lazyload: boolean;
792
+ lazyLoad: boolean;
793
793
  }>;
794
794
  VvFormTemplate: (import("vue").ComponentOptions<any, any, any, import("vue").ComputedOptions, import("vue").MethodOptions, any, any, any> | {
795
795
  new (...args: any[]): any;
package/dist/index.es.js CHANGED
@@ -1,4 +1,4 @@
1
- import { defineComponent as W, 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";
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
2
  import { watchThrottled as re } from "@vueuse/core";
3
3
  import { ZodObject as M, ZodDefault as te, ZodNullable as ne, ZodSchema as ae, ZodEffects as oe } from "zod";
4
4
  function _(e) {
@@ -20,7 +20,7 @@ function $(e) {
20
20
  return typeof e > "u";
21
21
  }
22
22
  const ue = /^[0-9]+$/, le = ["__proto__", "prototype", "constructor"];
23
- function B(e, n, i) {
23
+ function N(e, n, i) {
24
24
  const s = se(i) ? i : void 0;
25
25
  if (!U(e) || !q(n))
26
26
  return s;
@@ -64,8 +64,8 @@ function D(e) {
64
64
  const n = e.split(/[.]|(?:\[(\d|\*)\])/).filter((i) => !!i);
65
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 || {}), N = /* @__PURE__ */ ((e) => (e.invalid = "invalid", e.valid = "valid", e))(N || {});
68
- const ie = (e, n, i, s) => W({
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: {
@@ -93,7 +93,7 @@ const ie = (e, n, i, s) => W({
93
93
  type: [String, Number, Boolean, Array, Object],
94
94
  default: void 0
95
95
  },
96
- lazyload: {
96
+ lazyLoad: {
97
97
  type: Boolean,
98
98
  default: !1
99
99
  }
@@ -104,7 +104,7 @@ const ie = (e, n, i, s) => W({
104
104
  const o = V({
105
105
  get() {
106
106
  if (t != null && t.formData)
107
- return B(
107
+ return N(
108
108
  Object(t.formData.value),
109
109
  String(a.name)
110
110
  );
@@ -129,7 +129,7 @@ const ie = (e, n, i, s) => W({
129
129
  u && u.fields.value.add(a.name);
130
130
  const t = O(e), { props: m, name: p } = J(a), h = V(() => {
131
131
  if (t != null && t.errors.value)
132
- return B(t.errors.value, String(a.name));
132
+ return N(t.errors.value, String(a.name));
133
133
  }), d = V(() => {
134
134
  var c;
135
135
  return (c = h.value) == null ? void 0 : c._errors;
@@ -150,7 +150,7 @@ const ie = (e, n, i, s) => W({
150
150
  { deep: !0 }
151
151
  ), b = (c) => {
152
152
  o.value = c;
153
- }, I = V(() => typeof m.value == "function" ? m.value(t == null ? void 0 : t.formData) : m.value), A = V(() => ({
153
+ }, I = V(() => typeof m.value == "function" ? m.value(t == null ? void 0 : t.formData) : m.value), W = V(() => ({
154
154
  ...I.value,
155
155
  name: I.value.name ?? a.name,
156
156
  invalid: v.value,
@@ -196,7 +196,7 @@ const ie = (e, n, i, s) => W({
196
196
  })) ?? r.defalut;
197
197
  }
198
198
  };
199
- if (!((s == null ? void 0 : s.lazyLoad) ?? a.lazyload)) {
199
+ if (!((s == null ? void 0 : s.lazyLoad) ?? a.lazyLoad)) {
200
200
  let c;
201
201
  switch (a.type) {
202
202
  case f.select:
@@ -246,7 +246,7 @@ const ie = (e, n, i, s) => W({
246
246
  }
247
247
  return import("@volverjs/ui-vue/vv-input-text");
248
248
  });
249
- }), hasProps: A, invalid: v };
249
+ }), hasProps: W, invalid: v };
250
250
  },
251
251
  render() {
252
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);
@@ -282,7 +282,7 @@ const ie = (e, n, i, s) => W({
282
282
  )
283
283
  };
284
284
  }, fe = (e, n, i) => {
285
- const s = E(), a = E(), r = E(), l = W({
285
+ const s = E(), a = E(), r = E(), l = G({
286
286
  name: "FormComponent",
287
287
  props: {
288
288
  modelValue: {
@@ -324,8 +324,8 @@ const ie = (e, n, i, s) => W({
324
324
  );
325
325
  const m = (d = r.value) => {
326
326
  const v = e.safeParse(d);
327
- return v.success ? (s.value = void 0, a.value = N.valid, r.value = v.data, u("update:modelValue", r.value), u("valid", v.data), !0) : (s.value = v.error.format(), a.value = N.invalid, u("invalid", s.value), !1);
328
- }, p = () => m() ? (u("submit", r.value), !0) : !1, h = V(() => a.value === N.invalid);
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
329
  return z(n, {
330
330
  formData: r,
331
331
  submit: p,
@@ -370,7 +370,7 @@ const ie = (e, n, i, s) => W({
370
370
  */
371
371
  VvForm: l
372
372
  };
373
- }, ce = (e, n) => W({
373
+ }, ce = (e, n) => G({
374
374
  name: "WrapperComponent",
375
375
  props: {
376
376
  name: {
@@ -441,7 +441,7 @@ const ie = (e, n, i, s) => W({
441
441
  })) ?? this.$slots.defalut;
442
442
  }
443
443
  }), de = (e, n) => {
444
- const i = W({
444
+ const i = G({
445
445
  props: {
446
446
  schema: {
447
447
  type: [Array, Function],
@@ -466,25 +466,25 @@ const ie = (e, n, i, s) => W({
466
466
  vvIf: y,
467
467
  vvElseIf: b,
468
468
  vvType: I,
469
- vvDefaultValue: A,
469
+ vvDefaultValue: W,
470
470
  vvShowValid: K,
471
471
  ...c
472
472
  } = p;
473
473
  if (y !== void 0) {
474
- if (typeof y == "string" ? o = !!B(
474
+ if (typeof y == "string" ? o = !!N(
475
475
  Object(r.formData.value),
476
476
  y
477
477
  ) : typeof y == "function" ? o = C(y(r)) : o = C(y), !o)
478
478
  return t;
479
479
  } else if (b !== void 0 && o !== void 0) {
480
- if (o || (typeof b == "string" ? o = !!B(
480
+ if (o || (typeof b == "string" ? o = !!N(
481
481
  Object(r.formData.value),
482
482
  b
483
483
  ) : typeof b == "function" ? o = C(b(r)) : o = C(b), !o))
484
484
  return t;
485
485
  } else
486
486
  o = void 0;
487
- const L = S ? x(i, {
487
+ const A = S ? x(i, {
488
488
  schema: S
489
489
  }) : void 0;
490
490
  return d ? (t.push(
@@ -494,19 +494,19 @@ const ie = (e, n, i, s) => W({
494
494
  name: d,
495
495
  is: h,
496
496
  type: I,
497
- defaultValue: A,
497
+ defaultValue: W,
498
498
  showValid: K,
499
499
  props: c
500
500
  },
501
- v ?? L
501
+ v ?? A
502
502
  )
503
503
  ), t) : h ? (t.push(
504
504
  x(
505
505
  h,
506
506
  c,
507
- v ?? L
507
+ v ?? A
508
508
  )
509
- ), t) : (S && t.push(L), t);
509
+ ), t) : (S && t.push(A), t);
510
510
  },
511
511
  [
512
512
  (u = a == null ? void 0 : a.default) == null ? void 0 : u.call(a, {
@@ -522,7 +522,7 @@ const ie = (e, n, i, s) => W({
522
522
  }
523
523
  });
524
524
  return i;
525
- }, G = (e, n = {}) => {
525
+ }, B = (e, n = {}) => {
526
526
  const i = Symbol(), s = Symbol(), a = Symbol(), { VvForm: r, errors: l, status: o, formData: u } = fe(
527
527
  e,
528
528
  i,
@@ -550,16 +550,16 @@ const ie = (e, n, i, s) => W({
550
550
  };
551
551
  }, Q = Symbol(), pe = (e) => {
552
552
  let n = {};
553
- return e.schema && (n = G(e.schema, e)), {
553
+ return e.schema && (n = B(e.schema, e)), {
554
554
  ...n,
555
555
  install(i, { global: s = !1 } = {}) {
556
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));
557
557
  }
558
558
  };
559
- }, be = (e, n = {}) => ee() ? G(e, {
559
+ }, be = (e, n = {}) => ee() ? B(e, {
560
560
  ...O(Q, {}),
561
561
  ...n
562
- }) : G(e, n), Ve = (e, n = {}) => G(e, n);
562
+ }) : B(e, n), Ve = (e, n = {}) => B(e, n);
563
563
  export {
564
564
  f as FormFieldType,
565
565
  pe as createForm,
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 I(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 z=/^[0-9]+$/,U=["__proto__","prototype","constructor"];function C(e,o,f){const i=Z(f)?f:void 0;if(!A(e)||!L(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)||W(l)?l:I(l)?u(l):l[r])};if(I(e)&&!z.test(r)?e=u(e):e=e[r],k(e)||W(e))break}return k(e)?i:e}}function _(e,o,f){if(!A(e)||!L(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),N=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:N,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:N,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 G=w?t.h(f,{schema:w}):void 0;return m?(n.push(t.h(o,{name:m,is:p,type:E,defaultValue:N,showValid:q,props:d},v??G)),n):p?(n.push(t.h(p,d,v??G)),n):(w&&n.push(G),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"})});
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/package.json CHANGED
@@ -19,7 +19,7 @@
19
19
  "bugs": {
20
20
  "url": "https://github.com/volverjs/form-vue/issues"
21
21
  },
22
- "version": "0.0.10-beta.8",
22
+ "version": "0.0.10-beta.9",
23
23
  "engines": {
24
24
  "node": ">= 16.x"
25
25
  },
@@ -76,7 +76,7 @@ export const defineFormField = <Schema extends FormSchema>(
76
76
  type: [String, Number, Boolean, Array, Object],
77
77
  default: undefined,
78
78
  },
79
- lazyload: {
79
+ lazyLoad: {
80
80
  type: Boolean,
81
81
  default: false,
82
82
  },
@@ -235,7 +235,7 @@ export const defineFormField = <Schema extends FormSchema>(
235
235
  },
236
236
  }
237
237
  }
238
- if (!(options?.lazyLoad ?? props.lazyload)) {
238
+ if (!(options?.lazyLoad ?? props.lazyLoad)) {
239
239
  let component: string | ConcreteComponent
240
240
  switch (props.type) {
241
241
  case FormFieldType.select: