@harnessio/forms 0.4.1 → 0.4.2
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.cjs +2 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +77 -77
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
var pe = Object.defineProperty;
|
|
2
2
|
var ye = (r, e, n) => e in r ? pe(r, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : r[e] = n;
|
|
3
3
|
var N = (r, e, n) => ye(r, typeof e != "symbol" ? e + "" : e, n);
|
|
4
|
-
import { isEmpty as I, cloneDeep as q, set as
|
|
4
|
+
import { isEmpty as I, cloneDeep as q, set as g, get as _, forOwn as te, isArray as S, isObject as ne, merge as w, isUndefined as F, unset as se, pick as ge, isNull as ae, omitBy as oe, isNil as be, isString as ve, capitalize as _e } from "lodash-es";
|
|
5
5
|
import Ee, { createContext as Re, useContext as Te, useMemo as D, useRef as M, useEffect as j, useCallback as Oe, forwardRef as Se, Fragment as je } from "react";
|
|
6
6
|
import { useFormContext as Ce, get as Ie, useForm as Ve, FormProvider as we, appendErrors as xe, useController as Pe } from "react-hook-form";
|
|
7
7
|
export * from "react-hook-form";
|
|
@@ -126,11 +126,11 @@ function ke() {
|
|
|
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
128
|
function i(o, u, c) {
|
|
129
|
-
var l, m = {}, f = null,
|
|
130
|
-
c !== void 0 && (f = "" + c), u.key !== void 0 && (f = "" + u.key), u.ref !== void 0 && (
|
|
129
|
+
var l, m = {}, f = null, p = null;
|
|
130
|
+
c !== void 0 && (f = "" + c), u.key !== void 0 && (f = "" + u.key), u.ref !== void 0 && (p = u.ref);
|
|
131
131
|
for (l in u) a.call(u, l) && !s.hasOwnProperty(l) && (m[l] = u[l]);
|
|
132
132
|
if (o && o.defaultProps) for (l in u = o.defaultProps, u) m[l] === void 0 && (m[l] = u[l]);
|
|
133
|
-
return { $$typeof: e, type: o, key: f, ref:
|
|
133
|
+
return { $$typeof: e, type: o, key: f, ref: p, props: m, _owner: t.current };
|
|
134
134
|
}
|
|
135
135
|
return O.jsx = i, O.jsxs = i, O;
|
|
136
136
|
}
|
|
@@ -138,14 +138,14 @@ var K;
|
|
|
138
138
|
function Ne() {
|
|
139
139
|
return K || (K = 1, Z.exports = ke()), Z.exports;
|
|
140
140
|
}
|
|
141
|
-
var
|
|
141
|
+
var h = Ne();
|
|
142
142
|
const ie = Re({});
|
|
143
143
|
function De({
|
|
144
144
|
children: r,
|
|
145
145
|
metadata: e,
|
|
146
146
|
readonly: n
|
|
147
147
|
}) {
|
|
148
|
-
return /* @__PURE__ */
|
|
148
|
+
return /* @__PURE__ */ h.jsx(
|
|
149
149
|
ie.Provider,
|
|
150
150
|
{
|
|
151
151
|
value: {
|
|
@@ -163,7 +163,7 @@ function Me() {
|
|
|
163
163
|
const z = ({
|
|
164
164
|
children: r,
|
|
165
165
|
withoutWrapper: e = !1
|
|
166
|
-
}) => e || !r ? r : /* @__PURE__ */
|
|
166
|
+
}) => e || !r ? r : /* @__PURE__ */ h.jsx("div", { children: r });
|
|
167
167
|
function Ze({
|
|
168
168
|
path: r,
|
|
169
169
|
factory: e,
|
|
@@ -177,20 +177,20 @@ function Ze({
|
|
|
177
177
|
const { formState: o, watch: u } = Ce(), {
|
|
178
178
|
fixedValues: c = {}
|
|
179
179
|
/*getValuesWithDependencies*/
|
|
180
|
-
} = {}, { metadata: l, readonly: m } = Me(), f = e == null ? void 0 : e.getComponent(s.inputType),
|
|
180
|
+
} = {}, { metadata: l, readonly: m } = Me(), f = e == null ? void 0 : e.getComponent(s.inputType), p = u(), b = q(p);
|
|
181
181
|
c && Object.keys(c).forEach((V) => {
|
|
182
182
|
const A = c[V];
|
|
183
|
-
|
|
183
|
+
g(b, V, A);
|
|
184
184
|
});
|
|
185
|
-
const
|
|
186
|
-
let R,
|
|
187
|
-
|
|
188
|
-
const
|
|
185
|
+
const y = !s.isVisible || s.isVisible(b, l);
|
|
186
|
+
let R, E;
|
|
187
|
+
y && (R = m || s.readonly, E = typeof s.disabled == "function" ? s.disabled(b, l) : s.disabled);
|
|
188
|
+
const T = (W = s.warning) == null ? void 0 : W.schema, v = D(() => {
|
|
189
189
|
var H, Q;
|
|
190
|
-
if (!
|
|
191
|
-
const V = Ie(
|
|
190
|
+
if (!y || typeof T > "u") return;
|
|
191
|
+
const V = Ie(p, s.path), A = typeof T == "function" ? T(b) : T, { success: he, error: k } = A.safeParse(V), G = (Q = (H = k == null ? void 0 : k.errors) == null ? void 0 : H[0]) == null ? void 0 : Q.message;
|
|
192
192
|
return !he && G ? G : void 0;
|
|
193
|
-
}, [s.path,
|
|
193
|
+
}, [s.path, p, T, y]), L = D(
|
|
194
194
|
() => ({
|
|
195
195
|
path: r,
|
|
196
196
|
key: r,
|
|
@@ -200,16 +200,16 @@ function Ze({
|
|
|
200
200
|
factory: e,
|
|
201
201
|
readonly: R,
|
|
202
202
|
input: s,
|
|
203
|
-
disabled:
|
|
204
|
-
warning:
|
|
203
|
+
disabled: E,
|
|
204
|
+
warning: v
|
|
205
205
|
}),
|
|
206
|
-
[e, a, s, t, n, r, R, o.errors,
|
|
207
|
-
), me = D(() =>
|
|
206
|
+
[e, a, s, t, n, r, R, o.errors, E, v]
|
|
207
|
+
), me = D(() => y ? /* @__PURE__ */ h.jsxs(h.Fragment, { children: [
|
|
208
208
|
s.before ? s.before : null,
|
|
209
209
|
f == null ? void 0 : f.renderComponent(L),
|
|
210
210
|
s.after ? s.after : null
|
|
211
|
-
] }) : null, [L, s.after, s.before, f,
|
|
212
|
-
return f ? /* @__PURE__ */
|
|
211
|
+
] }) : null, [L, s.after, s.before, f, y, o.errors]);
|
|
212
|
+
return f ? /* @__PURE__ */ h.jsx(z, { withoutWrapper: i, children: me }) : /* @__PURE__ */ h.jsx(z, { withoutWrapper: i, children: /* @__PURE__ */ h.jsxs("p", { children: [
|
|
213
213
|
"Input component not found (internal type: ",
|
|
214
214
|
s.inputType,
|
|
215
215
|
")"
|
|
@@ -244,11 +244,11 @@ function or(r) {
|
|
|
244
244
|
defaultValues: t,
|
|
245
245
|
shouldFocusError: a,
|
|
246
246
|
resolver: n
|
|
247
|
-
}),
|
|
247
|
+
}), p = M(!1);
|
|
248
248
|
j(() => {
|
|
249
249
|
f.reset(t, {});
|
|
250
250
|
}, [f.reset, t]), j(() => {
|
|
251
|
-
const
|
|
251
|
+
const v = requestIdleCallback(() => {
|
|
252
252
|
f.reset({}, {
|
|
253
253
|
keepErrors: !0,
|
|
254
254
|
keepDirty: !0,
|
|
@@ -262,41 +262,41 @@ function or(r) {
|
|
|
262
262
|
keepSubmitCount: !0
|
|
263
263
|
});
|
|
264
264
|
});
|
|
265
|
-
return () => cancelIdleCallback(
|
|
265
|
+
return () => cancelIdleCallback(v);
|
|
266
266
|
}, []);
|
|
267
|
-
const { getValues:
|
|
267
|
+
const { getValues: b, handleSubmit: y } = f, R = b(), E = M(!0);
|
|
268
268
|
j(() => {
|
|
269
|
-
if (
|
|
270
|
-
|
|
269
|
+
if (E.current) {
|
|
270
|
+
E.current = !1;
|
|
271
271
|
return;
|
|
272
272
|
}
|
|
273
|
-
s == null || s({ ...R }),
|
|
273
|
+
s == null || s({ ...R }), p.current === !0 && f.trigger();
|
|
274
274
|
}, [JSON.stringify(R)]);
|
|
275
|
-
const
|
|
275
|
+
const T = M(!0);
|
|
276
276
|
return j(() => {
|
|
277
|
-
if (
|
|
278
|
-
|
|
277
|
+
if (T.current) {
|
|
278
|
+
T.current = !1;
|
|
279
279
|
return;
|
|
280
280
|
}
|
|
281
281
|
i == null || i({ isValid: f.formState.isValid, isSubmitted: f.formState.isSubmitted });
|
|
282
282
|
}, [f.formState.isValid, f.formState.isSubmitted]), j(() => {
|
|
283
283
|
if (l)
|
|
284
284
|
if ("requestIdleCallback" in window) {
|
|
285
|
-
const
|
|
285
|
+
const v = requestIdleCallback(() => {
|
|
286
286
|
f.setFocus(l);
|
|
287
287
|
});
|
|
288
|
-
return () => cancelIdleCallback(
|
|
288
|
+
return () => cancelIdleCallback(v);
|
|
289
289
|
} else {
|
|
290
|
-
const
|
|
290
|
+
const v = setTimeout(() => {
|
|
291
291
|
f.setFocus(l);
|
|
292
292
|
}, 100);
|
|
293
|
-
return () => clearTimeout(
|
|
293
|
+
return () => clearTimeout(v);
|
|
294
294
|
}
|
|
295
|
-
}, [f]), /* @__PURE__ */
|
|
295
|
+
}, [f]), /* @__PURE__ */ h.jsx(De, { metadata: u, readonly: m, children: /* @__PURE__ */ h.jsx(we, { ...f, children: typeof c == "function" ? c({
|
|
296
296
|
...f,
|
|
297
297
|
submitForm: async () => {
|
|
298
|
-
o && (
|
|
299
|
-
o(
|
|
298
|
+
o && (p.current = !0, y((v) => {
|
|
299
|
+
o(v);
|
|
300
300
|
})());
|
|
301
301
|
}
|
|
302
302
|
}) : c }) });
|
|
@@ -305,7 +305,7 @@ const ur = (r) => {
|
|
|
305
305
|
const e = {}, n = (t) => {
|
|
306
306
|
t.forEach((a) => {
|
|
307
307
|
const { path: s, default: i, inputType: o, inputs: u } = a;
|
|
308
|
-
(o === "group" || o === "accordion") && Array.isArray(u) ? n(u) :
|
|
308
|
+
(o === "group" || o === "accordion") && Array.isArray(u) ? n(u) : _(e, s) === void 0 && g(e, s, i);
|
|
309
309
|
});
|
|
310
310
|
};
|
|
311
311
|
return Array.isArray(r.inputs) && n(r.inputs), e;
|
|
@@ -341,7 +341,7 @@ function Ue(r, e, n) {
|
|
|
341
341
|
let t = {};
|
|
342
342
|
if (P(t, r.inputs, e, n), n != null && n.prefix) {
|
|
343
343
|
const s = n == null ? void 0 : n.prefix.replace(/.$/, "");
|
|
344
|
-
t =
|
|
344
|
+
t = g({}, s, t);
|
|
345
345
|
}
|
|
346
346
|
return d.object(x(t, e, n));
|
|
347
347
|
}
|
|
@@ -361,8 +361,8 @@ function x(r, e, n) {
|
|
|
361
361
|
const m = d.array(d.object(x(i, e, n))).optional(), f = ee(l, o, e, n, m);
|
|
362
362
|
t[a] = f;
|
|
363
363
|
} else if (c && o) {
|
|
364
|
-
const m = i != null && i.___array ? x({ ___array: i.___array }, e, n) : { ___array: d.any() }, f = d.array(m.___array).optional(),
|
|
365
|
-
t[a] =
|
|
364
|
+
const m = i != null && i.___array ? x({ ___array: i.___array }, e, n) : { ___array: d.any() }, f = d.array(m.___array).optional(), p = ee(l, o, e, n, f);
|
|
365
|
+
t[a] = p;
|
|
366
366
|
} else if (l && o) {
|
|
367
367
|
const m = Le(l, o, e, n);
|
|
368
368
|
t[a] = m;
|
|
@@ -438,44 +438,44 @@ function ee(r, e, n, t, a) {
|
|
|
438
438
|
}
|
|
439
439
|
function P(r, e, n, t, a) {
|
|
440
440
|
e.forEach((s) => {
|
|
441
|
-
var o, u, c, l, m;
|
|
441
|
+
var o, u, c, l, m, f, p;
|
|
442
442
|
const i = n;
|
|
443
443
|
if (!s.isVisible || (o = s.isVisible) != null && o.call(s, i, t == null ? void 0 : t.metadata)) {
|
|
444
|
-
const
|
|
445
|
-
if ((u = s.validation) != null && u.schema ?
|
|
444
|
+
const b = _(r, s.path);
|
|
445
|
+
if ((u = s.validation) != null && u.schema ? g(
|
|
446
446
|
r,
|
|
447
447
|
s.path,
|
|
448
|
-
w(
|
|
448
|
+
w(b, {
|
|
449
449
|
_schema: (c = s.validation) == null ? void 0 : c.schema,
|
|
450
450
|
_input: s
|
|
451
451
|
})
|
|
452
|
-
) : s.required &&
|
|
453
|
-
const
|
|
452
|
+
) : s.required && g(r, s.path, w(b, { _requiredOnly: !0, _input: s })), s.inputs && P(r, s.inputs, n, t), s.inputType === "list") {
|
|
453
|
+
const y = {};
|
|
454
454
|
P(
|
|
455
|
-
|
|
456
|
-
s.inputConfig.inputs.map((
|
|
457
|
-
...
|
|
458
|
-
path:
|
|
455
|
+
y,
|
|
456
|
+
(m = (l = s.inputConfig) == null ? void 0 : l.inputs) == null ? void 0 : m.map((E) => ({
|
|
457
|
+
...E,
|
|
458
|
+
path: E.relativePath
|
|
459
459
|
})),
|
|
460
460
|
n,
|
|
461
461
|
t
|
|
462
462
|
);
|
|
463
|
-
const
|
|
464
|
-
|
|
463
|
+
const R = _(r, s.path);
|
|
464
|
+
g(r, s.path, w(R, { _schemaObj: y, _isList: !0, _input: s }));
|
|
465
465
|
}
|
|
466
|
-
if (!((
|
|
467
|
-
const
|
|
466
|
+
if (!((f = s.validation) != null && f.schema) && s.inputType === "array") {
|
|
467
|
+
const y = {};
|
|
468
468
|
P(
|
|
469
|
-
|
|
469
|
+
y,
|
|
470
470
|
[{ ...s.inputConfig.input, path: "___array" }],
|
|
471
471
|
n,
|
|
472
472
|
t
|
|
473
|
-
),
|
|
473
|
+
), g(
|
|
474
474
|
r,
|
|
475
475
|
s.path,
|
|
476
|
-
w(
|
|
477
|
-
_schemaObj:
|
|
478
|
-
_schema: (
|
|
476
|
+
w(b, {
|
|
477
|
+
_schemaObj: y,
|
|
478
|
+
_schema: (p = s.validation) == null ? void 0 : p.schema,
|
|
479
479
|
_isArrayItem: !0,
|
|
480
480
|
_input: s
|
|
481
481
|
})
|
|
@@ -564,8 +564,8 @@ function He(r, e) {
|
|
|
564
564
|
const n = q(r);
|
|
565
565
|
return e.forEach((t) => {
|
|
566
566
|
t.inputTransform && (S(t.inputTransform) ? t.inputTransform : [t.inputTransform]).forEach((s) => {
|
|
567
|
-
const i =
|
|
568
|
-
o &&
|
|
567
|
+
const i = _(n, t.path), o = s(i, n);
|
|
568
|
+
o && g(n, o.path ?? t.path, o.value);
|
|
569
569
|
});
|
|
570
570
|
}), n;
|
|
571
571
|
}
|
|
@@ -573,8 +573,8 @@ function Qe(r, e) {
|
|
|
573
573
|
const n = [], t = q(r);
|
|
574
574
|
return e.forEach((a) => {
|
|
575
575
|
a.outputTransform && (S(a.outputTransform) ? a.outputTransform : [a.outputTransform]).forEach((i) => {
|
|
576
|
-
const o =
|
|
577
|
-
u && (u.path ? (
|
|
576
|
+
const o = _(t, a.path), u = i(o, t);
|
|
577
|
+
u && (u.path ? (g(t, u.path, u.value), u.unset && n.push(a.path)) : g(t, a.path, u.value));
|
|
578
578
|
});
|
|
579
579
|
}), n.forEach((a) => {
|
|
580
580
|
se(t, a);
|
|
@@ -613,7 +613,7 @@ function mr(r) {
|
|
|
613
613
|
const e = {}, n = (t) => {
|
|
614
614
|
t.forEach((a) => {
|
|
615
615
|
const { default: s, path: i, inputType: o, inputs: u } = a;
|
|
616
|
-
(o === "group" || o === "accordion") && Array.isArray(u) ? n(u) : s !== void 0 &&
|
|
616
|
+
(o === "group" || o === "accordion") && Array.isArray(u) ? n(u) : s !== void 0 && g(e, i, s);
|
|
617
617
|
});
|
|
618
618
|
};
|
|
619
619
|
return Array.isArray(r.inputs) && n(r.inputs), e;
|
|
@@ -644,7 +644,7 @@ function yr() {
|
|
|
644
644
|
}
|
|
645
645
|
function gr(r) {
|
|
646
646
|
return function(e, n) {
|
|
647
|
-
const t = r ?
|
|
647
|
+
const t = r ? _(n, r) : e;
|
|
648
648
|
if (!(typeof t > "u")) {
|
|
649
649
|
if (ae(t)) return { value: void 0, path: r };
|
|
650
650
|
if (ne(t)) {
|
|
@@ -664,7 +664,7 @@ function br() {
|
|
|
664
664
|
}
|
|
665
665
|
function vr(r) {
|
|
666
666
|
return function(e, n) {
|
|
667
|
-
const t =
|
|
667
|
+
const t = _(n, r);
|
|
668
668
|
return typeof t == "string" ? { value: t } : { value: e };
|
|
669
669
|
};
|
|
670
670
|
}
|
|
@@ -672,7 +672,7 @@ function _r(r) {
|
|
|
672
672
|
return function(e, n) {
|
|
673
673
|
if (typeof e > "u") return;
|
|
674
674
|
if (!e) return { value: e };
|
|
675
|
-
const t =
|
|
675
|
+
const t = _(n, r);
|
|
676
676
|
if (typeof t == "object") {
|
|
677
677
|
const a = Ye(t);
|
|
678
678
|
if (Object.getOwnPropertyNames(a).length === 1)
|
|
@@ -684,7 +684,7 @@ function _r(r) {
|
|
|
684
684
|
function Er(r) {
|
|
685
685
|
return function(e, n) {
|
|
686
686
|
if (typeof e > "u") return;
|
|
687
|
-
const t =
|
|
687
|
+
const t = _(n, r);
|
|
688
688
|
return typeof t == "string" ? { value: [t] } : { value: e };
|
|
689
689
|
};
|
|
690
690
|
}
|
|
@@ -692,7 +692,7 @@ function Rr(r, e) {
|
|
|
692
692
|
return function(n, t) {
|
|
693
693
|
if (typeof n > "u") return;
|
|
694
694
|
if (!n) return { value: n };
|
|
695
|
-
const a =
|
|
695
|
+
const a = _(t, r);
|
|
696
696
|
if (S(a)) {
|
|
697
697
|
if (a.length === 1)
|
|
698
698
|
return { value: a[0], path: r };
|
|
@@ -710,7 +710,7 @@ function Ye(r) {
|
|
|
710
710
|
}
|
|
711
711
|
function re(r) {
|
|
712
712
|
const { items: e, ...n } = r;
|
|
713
|
-
return /* @__PURE__ */
|
|
713
|
+
return /* @__PURE__ */ h.jsx(h.Fragment, { children: e.map((t) => /* @__PURE__ */ h.jsx(
|
|
714
714
|
Ze,
|
|
715
715
|
{
|
|
716
716
|
input: t,
|
|
@@ -722,12 +722,12 @@ function re(r) {
|
|
|
722
722
|
}
|
|
723
723
|
const Ke = Se((r, e) => {
|
|
724
724
|
const { inputs: n, className: t, factory: a, withoutWrapper: s } = r;
|
|
725
|
-
return s ? /* @__PURE__ */
|
|
725
|
+
return s ? /* @__PURE__ */ h.jsxs(je, { children: [
|
|
726
726
|
n.hero,
|
|
727
|
-
/* @__PURE__ */
|
|
728
|
-
] }) : /* @__PURE__ */
|
|
727
|
+
/* @__PURE__ */ h.jsx(re, { items: n.inputs, factory: a, withoutWrapper: s })
|
|
728
|
+
] }) : /* @__PURE__ */ h.jsxs("div", { className: t, ref: e, children: [
|
|
729
729
|
n.hero,
|
|
730
|
-
/* @__PURE__ */
|
|
730
|
+
/* @__PURE__ */ h.jsx(re, { items: n.inputs, factory: a, withoutWrapper: s })
|
|
731
731
|
] });
|
|
732
732
|
});
|
|
733
733
|
Ke.displayName = "RenderForm";
|