@rjsf/utils 6.5.1 → 6.5.3
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 +40 -40
- package/dist/index.cjs.map +3 -3
- package/dist/utils.esm.js +40 -40
- package/dist/utils.esm.js.map +3 -3
- package/dist/utils.umd.js +43 -40
- package/lib/createSchemaUtils.js.map +1 -1
- package/lib/deepEquals.d.ts +5 -3
- package/lib/deepEquals.js +13 -13
- package/lib/deepEquals.js.map +1 -1
- package/lib/enums.d.ts +2 -0
- package/lib/enums.js +2 -0
- package/lib/enums.js.map +1 -1
- package/lib/isRootSchema.js +3 -3
- package/lib/isRootSchema.js.map +1 -1
- package/lib/jsonSchemaAugmentation.d.ts +19 -0
- package/lib/jsonSchemaAugmentation.js +2 -0
- package/lib/jsonSchemaAugmentation.js.map +1 -0
- package/lib/mergeDefaultsWithFormData.js +1 -1
- package/lib/mergeDefaultsWithFormData.js.map +1 -1
- package/lib/schema/findFieldInSchema.d.ts +2 -2
- package/lib/schema/findFieldInSchema.js +6 -5
- package/lib/schema/findFieldInSchema.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/schema/getFromSchema.d.ts +3 -3
- package/lib/schema/getFromSchema.js +2 -2
- package/lib/schema/getFromSchema.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/types.d.ts +13 -4
- package/lib/types.js +1 -1
- package/lib/types.js.map +1 -1
- package/lib/useDeepCompareMemo.js +2 -2
- package/lib/useDeepCompareMemo.js.map +1 -1
- package/package.json +3 -2
- package/src/createSchemaUtils.ts +5 -4
- package/src/deepEquals.ts +14 -13
- package/src/enums.ts +2 -0
- package/src/isRootSchema.ts +3 -3
- package/src/jsonSchemaAugmentation.ts +21 -0
- package/src/mergeDefaultsWithFormData.ts +2 -1
- package/src/schema/findFieldInSchema.ts +8 -6
- package/src/schema/findSelectedOptionInXxxOf.ts +2 -2
- package/src/schema/getDefaultFormState.ts +8 -5
- package/src/schema/getFromSchema.ts +14 -7
- package/src/types.ts +14 -4
- 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
|
);
|
|
@@ -1200,9 +1200,9 @@ function getFromSchemaInternal(validator, rootSchema, schema, path, experimental
|
|
|
1200
1200
|
if ((0, import_isEmpty3.default)(path)) {
|
|
1201
1201
|
return fieldSchema;
|
|
1202
1202
|
}
|
|
1203
|
-
const pathList = Array.isArray(path) ? path : path.split(".");
|
|
1203
|
+
const pathList = Array.isArray(path) ? [...path] : path.split(".");
|
|
1204
1204
|
const [part, ...nestedPath] = pathList;
|
|
1205
|
-
if (part && (0, import_has2.default)(fieldSchema, part)) {
|
|
1205
|
+
if (part !== void 0 && part !== "" && (0, import_has2.default)(fieldSchema, part)) {
|
|
1206
1206
|
fieldSchema = (0, import_get7.default)(fieldSchema, part);
|
|
1207
1207
|
return getFromSchemaInternal(
|
|
1208
1208
|
validator,
|
|
@@ -1228,6 +1228,7 @@ function findFieldInSchema(validator, rootSchema, schema, path, formData = {}, e
|
|
|
1228
1228
|
const pathList = Array.isArray(path) ? [...path] : path.split(".");
|
|
1229
1229
|
let parentField = schema;
|
|
1230
1230
|
const fieldName = pathList.pop();
|
|
1231
|
+
const fieldNameKey = String(fieldName);
|
|
1231
1232
|
if (pathList.length) {
|
|
1232
1233
|
pathList.forEach((subPath) => {
|
|
1233
1234
|
parentField = getFromSchema(
|
|
@@ -1243,7 +1244,7 @@ function findFieldInSchema(validator, rootSchema, schema, path, formData = {}, e
|
|
|
1243
1244
|
validator,
|
|
1244
1245
|
rootSchema,
|
|
1245
1246
|
parentField,
|
|
1246
|
-
|
|
1247
|
+
fieldNameKey,
|
|
1247
1248
|
ONE_OF_KEY,
|
|
1248
1249
|
(0, import_get8.default)(formData, subPath),
|
|
1249
1250
|
experimental_customMergeAllOf
|
|
@@ -1253,7 +1254,7 @@ function findFieldInSchema(validator, rootSchema, schema, path, formData = {}, e
|
|
|
1253
1254
|
validator,
|
|
1254
1255
|
rootSchema,
|
|
1255
1256
|
parentField,
|
|
1256
|
-
|
|
1257
|
+
fieldNameKey,
|
|
1257
1258
|
ANY_OF_KEY,
|
|
1258
1259
|
(0, import_get8.default)(formData, subPath),
|
|
1259
1260
|
experimental_customMergeAllOf
|
|
@@ -1266,7 +1267,7 @@ function findFieldInSchema(validator, rootSchema, schema, path, formData = {}, e
|
|
|
1266
1267
|
validator,
|
|
1267
1268
|
rootSchema,
|
|
1268
1269
|
parentField,
|
|
1269
|
-
|
|
1270
|
+
fieldNameKey,
|
|
1270
1271
|
ONE_OF_KEY,
|
|
1271
1272
|
formData,
|
|
1272
1273
|
experimental_customMergeAllOf
|
|
@@ -1276,7 +1277,7 @@ function findFieldInSchema(validator, rootSchema, schema, path, formData = {}, e
|
|
|
1276
1277
|
validator,
|
|
1277
1278
|
rootSchema,
|
|
1278
1279
|
parentField,
|
|
1279
|
-
|
|
1280
|
+
fieldNameKey,
|
|
1280
1281
|
ANY_OF_KEY,
|
|
1281
1282
|
formData,
|
|
1282
1283
|
experimental_customMergeAllOf
|
|
@@ -1303,7 +1304,7 @@ function findFieldInSchema(validator, rootSchema, schema, path, formData = {}, e
|
|
|
1303
1304
|
);
|
|
1304
1305
|
let isRequired;
|
|
1305
1306
|
if (field && Array.isArray(requiredArray)) {
|
|
1306
|
-
isRequired = requiredArray.includes(
|
|
1307
|
+
isRequired = requiredArray.includes(fieldNameKey);
|
|
1307
1308
|
}
|
|
1308
1309
|
return { field, isRequired };
|
|
1309
1310
|
}
|
|
@@ -1473,7 +1474,7 @@ function mergeDefaultsWithFormData(defaults, formData, mergeExtraArrayDefaults =
|
|
|
1473
1474
|
const keyExistsInDefaults = isObject(defaults) && key in defaults;
|
|
1474
1475
|
const keyExistsInFormData = key in formData;
|
|
1475
1476
|
const keyDefault = (0, import_get10.default)(defaults, key) ?? {};
|
|
1476
|
-
const defaultValueIsNestedObject = keyExistsInDefaults && Object.
|
|
1477
|
+
const defaultValueIsNestedObject = keyExistsInDefaults && isObject(keyDefault) && Object.values(keyDefault).some((v) => isObject(v));
|
|
1477
1478
|
const keyDefaultIsObject = keyExistsInDefaults && isObject((0, import_get10.default)(defaults, key));
|
|
1478
1479
|
const keyHasFormDataObject = keyExistsInFormData && isObject(keyValue);
|
|
1479
1480
|
if (keyDefaultIsObject && keyHasFormDataObject && !defaultValueIsNestedObject) {
|
|
@@ -1847,7 +1848,7 @@ function ensureFormDataMatchingSchema(validator, schema, rootSchema, formData, e
|
|
|
1847
1848
|
let validFormData = formData;
|
|
1848
1849
|
if (isSelectField) {
|
|
1849
1850
|
const getOptionsList = optionsList(schema);
|
|
1850
|
-
const isValid = getOptionsList?.some((option) =>
|
|
1851
|
+
const isValid = getOptionsList?.some((option) => deepEquals_default(option.value, formData));
|
|
1851
1852
|
validFormData = isValid ? formData : void 0;
|
|
1852
1853
|
}
|
|
1853
1854
|
const constTakesPrecedence = schema[CONST_KEY] && experimental_defaultFormStateBehavior?.constAsDefaults === "always";
|
|
@@ -1908,14 +1909,14 @@ function getObjectDefaults(validator, rawSchema, {
|
|
|
1908
1909
|
if (retrievedSchema.additionalProperties && !initialDefaultsGenerated) {
|
|
1909
1910
|
const additionalPropertiesSchema = isObject(retrievedSchema.additionalProperties) ? retrievedSchema.additionalProperties : {};
|
|
1910
1911
|
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
1912
|
const formDataRequired = [];
|
|
1915
1913
|
Object.keys(formData).filter((key) => !retrievedSchema.properties || !retrievedSchema.properties[key]).forEach((key) => {
|
|
1916
1914
|
keys2.add(key);
|
|
1917
1915
|
formDataRequired.push(key);
|
|
1918
1916
|
});
|
|
1917
|
+
if (isObject(defaults) && formDataRequired.length === 0) {
|
|
1918
|
+
Object.keys(defaults).filter((key) => !retrievedSchema.properties || !retrievedSchema.properties[key]).forEach((key) => keys2.add(key));
|
|
1919
|
+
}
|
|
1919
1920
|
keys2.forEach((key) => {
|
|
1920
1921
|
const computedDefault = computeDefaults(validator, additionalPropertiesSchema, {
|
|
1921
1922
|
rootSchema,
|
|
@@ -2149,7 +2150,7 @@ var import_set2 = __toESM(require("lodash/set"), 1);
|
|
|
2149
2150
|
function toPathSchemaInternal(validator, schema, name, rootSchema, formData, _recurseList = [], experimental_customMergeAllOf) {
|
|
2150
2151
|
if (REF_KEY in schema || DEPENDENCIES_KEY in schema || ALL_OF_KEY in schema || IF_KEY in schema) {
|
|
2151
2152
|
const _schema = retrieveSchema(validator, schema, rootSchema, formData, experimental_customMergeAllOf);
|
|
2152
|
-
const sameSchemaIndex = _recurseList.findIndex((item) =>
|
|
2153
|
+
const sameSchemaIndex = _recurseList.findIndex((item) => deepEquals_default(item, _schema));
|
|
2153
2154
|
if (sameSchemaIndex === -1) {
|
|
2154
2155
|
return toPathSchemaInternal(
|
|
2155
2156
|
validator,
|
|
@@ -2501,7 +2502,7 @@ var SchemaUtils = class {
|
|
|
2501
2502
|
if (!validator || !rootSchema) {
|
|
2502
2503
|
return false;
|
|
2503
2504
|
}
|
|
2504
|
-
return this.validator !== validator || !
|
|
2505
|
+
return this.validator !== validator || !deepEquals_default(this.rootSchema, rootSchema) || !deepEquals_default(this.experimental_defaultFormStateBehavior, experimental_defaultFormStateBehavior) || this.experimental_customMergeAllOf !== experimental_customMergeAllOf;
|
|
2505
2506
|
}
|
|
2506
2507
|
/** Finds the field specified by the `path` within the root or recursed `schema`. If there is no field for the specified
|
|
2507
2508
|
* `path`, then the default `{ field: undefined, isRequired: undefined }` is returned. It determines whether a leaf
|
|
@@ -2843,9 +2844,9 @@ function englishStringTranslator(stringToTranslate, params) {
|
|
|
2843
2844
|
// src/enumOptionsIsSelected.ts
|
|
2844
2845
|
function enumOptionsIsSelected(value, selected) {
|
|
2845
2846
|
if (Array.isArray(selected)) {
|
|
2846
|
-
return selected.some((sel) =>
|
|
2847
|
+
return selected.some((sel) => deepEquals_default(sel, value));
|
|
2847
2848
|
}
|
|
2848
|
-
return
|
|
2849
|
+
return deepEquals_default(selected, value);
|
|
2849
2850
|
}
|
|
2850
2851
|
|
|
2851
2852
|
// src/enumOptionsIndexForValue.ts
|
|
@@ -2924,9 +2925,9 @@ function enumOptionValueEncoder(value, index, format = "indexed") {
|
|
|
2924
2925
|
function enumOptionsDeselectValue(valueIndex, selected, allEnumOptions = []) {
|
|
2925
2926
|
const value = enumOptionsValueForIndex(valueIndex, allEnumOptions);
|
|
2926
2927
|
if (Array.isArray(selected)) {
|
|
2927
|
-
return selected.filter((v) => !
|
|
2928
|
+
return selected.filter((v) => !deepEquals_default(v, value));
|
|
2928
2929
|
}
|
|
2929
|
-
return
|
|
2930
|
+
return deepEquals_default(value, selected) ? void 0 : selected;
|
|
2930
2931
|
}
|
|
2931
2932
|
|
|
2932
2933
|
// src/enumOptionsSelectValue.ts
|
|
@@ -3056,7 +3057,7 @@ function getChangedFields(a, b) {
|
|
|
3056
3057
|
} else if (!aIsPlainObject && bIsPlainObject) {
|
|
3057
3058
|
return (0, import_keys.default)(b);
|
|
3058
3059
|
} else {
|
|
3059
|
-
const unequalFields = (0, import_keys.default)((0, import_pickBy.default)(a, (value, key) => !
|
|
3060
|
+
const unequalFields = (0, import_keys.default)((0, import_pickBy.default)(a, (value, key) => !deepEquals_default(value, (0, import_get19.default)(b, key))));
|
|
3060
3061
|
const diffFields = (0, import_difference.default)((0, import_keys.default)(b), (0, import_keys.default)(a));
|
|
3061
3062
|
return [...unequalFields, ...diffFields];
|
|
3062
3063
|
}
|
|
@@ -3376,16 +3377,15 @@ function isFormDataAvailable(formData) {
|
|
|
3376
3377
|
}
|
|
3377
3378
|
|
|
3378
3379
|
// src/isRootSchema.ts
|
|
3379
|
-
var import_isEqual2 = __toESM(require("lodash/isEqual"), 1);
|
|
3380
3380
|
var import_omit2 = __toESM(require("lodash/omit"), 1);
|
|
3381
3381
|
function isRootSchema(registry, schemaToCompare) {
|
|
3382
3382
|
const { rootSchema, schemaUtils } = registry;
|
|
3383
|
-
if ((
|
|
3383
|
+
if (deepEquals_default(schemaToCompare, rootSchema)) {
|
|
3384
3384
|
return true;
|
|
3385
3385
|
}
|
|
3386
3386
|
if (REF_KEY in rootSchema) {
|
|
3387
3387
|
const resolvedSchema = schemaUtils.retrieveSchema(rootSchema);
|
|
3388
|
-
return (
|
|
3388
|
+
return deepEquals_default(schemaToCompare, (0, import_omit2.default)(resolvedSchema, RJSF_REF_KEY));
|
|
3389
3389
|
}
|
|
3390
3390
|
return false;
|
|
3391
3391
|
}
|
|
@@ -3622,7 +3622,7 @@ function shouldRender(component, nextProps, nextState, updateStrategy = "customD
|
|
|
3622
3622
|
return !shallowEquals(props2, nextProps) || !shallowEquals(state2, nextState);
|
|
3623
3623
|
}
|
|
3624
3624
|
const { props, state } = component;
|
|
3625
|
-
return !
|
|
3625
|
+
return !deepEquals_default(props, nextProps) || !deepEquals_default(state, nextState);
|
|
3626
3626
|
}
|
|
3627
3627
|
|
|
3628
3628
|
// src/shouldRenderOptionalField.ts
|
|
@@ -3838,10 +3838,9 @@ function useAltDateWidgetProps(props) {
|
|
|
3838
3838
|
|
|
3839
3839
|
// src/useDeepCompareMemo.ts
|
|
3840
3840
|
var import_react3 = require("react");
|
|
3841
|
-
var import_isEqual3 = __toESM(require("lodash/isEqual"), 1);
|
|
3842
3841
|
function useDeepCompareMemo(newValue) {
|
|
3843
3842
|
const valueRef = (0, import_react3.useRef)(newValue);
|
|
3844
|
-
if (!(
|
|
3843
|
+
if (!deepEquals_default(newValue, valueRef.current)) {
|
|
3845
3844
|
valueRef.current = newValue;
|
|
3846
3845
|
}
|
|
3847
3846
|
return valueRef.current;
|
|
@@ -4057,6 +4056,7 @@ var TranslatableString = /* @__PURE__ */ ((TranslatableString2) => {
|
|
|
4057
4056
|
TranslatableString2["OptionPrefix"] = "Option %1";
|
|
4058
4057
|
TranslatableString2["TitleOptionPrefix"] = "%1 option %2";
|
|
4059
4058
|
TranslatableString2["KeyLabel"] = "%1 Key";
|
|
4059
|
+
TranslatableString2["DeprecatedLabel"] = "%1 (deprecated)";
|
|
4060
4060
|
TranslatableString2["InvalidObjectField"] = 'Invalid "%1" object field configuration: _%2_.';
|
|
4061
4061
|
TranslatableString2["UnsupportedField"] = "Unsupported field schema.";
|
|
4062
4062
|
TranslatableString2["UnsupportedFieldWithId"] = "Unsupported field schema for field `%1`.";
|
|
@@ -4101,7 +4101,7 @@ var ParserValidator = class {
|
|
|
4101
4101
|
const existing = this.schemaMap[key];
|
|
4102
4102
|
if (!existing) {
|
|
4103
4103
|
this.schemaMap[key] = identifiedSchema;
|
|
4104
|
-
} else if (!
|
|
4104
|
+
} else if (!deepEquals_default(existing, identifiedSchema)) {
|
|
4105
4105
|
console.error("existing schema:", JSON.stringify(existing, null, 2));
|
|
4106
4106
|
console.error("new schema:", JSON.stringify(identifiedSchema, null, 2));
|
|
4107
4107
|
throw new Error(
|
|
@@ -4123,7 +4123,7 @@ var ParserValidator = class {
|
|
|
4123
4123
|
* @throws - Error when the given `rootSchema` differs from the root schema provided during construction
|
|
4124
4124
|
*/
|
|
4125
4125
|
isValid(schema, _formData, rootSchema) {
|
|
4126
|
-
if (!
|
|
4126
|
+
if (!deepEquals_default(rootSchema, this.rootSchema)) {
|
|
4127
4127
|
throw new Error("Unexpectedly calling isValid() with a rootSchema that differs from the construction rootSchema");
|
|
4128
4128
|
}
|
|
4129
4129
|
this.addSchema(schema, hashForSchema(schema));
|
|
@@ -4163,7 +4163,7 @@ var ParserValidator = class {
|
|
|
4163
4163
|
function parseSchema(validator, recurseList, rootSchema, schema) {
|
|
4164
4164
|
const schemas = retrieveSchemaInternal(validator, schema, rootSchema, void 0, true);
|
|
4165
4165
|
schemas.forEach((schema2) => {
|
|
4166
|
-
const sameSchemaIndex = recurseList.findIndex((item) =>
|
|
4166
|
+
const sameSchemaIndex = recurseList.findIndex((item) => deepEquals_default(item, schema2));
|
|
4167
4167
|
if (sameSchemaIndex === -1) {
|
|
4168
4168
|
recurseList.push(schema2);
|
|
4169
4169
|
const allOptions = resolveAnyOrOneOfSchemas(validator, schema2, rootSchema, true);
|