@foormjs/vue 0.2.1 → 0.2.2

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.js CHANGED
@@ -1,107 +1,120 @@
1
- var J = Object.defineProperty;
2
- var Z = (n, t, o) => t in n ? J(n, t, { enumerable: !0, configurable: !0, writable: !0, value: o }) : n[t] = o;
3
- var R = (n, t, o) => Z(n, typeof t != "symbol" ? t + "" : t, o);
4
- import { defineComponent as j, useModel as ee, inject as Q, ref as N, computed as v, watch as te, onUnmounted as oe, getCurrentInstance as X, renderSlot as E, unref as w, mergeModels as ne, provide as le, openBlock as d, createElementBlock as h, withModifiers as re, nextTick as ae, createBlock as O, withCtx as G, toDisplayString as m, createCommentVNode as T, Fragment as I, renderList as H, mergeProps as L, resolveDynamicComponent as Y, withDirectives as q, normalizeClass as M, createElementVNode as _, vModelDynamic as se, vShow as U, vModelSelect as ue, vModelRadio as ie, createTextVNode as K, vModelCheckbox as ce, reactive as de } from "vue";
5
- function C(n, t) {
6
- return typeof n == "function" ? n(t) : n;
1
+ var re = Object.defineProperty;
2
+ var se = (o, e, t) => e in o ? re(o, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : o[e] = t;
3
+ var Y = (o, e, t) => se(o, typeof e != "symbol" ? e + "" : e, t);
4
+ import { defineComponent as I, useModel as ae, inject as te, ref as q, computed as _, watch as oe, onUnmounted as le, getCurrentInstance as Q, renderSlot as w, unref as x, mergeModels as ie, provide as ue, openBlock as y, createElementBlock as b, withModifiers as ce, nextTick as pe, createBlock as U, withCtx as K, toDisplayString as g, createCommentVNode as P, Fragment as H, renderList as R, mergeProps as L, resolveDynamicComponent as J, withDirectives as T, normalizeClass as O, createElementVNode as V, vModelDynamic as de, vShow as N, vModelSelect as me, vModelRadio as fe, createTextVNode as Z, vModelCheckbox as he, reactive as ye } from "vue";
5
+ function M(o, e) {
6
+ return typeof o == "function" ? o(e) : o;
7
7
  }
8
- const me = /* @__PURE__ */ new Set(["action", "paragraph"]);
9
- function pe(n) {
10
- var t;
11
- const o = {};
12
- for (const l of n)
13
- me.has(l.type) || (o[l.field] = (t = l.value) !== null && t !== void 0 ? t : void 0);
14
- return o;
8
+ const ge = /* @__PURE__ */ new Set(["action", "paragraph"]);
9
+ function ve(o) {
10
+ var e;
11
+ const t = {};
12
+ for (const r of o)
13
+ if (!ge.has(r.type)) {
14
+ const s = {
15
+ v: void 0,
16
+ data: t,
17
+ context: {},
18
+ entry: {
19
+ field: r.field,
20
+ type: r.type,
21
+ component: r.component,
22
+ name: r.name || r.field
23
+ }
24
+ };
25
+ t[r.field] = (e = M(r.value, s)) !== null && e !== void 0 ? e : void 0;
26
+ }
27
+ return t;
15
28
  }
16
- function ve(n, t) {
17
- return n.fields.some((o) => o.altAction === t);
29
+ function be(o, e) {
30
+ return o.fields.some((t) => t.altAction === e);
18
31
  }
19
- function fe(n, t) {
20
- if (!n)
32
+ function xe(o, e) {
33
+ if (!o)
21
34
  return;
22
- const o = {};
23
- for (const [l, a] of Object.entries(n))
24
- o[l] = C(a, t);
25
- return o;
35
+ const t = {};
36
+ for (const [r, s] of Object.entries(o))
37
+ t[r] = M(s, e);
38
+ return t;
26
39
  }
27
- const be = /* @__PURE__ */ j({
40
+ const ke = /* @__PURE__ */ I({
28
41
  __name: "VuilessField",
29
- props: /* @__PURE__ */ ne({
42
+ props: /* @__PURE__ */ ie({
30
43
  rules: {}
31
44
  }, {
32
45
  modelValue: {},
33
46
  modelModifiers: {}
34
47
  }),
35
48
  emits: ["update:modelValue"],
36
- setup(n) {
37
- const t = n, o = ee(n, "modelValue"), l = Q("vuiless"), a = N(), s = N(!1), f = N(!1), p = v(() => {
38
- var r;
39
- if ((r = l == null ? void 0 : l.value) != null && r.firstValidation)
40
- switch (l.value.firstValidation) {
49
+ setup(o) {
50
+ const e = o, t = ae(o, "modelValue"), r = te("vuiless"), s = q(), a = q(!1), l = q(!1), c = _(() => {
51
+ var u;
52
+ if ((u = r == null ? void 0 : r.value) != null && u.firstValidation)
53
+ switch (r.value.firstValidation) {
41
54
  case "on-change":
42
- return l.value.firstSubmitHappened || s.value;
55
+ return r.value.firstSubmitHappened || a.value;
43
56
  case "touched-on-blur":
44
- return l.value.firstSubmitHappened || f.value && s.value;
57
+ return r.value.firstSubmitHappened || l.value && a.value;
45
58
  case "on-blur":
46
- return l.value.firstSubmitHappened || f.value;
59
+ return r.value.firstSubmitHappened || l.value;
47
60
  case "on-submit":
48
- return l.value.firstSubmitHappened;
61
+ return r.value.firstSubmitHappened;
49
62
  case "none":
50
63
  return !1;
51
64
  }
52
65
  return !1;
53
- }), S = v(() => {
54
- if (p.value || a.value)
55
- return V();
66
+ }), m = _(() => {
67
+ if (c.value || s.value)
68
+ return p();
56
69
  });
57
- te([o], () => {
58
- a.value = void 0, s.value = !0;
59
- }), oe(() => {
60
- var r;
61
- (r = l == null ? void 0 : l.value) == null || r.unregister(X());
62
- }), l != null && l.value && l.value.register(X(), {
63
- validate: () => (a.value = V(), a.value || !0),
70
+ oe([t], () => {
71
+ s.value = void 0, a.value = !0;
72
+ }), le(() => {
73
+ var u;
74
+ (u = r == null ? void 0 : r.value) == null || u.unregister(Q());
75
+ }), r != null && r.value && r.value.register(Q(), {
76
+ validate: () => (s.value = p(), s.value || !0),
64
77
  clearErrors: () => {
65
- s.value = !1, f.value = !1, a.value = void 0;
78
+ a.value = !1, l.value = !1, s.value = void 0;
66
79
  },
67
80
  reset: () => {
68
- o.value = "";
81
+ t.value = "";
69
82
  }
70
83
  });
71
- function V() {
72
- var r, u, k;
73
- if ((r = t.rules) != null && r.length)
74
- for (const b of t.rules) {
75
- const x = b(
76
- o.value,
77
- (u = l == null ? void 0 : l.value) == null ? void 0 : u.formData,
78
- (k = l == null ? void 0 : l.value) == null ? void 0 : k.formContext
84
+ function p() {
85
+ var u, d, A;
86
+ if ((u = e.rules) != null && u.length)
87
+ for (const v of e.rules) {
88
+ const E = v(
89
+ t.value,
90
+ (d = r == null ? void 0 : r.value) == null ? void 0 : d.formData,
91
+ (A = r == null ? void 0 : r.value) == null ? void 0 : A.formContext
79
92
  );
80
- if (x !== !0)
81
- return x || "Wrong value";
93
+ if (E !== !0)
94
+ return E || "Wrong value";
82
95
  }
83
96
  }
84
- function i() {
85
- f.value = !0;
97
+ function f() {
98
+ l.value = !0;
86
99
  }
87
- const y = {
88
- v: v({
89
- get: () => o.value,
90
- set: (r) => o.value = r
100
+ const h = {
101
+ v: _({
102
+ get: () => t.value,
103
+ set: (u) => t.value = u
91
104
  })
92
105
  };
93
- return (r, u) => {
94
- var k, b;
95
- return E(r.$slots, "default", {
96
- onBlur: i,
97
- error: S.value,
98
- formData: (k = w(l)) == null ? void 0 : k.formData,
99
- formContext: (b = w(l)) == null ? void 0 : b.formContext,
100
- model: y.v
106
+ return (u, d) => {
107
+ var A, v;
108
+ return w(u.$slots, "default", {
109
+ onBlur: f,
110
+ error: m.value,
111
+ formData: (A = x(r)) == null ? void 0 : A.formData,
112
+ formContext: (v = x(r)) == null ? void 0 : v.formContext,
113
+ model: h.v
101
114
  });
102
115
  };
103
116
  }
104
- }), he = /* @__PURE__ */ j({
117
+ }), Ee = /* @__PURE__ */ I({
105
118
  __name: "VuilessForm",
106
119
  props: {
107
120
  formData: {},
@@ -109,46 +122,46 @@ const be = /* @__PURE__ */ j({
109
122
  firstValidation: { default: "on-change" }
110
123
  },
111
124
  emits: ["submit"],
112
- setup(n, { emit: t }) {
113
- const o = n, l = t, a = /* @__PURE__ */ new Map(), s = N(!1), f = v(() => ({
114
- firstSubmitHappened: s.value,
115
- firstValidation: o.firstValidation,
116
- register: (i, y) => {
117
- a.set(i, y);
125
+ setup(o, { emit: e }) {
126
+ const t = o, r = e, s = /* @__PURE__ */ new Map(), a = q(!1), l = _(() => ({
127
+ firstSubmitHappened: a.value,
128
+ firstValidation: t.firstValidation,
129
+ register: (f, h) => {
130
+ s.set(f, h);
118
131
  },
119
- unregister: (i) => a.delete(i),
120
- formData: o.formData,
121
- formContext: o.formContext
132
+ unregister: (f) => s.delete(f),
133
+ formData: t.formData,
134
+ formContext: t.formContext
122
135
  }));
123
- le("vuiless", f);
124
- function p() {
125
- s.value = !1;
126
- for (const { clearErrors: i } of a.values())
127
- i();
136
+ ue("vuiless", l);
137
+ function c() {
138
+ a.value = !1;
139
+ for (const { clearErrors: f } of s.values())
140
+ f();
128
141
  }
129
- async function S() {
130
- for (const { reset: i } of a.values())
131
- i();
132
- await ae(), p();
142
+ async function m() {
143
+ for (const { reset: f } of s.values())
144
+ f();
145
+ await pe(), c();
133
146
  }
134
- function V() {
135
- s.value = !0;
136
- let i = !1;
137
- if (o.firstValidation !== "none")
138
- for (const { validate: y } of a.values())
139
- y() !== !0 && (i = !0);
140
- i || l("submit", o.formData);
147
+ function p() {
148
+ a.value = !0;
149
+ let f = !1;
150
+ if (t.firstValidation !== "none")
151
+ for (const { validate: h } of s.values())
152
+ h() !== !0 && (f = !0);
153
+ f || r("submit", t.formData);
141
154
  }
142
- return (i, y) => (d(), h("form", {
143
- onSubmit: re(V, ["prevent"])
155
+ return (f, h) => (y(), b("form", {
156
+ onSubmit: ce(p, ["prevent"])
144
157
  }, [
145
- E(i.$slots, "default", {
146
- clearErrors: p,
147
- reset: S
158
+ w(f.$slots, "default", {
159
+ clearErrors: c,
160
+ reset: m
148
161
  })
149
162
  ], 32));
150
163
  }
151
- }), ye = /* @__PURE__ */ j({
164
+ }), _e = /* @__PURE__ */ I({
152
165
  __name: "oo-field",
153
166
  props: {
154
167
  field: {},
@@ -165,11 +178,12 @@ const be = /* @__PURE__ */ j({
165
178
  optional: { type: [Boolean, Function] },
166
179
  disabled: { type: [Boolean, Function] },
167
180
  hidden: { type: [Boolean, Function] },
181
+ readonly: { type: [Boolean, Function] },
168
182
  classes: { type: [String, Object, Function] },
169
183
  styles: { type: [String, Object, Function] },
170
184
  options: { type: [Array, Function] },
171
185
  attrs: {},
172
- value: {},
186
+ value: { type: Function },
173
187
  validators: {},
174
188
  maxLength: {},
175
189
  minLength: {},
@@ -177,90 +191,112 @@ const be = /* @__PURE__ */ j({
177
191
  max: {},
178
192
  error: {}
179
193
  },
180
- setup(n) {
181
- const t = n, o = Q(
194
+ setup(o) {
195
+ const e = o, t = te(
182
196
  "vuiless"
183
- ), l = v(() => ({
184
- v: o.value.formData[t.field],
185
- data: o.value.formData,
186
- context: o.value.formContext ?? {},
197
+ );
198
+ function r(i, k, S) {
199
+ return typeof i == "function" ? _(() => i(k.value)) : i ?? S;
200
+ }
201
+ const s = (i) => typeof i == "object" && i !== null && "value" in i ? i.value : i, a = _(() => ({
202
+ v: t.value.formData[e.field],
203
+ data: t.value.formData,
204
+ context: t.value.formContext ?? {},
187
205
  entry: void 0
188
- })), a = v(() => C(t.optional, l.value)), s = v(() => C(t.disabled, l.value)), f = v(() => C(t.hidden, l.value)), p = v(() => ({
189
- ...l.value,
206
+ })), l = r(e.optional, a, !1), c = r(e.disabled, a, !1), m = r(e.hidden, a, !1), p = r(e.readonly, a, !1), f = _(() => !s(l)), h = _(() => ({
207
+ v: t.value.formData[e.field],
208
+ data: t.value.formData,
209
+ context: t.value.formContext ?? {},
190
210
  entry: {
191
- field: t.field,
192
- type: t.type,
193
- component: t.component,
194
- name: t.name || t.field,
195
- disabled: s.value,
196
- optional: a.value,
197
- hidden: f.value
211
+ field: e.field,
212
+ type: e.type,
213
+ component: e.component,
214
+ name: e.name || e.field,
215
+ optional: s(l),
216
+ disabled: s(c),
217
+ hidden: s(m),
218
+ readonly: s(p)
198
219
  }
199
- })), S = v(() => C(t.label, p.value)), V = v(() => C(t.description, p.value)), i = v(() => C(t.hint, p.value)), y = v(() => C(t.placeholder, p.value)), r = v(() => C(t.options, p.value)), u = v(() => {
200
- const A = C(t.classes, p.value);
201
- return typeof A == "string" ? {
202
- [A]: !0,
203
- disabled: s.value,
204
- required: !a.value
220
+ })), u = r(e.label, h, void 0), d = r(e.description, h, void 0), A = r(e.hint, h, void 0), v = r(e.placeholder, h, void 0), E = r(e.options, h, void 0), C = r(e.styles, h, void 0), n = _(() => {
221
+ const i = typeof e.classes == "function" ? e.classes(h.value) : e.classes;
222
+ return typeof i == "string" ? {
223
+ [i]: !0,
224
+ disabled: s(c),
225
+ required: !s(l)
205
226
  } : {
206
- ...A,
207
- disabled: s.value,
208
- required: !a.value
227
+ ...i,
228
+ disabled: s(c),
229
+ required: !s(l)
209
230
  };
210
- }), k = v(
211
- () => C(t.styles, p.value)
212
- ), b = v(() => fe(t.attrs, p.value)), x = v(() => t.validators.map(
213
- (A) => (e, F, c) => A({
214
- v: e,
215
- data: F,
216
- context: c ?? {},
217
- entry: p.value.entry
218
- })
219
- ));
220
- return (A, e) => (d(), O(w(be), {
221
- modelValue: w(o).formData[t.field],
222
- "onUpdate:modelValue": e[0] || (e[0] = (F) => w(o).formData[t.field] = F),
223
- rules: x.value
231
+ });
232
+ function F(i, k) {
233
+ return {
234
+ ...n.value,
235
+ error: !!i || !!k
236
+ };
237
+ }
238
+ const D = _(() => xe(e.attrs, h.value));
239
+ if (typeof e.value == "function") {
240
+ const i = _(() => {
241
+ if (s(p))
242
+ return e.value(h.value);
243
+ });
244
+ oe(
245
+ i,
246
+ (k) => {
247
+ k !== void 0 && s(p) && (t.value.formData[e.field] = k);
248
+ },
249
+ { immediate: !0 }
250
+ );
251
+ }
252
+ const j = e.validators.map((i) => (k, S, X) => i({
253
+ v: k,
254
+ data: S,
255
+ context: X ?? {},
256
+ entry: h.value.entry
257
+ }));
258
+ return (i, k) => (y(), U(x(ke), {
259
+ modelValue: x(t).formData[e.field],
260
+ "onUpdate:modelValue": k[0] || (k[0] = (S) => x(t).formData[e.field] = S),
261
+ rules: x(j)
224
262
  }, {
225
- default: G((F) => [
226
- E(A.$slots, "default", {
227
- onBlur: F.onBlur,
228
- error: n.error || F.error,
229
- model: F.model,
230
- formData: w(o).formData,
231
- formContext: w(o).formContext,
232
- label: S.value,
233
- description: V.value,
234
- hint: i.value,
235
- placeholder: y.value,
236
- classes: {
237
- ...u.value,
238
- error: !!n.error || !!F.error
239
- },
240
- styles: k.value,
241
- optional: a.value,
242
- disabled: s.value,
243
- hidden: f.value,
244
- type: n.type,
245
- altAction: n.altAction,
246
- component: n.component,
247
- vName: n.name,
248
- field: n.field,
249
- options: r.value,
250
- maxLength: n.maxLength,
251
- required: !a.value,
252
- autocomplete: n.autocomplete,
253
- attrs: b.value
263
+ default: K((S) => [
264
+ w(i.$slots, "default", {
265
+ onBlur: S.onBlur,
266
+ error: o.error || S.error,
267
+ model: S.model,
268
+ formData: x(t).formData,
269
+ formContext: x(t).formContext,
270
+ label: x(u),
271
+ description: x(d),
272
+ hint: x(A),
273
+ placeholder: x(v),
274
+ classes: F(o.error, S.error),
275
+ styles: x(C),
276
+ optional: x(l),
277
+ disabled: x(c),
278
+ hidden: x(m),
279
+ readonly: x(p),
280
+ type: o.type,
281
+ altAction: o.altAction,
282
+ component: o.component,
283
+ vName: o.name,
284
+ field: o.field,
285
+ options: x(E),
286
+ maxLength: o.maxLength,
287
+ required: f.value,
288
+ autocomplete: o.autocomplete,
289
+ attrs: D.value
254
290
  })
255
291
  ]),
256
292
  _: 3
257
293
  }, 8, ["modelValue", "rules"]));
258
294
  }
259
- }), ge = { key: 0 }, xe = { key: 1 }, _e = { key: 0 }, Ve = ["onUpdate:modelValue", "onBlur", "placeholder", "autocomplete", "name", "type", "disabled"], ke = { class: "oo-error-slot" }, Ce = { key: 4 }, Se = { key: 0 }, Ae = ["onUpdate:modelValue", "onBlur", "name", "disabled"], Fe = {
295
+ }), Ve = { key: 0 }, $e = { key: 1 }, Ae = { key: 0 }, Se = ["onUpdate:modelValue", "onBlur", "placeholder", "autocomplete", "name", "type", "disabled", "readonly"], we = { class: "oo-error-slot" }, Ce = { key: 4 }, Le = { key: 0 }, Te = ["onUpdate:modelValue", "onBlur", "name", "disabled", "readonly"], Be = {
260
296
  key: 0,
261
297
  value: "",
262
298
  disabled: ""
263
- }, Be = ["value"], De = { class: "oo-error-slot" }, Ee = { class: "oo-field-label" }, Le = { key: 0 }, qe = { class: "oo-radio-group" }, we = ["value", "onUpdate:modelValue", "onBlur", "name", "disabled"], Te = { class: "oo-error-slot" }, $e = ["onUpdate:modelValue", "onBlur", "name", "disabled"], Me = { key: 0 }, Oe = { class: "oo-error-slot" }, Ne = ["onClick"], Ue = { key: 9 }, je = ["disabled"], We = /* @__PURE__ */ j({
299
+ }, Fe = ["value"], De = { class: "oo-error-slot" }, je = { class: "oo-field-label" }, Pe = { key: 0 }, Oe = { class: "oo-radio-group" }, Ue = ["value", "onUpdate:modelValue", "onBlur", "name", "disabled", "readonly"], qe = { class: "oo-error-slot" }, Me = ["onUpdate:modelValue", "onBlur", "name", "disabled", "readonly"], Ne = { key: 0 }, Ie = { class: "oo-error-slot" }, ze = ["onClick"], He = { key: 9 }, Re = ["disabled"], ut = /* @__PURE__ */ I({
264
300
  __name: "oo-form",
265
301
  props: {
266
302
  form: {},
@@ -272,240 +308,244 @@ const be = /* @__PURE__ */ j({
272
308
  errors: {}
273
309
  },
274
310
  emits: ["submit", "action", "unsupported-action"],
275
- setup(n, { emit: t }) {
276
- const o = n, l = N({}), a = v(() => o.formData || l.value), s = v(() => ({
311
+ setup(o, { emit: e }) {
312
+ const t = o, r = q({}), s = _(() => t.formData || r.value), a = _(() => ({
277
313
  v: void 0,
278
- data: a.value,
279
- context: o.formContext ?? {},
314
+ data: s.value,
315
+ context: t.formContext ?? {},
280
316
  entry: void 0
281
- })), f = v(() => C(o.form.title, s.value)), p = v(() => C(o.form.submit.text, s.value)), S = v(() => C(o.form.submit.disabled, s.value));
282
- function V(u) {
283
- ve(o.form, u) ? i("action", u, a.value) : i("unsupported-action", u, a.value);
317
+ })), l = _(() => M(t.form.title, a.value)), c = _(() => M(t.form.submit.text, a.value)), m = _(() => M(t.form.submit.disabled, a.value));
318
+ function p(d) {
319
+ be(t.form, d) ? f("action", d, s.value) : f("unsupported-action", d, s.value);
284
320
  }
285
- const i = t;
286
- function y(u) {
287
- return typeof u == "string" ? u : u.key;
321
+ const f = e;
322
+ function h(d) {
323
+ return typeof d == "string" ? d : d.key;
288
324
  }
289
- function r(u) {
290
- return typeof u == "string" ? u : u.label;
325
+ function u(d) {
326
+ return typeof d == "string" ? d : d.label;
291
327
  }
292
- return (u, k) => (d(), O(w(he), {
293
- "first-validation": n.firstValidation,
294
- onSubmit: k[0] || (k[0] = (b) => i("submit", b)),
295
- "form-data": a.value,
296
- "form-context": n.formContext
328
+ return (d, A) => (y(), U(x(Ee), {
329
+ "first-validation": o.firstValidation,
330
+ onSubmit: A[0] || (A[0] = (v) => f("submit", v)),
331
+ "form-data": s.value,
332
+ "form-context": o.formContext
297
333
  }, {
298
- default: G((b) => [
299
- E(u.$slots, "form.header", {
300
- clearErrors: b.clearErrors,
301
- reset: b.reset,
302
- title: f.value,
303
- formContext: n.formContext,
304
- disabled: S.value
334
+ default: K((v) => [
335
+ w(d.$slots, "form.header", {
336
+ clearErrors: v.clearErrors,
337
+ reset: v.reset,
338
+ title: l.value,
339
+ formContext: o.formContext,
340
+ disabled: m.value
305
341
  }, () => [
306
- f.value ? (d(), h("h2", ge, m(f.value), 1)) : T("", !0)
342
+ l.value ? (y(), b("h2", Ve, g(l.value), 1)) : P("", !0)
307
343
  ]),
308
- E(u.$slots, "form.before", {
309
- clearErrors: b.clearErrors,
310
- reset: b.reset
344
+ w(d.$slots, "form.before", {
345
+ clearErrors: v.clearErrors,
346
+ reset: v.reset
311
347
  }),
312
- (d(!0), h(I, null, H(o.form.fields, (x) => {
313
- var A;
314
- return d(), O(ye, L({
315
- key: x.field
316
- }, { ref_for: !0 }, x, {
317
- error: (A = n.errors) == null ? void 0 : A[x.field]
348
+ (y(!0), b(H, null, R(t.form.fields, (E) => {
349
+ var C;
350
+ return y(), U(_e, L({
351
+ key: E.field
352
+ }, { ref_for: !0 }, E, {
353
+ error: (C = o.errors) == null ? void 0 : C[E.field]
318
354
  }), {
319
- default: G((e) => [
320
- E(u.$slots, `field:${e.type}`, L({ ref_for: !0 }, e), () => {
321
- var F, c, B;
355
+ default: K((n) => [
356
+ w(d.$slots, `field:${n.type}`, L({ ref_for: !0 }, n), () => {
357
+ var F, D, j;
322
358
  return [
323
- x.component && ((F = o.components) != null && F[x.component]) ? (d(), O(Y(o.components[x.component]), L({
359
+ E.component && ((F = t.components) != null && F[E.component]) ? (y(), U(J(t.components[E.component]), L({
324
360
  key: 0,
325
- "on-blur": e.onBlur,
326
- error: e.error,
327
- model: e.model,
328
- "form-data": e.formData,
329
- "form-context": e.formContext,
330
- label: e.label,
331
- description: e.description,
332
- hint: e.hint,
333
- placeholder: e.placeholder,
334
- class: e.classes,
335
- style: e.styles,
336
- optional: e.optional,
337
- required: !e.required,
338
- disabled: e.disabled,
339
- hidden: e.hidden,
340
- type: e.type,
341
- "alt-action": e.altAction,
342
- name: e.vName,
343
- field: e,
344
- options: e.options,
345
- "max-length": e.maxLength,
346
- autocomplete: e.autocomplete,
347
- onAction: V
348
- }, { ref_for: !0 }, e.attrs, {
349
- modelValue: e.model.value,
350
- "onUpdate:modelValue": (g) => e.model.value = g
351
- }), null, 16, ["on-blur", "error", "model", "form-data", "form-context", "label", "description", "hint", "placeholder", "class", "style", "optional", "required", "disabled", "hidden", "type", "alt-action", "name", "field", "options", "max-length", "autocomplete", "modelValue", "onUpdate:modelValue"])) : x.component && !((c = o.components) != null && c[x.component]) ? (d(), h("div", xe, " [" + m(e.label) + '] Component "' + m(e.component) + '" not supplied ', 1)) : (B = o.types) != null && B[x.type] ? (d(), O(Y(o.types[x.type]), L({
361
+ "on-blur": n.onBlur,
362
+ error: n.error,
363
+ model: n.model,
364
+ "form-data": n.formData,
365
+ "form-context": n.formContext,
366
+ label: n.label,
367
+ description: n.description,
368
+ hint: n.hint,
369
+ placeholder: n.placeholder,
370
+ class: n.classes,
371
+ style: n.styles,
372
+ optional: n.optional,
373
+ required: !n.required,
374
+ disabled: n.disabled,
375
+ hidden: n.hidden,
376
+ type: n.type,
377
+ "alt-action": n.altAction,
378
+ name: n.vName,
379
+ field: n,
380
+ options: n.options,
381
+ "max-length": n.maxLength,
382
+ autocomplete: n.autocomplete,
383
+ onAction: p
384
+ }, { ref_for: !0 }, n.attrs, {
385
+ modelValue: n.model.value,
386
+ "onUpdate:modelValue": (i) => n.model.value = i
387
+ }), null, 16, ["on-blur", "error", "model", "form-data", "form-context", "label", "description", "hint", "placeholder", "class", "style", "optional", "required", "disabled", "hidden", "type", "alt-action", "name", "field", "options", "max-length", "autocomplete", "modelValue", "onUpdate:modelValue"])) : E.component && !((D = t.components) != null && D[E.component]) ? (y(), b("div", $e, " [" + g(n.label) + '] Component "' + g(n.component) + '" not supplied ', 1)) : (j = t.types) != null && j[E.type] ? (y(), U(J(t.types[E.type]), L({
352
388
  key: 2,
353
- "on-blur": e.onBlur,
354
- error: e.error,
355
- model: e.model,
356
- "form-data": e.formData,
357
- "form-context": e.formContext,
358
- label: e.label,
359
- description: e.description,
360
- hint: e.hint,
361
- placeholder: e.placeholder,
362
- class: e.classes,
363
- style: e.styles,
364
- optional: e.optional,
365
- required: !e.required,
366
- disabled: e.disabled,
367
- hidden: e.hidden,
368
- type: e.type,
369
- "alt-action": e.altAction,
370
- name: e.vName,
371
- field: e,
372
- options: e.options,
373
- "max-length": e.maxLength,
374
- autocomplete: e.autocomplete,
375
- onAction: V
376
- }, { ref_for: !0 }, e.attrs, {
377
- modelValue: e.model.value,
378
- "onUpdate:modelValue": (g) => e.model.value = g
379
- }), null, 16, ["on-blur", "error", "model", "form-data", "form-context", "label", "description", "hint", "placeholder", "class", "style", "optional", "required", "disabled", "hidden", "type", "alt-action", "name", "field", "options", "max-length", "autocomplete", "modelValue", "onUpdate:modelValue"])) : ["text", "password", "number"].includes(e.type) ? q((d(), h("div", {
389
+ "on-blur": n.onBlur,
390
+ error: n.error,
391
+ model: n.model,
392
+ "form-data": n.formData,
393
+ "form-context": n.formContext,
394
+ label: n.label,
395
+ description: n.description,
396
+ hint: n.hint,
397
+ placeholder: n.placeholder,
398
+ class: n.classes,
399
+ style: n.styles,
400
+ optional: n.optional,
401
+ required: !n.required,
402
+ disabled: n.disabled,
403
+ hidden: n.hidden,
404
+ type: n.type,
405
+ "alt-action": n.altAction,
406
+ name: n.vName,
407
+ field: n,
408
+ options: n.options,
409
+ "max-length": n.maxLength,
410
+ autocomplete: n.autocomplete,
411
+ onAction: p
412
+ }, { ref_for: !0 }, n.attrs, {
413
+ modelValue: n.model.value,
414
+ "onUpdate:modelValue": (i) => n.model.value = i
415
+ }), null, 16, ["on-blur", "error", "model", "form-data", "form-context", "label", "description", "hint", "placeholder", "class", "style", "optional", "required", "disabled", "hidden", "type", "alt-action", "name", "field", "options", "max-length", "autocomplete", "modelValue", "onUpdate:modelValue"])) : ["text", "password", "number"].includes(n.type) ? T((y(), b("div", {
380
416
  key: 3,
381
- class: M(["oo-default-field", e.classes])
417
+ class: O(["oo-default-field", n.classes])
382
418
  }, [
383
- _("label", null, m(e.label), 1),
384
- e.description ? (d(), h("span", _e, m(e.description), 1)) : T("", !0),
385
- q(_("input", L({
386
- "onUpdate:modelValue": (g) => e.model.value = g,
387
- onBlur: e.onBlur,
388
- placeholder: e.placeholder,
389
- autocomplete: e.autocomplete,
390
- name: e.vName,
391
- type: e.type,
392
- disabled: e.disabled
393
- }, { ref_for: !0 }, e.attrs), null, 16, Ve), [
394
- [se, e.model.value]
419
+ V("label", null, g(n.label), 1),
420
+ n.description ? (y(), b("span", Ae, g(n.description), 1)) : P("", !0),
421
+ T(V("input", L({
422
+ "onUpdate:modelValue": (i) => n.model.value = i,
423
+ onBlur: n.onBlur,
424
+ placeholder: n.placeholder,
425
+ autocomplete: n.autocomplete,
426
+ name: n.vName,
427
+ type: n.type,
428
+ disabled: n.disabled,
429
+ readonly: n.readonly
430
+ }, { ref_for: !0 }, n.attrs), null, 16, Se), [
431
+ [de, n.model.value]
395
432
  ]),
396
- _("div", ke, m(e.error || e.hint), 1)
433
+ V("div", we, g(n.error || n.hint), 1)
397
434
  ], 2)), [
398
- [U, !e.hidden]
399
- ]) : e.type === "paragraph" ? (d(), h("p", Ce, m(e.description), 1)) : e.type === "select" ? q((d(), h("div", {
435
+ [N, !n.hidden]
436
+ ]) : n.type === "paragraph" ? (y(), b("p", Ce, g(n.description), 1)) : n.type === "select" ? T((y(), b("div", {
400
437
  key: 5,
401
- class: M(["oo-default-field", e.classes])
438
+ class: O(["oo-default-field", n.classes])
402
439
  }, [
403
- _("label", null, m(e.label), 1),
404
- e.description ? (d(), h("span", Se, m(e.description), 1)) : T("", !0),
405
- q(_("select", L({
406
- "onUpdate:modelValue": (g) => e.model.value = g,
407
- onBlur: e.onBlur,
408
- name: e.vName,
409
- disabled: e.disabled
410
- }, { ref_for: !0 }, e.attrs), [
411
- e.placeholder ? (d(), h("option", Fe, m(e.placeholder), 1)) : T("", !0),
412
- (d(!0), h(I, null, H(e.options, (g) => (d(), h("option", {
413
- key: y(g),
414
- value: y(g)
415
- }, m(r(g)), 9, Be))), 128))
416
- ], 16, Ae), [
417
- [ue, e.model.value]
440
+ V("label", null, g(n.label), 1),
441
+ n.description ? (y(), b("span", Le, g(n.description), 1)) : P("", !0),
442
+ T(V("select", L({
443
+ "onUpdate:modelValue": (i) => n.model.value = i,
444
+ onBlur: n.onBlur,
445
+ name: n.vName,
446
+ disabled: n.disabled,
447
+ readonly: n.readonly
448
+ }, { ref_for: !0 }, n.attrs), [
449
+ n.placeholder ? (y(), b("option", Be, g(n.placeholder), 1)) : P("", !0),
450
+ (y(!0), b(H, null, R(n.options, (i) => (y(), b("option", {
451
+ key: h(i),
452
+ value: h(i)
453
+ }, g(u(i)), 9, Fe))), 128))
454
+ ], 16, Te), [
455
+ [me, n.model.value]
418
456
  ]),
419
- _("div", De, m(e.error || e.hint), 1)
457
+ V("div", De, g(n.error || n.hint), 1)
420
458
  ], 2)), [
421
- [U, !e.hidden]
422
- ]) : e.type === "radio" ? q((d(), h("div", {
459
+ [N, !n.hidden]
460
+ ]) : n.type === "radio" ? T((y(), b("div", {
423
461
  key: 6,
424
- class: M(["oo-default-field oo-radio-field", e.classes])
462
+ class: O(["oo-default-field oo-radio-field", n.classes])
425
463
  }, [
426
- _("span", Ee, m(e.label), 1),
427
- e.description ? (d(), h("span", Le, m(e.description), 1)) : T("", !0),
428
- _("div", qe, [
429
- (d(!0), h(I, null, H(e.options, (g) => (d(), h("label", {
430
- key: y(g)
464
+ V("span", je, g(n.label), 1),
465
+ n.description ? (y(), b("span", Pe, g(n.description), 1)) : P("", !0),
466
+ V("div", Oe, [
467
+ (y(!0), b(H, null, R(n.options, (i) => (y(), b("label", {
468
+ key: h(i)
431
469
  }, [
432
- q(_("input", L({
470
+ T(V("input", L({
433
471
  type: "radio",
434
- value: y(g),
435
- "onUpdate:modelValue": (W) => e.model.value = W,
436
- onBlur: e.onBlur,
437
- name: e.vName,
438
- disabled: e.disabled
439
- }, { ref_for: !0 }, e.attrs), null, 16, we), [
440
- [ie, e.model.value]
472
+ value: h(i),
473
+ "onUpdate:modelValue": (k) => n.model.value = k,
474
+ onBlur: n.onBlur,
475
+ name: n.vName,
476
+ disabled: n.disabled,
477
+ readonly: n.readonly
478
+ }, { ref_for: !0 }, n.attrs), null, 16, Ue), [
479
+ [fe, n.model.value]
441
480
  ]),
442
- K(" " + m(r(g)), 1)
481
+ Z(" " + g(u(i)), 1)
443
482
  ]))), 128))
444
483
  ]),
445
- _("div", Te, m(e.error || e.hint), 1)
484
+ V("div", qe, g(n.error || n.hint), 1)
446
485
  ], 2)), [
447
- [U, !e.hidden]
448
- ]) : e.type === "checkbox" ? q((d(), h("div", {
486
+ [N, !n.hidden]
487
+ ]) : n.type === "checkbox" ? T((y(), b("div", {
449
488
  key: 7,
450
- class: M(["oo-default-field oo-checkbox-field", e.classes])
489
+ class: O(["oo-default-field oo-checkbox-field", n.classes])
451
490
  }, [
452
- _("label", null, [
453
- q(_("input", L({
491
+ V("label", null, [
492
+ T(V("input", L({
454
493
  type: "checkbox",
455
- "onUpdate:modelValue": (g) => e.model.value = g,
456
- onBlur: e.onBlur,
457
- name: e.vName,
458
- disabled: e.disabled
459
- }, { ref_for: !0 }, e.attrs), null, 16, $e), [
460
- [ce, e.model.value]
494
+ "onUpdate:modelValue": (i) => n.model.value = i,
495
+ onBlur: n.onBlur,
496
+ name: n.vName,
497
+ disabled: n.disabled,
498
+ readonly: n.readonly
499
+ }, { ref_for: !0 }, n.attrs), null, 16, Me), [
500
+ [he, n.model.value]
461
501
  ]),
462
- K(" " + m(e.label), 1)
502
+ Z(" " + g(n.label), 1)
463
503
  ]),
464
- e.description ? (d(), h("span", Me, m(e.description), 1)) : T("", !0),
465
- _("div", Oe, m(e.error || e.hint), 1)
504
+ n.description ? (y(), b("span", Ne, g(n.description), 1)) : P("", !0),
505
+ V("div", Ie, g(n.error || n.hint), 1)
466
506
  ], 2)), [
467
- [U, !e.hidden]
468
- ]) : e.type === "action" ? (d(), h("div", {
507
+ [N, !n.hidden]
508
+ ]) : n.type === "action" ? (y(), b("div", {
469
509
  key: 8,
470
- class: M(["oo-default-field oo-action-field", e.classes])
510
+ class: O(["oo-default-field oo-action-field", n.classes])
471
511
  }, [
472
- _("button", {
512
+ V("button", {
473
513
  type: "button",
474
- onClick: (g) => V(e.altAction)
475
- }, m(e.label), 9, Ne)
476
- ], 2)) : (d(), h("div", Ue, " [" + m(e.label) + '] Not supported field type "' + m(e.type) + '" ' + m(e.component), 1))
514
+ onClick: (i) => p(n.altAction)
515
+ }, g(n.label), 9, ze)
516
+ ], 2)) : (y(), b("div", He, " [" + g(n.label) + '] Not supported field type "' + g(n.type) + '" ' + g(n.component), 1))
477
517
  ];
478
518
  })
479
519
  ]),
480
520
  _: 2
481
521
  }, 1040, ["error"]);
482
522
  }), 128)),
483
- E(u.$slots, "form.after", {
484
- clearErrors: b.clearErrors,
485
- reset: b.reset,
486
- disabled: S.value,
487
- formContext: n.formContext
523
+ w(d.$slots, "form.after", {
524
+ clearErrors: v.clearErrors,
525
+ reset: v.reset,
526
+ disabled: m.value,
527
+ formContext: o.formContext
488
528
  }),
489
- E(u.$slots, "form.submit", {
490
- disabled: S.value,
491
- text: p.value,
492
- clearErrors: b.clearErrors,
493
- reset: b.reset,
494
- formContext: n.formContext
529
+ w(d.$slots, "form.submit", {
530
+ disabled: m.value,
531
+ text: c.value,
532
+ clearErrors: v.clearErrors,
533
+ reset: v.reset,
534
+ formContext: o.formContext
495
535
  }, () => [
496
- _("button", { disabled: S.value }, m(p.value), 9, je)
536
+ V("button", { disabled: m.value }, g(c.value), 9, Re)
497
537
  ]),
498
- E(u.$slots, "form.footer", {
499
- disabled: S.value,
500
- clearErrors: b.clearErrors,
501
- reset: b.reset,
502
- formContext: n.formContext
538
+ w(d.$slots, "form.footer", {
539
+ disabled: m.value,
540
+ clearErrors: v.clearErrors,
541
+ reset: v.reset,
542
+ formContext: o.formContext
503
543
  })
504
544
  ]),
505
545
  _: 3
506
546
  }, 8, ["first-validation", "form-data", "form-context"]));
507
547
  }
508
- }), Ie = {
548
+ }), Ge = {
509
549
  // Node.js Globals
510
550
  global: null,
511
551
  process: null,
@@ -592,159 +632,464 @@ const be = /* @__PURE__ */ j({
592
632
  eval: null,
593
633
  __ctx__: null
594
634
  };
595
- class He {
635
+ class Ke {
596
636
  constructor() {
597
- R(this, "cache", /* @__PURE__ */ new Map());
637
+ Y(this, "cache", /* @__PURE__ */ new Map());
598
638
  }
599
- call(t, o) {
600
- return this.getFn(t)(o);
639
+ call(e, t) {
640
+ return this.getFn(e)(t);
601
641
  }
602
- getFn(t) {
603
- let o = this.cache.get(t);
604
- return o || (o = ze(t), this.cache.set(t, o)), o;
642
+ getFn(e) {
643
+ let t = this.cache.get(e);
644
+ return t || (t = We(e), this.cache.set(e, t)), t;
605
645
  }
606
646
  }
607
- function ze(n) {
608
- const t = `with(__ctx__){
609
- ${n}
610
- }`, o = new Function("__ctx__", t);
611
- return (l) => {
612
- const a = Object.freeze(Object.assign({}, Ie, l));
613
- return o(a);
647
+ function We(o) {
648
+ const e = `with(__ctx__){
649
+ ${o}
650
+ }`, t = new Function("__ctx__", e);
651
+ return (r) => {
652
+ const s = Object.freeze(Object.assign({}, Ge, r));
653
+ return t(s);
614
654
  };
615
655
  }
616
- const P = new He();
617
- function D(n) {
618
- const t = `return (${n})(v, data, context, entry)`;
619
- return P.getFn(t);
656
+ const W = new Ke();
657
+ function ne(o) {
658
+ const e = `return (${o})(v, data, context, entry)`;
659
+ return W.getFn(e);
660
+ }
661
+ function G(o) {
662
+ const e = `return (${o})(data, context)`;
663
+ return W.getFn(e);
664
+ }
665
+ function Xe(o) {
666
+ const e = `return (${o})(v, data, context, entry)`;
667
+ return W.getFn(e);
620
668
  }
621
- function z(n) {
622
- const t = `return (${n})(data, context)`;
623
- return P.getFn(t);
669
+ function Ye(o, e) {
670
+ switch (o.type.kind) {
671
+ case "": {
672
+ const t = o;
673
+ return e.phantom && t.type.designType === "phantom" ? e.phantom(t) : e.final(t);
674
+ }
675
+ case "object":
676
+ return e.object(o);
677
+ case "array":
678
+ return e.array(o);
679
+ case "union":
680
+ return e.union(o);
681
+ case "intersection":
682
+ return e.intersection(o);
683
+ case "tuple":
684
+ return e.tuple(o);
685
+ default:
686
+ throw new Error(`Unknown type kind "${o.type.kind}"`);
687
+ }
624
688
  }
625
- function Ge(n) {
626
- const t = `return (${n})(v, data, context)`;
627
- return P.getFn(t);
689
+ function B(o, e, t) {
690
+ return e in o ? Object.defineProperty(o, e, {
691
+ value: t,
692
+ enumerable: !0,
693
+ configurable: !0,
694
+ writable: !0
695
+ }) : o[e] = t, o;
628
696
  }
629
- const Pe = /* @__PURE__ */ new Set(["action", "paragraph", "select", "radio", "checkbox"]);
630
- function Re(n) {
631
- return (Array.isArray(n) ? n : [n]).map((o) => {
632
- if (typeof o == "object" && o !== null && "label" in o) {
633
- const { label: l, value: a } = o;
634
- return a !== void 0 ? { key: a, label: l } : l;
697
+ const ee = /* @__PURE__ */ new Map();
698
+ var Qe = class {
699
+ isLimitExceeded() {
700
+ return this.stackErrors.length > 0 ? this.stackErrors[this.stackErrors.length - 1].length >= this.opts.errorLimit : this.errors.length >= this.opts.errorLimit;
701
+ }
702
+ push(o) {
703
+ this.stackPath.push(o), this.stackErrors.push([]);
704
+ }
705
+ pop(o) {
706
+ this.stackPath.pop();
707
+ const e = this.stackErrors.pop();
708
+ return o && (e != null && e.length) && e.forEach((t) => {
709
+ this.error(t.message, t.path, t.details);
710
+ }), e;
711
+ }
712
+ clear() {
713
+ this.stackErrors[this.stackErrors.length - 1] = [];
714
+ }
715
+ error(o, e, t) {
716
+ const r = this.stackErrors[this.stackErrors.length - 1] || this.errors, s = {
717
+ path: e || this.path,
718
+ message: o
719
+ };
720
+ t != null && t.length && (s.details = t), r.push(s);
721
+ }
722
+ throw() {
723
+ throw new Je(this.errors);
724
+ }
725
+ /**
726
+ * Validates a value against the type definition.
727
+ *
728
+ * Acts as a TypeScript type guard — when it returns `true`, the value
729
+ * is narrowed to `DataType`.
730
+ *
731
+ * @param value - The value to validate.
732
+ * @param safe - If `true`, returns `false` on failure instead of throwing.
733
+ * @returns `true` if the value matches the type definition.
734
+ * @throws {ValidatorError} When validation fails and `safe` is not `true`.
735
+ */
736
+ validate(o, e) {
737
+ this.push(""), this.errors = [], this.stackErrors = [];
738
+ const t = this.validateSafe(this.def, o);
739
+ if (this.pop(!t), !t) {
740
+ if (e) return !1;
741
+ this.throw();
742
+ }
743
+ return !0;
744
+ }
745
+ validateSafe(o, e) {
746
+ if (this.isLimitExceeded()) return !1;
747
+ if (!Ze(o)) throw new Error("Can not validate not-annotated type");
748
+ if (typeof this.opts.replace == "function" && (o = this.opts.replace(o, this.path)), o.optional && e === void 0) return !0;
749
+ for (const t of this.opts.plugins) {
750
+ const r = t(this, o, e);
751
+ if (r === !1 || r === !0) return r;
752
+ }
753
+ return this.validateAnnotatedType(o, e);
754
+ }
755
+ get path() {
756
+ return this.stackPath.slice(1).join(".");
757
+ }
758
+ validateAnnotatedType(o, e) {
759
+ return Ye(o, {
760
+ final: (t) => this.validatePrimitive(t, e),
761
+ phantom: () => !0,
762
+ object: (t) => this.validateObject(t, e),
763
+ array: (t) => this.validateArray(t, e),
764
+ union: (t) => this.validateUnion(t, e),
765
+ intersection: (t) => this.validateIntersection(t, e),
766
+ tuple: (t) => this.validateTuple(t, e)
767
+ });
768
+ }
769
+ validateUnion(o, e) {
770
+ let t = 0;
771
+ const r = [];
772
+ for (const a of o.type.items) {
773
+ if (this.push(`[${a.type.kind || a.type.designType}(${t})]`), this.validateSafe(a, e))
774
+ return this.pop(!1), !0;
775
+ const l = this.pop(!1);
776
+ l && r.push(...l), t++;
777
+ }
778
+ this.clear();
779
+ const s = o.type.items.map((a, l) => `[${a.type.kind || a.type.designType}(${l})]`).join(", ");
780
+ return this.error(`Value does not match any of the allowed types: ${s}`, void 0, r), !1;
781
+ }
782
+ validateIntersection(o, e) {
783
+ for (const t of o.type.items) if (!this.validateSafe(t, e)) return !1;
784
+ return !0;
785
+ }
786
+ validateTuple(o, e) {
787
+ if (!Array.isArray(e) || e.length !== o.type.items.length)
788
+ return this.error(`Expected array of length ${o.type.items.length}`), !1;
789
+ let t = 0;
790
+ for (const r of o.type.items) {
791
+ if (this.push(`[${t}]`), !this.validateSafe(r, e[t]))
792
+ return this.pop(!0), !1;
793
+ this.pop(!1), t++;
794
+ }
795
+ return !0;
796
+ }
797
+ validateArray(o, e) {
798
+ if (!Array.isArray(e))
799
+ return this.error("Expected array"), !1;
800
+ const t = o.metadata.get("expect.minLength");
801
+ if (t) {
802
+ const l = typeof t == "number" ? t : t.length;
803
+ if (e.length < l) {
804
+ const c = typeof t == "object" && t.message ? t.message : `Expected minimum length of ${l} items, got ${e.length} items`;
805
+ return this.error(c), !1;
806
+ }
807
+ }
808
+ const r = o.metadata.get("expect.maxLength");
809
+ if (r) {
810
+ const l = typeof r == "number" ? r : r.length;
811
+ if (e.length > l) {
812
+ const c = typeof r == "object" && r.message ? r.message : `Expected maximum length of ${l} items, got ${e.length} items`;
813
+ return this.error(c), !1;
814
+ }
815
+ }
816
+ let s = 0, a = !0;
817
+ for (const l of e) {
818
+ if (this.push(`[${s}]`), this.validateSafe(o.type.of, l))
819
+ this.pop(!1);
820
+ else if (a = !1, this.pop(!0), this.isLimitExceeded()) return !1;
821
+ s++;
635
822
  }
636
- return String(o);
823
+ return a;
824
+ }
825
+ validateObject(o, e) {
826
+ if (typeof e != "object" || e === null || Array.isArray(e))
827
+ return this.error("Expected object"), !1;
828
+ let t = !0;
829
+ const r = new Set(Object.keys(e)), s = /* @__PURE__ */ new Set(), a = /* @__PURE__ */ new Set();
830
+ if (this.opts.skipList) {
831
+ const c = this.stackPath.length > 1 ? `${this.path}.` : "";
832
+ this.opts.skipList.forEach((m) => {
833
+ if (m.startsWith(c)) {
834
+ const p = m.slice(c.length);
835
+ a.add(p), r.delete(p);
836
+ }
837
+ });
838
+ }
839
+ let l = !1;
840
+ typeof this.opts.partial == "function" && (l = this.opts.partial(o, this.path));
841
+ for (const [c, m] of o.type.props.entries())
842
+ if (!(a.has(c) || et(m)) && (s.add(c), !(e[c] === void 0 && (l || this.opts.partial === "deep" || this.opts.partial === !0 && this.stackPath.length <= 1)))) {
843
+ if (this.push(c), this.validateSafe(m, e[c])) this.pop(!1);
844
+ else if (t = !1, this.pop(!0), this.isLimitExceeded()) return !1;
845
+ }
846
+ for (const c of r)
847
+ if (!s.has(c)) {
848
+ const m = [];
849
+ for (const { pattern: p, def: f } of o.type.propsPatterns) p.test(c) && m.push({
850
+ pattern: p,
851
+ def: f
852
+ });
853
+ if (m.length) {
854
+ let p = !1;
855
+ for (const { def: f } of m) if (this.validateSafe(f, e[c])) {
856
+ this.pop(!1), p = !0;
857
+ break;
858
+ }
859
+ if (!p && (this.push(c), this.validateSafe(m[0].def, e[c]), this.pop(!0), t = !1, this.isLimitExceeded()))
860
+ return !1;
861
+ } else if (this.opts.unknwonProps !== "ignore")
862
+ if (this.opts.unknwonProps === "error") {
863
+ if (this.push(c), this.error("Unexpected property"), this.pop(!0), this.isLimitExceeded()) return !1;
864
+ t = !1;
865
+ } else this.opts.unknwonProps === "strip" && delete e[c];
866
+ }
867
+ return t;
868
+ }
869
+ validatePrimitive(o, e) {
870
+ if (typeof o.type.value < "u")
871
+ return e !== o.type.value ? (this.error(`Expected ${o.type.value}, got ${e}`), !1) : !0;
872
+ const t = Array.isArray(e) ? "array" : typeof e;
873
+ switch (o.type.designType) {
874
+ case "never":
875
+ return this.error("This type is impossible, must be an internal problem"), !1;
876
+ case "any":
877
+ return !0;
878
+ case "string":
879
+ return t !== o.type.designType ? (this.error(`Expected ${o.type.designType}, got ${t}`), !1) : this.validateString(o, e);
880
+ case "number":
881
+ return t !== o.type.designType ? (this.error(`Expected ${o.type.designType}, got ${t}`), !1) : this.validateNumber(o, e);
882
+ case "boolean":
883
+ return t !== o.type.designType ? (this.error(`Expected ${o.type.designType}, got ${t}`), !1) : !0;
884
+ case "undefined":
885
+ return e !== void 0 ? (this.error(`Expected ${o.type.designType}, got ${t}`), !1) : !0;
886
+ case "null":
887
+ return e !== null ? (this.error(`Expected ${o.type.designType}, got ${t}`), !1) : !0;
888
+ default:
889
+ throw new Error(`Unknown type "${o.type.designType}"`);
890
+ }
891
+ }
892
+ validateString(o, e) {
893
+ const t = o.metadata.get("expect.minLength");
894
+ if (t) {
895
+ const a = typeof t == "number" ? t : t.length;
896
+ if (e.length < a) {
897
+ const l = typeof t == "object" && t.message ? t.message : `Expected minimum length of ${a} characters, got ${e.length} characters`;
898
+ return this.error(l), !1;
899
+ }
900
+ }
901
+ const r = o.metadata.get("expect.maxLength");
902
+ if (r) {
903
+ const a = typeof r == "number" ? r : r.length;
904
+ if (e.length > a) {
905
+ const l = typeof r == "object" && r.message ? r.message : `Expected maximum length of ${a} characters, got ${e.length} characters`;
906
+ return this.error(l), !1;
907
+ }
908
+ }
909
+ const s = o.metadata.get("expect.pattern");
910
+ for (const { pattern: a, flags: l, message: c } of s || []) {
911
+ if (!a) continue;
912
+ const m = `${a}//${l || ""}`;
913
+ let p = ee.get(m);
914
+ if (p || (p = new RegExp(a, l), ee.set(m, p)), !p.test(e))
915
+ return this.error(c || `Value is expected to match pattern "${a}"`), !1;
916
+ }
917
+ return !0;
918
+ }
919
+ validateNumber(o, e) {
920
+ const t = o.metadata.get("expect.int");
921
+ if (t && e % 1 !== 0) {
922
+ const a = typeof t == "object" && t.message ? t.message : `Expected integer, got ${e}`;
923
+ return this.error(a), !1;
924
+ }
925
+ const r = o.metadata.get("expect.min");
926
+ if (r) {
927
+ const a = typeof r == "number" ? r : r.minValue;
928
+ if (e < a) {
929
+ const l = typeof r == "object" && r.message ? r.message : `Expected minimum ${a}, got ${e}`;
930
+ return this.error(l), !1;
931
+ }
932
+ }
933
+ const s = o.metadata.get("expect.max");
934
+ if (s) {
935
+ const a = typeof s == "number" ? s : s.maxValue;
936
+ if (e > a) {
937
+ const l = typeof s == "object" && s.message ? s.message : `Expected maximum ${a}, got ${e}`;
938
+ return this.error(l), !1;
939
+ }
940
+ }
941
+ return !0;
942
+ }
943
+ constructor(o, e) {
944
+ B(this, "def", void 0), B(this, "opts", void 0), B(this, "errors", void 0), B(this, "stackErrors", void 0), B(this, "stackPath", void 0), this.def = o, this.errors = [], this.stackErrors = [], this.stackPath = [], this.opts = {
945
+ partial: !1,
946
+ unknwonProps: "error",
947
+ errorLimit: 10,
948
+ ...e,
949
+ plugins: (e == null ? void 0 : e.plugins) || []
950
+ };
951
+ }
952
+ }, Je = class extends Error {
953
+ constructor(o) {
954
+ super(`${o[0].path ? o[0].path + ": " : ""}${o[0].message}`), B(this, "errors", void 0), B(this, "name", void 0), this.errors = o, this.name = "Validation Error";
955
+ }
956
+ };
957
+ function Ze(o) {
958
+ return o && o.__is_atscript_annotated_type;
959
+ }
960
+ function et(o) {
961
+ return o.type.kind === "" && o.type.designType === "phantom";
962
+ }
963
+ const tt = /* @__PURE__ */ new Set(["action", "paragraph", "select", "radio", "checkbox"]);
964
+ function ot(o) {
965
+ return (Array.isArray(o) ? o : [o]).map((t) => {
966
+ if (typeof t == "object" && t !== null && "label" in t) {
967
+ const { label: r, value: s } = t;
968
+ return s !== void 0 ? { key: s, label: r } : r;
969
+ }
970
+ return String(t);
637
971
  });
638
972
  }
639
- function $(n, t, o, l, a) {
640
- const s = o.get(t);
641
- if (typeof s == "string")
642
- return l(s);
643
- const f = o.get(n);
644
- return f !== void 0 ? f : a;
973
+ function $(o, e, t, r) {
974
+ const { transform: s, defaultValue: a, staticAsBoolean: l = !1, compiler: c = ne } = r ?? {}, m = t.get(o);
975
+ if (typeof m == "string")
976
+ return c(m);
977
+ if (e !== void 0) {
978
+ const p = t.get(e);
979
+ if (p !== void 0)
980
+ return l ? !0 : s ? s(p) : p;
981
+ }
982
+ return a;
983
+ }
984
+ function nt(o, e) {
985
+ var t, r, s, a;
986
+ return {
987
+ optional: (t = $("foorm.fn.optional", void 0, o)) !== null && t !== void 0 ? t : e ?? !1,
988
+ disabled: (r = $("foorm.fn.disabled", "foorm.disabled", o, {
989
+ staticAsBoolean: !0
990
+ })) !== null && r !== void 0 ? r : !1,
991
+ hidden: (s = $("foorm.fn.hidden", "foorm.hidden", o, {
992
+ staticAsBoolean: !0
993
+ })) !== null && s !== void 0 ? s : !1,
994
+ readonly: (a = $("foorm.fn.readonly", "foorm.readonly", o, {
995
+ staticAsBoolean: !0
996
+ })) !== null && a !== void 0 ? a : !1
997
+ };
645
998
  }
646
- function Xe(n) {
647
- const t = n.get("foorm.attr"), o = n.get("foorm.fn.attr");
648
- if (!t && !o)
999
+ function rt(o, e) {
1000
+ return {
1001
+ label: $("foorm.fn.label", "meta.label", o, {
1002
+ defaultValue: e
1003
+ }),
1004
+ description: $("foorm.fn.description", "meta.description", o),
1005
+ hint: $("foorm.fn.hint", "meta.hint", o),
1006
+ placeholder: $("foorm.fn.placeholder", "meta.placeholder", o)
1007
+ };
1008
+ }
1009
+ function st(o) {
1010
+ const e = o.get("foorm.attr"), t = o.get("foorm.fn.attr");
1011
+ if (!e && !t)
649
1012
  return;
650
- const l = {};
651
- if (t) {
652
- const a = Array.isArray(t) ? t : [t];
653
- for (const s of a)
654
- if (typeof s == "object" && s !== null && "name" in s && "value" in s) {
655
- const { name: f, value: p } = s;
656
- l[f] = p;
1013
+ const r = {};
1014
+ if (e) {
1015
+ const s = Array.isArray(e) ? e : [e];
1016
+ for (const a of s)
1017
+ if (typeof a == "object" && a !== null && "name" in a && "value" in a) {
1018
+ const { name: l, value: c } = a;
1019
+ r[l] = c;
657
1020
  }
658
1021
  }
659
- if (o) {
660
- const a = Array.isArray(o) ? o : [o];
661
- for (const s of a)
662
- if (typeof s == "object" && s !== null && "name" in s && "fn" in s) {
663
- const { name: f, fn: p } = s;
664
- l[f] = D(p);
1022
+ if (t) {
1023
+ const s = Array.isArray(t) ? t : [t];
1024
+ for (const a of s)
1025
+ if (typeof a == "object" && a !== null && "name" in a && "fn" in a) {
1026
+ const { name: l, fn: c } = a;
1027
+ r[l] = ne(c);
665
1028
  }
666
1029
  }
667
- return Object.keys(l).length > 0 ? l : void 0;
1030
+ return Object.keys(r).length > 0 ? r : void 0;
668
1031
  }
669
- function Ye(n) {
670
- var t, o;
671
- const l = n.metadata, a = n.type.props, s = $("foorm.title", "foorm.fn.title", l, z, ""), f = $("foorm.submit.text", "foorm.fn.submit.text", l, z, "Submit"), p = (() => {
672
- const i = l.get("foorm.fn.submit.disabled");
673
- return typeof i == "string" ? z(i) : !1;
674
- })(), S = { text: f, disabled: p }, V = [];
675
- for (const [i, y] of a.entries()) {
676
- const r = y.metadata, u = (t = y.type) === null || t === void 0 ? void 0 : t.tags, k = r.get("foorm.type"), b = u ? [...u].find((c) => Pe.has(c)) : void 0, x = (o = k ?? b) !== null && o !== void 0 ? o : "text", A = [], e = r.get("foorm.validate");
677
- if (e) {
678
- const c = Array.isArray(e) ? e : [e];
679
- for (const B of c)
680
- typeof B == "string" && A.push(Ge(B));
1032
+ function at(o) {
1033
+ var e, t;
1034
+ const r = o.metadata, s = o.type.props, a = $("foorm.fn.title", "foorm.title", r, {
1035
+ compiler: G,
1036
+ defaultValue: ""
1037
+ }), l = $("foorm.fn.submit.text", "foorm.submit.text", r, {
1038
+ compiler: G,
1039
+ defaultValue: "Submit"
1040
+ }), c = $("foorm.fn.submit.disabled", "foorm.submit.disabled", r, {
1041
+ compiler: G,
1042
+ defaultValue: !1
1043
+ }), m = { text: l, disabled: c }, p = [];
1044
+ for (const [f, h] of s.entries()) {
1045
+ const u = h.metadata, d = (e = h.type) === null || e === void 0 ? void 0 : e.tags, A = u.get("foorm.type"), v = d ? [...d].find((i) => tt.has(i)) : void 0, E = (t = A ?? v) !== null && t !== void 0 ? t : "text", C = [], n = u.get("foorm.validate");
1046
+ if (n) {
1047
+ const i = Array.isArray(n) ? n : [n];
1048
+ for (const k of i)
1049
+ typeof k == "string" && C.push(Xe(k));
1050
+ }
1051
+ const F = u.get("expect.pattern") !== void 0 || u.get("expect.min") !== void 0 || u.get("expect.max") !== void 0 || u.get("expect.minLength") !== void 0 || u.get("expect.maxLength") !== void 0 || u.get("expect.int") !== void 0, D = d && d.size > 0;
1052
+ if (F || D) {
1053
+ const i = new Qe(h);
1054
+ C.push((k) => {
1055
+ var S;
1056
+ if (i.validate(k.v, !0))
1057
+ return !0;
1058
+ const z = (S = i.errors) === null || S === void 0 ? void 0 : S[0];
1059
+ return (z == null ? void 0 : z.message) || "Validation failed";
1060
+ });
681
1061
  }
682
- const F = {
683
- field: i,
684
- type: x,
685
- component: r.get("foorm.component"),
686
- autocomplete: r.get("foorm.autocomplete"),
687
- altAction: r.get("foorm.altAction"),
688
- order: r.get("foorm.order"),
689
- name: i,
690
- label: $("meta.label", "foorm.fn.label", r, D, i),
691
- description: $("meta.description", "foorm.fn.description", r, D, ""),
692
- hint: $("meta.hint", "foorm.fn.hint", r, D, ""),
693
- placeholder: $("meta.placeholder", "foorm.fn.placeholder", r, D, ""),
694
- optional: (() => {
695
- var c;
696
- const B = r.get("foorm.fn.optional");
697
- return typeof B == "string" ? D(B) : (c = y.optional) !== null && c !== void 0 ? c : !1;
698
- })(),
699
- disabled: (() => {
700
- const c = r.get("foorm.fn.disabled");
701
- return typeof c == "string" ? D(c) : r.get("foorm.disabled") !== void 0;
702
- })(),
703
- hidden: (() => {
704
- const c = r.get("foorm.fn.hidden");
705
- return typeof c == "string" ? D(c) : r.get("foorm.hidden") !== void 0;
706
- })(),
707
- classes: (() => {
708
- const c = r.get("foorm.fn.classes");
709
- if (typeof c == "string")
710
- return D(c);
711
- })(),
712
- styles: (() => {
713
- const c = r.get("foorm.fn.styles");
714
- if (typeof c == "string")
715
- return D(c);
716
- })(),
717
- options: (() => {
718
- const c = r.get("foorm.fn.options");
719
- if (typeof c == "string")
720
- return D(c);
721
- const B = r.get("foorm.options");
722
- if (B)
723
- return Re(B);
724
- })(),
725
- value: r.get("foorm.value"),
726
- validators: A,
1062
+ const j = Object.assign(Object.assign(Object.assign({ field: f, type: E, component: u.get("foorm.component"), autocomplete: u.get("foorm.autocomplete"), altAction: u.get("foorm.altAction"), order: u.get("foorm.order"), name: f }, rt(u, f)), nt(u, h.optional)), {
1063
+ // Appearance - truly optional
1064
+ classes: $("foorm.fn.classes", void 0, u),
1065
+ styles: $("foorm.fn.styles", void 0, u),
1066
+ // Data properties - truly optional
1067
+ options: $("foorm.fn.options", "foorm.options", u, {
1068
+ transform: ot
1069
+ }),
1070
+ value: $("foorm.fn.value", "foorm.value", u),
1071
+ validators: C,
727
1072
  // Custom attributes/props
728
- attrs: Xe(r),
1073
+ attrs: st(u),
729
1074
  // ATScript @expect constraints
730
- maxLength: r.get("expect.maxLength"),
731
- minLength: r.get("expect.minLength"),
732
- min: r.get("expect.min"),
733
- max: r.get("expect.max")
734
- };
735
- V.push(F);
1075
+ maxLength: u.get("expect.maxLength"),
1076
+ minLength: u.get("expect.minLength"),
1077
+ min: u.get("expect.min"),
1078
+ max: u.get("expect.max")
1079
+ });
1080
+ p.push(j);
736
1081
  }
737
- return V.sort((i, y) => {
738
- var r, u;
739
- return ((r = i.order) !== null && r !== void 0 ? r : 1 / 0) - ((u = y.order) !== null && u !== void 0 ? u : 1 / 0);
740
- }), { title: s, submit: S, fields: V };
1082
+ return p.sort((f, h) => {
1083
+ var u, d;
1084
+ return ((u = f.order) !== null && u !== void 0 ? u : 1 / 0) - ((d = h.order) !== null && d !== void 0 ? d : 1 / 0);
1085
+ }), { title: a, submit: m, fields: p };
741
1086
  }
742
- function Je(n) {
743
- const t = Ye(n), o = de(pe(t.fields));
744
- return { form: t, formData: o };
1087
+ function ct(o) {
1088
+ const e = at(o), t = ye(ve(e.fields));
1089
+ return { form: e, formData: t };
745
1090
  }
746
1091
  export {
747
- ye as OoField,
748
- We as OoForm,
749
- Je as useFoorm
1092
+ _e as OoField,
1093
+ ut as OoForm,
1094
+ ct as useFoorm
750
1095
  };