@rjsf/utils 5.9.0 → 5.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/utils.cjs.development.js +49 -28
- package/dist/utils.cjs.development.js.map +1 -1
- package/dist/utils.cjs.production.min.js +1 -1
- package/dist/utils.cjs.production.min.js.map +1 -1
- package/dist/utils.esm.js +49 -28
- package/dist/utils.esm.js.map +1 -1
- package/dist/utils.umd.development.js +49 -28
- package/dist/utils.umd.development.js.map +1 -1
- package/dist/utils.umd.production.min.js +1 -1
- package/dist/utils.umd.production.min.js.map +1 -1
- package/package.json +5 -5
|
@@ -549,11 +549,12 @@ function mergeSchemas(obj1, obj2) {
|
|
|
549
549
|
}, acc);
|
|
550
550
|
}
|
|
551
551
|
|
|
552
|
-
var _excluded$
|
|
553
|
-
_excluded2 = ["$ref"],
|
|
552
|
+
var _excluded$2 = ["if", "then", "else"],
|
|
553
|
+
_excluded2$1 = ["$ref"],
|
|
554
554
|
_excluded3 = ["allOf"],
|
|
555
|
-
_excluded4 = ["
|
|
556
|
-
_excluded5 = ["
|
|
555
|
+
_excluded4 = ["oneOf", "anyOf"],
|
|
556
|
+
_excluded5 = ["dependencies"],
|
|
557
|
+
_excluded6 = ["oneOf"];
|
|
557
558
|
/** Retrieves an expanded schema that has had all of its conditions, additional properties, references and dependencies
|
|
558
559
|
* resolved and merged into the `schema` given a `validator`, `rootSchema` and `rawFormData` that is used to do the
|
|
559
560
|
* potentially recursive resolution.
|
|
@@ -586,7 +587,7 @@ function resolveCondition(validator, schema, rootSchema, expandAllBranches, form
|
|
|
586
587
|
var expression = schema["if"],
|
|
587
588
|
then = schema.then,
|
|
588
589
|
otherwise = schema["else"],
|
|
589
|
-
resolvedSchemaLessConditional = _objectWithoutPropertiesLoose(schema, _excluded$
|
|
590
|
+
resolvedSchemaLessConditional = _objectWithoutPropertiesLoose(schema, _excluded$2);
|
|
590
591
|
var conditionValue = validator.isValid(expression, formData || {}, rootSchema);
|
|
591
592
|
var resolvedSchemas = [resolvedSchemaLessConditional];
|
|
592
593
|
var schemas = [];
|
|
@@ -696,7 +697,7 @@ function resolveSchema(validator, schema, rootSchema, expandAllBranches, formDat
|
|
|
696
697
|
function resolveReference(validator, schema, rootSchema, expandAllBranches, formData) {
|
|
697
698
|
// Drop the $ref property of the source schema.
|
|
698
699
|
var $ref = schema.$ref,
|
|
699
|
-
localSchema = _objectWithoutPropertiesLoose(schema, _excluded2);
|
|
700
|
+
localSchema = _objectWithoutPropertiesLoose(schema, _excluded2$1);
|
|
700
701
|
// Retrieve the referenced schema definition.
|
|
701
702
|
var refSchema = findSchemaDefinition($ref, rootSchema);
|
|
702
703
|
// Update referenced schema definition with local schema properties.
|
|
@@ -778,9 +779,9 @@ function retrieveSchemaInternal(validator, schema, rootSchema, rawFormData, expa
|
|
|
778
779
|
if (IF_KEY in resolvedSchema) {
|
|
779
780
|
return resolveCondition(validator, resolvedSchema, rootSchema, expandAllBranches, rawFormData);
|
|
780
781
|
}
|
|
781
|
-
if (ALL_OF_KEY in
|
|
782
|
+
if (ALL_OF_KEY in resolvedSchema) {
|
|
782
783
|
try {
|
|
783
|
-
resolvedSchema = mergeAllOf__default["default"](
|
|
784
|
+
resolvedSchema = mergeAllOf__default["default"](resolvedSchema, {
|
|
784
785
|
deep: false
|
|
785
786
|
});
|
|
786
787
|
} catch (e) {
|
|
@@ -815,10 +816,14 @@ function retrieveSchemaInternal(validator, schema, rootSchema, rawFormData, expa
|
|
|
815
816
|
*/
|
|
816
817
|
function resolveAnyOrOneOfSchemas(validator, schema, rootSchema, expandAllBranches, rawFormData) {
|
|
817
818
|
var anyOrOneOf;
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
819
|
+
var _schema = schema,
|
|
820
|
+
oneOf = _schema.oneOf,
|
|
821
|
+
anyOf = _schema.anyOf,
|
|
822
|
+
remaining = _objectWithoutPropertiesLoose(_schema, _excluded4);
|
|
823
|
+
if (Array.isArray(oneOf)) {
|
|
824
|
+
anyOrOneOf = oneOf;
|
|
825
|
+
} else if (Array.isArray(anyOf)) {
|
|
826
|
+
anyOrOneOf = anyOf;
|
|
822
827
|
}
|
|
823
828
|
if (anyOrOneOf) {
|
|
824
829
|
// Ensure that during expand all branches we pass an object rather than undefined so that all options are interrogated
|
|
@@ -834,9 +839,11 @@ function resolveAnyOrOneOfSchemas(validator, schema, rootSchema, expandAllBranch
|
|
|
834
839
|
// Call this to trigger the set of isValid() calls that the schema parser will need
|
|
835
840
|
var option = getFirstMatchingOption(validator, formData, anyOrOneOf, rootSchema, discriminator);
|
|
836
841
|
if (expandAllBranches) {
|
|
837
|
-
return anyOrOneOf
|
|
842
|
+
return anyOrOneOf.map(function (item) {
|
|
843
|
+
return _extends({}, remaining, item);
|
|
844
|
+
});
|
|
838
845
|
}
|
|
839
|
-
schema = anyOrOneOf[option];
|
|
846
|
+
schema = _extends({}, remaining, anyOrOneOf[option]);
|
|
840
847
|
}
|
|
841
848
|
return [schema];
|
|
842
849
|
}
|
|
@@ -854,7 +861,7 @@ function resolveAnyOrOneOfSchemas(validator, schema, rootSchema, expandAllBranch
|
|
|
854
861
|
function resolveDependencies(validator, schema, rootSchema, expandAllBranches, formData) {
|
|
855
862
|
// Drop the dependencies from the source schema.
|
|
856
863
|
var dependencies = schema.dependencies,
|
|
857
|
-
remainingSchema = _objectWithoutPropertiesLoose(schema,
|
|
864
|
+
remainingSchema = _objectWithoutPropertiesLoose(schema, _excluded5);
|
|
858
865
|
var resolvedSchemas = resolveAnyOrOneOfSchemas(validator, remainingSchema, rootSchema, expandAllBranches, formData);
|
|
859
866
|
return resolvedSchemas.flatMap(function (resolvedSchema) {
|
|
860
867
|
return processDependencies(validator, dependencies, resolvedSchema, rootSchema, expandAllBranches, formData);
|
|
@@ -937,7 +944,7 @@ function withDependentSchema(validator, schema, rootSchema, dependencyKey, depen
|
|
|
937
944
|
var dependentSchemas = retrieveSchemaInternal(validator, dependencyValue, rootSchema, formData, expandAllBranches);
|
|
938
945
|
return dependentSchemas.flatMap(function (dependent) {
|
|
939
946
|
var oneOf = dependent.oneOf,
|
|
940
|
-
dependentSchema = _objectWithoutPropertiesLoose(dependent,
|
|
947
|
+
dependentSchema = _objectWithoutPropertiesLoose(dependent, _excluded6);
|
|
941
948
|
schema = mergeSchemas(schema, dependentSchema);
|
|
942
949
|
// Since it does not contain oneOf, we return the original schema.
|
|
943
950
|
if (oneOf === undefined) {
|
|
@@ -1052,8 +1059,10 @@ function calculateIndexScore(validator, rootSchema, schema, formData) {
|
|
|
1052
1059
|
var newSchema = retrieveSchema(validator, value, rootSchema, formValue);
|
|
1053
1060
|
return score + calculateIndexScore(validator, rootSchema, newSchema, formValue || {});
|
|
1054
1061
|
}
|
|
1055
|
-
if (has__default["default"](value, ONE_OF_KEY) && formValue) {
|
|
1056
|
-
|
|
1062
|
+
if ((has__default["default"](value, ONE_OF_KEY) || has__default["default"](value, ANY_OF_KEY)) && formValue) {
|
|
1063
|
+
var _key = has__default["default"](value, ONE_OF_KEY) ? ONE_OF_KEY : ANY_OF_KEY;
|
|
1064
|
+
var discriminator = getDiscriminatorFieldFromSchema(value);
|
|
1065
|
+
return score + getClosestMatchingOption(validator, rootSchema, formValue, get__default["default"](value, _key), -1, discriminator);
|
|
1057
1066
|
}
|
|
1058
1067
|
if (value.type === 'object') {
|
|
1059
1068
|
return score + calculateIndexScore(validator, rootSchema, value, formValue || {});
|
|
@@ -1107,8 +1116,15 @@ function getClosestMatchingOption(validator, rootSchema, formData, options, sele
|
|
|
1107
1116
|
if (selectedOption === void 0) {
|
|
1108
1117
|
selectedOption = -1;
|
|
1109
1118
|
}
|
|
1119
|
+
// First resolve any refs in the options
|
|
1120
|
+
var resolvedOptions = options.map(function (option) {
|
|
1121
|
+
if (has__default["default"](option, REF_KEY)) {
|
|
1122
|
+
return retrieveSchema(validator, option, rootSchema, formData);
|
|
1123
|
+
}
|
|
1124
|
+
return option;
|
|
1125
|
+
});
|
|
1110
1126
|
// Reduce the array of options down to a list of the indexes that are considered matching options
|
|
1111
|
-
var allValidIndexes =
|
|
1127
|
+
var allValidIndexes = resolvedOptions.reduce(function (validList, option, index) {
|
|
1112
1128
|
var testOptions = [JUNK_OPTION, option];
|
|
1113
1129
|
var match = getFirstMatchingOption(validator, formData, testOptions, rootSchema, discriminatorField);
|
|
1114
1130
|
// The match is the real option, so add its index to list of valid indexes
|
|
@@ -1123,7 +1139,7 @@ function getClosestMatchingOption(validator, rootSchema, formData, options, sele
|
|
|
1123
1139
|
}
|
|
1124
1140
|
if (!allValidIndexes.length) {
|
|
1125
1141
|
// No indexes were valid, so we'll score all the options, add all the indexes
|
|
1126
|
-
times__default["default"](
|
|
1142
|
+
times__default["default"](resolvedOptions.length, function (i) {
|
|
1127
1143
|
return allValidIndexes.push(i);
|
|
1128
1144
|
});
|
|
1129
1145
|
}
|
|
@@ -1131,10 +1147,7 @@ function getClosestMatchingOption(validator, rootSchema, formData, options, sele
|
|
|
1131
1147
|
// Score all the options in the list of valid indexes and return the index with the best score
|
|
1132
1148
|
var _allValidIndexes$redu = allValidIndexes.reduce(function (scoreData, index) {
|
|
1133
1149
|
var bestScore = scoreData.bestScore;
|
|
1134
|
-
var option =
|
|
1135
|
-
if (has__default["default"](option, REF_KEY)) {
|
|
1136
|
-
option = retrieveSchema(validator, option, rootSchema, formData);
|
|
1137
|
-
}
|
|
1150
|
+
var option = resolvedOptions[index];
|
|
1138
1151
|
var score = calculateIndexScore(validator, rootSchema, option, formData);
|
|
1139
1152
|
scoreCount.add(score);
|
|
1140
1153
|
if (score > bestScore) {
|
|
@@ -1296,6 +1309,8 @@ function isMultiSelect(validator, schema, rootSchema) {
|
|
|
1296
1309
|
return isSelect(validator, schema.items, rootSchema);
|
|
1297
1310
|
}
|
|
1298
1311
|
|
|
1312
|
+
var _excluded$1 = ["oneOf"],
|
|
1313
|
+
_excluded2 = ["anyOf"];
|
|
1299
1314
|
/** Enum that indicates how `schema.additionalItems` should be handled by the `getInnerSchemaForArrayItem()` function.
|
|
1300
1315
|
*/
|
|
1301
1316
|
var AdditionalItemsHandling;
|
|
@@ -1458,17 +1473,23 @@ function computeDefaults(validator, rawSchema, _temp) {
|
|
|
1458
1473
|
});
|
|
1459
1474
|
});
|
|
1460
1475
|
} else if (ONE_OF_KEY in schema) {
|
|
1461
|
-
|
|
1476
|
+
var oneOf = schema.oneOf,
|
|
1477
|
+
remaining = _objectWithoutPropertiesLoose(schema, _excluded$1);
|
|
1478
|
+
if (oneOf.length === 0) {
|
|
1462
1479
|
return undefined;
|
|
1463
1480
|
}
|
|
1464
1481
|
var discriminator = getDiscriminatorFieldFromSchema(schema);
|
|
1465
|
-
schemaToCompute =
|
|
1482
|
+
schemaToCompute = oneOf[getClosestMatchingOption(validator, rootSchema, isEmpty__default["default"](formData) ? undefined : formData, oneOf, 0, discriminator)];
|
|
1483
|
+
schemaToCompute = _extends({}, remaining, schemaToCompute);
|
|
1466
1484
|
} else if (ANY_OF_KEY in schema) {
|
|
1467
|
-
|
|
1485
|
+
var anyOf = schema.anyOf,
|
|
1486
|
+
_remaining = _objectWithoutPropertiesLoose(schema, _excluded2);
|
|
1487
|
+
if (anyOf.length === 0) {
|
|
1468
1488
|
return undefined;
|
|
1469
1489
|
}
|
|
1470
1490
|
var _discriminator = getDiscriminatorFieldFromSchema(schema);
|
|
1471
|
-
schemaToCompute =
|
|
1491
|
+
schemaToCompute = anyOf[getClosestMatchingOption(validator, rootSchema, isEmpty__default["default"](formData) ? undefined : formData, anyOf, 0, _discriminator)];
|
|
1492
|
+
schemaToCompute = _extends({}, _remaining, schemaToCompute);
|
|
1472
1493
|
}
|
|
1473
1494
|
if (schemaToCompute) {
|
|
1474
1495
|
return computeDefaults(validator, schemaToCompute, {
|