@rjsf/utils 6.0.0-alpha.0 → 6.0.0-beta.1
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 +1281 -625
- package/dist/index.js.map +4 -4
- package/dist/utils.esm.js +1254 -598
- package/dist/utils.esm.js.map +4 -4
- package/dist/utils.umd.js +1201 -570
- package/lib/ErrorSchemaBuilder.d.ts +8 -4
- package/lib/ErrorSchemaBuilder.js +10 -8
- package/lib/ErrorSchemaBuilder.js.map +1 -1
- package/lib/allowAdditionalItems.d.ts +1 -1
- package/lib/allowAdditionalItems.js +1 -1
- package/lib/allowAdditionalItems.js.map +1 -1
- package/lib/asNumber.js.map +1 -1
- package/lib/canExpand.d.ts +1 -1
- package/lib/canExpand.js +2 -2
- package/lib/canExpand.js.map +1 -1
- package/lib/constIsAjvDataReference.d.ts +9 -0
- package/lib/constIsAjvDataReference.js +15 -0
- package/lib/constIsAjvDataReference.js.map +1 -0
- package/lib/constants.d.ts +11 -3
- package/lib/constants.js +11 -3
- package/lib/constants.js.map +1 -1
- package/lib/createErrorHandler.d.ts +1 -1
- package/lib/createErrorHandler.js +2 -2
- package/lib/createErrorHandler.js.map +1 -1
- package/lib/createSchemaUtils.d.ts +3 -2
- package/lib/createSchemaUtils.js +56 -46
- package/lib/createSchemaUtils.js.map +1 -1
- package/lib/dataURItoBlob.js.map +1 -1
- package/lib/dateRangeOptions.d.ts +1 -1
- package/lib/dateRangeOptions.js +1 -1
- package/lib/dateRangeOptions.js.map +1 -1
- package/lib/deepEquals.js +1 -1
- package/lib/deepEquals.js.map +1 -1
- package/lib/englishStringTranslator.d.ts +1 -1
- package/lib/englishStringTranslator.js +1 -1
- package/lib/enumOptionsDeselectValue.d.ts +1 -1
- package/lib/enumOptionsDeselectValue.js +4 -4
- package/lib/enumOptionsDeselectValue.js.map +1 -1
- package/lib/enumOptionsIndexForValue.d.ts +1 -1
- package/lib/enumOptionsIndexForValue.js +1 -1
- package/lib/enumOptionsIndexForValue.js.map +1 -1
- package/lib/enumOptionsIsSelected.d.ts +1 -1
- package/lib/enumOptionsIsSelected.js +3 -3
- package/lib/enumOptionsIsSelected.js.map +1 -1
- package/lib/enumOptionsSelectValue.d.ts +1 -1
- package/lib/enumOptionsSelectValue.js +2 -2
- package/lib/enumOptionsSelectValue.js.map +1 -1
- package/lib/enumOptionsValueForIndex.d.ts +1 -1
- package/lib/enumOptionsValueForIndex.js.map +1 -1
- package/lib/enums.d.ts +2 -0
- package/lib/enums.js +2 -0
- package/lib/enums.js.map +1 -1
- package/lib/findSchemaDefinition.d.ts +1 -1
- package/lib/findSchemaDefinition.js +2 -2
- package/lib/findSchemaDefinition.js.map +1 -1
- package/lib/getChangedFields.d.ts +17 -0
- package/lib/getChangedFields.js +42 -0
- package/lib/getChangedFields.js.map +1 -0
- package/lib/getDateElementProps.d.ts +1 -1
- package/lib/getDateElementProps.js.map +1 -1
- package/lib/getDiscriminatorFieldFromSchema.d.ts +1 -1
- package/lib/getDiscriminatorFieldFromSchema.js +4 -3
- package/lib/getDiscriminatorFieldFromSchema.js.map +1 -1
- package/lib/getInputProps.d.ts +1 -1
- package/lib/getInputProps.js +4 -1
- package/lib/getInputProps.js.map +1 -1
- package/lib/getOptionMatchingSimpleDiscriminator.d.ts +1 -1
- package/lib/getOptionMatchingSimpleDiscriminator.js +2 -2
- package/lib/getOptionMatchingSimpleDiscriminator.js.map +1 -1
- package/lib/getSchemaType.d.ts +2 -1
- package/lib/getSchemaType.js +3 -2
- package/lib/getSchemaType.js.map +1 -1
- package/lib/getSubmitButtonOptions.d.ts +1 -1
- package/lib/getSubmitButtonOptions.js +2 -2
- package/lib/getSubmitButtonOptions.js.map +1 -1
- package/lib/getTemplate.d.ts +1 -1
- package/lib/getTemplate.js +9 -0
- package/lib/getTemplate.js.map +1 -1
- package/lib/getTestIds.d.ts +17 -0
- package/lib/getTestIds.js +34 -0
- package/lib/getTestIds.js.map +1 -0
- package/lib/getUiOptions.d.ts +1 -1
- package/lib/getUiOptions.js +2 -2
- package/lib/getUiOptions.js.map +1 -1
- package/lib/getWidget.d.ts +1 -1
- package/lib/getWidget.js +3 -3
- package/lib/getWidget.js.map +1 -1
- package/lib/guessType.d.ts +1 -1
- package/lib/guessType.js.map +1 -1
- package/lib/hasWidget.d.ts +1 -1
- package/lib/hasWidget.js +1 -1
- package/lib/hasWidget.js.map +1 -1
- package/lib/hashForSchema.d.ts +23 -1
- package/lib/hashForSchema.js +24 -6
- package/lib/hashForSchema.js.map +1 -1
- package/lib/idGenerators.d.ts +8 -1
- package/lib/idGenerators.js +11 -2
- package/lib/idGenerators.js.map +1 -1
- package/lib/index.d.ts +63 -60
- package/lib/index.js +63 -60
- package/lib/index.js.map +1 -1
- package/lib/isConstant.d.ts +1 -1
- package/lib/isConstant.js +1 -1
- package/lib/isCustomWidget.d.ts +1 -1
- package/lib/isCustomWidget.js +1 -1
- package/lib/isFixedItems.d.ts +1 -1
- package/lib/isFixedItems.js +1 -1
- package/lib/isObject.d.ts +2 -2
- package/lib/isObject.js +11 -4
- package/lib/isObject.js.map +1 -1
- package/lib/lookupFromFormContext.d.ts +11 -0
- package/lib/lookupFromFormContext.js +20 -0
- package/lib/lookupFromFormContext.js.map +1 -0
- package/lib/mergeDefaultsWithFormData.d.ts +8 -2
- package/lib/mergeDefaultsWithFormData.js +39 -10
- package/lib/mergeDefaultsWithFormData.js.map +1 -1
- package/lib/mergeObjects.d.ts +1 -1
- package/lib/mergeObjects.js +1 -1
- package/lib/mergeObjects.js.map +1 -1
- package/lib/mergeSchemas.d.ts +1 -1
- package/lib/mergeSchemas.js +4 -4
- package/lib/mergeSchemas.js.map +1 -1
- package/lib/optionsList.d.ts +9 -7
- package/lib/optionsList.js +30 -19
- package/lib/optionsList.js.map +1 -1
- package/lib/orderProperties.js.map +1 -1
- package/lib/pad.js.map +1 -1
- package/lib/parseDateString.d.ts +1 -1
- package/lib/parseDateString.js +1 -1
- package/lib/parseDateString.js.map +1 -1
- package/lib/parser/ParserValidator.d.ts +1 -1
- package/lib/parser/ParserValidator.js +6 -6
- package/lib/parser/ParserValidator.js.map +1 -1
- package/lib/parser/index.d.ts +2 -2
- package/lib/parser/index.js +1 -1
- package/lib/parser/schemaParser.d.ts +2 -2
- package/lib/parser/schemaParser.js +6 -6
- package/lib/parser/schemaParser.js.map +1 -1
- package/lib/rangeSpec.d.ts +2 -2
- package/lib/rangeSpec.js.map +1 -1
- package/lib/replaceStringParameters.js.map +1 -1
- package/lib/schema/findFieldInSchema.d.ts +19 -0
- package/lib/schema/findFieldInSchema.js +61 -0
- package/lib/schema/findFieldInSchema.js.map +1 -0
- package/lib/schema/findSelectedOptionInXxxOf.d.ts +16 -0
- package/lib/schema/findSelectedOptionInXxxOf.js +34 -0
- package/lib/schema/findSelectedOptionInXxxOf.js.map +1 -0
- package/lib/schema/getClosestMatchingOption.d.ts +5 -3
- package/lib/schema/getClosestMatchingOption.js +28 -20
- package/lib/schema/getClosestMatchingOption.js.map +1 -1
- package/lib/schema/getDefaultFormState.d.ts +60 -13
- package/lib/schema/getDefaultFormState.js +304 -166
- package/lib/schema/getDefaultFormState.js.map +1 -1
- package/lib/schema/getDisplayLabel.d.ts +3 -2
- package/lib/schema/getDisplayLabel.js +10 -9
- package/lib/schema/getDisplayLabel.js.map +1 -1
- package/lib/schema/getFirstMatchingOption.d.ts +1 -1
- package/lib/schema/getFirstMatchingOption.js +70 -2
- package/lib/schema/getFirstMatchingOption.js.map +1 -1
- package/lib/schema/getFromSchema.d.ts +14 -0
- package/lib/schema/getFromSchema.js +39 -0
- package/lib/schema/getFromSchema.js.map +1 -0
- package/lib/schema/index.d.ts +15 -14
- package/lib/schema/index.js +15 -14
- package/lib/schema/index.js.map +1 -1
- package/lib/schema/isFilesArray.d.ts +3 -2
- package/lib/schema/isFilesArray.js +5 -4
- package/lib/schema/isFilesArray.js.map +1 -1
- package/lib/schema/isMultiSelect.d.ts +3 -2
- package/lib/schema/isMultiSelect.js +4 -3
- package/lib/schema/isMultiSelect.js.map +1 -1
- package/lib/schema/isSelect.d.ts +3 -2
- package/lib/schema/isSelect.js +5 -4
- package/lib/schema/isSelect.js.map +1 -1
- package/lib/schema/retrieveSchema.d.ts +28 -11
- package/lib/schema/retrieveSchema.js +142 -66
- package/lib/schema/retrieveSchema.js.map +1 -1
- package/lib/schema/sanitizeDataForNewSchema.d.ts +3 -2
- package/lib/schema/sanitizeDataForNewSchema.js +12 -11
- package/lib/schema/sanitizeDataForNewSchema.js.map +1 -1
- package/lib/schema/toIdSchema.d.ts +3 -2
- package/lib/schema/toIdSchema.js +30 -27
- package/lib/schema/toIdSchema.js.map +1 -1
- package/lib/schema/toPathSchema.d.ts +3 -2
- package/lib/schema/toPathSchema.js +22 -20
- package/lib/schema/toPathSchema.js.map +1 -1
- package/lib/schemaRequiresTrueValue.d.ts +1 -1
- package/lib/schemaRequiresTrueValue.js.map +1 -1
- package/lib/shouldRender.js +1 -1
- package/lib/toConstant.d.ts +1 -1
- package/lib/toConstant.js +1 -1
- package/lib/toConstant.js.map +1 -1
- package/lib/toDateString.d.ts +1 -1
- package/lib/toErrorList.d.ts +1 -1
- package/lib/toErrorList.js +2 -2
- package/lib/toErrorList.js.map +1 -1
- package/lib/toErrorSchema.d.ts +1 -1
- package/lib/toErrorSchema.js +2 -2
- package/lib/toErrorSchema.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/types.d.ts +160 -131
- package/lib/unwrapErrorHandler.d.ts +1 -1
- package/lib/unwrapErrorHandler.js +1 -1
- package/lib/unwrapErrorHandler.js.map +1 -1
- package/lib/utcToLocal.js +1 -1
- package/lib/utcToLocal.js.map +1 -1
- package/lib/validationDataMerge.d.ts +1 -1
- package/lib/validationDataMerge.js +3 -3
- package/lib/validationDataMerge.js.map +1 -1
- package/lib/withIdRefPrefix.d.ts +1 -1
- package/lib/withIdRefPrefix.js +2 -2
- package/lib/withIdRefPrefix.js.map +1 -1
- package/package.json +36 -26
- package/src/ErrorSchemaBuilder.ts +15 -8
- package/src/canExpand.ts +2 -2
- package/src/constIsAjvDataReference.ts +17 -0
- package/src/constants.ts +12 -3
- package/src/createSchemaUtils.ts +140 -50
- package/src/dataURItoBlob.ts +1 -1
- package/src/dateRangeOptions.ts +1 -1
- package/src/enumOptionsDeselectValue.ts +4 -5
- package/src/enumOptionsIndexForValue.ts +1 -1
- package/src/enumOptionsIsSelected.ts +4 -5
- package/src/enumOptionsSelectValue.ts +1 -1
- package/src/enumOptionsValueForIndex.ts +1 -1
- package/src/enums.ts +2 -0
- package/src/findSchemaDefinition.ts +2 -2
- package/src/getChangedFields.ts +40 -0
- package/src/getDateElementProps.ts +2 -2
- package/src/getDiscriminatorFieldFromSchema.ts +2 -1
- package/src/getInputProps.ts +6 -2
- package/src/getOptionMatchingSimpleDiscriminator.ts +2 -2
- package/src/getSchemaType.ts +3 -2
- package/src/getSubmitButtonOptions.ts +1 -1
- package/src/getTemplate.ts +12 -1
- package/src/getTestIds.ts +40 -0
- package/src/getUiOptions.ts +2 -2
- package/src/getWidget.tsx +2 -2
- package/src/hasWidget.ts +1 -1
- package/src/hashForSchema.ts +26 -6
- package/src/idGenerators.ts +10 -0
- package/src/index.ts +21 -2
- package/src/isCustomWidget.ts +1 -1
- package/src/isObject.ts +12 -5
- package/src/labelValue.ts +2 -2
- package/src/lookupFromFormContext.ts +26 -0
- package/src/mergeDefaultsWithFormData.ts +54 -9
- package/src/mergeObjects.ts +24 -21
- package/src/optionsList.ts +31 -22
- package/src/parser/ParserValidator.ts +5 -5
- package/src/parser/schemaParser.ts +6 -6
- package/src/schema/findFieldInSchema.ts +138 -0
- package/src/schema/findSelectedOptionInXxxOf.ts +53 -0
- package/src/schema/getClosestMatchingOption.ts +38 -11
- package/src/schema/getDefaultFormState.ts +447 -191
- package/src/schema/getDisplayLabel.ts +7 -4
- package/src/schema/getFirstMatchingOption.ts +79 -4
- package/src/schema/getFromSchema.ts +100 -0
- package/src/schema/index.ts +6 -4
- package/src/schema/isFilesArray.ts +18 -3
- package/src/schema/isMultiSelect.ts +10 -4
- package/src/schema/isSelect.ts +5 -3
- package/src/schema/retrieveSchema.ts +256 -75
- package/src/schema/sanitizeDataForNewSchema.ts +52 -11
- package/src/schema/toIdSchema.ts +69 -43
- package/src/schema/toPathSchema.ts +49 -16
- package/src/toErrorList.ts +2 -2
- package/src/types.ts +266 -174
- package/src/validationDataMerge.ts +1 -1
- package/src/withIdRefPrefix.ts +1 -1
- package/LICENSE.md +0 -201
- package/lib/schema/getMatchingOption.d.ts +0 -14
- package/lib/schema/getMatchingOption.js +0 -85
- package/lib/schema/getMatchingOption.js.map +0 -1
- package/lib/schema/mergeValidationData.d.ts +0 -14
- package/lib/schema/mergeValidationData.js +0 -28
- package/lib/schema/mergeValidationData.js.map +0 -1
- package/src/schema/getMatchingOption.ts +0 -103
- package/src/schema/mergeValidationData.ts +0 -38
package/dist/index.js
CHANGED
|
@@ -28,8 +28,8 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
29
|
|
|
30
30
|
// src/index.ts
|
|
31
|
-
var
|
|
32
|
-
__export(
|
|
31
|
+
var index_exports = {};
|
|
32
|
+
__export(index_exports, {
|
|
33
33
|
ADDITIONAL_PROPERTIES_KEY: () => ADDITIONAL_PROPERTIES_KEY,
|
|
34
34
|
ADDITIONAL_PROPERTY_FLAG: () => ADDITIONAL_PROPERTY_FLAG,
|
|
35
35
|
ALL_OF_KEY: () => ALL_OF_KEY,
|
|
@@ -38,20 +38,24 @@ __export(src_exports, {
|
|
|
38
38
|
DEFAULT_KEY: () => DEFAULT_KEY,
|
|
39
39
|
DEFINITIONS_KEY: () => DEFINITIONS_KEY,
|
|
40
40
|
DEPENDENCIES_KEY: () => DEPENDENCIES_KEY,
|
|
41
|
+
DISCRIMINATOR_PATH: () => DISCRIMINATOR_PATH,
|
|
41
42
|
ENUM_KEY: () => ENUM_KEY,
|
|
42
43
|
ERRORS_KEY: () => ERRORS_KEY,
|
|
43
44
|
ErrorSchemaBuilder: () => ErrorSchemaBuilder,
|
|
45
|
+
FORM_CONTEXT_NAME: () => FORM_CONTEXT_NAME,
|
|
44
46
|
ID_KEY: () => ID_KEY,
|
|
45
47
|
IF_KEY: () => IF_KEY,
|
|
46
48
|
ITEMS_KEY: () => ITEMS_KEY,
|
|
47
49
|
JUNK_OPTION_ID: () => JUNK_OPTION_ID,
|
|
50
|
+
LOOKUP_MAP_NAME: () => LOOKUP_MAP_NAME,
|
|
48
51
|
NAME_KEY: () => NAME_KEY,
|
|
49
52
|
ONE_OF_KEY: () => ONE_OF_KEY,
|
|
53
|
+
PATTERN_PROPERTIES_KEY: () => PATTERN_PROPERTIES_KEY,
|
|
50
54
|
PROPERTIES_KEY: () => PROPERTIES_KEY,
|
|
55
|
+
READONLY_KEY: () => READONLY_KEY,
|
|
51
56
|
REF_KEY: () => REF_KEY,
|
|
52
57
|
REQUIRED_KEY: () => REQUIRED_KEY,
|
|
53
58
|
RJSF_ADDITIONAL_PROPERTIES_FLAG: () => RJSF_ADDITIONAL_PROPERTIES_FLAG,
|
|
54
|
-
RJSF_ADDITONAL_PROPERTIES_FLAG: () => RJSF_ADDITONAL_PROPERTIES_FLAG,
|
|
55
59
|
ROOT_SCHEMA_PREFIX: () => ROOT_SCHEMA_PREFIX,
|
|
56
60
|
SUBMIT_BTN_OPTIONS_KEY: () => SUBMIT_BTN_OPTIONS_KEY,
|
|
57
61
|
TranslatableString: () => TranslatableString,
|
|
@@ -62,6 +66,7 @@ __export(src_exports, {
|
|
|
62
66
|
allowAdditionalItems: () => allowAdditionalItems,
|
|
63
67
|
ariaDescribedByIds: () => ariaDescribedByIds,
|
|
64
68
|
asNumber: () => asNumber,
|
|
69
|
+
buttonId: () => buttonId,
|
|
65
70
|
canExpand: () => canExpand,
|
|
66
71
|
createErrorHandler: () => createErrorHandler,
|
|
67
72
|
createSchemaUtils: () => createSchemaUtils,
|
|
@@ -77,24 +82,30 @@ __export(src_exports, {
|
|
|
77
82
|
enumOptionsValueForIndex: () => enumOptionsValueForIndex,
|
|
78
83
|
errorId: () => errorId,
|
|
79
84
|
examplesId: () => examplesId,
|
|
85
|
+
findFieldInSchema: () => findFieldInSchema,
|
|
80
86
|
findSchemaDefinition: () => findSchemaDefinition,
|
|
87
|
+
findSelectedOptionInXxxOf: () => findSelectedOptionInXxxOf,
|
|
88
|
+
getChangedFields: () => getChangedFields,
|
|
81
89
|
getClosestMatchingOption: () => getClosestMatchingOption,
|
|
82
90
|
getDateElementProps: () => getDateElementProps,
|
|
83
91
|
getDefaultFormState: () => getDefaultFormState,
|
|
84
92
|
getDiscriminatorFieldFromSchema: () => getDiscriminatorFieldFromSchema,
|
|
85
93
|
getDisplayLabel: () => getDisplayLabel,
|
|
86
94
|
getFirstMatchingOption: () => getFirstMatchingOption,
|
|
95
|
+
getFromSchema: () => getFromSchema,
|
|
87
96
|
getInputProps: () => getInputProps,
|
|
88
|
-
getMatchingOption: () => getMatchingOption,
|
|
89
97
|
getOptionMatchingSimpleDiscriminator: () => getOptionMatchingSimpleDiscriminator,
|
|
90
98
|
getSchemaType: () => getSchemaType,
|
|
91
99
|
getSubmitButtonOptions: () => getSubmitButtonOptions,
|
|
92
100
|
getTemplate: () => getTemplate,
|
|
101
|
+
getTestIds: () => getTestIds,
|
|
93
102
|
getUiOptions: () => getUiOptions,
|
|
94
103
|
getWidget: () => getWidget,
|
|
95
104
|
guessType: () => guessType,
|
|
96
105
|
hasWidget: () => hasWidget,
|
|
97
106
|
hashForSchema: () => hashForSchema,
|
|
107
|
+
hashObject: () => hashObject,
|
|
108
|
+
hashString: () => hashString,
|
|
98
109
|
helpId: () => helpId,
|
|
99
110
|
isConstant: () => isConstant,
|
|
100
111
|
isCustomWidget: () => isCustomWidget,
|
|
@@ -105,10 +116,10 @@ __export(src_exports, {
|
|
|
105
116
|
isSelect: () => isSelect,
|
|
106
117
|
labelValue: () => labelValue,
|
|
107
118
|
localToUTC: () => localToUTC,
|
|
119
|
+
lookupFromFormContext: () => lookupFromFormContext,
|
|
108
120
|
mergeDefaultsWithFormData: () => mergeDefaultsWithFormData,
|
|
109
121
|
mergeObjects: () => mergeObjects,
|
|
110
122
|
mergeSchemas: () => mergeSchemas,
|
|
111
|
-
mergeValidationData: () => mergeValidationData,
|
|
112
123
|
optionId: () => optionId,
|
|
113
124
|
optionsList: () => optionsList,
|
|
114
125
|
orderProperties: () => orderProperties,
|
|
@@ -121,6 +132,7 @@ __export(src_exports, {
|
|
|
121
132
|
schemaParser: () => schemaParser,
|
|
122
133
|
schemaRequiresTrueValue: () => schemaRequiresTrueValue,
|
|
123
134
|
shouldRender: () => shouldRender,
|
|
135
|
+
sortedJSONStringify: () => sortedJSONStringify,
|
|
124
136
|
titleId: () => titleId,
|
|
125
137
|
toConstant: () => toConstant,
|
|
126
138
|
toDateString: () => toDateString,
|
|
@@ -133,17 +145,20 @@ __export(src_exports, {
|
|
|
133
145
|
validationDataMerge: () => validationDataMerge,
|
|
134
146
|
withIdRefPrefix: () => withIdRefPrefix
|
|
135
147
|
});
|
|
136
|
-
module.exports = __toCommonJS(
|
|
148
|
+
module.exports = __toCommonJS(index_exports);
|
|
137
149
|
|
|
138
150
|
// src/isObject.ts
|
|
139
151
|
function isObject(thing) {
|
|
140
|
-
if (typeof
|
|
152
|
+
if (typeof thing !== "object" || thing === null) {
|
|
141
153
|
return false;
|
|
142
154
|
}
|
|
143
|
-
if (typeof
|
|
155
|
+
if (typeof thing.lastModified === "number" && typeof File !== "undefined" && thing instanceof File) {
|
|
144
156
|
return false;
|
|
145
157
|
}
|
|
146
|
-
|
|
158
|
+
if (typeof thing.getMonth === "function" && typeof Date !== "undefined" && thing instanceof Date) {
|
|
159
|
+
return false;
|
|
160
|
+
}
|
|
161
|
+
return !Array.isArray(thing);
|
|
147
162
|
}
|
|
148
163
|
|
|
149
164
|
// src/allowAdditionalItems.ts
|
|
@@ -193,11 +208,15 @@ var ITEMS_KEY = "items";
|
|
|
193
208
|
var JUNK_OPTION_ID = "_$junk_option_schema_id$_";
|
|
194
209
|
var NAME_KEY = "$name";
|
|
195
210
|
var ONE_OF_KEY = "oneOf";
|
|
211
|
+
var PATTERN_PROPERTIES_KEY = "patternProperties";
|
|
196
212
|
var PROPERTIES_KEY = "properties";
|
|
213
|
+
var READONLY_KEY = "readonly";
|
|
197
214
|
var REQUIRED_KEY = "required";
|
|
198
215
|
var SUBMIT_BTN_OPTIONS_KEY = "submitButtonOptions";
|
|
199
216
|
var REF_KEY = "$ref";
|
|
200
|
-
var
|
|
217
|
+
var DISCRIMINATOR_PATH = ["discriminator", "propertyName"];
|
|
218
|
+
var FORM_CONTEXT_NAME = "formContext";
|
|
219
|
+
var LOOKUP_MAP_NAME = "layoutGridLookupMap";
|
|
201
220
|
var RJSF_ADDITIONAL_PROPERTIES_FLAG = "__rjsf_additionalProperties";
|
|
202
221
|
var ROOT_SCHEMA_PREFIX = "__rjsf_rootSchema";
|
|
203
222
|
var UI_FIELD_KEY = "ui:field";
|
|
@@ -225,7 +244,7 @@ function getUiOptions(uiSchema = {}, globalOptions = {}) {
|
|
|
225
244
|
|
|
226
245
|
// src/canExpand.ts
|
|
227
246
|
function canExpand(schema, uiSchema = {}, formData) {
|
|
228
|
-
if (!schema.additionalProperties) {
|
|
247
|
+
if (!(schema.additionalProperties || schema.patternProperties)) {
|
|
229
248
|
return false;
|
|
230
249
|
}
|
|
231
250
|
const { expandable = true } = getUiOptions(uiSchema);
|
|
@@ -239,7 +258,7 @@ function canExpand(schema, uiSchema = {}, formData) {
|
|
|
239
258
|
}
|
|
240
259
|
|
|
241
260
|
// src/createErrorHandler.ts
|
|
242
|
-
var import_isPlainObject = __toESM(require("lodash/isPlainObject"));
|
|
261
|
+
var import_isPlainObject = __toESM(require("lodash/isPlainObject"), 1);
|
|
243
262
|
function createErrorHandler(formData) {
|
|
244
263
|
const handler = {
|
|
245
264
|
// We store the list of errors for this node in a property named __errors
|
|
@@ -265,7 +284,7 @@ function createErrorHandler(formData) {
|
|
|
265
284
|
}
|
|
266
285
|
|
|
267
286
|
// src/deepEquals.ts
|
|
268
|
-
var import_isEqualWith = __toESM(require("lodash/isEqualWith"));
|
|
287
|
+
var import_isEqualWith = __toESM(require("lodash/isEqualWith"), 1);
|
|
269
288
|
function deepEquals(a, b) {
|
|
270
289
|
return (0, import_isEqualWith.default)(a, b, (obj, other) => {
|
|
271
290
|
if (typeof obj === "function" && typeof other === "function") {
|
|
@@ -275,13 +294,27 @@ function deepEquals(a, b) {
|
|
|
275
294
|
});
|
|
276
295
|
}
|
|
277
296
|
|
|
278
|
-
// src/schema/
|
|
279
|
-
var import_get7 = __toESM(require("lodash/get"));
|
|
280
|
-
var
|
|
297
|
+
// src/schema/findFieldInSchema.ts
|
|
298
|
+
var import_get7 = __toESM(require("lodash/get"), 1);
|
|
299
|
+
var import_has3 = __toESM(require("lodash/has"), 1);
|
|
300
|
+
|
|
301
|
+
// src/schema/findSelectedOptionInXxxOf.ts
|
|
302
|
+
var import_get5 = __toESM(require("lodash/get"), 1);
|
|
303
|
+
var import_isEqual = __toESM(require("lodash/isEqual"), 1);
|
|
304
|
+
|
|
305
|
+
// src/schema/retrieveSchema.ts
|
|
306
|
+
var import_get4 = __toESM(require("lodash/get"), 1);
|
|
307
|
+
var import_set = __toESM(require("lodash/set"), 1);
|
|
308
|
+
var import_times = __toESM(require("lodash/times"), 1);
|
|
309
|
+
var import_transform = __toESM(require("lodash/transform"), 1);
|
|
310
|
+
var import_merge = __toESM(require("lodash/merge"), 1);
|
|
311
|
+
var import_flattenDeep = __toESM(require("lodash/flattenDeep"), 1);
|
|
312
|
+
var import_uniq = __toESM(require("lodash/uniq"), 1);
|
|
313
|
+
var import_json_schema_merge_allof = __toESM(require("json-schema-merge-allof"), 1);
|
|
281
314
|
|
|
282
315
|
// src/findSchemaDefinition.ts
|
|
283
|
-
var import_jsonpointer = __toESM(require("jsonpointer"));
|
|
284
|
-
var import_omit = __toESM(require("lodash/omit"));
|
|
316
|
+
var import_jsonpointer = __toESM(require("jsonpointer"), 1);
|
|
317
|
+
var import_omit = __toESM(require("lodash/omit"), 1);
|
|
285
318
|
function splitKeyElementFromObject(key, object) {
|
|
286
319
|
const value = object[key];
|
|
287
320
|
const remaining = (0, import_omit.default)(object, [key]);
|
|
@@ -323,114 +356,12 @@ function findSchemaDefinition($ref, rootSchema = {}) {
|
|
|
323
356
|
return findSchemaDefinitionRecursive($ref, rootSchema, recurseList);
|
|
324
357
|
}
|
|
325
358
|
|
|
326
|
-
// src/schema/getClosestMatchingOption.ts
|
|
327
|
-
var import_get5 = __toESM(require("lodash/get"));
|
|
328
|
-
var import_has2 = __toESM(require("lodash/has"));
|
|
329
|
-
var import_isNumber2 = __toESM(require("lodash/isNumber"));
|
|
330
|
-
var import_isObject5 = __toESM(require("lodash/isObject"));
|
|
331
|
-
var import_isString2 = __toESM(require("lodash/isString"));
|
|
332
|
-
var import_reduce = __toESM(require("lodash/reduce"));
|
|
333
|
-
var import_times2 = __toESM(require("lodash/times"));
|
|
334
|
-
|
|
335
|
-
// src/schema/getMatchingOption.ts
|
|
336
|
-
var import_get2 = __toESM(require("lodash/get"));
|
|
337
|
-
var import_has = __toESM(require("lodash/has"));
|
|
338
|
-
var import_isNumber = __toESM(require("lodash/isNumber"));
|
|
339
|
-
|
|
340
|
-
// src/getOptionMatchingSimpleDiscriminator.ts
|
|
341
|
-
var import_get = __toESM(require("lodash/get"));
|
|
342
|
-
function getOptionMatchingSimpleDiscriminator(formData, options, discriminatorField) {
|
|
343
|
-
if (formData && discriminatorField) {
|
|
344
|
-
const value = (0, import_get.default)(formData, discriminatorField);
|
|
345
|
-
if (value === void 0) {
|
|
346
|
-
return;
|
|
347
|
-
}
|
|
348
|
-
for (let i = 0; i < options.length; i++) {
|
|
349
|
-
const option = options[i];
|
|
350
|
-
const discriminator = (0, import_get.default)(option, [PROPERTIES_KEY, discriminatorField], {});
|
|
351
|
-
if (discriminator.type === "object" || discriminator.type === "array") {
|
|
352
|
-
continue;
|
|
353
|
-
}
|
|
354
|
-
if (discriminator.const === value) {
|
|
355
|
-
return i;
|
|
356
|
-
}
|
|
357
|
-
if (discriminator.enum?.includes(value)) {
|
|
358
|
-
return i;
|
|
359
|
-
}
|
|
360
|
-
}
|
|
361
|
-
}
|
|
362
|
-
return;
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
// src/schema/getMatchingOption.ts
|
|
366
|
-
function getMatchingOption(validator, formData, options, rootSchema, discriminatorField) {
|
|
367
|
-
if (formData === void 0) {
|
|
368
|
-
return 0;
|
|
369
|
-
}
|
|
370
|
-
const simpleDiscriminatorMatch = getOptionMatchingSimpleDiscriminator(formData, options, discriminatorField);
|
|
371
|
-
if ((0, import_isNumber.default)(simpleDiscriminatorMatch)) {
|
|
372
|
-
return simpleDiscriminatorMatch;
|
|
373
|
-
}
|
|
374
|
-
for (let i = 0; i < options.length; i++) {
|
|
375
|
-
const option = options[i];
|
|
376
|
-
if (discriminatorField && (0, import_has.default)(option, [PROPERTIES_KEY, discriminatorField])) {
|
|
377
|
-
const value = (0, import_get2.default)(formData, discriminatorField);
|
|
378
|
-
const discriminator = (0, import_get2.default)(option, [PROPERTIES_KEY, discriminatorField], {});
|
|
379
|
-
if (validator.isValid(discriminator, value, rootSchema)) {
|
|
380
|
-
return i;
|
|
381
|
-
}
|
|
382
|
-
} else if (option[PROPERTIES_KEY]) {
|
|
383
|
-
const requiresAnyOf = {
|
|
384
|
-
anyOf: Object.keys(option[PROPERTIES_KEY]).map((key) => ({
|
|
385
|
-
required: [key]
|
|
386
|
-
}))
|
|
387
|
-
};
|
|
388
|
-
let augmentedSchema;
|
|
389
|
-
if (option.anyOf) {
|
|
390
|
-
const { ...shallowClone } = option;
|
|
391
|
-
if (!shallowClone.allOf) {
|
|
392
|
-
shallowClone.allOf = [];
|
|
393
|
-
} else {
|
|
394
|
-
shallowClone.allOf = shallowClone.allOf.slice();
|
|
395
|
-
}
|
|
396
|
-
shallowClone.allOf.push(requiresAnyOf);
|
|
397
|
-
augmentedSchema = shallowClone;
|
|
398
|
-
} else {
|
|
399
|
-
augmentedSchema = Object.assign({}, option, requiresAnyOf);
|
|
400
|
-
}
|
|
401
|
-
delete augmentedSchema.required;
|
|
402
|
-
if (validator.isValid(augmentedSchema, formData, rootSchema)) {
|
|
403
|
-
return i;
|
|
404
|
-
}
|
|
405
|
-
} else if (validator.isValid(option, formData, rootSchema)) {
|
|
406
|
-
return i;
|
|
407
|
-
}
|
|
408
|
-
}
|
|
409
|
-
return 0;
|
|
410
|
-
}
|
|
411
|
-
|
|
412
|
-
// src/schema/getFirstMatchingOption.ts
|
|
413
|
-
function getFirstMatchingOption(validator, formData, options, rootSchema, discriminatorField) {
|
|
414
|
-
return getMatchingOption(validator, formData, options, rootSchema, discriminatorField);
|
|
415
|
-
}
|
|
416
|
-
|
|
417
|
-
// src/schema/retrieveSchema.ts
|
|
418
|
-
var import_get4 = __toESM(require("lodash/get"));
|
|
419
|
-
var import_isEqual = __toESM(require("lodash/isEqual"));
|
|
420
|
-
var import_set = __toESM(require("lodash/set"));
|
|
421
|
-
var import_times = __toESM(require("lodash/times"));
|
|
422
|
-
var import_transform = __toESM(require("lodash/transform"));
|
|
423
|
-
var import_merge = __toESM(require("lodash/merge"));
|
|
424
|
-
var import_flattenDeep = __toESM(require("lodash/flattenDeep"));
|
|
425
|
-
var import_uniq = __toESM(require("lodash/uniq"));
|
|
426
|
-
var import_json_schema_merge_allof = __toESM(require("json-schema-merge-allof"));
|
|
427
|
-
|
|
428
359
|
// src/getDiscriminatorFieldFromSchema.ts
|
|
429
|
-
var
|
|
430
|
-
var import_isString = __toESM(require("lodash/isString"));
|
|
360
|
+
var import_get = __toESM(require("lodash/get"), 1);
|
|
361
|
+
var import_isString = __toESM(require("lodash/isString"), 1);
|
|
431
362
|
function getDiscriminatorFieldFromSchema(schema) {
|
|
432
363
|
let discriminator;
|
|
433
|
-
const maybeString = (0,
|
|
364
|
+
const maybeString = (0, import_get.default)(schema, DISCRIMINATOR_PATH);
|
|
434
365
|
if ((0, import_isString.default)(maybeString)) {
|
|
435
366
|
discriminator = maybeString;
|
|
436
367
|
} else if (maybeString !== void 0) {
|
|
@@ -463,7 +394,7 @@ function guessType(value) {
|
|
|
463
394
|
}
|
|
464
395
|
|
|
465
396
|
// src/mergeSchemas.ts
|
|
466
|
-
var import_union = __toESM(require("lodash/union"));
|
|
397
|
+
var import_union = __toESM(require("lodash/union"), 1);
|
|
467
398
|
|
|
468
399
|
// src/getSchemaType.ts
|
|
469
400
|
function getSchemaType(schema) {
|
|
@@ -474,7 +405,7 @@ function getSchemaType(schema) {
|
|
|
474
405
|
if (!type && schema.enum) {
|
|
475
406
|
return "string";
|
|
476
407
|
}
|
|
477
|
-
if (!type && (schema.properties || schema.additionalProperties)) {
|
|
408
|
+
if (!type && (schema.properties || schema.additionalProperties || schema.patternProperties)) {
|
|
478
409
|
return "object";
|
|
479
410
|
}
|
|
480
411
|
if (Array.isArray(type)) {
|
|
@@ -503,11 +434,97 @@ function mergeSchemas(obj1, obj2) {
|
|
|
503
434
|
}, acc);
|
|
504
435
|
}
|
|
505
436
|
|
|
437
|
+
// src/schema/getFirstMatchingOption.ts
|
|
438
|
+
var import_get3 = __toESM(require("lodash/get"), 1);
|
|
439
|
+
var import_has = __toESM(require("lodash/has"), 1);
|
|
440
|
+
var import_isNumber = __toESM(require("lodash/isNumber"), 1);
|
|
441
|
+
|
|
442
|
+
// src/getOptionMatchingSimpleDiscriminator.ts
|
|
443
|
+
var import_get2 = __toESM(require("lodash/get"), 1);
|
|
444
|
+
function getOptionMatchingSimpleDiscriminator(formData, options, discriminatorField) {
|
|
445
|
+
if (formData && discriminatorField) {
|
|
446
|
+
const value = (0, import_get2.default)(formData, discriminatorField);
|
|
447
|
+
if (value === void 0) {
|
|
448
|
+
return;
|
|
449
|
+
}
|
|
450
|
+
for (let i = 0; i < options.length; i++) {
|
|
451
|
+
const option = options[i];
|
|
452
|
+
const discriminator = (0, import_get2.default)(option, [PROPERTIES_KEY, discriminatorField], {});
|
|
453
|
+
if (discriminator.type === "object" || discriminator.type === "array") {
|
|
454
|
+
continue;
|
|
455
|
+
}
|
|
456
|
+
if (discriminator.const === value) {
|
|
457
|
+
return i;
|
|
458
|
+
}
|
|
459
|
+
if (discriminator.enum?.includes(value)) {
|
|
460
|
+
return i;
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
return;
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
// src/schema/getFirstMatchingOption.ts
|
|
468
|
+
function getFirstMatchingOption(validator, formData, options, rootSchema, discriminatorField) {
|
|
469
|
+
if (formData === void 0) {
|
|
470
|
+
return 0;
|
|
471
|
+
}
|
|
472
|
+
const simpleDiscriminatorMatch = getOptionMatchingSimpleDiscriminator(formData, options, discriminatorField);
|
|
473
|
+
if ((0, import_isNumber.default)(simpleDiscriminatorMatch)) {
|
|
474
|
+
return simpleDiscriminatorMatch;
|
|
475
|
+
}
|
|
476
|
+
for (let i = 0; i < options.length; i++) {
|
|
477
|
+
const option = options[i];
|
|
478
|
+
if (discriminatorField && (0, import_has.default)(option, [PROPERTIES_KEY, discriminatorField])) {
|
|
479
|
+
const value = (0, import_get3.default)(formData, discriminatorField);
|
|
480
|
+
const discriminator = (0, import_get3.default)(option, [PROPERTIES_KEY, discriminatorField], {});
|
|
481
|
+
if (validator.isValid(discriminator, value, rootSchema)) {
|
|
482
|
+
return i;
|
|
483
|
+
}
|
|
484
|
+
} else if (option[PROPERTIES_KEY]) {
|
|
485
|
+
const requiresAnyOf = {
|
|
486
|
+
anyOf: Object.keys(option[PROPERTIES_KEY]).map((key) => ({
|
|
487
|
+
required: [key]
|
|
488
|
+
}))
|
|
489
|
+
};
|
|
490
|
+
let augmentedSchema;
|
|
491
|
+
if (option.anyOf) {
|
|
492
|
+
const { ...shallowClone } = option;
|
|
493
|
+
if (!shallowClone.allOf) {
|
|
494
|
+
shallowClone.allOf = [];
|
|
495
|
+
} else {
|
|
496
|
+
shallowClone.allOf = shallowClone.allOf.slice();
|
|
497
|
+
}
|
|
498
|
+
shallowClone.allOf.push(requiresAnyOf);
|
|
499
|
+
augmentedSchema = shallowClone;
|
|
500
|
+
} else {
|
|
501
|
+
augmentedSchema = Object.assign({}, option, requiresAnyOf);
|
|
502
|
+
}
|
|
503
|
+
delete augmentedSchema.required;
|
|
504
|
+
if (validator.isValid(augmentedSchema, formData, rootSchema)) {
|
|
505
|
+
return i;
|
|
506
|
+
}
|
|
507
|
+
} else if (validator.isValid(option, formData, rootSchema)) {
|
|
508
|
+
return i;
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
return 0;
|
|
512
|
+
}
|
|
513
|
+
|
|
506
514
|
// src/schema/retrieveSchema.ts
|
|
507
|
-
|
|
508
|
-
|
|
515
|
+
var import_isEmpty = __toESM(require("lodash/isEmpty"), 1);
|
|
516
|
+
function retrieveSchema(validator, schema, rootSchema = {}, rawFormData, experimental_customMergeAllOf) {
|
|
517
|
+
return retrieveSchemaInternal(
|
|
518
|
+
validator,
|
|
519
|
+
schema,
|
|
520
|
+
rootSchema,
|
|
521
|
+
rawFormData,
|
|
522
|
+
void 0,
|
|
523
|
+
void 0,
|
|
524
|
+
experimental_customMergeAllOf
|
|
525
|
+
)[0];
|
|
509
526
|
}
|
|
510
|
-
function resolveCondition(validator, schema, rootSchema, expandAllBranches, recurseList, formData) {
|
|
527
|
+
function resolveCondition(validator, schema, rootSchema, expandAllBranches, recurseList, formData, experimental_customMergeAllOf) {
|
|
511
528
|
const { if: expression, then, else: otherwise, ...resolvedSchemaLessConditional } = schema;
|
|
512
529
|
const conditionValue = validator.isValid(expression, formData || {}, rootSchema);
|
|
513
530
|
let resolvedSchemas = [resolvedSchemaLessConditional];
|
|
@@ -515,12 +532,28 @@ function resolveCondition(validator, schema, rootSchema, expandAllBranches, recu
|
|
|
515
532
|
if (expandAllBranches) {
|
|
516
533
|
if (then && typeof then !== "boolean") {
|
|
517
534
|
schemas = schemas.concat(
|
|
518
|
-
retrieveSchemaInternal(
|
|
535
|
+
retrieveSchemaInternal(
|
|
536
|
+
validator,
|
|
537
|
+
then,
|
|
538
|
+
rootSchema,
|
|
539
|
+
formData,
|
|
540
|
+
expandAllBranches,
|
|
541
|
+
recurseList,
|
|
542
|
+
experimental_customMergeAllOf
|
|
543
|
+
)
|
|
519
544
|
);
|
|
520
545
|
}
|
|
521
546
|
if (otherwise && typeof otherwise !== "boolean") {
|
|
522
547
|
schemas = schemas.concat(
|
|
523
|
-
retrieveSchemaInternal(
|
|
548
|
+
retrieveSchemaInternal(
|
|
549
|
+
validator,
|
|
550
|
+
otherwise,
|
|
551
|
+
rootSchema,
|
|
552
|
+
formData,
|
|
553
|
+
expandAllBranches,
|
|
554
|
+
recurseList,
|
|
555
|
+
experimental_customMergeAllOf
|
|
556
|
+
)
|
|
524
557
|
);
|
|
525
558
|
}
|
|
526
559
|
} else {
|
|
@@ -533,7 +566,8 @@ function resolveCondition(validator, schema, rootSchema, expandAllBranches, recu
|
|
|
533
566
|
rootSchema,
|
|
534
567
|
formData,
|
|
535
568
|
expandAllBranches,
|
|
536
|
-
recurseList
|
|
569
|
+
recurseList,
|
|
570
|
+
experimental_customMergeAllOf
|
|
537
571
|
)
|
|
538
572
|
);
|
|
539
573
|
}
|
|
@@ -542,7 +576,15 @@ function resolveCondition(validator, schema, rootSchema, expandAllBranches, recu
|
|
|
542
576
|
resolvedSchemas = schemas.map((s) => mergeSchemas(resolvedSchemaLessConditional, s));
|
|
543
577
|
}
|
|
544
578
|
return resolvedSchemas.flatMap(
|
|
545
|
-
(s) => retrieveSchemaInternal(
|
|
579
|
+
(s) => retrieveSchemaInternal(
|
|
580
|
+
validator,
|
|
581
|
+
s,
|
|
582
|
+
rootSchema,
|
|
583
|
+
formData,
|
|
584
|
+
expandAllBranches,
|
|
585
|
+
recurseList,
|
|
586
|
+
experimental_customMergeAllOf
|
|
587
|
+
)
|
|
546
588
|
);
|
|
547
589
|
}
|
|
548
590
|
function getAllPermutationsOfXxxOf(listOfLists) {
|
|
@@ -559,7 +601,16 @@ function getAllPermutationsOfXxxOf(listOfLists) {
|
|
|
559
601
|
);
|
|
560
602
|
return allPermutations;
|
|
561
603
|
}
|
|
562
|
-
function
|
|
604
|
+
function getMatchingPatternProperties(schema, key) {
|
|
605
|
+
return Object.keys(schema.patternProperties).filter((pattern) => RegExp(pattern).test(key)).reduce(
|
|
606
|
+
(obj, pattern) => {
|
|
607
|
+
(0, import_set.default)(obj, [pattern], schema.patternProperties[pattern]);
|
|
608
|
+
return obj;
|
|
609
|
+
},
|
|
610
|
+
{}
|
|
611
|
+
);
|
|
612
|
+
}
|
|
613
|
+
function resolveSchema(validator, schema, rootSchema, expandAllBranches, recurseList, formData, experimental_customMergeAllOf) {
|
|
563
614
|
const updatedSchemas = resolveReference(
|
|
564
615
|
validator,
|
|
565
616
|
schema,
|
|
@@ -581,7 +632,15 @@ function resolveSchema(validator, schema, rootSchema, expandAllBranches, recurse
|
|
|
581
632
|
formData
|
|
582
633
|
);
|
|
583
634
|
return resolvedSchemas.flatMap((s) => {
|
|
584
|
-
return retrieveSchemaInternal(
|
|
635
|
+
return retrieveSchemaInternal(
|
|
636
|
+
validator,
|
|
637
|
+
s,
|
|
638
|
+
rootSchema,
|
|
639
|
+
formData,
|
|
640
|
+
expandAllBranches,
|
|
641
|
+
recurseList,
|
|
642
|
+
experimental_customMergeAllOf
|
|
643
|
+
);
|
|
585
644
|
});
|
|
586
645
|
}
|
|
587
646
|
if (ALL_OF_KEY in schema && Array.isArray(schema.allOf)) {
|
|
@@ -592,15 +651,19 @@ function resolveSchema(validator, schema, rootSchema, expandAllBranches, recurse
|
|
|
592
651
|
rootSchema,
|
|
593
652
|
formData,
|
|
594
653
|
expandAllBranches,
|
|
595
|
-
recurseList
|
|
654
|
+
recurseList,
|
|
655
|
+
experimental_customMergeAllOf
|
|
596
656
|
)
|
|
597
657
|
);
|
|
598
658
|
const allPermutations = getAllPermutationsOfXxxOf(allOfSchemaElements);
|
|
599
|
-
return allPermutations.map((permutation) => ({
|
|
659
|
+
return allPermutations.map((permutation) => ({
|
|
660
|
+
...schema,
|
|
661
|
+
allOf: permutation
|
|
662
|
+
}));
|
|
600
663
|
}
|
|
601
664
|
return [schema];
|
|
602
665
|
}
|
|
603
|
-
function resolveReference(validator, schema, rootSchema, expandAllBranches, recurseList, formData) {
|
|
666
|
+
function resolveReference(validator, schema, rootSchema, expandAllBranches, recurseList, formData, experimental_customMergeAllOf) {
|
|
604
667
|
const updatedSchema = resolveAllReferences(schema, rootSchema, recurseList);
|
|
605
668
|
if (updatedSchema !== schema) {
|
|
606
669
|
return retrieveSchemaInternal(
|
|
@@ -609,7 +672,8 @@ function resolveReference(validator, schema, rootSchema, expandAllBranches, recu
|
|
|
609
672
|
rootSchema,
|
|
610
673
|
formData,
|
|
611
674
|
expandAllBranches,
|
|
612
|
-
recurseList
|
|
675
|
+
recurseList,
|
|
676
|
+
experimental_customMergeAllOf
|
|
613
677
|
);
|
|
614
678
|
}
|
|
615
679
|
return [schema];
|
|
@@ -648,9 +712,9 @@ function resolveAllReferences(schema, rootSchema, recurseList) {
|
|
|
648
712
|
items: resolveAllReferences(resolvedSchema.items, rootSchema, recurseList)
|
|
649
713
|
};
|
|
650
714
|
}
|
|
651
|
-
return (
|
|
715
|
+
return deepEquals(schema, resolvedSchema) ? schema : resolvedSchema;
|
|
652
716
|
}
|
|
653
|
-
function stubExistingAdditionalProperties(validator, theSchema, rootSchema, aFormData) {
|
|
717
|
+
function stubExistingAdditionalProperties(validator, theSchema, rootSchema, aFormData, experimental_customMergeAllOf) {
|
|
654
718
|
const schema = {
|
|
655
719
|
...theSchema,
|
|
656
720
|
properties: { ...theSchema.properties }
|
|
@@ -660,34 +724,54 @@ function stubExistingAdditionalProperties(validator, theSchema, rootSchema, aFor
|
|
|
660
724
|
if (key in schema.properties) {
|
|
661
725
|
return;
|
|
662
726
|
}
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
if (
|
|
666
|
-
|
|
727
|
+
if (PATTERN_PROPERTIES_KEY in schema) {
|
|
728
|
+
const matchingProperties = getMatchingPatternProperties(schema, key);
|
|
729
|
+
if (!(0, import_isEmpty.default)(matchingProperties)) {
|
|
730
|
+
schema.properties[key] = retrieveSchema(
|
|
667
731
|
validator,
|
|
668
|
-
{
|
|
732
|
+
{ allOf: Object.values(matchingProperties) },
|
|
669
733
|
rootSchema,
|
|
670
|
-
formData
|
|
734
|
+
formData,
|
|
735
|
+
experimental_customMergeAllOf
|
|
671
736
|
);
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
}
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
737
|
+
(0, import_set.default)(schema.properties, [key, ADDITIONAL_PROPERTY_FLAG], true);
|
|
738
|
+
return;
|
|
739
|
+
}
|
|
740
|
+
}
|
|
741
|
+
if (ADDITIONAL_PROPERTIES_KEY in schema && schema.additionalProperties !== false) {
|
|
742
|
+
let additionalProperties = {};
|
|
743
|
+
if (typeof schema.additionalProperties !== "boolean") {
|
|
744
|
+
if (REF_KEY in schema.additionalProperties) {
|
|
745
|
+
additionalProperties = retrieveSchema(
|
|
746
|
+
validator,
|
|
747
|
+
{ $ref: (0, import_get4.default)(schema.additionalProperties, [REF_KEY]) },
|
|
748
|
+
rootSchema,
|
|
749
|
+
formData,
|
|
750
|
+
experimental_customMergeAllOf
|
|
751
|
+
);
|
|
752
|
+
} else if ("type" in schema.additionalProperties) {
|
|
753
|
+
additionalProperties = { ...schema.additionalProperties };
|
|
754
|
+
} else if (ANY_OF_KEY in schema.additionalProperties || ONE_OF_KEY in schema.additionalProperties) {
|
|
755
|
+
additionalProperties = {
|
|
756
|
+
type: "object",
|
|
757
|
+
...schema.additionalProperties
|
|
758
|
+
};
|
|
759
|
+
} else {
|
|
760
|
+
additionalProperties = { type: guessType((0, import_get4.default)(formData, [key])) };
|
|
761
|
+
}
|
|
679
762
|
} else {
|
|
680
763
|
additionalProperties = { type: guessType((0, import_get4.default)(formData, [key])) };
|
|
681
764
|
}
|
|
765
|
+
schema.properties[key] = additionalProperties;
|
|
766
|
+
(0, import_set.default)(schema.properties, [key, ADDITIONAL_PROPERTY_FLAG], true);
|
|
682
767
|
} else {
|
|
683
|
-
|
|
768
|
+
schema.properties[key] = { type: "null" };
|
|
769
|
+
(0, import_set.default)(schema.properties, [key, ADDITIONAL_PROPERTY_FLAG], true);
|
|
684
770
|
}
|
|
685
|
-
schema.properties[key] = additionalProperties;
|
|
686
|
-
(0, import_set.default)(schema.properties, [key, ADDITIONAL_PROPERTY_FLAG], true);
|
|
687
771
|
});
|
|
688
772
|
return schema;
|
|
689
773
|
}
|
|
690
|
-
function retrieveSchemaInternal(validator, schema, rootSchema, rawFormData, expandAllBranches = false, recurseList = []) {
|
|
774
|
+
function retrieveSchemaInternal(validator, schema, rootSchema, rawFormData, expandAllBranches = false, recurseList = [], experimental_customMergeAllOf) {
|
|
691
775
|
if (!isObject(schema)) {
|
|
692
776
|
return [{}];
|
|
693
777
|
}
|
|
@@ -697,7 +781,8 @@ function retrieveSchemaInternal(validator, schema, rootSchema, rawFormData, expa
|
|
|
697
781
|
rootSchema,
|
|
698
782
|
expandAllBranches,
|
|
699
783
|
recurseList,
|
|
700
|
-
rawFormData
|
|
784
|
+
rawFormData,
|
|
785
|
+
experimental_customMergeAllOf
|
|
701
786
|
);
|
|
702
787
|
return resolvedSchemas.flatMap((s) => {
|
|
703
788
|
let resolvedSchema = s;
|
|
@@ -708,7 +793,8 @@ function retrieveSchemaInternal(validator, schema, rootSchema, rawFormData, expa
|
|
|
708
793
|
rootSchema,
|
|
709
794
|
expandAllBranches,
|
|
710
795
|
recurseList,
|
|
711
|
-
rawFormData
|
|
796
|
+
rawFormData,
|
|
797
|
+
experimental_customMergeAllOf
|
|
712
798
|
);
|
|
713
799
|
}
|
|
714
800
|
if (ALL_OF_KEY in resolvedSchema) {
|
|
@@ -717,18 +803,60 @@ function retrieveSchemaInternal(validator, schema, rootSchema, rawFormData, expa
|
|
|
717
803
|
return [...allOf, restOfSchema];
|
|
718
804
|
}
|
|
719
805
|
try {
|
|
720
|
-
|
|
806
|
+
const withContainsSchemas = [];
|
|
807
|
+
const withoutContainsSchemas = [];
|
|
808
|
+
resolvedSchema.allOf?.forEach((s2) => {
|
|
809
|
+
if (typeof s2 === "object" && s2.contains) {
|
|
810
|
+
withContainsSchemas.push(s2);
|
|
811
|
+
} else {
|
|
812
|
+
withoutContainsSchemas.push(s2);
|
|
813
|
+
}
|
|
814
|
+
});
|
|
815
|
+
if (withContainsSchemas.length) {
|
|
816
|
+
resolvedSchema = { ...resolvedSchema, allOf: withoutContainsSchemas };
|
|
817
|
+
}
|
|
818
|
+
resolvedSchema = experimental_customMergeAllOf ? experimental_customMergeAllOf(resolvedSchema) : (0, import_json_schema_merge_allof.default)(resolvedSchema, {
|
|
721
819
|
deep: false
|
|
722
820
|
});
|
|
821
|
+
if (withContainsSchemas.length) {
|
|
822
|
+
resolvedSchema.allOf = withContainsSchemas;
|
|
823
|
+
}
|
|
723
824
|
} catch (e) {
|
|
724
825
|
console.warn("could not merge subschemas in allOf:\n", e);
|
|
725
826
|
const { allOf, ...resolvedSchemaWithoutAllOf } = resolvedSchema;
|
|
726
827
|
return resolvedSchemaWithoutAllOf;
|
|
727
828
|
}
|
|
728
829
|
}
|
|
729
|
-
|
|
830
|
+
if (PROPERTIES_KEY in resolvedSchema && PATTERN_PROPERTIES_KEY in resolvedSchema) {
|
|
831
|
+
resolvedSchema = Object.keys(resolvedSchema.properties).reduce(
|
|
832
|
+
(schema2, key) => {
|
|
833
|
+
const matchingProperties = getMatchingPatternProperties(schema2, key);
|
|
834
|
+
if (!(0, import_isEmpty.default)(matchingProperties)) {
|
|
835
|
+
schema2.properties[key] = retrieveSchema(
|
|
836
|
+
validator,
|
|
837
|
+
{ allOf: [schema2.properties[key], ...Object.values(matchingProperties)] },
|
|
838
|
+
rootSchema,
|
|
839
|
+
rawFormData,
|
|
840
|
+
experimental_customMergeAllOf
|
|
841
|
+
);
|
|
842
|
+
}
|
|
843
|
+
return schema2;
|
|
844
|
+
},
|
|
845
|
+
{
|
|
846
|
+
...resolvedSchema,
|
|
847
|
+
properties: { ...resolvedSchema.properties }
|
|
848
|
+
}
|
|
849
|
+
);
|
|
850
|
+
}
|
|
851
|
+
const hasAdditionalProperties = PATTERN_PROPERTIES_KEY in resolvedSchema || ADDITIONAL_PROPERTIES_KEY in resolvedSchema && resolvedSchema.additionalProperties !== false;
|
|
730
852
|
if (hasAdditionalProperties) {
|
|
731
|
-
return stubExistingAdditionalProperties(
|
|
853
|
+
return stubExistingAdditionalProperties(
|
|
854
|
+
validator,
|
|
855
|
+
resolvedSchema,
|
|
856
|
+
rootSchema,
|
|
857
|
+
rawFormData,
|
|
858
|
+
experimental_customMergeAllOf
|
|
859
|
+
);
|
|
732
860
|
}
|
|
733
861
|
return resolvedSchema;
|
|
734
862
|
});
|
|
@@ -755,7 +883,7 @@ function resolveAnyOrOneOfSchemas(validator, schema, rootSchema, expandAllBranch
|
|
|
755
883
|
}
|
|
756
884
|
return [schema];
|
|
757
885
|
}
|
|
758
|
-
function resolveDependencies(validator, schema, rootSchema, expandAllBranches, recurseList, formData) {
|
|
886
|
+
function resolveDependencies(validator, schema, rootSchema, expandAllBranches, recurseList, formData, experimental_customMergeAllOf) {
|
|
759
887
|
const { dependencies, ...remainingSchema } = schema;
|
|
760
888
|
const resolvedSchemas = resolveAnyOrOneOfSchemas(
|
|
761
889
|
validator,
|
|
@@ -772,11 +900,12 @@ function resolveDependencies(validator, schema, rootSchema, expandAllBranches, r
|
|
|
772
900
|
rootSchema,
|
|
773
901
|
expandAllBranches,
|
|
774
902
|
recurseList,
|
|
775
|
-
formData
|
|
903
|
+
formData,
|
|
904
|
+
experimental_customMergeAllOf
|
|
776
905
|
)
|
|
777
906
|
);
|
|
778
907
|
}
|
|
779
|
-
function processDependencies(validator, dependencies, resolvedSchema, rootSchema, expandAllBranches, recurseList, formData) {
|
|
908
|
+
function processDependencies(validator, dependencies, resolvedSchema, rootSchema, expandAllBranches, recurseList, formData, experimental_customMergeAllOf) {
|
|
780
909
|
let schemas = [resolvedSchema];
|
|
781
910
|
for (const dependencyKey in dependencies) {
|
|
782
911
|
if (!expandAllBranches && (0, import_get4.default)(formData, [dependencyKey]) === void 0) {
|
|
@@ -800,7 +929,8 @@ function processDependencies(validator, dependencies, resolvedSchema, rootSchema
|
|
|
800
929
|
dependencyValue,
|
|
801
930
|
expandAllBranches,
|
|
802
931
|
recurseList,
|
|
803
|
-
formData
|
|
932
|
+
formData,
|
|
933
|
+
experimental_customMergeAllOf
|
|
804
934
|
);
|
|
805
935
|
}
|
|
806
936
|
return schemas.flatMap(
|
|
@@ -811,7 +941,8 @@ function processDependencies(validator, dependencies, resolvedSchema, rootSchema
|
|
|
811
941
|
rootSchema,
|
|
812
942
|
expandAllBranches,
|
|
813
943
|
recurseList,
|
|
814
|
-
formData
|
|
944
|
+
formData,
|
|
945
|
+
experimental_customMergeAllOf
|
|
815
946
|
)
|
|
816
947
|
);
|
|
817
948
|
}
|
|
@@ -824,14 +955,15 @@ function withDependentProperties(schema, additionallyRequired) {
|
|
|
824
955
|
const required = Array.isArray(schema.required) ? Array.from(/* @__PURE__ */ new Set([...schema.required, ...additionallyRequired])) : additionallyRequired;
|
|
825
956
|
return { ...schema, required };
|
|
826
957
|
}
|
|
827
|
-
function withDependentSchema(validator, schema, rootSchema, dependencyKey, dependencyValue, expandAllBranches, recurseList, formData) {
|
|
958
|
+
function withDependentSchema(validator, schema, rootSchema, dependencyKey, dependencyValue, expandAllBranches, recurseList, formData, experimental_customMergeAllOf) {
|
|
828
959
|
const dependentSchemas = retrieveSchemaInternal(
|
|
829
960
|
validator,
|
|
830
961
|
dependencyValue,
|
|
831
962
|
rootSchema,
|
|
832
963
|
formData,
|
|
833
964
|
expandAllBranches,
|
|
834
|
-
recurseList
|
|
965
|
+
recurseList,
|
|
966
|
+
experimental_customMergeAllOf
|
|
835
967
|
);
|
|
836
968
|
return dependentSchemas.flatMap((dependent) => {
|
|
837
969
|
const { oneOf, ...dependentSchema } = dependent;
|
|
@@ -855,12 +987,13 @@ function withDependentSchema(validator, schema, rootSchema, dependencyKey, depen
|
|
|
855
987
|
resolvedOneOf,
|
|
856
988
|
expandAllBranches,
|
|
857
989
|
recurseList,
|
|
858
|
-
formData
|
|
990
|
+
formData,
|
|
991
|
+
experimental_customMergeAllOf
|
|
859
992
|
)
|
|
860
993
|
);
|
|
861
994
|
});
|
|
862
995
|
}
|
|
863
|
-
function withExactlyOneSubschema(validator, schema, rootSchema, dependencyKey, oneOf, expandAllBranches, recurseList, formData) {
|
|
996
|
+
function withExactlyOneSubschema(validator, schema, rootSchema, dependencyKey, oneOf, expandAllBranches, recurseList, formData, experimental_customMergeAllOf) {
|
|
864
997
|
const validSubschemas = oneOf.filter((subschema) => {
|
|
865
998
|
if (typeof subschema === "boolean" || !subschema || !subschema.properties) {
|
|
866
999
|
return false;
|
|
@@ -891,13 +1024,166 @@ function withExactlyOneSubschema(validator, schema, rootSchema, dependencyKey, o
|
|
|
891
1024
|
rootSchema,
|
|
892
1025
|
formData,
|
|
893
1026
|
expandAllBranches,
|
|
894
|
-
recurseList
|
|
1027
|
+
recurseList,
|
|
1028
|
+
experimental_customMergeAllOf
|
|
895
1029
|
);
|
|
896
1030
|
return schemas.map((s2) => mergeSchemas(schema, s2));
|
|
897
1031
|
});
|
|
898
1032
|
}
|
|
899
1033
|
|
|
1034
|
+
// src/schema/findSelectedOptionInXxxOf.ts
|
|
1035
|
+
function findSelectedOptionInXxxOf(validator, rootSchema, schema, fallbackField, xxx, formData = {}, experimental_customMergeAllOf) {
|
|
1036
|
+
if (Array.isArray(schema[xxx])) {
|
|
1037
|
+
const discriminator = getDiscriminatorFieldFromSchema(schema);
|
|
1038
|
+
const selectorField = discriminator || fallbackField;
|
|
1039
|
+
const xxxOfs = schema[xxx].map(
|
|
1040
|
+
(xxxOf) => retrieveSchema(validator, xxxOf, rootSchema, formData, experimental_customMergeAllOf)
|
|
1041
|
+
);
|
|
1042
|
+
const data = (0, import_get5.default)(formData, selectorField);
|
|
1043
|
+
if (data !== void 0) {
|
|
1044
|
+
return xxxOfs.find((xxx2) => {
|
|
1045
|
+
return (0, import_isEqual.default)(
|
|
1046
|
+
(0, import_get5.default)(xxx2, [PROPERTIES_KEY, selectorField, DEFAULT_KEY], (0, import_get5.default)(xxx2, [PROPERTIES_KEY, selectorField, CONST_KEY])),
|
|
1047
|
+
data
|
|
1048
|
+
);
|
|
1049
|
+
});
|
|
1050
|
+
}
|
|
1051
|
+
}
|
|
1052
|
+
return void 0;
|
|
1053
|
+
}
|
|
1054
|
+
|
|
1055
|
+
// src/schema/getFromSchema.ts
|
|
1056
|
+
var import_get6 = __toESM(require("lodash/get"), 1);
|
|
1057
|
+
var import_has2 = __toESM(require("lodash/has"), 1);
|
|
1058
|
+
var import_isEmpty2 = __toESM(require("lodash/isEmpty"), 1);
|
|
1059
|
+
function getFromSchemaInternal(validator, rootSchema, schema, path, experimental_customMergeAllOf) {
|
|
1060
|
+
let fieldSchema = schema;
|
|
1061
|
+
if ((0, import_has2.default)(schema, REF_KEY)) {
|
|
1062
|
+
fieldSchema = retrieveSchema(validator, schema, rootSchema, void 0, experimental_customMergeAllOf);
|
|
1063
|
+
}
|
|
1064
|
+
if ((0, import_isEmpty2.default)(path)) {
|
|
1065
|
+
return fieldSchema;
|
|
1066
|
+
}
|
|
1067
|
+
const pathList = Array.isArray(path) ? path : path.split(".");
|
|
1068
|
+
const [part, ...nestedPath] = pathList;
|
|
1069
|
+
if (part && (0, import_has2.default)(fieldSchema, part)) {
|
|
1070
|
+
fieldSchema = (0, import_get6.default)(fieldSchema, part);
|
|
1071
|
+
return getFromSchemaInternal(
|
|
1072
|
+
validator,
|
|
1073
|
+
rootSchema,
|
|
1074
|
+
fieldSchema,
|
|
1075
|
+
nestedPath,
|
|
1076
|
+
experimental_customMergeAllOf
|
|
1077
|
+
);
|
|
1078
|
+
}
|
|
1079
|
+
return void 0;
|
|
1080
|
+
}
|
|
1081
|
+
function getFromSchema(validator, rootSchema, schema, path, defaultValue, experimental_customMergeAllOf) {
|
|
1082
|
+
const result = getFromSchemaInternal(validator, rootSchema, schema, path, experimental_customMergeAllOf);
|
|
1083
|
+
if (result === void 0) {
|
|
1084
|
+
return defaultValue;
|
|
1085
|
+
}
|
|
1086
|
+
return result;
|
|
1087
|
+
}
|
|
1088
|
+
|
|
1089
|
+
// src/schema/findFieldInSchema.ts
|
|
1090
|
+
var NOT_FOUND_SCHEMA = { title: "!@#$_UNKNOWN_$#@!" };
|
|
1091
|
+
function findFieldInSchema(validator, rootSchema, schema, path, formData = {}, experimental_customMergeAllOf) {
|
|
1092
|
+
const pathList = Array.isArray(path) ? [...path] : path.split(".");
|
|
1093
|
+
let parentField = schema;
|
|
1094
|
+
const fieldName = pathList.pop();
|
|
1095
|
+
if (pathList.length) {
|
|
1096
|
+
pathList.forEach((subPath) => {
|
|
1097
|
+
parentField = getFromSchema(
|
|
1098
|
+
validator,
|
|
1099
|
+
rootSchema,
|
|
1100
|
+
parentField,
|
|
1101
|
+
[PROPERTIES_KEY, subPath],
|
|
1102
|
+
{},
|
|
1103
|
+
experimental_customMergeAllOf
|
|
1104
|
+
);
|
|
1105
|
+
if ((0, import_has3.default)(parentField, ONE_OF_KEY)) {
|
|
1106
|
+
parentField = findSelectedOptionInXxxOf(
|
|
1107
|
+
validator,
|
|
1108
|
+
rootSchema,
|
|
1109
|
+
parentField,
|
|
1110
|
+
fieldName,
|
|
1111
|
+
ONE_OF_KEY,
|
|
1112
|
+
(0, import_get7.default)(formData, subPath),
|
|
1113
|
+
experimental_customMergeAllOf
|
|
1114
|
+
);
|
|
1115
|
+
} else if ((0, import_has3.default)(parentField, ANY_OF_KEY)) {
|
|
1116
|
+
parentField = findSelectedOptionInXxxOf(
|
|
1117
|
+
validator,
|
|
1118
|
+
rootSchema,
|
|
1119
|
+
parentField,
|
|
1120
|
+
fieldName,
|
|
1121
|
+
ANY_OF_KEY,
|
|
1122
|
+
(0, import_get7.default)(formData, subPath),
|
|
1123
|
+
experimental_customMergeAllOf
|
|
1124
|
+
);
|
|
1125
|
+
}
|
|
1126
|
+
});
|
|
1127
|
+
}
|
|
1128
|
+
if ((0, import_has3.default)(parentField, ONE_OF_KEY)) {
|
|
1129
|
+
parentField = findSelectedOptionInXxxOf(
|
|
1130
|
+
validator,
|
|
1131
|
+
rootSchema,
|
|
1132
|
+
parentField,
|
|
1133
|
+
fieldName,
|
|
1134
|
+
ONE_OF_KEY,
|
|
1135
|
+
formData,
|
|
1136
|
+
experimental_customMergeAllOf
|
|
1137
|
+
);
|
|
1138
|
+
} else if ((0, import_has3.default)(parentField, ANY_OF_KEY)) {
|
|
1139
|
+
parentField = findSelectedOptionInXxxOf(
|
|
1140
|
+
validator,
|
|
1141
|
+
rootSchema,
|
|
1142
|
+
parentField,
|
|
1143
|
+
fieldName,
|
|
1144
|
+
ANY_OF_KEY,
|
|
1145
|
+
formData,
|
|
1146
|
+
experimental_customMergeAllOf
|
|
1147
|
+
);
|
|
1148
|
+
}
|
|
1149
|
+
let field = getFromSchema(
|
|
1150
|
+
validator,
|
|
1151
|
+
rootSchema,
|
|
1152
|
+
parentField,
|
|
1153
|
+
[PROPERTIES_KEY, fieldName],
|
|
1154
|
+
NOT_FOUND_SCHEMA,
|
|
1155
|
+
experimental_customMergeAllOf
|
|
1156
|
+
);
|
|
1157
|
+
if (field === NOT_FOUND_SCHEMA) {
|
|
1158
|
+
field = void 0;
|
|
1159
|
+
}
|
|
1160
|
+
const requiredArray = getFromSchema(
|
|
1161
|
+
validator,
|
|
1162
|
+
rootSchema,
|
|
1163
|
+
parentField,
|
|
1164
|
+
REQUIRED_KEY,
|
|
1165
|
+
[],
|
|
1166
|
+
experimental_customMergeAllOf
|
|
1167
|
+
);
|
|
1168
|
+
let isRequired;
|
|
1169
|
+
if (field && Array.isArray(requiredArray)) {
|
|
1170
|
+
isRequired = requiredArray.includes(fieldName);
|
|
1171
|
+
}
|
|
1172
|
+
return { field, isRequired };
|
|
1173
|
+
}
|
|
1174
|
+
|
|
1175
|
+
// src/schema/getDefaultFormState.ts
|
|
1176
|
+
var import_get11 = __toESM(require("lodash/get"), 1);
|
|
1177
|
+
var import_isEmpty3 = __toESM(require("lodash/isEmpty"), 1);
|
|
1178
|
+
|
|
900
1179
|
// src/schema/getClosestMatchingOption.ts
|
|
1180
|
+
var import_get8 = __toESM(require("lodash/get"), 1);
|
|
1181
|
+
var import_has4 = __toESM(require("lodash/has"), 1);
|
|
1182
|
+
var import_isNumber2 = __toESM(require("lodash/isNumber"), 1);
|
|
1183
|
+
var import_isObject5 = __toESM(require("lodash/isObject"), 1);
|
|
1184
|
+
var import_isString2 = __toESM(require("lodash/isString"), 1);
|
|
1185
|
+
var import_reduce = __toESM(require("lodash/reduce"), 1);
|
|
1186
|
+
var import_times2 = __toESM(require("lodash/times"), 1);
|
|
901
1187
|
var JUNK_OPTION = {
|
|
902
1188
|
type: "object",
|
|
903
1189
|
$id: JUNK_OPTION_ID,
|
|
@@ -907,35 +1193,51 @@ var JUNK_OPTION = {
|
|
|
907
1193
|
}
|
|
908
1194
|
}
|
|
909
1195
|
};
|
|
910
|
-
function calculateIndexScore(validator, rootSchema, schema, formData
|
|
1196
|
+
function calculateIndexScore(validator, rootSchema, schema, formData, experimental_customMergeAllOf) {
|
|
911
1197
|
let totalScore = 0;
|
|
912
1198
|
if (schema) {
|
|
913
1199
|
if ((0, import_isObject5.default)(schema.properties)) {
|
|
914
1200
|
totalScore += (0, import_reduce.default)(
|
|
915
1201
|
schema.properties,
|
|
916
1202
|
(score, value, key) => {
|
|
917
|
-
const formValue = (0,
|
|
1203
|
+
const formValue = (0, import_get8.default)(formData, key);
|
|
918
1204
|
if (typeof value === "boolean") {
|
|
919
1205
|
return score;
|
|
920
1206
|
}
|
|
921
|
-
if ((0,
|
|
922
|
-
const newSchema = retrieveSchema(
|
|
923
|
-
|
|
1207
|
+
if ((0, import_has4.default)(value, REF_KEY)) {
|
|
1208
|
+
const newSchema = retrieveSchema(
|
|
1209
|
+
validator,
|
|
1210
|
+
value,
|
|
1211
|
+
rootSchema,
|
|
1212
|
+
formValue,
|
|
1213
|
+
experimental_customMergeAllOf
|
|
1214
|
+
);
|
|
1215
|
+
return score + calculateIndexScore(
|
|
1216
|
+
validator,
|
|
1217
|
+
rootSchema,
|
|
1218
|
+
newSchema,
|
|
1219
|
+
formValue || {},
|
|
1220
|
+
experimental_customMergeAllOf
|
|
1221
|
+
);
|
|
924
1222
|
}
|
|
925
|
-
if (((0,
|
|
926
|
-
const key2 = (0,
|
|
1223
|
+
if (((0, import_has4.default)(value, ONE_OF_KEY) || (0, import_has4.default)(value, ANY_OF_KEY)) && formValue) {
|
|
1224
|
+
const key2 = (0, import_has4.default)(value, ONE_OF_KEY) ? ONE_OF_KEY : ANY_OF_KEY;
|
|
927
1225
|
const discriminator = getDiscriminatorFieldFromSchema(value);
|
|
928
1226
|
return score + getClosestMatchingOption(
|
|
929
1227
|
validator,
|
|
930
1228
|
rootSchema,
|
|
931
1229
|
formValue,
|
|
932
|
-
(0,
|
|
1230
|
+
(0, import_get8.default)(value, key2),
|
|
933
1231
|
-1,
|
|
934
|
-
discriminator
|
|
1232
|
+
discriminator,
|
|
1233
|
+
experimental_customMergeAllOf
|
|
935
1234
|
);
|
|
936
1235
|
}
|
|
937
1236
|
if (value.type === "object") {
|
|
938
|
-
|
|
1237
|
+
if ((0, import_isObject5.default)(formValue)) {
|
|
1238
|
+
score += 1;
|
|
1239
|
+
}
|
|
1240
|
+
return score + calculateIndexScore(validator, rootSchema, value, formValue, experimental_customMergeAllOf);
|
|
939
1241
|
}
|
|
940
1242
|
if (value.type === guessType(formValue)) {
|
|
941
1243
|
let newScore = score + 1;
|
|
@@ -956,7 +1258,7 @@ function calculateIndexScore(validator, rootSchema, schema, formData = {}) {
|
|
|
956
1258
|
}
|
|
957
1259
|
return totalScore;
|
|
958
1260
|
}
|
|
959
|
-
function getClosestMatchingOption(validator, rootSchema, formData, options, selectedOption = -1, discriminatorField) {
|
|
1261
|
+
function getClosestMatchingOption(validator, rootSchema, formData, options, selectedOption = -1, discriminatorField, experimental_customMergeAllOf) {
|
|
960
1262
|
const resolvedOptions = options.map((option) => {
|
|
961
1263
|
return resolveAllReferences(option, rootSchema, []);
|
|
962
1264
|
});
|
|
@@ -983,7 +1285,7 @@ function getClosestMatchingOption(validator, rootSchema, formData, options, sele
|
|
|
983
1285
|
(scoreData, index) => {
|
|
984
1286
|
const { bestScore } = scoreData;
|
|
985
1287
|
const option = resolvedOptions[index];
|
|
986
|
-
const score = calculateIndexScore(validator, rootSchema, option, formData);
|
|
1288
|
+
const score = calculateIndexScore(validator, rootSchema, option, formData, experimental_customMergeAllOf);
|
|
987
1289
|
scoreCount.add(score);
|
|
988
1290
|
if (score > bestScore) {
|
|
989
1291
|
return { bestIndex: index, bestScore: score };
|
|
@@ -1004,57 +1306,79 @@ function isFixedItems(schema) {
|
|
|
1004
1306
|
}
|
|
1005
1307
|
|
|
1006
1308
|
// src/mergeDefaultsWithFormData.ts
|
|
1007
|
-
var
|
|
1008
|
-
|
|
1309
|
+
var import_get9 = __toESM(require("lodash/get"), 1);
|
|
1310
|
+
var import_isNil = __toESM(require("lodash/isNil"), 1);
|
|
1311
|
+
function mergeDefaultsWithFormData(defaults, formData, mergeExtraArrayDefaults = false, defaultSupercedesUndefined = false, overrideFormDataWithDefaults = false) {
|
|
1009
1312
|
if (Array.isArray(formData)) {
|
|
1010
1313
|
const defaultsArray = Array.isArray(defaults) ? defaults : [];
|
|
1011
|
-
const
|
|
1012
|
-
|
|
1013
|
-
|
|
1314
|
+
const overrideArray = overrideFormDataWithDefaults ? defaultsArray : formData;
|
|
1315
|
+
const overrideOppositeArray = overrideFormDataWithDefaults ? formData : defaultsArray;
|
|
1316
|
+
const mapped = overrideArray.map((value, idx) => {
|
|
1317
|
+
if (overrideOppositeArray[idx] !== void 0) {
|
|
1318
|
+
return mergeDefaultsWithFormData(
|
|
1319
|
+
defaultsArray[idx],
|
|
1320
|
+
formData[idx],
|
|
1321
|
+
mergeExtraArrayDefaults,
|
|
1322
|
+
defaultSupercedesUndefined,
|
|
1323
|
+
overrideFormDataWithDefaults
|
|
1324
|
+
);
|
|
1014
1325
|
}
|
|
1015
1326
|
return value;
|
|
1016
1327
|
});
|
|
1017
|
-
if (mergeExtraArrayDefaults && mapped.length <
|
|
1018
|
-
mapped.push(...
|
|
1328
|
+
if ((mergeExtraArrayDefaults || overrideFormDataWithDefaults) && mapped.length < overrideOppositeArray.length) {
|
|
1329
|
+
mapped.push(...overrideOppositeArray.slice(mapped.length));
|
|
1019
1330
|
}
|
|
1020
1331
|
return mapped;
|
|
1021
1332
|
}
|
|
1022
1333
|
if (isObject(formData)) {
|
|
1023
1334
|
const acc = Object.assign({}, defaults);
|
|
1024
1335
|
return Object.keys(formData).reduce((acc2, key) => {
|
|
1336
|
+
const keyValue = (0, import_get9.default)(formData, key);
|
|
1337
|
+
const keyExistsInDefaults = isObject(defaults) && key in defaults;
|
|
1338
|
+
const keyExistsInFormData = key in formData;
|
|
1025
1339
|
acc2[key] = mergeDefaultsWithFormData(
|
|
1026
|
-
defaults ? (0,
|
|
1027
|
-
|
|
1028
|
-
mergeExtraArrayDefaults
|
|
1340
|
+
defaults ? (0, import_get9.default)(defaults, key) : {},
|
|
1341
|
+
keyValue,
|
|
1342
|
+
mergeExtraArrayDefaults,
|
|
1343
|
+
defaultSupercedesUndefined,
|
|
1344
|
+
// overrideFormDataWithDefaults can be true only when the key value exists in defaults
|
|
1345
|
+
// Or if the key value doesn't exist in formData
|
|
1346
|
+
overrideFormDataWithDefaults && (keyExistsInDefaults || !keyExistsInFormData)
|
|
1029
1347
|
);
|
|
1030
1348
|
return acc2;
|
|
1031
1349
|
}, acc);
|
|
1032
1350
|
}
|
|
1351
|
+
if (defaultSupercedesUndefined && (!(0, import_isNil.default)(defaults) && (0, import_isNil.default)(formData) || typeof formData === "number" && isNaN(formData)) || overrideFormDataWithDefaults && !(0, import_isNil.default)(formData)) {
|
|
1352
|
+
return defaults;
|
|
1353
|
+
}
|
|
1033
1354
|
return formData;
|
|
1034
1355
|
}
|
|
1035
1356
|
|
|
1036
1357
|
// src/mergeObjects.ts
|
|
1037
1358
|
function mergeObjects(obj1, obj2, concatArrays = false) {
|
|
1038
|
-
return Object.keys(obj2).reduce(
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1359
|
+
return Object.keys(obj2).reduce(
|
|
1360
|
+
(acc, key) => {
|
|
1361
|
+
const left = obj1 ? obj1[key] : {}, right = obj2[key];
|
|
1362
|
+
if (obj1 && key in obj1 && isObject(right)) {
|
|
1363
|
+
acc[key] = mergeObjects(left, right, concatArrays);
|
|
1364
|
+
} else if (concatArrays && Array.isArray(left) && Array.isArray(right)) {
|
|
1365
|
+
let toMerge = right;
|
|
1366
|
+
if (concatArrays === "preventDuplicates") {
|
|
1367
|
+
toMerge = right.reduce((result, value) => {
|
|
1368
|
+
if (!left.includes(value)) {
|
|
1369
|
+
result.push(value);
|
|
1370
|
+
}
|
|
1371
|
+
return result;
|
|
1372
|
+
}, []);
|
|
1373
|
+
}
|
|
1374
|
+
acc[key] = left.concat(toMerge);
|
|
1375
|
+
} else {
|
|
1376
|
+
acc[key] = right;
|
|
1051
1377
|
}
|
|
1052
|
-
acc
|
|
1053
|
-
}
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
return acc;
|
|
1057
|
-
}, Object.assign({}, obj1));
|
|
1378
|
+
return acc;
|
|
1379
|
+
},
|
|
1380
|
+
Object.assign({}, obj1)
|
|
1381
|
+
);
|
|
1058
1382
|
}
|
|
1059
1383
|
|
|
1060
1384
|
// src/isConstant.ts
|
|
@@ -1063,8 +1387,8 @@ function isConstant(schema) {
|
|
|
1063
1387
|
}
|
|
1064
1388
|
|
|
1065
1389
|
// src/schema/isSelect.ts
|
|
1066
|
-
function isSelect(validator, theSchema, rootSchema = {}) {
|
|
1067
|
-
const schema = retrieveSchema(validator, theSchema, rootSchema, void 0);
|
|
1390
|
+
function isSelect(validator, theSchema, rootSchema = {}, experimental_customMergeAllOf) {
|
|
1391
|
+
const schema = retrieveSchema(validator, theSchema, rootSchema, void 0, experimental_customMergeAllOf);
|
|
1068
1392
|
const altSchemas = schema.oneOf || schema.anyOf;
|
|
1069
1393
|
if (Array.isArray(schema.enum)) {
|
|
1070
1394
|
return true;
|
|
@@ -1076,14 +1400,85 @@ function isSelect(validator, theSchema, rootSchema = {}) {
|
|
|
1076
1400
|
}
|
|
1077
1401
|
|
|
1078
1402
|
// src/schema/isMultiSelect.ts
|
|
1079
|
-
function isMultiSelect(validator, schema, rootSchema) {
|
|
1403
|
+
function isMultiSelect(validator, schema, rootSchema, experimental_customMergeAllOf) {
|
|
1080
1404
|
if (!schema.uniqueItems || !schema.items || typeof schema.items === "boolean") {
|
|
1081
1405
|
return false;
|
|
1082
1406
|
}
|
|
1083
|
-
return isSelect(validator, schema.items, rootSchema);
|
|
1407
|
+
return isSelect(validator, schema.items, rootSchema, experimental_customMergeAllOf);
|
|
1408
|
+
}
|
|
1409
|
+
|
|
1410
|
+
// src/constIsAjvDataReference.ts
|
|
1411
|
+
var import_isString3 = __toESM(require("lodash/isString"), 1);
|
|
1412
|
+
function constIsAjvDataReference(schema) {
|
|
1413
|
+
const schemaConst = schema[CONST_KEY];
|
|
1414
|
+
const schemaType = getSchemaType(schema);
|
|
1415
|
+
return isObject(schemaConst) && (0, import_isString3.default)(schemaConst?.$data) && schemaType !== "object" && schemaType !== "array";
|
|
1416
|
+
}
|
|
1417
|
+
|
|
1418
|
+
// src/optionsList.ts
|
|
1419
|
+
var import_get10 = __toESM(require("lodash/get"), 1);
|
|
1420
|
+
|
|
1421
|
+
// src/toConstant.ts
|
|
1422
|
+
function toConstant(schema) {
|
|
1423
|
+
if (ENUM_KEY in schema && Array.isArray(schema.enum) && schema.enum.length === 1) {
|
|
1424
|
+
return schema.enum[0];
|
|
1425
|
+
}
|
|
1426
|
+
if (CONST_KEY in schema) {
|
|
1427
|
+
return schema.const;
|
|
1428
|
+
}
|
|
1429
|
+
throw new Error("schema cannot be inferred as a constant");
|
|
1430
|
+
}
|
|
1431
|
+
|
|
1432
|
+
// src/optionsList.ts
|
|
1433
|
+
function optionsList(schema, uiSchema) {
|
|
1434
|
+
if (schema.enum) {
|
|
1435
|
+
let enumNames;
|
|
1436
|
+
if (uiSchema) {
|
|
1437
|
+
const { enumNames: uiEnumNames } = getUiOptions(uiSchema);
|
|
1438
|
+
enumNames = uiEnumNames;
|
|
1439
|
+
}
|
|
1440
|
+
return schema.enum.map((value, i) => {
|
|
1441
|
+
const label = enumNames?.[i] || String(value);
|
|
1442
|
+
return { label, value };
|
|
1443
|
+
});
|
|
1444
|
+
}
|
|
1445
|
+
let altSchemas = void 0;
|
|
1446
|
+
let altUiSchemas = void 0;
|
|
1447
|
+
if (schema.anyOf) {
|
|
1448
|
+
altSchemas = schema.anyOf;
|
|
1449
|
+
altUiSchemas = uiSchema?.anyOf;
|
|
1450
|
+
} else if (schema.oneOf) {
|
|
1451
|
+
altSchemas = schema.oneOf;
|
|
1452
|
+
altUiSchemas = uiSchema?.oneOf;
|
|
1453
|
+
}
|
|
1454
|
+
let selectorField = getDiscriminatorFieldFromSchema(schema);
|
|
1455
|
+
if (uiSchema) {
|
|
1456
|
+
const { optionsSchemaSelector = selectorField } = getUiOptions(uiSchema);
|
|
1457
|
+
selectorField = optionsSchemaSelector;
|
|
1458
|
+
}
|
|
1459
|
+
return altSchemas && altSchemas.map((aSchemaDef, index) => {
|
|
1460
|
+
const { title } = getUiOptions(altUiSchemas?.[index]);
|
|
1461
|
+
const aSchema = aSchemaDef;
|
|
1462
|
+
let value;
|
|
1463
|
+
let label = title;
|
|
1464
|
+
if (selectorField) {
|
|
1465
|
+
const innerSchema = (0, import_get10.default)(aSchema, [PROPERTIES_KEY, selectorField], {});
|
|
1466
|
+
value = (0, import_get10.default)(innerSchema, DEFAULT_KEY, (0, import_get10.default)(innerSchema, CONST_KEY));
|
|
1467
|
+
label = label || innerSchema?.title || aSchema.title || String(value);
|
|
1468
|
+
} else {
|
|
1469
|
+
value = toConstant(aSchema);
|
|
1470
|
+
label = label || aSchema.title || String(value);
|
|
1471
|
+
}
|
|
1472
|
+
return {
|
|
1473
|
+
schema: aSchema,
|
|
1474
|
+
label,
|
|
1475
|
+
value
|
|
1476
|
+
};
|
|
1477
|
+
});
|
|
1084
1478
|
}
|
|
1085
1479
|
|
|
1086
1480
|
// src/schema/getDefaultFormState.ts
|
|
1481
|
+
var PRIMITIVE_TYPES = ["string", "number", "integer", "boolean", "null"];
|
|
1087
1482
|
function getInnerSchemaForArrayItem(schema, additionalItems = 0 /* Ignore */, idx = -1) {
|
|
1088
1483
|
if (idx >= 0) {
|
|
1089
1484
|
if (Array.isArray(schema.items) && idx < schema.items.length) {
|
|
@@ -1100,47 +1495,54 @@ function getInnerSchemaForArrayItem(schema, additionalItems = 0 /* Ignore */, id
|
|
|
1100
1495
|
}
|
|
1101
1496
|
return {};
|
|
1102
1497
|
}
|
|
1103
|
-
function maybeAddDefaultToObject(obj, key, computedDefault, includeUndefinedValues, isParentRequired, requiredFields = [], experimental_defaultFormStateBehavior = {}) {
|
|
1498
|
+
function maybeAddDefaultToObject(obj, key, computedDefault, includeUndefinedValues, isParentRequired, requiredFields = [], experimental_defaultFormStateBehavior = {}, isConst = false) {
|
|
1104
1499
|
const { emptyObjectFields = "populateAllDefaults" } = experimental_defaultFormStateBehavior;
|
|
1105
|
-
if (includeUndefinedValues) {
|
|
1500
|
+
if (includeUndefinedValues || isConst) {
|
|
1106
1501
|
obj[key] = computedDefault;
|
|
1107
1502
|
} else if (emptyObjectFields !== "skipDefaults") {
|
|
1503
|
+
const isSelfOrParentRequired = isParentRequired === void 0 ? requiredFields.includes(key) : isParentRequired;
|
|
1108
1504
|
if (isObject(computedDefault)) {
|
|
1109
|
-
const isSelfOrParentRequired = isParentRequired === void 0 ? requiredFields.includes(key) : isParentRequired;
|
|
1110
1505
|
if (emptyObjectFields === "skipEmptyDefaults") {
|
|
1111
|
-
if (!(0,
|
|
1506
|
+
if (!(0, import_isEmpty3.default)(computedDefault)) {
|
|
1112
1507
|
obj[key] = computedDefault;
|
|
1113
1508
|
}
|
|
1114
|
-
} else if ((!(0,
|
|
1509
|
+
} else if ((!(0, import_isEmpty3.default)(computedDefault) || requiredFields.includes(key)) && (isSelfOrParentRequired || emptyObjectFields !== "populateRequiredDefaults")) {
|
|
1115
1510
|
obj[key] = computedDefault;
|
|
1116
1511
|
}
|
|
1117
1512
|
} else if (
|
|
1118
1513
|
// Store computedDefault if it's a defined primitive (e.g., true) and satisfies certain conditions
|
|
1119
1514
|
// Condition 1: computedDefault is not undefined
|
|
1120
|
-
// Condition 2: If emptyObjectFields is 'populateAllDefaults' or 'skipEmptyDefaults)
|
|
1121
|
-
|
|
1515
|
+
// Condition 2: If emptyObjectFields is 'populateAllDefaults' or 'skipEmptyDefaults)
|
|
1516
|
+
// Or if isSelfOrParentRequired is 'true' and the key is a required field
|
|
1517
|
+
computedDefault !== void 0 && (emptyObjectFields === "populateAllDefaults" || emptyObjectFields === "skipEmptyDefaults" || isSelfOrParentRequired && requiredFields.includes(key))
|
|
1122
1518
|
) {
|
|
1123
1519
|
obj[key] = computedDefault;
|
|
1124
1520
|
}
|
|
1125
1521
|
}
|
|
1126
1522
|
}
|
|
1127
|
-
function computeDefaults(validator, rawSchema, {
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1523
|
+
function computeDefaults(validator, rawSchema, computeDefaultsProps = {}) {
|
|
1524
|
+
const {
|
|
1525
|
+
parentDefaults,
|
|
1526
|
+
rawFormData,
|
|
1527
|
+
rootSchema = {},
|
|
1528
|
+
includeUndefinedValues = false,
|
|
1529
|
+
_recurseList = [],
|
|
1530
|
+
experimental_defaultFormStateBehavior = void 0,
|
|
1531
|
+
experimental_customMergeAllOf = void 0,
|
|
1532
|
+
required,
|
|
1533
|
+
shouldMergeDefaultsIntoFormData = false
|
|
1534
|
+
} = computeDefaultsProps;
|
|
1136
1535
|
const formData = isObject(rawFormData) ? rawFormData : {};
|
|
1137
1536
|
const schema = isObject(rawSchema) ? rawSchema : {};
|
|
1138
1537
|
let defaults = parentDefaults;
|
|
1139
1538
|
let schemaToCompute = null;
|
|
1539
|
+
let experimental_dfsb_to_compute = experimental_defaultFormStateBehavior;
|
|
1140
1540
|
let updatedRecurseList = _recurseList;
|
|
1141
|
-
if (
|
|
1541
|
+
if (schema[CONST_KEY] && experimental_defaultFormStateBehavior?.constAsDefaults !== "never" && !constIsAjvDataReference(schema)) {
|
|
1542
|
+
defaults = schema[CONST_KEY];
|
|
1543
|
+
} else if (isObject(defaults) && isObject(schema.default)) {
|
|
1142
1544
|
defaults = mergeObjects(defaults, schema.default);
|
|
1143
|
-
} else if (DEFAULT_KEY in schema) {
|
|
1545
|
+
} else if (DEFAULT_KEY in schema && !schema[ANY_OF_KEY] && !schema[ONE_OF_KEY]) {
|
|
1144
1546
|
defaults = schema.default;
|
|
1145
1547
|
} else if (REF_KEY in schema) {
|
|
1146
1548
|
const refName = schema[REF_KEY];
|
|
@@ -1149,7 +1551,19 @@ function computeDefaults(validator, rawSchema, {
|
|
|
1149
1551
|
schemaToCompute = findSchemaDefinition(refName, rootSchema);
|
|
1150
1552
|
}
|
|
1151
1553
|
} else if (DEPENDENCIES_KEY in schema) {
|
|
1152
|
-
const
|
|
1554
|
+
const defaultFormData = {
|
|
1555
|
+
...getDefaultBasedOnSchemaType(validator, schema, computeDefaultsProps, defaults),
|
|
1556
|
+
...formData
|
|
1557
|
+
};
|
|
1558
|
+
const resolvedSchema = resolveDependencies(
|
|
1559
|
+
validator,
|
|
1560
|
+
schema,
|
|
1561
|
+
rootSchema,
|
|
1562
|
+
false,
|
|
1563
|
+
[],
|
|
1564
|
+
defaultFormData,
|
|
1565
|
+
experimental_customMergeAllOf
|
|
1566
|
+
);
|
|
1153
1567
|
schemaToCompute = resolvedSchema[0];
|
|
1154
1568
|
} else if (isFixedItems(schema)) {
|
|
1155
1569
|
defaults = schema.items.map(
|
|
@@ -1158,9 +1572,11 @@ function computeDefaults(validator, rawSchema, {
|
|
|
1158
1572
|
includeUndefinedValues,
|
|
1159
1573
|
_recurseList,
|
|
1160
1574
|
experimental_defaultFormStateBehavior,
|
|
1575
|
+
experimental_customMergeAllOf,
|
|
1161
1576
|
parentDefaults: Array.isArray(parentDefaults) ? parentDefaults[idx] : void 0,
|
|
1162
1577
|
rawFormData: formData,
|
|
1163
|
-
required
|
|
1578
|
+
required,
|
|
1579
|
+
shouldMergeDefaultsIntoFormData
|
|
1164
1580
|
})
|
|
1165
1581
|
);
|
|
1166
1582
|
} else if (ONE_OF_KEY in schema) {
|
|
@@ -1169,13 +1585,21 @@ function computeDefaults(validator, rawSchema, {
|
|
|
1169
1585
|
return void 0;
|
|
1170
1586
|
}
|
|
1171
1587
|
const discriminator = getDiscriminatorFieldFromSchema(schema);
|
|
1588
|
+
const { type = "null" } = remaining;
|
|
1589
|
+
if (!Array.isArray(type) && PRIMITIVE_TYPES.includes(type) && experimental_dfsb_to_compute?.constAsDefaults === "skipOneOf") {
|
|
1590
|
+
experimental_dfsb_to_compute = {
|
|
1591
|
+
...experimental_dfsb_to_compute,
|
|
1592
|
+
constAsDefaults: "never"
|
|
1593
|
+
};
|
|
1594
|
+
}
|
|
1172
1595
|
schemaToCompute = oneOf[getClosestMatchingOption(
|
|
1173
1596
|
validator,
|
|
1174
1597
|
rootSchema,
|
|
1175
|
-
|
|
1598
|
+
rawFormData ?? schema.default,
|
|
1176
1599
|
oneOf,
|
|
1177
1600
|
0,
|
|
1178
|
-
discriminator
|
|
1601
|
+
discriminator,
|
|
1602
|
+
experimental_customMergeAllOf
|
|
1179
1603
|
)];
|
|
1180
1604
|
schemaToCompute = mergeSchemas(remaining, schemaToCompute);
|
|
1181
1605
|
} else if (ANY_OF_KEY in schema) {
|
|
@@ -1187,10 +1611,11 @@ function computeDefaults(validator, rawSchema, {
|
|
|
1187
1611
|
schemaToCompute = anyOf[getClosestMatchingOption(
|
|
1188
1612
|
validator,
|
|
1189
1613
|
rootSchema,
|
|
1190
|
-
|
|
1614
|
+
rawFormData ?? schema.default,
|
|
1191
1615
|
anyOf,
|
|
1192
1616
|
0,
|
|
1193
|
-
discriminator
|
|
1617
|
+
discriminator,
|
|
1618
|
+
experimental_customMergeAllOf
|
|
1194
1619
|
)];
|
|
1195
1620
|
schemaToCompute = mergeSchemas(remaining, schemaToCompute);
|
|
1196
1621
|
}
|
|
@@ -1199,159 +1624,257 @@ function computeDefaults(validator, rawSchema, {
|
|
|
1199
1624
|
rootSchema,
|
|
1200
1625
|
includeUndefinedValues,
|
|
1201
1626
|
_recurseList: updatedRecurseList,
|
|
1202
|
-
experimental_defaultFormStateBehavior,
|
|
1627
|
+
experimental_defaultFormStateBehavior: experimental_dfsb_to_compute,
|
|
1628
|
+
experimental_customMergeAllOf,
|
|
1203
1629
|
parentDefaults: defaults,
|
|
1204
1630
|
rawFormData: formData,
|
|
1205
|
-
required
|
|
1631
|
+
required,
|
|
1632
|
+
shouldMergeDefaultsIntoFormData
|
|
1633
|
+
});
|
|
1634
|
+
}
|
|
1635
|
+
if (defaults === void 0) {
|
|
1636
|
+
defaults = schema.default;
|
|
1637
|
+
}
|
|
1638
|
+
const defaultBasedOnSchemaType = getDefaultBasedOnSchemaType(validator, schema, computeDefaultsProps, defaults);
|
|
1639
|
+
let defaultsWithFormData = defaultBasedOnSchemaType ?? defaults;
|
|
1640
|
+
if (shouldMergeDefaultsIntoFormData) {
|
|
1641
|
+
const { arrayMinItems = {} } = experimental_defaultFormStateBehavior || {};
|
|
1642
|
+
const { mergeExtraDefaults } = arrayMinItems;
|
|
1643
|
+
const matchingFormData = ensureFormDataMatchingSchema(
|
|
1644
|
+
validator,
|
|
1645
|
+
schema,
|
|
1646
|
+
rootSchema,
|
|
1647
|
+
rawFormData,
|
|
1648
|
+
experimental_defaultFormStateBehavior,
|
|
1649
|
+
experimental_customMergeAllOf
|
|
1650
|
+
);
|
|
1651
|
+
if (!isObject(rawFormData) || ALL_OF_KEY in schema) {
|
|
1652
|
+
defaultsWithFormData = mergeDefaultsWithFormData(
|
|
1653
|
+
defaultsWithFormData,
|
|
1654
|
+
matchingFormData,
|
|
1655
|
+
mergeExtraDefaults,
|
|
1656
|
+
true
|
|
1657
|
+
);
|
|
1658
|
+
}
|
|
1659
|
+
}
|
|
1660
|
+
return defaultsWithFormData;
|
|
1661
|
+
}
|
|
1662
|
+
function ensureFormDataMatchingSchema(validator, schema, rootSchema, formData, experimental_defaultFormStateBehavior, experimental_customMergeAllOf) {
|
|
1663
|
+
const isSelectField = !isConstant(schema) && isSelect(validator, schema, rootSchema, experimental_customMergeAllOf);
|
|
1664
|
+
let validFormData = formData;
|
|
1665
|
+
if (isSelectField) {
|
|
1666
|
+
const getOptionsList = optionsList(schema);
|
|
1667
|
+
const isValid = getOptionsList?.some((option) => deepEquals(option.value, formData));
|
|
1668
|
+
validFormData = isValid ? formData : void 0;
|
|
1669
|
+
}
|
|
1670
|
+
const constTakesPrecedence = schema[CONST_KEY] && experimental_defaultFormStateBehavior?.constAsDefaults === "always";
|
|
1671
|
+
if (constTakesPrecedence) {
|
|
1672
|
+
validFormData = schema.const;
|
|
1673
|
+
}
|
|
1674
|
+
return validFormData;
|
|
1675
|
+
}
|
|
1676
|
+
function getObjectDefaults(validator, rawSchema, {
|
|
1677
|
+
rawFormData,
|
|
1678
|
+
rootSchema = {},
|
|
1679
|
+
includeUndefinedValues = false,
|
|
1680
|
+
_recurseList = [],
|
|
1681
|
+
experimental_defaultFormStateBehavior = void 0,
|
|
1682
|
+
experimental_customMergeAllOf = void 0,
|
|
1683
|
+
required,
|
|
1684
|
+
shouldMergeDefaultsIntoFormData
|
|
1685
|
+
} = {}, defaults) {
|
|
1686
|
+
{
|
|
1687
|
+
const formData = isObject(rawFormData) ? rawFormData : {};
|
|
1688
|
+
const schema = rawSchema;
|
|
1689
|
+
const retrievedSchema = experimental_defaultFormStateBehavior?.allOf === "populateDefaults" && ALL_OF_KEY in schema ? retrieveSchema(validator, schema, rootSchema, formData, experimental_customMergeAllOf) : schema;
|
|
1690
|
+
const parentConst = retrievedSchema[CONST_KEY];
|
|
1691
|
+
const objectDefaults = Object.keys(retrievedSchema.properties || {}).reduce(
|
|
1692
|
+
(acc, key) => {
|
|
1693
|
+
const propertySchema = (0, import_get11.default)(retrievedSchema, [PROPERTIES_KEY, key], {});
|
|
1694
|
+
const hasParentConst = isObject(parentConst) && parentConst[key] !== void 0;
|
|
1695
|
+
const hasConst = (isObject(propertySchema) && CONST_KEY in propertySchema || hasParentConst) && experimental_defaultFormStateBehavior?.constAsDefaults !== "never" && !constIsAjvDataReference(propertySchema);
|
|
1696
|
+
const computedDefault = computeDefaults(validator, propertySchema, {
|
|
1697
|
+
rootSchema,
|
|
1698
|
+
_recurseList,
|
|
1699
|
+
experimental_defaultFormStateBehavior,
|
|
1700
|
+
experimental_customMergeAllOf,
|
|
1701
|
+
includeUndefinedValues: includeUndefinedValues === true,
|
|
1702
|
+
parentDefaults: (0, import_get11.default)(defaults, [key]),
|
|
1703
|
+
rawFormData: (0, import_get11.default)(formData, [key]),
|
|
1704
|
+
required: retrievedSchema.required?.includes(key),
|
|
1705
|
+
shouldMergeDefaultsIntoFormData
|
|
1706
|
+
});
|
|
1707
|
+
maybeAddDefaultToObject(
|
|
1708
|
+
acc,
|
|
1709
|
+
key,
|
|
1710
|
+
computedDefault,
|
|
1711
|
+
includeUndefinedValues,
|
|
1712
|
+
required,
|
|
1713
|
+
retrievedSchema.required,
|
|
1714
|
+
experimental_defaultFormStateBehavior,
|
|
1715
|
+
hasConst
|
|
1716
|
+
);
|
|
1717
|
+
return acc;
|
|
1718
|
+
},
|
|
1719
|
+
{}
|
|
1720
|
+
);
|
|
1721
|
+
if (retrievedSchema.additionalProperties) {
|
|
1722
|
+
const additionalPropertiesSchema = isObject(retrievedSchema.additionalProperties) ? retrievedSchema.additionalProperties : {};
|
|
1723
|
+
const keys2 = /* @__PURE__ */ new Set();
|
|
1724
|
+
if (isObject(defaults)) {
|
|
1725
|
+
Object.keys(defaults).filter((key) => !retrievedSchema.properties || !retrievedSchema.properties[key]).forEach((key) => keys2.add(key));
|
|
1726
|
+
}
|
|
1727
|
+
const formDataRequired = [];
|
|
1728
|
+
Object.keys(formData).filter((key) => !retrievedSchema.properties || !retrievedSchema.properties[key]).forEach((key) => {
|
|
1729
|
+
keys2.add(key);
|
|
1730
|
+
formDataRequired.push(key);
|
|
1731
|
+
});
|
|
1732
|
+
keys2.forEach((key) => {
|
|
1733
|
+
const computedDefault = computeDefaults(validator, additionalPropertiesSchema, {
|
|
1734
|
+
rootSchema,
|
|
1735
|
+
_recurseList,
|
|
1736
|
+
experimental_defaultFormStateBehavior,
|
|
1737
|
+
experimental_customMergeAllOf,
|
|
1738
|
+
includeUndefinedValues: includeUndefinedValues === true,
|
|
1739
|
+
parentDefaults: (0, import_get11.default)(defaults, [key]),
|
|
1740
|
+
rawFormData: (0, import_get11.default)(formData, [key]),
|
|
1741
|
+
required: retrievedSchema.required?.includes(key),
|
|
1742
|
+
shouldMergeDefaultsIntoFormData
|
|
1743
|
+
});
|
|
1744
|
+
maybeAddDefaultToObject(
|
|
1745
|
+
objectDefaults,
|
|
1746
|
+
key,
|
|
1747
|
+
computedDefault,
|
|
1748
|
+
includeUndefinedValues,
|
|
1749
|
+
required,
|
|
1750
|
+
formDataRequired
|
|
1751
|
+
);
|
|
1752
|
+
});
|
|
1753
|
+
}
|
|
1754
|
+
return objectDefaults;
|
|
1755
|
+
}
|
|
1756
|
+
}
|
|
1757
|
+
function getArrayDefaults(validator, rawSchema, {
|
|
1758
|
+
rawFormData,
|
|
1759
|
+
rootSchema = {},
|
|
1760
|
+
_recurseList = [],
|
|
1761
|
+
experimental_defaultFormStateBehavior = void 0,
|
|
1762
|
+
experimental_customMergeAllOf = void 0,
|
|
1763
|
+
required,
|
|
1764
|
+
shouldMergeDefaultsIntoFormData
|
|
1765
|
+
} = {}, defaults) {
|
|
1766
|
+
const schema = rawSchema;
|
|
1767
|
+
const arrayMinItemsStateBehavior = experimental_defaultFormStateBehavior?.arrayMinItems ?? {};
|
|
1768
|
+
const { populate: arrayMinItemsPopulate, mergeExtraDefaults: arrayMergeExtraDefaults } = arrayMinItemsStateBehavior;
|
|
1769
|
+
const neverPopulate = arrayMinItemsPopulate === "never";
|
|
1770
|
+
const ignoreMinItemsFlagSet = arrayMinItemsPopulate === "requiredOnly";
|
|
1771
|
+
const isPopulateAll = arrayMinItemsPopulate === "all" || !neverPopulate && !ignoreMinItemsFlagSet;
|
|
1772
|
+
const computeSkipPopulate = arrayMinItemsStateBehavior?.computeSkipPopulate ?? (() => false);
|
|
1773
|
+
const isSkipEmptyDefaults = experimental_defaultFormStateBehavior?.emptyObjectFields === "skipEmptyDefaults";
|
|
1774
|
+
const emptyDefault = isSkipEmptyDefaults ? void 0 : [];
|
|
1775
|
+
if (Array.isArray(defaults)) {
|
|
1776
|
+
defaults = defaults.map((item, idx) => {
|
|
1777
|
+
const schemaItem = getInnerSchemaForArrayItem(schema, 2 /* Fallback */, idx);
|
|
1778
|
+
return computeDefaults(validator, schemaItem, {
|
|
1779
|
+
rootSchema,
|
|
1780
|
+
_recurseList,
|
|
1781
|
+
experimental_defaultFormStateBehavior,
|
|
1782
|
+
experimental_customMergeAllOf,
|
|
1783
|
+
parentDefaults: item,
|
|
1784
|
+
required,
|
|
1785
|
+
shouldMergeDefaultsIntoFormData
|
|
1786
|
+
});
|
|
1206
1787
|
});
|
|
1207
1788
|
}
|
|
1208
|
-
if (
|
|
1209
|
-
|
|
1789
|
+
if (Array.isArray(rawFormData)) {
|
|
1790
|
+
const schemaItem = getInnerSchemaForArrayItem(schema);
|
|
1791
|
+
if (neverPopulate) {
|
|
1792
|
+
defaults = rawFormData;
|
|
1793
|
+
} else {
|
|
1794
|
+
const itemDefaults = rawFormData.map((item, idx) => {
|
|
1795
|
+
return computeDefaults(validator, schemaItem, {
|
|
1796
|
+
rootSchema,
|
|
1797
|
+
_recurseList,
|
|
1798
|
+
experimental_defaultFormStateBehavior,
|
|
1799
|
+
experimental_customMergeAllOf,
|
|
1800
|
+
rawFormData: item,
|
|
1801
|
+
parentDefaults: (0, import_get11.default)(defaults, [idx]),
|
|
1802
|
+
required,
|
|
1803
|
+
shouldMergeDefaultsIntoFormData
|
|
1804
|
+
});
|
|
1805
|
+
});
|
|
1806
|
+
const mergeExtraDefaults = (ignoreMinItemsFlagSet && required || isPopulateAll) && arrayMergeExtraDefaults;
|
|
1807
|
+
defaults = mergeDefaultsWithFormData(defaults, itemDefaults, mergeExtraDefaults);
|
|
1808
|
+
}
|
|
1809
|
+
}
|
|
1810
|
+
const hasConst = isObject(schema) && CONST_KEY in schema && experimental_defaultFormStateBehavior?.constAsDefaults !== "never";
|
|
1811
|
+
if (hasConst === false) {
|
|
1812
|
+
if (neverPopulate) {
|
|
1813
|
+
return defaults ?? emptyDefault;
|
|
1814
|
+
}
|
|
1815
|
+
if (ignoreMinItemsFlagSet && !required) {
|
|
1816
|
+
return defaults ? defaults : void 0;
|
|
1817
|
+
}
|
|
1818
|
+
}
|
|
1819
|
+
const defaultsLength = Array.isArray(defaults) ? defaults.length : 0;
|
|
1820
|
+
if (!schema.minItems || isMultiSelect(validator, schema, rootSchema, experimental_customMergeAllOf) || computeSkipPopulate(validator, schema, rootSchema) || schema.minItems <= defaultsLength) {
|
|
1821
|
+
return defaults ? defaults : emptyDefault;
|
|
1210
1822
|
}
|
|
1211
|
-
|
|
1823
|
+
const defaultEntries = defaults || [];
|
|
1824
|
+
const fillerSchema = getInnerSchemaForArrayItem(schema, 1 /* Invert */);
|
|
1825
|
+
const fillerDefault = fillerSchema.default;
|
|
1826
|
+
const fillerEntries = new Array(schema.minItems - defaultsLength).fill(
|
|
1827
|
+
computeDefaults(validator, fillerSchema, {
|
|
1828
|
+
parentDefaults: fillerDefault,
|
|
1829
|
+
rootSchema,
|
|
1830
|
+
_recurseList,
|
|
1831
|
+
experimental_defaultFormStateBehavior,
|
|
1832
|
+
experimental_customMergeAllOf,
|
|
1833
|
+
required,
|
|
1834
|
+
shouldMergeDefaultsIntoFormData
|
|
1835
|
+
})
|
|
1836
|
+
);
|
|
1837
|
+
return defaultEntries.concat(fillerEntries);
|
|
1838
|
+
}
|
|
1839
|
+
function getDefaultBasedOnSchemaType(validator, rawSchema, computeDefaultsProps = {}, defaults) {
|
|
1840
|
+
switch (getSchemaType(rawSchema)) {
|
|
1841
|
+
// We need to recurse for object schema inner default values.
|
|
1212
1842
|
case "object": {
|
|
1213
|
-
|
|
1214
|
-
const objectDefaults = Object.keys(retrievedSchema.properties || {}).reduce(
|
|
1215
|
-
(acc, key) => {
|
|
1216
|
-
const computedDefault = computeDefaults(validator, (0, import_get7.default)(retrievedSchema, [PROPERTIES_KEY, key]), {
|
|
1217
|
-
rootSchema,
|
|
1218
|
-
_recurseList,
|
|
1219
|
-
experimental_defaultFormStateBehavior,
|
|
1220
|
-
includeUndefinedValues: includeUndefinedValues === true,
|
|
1221
|
-
parentDefaults: (0, import_get7.default)(defaults, [key]),
|
|
1222
|
-
rawFormData: (0, import_get7.default)(formData, [key]),
|
|
1223
|
-
required: retrievedSchema.required?.includes(key)
|
|
1224
|
-
});
|
|
1225
|
-
maybeAddDefaultToObject(
|
|
1226
|
-
acc,
|
|
1227
|
-
key,
|
|
1228
|
-
computedDefault,
|
|
1229
|
-
includeUndefinedValues,
|
|
1230
|
-
required,
|
|
1231
|
-
retrievedSchema.required,
|
|
1232
|
-
experimental_defaultFormStateBehavior
|
|
1233
|
-
);
|
|
1234
|
-
return acc;
|
|
1235
|
-
},
|
|
1236
|
-
{}
|
|
1237
|
-
);
|
|
1238
|
-
if (retrievedSchema.additionalProperties) {
|
|
1239
|
-
const additionalPropertiesSchema = isObject(retrievedSchema.additionalProperties) ? retrievedSchema.additionalProperties : {};
|
|
1240
|
-
const keys = /* @__PURE__ */ new Set();
|
|
1241
|
-
if (isObject(defaults)) {
|
|
1242
|
-
Object.keys(defaults).filter((key) => !retrievedSchema.properties || !retrievedSchema.properties[key]).forEach((key) => keys.add(key));
|
|
1243
|
-
}
|
|
1244
|
-
const formDataRequired = [];
|
|
1245
|
-
Object.keys(formData).filter((key) => !retrievedSchema.properties || !retrievedSchema.properties[key]).forEach((key) => {
|
|
1246
|
-
keys.add(key);
|
|
1247
|
-
formDataRequired.push(key);
|
|
1248
|
-
});
|
|
1249
|
-
keys.forEach((key) => {
|
|
1250
|
-
const computedDefault = computeDefaults(validator, additionalPropertiesSchema, {
|
|
1251
|
-
rootSchema,
|
|
1252
|
-
_recurseList,
|
|
1253
|
-
experimental_defaultFormStateBehavior,
|
|
1254
|
-
includeUndefinedValues: includeUndefinedValues === true,
|
|
1255
|
-
parentDefaults: (0, import_get7.default)(defaults, [key]),
|
|
1256
|
-
rawFormData: (0, import_get7.default)(formData, [key]),
|
|
1257
|
-
required: retrievedSchema.required?.includes(key)
|
|
1258
|
-
});
|
|
1259
|
-
maybeAddDefaultToObject(
|
|
1260
|
-
objectDefaults,
|
|
1261
|
-
key,
|
|
1262
|
-
computedDefault,
|
|
1263
|
-
includeUndefinedValues,
|
|
1264
|
-
required,
|
|
1265
|
-
formDataRequired
|
|
1266
|
-
);
|
|
1267
|
-
});
|
|
1268
|
-
}
|
|
1269
|
-
return objectDefaults;
|
|
1843
|
+
return getObjectDefaults(validator, rawSchema, computeDefaultsProps, defaults);
|
|
1270
1844
|
}
|
|
1271
1845
|
case "array": {
|
|
1272
|
-
|
|
1273
|
-
const ignoreMinItemsFlagSet = experimental_defaultFormStateBehavior?.arrayMinItems?.populate === "requiredOnly";
|
|
1274
|
-
const isSkipEmptyDefaults = experimental_defaultFormStateBehavior?.emptyObjectFields === "skipEmptyDefaults";
|
|
1275
|
-
const computeSkipPopulate = experimental_defaultFormStateBehavior?.arrayMinItems?.computeSkipPopulate ?? (() => false);
|
|
1276
|
-
const emptyDefault = isSkipEmptyDefaults ? void 0 : [];
|
|
1277
|
-
if (Array.isArray(defaults)) {
|
|
1278
|
-
defaults = defaults.map((item, idx) => {
|
|
1279
|
-
const schemaItem = getInnerSchemaForArrayItem(schema, 2 /* Fallback */, idx);
|
|
1280
|
-
return computeDefaults(validator, schemaItem, {
|
|
1281
|
-
rootSchema,
|
|
1282
|
-
_recurseList,
|
|
1283
|
-
experimental_defaultFormStateBehavior,
|
|
1284
|
-
parentDefaults: item,
|
|
1285
|
-
required
|
|
1286
|
-
});
|
|
1287
|
-
});
|
|
1288
|
-
}
|
|
1289
|
-
if (Array.isArray(rawFormData)) {
|
|
1290
|
-
const schemaItem = getInnerSchemaForArrayItem(schema);
|
|
1291
|
-
if (neverPopulate) {
|
|
1292
|
-
defaults = rawFormData;
|
|
1293
|
-
} else {
|
|
1294
|
-
defaults = rawFormData.map((item, idx) => {
|
|
1295
|
-
return computeDefaults(validator, schemaItem, {
|
|
1296
|
-
rootSchema,
|
|
1297
|
-
_recurseList,
|
|
1298
|
-
experimental_defaultFormStateBehavior,
|
|
1299
|
-
rawFormData: item,
|
|
1300
|
-
parentDefaults: (0, import_get7.default)(defaults, [idx]),
|
|
1301
|
-
required
|
|
1302
|
-
});
|
|
1303
|
-
});
|
|
1304
|
-
}
|
|
1305
|
-
}
|
|
1306
|
-
if (neverPopulate) {
|
|
1307
|
-
return defaults ?? emptyDefault;
|
|
1308
|
-
}
|
|
1309
|
-
if (ignoreMinItemsFlagSet && !required) {
|
|
1310
|
-
return defaults ? defaults : void 0;
|
|
1311
|
-
}
|
|
1312
|
-
const defaultsLength = Array.isArray(defaults) ? defaults.length : 0;
|
|
1313
|
-
if (!schema.minItems || isMultiSelect(validator, schema, rootSchema) || computeSkipPopulate(validator, schema, rootSchema) || schema.minItems <= defaultsLength) {
|
|
1314
|
-
return defaults ? defaults : emptyDefault;
|
|
1315
|
-
}
|
|
1316
|
-
const defaultEntries = defaults || [];
|
|
1317
|
-
const fillerSchema = getInnerSchemaForArrayItem(schema, 1 /* Invert */);
|
|
1318
|
-
const fillerDefault = fillerSchema.default;
|
|
1319
|
-
const fillerEntries = new Array(schema.minItems - defaultsLength).fill(
|
|
1320
|
-
computeDefaults(validator, fillerSchema, {
|
|
1321
|
-
parentDefaults: fillerDefault,
|
|
1322
|
-
rootSchema,
|
|
1323
|
-
_recurseList,
|
|
1324
|
-
experimental_defaultFormStateBehavior,
|
|
1325
|
-
required
|
|
1326
|
-
})
|
|
1327
|
-
);
|
|
1328
|
-
return defaultEntries.concat(fillerEntries);
|
|
1846
|
+
return getArrayDefaults(validator, rawSchema, computeDefaultsProps, defaults);
|
|
1329
1847
|
}
|
|
1330
1848
|
}
|
|
1331
|
-
return defaults;
|
|
1332
1849
|
}
|
|
1333
|
-
function getDefaultFormState(validator, theSchema, formData, rootSchema, includeUndefinedValues = false, experimental_defaultFormStateBehavior) {
|
|
1850
|
+
function getDefaultFormState(validator, theSchema, formData, rootSchema, includeUndefinedValues = false, experimental_defaultFormStateBehavior, experimental_customMergeAllOf) {
|
|
1334
1851
|
if (!isObject(theSchema)) {
|
|
1335
1852
|
throw new Error("Invalid schema: " + theSchema);
|
|
1336
1853
|
}
|
|
1337
|
-
const schema = retrieveSchema(validator, theSchema, rootSchema, formData);
|
|
1854
|
+
const schema = retrieveSchema(validator, theSchema, rootSchema, formData, experimental_customMergeAllOf);
|
|
1338
1855
|
const defaults = computeDefaults(validator, schema, {
|
|
1339
1856
|
rootSchema,
|
|
1340
1857
|
includeUndefinedValues,
|
|
1341
1858
|
experimental_defaultFormStateBehavior,
|
|
1342
|
-
|
|
1859
|
+
experimental_customMergeAllOf,
|
|
1860
|
+
rawFormData: formData,
|
|
1861
|
+
shouldMergeDefaultsIntoFormData: true
|
|
1343
1862
|
});
|
|
1344
|
-
if (formData
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1863
|
+
if (isObject(formData) || Array.isArray(formData)) {
|
|
1864
|
+
const { mergeDefaultsIntoFormData } = experimental_defaultFormStateBehavior || {};
|
|
1865
|
+
const defaultSupercedesUndefined = mergeDefaultsIntoFormData === "useDefaultIfFormDataUndefined";
|
|
1866
|
+
const result = mergeDefaultsWithFormData(
|
|
1867
|
+
defaults,
|
|
1868
|
+
formData,
|
|
1869
|
+
true,
|
|
1870
|
+
// set to true to add any additional default array entries.
|
|
1871
|
+
defaultSupercedesUndefined,
|
|
1872
|
+
true
|
|
1873
|
+
// set to true to override formData with defaults if they exist.
|
|
1874
|
+
);
|
|
1875
|
+
return result;
|
|
1353
1876
|
}
|
|
1354
|
-
return
|
|
1877
|
+
return defaults;
|
|
1355
1878
|
}
|
|
1356
1879
|
|
|
1357
1880
|
// src/isCustomWidget.ts
|
|
@@ -1364,25 +1887,31 @@ function isCustomWidget(uiSchema = {}) {
|
|
|
1364
1887
|
}
|
|
1365
1888
|
|
|
1366
1889
|
// src/schema/isFilesArray.ts
|
|
1367
|
-
function isFilesArray(validator, schema, uiSchema = {}, rootSchema) {
|
|
1890
|
+
function isFilesArray(validator, schema, uiSchema = {}, rootSchema, experimental_customMergeAllOf) {
|
|
1368
1891
|
if (uiSchema[UI_WIDGET_KEY] === "files") {
|
|
1369
1892
|
return true;
|
|
1370
1893
|
}
|
|
1371
1894
|
if (schema.items) {
|
|
1372
|
-
const itemsSchema = retrieveSchema(
|
|
1895
|
+
const itemsSchema = retrieveSchema(
|
|
1896
|
+
validator,
|
|
1897
|
+
schema.items,
|
|
1898
|
+
rootSchema,
|
|
1899
|
+
void 0,
|
|
1900
|
+
experimental_customMergeAllOf
|
|
1901
|
+
);
|
|
1373
1902
|
return itemsSchema.type === "string" && itemsSchema.format === "data-url";
|
|
1374
1903
|
}
|
|
1375
1904
|
return false;
|
|
1376
1905
|
}
|
|
1377
1906
|
|
|
1378
1907
|
// src/schema/getDisplayLabel.ts
|
|
1379
|
-
function getDisplayLabel(validator, schema, uiSchema = {}, rootSchema, globalOptions) {
|
|
1908
|
+
function getDisplayLabel(validator, schema, uiSchema = {}, rootSchema, globalOptions, experimental_customMergeAllOf) {
|
|
1380
1909
|
const uiOptions = getUiOptions(uiSchema, globalOptions);
|
|
1381
1910
|
const { label = true } = uiOptions;
|
|
1382
1911
|
let displayLabel = !!label;
|
|
1383
1912
|
const schemaType = getSchemaType(schema);
|
|
1384
1913
|
if (schemaType === "array") {
|
|
1385
|
-
displayLabel = isMultiSelect(validator, schema, rootSchema) || isFilesArray(validator, schema, uiSchema, rootSchema) || isCustomWidget(uiSchema);
|
|
1914
|
+
displayLabel = isMultiSelect(validator, schema, rootSchema, experimental_customMergeAllOf) || isFilesArray(validator, schema, uiSchema, rootSchema, experimental_customMergeAllOf) || isCustomWidget(uiSchema);
|
|
1386
1915
|
}
|
|
1387
1916
|
if (schemaType === "object") {
|
|
1388
1917
|
displayLabel = false;
|
|
@@ -1396,54 +1925,50 @@ function getDisplayLabel(validator, schema, uiSchema = {}, rootSchema, globalOpt
|
|
|
1396
1925
|
return displayLabel;
|
|
1397
1926
|
}
|
|
1398
1927
|
|
|
1399
|
-
// src/schema/mergeValidationData.ts
|
|
1400
|
-
var import_isEmpty2 = __toESM(require("lodash/isEmpty"));
|
|
1401
|
-
function mergeValidationData(validator, validationData, additionalErrorSchema) {
|
|
1402
|
-
if (!additionalErrorSchema) {
|
|
1403
|
-
return validationData;
|
|
1404
|
-
}
|
|
1405
|
-
const { errors: oldErrors, errorSchema: oldErrorSchema } = validationData;
|
|
1406
|
-
let errors = validator.toErrorList(additionalErrorSchema);
|
|
1407
|
-
let errorSchema = additionalErrorSchema;
|
|
1408
|
-
if (!(0, import_isEmpty2.default)(oldErrorSchema)) {
|
|
1409
|
-
errorSchema = mergeObjects(oldErrorSchema, additionalErrorSchema, true);
|
|
1410
|
-
errors = [...oldErrors].concat(errors);
|
|
1411
|
-
}
|
|
1412
|
-
return { errorSchema, errors };
|
|
1413
|
-
}
|
|
1414
|
-
|
|
1415
1928
|
// src/schema/sanitizeDataForNewSchema.ts
|
|
1416
|
-
var
|
|
1417
|
-
var
|
|
1929
|
+
var import_get12 = __toESM(require("lodash/get"), 1);
|
|
1930
|
+
var import_has5 = __toESM(require("lodash/has"), 1);
|
|
1418
1931
|
var NO_VALUE = Symbol("no Value");
|
|
1419
|
-
function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, data = {}) {
|
|
1932
|
+
function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, data = {}, experimental_customMergeAllOf) {
|
|
1420
1933
|
let newFormData;
|
|
1421
|
-
if ((0,
|
|
1934
|
+
if ((0, import_has5.default)(newSchema, PROPERTIES_KEY)) {
|
|
1422
1935
|
const removeOldSchemaData = {};
|
|
1423
|
-
if ((0,
|
|
1424
|
-
const properties = (0,
|
|
1936
|
+
if ((0, import_has5.default)(oldSchema, PROPERTIES_KEY)) {
|
|
1937
|
+
const properties = (0, import_get12.default)(oldSchema, PROPERTIES_KEY, {});
|
|
1425
1938
|
Object.keys(properties).forEach((key) => {
|
|
1426
|
-
if ((0,
|
|
1939
|
+
if ((0, import_has5.default)(data, key)) {
|
|
1427
1940
|
removeOldSchemaData[key] = void 0;
|
|
1428
1941
|
}
|
|
1429
1942
|
});
|
|
1430
1943
|
}
|
|
1431
|
-
const
|
|
1944
|
+
const keys2 = Object.keys((0, import_get12.default)(newSchema, PROPERTIES_KEY, {}));
|
|
1432
1945
|
const nestedData = {};
|
|
1433
|
-
|
|
1434
|
-
const formValue = (0,
|
|
1435
|
-
let oldKeyedSchema = (0,
|
|
1436
|
-
let newKeyedSchema = (0,
|
|
1437
|
-
if ((0,
|
|
1438
|
-
oldKeyedSchema = retrieveSchema(
|
|
1946
|
+
keys2.forEach((key) => {
|
|
1947
|
+
const formValue = (0, import_get12.default)(data, key);
|
|
1948
|
+
let oldKeyedSchema = (0, import_get12.default)(oldSchema, [PROPERTIES_KEY, key], {});
|
|
1949
|
+
let newKeyedSchema = (0, import_get12.default)(newSchema, [PROPERTIES_KEY, key], {});
|
|
1950
|
+
if ((0, import_has5.default)(oldKeyedSchema, REF_KEY)) {
|
|
1951
|
+
oldKeyedSchema = retrieveSchema(
|
|
1952
|
+
validator,
|
|
1953
|
+
oldKeyedSchema,
|
|
1954
|
+
rootSchema,
|
|
1955
|
+
formValue,
|
|
1956
|
+
experimental_customMergeAllOf
|
|
1957
|
+
);
|
|
1439
1958
|
}
|
|
1440
|
-
if ((0,
|
|
1441
|
-
newKeyedSchema = retrieveSchema(
|
|
1959
|
+
if ((0, import_has5.default)(newKeyedSchema, REF_KEY)) {
|
|
1960
|
+
newKeyedSchema = retrieveSchema(
|
|
1961
|
+
validator,
|
|
1962
|
+
newKeyedSchema,
|
|
1963
|
+
rootSchema,
|
|
1964
|
+
formValue,
|
|
1965
|
+
experimental_customMergeAllOf
|
|
1966
|
+
);
|
|
1442
1967
|
}
|
|
1443
|
-
const oldSchemaTypeForKey = (0,
|
|
1444
|
-
const newSchemaTypeForKey = (0,
|
|
1968
|
+
const oldSchemaTypeForKey = (0, import_get12.default)(oldKeyedSchema, "type");
|
|
1969
|
+
const newSchemaTypeForKey = (0, import_get12.default)(newKeyedSchema, "type");
|
|
1445
1970
|
if (!oldSchemaTypeForKey || oldSchemaTypeForKey === newSchemaTypeForKey) {
|
|
1446
|
-
if ((0,
|
|
1971
|
+
if ((0, import_has5.default)(removeOldSchemaData, key)) {
|
|
1447
1972
|
delete removeOldSchemaData[key];
|
|
1448
1973
|
}
|
|
1449
1974
|
if (newSchemaTypeForKey === "object" || newSchemaTypeForKey === "array" && Array.isArray(formValue)) {
|
|
@@ -1452,23 +1977,24 @@ function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, d
|
|
|
1452
1977
|
rootSchema,
|
|
1453
1978
|
newKeyedSchema,
|
|
1454
1979
|
oldKeyedSchema,
|
|
1455
|
-
formValue
|
|
1980
|
+
formValue,
|
|
1981
|
+
experimental_customMergeAllOf
|
|
1456
1982
|
);
|
|
1457
1983
|
if (itemData !== void 0 || newSchemaTypeForKey === "array") {
|
|
1458
1984
|
nestedData[key] = itemData;
|
|
1459
1985
|
}
|
|
1460
1986
|
} else {
|
|
1461
|
-
const newOptionDefault = (0,
|
|
1462
|
-
const oldOptionDefault = (0,
|
|
1987
|
+
const newOptionDefault = (0, import_get12.default)(newKeyedSchema, "default", NO_VALUE);
|
|
1988
|
+
const oldOptionDefault = (0, import_get12.default)(oldKeyedSchema, "default", NO_VALUE);
|
|
1463
1989
|
if (newOptionDefault !== NO_VALUE && newOptionDefault !== formValue) {
|
|
1464
1990
|
if (oldOptionDefault === formValue) {
|
|
1465
1991
|
removeOldSchemaData[key] = newOptionDefault;
|
|
1466
|
-
} else if ((0,
|
|
1992
|
+
} else if ((0, import_get12.default)(newKeyedSchema, "readOnly") === true) {
|
|
1467
1993
|
removeOldSchemaData[key] = void 0;
|
|
1468
1994
|
}
|
|
1469
1995
|
}
|
|
1470
|
-
const newOptionConst = (0,
|
|
1471
|
-
const oldOptionConst = (0,
|
|
1996
|
+
const newOptionConst = (0, import_get12.default)(newKeyedSchema, "const", NO_VALUE);
|
|
1997
|
+
const oldOptionConst = (0, import_get12.default)(oldKeyedSchema, "const", NO_VALUE);
|
|
1472
1998
|
if (newOptionConst !== NO_VALUE && newOptionConst !== formValue) {
|
|
1473
1999
|
removeOldSchemaData[key] = oldOptionConst === formValue ? newOptionConst : void 0;
|
|
1474
2000
|
}
|
|
@@ -1480,20 +2006,32 @@ function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, d
|
|
|
1480
2006
|
...removeOldSchemaData,
|
|
1481
2007
|
...nestedData
|
|
1482
2008
|
};
|
|
1483
|
-
} else if ((0,
|
|
1484
|
-
let oldSchemaItems = (0,
|
|
1485
|
-
let newSchemaItems = (0,
|
|
2009
|
+
} else if ((0, import_get12.default)(oldSchema, "type") === "array" && (0, import_get12.default)(newSchema, "type") === "array" && Array.isArray(data)) {
|
|
2010
|
+
let oldSchemaItems = (0, import_get12.default)(oldSchema, "items");
|
|
2011
|
+
let newSchemaItems = (0, import_get12.default)(newSchema, "items");
|
|
1486
2012
|
if (typeof oldSchemaItems === "object" && typeof newSchemaItems === "object" && !Array.isArray(oldSchemaItems) && !Array.isArray(newSchemaItems)) {
|
|
1487
|
-
if ((0,
|
|
1488
|
-
oldSchemaItems = retrieveSchema(
|
|
2013
|
+
if ((0, import_has5.default)(oldSchemaItems, REF_KEY)) {
|
|
2014
|
+
oldSchemaItems = retrieveSchema(
|
|
2015
|
+
validator,
|
|
2016
|
+
oldSchemaItems,
|
|
2017
|
+
rootSchema,
|
|
2018
|
+
data,
|
|
2019
|
+
experimental_customMergeAllOf
|
|
2020
|
+
);
|
|
1489
2021
|
}
|
|
1490
|
-
if ((0,
|
|
1491
|
-
newSchemaItems = retrieveSchema(
|
|
2022
|
+
if ((0, import_has5.default)(newSchemaItems, REF_KEY)) {
|
|
2023
|
+
newSchemaItems = retrieveSchema(
|
|
2024
|
+
validator,
|
|
2025
|
+
newSchemaItems,
|
|
2026
|
+
rootSchema,
|
|
2027
|
+
data,
|
|
2028
|
+
experimental_customMergeAllOf
|
|
2029
|
+
);
|
|
1492
2030
|
}
|
|
1493
|
-
const oldSchemaType = (0,
|
|
1494
|
-
const newSchemaType = (0,
|
|
2031
|
+
const oldSchemaType = (0, import_get12.default)(oldSchemaItems, "type");
|
|
2032
|
+
const newSchemaType = (0, import_get12.default)(newSchemaItems, "type");
|
|
1495
2033
|
if (!oldSchemaType || oldSchemaType === newSchemaType) {
|
|
1496
|
-
const maxItems = (0,
|
|
2034
|
+
const maxItems = (0, import_get12.default)(newSchema, "maxItems", -1);
|
|
1497
2035
|
if (newSchemaType === "object") {
|
|
1498
2036
|
newFormData = data.reduce((newValue, aValue) => {
|
|
1499
2037
|
const itemValue = sanitizeDataForNewSchema(
|
|
@@ -1501,7 +2039,8 @@ function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, d
|
|
|
1501
2039
|
rootSchema,
|
|
1502
2040
|
newSchemaItems,
|
|
1503
2041
|
oldSchemaItems,
|
|
1504
|
-
aValue
|
|
2042
|
+
aValue,
|
|
2043
|
+
experimental_customMergeAllOf
|
|
1505
2044
|
);
|
|
1506
2045
|
if (itemValue !== void 0 && (maxItems < 0 || newValue.length < maxItems)) {
|
|
1507
2046
|
newValue.push(itemValue);
|
|
@@ -1520,71 +2059,84 @@ function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, d
|
|
|
1520
2059
|
}
|
|
1521
2060
|
|
|
1522
2061
|
// src/schema/toIdSchema.ts
|
|
1523
|
-
var
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
2062
|
+
var import_get13 = __toESM(require("lodash/get"), 1);
|
|
2063
|
+
function toIdSchemaInternal(validator, schema, idPrefix, idSeparator, id, rootSchema, formData, _recurseList = [], experimental_customMergeAllOf) {
|
|
2064
|
+
const $id = id || idPrefix;
|
|
2065
|
+
const idSchema = { $id };
|
|
2066
|
+
if (typeof schema === "object") {
|
|
2067
|
+
if (REF_KEY in schema || DEPENDENCIES_KEY in schema || ALL_OF_KEY in schema) {
|
|
2068
|
+
const _schema = retrieveSchema(validator, schema, rootSchema, formData, experimental_customMergeAllOf);
|
|
2069
|
+
const sameSchemaIndex = _recurseList.findIndex((item) => deepEquals(item, _schema));
|
|
2070
|
+
if (sameSchemaIndex === -1) {
|
|
2071
|
+
return toIdSchemaInternal(
|
|
2072
|
+
validator,
|
|
2073
|
+
_schema,
|
|
2074
|
+
idPrefix,
|
|
2075
|
+
idSeparator,
|
|
2076
|
+
id,
|
|
2077
|
+
rootSchema,
|
|
2078
|
+
formData,
|
|
2079
|
+
_recurseList.concat(_schema),
|
|
2080
|
+
experimental_customMergeAllOf
|
|
2081
|
+
);
|
|
2082
|
+
}
|
|
2083
|
+
}
|
|
2084
|
+
if (ITEMS_KEY in schema && !(0, import_get13.default)(schema, [ITEMS_KEY, REF_KEY])) {
|
|
1530
2085
|
return toIdSchemaInternal(
|
|
1531
2086
|
validator,
|
|
1532
|
-
|
|
2087
|
+
(0, import_get13.default)(schema, ITEMS_KEY),
|
|
1533
2088
|
idPrefix,
|
|
1534
2089
|
idSeparator,
|
|
1535
2090
|
id,
|
|
1536
2091
|
rootSchema,
|
|
1537
2092
|
formData,
|
|
1538
|
-
_recurseList
|
|
2093
|
+
_recurseList,
|
|
2094
|
+
experimental_customMergeAllOf
|
|
1539
2095
|
);
|
|
1540
2096
|
}
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
const fieldId = idSchema[ID_KEY] + idSeparator + name;
|
|
1560
|
-
idSchema[name] = toIdSchemaInternal(
|
|
1561
|
-
validator,
|
|
1562
|
-
isObject(field) ? field : {},
|
|
1563
|
-
idPrefix,
|
|
1564
|
-
idSeparator,
|
|
1565
|
-
fieldId,
|
|
1566
|
-
rootSchema,
|
|
1567
|
-
// It's possible that formData is not an object -- this can happen if an
|
|
1568
|
-
// array item has just been added, but not populated with data yet
|
|
1569
|
-
(0, import_get9.default)(formData, [name]),
|
|
1570
|
-
_recurseList
|
|
1571
|
-
);
|
|
2097
|
+
if (getSchemaType(schema) === "object" && PROPERTIES_KEY in schema) {
|
|
2098
|
+
for (const name in schema.properties) {
|
|
2099
|
+
const field = schema[PROPERTIES_KEY][name];
|
|
2100
|
+
const fieldId = idSchema[ID_KEY] + idSeparator + name;
|
|
2101
|
+
idSchema[name] = toIdSchemaInternal(
|
|
2102
|
+
validator,
|
|
2103
|
+
field,
|
|
2104
|
+
idPrefix,
|
|
2105
|
+
idSeparator,
|
|
2106
|
+
fieldId,
|
|
2107
|
+
rootSchema,
|
|
2108
|
+
// It's possible that formData is not an object -- this can happen if an
|
|
2109
|
+
// array item has just been added, but not populated with data yet
|
|
2110
|
+
(0, import_get13.default)(formData, [name]),
|
|
2111
|
+
_recurseList,
|
|
2112
|
+
experimental_customMergeAllOf
|
|
2113
|
+
);
|
|
2114
|
+
}
|
|
1572
2115
|
}
|
|
1573
2116
|
}
|
|
1574
2117
|
return idSchema;
|
|
1575
2118
|
}
|
|
1576
|
-
function toIdSchema(validator, schema, id, rootSchema, formData, idPrefix = "root", idSeparator = "_") {
|
|
1577
|
-
return toIdSchemaInternal(
|
|
2119
|
+
function toIdSchema(validator, schema, id, rootSchema, formData, idPrefix = "root", idSeparator = "_", experimental_customMergeAllOf) {
|
|
2120
|
+
return toIdSchemaInternal(
|
|
2121
|
+
validator,
|
|
2122
|
+
schema,
|
|
2123
|
+
idPrefix,
|
|
2124
|
+
idSeparator,
|
|
2125
|
+
id,
|
|
2126
|
+
rootSchema,
|
|
2127
|
+
formData,
|
|
2128
|
+
void 0,
|
|
2129
|
+
experimental_customMergeAllOf
|
|
2130
|
+
);
|
|
1578
2131
|
}
|
|
1579
2132
|
|
|
1580
2133
|
// src/schema/toPathSchema.ts
|
|
1581
|
-
var
|
|
1582
|
-
var
|
|
1583
|
-
|
|
1584
|
-
function toPathSchemaInternal(validator, schema, name, rootSchema, formData, _recurseList = []) {
|
|
2134
|
+
var import_get14 = __toESM(require("lodash/get"), 1);
|
|
2135
|
+
var import_set2 = __toESM(require("lodash/set"), 1);
|
|
2136
|
+
function toPathSchemaInternal(validator, schema, name, rootSchema, formData, _recurseList = [], experimental_customMergeAllOf) {
|
|
1585
2137
|
if (REF_KEY in schema || DEPENDENCIES_KEY in schema || ALL_OF_KEY in schema) {
|
|
1586
|
-
const _schema = retrieveSchema(validator, schema, rootSchema, formData);
|
|
1587
|
-
const sameSchemaIndex = _recurseList.findIndex((item) => (
|
|
2138
|
+
const _schema = retrieveSchema(validator, schema, rootSchema, formData, experimental_customMergeAllOf);
|
|
2139
|
+
const sameSchemaIndex = _recurseList.findIndex((item) => deepEquals(item, _schema));
|
|
1588
2140
|
if (sameSchemaIndex === -1) {
|
|
1589
2141
|
return toPathSchemaInternal(
|
|
1590
2142
|
validator,
|
|
@@ -1592,7 +2144,8 @@ function toPathSchemaInternal(validator, schema, name, rootSchema, formData, _re
|
|
|
1592
2144
|
name,
|
|
1593
2145
|
rootSchema,
|
|
1594
2146
|
formData,
|
|
1595
|
-
_recurseList.concat(_schema)
|
|
2147
|
+
_recurseList.concat(_schema),
|
|
2148
|
+
experimental_customMergeAllOf
|
|
1596
2149
|
);
|
|
1597
2150
|
}
|
|
1598
2151
|
}
|
|
@@ -1602,11 +2155,27 @@ function toPathSchemaInternal(validator, schema, name, rootSchema, formData, _re
|
|
|
1602
2155
|
if (ONE_OF_KEY in schema || ANY_OF_KEY in schema) {
|
|
1603
2156
|
const xxxOf = ONE_OF_KEY in schema ? schema.oneOf : schema.anyOf;
|
|
1604
2157
|
const discriminator = getDiscriminatorFieldFromSchema(schema);
|
|
1605
|
-
const index = getClosestMatchingOption(
|
|
2158
|
+
const index = getClosestMatchingOption(
|
|
2159
|
+
validator,
|
|
2160
|
+
rootSchema,
|
|
2161
|
+
formData,
|
|
2162
|
+
xxxOf,
|
|
2163
|
+
0,
|
|
2164
|
+
discriminator,
|
|
2165
|
+
experimental_customMergeAllOf
|
|
2166
|
+
);
|
|
1606
2167
|
const _schema = xxxOf[index];
|
|
1607
2168
|
pathSchema = {
|
|
1608
2169
|
...pathSchema,
|
|
1609
|
-
...toPathSchemaInternal(
|
|
2170
|
+
...toPathSchemaInternal(
|
|
2171
|
+
validator,
|
|
2172
|
+
_schema,
|
|
2173
|
+
name,
|
|
2174
|
+
rootSchema,
|
|
2175
|
+
formData,
|
|
2176
|
+
_recurseList,
|
|
2177
|
+
experimental_customMergeAllOf
|
|
2178
|
+
)
|
|
1610
2179
|
};
|
|
1611
2180
|
}
|
|
1612
2181
|
if (ADDITIONAL_PROPERTIES_KEY in schema && schema[ADDITIONAL_PROPERTIES_KEY] !== false) {
|
|
@@ -1623,7 +2192,8 @@ function toPathSchemaInternal(validator, schema, name, rootSchema, formData, _re
|
|
|
1623
2192
|
`${name}.${i}`,
|
|
1624
2193
|
rootSchema,
|
|
1625
2194
|
element,
|
|
1626
|
-
_recurseList
|
|
2195
|
+
_recurseList,
|
|
2196
|
+
experimental_customMergeAllOf
|
|
1627
2197
|
);
|
|
1628
2198
|
} else if (schemaAdditionalItems) {
|
|
1629
2199
|
pathSchema[i] = toPathSchemaInternal(
|
|
@@ -1632,7 +2202,8 @@ function toPathSchemaInternal(validator, schema, name, rootSchema, formData, _re
|
|
|
1632
2202
|
`${name}.${i}`,
|
|
1633
2203
|
rootSchema,
|
|
1634
2204
|
element,
|
|
1635
|
-
_recurseList
|
|
2205
|
+
_recurseList,
|
|
2206
|
+
experimental_customMergeAllOf
|
|
1636
2207
|
);
|
|
1637
2208
|
} else {
|
|
1638
2209
|
console.warn(`Unable to generate path schema for "${name}.${i}". No schema defined for it`);
|
|
@@ -1646,13 +2217,14 @@ function toPathSchemaInternal(validator, schema, name, rootSchema, formData, _re
|
|
|
1646
2217
|
`${name}.${i}`,
|
|
1647
2218
|
rootSchema,
|
|
1648
2219
|
element,
|
|
1649
|
-
_recurseList
|
|
2220
|
+
_recurseList,
|
|
2221
|
+
experimental_customMergeAllOf
|
|
1650
2222
|
);
|
|
1651
2223
|
});
|
|
1652
2224
|
}
|
|
1653
2225
|
} else if (PROPERTIES_KEY in schema) {
|
|
1654
2226
|
for (const property in schema.properties) {
|
|
1655
|
-
const field = (0,
|
|
2227
|
+
const field = (0, import_get14.default)(schema, [PROPERTIES_KEY, property], {});
|
|
1656
2228
|
pathSchema[property] = toPathSchemaInternal(
|
|
1657
2229
|
validator,
|
|
1658
2230
|
field,
|
|
@@ -1660,15 +2232,16 @@ function toPathSchemaInternal(validator, schema, name, rootSchema, formData, _re
|
|
|
1660
2232
|
rootSchema,
|
|
1661
2233
|
// It's possible that formData is not an object -- this can happen if an
|
|
1662
2234
|
// array item has just been added, but not populated with data yet
|
|
1663
|
-
(0,
|
|
1664
|
-
_recurseList
|
|
2235
|
+
(0, import_get14.default)(formData, [property]),
|
|
2236
|
+
_recurseList,
|
|
2237
|
+
experimental_customMergeAllOf
|
|
1665
2238
|
);
|
|
1666
2239
|
}
|
|
1667
2240
|
}
|
|
1668
2241
|
return pathSchema;
|
|
1669
2242
|
}
|
|
1670
|
-
function toPathSchema(validator, schema, name = "", rootSchema, formData) {
|
|
1671
|
-
return toPathSchemaInternal(validator, schema, name, rootSchema, formData);
|
|
2243
|
+
function toPathSchema(validator, schema, name = "", rootSchema, formData, experimental_customMergeAllOf) {
|
|
2244
|
+
return toPathSchemaInternal(validator, schema, name, rootSchema, formData, void 0, experimental_customMergeAllOf);
|
|
1672
2245
|
}
|
|
1673
2246
|
|
|
1674
2247
|
// src/createSchemaUtils.ts
|
|
@@ -1678,11 +2251,13 @@ var SchemaUtils = class {
|
|
|
1678
2251
|
* @param validator - An implementation of the `ValidatorType` interface that will be forwarded to all the APIs
|
|
1679
2252
|
* @param rootSchema - The root schema that will be forwarded to all the APIs
|
|
1680
2253
|
* @param experimental_defaultFormStateBehavior - Configuration flags to allow users to override default form state behavior
|
|
2254
|
+
* @param [experimental_customMergeAllOf] - Optional function that allows for custom merging of `allOf` schemas
|
|
1681
2255
|
*/
|
|
1682
|
-
constructor(validator, rootSchema, experimental_defaultFormStateBehavior) {
|
|
2256
|
+
constructor(validator, rootSchema, experimental_defaultFormStateBehavior, experimental_customMergeAllOf) {
|
|
1683
2257
|
this.rootSchema = rootSchema;
|
|
1684
2258
|
this.validator = validator;
|
|
1685
2259
|
this.experimental_defaultFormStateBehavior = experimental_defaultFormStateBehavior;
|
|
2260
|
+
this.experimental_customMergeAllOf = experimental_customMergeAllOf;
|
|
1686
2261
|
}
|
|
1687
2262
|
/** Returns the `ValidatorType` in the `SchemaUtilsType`
|
|
1688
2263
|
*
|
|
@@ -1698,13 +2273,55 @@ var SchemaUtils = class {
|
|
|
1698
2273
|
* @param validator - An implementation of the `ValidatorType` interface that will be compared against the current one
|
|
1699
2274
|
* @param rootSchema - The root schema that will be compared against the current one
|
|
1700
2275
|
* @param [experimental_defaultFormStateBehavior] Optional configuration object, if provided, allows users to override default form state behavior
|
|
2276
|
+
* @param [experimental_customMergeAllOf] - Optional function that allows for custom merging of `allOf` schemas
|
|
1701
2277
|
* @returns - True if the `SchemaUtilsType` differs from the given `validator` or `rootSchema`
|
|
1702
2278
|
*/
|
|
1703
|
-
doesSchemaUtilsDiffer(validator, rootSchema, experimental_defaultFormStateBehavior = {}) {
|
|
2279
|
+
doesSchemaUtilsDiffer(validator, rootSchema, experimental_defaultFormStateBehavior = {}, experimental_customMergeAllOf) {
|
|
1704
2280
|
if (!validator || !rootSchema) {
|
|
1705
2281
|
return false;
|
|
1706
2282
|
}
|
|
1707
|
-
return this.validator !== validator || !deepEquals(this.rootSchema, rootSchema) || !deepEquals(this.experimental_defaultFormStateBehavior, experimental_defaultFormStateBehavior);
|
|
2283
|
+
return this.validator !== validator || !deepEquals(this.rootSchema, rootSchema) || !deepEquals(this.experimental_defaultFormStateBehavior, experimental_defaultFormStateBehavior) || this.experimental_customMergeAllOf !== experimental_customMergeAllOf;
|
|
2284
|
+
}
|
|
2285
|
+
/** Finds the field specified by the `path` within the root or recursed `schema`. If there is no field for the specified
|
|
2286
|
+
* `path`, then the default `{ field: undefined, isRequired: undefined }` is returned. It determines whether a leaf
|
|
2287
|
+
* field is in the `required` list for its parent and if so, it is marked as required on return.
|
|
2288
|
+
*
|
|
2289
|
+
* @param schema - The current node within the JSON schema
|
|
2290
|
+
* @param path - The remaining keys in the path to the desired field
|
|
2291
|
+
* @param [formData] - The form data that is used to determine which oneOf option
|
|
2292
|
+
* @returns - An object that contains the field and its required state. If no field can be found then
|
|
2293
|
+
* `{ field: undefined, isRequired: undefined }` is returned.
|
|
2294
|
+
*/
|
|
2295
|
+
findFieldInSchema(schema, path, formData) {
|
|
2296
|
+
return findFieldInSchema(
|
|
2297
|
+
this.validator,
|
|
2298
|
+
this.rootSchema,
|
|
2299
|
+
schema,
|
|
2300
|
+
path,
|
|
2301
|
+
formData,
|
|
2302
|
+
this.experimental_customMergeAllOf
|
|
2303
|
+
);
|
|
2304
|
+
}
|
|
2305
|
+
/** Finds the oneOf option inside the `schema['any/oneOf']` list which has the `properties[selectorField].default` that
|
|
2306
|
+
* matches the `formData[selectorField]` value. For the purposes of this function, `selectorField` is either
|
|
2307
|
+
* `schema.discriminator.propertyName` or `fallbackField`.
|
|
2308
|
+
*
|
|
2309
|
+
* @param schema - The schema element in which to search for the selected oneOf option
|
|
2310
|
+
* @param fallbackField - The field to use as a backup selector field if the schema does not have a required field
|
|
2311
|
+
* @param xxx - Either `oneOf` or `anyOf`, defines which value is being sought
|
|
2312
|
+
* @param [formData={}] - The form data that is used to determine which oneOf option
|
|
2313
|
+
* @returns - The anyOf/oneOf option that matches the selector field in the schema or undefined if nothing is selected
|
|
2314
|
+
*/
|
|
2315
|
+
findSelectedOptionInXxxOf(schema, fallbackField, xxx, formData) {
|
|
2316
|
+
return findSelectedOptionInXxxOf(
|
|
2317
|
+
this.validator,
|
|
2318
|
+
this.rootSchema,
|
|
2319
|
+
schema,
|
|
2320
|
+
fallbackField,
|
|
2321
|
+
xxx,
|
|
2322
|
+
formData,
|
|
2323
|
+
this.experimental_customMergeAllOf
|
|
2324
|
+
);
|
|
1708
2325
|
}
|
|
1709
2326
|
/** Returns the superset of `formData` that includes the given set updated to include any missing fields that have
|
|
1710
2327
|
* computed to have defaults provided in the `schema`.
|
|
@@ -1723,7 +2340,8 @@ var SchemaUtils = class {
|
|
|
1723
2340
|
formData,
|
|
1724
2341
|
this.rootSchema,
|
|
1725
2342
|
includeUndefinedValues,
|
|
1726
|
-
this.experimental_defaultFormStateBehavior
|
|
2343
|
+
this.experimental_defaultFormStateBehavior,
|
|
2344
|
+
this.experimental_customMergeAllOf
|
|
1727
2345
|
);
|
|
1728
2346
|
}
|
|
1729
2347
|
/** Determines whether the combination of `schema` and `uiSchema` properties indicates that the label for the `schema`
|
|
@@ -1735,7 +2353,14 @@ var SchemaUtils = class {
|
|
|
1735
2353
|
* @returns - True if the label should be displayed or false if it should not
|
|
1736
2354
|
*/
|
|
1737
2355
|
getDisplayLabel(schema, uiSchema, globalOptions) {
|
|
1738
|
-
return getDisplayLabel(
|
|
2356
|
+
return getDisplayLabel(
|
|
2357
|
+
this.validator,
|
|
2358
|
+
schema,
|
|
2359
|
+
uiSchema,
|
|
2360
|
+
this.rootSchema,
|
|
2361
|
+
globalOptions,
|
|
2362
|
+
this.experimental_customMergeAllOf
|
|
2363
|
+
);
|
|
1739
2364
|
}
|
|
1740
2365
|
/** Determines which of the given `options` provided most closely matches the `formData`.
|
|
1741
2366
|
* Returns the index of the option that is valid and is the closest match, or 0 if there is no match.
|
|
@@ -1757,7 +2382,8 @@ var SchemaUtils = class {
|
|
|
1757
2382
|
formData,
|
|
1758
2383
|
options,
|
|
1759
2384
|
selectedOption,
|
|
1760
|
-
discriminatorField
|
|
2385
|
+
discriminatorField,
|
|
2386
|
+
this.experimental_customMergeAllOf
|
|
1761
2387
|
);
|
|
1762
2388
|
}
|
|
1763
2389
|
/** Given the `formData` and list of `options`, attempts to find the index of the first option that matches the data.
|
|
@@ -1772,18 +2398,16 @@ var SchemaUtils = class {
|
|
|
1772
2398
|
getFirstMatchingOption(formData, options, discriminatorField) {
|
|
1773
2399
|
return getFirstMatchingOption(this.validator, formData, options, this.rootSchema, discriminatorField);
|
|
1774
2400
|
}
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
getMatchingOption(formData, options, discriminatorField) {
|
|
1786
|
-
return getMatchingOption(this.validator, formData, options, this.rootSchema, discriminatorField);
|
|
2401
|
+
getFromSchema(schema, path, defaultValue) {
|
|
2402
|
+
return getFromSchema(
|
|
2403
|
+
this.validator,
|
|
2404
|
+
this.rootSchema,
|
|
2405
|
+
schema,
|
|
2406
|
+
path,
|
|
2407
|
+
// @ts-expect-error TS2769: No overload matches this call
|
|
2408
|
+
defaultValue,
|
|
2409
|
+
this.experimental_customMergeAllOf
|
|
2410
|
+
);
|
|
1787
2411
|
}
|
|
1788
2412
|
/** Checks to see if the `schema` and `uiSchema` combination represents an array of files
|
|
1789
2413
|
*
|
|
@@ -1792,7 +2416,7 @@ var SchemaUtils = class {
|
|
|
1792
2416
|
* @returns - True if schema/uiSchema contains an array of files, otherwise false
|
|
1793
2417
|
*/
|
|
1794
2418
|
isFilesArray(schema, uiSchema) {
|
|
1795
|
-
return isFilesArray(this.validator, schema, uiSchema, this.rootSchema);
|
|
2419
|
+
return isFilesArray(this.validator, schema, uiSchema, this.rootSchema, this.experimental_customMergeAllOf);
|
|
1796
2420
|
}
|
|
1797
2421
|
/** Checks to see if the `schema` combination represents a multi-select
|
|
1798
2422
|
*
|
|
@@ -1800,7 +2424,7 @@ var SchemaUtils = class {
|
|
|
1800
2424
|
* @returns - True if schema contains a multi-select, otherwise false
|
|
1801
2425
|
*/
|
|
1802
2426
|
isMultiSelect(schema) {
|
|
1803
|
-
return isMultiSelect(this.validator, schema, this.rootSchema);
|
|
2427
|
+
return isMultiSelect(this.validator, schema, this.rootSchema, this.experimental_customMergeAllOf);
|
|
1804
2428
|
}
|
|
1805
2429
|
/** Checks to see if the `schema` combination represents a select
|
|
1806
2430
|
*
|
|
@@ -1808,21 +2432,7 @@ var SchemaUtils = class {
|
|
|
1808
2432
|
* @returns - True if schema contains a select, otherwise false
|
|
1809
2433
|
*/
|
|
1810
2434
|
isSelect(schema) {
|
|
1811
|
-
return isSelect(this.validator, schema, this.rootSchema);
|
|
1812
|
-
}
|
|
1813
|
-
/** Merges the errors in `additionalErrorSchema` into the existing `validationData` by combining the hierarchies in
|
|
1814
|
-
* the two `ErrorSchema`s and then appending the error list from the `additionalErrorSchema` obtained by calling
|
|
1815
|
-
* `getValidator().toErrorList()` onto the `errors` in the `validationData`. If no `additionalErrorSchema` is passed,
|
|
1816
|
-
* then `validationData` is returned.
|
|
1817
|
-
*
|
|
1818
|
-
* @param validationData - The current `ValidationData` into which to merge the additional errors
|
|
1819
|
-
* @param [additionalErrorSchema] - The additional set of errors
|
|
1820
|
-
* @returns - The `validationData` with the additional errors from `additionalErrorSchema` merged into it, if provided.
|
|
1821
|
-
* @deprecated - Use the `validationDataMerge()` function exported from `@rjsf/utils` instead. This function will be
|
|
1822
|
-
* removed in the next major release.
|
|
1823
|
-
*/
|
|
1824
|
-
mergeValidationData(validationData, additionalErrorSchema) {
|
|
1825
|
-
return mergeValidationData(this.validator, validationData, additionalErrorSchema);
|
|
2435
|
+
return isSelect(this.validator, schema, this.rootSchema, this.experimental_customMergeAllOf);
|
|
1826
2436
|
}
|
|
1827
2437
|
/** Retrieves an expanded schema that has had all of its conditions, additional properties, references and
|
|
1828
2438
|
* dependencies resolved and merged into the `schema` given a `rawFormData` that is used to do the potentially
|
|
@@ -1833,7 +2443,13 @@ var SchemaUtils = class {
|
|
|
1833
2443
|
* @returns - The schema having its conditions, additional properties, references and dependencies resolved
|
|
1834
2444
|
*/
|
|
1835
2445
|
retrieveSchema(schema, rawFormData) {
|
|
1836
|
-
return retrieveSchema(
|
|
2446
|
+
return retrieveSchema(
|
|
2447
|
+
this.validator,
|
|
2448
|
+
schema,
|
|
2449
|
+
this.rootSchema,
|
|
2450
|
+
rawFormData,
|
|
2451
|
+
this.experimental_customMergeAllOf
|
|
2452
|
+
);
|
|
1837
2453
|
}
|
|
1838
2454
|
/** Sanitize the `data` associated with the `oldSchema` so it is considered appropriate for the `newSchema`. If the
|
|
1839
2455
|
* new schema does not contain any properties, then `undefined` is returned to clear all the form data. Due to the
|
|
@@ -1847,7 +2463,14 @@ var SchemaUtils = class {
|
|
|
1847
2463
|
* to `undefined`. Will return `undefined` if the new schema is not an object containing properties.
|
|
1848
2464
|
*/
|
|
1849
2465
|
sanitizeDataForNewSchema(newSchema, oldSchema, data) {
|
|
1850
|
-
return sanitizeDataForNewSchema(
|
|
2466
|
+
return sanitizeDataForNewSchema(
|
|
2467
|
+
this.validator,
|
|
2468
|
+
this.rootSchema,
|
|
2469
|
+
newSchema,
|
|
2470
|
+
oldSchema,
|
|
2471
|
+
data,
|
|
2472
|
+
this.experimental_customMergeAllOf
|
|
2473
|
+
);
|
|
1851
2474
|
}
|
|
1852
2475
|
/** Generates an `IdSchema` object for the `schema`, recursively
|
|
1853
2476
|
*
|
|
@@ -1859,7 +2482,16 @@ var SchemaUtils = class {
|
|
|
1859
2482
|
* @returns - The `IdSchema` object for the `schema`
|
|
1860
2483
|
*/
|
|
1861
2484
|
toIdSchema(schema, id, formData, idPrefix = "root", idSeparator = "_") {
|
|
1862
|
-
return toIdSchema(
|
|
2485
|
+
return toIdSchema(
|
|
2486
|
+
this.validator,
|
|
2487
|
+
schema,
|
|
2488
|
+
id,
|
|
2489
|
+
this.rootSchema,
|
|
2490
|
+
formData,
|
|
2491
|
+
idPrefix,
|
|
2492
|
+
idSeparator,
|
|
2493
|
+
this.experimental_customMergeAllOf
|
|
2494
|
+
);
|
|
1863
2495
|
}
|
|
1864
2496
|
/** Generates an `PathSchema` object for the `schema`, recursively
|
|
1865
2497
|
*
|
|
@@ -1869,11 +2501,23 @@ var SchemaUtils = class {
|
|
|
1869
2501
|
* @returns - The `PathSchema` object for the `schema`
|
|
1870
2502
|
*/
|
|
1871
2503
|
toPathSchema(schema, name, formData) {
|
|
1872
|
-
return toPathSchema(
|
|
2504
|
+
return toPathSchema(
|
|
2505
|
+
this.validator,
|
|
2506
|
+
schema,
|
|
2507
|
+
name,
|
|
2508
|
+
this.rootSchema,
|
|
2509
|
+
formData,
|
|
2510
|
+
this.experimental_customMergeAllOf
|
|
2511
|
+
);
|
|
1873
2512
|
}
|
|
1874
2513
|
};
|
|
1875
|
-
function createSchemaUtils(validator, rootSchema, experimental_defaultFormStateBehavior = {}) {
|
|
1876
|
-
return new SchemaUtils(
|
|
2514
|
+
function createSchemaUtils(validator, rootSchema, experimental_defaultFormStateBehavior = {}, experimental_customMergeAllOf) {
|
|
2515
|
+
return new SchemaUtils(
|
|
2516
|
+
validator,
|
|
2517
|
+
rootSchema,
|
|
2518
|
+
experimental_defaultFormStateBehavior,
|
|
2519
|
+
experimental_customMergeAllOf
|
|
2520
|
+
);
|
|
1877
2521
|
}
|
|
1878
2522
|
|
|
1879
2523
|
// src/dataURItoBlob.ts
|
|
@@ -1955,9 +2599,6 @@ function englishStringTranslator(stringToTranslate, params) {
|
|
|
1955
2599
|
return replaceStringParameters(stringToTranslate, params);
|
|
1956
2600
|
}
|
|
1957
2601
|
|
|
1958
|
-
// src/enumOptionsDeselectValue.ts
|
|
1959
|
-
var import_isEqual4 = __toESM(require("lodash/isEqual"));
|
|
1960
|
-
|
|
1961
2602
|
// src/enumOptionsValueForIndex.ts
|
|
1962
2603
|
function enumOptionsValueForIndex(valueIndex, allEnumOptions = [], emptyValue) {
|
|
1963
2604
|
if (Array.isArray(valueIndex)) {
|
|
@@ -1972,18 +2613,17 @@ function enumOptionsValueForIndex(valueIndex, allEnumOptions = [], emptyValue) {
|
|
|
1972
2613
|
function enumOptionsDeselectValue(valueIndex, selected, allEnumOptions = []) {
|
|
1973
2614
|
const value = enumOptionsValueForIndex(valueIndex, allEnumOptions);
|
|
1974
2615
|
if (Array.isArray(selected)) {
|
|
1975
|
-
return selected.filter((v) => !(
|
|
2616
|
+
return selected.filter((v) => !deepEquals(v, value));
|
|
1976
2617
|
}
|
|
1977
|
-
return (
|
|
2618
|
+
return deepEquals(value, selected) ? void 0 : selected;
|
|
1978
2619
|
}
|
|
1979
2620
|
|
|
1980
2621
|
// src/enumOptionsIsSelected.ts
|
|
1981
|
-
var import_isEqual5 = __toESM(require("lodash/isEqual"));
|
|
1982
2622
|
function enumOptionsIsSelected(value, selected) {
|
|
1983
2623
|
if (Array.isArray(selected)) {
|
|
1984
|
-
return selected.some((sel) => (
|
|
2624
|
+
return selected.some((sel) => deepEquals(sel, value));
|
|
1985
2625
|
}
|
|
1986
|
-
return (
|
|
2626
|
+
return deepEquals(selected, value);
|
|
1987
2627
|
}
|
|
1988
2628
|
|
|
1989
2629
|
// src/enumOptionsIndexForValue.ts
|
|
@@ -1996,10 +2636,10 @@ function enumOptionsIndexForValue(value, allEnumOptions = [], multiple = false)
|
|
|
1996
2636
|
}
|
|
1997
2637
|
|
|
1998
2638
|
// src/enumOptionsSelectValue.ts
|
|
1999
|
-
var
|
|
2639
|
+
var import_isNil2 = __toESM(require("lodash/isNil"), 1);
|
|
2000
2640
|
function enumOptionsSelectValue(valueIndex, selected, allEnumOptions = []) {
|
|
2001
2641
|
const value = enumOptionsValueForIndex(valueIndex, allEnumOptions);
|
|
2002
|
-
if (!(0,
|
|
2642
|
+
if (!(0, import_isNil2.default)(value)) {
|
|
2003
2643
|
const index = allEnumOptions.findIndex((opt) => value === opt.value);
|
|
2004
2644
|
const all = allEnumOptions.map(({ value: val }) => val);
|
|
2005
2645
|
const updated = selected.slice(0, index).concat(value, selected.slice(index));
|
|
@@ -2009,9 +2649,10 @@ function enumOptionsSelectValue(valueIndex, selected, allEnumOptions = []) {
|
|
|
2009
2649
|
}
|
|
2010
2650
|
|
|
2011
2651
|
// src/ErrorSchemaBuilder.ts
|
|
2012
|
-
var import_cloneDeep = __toESM(require("lodash/cloneDeep"));
|
|
2013
|
-
var
|
|
2014
|
-
var import_set3 = __toESM(require("lodash/set"));
|
|
2652
|
+
var import_cloneDeep = __toESM(require("lodash/cloneDeep"), 1);
|
|
2653
|
+
var import_get15 = __toESM(require("lodash/get"), 1);
|
|
2654
|
+
var import_set3 = __toESM(require("lodash/set"), 1);
|
|
2655
|
+
var import_setWith = __toESM(require("lodash/setWith"), 1);
|
|
2015
2656
|
var ErrorSchemaBuilder = class {
|
|
2016
2657
|
/** Construct an `ErrorSchemaBuilder` with an optional initial set of errors in an `ErrorSchema`.
|
|
2017
2658
|
*
|
|
@@ -2038,10 +2679,10 @@ var ErrorSchemaBuilder = class {
|
|
|
2038
2679
|
*/
|
|
2039
2680
|
getOrCreateErrorBlock(pathOfError) {
|
|
2040
2681
|
const hasPath = Array.isArray(pathOfError) && pathOfError.length > 0 || typeof pathOfError === "string";
|
|
2041
|
-
let errorBlock = hasPath ? (0,
|
|
2682
|
+
let errorBlock = hasPath ? (0, import_get15.default)(this.errorSchema, pathOfError) : this.errorSchema;
|
|
2042
2683
|
if (!errorBlock && pathOfError) {
|
|
2043
2684
|
errorBlock = {};
|
|
2044
|
-
(0,
|
|
2685
|
+
(0, import_setWith.default)(this.errorSchema, pathOfError, errorBlock, Object);
|
|
2045
2686
|
}
|
|
2046
2687
|
return errorBlock;
|
|
2047
2688
|
}
|
|
@@ -2064,15 +2705,15 @@ var ErrorSchemaBuilder = class {
|
|
|
2064
2705
|
*/
|
|
2065
2706
|
addErrors(errorOrList, pathOfError) {
|
|
2066
2707
|
const errorBlock = this.getOrCreateErrorBlock(pathOfError);
|
|
2067
|
-
let errorsList = (0,
|
|
2708
|
+
let errorsList = (0, import_get15.default)(errorBlock, ERRORS_KEY);
|
|
2068
2709
|
if (!Array.isArray(errorsList)) {
|
|
2069
2710
|
errorsList = [];
|
|
2070
2711
|
errorBlock[ERRORS_KEY] = errorsList;
|
|
2071
2712
|
}
|
|
2072
2713
|
if (Array.isArray(errorOrList)) {
|
|
2073
|
-
|
|
2714
|
+
(0, import_set3.default)(errorBlock, ERRORS_KEY, [.../* @__PURE__ */ new Set([...errorsList, ...errorOrList])]);
|
|
2074
2715
|
} else {
|
|
2075
|
-
|
|
2716
|
+
(0, import_set3.default)(errorBlock, ERRORS_KEY, [.../* @__PURE__ */ new Set([...errorsList, errorOrList])]);
|
|
2076
2717
|
}
|
|
2077
2718
|
return this;
|
|
2078
2719
|
}
|
|
@@ -2086,7 +2727,7 @@ var ErrorSchemaBuilder = class {
|
|
|
2086
2727
|
*/
|
|
2087
2728
|
setErrors(errorOrList, pathOfError) {
|
|
2088
2729
|
const errorBlock = this.getOrCreateErrorBlock(pathOfError);
|
|
2089
|
-
const listToAdd = Array.isArray(errorOrList) ? [...errorOrList] : [errorOrList];
|
|
2730
|
+
const listToAdd = Array.isArray(errorOrList) ? [.../* @__PURE__ */ new Set([...errorOrList])] : [errorOrList];
|
|
2090
2731
|
(0, import_set3.default)(errorBlock, ERRORS_KEY, listToAdd);
|
|
2091
2732
|
return this;
|
|
2092
2733
|
}
|
|
@@ -2171,6 +2812,9 @@ function getInputProps(schema, defaultType, options = {}, autoDefaultStepAny = t
|
|
|
2171
2812
|
if (options.autocomplete) {
|
|
2172
2813
|
inputProps.autoComplete = options.autocomplete;
|
|
2173
2814
|
}
|
|
2815
|
+
if (options.accept) {
|
|
2816
|
+
inputProps.accept = options.accept;
|
|
2817
|
+
}
|
|
2174
2818
|
return inputProps;
|
|
2175
2819
|
}
|
|
2176
2820
|
|
|
@@ -2197,6 +2841,10 @@ function getTemplate(name, registry, uiOptions = {}) {
|
|
|
2197
2841
|
if (name === "ButtonTemplates") {
|
|
2198
2842
|
return templates[name];
|
|
2199
2843
|
}
|
|
2844
|
+
if (Object.hasOwn(uiOptions, name) && typeof uiOptions[name] === "string" && Object.hasOwn(templates, uiOptions[name])) {
|
|
2845
|
+
const key = uiOptions[name];
|
|
2846
|
+
return templates[key];
|
|
2847
|
+
}
|
|
2200
2848
|
return (
|
|
2201
2849
|
// Evaluating uiOptions[name] results in TS2590: Expression produces a union type that is too complex to represent
|
|
2202
2850
|
// To avoid that, we cast uiOptions to `any` before accessing the name field
|
|
@@ -2204,11 +2852,32 @@ function getTemplate(name, registry, uiOptions = {}) {
|
|
|
2204
2852
|
);
|
|
2205
2853
|
}
|
|
2206
2854
|
|
|
2855
|
+
// src/getTestIds.ts
|
|
2856
|
+
var import_nanoid = require("nanoid");
|
|
2857
|
+
var import_get16 = __toESM(require("lodash/get"), 1);
|
|
2858
|
+
function getTestIds() {
|
|
2859
|
+
if (typeof process === "undefined" || (0, import_get16.default)(process, "env.NODE_ENV") !== "test") {
|
|
2860
|
+
return {};
|
|
2861
|
+
}
|
|
2862
|
+
const ids = /* @__PURE__ */ new Map();
|
|
2863
|
+
return new Proxy(
|
|
2864
|
+
{},
|
|
2865
|
+
{
|
|
2866
|
+
get(_obj, prop) {
|
|
2867
|
+
if (!ids.has(prop)) {
|
|
2868
|
+
ids.set(prop, (0, import_nanoid.nanoid)());
|
|
2869
|
+
}
|
|
2870
|
+
return ids.get(prop);
|
|
2871
|
+
}
|
|
2872
|
+
}
|
|
2873
|
+
);
|
|
2874
|
+
}
|
|
2875
|
+
|
|
2207
2876
|
// src/getWidget.tsx
|
|
2208
2877
|
var import_react = require("react");
|
|
2209
|
-
var import_react_is = __toESM(require("react-is"));
|
|
2210
|
-
var
|
|
2211
|
-
var import_set4 = __toESM(require("lodash/set"));
|
|
2878
|
+
var import_react_is = __toESM(require("react-is"), 1);
|
|
2879
|
+
var import_get17 = __toESM(require("lodash/get"), 1);
|
|
2880
|
+
var import_set4 = __toESM(require("lodash/set"), 1);
|
|
2212
2881
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
2213
2882
|
var widgetMap = {
|
|
2214
2883
|
boolean: {
|
|
@@ -2263,7 +2932,7 @@ var widgetMap = {
|
|
|
2263
2932
|
}
|
|
2264
2933
|
};
|
|
2265
2934
|
function mergeWidgetOptions(AWidget) {
|
|
2266
|
-
let MergedWidget = (0,
|
|
2935
|
+
let MergedWidget = (0, import_get17.default)(AWidget, "MergedWidget");
|
|
2267
2936
|
if (!MergedWidget) {
|
|
2268
2937
|
const defaultOptions = AWidget.defaultProps && AWidget.defaultProps.options || {};
|
|
2269
2938
|
MergedWidget = ({ options, ...props }) => {
|
|
@@ -2307,10 +2976,16 @@ function hashString(string) {
|
|
|
2307
2976
|
}
|
|
2308
2977
|
return hash.toString(16);
|
|
2309
2978
|
}
|
|
2310
|
-
function
|
|
2979
|
+
function sortedJSONStringify(object) {
|
|
2311
2980
|
const allKeys = /* @__PURE__ */ new Set();
|
|
2312
|
-
JSON.stringify(
|
|
2313
|
-
return
|
|
2981
|
+
JSON.stringify(object, (key, value) => (allKeys.add(key), value));
|
|
2982
|
+
return JSON.stringify(object, Array.from(allKeys).sort());
|
|
2983
|
+
}
|
|
2984
|
+
function hashObject(object) {
|
|
2985
|
+
return hashString(sortedJSONStringify(object));
|
|
2986
|
+
}
|
|
2987
|
+
function hashForSchema(schema) {
|
|
2988
|
+
return hashObject(schema);
|
|
2314
2989
|
}
|
|
2315
2990
|
|
|
2316
2991
|
// src/hasWidget.ts
|
|
@@ -2328,9 +3003,9 @@ function hasWidget(schema, widget, registeredWidgets = {}) {
|
|
|
2328
3003
|
}
|
|
2329
3004
|
|
|
2330
3005
|
// src/idGenerators.ts
|
|
2331
|
-
var
|
|
3006
|
+
var import_isString4 = __toESM(require("lodash/isString"), 1);
|
|
2332
3007
|
function idGenerator(id, suffix) {
|
|
2333
|
-
const theId = (0,
|
|
3008
|
+
const theId = (0, import_isString4.default)(id) ? id : id[ID_KEY];
|
|
2334
3009
|
return `${theId}__${suffix}`;
|
|
2335
3010
|
}
|
|
2336
3011
|
function descriptionId(id) {
|
|
@@ -2355,6 +3030,9 @@ function ariaDescribedByIds(id, includeExamples = false) {
|
|
|
2355
3030
|
function optionId(id, optionIndex) {
|
|
2356
3031
|
return `${id}-${optionIndex}`;
|
|
2357
3032
|
}
|
|
3033
|
+
function buttonId(id, btn) {
|
|
3034
|
+
return idGenerator(id, btn);
|
|
3035
|
+
}
|
|
2358
3036
|
|
|
2359
3037
|
// src/labelValue.ts
|
|
2360
3038
|
function labelValue(label, hideLabel, fallback) {
|
|
@@ -2366,59 +3044,15 @@ function localToUTC(dateString) {
|
|
|
2366
3044
|
return dateString ? new Date(dateString).toJSON() : void 0;
|
|
2367
3045
|
}
|
|
2368
3046
|
|
|
2369
|
-
// src/
|
|
2370
|
-
|
|
2371
|
-
|
|
2372
|
-
|
|
2373
|
-
|
|
2374
|
-
if (
|
|
2375
|
-
|
|
2376
|
-
}
|
|
2377
|
-
throw new Error("schema cannot be inferred as a constant");
|
|
2378
|
-
}
|
|
2379
|
-
|
|
2380
|
-
// src/optionsList.ts
|
|
2381
|
-
function optionsList(schema, uiSchema) {
|
|
2382
|
-
const schemaWithEnumNames = schema;
|
|
2383
|
-
if (schema.enum) {
|
|
2384
|
-
let enumNames;
|
|
2385
|
-
if (uiSchema) {
|
|
2386
|
-
const { enumNames: uiEnumNames } = getUiOptions(uiSchema);
|
|
2387
|
-
enumNames = uiEnumNames;
|
|
2388
|
-
}
|
|
2389
|
-
if (!enumNames && schemaWithEnumNames.enumNames) {
|
|
2390
|
-
if (true) {
|
|
2391
|
-
console.warn(
|
|
2392
|
-
'The "enumNames" property in the schema is deprecated and will be removed in a future major release. Use the "ui:enumNames" property in the uiSchema instead.'
|
|
2393
|
-
);
|
|
2394
|
-
}
|
|
2395
|
-
enumNames = schemaWithEnumNames.enumNames;
|
|
2396
|
-
}
|
|
2397
|
-
return schema.enum.map((value, i) => {
|
|
2398
|
-
const label = enumNames?.[i] || String(value);
|
|
2399
|
-
return { label, value };
|
|
2400
|
-
});
|
|
2401
|
-
}
|
|
2402
|
-
let altSchemas = void 0;
|
|
2403
|
-
let altUiSchemas = void 0;
|
|
2404
|
-
if (schema.anyOf) {
|
|
2405
|
-
altSchemas = schema.anyOf;
|
|
2406
|
-
altUiSchemas = uiSchema?.anyOf;
|
|
2407
|
-
} else if (schema.oneOf) {
|
|
2408
|
-
altSchemas = schema.oneOf;
|
|
2409
|
-
altUiSchemas = uiSchema?.oneOf;
|
|
3047
|
+
// src/lookupFromFormContext.ts
|
|
3048
|
+
var import_get18 = __toESM(require("lodash/get"), 1);
|
|
3049
|
+
var import_has6 = __toESM(require("lodash/has"), 1);
|
|
3050
|
+
function lookupFromFormContext(regOrFc, toLookup, fallback) {
|
|
3051
|
+
const lookupPath = [LOOKUP_MAP_NAME];
|
|
3052
|
+
if ((0, import_has6.default)(regOrFc, FORM_CONTEXT_NAME)) {
|
|
3053
|
+
lookupPath.unshift(FORM_CONTEXT_NAME);
|
|
2410
3054
|
}
|
|
2411
|
-
return
|
|
2412
|
-
const { title } = getUiOptions(altUiSchemas?.[index]);
|
|
2413
|
-
const aSchema = aSchemaDef;
|
|
2414
|
-
const value = toConstant(aSchema);
|
|
2415
|
-
const label = title || aSchema.title || String(value);
|
|
2416
|
-
return {
|
|
2417
|
-
schema: aSchema,
|
|
2418
|
-
label,
|
|
2419
|
-
value
|
|
2420
|
-
};
|
|
2421
|
-
});
|
|
3055
|
+
return (0, import_get18.default)(regOrFc, [...lookupPath, toLookup], fallback);
|
|
2422
3056
|
}
|
|
2423
3057
|
|
|
2424
3058
|
// src/orderProperties.ts
|
|
@@ -2513,7 +3147,7 @@ function toDateString(dateObject, time = true) {
|
|
|
2513
3147
|
}
|
|
2514
3148
|
|
|
2515
3149
|
// src/toErrorList.ts
|
|
2516
|
-
var import_isPlainObject2 = __toESM(require("lodash/isPlainObject"));
|
|
3150
|
+
var import_isPlainObject2 = __toESM(require("lodash/isPlainObject"), 1);
|
|
2517
3151
|
function toErrorList(errorSchema, fieldPath = []) {
|
|
2518
3152
|
if (!errorSchema) {
|
|
2519
3153
|
return [];
|
|
@@ -2543,7 +3177,7 @@ function toErrorList(errorSchema, fieldPath = []) {
|
|
|
2543
3177
|
}
|
|
2544
3178
|
|
|
2545
3179
|
// src/toErrorSchema.ts
|
|
2546
|
-
var import_toPath = __toESM(require("lodash/toPath"));
|
|
3180
|
+
var import_toPath = __toESM(require("lodash/toPath"), 1);
|
|
2547
3181
|
function toErrorSchema(errors) {
|
|
2548
3182
|
const builder = new ErrorSchemaBuilder();
|
|
2549
3183
|
if (errors.length) {
|
|
@@ -2562,7 +3196,7 @@ function toErrorSchema(errors) {
|
|
|
2562
3196
|
}
|
|
2563
3197
|
|
|
2564
3198
|
// src/unwrapErrorHandler.ts
|
|
2565
|
-
var import_isPlainObject3 = __toESM(require("lodash/isPlainObject"));
|
|
3199
|
+
var import_isPlainObject3 = __toESM(require("lodash/isPlainObject"), 1);
|
|
2566
3200
|
function unwrapErrorHandler(errorHandler) {
|
|
2567
3201
|
return Object.keys(errorHandler).reduce((acc, key) => {
|
|
2568
3202
|
if (key === "addError") {
|
|
@@ -2597,7 +3231,7 @@ function utcToLocal(jsonDate) {
|
|
|
2597
3231
|
}
|
|
2598
3232
|
|
|
2599
3233
|
// src/validationDataMerge.ts
|
|
2600
|
-
var
|
|
3234
|
+
var import_isEmpty4 = __toESM(require("lodash/isEmpty"), 1);
|
|
2601
3235
|
function validationDataMerge(validationData, additionalErrorSchema) {
|
|
2602
3236
|
if (!additionalErrorSchema) {
|
|
2603
3237
|
return validationData;
|
|
@@ -2605,7 +3239,7 @@ function validationDataMerge(validationData, additionalErrorSchema) {
|
|
|
2605
3239
|
const { errors: oldErrors, errorSchema: oldErrorSchema } = validationData;
|
|
2606
3240
|
let errors = toErrorList(additionalErrorSchema);
|
|
2607
3241
|
let errorSchema = additionalErrorSchema;
|
|
2608
|
-
if (!(0,
|
|
3242
|
+
if (!(0, import_isEmpty4.default)(oldErrorSchema)) {
|
|
2609
3243
|
errorSchema = mergeObjects(oldErrorSchema, additionalErrorSchema, true);
|
|
2610
3244
|
errors = [...oldErrors].concat(errors);
|
|
2611
3245
|
}
|
|
@@ -2613,7 +3247,7 @@ function validationDataMerge(validationData, additionalErrorSchema) {
|
|
|
2613
3247
|
}
|
|
2614
3248
|
|
|
2615
3249
|
// src/withIdRefPrefix.ts
|
|
2616
|
-
var
|
|
3250
|
+
var import_isObject10 = __toESM(require("lodash/isObject"), 1);
|
|
2617
3251
|
function withIdRefPrefixObject(node) {
|
|
2618
3252
|
for (const key in node) {
|
|
2619
3253
|
const realObj = node;
|
|
@@ -2636,16 +3270,40 @@ function withIdRefPrefix(schemaNode) {
|
|
|
2636
3270
|
if (Array.isArray(schemaNode)) {
|
|
2637
3271
|
return withIdRefPrefixArray([...schemaNode]);
|
|
2638
3272
|
}
|
|
2639
|
-
if ((0,
|
|
3273
|
+
if ((0, import_isObject10.default)(schemaNode)) {
|
|
2640
3274
|
return withIdRefPrefixObject({ ...schemaNode });
|
|
2641
3275
|
}
|
|
2642
3276
|
return schemaNode;
|
|
2643
3277
|
}
|
|
2644
3278
|
|
|
3279
|
+
// src/getChangedFields.ts
|
|
3280
|
+
var import_keys = __toESM(require("lodash/keys"), 1);
|
|
3281
|
+
var import_pickBy = __toESM(require("lodash/pickBy"), 1);
|
|
3282
|
+
var import_isPlainObject4 = __toESM(require("lodash/isPlainObject"), 1);
|
|
3283
|
+
var import_get19 = __toESM(require("lodash/get"), 1);
|
|
3284
|
+
var import_difference = __toESM(require("lodash/difference"), 1);
|
|
3285
|
+
function getChangedFields(a, b) {
|
|
3286
|
+
const aIsPlainObject = (0, import_isPlainObject4.default)(a);
|
|
3287
|
+
const bIsPlainObject = (0, import_isPlainObject4.default)(b);
|
|
3288
|
+
if (a === b || !aIsPlainObject && !bIsPlainObject) {
|
|
3289
|
+
return [];
|
|
3290
|
+
}
|
|
3291
|
+
if (aIsPlainObject && !bIsPlainObject) {
|
|
3292
|
+
return (0, import_keys.default)(a);
|
|
3293
|
+
} else if (!aIsPlainObject && bIsPlainObject) {
|
|
3294
|
+
return (0, import_keys.default)(b);
|
|
3295
|
+
} else {
|
|
3296
|
+
const unequalFields = (0, import_keys.default)((0, import_pickBy.default)(a, (value, key) => !deepEquals(value, (0, import_get19.default)(b, key))));
|
|
3297
|
+
const diffFields = (0, import_difference.default)((0, import_keys.default)(b), (0, import_keys.default)(a));
|
|
3298
|
+
return [...unequalFields, ...diffFields];
|
|
3299
|
+
}
|
|
3300
|
+
}
|
|
3301
|
+
|
|
2645
3302
|
// src/enums.ts
|
|
2646
3303
|
var TranslatableString = /* @__PURE__ */ ((TranslatableString2) => {
|
|
2647
3304
|
TranslatableString2["ArrayItemTitle"] = "Item";
|
|
2648
3305
|
TranslatableString2["MissingItems"] = "Missing items definition";
|
|
3306
|
+
TranslatableString2["EmptyArray"] = "No items yet. Use the button below to add some.";
|
|
2649
3307
|
TranslatableString2["YesLabel"] = "Yes";
|
|
2650
3308
|
TranslatableString2["NoLabel"] = "No";
|
|
2651
3309
|
TranslatableString2["CloseLabel"] = "Close";
|
|
@@ -2677,12 +3335,10 @@ var TranslatableString = /* @__PURE__ */ ((TranslatableString2) => {
|
|
|
2677
3335
|
})(TranslatableString || {});
|
|
2678
3336
|
|
|
2679
3337
|
// src/parser/schemaParser.ts
|
|
2680
|
-
var import_forEach = __toESM(require("lodash/forEach"));
|
|
2681
|
-
var import_isEqual7 = __toESM(require("lodash/isEqual"));
|
|
3338
|
+
var import_forEach = __toESM(require("lodash/forEach"), 1);
|
|
2682
3339
|
|
|
2683
3340
|
// src/parser/ParserValidator.ts
|
|
2684
|
-
var
|
|
2685
|
-
var import_isEqual6 = __toESM(require("lodash/isEqual"));
|
|
3341
|
+
var import_get20 = __toESM(require("lodash/get"), 1);
|
|
2686
3342
|
var ParserValidator = class {
|
|
2687
3343
|
/** Construct the ParserValidator for the given `rootSchema`. This `rootSchema` will be stashed in the `schemaMap`
|
|
2688
3344
|
* first.
|
|
@@ -2708,12 +3364,12 @@ var ParserValidator = class {
|
|
|
2708
3364
|
* @param hash - The hash value at which to map the schema
|
|
2709
3365
|
*/
|
|
2710
3366
|
addSchema(schema, hash) {
|
|
2711
|
-
const key = (0,
|
|
3367
|
+
const key = (0, import_get20.default)(schema, ID_KEY, hash);
|
|
2712
3368
|
const identifiedSchema = { ...schema, [ID_KEY]: key };
|
|
2713
3369
|
const existing = this.schemaMap[key];
|
|
2714
3370
|
if (!existing) {
|
|
2715
3371
|
this.schemaMap[key] = identifiedSchema;
|
|
2716
|
-
} else if (!(
|
|
3372
|
+
} else if (!deepEquals(existing, identifiedSchema)) {
|
|
2717
3373
|
console.error("existing schema:", JSON.stringify(existing, null, 2));
|
|
2718
3374
|
console.error("new schema:", JSON.stringify(identifiedSchema, null, 2));
|
|
2719
3375
|
throw new Error(
|
|
@@ -2735,7 +3391,7 @@ var ParserValidator = class {
|
|
|
2735
3391
|
* @throws - Error when the given `rootSchema` differs from the root schema provided during construction
|
|
2736
3392
|
*/
|
|
2737
3393
|
isValid(schema, _formData, rootSchema) {
|
|
2738
|
-
if (!(
|
|
3394
|
+
if (!deepEquals(rootSchema, this.rootSchema)) {
|
|
2739
3395
|
throw new Error("Unexpectedly calling isValid() with a rootSchema that differs from the construction rootSchema");
|
|
2740
3396
|
}
|
|
2741
3397
|
this.addSchema(schema, hashForSchema(schema));
|
|
@@ -2775,7 +3431,7 @@ var ParserValidator = class {
|
|
|
2775
3431
|
function parseSchema(validator, recurseList, rootSchema, schema) {
|
|
2776
3432
|
const schemas = retrieveSchemaInternal(validator, schema, rootSchema, void 0, true);
|
|
2777
3433
|
schemas.forEach((schema2) => {
|
|
2778
|
-
const sameSchemaIndex = recurseList.findIndex((item) => (
|
|
3434
|
+
const sameSchemaIndex = recurseList.findIndex((item) => deepEquals(item, schema2));
|
|
2779
3435
|
if (sameSchemaIndex === -1) {
|
|
2780
3436
|
recurseList.push(schema2);
|
|
2781
3437
|
const allOptions = resolveAnyOrOneOfSchemas(validator, schema2, rootSchema, true);
|