@harnessio/forms 0.11.2 → 0.12.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/form/RenderInputs/RenderInputs.d.ts +4 -2
- package/dist/index.cjs +3 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +66 -74
- package/dist/index.js.map +1 -1
- package/dist/types/index.d.ts +2 -0
- package/dist/types/pipeline-input.d.ts +103 -0
- package/dist/types/runtime-input.d.ts +4 -0
- package/dist/types/types.d.ts +0 -4
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var D = (r, e, n) =>
|
|
4
|
-
import { isEmpty as k, set as S, get as T, forOwn as me, isArray as j, isObject as he, merge as M, isUndefined as B, cloneDeep as H, unset as
|
|
5
|
-
import Pe, { createContext as qe, useContext as Ae, Component as ke, memo as Ne, useMemo as $, useRef as
|
|
1
|
+
var we = Object.defineProperty;
|
|
2
|
+
var Ie = (r, e, n) => e in r ? we(r, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : r[e] = n;
|
|
3
|
+
var D = (r, e, n) => Ie(r, typeof e != "symbol" ? e + "" : e, n);
|
|
4
|
+
import { isEmpty as k, set as S, get as T, forOwn as me, isArray as j, isObject as he, merge as M, isUndefined as B, cloneDeep as H, unset as pe, pick as Oe, isPlainObject as je, isNull as ye, omitBy as ge, isNil as Ve, isString as xe, capitalize as Fe } from "lodash-es";
|
|
5
|
+
import Pe, { createContext as qe, useContext as Ae, Component as ke, memo as Ne, useMemo as $, useRef as O, useEffect as I, useCallback as De, forwardRef as Me, Fragment as $e } from "react";
|
|
6
6
|
import { useFormContext as Ze, get as Be, useForm as We, FormProvider as Je, appendErrors as Ue, useController as Le } from "react-hook-form";
|
|
7
7
|
import { Controller as Ur, Form as Lr, FormProvider as Hr, get as Gr, set as Kr, useFieldArray as Qr, useForm as Xr, useFormContext as Yr, useFormState as zr, useWatch as et } from "react-hook-form";
|
|
8
8
|
import * as d from "zod";
|
|
@@ -138,7 +138,7 @@ var ie;
|
|
|
138
138
|
function Xe() {
|
|
139
139
|
return ie || (ie = 1, W.exports = Qe()), W.exports;
|
|
140
140
|
}
|
|
141
|
-
var
|
|
141
|
+
var p = Xe();
|
|
142
142
|
const ve = qe({});
|
|
143
143
|
function Ye({
|
|
144
144
|
children: r,
|
|
@@ -146,7 +146,7 @@ function Ye({
|
|
|
146
146
|
inputErrorHandler: n,
|
|
147
147
|
readonly: t
|
|
148
148
|
}) {
|
|
149
|
-
return /* @__PURE__ */
|
|
149
|
+
return /* @__PURE__ */ p.jsx(
|
|
150
150
|
ve.Provider,
|
|
151
151
|
{
|
|
152
152
|
value: {
|
|
@@ -181,13 +181,13 @@ class er extends ke {
|
|
|
181
181
|
(o = (s = this.props).inputErrorHandler) == null || o.call(s, a);
|
|
182
182
|
}
|
|
183
183
|
render() {
|
|
184
|
-
return this.state.hasError ? /* @__PURE__ */
|
|
184
|
+
return this.state.hasError ? /* @__PURE__ */ p.jsx(p.Fragment, {}) : this.props.children;
|
|
185
185
|
}
|
|
186
186
|
}
|
|
187
187
|
const ce = ({
|
|
188
188
|
children: r,
|
|
189
189
|
withoutWrapper: e = !1
|
|
190
|
-
}) => e || !r ? r : /* @__PURE__ */
|
|
190
|
+
}) => e || !r ? r : /* @__PURE__ */ p.jsx("div", { children: r }), rr = Ne(function({
|
|
191
191
|
path: e,
|
|
192
192
|
factory: n,
|
|
193
193
|
onUpdate: t,
|
|
@@ -197,19 +197,19 @@ const ce = ({
|
|
|
197
197
|
withoutWrapper: u = !1
|
|
198
198
|
}) {
|
|
199
199
|
var Y, z, ee, re, te;
|
|
200
|
-
const i = Ze(), { formState: c } = i, { fixedValues: f = {} } = {}, { metadata: m, readonly: l, inputErrorHandler: h } = ze(),
|
|
200
|
+
const i = Ze(), { formState: c } = i, { fixedValues: f = {} } = {}, { metadata: m, readonly: l, inputErrorHandler: h } = ze(), y = n == null ? void 0 : n.getComponent(o.inputType), g = !!(o.isVisible || typeof o.disabled == "function" || typeof ((Y = o.validation) == null ? void 0 : Y.schema) == "function" || typeof ((z = o.warning) == null ? void 0 : z.schema) == "function"), x = !!((ee = o.warning) != null && ee.schema || (re = o.validation) != null && re.schema), E = g ? i.watch() : {}, R = x ? g ? Be(E, o.path) : i.watch(o.path) : void 0, C = $(() => {
|
|
201
201
|
if (!g) return {};
|
|
202
202
|
let F = E;
|
|
203
203
|
return f && Object.keys(f).forEach((N) => {
|
|
204
204
|
const P = f[N];
|
|
205
205
|
F = S(F, N, P);
|
|
206
206
|
}), F;
|
|
207
|
-
}, [g, E, f]),
|
|
207
|
+
}, [g, E, f]), w = !o.isVisible || o.isVisible(C, m), b = l || o.readonly, _ = typeof o.disabled == "function" ? o.disabled(C, m) : o.disabled, v = (te = o.warning) == null ? void 0 : te.schema, Q = $(() => {
|
|
208
208
|
var se, ae;
|
|
209
|
-
if (!
|
|
209
|
+
if (!w || typeof v > "u") return;
|
|
210
210
|
const F = typeof v == "function" ? v(C) : v, { success: N, error: P } = F.safeParse(R), ne = (ae = (se = P == null ? void 0 : P.errors) == null ? void 0 : se[0]) == null ? void 0 : ae.message;
|
|
211
211
|
return !N && ne ? ne : void 0;
|
|
212
|
-
}, [o.path, R, v,
|
|
212
|
+
}, [o.path, R, v, w]), X = $(
|
|
213
213
|
() => ({
|
|
214
214
|
path: e,
|
|
215
215
|
key: e,
|
|
@@ -223,12 +223,12 @@ const ce = ({
|
|
|
223
223
|
warning: Q
|
|
224
224
|
}),
|
|
225
225
|
[n, s, o, a, t, e, b, c.errors, _, Q]
|
|
226
|
-
), Ce = $(() =>
|
|
226
|
+
), Ce = $(() => w ? /* @__PURE__ */ p.jsxs(p.Fragment, { children: [
|
|
227
227
|
o.before ? o.before : null,
|
|
228
|
-
/* @__PURE__ */
|
|
228
|
+
/* @__PURE__ */ p.jsx(er, { path: e, inputType: o.inputType, inputErrorHandler: h, children: y == null ? void 0 : y.renderComponent(X) }),
|
|
229
229
|
o.after ? o.after : null
|
|
230
|
-
] }) : null, [
|
|
231
|
-
return
|
|
230
|
+
] }) : null, [w, o.before, o.inputType, o.after, e, y, X, c.errors]);
|
|
231
|
+
return y ? /* @__PURE__ */ p.jsx(ce, { withoutWrapper: u, children: Ce }) : /* @__PURE__ */ p.jsx(ce, { withoutWrapper: u, children: /* @__PURE__ */ p.jsxs("p", { children: [
|
|
232
232
|
"Input component not found (internal type: ",
|
|
233
233
|
o.inputType,
|
|
234
234
|
")"
|
|
@@ -280,10 +280,10 @@ function _r(r) {
|
|
|
280
280
|
defaultValues: t,
|
|
281
281
|
shouldFocusError: a,
|
|
282
282
|
resolver: n
|
|
283
|
-
}),
|
|
284
|
-
|
|
283
|
+
}), y = O(!1), g = O(JSON.stringify(t ?? {}));
|
|
284
|
+
I(() => {
|
|
285
285
|
g.current = JSON.stringify(t ?? {}), h.reset(t, {});
|
|
286
|
-
}, [h.reset, t]),
|
|
286
|
+
}, [h.reset, t]), I(() => {
|
|
287
287
|
const b = fe(), _ = le(), v = b(() => {
|
|
288
288
|
h.reset({}, {
|
|
289
289
|
keepErrors: !0,
|
|
@@ -300,19 +300,19 @@ function _r(r) {
|
|
|
300
300
|
});
|
|
301
301
|
return () => _(v);
|
|
302
302
|
}, []);
|
|
303
|
-
const { handleSubmit: x } = h, E =
|
|
304
|
-
|
|
303
|
+
const { handleSubmit: x } = h, E = O(s);
|
|
304
|
+
I(() => {
|
|
305
305
|
E.current = s;
|
|
306
306
|
}, [s]);
|
|
307
|
-
const R =
|
|
308
|
-
|
|
307
|
+
const R = O(o);
|
|
308
|
+
I(() => {
|
|
309
309
|
R.current = o;
|
|
310
310
|
}, [o]);
|
|
311
|
-
const C =
|
|
312
|
-
|
|
311
|
+
const C = O(!1);
|
|
312
|
+
I(() => {
|
|
313
313
|
const b = h.watch((_) => {
|
|
314
314
|
var v;
|
|
315
|
-
C.current || JSON.stringify(_ ?? {}) !== g.current && ((v = E.current) == null || v.call(E, { ..._ }),
|
|
315
|
+
C.current || JSON.stringify(_ ?? {}) !== g.current && ((v = E.current) == null || v.call(E, { ..._ }), y.current === !0 && (C.current = !0, h.trigger().finally(() => {
|
|
316
316
|
C.current = !1;
|
|
317
317
|
})));
|
|
318
318
|
});
|
|
@@ -320,25 +320,25 @@ function _r(r) {
|
|
|
320
320
|
b.unsubscribe();
|
|
321
321
|
};
|
|
322
322
|
}, [h]);
|
|
323
|
-
const
|
|
324
|
-
return
|
|
323
|
+
const w = O(!0);
|
|
324
|
+
return I(() => {
|
|
325
325
|
var b;
|
|
326
|
-
if (
|
|
327
|
-
|
|
326
|
+
if (w.current) {
|
|
327
|
+
w.current = !1;
|
|
328
328
|
return;
|
|
329
329
|
}
|
|
330
330
|
(b = R.current) == null || b.call(R, { isValid: h.formState.isValid, isSubmitted: h.formState.isSubmitted });
|
|
331
|
-
}, [h.formState.isValid, h.formState.isSubmitted]),
|
|
331
|
+
}, [h.formState.isValid, h.formState.isSubmitted]), I(() => {
|
|
332
332
|
if (m) {
|
|
333
333
|
const b = fe(), _ = le(), v = b(() => {
|
|
334
334
|
h.setFocus(m);
|
|
335
335
|
});
|
|
336
336
|
return () => _(v);
|
|
337
337
|
}
|
|
338
|
-
}, [h, m]), /* @__PURE__ */
|
|
338
|
+
}, [h, m]), /* @__PURE__ */ p.jsx(Ye, { metadata: c, readonly: l, inputErrorHandler: i, children: /* @__PURE__ */ p.jsx(Je, { ...h, children: typeof f == "function" ? f({
|
|
339
339
|
...h,
|
|
340
340
|
submitForm: async () => {
|
|
341
|
-
u && (
|
|
341
|
+
u && (y.current = !0, x((b) => {
|
|
342
342
|
u(b);
|
|
343
343
|
})());
|
|
344
344
|
}
|
|
@@ -363,7 +363,7 @@ function Cr(r, e) {
|
|
|
363
363
|
function tr(r, e) {
|
|
364
364
|
return r.inputs.find((n) => n.path === e);
|
|
365
365
|
}
|
|
366
|
-
const Ee = "__temp_",
|
|
366
|
+
const Ee = "__temp_", wr = (r) => Ee + r.split(".").join("__");
|
|
367
367
|
function nr(r) {
|
|
368
368
|
const e = { ...r };
|
|
369
369
|
return me(e, (n, t) => {
|
|
@@ -432,11 +432,11 @@ function A(r, e, n) {
|
|
|
432
432
|
const l = d.object(A(o, e, n)), h = d.union([
|
|
433
433
|
d.array(l).optional(),
|
|
434
434
|
Se(u, n)
|
|
435
|
-
]),
|
|
436
|
-
t[a] =
|
|
435
|
+
]), y = de(m, u, e, n, h);
|
|
436
|
+
t[a] = y;
|
|
437
437
|
} else if (c && u) {
|
|
438
|
-
const l = o != null && o.___array ? A({ ___array: o.___array }, e, n) : { ___array: d.any() }, h = ur(l, u, n),
|
|
439
|
-
t[a] =
|
|
438
|
+
const l = o != null && o.___array ? A({ ___array: o.___array }, e, n) : { ___array: d.any() }, h = ur(l, u, n), y = de(m, u, e, n, h);
|
|
439
|
+
t[a] = y;
|
|
440
440
|
} else if (m && u) {
|
|
441
441
|
const l = ir(m, u, e, n);
|
|
442
442
|
t[a] = l;
|
|
@@ -534,15 +534,15 @@ function Z(r, e, n, t, a) {
|
|
|
534
534
|
var u, i, c, f, m, l, h;
|
|
535
535
|
const o = n;
|
|
536
536
|
if (!s.isVisible || (u = s.isVisible) != null && u.call(s, o, t == null ? void 0 : t.metadata)) {
|
|
537
|
-
const
|
|
537
|
+
const y = T(r, s.path);
|
|
538
538
|
if ((i = s.validation) != null && i.schema ? S(
|
|
539
539
|
r,
|
|
540
540
|
s.path,
|
|
541
|
-
M(
|
|
541
|
+
M(y, {
|
|
542
542
|
_schema: (c = s.validation) == null ? void 0 : c.schema,
|
|
543
543
|
_input: s
|
|
544
544
|
})
|
|
545
|
-
) : s.required && S(r, s.path, M(
|
|
545
|
+
) : s.required && S(r, s.path, M(y, { _requiredOnly: !0, _input: s })), s.inputs && Z(r, s.inputs, n, t), s.inputType === "list") {
|
|
546
546
|
const g = {};
|
|
547
547
|
Z(
|
|
548
548
|
g,
|
|
@@ -566,7 +566,7 @@ function Z(r, e, n, t, a) {
|
|
|
566
566
|
), S(
|
|
567
567
|
r,
|
|
568
568
|
s.path,
|
|
569
|
-
M(
|
|
569
|
+
M(y, {
|
|
570
570
|
_schemaObj: g,
|
|
571
571
|
_schema: (h = s.validation) == null ? void 0 : h.schema,
|
|
572
572
|
_isArrayItem: !0,
|
|
@@ -644,7 +644,7 @@ const cr = (r) => Array.isArray(r == null ? void 0 : r.errors), fr = (r, e) => {
|
|
|
644
644
|
}
|
|
645
645
|
return n;
|
|
646
646
|
};
|
|
647
|
-
function
|
|
647
|
+
function Ir(r, e) {
|
|
648
648
|
return De(
|
|
649
649
|
async (n, t, a) => {
|
|
650
650
|
try {
|
|
@@ -681,7 +681,7 @@ function dr(r, e) {
|
|
|
681
681
|
i && (i.path ? (S(t, i.path, i.value), i.unset && n.push(a.path)) : S(t, a.path, i.value));
|
|
682
682
|
});
|
|
683
683
|
}), n.forEach((a) => {
|
|
684
|
-
|
|
684
|
+
pe(t, a);
|
|
685
685
|
}), t;
|
|
686
686
|
}
|
|
687
687
|
function K(r) {
|
|
@@ -691,7 +691,7 @@ function _e(r) {
|
|
|
691
691
|
const n = K(r.inputs).reduce((t, a) => {
|
|
692
692
|
const s = a.inputType === "text" || a.inputType === "boolean" || a.inputType === "number" || a.inputType === "textarea" || a.inputType === "select";
|
|
693
693
|
return (a.inputTransform || a.outputTransform) && t.push({
|
|
694
|
-
...
|
|
694
|
+
...Oe(a, "path", "inputTransform", "outputTransform"),
|
|
695
695
|
level: a.path.split(".").length,
|
|
696
696
|
isPrimitive: s
|
|
697
697
|
}), t;
|
|
@@ -701,10 +701,10 @@ function _e(r) {
|
|
|
701
701
|
function mr(r, e, n, t = {}) {
|
|
702
702
|
const { preserve: a } = t, s = K(r.inputs), o = H(e);
|
|
703
703
|
return s.forEach((u) => {
|
|
704
|
-
a && a.includes(u.path) || u.isVisible && !u.isVisible(e, n) &&
|
|
704
|
+
a && a.includes(u.path) || u.isVisible && !u.isVisible(e, n) && pe(o, u.path);
|
|
705
705
|
}), o;
|
|
706
706
|
}
|
|
707
|
-
function
|
|
707
|
+
function Or(r, e) {
|
|
708
708
|
const n = _e(e);
|
|
709
709
|
return lr(r, n);
|
|
710
710
|
}
|
|
@@ -753,7 +753,7 @@ function qr(r) {
|
|
|
753
753
|
return function(e, n) {
|
|
754
754
|
const t = r ? T(n, r) : e;
|
|
755
755
|
if (!(typeof t > "u")) {
|
|
756
|
-
if (
|
|
756
|
+
if (ye(t)) return { value: void 0, path: r };
|
|
757
757
|
if (he(t)) {
|
|
758
758
|
const a = ge(t, Ve);
|
|
759
759
|
if (k(a))
|
|
@@ -816,36 +816,28 @@ function hr(r) {
|
|
|
816
816
|
return ge(r, (e) => typeof e == "object" ? Re(e) : B(e));
|
|
817
817
|
}
|
|
818
818
|
function L(r) {
|
|
819
|
-
const { items: e,
|
|
820
|
-
return /* @__PURE__ */
|
|
821
|
-
rr,
|
|
822
|
-
{
|
|
823
|
-
input: t,
|
|
824
|
-
path: t.path,
|
|
825
|
-
...n
|
|
826
|
-
},
|
|
827
|
-
`${t.inputType}_${t.path}`
|
|
828
|
-
)) });
|
|
819
|
+
const { items: e, className: n, withoutWrapper: t = !0, ...a } = r, s = e.map((o) => /* @__PURE__ */ p.jsx(rr, { input: o, path: o.path, ...a }, `${o.inputType}_${o.path}`));
|
|
820
|
+
return t ? /* @__PURE__ */ p.jsx(p.Fragment, { children: s }) : /* @__PURE__ */ p.jsx("div", { className: n, children: s });
|
|
829
821
|
}
|
|
830
822
|
L.displayName = "RenderInputs";
|
|
831
|
-
const
|
|
823
|
+
const pr = Me((r, e) => {
|
|
832
824
|
const { inputs: n, className: t, factory: a, withoutWrapper: s } = r;
|
|
833
|
-
return s ? /* @__PURE__ */
|
|
825
|
+
return s ? /* @__PURE__ */ p.jsxs($e, { children: [
|
|
834
826
|
n.hero,
|
|
835
|
-
/* @__PURE__ */
|
|
836
|
-
] }) : /* @__PURE__ */
|
|
827
|
+
/* @__PURE__ */ p.jsx(L, { items: n.inputs, factory: a })
|
|
828
|
+
] }) : /* @__PURE__ */ p.jsxs("div", { className: t, ref: e, children: [
|
|
837
829
|
n.hero,
|
|
838
|
-
/* @__PURE__ */
|
|
830
|
+
/* @__PURE__ */ p.jsx(L, { items: n.inputs, factory: a })
|
|
839
831
|
] });
|
|
840
832
|
});
|
|
841
|
-
|
|
833
|
+
pr.displayName = "RenderForm";
|
|
842
834
|
function $r(r) {
|
|
843
835
|
let e = !0;
|
|
844
836
|
return me(r, (n) => {
|
|
845
|
-
e = e && (n === "" ||
|
|
837
|
+
e = e && (n === "" || ye(n) || B(n));
|
|
846
838
|
}), e;
|
|
847
839
|
}
|
|
848
|
-
const Zr = (r = "") => Fe(r.split("_").join(" ")),
|
|
840
|
+
const Zr = (r = "") => Fe(r.split("_").join(" ")), yr = (r, e = 2, n, t = 1e3) => {
|
|
849
841
|
let a = !1;
|
|
850
842
|
const s = () => {
|
|
851
843
|
requestAnimationFrame(() => {
|
|
@@ -861,12 +853,12 @@ function Br(r) {
|
|
|
861
853
|
const {
|
|
862
854
|
field: { onBlur: e, ...n },
|
|
863
855
|
...t
|
|
864
|
-
} = Le(r), a =
|
|
856
|
+
} = Le(r), a = O(Date.now());
|
|
865
857
|
return {
|
|
866
858
|
...t,
|
|
867
859
|
field: {
|
|
868
860
|
...n,
|
|
869
|
-
onBlur:
|
|
861
|
+
onBlur: yr(e, 2, a.current)
|
|
870
862
|
}
|
|
871
863
|
};
|
|
872
864
|
}
|
|
@@ -878,18 +870,18 @@ export {
|
|
|
878
870
|
rr as InputComponentRenderer,
|
|
879
871
|
be as InputFactory,
|
|
880
872
|
Ge as InputOverrideError,
|
|
881
|
-
|
|
873
|
+
pr as RenderForm,
|
|
882
874
|
L as RenderInputs,
|
|
883
875
|
_r as RootForm,
|
|
884
|
-
|
|
876
|
+
yr as afterFrames,
|
|
885
877
|
Fr as arrayToObjectOutputTransformer,
|
|
886
878
|
Vr as collectDefaultValues,
|
|
887
|
-
|
|
879
|
+
Or as convertDataToFormModel,
|
|
888
880
|
jr as convertFormModelToData,
|
|
889
881
|
Zr as generateReadableLabel,
|
|
890
882
|
Gr as get,
|
|
891
883
|
Rr as getDefaultValuesFromFormDefinition,
|
|
892
|
-
|
|
884
|
+
wr as getTemporaryPath,
|
|
893
885
|
_e as getTransformers,
|
|
894
886
|
ar as getValidationSchema,
|
|
895
887
|
lr as inputTransformValues,
|
|
@@ -915,6 +907,6 @@ export {
|
|
|
915
907
|
zr as useFormState,
|
|
916
908
|
ze as useRootFormContext,
|
|
917
909
|
et as useWatch,
|
|
918
|
-
|
|
910
|
+
Ir as useZodValidationResolver
|
|
919
911
|
};
|
|
920
912
|
//# sourceMappingURL=index.js.map
|