@rjsf/utils 6.6.2 → 6.7.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/LICENSE.md +201 -0
- package/dist/index.cjs +229 -108
- package/dist/index.cjs.map +4 -4
- package/dist/utils.esm.js +229 -108
- package/dist/utils.esm.js.map +4 -4
- package/dist/utils.umd.js +260 -136
- package/lib/SelectedOptionDescription.d.ts +4 -0
- package/lib/SelectedOptionDescription.js +24 -0
- package/lib/SelectedOptionDescription.js.map +1 -0
- package/lib/constants.d.ts +8 -5
- package/lib/constants.js +10 -7
- package/lib/constants.js.map +1 -1
- package/lib/createSchemaUtils.js +1 -1
- package/lib/createSchemaUtils.js.map +1 -1
- package/lib/enums.d.ts +4 -0
- package/lib/enums.js +4 -0
- package/lib/enums.js.map +1 -1
- package/lib/getSubmitButtonOptions.js +1 -1
- package/lib/getSubmitButtonOptions.js.map +1 -1
- package/lib/getWidget.js +2 -1
- package/lib/getWidget.js.map +1 -1
- package/lib/hashForSchema.d.ts +2 -0
- package/lib/hashForSchema.js +3 -1
- package/lib/hashForSchema.js.map +1 -1
- package/lib/index.d.ts +5 -2
- package/lib/index.js +4 -2
- package/lib/index.js.map +1 -1
- package/lib/isFixedItems.d.ts +2 -2
- package/lib/isFixedItems.js +3 -3
- package/lib/isFixedItems.js.map +1 -1
- package/lib/isRootSchema.js +2 -3
- package/lib/isRootSchema.js.map +1 -1
- package/lib/logUnsupportedDefaultForEnum.d.ts +9 -0
- package/lib/logUnsupportedDefaultForEnum.js +18 -0
- package/lib/logUnsupportedDefaultForEnum.js.map +1 -0
- package/lib/mergeSchemas.js +8 -1
- package/lib/mergeSchemas.js.map +1 -1
- package/lib/optionsList.js +22 -21
- package/lib/optionsList.js.map +1 -1
- package/lib/resolveUiSchema.js.map +1 -1
- package/lib/schema/getDefaultFormState.d.ts +1 -1
- package/lib/schema/getDefaultFormState.js +54 -17
- package/lib/schema/getDefaultFormState.js.map +1 -1
- package/lib/schema/getDisplayLabel.js +2 -3
- package/lib/schema/getDisplayLabel.js.map +1 -1
- package/lib/schema/omitExtraData.js +11 -0
- package/lib/schema/omitExtraData.js.map +1 -1
- package/lib/schema/retrieveSchema.d.ts +5 -1
- package/lib/schema/retrieveSchema.js +49 -14
- package/lib/schema/retrieveSchema.js.map +1 -1
- package/lib/schemaRequiresTrueValue.js +4 -3
- package/lib/schemaRequiresTrueValue.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/types.d.ts +24 -0
- package/lib/useAltDateWidgetProps.d.ts +1 -1
- package/lib/useFileWidgetProps.js +2 -2
- package/lib/useFileWidgetProps.js.map +1 -1
- package/package.json +19 -19
- package/src/SelectedOptionDescription.tsx +48 -0
- package/src/constants.ts +10 -7
- package/src/createSchemaUtils.ts +1 -1
- package/src/enums.ts +4 -0
- package/src/getSubmitButtonOptions.ts +1 -1
- package/src/getWidget.tsx +1 -1
- package/src/hashForSchema.ts +3 -1
- package/src/index.ts +6 -0
- package/src/isFixedItems.ts +3 -3
- package/src/isRootSchema.ts +2 -4
- package/src/logUnsupportedDefaultForEnum.ts +28 -0
- package/src/mergeSchemas.ts +9 -2
- package/src/optionsList.ts +20 -22
- package/src/resolveUiSchema.ts +12 -4
- package/src/schema/getDefaultFormState.ts +80 -22
- package/src/schema/getDisplayLabel.ts +3 -4
- package/src/schema/omitExtraData.ts +11 -0
- package/src/schema/retrieveSchema.ts +59 -13
- package/src/schemaRequiresTrueValue.ts +3 -3
- package/src/types.ts +31 -0
- package/src/useFileWidgetProps.ts +2 -2
package/dist/utils.esm.js
CHANGED
|
@@ -43,7 +43,7 @@ function asNumber(value) {
|
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
// src/constants.ts
|
|
46
|
-
var ADDITIONAL_PROPERTY_FLAG = "__additional_property";
|
|
46
|
+
var ADDITIONAL_PROPERTY_FLAG = /* @__PURE__ */ Symbol("__additional_property");
|
|
47
47
|
var ADDITIONAL_PROPERTIES_KEY = "additionalProperties";
|
|
48
48
|
var ALL_OF_KEY = "allOf";
|
|
49
49
|
var ANY_OF_KEY = "anyOf";
|
|
@@ -65,15 +65,17 @@ var READONLY_KEY = "readonly";
|
|
|
65
65
|
var REQUIRED_KEY = "required";
|
|
66
66
|
var SUBMIT_BTN_OPTIONS_KEY = "submitButtonOptions";
|
|
67
67
|
var REF_KEY = "$ref";
|
|
68
|
-
var RJSF_REF_KEY = "__rjsf_ref";
|
|
68
|
+
var RJSF_REF_KEY = /* @__PURE__ */ Symbol("__rjsf_ref");
|
|
69
|
+
var RJSF_REF_CYCLE_KEY = /* @__PURE__ */ Symbol("__rjsf_ref_cycle");
|
|
69
70
|
var SCHEMA_KEY = "$schema";
|
|
70
71
|
var DEFAULT_ID_PREFIX = "root";
|
|
71
72
|
var DEFAULT_ID_SEPARATOR = "_";
|
|
72
73
|
var DISCRIMINATOR_PATH = ["discriminator", "propertyName"];
|
|
73
74
|
var FORM_CONTEXT_NAME = "formContext";
|
|
74
75
|
var LOOKUP_MAP_NAME = "layoutGridLookupMap";
|
|
75
|
-
var
|
|
76
|
-
var
|
|
76
|
+
var RJSF_PREFIX_KEY = "__rjsf";
|
|
77
|
+
var RJSF_ADDITIONAL_PROPERTIES_FLAG = `${RJSF_PREFIX_KEY}_additionalProperties`;
|
|
78
|
+
var ROOT_SCHEMA_PREFIX = `${RJSF_PREFIX_KEY}_rootSchema`;
|
|
77
79
|
var UI_FIELD_KEY = "ui:field";
|
|
78
80
|
var UI_WIDGET_KEY = "ui:widget";
|
|
79
81
|
var UI_OPTIONS_KEY = "ui:options";
|
|
@@ -144,7 +146,7 @@ function createErrorHandler(formData) {
|
|
|
144
146
|
}
|
|
145
147
|
|
|
146
148
|
// src/createSchemaUtils.ts
|
|
147
|
-
import
|
|
149
|
+
import get16 from "lodash/get";
|
|
148
150
|
|
|
149
151
|
// src/deepEquals.ts
|
|
150
152
|
import { createCustomEqual } from "fast-equals";
|
|
@@ -348,7 +350,7 @@ function getSchemaType(schema) {
|
|
|
348
350
|
// src/mergeSchemas.ts
|
|
349
351
|
function mergeSchemas(obj1, obj2) {
|
|
350
352
|
const acc = { ...obj1 };
|
|
351
|
-
|
|
353
|
+
const result = Object.keys(obj2).reduce((accumulator, key) => {
|
|
352
354
|
const left = obj1 ? obj1[key] : {}, right = obj2[key];
|
|
353
355
|
if (obj1 && key in obj1 && isObject(right)) {
|
|
354
356
|
accumulator[key] = mergeSchemas(left, right);
|
|
@@ -359,6 +361,10 @@ function mergeSchemas(obj1, obj2) {
|
|
|
359
361
|
}
|
|
360
362
|
return accumulator;
|
|
361
363
|
}, acc);
|
|
364
|
+
for (const sym of Object.getOwnPropertySymbols(obj2)) {
|
|
365
|
+
result[sym] = obj2[sym];
|
|
366
|
+
}
|
|
367
|
+
return result;
|
|
362
368
|
}
|
|
363
369
|
|
|
364
370
|
// src/schema/getFirstMatchingOption.ts
|
|
@@ -460,6 +466,12 @@ function retrieveSchema(validator, schema, rootSchema = {}, rawFormData, experim
|
|
|
460
466
|
resolveAnyOfOrOneOfRefs
|
|
461
467
|
)[0];
|
|
462
468
|
}
|
|
469
|
+
function normalizeBooleanSchema(schema) {
|
|
470
|
+
if (typeof schema !== "boolean") {
|
|
471
|
+
return schema;
|
|
472
|
+
}
|
|
473
|
+
return schema ? {} : { not: {} };
|
|
474
|
+
}
|
|
463
475
|
function resolveCondition(validator, schema, rootSchema, expandAllBranches, recurseList, formData, experimental_customMergeAllOf) {
|
|
464
476
|
const { if: expression, then, else: otherwise, ...resolvedSchemaLessConditional } = schema;
|
|
465
477
|
const conditionValue = validator.isValid(expression, formData || {}, rootSchema);
|
|
@@ -467,10 +479,11 @@ function resolveCondition(validator, schema, rootSchema, expandAllBranches, recu
|
|
|
467
479
|
let schemas = [];
|
|
468
480
|
if (expandAllBranches) {
|
|
469
481
|
if (then && typeof then !== "boolean") {
|
|
482
|
+
const thenSchema = then;
|
|
470
483
|
schemas = schemas.concat(
|
|
471
484
|
retrieveSchemaInternal(
|
|
472
485
|
validator,
|
|
473
|
-
|
|
486
|
+
thenSchema,
|
|
474
487
|
rootSchema,
|
|
475
488
|
formData,
|
|
476
489
|
expandAllBranches,
|
|
@@ -480,10 +493,11 @@ function resolveCondition(validator, schema, rootSchema, expandAllBranches, recu
|
|
|
480
493
|
);
|
|
481
494
|
}
|
|
482
495
|
if (otherwise && typeof otherwise !== "boolean") {
|
|
496
|
+
const otherwiseSchema = otherwise;
|
|
483
497
|
schemas = schemas.concat(
|
|
484
498
|
retrieveSchemaInternal(
|
|
485
499
|
validator,
|
|
486
|
-
|
|
500
|
+
otherwiseSchema,
|
|
487
501
|
rootSchema,
|
|
488
502
|
formData,
|
|
489
503
|
expandAllBranches,
|
|
@@ -493,8 +507,9 @@ function resolveCondition(validator, schema, rootSchema, expandAllBranches, recu
|
|
|
493
507
|
);
|
|
494
508
|
}
|
|
495
509
|
} else {
|
|
496
|
-
const
|
|
497
|
-
if (
|
|
510
|
+
const conditionalBranch = conditionValue ? then : otherwise;
|
|
511
|
+
if (conditionalBranch !== void 0) {
|
|
512
|
+
const conditionalSchema = normalizeBooleanSchema(conditionalBranch);
|
|
498
513
|
schemas = schemas.concat(
|
|
499
514
|
retrieveSchemaInternal(
|
|
500
515
|
validator,
|
|
@@ -618,7 +633,7 @@ function resolveReference(validator, schema, rootSchema, expandAllBranches, recu
|
|
|
618
633
|
}
|
|
619
634
|
return [schema];
|
|
620
635
|
}
|
|
621
|
-
function resolveAllReferences(schema, rootSchema, recurseList, baseURI, resolveAnyOfOrOneOfRefs) {
|
|
636
|
+
function resolveAllReferences(schema, rootSchema, recurseList, baseURI, resolveAnyOfOrOneOfRefs, markCycleOnDetection = false) {
|
|
622
637
|
if (!isObject(schema)) {
|
|
623
638
|
return schema;
|
|
624
639
|
}
|
|
@@ -627,7 +642,7 @@ function resolveAllReferences(schema, rootSchema, recurseList, baseURI, resolveA
|
|
|
627
642
|
if (REF_KEY in resolvedSchema) {
|
|
628
643
|
const { $ref, ...localSchema } = resolvedSchema;
|
|
629
644
|
if (recurseList.includes($ref)) {
|
|
630
|
-
return resolvedSchema;
|
|
645
|
+
return markCycleOnDetection ? { ...resolvedSchema, [RJSF_REF_CYCLE_KEY]: true } : resolvedSchema;
|
|
631
646
|
}
|
|
632
647
|
recurseList.push($ref);
|
|
633
648
|
const refSchema = findSchemaDefinition($ref, rootSchema, currentBaseURI);
|
|
@@ -642,7 +657,14 @@ function resolveAllReferences(schema, rootSchema, recurseList, baseURI, resolveA
|
|
|
642
657
|
resolvedSchema[PROPERTIES_KEY],
|
|
643
658
|
(acc, value, key) => {
|
|
644
659
|
const childList = [...recurseList];
|
|
645
|
-
acc[key] = resolveAllReferences(
|
|
660
|
+
acc[key] = resolveAllReferences(
|
|
661
|
+
value,
|
|
662
|
+
rootSchema,
|
|
663
|
+
childList,
|
|
664
|
+
currentBaseURI,
|
|
665
|
+
resolveAnyOfOrOneOfRefs,
|
|
666
|
+
!resolveAnyOfOrOneOfRefs
|
|
667
|
+
);
|
|
646
668
|
childrenLists.push(childList);
|
|
647
669
|
},
|
|
648
670
|
{}
|
|
@@ -653,6 +675,7 @@ function resolveAllReferences(schema, rootSchema, recurseList, baseURI, resolveA
|
|
|
653
675
|
if (ITEMS_KEY in resolvedSchema && !Array.isArray(resolvedSchema.items) && typeof resolvedSchema.items !== "boolean") {
|
|
654
676
|
resolvedSchema = {
|
|
655
677
|
...resolvedSchema,
|
|
678
|
+
// Array items are only rendered when data exists, so a $ref cycle here does NOT cause an infinite render.
|
|
656
679
|
items: resolveAllReferences(
|
|
657
680
|
resolvedSchema.items,
|
|
658
681
|
rootSchema,
|
|
@@ -703,7 +726,7 @@ function stubExistingAdditionalProperties(validator, theSchema, rootSchema, aFor
|
|
|
703
726
|
get5(formData, [key]),
|
|
704
727
|
experimental_customMergeAllOf
|
|
705
728
|
);
|
|
706
|
-
|
|
729
|
+
schema.properties[key][ADDITIONAL_PROPERTY_FLAG] = true;
|
|
707
730
|
return;
|
|
708
731
|
}
|
|
709
732
|
}
|
|
@@ -715,7 +738,7 @@ function stubExistingAdditionalProperties(validator, theSchema, rootSchema, aFor
|
|
|
715
738
|
validator,
|
|
716
739
|
{ [REF_KEY]: get5(schema.additionalProperties, [REF_KEY]) },
|
|
717
740
|
rootSchema,
|
|
718
|
-
formData,
|
|
741
|
+
get5(formData, [key]),
|
|
719
742
|
experimental_customMergeAllOf
|
|
720
743
|
);
|
|
721
744
|
} else if ("type" in schema.additionalProperties) {
|
|
@@ -732,10 +755,10 @@ function stubExistingAdditionalProperties(validator, theSchema, rootSchema, aFor
|
|
|
732
755
|
additionalProperties = { type: guessType(get5(formData, [key])) };
|
|
733
756
|
}
|
|
734
757
|
schema.properties[key] = additionalProperties;
|
|
735
|
-
|
|
758
|
+
schema.properties[key][ADDITIONAL_PROPERTY_FLAG] = true;
|
|
736
759
|
} else {
|
|
737
760
|
schema.properties[key] = { type: "null" };
|
|
738
|
-
|
|
761
|
+
schema.properties[key][ADDITIONAL_PROPERTY_FLAG] = true;
|
|
739
762
|
}
|
|
740
763
|
});
|
|
741
764
|
return schema;
|
|
@@ -778,17 +801,26 @@ function retrieveSchemaInternal(validator, schema, rootSchema, rawFormData, expa
|
|
|
778
801
|
try {
|
|
779
802
|
const withContainsSchemas = [];
|
|
780
803
|
const withoutContainsSchemas = [];
|
|
804
|
+
const allOfSymbols = {};
|
|
781
805
|
resolvedSchema.allOf?.forEach((allOfItem) => {
|
|
782
806
|
if (typeof allOfItem === "object" && allOfItem.contains) {
|
|
783
807
|
withContainsSchemas.push(allOfItem);
|
|
784
808
|
} else {
|
|
785
809
|
withoutContainsSchemas.push(allOfItem);
|
|
810
|
+
for (const sym of Object.getOwnPropertySymbols(allOfItem)) {
|
|
811
|
+
if (!(sym in allOfSymbols)) {
|
|
812
|
+
allOfSymbols[sym] = allOfItem[sym];
|
|
813
|
+
}
|
|
814
|
+
}
|
|
786
815
|
}
|
|
787
816
|
});
|
|
788
817
|
if (withContainsSchemas.length) {
|
|
789
818
|
resolvedSchema = { ...resolvedSchema, allOf: withoutContainsSchemas };
|
|
790
819
|
}
|
|
791
820
|
resolvedSchema = experimental_customMergeAllOf ? experimental_customMergeAllOf(resolvedSchema) : mergeAllOf(resolvedSchema);
|
|
821
|
+
for (const sym of Object.getOwnPropertySymbols(allOfSymbols)) {
|
|
822
|
+
resolvedSchema[sym] = allOfSymbols[sym];
|
|
823
|
+
}
|
|
792
824
|
if (withContainsSchemas.length) {
|
|
793
825
|
resolvedSchema.allOf = withContainsSchemas;
|
|
794
826
|
}
|
|
@@ -857,7 +889,7 @@ function resolveAnyOrOneOfSchemas(validator, schema, rootSchema, expandAllBranch
|
|
|
857
889
|
function relaxOptionsForScoring(options, resolveRefs = false, rootSchema) {
|
|
858
890
|
return options.map((d) => {
|
|
859
891
|
if (!isObject(d)) {
|
|
860
|
-
return d
|
|
892
|
+
return normalizeBooleanSchema(d);
|
|
861
893
|
}
|
|
862
894
|
const schema = resolveRefs && rootSchema ? resolveAllReferences(d, rootSchema, []) : d;
|
|
863
895
|
return schema.additionalProperties === false ? { ...schema, additionalProperties: true } : schema;
|
|
@@ -971,7 +1003,7 @@ function withDependentSchema(validator, schema, rootSchema, dependencyKey, depen
|
|
|
971
1003
|
}
|
|
972
1004
|
function withExactlyOneSubschema(validator, schema, rootSchema, dependencyKey, oneOf, expandAllBranches, recurseList, formData, experimental_customMergeAllOf) {
|
|
973
1005
|
const validSubschemas = oneOf.filter((subschema) => {
|
|
974
|
-
if (typeof subschema === "boolean" || !subschema
|
|
1006
|
+
if (typeof subschema === "boolean" || !subschema?.properties) {
|
|
975
1007
|
return false;
|
|
976
1008
|
}
|
|
977
1009
|
const { [dependencyKey]: conditionPropertySchema } = subschema.properties;
|
|
@@ -1292,7 +1324,7 @@ function isConstant(schema) {
|
|
|
1292
1324
|
|
|
1293
1325
|
// src/isFixedItems.ts
|
|
1294
1326
|
function isFixedItems(schema) {
|
|
1295
|
-
return Array.isArray(schema.items) && schema.items.
|
|
1327
|
+
return Array.isArray(schema.items) && schema.items.every((item) => isObject(item));
|
|
1296
1328
|
}
|
|
1297
1329
|
|
|
1298
1330
|
// src/mergeDefaultsWithFormData.ts
|
|
@@ -1441,7 +1473,7 @@ function optionsList(schema, uiSchema) {
|
|
|
1441
1473
|
const { optionsSchemaSelector = selectorField } = getUiOptions(uiSchema);
|
|
1442
1474
|
selectorField = optionsSchemaSelector;
|
|
1443
1475
|
}
|
|
1444
|
-
return altSchemas
|
|
1476
|
+
return altSchemas?.map((aSchemaDef, index) => {
|
|
1445
1477
|
const { title } = getUiOptions(altUiSchemas?.[index]);
|
|
1446
1478
|
const aSchema = aSchemaDef;
|
|
1447
1479
|
let value;
|
|
@@ -1449,10 +1481,10 @@ function optionsList(schema, uiSchema) {
|
|
|
1449
1481
|
if (selectorField) {
|
|
1450
1482
|
const innerSchema = get11(aSchema, [PROPERTIES_KEY, selectorField], {});
|
|
1451
1483
|
value = get11(innerSchema, DEFAULT_KEY, get11(innerSchema, CONST_KEY));
|
|
1452
|
-
label = label
|
|
1484
|
+
label = label ?? innerSchema?.title ?? aSchema.title ?? String(value);
|
|
1453
1485
|
} else {
|
|
1454
1486
|
value = toConstant(aSchema);
|
|
1455
|
-
label = label
|
|
1487
|
+
label = label ?? aSchema.title ?? String(value);
|
|
1456
1488
|
}
|
|
1457
1489
|
return {
|
|
1458
1490
|
schema: aSchema,
|
|
@@ -1542,8 +1574,8 @@ function computeDefaults(validator, rawSchema, computeDefaultsProps = {}) {
|
|
|
1542
1574
|
rootSchema = {},
|
|
1543
1575
|
includeUndefinedValues = false,
|
|
1544
1576
|
_recurseList = [],
|
|
1545
|
-
experimental_defaultFormStateBehavior
|
|
1546
|
-
experimental_customMergeAllOf
|
|
1577
|
+
experimental_defaultFormStateBehavior,
|
|
1578
|
+
experimental_customMergeAllOf,
|
|
1547
1579
|
required,
|
|
1548
1580
|
shouldMergeDefaultsIntoFormData = false,
|
|
1549
1581
|
initialDefaultsGenerated
|
|
@@ -1551,14 +1583,19 @@ function computeDefaults(validator, rawSchema, computeDefaultsProps = {}) {
|
|
|
1551
1583
|
let formData = isObject(rawFormData) ? rawFormData : {};
|
|
1552
1584
|
const schema = isObject(rawSchema) ? rawSchema : {};
|
|
1553
1585
|
let defaults = parentDefaults;
|
|
1586
|
+
const preferParentDefaults = defaults && experimental_defaultFormStateBehavior?.nestedDefaultsPrecedence === "ancestorWins";
|
|
1554
1587
|
let schemaToCompute = null;
|
|
1555
1588
|
let experimental_dfsb_to_compute = experimental_defaultFormStateBehavior;
|
|
1556
1589
|
let updatedRecurseList = _recurseList;
|
|
1557
1590
|
if (schema[CONST_KEY] !== void 0 && experimental_defaultFormStateBehavior?.constAsDefaults !== "never" && !constIsAjvDataReference(schema)) {
|
|
1558
1591
|
defaults = schema[CONST_KEY];
|
|
1559
1592
|
} else if (isObject(defaults) && isObject(schema.default) && !schema[ANY_OF_KEY] && !schema[ONE_OF_KEY] && !schema[REF_KEY]) {
|
|
1560
|
-
|
|
1561
|
-
|
|
1593
|
+
if (preferParentDefaults) {
|
|
1594
|
+
defaults = mergeObjects(schema.default, defaults);
|
|
1595
|
+
} else {
|
|
1596
|
+
defaults = mergeObjects(defaults, schema.default);
|
|
1597
|
+
}
|
|
1598
|
+
} else if (DEFAULT_KEY in schema && !preferParentDefaults && !schema[ANY_OF_KEY] && !schema[ONE_OF_KEY] && !schema[REF_KEY]) {
|
|
1562
1599
|
defaults = schema.default;
|
|
1563
1600
|
} else if (REF_KEY in schema) {
|
|
1564
1601
|
const refName = schema[REF_KEY];
|
|
@@ -1588,7 +1625,7 @@ function computeDefaults(validator, rawSchema, computeDefaultsProps = {}) {
|
|
|
1588
1625
|
experimental_customMergeAllOf
|
|
1589
1626
|
);
|
|
1590
1627
|
[schemaToCompute] = resolvedSchema;
|
|
1591
|
-
} else if (isFixedItems(schema)) {
|
|
1628
|
+
} else if (isFixedItems(schema) && !preferParentDefaults) {
|
|
1592
1629
|
defaults = schema.items.map(
|
|
1593
1630
|
(itemSchema, idx) => computeDefaults(validator, itemSchema, {
|
|
1594
1631
|
rootSchema,
|
|
@@ -1684,16 +1721,36 @@ function computeDefaults(validator, rawSchema, computeDefaultsProps = {}) {
|
|
|
1684
1721
|
return defaultsWithFormData;
|
|
1685
1722
|
}
|
|
1686
1723
|
function ensureFormDataMatchingSchema(validator, schema, rootSchema, formData, experimental_defaultFormStateBehavior, experimental_customMergeAllOf) {
|
|
1687
|
-
const
|
|
1724
|
+
const shouldRetrieveAllOf = experimental_defaultFormStateBehavior?.allOf === "populateDefaults" && ALL_OF_KEY in schema;
|
|
1725
|
+
const schemaToMatch = shouldRetrieveAllOf ? retrieveSchema(validator, schema, rootSchema, formData, experimental_customMergeAllOf) : schema;
|
|
1726
|
+
const isSelectField = !isConstant(schemaToMatch) && isSelect(validator, schemaToMatch, rootSchema, experimental_customMergeAllOf);
|
|
1688
1727
|
let validFormData = formData;
|
|
1689
1728
|
if (isSelectField) {
|
|
1690
|
-
const getOptionsList = optionsList(
|
|
1729
|
+
const getOptionsList = optionsList(schemaToMatch);
|
|
1691
1730
|
const isValid = getOptionsList?.some((option) => deepEquals_default(option.value, formData));
|
|
1692
1731
|
validFormData = isValid ? formData : void 0;
|
|
1693
1732
|
}
|
|
1694
|
-
const constTakesPrecedence =
|
|
1733
|
+
const constTakesPrecedence = schemaToMatch[CONST_KEY] && experimental_defaultFormStateBehavior?.constAsDefaults === "always";
|
|
1695
1734
|
if (constTakesPrecedence) {
|
|
1696
|
-
validFormData =
|
|
1735
|
+
validFormData = schemaToMatch.const;
|
|
1736
|
+
} else if (isObject(validFormData) && isObject(schemaToMatch.properties)) {
|
|
1737
|
+
validFormData = Object.keys(schemaToMatch.properties).reduce(
|
|
1738
|
+
(acc, key) => {
|
|
1739
|
+
const propertySchema = get12(schemaToMatch, [PROPERTIES_KEY, key], {});
|
|
1740
|
+
if (key in acc && (shouldRetrieveAllOf || isObject(propertySchema) && ALL_OF_KEY in propertySchema)) {
|
|
1741
|
+
acc[key] = ensureFormDataMatchingSchema(
|
|
1742
|
+
validator,
|
|
1743
|
+
propertySchema,
|
|
1744
|
+
rootSchema,
|
|
1745
|
+
get12(acc, key),
|
|
1746
|
+
experimental_defaultFormStateBehavior,
|
|
1747
|
+
experimental_customMergeAllOf
|
|
1748
|
+
);
|
|
1749
|
+
}
|
|
1750
|
+
return acc;
|
|
1751
|
+
},
|
|
1752
|
+
{ ...validFormData }
|
|
1753
|
+
);
|
|
1697
1754
|
}
|
|
1698
1755
|
return validFormData;
|
|
1699
1756
|
}
|
|
@@ -1702,8 +1759,8 @@ function getObjectDefaults(validator, rawSchema, {
|
|
|
1702
1759
|
rootSchema = {},
|
|
1703
1760
|
includeUndefinedValues = false,
|
|
1704
1761
|
_recurseList = [],
|
|
1705
|
-
experimental_defaultFormStateBehavior
|
|
1706
|
-
experimental_customMergeAllOf
|
|
1762
|
+
experimental_defaultFormStateBehavior,
|
|
1763
|
+
experimental_customMergeAllOf,
|
|
1707
1764
|
required,
|
|
1708
1765
|
shouldMergeDefaultsIntoFormData,
|
|
1709
1766
|
initialDefaultsGenerated
|
|
@@ -1787,8 +1844,8 @@ function getArrayDefaults(validator, rawSchema, {
|
|
|
1787
1844
|
rawFormData,
|
|
1788
1845
|
rootSchema = {},
|
|
1789
1846
|
_recurseList = [],
|
|
1790
|
-
experimental_defaultFormStateBehavior
|
|
1791
|
-
experimental_customMergeAllOf
|
|
1847
|
+
experimental_defaultFormStateBehavior,
|
|
1848
|
+
experimental_customMergeAllOf,
|
|
1792
1849
|
required,
|
|
1793
1850
|
requiredAsRoot = false,
|
|
1794
1851
|
shouldMergeDefaultsIntoFormData,
|
|
@@ -1843,14 +1900,21 @@ function getArrayDefaults(validator, rawSchema, {
|
|
|
1843
1900
|
defaults = mergeDefaultsWithFormData(defaults, itemDefaults, mergeExtraDefaults);
|
|
1844
1901
|
}
|
|
1845
1902
|
}
|
|
1903
|
+
const defaultsLength = Array.isArray(defaults) ? defaults.length : 0;
|
|
1846
1904
|
if (neverPopulate) {
|
|
1905
|
+
if (shouldMergeDefaultsIntoFormData) {
|
|
1906
|
+
if (schema.minItems && schema.minItems > defaultsLength) {
|
|
1907
|
+
const fillerEntries = Array.from({ length: schema.minItems - defaultsLength }, () => null);
|
|
1908
|
+
return (defaults ?? []).concat(fillerEntries);
|
|
1909
|
+
}
|
|
1910
|
+
return defaults;
|
|
1911
|
+
}
|
|
1847
1912
|
return defaults ?? emptyDefault;
|
|
1848
1913
|
}
|
|
1849
1914
|
if (ignoreMinItemsFlagSet && !required) {
|
|
1850
1915
|
return defaults || void 0;
|
|
1851
1916
|
}
|
|
1852
1917
|
let arrayDefault;
|
|
1853
|
-
const defaultsLength = Array.isArray(defaults) ? defaults.length : 0;
|
|
1854
1918
|
if (!schema.minItems || isMultiSelect(validator, schema, rootSchema, experimental_customMergeAllOf) || computeSkipPopulate(validator, schema, rootSchema) || schema.minItems <= defaultsLength) {
|
|
1855
1919
|
arrayDefault = defaults || !required && !requiredAsRoot ? defaults : emptyDefault;
|
|
1856
1920
|
} else {
|
|
@@ -1910,9 +1974,17 @@ function getDefaultFormState(validator, theSchema, formData, rootSchema, include
|
|
|
1910
1974
|
if (isObject(formData) || Array.isArray(formData)) {
|
|
1911
1975
|
const { mergeDefaultsIntoFormData } = experimental_defaultFormStateBehavior || {};
|
|
1912
1976
|
const defaultSupercedesUndefined = mergeDefaultsIntoFormData === "useDefaultIfFormDataUndefined";
|
|
1977
|
+
const matchingFormData = ensureFormDataMatchingSchema(
|
|
1978
|
+
validator,
|
|
1979
|
+
schema,
|
|
1980
|
+
rootSchema ?? schema,
|
|
1981
|
+
formData,
|
|
1982
|
+
experimental_defaultFormStateBehavior,
|
|
1983
|
+
experimental_customMergeAllOf
|
|
1984
|
+
);
|
|
1913
1985
|
const result = mergeDefaultsWithFormData(
|
|
1914
1986
|
defaults,
|
|
1915
|
-
|
|
1987
|
+
matchingFormData,
|
|
1916
1988
|
true,
|
|
1917
1989
|
// set to true to add any additional default array entries.
|
|
1918
1990
|
defaultSupercedesUndefined,
|
|
@@ -1924,9 +1996,6 @@ function getDefaultFormState(validator, theSchema, formData, rootSchema, include
|
|
|
1924
1996
|
return defaults;
|
|
1925
1997
|
}
|
|
1926
1998
|
|
|
1927
|
-
// src/schema/getDisplayLabel.ts
|
|
1928
|
-
import get13 from "lodash/get";
|
|
1929
|
-
|
|
1930
1999
|
// src/isCustomWidget.ts
|
|
1931
2000
|
function isCustomWidget(uiSchema = {}) {
|
|
1932
2001
|
return (
|
|
@@ -1961,7 +2030,7 @@ function getDisplayLabel(validator, schema, uiSchema = {}, rootSchema, globalOpt
|
|
|
1961
2030
|
let displayLabel = Boolean(label);
|
|
1962
2031
|
if (displayLabel) {
|
|
1963
2032
|
const schemaType = getSchemaType(schema);
|
|
1964
|
-
const addedByAdditionalProperty =
|
|
2033
|
+
const addedByAdditionalProperty = Boolean(schema[ADDITIONAL_PROPERTY_FLAG]);
|
|
1965
2034
|
if (schemaType === "array") {
|
|
1966
2035
|
displayLabel = addedByAdditionalProperty || isMultiSelect(validator, schema, rootSchema, experimental_customMergeAllOf) || isFilesArray(validator, schema, uiSchema, rootSchema, experimental_customMergeAllOf) || isCustomWidget(uiSchema);
|
|
1967
2036
|
}
|
|
@@ -1971,7 +2040,7 @@ function getDisplayLabel(validator, schema, uiSchema = {}, rootSchema, globalOpt
|
|
|
1971
2040
|
if (schemaType === "boolean" && uiSchema && !uiSchema[UI_WIDGET_KEY]) {
|
|
1972
2041
|
displayLabel = false;
|
|
1973
2042
|
}
|
|
1974
|
-
if (uiSchema
|
|
2043
|
+
if (uiSchema?.[UI_FIELD_KEY]) {
|
|
1975
2044
|
displayLabel = false;
|
|
1976
2045
|
}
|
|
1977
2046
|
}
|
|
@@ -1979,7 +2048,7 @@ function getDisplayLabel(validator, schema, uiSchema = {}, rootSchema, globalOpt
|
|
|
1979
2048
|
}
|
|
1980
2049
|
|
|
1981
2050
|
// src/schema/omitExtraData.ts
|
|
1982
|
-
import
|
|
2051
|
+
import get13 from "lodash/get";
|
|
1983
2052
|
import isEmpty5 from "lodash/isEmpty";
|
|
1984
2053
|
import isNil2 from "lodash/isNil";
|
|
1985
2054
|
import pick from "lodash/pick";
|
|
@@ -2008,7 +2077,7 @@ function getFieldNames(pathSchema, formData) {
|
|
|
2008
2077
|
}
|
|
2009
2078
|
} else if (key === NAME_KEY && data !== "") {
|
|
2010
2079
|
paths.forEach((path) => {
|
|
2011
|
-
const formValue =
|
|
2080
|
+
const formValue = get13(formData, path);
|
|
2012
2081
|
const isLeaf = objKeys.length === 1;
|
|
2013
2082
|
if (formValueHasData(formValue, isLeaf) || Array.isArray(formValue) && formValue.every((val) => formValueHasData(val, isLeaf))) {
|
|
2014
2083
|
acc.push(path);
|
|
@@ -2046,7 +2115,7 @@ function omitExtraData(validator, schema, rootSchema = {}, formData, experimenta
|
|
|
2046
2115
|
const { properties, additionalProperties, patternProperties, propertyNames } = childSchema;
|
|
2047
2116
|
const requiredSet = new Set(childSchema.required ?? []);
|
|
2048
2117
|
function setProperty(key, schemaDef, value, required = false) {
|
|
2049
|
-
const v =
|
|
2118
|
+
const v = omit2(schemaDef, value, target[key]);
|
|
2050
2119
|
if (!required && isObject(v)) {
|
|
2051
2120
|
let sd = isSchemaObj(schemaDef) ? schemaDef : {};
|
|
2052
2121
|
if (sd.$ref !== void 0) {
|
|
@@ -2115,17 +2184,17 @@ function omitExtraData(validator, schema, rootSchema = {}, formData, experimenta
|
|
|
2115
2184
|
if (items !== void 0) {
|
|
2116
2185
|
if (Array.isArray(items)) {
|
|
2117
2186
|
for (let i = 0; i < items.length; i += 1) {
|
|
2118
|
-
target.push(
|
|
2187
|
+
target.push(omit2(items[i], source[i]));
|
|
2119
2188
|
}
|
|
2120
2189
|
} else {
|
|
2121
2190
|
for (let i = 0; i < source.length; i += 1) {
|
|
2122
|
-
target.push(
|
|
2191
|
+
target.push(omit2(items, source[i]));
|
|
2123
2192
|
}
|
|
2124
2193
|
}
|
|
2125
2194
|
}
|
|
2126
2195
|
if (additionalItems) {
|
|
2127
2196
|
for (let i = target.length; i < source.length; i += 1) {
|
|
2128
|
-
target.push(
|
|
2197
|
+
target.push(omit2(additionalItems, source[i]));
|
|
2129
2198
|
}
|
|
2130
2199
|
}
|
|
2131
2200
|
return target;
|
|
@@ -2137,7 +2206,7 @@ function omitExtraData(validator, schema, rootSchema = {}, formData, experimenta
|
|
|
2137
2206
|
}
|
|
2138
2207
|
const isThenBranch = isSchemaObj(condition) ? validator.isValid(condition, source, rootSchema) : condition;
|
|
2139
2208
|
const branch = isThenBranch ? then : otherwise;
|
|
2140
|
-
return branch === void 0 ? target :
|
|
2209
|
+
return branch === void 0 ? target : omit2(branch, source, target);
|
|
2141
2210
|
}
|
|
2142
2211
|
function handleOneOf(oneOf, childSchema, source, target) {
|
|
2143
2212
|
if (!Array.isArray(oneOf) || isSelect(validator, childSchema, rootSchema, experimental_customMergeAllOf)) {
|
|
@@ -2155,7 +2224,7 @@ function omitExtraData(validator, schema, rootSchema = {}, formData, experimenta
|
|
|
2155
2224
|
);
|
|
2156
2225
|
const winning = oneOf[bestIndex];
|
|
2157
2226
|
const resolved = isObject(winning) ? resolveAllReferences(winning, rootSchema, []) : scoringOptions[bestIndex];
|
|
2158
|
-
return
|
|
2227
|
+
return omit2(resolved, source, target);
|
|
2159
2228
|
}
|
|
2160
2229
|
function handleAnyOf(childSchema, source, target) {
|
|
2161
2230
|
const { anyOf } = childSchema;
|
|
@@ -2165,7 +2234,7 @@ function omitExtraData(validator, schema, rootSchema = {}, formData, experimenta
|
|
|
2165
2234
|
if (source === void 0 || Array.isArray(source) && source.length === 0 || isObject(source) && Object.keys(source).length === 0) {
|
|
2166
2235
|
let result = target;
|
|
2167
2236
|
for (const branch of anyOf) {
|
|
2168
|
-
result =
|
|
2237
|
+
result = omit2(branch, source, result);
|
|
2169
2238
|
}
|
|
2170
2239
|
return result;
|
|
2171
2240
|
}
|
|
@@ -2179,12 +2248,12 @@ function omitExtraData(validator, schema, rootSchema = {}, formData, experimenta
|
|
|
2179
2248
|
let result = target;
|
|
2180
2249
|
for (const [key, deps] of Object.entries(dependencies)) {
|
|
2181
2250
|
if (key in source && !Array.isArray(deps)) {
|
|
2182
|
-
result =
|
|
2251
|
+
result = omit2(deps, source, result);
|
|
2183
2252
|
}
|
|
2184
2253
|
}
|
|
2185
2254
|
return result;
|
|
2186
2255
|
}
|
|
2187
|
-
function
|
|
2256
|
+
function omit2(schemaDef, source, target) {
|
|
2188
2257
|
if (source === void 0 || schemaDef === false) {
|
|
2189
2258
|
return void 0;
|
|
2190
2259
|
}
|
|
@@ -2194,10 +2263,16 @@ function omitExtraData(validator, schema, rootSchema = {}, formData, experimenta
|
|
|
2194
2263
|
let localSchema = schemaDef;
|
|
2195
2264
|
const { $ref: ref, allOf } = localSchema;
|
|
2196
2265
|
if (ref !== void 0) {
|
|
2197
|
-
return
|
|
2266
|
+
return omit2(findSchemaDefinition(ref, rootSchema), source, target);
|
|
2198
2267
|
}
|
|
2199
2268
|
if (allOf) {
|
|
2200
2269
|
localSchema = doMergeAllOf(localSchema, experimental_customMergeAllOf);
|
|
2270
|
+
const remainingAllOf = localSchema.allOf;
|
|
2271
|
+
if (remainingAllOf) {
|
|
2272
|
+
for (let i = 0; i < remainingAllOf.length; i++) {
|
|
2273
|
+
target = omit2(remainingAllOf[i], source, target);
|
|
2274
|
+
}
|
|
2275
|
+
}
|
|
2201
2276
|
}
|
|
2202
2277
|
let filtered = handleAnyOf(localSchema, source, handleOneOf(localSchema.oneOf, localSchema, source, target));
|
|
2203
2278
|
const type = getSchemaType(localSchema);
|
|
@@ -2216,11 +2291,11 @@ function omitExtraData(validator, schema, rootSchema = {}, formData, experimenta
|
|
|
2216
2291
|
}
|
|
2217
2292
|
return handleDependencies(localSchema, source, handleConditions(localSchema, source, filtered));
|
|
2218
2293
|
}
|
|
2219
|
-
return
|
|
2294
|
+
return omit2(schema, formData);
|
|
2220
2295
|
}
|
|
2221
2296
|
|
|
2222
2297
|
// src/schema/sanitizeDataForNewSchema.ts
|
|
2223
|
-
import
|
|
2298
|
+
import get14 from "lodash/get";
|
|
2224
2299
|
import has5 from "lodash/has";
|
|
2225
2300
|
var NO_VALUE = /* @__PURE__ */ Symbol("no Value");
|
|
2226
2301
|
function enumValuesForSchema(schema) {
|
|
@@ -2244,7 +2319,7 @@ function replacementForInvalidEnumValue(schema, formValue) {
|
|
|
2244
2319
|
if (!enumValues || enumValues.some((value) => deepEquals_default(value, formValue))) {
|
|
2245
2320
|
return NO_VALUE;
|
|
2246
2321
|
}
|
|
2247
|
-
const defaultValue =
|
|
2322
|
+
const defaultValue = get14(schema, DEFAULT_KEY, NO_VALUE);
|
|
2248
2323
|
if (defaultValue !== NO_VALUE && enumValues.some((value) => deepEquals_default(value, defaultValue))) {
|
|
2249
2324
|
return defaultValue;
|
|
2250
2325
|
}
|
|
@@ -2255,19 +2330,19 @@ function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, d
|
|
|
2255
2330
|
if (has5(newSchema, PROPERTIES_KEY)) {
|
|
2256
2331
|
const removeOldSchemaData = {};
|
|
2257
2332
|
if (has5(oldSchema, PROPERTIES_KEY)) {
|
|
2258
|
-
const properties =
|
|
2333
|
+
const properties = get14(oldSchema, PROPERTIES_KEY, {});
|
|
2259
2334
|
Object.keys(properties).forEach((key) => {
|
|
2260
2335
|
if (has5(data, key)) {
|
|
2261
2336
|
removeOldSchemaData[key] = void 0;
|
|
2262
2337
|
}
|
|
2263
2338
|
});
|
|
2264
2339
|
}
|
|
2265
|
-
const keys2 = Object.keys(
|
|
2340
|
+
const keys2 = Object.keys(get14(newSchema, PROPERTIES_KEY, {}));
|
|
2266
2341
|
const nestedData = {};
|
|
2267
2342
|
keys2.forEach((key) => {
|
|
2268
|
-
const formValue =
|
|
2269
|
-
let oldKeyedSchema =
|
|
2270
|
-
let newKeyedSchema =
|
|
2343
|
+
const formValue = get14(data, key);
|
|
2344
|
+
let oldKeyedSchema = get14(oldSchema, [PROPERTIES_KEY, key], {});
|
|
2345
|
+
let newKeyedSchema = get14(newSchema, [PROPERTIES_KEY, key], {});
|
|
2271
2346
|
if (has5(oldKeyedSchema, REF_KEY)) {
|
|
2272
2347
|
oldKeyedSchema = retrieveSchema(
|
|
2273
2348
|
validator,
|
|
@@ -2286,8 +2361,8 @@ function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, d
|
|
|
2286
2361
|
experimental_customMergeAllOf
|
|
2287
2362
|
);
|
|
2288
2363
|
}
|
|
2289
|
-
const oldSchemaTypeForKey =
|
|
2290
|
-
const newSchemaTypeForKey =
|
|
2364
|
+
const oldSchemaTypeForKey = get14(oldKeyedSchema, "type");
|
|
2365
|
+
const newSchemaTypeForKey = get14(newKeyedSchema, "type");
|
|
2291
2366
|
if (!oldSchemaTypeForKey || oldSchemaTypeForKey === newSchemaTypeForKey) {
|
|
2292
2367
|
if (has5(removeOldSchemaData, key)) {
|
|
2293
2368
|
delete removeOldSchemaData[key];
|
|
@@ -2305,17 +2380,17 @@ function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, d
|
|
|
2305
2380
|
nestedData[key] = itemData;
|
|
2306
2381
|
}
|
|
2307
2382
|
} else {
|
|
2308
|
-
const newOptionDefault =
|
|
2309
|
-
const oldOptionDefault =
|
|
2383
|
+
const newOptionDefault = get14(newKeyedSchema, DEFAULT_KEY, NO_VALUE);
|
|
2384
|
+
const oldOptionDefault = get14(oldKeyedSchema, DEFAULT_KEY, NO_VALUE);
|
|
2310
2385
|
if (newOptionDefault !== NO_VALUE && newOptionDefault !== formValue) {
|
|
2311
2386
|
if (oldOptionDefault === formValue) {
|
|
2312
2387
|
removeOldSchemaData[key] = newOptionDefault;
|
|
2313
|
-
} else if (
|
|
2388
|
+
} else if (get14(newKeyedSchema, "readOnly") === true) {
|
|
2314
2389
|
removeOldSchemaData[key] = void 0;
|
|
2315
2390
|
}
|
|
2316
2391
|
}
|
|
2317
|
-
const newOptionConst =
|
|
2318
|
-
const oldOptionConst =
|
|
2392
|
+
const newOptionConst = get14(newKeyedSchema, CONST_KEY, NO_VALUE);
|
|
2393
|
+
const oldOptionConst = get14(oldKeyedSchema, CONST_KEY, NO_VALUE);
|
|
2319
2394
|
if (newOptionConst !== NO_VALUE && newOptionConst !== formValue) {
|
|
2320
2395
|
removeOldSchemaData[key] = oldOptionConst === formValue ? newOptionConst : void 0;
|
|
2321
2396
|
}
|
|
@@ -2333,9 +2408,9 @@ function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, d
|
|
|
2333
2408
|
...removeOldSchemaData,
|
|
2334
2409
|
...nestedData
|
|
2335
2410
|
};
|
|
2336
|
-
} else if (
|
|
2337
|
-
let oldSchemaItems =
|
|
2338
|
-
let newSchemaItems =
|
|
2411
|
+
} else if (get14(oldSchema, "type") === "array" && get14(newSchema, "type") === "array" && Array.isArray(data)) {
|
|
2412
|
+
let oldSchemaItems = get14(oldSchema, "items");
|
|
2413
|
+
let newSchemaItems = get14(newSchema, "items");
|
|
2339
2414
|
if (typeof oldSchemaItems === "object" && typeof newSchemaItems === "object" && !Array.isArray(oldSchemaItems) && !Array.isArray(newSchemaItems)) {
|
|
2340
2415
|
if (has5(oldSchemaItems, REF_KEY)) {
|
|
2341
2416
|
oldSchemaItems = retrieveSchema(
|
|
@@ -2355,10 +2430,10 @@ function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, d
|
|
|
2355
2430
|
experimental_customMergeAllOf
|
|
2356
2431
|
);
|
|
2357
2432
|
}
|
|
2358
|
-
const oldSchemaType =
|
|
2359
|
-
const newSchemaType =
|
|
2433
|
+
const oldSchemaType = get14(oldSchemaItems, "type");
|
|
2434
|
+
const newSchemaType = get14(newSchemaItems, "type");
|
|
2360
2435
|
if (!oldSchemaType || oldSchemaType === newSchemaType) {
|
|
2361
|
-
const maxItems =
|
|
2436
|
+
const maxItems = get14(newSchema, "maxItems", -1);
|
|
2362
2437
|
if (newSchemaType === "object") {
|
|
2363
2438
|
newFormData = data.reduce((newValue, aValue) => {
|
|
2364
2439
|
const itemValue = sanitizeDataForNewSchema(
|
|
@@ -2388,7 +2463,7 @@ function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, d
|
|
|
2388
2463
|
}
|
|
2389
2464
|
|
|
2390
2465
|
// src/schema/toPathSchema.ts
|
|
2391
|
-
import
|
|
2466
|
+
import get15 from "lodash/get";
|
|
2392
2467
|
import isObject4 from "lodash/isObject";
|
|
2393
2468
|
import set2 from "lodash/set";
|
|
2394
2469
|
function toPathSchemaInternal(validator, schema, name, rootSchema, formData, _recurseList = [], experimental_customMergeAllOf) {
|
|
@@ -2439,7 +2514,7 @@ function toPathSchemaInternal(validator, schema, name, rootSchema, formData, _re
|
|
|
2439
2514
|
if (ADDITIONAL_PROPERTIES_KEY in schema && schema[ADDITIONAL_PROPERTIES_KEY] !== false) {
|
|
2440
2515
|
set2(pathSchema, RJSF_ADDITIONAL_PROPERTIES_FLAG, true);
|
|
2441
2516
|
const additionalSchema = isObject4(schema[ADDITIONAL_PROPERTIES_KEY]) ? schema[ADDITIONAL_PROPERTIES_KEY] : {};
|
|
2442
|
-
const definedProperties =
|
|
2517
|
+
const definedProperties = get15(schema, PROPERTIES_KEY, {});
|
|
2443
2518
|
for (const key of Object.keys(formData ?? {})) {
|
|
2444
2519
|
if (!(key in definedProperties)) {
|
|
2445
2520
|
pathSchema[key] = toPathSchemaInternal(
|
|
@@ -2447,7 +2522,7 @@ function toPathSchemaInternal(validator, schema, name, rootSchema, formData, _re
|
|
|
2447
2522
|
additionalSchema,
|
|
2448
2523
|
`${name}.${key}`,
|
|
2449
2524
|
rootSchema,
|
|
2450
|
-
|
|
2525
|
+
get15(formData, [key]),
|
|
2451
2526
|
_recurseList,
|
|
2452
2527
|
experimental_customMergeAllOf
|
|
2453
2528
|
);
|
|
@@ -2497,7 +2572,7 @@ function toPathSchemaInternal(validator, schema, name, rootSchema, formData, _re
|
|
|
2497
2572
|
}
|
|
2498
2573
|
} else if (PROPERTIES_KEY in schema) {
|
|
2499
2574
|
for (const property in schema.properties) {
|
|
2500
|
-
const field =
|
|
2575
|
+
const field = get15(schema, [PROPERTIES_KEY, property], {});
|
|
2501
2576
|
pathSchema[property] = toPathSchemaInternal(
|
|
2502
2577
|
validator,
|
|
2503
2578
|
field,
|
|
@@ -2505,7 +2580,7 @@ function toPathSchemaInternal(validator, schema, name, rootSchema, formData, _re
|
|
|
2505
2580
|
rootSchema,
|
|
2506
2581
|
// It's possible that formData is not an object -- this can happen if an
|
|
2507
2582
|
// array item has just been added, but not populated with data yet
|
|
2508
|
-
|
|
2583
|
+
get15(formData, [property]),
|
|
2509
2584
|
_recurseList,
|
|
2510
2585
|
experimental_customMergeAllOf
|
|
2511
2586
|
);
|
|
@@ -2527,8 +2602,8 @@ var SchemaUtils = class {
|
|
|
2527
2602
|
* @param [experimental_customMergeAllOf] - Optional function that allows for custom merging of `allOf` schemas
|
|
2528
2603
|
*/
|
|
2529
2604
|
constructor(validator, rootSchema, experimental_defaultFormStateBehavior, experimental_customMergeAllOf) {
|
|
2530
|
-
if (rootSchema
|
|
2531
|
-
this.rootSchema = makeAllReferencesAbsolute(rootSchema,
|
|
2605
|
+
if (rootSchema?.[SCHEMA_KEY] === JSON_SCHEMA_DRAFT_2020_12) {
|
|
2606
|
+
this.rootSchema = makeAllReferencesAbsolute(rootSchema, get16(rootSchema, ID_KEY, "#"));
|
|
2532
2607
|
} else {
|
|
2533
2608
|
this.rootSchema = rootSchema;
|
|
2534
2609
|
}
|
|
@@ -2985,7 +3060,7 @@ function enumOptionValueEncoder(value, index, format = "indexed") {
|
|
|
2985
3060
|
|
|
2986
3061
|
// src/ErrorSchemaBuilder.ts
|
|
2987
3062
|
import cloneDeep from "lodash/cloneDeep";
|
|
2988
|
-
import
|
|
3063
|
+
import get17 from "lodash/get";
|
|
2989
3064
|
import set3 from "lodash/set";
|
|
2990
3065
|
import setWith from "lodash/setWith";
|
|
2991
3066
|
var ErrorSchemaBuilder = class {
|
|
@@ -3014,7 +3089,7 @@ var ErrorSchemaBuilder = class {
|
|
|
3014
3089
|
*/
|
|
3015
3090
|
getOrCreateErrorBlock(pathOfError) {
|
|
3016
3091
|
const hasPath = Array.isArray(pathOfError) && pathOfError.length > 0 || typeof pathOfError === "string";
|
|
3017
|
-
let errorBlock = hasPath ?
|
|
3092
|
+
let errorBlock = hasPath ? get17(this.errorSchema, pathOfError) : this.errorSchema;
|
|
3018
3093
|
if (!errorBlock && pathOfError) {
|
|
3019
3094
|
errorBlock = {};
|
|
3020
3095
|
setWith(this.errorSchema, pathOfError, errorBlock, Object);
|
|
@@ -3040,7 +3115,7 @@ var ErrorSchemaBuilder = class {
|
|
|
3040
3115
|
*/
|
|
3041
3116
|
addErrors(errorOrList, pathOfError) {
|
|
3042
3117
|
const errorBlock = this.getOrCreateErrorBlock(pathOfError);
|
|
3043
|
-
let errorsList =
|
|
3118
|
+
let errorsList = get17(errorBlock, ERRORS_KEY);
|
|
3044
3119
|
if (!Array.isArray(errorsList)) {
|
|
3045
3120
|
errorsList = [];
|
|
3046
3121
|
errorBlock[ERRORS_KEY] = errorsList;
|
|
@@ -3082,7 +3157,7 @@ var ErrorSchemaBuilder = class {
|
|
|
3082
3157
|
|
|
3083
3158
|
// src/getChangedFields.ts
|
|
3084
3159
|
import difference from "lodash/difference";
|
|
3085
|
-
import
|
|
3160
|
+
import get18 from "lodash/get";
|
|
3086
3161
|
import isPlainObject2 from "lodash/isPlainObject";
|
|
3087
3162
|
import keys from "lodash/keys";
|
|
3088
3163
|
import pickBy from "lodash/pickBy";
|
|
@@ -3098,7 +3173,7 @@ function getChangedFields(a, b) {
|
|
|
3098
3173
|
if (!aIsPlainObject && bIsPlainObject) {
|
|
3099
3174
|
return keys(b);
|
|
3100
3175
|
}
|
|
3101
|
-
const unequalFields = keys(pickBy(a, (value, key) => !deepEquals_default(value,
|
|
3176
|
+
const unequalFields = keys(pickBy(a, (value, key) => !deepEquals_default(value, get18(b, key))));
|
|
3102
3177
|
const diffFields = difference(keys(b), keys(a));
|
|
3103
3178
|
return [...unequalFields, ...diffFields];
|
|
3104
3179
|
}
|
|
@@ -3199,7 +3274,7 @@ var DEFAULT_OPTIONS = {
|
|
|
3199
3274
|
};
|
|
3200
3275
|
function getSubmitButtonOptions(uiSchema = {}) {
|
|
3201
3276
|
const uiOptions = getUiOptions(uiSchema);
|
|
3202
|
-
if (uiOptions
|
|
3277
|
+
if (uiOptions?.[SUBMIT_BTN_OPTIONS_KEY]) {
|
|
3203
3278
|
const options = uiOptions[SUBMIT_BTN_OPTIONS_KEY];
|
|
3204
3279
|
return { ...DEFAULT_OPTIONS, ...options };
|
|
3205
3280
|
}
|
|
@@ -3224,10 +3299,10 @@ function getTemplate(name, registry, uiOptions = {}) {
|
|
|
3224
3299
|
}
|
|
3225
3300
|
|
|
3226
3301
|
// src/getTestIds.ts
|
|
3227
|
-
import
|
|
3302
|
+
import get19 from "lodash/get";
|
|
3228
3303
|
import uniqueId from "lodash/uniqueId";
|
|
3229
3304
|
function getTestIds() {
|
|
3230
|
-
if (
|
|
3305
|
+
if (get19(globalThis, "process.env.NODE_ENV") !== "test") {
|
|
3231
3306
|
return {};
|
|
3232
3307
|
}
|
|
3233
3308
|
const ids = /* @__PURE__ */ new Map();
|
|
@@ -3246,7 +3321,7 @@ function getTestIds() {
|
|
|
3246
3321
|
|
|
3247
3322
|
// src/getWidget.tsx
|
|
3248
3323
|
import { createElement } from "react";
|
|
3249
|
-
import
|
|
3324
|
+
import get20 from "lodash/get";
|
|
3250
3325
|
import set4 from "lodash/set";
|
|
3251
3326
|
import ReactIs from "react-is";
|
|
3252
3327
|
import { jsx } from "react/jsx-runtime";
|
|
@@ -3303,9 +3378,9 @@ var widgetMap = {
|
|
|
3303
3378
|
}
|
|
3304
3379
|
};
|
|
3305
3380
|
function mergeWidgetOptions(AWidget) {
|
|
3306
|
-
let MergedWidget =
|
|
3381
|
+
let MergedWidget = get20(AWidget, "MergedWidget");
|
|
3307
3382
|
if (!MergedWidget) {
|
|
3308
|
-
const defaultOptions = AWidget.defaultProps
|
|
3383
|
+
const defaultOptions = AWidget.defaultProps?.options || {};
|
|
3309
3384
|
MergedWidget = ({ options, ...props }) => /* @__PURE__ */ jsx(AWidget, { options: { ...defaultOptions, ...options }, ...props });
|
|
3310
3385
|
set4(AWidget, "MergedWidget", MergedWidget);
|
|
3311
3386
|
}
|
|
@@ -3357,7 +3432,7 @@ function hashObject(object) {
|
|
|
3357
3432
|
return hashString(sortedJSONStringify(object));
|
|
3358
3433
|
}
|
|
3359
3434
|
function hashForSchema(schema) {
|
|
3360
|
-
return
|
|
3435
|
+
return hashString(sortedJSONStringify(schema));
|
|
3361
3436
|
}
|
|
3362
3437
|
|
|
3363
3438
|
// src/hasWidget.ts
|
|
@@ -3418,7 +3493,6 @@ function isFormDataAvailable(formData) {
|
|
|
3418
3493
|
}
|
|
3419
3494
|
|
|
3420
3495
|
// src/isRootSchema.ts
|
|
3421
|
-
import omit2 from "lodash/omit";
|
|
3422
3496
|
function isRootSchema(registry, schemaToCompare) {
|
|
3423
3497
|
const { rootSchema, schemaUtils } = registry;
|
|
3424
3498
|
if (deepEquals_default(schemaToCompare, rootSchema)) {
|
|
@@ -3426,7 +3500,7 @@ function isRootSchema(registry, schemaToCompare) {
|
|
|
3426
3500
|
}
|
|
3427
3501
|
if (REF_KEY in rootSchema) {
|
|
3428
3502
|
const resolvedSchema = schemaUtils.retrieveSchema(rootSchema);
|
|
3429
|
-
return deepEquals_default(schemaToCompare,
|
|
3503
|
+
return deepEquals_default(schemaToCompare, resolvedSchema);
|
|
3430
3504
|
}
|
|
3431
3505
|
return false;
|
|
3432
3506
|
}
|
|
@@ -3441,15 +3515,24 @@ function localToUTC(dateString) {
|
|
|
3441
3515
|
return dateString ? new Date(dateString).toJSON() : void 0;
|
|
3442
3516
|
}
|
|
3443
3517
|
|
|
3518
|
+
// src/logUnsupportedDefaultForEnum.ts
|
|
3519
|
+
function logUnsupportedDefaultForEnum(id, schema, enumOptions, multiple = false) {
|
|
3520
|
+
if (!multiple && Array.isArray(enumOptions) && schema.default !== void 0 && enumOptionsIndexForValue(schema.default, enumOptions, multiple) === void 0) {
|
|
3521
|
+
console.error(
|
|
3522
|
+
`The schema default value "${schema.default}" is not one of the values in the enum options for "${id}"`
|
|
3523
|
+
);
|
|
3524
|
+
}
|
|
3525
|
+
}
|
|
3526
|
+
|
|
3444
3527
|
// src/lookupFromFormContext.ts
|
|
3445
|
-
import
|
|
3528
|
+
import get21 from "lodash/get";
|
|
3446
3529
|
import has6 from "lodash/has";
|
|
3447
3530
|
function lookupFromFormContext(regOrFc, toLookup, fallback) {
|
|
3448
3531
|
const lookupPath = [LOOKUP_MAP_NAME];
|
|
3449
3532
|
if (has6(regOrFc, FORM_CONTEXT_NAME)) {
|
|
3450
3533
|
lookupPath.unshift(FORM_CONTEXT_NAME);
|
|
3451
3534
|
}
|
|
3452
|
-
return
|
|
3535
|
+
return get21(regOrFc, [...lookupPath, toLookup], fallback);
|
|
3453
3536
|
}
|
|
3454
3537
|
|
|
3455
3538
|
// src/nameGenerators.ts
|
|
@@ -3638,13 +3721,13 @@ function schemaRequiresTrueValue(schema) {
|
|
|
3638
3721
|
if (schema.const) {
|
|
3639
3722
|
return true;
|
|
3640
3723
|
}
|
|
3641
|
-
if (schema.enum
|
|
3724
|
+
if (schema.enum?.length === 1 && schema.enum[0] === true) {
|
|
3642
3725
|
return true;
|
|
3643
3726
|
}
|
|
3644
|
-
if (schema.anyOf
|
|
3727
|
+
if (schema.anyOf?.length === 1) {
|
|
3645
3728
|
return schemaRequiresTrueValue(schema.anyOf[0]);
|
|
3646
3729
|
}
|
|
3647
|
-
if (schema.oneOf
|
|
3730
|
+
if (schema.oneOf?.length === 1) {
|
|
3648
3731
|
return schemaRequiresTrueValue(schema.oneOf[0]);
|
|
3649
3732
|
}
|
|
3650
3733
|
if (schema.allOf) {
|
|
@@ -3654,6 +3737,38 @@ function schemaRequiresTrueValue(schema) {
|
|
|
3654
3737
|
return false;
|
|
3655
3738
|
}
|
|
3656
3739
|
|
|
3740
|
+
// src/SelectedOptionDescription.tsx
|
|
3741
|
+
import { jsx as jsx2 } from "react/jsx-runtime";
|
|
3742
|
+
function SelectedOptionDescription({ hideLabel, id, multiple, options, registry, uiSchema, value }) {
|
|
3743
|
+
if (multiple || hideLabel) {
|
|
3744
|
+
return null;
|
|
3745
|
+
}
|
|
3746
|
+
const { label = true } = getUiOptions(uiSchema, registry.globalUiOptions);
|
|
3747
|
+
if (!label) {
|
|
3748
|
+
return null;
|
|
3749
|
+
}
|
|
3750
|
+
const option = options.enumOptions?.find(({ value: enumValue }) => enumOptionsIsSelected(enumValue, value));
|
|
3751
|
+
const description = option?.schema?.description;
|
|
3752
|
+
if (!description) {
|
|
3753
|
+
return null;
|
|
3754
|
+
}
|
|
3755
|
+
const DescriptionFieldTemplate = getTemplate(
|
|
3756
|
+
"DescriptionFieldTemplate",
|
|
3757
|
+
registry,
|
|
3758
|
+
options
|
|
3759
|
+
);
|
|
3760
|
+
return /* @__PURE__ */ jsx2(
|
|
3761
|
+
DescriptionFieldTemplate,
|
|
3762
|
+
{
|
|
3763
|
+
id: descriptionId(id),
|
|
3764
|
+
description,
|
|
3765
|
+
schema: option.schema,
|
|
3766
|
+
uiSchema,
|
|
3767
|
+
registry
|
|
3768
|
+
}
|
|
3769
|
+
);
|
|
3770
|
+
}
|
|
3771
|
+
|
|
3657
3772
|
// src/shallowEquals.ts
|
|
3658
3773
|
function shallowEquals(a, b) {
|
|
3659
3774
|
if (Object.is(a, b)) {
|
|
@@ -3804,7 +3919,7 @@ function unwrapErrorHandler(errorHandler) {
|
|
|
3804
3919
|
|
|
3805
3920
|
// src/useAltDateWidgetProps.tsx
|
|
3806
3921
|
import { useCallback, useEffect, useMemo, useState } from "react";
|
|
3807
|
-
import { jsx as
|
|
3922
|
+
import { jsx as jsx3 } from "react/jsx-runtime";
|
|
3808
3923
|
function readyForChange(state) {
|
|
3809
3924
|
return Object.values(state).every((value) => value !== -1);
|
|
3810
3925
|
}
|
|
@@ -3827,7 +3942,7 @@ function DateElement(props) {
|
|
|
3827
3942
|
const id = `${rootId}_${type}`;
|
|
3828
3943
|
const { SelectWidget } = registry.widgets;
|
|
3829
3944
|
const onChange = useCallback((newValue) => select(type, newValue), [select, type]);
|
|
3830
|
-
return /* @__PURE__ */
|
|
3945
|
+
return /* @__PURE__ */ jsx3(
|
|
3831
3946
|
SelectWidget,
|
|
3832
3947
|
{
|
|
3833
3948
|
schema: { type: "integer" },
|
|
@@ -3917,7 +4032,7 @@ import { useCallback as useCallback2, useMemo as useMemo2 } from "react";
|
|
|
3917
4032
|
function addNameToDataURL(dataURL, name) {
|
|
3918
4033
|
return dataURL.replace(";base64", `;name=${encodeURIComponent(name)};base64`);
|
|
3919
4034
|
}
|
|
3920
|
-
function processFile(file) {
|
|
4035
|
+
async function processFile(file) {
|
|
3921
4036
|
const { name, size, type } = file;
|
|
3922
4037
|
return new Promise((resolve, reject) => {
|
|
3923
4038
|
const reader = new window.FileReader();
|
|
@@ -3942,7 +4057,7 @@ function processFile(file) {
|
|
|
3942
4057
|
reader.readAsDataURL(file);
|
|
3943
4058
|
});
|
|
3944
4059
|
}
|
|
3945
|
-
function processFiles(files) {
|
|
4060
|
+
async function processFiles(files) {
|
|
3946
4061
|
return Promise.all(Array.from(files).map(processFile));
|
|
3947
4062
|
}
|
|
3948
4063
|
function extractFileInfo(dataURLs) {
|
|
@@ -4081,6 +4196,7 @@ var TranslatableString = /* @__PURE__ */ ((TranslatableString2) => {
|
|
|
4081
4196
|
TranslatableString2["AddButton"] = "Add";
|
|
4082
4197
|
TranslatableString2["AddItemButton"] = "Add Item";
|
|
4083
4198
|
TranslatableString2["CopyButton"] = "Copy";
|
|
4199
|
+
TranslatableString2["ExpandButton"] = "Expand Cycle";
|
|
4084
4200
|
TranslatableString2["MoveDownButton"] = "Move down";
|
|
4085
4201
|
TranslatableString2["MoveUpButton"] = "Move up";
|
|
4086
4202
|
TranslatableString2["RemoveButton"] = "Remove";
|
|
@@ -4101,6 +4217,7 @@ var TranslatableString = /* @__PURE__ */ ((TranslatableString2) => {
|
|
|
4101
4217
|
TranslatableString2["TitleOptionPrefix"] = "%1 option %2";
|
|
4102
4218
|
TranslatableString2["KeyLabel"] = "%1 Key";
|
|
4103
4219
|
TranslatableString2["DeprecatedLabel"] = "%1 (deprecated)";
|
|
4220
|
+
TranslatableString2["CycleDetected"] = 'Circular reference ($ref cycle) detected for field "%1". You may choose to expand to the next cycle break';
|
|
4104
4221
|
TranslatableString2["InvalidObjectField"] = 'Invalid "%1" object field configuration: _%2_.';
|
|
4105
4222
|
TranslatableString2["UnsupportedField"] = "Unsupported field schema.";
|
|
4106
4223
|
TranslatableString2["UnsupportedFieldWithId"] = "Unsupported field schema for field `%1`.";
|
|
@@ -4114,7 +4231,7 @@ var TranslatableString = /* @__PURE__ */ ((TranslatableString2) => {
|
|
|
4114
4231
|
import forEach from "lodash/forEach";
|
|
4115
4232
|
|
|
4116
4233
|
// src/parser/ParserValidator.ts
|
|
4117
|
-
import
|
|
4234
|
+
import get22 from "lodash/get";
|
|
4118
4235
|
var ParserValidator = class {
|
|
4119
4236
|
/** Construct the ParserValidator for the given `rootSchema`. This `rootSchema` will be stashed in the `schemaMap`
|
|
4120
4237
|
* first.
|
|
@@ -4140,7 +4257,7 @@ var ParserValidator = class {
|
|
|
4140
4257
|
* @param hash - The hash value at which to map the schema
|
|
4141
4258
|
*/
|
|
4142
4259
|
addSchema(schema, hash) {
|
|
4143
|
-
const key =
|
|
4260
|
+
const key = get22(schema, ID_KEY, hash);
|
|
4144
4261
|
const identifiedSchema = { ...schema, [ID_KEY]: key };
|
|
4145
4262
|
const existing = this.schemaMap[key];
|
|
4146
4263
|
if (!existing) {
|
|
@@ -4262,10 +4379,13 @@ export {
|
|
|
4262
4379
|
REF_KEY,
|
|
4263
4380
|
REQUIRED_KEY,
|
|
4264
4381
|
RJSF_ADDITIONAL_PROPERTIES_FLAG,
|
|
4382
|
+
RJSF_PREFIX_KEY,
|
|
4383
|
+
RJSF_REF_CYCLE_KEY,
|
|
4265
4384
|
RJSF_REF_KEY,
|
|
4266
4385
|
ROOT_SCHEMA_PREFIX,
|
|
4267
4386
|
SCHEMA_KEY,
|
|
4268
4387
|
SUBMIT_BTN_OPTIONS_KEY,
|
|
4388
|
+
SelectedOptionDescription,
|
|
4269
4389
|
TranslatableString,
|
|
4270
4390
|
UI_DEFINITIONS_KEY,
|
|
4271
4391
|
UI_FIELD_KEY,
|
|
@@ -4336,6 +4456,7 @@ export {
|
|
|
4336
4456
|
isValueEmpty,
|
|
4337
4457
|
labelValue,
|
|
4338
4458
|
localToUTC,
|
|
4459
|
+
logUnsupportedDefaultForEnum,
|
|
4339
4460
|
lookupFromFormContext,
|
|
4340
4461
|
mergeDefaultsWithFormData,
|
|
4341
4462
|
mergeObjects,
|