@rjsf/utils 6.5.0 → 6.5.2
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.cjs +30 -32
- package/dist/index.cjs.map +3 -3
- package/dist/utils.esm.js +30 -32
- package/dist/utils.esm.js.map +3 -3
- package/dist/utils.umd.js +33 -32
- package/lib/deepEquals.d.ts +5 -3
- package/lib/deepEquals.js +13 -13
- package/lib/deepEquals.js.map +1 -1
- package/lib/isRootSchema.js +3 -3
- package/lib/isRootSchema.js.map +1 -1
- package/lib/schema/findSelectedOptionInXxxOf.js +2 -2
- package/lib/schema/findSelectedOptionInXxxOf.js.map +1 -1
- package/lib/schema/getDefaultFormState.js +8 -5
- package/lib/schema/getDefaultFormState.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/useDeepCompareMemo.js +2 -2
- package/lib/useDeepCompareMemo.js.map +1 -1
- package/package.json +2 -1
- package/src/deepEquals.ts +14 -13
- package/src/isRootSchema.ts +3 -3
- package/src/schema/findSelectedOptionInXxxOf.ts +2 -2
- package/src/schema/getDefaultFormState.ts +8 -5
- package/src/useDeepCompareMemo.ts +3 -2
package/dist/index.cjs
CHANGED
|
@@ -81,7 +81,7 @@ __export(index_exports, {
|
|
|
81
81
|
createSchemaUtils: () => createSchemaUtils,
|
|
82
82
|
dataURItoBlob: () => dataURItoBlob,
|
|
83
83
|
dateRangeOptions: () => dateRangeOptions,
|
|
84
|
-
deepEquals: () =>
|
|
84
|
+
deepEquals: () => deepEquals_default,
|
|
85
85
|
descriptionId: () => descriptionId,
|
|
86
86
|
dotNotationNameGenerator: () => dotNotationNameGenerator,
|
|
87
87
|
englishStringTranslator: () => englishStringTranslator,
|
|
@@ -321,15 +321,16 @@ function createErrorHandler(formData) {
|
|
|
321
321
|
}
|
|
322
322
|
|
|
323
323
|
// src/deepEquals.ts
|
|
324
|
-
var
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
324
|
+
var import_fast_equals = require("fast-equals");
|
|
325
|
+
var deepEquals = (0, import_fast_equals.createCustomEqual)({
|
|
326
|
+
circular: true,
|
|
327
|
+
createCustomConfig: () => ({
|
|
328
|
+
areFunctionsEqual(_a, b) {
|
|
329
|
+
return typeof b === "function";
|
|
329
330
|
}
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
331
|
+
})
|
|
332
|
+
});
|
|
333
|
+
var deepEquals_default = deepEquals;
|
|
333
334
|
|
|
334
335
|
// src/schema/findFieldInSchema.ts
|
|
335
336
|
var import_get8 = __toESM(require("lodash/get"), 1);
|
|
@@ -337,7 +338,6 @@ var import_has3 = __toESM(require("lodash/has"), 1);
|
|
|
337
338
|
|
|
338
339
|
// src/schema/findSelectedOptionInXxxOf.ts
|
|
339
340
|
var import_get6 = __toESM(require("lodash/get"), 1);
|
|
340
|
-
var import_isEqual = __toESM(require("lodash/isEqual"), 1);
|
|
341
341
|
|
|
342
342
|
// src/schema/retrieveSchema.ts
|
|
343
343
|
var import_get5 = __toESM(require("lodash/get"), 1);
|
|
@@ -840,7 +840,7 @@ function resolveAllReferences(schema, rootSchema, recurseList, baseURI, resolveA
|
|
|
840
840
|
};
|
|
841
841
|
}
|
|
842
842
|
}
|
|
843
|
-
return
|
|
843
|
+
return deepEquals_default(schema, resolvedSchema) ? schema : resolvedSchema;
|
|
844
844
|
}
|
|
845
845
|
function stubExistingAdditionalProperties(validator, theSchema, rootSchema, aFormData, experimental_customMergeAllOf) {
|
|
846
846
|
const schema = {
|
|
@@ -1178,7 +1178,7 @@ function findSelectedOptionInXxxOf(validator, rootSchema, schema, fallbackField,
|
|
|
1178
1178
|
const data = (0, import_get6.default)(formData, selectorField);
|
|
1179
1179
|
if (data !== void 0) {
|
|
1180
1180
|
return xxxOfs.find((xxx2) => {
|
|
1181
|
-
return (
|
|
1181
|
+
return deepEquals_default(
|
|
1182
1182
|
(0, import_get6.default)(xxx2, [PROPERTIES_KEY, selectorField, DEFAULT_KEY], (0, import_get6.default)(xxx2, [PROPERTIES_KEY, selectorField, CONST_KEY])),
|
|
1183
1183
|
data
|
|
1184
1184
|
);
|
|
@@ -1847,7 +1847,7 @@ function ensureFormDataMatchingSchema(validator, schema, rootSchema, formData, e
|
|
|
1847
1847
|
let validFormData = formData;
|
|
1848
1848
|
if (isSelectField) {
|
|
1849
1849
|
const getOptionsList = optionsList(schema);
|
|
1850
|
-
const isValid = getOptionsList?.some((option) =>
|
|
1850
|
+
const isValid = getOptionsList?.some((option) => deepEquals_default(option.value, formData));
|
|
1851
1851
|
validFormData = isValid ? formData : void 0;
|
|
1852
1852
|
}
|
|
1853
1853
|
const constTakesPrecedence = schema[CONST_KEY] && experimental_defaultFormStateBehavior?.constAsDefaults === "always";
|
|
@@ -1908,14 +1908,14 @@ function getObjectDefaults(validator, rawSchema, {
|
|
|
1908
1908
|
if (retrievedSchema.additionalProperties && !initialDefaultsGenerated) {
|
|
1909
1909
|
const additionalPropertiesSchema = isObject(retrievedSchema.additionalProperties) ? retrievedSchema.additionalProperties : {};
|
|
1910
1910
|
const keys2 = /* @__PURE__ */ new Set();
|
|
1911
|
-
if (isObject(defaults)) {
|
|
1912
|
-
Object.keys(defaults).filter((key) => !retrievedSchema.properties || !retrievedSchema.properties[key]).forEach((key) => keys2.add(key));
|
|
1913
|
-
}
|
|
1914
1911
|
const formDataRequired = [];
|
|
1915
1912
|
Object.keys(formData).filter((key) => !retrievedSchema.properties || !retrievedSchema.properties[key]).forEach((key) => {
|
|
1916
1913
|
keys2.add(key);
|
|
1917
1914
|
formDataRequired.push(key);
|
|
1918
1915
|
});
|
|
1916
|
+
if (isObject(defaults) && formDataRequired.length === 0) {
|
|
1917
|
+
Object.keys(defaults).filter((key) => !retrievedSchema.properties || !retrievedSchema.properties[key]).forEach((key) => keys2.add(key));
|
|
1918
|
+
}
|
|
1919
1919
|
keys2.forEach((key) => {
|
|
1920
1920
|
const computedDefault = computeDefaults(validator, additionalPropertiesSchema, {
|
|
1921
1921
|
rootSchema,
|
|
@@ -2149,7 +2149,7 @@ var import_set2 = __toESM(require("lodash/set"), 1);
|
|
|
2149
2149
|
function toPathSchemaInternal(validator, schema, name, rootSchema, formData, _recurseList = [], experimental_customMergeAllOf) {
|
|
2150
2150
|
if (REF_KEY in schema || DEPENDENCIES_KEY in schema || ALL_OF_KEY in schema || IF_KEY in schema) {
|
|
2151
2151
|
const _schema = retrieveSchema(validator, schema, rootSchema, formData, experimental_customMergeAllOf);
|
|
2152
|
-
const sameSchemaIndex = _recurseList.findIndex((item) =>
|
|
2152
|
+
const sameSchemaIndex = _recurseList.findIndex((item) => deepEquals_default(item, _schema));
|
|
2153
2153
|
if (sameSchemaIndex === -1) {
|
|
2154
2154
|
return toPathSchemaInternal(
|
|
2155
2155
|
validator,
|
|
@@ -2501,7 +2501,7 @@ var SchemaUtils = class {
|
|
|
2501
2501
|
if (!validator || !rootSchema) {
|
|
2502
2502
|
return false;
|
|
2503
2503
|
}
|
|
2504
|
-
return this.validator !== validator || !
|
|
2504
|
+
return this.validator !== validator || !deepEquals_default(this.rootSchema, rootSchema) || !deepEquals_default(this.experimental_defaultFormStateBehavior, experimental_defaultFormStateBehavior) || this.experimental_customMergeAllOf !== experimental_customMergeAllOf;
|
|
2505
2505
|
}
|
|
2506
2506
|
/** Finds the field specified by the `path` within the root or recursed `schema`. If there is no field for the specified
|
|
2507
2507
|
* `path`, then the default `{ field: undefined, isRequired: undefined }` is returned. It determines whether a leaf
|
|
@@ -2843,9 +2843,9 @@ function englishStringTranslator(stringToTranslate, params) {
|
|
|
2843
2843
|
// src/enumOptionsIsSelected.ts
|
|
2844
2844
|
function enumOptionsIsSelected(value, selected) {
|
|
2845
2845
|
if (Array.isArray(selected)) {
|
|
2846
|
-
return selected.some((sel) =>
|
|
2846
|
+
return selected.some((sel) => deepEquals_default(sel, value));
|
|
2847
2847
|
}
|
|
2848
|
-
return
|
|
2848
|
+
return deepEquals_default(selected, value);
|
|
2849
2849
|
}
|
|
2850
2850
|
|
|
2851
2851
|
// src/enumOptionsIndexForValue.ts
|
|
@@ -2924,9 +2924,9 @@ function enumOptionValueEncoder(value, index, format = "indexed") {
|
|
|
2924
2924
|
function enumOptionsDeselectValue(valueIndex, selected, allEnumOptions = []) {
|
|
2925
2925
|
const value = enumOptionsValueForIndex(valueIndex, allEnumOptions);
|
|
2926
2926
|
if (Array.isArray(selected)) {
|
|
2927
|
-
return selected.filter((v) => !
|
|
2927
|
+
return selected.filter((v) => !deepEquals_default(v, value));
|
|
2928
2928
|
}
|
|
2929
|
-
return
|
|
2929
|
+
return deepEquals_default(value, selected) ? void 0 : selected;
|
|
2930
2930
|
}
|
|
2931
2931
|
|
|
2932
2932
|
// src/enumOptionsSelectValue.ts
|
|
@@ -3056,7 +3056,7 @@ function getChangedFields(a, b) {
|
|
|
3056
3056
|
} else if (!aIsPlainObject && bIsPlainObject) {
|
|
3057
3057
|
return (0, import_keys.default)(b);
|
|
3058
3058
|
} else {
|
|
3059
|
-
const unequalFields = (0, import_keys.default)((0, import_pickBy.default)(a, (value, key) => !
|
|
3059
|
+
const unequalFields = (0, import_keys.default)((0, import_pickBy.default)(a, (value, key) => !deepEquals_default(value, (0, import_get19.default)(b, key))));
|
|
3060
3060
|
const diffFields = (0, import_difference.default)((0, import_keys.default)(b), (0, import_keys.default)(a));
|
|
3061
3061
|
return [...unequalFields, ...diffFields];
|
|
3062
3062
|
}
|
|
@@ -3376,16 +3376,15 @@ function isFormDataAvailable(formData) {
|
|
|
3376
3376
|
}
|
|
3377
3377
|
|
|
3378
3378
|
// src/isRootSchema.ts
|
|
3379
|
-
var import_isEqual2 = __toESM(require("lodash/isEqual"), 1);
|
|
3380
3379
|
var import_omit2 = __toESM(require("lodash/omit"), 1);
|
|
3381
3380
|
function isRootSchema(registry, schemaToCompare) {
|
|
3382
3381
|
const { rootSchema, schemaUtils } = registry;
|
|
3383
|
-
if ((
|
|
3382
|
+
if (deepEquals_default(schemaToCompare, rootSchema)) {
|
|
3384
3383
|
return true;
|
|
3385
3384
|
}
|
|
3386
3385
|
if (REF_KEY in rootSchema) {
|
|
3387
3386
|
const resolvedSchema = schemaUtils.retrieveSchema(rootSchema);
|
|
3388
|
-
return (
|
|
3387
|
+
return deepEquals_default(schemaToCompare, (0, import_omit2.default)(resolvedSchema, RJSF_REF_KEY));
|
|
3389
3388
|
}
|
|
3390
3389
|
return false;
|
|
3391
3390
|
}
|
|
@@ -3622,7 +3621,7 @@ function shouldRender(component, nextProps, nextState, updateStrategy = "customD
|
|
|
3622
3621
|
return !shallowEquals(props2, nextProps) || !shallowEquals(state2, nextState);
|
|
3623
3622
|
}
|
|
3624
3623
|
const { props, state } = component;
|
|
3625
|
-
return !
|
|
3624
|
+
return !deepEquals_default(props, nextProps) || !deepEquals_default(state, nextState);
|
|
3626
3625
|
}
|
|
3627
3626
|
|
|
3628
3627
|
// src/shouldRenderOptionalField.ts
|
|
@@ -3838,10 +3837,9 @@ function useAltDateWidgetProps(props) {
|
|
|
3838
3837
|
|
|
3839
3838
|
// src/useDeepCompareMemo.ts
|
|
3840
3839
|
var import_react3 = require("react");
|
|
3841
|
-
var import_isEqual3 = __toESM(require("lodash/isEqual"), 1);
|
|
3842
3840
|
function useDeepCompareMemo(newValue) {
|
|
3843
3841
|
const valueRef = (0, import_react3.useRef)(newValue);
|
|
3844
|
-
if (!(
|
|
3842
|
+
if (!deepEquals_default(newValue, valueRef.current)) {
|
|
3845
3843
|
valueRef.current = newValue;
|
|
3846
3844
|
}
|
|
3847
3845
|
return valueRef.current;
|
|
@@ -4101,7 +4099,7 @@ var ParserValidator = class {
|
|
|
4101
4099
|
const existing = this.schemaMap[key];
|
|
4102
4100
|
if (!existing) {
|
|
4103
4101
|
this.schemaMap[key] = identifiedSchema;
|
|
4104
|
-
} else if (!
|
|
4102
|
+
} else if (!deepEquals_default(existing, identifiedSchema)) {
|
|
4105
4103
|
console.error("existing schema:", JSON.stringify(existing, null, 2));
|
|
4106
4104
|
console.error("new schema:", JSON.stringify(identifiedSchema, null, 2));
|
|
4107
4105
|
throw new Error(
|
|
@@ -4123,7 +4121,7 @@ var ParserValidator = class {
|
|
|
4123
4121
|
* @throws - Error when the given `rootSchema` differs from the root schema provided during construction
|
|
4124
4122
|
*/
|
|
4125
4123
|
isValid(schema, _formData, rootSchema) {
|
|
4126
|
-
if (!
|
|
4124
|
+
if (!deepEquals_default(rootSchema, this.rootSchema)) {
|
|
4127
4125
|
throw new Error("Unexpectedly calling isValid() with a rootSchema that differs from the construction rootSchema");
|
|
4128
4126
|
}
|
|
4129
4127
|
this.addSchema(schema, hashForSchema(schema));
|
|
@@ -4163,7 +4161,7 @@ var ParserValidator = class {
|
|
|
4163
4161
|
function parseSchema(validator, recurseList, rootSchema, schema) {
|
|
4164
4162
|
const schemas = retrieveSchemaInternal(validator, schema, rootSchema, void 0, true);
|
|
4165
4163
|
schemas.forEach((schema2) => {
|
|
4166
|
-
const sameSchemaIndex = recurseList.findIndex((item) =>
|
|
4164
|
+
const sameSchemaIndex = recurseList.findIndex((item) => deepEquals_default(item, schema2));
|
|
4167
4165
|
if (sameSchemaIndex === -1) {
|
|
4168
4166
|
recurseList.push(schema2);
|
|
4169
4167
|
const allOptions = resolveAnyOrOneOfSchemas(validator, schema2, rootSchema, true);
|