@volverjs/form-vue 0.0.12-beta.2 → 0.0.13-beta.1

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.
@@ -39,7 +39,21 @@ export declare const defineFormField: <Schema extends FormSchema>(formProvideKey
39
39
  __isTeleport?: undefined;
40
40
  __isSuspense?: undefined;
41
41
  } | ConcreteComponent>;
42
- hasProps: import("vue").ComputedRef<any>;
42
+ hasProps: import("vue").ComputedRef<{
43
+ name: {} | ([{
44
+ type: PropType<Path<z.TypeOf<Schema>>>;
45
+ required: true;
46
+ }] extends [import("vue").Prop<infer V, infer D>] ? unknown extends V ? import("@vue/shared").IfAny<V, V, D> : V : {
47
+ type: PropType<Path<z.TypeOf<Schema>>>;
48
+ required: true;
49
+ });
50
+ invalid: boolean;
51
+ valid: boolean | undefined;
52
+ type: FormFieldType | undefined;
53
+ invalidLabel: any;
54
+ modelValue: any;
55
+ 'onUpdate:modelValue': (value: unknown) => void;
56
+ }>;
43
57
  invalid: import("vue").ComputedRef<boolean>;
44
58
  }, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, ("invalid" | "valid" | "update:modelValue" | "update:formData")[], "invalid" | "valid" | "update:modelValue" | "update:formData", import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<{
45
59
  type: {
package/dist/index.d.ts CHANGED
@@ -408,7 +408,21 @@ export declare const useForm: <Schema extends FormSchema>(schema: Schema, option
408
408
  __isTeleport?: undefined;
409
409
  __isSuspense?: undefined;
410
410
  } | import("vue").ConcreteComponent>;
411
- hasProps: import("vue").ComputedRef<any>;
411
+ hasProps: import("vue").ComputedRef<{
412
+ name: {} | ([{
413
+ type: import("vue").PropType<Path<import("zod").TypeOf<Schema>>>;
414
+ required: true;
415
+ }] extends [import("vue").Prop<infer V, infer D>] ? unknown extends V ? import("@vue/shared").IfAny<V, V, D> : V : {
416
+ type: import("vue").PropType<Path<import("zod").TypeOf<Schema>>>;
417
+ required: true;
418
+ });
419
+ invalid: boolean;
420
+ valid: boolean | undefined;
421
+ type: import("./enums").FormFieldType | undefined;
422
+ invalidLabel: any;
423
+ modelValue: any;
424
+ 'onUpdate:modelValue': (value: unknown) => void;
425
+ }>;
412
426
  invalid: import("vue").ComputedRef<boolean>;
413
427
  }, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, ("invalid" | "valid" | "update:modelValue" | "update:formData")[], "invalid" | "valid" | "update:modelValue" | "update:formData", import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<{
414
428
  type: {
@@ -895,7 +909,21 @@ export declare const formFactory: <Schema extends FormSchema>(schema: Schema, op
895
909
  __isTeleport?: undefined;
896
910
  __isSuspense?: undefined;
897
911
  } | import("vue").ConcreteComponent>;
898
- hasProps: import("vue").ComputedRef<any>;
912
+ hasProps: import("vue").ComputedRef<{
913
+ name: {} | ([{
914
+ type: import("vue").PropType<Path<import("zod").TypeOf<Schema>>>;
915
+ required: true;
916
+ }] extends [import("vue").Prop<infer V, infer D>] ? unknown extends V ? import("@vue/shared").IfAny<V, V, D> : V : {
917
+ type: import("vue").PropType<Path<import("zod").TypeOf<Schema>>>;
918
+ required: true;
919
+ });
920
+ invalid: boolean;
921
+ valid: boolean | undefined;
922
+ type: import("./enums").FormFieldType | undefined;
923
+ invalidLabel: any;
924
+ modelValue: any;
925
+ 'onUpdate:modelValue': (value: unknown) => void;
926
+ }>;
899
927
  invalid: import("vue").ComputedRef<boolean>;
900
928
  }, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, ("invalid" | "valid" | "update:modelValue" | "update:formData")[], "invalid" | "valid" | "update:modelValue" | "update:formData", import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<{
901
929
  type: {
package/dist/index.es.js CHANGED
@@ -1,47 +1,47 @@
1
- import { defineComponent as G, computed as y, onMounted as R, onBeforeUnmount as T, inject as O, toRefs as U, watch as w, provide as z, readonly as k, resolveComponent as g, defineAsyncComponent as D, h as x, ref as E, toRaw as Z, isProxy 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 J, ZodDefault as te, ZodNullable as ae, ZodSchema as ne, ZodEffects as se, ZodOptional as oe } from "zod";
1
+ import { defineComponent as W, computed as y, onMounted as T, onBeforeUnmount as D, inject as S, toRefs as q, watch as O, unref as I, provide as z, readonly as k, resolveComponent as g, defineAsyncComponent as j, h as x, ref as C, toRaw as J, isProxy as F, withModifiers as ee, getCurrentInstance as re } from "vue";
2
+ import { watchThrottled as te } from "@vueuse/core";
3
+ import { ZodObject as M, ZodDefault as ae, ZodNullable as ne, ZodSchema as se, ZodEffects as oe, ZodOptional as ue } from "zod";
4
4
  function A(e) {
5
5
  return Array.isArray(e);
6
6
  }
7
- function ue(e) {
7
+ function ie(e) {
8
8
  return typeof e < "u";
9
9
  }
10
- function M(e) {
10
+ function U(e) {
11
11
  return e === null;
12
12
  }
13
- function q(e) {
13
+ function P(e) {
14
14
  return typeof e == "object";
15
15
  }
16
- function P(e) {
16
+ function H(e) {
17
17
  return typeof e == "string";
18
18
  }
19
- function $(e) {
19
+ function L(e) {
20
20
  return typeof e > "u";
21
21
  }
22
- const ie = /^[0-9]+$/, le = ["__proto__", "prototype", "constructor"];
23
- function N(e, s, l) {
24
- const u = ue(l) ? l : void 0;
25
- if (!q(e) || !P(s))
22
+ const le = /^[0-9]+$/, fe = ["__proto__", "prototype", "constructor"];
23
+ function B(e, s, l) {
24
+ const u = ie(l) ? l : void 0;
25
+ if (!P(e) || !H(s))
26
26
  return u;
27
- const n = Q(s);
27
+ const n = R(s);
28
28
  if (n.length !== 0) {
29
29
  for (const r of n) {
30
30
  if (r === "*")
31
31
  continue;
32
32
  const o = function(a) {
33
- return a.map((i) => $(i) || M(i) ? i : A(i) ? o(i) : i[r]);
33
+ return a.map((i) => L(i) || U(i) ? i : A(i) ? o(i) : i[r]);
34
34
  };
35
- if (A(e) && !ie.test(r) ? e = o(e) : e = e[r], $(e) || M(e))
35
+ if (A(e) && !le.test(r) ? e = o(e) : e = e[r], L(e) || U(e))
36
36
  break;
37
37
  }
38
- return $(e) ? u : e;
38
+ return L(e) ? u : e;
39
39
  }
40
40
  }
41
- function H(e, s, l) {
42
- if (!q(e) || !P(s))
41
+ function Q(e, s, l) {
42
+ if (!P(e) || !H(s))
43
43
  return;
44
- const u = Q(s);
44
+ const u = R(s);
45
45
  if (u.length === 0)
46
46
  return;
47
47
  const n = u.length;
@@ -54,24 +54,24 @@ function H(e, s, l) {
54
54
  if (o === "*" && A(e)) {
55
55
  const a = u.slice(r + 1).join(".");
56
56
  for (const i of e)
57
- H(i, a, l);
57
+ Q(i, a, l);
58
58
  return;
59
59
  }
60
- $(e[o]) && (e[o] = {}), e = e[o];
60
+ L(e[o]) && (e[o] = {}), e = e[o];
61
61
  }
62
62
  }
63
- function Q(e) {
63
+ function R(e) {
64
64
  const s = e.split(/[.]|(?:\[(\d|\*)\])/).filter((l) => !!l);
65
- return s.some((l) => le.indexOf(l) !== -1) ? [] : s;
65
+ return s.some((l) => fe.indexOf(l) !== -1) ? [] : s;
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 || {}), L = /* @__PURE__ */ ((e) => (e.invalid = "invalid", e.valid = "valid", e))(L || {});
68
- const fe = (e, s, l, u) => G({
67
+ var v = /* @__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))(v || {}), N = /* @__PURE__ */ ((e) => (e.invalid = "invalid", e.valid = "valid", e))(N || {});
68
+ const ve = (e, s, l, u) => W({
69
69
  name: "FieldComponent",
70
70
  props: {
71
71
  type: {
72
72
  type: String,
73
- validator: (n) => Object.values(f).includes(n),
74
- default: f.custom
73
+ validator: (n) => Object.values(v).includes(n),
74
+ default: v.custom
75
75
  },
76
76
  is: {
77
77
  type: [Object, String],
@@ -104,36 +104,36 @@ const fe = (e, s, l, u) => G({
104
104
  const a = y({
105
105
  get() {
106
106
  if (t != null && t.formData)
107
- return N(
107
+ return B(
108
108
  Object(t.formData.value),
109
109
  String(n.name)
110
110
  );
111
111
  },
112
- set(v) {
113
- t != null && t.formData && (H(
112
+ set(f) {
113
+ t != null && t.formData && (Q(
114
114
  Object(t.formData.value),
115
115
  String(n.name),
116
- v
116
+ f
117
117
  ), o("update:modelValue", {
118
118
  newValue: a.value,
119
119
  formData: t == null ? void 0 : t.formData
120
120
  }));
121
121
  }
122
122
  });
123
- R(() => {
123
+ T(() => {
124
124
  a.value === void 0 && n.defaultValue !== void 0 && (a.value = n.defaultValue);
125
- }), T(() => {
126
- S(), V();
125
+ }), D(() => {
126
+ E(), V();
127
127
  });
128
- const i = O(s, void 0);
128
+ const i = S(s, void 0);
129
129
  i && i.fields.value.add(n.name);
130
- const t = O(e), { props: m, name: h } = U(n), d = y(() => {
130
+ const t = S(e), { props: m, name: h } = q(n), d = y(() => {
131
131
  if (t != null && t.errors.value)
132
- return N(t.errors.value, String(n.name));
132
+ return B(t.errors.value, String(n.name));
133
133
  }), c = y(() => {
134
- var v;
135
- return (v = d.value) == null ? void 0 : v._errors;
136
- }), b = y(() => d.value !== void 0), S = w(b, () => {
134
+ var f;
135
+ return (f = d.value) == null ? void 0 : f._errors;
136
+ }), b = y(() => d.value !== void 0), E = O(b, () => {
137
137
  b.value ? (o("invalid", c.value), i && i.errors.value.set(
138
138
  n.name,
139
139
  {
@@ -142,36 +142,42 @@ const fe = (e, s, l, u) => G({
142
142
  )) : (o("valid", a.value), i && i.errors.value.delete(
143
143
  n.name
144
144
  ));
145
- }), V = w(
145
+ }), V = O(
146
146
  () => t == null ? void 0 : t.formData,
147
147
  () => {
148
148
  o("update:formData", t == null ? void 0 : t.formData);
149
149
  },
150
150
  { deep: !0 }
151
- ), p = (v) => {
152
- a.value = v;
153
- }, I = y(() => typeof m.value == "function" ? m.value(t == null ? void 0 : t.formData) : m.value), W = y(() => ({
154
- ...I.value,
155
- name: I.value.name ?? n.name,
151
+ ), p = (f) => {
152
+ a.value = f;
153
+ }, $ = y(() => {
154
+ let f = m.value;
155
+ return typeof f == "function" && (f = f(t == null ? void 0 : t.formData)), Object.keys(f).reduce(
156
+ (w, Z) => (w[Z] = I(f[Z]), w),
157
+ {}
158
+ );
159
+ }), _ = y(() => ({
160
+ ...$.value,
161
+ name: $.value.name ?? n.name,
156
162
  invalid: b.value,
157
163
  valid: n.showValid ? !!(!b.value && a.value) : void 0,
158
- type: ((v) => {
164
+ type: ((f) => {
159
165
  if ([
160
- f.text,
161
- f.number,
162
- f.email,
163
- f.password,
164
- f.tel,
165
- f.url,
166
- f.search,
167
- f.date,
168
- f.time,
169
- f.datetimeLocal,
170
- f.month,
171
- f.week,
172
- f.color
173
- ].includes(v))
174
- return v;
166
+ v.text,
167
+ v.number,
168
+ v.email,
169
+ v.password,
170
+ v.tel,
171
+ v.url,
172
+ v.search,
173
+ v.date,
174
+ v.time,
175
+ v.datetimeLocal,
176
+ v.month,
177
+ v.week,
178
+ v.color
179
+ ].includes(f))
180
+ return f;
175
181
  })(n.type),
176
182
  invalidLabel: c.value,
177
183
  modelValue: a.value,
@@ -181,11 +187,11 @@ const fe = (e, s, l, u) => G({
181
187
  name: k(h),
182
188
  errors: k(d)
183
189
  }), { component: y(() => {
184
- if (n.type === f.custom)
190
+ if (n.type === v.custom)
185
191
  return {
186
192
  render() {
187
- var v;
188
- return ((v = r.default) == null ? void 0 : v.call(r, {
193
+ var f;
194
+ return ((f = r.default) == null ? void 0 : f.call(r, {
189
195
  modelValue: a.value,
190
196
  onUpdate: p,
191
197
  submit: t == null ? void 0 : t.submit,
@@ -199,86 +205,86 @@ const fe = (e, s, l, u) => G({
199
205
  }
200
206
  };
201
207
  if (!((u == null ? void 0 : u.lazyLoad) ?? n.lazyLoad)) {
202
- let v;
208
+ let f;
203
209
  switch (n.type) {
204
- case f.select:
205
- v = g("VvSelect");
210
+ case v.select:
211
+ f = g("VvSelect");
206
212
  break;
207
- case f.checkbox:
208
- v = g("VvCheckbox");
213
+ case v.checkbox:
214
+ f = g("VvCheckbox");
209
215
  break;
210
- case f.radio:
211
- v = g("VvRadio");
216
+ case v.radio:
217
+ f = g("VvRadio");
212
218
  break;
213
- case f.textarea:
214
- v = g("VvTextarea");
219
+ case v.textarea:
220
+ f = g("VvTextarea");
215
221
  break;
216
- case f.radioGroup:
217
- v = g("VvRadioGroup");
222
+ case v.radioGroup:
223
+ f = g("VvRadioGroup");
218
224
  break;
219
- case f.checkboxGroup:
220
- v = g("VvCheckboxGroup");
225
+ case v.checkboxGroup:
226
+ f = g("VvCheckboxGroup");
221
227
  break;
222
- case f.combobox:
223
- v = g("VvCombobox");
228
+ case v.combobox:
229
+ f = g("VvCombobox");
224
230
  break;
225
231
  default:
226
- v = g("VvInputText");
232
+ f = g("VvInputText");
227
233
  }
228
- if (typeof v != "string")
229
- return v;
234
+ if (typeof f != "string")
235
+ return f;
230
236
  console.warn(
231
- `[form-vue warn]: ${v} not found, the component will be loaded asynchronously. To avoid this warning, please set "lazyLoad" option.`
237
+ `[form-vue warn]: ${f} not found, the component will be loaded asynchronously. To avoid this warning, please set "lazyLoad" option.`
232
238
  );
233
239
  }
234
- return D(async () => {
240
+ return j(async () => {
235
241
  switch (u != null && u.sideEffects && await Promise.resolve(u.sideEffects(n.type)), n.type) {
236
- case f.textarea:
242
+ case v.textarea:
237
243
  return import("@volverjs/ui-vue/vv-textarea");
238
- case f.radio:
244
+ case v.radio:
239
245
  return import("@volverjs/ui-vue/vv-radio");
240
- case f.radioGroup:
246
+ case v.radioGroup:
241
247
  return import("@volverjs/ui-vue/vv-radio-group");
242
- case f.checkbox:
248
+ case v.checkbox:
243
249
  return import("@volverjs/ui-vue/vv-checkbox");
244
- case f.checkboxGroup:
250
+ case v.checkboxGroup:
245
251
  return import("@volverjs/ui-vue/vv-checkbox-group");
246
- case f.select:
252
+ case v.select:
247
253
  return import("@volverjs/ui-vue/vv-select");
248
- case f.combobox:
254
+ case v.combobox:
249
255
  return import("@volverjs/ui-vue/vv-combobox");
250
256
  }
251
257
  return import("@volverjs/ui-vue/vv-input-text");
252
258
  });
253
- }), hasProps: W, invalid: b };
259
+ }), hasProps: _, invalid: b };
254
260
  },
255
261
  render() {
256
- 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);
262
+ return this.is ? x(this.is, this.hasProps, this.$slots) : this.type === v.custom ? x(this.component, null, this.$slots) : x(this.component, this.hasProps, this.$slots);
257
263
  }
258
264
  }), X = (e, s = {}) => {
259
265
  const l = (r) => {
260
266
  let o = r;
261
- for (; o instanceof se; )
262
- o = o.innerType();
263
267
  for (; o instanceof oe; )
268
+ o = o.innerType();
269
+ for (; o instanceof ue; )
264
270
  o = o._def.innerType;
265
271
  return o;
266
272
  }, u = l(e);
267
273
  return {
268
- ...(u instanceof J ? u._def.unknownKeys === "passthrough" : !1) ? s : {},
274
+ ...(u instanceof M ? u._def.unknownKeys === "passthrough" : !1) ? s : {},
269
275
  ...Object.fromEntries(
270
276
  Object.entries(u.shape).map(
271
277
  ([r, o]) => {
272
278
  const a = s[r], i = l(o);
273
279
  let t;
274
- if (i instanceof te && (t = i._def.defaultValue()), a === null && i instanceof ae)
280
+ if (i instanceof ae && (t = i._def.defaultValue()), a === null && i instanceof ne)
275
281
  return [r, a];
276
- if (i instanceof ne) {
282
+ if (i instanceof se) {
277
283
  const m = o.safeParse(a);
278
284
  if (m.success)
279
285
  return [r, m.data ?? t];
280
286
  }
281
- return i instanceof J ? [
287
+ return i instanceof M ? [
282
288
  r,
283
289
  X(
284
290
  i,
@@ -289,8 +295,8 @@ const fe = (e, s, l, u) => G({
289
295
  )
290
296
  )
291
297
  };
292
- }, ve = (e, s, l) => {
293
- const u = E(), n = E(), r = E(), o = G({
298
+ }, de = (e, s, l) => {
299
+ const u = C(), n = C(), r = C(), o = W({
294
300
  name: "FormComponent",
295
301
  props: {
296
302
  modelValue: {
@@ -311,17 +317,17 @@ const fe = (e, s, l, u) => G({
311
317
  setup(a, { emit: i }) {
312
318
  r.value = X(
313
319
  e,
314
- Z(a.modelValue)
315
- ), w(
320
+ J(a.modelValue)
321
+ ), O(
316
322
  () => a.modelValue,
317
323
  (d) => {
318
324
  if (d) {
319
- const c = j(d) ? Z(d) : d;
325
+ const c = F(d) ? J(d) : d;
320
326
  r.value = typeof (c == null ? void 0 : c.clone) == "function" ? c.clone() : JSON.parse(JSON.stringify(c));
321
327
  }
322
328
  },
323
329
  { deep: !0 }
324
- ), re(
330
+ ), te(
325
331
  r,
326
332
  (d) => {
327
333
  ((u.value || (l == null ? void 0 : l.continuosValidation)) ?? a.continuosValidation) && t(), (!d || !a.modelValue || JSON.stringify(d) !== JSON.stringify(a.modelValue)) && i("update:modelValue", d);
@@ -333,8 +339,8 @@ const fe = (e, s, l, u) => G({
333
339
  );
334
340
  const t = (d = r.value) => {
335
341
  const c = e.safeParse(d);
336
- return c.success ? (u.value = void 0, n.value = L.valid, r.value = c.data, i("update:modelValue", r.value), i("valid", c.data), !0) : (u.value = c.error.format(), n.value = L.invalid, i("invalid", u.value), !1);
337
- }, m = () => t() ? (i("submit", r.value), !0) : !1, h = y(() => n.value === L.invalid);
342
+ return c.success ? (u.value = void 0, n.value = N.valid, r.value = c.data, i("update:modelValue", r.value), i("valid", c.data), !0) : (u.value = c.error.format(), n.value = N.invalid, i("invalid", u.value), !1);
343
+ }, m = () => t() ? (i("submit", r.value), !0) : !1, h = y(() => n.value === N.invalid);
338
344
  return z(s, {
339
345
  formData: r,
340
346
  submit: m,
@@ -355,7 +361,7 @@ const fe = (e, s, l, u) => G({
355
361
  return x(
356
362
  "form",
357
363
  {
358
- onSubmit: F(this.submit, ["prevent"])
364
+ onSubmit: ee(this.submit, ["prevent"])
359
365
  },
360
366
  {
361
367
  default: () => {
@@ -382,7 +388,7 @@ const fe = (e, s, l, u) => G({
382
388
  */
383
389
  VvForm: o
384
390
  };
385
- }, de = (e, s) => G({
391
+ }, ce = (e, s) => W({
386
392
  name: "WrapperComponent",
387
393
  props: {
388
394
  name: {
@@ -397,12 +403,12 @@ const fe = (e, s, l, u) => G({
397
403
  emits: ["invalid", "valid"],
398
404
  expose: ["fields", "invalid"],
399
405
  setup(u, { emit: n }) {
400
- const r = O(e), o = O(s, void 0), a = E(/* @__PURE__ */ new Set()), i = E(/* @__PURE__ */ new Map()), { name: t } = U(u);
406
+ const r = S(e), o = S(s, void 0), a = C(/* @__PURE__ */ new Set()), i = C(/* @__PURE__ */ new Map()), { name: t } = q(u);
401
407
  z(s, {
402
408
  name: k(t),
403
409
  errors: i,
404
410
  fields: a
405
- }), w(
411
+ }), O(
406
412
  a,
407
413
  (h) => {
408
414
  o != null && o.fields && h.forEach((d) => {
@@ -410,7 +416,7 @@ const fe = (e, s, l, u) => G({
410
416
  });
411
417
  },
412
418
  { deep: !0 }
413
- ), w(
419
+ ), O(
414
420
  () => new Map(i.value),
415
421
  (h, d) => {
416
422
  o != null && o.errors && (Array.from(d.keys()).forEach((c) => {
@@ -423,7 +429,7 @@ const fe = (e, s, l, u) => G({
423
429
  { deep: !0 }
424
430
  );
425
431
  const m = y(() => r != null && r.invalid.value ? i.value.size > 0 : !1);
426
- return w(m, () => {
432
+ return O(m, () => {
427
433
  m.value ? n("invalid") : n("valid");
428
434
  }), {
429
435
  formData: r == null ? void 0 : r.formData,
@@ -458,8 +464,8 @@ const fe = (e, s, l, u) => G({
458
464
  fieldsErrors: this.fieldsErrors
459
465
  })) ?? this.$slots.defalut;
460
466
  }
461
- }), ce = (e, s) => {
462
- const l = G({
467
+ }), me = (e, s) => {
468
+ const l = W({
463
469
  props: {
464
470
  schema: {
465
471
  type: [Array, Function],
@@ -467,7 +473,7 @@ const fe = (e, s, l, u) => G({
467
473
  }
468
474
  },
469
475
  setup(u, { slots: n }) {
470
- const r = O(e);
476
+ const r = S(e);
471
477
  if (!(r != null && r.formData))
472
478
  return;
473
479
  const o = typeof u.schema == "function" ? u.schema(r) : u.schema;
@@ -480,30 +486,30 @@ const fe = (e, s, l, u) => G({
480
486
  vvIs: d,
481
487
  vvName: c,
482
488
  vvSlots: b,
483
- vvChildren: S,
489
+ vvChildren: E,
484
490
  vvIf: V,
485
491
  vvElseIf: p,
486
- vvType: I,
487
- vvDefaultValue: W,
492
+ vvType: $,
493
+ vvDefaultValue: _,
488
494
  vvShowValid: K,
489
- ...v
495
+ ...f
490
496
  } = h;
491
497
  if (V !== void 0) {
492
- if (typeof V == "string" ? a = !!N(
498
+ if (typeof V == "string" ? a = !!B(
493
499
  Object(r.formData.value),
494
500
  V
495
- ) : typeof V == "function" ? a = C(V(r)) : a = C(V), !a)
501
+ ) : typeof V == "function" ? a = I(V(r)) : a = I(V), !a)
496
502
  return t;
497
503
  } else if (p !== void 0 && a !== void 0) {
498
- if (a || (typeof p == "string" ? a = !!N(
504
+ if (a || (typeof p == "string" ? a = !!B(
499
505
  Object(r.formData.value),
500
506
  p
501
- ) : typeof p == "function" ? a = C(p(r)) : a = C(p), !a))
507
+ ) : typeof p == "function" ? a = I(p(r)) : a = I(p), !a))
502
508
  return t;
503
509
  } else
504
510
  a = void 0;
505
- const _ = S ? x(l, {
506
- schema: S
511
+ const w = E ? x(l, {
512
+ schema: E
507
513
  }) : void 0;
508
514
  return c ? (t.push(
509
515
  x(
@@ -511,20 +517,20 @@ const fe = (e, s, l, u) => G({
511
517
  {
512
518
  name: c,
513
519
  is: d,
514
- type: I,
515
- defaultValue: W,
520
+ type: $,
521
+ defaultValue: _,
516
522
  showValid: K,
517
- props: v
523
+ props: f
518
524
  },
519
- b ?? _
525
+ b ?? w
520
526
  )
521
527
  ), t) : d ? (t.push(
522
528
  x(
523
529
  d,
524
- v,
525
- b ?? _
530
+ f,
531
+ b ?? w
526
532
  )
527
- ), t) : (S && t.push(_), t);
533
+ ), t) : (E && t.push(w), t);
528
534
  },
529
535
  [
530
536
  (i = n == null ? void 0 : n.default) == null ? void 0 : i.call(n, {
@@ -541,20 +547,20 @@ const fe = (e, s, l, u) => G({
541
547
  }
542
548
  });
543
549
  return l;
544
- }, B = (e, s = {}) => {
545
- const l = Symbol(), u = Symbol(), n = Symbol(), { VvForm: r, errors: o, status: a, formData: i } = ve(
550
+ }, G = (e, s = {}) => {
551
+ const l = Symbol(), u = Symbol(), n = Symbol(), { VvForm: r, errors: o, status: a, formData: i } = de(
546
552
  e,
547
553
  l,
548
554
  s
549
- ), t = de(
555
+ ), t = ce(
550
556
  l,
551
557
  u
552
- ), m = fe(
558
+ ), m = ve(
553
559
  l,
554
560
  u,
555
561
  n,
556
562
  s
557
- ), h = ce(l, m);
563
+ ), h = me(l, m);
558
564
  return {
559
565
  VvForm: r,
560
566
  VvFormWrapper: t,
@@ -567,23 +573,23 @@ const fe = (e, s, l, u) => G({
567
573
  status: a,
568
574
  formData: i
569
575
  };
570
- }, Y = Symbol(), pe = (e) => {
576
+ }, Y = Symbol(), ye = (e) => {
571
577
  let s = {};
572
- return e.schema && (s = B(e.schema, e)), {
578
+ return e.schema && (s = G(e.schema, e)), {
573
579
  ...s,
574
580
  install(l, { global: u = !1 } = {}) {
575
581
  l.provide(Y, e), u && (l.config.globalProperties.$vvForm = e, s != null && s.VvForm && l.component("VvForm", s.VvForm), s != null && s.VvFormWrapper && l.component("VvFormWrapper", s.VvFormWrapper), s != null && s.VvFormField && l.component("VvFormField", s.VvFormField), s != null && s.VvFormTemplate && l.component("VvFormTemplate", s.VvFormTemplate));
576
582
  }
577
583
  };
578
- }, ye = (e, s = {}) => ee() ? B(e, {
579
- ...O(Y, {}),
584
+ }, Ve = (e, s = {}) => re() ? G(e, {
585
+ ...S(Y, {}),
580
586
  ...s
581
- }) : B(e, s), Ve = (e, s = {}) => B(e, s);
587
+ }) : G(e, s), ge = (e, s = {}) => G(e, s);
582
588
  export {
583
- f as FormFieldType,
584
- pe as createForm,
589
+ v as FormFieldType,
590
+ ye as createForm,
585
591
  X as defaultObjectBySchema,
586
- Ve as formFactory,
592
+ ge as formFactory,
587
593
  Y as pluginInjectionKey,
588
- ye as useForm
594
+ Ve as useForm
589
595
  };
package/dist/index.umd.js CHANGED
@@ -1 +1 @@
1
- (function(p,r){typeof exports=="object"&&typeof module<"u"?r(exports,require("vue"),require("@vueuse/core"),require("zod")):typeof define=="function"&&define.amd?define(["exports","vue","@vueuse/core","zod"],r):(p=typeof globalThis<"u"?globalThis:p||self,r(p["@volverjs/form-vue"]={},p.Vue,p.VueUseCore,p.zod))})(this,function(p,r,q,x){"use strict";function I(e){return Array.isArray(e)}function M(e){return typeof e<"u"}function G(e){return e===null}function W(e){return typeof e=="object"}function _(e){return typeof e=="string"}function k(e){return typeof e>"u"}const U=/^[0-9]+$/,z=["__proto__","prototype","constructor"];function C(e,s,f){const l=M(f)?f:void 0;if(!W(e)||!_(s))return l;const o=K(s);if(o.length!==0){for(const t of o){if(t==="*")continue;const i=function(a){return a.map(u=>k(u)||G(u)?u:I(u)?i(u):u[t])};if(I(e)&&!U.test(t)?e=i(e):e=e[t],k(e)||G(e))break}return k(e)?l:e}}function A(e,s,f){if(!W(e)||!_(s))return;const l=K(s);if(l.length===0)return;const o=l.length;for(let t=0;t<o;t++){const i=l[t];if(t===o-1){e[i]=f;return}if(i==="*"&&I(e)){const a=l.slice(t+1).join(".");for(const u of e)A(u,a,f);return}k(e[i])&&(e[i]={}),e=e[i]}}function K(e){const s=e.split(/[.]|(?:\[(\d|\*)\])/).filter(f=>!!f);return s.some(f=>z.indexOf(f)!==-1)?[]:s}var d=(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))(d||{}),O=(e=>(e.invalid="invalid",e.valid="valid",e))(O||{});const J=(e,s,f,l)=>r.defineComponent({name:"FieldComponent",props:{type:{type:String,validator:o=>Object.values(d).includes(o),default:d.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(o,{slots:t,emit:i}){const a=r.computed({get(){if(n!=null&&n.formData)return C(Object(n.formData.value),String(o.name))},set(c){n!=null&&n.formData&&(A(Object(n.formData.value),String(o.name),c),i("update:modelValue",{newValue:a.value,formData:n==null?void 0:n.formData}))}});r.onMounted(()=>{a.value===void 0&&o.defaultValue!==void 0&&(a.value=o.defaultValue)}),r.onBeforeUnmount(()=>{w(),g()});const u=r.inject(s,void 0);u&&u.fields.value.add(o.name);const n=r.inject(e),{props:h,name:y}=r.toRefs(o),m=r.computed(()=>{if(n!=null&&n.errors.value)return C(n.errors.value,String(o.name))}),v=r.computed(()=>{var c;return(c=m.value)==null?void 0:c._errors}),b=r.computed(()=>m.value!==void 0),w=r.watch(b,()=>{b.value?(i("invalid",v.value),u&&u.errors.value.set(o.name,{_errors:v.value})):(i("valid",a.value),u&&u.errors.value.delete(o.name))}),g=r.watch(()=>n==null?void 0:n.formData,()=>{i("update:formData",n==null?void 0:n.formData)},{deep:!0}),V=c=>{a.value=c},E=r.computed(()=>typeof h.value=="function"?h.value(n==null?void 0:n.formData):h.value),L=r.computed(()=>({...E.value,name:E.value.name??o.name,invalid:b.value,valid:o.showValid?!!(!b.value&&a.value):void 0,type:(c=>{if([d.text,d.number,d.email,d.password,d.tel,d.url,d.search,d.date,d.time,d.datetimeLocal,d.month,d.week,d.color].includes(c))return c})(o.type),invalidLabel:v.value,modelValue:a.value,"onUpdate:modelValue":V}));return r.provide(f,{name:r.readonly(y),errors:r.readonly(m)}),{component:r.computed(()=>{if(o.type===d.custom)return{render(){var c;return((c=t.default)==null?void 0:c.call(t,{modelValue:a.value,onUpdate:V,submit:n==null?void 0:n.submit,validate:n==null?void 0:n.validate,invalid:b.value,invalidLabel:v.value,formData:n==null?void 0:n.formData.value,formErrors:n==null?void 0:n.errors.value,errors:m.value}))??t.defalut}};if(!((l==null?void 0:l.lazyLoad)??o.lazyLoad)){let c;switch(o.type){case d.select:c=r.resolveComponent("VvSelect");break;case d.checkbox:c=r.resolveComponent("VvCheckbox");break;case d.radio:c=r.resolveComponent("VvRadio");break;case d.textarea:c=r.resolveComponent("VvTextarea");break;case d.radioGroup:c=r.resolveComponent("VvRadioGroup");break;case d.checkboxGroup:c=r.resolveComponent("VvCheckboxGroup");break;case d.combobox:c=r.resolveComponent("VvCombobox");break;default:c=r.resolveComponent("VvInputText")}if(typeof c!="string")return c;console.warn(`[form-vue warn]: ${c} not found, the component will be loaded asynchronously. To avoid this warning, please set "lazyLoad" option.`)}return r.defineAsyncComponent(async()=>{switch(l!=null&&l.sideEffects&&await Promise.resolve(l.sideEffects(o.type)),o.type){case d.textarea:return import("@volverjs/ui-vue/vv-textarea");case d.radio:return import("@volverjs/ui-vue/vv-radio");case d.radioGroup:return import("@volverjs/ui-vue/vv-radio-group");case d.checkbox:return import("@volverjs/ui-vue/vv-checkbox");case d.checkboxGroup:return import("@volverjs/ui-vue/vv-checkbox-group");case d.select:return import("@volverjs/ui-vue/vv-select");case d.combobox:return import("@volverjs/ui-vue/vv-combobox")}return import("@volverjs/ui-vue/vv-input-text")})}),hasProps:L,invalid:b}},render(){return this.is?r.h(this.is,this.hasProps,this.$slots):this.type===d.custom?r.h(this.component,null,this.$slots):r.h(this.component,this.hasProps,this.$slots)}}),$=(e,s={})=>{const f=t=>{let i=t;for(;i instanceof x.ZodEffects;)i=i.innerType();for(;i instanceof x.ZodOptional;)i=i._def.innerType;return i},l=f(e);return{...(l instanceof x.ZodObject?l._def.unknownKeys==="passthrough":!1)?s:{},...Object.fromEntries(Object.entries(l.shape).map(([t,i])=>{const a=s[t],u=f(i);let n;if(u instanceof x.ZodDefault&&(n=u._def.defaultValue()),a===null&&u instanceof x.ZodNullable)return[t,a];if(u instanceof x.ZodSchema){const h=i.safeParse(a);if(h.success)return[t,h.data??n]}return u instanceof x.ZodObject?[t,$(u,a&&typeof a=="object"?a:{})]:[t,n]}))}},P=(e,s,f)=>{const l=r.ref(),o=r.ref(),t=r.ref(),i=r.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","validate","errors","status","valid","invalid"],setup(a,{emit:u}){t.value=$(e,r.toRaw(a.modelValue)),r.watch(()=>a.modelValue,m=>{if(m){const v=r.isProxy(m)?r.toRaw(m):m;t.value=typeof(v==null?void 0:v.clone)=="function"?v.clone():JSON.parse(JSON.stringify(v))}},{deep:!0}),q.watchThrottled(t,m=>{((l.value||(f==null?void 0:f.continuosValidation))??a.continuosValidation)&&n(),(!m||!a.modelValue||JSON.stringify(m)!==JSON.stringify(a.modelValue))&&u("update:modelValue",m)},{deep:!0,throttle:(f==null?void 0:f.updateThrottle)??a.updateThrottle});const n=(m=t.value)=>{const v=e.safeParse(m);return v.success?(l.value=void 0,o.value=O.valid,t.value=v.data,u("update:modelValue",t.value),u("valid",v.data),!0):(l.value=v.error.format(),o.value=O.invalid,u("invalid",l.value),!1)},h=()=>n()?(u("submit",t.value),!0):!1,y=r.computed(()=>o.value===O.invalid);return r.provide(s,{formData:t,submit:h,validate:n,errors:r.readonly(l),status:r.readonly(o),invalid:y}),{formData:t,submit:h,validate:n,errors:r.readonly(l),status:r.readonly(o),invalid:y}},render(){return r.h("form",{onSubmit:r.withModifiers(this.submit,["prevent"])},{default:()=>{var a,u;return((u=(a=this.$slots)==null?void 0:a.default)==null?void 0:u.call(a,{formData:this.formData,submit:this.submit,validate:this.validate,errors:this.errors,status:this.status,invalid:this.invalid}))??this.$slots.default}})}});return{errors:l,status:o,formData:t,VvForm:i}},T=(e,s)=>r.defineComponent({name:"WrapperComponent",props:{name:{type:String,required:!0},tag:{type:String,default:void 0}},emits:["invalid","valid"],expose:["fields","invalid"],setup(l,{emit:o}){const t=r.inject(e),i=r.inject(s,void 0),a=r.ref(new Set),u=r.ref(new Map),{name:n}=r.toRefs(l);r.provide(s,{name:r.readonly(n),errors:u,fields:a}),r.watch(a,y=>{i!=null&&i.fields&&y.forEach(m=>{i==null||i.fields.value.add(m)})},{deep:!0}),r.watch(()=>new Map(u.value),(y,m)=>{i!=null&&i.errors&&(Array.from(m.keys()).forEach(v=>{i.errors.value.delete(v)}),Array.from(y.keys()).forEach(v=>{const b=y.get(v);b&&i.errors.value.set(v,b)}))},{deep:!0});const h=r.computed(()=>t!=null&&t.invalid.value?u.value.size>0:!1);return r.watch(h,()=>{h.value?o("invalid"):o("valid")}),{formData:t==null?void 0:t.formData,errors:t==null?void 0:t.errors,submit:t==null?void 0:t.submit,validate:t==null?void 0:t.validate,invalid:h,fields:a,fieldsErrors:u}},render(){var l,o;return this.tag?r.h(this.tag,null,{default:()=>{var t,i;return((i=(t=this.$slots).default)==null?void 0:i.call(t,{invalid:this.invalid,formData:this.formData,submit:this.submit,validate:this.validate,errors:this.errors,fieldsErrors:this.fieldsErrors}))??this.$slots.defalut}}):((o=(l=this.$slots).default)==null?void 0:o.call(l,{invalid:this.invalid,formData:this.formData,submit:this.submit,validate:this.validate,errors:this.errors,fieldsErrors:this.fieldsErrors}))??this.$slots.defalut}}),R=(e,s)=>{const f=r.defineComponent({props:{schema:{type:[Array,Function],required:!0}},setup(l,{slots:o}){const t=r.inject(e);if(!(t!=null&&t.formData))return;const i=typeof l.schema=="function"?l.schema(t):l.schema;let a;return()=>{var u;return i.reduce((n,h)=>{const y=typeof h=="function"?h(t):h,{vvIs:m,vvName:v,vvSlots:b,vvChildren:w,vvIf:g,vvElseIf:V,vvType:E,vvDefaultValue:L,vvShowValid:Z,...c}=y;if(g!==void 0){if(typeof g=="string"?a=!!C(Object(t.formData.value),g):typeof g=="function"?a=r.unref(g(t)):a=r.unref(g),!a)return n}else if(V!==void 0&&a!==void 0){if(a||(typeof V=="string"?a=!!C(Object(t.formData.value),V):typeof V=="function"?a=r.unref(V(t)):a=r.unref(V),!a))return n}else a=void 0;const N=w?r.h(f,{schema:w}):void 0;return v?(n.push(r.h(s,{name:v,is:m,type:E,defaultValue:L,showValid:Z,props:c},b??N)),n):m?(n.push(r.h(m,c,b??N)),n):(w&&n.push(N),n)},[(u=o==null?void 0:o.default)==null?void 0:u.call(o,{formData:t==null?void 0:t.formData.value,submit:t==null?void 0:t.submit,validate:t==null?void 0:t.validate,errors:t==null?void 0:t.errors.value,status:t==null?void 0:t.status.value,invalid:t==null?void 0:t.invalid.value})])}}});return f},S=(e,s={})=>{const f=Symbol(),l=Symbol(),o=Symbol(),{VvForm:t,errors:i,status:a,formData:u}=P(e,f,s),n=T(f,l),h=J(f,l,o,s),y=R(f,h);return{VvForm:t,VvFormWrapper:n,VvFormField:h,VvFormTemplate:y,formInjectionKey:f,formWrapperInjectionKey:l,formFieldInjectionKey:o,errors:i,status:a,formData:u}},B=Symbol(),H=e=>{let s={};return e.schema&&(s=S(e.schema,e)),{...s,install(f,{global:l=!1}={}){f.provide(B,e),l&&(f.config.globalProperties.$vvForm=e,s!=null&&s.VvForm&&f.component("VvForm",s.VvForm),s!=null&&s.VvFormWrapper&&f.component("VvFormWrapper",s.VvFormWrapper),s!=null&&s.VvFormField&&f.component("VvFormField",s.VvFormField),s!=null&&s.VvFormTemplate&&f.component("VvFormTemplate",s.VvFormTemplate))}}},Q=(e,s={})=>r.getCurrentInstance()?S(e,{...r.inject(B,{}),...s}):S(e,s),X=(e,s={})=>S(e,s);p.FormFieldType=d,p.createForm=H,p.defaultObjectBySchema=$,p.formFactory=X,p.pluginInjectionKey=B,p.useForm=Q,Object.defineProperty(p,Symbol.toStringTag,{value:"Module"})});
1
+ (function(p,r){typeof exports=="object"&&typeof module<"u"?r(exports,require("vue"),require("@vueuse/core"),require("zod")):typeof define=="function"&&define.amd?define(["exports","vue","@vueuse/core","zod"],r):(p=typeof globalThis<"u"?globalThis:p||self,r(p["@volverjs/form-vue"]={},p.Vue,p.VueUseCore,p.zod))})(this,function(p,r,M,x){"use strict";function $(e){return Array.isArray(e)}function U(e){return typeof e<"u"}function G(e){return e===null}function W(e){return typeof e=="object"}function _(e){return typeof e=="string"}function k(e){return typeof e>"u"}const z=/^[0-9]+$/,J=["__proto__","prototype","constructor"];function C(e,s,f){const l=U(f)?f:void 0;if(!W(e)||!_(s))return l;const a=K(s);if(a.length!==0){for(const t of a){if(t==="*")continue;const i=function(o){return o.map(u=>k(u)||G(u)?u:$(u)?i(u):u[t])};if($(e)&&!z.test(t)?e=i(e):e=e[t],k(e)||G(e))break}return k(e)?l:e}}function A(e,s,f){if(!W(e)||!_(s))return;const l=K(s);if(l.length===0)return;const a=l.length;for(let t=0;t<a;t++){const i=l[t];if(t===a-1){e[i]=f;return}if(i==="*"&&$(e)){const o=l.slice(t+1).join(".");for(const u of e)A(u,o,f);return}k(e[i])&&(e[i]={}),e=e[i]}}function K(e){const s=e.split(/[.]|(?:\[(\d|\*)\])/).filter(f=>!!f);return s.some(f=>J.indexOf(f)!==-1)?[]:s}var d=(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))(d||{}),S=(e=>(e.invalid="invalid",e.valid="valid",e))(S||{});const P=(e,s,f,l)=>r.defineComponent({name:"FieldComponent",props:{type:{type:String,validator:a=>Object.values(d).includes(a),default:d.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:t,emit:i}){const o=r.computed({get(){if(n!=null&&n.formData)return C(Object(n.formData.value),String(a.name))},set(c){n!=null&&n.formData&&(A(Object(n.formData.value),String(a.name),c),i("update:modelValue",{newValue:o.value,formData:n==null?void 0:n.formData}))}});r.onMounted(()=>{o.value===void 0&&a.defaultValue!==void 0&&(o.value=a.defaultValue)}),r.onBeforeUnmount(()=>{O(),g()});const u=r.inject(s,void 0);u&&u.fields.value.add(a.name);const n=r.inject(e),{props:h,name:y}=r.toRefs(a),m=r.computed(()=>{if(n!=null&&n.errors.value)return C(n.errors.value,String(a.name))}),v=r.computed(()=>{var c;return(c=m.value)==null?void 0:c._errors}),b=r.computed(()=>m.value!==void 0),O=r.watch(b,()=>{b.value?(i("invalid",v.value),u&&u.errors.value.set(a.name,{_errors:v.value})):(i("valid",o.value),u&&u.errors.value.delete(a.name))}),g=r.watch(()=>n==null?void 0:n.formData,()=>{i("update:formData",n==null?void 0:n.formData)},{deep:!0}),V=c=>{o.value=c},I=r.computed(()=>{let c=h.value;return typeof c=="function"&&(c=c(n==null?void 0:n.formData)),Object.keys(c).reduce((w,q)=>(w[q]=r.unref(c[q]),w),{})}),N=r.computed(()=>({...I.value,name:I.value.name??a.name,invalid:b.value,valid:a.showValid?!!(!b.value&&o.value):void 0,type:(c=>{if([d.text,d.number,d.email,d.password,d.tel,d.url,d.search,d.date,d.time,d.datetimeLocal,d.month,d.week,d.color].includes(c))return c})(a.type),invalidLabel:v.value,modelValue:o.value,"onUpdate:modelValue":V}));return r.provide(f,{name:r.readonly(y),errors:r.readonly(m)}),{component:r.computed(()=>{if(a.type===d.custom)return{render(){var c;return((c=t.default)==null?void 0:c.call(t,{modelValue:o.value,onUpdate:V,submit:n==null?void 0:n.submit,validate:n==null?void 0:n.validate,invalid:b.value,invalidLabel:v.value,formData:n==null?void 0:n.formData.value,formErrors:n==null?void 0:n.errors.value,errors:m.value}))??t.defalut}};if(!((l==null?void 0:l.lazyLoad)??a.lazyLoad)){let c;switch(a.type){case d.select:c=r.resolveComponent("VvSelect");break;case d.checkbox:c=r.resolveComponent("VvCheckbox");break;case d.radio:c=r.resolveComponent("VvRadio");break;case d.textarea:c=r.resolveComponent("VvTextarea");break;case d.radioGroup:c=r.resolveComponent("VvRadioGroup");break;case d.checkboxGroup:c=r.resolveComponent("VvCheckboxGroup");break;case d.combobox:c=r.resolveComponent("VvCombobox");break;default:c=r.resolveComponent("VvInputText")}if(typeof c!="string")return c;console.warn(`[form-vue warn]: ${c} not found, the component will be loaded asynchronously. To avoid this warning, please set "lazyLoad" option.`)}return r.defineAsyncComponent(async()=>{switch(l!=null&&l.sideEffects&&await Promise.resolve(l.sideEffects(a.type)),a.type){case d.textarea:return import("@volverjs/ui-vue/vv-textarea");case d.radio:return import("@volverjs/ui-vue/vv-radio");case d.radioGroup:return import("@volverjs/ui-vue/vv-radio-group");case d.checkbox:return import("@volverjs/ui-vue/vv-checkbox");case d.checkboxGroup:return import("@volverjs/ui-vue/vv-checkbox-group");case d.select:return import("@volverjs/ui-vue/vv-select");case d.combobox:return import("@volverjs/ui-vue/vv-combobox")}return import("@volverjs/ui-vue/vv-input-text")})}),hasProps:N,invalid:b}},render(){return this.is?r.h(this.is,this.hasProps,this.$slots):this.type===d.custom?r.h(this.component,null,this.$slots):r.h(this.component,this.hasProps,this.$slots)}}),B=(e,s={})=>{const f=t=>{let i=t;for(;i instanceof x.ZodEffects;)i=i.innerType();for(;i instanceof x.ZodOptional;)i=i._def.innerType;return i},l=f(e);return{...(l instanceof x.ZodObject?l._def.unknownKeys==="passthrough":!1)?s:{},...Object.fromEntries(Object.entries(l.shape).map(([t,i])=>{const o=s[t],u=f(i);let n;if(u instanceof x.ZodDefault&&(n=u._def.defaultValue()),o===null&&u instanceof x.ZodNullable)return[t,o];if(u instanceof x.ZodSchema){const h=i.safeParse(o);if(h.success)return[t,h.data??n]}return u instanceof x.ZodObject?[t,B(u,o&&typeof o=="object"?o:{})]:[t,n]}))}},T=(e,s,f)=>{const l=r.ref(),a=r.ref(),t=r.ref(),i=r.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","validate","errors","status","valid","invalid"],setup(o,{emit:u}){t.value=B(e,r.toRaw(o.modelValue)),r.watch(()=>o.modelValue,m=>{if(m){const v=r.isProxy(m)?r.toRaw(m):m;t.value=typeof(v==null?void 0:v.clone)=="function"?v.clone():JSON.parse(JSON.stringify(v))}},{deep:!0}),M.watchThrottled(t,m=>{((l.value||(f==null?void 0:f.continuosValidation))??o.continuosValidation)&&n(),(!m||!o.modelValue||JSON.stringify(m)!==JSON.stringify(o.modelValue))&&u("update:modelValue",m)},{deep:!0,throttle:(f==null?void 0:f.updateThrottle)??o.updateThrottle});const n=(m=t.value)=>{const v=e.safeParse(m);return v.success?(l.value=void 0,a.value=S.valid,t.value=v.data,u("update:modelValue",t.value),u("valid",v.data),!0):(l.value=v.error.format(),a.value=S.invalid,u("invalid",l.value),!1)},h=()=>n()?(u("submit",t.value),!0):!1,y=r.computed(()=>a.value===S.invalid);return r.provide(s,{formData:t,submit:h,validate:n,errors:r.readonly(l),status:r.readonly(a),invalid:y}),{formData:t,submit:h,validate:n,errors:r.readonly(l),status:r.readonly(a),invalid:y}},render(){return r.h("form",{onSubmit:r.withModifiers(this.submit,["prevent"])},{default:()=>{var o,u;return((u=(o=this.$slots)==null?void 0:o.default)==null?void 0:u.call(o,{formData:this.formData,submit:this.submit,validate:this.validate,errors:this.errors,status:this.status,invalid:this.invalid}))??this.$slots.default}})}});return{errors:l,status:a,formData:t,VvForm:i}},R=(e,s)=>r.defineComponent({name:"WrapperComponent",props:{name:{type:String,required:!0},tag:{type:String,default:void 0}},emits:["invalid","valid"],expose:["fields","invalid"],setup(l,{emit:a}){const t=r.inject(e),i=r.inject(s,void 0),o=r.ref(new Set),u=r.ref(new Map),{name:n}=r.toRefs(l);r.provide(s,{name:r.readonly(n),errors:u,fields:o}),r.watch(o,y=>{i!=null&&i.fields&&y.forEach(m=>{i==null||i.fields.value.add(m)})},{deep:!0}),r.watch(()=>new Map(u.value),(y,m)=>{i!=null&&i.errors&&(Array.from(m.keys()).forEach(v=>{i.errors.value.delete(v)}),Array.from(y.keys()).forEach(v=>{const b=y.get(v);b&&i.errors.value.set(v,b)}))},{deep:!0});const h=r.computed(()=>t!=null&&t.invalid.value?u.value.size>0:!1);return r.watch(h,()=>{h.value?a("invalid"):a("valid")}),{formData:t==null?void 0:t.formData,errors:t==null?void 0:t.errors,submit:t==null?void 0:t.submit,validate:t==null?void 0:t.validate,invalid:h,fields:o,fieldsErrors:u}},render(){var l,a;return this.tag?r.h(this.tag,null,{default:()=>{var t,i;return((i=(t=this.$slots).default)==null?void 0:i.call(t,{invalid:this.invalid,formData:this.formData,submit:this.submit,validate:this.validate,errors:this.errors,fieldsErrors:this.fieldsErrors}))??this.$slots.defalut}}):((a=(l=this.$slots).default)==null?void 0:a.call(l,{invalid:this.invalid,formData:this.formData,submit:this.submit,validate:this.validate,errors:this.errors,fieldsErrors:this.fieldsErrors}))??this.$slots.defalut}}),H=(e,s)=>{const f=r.defineComponent({props:{schema:{type:[Array,Function],required:!0}},setup(l,{slots:a}){const t=r.inject(e);if(!(t!=null&&t.formData))return;const i=typeof l.schema=="function"?l.schema(t):l.schema;let o;return()=>{var u;return i.reduce((n,h)=>{const y=typeof h=="function"?h(t):h,{vvIs:m,vvName:v,vvSlots:b,vvChildren:O,vvIf:g,vvElseIf:V,vvType:I,vvDefaultValue:N,vvShowValid:Z,...c}=y;if(g!==void 0){if(typeof g=="string"?o=!!C(Object(t.formData.value),g):typeof g=="function"?o=r.unref(g(t)):o=r.unref(g),!o)return n}else if(V!==void 0&&o!==void 0){if(o||(typeof V=="string"?o=!!C(Object(t.formData.value),V):typeof V=="function"?o=r.unref(V(t)):o=r.unref(V),!o))return n}else o=void 0;const w=O?r.h(f,{schema:O}):void 0;return v?(n.push(r.h(s,{name:v,is:m,type:I,defaultValue:N,showValid:Z,props:c},b??w)),n):m?(n.push(r.h(m,c,b??w)),n):(O&&n.push(w),n)},[(u=a==null?void 0:a.default)==null?void 0:u.call(a,{formData:t==null?void 0:t.formData.value,submit:t==null?void 0:t.submit,validate:t==null?void 0:t.validate,errors:t==null?void 0:t.errors.value,status:t==null?void 0:t.status.value,invalid:t==null?void 0:t.invalid.value})])}}});return f},E=(e,s={})=>{const f=Symbol(),l=Symbol(),a=Symbol(),{VvForm:t,errors:i,status:o,formData:u}=T(e,f,s),n=R(f,l),h=P(f,l,a,s),y=H(f,h);return{VvForm:t,VvFormWrapper:n,VvFormField:h,VvFormTemplate:y,formInjectionKey:f,formWrapperInjectionKey:l,formFieldInjectionKey:a,errors:i,status:o,formData:u}},L=Symbol(),Q=e=>{let s={};return e.schema&&(s=E(e.schema,e)),{...s,install(f,{global:l=!1}={}){f.provide(L,e),l&&(f.config.globalProperties.$vvForm=e,s!=null&&s.VvForm&&f.component("VvForm",s.VvForm),s!=null&&s.VvFormWrapper&&f.component("VvFormWrapper",s.VvFormWrapper),s!=null&&s.VvFormField&&f.component("VvFormField",s.VvFormField),s!=null&&s.VvFormTemplate&&f.component("VvFormTemplate",s.VvFormTemplate))}}},X=(e,s={})=>r.getCurrentInstance()?E(e,{...r.inject(L,{}),...s}):E(e,s),Y=(e,s={})=>E(e,s);p.FormFieldType=d,p.createForm=Q,p.defaultObjectBySchema=B,p.formFactory=Y,p.pluginInjectionKey=L,p.useForm=X,Object.defineProperty(p,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.12-beta.2",
22
+ "version": "0.0.13-beta.1",
23
23
  "engines": {
24
24
  "node": ">= 16.x"
25
25
  },
@@ -35,33 +35,33 @@
35
35
  "*.d.ts"
36
36
  ],
37
37
  "dependencies": {
38
- "@volverjs/ui-vue": "0.0.6-beta.7",
38
+ "@volverjs/ui-vue": "0.0.7",
39
39
  "@vueuse/core": "^10.1.2",
40
40
  "ts-dot-prop": "^2.1.2",
41
- "vue": "^3.3.2",
41
+ "vue": "^3.3.4",
42
42
  "zod": "^3.21.4"
43
43
  },
44
44
  "devDependencies": {
45
- "@playwright/experimental-ct-vue": "1.32.3",
45
+ "@playwright/experimental-ct-vue": "1.33.0",
46
46
  "@testing-library/vue": "^7.0.0",
47
47
  "@typescript-eslint/eslint-plugin": "^5.59.6",
48
48
  "@typescript-eslint/parser": "^5.59.6",
49
49
  "@vitejs/plugin-vue": "^4.2.3",
50
50
  "@volverjs/style": "^0.1.10",
51
- "@vue/compiler-sfc": "^3.3.2",
52
- "@vue/runtime-core": "^3.3.2",
51
+ "@vue/compiler-sfc": "^3.3.4",
52
+ "@vue/runtime-core": "^3.3.4",
53
53
  "@vue/test-utils": "^2.3.2",
54
54
  "copy": "^0.3.2",
55
55
  "eslint": "^8.40.0",
56
56
  "eslint-config-prettier": "^8.8.0",
57
57
  "eslint-plugin-prettier": "^4.2.1",
58
- "happy-dom": "^9.18.3",
58
+ "happy-dom": "^9.19.2",
59
59
  "prettier": "^2.8.8",
60
60
  "typescript": "^5.0.4",
61
- "vite": "^4.3.7",
61
+ "vite": "^4.3.8",
62
62
  "vite-plugin-eslint": "^1.8.1",
63
63
  "vite-plugin-externalize-deps": "^0.6.0",
64
- "vitest": "^0.30.1",
64
+ "vitest": "^0.31.1",
65
65
  "vue-tsc": "^1.6.5"
66
66
  },
67
67
  "typesVersions": {
@@ -17,6 +17,7 @@ import {
17
17
  watch,
18
18
  defineComponent,
19
19
  onBeforeUnmount,
20
+ unref,
20
21
  } from 'vue'
21
22
  import type { z } from 'zod'
22
23
  import { FormFieldType } from './enums'
@@ -173,10 +174,17 @@ export const defineFormField = <Schema extends FormSchema>(
173
174
  modelValue.value = value
174
175
  }
175
176
  const hasFieldProps = computed(() => {
176
- if (typeof fieldProps.value === 'function') {
177
- return fieldProps.value(injectedFormData?.formData)
177
+ let toReturn = fieldProps.value
178
+ if (typeof toReturn === 'function') {
179
+ toReturn = toReturn(injectedFormData?.formData)
178
180
  }
179
- return fieldProps.value
181
+ return Object.keys(toReturn).reduce<Record<string, unknown>>(
182
+ (acc, key) => {
183
+ acc[key] = unref(toReturn[key])
184
+ return acc
185
+ },
186
+ {},
187
+ )
180
188
  })
181
189
  const hasProps = computed(() => ({
182
190
  ...hasFieldProps.value,
@@ -58,6 +58,7 @@ export const defineFormTemplate = <Schema extends FormSchema>(
58
58
  vvShowValid,
59
59
  ...props
60
60
  } = normalizedField
61
+
61
62
  // conditions
62
63
  if (vvIf !== undefined) {
63
64
  if (typeof vvIf === 'string') {