@rjsf/utils 5.22.4 → 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 +166 -55
- package/dist/index.js.map +2 -2
- package/dist/utils.esm.js +166 -55
- package/dist/utils.esm.js.map +2 -2
- package/dist/utils.umd.js +178 -59
- 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 +28 -11
- 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 +35 -10
- 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,6 +1418,7 @@ 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;
|
|
@@ -1404,6 +1437,7 @@ function getArrayDefaults(validator, rawSchema, {
|
|
|
1404
1437
|
rootSchema,
|
|
1405
1438
|
_recurseList,
|
|
1406
1439
|
experimental_defaultFormStateBehavior,
|
|
1440
|
+
experimental_customMergeAllOf,
|
|
1407
1441
|
parentDefaults: item,
|
|
1408
1442
|
required
|
|
1409
1443
|
});
|
|
@@ -1419,6 +1453,7 @@ function getArrayDefaults(validator, rawSchema, {
|
|
|
1419
1453
|
rootSchema,
|
|
1420
1454
|
_recurseList,
|
|
1421
1455
|
experimental_defaultFormStateBehavior,
|
|
1456
|
+
experimental_customMergeAllOf,
|
|
1422
1457
|
rawFormData: item,
|
|
1423
1458
|
parentDefaults: (0, import_get7.default)(defaults, [idx]),
|
|
1424
1459
|
required
|
|
@@ -1428,7 +1463,7 @@ function getArrayDefaults(validator, rawSchema, {
|
|
|
1428
1463
|
defaults = mergeDefaultsWithFormData(defaults, itemDefaults, mergeExtraDefaults);
|
|
1429
1464
|
}
|
|
1430
1465
|
}
|
|
1431
|
-
const hasConst = isObject(schema) && CONST_KEY in schema;
|
|
1466
|
+
const hasConst = isObject(schema) && CONST_KEY in schema && experimental_defaultFormStateBehavior?.constAsDefaults !== "never";
|
|
1432
1467
|
if (hasConst === false) {
|
|
1433
1468
|
if (neverPopulate) {
|
|
1434
1469
|
return defaults ?? emptyDefault;
|
|
@@ -1438,7 +1473,7 @@ function getArrayDefaults(validator, rawSchema, {
|
|
|
1438
1473
|
}
|
|
1439
1474
|
}
|
|
1440
1475
|
const defaultsLength = Array.isArray(defaults) ? defaults.length : 0;
|
|
1441
|
-
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) {
|
|
1442
1477
|
return defaults ? defaults : emptyDefault;
|
|
1443
1478
|
}
|
|
1444
1479
|
const defaultEntries = defaults || [];
|
|
@@ -1450,6 +1485,7 @@ function getArrayDefaults(validator, rawSchema, {
|
|
|
1450
1485
|
rootSchema,
|
|
1451
1486
|
_recurseList,
|
|
1452
1487
|
experimental_defaultFormStateBehavior,
|
|
1488
|
+
experimental_customMergeAllOf,
|
|
1453
1489
|
required
|
|
1454
1490
|
})
|
|
1455
1491
|
);
|
|
@@ -1502,25 +1538,31 @@ function isCustomWidget(uiSchema = {}) {
|
|
|
1502
1538
|
}
|
|
1503
1539
|
|
|
1504
1540
|
// src/schema/isFilesArray.ts
|
|
1505
|
-
function isFilesArray(validator, schema, uiSchema = {}, rootSchema) {
|
|
1541
|
+
function isFilesArray(validator, schema, uiSchema = {}, rootSchema, experimental_customMergeAllOf) {
|
|
1506
1542
|
if (uiSchema[UI_WIDGET_KEY] === "files") {
|
|
1507
1543
|
return true;
|
|
1508
1544
|
}
|
|
1509
1545
|
if (schema.items) {
|
|
1510
|
-
const itemsSchema = retrieveSchema(
|
|
1546
|
+
const itemsSchema = retrieveSchema(
|
|
1547
|
+
validator,
|
|
1548
|
+
schema.items,
|
|
1549
|
+
rootSchema,
|
|
1550
|
+
void 0,
|
|
1551
|
+
experimental_customMergeAllOf
|
|
1552
|
+
);
|
|
1511
1553
|
return itemsSchema.type === "string" && itemsSchema.format === "data-url";
|
|
1512
1554
|
}
|
|
1513
1555
|
return false;
|
|
1514
1556
|
}
|
|
1515
1557
|
|
|
1516
1558
|
// src/schema/getDisplayLabel.ts
|
|
1517
|
-
function getDisplayLabel(validator, schema, uiSchema = {}, rootSchema, globalOptions) {
|
|
1559
|
+
function getDisplayLabel(validator, schema, uiSchema = {}, rootSchema, globalOptions, experimental_customMergeAllOf) {
|
|
1518
1560
|
const uiOptions = getUiOptions(uiSchema, globalOptions);
|
|
1519
1561
|
const { label = true } = uiOptions;
|
|
1520
1562
|
let displayLabel = !!label;
|
|
1521
1563
|
const schemaType = getSchemaType(schema);
|
|
1522
1564
|
if (schemaType === "array") {
|
|
1523
|
-
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);
|
|
1524
1566
|
}
|
|
1525
1567
|
if (schemaType === "object") {
|
|
1526
1568
|
displayLabel = false;
|
|
@@ -1554,7 +1596,7 @@ function mergeValidationData(validator, validationData, additionalErrorSchema) {
|
|
|
1554
1596
|
var import_get8 = __toESM(require("lodash/get"));
|
|
1555
1597
|
var import_has3 = __toESM(require("lodash/has"));
|
|
1556
1598
|
var NO_VALUE = Symbol("no Value");
|
|
1557
|
-
function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, data = {}) {
|
|
1599
|
+
function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, data = {}, experimental_customMergeAllOf) {
|
|
1558
1600
|
let newFormData;
|
|
1559
1601
|
if ((0, import_has3.default)(newSchema, PROPERTIES_KEY)) {
|
|
1560
1602
|
const removeOldSchemaData = {};
|
|
@@ -1573,10 +1615,22 @@ function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, d
|
|
|
1573
1615
|
let oldKeyedSchema = (0, import_get8.default)(oldSchema, [PROPERTIES_KEY, key], {});
|
|
1574
1616
|
let newKeyedSchema = (0, import_get8.default)(newSchema, [PROPERTIES_KEY, key], {});
|
|
1575
1617
|
if ((0, import_has3.default)(oldKeyedSchema, REF_KEY)) {
|
|
1576
|
-
oldKeyedSchema = retrieveSchema(
|
|
1618
|
+
oldKeyedSchema = retrieveSchema(
|
|
1619
|
+
validator,
|
|
1620
|
+
oldKeyedSchema,
|
|
1621
|
+
rootSchema,
|
|
1622
|
+
formValue,
|
|
1623
|
+
experimental_customMergeAllOf
|
|
1624
|
+
);
|
|
1577
1625
|
}
|
|
1578
1626
|
if ((0, import_has3.default)(newKeyedSchema, REF_KEY)) {
|
|
1579
|
-
newKeyedSchema = retrieveSchema(
|
|
1627
|
+
newKeyedSchema = retrieveSchema(
|
|
1628
|
+
validator,
|
|
1629
|
+
newKeyedSchema,
|
|
1630
|
+
rootSchema,
|
|
1631
|
+
formValue,
|
|
1632
|
+
experimental_customMergeAllOf
|
|
1633
|
+
);
|
|
1580
1634
|
}
|
|
1581
1635
|
const oldSchemaTypeForKey = (0, import_get8.default)(oldKeyedSchema, "type");
|
|
1582
1636
|
const newSchemaTypeForKey = (0, import_get8.default)(newKeyedSchema, "type");
|
|
@@ -1590,7 +1644,8 @@ function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, d
|
|
|
1590
1644
|
rootSchema,
|
|
1591
1645
|
newKeyedSchema,
|
|
1592
1646
|
oldKeyedSchema,
|
|
1593
|
-
formValue
|
|
1647
|
+
formValue,
|
|
1648
|
+
experimental_customMergeAllOf
|
|
1594
1649
|
);
|
|
1595
1650
|
if (itemData !== void 0 || newSchemaTypeForKey === "array") {
|
|
1596
1651
|
nestedData[key] = itemData;
|
|
@@ -1623,10 +1678,22 @@ function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, d
|
|
|
1623
1678
|
let newSchemaItems = (0, import_get8.default)(newSchema, "items");
|
|
1624
1679
|
if (typeof oldSchemaItems === "object" && typeof newSchemaItems === "object" && !Array.isArray(oldSchemaItems) && !Array.isArray(newSchemaItems)) {
|
|
1625
1680
|
if ((0, import_has3.default)(oldSchemaItems, REF_KEY)) {
|
|
1626
|
-
oldSchemaItems = retrieveSchema(
|
|
1681
|
+
oldSchemaItems = retrieveSchema(
|
|
1682
|
+
validator,
|
|
1683
|
+
oldSchemaItems,
|
|
1684
|
+
rootSchema,
|
|
1685
|
+
data,
|
|
1686
|
+
experimental_customMergeAllOf
|
|
1687
|
+
);
|
|
1627
1688
|
}
|
|
1628
1689
|
if ((0, import_has3.default)(newSchemaItems, REF_KEY)) {
|
|
1629
|
-
newSchemaItems = retrieveSchema(
|
|
1690
|
+
newSchemaItems = retrieveSchema(
|
|
1691
|
+
validator,
|
|
1692
|
+
newSchemaItems,
|
|
1693
|
+
rootSchema,
|
|
1694
|
+
data,
|
|
1695
|
+
experimental_customMergeAllOf
|
|
1696
|
+
);
|
|
1630
1697
|
}
|
|
1631
1698
|
const oldSchemaType = (0, import_get8.default)(oldSchemaItems, "type");
|
|
1632
1699
|
const newSchemaType = (0, import_get8.default)(newSchemaItems, "type");
|
|
@@ -1639,7 +1706,8 @@ function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, d
|
|
|
1639
1706
|
rootSchema,
|
|
1640
1707
|
newSchemaItems,
|
|
1641
1708
|
oldSchemaItems,
|
|
1642
|
-
aValue
|
|
1709
|
+
aValue,
|
|
1710
|
+
experimental_customMergeAllOf
|
|
1643
1711
|
);
|
|
1644
1712
|
if (itemValue !== void 0 && (maxItems < 0 || newValue.length < maxItems)) {
|
|
1645
1713
|
newValue.push(itemValue);
|
|
@@ -1662,7 +1730,7 @@ var import_get9 = __toESM(require("lodash/get"));
|
|
|
1662
1730
|
var import_isEqual2 = __toESM(require("lodash/isEqual"));
|
|
1663
1731
|
function toIdSchemaInternal(validator, schema, idPrefix, idSeparator, id, rootSchema, formData, _recurseList = [], experimental_customMergeAllOf) {
|
|
1664
1732
|
if (REF_KEY in schema || DEPENDENCIES_KEY in schema || ALL_OF_KEY in schema) {
|
|
1665
|
-
const _schema = retrieveSchema(validator, schema, rootSchema, formData);
|
|
1733
|
+
const _schema = retrieveSchema(validator, schema, rootSchema, formData, experimental_customMergeAllOf);
|
|
1666
1734
|
const sameSchemaIndex = _recurseList.findIndex((item) => (0, import_isEqual2.default)(item, _schema));
|
|
1667
1735
|
if (sameSchemaIndex === -1) {
|
|
1668
1736
|
return toIdSchemaInternal(
|
|
@@ -1732,9 +1800,9 @@ function toIdSchema(validator, schema, id, rootSchema, formData, idPrefix = "roo
|
|
|
1732
1800
|
var import_get10 = __toESM(require("lodash/get"));
|
|
1733
1801
|
var import_isEqual3 = __toESM(require("lodash/isEqual"));
|
|
1734
1802
|
var import_set2 = __toESM(require("lodash/set"));
|
|
1735
|
-
function toPathSchemaInternal(validator, schema, name, rootSchema, formData, _recurseList = []) {
|
|
1803
|
+
function toPathSchemaInternal(validator, schema, name, rootSchema, formData, _recurseList = [], experimental_customMergeAllOf) {
|
|
1736
1804
|
if (REF_KEY in schema || DEPENDENCIES_KEY in schema || ALL_OF_KEY in schema) {
|
|
1737
|
-
const _schema = retrieveSchema(validator, schema, rootSchema, formData);
|
|
1805
|
+
const _schema = retrieveSchema(validator, schema, rootSchema, formData, experimental_customMergeAllOf);
|
|
1738
1806
|
const sameSchemaIndex = _recurseList.findIndex((item) => (0, import_isEqual3.default)(item, _schema));
|
|
1739
1807
|
if (sameSchemaIndex === -1) {
|
|
1740
1808
|
return toPathSchemaInternal(
|
|
@@ -1743,7 +1811,8 @@ function toPathSchemaInternal(validator, schema, name, rootSchema, formData, _re
|
|
|
1743
1811
|
name,
|
|
1744
1812
|
rootSchema,
|
|
1745
1813
|
formData,
|
|
1746
|
-
_recurseList.concat(_schema)
|
|
1814
|
+
_recurseList.concat(_schema),
|
|
1815
|
+
experimental_customMergeAllOf
|
|
1747
1816
|
);
|
|
1748
1817
|
}
|
|
1749
1818
|
}
|
|
@@ -1753,11 +1822,27 @@ function toPathSchemaInternal(validator, schema, name, rootSchema, formData, _re
|
|
|
1753
1822
|
if (ONE_OF_KEY in schema || ANY_OF_KEY in schema) {
|
|
1754
1823
|
const xxxOf = ONE_OF_KEY in schema ? schema.oneOf : schema.anyOf;
|
|
1755
1824
|
const discriminator = getDiscriminatorFieldFromSchema(schema);
|
|
1756
|
-
const index = getClosestMatchingOption(
|
|
1825
|
+
const index = getClosestMatchingOption(
|
|
1826
|
+
validator,
|
|
1827
|
+
rootSchema,
|
|
1828
|
+
formData,
|
|
1829
|
+
xxxOf,
|
|
1830
|
+
0,
|
|
1831
|
+
discriminator,
|
|
1832
|
+
experimental_customMergeAllOf
|
|
1833
|
+
);
|
|
1757
1834
|
const _schema = xxxOf[index];
|
|
1758
1835
|
pathSchema = {
|
|
1759
1836
|
...pathSchema,
|
|
1760
|
-
...toPathSchemaInternal(
|
|
1837
|
+
...toPathSchemaInternal(
|
|
1838
|
+
validator,
|
|
1839
|
+
_schema,
|
|
1840
|
+
name,
|
|
1841
|
+
rootSchema,
|
|
1842
|
+
formData,
|
|
1843
|
+
_recurseList,
|
|
1844
|
+
experimental_customMergeAllOf
|
|
1845
|
+
)
|
|
1761
1846
|
};
|
|
1762
1847
|
}
|
|
1763
1848
|
if (ADDITIONAL_PROPERTIES_KEY in schema && schema[ADDITIONAL_PROPERTIES_KEY] !== false) {
|
|
@@ -1774,7 +1859,8 @@ function toPathSchemaInternal(validator, schema, name, rootSchema, formData, _re
|
|
|
1774
1859
|
`${name}.${i}`,
|
|
1775
1860
|
rootSchema,
|
|
1776
1861
|
element,
|
|
1777
|
-
_recurseList
|
|
1862
|
+
_recurseList,
|
|
1863
|
+
experimental_customMergeAllOf
|
|
1778
1864
|
);
|
|
1779
1865
|
} else if (schemaAdditionalItems) {
|
|
1780
1866
|
pathSchema[i] = toPathSchemaInternal(
|
|
@@ -1783,7 +1869,8 @@ function toPathSchemaInternal(validator, schema, name, rootSchema, formData, _re
|
|
|
1783
1869
|
`${name}.${i}`,
|
|
1784
1870
|
rootSchema,
|
|
1785
1871
|
element,
|
|
1786
|
-
_recurseList
|
|
1872
|
+
_recurseList,
|
|
1873
|
+
experimental_customMergeAllOf
|
|
1787
1874
|
);
|
|
1788
1875
|
} else {
|
|
1789
1876
|
console.warn(`Unable to generate path schema for "${name}.${i}". No schema defined for it`);
|
|
@@ -1797,7 +1884,8 @@ function toPathSchemaInternal(validator, schema, name, rootSchema, formData, _re
|
|
|
1797
1884
|
`${name}.${i}`,
|
|
1798
1885
|
rootSchema,
|
|
1799
1886
|
element,
|
|
1800
|
-
_recurseList
|
|
1887
|
+
_recurseList,
|
|
1888
|
+
experimental_customMergeAllOf
|
|
1801
1889
|
);
|
|
1802
1890
|
});
|
|
1803
1891
|
}
|
|
@@ -1812,14 +1900,15 @@ function toPathSchemaInternal(validator, schema, name, rootSchema, formData, _re
|
|
|
1812
1900
|
// It's possible that formData is not an object -- this can happen if an
|
|
1813
1901
|
// array item has just been added, but not populated with data yet
|
|
1814
1902
|
(0, import_get10.default)(formData, [property]),
|
|
1815
|
-
_recurseList
|
|
1903
|
+
_recurseList,
|
|
1904
|
+
experimental_customMergeAllOf
|
|
1816
1905
|
);
|
|
1817
1906
|
}
|
|
1818
1907
|
}
|
|
1819
1908
|
return pathSchema;
|
|
1820
1909
|
}
|
|
1821
|
-
function toPathSchema(validator, schema, name = "", rootSchema, formData) {
|
|
1822
|
-
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);
|
|
1823
1912
|
}
|
|
1824
1913
|
|
|
1825
1914
|
// src/createSchemaUtils.ts
|
|
@@ -1890,7 +1979,14 @@ var SchemaUtils = class {
|
|
|
1890
1979
|
* @returns - True if the label should be displayed or false if it should not
|
|
1891
1980
|
*/
|
|
1892
1981
|
getDisplayLabel(schema, uiSchema, globalOptions) {
|
|
1893
|
-
return getDisplayLabel(
|
|
1982
|
+
return getDisplayLabel(
|
|
1983
|
+
this.validator,
|
|
1984
|
+
schema,
|
|
1985
|
+
uiSchema,
|
|
1986
|
+
this.rootSchema,
|
|
1987
|
+
globalOptions,
|
|
1988
|
+
this.experimental_customMergeAllOf
|
|
1989
|
+
);
|
|
1894
1990
|
}
|
|
1895
1991
|
/** Determines which of the given `options` provided most closely matches the `formData`.
|
|
1896
1992
|
* Returns the index of the option that is valid and is the closest match, or 0 if there is no match.
|
|
@@ -1912,7 +2008,8 @@ var SchemaUtils = class {
|
|
|
1912
2008
|
formData,
|
|
1913
2009
|
options,
|
|
1914
2010
|
selectedOption,
|
|
1915
|
-
discriminatorField
|
|
2011
|
+
discriminatorField,
|
|
2012
|
+
this.experimental_customMergeAllOf
|
|
1916
2013
|
);
|
|
1917
2014
|
}
|
|
1918
2015
|
/** Given the `formData` and list of `options`, attempts to find the index of the first option that matches the data.
|
|
@@ -1947,7 +2044,7 @@ var SchemaUtils = class {
|
|
|
1947
2044
|
* @returns - True if schema/uiSchema contains an array of files, otherwise false
|
|
1948
2045
|
*/
|
|
1949
2046
|
isFilesArray(schema, uiSchema) {
|
|
1950
|
-
return isFilesArray(this.validator, schema, uiSchema, this.rootSchema);
|
|
2047
|
+
return isFilesArray(this.validator, schema, uiSchema, this.rootSchema, this.experimental_customMergeAllOf);
|
|
1951
2048
|
}
|
|
1952
2049
|
/** Checks to see if the `schema` combination represents a multi-select
|
|
1953
2050
|
*
|
|
@@ -1955,7 +2052,7 @@ var SchemaUtils = class {
|
|
|
1955
2052
|
* @returns - True if schema contains a multi-select, otherwise false
|
|
1956
2053
|
*/
|
|
1957
2054
|
isMultiSelect(schema) {
|
|
1958
|
-
return isMultiSelect(this.validator, schema, this.rootSchema);
|
|
2055
|
+
return isMultiSelect(this.validator, schema, this.rootSchema, this.experimental_customMergeAllOf);
|
|
1959
2056
|
}
|
|
1960
2057
|
/** Checks to see if the `schema` combination represents a select
|
|
1961
2058
|
*
|
|
@@ -1963,7 +2060,7 @@ var SchemaUtils = class {
|
|
|
1963
2060
|
* @returns - True if schema contains a select, otherwise false
|
|
1964
2061
|
*/
|
|
1965
2062
|
isSelect(schema) {
|
|
1966
|
-
return isSelect(this.validator, schema, this.rootSchema);
|
|
2063
|
+
return isSelect(this.validator, schema, this.rootSchema, this.experimental_customMergeAllOf);
|
|
1967
2064
|
}
|
|
1968
2065
|
/** Merges the errors in `additionalErrorSchema` into the existing `validationData` by combining the hierarchies in
|
|
1969
2066
|
* the two `ErrorSchema`s and then appending the error list from the `additionalErrorSchema` obtained by calling
|
|
@@ -2008,7 +2105,14 @@ var SchemaUtils = class {
|
|
|
2008
2105
|
* to `undefined`. Will return `undefined` if the new schema is not an object containing properties.
|
|
2009
2106
|
*/
|
|
2010
2107
|
sanitizeDataForNewSchema(newSchema, oldSchema, data) {
|
|
2011
|
-
return sanitizeDataForNewSchema(
|
|
2108
|
+
return sanitizeDataForNewSchema(
|
|
2109
|
+
this.validator,
|
|
2110
|
+
this.rootSchema,
|
|
2111
|
+
newSchema,
|
|
2112
|
+
oldSchema,
|
|
2113
|
+
data,
|
|
2114
|
+
this.experimental_customMergeAllOf
|
|
2115
|
+
);
|
|
2012
2116
|
}
|
|
2013
2117
|
/** Generates an `IdSchema` object for the `schema`, recursively
|
|
2014
2118
|
*
|
|
@@ -2039,7 +2143,14 @@ var SchemaUtils = class {
|
|
|
2039
2143
|
* @returns - The `PathSchema` object for the `schema`
|
|
2040
2144
|
*/
|
|
2041
2145
|
toPathSchema(schema, name, formData) {
|
|
2042
|
-
return toPathSchema(
|
|
2146
|
+
return toPathSchema(
|
|
2147
|
+
this.validator,
|
|
2148
|
+
schema,
|
|
2149
|
+
name,
|
|
2150
|
+
this.rootSchema,
|
|
2151
|
+
formData,
|
|
2152
|
+
this.experimental_customMergeAllOf
|
|
2153
|
+
);
|
|
2043
2154
|
}
|
|
2044
2155
|
};
|
|
2045
2156
|
function createSchemaUtils(validator, rootSchema, experimental_defaultFormStateBehavior = {}, experimental_customMergeAllOf) {
|
|
@@ -2246,9 +2357,9 @@ var ErrorSchemaBuilder = class {
|
|
|
2246
2357
|
errorBlock[ERRORS_KEY] = errorsList;
|
|
2247
2358
|
}
|
|
2248
2359
|
if (Array.isArray(errorOrList)) {
|
|
2249
|
-
|
|
2360
|
+
(0, import_set3.default)(errorBlock, ERRORS_KEY, [.../* @__PURE__ */ new Set([...errorsList, ...errorOrList])]);
|
|
2250
2361
|
} else {
|
|
2251
|
-
|
|
2362
|
+
(0, import_set3.default)(errorBlock, ERRORS_KEY, [.../* @__PURE__ */ new Set([...errorsList, errorOrList])]);
|
|
2252
2363
|
}
|
|
2253
2364
|
return this;
|
|
2254
2365
|
}
|
|
@@ -2262,7 +2373,7 @@ var ErrorSchemaBuilder = class {
|
|
|
2262
2373
|
*/
|
|
2263
2374
|
setErrors(errorOrList, pathOfError) {
|
|
2264
2375
|
const errorBlock = this.getOrCreateErrorBlock(pathOfError);
|
|
2265
|
-
const listToAdd = Array.isArray(errorOrList) ? [...errorOrList] : [errorOrList];
|
|
2376
|
+
const listToAdd = Array.isArray(errorOrList) ? [.../* @__PURE__ */ new Set([...errorOrList])] : [errorOrList];
|
|
2266
2377
|
(0, import_set3.default)(errorBlock, ERRORS_KEY, listToAdd);
|
|
2267
2378
|
return this;
|
|
2268
2379
|
}
|