@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
|
@@ -528,11 +528,12 @@
|
|
|
528
528
|
}, acc);
|
|
529
529
|
}
|
|
530
530
|
|
|
531
|
-
var _excluded$
|
|
532
|
-
_excluded2 = ["$ref"],
|
|
531
|
+
var _excluded$2 = ["if", "then", "else"],
|
|
532
|
+
_excluded2$1 = ["$ref"],
|
|
533
533
|
_excluded3 = ["allOf"],
|
|
534
|
-
_excluded4 = ["
|
|
535
|
-
_excluded5 = ["
|
|
534
|
+
_excluded4 = ["oneOf", "anyOf"],
|
|
535
|
+
_excluded5 = ["dependencies"],
|
|
536
|
+
_excluded6 = ["oneOf"];
|
|
536
537
|
/** Retrieves an expanded schema that has had all of its conditions, additional properties, references and dependencies
|
|
537
538
|
* resolved and merged into the `schema` given a `validator`, `rootSchema` and `rawFormData` that is used to do the
|
|
538
539
|
* potentially recursive resolution.
|
|
@@ -565,7 +566,7 @@
|
|
|
565
566
|
var expression = schema["if"],
|
|
566
567
|
then = schema.then,
|
|
567
568
|
otherwise = schema["else"],
|
|
568
|
-
resolvedSchemaLessConditional = _objectWithoutPropertiesLoose(schema, _excluded$
|
|
569
|
+
resolvedSchemaLessConditional = _objectWithoutPropertiesLoose(schema, _excluded$2);
|
|
569
570
|
var conditionValue = validator.isValid(expression, formData || {}, rootSchema);
|
|
570
571
|
var resolvedSchemas = [resolvedSchemaLessConditional];
|
|
571
572
|
var schemas = [];
|
|
@@ -675,7 +676,7 @@
|
|
|
675
676
|
function resolveReference(validator, schema, rootSchema, expandAllBranches, formData) {
|
|
676
677
|
// Drop the $ref property of the source schema.
|
|
677
678
|
var $ref = schema.$ref,
|
|
678
|
-
localSchema = _objectWithoutPropertiesLoose(schema, _excluded2);
|
|
679
|
+
localSchema = _objectWithoutPropertiesLoose(schema, _excluded2$1);
|
|
679
680
|
// Retrieve the referenced schema definition.
|
|
680
681
|
var refSchema = findSchemaDefinition($ref, rootSchema);
|
|
681
682
|
// Update referenced schema definition with local schema properties.
|
|
@@ -757,9 +758,9 @@
|
|
|
757
758
|
if (IF_KEY in resolvedSchema) {
|
|
758
759
|
return resolveCondition(validator, resolvedSchema, rootSchema, expandAllBranches, rawFormData);
|
|
759
760
|
}
|
|
760
|
-
if (ALL_OF_KEY in
|
|
761
|
+
if (ALL_OF_KEY in resolvedSchema) {
|
|
761
762
|
try {
|
|
762
|
-
resolvedSchema = mergeAllOf__default["default"](
|
|
763
|
+
resolvedSchema = mergeAllOf__default["default"](resolvedSchema, {
|
|
763
764
|
deep: false
|
|
764
765
|
});
|
|
765
766
|
} catch (e) {
|
|
@@ -794,10 +795,14 @@
|
|
|
794
795
|
*/
|
|
795
796
|
function resolveAnyOrOneOfSchemas(validator, schema, rootSchema, expandAllBranches, rawFormData) {
|
|
796
797
|
var anyOrOneOf;
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
798
|
+
var _schema = schema,
|
|
799
|
+
oneOf = _schema.oneOf,
|
|
800
|
+
anyOf = _schema.anyOf,
|
|
801
|
+
remaining = _objectWithoutPropertiesLoose(_schema, _excluded4);
|
|
802
|
+
if (Array.isArray(oneOf)) {
|
|
803
|
+
anyOrOneOf = oneOf;
|
|
804
|
+
} else if (Array.isArray(anyOf)) {
|
|
805
|
+
anyOrOneOf = anyOf;
|
|
801
806
|
}
|
|
802
807
|
if (anyOrOneOf) {
|
|
803
808
|
// Ensure that during expand all branches we pass an object rather than undefined so that all options are interrogated
|
|
@@ -813,9 +818,11 @@
|
|
|
813
818
|
// Call this to trigger the set of isValid() calls that the schema parser will need
|
|
814
819
|
var option = getFirstMatchingOption(validator, formData, anyOrOneOf, rootSchema, discriminator);
|
|
815
820
|
if (expandAllBranches) {
|
|
816
|
-
return anyOrOneOf
|
|
821
|
+
return anyOrOneOf.map(function (item) {
|
|
822
|
+
return _extends({}, remaining, item);
|
|
823
|
+
});
|
|
817
824
|
}
|
|
818
|
-
schema = anyOrOneOf[option];
|
|
825
|
+
schema = _extends({}, remaining, anyOrOneOf[option]);
|
|
819
826
|
}
|
|
820
827
|
return [schema];
|
|
821
828
|
}
|
|
@@ -833,7 +840,7 @@
|
|
|
833
840
|
function resolveDependencies(validator, schema, rootSchema, expandAllBranches, formData) {
|
|
834
841
|
// Drop the dependencies from the source schema.
|
|
835
842
|
var dependencies = schema.dependencies,
|
|
836
|
-
remainingSchema = _objectWithoutPropertiesLoose(schema,
|
|
843
|
+
remainingSchema = _objectWithoutPropertiesLoose(schema, _excluded5);
|
|
837
844
|
var resolvedSchemas = resolveAnyOrOneOfSchemas(validator, remainingSchema, rootSchema, expandAllBranches, formData);
|
|
838
845
|
return resolvedSchemas.flatMap(function (resolvedSchema) {
|
|
839
846
|
return processDependencies(validator, dependencies, resolvedSchema, rootSchema, expandAllBranches, formData);
|
|
@@ -916,7 +923,7 @@
|
|
|
916
923
|
var dependentSchemas = retrieveSchemaInternal(validator, dependencyValue, rootSchema, formData, expandAllBranches);
|
|
917
924
|
return dependentSchemas.flatMap(function (dependent) {
|
|
918
925
|
var oneOf = dependent.oneOf,
|
|
919
|
-
dependentSchema = _objectWithoutPropertiesLoose(dependent,
|
|
926
|
+
dependentSchema = _objectWithoutPropertiesLoose(dependent, _excluded6);
|
|
920
927
|
schema = mergeSchemas(schema, dependentSchema);
|
|
921
928
|
// Since it does not contain oneOf, we return the original schema.
|
|
922
929
|
if (oneOf === undefined) {
|
|
@@ -1031,8 +1038,10 @@
|
|
|
1031
1038
|
var newSchema = retrieveSchema(validator, value, rootSchema, formValue);
|
|
1032
1039
|
return score + calculateIndexScore(validator, rootSchema, newSchema, formValue || {});
|
|
1033
1040
|
}
|
|
1034
|
-
if (has__default["default"](value, ONE_OF_KEY) && formValue) {
|
|
1035
|
-
|
|
1041
|
+
if ((has__default["default"](value, ONE_OF_KEY) || has__default["default"](value, ANY_OF_KEY)) && formValue) {
|
|
1042
|
+
var _key = has__default["default"](value, ONE_OF_KEY) ? ONE_OF_KEY : ANY_OF_KEY;
|
|
1043
|
+
var discriminator = getDiscriminatorFieldFromSchema(value);
|
|
1044
|
+
return score + getClosestMatchingOption(validator, rootSchema, formValue, get__default["default"](value, _key), -1, discriminator);
|
|
1036
1045
|
}
|
|
1037
1046
|
if (value.type === 'object') {
|
|
1038
1047
|
return score + calculateIndexScore(validator, rootSchema, value, formValue || {});
|
|
@@ -1086,8 +1095,15 @@
|
|
|
1086
1095
|
if (selectedOption === void 0) {
|
|
1087
1096
|
selectedOption = -1;
|
|
1088
1097
|
}
|
|
1098
|
+
// First resolve any refs in the options
|
|
1099
|
+
var resolvedOptions = options.map(function (option) {
|
|
1100
|
+
if (has__default["default"](option, REF_KEY)) {
|
|
1101
|
+
return retrieveSchema(validator, option, rootSchema, formData);
|
|
1102
|
+
}
|
|
1103
|
+
return option;
|
|
1104
|
+
});
|
|
1089
1105
|
// Reduce the array of options down to a list of the indexes that are considered matching options
|
|
1090
|
-
var allValidIndexes =
|
|
1106
|
+
var allValidIndexes = resolvedOptions.reduce(function (validList, option, index) {
|
|
1091
1107
|
var testOptions = [JUNK_OPTION, option];
|
|
1092
1108
|
var match = getFirstMatchingOption(validator, formData, testOptions, rootSchema, discriminatorField);
|
|
1093
1109
|
// The match is the real option, so add its index to list of valid indexes
|
|
@@ -1102,7 +1118,7 @@
|
|
|
1102
1118
|
}
|
|
1103
1119
|
if (!allValidIndexes.length) {
|
|
1104
1120
|
// No indexes were valid, so we'll score all the options, add all the indexes
|
|
1105
|
-
times__default["default"](
|
|
1121
|
+
times__default["default"](resolvedOptions.length, function (i) {
|
|
1106
1122
|
return allValidIndexes.push(i);
|
|
1107
1123
|
});
|
|
1108
1124
|
}
|
|
@@ -1110,10 +1126,7 @@
|
|
|
1110
1126
|
// Score all the options in the list of valid indexes and return the index with the best score
|
|
1111
1127
|
var _allValidIndexes$redu = allValidIndexes.reduce(function (scoreData, index) {
|
|
1112
1128
|
var bestScore = scoreData.bestScore;
|
|
1113
|
-
var option =
|
|
1114
|
-
if (has__default["default"](option, REF_KEY)) {
|
|
1115
|
-
option = retrieveSchema(validator, option, rootSchema, formData);
|
|
1116
|
-
}
|
|
1129
|
+
var option = resolvedOptions[index];
|
|
1117
1130
|
var score = calculateIndexScore(validator, rootSchema, option, formData);
|
|
1118
1131
|
scoreCount.add(score);
|
|
1119
1132
|
if (score > bestScore) {
|
|
@@ -1275,6 +1288,8 @@
|
|
|
1275
1288
|
return isSelect(validator, schema.items, rootSchema);
|
|
1276
1289
|
}
|
|
1277
1290
|
|
|
1291
|
+
var _excluded$1 = ["oneOf"],
|
|
1292
|
+
_excluded2 = ["anyOf"];
|
|
1278
1293
|
/** Enum that indicates how `schema.additionalItems` should be handled by the `getInnerSchemaForArrayItem()` function.
|
|
1279
1294
|
*/
|
|
1280
1295
|
var AdditionalItemsHandling;
|
|
@@ -1437,17 +1452,23 @@
|
|
|
1437
1452
|
});
|
|
1438
1453
|
});
|
|
1439
1454
|
} else if (ONE_OF_KEY in schema) {
|
|
1440
|
-
|
|
1455
|
+
var oneOf = schema.oneOf,
|
|
1456
|
+
remaining = _objectWithoutPropertiesLoose(schema, _excluded$1);
|
|
1457
|
+
if (oneOf.length === 0) {
|
|
1441
1458
|
return undefined;
|
|
1442
1459
|
}
|
|
1443
1460
|
var discriminator = getDiscriminatorFieldFromSchema(schema);
|
|
1444
|
-
schemaToCompute =
|
|
1461
|
+
schemaToCompute = oneOf[getClosestMatchingOption(validator, rootSchema, isEmpty__default["default"](formData) ? undefined : formData, oneOf, 0, discriminator)];
|
|
1462
|
+
schemaToCompute = _extends({}, remaining, schemaToCompute);
|
|
1445
1463
|
} else if (ANY_OF_KEY in schema) {
|
|
1446
|
-
|
|
1464
|
+
var anyOf = schema.anyOf,
|
|
1465
|
+
_remaining = _objectWithoutPropertiesLoose(schema, _excluded2);
|
|
1466
|
+
if (anyOf.length === 0) {
|
|
1447
1467
|
return undefined;
|
|
1448
1468
|
}
|
|
1449
1469
|
var _discriminator = getDiscriminatorFieldFromSchema(schema);
|
|
1450
|
-
schemaToCompute =
|
|
1470
|
+
schemaToCompute = anyOf[getClosestMatchingOption(validator, rootSchema, isEmpty__default["default"](formData) ? undefined : formData, anyOf, 0, _discriminator)];
|
|
1471
|
+
schemaToCompute = _extends({}, _remaining, schemaToCompute);
|
|
1451
1472
|
}
|
|
1452
1473
|
if (schemaToCompute) {
|
|
1453
1474
|
return computeDefaults(validator, schemaToCompute, {
|