@rjsf/utils 5.22.3 → 5.23.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 +175 -59
- package/dist/index.js.map +2 -2
- package/dist/utils.esm.js +175 -59
- package/dist/utils.esm.js.map +2 -2
- package/dist/utils.umd.js +187 -63
- package/lib/ErrorSchemaBuilder.js +3 -3
- package/lib/ErrorSchemaBuilder.js.map +1 -1
- package/lib/createSchemaUtils.js +7 -7
- package/lib/createSchemaUtils.js.map +1 -1
- package/lib/schema/getClosestMatchingOption.d.ts +5 -3
- package/lib/schema/getClosestMatchingOption.js +11 -7
- package/lib/schema/getClosestMatchingOption.js.map +1 -1
- package/lib/schema/getDefaultFormState.d.ts +1 -1
- package/lib/schema/getDefaultFormState.js +40 -16
- package/lib/schema/getDefaultFormState.js.map +1 -1
- package/lib/schema/getDisplayLabel.d.ts +3 -2
- package/lib/schema/getDisplayLabel.js +4 -3
- package/lib/schema/getDisplayLabel.js.map +1 -1
- package/lib/schema/isFilesArray.d.ts +3 -2
- package/lib/schema/isFilesArray.js +3 -2
- package/lib/schema/isFilesArray.js.map +1 -1
- package/lib/schema/isMultiSelect.d.ts +3 -2
- package/lib/schema/isMultiSelect.js +3 -2
- package/lib/schema/isMultiSelect.js.map +1 -1
- package/lib/schema/isSelect.d.ts +3 -2
- package/lib/schema/isSelect.js +3 -2
- package/lib/schema/isSelect.js.map +1 -1
- package/lib/schema/retrieveSchema.d.ts +2 -1
- package/lib/schema/retrieveSchema.js +5 -4
- package/lib/schema/retrieveSchema.js.map +1 -1
- package/lib/schema/sanitizeDataForNewSchema.d.ts +3 -2
- package/lib/schema/sanitizeDataForNewSchema.js +8 -7
- package/lib/schema/sanitizeDataForNewSchema.js.map +1 -1
- package/lib/schema/toIdSchema.js +1 -1
- package/lib/schema/toIdSchema.js.map +1 -1
- package/lib/schema/toPathSchema.d.ts +3 -2
- package/lib/schema/toPathSchema.js +13 -11
- package/lib/schema/toPathSchema.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/types.d.ts +12 -0
- package/package.json +2 -2
- package/src/ErrorSchemaBuilder.ts +3 -3
- package/src/createSchemaUtils.ts +29 -7
- package/src/schema/getClosestMatchingOption.ts +31 -8
- package/src/schema/getDefaultFormState.ts +48 -15
- package/src/schema/getDisplayLabel.ts +6 -3
- package/src/schema/isFilesArray.ts +18 -3
- package/src/schema/isMultiSelect.ts +9 -3
- package/src/schema/isSelect.ts +5 -3
- package/src/schema/retrieveSchema.ts +19 -4
- package/src/schema/sanitizeDataForNewSchema.ts +49 -8
- package/src/schema/toIdSchema.ts +1 -1
- package/src/schema/toPathSchema.ts +45 -12
- package/src/types.ts +12 -0
package/dist/index.js
CHANGED
|
@@ -693,7 +693,7 @@ function resolveAllReferences(schema, rootSchema, recurseList) {
|
|
|
693
693
|
}
|
|
694
694
|
return (0, import_isEqual.default)(schema, resolvedSchema) ? schema : resolvedSchema;
|
|
695
695
|
}
|
|
696
|
-
function stubExistingAdditionalProperties(validator, theSchema, rootSchema, aFormData) {
|
|
696
|
+
function stubExistingAdditionalProperties(validator, theSchema, rootSchema, aFormData, experimental_customMergeAllOf) {
|
|
697
697
|
const schema = {
|
|
698
698
|
...theSchema,
|
|
699
699
|
properties: { ...theSchema.properties }
|
|
@@ -710,7 +710,8 @@ function stubExistingAdditionalProperties(validator, theSchema, rootSchema, aFor
|
|
|
710
710
|
validator,
|
|
711
711
|
{ $ref: (0, import_get4.default)(schema.additionalProperties, [REF_KEY]) },
|
|
712
712
|
rootSchema,
|
|
713
|
-
formData
|
|
713
|
+
formData,
|
|
714
|
+
experimental_customMergeAllOf
|
|
714
715
|
);
|
|
715
716
|
} else if ("type" in schema.additionalProperties) {
|
|
716
717
|
additionalProperties = { ...schema.additionalProperties };
|
|
@@ -740,7 +741,8 @@ function retrieveSchemaInternal(validator, schema, rootSchema, rawFormData, expa
|
|
|
740
741
|
rootSchema,
|
|
741
742
|
expandAllBranches,
|
|
742
743
|
recurseList,
|
|
743
|
-
rawFormData
|
|
744
|
+
rawFormData,
|
|
745
|
+
experimental_customMergeAllOf
|
|
744
746
|
);
|
|
745
747
|
return resolvedSchemas.flatMap((s) => {
|
|
746
748
|
let resolvedSchema = s;
|
|
@@ -787,7 +789,13 @@ function retrieveSchemaInternal(validator, schema, rootSchema, rawFormData, expa
|
|
|
787
789
|
}
|
|
788
790
|
const hasAdditionalProperties = ADDITIONAL_PROPERTIES_KEY in resolvedSchema && resolvedSchema.additionalProperties !== false;
|
|
789
791
|
if (hasAdditionalProperties) {
|
|
790
|
-
return stubExistingAdditionalProperties(
|
|
792
|
+
return stubExistingAdditionalProperties(
|
|
793
|
+
validator,
|
|
794
|
+
resolvedSchema,
|
|
795
|
+
rootSchema,
|
|
796
|
+
rawFormData,
|
|
797
|
+
experimental_customMergeAllOf
|
|
798
|
+
);
|
|
791
799
|
}
|
|
792
800
|
return resolvedSchema;
|
|
793
801
|
});
|
|
@@ -972,7 +980,7 @@ var JUNK_OPTION = {
|
|
|
972
980
|
}
|
|
973
981
|
}
|
|
974
982
|
};
|
|
975
|
-
function calculateIndexScore(validator, rootSchema, schema, formData) {
|
|
983
|
+
function calculateIndexScore(validator, rootSchema, schema, formData, experimental_customMergeAllOf) {
|
|
976
984
|
let totalScore = 0;
|
|
977
985
|
if (schema) {
|
|
978
986
|
if ((0, import_isObject5.default)(schema.properties)) {
|
|
@@ -984,8 +992,20 @@ function calculateIndexScore(validator, rootSchema, schema, formData) {
|
|
|
984
992
|
return score;
|
|
985
993
|
}
|
|
986
994
|
if ((0, import_has2.default)(value, REF_KEY)) {
|
|
987
|
-
const newSchema = retrieveSchema(
|
|
988
|
-
|
|
995
|
+
const newSchema = retrieveSchema(
|
|
996
|
+
validator,
|
|
997
|
+
value,
|
|
998
|
+
rootSchema,
|
|
999
|
+
formValue,
|
|
1000
|
+
experimental_customMergeAllOf
|
|
1001
|
+
);
|
|
1002
|
+
return score + calculateIndexScore(
|
|
1003
|
+
validator,
|
|
1004
|
+
rootSchema,
|
|
1005
|
+
newSchema,
|
|
1006
|
+
formValue || {},
|
|
1007
|
+
experimental_customMergeAllOf
|
|
1008
|
+
);
|
|
989
1009
|
}
|
|
990
1010
|
if (((0, import_has2.default)(value, ONE_OF_KEY) || (0, import_has2.default)(value, ANY_OF_KEY)) && formValue) {
|
|
991
1011
|
const key2 = (0, import_has2.default)(value, ONE_OF_KEY) ? ONE_OF_KEY : ANY_OF_KEY;
|
|
@@ -996,14 +1016,15 @@ function calculateIndexScore(validator, rootSchema, schema, formData) {
|
|
|
996
1016
|
formValue,
|
|
997
1017
|
(0, import_get5.default)(value, key2),
|
|
998
1018
|
-1,
|
|
999
|
-
discriminator
|
|
1019
|
+
discriminator,
|
|
1020
|
+
experimental_customMergeAllOf
|
|
1000
1021
|
);
|
|
1001
1022
|
}
|
|
1002
1023
|
if (value.type === "object") {
|
|
1003
1024
|
if ((0, import_isObject5.default)(formValue)) {
|
|
1004
1025
|
score += 1;
|
|
1005
1026
|
}
|
|
1006
|
-
return score + calculateIndexScore(validator, rootSchema, value, formValue);
|
|
1027
|
+
return score + calculateIndexScore(validator, rootSchema, value, formValue, experimental_customMergeAllOf);
|
|
1007
1028
|
}
|
|
1008
1029
|
if (value.type === guessType(formValue)) {
|
|
1009
1030
|
let newScore = score + 1;
|
|
@@ -1024,7 +1045,7 @@ function calculateIndexScore(validator, rootSchema, schema, formData) {
|
|
|
1024
1045
|
}
|
|
1025
1046
|
return totalScore;
|
|
1026
1047
|
}
|
|
1027
|
-
function getClosestMatchingOption(validator, rootSchema, formData, options, selectedOption = -1, discriminatorField) {
|
|
1048
|
+
function getClosestMatchingOption(validator, rootSchema, formData, options, selectedOption = -1, discriminatorField, experimental_customMergeAllOf) {
|
|
1028
1049
|
const resolvedOptions = options.map((option) => {
|
|
1029
1050
|
return resolveAllReferences(option, rootSchema, []);
|
|
1030
1051
|
});
|
|
@@ -1051,7 +1072,7 @@ function getClosestMatchingOption(validator, rootSchema, formData, options, sele
|
|
|
1051
1072
|
(scoreData, index) => {
|
|
1052
1073
|
const { bestScore } = scoreData;
|
|
1053
1074
|
const option = resolvedOptions[index];
|
|
1054
|
-
const score = calculateIndexScore(validator, rootSchema, option, formData);
|
|
1075
|
+
const score = calculateIndexScore(validator, rootSchema, option, formData, experimental_customMergeAllOf);
|
|
1055
1076
|
scoreCount.add(score);
|
|
1056
1077
|
if (score > bestScore) {
|
|
1057
1078
|
return { bestIndex: index, bestScore: score };
|
|
@@ -1140,8 +1161,8 @@ function isConstant(schema) {
|
|
|
1140
1161
|
}
|
|
1141
1162
|
|
|
1142
1163
|
// src/schema/isSelect.ts
|
|
1143
|
-
function isSelect(validator, theSchema, rootSchema = {}) {
|
|
1144
|
-
const schema = retrieveSchema(validator, theSchema, rootSchema, void 0);
|
|
1164
|
+
function isSelect(validator, theSchema, rootSchema = {}, experimental_customMergeAllOf) {
|
|
1165
|
+
const schema = retrieveSchema(validator, theSchema, rootSchema, void 0, experimental_customMergeAllOf);
|
|
1145
1166
|
const altSchemas = schema.oneOf || schema.anyOf;
|
|
1146
1167
|
if (Array.isArray(schema.enum)) {
|
|
1147
1168
|
return true;
|
|
@@ -1153,14 +1174,15 @@ function isSelect(validator, theSchema, rootSchema = {}) {
|
|
|
1153
1174
|
}
|
|
1154
1175
|
|
|
1155
1176
|
// src/schema/isMultiSelect.ts
|
|
1156
|
-
function isMultiSelect(validator, schema, rootSchema) {
|
|
1177
|
+
function isMultiSelect(validator, schema, rootSchema, experimental_customMergeAllOf) {
|
|
1157
1178
|
if (!schema.uniqueItems || !schema.items || typeof schema.items === "boolean") {
|
|
1158
1179
|
return false;
|
|
1159
1180
|
}
|
|
1160
|
-
return isSelect(validator, schema.items, rootSchema);
|
|
1181
|
+
return isSelect(validator, schema.items, rootSchema, experimental_customMergeAllOf);
|
|
1161
1182
|
}
|
|
1162
1183
|
|
|
1163
1184
|
// src/schema/getDefaultFormState.ts
|
|
1185
|
+
var PRIMITIVE_TYPES = ["string", "number", "integer", "boolean", "null"];
|
|
1164
1186
|
function getInnerSchemaForArrayItem(schema, additionalItems = 0 /* Ignore */, idx = -1) {
|
|
1165
1187
|
if (idx >= 0) {
|
|
1166
1188
|
if (Array.isArray(schema.items) && idx < schema.items.length) {
|
|
@@ -1216,8 +1238,9 @@ function computeDefaults(validator, rawSchema, computeDefaultsProps = {}) {
|
|
|
1216
1238
|
const schema = isObject(rawSchema) ? rawSchema : {};
|
|
1217
1239
|
let defaults = parentDefaults;
|
|
1218
1240
|
let schemaToCompute = null;
|
|
1241
|
+
let experimental_dfsb_to_compute = experimental_defaultFormStateBehavior;
|
|
1219
1242
|
let updatedRecurseList = _recurseList;
|
|
1220
|
-
if (
|
|
1243
|
+
if (schema[CONST_KEY] && experimental_defaultFormStateBehavior?.constAsDefaults !== "never") {
|
|
1221
1244
|
defaults = schema.const;
|
|
1222
1245
|
} else if (isObject(defaults) && isObject(schema.default)) {
|
|
1223
1246
|
defaults = mergeObjects(defaults, schema.default);
|
|
@@ -1251,6 +1274,7 @@ function computeDefaults(validator, rawSchema, computeDefaultsProps = {}) {
|
|
|
1251
1274
|
includeUndefinedValues,
|
|
1252
1275
|
_recurseList,
|
|
1253
1276
|
experimental_defaultFormStateBehavior,
|
|
1277
|
+
experimental_customMergeAllOf,
|
|
1254
1278
|
parentDefaults: Array.isArray(parentDefaults) ? parentDefaults[idx] : void 0,
|
|
1255
1279
|
rawFormData: formData,
|
|
1256
1280
|
required
|
|
@@ -1262,13 +1286,18 @@ function computeDefaults(validator, rawSchema, computeDefaultsProps = {}) {
|
|
|
1262
1286
|
return void 0;
|
|
1263
1287
|
}
|
|
1264
1288
|
const discriminator = getDiscriminatorFieldFromSchema(schema);
|
|
1289
|
+
const { type = "null" } = remaining;
|
|
1290
|
+
if (!Array.isArray(type) && PRIMITIVE_TYPES.includes(type) && experimental_dfsb_to_compute?.constAsDefaults === "skipOneOf") {
|
|
1291
|
+
experimental_dfsb_to_compute = { ...experimental_dfsb_to_compute, constAsDefaults: "never" };
|
|
1292
|
+
}
|
|
1265
1293
|
schemaToCompute = oneOf[getClosestMatchingOption(
|
|
1266
1294
|
validator,
|
|
1267
1295
|
rootSchema,
|
|
1268
1296
|
(0, import_isEmpty.default)(formData) ? void 0 : formData,
|
|
1269
1297
|
oneOf,
|
|
1270
1298
|
0,
|
|
1271
|
-
discriminator
|
|
1299
|
+
discriminator,
|
|
1300
|
+
experimental_customMergeAllOf
|
|
1272
1301
|
)];
|
|
1273
1302
|
schemaToCompute = mergeSchemas(remaining, schemaToCompute);
|
|
1274
1303
|
} else if (ANY_OF_KEY in schema) {
|
|
@@ -1283,7 +1312,8 @@ function computeDefaults(validator, rawSchema, computeDefaultsProps = {}) {
|
|
|
1283
1312
|
(0, import_isEmpty.default)(formData) ? void 0 : formData,
|
|
1284
1313
|
anyOf,
|
|
1285
1314
|
0,
|
|
1286
|
-
discriminator
|
|
1315
|
+
discriminator,
|
|
1316
|
+
experimental_customMergeAllOf
|
|
1287
1317
|
)];
|
|
1288
1318
|
schemaToCompute = mergeSchemas(remaining, schemaToCompute);
|
|
1289
1319
|
}
|
|
@@ -1292,7 +1322,8 @@ function computeDefaults(validator, rawSchema, computeDefaultsProps = {}) {
|
|
|
1292
1322
|
rootSchema,
|
|
1293
1323
|
includeUndefinedValues,
|
|
1294
1324
|
_recurseList: updatedRecurseList,
|
|
1295
|
-
experimental_defaultFormStateBehavior,
|
|
1325
|
+
experimental_defaultFormStateBehavior: experimental_dfsb_to_compute,
|
|
1326
|
+
experimental_customMergeAllOf,
|
|
1296
1327
|
parentDefaults: defaults,
|
|
1297
1328
|
rawFormData: formData,
|
|
1298
1329
|
required
|
|
@@ -1322,7 +1353,7 @@ function getObjectDefaults(validator, rawSchema, {
|
|
|
1322
1353
|
(acc, key) => {
|
|
1323
1354
|
const propertySchema = (0, import_get7.default)(retrievedSchema, [PROPERTIES_KEY, key]);
|
|
1324
1355
|
const hasParentConst = isObject(parentConst) && parentConst[key] !== void 0;
|
|
1325
|
-
const hasConst = isObject(propertySchema) && CONST_KEY in propertySchema || hasParentConst;
|
|
1356
|
+
const hasConst = (isObject(propertySchema) && CONST_KEY in propertySchema || hasParentConst) && experimental_defaultFormStateBehavior?.constAsDefaults !== "never";
|
|
1326
1357
|
const computedDefault = computeDefaults(validator, propertySchema, {
|
|
1327
1358
|
rootSchema,
|
|
1328
1359
|
_recurseList,
|
|
@@ -1363,6 +1394,7 @@ function getObjectDefaults(validator, rawSchema, {
|
|
|
1363
1394
|
rootSchema,
|
|
1364
1395
|
_recurseList,
|
|
1365
1396
|
experimental_defaultFormStateBehavior,
|
|
1397
|
+
experimental_customMergeAllOf,
|
|
1366
1398
|
includeUndefinedValues: includeUndefinedValues === true,
|
|
1367
1399
|
parentDefaults: (0, import_get7.default)(defaults, [key]),
|
|
1368
1400
|
rawFormData: (0, import_get7.default)(formData, [key]),
|
|
@@ -1386,13 +1418,17 @@ function getArrayDefaults(validator, rawSchema, {
|
|
|
1386
1418
|
rootSchema = {},
|
|
1387
1419
|
_recurseList = [],
|
|
1388
1420
|
experimental_defaultFormStateBehavior = void 0,
|
|
1421
|
+
experimental_customMergeAllOf = void 0,
|
|
1389
1422
|
required
|
|
1390
1423
|
} = {}, defaults) {
|
|
1391
1424
|
const schema = rawSchema;
|
|
1392
|
-
const
|
|
1393
|
-
const
|
|
1425
|
+
const arrayMinItemsStateBehavior = experimental_defaultFormStateBehavior?.arrayMinItems ?? {};
|
|
1426
|
+
const { populate: arrayMinItemsPopulate, mergeExtraDefaults: arrayMergeExtraDefaults } = arrayMinItemsStateBehavior;
|
|
1427
|
+
const neverPopulate = arrayMinItemsPopulate === "never";
|
|
1428
|
+
const ignoreMinItemsFlagSet = arrayMinItemsPopulate === "requiredOnly";
|
|
1429
|
+
const isPopulateAll = arrayMinItemsPopulate === "all" || !neverPopulate && !ignoreMinItemsFlagSet;
|
|
1430
|
+
const computeSkipPopulate = arrayMinItemsStateBehavior?.computeSkipPopulate ?? (() => false);
|
|
1394
1431
|
const isSkipEmptyDefaults = experimental_defaultFormStateBehavior?.emptyObjectFields === "skipEmptyDefaults";
|
|
1395
|
-
const computeSkipPopulate = experimental_defaultFormStateBehavior?.arrayMinItems?.computeSkipPopulate ?? (() => false);
|
|
1396
1432
|
const emptyDefault = isSkipEmptyDefaults ? void 0 : [];
|
|
1397
1433
|
if (Array.isArray(defaults)) {
|
|
1398
1434
|
defaults = defaults.map((item, idx) => {
|
|
@@ -1401,6 +1437,7 @@ function getArrayDefaults(validator, rawSchema, {
|
|
|
1401
1437
|
rootSchema,
|
|
1402
1438
|
_recurseList,
|
|
1403
1439
|
experimental_defaultFormStateBehavior,
|
|
1440
|
+
experimental_customMergeAllOf,
|
|
1404
1441
|
parentDefaults: item,
|
|
1405
1442
|
required
|
|
1406
1443
|
});
|
|
@@ -1411,19 +1448,22 @@ function getArrayDefaults(validator, rawSchema, {
|
|
|
1411
1448
|
if (neverPopulate) {
|
|
1412
1449
|
defaults = rawFormData;
|
|
1413
1450
|
} else {
|
|
1414
|
-
|
|
1451
|
+
const itemDefaults = rawFormData.map((item, idx) => {
|
|
1415
1452
|
return computeDefaults(validator, schemaItem, {
|
|
1416
1453
|
rootSchema,
|
|
1417
1454
|
_recurseList,
|
|
1418
1455
|
experimental_defaultFormStateBehavior,
|
|
1456
|
+
experimental_customMergeAllOf,
|
|
1419
1457
|
rawFormData: item,
|
|
1420
1458
|
parentDefaults: (0, import_get7.default)(defaults, [idx]),
|
|
1421
1459
|
required
|
|
1422
1460
|
});
|
|
1423
1461
|
});
|
|
1462
|
+
const mergeExtraDefaults = (ignoreMinItemsFlagSet && required || isPopulateAll) && arrayMergeExtraDefaults;
|
|
1463
|
+
defaults = mergeDefaultsWithFormData(defaults, itemDefaults, mergeExtraDefaults);
|
|
1424
1464
|
}
|
|
1425
1465
|
}
|
|
1426
|
-
const hasConst = isObject(schema) && CONST_KEY in schema;
|
|
1466
|
+
const hasConst = isObject(schema) && CONST_KEY in schema && experimental_defaultFormStateBehavior?.constAsDefaults !== "never";
|
|
1427
1467
|
if (hasConst === false) {
|
|
1428
1468
|
if (neverPopulate) {
|
|
1429
1469
|
return defaults ?? emptyDefault;
|
|
@@ -1433,7 +1473,7 @@ function getArrayDefaults(validator, rawSchema, {
|
|
|
1433
1473
|
}
|
|
1434
1474
|
}
|
|
1435
1475
|
const defaultsLength = Array.isArray(defaults) ? defaults.length : 0;
|
|
1436
|
-
if (!schema.minItems || isMultiSelect(validator, schema, rootSchema) || computeSkipPopulate(validator, schema, rootSchema) || schema.minItems <= defaultsLength) {
|
|
1476
|
+
if (!schema.minItems || isMultiSelect(validator, schema, rootSchema, experimental_customMergeAllOf) || computeSkipPopulate(validator, schema, rootSchema) || schema.minItems <= defaultsLength) {
|
|
1437
1477
|
return defaults ? defaults : emptyDefault;
|
|
1438
1478
|
}
|
|
1439
1479
|
const defaultEntries = defaults || [];
|
|
@@ -1445,6 +1485,7 @@ function getArrayDefaults(validator, rawSchema, {
|
|
|
1445
1485
|
rootSchema,
|
|
1446
1486
|
_recurseList,
|
|
1447
1487
|
experimental_defaultFormStateBehavior,
|
|
1488
|
+
experimental_customMergeAllOf,
|
|
1448
1489
|
required
|
|
1449
1490
|
})
|
|
1450
1491
|
);
|
|
@@ -1497,25 +1538,31 @@ function isCustomWidget(uiSchema = {}) {
|
|
|
1497
1538
|
}
|
|
1498
1539
|
|
|
1499
1540
|
// src/schema/isFilesArray.ts
|
|
1500
|
-
function isFilesArray(validator, schema, uiSchema = {}, rootSchema) {
|
|
1541
|
+
function isFilesArray(validator, schema, uiSchema = {}, rootSchema, experimental_customMergeAllOf) {
|
|
1501
1542
|
if (uiSchema[UI_WIDGET_KEY] === "files") {
|
|
1502
1543
|
return true;
|
|
1503
1544
|
}
|
|
1504
1545
|
if (schema.items) {
|
|
1505
|
-
const itemsSchema = retrieveSchema(
|
|
1546
|
+
const itemsSchema = retrieveSchema(
|
|
1547
|
+
validator,
|
|
1548
|
+
schema.items,
|
|
1549
|
+
rootSchema,
|
|
1550
|
+
void 0,
|
|
1551
|
+
experimental_customMergeAllOf
|
|
1552
|
+
);
|
|
1506
1553
|
return itemsSchema.type === "string" && itemsSchema.format === "data-url";
|
|
1507
1554
|
}
|
|
1508
1555
|
return false;
|
|
1509
1556
|
}
|
|
1510
1557
|
|
|
1511
1558
|
// src/schema/getDisplayLabel.ts
|
|
1512
|
-
function getDisplayLabel(validator, schema, uiSchema = {}, rootSchema, globalOptions) {
|
|
1559
|
+
function getDisplayLabel(validator, schema, uiSchema = {}, rootSchema, globalOptions, experimental_customMergeAllOf) {
|
|
1513
1560
|
const uiOptions = getUiOptions(uiSchema, globalOptions);
|
|
1514
1561
|
const { label = true } = uiOptions;
|
|
1515
1562
|
let displayLabel = !!label;
|
|
1516
1563
|
const schemaType = getSchemaType(schema);
|
|
1517
1564
|
if (schemaType === "array") {
|
|
1518
|
-
displayLabel = isMultiSelect(validator, schema, rootSchema) || isFilesArray(validator, schema, uiSchema, rootSchema) || isCustomWidget(uiSchema);
|
|
1565
|
+
displayLabel = isMultiSelect(validator, schema, rootSchema, experimental_customMergeAllOf) || isFilesArray(validator, schema, uiSchema, rootSchema, experimental_customMergeAllOf) || isCustomWidget(uiSchema);
|
|
1519
1566
|
}
|
|
1520
1567
|
if (schemaType === "object") {
|
|
1521
1568
|
displayLabel = false;
|
|
@@ -1549,7 +1596,7 @@ function mergeValidationData(validator, validationData, additionalErrorSchema) {
|
|
|
1549
1596
|
var import_get8 = __toESM(require("lodash/get"));
|
|
1550
1597
|
var import_has3 = __toESM(require("lodash/has"));
|
|
1551
1598
|
var NO_VALUE = Symbol("no Value");
|
|
1552
|
-
function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, data = {}) {
|
|
1599
|
+
function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, data = {}, experimental_customMergeAllOf) {
|
|
1553
1600
|
let newFormData;
|
|
1554
1601
|
if ((0, import_has3.default)(newSchema, PROPERTIES_KEY)) {
|
|
1555
1602
|
const removeOldSchemaData = {};
|
|
@@ -1568,10 +1615,22 @@ function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, d
|
|
|
1568
1615
|
let oldKeyedSchema = (0, import_get8.default)(oldSchema, [PROPERTIES_KEY, key], {});
|
|
1569
1616
|
let newKeyedSchema = (0, import_get8.default)(newSchema, [PROPERTIES_KEY, key], {});
|
|
1570
1617
|
if ((0, import_has3.default)(oldKeyedSchema, REF_KEY)) {
|
|
1571
|
-
oldKeyedSchema = retrieveSchema(
|
|
1618
|
+
oldKeyedSchema = retrieveSchema(
|
|
1619
|
+
validator,
|
|
1620
|
+
oldKeyedSchema,
|
|
1621
|
+
rootSchema,
|
|
1622
|
+
formValue,
|
|
1623
|
+
experimental_customMergeAllOf
|
|
1624
|
+
);
|
|
1572
1625
|
}
|
|
1573
1626
|
if ((0, import_has3.default)(newKeyedSchema, REF_KEY)) {
|
|
1574
|
-
newKeyedSchema = retrieveSchema(
|
|
1627
|
+
newKeyedSchema = retrieveSchema(
|
|
1628
|
+
validator,
|
|
1629
|
+
newKeyedSchema,
|
|
1630
|
+
rootSchema,
|
|
1631
|
+
formValue,
|
|
1632
|
+
experimental_customMergeAllOf
|
|
1633
|
+
);
|
|
1575
1634
|
}
|
|
1576
1635
|
const oldSchemaTypeForKey = (0, import_get8.default)(oldKeyedSchema, "type");
|
|
1577
1636
|
const newSchemaTypeForKey = (0, import_get8.default)(newKeyedSchema, "type");
|
|
@@ -1585,7 +1644,8 @@ function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, d
|
|
|
1585
1644
|
rootSchema,
|
|
1586
1645
|
newKeyedSchema,
|
|
1587
1646
|
oldKeyedSchema,
|
|
1588
|
-
formValue
|
|
1647
|
+
formValue,
|
|
1648
|
+
experimental_customMergeAllOf
|
|
1589
1649
|
);
|
|
1590
1650
|
if (itemData !== void 0 || newSchemaTypeForKey === "array") {
|
|
1591
1651
|
nestedData[key] = itemData;
|
|
@@ -1618,10 +1678,22 @@ function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, d
|
|
|
1618
1678
|
let newSchemaItems = (0, import_get8.default)(newSchema, "items");
|
|
1619
1679
|
if (typeof oldSchemaItems === "object" && typeof newSchemaItems === "object" && !Array.isArray(oldSchemaItems) && !Array.isArray(newSchemaItems)) {
|
|
1620
1680
|
if ((0, import_has3.default)(oldSchemaItems, REF_KEY)) {
|
|
1621
|
-
oldSchemaItems = retrieveSchema(
|
|
1681
|
+
oldSchemaItems = retrieveSchema(
|
|
1682
|
+
validator,
|
|
1683
|
+
oldSchemaItems,
|
|
1684
|
+
rootSchema,
|
|
1685
|
+
data,
|
|
1686
|
+
experimental_customMergeAllOf
|
|
1687
|
+
);
|
|
1622
1688
|
}
|
|
1623
1689
|
if ((0, import_has3.default)(newSchemaItems, REF_KEY)) {
|
|
1624
|
-
newSchemaItems = retrieveSchema(
|
|
1690
|
+
newSchemaItems = retrieveSchema(
|
|
1691
|
+
validator,
|
|
1692
|
+
newSchemaItems,
|
|
1693
|
+
rootSchema,
|
|
1694
|
+
data,
|
|
1695
|
+
experimental_customMergeAllOf
|
|
1696
|
+
);
|
|
1625
1697
|
}
|
|
1626
1698
|
const oldSchemaType = (0, import_get8.default)(oldSchemaItems, "type");
|
|
1627
1699
|
const newSchemaType = (0, import_get8.default)(newSchemaItems, "type");
|
|
@@ -1634,7 +1706,8 @@ function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, d
|
|
|
1634
1706
|
rootSchema,
|
|
1635
1707
|
newSchemaItems,
|
|
1636
1708
|
oldSchemaItems,
|
|
1637
|
-
aValue
|
|
1709
|
+
aValue,
|
|
1710
|
+
experimental_customMergeAllOf
|
|
1638
1711
|
);
|
|
1639
1712
|
if (itemValue !== void 0 && (maxItems < 0 || newValue.length < maxItems)) {
|
|
1640
1713
|
newValue.push(itemValue);
|
|
@@ -1657,7 +1730,7 @@ var import_get9 = __toESM(require("lodash/get"));
|
|
|
1657
1730
|
var import_isEqual2 = __toESM(require("lodash/isEqual"));
|
|
1658
1731
|
function toIdSchemaInternal(validator, schema, idPrefix, idSeparator, id, rootSchema, formData, _recurseList = [], experimental_customMergeAllOf) {
|
|
1659
1732
|
if (REF_KEY in schema || DEPENDENCIES_KEY in schema || ALL_OF_KEY in schema) {
|
|
1660
|
-
const _schema = retrieveSchema(validator, schema, rootSchema, formData);
|
|
1733
|
+
const _schema = retrieveSchema(validator, schema, rootSchema, formData, experimental_customMergeAllOf);
|
|
1661
1734
|
const sameSchemaIndex = _recurseList.findIndex((item) => (0, import_isEqual2.default)(item, _schema));
|
|
1662
1735
|
if (sameSchemaIndex === -1) {
|
|
1663
1736
|
return toIdSchemaInternal(
|
|
@@ -1727,9 +1800,9 @@ function toIdSchema(validator, schema, id, rootSchema, formData, idPrefix = "roo
|
|
|
1727
1800
|
var import_get10 = __toESM(require("lodash/get"));
|
|
1728
1801
|
var import_isEqual3 = __toESM(require("lodash/isEqual"));
|
|
1729
1802
|
var import_set2 = __toESM(require("lodash/set"));
|
|
1730
|
-
function toPathSchemaInternal(validator, schema, name, rootSchema, formData, _recurseList = []) {
|
|
1803
|
+
function toPathSchemaInternal(validator, schema, name, rootSchema, formData, _recurseList = [], experimental_customMergeAllOf) {
|
|
1731
1804
|
if (REF_KEY in schema || DEPENDENCIES_KEY in schema || ALL_OF_KEY in schema) {
|
|
1732
|
-
const _schema = retrieveSchema(validator, schema, rootSchema, formData);
|
|
1805
|
+
const _schema = retrieveSchema(validator, schema, rootSchema, formData, experimental_customMergeAllOf);
|
|
1733
1806
|
const sameSchemaIndex = _recurseList.findIndex((item) => (0, import_isEqual3.default)(item, _schema));
|
|
1734
1807
|
if (sameSchemaIndex === -1) {
|
|
1735
1808
|
return toPathSchemaInternal(
|
|
@@ -1738,7 +1811,8 @@ function toPathSchemaInternal(validator, schema, name, rootSchema, formData, _re
|
|
|
1738
1811
|
name,
|
|
1739
1812
|
rootSchema,
|
|
1740
1813
|
formData,
|
|
1741
|
-
_recurseList.concat(_schema)
|
|
1814
|
+
_recurseList.concat(_schema),
|
|
1815
|
+
experimental_customMergeAllOf
|
|
1742
1816
|
);
|
|
1743
1817
|
}
|
|
1744
1818
|
}
|
|
@@ -1748,11 +1822,27 @@ function toPathSchemaInternal(validator, schema, name, rootSchema, formData, _re
|
|
|
1748
1822
|
if (ONE_OF_KEY in schema || ANY_OF_KEY in schema) {
|
|
1749
1823
|
const xxxOf = ONE_OF_KEY in schema ? schema.oneOf : schema.anyOf;
|
|
1750
1824
|
const discriminator = getDiscriminatorFieldFromSchema(schema);
|
|
1751
|
-
const index = getClosestMatchingOption(
|
|
1825
|
+
const index = getClosestMatchingOption(
|
|
1826
|
+
validator,
|
|
1827
|
+
rootSchema,
|
|
1828
|
+
formData,
|
|
1829
|
+
xxxOf,
|
|
1830
|
+
0,
|
|
1831
|
+
discriminator,
|
|
1832
|
+
experimental_customMergeAllOf
|
|
1833
|
+
);
|
|
1752
1834
|
const _schema = xxxOf[index];
|
|
1753
1835
|
pathSchema = {
|
|
1754
1836
|
...pathSchema,
|
|
1755
|
-
...toPathSchemaInternal(
|
|
1837
|
+
...toPathSchemaInternal(
|
|
1838
|
+
validator,
|
|
1839
|
+
_schema,
|
|
1840
|
+
name,
|
|
1841
|
+
rootSchema,
|
|
1842
|
+
formData,
|
|
1843
|
+
_recurseList,
|
|
1844
|
+
experimental_customMergeAllOf
|
|
1845
|
+
)
|
|
1756
1846
|
};
|
|
1757
1847
|
}
|
|
1758
1848
|
if (ADDITIONAL_PROPERTIES_KEY in schema && schema[ADDITIONAL_PROPERTIES_KEY] !== false) {
|
|
@@ -1769,7 +1859,8 @@ function toPathSchemaInternal(validator, schema, name, rootSchema, formData, _re
|
|
|
1769
1859
|
`${name}.${i}`,
|
|
1770
1860
|
rootSchema,
|
|
1771
1861
|
element,
|
|
1772
|
-
_recurseList
|
|
1862
|
+
_recurseList,
|
|
1863
|
+
experimental_customMergeAllOf
|
|
1773
1864
|
);
|
|
1774
1865
|
} else if (schemaAdditionalItems) {
|
|
1775
1866
|
pathSchema[i] = toPathSchemaInternal(
|
|
@@ -1778,7 +1869,8 @@ function toPathSchemaInternal(validator, schema, name, rootSchema, formData, _re
|
|
|
1778
1869
|
`${name}.${i}`,
|
|
1779
1870
|
rootSchema,
|
|
1780
1871
|
element,
|
|
1781
|
-
_recurseList
|
|
1872
|
+
_recurseList,
|
|
1873
|
+
experimental_customMergeAllOf
|
|
1782
1874
|
);
|
|
1783
1875
|
} else {
|
|
1784
1876
|
console.warn(`Unable to generate path schema for "${name}.${i}". No schema defined for it`);
|
|
@@ -1792,7 +1884,8 @@ function toPathSchemaInternal(validator, schema, name, rootSchema, formData, _re
|
|
|
1792
1884
|
`${name}.${i}`,
|
|
1793
1885
|
rootSchema,
|
|
1794
1886
|
element,
|
|
1795
|
-
_recurseList
|
|
1887
|
+
_recurseList,
|
|
1888
|
+
experimental_customMergeAllOf
|
|
1796
1889
|
);
|
|
1797
1890
|
});
|
|
1798
1891
|
}
|
|
@@ -1807,14 +1900,15 @@ function toPathSchemaInternal(validator, schema, name, rootSchema, formData, _re
|
|
|
1807
1900
|
// It's possible that formData is not an object -- this can happen if an
|
|
1808
1901
|
// array item has just been added, but not populated with data yet
|
|
1809
1902
|
(0, import_get10.default)(formData, [property]),
|
|
1810
|
-
_recurseList
|
|
1903
|
+
_recurseList,
|
|
1904
|
+
experimental_customMergeAllOf
|
|
1811
1905
|
);
|
|
1812
1906
|
}
|
|
1813
1907
|
}
|
|
1814
1908
|
return pathSchema;
|
|
1815
1909
|
}
|
|
1816
|
-
function toPathSchema(validator, schema, name = "", rootSchema, formData) {
|
|
1817
|
-
return toPathSchemaInternal(validator, schema, name, rootSchema, formData);
|
|
1910
|
+
function toPathSchema(validator, schema, name = "", rootSchema, formData, experimental_customMergeAllOf) {
|
|
1911
|
+
return toPathSchemaInternal(validator, schema, name, rootSchema, formData, void 0, experimental_customMergeAllOf);
|
|
1818
1912
|
}
|
|
1819
1913
|
|
|
1820
1914
|
// src/createSchemaUtils.ts
|
|
@@ -1885,7 +1979,14 @@ var SchemaUtils = class {
|
|
|
1885
1979
|
* @returns - True if the label should be displayed or false if it should not
|
|
1886
1980
|
*/
|
|
1887
1981
|
getDisplayLabel(schema, uiSchema, globalOptions) {
|
|
1888
|
-
return getDisplayLabel(
|
|
1982
|
+
return getDisplayLabel(
|
|
1983
|
+
this.validator,
|
|
1984
|
+
schema,
|
|
1985
|
+
uiSchema,
|
|
1986
|
+
this.rootSchema,
|
|
1987
|
+
globalOptions,
|
|
1988
|
+
this.experimental_customMergeAllOf
|
|
1989
|
+
);
|
|
1889
1990
|
}
|
|
1890
1991
|
/** Determines which of the given `options` provided most closely matches the `formData`.
|
|
1891
1992
|
* Returns the index of the option that is valid and is the closest match, or 0 if there is no match.
|
|
@@ -1907,7 +2008,8 @@ var SchemaUtils = class {
|
|
|
1907
2008
|
formData,
|
|
1908
2009
|
options,
|
|
1909
2010
|
selectedOption,
|
|
1910
|
-
discriminatorField
|
|
2011
|
+
discriminatorField,
|
|
2012
|
+
this.experimental_customMergeAllOf
|
|
1911
2013
|
);
|
|
1912
2014
|
}
|
|
1913
2015
|
/** Given the `formData` and list of `options`, attempts to find the index of the first option that matches the data.
|
|
@@ -1942,7 +2044,7 @@ var SchemaUtils = class {
|
|
|
1942
2044
|
* @returns - True if schema/uiSchema contains an array of files, otherwise false
|
|
1943
2045
|
*/
|
|
1944
2046
|
isFilesArray(schema, uiSchema) {
|
|
1945
|
-
return isFilesArray(this.validator, schema, uiSchema, this.rootSchema);
|
|
2047
|
+
return isFilesArray(this.validator, schema, uiSchema, this.rootSchema, this.experimental_customMergeAllOf);
|
|
1946
2048
|
}
|
|
1947
2049
|
/** Checks to see if the `schema` combination represents a multi-select
|
|
1948
2050
|
*
|
|
@@ -1950,7 +2052,7 @@ var SchemaUtils = class {
|
|
|
1950
2052
|
* @returns - True if schema contains a multi-select, otherwise false
|
|
1951
2053
|
*/
|
|
1952
2054
|
isMultiSelect(schema) {
|
|
1953
|
-
return isMultiSelect(this.validator, schema, this.rootSchema);
|
|
2055
|
+
return isMultiSelect(this.validator, schema, this.rootSchema, this.experimental_customMergeAllOf);
|
|
1954
2056
|
}
|
|
1955
2057
|
/** Checks to see if the `schema` combination represents a select
|
|
1956
2058
|
*
|
|
@@ -1958,7 +2060,7 @@ var SchemaUtils = class {
|
|
|
1958
2060
|
* @returns - True if schema contains a select, otherwise false
|
|
1959
2061
|
*/
|
|
1960
2062
|
isSelect(schema) {
|
|
1961
|
-
return isSelect(this.validator, schema, this.rootSchema);
|
|
2063
|
+
return isSelect(this.validator, schema, this.rootSchema, this.experimental_customMergeAllOf);
|
|
1962
2064
|
}
|
|
1963
2065
|
/** Merges the errors in `additionalErrorSchema` into the existing `validationData` by combining the hierarchies in
|
|
1964
2066
|
* the two `ErrorSchema`s and then appending the error list from the `additionalErrorSchema` obtained by calling
|
|
@@ -2003,7 +2105,14 @@ var SchemaUtils = class {
|
|
|
2003
2105
|
* to `undefined`. Will return `undefined` if the new schema is not an object containing properties.
|
|
2004
2106
|
*/
|
|
2005
2107
|
sanitizeDataForNewSchema(newSchema, oldSchema, data) {
|
|
2006
|
-
return sanitizeDataForNewSchema(
|
|
2108
|
+
return sanitizeDataForNewSchema(
|
|
2109
|
+
this.validator,
|
|
2110
|
+
this.rootSchema,
|
|
2111
|
+
newSchema,
|
|
2112
|
+
oldSchema,
|
|
2113
|
+
data,
|
|
2114
|
+
this.experimental_customMergeAllOf
|
|
2115
|
+
);
|
|
2007
2116
|
}
|
|
2008
2117
|
/** Generates an `IdSchema` object for the `schema`, recursively
|
|
2009
2118
|
*
|
|
@@ -2034,7 +2143,14 @@ var SchemaUtils = class {
|
|
|
2034
2143
|
* @returns - The `PathSchema` object for the `schema`
|
|
2035
2144
|
*/
|
|
2036
2145
|
toPathSchema(schema, name, formData) {
|
|
2037
|
-
return toPathSchema(
|
|
2146
|
+
return toPathSchema(
|
|
2147
|
+
this.validator,
|
|
2148
|
+
schema,
|
|
2149
|
+
name,
|
|
2150
|
+
this.rootSchema,
|
|
2151
|
+
formData,
|
|
2152
|
+
this.experimental_customMergeAllOf
|
|
2153
|
+
);
|
|
2038
2154
|
}
|
|
2039
2155
|
};
|
|
2040
2156
|
function createSchemaUtils(validator, rootSchema, experimental_defaultFormStateBehavior = {}, experimental_customMergeAllOf) {
|
|
@@ -2241,9 +2357,9 @@ var ErrorSchemaBuilder = class {
|
|
|
2241
2357
|
errorBlock[ERRORS_KEY] = errorsList;
|
|
2242
2358
|
}
|
|
2243
2359
|
if (Array.isArray(errorOrList)) {
|
|
2244
|
-
|
|
2360
|
+
(0, import_set3.default)(errorBlock, ERRORS_KEY, [.../* @__PURE__ */ new Set([...errorsList, ...errorOrList])]);
|
|
2245
2361
|
} else {
|
|
2246
|
-
|
|
2362
|
+
(0, import_set3.default)(errorBlock, ERRORS_KEY, [.../* @__PURE__ */ new Set([...errorsList, errorOrList])]);
|
|
2247
2363
|
}
|
|
2248
2364
|
return this;
|
|
2249
2365
|
}
|
|
@@ -2257,7 +2373,7 @@ var ErrorSchemaBuilder = class {
|
|
|
2257
2373
|
*/
|
|
2258
2374
|
setErrors(errorOrList, pathOfError) {
|
|
2259
2375
|
const errorBlock = this.getOrCreateErrorBlock(pathOfError);
|
|
2260
|
-
const listToAdd = Array.isArray(errorOrList) ? [...errorOrList] : [errorOrList];
|
|
2376
|
+
const listToAdd = Array.isArray(errorOrList) ? [.../* @__PURE__ */ new Set([...errorOrList])] : [errorOrList];
|
|
2261
2377
|
(0, import_set3.default)(errorBlock, ERRORS_KEY, listToAdd);
|
|
2262
2378
|
return this;
|
|
2263
2379
|
}
|