@rjsf/utils 5.21.2 → 5.22.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 +184 -61
- package/dist/index.js.map +2 -2
- package/dist/utils.esm.js +184 -61
- package/dist/utils.esm.js.map +2 -2
- package/dist/utils.umd.js +179 -64
- package/lib/createSchemaUtils.d.ts +3 -2
- package/lib/createSchemaUtils.js +17 -11
- package/lib/createSchemaUtils.js.map +1 -1
- package/lib/mergeDefaultsWithFormData.d.ts +4 -2
- package/lib/mergeDefaultsWithFormData.js +9 -4
- package/lib/mergeDefaultsWithFormData.js.map +1 -1
- package/lib/schema/getClosestMatchingOption.js +6 -2
- package/lib/schema/getClosestMatchingOption.js.map +1 -1
- package/lib/schema/getDefaultFormState.d.ts +6 -3
- package/lib/schema/getDefaultFormState.js +43 -22
- package/lib/schema/getDefaultFormState.js.map +1 -1
- package/lib/schema/retrieveSchema.d.ts +19 -10
- package/lib/schema/retrieveSchema.js +38 -27
- package/lib/schema/retrieveSchema.js.map +1 -1
- package/lib/schema/toIdSchema.d.ts +3 -2
- package/lib/schema/toIdSchema.js +8 -6
- package/lib/schema/toIdSchema.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/types.d.ts +19 -3
- package/package.json +2 -2
- package/src/createSchemaUtils.ts +43 -11
- package/src/mergeDefaultsWithFormData.ts +16 -4
- package/src/schema/getClosestMatchingOption.ts +6 -2
- package/src/schema/getDefaultFormState.ts +58 -19
- package/src/schema/retrieveSchema.ts +110 -28
- package/src/schema/toIdSchema.ts +32 -7
- package/src/types.ts +20 -2
package/dist/utils.umd.js
CHANGED
|
@@ -324,10 +324,18 @@
|
|
|
324
324
|
}
|
|
325
325
|
|
|
326
326
|
// src/schema/retrieveSchema.ts
|
|
327
|
-
function retrieveSchema(validator, schema, rootSchema = {}, rawFormData) {
|
|
328
|
-
return retrieveSchemaInternal(
|
|
327
|
+
function retrieveSchema(validator, schema, rootSchema = {}, rawFormData, experimental_customMergeAllOf) {
|
|
328
|
+
return retrieveSchemaInternal(
|
|
329
|
+
validator,
|
|
330
|
+
schema,
|
|
331
|
+
rootSchema,
|
|
332
|
+
rawFormData,
|
|
333
|
+
void 0,
|
|
334
|
+
void 0,
|
|
335
|
+
experimental_customMergeAllOf
|
|
336
|
+
)[0];
|
|
329
337
|
}
|
|
330
|
-
function resolveCondition(validator, schema, rootSchema, expandAllBranches, recurseList, formData) {
|
|
338
|
+
function resolveCondition(validator, schema, rootSchema, expandAllBranches, recurseList, formData, experimental_customMergeAllOf) {
|
|
331
339
|
const { if: expression, then, else: otherwise, ...resolvedSchemaLessConditional } = schema;
|
|
332
340
|
const conditionValue = validator.isValid(expression, formData || {}, rootSchema);
|
|
333
341
|
let resolvedSchemas = [resolvedSchemaLessConditional];
|
|
@@ -335,12 +343,28 @@
|
|
|
335
343
|
if (expandAllBranches) {
|
|
336
344
|
if (then && typeof then !== "boolean") {
|
|
337
345
|
schemas = schemas.concat(
|
|
338
|
-
retrieveSchemaInternal(
|
|
346
|
+
retrieveSchemaInternal(
|
|
347
|
+
validator,
|
|
348
|
+
then,
|
|
349
|
+
rootSchema,
|
|
350
|
+
formData,
|
|
351
|
+
expandAllBranches,
|
|
352
|
+
recurseList,
|
|
353
|
+
experimental_customMergeAllOf
|
|
354
|
+
)
|
|
339
355
|
);
|
|
340
356
|
}
|
|
341
357
|
if (otherwise && typeof otherwise !== "boolean") {
|
|
342
358
|
schemas = schemas.concat(
|
|
343
|
-
retrieveSchemaInternal(
|
|
359
|
+
retrieveSchemaInternal(
|
|
360
|
+
validator,
|
|
361
|
+
otherwise,
|
|
362
|
+
rootSchema,
|
|
363
|
+
formData,
|
|
364
|
+
expandAllBranches,
|
|
365
|
+
recurseList,
|
|
366
|
+
experimental_customMergeAllOf
|
|
367
|
+
)
|
|
344
368
|
);
|
|
345
369
|
}
|
|
346
370
|
} else {
|
|
@@ -353,7 +377,8 @@
|
|
|
353
377
|
rootSchema,
|
|
354
378
|
formData,
|
|
355
379
|
expandAllBranches,
|
|
356
|
-
recurseList
|
|
380
|
+
recurseList,
|
|
381
|
+
experimental_customMergeAllOf
|
|
357
382
|
)
|
|
358
383
|
);
|
|
359
384
|
}
|
|
@@ -362,7 +387,15 @@
|
|
|
362
387
|
resolvedSchemas = schemas.map((s) => mergeSchemas(resolvedSchemaLessConditional, s));
|
|
363
388
|
}
|
|
364
389
|
return resolvedSchemas.flatMap(
|
|
365
|
-
(s) => retrieveSchemaInternal(
|
|
390
|
+
(s) => retrieveSchemaInternal(
|
|
391
|
+
validator,
|
|
392
|
+
s,
|
|
393
|
+
rootSchema,
|
|
394
|
+
formData,
|
|
395
|
+
expandAllBranches,
|
|
396
|
+
recurseList,
|
|
397
|
+
experimental_customMergeAllOf
|
|
398
|
+
)
|
|
366
399
|
);
|
|
367
400
|
}
|
|
368
401
|
function getAllPermutationsOfXxxOf(listOfLists) {
|
|
@@ -379,7 +412,7 @@
|
|
|
379
412
|
);
|
|
380
413
|
return allPermutations;
|
|
381
414
|
}
|
|
382
|
-
function resolveSchema(validator, schema, rootSchema, expandAllBranches, recurseList, formData) {
|
|
415
|
+
function resolveSchema(validator, schema, rootSchema, expandAllBranches, recurseList, formData, experimental_customMergeAllOf) {
|
|
383
416
|
const updatedSchemas = resolveReference(
|
|
384
417
|
validator,
|
|
385
418
|
schema,
|
|
@@ -401,7 +434,15 @@
|
|
|
401
434
|
formData
|
|
402
435
|
);
|
|
403
436
|
return resolvedSchemas.flatMap((s) => {
|
|
404
|
-
return retrieveSchemaInternal(
|
|
437
|
+
return retrieveSchemaInternal(
|
|
438
|
+
validator,
|
|
439
|
+
s,
|
|
440
|
+
rootSchema,
|
|
441
|
+
formData,
|
|
442
|
+
expandAllBranches,
|
|
443
|
+
recurseList,
|
|
444
|
+
experimental_customMergeAllOf
|
|
445
|
+
);
|
|
405
446
|
});
|
|
406
447
|
}
|
|
407
448
|
if (ALL_OF_KEY in schema && Array.isArray(schema.allOf)) {
|
|
@@ -412,7 +453,8 @@
|
|
|
412
453
|
rootSchema,
|
|
413
454
|
formData,
|
|
414
455
|
expandAllBranches,
|
|
415
|
-
recurseList
|
|
456
|
+
recurseList,
|
|
457
|
+
experimental_customMergeAllOf
|
|
416
458
|
)
|
|
417
459
|
);
|
|
418
460
|
const allPermutations = getAllPermutationsOfXxxOf(allOfSchemaElements);
|
|
@@ -420,7 +462,7 @@
|
|
|
420
462
|
}
|
|
421
463
|
return [schema];
|
|
422
464
|
}
|
|
423
|
-
function resolveReference(validator, schema, rootSchema, expandAllBranches, recurseList, formData) {
|
|
465
|
+
function resolveReference(validator, schema, rootSchema, expandAllBranches, recurseList, formData, experimental_customMergeAllOf) {
|
|
424
466
|
const updatedSchema = resolveAllReferences(schema, rootSchema, recurseList);
|
|
425
467
|
if (updatedSchema !== schema) {
|
|
426
468
|
return retrieveSchemaInternal(
|
|
@@ -429,7 +471,8 @@
|
|
|
429
471
|
rootSchema,
|
|
430
472
|
formData,
|
|
431
473
|
expandAllBranches,
|
|
432
|
-
recurseList
|
|
474
|
+
recurseList,
|
|
475
|
+
experimental_customMergeAllOf
|
|
433
476
|
);
|
|
434
477
|
}
|
|
435
478
|
return [schema];
|
|
@@ -507,7 +550,7 @@
|
|
|
507
550
|
});
|
|
508
551
|
return schema;
|
|
509
552
|
}
|
|
510
|
-
function retrieveSchemaInternal(validator, schema, rootSchema, rawFormData, expandAllBranches = false, recurseList = []) {
|
|
553
|
+
function retrieveSchemaInternal(validator, schema, rootSchema, rawFormData, expandAllBranches = false, recurseList = [], experimental_customMergeAllOf) {
|
|
511
554
|
if (!isObject(schema)) {
|
|
512
555
|
return [{}];
|
|
513
556
|
}
|
|
@@ -528,7 +571,8 @@
|
|
|
528
571
|
rootSchema,
|
|
529
572
|
expandAllBranches,
|
|
530
573
|
recurseList,
|
|
531
|
-
rawFormData
|
|
574
|
+
rawFormData,
|
|
575
|
+
experimental_customMergeAllOf
|
|
532
576
|
);
|
|
533
577
|
}
|
|
534
578
|
if (ALL_OF_KEY in resolvedSchema) {
|
|
@@ -549,7 +593,7 @@
|
|
|
549
593
|
if (withContainsSchemas.length) {
|
|
550
594
|
resolvedSchema = { ...resolvedSchema, allOf: withoutContainsSchemas };
|
|
551
595
|
}
|
|
552
|
-
resolvedSchema = mergeAllOf(resolvedSchema, {
|
|
596
|
+
resolvedSchema = experimental_customMergeAllOf ? experimental_customMergeAllOf(resolvedSchema) : mergeAllOf(resolvedSchema, {
|
|
553
597
|
deep: false
|
|
554
598
|
});
|
|
555
599
|
if (withContainsSchemas.length) {
|
|
@@ -590,7 +634,7 @@
|
|
|
590
634
|
}
|
|
591
635
|
return [schema];
|
|
592
636
|
}
|
|
593
|
-
function resolveDependencies(validator, schema, rootSchema, expandAllBranches, recurseList, formData) {
|
|
637
|
+
function resolveDependencies(validator, schema, rootSchema, expandAllBranches, recurseList, formData, experimental_customMergeAllOf) {
|
|
594
638
|
const { dependencies, ...remainingSchema } = schema;
|
|
595
639
|
const resolvedSchemas = resolveAnyOrOneOfSchemas(
|
|
596
640
|
validator,
|
|
@@ -607,11 +651,12 @@
|
|
|
607
651
|
rootSchema,
|
|
608
652
|
expandAllBranches,
|
|
609
653
|
recurseList,
|
|
610
|
-
formData
|
|
654
|
+
formData,
|
|
655
|
+
experimental_customMergeAllOf
|
|
611
656
|
)
|
|
612
657
|
);
|
|
613
658
|
}
|
|
614
|
-
function processDependencies(validator, dependencies, resolvedSchema, rootSchema, expandAllBranches, recurseList, formData) {
|
|
659
|
+
function processDependencies(validator, dependencies, resolvedSchema, rootSchema, expandAllBranches, recurseList, formData, experimental_customMergeAllOf) {
|
|
615
660
|
let schemas = [resolvedSchema];
|
|
616
661
|
for (const dependencyKey in dependencies) {
|
|
617
662
|
if (!expandAllBranches && get8(formData, [dependencyKey]) === void 0) {
|
|
@@ -635,7 +680,8 @@
|
|
|
635
680
|
dependencyValue,
|
|
636
681
|
expandAllBranches,
|
|
637
682
|
recurseList,
|
|
638
|
-
formData
|
|
683
|
+
formData,
|
|
684
|
+
experimental_customMergeAllOf
|
|
639
685
|
);
|
|
640
686
|
}
|
|
641
687
|
return schemas.flatMap(
|
|
@@ -646,7 +692,8 @@
|
|
|
646
692
|
rootSchema,
|
|
647
693
|
expandAllBranches,
|
|
648
694
|
recurseList,
|
|
649
|
-
formData
|
|
695
|
+
formData,
|
|
696
|
+
experimental_customMergeAllOf
|
|
650
697
|
)
|
|
651
698
|
);
|
|
652
699
|
}
|
|
@@ -659,14 +706,15 @@
|
|
|
659
706
|
const required = Array.isArray(schema.required) ? Array.from(/* @__PURE__ */ new Set([...schema.required, ...additionallyRequired])) : additionallyRequired;
|
|
660
707
|
return { ...schema, required };
|
|
661
708
|
}
|
|
662
|
-
function withDependentSchema(validator, schema, rootSchema, dependencyKey, dependencyValue, expandAllBranches, recurseList, formData) {
|
|
709
|
+
function withDependentSchema(validator, schema, rootSchema, dependencyKey, dependencyValue, expandAllBranches, recurseList, formData, experimental_customMergeAllOf) {
|
|
663
710
|
const dependentSchemas = retrieveSchemaInternal(
|
|
664
711
|
validator,
|
|
665
712
|
dependencyValue,
|
|
666
713
|
rootSchema,
|
|
667
714
|
formData,
|
|
668
715
|
expandAllBranches,
|
|
669
|
-
recurseList
|
|
716
|
+
recurseList,
|
|
717
|
+
experimental_customMergeAllOf
|
|
670
718
|
);
|
|
671
719
|
return dependentSchemas.flatMap((dependent) => {
|
|
672
720
|
const { oneOf, ...dependentSchema } = dependent;
|
|
@@ -690,12 +738,13 @@
|
|
|
690
738
|
resolvedOneOf,
|
|
691
739
|
expandAllBranches,
|
|
692
740
|
recurseList,
|
|
693
|
-
formData
|
|
741
|
+
formData,
|
|
742
|
+
experimental_customMergeAllOf
|
|
694
743
|
)
|
|
695
744
|
);
|
|
696
745
|
});
|
|
697
746
|
}
|
|
698
|
-
function withExactlyOneSubschema(validator, schema, rootSchema, dependencyKey, oneOf, expandAllBranches, recurseList, formData) {
|
|
747
|
+
function withExactlyOneSubschema(validator, schema, rootSchema, dependencyKey, oneOf, expandAllBranches, recurseList, formData, experimental_customMergeAllOf) {
|
|
699
748
|
const validSubschemas = oneOf.filter((subschema) => {
|
|
700
749
|
if (typeof subschema === "boolean" || !subschema || !subschema.properties) {
|
|
701
750
|
return false;
|
|
@@ -726,7 +775,8 @@
|
|
|
726
775
|
rootSchema,
|
|
727
776
|
formData,
|
|
728
777
|
expandAllBranches,
|
|
729
|
-
recurseList
|
|
778
|
+
recurseList,
|
|
779
|
+
experimental_customMergeAllOf
|
|
730
780
|
);
|
|
731
781
|
return schemas.map((s2) => mergeSchemas(schema, s2));
|
|
732
782
|
});
|
|
@@ -742,7 +792,7 @@
|
|
|
742
792
|
}
|
|
743
793
|
}
|
|
744
794
|
};
|
|
745
|
-
function calculateIndexScore(validator, rootSchema, schema, formData
|
|
795
|
+
function calculateIndexScore(validator, rootSchema, schema, formData) {
|
|
746
796
|
let totalScore = 0;
|
|
747
797
|
if (schema) {
|
|
748
798
|
if (isObject2(schema.properties)) {
|
|
@@ -770,7 +820,10 @@
|
|
|
770
820
|
);
|
|
771
821
|
}
|
|
772
822
|
if (value.type === "object") {
|
|
773
|
-
|
|
823
|
+
if (isObject2(formValue)) {
|
|
824
|
+
score += 1;
|
|
825
|
+
}
|
|
826
|
+
return score + calculateIndexScore(validator, rootSchema, value, formValue);
|
|
774
827
|
}
|
|
775
828
|
if (value.type === guessType(formValue)) {
|
|
776
829
|
let newScore = score + 1;
|
|
@@ -837,12 +890,17 @@
|
|
|
837
890
|
function isFixedItems(schema) {
|
|
838
891
|
return Array.isArray(schema.items) && schema.items.length > 0 && schema.items.every((item) => isObject(item));
|
|
839
892
|
}
|
|
840
|
-
function mergeDefaultsWithFormData(defaults, formData, mergeExtraArrayDefaults = false) {
|
|
893
|
+
function mergeDefaultsWithFormData(defaults, formData, mergeExtraArrayDefaults = false, defaultSupercedesUndefined = false) {
|
|
841
894
|
if (Array.isArray(formData)) {
|
|
842
895
|
const defaultsArray = Array.isArray(defaults) ? defaults : [];
|
|
843
896
|
const mapped = formData.map((value, idx) => {
|
|
844
897
|
if (defaultsArray[idx]) {
|
|
845
|
-
return mergeDefaultsWithFormData(
|
|
898
|
+
return mergeDefaultsWithFormData(
|
|
899
|
+
defaultsArray[idx],
|
|
900
|
+
value,
|
|
901
|
+
mergeExtraArrayDefaults,
|
|
902
|
+
defaultSupercedesUndefined
|
|
903
|
+
);
|
|
846
904
|
}
|
|
847
905
|
return value;
|
|
848
906
|
});
|
|
@@ -857,11 +915,15 @@
|
|
|
857
915
|
acc2[key] = mergeDefaultsWithFormData(
|
|
858
916
|
defaults ? get8(defaults, key) : {},
|
|
859
917
|
get8(formData, key),
|
|
860
|
-
mergeExtraArrayDefaults
|
|
918
|
+
mergeExtraArrayDefaults,
|
|
919
|
+
defaultSupercedesUndefined
|
|
861
920
|
);
|
|
862
921
|
return acc2;
|
|
863
922
|
}, acc);
|
|
864
923
|
}
|
|
924
|
+
if (defaultSupercedesUndefined && formData === void 0) {
|
|
925
|
+
return defaults;
|
|
926
|
+
}
|
|
865
927
|
return formData;
|
|
866
928
|
}
|
|
867
929
|
|
|
@@ -932,9 +994,9 @@
|
|
|
932
994
|
}
|
|
933
995
|
return {};
|
|
934
996
|
}
|
|
935
|
-
function maybeAddDefaultToObject(obj, key, computedDefault, includeUndefinedValues, isParentRequired, requiredFields = [], experimental_defaultFormStateBehavior = {}) {
|
|
997
|
+
function maybeAddDefaultToObject(obj, key, computedDefault, includeUndefinedValues, isParentRequired, requiredFields = [], experimental_defaultFormStateBehavior = {}, isConst = false) {
|
|
936
998
|
const { emptyObjectFields = "populateAllDefaults" } = experimental_defaultFormStateBehavior;
|
|
937
|
-
if (includeUndefinedValues) {
|
|
999
|
+
if (includeUndefinedValues || isConst) {
|
|
938
1000
|
obj[key] = computedDefault;
|
|
939
1001
|
} else if (emptyObjectFields !== "skipDefaults") {
|
|
940
1002
|
if (isObject(computedDefault)) {
|
|
@@ -964,6 +1026,7 @@
|
|
|
964
1026
|
includeUndefinedValues = false,
|
|
965
1027
|
_recurseList = [],
|
|
966
1028
|
experimental_defaultFormStateBehavior = void 0,
|
|
1029
|
+
experimental_customMergeAllOf = void 0,
|
|
967
1030
|
required
|
|
968
1031
|
} = computeDefaultsProps;
|
|
969
1032
|
const formData = isObject(rawFormData) ? rawFormData : {};
|
|
@@ -971,7 +1034,9 @@
|
|
|
971
1034
|
let defaults = parentDefaults;
|
|
972
1035
|
let schemaToCompute = null;
|
|
973
1036
|
let updatedRecurseList = _recurseList;
|
|
974
|
-
if (
|
|
1037
|
+
if (isConstant(schema)) {
|
|
1038
|
+
defaults = schema.const;
|
|
1039
|
+
} else if (isObject(defaults) && isObject(schema.default)) {
|
|
975
1040
|
defaults = mergeObjects(defaults, schema.default);
|
|
976
1041
|
} else if (DEFAULT_KEY in schema) {
|
|
977
1042
|
defaults = schema.default;
|
|
@@ -986,7 +1051,15 @@
|
|
|
986
1051
|
...formData,
|
|
987
1052
|
...getDefaultBasedOnSchemaType(validator, schema, computeDefaultsProps, defaults)
|
|
988
1053
|
};
|
|
989
|
-
const resolvedSchema = resolveDependencies(
|
|
1054
|
+
const resolvedSchema = resolveDependencies(
|
|
1055
|
+
validator,
|
|
1056
|
+
schema,
|
|
1057
|
+
rootSchema,
|
|
1058
|
+
false,
|
|
1059
|
+
[],
|
|
1060
|
+
defaultFormData,
|
|
1061
|
+
experimental_customMergeAllOf
|
|
1062
|
+
);
|
|
990
1063
|
schemaToCompute = resolvedSchema[0];
|
|
991
1064
|
} else if (isFixedItems(schema)) {
|
|
992
1065
|
defaults = schema.items.map(
|
|
@@ -1054,18 +1127,24 @@
|
|
|
1054
1127
|
includeUndefinedValues = false,
|
|
1055
1128
|
_recurseList = [],
|
|
1056
1129
|
experimental_defaultFormStateBehavior = void 0,
|
|
1130
|
+
experimental_customMergeAllOf = void 0,
|
|
1057
1131
|
required
|
|
1058
1132
|
} = {}, defaults) {
|
|
1059
1133
|
{
|
|
1060
1134
|
const formData = isObject(rawFormData) ? rawFormData : {};
|
|
1061
1135
|
const schema = rawSchema;
|
|
1062
|
-
const retrievedSchema = experimental_defaultFormStateBehavior?.allOf === "populateDefaults" && ALL_OF_KEY in schema ? retrieveSchema(validator, schema, rootSchema, formData) : schema;
|
|
1136
|
+
const retrievedSchema = experimental_defaultFormStateBehavior?.allOf === "populateDefaults" && ALL_OF_KEY in schema ? retrieveSchema(validator, schema, rootSchema, formData, experimental_customMergeAllOf) : schema;
|
|
1137
|
+
const parentConst = retrievedSchema[CONST_KEY];
|
|
1063
1138
|
const objectDefaults = Object.keys(retrievedSchema.properties || {}).reduce(
|
|
1064
1139
|
(acc, key) => {
|
|
1065
|
-
const
|
|
1140
|
+
const propertySchema = get8(retrievedSchema, [PROPERTIES_KEY, key]);
|
|
1141
|
+
const hasParentConst = isObject(parentConst) && parentConst[key] !== void 0;
|
|
1142
|
+
const hasConst = isObject(propertySchema) && CONST_KEY in propertySchema || hasParentConst;
|
|
1143
|
+
const computedDefault = computeDefaults(validator, propertySchema, {
|
|
1066
1144
|
rootSchema,
|
|
1067
1145
|
_recurseList,
|
|
1068
1146
|
experimental_defaultFormStateBehavior,
|
|
1147
|
+
experimental_customMergeAllOf,
|
|
1069
1148
|
includeUndefinedValues: includeUndefinedValues === true,
|
|
1070
1149
|
parentDefaults: get8(defaults, [key]),
|
|
1071
1150
|
rawFormData: get8(formData, [key]),
|
|
@@ -1078,7 +1157,8 @@
|
|
|
1078
1157
|
includeUndefinedValues,
|
|
1079
1158
|
required,
|
|
1080
1159
|
retrievedSchema.required,
|
|
1081
|
-
experimental_defaultFormStateBehavior
|
|
1160
|
+
experimental_defaultFormStateBehavior,
|
|
1161
|
+
hasConst
|
|
1082
1162
|
);
|
|
1083
1163
|
return acc;
|
|
1084
1164
|
},
|
|
@@ -1160,11 +1240,14 @@
|
|
|
1160
1240
|
});
|
|
1161
1241
|
}
|
|
1162
1242
|
}
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1243
|
+
const hasConst = isObject(schema) && CONST_KEY in schema;
|
|
1244
|
+
if (hasConst === false) {
|
|
1245
|
+
if (neverPopulate) {
|
|
1246
|
+
return defaults ?? emptyDefault;
|
|
1247
|
+
}
|
|
1248
|
+
if (ignoreMinItemsFlagSet && !required) {
|
|
1249
|
+
return defaults ? defaults : void 0;
|
|
1250
|
+
}
|
|
1168
1251
|
}
|
|
1169
1252
|
const defaultsLength = Array.isArray(defaults) ? defaults.length : 0;
|
|
1170
1253
|
if (!schema.minItems || isMultiSelect(validator, schema, rootSchema) || computeSkipPopulate(validator, schema, rootSchema) || schema.minItems <= defaultsLength) {
|
|
@@ -1194,26 +1277,29 @@
|
|
|
1194
1277
|
}
|
|
1195
1278
|
}
|
|
1196
1279
|
}
|
|
1197
|
-
function getDefaultFormState(validator, theSchema, formData, rootSchema, includeUndefinedValues = false, experimental_defaultFormStateBehavior) {
|
|
1280
|
+
function getDefaultFormState(validator, theSchema, formData, rootSchema, includeUndefinedValues = false, experimental_defaultFormStateBehavior, experimental_customMergeAllOf) {
|
|
1198
1281
|
if (!isObject(theSchema)) {
|
|
1199
1282
|
throw new Error("Invalid schema: " + theSchema);
|
|
1200
1283
|
}
|
|
1201
|
-
const schema = retrieveSchema(validator, theSchema, rootSchema, formData);
|
|
1284
|
+
const schema = retrieveSchema(validator, theSchema, rootSchema, formData, experimental_customMergeAllOf);
|
|
1202
1285
|
const defaults = computeDefaults(validator, schema, {
|
|
1203
1286
|
rootSchema,
|
|
1204
1287
|
includeUndefinedValues,
|
|
1205
1288
|
experimental_defaultFormStateBehavior,
|
|
1289
|
+
experimental_customMergeAllOf,
|
|
1206
1290
|
rawFormData: formData
|
|
1207
1291
|
});
|
|
1208
1292
|
if (formData === void 0 || formData === null || typeof formData === "number" && isNaN(formData)) {
|
|
1209
1293
|
return defaults;
|
|
1210
1294
|
}
|
|
1211
|
-
const {
|
|
1295
|
+
const { mergeDefaultsIntoFormData, arrayMinItems = {} } = experimental_defaultFormStateBehavior || {};
|
|
1296
|
+
const { mergeExtraDefaults } = arrayMinItems;
|
|
1297
|
+
const defaultSupercedesUndefined = mergeDefaultsIntoFormData === "useDefaultIfFormDataUndefined";
|
|
1212
1298
|
if (isObject(formData)) {
|
|
1213
|
-
return mergeDefaultsWithFormData(defaults, formData, mergeExtraDefaults);
|
|
1299
|
+
return mergeDefaultsWithFormData(defaults, formData, mergeExtraDefaults, defaultSupercedesUndefined);
|
|
1214
1300
|
}
|
|
1215
1301
|
if (Array.isArray(formData)) {
|
|
1216
|
-
return mergeDefaultsWithFormData(defaults, formData, mergeExtraDefaults);
|
|
1302
|
+
return mergeDefaultsWithFormData(defaults, formData, mergeExtraDefaults, defaultSupercedesUndefined);
|
|
1217
1303
|
}
|
|
1218
1304
|
return formData;
|
|
1219
1305
|
}
|
|
@@ -1375,7 +1461,7 @@
|
|
|
1375
1461
|
}
|
|
1376
1462
|
return newFormData;
|
|
1377
1463
|
}
|
|
1378
|
-
function toIdSchemaInternal(validator, schema, idPrefix, idSeparator, id, rootSchema, formData, _recurseList = []) {
|
|
1464
|
+
function toIdSchemaInternal(validator, schema, idPrefix, idSeparator, id, rootSchema, formData, _recurseList = [], experimental_customMergeAllOf) {
|
|
1379
1465
|
if (REF_KEY in schema || DEPENDENCIES_KEY in schema || ALL_OF_KEY in schema) {
|
|
1380
1466
|
const _schema = retrieveSchema(validator, schema, rootSchema, formData);
|
|
1381
1467
|
const sameSchemaIndex = _recurseList.findIndex((item) => isEqual4(item, _schema));
|
|
@@ -1388,8 +1474,7 @@
|
|
|
1388
1474
|
id,
|
|
1389
1475
|
rootSchema,
|
|
1390
1476
|
formData,
|
|
1391
|
-
_recurseList.concat(_schema)
|
|
1392
|
-
);
|
|
1477
|
+
_recurseList.concat(_schema));
|
|
1393
1478
|
}
|
|
1394
1479
|
}
|
|
1395
1480
|
if (ITEMS_KEY in schema && !get8(schema, [ITEMS_KEY, REF_KEY])) {
|
|
@@ -1401,8 +1486,7 @@
|
|
|
1401
1486
|
id,
|
|
1402
1487
|
rootSchema,
|
|
1403
1488
|
formData,
|
|
1404
|
-
_recurseList
|
|
1405
|
-
);
|
|
1489
|
+
_recurseList);
|
|
1406
1490
|
}
|
|
1407
1491
|
const $id = id || idPrefix;
|
|
1408
1492
|
const idSchema = { $id };
|
|
@@ -1420,14 +1504,21 @@
|
|
|
1420
1504
|
// It's possible that formData is not an object -- this can happen if an
|
|
1421
1505
|
// array item has just been added, but not populated with data yet
|
|
1422
1506
|
get8(formData, [name]),
|
|
1423
|
-
_recurseList
|
|
1424
|
-
);
|
|
1507
|
+
_recurseList);
|
|
1425
1508
|
}
|
|
1426
1509
|
}
|
|
1427
1510
|
return idSchema;
|
|
1428
1511
|
}
|
|
1429
|
-
function toIdSchema(validator, schema, id, rootSchema, formData, idPrefix = "root", idSeparator = "_") {
|
|
1430
|
-
return toIdSchemaInternal(
|
|
1512
|
+
function toIdSchema(validator, schema, id, rootSchema, formData, idPrefix = "root", idSeparator = "_", experimental_customMergeAllOf) {
|
|
1513
|
+
return toIdSchemaInternal(
|
|
1514
|
+
validator,
|
|
1515
|
+
schema,
|
|
1516
|
+
idPrefix,
|
|
1517
|
+
idSeparator,
|
|
1518
|
+
id,
|
|
1519
|
+
rootSchema,
|
|
1520
|
+
formData,
|
|
1521
|
+
void 0);
|
|
1431
1522
|
}
|
|
1432
1523
|
function toPathSchemaInternal(validator, schema, name, rootSchema, formData, _recurseList = []) {
|
|
1433
1524
|
if (REF_KEY in schema || DEPENDENCIES_KEY in schema || ALL_OF_KEY in schema) {
|
|
@@ -1526,11 +1617,13 @@
|
|
|
1526
1617
|
* @param validator - An implementation of the `ValidatorType` interface that will be forwarded to all the APIs
|
|
1527
1618
|
* @param rootSchema - The root schema that will be forwarded to all the APIs
|
|
1528
1619
|
* @param experimental_defaultFormStateBehavior - Configuration flags to allow users to override default form state behavior
|
|
1620
|
+
* @param [experimental_customMergeAllOf] - Optional function that allows for custom merging of `allOf` schemas
|
|
1529
1621
|
*/
|
|
1530
|
-
constructor(validator, rootSchema, experimental_defaultFormStateBehavior) {
|
|
1622
|
+
constructor(validator, rootSchema, experimental_defaultFormStateBehavior, experimental_customMergeAllOf) {
|
|
1531
1623
|
this.rootSchema = rootSchema;
|
|
1532
1624
|
this.validator = validator;
|
|
1533
1625
|
this.experimental_defaultFormStateBehavior = experimental_defaultFormStateBehavior;
|
|
1626
|
+
this.experimental_customMergeAllOf = experimental_customMergeAllOf;
|
|
1534
1627
|
}
|
|
1535
1628
|
/** Returns the `ValidatorType` in the `SchemaUtilsType`
|
|
1536
1629
|
*
|
|
@@ -1546,13 +1639,14 @@
|
|
|
1546
1639
|
* @param validator - An implementation of the `ValidatorType` interface that will be compared against the current one
|
|
1547
1640
|
* @param rootSchema - The root schema that will be compared against the current one
|
|
1548
1641
|
* @param [experimental_defaultFormStateBehavior] Optional configuration object, if provided, allows users to override default form state behavior
|
|
1642
|
+
* @param [experimental_customMergeAllOf] - Optional function that allows for custom merging of `allOf` schemas
|
|
1549
1643
|
* @returns - True if the `SchemaUtilsType` differs from the given `validator` or `rootSchema`
|
|
1550
1644
|
*/
|
|
1551
|
-
doesSchemaUtilsDiffer(validator, rootSchema, experimental_defaultFormStateBehavior = {}) {
|
|
1645
|
+
doesSchemaUtilsDiffer(validator, rootSchema, experimental_defaultFormStateBehavior = {}, experimental_customMergeAllOf) {
|
|
1552
1646
|
if (!validator || !rootSchema) {
|
|
1553
1647
|
return false;
|
|
1554
1648
|
}
|
|
1555
|
-
return this.validator !== validator || !deepEquals(this.rootSchema, rootSchema) || !deepEquals(this.experimental_defaultFormStateBehavior, experimental_defaultFormStateBehavior);
|
|
1649
|
+
return this.validator !== validator || !deepEquals(this.rootSchema, rootSchema) || !deepEquals(this.experimental_defaultFormStateBehavior, experimental_defaultFormStateBehavior) || this.experimental_customMergeAllOf !== experimental_customMergeAllOf;
|
|
1556
1650
|
}
|
|
1557
1651
|
/** Returns the superset of `formData` that includes the given set updated to include any missing fields that have
|
|
1558
1652
|
* computed to have defaults provided in the `schema`.
|
|
@@ -1571,7 +1665,8 @@
|
|
|
1571
1665
|
formData,
|
|
1572
1666
|
this.rootSchema,
|
|
1573
1667
|
includeUndefinedValues,
|
|
1574
|
-
this.experimental_defaultFormStateBehavior
|
|
1668
|
+
this.experimental_defaultFormStateBehavior,
|
|
1669
|
+
this.experimental_customMergeAllOf
|
|
1575
1670
|
);
|
|
1576
1671
|
}
|
|
1577
1672
|
/** Determines whether the combination of `schema` and `uiSchema` properties indicates that the label for the `schema`
|
|
@@ -1681,7 +1776,13 @@
|
|
|
1681
1776
|
* @returns - The schema having its conditions, additional properties, references and dependencies resolved
|
|
1682
1777
|
*/
|
|
1683
1778
|
retrieveSchema(schema, rawFormData) {
|
|
1684
|
-
return retrieveSchema(
|
|
1779
|
+
return retrieveSchema(
|
|
1780
|
+
this.validator,
|
|
1781
|
+
schema,
|
|
1782
|
+
this.rootSchema,
|
|
1783
|
+
rawFormData,
|
|
1784
|
+
this.experimental_customMergeAllOf
|
|
1785
|
+
);
|
|
1685
1786
|
}
|
|
1686
1787
|
/** Sanitize the `data` associated with the `oldSchema` so it is considered appropriate for the `newSchema`. If the
|
|
1687
1788
|
* new schema does not contain any properties, then `undefined` is returned to clear all the form data. Due to the
|
|
@@ -1707,7 +1808,16 @@
|
|
|
1707
1808
|
* @returns - The `IdSchema` object for the `schema`
|
|
1708
1809
|
*/
|
|
1709
1810
|
toIdSchema(schema, id, formData, idPrefix = "root", idSeparator = "_") {
|
|
1710
|
-
return toIdSchema(
|
|
1811
|
+
return toIdSchema(
|
|
1812
|
+
this.validator,
|
|
1813
|
+
schema,
|
|
1814
|
+
id,
|
|
1815
|
+
this.rootSchema,
|
|
1816
|
+
formData,
|
|
1817
|
+
idPrefix,
|
|
1818
|
+
idSeparator,
|
|
1819
|
+
this.experimental_customMergeAllOf
|
|
1820
|
+
);
|
|
1711
1821
|
}
|
|
1712
1822
|
/** Generates an `PathSchema` object for the `schema`, recursively
|
|
1713
1823
|
*
|
|
@@ -1720,8 +1830,13 @@
|
|
|
1720
1830
|
return toPathSchema(this.validator, schema, name, this.rootSchema, formData);
|
|
1721
1831
|
}
|
|
1722
1832
|
};
|
|
1723
|
-
function createSchemaUtils(validator, rootSchema, experimental_defaultFormStateBehavior = {}) {
|
|
1724
|
-
return new SchemaUtils(
|
|
1833
|
+
function createSchemaUtils(validator, rootSchema, experimental_defaultFormStateBehavior = {}, experimental_customMergeAllOf) {
|
|
1834
|
+
return new SchemaUtils(
|
|
1835
|
+
validator,
|
|
1836
|
+
rootSchema,
|
|
1837
|
+
experimental_defaultFormStateBehavior,
|
|
1838
|
+
experimental_customMergeAllOf
|
|
1839
|
+
);
|
|
1725
1840
|
}
|
|
1726
1841
|
|
|
1727
1842
|
// src/dataURItoBlob.ts
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { FormContextType, RJSFSchema, SchemaUtilsType, StrictRJSFSchema, ValidatorType } from './types';
|
|
1
|
+
import { Experimental_CustomMergeAllOf, FormContextType, RJSFSchema, SchemaUtilsType, StrictRJSFSchema, ValidatorType } from './types';
|
|
2
2
|
/** Creates a `SchemaUtilsType` interface that is based around the given `validator` and `rootSchema` parameters. The
|
|
3
3
|
* resulting interface implementation will forward the `validator` and `rootSchema` to all the wrapped APIs.
|
|
4
4
|
*
|
|
5
5
|
* @param validator - an implementation of the `ValidatorType` interface that will be forwarded to all the APIs
|
|
6
6
|
* @param rootSchema - The root schema that will be forwarded to all the APIs
|
|
7
7
|
* @param [experimental_defaultFormStateBehavior] Optional configuration object, if provided, allows users to override default form state behavior
|
|
8
|
+
* @param [experimental_customMergeAllOf] - Optional function that allows for custom merging of `allOf` schemas
|
|
8
9
|
* @returns - An implementation of a `SchemaUtilsType` interface
|
|
9
10
|
*/
|
|
10
|
-
export default function createSchemaUtils<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(validator: ValidatorType<T, S, F>, rootSchema: S, experimental_defaultFormStateBehavior?: {}): SchemaUtilsType<T, S, F>;
|
|
11
|
+
export default function createSchemaUtils<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(validator: ValidatorType<T, S, F>, rootSchema: S, experimental_defaultFormStateBehavior?: {}, experimental_customMergeAllOf?: Experimental_CustomMergeAllOf<S>): SchemaUtilsType<T, S, F>;
|