@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,142 +1,150 @@
|
|
|
1
1
|
import * as u from "yup";
|
|
2
|
-
import { DYNAMIC_FORM_DICTIONARY as
|
|
3
|
-
import { resolveValidationErrorMessage as
|
|
4
|
-
import { resolveFieldMandatory as
|
|
5
|
-
import { isDynamicFormDateRangeField as
|
|
6
|
-
import { applyRequiredValidation as
|
|
7
|
-
|
|
2
|
+
import { DYNAMIC_FORM_DICTIONARY as c } from "../../../../dictionary.js";
|
|
3
|
+
import { resolveValidationErrorMessage as d } from "../../../resolveValidationErrorMessage/resolveValidationErrorMessage.js";
|
|
4
|
+
import { resolveFieldMandatory as A, resolveFieldHelperMessage as M } from "../../../resolveFieldContractAliases/resolveFieldContractAliases.js";
|
|
5
|
+
import { isDynamicFormDateRangeField as b } from "../../../isDateRangeField/isDateRangeField.js";
|
|
6
|
+
import { applyRequiredValidation as L } from "../../../applyRequiredValidation/applyRequiredValidation.js";
|
|
7
|
+
function p(o) {
|
|
8
|
+
const a = Number(o);
|
|
9
|
+
return Number.isFinite(a) ? a : void 0;
|
|
10
|
+
}
|
|
11
|
+
function _(o) {
|
|
12
|
+
const a = p(o);
|
|
13
|
+
return a !== void 0 && Number.isInteger(a) && a >= 0 ? a : void 0;
|
|
14
|
+
}
|
|
15
|
+
const S = {
|
|
8
16
|
validationTypeId: "fvl_required",
|
|
9
17
|
/**
|
|
10
18
|
* Applies required validation when the field is required; otherwise returns the schema unchanged.
|
|
11
19
|
* @param ctx - Context with field, getLabel, baseSchema, schema, and validation
|
|
12
20
|
* @returns Schema with required validation applied, or unchanged schema
|
|
13
21
|
*/
|
|
14
|
-
apply(
|
|
15
|
-
const { field: a, getLabel: e, baseSchema:
|
|
16
|
-
if (!
|
|
22
|
+
apply(o) {
|
|
23
|
+
const { field: a, getLabel: e, baseSchema: s, schema: t, validation: r } = o;
|
|
24
|
+
if (!A(a))
|
|
17
25
|
return t;
|
|
18
|
-
const n =
|
|
19
|
-
return
|
|
26
|
+
const n = b(a), l = M(a), m = n && l ? l : e(n ? c.DATE_RANGE_REQUIRED_MESSAGE : c.IS_REQUIRED_MESSAGE), v = d(r, e, m);
|
|
27
|
+
return L(a, t, s, v);
|
|
20
28
|
}
|
|
21
|
-
},
|
|
29
|
+
}, g = {
|
|
22
30
|
validationTypeId: "fvl_max_length",
|
|
23
31
|
/**
|
|
24
32
|
* Applies max length constraint to string schema when validation value is present.
|
|
25
33
|
* @param ctx - Context with field, getLabel, baseSchema, schema, and validation
|
|
26
34
|
* @returns Schema with `.max(length)` applied, or unchanged schema if not applicable
|
|
27
35
|
*/
|
|
28
|
-
apply(
|
|
29
|
-
const { validation: a, getLabel: e, baseSchema:
|
|
30
|
-
if (!
|
|
36
|
+
apply(o) {
|
|
37
|
+
const { validation: a, getLabel: e, baseSchema: s, schema: t } = o, r = a.validationType, i = a.validationValue;
|
|
38
|
+
if (!r?.requiresValue || !i || !(s instanceof u.StringSchema))
|
|
31
39
|
return t;
|
|
32
|
-
const n =
|
|
33
|
-
if (
|
|
40
|
+
const n = _(i);
|
|
41
|
+
if (n === void 0)
|
|
34
42
|
return t;
|
|
35
|
-
const l =
|
|
43
|
+
const l = d(
|
|
36
44
|
a,
|
|
37
45
|
e,
|
|
38
|
-
e(
|
|
46
|
+
e(c.MAX_LENGTH_MESSAGE, n)
|
|
39
47
|
);
|
|
40
48
|
return t.max(n, l);
|
|
41
49
|
}
|
|
42
|
-
},
|
|
50
|
+
}, y = {
|
|
43
51
|
validationTypeId: "fvl_min_length",
|
|
44
52
|
/**
|
|
45
53
|
* Applies min length constraint to string schema when validation value is present.
|
|
46
54
|
* @param ctx - Context with field, getLabel, baseSchema, schema, and validation
|
|
47
55
|
* @returns Schema with `.min(length)` applied, or unchanged schema if not applicable
|
|
48
56
|
*/
|
|
49
|
-
apply(
|
|
50
|
-
const { validation: a, getLabel: e, baseSchema:
|
|
51
|
-
if (!
|
|
57
|
+
apply(o) {
|
|
58
|
+
const { validation: a, getLabel: e, baseSchema: s, schema: t } = o, r = a.validationType, i = a.validationValue;
|
|
59
|
+
if (!r?.requiresValue || !i || !(s instanceof u.StringSchema))
|
|
52
60
|
return t;
|
|
53
|
-
const n =
|
|
54
|
-
if (
|
|
61
|
+
const n = _(i);
|
|
62
|
+
if (n === void 0)
|
|
55
63
|
return t;
|
|
56
|
-
const l =
|
|
64
|
+
const l = d(
|
|
57
65
|
a,
|
|
58
66
|
e,
|
|
59
|
-
e(
|
|
67
|
+
e(c.MIN_LENGTH_MESSAGE, n)
|
|
60
68
|
);
|
|
61
69
|
return t.min(n, l);
|
|
62
70
|
}
|
|
63
|
-
},
|
|
71
|
+
}, f = {
|
|
64
72
|
validationTypeId: "fvl_max",
|
|
65
73
|
/**
|
|
66
74
|
* Applies maximum numeric value constraint when validation value is present.
|
|
67
75
|
* @param ctx - Context with field, getLabel, baseSchema, schema, and validation
|
|
68
76
|
* @returns Schema with `.max(value)` applied, or unchanged schema if not applicable
|
|
69
77
|
*/
|
|
70
|
-
apply(
|
|
71
|
-
const { validation: a, getLabel: e, baseSchema:
|
|
72
|
-
if (!
|
|
78
|
+
apply(o) {
|
|
79
|
+
const { validation: a, getLabel: e, baseSchema: s, schema: t } = o, r = a.validationType, i = a.validationValue;
|
|
80
|
+
if (!r?.requiresValue || !i || !(s instanceof u.NumberSchema))
|
|
73
81
|
return t;
|
|
74
|
-
const n =
|
|
75
|
-
if (
|
|
82
|
+
const n = p(i);
|
|
83
|
+
if (n === void 0)
|
|
76
84
|
return t;
|
|
77
|
-
const l =
|
|
85
|
+
const l = d(
|
|
78
86
|
a,
|
|
79
87
|
e,
|
|
80
|
-
e(
|
|
88
|
+
e(c.MAX_VALUE_MESSAGE, n)
|
|
81
89
|
);
|
|
82
90
|
return t.max(n, l);
|
|
83
91
|
}
|
|
84
|
-
},
|
|
92
|
+
}, I = {
|
|
85
93
|
validationTypeId: "fvl_min",
|
|
86
94
|
/**
|
|
87
95
|
* Applies minimum numeric value constraint when validation value is present.
|
|
88
96
|
* @param ctx - Context with field, getLabel, baseSchema, schema, and validation
|
|
89
97
|
* @returns Schema with `.min(value)` applied, or unchanged schema if not applicable
|
|
90
98
|
*/
|
|
91
|
-
apply(
|
|
92
|
-
const { validation: a, getLabel: e, baseSchema:
|
|
93
|
-
if (!
|
|
99
|
+
apply(o) {
|
|
100
|
+
const { validation: a, getLabel: e, baseSchema: s, schema: t } = o, r = a.validationType, i = a.validationValue;
|
|
101
|
+
if (!r?.requiresValue || !i || !(s instanceof u.NumberSchema))
|
|
94
102
|
return t;
|
|
95
|
-
const n =
|
|
96
|
-
if (
|
|
103
|
+
const n = p(i);
|
|
104
|
+
if (n === void 0)
|
|
97
105
|
return t;
|
|
98
|
-
const l =
|
|
106
|
+
const l = d(
|
|
99
107
|
a,
|
|
100
108
|
e,
|
|
101
|
-
e(
|
|
109
|
+
e(c.MIN_VALUE_MESSAGE, n)
|
|
102
110
|
);
|
|
103
111
|
return t.min(n, l);
|
|
104
112
|
}
|
|
105
|
-
},
|
|
113
|
+
}, V = {
|
|
106
114
|
validationTypeId: "fvl_email",
|
|
107
115
|
/**
|
|
108
116
|
* Applies email format validation to string schema.
|
|
109
117
|
* @param ctx - Context with field, getLabel, baseSchema, schema, and validation
|
|
110
118
|
* @returns Schema with `.email()` applied, or unchanged schema if base is not string
|
|
111
119
|
*/
|
|
112
|
-
apply(
|
|
113
|
-
const { validation: a, getLabel: e, baseSchema:
|
|
114
|
-
if (!(
|
|
120
|
+
apply(o) {
|
|
121
|
+
const { validation: a, getLabel: e, baseSchema: s, schema: t } = o;
|
|
122
|
+
if (!(s instanceof u.StringSchema))
|
|
115
123
|
return t;
|
|
116
|
-
const
|
|
124
|
+
const r = d(
|
|
117
125
|
a,
|
|
118
126
|
e,
|
|
119
|
-
e(
|
|
127
|
+
e(c.EMAIL_INVALID_MESSAGE)
|
|
120
128
|
);
|
|
121
|
-
return t.email(
|
|
129
|
+
return t.email(r).required(r);
|
|
122
130
|
}
|
|
123
|
-
},
|
|
131
|
+
}, h = {
|
|
124
132
|
validationTypeId: "fvl_url",
|
|
125
133
|
/**
|
|
126
134
|
* Applies URL format validation to string schema.
|
|
127
135
|
* @param ctx - Context with field, getLabel, baseSchema, schema, and validation
|
|
128
136
|
* @returns Schema with `.url()` applied, or unchanged schema if base is not string
|
|
129
137
|
*/
|
|
130
|
-
apply(
|
|
131
|
-
const { validation: a, getLabel: e, baseSchema:
|
|
132
|
-
if (!(
|
|
138
|
+
apply(o) {
|
|
139
|
+
const { validation: a, getLabel: e, baseSchema: s, schema: t } = o;
|
|
140
|
+
if (!(s instanceof u.StringSchema))
|
|
133
141
|
return t;
|
|
134
|
-
const
|
|
142
|
+
const r = d(
|
|
135
143
|
a,
|
|
136
144
|
e,
|
|
137
|
-
e(
|
|
145
|
+
e(c.URL_INVALID_MESSAGE)
|
|
138
146
|
);
|
|
139
|
-
return t.url(
|
|
147
|
+
return t.url(r).required(r);
|
|
140
148
|
}
|
|
141
149
|
}, E = {
|
|
142
150
|
validationTypeId: "fvl_pattern",
|
|
@@ -146,94 +154,88 @@ const v = {
|
|
|
146
154
|
* @param ctx - Context with field, getLabel, baseSchema, schema, and validation
|
|
147
155
|
* @returns Schema with `.matches(regex)` applied, or unchanged schema if not applicable
|
|
148
156
|
*/
|
|
149
|
-
apply(
|
|
150
|
-
const { validation: a, getLabel: e, baseSchema:
|
|
151
|
-
if (!
|
|
157
|
+
apply(o) {
|
|
158
|
+
const { validation: a, getLabel: e, baseSchema: s, schema: t } = o, r = a.validationType, i = a.validationValue;
|
|
159
|
+
if (!r?.requiresValue || !i || !(s instanceof u.StringSchema))
|
|
152
160
|
return t;
|
|
153
161
|
try {
|
|
154
|
-
const n = new RegExp(i), l =
|
|
162
|
+
const n = new RegExp(i), l = d(
|
|
155
163
|
a,
|
|
156
164
|
e,
|
|
157
|
-
e(
|
|
165
|
+
e(c.PATTERN_INVALID_MESSAGE)
|
|
158
166
|
);
|
|
159
167
|
return t.matches(n, l);
|
|
160
168
|
} catch (n) {
|
|
161
169
|
return console.warn(`Invalid regex pattern: ${i}`, n), t;
|
|
162
170
|
}
|
|
163
171
|
}
|
|
164
|
-
},
|
|
172
|
+
}, T = {
|
|
165
173
|
validationTypeId: "fvl_custom",
|
|
166
174
|
/**
|
|
167
175
|
* Applies custom validation: for string, regex or exact match; for number, exact value match.
|
|
168
|
-
* When no value is configured,
|
|
176
|
+
* When no value is configured, the rule is skipped because it has no enforceable constraint.
|
|
169
177
|
* @param ctx - Context with field, getLabel, baseSchema, schema, and validation
|
|
170
178
|
* @returns Schema with custom `.test()` applied, or unchanged schema if base type not supported
|
|
171
179
|
*/
|
|
172
|
-
apply(
|
|
173
|
-
const { validation: a, getLabel: e, baseSchema:
|
|
174
|
-
if (
|
|
175
|
-
const l =
|
|
180
|
+
apply(o) {
|
|
181
|
+
const { validation: a, getLabel: e, baseSchema: s, schema: t } = o, r = a.validationType, i = a.validationValue, n = r?.requiresValue === !0 && typeof i == "string" && i.trim() !== "";
|
|
182
|
+
if (s instanceof u.StringSchema) {
|
|
183
|
+
const l = d(
|
|
176
184
|
a,
|
|
177
185
|
e,
|
|
178
|
-
e(
|
|
186
|
+
e(c.CUSTOM_VALIDATION_MESSAGE)
|
|
179
187
|
);
|
|
180
188
|
return n ? t.test(
|
|
181
189
|
"custom",
|
|
182
190
|
l,
|
|
183
|
-
(
|
|
184
|
-
if (
|
|
185
|
-
return !
|
|
191
|
+
(m) => {
|
|
192
|
+
if (m == null)
|
|
193
|
+
return !1;
|
|
186
194
|
try {
|
|
187
|
-
return new RegExp(i).test(
|
|
195
|
+
return new RegExp(i).test(m);
|
|
188
196
|
} catch {
|
|
189
|
-
return
|
|
197
|
+
return m === i;
|
|
190
198
|
}
|
|
191
199
|
}
|
|
192
|
-
) : t
|
|
193
|
-
"custom",
|
|
194
|
-
l,
|
|
195
|
-
(c) => !c || !0
|
|
196
|
-
);
|
|
200
|
+
) : t;
|
|
197
201
|
}
|
|
198
|
-
if (
|
|
199
|
-
const l =
|
|
202
|
+
if (s instanceof u.NumberSchema && n) {
|
|
203
|
+
const l = p(i);
|
|
204
|
+
if (l === void 0)
|
|
205
|
+
return t;
|
|
206
|
+
const m = d(
|
|
200
207
|
a,
|
|
201
208
|
e,
|
|
202
|
-
e(
|
|
209
|
+
e(c.CUSTOM_VALIDATION_MESSAGE)
|
|
203
210
|
);
|
|
204
211
|
return t.test(
|
|
205
212
|
"custom",
|
|
206
|
-
|
|
207
|
-
(
|
|
208
|
-
if (c == null)
|
|
209
|
-
return !0;
|
|
210
|
-
const p = parseFloat(i);
|
|
211
|
-
return isNaN(p) ? !0 : c === p;
|
|
212
|
-
}
|
|
213
|
+
m,
|
|
214
|
+
(v) => v == null ? !1 : v === l
|
|
213
215
|
);
|
|
214
216
|
}
|
|
215
217
|
return t;
|
|
216
218
|
}
|
|
217
|
-
},
|
|
218
|
-
[v.validationTypeId]: v,
|
|
219
|
+
}, q = {
|
|
219
220
|
[S.validationTypeId]: S,
|
|
220
221
|
[g.validationTypeId]: g,
|
|
221
222
|
[y.validationTypeId]: y,
|
|
222
223
|
[f.validationTypeId]: f,
|
|
223
224
|
[I.validationTypeId]: I,
|
|
224
225
|
[V.validationTypeId]: V,
|
|
226
|
+
[h.validationTypeId]: h,
|
|
225
227
|
[E.validationTypeId]: E,
|
|
226
|
-
[
|
|
228
|
+
[T.validationTypeId]: T
|
|
227
229
|
};
|
|
228
230
|
export {
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
231
|
+
q as VALIDATION_STRATEGY_REGISTRY,
|
|
232
|
+
T as customValidationStrategy,
|
|
233
|
+
V as emailValidationStrategy,
|
|
234
|
+
g as maxLengthValidationStrategy,
|
|
235
|
+
f as maxValidationStrategy,
|
|
236
|
+
y as minLengthValidationStrategy,
|
|
237
|
+
I as minValidationStrategy,
|
|
236
238
|
E as patternValidationStrategy,
|
|
237
|
-
|
|
238
|
-
|
|
239
|
+
S as requiredValidationStrategy,
|
|
240
|
+
h as urlValidationStrategy
|
|
239
241
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDynamicForm.d.ts","sourceRoot":"","sources":["../../../../../../../../packages/components/src/components/DynamicForm/hooks/useDynamicForm/useDynamicForm.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,sBAAsB,EAAqB,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"useDynamicForm.d.ts","sourceRoot":"","sources":["../../../../../../../../packages/components/src/components/DynamicForm/hooks/useDynamicForm/useDynamicForm.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,sBAAsB,EAAqB,MAAM,aAAa,CAAC;AA+BxE;;;;;;;;;;GAUG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,sBAAsB;;;EA8H1D"}
|
|
@@ -1,69 +1,73 @@
|
|
|
1
|
-
import { useMemo as
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
|
|
1
|
+
import { useMemo as r } from "react";
|
|
2
|
+
import * as A from "yup";
|
|
3
|
+
import { EMPTY_DATA as S } from "../../constants.js";
|
|
4
|
+
import { createValidationPartialObject as E, createValidationSchema as I, createValidationFullObject as M } from "../../../hook-form/RHFormProvider/schema.js";
|
|
5
|
+
import { useUserPreferences as P, useModuleDictionary as j } from "@m4l/core";
|
|
6
|
+
import { normalizeDynamicFormFields as x, resolveFormSections as O, isSectionField as V } from "../../helpers/resolveFormSections/resolveFormSections.js";
|
|
7
|
+
import { isSupportedInformationalField as b, isSupportedDynamicFormField as Y } from "../../helpers/fieldContractAllowlist/fieldContractAllowlist.js";
|
|
8
|
+
import { resolveInitialValue as Z } from "../../helpers/resolveInitialValue/resolveInitialValue.js";
|
|
9
|
+
import { createFieldValidationSchema as q } from "../../helpers/createFieldValidationSchema/createFieldValidationSchema.js";
|
|
10
|
+
import { evaluateConditionalRule as g } from "../../helpers/evaluateConditionalRule/evaluateConditionalRule.js";
|
|
11
|
+
function y(s, a) {
|
|
11
12
|
return s.some(
|
|
12
|
-
(
|
|
13
|
+
(i) => i.actionType === "show" && g(i, a[i.sourceFieldName]) || i.actionType === "hide" && !g(i, a[i.sourceFieldName])
|
|
13
14
|
);
|
|
14
15
|
}
|
|
15
|
-
function
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
function f() {
|
|
17
|
+
return A.mixed().nullable().notRequired();
|
|
18
|
+
}
|
|
19
|
+
function K(s) {
|
|
20
|
+
const a = P().timeZone ?? null, i = r(
|
|
21
|
+
() => x(s.fields ?? S.fields).fields,
|
|
18
22
|
[s.fields]
|
|
19
|
-
),
|
|
20
|
-
const
|
|
21
|
-
return
|
|
22
|
-
|
|
23
|
-
}),
|
|
24
|
-
}, [
|
|
25
|
-
const
|
|
26
|
-
return
|
|
27
|
-
if (typeof
|
|
23
|
+
), c = s.conditionalRules ?? S.conditionalRules, { ownerByFieldId: h } = r(() => O(i), [i]), { getLabel: F } = j(), v = r(() => {
|
|
24
|
+
const o = {};
|
|
25
|
+
return i.forEach((e) => {
|
|
26
|
+
e.isVisible !== !1 && !V(e) && !b(e) && typeof e.name == "string" && e.name.trim() !== "" && (o[e.name] = Z(e, { timeZone: a }));
|
|
27
|
+
}), o;
|
|
28
|
+
}, [i, a]), C = r(() => {
|
|
29
|
+
const o = E({});
|
|
30
|
+
return i.forEach((e) => {
|
|
31
|
+
if (typeof e.name != "string" || e.name.trim() === "" || V(e) || !Y(e) || b(e))
|
|
28
32
|
return;
|
|
29
|
-
const
|
|
30
|
-
if (!
|
|
33
|
+
const m = q(e, F);
|
|
34
|
+
if (!m)
|
|
31
35
|
return;
|
|
32
|
-
const n =
|
|
33
|
-
if (!
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
+
const n = h.get(e.id), l = n?.isConditional && typeof n.name == "string" ? c.filter((t) => t.isActive && t.targetFieldName === n.name) : [];
|
|
37
|
+
if (!e.isConditional && !n?.isConditional) {
|
|
38
|
+
const t = e.isVisible !== !1 && n?.isVisible !== !1;
|
|
39
|
+
o[e.name] = t ? m : f();
|
|
36
40
|
return;
|
|
37
41
|
}
|
|
38
|
-
const u =
|
|
39
|
-
if (
|
|
40
|
-
|
|
42
|
+
const u = e.isConditional ? c.filter((t) => t.isActive && t.targetFieldName === e.name) : [], d = [...new Set([...u, ...l].map((t) => t.sourceFieldName))];
|
|
43
|
+
if (e.isConditional && u.length === 0 || n?.isConditional && l.length === 0 || d.length === 0) {
|
|
44
|
+
o[e.name] = f();
|
|
41
45
|
return;
|
|
42
46
|
}
|
|
43
|
-
const
|
|
44
|
-
|
|
47
|
+
const w = m.when(
|
|
48
|
+
d,
|
|
45
49
|
{
|
|
46
50
|
/** Returns true when the field is visible (any show rule met or any hide rule not met). */
|
|
47
|
-
is: (
|
|
48
|
-
const
|
|
49
|
-
|
|
50
|
-
|
|
51
|
+
is: (...t) => {
|
|
52
|
+
const p = {};
|
|
53
|
+
d.forEach((T, D) => {
|
|
54
|
+
p[T] = t[D];
|
|
51
55
|
});
|
|
52
|
-
const N =
|
|
53
|
-
return N &&
|
|
56
|
+
const N = e.isConditional ? y(u, p) : e.isVisible !== !1, R = n?.isConditional ? y(l, p) : n?.isVisible !== !1;
|
|
57
|
+
return N && R;
|
|
54
58
|
},
|
|
55
|
-
then: (
|
|
56
|
-
otherwise: (
|
|
59
|
+
then: (t) => t,
|
|
60
|
+
otherwise: () => f()
|
|
57
61
|
}
|
|
58
62
|
);
|
|
59
|
-
|
|
60
|
-
}),
|
|
61
|
-
}, [
|
|
63
|
+
o[e.name] = w;
|
|
64
|
+
}), I(M(o));
|
|
65
|
+
}, [i, c, F, h]);
|
|
62
66
|
return {
|
|
63
|
-
initialValues:
|
|
64
|
-
validationSchema:
|
|
67
|
+
initialValues: v,
|
|
68
|
+
validationSchema: C
|
|
65
69
|
};
|
|
66
70
|
}
|
|
67
71
|
export {
|
|
68
|
-
|
|
72
|
+
K as useDynamicForm
|
|
69
73
|
};
|
|
@@ -14,8 +14,9 @@ export interface UseDynamicFormDataProps {
|
|
|
14
14
|
outputEndpoint?: string;
|
|
15
15
|
/**
|
|
16
16
|
* Submit strategy: `'form'` (default) sends a single request to `outputEndpoint`;
|
|
17
|
-
* `'
|
|
18
|
-
*
|
|
17
|
+
* `'batch'` sends one atomic PATCH to `forms/instances/{instanceId}/values`; and
|
|
18
|
+
* `'perField'` sends one PATCH per field to `forms/instances/{instanceId}/fields/{fieldId}/values`
|
|
19
|
+
* concurrently via `Promise.all` for legacy consumers.
|
|
19
20
|
*/
|
|
20
21
|
submitMode?: DynamicFormSubmitMode;
|
|
21
22
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../../../../../packages/components/src/components/DynamicForm/hooks/useDynamicFormData/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,yCAAyC,CAAC;AACzE,OAAO,EAAE,sBAAsB,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAE5E;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC,qFAAqF;IACrF,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,kFAAkF;IAClF,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,0DAA0D;IAC1D,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,oFAAoF;IACpF,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../../../../../packages/components/src/components/DynamicForm/hooks/useDynamicFormData/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,yCAAyC,CAAC;AACzE,OAAO,EAAE,sBAAsB,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAE5E;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC,qFAAqF;IACrF,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,kFAAkF;IAClF,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,0DAA0D;IAC1D,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,oFAAoF;IACpF,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB;;;;;OAKG;IACH,UAAU,CAAC,EAAE,qBAAqB,CAAC;IACnC;;OAEG;IACH,eAAe,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,sBAAsB,CAAC;IACtG,uFAAuF;IACvF,gBAAgB,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC9E,uEAAuE;IACvE,QAAQ,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACnE,0FAA0F;IAC1F,WAAW,CAAC,EAAE,sBAAsB,GAAG,IAAI,CAAC;CAC7C;AAED;;GAEG;AACH,MAAM,WAAW,wBAAwB;IACvC,yEAAyE;IACzE,QAAQ,EAAE,sBAAsB,GAAG,IAAI,CAAC;IACxC,oEAAoE;IACpE,UAAU,EAAE,cAAc,CAAC;IAC3B,8EAA8E;IAC9E,YAAY,EAAE,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAC/D,2DAA2D;IAC3D,SAAS,EAAE,OAAO,CAAC;CACpB"}
|
|
@@ -6,8 +6,8 @@ import { UseDynamicFormDataProps, UseDynamicFormDataReturn } from './types';
|
|
|
6
6
|
* - Fetch data from inputEndpoint via networkOperation
|
|
7
7
|
* - Apply formatInputData when provided
|
|
8
8
|
* - Manage loading state
|
|
9
|
-
* - Send data to outputEndpoint on submit (submitMode 'form'),
|
|
10
|
-
*
|
|
9
|
+
* - Send data to outputEndpoint on submit (submitMode 'form'), one atomic form-instance PATCH
|
|
10
|
+
* (submitMode 'batch'), or one request per field via Promise.all (submitMode 'perField')
|
|
11
11
|
* - Apply formatOutputData before sending
|
|
12
12
|
* - Serialize objects/arrays to JSON only when the target backend body key expects string payloads
|
|
13
13
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDynamicFormData.d.ts","sourceRoot":"","sources":["../../../../../../../../packages/components/src/components/DynamicForm/hooks/useDynamicFormData/useDynamicFormData.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useDynamicFormData.d.ts","sourceRoot":"","sources":["../../../../../../../../packages/components/src/components/DynamicForm/hooks/useDynamicFormData/useDynamicFormData.ts"],"names":[],"mappings":"AAYA,OAAO,EAAE,uBAAuB,EAAE,wBAAwB,EAAE,MAAM,SAAS,CAAC;AAgB5E;;;;;;;;;;;GAWG;AACH,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,uBAAuB,GAC7B,wBAAwB,CAsO1B"}
|