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