@foormjs/vue 0.2.0 → 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,105 +1,120 @@
1
- var X = Object.defineProperty;
2
- var Q = (n, t, o) => t in n ? X(n, t, { enumerable: !0, configurable: !0, writable: !0, value: o }) : n[t] = o;
3
- var N = (n, t, o) => Q(n, typeof t != "symbol" ? t + "" : t, o);
4
- import { defineComponent as T, useModel as R, inject as P, ref as w, computed as m, watch as W, onUnmounted as Y, getCurrentInstance as U, renderSlot as A, unref as B, mergeModels as J, provide as K, openBlock as x, createElementBlock as E, withModifiers as Z, nextTick as ee, createBlock as q, withCtx as O, toDisplayString as F, createCommentVNode as H, Fragment as te, renderList as oe, mergeProps as $, resolveDynamicComponent as z, normalizeClass as ne, createElementVNode as M, withDirectives as le, vModelDynamic as re, reactive as ae } from "vue";
5
- function b(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
- function ue(n) {
9
- var t;
10
- const o = {};
11
- for (const r of n)
12
- r.type !== "action" && (o[r.field] = (t = r.value) !== null && t !== void 0 ? t : void 0);
13
- 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;
14
28
  }
15
- function se(n, t) {
16
- return n.fields.some((o) => o.altAction === t);
29
+ function be(o, e) {
30
+ return o.fields.some((t) => t.altAction === e);
17
31
  }
18
- function ie(n, t) {
19
- if (!n) return;
20
- const o = {};
21
- for (const [r, a] of Object.entries(n))
22
- o[r] = b(a, t);
23
- return o;
32
+ function xe(o, e) {
33
+ if (!o)
34
+ return;
35
+ const t = {};
36
+ for (const [r, s] of Object.entries(o))
37
+ t[r] = M(s, e);
38
+ return t;
24
39
  }
25
- const ce = /* @__PURE__ */ T({
40
+ const ke = /* @__PURE__ */ I({
26
41
  __name: "VuilessField",
27
- props: /* @__PURE__ */ J({
42
+ props: /* @__PURE__ */ ie({
28
43
  rules: {}
29
44
  }, {
30
45
  modelValue: {},
31
46
  modelModifiers: {}
32
47
  }),
33
48
  emits: ["update:modelValue"],
34
- setup(n) {
35
- const t = n, o = R(n, "modelValue"), r = P("vuiless"), a = w(), d = w(!1), v = w(!1), f = m(() => {
36
- var c;
37
- if ((c = r == null ? void 0 : r.value) != null && c.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)
38
53
  switch (r.value.firstValidation) {
39
54
  case "on-change":
40
- return r.value.firstSubmitHappened || d.value;
55
+ return r.value.firstSubmitHappened || a.value;
41
56
  case "touched-on-blur":
42
- return r.value.firstSubmitHappened || v.value && d.value;
57
+ return r.value.firstSubmitHappened || l.value && a.value;
43
58
  case "on-blur":
44
- return r.value.firstSubmitHappened || v.value;
59
+ return r.value.firstSubmitHappened || l.value;
45
60
  case "on-submit":
46
61
  return r.value.firstSubmitHappened;
47
62
  case "none":
48
63
  return !1;
49
64
  }
50
65
  return !1;
51
- }), g = m(() => {
52
- if (f.value || a.value)
53
- return V();
66
+ }), m = _(() => {
67
+ if (c.value || s.value)
68
+ return p();
54
69
  });
55
- W([o], () => {
56
- a.value = void 0, d.value = !0;
57
- }), Y(() => {
58
- var c;
59
- (c = r == null ? void 0 : r.value) == null || c.unregister(U());
60
- }), r != null && r.value && r.value.register(U(), {
61
- 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),
62
77
  clearErrors: () => {
63
- d.value = !1, v.value = !1, a.value = void 0;
78
+ a.value = !1, l.value = !1, s.value = void 0;
64
79
  },
65
80
  reset: () => {
66
- o.value = "";
81
+ t.value = "";
67
82
  }
68
83
  });
69
- function V() {
70
- var c, l, u;
71
- if ((c = t.rules) != null && c.length)
72
- for (const y of t.rules) {
73
- const e = y(
74
- o.value,
75
- (l = r == null ? void 0 : r.value) == null ? void 0 : l.formData,
76
- (u = r == null ? void 0 : r.value) == null ? void 0 : u.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
77
92
  );
78
- if (e !== !0)
79
- return e || "Wrong value";
93
+ if (E !== !0)
94
+ return E || "Wrong value";
80
95
  }
81
96
  }
82
- function i() {
83
- v.value = !0;
97
+ function f() {
98
+ l.value = !0;
84
99
  }
85
- const s = {
86
- v: m({
87
- get: () => o.value,
88
- set: (c) => o.value = c
100
+ const h = {
101
+ v: _({
102
+ get: () => t.value,
103
+ set: (u) => t.value = u
89
104
  })
90
105
  };
91
- return (c, l) => {
92
- var u, y;
93
- return A(c.$slots, "default", {
94
- onBlur: i,
95
- error: g.value,
96
- formData: (u = B(r)) == null ? void 0 : u.formData,
97
- formContext: (y = B(r)) == null ? void 0 : y.formContext,
98
- model: s.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
99
114
  });
100
115
  };
101
116
  }
102
- }), me = /* @__PURE__ */ T({
117
+ }), Ee = /* @__PURE__ */ I({
103
118
  __name: "VuilessForm",
104
119
  props: {
105
120
  formData: {},
@@ -107,46 +122,46 @@ const ce = /* @__PURE__ */ T({
107
122
  firstValidation: { default: "on-change" }
108
123
  },
109
124
  emits: ["submit"],
110
- setup(n, { emit: t }) {
111
- const o = n, r = t, a = /* @__PURE__ */ new Map(), d = w(!1), v = m(() => ({
112
- firstSubmitHappened: d.value,
113
- firstValidation: o.firstValidation,
114
- register: (i, s) => {
115
- a.set(i, s);
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);
116
131
  },
117
- unregister: (i) => a.delete(i),
118
- formData: o.formData,
119
- formContext: o.formContext
132
+ unregister: (f) => s.delete(f),
133
+ formData: t.formData,
134
+ formContext: t.formContext
120
135
  }));
121
- K("vuiless", v);
122
- function f() {
123
- d.value = !1;
124
- for (const { clearErrors: i } of a.values())
125
- i();
136
+ ue("vuiless", l);
137
+ function c() {
138
+ a.value = !1;
139
+ for (const { clearErrors: f } of s.values())
140
+ f();
126
141
  }
127
- async function g() {
128
- for (const { reset: i } of a.values())
129
- i();
130
- await ee(), f();
142
+ async function m() {
143
+ for (const { reset: f } of s.values())
144
+ f();
145
+ await pe(), c();
131
146
  }
132
- function V() {
133
- d.value = !0;
134
- let i = !1;
135
- if (o.firstValidation !== "none")
136
- for (const { validate: s } of a.values())
137
- s() !== !0 && (i = !0);
138
- i || r("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);
139
154
  }
140
- return (i, s) => (x(), E("form", {
141
- onSubmit: Z(V, ["prevent"])
155
+ return (f, h) => (y(), b("form", {
156
+ onSubmit: ce(p, ["prevent"])
142
157
  }, [
143
- A(i.$slots, "default", {
144
- clearErrors: f,
145
- reset: g
158
+ w(f.$slots, "default", {
159
+ clearErrors: c,
160
+ reset: m
146
161
  })
147
162
  ], 32));
148
163
  }
149
- }), de = /* @__PURE__ */ T({
164
+ }), _e = /* @__PURE__ */ I({
150
165
  __name: "oo-field",
151
166
  props: {
152
167
  field: {},
@@ -163,11 +178,12 @@ const ce = /* @__PURE__ */ T({
163
178
  optional: { type: [Boolean, Function] },
164
179
  disabled: { type: [Boolean, Function] },
165
180
  hidden: { type: [Boolean, Function] },
181
+ readonly: { type: [Boolean, Function] },
166
182
  classes: { type: [String, Object, Function] },
167
183
  styles: { type: [String, Object, Function] },
168
184
  options: { type: [Array, Function] },
169
185
  attrs: {},
170
- value: {},
186
+ value: { type: Function },
171
187
  validators: {},
172
188
  maxLength: {},
173
189
  minLength: {},
@@ -175,85 +191,112 @@ const ce = /* @__PURE__ */ T({
175
191
  max: {},
176
192
  error: {}
177
193
  },
178
- setup(n) {
179
- const t = n, o = P(
194
+ setup(o) {
195
+ const e = o, t = te(
180
196
  "vuiless"
181
- ), r = m(() => ({
182
- v: o.value.formData[t.field],
183
- data: o.value.formData,
184
- context: o.value.formContext ?? {}
185
- })), a = m(() => b(t.optional, r.value)), d = m(() => b(t.disabled, r.value)), v = m(() => b(t.hidden, r.value)), f = m(() => ({
186
- ...r.value,
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 ?? {},
205
+ entry: void 0
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 ?? {},
187
210
  entry: {
188
- field: t.field,
189
- type: t.type,
190
- component: t.component,
191
- name: t.name || t.field,
192
- disabled: d.value,
193
- optional: a.value,
194
- hidden: v.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)
195
219
  }
196
- })), g = m(() => b(t.label, f.value)), V = m(() => b(t.description, f.value)), i = m(() => b(t.hint, f.value)), s = m(() => b(t.placeholder, f.value)), c = m(() => b(t.options, f.value)), l = m(() => {
197
- const C = b(t.classes, f.value);
198
- return typeof C == "string" ? {
199
- [C]: !0,
200
- disabled: d.value,
201
- 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)
202
226
  } : {
203
- ...C || {},
204
- disabled: d.value,
205
- required: !a.value
227
+ ...i,
228
+ disabled: s(c),
229
+ required: !s(l)
206
230
  };
207
- }), u = m(
208
- () => b(t.styles, f.value)
209
- ), y = m(() => ie(t.attrs, f.value)), e = m(() => t.validators.map(
210
- (C) => (D, h, _) => C({
211
- v: D,
212
- data: h,
213
- context: _ ?? {},
214
- entry: f.value.entry
215
- })
216
- ));
217
- return (C, D) => (x(), q(B(ce), {
218
- modelValue: B(o).formData[t.field],
219
- "onUpdate:modelValue": D[0] || (D[0] = (h) => B(o).formData[t.field] = h),
220
- rules: e.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)
221
262
  }, {
222
- default: O((h) => [
223
- A(C.$slots, "default", {
224
- onBlur: h.onBlur,
225
- error: n.error || h.error,
226
- model: h.model,
227
- formData: B(o).formData,
228
- formContext: B(o).formContext,
229
- label: g.value,
230
- description: V.value,
231
- hint: i.value,
232
- placeholder: s.value,
233
- classes: {
234
- ...l.value,
235
- error: !!n.error || !!h.error
236
- },
237
- styles: u.value,
238
- optional: a.value,
239
- disabled: d.value,
240
- hidden: v.value,
241
- type: n.type,
242
- altAction: n.altAction,
243
- component: n.component,
244
- vName: n.name,
245
- field: n.field,
246
- options: c.value,
247
- maxLength: n.maxLength,
248
- required: !a.value,
249
- autocomplete: n.autocomplete,
250
- attrs: y.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
251
290
  })
252
291
  ]),
253
292
  _: 3
254
293
  }, 8, ["modelValue", "rules"]));
255
294
  }
256
- }), pe = { key: 0 }, fe = { key: 1 }, ve = { key: 0 }, he = ["onUpdate:modelValue", "onBlur", "placeholder", "autocomplete", "name", "type"], be = { class: "oo-error-slot" }, ge = { key: 4 }, ye = { key: 5 }, xe = ["disabled"], Ee = /* @__PURE__ */ T({
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 = {
296
+ key: 0,
297
+ value: "",
298
+ disabled: ""
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({
257
300
  __name: "oo-form",
258
301
  props: {
259
302
  form: {},
@@ -265,153 +308,244 @@ const ce = /* @__PURE__ */ T({
265
308
  errors: {}
266
309
  },
267
310
  emits: ["submit", "action", "unsupported-action"],
268
- setup(n, { emit: t }) {
269
- const o = n, r = w({}), a = m(() => o.formData || r.value), d = m(() => ({
311
+ setup(o, { emit: e }) {
312
+ const t = o, r = q({}), s = _(() => t.formData || r.value), a = _(() => ({
270
313
  v: void 0,
271
- data: a.value,
272
- context: o.formContext ?? {}
273
- })), v = m(() => b(o.form.title, d.value)), f = m(() => b(o.form.submit.text, d.value)), g = m(() => b(o.form.submit.disabled, d.value));
274
- function V(s) {
275
- se(o.form, s) ? i("action", s, a.value) : i("unsupported-action", s, a.value);
314
+ data: s.value,
315
+ context: t.formContext ?? {},
316
+ entry: void 0
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);
320
+ }
321
+ const f = e;
322
+ function h(d) {
323
+ return typeof d == "string" ? d : d.key;
324
+ }
325
+ function u(d) {
326
+ return typeof d == "string" ? d : d.label;
276
327
  }
277
- const i = t;
278
- return (s, c) => (x(), q(B(me), {
279
- "first-validation": n.firstValidation,
280
- onSubmit: c[0] || (c[0] = (l) => i("submit", l)),
281
- "form-data": a.value,
282
- "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
283
333
  }, {
284
- default: O((l) => [
285
- A(s.$slots, "form.header", {
286
- clearErrors: l.clearErrors,
287
- reset: l.reset,
288
- title: v.value,
289
- formContext: n.formContext,
290
- disabled: g.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
291
341
  }, () => [
292
- v.value ? (x(), E("h2", pe, F(v.value), 1)) : H("", !0)
342
+ l.value ? (y(), b("h2", Ve, g(l.value), 1)) : P("", !0)
293
343
  ]),
294
- A(s.$slots, "form.before", {
295
- clearErrors: l.clearErrors,
296
- reset: l.reset
344
+ w(d.$slots, "form.before", {
345
+ clearErrors: v.clearErrors,
346
+ reset: v.reset
297
347
  }),
298
- (x(!0), E(te, null, oe(o.form.fields, (u) => {
299
- var y;
300
- return x(), q(de, $({
301
- key: u.field
302
- }, { ref_for: !0 }, u, {
303
- error: (y = n.errors) == null ? void 0 : y[u.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]
304
354
  }), {
305
- default: O((e) => [
306
- A(s.$slots, `field:${e.type}`, $({ ref_for: !0 }, e), () => {
307
- var C, D, h;
355
+ default: K((n) => [
356
+ w(d.$slots, `field:${n.type}`, L({ ref_for: !0 }, n), () => {
357
+ var F, D, j;
308
358
  return [
309
- u.component && ((C = o.components) != null && C[u.component]) ? (x(), q(z(o.components[u.component]), $({
359
+ E.component && ((F = t.components) != null && F[E.component]) ? (y(), U(J(t.components[E.component]), L({
310
360
  key: 0,
311
- "on-blur": e.onBlur,
312
- error: e.error,
313
- model: e.model,
314
- "form-data": e.formData,
315
- "form-context": e.formContext,
316
- label: e.label,
317
- description: e.description,
318
- hint: e.hint,
319
- placeholder: e.placeholder,
320
- class: e.classes,
321
- style: e.styles,
322
- optional: e.optional,
323
- required: !e.required,
324
- disabled: e.disabled,
325
- hidden: e.hidden,
326
- type: e.type,
327
- "alt-action": e.altAction,
328
- name: e.vName,
329
- field: e,
330
- options: e.options,
331
- "max-length": e.maxLength,
332
- autocomplete: e.autocomplete,
333
- onAction: V
334
- }, { ref_for: !0 }, e.attrs, {
335
- modelValue: e.model.value,
336
- "onUpdate:modelValue": (_) => e.model.value = _
337
- }), 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"])) : u.component && !((D = o.components) != null && D[u.component]) ? (x(), E("div", fe, " [" + F(e.label) + '] Component "' + F(e.component) + '" not supplied ', 1)) : (h = o.types) != null && h[u.type] ? (x(), q(z(o.types[u.type]), $({
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({
338
388
  key: 2,
339
- "on-blur": e.onBlur,
340
- error: e.error,
341
- model: e.model,
342
- "form-data": e.formData,
343
- "form-context": e.formContext,
344
- label: e.label,
345
- description: e.description,
346
- hint: e.hint,
347
- placeholder: e.placeholder,
348
- class: e.classes,
349
- style: e.styles,
350
- optional: e.optional,
351
- required: !e.required,
352
- disabled: e.disabled,
353
- hidden: e.hidden,
354
- type: e.type,
355
- "alt-action": e.altAction,
356
- name: e.vName,
357
- field: e,
358
- options: e.options,
359
- "max-length": e.maxLength,
360
- autocomplete: e.autocomplete,
361
- onAction: V
362
- }, { ref_for: !0 }, e.attrs, {
363
- modelValue: e.model.value,
364
- "onUpdate:modelValue": (_) => e.model.value = _
365
- }), 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) ? (x(), E("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", {
366
416
  key: 3,
367
- class: ne(["oo-default-field", e.classes])
417
+ class: O(["oo-default-field", n.classes])
418
+ }, [
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]
432
+ ]),
433
+ V("div", we, g(n.error || n.hint), 1)
434
+ ], 2)), [
435
+ [N, !n.hidden]
436
+ ]) : n.type === "paragraph" ? (y(), b("p", Ce, g(n.description), 1)) : n.type === "select" ? T((y(), b("div", {
437
+ key: 5,
438
+ class: O(["oo-default-field", n.classes])
439
+ }, [
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]
456
+ ]),
457
+ V("div", De, g(n.error || n.hint), 1)
458
+ ], 2)), [
459
+ [N, !n.hidden]
460
+ ]) : n.type === "radio" ? T((y(), b("div", {
461
+ key: 6,
462
+ class: O(["oo-default-field oo-radio-field", n.classes])
463
+ }, [
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)
469
+ }, [
470
+ T(V("input", L({
471
+ type: "radio",
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]
480
+ ]),
481
+ Z(" " + g(u(i)), 1)
482
+ ]))), 128))
483
+ ]),
484
+ V("div", qe, g(n.error || n.hint), 1)
485
+ ], 2)), [
486
+ [N, !n.hidden]
487
+ ]) : n.type === "checkbox" ? T((y(), b("div", {
488
+ key: 7,
489
+ class: O(["oo-default-field oo-checkbox-field", n.classes])
368
490
  }, [
369
- M("label", null, F(e.label), 1),
370
- e.description ? (x(), E("span", ve, F(e.description), 1)) : H("", !0),
371
- le(M("input", {
372
- "onUpdate:modelValue": (_) => e.model.value = _,
373
- onBlur: e.onBlur,
374
- placeholder: e.placeholder,
375
- autocomplete: e.autocomplete,
376
- name: e.vName,
377
- type: e.type
378
- }, null, 40, he), [
379
- [re, e.model.value]
491
+ V("label", null, [
492
+ T(V("input", L({
493
+ type: "checkbox",
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]
501
+ ]),
502
+ Z(" " + g(n.label), 1)
380
503
  ]),
381
- M("div", be, F(e.error || e.hint), 1)
382
- ], 2)) : e.type === "paragraph" ? (x(), E("p", ge, F(e.description), 1)) : (x(), E("div", ye, " [" + F(e.label) + '] Not supported field type "' + F(e.type) + '" ' + F(e.component), 1))
504
+ n.description ? (y(), b("span", Ne, g(n.description), 1)) : P("", !0),
505
+ V("div", Ie, g(n.error || n.hint), 1)
506
+ ], 2)), [
507
+ [N, !n.hidden]
508
+ ]) : n.type === "action" ? (y(), b("div", {
509
+ key: 8,
510
+ class: O(["oo-default-field oo-action-field", n.classes])
511
+ }, [
512
+ V("button", {
513
+ type: "button",
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))
383
517
  ];
384
518
  })
385
519
  ]),
386
520
  _: 2
387
521
  }, 1040, ["error"]);
388
522
  }), 128)),
389
- A(s.$slots, "form.after", {
390
- clearErrors: l.clearErrors,
391
- reset: l.reset,
392
- disabled: g.value,
393
- 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
394
528
  }),
395
- A(s.$slots, "form.submit", {
396
- disabled: g.value,
397
- text: f.value,
398
- clearErrors: l.clearErrors,
399
- reset: l.reset,
400
- 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
401
535
  }, () => [
402
- M("button", { disabled: g.value }, F(f.value), 9, xe)
536
+ V("button", { disabled: m.value }, g(c.value), 9, Re)
403
537
  ]),
404
- A(s.$slots, "form.footer", {
405
- disabled: g.value,
406
- clearErrors: l.clearErrors,
407
- reset: l.reset,
408
- 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
409
543
  })
410
544
  ]),
411
545
  _: 3
412
546
  }, 8, ["first-validation", "form-data", "form-context"]));
413
547
  }
414
- }), Ce = {
548
+ }), Ge = {
415
549
  // Node.js Globals
416
550
  global: null,
417
551
  process: null,
@@ -498,121 +632,464 @@ const ce = /* @__PURE__ */ T({
498
632
  eval: null,
499
633
  __ctx__: null
500
634
  };
501
- class _e {
635
+ class Ke {
502
636
  constructor() {
503
- N(this, "cache", /* @__PURE__ */ new Map());
637
+ Y(this, "cache", /* @__PURE__ */ new Map());
504
638
  }
505
- call(t, o) {
506
- return this.getFn(t)(o);
639
+ call(e, t) {
640
+ return this.getFn(e)(t);
507
641
  }
508
- getFn(t) {
509
- let o = this.cache.get(t);
510
- return o || (o = Ve(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;
511
645
  }
512
646
  }
513
- function Ve(n) {
514
- const t = `with(__ctx__){
515
- ${n}
516
- }`, o = new Function("__ctx__", t);
647
+ function We(o) {
648
+ const e = `with(__ctx__){
649
+ ${o}
650
+ }`, t = new Function("__ctx__", e);
517
651
  return (r) => {
518
- const a = Object.freeze(Object.assign({}, Ce, r));
519
- return o(a);
652
+ const s = Object.freeze(Object.assign({}, Ge, r));
653
+ return t(s);
520
654
  };
521
655
  }
522
- const j = new _e();
523
- function S(n) {
524
- const t = `return (${n})(v, data, context, entry)`;
525
- return j.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);
526
660
  }
527
- function I(n) {
528
- const t = `return (${n})(data, context)`;
529
- return j.getFn(t);
661
+ function G(o) {
662
+ const e = `return (${o})(data, context)`;
663
+ return W.getFn(e);
530
664
  }
531
- function Fe(n) {
532
- const t = `return (${n})(v, data, context)`;
533
- return j.getFn(t);
665
+ function Xe(o) {
666
+ const e = `return (${o})(v, data, context, entry)`;
667
+ return W.getFn(e);
534
668
  }
535
- function k(n, t, o, r, a) {
536
- const d = o.get(t);
537
- if (typeof d == "string")
538
- return r(d);
539
- const v = o.get(n);
540
- return v !== void 0 ? v : a;
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
+ }
541
688
  }
542
- function Se(n) {
543
- var t, o, r;
544
- const a = n.metadata, d = n.type.props, v = k("foorm.title", "foorm.fn.title", a, I, ""), f = k("foorm.submit.text", "foorm.fn.submit.text", a, I, "Submit"), g = (() => {
545
- const s = a.get("foorm.fn.submit.disabled");
546
- return typeof s == "string" ? I(s) : !1;
547
- })(), V = { text: f, disabled: g }, i = [];
548
- for (const [s, c] of d.entries()) {
549
- const l = c.metadata, u = (t = c.type) === null || t === void 0 ? void 0 : t.tags, y = l.get("foorm.type"), e = (o = u == null ? void 0 : u.has("action")) !== null && o !== void 0 ? o : !1, C = (r = u == null ? void 0 : u.has("paragraph")) !== null && r !== void 0 ? r : !1, D = y ?? (e ? "action" : C ? "paragraph" : "text"), h = [], _ = l.get("foorm.validate");
550
- if (_) {
551
- const p = Array.isArray(_) ? _ : [_];
552
- for (const L of p)
553
- typeof L == "string" && h.push(Fe(L));
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;
696
+ }
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();
554
742
  }
555
- const G = {
556
- field: s,
557
- type: D,
558
- component: l.get("foorm.component"),
559
- autocomplete: l.get("foorm.autocomplete"),
560
- altAction: l.get("foorm.altAction"),
561
- order: l.get("foorm.order"),
562
- name: s,
563
- label: k("meta.label", "foorm.fn.label", l, S, s),
564
- description: k("meta.description", "foorm.fn.description", l, S, ""),
565
- hint: k("meta.hint", "foorm.fn.hint", l, S, ""),
566
- placeholder: k("meta.placeholder", "foorm.fn.placeholder", l, S, ""),
567
- optional: (() => {
568
- var p;
569
- const L = l.get("foorm.fn.optional");
570
- return typeof L == "string" ? S(L) : (p = c.optional) !== null && p !== void 0 ? p : !1;
571
- })(),
572
- disabled: (() => {
573
- const p = l.get("foorm.fn.disabled");
574
- return typeof p == "string" ? S(p) : l.get("foorm.disabled") !== void 0;
575
- })(),
576
- hidden: (() => {
577
- const p = l.get("foorm.fn.hidden");
578
- return typeof p == "string" ? S(p) : l.get("foorm.hidden") !== void 0;
579
- })(),
580
- classes: (() => {
581
- const p = l.get("foorm.fn.classes");
582
- if (typeof p == "string")
583
- return S(p);
584
- })(),
585
- styles: (() => {
586
- const p = l.get("foorm.fn.styles");
587
- if (typeof p == "string")
588
- return S(p);
589
- })(),
590
- options: (() => {
591
- const p = l.get("foorm.fn.options");
592
- if (typeof p == "string")
593
- return S(p);
594
- })(),
595
- value: l.get("foorm.value"),
596
- validators: h,
597
- // ATScript @expect constraints
598
- maxLength: l.get("expect.maxLength"),
599
- minLength: l.get("expect.minLength"),
600
- min: l.get("expect.min"),
601
- max: l.get("expect.max")
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++;
822
+ }
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) || []
602
950
  };
603
- i.push(G);
604
951
  }
605
- return i.sort((s, c) => {
606
- var l, u;
607
- return ((l = s.order) !== null && l !== void 0 ? l : 1 / 0) - ((u = c.order) !== null && u !== void 0 ? u : 1 / 0);
608
- }), { title: v, submit: V, fields: i };
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);
971
+ });
972
+ }
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
+ };
998
+ }
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)
1012
+ return;
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;
1020
+ }
1021
+ }
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);
1028
+ }
1029
+ }
1030
+ return Object.keys(r).length > 0 ? r : void 0;
1031
+ }
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
+ });
1061
+ }
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,
1072
+ // Custom attributes/props
1073
+ attrs: st(u),
1074
+ // ATScript @expect constraints
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);
1081
+ }
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 };
609
1086
  }
610
- function Be(n) {
611
- const t = Se(n), o = ae(ue(t.fields));
612
- 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 };
613
1090
  }
614
1091
  export {
615
- de as OoField,
616
- Ee as OoForm,
617
- Be as useFoorm
1092
+ _e as OoField,
1093
+ ut as OoForm,
1094
+ ct as useFoorm
618
1095
  };