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