@rjsf/utils 5.21.1 → 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 +201 -62
- package/dist/index.js.map +3 -3
- package/dist/utils.esm.js +201 -62
- package/dist/utils.esm.js.map +2 -2
- package/dist/utils.umd.js +199 -69
- package/lib/ErrorSchemaBuilder.d.ts +3 -3
- package/lib/ErrorSchemaBuilder.js +2 -1
- package/lib/ErrorSchemaBuilder.js.map +1 -1
- 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 +54 -26
- 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/ErrorSchemaBuilder.ts +6 -5
- 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 +125 -28
- package/src/schema/toIdSchema.ts +32 -7
- package/src/types.ts +20 -2
package/dist/utils.esm.js
CHANGED
|
@@ -367,10 +367,18 @@ function mergeSchemas(obj1, obj2) {
|
|
|
367
367
|
}
|
|
368
368
|
|
|
369
369
|
// src/schema/retrieveSchema.ts
|
|
370
|
-
function retrieveSchema(validator, schema, rootSchema = {}, rawFormData) {
|
|
371
|
-
return retrieveSchemaInternal(
|
|
370
|
+
function retrieveSchema(validator, schema, rootSchema = {}, rawFormData, experimental_customMergeAllOf) {
|
|
371
|
+
return retrieveSchemaInternal(
|
|
372
|
+
validator,
|
|
373
|
+
schema,
|
|
374
|
+
rootSchema,
|
|
375
|
+
rawFormData,
|
|
376
|
+
void 0,
|
|
377
|
+
void 0,
|
|
378
|
+
experimental_customMergeAllOf
|
|
379
|
+
)[0];
|
|
372
380
|
}
|
|
373
|
-
function resolveCondition(validator, schema, rootSchema, expandAllBranches, recurseList, formData) {
|
|
381
|
+
function resolveCondition(validator, schema, rootSchema, expandAllBranches, recurseList, formData, experimental_customMergeAllOf) {
|
|
374
382
|
const { if: expression, then, else: otherwise, ...resolvedSchemaLessConditional } = schema;
|
|
375
383
|
const conditionValue = validator.isValid(expression, formData || {}, rootSchema);
|
|
376
384
|
let resolvedSchemas = [resolvedSchemaLessConditional];
|
|
@@ -378,12 +386,28 @@ function resolveCondition(validator, schema, rootSchema, expandAllBranches, recu
|
|
|
378
386
|
if (expandAllBranches) {
|
|
379
387
|
if (then && typeof then !== "boolean") {
|
|
380
388
|
schemas = schemas.concat(
|
|
381
|
-
retrieveSchemaInternal(
|
|
389
|
+
retrieveSchemaInternal(
|
|
390
|
+
validator,
|
|
391
|
+
then,
|
|
392
|
+
rootSchema,
|
|
393
|
+
formData,
|
|
394
|
+
expandAllBranches,
|
|
395
|
+
recurseList,
|
|
396
|
+
experimental_customMergeAllOf
|
|
397
|
+
)
|
|
382
398
|
);
|
|
383
399
|
}
|
|
384
400
|
if (otherwise && typeof otherwise !== "boolean") {
|
|
385
401
|
schemas = schemas.concat(
|
|
386
|
-
retrieveSchemaInternal(
|
|
402
|
+
retrieveSchemaInternal(
|
|
403
|
+
validator,
|
|
404
|
+
otherwise,
|
|
405
|
+
rootSchema,
|
|
406
|
+
formData,
|
|
407
|
+
expandAllBranches,
|
|
408
|
+
recurseList,
|
|
409
|
+
experimental_customMergeAllOf
|
|
410
|
+
)
|
|
387
411
|
);
|
|
388
412
|
}
|
|
389
413
|
} else {
|
|
@@ -396,7 +420,8 @@ function resolveCondition(validator, schema, rootSchema, expandAllBranches, recu
|
|
|
396
420
|
rootSchema,
|
|
397
421
|
formData,
|
|
398
422
|
expandAllBranches,
|
|
399
|
-
recurseList
|
|
423
|
+
recurseList,
|
|
424
|
+
experimental_customMergeAllOf
|
|
400
425
|
)
|
|
401
426
|
);
|
|
402
427
|
}
|
|
@@ -405,7 +430,15 @@ function resolveCondition(validator, schema, rootSchema, expandAllBranches, recu
|
|
|
405
430
|
resolvedSchemas = schemas.map((s) => mergeSchemas(resolvedSchemaLessConditional, s));
|
|
406
431
|
}
|
|
407
432
|
return resolvedSchemas.flatMap(
|
|
408
|
-
(s) => retrieveSchemaInternal(
|
|
433
|
+
(s) => retrieveSchemaInternal(
|
|
434
|
+
validator,
|
|
435
|
+
s,
|
|
436
|
+
rootSchema,
|
|
437
|
+
formData,
|
|
438
|
+
expandAllBranches,
|
|
439
|
+
recurseList,
|
|
440
|
+
experimental_customMergeAllOf
|
|
441
|
+
)
|
|
409
442
|
);
|
|
410
443
|
}
|
|
411
444
|
function getAllPermutationsOfXxxOf(listOfLists) {
|
|
@@ -422,7 +455,7 @@ function getAllPermutationsOfXxxOf(listOfLists) {
|
|
|
422
455
|
);
|
|
423
456
|
return allPermutations;
|
|
424
457
|
}
|
|
425
|
-
function resolveSchema(validator, schema, rootSchema, expandAllBranches, recurseList, formData) {
|
|
458
|
+
function resolveSchema(validator, schema, rootSchema, expandAllBranches, recurseList, formData, experimental_customMergeAllOf) {
|
|
426
459
|
const updatedSchemas = resolveReference(
|
|
427
460
|
validator,
|
|
428
461
|
schema,
|
|
@@ -444,7 +477,15 @@ function resolveSchema(validator, schema, rootSchema, expandAllBranches, recurse
|
|
|
444
477
|
formData
|
|
445
478
|
);
|
|
446
479
|
return resolvedSchemas.flatMap((s) => {
|
|
447
|
-
return retrieveSchemaInternal(
|
|
480
|
+
return retrieveSchemaInternal(
|
|
481
|
+
validator,
|
|
482
|
+
s,
|
|
483
|
+
rootSchema,
|
|
484
|
+
formData,
|
|
485
|
+
expandAllBranches,
|
|
486
|
+
recurseList,
|
|
487
|
+
experimental_customMergeAllOf
|
|
488
|
+
);
|
|
448
489
|
});
|
|
449
490
|
}
|
|
450
491
|
if (ALL_OF_KEY in schema && Array.isArray(schema.allOf)) {
|
|
@@ -455,7 +496,8 @@ function resolveSchema(validator, schema, rootSchema, expandAllBranches, recurse
|
|
|
455
496
|
rootSchema,
|
|
456
497
|
formData,
|
|
457
498
|
expandAllBranches,
|
|
458
|
-
recurseList
|
|
499
|
+
recurseList,
|
|
500
|
+
experimental_customMergeAllOf
|
|
459
501
|
)
|
|
460
502
|
);
|
|
461
503
|
const allPermutations = getAllPermutationsOfXxxOf(allOfSchemaElements);
|
|
@@ -463,7 +505,7 @@ function resolveSchema(validator, schema, rootSchema, expandAllBranches, recurse
|
|
|
463
505
|
}
|
|
464
506
|
return [schema];
|
|
465
507
|
}
|
|
466
|
-
function resolveReference(validator, schema, rootSchema, expandAllBranches, recurseList, formData) {
|
|
508
|
+
function resolveReference(validator, schema, rootSchema, expandAllBranches, recurseList, formData, experimental_customMergeAllOf) {
|
|
467
509
|
const updatedSchema = resolveAllReferences(schema, rootSchema, recurseList);
|
|
468
510
|
if (updatedSchema !== schema) {
|
|
469
511
|
return retrieveSchemaInternal(
|
|
@@ -472,7 +514,8 @@ function resolveReference(validator, schema, rootSchema, expandAllBranches, recu
|
|
|
472
514
|
rootSchema,
|
|
473
515
|
formData,
|
|
474
516
|
expandAllBranches,
|
|
475
|
-
recurseList
|
|
517
|
+
recurseList,
|
|
518
|
+
experimental_customMergeAllOf
|
|
476
519
|
);
|
|
477
520
|
}
|
|
478
521
|
return [schema];
|
|
@@ -550,7 +593,7 @@ function stubExistingAdditionalProperties(validator, theSchema, rootSchema, aFor
|
|
|
550
593
|
});
|
|
551
594
|
return schema;
|
|
552
595
|
}
|
|
553
|
-
function retrieveSchemaInternal(validator, schema, rootSchema, rawFormData, expandAllBranches = false, recurseList = []) {
|
|
596
|
+
function retrieveSchemaInternal(validator, schema, rootSchema, rawFormData, expandAllBranches = false, recurseList = [], experimental_customMergeAllOf) {
|
|
554
597
|
if (!isObject(schema)) {
|
|
555
598
|
return [{}];
|
|
556
599
|
}
|
|
@@ -571,7 +614,8 @@ function retrieveSchemaInternal(validator, schema, rootSchema, rawFormData, expa
|
|
|
571
614
|
rootSchema,
|
|
572
615
|
expandAllBranches,
|
|
573
616
|
recurseList,
|
|
574
|
-
rawFormData
|
|
617
|
+
rawFormData,
|
|
618
|
+
experimental_customMergeAllOf
|
|
575
619
|
);
|
|
576
620
|
}
|
|
577
621
|
if (ALL_OF_KEY in resolvedSchema) {
|
|
@@ -580,9 +624,24 @@ function retrieveSchemaInternal(validator, schema, rootSchema, rawFormData, expa
|
|
|
580
624
|
return [...allOf, restOfSchema];
|
|
581
625
|
}
|
|
582
626
|
try {
|
|
583
|
-
|
|
627
|
+
const withContainsSchemas = [];
|
|
628
|
+
const withoutContainsSchemas = [];
|
|
629
|
+
resolvedSchema.allOf?.forEach((s2) => {
|
|
630
|
+
if (typeof s2 === "object" && s2.contains) {
|
|
631
|
+
withContainsSchemas.push(s2);
|
|
632
|
+
} else {
|
|
633
|
+
withoutContainsSchemas.push(s2);
|
|
634
|
+
}
|
|
635
|
+
});
|
|
636
|
+
if (withContainsSchemas.length) {
|
|
637
|
+
resolvedSchema = { ...resolvedSchema, allOf: withoutContainsSchemas };
|
|
638
|
+
}
|
|
639
|
+
resolvedSchema = experimental_customMergeAllOf ? experimental_customMergeAllOf(resolvedSchema) : mergeAllOf(resolvedSchema, {
|
|
584
640
|
deep: false
|
|
585
641
|
});
|
|
642
|
+
if (withContainsSchemas.length) {
|
|
643
|
+
resolvedSchema.allOf = withContainsSchemas;
|
|
644
|
+
}
|
|
586
645
|
} catch (e) {
|
|
587
646
|
console.warn("could not merge subschemas in allOf:\n", e);
|
|
588
647
|
const { allOf, ...resolvedSchemaWithoutAllOf } = resolvedSchema;
|
|
@@ -618,7 +677,7 @@ function resolveAnyOrOneOfSchemas(validator, schema, rootSchema, expandAllBranch
|
|
|
618
677
|
}
|
|
619
678
|
return [schema];
|
|
620
679
|
}
|
|
621
|
-
function resolveDependencies(validator, schema, rootSchema, expandAllBranches, recurseList, formData) {
|
|
680
|
+
function resolveDependencies(validator, schema, rootSchema, expandAllBranches, recurseList, formData, experimental_customMergeAllOf) {
|
|
622
681
|
const { dependencies, ...remainingSchema } = schema;
|
|
623
682
|
const resolvedSchemas = resolveAnyOrOneOfSchemas(
|
|
624
683
|
validator,
|
|
@@ -635,11 +694,12 @@ function resolveDependencies(validator, schema, rootSchema, expandAllBranches, r
|
|
|
635
694
|
rootSchema,
|
|
636
695
|
expandAllBranches,
|
|
637
696
|
recurseList,
|
|
638
|
-
formData
|
|
697
|
+
formData,
|
|
698
|
+
experimental_customMergeAllOf
|
|
639
699
|
)
|
|
640
700
|
);
|
|
641
701
|
}
|
|
642
|
-
function processDependencies(validator, dependencies, resolvedSchema, rootSchema, expandAllBranches, recurseList, formData) {
|
|
702
|
+
function processDependencies(validator, dependencies, resolvedSchema, rootSchema, expandAllBranches, recurseList, formData, experimental_customMergeAllOf) {
|
|
643
703
|
let schemas = [resolvedSchema];
|
|
644
704
|
for (const dependencyKey in dependencies) {
|
|
645
705
|
if (!expandAllBranches && get4(formData, [dependencyKey]) === void 0) {
|
|
@@ -663,7 +723,8 @@ function processDependencies(validator, dependencies, resolvedSchema, rootSchema
|
|
|
663
723
|
dependencyValue,
|
|
664
724
|
expandAllBranches,
|
|
665
725
|
recurseList,
|
|
666
|
-
formData
|
|
726
|
+
formData,
|
|
727
|
+
experimental_customMergeAllOf
|
|
667
728
|
);
|
|
668
729
|
}
|
|
669
730
|
return schemas.flatMap(
|
|
@@ -674,7 +735,8 @@ function processDependencies(validator, dependencies, resolvedSchema, rootSchema
|
|
|
674
735
|
rootSchema,
|
|
675
736
|
expandAllBranches,
|
|
676
737
|
recurseList,
|
|
677
|
-
formData
|
|
738
|
+
formData,
|
|
739
|
+
experimental_customMergeAllOf
|
|
678
740
|
)
|
|
679
741
|
);
|
|
680
742
|
}
|
|
@@ -687,14 +749,15 @@ function withDependentProperties(schema, additionallyRequired) {
|
|
|
687
749
|
const required = Array.isArray(schema.required) ? Array.from(/* @__PURE__ */ new Set([...schema.required, ...additionallyRequired])) : additionallyRequired;
|
|
688
750
|
return { ...schema, required };
|
|
689
751
|
}
|
|
690
|
-
function withDependentSchema(validator, schema, rootSchema, dependencyKey, dependencyValue, expandAllBranches, recurseList, formData) {
|
|
752
|
+
function withDependentSchema(validator, schema, rootSchema, dependencyKey, dependencyValue, expandAllBranches, recurseList, formData, experimental_customMergeAllOf) {
|
|
691
753
|
const dependentSchemas = retrieveSchemaInternal(
|
|
692
754
|
validator,
|
|
693
755
|
dependencyValue,
|
|
694
756
|
rootSchema,
|
|
695
757
|
formData,
|
|
696
758
|
expandAllBranches,
|
|
697
|
-
recurseList
|
|
759
|
+
recurseList,
|
|
760
|
+
experimental_customMergeAllOf
|
|
698
761
|
);
|
|
699
762
|
return dependentSchemas.flatMap((dependent) => {
|
|
700
763
|
const { oneOf, ...dependentSchema } = dependent;
|
|
@@ -718,12 +781,13 @@ function withDependentSchema(validator, schema, rootSchema, dependencyKey, depen
|
|
|
718
781
|
resolvedOneOf,
|
|
719
782
|
expandAllBranches,
|
|
720
783
|
recurseList,
|
|
721
|
-
formData
|
|
784
|
+
formData,
|
|
785
|
+
experimental_customMergeAllOf
|
|
722
786
|
)
|
|
723
787
|
);
|
|
724
788
|
});
|
|
725
789
|
}
|
|
726
|
-
function withExactlyOneSubschema(validator, schema, rootSchema, dependencyKey, oneOf, expandAllBranches, recurseList, formData) {
|
|
790
|
+
function withExactlyOneSubschema(validator, schema, rootSchema, dependencyKey, oneOf, expandAllBranches, recurseList, formData, experimental_customMergeAllOf) {
|
|
727
791
|
const validSubschemas = oneOf.filter((subschema) => {
|
|
728
792
|
if (typeof subschema === "boolean" || !subschema || !subschema.properties) {
|
|
729
793
|
return false;
|
|
@@ -754,7 +818,8 @@ function withExactlyOneSubschema(validator, schema, rootSchema, dependencyKey, o
|
|
|
754
818
|
rootSchema,
|
|
755
819
|
formData,
|
|
756
820
|
expandAllBranches,
|
|
757
|
-
recurseList
|
|
821
|
+
recurseList,
|
|
822
|
+
experimental_customMergeAllOf
|
|
758
823
|
);
|
|
759
824
|
return schemas.map((s2) => mergeSchemas(schema, s2));
|
|
760
825
|
});
|
|
@@ -770,7 +835,7 @@ var JUNK_OPTION = {
|
|
|
770
835
|
}
|
|
771
836
|
}
|
|
772
837
|
};
|
|
773
|
-
function calculateIndexScore(validator, rootSchema, schema, formData
|
|
838
|
+
function calculateIndexScore(validator, rootSchema, schema, formData) {
|
|
774
839
|
let totalScore = 0;
|
|
775
840
|
if (schema) {
|
|
776
841
|
if (isObject2(schema.properties)) {
|
|
@@ -798,7 +863,10 @@ function calculateIndexScore(validator, rootSchema, schema, formData = {}) {
|
|
|
798
863
|
);
|
|
799
864
|
}
|
|
800
865
|
if (value.type === "object") {
|
|
801
|
-
|
|
866
|
+
if (isObject2(formValue)) {
|
|
867
|
+
score += 1;
|
|
868
|
+
}
|
|
869
|
+
return score + calculateIndexScore(validator, rootSchema, value, formValue);
|
|
802
870
|
}
|
|
803
871
|
if (value.type === guessType(formValue)) {
|
|
804
872
|
let newScore = score + 1;
|
|
@@ -868,12 +936,17 @@ function isFixedItems(schema) {
|
|
|
868
936
|
|
|
869
937
|
// src/mergeDefaultsWithFormData.ts
|
|
870
938
|
import get6 from "lodash/get";
|
|
871
|
-
function mergeDefaultsWithFormData(defaults, formData, mergeExtraArrayDefaults = false) {
|
|
939
|
+
function mergeDefaultsWithFormData(defaults, formData, mergeExtraArrayDefaults = false, defaultSupercedesUndefined = false) {
|
|
872
940
|
if (Array.isArray(formData)) {
|
|
873
941
|
const defaultsArray = Array.isArray(defaults) ? defaults : [];
|
|
874
942
|
const mapped = formData.map((value, idx) => {
|
|
875
943
|
if (defaultsArray[idx]) {
|
|
876
|
-
return mergeDefaultsWithFormData(
|
|
944
|
+
return mergeDefaultsWithFormData(
|
|
945
|
+
defaultsArray[idx],
|
|
946
|
+
value,
|
|
947
|
+
mergeExtraArrayDefaults,
|
|
948
|
+
defaultSupercedesUndefined
|
|
949
|
+
);
|
|
877
950
|
}
|
|
878
951
|
return value;
|
|
879
952
|
});
|
|
@@ -888,11 +961,15 @@ function mergeDefaultsWithFormData(defaults, formData, mergeExtraArrayDefaults =
|
|
|
888
961
|
acc2[key] = mergeDefaultsWithFormData(
|
|
889
962
|
defaults ? get6(defaults, key) : {},
|
|
890
963
|
get6(formData, key),
|
|
891
|
-
mergeExtraArrayDefaults
|
|
964
|
+
mergeExtraArrayDefaults,
|
|
965
|
+
defaultSupercedesUndefined
|
|
892
966
|
);
|
|
893
967
|
return acc2;
|
|
894
968
|
}, acc);
|
|
895
969
|
}
|
|
970
|
+
if (defaultSupercedesUndefined && formData === void 0) {
|
|
971
|
+
return defaults;
|
|
972
|
+
}
|
|
896
973
|
return formData;
|
|
897
974
|
}
|
|
898
975
|
|
|
@@ -963,9 +1040,9 @@ function getInnerSchemaForArrayItem(schema, additionalItems = 0 /* Ignore */, id
|
|
|
963
1040
|
}
|
|
964
1041
|
return {};
|
|
965
1042
|
}
|
|
966
|
-
function maybeAddDefaultToObject(obj, key, computedDefault, includeUndefinedValues, isParentRequired, requiredFields = [], experimental_defaultFormStateBehavior = {}) {
|
|
1043
|
+
function maybeAddDefaultToObject(obj, key, computedDefault, includeUndefinedValues, isParentRequired, requiredFields = [], experimental_defaultFormStateBehavior = {}, isConst = false) {
|
|
967
1044
|
const { emptyObjectFields = "populateAllDefaults" } = experimental_defaultFormStateBehavior;
|
|
968
|
-
if (includeUndefinedValues) {
|
|
1045
|
+
if (includeUndefinedValues || isConst) {
|
|
969
1046
|
obj[key] = computedDefault;
|
|
970
1047
|
} else if (emptyObjectFields !== "skipDefaults") {
|
|
971
1048
|
if (isObject(computedDefault)) {
|
|
@@ -995,6 +1072,7 @@ function computeDefaults(validator, rawSchema, computeDefaultsProps = {}) {
|
|
|
995
1072
|
includeUndefinedValues = false,
|
|
996
1073
|
_recurseList = [],
|
|
997
1074
|
experimental_defaultFormStateBehavior = void 0,
|
|
1075
|
+
experimental_customMergeAllOf = void 0,
|
|
998
1076
|
required
|
|
999
1077
|
} = computeDefaultsProps;
|
|
1000
1078
|
const formData = isObject(rawFormData) ? rawFormData : {};
|
|
@@ -1002,7 +1080,9 @@ function computeDefaults(validator, rawSchema, computeDefaultsProps = {}) {
|
|
|
1002
1080
|
let defaults = parentDefaults;
|
|
1003
1081
|
let schemaToCompute = null;
|
|
1004
1082
|
let updatedRecurseList = _recurseList;
|
|
1005
|
-
if (
|
|
1083
|
+
if (isConstant(schema)) {
|
|
1084
|
+
defaults = schema.const;
|
|
1085
|
+
} else if (isObject(defaults) && isObject(schema.default)) {
|
|
1006
1086
|
defaults = mergeObjects(defaults, schema.default);
|
|
1007
1087
|
} else if (DEFAULT_KEY in schema) {
|
|
1008
1088
|
defaults = schema.default;
|
|
@@ -1017,7 +1097,15 @@ function computeDefaults(validator, rawSchema, computeDefaultsProps = {}) {
|
|
|
1017
1097
|
...formData,
|
|
1018
1098
|
...getDefaultBasedOnSchemaType(validator, schema, computeDefaultsProps, defaults)
|
|
1019
1099
|
};
|
|
1020
|
-
const resolvedSchema = resolveDependencies(
|
|
1100
|
+
const resolvedSchema = resolveDependencies(
|
|
1101
|
+
validator,
|
|
1102
|
+
schema,
|
|
1103
|
+
rootSchema,
|
|
1104
|
+
false,
|
|
1105
|
+
[],
|
|
1106
|
+
defaultFormData,
|
|
1107
|
+
experimental_customMergeAllOf
|
|
1108
|
+
);
|
|
1021
1109
|
schemaToCompute = resolvedSchema[0];
|
|
1022
1110
|
} else if (isFixedItems(schema)) {
|
|
1023
1111
|
defaults = schema.items.map(
|
|
@@ -1085,18 +1173,24 @@ function getObjectDefaults(validator, rawSchema, {
|
|
|
1085
1173
|
includeUndefinedValues = false,
|
|
1086
1174
|
_recurseList = [],
|
|
1087
1175
|
experimental_defaultFormStateBehavior = void 0,
|
|
1176
|
+
experimental_customMergeAllOf = void 0,
|
|
1088
1177
|
required
|
|
1089
1178
|
} = {}, defaults) {
|
|
1090
1179
|
{
|
|
1091
1180
|
const formData = isObject(rawFormData) ? rawFormData : {};
|
|
1092
1181
|
const schema = rawSchema;
|
|
1093
|
-
const retrievedSchema = experimental_defaultFormStateBehavior?.allOf === "populateDefaults" && ALL_OF_KEY in schema ? retrieveSchema(validator, schema, rootSchema, formData) : schema;
|
|
1182
|
+
const retrievedSchema = experimental_defaultFormStateBehavior?.allOf === "populateDefaults" && ALL_OF_KEY in schema ? retrieveSchema(validator, schema, rootSchema, formData, experimental_customMergeAllOf) : schema;
|
|
1183
|
+
const parentConst = retrievedSchema[CONST_KEY];
|
|
1094
1184
|
const objectDefaults = Object.keys(retrievedSchema.properties || {}).reduce(
|
|
1095
1185
|
(acc, key) => {
|
|
1096
|
-
const
|
|
1186
|
+
const propertySchema = get7(retrievedSchema, [PROPERTIES_KEY, key]);
|
|
1187
|
+
const hasParentConst = isObject(parentConst) && parentConst[key] !== void 0;
|
|
1188
|
+
const hasConst = isObject(propertySchema) && CONST_KEY in propertySchema || hasParentConst;
|
|
1189
|
+
const computedDefault = computeDefaults(validator, propertySchema, {
|
|
1097
1190
|
rootSchema,
|
|
1098
1191
|
_recurseList,
|
|
1099
1192
|
experimental_defaultFormStateBehavior,
|
|
1193
|
+
experimental_customMergeAllOf,
|
|
1100
1194
|
includeUndefinedValues: includeUndefinedValues === true,
|
|
1101
1195
|
parentDefaults: get7(defaults, [key]),
|
|
1102
1196
|
rawFormData: get7(formData, [key]),
|
|
@@ -1109,7 +1203,8 @@ function getObjectDefaults(validator, rawSchema, {
|
|
|
1109
1203
|
includeUndefinedValues,
|
|
1110
1204
|
required,
|
|
1111
1205
|
retrievedSchema.required,
|
|
1112
|
-
experimental_defaultFormStateBehavior
|
|
1206
|
+
experimental_defaultFormStateBehavior,
|
|
1207
|
+
hasConst
|
|
1113
1208
|
);
|
|
1114
1209
|
return acc;
|
|
1115
1210
|
},
|
|
@@ -1191,11 +1286,14 @@ function getArrayDefaults(validator, rawSchema, {
|
|
|
1191
1286
|
});
|
|
1192
1287
|
}
|
|
1193
1288
|
}
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1289
|
+
const hasConst = isObject(schema) && CONST_KEY in schema;
|
|
1290
|
+
if (hasConst === false) {
|
|
1291
|
+
if (neverPopulate) {
|
|
1292
|
+
return defaults ?? emptyDefault;
|
|
1293
|
+
}
|
|
1294
|
+
if (ignoreMinItemsFlagSet && !required) {
|
|
1295
|
+
return defaults ? defaults : void 0;
|
|
1296
|
+
}
|
|
1199
1297
|
}
|
|
1200
1298
|
const defaultsLength = Array.isArray(defaults) ? defaults.length : 0;
|
|
1201
1299
|
if (!schema.minItems || isMultiSelect(validator, schema, rootSchema) || computeSkipPopulate(validator, schema, rootSchema) || schema.minItems <= defaultsLength) {
|
|
@@ -1225,26 +1323,29 @@ function getDefaultBasedOnSchemaType(validator, rawSchema, computeDefaultsProps
|
|
|
1225
1323
|
}
|
|
1226
1324
|
}
|
|
1227
1325
|
}
|
|
1228
|
-
function getDefaultFormState(validator, theSchema, formData, rootSchema, includeUndefinedValues = false, experimental_defaultFormStateBehavior) {
|
|
1326
|
+
function getDefaultFormState(validator, theSchema, formData, rootSchema, includeUndefinedValues = false, experimental_defaultFormStateBehavior, experimental_customMergeAllOf) {
|
|
1229
1327
|
if (!isObject(theSchema)) {
|
|
1230
1328
|
throw new Error("Invalid schema: " + theSchema);
|
|
1231
1329
|
}
|
|
1232
|
-
const schema = retrieveSchema(validator, theSchema, rootSchema, formData);
|
|
1330
|
+
const schema = retrieveSchema(validator, theSchema, rootSchema, formData, experimental_customMergeAllOf);
|
|
1233
1331
|
const defaults = computeDefaults(validator, schema, {
|
|
1234
1332
|
rootSchema,
|
|
1235
1333
|
includeUndefinedValues,
|
|
1236
1334
|
experimental_defaultFormStateBehavior,
|
|
1335
|
+
experimental_customMergeAllOf,
|
|
1237
1336
|
rawFormData: formData
|
|
1238
1337
|
});
|
|
1239
1338
|
if (formData === void 0 || formData === null || typeof formData === "number" && isNaN(formData)) {
|
|
1240
1339
|
return defaults;
|
|
1241
1340
|
}
|
|
1242
|
-
const {
|
|
1341
|
+
const { mergeDefaultsIntoFormData, arrayMinItems = {} } = experimental_defaultFormStateBehavior || {};
|
|
1342
|
+
const { mergeExtraDefaults } = arrayMinItems;
|
|
1343
|
+
const defaultSupercedesUndefined = mergeDefaultsIntoFormData === "useDefaultIfFormDataUndefined";
|
|
1243
1344
|
if (isObject(formData)) {
|
|
1244
|
-
return mergeDefaultsWithFormData(defaults, formData, mergeExtraDefaults);
|
|
1345
|
+
return mergeDefaultsWithFormData(defaults, formData, mergeExtraDefaults, defaultSupercedesUndefined);
|
|
1245
1346
|
}
|
|
1246
1347
|
if (Array.isArray(formData)) {
|
|
1247
|
-
return mergeDefaultsWithFormData(defaults, formData, mergeExtraDefaults);
|
|
1348
|
+
return mergeDefaultsWithFormData(defaults, formData, mergeExtraDefaults, defaultSupercedesUndefined);
|
|
1248
1349
|
}
|
|
1249
1350
|
return formData;
|
|
1250
1351
|
}
|
|
@@ -1417,7 +1518,7 @@ function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, d
|
|
|
1417
1518
|
// src/schema/toIdSchema.ts
|
|
1418
1519
|
import get9 from "lodash/get";
|
|
1419
1520
|
import isEqual2 from "lodash/isEqual";
|
|
1420
|
-
function toIdSchemaInternal(validator, schema, idPrefix, idSeparator, id, rootSchema, formData, _recurseList = []) {
|
|
1521
|
+
function toIdSchemaInternal(validator, schema, idPrefix, idSeparator, id, rootSchema, formData, _recurseList = [], experimental_customMergeAllOf) {
|
|
1421
1522
|
if (REF_KEY in schema || DEPENDENCIES_KEY in schema || ALL_OF_KEY in schema) {
|
|
1422
1523
|
const _schema = retrieveSchema(validator, schema, rootSchema, formData);
|
|
1423
1524
|
const sameSchemaIndex = _recurseList.findIndex((item) => isEqual2(item, _schema));
|
|
@@ -1430,7 +1531,8 @@ function toIdSchemaInternal(validator, schema, idPrefix, idSeparator, id, rootSc
|
|
|
1430
1531
|
id,
|
|
1431
1532
|
rootSchema,
|
|
1432
1533
|
formData,
|
|
1433
|
-
_recurseList.concat(_schema)
|
|
1534
|
+
_recurseList.concat(_schema),
|
|
1535
|
+
experimental_customMergeAllOf
|
|
1434
1536
|
);
|
|
1435
1537
|
}
|
|
1436
1538
|
}
|
|
@@ -1443,7 +1545,8 @@ function toIdSchemaInternal(validator, schema, idPrefix, idSeparator, id, rootSc
|
|
|
1443
1545
|
id,
|
|
1444
1546
|
rootSchema,
|
|
1445
1547
|
formData,
|
|
1446
|
-
_recurseList
|
|
1548
|
+
_recurseList,
|
|
1549
|
+
experimental_customMergeAllOf
|
|
1447
1550
|
);
|
|
1448
1551
|
}
|
|
1449
1552
|
const $id = id || idPrefix;
|
|
@@ -1462,14 +1565,25 @@ function toIdSchemaInternal(validator, schema, idPrefix, idSeparator, id, rootSc
|
|
|
1462
1565
|
// It's possible that formData is not an object -- this can happen if an
|
|
1463
1566
|
// array item has just been added, but not populated with data yet
|
|
1464
1567
|
get9(formData, [name]),
|
|
1465
|
-
_recurseList
|
|
1568
|
+
_recurseList,
|
|
1569
|
+
experimental_customMergeAllOf
|
|
1466
1570
|
);
|
|
1467
1571
|
}
|
|
1468
1572
|
}
|
|
1469
1573
|
return idSchema;
|
|
1470
1574
|
}
|
|
1471
|
-
function toIdSchema(validator, schema, id, rootSchema, formData, idPrefix = "root", idSeparator = "_") {
|
|
1472
|
-
return toIdSchemaInternal(
|
|
1575
|
+
function toIdSchema(validator, schema, id, rootSchema, formData, idPrefix = "root", idSeparator = "_", experimental_customMergeAllOf) {
|
|
1576
|
+
return toIdSchemaInternal(
|
|
1577
|
+
validator,
|
|
1578
|
+
schema,
|
|
1579
|
+
idPrefix,
|
|
1580
|
+
idSeparator,
|
|
1581
|
+
id,
|
|
1582
|
+
rootSchema,
|
|
1583
|
+
formData,
|
|
1584
|
+
void 0,
|
|
1585
|
+
experimental_customMergeAllOf
|
|
1586
|
+
);
|
|
1473
1587
|
}
|
|
1474
1588
|
|
|
1475
1589
|
// src/schema/toPathSchema.ts
|
|
@@ -1573,11 +1687,13 @@ var SchemaUtils = class {
|
|
|
1573
1687
|
* @param validator - An implementation of the `ValidatorType` interface that will be forwarded to all the APIs
|
|
1574
1688
|
* @param rootSchema - The root schema that will be forwarded to all the APIs
|
|
1575
1689
|
* @param experimental_defaultFormStateBehavior - Configuration flags to allow users to override default form state behavior
|
|
1690
|
+
* @param [experimental_customMergeAllOf] - Optional function that allows for custom merging of `allOf` schemas
|
|
1576
1691
|
*/
|
|
1577
|
-
constructor(validator, rootSchema, experimental_defaultFormStateBehavior) {
|
|
1692
|
+
constructor(validator, rootSchema, experimental_defaultFormStateBehavior, experimental_customMergeAllOf) {
|
|
1578
1693
|
this.rootSchema = rootSchema;
|
|
1579
1694
|
this.validator = validator;
|
|
1580
1695
|
this.experimental_defaultFormStateBehavior = experimental_defaultFormStateBehavior;
|
|
1696
|
+
this.experimental_customMergeAllOf = experimental_customMergeAllOf;
|
|
1581
1697
|
}
|
|
1582
1698
|
/** Returns the `ValidatorType` in the `SchemaUtilsType`
|
|
1583
1699
|
*
|
|
@@ -1593,13 +1709,14 @@ var SchemaUtils = class {
|
|
|
1593
1709
|
* @param validator - An implementation of the `ValidatorType` interface that will be compared against the current one
|
|
1594
1710
|
* @param rootSchema - The root schema that will be compared against the current one
|
|
1595
1711
|
* @param [experimental_defaultFormStateBehavior] Optional configuration object, if provided, allows users to override default form state behavior
|
|
1712
|
+
* @param [experimental_customMergeAllOf] - Optional function that allows for custom merging of `allOf` schemas
|
|
1596
1713
|
* @returns - True if the `SchemaUtilsType` differs from the given `validator` or `rootSchema`
|
|
1597
1714
|
*/
|
|
1598
|
-
doesSchemaUtilsDiffer(validator, rootSchema, experimental_defaultFormStateBehavior = {}) {
|
|
1715
|
+
doesSchemaUtilsDiffer(validator, rootSchema, experimental_defaultFormStateBehavior = {}, experimental_customMergeAllOf) {
|
|
1599
1716
|
if (!validator || !rootSchema) {
|
|
1600
1717
|
return false;
|
|
1601
1718
|
}
|
|
1602
|
-
return this.validator !== validator || !deepEquals(this.rootSchema, rootSchema) || !deepEquals(this.experimental_defaultFormStateBehavior, experimental_defaultFormStateBehavior);
|
|
1719
|
+
return this.validator !== validator || !deepEquals(this.rootSchema, rootSchema) || !deepEquals(this.experimental_defaultFormStateBehavior, experimental_defaultFormStateBehavior) || this.experimental_customMergeAllOf !== experimental_customMergeAllOf;
|
|
1603
1720
|
}
|
|
1604
1721
|
/** Returns the superset of `formData` that includes the given set updated to include any missing fields that have
|
|
1605
1722
|
* computed to have defaults provided in the `schema`.
|
|
@@ -1618,7 +1735,8 @@ var SchemaUtils = class {
|
|
|
1618
1735
|
formData,
|
|
1619
1736
|
this.rootSchema,
|
|
1620
1737
|
includeUndefinedValues,
|
|
1621
|
-
this.experimental_defaultFormStateBehavior
|
|
1738
|
+
this.experimental_defaultFormStateBehavior,
|
|
1739
|
+
this.experimental_customMergeAllOf
|
|
1622
1740
|
);
|
|
1623
1741
|
}
|
|
1624
1742
|
/** Determines whether the combination of `schema` and `uiSchema` properties indicates that the label for the `schema`
|
|
@@ -1728,7 +1846,13 @@ var SchemaUtils = class {
|
|
|
1728
1846
|
* @returns - The schema having its conditions, additional properties, references and dependencies resolved
|
|
1729
1847
|
*/
|
|
1730
1848
|
retrieveSchema(schema, rawFormData) {
|
|
1731
|
-
return retrieveSchema(
|
|
1849
|
+
return retrieveSchema(
|
|
1850
|
+
this.validator,
|
|
1851
|
+
schema,
|
|
1852
|
+
this.rootSchema,
|
|
1853
|
+
rawFormData,
|
|
1854
|
+
this.experimental_customMergeAllOf
|
|
1855
|
+
);
|
|
1732
1856
|
}
|
|
1733
1857
|
/** Sanitize the `data` associated with the `oldSchema` so it is considered appropriate for the `newSchema`. If the
|
|
1734
1858
|
* new schema does not contain any properties, then `undefined` is returned to clear all the form data. Due to the
|
|
@@ -1754,7 +1878,16 @@ var SchemaUtils = class {
|
|
|
1754
1878
|
* @returns - The `IdSchema` object for the `schema`
|
|
1755
1879
|
*/
|
|
1756
1880
|
toIdSchema(schema, id, formData, idPrefix = "root", idSeparator = "_") {
|
|
1757
|
-
return toIdSchema(
|
|
1881
|
+
return toIdSchema(
|
|
1882
|
+
this.validator,
|
|
1883
|
+
schema,
|
|
1884
|
+
id,
|
|
1885
|
+
this.rootSchema,
|
|
1886
|
+
formData,
|
|
1887
|
+
idPrefix,
|
|
1888
|
+
idSeparator,
|
|
1889
|
+
this.experimental_customMergeAllOf
|
|
1890
|
+
);
|
|
1758
1891
|
}
|
|
1759
1892
|
/** Generates an `PathSchema` object for the `schema`, recursively
|
|
1760
1893
|
*
|
|
@@ -1767,8 +1900,13 @@ var SchemaUtils = class {
|
|
|
1767
1900
|
return toPathSchema(this.validator, schema, name, this.rootSchema, formData);
|
|
1768
1901
|
}
|
|
1769
1902
|
};
|
|
1770
|
-
function createSchemaUtils(validator, rootSchema, experimental_defaultFormStateBehavior = {}) {
|
|
1771
|
-
return new SchemaUtils(
|
|
1903
|
+
function createSchemaUtils(validator, rootSchema, experimental_defaultFormStateBehavior = {}, experimental_customMergeAllOf) {
|
|
1904
|
+
return new SchemaUtils(
|
|
1905
|
+
validator,
|
|
1906
|
+
rootSchema,
|
|
1907
|
+
experimental_defaultFormStateBehavior,
|
|
1908
|
+
experimental_customMergeAllOf
|
|
1909
|
+
);
|
|
1772
1910
|
}
|
|
1773
1911
|
|
|
1774
1912
|
// src/dataURItoBlob.ts
|
|
@@ -1907,6 +2045,7 @@ function enumOptionsSelectValue(valueIndex, selected, allEnumOptions = []) {
|
|
|
1907
2045
|
import cloneDeep from "lodash/cloneDeep";
|
|
1908
2046
|
import get11 from "lodash/get";
|
|
1909
2047
|
import set3 from "lodash/set";
|
|
2048
|
+
import setWith from "lodash/setWith";
|
|
1910
2049
|
var ErrorSchemaBuilder = class {
|
|
1911
2050
|
/** Construct an `ErrorSchemaBuilder` with an optional initial set of errors in an `ErrorSchema`.
|
|
1912
2051
|
*
|
|
@@ -1936,7 +2075,7 @@ var ErrorSchemaBuilder = class {
|
|
|
1936
2075
|
let errorBlock = hasPath ? get11(this.errorSchema, pathOfError) : this.errorSchema;
|
|
1937
2076
|
if (!errorBlock && pathOfError) {
|
|
1938
2077
|
errorBlock = {};
|
|
1939
|
-
|
|
2078
|
+
setWith(this.errorSchema, pathOfError, errorBlock, Object);
|
|
1940
2079
|
}
|
|
1941
2080
|
return errorBlock;
|
|
1942
2081
|
}
|