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