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