@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/index.js
CHANGED
|
@@ -67,7 +67,7 @@ __export(src_exports, {
|
|
|
67
67
|
createSchemaUtils: () => createSchemaUtils,
|
|
68
68
|
dataURItoBlob: () => dataURItoBlob,
|
|
69
69
|
dateRangeOptions: () => dateRangeOptions,
|
|
70
|
-
deepEquals: () =>
|
|
70
|
+
deepEquals: () => deepEquals,
|
|
71
71
|
descriptionId: () => descriptionId,
|
|
72
72
|
englishStringTranslator: () => englishStringTranslator,
|
|
73
73
|
enumOptionsDeselectValue: () => enumOptionsDeselectValue,
|
|
@@ -269,20 +269,15 @@ function createErrorHandler(formData) {
|
|
|
269
269
|
}
|
|
270
270
|
|
|
271
271
|
// src/deepEquals.ts
|
|
272
|
-
var
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
return typeof b === "function";
|
|
282
|
-
}
|
|
283
|
-
})
|
|
284
|
-
});
|
|
285
|
-
var deepEquals_default = deepEquals;
|
|
272
|
+
var import_isEqualWith = __toESM(require("lodash/isEqualWith"));
|
|
273
|
+
function deepEquals(a, b) {
|
|
274
|
+
return (0, import_isEqualWith.default)(a, b, (obj, other) => {
|
|
275
|
+
if (typeof obj === "function" && typeof other === "function") {
|
|
276
|
+
return true;
|
|
277
|
+
}
|
|
278
|
+
return void 0;
|
|
279
|
+
});
|
|
280
|
+
}
|
|
286
281
|
|
|
287
282
|
// src/schema/getDefaultFormState.ts
|
|
288
283
|
var import_get7 = __toESM(require("lodash/get"));
|
|
@@ -702,7 +697,7 @@ function resolveAllReferences(schema, rootSchema, recurseList) {
|
|
|
702
697
|
items: resolveAllReferences(resolvedSchema.items, rootSchema, recurseList)
|
|
703
698
|
};
|
|
704
699
|
}
|
|
705
|
-
return
|
|
700
|
+
return deepEquals(schema, resolvedSchema) ? schema : resolvedSchema;
|
|
706
701
|
}
|
|
707
702
|
function stubExistingAdditionalProperties(validator, theSchema, rootSchema, aFormData, experimental_customMergeAllOf) {
|
|
708
703
|
const schema = {
|
|
@@ -1433,7 +1428,8 @@ function computeDefaults(validator, rawSchema, computeDefaultsProps = {}) {
|
|
|
1433
1428
|
schema,
|
|
1434
1429
|
rootSchema,
|
|
1435
1430
|
rawFormData,
|
|
1436
|
-
experimental_defaultFormStateBehavior
|
|
1431
|
+
experimental_defaultFormStateBehavior,
|
|
1432
|
+
experimental_customMergeAllOf
|
|
1437
1433
|
);
|
|
1438
1434
|
if (!isObject(rawFormData)) {
|
|
1439
1435
|
defaultsWithFormData = mergeDefaultsWithFormData(
|
|
@@ -1446,12 +1442,12 @@ function computeDefaults(validator, rawSchema, computeDefaultsProps = {}) {
|
|
|
1446
1442
|
}
|
|
1447
1443
|
return defaultsWithFormData;
|
|
1448
1444
|
}
|
|
1449
|
-
function ensureFormDataMatchingSchema(validator, schema, rootSchema, formData, experimental_defaultFormStateBehavior) {
|
|
1450
|
-
const isSelectField = !isConstant(schema) && isSelect(validator, schema, rootSchema);
|
|
1445
|
+
function ensureFormDataMatchingSchema(validator, schema, rootSchema, formData, experimental_defaultFormStateBehavior, experimental_customMergeAllOf) {
|
|
1446
|
+
const isSelectField = !isConstant(schema) && isSelect(validator, schema, rootSchema, experimental_customMergeAllOf);
|
|
1451
1447
|
let validFormData = formData;
|
|
1452
1448
|
if (isSelectField) {
|
|
1453
1449
|
const getOptionsList = optionsList(schema);
|
|
1454
|
-
const isValid = getOptionsList?.some((option) =>
|
|
1450
|
+
const isValid = getOptionsList?.some((option) => deepEquals(option.value, formData));
|
|
1455
1451
|
validFormData = isValid ? formData : void 0;
|
|
1456
1452
|
}
|
|
1457
1453
|
const constTakesPrecedence = schema[CONST_KEY] && experimental_defaultFormStateBehavior?.constAsDefaults === "always";
|
|
@@ -1865,7 +1861,7 @@ var import_get9 = __toESM(require("lodash/get"));
|
|
|
1865
1861
|
function toIdSchemaInternal(validator, schema, idPrefix, idSeparator, id, rootSchema, formData, _recurseList = [], experimental_customMergeAllOf) {
|
|
1866
1862
|
if (REF_KEY in schema || DEPENDENCIES_KEY in schema || ALL_OF_KEY in schema) {
|
|
1867
1863
|
const _schema = retrieveSchema(validator, schema, rootSchema, formData, experimental_customMergeAllOf);
|
|
1868
|
-
const sameSchemaIndex = _recurseList.findIndex((item) =>
|
|
1864
|
+
const sameSchemaIndex = _recurseList.findIndex((item) => deepEquals(item, _schema));
|
|
1869
1865
|
if (sameSchemaIndex === -1) {
|
|
1870
1866
|
return toIdSchemaInternal(
|
|
1871
1867
|
validator,
|
|
@@ -1936,7 +1932,7 @@ var import_set2 = __toESM(require("lodash/set"));
|
|
|
1936
1932
|
function toPathSchemaInternal(validator, schema, name, rootSchema, formData, _recurseList = [], experimental_customMergeAllOf) {
|
|
1937
1933
|
if (REF_KEY in schema || DEPENDENCIES_KEY in schema || ALL_OF_KEY in schema) {
|
|
1938
1934
|
const _schema = retrieveSchema(validator, schema, rootSchema, formData, experimental_customMergeAllOf);
|
|
1939
|
-
const sameSchemaIndex = _recurseList.findIndex((item) =>
|
|
1935
|
+
const sameSchemaIndex = _recurseList.findIndex((item) => deepEquals(item, _schema));
|
|
1940
1936
|
if (sameSchemaIndex === -1) {
|
|
1941
1937
|
return toPathSchemaInternal(
|
|
1942
1938
|
validator,
|
|
@@ -2080,7 +2076,7 @@ var SchemaUtils = class {
|
|
|
2080
2076
|
if (!validator || !rootSchema) {
|
|
2081
2077
|
return false;
|
|
2082
2078
|
}
|
|
2083
|
-
return this.validator !== validator || !
|
|
2079
|
+
return this.validator !== validator || !deepEquals(this.rootSchema, rootSchema) || !deepEquals(this.experimental_defaultFormStateBehavior, experimental_defaultFormStateBehavior) || this.experimental_customMergeAllOf !== experimental_customMergeAllOf;
|
|
2084
2080
|
}
|
|
2085
2081
|
/** Returns the superset of `formData` that includes the given set updated to include any missing fields that have
|
|
2086
2082
|
* computed to have defaults provided in the `schema`.
|
|
@@ -2388,17 +2384,17 @@ function enumOptionsValueForIndex(valueIndex, allEnumOptions = [], emptyValue) {
|
|
|
2388
2384
|
function enumOptionsDeselectValue(valueIndex, selected, allEnumOptions = []) {
|
|
2389
2385
|
const value = enumOptionsValueForIndex(valueIndex, allEnumOptions);
|
|
2390
2386
|
if (Array.isArray(selected)) {
|
|
2391
|
-
return selected.filter((v) => !
|
|
2387
|
+
return selected.filter((v) => !deepEquals(v, value));
|
|
2392
2388
|
}
|
|
2393
|
-
return
|
|
2389
|
+
return deepEquals(value, selected) ? void 0 : selected;
|
|
2394
2390
|
}
|
|
2395
2391
|
|
|
2396
2392
|
// src/enumOptionsIsSelected.ts
|
|
2397
2393
|
function enumOptionsIsSelected(value, selected) {
|
|
2398
2394
|
if (Array.isArray(selected)) {
|
|
2399
|
-
return selected.some((sel) =>
|
|
2395
|
+
return selected.some((sel) => deepEquals(sel, value));
|
|
2400
2396
|
}
|
|
2401
|
-
return
|
|
2397
|
+
return deepEquals(selected, value);
|
|
2402
2398
|
}
|
|
2403
2399
|
|
|
2404
2400
|
// src/enumOptionsIndexForValue.ts
|
|
@@ -2865,7 +2861,7 @@ function schemaRequiresTrueValue(schema) {
|
|
|
2865
2861
|
// src/shouldRender.ts
|
|
2866
2862
|
function shouldRender(component, nextProps, nextState) {
|
|
2867
2863
|
const { props, state } = component;
|
|
2868
|
-
return !
|
|
2864
|
+
return !deepEquals(props, nextProps) || !deepEquals(state, nextState);
|
|
2869
2865
|
}
|
|
2870
2866
|
|
|
2871
2867
|
// src/toDateString.ts
|
|
@@ -3023,7 +3019,7 @@ function getChangedFields(a, b) {
|
|
|
3023
3019
|
} else if (!aIsPlainObject && bIsPlainObject) {
|
|
3024
3020
|
return (0, import_keys.default)(b);
|
|
3025
3021
|
} else {
|
|
3026
|
-
const unequalFields = (0, import_keys.default)((0, import_pickBy.default)(a, (value, key) => !
|
|
3022
|
+
const unequalFields = (0, import_keys.default)((0, import_pickBy.default)(a, (value, key) => !deepEquals(value, (0, import_get13.default)(b, key))));
|
|
3027
3023
|
const diffFields = (0, import_difference.default)((0, import_keys.default)(b), (0, import_keys.default)(a));
|
|
3028
3024
|
return [...unequalFields, ...diffFields];
|
|
3029
3025
|
}
|
|
@@ -3098,7 +3094,7 @@ var ParserValidator = class {
|
|
|
3098
3094
|
const existing = this.schemaMap[key];
|
|
3099
3095
|
if (!existing) {
|
|
3100
3096
|
this.schemaMap[key] = identifiedSchema;
|
|
3101
|
-
} else if (!
|
|
3097
|
+
} else if (!deepEquals(existing, identifiedSchema)) {
|
|
3102
3098
|
console.error("existing schema:", JSON.stringify(existing, null, 2));
|
|
3103
3099
|
console.error("new schema:", JSON.stringify(identifiedSchema, null, 2));
|
|
3104
3100
|
throw new Error(
|
|
@@ -3120,7 +3116,7 @@ var ParserValidator = class {
|
|
|
3120
3116
|
* @throws - Error when the given `rootSchema` differs from the root schema provided during construction
|
|
3121
3117
|
*/
|
|
3122
3118
|
isValid(schema, _formData, rootSchema) {
|
|
3123
|
-
if (!
|
|
3119
|
+
if (!deepEquals(rootSchema, this.rootSchema)) {
|
|
3124
3120
|
throw new Error("Unexpectedly calling isValid() with a rootSchema that differs from the construction rootSchema");
|
|
3125
3121
|
}
|
|
3126
3122
|
this.addSchema(schema, hashForSchema(schema));
|
|
@@ -3160,7 +3156,7 @@ var ParserValidator = class {
|
|
|
3160
3156
|
function parseSchema(validator, recurseList, rootSchema, schema) {
|
|
3161
3157
|
const schemas = retrieveSchemaInternal(validator, schema, rootSchema, void 0, true);
|
|
3162
3158
|
schemas.forEach((schema2) => {
|
|
3163
|
-
const sameSchemaIndex = recurseList.findIndex((item) =>
|
|
3159
|
+
const sameSchemaIndex = recurseList.findIndex((item) => deepEquals(item, schema2));
|
|
3164
3160
|
if (sameSchemaIndex === -1) {
|
|
3165
3161
|
recurseList.push(schema2);
|
|
3166
3162
|
const allOptions = resolveAnyOrOneOfSchemas(validator, schema2, rootSchema, true);
|