@harnessio/forms 0.1.4 → 0.1.6-beta.1

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