@volverjs/form-vue 1.0.0-beta.5 → 1.0.0-beta.7

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/dist/index.es.js CHANGED
@@ -1,7 +1,7 @@
1
- import { defineComponent as z, computed as k, onMounted as D, onBeforeUnmount as j, inject as U, toRefs as P, watch as I, unref as B, provide as M, readonly as S, resolveComponent as O, defineAsyncComponent as F, h as w, ref as C, toRaw as E, isProxy as ee, withModifiers as re, getCurrentInstance as te } from "vue";
1
+ import { defineComponent as z, computed as w, onMounted as P, onBeforeUnmount as j, inject as B, toRefs as H, watch as O, unref as C, provide as M, readonly as E, resolveComponent as S, defineAsyncComponent as F, h as p, ref as $, toRaw as A, isProxy as ee, withModifiers as re, getCurrentInstance as te } from "vue";
2
2
  import { watchIgnorable as ae, throttleFilter as ne } from "@vueuse/core";
3
- import { ZodObject as K, ZodDefault as ue, ZodNullable as le, ZodSchema as se, ZodArray as ie, ZodEffects as fe, ZodOptional as oe } from "zod";
4
- function R(e) {
3
+ import { ZodObject as Z, ZodDefault as ue, ZodNullable as le, ZodSchema as se, ZodArray as ie, ZodEffects as fe, ZodOptional as oe } from "zod";
4
+ function J(e) {
5
5
  return Array.isArray(e);
6
6
  }
7
7
  function de(e) {
@@ -10,62 +10,62 @@ function de(e) {
10
10
  function q(e) {
11
11
  return e === null;
12
12
  }
13
- function H(e) {
13
+ function Q(e) {
14
14
  return typeof e == "object";
15
15
  }
16
- function Q(e) {
16
+ function X(e) {
17
17
  return typeof e == "string";
18
18
  }
19
19
  function G(e) {
20
20
  return typeof e > "u";
21
21
  }
22
22
  const ve = /^[0-9]+$/, ce = ["__proto__", "prototype", "constructor"];
23
- function L(e, s, t) {
23
+ function L(e, i, t) {
24
24
  const o = de(t) ? t : void 0;
25
- if (!H(e) || !Q(s))
25
+ if (!Q(e) || !X(i))
26
26
  return o;
27
- const u = Y(s);
27
+ const u = T(i);
28
28
  if (u.length !== 0) {
29
29
  for (const r of u) {
30
30
  if (r === "*")
31
31
  continue;
32
- const l = function(a) {
33
- return a.map((f) => G(f) || q(f) ? f : R(f) ? l(f) : f[r]);
32
+ const s = function(n) {
33
+ return n.map((f) => G(f) || q(f) ? f : J(f) ? s(f) : f[r]);
34
34
  };
35
- if (R(e) && !ve.test(r) ? e = l(e) : e = e[r], G(e) || q(e))
35
+ if (J(e) && !ve.test(r) ? e = s(e) : e = e[r], G(e) || q(e))
36
36
  break;
37
37
  }
38
38
  return G(e) ? o : e;
39
39
  }
40
40
  }
41
- function X(e, s, t) {
42
- if (!H(e) || !Q(s))
41
+ function Y(e, i, t) {
42
+ if (!Q(e) || !X(i))
43
43
  return;
44
- const o = Y(s);
44
+ const o = T(i);
45
45
  if (o.length === 0)
46
46
  return;
47
47
  const u = o.length;
48
48
  for (let r = 0; r < u; r++) {
49
- const l = o[r];
49
+ const s = o[r];
50
50
  if (r === u - 1) {
51
- e[l] = t;
51
+ e[s] = t;
52
52
  return;
53
53
  }
54
- if (l === "*" && R(e)) {
55
- const a = o.slice(r + 1).join(".");
54
+ if (s === "*" && J(e)) {
55
+ const n = o.slice(r + 1).join(".");
56
56
  for (const f of e)
57
- X(f, a, t);
57
+ Y(f, n, t);
58
58
  return;
59
59
  }
60
- G(e[l]) && (e[l] = {}), e = e[l];
60
+ G(e[s]) && (e[s] = {}), e = e[s];
61
61
  }
62
62
  }
63
- function Y(e) {
64
- const s = e.split(/[.]|(?:\[(\d|\*)\])/).filter((t) => !!t);
65
- return s.some((t) => ce.indexOf(t) !== -1) ? [] : s;
63
+ function T(e) {
64
+ const i = e.split(/[.]|(?:\[(\d|\*)\])/).filter((t) => !!t);
65
+ return i.some((t) => ce.indexOf(t) !== -1) ? [] : i;
66
66
  }
67
- var d = /* @__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 = "datetime-local", 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 || {}), x = /* @__PURE__ */ ((e) => (e.invalid = "invalid", e.valid = "valid", e.submitting = "submitting", e.updated = "updated", e.unknown = "unknown", e))(x || {});
68
- const me = (e, s, t, o) => z({
67
+ var d = /* @__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 = "datetime-local", 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 || {}), k = /* @__PURE__ */ ((e) => (e.invalid = "invalid", e.valid = "valid", e.submitting = "submitting", e.updated = "updated", e.unknown = "unknown", e))(k || {});
68
+ const me = (e, i, t, o) => z({
69
69
  name: "VvFormField",
70
70
  props: {
71
71
  type: {
@@ -96,72 +96,79 @@ const me = (e, s, t, o) => z({
96
96
  lazyLoad: {
97
97
  type: Boolean,
98
98
  default: !1
99
+ },
100
+ readonly: {
101
+ type: Boolean,
102
+ default: void 0
99
103
  }
100
104
  },
101
105
  emits: ["invalid", "valid", "update:formData", "update:modelValue"],
102
106
  expose: ["invalid", "invalidLabel", "errors"],
103
- setup(u, { slots: r, emit: l }) {
104
- const a = k({
107
+ setup(u, { slots: r, emit: s }) {
108
+ const n = w({
105
109
  get() {
106
- if (n != null && n.formData)
110
+ if (a != null && a.formData)
107
111
  return L(
108
- Object(n.formData.value),
112
+ Object(a.formData.value),
109
113
  String(u.name)
110
114
  );
111
115
  },
112
- set(i) {
113
- n != null && n.formData && (X(
114
- Object(n.formData.value),
116
+ set(l) {
117
+ a != null && a.formData && (Y(
118
+ Object(a.formData.value),
115
119
  String(u.name),
116
- i
117
- ), l("update:modelValue", {
118
- newValue: a.value,
119
- formData: n == null ? void 0 : n.formData
120
+ l
121
+ ), s("update:modelValue", {
122
+ newValue: n.value,
123
+ formData: a == null ? void 0 : a.formData
120
124
  }));
121
125
  }
122
126
  });
123
- D(() => {
124
- a.value === void 0 && u.defaultValue !== void 0 && (a.value = u.defaultValue);
127
+ P(() => {
128
+ n.value === void 0 && u.defaultValue !== void 0 && (n.value = u.defaultValue);
125
129
  }), j(() => {
126
- b(), y();
130
+ h(), m();
127
131
  });
128
- const f = U(s, void 0);
132
+ const f = B(i, void 0);
129
133
  f && f.fields.value.add(u.name);
130
- const n = U(e), { props: c, name: h } = P(u), V = k(() => {
131
- if (n != null && n.errors.value)
132
- return L(n.errors.value, String(u.name));
133
- }), m = k(() => {
134
- var i;
135
- return (i = V.value) == null ? void 0 : i._errors;
136
- }), v = k(() => V.value !== void 0), b = I(v, () => {
137
- v.value ? (l("invalid", m.value), f && f.errors.value.set(
134
+ const a = B(e), { props: c, name: b } = H(u), g = w(() => {
135
+ if (a != null && a.errors.value)
136
+ return L(a.errors.value, String(u.name));
137
+ }), V = w(() => {
138
+ var l;
139
+ return (l = g.value) == null ? void 0 : l._errors;
140
+ }), v = w(() => g.value !== void 0), h = O(v, () => {
141
+ v.value ? (s("invalid", V.value), f && f.errors.value.set(
138
142
  u.name,
139
143
  {
140
- _errors: m.value
144
+ _errors: V.value
141
145
  }
142
- )) : (l("valid", a.value), f && f.errors.value.delete(
146
+ )) : (s("valid", n.value), f && f.errors.value.delete(
143
147
  u.name
144
148
  ));
145
- }), y = I(
146
- () => n == null ? void 0 : n.formData,
149
+ }), m = O(
150
+ () => a == null ? void 0 : a.formData,
147
151
  () => {
148
- l("update:formData", n == null ? void 0 : n.formData);
152
+ s("update:formData", a == null ? void 0 : a.formData);
149
153
  },
150
154
  { deep: !0 }
151
- ), g = (i) => {
152
- a.value = i;
153
- }, p = k(() => {
154
- let i = c.value;
155
- return typeof i == "function" && (i = i(n == null ? void 0 : n.formData)), Object.keys(i).reduce(
156
- (_, $) => (_[$] = B(i[$]), _),
155
+ ), y = (l) => {
156
+ n.value = l;
157
+ }, x = w(() => {
158
+ let l = c.value;
159
+ return typeof l == "function" && (l = l(a == null ? void 0 : a.formData)), Object.keys(l).reduce(
160
+ (_, W) => (_[W] = C(l[W]), _),
157
161
  {}
158
162
  );
159
- }), A = k(() => ({
160
- ...p.value,
161
- name: p.value.name ?? u.name,
163
+ }), I = w(() => {
164
+ const l = x.value.readonly ?? u.readonly;
165
+ return l === void 0 ? a == null ? void 0 : a.readonly.value : l;
166
+ }), U = w(() => ({
167
+ ...x.value,
168
+ name: x.value.name ?? u.name,
162
169
  invalid: v.value,
163
- valid: u.showValid ? !!(!v.value && a.value) : void 0,
164
- type: ((i) => {
170
+ valid: u.showValid ? !!(!v.value && n.value) : void 0,
171
+ type: ((l) => {
165
172
  if ([
166
173
  d.text,
167
174
  d.number,
@@ -176,65 +183,67 @@ const me = (e, s, t, o) => z({
176
183
  d.month,
177
184
  d.week,
178
185
  d.color
179
- ].includes(i))
180
- return i;
186
+ ].includes(l))
187
+ return l;
181
188
  })(u.type),
182
- invalidLabel: m.value,
183
- modelValue: a.value,
184
- "onUpdate:modelValue": g
189
+ invalidLabel: V.value,
190
+ modelValue: n.value,
191
+ readonly: I.value,
192
+ "onUpdate:modelValue": y
185
193
  }));
186
194
  return M(t, {
187
- name: S(h),
188
- errors: S(V)
189
- }), { component: k(() => {
195
+ name: E(b),
196
+ errors: E(g)
197
+ }), { component: w(() => {
190
198
  if (u.type === d.custom)
191
199
  return {
192
200
  render() {
193
- var i;
194
- return ((i = r.default) == null ? void 0 : i.call(r, {
195
- modelValue: a.value,
196
- onUpdate: g,
197
- submit: n == null ? void 0 : n.submit,
198
- validate: n == null ? void 0 : n.validate,
201
+ var l;
202
+ return ((l = r.default) == null ? void 0 : l.call(r, {
203
+ modelValue: n.value,
204
+ onUpdate: y,
205
+ submit: a == null ? void 0 : a.submit,
206
+ validate: a == null ? void 0 : a.validate,
199
207
  invalid: v.value,
200
- invalidLabel: m.value,
201
- formData: n == null ? void 0 : n.formData.value,
202
- formErrors: n == null ? void 0 : n.errors.value,
203
- errors: V.value
208
+ invalidLabel: V.value,
209
+ formData: a == null ? void 0 : a.formData.value,
210
+ formErrors: a == null ? void 0 : a.errors.value,
211
+ errors: g.value,
212
+ readonly: I.value
204
213
  })) ?? r.defalut;
205
214
  }
206
215
  };
207
216
  if (!((o == null ? void 0 : o.lazyLoad) ?? u.lazyLoad)) {
208
- let i;
217
+ let l;
209
218
  switch (u.type) {
210
219
  case d.select:
211
- i = O("VvSelect");
220
+ l = S("VvSelect");
212
221
  break;
213
222
  case d.checkbox:
214
- i = O("VvCheckbox");
223
+ l = S("VvCheckbox");
215
224
  break;
216
225
  case d.radio:
217
- i = O("VvRadio");
226
+ l = S("VvRadio");
218
227
  break;
219
228
  case d.textarea:
220
- i = O("VvTextarea");
229
+ l = S("VvTextarea");
221
230
  break;
222
231
  case d.radioGroup:
223
- i = O("VvRadioGroup");
232
+ l = S("VvRadioGroup");
224
233
  break;
225
234
  case d.checkboxGroup:
226
- i = O("VvCheckboxGroup");
235
+ l = S("VvCheckboxGroup");
227
236
  break;
228
237
  case d.combobox:
229
- i = O("VvCombobox");
238
+ l = S("VvCombobox");
230
239
  break;
231
240
  default:
232
- i = O("VvInputText");
241
+ l = S("VvInputText");
233
242
  }
234
- if (typeof i != "string")
235
- return i;
243
+ if (typeof l != "string")
244
+ return l;
236
245
  console.warn(
237
- `[form-vue warn]: ${i} not found, the component will be loaded asynchronously. To avoid this warning, please set "lazyLoad" option.`
246
+ `[form-vue warn]: ${l} not found, the component will be loaded asynchronously. To avoid this warning, please set "lazyLoad" option.`
238
247
  );
239
248
  }
240
249
  return F(async () => {
@@ -256,64 +265,66 @@ const me = (e, s, t, o) => z({
256
265
  }
257
266
  return import("@volverjs/ui-vue/vv-input-text");
258
267
  });
259
- }), hasProps: A, invalid: v };
268
+ }), hasProps: U, invalid: v };
260
269
  },
261
270
  render() {
262
- return this.is ? w(this.is, this.hasProps, this.$slots) : this.type === d.custom ? w(this.component, null, this.$slots) : w(this.component, this.hasProps, this.$slots);
271
+ return this.is ? p(this.is, this.hasProps, this.$slots) : this.type === d.custom ? p(this.component, null, this.$slots) : p(this.component, this.hasProps, this.$slots);
263
272
  }
264
- }), J = (e, s = {}) => {
273
+ }), K = (e, i = {}) => {
265
274
  const t = (r) => {
266
- let l = r;
267
- for (; l instanceof fe; )
268
- l = l.innerType();
269
- return l instanceof oe && (l = l._def.innerType), l;
275
+ let s = r;
276
+ for (; s instanceof fe; )
277
+ s = s.innerType();
278
+ return s instanceof oe && (s = s._def.innerType), s;
270
279
  }, o = t(e);
271
280
  return {
272
- ...(o instanceof K ? o._def.unknownKeys === "passthrough" : !1) ? s : {},
281
+ ...(o instanceof Z ? o._def.unknownKeys === "passthrough" : !1) ? i : {},
273
282
  ...Object.fromEntries(
274
283
  Object.entries(o.shape).map(
275
- ([r, l]) => {
276
- const a = s[r];
277
- let f = t(l), n;
278
- if (f instanceof ue && (n = f._def.defaultValue(), f = f._def.innerType), a === null && f instanceof le)
279
- return [r, a];
284
+ ([r, s]) => {
285
+ const n = i[r];
286
+ let f = t(s), a;
287
+ if (f instanceof ue && (a = f._def.defaultValue(), f = f._def.innerType), n === null && f instanceof le)
288
+ return [r, n];
280
289
  if (f instanceof se) {
281
- const c = l.safeParse(a);
290
+ const c = s.safeParse(n);
282
291
  if (c.success)
283
- return [r, c.data ?? n];
292
+ return [r, c.data ?? a];
284
293
  }
285
- if (f instanceof ie && Array.isArray(a) && a.length) {
294
+ if (f instanceof ie && Array.isArray(n) && n.length) {
286
295
  const c = t(f._def.type);
287
- if (c instanceof K)
296
+ if (c instanceof Z)
288
297
  return [
289
298
  r,
290
- a.map(
291
- (h) => J(
299
+ n.map(
300
+ (b) => K(
292
301
  c,
293
- h && typeof h == "object" ? h : void 0
302
+ b && typeof b == "object" ? b : void 0
294
303
  )
295
- ) ?? n
304
+ ) ?? a
296
305
  ];
297
306
  }
298
- return f instanceof K ? [
307
+ return f instanceof Z ? [
299
308
  r,
300
- J(
309
+ K(
301
310
  f,
302
- a && typeof a == "object" ? a : n
311
+ n && typeof n == "object" ? n : a
303
312
  )
304
- ] : [r, n];
313
+ ] : [r, a];
305
314
  }
306
315
  )
307
316
  )
308
317
  };
309
- }, he = (e, s, t, o) => {
310
- const u = C(), r = C(), l = k(() => r.value === x.invalid), a = C(), f = async (m = a.value) => {
311
- const v = await e.safeParseAsync(m);
312
- return v.success ? (u.value = void 0, r.value = x.valid, a.value = v.data, !0) : (u.value = v.error.format(), r.value = x.invalid, !1);
313
- }, n = async () => await f() ? (r.value = x.submitting, !0) : !1, { ignoreUpdates: c, stop: h } = ae(
314
- a,
318
+ }, he = (e, i, t, o) => {
319
+ const u = $(), r = $(), s = w(() => r.value === k.invalid), n = $(), f = $(!1), a = async (v = n.value) => {
320
+ if (f.value)
321
+ return !0;
322
+ const h = await e.safeParseAsync(v);
323
+ return h.success ? (u.value = void 0, r.value = k.valid, n.value = h.data, !0) : (u.value = h.error.format(), r.value = k.invalid, !1);
324
+ }, c = async () => f.value || !await a() ? !1 : (r.value = k.submitting, !0), { ignoreUpdates: b, stop: g } = ae(
325
+ n,
315
326
  () => {
316
- r.value = x.updated;
327
+ r.value = k.updated;
317
328
  },
318
329
  {
319
330
  deep: !0,
@@ -330,6 +341,10 @@ const me = (e, s, t, o) => z({
330
341
  type: Object,
331
342
  default: () => ({})
332
343
  },
344
+ readonly: {
345
+ type: Boolean,
346
+ default: (t == null ? void 0 : t.readonly) ?? !1
347
+ },
333
348
  tag: {
334
349
  type: String,
335
350
  default: "form"
@@ -339,72 +354,99 @@ const me = (e, s, t, o) => z({
339
354
  default: void 0
340
355
  }
341
356
  },
342
- emits: ["invalid", "valid", "submit", "update:modelValue"],
343
- expose: ["submit", "validate", "errors", "status", "valid", "invalid"],
344
- setup(m, { emit: v }) {
345
- return a.value = J(
357
+ emits: [
358
+ "invalid",
359
+ "valid",
360
+ "submit",
361
+ "update:modelValue",
362
+ "update:readonly"
363
+ ],
364
+ expose: [
365
+ "submit",
366
+ "validate",
367
+ "errors",
368
+ "status",
369
+ "valid",
370
+ "invalid",
371
+ "readonly"
372
+ ],
373
+ setup(v, { emit: h }) {
374
+ return n.value = K(
346
375
  e,
347
- E(m.modelValue)
348
- ), I(
349
- () => m.modelValue,
350
- (b) => {
351
- if (b) {
352
- const y = ee(b) ? E(b) : b;
353
- a.value = typeof (y == null ? void 0 : y.clone) == "function" ? y.clone() : JSON.parse(JSON.stringify(y));
376
+ A(v.modelValue)
377
+ ), O(
378
+ () => v.modelValue,
379
+ (m) => {
380
+ if (m) {
381
+ const y = ee(m) ? A(m) : m;
382
+ if (JSON.stringify(y) === JSON.stringify(A(n.value)))
383
+ return;
384
+ n.value = typeof (y == null ? void 0 : y.clone) == "function" ? y.clone() : JSON.parse(JSON.stringify(y));
354
385
  }
355
386
  },
356
387
  { deep: !0 }
357
- ), I(r, async (b) => {
358
- var y, g, p, A, W;
359
- if (b === x.invalid) {
360
- const i = E(
388
+ ), O(r, async (m) => {
389
+ var y, x, I, U, N;
390
+ if (m === k.invalid) {
391
+ const l = A(
361
392
  u.value
362
393
  );
363
- v("invalid", i), (y = t == null ? void 0 : t.onInvalid) == null || y.call(t, i);
394
+ h("invalid", l), (y = t == null ? void 0 : t.onInvalid) == null || y.call(t, l);
364
395
  return;
365
396
  }
366
- if (b === x.valid) {
367
- const i = E(a.value);
368
- v("valid", i), (g = t == null ? void 0 : t.onValid) == null || g.call(t, i), v("update:modelValue", i), (p = t == null ? void 0 : t.onUpdate) == null || p.call(t, i);
397
+ if (m === k.valid) {
398
+ const l = A(n.value);
399
+ h("valid", l), (x = t == null ? void 0 : t.onValid) == null || x.call(t, l), h("update:modelValue", l), (I = t == null ? void 0 : t.onUpdate) == null || I.call(t, l);
369
400
  return;
370
401
  }
371
- if (b === x.submitting) {
372
- const i = E(a.value);
373
- v("submit", i), (A = t == null ? void 0 : t.onSubmit) == null || A.call(t, i);
402
+ if (m === k.submitting) {
403
+ const l = A(n.value);
404
+ h("submit", l), (U = t == null ? void 0 : t.onSubmit) == null || U.call(t, l);
374
405
  }
375
- if (b === x.updated) {
376
- if ((u.value || t != null && t.continuosValidation || m.continuosValidation) && await f(), !a.value || !m.modelValue || JSON.stringify(a.value) !== JSON.stringify(m.modelValue)) {
377
- const i = E(
378
- a.value
406
+ if (m === k.updated) {
407
+ if ((u.value || t != null && t.continuosValidation || v.continuosValidation) && await a(), !n.value || !v.modelValue || JSON.stringify(n.value) !== JSON.stringify(v.modelValue)) {
408
+ const l = A(
409
+ n.value
379
410
  );
380
- v("update:modelValue", i), (W = t == null ? void 0 : t.onUpdate) == null || W.call(t, i);
411
+ h("update:modelValue", l), (N = t == null ? void 0 : t.onUpdate) == null || N.call(t, l);
381
412
  }
382
- r.value === x.updated && (r.value = x.unknown);
413
+ r.value === k.updated && (r.value = k.unknown);
414
+ }
415
+ }), P(() => {
416
+ v.readonly && !f.value && (f.value = v.readonly);
417
+ }), O(
418
+ () => v.readonly,
419
+ (m) => {
420
+ f.value = m;
383
421
  }
384
- }), M(s, {
385
- formData: a,
386
- submit: n,
387
- validate: f,
388
- ignoreUpdates: c,
389
- stopUpdatesWatch: h,
390
- errors: S(u),
391
- status: S(r),
392
- invalid: l
422
+ ), O(f, (m) => {
423
+ m !== v.readonly && h("update:readonly", f.value);
424
+ }), M(i, {
425
+ formData: n,
426
+ submit: c,
427
+ validate: a,
428
+ ignoreUpdates: b,
429
+ stopUpdatesWatch: g,
430
+ errors: E(u),
431
+ status: E(r),
432
+ invalid: s,
433
+ readonly: f
393
434
  }), {
394
- formData: a,
395
- submit: n,
396
- validate: f,
397
- ignoreUpdates: c,
398
- stopUpdatesWatch: h,
399
- errors: S(u),
400
- status: S(r),
401
- invalid: l
435
+ formData: n,
436
+ submit: c,
437
+ validate: a,
438
+ ignoreUpdates: b,
439
+ stopUpdatesWatch: g,
440
+ errors: E(u),
441
+ status: E(r),
442
+ invalid: s,
443
+ isReadonly: f
402
444
  };
403
445
  },
404
446
  render() {
405
- const m = () => {
406
- var v, b;
407
- return ((b = (v = this.$slots) == null ? void 0 : v.default) == null ? void 0 : b.call(v, {
447
+ const v = () => {
448
+ var h, m;
449
+ return ((m = (h = this.$slots) == null ? void 0 : h.default) == null ? void 0 : m.call(h, {
408
450
  formData: this.formData,
409
451
  submit: this.submit,
410
452
  validate: this.validate,
@@ -412,26 +454,27 @@ const me = (e, s, t, o) => z({
412
454
  stopUpdatesWatch: this.stopUpdatesWatch,
413
455
  errors: this.errors,
414
456
  status: this.status,
415
- invalid: this.invalid
457
+ invalid: this.invalid,
458
+ readonly: this.isReadonly
416
459
  })) ?? this.$slots.default;
417
460
  };
418
- return w(
461
+ return p(
419
462
  this.tag,
420
463
  {
421
464
  onSubmit: re(this.submit, ["prevent"])
422
465
  },
423
466
  (this.template ?? (t == null ? void 0 : t.template)) && o ? [
424
- w(
467
+ p(
425
468
  o,
426
469
  {
427
470
  schema: this.template ?? (t == null ? void 0 : t.template)
428
471
  },
429
472
  {
430
- default: m
473
+ default: v
431
474
  }
432
475
  )
433
476
  ] : {
434
- default: m
477
+ default: v
435
478
  }
436
479
  );
437
480
  }
@@ -439,18 +482,19 @@ const me = (e, s, t, o) => z({
439
482
  return {
440
483
  errors: u,
441
484
  status: r,
442
- invalid: l,
443
- formData: a,
444
- validate: f,
445
- submit: n,
446
- ignoreUpdates: c,
447
- stopUpdatesWatch: h,
485
+ invalid: s,
486
+ readonly: f,
487
+ formData: n,
488
+ validate: a,
489
+ submit: c,
490
+ ignoreUpdates: b,
491
+ stopUpdatesWatch: g,
448
492
  /**
449
493
  * An hack to add types to the default slot
450
494
  */
451
495
  VvForm: V
452
496
  };
453
- }, be = (e, s) => z({
497
+ }, ye = (e, i) => z({
454
498
  name: "VvFormWrapper",
455
499
  props: {
456
500
  name: {
@@ -465,33 +509,33 @@ const me = (e, s, t, o) => z({
465
509
  emits: ["invalid", "valid"],
466
510
  expose: ["fields", "invalid"],
467
511
  setup(o, { emit: u }) {
468
- const r = U(e), l = U(s, void 0), a = C(/* @__PURE__ */ new Set()), f = C(/* @__PURE__ */ new Map()), { name: n } = P(o);
469
- M(s, {
470
- name: S(n),
512
+ const r = B(e), s = B(i, void 0), n = $(/* @__PURE__ */ new Set()), f = $(/* @__PURE__ */ new Map()), { name: a } = H(o);
513
+ M(i, {
514
+ name: E(a),
471
515
  errors: f,
472
- fields: a
473
- }), I(
474
- a,
475
- (h) => {
476
- l != null && l.fields && h.forEach((V) => {
477
- l == null || l.fields.value.add(V);
516
+ fields: n
517
+ }), O(
518
+ n,
519
+ (b) => {
520
+ s != null && s.fields && b.forEach((g) => {
521
+ s == null || s.fields.value.add(g);
478
522
  });
479
523
  },
480
524
  { deep: !0 }
481
- ), I(
525
+ ), O(
482
526
  () => new Map(f.value),
483
- (h, V) => {
484
- l != null && l.errors && (Array.from(V.keys()).forEach((m) => {
485
- l.errors.value.delete(m);
486
- }), Array.from(h.keys()).forEach((m) => {
487
- const v = h.get(m);
488
- v && l.errors.value.set(m, v);
527
+ (b, g) => {
528
+ s != null && s.errors && (Array.from(g.keys()).forEach((V) => {
529
+ s.errors.value.delete(V);
530
+ }), Array.from(b.keys()).forEach((V) => {
531
+ const v = b.get(V);
532
+ v && s.errors.value.set(V, v);
489
533
  }));
490
534
  },
491
535
  { deep: !0 }
492
536
  );
493
- const c = k(() => r != null && r.invalid.value ? f.value.size > 0 : !1);
494
- return I(c, () => {
537
+ const c = w(() => r != null && r.invalid.value ? f.value.size > 0 : !1);
538
+ return O(c, () => {
495
539
  c.value ? u("invalid") : u("valid");
496
540
  }), {
497
541
  formData: r == null ? void 0 : r.formData,
@@ -499,16 +543,16 @@ const me = (e, s, t, o) => z({
499
543
  submit: r == null ? void 0 : r.submit,
500
544
  validate: r == null ? void 0 : r.validate,
501
545
  invalid: c,
502
- fields: a,
546
+ fields: n,
503
547
  fieldsErrors: f
504
548
  };
505
549
  },
506
550
  render() {
507
551
  var o, u;
508
- return this.tag ? w(this.tag, null, {
552
+ return this.tag ? p(this.tag, null, {
509
553
  default: () => {
510
- var r, l;
511
- return ((l = (r = this.$slots).default) == null ? void 0 : l.call(r, {
554
+ var r, s;
555
+ return ((s = (r = this.$slots).default) == null ? void 0 : s.call(r, {
512
556
  invalid: this.invalid,
513
557
  formData: this.formData,
514
558
  submit: this.submit,
@@ -526,7 +570,7 @@ const me = (e, s, t, o) => z({
526
570
  fieldsErrors: this.fieldsErrors
527
571
  })) ?? this.$slots.defalut;
528
572
  }
529
- }), ye = (e, s) => {
573
+ }), be = (e, i) => {
530
574
  const t = z({
531
575
  name: "VvFormTemplate",
532
576
  props: {
@@ -536,66 +580,66 @@ const me = (e, s, t, o) => z({
536
580
  }
537
581
  },
538
582
  setup(o, { slots: u }) {
539
- const r = U(e);
583
+ const r = B(e);
540
584
  if (r != null && r.formData)
541
585
  return () => {
542
- var n;
543
- const l = typeof o.schema == "function" ? o.schema(r) : o.schema;
544
- let a;
545
- const f = l.reduce((c, h) => {
546
- const V = typeof h == "function" ? h(r) : h, {
547
- vvIs: m,
586
+ var a;
587
+ const s = typeof o.schema == "function" ? o.schema(r) : o.schema;
588
+ let n;
589
+ const f = s.reduce((c, b) => {
590
+ const g = typeof b == "function" ? b(r) : b, {
591
+ vvIs: V,
548
592
  vvName: v,
549
- vvSlots: b,
550
- vvChildren: y,
551
- vvIf: g,
552
- vvElseIf: p,
553
- vvType: A,
554
- vvDefaultValue: W,
555
- vvShowValid: i,
556
- vvContent: _,
557
- ...$
558
- } = V;
559
- if (g !== void 0) {
560
- if (typeof g == "string" ? a = !!L(
593
+ vvSlots: h,
594
+ vvChildren: m,
595
+ vvIf: y,
596
+ vvElseIf: x,
597
+ vvType: I,
598
+ vvDefaultValue: U,
599
+ vvShowValid: N,
600
+ vvContent: l,
601
+ ..._
602
+ } = g;
603
+ if (y !== void 0) {
604
+ if (typeof y == "string" ? n = !!L(
561
605
  Object(r.formData.value),
562
- g
563
- ) : typeof g == "function" ? a = B(g(r)) : a = B(g), !a)
606
+ y
607
+ ) : typeof y == "function" ? n = C(y(r)) : n = C(y), !n)
564
608
  return c;
565
- } else if (p !== void 0 && a !== void 0) {
566
- if (a || (typeof p == "string" ? a = !!L(
609
+ } else if (x !== void 0 && n !== void 0) {
610
+ if (n || (typeof x == "string" ? n = !!L(
567
611
  Object(r.formData.value),
568
- p
569
- ) : typeof p == "function" ? a = B(p(r)) : a = B(p), !a))
612
+ x
613
+ ) : typeof x == "function" ? n = C(x(r)) : n = C(x), !n))
570
614
  return c;
571
615
  } else
572
- a = void 0;
573
- const Z = y ? w(t, {
574
- schema: y
616
+ n = void 0;
617
+ const W = m ? p(t, {
618
+ schema: m
575
619
  }) : void 0;
576
620
  return v ? (c.push(
577
- w(
578
- s,
621
+ p(
622
+ i,
579
623
  {
580
624
  name: v,
581
- is: m,
582
- type: A,
583
- defaultValue: W,
584
- showValid: i,
585
- props: $
625
+ is: V,
626
+ type: I,
627
+ defaultValue: U,
628
+ showValid: N,
629
+ props: _
586
630
  },
587
- b ?? Z ?? _
631
+ h ?? W ?? l
588
632
  )
589
- ), c) : m ? (c.push(
590
- w(
591
- m,
592
- $,
593
- b ?? Z ?? _
633
+ ), c) : V ? (c.push(
634
+ p(
635
+ V,
636
+ _,
637
+ h ?? W ?? l
594
638
  )
595
- ), c) : (y && c.push(Z), c);
639
+ ), c) : (m && c.push(W), c);
596
640
  }, []);
597
641
  return f.push(
598
- (n = u == null ? void 0 : u.default) == null ? void 0 : n.call(u, {
642
+ (a = u == null ? void 0 : u.default) == null ? void 0 : a.call(u, {
599
643
  formData: r == null ? void 0 : r.formData.value,
600
644
  submit: r == null ? void 0 : r.submit,
601
645
  validate: r == null ? void 0 : r.validate,
@@ -608,63 +652,65 @@ const me = (e, s, t, o) => z({
608
652
  }
609
653
  });
610
654
  return t;
611
- }, N = (e, s = {}) => {
612
- const t = Symbol(), o = Symbol(), u = Symbol(), r = be(
655
+ }, R = (e, i = {}) => {
656
+ const t = Symbol(), o = Symbol(), u = Symbol(), r = ye(
613
657
  t,
614
658
  o
615
- ), l = me(
659
+ ), s = me(
616
660
  t,
617
661
  o,
618
662
  u,
619
- s
620
- ), a = ye(t, l), {
663
+ i
664
+ ), n = be(t, s), {
621
665
  VvForm: f,
622
- errors: n,
666
+ errors: a,
623
667
  status: c,
624
- invalid: h,
668
+ invalid: b,
669
+ readonly: g,
625
670
  formData: V,
626
- validate: m,
627
- submit: v,
628
- ignoreUpdates: b,
671
+ validate: v,
672
+ submit: h,
673
+ ignoreUpdates: m,
629
674
  stopUpdatesWatch: y
630
- } = he(e, t, s, a);
675
+ } = he(e, t, i, n);
631
676
  return {
632
677
  VvForm: f,
633
678
  VvFormWrapper: r,
634
- VvFormField: l,
635
- VvFormTemplate: a,
679
+ VvFormField: s,
680
+ VvFormTemplate: n,
636
681
  formInjectionKey: t,
637
682
  formWrapperInjectionKey: o,
638
683
  formFieldInjectionKey: u,
639
- errors: n,
684
+ errors: a,
640
685
  status: c,
641
- invalid: h,
686
+ invalid: b,
687
+ readonly: g,
642
688
  formData: V,
643
- validate: m,
644
- submit: v,
645
- ignoreUpdates: b,
689
+ validate: v,
690
+ submit: h,
691
+ ignoreUpdates: m,
646
692
  stopUpdatesWatch: y
647
693
  };
648
- }, T = Symbol(), xe = (e) => {
649
- let s = {};
650
- return e.schema && (s = N(e.schema, e)), {
651
- ...s,
694
+ }, D = Symbol(), ke = (e) => {
695
+ let i = {};
696
+ return e.schema && (i = R(e.schema, e)), {
697
+ ...i,
652
698
  install(t, { global: o = !1 } = {}) {
653
- t.provide(T, e), o && (t.config.globalProperties.$vvForm = e, s != null && s.VvForm && t.component("VvForm", s.VvForm), s != null && s.VvFormWrapper && t.component("VvFormWrapper", s.VvFormWrapper), s != null && s.VvFormField && t.component("VvFormField", s.VvFormField), s != null && s.VvFormTemplate && t.component("VvFormTemplate", s.VvFormTemplate));
699
+ t.provide(D, e), o && (t.config.globalProperties.$vvForm = e, i != null && i.VvForm && t.component("VvForm", i.VvForm), i != null && i.VvFormWrapper && t.component("VvFormWrapper", i.VvFormWrapper), i != null && i.VvFormField && t.component("VvFormField", i.VvFormField), i != null && i.VvFormTemplate && t.component("VvFormTemplate", i.VvFormTemplate));
654
700
  }
655
701
  };
656
- }, ke = (e, s = {}) => te() ? N(
702
+ }, we = (e, i = {}) => te() ? R(
657
703
  e,
658
704
  {
659
- ...U(T, {}),
660
- ...s
705
+ ...B(D, {}),
706
+ ...i
661
707
  }
662
- ) : N(e, s), we = (e, s = {}) => N(e, s);
708
+ ) : R(e, i), Oe = (e, i = {}) => R(e, i);
663
709
  export {
664
710
  d as FormFieldType,
665
- xe as createForm,
666
- J as defaultObjectBySchema,
667
- we as formFactory,
668
- T as pluginInjectionKey,
669
- ke as useForm
711
+ ke as createForm,
712
+ K as defaultObjectBySchema,
713
+ Oe as formFactory,
714
+ D as pluginInjectionKey,
715
+ we as useForm
670
716
  };