react-form-dto 1.0.1 β 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.
- package/README.md +31 -0
- package/dist/components/FormBuilder.d.ts +1 -0
- package/dist/hooks/useFormBuilder.d.ts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/react-form-dto.es.js +326 -301
- package/dist/react-form-dto.umd.js +2 -2
- package/dist/stories/FormBuilder.stories.d.ts +1 -0
- package/dist/types/dto.d.ts +15 -0
- package/dist/utils/evaluateVisibleWhen.d.ts +8 -0
- package/dist/utils/index.d.ts +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -38,6 +38,7 @@ It operates at a higher abstraction level where **layout, validation, rendering,
|
|
|
38
38
|
- π§© **Extensible renderers** β plug in custom components
|
|
39
39
|
- π‘οΈ **Strong TypeScript typing** β safe, predictable APIs
|
|
40
40
|
- π **Enterprise-ready** β optimized for large, config-driven forms
|
|
41
|
+
- π **Nested condition engine** β combine AND/OR groups for powerful, multiβfield visibility rules
|
|
41
42
|
|
|
42
43
|
---
|
|
43
44
|
|
|
@@ -92,6 +93,12 @@ pnpm add react-form-dto
|
|
|
92
93
|
|
|
93
94
|
---
|
|
94
95
|
|
|
96
|
+
## Release Notes
|
|
97
|
+
|
|
98
|
+
See [CHANGELOG.md](./.github/CHANGELOG.md) for detailed version history.
|
|
99
|
+
|
|
100
|
+
---
|
|
101
|
+
|
|
95
102
|
## Core Concepts
|
|
96
103
|
|
|
97
104
|
### DTO as Source of Truth
|
|
@@ -267,6 +274,30 @@ const profileForm: FormDTO = {
|
|
|
267
274
|
|
|
268
275
|
---
|
|
269
276
|
|
|
277
|
+
## π Conditional Visibility with `visibleWhen`
|
|
278
|
+
|
|
279
|
+
React Form DTO supports dynamic field visibility based on the values of other fields in the form. This is achieved through the `visibleWhen` property, which allows you to define simple conditions or complex logical expressions.
|
|
280
|
+
|
|
281
|
+
### Basic Usage
|
|
282
|
+
|
|
283
|
+
Show a field only when another field has a specific value:
|
|
284
|
+
|
|
285
|
+
```tsx
|
|
286
|
+
{
|
|
287
|
+
id: "partnerName",
|
|
288
|
+
type: "text",
|
|
289
|
+
label: "Partner Name",
|
|
290
|
+
visibleWhen: {
|
|
291
|
+
field: "maritalStatus",
|
|
292
|
+
equals: "married"
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
For detail documentation, please visit [Docs](https://shakir-afridi.github.io/react-form-dto/docs/api/visibleWhen.html)
|
|
298
|
+
|
|
299
|
+
---
|
|
300
|
+
|
|
270
301
|
## π Internationalization (I18n)
|
|
271
302
|
|
|
272
303
|
React Form DTO has built-in support for multi-language forms through `I18String` and `I18nOption` types.
|
|
@@ -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 */
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { FormBuilder, Section, Field, TextAreaInput, AutoCompleteField, MultiAutoCompleteField, RadioInput, SelectInput, TextInput, CheckBoxInput, } from './components';
|
|
2
2
|
export { validateAll, validateField, validationRules } from './utils';
|
|
3
|
-
export type { FieldDTO, SectionDTO, FormDTO, InputType, Validations, } from './types';
|
|
3
|
+
export type { FieldDTO, SectionDTO, FormDTO, InputType, Validations, Condition as VisibleWhenCondition, FieldCondition as VisibleWhenFieldCondition, ConditionGroup as VisibleWhenConditionGroup, } from './types';
|
|
4
4
|
export { useFormBuilder } from './hooks';
|
|
@@ -1,67 +1,67 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { FormControl as
|
|
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
3
|
var S = { exports: {} }, _ = {};
|
|
4
|
-
var
|
|
5
|
-
function
|
|
6
|
-
if (
|
|
7
|
-
|
|
4
|
+
var U;
|
|
5
|
+
function je() {
|
|
6
|
+
if (U) return _;
|
|
7
|
+
U = 1;
|
|
8
8
|
var e = Symbol.for("react.transitional.element"), t = Symbol.for("react.fragment");
|
|
9
|
-
function n(
|
|
10
|
-
var
|
|
11
|
-
if (
|
|
12
|
-
|
|
9
|
+
function n(a, o, s) {
|
|
10
|
+
var u = null;
|
|
11
|
+
if (s !== void 0 && (u = "" + s), o.key !== void 0 && (u = "" + o.key), "key" in o) {
|
|
12
|
+
s = {};
|
|
13
13
|
for (var c in o)
|
|
14
|
-
c !== "key" && (
|
|
15
|
-
} else
|
|
16
|
-
return o =
|
|
14
|
+
c !== "key" && (s[c] = o[c]);
|
|
15
|
+
} else s = o;
|
|
16
|
+
return o = s.ref, {
|
|
17
17
|
$$typeof: e,
|
|
18
|
-
type:
|
|
19
|
-
key:
|
|
18
|
+
type: a,
|
|
19
|
+
key: u,
|
|
20
20
|
ref: o !== void 0 ? o : null,
|
|
21
|
-
props:
|
|
21
|
+
props: s
|
|
22
22
|
};
|
|
23
23
|
}
|
|
24
24
|
return _.Fragment = t, _.jsx = n, _.jsxs = n, _;
|
|
25
25
|
}
|
|
26
|
-
var
|
|
27
|
-
var
|
|
28
|
-
function
|
|
29
|
-
return
|
|
26
|
+
var R = {};
|
|
27
|
+
var G;
|
|
28
|
+
function _e() {
|
|
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
|
-
return r.$$typeof ===
|
|
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
|
-
case
|
|
38
|
+
case te:
|
|
39
39
|
return "Profiler";
|
|
40
|
-
case
|
|
40
|
+
case re:
|
|
41
41
|
return "StrictMode";
|
|
42
42
|
case oe:
|
|
43
43
|
return "Suspense";
|
|
44
|
-
case
|
|
44
|
+
case ue:
|
|
45
45
|
return "SuspenseList";
|
|
46
|
-
case
|
|
46
|
+
case ie:
|
|
47
47
|
return "Activity";
|
|
48
48
|
}
|
|
49
49
|
if (typeof r == "object")
|
|
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
|
-
case
|
|
55
|
+
case ae:
|
|
56
56
|
return r.displayName || "Context";
|
|
57
|
-
case
|
|
57
|
+
case ne:
|
|
58
58
|
return (r._context.displayName || "Context") + ".Consumer";
|
|
59
|
-
case
|
|
59
|
+
case se:
|
|
60
60
|
var i = r.render;
|
|
61
61
|
return r = r.displayName, r || (r = i.displayName || i.name || "", r = r !== "" ? "ForwardRef(" + r + ")" : "ForwardRef"), r;
|
|
62
|
-
case
|
|
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));
|
|
@@ -82,17 +82,17 @@ function je() {
|
|
|
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
|
-
|
|
89
|
+
p
|
|
90
90
|
), t(r);
|
|
91
91
|
}
|
|
92
92
|
}
|
|
93
|
-
function
|
|
94
|
-
if (r ===
|
|
95
|
-
if (typeof r == "object" && r !== null && r.$$typeof ===
|
|
93
|
+
function a(r) {
|
|
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 je() {
|
|
|
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
|
-
function
|
|
108
|
+
function s() {
|
|
109
109
|
return Error("react-stack-top-frame");
|
|
110
110
|
}
|
|
111
|
-
function
|
|
112
|
-
if (
|
|
111
|
+
function u(r) {
|
|
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 je() {
|
|
|
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 je() {
|
|
|
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,127 +158,127 @@ function je() {
|
|
|
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 (
|
|
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 v(r) {
|
|
218
|
-
y(r) ? r._store && (r._store.validated = 1) : typeof r == "object" && r !== null && r.$$typeof === w && (r._payload.status === "fulfilled" ? y(r._payload.value) && r._payload.value._store && (r._payload.value._store.validated = 1) : r._store && (r._store.validated = 1));
|
|
219
|
-
}
|
|
220
217
|
function y(r) {
|
|
221
|
-
|
|
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
|
+
}
|
|
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
|
-
|
|
233
|
-
|
|
234
|
-
)(),
|
|
235
|
-
|
|
236
|
-
var
|
|
237
|
-
return
|
|
231
|
+
var q, z = {}, Y = b.react_stack_bottom_frame.bind(
|
|
232
|
+
b,
|
|
233
|
+
s
|
|
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
|
|
263
|
+
function f(e, t = "en") {
|
|
264
264
|
return e ? typeof e == "string" ? e : e[t] || e.en || Object.values(e)[0] || "" : "";
|
|
265
265
|
}
|
|
266
|
-
function
|
|
266
|
+
function $(e, t = "en") {
|
|
267
267
|
return e ? e.map((n) => typeof n == "string" ? { value: n, label: n } : {
|
|
268
268
|
value: n.value,
|
|
269
|
-
label:
|
|
269
|
+
label: f(n.label, t)
|
|
270
270
|
}) : [];
|
|
271
271
|
}
|
|
272
|
-
function
|
|
272
|
+
function Te({
|
|
273
273
|
field: e,
|
|
274
274
|
value: t,
|
|
275
275
|
onChange: n,
|
|
276
|
-
error:
|
|
276
|
+
error: a,
|
|
277
277
|
locale: o = "en"
|
|
278
278
|
}) {
|
|
279
|
-
const
|
|
280
|
-
return /* @__PURE__ */ l.jsxs(
|
|
281
|
-
/* @__PURE__ */ l.jsx(
|
|
279
|
+
const s = $(e.options || [], o);
|
|
280
|
+
return /* @__PURE__ */ l.jsxs(H, { fullWidth: !0, children: [
|
|
281
|
+
/* @__PURE__ */ l.jsx(fe, { id: `${e.id}-label`, children: f(e.label, o) }),
|
|
282
282
|
/* @__PURE__ */ l.jsx(
|
|
283
283
|
be,
|
|
284
284
|
{
|
|
@@ -286,31 +286,31 @@ function ye({
|
|
|
286
286
|
value: t,
|
|
287
287
|
id: e.id,
|
|
288
288
|
name: e.id,
|
|
289
|
-
onChange: (
|
|
290
|
-
label:
|
|
291
|
-
error: !!
|
|
292
|
-
children:
|
|
289
|
+
onChange: (u) => n(u.target.value),
|
|
290
|
+
label: f(e.label, o),
|
|
291
|
+
error: !!a,
|
|
292
|
+
children: s?.map((u) => /* @__PURE__ */ l.jsx(he, { value: u.value, children: u.label }, u.label))
|
|
293
293
|
}
|
|
294
294
|
),
|
|
295
|
-
|
|
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
300
|
value: t,
|
|
301
301
|
onChange: n,
|
|
302
|
-
error:
|
|
302
|
+
error: a,
|
|
303
303
|
locale: o
|
|
304
304
|
}) {
|
|
305
|
-
return console.log("error",
|
|
305
|
+
return console.log("error", a), /* @__PURE__ */ l.jsx(
|
|
306
306
|
k,
|
|
307
307
|
{
|
|
308
308
|
fullWidth: !0,
|
|
309
|
-
label:
|
|
310
|
-
placeholder:
|
|
309
|
+
label: f(e.label, o),
|
|
310
|
+
placeholder: f(e.placeholder || "", o),
|
|
311
311
|
value: t || "",
|
|
312
312
|
name: e.id,
|
|
313
|
-
onChange: (
|
|
313
|
+
onChange: (s) => n(s.target.value),
|
|
314
314
|
disabled: e.disabled,
|
|
315
315
|
type: e.type,
|
|
316
316
|
slotProps: {
|
|
@@ -318,8 +318,8 @@ function Te({
|
|
|
318
318
|
shrink: e.type === "date" ? !0 : void 0
|
|
319
319
|
}
|
|
320
320
|
},
|
|
321
|
-
error: !!
|
|
322
|
-
helperText:
|
|
321
|
+
error: !!a,
|
|
322
|
+
helperText: a
|
|
323
323
|
}
|
|
324
324
|
);
|
|
325
325
|
}
|
|
@@ -327,98 +327,98 @@ function Se({
|
|
|
327
327
|
field: e,
|
|
328
328
|
value: t,
|
|
329
329
|
onChange: n,
|
|
330
|
-
error:
|
|
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
341
|
checked: !!t,
|
|
342
|
-
onChange: (
|
|
342
|
+
onChange: (s) => n(s.target.checked),
|
|
343
343
|
disabled: e.disabled
|
|
344
344
|
}
|
|
345
345
|
),
|
|
346
|
-
label:
|
|
346
|
+
label: f(e.label, o)
|
|
347
347
|
}
|
|
348
348
|
),
|
|
349
|
-
|
|
349
|
+
a && /* @__PURE__ */ l.jsx(Q, { children: a })
|
|
350
350
|
] });
|
|
351
351
|
}
|
|
352
352
|
const ke = ({
|
|
353
353
|
field: e,
|
|
354
354
|
value: t,
|
|
355
355
|
onChange: n,
|
|
356
|
-
error:
|
|
356
|
+
error: a,
|
|
357
357
|
locale: o
|
|
358
358
|
}) => {
|
|
359
|
-
const
|
|
359
|
+
const s = $(e.options || [], o);
|
|
360
360
|
return /* @__PURE__ */ l.jsx(
|
|
361
|
-
|
|
361
|
+
K,
|
|
362
362
|
{
|
|
363
363
|
fullWidth: !0,
|
|
364
|
-
options:
|
|
364
|
+
options: s || [],
|
|
365
365
|
value: t || null,
|
|
366
|
-
onChange: (
|
|
367
|
-
renderInput: (
|
|
366
|
+
onChange: (u, c) => n(c),
|
|
367
|
+
renderInput: (u) => /* @__PURE__ */ l.jsx(
|
|
368
368
|
k,
|
|
369
369
|
{
|
|
370
|
-
...
|
|
370
|
+
...u,
|
|
371
371
|
name: e.id,
|
|
372
|
-
label:
|
|
373
|
-
placeholder:
|
|
372
|
+
label: f(e.label, o),
|
|
373
|
+
placeholder: f(
|
|
374
374
|
e.placeholder || "",
|
|
375
375
|
o
|
|
376
376
|
),
|
|
377
377
|
disabled: e.disabled,
|
|
378
|
-
error: !!
|
|
379
|
-
helperText:
|
|
378
|
+
error: !!a,
|
|
379
|
+
helperText: a
|
|
380
380
|
}
|
|
381
381
|
)
|
|
382
382
|
}
|
|
383
383
|
);
|
|
384
|
-
},
|
|
384
|
+
}, $e = ({
|
|
385
385
|
field: e,
|
|
386
386
|
value: t,
|
|
387
387
|
onChange: n,
|
|
388
|
-
error:
|
|
388
|
+
error: a,
|
|
389
389
|
locale: o
|
|
390
390
|
}) => {
|
|
391
|
-
const
|
|
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
|
-
options:
|
|
397
|
+
options: s || [],
|
|
398
398
|
value: t || [],
|
|
399
|
-
onChange: (
|
|
400
|
-
renderInput: (
|
|
399
|
+
onChange: (u, c) => n(c),
|
|
400
|
+
renderInput: (u) => /* @__PURE__ */ l.jsx(
|
|
401
401
|
k,
|
|
402
402
|
{
|
|
403
|
-
...
|
|
403
|
+
...u,
|
|
404
404
|
name: e.id,
|
|
405
|
-
label:
|
|
406
|
-
placeholder:
|
|
405
|
+
label: f(e.label, o),
|
|
406
|
+
placeholder: f(
|
|
407
407
|
e.placeholder || "",
|
|
408
408
|
o
|
|
409
409
|
),
|
|
410
410
|
disabled: e.disabled,
|
|
411
|
-
error: !!
|
|
412
|
-
helperText:
|
|
411
|
+
error: !!a,
|
|
412
|
+
helperText: a
|
|
413
413
|
}
|
|
414
414
|
)
|
|
415
415
|
}
|
|
416
416
|
);
|
|
417
|
-
},
|
|
417
|
+
}, we = ({
|
|
418
418
|
field: e,
|
|
419
419
|
value: t,
|
|
420
420
|
onChange: n,
|
|
421
|
-
error:
|
|
421
|
+
error: a,
|
|
422
422
|
locale: o = "en"
|
|
423
423
|
}) => /* @__PURE__ */ l.jsx(
|
|
424
424
|
k,
|
|
@@ -426,53 +426,53 @@ const ke = ({
|
|
|
426
426
|
fullWidth: !0,
|
|
427
427
|
multiline: !0,
|
|
428
428
|
rows: e.rows || 4,
|
|
429
|
-
label:
|
|
430
|
-
placeholder:
|
|
429
|
+
label: f(e.label, o),
|
|
430
|
+
placeholder: f(e.placeholder || "", o),
|
|
431
431
|
value: t || "",
|
|
432
|
-
onChange: (
|
|
432
|
+
onChange: (s) => n(s.target.value),
|
|
433
433
|
required: !!e.validations?.required,
|
|
434
434
|
disabled: e.disabled,
|
|
435
|
-
error: !!
|
|
436
|
-
helperText:
|
|
435
|
+
error: !!a,
|
|
436
|
+
helperText: a
|
|
437
437
|
}
|
|
438
|
-
),
|
|
438
|
+
), Oe = ({
|
|
439
439
|
field: e,
|
|
440
440
|
value: t,
|
|
441
441
|
onChange: n,
|
|
442
|
-
error:
|
|
442
|
+
error: a,
|
|
443
443
|
locale: o = "en"
|
|
444
444
|
}) => {
|
|
445
|
-
const
|
|
446
|
-
return /* @__PURE__ */ l.jsxs(
|
|
447
|
-
/* @__PURE__ */ l.jsxs(
|
|
448
|
-
|
|
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
|
+
f(e.label, o),
|
|
449
449
|
e.validations?.required ? " *" : ""
|
|
450
450
|
] }),
|
|
451
451
|
/* @__PURE__ */ l.jsx(
|
|
452
|
-
|
|
452
|
+
ge,
|
|
453
453
|
{
|
|
454
454
|
row: e.layout?.direction === "row" || !1,
|
|
455
455
|
value: t || "",
|
|
456
|
-
onChange: (
|
|
457
|
-
children: (
|
|
458
|
-
|
|
456
|
+
onChange: (u) => n(u.target.value),
|
|
457
|
+
children: (s || []).map((u) => /* @__PURE__ */ l.jsx(
|
|
458
|
+
Z,
|
|
459
459
|
{
|
|
460
|
-
value:
|
|
461
|
-
control: /* @__PURE__ */ l.jsx(
|
|
462
|
-
label:
|
|
460
|
+
value: u.value,
|
|
461
|
+
control: /* @__PURE__ */ l.jsx(Ee, {}),
|
|
462
|
+
label: u.label,
|
|
463
463
|
disabled: e.disabled
|
|
464
464
|
},
|
|
465
|
-
|
|
465
|
+
u.label
|
|
466
466
|
))
|
|
467
467
|
}
|
|
468
468
|
),
|
|
469
|
-
|
|
469
|
+
a && /* @__PURE__ */ l.jsx(Q, { children: a })
|
|
470
470
|
] });
|
|
471
|
-
},
|
|
471
|
+
}, Fe = ({
|
|
472
472
|
field: e,
|
|
473
473
|
value: t,
|
|
474
474
|
onChange: n,
|
|
475
|
-
error:
|
|
475
|
+
error: a,
|
|
476
476
|
locale: o = "en"
|
|
477
477
|
}) => {
|
|
478
478
|
switch (e.type) {
|
|
@@ -482,23 +482,23 @@ 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
488
|
value: t,
|
|
489
489
|
onChange: n,
|
|
490
|
-
error:
|
|
490
|
+
error: a,
|
|
491
491
|
locale: o
|
|
492
492
|
}
|
|
493
493
|
);
|
|
494
494
|
case "select":
|
|
495
495
|
return /* @__PURE__ */ l.jsx(
|
|
496
|
-
|
|
496
|
+
Te,
|
|
497
497
|
{
|
|
498
498
|
field: e,
|
|
499
499
|
value: t,
|
|
500
500
|
onChange: n,
|
|
501
|
-
error:
|
|
501
|
+
error: a,
|
|
502
502
|
locale: o
|
|
503
503
|
}
|
|
504
504
|
);
|
|
@@ -509,18 +509,18 @@ const ke = ({
|
|
|
509
509
|
field: e,
|
|
510
510
|
value: t,
|
|
511
511
|
onChange: n,
|
|
512
|
-
error:
|
|
512
|
+
error: a,
|
|
513
513
|
locale: o
|
|
514
514
|
}
|
|
515
515
|
);
|
|
516
516
|
case "multi-autocomplete":
|
|
517
517
|
return /* @__PURE__ */ l.jsx(
|
|
518
|
-
|
|
518
|
+
$e,
|
|
519
519
|
{
|
|
520
520
|
field: e,
|
|
521
521
|
value: t,
|
|
522
522
|
onChange: n,
|
|
523
|
-
error:
|
|
523
|
+
error: a,
|
|
524
524
|
locale: o
|
|
525
525
|
}
|
|
526
526
|
);
|
|
@@ -531,29 +531,29 @@ const ke = ({
|
|
|
531
531
|
field: e,
|
|
532
532
|
value: t,
|
|
533
533
|
onChange: n,
|
|
534
|
-
error:
|
|
534
|
+
error: a,
|
|
535
535
|
locale: o
|
|
536
536
|
}
|
|
537
537
|
);
|
|
538
538
|
case "textarea":
|
|
539
539
|
return /* @__PURE__ */ l.jsx(
|
|
540
|
-
|
|
540
|
+
we,
|
|
541
541
|
{
|
|
542
542
|
field: e,
|
|
543
543
|
value: t,
|
|
544
544
|
onChange: n,
|
|
545
|
-
error:
|
|
545
|
+
error: a,
|
|
546
546
|
locale: o
|
|
547
547
|
}
|
|
548
548
|
);
|
|
549
549
|
case "radio":
|
|
550
550
|
return /* @__PURE__ */ l.jsx(
|
|
551
|
-
|
|
551
|
+
Oe,
|
|
552
552
|
{
|
|
553
553
|
field: e,
|
|
554
554
|
value: t,
|
|
555
555
|
onChange: n,
|
|
556
|
-
error:
|
|
556
|
+
error: a,
|
|
557
557
|
locale: o
|
|
558
558
|
}
|
|
559
559
|
);
|
|
@@ -563,27 +563,27 @@ const ke = ({
|
|
|
563
563
|
e.type
|
|
564
564
|
] });
|
|
565
565
|
}
|
|
566
|
-
},
|
|
566
|
+
}, Pe = ({
|
|
567
567
|
field: e,
|
|
568
568
|
value: t,
|
|
569
569
|
onChange: n,
|
|
570
|
-
error:
|
|
570
|
+
error: a,
|
|
571
571
|
renderers: o = {},
|
|
572
|
-
locale:
|
|
572
|
+
locale: s = "en"
|
|
573
573
|
}) => {
|
|
574
|
-
const
|
|
574
|
+
const u = o[e.type] || Fe;
|
|
575
575
|
return /* @__PURE__ */ l.jsx(
|
|
576
|
-
|
|
576
|
+
u,
|
|
577
577
|
{
|
|
578
578
|
field: e,
|
|
579
579
|
value: t,
|
|
580
580
|
onChange: n,
|
|
581
|
-
error:
|
|
582
|
-
locale:
|
|
581
|
+
error: a,
|
|
582
|
+
locale: s
|
|
583
583
|
}
|
|
584
584
|
);
|
|
585
585
|
};
|
|
586
|
-
function
|
|
586
|
+
function Ce(e) {
|
|
587
587
|
const t = e ?? 12;
|
|
588
588
|
return {
|
|
589
589
|
xs: 12,
|
|
@@ -597,57 +597,7 @@ function Pe(e) {
|
|
|
597
597
|
xl: t
|
|
598
598
|
};
|
|
599
599
|
}
|
|
600
|
-
const
|
|
601
|
-
section: e,
|
|
602
|
-
values: t,
|
|
603
|
-
onChange: n,
|
|
604
|
-
renderers: u,
|
|
605
|
-
validateField: o,
|
|
606
|
-
locale: a = "en"
|
|
607
|
-
}) => /* @__PURE__ */ l.jsxs(Ee, { mb: 2, children: [
|
|
608
|
-
e.heading && /* @__PURE__ */ l.jsx(
|
|
609
|
-
R,
|
|
610
|
-
{
|
|
611
|
-
variant: "h6",
|
|
612
|
-
sx: {
|
|
613
|
-
fontSize: e.headingFontSize ? `${e.headingFontSize}rem` : "1.25rem"
|
|
614
|
-
},
|
|
615
|
-
gutterBottom: !0,
|
|
616
|
-
color: "black",
|
|
617
|
-
children: b(e.heading, a)
|
|
618
|
-
}
|
|
619
|
-
),
|
|
620
|
-
e.description && /* @__PURE__ */ l.jsx(
|
|
621
|
-
R,
|
|
622
|
-
{
|
|
623
|
-
variant: "body2",
|
|
624
|
-
sx: {
|
|
625
|
-
fontSize: e.descriptionFontSize ? `${e.descriptionFontSize}rem` : "inherit"
|
|
626
|
-
},
|
|
627
|
-
color: "textSecondary",
|
|
628
|
-
gutterBottom: !0,
|
|
629
|
-
children: b(e.description, a)
|
|
630
|
-
}
|
|
631
|
-
),
|
|
632
|
-
/* @__PURE__ */ l.jsx(V, { container: !0, spacing: 2, children: e.fields.map((s) => /* @__PURE__ */ l.jsx(
|
|
633
|
-
V,
|
|
634
|
-
{
|
|
635
|
-
size: Pe(s.layout?.cols),
|
|
636
|
-
children: /* @__PURE__ */ l.jsx(
|
|
637
|
-
Fe,
|
|
638
|
-
{
|
|
639
|
-
field: s,
|
|
640
|
-
value: t[s.id],
|
|
641
|
-
onChange: (c) => n(s.id, c),
|
|
642
|
-
renderers: u,
|
|
643
|
-
error: o(s.id)?.join(","),
|
|
644
|
-
locale: a
|
|
645
|
-
}
|
|
646
|
-
)
|
|
647
|
-
},
|
|
648
|
-
s.id
|
|
649
|
-
)) })
|
|
650
|
-
] }), ze = {
|
|
600
|
+
const ze = {
|
|
651
601
|
/**
|
|
652
602
|
* Validates that a required field has a value.
|
|
653
603
|
* @param field - The field definition
|
|
@@ -727,62 +677,137 @@ const Ce = ({
|
|
|
727
677
|
}
|
|
728
678
|
return null;
|
|
729
679
|
}
|
|
730
|
-
},
|
|
731
|
-
const
|
|
680
|
+
}, Ie = (e, t, n = "en") => {
|
|
681
|
+
const a = {};
|
|
732
682
|
return e.sections.forEach((o) => {
|
|
733
|
-
o.fields.forEach((
|
|
734
|
-
const
|
|
735
|
-
|
|
683
|
+
o.fields.forEach((s) => {
|
|
684
|
+
const u = ee(e, t, s.id);
|
|
685
|
+
u.length > 0 && (a[s.id] = u);
|
|
736
686
|
});
|
|
737
|
-
}),
|
|
738
|
-
},
|
|
739
|
-
const o = e.sections.flatMap((
|
|
687
|
+
}), a;
|
|
688
|
+
}, ee = (e, t, n, a = "en") => {
|
|
689
|
+
const o = e.sections.flatMap((x) => x.fields).find((x) => x.id === n);
|
|
740
690
|
if (!o) return [];
|
|
741
|
-
const
|
|
742
|
-
if (
|
|
743
|
-
typeof
|
|
744
|
-
),
|
|
745
|
-
const
|
|
746
|
-
|
|
691
|
+
const s = o.validations || {}, u = t[n], c = [], h = f(o.label, a);
|
|
692
|
+
if (s.required && (u == null || u === "") && c.push(
|
|
693
|
+
typeof s.required == "string" ? s.required : `${h} is required`
|
|
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 x = s.validate(u);
|
|
696
|
+
x && c.push(f(x, a));
|
|
747
697
|
}
|
|
748
698
|
return c;
|
|
749
699
|
};
|
|
750
|
-
function
|
|
751
|
-
|
|
700
|
+
function N(e, t) {
|
|
701
|
+
if (!e)
|
|
702
|
+
return !0;
|
|
703
|
+
if ("field" in e) {
|
|
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
|
+
}
|
|
707
|
+
if ("operator" in e) {
|
|
708
|
+
if (e.operator === "AND")
|
|
709
|
+
return e.conditions.every(
|
|
710
|
+
(a) => N(a, t)
|
|
711
|
+
);
|
|
712
|
+
if (e.operator === "OR")
|
|
713
|
+
return e.conditions.some(
|
|
714
|
+
(n) => N(n, t)
|
|
715
|
+
);
|
|
716
|
+
}
|
|
717
|
+
return !1;
|
|
718
|
+
}
|
|
719
|
+
const Le = ({
|
|
720
|
+
section: e,
|
|
721
|
+
values: t,
|
|
722
|
+
onChange: n,
|
|
723
|
+
renderers: a,
|
|
724
|
+
validateField: o,
|
|
725
|
+
locale: s = "en"
|
|
726
|
+
}) => /* @__PURE__ */ l.jsxs(ye, { mb: 2, children: [
|
|
727
|
+
e.heading && /* @__PURE__ */ l.jsx(
|
|
728
|
+
T,
|
|
729
|
+
{
|
|
730
|
+
variant: "h6",
|
|
731
|
+
sx: {
|
|
732
|
+
fontSize: e.headingFontSize ? `${e.headingFontSize}rem` : "1.25rem"
|
|
733
|
+
},
|
|
734
|
+
gutterBottom: !0,
|
|
735
|
+
color: "black",
|
|
736
|
+
children: f(e.heading, s)
|
|
737
|
+
}
|
|
738
|
+
),
|
|
739
|
+
e.description && /* @__PURE__ */ l.jsx(
|
|
740
|
+
T,
|
|
741
|
+
{
|
|
742
|
+
variant: "body2",
|
|
743
|
+
sx: {
|
|
744
|
+
fontSize: e.descriptionFontSize ? `${e.descriptionFontSize}rem` : "inherit"
|
|
745
|
+
},
|
|
746
|
+
color: "textSecondary",
|
|
747
|
+
gutterBottom: !0,
|
|
748
|
+
children: f(e.description, s)
|
|
749
|
+
}
|
|
750
|
+
),
|
|
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
|
+
{
|
|
755
|
+
size: Ce(u.layout?.cols),
|
|
756
|
+
children: /* @__PURE__ */ l.jsx(
|
|
757
|
+
Pe,
|
|
758
|
+
{
|
|
759
|
+
field: u,
|
|
760
|
+
value: t[u.id],
|
|
761
|
+
onChange: (c) => n(u.id, c),
|
|
762
|
+
renderers: a,
|
|
763
|
+
error: o(u.id)?.join(","),
|
|
764
|
+
locale: s
|
|
765
|
+
}
|
|
766
|
+
)
|
|
767
|
+
},
|
|
768
|
+
u.id
|
|
769
|
+
)
|
|
770
|
+
) })
|
|
771
|
+
] });
|
|
772
|
+
function Ne(e, t = "en", n) {
|
|
773
|
+
const [a, o] = M({}), [s, u] = M({});
|
|
752
774
|
return {
|
|
753
775
|
/** Current form values for all fields */
|
|
754
|
-
values:
|
|
776
|
+
values: a,
|
|
755
777
|
/** Function to update a field value */
|
|
756
|
-
handleChange: (
|
|
757
|
-
|
|
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
|
+
}
|
|
758
783
|
},
|
|
759
784
|
/** Function to validate all fields */
|
|
760
|
-
validateAll: () =>
|
|
785
|
+
validateAll: () => Ie(e, a, t),
|
|
761
786
|
/** Function to get all current form values */
|
|
762
|
-
getValues: () =>
|
|
787
|
+
getValues: () => a,
|
|
763
788
|
/** Function to get all current form errors */
|
|
764
|
-
getErrors: () =>
|
|
789
|
+
getErrors: () => s,
|
|
765
790
|
/** Function to validate a specific field */
|
|
766
|
-
validateField: (
|
|
791
|
+
validateField: (g) => ee(e, a, g, t)
|
|
767
792
|
};
|
|
768
793
|
}
|
|
769
|
-
const Ye =
|
|
794
|
+
const Ye = X.forwardRef(({ dto: e, renderers: t, locale: n = "en", handleChangeCallback: a }, o) => {
|
|
770
795
|
const {
|
|
771
|
-
values:
|
|
772
|
-
handleChange:
|
|
773
|
-
getValues:
|
|
774
|
-
getErrors:
|
|
775
|
-
validateAll:
|
|
776
|
-
validateField:
|
|
777
|
-
} =
|
|
778
|
-
return de(
|
|
779
|
-
getValues:
|
|
780
|
-
getErrors:
|
|
781
|
-
validateAll:
|
|
782
|
-
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
|
|
783
808
|
})), /* @__PURE__ */ l.jsxs(l.Fragment, { children: [
|
|
784
809
|
e.title && /* @__PURE__ */ l.jsx(
|
|
785
|
-
|
|
810
|
+
T,
|
|
786
811
|
{
|
|
787
812
|
variant: "h5",
|
|
788
813
|
color: "black",
|
|
@@ -791,11 +816,11 @@ const Ye = G.forwardRef(({ dto: e, renderers: t, locale: n = "en" }, u) => {
|
|
|
791
816
|
fontWeight: "bold"
|
|
792
817
|
},
|
|
793
818
|
gutterBottom: !0,
|
|
794
|
-
children:
|
|
819
|
+
children: f(e.title, n)
|
|
795
820
|
}
|
|
796
821
|
),
|
|
797
822
|
e.description && /* @__PURE__ */ l.jsx(
|
|
798
|
-
|
|
823
|
+
T,
|
|
799
824
|
{
|
|
800
825
|
component: "p",
|
|
801
826
|
sx: {
|
|
@@ -803,36 +828,36 @@ const Ye = G.forwardRef(({ dto: e, renderers: t, locale: n = "en" }, u) => {
|
|
|
803
828
|
},
|
|
804
829
|
color: "textSecondary",
|
|
805
830
|
gutterBottom: !0,
|
|
806
|
-
children:
|
|
831
|
+
children: f(e.description, n)
|
|
807
832
|
}
|
|
808
833
|
),
|
|
809
|
-
e.sections.map((
|
|
810
|
-
|
|
834
|
+
e.sections.map((y) => /* @__PURE__ */ l.jsx(
|
|
835
|
+
Le,
|
|
811
836
|
{
|
|
812
|
-
section:
|
|
813
|
-
values:
|
|
814
|
-
onChange:
|
|
837
|
+
section: y,
|
|
838
|
+
values: s,
|
|
839
|
+
onChange: u,
|
|
815
840
|
renderers: t,
|
|
816
|
-
validateField:
|
|
841
|
+
validateField: E,
|
|
817
842
|
locale: n
|
|
818
843
|
},
|
|
819
|
-
|
|
844
|
+
y.id
|
|
820
845
|
))
|
|
821
846
|
] });
|
|
822
847
|
});
|
|
823
848
|
export {
|
|
824
849
|
ke as AutoCompleteField,
|
|
825
850
|
Se as CheckBoxInput,
|
|
826
|
-
|
|
851
|
+
Pe as Field,
|
|
827
852
|
Ye as FormBuilder,
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
853
|
+
$e as MultiAutoCompleteField,
|
|
854
|
+
Oe as RadioInput,
|
|
855
|
+
Le as Section,
|
|
856
|
+
Te as SelectInput,
|
|
857
|
+
we as TextAreaInput,
|
|
858
|
+
Ae as TextInput,
|
|
859
|
+
Ne as useFormBuilder,
|
|
860
|
+
Ie as validateAll,
|
|
861
|
+
ee as validateField,
|
|
837
862
|
ze as validationRules
|
|
838
863
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
(function(
|
|
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),ne[h+b]=!0)}if(h=null,m!==void 0&&(n(m),h=""+m),s(i)&&(n(i.key),h=""+i.key),"key"in i){m={};for(var L in i)L!=="key"&&(m[L]=i[L])}else m=i;return h&&d(m,typeof t=="function"?t.displayName||t.name||"Unknown":t),x(t,h,m,o(),F,I)}function T(t){A(t)?t._store&&(t._store.validated=1):typeof t=="object"&&t!==null&&t.$$typeof===C&&(t._payload.status==="fulfilled"?A(t._payload.value)&&t._payload.value._store&&(t._payload.value._store.validated=1):t._store&&(t._store.validated=1))}function A(t){return typeof t=="object"&&t!==null&&t.$$typeof===Z}var E=g,Z=Symbol.for("react.transitional.element"),de=Symbol.for("react.portal"),O=Symbol.for("react.fragment"),me=Symbol.for("react.strict_mode"),pe=Symbol.for("react.profiler"),fe=Symbol.for("react.consumer"),be=Symbol.for("react.context"),he=Symbol.for("react.forward_ref"),xe=Symbol.for("react.suspense"),ve=Symbol.for("react.suspense_list"),ge=Symbol.for("react.memo"),C=Symbol.for("react.lazy"),Ee=Symbol.for("react.activity"),Te=Symbol.for("react.client.reference"),P=E.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,Q=Object.prototype.hasOwnProperty,ye=Array.isArray,$=console.createTask?console.createTask:function(){return null};E={react_stack_bottom_frame:function(t){return t()}};var K,ee={},te=E.react_stack_bottom_frame.bind(E,a)(),re=$(u(a)),ne={};_.Fragment=O,_.jsx=function(t,i,m){var b=1e4>P.recentlyCreatedOwnerStacks++;return y(t,i,m,!1,b?Error("react-stack-top-frame"):te,b?$(u(t)):re)},_.jsxs=function(t,i,m){var b=1e4>P.recentlyCreatedOwnerStacks++;return y(t,i,m,!0,b?Error("react-stack-top-frame"):te,b?$(u(t)):re)}})()),_}var z;function se(){return z||(z=1,process.env.NODE_ENV==="production"?S.exports=ae():S.exports=oe()),S.exports}var l=se();function f(e,r="en"){return e?typeof e=="string"?e:e[r]||e.en||Object.values(e)[0]||"":""}function k(e,r="en"){return e?e.map(n=>typeof n=="string"?{value:n,label:n}:{value:n.value,label:f(n.label,r)}):[]}function Y({field:e,value:r,onChange:n,error:u,locale:o="en"}){const a=k(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:r,id:e.id,name:e.id,onChange:s=>n(s.target.value),label:f(e.label,o),error:!!u,children:a?.map(s=>l.jsx(c.MenuItem,{value:s.value,children:s.label},s.label))}),u&&l.jsx(c.Typography,{variant:"caption",color:"error",children:u})]})}function W({field:e,value:r,onChange:n,error:u,locale:o}){return console.log("error",u),l.jsx(c.TextField,{fullWidth:!0,label:f(e.label,o),placeholder:f(e.placeholder||"",o),value:r||"",name:e.id,onChange:a=>n(a.target.value),disabled:e.disabled,type:e.type,slotProps:{inputLabel:{shrink:e.type==="date"?!0:void 0}},error:!!u,helperText:u})}function M({field:e,value:r,onChange:n,error:u,locale:o}){return l.jsxs(l.Fragment,{children:[l.jsx(c.FormControlLabel,{name:e.id,control:l.jsx(c.Checkbox,{checked:!!r,onChange:a=>n(a.target.checked),disabled:e.disabled}),label:f(e.label,o)}),u&&l.jsx(c.FormHelperText,{children:u})]})}const V=({field:e,value:r,onChange:n,error:u,locale:o})=>{const a=k(e.options||[],o);return l.jsx(c.Autocomplete,{fullWidth:!0,options:a||[],value:r||null,onChange:(s,d)=>n(d),renderInput:s=>l.jsx(c.TextField,{...s,name:e.id,label:f(e.label,o),placeholder:f(e.placeholder||"",o),disabled:e.disabled,error:!!u,helperText:u})})},q=({field:e,value:r,onChange:n,error:u,locale:o})=>{const a=k(e.options||[],o);return l.jsx(c.Autocomplete,{multiple:!0,fullWidth:!0,options:a||[],value:r||[],onChange:(s,d)=>n(d),renderInput:s=>l.jsx(c.TextField,{...s,name:e.id,label:f(e.label,o),placeholder:f(e.placeholder||"",o),disabled:e.disabled,error:!!u,helperText:u})})},B=({field:e,value:r,onChange:n,error:u,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:r||"",onChange:a=>n(a.target.value),required:!!e.validations?.required,disabled:e.disabled,error:!!u,helperText:u}),U=({field:e,value:r,onChange:n,error:u,locale:o="en"})=>{const a=k(e.options||[],o);return l.jsxs(c.FormControl,{component:"fieldset",fullWidth:!0,error:!!u,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:r||"",onChange:s=>n(s.target.value),children:(a||[]).map(s=>l.jsx(c.FormControlLabel,{value:s,control:l.jsx(c.Radio,{}),label:s.label,disabled:e.disabled},s.label))}),u&&l.jsx(c.FormHelperText,{children:u})]})},ue=({field:e,value:r,onChange:n,error:u,locale:o="en"})=>{switch(e.type){case"text":case"date":case"email":case"password":case"number":return l.jsx(W,{field:e,value:r,onChange:n,error:u,locale:o});case"select":return l.jsx(Y,{field:e,value:r,onChange:n,error:u,locale:o});case"autocomplete":return l.jsx(V,{field:e,value:r,onChange:n,error:u,locale:o});case"multi-autocomplete":return l.jsx(q,{field:e,value:r,onChange:n,error:u,locale:o});case"checkbox":return l.jsx(M,{field:e,value:r,onChange:n,error:u,locale:o});case"textarea":return l.jsx(B,{field:e,value:r,onChange:n,error:u,locale:o});case"radio":return l.jsx(U,{field:e,value:r,onChange:n,error:u,locale:o});default:return l.jsxs("span",{children:["Unsupported field type: ",e.type]})}},G=({field:e,value:r,onChange:n,error:u,renderers:o={},locale:a="en"})=>{const s=o[e.type]||ue;return l.jsx(s,{field:e,value:r,onChange:n,error:u,locale:a})};function le(e){const r=e??12;return{xs:12,sm:r,md:r,lg:r,xl:r}}const J=({section:e,values:r,onChange:n,renderers:u,validateField:o,locale:a="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,a)}),e.description&&l.jsx(c.Typography,{variant:"body2",sx:{fontSize:e.descriptionFontSize?`${e.descriptionFontSize}rem`:"inherit"},color:"textSecondary",gutterBottom:!0,children:f(e.description,a)}),l.jsx(c.Grid,{container:!0,spacing:2,children:e.fields.map(s=>l.jsx(c.Grid,{size:le(s.layout?.cols),children:l.jsx(G,{field:s,value:r[s.id],onChange:d=>n(s.id,d),renderers:u,error:o(s.id)?.join(","),locale:a})},s.id))})]}),ie={required:(e,r)=>e.required&&(r==null||r==="")?`${e.label} is required`:null,min:(e,r)=>e.type==="number"&&e.min!==void 0&&r<e.min?`${e.label} must be at least ${e.min}`:null,max:(e,r)=>e.type==="number"&&e.max!==void 0&&r>e.max?`${e.label} must be at most ${e.max}`:null,minLength:(e,r)=>typeof r=="string"&&e.minLength!==void 0&&r.length<e.minLength?`${e.label} must be at least ${e.minLength} characters`:null,maxLength:(e,r)=>typeof r=="string"&&e.maxLength!==void 0&&r.length>e.maxLength?`${e.label} must be at most ${e.maxLength} characters`:null,pattern:(e,r)=>e.pattern&&typeof r=="string"&&!e.pattern.test(r)?`${e.label} is invalid`:null,options:(e,r)=>e.type==="select"&&e.options&&!e.options.includes(r)?`${e.label} must be one of: ${e.options.join(", ")}`:null,dateRange:(e,r)=>{if(e.type==="date"&&r){const n=new Date(r);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,r)=>{if(e.customValidator&&typeof e.customValidator=="function"){const n=e.customValidator(r);if(typeof n=="string")return n}return null}},H=(e,r,n="en")=>{const u={};return e.sections.forEach(o=>{o.fields.forEach(a=>{const s=w(e,r,a.id);s.length>0&&(u[a.id]=s)})}),u},w=(e,r,n,u="en")=>{const o=e.sections.flatMap(x=>x.fields).find(x=>x.id===n);if(!o)return[];const a=o.validations||{},s=r[n],d=[],v=f(o.label,u);if(a.required&&(s==null||s==="")&&d.push(typeof a.required=="string"?a.required:`${v} is required`),a.min!==void 0&&typeof s=="number"&&s<a.min&&d.push(`${v} must be at least ${a.min}`),a.max!==void 0&&typeof s=="number"&&s>a.max&&d.push(`${v} must be at most ${a.max}`),a.minLength!==void 0&&typeof s=="string"&&s.length<a.minLength&&d.push(`${v} must be at least ${a.minLength} characters`),a.maxLength!==void 0&&typeof s=="string"&&s.length>a.maxLength&&d.push(`${v} must be at most ${a.maxLength} characters`),a.pattern&&typeof s=="string"&&!a.pattern.test(s)&&d.push(`${v} is invalid`),a.validate){const x=a.validate(s);x&&d.push(f(x,u))}return d};function X(e,r="en"){const[n,u]=g.useState({}),[o,a]=g.useState({});return{values:n,handleChange:(T,A)=>{u(E=>({...E,[T]:A})),a(E=>({...E,[T]:null}))},validateAll:()=>H(e,n,r),getValues:()=>n,getErrors:()=>o,validateField:T=>w(e,n,T,r)}}const ce=g.forwardRef(({dto:e,renderers:r,locale:n="en"},u)=>{const{values:o,handleChange:a,getValues:s,getErrors:d,validateAll:v,validateField:x}=X(e,n);return g.useImperativeHandle(u,()=>({getValues:s,getErrors:d,validateAll:v,validateField:x})),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(y=>l.jsx(J,{section:y,values:o,onChange:a,renderers:r,validateField:x,locale:n},y.id))]})});p.AutoCompleteField=V,p.CheckBoxInput=M,p.Field=G,p.FormBuilder=ce,p.MultiAutoCompleteField=q,p.RadioInput=U,p.Section=J,p.SelectInput=Y,p.TextAreaInput=B,p.TextInput=W,p.useFormBuilder=X,p.validateAll=H,p.validateField=w,p.validationRules=ie,Object.defineProperty(p,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/dist/types/dto.d.ts
CHANGED
|
@@ -22,6 +22,7 @@ export type FieldDTO = {
|
|
|
22
22
|
defaultValue?: any;
|
|
23
23
|
layout?: LayoutDTO;
|
|
24
24
|
validations?: Validations;
|
|
25
|
+
visibleWhen?: Condition;
|
|
25
26
|
};
|
|
26
27
|
export type SectionDTO = {
|
|
27
28
|
id: string;
|
|
@@ -49,3 +50,17 @@ export type Validations = {
|
|
|
49
50
|
pattern?: RegExp;
|
|
50
51
|
validate?: (value: any) => I18nString | null;
|
|
51
52
|
};
|
|
53
|
+
export interface FieldCondition {
|
|
54
|
+
field: string;
|
|
55
|
+
equals?: any;
|
|
56
|
+
notEquals?: any;
|
|
57
|
+
in?: any[];
|
|
58
|
+
notIn?: any[];
|
|
59
|
+
greaterThan?: number;
|
|
60
|
+
lessThan?: number;
|
|
61
|
+
}
|
|
62
|
+
export interface ConditionGroup {
|
|
63
|
+
operator: "AND" | "OR";
|
|
64
|
+
conditions: Condition[];
|
|
65
|
+
}
|
|
66
|
+
export type Condition = FieldCondition | ConditionGroup;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Condition } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Evaluates a condition tree against form state.
|
|
4
|
+
* @param condition - The condition or group to evaluate
|
|
5
|
+
* @param formState - Current form values (key-value pairs)
|
|
6
|
+
* @returns boolean
|
|
7
|
+
*/
|
|
8
|
+
export declare function evaluateCondition(condition: Condition | undefined, formState: Record<string, any>): boolean;
|
package/dist/utils/index.d.ts
CHANGED
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",
|