@m4l/components 9.82.0 → 9.82.1-beta-hotfix-790-m4l-components-dynamic-form-validation.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/components/DynamicForm/DynamicForm.d.ts.map +1 -1
- package/components/DynamicForm/DynamicForm.js +69 -69
- package/components/DynamicForm/helpers/buildDynamicFormBatchPayload/buildDynamicFormBatchPayload.d.ts +11 -0
- package/components/DynamicForm/helpers/buildDynamicFormBatchPayload/buildDynamicFormBatchPayload.d.ts.map +1 -0
- package/components/DynamicForm/helpers/buildDynamicFormBatchPayload/buildDynamicFormBatchPayload.js +64 -0
- package/components/DynamicForm/helpers/buildDynamicFormBatchPayload/constants.d.ts +3 -0
- package/components/DynamicForm/helpers/buildDynamicFormBatchPayload/constants.d.ts.map +1 -0
- package/components/DynamicForm/helpers/buildDynamicFormBatchPayload/constants.js +10 -0
- package/components/DynamicForm/helpers/buildDynamicFormBatchPayload/index.d.ts +3 -0
- package/components/DynamicForm/helpers/buildDynamicFormBatchPayload/index.d.ts.map +1 -0
- package/components/DynamicForm/helpers/buildDynamicFormBatchPayload/types.d.ts +13 -0
- package/components/DynamicForm/helpers/buildDynamicFormBatchPayload/types.d.ts.map +1 -0
- package/components/DynamicForm/helpers/createFieldValidationSchema/createFieldValidationSchema.d.ts.map +1 -1
- package/components/DynamicForm/helpers/createFieldValidationSchema/createFieldValidationSchema.js +68 -49
- package/components/DynamicForm/helpers/createFieldValidationSchema/strategies/validation/validationStrategies.d.ts.map +1 -1
- package/components/DynamicForm/helpers/createFieldValidationSchema/strategies/validation/validationStrategies.js +103 -101
- package/components/DynamicForm/hooks/useDynamicForm/useDynamicForm.d.ts.map +1 -1
- package/components/DynamicForm/hooks/useDynamicForm/useDynamicForm.js +52 -48
- package/components/DynamicForm/hooks/useDynamicFormData/types.d.ts +3 -2
- package/components/DynamicForm/hooks/useDynamicFormData/types.d.ts.map +1 -1
- package/components/DynamicForm/hooks/useDynamicFormData/useDynamicFormData.d.ts +2 -2
- package/components/DynamicForm/hooks/useDynamicFormData/useDynamicFormData.d.ts.map +1 -1
- package/components/DynamicForm/hooks/useDynamicFormData/useDynamicFormData.js +106 -82
- package/components/DynamicForm/types.d.ts +8 -6
- package/components/DynamicForm/types.d.ts.map +1 -1
- package/package.json +7 -7
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DynamicForm.d.ts","sourceRoot":"","sources":["../../../../../../packages/components/src/components/DynamicForm/DynamicForm.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAqF,MAAM,OAAO,CAAC;AAU1G,OAAO,EAEL,gBAAgB,EAChB,cAAc,EAGf,MAAM,SAAS,CAAC;AAYjB;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,eAAO,MAAM,WAAW,
|
|
1
|
+
{"version":3,"file":"DynamicForm.d.ts","sourceRoot":"","sources":["../../../../../../packages/components/src/components/DynamicForm/DynamicForm.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAqF,MAAM,OAAO,CAAC;AAU1G,OAAO,EAEL,gBAAgB,EAChB,cAAc,EAGf,MAAM,SAAS,CAAC;AAYjB;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,eAAO,MAAM,WAAW,yFAiStB,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import Z, { forwardRef as $, useMemo as c, useState as tt, useEffect as et, useImperativeHandle as ot, useCallback as
|
|
3
|
-
import
|
|
1
|
+
import { jsx as i } from "@emotion/react/jsx-runtime";
|
|
2
|
+
import Z, { forwardRef as $, useMemo as c, useState as tt, useEffect as et, useImperativeHandle as ot, useCallback as P } from "react";
|
|
3
|
+
import T from "clsx";
|
|
4
4
|
import { useModuleSkeleton as rt } from "@m4l/core";
|
|
5
5
|
import { useComponentSize as it } from "../../hooks/useComponentSize/index.js";
|
|
6
6
|
import { TEST_PROP_ID as st } from "../../test/constants_no_mock.js";
|
|
@@ -9,24 +9,24 @@ import { DynamicFormContentRootStyled as at, DynamicFormFormProviderStyled as mt
|
|
|
9
9
|
import { DYNAMIC_FORM_CLASSES as b, EMPTY_DATA as ut } from "./constants.js";
|
|
10
10
|
import { useDynamicForm as dt } from "./hooks/useDynamicForm/useDynamicForm.js";
|
|
11
11
|
import { useDynamicFormData as lt } from "./hooks/useDynamicFormData/useDynamicFormData.js";
|
|
12
|
-
import { DynamicFormContent as
|
|
12
|
+
import { DynamicFormContent as C } from "./subcomponents/DynamicFormContent/DynamicFormContent.js";
|
|
13
13
|
import { useFieldsWithFetchedOptions as ct } from "./hooks/useFieldsWithFetchedOptions/useFieldsWithFetchedOptions.js";
|
|
14
14
|
import { filterUnknownFieldsFromSubmit as ft } from "./helpers/filterUnknownFieldsFromSubmit/filterUnknownFieldsFromSubmit.js";
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
const Ft = $((
|
|
15
|
+
import { normalizeDynamicFormFields as pt } from "./helpers/resolveFormSections/resolveFormSections.js";
|
|
16
|
+
import { mapOptionFieldValuesForSubmit as St } from "./helpers/mapOptionFieldValuesForSubmit/mapOptionFieldValuesForSubmit.js";
|
|
17
|
+
const Ft = $((k, z) => {
|
|
18
18
|
const {
|
|
19
|
-
formId:
|
|
20
|
-
formInstanceId:
|
|
21
|
-
inputEndpoint:
|
|
22
|
-
outputEndpoint:
|
|
23
|
-
submitMode:
|
|
19
|
+
formId: _,
|
|
20
|
+
formInstanceId: A,
|
|
21
|
+
inputEndpoint: H,
|
|
22
|
+
outputEndpoint: s,
|
|
23
|
+
submitMode: t,
|
|
24
24
|
initialData: D,
|
|
25
|
-
formatInputData:
|
|
26
|
-
formatOutputData:
|
|
25
|
+
formatInputData: L,
|
|
26
|
+
formatOutputData: g,
|
|
27
27
|
onSubmit: n,
|
|
28
28
|
onSubmitError: y,
|
|
29
|
-
size:
|
|
29
|
+
size: x,
|
|
30
30
|
readOnly: a = !1,
|
|
31
31
|
suppressFormHeader: h = !0,
|
|
32
32
|
className: v,
|
|
@@ -35,39 +35,39 @@ const Ft = $((C, k) => {
|
|
|
35
35
|
fieldWrapperClassName: E,
|
|
36
36
|
fieldFlow: u = "responsiveWrap",
|
|
37
37
|
coupled: p = !1,
|
|
38
|
-
coupledStatusLoad:
|
|
39
|
-
actionFormIntroProps:
|
|
40
|
-
renderActions:
|
|
41
|
-
} =
|
|
42
|
-
formData:
|
|
38
|
+
coupledStatusLoad: W,
|
|
39
|
+
actionFormIntroProps: V,
|
|
40
|
+
renderActions: U
|
|
41
|
+
} = k, { currentSize: d } = it(x), Y = rt(), {
|
|
42
|
+
formData: j,
|
|
43
43
|
statusLoad: I,
|
|
44
44
|
handleSubmit: w
|
|
45
45
|
} = lt({
|
|
46
|
-
formId:
|
|
47
|
-
formInstanceId:
|
|
48
|
-
inputEndpoint:
|
|
49
|
-
outputEndpoint:
|
|
50
|
-
submitMode:
|
|
46
|
+
formId: _,
|
|
47
|
+
formInstanceId: A,
|
|
48
|
+
inputEndpoint: H,
|
|
49
|
+
outputEndpoint: s,
|
|
50
|
+
submitMode: t,
|
|
51
51
|
initialData: D,
|
|
52
|
-
formatInputData:
|
|
53
|
-
formatOutputData:
|
|
52
|
+
formatInputData: L,
|
|
53
|
+
formatOutputData: g,
|
|
54
54
|
onSubmit: n
|
|
55
|
-
}),
|
|
56
|
-
() =>
|
|
57
|
-
[
|
|
55
|
+
}), o = j || D, S = c(
|
|
56
|
+
() => pt(o?.fields),
|
|
57
|
+
[o?.fields]
|
|
58
58
|
), { fields: O } = ct({
|
|
59
59
|
fields: S.fields
|
|
60
|
-
}),
|
|
61
|
-
...
|
|
60
|
+
}), e = c(() => o && {
|
|
61
|
+
...o,
|
|
62
62
|
fields: O
|
|
63
|
-
}, [O,
|
|
63
|
+
}, [O, o]), { initialValues: B, validationSchema: q } = dt(e || ut), [F, l] = tt(null);
|
|
64
64
|
et(() => {
|
|
65
65
|
if (!F)
|
|
66
66
|
return;
|
|
67
|
-
const
|
|
68
|
-
return () => clearTimeout(
|
|
67
|
+
const r = setTimeout(() => l(null), 5e3);
|
|
68
|
+
return () => clearTimeout(r);
|
|
69
69
|
}, [F]);
|
|
70
|
-
const
|
|
70
|
+
const G = c(() => ({
|
|
71
71
|
size: d,
|
|
72
72
|
readOnly: a,
|
|
73
73
|
fieldFlow: u
|
|
@@ -80,43 +80,43 @@ const Ft = $((C, k) => {
|
|
|
80
80
|
onSubmit: () => {
|
|
81
81
|
}
|
|
82
82
|
}), []);
|
|
83
|
-
ot(
|
|
84
|
-
const
|
|
85
|
-
async (
|
|
86
|
-
if (!!!(
|
|
83
|
+
ot(z, () => R.current ?? M, [M]);
|
|
84
|
+
const J = P(
|
|
85
|
+
async (r) => {
|
|
86
|
+
if (!!!(s || t === "batch" || t === "perField" || n))
|
|
87
87
|
return;
|
|
88
|
-
const
|
|
89
|
-
}),
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
), X =
|
|
88
|
+
const Q = s || t === "batch" || t === "perField" ? w : n ?? (() => {
|
|
89
|
+
}), N = ft(
|
|
90
|
+
r,
|
|
91
|
+
e?.fields ?? []
|
|
92
|
+
), X = t === "batch" ? N : St(N, e?.fields ?? []);
|
|
93
93
|
try {
|
|
94
|
-
await
|
|
94
|
+
await Q(X), l("success");
|
|
95
95
|
} catch {
|
|
96
96
|
l("error");
|
|
97
97
|
}
|
|
98
98
|
},
|
|
99
|
-
[w, n,
|
|
100
|
-
),
|
|
101
|
-
(
|
|
102
|
-
l("error"), y?.(
|
|
99
|
+
[w, n, s, e?.fields, t]
|
|
100
|
+
), K = P(
|
|
101
|
+
(r) => {
|
|
102
|
+
l("error"), y?.(r);
|
|
103
103
|
},
|
|
104
104
|
[y]
|
|
105
105
|
);
|
|
106
|
-
return
|
|
106
|
+
return Y ? /* @__PURE__ */ i(
|
|
107
107
|
at,
|
|
108
108
|
{
|
|
109
|
-
ownerState:
|
|
110
|
-
className:
|
|
109
|
+
ownerState: G,
|
|
110
|
+
className: T(v, b.contentRoot),
|
|
111
111
|
...typeof m == "string" ? { "data-meta": m } : {},
|
|
112
112
|
...process.env.NODE_ENV !== "production" ? { [st]: f } : {},
|
|
113
|
-
children: /* @__PURE__ */
|
|
113
|
+
children: /* @__PURE__ */ i(nt, {})
|
|
114
114
|
}
|
|
115
|
-
) :
|
|
116
|
-
|
|
115
|
+
) : e ? p ? /* @__PURE__ */ i(
|
|
116
|
+
C,
|
|
117
117
|
{
|
|
118
|
-
data:
|
|
119
|
-
statusLoad:
|
|
118
|
+
data: e,
|
|
119
|
+
statusLoad: W,
|
|
120
120
|
currentSize: d,
|
|
121
121
|
fieldWrapperClassName: E,
|
|
122
122
|
dataTestId: f,
|
|
@@ -127,21 +127,21 @@ const Ft = $((C, k) => {
|
|
|
127
127
|
fieldFlow: u,
|
|
128
128
|
contractIssues: S.issues
|
|
129
129
|
}
|
|
130
|
-
) : /* @__PURE__ */
|
|
130
|
+
) : /* @__PURE__ */ i(
|
|
131
131
|
mt,
|
|
132
132
|
{
|
|
133
133
|
ref: R,
|
|
134
|
-
values:
|
|
135
|
-
validationSchema:
|
|
136
|
-
onSubmit:
|
|
137
|
-
onSubmitError:
|
|
134
|
+
values: B,
|
|
135
|
+
validationSchema: q,
|
|
136
|
+
onSubmit: J,
|
|
137
|
+
onSubmitError: K,
|
|
138
138
|
statusLoad: I,
|
|
139
139
|
mode: "onSubmit",
|
|
140
|
-
className:
|
|
141
|
-
children: /* @__PURE__ */
|
|
142
|
-
|
|
140
|
+
className: T(v, b.contentRoot, b.formProvider),
|
|
141
|
+
children: /* @__PURE__ */ i(
|
|
142
|
+
C,
|
|
143
143
|
{
|
|
144
|
-
data:
|
|
144
|
+
data: e,
|
|
145
145
|
statusLoad: I,
|
|
146
146
|
currentSize: d,
|
|
147
147
|
fieldWrapperClassName: E,
|
|
@@ -152,8 +152,8 @@ const Ft = $((C, k) => {
|
|
|
152
152
|
suppressFormHeader: h,
|
|
153
153
|
fieldFlow: u,
|
|
154
154
|
contractIssues: S.issues,
|
|
155
|
-
actionFormIntroProps:
|
|
156
|
-
renderActions:
|
|
155
|
+
actionFormIntroProps: V,
|
|
156
|
+
renderActions: U,
|
|
157
157
|
submitFeedbackStatus: F
|
|
158
158
|
}
|
|
159
159
|
)
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Field } from '../../types';
|
|
2
|
+
import { BuildDynamicFormBatchPayloadOptions, DynamicFormBatchPayload } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Reject a draft that tries to clear a persisted answer because the batch API treats null or an
|
|
5
|
+
* absent typed value as no change. This check intentionally runs before option mapping can turn a
|
|
6
|
+
* null single selection into an empty array.
|
|
7
|
+
*/
|
|
8
|
+
export declare function assertNoUnsupportedBatchClear(data: Record<string, unknown>, fields: Field[]): void;
|
|
9
|
+
/** Build the native typed body accepted by the atomic form-instance values endpoint. */
|
|
10
|
+
export declare function buildDynamicFormBatchPayload(options: BuildDynamicFormBatchPayloadOptions): DynamicFormBatchPayload;
|
|
11
|
+
//# sourceMappingURL=buildDynamicFormBatchPayload.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buildDynamicFormBatchPayload.d.ts","sourceRoot":"","sources":["../../../../../../../../packages/components/src/components/DynamicForm/helpers/buildDynamicFormBatchPayload/buildDynamicFormBatchPayload.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAOzC,OAAO,KAAK,EACV,mCAAmC,EAEnC,uBAAuB,EAExB,MAAM,SAAS,CAAC;AAYjB;;;;GAIG;AACH,wBAAgB,6BAA6B,CAC3C,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,MAAM,EAAE,KAAK,EAAE,GACd,IAAI,CAyBN;AAqED,wFAAwF;AACxF,wBAAgB,4BAA4B,CAC1C,OAAO,EAAE,mCAAmC,GAC3C,uBAAuB,CAiDzB"}
|
package/components/DynamicForm/helpers/buildDynamicFormBatchPayload/buildDynamicFormBatchPayload.js
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { DYNAMIC_FORM_BATCH_VALUE_KEYS as b } from "./constants.js";
|
|
2
|
+
import { isKnownFieldComponent as d, isFieldExcludedFromSubmit as m } from "../filterUnknownFieldsFromSubmit/filterUnknownFieldsFromSubmit.js";
|
|
3
|
+
import { getFieldTypeApiKey as u } from "../getFieldTypeApiKey/getFieldTypeApiKey.js";
|
|
4
|
+
import { mapOptionFieldValuesForSubmit as p } from "../mapOptionFieldValuesForSubmit/mapOptionFieldValuesForSubmit.js";
|
|
5
|
+
function y(e) {
|
|
6
|
+
return Array.isArray(e) ? e.length > 0 : e != null;
|
|
7
|
+
}
|
|
8
|
+
function h(e, i) {
|
|
9
|
+
for (const t of i) {
|
|
10
|
+
if (!d(t) || m(t) || typeof t.name != "string" || !(t.name in e))
|
|
11
|
+
continue;
|
|
12
|
+
const n = e[t.name], a = n === null && t.currentValue !== null, o = u(t) === "value_jsonb" && Array.isArray(n) && n.length === 0 && y(t.currentValue);
|
|
13
|
+
if (a || o)
|
|
14
|
+
throw new Error(
|
|
15
|
+
`DynamicForm batch cannot clear field ${t.id}; the endpoint treats empty values as no change.`
|
|
16
|
+
);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
function F(e) {
|
|
20
|
+
return e !== null && typeof e == "object" && !Array.isArray(e) && Object.getPrototypeOf(e) === Object.prototype;
|
|
21
|
+
}
|
|
22
|
+
function f(e) {
|
|
23
|
+
return e === null || typeof e == "string" || typeof e == "boolean" ? !0 : typeof e == "number" ? Number.isFinite(e) : Array.isArray(e) ? e.every(f) : F(e) && Object.values(e).every(f);
|
|
24
|
+
}
|
|
25
|
+
function g(e, i, t) {
|
|
26
|
+
if (i === null)
|
|
27
|
+
return;
|
|
28
|
+
const n = () => {
|
|
29
|
+
throw new Error(`DynamicForm batch value is incompatible with ${e} for field ${t.id}.`);
|
|
30
|
+
};
|
|
31
|
+
e === "value_boolean" && typeof i != "boolean" && n(), e === "value_double" && (typeof i != "number" || !Number.isFinite(i)) && n(), e === "value_integer" && (typeof i != "number" || !Number.isSafeInteger(i)) && n(), e === "value_jsonb" && !f(i) && n(), e === "value_string" && typeof i != "string" && n();
|
|
32
|
+
}
|
|
33
|
+
function E(e) {
|
|
34
|
+
const { data: i, fields: t } = e;
|
|
35
|
+
h(i, t);
|
|
36
|
+
const n = p(i, t), a = /* @__PURE__ */ new Set(), o = [];
|
|
37
|
+
for (const r of t) {
|
|
38
|
+
if (!d(r) || m(r) || typeof r.name != "string" || !(r.name in n))
|
|
39
|
+
continue;
|
|
40
|
+
if (!Number.isSafeInteger(r.id))
|
|
41
|
+
throw new Error(`DynamicForm batch field id must be a safe integer: ${r.id}.`);
|
|
42
|
+
if (a.has(r.id))
|
|
43
|
+
throw new Error(`DynamicForm batch field id is duplicated: ${r.id}.`);
|
|
44
|
+
a.add(r.id);
|
|
45
|
+
const s = n[r.name];
|
|
46
|
+
if (s === void 0)
|
|
47
|
+
continue;
|
|
48
|
+
const c = u(r);
|
|
49
|
+
if (!b.has(c))
|
|
50
|
+
throw new Error(`DynamicForm field ${r.id} does not have a supported batch value key.`);
|
|
51
|
+
const l = c;
|
|
52
|
+
g(l, s, r), o.push({
|
|
53
|
+
form_field_id: r.id,
|
|
54
|
+
[l]: s
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
if (o.length === 0)
|
|
58
|
+
throw new Error("DynamicForm batch submit requires at least one eligible field value.");
|
|
59
|
+
return { fields: o };
|
|
60
|
+
}
|
|
61
|
+
export {
|
|
62
|
+
h as assertNoUnsupportedBatchClear,
|
|
63
|
+
E as buildDynamicFormBatchPayload
|
|
64
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../../../../../../packages/components/src/components/DynamicForm/helpers/buildDynamicFormBatchPayload/constants.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,SAAS,CAAC;AAExD,eAAO,MAAM,6BAA6B,+BAMxC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../../../packages/components/src/components/DynamicForm/helpers/buildDynamicFormBatchPayload/index.ts"],"names":[],"mappings":"AAAA,cAAc,gCAAgC,CAAC;AAC/C,mBAAmB,SAAS,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Field } from '../../types';
|
|
2
|
+
export type DynamicFormBatchValueKey = 'value_boolean' | 'value_double' | 'value_integer' | 'value_jsonb' | 'value_string';
|
|
3
|
+
export type DynamicFormBatchField = {
|
|
4
|
+
form_field_id: number;
|
|
5
|
+
} & Partial<Record<DynamicFormBatchValueKey, unknown>>;
|
|
6
|
+
export interface DynamicFormBatchPayload {
|
|
7
|
+
fields: DynamicFormBatchField[];
|
|
8
|
+
}
|
|
9
|
+
export interface BuildDynamicFormBatchPayloadOptions {
|
|
10
|
+
data: Record<string, unknown>;
|
|
11
|
+
fields: Field[];
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../../../../../packages/components/src/components/DynamicForm/helpers/buildDynamicFormBatchPayload/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAEzC,MAAM,MAAM,wBAAwB,GAChC,eAAe,GACf,cAAc,GACd,eAAe,GACf,aAAa,GACb,cAAc,CAAC;AAEnB,MAAM,MAAM,qBAAqB,GAAG;IAClC,aAAa,EAAE,MAAM,CAAC;CACvB,GAAG,OAAO,CAAC,MAAM,CAAC,wBAAwB,EAAE,OAAO,CAAC,CAAC,CAAC;AAEvD,MAAM,WAAW,uBAAuB;IACtC,MAAM,EAAE,qBAAqB,EAAE,CAAC;CACjC;AAED,MAAM,WAAW,mCAAmC;IAClD,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC9B,MAAM,EAAE,KAAK,EAAE,CAAC;CACjB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createFieldValidationSchema.d.ts","sourceRoot":"","sources":["../../../../../../../../packages/components/src/components/DynamicForm/helpers/createFieldValidationSchema/createFieldValidationSchema.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAmB,MAAM,aAAa,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAIzC,OAAO,KAAK,EAEV,+BAA+B,EAChC,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"createFieldValidationSchema.d.ts","sourceRoot":"","sources":["../../../../../../../../packages/components/src/components/DynamicForm/helpers/createFieldValidationSchema/createFieldValidationSchema.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAmB,MAAM,aAAa,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAIzC,OAAO,KAAK,EAEV,+BAA+B,EAChC,MAAM,0BAA0B,CAAC;AA2ElC;;;;;;;GAOG;AACH,wBAAgB,2BAA2B,CACzC,KAAK,EAAE,KAAK,EACZ,QAAQ,EAAE,YAAY,GACrB,+BAA+B,CA8EjC"}
|
package/components/DynamicForm/helpers/createFieldValidationSchema/createFieldValidationSchema.js
CHANGED
|
@@ -1,65 +1,84 @@
|
|
|
1
|
-
import * as
|
|
2
|
-
import { DYNAMIC_FORM_DICTIONARY as
|
|
3
|
-
import { createBaseSchema as
|
|
4
|
-
import { VALIDATION_STRATEGY_REGISTRY as
|
|
5
|
-
import { isSupportedDynamicFormField as
|
|
6
|
-
import { resolveFieldMandatory as
|
|
7
|
-
import { applyRequiredValidation as
|
|
8
|
-
import { isRecord as
|
|
9
|
-
import { normalizeValidation as
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
import * as y from "yup";
|
|
2
|
+
import { DYNAMIC_FORM_DICTIONARY as c } from "../../dictionary.js";
|
|
3
|
+
import { createBaseSchema as v } from "./strategies/baseSchema/createBaseSchema.js";
|
|
4
|
+
import { VALIDATION_STRATEGY_REGISTRY as S } from "./strategies/validation/validationStrategies.js";
|
|
5
|
+
import { isSupportedDynamicFormField as A } from "../fieldContractAllowlist/fieldContractAllowlist.js";
|
|
6
|
+
import { resolveFieldMandatory as E } from "../resolveFieldContractAliases/resolveFieldContractAliases.js";
|
|
7
|
+
import { applyRequiredValidation as R } from "../applyRequiredValidation/applyRequiredValidation.js";
|
|
8
|
+
import { isRecord as p } from "../isRecord/isRecord.js";
|
|
9
|
+
import { normalizeValidation as F } from "../normalizeValidation/normalizeValidation.js";
|
|
10
|
+
import { resolveValidationErrorMessage as I } from "../resolveValidationErrorMessage/resolveValidationErrorMessage.js";
|
|
11
|
+
function M(e, r) {
|
|
12
|
+
if (!(!p(e) || typeof e.id != "string" || e.id === ""))
|
|
12
13
|
return {
|
|
13
|
-
id:
|
|
14
|
-
name: typeof
|
|
15
|
-
requiresValue: typeof
|
|
16
|
-
errorMessageForm: typeof
|
|
14
|
+
id: e.id,
|
|
15
|
+
name: typeof e.name == "string" ? e.name : e.id,
|
|
16
|
+
requiresValue: typeof e.requiresValue == "boolean" ? e.requiresValue : r !== void 0,
|
|
17
|
+
errorMessageForm: typeof e.errorMessageForm == "string" ? e.errorMessageForm : ""
|
|
17
18
|
};
|
|
18
19
|
}
|
|
19
|
-
function
|
|
20
|
-
if (!
|
|
20
|
+
function _(e) {
|
|
21
|
+
if (!p(e) || e.isActive !== !0)
|
|
21
22
|
return;
|
|
22
|
-
const
|
|
23
|
-
if (typeof
|
|
23
|
+
const r = e.displayOrder;
|
|
24
|
+
if (typeof r != "number" || !Number.isFinite(r))
|
|
24
25
|
return;
|
|
25
|
-
const
|
|
26
|
-
return
|
|
27
|
-
id: typeof
|
|
26
|
+
const o = typeof e.validationValue == "string" ? e.validationValue : typeof e.validationValue == "number" ? String(e.validationValue) : void 0;
|
|
27
|
+
return F({
|
|
28
|
+
id: typeof e.id == "string" ? e.id : "",
|
|
28
29
|
isActive: !0,
|
|
29
|
-
displayOrder:
|
|
30
|
-
validationType:
|
|
31
|
-
validationValue:
|
|
30
|
+
displayOrder: r,
|
|
31
|
+
validationType: M(e.validationType, o),
|
|
32
|
+
validationValue: o
|
|
32
33
|
});
|
|
33
34
|
}
|
|
34
|
-
function
|
|
35
|
-
|
|
35
|
+
function g(e, r) {
|
|
36
|
+
return e.nullable().defined(r).test(
|
|
37
|
+
"active-validation-value-present",
|
|
38
|
+
r,
|
|
39
|
+
(o) => o != null
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
function U(e, r) {
|
|
43
|
+
if (!A(e))
|
|
36
44
|
return;
|
|
37
|
-
const
|
|
38
|
-
if (
|
|
45
|
+
const o = E(e), l = Array.isArray(e.validations) ? e.validations : [];
|
|
46
|
+
if (l.length === 0 && !o)
|
|
39
47
|
return;
|
|
40
|
-
const
|
|
41
|
-
let
|
|
42
|
-
for (const
|
|
43
|
-
const
|
|
44
|
-
if (!
|
|
48
|
+
const a = v(e), u = l.map(_).filter((t) => t !== void 0).sort((t, n) => t.displayOrder - n.displayOrder);
|
|
49
|
+
let i = a, s = !1, d = r(c.IS_REQUIRED_MESSAGE);
|
|
50
|
+
for (const t of u) {
|
|
51
|
+
const n = t.validationType;
|
|
52
|
+
if (!n)
|
|
45
53
|
continue;
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
+
const f = S[n.id];
|
|
55
|
+
if (f !== void 0) {
|
|
56
|
+
const m = f.apply({
|
|
57
|
+
field: e,
|
|
58
|
+
getLabel: r,
|
|
59
|
+
baseSchema: a,
|
|
60
|
+
schema: i,
|
|
61
|
+
validation: t
|
|
62
|
+
});
|
|
63
|
+
n.id !== "fvl_required" && m !== i && (s || (d = I(
|
|
64
|
+
t,
|
|
65
|
+
r,
|
|
66
|
+
d
|
|
67
|
+
)), s = !0), i = m;
|
|
68
|
+
} else
|
|
69
|
+
console.warn(`Unsupported validation type: ${n.id}`);
|
|
54
70
|
}
|
|
55
|
-
const
|
|
56
|
-
return
|
|
57
|
-
r,
|
|
71
|
+
const V = u.some((t) => t.validationType?.id === "fvl_required");
|
|
72
|
+
return o && !V && (i = R(
|
|
58
73
|
e,
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
74
|
+
i,
|
|
75
|
+
a,
|
|
76
|
+
r(c.IS_REQUIRED_MESSAGE)
|
|
77
|
+
)), o || (a instanceof y.ArraySchema ? i = i.default([]) : s ? i = g(
|
|
78
|
+
i,
|
|
79
|
+
d
|
|
80
|
+
) : i = i.nullable()), i;
|
|
62
81
|
}
|
|
63
82
|
export {
|
|
64
|
-
|
|
83
|
+
U as createFieldValidationSchema
|
|
65
84
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validationStrategies.d.ts","sourceRoot":"","sources":["../../../../../../../../../../packages/components/src/components/DynamicForm/helpers/createFieldValidationSchema/strategies/validation/validationStrategies.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"validationStrategies.d.ts","sourceRoot":"","sources":["../../../../../../../../../../packages/components/src/components/DynamicForm/helpers/createFieldValidationSchema/strategies/validation/validationStrategies.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAkBlD,oGAAoG;AACpG,eAAO,MAAM,0BAA0B,EAAE,kBAwBxC,CAAC;AAEF,2BAA2B;AAC3B,eAAO,MAAM,2BAA2B,EAAE,kBAyBzC,CAAC;AAEF,2BAA2B;AAC3B,eAAO,MAAM,2BAA2B,EAAE,kBAyBzC,CAAC;AAEF,0BAA0B;AAC1B,eAAO,MAAM,qBAAqB,EAAE,kBAyBnC,CAAC;AAEF,0BAA0B;AAC1B,eAAO,MAAM,qBAAqB,EAAE,kBAyBnC,CAAC;AAEF,6BAA6B;AAC7B,eAAO,MAAM,uBAAuB,EAAE,kBAmBrC,CAAC;AAEF,2BAA2B;AAC3B,eAAO,MAAM,qBAAqB,EAAE,kBAmBnC,CAAC;AAEF,8BAA8B;AAC9B,eAAO,MAAM,yBAAyB,EAAE,kBA4BvC,CAAC;AAEF,iEAAiE;AACjE,eAAO,MAAM,wBAAwB,EAAE,kBAkEtC,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,4BAA4B,EAAE,MAAM,CAAC,MAAM,EAAE,kBAAkB,CAU3E,CAAC"}
|