@rjsf/utils 5.7.2 → 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 +4 -2
- package/dist/utils.cjs.development.js +27 -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 +27 -5
- package/dist/utils.esm.js.map +1 -1
- package/dist/utils.umd.development.js +30 -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 +12 -11
|
@@ -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
|
|
|
@@ -170,6 +170,7 @@
|
|
|
170
170
|
var ID_KEY = '$id';
|
|
171
171
|
var IF_KEY = 'if';
|
|
172
172
|
var ITEMS_KEY = 'items';
|
|
173
|
+
var JUNK_OPTION_ID = '_$junk_option_schema_id$_';
|
|
173
174
|
var NAME_KEY = '$name';
|
|
174
175
|
var ONE_OF_KEY = 'oneOf';
|
|
175
176
|
var PROPERTIES_KEY = 'properties';
|
|
@@ -565,7 +566,7 @@
|
|
|
565
566
|
then = schema.then,
|
|
566
567
|
otherwise = schema["else"],
|
|
567
568
|
resolvedSchemaLessConditional = _objectWithoutPropertiesLoose(schema, _excluded$1);
|
|
568
|
-
var conditionValue = validator.isValid(expression, formData, rootSchema);
|
|
569
|
+
var conditionValue = validator.isValid(expression, formData || {}, rootSchema);
|
|
569
570
|
var resolvedSchemas = [resolvedSchemaLessConditional];
|
|
570
571
|
var schemas = [];
|
|
571
572
|
if (expandAllBranches) {
|
|
@@ -764,7 +765,11 @@
|
|
|
764
765
|
} catch (e) {
|
|
765
766
|
console.warn('could not merge subschemas in allOf:\n', e);
|
|
766
767
|
var _resolvedSchema = resolvedSchema,
|
|
768
|
+
allOf = _resolvedSchema.allOf,
|
|
767
769
|
resolvedSchemaWithoutAllOf = _objectWithoutPropertiesLoose(_resolvedSchema, _excluded3);
|
|
770
|
+
if (expandAllBranches && allOf) {
|
|
771
|
+
return [resolvedSchemaWithoutAllOf].concat(allOf);
|
|
772
|
+
}
|
|
768
773
|
return resolvedSchemaWithoutAllOf;
|
|
769
774
|
}
|
|
770
775
|
}
|
|
@@ -983,6 +988,7 @@
|
|
|
983
988
|
*/
|
|
984
989
|
var JUNK_OPTION = {
|
|
985
990
|
type: 'object',
|
|
991
|
+
$id: JUNK_OPTION_ID,
|
|
986
992
|
properties: {
|
|
987
993
|
__not_really_there__: {
|
|
988
994
|
type: 'number'
|
|
@@ -1100,6 +1106,7 @@
|
|
|
1100
1106
|
return allValidIndexes.push(i);
|
|
1101
1107
|
});
|
|
1102
1108
|
}
|
|
1109
|
+
var scoreCount = new Set();
|
|
1103
1110
|
// Score all the options in the list of valid indexes and return the index with the best score
|
|
1104
1111
|
var _allValidIndexes$redu = allValidIndexes.reduce(function (scoreData, index) {
|
|
1105
1112
|
var bestScore = scoreData.bestScore;
|
|
@@ -1108,6 +1115,7 @@
|
|
|
1108
1115
|
option = retrieveSchema(validator, option, rootSchema, formData);
|
|
1109
1116
|
}
|
|
1110
1117
|
var score = calculateIndexScore(validator, rootSchema, option, formData);
|
|
1118
|
+
scoreCount.add(score);
|
|
1111
1119
|
if (score > bestScore) {
|
|
1112
1120
|
return {
|
|
1113
1121
|
bestIndex: index,
|
|
@@ -1120,6 +1128,10 @@
|
|
|
1120
1128
|
bestScore: 0
|
|
1121
1129
|
}),
|
|
1122
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
|
+
}
|
|
1123
1135
|
return bestIndex;
|
|
1124
1136
|
}
|
|
1125
1137
|
|
|
@@ -2410,7 +2422,7 @@
|
|
|
2410
2422
|
allEnumOptions = [];
|
|
2411
2423
|
}
|
|
2412
2424
|
var value = enumOptionsValueForIndex(valueIndex, allEnumOptions);
|
|
2413
|
-
if (value) {
|
|
2425
|
+
if (!lodashEs.isNil(value)) {
|
|
2414
2426
|
var index = allEnumOptions.findIndex(function (opt) {
|
|
2415
2427
|
return value === opt.value;
|
|
2416
2428
|
});
|
|
@@ -2780,13 +2792,19 @@
|
|
|
2780
2792
|
|
|
2781
2793
|
return hash.toString(16);
|
|
2782
2794
|
}
|
|
2783
|
-
/** 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.
|
|
2784
2797
|
*
|
|
2785
2798
|
* @param schema - The schema for which the hash is desired
|
|
2786
2799
|
* @returns - The string obtained from the hash of the stringified schema
|
|
2787
2800
|
*/
|
|
2788
2801
|
function hashForSchema(schema) {
|
|
2789
|
-
|
|
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()));
|
|
2790
2808
|
}
|
|
2791
2809
|
|
|
2792
2810
|
/** Detects whether the `widget` exists for the `schema` with the associated `registryWidgets` and returns true if it
|
|
@@ -3511,6 +3529,9 @@
|
|
|
3511
3529
|
});
|
|
3512
3530
|
}
|
|
3513
3531
|
});
|
|
3532
|
+
if (ITEMS_KEY in schema && !Array.isArray(schema.items) && typeof schema.items !== 'boolean') {
|
|
3533
|
+
parseSchema(validator, recurseList, rootSchema, schema.items);
|
|
3534
|
+
}
|
|
3514
3535
|
}
|
|
3515
3536
|
});
|
|
3516
3537
|
}
|
|
@@ -3541,6 +3562,7 @@
|
|
|
3541
3562
|
exports.ID_KEY = ID_KEY;
|
|
3542
3563
|
exports.IF_KEY = IF_KEY;
|
|
3543
3564
|
exports.ITEMS_KEY = ITEMS_KEY;
|
|
3565
|
+
exports.JUNK_OPTION_ID = JUNK_OPTION_ID;
|
|
3544
3566
|
exports.NAME_KEY = NAME_KEY;
|
|
3545
3567
|
exports.ONE_OF_KEY = ONE_OF_KEY;
|
|
3546
3568
|
exports.PROPERTIES_KEY = PROPERTIES_KEY;
|