@harnessio/forms 0.0.14 → 0.1.0

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