@rjsf/utils 5.24.2 → 5.24.4
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.js +28 -32
- package/dist/index.js.map +3 -3
- package/dist/utils.esm.js +28 -32
- package/dist/utils.esm.js.map +2 -2
- package/dist/utils.umd.js +31 -35
- package/lib/deepEquals.d.ts +3 -3
- package/lib/deepEquals.js +13 -15
- package/lib/deepEquals.js.map +1 -1
- package/lib/schema/getDefaultFormState.d.ts +3 -2
- package/lib/schema/getDefaultFormState.js +5 -4
- package/lib/schema/getDefaultFormState.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +10 -4
- package/src/deepEquals.ts +13 -16
- package/src/schema/getDefaultFormState.ts +7 -4
package/dist/utils.esm.js
CHANGED
|
@@ -131,20 +131,15 @@ function createErrorHandler(formData) {
|
|
|
131
131
|
}
|
|
132
132
|
|
|
133
133
|
// src/deepEquals.ts
|
|
134
|
-
import
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
return typeof b === "function";
|
|
144
|
-
}
|
|
145
|
-
})
|
|
146
|
-
});
|
|
147
|
-
var deepEquals_default = deepEquals;
|
|
134
|
+
import isEqualWith from "lodash/isEqualWith";
|
|
135
|
+
function deepEquals(a, b) {
|
|
136
|
+
return isEqualWith(a, b, (obj, other) => {
|
|
137
|
+
if (typeof obj === "function" && typeof other === "function") {
|
|
138
|
+
return true;
|
|
139
|
+
}
|
|
140
|
+
return void 0;
|
|
141
|
+
});
|
|
142
|
+
}
|
|
148
143
|
|
|
149
144
|
// src/schema/getDefaultFormState.ts
|
|
150
145
|
import get7 from "lodash/get";
|
|
@@ -564,7 +559,7 @@ function resolveAllReferences(schema, rootSchema, recurseList) {
|
|
|
564
559
|
items: resolveAllReferences(resolvedSchema.items, rootSchema, recurseList)
|
|
565
560
|
};
|
|
566
561
|
}
|
|
567
|
-
return
|
|
562
|
+
return deepEquals(schema, resolvedSchema) ? schema : resolvedSchema;
|
|
568
563
|
}
|
|
569
564
|
function stubExistingAdditionalProperties(validator, theSchema, rootSchema, aFormData, experimental_customMergeAllOf) {
|
|
570
565
|
const schema = {
|
|
@@ -1295,7 +1290,8 @@ function computeDefaults(validator, rawSchema, computeDefaultsProps = {}) {
|
|
|
1295
1290
|
schema,
|
|
1296
1291
|
rootSchema,
|
|
1297
1292
|
rawFormData,
|
|
1298
|
-
experimental_defaultFormStateBehavior
|
|
1293
|
+
experimental_defaultFormStateBehavior,
|
|
1294
|
+
experimental_customMergeAllOf
|
|
1299
1295
|
);
|
|
1300
1296
|
if (!isObject(rawFormData)) {
|
|
1301
1297
|
defaultsWithFormData = mergeDefaultsWithFormData(
|
|
@@ -1308,12 +1304,12 @@ function computeDefaults(validator, rawSchema, computeDefaultsProps = {}) {
|
|
|
1308
1304
|
}
|
|
1309
1305
|
return defaultsWithFormData;
|
|
1310
1306
|
}
|
|
1311
|
-
function ensureFormDataMatchingSchema(validator, schema, rootSchema, formData, experimental_defaultFormStateBehavior) {
|
|
1312
|
-
const isSelectField = !isConstant(schema) && isSelect(validator, schema, rootSchema);
|
|
1307
|
+
function ensureFormDataMatchingSchema(validator, schema, rootSchema, formData, experimental_defaultFormStateBehavior, experimental_customMergeAllOf) {
|
|
1308
|
+
const isSelectField = !isConstant(schema) && isSelect(validator, schema, rootSchema, experimental_customMergeAllOf);
|
|
1313
1309
|
let validFormData = formData;
|
|
1314
1310
|
if (isSelectField) {
|
|
1315
1311
|
const getOptionsList = optionsList(schema);
|
|
1316
|
-
const isValid = getOptionsList?.some((option) =>
|
|
1312
|
+
const isValid = getOptionsList?.some((option) => deepEquals(option.value, formData));
|
|
1317
1313
|
validFormData = isValid ? formData : void 0;
|
|
1318
1314
|
}
|
|
1319
1315
|
const constTakesPrecedence = schema[CONST_KEY] && experimental_defaultFormStateBehavior?.constAsDefaults === "always";
|
|
@@ -1727,7 +1723,7 @@ import get9 from "lodash/get";
|
|
|
1727
1723
|
function toIdSchemaInternal(validator, schema, idPrefix, idSeparator, id, rootSchema, formData, _recurseList = [], experimental_customMergeAllOf) {
|
|
1728
1724
|
if (REF_KEY in schema || DEPENDENCIES_KEY in schema || ALL_OF_KEY in schema) {
|
|
1729
1725
|
const _schema = retrieveSchema(validator, schema, rootSchema, formData, experimental_customMergeAllOf);
|
|
1730
|
-
const sameSchemaIndex = _recurseList.findIndex((item) =>
|
|
1726
|
+
const sameSchemaIndex = _recurseList.findIndex((item) => deepEquals(item, _schema));
|
|
1731
1727
|
if (sameSchemaIndex === -1) {
|
|
1732
1728
|
return toIdSchemaInternal(
|
|
1733
1729
|
validator,
|
|
@@ -1798,7 +1794,7 @@ import set2 from "lodash/set";
|
|
|
1798
1794
|
function toPathSchemaInternal(validator, schema, name, rootSchema, formData, _recurseList = [], experimental_customMergeAllOf) {
|
|
1799
1795
|
if (REF_KEY in schema || DEPENDENCIES_KEY in schema || ALL_OF_KEY in schema) {
|
|
1800
1796
|
const _schema = retrieveSchema(validator, schema, rootSchema, formData, experimental_customMergeAllOf);
|
|
1801
|
-
const sameSchemaIndex = _recurseList.findIndex((item) =>
|
|
1797
|
+
const sameSchemaIndex = _recurseList.findIndex((item) => deepEquals(item, _schema));
|
|
1802
1798
|
if (sameSchemaIndex === -1) {
|
|
1803
1799
|
return toPathSchemaInternal(
|
|
1804
1800
|
validator,
|
|
@@ -1942,7 +1938,7 @@ var SchemaUtils = class {
|
|
|
1942
1938
|
if (!validator || !rootSchema) {
|
|
1943
1939
|
return false;
|
|
1944
1940
|
}
|
|
1945
|
-
return this.validator !== validator || !
|
|
1941
|
+
return this.validator !== validator || !deepEquals(this.rootSchema, rootSchema) || !deepEquals(this.experimental_defaultFormStateBehavior, experimental_defaultFormStateBehavior) || this.experimental_customMergeAllOf !== experimental_customMergeAllOf;
|
|
1946
1942
|
}
|
|
1947
1943
|
/** Returns the superset of `formData` that includes the given set updated to include any missing fields that have
|
|
1948
1944
|
* computed to have defaults provided in the `schema`.
|
|
@@ -2250,17 +2246,17 @@ function enumOptionsValueForIndex(valueIndex, allEnumOptions = [], emptyValue) {
|
|
|
2250
2246
|
function enumOptionsDeselectValue(valueIndex, selected, allEnumOptions = []) {
|
|
2251
2247
|
const value = enumOptionsValueForIndex(valueIndex, allEnumOptions);
|
|
2252
2248
|
if (Array.isArray(selected)) {
|
|
2253
|
-
return selected.filter((v) => !
|
|
2249
|
+
return selected.filter((v) => !deepEquals(v, value));
|
|
2254
2250
|
}
|
|
2255
|
-
return
|
|
2251
|
+
return deepEquals(value, selected) ? void 0 : selected;
|
|
2256
2252
|
}
|
|
2257
2253
|
|
|
2258
2254
|
// src/enumOptionsIsSelected.ts
|
|
2259
2255
|
function enumOptionsIsSelected(value, selected) {
|
|
2260
2256
|
if (Array.isArray(selected)) {
|
|
2261
|
-
return selected.some((sel) =>
|
|
2257
|
+
return selected.some((sel) => deepEquals(sel, value));
|
|
2262
2258
|
}
|
|
2263
|
-
return
|
|
2259
|
+
return deepEquals(selected, value);
|
|
2264
2260
|
}
|
|
2265
2261
|
|
|
2266
2262
|
// src/enumOptionsIndexForValue.ts
|
|
@@ -2727,7 +2723,7 @@ function schemaRequiresTrueValue(schema) {
|
|
|
2727
2723
|
// src/shouldRender.ts
|
|
2728
2724
|
function shouldRender(component, nextProps, nextState) {
|
|
2729
2725
|
const { props, state } = component;
|
|
2730
|
-
return !
|
|
2726
|
+
return !deepEquals(props, nextProps) || !deepEquals(state, nextState);
|
|
2731
2727
|
}
|
|
2732
2728
|
|
|
2733
2729
|
// src/toDateString.ts
|
|
@@ -2885,7 +2881,7 @@ function getChangedFields(a, b) {
|
|
|
2885
2881
|
} else if (!aIsPlainObject && bIsPlainObject) {
|
|
2886
2882
|
return keys(b);
|
|
2887
2883
|
} else {
|
|
2888
|
-
const unequalFields = keys(pickBy(a, (value, key) => !
|
|
2884
|
+
const unequalFields = keys(pickBy(a, (value, key) => !deepEquals(value, get13(b, key))));
|
|
2889
2885
|
const diffFields = difference(keys(b), keys(a));
|
|
2890
2886
|
return [...unequalFields, ...diffFields];
|
|
2891
2887
|
}
|
|
@@ -2960,7 +2956,7 @@ var ParserValidator = class {
|
|
|
2960
2956
|
const existing = this.schemaMap[key];
|
|
2961
2957
|
if (!existing) {
|
|
2962
2958
|
this.schemaMap[key] = identifiedSchema;
|
|
2963
|
-
} else if (!
|
|
2959
|
+
} else if (!deepEquals(existing, identifiedSchema)) {
|
|
2964
2960
|
console.error("existing schema:", JSON.stringify(existing, null, 2));
|
|
2965
2961
|
console.error("new schema:", JSON.stringify(identifiedSchema, null, 2));
|
|
2966
2962
|
throw new Error(
|
|
@@ -2982,7 +2978,7 @@ var ParserValidator = class {
|
|
|
2982
2978
|
* @throws - Error when the given `rootSchema` differs from the root schema provided during construction
|
|
2983
2979
|
*/
|
|
2984
2980
|
isValid(schema, _formData, rootSchema) {
|
|
2985
|
-
if (!
|
|
2981
|
+
if (!deepEquals(rootSchema, this.rootSchema)) {
|
|
2986
2982
|
throw new Error("Unexpectedly calling isValid() with a rootSchema that differs from the construction rootSchema");
|
|
2987
2983
|
}
|
|
2988
2984
|
this.addSchema(schema, hashForSchema(schema));
|
|
@@ -3022,7 +3018,7 @@ var ParserValidator = class {
|
|
|
3022
3018
|
function parseSchema(validator, recurseList, rootSchema, schema) {
|
|
3023
3019
|
const schemas = retrieveSchemaInternal(validator, schema, rootSchema, void 0, true);
|
|
3024
3020
|
schemas.forEach((schema2) => {
|
|
3025
|
-
const sameSchemaIndex = recurseList.findIndex((item) =>
|
|
3021
|
+
const sameSchemaIndex = recurseList.findIndex((item) => deepEquals(item, schema2));
|
|
3026
3022
|
if (sameSchemaIndex === -1) {
|
|
3027
3023
|
recurseList.push(schema2);
|
|
3028
3024
|
const allOptions = resolveAnyOrOneOfSchemas(validator, schema2, rootSchema, true);
|
|
@@ -3083,7 +3079,7 @@ export {
|
|
|
3083
3079
|
createSchemaUtils,
|
|
3084
3080
|
dataURItoBlob,
|
|
3085
3081
|
dateRangeOptions,
|
|
3086
|
-
|
|
3082
|
+
deepEquals,
|
|
3087
3083
|
descriptionId,
|
|
3088
3084
|
englishStringTranslator,
|
|
3089
3085
|
enumOptionsDeselectValue,
|