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