@rjsf/utils 5.24.0 → 5.24.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.js +33 -25
- package/dist/index.js.map +3 -3
- package/dist/utils.esm.js +33 -25
- package/dist/utils.esm.js.map +2 -2
- package/dist/utils.umd.js +36 -28
- package/lib/deepEquals.d.ts +3 -3
- package/lib/deepEquals.js +15 -13
- package/lib/deepEquals.js.map +1 -1
- package/lib/getChangedFields.d.ts +3 -3
- package/lib/getChangedFields.js +3 -3
- package/lib/getInputProps.js +3 -0
- package/lib/getInputProps.js.map +1 -1
- package/lib/mergeDefaultsWithFormData.js +2 -1
- package/lib/mergeDefaultsWithFormData.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/types.d.ts +2 -0
- package/package.json +3 -2
- package/src/deepEquals.ts +16 -13
- package/src/getChangedFields.ts +3 -3
- package/src/getInputProps.ts +4 -0
- package/src/mergeDefaultsWithFormData.ts +2 -1
- package/src/types.ts +2 -0
package/dist/utils.esm.js
CHANGED
|
@@ -131,15 +131,20 @@ function createErrorHandler(formData) {
|
|
|
131
131
|
}
|
|
132
132
|
|
|
133
133
|
// src/deepEquals.ts
|
|
134
|
-
import
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
134
|
+
import { createCustomEqual } from "fast-equals";
|
|
135
|
+
var deepEquals = createCustomEqual({
|
|
136
|
+
createCustomConfig: () => ({
|
|
137
|
+
// Assume all functions are equivalent
|
|
138
|
+
// see https://github.com/rjsf-team/react-jsonschema-form/issues/255
|
|
139
|
+
//
|
|
140
|
+
// Performance improvement: knowing that typeof a === function, so, only needs to check if typeof b === function.
|
|
141
|
+
// https://github.com/planttheidea/fast-equals/blob/c633c4e653cacf8fd5cbb309b6841df62322d74c/src/comparator.ts#L99
|
|
142
|
+
areFunctionsEqual(_a, b) {
|
|
143
|
+
return typeof b === "function";
|
|
144
|
+
}
|
|
145
|
+
})
|
|
146
|
+
});
|
|
147
|
+
var deepEquals_default = deepEquals;
|
|
143
148
|
|
|
144
149
|
// src/schema/getDefaultFormState.ts
|
|
145
150
|
import get7 from "lodash/get";
|
|
@@ -559,7 +564,7 @@ function resolveAllReferences(schema, rootSchema, recurseList) {
|
|
|
559
564
|
items: resolveAllReferences(resolvedSchema.items, rootSchema, recurseList)
|
|
560
565
|
};
|
|
561
566
|
}
|
|
562
|
-
return
|
|
567
|
+
return deepEquals_default(schema, resolvedSchema) ? schema : resolvedSchema;
|
|
563
568
|
}
|
|
564
569
|
function stubExistingAdditionalProperties(validator, theSchema, rootSchema, aFormData, experimental_customMergeAllOf) {
|
|
565
570
|
const schema = {
|
|
@@ -969,7 +974,7 @@ function mergeDefaultsWithFormData(defaults, formData, mergeExtraArrayDefaults =
|
|
|
969
974
|
const overrideArray = overrideFormDataWithDefaults ? defaultsArray : formData;
|
|
970
975
|
const overrideOppositeArray = overrideFormDataWithDefaults ? formData : defaultsArray;
|
|
971
976
|
const mapped = overrideArray.map((value, idx) => {
|
|
972
|
-
if (overrideOppositeArray[idx]) {
|
|
977
|
+
if (overrideOppositeArray[idx] !== void 0) {
|
|
973
978
|
return mergeDefaultsWithFormData(
|
|
974
979
|
defaultsArray[idx],
|
|
975
980
|
formData[idx],
|
|
@@ -1308,7 +1313,7 @@ function ensureFormDataMatchingSchema(validator, schema, rootSchema, formData, e
|
|
|
1308
1313
|
let validFormData = formData;
|
|
1309
1314
|
if (isSelectField) {
|
|
1310
1315
|
const getOptionsList = optionsList(schema);
|
|
1311
|
-
const isValid = getOptionsList?.some((option) =>
|
|
1316
|
+
const isValid = getOptionsList?.some((option) => deepEquals_default(option.value, formData));
|
|
1312
1317
|
validFormData = isValid ? formData : void 0;
|
|
1313
1318
|
}
|
|
1314
1319
|
const constTakesPrecedence = schema[CONST_KEY] && experimental_defaultFormStateBehavior?.constAsDefaults === "always";
|
|
@@ -1722,7 +1727,7 @@ import get9 from "lodash/get";
|
|
|
1722
1727
|
function toIdSchemaInternal(validator, schema, idPrefix, idSeparator, id, rootSchema, formData, _recurseList = [], experimental_customMergeAllOf) {
|
|
1723
1728
|
if (REF_KEY in schema || DEPENDENCIES_KEY in schema || ALL_OF_KEY in schema) {
|
|
1724
1729
|
const _schema = retrieveSchema(validator, schema, rootSchema, formData, experimental_customMergeAllOf);
|
|
1725
|
-
const sameSchemaIndex = _recurseList.findIndex((item) =>
|
|
1730
|
+
const sameSchemaIndex = _recurseList.findIndex((item) => deepEquals_default(item, _schema));
|
|
1726
1731
|
if (sameSchemaIndex === -1) {
|
|
1727
1732
|
return toIdSchemaInternal(
|
|
1728
1733
|
validator,
|
|
@@ -1793,7 +1798,7 @@ import set2 from "lodash/set";
|
|
|
1793
1798
|
function toPathSchemaInternal(validator, schema, name, rootSchema, formData, _recurseList = [], experimental_customMergeAllOf) {
|
|
1794
1799
|
if (REF_KEY in schema || DEPENDENCIES_KEY in schema || ALL_OF_KEY in schema) {
|
|
1795
1800
|
const _schema = retrieveSchema(validator, schema, rootSchema, formData, experimental_customMergeAllOf);
|
|
1796
|
-
const sameSchemaIndex = _recurseList.findIndex((item) =>
|
|
1801
|
+
const sameSchemaIndex = _recurseList.findIndex((item) => deepEquals_default(item, _schema));
|
|
1797
1802
|
if (sameSchemaIndex === -1) {
|
|
1798
1803
|
return toPathSchemaInternal(
|
|
1799
1804
|
validator,
|
|
@@ -1937,7 +1942,7 @@ var SchemaUtils = class {
|
|
|
1937
1942
|
if (!validator || !rootSchema) {
|
|
1938
1943
|
return false;
|
|
1939
1944
|
}
|
|
1940
|
-
return this.validator !== validator || !
|
|
1945
|
+
return this.validator !== validator || !deepEquals_default(this.rootSchema, rootSchema) || !deepEquals_default(this.experimental_defaultFormStateBehavior, experimental_defaultFormStateBehavior) || this.experimental_customMergeAllOf !== experimental_customMergeAllOf;
|
|
1941
1946
|
}
|
|
1942
1947
|
/** Returns the superset of `formData` that includes the given set updated to include any missing fields that have
|
|
1943
1948
|
* computed to have defaults provided in the `schema`.
|
|
@@ -2245,17 +2250,17 @@ function enumOptionsValueForIndex(valueIndex, allEnumOptions = [], emptyValue) {
|
|
|
2245
2250
|
function enumOptionsDeselectValue(valueIndex, selected, allEnumOptions = []) {
|
|
2246
2251
|
const value = enumOptionsValueForIndex(valueIndex, allEnumOptions);
|
|
2247
2252
|
if (Array.isArray(selected)) {
|
|
2248
|
-
return selected.filter((v) => !
|
|
2253
|
+
return selected.filter((v) => !deepEquals_default(v, value));
|
|
2249
2254
|
}
|
|
2250
|
-
return
|
|
2255
|
+
return deepEquals_default(value, selected) ? void 0 : selected;
|
|
2251
2256
|
}
|
|
2252
2257
|
|
|
2253
2258
|
// src/enumOptionsIsSelected.ts
|
|
2254
2259
|
function enumOptionsIsSelected(value, selected) {
|
|
2255
2260
|
if (Array.isArray(selected)) {
|
|
2256
|
-
return selected.some((sel) =>
|
|
2261
|
+
return selected.some((sel) => deepEquals_default(sel, value));
|
|
2257
2262
|
}
|
|
2258
|
-
return
|
|
2263
|
+
return deepEquals_default(selected, value);
|
|
2259
2264
|
}
|
|
2260
2265
|
|
|
2261
2266
|
// src/enumOptionsIndexForValue.ts
|
|
@@ -2444,6 +2449,9 @@ function getInputProps(schema, defaultType, options = {}, autoDefaultStepAny = t
|
|
|
2444
2449
|
if (options.autocomplete) {
|
|
2445
2450
|
inputProps.autoComplete = options.autocomplete;
|
|
2446
2451
|
}
|
|
2452
|
+
if (options.accept) {
|
|
2453
|
+
inputProps.accept = options.accept;
|
|
2454
|
+
}
|
|
2447
2455
|
return inputProps;
|
|
2448
2456
|
}
|
|
2449
2457
|
|
|
@@ -2719,7 +2727,7 @@ function schemaRequiresTrueValue(schema) {
|
|
|
2719
2727
|
// src/shouldRender.ts
|
|
2720
2728
|
function shouldRender(component, nextProps, nextState) {
|
|
2721
2729
|
const { props, state } = component;
|
|
2722
|
-
return !
|
|
2730
|
+
return !deepEquals_default(props, nextProps) || !deepEquals_default(state, nextState);
|
|
2723
2731
|
}
|
|
2724
2732
|
|
|
2725
2733
|
// src/toDateString.ts
|
|
@@ -2877,7 +2885,7 @@ function getChangedFields(a, b) {
|
|
|
2877
2885
|
} else if (!aIsPlainObject && bIsPlainObject) {
|
|
2878
2886
|
return keys(b);
|
|
2879
2887
|
} else {
|
|
2880
|
-
const unequalFields = keys(pickBy(a, (value, key) => !
|
|
2888
|
+
const unequalFields = keys(pickBy(a, (value, key) => !deepEquals_default(value, get13(b, key))));
|
|
2881
2889
|
const diffFields = difference(keys(b), keys(a));
|
|
2882
2890
|
return [...unequalFields, ...diffFields];
|
|
2883
2891
|
}
|
|
@@ -2952,7 +2960,7 @@ var ParserValidator = class {
|
|
|
2952
2960
|
const existing = this.schemaMap[key];
|
|
2953
2961
|
if (!existing) {
|
|
2954
2962
|
this.schemaMap[key] = identifiedSchema;
|
|
2955
|
-
} else if (!
|
|
2963
|
+
} else if (!deepEquals_default(existing, identifiedSchema)) {
|
|
2956
2964
|
console.error("existing schema:", JSON.stringify(existing, null, 2));
|
|
2957
2965
|
console.error("new schema:", JSON.stringify(identifiedSchema, null, 2));
|
|
2958
2966
|
throw new Error(
|
|
@@ -2974,7 +2982,7 @@ var ParserValidator = class {
|
|
|
2974
2982
|
* @throws - Error when the given `rootSchema` differs from the root schema provided during construction
|
|
2975
2983
|
*/
|
|
2976
2984
|
isValid(schema, _formData, rootSchema) {
|
|
2977
|
-
if (!
|
|
2985
|
+
if (!deepEquals_default(rootSchema, this.rootSchema)) {
|
|
2978
2986
|
throw new Error("Unexpectedly calling isValid() with a rootSchema that differs from the construction rootSchema");
|
|
2979
2987
|
}
|
|
2980
2988
|
this.addSchema(schema, hashForSchema(schema));
|
|
@@ -3014,7 +3022,7 @@ var ParserValidator = class {
|
|
|
3014
3022
|
function parseSchema(validator, recurseList, rootSchema, schema) {
|
|
3015
3023
|
const schemas = retrieveSchemaInternal(validator, schema, rootSchema, void 0, true);
|
|
3016
3024
|
schemas.forEach((schema2) => {
|
|
3017
|
-
const sameSchemaIndex = recurseList.findIndex((item) =>
|
|
3025
|
+
const sameSchemaIndex = recurseList.findIndex((item) => deepEquals_default(item, schema2));
|
|
3018
3026
|
if (sameSchemaIndex === -1) {
|
|
3019
3027
|
recurseList.push(schema2);
|
|
3020
3028
|
const allOptions = resolveAnyOrOneOfSchemas(validator, schema2, rootSchema, true);
|
|
@@ -3075,7 +3083,7 @@ export {
|
|
|
3075
3083
|
createSchemaUtils,
|
|
3076
3084
|
dataURItoBlob,
|
|
3077
3085
|
dateRangeOptions,
|
|
3078
|
-
deepEquals,
|
|
3086
|
+
deepEquals_default as deepEquals,
|
|
3079
3087
|
descriptionId,
|
|
3080
3088
|
englishStringTranslator,
|
|
3081
3089
|
enumOptionsDeselectValue,
|