@rjsf/utils 6.0.0-beta.2 → 6.0.0-beta.20
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/{index.js → index.cjs} +241 -205
- package/dist/index.cjs.map +7 -0
- package/dist/utils.esm.js +240 -204
- package/dist/utils.esm.js.map +4 -4
- package/dist/utils.umd.js +235 -200
- package/lib/canExpand.d.ts +1 -1
- package/lib/constants.d.ts +3 -0
- package/lib/constants.js +3 -0
- package/lib/constants.js.map +1 -1
- package/lib/createSchemaUtils.js +19 -14
- package/lib/createSchemaUtils.js.map +1 -1
- package/lib/enums.d.ts +3 -3
- package/lib/enums.js +3 -3
- package/lib/findSchemaDefinition.d.ts +7 -1
- package/lib/findSchemaDefinition.js +48 -6
- package/lib/findSchemaDefinition.js.map +1 -1
- package/lib/getTestIds.js +2 -2
- package/lib/getTestIds.js.map +1 -1
- package/lib/getUiOptions.js +4 -0
- package/lib/getUiOptions.js.map +1 -1
- package/lib/getWidget.js +3 -3
- package/lib/getWidget.js.map +1 -1
- package/lib/idGenerators.d.ts +15 -15
- package/lib/idGenerators.js +8 -8
- package/lib/idGenerators.js.map +1 -1
- package/lib/index.d.ts +4 -1
- package/lib/index.js +3 -1
- package/lib/index.js.map +1 -1
- package/lib/mergeDefaultsWithFormData.js +14 -2
- package/lib/mergeDefaultsWithFormData.js.map +1 -1
- package/lib/schema/findFieldInSchema.d.ts +1 -1
- package/lib/schema/findFieldInSchema.js +1 -1
- package/lib/schema/getDefaultFormState.d.ts +11 -2
- package/lib/schema/getDefaultFormState.js +59 -22
- package/lib/schema/getDefaultFormState.js.map +1 -1
- package/lib/schema/getDisplayLabel.js +2 -2
- package/lib/schema/getDisplayLabel.js.map +1 -1
- package/lib/schema/index.d.ts +1 -2
- package/lib/schema/index.js +1 -2
- package/lib/schema/index.js.map +1 -1
- package/lib/schema/retrieveSchema.d.ts +1 -1
- package/lib/schema/retrieveSchema.js +6 -6
- package/lib/schema/retrieveSchema.js.map +1 -1
- package/lib/shallowEquals.d.ts +8 -0
- package/lib/shallowEquals.js +36 -0
- package/lib/shallowEquals.js.map +1 -0
- package/lib/shouldRender.d.ts +8 -2
- package/lib/shouldRender.js +17 -2
- package/lib/shouldRender.js.map +1 -1
- package/lib/toFieldPathId.d.ts +12 -0
- package/lib/toFieldPathId.js +19 -0
- package/lib/toFieldPathId.js.map +1 -0
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/types.d.ts +97 -66
- package/package.json +13 -14
- package/src/constants.ts +3 -0
- package/src/createSchemaUtils.ts +19 -25
- package/src/enums.ts +3 -3
- package/src/findSchemaDefinition.ts +55 -6
- package/src/getTestIds.ts +2 -2
- package/src/getUiOptions.ts +4 -0
- package/src/getWidget.tsx +3 -3
- package/src/idGenerators.ts +25 -25
- package/src/index.ts +6 -0
- package/src/mergeDefaultsWithFormData.ts +16 -2
- package/src/schema/findFieldInSchema.ts +1 -1
- package/src/schema/getDefaultFormState.ts +76 -32
- package/src/schema/getDisplayLabel.ts +2 -2
- package/src/schema/index.ts +0 -2
- package/src/schema/retrieveSchema.ts +7 -5
- package/src/shallowEquals.ts +41 -0
- package/src/shouldRender.ts +27 -2
- package/src/toFieldPathId.ts +24 -0
- package/src/types.ts +107 -70
- package/dist/index.js.map +0 -7
- package/lib/schema/toIdSchema.d.ts +0 -14
- package/lib/schema/toIdSchema.js +0 -62
- package/lib/schema/toIdSchema.js.map +0 -1
- package/src/schema/toIdSchema.ts +0 -131
package/dist/utils.esm.js
CHANGED
|
@@ -66,6 +66,8 @@ var REQUIRED_KEY = "required";
|
|
|
66
66
|
var SUBMIT_BTN_OPTIONS_KEY = "submitButtonOptions";
|
|
67
67
|
var REF_KEY = "$ref";
|
|
68
68
|
var SCHEMA_KEY = "$schema";
|
|
69
|
+
var DEFAULT_ID_PREFIX = "root";
|
|
70
|
+
var DEFAULT_ID_SEPARATOR = "_";
|
|
69
71
|
var DISCRIMINATOR_PATH = ["discriminator", "propertyName"];
|
|
70
72
|
var FORM_CONTEXT_NAME = "formContext";
|
|
71
73
|
var LOOKUP_MAP_NAME = "layoutGridLookupMap";
|
|
@@ -75,10 +77,14 @@ var UI_FIELD_KEY = "ui:field";
|
|
|
75
77
|
var UI_WIDGET_KEY = "ui:widget";
|
|
76
78
|
var UI_OPTIONS_KEY = "ui:options";
|
|
77
79
|
var UI_GLOBAL_OPTIONS_KEY = "ui:globalOptions";
|
|
80
|
+
var JSON_SCHEMA_DRAFT_2019_09 = "https://json-schema.org/draft/2019-09/schema";
|
|
78
81
|
var JSON_SCHEMA_DRAFT_2020_12 = "https://json-schema.org/draft/2020-12/schema";
|
|
79
82
|
|
|
80
83
|
// src/getUiOptions.ts
|
|
81
84
|
function getUiOptions(uiSchema = {}, globalOptions = {}) {
|
|
85
|
+
if (!uiSchema) {
|
|
86
|
+
return { ...globalOptions };
|
|
87
|
+
}
|
|
82
88
|
return Object.keys(uiSchema).filter((key) => key.indexOf("ui:") === 0).reduce(
|
|
83
89
|
(options, key) => {
|
|
84
90
|
const value = uiSchema[key];
|
|
@@ -148,15 +154,15 @@ function deepEquals(a, b) {
|
|
|
148
154
|
}
|
|
149
155
|
|
|
150
156
|
// src/schema/findFieldInSchema.ts
|
|
151
|
-
import
|
|
157
|
+
import get8 from "lodash/get";
|
|
152
158
|
import has3 from "lodash/has";
|
|
153
159
|
|
|
154
160
|
// src/schema/findSelectedOptionInXxxOf.ts
|
|
155
|
-
import
|
|
161
|
+
import get6 from "lodash/get";
|
|
156
162
|
import isEqual from "lodash/isEqual";
|
|
157
163
|
|
|
158
164
|
// src/schema/retrieveSchema.ts
|
|
159
|
-
import
|
|
165
|
+
import get5 from "lodash/get";
|
|
160
166
|
import set from "lodash/set";
|
|
161
167
|
import times from "lodash/times";
|
|
162
168
|
import transform from "lodash/transform";
|
|
@@ -171,12 +177,22 @@ import omit from "lodash/omit";
|
|
|
171
177
|
import isObject2 from "lodash/isObject";
|
|
172
178
|
import isEmpty from "lodash/isEmpty";
|
|
173
179
|
import UriResolver from "fast-uri";
|
|
180
|
+
import get from "lodash/get";
|
|
174
181
|
function findEmbeddedSchemaRecursive(schema, ref) {
|
|
175
182
|
if (ID_KEY in schema && UriResolver.equal(schema[ID_KEY], ref)) {
|
|
176
183
|
return schema;
|
|
177
184
|
}
|
|
178
185
|
for (const subSchema of Object.values(schema)) {
|
|
179
|
-
if (
|
|
186
|
+
if (Array.isArray(subSchema)) {
|
|
187
|
+
for (const item of subSchema) {
|
|
188
|
+
if (isObject2(item)) {
|
|
189
|
+
const result = findEmbeddedSchemaRecursive(item, ref);
|
|
190
|
+
if (result !== void 0) {
|
|
191
|
+
return result;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
} else if (isObject2(subSchema)) {
|
|
180
196
|
const result = findEmbeddedSchemaRecursive(subSchema, ref);
|
|
181
197
|
if (result !== void 0) {
|
|
182
198
|
return result;
|
|
@@ -185,12 +201,29 @@ function findEmbeddedSchemaRecursive(schema, ref) {
|
|
|
185
201
|
}
|
|
186
202
|
return void 0;
|
|
187
203
|
}
|
|
204
|
+
function makeAllReferencesAbsolute(schema, baseURI) {
|
|
205
|
+
const currentURI = get(schema, ID_KEY, baseURI);
|
|
206
|
+
if (REF_KEY in schema) {
|
|
207
|
+
schema = { ...schema, [REF_KEY]: UriResolver.resolve(currentURI, schema[REF_KEY]) };
|
|
208
|
+
}
|
|
209
|
+
for (const [key, subSchema] of Object.entries(schema)) {
|
|
210
|
+
if (Array.isArray(subSchema)) {
|
|
211
|
+
schema = {
|
|
212
|
+
...schema,
|
|
213
|
+
[key]: subSchema.map((item) => isObject2(item) ? makeAllReferencesAbsolute(item, currentURI) : item)
|
|
214
|
+
};
|
|
215
|
+
} else if (isObject2(subSchema)) {
|
|
216
|
+
schema = { ...schema, [key]: makeAllReferencesAbsolute(subSchema, currentURI) };
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
return schema;
|
|
220
|
+
}
|
|
188
221
|
function splitKeyElementFromObject(key, object) {
|
|
189
222
|
const value = object[key];
|
|
190
223
|
const remaining = omit(object, [key]);
|
|
191
224
|
return [remaining, value];
|
|
192
225
|
}
|
|
193
|
-
function findSchemaDefinitionRecursive($ref, rootSchema = {}, recurseList = [], baseURI =
|
|
226
|
+
function findSchemaDefinitionRecursive($ref, rootSchema = {}, recurseList = [], baseURI = get(rootSchema, [ID_KEY])) {
|
|
194
227
|
const ref = $ref || "";
|
|
195
228
|
let current = void 0;
|
|
196
229
|
if (ref.startsWith("#")) {
|
|
@@ -230,23 +263,27 @@ function findSchemaDefinitionRecursive($ref, rootSchema = {}, recurseList = [],
|
|
|
230
263
|
const [remaining, theRef] = splitKeyElementFromObject(REF_KEY, current);
|
|
231
264
|
const subSchema = findSchemaDefinitionRecursive(theRef, rootSchema, [...recurseList, ref], baseURI);
|
|
232
265
|
if (Object.keys(remaining).length > 0) {
|
|
233
|
-
|
|
266
|
+
if (rootSchema[SCHEMA_KEY] === JSON_SCHEMA_DRAFT_2019_09 || rootSchema[SCHEMA_KEY] === JSON_SCHEMA_DRAFT_2020_12) {
|
|
267
|
+
return { [ALL_OF_KEY]: [remaining, subSchema] };
|
|
268
|
+
} else {
|
|
269
|
+
return { ...remaining, ...subSchema };
|
|
270
|
+
}
|
|
234
271
|
}
|
|
235
272
|
return subSchema;
|
|
236
273
|
}
|
|
237
274
|
return current;
|
|
238
275
|
}
|
|
239
|
-
function findSchemaDefinition($ref, rootSchema = {}, baseURI =
|
|
276
|
+
function findSchemaDefinition($ref, rootSchema = {}, baseURI = get(rootSchema, [ID_KEY])) {
|
|
240
277
|
const recurseList = [];
|
|
241
278
|
return findSchemaDefinitionRecursive($ref, rootSchema, recurseList, baseURI);
|
|
242
279
|
}
|
|
243
280
|
|
|
244
281
|
// src/getDiscriminatorFieldFromSchema.ts
|
|
245
|
-
import
|
|
282
|
+
import get2 from "lodash/get";
|
|
246
283
|
import isString from "lodash/isString";
|
|
247
284
|
function getDiscriminatorFieldFromSchema(schema) {
|
|
248
285
|
let discriminator;
|
|
249
|
-
const maybeString =
|
|
286
|
+
const maybeString = get2(schema, DISCRIMINATOR_PATH);
|
|
250
287
|
if (isString(maybeString)) {
|
|
251
288
|
discriminator = maybeString;
|
|
252
289
|
} else if (maybeString !== void 0) {
|
|
@@ -320,21 +357,21 @@ function mergeSchemas(obj1, obj2) {
|
|
|
320
357
|
}
|
|
321
358
|
|
|
322
359
|
// src/schema/getFirstMatchingOption.ts
|
|
323
|
-
import
|
|
360
|
+
import get4 from "lodash/get";
|
|
324
361
|
import has from "lodash/has";
|
|
325
362
|
import isNumber from "lodash/isNumber";
|
|
326
363
|
|
|
327
364
|
// src/getOptionMatchingSimpleDiscriminator.ts
|
|
328
|
-
import
|
|
365
|
+
import get3 from "lodash/get";
|
|
329
366
|
function getOptionMatchingSimpleDiscriminator(formData, options, discriminatorField) {
|
|
330
367
|
if (formData && discriminatorField) {
|
|
331
|
-
const value =
|
|
368
|
+
const value = get3(formData, discriminatorField);
|
|
332
369
|
if (value === void 0) {
|
|
333
370
|
return;
|
|
334
371
|
}
|
|
335
372
|
for (let i = 0; i < options.length; i++) {
|
|
336
373
|
const option = options[i];
|
|
337
|
-
const discriminator =
|
|
374
|
+
const discriminator = get3(option, [PROPERTIES_KEY, discriminatorField], {});
|
|
338
375
|
if (discriminator.type === "object" || discriminator.type === "array") {
|
|
339
376
|
continue;
|
|
340
377
|
}
|
|
@@ -361,8 +398,8 @@ function getFirstMatchingOption(validator, formData, options, rootSchema, discri
|
|
|
361
398
|
for (let i = 0; i < options.length; i++) {
|
|
362
399
|
const option = options[i];
|
|
363
400
|
if (discriminatorField && has(option, [PROPERTIES_KEY, discriminatorField])) {
|
|
364
|
-
const value =
|
|
365
|
-
const discriminator =
|
|
401
|
+
const value = get4(formData, discriminatorField);
|
|
402
|
+
const discriminator = get4(option, [PROPERTIES_KEY, discriminatorField], {});
|
|
366
403
|
if (validator.isValid(discriminator, value, rootSchema)) {
|
|
367
404
|
return i;
|
|
368
405
|
}
|
|
@@ -502,7 +539,8 @@ function resolveSchema(validator, schema, rootSchema, expandAllBranches, recurse
|
|
|
502
539
|
rootSchema,
|
|
503
540
|
expandAllBranches,
|
|
504
541
|
recurseList,
|
|
505
|
-
formData
|
|
542
|
+
formData,
|
|
543
|
+
experimental_customMergeAllOf
|
|
506
544
|
);
|
|
507
545
|
if (updatedSchemas.length > 1 || updatedSchemas[0] !== schema) {
|
|
508
546
|
return updatedSchemas;
|
|
@@ -514,7 +552,8 @@ function resolveSchema(validator, schema, rootSchema, expandAllBranches, recurse
|
|
|
514
552
|
rootSchema,
|
|
515
553
|
expandAllBranches,
|
|
516
554
|
recurseList,
|
|
517
|
-
formData
|
|
555
|
+
formData,
|
|
556
|
+
experimental_customMergeAllOf
|
|
518
557
|
);
|
|
519
558
|
return resolvedSchemas.flatMap((s) => {
|
|
520
559
|
return retrieveSchemaInternal(
|
|
@@ -617,9 +656,9 @@ function stubExistingAdditionalProperties(validator, theSchema, rootSchema, aFor
|
|
|
617
656
|
if (!isEmpty2(matchingProperties)) {
|
|
618
657
|
schema.properties[key] = retrieveSchema(
|
|
619
658
|
validator,
|
|
620
|
-
{
|
|
659
|
+
{ [ALL_OF_KEY]: Object.values(matchingProperties) },
|
|
621
660
|
rootSchema,
|
|
622
|
-
formData,
|
|
661
|
+
get5(formData, [key]),
|
|
623
662
|
experimental_customMergeAllOf
|
|
624
663
|
);
|
|
625
664
|
set(schema.properties, [key, ADDITIONAL_PROPERTY_FLAG], true);
|
|
@@ -632,7 +671,7 @@ function stubExistingAdditionalProperties(validator, theSchema, rootSchema, aFor
|
|
|
632
671
|
if (REF_KEY in schema.additionalProperties) {
|
|
633
672
|
additionalProperties = retrieveSchema(
|
|
634
673
|
validator,
|
|
635
|
-
{
|
|
674
|
+
{ [REF_KEY]: get5(schema.additionalProperties, [REF_KEY]) },
|
|
636
675
|
rootSchema,
|
|
637
676
|
formData,
|
|
638
677
|
experimental_customMergeAllOf
|
|
@@ -645,10 +684,10 @@ function stubExistingAdditionalProperties(validator, theSchema, rootSchema, aFor
|
|
|
645
684
|
...schema.additionalProperties
|
|
646
685
|
};
|
|
647
686
|
} else {
|
|
648
|
-
additionalProperties = { type: guessType(
|
|
687
|
+
additionalProperties = { type: guessType(get5(formData, [key])) };
|
|
649
688
|
}
|
|
650
689
|
} else {
|
|
651
|
-
additionalProperties = { type: guessType(
|
|
690
|
+
additionalProperties = { type: guessType(get5(formData, [key])) };
|
|
652
691
|
}
|
|
653
692
|
schema.properties[key] = additionalProperties;
|
|
654
693
|
set(schema.properties, [key, ADDITIONAL_PROPERTY_FLAG], true);
|
|
@@ -727,7 +766,7 @@ function retrieveSchemaInternal(validator, schema, rootSchema, rawFormData, expa
|
|
|
727
766
|
validator,
|
|
728
767
|
{ allOf: [schema2.properties[key], ...Object.values(matchingProperties)] },
|
|
729
768
|
rootSchema,
|
|
730
|
-
rawFormData,
|
|
769
|
+
get5(rawFormData, [key]),
|
|
731
770
|
experimental_customMergeAllOf
|
|
732
771
|
);
|
|
733
772
|
}
|
|
@@ -799,7 +838,7 @@ function resolveDependencies(validator, schema, rootSchema, expandAllBranches, r
|
|
|
799
838
|
function processDependencies(validator, dependencies, resolvedSchema, rootSchema, expandAllBranches, recurseList, formData, experimental_customMergeAllOf) {
|
|
800
839
|
let schemas = [resolvedSchema];
|
|
801
840
|
for (const dependencyKey in dependencies) {
|
|
802
|
-
if (!expandAllBranches &&
|
|
841
|
+
if (!expandAllBranches && get5(formData, [dependencyKey]) === void 0) {
|
|
803
842
|
continue;
|
|
804
843
|
}
|
|
805
844
|
if (resolvedSchema.properties && !(dependencyKey in resolvedSchema.properties)) {
|
|
@@ -930,11 +969,11 @@ function findSelectedOptionInXxxOf(validator, rootSchema, schema, fallbackField,
|
|
|
930
969
|
const xxxOfs = schema[xxx].map(
|
|
931
970
|
(xxxOf) => retrieveSchema(validator, xxxOf, rootSchema, formData, experimental_customMergeAllOf)
|
|
932
971
|
);
|
|
933
|
-
const data =
|
|
972
|
+
const data = get6(formData, selectorField);
|
|
934
973
|
if (data !== void 0) {
|
|
935
974
|
return xxxOfs.find((xxx2) => {
|
|
936
975
|
return isEqual(
|
|
937
|
-
|
|
976
|
+
get6(xxx2, [PROPERTIES_KEY, selectorField, DEFAULT_KEY], get6(xxx2, [PROPERTIES_KEY, selectorField, CONST_KEY])),
|
|
938
977
|
data
|
|
939
978
|
);
|
|
940
979
|
});
|
|
@@ -944,7 +983,7 @@ function findSelectedOptionInXxxOf(validator, rootSchema, schema, fallbackField,
|
|
|
944
983
|
}
|
|
945
984
|
|
|
946
985
|
// src/schema/getFromSchema.ts
|
|
947
|
-
import
|
|
986
|
+
import get7 from "lodash/get";
|
|
948
987
|
import has2 from "lodash/has";
|
|
949
988
|
import isEmpty3 from "lodash/isEmpty";
|
|
950
989
|
function getFromSchemaInternal(validator, rootSchema, schema, path, experimental_customMergeAllOf) {
|
|
@@ -958,7 +997,7 @@ function getFromSchemaInternal(validator, rootSchema, schema, path, experimental
|
|
|
958
997
|
const pathList = Array.isArray(path) ? path : path.split(".");
|
|
959
998
|
const [part, ...nestedPath] = pathList;
|
|
960
999
|
if (part && has2(fieldSchema, part)) {
|
|
961
|
-
fieldSchema =
|
|
1000
|
+
fieldSchema = get7(fieldSchema, part);
|
|
962
1001
|
return getFromSchemaInternal(
|
|
963
1002
|
validator,
|
|
964
1003
|
rootSchema,
|
|
@@ -1000,7 +1039,7 @@ function findFieldInSchema(validator, rootSchema, schema, path, formData = {}, e
|
|
|
1000
1039
|
parentField,
|
|
1001
1040
|
fieldName,
|
|
1002
1041
|
ONE_OF_KEY,
|
|
1003
|
-
|
|
1042
|
+
get8(formData, subPath),
|
|
1004
1043
|
experimental_customMergeAllOf
|
|
1005
1044
|
);
|
|
1006
1045
|
} else if (has3(parentField, ANY_OF_KEY)) {
|
|
@@ -1010,7 +1049,7 @@ function findFieldInSchema(validator, rootSchema, schema, path, formData = {}, e
|
|
|
1010
1049
|
parentField,
|
|
1011
1050
|
fieldName,
|
|
1012
1051
|
ANY_OF_KEY,
|
|
1013
|
-
|
|
1052
|
+
get8(formData, subPath),
|
|
1014
1053
|
experimental_customMergeAllOf
|
|
1015
1054
|
);
|
|
1016
1055
|
}
|
|
@@ -1064,11 +1103,11 @@ function findFieldInSchema(validator, rootSchema, schema, path, formData = {}, e
|
|
|
1064
1103
|
}
|
|
1065
1104
|
|
|
1066
1105
|
// src/schema/getDefaultFormState.ts
|
|
1067
|
-
import
|
|
1106
|
+
import get12 from "lodash/get";
|
|
1068
1107
|
import isEmpty4 from "lodash/isEmpty";
|
|
1069
1108
|
|
|
1070
1109
|
// src/schema/getClosestMatchingOption.ts
|
|
1071
|
-
import
|
|
1110
|
+
import get9 from "lodash/get";
|
|
1072
1111
|
import has4 from "lodash/has";
|
|
1073
1112
|
import isNumber2 from "lodash/isNumber";
|
|
1074
1113
|
import isObject3 from "lodash/isObject";
|
|
@@ -1091,7 +1130,7 @@ function calculateIndexScore(validator, rootSchema, schema, formData, experiment
|
|
|
1091
1130
|
totalScore += reduce(
|
|
1092
1131
|
schema.properties,
|
|
1093
1132
|
(score, value, key) => {
|
|
1094
|
-
const formValue =
|
|
1133
|
+
const formValue = get9(formData, key);
|
|
1095
1134
|
if (typeof value === "boolean") {
|
|
1096
1135
|
return score;
|
|
1097
1136
|
}
|
|
@@ -1118,7 +1157,7 @@ function calculateIndexScore(validator, rootSchema, schema, formData, experiment
|
|
|
1118
1157
|
validator,
|
|
1119
1158
|
rootSchema,
|
|
1120
1159
|
formValue,
|
|
1121
|
-
|
|
1160
|
+
get9(value, key2),
|
|
1122
1161
|
-1,
|
|
1123
1162
|
discriminator,
|
|
1124
1163
|
experimental_customMergeAllOf
|
|
@@ -1197,7 +1236,7 @@ function isFixedItems(schema) {
|
|
|
1197
1236
|
}
|
|
1198
1237
|
|
|
1199
1238
|
// src/mergeDefaultsWithFormData.ts
|
|
1200
|
-
import
|
|
1239
|
+
import get10 from "lodash/get";
|
|
1201
1240
|
import isNil from "lodash/isNil";
|
|
1202
1241
|
function mergeDefaultsWithFormData(defaults, formData, mergeExtraArrayDefaults = false, defaultSupercedesUndefined = false, overrideFormDataWithDefaults = false) {
|
|
1203
1242
|
if (Array.isArray(formData)) {
|
|
@@ -1224,11 +1263,22 @@ function mergeDefaultsWithFormData(defaults, formData, mergeExtraArrayDefaults =
|
|
|
1224
1263
|
if (isObject(formData)) {
|
|
1225
1264
|
const acc = Object.assign({}, defaults);
|
|
1226
1265
|
return Object.keys(formData).reduce((acc2, key) => {
|
|
1227
|
-
const keyValue =
|
|
1266
|
+
const keyValue = get10(formData, key);
|
|
1228
1267
|
const keyExistsInDefaults = isObject(defaults) && key in defaults;
|
|
1229
1268
|
const keyExistsInFormData = key in formData;
|
|
1269
|
+
const keyDefault = get10(defaults, key) ?? {};
|
|
1270
|
+
const defaultValueIsNestedObject = keyExistsInDefaults && Object.entries(keyDefault).some(([, v]) => isObject(v));
|
|
1271
|
+
const keyDefaultIsObject = keyExistsInDefaults && isObject(get10(defaults, key));
|
|
1272
|
+
const keyHasFormDataObject = keyExistsInFormData && isObject(keyValue);
|
|
1273
|
+
if (keyDefaultIsObject && keyHasFormDataObject && !defaultValueIsNestedObject) {
|
|
1274
|
+
acc2[key] = {
|
|
1275
|
+
...get10(defaults, key),
|
|
1276
|
+
...keyValue
|
|
1277
|
+
};
|
|
1278
|
+
return acc2;
|
|
1279
|
+
}
|
|
1230
1280
|
acc2[key] = mergeDefaultsWithFormData(
|
|
1231
|
-
|
|
1281
|
+
get10(defaults, key),
|
|
1232
1282
|
keyValue,
|
|
1233
1283
|
mergeExtraArrayDefaults,
|
|
1234
1284
|
defaultSupercedesUndefined,
|
|
@@ -1239,7 +1289,7 @@ function mergeDefaultsWithFormData(defaults, formData, mergeExtraArrayDefaults =
|
|
|
1239
1289
|
return acc2;
|
|
1240
1290
|
}, acc);
|
|
1241
1291
|
}
|
|
1242
|
-
if (defaultSupercedesUndefined && (!
|
|
1292
|
+
if (defaultSupercedesUndefined && (!(defaults === void 0) && isNil(formData) || typeof formData === "number" && isNaN(formData)) || overrideFormDataWithDefaults && !isNil(formData)) {
|
|
1243
1293
|
return defaults;
|
|
1244
1294
|
}
|
|
1245
1295
|
return formData;
|
|
@@ -1307,7 +1357,7 @@ function constIsAjvDataReference(schema) {
|
|
|
1307
1357
|
}
|
|
1308
1358
|
|
|
1309
1359
|
// src/optionsList.ts
|
|
1310
|
-
import
|
|
1360
|
+
import get11 from "lodash/get";
|
|
1311
1361
|
|
|
1312
1362
|
// src/toConstant.ts
|
|
1313
1363
|
function toConstant(schema) {
|
|
@@ -1353,8 +1403,8 @@ function optionsList(schema, uiSchema) {
|
|
|
1353
1403
|
let value;
|
|
1354
1404
|
let label = title;
|
|
1355
1405
|
if (selectorField) {
|
|
1356
|
-
const innerSchema =
|
|
1357
|
-
value =
|
|
1406
|
+
const innerSchema = get11(aSchema, [PROPERTIES_KEY, selectorField], {});
|
|
1407
|
+
value = get11(innerSchema, DEFAULT_KEY, get11(innerSchema, CONST_KEY));
|
|
1358
1408
|
label = label || innerSchema?.title || aSchema.title || String(value);
|
|
1359
1409
|
} else {
|
|
1360
1410
|
value = toConstant(aSchema);
|
|
@@ -1386,10 +1436,19 @@ function getInnerSchemaForArrayItem(schema, additionalItems = 0 /* Ignore */, id
|
|
|
1386
1436
|
}
|
|
1387
1437
|
return {};
|
|
1388
1438
|
}
|
|
1439
|
+
function computeDefaultBasedOnSchemaTypeAndDefaults(schema, computedDefault) {
|
|
1440
|
+
const { default: schemaDefault, type } = schema;
|
|
1441
|
+
const shouldReturnNullAsDefault = Array.isArray(type) && type.includes("null") && isEmpty4(computedDefault) && schemaDefault === null;
|
|
1442
|
+
return shouldReturnNullAsDefault ? null : computedDefault;
|
|
1443
|
+
}
|
|
1389
1444
|
function maybeAddDefaultToObject(obj, key, computedDefault, includeUndefinedValues, isParentRequired, requiredFields = [], experimental_defaultFormStateBehavior = {}, isConst = false) {
|
|
1390
1445
|
const { emptyObjectFields = "populateAllDefaults" } = experimental_defaultFormStateBehavior;
|
|
1391
|
-
if (includeUndefinedValues || isConst) {
|
|
1446
|
+
if (includeUndefinedValues === true || isConst) {
|
|
1392
1447
|
obj[key] = computedDefault;
|
|
1448
|
+
} else if (includeUndefinedValues === "excludeObjectChildren") {
|
|
1449
|
+
if (!isObject(computedDefault) || !isEmpty4(computedDefault)) {
|
|
1450
|
+
obj[key] = computedDefault;
|
|
1451
|
+
}
|
|
1393
1452
|
} else if (emptyObjectFields !== "skipDefaults") {
|
|
1394
1453
|
const isSelfOrParentRequired = isParentRequired === void 0 ? requiredFields.includes(key) : isParentRequired;
|
|
1395
1454
|
if (isObject(computedDefault)) {
|
|
@@ -1423,13 +1482,13 @@ function computeDefaults(validator, rawSchema, computeDefaultsProps = {}) {
|
|
|
1423
1482
|
required,
|
|
1424
1483
|
shouldMergeDefaultsIntoFormData = false
|
|
1425
1484
|
} = computeDefaultsProps;
|
|
1426
|
-
|
|
1485
|
+
let formData = isObject(rawFormData) ? rawFormData : {};
|
|
1427
1486
|
const schema = isObject(rawSchema) ? rawSchema : {};
|
|
1428
1487
|
let defaults = parentDefaults;
|
|
1429
1488
|
let schemaToCompute = null;
|
|
1430
1489
|
let experimental_dfsb_to_compute = experimental_defaultFormStateBehavior;
|
|
1431
1490
|
let updatedRecurseList = _recurseList;
|
|
1432
|
-
if (schema[CONST_KEY] && experimental_defaultFormStateBehavior?.constAsDefaults !== "never" && !constIsAjvDataReference(schema)) {
|
|
1491
|
+
if (schema[CONST_KEY] !== void 0 && experimental_defaultFormStateBehavior?.constAsDefaults !== "never" && !constIsAjvDataReference(schema)) {
|
|
1433
1492
|
defaults = schema[CONST_KEY];
|
|
1434
1493
|
} else if (isObject(defaults) && isObject(schema.default)) {
|
|
1435
1494
|
defaults = mergeObjects(defaults, schema.default);
|
|
@@ -1444,6 +1503,9 @@ function computeDefaults(validator, rawSchema, computeDefaultsProps = {}) {
|
|
|
1444
1503
|
if (schemaToCompute && !defaults) {
|
|
1445
1504
|
defaults = schema.default;
|
|
1446
1505
|
}
|
|
1506
|
+
if (shouldMergeDefaultsIntoFormData && schemaToCompute && !isObject(rawFormData)) {
|
|
1507
|
+
formData = rawFormData;
|
|
1508
|
+
}
|
|
1447
1509
|
} else if (DEPENDENCIES_KEY in schema) {
|
|
1448
1510
|
const defaultFormData = {
|
|
1449
1511
|
...getDefaultBasedOnSchemaType(validator, schema, computeDefaultsProps, defaults),
|
|
@@ -1521,7 +1583,7 @@ function computeDefaults(validator, rawSchema, computeDefaultsProps = {}) {
|
|
|
1521
1583
|
experimental_defaultFormStateBehavior: experimental_dfsb_to_compute,
|
|
1522
1584
|
experimental_customMergeAllOf,
|
|
1523
1585
|
parentDefaults: defaults,
|
|
1524
|
-
rawFormData: formData,
|
|
1586
|
+
rawFormData: rawFormData ?? formData,
|
|
1525
1587
|
required,
|
|
1526
1588
|
shouldMergeDefaultsIntoFormData
|
|
1527
1589
|
});
|
|
@@ -1584,7 +1646,7 @@ function getObjectDefaults(validator, rawSchema, {
|
|
|
1584
1646
|
const parentConst = retrievedSchema[CONST_KEY];
|
|
1585
1647
|
const objectDefaults = Object.keys(retrievedSchema.properties || {}).reduce(
|
|
1586
1648
|
(acc, key) => {
|
|
1587
|
-
const propertySchema =
|
|
1649
|
+
const propertySchema = get12(retrievedSchema, [PROPERTIES_KEY, key], {});
|
|
1588
1650
|
const hasParentConst = isObject(parentConst) && parentConst[key] !== void 0;
|
|
1589
1651
|
const hasConst = (isObject(propertySchema) && CONST_KEY in propertySchema || hasParentConst) && experimental_defaultFormStateBehavior?.constAsDefaults !== "never" && !constIsAjvDataReference(propertySchema);
|
|
1590
1652
|
const computedDefault = computeDefaults(validator, propertySchema, {
|
|
@@ -1593,8 +1655,8 @@ function getObjectDefaults(validator, rawSchema, {
|
|
|
1593
1655
|
experimental_defaultFormStateBehavior,
|
|
1594
1656
|
experimental_customMergeAllOf,
|
|
1595
1657
|
includeUndefinedValues: includeUndefinedValues === true,
|
|
1596
|
-
parentDefaults:
|
|
1597
|
-
rawFormData:
|
|
1658
|
+
parentDefaults: get12(defaults, [key]),
|
|
1659
|
+
rawFormData: get12(formData, [key]),
|
|
1598
1660
|
required: retrievedSchema.required?.includes(key),
|
|
1599
1661
|
shouldMergeDefaultsIntoFormData
|
|
1600
1662
|
});
|
|
@@ -1630,8 +1692,8 @@ function getObjectDefaults(validator, rawSchema, {
|
|
|
1630
1692
|
experimental_defaultFormStateBehavior,
|
|
1631
1693
|
experimental_customMergeAllOf,
|
|
1632
1694
|
includeUndefinedValues: includeUndefinedValues === true,
|
|
1633
|
-
parentDefaults:
|
|
1634
|
-
rawFormData:
|
|
1695
|
+
parentDefaults: get12(defaults, [key]),
|
|
1696
|
+
rawFormData: get12(formData, [key]),
|
|
1635
1697
|
required: retrievedSchema.required?.includes(key),
|
|
1636
1698
|
shouldMergeDefaultsIntoFormData
|
|
1637
1699
|
});
|
|
@@ -1645,7 +1707,7 @@ function getObjectDefaults(validator, rawSchema, {
|
|
|
1645
1707
|
);
|
|
1646
1708
|
});
|
|
1647
1709
|
}
|
|
1648
|
-
return objectDefaults;
|
|
1710
|
+
return computeDefaultBasedOnSchemaTypeAndDefaults(rawSchema, objectDefaults);
|
|
1649
1711
|
}
|
|
1650
1712
|
}
|
|
1651
1713
|
function getArrayDefaults(validator, rawSchema, {
|
|
@@ -1692,7 +1754,7 @@ function getArrayDefaults(validator, rawSchema, {
|
|
|
1692
1754
|
experimental_defaultFormStateBehavior,
|
|
1693
1755
|
experimental_customMergeAllOf,
|
|
1694
1756
|
rawFormData: item,
|
|
1695
|
-
parentDefaults:
|
|
1757
|
+
parentDefaults: get12(defaults, [idx]),
|
|
1696
1758
|
required,
|
|
1697
1759
|
shouldMergeDefaultsIntoFormData
|
|
1698
1760
|
});
|
|
@@ -1710,25 +1772,29 @@ function getArrayDefaults(validator, rawSchema, {
|
|
|
1710
1772
|
return defaults ? defaults : void 0;
|
|
1711
1773
|
}
|
|
1712
1774
|
}
|
|
1775
|
+
let arrayDefault;
|
|
1713
1776
|
const defaultsLength = Array.isArray(defaults) ? defaults.length : 0;
|
|
1714
1777
|
if (!schema.minItems || isMultiSelect(validator, schema, rootSchema, experimental_customMergeAllOf) || computeSkipPopulate(validator, schema, rootSchema) || schema.minItems <= defaultsLength) {
|
|
1715
|
-
|
|
1716
|
-
}
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1778
|
+
arrayDefault = defaults ? defaults : emptyDefault;
|
|
1779
|
+
} else {
|
|
1780
|
+
const defaultEntries = defaults || [];
|
|
1781
|
+
const fillerSchema = getInnerSchemaForArrayItem(schema, 1 /* Invert */);
|
|
1782
|
+
const fillerDefault = fillerSchema.default;
|
|
1783
|
+
const fillerEntries = Array.from(
|
|
1784
|
+
{ length: schema.minItems - defaultsLength },
|
|
1785
|
+
() => computeDefaults(validator, fillerSchema, {
|
|
1786
|
+
parentDefaults: fillerDefault,
|
|
1787
|
+
rootSchema,
|
|
1788
|
+
_recurseList,
|
|
1789
|
+
experimental_defaultFormStateBehavior,
|
|
1790
|
+
experimental_customMergeAllOf,
|
|
1791
|
+
required,
|
|
1792
|
+
shouldMergeDefaultsIntoFormData
|
|
1793
|
+
})
|
|
1794
|
+
);
|
|
1795
|
+
arrayDefault = defaultEntries.concat(fillerEntries);
|
|
1796
|
+
}
|
|
1797
|
+
return computeDefaultBasedOnSchemaTypeAndDefaults(rawSchema, arrayDefault);
|
|
1732
1798
|
}
|
|
1733
1799
|
function getDefaultBasedOnSchemaType(validator, rawSchema, computeDefaultsProps = {}, defaults) {
|
|
1734
1800
|
switch (getSchemaType(rawSchema)) {
|
|
@@ -1754,6 +1820,12 @@ function getDefaultFormState(validator, theSchema, formData, rootSchema, include
|
|
|
1754
1820
|
rawFormData: formData,
|
|
1755
1821
|
shouldMergeDefaultsIntoFormData: true
|
|
1756
1822
|
});
|
|
1823
|
+
if (schema.type !== "object" && isObject(schema.default)) {
|
|
1824
|
+
return {
|
|
1825
|
+
...defaults,
|
|
1826
|
+
...formData
|
|
1827
|
+
};
|
|
1828
|
+
}
|
|
1757
1829
|
if (isObject(formData) || Array.isArray(formData)) {
|
|
1758
1830
|
const { mergeDefaultsIntoFormData } = experimental_defaultFormStateBehavior || {};
|
|
1759
1831
|
const defaultSupercedesUndefined = mergeDefaultsIntoFormData === "useDefaultIfFormDataUndefined";
|
|
@@ -1810,17 +1882,17 @@ function getDisplayLabel(validator, schema, uiSchema = {}, rootSchema, globalOpt
|
|
|
1810
1882
|
if (schemaType === "object") {
|
|
1811
1883
|
displayLabel = false;
|
|
1812
1884
|
}
|
|
1813
|
-
if (schemaType === "boolean" && !uiSchema[UI_WIDGET_KEY]) {
|
|
1885
|
+
if (schemaType === "boolean" && uiSchema && !uiSchema[UI_WIDGET_KEY]) {
|
|
1814
1886
|
displayLabel = false;
|
|
1815
1887
|
}
|
|
1816
|
-
if (uiSchema[UI_FIELD_KEY]) {
|
|
1888
|
+
if (uiSchema && uiSchema[UI_FIELD_KEY]) {
|
|
1817
1889
|
displayLabel = false;
|
|
1818
1890
|
}
|
|
1819
1891
|
return displayLabel;
|
|
1820
1892
|
}
|
|
1821
1893
|
|
|
1822
1894
|
// src/schema/sanitizeDataForNewSchema.ts
|
|
1823
|
-
import
|
|
1895
|
+
import get13 from "lodash/get";
|
|
1824
1896
|
import has5 from "lodash/has";
|
|
1825
1897
|
var NO_VALUE = Symbol("no Value");
|
|
1826
1898
|
function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, data = {}, experimental_customMergeAllOf) {
|
|
@@ -1828,19 +1900,19 @@ function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, d
|
|
|
1828
1900
|
if (has5(newSchema, PROPERTIES_KEY)) {
|
|
1829
1901
|
const removeOldSchemaData = {};
|
|
1830
1902
|
if (has5(oldSchema, PROPERTIES_KEY)) {
|
|
1831
|
-
const properties =
|
|
1903
|
+
const properties = get13(oldSchema, PROPERTIES_KEY, {});
|
|
1832
1904
|
Object.keys(properties).forEach((key) => {
|
|
1833
1905
|
if (has5(data, key)) {
|
|
1834
1906
|
removeOldSchemaData[key] = void 0;
|
|
1835
1907
|
}
|
|
1836
1908
|
});
|
|
1837
1909
|
}
|
|
1838
|
-
const keys2 = Object.keys(
|
|
1910
|
+
const keys2 = Object.keys(get13(newSchema, PROPERTIES_KEY, {}));
|
|
1839
1911
|
const nestedData = {};
|
|
1840
1912
|
keys2.forEach((key) => {
|
|
1841
|
-
const formValue =
|
|
1842
|
-
let oldKeyedSchema =
|
|
1843
|
-
let newKeyedSchema =
|
|
1913
|
+
const formValue = get13(data, key);
|
|
1914
|
+
let oldKeyedSchema = get13(oldSchema, [PROPERTIES_KEY, key], {});
|
|
1915
|
+
let newKeyedSchema = get13(newSchema, [PROPERTIES_KEY, key], {});
|
|
1844
1916
|
if (has5(oldKeyedSchema, REF_KEY)) {
|
|
1845
1917
|
oldKeyedSchema = retrieveSchema(
|
|
1846
1918
|
validator,
|
|
@@ -1859,8 +1931,8 @@ function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, d
|
|
|
1859
1931
|
experimental_customMergeAllOf
|
|
1860
1932
|
);
|
|
1861
1933
|
}
|
|
1862
|
-
const oldSchemaTypeForKey =
|
|
1863
|
-
const newSchemaTypeForKey =
|
|
1934
|
+
const oldSchemaTypeForKey = get13(oldKeyedSchema, "type");
|
|
1935
|
+
const newSchemaTypeForKey = get13(newKeyedSchema, "type");
|
|
1864
1936
|
if (!oldSchemaTypeForKey || oldSchemaTypeForKey === newSchemaTypeForKey) {
|
|
1865
1937
|
if (has5(removeOldSchemaData, key)) {
|
|
1866
1938
|
delete removeOldSchemaData[key];
|
|
@@ -1878,17 +1950,17 @@ function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, d
|
|
|
1878
1950
|
nestedData[key] = itemData;
|
|
1879
1951
|
}
|
|
1880
1952
|
} else {
|
|
1881
|
-
const newOptionDefault =
|
|
1882
|
-
const oldOptionDefault =
|
|
1953
|
+
const newOptionDefault = get13(newKeyedSchema, "default", NO_VALUE);
|
|
1954
|
+
const oldOptionDefault = get13(oldKeyedSchema, "default", NO_VALUE);
|
|
1883
1955
|
if (newOptionDefault !== NO_VALUE && newOptionDefault !== formValue) {
|
|
1884
1956
|
if (oldOptionDefault === formValue) {
|
|
1885
1957
|
removeOldSchemaData[key] = newOptionDefault;
|
|
1886
|
-
} else if (
|
|
1958
|
+
} else if (get13(newKeyedSchema, "readOnly") === true) {
|
|
1887
1959
|
removeOldSchemaData[key] = void 0;
|
|
1888
1960
|
}
|
|
1889
1961
|
}
|
|
1890
|
-
const newOptionConst =
|
|
1891
|
-
const oldOptionConst =
|
|
1962
|
+
const newOptionConst = get13(newKeyedSchema, "const", NO_VALUE);
|
|
1963
|
+
const oldOptionConst = get13(oldKeyedSchema, "const", NO_VALUE);
|
|
1892
1964
|
if (newOptionConst !== NO_VALUE && newOptionConst !== formValue) {
|
|
1893
1965
|
removeOldSchemaData[key] = oldOptionConst === formValue ? newOptionConst : void 0;
|
|
1894
1966
|
}
|
|
@@ -1900,9 +1972,9 @@ function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, d
|
|
|
1900
1972
|
...removeOldSchemaData,
|
|
1901
1973
|
...nestedData
|
|
1902
1974
|
};
|
|
1903
|
-
} else if (
|
|
1904
|
-
let oldSchemaItems =
|
|
1905
|
-
let newSchemaItems =
|
|
1975
|
+
} else if (get13(oldSchema, "type") === "array" && get13(newSchema, "type") === "array" && Array.isArray(data)) {
|
|
1976
|
+
let oldSchemaItems = get13(oldSchema, "items");
|
|
1977
|
+
let newSchemaItems = get13(newSchema, "items");
|
|
1906
1978
|
if (typeof oldSchemaItems === "object" && typeof newSchemaItems === "object" && !Array.isArray(oldSchemaItems) && !Array.isArray(newSchemaItems)) {
|
|
1907
1979
|
if (has5(oldSchemaItems, REF_KEY)) {
|
|
1908
1980
|
oldSchemaItems = retrieveSchema(
|
|
@@ -1922,10 +1994,10 @@ function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, d
|
|
|
1922
1994
|
experimental_customMergeAllOf
|
|
1923
1995
|
);
|
|
1924
1996
|
}
|
|
1925
|
-
const oldSchemaType =
|
|
1926
|
-
const newSchemaType =
|
|
1997
|
+
const oldSchemaType = get13(oldSchemaItems, "type");
|
|
1998
|
+
const newSchemaType = get13(newSchemaItems, "type");
|
|
1927
1999
|
if (!oldSchemaType || oldSchemaType === newSchemaType) {
|
|
1928
|
-
const maxItems =
|
|
2000
|
+
const maxItems = get13(newSchema, "maxItems", -1);
|
|
1929
2001
|
if (newSchemaType === "object") {
|
|
1930
2002
|
newFormData = data.reduce((newValue, aValue) => {
|
|
1931
2003
|
const itemValue = sanitizeDataForNewSchema(
|
|
@@ -1952,78 +2024,6 @@ function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, d
|
|
|
1952
2024
|
return newFormData;
|
|
1953
2025
|
}
|
|
1954
2026
|
|
|
1955
|
-
// src/schema/toIdSchema.ts
|
|
1956
|
-
import get13 from "lodash/get";
|
|
1957
|
-
function toIdSchemaInternal(validator, schema, idPrefix, idSeparator, id, rootSchema, formData, _recurseList = [], experimental_customMergeAllOf) {
|
|
1958
|
-
const $id = id || idPrefix;
|
|
1959
|
-
const idSchema = { $id };
|
|
1960
|
-
if (typeof schema === "object") {
|
|
1961
|
-
if (REF_KEY in schema || DEPENDENCIES_KEY in schema || ALL_OF_KEY in schema) {
|
|
1962
|
-
const _schema = retrieveSchema(validator, schema, rootSchema, formData, experimental_customMergeAllOf);
|
|
1963
|
-
const sameSchemaIndex = _recurseList.findIndex((item) => deepEquals(item, _schema));
|
|
1964
|
-
if (sameSchemaIndex === -1) {
|
|
1965
|
-
return toIdSchemaInternal(
|
|
1966
|
-
validator,
|
|
1967
|
-
_schema,
|
|
1968
|
-
idPrefix,
|
|
1969
|
-
idSeparator,
|
|
1970
|
-
id,
|
|
1971
|
-
rootSchema,
|
|
1972
|
-
formData,
|
|
1973
|
-
_recurseList.concat(_schema),
|
|
1974
|
-
experimental_customMergeAllOf
|
|
1975
|
-
);
|
|
1976
|
-
}
|
|
1977
|
-
}
|
|
1978
|
-
if (ITEMS_KEY in schema && !get13(schema, [ITEMS_KEY, REF_KEY])) {
|
|
1979
|
-
return toIdSchemaInternal(
|
|
1980
|
-
validator,
|
|
1981
|
-
get13(schema, ITEMS_KEY),
|
|
1982
|
-
idPrefix,
|
|
1983
|
-
idSeparator,
|
|
1984
|
-
id,
|
|
1985
|
-
rootSchema,
|
|
1986
|
-
formData,
|
|
1987
|
-
_recurseList,
|
|
1988
|
-
experimental_customMergeAllOf
|
|
1989
|
-
);
|
|
1990
|
-
}
|
|
1991
|
-
if (getSchemaType(schema) === "object" && PROPERTIES_KEY in schema) {
|
|
1992
|
-
for (const name in schema.properties) {
|
|
1993
|
-
const field = schema[PROPERTIES_KEY][name];
|
|
1994
|
-
const fieldId = idSchema[ID_KEY] + idSeparator + name;
|
|
1995
|
-
idSchema[name] = toIdSchemaInternal(
|
|
1996
|
-
validator,
|
|
1997
|
-
field,
|
|
1998
|
-
idPrefix,
|
|
1999
|
-
idSeparator,
|
|
2000
|
-
fieldId,
|
|
2001
|
-
rootSchema,
|
|
2002
|
-
// It's possible that formData is not an object -- this can happen if an
|
|
2003
|
-
// array item has just been added, but not populated with data yet
|
|
2004
|
-
get13(formData, [name]),
|
|
2005
|
-
_recurseList,
|
|
2006
|
-
experimental_customMergeAllOf
|
|
2007
|
-
);
|
|
2008
|
-
}
|
|
2009
|
-
}
|
|
2010
|
-
}
|
|
2011
|
-
return idSchema;
|
|
2012
|
-
}
|
|
2013
|
-
function toIdSchema(validator, schema, id, rootSchema, formData, idPrefix = "root", idSeparator = "_", experimental_customMergeAllOf) {
|
|
2014
|
-
return toIdSchemaInternal(
|
|
2015
|
-
validator,
|
|
2016
|
-
schema,
|
|
2017
|
-
idPrefix,
|
|
2018
|
-
idSeparator,
|
|
2019
|
-
id,
|
|
2020
|
-
rootSchema,
|
|
2021
|
-
formData,
|
|
2022
|
-
void 0,
|
|
2023
|
-
experimental_customMergeAllOf
|
|
2024
|
-
);
|
|
2025
|
-
}
|
|
2026
|
-
|
|
2027
2027
|
// src/schema/toPathSchema.ts
|
|
2028
2028
|
import get14 from "lodash/get";
|
|
2029
2029
|
import set2 from "lodash/set";
|
|
@@ -2139,6 +2139,7 @@ function toPathSchema(validator, schema, name = "", rootSchema, formData, experi
|
|
|
2139
2139
|
}
|
|
2140
2140
|
|
|
2141
2141
|
// src/createSchemaUtils.ts
|
|
2142
|
+
import get15 from "lodash/get";
|
|
2142
2143
|
var SchemaUtils = class {
|
|
2143
2144
|
/** Constructs the `SchemaUtils` instance with the given `validator` and `rootSchema` stored as instance variables
|
|
2144
2145
|
*
|
|
@@ -2148,11 +2149,22 @@ var SchemaUtils = class {
|
|
|
2148
2149
|
* @param [experimental_customMergeAllOf] - Optional function that allows for custom merging of `allOf` schemas
|
|
2149
2150
|
*/
|
|
2150
2151
|
constructor(validator, rootSchema, experimental_defaultFormStateBehavior, experimental_customMergeAllOf) {
|
|
2151
|
-
|
|
2152
|
+
if (rootSchema && rootSchema[SCHEMA_KEY] === JSON_SCHEMA_DRAFT_2020_12) {
|
|
2153
|
+
this.rootSchema = makeAllReferencesAbsolute(rootSchema, get15(rootSchema, ID_KEY, "#"));
|
|
2154
|
+
} else {
|
|
2155
|
+
this.rootSchema = rootSchema;
|
|
2156
|
+
}
|
|
2152
2157
|
this.validator = validator;
|
|
2153
2158
|
this.experimental_defaultFormStateBehavior = experimental_defaultFormStateBehavior;
|
|
2154
2159
|
this.experimental_customMergeAllOf = experimental_customMergeAllOf;
|
|
2155
2160
|
}
|
|
2161
|
+
/** Returns the `rootSchema` in the `SchemaUtilsType`
|
|
2162
|
+
*
|
|
2163
|
+
* @returns - The `rootSchema`
|
|
2164
|
+
*/
|
|
2165
|
+
getRootSchema() {
|
|
2166
|
+
return this.rootSchema;
|
|
2167
|
+
}
|
|
2156
2168
|
/** Returns the `ValidatorType` in the `SchemaUtilsType`
|
|
2157
2169
|
*
|
|
2158
2170
|
* @returns - The `ValidatorType`
|
|
@@ -2366,27 +2378,6 @@ var SchemaUtils = class {
|
|
|
2366
2378
|
this.experimental_customMergeAllOf
|
|
2367
2379
|
);
|
|
2368
2380
|
}
|
|
2369
|
-
/** Generates an `IdSchema` object for the `schema`, recursively
|
|
2370
|
-
*
|
|
2371
|
-
* @param schema - The schema for which the display label flag is desired
|
|
2372
|
-
* @param [id] - The base id for the schema
|
|
2373
|
-
* @param [formData] - The current formData, if any, onto which to provide any missing defaults
|
|
2374
|
-
* @param [idPrefix='root'] - The prefix to use for the id
|
|
2375
|
-
* @param [idSeparator='_'] - The separator to use for the path segments in the id
|
|
2376
|
-
* @returns - The `IdSchema` object for the `schema`
|
|
2377
|
-
*/
|
|
2378
|
-
toIdSchema(schema, id, formData, idPrefix = "root", idSeparator = "_") {
|
|
2379
|
-
return toIdSchema(
|
|
2380
|
-
this.validator,
|
|
2381
|
-
schema,
|
|
2382
|
-
id,
|
|
2383
|
-
this.rootSchema,
|
|
2384
|
-
formData,
|
|
2385
|
-
idPrefix,
|
|
2386
|
-
idSeparator,
|
|
2387
|
-
this.experimental_customMergeAllOf
|
|
2388
|
-
);
|
|
2389
|
-
}
|
|
2390
2381
|
/** Generates an `PathSchema` object for the `schema`, recursively
|
|
2391
2382
|
*
|
|
2392
2383
|
* @param schema - The schema for which the display label flag is desired
|
|
@@ -2472,6 +2463,31 @@ function dateRangeOptions(start, stop) {
|
|
|
2472
2463
|
return options;
|
|
2473
2464
|
}
|
|
2474
2465
|
|
|
2466
|
+
// src/shallowEquals.ts
|
|
2467
|
+
function shallowEquals(a, b) {
|
|
2468
|
+
if (Object.is(a, b)) {
|
|
2469
|
+
return true;
|
|
2470
|
+
}
|
|
2471
|
+
if (a == null || b == null) {
|
|
2472
|
+
return false;
|
|
2473
|
+
}
|
|
2474
|
+
if (typeof a !== "object" || typeof b !== "object") {
|
|
2475
|
+
return false;
|
|
2476
|
+
}
|
|
2477
|
+
const keysA = Object.keys(a);
|
|
2478
|
+
const keysB = Object.keys(b);
|
|
2479
|
+
if (keysA.length !== keysB.length) {
|
|
2480
|
+
return false;
|
|
2481
|
+
}
|
|
2482
|
+
for (let i = 0; i < keysA.length; i++) {
|
|
2483
|
+
const key = keysA[i];
|
|
2484
|
+
if (!Object.prototype.hasOwnProperty.call(b, key) || !Object.is(a[key], b[key])) {
|
|
2485
|
+
return false;
|
|
2486
|
+
}
|
|
2487
|
+
}
|
|
2488
|
+
return true;
|
|
2489
|
+
}
|
|
2490
|
+
|
|
2475
2491
|
// src/replaceStringParameters.ts
|
|
2476
2492
|
function replaceStringParameters(inputString, params) {
|
|
2477
2493
|
let output = inputString;
|
|
@@ -2544,7 +2560,7 @@ function enumOptionsSelectValue(valueIndex, selected, allEnumOptions = []) {
|
|
|
2544
2560
|
|
|
2545
2561
|
// src/ErrorSchemaBuilder.ts
|
|
2546
2562
|
import cloneDeep from "lodash/cloneDeep";
|
|
2547
|
-
import
|
|
2563
|
+
import get16 from "lodash/get";
|
|
2548
2564
|
import set3 from "lodash/set";
|
|
2549
2565
|
import setWith from "lodash/setWith";
|
|
2550
2566
|
var ErrorSchemaBuilder = class {
|
|
@@ -2573,7 +2589,7 @@ var ErrorSchemaBuilder = class {
|
|
|
2573
2589
|
*/
|
|
2574
2590
|
getOrCreateErrorBlock(pathOfError) {
|
|
2575
2591
|
const hasPath = Array.isArray(pathOfError) && pathOfError.length > 0 || typeof pathOfError === "string";
|
|
2576
|
-
let errorBlock = hasPath ?
|
|
2592
|
+
let errorBlock = hasPath ? get16(this.errorSchema, pathOfError) : this.errorSchema;
|
|
2577
2593
|
if (!errorBlock && pathOfError) {
|
|
2578
2594
|
errorBlock = {};
|
|
2579
2595
|
setWith(this.errorSchema, pathOfError, errorBlock, Object);
|
|
@@ -2599,7 +2615,7 @@ var ErrorSchemaBuilder = class {
|
|
|
2599
2615
|
*/
|
|
2600
2616
|
addErrors(errorOrList, pathOfError) {
|
|
2601
2617
|
const errorBlock = this.getOrCreateErrorBlock(pathOfError);
|
|
2602
|
-
let errorsList =
|
|
2618
|
+
let errorsList = get16(errorBlock, ERRORS_KEY);
|
|
2603
2619
|
if (!Array.isArray(errorsList)) {
|
|
2604
2620
|
errorsList = [];
|
|
2605
2621
|
errorBlock[ERRORS_KEY] = errorsList;
|
|
@@ -2747,10 +2763,10 @@ function getTemplate(name, registry, uiOptions = {}) {
|
|
|
2747
2763
|
}
|
|
2748
2764
|
|
|
2749
2765
|
// src/getTestIds.ts
|
|
2750
|
-
import
|
|
2751
|
-
import
|
|
2766
|
+
import get17 from "lodash/get";
|
|
2767
|
+
import uniqueId from "lodash/uniqueId";
|
|
2752
2768
|
function getTestIds() {
|
|
2753
|
-
if (typeof process === "undefined" ||
|
|
2769
|
+
if (typeof process === "undefined" || get17(process, "env.NODE_ENV") !== "test") {
|
|
2754
2770
|
return {};
|
|
2755
2771
|
}
|
|
2756
2772
|
const ids = /* @__PURE__ */ new Map();
|
|
@@ -2759,7 +2775,7 @@ function getTestIds() {
|
|
|
2759
2775
|
{
|
|
2760
2776
|
get(_obj, prop) {
|
|
2761
2777
|
if (!ids.has(prop)) {
|
|
2762
|
-
ids.set(prop,
|
|
2778
|
+
ids.set(prop, uniqueId("test-id-"));
|
|
2763
2779
|
}
|
|
2764
2780
|
return ids.get(prop);
|
|
2765
2781
|
}
|
|
@@ -2770,7 +2786,7 @@ function getTestIds() {
|
|
|
2770
2786
|
// src/getWidget.tsx
|
|
2771
2787
|
import { createElement } from "react";
|
|
2772
2788
|
import ReactIs from "react-is";
|
|
2773
|
-
import
|
|
2789
|
+
import get18 from "lodash/get";
|
|
2774
2790
|
import set4 from "lodash/set";
|
|
2775
2791
|
import { jsx } from "react/jsx-runtime";
|
|
2776
2792
|
var widgetMap = {
|
|
@@ -2826,7 +2842,7 @@ var widgetMap = {
|
|
|
2826
2842
|
}
|
|
2827
2843
|
};
|
|
2828
2844
|
function mergeWidgetOptions(AWidget) {
|
|
2829
|
-
let MergedWidget =
|
|
2845
|
+
let MergedWidget = get18(AWidget, "MergedWidget");
|
|
2830
2846
|
if (!MergedWidget) {
|
|
2831
2847
|
const defaultOptions = AWidget.defaultProps && AWidget.defaultProps.options || {};
|
|
2832
2848
|
MergedWidget = ({ options, ...props }) => {
|
|
@@ -2842,7 +2858,7 @@ function getWidget(schema, widget, registeredWidgets = {}) {
|
|
|
2842
2858
|
return mergeWidgetOptions(widget);
|
|
2843
2859
|
}
|
|
2844
2860
|
if (typeof widget !== "string") {
|
|
2845
|
-
throw new Error(`Unsupported widget definition: ${typeof widget}`);
|
|
2861
|
+
throw new Error(`Unsupported widget definition: ${typeof widget} in schema: ${JSON.stringify(schema)}`);
|
|
2846
2862
|
}
|
|
2847
2863
|
if (widget in registeredWidgets) {
|
|
2848
2864
|
const registeredWidget = registeredWidgets[widget];
|
|
@@ -2850,14 +2866,14 @@ function getWidget(schema, widget, registeredWidgets = {}) {
|
|
|
2850
2866
|
}
|
|
2851
2867
|
if (typeof type === "string") {
|
|
2852
2868
|
if (!(type in widgetMap)) {
|
|
2853
|
-
throw new Error(`No widget for type '${type}'`);
|
|
2869
|
+
throw new Error(`No widget for type '${type}' in schema: ${JSON.stringify(schema)}`);
|
|
2854
2870
|
}
|
|
2855
2871
|
if (widget in widgetMap[type]) {
|
|
2856
2872
|
const registeredWidget = registeredWidgets[widgetMap[type][widget]];
|
|
2857
2873
|
return getWidget(schema, registeredWidget, registeredWidgets);
|
|
2858
2874
|
}
|
|
2859
2875
|
}
|
|
2860
|
-
throw new Error(`No widget '${widget}' for type '${type}'`);
|
|
2876
|
+
throw new Error(`No widget '${widget}' for type '${type}' in schema: ${JSON.stringify(schema)}`);
|
|
2861
2877
|
}
|
|
2862
2878
|
|
|
2863
2879
|
// src/hashForSchema.ts
|
|
@@ -2939,14 +2955,14 @@ function localToUTC(dateString) {
|
|
|
2939
2955
|
}
|
|
2940
2956
|
|
|
2941
2957
|
// src/lookupFromFormContext.ts
|
|
2942
|
-
import
|
|
2958
|
+
import get19 from "lodash/get";
|
|
2943
2959
|
import has6 from "lodash/has";
|
|
2944
2960
|
function lookupFromFormContext(regOrFc, toLookup, fallback) {
|
|
2945
2961
|
const lookupPath = [LOOKUP_MAP_NAME];
|
|
2946
2962
|
if (has6(regOrFc, FORM_CONTEXT_NAME)) {
|
|
2947
2963
|
lookupPath.unshift(FORM_CONTEXT_NAME);
|
|
2948
2964
|
}
|
|
2949
|
-
return
|
|
2965
|
+
return get19(regOrFc, [...lookupPath, toLookup], fallback);
|
|
2950
2966
|
}
|
|
2951
2967
|
|
|
2952
2968
|
// src/orderProperties.ts
|
|
@@ -3027,7 +3043,14 @@ function schemaRequiresTrueValue(schema) {
|
|
|
3027
3043
|
}
|
|
3028
3044
|
|
|
3029
3045
|
// src/shouldRender.ts
|
|
3030
|
-
function shouldRender(component, nextProps, nextState) {
|
|
3046
|
+
function shouldRender(component, nextProps, nextState, updateStrategy = "customDeep") {
|
|
3047
|
+
if (updateStrategy === "always") {
|
|
3048
|
+
return true;
|
|
3049
|
+
}
|
|
3050
|
+
if (updateStrategy === "shallow") {
|
|
3051
|
+
const { props: props2, state: state2 } = component;
|
|
3052
|
+
return !shallowEquals(props2, nextProps) || !shallowEquals(state2, nextState);
|
|
3053
|
+
}
|
|
3031
3054
|
const { props, state } = component;
|
|
3032
3055
|
return !deepEquals(props, nextProps) || !deepEquals(state, nextState);
|
|
3033
3056
|
}
|
|
@@ -3089,6 +3112,15 @@ function toErrorSchema(errors) {
|
|
|
3089
3112
|
return builder.ErrorSchema;
|
|
3090
3113
|
}
|
|
3091
3114
|
|
|
3115
|
+
// src/toFieldPathId.ts
|
|
3116
|
+
function toFieldPathId(fieldPath, globalFormOptions, parentPath) {
|
|
3117
|
+
const basePath = Array.isArray(parentPath) ? parentPath : parentPath?.path;
|
|
3118
|
+
const childPath = fieldPath === "" ? [] : [fieldPath];
|
|
3119
|
+
const path = basePath ? basePath.concat(...childPath) : childPath;
|
|
3120
|
+
const id = [globalFormOptions.idPrefix, ...path].join(globalFormOptions.idSeparator);
|
|
3121
|
+
return { path, [ID_KEY]: id };
|
|
3122
|
+
}
|
|
3123
|
+
|
|
3092
3124
|
// src/unwrapErrorHandler.ts
|
|
3093
3125
|
import isPlainObject3 from "lodash/isPlainObject";
|
|
3094
3126
|
function unwrapErrorHandler(errorHandler) {
|
|
@@ -3174,7 +3206,7 @@ function withIdRefPrefix(schemaNode) {
|
|
|
3174
3206
|
import keys from "lodash/keys";
|
|
3175
3207
|
import pickBy from "lodash/pickBy";
|
|
3176
3208
|
import isPlainObject4 from "lodash/isPlainObject";
|
|
3177
|
-
import
|
|
3209
|
+
import get20 from "lodash/get";
|
|
3178
3210
|
import difference from "lodash/difference";
|
|
3179
3211
|
function getChangedFields(a, b) {
|
|
3180
3212
|
const aIsPlainObject = isPlainObject4(a);
|
|
@@ -3187,7 +3219,7 @@ function getChangedFields(a, b) {
|
|
|
3187
3219
|
} else if (!aIsPlainObject && bIsPlainObject) {
|
|
3188
3220
|
return keys(b);
|
|
3189
3221
|
} else {
|
|
3190
|
-
const unequalFields = keys(pickBy(a, (value, key) => !deepEquals(value,
|
|
3222
|
+
const unequalFields = keys(pickBy(a, (value, key) => !deepEquals(value, get20(b, key))));
|
|
3191
3223
|
const diffFields = difference(keys(b), keys(a));
|
|
3192
3224
|
return [...unequalFields, ...diffFields];
|
|
3193
3225
|
}
|
|
@@ -3232,7 +3264,7 @@ var TranslatableString = /* @__PURE__ */ ((TranslatableString2) => {
|
|
|
3232
3264
|
import forEach from "lodash/forEach";
|
|
3233
3265
|
|
|
3234
3266
|
// src/parser/ParserValidator.ts
|
|
3235
|
-
import
|
|
3267
|
+
import get21 from "lodash/get";
|
|
3236
3268
|
var ParserValidator = class {
|
|
3237
3269
|
/** Construct the ParserValidator for the given `rootSchema`. This `rootSchema` will be stashed in the `schemaMap`
|
|
3238
3270
|
* first.
|
|
@@ -3258,7 +3290,7 @@ var ParserValidator = class {
|
|
|
3258
3290
|
* @param hash - The hash value at which to map the schema
|
|
3259
3291
|
*/
|
|
3260
3292
|
addSchema(schema, hash) {
|
|
3261
|
-
const key =
|
|
3293
|
+
const key = get21(schema, ID_KEY, hash);
|
|
3262
3294
|
const identifiedSchema = { ...schema, [ID_KEY]: key };
|
|
3263
3295
|
const existing = this.schemaMap[key];
|
|
3264
3296
|
if (!existing) {
|
|
@@ -3354,6 +3386,8 @@ export {
|
|
|
3354
3386
|
ALL_OF_KEY,
|
|
3355
3387
|
ANY_OF_KEY,
|
|
3356
3388
|
CONST_KEY,
|
|
3389
|
+
DEFAULT_ID_PREFIX,
|
|
3390
|
+
DEFAULT_ID_SEPARATOR,
|
|
3357
3391
|
DEFAULT_KEY,
|
|
3358
3392
|
DEFINITIONS_KEY,
|
|
3359
3393
|
DEPENDENCIES_KEY,
|
|
@@ -3365,6 +3399,7 @@ export {
|
|
|
3365
3399
|
ID_KEY,
|
|
3366
3400
|
IF_KEY,
|
|
3367
3401
|
ITEMS_KEY,
|
|
3402
|
+
JSON_SCHEMA_DRAFT_2019_09,
|
|
3368
3403
|
JSON_SCHEMA_DRAFT_2020_12,
|
|
3369
3404
|
JUNK_OPTION_ID,
|
|
3370
3405
|
LOOKUP_MAP_NAME,
|
|
@@ -3452,6 +3487,7 @@ export {
|
|
|
3452
3487
|
sanitizeDataForNewSchema,
|
|
3453
3488
|
schemaParser,
|
|
3454
3489
|
schemaRequiresTrueValue,
|
|
3490
|
+
shallowEquals,
|
|
3455
3491
|
shouldRender,
|
|
3456
3492
|
sortedJSONStringify,
|
|
3457
3493
|
titleId,
|
|
@@ -3459,7 +3495,7 @@ export {
|
|
|
3459
3495
|
toDateString,
|
|
3460
3496
|
toErrorList,
|
|
3461
3497
|
toErrorSchema,
|
|
3462
|
-
|
|
3498
|
+
toFieldPathId,
|
|
3463
3499
|
toPathSchema,
|
|
3464
3500
|
unwrapErrorHandler,
|
|
3465
3501
|
utcToLocal,
|