@bach.software/vue-dynamic-form 0.4.0 → 0.5.0

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.
@@ -0,0 +1,732 @@
1
+ import { computed as u, defineComponent as le, inject as me, ref as X, watch as ie, watchEffect as _e, createElementBlock as B, openBlock as x, Fragment as z, withDirectives as Ie, createCommentVNode as Z, createBlock as $, unref as w, createElementVNode as Se, toDisplayString as Ue, isRef as Pe, vShow as Ee, resolveDynamicComponent as ce, withCtx as oe, renderList as ue, onMounted as Te, onBeforeUnmount as ke, resolveComponent as qe, mergeProps as ne, provide as We, useSlots as ze, useAttrs as Re, renderSlot as fe, normalizeProps as he, getCurrentInstance as He } from "vue";
2
+ import { useFieldArray as Ke, defineRule as I, validate as ye, useValidateField as Je, useField as ge, useSubmitCount as Me, FormContextKey as Oe, useForm as Xe, useFieldValue as Ge } from "vee-validate";
3
+ function Qe(e) {
4
+ const { fields: r, ...t } = Ke(e), n = u(() => r.value.map(({ value: a }) => a));
5
+ return {
6
+ fields: r,
7
+ values: n,
8
+ ...t
9
+ };
10
+ }
11
+ const ve = Symbol("dynamicFormSettings");
12
+ /**
13
+ * vee-validate v4.15.1
14
+ * (c) 2025 Abdelrahman Awad
15
+ * @license MIT
16
+ */
17
+ function se(e, r) {
18
+ return Array.isArray(e) ? e[0] : e[r];
19
+ }
20
+ function ee(e) {
21
+ return !!(e == null || e === "" || Array.isArray(e) && e.length === 0);
22
+ }
23
+ const Ne = (e, r) => {
24
+ if (ee(e))
25
+ return !0;
26
+ const t = se(r, "length");
27
+ return Array.isArray(e) ? e.every((n) => Ne(n, { length: t })) : [...String(e)].length <= Number(t);
28
+ }, $e = (e, r) => {
29
+ if (ee(e))
30
+ return !0;
31
+ const t = se(r, "max");
32
+ return Array.isArray(e) ? e.length > 0 && e.every((n) => $e(n, { max: t })) : Number(e) <= Number(t);
33
+ }, De = (e, r) => {
34
+ if (ee(e))
35
+ return !0;
36
+ const t = se(r, "length");
37
+ return Array.isArray(e) ? e.every((n) => De(n, { length: t })) : [...String(e)].length >= Number(t);
38
+ }, we = (e, r) => {
39
+ if (ee(e))
40
+ return !0;
41
+ const t = se(r, "min");
42
+ return Array.isArray(e) ? e.length > 0 && e.every((n) => we(n, { min: t })) : Number(e) >= Number(t);
43
+ }, Be = (e, r) => ee(e) ? !0 : Array.isArray(e) ? e.every((t) => Be(t, r)) : Array.from(r).some((t) => t == e), je = (e, r) => {
44
+ if (ee(e))
45
+ return !0;
46
+ let t = se(r, "regex");
47
+ return typeof t == "string" && (t = new RegExp(t)), Array.isArray(e) ? e.every((n) => je(n, { regex: t })) : t.test(String(e));
48
+ };
49
+ function W(e) {
50
+ return e == null ? !1 : Array.isArray(e) ? e.some((r) => W(r)) : typeof e == "object" ? Object.values(e).some((r) => W(r)) : !0;
51
+ }
52
+ function Ye(e, r, t) {
53
+ return typeof e == "function" ? e(r) : e.replace(/\{(\w+)\}/g, (n, a) => {
54
+ if (a in r)
55
+ return String(r[a]);
56
+ if (t && !Array.isArray(t) && a in t)
57
+ return String(t[a]);
58
+ const i = Number(a);
59
+ return Number.isNaN(i) ? r.rule?.params && !Array.isArray(r.rule.params) ? String(r.rule.params[a] ?? `{${a}}`) : `{${a}}` : Array.isArray(t) && t[i] !== void 0 ? String(t[i]) : String(r.rule?.params?.[i] ?? `{${a}}`);
60
+ });
61
+ }
62
+ I("xsd_required", (e) => e != null && e !== "");
63
+ I("xsd_minOccurs", (e, [r]) => Array.isArray(e) ? e.filter(W).length >= Number(r) : Number(r) <= 0);
64
+ I("xsd_choiceMinOccurs", () => !1);
65
+ I("xsd_minLength", De);
66
+ I("xsd_maxLength", Ne);
67
+ I("xsd_length", (e, [r]) => e == null || e === "" ? !0 : String(e).length === Number(r));
68
+ I("xsd_pattern", je);
69
+ I("xsd_minInclusive", we);
70
+ I("xsd_maxInclusive", $e);
71
+ I("xsd_minExclusive", (e, [r]) => e == null || e === "" ? !0 : Number(e) > Number(r));
72
+ I("xsd_maxExclusive", (e, [r]) => e == null || e === "" ? !0 : Number(e) < Number(r));
73
+ I("xsd_enumeration", Be);
74
+ I("xsd_whiteSpace", (e, [r]) => {
75
+ if (e == null || e === "")
76
+ return !0;
77
+ const t = String(e);
78
+ return r === "replace" ? !/[\t\n\r]/.test(t) : r === "collapse" ? t === t.trim() && !/\s{2,}/.test(t) : !0;
79
+ });
80
+ I("xsd_fractionDigits", (e, [r]) => {
81
+ if (e == null || e === "")
82
+ return !0;
83
+ const t = String(e).indexOf(".");
84
+ return t === -1 ? !0 : String(e).length - t - 1 <= Number(r);
85
+ });
86
+ I("xsd_totalDigits", (e, [r]) => e == null || e === "" ? !0 : (String(e).replace(/^-/, "").replace(".", "").replace(/^0+/, "") || "0").length <= Number(r));
87
+ const Ze = {
88
+ xsd_minOccurs: "min",
89
+ xsd_choiceMinOccurs: "min",
90
+ xsd_minLength: "length",
91
+ xsd_maxLength: "length",
92
+ xsd_length: "length",
93
+ xsd_pattern: "pattern",
94
+ xsd_minInclusive: "min",
95
+ xsd_maxInclusive: "max",
96
+ xsd_minExclusive: "min",
97
+ xsd_maxExclusive: "max",
98
+ xsd_whiteSpace: "mode",
99
+ xsd_fractionDigits: "digits",
100
+ xsd_totalDigits: "digits"
101
+ };
102
+ function xe(e) {
103
+ return e.label ?? e.field ?? e.name ?? "";
104
+ }
105
+ function _(e, r, t) {
106
+ const n = Ze[e], a = r !== void 0 ? { 0: r, ...n ? { [n]: r } : {} } : {};
107
+ return async (i, c) => {
108
+ const o = xe(c), h = o ? { name: o } : void 0, m = o && c.field !== o ? { ...c, field: o } : c, F = await ye(
109
+ i,
110
+ r !== void 0 ? { [e]: r } : e,
111
+ h
112
+ );
113
+ return F.valid ? !0 : t ? Ye(t, m, a) : F.errors[0];
114
+ };
115
+ }
116
+ function Ae(e) {
117
+ return e?.replaceAll(/\[[`'"](.*?)[`'"]\]/g, ".$1") ?? "";
118
+ }
119
+ function be(e, r) {
120
+ if (!e || !r)
121
+ return e;
122
+ const t = r.split(".") ?? [], n = e.split(".") ?? [];
123
+ for (let a = 0; a < t.length; a++)
124
+ n[a] = t[a];
125
+ return n.join(".");
126
+ }
127
+ function Ce(e) {
128
+ return e ? typeof e == "function" ? [e] : Array.isArray(e) ? e.flatMap(Ce) : typeof e == "string" ? e.split("|").map((r) => async (t, n) => {
129
+ const a = xe(n), i = await ye(t, r, a ? { name: a } : void 0);
130
+ return i.valid ? !0 : i.errors[0];
131
+ }) : Object.entries(e).map(([r, t]) => async (n, a) => {
132
+ const i = xe(a), c = await ye(n, { [r]: t }, i ? { name: i } : void 0);
133
+ return c.valid ? !0 : c.errors[0];
134
+ }) : [];
135
+ }
136
+ const et = { key: 0 }, tt = ["data-testid"], rt = /* @__PURE__ */ le({
137
+ __name: "DynamicFormItemArray",
138
+ props: {
139
+ template: { type: [Object, Function] },
140
+ fieldMetadata: {},
141
+ pathOverride: {},
142
+ minOccursOverride: {},
143
+ maxOccursOverride: {},
144
+ partOfArrayField: { type: Boolean },
145
+ partOfChoiceField: { type: Boolean },
146
+ isArrayOverride: {},
147
+ index: {},
148
+ canAddItems: { type: Boolean },
149
+ canRemoveItems: { type: Boolean },
150
+ addItem: { type: Function },
151
+ removeItem: { type: Function },
152
+ slotProps: {}
153
+ },
154
+ emits: ["update:modelValue", "update:computedField"],
155
+ setup(e, { emit: r }) {
156
+ const t = e, n = r, a = me(ve);
157
+ let i = 0;
158
+ const c = u(() => t.fieldMetadata), o = u(() => c.value?.path ? be(c.value.path, t.pathOverride) : ""), h = u(() => Ae(o.value)), m = Je(h), { remove: F, push: S, fields: g, update: P, values: U, replace: E } = Qe(h), A = u(
159
+ () => t.minOccursOverride !== void 0 ? t.minOccursOverride : c.value?.minOccurs ?? 1
160
+ ), y = u(
161
+ () => t.maxOccursOverride !== void 0 ? t.maxOccursOverride : c.value?.maxOccurs ?? 1
162
+ ), k = u(() => y.value === 0), G = u(() => A.value >= 1 && !k.value), R = u(
163
+ () => y.value === 0 ? 0 : 1
164
+ ), H = u(() => y.value > g.value?.length), K = u(() => t.partOfChoiceField || c.value?.autoAddMinOccurs === !1 ? g.value?.length > 0 : g.value?.length > A.value && g.value?.length > 1), Q = u(() => {
165
+ const b = [], M = a?.value?.messages;
166
+ return G.value && b.push(_("xsd_minOccurs", A.value, M?.minOccurs)), c.value?.validation && b.push(...Ce(c.value?.validation)), b;
167
+ }), { label: q, errors: v, errorMessage: O, handleBlur: p } = ge(h, Q, {
168
+ ...c.value?.fieldOptions ?? {},
169
+ validateOnValueUpdate: !1
170
+ // validation timing is owned by this component
171
+ }), f = { label: q, errors: v, errorMessage: O, value: U }, d = Me(), V = X(!1), N = u(() => {
172
+ if (!V.value)
173
+ return;
174
+ const b = a?.value?.validateOnValueUpdateAfterSubmit === !0 ? d.value > 0 && a?.value?.validateOnValueUpdateAfterSubmit : void 0, M = a?.value?.validateWhenInError && f?.errors.value?.length > 0 ? !0 : void 0;
175
+ return c.value?.fieldOptions?.validateOnValueUpdate ?? M ?? b ?? a?.value?.validateOnValueUpdate;
176
+ });
177
+ ie(
178
+ U,
179
+ (b) => {
180
+ N.value && m(), n("update:modelValue", b);
181
+ },
182
+ { immediate: !0 }
183
+ ), _e(() => {
184
+ t.partOfChoiceField || c.value?.autoAddMinOccurs !== !1 && (g.value?.length < 1 || g.value?.length < A.value) && j();
185
+ });
186
+ function j() {
187
+ S(null), n("update:modelValue", U.value);
188
+ }
189
+ function J(b) {
190
+ K.value ? F(b ?? g.value.length - 1) : E(U.value?.map((M, te) => te === b ? null : M)), n("update:modelValue", U.value);
191
+ }
192
+ function D(b, M) {
193
+ V.value || (V.value = !0, N.value && m()), b === void 0 && M >= 0 && P(M, void 0), n("update:modelValue", U.value);
194
+ }
195
+ return (b, M) => (x(), B(z, null, [
196
+ w(a)?.analytics ? Ie((x(), B("div", et, [
197
+ Se("span", {
198
+ "data-testid": `${o.value}-analytics-render-count`
199
+ }, Ue(Pe(i) ? ++i.value : ++i), 9, tt)
200
+ ], 512)), [
201
+ [Ee, !1]
202
+ ]) : Z("", !0),
203
+ (x(), $(ce(e.template), {
204
+ type: `${e.fieldMetadata.type}-array`,
205
+ "field-metadata": e.fieldMetadata,
206
+ "field-context": f,
207
+ "slot-props": e.slotProps,
208
+ settings: w(a),
209
+ required: G.value,
210
+ disabled: k.value,
211
+ index: e.index,
212
+ "can-add-items": H.value,
213
+ "can-remove-items": K.value,
214
+ "add-item": j,
215
+ "remove-item": J
216
+ }, {
217
+ default: oe((te) => [
218
+ (x(!0), B(z, null, ue(w(g) ?? [], ({ key: re }, L) => (x(), $(de, {
219
+ key: re,
220
+ "field-metadata": e.fieldMetadata,
221
+ "path-override": `${o.value}[${L}]`,
222
+ index: L,
223
+ template: e.template,
224
+ "slot-props": te,
225
+ "max-occurs-override": R.value,
226
+ "can-add-items": H.value,
227
+ "can-remove-items": K.value,
228
+ "add-item": j,
229
+ "remove-item": () => J(L),
230
+ "part-of-array-field": "",
231
+ "is-array-override": "single",
232
+ "onUpdate:modelValue": (T) => D(T, L),
233
+ "onUpdate:computedField": M[0] || (M[0] = (T) => n("update:computedField", T)),
234
+ onBlur: w(p)
235
+ }, null, 8, ["field-metadata", "path-override", "index", "template", "slot-props", "max-occurs-override", "can-add-items", "can-remove-items", "remove-item", "onUpdate:modelValue", "onBlur"]))), 128))
236
+ ]),
237
+ _: 1
238
+ }, 8, ["type", "field-metadata", "slot-props", "settings", "required", "disabled", "index", "can-add-items", "can-remove-items"]))
239
+ ], 64));
240
+ }
241
+ }), at = /* @__PURE__ */ le({
242
+ __name: "DynamicFormItemChoice",
243
+ props: {
244
+ template: { type: [Object, Function] },
245
+ fieldMetadata: {},
246
+ pathOverride: {},
247
+ minOccursOverride: {},
248
+ maxOccursOverride: {},
249
+ partOfArrayField: { type: Boolean },
250
+ partOfChoiceField: { type: Boolean },
251
+ isArrayOverride: {},
252
+ index: {},
253
+ canAddItems: { type: Boolean },
254
+ canRemoveItems: { type: Boolean },
255
+ addItem: { type: Function },
256
+ removeItem: { type: Function },
257
+ slotProps: {}
258
+ },
259
+ emits: ["update:modelValue", "update:computedField"],
260
+ setup(e, { emit: r }) {
261
+ const t = e, n = r, a = me(ve), i = u(() => t.fieldMetadata), c = u(() => be(i.value.path ?? "", t.pathOverride)), o = u(() => Ae(c.value)), h = u(
262
+ () => t.minOccursOverride !== void 0 ? t.minOccursOverride : i.value?.minOccurs ?? 1
263
+ ), m = u(
264
+ () => t.maxOccursOverride !== void 0 ? t.maxOccursOverride : i.value?.maxOccurs ?? 1
265
+ ), F = u(() => m.value === 0), S = u(() => h.value >= 1 && !F.value), g = u(
266
+ () => h.value === 0 ? 0 : void 0
267
+ ), P = u(
268
+ () => m.value === 0 ? 0 : void 0
269
+ ), U = u(() => i.value?.maxOccurs > 1 ? "array" : void 0), E = X({}), A = u(() => Object.values(E.value).map((v) => v.value)), y = u(
270
+ () => i.value?.choice?.length === 1 ? i.value?.choice[0] : void 0
271
+ ), k = u(() => {
272
+ const v = {};
273
+ i.value?.choice?.forEach((f, d) => {
274
+ v[d] = {
275
+ childValuesCount: 0,
276
+ childOccurrences: 0,
277
+ childMaxOccurrences: 1,
278
+ choiceValuesCount: 0,
279
+ choiceOccurrences: 0,
280
+ overrideChildMaxOccurrences: void 0,
281
+ overrideChildMinOccurrences: 0
282
+ // children are optional by default inside a choice
283
+ };
284
+ });
285
+ const O = m.value ?? 1;
286
+ if (O === 0)
287
+ return i.value?.choice?.forEach((f, d) => {
288
+ v[d].overrideChildMaxOccurrences = 0, v[d].overrideChildMinOccurrences = 0;
289
+ }), v;
290
+ for (const [f, d] of Object.entries(E.value ?? {})) {
291
+ let V = Math.ceil(d.occurrences / d.maxOccurrences);
292
+ const N = Math.ceil(d.valuesCount / d.maxOccurrences);
293
+ O * d.maxOccurrences === 1 && (V = N), v[f] = {
294
+ childValuesCount: d.valuesCount,
295
+ childOccurrences: d.occurrences,
296
+ childMaxOccurrences: d.maxOccurrences,
297
+ choiceOccurrences: V,
298
+ choiceValuesCount: N,
299
+ overrideChildMinOccurrences: d.valuesCount === 0 ? 0 : void 0,
300
+ // optional when empty
301
+ overrideChildMaxOccurrences: void 0
302
+ // calculated in pass 2
303
+ };
304
+ }
305
+ const p = Object.values(v).reduce(
306
+ (f, d) => f + d.choiceOccurrences,
307
+ 0
308
+ );
309
+ return Object.values(v).forEach((f) => {
310
+ const V = (p - f.choiceOccurrences) * f.childMaxOccurrences, N = O * f.childMaxOccurrences;
311
+ f.overrideChildMaxOccurrences = N - V;
312
+ }), v;
313
+ }), G = u(
314
+ () => Object.values(k.value).reduce(
315
+ (v, O) => v + O.choiceValuesCount,
316
+ 0
317
+ )
318
+ ), R = u(() => {
319
+ if (y.value || F.value || G.value >= h.value)
320
+ return;
321
+ const v = a?.value?.messages;
322
+ return [_("xsd_choiceMinOccurs", h.value, v?.choiceMinOccurs)];
323
+ }), { errors: H, errorMessage: K } = ge(o, R, i.value?.fieldOptions), Q = { label: i.value?.fieldOptions?.label, errors: H, errorMessage: K, value: A };
324
+ ie(i, (v) => {
325
+ v && v.choice?.forEach((O, p) => {
326
+ p in E.value || q(void 0, p, O.maxOccurs);
327
+ });
328
+ }, { immediate: !0 });
329
+ function q(v, O, p = 1, f = !1) {
330
+ if (f) {
331
+ n("update:modelValue", A.value);
332
+ return;
333
+ }
334
+ if (O === void 0)
335
+ return;
336
+ let d = Array.isArray(v) ? v : [v];
337
+ (m.value ?? 1) * p === 1 && (d = d.filter((b) => b !== void 0));
338
+ const j = d.length, J = d.filter((b) => W(b)).length, D = E.value[O] ?? {};
339
+ D.value = v, D.occurrences = j, D.valuesCount = J, D.maxOccurrences = p, E.value[O] || (E.value[O] = D), n("update:modelValue", A.value);
340
+ }
341
+ return (v, O) => (x(), $(ce(e.template), {
342
+ type: `${e.fieldMetadata.type}-choice`,
343
+ "field-metadata": e.fieldMetadata,
344
+ "field-context": Q,
345
+ "slot-props": e.slotProps,
346
+ settings: w(a),
347
+ required: S.value,
348
+ index: e.index,
349
+ disabled: F.value,
350
+ "can-add-items": e.canAddItems,
351
+ "can-remove-items": e.canRemoveItems,
352
+ "add-item": e.addItem,
353
+ "remove-item": e.removeItem
354
+ }, {
355
+ default: oe((p) => [
356
+ y.value ? (x(), $(de, {
357
+ key: 0,
358
+ "field-metadata": y.value,
359
+ "path-override": e.pathOverride,
360
+ template: e.template,
361
+ "slot-props": p,
362
+ "min-occurs-override": g.value,
363
+ "max-occurs-override": P.value,
364
+ "part-of-choice-field": "",
365
+ "onUpdate:modelValue": O[0] || (O[0] = (f) => q(f, 0, y.value.maxOccurs, !0)),
366
+ "onUpdate:computedField": O[1] || (O[1] = (f) => n("update:computedField", f))
367
+ }, null, 8, ["field-metadata", "path-override", "template", "slot-props", "min-occurs-override", "max-occurs-override"])) : (x(!0), B(z, { key: 1 }, ue(i.value.choice, (f, d) => (x(), $(de, {
368
+ key: f.name,
369
+ "field-metadata": f,
370
+ "path-override": e.pathOverride,
371
+ index: d,
372
+ template: e.template,
373
+ "slot-props": p,
374
+ "min-occurs-override": k.value[d]?.overrideChildMinOccurrences,
375
+ "max-occurs-override": k.value[d]?.overrideChildMaxOccurrences,
376
+ "is-array-override": U.value,
377
+ "part-of-choice-field": "",
378
+ "onUpdate:modelValue": (V) => q(V, d, f.maxOccurs),
379
+ "onUpdate:computedField": O[2] || (O[2] = (V) => n("update:computedField", V))
380
+ }, null, 8, ["field-metadata", "path-override", "index", "template", "slot-props", "min-occurs-override", "max-occurs-override", "is-array-override", "onUpdate:modelValue"]))), 128))
381
+ ]),
382
+ _: 1
383
+ }, 8, ["type", "field-metadata", "slot-props", "settings", "required", "index", "disabled", "can-add-items", "can-remove-items", "add-item", "remove-item"]));
384
+ }
385
+ });
386
+ function it(e) {
387
+ const {
388
+ name: r,
389
+ path: t,
390
+ children: n,
391
+ choice: a,
392
+ attributes: i,
393
+ fieldOptions: c,
394
+ computedProps: o,
395
+ maxOccurs: h,
396
+ _hash: m,
397
+ parent: F,
398
+ isComplexType: S,
399
+ computeOnChildValueChange: g,
400
+ ...P
401
+ } = e, U = Object.fromEntries(
402
+ Object.entries(P).sort(([E], [A]) => E.localeCompare(A))
403
+ );
404
+ return JSON.stringify(U);
405
+ }
406
+ const nt = { key: 0 }, ut = ["data-testid"], Fe = 10, de = /* @__PURE__ */ le({
407
+ __name: "DynamicFormItem",
408
+ props: {
409
+ template: { type: [Object, Function] },
410
+ fieldMetadata: {},
411
+ pathOverride: {},
412
+ minOccursOverride: {},
413
+ maxOccursOverride: {},
414
+ partOfArrayField: { type: Boolean },
415
+ partOfChoiceField: { type: Boolean },
416
+ isArrayOverride: {},
417
+ index: {},
418
+ canAddItems: { type: Boolean },
419
+ canRemoveItems: { type: Boolean },
420
+ addItem: { type: Function },
421
+ removeItem: { type: Function },
422
+ slotProps: {}
423
+ },
424
+ emits: ["update:modelValue", "blur", "update:computedField"],
425
+ setup(e, { emit: r }) {
426
+ const t = e, n = r, a = me(ve);
427
+ let i = 0, c = 0, o;
428
+ function h(l) {
429
+ if (c++, o == null && (o = setTimeout(() => {
430
+ c = 0, o = void 0;
431
+ }, 0)), c > Fe)
432
+ throw new Error(
433
+ `[DynamicFormItem] Possible infinite loop detected in computedProps for field "${l}". computedProps recomputed more than ${Fe} times synchronously. Ensure value writes inside computedProps are idempotent (the same input always produces the same output).`
434
+ );
435
+ }
436
+ const m = u(() => t.fieldMetadata), F = u(() => m.value?.path ? be(m.value.path, t.pathOverride) : ""), S = u(() => m.value?.isComplexType || m.value?.attributes?.length), g = u(() => {
437
+ let l = F.value;
438
+ if (S.value && l) {
439
+ const s = a?.value?.complexTypeValueProperty ?? "value";
440
+ l = `${l}['${s}']`;
441
+ }
442
+ return l;
443
+ }), P = u(() => Ae(g.value)), U = u(() => t.isArrayOverride === "array" ? !0 : t.isArrayOverride === "single" ? !1 : (m.value?.maxOccurs ?? 1) > 1), E = X([]), A = U.value ? { value: X(void 0) } : ge(P, E, {
444
+ ...m.value?.fieldOptions ?? {},
445
+ validateOnValueUpdate: !1
446
+ // validation timing is owned by this component
447
+ }), y = A.value;
448
+ A.hasValue = u(() => W(y.value));
449
+ const k = A.handleBlur;
450
+ A.handleBlur = function(l, s) {
451
+ s = s ?? a?.value?.validateOnBlur, k(l, s), n("blur", l, s);
452
+ };
453
+ const G = A.handleChange;
454
+ A.handleChange = function(l, s) {
455
+ G(l, s === !0);
456
+ };
457
+ const R = u(() => !!m.value?.children?.length), H = u(() => !!m.value?.choice?.length), K = u(() => !U.value && !H.value && !R.value), Q = X(!0), q = X(0), v = X({}), O = u(() => Object.values(v.value)), p = u(() => {
458
+ h(F.value), m.value?.computeOnChildValueChange === !0 && q.value;
459
+ const s = (m.value?.computedProps ?? []).reduce(
460
+ (C, Y) => (Y(C, y, O), C),
461
+ { ...m.value, path: F.value }
462
+ );
463
+ return s.path = F.value, s._hash = it(s), s;
464
+ }), f = u(() => t.minOccursOverride !== void 0 ? t.minOccursOverride : t.partOfArrayField ? 0 : p.value?.minOccurs ?? 1), d = u(
465
+ () => t.maxOccursOverride !== void 0 ? t.maxOccursOverride : p.value?.maxOccurs ?? 1
466
+ ), V = u(() => d.value === 0), N = u(() => f.value >= 1 && !V.value), j = u(() => {
467
+ if (t.minOccursOverride === 0)
468
+ return t.minOccursOverride;
469
+ if (!(f.value > 0) && !W(y.value))
470
+ return 0;
471
+ }), J = u(
472
+ () => d.value === 0 ? 0 : void 0
473
+ ), D = u(() => t.partOfArrayField && W(y.value) ? !0 : t.canRemoveItems), b = Me(), M = u(() => {
474
+ const l = a?.value?.validateOnValueUpdateAfterSubmit === !0 ? b.value > 0 && a?.value?.validateOnValueUpdateAfterSubmit : void 0, s = a?.value?.validateWhenInError && A?.errors.value?.length > 0 ? !0 : void 0;
475
+ return m.value?.fieldOptions?.validateOnValueUpdate ?? s ?? l ?? a?.value?.validateOnValueUpdate;
476
+ }), te = u(
477
+ () => m.value?.attributes?.length && W(y.value)
478
+ );
479
+ _e(() => {
480
+ const l = [], s = m.value.restriction ?? {}, C = a?.value?.messages;
481
+ N.value && l.push(_("xsd_required", void 0, C?.required)), s.minLength != null && l.push(_("xsd_minLength", s.minLength, C?.minLength)), s.maxLength != null && l.push(_("xsd_maxLength", s.maxLength, C?.maxLength)), s.length != null && l.push(_("xsd_length", s.length, C?.length)), s.pattern != null && l.push(_("xsd_pattern", s.pattern, C?.pattern)), s.minInclusive != null && l.push(_("xsd_minInclusive", s.minInclusive, C?.minInclusive)), s.maxInclusive != null && l.push(_("xsd_maxInclusive", s.maxInclusive, C?.maxInclusive)), s.minExclusive != null && l.push(_("xsd_minExclusive", s.minExclusive, C?.minExclusive)), s.maxExclusive != null && l.push(_("xsd_maxExclusive", s.maxExclusive, C?.maxExclusive)), s.enumeration != null && l.push(_("xsd_enumeration", s.enumeration, C?.enumeration)), s.whiteSpace != null && l.push(_("xsd_whiteSpace", s.whiteSpace, C?.whiteSpace)), s.fractionDigits != null && l.push(_("xsd_fractionDigits", s.fractionDigits, C?.fractionDigits)), s.totalDigits != null && l.push(_("xsd_totalDigits", s.totalDigits, C?.totalDigits)), m.value?.validation && l.push(...Ce(m.value?.validation)), E.value = l;
482
+ });
483
+ let re = !1;
484
+ ie(y, (l) => {
485
+ re || (re = !0, l === "" && (y.value = t.partOfArrayField ? null : void 0), re = !1);
486
+ }, {
487
+ flush: "sync"
488
+ }), ie(
489
+ y,
490
+ (l) => {
491
+ K.value && ((!Q.value || l) && (T(), M.value && A?.validate()), Q.value = !1);
492
+ },
493
+ {
494
+ immediate: !0
495
+ }
496
+ ), Te(() => {
497
+ n("update:computedField", p.value), ie(() => p.value._hash, (l, s) => {
498
+ l !== s && n("update:computedField", p.value);
499
+ });
500
+ }), ke(() => {
501
+ o != null && clearTimeout(o), !t.partOfArrayField && y.value !== void 0 && (y.value = void 0, T());
502
+ });
503
+ function L(l) {
504
+ !l.path || v.value[l.path]?._hash === l._hash || (v.value[l.path] = l);
505
+ }
506
+ function T() {
507
+ q.value++, n("update:modelValue", y.value);
508
+ }
509
+ function Le(l) {
510
+ y.value = l, n("update:modelValue", y.value);
511
+ }
512
+ return (l, s) => {
513
+ const C = qe("DynamicFormItem", !0);
514
+ return x(), B(z, null, [
515
+ w(a)?.analytics ? Ie((x(), B("div", nt, [
516
+ Se("span", {
517
+ "data-testid": `${F.value}-analytics-render-count`
518
+ }, Ue(Pe(i) ? ++i.value : ++i), 9, ut)
519
+ ], 512)), [
520
+ [Ee, !1]
521
+ ]) : Z("", !0),
522
+ H.value ? (x(), $(at, ne({ key: 1 }, t, {
523
+ "field-metadata": p.value,
524
+ "onUpdate:modelValue": T,
525
+ "onUpdate:computedField": L
526
+ }), null, 16, ["field-metadata"])) : U.value ? (x(), $(rt, ne({ key: 2 }, t, {
527
+ "part-of-choice-field": e.partOfChoiceField,
528
+ "field-metadata": p.value,
529
+ "onUpdate:modelValue": Le,
530
+ "onUpdate:computedField": L
531
+ }), null, 16, ["part-of-choice-field", "field-metadata"])) : (x(), $(ce(e.template), {
532
+ key: 3,
533
+ type: e.partOfArrayField ? `${p.value.type}-array-item` : p.value.type,
534
+ "field-metadata": p.value,
535
+ "field-context": w(A),
536
+ "slot-props": e.slotProps,
537
+ settings: w(a),
538
+ required: N.value,
539
+ disabled: V.value,
540
+ index: e.index,
541
+ "can-add-items": e.canAddItems,
542
+ "can-remove-items": D.value,
543
+ "add-item": e.addItem,
544
+ "remove-item": e.removeItem
545
+ }, {
546
+ default: oe((Y) => [
547
+ R.value ? (x(!0), B(z, { key: 0 }, ue(p.value.children, (ae, pe) => (x(), $(C, {
548
+ key: ae.path,
549
+ "field-metadata": ae,
550
+ "path-override": g.value,
551
+ index: pe,
552
+ template: e.template,
553
+ "slot-props": Y,
554
+ "min-occurs-override": j.value,
555
+ "max-occurs-override": J.value,
556
+ "onUpdate:modelValue": T,
557
+ "onUpdate:computedField": L
558
+ }, null, 8, ["field-metadata", "path-override", "index", "template", "slot-props", "min-occurs-override", "max-occurs-override"]))), 128)) : Z("", !0),
559
+ R.value ? Z("", !0) : (x(), $(ce(e.template), {
560
+ key: 1,
561
+ type: `${p.value.type}-input`,
562
+ "field-metadata": p.value,
563
+ "field-context": w(A),
564
+ "slot-props": Y,
565
+ settings: w(a),
566
+ required: N.value,
567
+ disabled: V.value,
568
+ index: e.index,
569
+ "can-add-items": e.canAddItems,
570
+ "can-remove-items": D.value,
571
+ "add-item": e.addItem,
572
+ "remove-item": e.removeItem
573
+ }, null, 8, ["type", "field-metadata", "field-context", "slot-props", "settings", "required", "disabled", "index", "can-add-items", "can-remove-items", "add-item", "remove-item"]))
574
+ ]),
575
+ attributes: oe((Y) => [
576
+ te.value ? (x(!0), B(z, { key: 0 }, ue(p.value.attributes, (ae, pe) => (x(), $(C, {
577
+ key: ae.path,
578
+ "field-metadata": ae,
579
+ "path-override": F.value,
580
+ index: pe,
581
+ template: e.template,
582
+ "slot-props": Y,
583
+ "min-occurs-override": j.value,
584
+ "max-occurs-override": J.value,
585
+ "onUpdate:modelValue": T,
586
+ "onUpdate:computedField": L
587
+ }, null, 8, ["field-metadata", "path-override", "index", "template", "slot-props", "min-occurs-override", "max-occurs-override"]))), 128)) : Z("", !0)
588
+ ]),
589
+ _: 1
590
+ }, 8, ["type", "field-metadata", "field-context", "slot-props", "settings", "required", "disabled", "index", "can-add-items", "can-remove-items", "add-item", "remove-item"]))
591
+ ], 64);
592
+ };
593
+ }
594
+ }), pt = /* @__PURE__ */ le({
595
+ name: "DynamicForm",
596
+ inheritAttrs: !1,
597
+ __name: "DynamicForm",
598
+ props: {
599
+ metadata: {},
600
+ template: { type: [Object, Function] },
601
+ settings: {}
602
+ },
603
+ setup(e) {
604
+ const r = u(() => ({
605
+ validateOnValueUpdate: !0,
606
+ validateWhenInError: !0,
607
+ ...e.settings ?? {}
608
+ }));
609
+ We(ve, r);
610
+ const t = u(
611
+ () => Array.isArray(e.metadata) ? e.metadata : [e.metadata]
612
+ ), n = u(
613
+ () => t.value?.map((c, o) => i(c, o)) ?? []
614
+ ), a = u(
615
+ () => e.template
616
+ );
617
+ function i(c, o, h) {
618
+ if (!c)
619
+ return c;
620
+ const m = c.name ?? `field-${o}`, F = c.path ?? [h?.path, m].filter(Boolean).join("."), S = {
621
+ name: m,
622
+ path: F,
623
+ type: "text",
624
+ minOccurs: 1,
625
+ maxOccurs: 1,
626
+ ...c,
627
+ computedProps: [...c.computedProps ?? []],
628
+ parent: h
629
+ };
630
+ return S.children = (c.children ?? []).map(
631
+ (g, P) => i(g, P, S)
632
+ ), S.choice = (c.choice ?? []).map(
633
+ (g, P) => i(g, P, S)
634
+ ), S.attributes = (c.attributes ?? []).map(
635
+ (g, P) => i(g, P, S)
636
+ ), S;
637
+ }
638
+ return (c, o) => (x(!0), B(z, null, ue(n.value, (h) => (x(), $(de, {
639
+ key: h.name,
640
+ template: a.value,
641
+ "field-metadata": h
642
+ }, null, 8, ["template", "field-metadata"]))), 128));
643
+ }
644
+ }), lt = /-\w/g, st = ct(
645
+ (e) => e.replace(lt, (r) => r.slice(1).toUpperCase())
646
+ );
647
+ function ct(e) {
648
+ const r = /* @__PURE__ */ Object.create(null);
649
+ return ((t) => r[t] || (r[t] = e(t)));
650
+ }
651
+ const ft = /* @__PURE__ */ le({
652
+ name: "DynamicFormTemplate",
653
+ inheritAttrs: !1,
654
+ __name: "DynamicFormTemplate",
655
+ props: {
656
+ metadataConfiguration: {}
657
+ },
658
+ setup(e) {
659
+ const r = ze(), t = Re(), n = u(() => {
660
+ const i = {};
661
+ for (const [c, o] of Object.entries(t))
662
+ i[st(c)] = o;
663
+ return i;
664
+ }), a = u(() => {
665
+ const i = n.value.type;
666
+ return i && r[i] ? i : i?.endsWith("-input") ? r["default-input"] ? "default-input" : "default" : i?.endsWith("-array") ? r["default-array"] ? "default-array" : "default" : i?.endsWith("-array-item") ? r["default-array-item"] ? "default-array-item" : "default" : i?.endsWith("-choice") && r["default-choice"] ? "default-choice" : "default";
667
+ });
668
+ return (i, c) => n.value.fieldMetadata ? (x(), B(z, { key: 0 }, [
669
+ n.value.type?.endsWith("-array") ? fe(i.$slots, a.value, he(ne({ key: 0 }, n.value))) : n.value.type?.endsWith("-choice") ? fe(i.$slots, a.value, he(ne({ key: 1 }, n.value))) : fe(i.$slots, a.value, he(ne({ key: 2 }, n.value)))
670
+ ], 64)) : Z("", !0);
671
+ }
672
+ });
673
+ function ht() {
674
+ return {
675
+ fieldTypes: Object.keys({}),
676
+ extendedProperties: {},
677
+ slotProperties: {},
678
+ extendedSettingsProperties: {},
679
+ valueTypes: {}
680
+ };
681
+ }
682
+ function ot() {
683
+ const r = He()?.provides;
684
+ return r && Oe in r ? r[Oe] : me(Oe);
685
+ }
686
+ function dt() {
687
+ const e = ot();
688
+ async function r(t) {
689
+ const n = e.getAllPathStates().map((o) => o.path).filter((o) => o === t || o.startsWith(`${t}.`) || o.startsWith(`${t}[`)), a = await Promise.all(
690
+ n.map(async (o) => ({
691
+ path: o,
692
+ result: await e.validateField(o)
693
+ }))
694
+ ), i = Object.fromEntries(
695
+ a.map(({ path: o, result: h }) => [o, h])
696
+ ), c = Object.fromEntries(
697
+ a.filter(({ result: o }) => !o.valid).map(({ path: o, result: h }) => [o, h.errors[0] ?? ""])
698
+ );
699
+ return {
700
+ valid: a.every(({ result: o }) => o.valid),
701
+ results: i,
702
+ errors: c,
703
+ source: "fields"
704
+ };
705
+ }
706
+ return { validateSection: r };
707
+ }
708
+ function Ot(e) {
709
+ const r = (a) => Ge(a), t = Xe(e), { validateSection: n } = dt();
710
+ return {
711
+ ...t,
712
+ useFieldValue: r,
713
+ validateSection: n
714
+ };
715
+ }
716
+ function Ve(e, r) {
717
+ return !e || !r || (e = r?.({ ...e }), e.children = e?.children?.map((t) => Ve(t, r)), e.choice = e?.choice?.map((t) => Ve(t, r))), e;
718
+ }
719
+ export {
720
+ pt as _,
721
+ de as a,
722
+ rt as b,
723
+ at as c,
724
+ ft as d,
725
+ ht as e,
726
+ dt as f,
727
+ ve as g,
728
+ W as h,
729
+ Ve as m,
730
+ Ot as u
731
+ };
732
+ //# sourceMappingURL=mapEachMetadataItem-B4xJvJDj.js.map