@rjsf/utils 6.0.0-beta.1 → 6.0.0-beta.11
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 +177 -111
- package/dist/index.js.map +3 -3
- package/dist/utils.esm.js +177 -111
- package/dist/utils.esm.js.map +3 -3
- package/dist/utils.umd.js +151 -89
- package/lib/canExpand.d.ts +1 -1
- package/lib/constants.d.ts +4 -0
- package/lib/constants.js +4 -0
- package/lib/constants.js.map +1 -1
- package/lib/findSchemaDefinition.d.ts +4 -2
- package/lib/findSchemaDefinition.js +53 -10
- package/lib/findSchemaDefinition.js.map +1 -1
- package/lib/mergeDefaultsWithFormData.js +13 -1
- 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.js +21 -4
- package/lib/schema/getDefaultFormState.js.map +1 -1
- package/lib/schema/retrieveSchema.d.ts +2 -1
- package/lib/schema/retrieveSchema.js +14 -7
- package/lib/schema/retrieveSchema.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/types.d.ts +22 -12
- package/package.json +2 -1
- package/src/constants.ts +5 -0
- package/src/findSchemaDefinition.ts +53 -8
- package/src/mergeDefaultsWithFormData.ts +15 -1
- package/src/schema/findFieldInSchema.ts +1 -1
- package/src/schema/getDefaultFormState.ts +24 -5
- package/src/schema/retrieveSchema.ts +14 -5
- package/src/types.ts +27 -11
package/dist/utils.esm.js
CHANGED
|
@@ -65,6 +65,7 @@ var READONLY_KEY = "readonly";
|
|
|
65
65
|
var REQUIRED_KEY = "required";
|
|
66
66
|
var SUBMIT_BTN_OPTIONS_KEY = "submitButtonOptions";
|
|
67
67
|
var REF_KEY = "$ref";
|
|
68
|
+
var SCHEMA_KEY = "$schema";
|
|
68
69
|
var DISCRIMINATOR_PATH = ["discriminator", "propertyName"];
|
|
69
70
|
var FORM_CONTEXT_NAME = "formContext";
|
|
70
71
|
var LOOKUP_MAP_NAME = "layoutGridLookupMap";
|
|
@@ -74,6 +75,7 @@ var UI_FIELD_KEY = "ui:field";
|
|
|
74
75
|
var UI_WIDGET_KEY = "ui:widget";
|
|
75
76
|
var UI_OPTIONS_KEY = "ui:options";
|
|
76
77
|
var UI_GLOBAL_OPTIONS_KEY = "ui:globalOptions";
|
|
78
|
+
var JSON_SCHEMA_DRAFT_2020_12 = "https://json-schema.org/draft/2020-12/schema";
|
|
77
79
|
|
|
78
80
|
// src/getUiOptions.ts
|
|
79
81
|
function getUiOptions(uiSchema = {}, globalOptions = {}) {
|
|
@@ -146,15 +148,15 @@ function deepEquals(a, b) {
|
|
|
146
148
|
}
|
|
147
149
|
|
|
148
150
|
// src/schema/findFieldInSchema.ts
|
|
149
|
-
import
|
|
151
|
+
import get8 from "lodash/get";
|
|
150
152
|
import has3 from "lodash/has";
|
|
151
153
|
|
|
152
154
|
// src/schema/findSelectedOptionInXxxOf.ts
|
|
153
|
-
import
|
|
155
|
+
import get6 from "lodash/get";
|
|
154
156
|
import isEqual from "lodash/isEqual";
|
|
155
157
|
|
|
156
158
|
// src/schema/retrieveSchema.ts
|
|
157
|
-
import
|
|
159
|
+
import get5 from "lodash/get";
|
|
158
160
|
import set from "lodash/set";
|
|
159
161
|
import times from "lodash/times";
|
|
160
162
|
import transform from "lodash/transform";
|
|
@@ -166,20 +168,53 @@ import mergeAllOf from "json-schema-merge-allof";
|
|
|
166
168
|
// src/findSchemaDefinition.ts
|
|
167
169
|
import jsonpointer from "jsonpointer";
|
|
168
170
|
import omit from "lodash/omit";
|
|
171
|
+
import isObject2 from "lodash/isObject";
|
|
172
|
+
import isEmpty from "lodash/isEmpty";
|
|
173
|
+
import UriResolver from "fast-uri";
|
|
174
|
+
import get from "lodash/get";
|
|
175
|
+
function findEmbeddedSchemaRecursive(schema, ref) {
|
|
176
|
+
if (ID_KEY in schema && UriResolver.equal(schema[ID_KEY], ref)) {
|
|
177
|
+
return schema;
|
|
178
|
+
}
|
|
179
|
+
for (const subSchema of Object.values(schema)) {
|
|
180
|
+
if (isObject2(subSchema)) {
|
|
181
|
+
const result = findEmbeddedSchemaRecursive(subSchema, ref);
|
|
182
|
+
if (result !== void 0) {
|
|
183
|
+
return result;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
return void 0;
|
|
188
|
+
}
|
|
169
189
|
function splitKeyElementFromObject(key, object) {
|
|
170
190
|
const value = object[key];
|
|
171
191
|
const remaining = omit(object, [key]);
|
|
172
192
|
return [remaining, value];
|
|
173
193
|
}
|
|
174
|
-
function findSchemaDefinitionRecursive($ref, rootSchema = {}, recurseList = []) {
|
|
194
|
+
function findSchemaDefinitionRecursive($ref, rootSchema = {}, recurseList = [], baseURI = get(rootSchema, [ID_KEY])) {
|
|
175
195
|
const ref = $ref || "";
|
|
176
|
-
let
|
|
196
|
+
let current = void 0;
|
|
177
197
|
if (ref.startsWith("#")) {
|
|
178
|
-
decodedRef = decodeURIComponent(ref.substring(1));
|
|
179
|
-
|
|
180
|
-
|
|
198
|
+
const decodedRef = decodeURIComponent(ref.substring(1));
|
|
199
|
+
if (baseURI === void 0 || ID_KEY in rootSchema && rootSchema[ID_KEY] === baseURI) {
|
|
200
|
+
current = jsonpointer.get(rootSchema, decodedRef);
|
|
201
|
+
} else if (rootSchema[SCHEMA_KEY] === JSON_SCHEMA_DRAFT_2020_12) {
|
|
202
|
+
current = findEmbeddedSchemaRecursive(rootSchema, baseURI.replace(/\/$/, ""));
|
|
203
|
+
if (current !== void 0) {
|
|
204
|
+
current = jsonpointer.get(current, decodedRef);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
} else if (rootSchema[SCHEMA_KEY] === JSON_SCHEMA_DRAFT_2020_12) {
|
|
208
|
+
const resolvedRef = baseURI ? UriResolver.resolve(baseURI, ref) : ref;
|
|
209
|
+
const [refId, ...refAnchor] = resolvedRef.replace(/#\/?$/, "").split("#");
|
|
210
|
+
current = findEmbeddedSchemaRecursive(rootSchema, refId.replace(/\/$/, ""));
|
|
211
|
+
if (current !== void 0) {
|
|
212
|
+
baseURI = current[ID_KEY];
|
|
213
|
+
if (!isEmpty(refAnchor)) {
|
|
214
|
+
current = jsonpointer.get(current, decodeURIComponent(refAnchor.join("#")));
|
|
215
|
+
}
|
|
216
|
+
}
|
|
181
217
|
}
|
|
182
|
-
const current = jsonpointer.get(rootSchema, decodedRef);
|
|
183
218
|
if (current === void 0) {
|
|
184
219
|
throw new Error(`Could not find a definition for ${$ref}.`);
|
|
185
220
|
}
|
|
@@ -194,7 +229,7 @@ function findSchemaDefinitionRecursive($ref, rootSchema = {}, recurseList = [])
|
|
|
194
229
|
throw new Error(`Definition for ${firstRef} contains a circular reference through ${circularPath}`);
|
|
195
230
|
}
|
|
196
231
|
const [remaining, theRef] = splitKeyElementFromObject(REF_KEY, current);
|
|
197
|
-
const subSchema = findSchemaDefinitionRecursive(theRef, rootSchema, [...recurseList, ref]);
|
|
232
|
+
const subSchema = findSchemaDefinitionRecursive(theRef, rootSchema, [...recurseList, ref], baseURI);
|
|
198
233
|
if (Object.keys(remaining).length > 0) {
|
|
199
234
|
return { ...remaining, ...subSchema };
|
|
200
235
|
}
|
|
@@ -202,17 +237,17 @@ function findSchemaDefinitionRecursive($ref, rootSchema = {}, recurseList = [])
|
|
|
202
237
|
}
|
|
203
238
|
return current;
|
|
204
239
|
}
|
|
205
|
-
function findSchemaDefinition($ref, rootSchema = {}) {
|
|
240
|
+
function findSchemaDefinition($ref, rootSchema = {}, baseURI = get(rootSchema, [ID_KEY])) {
|
|
206
241
|
const recurseList = [];
|
|
207
|
-
return findSchemaDefinitionRecursive($ref, rootSchema, recurseList);
|
|
242
|
+
return findSchemaDefinitionRecursive($ref, rootSchema, recurseList, baseURI);
|
|
208
243
|
}
|
|
209
244
|
|
|
210
245
|
// src/getDiscriminatorFieldFromSchema.ts
|
|
211
|
-
import
|
|
246
|
+
import get2 from "lodash/get";
|
|
212
247
|
import isString from "lodash/isString";
|
|
213
248
|
function getDiscriminatorFieldFromSchema(schema) {
|
|
214
249
|
let discriminator;
|
|
215
|
-
const maybeString =
|
|
250
|
+
const maybeString = get2(schema, DISCRIMINATOR_PATH);
|
|
216
251
|
if (isString(maybeString)) {
|
|
217
252
|
discriminator = maybeString;
|
|
218
253
|
} else if (maybeString !== void 0) {
|
|
@@ -286,21 +321,21 @@ function mergeSchemas(obj1, obj2) {
|
|
|
286
321
|
}
|
|
287
322
|
|
|
288
323
|
// src/schema/getFirstMatchingOption.ts
|
|
289
|
-
import
|
|
324
|
+
import get4 from "lodash/get";
|
|
290
325
|
import has from "lodash/has";
|
|
291
326
|
import isNumber from "lodash/isNumber";
|
|
292
327
|
|
|
293
328
|
// src/getOptionMatchingSimpleDiscriminator.ts
|
|
294
|
-
import
|
|
329
|
+
import get3 from "lodash/get";
|
|
295
330
|
function getOptionMatchingSimpleDiscriminator(formData, options, discriminatorField) {
|
|
296
331
|
if (formData && discriminatorField) {
|
|
297
|
-
const value =
|
|
332
|
+
const value = get3(formData, discriminatorField);
|
|
298
333
|
if (value === void 0) {
|
|
299
334
|
return;
|
|
300
335
|
}
|
|
301
336
|
for (let i = 0; i < options.length; i++) {
|
|
302
337
|
const option = options[i];
|
|
303
|
-
const discriminator =
|
|
338
|
+
const discriminator = get3(option, [PROPERTIES_KEY, discriminatorField], {});
|
|
304
339
|
if (discriminator.type === "object" || discriminator.type === "array") {
|
|
305
340
|
continue;
|
|
306
341
|
}
|
|
@@ -327,8 +362,8 @@ function getFirstMatchingOption(validator, formData, options, rootSchema, discri
|
|
|
327
362
|
for (let i = 0; i < options.length; i++) {
|
|
328
363
|
const option = options[i];
|
|
329
364
|
if (discriminatorField && has(option, [PROPERTIES_KEY, discriminatorField])) {
|
|
330
|
-
const value =
|
|
331
|
-
const discriminator =
|
|
365
|
+
const value = get4(formData, discriminatorField);
|
|
366
|
+
const discriminator = get4(option, [PROPERTIES_KEY, discriminatorField], {});
|
|
332
367
|
if (validator.isValid(discriminator, value, rootSchema)) {
|
|
333
368
|
return i;
|
|
334
369
|
}
|
|
@@ -363,7 +398,7 @@ function getFirstMatchingOption(validator, formData, options, rootSchema, discri
|
|
|
363
398
|
}
|
|
364
399
|
|
|
365
400
|
// src/schema/retrieveSchema.ts
|
|
366
|
-
import
|
|
401
|
+
import isEmpty2 from "lodash/isEmpty";
|
|
367
402
|
function retrieveSchema(validator, schema, rootSchema = {}, rawFormData, experimental_customMergeAllOf) {
|
|
368
403
|
return retrieveSchemaInternal(
|
|
369
404
|
validator,
|
|
@@ -529,7 +564,7 @@ function resolveReference(validator, schema, rootSchema, expandAllBranches, recu
|
|
|
529
564
|
}
|
|
530
565
|
return [schema];
|
|
531
566
|
}
|
|
532
|
-
function resolveAllReferences(schema, rootSchema, recurseList) {
|
|
567
|
+
function resolveAllReferences(schema, rootSchema, recurseList, baseURI) {
|
|
533
568
|
if (!isObject(schema)) {
|
|
534
569
|
return schema;
|
|
535
570
|
}
|
|
@@ -540,8 +575,11 @@ function resolveAllReferences(schema, rootSchema, recurseList) {
|
|
|
540
575
|
return resolvedSchema;
|
|
541
576
|
}
|
|
542
577
|
recurseList.push($ref);
|
|
543
|
-
const refSchema = findSchemaDefinition($ref, rootSchema);
|
|
578
|
+
const refSchema = findSchemaDefinition($ref, rootSchema, baseURI);
|
|
544
579
|
resolvedSchema = { ...refSchema, ...localSchema };
|
|
580
|
+
if (ID_KEY in resolvedSchema) {
|
|
581
|
+
baseURI = resolvedSchema[ID_KEY];
|
|
582
|
+
}
|
|
545
583
|
}
|
|
546
584
|
if (PROPERTIES_KEY in resolvedSchema) {
|
|
547
585
|
const childrenLists = [];
|
|
@@ -549,7 +587,7 @@ function resolveAllReferences(schema, rootSchema, recurseList) {
|
|
|
549
587
|
resolvedSchema[PROPERTIES_KEY],
|
|
550
588
|
(result, value, key) => {
|
|
551
589
|
const childList = [...recurseList];
|
|
552
|
-
result[key] = resolveAllReferences(value, rootSchema, childList);
|
|
590
|
+
result[key] = resolveAllReferences(value, rootSchema, childList, baseURI);
|
|
553
591
|
childrenLists.push(childList);
|
|
554
592
|
},
|
|
555
593
|
{}
|
|
@@ -560,7 +598,7 @@ function resolveAllReferences(schema, rootSchema, recurseList) {
|
|
|
560
598
|
if (ITEMS_KEY in resolvedSchema && !Array.isArray(resolvedSchema.items) && typeof resolvedSchema.items !== "boolean") {
|
|
561
599
|
resolvedSchema = {
|
|
562
600
|
...resolvedSchema,
|
|
563
|
-
items: resolveAllReferences(resolvedSchema.items, rootSchema, recurseList)
|
|
601
|
+
items: resolveAllReferences(resolvedSchema.items, rootSchema, recurseList, baseURI)
|
|
564
602
|
};
|
|
565
603
|
}
|
|
566
604
|
return deepEquals(schema, resolvedSchema) ? schema : resolvedSchema;
|
|
@@ -577,12 +615,12 @@ function stubExistingAdditionalProperties(validator, theSchema, rootSchema, aFor
|
|
|
577
615
|
}
|
|
578
616
|
if (PATTERN_PROPERTIES_KEY in schema) {
|
|
579
617
|
const matchingProperties = getMatchingPatternProperties(schema, key);
|
|
580
|
-
if (!
|
|
618
|
+
if (!isEmpty2(matchingProperties)) {
|
|
581
619
|
schema.properties[key] = retrieveSchema(
|
|
582
620
|
validator,
|
|
583
621
|
{ allOf: Object.values(matchingProperties) },
|
|
584
622
|
rootSchema,
|
|
585
|
-
formData,
|
|
623
|
+
get5(formData, [key]),
|
|
586
624
|
experimental_customMergeAllOf
|
|
587
625
|
);
|
|
588
626
|
set(schema.properties, [key, ADDITIONAL_PROPERTY_FLAG], true);
|
|
@@ -595,7 +633,7 @@ function stubExistingAdditionalProperties(validator, theSchema, rootSchema, aFor
|
|
|
595
633
|
if (REF_KEY in schema.additionalProperties) {
|
|
596
634
|
additionalProperties = retrieveSchema(
|
|
597
635
|
validator,
|
|
598
|
-
{ $ref:
|
|
636
|
+
{ $ref: get5(schema.additionalProperties, [REF_KEY]) },
|
|
599
637
|
rootSchema,
|
|
600
638
|
formData,
|
|
601
639
|
experimental_customMergeAllOf
|
|
@@ -608,10 +646,10 @@ function stubExistingAdditionalProperties(validator, theSchema, rootSchema, aFor
|
|
|
608
646
|
...schema.additionalProperties
|
|
609
647
|
};
|
|
610
648
|
} else {
|
|
611
|
-
additionalProperties = { type: guessType(
|
|
649
|
+
additionalProperties = { type: guessType(get5(formData, [key])) };
|
|
612
650
|
}
|
|
613
651
|
} else {
|
|
614
|
-
additionalProperties = { type: guessType(
|
|
652
|
+
additionalProperties = { type: guessType(get5(formData, [key])) };
|
|
615
653
|
}
|
|
616
654
|
schema.properties[key] = additionalProperties;
|
|
617
655
|
set(schema.properties, [key, ADDITIONAL_PROPERTY_FLAG], true);
|
|
@@ -667,7 +705,10 @@ function retrieveSchemaInternal(validator, schema, rootSchema, rawFormData, expa
|
|
|
667
705
|
resolvedSchema = { ...resolvedSchema, allOf: withoutContainsSchemas };
|
|
668
706
|
}
|
|
669
707
|
resolvedSchema = experimental_customMergeAllOf ? experimental_customMergeAllOf(resolvedSchema) : mergeAllOf(resolvedSchema, {
|
|
670
|
-
deep: false
|
|
708
|
+
deep: false,
|
|
709
|
+
resolvers: {
|
|
710
|
+
$defs: mergeAllOf.options.resolvers.definitions
|
|
711
|
+
}
|
|
671
712
|
});
|
|
672
713
|
if (withContainsSchemas.length) {
|
|
673
714
|
resolvedSchema.allOf = withContainsSchemas;
|
|
@@ -682,12 +723,12 @@ function retrieveSchemaInternal(validator, schema, rootSchema, rawFormData, expa
|
|
|
682
723
|
resolvedSchema = Object.keys(resolvedSchema.properties).reduce(
|
|
683
724
|
(schema2, key) => {
|
|
684
725
|
const matchingProperties = getMatchingPatternProperties(schema2, key);
|
|
685
|
-
if (!
|
|
726
|
+
if (!isEmpty2(matchingProperties)) {
|
|
686
727
|
schema2.properties[key] = retrieveSchema(
|
|
687
728
|
validator,
|
|
688
729
|
{ allOf: [schema2.properties[key], ...Object.values(matchingProperties)] },
|
|
689
730
|
rootSchema,
|
|
690
|
-
rawFormData,
|
|
731
|
+
get5(rawFormData, [key]),
|
|
691
732
|
experimental_customMergeAllOf
|
|
692
733
|
);
|
|
693
734
|
}
|
|
@@ -759,7 +800,7 @@ function resolveDependencies(validator, schema, rootSchema, expandAllBranches, r
|
|
|
759
800
|
function processDependencies(validator, dependencies, resolvedSchema, rootSchema, expandAllBranches, recurseList, formData, experimental_customMergeAllOf) {
|
|
760
801
|
let schemas = [resolvedSchema];
|
|
761
802
|
for (const dependencyKey in dependencies) {
|
|
762
|
-
if (!expandAllBranches &&
|
|
803
|
+
if (!expandAllBranches && get5(formData, [dependencyKey]) === void 0) {
|
|
763
804
|
continue;
|
|
764
805
|
}
|
|
765
806
|
if (resolvedSchema.properties && !(dependencyKey in resolvedSchema.properties)) {
|
|
@@ -890,11 +931,11 @@ function findSelectedOptionInXxxOf(validator, rootSchema, schema, fallbackField,
|
|
|
890
931
|
const xxxOfs = schema[xxx].map(
|
|
891
932
|
(xxxOf) => retrieveSchema(validator, xxxOf, rootSchema, formData, experimental_customMergeAllOf)
|
|
892
933
|
);
|
|
893
|
-
const data =
|
|
934
|
+
const data = get6(formData, selectorField);
|
|
894
935
|
if (data !== void 0) {
|
|
895
936
|
return xxxOfs.find((xxx2) => {
|
|
896
937
|
return isEqual(
|
|
897
|
-
|
|
938
|
+
get6(xxx2, [PROPERTIES_KEY, selectorField, DEFAULT_KEY], get6(xxx2, [PROPERTIES_KEY, selectorField, CONST_KEY])),
|
|
898
939
|
data
|
|
899
940
|
);
|
|
900
941
|
});
|
|
@@ -904,21 +945,21 @@ function findSelectedOptionInXxxOf(validator, rootSchema, schema, fallbackField,
|
|
|
904
945
|
}
|
|
905
946
|
|
|
906
947
|
// src/schema/getFromSchema.ts
|
|
907
|
-
import
|
|
948
|
+
import get7 from "lodash/get";
|
|
908
949
|
import has2 from "lodash/has";
|
|
909
|
-
import
|
|
950
|
+
import isEmpty3 from "lodash/isEmpty";
|
|
910
951
|
function getFromSchemaInternal(validator, rootSchema, schema, path, experimental_customMergeAllOf) {
|
|
911
952
|
let fieldSchema = schema;
|
|
912
953
|
if (has2(schema, REF_KEY)) {
|
|
913
954
|
fieldSchema = retrieveSchema(validator, schema, rootSchema, void 0, experimental_customMergeAllOf);
|
|
914
955
|
}
|
|
915
|
-
if (
|
|
956
|
+
if (isEmpty3(path)) {
|
|
916
957
|
return fieldSchema;
|
|
917
958
|
}
|
|
918
959
|
const pathList = Array.isArray(path) ? path : path.split(".");
|
|
919
960
|
const [part, ...nestedPath] = pathList;
|
|
920
961
|
if (part && has2(fieldSchema, part)) {
|
|
921
|
-
fieldSchema =
|
|
962
|
+
fieldSchema = get7(fieldSchema, part);
|
|
922
963
|
return getFromSchemaInternal(
|
|
923
964
|
validator,
|
|
924
965
|
rootSchema,
|
|
@@ -960,7 +1001,7 @@ function findFieldInSchema(validator, rootSchema, schema, path, formData = {}, e
|
|
|
960
1001
|
parentField,
|
|
961
1002
|
fieldName,
|
|
962
1003
|
ONE_OF_KEY,
|
|
963
|
-
|
|
1004
|
+
get8(formData, subPath),
|
|
964
1005
|
experimental_customMergeAllOf
|
|
965
1006
|
);
|
|
966
1007
|
} else if (has3(parentField, ANY_OF_KEY)) {
|
|
@@ -970,7 +1011,7 @@ function findFieldInSchema(validator, rootSchema, schema, path, formData = {}, e
|
|
|
970
1011
|
parentField,
|
|
971
1012
|
fieldName,
|
|
972
1013
|
ANY_OF_KEY,
|
|
973
|
-
|
|
1014
|
+
get8(formData, subPath),
|
|
974
1015
|
experimental_customMergeAllOf
|
|
975
1016
|
);
|
|
976
1017
|
}
|
|
@@ -1024,14 +1065,14 @@ function findFieldInSchema(validator, rootSchema, schema, path, formData = {}, e
|
|
|
1024
1065
|
}
|
|
1025
1066
|
|
|
1026
1067
|
// src/schema/getDefaultFormState.ts
|
|
1027
|
-
import
|
|
1028
|
-
import
|
|
1068
|
+
import get12 from "lodash/get";
|
|
1069
|
+
import isEmpty4 from "lodash/isEmpty";
|
|
1029
1070
|
|
|
1030
1071
|
// src/schema/getClosestMatchingOption.ts
|
|
1031
|
-
import
|
|
1072
|
+
import get9 from "lodash/get";
|
|
1032
1073
|
import has4 from "lodash/has";
|
|
1033
1074
|
import isNumber2 from "lodash/isNumber";
|
|
1034
|
-
import
|
|
1075
|
+
import isObject3 from "lodash/isObject";
|
|
1035
1076
|
import isString2 from "lodash/isString";
|
|
1036
1077
|
import reduce from "lodash/reduce";
|
|
1037
1078
|
import times2 from "lodash/times";
|
|
@@ -1047,11 +1088,11 @@ var JUNK_OPTION = {
|
|
|
1047
1088
|
function calculateIndexScore(validator, rootSchema, schema, formData, experimental_customMergeAllOf) {
|
|
1048
1089
|
let totalScore = 0;
|
|
1049
1090
|
if (schema) {
|
|
1050
|
-
if (
|
|
1091
|
+
if (isObject3(schema.properties)) {
|
|
1051
1092
|
totalScore += reduce(
|
|
1052
1093
|
schema.properties,
|
|
1053
1094
|
(score, value, key) => {
|
|
1054
|
-
const formValue =
|
|
1095
|
+
const formValue = get9(formData, key);
|
|
1055
1096
|
if (typeof value === "boolean") {
|
|
1056
1097
|
return score;
|
|
1057
1098
|
}
|
|
@@ -1078,14 +1119,14 @@ function calculateIndexScore(validator, rootSchema, schema, formData, experiment
|
|
|
1078
1119
|
validator,
|
|
1079
1120
|
rootSchema,
|
|
1080
1121
|
formValue,
|
|
1081
|
-
|
|
1122
|
+
get9(value, key2),
|
|
1082
1123
|
-1,
|
|
1083
1124
|
discriminator,
|
|
1084
1125
|
experimental_customMergeAllOf
|
|
1085
1126
|
);
|
|
1086
1127
|
}
|
|
1087
1128
|
if (value.type === "object") {
|
|
1088
|
-
if (
|
|
1129
|
+
if (isObject3(formValue)) {
|
|
1089
1130
|
score += 1;
|
|
1090
1131
|
}
|
|
1091
1132
|
return score + calculateIndexScore(validator, rootSchema, value, formValue, experimental_customMergeAllOf);
|
|
@@ -1157,7 +1198,7 @@ function isFixedItems(schema) {
|
|
|
1157
1198
|
}
|
|
1158
1199
|
|
|
1159
1200
|
// src/mergeDefaultsWithFormData.ts
|
|
1160
|
-
import
|
|
1201
|
+
import get10 from "lodash/get";
|
|
1161
1202
|
import isNil from "lodash/isNil";
|
|
1162
1203
|
function mergeDefaultsWithFormData(defaults, formData, mergeExtraArrayDefaults = false, defaultSupercedesUndefined = false, overrideFormDataWithDefaults = false) {
|
|
1163
1204
|
if (Array.isArray(formData)) {
|
|
@@ -1184,11 +1225,22 @@ function mergeDefaultsWithFormData(defaults, formData, mergeExtraArrayDefaults =
|
|
|
1184
1225
|
if (isObject(formData)) {
|
|
1185
1226
|
const acc = Object.assign({}, defaults);
|
|
1186
1227
|
return Object.keys(formData).reduce((acc2, key) => {
|
|
1187
|
-
const keyValue =
|
|
1228
|
+
const keyValue = get10(formData, key);
|
|
1188
1229
|
const keyExistsInDefaults = isObject(defaults) && key in defaults;
|
|
1189
1230
|
const keyExistsInFormData = key in formData;
|
|
1231
|
+
const keyDefault = get10(defaults, key) ?? {};
|
|
1232
|
+
const defaultValueIsNestedObject = keyExistsInDefaults && Object.entries(keyDefault).some(([, v]) => isObject(v));
|
|
1233
|
+
const keyDefaultIsObject = keyExistsInDefaults && isObject(get10(defaults, key));
|
|
1234
|
+
const keyHasFormDataObject = keyExistsInFormData && isObject(keyValue);
|
|
1235
|
+
if (keyDefaultIsObject && keyHasFormDataObject && !defaultValueIsNestedObject) {
|
|
1236
|
+
acc2[key] = {
|
|
1237
|
+
...get10(defaults, key),
|
|
1238
|
+
...keyValue
|
|
1239
|
+
};
|
|
1240
|
+
return acc2;
|
|
1241
|
+
}
|
|
1190
1242
|
acc2[key] = mergeDefaultsWithFormData(
|
|
1191
|
-
|
|
1243
|
+
get10(defaults, key) ?? {},
|
|
1192
1244
|
keyValue,
|
|
1193
1245
|
mergeExtraArrayDefaults,
|
|
1194
1246
|
defaultSupercedesUndefined,
|
|
@@ -1267,7 +1319,7 @@ function constIsAjvDataReference(schema) {
|
|
|
1267
1319
|
}
|
|
1268
1320
|
|
|
1269
1321
|
// src/optionsList.ts
|
|
1270
|
-
import
|
|
1322
|
+
import get11 from "lodash/get";
|
|
1271
1323
|
|
|
1272
1324
|
// src/toConstant.ts
|
|
1273
1325
|
function toConstant(schema) {
|
|
@@ -1313,8 +1365,8 @@ function optionsList(schema, uiSchema) {
|
|
|
1313
1365
|
let value;
|
|
1314
1366
|
let label = title;
|
|
1315
1367
|
if (selectorField) {
|
|
1316
|
-
const innerSchema =
|
|
1317
|
-
value =
|
|
1368
|
+
const innerSchema = get11(aSchema, [PROPERTIES_KEY, selectorField], {});
|
|
1369
|
+
value = get11(innerSchema, DEFAULT_KEY, get11(innerSchema, CONST_KEY));
|
|
1318
1370
|
label = label || innerSchema?.title || aSchema.title || String(value);
|
|
1319
1371
|
} else {
|
|
1320
1372
|
value = toConstant(aSchema);
|
|
@@ -1354,10 +1406,10 @@ function maybeAddDefaultToObject(obj, key, computedDefault, includeUndefinedValu
|
|
|
1354
1406
|
const isSelfOrParentRequired = isParentRequired === void 0 ? requiredFields.includes(key) : isParentRequired;
|
|
1355
1407
|
if (isObject(computedDefault)) {
|
|
1356
1408
|
if (emptyObjectFields === "skipEmptyDefaults") {
|
|
1357
|
-
if (!
|
|
1409
|
+
if (!isEmpty4(computedDefault)) {
|
|
1358
1410
|
obj[key] = computedDefault;
|
|
1359
1411
|
}
|
|
1360
|
-
} else if ((!
|
|
1412
|
+
} else if ((!isEmpty4(computedDefault) || requiredFields.includes(key)) && (isSelfOrParentRequired || emptyObjectFields !== "populateRequiredDefaults")) {
|
|
1361
1413
|
obj[key] = computedDefault;
|
|
1362
1414
|
}
|
|
1363
1415
|
} else if (
|
|
@@ -1383,17 +1435,17 @@ function computeDefaults(validator, rawSchema, computeDefaultsProps = {}) {
|
|
|
1383
1435
|
required,
|
|
1384
1436
|
shouldMergeDefaultsIntoFormData = false
|
|
1385
1437
|
} = computeDefaultsProps;
|
|
1386
|
-
|
|
1438
|
+
let formData = isObject(rawFormData) ? rawFormData : {};
|
|
1387
1439
|
const schema = isObject(rawSchema) ? rawSchema : {};
|
|
1388
1440
|
let defaults = parentDefaults;
|
|
1389
1441
|
let schemaToCompute = null;
|
|
1390
1442
|
let experimental_dfsb_to_compute = experimental_defaultFormStateBehavior;
|
|
1391
1443
|
let updatedRecurseList = _recurseList;
|
|
1392
|
-
if (schema[CONST_KEY] && experimental_defaultFormStateBehavior?.constAsDefaults !== "never" && !constIsAjvDataReference(schema)) {
|
|
1444
|
+
if (schema[CONST_KEY] !== void 0 && experimental_defaultFormStateBehavior?.constAsDefaults !== "never" && !constIsAjvDataReference(schema)) {
|
|
1393
1445
|
defaults = schema[CONST_KEY];
|
|
1394
1446
|
} else if (isObject(defaults) && isObject(schema.default)) {
|
|
1395
1447
|
defaults = mergeObjects(defaults, schema.default);
|
|
1396
|
-
} else if (DEFAULT_KEY in schema && !schema[ANY_OF_KEY] && !schema[ONE_OF_KEY]) {
|
|
1448
|
+
} else if (DEFAULT_KEY in schema && !schema[ANY_OF_KEY] && !schema[ONE_OF_KEY] && !schema[REF_KEY]) {
|
|
1397
1449
|
defaults = schema.default;
|
|
1398
1450
|
} else if (REF_KEY in schema) {
|
|
1399
1451
|
const refName = schema[REF_KEY];
|
|
@@ -1401,6 +1453,12 @@ function computeDefaults(validator, rawSchema, computeDefaultsProps = {}) {
|
|
|
1401
1453
|
updatedRecurseList = _recurseList.concat(refName);
|
|
1402
1454
|
schemaToCompute = findSchemaDefinition(refName, rootSchema);
|
|
1403
1455
|
}
|
|
1456
|
+
if (schemaToCompute && !defaults) {
|
|
1457
|
+
defaults = schema.default;
|
|
1458
|
+
}
|
|
1459
|
+
if (shouldMergeDefaultsIntoFormData && schemaToCompute && !isObject(rawFormData)) {
|
|
1460
|
+
formData = rawFormData;
|
|
1461
|
+
}
|
|
1404
1462
|
} else if (DEPENDENCIES_KEY in schema) {
|
|
1405
1463
|
const defaultFormData = {
|
|
1406
1464
|
...getDefaultBasedOnSchemaType(validator, schema, computeDefaultsProps, defaults),
|
|
@@ -1478,7 +1536,7 @@ function computeDefaults(validator, rawSchema, computeDefaultsProps = {}) {
|
|
|
1478
1536
|
experimental_defaultFormStateBehavior: experimental_dfsb_to_compute,
|
|
1479
1537
|
experimental_customMergeAllOf,
|
|
1480
1538
|
parentDefaults: defaults,
|
|
1481
|
-
rawFormData: formData,
|
|
1539
|
+
rawFormData: rawFormData ?? formData,
|
|
1482
1540
|
required,
|
|
1483
1541
|
shouldMergeDefaultsIntoFormData
|
|
1484
1542
|
});
|
|
@@ -1541,7 +1599,7 @@ function getObjectDefaults(validator, rawSchema, {
|
|
|
1541
1599
|
const parentConst = retrievedSchema[CONST_KEY];
|
|
1542
1600
|
const objectDefaults = Object.keys(retrievedSchema.properties || {}).reduce(
|
|
1543
1601
|
(acc, key) => {
|
|
1544
|
-
const propertySchema =
|
|
1602
|
+
const propertySchema = get12(retrievedSchema, [PROPERTIES_KEY, key], {});
|
|
1545
1603
|
const hasParentConst = isObject(parentConst) && parentConst[key] !== void 0;
|
|
1546
1604
|
const hasConst = (isObject(propertySchema) && CONST_KEY in propertySchema || hasParentConst) && experimental_defaultFormStateBehavior?.constAsDefaults !== "never" && !constIsAjvDataReference(propertySchema);
|
|
1547
1605
|
const computedDefault = computeDefaults(validator, propertySchema, {
|
|
@@ -1550,8 +1608,8 @@ function getObjectDefaults(validator, rawSchema, {
|
|
|
1550
1608
|
experimental_defaultFormStateBehavior,
|
|
1551
1609
|
experimental_customMergeAllOf,
|
|
1552
1610
|
includeUndefinedValues: includeUndefinedValues === true,
|
|
1553
|
-
parentDefaults:
|
|
1554
|
-
rawFormData:
|
|
1611
|
+
parentDefaults: get12(defaults, [key]),
|
|
1612
|
+
rawFormData: get12(formData, [key]),
|
|
1555
1613
|
required: retrievedSchema.required?.includes(key),
|
|
1556
1614
|
shouldMergeDefaultsIntoFormData
|
|
1557
1615
|
});
|
|
@@ -1587,8 +1645,8 @@ function getObjectDefaults(validator, rawSchema, {
|
|
|
1587
1645
|
experimental_defaultFormStateBehavior,
|
|
1588
1646
|
experimental_customMergeAllOf,
|
|
1589
1647
|
includeUndefinedValues: includeUndefinedValues === true,
|
|
1590
|
-
parentDefaults:
|
|
1591
|
-
rawFormData:
|
|
1648
|
+
parentDefaults: get12(defaults, [key]),
|
|
1649
|
+
rawFormData: get12(formData, [key]),
|
|
1592
1650
|
required: retrievedSchema.required?.includes(key),
|
|
1593
1651
|
shouldMergeDefaultsIntoFormData
|
|
1594
1652
|
});
|
|
@@ -1649,7 +1707,7 @@ function getArrayDefaults(validator, rawSchema, {
|
|
|
1649
1707
|
experimental_defaultFormStateBehavior,
|
|
1650
1708
|
experimental_customMergeAllOf,
|
|
1651
1709
|
rawFormData: item,
|
|
1652
|
-
parentDefaults:
|
|
1710
|
+
parentDefaults: get12(defaults, [idx]),
|
|
1653
1711
|
required,
|
|
1654
1712
|
shouldMergeDefaultsIntoFormData
|
|
1655
1713
|
});
|
|
@@ -1711,6 +1769,12 @@ function getDefaultFormState(validator, theSchema, formData, rootSchema, include
|
|
|
1711
1769
|
rawFormData: formData,
|
|
1712
1770
|
shouldMergeDefaultsIntoFormData: true
|
|
1713
1771
|
});
|
|
1772
|
+
if (schema.type !== "object" && isObject(schema.default)) {
|
|
1773
|
+
return {
|
|
1774
|
+
...defaults,
|
|
1775
|
+
...formData
|
|
1776
|
+
};
|
|
1777
|
+
}
|
|
1714
1778
|
if (isObject(formData) || Array.isArray(formData)) {
|
|
1715
1779
|
const { mergeDefaultsIntoFormData } = experimental_defaultFormStateBehavior || {};
|
|
1716
1780
|
const defaultSupercedesUndefined = mergeDefaultsIntoFormData === "useDefaultIfFormDataUndefined";
|
|
@@ -1777,7 +1841,7 @@ function getDisplayLabel(validator, schema, uiSchema = {}, rootSchema, globalOpt
|
|
|
1777
1841
|
}
|
|
1778
1842
|
|
|
1779
1843
|
// src/schema/sanitizeDataForNewSchema.ts
|
|
1780
|
-
import
|
|
1844
|
+
import get13 from "lodash/get";
|
|
1781
1845
|
import has5 from "lodash/has";
|
|
1782
1846
|
var NO_VALUE = Symbol("no Value");
|
|
1783
1847
|
function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, data = {}, experimental_customMergeAllOf) {
|
|
@@ -1785,19 +1849,19 @@ function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, d
|
|
|
1785
1849
|
if (has5(newSchema, PROPERTIES_KEY)) {
|
|
1786
1850
|
const removeOldSchemaData = {};
|
|
1787
1851
|
if (has5(oldSchema, PROPERTIES_KEY)) {
|
|
1788
|
-
const properties =
|
|
1852
|
+
const properties = get13(oldSchema, PROPERTIES_KEY, {});
|
|
1789
1853
|
Object.keys(properties).forEach((key) => {
|
|
1790
1854
|
if (has5(data, key)) {
|
|
1791
1855
|
removeOldSchemaData[key] = void 0;
|
|
1792
1856
|
}
|
|
1793
1857
|
});
|
|
1794
1858
|
}
|
|
1795
|
-
const keys2 = Object.keys(
|
|
1859
|
+
const keys2 = Object.keys(get13(newSchema, PROPERTIES_KEY, {}));
|
|
1796
1860
|
const nestedData = {};
|
|
1797
1861
|
keys2.forEach((key) => {
|
|
1798
|
-
const formValue =
|
|
1799
|
-
let oldKeyedSchema =
|
|
1800
|
-
let newKeyedSchema =
|
|
1862
|
+
const formValue = get13(data, key);
|
|
1863
|
+
let oldKeyedSchema = get13(oldSchema, [PROPERTIES_KEY, key], {});
|
|
1864
|
+
let newKeyedSchema = get13(newSchema, [PROPERTIES_KEY, key], {});
|
|
1801
1865
|
if (has5(oldKeyedSchema, REF_KEY)) {
|
|
1802
1866
|
oldKeyedSchema = retrieveSchema(
|
|
1803
1867
|
validator,
|
|
@@ -1816,8 +1880,8 @@ function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, d
|
|
|
1816
1880
|
experimental_customMergeAllOf
|
|
1817
1881
|
);
|
|
1818
1882
|
}
|
|
1819
|
-
const oldSchemaTypeForKey =
|
|
1820
|
-
const newSchemaTypeForKey =
|
|
1883
|
+
const oldSchemaTypeForKey = get13(oldKeyedSchema, "type");
|
|
1884
|
+
const newSchemaTypeForKey = get13(newKeyedSchema, "type");
|
|
1821
1885
|
if (!oldSchemaTypeForKey || oldSchemaTypeForKey === newSchemaTypeForKey) {
|
|
1822
1886
|
if (has5(removeOldSchemaData, key)) {
|
|
1823
1887
|
delete removeOldSchemaData[key];
|
|
@@ -1835,17 +1899,17 @@ function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, d
|
|
|
1835
1899
|
nestedData[key] = itemData;
|
|
1836
1900
|
}
|
|
1837
1901
|
} else {
|
|
1838
|
-
const newOptionDefault =
|
|
1839
|
-
const oldOptionDefault =
|
|
1902
|
+
const newOptionDefault = get13(newKeyedSchema, "default", NO_VALUE);
|
|
1903
|
+
const oldOptionDefault = get13(oldKeyedSchema, "default", NO_VALUE);
|
|
1840
1904
|
if (newOptionDefault !== NO_VALUE && newOptionDefault !== formValue) {
|
|
1841
1905
|
if (oldOptionDefault === formValue) {
|
|
1842
1906
|
removeOldSchemaData[key] = newOptionDefault;
|
|
1843
|
-
} else if (
|
|
1907
|
+
} else if (get13(newKeyedSchema, "readOnly") === true) {
|
|
1844
1908
|
removeOldSchemaData[key] = void 0;
|
|
1845
1909
|
}
|
|
1846
1910
|
}
|
|
1847
|
-
const newOptionConst =
|
|
1848
|
-
const oldOptionConst =
|
|
1911
|
+
const newOptionConst = get13(newKeyedSchema, "const", NO_VALUE);
|
|
1912
|
+
const oldOptionConst = get13(oldKeyedSchema, "const", NO_VALUE);
|
|
1849
1913
|
if (newOptionConst !== NO_VALUE && newOptionConst !== formValue) {
|
|
1850
1914
|
removeOldSchemaData[key] = oldOptionConst === formValue ? newOptionConst : void 0;
|
|
1851
1915
|
}
|
|
@@ -1857,9 +1921,9 @@ function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, d
|
|
|
1857
1921
|
...removeOldSchemaData,
|
|
1858
1922
|
...nestedData
|
|
1859
1923
|
};
|
|
1860
|
-
} else if (
|
|
1861
|
-
let oldSchemaItems =
|
|
1862
|
-
let newSchemaItems =
|
|
1924
|
+
} else if (get13(oldSchema, "type") === "array" && get13(newSchema, "type") === "array" && Array.isArray(data)) {
|
|
1925
|
+
let oldSchemaItems = get13(oldSchema, "items");
|
|
1926
|
+
let newSchemaItems = get13(newSchema, "items");
|
|
1863
1927
|
if (typeof oldSchemaItems === "object" && typeof newSchemaItems === "object" && !Array.isArray(oldSchemaItems) && !Array.isArray(newSchemaItems)) {
|
|
1864
1928
|
if (has5(oldSchemaItems, REF_KEY)) {
|
|
1865
1929
|
oldSchemaItems = retrieveSchema(
|
|
@@ -1879,10 +1943,10 @@ function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, d
|
|
|
1879
1943
|
experimental_customMergeAllOf
|
|
1880
1944
|
);
|
|
1881
1945
|
}
|
|
1882
|
-
const oldSchemaType =
|
|
1883
|
-
const newSchemaType =
|
|
1946
|
+
const oldSchemaType = get13(oldSchemaItems, "type");
|
|
1947
|
+
const newSchemaType = get13(newSchemaItems, "type");
|
|
1884
1948
|
if (!oldSchemaType || oldSchemaType === newSchemaType) {
|
|
1885
|
-
const maxItems =
|
|
1949
|
+
const maxItems = get13(newSchema, "maxItems", -1);
|
|
1886
1950
|
if (newSchemaType === "object") {
|
|
1887
1951
|
newFormData = data.reduce((newValue, aValue) => {
|
|
1888
1952
|
const itemValue = sanitizeDataForNewSchema(
|
|
@@ -1910,7 +1974,7 @@ function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, d
|
|
|
1910
1974
|
}
|
|
1911
1975
|
|
|
1912
1976
|
// src/schema/toIdSchema.ts
|
|
1913
|
-
import
|
|
1977
|
+
import get14 from "lodash/get";
|
|
1914
1978
|
function toIdSchemaInternal(validator, schema, idPrefix, idSeparator, id, rootSchema, formData, _recurseList = [], experimental_customMergeAllOf) {
|
|
1915
1979
|
const $id = id || idPrefix;
|
|
1916
1980
|
const idSchema = { $id };
|
|
@@ -1932,10 +1996,10 @@ function toIdSchemaInternal(validator, schema, idPrefix, idSeparator, id, rootSc
|
|
|
1932
1996
|
);
|
|
1933
1997
|
}
|
|
1934
1998
|
}
|
|
1935
|
-
if (ITEMS_KEY in schema && !
|
|
1999
|
+
if (ITEMS_KEY in schema && !get14(schema, [ITEMS_KEY, REF_KEY])) {
|
|
1936
2000
|
return toIdSchemaInternal(
|
|
1937
2001
|
validator,
|
|
1938
|
-
|
|
2002
|
+
get14(schema, ITEMS_KEY),
|
|
1939
2003
|
idPrefix,
|
|
1940
2004
|
idSeparator,
|
|
1941
2005
|
id,
|
|
@@ -1958,7 +2022,7 @@ function toIdSchemaInternal(validator, schema, idPrefix, idSeparator, id, rootSc
|
|
|
1958
2022
|
rootSchema,
|
|
1959
2023
|
// It's possible that formData is not an object -- this can happen if an
|
|
1960
2024
|
// array item has just been added, but not populated with data yet
|
|
1961
|
-
|
|
2025
|
+
get14(formData, [name]),
|
|
1962
2026
|
_recurseList,
|
|
1963
2027
|
experimental_customMergeAllOf
|
|
1964
2028
|
);
|
|
@@ -1982,7 +2046,7 @@ function toIdSchema(validator, schema, id, rootSchema, formData, idPrefix = "roo
|
|
|
1982
2046
|
}
|
|
1983
2047
|
|
|
1984
2048
|
// src/schema/toPathSchema.ts
|
|
1985
|
-
import
|
|
2049
|
+
import get15 from "lodash/get";
|
|
1986
2050
|
import set2 from "lodash/set";
|
|
1987
2051
|
function toPathSchemaInternal(validator, schema, name, rootSchema, formData, _recurseList = [], experimental_customMergeAllOf) {
|
|
1988
2052
|
if (REF_KEY in schema || DEPENDENCIES_KEY in schema || ALL_OF_KEY in schema) {
|
|
@@ -2075,7 +2139,7 @@ function toPathSchemaInternal(validator, schema, name, rootSchema, formData, _re
|
|
|
2075
2139
|
}
|
|
2076
2140
|
} else if (PROPERTIES_KEY in schema) {
|
|
2077
2141
|
for (const property in schema.properties) {
|
|
2078
|
-
const field =
|
|
2142
|
+
const field = get15(schema, [PROPERTIES_KEY, property], {});
|
|
2079
2143
|
pathSchema[property] = toPathSchemaInternal(
|
|
2080
2144
|
validator,
|
|
2081
2145
|
field,
|
|
@@ -2083,7 +2147,7 @@ function toPathSchemaInternal(validator, schema, name, rootSchema, formData, _re
|
|
|
2083
2147
|
rootSchema,
|
|
2084
2148
|
// It's possible that formData is not an object -- this can happen if an
|
|
2085
2149
|
// array item has just been added, but not populated with data yet
|
|
2086
|
-
|
|
2150
|
+
get15(formData, [property]),
|
|
2087
2151
|
_recurseList,
|
|
2088
2152
|
experimental_customMergeAllOf
|
|
2089
2153
|
);
|
|
@@ -2501,7 +2565,7 @@ function enumOptionsSelectValue(valueIndex, selected, allEnumOptions = []) {
|
|
|
2501
2565
|
|
|
2502
2566
|
// src/ErrorSchemaBuilder.ts
|
|
2503
2567
|
import cloneDeep from "lodash/cloneDeep";
|
|
2504
|
-
import
|
|
2568
|
+
import get16 from "lodash/get";
|
|
2505
2569
|
import set3 from "lodash/set";
|
|
2506
2570
|
import setWith from "lodash/setWith";
|
|
2507
2571
|
var ErrorSchemaBuilder = class {
|
|
@@ -2530,7 +2594,7 @@ var ErrorSchemaBuilder = class {
|
|
|
2530
2594
|
*/
|
|
2531
2595
|
getOrCreateErrorBlock(pathOfError) {
|
|
2532
2596
|
const hasPath = Array.isArray(pathOfError) && pathOfError.length > 0 || typeof pathOfError === "string";
|
|
2533
|
-
let errorBlock = hasPath ?
|
|
2597
|
+
let errorBlock = hasPath ? get16(this.errorSchema, pathOfError) : this.errorSchema;
|
|
2534
2598
|
if (!errorBlock && pathOfError) {
|
|
2535
2599
|
errorBlock = {};
|
|
2536
2600
|
setWith(this.errorSchema, pathOfError, errorBlock, Object);
|
|
@@ -2556,7 +2620,7 @@ var ErrorSchemaBuilder = class {
|
|
|
2556
2620
|
*/
|
|
2557
2621
|
addErrors(errorOrList, pathOfError) {
|
|
2558
2622
|
const errorBlock = this.getOrCreateErrorBlock(pathOfError);
|
|
2559
|
-
let errorsList =
|
|
2623
|
+
let errorsList = get16(errorBlock, ERRORS_KEY);
|
|
2560
2624
|
if (!Array.isArray(errorsList)) {
|
|
2561
2625
|
errorsList = [];
|
|
2562
2626
|
errorBlock[ERRORS_KEY] = errorsList;
|
|
@@ -2705,9 +2769,9 @@ function getTemplate(name, registry, uiOptions = {}) {
|
|
|
2705
2769
|
|
|
2706
2770
|
// src/getTestIds.ts
|
|
2707
2771
|
import { nanoid } from "nanoid";
|
|
2708
|
-
import
|
|
2772
|
+
import get17 from "lodash/get";
|
|
2709
2773
|
function getTestIds() {
|
|
2710
|
-
if (typeof process === "undefined" ||
|
|
2774
|
+
if (typeof process === "undefined" || get17(process, "env.NODE_ENV") !== "test") {
|
|
2711
2775
|
return {};
|
|
2712
2776
|
}
|
|
2713
2777
|
const ids = /* @__PURE__ */ new Map();
|
|
@@ -2727,7 +2791,7 @@ function getTestIds() {
|
|
|
2727
2791
|
// src/getWidget.tsx
|
|
2728
2792
|
import { createElement } from "react";
|
|
2729
2793
|
import ReactIs from "react-is";
|
|
2730
|
-
import
|
|
2794
|
+
import get18 from "lodash/get";
|
|
2731
2795
|
import set4 from "lodash/set";
|
|
2732
2796
|
import { jsx } from "react/jsx-runtime";
|
|
2733
2797
|
var widgetMap = {
|
|
@@ -2783,7 +2847,7 @@ var widgetMap = {
|
|
|
2783
2847
|
}
|
|
2784
2848
|
};
|
|
2785
2849
|
function mergeWidgetOptions(AWidget) {
|
|
2786
|
-
let MergedWidget =
|
|
2850
|
+
let MergedWidget = get18(AWidget, "MergedWidget");
|
|
2787
2851
|
if (!MergedWidget) {
|
|
2788
2852
|
const defaultOptions = AWidget.defaultProps && AWidget.defaultProps.options || {};
|
|
2789
2853
|
MergedWidget = ({ options, ...props }) => {
|
|
@@ -2896,14 +2960,14 @@ function localToUTC(dateString) {
|
|
|
2896
2960
|
}
|
|
2897
2961
|
|
|
2898
2962
|
// src/lookupFromFormContext.ts
|
|
2899
|
-
import
|
|
2963
|
+
import get19 from "lodash/get";
|
|
2900
2964
|
import has6 from "lodash/has";
|
|
2901
2965
|
function lookupFromFormContext(regOrFc, toLookup, fallback) {
|
|
2902
2966
|
const lookupPath = [LOOKUP_MAP_NAME];
|
|
2903
2967
|
if (has6(regOrFc, FORM_CONTEXT_NAME)) {
|
|
2904
2968
|
lookupPath.unshift(FORM_CONTEXT_NAME);
|
|
2905
2969
|
}
|
|
2906
|
-
return
|
|
2970
|
+
return get19(regOrFc, [...lookupPath, toLookup], fallback);
|
|
2907
2971
|
}
|
|
2908
2972
|
|
|
2909
2973
|
// src/orderProperties.ts
|
|
@@ -3082,7 +3146,7 @@ function utcToLocal(jsonDate) {
|
|
|
3082
3146
|
}
|
|
3083
3147
|
|
|
3084
3148
|
// src/validationDataMerge.ts
|
|
3085
|
-
import
|
|
3149
|
+
import isEmpty5 from "lodash/isEmpty";
|
|
3086
3150
|
function validationDataMerge(validationData, additionalErrorSchema) {
|
|
3087
3151
|
if (!additionalErrorSchema) {
|
|
3088
3152
|
return validationData;
|
|
@@ -3090,7 +3154,7 @@ function validationDataMerge(validationData, additionalErrorSchema) {
|
|
|
3090
3154
|
const { errors: oldErrors, errorSchema: oldErrorSchema } = validationData;
|
|
3091
3155
|
let errors = toErrorList(additionalErrorSchema);
|
|
3092
3156
|
let errorSchema = additionalErrorSchema;
|
|
3093
|
-
if (!
|
|
3157
|
+
if (!isEmpty5(oldErrorSchema)) {
|
|
3094
3158
|
errorSchema = mergeObjects(oldErrorSchema, additionalErrorSchema, true);
|
|
3095
3159
|
errors = [...oldErrors].concat(errors);
|
|
3096
3160
|
}
|
|
@@ -3098,7 +3162,7 @@ function validationDataMerge(validationData, additionalErrorSchema) {
|
|
|
3098
3162
|
}
|
|
3099
3163
|
|
|
3100
3164
|
// src/withIdRefPrefix.ts
|
|
3101
|
-
import
|
|
3165
|
+
import isObject4 from "lodash/isObject";
|
|
3102
3166
|
function withIdRefPrefixObject(node) {
|
|
3103
3167
|
for (const key in node) {
|
|
3104
3168
|
const realObj = node;
|
|
@@ -3121,7 +3185,7 @@ function withIdRefPrefix(schemaNode) {
|
|
|
3121
3185
|
if (Array.isArray(schemaNode)) {
|
|
3122
3186
|
return withIdRefPrefixArray([...schemaNode]);
|
|
3123
3187
|
}
|
|
3124
|
-
if (
|
|
3188
|
+
if (isObject4(schemaNode)) {
|
|
3125
3189
|
return withIdRefPrefixObject({ ...schemaNode });
|
|
3126
3190
|
}
|
|
3127
3191
|
return schemaNode;
|
|
@@ -3131,7 +3195,7 @@ function withIdRefPrefix(schemaNode) {
|
|
|
3131
3195
|
import keys from "lodash/keys";
|
|
3132
3196
|
import pickBy from "lodash/pickBy";
|
|
3133
3197
|
import isPlainObject4 from "lodash/isPlainObject";
|
|
3134
|
-
import
|
|
3198
|
+
import get20 from "lodash/get";
|
|
3135
3199
|
import difference from "lodash/difference";
|
|
3136
3200
|
function getChangedFields(a, b) {
|
|
3137
3201
|
const aIsPlainObject = isPlainObject4(a);
|
|
@@ -3144,7 +3208,7 @@ function getChangedFields(a, b) {
|
|
|
3144
3208
|
} else if (!aIsPlainObject && bIsPlainObject) {
|
|
3145
3209
|
return keys(b);
|
|
3146
3210
|
} else {
|
|
3147
|
-
const unequalFields = keys(pickBy(a, (value, key) => !deepEquals(value,
|
|
3211
|
+
const unequalFields = keys(pickBy(a, (value, key) => !deepEquals(value, get20(b, key))));
|
|
3148
3212
|
const diffFields = difference(keys(b), keys(a));
|
|
3149
3213
|
return [...unequalFields, ...diffFields];
|
|
3150
3214
|
}
|
|
@@ -3189,7 +3253,7 @@ var TranslatableString = /* @__PURE__ */ ((TranslatableString2) => {
|
|
|
3189
3253
|
import forEach from "lodash/forEach";
|
|
3190
3254
|
|
|
3191
3255
|
// src/parser/ParserValidator.ts
|
|
3192
|
-
import
|
|
3256
|
+
import get21 from "lodash/get";
|
|
3193
3257
|
var ParserValidator = class {
|
|
3194
3258
|
/** Construct the ParserValidator for the given `rootSchema`. This `rootSchema` will be stashed in the `schemaMap`
|
|
3195
3259
|
* first.
|
|
@@ -3215,7 +3279,7 @@ var ParserValidator = class {
|
|
|
3215
3279
|
* @param hash - The hash value at which to map the schema
|
|
3216
3280
|
*/
|
|
3217
3281
|
addSchema(schema, hash) {
|
|
3218
|
-
const key =
|
|
3282
|
+
const key = get21(schema, ID_KEY, hash);
|
|
3219
3283
|
const identifiedSchema = { ...schema, [ID_KEY]: key };
|
|
3220
3284
|
const existing = this.schemaMap[key];
|
|
3221
3285
|
if (!existing) {
|
|
@@ -3322,6 +3386,7 @@ export {
|
|
|
3322
3386
|
ID_KEY,
|
|
3323
3387
|
IF_KEY,
|
|
3324
3388
|
ITEMS_KEY,
|
|
3389
|
+
JSON_SCHEMA_DRAFT_2020_12,
|
|
3325
3390
|
JUNK_OPTION_ID,
|
|
3326
3391
|
LOOKUP_MAP_NAME,
|
|
3327
3392
|
NAME_KEY,
|
|
@@ -3333,6 +3398,7 @@ export {
|
|
|
3333
3398
|
REQUIRED_KEY,
|
|
3334
3399
|
RJSF_ADDITIONAL_PROPERTIES_FLAG,
|
|
3335
3400
|
ROOT_SCHEMA_PREFIX,
|
|
3401
|
+
SCHEMA_KEY,
|
|
3336
3402
|
SUBMIT_BTN_OPTIONS_KEY,
|
|
3337
3403
|
TranslatableString,
|
|
3338
3404
|
UI_FIELD_KEY,
|