@harnessio/forms 0.4.4 → 0.5.0
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/components/InputErrorBoundary.d.ts +18 -0
- package/dist/index.cjs +3 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +240 -223
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
import { isEmpty as I, cloneDeep as q, set as g, get as _, forOwn as te, isArray as O, isObject as ne, merge as
|
|
5
|
-
import
|
|
6
|
-
import { useFormContext as
|
|
1
|
+
var pe = Object.defineProperty;
|
|
2
|
+
var ye = (r, e, n) => e in r ? pe(r, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : r[e] = n;
|
|
3
|
+
var w = (r, e, n) => ye(r, typeof e != "symbol" ? e + "" : e, n);
|
|
4
|
+
import { isEmpty as I, cloneDeep as q, set as g, get as _, forOwn as te, isArray as O, isObject as ne, merge as x, isUndefined as A, 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
|
+
import Ee, { createContext as Te, useContext as Re, Component as Se, useMemo as D, useRef as M, useEffect as j, useCallback as Oe, forwardRef as je, Fragment as Ce } from "react";
|
|
6
|
+
import { useFormContext as Ie, get as Ve, useForm as we, FormProvider as xe, appendErrors as Fe, useController as Pe } from "react-hook-form";
|
|
7
7
|
export * from "react-hook-form";
|
|
8
8
|
import * as d from "zod";
|
|
9
9
|
import { toNestErrors as qe } from "@hookform/resolvers";
|
|
10
|
-
class
|
|
10
|
+
class Ae extends Error {
|
|
11
11
|
constructor(e) {
|
|
12
12
|
super(`Input component '${e}' is already registered.`);
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
|
-
class
|
|
15
|
+
class ue {
|
|
16
16
|
constructor(e) {
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
w(this, "componentBank");
|
|
18
|
+
w(this, "allowOverride");
|
|
19
19
|
this.allowOverride = (e == null ? void 0 : e.allowOverride) ?? !1, this.componentBank = /* @__PURE__ */ new Map();
|
|
20
20
|
}
|
|
21
21
|
/**
|
|
@@ -26,7 +26,7 @@ class oe {
|
|
|
26
26
|
*/
|
|
27
27
|
registerComponent(e) {
|
|
28
28
|
if (!this.allowOverride && this.getComponent(e.internalType))
|
|
29
|
-
throw new
|
|
29
|
+
throw new Ae(e.internalType);
|
|
30
30
|
this.componentBank.set(e.internalType, e);
|
|
31
31
|
}
|
|
32
32
|
getComponent(e) {
|
|
@@ -47,7 +47,7 @@ class oe {
|
|
|
47
47
|
* @returns new input factory
|
|
48
48
|
*/
|
|
49
49
|
clone() {
|
|
50
|
-
const e = new
|
|
50
|
+
const e = new ue({
|
|
51
51
|
allowOverride: this.allowOverride
|
|
52
52
|
});
|
|
53
53
|
return this.listRegisteredComponents().forEach((n) => {
|
|
@@ -61,9 +61,9 @@ object-assign
|
|
|
61
61
|
(c) Sindre Sorhus
|
|
62
62
|
@license MIT
|
|
63
63
|
*/
|
|
64
|
-
var
|
|
65
|
-
function
|
|
66
|
-
if (X) return
|
|
64
|
+
var $, X;
|
|
65
|
+
function ke() {
|
|
66
|
+
if (X) return $;
|
|
67
67
|
X = 1;
|
|
68
68
|
var r = Object.getOwnPropertySymbols, e = Object.prototype.hasOwnProperty, n = Object.prototype.propertyIsEnumerable;
|
|
69
69
|
function t(s) {
|
|
@@ -78,12 +78,12 @@ function Ae() {
|
|
|
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 i = {},
|
|
82
|
-
i["_" + String.fromCharCode(
|
|
83
|
-
var
|
|
81
|
+
for (var i = {}, o = 0; o < 10; o++)
|
|
82
|
+
i["_" + String.fromCharCode(o)] = o;
|
|
83
|
+
var u = Object.getOwnPropertyNames(i).map(function(l) {
|
|
84
84
|
return i[l];
|
|
85
85
|
});
|
|
86
|
-
if (
|
|
86
|
+
if (u.join("") !== "0123456789")
|
|
87
87
|
return !1;
|
|
88
88
|
var c = {};
|
|
89
89
|
return "abcdefghijklmnopqrst".split("").forEach(function(l) {
|
|
@@ -93,19 +93,19 @@ function Ae() {
|
|
|
93
93
|
return !1;
|
|
94
94
|
}
|
|
95
95
|
}
|
|
96
|
-
return
|
|
97
|
-
for (var
|
|
98
|
-
|
|
99
|
-
for (var m in
|
|
100
|
-
e.call(
|
|
96
|
+
return $ = a() ? Object.assign : function(s, i) {
|
|
97
|
+
for (var o, u = t(s), c, l = 1; l < arguments.length; l++) {
|
|
98
|
+
o = Object(arguments[l]);
|
|
99
|
+
for (var m in o)
|
|
100
|
+
e.call(o, m) && (u[m] = o[m]);
|
|
101
101
|
if (r) {
|
|
102
|
-
c = r(
|
|
102
|
+
c = r(o);
|
|
103
103
|
for (var f = 0; f < c.length; f++)
|
|
104
|
-
n.call(
|
|
104
|
+
n.call(o, c[f]) && (u[c[f]] = o[c[f]]);
|
|
105
105
|
}
|
|
106
106
|
}
|
|
107
|
-
return
|
|
108
|
-
},
|
|
107
|
+
return u;
|
|
108
|
+
}, $;
|
|
109
109
|
}
|
|
110
110
|
/** @license React v17.0.2
|
|
111
111
|
* react-jsx-runtime.production.min.js
|
|
@@ -116,31 +116,31 @@ function Ae() {
|
|
|
116
116
|
* LICENSE file in the root directory of this source tree.
|
|
117
117
|
*/
|
|
118
118
|
var Y;
|
|
119
|
-
function
|
|
119
|
+
function Ne() {
|
|
120
120
|
if (Y) return S;
|
|
121
|
-
Y = 1,
|
|
122
|
-
var r =
|
|
121
|
+
Y = 1, ke();
|
|
122
|
+
var r = Ee, e = 60103;
|
|
123
123
|
if (S.Fragment = 60107, typeof Symbol == "function" && Symbol.for) {
|
|
124
124
|
var n = Symbol.for;
|
|
125
125
|
e = n("react.element"), S.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 i(
|
|
129
|
-
var l, m = {}, f = null,
|
|
130
|
-
c !== void 0 && (f = "" + c),
|
|
131
|
-
for (l in
|
|
132
|
-
if (
|
|
133
|
-
return { $$typeof: e, type:
|
|
128
|
+
function i(o, u, c) {
|
|
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
|
+
for (l in u) a.call(u, l) && !s.hasOwnProperty(l) && (m[l] = u[l]);
|
|
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: p, props: m, _owner: t.current };
|
|
134
134
|
}
|
|
135
135
|
return S.jsx = i, S.jsxs = i, S;
|
|
136
136
|
}
|
|
137
137
|
var K;
|
|
138
|
-
function
|
|
139
|
-
return K || (K = 1, Z.exports =
|
|
138
|
+
function De() {
|
|
139
|
+
return K || (K = 1, Z.exports = Ne()), Z.exports;
|
|
140
140
|
}
|
|
141
|
-
var h =
|
|
142
|
-
const ie =
|
|
143
|
-
function
|
|
141
|
+
var h = De();
|
|
142
|
+
const ie = Te({});
|
|
143
|
+
function Me({
|
|
144
144
|
children: r,
|
|
145
145
|
metadata: e,
|
|
146
146
|
readonly: n
|
|
@@ -156,15 +156,32 @@ function De({
|
|
|
156
156
|
}
|
|
157
157
|
);
|
|
158
158
|
}
|
|
159
|
-
function
|
|
160
|
-
const r =
|
|
159
|
+
function Ze() {
|
|
160
|
+
const r = Re(ie);
|
|
161
161
|
return r || console.warn("useRootFormContext must be used within RootFormProvider"), r;
|
|
162
162
|
}
|
|
163
|
+
class $e extends Se {
|
|
164
|
+
constructor() {
|
|
165
|
+
super(...arguments);
|
|
166
|
+
w(this, "state", {
|
|
167
|
+
hasError: !1
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
static getDerivedStateFromError() {
|
|
171
|
+
return { hasError: !0 };
|
|
172
|
+
}
|
|
173
|
+
componentDidCatch(n, t) {
|
|
174
|
+
console.error(`Form Input [${this.props.inputType}] has failed at path [${this.props.path}].`, n, t);
|
|
175
|
+
}
|
|
176
|
+
render() {
|
|
177
|
+
return this.state.hasError ? /* @__PURE__ */ h.jsx(h.Fragment, {}) : this.props.children;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
163
180
|
const z = ({
|
|
164
181
|
children: r,
|
|
165
182
|
withoutWrapper: e = !1
|
|
166
183
|
}) => e || !r ? r : /* @__PURE__ */ h.jsx("div", { children: r });
|
|
167
|
-
function
|
|
184
|
+
function Be({
|
|
168
185
|
path: r,
|
|
169
186
|
factory: e,
|
|
170
187
|
onUpdate: n,
|
|
@@ -174,23 +191,23 @@ function Ze({
|
|
|
174
191
|
withoutWrapper: i = !1
|
|
175
192
|
}) {
|
|
176
193
|
var W;
|
|
177
|
-
const { formState:
|
|
194
|
+
const { formState: o, watch: u } = Ie(), {
|
|
178
195
|
fixedValues: c = {}
|
|
179
196
|
/*getValuesWithDependencies*/
|
|
180
|
-
} = {}, { metadata: l, readonly: m } =
|
|
197
|
+
} = {}, { metadata: l, readonly: m } = Ze(), f = e == null ? void 0 : e.getComponent(s.inputType), p = u(), b = q(p);
|
|
181
198
|
c && Object.keys(c).forEach((V) => {
|
|
182
|
-
const
|
|
183
|
-
g(b, V,
|
|
199
|
+
const k = c[V];
|
|
200
|
+
g(b, V, k);
|
|
184
201
|
});
|
|
185
|
-
const
|
|
186
|
-
let
|
|
187
|
-
|
|
188
|
-
const
|
|
202
|
+
const y = !s.isVisible || s.isVisible(b, l);
|
|
203
|
+
let T, E;
|
|
204
|
+
y && (T = m || s.readonly, E = typeof s.disabled == "function" ? s.disabled(b, l) : s.disabled);
|
|
205
|
+
const R = (W = s.warning) == null ? void 0 : W.schema, v = D(() => {
|
|
189
206
|
var H, Q;
|
|
190
|
-
if (!
|
|
191
|
-
const V =
|
|
207
|
+
if (!y || typeof R > "u") return;
|
|
208
|
+
const V = Ve(p, s.path), k = typeof R == "function" ? R(b) : R, { success: he, error: N } = k.safeParse(V), G = (Q = (H = N == null ? void 0 : N.errors) == null ? void 0 : H[0]) == null ? void 0 : Q.message;
|
|
192
209
|
return !he && G ? G : void 0;
|
|
193
|
-
}, [s.path,
|
|
210
|
+
}, [s.path, p, R, y]), L = D(
|
|
194
211
|
() => ({
|
|
195
212
|
path: r,
|
|
196
213
|
key: r,
|
|
@@ -198,29 +215,29 @@ function Ze({
|
|
|
198
215
|
onUpdate: n,
|
|
199
216
|
onChange: t,
|
|
200
217
|
factory: e,
|
|
201
|
-
readonly:
|
|
218
|
+
readonly: T,
|
|
202
219
|
input: s,
|
|
203
|
-
disabled:
|
|
220
|
+
disabled: E,
|
|
204
221
|
warning: v
|
|
205
222
|
}),
|
|
206
|
-
[e, a, s, t, n, r,
|
|
207
|
-
), me = D(() =>
|
|
223
|
+
[e, a, s, t, n, r, T, o.errors, E, v]
|
|
224
|
+
), me = D(() => y ? /* @__PURE__ */ h.jsxs(h.Fragment, { children: [
|
|
208
225
|
s.before ? s.before : null,
|
|
209
|
-
f == null ? void 0 : f.renderComponent(L),
|
|
226
|
+
/* @__PURE__ */ h.jsx($e, { path: r, inputType: s.inputType, children: f == null ? void 0 : f.renderComponent(L) }),
|
|
210
227
|
s.after ? s.after : null
|
|
211
|
-
] }) : null, [
|
|
228
|
+
] }) : null, [y, s.before, s.inputType, s.after, r, f, L, o.errors]);
|
|
212
229
|
return f ? /* @__PURE__ */ h.jsx(z, { withoutWrapper: i, children: me }) : /* @__PURE__ */ h.jsx(z, { withoutWrapper: i, children: /* @__PURE__ */ h.jsxs("p", { children: [
|
|
213
230
|
"Input component not found (internal type: ",
|
|
214
231
|
s.inputType,
|
|
215
232
|
")"
|
|
216
233
|
] }) });
|
|
217
234
|
}
|
|
218
|
-
class
|
|
235
|
+
class ir {
|
|
219
236
|
getType() {
|
|
220
237
|
return this.internalType;
|
|
221
238
|
}
|
|
222
239
|
}
|
|
223
|
-
function
|
|
240
|
+
function cr(r) {
|
|
224
241
|
const {
|
|
225
242
|
mode: e = "onSubmit",
|
|
226
243
|
resolver: n,
|
|
@@ -229,22 +246,22 @@ function or(r) {
|
|
|
229
246
|
// validateAfterFirstSubmit,
|
|
230
247
|
onValuesChange: s,
|
|
231
248
|
onValidationChange: i,
|
|
232
|
-
onSubmit:
|
|
249
|
+
onSubmit: o,
|
|
233
250
|
// validate,
|
|
234
251
|
// validateDebounceInterval,
|
|
235
252
|
// validationConfig,
|
|
236
|
-
metadata:
|
|
253
|
+
metadata: u,
|
|
237
254
|
children: c,
|
|
238
255
|
// fixedValues
|
|
239
256
|
autoFocusPath: l,
|
|
240
257
|
readonly: m
|
|
241
|
-
} = r, f =
|
|
258
|
+
} = r, f = we({
|
|
242
259
|
mode: e ?? "onSubmit",
|
|
243
260
|
reValidateMode: "onChange",
|
|
244
261
|
defaultValues: t,
|
|
245
262
|
shouldFocusError: a,
|
|
246
263
|
resolver: n
|
|
247
|
-
}),
|
|
264
|
+
}), p = M(!1);
|
|
248
265
|
j(() => {
|
|
249
266
|
f.reset(t, {});
|
|
250
267
|
}, [f.reset, t]), j(() => {
|
|
@@ -264,18 +281,18 @@ function or(r) {
|
|
|
264
281
|
});
|
|
265
282
|
return () => cancelIdleCallback(v);
|
|
266
283
|
}, []);
|
|
267
|
-
const { getValues: b, handleSubmit:
|
|
284
|
+
const { getValues: b, handleSubmit: y } = f, T = b(), E = M(!0);
|
|
268
285
|
j(() => {
|
|
269
|
-
if (
|
|
270
|
-
|
|
286
|
+
if (E.current) {
|
|
287
|
+
E.current = !1;
|
|
271
288
|
return;
|
|
272
289
|
}
|
|
273
|
-
s == null || s({ ...
|
|
274
|
-
}, [JSON.stringify(
|
|
275
|
-
const
|
|
290
|
+
s == null || s({ ...T }), p.current === !0 && f.trigger();
|
|
291
|
+
}, [JSON.stringify(T)]);
|
|
292
|
+
const R = M(!0);
|
|
276
293
|
return j(() => {
|
|
277
|
-
if (
|
|
278
|
-
|
|
294
|
+
if (R.current) {
|
|
295
|
+
R.current = !1;
|
|
279
296
|
return;
|
|
280
297
|
}
|
|
281
298
|
i == null || i({ isValid: f.formState.isValid, isSubmitted: f.formState.isSubmitted });
|
|
@@ -292,42 +309,42 @@ function or(r) {
|
|
|
292
309
|
}, 100);
|
|
293
310
|
return () => clearTimeout(v);
|
|
294
311
|
}
|
|
295
|
-
}, [f]), /* @__PURE__ */ h.jsx(
|
|
312
|
+
}, [f]), /* @__PURE__ */ h.jsx(Me, { metadata: u, readonly: m, children: /* @__PURE__ */ h.jsx(xe, { ...f, children: typeof c == "function" ? c({
|
|
296
313
|
...f,
|
|
297
314
|
submitForm: async () => {
|
|
298
|
-
|
|
299
|
-
|
|
315
|
+
o && (p.current = !0, y((v) => {
|
|
316
|
+
o(v);
|
|
300
317
|
})());
|
|
301
318
|
}
|
|
302
319
|
}) : c }) });
|
|
303
320
|
}
|
|
304
|
-
const
|
|
321
|
+
const fr = (r) => {
|
|
305
322
|
const e = {}, n = (t) => {
|
|
306
323
|
t.forEach((a) => {
|
|
307
|
-
const { path: s, default: i, inputType:
|
|
308
|
-
(
|
|
324
|
+
const { path: s, default: i, inputType: o, inputs: u } = a;
|
|
325
|
+
(o === "group" || o === "accordion") && Array.isArray(u) ? n(u) : _(e, s) === void 0 && g(e, s, i);
|
|
309
326
|
});
|
|
310
327
|
};
|
|
311
328
|
return Array.isArray(r.inputs) && n(r.inputs), e;
|
|
312
329
|
};
|
|
313
|
-
function
|
|
330
|
+
function lr(r, e) {
|
|
314
331
|
const n = r.inputs.map((t) => {
|
|
315
|
-
const a =
|
|
332
|
+
const a = Je(e, t.path);
|
|
316
333
|
return a || t;
|
|
317
334
|
});
|
|
318
335
|
return { ...r, inputs: n };
|
|
319
336
|
}
|
|
320
|
-
function
|
|
337
|
+
function Je(r, e) {
|
|
321
338
|
return r.inputs.find((n) => n.path === e);
|
|
322
339
|
}
|
|
323
|
-
const ce = "__temp_",
|
|
324
|
-
function
|
|
340
|
+
const ce = "__temp_", dr = (r) => ce + r.split(".").join("__");
|
|
341
|
+
function Ue(r) {
|
|
325
342
|
const e = { ...r };
|
|
326
343
|
return te(e, (n, t) => {
|
|
327
344
|
t.startsWith(ce) && delete e[t];
|
|
328
345
|
}), e;
|
|
329
346
|
}
|
|
330
|
-
const
|
|
347
|
+
const Le = "Required field";
|
|
331
348
|
function C(r) {
|
|
332
349
|
const e = typeof r == "string" ? JSON.parse(r) : r;
|
|
333
350
|
if (typeof e == "string")
|
|
@@ -337,39 +354,39 @@ function C(r) {
|
|
|
337
354
|
const n = e;
|
|
338
355
|
return ne(n) && (n != null && n.message) ? e == null ? void 0 : e.message : "Unknown error";
|
|
339
356
|
}
|
|
340
|
-
function
|
|
357
|
+
function We(r, e, n) {
|
|
341
358
|
let t = {};
|
|
342
359
|
if (P(t, r.inputs, e, n), n != null && n.prefix) {
|
|
343
360
|
const s = n == null ? void 0 : n.prefix.replace(/.$/, "");
|
|
344
361
|
t = g({}, s, t);
|
|
345
362
|
}
|
|
346
|
-
return d.object(
|
|
363
|
+
return d.object(F(t, e, n));
|
|
347
364
|
}
|
|
348
|
-
function
|
|
365
|
+
function F(r, e, n) {
|
|
349
366
|
const t = {};
|
|
350
367
|
return Object.keys(r).forEach((a) => {
|
|
351
368
|
const {
|
|
352
369
|
_requiredOnly: s,
|
|
353
370
|
_schemaObj: i,
|
|
354
|
-
_input:
|
|
355
|
-
_isList:
|
|
371
|
+
_input: o,
|
|
372
|
+
_isList: u,
|
|
356
373
|
_isArrayItem: c,
|
|
357
374
|
_schema: l
|
|
358
375
|
/*...nestedSchemaObj*/
|
|
359
376
|
} = r[a];
|
|
360
|
-
if (
|
|
361
|
-
const m = d.array(d.object(
|
|
377
|
+
if (u && i && o) {
|
|
378
|
+
const m = d.array(d.object(F(i, e, n))).optional(), f = ee(l, o, e, n, m);
|
|
362
379
|
t[a] = f;
|
|
363
|
-
} else if (c &&
|
|
364
|
-
const m = i != null && i.___array ?
|
|
365
|
-
t[a] =
|
|
366
|
-
} else if (l &&
|
|
367
|
-
const m =
|
|
380
|
+
} else if (c && o) {
|
|
381
|
+
const m = i != null && i.___array ? F({ ___array: i.___array }, e, n) : { ___array: d.any() }, f = Ge(m, o, n), p = ee(l, o, e, n, f);
|
|
382
|
+
t[a] = p;
|
|
383
|
+
} else if (l && o) {
|
|
384
|
+
const m = He(l, o, e, n);
|
|
368
385
|
t[a] = m;
|
|
369
|
-
} else s &&
|
|
386
|
+
} else s && o ? t[a] = J(o, n) : t[a] = d.object(F(r[a], e, n)).optional();
|
|
370
387
|
}), t;
|
|
371
388
|
}
|
|
372
|
-
function
|
|
389
|
+
function Ge(r, e, n) {
|
|
373
390
|
return d.union([
|
|
374
391
|
d.array(r.___array).optional(),
|
|
375
392
|
d.string().superRefine((t, a) => {
|
|
@@ -388,16 +405,16 @@ function Le(r, e, n) {
|
|
|
388
405
|
})
|
|
389
406
|
]);
|
|
390
407
|
}
|
|
391
|
-
function
|
|
408
|
+
function He(r, e, n, t) {
|
|
392
409
|
return d.any().optional().superRefine(async (a, s) => {
|
|
393
|
-
var
|
|
410
|
+
var o, u;
|
|
394
411
|
if (e.required && !(await J(e, t).safeParseAsync(a)).success)
|
|
395
412
|
return s.addIssue({
|
|
396
413
|
code: d.ZodIssueCode.custom,
|
|
397
|
-
message:
|
|
414
|
+
message: B(e, t)
|
|
398
415
|
}), d.NEVER;
|
|
399
|
-
if ((
|
|
400
|
-
const c = (
|
|
416
|
+
if ((o = t == null ? void 0 : t.validationConfig) != null && o.globalValidation) {
|
|
417
|
+
const c = (u = t == null ? void 0 : t.validationConfig) == null ? void 0 : u.globalValidation(a, e, t.metadata);
|
|
401
418
|
if (c.error)
|
|
402
419
|
return s.addIssue({
|
|
403
420
|
code: d.ZodIssueCode.custom,
|
|
@@ -410,7 +427,7 @@ function We(r, e, n, t) {
|
|
|
410
427
|
if (i) {
|
|
411
428
|
const c = await i.safeParseAsync(a);
|
|
412
429
|
if (!c.success) {
|
|
413
|
-
const l = C(c == null ? void 0 : c.error.message), m = l === "Required" ?
|
|
430
|
+
const l = C(c == null ? void 0 : c.error.message), m = l === "Required" ? B(e, t) : l;
|
|
414
431
|
s.addIssue({
|
|
415
432
|
code: d.ZodIssueCode.custom,
|
|
416
433
|
message: m
|
|
@@ -422,12 +439,12 @@ function We(r, e, n, t) {
|
|
|
422
439
|
function ee(r, e, n, t, a) {
|
|
423
440
|
return d.any().optional().superRefine(async (s, i) => {
|
|
424
441
|
var l, m;
|
|
425
|
-
const
|
|
426
|
-
if (e.required && !
|
|
427
|
-
const f = C(
|
|
442
|
+
const u = await J(e, t).safeParseAsync(s);
|
|
443
|
+
if (e.required && !u.success) {
|
|
444
|
+
const f = C(u.error.message);
|
|
428
445
|
return i.addIssue({ code: d.ZodIssueCode.custom, message: f, fatal: !0 }), d.NEVER;
|
|
429
446
|
}
|
|
430
|
-
if (!e.required && !
|
|
447
|
+
if (!e.required && !u.success)
|
|
431
448
|
return d.NEVER;
|
|
432
449
|
if ((l = t == null ? void 0 : t.validationConfig) != null && l.globalValidation) {
|
|
433
450
|
const f = (m = t == null ? void 0 : t.validationConfig) == null ? void 0 : m.globalValidation(s, e, t.metadata);
|
|
@@ -457,44 +474,44 @@ function ee(r, e, n, t, a) {
|
|
|
457
474
|
}
|
|
458
475
|
function P(r, e, n, t, a) {
|
|
459
476
|
e.forEach((s) => {
|
|
460
|
-
var
|
|
477
|
+
var o, u, c, l, m, f, p;
|
|
461
478
|
const i = n;
|
|
462
|
-
if (!s.isVisible || (
|
|
479
|
+
if (!s.isVisible || (o = s.isVisible) != null && o.call(s, i, t == null ? void 0 : t.metadata)) {
|
|
463
480
|
const b = _(r, s.path);
|
|
464
|
-
if ((
|
|
481
|
+
if ((u = s.validation) != null && u.schema ? g(
|
|
465
482
|
r,
|
|
466
483
|
s.path,
|
|
467
|
-
|
|
484
|
+
x(b, {
|
|
468
485
|
_schema: (c = s.validation) == null ? void 0 : c.schema,
|
|
469
486
|
_input: s
|
|
470
487
|
})
|
|
471
|
-
) : s.required && g(r, s.path,
|
|
472
|
-
const
|
|
488
|
+
) : s.required && g(r, s.path, x(b, { _requiredOnly: !0, _input: s })), s.inputs && P(r, s.inputs, n, t), s.inputType === "list") {
|
|
489
|
+
const y = {};
|
|
473
490
|
P(
|
|
474
|
-
|
|
475
|
-
(m = (l = s.inputConfig) == null ? void 0 : l.inputs) == null ? void 0 : m.map((
|
|
476
|
-
...
|
|
477
|
-
path:
|
|
491
|
+
y,
|
|
492
|
+
(m = (l = s.inputConfig) == null ? void 0 : l.inputs) == null ? void 0 : m.map((E) => ({
|
|
493
|
+
...E,
|
|
494
|
+
path: E.relativePath
|
|
478
495
|
})),
|
|
479
496
|
n,
|
|
480
497
|
t
|
|
481
498
|
);
|
|
482
|
-
const
|
|
483
|
-
g(r, s.path,
|
|
499
|
+
const T = _(r, s.path);
|
|
500
|
+
g(r, s.path, x(T, { _schemaObj: y, _isList: !0, _input: s }));
|
|
484
501
|
}
|
|
485
502
|
if (!((f = s.validation) != null && f.schema) && s.inputType === "array") {
|
|
486
|
-
const
|
|
503
|
+
const y = {};
|
|
487
504
|
P(
|
|
488
|
-
|
|
505
|
+
y,
|
|
489
506
|
[{ ...s.inputConfig.input, path: "___array" }],
|
|
490
507
|
n,
|
|
491
508
|
t
|
|
492
509
|
), g(
|
|
493
510
|
r,
|
|
494
511
|
s.path,
|
|
495
|
-
|
|
496
|
-
_schemaObj:
|
|
497
|
-
_schema: (
|
|
512
|
+
x(b, {
|
|
513
|
+
_schemaObj: y,
|
|
514
|
+
_schema: (p = s.validation) == null ? void 0 : p.schema,
|
|
498
515
|
_isArrayItem: !0,
|
|
499
516
|
_input: s
|
|
500
517
|
})
|
|
@@ -503,22 +520,22 @@ function P(r, e, n, t, a) {
|
|
|
503
520
|
}
|
|
504
521
|
});
|
|
505
522
|
}
|
|
506
|
-
function
|
|
523
|
+
function B(r, e) {
|
|
507
524
|
var n, t, a;
|
|
508
|
-
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) ??
|
|
525
|
+
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) ?? Le;
|
|
509
526
|
}
|
|
510
527
|
function J(r, e) {
|
|
511
|
-
var t, a, s, i,
|
|
528
|
+
var t, a, s, i, o, u;
|
|
512
529
|
if ((a = (t = e == null ? void 0 : e.validationConfig) == null ? void 0 : t.requiredSchemaPerInput) != null && a[r.inputType])
|
|
513
530
|
return (i = (s = e == null ? void 0 : e.validationConfig) == null ? void 0 : s.requiredSchemaPerInput) == null ? void 0 : i[r.inputType];
|
|
514
|
-
if ((
|
|
515
|
-
return (
|
|
516
|
-
const n =
|
|
531
|
+
if ((o = e == null ? void 0 : e.validationConfig) != null && o.requiredSchema)
|
|
532
|
+
return (u = e == null ? void 0 : e.validationConfig) == null ? void 0 : u.requiredSchema;
|
|
533
|
+
const n = B(r, e);
|
|
517
534
|
return d.any().optional().superRefine((c, l) => {
|
|
518
535
|
typeof c == "object" && I(c) && l.addIssue({
|
|
519
536
|
code: d.ZodIssueCode.custom,
|
|
520
537
|
message: n
|
|
521
|
-
}), (
|
|
538
|
+
}), (A(c) || c === "") && l.addIssue({
|
|
522
539
|
code: d.ZodIssueCode.custom,
|
|
523
540
|
message: n
|
|
524
541
|
});
|
|
@@ -530,24 +547,24 @@ function fe(r, e) {
|
|
|
530
547
|
if (typeof r == "function")
|
|
531
548
|
return r(e);
|
|
532
549
|
}
|
|
533
|
-
const
|
|
550
|
+
const Qe = (r) => Array.isArray(r == null ? void 0 : r.errors), Xe = (r, e) => {
|
|
534
551
|
const n = {};
|
|
535
552
|
for (; r.length; ) {
|
|
536
|
-
const t = r[0], { code: a, message: s, path: i } = t,
|
|
537
|
-
if (!n[
|
|
553
|
+
const t = r[0], { code: a, message: s, path: i } = t, o = i.join(".");
|
|
554
|
+
if (!n[o])
|
|
538
555
|
if ("unionErrors" in t) {
|
|
539
|
-
const
|
|
540
|
-
n[
|
|
541
|
-
message:
|
|
542
|
-
type:
|
|
556
|
+
const u = t.unionErrors[0].errors[0];
|
|
557
|
+
n[o] = {
|
|
558
|
+
message: u.message,
|
|
559
|
+
type: u.code
|
|
543
560
|
};
|
|
544
561
|
} else
|
|
545
|
-
n[
|
|
546
|
-
"unionErrors" in t && t.unionErrors.forEach((
|
|
562
|
+
n[o] = { message: s, type: a };
|
|
563
|
+
"unionErrors" in t && t.unionErrors.forEach((u) => u.errors.forEach((c) => r.push(c)));
|
|
547
564
|
{
|
|
548
|
-
const
|
|
549
|
-
n[
|
|
550
|
-
|
|
565
|
+
const u = n[o].types, c = u && u[t.code];
|
|
566
|
+
n[o] = Fe(
|
|
567
|
+
o,
|
|
551
568
|
e,
|
|
552
569
|
n,
|
|
553
570
|
a,
|
|
@@ -558,20 +575,20 @@ const Ge = (r) => Array.isArray(r == null ? void 0 : r.errors), He = (r, e) => {
|
|
|
558
575
|
}
|
|
559
576
|
return n;
|
|
560
577
|
};
|
|
561
|
-
function
|
|
562
|
-
return
|
|
578
|
+
function mr(r, e) {
|
|
579
|
+
return Oe(
|
|
563
580
|
async (n, t, a) => {
|
|
564
581
|
try {
|
|
565
|
-
return await
|
|
582
|
+
return await We(r, n, e).parseAsync(n), {
|
|
566
583
|
values: n,
|
|
567
584
|
// TODO: check this - values does not contains all data
|
|
568
585
|
errors: {}
|
|
569
586
|
};
|
|
570
587
|
} catch (s) {
|
|
571
|
-
if (
|
|
588
|
+
if (Qe(s))
|
|
572
589
|
return {
|
|
573
590
|
values: {},
|
|
574
|
-
errors: qe(
|
|
591
|
+
errors: qe(Xe(s.errors, !0), a)
|
|
575
592
|
};
|
|
576
593
|
throw s;
|
|
577
594
|
}
|
|
@@ -579,21 +596,21 @@ function lr(r, e) {
|
|
|
579
596
|
[r]
|
|
580
597
|
);
|
|
581
598
|
}
|
|
582
|
-
function
|
|
599
|
+
function Ye(r, e) {
|
|
583
600
|
const n = q(r);
|
|
584
601
|
return e.forEach((t) => {
|
|
585
602
|
t.inputTransform && (O(t.inputTransform) ? t.inputTransform : [t.inputTransform]).forEach((s) => {
|
|
586
|
-
const i = _(n, t.path),
|
|
587
|
-
|
|
603
|
+
const i = _(n, t.path), o = s(i, n);
|
|
604
|
+
o && g(n, o.path ?? t.path, o.value);
|
|
588
605
|
});
|
|
589
606
|
}), n;
|
|
590
607
|
}
|
|
591
|
-
function
|
|
608
|
+
function Ke(r, e) {
|
|
592
609
|
const n = [], t = q(r);
|
|
593
610
|
return e.forEach((a) => {
|
|
594
611
|
a.outputTransform && (O(a.outputTransform) ? a.outputTransform : [a.outputTransform]).forEach((i) => {
|
|
595
|
-
const
|
|
596
|
-
|
|
612
|
+
const o = _(t, a.path), u = i(o, t);
|
|
613
|
+
u && (u.path ? (g(t, u.path, u.value), u.unset && n.push(a.path)) : g(t, a.path, u.value));
|
|
597
614
|
});
|
|
598
615
|
}), n.forEach((a) => {
|
|
599
616
|
se(t, a);
|
|
@@ -613,31 +630,31 @@ function le(r) {
|
|
|
613
630
|
}, []);
|
|
614
631
|
return n.sort((t, a) => t.level === a.level ? t.isPrimitive ? 1 : -1 : t.level > a.level ? -1 : 1), n;
|
|
615
632
|
}
|
|
616
|
-
function
|
|
633
|
+
function ze(r, e, n, t = {}) {
|
|
617
634
|
const { preserve: a } = t, s = U(r.inputs), i = q(e);
|
|
618
|
-
return s.forEach((
|
|
619
|
-
a && a.includes(
|
|
635
|
+
return s.forEach((o) => {
|
|
636
|
+
a && a.includes(o.path) || o.isVisible && !o.isVisible(e, n) && se(i, o.path);
|
|
620
637
|
}), i;
|
|
621
638
|
}
|
|
622
|
-
function
|
|
639
|
+
function hr(r, e) {
|
|
623
640
|
const n = le(e);
|
|
624
|
-
return
|
|
641
|
+
return Ye(r, n);
|
|
625
642
|
}
|
|
626
|
-
function
|
|
643
|
+
function pr(r, e, n, t = {}) {
|
|
627
644
|
const a = le(e);
|
|
628
|
-
let s =
|
|
629
|
-
return s =
|
|
645
|
+
let s = ze(e, r, n, t);
|
|
646
|
+
return s = Ke(s, a), s = Ue(s), s;
|
|
630
647
|
}
|
|
631
|
-
function
|
|
648
|
+
function yr(r) {
|
|
632
649
|
const e = {}, n = (t) => {
|
|
633
650
|
t.forEach((a) => {
|
|
634
|
-
const { default: s, path: i, inputType:
|
|
635
|
-
(
|
|
651
|
+
const { default: s, path: i, inputType: o, inputs: u } = a;
|
|
652
|
+
(o === "group" || o === "accordion") && Array.isArray(u) ? n(u) : s !== void 0 && g(e, i, s);
|
|
636
653
|
});
|
|
637
654
|
};
|
|
638
655
|
return Array.isArray(r.inputs) && n(r.inputs), e;
|
|
639
656
|
}
|
|
640
|
-
function
|
|
657
|
+
function gr() {
|
|
641
658
|
return function(r, e) {
|
|
642
659
|
if (!(typeof r > "u"))
|
|
643
660
|
return r ? {
|
|
@@ -645,7 +662,7 @@ function yr() {
|
|
|
645
662
|
} : { value: r };
|
|
646
663
|
};
|
|
647
664
|
}
|
|
648
|
-
function
|
|
665
|
+
function br(r) {
|
|
649
666
|
return function(e, n) {
|
|
650
667
|
if (typeof e > "u") return;
|
|
651
668
|
if (!e) return { value: e };
|
|
@@ -655,19 +672,19 @@ function pr(r) {
|
|
|
655
672
|
return r != null && r.unsetIfEmpty && Object.getOwnPropertyNames(t.value).length === 0 ? { value: void 0 } : t;
|
|
656
673
|
};
|
|
657
674
|
}
|
|
658
|
-
function
|
|
675
|
+
function vr() {
|
|
659
676
|
return function(r, e) {
|
|
660
677
|
if (!(typeof r > "u"))
|
|
661
678
|
return O(r) && I(r) ? { value: void 0 } : { value: r };
|
|
662
679
|
};
|
|
663
680
|
}
|
|
664
|
-
function
|
|
681
|
+
function _r(r) {
|
|
665
682
|
return function(e, n) {
|
|
666
683
|
const t = r ? _(n, r) : e;
|
|
667
684
|
if (!(typeof t > "u")) {
|
|
668
685
|
if (ae(t)) return { value: void 0, path: r };
|
|
669
686
|
if (ne(t)) {
|
|
670
|
-
const a =
|
|
687
|
+
const a = oe(t, be);
|
|
671
688
|
if (I(a))
|
|
672
689
|
return { value: void 0, path: r };
|
|
673
690
|
}
|
|
@@ -675,13 +692,13 @@ function br(r) {
|
|
|
675
692
|
}
|
|
676
693
|
};
|
|
677
694
|
}
|
|
678
|
-
function
|
|
695
|
+
function Er() {
|
|
679
696
|
return function(r, e) {
|
|
680
697
|
if (!(typeof r > "u"))
|
|
681
698
|
return ve(r) && I(r) ? { value: void 0 } : { value: r };
|
|
682
699
|
};
|
|
683
700
|
}
|
|
684
|
-
function
|
|
701
|
+
function Tr(r) {
|
|
685
702
|
return function(e, n) {
|
|
686
703
|
const t = _(n, r);
|
|
687
704
|
return typeof t == "string" ? { value: t } : { value: e };
|
|
@@ -693,21 +710,21 @@ function Rr(r) {
|
|
|
693
710
|
if (!e) return { value: e };
|
|
694
711
|
const t = _(n, r);
|
|
695
712
|
if (typeof t == "object") {
|
|
696
|
-
const a =
|
|
713
|
+
const a = er(t);
|
|
697
714
|
if (Object.getOwnPropertyNames(a).length === 1)
|
|
698
715
|
return { value: e, path: r };
|
|
699
716
|
}
|
|
700
717
|
return { value: e };
|
|
701
718
|
};
|
|
702
719
|
}
|
|
703
|
-
function
|
|
720
|
+
function Sr(r) {
|
|
704
721
|
return function(e, n) {
|
|
705
722
|
if (typeof e > "u") return;
|
|
706
723
|
const t = _(n, r);
|
|
707
724
|
return typeof t == "string" ? { value: [t] } : { value: e };
|
|
708
725
|
};
|
|
709
726
|
}
|
|
710
|
-
function
|
|
727
|
+
function Or(r, e) {
|
|
711
728
|
return function(n, t) {
|
|
712
729
|
if (typeof n > "u") return;
|
|
713
730
|
if (!n) return { value: n };
|
|
@@ -722,15 +739,15 @@ function Tr(r, e) {
|
|
|
722
739
|
};
|
|
723
740
|
}
|
|
724
741
|
function de(r) {
|
|
725
|
-
return typeof r == "object" ? !Object.getOwnPropertyNames(r).some((e) => !de(r[e])) :
|
|
742
|
+
return typeof r == "object" ? !Object.getOwnPropertyNames(r).some((e) => !de(r[e])) : A(r);
|
|
726
743
|
}
|
|
727
|
-
function
|
|
728
|
-
return
|
|
744
|
+
function er(r) {
|
|
745
|
+
return oe(r, (e) => typeof e == "object" ? de(e) : A(e));
|
|
729
746
|
}
|
|
730
747
|
function re(r) {
|
|
731
748
|
const { items: e, ...n } = r;
|
|
732
749
|
return /* @__PURE__ */ h.jsx(h.Fragment, { children: e.map((t) => /* @__PURE__ */ h.jsx(
|
|
733
|
-
|
|
750
|
+
Be,
|
|
734
751
|
{
|
|
735
752
|
input: t,
|
|
736
753
|
path: t.path,
|
|
@@ -739,9 +756,9 @@ function re(r) {
|
|
|
739
756
|
`${t.inputType}_${t.path}_${t.label}`
|
|
740
757
|
)) });
|
|
741
758
|
}
|
|
742
|
-
const
|
|
759
|
+
const rr = je((r, e) => {
|
|
743
760
|
const { inputs: n, className: t, factory: a, withoutWrapper: s } = r;
|
|
744
|
-
return s ? /* @__PURE__ */ h.jsxs(
|
|
761
|
+
return s ? /* @__PURE__ */ h.jsxs(Ce, { children: [
|
|
745
762
|
n.hero,
|
|
746
763
|
/* @__PURE__ */ h.jsx(re, { items: n.inputs, factory: a, withoutWrapper: s })
|
|
747
764
|
] }) : /* @__PURE__ */ h.jsxs("div", { className: t, ref: e, children: [
|
|
@@ -749,14 +766,14 @@ const ze = Oe((r, e) => {
|
|
|
749
766
|
/* @__PURE__ */ h.jsx(re, { items: n.inputs, factory: a, withoutWrapper: s })
|
|
750
767
|
] });
|
|
751
768
|
});
|
|
752
|
-
|
|
753
|
-
function
|
|
769
|
+
rr.displayName = "RenderForm";
|
|
770
|
+
function jr(r) {
|
|
754
771
|
let e = !0;
|
|
755
772
|
return te(r, (n) => {
|
|
756
|
-
e = e && (n === "" || ae(n) ||
|
|
773
|
+
e = e && (n === "" || ae(n) || A(n));
|
|
757
774
|
}), e;
|
|
758
775
|
}
|
|
759
|
-
const
|
|
776
|
+
const Cr = (r = "") => _e(r.split("_").join(" ")), tr = (r, e = 2) => {
|
|
760
777
|
let n = !1;
|
|
761
778
|
const t = () => {
|
|
762
779
|
requestAnimationFrame(() => {
|
|
@@ -767,7 +784,7 @@ const Or = (r = "") => _e(r.split("_").join(" ")), er = (r, e = 2) => {
|
|
|
767
784
|
n = !0;
|
|
768
785
|
};
|
|
769
786
|
};
|
|
770
|
-
function
|
|
787
|
+
function Ir(r) {
|
|
771
788
|
const {
|
|
772
789
|
field: { onBlur: e, ...n },
|
|
773
790
|
...t
|
|
@@ -776,45 +793,45 @@ function jr(r) {
|
|
|
776
793
|
...t,
|
|
777
794
|
field: {
|
|
778
795
|
...n,
|
|
779
|
-
onBlur:
|
|
796
|
+
onBlur: tr(e)
|
|
780
797
|
}
|
|
781
798
|
};
|
|
782
799
|
}
|
|
783
800
|
export {
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
801
|
+
ir as InputComponent,
|
|
802
|
+
Be as InputComponentRenderer,
|
|
803
|
+
ue as InputFactory,
|
|
804
|
+
Ae as InputOverrideError,
|
|
805
|
+
rr as RenderForm,
|
|
789
806
|
re as RenderInputs,
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
807
|
+
cr as RootForm,
|
|
808
|
+
tr as afterFrames,
|
|
809
|
+
br as arrayToObjectOutputTransformer,
|
|
810
|
+
yr as collectDefaultValues,
|
|
811
|
+
hr as convertDataToFormModel,
|
|
812
|
+
pr as convertFormModelToData,
|
|
813
|
+
Cr as generateReadableLabel,
|
|
814
|
+
fr as getDefaultValuesFromFormDefinition,
|
|
815
|
+
dr as getTemporaryPath,
|
|
799
816
|
le as getTransformers,
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
817
|
+
We as getValidationSchema,
|
|
818
|
+
Ye as inputTransformValues,
|
|
819
|
+
jr as isChildrenEmpty,
|
|
820
|
+
gr as objectToArrayInputTransformer,
|
|
821
|
+
Ke as outputTransformValues,
|
|
822
|
+
lr as overrideFormDefinition,
|
|
806
823
|
C as processValidationParseResponse,
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
824
|
+
Ue as removeTemporaryFieldsValue,
|
|
825
|
+
Sr as shorthandArrayInputTransformer,
|
|
826
|
+
Or as shorthandArrayOutputTransformer,
|
|
827
|
+
Tr as shorthandObjectInputTransformer,
|
|
811
828
|
Rr as shorthandObjectOutputTransformer,
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
829
|
+
vr as unsetEmptyArrayOutputTransformer,
|
|
830
|
+
_r as unsetEmptyObjectOutputTransformer,
|
|
831
|
+
Er as unsetEmptyStringOutputTransformer,
|
|
832
|
+
ze as unsetHiddenInputsValues,
|
|
833
|
+
Ir as useController,
|
|
834
|
+
Ze as useRootFormContext,
|
|
835
|
+
mr as useZodValidationResolver
|
|
819
836
|
};
|
|
820
837
|
//# sourceMappingURL=index.js.map
|