@harnessio/forms 0.0.2 → 0.0.4

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/dist/index.js CHANGED
@@ -1,21 +1,21 @@
1
- var H = Object.defineProperty;
2
- var Y = (r, e, t) => e in r ? H(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t;
3
- var C = (r, e, t) => Y(r, typeof e != "symbol" ? e + "" : e, t);
4
- import { isEmpty as S, cloneDeep as w, set as g, get as b, forOwn as G, isNull as K, isUndefined as j, capitalize as Q, isArray as V, isObject as B, merge as I, pick as X, unset as z, omitBy as J, isString as ee } from "lodash-es";
5
- import re, { useMemo as k, useRef as te, useEffect as E, forwardRef as ne, useCallback as se } from "react";
6
- import { useFormContext as ae, useForm as ue, FormProvider as ie, appendErrors as oe } from "react-hook-form";
1
+ var Q = Object.defineProperty;
2
+ var Y = (r, e, t) => e in r ? Q(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t;
3
+ var x = (r, e, t) => Y(r, typeof e != "symbol" ? e + "" : e, t);
4
+ import { isEmpty as R, cloneDeep as C, set as g, get as b, isArray as q, isObject as L, merge as T, isUndefined as I, pick as K, unset as X, omitBy as U, isString as z, forOwn as ee, isNull as re, capitalize as te } from "lodash-es";
5
+ import ne, { useMemo as Z, useRef as P, useEffect as O, useCallback as se, forwardRef as ae } from "react";
6
+ import { useFormContext as ue, useForm as ie, FormProvider as oe, appendErrors as ce } from "react-hook-form";
7
7
  export * from "react-hook-form";
8
8
  import * as m from "zod";
9
- import { toNestErrors as ce } from "@hookform/resolvers";
10
- class fe extends Error {
9
+ import { toNestErrors as fe } from "@hookform/resolvers";
10
+ class de extends Error {
11
11
  constructor(e) {
12
12
  super(`Input component '${e}' is already registered.`);
13
13
  }
14
14
  }
15
- class Ve {
15
+ class qe {
16
16
  constructor(e) {
17
- C(this, "componentBank");
18
- C(this, "allowOverride");
17
+ x(this, "componentBank");
18
+ x(this, "allowOverride");
19
19
  this.allowOverride = (e == null ? void 0 : e.allowOverride) ?? !1, this.componentBank = /* @__PURE__ */ new Map();
20
20
  }
21
21
  /**
@@ -26,24 +26,24 @@ class Ve {
26
26
  */
27
27
  registerComponent(e) {
28
28
  if (!this.allowOverride && this.getComponent(e.internalType))
29
- throw new fe(e.internalType);
29
+ throw new de(e.internalType);
30
30
  this.componentBank.set(e.internalType, e);
31
31
  }
32
32
  getComponent(e) {
33
- if (e && !S(e))
33
+ if (e && !R(e))
34
34
  return this.componentBank.get(e);
35
35
  }
36
36
  }
37
- var q = { exports: {} }, v = {};
37
+ var N = { exports: {} }, v = {};
38
38
  /*
39
39
  object-assign
40
40
  (c) Sindre Sorhus
41
41
  @license MIT
42
42
  */
43
- var x, A;
44
- function de() {
45
- if (A) return x;
46
- A = 1;
43
+ var k, $;
44
+ function le() {
45
+ if ($) return k;
46
+ $ = 1;
47
47
  var r = Object.getOwnPropertySymbols, e = Object.prototype.hasOwnProperty, t = Object.prototype.propertyIsEnumerable;
48
48
  function n(s) {
49
49
  if (s == null)
@@ -59,32 +59,32 @@ function de() {
59
59
  return !1;
60
60
  for (var o = {}, i = 0; i < 10; i++)
61
61
  o["_" + String.fromCharCode(i)] = i;
62
- var c = Object.getOwnPropertyNames(o).map(function(f) {
63
- return o[f];
62
+ var c = Object.getOwnPropertyNames(o).map(function(u) {
63
+ return o[u];
64
64
  });
65
65
  if (c.join("") !== "0123456789")
66
66
  return !1;
67
- var u = {};
68
- return "abcdefghijklmnopqrst".split("").forEach(function(f) {
69
- u[f] = f;
70
- }), Object.keys(Object.assign({}, u)).join("") === "abcdefghijklmnopqrst";
67
+ var f = {};
68
+ return "abcdefghijklmnopqrst".split("").forEach(function(u) {
69
+ f[u] = u;
70
+ }), Object.keys(Object.assign({}, f)).join("") === "abcdefghijklmnopqrst";
71
71
  } catch {
72
72
  return !1;
73
73
  }
74
74
  }
75
- return x = a() ? Object.assign : function(s, o) {
76
- for (var i, c = n(s), u, f = 1; f < arguments.length; f++) {
77
- i = Object(arguments[f]);
78
- for (var l in i)
79
- e.call(i, l) && (c[l] = i[l]);
75
+ return k = a() ? Object.assign : function(s, o) {
76
+ for (var i, c = n(s), f, u = 1; u < arguments.length; u++) {
77
+ i = Object(arguments[u]);
78
+ for (var d in i)
79
+ e.call(i, d) && (c[d] = i[d]);
80
80
  if (r) {
81
- u = r(i);
82
- for (var d = 0; d < u.length; d++)
83
- t.call(i, u[d]) && (c[u[d]] = i[u[d]]);
81
+ f = r(i);
82
+ for (var l = 0; l < f.length; l++)
83
+ t.call(i, f[l]) && (c[f[l]] = i[f[l]]);
84
84
  }
85
85
  }
86
86
  return c;
87
- }, x;
87
+ }, k;
88
88
  }
89
89
  /** @license React v17.0.2
90
90
  * react-jsx-runtime.production.min.js
@@ -94,31 +94,31 @@ function de() {
94
94
  * This source code is licensed under the MIT license found in the
95
95
  * LICENSE file in the root directory of this source tree.
96
96
  */
97
- var Z;
98
- function le() {
99
- if (Z) return v;
100
- Z = 1, de();
101
- var r = re, e = 60103;
97
+ var M;
98
+ function me() {
99
+ if (M) return v;
100
+ M = 1, le();
101
+ var r = ne, e = 60103;
102
102
  if (v.Fragment = 60107, typeof Symbol == "function" && Symbol.for) {
103
103
  var t = Symbol.for;
104
104
  e = t("react.element"), v.Fragment = t("react.fragment");
105
105
  }
106
106
  var n = r.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner, a = Object.prototype.hasOwnProperty, s = { key: !0, ref: !0, __self: !0, __source: !0 };
107
- function o(i, c, u) {
108
- var f, l = {}, d = null, h = null;
109
- u !== void 0 && (d = "" + u), c.key !== void 0 && (d = "" + c.key), c.ref !== void 0 && (h = c.ref);
110
- for (f in c) a.call(c, f) && !s.hasOwnProperty(f) && (l[f] = c[f]);
111
- if (i && i.defaultProps) for (f in c = i.defaultProps, c) l[f] === void 0 && (l[f] = c[f]);
112
- return { $$typeof: e, type: i, key: d, ref: h, props: l, _owner: n.current };
107
+ function o(i, c, f) {
108
+ var u, d = {}, l = null, h = null;
109
+ f !== void 0 && (l = "" + f), c.key !== void 0 && (l = "" + c.key), c.ref !== void 0 && (h = c.ref);
110
+ for (u in c) a.call(c, u) && !s.hasOwnProperty(u) && (d[u] = c[u]);
111
+ if (i && i.defaultProps) for (u in c = i.defaultProps, c) d[u] === void 0 && (d[u] = c[u]);
112
+ return { $$typeof: e, type: i, key: l, ref: h, props: d, _owner: n.current };
113
113
  }
114
114
  return v.jsx = o, v.jsxs = o, v;
115
115
  }
116
- var D;
117
- function me() {
118
- return D || (D = 1, q.exports = le()), q.exports;
116
+ var B;
117
+ function he() {
118
+ return B || (B = 1, N.exports = me()), N.exports;
119
119
  }
120
- var y = me();
121
- function he({
120
+ var y = he();
121
+ function ye({
122
122
  path: r,
123
123
  factory: e,
124
124
  onUpdate: t,
@@ -127,11 +127,11 @@ function he({
127
127
  initialValues: s,
128
128
  input: o
129
129
  }) {
130
- const { formState: i, watch: c } = ae(), {
131
- metadata: u = {},
132
- fixedValues: f = {}
130
+ const { formState: i, watch: c } = ue(), {
131
+ metadata: f = {},
132
+ fixedValues: u = {}
133
133
  /*getValuesWithDependencies*/
134
- } = {}, l = e == null ? void 0 : e.getComponent(o.inputType), d = k(
134
+ } = {}, d = e == null ? void 0 : e.getComponent(o.inputType), l = Z(
135
135
  () => ({
136
136
  path: r,
137
137
  initialValues: s,
@@ -142,28 +142,28 @@ function he({
142
142
  input: o
143
143
  }),
144
144
  [e, s, o, n, t, r, a, i.errors]
145
- ), h = c(), p = w(h);
146
- f && Object.keys(f).forEach((F) => {
147
- const W = f[F];
148
- g(p, F, W);
145
+ ), h = c(), S = C(h);
146
+ u && Object.keys(u).forEach((_) => {
147
+ const H = u[_];
148
+ g(S, _, H);
149
149
  });
150
- const _ = !o.isVisible || (o == null ? void 0 : o.isVisible(p, u)), U = k(() => _ ? /* @__PURE__ */ y.jsxs(y.Fragment, { children: [
150
+ const p = !o.isVisible || (o == null ? void 0 : o.isVisible(S, f)), j = Z(() => p ? /* @__PURE__ */ y.jsxs(y.Fragment, { children: [
151
151
  o.before ? o.before : null,
152
- l == null ? void 0 : l.renderComponent(d),
152
+ d == null ? void 0 : d.renderComponent(l),
153
153
  o.after ? o.after : null
154
- ] }) : null, [d, o.after, o.before, l, _, i.errors]);
155
- return l ? _ ? U : null : /* @__PURE__ */ y.jsxs("p", { children: [
154
+ ] }) : null, [l, o.after, o.before, d, p, i.errors]);
155
+ return d ? p ? j : null : /* @__PURE__ */ y.jsxs("p", { children: [
156
156
  "Input component not found (internal type: ",
157
157
  o.inputType,
158
158
  ")"
159
159
  ] });
160
160
  }
161
- class Ce {
161
+ class xe {
162
162
  getType() {
163
163
  return this.internalType;
164
164
  }
165
165
  }
166
- function qe(r) {
166
+ function Pe(r) {
167
167
  const {
168
168
  mode: e = "onSubmit",
169
169
  resolver: t,
@@ -171,24 +171,25 @@ function qe(r) {
171
171
  shouldFocusError: a,
172
172
  // validateAfterFirstSubmit,
173
173
  onValuesChange: s,
174
- onSubmit: o,
174
+ onValidationChange: o,
175
+ onSubmit: i,
175
176
  // validate,
176
177
  // validateDebounceInterval,
177
178
  // validationConfig,
178
179
  // metadata,
179
- children: i,
180
+ children: c,
180
181
  // fixedValues
181
- autoFocusPath: c
182
- } = r, u = ue({
182
+ autoFocusPath: f
183
+ } = r, u = ie({
183
184
  mode: e ?? "onSubmit",
184
185
  reValidateMode: "onChange",
185
186
  defaultValues: n,
186
187
  shouldFocusError: a,
187
188
  resolver: t
188
- }), f = te(!1);
189
- E(() => {
189
+ }), d = P(!1);
190
+ O(() => {
190
191
  u.reset(n, {});
191
- }, [u.reset, n]), E(() => {
192
+ }, [u.reset, n]), O(() => {
192
193
  requestIdleCallback(() => {
193
194
  u.reset({}, {
194
195
  keepErrors: !0,
@@ -204,91 +205,78 @@ function qe(r) {
204
205
  });
205
206
  });
206
207
  }, []);
207
- const { getValues: l, handleSubmit: d } = u, h = l();
208
- return E(() => {
209
- s == null || s({ ...h }, { isValid: u.formState.isValid }), f.current === !0 && u.trigger();
210
- }, [JSON.stringify(h)]), E(() => {
211
- if (c)
208
+ const { getValues: l, handleSubmit: h } = u, S = l(), p = P(!0);
209
+ O(() => {
210
+ if (p.current) {
211
+ p.current = !1;
212
+ return;
213
+ }
214
+ s == null || s({ ...S }), d.current === !0 && u.trigger();
215
+ }, [JSON.stringify(S)]);
216
+ const j = P(!0);
217
+ return O(() => {
218
+ if (j.current) {
219
+ j.current = !1;
220
+ return;
221
+ }
222
+ o == null || o({ isValid: u.formState.isValid, isSubmitted: u.formState.isSubmitted });
223
+ }, [u.formState.isValid, u.formState.isSubmitted]), O(() => {
224
+ if (f)
212
225
  if ("requestIdleCallback" in window) {
213
- const p = requestIdleCallback(() => {
214
- u.setFocus(c);
226
+ const _ = requestIdleCallback(() => {
227
+ u.setFocus(f);
215
228
  });
216
- return () => cancelIdleCallback(p);
229
+ return () => cancelIdleCallback(_);
217
230
  } else {
218
- const p = setTimeout(() => {
219
- u.setFocus(c);
231
+ const _ = setTimeout(() => {
232
+ u.setFocus(f);
220
233
  }, 100);
221
- return () => clearTimeout(p);
234
+ return () => clearTimeout(_);
222
235
  }
223
- }, [u]), /* @__PURE__ */ y.jsx(ie, { ...u, children: typeof i == "function" ? i({
236
+ }, [u]), /* @__PURE__ */ y.jsx(oe, { ...u, children: typeof c == "function" ? c({
224
237
  ...u,
225
238
  submitForm: async () => {
226
- o && (f.current = !0, d((p) => {
227
- o(p);
239
+ i && (d.current = !0, h((_) => {
240
+ i(_);
228
241
  })());
229
242
  }
230
- }) : i });
243
+ }) : c });
231
244
  }
232
- const xe = (r) => {
245
+ const Ne = (r) => {
233
246
  const e = {};
234
247
  return r.inputs.forEach((t) => {
235
248
  typeof b(e, t.path) > "u" && g(e, t.path, t.default);
236
249
  }), e;
237
250
  };
238
- function Pe(r, e) {
251
+ function ke(r, e) {
239
252
  const t = r.inputs.map((n) => {
240
- const a = ye(e, n.path);
253
+ const a = pe(e, n.path);
241
254
  return a || n;
242
255
  });
243
256
  return { ...r, inputs: t };
244
257
  }
245
- function ye(r, e) {
258
+ function pe(r, e) {
246
259
  return r.inputs.find((t) => t.path === e);
247
260
  }
248
- function pe({ input: r, factory: e }) {
249
- const { prefix: t = "" } = {};
250
- return /* @__PURE__ */ y.jsx("div", { children: /* @__PURE__ */ y.jsx(he, { path: `${t}${r.path}`, factory: e, readonly: !1, input: r }) });
251
- }
252
- function ge(r) {
253
- const { items: e, factory: t } = r;
254
- return /* @__PURE__ */ y.jsx(y.Fragment, { children: e.map((n) => {
255
- const a = `${n.inputType}_${n.path}_${n.label}`;
256
- return /* @__PURE__ */ y.jsx(pe, { input: n, factory: t }, a);
257
- }) });
258
- }
259
- const be = ne((r, e) => {
260
- const { inputs: t, className: n, factory: a } = r;
261
- return /* @__PURE__ */ y.jsxs("div", { className: n, ref: e, children: [
262
- t.hero,
263
- /* @__PURE__ */ y.jsx(ge, { items: t.inputs, factory: a })
264
- ] });
265
- });
266
- be.displayName = "RenderForm";
267
- function Ne(r) {
268
- let e = !0;
269
- return G(r, (t) => {
270
- e = e && (t === "" || K(t) || j(t));
271
- }), e;
272
- }
273
- const Fe = (r = "") => Q(r.split("_").join(" "));
274
- function O(r) {
261
+ const ge = "Required field";
262
+ function E(r) {
275
263
  const e = typeof r == "string" ? JSON.parse(r) : r;
276
264
  if (typeof e == "string")
277
265
  return e;
278
- if (V(e))
279
- return O(e[0]);
266
+ if (q(e))
267
+ return E(e[0]);
280
268
  const t = e;
281
- return B(t) && (t != null && t.message) ? e == null ? void 0 : e.message : "Unknown error";
269
+ return L(t) && (t != null && t.message) ? e == null ? void 0 : e.message : "Unknown error";
282
270
  }
283
- function _e(r, e, t) {
271
+ function be(r, e, t) {
284
272
  let n = {};
285
- if (T(n, r.inputs, e, t), t != null && t.prefix) {
273
+ if (w(n, r.inputs, e, t), t != null && t.prefix) {
286
274
  const s = t == null ? void 0 : t.prefix.replace(/.$/, "");
287
275
  n = g({}, s, n);
288
276
  }
289
- return m.object(R(n, e, t));
277
+ return m.object(V(n, e, t));
290
278
  }
291
- function R(r, e, t) {
279
+ function V(r, e, t) {
292
280
  const n = {};
293
281
  return Object.keys(r).forEach((a) => {
294
282
  const {
@@ -296,112 +284,119 @@ function R(r, e, t) {
296
284
  _schemaObj: o,
297
285
  _input: i,
298
286
  _isList: c,
299
- _isArrayItem: u,
300
- _schema: f
287
+ _isArrayItem: f,
288
+ _schema: u
301
289
  /*...nestedSchemaObj*/
302
290
  } = r[a];
303
291
  if (c && o && i) {
304
- const l = m.array(m.object(R(o, e, t))).optional(), d = $(f, i, e, t, l);
305
- n[a] = d;
306
- } else if (u && i) {
307
- const l = o != null && o.___array ? R({ ___array: o.___array }, e, t) : { ___array: m.any() }, d = m.array(l.___array).optional(), h = $(f, i, e, t, d);
308
- n[a] = h;
309
- } else if (f && i) {
310
- const l = ve(f, i, e, t);
292
+ const d = m.array(m.object(V(o, e, t))).optional(), l = J(u, i, e, t, d);
311
293
  n[a] = l;
312
- } else s && i ? n[a] = P(i, t) : n[a] = m.object(R(r[a], e, t)).optional();
294
+ } else if (f && i) {
295
+ const d = o != null && o.___array ? V({ ___array: o.___array }, e, t) : { ___array: m.any() }, l = m.array(d.___array).optional(), h = J(u, i, e, t, l);
296
+ n[a] = h;
297
+ } else if (u && i) {
298
+ const d = _e(u, i, e, t);
299
+ n[a] = d;
300
+ } else s && i ? n[a] = A(i, t) : n[a] = m.object(V(r[a], e, t)).optional();
313
301
  }), n;
314
302
  }
315
- function ve(r, e, t, n) {
316
- return m.any().superRefine(async (a, s) => {
303
+ function _e(r, e, t, n) {
304
+ return m.any().optional().superRefine(async (a, s) => {
317
305
  var i, c;
318
- if (e.required && ((await P(e, n).safeParseAsync(a)).success || s.addIssue({
319
- code: m.ZodIssueCode.custom,
320
- message: "Required field"
321
- })), (i = n == null ? void 0 : n.validationConfig) != null && i.globalValidation) {
322
- const u = (c = n == null ? void 0 : n.validationConfig) == null ? void 0 : c.globalValidation(a, e, n.metadata);
323
- if (u.error && s.addIssue({
306
+ if (e.required && !(await A(e, n).safeParseAsync(a)).success)
307
+ return s.addIssue({
324
308
  code: m.ZodIssueCode.custom,
325
- message: u.error
326
- }), !u.continue)
309
+ message: F(e, n)
310
+ }), m.NEVER;
311
+ if ((i = n == null ? void 0 : n.validationConfig) != null && i.globalValidation) {
312
+ const f = (c = n == null ? void 0 : n.validationConfig) == null ? void 0 : c.globalValidation(a, e, n.metadata);
313
+ if (f.error)
314
+ return s.addIssue({
315
+ code: m.ZodIssueCode.custom,
316
+ message: f.error
317
+ }), m.NEVER;
318
+ if (!f.continue)
327
319
  return !0;
328
320
  }
329
- const o = L(r, t);
321
+ const o = W(r, t);
330
322
  if (o) {
331
- const u = await o.safeParseAsync(a);
332
- u.success || s.addIssue({
333
- code: m.ZodIssueCode.custom,
334
- message: O(u == null ? void 0 : u.error.message)
335
- });
323
+ const f = await o.safeParseAsync(a);
324
+ if (!f.success) {
325
+ const u = E(f == null ? void 0 : f.error.message), d = u === "Required" ? F(e, n) : u;
326
+ s.addIssue({
327
+ code: m.ZodIssueCode.custom,
328
+ message: d
329
+ });
330
+ }
336
331
  }
337
332
  });
338
333
  }
339
- function $(r, e, t, n, a) {
340
- return m.any().superRefine(async (s, o) => {
341
- var f, l;
342
- const c = await P(e, n).safeParseAsync(s);
334
+ function J(r, e, t, n, a) {
335
+ return m.any().optional().superRefine(async (s, o) => {
336
+ var u, d;
337
+ const c = await A(e, n).safeParseAsync(s);
343
338
  if (e.required && !c.success) {
344
- const d = O(c.error.message);
345
- return o.addIssue({ code: m.ZodIssueCode.custom, message: d, fatal: !0 }), m.NEVER;
339
+ const l = E(c.error.message);
340
+ return o.addIssue({ code: m.ZodIssueCode.custom, message: l, fatal: !0 }), m.NEVER;
346
341
  }
347
342
  if (!e.required && !c.success)
348
343
  return m.NEVER;
349
- if ((f = n == null ? void 0 : n.validationConfig) != null && f.globalValidation) {
350
- const d = (l = n == null ? void 0 : n.validationConfig) == null ? void 0 : l.globalValidation(s, e, n.metadata);
351
- if (d.error)
344
+ if ((u = n == null ? void 0 : n.validationConfig) != null && u.globalValidation) {
345
+ const l = (d = n == null ? void 0 : n.validationConfig) == null ? void 0 : d.globalValidation(s, e, n.metadata);
346
+ if (l.error)
352
347
  return o.addIssue({
353
348
  code: m.ZodIssueCode.custom,
354
- message: O(d.error)
349
+ message: E(l.error)
355
350
  }), m.NEVER;
356
- if (!d.continue)
351
+ if (!l.continue)
357
352
  return m.NEVER;
358
353
  }
359
- if (!V(s))
354
+ if (!q(s))
360
355
  return o.addIssue({
361
356
  code: m.ZodIssueCode.custom,
362
357
  message: "'Value is not array'"
363
358
  }), m.NEVER;
364
- const u = L(r, t);
365
- if (u) {
366
- const d = await u.safeParseAsync(s);
367
- if (!d.success)
359
+ const f = W(r, t);
360
+ if (f) {
361
+ const l = await f.safeParseAsync(s);
362
+ if (!l.success)
368
363
  return o.addIssue({
369
364
  code: m.ZodIssueCode.custom,
370
- message: O(d.error.message)
365
+ message: E(l.error.message)
371
366
  }), m.NEVER;
372
367
  }
373
368
  }).pipe(a ?? m.any());
374
369
  }
375
- function T(r, e, t, n, a) {
370
+ function w(r, e, t, n, a) {
376
371
  e.forEach((s) => {
377
- var i, c, u, f, l;
372
+ var i, c, f, u, d;
378
373
  const o = t;
379
374
  if (!s.isVisible || (i = s.isVisible) != null && i.call(s, o, n == null ? void 0 : n.metadata)) {
380
- const d = b(r, s.path);
375
+ const l = b(r, s.path);
381
376
  if ((c = s.validation) != null && c.schema ? g(
382
377
  r,
383
378
  s.path,
384
- I(d, {
385
- _schema: (u = s.validation) == null ? void 0 : u.schema,
379
+ T(l, {
380
+ _schema: (f = s.validation) == null ? void 0 : f.schema,
386
381
  _input: s
387
382
  })
388
- ) : s.required && g(r, s.path, I(d, { _requiredOnly: !0, _input: s })), s.inputs && T(r, s.inputs, t, n), s.inputType === "list") {
383
+ ) : s.required && g(r, s.path, T(l, { _requiredOnly: !0, _input: s })), s.inputs && w(r, s.inputs, t, n), s.inputType === "list") {
389
384
  const h = {};
390
- T(
385
+ w(
391
386
  h,
392
- s.inputConfig.inputs.map((_) => ({
393
- ..._,
394
- path: _.relativePath
387
+ s.inputConfig.inputs.map((p) => ({
388
+ ...p,
389
+ path: p.relativePath
395
390
  })),
396
391
  t,
397
392
  n
398
393
  );
399
- const p = b(r, s.path);
400
- g(r, s.path, I(p, { _schemaObj: h, _isList: !0, _input: s }));
394
+ const S = b(r, s.path);
395
+ g(r, s.path, T(S, { _schemaObj: h, _isList: !0, _input: s }));
401
396
  }
402
- if (!((f = s.validation) != null && f.schema) && s.inputType === "array") {
397
+ if (!((u = s.validation) != null && u.schema) && s.inputType === "array") {
403
398
  const h = {};
404
- T(
399
+ w(
405
400
  h,
406
401
  [{ ...s.inputConfig.input, path: "___array" }],
407
402
  t,
@@ -409,9 +404,9 @@ function T(r, e, t, n, a) {
409
404
  ), g(
410
405
  r,
411
406
  s.path,
412
- I(d, {
407
+ T(l, {
413
408
  _schemaObj: h,
414
- _schema: (l = s.validation) == null ? void 0 : l.schema,
409
+ _schema: (d = s.validation) == null ? void 0 : d.schema,
415
410
  _isArrayItem: !0,
416
411
  _input: s
417
412
  })
@@ -420,30 +415,34 @@ function T(r, e, t, n, a) {
420
415
  }
421
416
  });
422
417
  }
423
- function P(r, e) {
424
- var n, a, s, o, i, c, u, f, l;
418
+ function F(r, e) {
419
+ var t, n, a;
420
+ return ((n = (t = e == null ? void 0 : e.validationConfig) == null ? void 0 : t.requiredMessagePerInput) == null ? void 0 : n[r.inputType]) ?? ((a = e == null ? void 0 : e.validationConfig) == null ? void 0 : a.requiredMessage) ?? ge;
421
+ }
422
+ function A(r, e) {
423
+ var n, a, s, o, i, c;
425
424
  if ((a = (n = e == null ? void 0 : e.validationConfig) == null ? void 0 : n.requiredSchemaPerInput) != null && a[r.inputType])
426
425
  return (o = (s = e == null ? void 0 : e.validationConfig) == null ? void 0 : s.requiredSchemaPerInput) == null ? void 0 : o[r.inputType];
427
426
  if ((i = e == null ? void 0 : e.validationConfig) != null && i.requiredSchema)
428
427
  return (c = e == null ? void 0 : e.validationConfig) == null ? void 0 : c.requiredSchema;
429
- const t = ((f = (u = e == null ? void 0 : e.validationConfig) == null ? void 0 : u.requiredMessagePerInput) == null ? void 0 : f[r.inputType]) ?? ((l = e == null ? void 0 : e.validationConfig) == null ? void 0 : l.requiredMessage) ?? "Required fields";
430
- return m.any().superRefine((d, h) => {
431
- typeof d == "object" && S(d) && h.addIssue({
428
+ const t = F(r, e);
429
+ return m.any().optional().superRefine((f, u) => {
430
+ typeof f == "object" && R(f) && u.addIssue({
432
431
  code: m.ZodIssueCode.custom,
433
432
  message: t
434
- }), (j(d) || d === "") && h.addIssue({
433
+ }), (I(f) || f === "") && u.addIssue({
435
434
  code: m.ZodIssueCode.custom,
436
435
  message: t
437
436
  });
438
437
  });
439
438
  }
440
- function L(r, e) {
439
+ function W(r, e) {
441
440
  if (r instanceof m.ZodType)
442
441
  return r;
443
442
  if (typeof r == "function")
444
443
  return r(e);
445
444
  }
446
- const Oe = (r) => Array.isArray(r == null ? void 0 : r.errors), Se = (r, e) => {
445
+ const Se = (r) => Array.isArray(r == null ? void 0 : r.errors), ve = (r, e) => {
447
446
  const t = {};
448
447
  for (; r.length; ) {
449
448
  const n = r[0], { code: a, message: s, path: o } = n, i = o.join(".");
@@ -456,35 +455,35 @@ const Oe = (r) => Array.isArray(r == null ? void 0 : r.errors), Se = (r, e) => {
456
455
  };
457
456
  } else
458
457
  t[i] = { message: s, type: a };
459
- "unionErrors" in n && n.unionErrors.forEach((c) => c.errors.forEach((u) => r.push(u)));
458
+ "unionErrors" in n && n.unionErrors.forEach((c) => c.errors.forEach((f) => r.push(f)));
460
459
  {
461
- const c = t[i].types, u = c && c[n.code];
462
- t[i] = oe(
460
+ const c = t[i].types, f = c && c[n.code];
461
+ t[i] = ce(
463
462
  i,
464
463
  e,
465
464
  t,
466
465
  a,
467
- u ? [].concat(u, n.message) : n.message
466
+ f ? [].concat(f, n.message) : n.message
468
467
  );
469
468
  }
470
469
  r.shift();
471
470
  }
472
471
  return t;
473
472
  };
474
- function ke(r, e) {
473
+ function Fe(r, e) {
475
474
  return se(
476
475
  async (t, n, a) => {
477
476
  try {
478
- return await _e(r, t, e).parseAsync(t), {
477
+ return await be(r, t, e).parseAsync(t), {
479
478
  values: t,
480
479
  // TODO: check this - values does not contains all data
481
480
  errors: {}
482
481
  };
483
482
  } catch (s) {
484
- if (Oe(s))
483
+ if (Se(s))
485
484
  return {
486
485
  values: {},
487
- errors: ce(Se(s.errors, !0), a)
486
+ errors: fe(ve(s.errors, !0), a)
488
487
  };
489
488
  throw s;
490
489
  }
@@ -493,7 +492,7 @@ function ke(r, e) {
493
492
  );
494
493
  }
495
494
  function Ae(r, e) {
496
- const t = w(r);
495
+ const t = C(r);
497
496
  return e.forEach((n) => {
498
497
  if (n.inputTransform) {
499
498
  const a = b(t, n.path), s = n.inputTransform(a, t);
@@ -501,8 +500,8 @@ function Ae(r, e) {
501
500
  }
502
501
  }), t;
503
502
  }
504
- function Ze(r, e) {
505
- const t = w(r);
503
+ function De(r, e) {
504
+ const t = C(r);
506
505
  return e.forEach((n) => {
507
506
  if (n.outputTransform) {
508
507
  const a = b(t, n.path), s = n.outputTransform(a, t);
@@ -510,14 +509,14 @@ function Ze(r, e) {
510
509
  }
511
510
  }), t;
512
511
  }
513
- function N(r) {
514
- return r.reduce((t, n) => n.inputType === "group" && n.inputs ? [...t, n, ...N(n.inputs)] : [...t, n], []);
512
+ function D(r) {
513
+ return r.reduce((t, n) => n.inputType === "group" && n.inputs ? [...t, n, ...D(n.inputs)] : [...t, n], []);
515
514
  }
516
- function De(r) {
517
- const t = N(r.inputs).reduce((n, a) => {
515
+ function Ze(r) {
516
+ const t = D(r.inputs).reduce((n, a) => {
518
517
  const s = a.inputType === "text" || a.inputType === "boolean" || a.inputType === "number" || a.inputType === "textarea" || a.inputType === "select";
519
518
  return (a.inputTransform || a.outputTransform) && n.push({
520
- ...X(a, "path", "inputTransform", "outputTransform"),
519
+ ...K(a, "path", "inputTransform", "outputTransform"),
521
520
  level: a.path.split(".").length,
522
521
  isPrimitive: s
523
522
  }), n;
@@ -525,12 +524,12 @@ function De(r) {
525
524
  return t.sort((n, a) => n.level === a.level ? n.isPrimitive ? 1 : -1 : n.level > a.level ? -1 : 1), t;
526
525
  }
527
526
  function $e(r, e, t) {
528
- const n = N(r.inputs), a = w(e);
527
+ const n = D(r.inputs), a = C(e);
529
528
  return n.forEach((s) => {
530
- s.isVisible && !s.isVisible(e, t) && z(a, s.path);
529
+ s.isVisible && !s.isVisible(e, t) && X(a, s.path);
531
530
  }), a;
532
531
  }
533
- function Be() {
532
+ function Me() {
534
533
  return function(r, e) {
535
534
  if (!(typeof r > "u"))
536
535
  return r ? {
@@ -538,7 +537,7 @@ function Be() {
538
537
  } : { value: r };
539
538
  };
540
539
  }
541
- function Je(r) {
540
+ function Be(r) {
542
541
  return function(e, t) {
543
542
  if (typeof e > "u") return;
544
543
  if (!e) return { value: e };
@@ -548,18 +547,18 @@ function Je(r) {
548
547
  return r != null && r.unsetIfEmpty && Object.getOwnPropertyNames(n.value).length === 0 ? { value: void 0 } : n;
549
548
  };
550
549
  }
551
- function Le() {
550
+ function Je() {
552
551
  return function(r, e) {
553
552
  if (!(typeof r > "u"))
554
- return V(r) && S(r) ? { value: void 0 } : { value: r };
553
+ return q(r) && R(r) ? { value: void 0 } : { value: r };
555
554
  };
556
555
  }
557
- function Me() {
556
+ function Le() {
558
557
  return function(r, e) {
559
558
  if (!(typeof r > "u")) {
560
- if (B(r)) {
561
- const t = J(r, j);
562
- if (S(t))
559
+ if (L(r)) {
560
+ const t = U(r, I);
561
+ if (R(t))
563
562
  return { value: void 0 };
564
563
  }
565
564
  return { value: r };
@@ -569,7 +568,7 @@ function Me() {
569
568
  function Ue() {
570
569
  return function(r, e) {
571
570
  if (!(typeof r > "u"))
572
- return ee(r) && S(r) ? { value: void 0 } : { value: r };
571
+ return z(r) && R(r) ? { value: void 0 } : { value: r };
573
572
  };
574
573
  }
575
574
  function We(r) {
@@ -578,32 +577,32 @@ function We(r) {
578
577
  return typeof n == "string" ? { value: n } : { value: e };
579
578
  };
580
579
  }
581
- function He(r) {
580
+ function Ge(r) {
582
581
  return function(e, t) {
583
582
  if (typeof e > "u") return;
584
583
  if (!e) return { value: e };
585
584
  const n = b(t, r);
586
585
  if (typeof n == "object") {
587
- const a = je(n);
586
+ const a = Oe(n);
588
587
  if (Object.getOwnPropertyNames(a).length === 1)
589
588
  return { value: e, path: r };
590
589
  }
591
590
  return { value: e };
592
591
  };
593
592
  }
594
- function Ye(r) {
593
+ function He(r) {
595
594
  return function(e, t) {
596
595
  if (typeof e > "u") return;
597
596
  const n = b(t, r);
598
597
  return typeof n == "string" ? { value: [n] } : { value: e };
599
598
  };
600
599
  }
601
- function Ge(r, e) {
600
+ function Qe(r, e) {
602
601
  return function(t, n) {
603
602
  if (typeof t > "u") return;
604
603
  if (!t) return { value: t };
605
604
  const a = b(n, r);
606
- if (V(a)) {
605
+ if (q(a)) {
607
606
  if (a.length === 1)
608
607
  return { value: a[0], path: r };
609
608
  if (a.length === 0 && e != null && e.unsetIfEmpty)
@@ -612,40 +611,66 @@ function Ge(r, e) {
612
611
  return { value: t };
613
612
  };
614
613
  }
615
- function M(r) {
616
- return typeof r == "object" ? !Object.getOwnPropertyNames(r).some((e) => !M(r[e])) : j(r);
614
+ function G(r) {
615
+ return typeof r == "object" ? !Object.getOwnPropertyNames(r).some((e) => !G(r[e])) : I(r);
617
616
  }
618
- function je(r) {
619
- return J(r, (e) => typeof e == "object" ? M(e) : j(e));
617
+ function Oe(r) {
618
+ return U(r, (e) => typeof e == "object" ? G(e) : I(e));
619
+ }
620
+ function Ee({ input: r, factory: e }) {
621
+ const { prefix: t = "" } = {};
622
+ return /* @__PURE__ */ y.jsx("div", { children: /* @__PURE__ */ y.jsx(ye, { path: `${t}${r.path}`, factory: e, readonly: !1, input: r }) });
623
+ }
624
+ function Re(r) {
625
+ const { items: e, factory: t } = r;
626
+ return /* @__PURE__ */ y.jsx(y.Fragment, { children: e.map((n) => {
627
+ const a = `${n.inputType}_${n.path}_${n.label}`;
628
+ return /* @__PURE__ */ y.jsx(Ee, { input: n, factory: t }, a);
629
+ }) });
630
+ }
631
+ const Ie = ae((r, e) => {
632
+ const { inputs: t, className: n, factory: a } = r;
633
+ return /* @__PURE__ */ y.jsxs("div", { className: n, ref: e, children: [
634
+ t.hero,
635
+ /* @__PURE__ */ y.jsx(Re, { items: t.inputs, factory: a })
636
+ ] });
637
+ });
638
+ Ie.displayName = "RenderForm";
639
+ function Ye(r) {
640
+ let e = !0;
641
+ return ee(r, (t) => {
642
+ e = e && (t === "" || re(t) || I(t));
643
+ }), e;
620
644
  }
645
+ const Ke = (r = "") => te(r.split("_").join(" "));
621
646
  export {
622
- Ce as InputComponent,
623
- he as InputComponentRenderer,
624
- Ve as InputFactory,
625
- fe as InputOverrideError,
626
- be as RenderForm,
627
- ge as RenderInputs,
628
- qe as RootForm,
629
- pe as Row,
630
- Je as arrayToObjectOutputTransformer,
631
- Fe as generateReadableLabel,
632
- xe as getDefaultValuesFromFormDefinition,
633
- De as getTransformers,
634
- _e as getValidationSchema,
647
+ xe as InputComponent,
648
+ ye as InputComponentRenderer,
649
+ qe as InputFactory,
650
+ de as InputOverrideError,
651
+ Ie as RenderForm,
652
+ Re as RenderInputs,
653
+ Pe as RootForm,
654
+ Ee as Row,
655
+ Be as arrayToObjectOutputTransformer,
656
+ Ke as generateReadableLabel,
657
+ Ne as getDefaultValuesFromFormDefinition,
658
+ Ze as getTransformers,
659
+ be as getValidationSchema,
635
660
  Ae as inputTransformValues,
636
- Ne as isChildrenEmpty,
637
- Be as objectToArrayInputTransformer,
638
- Ze as outputTransformValues,
639
- Pe as overrideFormDefinition,
640
- O as processValidationParseResponse,
641
- Ye as shorthandArrayInputTransformer,
642
- Ge as shorthandArrayOutputTransformer,
661
+ Ye as isChildrenEmpty,
662
+ Me as objectToArrayInputTransformer,
663
+ De as outputTransformValues,
664
+ ke as overrideFormDefinition,
665
+ E as processValidationParseResponse,
666
+ He as shorthandArrayInputTransformer,
667
+ Qe as shorthandArrayOutputTransformer,
643
668
  We as shorthandObjectInputTransformer,
644
- He as shorthandObjectOutputTransformer,
645
- Le as unsetEmptyArrayOutputTransformer,
646
- Me as unsetEmptyObjectOutputTransformer,
669
+ Ge as shorthandObjectOutputTransformer,
670
+ Je as unsetEmptyArrayOutputTransformer,
671
+ Le as unsetEmptyObjectOutputTransformer,
647
672
  Ue as unsetEmptyStringOutputTransformer,
648
673
  $e as unsetHiddenInputsValues,
649
- ke as useZodValidationResolver
674
+ Fe as useZodValidationResolver
650
675
  };
651
676
  //# sourceMappingURL=index.js.map