@bach.software/vue-dynamic-form 0.1.3 → 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.
- package/README.md +203 -7
- package/dist/examples.cjs.js +12 -0
- package/dist/examples.cjs.js.map +1 -0
- package/dist/examples.es.js +612 -0
- package/dist/examples.es.js.map +1 -0
- package/dist/src/components/DynamicForm.vue.d.ts +2 -0
- package/dist/src/components/DynamicFormItem.vue.d.ts +11 -2
- package/dist/src/components/DynamicFormItemArray.vue.d.ts +9 -2
- package/dist/src/components/DynamicFormItemChoice.vue.d.ts +9 -2
- package/dist/src/components/DynamicFormTemplate.vue.d.ts +72 -21
- package/dist/src/components/__tests__/DynamicFormItem.analytics.test.d.ts +1 -0
- package/dist/src/components/__tests__/DynamicFormItem.logic.test.d.ts +1 -0
- package/dist/src/components/__tests__/DynamicFormItem.test-helpers.d.ts +21 -0
- package/dist/src/components/__tests__/DynamicFormItem.validation.test.d.ts +1 -0
- package/dist/src/components/__tests__/DynamicFormItemArray.logic.test.d.ts +1 -0
- package/dist/src/components/__tests__/DynamicFormItemArray.validation.test.d.ts +1 -0
- package/dist/src/components/__tests__/DynamicFormItemChoice.logic.test.d.ts +1 -0
- package/dist/src/components/__tests__/DynamicFormItemChoice.validation.test.d.ts +1 -0
- package/dist/src/core/__tests__/useValidatePartialForm.test.d.ts +1 -0
- package/dist/src/core/__tests__/validation.test.d.ts +1 -0
- package/dist/src/core/defineMetadata.d.ts +32 -7
- package/dist/src/core/useDynamicForm.d.ts +16 -0
- package/dist/src/core/useFieldArrayExtended.d.ts +16 -0
- package/dist/src/core/useValidatePartialForm.d.ts +4 -0
- package/dist/src/core/validation.d.ts +7 -0
- package/dist/src/examples/TestForm.vue.d.ts +13 -0
- package/dist/src/examples/TestFormTemplate.vue.d.ts +76 -0
- package/dist/src/examples/__tests__/DynamicForm.test.d.ts +1 -0
- package/dist/src/examples/__tests__/TestFormTemplate.testcases.d.ts +14 -0
- package/dist/src/examples/components/IconButton.vue.d.ts +10 -0
- package/dist/src/examples/index.d.ts +3 -0
- package/dist/src/index.d.ts +6 -0
- package/dist/src/tests/test-setup.d.ts +1 -0
- package/dist/src/types/DynamicFormItemProps.d.ts +56 -1
- package/dist/src/types/DynamicFormSettings.d.ts +89 -0
- package/dist/src/types/FieldMetadata.d.ts +109 -17
- package/dist/src/types/InternalFieldMetadata.d.ts +9 -3
- package/dist/src/types/KeyValue.d.ts +3 -0
- package/dist/src/types/MetadataConfiguration.d.ts +2 -0
- package/dist/src/types/ValidationMessage.d.ts +3 -0
- package/dist/src/utils/__tests__/checkTreeHasValue.test.d.ts +1 -0
- package/dist/src/utils/__tests__/createValidation.test.d.ts +1 -0
- package/dist/src/utils/__tests__/mapEachMetadataItem.test.d.ts +16 -0
- package/dist/src/utils/__tests__/normalizePath.test.d.ts +1 -0
- package/dist/src/utils/__tests__/overridePath.test.d.ts +1 -0
- package/dist/src/utils/__tests__/resolveMessage.test.d.ts +1 -0
- package/dist/src/utils/__tests__/setInPath.test.d.ts +1 -0
- package/dist/src/utils/__tests__/splitValidationFunctions.test.d.ts +1 -0
- package/dist/src/utils/camelize.d.ts +5 -0
- package/dist/src/utils/checkTreeHasValue.d.ts +9 -0
- package/dist/src/utils/createValidation.d.ts +12 -0
- package/dist/src/utils/getFieldLabel.d.ts +16 -0
- package/dist/src/utils/hashField.d.ts +7 -0
- package/dist/src/utils/mapEachMetadataItem.d.ts +10 -0
- package/dist/src/utils/normalizePath.d.ts +15 -0
- package/dist/src/utils/overridePath.d.ts +19 -0
- package/dist/src/utils/resolveMessage.d.ts +17 -0
- package/dist/src/utils/setInPath.d.ts +10 -0
- package/dist/src/utils/splitValidationFunctions.d.ts +15 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/useDynamicForm-C6-0mGw4.js +737 -0
- package/dist/useDynamicForm-C6-0mGw4.js.map +1 -0
- package/dist/useDynamicForm-SHyV1lLH.cjs +6 -0
- package/dist/useDynamicForm-SHyV1lLH.cjs.map +1 -0
- package/dist/vue-dynamic-form.cjs.js +2 -0
- package/dist/vue-dynamic-form.cjs.js.map +1 -0
- package/dist/vue-dynamic-form.es.js +13 -178
- package/dist/vue-dynamic-form.es.js.map +1 -0
- package/package.json +17 -9
- package/dist/vue-dynamic-form.umd.js +0 -1
- /package/dist/src/components/{DynamicForm.test.d.ts → __tests__/DynamicForm.test.d.ts} +0 -0
|
@@ -0,0 +1,612 @@
|
|
|
1
|
+
import { defineComponent as B, createElementBlock as l, openBlock as t, normalizeClass as g, createCommentVNode as d, createElementVNode as r, createBlock as k, unref as O, withCtx as x, withDirectives as W, vModelText as L, vModelCheckbox as D, Fragment as F, renderList as T, toDisplayString as a, vModelSelect as A, renderSlot as v, createTextVNode as C, createVNode as R, ref as V, computed as I, withModifiers as U, markRaw as j, h as P } from "vue";
|
|
2
|
+
import { d as z, e as G, u as H, _ as J, i as Y } from "./useDynamicForm-C6-0mGw4.js";
|
|
3
|
+
function q(h, m) {
|
|
4
|
+
return !h || !m || (h = m?.({ ...h }), h.children = h?.children?.map((u) => q(u, m)), h.choice = h?.choice?.map((u) => q(u, m))), h;
|
|
5
|
+
}
|
|
6
|
+
const Q = {
|
|
7
|
+
key: 0,
|
|
8
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
9
|
+
fill: "none",
|
|
10
|
+
viewBox: "0 0 24 24",
|
|
11
|
+
"stroke-width": "1.5",
|
|
12
|
+
stroke: "currentColor",
|
|
13
|
+
class: "size-3"
|
|
14
|
+
}, X = {
|
|
15
|
+
key: 1,
|
|
16
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
17
|
+
fill: "none",
|
|
18
|
+
viewBox: "0 0 24 24",
|
|
19
|
+
"stroke-width": "1.5",
|
|
20
|
+
stroke: "currentColor",
|
|
21
|
+
class: "size-3"
|
|
22
|
+
}, _ = /* @__PURE__ */ B({
|
|
23
|
+
__name: "IconButton",
|
|
24
|
+
props: {
|
|
25
|
+
icon: {},
|
|
26
|
+
color: { default: "blue" }
|
|
27
|
+
},
|
|
28
|
+
emits: ["click"],
|
|
29
|
+
setup(h) {
|
|
30
|
+
return (m, u) => (t(), l("button", {
|
|
31
|
+
type: "button",
|
|
32
|
+
class: g(["cursor-pointer inline-flex items-center justify-center rounded-full size-5 text-white-800 cursor-pointer", {
|
|
33
|
+
"bg-blue-200 hover:bg-blue-300": m.color === "blue",
|
|
34
|
+
"bg-red-200 hover:bg-red-300": m.color === "red"
|
|
35
|
+
}]),
|
|
36
|
+
onClick: u[0] || (u[0] = ($) => m.$emit("click"))
|
|
37
|
+
}, [
|
|
38
|
+
m.icon === "plus" ? (t(), l("svg", Q, u[1] || (u[1] = [
|
|
39
|
+
r("path", {
|
|
40
|
+
"stroke-linecap": "round",
|
|
41
|
+
"stroke-linejoin": "round",
|
|
42
|
+
d: "M12 4.5v15m7.5-7.5h-15"
|
|
43
|
+
}, null, -1)
|
|
44
|
+
]))) : d("", !0),
|
|
45
|
+
m.icon === "minus" ? (t(), l("svg", X, u[2] || (u[2] = [
|
|
46
|
+
r("path", {
|
|
47
|
+
"stroke-linecap": "round",
|
|
48
|
+
"stroke-linejoin": "round",
|
|
49
|
+
d: "M5 12h14"
|
|
50
|
+
}, null, -1)
|
|
51
|
+
]))) : d("", !0)
|
|
52
|
+
], 2));
|
|
53
|
+
}
|
|
54
|
+
}), Z = { class: "text-sm whitespace-pre-wrap" }, K = ["data-testid"], M = { class: "grid grid-cols-1 md:grid-cols-2 gap-6" }, ee = { class: "grid grid-cols-1 md:grid-cols-2 gap-6 ms-6" }, te = { class: "text-sm whitespace-pre-wrap" }, le = ["data-testid"], ie = ["for"], se = {
|
|
55
|
+
key: 0,
|
|
56
|
+
class: "-ml-0.5 text-red-500"
|
|
57
|
+
}, de = { class: "text-sm whitespace-pre-wrap" }, ne = ["data-testid"], oe = ["for"], re = {
|
|
58
|
+
key: 0,
|
|
59
|
+
class: "-ml-0.5 text-red-500"
|
|
60
|
+
}, ae = { class: "flex gap-2 items-center" }, ue = { class: "flex flex-col grow" }, ce = { class: "text-sm whitespace-pre-wrap" }, pe = ["data-testid"], he = {
|
|
61
|
+
key: 0,
|
|
62
|
+
class: "-ml-0.5 text-red-500"
|
|
63
|
+
}, me = { class: "grid grid-cols-1 md:grid-cols-2 gap-6 ms-6" }, fe = { class: "text-sm whitespace-pre-wrap" }, be = ["data-testid"], ge = {
|
|
64
|
+
key: 0,
|
|
65
|
+
class: "-ml-0.5 text-red-500"
|
|
66
|
+
}, ye = { class: "grid grid-cols-1 md:grid-cols-2 gap-6 ms-6" }, xe = { class: "text-sm whitespace-pre-wrap" }, ve = ["data-testid"], Oe = ["id", "value", "disabled", "onChange", "onBlur"], ke = ["value"], _e = ["id", "onUpdate:modelValue", "disabled", "onBlur"], Ce = ["value"], we = ["id", "checked", "disabled", "onChange", "onBlur"], $e = ["id", "onUpdate:modelValue", "disabled", "onBlur"], Ne = ["id", "onUpdate:modelValue", "disabled", "onBlur"], Fe = ["id", "value", "disabled", "onInput", "onBlur"], Be = /* @__PURE__ */ B({
|
|
67
|
+
__name: "TestFormTemplate",
|
|
68
|
+
setup(h) {
|
|
69
|
+
const m = G();
|
|
70
|
+
return (u, $) => (t(), k(z, { "metadata-configuration": O(m) }, {
|
|
71
|
+
heading: x(({ fieldMetadata: e, fieldContext: { errorMessage: i, label: s }, disabled: n, canAddItems: o, addItem: p, canRemoveItems: y, removeItem: f, slotProps: c }) => [
|
|
72
|
+
e.hidden ? d("", !0) : (t(), l("div", {
|
|
73
|
+
key: 0,
|
|
74
|
+
class: g(["mt-4", { "md:col-span-2": e.fullWidth }])
|
|
75
|
+
}, [
|
|
76
|
+
s ? (t(), l("h3", {
|
|
77
|
+
key: 0,
|
|
78
|
+
class: g(["flex text-xl font-bold gap-2 items-center mb-2", { "text-gray-500": e.disabled || n }])
|
|
79
|
+
}, [
|
|
80
|
+
C(a(s) + " ", 1),
|
|
81
|
+
o ? (t(), k(_, {
|
|
82
|
+
key: 0,
|
|
83
|
+
icon: "plus",
|
|
84
|
+
tabindex: "-1",
|
|
85
|
+
"data-testid": `${e.path}-add-button`,
|
|
86
|
+
onClick: p
|
|
87
|
+
}, null, 8, ["data-testid", "onClick"])) : d("", !0),
|
|
88
|
+
y ? (t(), k(_, {
|
|
89
|
+
key: 1,
|
|
90
|
+
icon: "minus",
|
|
91
|
+
tabindex: "-1",
|
|
92
|
+
color: "red",
|
|
93
|
+
"data-testid": `${e.path}-remove-button`,
|
|
94
|
+
onClick: f
|
|
95
|
+
}, null, 8, ["data-testid", "onClick"])) : d("", !0)
|
|
96
|
+
], 2)) : d("", !0),
|
|
97
|
+
r("pre", Z, a(e.description), 1),
|
|
98
|
+
i.value ? (t(), l("span", {
|
|
99
|
+
key: 1,
|
|
100
|
+
class: "text-red-600 text-sm",
|
|
101
|
+
"data-testid": `${e.path}-error-message`
|
|
102
|
+
}, a(i.value), 9, K)) : d("", !0),
|
|
103
|
+
r("div", M, [
|
|
104
|
+
v(u.$slots, "default", {
|
|
105
|
+
level: (c?.level ?? 0) + 1
|
|
106
|
+
})
|
|
107
|
+
])
|
|
108
|
+
], 2))
|
|
109
|
+
]),
|
|
110
|
+
"heading-array": x(() => [
|
|
111
|
+
v(u.$slots, "default")
|
|
112
|
+
]),
|
|
113
|
+
"default-choice": x(({ fieldMetadata: e, fieldContext: { errorMessage: i, label: s }, disabled: n, required: o, slotProps: p }) => [
|
|
114
|
+
e.hidden ? d("", !0) : (t(), l("div", {
|
|
115
|
+
key: 0,
|
|
116
|
+
class: g(["flex flex-col gap-2", { "md:col-span-2": e.fullWidth }])
|
|
117
|
+
}, [
|
|
118
|
+
r("span", {
|
|
119
|
+
class: g(["flex gap-2 items-center", { "text-gray-500": n, "after:content-['*'] after:-ml-0.5 after:text-red-500": o }])
|
|
120
|
+
}, a(s), 3),
|
|
121
|
+
r("div", ee, [
|
|
122
|
+
v(u.$slots, "default", {
|
|
123
|
+
level: (p?.level ?? 0) + 1,
|
|
124
|
+
belowChoiceField: !0
|
|
125
|
+
})
|
|
126
|
+
]),
|
|
127
|
+
r("pre", te, a(e.description), 1),
|
|
128
|
+
i.value ? (t(), l("span", {
|
|
129
|
+
key: 0,
|
|
130
|
+
class: "text-red-600 text-sm",
|
|
131
|
+
"data-testid": `${e.path}-error-message`
|
|
132
|
+
}, a(i.value), 9, le)) : d("", !0)
|
|
133
|
+
], 2))
|
|
134
|
+
]),
|
|
135
|
+
"default-array": x(({ fieldMetadata: e, fieldContext: { errorMessage: i, label: s }, disabled: n, required: o, canAddItems: p, addItem: y }) => [
|
|
136
|
+
e.hidden ? d("", !0) : (t(), l("div", {
|
|
137
|
+
key: 0,
|
|
138
|
+
class: g(["flex flex-col gap-2", { "md:col-span-2": e.fullWidth }])
|
|
139
|
+
}, [
|
|
140
|
+
r("label", {
|
|
141
|
+
for: `${e.path}[0]`,
|
|
142
|
+
class: g([{ "text-gray-500": e.disabled || n }, "flex gap-2 items-center"])
|
|
143
|
+
}, [
|
|
144
|
+
C(a(s) + " ", 1),
|
|
145
|
+
o ? (t(), l("span", se, "*")) : d("", !0),
|
|
146
|
+
p ? (t(), k(_, {
|
|
147
|
+
key: 1,
|
|
148
|
+
icon: "plus",
|
|
149
|
+
tabindex: "-1",
|
|
150
|
+
"data-testid": `${e.path}-add-button`,
|
|
151
|
+
onClick: y
|
|
152
|
+
}, null, 8, ["data-testid", "onClick"])) : d("", !0)
|
|
153
|
+
], 10, ie),
|
|
154
|
+
v(u.$slots, "default", { hideLabel: !0 }),
|
|
155
|
+
r("pre", de, a(e.description), 1),
|
|
156
|
+
i.value ? (t(), l("span", {
|
|
157
|
+
key: 0,
|
|
158
|
+
class: "text-red-600 text-sm",
|
|
159
|
+
"data-testid": `${e.path}-error-message`
|
|
160
|
+
}, a(i.value), 9, ne)) : d("", !0)
|
|
161
|
+
], 2))
|
|
162
|
+
]),
|
|
163
|
+
default: x(({ fieldMetadata: e, fieldContext: { errorMessage: i, label: s }, disabled: n, required: o, canRemoveItems: p, removeItem: y, slotProps: f }) => [
|
|
164
|
+
e.hidden ? d("", !0) : (t(), l("div", {
|
|
165
|
+
key: 0,
|
|
166
|
+
class: g(["flex flex-col gap-2", { "md:col-span-2": e.fullWidth }])
|
|
167
|
+
}, [
|
|
168
|
+
f?.hideLabel ? d("", !0) : (t(), l("label", {
|
|
169
|
+
key: 0,
|
|
170
|
+
for: e.path,
|
|
171
|
+
class: g({ "text-gray-500": e.disabled || n })
|
|
172
|
+
}, [
|
|
173
|
+
C(a(s) + " ", 1),
|
|
174
|
+
o ? (t(), l("span", re, "*")) : d("", !0)
|
|
175
|
+
], 10, oe)),
|
|
176
|
+
r("div", ae, [
|
|
177
|
+
r("div", ue, [
|
|
178
|
+
v(u.$slots, "default")
|
|
179
|
+
]),
|
|
180
|
+
R(_, {
|
|
181
|
+
class: g({ invisible: !p }),
|
|
182
|
+
icon: "minus",
|
|
183
|
+
tabindex: "-1",
|
|
184
|
+
color: "red",
|
|
185
|
+
"data-testid": `${e.path}-remove-button`,
|
|
186
|
+
onClick: y
|
|
187
|
+
}, null, 8, ["class", "data-testid", "onClick"])
|
|
188
|
+
]),
|
|
189
|
+
r("pre", ce, a(e.description), 1),
|
|
190
|
+
i.value ? (t(), l("span", {
|
|
191
|
+
key: 1,
|
|
192
|
+
class: "text-red-600 text-sm",
|
|
193
|
+
"data-testid": `${e.path}-error-message`
|
|
194
|
+
}, a(i.value), 9, pe)) : d("", !0)
|
|
195
|
+
], 2)),
|
|
196
|
+
v(u.$slots, "attributes")
|
|
197
|
+
]),
|
|
198
|
+
"group-array": x(({ fieldMetadata: e, fieldContext: { errorMessage: i, label: s }, disabled: n, required: o, canAddItems: p, addItem: y, slotProps: f }) => [
|
|
199
|
+
e.hidden ? (t(), l(F, { key: 0 }, [], 64)) : f?.belowChoiceField ? (t(), l("div", {
|
|
200
|
+
key: 1,
|
|
201
|
+
class: g({ "md:col-span-2": e.fullWidth })
|
|
202
|
+
}, [
|
|
203
|
+
r("span", {
|
|
204
|
+
class: g(["flex gap-2 items-center mb-2", { "text-gray-500": e.disabled || n }])
|
|
205
|
+
}, [
|
|
206
|
+
C(a(s) + " ", 1),
|
|
207
|
+
o ? (t(), l("span", he, "*")) : d("", !0),
|
|
208
|
+
p ? (t(), k(_, {
|
|
209
|
+
key: 1,
|
|
210
|
+
icon: "plus",
|
|
211
|
+
tabindex: "-1",
|
|
212
|
+
"data-testid": `${e.path}-add-button`,
|
|
213
|
+
onClick: y
|
|
214
|
+
}, null, 8, ["data-testid", "onClick"])) : d("", !0)
|
|
215
|
+
], 2),
|
|
216
|
+
r("div", me, [
|
|
217
|
+
v(u.$slots, "default", {
|
|
218
|
+
level: (f?.level ?? 0) + 1
|
|
219
|
+
})
|
|
220
|
+
]),
|
|
221
|
+
r("pre", fe, a(e.description), 1),
|
|
222
|
+
i.value ? (t(), l("span", {
|
|
223
|
+
key: 0,
|
|
224
|
+
class: "text-red-600 text-sm",
|
|
225
|
+
"data-testid": `${e.path}-error-message`
|
|
226
|
+
}, a(i.value), 9, be)) : d("", !0)
|
|
227
|
+
], 2)) : v(u.$slots, "default", { key: 2 })
|
|
228
|
+
]),
|
|
229
|
+
group: x(({ fieldMetadata: e, fieldContext: { errorMessage: i, label: s }, disabled: n, required: o, canAddItems: p, canRemoveItems: y, addItem: f, removeItem: c, slotProps: b }) => [
|
|
230
|
+
e.hidden ? d("", !0) : (t(), l("div", {
|
|
231
|
+
key: 0,
|
|
232
|
+
class: g({ "md:col-span-2": e.fullWidth })
|
|
233
|
+
}, [
|
|
234
|
+
b?.hideLabel ? d("", !0) : (t(), l("span", {
|
|
235
|
+
key: 0,
|
|
236
|
+
class: g(["flex gap-2 items-center mb-2", { "text-gray-500": e.disabled || n }])
|
|
237
|
+
}, [
|
|
238
|
+
C(a(s) + " ", 1),
|
|
239
|
+
o ? (t(), l("span", ge, "*")) : d("", !0),
|
|
240
|
+
p ? (t(), k(_, {
|
|
241
|
+
key: 1,
|
|
242
|
+
icon: "plus",
|
|
243
|
+
tabindex: "-1",
|
|
244
|
+
"data-testid": `${e.path}-add-button`,
|
|
245
|
+
onClick: f
|
|
246
|
+
}, null, 8, ["data-testid", "onClick"])) : d("", !0),
|
|
247
|
+
y ? (t(), k(_, {
|
|
248
|
+
key: 2,
|
|
249
|
+
icon: "minus",
|
|
250
|
+
tabindex: "-1",
|
|
251
|
+
"data-testid": `${e.path}-remove-button`,
|
|
252
|
+
color: "red",
|
|
253
|
+
onClick: c
|
|
254
|
+
}, null, 8, ["data-testid", "onClick"])) : d("", !0)
|
|
255
|
+
], 2)),
|
|
256
|
+
r("div", ye, [
|
|
257
|
+
v(u.$slots, "default", {
|
|
258
|
+
level: (b?.level ?? 0) + 1
|
|
259
|
+
})
|
|
260
|
+
]),
|
|
261
|
+
r("pre", xe, a(e.description), 1),
|
|
262
|
+
i.value ? (t(), l("span", {
|
|
263
|
+
key: 1,
|
|
264
|
+
class: "text-red-600 text-sm",
|
|
265
|
+
"data-testid": `${e.path}-error-message`
|
|
266
|
+
}, a(i.value), 9, ve)) : d("", !0)
|
|
267
|
+
], 2)),
|
|
268
|
+
v(u.$slots, "attributes")
|
|
269
|
+
]),
|
|
270
|
+
"select-input": x(({ fieldMetadata: e, fieldContext: { value: i, handleBlur: s, handleChange: n }, disabled: o }) => [
|
|
271
|
+
r("select", {
|
|
272
|
+
id: e.path,
|
|
273
|
+
value: i.value,
|
|
274
|
+
disabled: e.disabled || o,
|
|
275
|
+
class: "h-9 bg-gray-100 border-gray-200 border rounded px-3 text-sm",
|
|
276
|
+
onChange: n,
|
|
277
|
+
onBlur: s
|
|
278
|
+
}, [
|
|
279
|
+
(t(!0), l(F, null, T(e.options, ({ key: p, value: y }) => (t(), l("option", {
|
|
280
|
+
key: p,
|
|
281
|
+
value: p
|
|
282
|
+
}, a(y), 9, ke))), 128))
|
|
283
|
+
], 40, Oe)
|
|
284
|
+
]),
|
|
285
|
+
"selectBoundByVModel-input": x(({ fieldMetadata: e, fieldContext: { value: i, handleBlur: s }, disabled: n }) => [
|
|
286
|
+
W(r("select", {
|
|
287
|
+
id: e.path,
|
|
288
|
+
"onUpdate:modelValue": (o) => i.value = o,
|
|
289
|
+
disabled: e.disabled || n,
|
|
290
|
+
class: "h-9 bg-gray-100 border-gray-200 border rounded px-3 text-sm",
|
|
291
|
+
onBlur: s
|
|
292
|
+
}, [
|
|
293
|
+
(t(!0), l(F, null, T(e.options, ({ key: o, value: p }) => (t(), l("option", {
|
|
294
|
+
key: o,
|
|
295
|
+
value: o
|
|
296
|
+
}, a(p), 9, Ce))), 128))
|
|
297
|
+
], 40, _e), [
|
|
298
|
+
[A, i.value]
|
|
299
|
+
])
|
|
300
|
+
]),
|
|
301
|
+
"checkbox-input": x(({ fieldMetadata: e, fieldContext: { value: i, handleBlur: s, handleChange: n }, disabled: o }) => [
|
|
302
|
+
r("input", {
|
|
303
|
+
id: e.path,
|
|
304
|
+
checked: i.value,
|
|
305
|
+
disabled: e.disabled || o,
|
|
306
|
+
type: "checkbox",
|
|
307
|
+
class: "h-6 bg-gray-100 border-gray-200 border rounded px-3 text-sm",
|
|
308
|
+
onChange: (p) => n(p.target.checked),
|
|
309
|
+
onBlur: s
|
|
310
|
+
}, null, 40, we)
|
|
311
|
+
]),
|
|
312
|
+
"checkboxBoundByVModel-input": x(({ fieldMetadata: e, fieldContext: { value: i, handleBlur: s }, disabled: n }) => [
|
|
313
|
+
W(r("input", {
|
|
314
|
+
id: e.path,
|
|
315
|
+
"onUpdate:modelValue": (o) => i.value = o,
|
|
316
|
+
disabled: e.disabled || n,
|
|
317
|
+
type: "checkbox",
|
|
318
|
+
class: "h-6 bg-gray-100 border-gray-200 border rounded px-3 text-sm",
|
|
319
|
+
onBlur: s
|
|
320
|
+
}, null, 40, $e), [
|
|
321
|
+
[D, i.value]
|
|
322
|
+
])
|
|
323
|
+
]),
|
|
324
|
+
"textBoundByVModel-input": x(({ fieldMetadata: e, fieldContext: { value: i, handleBlur: s }, disabled: n }) => [
|
|
325
|
+
W(r("input", {
|
|
326
|
+
id: e.path,
|
|
327
|
+
"onUpdate:modelValue": (o) => i.value = o,
|
|
328
|
+
disabled: e.disabled || n,
|
|
329
|
+
type: "text",
|
|
330
|
+
class: "h-9 bg-gray-100 border-gray-200 border rounded px-3 text-sm",
|
|
331
|
+
onBlur: s
|
|
332
|
+
}, null, 40, Ne), [
|
|
333
|
+
[L, i.value]
|
|
334
|
+
])
|
|
335
|
+
]),
|
|
336
|
+
"default-input": x(({ fieldMetadata: e, fieldContext: { value: i, handleBlur: s, handleChange: n }, disabled: o }) => [
|
|
337
|
+
r("input", {
|
|
338
|
+
id: e.path,
|
|
339
|
+
value: i.value,
|
|
340
|
+
disabled: e.disabled || o,
|
|
341
|
+
type: "text",
|
|
342
|
+
class: "h-9 bg-gray-100 border-gray-200 border rounded px-3 text-sm",
|
|
343
|
+
onInput: n,
|
|
344
|
+
onBlur: s
|
|
345
|
+
}, null, 40, Fe)
|
|
346
|
+
]),
|
|
347
|
+
_: 3
|
|
348
|
+
}, 8, ["metadata-configuration"]));
|
|
349
|
+
}
|
|
350
|
+
}), We = { class: "flex justify-end gap-2" }, Ve = {
|
|
351
|
+
key: 1,
|
|
352
|
+
type: "submit",
|
|
353
|
+
class: "cursor-pointer mt-4 bg-blue-500 text-white px-4 py-2 rounded",
|
|
354
|
+
"data-testid": "submit"
|
|
355
|
+
}, Te = {
|
|
356
|
+
key: 0,
|
|
357
|
+
"data-testid": "errors",
|
|
358
|
+
class: "col-12 text-red-600"
|
|
359
|
+
}, qe = ["innerHTML"], Se = {
|
|
360
|
+
key: 1,
|
|
361
|
+
"data-testid": "isSubmitted"
|
|
362
|
+
}, Ie = {
|
|
363
|
+
key: 2,
|
|
364
|
+
class: "bg-gray-100 p-4 rounded-lg text-sm overflow-auto"
|
|
365
|
+
}, Re = /* @__PURE__ */ B({
|
|
366
|
+
__name: "TestForm",
|
|
367
|
+
props: {
|
|
368
|
+
metadata: {},
|
|
369
|
+
settings: {},
|
|
370
|
+
showDebugState: { type: Boolean, default: !1 },
|
|
371
|
+
initialEdit: { type: Boolean, default: !0 },
|
|
372
|
+
hideFieldsWithoutValue: { type: Boolean, default: !1 },
|
|
373
|
+
initialValues: {}
|
|
374
|
+
},
|
|
375
|
+
setup(h) {
|
|
376
|
+
const { values: m, handleSubmit: u, errors: $, meta: e } = H({
|
|
377
|
+
initialValues: h.initialValues
|
|
378
|
+
}), i = V(), s = V(h.initialEdit), n = V(!1), o = I(() => h.metadata?.map((f) => q(f, (c) => (c.computedProps = c.computedProps ?? [], c.computedProps.push((b) => {
|
|
379
|
+
s.value || (b.disabled = !0);
|
|
380
|
+
}), h.hideFieldsWithoutValue && (c.computedProps.push((b, N) => {
|
|
381
|
+
!s.value && !Y(N.value) && (b.hidden = !0);
|
|
382
|
+
}), c.computedProps.push((b, N, S) => {
|
|
383
|
+
!s.value && S.value.length > 0 && S.value.every((E) => E.hidden) && (b.hidden = !0);
|
|
384
|
+
})), c)))), p = I(() => ({
|
|
385
|
+
analytics: !0,
|
|
386
|
+
messages: {
|
|
387
|
+
required: "{field} is required",
|
|
388
|
+
minOccurs: "At least {min} items required",
|
|
389
|
+
choiceMinOccurs: "The following fields need to occur at least {min} time(s): {field}",
|
|
390
|
+
minLength: "The minimum length of {field} is {length}",
|
|
391
|
+
maxLength: "The maximum length of {field} is {length}",
|
|
392
|
+
length: "{field} must be exactly {length} characters",
|
|
393
|
+
pattern: "{field} does not match the required pattern",
|
|
394
|
+
minInclusive: "{field} must be at least {min}",
|
|
395
|
+
maxInclusive: "{field} must be at most {max}",
|
|
396
|
+
minExclusive: "{field} must be greater than {min}",
|
|
397
|
+
maxExclusive: "{field} must be less than {max}",
|
|
398
|
+
enumeration: "{field} must be one of the allowed values",
|
|
399
|
+
whiteSpace: "{field} contains invalid whitespace (mode: {mode})",
|
|
400
|
+
fractionDigits: "{field} may have at most {digits} decimal place(s)",
|
|
401
|
+
totalDigits: "{field} may have at most {digits} significant digit(s)"
|
|
402
|
+
},
|
|
403
|
+
...h.settings ?? {}
|
|
404
|
+
}));
|
|
405
|
+
function y(f) {
|
|
406
|
+
u(
|
|
407
|
+
(c) => {
|
|
408
|
+
n.value = !0, s.value = !1;
|
|
409
|
+
},
|
|
410
|
+
({ errors: c }) => {
|
|
411
|
+
n.value = !1;
|
|
412
|
+
}
|
|
413
|
+
)(f);
|
|
414
|
+
}
|
|
415
|
+
return (f, c) => (t(), l("form", {
|
|
416
|
+
onSubmit: U(y, ["prevent"])
|
|
417
|
+
}, [
|
|
418
|
+
r("div", We, [
|
|
419
|
+
s.value ? d("", !0) : (t(), l("button", {
|
|
420
|
+
key: 0,
|
|
421
|
+
type: "button",
|
|
422
|
+
class: "cursor-pointer mt-4 bg-blue-500 text-white px-4 py-2 rounded",
|
|
423
|
+
"data-testid": "submit",
|
|
424
|
+
onClick: c[0] || (c[0] = (b) => s.value = !0)
|
|
425
|
+
}, " Edit ")),
|
|
426
|
+
s.value ? (t(), l("button", Ve, " Submit ")) : d("", !0),
|
|
427
|
+
s.value ? (t(), l("button", {
|
|
428
|
+
key: 2,
|
|
429
|
+
type: "button",
|
|
430
|
+
class: "cursor-pointer mt-4 bg-gray-200 text-black px-4 py-2 rounded",
|
|
431
|
+
"data-testid": "cancel",
|
|
432
|
+
onClick: c[1] || (c[1] = (b) => s.value = !1)
|
|
433
|
+
}, " Cancel ")) : d("", !0)
|
|
434
|
+
]),
|
|
435
|
+
Object.values(O($)).length ? (t(), l("div", Te, [
|
|
436
|
+
c[3] || (c[3] = C(" Errors: ", -1)),
|
|
437
|
+
r("ul", null, [
|
|
438
|
+
(t(!0), l(F, null, T(O($), (b, N) => (t(), l("li", { key: N }, [
|
|
439
|
+
r("span", { innerHTML: b }, null, 8, qe)
|
|
440
|
+
]))), 128))
|
|
441
|
+
])
|
|
442
|
+
])) : d("", !0),
|
|
443
|
+
R(J, {
|
|
444
|
+
template: Be,
|
|
445
|
+
metadata: o.value,
|
|
446
|
+
settings: p.value,
|
|
447
|
+
"onUpdate:modelValue": c[2] || (c[2] = (b) => i.value = b)
|
|
448
|
+
}, null, 8, ["metadata", "settings"]),
|
|
449
|
+
n.value ? (t(), l("span", Se)) : d("", !0),
|
|
450
|
+
f.showDebugState ? (t(), l("pre", Ie, "IsDirty: " + a(O(e).dirty) + `
|
|
451
|
+
Pending: ` + a(O(e).pending) + `
|
|
452
|
+
Touched: ` + a(O(e).touched) + `
|
|
453
|
+
Valid: ` + a(O(e).valid) + `
|
|
454
|
+
Submitted: ` + a(n.value) + `
|
|
455
|
+
|
|
456
|
+
// form values:
|
|
457
|
+
` + a(JSON.stringify(O(m), null, 2)) + `
|
|
458
|
+
`, 1)) : d("", !0)
|
|
459
|
+
], 32));
|
|
460
|
+
}
|
|
461
|
+
}), De = w([{
|
|
462
|
+
name: "text",
|
|
463
|
+
type: "text",
|
|
464
|
+
fieldOptions: { label: "Text Input" },
|
|
465
|
+
path: "with.custom.structure",
|
|
466
|
+
restriction: { maxLength: 10 }
|
|
467
|
+
}]), Ae = w([{
|
|
468
|
+
fieldOptions: { label: "Array Fields" },
|
|
469
|
+
type: "heading",
|
|
470
|
+
children: [
|
|
471
|
+
{ fieldOptions: { label: "Optional field (max 3)" }, minOccurs: 0, maxOccurs: 3 },
|
|
472
|
+
{ fieldOptions: { label: "Required field (max 3)" }, maxOccurs: 3 },
|
|
473
|
+
{ fieldOptions: { label: "2 Fields required" }, minOccurs: 2, maxOccurs: 4 },
|
|
474
|
+
{ fieldOptions: { label: "Section (2 sections required)" }, type: "heading", minOccurs: 2, maxOccurs: 4, fullWidth: !0, children: [
|
|
475
|
+
{ fieldOptions: { label: "Nested field 1" } },
|
|
476
|
+
{ fieldOptions: { label: "Required Nested field 2" }, type: "select", options: [
|
|
477
|
+
{ key: "option1", value: "Option 1" },
|
|
478
|
+
{ key: "option2", value: "Option 2" },
|
|
479
|
+
{ key: "option3", value: "Option 3" }
|
|
480
|
+
] },
|
|
481
|
+
{ fieldOptions: { label: "Nested field 3" }, type: "checkbox" }
|
|
482
|
+
] }
|
|
483
|
+
]
|
|
484
|
+
}]), Ue = w([{
|
|
485
|
+
fieldOptions: { label: "Grouped Fields" },
|
|
486
|
+
type: "heading",
|
|
487
|
+
children: [
|
|
488
|
+
{ fieldOptions: { label: "Required group" }, type: "group", children: [
|
|
489
|
+
{ fieldOptions: { label: "Required Nested field 1" }, fullWidth: !0 },
|
|
490
|
+
{ fieldOptions: { label: "Required Nested field 2" }, fullWidth: !0 }
|
|
491
|
+
] },
|
|
492
|
+
{ fieldOptions: { label: "Optional group" }, type: "group", minOccurs: 0, description: `The group is optional, therefore the children will only be required once 1 value is filled in.
|
|
493
|
+
|
|
494
|
+
You can test it by filling in one of the fields.`, children: [
|
|
495
|
+
{ fieldOptions: { label: "Required Nested field 1" }, fullWidth: !0 },
|
|
496
|
+
{ fieldOptions: { label: "Required Nested field 2" }, fullWidth: !0 }
|
|
497
|
+
] }
|
|
498
|
+
]
|
|
499
|
+
}, {
|
|
500
|
+
fieldOptions: { label: "Grouped Array Fields" },
|
|
501
|
+
type: "heading",
|
|
502
|
+
children: [
|
|
503
|
+
{ fieldOptions: { label: "Required group" }, type: "group", maxOccurs: 5, fullWidth: !0, children: [
|
|
504
|
+
{ fieldOptions: { label: "Required Nested field 1" } },
|
|
505
|
+
{ fieldOptions: { label: "Required Nested field 2" } }
|
|
506
|
+
] },
|
|
507
|
+
{ fieldOptions: { label: "Optional group" }, type: "group", minOccurs: 0, maxOccurs: 5, fullWidth: !0, children: [
|
|
508
|
+
{ fieldOptions: { label: "Required Nested field 1" } },
|
|
509
|
+
{ fieldOptions: { label: "Required Nested field 2" } }
|
|
510
|
+
] }
|
|
511
|
+
]
|
|
512
|
+
}]), je = w([
|
|
513
|
+
{
|
|
514
|
+
fieldOptions: { label: "Choice Fields (minOccurs 1, maxOccurs 1)" },
|
|
515
|
+
type: "heading",
|
|
516
|
+
children: [
|
|
517
|
+
{ fieldOptions: { label: "Simple Choice Field" }, fullWidth: !0, description: "In a choice field, only 1 of the fields can be filled in.", choice: [
|
|
518
|
+
{ fieldOptions: { label: "Nested Field 1" } },
|
|
519
|
+
{ fieldOptions: { label: "Nested Field 2" } }
|
|
520
|
+
] }
|
|
521
|
+
]
|
|
522
|
+
},
|
|
523
|
+
{
|
|
524
|
+
fieldOptions: { label: "Choice Grouped Fields (minOccurs 1, maxOccurs 3)" },
|
|
525
|
+
type: "heading",
|
|
526
|
+
children: [
|
|
527
|
+
{ fieldOptions: { label: "Array Choice Field" }, type: "group", maxOccurs: 3, fullWidth: !0, description: "In a choice field, only 1 of the fields can be filled in.", choice: [
|
|
528
|
+
{ fieldOptions: { label: "Nested Field 1" }, type: "group", children: [
|
|
529
|
+
{ fieldOptions: { label: "Nested Child Field 1" }, fullWidth: !0 },
|
|
530
|
+
{ fieldOptions: { label: "Nested Child Field 2" }, fullWidth: !0 }
|
|
531
|
+
] },
|
|
532
|
+
{ fieldOptions: { label: "Nested Field 2" }, type: "group", children: [
|
|
533
|
+
{ fieldOptions: { label: "Nested Child Field 1" }, fullWidth: !0 },
|
|
534
|
+
{ fieldOptions: { label: "Nested Child Field 2" }, fullWidth: !0 }
|
|
535
|
+
] }
|
|
536
|
+
] }
|
|
537
|
+
]
|
|
538
|
+
},
|
|
539
|
+
{
|
|
540
|
+
fieldOptions: { label: "Choice Array Fields (minOccurs 1, maxOccurs 3)" },
|
|
541
|
+
type: "heading",
|
|
542
|
+
children: [
|
|
543
|
+
{ fieldOptions: { label: "Array Choice Field" }, type: "group", maxOccurs: 3, fullWidth: !0, description: "In a choice field, only 1 of the fields can be filled in.", choice: [
|
|
544
|
+
{ fieldOptions: { label: "Nested Field 1" }, maxOccurs: 3 },
|
|
545
|
+
{ fieldOptions: { label: "Nested Field 2" }, maxOccurs: 3 }
|
|
546
|
+
] }
|
|
547
|
+
]
|
|
548
|
+
}
|
|
549
|
+
]), Pe = w([
|
|
550
|
+
{
|
|
551
|
+
fieldOptions: { label: "Personal Info" },
|
|
552
|
+
type: "heading",
|
|
553
|
+
name: "person",
|
|
554
|
+
description: "Only showing the fields that have a value. Click edit to change.",
|
|
555
|
+
fullWidth: !0,
|
|
556
|
+
children: [
|
|
557
|
+
{ name: "firstName", fieldOptions: { label: "First Name" } },
|
|
558
|
+
{ name: "lastName", fieldOptions: { label: "Last Name" } },
|
|
559
|
+
{ name: "email", fieldOptions: { label: "Email" } }
|
|
560
|
+
]
|
|
561
|
+
},
|
|
562
|
+
{
|
|
563
|
+
fieldOptions: { label: "Address" },
|
|
564
|
+
type: "heading",
|
|
565
|
+
name: "address",
|
|
566
|
+
fullWidth: !0,
|
|
567
|
+
children: [
|
|
568
|
+
{ name: "street", fieldOptions: { label: "Street" }, minOccurs: 0 },
|
|
569
|
+
{ name: "city", fieldOptions: { label: "City" }, minOccurs: 0 },
|
|
570
|
+
{ name: "country", fieldOptions: { label: "Country" }, minOccurs: 0 }
|
|
571
|
+
]
|
|
572
|
+
}
|
|
573
|
+
], void 0, {
|
|
574
|
+
initialEdit: !1,
|
|
575
|
+
hideFieldsWithoutValue: !0,
|
|
576
|
+
initialValues: {
|
|
577
|
+
person: {
|
|
578
|
+
firstName: "Jack",
|
|
579
|
+
lastName: "Smit"
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
}), ze = w(
|
|
583
|
+
[{
|
|
584
|
+
name: "items",
|
|
585
|
+
type: "text",
|
|
586
|
+
fieldOptions: { label: "Items" },
|
|
587
|
+
maxOccurs: 3,
|
|
588
|
+
attributes: [{ name: "lang", type: "text", minOccurs: 0 }]
|
|
589
|
+
}],
|
|
590
|
+
{
|
|
591
|
+
// validateOnValueUpdate: false,
|
|
592
|
+
// validateOnValueUpdateAfterSubmit: false,
|
|
593
|
+
// validateWhenInError: true,
|
|
594
|
+
// validateOnBlur: true,
|
|
595
|
+
}
|
|
596
|
+
);
|
|
597
|
+
function w(h, m, u = {}) {
|
|
598
|
+
return j(B({
|
|
599
|
+
render: () => P(Re, { ...u, metadata: h, settings: m, showDebugState: !0 })
|
|
600
|
+
}));
|
|
601
|
+
}
|
|
602
|
+
export {
|
|
603
|
+
Be as TestFormTemplate,
|
|
604
|
+
Ae as arrayTestCase,
|
|
605
|
+
Pe as childFieldsTestCase,
|
|
606
|
+
je as choiceTestCase,
|
|
607
|
+
w as createTestCase,
|
|
608
|
+
De as defaultTestCase,
|
|
609
|
+
Ue as groupTestCase,
|
|
610
|
+
ze as individualTestCase
|
|
611
|
+
};
|
|
612
|
+
//# sourceMappingURL=examples.es.js.map
|