@digiform/wizard 0.2.18 → 0.3.1
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/core/src/types/guards.js +0 -12
- package/core/src/utils/apiBodyUtils.js +43 -75
- package/index.d.ts +2 -8
- package/index.js +2 -108
- package/package.json +1 -28
- package/styles.css +1 -1
- package/ui/src/lib/utils/templateUtils.js +11 -43
- package/wizard/src/features/form-runtime/FormWizard/FormWizard.js +36 -33
- package/wizard/src/features/form-runtime/components/FormField.js +28 -28
- package/wizard/src/features/form-runtime/components/FormFooter.js +4 -4
- package/wizard/src/features/form-runtime/components/FormSection/FormSection.js +19 -19
- package/wizard/src/features/form-runtime/components/FormStep/FormStep.js +21 -21
- package/wizard/src/features/form-runtime/components/StepProgressIndicator/StepProgressIndicator.js +1 -1
- package/wizard/src/features/form-runtime/config/configResolver.js +10 -14
- package/wizard/src/features/form-runtime/config/templateLoader.js +82 -112
- package/wizard/src/features/form-runtime/hooks/useComponentTriggers.js +42 -66
- package/wizard/src/features/form-runtime/hooks/useFieldEventHandlers.js +3 -3
- package/wizard/src/features/form-runtime/hooks/useFormFieldState.js +5 -5
- package/wizard/src/features/form-runtime/utils/errorUtils.js +31 -42
- package/wizard/src/features/form-runtime/utils/validationUX.js +14 -55
- package/wizard/src/features/state-management/machines/useFormMachine.js +3 -3
- package/wizard/src/features/trigger-action-system/components/ActionManager.js +4 -4
- package/wizard/src/features/validation-system/validation/ValidationEngine.js +24 -29
- package/FormWizard.d.ts +0 -10
- package/core/src/types/api.js +0 -12
- package/core/src/types/form-config.js +0 -60
- package/core/src/types/form-wizard-config-schema.js +0 -113
- package/core/src/types/validation.js +0 -61
- package/features/api-integration.d.ts +0 -2
- package/features/api-integration.js +0 -17
- package/features/dialog-system.d.ts +0 -2
- package/features/dialog-system.js +0 -9
- package/features/form-runtime.d.ts +0 -2
- package/features/form-runtime.js +0 -63
- package/features/index.d.ts +0 -11
- package/features/state-management.d.ts +0 -2
- package/features/state-management.js +0 -21
- package/features/trigger-action-system.d.ts +0 -2
- package/features/trigger-action-system.js +0 -12
- package/features/validation-system.d.ts +0 -2
- package/features/validation-system.js +0 -23
- package/styles/index.d.ts +0 -0
- package/ui/src/components/badge/badge.js +0 -20
- package/ui/src/components/badge/badge.module.css.js +0 -12
- package/wizard/src/features/api-integration/services/ActionExecutor.js +0 -339
- package/wizard/src/features/api-integration/services/ApiCallExecutor.js +0 -6
- package/wizard/src/features/api-integration/services/DialogExecutor.js +0 -6
- package/wizard/src/features/api-integration/services/GenericTriggerService.js +0 -284
- package/wizard/src/features/api-integration/services/NavigationExecutor.js +0 -6
- package/wizard/src/features/form-runtime/config/templateConfig.js +0 -156
- package/wizard/src/features/form-runtime/config/templateUtils.js +0 -14
- package/wizard/src/features/form-runtime/utils/validation.js +0 -100
- package/wizard/src/features/trigger-action-system/components/ActionLoadingIndicator/ActionLoadingIndicator.js +0 -46
- package/wizard/src/features/trigger-action-system/components/ActionLoadingIndicator/ActionLoadingIndicator.module.css.js +0 -30
- package/wizard/src/features/trigger-action-system/utils/GenericTriggerEngine.js +0 -376
- package/wizard/src/features/validation-system/components/ValidationDebugger.js +0 -69
- package/wizard/src/features/validation-system/validation/tanstackSchemaAdapter.js +0 -17
- package/wizard/src/features/validation-system/validation/validationService.js +0 -74
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
/* empty css */
|
|
3
|
-
import { isGenericTemplate as
|
|
3
|
+
import { isGenericTemplate as v, isTeamTemplate as h } from "../../../../../ui/src/lib/utils/templateUtils.js";
|
|
4
4
|
async function m() {
|
|
5
5
|
try {
|
|
6
6
|
const { templateStorageService: e } = await import("@formbuilder/builder");
|
|
@@ -9,22 +9,22 @@ async function m() {
|
|
|
9
9
|
return console.warn("Template storage service not available:", e), null;
|
|
10
10
|
}
|
|
11
11
|
}
|
|
12
|
-
async function
|
|
12
|
+
async function y() {
|
|
13
13
|
try {
|
|
14
14
|
const e = await m();
|
|
15
15
|
if (!e) return;
|
|
16
16
|
if (!e.isReady()) {
|
|
17
|
-
const
|
|
18
|
-
if (
|
|
19
|
-
const
|
|
20
|
-
|
|
17
|
+
const i = await fetch("/form.config.json");
|
|
18
|
+
if (i.ok) {
|
|
19
|
+
const r = (await i.json()).storage?.paths?.templates;
|
|
20
|
+
r && await e.initialize(r);
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
23
|
} catch (e) {
|
|
24
24
|
console.warn("Failed to initialize template storage service:", e);
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
|
-
function
|
|
27
|
+
function d(e) {
|
|
28
28
|
return {
|
|
29
29
|
metadata: e.metadata,
|
|
30
30
|
stepsData: e.stepsData || [],
|
|
@@ -40,7 +40,7 @@ function f(e) {
|
|
|
40
40
|
}
|
|
41
41
|
};
|
|
42
42
|
}
|
|
43
|
-
const
|
|
43
|
+
const f = /* @__PURE__ */ new Map(), c = {
|
|
44
44
|
"generic-contact-information": async () => {
|
|
45
45
|
const e = await fetch(
|
|
46
46
|
"/src/packages/form-wizard/admin/templates/generic/contact-information.json"
|
|
@@ -82,100 +82,100 @@ const p = /* @__PURE__ */ new Map(), o = {
|
|
|
82
82
|
return e.json();
|
|
83
83
|
}
|
|
84
84
|
};
|
|
85
|
-
async function
|
|
86
|
-
if (
|
|
87
|
-
return
|
|
85
|
+
async function b(e) {
|
|
86
|
+
if (f.has(e))
|
|
87
|
+
return f.get(e);
|
|
88
88
|
try {
|
|
89
|
-
let
|
|
90
|
-
if (
|
|
91
|
-
const
|
|
92
|
-
if (!
|
|
93
|
-
const
|
|
89
|
+
let i;
|
|
90
|
+
if (v(e)) {
|
|
91
|
+
const a = c[e];
|
|
92
|
+
if (!a) {
|
|
93
|
+
const o = Object.keys(c);
|
|
94
94
|
throw new Error(
|
|
95
|
-
`Generic template '${e}' not found. Available generic templates: ${
|
|
95
|
+
`Generic template '${e}' not found. Available generic templates: ${o.join(", ")}`
|
|
96
96
|
);
|
|
97
97
|
}
|
|
98
|
-
const
|
|
99
|
-
|
|
100
|
-
|
|
98
|
+
const r = await a();
|
|
99
|
+
i = d(
|
|
100
|
+
r
|
|
101
101
|
);
|
|
102
|
-
} else if (
|
|
103
|
-
await
|
|
104
|
-
const
|
|
105
|
-
if (!
|
|
102
|
+
} else if (h(e)) {
|
|
103
|
+
await y();
|
|
104
|
+
const a = await m();
|
|
105
|
+
if (!a)
|
|
106
106
|
throw new Error(
|
|
107
107
|
`Team template '${e}' could not be loaded: template storage service is not available`
|
|
108
108
|
);
|
|
109
|
-
const
|
|
109
|
+
const r = await a.loadTemplate(
|
|
110
110
|
e,
|
|
111
111
|
"team"
|
|
112
112
|
);
|
|
113
|
-
if (!
|
|
113
|
+
if (!r.success)
|
|
114
114
|
throw new Error(
|
|
115
|
-
`Team template '${e}' not found: ${"error" in
|
|
115
|
+
`Team template '${e}' not found: ${"error" in r && r.error?.message || "Unknown error"}`
|
|
116
116
|
);
|
|
117
|
-
|
|
117
|
+
i = d(r.data);
|
|
118
118
|
} else {
|
|
119
|
-
const
|
|
120
|
-
if (
|
|
121
|
-
const
|
|
122
|
-
|
|
123
|
-
|
|
119
|
+
const a = c[e];
|
|
120
|
+
if (a) {
|
|
121
|
+
const r = await a();
|
|
122
|
+
i = d(
|
|
123
|
+
r
|
|
124
124
|
);
|
|
125
125
|
} else {
|
|
126
|
-
const
|
|
126
|
+
const r = Object.keys(c);
|
|
127
127
|
throw new Error(
|
|
128
|
-
`Template '${e}' not found. Available generic templates: ${
|
|
128
|
+
`Template '${e}' not found. Available generic templates: ${r.join(", ")}`
|
|
129
129
|
);
|
|
130
130
|
}
|
|
131
131
|
}
|
|
132
|
-
if (!
|
|
132
|
+
if (!i.metadata || !Array.isArray(i.stepsData))
|
|
133
133
|
throw new Error(
|
|
134
134
|
`Invalid template structure for template: ${e}. Templates must have metadata and stepsData array.`
|
|
135
135
|
);
|
|
136
|
-
return
|
|
137
|
-
} catch (
|
|
136
|
+
return f.set(e, i), i;
|
|
137
|
+
} catch (i) {
|
|
138
138
|
throw new Error(
|
|
139
|
-
`Failed to load template '${e}': ${
|
|
139
|
+
`Failed to load template '${e}': ${i instanceof Error ? i.message : "Unknown error"}`
|
|
140
140
|
);
|
|
141
141
|
}
|
|
142
142
|
}
|
|
143
|
-
async function
|
|
143
|
+
async function E(e, i, a) {
|
|
144
144
|
console.log(
|
|
145
145
|
"Resolving template step:",
|
|
146
146
|
e,
|
|
147
147
|
"stepIndex:",
|
|
148
|
-
|
|
148
|
+
a
|
|
149
149
|
);
|
|
150
|
-
const
|
|
151
|
-
console.log("Loaded template:",
|
|
152
|
-
let
|
|
153
|
-
if (
|
|
154
|
-
|
|
155
|
-
`Invalid stepIndex ${
|
|
150
|
+
const r = await b(e.templateId);
|
|
151
|
+
console.log("Loaded template:", r);
|
|
152
|
+
let o;
|
|
153
|
+
if (r.stepsData && Array.isArray(r.stepsData) && r.stepsData.length > 0)
|
|
154
|
+
a !== void 0 && a >= 0 && a < r.stepsData.length ? (o = r.stepsData[a], console.log(`Using template data for step ${a}:`, o)) : (o = r.stepsData[0], console.warn(
|
|
155
|
+
`Invalid stepIndex ${a} for template, using first step`
|
|
156
156
|
));
|
|
157
157
|
else
|
|
158
158
|
throw new Error(`Template ${e.templateId} has no steps data`);
|
|
159
|
-
const
|
|
159
|
+
const u = o.sections?.map((w) => ({
|
|
160
160
|
...w,
|
|
161
|
-
components: w.components.map((
|
|
162
|
-
const g = ((
|
|
161
|
+
components: w.components.map((t) => {
|
|
162
|
+
const g = ((l) => `comp-${e.id}-${t.id || l}`)(t.id), s = {
|
|
163
163
|
id: g,
|
|
164
|
-
type:
|
|
164
|
+
type: t.type,
|
|
165
165
|
properties: {
|
|
166
166
|
// Use properties from component.properties if it exists, otherwise fallback to root level
|
|
167
|
-
label:
|
|
168
|
-
placeholder:
|
|
169
|
-
description:
|
|
170
|
-
required:
|
|
171
|
-
disabled:
|
|
172
|
-
readOnly:
|
|
173
|
-
invalid:
|
|
167
|
+
label: t.properties?.label || t.label || "",
|
|
168
|
+
placeholder: t.properties?.placeholder || t.placeholder || "",
|
|
169
|
+
description: t.properties?.description || t.description || "",
|
|
170
|
+
required: t.properties?.required || t.required || !1,
|
|
171
|
+
disabled: t.properties?.disabled || t.disabled || !1,
|
|
172
|
+
readOnly: t.properties?.readOnly || t.readOnly || !1,
|
|
173
|
+
invalid: t.properties?.invalid || !1,
|
|
174
174
|
// Add type-specific properties
|
|
175
|
-
type:
|
|
175
|
+
type: t.properties?.type || t.type,
|
|
176
176
|
// Copy all other properties from component.properties if it exists
|
|
177
|
-
...
|
|
178
|
-
(
|
|
177
|
+
...t.properties && Object.keys(t.properties).reduce(
|
|
178
|
+
(l, p) => ([
|
|
179
179
|
"label",
|
|
180
180
|
"placeholder",
|
|
181
181
|
"description",
|
|
@@ -184,82 +184,52 @@ async function S(e, r, i) {
|
|
|
184
184
|
"readOnly",
|
|
185
185
|
"invalid",
|
|
186
186
|
"type"
|
|
187
|
-
].includes(
|
|
187
|
+
].includes(p) || (l[p] = t.properties[p]), l),
|
|
188
188
|
{}
|
|
189
189
|
)
|
|
190
190
|
},
|
|
191
191
|
// Copy validation if it exists
|
|
192
|
-
...
|
|
193
|
-
},
|
|
194
|
-
return
|
|
192
|
+
...t.validation && { validation: t.validation }
|
|
193
|
+
}, n = e.componentOverrides?.[g];
|
|
194
|
+
return n ? {
|
|
195
|
+
...s,
|
|
195
196
|
...n,
|
|
196
|
-
...l,
|
|
197
197
|
// Merge properties deeply to allow partial property updates
|
|
198
198
|
properties: {
|
|
199
|
-
...
|
|
200
|
-
...
|
|
199
|
+
...s.properties,
|
|
200
|
+
...n.properties
|
|
201
201
|
},
|
|
202
202
|
// Merge validation deeply if both exist
|
|
203
|
-
...
|
|
203
|
+
...s.validation && n.validation && {
|
|
204
204
|
validation: {
|
|
205
|
-
...
|
|
206
|
-
...
|
|
205
|
+
...s.validation,
|
|
206
|
+
...n.validation
|
|
207
207
|
}
|
|
208
208
|
}
|
|
209
|
-
} :
|
|
209
|
+
} : s;
|
|
210
210
|
})
|
|
211
211
|
}));
|
|
212
212
|
return {
|
|
213
213
|
id: e.id,
|
|
214
214
|
// Use the step ID from the form config
|
|
215
|
-
title: e.title ||
|
|
216
|
-
displayTitle:
|
|
217
|
-
showStepNumber: e.showStepNumber !== void 0 ? e.showStepNumber :
|
|
218
|
-
sections:
|
|
215
|
+
title: e.title || o.title,
|
|
216
|
+
displayTitle: o.displayTitle,
|
|
217
|
+
showStepNumber: e.showStepNumber !== void 0 ? e.showStepNumber : o.showStepNumber,
|
|
218
|
+
sections: u,
|
|
219
219
|
navigation: {
|
|
220
220
|
// Use default navigation, then template navigation if available, then step override
|
|
221
|
-
...
|
|
222
|
-
...
|
|
221
|
+
...i,
|
|
222
|
+
...o.navigation,
|
|
223
223
|
// Cast since navigation might not exist in Omit type
|
|
224
224
|
...e.navigation
|
|
225
225
|
},
|
|
226
226
|
// Copy actions if they exist
|
|
227
|
-
...
|
|
228
|
-
actions:
|
|
227
|
+
...o.actions && {
|
|
228
|
+
actions: o.actions
|
|
229
229
|
}
|
|
230
230
|
};
|
|
231
231
|
}
|
|
232
|
-
async function E(e) {
|
|
233
|
-
return (await v(e)).metadata;
|
|
234
|
-
}
|
|
235
|
-
async function D() {
|
|
236
|
-
const e = Object.keys(o);
|
|
237
|
-
try {
|
|
238
|
-
await u();
|
|
239
|
-
const r = await m();
|
|
240
|
-
if (r) {
|
|
241
|
-
const i = await r.listTemplates("team");
|
|
242
|
-
if (i.success && i.data) {
|
|
243
|
-
const t = i.data.map((s) => s.metadata.id);
|
|
244
|
-
return [...e, ...t];
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
} catch (r) {
|
|
248
|
-
console.warn("Failed to load team templates:", r);
|
|
249
|
-
}
|
|
250
|
-
return e;
|
|
251
|
-
}
|
|
252
|
-
function O() {
|
|
253
|
-
return Object.keys(o);
|
|
254
|
-
}
|
|
255
|
-
function A() {
|
|
256
|
-
p.clear();
|
|
257
|
-
}
|
|
258
232
|
export {
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
D as getAvailableTemplates,
|
|
262
|
-
E as getTemplateMetadata,
|
|
263
|
-
v as loadTemplate,
|
|
264
|
-
S as resolveTemplateStep
|
|
233
|
+
b as loadTemplate,
|
|
234
|
+
E as resolveTemplateStep
|
|
265
235
|
};
|
|
@@ -1,102 +1,78 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
const
|
|
2
|
+
import { useRef as C, useCallback as g } from "react";
|
|
3
|
+
import { useFormMachine as x } from "../../state-management/machines/useFormMachine.js";
|
|
4
|
+
const M = ({
|
|
5
5
|
componentId: e,
|
|
6
|
-
initialValue:
|
|
7
|
-
onValueChange:
|
|
6
|
+
initialValue: l,
|
|
7
|
+
onValueChange: i
|
|
8
8
|
}) => {
|
|
9
|
-
const [, ,
|
|
10
|
-
evaluateComponentTriggers:
|
|
11
|
-
setComponentOriginalValue:
|
|
9
|
+
const [, , T] = x(), {
|
|
10
|
+
evaluateComponentTriggers: n,
|
|
11
|
+
setComponentOriginalValue: u,
|
|
12
12
|
getComponentAlerts: h,
|
|
13
|
-
dismissComponentAlert:
|
|
13
|
+
dismissComponentAlert: c,
|
|
14
14
|
hasComponentTriggers: A,
|
|
15
15
|
hasComponentActions: m,
|
|
16
|
-
getComponentTriggerState:
|
|
17
|
-
} =
|
|
18
|
-
|
|
19
|
-
const t =
|
|
20
|
-
(r,
|
|
16
|
+
getComponentTriggerState: p
|
|
17
|
+
} = T, f = C(!1), o = C(l);
|
|
18
|
+
l !== void 0 && !f.current && (u(e, l), o.current = l, f.current = !0);
|
|
19
|
+
const t = g(
|
|
20
|
+
(r, a) => {
|
|
21
21
|
console.log(
|
|
22
22
|
`🧪 [useComponentTriggers] evaluateTriggers called for ${e}:`,
|
|
23
23
|
{
|
|
24
24
|
eventType: r,
|
|
25
|
-
value:
|
|
26
|
-
evaluateComponentTriggers: !!
|
|
25
|
+
value: a,
|
|
26
|
+
evaluateComponentTriggers: !!n
|
|
27
27
|
}
|
|
28
|
-
),
|
|
28
|
+
), n(e, r, a);
|
|
29
29
|
},
|
|
30
|
-
[e,
|
|
31
|
-
),
|
|
32
|
-
(r,
|
|
33
|
-
|
|
30
|
+
[e, n]
|
|
31
|
+
), $ = g(
|
|
32
|
+
(r, a = "api_populated") => {
|
|
33
|
+
u(e, r, a), o.current = r;
|
|
34
34
|
},
|
|
35
|
-
[e,
|
|
36
|
-
),
|
|
35
|
+
[e, u]
|
|
36
|
+
), b = h(e), R = g(
|
|
37
37
|
(r) => {
|
|
38
|
-
|
|
38
|
+
c(e, r);
|
|
39
39
|
},
|
|
40
|
-
[e,
|
|
41
|
-
), s = A(e),
|
|
40
|
+
[e, c]
|
|
41
|
+
), s = A(e), F = m(e), O = p(e), S = g(
|
|
42
42
|
(r) => {
|
|
43
43
|
console.log(
|
|
44
44
|
`🧪 [useComponentTriggers] handleValueChange called for ${e}:`,
|
|
45
45
|
{
|
|
46
46
|
value: r,
|
|
47
|
-
oldValue:
|
|
47
|
+
oldValue: o.current,
|
|
48
48
|
hasTriggers: s,
|
|
49
|
-
onValueChange: !!
|
|
49
|
+
onValueChange: !!i
|
|
50
50
|
}
|
|
51
|
-
),
|
|
51
|
+
), o.current = r, i && i(r), s ? (console.log(
|
|
52
52
|
`🧪 [useComponentTriggers] About to call evaluateTriggers for ${e}`
|
|
53
53
|
), t("valueChange", r)) : console.log(
|
|
54
54
|
`🧪 [useComponentTriggers] hasTriggers is false for ${e}`
|
|
55
55
|
);
|
|
56
56
|
},
|
|
57
|
-
[t, s,
|
|
58
|
-
),
|
|
59
|
-
s && t("focus",
|
|
60
|
-
}, [t, s]),
|
|
61
|
-
s && t("blur",
|
|
57
|
+
[t, s, i, e]
|
|
58
|
+
), k = g(() => {
|
|
59
|
+
s && t("focus", o.current);
|
|
60
|
+
}, [t, s]), v = g(() => {
|
|
61
|
+
s && t("blur", o.current);
|
|
62
62
|
}, [t, s]);
|
|
63
63
|
return {
|
|
64
64
|
evaluateTriggers: t,
|
|
65
|
-
setOriginalValue:
|
|
66
|
-
alerts:
|
|
67
|
-
dismissAlert:
|
|
65
|
+
setOriginalValue: $,
|
|
66
|
+
alerts: b,
|
|
67
|
+
dismissAlert: R,
|
|
68
68
|
hasTriggers: s,
|
|
69
|
-
hasActions:
|
|
69
|
+
hasActions: F,
|
|
70
70
|
triggerState: O,
|
|
71
|
-
handleValueChange:
|
|
72
|
-
handleFocus:
|
|
73
|
-
handleBlur:
|
|
74
|
-
};
|
|
75
|
-
}, x = (e, o) => {
|
|
76
|
-
const {
|
|
77
|
-
handleValueChange: l,
|
|
78
|
-
handleFocus: f,
|
|
79
|
-
handleBlur: a,
|
|
80
|
-
alerts: i,
|
|
81
|
-
dismissAlert: h,
|
|
82
|
-
setOriginalValue: u
|
|
83
|
-
} = S({
|
|
84
|
-
componentId: e,
|
|
85
|
-
initialValue: o
|
|
86
|
-
});
|
|
87
|
-
return {
|
|
88
|
-
// Event handlers to attach to form fields
|
|
89
|
-
onChange: l,
|
|
90
|
-
onFocus: f,
|
|
91
|
-
onBlur: a,
|
|
92
|
-
// Alert management
|
|
93
|
-
alerts: i,
|
|
94
|
-
dismissAlert: h,
|
|
95
|
-
// For setting original value after API population
|
|
96
|
-
setOriginalValue: u
|
|
71
|
+
handleValueChange: S,
|
|
72
|
+
handleFocus: k,
|
|
73
|
+
handleBlur: v
|
|
97
74
|
};
|
|
98
75
|
};
|
|
99
76
|
export {
|
|
100
|
-
|
|
101
|
-
x as useFieldTriggerMonitor
|
|
77
|
+
M as useComponentTriggers
|
|
102
78
|
};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { useFormMachine as B } from "../../state-management/machines/useFormMachine.js";
|
|
3
2
|
import { useCallback as g } from "react";
|
|
4
3
|
import { markFieldAsUserInteracted as u } from "../utils/validationUX.js";
|
|
5
|
-
import { useComponentTriggers as
|
|
4
|
+
import { useComponentTriggers as B } from "./useComponentTriggers.js";
|
|
5
|
+
import { useFormMachine as F } from "../../state-management/machines/useFormMachine.js";
|
|
6
6
|
const E = ({
|
|
7
7
|
componentId: s,
|
|
8
8
|
hasIsDirtyTriggers: r,
|
|
@@ -10,7 +10,7 @@ const E = ({
|
|
|
10
10
|
getEnhancedIsDirty: n,
|
|
11
11
|
resetValidationState: f
|
|
12
12
|
}) => {
|
|
13
|
-
const [, , d] =
|
|
13
|
+
const [, , d] = F(), { setData: h } = d, t = B({ componentId: s }), C = g(
|
|
14
14
|
(a) => (e) => {
|
|
15
15
|
const l = a.state.value;
|
|
16
16
|
if (console.log(
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
2
|
+
import { useRef as F, useCallback as u, useEffect as p } from "react";
|
|
3
|
+
import { useFormContext as O } from "./useFormContext.js";
|
|
4
|
+
import { useFormMachine as h } from "../../state-management/machines/useFormMachine.js";
|
|
5
5
|
const b = ({
|
|
6
6
|
componentId: r,
|
|
7
7
|
hasIsDirtyTriggers: s
|
|
8
8
|
}) => {
|
|
9
|
-
const [V] =
|
|
9
|
+
const [V] = h(), t = O(), a = F(!1), c = F(), d = (e) => typeof e == "string" || typeof e == "boolean" || typeof e == "number" || e === null || e === void 0, f = V.context.componentOriginalValues[r]?.value, i = d(f) ? f : void 0, g = u(() => {
|
|
10
10
|
if (a.current) return;
|
|
11
11
|
const e = t.getFieldValue(r);
|
|
12
12
|
return a.current = !0, e;
|
|
@@ -26,7 +26,7 @@ const b = ({
|
|
|
26
26
|
(e, l) => i !== void 0 ? e !== i : l,
|
|
27
27
|
[i]
|
|
28
28
|
);
|
|
29
|
-
return
|
|
29
|
+
return p(() => {
|
|
30
30
|
o();
|
|
31
31
|
}, [o]), {
|
|
32
32
|
originalValueFromMachine: i,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { z as
|
|
3
|
-
const
|
|
2
|
+
import { z as s } from "zod";
|
|
3
|
+
const l = {
|
|
4
4
|
required: 10,
|
|
5
5
|
minLength: 8,
|
|
6
6
|
maxLength: 7,
|
|
@@ -10,19 +10,19 @@ const u = {
|
|
|
10
10
|
email: 3,
|
|
11
11
|
custom: 2,
|
|
12
12
|
default: 1
|
|
13
|
-
},
|
|
13
|
+
}, e = (t) => {
|
|
14
14
|
if (typeof t == "string")
|
|
15
15
|
return t.includes("verplicht") || t.includes("required") ? "required" : t.includes("minimaal") && t.includes("tekens") ? "minLength" : t.includes("maximaal") && t.includes("tekens") ? "maxLength" : t.includes("minimaal") && !t.includes("tekens") ? "min" : t.includes("maximaal") && !t.includes("tekens") ? "max" : t.includes("formaat") || t.includes("format") || t.includes("pattern") ? "pattern" : t.includes("e-mail") || t.includes("email") ? "email" : "default";
|
|
16
|
-
if (t instanceof
|
|
17
|
-
const
|
|
18
|
-
if (
|
|
19
|
-
switch (
|
|
16
|
+
if (t instanceof s.ZodError) {
|
|
17
|
+
const i = t.errors[0];
|
|
18
|
+
if (i?.code)
|
|
19
|
+
switch (i.code) {
|
|
20
20
|
case "too_small":
|
|
21
|
-
return
|
|
21
|
+
return i.type === "string" ? "minLength" : "min";
|
|
22
22
|
case "too_big":
|
|
23
|
-
return
|
|
23
|
+
return i.type === "string" ? "maxLength" : "max";
|
|
24
24
|
case "invalid_string":
|
|
25
|
-
return
|
|
25
|
+
return i.validation === "email" ? "email" : "pattern";
|
|
26
26
|
case "custom":
|
|
27
27
|
return "custom";
|
|
28
28
|
default:
|
|
@@ -30,27 +30,27 @@ const u = {
|
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
32
|
if (typeof t == "object" && t !== null && "code" in t) {
|
|
33
|
-
const
|
|
34
|
-
if (
|
|
35
|
-
if (
|
|
36
|
-
if (
|
|
33
|
+
const i = t.code;
|
|
34
|
+
if (i === "too_small") return "minLength";
|
|
35
|
+
if (i === "too_big") return "maxLength";
|
|
36
|
+
if (i === "invalid_string") return "email";
|
|
37
37
|
}
|
|
38
38
|
return "default";
|
|
39
|
-
},
|
|
39
|
+
}, a = (t) => {
|
|
40
40
|
if (t == null) return "";
|
|
41
41
|
if (typeof t == "string")
|
|
42
42
|
return t;
|
|
43
|
-
if (t instanceof
|
|
44
|
-
return t.errors.map((
|
|
43
|
+
if (t instanceof s.ZodError)
|
|
44
|
+
return t.errors.map((i) => i.message).join(", ");
|
|
45
45
|
if (typeof t == "object" && t !== null) {
|
|
46
46
|
if ("message" in t && typeof t.message == "string")
|
|
47
47
|
return t.message;
|
|
48
48
|
if ("_errors" in t && Array.isArray(t._errors))
|
|
49
49
|
return t._errors.filter(Boolean).join(", ");
|
|
50
50
|
if ("issues" in t && Array.isArray(t.issues))
|
|
51
|
-
return t.issues.map((
|
|
51
|
+
return t.issues.map((i) => i.message || "Validation error").join(", ");
|
|
52
52
|
if ("error" in t)
|
|
53
|
-
return
|
|
53
|
+
return a(t.error);
|
|
54
54
|
try {
|
|
55
55
|
if (Object.keys(t).length > 0) {
|
|
56
56
|
for (const n of ["message", "msg", "error", "description"])
|
|
@@ -61,33 +61,22 @@ const u = {
|
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
63
|
try {
|
|
64
|
-
const
|
|
65
|
-
if (
|
|
66
|
-
return
|
|
64
|
+
const i = JSON.stringify(t);
|
|
65
|
+
if (i.length < 200)
|
|
66
|
+
return i;
|
|
67
67
|
} catch {
|
|
68
68
|
}
|
|
69
69
|
return "Validation error occurred";
|
|
70
|
-
},
|
|
70
|
+
}, f = (t) => {
|
|
71
71
|
if (!t || t.length === 0) return "";
|
|
72
|
-
const
|
|
73
|
-
message:
|
|
74
|
-
type:
|
|
75
|
-
priority:
|
|
72
|
+
const i = t.filter((n) => n != null).map((n) => ({
|
|
73
|
+
message: a(n),
|
|
74
|
+
type: e(n),
|
|
75
|
+
priority: l[e(n)]
|
|
76
76
|
})).filter((n) => n.message.length > 0);
|
|
77
|
-
return
|
|
78
|
-
}
|
|
79
|
-
index: n,
|
|
80
|
-
type: typeof e,
|
|
81
|
-
constructor: e?.constructor?.name,
|
|
82
|
-
raw: e,
|
|
83
|
-
parsed: s(e),
|
|
84
|
-
validationType: i(e),
|
|
85
|
-
priority: u[i(e)]
|
|
86
|
-
}));
|
|
77
|
+
return i.length === 0 ? "" : (i.sort((n, u) => u.priority - n.priority), i[0].message);
|
|
78
|
+
};
|
|
87
79
|
export {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
m as getMostRelevantError,
|
|
91
|
-
c as parseAllErrors,
|
|
92
|
-
s as parseError
|
|
80
|
+
f as getMostRelevantError,
|
|
81
|
+
a as parseError
|
|
93
82
|
};
|