@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/utils.esm.js
CHANGED
|
@@ -145,15 +145,16 @@ function createErrorHandler(formData) {
|
|
|
145
145
|
}
|
|
146
146
|
|
|
147
147
|
// src/deepEquals.ts
|
|
148
|
-
import
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
148
|
+
import { createCustomEqual } from "fast-equals";
|
|
149
|
+
var deepEquals = createCustomEqual({
|
|
150
|
+
circular: true,
|
|
151
|
+
createCustomConfig: () => ({
|
|
152
|
+
areFunctionsEqual(_a, b) {
|
|
153
|
+
return typeof b === "function";
|
|
153
154
|
}
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
155
|
+
})
|
|
156
|
+
});
|
|
157
|
+
var deepEquals_default = deepEquals;
|
|
157
158
|
|
|
158
159
|
// src/schema/findFieldInSchema.ts
|
|
159
160
|
import get8 from "lodash/get";
|
|
@@ -161,7 +162,6 @@ import has3 from "lodash/has";
|
|
|
161
162
|
|
|
162
163
|
// src/schema/findSelectedOptionInXxxOf.ts
|
|
163
164
|
import get6 from "lodash/get";
|
|
164
|
-
import isEqual from "lodash/isEqual";
|
|
165
165
|
|
|
166
166
|
// src/schema/retrieveSchema.ts
|
|
167
167
|
import get5 from "lodash/get";
|
|
@@ -664,7 +664,7 @@ function resolveAllReferences(schema, rootSchema, recurseList, baseURI, resolveA
|
|
|
664
664
|
};
|
|
665
665
|
}
|
|
666
666
|
}
|
|
667
|
-
return
|
|
667
|
+
return deepEquals_default(schema, resolvedSchema) ? schema : resolvedSchema;
|
|
668
668
|
}
|
|
669
669
|
function stubExistingAdditionalProperties(validator, theSchema, rootSchema, aFormData, experimental_customMergeAllOf) {
|
|
670
670
|
const schema = {
|
|
@@ -1002,7 +1002,7 @@ function findSelectedOptionInXxxOf(validator, rootSchema, schema, fallbackField,
|
|
|
1002
1002
|
const data = get6(formData, selectorField);
|
|
1003
1003
|
if (data !== void 0) {
|
|
1004
1004
|
return xxxOfs.find((xxx2) => {
|
|
1005
|
-
return
|
|
1005
|
+
return deepEquals_default(
|
|
1006
1006
|
get6(xxx2, [PROPERTIES_KEY, selectorField, DEFAULT_KEY], get6(xxx2, [PROPERTIES_KEY, selectorField, CONST_KEY])),
|
|
1007
1007
|
data
|
|
1008
1008
|
);
|
|
@@ -1024,9 +1024,9 @@ function getFromSchemaInternal(validator, rootSchema, schema, path, experimental
|
|
|
1024
1024
|
if (isEmpty3(path)) {
|
|
1025
1025
|
return fieldSchema;
|
|
1026
1026
|
}
|
|
1027
|
-
const pathList = Array.isArray(path) ? path : path.split(".");
|
|
1027
|
+
const pathList = Array.isArray(path) ? [...path] : path.split(".");
|
|
1028
1028
|
const [part, ...nestedPath] = pathList;
|
|
1029
|
-
if (part && has2(fieldSchema, part)) {
|
|
1029
|
+
if (part !== void 0 && part !== "" && has2(fieldSchema, part)) {
|
|
1030
1030
|
fieldSchema = get7(fieldSchema, part);
|
|
1031
1031
|
return getFromSchemaInternal(
|
|
1032
1032
|
validator,
|
|
@@ -1052,6 +1052,7 @@ function findFieldInSchema(validator, rootSchema, schema, path, formData = {}, e
|
|
|
1052
1052
|
const pathList = Array.isArray(path) ? [...path] : path.split(".");
|
|
1053
1053
|
let parentField = schema;
|
|
1054
1054
|
const fieldName = pathList.pop();
|
|
1055
|
+
const fieldNameKey = String(fieldName);
|
|
1055
1056
|
if (pathList.length) {
|
|
1056
1057
|
pathList.forEach((subPath) => {
|
|
1057
1058
|
parentField = getFromSchema(
|
|
@@ -1067,7 +1068,7 @@ function findFieldInSchema(validator, rootSchema, schema, path, formData = {}, e
|
|
|
1067
1068
|
validator,
|
|
1068
1069
|
rootSchema,
|
|
1069
1070
|
parentField,
|
|
1070
|
-
|
|
1071
|
+
fieldNameKey,
|
|
1071
1072
|
ONE_OF_KEY,
|
|
1072
1073
|
get8(formData, subPath),
|
|
1073
1074
|
experimental_customMergeAllOf
|
|
@@ -1077,7 +1078,7 @@ function findFieldInSchema(validator, rootSchema, schema, path, formData = {}, e
|
|
|
1077
1078
|
validator,
|
|
1078
1079
|
rootSchema,
|
|
1079
1080
|
parentField,
|
|
1080
|
-
|
|
1081
|
+
fieldNameKey,
|
|
1081
1082
|
ANY_OF_KEY,
|
|
1082
1083
|
get8(formData, subPath),
|
|
1083
1084
|
experimental_customMergeAllOf
|
|
@@ -1090,7 +1091,7 @@ function findFieldInSchema(validator, rootSchema, schema, path, formData = {}, e
|
|
|
1090
1091
|
validator,
|
|
1091
1092
|
rootSchema,
|
|
1092
1093
|
parentField,
|
|
1093
|
-
|
|
1094
|
+
fieldNameKey,
|
|
1094
1095
|
ONE_OF_KEY,
|
|
1095
1096
|
formData,
|
|
1096
1097
|
experimental_customMergeAllOf
|
|
@@ -1100,7 +1101,7 @@ function findFieldInSchema(validator, rootSchema, schema, path, formData = {}, e
|
|
|
1100
1101
|
validator,
|
|
1101
1102
|
rootSchema,
|
|
1102
1103
|
parentField,
|
|
1103
|
-
|
|
1104
|
+
fieldNameKey,
|
|
1104
1105
|
ANY_OF_KEY,
|
|
1105
1106
|
formData,
|
|
1106
1107
|
experimental_customMergeAllOf
|
|
@@ -1127,7 +1128,7 @@ function findFieldInSchema(validator, rootSchema, schema, path, formData = {}, e
|
|
|
1127
1128
|
);
|
|
1128
1129
|
let isRequired;
|
|
1129
1130
|
if (field && Array.isArray(requiredArray)) {
|
|
1130
|
-
isRequired = requiredArray.includes(
|
|
1131
|
+
isRequired = requiredArray.includes(fieldNameKey);
|
|
1131
1132
|
}
|
|
1132
1133
|
return { field, isRequired };
|
|
1133
1134
|
}
|
|
@@ -1297,7 +1298,7 @@ function mergeDefaultsWithFormData(defaults, formData, mergeExtraArrayDefaults =
|
|
|
1297
1298
|
const keyExistsInDefaults = isObject(defaults) && key in defaults;
|
|
1298
1299
|
const keyExistsInFormData = key in formData;
|
|
1299
1300
|
const keyDefault = get10(defaults, key) ?? {};
|
|
1300
|
-
const defaultValueIsNestedObject = keyExistsInDefaults && Object.
|
|
1301
|
+
const defaultValueIsNestedObject = keyExistsInDefaults && isObject(keyDefault) && Object.values(keyDefault).some((v) => isObject(v));
|
|
1301
1302
|
const keyDefaultIsObject = keyExistsInDefaults && isObject(get10(defaults, key));
|
|
1302
1303
|
const keyHasFormDataObject = keyExistsInFormData && isObject(keyValue);
|
|
1303
1304
|
if (keyDefaultIsObject && keyHasFormDataObject && !defaultValueIsNestedObject) {
|
|
@@ -1671,7 +1672,7 @@ function ensureFormDataMatchingSchema(validator, schema, rootSchema, formData, e
|
|
|
1671
1672
|
let validFormData = formData;
|
|
1672
1673
|
if (isSelectField) {
|
|
1673
1674
|
const getOptionsList = optionsList(schema);
|
|
1674
|
-
const isValid = getOptionsList?.some((option) =>
|
|
1675
|
+
const isValid = getOptionsList?.some((option) => deepEquals_default(option.value, formData));
|
|
1675
1676
|
validFormData = isValid ? formData : void 0;
|
|
1676
1677
|
}
|
|
1677
1678
|
const constTakesPrecedence = schema[CONST_KEY] && experimental_defaultFormStateBehavior?.constAsDefaults === "always";
|
|
@@ -1732,14 +1733,14 @@ function getObjectDefaults(validator, rawSchema, {
|
|
|
1732
1733
|
if (retrievedSchema.additionalProperties && !initialDefaultsGenerated) {
|
|
1733
1734
|
const additionalPropertiesSchema = isObject(retrievedSchema.additionalProperties) ? retrievedSchema.additionalProperties : {};
|
|
1734
1735
|
const keys2 = /* @__PURE__ */ new Set();
|
|
1735
|
-
if (isObject(defaults)) {
|
|
1736
|
-
Object.keys(defaults).filter((key) => !retrievedSchema.properties || !retrievedSchema.properties[key]).forEach((key) => keys2.add(key));
|
|
1737
|
-
}
|
|
1738
1736
|
const formDataRequired = [];
|
|
1739
1737
|
Object.keys(formData).filter((key) => !retrievedSchema.properties || !retrievedSchema.properties[key]).forEach((key) => {
|
|
1740
1738
|
keys2.add(key);
|
|
1741
1739
|
formDataRequired.push(key);
|
|
1742
1740
|
});
|
|
1741
|
+
if (isObject(defaults) && formDataRequired.length === 0) {
|
|
1742
|
+
Object.keys(defaults).filter((key) => !retrievedSchema.properties || !retrievedSchema.properties[key]).forEach((key) => keys2.add(key));
|
|
1743
|
+
}
|
|
1743
1744
|
keys2.forEach((key) => {
|
|
1744
1745
|
const computedDefault = computeDefaults(validator, additionalPropertiesSchema, {
|
|
1745
1746
|
rootSchema,
|
|
@@ -1973,7 +1974,7 @@ import set2 from "lodash/set";
|
|
|
1973
1974
|
function toPathSchemaInternal(validator, schema, name, rootSchema, formData, _recurseList = [], experimental_customMergeAllOf) {
|
|
1974
1975
|
if (REF_KEY in schema || DEPENDENCIES_KEY in schema || ALL_OF_KEY in schema || IF_KEY in schema) {
|
|
1975
1976
|
const _schema = retrieveSchema(validator, schema, rootSchema, formData, experimental_customMergeAllOf);
|
|
1976
|
-
const sameSchemaIndex = _recurseList.findIndex((item) =>
|
|
1977
|
+
const sameSchemaIndex = _recurseList.findIndex((item) => deepEquals_default(item, _schema));
|
|
1977
1978
|
if (sameSchemaIndex === -1) {
|
|
1978
1979
|
return toPathSchemaInternal(
|
|
1979
1980
|
validator,
|
|
@@ -2325,7 +2326,7 @@ var SchemaUtils = class {
|
|
|
2325
2326
|
if (!validator || !rootSchema) {
|
|
2326
2327
|
return false;
|
|
2327
2328
|
}
|
|
2328
|
-
return this.validator !== validator || !
|
|
2329
|
+
return this.validator !== validator || !deepEquals_default(this.rootSchema, rootSchema) || !deepEquals_default(this.experimental_defaultFormStateBehavior, experimental_defaultFormStateBehavior) || this.experimental_customMergeAllOf !== experimental_customMergeAllOf;
|
|
2329
2330
|
}
|
|
2330
2331
|
/** Finds the field specified by the `path` within the root or recursed `schema`. If there is no field for the specified
|
|
2331
2332
|
* `path`, then the default `{ field: undefined, isRequired: undefined }` is returned. It determines whether a leaf
|
|
@@ -2667,9 +2668,9 @@ function englishStringTranslator(stringToTranslate, params) {
|
|
|
2667
2668
|
// src/enumOptionsIsSelected.ts
|
|
2668
2669
|
function enumOptionsIsSelected(value, selected) {
|
|
2669
2670
|
if (Array.isArray(selected)) {
|
|
2670
|
-
return selected.some((sel) =>
|
|
2671
|
+
return selected.some((sel) => deepEquals_default(sel, value));
|
|
2671
2672
|
}
|
|
2672
|
-
return
|
|
2673
|
+
return deepEquals_default(selected, value);
|
|
2673
2674
|
}
|
|
2674
2675
|
|
|
2675
2676
|
// src/enumOptionsIndexForValue.ts
|
|
@@ -2748,9 +2749,9 @@ function enumOptionValueEncoder(value, index, format = "indexed") {
|
|
|
2748
2749
|
function enumOptionsDeselectValue(valueIndex, selected, allEnumOptions = []) {
|
|
2749
2750
|
const value = enumOptionsValueForIndex(valueIndex, allEnumOptions);
|
|
2750
2751
|
if (Array.isArray(selected)) {
|
|
2751
|
-
return selected.filter((v) => !
|
|
2752
|
+
return selected.filter((v) => !deepEquals_default(v, value));
|
|
2752
2753
|
}
|
|
2753
|
-
return
|
|
2754
|
+
return deepEquals_default(value, selected) ? void 0 : selected;
|
|
2754
2755
|
}
|
|
2755
2756
|
|
|
2756
2757
|
// src/enumOptionsSelectValue.ts
|
|
@@ -2880,7 +2881,7 @@ function getChangedFields(a, b) {
|
|
|
2880
2881
|
} else if (!aIsPlainObject && bIsPlainObject) {
|
|
2881
2882
|
return keys(b);
|
|
2882
2883
|
} else {
|
|
2883
|
-
const unequalFields = keys(pickBy(a, (value, key) => !
|
|
2884
|
+
const unequalFields = keys(pickBy(a, (value, key) => !deepEquals_default(value, get19(b, key))));
|
|
2884
2885
|
const diffFields = difference(keys(b), keys(a));
|
|
2885
2886
|
return [...unequalFields, ...diffFields];
|
|
2886
2887
|
}
|
|
@@ -3200,16 +3201,15 @@ function isFormDataAvailable(formData) {
|
|
|
3200
3201
|
}
|
|
3201
3202
|
|
|
3202
3203
|
// src/isRootSchema.ts
|
|
3203
|
-
import isEqual2 from "lodash/isEqual";
|
|
3204
3204
|
import omit2 from "lodash/omit";
|
|
3205
3205
|
function isRootSchema(registry, schemaToCompare) {
|
|
3206
3206
|
const { rootSchema, schemaUtils } = registry;
|
|
3207
|
-
if (
|
|
3207
|
+
if (deepEquals_default(schemaToCompare, rootSchema)) {
|
|
3208
3208
|
return true;
|
|
3209
3209
|
}
|
|
3210
3210
|
if (REF_KEY in rootSchema) {
|
|
3211
3211
|
const resolvedSchema = schemaUtils.retrieveSchema(rootSchema);
|
|
3212
|
-
return
|
|
3212
|
+
return deepEquals_default(schemaToCompare, omit2(resolvedSchema, RJSF_REF_KEY));
|
|
3213
3213
|
}
|
|
3214
3214
|
return false;
|
|
3215
3215
|
}
|
|
@@ -3446,7 +3446,7 @@ function shouldRender(component, nextProps, nextState, updateStrategy = "customD
|
|
|
3446
3446
|
return !shallowEquals(props2, nextProps) || !shallowEquals(state2, nextState);
|
|
3447
3447
|
}
|
|
3448
3448
|
const { props, state } = component;
|
|
3449
|
-
return !
|
|
3449
|
+
return !deepEquals_default(props, nextProps) || !deepEquals_default(state, nextState);
|
|
3450
3450
|
}
|
|
3451
3451
|
|
|
3452
3452
|
// src/shouldRenderOptionalField.ts
|
|
@@ -3662,10 +3662,9 @@ function useAltDateWidgetProps(props) {
|
|
|
3662
3662
|
|
|
3663
3663
|
// src/useDeepCompareMemo.ts
|
|
3664
3664
|
import { useRef } from "react";
|
|
3665
|
-
import isEqual3 from "lodash/isEqual";
|
|
3666
3665
|
function useDeepCompareMemo(newValue) {
|
|
3667
3666
|
const valueRef = useRef(newValue);
|
|
3668
|
-
if (!
|
|
3667
|
+
if (!deepEquals_default(newValue, valueRef.current)) {
|
|
3669
3668
|
valueRef.current = newValue;
|
|
3670
3669
|
}
|
|
3671
3670
|
return valueRef.current;
|
|
@@ -3881,6 +3880,7 @@ var TranslatableString = /* @__PURE__ */ ((TranslatableString2) => {
|
|
|
3881
3880
|
TranslatableString2["OptionPrefix"] = "Option %1";
|
|
3882
3881
|
TranslatableString2["TitleOptionPrefix"] = "%1 option %2";
|
|
3883
3882
|
TranslatableString2["KeyLabel"] = "%1 Key";
|
|
3883
|
+
TranslatableString2["DeprecatedLabel"] = "%1 (deprecated)";
|
|
3884
3884
|
TranslatableString2["InvalidObjectField"] = 'Invalid "%1" object field configuration: _%2_.';
|
|
3885
3885
|
TranslatableString2["UnsupportedField"] = "Unsupported field schema.";
|
|
3886
3886
|
TranslatableString2["UnsupportedFieldWithId"] = "Unsupported field schema for field `%1`.";
|
|
@@ -3925,7 +3925,7 @@ var ParserValidator = class {
|
|
|
3925
3925
|
const existing = this.schemaMap[key];
|
|
3926
3926
|
if (!existing) {
|
|
3927
3927
|
this.schemaMap[key] = identifiedSchema;
|
|
3928
|
-
} else if (!
|
|
3928
|
+
} else if (!deepEquals_default(existing, identifiedSchema)) {
|
|
3929
3929
|
console.error("existing schema:", JSON.stringify(existing, null, 2));
|
|
3930
3930
|
console.error("new schema:", JSON.stringify(identifiedSchema, null, 2));
|
|
3931
3931
|
throw new Error(
|
|
@@ -3947,7 +3947,7 @@ var ParserValidator = class {
|
|
|
3947
3947
|
* @throws - Error when the given `rootSchema` differs from the root schema provided during construction
|
|
3948
3948
|
*/
|
|
3949
3949
|
isValid(schema, _formData, rootSchema) {
|
|
3950
|
-
if (!
|
|
3950
|
+
if (!deepEquals_default(rootSchema, this.rootSchema)) {
|
|
3951
3951
|
throw new Error("Unexpectedly calling isValid() with a rootSchema that differs from the construction rootSchema");
|
|
3952
3952
|
}
|
|
3953
3953
|
this.addSchema(schema, hashForSchema(schema));
|
|
@@ -3987,7 +3987,7 @@ var ParserValidator = class {
|
|
|
3987
3987
|
function parseSchema(validator, recurseList, rootSchema, schema) {
|
|
3988
3988
|
const schemas = retrieveSchemaInternal(validator, schema, rootSchema, void 0, true);
|
|
3989
3989
|
schemas.forEach((schema2) => {
|
|
3990
|
-
const sameSchemaIndex = recurseList.findIndex((item) =>
|
|
3990
|
+
const sameSchemaIndex = recurseList.findIndex((item) => deepEquals_default(item, schema2));
|
|
3991
3991
|
if (sameSchemaIndex === -1) {
|
|
3992
3992
|
recurseList.push(schema2);
|
|
3993
3993
|
const allOptions = resolveAnyOrOneOfSchemas(validator, schema2, rootSchema, true);
|
|
@@ -4062,7 +4062,7 @@ export {
|
|
|
4062
4062
|
createSchemaUtils,
|
|
4063
4063
|
dataURItoBlob,
|
|
4064
4064
|
dateRangeOptions,
|
|
4065
|
-
deepEquals,
|
|
4065
|
+
deepEquals_default as deepEquals,
|
|
4066
4066
|
descriptionId,
|
|
4067
4067
|
dotNotationNameGenerator,
|
|
4068
4068
|
englishStringTranslator,
|