@rjsf/utils 5.7.3 → 5.8.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/index.d.ts +2 -1
- package/dist/utils.cjs.development.js +21 -4
- 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 +21 -4
- package/dist/utils.esm.js.map +1 -1
- package/dist/utils.umd.development.js +24 -8
- 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 +11 -10
package/dist/utils.esm.js
CHANGED
|
@@ -13,6 +13,7 @@ import set from 'lodash-es/set';
|
|
|
13
13
|
import mergeAllOf from 'json-schema-merge-allof';
|
|
14
14
|
import union from 'lodash-es/union';
|
|
15
15
|
import isEqual from 'lodash-es/isEqual';
|
|
16
|
+
import { isNil } from 'lodash-es';
|
|
16
17
|
import cloneDeep from 'lodash-es/cloneDeep';
|
|
17
18
|
import { jsx } from 'react/jsx-runtime';
|
|
18
19
|
import { createElement } from 'react';
|
|
@@ -560,7 +561,7 @@ function resolveCondition(validator, schema, rootSchema, expandAllBranches, form
|
|
|
560
561
|
then = schema.then,
|
|
561
562
|
otherwise = schema["else"],
|
|
562
563
|
resolvedSchemaLessConditional = _objectWithoutPropertiesLoose(schema, _excluded$1);
|
|
563
|
-
var conditionValue = validator.isValid(expression, formData, rootSchema);
|
|
564
|
+
var conditionValue = validator.isValid(expression, formData || {}, rootSchema);
|
|
564
565
|
var resolvedSchemas = [resolvedSchemaLessConditional];
|
|
565
566
|
var schemas = [];
|
|
566
567
|
if (expandAllBranches) {
|
|
@@ -759,7 +760,11 @@ function retrieveSchemaInternal(validator, schema, rootSchema, rawFormData, expa
|
|
|
759
760
|
} catch (e) {
|
|
760
761
|
console.warn('could not merge subschemas in allOf:\n', e);
|
|
761
762
|
var _resolvedSchema = resolvedSchema,
|
|
763
|
+
allOf = _resolvedSchema.allOf,
|
|
762
764
|
resolvedSchemaWithoutAllOf = _objectWithoutPropertiesLoose(_resolvedSchema, _excluded3);
|
|
765
|
+
if (expandAllBranches && allOf) {
|
|
766
|
+
return [resolvedSchemaWithoutAllOf].concat(allOf);
|
|
767
|
+
}
|
|
763
768
|
return resolvedSchemaWithoutAllOf;
|
|
764
769
|
}
|
|
765
770
|
}
|
|
@@ -1096,6 +1101,7 @@ function getClosestMatchingOption(validator, rootSchema, formData, options, sele
|
|
|
1096
1101
|
return allValidIndexes.push(i);
|
|
1097
1102
|
});
|
|
1098
1103
|
}
|
|
1104
|
+
var scoreCount = new Set();
|
|
1099
1105
|
// Score all the options in the list of valid indexes and return the index with the best score
|
|
1100
1106
|
var _allValidIndexes$redu = allValidIndexes.reduce(function (scoreData, index) {
|
|
1101
1107
|
var bestScore = scoreData.bestScore;
|
|
@@ -1104,6 +1110,7 @@ function getClosestMatchingOption(validator, rootSchema, formData, options, sele
|
|
|
1104
1110
|
option = retrieveSchema(validator, option, rootSchema, formData);
|
|
1105
1111
|
}
|
|
1106
1112
|
var score = calculateIndexScore(validator, rootSchema, option, formData);
|
|
1113
|
+
scoreCount.add(score);
|
|
1107
1114
|
if (score > bestScore) {
|
|
1108
1115
|
return {
|
|
1109
1116
|
bestIndex: index,
|
|
@@ -1116,6 +1123,10 @@ function getClosestMatchingOption(validator, rootSchema, formData, options, sele
|
|
|
1116
1123
|
bestScore: 0
|
|
1117
1124
|
}),
|
|
1118
1125
|
bestIndex = _allValidIndexes$redu.bestIndex;
|
|
1126
|
+
// if all scores are the same go with selectedOption
|
|
1127
|
+
if (scoreCount.size === 1 && selectedOption >= 0) {
|
|
1128
|
+
return selectedOption;
|
|
1129
|
+
}
|
|
1119
1130
|
return bestIndex;
|
|
1120
1131
|
}
|
|
1121
1132
|
|
|
@@ -2406,7 +2417,7 @@ function enumOptionsSelectValue(valueIndex, selected, allEnumOptions) {
|
|
|
2406
2417
|
allEnumOptions = [];
|
|
2407
2418
|
}
|
|
2408
2419
|
var value = enumOptionsValueForIndex(valueIndex, allEnumOptions);
|
|
2409
|
-
if (value) {
|
|
2420
|
+
if (!isNil(value)) {
|
|
2410
2421
|
var index = allEnumOptions.findIndex(function (opt) {
|
|
2411
2422
|
return value === opt.value;
|
|
2412
2423
|
});
|
|
@@ -2776,13 +2787,19 @@ function hashString(string) {
|
|
|
2776
2787
|
|
|
2777
2788
|
return hash.toString(16);
|
|
2778
2789
|
}
|
|
2779
|
-
/** Stringifies the schema and returns the hash of the resulting string.
|
|
2790
|
+
/** Stringifies the schema and returns the hash of the resulting string. Sorts schema fields
|
|
2791
|
+
* in consistent order before stringify to prevent different hash ids for the same schema.
|
|
2780
2792
|
*
|
|
2781
2793
|
* @param schema - The schema for which the hash is desired
|
|
2782
2794
|
* @returns - The string obtained from the hash of the stringified schema
|
|
2783
2795
|
*/
|
|
2784
2796
|
function hashForSchema(schema) {
|
|
2785
|
-
|
|
2797
|
+
var allKeys = new Set();
|
|
2798
|
+
// solution source: https://stackoverflow.com/questions/16167581/sort-object-properties-and-json-stringify/53593328#53593328
|
|
2799
|
+
JSON.stringify(schema, function (key, value) {
|
|
2800
|
+
return allKeys.add(key), value;
|
|
2801
|
+
});
|
|
2802
|
+
return hashString(JSON.stringify(schema, Array.from(allKeys).sort()));
|
|
2786
2803
|
}
|
|
2787
2804
|
|
|
2788
2805
|
/** Detects whether the `widget` exists for the `schema` with the associated `registryWidgets` and returns true if it
|