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 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 G, { useState as W, useImperativeHandle as de } from "react";
2
- import { FormControl as J, InputLabel as pe, Select as be, MenuItem as fe, Typography as R, TextField as k, FormControlLabel as X, Checkbox as he, FormHelperText as H, Autocomplete as Z, FormLabel as xe, RadioGroup as ve, Radio as ge, Box as Ee, Grid as V } from "@mui/material";
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 M;
5
- function _e() {
6
- if (M) return _;
7
- M = 1;
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(u, o, a) {
10
- var s = null;
11
- if (a !== void 0 && (s = "" + a), o.key !== void 0 && (s = "" + o.key), "key" in o) {
12
- a = {};
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" && (a[c] = o[c]);
15
- } else a = o;
16
- return o = a.ref, {
14
+ c !== "key" && (s[c] = o[c]);
15
+ } else s = o;
16
+ return o = s.ref, {
17
17
  $$typeof: e,
18
- type: u,
19
- key: s,
18
+ type: a,
19
+ key: u,
20
20
  ref: o !== void 0 ? o : null,
21
- props: a
21
+ props: s
22
22
  };
23
23
  }
24
24
  return _.Fragment = t, _.jsx = n, _.jsxs = n, _;
25
25
  }
26
- var j = {};
27
- var B;
28
- function je() {
29
- return B || (B = 1, process.env.NODE_ENV !== "production" && (function() {
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 === ie ? null : r.displayName || r.name || null;
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 re:
38
+ case te:
39
39
  return "Profiler";
40
- case ee:
40
+ case re:
41
41
  return "StrictMode";
42
42
  case oe:
43
43
  return "Suspense";
44
- case se:
44
+ case ue:
45
45
  return "SuspenseList";
46
- case le:
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 K:
53
+ case w:
54
54
  return "Portal";
55
- case ne:
55
+ case ae:
56
56
  return r.displayName || "Context";
57
- case te:
57
+ case ne:
58
58
  return (r._context.displayName || "Context") + ".Consumer";
59
- case ae:
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 ue:
62
+ case le:
63
63
  return i = r.displayName || null, i !== null ? i : e(r.type) || "Memo";
64
- case w:
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, d = typeof Symbol == "function" && Symbol.toStringTag && r[Symbol.toStringTag] || r.constructor.name || "Object";
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
- d
89
+ p
90
90
  ), t(r);
91
91
  }
92
92
  }
93
- function u(r) {
94
- if (r === $) return "<>";
95
- if (typeof r == "object" && r !== null && r.$$typeof === w)
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 = O.A;
105
+ var r = P.A;
106
106
  return r === null ? null : r.getOwner();
107
107
  }
108
- function a() {
108
+ function s() {
109
109
  return Error("react-stack-top-frame");
110
110
  }
111
- function s(r) {
112
- if (I.call(r, "key")) {
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
- N || (N = !0, console.error(
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 D[r] || (D[r] = !0, console.error(
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 f(r, i, m, d, T, P) {
137
- var p = m.ref;
136
+ function x(r, i, m, p, A, I) {
137
+ var d = m.ref;
138
138
  return r = {
139
- $$typeof: L,
139
+ $$typeof: v,
140
140
  type: r,
141
141
  key: i,
142
142
  props: m,
143
- _owner: d
144
- }, (p !== void 0 ? p : null) !== null ? Object.defineProperty(r, "ref", {
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: T
161
+ value: A
162
162
  }), Object.defineProperty(r, "_debugTask", {
163
163
  configurable: !1,
164
164
  enumerable: !1,
165
165
  writable: !0,
166
- value: P
166
+ value: I
167
167
  }), Object.freeze && (Object.freeze(r.props), Object.freeze(r)), r;
168
168
  }
169
- function g(r, i, m, d, T, P) {
170
- var p = i.children;
171
- if (p !== void 0)
172
- if (d)
173
- if (ce(p)) {
174
- for (d = 0; d < p.length; d++)
175
- v(p[d]);
176
- Object.freeze && Object.freeze(p);
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 v(p);
182
- if (I.call(i, "key")) {
183
- p = e(r);
184
- var E = Object.keys(i).filter(function(me) {
185
- return me !== "key";
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
- d = 0 < E.length ? "{key: someKey, " + E.join(": ..., ") + ": ...}" : "{key: someKey}", q[p + d] || (E = 0 < E.length ? "{" + E.join(": ..., ") + ": ...}" : "{}", console.error(
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
- E,
197
- p
198
- ), q[p + d] = !0);
195
+ d,
196
+ j,
197
+ d
198
+ ), V[d + p] = !0);
199
199
  }
200
- if (p = null, m !== void 0 && (n(m), p = "" + m), s(i) && (n(i.key), p = "" + i.key), "key" in i) {
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 C in i)
203
- C !== "key" && (m[C] = i[C]);
202
+ for (var L in i)
203
+ L !== "key" && (m[L] = i[L]);
204
204
  } else m = i;
205
- return p && c(
205
+ return d && c(
206
206
  m,
207
207
  typeof r == "function" ? r.displayName || r.name || "Unknown" : r
208
- ), f(
208
+ ), x(
209
209
  r,
210
- p,
210
+ d,
211
211
  m,
212
212
  o(),
213
- T,
214
- P
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
- return typeof r == "object" && r !== null && r.$$typeof === L;
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 x = G, L = Symbol.for("react.transitional.element"), K = Symbol.for("react.portal"), $ = Symbol.for("react.fragment"), ee = Symbol.for("react.strict_mode"), re = Symbol.for("react.profiler"), te = Symbol.for("react.consumer"), ne = Symbol.for("react.context"), ae = Symbol.for("react.forward_ref"), oe = Symbol.for("react.suspense"), se = Symbol.for("react.suspense_list"), ue = Symbol.for("react.memo"), w = Symbol.for("react.lazy"), le = Symbol.for("react.activity"), ie = Symbol.for("react.client.reference"), O = x.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, I = Object.prototype.hasOwnProperty, ce = Array.isArray, F = console.createTask ? console.createTask : function() {
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
- x = {
226
+ b = {
227
227
  react_stack_bottom_frame: function(r) {
228
228
  return r();
229
229
  }
230
230
  };
231
- var N, D = {}, z = x.react_stack_bottom_frame.bind(
232
- x,
233
- a
234
- )(), Y = F(u(a)), q = {};
235
- j.Fragment = $, j.jsx = function(r, i, m) {
236
- var d = 1e4 > O.recentlyCreatedOwnerStacks++;
237
- return g(
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
- d ? Error("react-stack-top-frame") : z,
243
- d ? F(u(r)) : Y
242
+ p ? Error("react-stack-top-frame") : Y,
243
+ p ? C(a(r)) : W
244
244
  );
245
- }, j.jsxs = function(r, i, m) {
246
- var d = 1e4 > O.recentlyCreatedOwnerStacks++;
247
- return g(
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
- d ? Error("react-stack-top-frame") : z,
253
- d ? F(u(r)) : Y
252
+ p ? Error("react-stack-top-frame") : Y,
253
+ p ? C(a(r)) : W
254
254
  );
255
255
  };
256
- })()), j;
256
+ })()), R;
257
257
  }
258
- var U;
258
+ var J;
259
259
  function Re() {
260
- return U || (U = 1, process.env.NODE_ENV === "production" ? S.exports = _e() : S.exports = je()), S.exports;
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 b(e, t = "en") {
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 A(e, t = "en") {
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: b(n.label, t)
269
+ label: f(n.label, t)
270
270
  }) : [];
271
271
  }
272
- function ye({
272
+ function Te({
273
273
  field: e,
274
274
  value: t,
275
275
  onChange: n,
276
- error: u,
276
+ error: a,
277
277
  locale: o = "en"
278
278
  }) {
279
- const a = A(e.options || [], o);
280
- return /* @__PURE__ */ l.jsxs(J, { fullWidth: !0, children: [
281
- /* @__PURE__ */ l.jsx(pe, { id: `${e.id}-label`, children: b(e.label, o) }),
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: (s) => n(s.target.value),
290
- label: b(e.label, o),
291
- error: !!u,
292
- children: a?.map((s) => /* @__PURE__ */ l.jsx(fe, { value: s.value, children: s.label }, s.label))
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
- u && /* @__PURE__ */ l.jsx(R, { variant: "caption", color: "error", children: u })
295
+ a && /* @__PURE__ */ l.jsx(T, { variant: "caption", color: "error", children: a })
296
296
  ] });
297
297
  }
298
- function Te({
298
+ function Ae({
299
299
  field: e,
300
300
  value: t,
301
301
  onChange: n,
302
- error: u,
302
+ error: a,
303
303
  locale: o
304
304
  }) {
305
- return console.log("error", u), /* @__PURE__ */ l.jsx(
305
+ return console.log("error", a), /* @__PURE__ */ l.jsx(
306
306
  k,
307
307
  {
308
308
  fullWidth: !0,
309
- label: b(e.label, o),
310
- placeholder: b(e.placeholder || "", o),
309
+ label: f(e.label, o),
310
+ placeholder: f(e.placeholder || "", o),
311
311
  value: t || "",
312
312
  name: e.id,
313
- onChange: (a) => n(a.target.value),
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: !!u,
322
- helperText: u
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: u,
330
+ error: a,
331
331
  locale: o
332
332
  }) {
333
333
  return /* @__PURE__ */ l.jsxs(l.Fragment, { children: [
334
334
  /* @__PURE__ */ l.jsx(
335
- X,
335
+ Z,
336
336
  {
337
337
  name: e.id,
338
338
  control: /* @__PURE__ */ l.jsx(
339
- he,
339
+ xe,
340
340
  {
341
341
  checked: !!t,
342
- onChange: (a) => n(a.target.checked),
342
+ onChange: (s) => n(s.target.checked),
343
343
  disabled: e.disabled
344
344
  }
345
345
  ),
346
- label: b(e.label, o)
346
+ label: f(e.label, o)
347
347
  }
348
348
  ),
349
- u && /* @__PURE__ */ l.jsx(H, { children: u })
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: u,
356
+ error: a,
357
357
  locale: o
358
358
  }) => {
359
- const a = A(e.options || [], o);
359
+ const s = $(e.options || [], o);
360
360
  return /* @__PURE__ */ l.jsx(
361
- Z,
361
+ K,
362
362
  {
363
363
  fullWidth: !0,
364
- options: a || [],
364
+ options: s || [],
365
365
  value: t || null,
366
- onChange: (s, c) => n(c),
367
- renderInput: (s) => /* @__PURE__ */ l.jsx(
366
+ onChange: (u, c) => n(c),
367
+ renderInput: (u) => /* @__PURE__ */ l.jsx(
368
368
  k,
369
369
  {
370
- ...s,
370
+ ...u,
371
371
  name: e.id,
372
- label: b(e.label, o),
373
- placeholder: b(
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: !!u,
379
- helperText: u
378
+ error: !!a,
379
+ helperText: a
380
380
  }
381
381
  )
382
382
  }
383
383
  );
384
- }, Ae = ({
384
+ }, $e = ({
385
385
  field: e,
386
386
  value: t,
387
387
  onChange: n,
388
- error: u,
388
+ error: a,
389
389
  locale: o
390
390
  }) => {
391
- const a = A(e.options || [], o);
391
+ const s = $(e.options || [], o);
392
392
  return /* @__PURE__ */ l.jsx(
393
- Z,
393
+ K,
394
394
  {
395
395
  multiple: !0,
396
396
  fullWidth: !0,
397
- options: a || [],
397
+ options: s || [],
398
398
  value: t || [],
399
- onChange: (s, c) => n(c),
400
- renderInput: (s) => /* @__PURE__ */ l.jsx(
399
+ onChange: (u, c) => n(c),
400
+ renderInput: (u) => /* @__PURE__ */ l.jsx(
401
401
  k,
402
402
  {
403
- ...s,
403
+ ...u,
404
404
  name: e.id,
405
- label: b(e.label, o),
406
- placeholder: b(
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: !!u,
412
- helperText: u
411
+ error: !!a,
412
+ helperText: a
413
413
  }
414
414
  )
415
415
  }
416
416
  );
417
- }, $e = ({
417
+ }, we = ({
418
418
  field: e,
419
419
  value: t,
420
420
  onChange: n,
421
- error: u,
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: b(e.label, o),
430
- placeholder: b(e.placeholder || "", o),
429
+ label: f(e.label, o),
430
+ placeholder: f(e.placeholder || "", o),
431
431
  value: t || "",
432
- onChange: (a) => n(a.target.value),
432
+ onChange: (s) => n(s.target.value),
433
433
  required: !!e.validations?.required,
434
434
  disabled: e.disabled,
435
- error: !!u,
436
- helperText: u
435
+ error: !!a,
436
+ helperText: a
437
437
  }
438
- ), we = ({
438
+ ), Oe = ({
439
439
  field: e,
440
440
  value: t,
441
441
  onChange: n,
442
- error: u,
442
+ error: a,
443
443
  locale: o = "en"
444
444
  }) => {
445
- const a = A(e.options || [], o);
446
- return /* @__PURE__ */ l.jsxs(J, { component: "fieldset", fullWidth: !0, error: !!u, children: [
447
- /* @__PURE__ */ l.jsxs(xe, { component: "legend", children: [
448
- b(e.label, o),
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
- ve,
452
+ ge,
453
453
  {
454
454
  row: e.layout?.direction === "row" || !1,
455
455
  value: t || "",
456
- onChange: (s) => n(s.target.value),
457
- children: (a || []).map((s) => /* @__PURE__ */ l.jsx(
458
- X,
456
+ onChange: (u) => n(u.target.value),
457
+ children: (s || []).map((u) => /* @__PURE__ */ l.jsx(
458
+ Z,
459
459
  {
460
- value: s,
461
- control: /* @__PURE__ */ l.jsx(ge, {}),
462
- label: s.label,
460
+ value: u.value,
461
+ control: /* @__PURE__ */ l.jsx(Ee, {}),
462
+ label: u.label,
463
463
  disabled: e.disabled
464
464
  },
465
- s.label
465
+ u.label
466
466
  ))
467
467
  }
468
468
  ),
469
- u && /* @__PURE__ */ l.jsx(H, { children: u })
469
+ a && /* @__PURE__ */ l.jsx(Q, { children: a })
470
470
  ] });
471
- }, Oe = ({
471
+ }, Fe = ({
472
472
  field: e,
473
473
  value: t,
474
474
  onChange: n,
475
- error: u,
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
- Te,
485
+ Ae,
486
486
  {
487
487
  field: e,
488
488
  value: t,
489
489
  onChange: n,
490
- error: u,
490
+ error: a,
491
491
  locale: o
492
492
  }
493
493
  );
494
494
  case "select":
495
495
  return /* @__PURE__ */ l.jsx(
496
- ye,
496
+ Te,
497
497
  {
498
498
  field: e,
499
499
  value: t,
500
500
  onChange: n,
501
- error: u,
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: u,
512
+ error: a,
513
513
  locale: o
514
514
  }
515
515
  );
516
516
  case "multi-autocomplete":
517
517
  return /* @__PURE__ */ l.jsx(
518
- Ae,
518
+ $e,
519
519
  {
520
520
  field: e,
521
521
  value: t,
522
522
  onChange: n,
523
- error: u,
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: u,
534
+ error: a,
535
535
  locale: o
536
536
  }
537
537
  );
538
538
  case "textarea":
539
539
  return /* @__PURE__ */ l.jsx(
540
- $e,
540
+ we,
541
541
  {
542
542
  field: e,
543
543
  value: t,
544
544
  onChange: n,
545
- error: u,
545
+ error: a,
546
546
  locale: o
547
547
  }
548
548
  );
549
549
  case "radio":
550
550
  return /* @__PURE__ */ l.jsx(
551
- we,
551
+ Oe,
552
552
  {
553
553
  field: e,
554
554
  value: t,
555
555
  onChange: n,
556
- error: u,
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
- }, Fe = ({
566
+ }, Pe = ({
567
567
  field: e,
568
568
  value: t,
569
569
  onChange: n,
570
- error: u,
570
+ error: a,
571
571
  renderers: o = {},
572
- locale: a = "en"
572
+ locale: s = "en"
573
573
  }) => {
574
- const s = o[e.type] || Oe;
574
+ const u = o[e.type] || Fe;
575
575
  return /* @__PURE__ */ l.jsx(
576
- s,
576
+ u,
577
577
  {
578
578
  field: e,
579
579
  value: t,
580
580
  onChange: n,
581
- error: u,
582
- locale: a
581
+ error: a,
582
+ locale: s
583
583
  }
584
584
  );
585
585
  };
586
- function Pe(e) {
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 Ce = ({
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
- }, Le = (e, t, n = "en") => {
731
- const u = {};
680
+ }, Ie = (e, t, n = "en") => {
681
+ const a = {};
732
682
  return e.sections.forEach((o) => {
733
- o.fields.forEach((a) => {
734
- const s = Q(e, t, a.id);
735
- s.length > 0 && (u[a.id] = s);
683
+ o.fields.forEach((s) => {
684
+ const u = ee(e, t, s.id);
685
+ u.length > 0 && (a[s.id] = u);
736
686
  });
737
- }), u;
738
- }, Q = (e, t, n, u = "en") => {
739
- const o = e.sections.flatMap((f) => f.fields).find((f) => f.id === n);
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 a = o.validations || {}, s = t[n], c = [], h = b(o.label, u);
742
- if (a.required && (s == null || s === "") && c.push(
743
- typeof a.required == "string" ? a.required : `${h} is required`
744
- ), a.min !== void 0 && typeof s == "number" && s < a.min && c.push(`${h} must be at least ${a.min}`), a.max !== void 0 && typeof s == "number" && s > a.max && c.push(`${h} must be at most ${a.max}`), a.minLength !== void 0 && typeof s == "string" && s.length < a.minLength && c.push(`${h} must be at least ${a.minLength} characters`), a.maxLength !== void 0 && typeof s == "string" && s.length > a.maxLength && c.push(`${h} must be at most ${a.maxLength} characters`), a.pattern && typeof s == "string" && !a.pattern.test(s) && c.push(`${h} is invalid`), a.validate) {
745
- const f = a.validate(s);
746
- f && c.push(b(f, u));
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 Ie(e, t = "en") {
751
- const [n, u] = W({}), [o, a] = W({});
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: n,
776
+ values: a,
755
777
  /** Function to update a field value */
756
- handleChange: (v, y) => {
757
- u((x) => ({ ...x, [v]: y })), a((x) => ({ ...x, [v]: null }));
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: () => Le(e, n, t),
785
+ validateAll: () => Ie(e, a, t),
761
786
  /** Function to get all current form values */
762
- getValues: () => n,
787
+ getValues: () => a,
763
788
  /** Function to get all current form errors */
764
- getErrors: () => o,
789
+ getErrors: () => s,
765
790
  /** Function to validate a specific field */
766
- validateField: (v) => Q(e, n, v, t)
791
+ validateField: (g) => ee(e, a, g, t)
767
792
  };
768
793
  }
769
- const Ye = G.forwardRef(({ dto: e, renderers: t, locale: n = "en" }, u) => {
794
+ const Ye = X.forwardRef(({ dto: e, renderers: t, locale: n = "en", handleChangeCallback: a }, o) => {
770
795
  const {
771
- values: o,
772
- handleChange: a,
773
- getValues: s,
774
- getErrors: c,
775
- validateAll: h,
776
- validateField: f
777
- } = Ie(e, n);
778
- return de(u, () => ({
779
- getValues: s,
780
- getErrors: c,
781
- validateAll: h,
782
- validateField: f
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
- R,
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: b(e.title, n)
819
+ children: f(e.title, n)
795
820
  }
796
821
  ),
797
822
  e.description && /* @__PURE__ */ l.jsx(
798
- R,
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: b(e.description, n)
831
+ children: f(e.description, n)
807
832
  }
808
833
  ),
809
- e.sections.map((g) => /* @__PURE__ */ l.jsx(
810
- Ce,
834
+ e.sections.map((y) => /* @__PURE__ */ l.jsx(
835
+ Le,
811
836
  {
812
- section: g,
813
- values: o,
814
- onChange: a,
837
+ section: y,
838
+ values: s,
839
+ onChange: u,
815
840
  renderers: t,
816
- validateField: f,
841
+ validateField: E,
817
842
  locale: n
818
843
  },
819
- g.id
844
+ y.id
820
845
  ))
821
846
  ] });
822
847
  });
823
848
  export {
824
849
  ke as AutoCompleteField,
825
850
  Se as CheckBoxInput,
826
- Fe as Field,
851
+ Pe as Field,
827
852
  Ye as FormBuilder,
828
- Ae as MultiAutoCompleteField,
829
- we as RadioInput,
830
- Ce as Section,
831
- ye as SelectInput,
832
- $e as TextAreaInput,
833
- Te as TextInput,
834
- Ie as useFormBuilder,
835
- Le as validateAll,
836
- Q as validateField,
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(p,g){typeof exports=="object"&&typeof module<"u"?g(exports,require("react"),require("@mui/material")):typeof define=="function"&&define.amd?define(["exports","react","@mui/material"],g):(p=typeof globalThis<"u"?globalThis:p||self,g(p.ReactFormDTO={},p.React,p.MaterialUI))})(this,(function(p,g,c){"use strict";var S={exports:{}},R={};var N;function ae(){if(N)return R;N=1;var e=Symbol.for("react.transitional.element"),r=Symbol.for("react.fragment");function n(u,o,a){var s=null;if(a!==void 0&&(s=""+a),o.key!==void 0&&(s=""+o.key),"key"in o){a={};for(var d in o)d!=="key"&&(a[d]=o[d])}else a=o;return o=a.ref,{$$typeof:e,type:u,key:s,ref:o!==void 0?o:null,props:a}}return R.Fragment=r,R.jsx=n,R.jsxs=n,R}var _={};var D;function oe(){return D||(D=1,process.env.NODE_ENV!=="production"&&(function(){function e(t){if(t==null)return null;if(typeof t=="function")return t.$$typeof===Te?null:t.displayName||t.name||null;if(typeof t=="string")return t;switch(t){case O:return"Fragment";case pe:return"Profiler";case me:return"StrictMode";case xe:return"Suspense";case ve:return"SuspenseList";case Ee:return"Activity"}if(typeof t=="object")switch(typeof t.tag=="number"&&console.error("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),t.$$typeof){case de:return"Portal";case be:return t.displayName||"Context";case fe:return(t._context.displayName||"Context")+".Consumer";case he:var i=t.render;return t=t.displayName,t||(t=i.displayName||i.name||"",t=t!==""?"ForwardRef("+t+")":"ForwardRef"),t;case ge:return i=t.displayName||null,i!==null?i:e(t.type)||"Memo";case C:i=t._payload,t=t._init;try{return e(t(i))}catch{}}return null}function r(t){return""+t}function n(t){try{r(t);var i=!1}catch{i=!0}if(i){i=console;var m=i.error,b=typeof Symbol=="function"&&Symbol.toStringTag&&t[Symbol.toStringTag]||t.constructor.name||"Object";return m.call(i,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",b),r(t)}}function u(t){if(t===O)return"<>";if(typeof t=="object"&&t!==null&&t.$$typeof===C)return"<...>";try{var i=e(t);return i?"<"+i+">":"<...>"}catch{return"<...>"}}function o(){var t=P.A;return t===null?null:t.getOwner()}function a(){return Error("react-stack-top-frame")}function s(t){if(Q.call(t,"key")){var i=Object.getOwnPropertyDescriptor(t,"key").get;if(i&&i.isReactWarning)return!1}return t.key!==void 0}function d(t,i){function m(){K||(K=!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))}m.isReactWarning=!0,Object.defineProperty(t,"key",{get:m,configurable:!0})}function v(){var t=e(this.type);return ee[t]||(ee[t]=!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.")),t=this.props.ref,t!==void 0?t:null}function x(t,i,m,b,F,I){var h=m.ref;return t={$$typeof:Z,type:t,key:i,props:m,_owner:b},(h!==void 0?h:null)!==null?Object.defineProperty(t,"ref",{enumerable:!1,get:v}):Object.defineProperty(t,"ref",{enumerable:!1,value:null}),t._store={},Object.defineProperty(t._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:0}),Object.defineProperty(t,"_debugInfo",{configurable:!1,enumerable:!1,writable:!0,value:null}),Object.defineProperty(t,"_debugStack",{configurable:!1,enumerable:!1,writable:!0,value:F}),Object.defineProperty(t,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:I}),Object.freeze&&(Object.freeze(t.props),Object.freeze(t)),t}function y(t,i,m,b,F,I){var h=i.children;if(h!==void 0)if(b)if(ye(h)){for(b=0;b<h.length;b++)T(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 T(h);if(Q.call(i,"key")){h=e(t);var j=Object.keys(i).filter(function(je){return je!=="key"});b=0<j.length?"{key: someKey, "+j.join(": ..., ")+": ...}":"{key: someKey}",ne[h+b]||(j=0<j.length?"{"+j.join(": ..., ")+": ...}":"{}",console.error(`A props object containing a "key" prop is being spread into JSX:
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"})}));
@@ -7,6 +7,7 @@ declare const _default: {
7
7
  dto: FormDTO;
8
8
  renderers?: Record<string, React.ComponentType<any>>;
9
9
  locale?: string;
10
+ handleChangeCallback?: (id: string, val: any) => void;
10
11
  } & React.RefAttributes<FormBuilderHandle>>;
11
12
  argTypes: {
12
13
  dto: {
@@ -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;
@@ -1,3 +1,4 @@
1
1
  export * from './layout';
2
2
  export * from './validation';
3
3
  export * from './i18n';
4
+ export * from './evaluateVisibleWhen';
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.1",
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",