@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
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
(function (global, factory) {
|
|
2
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('lodash-es/isPlainObject'), require('lodash-es/isEqualWith'), require('lodash-es/get'), require('lodash-es/isEmpty'), require('jsonpointer'), require('lodash-es/omit'), require('lodash-es/has'), require('lodash-es/isObject'), require('lodash-es/isString'), require('lodash-es/reduce'), require('lodash-es/times'), require('lodash-es/set'), require('json-schema-merge-allof'), require('lodash-es/union'), require('lodash-es/isEqual'), require('lodash-es/cloneDeep'), require('react/jsx-runtime'), require('react'), require('react-is'), require('lodash-es/toPath'), require('lodash-es/forEach')) :
|
|
3
|
-
typeof define === 'function' && define.amd ? define(['exports', 'lodash-es/isPlainObject', 'lodash-es/isEqualWith', 'lodash-es/get', 'lodash-es/isEmpty', 'jsonpointer', 'lodash-es/omit', 'lodash-es/has', 'lodash-es/isObject', 'lodash-es/isString', 'lodash-es/reduce', 'lodash-es/times', 'lodash-es/set', 'json-schema-merge-allof', 'lodash-es/union', 'lodash-es/isEqual', 'lodash-es/cloneDeep', 'react/jsx-runtime', 'react', 'react-is', 'lodash-es/toPath', 'lodash-es/forEach'], factory) :
|
|
4
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["@rjsf/utils"] = {}, global.isPlainObject, global.isEqualWith, global.get, global.isEmpty, global.jsonpointer, global.omit, global.has, global.isObject$1, global.isString, global.reduce, global.times, global.set, global.mergeAllOf, global.union, global.isEqual, global.cloneDeep, global.jsxRuntime, global.React, global.ReactIs, global.toPath, global.forEach));
|
|
5
|
-
})(this, (function (exports, isPlainObject, isEqualWith, get, isEmpty, jsonpointer, omit, has, isObject$1, isString, reduce, times, set, mergeAllOf, union, isEqual, cloneDeep, jsxRuntime, react, ReactIs, toPath, forEach) { 'use strict';
|
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('lodash-es/isPlainObject'), require('lodash-es/isEqualWith'), require('lodash-es/get'), require('lodash-es/isEmpty'), require('jsonpointer'), require('lodash-es/omit'), require('lodash-es/has'), require('lodash-es/isObject'), require('lodash-es/isString'), require('lodash-es/reduce'), require('lodash-es/times'), require('lodash-es/set'), require('json-schema-merge-allof'), require('lodash-es/union'), require('lodash-es/isEqual'), require('lodash-es'), require('lodash-es/cloneDeep'), require('react/jsx-runtime'), require('react'), require('react-is'), require('lodash-es/toPath'), require('lodash-es/forEach')) :
|
|
3
|
+
typeof define === 'function' && define.amd ? define(['exports', 'lodash-es/isPlainObject', 'lodash-es/isEqualWith', 'lodash-es/get', 'lodash-es/isEmpty', 'jsonpointer', 'lodash-es/omit', 'lodash-es/has', 'lodash-es/isObject', 'lodash-es/isString', 'lodash-es/reduce', 'lodash-es/times', 'lodash-es/set', 'json-schema-merge-allof', 'lodash-es/union', 'lodash-es/isEqual', 'lodash-es', 'lodash-es/cloneDeep', 'react/jsx-runtime', 'react', 'react-is', 'lodash-es/toPath', 'lodash-es/forEach'], factory) :
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["@rjsf/utils"] = {}, global.isPlainObject, global.isEqualWith, global.get, global.isEmpty, global.jsonpointer, global.omit, global.has, global.isObject$1, global.isString, global.reduce, global.times, global.set, global.mergeAllOf, global.union, global.isEqual, global.lodashEs, global.cloneDeep, global.jsxRuntime, global.React, global.ReactIs, global.toPath, global.forEach));
|
|
5
|
+
})(this, (function (exports, isPlainObject, isEqualWith, get, isEmpty, jsonpointer, omit, has, isObject$1, isString, reduce, times, set, mergeAllOf, union, isEqual, lodashEs, cloneDeep, jsxRuntime, react, ReactIs, toPath, forEach) { 'use strict';
|
|
6
6
|
|
|
7
7
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
8
8
|
|
|
@@ -566,7 +566,7 @@
|
|
|
566
566
|
then = schema.then,
|
|
567
567
|
otherwise = schema["else"],
|
|
568
568
|
resolvedSchemaLessConditional = _objectWithoutPropertiesLoose(schema, _excluded$1);
|
|
569
|
-
var conditionValue = validator.isValid(expression, formData, rootSchema);
|
|
569
|
+
var conditionValue = validator.isValid(expression, formData || {}, rootSchema);
|
|
570
570
|
var resolvedSchemas = [resolvedSchemaLessConditional];
|
|
571
571
|
var schemas = [];
|
|
572
572
|
if (expandAllBranches) {
|
|
@@ -765,7 +765,11 @@
|
|
|
765
765
|
} catch (e) {
|
|
766
766
|
console.warn('could not merge subschemas in allOf:\n', e);
|
|
767
767
|
var _resolvedSchema = resolvedSchema,
|
|
768
|
+
allOf = _resolvedSchema.allOf,
|
|
768
769
|
resolvedSchemaWithoutAllOf = _objectWithoutPropertiesLoose(_resolvedSchema, _excluded3);
|
|
770
|
+
if (expandAllBranches && allOf) {
|
|
771
|
+
return [resolvedSchemaWithoutAllOf].concat(allOf);
|
|
772
|
+
}
|
|
769
773
|
return resolvedSchemaWithoutAllOf;
|
|
770
774
|
}
|
|
771
775
|
}
|
|
@@ -1102,6 +1106,7 @@
|
|
|
1102
1106
|
return allValidIndexes.push(i);
|
|
1103
1107
|
});
|
|
1104
1108
|
}
|
|
1109
|
+
var scoreCount = new Set();
|
|
1105
1110
|
// Score all the options in the list of valid indexes and return the index with the best score
|
|
1106
1111
|
var _allValidIndexes$redu = allValidIndexes.reduce(function (scoreData, index) {
|
|
1107
1112
|
var bestScore = scoreData.bestScore;
|
|
@@ -1110,6 +1115,7 @@
|
|
|
1110
1115
|
option = retrieveSchema(validator, option, rootSchema, formData);
|
|
1111
1116
|
}
|
|
1112
1117
|
var score = calculateIndexScore(validator, rootSchema, option, formData);
|
|
1118
|
+
scoreCount.add(score);
|
|
1113
1119
|
if (score > bestScore) {
|
|
1114
1120
|
return {
|
|
1115
1121
|
bestIndex: index,
|
|
@@ -1122,6 +1128,10 @@
|
|
|
1122
1128
|
bestScore: 0
|
|
1123
1129
|
}),
|
|
1124
1130
|
bestIndex = _allValidIndexes$redu.bestIndex;
|
|
1131
|
+
// if all scores are the same go with selectedOption
|
|
1132
|
+
if (scoreCount.size === 1 && selectedOption >= 0) {
|
|
1133
|
+
return selectedOption;
|
|
1134
|
+
}
|
|
1125
1135
|
return bestIndex;
|
|
1126
1136
|
}
|
|
1127
1137
|
|
|
@@ -2412,7 +2422,7 @@
|
|
|
2412
2422
|
allEnumOptions = [];
|
|
2413
2423
|
}
|
|
2414
2424
|
var value = enumOptionsValueForIndex(valueIndex, allEnumOptions);
|
|
2415
|
-
if (value) {
|
|
2425
|
+
if (!lodashEs.isNil(value)) {
|
|
2416
2426
|
var index = allEnumOptions.findIndex(function (opt) {
|
|
2417
2427
|
return value === opt.value;
|
|
2418
2428
|
});
|
|
@@ -2782,13 +2792,19 @@
|
|
|
2782
2792
|
|
|
2783
2793
|
return hash.toString(16);
|
|
2784
2794
|
}
|
|
2785
|
-
/** Stringifies the schema and returns the hash of the resulting string.
|
|
2795
|
+
/** Stringifies the schema and returns the hash of the resulting string. Sorts schema fields
|
|
2796
|
+
* in consistent order before stringify to prevent different hash ids for the same schema.
|
|
2786
2797
|
*
|
|
2787
2798
|
* @param schema - The schema for which the hash is desired
|
|
2788
2799
|
* @returns - The string obtained from the hash of the stringified schema
|
|
2789
2800
|
*/
|
|
2790
2801
|
function hashForSchema(schema) {
|
|
2791
|
-
|
|
2802
|
+
var allKeys = new Set();
|
|
2803
|
+
// solution source: https://stackoverflow.com/questions/16167581/sort-object-properties-and-json-stringify/53593328#53593328
|
|
2804
|
+
JSON.stringify(schema, function (key, value) {
|
|
2805
|
+
return allKeys.add(key), value;
|
|
2806
|
+
});
|
|
2807
|
+
return hashString(JSON.stringify(schema, Array.from(allKeys).sort()));
|
|
2792
2808
|
}
|
|
2793
2809
|
|
|
2794
2810
|
/** Detects whether the `widget` exists for the `schema` with the associated `registryWidgets` and returns true if it
|