@rjsf/utils 5.23.2 → 5.24.0
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 +217 -130
- package/dist/index.js.map +4 -4
- package/dist/utils.esm.js +217 -130
- package/dist/utils.esm.js.map +4 -4
- package/dist/utils.umd.js +209 -122
- package/lib/constIsAjvDataReference.d.ts +9 -0
- package/lib/constIsAjvDataReference.js +15 -0
- package/lib/constIsAjvDataReference.js.map +1 -0
- package/lib/enumOptionsDeselectValue.js +3 -3
- package/lib/enumOptionsDeselectValue.js.map +1 -1
- package/lib/enumOptionsIsSelected.js +3 -3
- package/lib/enumOptionsIsSelected.js.map +1 -1
- package/lib/getChangedFields.d.ts +17 -0
- package/lib/getChangedFields.js +42 -0
- package/lib/getChangedFields.js.map +1 -0
- package/lib/index.d.ts +2 -1
- package/lib/index.js +2 -1
- package/lib/index.js.map +1 -1
- package/lib/mergeDefaultsWithFormData.d.ts +5 -1
- package/lib/mergeDefaultsWithFormData.js +31 -8
- package/lib/mergeDefaultsWithFormData.js.map +1 -1
- package/lib/parser/ParserValidator.js +3 -3
- package/lib/parser/ParserValidator.js.map +1 -1
- package/lib/parser/schemaParser.js +4 -4
- package/lib/parser/schemaParser.js.map +1 -1
- package/lib/schema/getDefaultFormState.d.ts +17 -2
- package/lib/schema/getDefaultFormState.js +85 -31
- package/lib/schema/getDefaultFormState.js.map +1 -1
- package/lib/schema/retrieveSchema.js +7 -4
- package/lib/schema/retrieveSchema.js.map +1 -1
- package/lib/schema/toIdSchema.js +2 -2
- package/lib/schema/toIdSchema.js.map +1 -1
- package/lib/schema/toPathSchema.js +3 -3
- package/lib/schema/toPathSchema.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/src/constIsAjvDataReference.ts +17 -0
- package/src/enumOptionsDeselectValue.ts +3 -4
- package/src/enumOptionsIsSelected.ts +3 -4
- package/src/getChangedFields.ts +40 -0
- package/src/index.ts +2 -0
- package/src/mergeDefaultsWithFormData.ts +42 -10
- package/src/parser/ParserValidator.ts +3 -3
- package/src/parser/schemaParser.ts +4 -4
- package/src/schema/getDefaultFormState.ts +126 -31
- package/src/schema/retrieveSchema.ts +8 -5
- package/src/schema/toIdSchema.ts +2 -2
- package/src/schema/toPathSchema.ts +3 -3
package/dist/utils.esm.js
CHANGED
|
@@ -282,7 +282,6 @@ function getFirstMatchingOption(validator, formData, options, rootSchema, discri
|
|
|
282
282
|
|
|
283
283
|
// src/schema/retrieveSchema.ts
|
|
284
284
|
import get4 from "lodash/get";
|
|
285
|
-
import isEqual from "lodash/isEqual";
|
|
286
285
|
import set from "lodash/set";
|
|
287
286
|
import times from "lodash/times";
|
|
288
287
|
import transform from "lodash/transform";
|
|
@@ -504,7 +503,10 @@ function resolveSchema(validator, schema, rootSchema, expandAllBranches, recurse
|
|
|
504
503
|
)
|
|
505
504
|
);
|
|
506
505
|
const allPermutations = getAllPermutationsOfXxxOf(allOfSchemaElements);
|
|
507
|
-
return allPermutations.map((permutation) => ({
|
|
506
|
+
return allPermutations.map((permutation) => ({
|
|
507
|
+
...schema,
|
|
508
|
+
allOf: permutation
|
|
509
|
+
}));
|
|
508
510
|
}
|
|
509
511
|
return [schema];
|
|
510
512
|
}
|
|
@@ -557,7 +559,7 @@ function resolveAllReferences(schema, rootSchema, recurseList) {
|
|
|
557
559
|
items: resolveAllReferences(resolvedSchema.items, rootSchema, recurseList)
|
|
558
560
|
};
|
|
559
561
|
}
|
|
560
|
-
return
|
|
562
|
+
return deepEquals(schema, resolvedSchema) ? schema : resolvedSchema;
|
|
561
563
|
}
|
|
562
564
|
function stubExistingAdditionalProperties(validator, theSchema, rootSchema, aFormData, experimental_customMergeAllOf) {
|
|
563
565
|
const schema = {
|
|
@@ -960,38 +962,48 @@ function isFixedItems(schema) {
|
|
|
960
962
|
|
|
961
963
|
// src/mergeDefaultsWithFormData.ts
|
|
962
964
|
import get6 from "lodash/get";
|
|
963
|
-
|
|
965
|
+
import isNil from "lodash/isNil";
|
|
966
|
+
function mergeDefaultsWithFormData(defaults, formData, mergeExtraArrayDefaults = false, defaultSupercedesUndefined = false, overrideFormDataWithDefaults = false) {
|
|
964
967
|
if (Array.isArray(formData)) {
|
|
965
968
|
const defaultsArray = Array.isArray(defaults) ? defaults : [];
|
|
966
|
-
const
|
|
967
|
-
|
|
969
|
+
const overrideArray = overrideFormDataWithDefaults ? defaultsArray : formData;
|
|
970
|
+
const overrideOppositeArray = overrideFormDataWithDefaults ? formData : defaultsArray;
|
|
971
|
+
const mapped = overrideArray.map((value, idx) => {
|
|
972
|
+
if (overrideOppositeArray[idx]) {
|
|
968
973
|
return mergeDefaultsWithFormData(
|
|
969
974
|
defaultsArray[idx],
|
|
970
|
-
|
|
975
|
+
formData[idx],
|
|
971
976
|
mergeExtraArrayDefaults,
|
|
972
|
-
defaultSupercedesUndefined
|
|
977
|
+
defaultSupercedesUndefined,
|
|
978
|
+
overrideFormDataWithDefaults
|
|
973
979
|
);
|
|
974
980
|
}
|
|
975
981
|
return value;
|
|
976
982
|
});
|
|
977
|
-
if (mergeExtraArrayDefaults && mapped.length <
|
|
978
|
-
mapped.push(...
|
|
983
|
+
if ((mergeExtraArrayDefaults || overrideFormDataWithDefaults) && mapped.length < overrideOppositeArray.length) {
|
|
984
|
+
mapped.push(...overrideOppositeArray.slice(mapped.length));
|
|
979
985
|
}
|
|
980
986
|
return mapped;
|
|
981
987
|
}
|
|
982
988
|
if (isObject(formData)) {
|
|
983
989
|
const acc = Object.assign({}, defaults);
|
|
984
990
|
return Object.keys(formData).reduce((acc2, key) => {
|
|
991
|
+
const keyValue = get6(formData, key);
|
|
992
|
+
const keyExistsInDefaults = isObject(defaults) && key in defaults;
|
|
993
|
+
const keyExistsInFormData = key in formData;
|
|
985
994
|
acc2[key] = mergeDefaultsWithFormData(
|
|
986
995
|
defaults ? get6(defaults, key) : {},
|
|
987
|
-
|
|
996
|
+
keyValue,
|
|
988
997
|
mergeExtraArrayDefaults,
|
|
989
|
-
defaultSupercedesUndefined
|
|
998
|
+
defaultSupercedesUndefined,
|
|
999
|
+
// overrideFormDataWithDefaults can be true only when the key value exists in defaults
|
|
1000
|
+
// Or if the key value doesn't exist in formData
|
|
1001
|
+
overrideFormDataWithDefaults && (keyExistsInDefaults || !keyExistsInFormData)
|
|
990
1002
|
);
|
|
991
1003
|
return acc2;
|
|
992
1004
|
}, acc);
|
|
993
1005
|
}
|
|
994
|
-
if (defaultSupercedesUndefined && formData ===
|
|
1006
|
+
if (defaultSupercedesUndefined && (!isNil(defaults) && isNil(formData) || typeof formData === "number" && isNaN(formData)) || overrideFormDataWithDefaults && !isNil(formData)) {
|
|
995
1007
|
return defaults;
|
|
996
1008
|
}
|
|
997
1009
|
return formData;
|
|
@@ -1047,6 +1059,69 @@ function isMultiSelect(validator, schema, rootSchema, experimental_customMergeAl
|
|
|
1047
1059
|
return isSelect(validator, schema.items, rootSchema, experimental_customMergeAllOf);
|
|
1048
1060
|
}
|
|
1049
1061
|
|
|
1062
|
+
// src/constIsAjvDataReference.ts
|
|
1063
|
+
import isString3 from "lodash/isString";
|
|
1064
|
+
function constIsAjvDataReference(schema) {
|
|
1065
|
+
const schemaConst = schema[CONST_KEY];
|
|
1066
|
+
const schemaType = getSchemaType(schema);
|
|
1067
|
+
return isObject(schemaConst) && isString3(schemaConst?.$data) && schemaType !== "object" && schemaType !== "array";
|
|
1068
|
+
}
|
|
1069
|
+
|
|
1070
|
+
// src/toConstant.ts
|
|
1071
|
+
function toConstant(schema) {
|
|
1072
|
+
if (ENUM_KEY in schema && Array.isArray(schema.enum) && schema.enum.length === 1) {
|
|
1073
|
+
return schema.enum[0];
|
|
1074
|
+
}
|
|
1075
|
+
if (CONST_KEY in schema) {
|
|
1076
|
+
return schema.const;
|
|
1077
|
+
}
|
|
1078
|
+
throw new Error("schema cannot be inferred as a constant");
|
|
1079
|
+
}
|
|
1080
|
+
|
|
1081
|
+
// src/optionsList.ts
|
|
1082
|
+
function optionsList(schema, uiSchema) {
|
|
1083
|
+
const schemaWithEnumNames = schema;
|
|
1084
|
+
if (schema.enum) {
|
|
1085
|
+
let enumNames;
|
|
1086
|
+
if (uiSchema) {
|
|
1087
|
+
const { enumNames: uiEnumNames } = getUiOptions(uiSchema);
|
|
1088
|
+
enumNames = uiEnumNames;
|
|
1089
|
+
}
|
|
1090
|
+
if (!enumNames && schemaWithEnumNames.enumNames) {
|
|
1091
|
+
if (true) {
|
|
1092
|
+
console.warn(
|
|
1093
|
+
'The "enumNames" property in the schema is deprecated and will be removed in a future major release. Use the "ui:enumNames" property in the uiSchema instead.'
|
|
1094
|
+
);
|
|
1095
|
+
}
|
|
1096
|
+
enumNames = schemaWithEnumNames.enumNames;
|
|
1097
|
+
}
|
|
1098
|
+
return schema.enum.map((value, i) => {
|
|
1099
|
+
const label = enumNames?.[i] || String(value);
|
|
1100
|
+
return { label, value };
|
|
1101
|
+
});
|
|
1102
|
+
}
|
|
1103
|
+
let altSchemas = void 0;
|
|
1104
|
+
let altUiSchemas = void 0;
|
|
1105
|
+
if (schema.anyOf) {
|
|
1106
|
+
altSchemas = schema.anyOf;
|
|
1107
|
+
altUiSchemas = uiSchema?.anyOf;
|
|
1108
|
+
} else if (schema.oneOf) {
|
|
1109
|
+
altSchemas = schema.oneOf;
|
|
1110
|
+
altUiSchemas = uiSchema?.oneOf;
|
|
1111
|
+
}
|
|
1112
|
+
return altSchemas && altSchemas.map((aSchemaDef, index) => {
|
|
1113
|
+
const { title } = getUiOptions(altUiSchemas?.[index]);
|
|
1114
|
+
const aSchema = aSchemaDef;
|
|
1115
|
+
const value = toConstant(aSchema);
|
|
1116
|
+
const label = title || aSchema.title || String(value);
|
|
1117
|
+
return {
|
|
1118
|
+
schema: aSchema,
|
|
1119
|
+
label,
|
|
1120
|
+
value
|
|
1121
|
+
};
|
|
1122
|
+
});
|
|
1123
|
+
}
|
|
1124
|
+
|
|
1050
1125
|
// src/schema/getDefaultFormState.ts
|
|
1051
1126
|
var PRIMITIVE_TYPES = ["string", "number", "integer", "boolean", "null"];
|
|
1052
1127
|
function getInnerSchemaForArrayItem(schema, additionalItems = 0 /* Ignore */, idx = -1) {
|
|
@@ -1070,8 +1145,8 @@ function maybeAddDefaultToObject(obj, key, computedDefault, includeUndefinedValu
|
|
|
1070
1145
|
if (includeUndefinedValues || isConst) {
|
|
1071
1146
|
obj[key] = computedDefault;
|
|
1072
1147
|
} else if (emptyObjectFields !== "skipDefaults") {
|
|
1148
|
+
const isSelfOrParentRequired = isParentRequired === void 0 ? requiredFields.includes(key) : isParentRequired;
|
|
1073
1149
|
if (isObject(computedDefault)) {
|
|
1074
|
-
const isSelfOrParentRequired = isParentRequired === void 0 ? requiredFields.includes(key) : isParentRequired;
|
|
1075
1150
|
if (emptyObjectFields === "skipEmptyDefaults") {
|
|
1076
1151
|
if (!isEmpty(computedDefault)) {
|
|
1077
1152
|
obj[key] = computedDefault;
|
|
@@ -1082,8 +1157,9 @@ function maybeAddDefaultToObject(obj, key, computedDefault, includeUndefinedValu
|
|
|
1082
1157
|
} else if (
|
|
1083
1158
|
// Store computedDefault if it's a defined primitive (e.g., true) and satisfies certain conditions
|
|
1084
1159
|
// Condition 1: computedDefault is not undefined
|
|
1085
|
-
// Condition 2: If emptyObjectFields is 'populateAllDefaults' or 'skipEmptyDefaults)
|
|
1086
|
-
|
|
1160
|
+
// Condition 2: If emptyObjectFields is 'populateAllDefaults' or 'skipEmptyDefaults)
|
|
1161
|
+
// Or if isSelfOrParentRequired is 'true' and the key is a required field
|
|
1162
|
+
computedDefault !== void 0 && (emptyObjectFields === "populateAllDefaults" || emptyObjectFields === "skipEmptyDefaults" || isSelfOrParentRequired && requiredFields.includes(key))
|
|
1087
1163
|
) {
|
|
1088
1164
|
obj[key] = computedDefault;
|
|
1089
1165
|
}
|
|
@@ -1098,7 +1174,8 @@ function computeDefaults(validator, rawSchema, computeDefaultsProps = {}) {
|
|
|
1098
1174
|
_recurseList = [],
|
|
1099
1175
|
experimental_defaultFormStateBehavior = void 0,
|
|
1100
1176
|
experimental_customMergeAllOf = void 0,
|
|
1101
|
-
required
|
|
1177
|
+
required,
|
|
1178
|
+
shouldMergeDefaultsIntoFormData = false
|
|
1102
1179
|
} = computeDefaultsProps;
|
|
1103
1180
|
const formData = isObject(rawFormData) ? rawFormData : {};
|
|
1104
1181
|
const schema = isObject(rawSchema) ? rawSchema : {};
|
|
@@ -1106,8 +1183,8 @@ function computeDefaults(validator, rawSchema, computeDefaultsProps = {}) {
|
|
|
1106
1183
|
let schemaToCompute = null;
|
|
1107
1184
|
let experimental_dfsb_to_compute = experimental_defaultFormStateBehavior;
|
|
1108
1185
|
let updatedRecurseList = _recurseList;
|
|
1109
|
-
if (schema[CONST_KEY] && experimental_defaultFormStateBehavior?.constAsDefaults !== "never") {
|
|
1110
|
-
defaults = schema
|
|
1186
|
+
if (schema[CONST_KEY] && experimental_defaultFormStateBehavior?.constAsDefaults !== "never" && !constIsAjvDataReference(schema)) {
|
|
1187
|
+
defaults = schema[CONST_KEY];
|
|
1111
1188
|
} else if (isObject(defaults) && isObject(schema.default)) {
|
|
1112
1189
|
defaults = mergeObjects(defaults, schema.default);
|
|
1113
1190
|
} else if (DEFAULT_KEY in schema) {
|
|
@@ -1143,7 +1220,8 @@ function computeDefaults(validator, rawSchema, computeDefaultsProps = {}) {
|
|
|
1143
1220
|
experimental_customMergeAllOf,
|
|
1144
1221
|
parentDefaults: Array.isArray(parentDefaults) ? parentDefaults[idx] : void 0,
|
|
1145
1222
|
rawFormData: formData,
|
|
1146
|
-
required
|
|
1223
|
+
required,
|
|
1224
|
+
shouldMergeDefaultsIntoFormData
|
|
1147
1225
|
})
|
|
1148
1226
|
);
|
|
1149
1227
|
} else if (ONE_OF_KEY in schema) {
|
|
@@ -1154,12 +1232,15 @@ function computeDefaults(validator, rawSchema, computeDefaultsProps = {}) {
|
|
|
1154
1232
|
const discriminator = getDiscriminatorFieldFromSchema(schema);
|
|
1155
1233
|
const { type = "null" } = remaining;
|
|
1156
1234
|
if (!Array.isArray(type) && PRIMITIVE_TYPES.includes(type) && experimental_dfsb_to_compute?.constAsDefaults === "skipOneOf") {
|
|
1157
|
-
experimental_dfsb_to_compute = {
|
|
1235
|
+
experimental_dfsb_to_compute = {
|
|
1236
|
+
...experimental_dfsb_to_compute,
|
|
1237
|
+
constAsDefaults: "never"
|
|
1238
|
+
};
|
|
1158
1239
|
}
|
|
1159
1240
|
schemaToCompute = oneOf[getClosestMatchingOption(
|
|
1160
1241
|
validator,
|
|
1161
1242
|
rootSchema,
|
|
1162
|
-
|
|
1243
|
+
rawFormData,
|
|
1163
1244
|
oneOf,
|
|
1164
1245
|
0,
|
|
1165
1246
|
discriminator,
|
|
@@ -1175,7 +1256,7 @@ function computeDefaults(validator, rawSchema, computeDefaultsProps = {}) {
|
|
|
1175
1256
|
schemaToCompute = anyOf[getClosestMatchingOption(
|
|
1176
1257
|
validator,
|
|
1177
1258
|
rootSchema,
|
|
1178
|
-
|
|
1259
|
+
rawFormData,
|
|
1179
1260
|
anyOf,
|
|
1180
1261
|
0,
|
|
1181
1262
|
discriminator,
|
|
@@ -1192,14 +1273,49 @@ function computeDefaults(validator, rawSchema, computeDefaultsProps = {}) {
|
|
|
1192
1273
|
experimental_customMergeAllOf,
|
|
1193
1274
|
parentDefaults: defaults,
|
|
1194
1275
|
rawFormData: formData,
|
|
1195
|
-
required
|
|
1276
|
+
required,
|
|
1277
|
+
shouldMergeDefaultsIntoFormData
|
|
1196
1278
|
});
|
|
1197
1279
|
}
|
|
1198
1280
|
if (defaults === void 0) {
|
|
1199
1281
|
defaults = schema.default;
|
|
1200
1282
|
}
|
|
1201
1283
|
const defaultBasedOnSchemaType = getDefaultBasedOnSchemaType(validator, schema, computeDefaultsProps, defaults);
|
|
1202
|
-
|
|
1284
|
+
let defaultsWithFormData = defaultBasedOnSchemaType ?? defaults;
|
|
1285
|
+
if (shouldMergeDefaultsIntoFormData) {
|
|
1286
|
+
const { arrayMinItems = {} } = experimental_defaultFormStateBehavior || {};
|
|
1287
|
+
const { mergeExtraDefaults } = arrayMinItems;
|
|
1288
|
+
const matchingFormData = ensureFormDataMatchingSchema(
|
|
1289
|
+
validator,
|
|
1290
|
+
schema,
|
|
1291
|
+
rootSchema,
|
|
1292
|
+
rawFormData,
|
|
1293
|
+
experimental_defaultFormStateBehavior
|
|
1294
|
+
);
|
|
1295
|
+
if (!isObject(rawFormData)) {
|
|
1296
|
+
defaultsWithFormData = mergeDefaultsWithFormData(
|
|
1297
|
+
defaultsWithFormData,
|
|
1298
|
+
matchingFormData,
|
|
1299
|
+
mergeExtraDefaults,
|
|
1300
|
+
true
|
|
1301
|
+
);
|
|
1302
|
+
}
|
|
1303
|
+
}
|
|
1304
|
+
return defaultsWithFormData;
|
|
1305
|
+
}
|
|
1306
|
+
function ensureFormDataMatchingSchema(validator, schema, rootSchema, formData, experimental_defaultFormStateBehavior) {
|
|
1307
|
+
const isSelectField = !isConstant(schema) && isSelect(validator, schema, rootSchema);
|
|
1308
|
+
let validFormData = formData;
|
|
1309
|
+
if (isSelectField) {
|
|
1310
|
+
const getOptionsList = optionsList(schema);
|
|
1311
|
+
const isValid = getOptionsList?.some((option) => deepEquals(option.value, formData));
|
|
1312
|
+
validFormData = isValid ? formData : void 0;
|
|
1313
|
+
}
|
|
1314
|
+
const constTakesPrecedence = schema[CONST_KEY] && experimental_defaultFormStateBehavior?.constAsDefaults === "always";
|
|
1315
|
+
if (constTakesPrecedence) {
|
|
1316
|
+
validFormData = schema.const;
|
|
1317
|
+
}
|
|
1318
|
+
return validFormData;
|
|
1203
1319
|
}
|
|
1204
1320
|
function getObjectDefaults(validator, rawSchema, {
|
|
1205
1321
|
rawFormData,
|
|
@@ -1208,7 +1324,8 @@ function getObjectDefaults(validator, rawSchema, {
|
|
|
1208
1324
|
_recurseList = [],
|
|
1209
1325
|
experimental_defaultFormStateBehavior = void 0,
|
|
1210
1326
|
experimental_customMergeAllOf = void 0,
|
|
1211
|
-
required
|
|
1327
|
+
required,
|
|
1328
|
+
shouldMergeDefaultsIntoFormData
|
|
1212
1329
|
} = {}, defaults) {
|
|
1213
1330
|
{
|
|
1214
1331
|
const formData = isObject(rawFormData) ? rawFormData : {};
|
|
@@ -1219,7 +1336,7 @@ function getObjectDefaults(validator, rawSchema, {
|
|
|
1219
1336
|
(acc, key) => {
|
|
1220
1337
|
const propertySchema = get7(retrievedSchema, [PROPERTIES_KEY, key]);
|
|
1221
1338
|
const hasParentConst = isObject(parentConst) && parentConst[key] !== void 0;
|
|
1222
|
-
const hasConst = (isObject(propertySchema) && CONST_KEY in propertySchema || hasParentConst) && experimental_defaultFormStateBehavior?.constAsDefaults !== "never";
|
|
1339
|
+
const hasConst = (isObject(propertySchema) && CONST_KEY in propertySchema || hasParentConst) && experimental_defaultFormStateBehavior?.constAsDefaults !== "never" && !constIsAjvDataReference(propertySchema);
|
|
1223
1340
|
const computedDefault = computeDefaults(validator, propertySchema, {
|
|
1224
1341
|
rootSchema,
|
|
1225
1342
|
_recurseList,
|
|
@@ -1228,7 +1345,8 @@ function getObjectDefaults(validator, rawSchema, {
|
|
|
1228
1345
|
includeUndefinedValues: includeUndefinedValues === true,
|
|
1229
1346
|
parentDefaults: get7(defaults, [key]),
|
|
1230
1347
|
rawFormData: get7(formData, [key]),
|
|
1231
|
-
required: retrievedSchema.required?.includes(key)
|
|
1348
|
+
required: retrievedSchema.required?.includes(key),
|
|
1349
|
+
shouldMergeDefaultsIntoFormData
|
|
1232
1350
|
});
|
|
1233
1351
|
maybeAddDefaultToObject(
|
|
1234
1352
|
acc,
|
|
@@ -1246,16 +1364,16 @@ function getObjectDefaults(validator, rawSchema, {
|
|
|
1246
1364
|
);
|
|
1247
1365
|
if (retrievedSchema.additionalProperties) {
|
|
1248
1366
|
const additionalPropertiesSchema = isObject(retrievedSchema.additionalProperties) ? retrievedSchema.additionalProperties : {};
|
|
1249
|
-
const
|
|
1367
|
+
const keys2 = /* @__PURE__ */ new Set();
|
|
1250
1368
|
if (isObject(defaults)) {
|
|
1251
|
-
Object.keys(defaults).filter((key) => !retrievedSchema.properties || !retrievedSchema.properties[key]).forEach((key) =>
|
|
1369
|
+
Object.keys(defaults).filter((key) => !retrievedSchema.properties || !retrievedSchema.properties[key]).forEach((key) => keys2.add(key));
|
|
1252
1370
|
}
|
|
1253
1371
|
const formDataRequired = [];
|
|
1254
1372
|
Object.keys(formData).filter((key) => !retrievedSchema.properties || !retrievedSchema.properties[key]).forEach((key) => {
|
|
1255
|
-
|
|
1373
|
+
keys2.add(key);
|
|
1256
1374
|
formDataRequired.push(key);
|
|
1257
1375
|
});
|
|
1258
|
-
|
|
1376
|
+
keys2.forEach((key) => {
|
|
1259
1377
|
const computedDefault = computeDefaults(validator, additionalPropertiesSchema, {
|
|
1260
1378
|
rootSchema,
|
|
1261
1379
|
_recurseList,
|
|
@@ -1264,7 +1382,8 @@ function getObjectDefaults(validator, rawSchema, {
|
|
|
1264
1382
|
includeUndefinedValues: includeUndefinedValues === true,
|
|
1265
1383
|
parentDefaults: get7(defaults, [key]),
|
|
1266
1384
|
rawFormData: get7(formData, [key]),
|
|
1267
|
-
required: retrievedSchema.required?.includes(key)
|
|
1385
|
+
required: retrievedSchema.required?.includes(key),
|
|
1386
|
+
shouldMergeDefaultsIntoFormData
|
|
1268
1387
|
});
|
|
1269
1388
|
maybeAddDefaultToObject(
|
|
1270
1389
|
objectDefaults,
|
|
@@ -1285,7 +1404,8 @@ function getArrayDefaults(validator, rawSchema, {
|
|
|
1285
1404
|
_recurseList = [],
|
|
1286
1405
|
experimental_defaultFormStateBehavior = void 0,
|
|
1287
1406
|
experimental_customMergeAllOf = void 0,
|
|
1288
|
-
required
|
|
1407
|
+
required,
|
|
1408
|
+
shouldMergeDefaultsIntoFormData
|
|
1289
1409
|
} = {}, defaults) {
|
|
1290
1410
|
const schema = rawSchema;
|
|
1291
1411
|
const arrayMinItemsStateBehavior = experimental_defaultFormStateBehavior?.arrayMinItems ?? {};
|
|
@@ -1305,7 +1425,8 @@ function getArrayDefaults(validator, rawSchema, {
|
|
|
1305
1425
|
experimental_defaultFormStateBehavior,
|
|
1306
1426
|
experimental_customMergeAllOf,
|
|
1307
1427
|
parentDefaults: item,
|
|
1308
|
-
required
|
|
1428
|
+
required,
|
|
1429
|
+
shouldMergeDefaultsIntoFormData
|
|
1309
1430
|
});
|
|
1310
1431
|
});
|
|
1311
1432
|
}
|
|
@@ -1322,7 +1443,8 @@ function getArrayDefaults(validator, rawSchema, {
|
|
|
1322
1443
|
experimental_customMergeAllOf,
|
|
1323
1444
|
rawFormData: item,
|
|
1324
1445
|
parentDefaults: get7(defaults, [idx]),
|
|
1325
|
-
required
|
|
1446
|
+
required,
|
|
1447
|
+
shouldMergeDefaultsIntoFormData
|
|
1326
1448
|
});
|
|
1327
1449
|
});
|
|
1328
1450
|
const mergeExtraDefaults = (ignoreMinItemsFlagSet && required || isPopulateAll) && arrayMergeExtraDefaults;
|
|
@@ -1352,7 +1474,8 @@ function getArrayDefaults(validator, rawSchema, {
|
|
|
1352
1474
|
_recurseList,
|
|
1353
1475
|
experimental_defaultFormStateBehavior,
|
|
1354
1476
|
experimental_customMergeAllOf,
|
|
1355
|
-
required
|
|
1477
|
+
required,
|
|
1478
|
+
shouldMergeDefaultsIntoFormData
|
|
1356
1479
|
})
|
|
1357
1480
|
);
|
|
1358
1481
|
return defaultEntries.concat(fillerEntries);
|
|
@@ -1377,21 +1500,24 @@ function getDefaultFormState(validator, theSchema, formData, rootSchema, include
|
|
|
1377
1500
|
includeUndefinedValues,
|
|
1378
1501
|
experimental_defaultFormStateBehavior,
|
|
1379
1502
|
experimental_customMergeAllOf,
|
|
1380
|
-
rawFormData: formData
|
|
1503
|
+
rawFormData: formData,
|
|
1504
|
+
shouldMergeDefaultsIntoFormData: true
|
|
1381
1505
|
});
|
|
1382
|
-
if (formData
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1506
|
+
if (isObject(formData) || Array.isArray(formData)) {
|
|
1507
|
+
const { mergeDefaultsIntoFormData } = experimental_defaultFormStateBehavior || {};
|
|
1508
|
+
const defaultSupercedesUndefined = mergeDefaultsIntoFormData === "useDefaultIfFormDataUndefined";
|
|
1509
|
+
const result = mergeDefaultsWithFormData(
|
|
1510
|
+
defaults,
|
|
1511
|
+
formData,
|
|
1512
|
+
true,
|
|
1513
|
+
// set to true to add any additional default array entries.
|
|
1514
|
+
defaultSupercedesUndefined,
|
|
1515
|
+
true
|
|
1516
|
+
// set to true to override formData with defaults if they exist.
|
|
1517
|
+
);
|
|
1518
|
+
return result;
|
|
1393
1519
|
}
|
|
1394
|
-
return
|
|
1520
|
+
return defaults;
|
|
1395
1521
|
}
|
|
1396
1522
|
|
|
1397
1523
|
// src/isCustomWidget.ts
|
|
@@ -1474,9 +1600,9 @@ function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, d
|
|
|
1474
1600
|
}
|
|
1475
1601
|
});
|
|
1476
1602
|
}
|
|
1477
|
-
const
|
|
1603
|
+
const keys2 = Object.keys(get8(newSchema, PROPERTIES_KEY, {}));
|
|
1478
1604
|
const nestedData = {};
|
|
1479
|
-
|
|
1605
|
+
keys2.forEach((key) => {
|
|
1480
1606
|
const formValue = get8(data, key);
|
|
1481
1607
|
let oldKeyedSchema = get8(oldSchema, [PROPERTIES_KEY, key], {});
|
|
1482
1608
|
let newKeyedSchema = get8(newSchema, [PROPERTIES_KEY, key], {});
|
|
@@ -1593,11 +1719,10 @@ function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, d
|
|
|
1593
1719
|
|
|
1594
1720
|
// src/schema/toIdSchema.ts
|
|
1595
1721
|
import get9 from "lodash/get";
|
|
1596
|
-
import isEqual2 from "lodash/isEqual";
|
|
1597
1722
|
function toIdSchemaInternal(validator, schema, idPrefix, idSeparator, id, rootSchema, formData, _recurseList = [], experimental_customMergeAllOf) {
|
|
1598
1723
|
if (REF_KEY in schema || DEPENDENCIES_KEY in schema || ALL_OF_KEY in schema) {
|
|
1599
1724
|
const _schema = retrieveSchema(validator, schema, rootSchema, formData, experimental_customMergeAllOf);
|
|
1600
|
-
const sameSchemaIndex = _recurseList.findIndex((item) =>
|
|
1725
|
+
const sameSchemaIndex = _recurseList.findIndex((item) => deepEquals(item, _schema));
|
|
1601
1726
|
if (sameSchemaIndex === -1) {
|
|
1602
1727
|
return toIdSchemaInternal(
|
|
1603
1728
|
validator,
|
|
@@ -1664,12 +1789,11 @@ function toIdSchema(validator, schema, id, rootSchema, formData, idPrefix = "roo
|
|
|
1664
1789
|
|
|
1665
1790
|
// src/schema/toPathSchema.ts
|
|
1666
1791
|
import get10 from "lodash/get";
|
|
1667
|
-
import isEqual3 from "lodash/isEqual";
|
|
1668
1792
|
import set2 from "lodash/set";
|
|
1669
1793
|
function toPathSchemaInternal(validator, schema, name, rootSchema, formData, _recurseList = [], experimental_customMergeAllOf) {
|
|
1670
1794
|
if (REF_KEY in schema || DEPENDENCIES_KEY in schema || ALL_OF_KEY in schema) {
|
|
1671
1795
|
const _schema = retrieveSchema(validator, schema, rootSchema, formData, experimental_customMergeAllOf);
|
|
1672
|
-
const sameSchemaIndex = _recurseList.findIndex((item) =>
|
|
1796
|
+
const sameSchemaIndex = _recurseList.findIndex((item) => deepEquals(item, _schema));
|
|
1673
1797
|
if (sameSchemaIndex === -1) {
|
|
1674
1798
|
return toPathSchemaInternal(
|
|
1675
1799
|
validator,
|
|
@@ -2107,9 +2231,6 @@ function englishStringTranslator(stringToTranslate, params) {
|
|
|
2107
2231
|
return replaceStringParameters(stringToTranslate, params);
|
|
2108
2232
|
}
|
|
2109
2233
|
|
|
2110
|
-
// src/enumOptionsDeselectValue.ts
|
|
2111
|
-
import isEqual4 from "lodash/isEqual";
|
|
2112
|
-
|
|
2113
2234
|
// src/enumOptionsValueForIndex.ts
|
|
2114
2235
|
function enumOptionsValueForIndex(valueIndex, allEnumOptions = [], emptyValue) {
|
|
2115
2236
|
if (Array.isArray(valueIndex)) {
|
|
@@ -2124,18 +2245,17 @@ function enumOptionsValueForIndex(valueIndex, allEnumOptions = [], emptyValue) {
|
|
|
2124
2245
|
function enumOptionsDeselectValue(valueIndex, selected, allEnumOptions = []) {
|
|
2125
2246
|
const value = enumOptionsValueForIndex(valueIndex, allEnumOptions);
|
|
2126
2247
|
if (Array.isArray(selected)) {
|
|
2127
|
-
return selected.filter((v) => !
|
|
2248
|
+
return selected.filter((v) => !deepEquals(v, value));
|
|
2128
2249
|
}
|
|
2129
|
-
return
|
|
2250
|
+
return deepEquals(value, selected) ? void 0 : selected;
|
|
2130
2251
|
}
|
|
2131
2252
|
|
|
2132
2253
|
// src/enumOptionsIsSelected.ts
|
|
2133
|
-
import isEqual5 from "lodash/isEqual";
|
|
2134
2254
|
function enumOptionsIsSelected(value, selected) {
|
|
2135
2255
|
if (Array.isArray(selected)) {
|
|
2136
|
-
return selected.some((sel) =>
|
|
2256
|
+
return selected.some((sel) => deepEquals(sel, value));
|
|
2137
2257
|
}
|
|
2138
|
-
return
|
|
2258
|
+
return deepEquals(selected, value);
|
|
2139
2259
|
}
|
|
2140
2260
|
|
|
2141
2261
|
// src/enumOptionsIndexForValue.ts
|
|
@@ -2148,10 +2268,10 @@ function enumOptionsIndexForValue(value, allEnumOptions = [], multiple = false)
|
|
|
2148
2268
|
}
|
|
2149
2269
|
|
|
2150
2270
|
// src/enumOptionsSelectValue.ts
|
|
2151
|
-
import
|
|
2271
|
+
import isNil2 from "lodash/isNil";
|
|
2152
2272
|
function enumOptionsSelectValue(valueIndex, selected, allEnumOptions = []) {
|
|
2153
2273
|
const value = enumOptionsValueForIndex(valueIndex, allEnumOptions);
|
|
2154
|
-
if (!
|
|
2274
|
+
if (!isNil2(value)) {
|
|
2155
2275
|
const index = allEnumOptions.findIndex((opt) => value === opt.value);
|
|
2156
2276
|
const all = allEnumOptions.map(({ value: val }) => val);
|
|
2157
2277
|
const updated = selected.slice(0, index).concat(value, selected.slice(index));
|
|
@@ -2481,9 +2601,9 @@ function hasWidget(schema, widget, registeredWidgets = {}) {
|
|
|
2481
2601
|
}
|
|
2482
2602
|
|
|
2483
2603
|
// src/idGenerators.ts
|
|
2484
|
-
import
|
|
2604
|
+
import isString4 from "lodash/isString";
|
|
2485
2605
|
function idGenerator(id, suffix) {
|
|
2486
|
-
const theId =
|
|
2606
|
+
const theId = isString4(id) ? id : id[ID_KEY];
|
|
2487
2607
|
return `${theId}__${suffix}`;
|
|
2488
2608
|
}
|
|
2489
2609
|
function descriptionId(id) {
|
|
@@ -2519,61 +2639,6 @@ function localToUTC(dateString) {
|
|
|
2519
2639
|
return dateString ? new Date(dateString).toJSON() : void 0;
|
|
2520
2640
|
}
|
|
2521
2641
|
|
|
2522
|
-
// src/toConstant.ts
|
|
2523
|
-
function toConstant(schema) {
|
|
2524
|
-
if (ENUM_KEY in schema && Array.isArray(schema.enum) && schema.enum.length === 1) {
|
|
2525
|
-
return schema.enum[0];
|
|
2526
|
-
}
|
|
2527
|
-
if (CONST_KEY in schema) {
|
|
2528
|
-
return schema.const;
|
|
2529
|
-
}
|
|
2530
|
-
throw new Error("schema cannot be inferred as a constant");
|
|
2531
|
-
}
|
|
2532
|
-
|
|
2533
|
-
// src/optionsList.ts
|
|
2534
|
-
function optionsList(schema, uiSchema) {
|
|
2535
|
-
const schemaWithEnumNames = schema;
|
|
2536
|
-
if (schema.enum) {
|
|
2537
|
-
let enumNames;
|
|
2538
|
-
if (uiSchema) {
|
|
2539
|
-
const { enumNames: uiEnumNames } = getUiOptions(uiSchema);
|
|
2540
|
-
enumNames = uiEnumNames;
|
|
2541
|
-
}
|
|
2542
|
-
if (!enumNames && schemaWithEnumNames.enumNames) {
|
|
2543
|
-
if (true) {
|
|
2544
|
-
console.warn(
|
|
2545
|
-
'The "enumNames" property in the schema is deprecated and will be removed in a future major release. Use the "ui:enumNames" property in the uiSchema instead.'
|
|
2546
|
-
);
|
|
2547
|
-
}
|
|
2548
|
-
enumNames = schemaWithEnumNames.enumNames;
|
|
2549
|
-
}
|
|
2550
|
-
return schema.enum.map((value, i) => {
|
|
2551
|
-
const label = enumNames?.[i] || String(value);
|
|
2552
|
-
return { label, value };
|
|
2553
|
-
});
|
|
2554
|
-
}
|
|
2555
|
-
let altSchemas = void 0;
|
|
2556
|
-
let altUiSchemas = void 0;
|
|
2557
|
-
if (schema.anyOf) {
|
|
2558
|
-
altSchemas = schema.anyOf;
|
|
2559
|
-
altUiSchemas = uiSchema?.anyOf;
|
|
2560
|
-
} else if (schema.oneOf) {
|
|
2561
|
-
altSchemas = schema.oneOf;
|
|
2562
|
-
altUiSchemas = uiSchema?.oneOf;
|
|
2563
|
-
}
|
|
2564
|
-
return altSchemas && altSchemas.map((aSchemaDef, index) => {
|
|
2565
|
-
const { title } = getUiOptions(altUiSchemas?.[index]);
|
|
2566
|
-
const aSchema = aSchemaDef;
|
|
2567
|
-
const value = toConstant(aSchema);
|
|
2568
|
-
const label = title || aSchema.title || String(value);
|
|
2569
|
-
return {
|
|
2570
|
-
schema: aSchema,
|
|
2571
|
-
label,
|
|
2572
|
-
value
|
|
2573
|
-
};
|
|
2574
|
-
});
|
|
2575
|
-
}
|
|
2576
|
-
|
|
2577
2642
|
// src/orderProperties.ts
|
|
2578
2643
|
function orderProperties(properties, order) {
|
|
2579
2644
|
if (!Array.isArray(order)) {
|
|
@@ -2795,6 +2860,29 @@ function withIdRefPrefix(schemaNode) {
|
|
|
2795
2860
|
return schemaNode;
|
|
2796
2861
|
}
|
|
2797
2862
|
|
|
2863
|
+
// src/getChangedFields.ts
|
|
2864
|
+
import keys from "lodash/keys";
|
|
2865
|
+
import pickBy from "lodash/pickBy";
|
|
2866
|
+
import isPlainObject4 from "lodash/isPlainObject";
|
|
2867
|
+
import get13 from "lodash/get";
|
|
2868
|
+
import difference from "lodash/difference";
|
|
2869
|
+
function getChangedFields(a, b) {
|
|
2870
|
+
const aIsPlainObject = isPlainObject4(a);
|
|
2871
|
+
const bIsPlainObject = isPlainObject4(b);
|
|
2872
|
+
if (a === b || !aIsPlainObject && !bIsPlainObject) {
|
|
2873
|
+
return [];
|
|
2874
|
+
}
|
|
2875
|
+
if (aIsPlainObject && !bIsPlainObject) {
|
|
2876
|
+
return keys(a);
|
|
2877
|
+
} else if (!aIsPlainObject && bIsPlainObject) {
|
|
2878
|
+
return keys(b);
|
|
2879
|
+
} else {
|
|
2880
|
+
const unequalFields = keys(pickBy(a, (value, key) => !deepEquals(value, get13(b, key))));
|
|
2881
|
+
const diffFields = difference(keys(b), keys(a));
|
|
2882
|
+
return [...unequalFields, ...diffFields];
|
|
2883
|
+
}
|
|
2884
|
+
}
|
|
2885
|
+
|
|
2798
2886
|
// src/enums.ts
|
|
2799
2887
|
var TranslatableString = /* @__PURE__ */ ((TranslatableString2) => {
|
|
2800
2888
|
TranslatableString2["ArrayItemTitle"] = "Item";
|
|
@@ -2831,11 +2919,9 @@ var TranslatableString = /* @__PURE__ */ ((TranslatableString2) => {
|
|
|
2831
2919
|
|
|
2832
2920
|
// src/parser/schemaParser.ts
|
|
2833
2921
|
import forEach from "lodash/forEach";
|
|
2834
|
-
import isEqual7 from "lodash/isEqual";
|
|
2835
2922
|
|
|
2836
2923
|
// src/parser/ParserValidator.ts
|
|
2837
|
-
import
|
|
2838
|
-
import isEqual6 from "lodash/isEqual";
|
|
2924
|
+
import get14 from "lodash/get";
|
|
2839
2925
|
var ParserValidator = class {
|
|
2840
2926
|
/** Construct the ParserValidator for the given `rootSchema`. This `rootSchema` will be stashed in the `schemaMap`
|
|
2841
2927
|
* first.
|
|
@@ -2861,12 +2947,12 @@ var ParserValidator = class {
|
|
|
2861
2947
|
* @param hash - The hash value at which to map the schema
|
|
2862
2948
|
*/
|
|
2863
2949
|
addSchema(schema, hash) {
|
|
2864
|
-
const key =
|
|
2950
|
+
const key = get14(schema, ID_KEY, hash);
|
|
2865
2951
|
const identifiedSchema = { ...schema, [ID_KEY]: key };
|
|
2866
2952
|
const existing = this.schemaMap[key];
|
|
2867
2953
|
if (!existing) {
|
|
2868
2954
|
this.schemaMap[key] = identifiedSchema;
|
|
2869
|
-
} else if (!
|
|
2955
|
+
} else if (!deepEquals(existing, identifiedSchema)) {
|
|
2870
2956
|
console.error("existing schema:", JSON.stringify(existing, null, 2));
|
|
2871
2957
|
console.error("new schema:", JSON.stringify(identifiedSchema, null, 2));
|
|
2872
2958
|
throw new Error(
|
|
@@ -2888,7 +2974,7 @@ var ParserValidator = class {
|
|
|
2888
2974
|
* @throws - Error when the given `rootSchema` differs from the root schema provided during construction
|
|
2889
2975
|
*/
|
|
2890
2976
|
isValid(schema, _formData, rootSchema) {
|
|
2891
|
-
if (!
|
|
2977
|
+
if (!deepEquals(rootSchema, this.rootSchema)) {
|
|
2892
2978
|
throw new Error("Unexpectedly calling isValid() with a rootSchema that differs from the construction rootSchema");
|
|
2893
2979
|
}
|
|
2894
2980
|
this.addSchema(schema, hashForSchema(schema));
|
|
@@ -2928,7 +3014,7 @@ var ParserValidator = class {
|
|
|
2928
3014
|
function parseSchema(validator, recurseList, rootSchema, schema) {
|
|
2929
3015
|
const schemas = retrieveSchemaInternal(validator, schema, rootSchema, void 0, true);
|
|
2930
3016
|
schemas.forEach((schema2) => {
|
|
2931
|
-
const sameSchemaIndex = recurseList.findIndex((item) =>
|
|
3017
|
+
const sameSchemaIndex = recurseList.findIndex((item) => deepEquals(item, schema2));
|
|
2932
3018
|
if (sameSchemaIndex === -1) {
|
|
2933
3019
|
recurseList.push(schema2);
|
|
2934
3020
|
const allOptions = resolveAnyOrOneOfSchemas(validator, schema2, rootSchema, true);
|
|
@@ -3000,6 +3086,7 @@ export {
|
|
|
3000
3086
|
errorId,
|
|
3001
3087
|
examplesId,
|
|
3002
3088
|
findSchemaDefinition,
|
|
3089
|
+
getChangedFields,
|
|
3003
3090
|
getClosestMatchingOption,
|
|
3004
3091
|
getDateElementProps,
|
|
3005
3092
|
getDefaultFormState,
|