@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/index.d.ts
CHANGED
|
@@ -1317,7 +1317,8 @@ declare function getWidget<T = any, S extends StrictRJSFSchema = RJSFSchema, F e
|
|
|
1317
1317
|
*/
|
|
1318
1318
|
declare function guessType(value: any): "array" | "string" | "null" | "boolean" | "number" | "object";
|
|
1319
1319
|
|
|
1320
|
-
/** Stringifies the schema and returns the hash of the resulting string.
|
|
1320
|
+
/** Stringifies the schema and returns the hash of the resulting string. Sorts schema fields
|
|
1321
|
+
* in consistent order before stringify to prevent different hash ids for the same schema.
|
|
1321
1322
|
*
|
|
1322
1323
|
* @param schema - The schema for which the hash is desired
|
|
1323
1324
|
* @returns - The string obtained from the hash of the stringified schema
|
|
@@ -17,6 +17,7 @@ var set = require('lodash/set');
|
|
|
17
17
|
var mergeAllOf = require('json-schema-merge-allof');
|
|
18
18
|
var union = require('lodash/union');
|
|
19
19
|
var isEqual = require('lodash/isEqual');
|
|
20
|
+
var lodash = require('lodash');
|
|
20
21
|
var cloneDeep = require('lodash/cloneDeep');
|
|
21
22
|
var jsxRuntime = require('react/jsx-runtime');
|
|
22
23
|
var react = require('react');
|
|
@@ -586,7 +587,7 @@ function resolveCondition(validator, schema, rootSchema, expandAllBranches, form
|
|
|
586
587
|
then = schema.then,
|
|
587
588
|
otherwise = schema["else"],
|
|
588
589
|
resolvedSchemaLessConditional = _objectWithoutPropertiesLoose(schema, _excluded$1);
|
|
589
|
-
var conditionValue = validator.isValid(expression, formData, rootSchema);
|
|
590
|
+
var conditionValue = validator.isValid(expression, formData || {}, rootSchema);
|
|
590
591
|
var resolvedSchemas = [resolvedSchemaLessConditional];
|
|
591
592
|
var schemas = [];
|
|
592
593
|
if (expandAllBranches) {
|
|
@@ -785,7 +786,11 @@ function retrieveSchemaInternal(validator, schema, rootSchema, rawFormData, expa
|
|
|
785
786
|
} catch (e) {
|
|
786
787
|
console.warn('could not merge subschemas in allOf:\n', e);
|
|
787
788
|
var _resolvedSchema = resolvedSchema,
|
|
789
|
+
allOf = _resolvedSchema.allOf,
|
|
788
790
|
resolvedSchemaWithoutAllOf = _objectWithoutPropertiesLoose(_resolvedSchema, _excluded3);
|
|
791
|
+
if (expandAllBranches && allOf) {
|
|
792
|
+
return [resolvedSchemaWithoutAllOf].concat(allOf);
|
|
793
|
+
}
|
|
789
794
|
return resolvedSchemaWithoutAllOf;
|
|
790
795
|
}
|
|
791
796
|
}
|
|
@@ -1122,6 +1127,7 @@ function getClosestMatchingOption(validator, rootSchema, formData, options, sele
|
|
|
1122
1127
|
return allValidIndexes.push(i);
|
|
1123
1128
|
});
|
|
1124
1129
|
}
|
|
1130
|
+
var scoreCount = new Set();
|
|
1125
1131
|
// Score all the options in the list of valid indexes and return the index with the best score
|
|
1126
1132
|
var _allValidIndexes$redu = allValidIndexes.reduce(function (scoreData, index) {
|
|
1127
1133
|
var bestScore = scoreData.bestScore;
|
|
@@ -1130,6 +1136,7 @@ function getClosestMatchingOption(validator, rootSchema, formData, options, sele
|
|
|
1130
1136
|
option = retrieveSchema(validator, option, rootSchema, formData);
|
|
1131
1137
|
}
|
|
1132
1138
|
var score = calculateIndexScore(validator, rootSchema, option, formData);
|
|
1139
|
+
scoreCount.add(score);
|
|
1133
1140
|
if (score > bestScore) {
|
|
1134
1141
|
return {
|
|
1135
1142
|
bestIndex: index,
|
|
@@ -1142,6 +1149,10 @@ function getClosestMatchingOption(validator, rootSchema, formData, options, sele
|
|
|
1142
1149
|
bestScore: 0
|
|
1143
1150
|
}),
|
|
1144
1151
|
bestIndex = _allValidIndexes$redu.bestIndex;
|
|
1152
|
+
// if all scores are the same go with selectedOption
|
|
1153
|
+
if (scoreCount.size === 1 && selectedOption >= 0) {
|
|
1154
|
+
return selectedOption;
|
|
1155
|
+
}
|
|
1145
1156
|
return bestIndex;
|
|
1146
1157
|
}
|
|
1147
1158
|
|
|
@@ -2432,7 +2443,7 @@ function enumOptionsSelectValue(valueIndex, selected, allEnumOptions) {
|
|
|
2432
2443
|
allEnumOptions = [];
|
|
2433
2444
|
}
|
|
2434
2445
|
var value = enumOptionsValueForIndex(valueIndex, allEnumOptions);
|
|
2435
|
-
if (value) {
|
|
2446
|
+
if (!lodash.isNil(value)) {
|
|
2436
2447
|
var index = allEnumOptions.findIndex(function (opt) {
|
|
2437
2448
|
return value === opt.value;
|
|
2438
2449
|
});
|
|
@@ -2802,13 +2813,19 @@ function hashString(string) {
|
|
|
2802
2813
|
|
|
2803
2814
|
return hash.toString(16);
|
|
2804
2815
|
}
|
|
2805
|
-
/** Stringifies the schema and returns the hash of the resulting string.
|
|
2816
|
+
/** Stringifies the schema and returns the hash of the resulting string. Sorts schema fields
|
|
2817
|
+
* in consistent order before stringify to prevent different hash ids for the same schema.
|
|
2806
2818
|
*
|
|
2807
2819
|
* @param schema - The schema for which the hash is desired
|
|
2808
2820
|
* @returns - The string obtained from the hash of the stringified schema
|
|
2809
2821
|
*/
|
|
2810
2822
|
function hashForSchema(schema) {
|
|
2811
|
-
|
|
2823
|
+
var allKeys = new Set();
|
|
2824
|
+
// solution source: https://stackoverflow.com/questions/16167581/sort-object-properties-and-json-stringify/53593328#53593328
|
|
2825
|
+
JSON.stringify(schema, function (key, value) {
|
|
2826
|
+
return allKeys.add(key), value;
|
|
2827
|
+
});
|
|
2828
|
+
return hashString(JSON.stringify(schema, Array.from(allKeys).sort()));
|
|
2812
2829
|
}
|
|
2813
2830
|
|
|
2814
2831
|
/** Detects whether the `widget` exists for the `schema` with the associated `registryWidgets` and returns true if it
|