react-form-dto 1.0.2 → 1.0.3
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.
|
@@ -25,6 +25,7 @@ type FormBuilderProps = {
|
|
|
25
25
|
renderers?: Record<string, React.ComponentType<any>>;
|
|
26
26
|
/** Current locale for i18n string resolution (default: 'en') */
|
|
27
27
|
locale?: string;
|
|
28
|
+
handleChangeCallback?: (id: string, val: any) => void;
|
|
28
29
|
};
|
|
29
30
|
/**
|
|
30
31
|
* FormBuilder component that dynamically renders a form based on a FormDTO definition.
|
|
@@ -12,7 +12,7 @@ type Errors = Record<string, string | null>;
|
|
|
12
12
|
* form.handleChange('email', 'user@example.com');
|
|
13
13
|
* const errors = form.validateAll();
|
|
14
14
|
*/
|
|
15
|
-
export declare function useFormBuilder(dto: FormDTO, locale?: string): {
|
|
15
|
+
export declare function useFormBuilder(dto: FormDTO, locale?: string, handleChangeCallback?: (id: string, val: any) => void): {
|
|
16
16
|
/** Current form values for all fields */
|
|
17
17
|
values: Record<string, any>;
|
|
18
18
|
/** Function to update a field value */
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { FormControl as
|
|
3
|
-
var S = { exports: {} },
|
|
4
|
-
var
|
|
5
|
-
function
|
|
6
|
-
if (
|
|
7
|
-
|
|
8
|
-
var e = Symbol.for("react.transitional.element"),
|
|
9
|
-
function
|
|
1
|
+
import X, { useState as M, useImperativeHandle as de } from "react";
|
|
2
|
+
import { FormControl as H, InputLabel as fe, Select as be, MenuItem as he, Typography as T, TextField as k, FormControlLabel as Z, Checkbox as xe, FormHelperText as Q, Autocomplete as K, FormLabel as ve, RadioGroup as ge, Radio as Ee, Box as ye, Grid as B } from "@mui/material";
|
|
3
|
+
var S = { exports: {} }, _ = {};
|
|
4
|
+
var U;
|
|
5
|
+
function je() {
|
|
6
|
+
if (U) return _;
|
|
7
|
+
U = 1;
|
|
8
|
+
var e = Symbol.for("react.transitional.element"), t = Symbol.for("react.fragment");
|
|
9
|
+
function n(a, o, s) {
|
|
10
10
|
var u = null;
|
|
11
11
|
if (s !== void 0 && (u = "" + s), o.key !== void 0 && (u = "" + o.key), "key" in o) {
|
|
12
12
|
s = {};
|
|
@@ -21,19 +21,19 @@ function ye() {
|
|
|
21
21
|
props: s
|
|
22
22
|
};
|
|
23
23
|
}
|
|
24
|
-
return
|
|
24
|
+
return _.Fragment = t, _.jsx = n, _.jsxs = n, _;
|
|
25
25
|
}
|
|
26
|
-
var
|
|
27
|
-
var
|
|
26
|
+
var R = {};
|
|
27
|
+
var G;
|
|
28
28
|
function _e() {
|
|
29
|
-
return
|
|
29
|
+
return G || (G = 1, process.env.NODE_ENV !== "production" && (function() {
|
|
30
30
|
function e(r) {
|
|
31
31
|
if (r == null) return null;
|
|
32
32
|
if (typeof r == "function")
|
|
33
33
|
return r.$$typeof === ce ? null : r.displayName || r.name || null;
|
|
34
34
|
if (typeof r == "string") return r;
|
|
35
35
|
switch (r) {
|
|
36
|
-
case
|
|
36
|
+
case O:
|
|
37
37
|
return "Fragment";
|
|
38
38
|
case te:
|
|
39
39
|
return "Profiler";
|
|
@@ -50,7 +50,7 @@ function _e() {
|
|
|
50
50
|
switch (typeof r.tag == "number" && console.error(
|
|
51
51
|
"Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."
|
|
52
52
|
), r.$$typeof) {
|
|
53
|
-
case
|
|
53
|
+
case w:
|
|
54
54
|
return "Portal";
|
|
55
55
|
case ae:
|
|
56
56
|
return r.displayName || "Context";
|
|
@@ -61,7 +61,7 @@ function _e() {
|
|
|
61
61
|
return r = r.displayName, r || (r = i.displayName || i.name || "", r = r !== "" ? "ForwardRef(" + r + ")" : "ForwardRef"), r;
|
|
62
62
|
case le:
|
|
63
63
|
return i = r.displayName || null, i !== null ? i : e(r.type) || "Memo";
|
|
64
|
-
case
|
|
64
|
+
case F:
|
|
65
65
|
i = r._payload, r = r._init;
|
|
66
66
|
try {
|
|
67
67
|
return e(r(i));
|
|
@@ -70,29 +70,29 @@ function _e() {
|
|
|
70
70
|
}
|
|
71
71
|
return null;
|
|
72
72
|
}
|
|
73
|
-
function
|
|
73
|
+
function t(r) {
|
|
74
74
|
return "" + r;
|
|
75
75
|
}
|
|
76
|
-
function
|
|
76
|
+
function n(r) {
|
|
77
77
|
try {
|
|
78
|
-
|
|
78
|
+
t(r);
|
|
79
79
|
var i = !1;
|
|
80
80
|
} catch {
|
|
81
81
|
i = !0;
|
|
82
82
|
}
|
|
83
83
|
if (i) {
|
|
84
84
|
i = console;
|
|
85
|
-
var m = i.error,
|
|
85
|
+
var m = i.error, p = typeof Symbol == "function" && Symbol.toStringTag && r[Symbol.toStringTag] || r.constructor.name || "Object";
|
|
86
86
|
return m.call(
|
|
87
87
|
i,
|
|
88
88
|
"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",
|
|
89
|
-
|
|
90
|
-
),
|
|
89
|
+
p
|
|
90
|
+
), t(r);
|
|
91
91
|
}
|
|
92
92
|
}
|
|
93
93
|
function a(r) {
|
|
94
|
-
if (r ===
|
|
95
|
-
if (typeof r == "object" && r !== null && r.$$typeof ===
|
|
94
|
+
if (r === O) return "<>";
|
|
95
|
+
if (typeof r == "object" && r !== null && r.$$typeof === F)
|
|
96
96
|
return "<...>";
|
|
97
97
|
try {
|
|
98
98
|
var i = e(r);
|
|
@@ -102,14 +102,14 @@ function _e() {
|
|
|
102
102
|
}
|
|
103
103
|
}
|
|
104
104
|
function o() {
|
|
105
|
-
var r =
|
|
105
|
+
var r = P.A;
|
|
106
106
|
return r === null ? null : r.getOwner();
|
|
107
107
|
}
|
|
108
108
|
function s() {
|
|
109
109
|
return Error("react-stack-top-frame");
|
|
110
110
|
}
|
|
111
111
|
function u(r) {
|
|
112
|
-
if (
|
|
112
|
+
if (D.call(r, "key")) {
|
|
113
113
|
var i = Object.getOwnPropertyDescriptor(r, "key").get;
|
|
114
114
|
if (i && i.isReactWarning) return !1;
|
|
115
115
|
}
|
|
@@ -117,7 +117,7 @@ function _e() {
|
|
|
117
117
|
}
|
|
118
118
|
function c(r, i) {
|
|
119
119
|
function m() {
|
|
120
|
-
|
|
120
|
+
q || (q = !0, console.error(
|
|
121
121
|
"%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",
|
|
122
122
|
i
|
|
123
123
|
));
|
|
@@ -129,19 +129,19 @@ function _e() {
|
|
|
129
129
|
}
|
|
130
130
|
function h() {
|
|
131
131
|
var r = e(this.type);
|
|
132
|
-
return
|
|
132
|
+
return z[r] || (z[r] = !0, console.error(
|
|
133
133
|
"Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release."
|
|
134
134
|
)), r = this.props.ref, r !== void 0 ? r : null;
|
|
135
135
|
}
|
|
136
|
-
function
|
|
137
|
-
var
|
|
136
|
+
function x(r, i, m, p, A, I) {
|
|
137
|
+
var d = m.ref;
|
|
138
138
|
return r = {
|
|
139
|
-
$$typeof:
|
|
139
|
+
$$typeof: v,
|
|
140
140
|
type: r,
|
|
141
141
|
key: i,
|
|
142
142
|
props: m,
|
|
143
|
-
_owner:
|
|
144
|
-
}, (
|
|
143
|
+
_owner: p
|
|
144
|
+
}, (d !== void 0 ? d : null) !== null ? Object.defineProperty(r, "ref", {
|
|
145
145
|
enumerable: !1,
|
|
146
146
|
get: h
|
|
147
147
|
}) : Object.defineProperty(r, "ref", { enumerable: !1, value: null }), r._store = {}, Object.defineProperty(r._store, "validated", {
|
|
@@ -158,159 +158,159 @@ function _e() {
|
|
|
158
158
|
configurable: !1,
|
|
159
159
|
enumerable: !1,
|
|
160
160
|
writable: !0,
|
|
161
|
-
value:
|
|
161
|
+
value: A
|
|
162
162
|
}), Object.defineProperty(r, "_debugTask", {
|
|
163
163
|
configurable: !1,
|
|
164
164
|
enumerable: !1,
|
|
165
165
|
writable: !0,
|
|
166
|
-
value:
|
|
166
|
+
value: I
|
|
167
167
|
}), Object.freeze && (Object.freeze(r.props), Object.freeze(r)), r;
|
|
168
168
|
}
|
|
169
|
-
function
|
|
170
|
-
var
|
|
171
|
-
if (
|
|
172
|
-
if (
|
|
173
|
-
if (me(
|
|
174
|
-
for (
|
|
175
|
-
|
|
176
|
-
Object.freeze && Object.freeze(
|
|
169
|
+
function E(r, i, m, p, A, I) {
|
|
170
|
+
var d = i.children;
|
|
171
|
+
if (d !== void 0)
|
|
172
|
+
if (p)
|
|
173
|
+
if (me(d)) {
|
|
174
|
+
for (p = 0; p < d.length; p++)
|
|
175
|
+
y(d[p]);
|
|
176
|
+
Object.freeze && Object.freeze(d);
|
|
177
177
|
} else
|
|
178
178
|
console.error(
|
|
179
179
|
"React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead."
|
|
180
180
|
);
|
|
181
|
-
else
|
|
182
|
-
if (
|
|
183
|
-
|
|
184
|
-
var
|
|
185
|
-
return
|
|
181
|
+
else y(d);
|
|
182
|
+
if (D.call(i, "key")) {
|
|
183
|
+
d = e(r);
|
|
184
|
+
var j = Object.keys(i).filter(function(pe) {
|
|
185
|
+
return pe !== "key";
|
|
186
186
|
});
|
|
187
|
-
|
|
187
|
+
p = 0 < j.length ? "{key: someKey, " + j.join(": ..., ") + ": ...}" : "{key: someKey}", V[d + p] || (j = 0 < j.length ? "{" + j.join(": ..., ") + ": ...}" : "{}", console.error(
|
|
188
188
|
`A props object containing a "key" prop is being spread into JSX:
|
|
189
189
|
let props = %s;
|
|
190
190
|
<%s {...props} />
|
|
191
191
|
React keys must be passed directly to JSX without using spread:
|
|
192
192
|
let props = %s;
|
|
193
193
|
<%s key={someKey} {...props} />`,
|
|
194
|
-
d,
|
|
195
194
|
p,
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
195
|
+
d,
|
|
196
|
+
j,
|
|
197
|
+
d
|
|
198
|
+
), V[d + p] = !0);
|
|
199
199
|
}
|
|
200
|
-
if (
|
|
200
|
+
if (d = null, m !== void 0 && (n(m), d = "" + m), u(i) && (n(i.key), d = "" + i.key), "key" in i) {
|
|
201
201
|
m = {};
|
|
202
|
-
for (var
|
|
203
|
-
|
|
202
|
+
for (var L in i)
|
|
203
|
+
L !== "key" && (m[L] = i[L]);
|
|
204
204
|
} else m = i;
|
|
205
|
-
return
|
|
205
|
+
return d && c(
|
|
206
206
|
m,
|
|
207
207
|
typeof r == "function" ? r.displayName || r.name || "Unknown" : r
|
|
208
|
-
),
|
|
208
|
+
), x(
|
|
209
209
|
r,
|
|
210
|
-
|
|
210
|
+
d,
|
|
211
211
|
m,
|
|
212
212
|
o(),
|
|
213
|
-
|
|
214
|
-
|
|
213
|
+
A,
|
|
214
|
+
I
|
|
215
215
|
);
|
|
216
216
|
}
|
|
217
|
-
function
|
|
218
|
-
|
|
217
|
+
function y(r) {
|
|
218
|
+
g(r) ? r._store && (r._store.validated = 1) : typeof r == "object" && r !== null && r.$$typeof === F && (r._payload.status === "fulfilled" ? g(r._payload.value) && r._payload.value._store && (r._payload.value._store.validated = 1) : r._store && (r._store.validated = 1));
|
|
219
219
|
}
|
|
220
|
-
function
|
|
221
|
-
return typeof r == "object" && r !== null && r.$$typeof ===
|
|
220
|
+
function g(r) {
|
|
221
|
+
return typeof r == "object" && r !== null && r.$$typeof === v;
|
|
222
222
|
}
|
|
223
|
-
var
|
|
223
|
+
var b = X, v = Symbol.for("react.transitional.element"), w = Symbol.for("react.portal"), O = Symbol.for("react.fragment"), re = Symbol.for("react.strict_mode"), te = Symbol.for("react.profiler"), ne = Symbol.for("react.consumer"), ae = Symbol.for("react.context"), se = Symbol.for("react.forward_ref"), oe = Symbol.for("react.suspense"), ue = Symbol.for("react.suspense_list"), le = Symbol.for("react.memo"), F = Symbol.for("react.lazy"), ie = Symbol.for("react.activity"), ce = Symbol.for("react.client.reference"), P = b.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, D = Object.prototype.hasOwnProperty, me = Array.isArray, C = console.createTask ? console.createTask : function() {
|
|
224
224
|
return null;
|
|
225
225
|
};
|
|
226
|
-
|
|
226
|
+
b = {
|
|
227
227
|
react_stack_bottom_frame: function(r) {
|
|
228
228
|
return r();
|
|
229
229
|
}
|
|
230
230
|
};
|
|
231
|
-
var
|
|
232
|
-
|
|
231
|
+
var q, z = {}, Y = b.react_stack_bottom_frame.bind(
|
|
232
|
+
b,
|
|
233
233
|
s
|
|
234
|
-
)(),
|
|
235
|
-
|
|
236
|
-
var
|
|
237
|
-
return
|
|
234
|
+
)(), W = C(a(s)), V = {};
|
|
235
|
+
R.Fragment = O, R.jsx = function(r, i, m) {
|
|
236
|
+
var p = 1e4 > P.recentlyCreatedOwnerStacks++;
|
|
237
|
+
return E(
|
|
238
238
|
r,
|
|
239
239
|
i,
|
|
240
240
|
m,
|
|
241
241
|
!1,
|
|
242
|
-
|
|
243
|
-
|
|
242
|
+
p ? Error("react-stack-top-frame") : Y,
|
|
243
|
+
p ? C(a(r)) : W
|
|
244
244
|
);
|
|
245
|
-
},
|
|
246
|
-
var
|
|
247
|
-
return
|
|
245
|
+
}, R.jsxs = function(r, i, m) {
|
|
246
|
+
var p = 1e4 > P.recentlyCreatedOwnerStacks++;
|
|
247
|
+
return E(
|
|
248
248
|
r,
|
|
249
249
|
i,
|
|
250
250
|
m,
|
|
251
251
|
!0,
|
|
252
|
-
|
|
253
|
-
|
|
252
|
+
p ? Error("react-stack-top-frame") : Y,
|
|
253
|
+
p ? C(a(r)) : W
|
|
254
254
|
);
|
|
255
255
|
};
|
|
256
|
-
})()),
|
|
256
|
+
})()), R;
|
|
257
257
|
}
|
|
258
|
-
var
|
|
258
|
+
var J;
|
|
259
259
|
function Re() {
|
|
260
|
-
return
|
|
260
|
+
return J || (J = 1, process.env.NODE_ENV === "production" ? S.exports = je() : S.exports = _e()), S.exports;
|
|
261
261
|
}
|
|
262
262
|
var l = Re();
|
|
263
|
-
function f(e,
|
|
264
|
-
return e ? typeof e == "string" ? e : e[
|
|
263
|
+
function f(e, t = "en") {
|
|
264
|
+
return e ? typeof e == "string" ? e : e[t] || e.en || Object.values(e)[0] || "" : "";
|
|
265
265
|
}
|
|
266
|
-
function
|
|
267
|
-
return e ? e.map((
|
|
268
|
-
value:
|
|
269
|
-
label: f(
|
|
266
|
+
function $(e, t = "en") {
|
|
267
|
+
return e ? e.map((n) => typeof n == "string" ? { value: n, label: n } : {
|
|
268
|
+
value: n.value,
|
|
269
|
+
label: f(n.label, t)
|
|
270
270
|
}) : [];
|
|
271
271
|
}
|
|
272
272
|
function Te({
|
|
273
273
|
field: e,
|
|
274
|
-
value:
|
|
275
|
-
onChange:
|
|
274
|
+
value: t,
|
|
275
|
+
onChange: n,
|
|
276
276
|
error: a,
|
|
277
277
|
locale: o = "en"
|
|
278
278
|
}) {
|
|
279
|
-
const s =
|
|
280
|
-
return /* @__PURE__ */ l.jsxs(
|
|
279
|
+
const s = $(e.options || [], o);
|
|
280
|
+
return /* @__PURE__ */ l.jsxs(H, { fullWidth: !0, children: [
|
|
281
281
|
/* @__PURE__ */ l.jsx(fe, { id: `${e.id}-label`, children: f(e.label, o) }),
|
|
282
282
|
/* @__PURE__ */ l.jsx(
|
|
283
283
|
be,
|
|
284
284
|
{
|
|
285
285
|
labelId: `${e.id}-label`,
|
|
286
|
-
value:
|
|
286
|
+
value: t,
|
|
287
287
|
id: e.id,
|
|
288
288
|
name: e.id,
|
|
289
|
-
onChange: (u) =>
|
|
289
|
+
onChange: (u) => n(u.target.value),
|
|
290
290
|
label: f(e.label, o),
|
|
291
291
|
error: !!a,
|
|
292
292
|
children: s?.map((u) => /* @__PURE__ */ l.jsx(he, { value: u.value, children: u.label }, u.label))
|
|
293
293
|
}
|
|
294
294
|
),
|
|
295
|
-
a && /* @__PURE__ */ l.jsx(
|
|
295
|
+
a && /* @__PURE__ */ l.jsx(T, { variant: "caption", color: "error", children: a })
|
|
296
296
|
] });
|
|
297
297
|
}
|
|
298
|
-
function
|
|
298
|
+
function Ae({
|
|
299
299
|
field: e,
|
|
300
|
-
value:
|
|
301
|
-
onChange:
|
|
300
|
+
value: t,
|
|
301
|
+
onChange: n,
|
|
302
302
|
error: a,
|
|
303
303
|
locale: o
|
|
304
304
|
}) {
|
|
305
305
|
return console.log("error", a), /* @__PURE__ */ l.jsx(
|
|
306
|
-
|
|
306
|
+
k,
|
|
307
307
|
{
|
|
308
308
|
fullWidth: !0,
|
|
309
309
|
label: f(e.label, o),
|
|
310
310
|
placeholder: f(e.placeholder || "", o),
|
|
311
|
-
value:
|
|
311
|
+
value: t || "",
|
|
312
312
|
name: e.id,
|
|
313
|
-
onChange: (s) =>
|
|
313
|
+
onChange: (s) => n(s.target.value),
|
|
314
314
|
disabled: e.disabled,
|
|
315
315
|
type: e.type,
|
|
316
316
|
slotProps: {
|
|
@@ -323,49 +323,49 @@ function Se({
|
|
|
323
323
|
}
|
|
324
324
|
);
|
|
325
325
|
}
|
|
326
|
-
function
|
|
326
|
+
function Se({
|
|
327
327
|
field: e,
|
|
328
|
-
value:
|
|
329
|
-
onChange:
|
|
328
|
+
value: t,
|
|
329
|
+
onChange: n,
|
|
330
330
|
error: a,
|
|
331
331
|
locale: o
|
|
332
332
|
}) {
|
|
333
333
|
return /* @__PURE__ */ l.jsxs(l.Fragment, { children: [
|
|
334
334
|
/* @__PURE__ */ l.jsx(
|
|
335
|
-
|
|
335
|
+
Z,
|
|
336
336
|
{
|
|
337
337
|
name: e.id,
|
|
338
338
|
control: /* @__PURE__ */ l.jsx(
|
|
339
|
-
|
|
339
|
+
xe,
|
|
340
340
|
{
|
|
341
|
-
checked: !!
|
|
342
|
-
onChange: (s) =>
|
|
341
|
+
checked: !!t,
|
|
342
|
+
onChange: (s) => n(s.target.checked),
|
|
343
343
|
disabled: e.disabled
|
|
344
344
|
}
|
|
345
345
|
),
|
|
346
346
|
label: f(e.label, o)
|
|
347
347
|
}
|
|
348
348
|
),
|
|
349
|
-
a && /* @__PURE__ */ l.jsx(
|
|
349
|
+
a && /* @__PURE__ */ l.jsx(Q, { children: a })
|
|
350
350
|
] });
|
|
351
351
|
}
|
|
352
352
|
const ke = ({
|
|
353
353
|
field: e,
|
|
354
|
-
value:
|
|
355
|
-
onChange:
|
|
354
|
+
value: t,
|
|
355
|
+
onChange: n,
|
|
356
356
|
error: a,
|
|
357
357
|
locale: o
|
|
358
358
|
}) => {
|
|
359
|
-
const s =
|
|
359
|
+
const s = $(e.options || [], o);
|
|
360
360
|
return /* @__PURE__ */ l.jsx(
|
|
361
|
-
|
|
361
|
+
K,
|
|
362
362
|
{
|
|
363
363
|
fullWidth: !0,
|
|
364
364
|
options: s || [],
|
|
365
|
-
value:
|
|
366
|
-
onChange: (u, c) =>
|
|
365
|
+
value: t || null,
|
|
366
|
+
onChange: (u, c) => n(c),
|
|
367
367
|
renderInput: (u) => /* @__PURE__ */ l.jsx(
|
|
368
|
-
|
|
368
|
+
k,
|
|
369
369
|
{
|
|
370
370
|
...u,
|
|
371
371
|
name: e.id,
|
|
@@ -383,22 +383,22 @@ const ke = ({
|
|
|
383
383
|
);
|
|
384
384
|
}, $e = ({
|
|
385
385
|
field: e,
|
|
386
|
-
value:
|
|
387
|
-
onChange:
|
|
386
|
+
value: t,
|
|
387
|
+
onChange: n,
|
|
388
388
|
error: a,
|
|
389
389
|
locale: o
|
|
390
390
|
}) => {
|
|
391
|
-
const s =
|
|
391
|
+
const s = $(e.options || [], o);
|
|
392
392
|
return /* @__PURE__ */ l.jsx(
|
|
393
|
-
|
|
393
|
+
K,
|
|
394
394
|
{
|
|
395
395
|
multiple: !0,
|
|
396
396
|
fullWidth: !0,
|
|
397
397
|
options: s || [],
|
|
398
|
-
value:
|
|
399
|
-
onChange: (u, c) =>
|
|
398
|
+
value: t || [],
|
|
399
|
+
onChange: (u, c) => n(c),
|
|
400
400
|
renderInput: (u) => /* @__PURE__ */ l.jsx(
|
|
401
|
-
|
|
401
|
+
k,
|
|
402
402
|
{
|
|
403
403
|
...u,
|
|
404
404
|
name: e.id,
|
|
@@ -416,20 +416,20 @@ const ke = ({
|
|
|
416
416
|
);
|
|
417
417
|
}, we = ({
|
|
418
418
|
field: e,
|
|
419
|
-
value:
|
|
420
|
-
onChange:
|
|
419
|
+
value: t,
|
|
420
|
+
onChange: n,
|
|
421
421
|
error: a,
|
|
422
422
|
locale: o = "en"
|
|
423
423
|
}) => /* @__PURE__ */ l.jsx(
|
|
424
|
-
|
|
424
|
+
k,
|
|
425
425
|
{
|
|
426
426
|
fullWidth: !0,
|
|
427
427
|
multiline: !0,
|
|
428
428
|
rows: e.rows || 4,
|
|
429
429
|
label: f(e.label, o),
|
|
430
430
|
placeholder: f(e.placeholder || "", o),
|
|
431
|
-
value:
|
|
432
|
-
onChange: (s) =>
|
|
431
|
+
value: t || "",
|
|
432
|
+
onChange: (s) => n(s.target.value),
|
|
433
433
|
required: !!e.validations?.required,
|
|
434
434
|
disabled: e.disabled,
|
|
435
435
|
error: !!a,
|
|
@@ -437,14 +437,14 @@ const ke = ({
|
|
|
437
437
|
}
|
|
438
438
|
), Oe = ({
|
|
439
439
|
field: e,
|
|
440
|
-
value:
|
|
441
|
-
onChange:
|
|
440
|
+
value: t,
|
|
441
|
+
onChange: n,
|
|
442
442
|
error: a,
|
|
443
443
|
locale: o = "en"
|
|
444
444
|
}) => {
|
|
445
|
-
const s =
|
|
446
|
-
return /* @__PURE__ */ l.jsxs(
|
|
447
|
-
/* @__PURE__ */ l.jsxs(
|
|
445
|
+
const s = $(e.options || [], o);
|
|
446
|
+
return /* @__PURE__ */ l.jsxs(H, { component: "fieldset", fullWidth: !0, error: !!a, children: [
|
|
447
|
+
/* @__PURE__ */ l.jsxs(ve, { component: "legend", children: [
|
|
448
448
|
f(e.label, o),
|
|
449
449
|
e.validations?.required ? " *" : ""
|
|
450
450
|
] }),
|
|
@@ -452,12 +452,12 @@ const ke = ({
|
|
|
452
452
|
ge,
|
|
453
453
|
{
|
|
454
454
|
row: e.layout?.direction === "row" || !1,
|
|
455
|
-
value:
|
|
456
|
-
onChange: (u) =>
|
|
455
|
+
value: t || "",
|
|
456
|
+
onChange: (u) => n(u.target.value),
|
|
457
457
|
children: (s || []).map((u) => /* @__PURE__ */ l.jsx(
|
|
458
|
-
|
|
458
|
+
Z,
|
|
459
459
|
{
|
|
460
|
-
value: u,
|
|
460
|
+
value: u.value,
|
|
461
461
|
control: /* @__PURE__ */ l.jsx(Ee, {}),
|
|
462
462
|
label: u.label,
|
|
463
463
|
disabled: e.disabled
|
|
@@ -466,12 +466,12 @@ const ke = ({
|
|
|
466
466
|
))
|
|
467
467
|
}
|
|
468
468
|
),
|
|
469
|
-
a && /* @__PURE__ */ l.jsx(
|
|
469
|
+
a && /* @__PURE__ */ l.jsx(Q, { children: a })
|
|
470
470
|
] });
|
|
471
471
|
}, Fe = ({
|
|
472
472
|
field: e,
|
|
473
|
-
value:
|
|
474
|
-
onChange:
|
|
473
|
+
value: t,
|
|
474
|
+
onChange: n,
|
|
475
475
|
error: a,
|
|
476
476
|
locale: o = "en"
|
|
477
477
|
}) => {
|
|
@@ -482,11 +482,11 @@ const ke = ({
|
|
|
482
482
|
case "password":
|
|
483
483
|
case "number":
|
|
484
484
|
return /* @__PURE__ */ l.jsx(
|
|
485
|
-
|
|
485
|
+
Ae,
|
|
486
486
|
{
|
|
487
487
|
field: e,
|
|
488
|
-
value:
|
|
489
|
-
onChange:
|
|
488
|
+
value: t,
|
|
489
|
+
onChange: n,
|
|
490
490
|
error: a,
|
|
491
491
|
locale: o
|
|
492
492
|
}
|
|
@@ -496,8 +496,8 @@ const ke = ({
|
|
|
496
496
|
Te,
|
|
497
497
|
{
|
|
498
498
|
field: e,
|
|
499
|
-
value:
|
|
500
|
-
onChange:
|
|
499
|
+
value: t,
|
|
500
|
+
onChange: n,
|
|
501
501
|
error: a,
|
|
502
502
|
locale: o
|
|
503
503
|
}
|
|
@@ -507,8 +507,8 @@ const ke = ({
|
|
|
507
507
|
ke,
|
|
508
508
|
{
|
|
509
509
|
field: e,
|
|
510
|
-
value:
|
|
511
|
-
onChange:
|
|
510
|
+
value: t,
|
|
511
|
+
onChange: n,
|
|
512
512
|
error: a,
|
|
513
513
|
locale: o
|
|
514
514
|
}
|
|
@@ -518,19 +518,19 @@ const ke = ({
|
|
|
518
518
|
$e,
|
|
519
519
|
{
|
|
520
520
|
field: e,
|
|
521
|
-
value:
|
|
522
|
-
onChange:
|
|
521
|
+
value: t,
|
|
522
|
+
onChange: n,
|
|
523
523
|
error: a,
|
|
524
524
|
locale: o
|
|
525
525
|
}
|
|
526
526
|
);
|
|
527
527
|
case "checkbox":
|
|
528
528
|
return /* @__PURE__ */ l.jsx(
|
|
529
|
-
|
|
529
|
+
Se,
|
|
530
530
|
{
|
|
531
531
|
field: e,
|
|
532
|
-
value:
|
|
533
|
-
onChange:
|
|
532
|
+
value: t,
|
|
533
|
+
onChange: n,
|
|
534
534
|
error: a,
|
|
535
535
|
locale: o
|
|
536
536
|
}
|
|
@@ -540,8 +540,8 @@ const ke = ({
|
|
|
540
540
|
we,
|
|
541
541
|
{
|
|
542
542
|
field: e,
|
|
543
|
-
value:
|
|
544
|
-
onChange:
|
|
543
|
+
value: t,
|
|
544
|
+
onChange: n,
|
|
545
545
|
error: a,
|
|
546
546
|
locale: o
|
|
547
547
|
}
|
|
@@ -551,8 +551,8 @@ const ke = ({
|
|
|
551
551
|
Oe,
|
|
552
552
|
{
|
|
553
553
|
field: e,
|
|
554
|
-
value:
|
|
555
|
-
onChange:
|
|
554
|
+
value: t,
|
|
555
|
+
onChange: n,
|
|
556
556
|
error: a,
|
|
557
557
|
locale: o
|
|
558
558
|
}
|
|
@@ -565,8 +565,8 @@ const ke = ({
|
|
|
565
565
|
}
|
|
566
566
|
}, Pe = ({
|
|
567
567
|
field: e,
|
|
568
|
-
value:
|
|
569
|
-
onChange:
|
|
568
|
+
value: t,
|
|
569
|
+
onChange: n,
|
|
570
570
|
error: a,
|
|
571
571
|
renderers: o = {},
|
|
572
572
|
locale: s = "en"
|
|
@@ -576,25 +576,25 @@ const ke = ({
|
|
|
576
576
|
u,
|
|
577
577
|
{
|
|
578
578
|
field: e,
|
|
579
|
-
value:
|
|
580
|
-
onChange:
|
|
579
|
+
value: t,
|
|
580
|
+
onChange: n,
|
|
581
581
|
error: a,
|
|
582
582
|
locale: s
|
|
583
583
|
}
|
|
584
584
|
);
|
|
585
585
|
};
|
|
586
586
|
function Ce(e) {
|
|
587
|
-
const
|
|
587
|
+
const t = e ?? 12;
|
|
588
588
|
return {
|
|
589
589
|
xs: 12,
|
|
590
590
|
// always full width on mobile
|
|
591
|
-
sm:
|
|
591
|
+
sm: t,
|
|
592
592
|
// use span for tablet
|
|
593
|
-
md:
|
|
593
|
+
md: t,
|
|
594
594
|
// use span for desktop
|
|
595
|
-
lg:
|
|
595
|
+
lg: t,
|
|
596
596
|
// use span for large screens
|
|
597
|
-
xl:
|
|
597
|
+
xl: t
|
|
598
598
|
};
|
|
599
599
|
}
|
|
600
600
|
const ze = {
|
|
@@ -604,61 +604,61 @@ const ze = {
|
|
|
604
604
|
* @param value - The field value to validate
|
|
605
605
|
* @returns Error message if validation fails, null otherwise
|
|
606
606
|
*/
|
|
607
|
-
required: (e,
|
|
607
|
+
required: (e, t) => e.required && (t == null || t === "") ? `${e.label} is required` : null,
|
|
608
608
|
/**
|
|
609
609
|
* Validates that a number field meets the minimum value requirement.
|
|
610
610
|
* @param field - The field definition
|
|
611
611
|
* @param value - The field value to validate
|
|
612
612
|
* @returns Error message if validation fails, null otherwise
|
|
613
613
|
*/
|
|
614
|
-
min: (e,
|
|
614
|
+
min: (e, t) => e.type === "number" && e.min !== void 0 && t < e.min ? `${e.label} must be at least ${e.min}` : null,
|
|
615
615
|
/**
|
|
616
616
|
* Validates that a number field does not exceed the maximum value.
|
|
617
617
|
* @param field - The field definition
|
|
618
618
|
* @param value - The field value to validate
|
|
619
619
|
* @returns Error message if validation fails, null otherwise
|
|
620
620
|
*/
|
|
621
|
-
max: (e,
|
|
621
|
+
max: (e, t) => e.type === "number" && e.max !== void 0 && t > e.max ? `${e.label} must be at most ${e.max}` : null,
|
|
622
622
|
/**
|
|
623
623
|
* Validates that a string field meets the minimum length requirement.
|
|
624
624
|
* @param field - The field definition
|
|
625
625
|
* @param value - The field value to validate
|
|
626
626
|
* @returns Error message if validation fails, null otherwise
|
|
627
627
|
*/
|
|
628
|
-
minLength: (e,
|
|
628
|
+
minLength: (e, t) => typeof t == "string" && e.minLength !== void 0 && t.length < e.minLength ? `${e.label} must be at least ${e.minLength} characters` : null,
|
|
629
629
|
/**
|
|
630
630
|
* Validates that a string field does not exceed the maximum length.
|
|
631
631
|
* @param field - The field definition
|
|
632
632
|
* @param value - The field value to validate
|
|
633
633
|
* @returns Error message if validation fails, null otherwise
|
|
634
634
|
*/
|
|
635
|
-
maxLength: (e,
|
|
635
|
+
maxLength: (e, t) => typeof t == "string" && e.maxLength !== void 0 && t.length > e.maxLength ? `${e.label} must be at most ${e.maxLength} characters` : null,
|
|
636
636
|
/**
|
|
637
637
|
* Validates that a string field matches the specified regex pattern.
|
|
638
638
|
* @param field - The field definition
|
|
639
639
|
* @param value - The field value to validate
|
|
640
640
|
* @returns Error message if validation fails, null otherwise
|
|
641
641
|
*/
|
|
642
|
-
pattern: (e,
|
|
642
|
+
pattern: (e, t) => e.pattern && typeof t == "string" && !e.pattern.test(t) ? `${e.label} is invalid` : null,
|
|
643
643
|
/**
|
|
644
644
|
* Validates that a select field value is one of the allowed options.
|
|
645
645
|
* @param field - The field definition
|
|
646
646
|
* @param value - The field value to validate
|
|
647
647
|
* @returns Error message if validation fails, null otherwise
|
|
648
648
|
*/
|
|
649
|
-
options: (e,
|
|
649
|
+
options: (e, t) => e.type === "select" && e.options && !e.options.includes(t) ? `${e.label} must be one of: ${e.options.join(", ")}` : null,
|
|
650
650
|
/**
|
|
651
651
|
* Validates that a date field falls within the specified date range.
|
|
652
652
|
* @param field - The field definition
|
|
653
653
|
* @param value - The field value to validate
|
|
654
654
|
* @returns Error message if validation fails, null otherwise
|
|
655
655
|
*/
|
|
656
|
-
dateRange: (e,
|
|
657
|
-
if (e.type === "date" &&
|
|
658
|
-
const
|
|
659
|
-
if (e.minDate &&
|
|
656
|
+
dateRange: (e, t) => {
|
|
657
|
+
if (e.type === "date" && t) {
|
|
658
|
+
const n = new Date(t);
|
|
659
|
+
if (e.minDate && n < new Date(e.minDate))
|
|
660
660
|
return `${e.label} must be after ${e.minDate}`;
|
|
661
|
-
if (e.maxDate &&
|
|
661
|
+
if (e.maxDate && n > new Date(e.maxDate))
|
|
662
662
|
return `${e.label} must be before ${e.maxDate}`;
|
|
663
663
|
}
|
|
664
664
|
return null;
|
|
@@ -669,63 +669,63 @@ const ze = {
|
|
|
669
669
|
* @param value - The field value to validate
|
|
670
670
|
* @returns Error message if validation fails, null otherwise
|
|
671
671
|
*/
|
|
672
|
-
customValidator: (e,
|
|
672
|
+
customValidator: (e, t) => {
|
|
673
673
|
if (e.customValidator && typeof e.customValidator == "function") {
|
|
674
|
-
const
|
|
675
|
-
if (typeof
|
|
676
|
-
return
|
|
674
|
+
const n = e.customValidator(t);
|
|
675
|
+
if (typeof n == "string")
|
|
676
|
+
return n;
|
|
677
677
|
}
|
|
678
678
|
return null;
|
|
679
679
|
}
|
|
680
|
-
}, Ie = (e,
|
|
680
|
+
}, Ie = (e, t, n = "en") => {
|
|
681
681
|
const a = {};
|
|
682
682
|
return e.sections.forEach((o) => {
|
|
683
683
|
o.fields.forEach((s) => {
|
|
684
|
-
const u =
|
|
684
|
+
const u = ee(e, t, s.id);
|
|
685
685
|
u.length > 0 && (a[s.id] = u);
|
|
686
686
|
});
|
|
687
687
|
}), a;
|
|
688
|
-
},
|
|
689
|
-
const o = e.sections.flatMap((
|
|
688
|
+
}, ee = (e, t, n, a = "en") => {
|
|
689
|
+
const o = e.sections.flatMap((x) => x.fields).find((x) => x.id === n);
|
|
690
690
|
if (!o) return [];
|
|
691
|
-
const s = o.validations || {}, u = n
|
|
691
|
+
const s = o.validations || {}, u = t[n], c = [], h = f(o.label, a);
|
|
692
692
|
if (s.required && (u == null || u === "") && c.push(
|
|
693
693
|
typeof s.required == "string" ? s.required : `${h} is required`
|
|
694
694
|
), s.min !== void 0 && typeof u == "number" && u < s.min && c.push(`${h} must be at least ${s.min}`), s.max !== void 0 && typeof u == "number" && u > s.max && c.push(`${h} must be at most ${s.max}`), s.minLength !== void 0 && typeof u == "string" && u.length < s.minLength && c.push(`${h} must be at least ${s.minLength} characters`), s.maxLength !== void 0 && typeof u == "string" && u.length > s.maxLength && c.push(`${h} must be at most ${s.maxLength} characters`), s.pattern && typeof u == "string" && !s.pattern.test(u) && c.push(`${h} is invalid`), s.validate) {
|
|
695
|
-
const
|
|
696
|
-
|
|
695
|
+
const x = s.validate(u);
|
|
696
|
+
x && c.push(f(x, a));
|
|
697
697
|
}
|
|
698
698
|
return c;
|
|
699
699
|
};
|
|
700
|
-
function
|
|
700
|
+
function N(e, t) {
|
|
701
701
|
if (!e)
|
|
702
702
|
return !0;
|
|
703
703
|
if ("field" in e) {
|
|
704
|
-
let
|
|
705
|
-
return Array.isArray(
|
|
704
|
+
let n = t[e.field] ?? "";
|
|
705
|
+
return Array.isArray(n) ? n = n.map((a) => a.value ?? "") : typeof n == "object" && n !== null && (n = n.value ?? ""), e.equals !== void 0 ? n === e.equals : e.notEquals !== void 0 ? n !== e.notEquals : e.in !== void 0 ? Array.isArray(n) ? e.in ? n.some((a) => e.in.includes(a)) : !1 : e.in.includes(n) : e.notIn !== void 0 ? Array.isArray(n) ? n.every((a) => !e.notIn.includes(a)) : !e.notIn.includes(n) : e.greaterThan !== void 0 ? n > e.greaterThan : e.lessThan !== void 0 ? n < e.lessThan : !0;
|
|
706
706
|
}
|
|
707
707
|
if ("operator" in e) {
|
|
708
708
|
if (e.operator === "AND")
|
|
709
709
|
return e.conditions.every(
|
|
710
|
-
(a) =>
|
|
710
|
+
(a) => N(a, t)
|
|
711
711
|
);
|
|
712
712
|
if (e.operator === "OR")
|
|
713
713
|
return e.conditions.some(
|
|
714
|
-
(
|
|
714
|
+
(n) => N(n, t)
|
|
715
715
|
);
|
|
716
716
|
}
|
|
717
717
|
return !1;
|
|
718
718
|
}
|
|
719
719
|
const Le = ({
|
|
720
720
|
section: e,
|
|
721
|
-
values:
|
|
722
|
-
onChange:
|
|
721
|
+
values: t,
|
|
722
|
+
onChange: n,
|
|
723
723
|
renderers: a,
|
|
724
724
|
validateField: o,
|
|
725
725
|
locale: s = "en"
|
|
726
|
-
}) => /* @__PURE__ */ l.jsxs(
|
|
726
|
+
}) => /* @__PURE__ */ l.jsxs(ye, { mb: 2, children: [
|
|
727
727
|
e.heading && /* @__PURE__ */ l.jsx(
|
|
728
|
-
|
|
728
|
+
T,
|
|
729
729
|
{
|
|
730
730
|
variant: "h6",
|
|
731
731
|
sx: {
|
|
@@ -737,7 +737,7 @@ const Le = ({
|
|
|
737
737
|
}
|
|
738
738
|
),
|
|
739
739
|
e.description && /* @__PURE__ */ l.jsx(
|
|
740
|
-
|
|
740
|
+
T,
|
|
741
741
|
{
|
|
742
742
|
variant: "body2",
|
|
743
743
|
sx: {
|
|
@@ -748,17 +748,17 @@ const Le = ({
|
|
|
748
748
|
children: f(e.description, s)
|
|
749
749
|
}
|
|
750
750
|
),
|
|
751
|
-
/* @__PURE__ */ l.jsx(
|
|
752
|
-
(u) =>
|
|
753
|
-
|
|
751
|
+
/* @__PURE__ */ l.jsx(B, { container: !0, spacing: 2, children: e.fields.map(
|
|
752
|
+
(u) => N(u.visibleWhen, t) && /* @__PURE__ */ l.jsx(
|
|
753
|
+
B,
|
|
754
754
|
{
|
|
755
755
|
size: Ce(u.layout?.cols),
|
|
756
756
|
children: /* @__PURE__ */ l.jsx(
|
|
757
757
|
Pe,
|
|
758
758
|
{
|
|
759
759
|
field: u,
|
|
760
|
-
value:
|
|
761
|
-
onChange: (c) =>
|
|
760
|
+
value: t[u.id],
|
|
761
|
+
onChange: (c) => n(u.id, c),
|
|
762
762
|
renderers: a,
|
|
763
763
|
error: o(u.id)?.join(","),
|
|
764
764
|
locale: s
|
|
@@ -769,42 +769,45 @@ const Le = ({
|
|
|
769
769
|
)
|
|
770
770
|
) })
|
|
771
771
|
] });
|
|
772
|
-
function Ne(e,
|
|
773
|
-
const [
|
|
772
|
+
function Ne(e, t = "en", n) {
|
|
773
|
+
const [a, o] = M({}), [s, u] = M({});
|
|
774
774
|
return {
|
|
775
775
|
/** Current form values for all fields */
|
|
776
|
-
values:
|
|
776
|
+
values: a,
|
|
777
777
|
/** Function to update a field value */
|
|
778
|
-
handleChange: (
|
|
779
|
-
|
|
778
|
+
handleChange: (g, b) => {
|
|
779
|
+
if (o((v) => ({ ...v, [g]: b })), u((v) => ({ ...v, [g]: null })), n) {
|
|
780
|
+
let v = b;
|
|
781
|
+
Array.isArray(b) ? v = b.map((w) => w.value ?? "") : typeof b == "object" && b !== null && (v = b.value ?? ""), n(g, v);
|
|
782
|
+
}
|
|
780
783
|
},
|
|
781
784
|
/** Function to validate all fields */
|
|
782
|
-
validateAll: () => Ie(e,
|
|
785
|
+
validateAll: () => Ie(e, a, t),
|
|
783
786
|
/** Function to get all current form values */
|
|
784
|
-
getValues: () =>
|
|
787
|
+
getValues: () => a,
|
|
785
788
|
/** Function to get all current form errors */
|
|
786
|
-
getErrors: () =>
|
|
789
|
+
getErrors: () => s,
|
|
787
790
|
/** Function to validate a specific field */
|
|
788
|
-
validateField: (
|
|
791
|
+
validateField: (g) => ee(e, a, g, t)
|
|
789
792
|
};
|
|
790
793
|
}
|
|
791
|
-
const Ye =
|
|
794
|
+
const Ye = X.forwardRef(({ dto: e, renderers: t, locale: n = "en", handleChangeCallback: a }, o) => {
|
|
792
795
|
const {
|
|
793
|
-
values:
|
|
794
|
-
handleChange:
|
|
795
|
-
getValues:
|
|
796
|
-
getErrors:
|
|
797
|
-
validateAll:
|
|
798
|
-
validateField:
|
|
799
|
-
} = Ne(e,
|
|
800
|
-
return
|
|
801
|
-
getValues:
|
|
802
|
-
getErrors:
|
|
803
|
-
validateAll:
|
|
804
|
-
validateField:
|
|
796
|
+
values: s,
|
|
797
|
+
handleChange: u,
|
|
798
|
+
getValues: c,
|
|
799
|
+
getErrors: h,
|
|
800
|
+
validateAll: x,
|
|
801
|
+
validateField: E
|
|
802
|
+
} = Ne(e, n, a);
|
|
803
|
+
return de(o, () => ({
|
|
804
|
+
getValues: c,
|
|
805
|
+
getErrors: h,
|
|
806
|
+
validateAll: x,
|
|
807
|
+
validateField: E
|
|
805
808
|
})), /* @__PURE__ */ l.jsxs(l.Fragment, { children: [
|
|
806
809
|
e.title && /* @__PURE__ */ l.jsx(
|
|
807
|
-
|
|
810
|
+
T,
|
|
808
811
|
{
|
|
809
812
|
variant: "h5",
|
|
810
813
|
color: "black",
|
|
@@ -813,11 +816,11 @@ const Ye = J.forwardRef(({ dto: e, renderers: n, locale: t = "en" }, a) => {
|
|
|
813
816
|
fontWeight: "bold"
|
|
814
817
|
},
|
|
815
818
|
gutterBottom: !0,
|
|
816
|
-
children: f(e.title,
|
|
819
|
+
children: f(e.title, n)
|
|
817
820
|
}
|
|
818
821
|
),
|
|
819
822
|
e.description && /* @__PURE__ */ l.jsx(
|
|
820
|
-
|
|
823
|
+
T,
|
|
821
824
|
{
|
|
822
825
|
component: "p",
|
|
823
826
|
sx: {
|
|
@@ -825,26 +828,26 @@ const Ye = J.forwardRef(({ dto: e, renderers: n, locale: t = "en" }, a) => {
|
|
|
825
828
|
},
|
|
826
829
|
color: "textSecondary",
|
|
827
830
|
gutterBottom: !0,
|
|
828
|
-
children: f(e.description,
|
|
831
|
+
children: f(e.description, n)
|
|
829
832
|
}
|
|
830
833
|
),
|
|
831
|
-
e.sections.map((
|
|
834
|
+
e.sections.map((y) => /* @__PURE__ */ l.jsx(
|
|
832
835
|
Le,
|
|
833
836
|
{
|
|
834
|
-
section:
|
|
835
|
-
values:
|
|
836
|
-
onChange:
|
|
837
|
-
renderers:
|
|
838
|
-
validateField:
|
|
839
|
-
locale:
|
|
837
|
+
section: y,
|
|
838
|
+
values: s,
|
|
839
|
+
onChange: u,
|
|
840
|
+
renderers: t,
|
|
841
|
+
validateField: E,
|
|
842
|
+
locale: n
|
|
840
843
|
},
|
|
841
|
-
|
|
844
|
+
y.id
|
|
842
845
|
))
|
|
843
846
|
] });
|
|
844
847
|
});
|
|
845
848
|
export {
|
|
846
849
|
ke as AutoCompleteField,
|
|
847
|
-
|
|
850
|
+
Se as CheckBoxInput,
|
|
848
851
|
Pe as Field,
|
|
849
852
|
Ye as FormBuilder,
|
|
850
853
|
$e as MultiAutoCompleteField,
|
|
@@ -852,9 +855,9 @@ export {
|
|
|
852
855
|
Le as Section,
|
|
853
856
|
Te as SelectInput,
|
|
854
857
|
we as TextAreaInput,
|
|
855
|
-
|
|
858
|
+
Ae as TextInput,
|
|
856
859
|
Ne as useFormBuilder,
|
|
857
860
|
Ie as validateAll,
|
|
858
|
-
|
|
861
|
+
ee as validateField,
|
|
859
862
|
ze as validationRules
|
|
860
863
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
(function(m,
|
|
1
|
+
(function(m,E){typeof exports=="object"&&typeof module<"u"?E(exports,require("react"),require("@mui/material")):typeof define=="function"&&define.amd?define(["exports","react","@mui/material"],E):(m=typeof globalThis<"u"?globalThis:m||self,E(m.ReactFormDTO={},m.React,m.MaterialUI))})(this,(function(m,E,c){"use strict";var k={exports:{}},A={};var Y;function oe(){if(Y)return A;Y=1;var e=Symbol.for("react.transitional.element"),t=Symbol.for("react.fragment");function n(a,o,s){var u=null;if(s!==void 0&&(u=""+s),o.key!==void 0&&(u=""+o.key),"key"in o){s={};for(var d in o)d!=="key"&&(s[d]=o[d])}else s=o;return o=s.ref,{$$typeof:e,type:a,key:u,ref:o!==void 0?o:null,props:s}}return A.Fragment=t,A.jsx=n,A.jsxs=n,A}var S={};var q;function ue(){return q||(q=1,process.env.NODE_ENV!=="production"&&(function(){function e(r){if(r==null)return null;if(typeof r=="function")return r.$$typeof===Te?null:r.displayName||r.name||null;if(typeof r=="string")return r;switch(r){case $:return"Fragment";case fe:return"Profiler";case me:return"StrictMode";case xe:return"Suspense";case ge:return"SuspenseList";case Ee:return"Activity"}if(typeof r=="object")switch(typeof r.tag=="number"&&console.error("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),r.$$typeof){case C:return"Portal";case he:return r.displayName||"Context";case be:return(r._context.displayName||"Context")+".Consumer";case ve:var i=r.render;return r=r.displayName,r||(r=i.displayName||i.name||"",r=r!==""?"ForwardRef("+r+")":"ForwardRef"),r;case ye:return i=r.displayName||null,i!==null?i:e(r.type)||"Memo";case I:i=r._payload,r=r._init;try{return e(r(i))}catch{}}return null}function t(r){return""+r}function n(r){try{t(r);var i=!1}catch{i=!0}if(i){i=console;var p=i.error,b=typeof Symbol=="function"&&Symbol.toStringTag&&r[Symbol.toStringTag]||r.constructor.name||"Object";return p.call(i,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",b),t(r)}}function a(r){if(r===$)return"<>";if(typeof r=="object"&&r!==null&&r.$$typeof===I)return"<...>";try{var i=e(r);return i?"<"+i+">":"<...>"}catch{return"<...>"}}function o(){var r=L.A;return r===null?null:r.getOwner()}function s(){return Error("react-stack-top-frame")}function u(r){if(ee.call(r,"key")){var i=Object.getOwnPropertyDescriptor(r,"key").get;if(i&&i.isReactWarning)return!1}return r.key!==void 0}function d(r,i){function p(){re||(re=!0,console.error("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",i))}p.isReactWarning=!0,Object.defineProperty(r,"key",{get:p,configurable:!0})}function x(){var r=e(this.type);return te[r]||(te[r]=!0,console.error("Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release.")),r=this.props.ref,r!==void 0?r:null}function g(r,i,p,b,O,D){var h=p.ref;return r={$$typeof:y,type:r,key:i,props:p,_owner:b},(h!==void 0?h:null)!==null?Object.defineProperty(r,"ref",{enumerable:!1,get:x}):Object.defineProperty(r,"ref",{enumerable:!1,value:null}),r._store={},Object.defineProperty(r._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:0}),Object.defineProperty(r,"_debugInfo",{configurable:!1,enumerable:!1,writable:!0,value:null}),Object.defineProperty(r,"_debugStack",{configurable:!1,enumerable:!1,writable:!0,value:O}),Object.defineProperty(r,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:D}),Object.freeze&&(Object.freeze(r.props),Object.freeze(r)),r}function j(r,i,p,b,O,D){var h=i.children;if(h!==void 0)if(b)if(je(h)){for(b=0;b<h.length;b++)R(h[b]);Object.freeze&&Object.freeze(h)}else console.error("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else R(h);if(ee.call(i,"key")){h=e(r);var _=Object.keys(i).filter(function(Re){return Re!=="key"});b=0<_.length?"{key: someKey, "+_.join(": ..., ")+": ...}":"{key: someKey}",se[h+b]||(_=0<_.length?"{"+_.join(": ..., ")+": ...}":"{}",console.error(`A props object containing a "key" prop is being spread into JSX:
|
|
2
2
|
let props = %s;
|
|
3
3
|
<%s {...props} />
|
|
4
4
|
React keys must be passed directly to JSX without using spread:
|
|
5
5
|
let props = %s;
|
|
6
|
-
<%s key={someKey} {...props} />`,b,h,j,h),ae[h+b]=!0)}if(h=null,p!==void 0&&(t(p),h=""+p),u(i)&&(t(i.key),h=""+i.key),"key"in i){p={};for(var N in i)N!=="key"&&(p[N]=i[N])}else p=i;return h&&d(p,typeof r=="function"?r.displayName||r.name||"Unknown":r),v(r,h,p,o(),F,L)}function E(r){k(r)?r._store&&(r._store.validated=1):typeof r=="object"&&r!==null&&r.$$typeof===P&&(r._payload.status==="fulfilled"?k(r._payload.value)&&r._payload.value._store&&(r._payload.value._store.validated=1):r._store&&(r._store.validated=1))}function k(r){return typeof r=="object"&&r!==null&&r.$$typeof===Q}var y=g,Q=Symbol.for("react.transitional.element"),pe=Symbol.for("react.portal"),C=Symbol.for("react.fragment"),me=Symbol.for("react.strict_mode"),fe=Symbol.for("react.profiler"),be=Symbol.for("react.consumer"),he=Symbol.for("react.context"),ve=Symbol.for("react.forward_ref"),xe=Symbol.for("react.suspense"),ge=Symbol.for("react.suspense_list"),ye=Symbol.for("react.memo"),P=Symbol.for("react.lazy"),Ee=Symbol.for("react.activity"),Te=Symbol.for("react.client.reference"),$=y.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,K=Object.prototype.hasOwnProperty,je=Array.isArray,I=console.createTask?console.createTask:function(){return null};y={react_stack_bottom_frame:function(r){return r()}};var ee,re={},te=y.react_stack_bottom_frame.bind(y,s)(),ne=I(a(s)),ae={};_.Fragment=C,_.jsx=function(r,i,p){var b=1e4>$.recentlyCreatedOwnerStacks++;return T(r,i,p,!1,b?Error("react-stack-top-frame"):te,b?I(a(r)):ne)},_.jsxs=function(r,i,p){var b=1e4>$.recentlyCreatedOwnerStacks++;return T(r,i,p,!0,b?Error("react-stack-top-frame"):te,b?I(a(r)):ne)}})()),_}var Y;function ue(){return Y||(Y=1,process.env.NODE_ENV==="production"?S.exports=se():S.exports=oe()),S.exports}var l=ue();function f(e,n="en"){return e?typeof e=="string"?e:e[n]||e.en||Object.values(e)[0]||"":""}function A(e,n="en"){return e?e.map(t=>typeof t=="string"?{value:t,label:t}:{value:t.value,label:f(t.label,n)}):[]}function q({field:e,value:n,onChange:t,error:a,locale:o="en"}){const s=A(e.options||[],o);return l.jsxs(c.FormControl,{fullWidth:!0,children:[l.jsx(c.InputLabel,{id:`${e.id}-label`,children:f(e.label,o)}),l.jsx(c.Select,{labelId:`${e.id}-label`,value:n,id:e.id,name:e.id,onChange:u=>t(u.target.value),label:f(e.label,o),error:!!a,children:s?.map(u=>l.jsx(c.MenuItem,{value:u.value,children:u.label},u.label))}),a&&l.jsx(c.Typography,{variant:"caption",color:"error",children:a})]})}function W({field:e,value:n,onChange:t,error:a,locale:o}){return console.log("error",a),l.jsx(c.TextField,{fullWidth:!0,label:f(e.label,o),placeholder:f(e.placeholder||"",o),value:n||"",name:e.id,onChange:s=>t(s.target.value),disabled:e.disabled,type:e.type,slotProps:{inputLabel:{shrink:e.type==="date"?!0:void 0}},error:!!a,helperText:a})}function M({field:e,value:n,onChange:t,error:a,locale:o}){return l.jsxs(l.Fragment,{children:[l.jsx(c.FormControlLabel,{name:e.id,control:l.jsx(c.Checkbox,{checked:!!n,onChange:s=>t(s.target.checked),disabled:e.disabled}),label:f(e.label,o)}),a&&l.jsx(c.FormHelperText,{children:a})]})}const V=({field:e,value:n,onChange:t,error:a,locale:o})=>{const s=A(e.options||[],o);return l.jsx(c.Autocomplete,{fullWidth:!0,options:s||[],value:n||null,onChange:(u,d)=>t(d),renderInput:u=>l.jsx(c.TextField,{...u,name:e.id,label:f(e.label,o),placeholder:f(e.placeholder||"",o),disabled:e.disabled,error:!!a,helperText:a})})},B=({field:e,value:n,onChange:t,error:a,locale:o})=>{const s=A(e.options||[],o);return l.jsx(c.Autocomplete,{multiple:!0,fullWidth:!0,options:s||[],value:n||[],onChange:(u,d)=>t(d),renderInput:u=>l.jsx(c.TextField,{...u,name:e.id,label:f(e.label,o),placeholder:f(e.placeholder||"",o),disabled:e.disabled,error:!!a,helperText:a})})},U=({field:e,value:n,onChange:t,error:a,locale:o="en"})=>l.jsx(c.TextField,{fullWidth:!0,multiline:!0,rows:e.rows||4,label:f(e.label,o),placeholder:f(e.placeholder||"",o),value:n||"",onChange:s=>t(s.target.value),required:!!e.validations?.required,disabled:e.disabled,error:!!a,helperText:a}),G=({field:e,value:n,onChange:t,error:a,locale:o="en"})=>{const s=A(e.options||[],o);return l.jsxs(c.FormControl,{component:"fieldset",fullWidth:!0,error:!!a,children:[l.jsxs(c.FormLabel,{component:"legend",children:[f(e.label,o),e.validations?.required?" *":""]}),l.jsx(c.RadioGroup,{row:e.layout?.direction==="row"||!1,value:n||"",onChange:u=>t(u.target.value),children:(s||[]).map(u=>l.jsx(c.FormControlLabel,{value:u,control:l.jsx(c.Radio,{}),label:u.label,disabled:e.disabled},u.label))}),a&&l.jsx(c.FormHelperText,{children:a})]})},le=({field:e,value:n,onChange:t,error:a,locale:o="en"})=>{switch(e.type){case"text":case"date":case"email":case"password":case"number":return l.jsx(W,{field:e,value:n,onChange:t,error:a,locale:o});case"select":return l.jsx(q,{field:e,value:n,onChange:t,error:a,locale:o});case"autocomplete":return l.jsx(V,{field:e,value:n,onChange:t,error:a,locale:o});case"multi-autocomplete":return l.jsx(B,{field:e,value:n,onChange:t,error:a,locale:o});case"checkbox":return l.jsx(M,{field:e,value:n,onChange:t,error:a,locale:o});case"textarea":return l.jsx(U,{field:e,value:n,onChange:t,error:a,locale:o});case"radio":return l.jsx(G,{field:e,value:n,onChange:t,error:a,locale:o});default:return l.jsxs("span",{children:["Unsupported field type: ",e.type]})}},J=({field:e,value:n,onChange:t,error:a,renderers:o={},locale:s="en"})=>{const u=o[e.type]||le;return l.jsx(u,{field:e,value:n,onChange:t,error:a,locale:s})};function ie(e){const n=e??12;return{xs:12,sm:n,md:n,lg:n,xl:n}}const ce={required:(e,n)=>e.required&&(n==null||n==="")?`${e.label} is required`:null,min:(e,n)=>e.type==="number"&&e.min!==void 0&&n<e.min?`${e.label} must be at least ${e.min}`:null,max:(e,n)=>e.type==="number"&&e.max!==void 0&&n>e.max?`${e.label} must be at most ${e.max}`:null,minLength:(e,n)=>typeof n=="string"&&e.minLength!==void 0&&n.length<e.minLength?`${e.label} must be at least ${e.minLength} characters`:null,maxLength:(e,n)=>typeof n=="string"&&e.maxLength!==void 0&&n.length>e.maxLength?`${e.label} must be at most ${e.maxLength} characters`:null,pattern:(e,n)=>e.pattern&&typeof n=="string"&&!e.pattern.test(n)?`${e.label} is invalid`:null,options:(e,n)=>e.type==="select"&&e.options&&!e.options.includes(n)?`${e.label} must be one of: ${e.options.join(", ")}`:null,dateRange:(e,n)=>{if(e.type==="date"&&n){const t=new Date(n);if(e.minDate&&t<new Date(e.minDate))return`${e.label} must be after ${e.minDate}`;if(e.maxDate&&t>new Date(e.maxDate))return`${e.label} must be before ${e.maxDate}`}return null},customValidator:(e,n)=>{if(e.customValidator&&typeof e.customValidator=="function"){const t=e.customValidator(n);if(typeof t=="string")return t}return null}},H=(e,n,t="en")=>{const a={};return e.sections.forEach(o=>{o.fields.forEach(s=>{const u=O(e,n,s.id);u.length>0&&(a[s.id]=u)})}),a},O=(e,n,t,a="en")=>{const o=e.sections.flatMap(v=>v.fields).find(v=>v.id===t);if(!o)return[];const s=o.validations||{},u=n[t],d=[],x=f(o.label,a);if(s.required&&(u==null||u==="")&&d.push(typeof s.required=="string"?s.required:`${x} is required`),s.min!==void 0&&typeof u=="number"&&u<s.min&&d.push(`${x} must be at least ${s.min}`),s.max!==void 0&&typeof u=="number"&&u>s.max&&d.push(`${x} must be at most ${s.max}`),s.minLength!==void 0&&typeof u=="string"&&u.length<s.minLength&&d.push(`${x} must be at least ${s.minLength} characters`),s.maxLength!==void 0&&typeof u=="string"&&u.length>s.maxLength&&d.push(`${x} must be at most ${s.maxLength} characters`),s.pattern&&typeof u=="string"&&!s.pattern.test(u)&&d.push(`${x} is invalid`),s.validate){const v=s.validate(u);v&&d.push(f(v,a))}return d};function w(e,n){if(!e)return!0;if("field"in e){let t=n[e.field]??"";return Array.isArray(t)?t=t.map(a=>a.value??""):typeof t=="object"&&t!==null&&(t=t.value??""),e.equals!==void 0?t===e.equals:e.notEquals!==void 0?t!==e.notEquals:e.in!==void 0?Array.isArray(t)?e.in?t.some(a=>e.in.includes(a)):!1:e.in.includes(t):e.notIn!==void 0?Array.isArray(t)?t.every(a=>!e.notIn.includes(a)):!e.notIn.includes(t):e.greaterThan!==void 0?t>e.greaterThan:e.lessThan!==void 0?t<e.lessThan:!0}if("operator"in e){if(e.operator==="AND")return e.conditions.every(a=>w(a,n));if(e.operator==="OR")return e.conditions.some(t=>w(t,n))}return!1}const X=({section:e,values:n,onChange:t,renderers:a,validateField:o,locale:s="en"})=>l.jsxs(c.Box,{mb:2,children:[e.heading&&l.jsx(c.Typography,{variant:"h6",sx:{fontSize:e.headingFontSize?`${e.headingFontSize}rem`:"1.25rem"},gutterBottom:!0,color:"black",children:f(e.heading,s)}),e.description&&l.jsx(c.Typography,{variant:"body2",sx:{fontSize:e.descriptionFontSize?`${e.descriptionFontSize}rem`:"inherit"},color:"textSecondary",gutterBottom:!0,children:f(e.description,s)}),l.jsx(c.Grid,{container:!0,spacing:2,children:e.fields.map(u=>w(u.visibleWhen,n)&&l.jsx(c.Grid,{size:ie(u.layout?.cols),children:l.jsx(J,{field:u,value:n[u.id],onChange:d=>t(u.id,d),renderers:a,error:o(u.id)?.join(","),locale:s})},u.id))})]});function Z(e,n="en"){const[t,a]=g.useState({}),[o,s]=g.useState({});return{values:t,handleChange:(E,k)=>{a(y=>({...y,[E]:k})),s(y=>({...y,[E]:null}))},validateAll:()=>H(e,t,n),getValues:()=>t,getErrors:()=>o,validateField:E=>O(e,t,E,n)}}const de=g.forwardRef(({dto:e,renderers:n,locale:t="en"},a)=>{const{values:o,handleChange:s,getValues:u,getErrors:d,validateAll:x,validateField:v}=Z(e,t);return g.useImperativeHandle(a,()=>({getValues:u,getErrors:d,validateAll:x,validateField:v})),l.jsxs(l.Fragment,{children:[e.title&&l.jsx(c.Typography,{variant:"h5",color:"black",sx:{fontSize:e.titleFontSize?`${e.titleFontSize}rem`:"1.5rem",fontWeight:"bold"},gutterBottom:!0,children:f(e.title,t)}),e.description&&l.jsx(c.Typography,{component:"p",sx:{fontSize:e.descriptionFontSize?`${e.descriptionFontSize}rem`:"inherit"},color:"textSecondary",gutterBottom:!0,children:f(e.description,t)}),e.sections.map(T=>l.jsx(X,{section:T,values:o,onChange:s,renderers:n,validateField:v,locale:t},T.id))]})});m.AutoCompleteField=V,m.CheckBoxInput=M,m.Field=J,m.FormBuilder=de,m.MultiAutoCompleteField=B,m.RadioInput=G,m.Section=X,m.SelectInput=q,m.TextAreaInput=U,m.TextInput=W,m.useFormBuilder=Z,m.validateAll=H,m.validateField=O,m.validationRules=ce,Object.defineProperty(m,Symbol.toStringTag,{value:"Module"})}));
|
|
6
|
+
<%s key={someKey} {...props} />`,b,h,_,h),se[h+b]=!0)}if(h=null,p!==void 0&&(n(p),h=""+p),u(i)&&(n(i.key),h=""+i.key),"key"in i){p={};for(var z in i)z!=="key"&&(p[z]=i[z])}else p=i;return h&&d(p,typeof r=="function"?r.displayName||r.name||"Unknown":r),g(r,h,p,o(),O,D)}function R(r){T(r)?r._store&&(r._store.validated=1):typeof r=="object"&&r!==null&&r.$$typeof===I&&(r._payload.status==="fulfilled"?T(r._payload.value)&&r._payload.value._store&&(r._payload.value._store.validated=1):r._store&&(r._store.validated=1))}function T(r){return typeof r=="object"&&r!==null&&r.$$typeof===y}var v=E,y=Symbol.for("react.transitional.element"),C=Symbol.for("react.portal"),$=Symbol.for("react.fragment"),me=Symbol.for("react.strict_mode"),fe=Symbol.for("react.profiler"),be=Symbol.for("react.consumer"),he=Symbol.for("react.context"),ve=Symbol.for("react.forward_ref"),xe=Symbol.for("react.suspense"),ge=Symbol.for("react.suspense_list"),ye=Symbol.for("react.memo"),I=Symbol.for("react.lazy"),Ee=Symbol.for("react.activity"),Te=Symbol.for("react.client.reference"),L=v.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,ee=Object.prototype.hasOwnProperty,je=Array.isArray,N=console.createTask?console.createTask:function(){return null};v={react_stack_bottom_frame:function(r){return r()}};var re,te={},ne=v.react_stack_bottom_frame.bind(v,s)(),ae=N(a(s)),se={};S.Fragment=$,S.jsx=function(r,i,p){var b=1e4>L.recentlyCreatedOwnerStacks++;return j(r,i,p,!1,b?Error("react-stack-top-frame"):ne,b?N(a(r)):ae)},S.jsxs=function(r,i,p){var b=1e4>L.recentlyCreatedOwnerStacks++;return j(r,i,p,!0,b?Error("react-stack-top-frame"):ne,b?N(a(r)):ae)}})()),S}var W;function le(){return W||(W=1,process.env.NODE_ENV==="production"?k.exports=oe():k.exports=ue()),k.exports}var l=le();function f(e,t="en"){return e?typeof e=="string"?e:e[t]||e.en||Object.values(e)[0]||"":""}function F(e,t="en"){return e?e.map(n=>typeof n=="string"?{value:n,label:n}:{value:n.value,label:f(n.label,t)}):[]}function M({field:e,value:t,onChange:n,error:a,locale:o="en"}){const s=F(e.options||[],o);return l.jsxs(c.FormControl,{fullWidth:!0,children:[l.jsx(c.InputLabel,{id:`${e.id}-label`,children:f(e.label,o)}),l.jsx(c.Select,{labelId:`${e.id}-label`,value:t,id:e.id,name:e.id,onChange:u=>n(u.target.value),label:f(e.label,o),error:!!a,children:s?.map(u=>l.jsx(c.MenuItem,{value:u.value,children:u.label},u.label))}),a&&l.jsx(c.Typography,{variant:"caption",color:"error",children:a})]})}function V({field:e,value:t,onChange:n,error:a,locale:o}){return console.log("error",a),l.jsx(c.TextField,{fullWidth:!0,label:f(e.label,o),placeholder:f(e.placeholder||"",o),value:t||"",name:e.id,onChange:s=>n(s.target.value),disabled:e.disabled,type:e.type,slotProps:{inputLabel:{shrink:e.type==="date"?!0:void 0}},error:!!a,helperText:a})}function B({field:e,value:t,onChange:n,error:a,locale:o}){return l.jsxs(l.Fragment,{children:[l.jsx(c.FormControlLabel,{name:e.id,control:l.jsx(c.Checkbox,{checked:!!t,onChange:s=>n(s.target.checked),disabled:e.disabled}),label:f(e.label,o)}),a&&l.jsx(c.FormHelperText,{children:a})]})}const U=({field:e,value:t,onChange:n,error:a,locale:o})=>{const s=F(e.options||[],o);return l.jsx(c.Autocomplete,{fullWidth:!0,options:s||[],value:t||null,onChange:(u,d)=>n(d),renderInput:u=>l.jsx(c.TextField,{...u,name:e.id,label:f(e.label,o),placeholder:f(e.placeholder||"",o),disabled:e.disabled,error:!!a,helperText:a})})},G=({field:e,value:t,onChange:n,error:a,locale:o})=>{const s=F(e.options||[],o);return l.jsx(c.Autocomplete,{multiple:!0,fullWidth:!0,options:s||[],value:t||[],onChange:(u,d)=>n(d),renderInput:u=>l.jsx(c.TextField,{...u,name:e.id,label:f(e.label,o),placeholder:f(e.placeholder||"",o),disabled:e.disabled,error:!!a,helperText:a})})},J=({field:e,value:t,onChange:n,error:a,locale:o="en"})=>l.jsx(c.TextField,{fullWidth:!0,multiline:!0,rows:e.rows||4,label:f(e.label,o),placeholder:f(e.placeholder||"",o),value:t||"",onChange:s=>n(s.target.value),required:!!e.validations?.required,disabled:e.disabled,error:!!a,helperText:a}),H=({field:e,value:t,onChange:n,error:a,locale:o="en"})=>{const s=F(e.options||[],o);return l.jsxs(c.FormControl,{component:"fieldset",fullWidth:!0,error:!!a,children:[l.jsxs(c.FormLabel,{component:"legend",children:[f(e.label,o),e.validations?.required?" *":""]}),l.jsx(c.RadioGroup,{row:e.layout?.direction==="row"||!1,value:t||"",onChange:u=>n(u.target.value),children:(s||[]).map(u=>l.jsx(c.FormControlLabel,{value:u.value,control:l.jsx(c.Radio,{}),label:u.label,disabled:e.disabled},u.label))}),a&&l.jsx(c.FormHelperText,{children:a})]})},ie=({field:e,value:t,onChange:n,error:a,locale:o="en"})=>{switch(e.type){case"text":case"date":case"email":case"password":case"number":return l.jsx(V,{field:e,value:t,onChange:n,error:a,locale:o});case"select":return l.jsx(M,{field:e,value:t,onChange:n,error:a,locale:o});case"autocomplete":return l.jsx(U,{field:e,value:t,onChange:n,error:a,locale:o});case"multi-autocomplete":return l.jsx(G,{field:e,value:t,onChange:n,error:a,locale:o});case"checkbox":return l.jsx(B,{field:e,value:t,onChange:n,error:a,locale:o});case"textarea":return l.jsx(J,{field:e,value:t,onChange:n,error:a,locale:o});case"radio":return l.jsx(H,{field:e,value:t,onChange:n,error:a,locale:o});default:return l.jsxs("span",{children:["Unsupported field type: ",e.type]})}},X=({field:e,value:t,onChange:n,error:a,renderers:o={},locale:s="en"})=>{const u=o[e.type]||ie;return l.jsx(u,{field:e,value:t,onChange:n,error:a,locale:s})};function ce(e){const t=e??12;return{xs:12,sm:t,md:t,lg:t,xl:t}}const de={required:(e,t)=>e.required&&(t==null||t==="")?`${e.label} is required`:null,min:(e,t)=>e.type==="number"&&e.min!==void 0&&t<e.min?`${e.label} must be at least ${e.min}`:null,max:(e,t)=>e.type==="number"&&e.max!==void 0&&t>e.max?`${e.label} must be at most ${e.max}`:null,minLength:(e,t)=>typeof t=="string"&&e.minLength!==void 0&&t.length<e.minLength?`${e.label} must be at least ${e.minLength} characters`:null,maxLength:(e,t)=>typeof t=="string"&&e.maxLength!==void 0&&t.length>e.maxLength?`${e.label} must be at most ${e.maxLength} characters`:null,pattern:(e,t)=>e.pattern&&typeof t=="string"&&!e.pattern.test(t)?`${e.label} is invalid`:null,options:(e,t)=>e.type==="select"&&e.options&&!e.options.includes(t)?`${e.label} must be one of: ${e.options.join(", ")}`:null,dateRange:(e,t)=>{if(e.type==="date"&&t){const n=new Date(t);if(e.minDate&&n<new Date(e.minDate))return`${e.label} must be after ${e.minDate}`;if(e.maxDate&&n>new Date(e.maxDate))return`${e.label} must be before ${e.maxDate}`}return null},customValidator:(e,t)=>{if(e.customValidator&&typeof e.customValidator=="function"){const n=e.customValidator(t);if(typeof n=="string")return n}return null}},Z=(e,t,n="en")=>{const a={};return e.sections.forEach(o=>{o.fields.forEach(s=>{const u=w(e,t,s.id);u.length>0&&(a[s.id]=u)})}),a},w=(e,t,n,a="en")=>{const o=e.sections.flatMap(g=>g.fields).find(g=>g.id===n);if(!o)return[];const s=o.validations||{},u=t[n],d=[],x=f(o.label,a);if(s.required&&(u==null||u==="")&&d.push(typeof s.required=="string"?s.required:`${x} is required`),s.min!==void 0&&typeof u=="number"&&u<s.min&&d.push(`${x} must be at least ${s.min}`),s.max!==void 0&&typeof u=="number"&&u>s.max&&d.push(`${x} must be at most ${s.max}`),s.minLength!==void 0&&typeof u=="string"&&u.length<s.minLength&&d.push(`${x} must be at least ${s.minLength} characters`),s.maxLength!==void 0&&typeof u=="string"&&u.length>s.maxLength&&d.push(`${x} must be at most ${s.maxLength} characters`),s.pattern&&typeof u=="string"&&!s.pattern.test(u)&&d.push(`${x} is invalid`),s.validate){const g=s.validate(u);g&&d.push(f(g,a))}return d};function P(e,t){if(!e)return!0;if("field"in e){let n=t[e.field]??"";return Array.isArray(n)?n=n.map(a=>a.value??""):typeof n=="object"&&n!==null&&(n=n.value??""),e.equals!==void 0?n===e.equals:e.notEquals!==void 0?n!==e.notEquals:e.in!==void 0?Array.isArray(n)?e.in?n.some(a=>e.in.includes(a)):!1:e.in.includes(n):e.notIn!==void 0?Array.isArray(n)?n.every(a=>!e.notIn.includes(a)):!e.notIn.includes(n):e.greaterThan!==void 0?n>e.greaterThan:e.lessThan!==void 0?n<e.lessThan:!0}if("operator"in e){if(e.operator==="AND")return e.conditions.every(a=>P(a,t));if(e.operator==="OR")return e.conditions.some(n=>P(n,t))}return!1}const Q=({section:e,values:t,onChange:n,renderers:a,validateField:o,locale:s="en"})=>l.jsxs(c.Box,{mb:2,children:[e.heading&&l.jsx(c.Typography,{variant:"h6",sx:{fontSize:e.headingFontSize?`${e.headingFontSize}rem`:"1.25rem"},gutterBottom:!0,color:"black",children:f(e.heading,s)}),e.description&&l.jsx(c.Typography,{variant:"body2",sx:{fontSize:e.descriptionFontSize?`${e.descriptionFontSize}rem`:"inherit"},color:"textSecondary",gutterBottom:!0,children:f(e.description,s)}),l.jsx(c.Grid,{container:!0,spacing:2,children:e.fields.map(u=>P(u.visibleWhen,t)&&l.jsx(c.Grid,{size:ce(u.layout?.cols),children:l.jsx(X,{field:u,value:t[u.id],onChange:d=>n(u.id,d),renderers:a,error:o(u.id)?.join(","),locale:s})},u.id))})]});function K(e,t="en",n){const[a,o]=E.useState({}),[s,u]=E.useState({});return{values:a,handleChange:(T,v)=>{if(o(y=>({...y,[T]:v})),u(y=>({...y,[T]:null})),n){let y=v;Array.isArray(v)?y=v.map(C=>C.value??""):typeof v=="object"&&v!==null&&(y=v.value??""),n(T,y)}},validateAll:()=>Z(e,a,t),getValues:()=>a,getErrors:()=>s,validateField:T=>w(e,a,T,t)}}const pe=E.forwardRef(({dto:e,renderers:t,locale:n="en",handleChangeCallback:a},o)=>{const{values:s,handleChange:u,getValues:d,getErrors:x,validateAll:g,validateField:j}=K(e,n,a);return E.useImperativeHandle(o,()=>({getValues:d,getErrors:x,validateAll:g,validateField:j})),l.jsxs(l.Fragment,{children:[e.title&&l.jsx(c.Typography,{variant:"h5",color:"black",sx:{fontSize:e.titleFontSize?`${e.titleFontSize}rem`:"1.5rem",fontWeight:"bold"},gutterBottom:!0,children:f(e.title,n)}),e.description&&l.jsx(c.Typography,{component:"p",sx:{fontSize:e.descriptionFontSize?`${e.descriptionFontSize}rem`:"inherit"},color:"textSecondary",gutterBottom:!0,children:f(e.description,n)}),e.sections.map(R=>l.jsx(Q,{section:R,values:s,onChange:u,renderers:t,validateField:j,locale:n},R.id))]})});m.AutoCompleteField=U,m.CheckBoxInput=B,m.Field=X,m.FormBuilder=pe,m.MultiAutoCompleteField=G,m.RadioInput=H,m.Section=Q,m.SelectInput=M,m.TextAreaInput=J,m.TextInput=V,m.useFormBuilder=K,m.validateAll=Z,m.validateField=w,m.validationRules=de,Object.defineProperty(m,Symbol.toStringTag,{value:"Module"})}));
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-form-dto",
|
|
3
3
|
"description": "A React library for building forms using DTOs with MUI and TypeScript.",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.3",
|
|
5
5
|
"main": "dist/react-form-dto.umd.js",
|
|
6
6
|
"module": "dist/react-form-dto.es.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|