@rjsf/utils 6.0.0-alpha.0 → 6.0.0-beta.10
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 +1347 -642
- package/dist/index.js.map +4 -4
- package/dist/utils.esm.js +1324 -619
- package/dist/utils.esm.js.map +4 -4
- package/dist/utils.umd.js +1266 -590
- 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 +2 -2
- 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 +15 -3
- package/lib/constants.js +15 -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 +5 -3
- package/lib/findSchemaDefinition.js +54 -11
- 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 +316 -167
- 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 +30 -12
- package/lib/schema/retrieveSchema.js +153 -70
- 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 +172 -142
- 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 +37 -26
- package/src/ErrorSchemaBuilder.ts +15 -8
- package/src/canExpand.ts +2 -2
- package/src/constIsAjvDataReference.ts +17 -0
- package/src/constants.ts +17 -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 +55 -10
- 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 +461 -193
- 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 +268 -78
- 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 +278 -184
- 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,21 +38,27 @@ __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,
|
|
49
|
+
JSON_SCHEMA_DRAFT_2020_12: () => JSON_SCHEMA_DRAFT_2020_12,
|
|
47
50
|
JUNK_OPTION_ID: () => JUNK_OPTION_ID,
|
|
51
|
+
LOOKUP_MAP_NAME: () => LOOKUP_MAP_NAME,
|
|
48
52
|
NAME_KEY: () => NAME_KEY,
|
|
49
53
|
ONE_OF_KEY: () => ONE_OF_KEY,
|
|
54
|
+
PATTERN_PROPERTIES_KEY: () => PATTERN_PROPERTIES_KEY,
|
|
50
55
|
PROPERTIES_KEY: () => PROPERTIES_KEY,
|
|
56
|
+
READONLY_KEY: () => READONLY_KEY,
|
|
51
57
|
REF_KEY: () => REF_KEY,
|
|
52
58
|
REQUIRED_KEY: () => REQUIRED_KEY,
|
|
53
59
|
RJSF_ADDITIONAL_PROPERTIES_FLAG: () => RJSF_ADDITIONAL_PROPERTIES_FLAG,
|
|
54
|
-
RJSF_ADDITONAL_PROPERTIES_FLAG: () => RJSF_ADDITONAL_PROPERTIES_FLAG,
|
|
55
60
|
ROOT_SCHEMA_PREFIX: () => ROOT_SCHEMA_PREFIX,
|
|
61
|
+
SCHEMA_KEY: () => SCHEMA_KEY,
|
|
56
62
|
SUBMIT_BTN_OPTIONS_KEY: () => SUBMIT_BTN_OPTIONS_KEY,
|
|
57
63
|
TranslatableString: () => TranslatableString,
|
|
58
64
|
UI_FIELD_KEY: () => UI_FIELD_KEY,
|
|
@@ -62,6 +68,7 @@ __export(src_exports, {
|
|
|
62
68
|
allowAdditionalItems: () => allowAdditionalItems,
|
|
63
69
|
ariaDescribedByIds: () => ariaDescribedByIds,
|
|
64
70
|
asNumber: () => asNumber,
|
|
71
|
+
buttonId: () => buttonId,
|
|
65
72
|
canExpand: () => canExpand,
|
|
66
73
|
createErrorHandler: () => createErrorHandler,
|
|
67
74
|
createSchemaUtils: () => createSchemaUtils,
|
|
@@ -77,24 +84,30 @@ __export(src_exports, {
|
|
|
77
84
|
enumOptionsValueForIndex: () => enumOptionsValueForIndex,
|
|
78
85
|
errorId: () => errorId,
|
|
79
86
|
examplesId: () => examplesId,
|
|
87
|
+
findFieldInSchema: () => findFieldInSchema,
|
|
80
88
|
findSchemaDefinition: () => findSchemaDefinition,
|
|
89
|
+
findSelectedOptionInXxxOf: () => findSelectedOptionInXxxOf,
|
|
90
|
+
getChangedFields: () => getChangedFields,
|
|
81
91
|
getClosestMatchingOption: () => getClosestMatchingOption,
|
|
82
92
|
getDateElementProps: () => getDateElementProps,
|
|
83
93
|
getDefaultFormState: () => getDefaultFormState,
|
|
84
94
|
getDiscriminatorFieldFromSchema: () => getDiscriminatorFieldFromSchema,
|
|
85
95
|
getDisplayLabel: () => getDisplayLabel,
|
|
86
96
|
getFirstMatchingOption: () => getFirstMatchingOption,
|
|
97
|
+
getFromSchema: () => getFromSchema,
|
|
87
98
|
getInputProps: () => getInputProps,
|
|
88
|
-
getMatchingOption: () => getMatchingOption,
|
|
89
99
|
getOptionMatchingSimpleDiscriminator: () => getOptionMatchingSimpleDiscriminator,
|
|
90
100
|
getSchemaType: () => getSchemaType,
|
|
91
101
|
getSubmitButtonOptions: () => getSubmitButtonOptions,
|
|
92
102
|
getTemplate: () => getTemplate,
|
|
103
|
+
getTestIds: () => getTestIds,
|
|
93
104
|
getUiOptions: () => getUiOptions,
|
|
94
105
|
getWidget: () => getWidget,
|
|
95
106
|
guessType: () => guessType,
|
|
96
107
|
hasWidget: () => hasWidget,
|
|
97
108
|
hashForSchema: () => hashForSchema,
|
|
109
|
+
hashObject: () => hashObject,
|
|
110
|
+
hashString: () => hashString,
|
|
98
111
|
helpId: () => helpId,
|
|
99
112
|
isConstant: () => isConstant,
|
|
100
113
|
isCustomWidget: () => isCustomWidget,
|
|
@@ -105,10 +118,10 @@ __export(src_exports, {
|
|
|
105
118
|
isSelect: () => isSelect,
|
|
106
119
|
labelValue: () => labelValue,
|
|
107
120
|
localToUTC: () => localToUTC,
|
|
121
|
+
lookupFromFormContext: () => lookupFromFormContext,
|
|
108
122
|
mergeDefaultsWithFormData: () => mergeDefaultsWithFormData,
|
|
109
123
|
mergeObjects: () => mergeObjects,
|
|
110
124
|
mergeSchemas: () => mergeSchemas,
|
|
111
|
-
mergeValidationData: () => mergeValidationData,
|
|
112
125
|
optionId: () => optionId,
|
|
113
126
|
optionsList: () => optionsList,
|
|
114
127
|
orderProperties: () => orderProperties,
|
|
@@ -121,6 +134,7 @@ __export(src_exports, {
|
|
|
121
134
|
schemaParser: () => schemaParser,
|
|
122
135
|
schemaRequiresTrueValue: () => schemaRequiresTrueValue,
|
|
123
136
|
shouldRender: () => shouldRender,
|
|
137
|
+
sortedJSONStringify: () => sortedJSONStringify,
|
|
124
138
|
titleId: () => titleId,
|
|
125
139
|
toConstant: () => toConstant,
|
|
126
140
|
toDateString: () => toDateString,
|
|
@@ -133,17 +147,20 @@ __export(src_exports, {
|
|
|
133
147
|
validationDataMerge: () => validationDataMerge,
|
|
134
148
|
withIdRefPrefix: () => withIdRefPrefix
|
|
135
149
|
});
|
|
136
|
-
module.exports = __toCommonJS(
|
|
150
|
+
module.exports = __toCommonJS(index_exports);
|
|
137
151
|
|
|
138
152
|
// src/isObject.ts
|
|
139
153
|
function isObject(thing) {
|
|
140
|
-
if (typeof
|
|
154
|
+
if (typeof thing !== "object" || thing === null) {
|
|
141
155
|
return false;
|
|
142
156
|
}
|
|
143
|
-
if (typeof
|
|
157
|
+
if (typeof thing.lastModified === "number" && typeof File !== "undefined" && thing instanceof File) {
|
|
144
158
|
return false;
|
|
145
159
|
}
|
|
146
|
-
|
|
160
|
+
if (typeof thing.getMonth === "function" && typeof Date !== "undefined" && thing instanceof Date) {
|
|
161
|
+
return false;
|
|
162
|
+
}
|
|
163
|
+
return !Array.isArray(thing);
|
|
147
164
|
}
|
|
148
165
|
|
|
149
166
|
// src/allowAdditionalItems.ts
|
|
@@ -193,17 +210,23 @@ var ITEMS_KEY = "items";
|
|
|
193
210
|
var JUNK_OPTION_ID = "_$junk_option_schema_id$_";
|
|
194
211
|
var NAME_KEY = "$name";
|
|
195
212
|
var ONE_OF_KEY = "oneOf";
|
|
213
|
+
var PATTERN_PROPERTIES_KEY = "patternProperties";
|
|
196
214
|
var PROPERTIES_KEY = "properties";
|
|
215
|
+
var READONLY_KEY = "readonly";
|
|
197
216
|
var REQUIRED_KEY = "required";
|
|
198
217
|
var SUBMIT_BTN_OPTIONS_KEY = "submitButtonOptions";
|
|
199
218
|
var REF_KEY = "$ref";
|
|
200
|
-
var
|
|
219
|
+
var SCHEMA_KEY = "$schema";
|
|
220
|
+
var DISCRIMINATOR_PATH = ["discriminator", "propertyName"];
|
|
221
|
+
var FORM_CONTEXT_NAME = "formContext";
|
|
222
|
+
var LOOKUP_MAP_NAME = "layoutGridLookupMap";
|
|
201
223
|
var RJSF_ADDITIONAL_PROPERTIES_FLAG = "__rjsf_additionalProperties";
|
|
202
224
|
var ROOT_SCHEMA_PREFIX = "__rjsf_rootSchema";
|
|
203
225
|
var UI_FIELD_KEY = "ui:field";
|
|
204
226
|
var UI_WIDGET_KEY = "ui:widget";
|
|
205
227
|
var UI_OPTIONS_KEY = "ui:options";
|
|
206
228
|
var UI_GLOBAL_OPTIONS_KEY = "ui:globalOptions";
|
|
229
|
+
var JSON_SCHEMA_DRAFT_2020_12 = "https://json-schema.org/draft/2020-12/schema";
|
|
207
230
|
|
|
208
231
|
// src/getUiOptions.ts
|
|
209
232
|
function getUiOptions(uiSchema = {}, globalOptions = {}) {
|
|
@@ -225,7 +248,7 @@ function getUiOptions(uiSchema = {}, globalOptions = {}) {
|
|
|
225
248
|
|
|
226
249
|
// src/canExpand.ts
|
|
227
250
|
function canExpand(schema, uiSchema = {}, formData) {
|
|
228
|
-
if (!schema.additionalProperties) {
|
|
251
|
+
if (!(schema.additionalProperties || schema.patternProperties)) {
|
|
229
252
|
return false;
|
|
230
253
|
}
|
|
231
254
|
const { expandable = true } = getUiOptions(uiSchema);
|
|
@@ -239,7 +262,7 @@ function canExpand(schema, uiSchema = {}, formData) {
|
|
|
239
262
|
}
|
|
240
263
|
|
|
241
264
|
// src/createErrorHandler.ts
|
|
242
|
-
var import_isPlainObject = __toESM(require("lodash/isPlainObject"));
|
|
265
|
+
var import_isPlainObject = __toESM(require("lodash/isPlainObject"), 1);
|
|
243
266
|
function createErrorHandler(formData) {
|
|
244
267
|
const handler = {
|
|
245
268
|
// We store the list of errors for this node in a property named __errors
|
|
@@ -265,7 +288,7 @@ function createErrorHandler(formData) {
|
|
|
265
288
|
}
|
|
266
289
|
|
|
267
290
|
// src/deepEquals.ts
|
|
268
|
-
var import_isEqualWith = __toESM(require("lodash/isEqualWith"));
|
|
291
|
+
var import_isEqualWith = __toESM(require("lodash/isEqualWith"), 1);
|
|
269
292
|
function deepEquals(a, b) {
|
|
270
293
|
return (0, import_isEqualWith.default)(a, b, (obj, other) => {
|
|
271
294
|
if (typeof obj === "function" && typeof other === "function") {
|
|
@@ -275,27 +298,74 @@ function deepEquals(a, b) {
|
|
|
275
298
|
});
|
|
276
299
|
}
|
|
277
300
|
|
|
278
|
-
// src/schema/
|
|
279
|
-
var
|
|
280
|
-
var
|
|
301
|
+
// src/schema/findFieldInSchema.ts
|
|
302
|
+
var import_get8 = __toESM(require("lodash/get"), 1);
|
|
303
|
+
var import_has3 = __toESM(require("lodash/has"), 1);
|
|
304
|
+
|
|
305
|
+
// src/schema/findSelectedOptionInXxxOf.ts
|
|
306
|
+
var import_get6 = __toESM(require("lodash/get"), 1);
|
|
307
|
+
var import_isEqual = __toESM(require("lodash/isEqual"), 1);
|
|
308
|
+
|
|
309
|
+
// src/schema/retrieveSchema.ts
|
|
310
|
+
var import_get5 = __toESM(require("lodash/get"), 1);
|
|
311
|
+
var import_set = __toESM(require("lodash/set"), 1);
|
|
312
|
+
var import_times = __toESM(require("lodash/times"), 1);
|
|
313
|
+
var import_transform = __toESM(require("lodash/transform"), 1);
|
|
314
|
+
var import_merge = __toESM(require("lodash/merge"), 1);
|
|
315
|
+
var import_flattenDeep = __toESM(require("lodash/flattenDeep"), 1);
|
|
316
|
+
var import_uniq = __toESM(require("lodash/uniq"), 1);
|
|
317
|
+
var import_json_schema_merge_allof = __toESM(require("json-schema-merge-allof"), 1);
|
|
281
318
|
|
|
282
319
|
// src/findSchemaDefinition.ts
|
|
283
|
-
var import_jsonpointer = __toESM(require("jsonpointer"));
|
|
284
|
-
var import_omit = __toESM(require("lodash/omit"));
|
|
320
|
+
var import_jsonpointer = __toESM(require("jsonpointer"), 1);
|
|
321
|
+
var import_omit = __toESM(require("lodash/omit"), 1);
|
|
322
|
+
var import_isObject3 = __toESM(require("lodash/isObject"), 1);
|
|
323
|
+
var import_isEmpty = __toESM(require("lodash/isEmpty"), 1);
|
|
324
|
+
var import_fast_uri = __toESM(require("fast-uri"), 1);
|
|
325
|
+
var import_get = __toESM(require("lodash/get"), 1);
|
|
326
|
+
function findEmbeddedSchemaRecursive(schema, ref) {
|
|
327
|
+
if (ID_KEY in schema && import_fast_uri.default.equal(schema[ID_KEY], ref)) {
|
|
328
|
+
return schema;
|
|
329
|
+
}
|
|
330
|
+
for (const subSchema of Object.values(schema)) {
|
|
331
|
+
if ((0, import_isObject3.default)(subSchema)) {
|
|
332
|
+
const result = findEmbeddedSchemaRecursive(subSchema, ref);
|
|
333
|
+
if (result !== void 0) {
|
|
334
|
+
return result;
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
return void 0;
|
|
339
|
+
}
|
|
285
340
|
function splitKeyElementFromObject(key, object) {
|
|
286
341
|
const value = object[key];
|
|
287
342
|
const remaining = (0, import_omit.default)(object, [key]);
|
|
288
343
|
return [remaining, value];
|
|
289
344
|
}
|
|
290
|
-
function findSchemaDefinitionRecursive($ref, rootSchema = {}, recurseList = []) {
|
|
345
|
+
function findSchemaDefinitionRecursive($ref, rootSchema = {}, recurseList = [], baseURI = (0, import_get.default)(rootSchema, [ID_KEY])) {
|
|
291
346
|
const ref = $ref || "";
|
|
292
|
-
let
|
|
347
|
+
let current = void 0;
|
|
293
348
|
if (ref.startsWith("#")) {
|
|
294
|
-
decodedRef = decodeURIComponent(ref.substring(1));
|
|
295
|
-
|
|
296
|
-
|
|
349
|
+
const decodedRef = decodeURIComponent(ref.substring(1));
|
|
350
|
+
if (baseURI === void 0 || ID_KEY in rootSchema && rootSchema[ID_KEY] === baseURI) {
|
|
351
|
+
current = import_jsonpointer.default.get(rootSchema, decodedRef);
|
|
352
|
+
} else if (rootSchema[SCHEMA_KEY] === JSON_SCHEMA_DRAFT_2020_12) {
|
|
353
|
+
current = findEmbeddedSchemaRecursive(rootSchema, baseURI.replace(/\/$/, ""));
|
|
354
|
+
if (current !== void 0) {
|
|
355
|
+
current = import_jsonpointer.default.get(current, decodedRef);
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
} else if (rootSchema[SCHEMA_KEY] === JSON_SCHEMA_DRAFT_2020_12) {
|
|
359
|
+
const resolvedRef = baseURI ? import_fast_uri.default.resolve(baseURI, ref) : ref;
|
|
360
|
+
const [refId, ...refAnchor] = resolvedRef.replace(/#\/?$/, "").split("#");
|
|
361
|
+
current = findEmbeddedSchemaRecursive(rootSchema, refId.replace(/\/$/, ""));
|
|
362
|
+
if (current !== void 0) {
|
|
363
|
+
baseURI = current[ID_KEY];
|
|
364
|
+
if (!(0, import_isEmpty.default)(refAnchor)) {
|
|
365
|
+
current = import_jsonpointer.default.get(current, decodeURIComponent(refAnchor.join("#")));
|
|
366
|
+
}
|
|
367
|
+
}
|
|
297
368
|
}
|
|
298
|
-
const current = import_jsonpointer.default.get(rootSchema, decodedRef);
|
|
299
369
|
if (current === void 0) {
|
|
300
370
|
throw new Error(`Could not find a definition for ${$ref}.`);
|
|
301
371
|
}
|
|
@@ -310,7 +380,7 @@ function findSchemaDefinitionRecursive($ref, rootSchema = {}, recurseList = [])
|
|
|
310
380
|
throw new Error(`Definition for ${firstRef} contains a circular reference through ${circularPath}`);
|
|
311
381
|
}
|
|
312
382
|
const [remaining, theRef] = splitKeyElementFromObject(REF_KEY, current);
|
|
313
|
-
const subSchema = findSchemaDefinitionRecursive(theRef, rootSchema, [...recurseList, ref]);
|
|
383
|
+
const subSchema = findSchemaDefinitionRecursive(theRef, rootSchema, [...recurseList, ref], baseURI);
|
|
314
384
|
if (Object.keys(remaining).length > 0) {
|
|
315
385
|
return { ...remaining, ...subSchema };
|
|
316
386
|
}
|
|
@@ -318,119 +388,17 @@ function findSchemaDefinitionRecursive($ref, rootSchema = {}, recurseList = [])
|
|
|
318
388
|
}
|
|
319
389
|
return current;
|
|
320
390
|
}
|
|
321
|
-
function findSchemaDefinition($ref, rootSchema = {}) {
|
|
391
|
+
function findSchemaDefinition($ref, rootSchema = {}, baseURI = (0, import_get.default)(rootSchema, [ID_KEY])) {
|
|
322
392
|
const recurseList = [];
|
|
323
|
-
return findSchemaDefinitionRecursive($ref, rootSchema, recurseList);
|
|
324
|
-
}
|
|
325
|
-
|
|
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;
|
|
393
|
+
return findSchemaDefinitionRecursive($ref, rootSchema, recurseList, baseURI);
|
|
410
394
|
}
|
|
411
395
|
|
|
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
396
|
// src/getDiscriminatorFieldFromSchema.ts
|
|
429
|
-
var
|
|
430
|
-
var import_isString = __toESM(require("lodash/isString"));
|
|
397
|
+
var import_get2 = __toESM(require("lodash/get"), 1);
|
|
398
|
+
var import_isString = __toESM(require("lodash/isString"), 1);
|
|
431
399
|
function getDiscriminatorFieldFromSchema(schema) {
|
|
432
400
|
let discriminator;
|
|
433
|
-
const maybeString = (0,
|
|
401
|
+
const maybeString = (0, import_get2.default)(schema, DISCRIMINATOR_PATH);
|
|
434
402
|
if ((0, import_isString.default)(maybeString)) {
|
|
435
403
|
discriminator = maybeString;
|
|
436
404
|
} else if (maybeString !== void 0) {
|
|
@@ -463,7 +431,7 @@ function guessType(value) {
|
|
|
463
431
|
}
|
|
464
432
|
|
|
465
433
|
// src/mergeSchemas.ts
|
|
466
|
-
var import_union = __toESM(require("lodash/union"));
|
|
434
|
+
var import_union = __toESM(require("lodash/union"), 1);
|
|
467
435
|
|
|
468
436
|
// src/getSchemaType.ts
|
|
469
437
|
function getSchemaType(schema) {
|
|
@@ -474,7 +442,7 @@ function getSchemaType(schema) {
|
|
|
474
442
|
if (!type && schema.enum) {
|
|
475
443
|
return "string";
|
|
476
444
|
}
|
|
477
|
-
if (!type && (schema.properties || schema.additionalProperties)) {
|
|
445
|
+
if (!type && (schema.properties || schema.additionalProperties || schema.patternProperties)) {
|
|
478
446
|
return "object";
|
|
479
447
|
}
|
|
480
448
|
if (Array.isArray(type)) {
|
|
@@ -503,11 +471,97 @@ function mergeSchemas(obj1, obj2) {
|
|
|
503
471
|
}, acc);
|
|
504
472
|
}
|
|
505
473
|
|
|
474
|
+
// src/schema/getFirstMatchingOption.ts
|
|
475
|
+
var import_get4 = __toESM(require("lodash/get"), 1);
|
|
476
|
+
var import_has = __toESM(require("lodash/has"), 1);
|
|
477
|
+
var import_isNumber = __toESM(require("lodash/isNumber"), 1);
|
|
478
|
+
|
|
479
|
+
// src/getOptionMatchingSimpleDiscriminator.ts
|
|
480
|
+
var import_get3 = __toESM(require("lodash/get"), 1);
|
|
481
|
+
function getOptionMatchingSimpleDiscriminator(formData, options, discriminatorField) {
|
|
482
|
+
if (formData && discriminatorField) {
|
|
483
|
+
const value = (0, import_get3.default)(formData, discriminatorField);
|
|
484
|
+
if (value === void 0) {
|
|
485
|
+
return;
|
|
486
|
+
}
|
|
487
|
+
for (let i = 0; i < options.length; i++) {
|
|
488
|
+
const option = options[i];
|
|
489
|
+
const discriminator = (0, import_get3.default)(option, [PROPERTIES_KEY, discriminatorField], {});
|
|
490
|
+
if (discriminator.type === "object" || discriminator.type === "array") {
|
|
491
|
+
continue;
|
|
492
|
+
}
|
|
493
|
+
if (discriminator.const === value) {
|
|
494
|
+
return i;
|
|
495
|
+
}
|
|
496
|
+
if (discriminator.enum?.includes(value)) {
|
|
497
|
+
return i;
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
return;
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
// src/schema/getFirstMatchingOption.ts
|
|
505
|
+
function getFirstMatchingOption(validator, formData, options, rootSchema, discriminatorField) {
|
|
506
|
+
if (formData === void 0) {
|
|
507
|
+
return 0;
|
|
508
|
+
}
|
|
509
|
+
const simpleDiscriminatorMatch = getOptionMatchingSimpleDiscriminator(formData, options, discriminatorField);
|
|
510
|
+
if ((0, import_isNumber.default)(simpleDiscriminatorMatch)) {
|
|
511
|
+
return simpleDiscriminatorMatch;
|
|
512
|
+
}
|
|
513
|
+
for (let i = 0; i < options.length; i++) {
|
|
514
|
+
const option = options[i];
|
|
515
|
+
if (discriminatorField && (0, import_has.default)(option, [PROPERTIES_KEY, discriminatorField])) {
|
|
516
|
+
const value = (0, import_get4.default)(formData, discriminatorField);
|
|
517
|
+
const discriminator = (0, import_get4.default)(option, [PROPERTIES_KEY, discriminatorField], {});
|
|
518
|
+
if (validator.isValid(discriminator, value, rootSchema)) {
|
|
519
|
+
return i;
|
|
520
|
+
}
|
|
521
|
+
} else if (option[PROPERTIES_KEY]) {
|
|
522
|
+
const requiresAnyOf = {
|
|
523
|
+
anyOf: Object.keys(option[PROPERTIES_KEY]).map((key) => ({
|
|
524
|
+
required: [key]
|
|
525
|
+
}))
|
|
526
|
+
};
|
|
527
|
+
let augmentedSchema;
|
|
528
|
+
if (option.anyOf) {
|
|
529
|
+
const { ...shallowClone } = option;
|
|
530
|
+
if (!shallowClone.allOf) {
|
|
531
|
+
shallowClone.allOf = [];
|
|
532
|
+
} else {
|
|
533
|
+
shallowClone.allOf = shallowClone.allOf.slice();
|
|
534
|
+
}
|
|
535
|
+
shallowClone.allOf.push(requiresAnyOf);
|
|
536
|
+
augmentedSchema = shallowClone;
|
|
537
|
+
} else {
|
|
538
|
+
augmentedSchema = Object.assign({}, option, requiresAnyOf);
|
|
539
|
+
}
|
|
540
|
+
delete augmentedSchema.required;
|
|
541
|
+
if (validator.isValid(augmentedSchema, formData, rootSchema)) {
|
|
542
|
+
return i;
|
|
543
|
+
}
|
|
544
|
+
} else if (validator.isValid(option, formData, rootSchema)) {
|
|
545
|
+
return i;
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
return 0;
|
|
549
|
+
}
|
|
550
|
+
|
|
506
551
|
// src/schema/retrieveSchema.ts
|
|
507
|
-
|
|
508
|
-
|
|
552
|
+
var import_isEmpty2 = __toESM(require("lodash/isEmpty"), 1);
|
|
553
|
+
function retrieveSchema(validator, schema, rootSchema = {}, rawFormData, experimental_customMergeAllOf) {
|
|
554
|
+
return retrieveSchemaInternal(
|
|
555
|
+
validator,
|
|
556
|
+
schema,
|
|
557
|
+
rootSchema,
|
|
558
|
+
rawFormData,
|
|
559
|
+
void 0,
|
|
560
|
+
void 0,
|
|
561
|
+
experimental_customMergeAllOf
|
|
562
|
+
)[0];
|
|
509
563
|
}
|
|
510
|
-
function resolveCondition(validator, schema, rootSchema, expandAllBranches, recurseList, formData) {
|
|
564
|
+
function resolveCondition(validator, schema, rootSchema, expandAllBranches, recurseList, formData, experimental_customMergeAllOf) {
|
|
511
565
|
const { if: expression, then, else: otherwise, ...resolvedSchemaLessConditional } = schema;
|
|
512
566
|
const conditionValue = validator.isValid(expression, formData || {}, rootSchema);
|
|
513
567
|
let resolvedSchemas = [resolvedSchemaLessConditional];
|
|
@@ -515,12 +569,28 @@ function resolveCondition(validator, schema, rootSchema, expandAllBranches, recu
|
|
|
515
569
|
if (expandAllBranches) {
|
|
516
570
|
if (then && typeof then !== "boolean") {
|
|
517
571
|
schemas = schemas.concat(
|
|
518
|
-
retrieveSchemaInternal(
|
|
572
|
+
retrieveSchemaInternal(
|
|
573
|
+
validator,
|
|
574
|
+
then,
|
|
575
|
+
rootSchema,
|
|
576
|
+
formData,
|
|
577
|
+
expandAllBranches,
|
|
578
|
+
recurseList,
|
|
579
|
+
experimental_customMergeAllOf
|
|
580
|
+
)
|
|
519
581
|
);
|
|
520
582
|
}
|
|
521
583
|
if (otherwise && typeof otherwise !== "boolean") {
|
|
522
584
|
schemas = schemas.concat(
|
|
523
|
-
retrieveSchemaInternal(
|
|
585
|
+
retrieveSchemaInternal(
|
|
586
|
+
validator,
|
|
587
|
+
otherwise,
|
|
588
|
+
rootSchema,
|
|
589
|
+
formData,
|
|
590
|
+
expandAllBranches,
|
|
591
|
+
recurseList,
|
|
592
|
+
experimental_customMergeAllOf
|
|
593
|
+
)
|
|
524
594
|
);
|
|
525
595
|
}
|
|
526
596
|
} else {
|
|
@@ -533,7 +603,8 @@ function resolveCondition(validator, schema, rootSchema, expandAllBranches, recu
|
|
|
533
603
|
rootSchema,
|
|
534
604
|
formData,
|
|
535
605
|
expandAllBranches,
|
|
536
|
-
recurseList
|
|
606
|
+
recurseList,
|
|
607
|
+
experimental_customMergeAllOf
|
|
537
608
|
)
|
|
538
609
|
);
|
|
539
610
|
}
|
|
@@ -542,7 +613,15 @@ function resolveCondition(validator, schema, rootSchema, expandAllBranches, recu
|
|
|
542
613
|
resolvedSchemas = schemas.map((s) => mergeSchemas(resolvedSchemaLessConditional, s));
|
|
543
614
|
}
|
|
544
615
|
return resolvedSchemas.flatMap(
|
|
545
|
-
(s) => retrieveSchemaInternal(
|
|
616
|
+
(s) => retrieveSchemaInternal(
|
|
617
|
+
validator,
|
|
618
|
+
s,
|
|
619
|
+
rootSchema,
|
|
620
|
+
formData,
|
|
621
|
+
expandAllBranches,
|
|
622
|
+
recurseList,
|
|
623
|
+
experimental_customMergeAllOf
|
|
624
|
+
)
|
|
546
625
|
);
|
|
547
626
|
}
|
|
548
627
|
function getAllPermutationsOfXxxOf(listOfLists) {
|
|
@@ -559,7 +638,16 @@ function getAllPermutationsOfXxxOf(listOfLists) {
|
|
|
559
638
|
);
|
|
560
639
|
return allPermutations;
|
|
561
640
|
}
|
|
562
|
-
function
|
|
641
|
+
function getMatchingPatternProperties(schema, key) {
|
|
642
|
+
return Object.keys(schema.patternProperties).filter((pattern) => RegExp(pattern).test(key)).reduce(
|
|
643
|
+
(obj, pattern) => {
|
|
644
|
+
(0, import_set.default)(obj, [pattern], schema.patternProperties[pattern]);
|
|
645
|
+
return obj;
|
|
646
|
+
},
|
|
647
|
+
{}
|
|
648
|
+
);
|
|
649
|
+
}
|
|
650
|
+
function resolveSchema(validator, schema, rootSchema, expandAllBranches, recurseList, formData, experimental_customMergeAllOf) {
|
|
563
651
|
const updatedSchemas = resolveReference(
|
|
564
652
|
validator,
|
|
565
653
|
schema,
|
|
@@ -581,7 +669,15 @@ function resolveSchema(validator, schema, rootSchema, expandAllBranches, recurse
|
|
|
581
669
|
formData
|
|
582
670
|
);
|
|
583
671
|
return resolvedSchemas.flatMap((s) => {
|
|
584
|
-
return retrieveSchemaInternal(
|
|
672
|
+
return retrieveSchemaInternal(
|
|
673
|
+
validator,
|
|
674
|
+
s,
|
|
675
|
+
rootSchema,
|
|
676
|
+
formData,
|
|
677
|
+
expandAllBranches,
|
|
678
|
+
recurseList,
|
|
679
|
+
experimental_customMergeAllOf
|
|
680
|
+
);
|
|
585
681
|
});
|
|
586
682
|
}
|
|
587
683
|
if (ALL_OF_KEY in schema && Array.isArray(schema.allOf)) {
|
|
@@ -592,15 +688,19 @@ function resolveSchema(validator, schema, rootSchema, expandAllBranches, recurse
|
|
|
592
688
|
rootSchema,
|
|
593
689
|
formData,
|
|
594
690
|
expandAllBranches,
|
|
595
|
-
recurseList
|
|
691
|
+
recurseList,
|
|
692
|
+
experimental_customMergeAllOf
|
|
596
693
|
)
|
|
597
694
|
);
|
|
598
695
|
const allPermutations = getAllPermutationsOfXxxOf(allOfSchemaElements);
|
|
599
|
-
return allPermutations.map((permutation) => ({
|
|
696
|
+
return allPermutations.map((permutation) => ({
|
|
697
|
+
...schema,
|
|
698
|
+
allOf: permutation
|
|
699
|
+
}));
|
|
600
700
|
}
|
|
601
701
|
return [schema];
|
|
602
702
|
}
|
|
603
|
-
function resolveReference(validator, schema, rootSchema, expandAllBranches, recurseList, formData) {
|
|
703
|
+
function resolveReference(validator, schema, rootSchema, expandAllBranches, recurseList, formData, experimental_customMergeAllOf) {
|
|
604
704
|
const updatedSchema = resolveAllReferences(schema, rootSchema, recurseList);
|
|
605
705
|
if (updatedSchema !== schema) {
|
|
606
706
|
return retrieveSchemaInternal(
|
|
@@ -609,12 +709,13 @@ function resolveReference(validator, schema, rootSchema, expandAllBranches, recu
|
|
|
609
709
|
rootSchema,
|
|
610
710
|
formData,
|
|
611
711
|
expandAllBranches,
|
|
612
|
-
recurseList
|
|
712
|
+
recurseList,
|
|
713
|
+
experimental_customMergeAllOf
|
|
613
714
|
);
|
|
614
715
|
}
|
|
615
716
|
return [schema];
|
|
616
717
|
}
|
|
617
|
-
function resolveAllReferences(schema, rootSchema, recurseList) {
|
|
718
|
+
function resolveAllReferences(schema, rootSchema, recurseList, baseURI) {
|
|
618
719
|
if (!isObject(schema)) {
|
|
619
720
|
return schema;
|
|
620
721
|
}
|
|
@@ -625,8 +726,11 @@ function resolveAllReferences(schema, rootSchema, recurseList) {
|
|
|
625
726
|
return resolvedSchema;
|
|
626
727
|
}
|
|
627
728
|
recurseList.push($ref);
|
|
628
|
-
const refSchema = findSchemaDefinition($ref, rootSchema);
|
|
729
|
+
const refSchema = findSchemaDefinition($ref, rootSchema, baseURI);
|
|
629
730
|
resolvedSchema = { ...refSchema, ...localSchema };
|
|
731
|
+
if (ID_KEY in resolvedSchema) {
|
|
732
|
+
baseURI = resolvedSchema[ID_KEY];
|
|
733
|
+
}
|
|
630
734
|
}
|
|
631
735
|
if (PROPERTIES_KEY in resolvedSchema) {
|
|
632
736
|
const childrenLists = [];
|
|
@@ -634,7 +738,7 @@ function resolveAllReferences(schema, rootSchema, recurseList) {
|
|
|
634
738
|
resolvedSchema[PROPERTIES_KEY],
|
|
635
739
|
(result, value, key) => {
|
|
636
740
|
const childList = [...recurseList];
|
|
637
|
-
result[key] = resolveAllReferences(value, rootSchema, childList);
|
|
741
|
+
result[key] = resolveAllReferences(value, rootSchema, childList, baseURI);
|
|
638
742
|
childrenLists.push(childList);
|
|
639
743
|
},
|
|
640
744
|
{}
|
|
@@ -645,12 +749,12 @@ function resolveAllReferences(schema, rootSchema, recurseList) {
|
|
|
645
749
|
if (ITEMS_KEY in resolvedSchema && !Array.isArray(resolvedSchema.items) && typeof resolvedSchema.items !== "boolean") {
|
|
646
750
|
resolvedSchema = {
|
|
647
751
|
...resolvedSchema,
|
|
648
|
-
items: resolveAllReferences(resolvedSchema.items, rootSchema, recurseList)
|
|
752
|
+
items: resolveAllReferences(resolvedSchema.items, rootSchema, recurseList, baseURI)
|
|
649
753
|
};
|
|
650
754
|
}
|
|
651
|
-
return (
|
|
755
|
+
return deepEquals(schema, resolvedSchema) ? schema : resolvedSchema;
|
|
652
756
|
}
|
|
653
|
-
function stubExistingAdditionalProperties(validator, theSchema, rootSchema, aFormData) {
|
|
757
|
+
function stubExistingAdditionalProperties(validator, theSchema, rootSchema, aFormData, experimental_customMergeAllOf) {
|
|
654
758
|
const schema = {
|
|
655
759
|
...theSchema,
|
|
656
760
|
properties: { ...theSchema.properties }
|
|
@@ -660,34 +764,54 @@ function stubExistingAdditionalProperties(validator, theSchema, rootSchema, aFor
|
|
|
660
764
|
if (key in schema.properties) {
|
|
661
765
|
return;
|
|
662
766
|
}
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
if (
|
|
666
|
-
|
|
767
|
+
if (PATTERN_PROPERTIES_KEY in schema) {
|
|
768
|
+
const matchingProperties = getMatchingPatternProperties(schema, key);
|
|
769
|
+
if (!(0, import_isEmpty2.default)(matchingProperties)) {
|
|
770
|
+
schema.properties[key] = retrieveSchema(
|
|
667
771
|
validator,
|
|
668
|
-
{
|
|
772
|
+
{ allOf: Object.values(matchingProperties) },
|
|
669
773
|
rootSchema,
|
|
670
|
-
formData
|
|
774
|
+
(0, import_get5.default)(formData, [key]),
|
|
775
|
+
experimental_customMergeAllOf
|
|
671
776
|
);
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
}
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
777
|
+
(0, import_set.default)(schema.properties, [key, ADDITIONAL_PROPERTY_FLAG], true);
|
|
778
|
+
return;
|
|
779
|
+
}
|
|
780
|
+
}
|
|
781
|
+
if (ADDITIONAL_PROPERTIES_KEY in schema && schema.additionalProperties !== false) {
|
|
782
|
+
let additionalProperties = {};
|
|
783
|
+
if (typeof schema.additionalProperties !== "boolean") {
|
|
784
|
+
if (REF_KEY in schema.additionalProperties) {
|
|
785
|
+
additionalProperties = retrieveSchema(
|
|
786
|
+
validator,
|
|
787
|
+
{ $ref: (0, import_get5.default)(schema.additionalProperties, [REF_KEY]) },
|
|
788
|
+
rootSchema,
|
|
789
|
+
formData,
|
|
790
|
+
experimental_customMergeAllOf
|
|
791
|
+
);
|
|
792
|
+
} else if ("type" in schema.additionalProperties) {
|
|
793
|
+
additionalProperties = { ...schema.additionalProperties };
|
|
794
|
+
} else if (ANY_OF_KEY in schema.additionalProperties || ONE_OF_KEY in schema.additionalProperties) {
|
|
795
|
+
additionalProperties = {
|
|
796
|
+
type: "object",
|
|
797
|
+
...schema.additionalProperties
|
|
798
|
+
};
|
|
799
|
+
} else {
|
|
800
|
+
additionalProperties = { type: guessType((0, import_get5.default)(formData, [key])) };
|
|
801
|
+
}
|
|
679
802
|
} else {
|
|
680
|
-
additionalProperties = { type: guessType((0,
|
|
803
|
+
additionalProperties = { type: guessType((0, import_get5.default)(formData, [key])) };
|
|
681
804
|
}
|
|
805
|
+
schema.properties[key] = additionalProperties;
|
|
806
|
+
(0, import_set.default)(schema.properties, [key, ADDITIONAL_PROPERTY_FLAG], true);
|
|
682
807
|
} else {
|
|
683
|
-
|
|
808
|
+
schema.properties[key] = { type: "null" };
|
|
809
|
+
(0, import_set.default)(schema.properties, [key, ADDITIONAL_PROPERTY_FLAG], true);
|
|
684
810
|
}
|
|
685
|
-
schema.properties[key] = additionalProperties;
|
|
686
|
-
(0, import_set.default)(schema.properties, [key, ADDITIONAL_PROPERTY_FLAG], true);
|
|
687
811
|
});
|
|
688
812
|
return schema;
|
|
689
813
|
}
|
|
690
|
-
function retrieveSchemaInternal(validator, schema, rootSchema, rawFormData, expandAllBranches = false, recurseList = []) {
|
|
814
|
+
function retrieveSchemaInternal(validator, schema, rootSchema, rawFormData, expandAllBranches = false, recurseList = [], experimental_customMergeAllOf) {
|
|
691
815
|
if (!isObject(schema)) {
|
|
692
816
|
return [{}];
|
|
693
817
|
}
|
|
@@ -697,7 +821,8 @@ function retrieveSchemaInternal(validator, schema, rootSchema, rawFormData, expa
|
|
|
697
821
|
rootSchema,
|
|
698
822
|
expandAllBranches,
|
|
699
823
|
recurseList,
|
|
700
|
-
rawFormData
|
|
824
|
+
rawFormData,
|
|
825
|
+
experimental_customMergeAllOf
|
|
701
826
|
);
|
|
702
827
|
return resolvedSchemas.flatMap((s) => {
|
|
703
828
|
let resolvedSchema = s;
|
|
@@ -708,7 +833,8 @@ function retrieveSchemaInternal(validator, schema, rootSchema, rawFormData, expa
|
|
|
708
833
|
rootSchema,
|
|
709
834
|
expandAllBranches,
|
|
710
835
|
recurseList,
|
|
711
|
-
rawFormData
|
|
836
|
+
rawFormData,
|
|
837
|
+
experimental_customMergeAllOf
|
|
712
838
|
);
|
|
713
839
|
}
|
|
714
840
|
if (ALL_OF_KEY in resolvedSchema) {
|
|
@@ -717,18 +843,63 @@ function retrieveSchemaInternal(validator, schema, rootSchema, rawFormData, expa
|
|
|
717
843
|
return [...allOf, restOfSchema];
|
|
718
844
|
}
|
|
719
845
|
try {
|
|
720
|
-
|
|
721
|
-
|
|
846
|
+
const withContainsSchemas = [];
|
|
847
|
+
const withoutContainsSchemas = [];
|
|
848
|
+
resolvedSchema.allOf?.forEach((s2) => {
|
|
849
|
+
if (typeof s2 === "object" && s2.contains) {
|
|
850
|
+
withContainsSchemas.push(s2);
|
|
851
|
+
} else {
|
|
852
|
+
withoutContainsSchemas.push(s2);
|
|
853
|
+
}
|
|
854
|
+
});
|
|
855
|
+
if (withContainsSchemas.length) {
|
|
856
|
+
resolvedSchema = { ...resolvedSchema, allOf: withoutContainsSchemas };
|
|
857
|
+
}
|
|
858
|
+
resolvedSchema = experimental_customMergeAllOf ? experimental_customMergeAllOf(resolvedSchema) : (0, import_json_schema_merge_allof.default)(resolvedSchema, {
|
|
859
|
+
deep: false,
|
|
860
|
+
resolvers: {
|
|
861
|
+
$defs: import_json_schema_merge_allof.default.options.resolvers.definitions
|
|
862
|
+
}
|
|
722
863
|
});
|
|
864
|
+
if (withContainsSchemas.length) {
|
|
865
|
+
resolvedSchema.allOf = withContainsSchemas;
|
|
866
|
+
}
|
|
723
867
|
} catch (e) {
|
|
724
868
|
console.warn("could not merge subschemas in allOf:\n", e);
|
|
725
869
|
const { allOf, ...resolvedSchemaWithoutAllOf } = resolvedSchema;
|
|
726
870
|
return resolvedSchemaWithoutAllOf;
|
|
727
871
|
}
|
|
728
872
|
}
|
|
729
|
-
|
|
873
|
+
if (PROPERTIES_KEY in resolvedSchema && PATTERN_PROPERTIES_KEY in resolvedSchema) {
|
|
874
|
+
resolvedSchema = Object.keys(resolvedSchema.properties).reduce(
|
|
875
|
+
(schema2, key) => {
|
|
876
|
+
const matchingProperties = getMatchingPatternProperties(schema2, key);
|
|
877
|
+
if (!(0, import_isEmpty2.default)(matchingProperties)) {
|
|
878
|
+
schema2.properties[key] = retrieveSchema(
|
|
879
|
+
validator,
|
|
880
|
+
{ allOf: [schema2.properties[key], ...Object.values(matchingProperties)] },
|
|
881
|
+
rootSchema,
|
|
882
|
+
(0, import_get5.default)(rawFormData, [key]),
|
|
883
|
+
experimental_customMergeAllOf
|
|
884
|
+
);
|
|
885
|
+
}
|
|
886
|
+
return schema2;
|
|
887
|
+
},
|
|
888
|
+
{
|
|
889
|
+
...resolvedSchema,
|
|
890
|
+
properties: { ...resolvedSchema.properties }
|
|
891
|
+
}
|
|
892
|
+
);
|
|
893
|
+
}
|
|
894
|
+
const hasAdditionalProperties = PATTERN_PROPERTIES_KEY in resolvedSchema || ADDITIONAL_PROPERTIES_KEY in resolvedSchema && resolvedSchema.additionalProperties !== false;
|
|
730
895
|
if (hasAdditionalProperties) {
|
|
731
|
-
return stubExistingAdditionalProperties(
|
|
896
|
+
return stubExistingAdditionalProperties(
|
|
897
|
+
validator,
|
|
898
|
+
resolvedSchema,
|
|
899
|
+
rootSchema,
|
|
900
|
+
rawFormData,
|
|
901
|
+
experimental_customMergeAllOf
|
|
902
|
+
);
|
|
732
903
|
}
|
|
733
904
|
return resolvedSchema;
|
|
734
905
|
});
|
|
@@ -755,7 +926,7 @@ function resolveAnyOrOneOfSchemas(validator, schema, rootSchema, expandAllBranch
|
|
|
755
926
|
}
|
|
756
927
|
return [schema];
|
|
757
928
|
}
|
|
758
|
-
function resolveDependencies(validator, schema, rootSchema, expandAllBranches, recurseList, formData) {
|
|
929
|
+
function resolveDependencies(validator, schema, rootSchema, expandAllBranches, recurseList, formData, experimental_customMergeAllOf) {
|
|
759
930
|
const { dependencies, ...remainingSchema } = schema;
|
|
760
931
|
const resolvedSchemas = resolveAnyOrOneOfSchemas(
|
|
761
932
|
validator,
|
|
@@ -772,14 +943,15 @@ function resolveDependencies(validator, schema, rootSchema, expandAllBranches, r
|
|
|
772
943
|
rootSchema,
|
|
773
944
|
expandAllBranches,
|
|
774
945
|
recurseList,
|
|
775
|
-
formData
|
|
946
|
+
formData,
|
|
947
|
+
experimental_customMergeAllOf
|
|
776
948
|
)
|
|
777
949
|
);
|
|
778
950
|
}
|
|
779
|
-
function processDependencies(validator, dependencies, resolvedSchema, rootSchema, expandAllBranches, recurseList, formData) {
|
|
951
|
+
function processDependencies(validator, dependencies, resolvedSchema, rootSchema, expandAllBranches, recurseList, formData, experimental_customMergeAllOf) {
|
|
780
952
|
let schemas = [resolvedSchema];
|
|
781
953
|
for (const dependencyKey in dependencies) {
|
|
782
|
-
if (!expandAllBranches && (0,
|
|
954
|
+
if (!expandAllBranches && (0, import_get5.default)(formData, [dependencyKey]) === void 0) {
|
|
783
955
|
continue;
|
|
784
956
|
}
|
|
785
957
|
if (resolvedSchema.properties && !(dependencyKey in resolvedSchema.properties)) {
|
|
@@ -800,7 +972,8 @@ function processDependencies(validator, dependencies, resolvedSchema, rootSchema
|
|
|
800
972
|
dependencyValue,
|
|
801
973
|
expandAllBranches,
|
|
802
974
|
recurseList,
|
|
803
|
-
formData
|
|
975
|
+
formData,
|
|
976
|
+
experimental_customMergeAllOf
|
|
804
977
|
);
|
|
805
978
|
}
|
|
806
979
|
return schemas.flatMap(
|
|
@@ -811,7 +984,8 @@ function processDependencies(validator, dependencies, resolvedSchema, rootSchema
|
|
|
811
984
|
rootSchema,
|
|
812
985
|
expandAllBranches,
|
|
813
986
|
recurseList,
|
|
814
|
-
formData
|
|
987
|
+
formData,
|
|
988
|
+
experimental_customMergeAllOf
|
|
815
989
|
)
|
|
816
990
|
);
|
|
817
991
|
}
|
|
@@ -824,14 +998,15 @@ function withDependentProperties(schema, additionallyRequired) {
|
|
|
824
998
|
const required = Array.isArray(schema.required) ? Array.from(/* @__PURE__ */ new Set([...schema.required, ...additionallyRequired])) : additionallyRequired;
|
|
825
999
|
return { ...schema, required };
|
|
826
1000
|
}
|
|
827
|
-
function withDependentSchema(validator, schema, rootSchema, dependencyKey, dependencyValue, expandAllBranches, recurseList, formData) {
|
|
1001
|
+
function withDependentSchema(validator, schema, rootSchema, dependencyKey, dependencyValue, expandAllBranches, recurseList, formData, experimental_customMergeAllOf) {
|
|
828
1002
|
const dependentSchemas = retrieveSchemaInternal(
|
|
829
1003
|
validator,
|
|
830
1004
|
dependencyValue,
|
|
831
1005
|
rootSchema,
|
|
832
1006
|
formData,
|
|
833
1007
|
expandAllBranches,
|
|
834
|
-
recurseList
|
|
1008
|
+
recurseList,
|
|
1009
|
+
experimental_customMergeAllOf
|
|
835
1010
|
);
|
|
836
1011
|
return dependentSchemas.flatMap((dependent) => {
|
|
837
1012
|
const { oneOf, ...dependentSchema } = dependent;
|
|
@@ -855,12 +1030,13 @@ function withDependentSchema(validator, schema, rootSchema, dependencyKey, depen
|
|
|
855
1030
|
resolvedOneOf,
|
|
856
1031
|
expandAllBranches,
|
|
857
1032
|
recurseList,
|
|
858
|
-
formData
|
|
1033
|
+
formData,
|
|
1034
|
+
experimental_customMergeAllOf
|
|
859
1035
|
)
|
|
860
1036
|
);
|
|
861
1037
|
});
|
|
862
1038
|
}
|
|
863
|
-
function withExactlyOneSubschema(validator, schema, rootSchema, dependencyKey, oneOf, expandAllBranches, recurseList, formData) {
|
|
1039
|
+
function withExactlyOneSubschema(validator, schema, rootSchema, dependencyKey, oneOf, expandAllBranches, recurseList, formData, experimental_customMergeAllOf) {
|
|
864
1040
|
const validSubschemas = oneOf.filter((subschema) => {
|
|
865
1041
|
if (typeof subschema === "boolean" || !subschema || !subschema.properties) {
|
|
866
1042
|
return false;
|
|
@@ -891,13 +1067,166 @@ function withExactlyOneSubschema(validator, schema, rootSchema, dependencyKey, o
|
|
|
891
1067
|
rootSchema,
|
|
892
1068
|
formData,
|
|
893
1069
|
expandAllBranches,
|
|
894
|
-
recurseList
|
|
1070
|
+
recurseList,
|
|
1071
|
+
experimental_customMergeAllOf
|
|
895
1072
|
);
|
|
896
1073
|
return schemas.map((s2) => mergeSchemas(schema, s2));
|
|
897
1074
|
});
|
|
898
1075
|
}
|
|
899
1076
|
|
|
1077
|
+
// src/schema/findSelectedOptionInXxxOf.ts
|
|
1078
|
+
function findSelectedOptionInXxxOf(validator, rootSchema, schema, fallbackField, xxx, formData = {}, experimental_customMergeAllOf) {
|
|
1079
|
+
if (Array.isArray(schema[xxx])) {
|
|
1080
|
+
const discriminator = getDiscriminatorFieldFromSchema(schema);
|
|
1081
|
+
const selectorField = discriminator || fallbackField;
|
|
1082
|
+
const xxxOfs = schema[xxx].map(
|
|
1083
|
+
(xxxOf) => retrieveSchema(validator, xxxOf, rootSchema, formData, experimental_customMergeAllOf)
|
|
1084
|
+
);
|
|
1085
|
+
const data = (0, import_get6.default)(formData, selectorField);
|
|
1086
|
+
if (data !== void 0) {
|
|
1087
|
+
return xxxOfs.find((xxx2) => {
|
|
1088
|
+
return (0, import_isEqual.default)(
|
|
1089
|
+
(0, import_get6.default)(xxx2, [PROPERTIES_KEY, selectorField, DEFAULT_KEY], (0, import_get6.default)(xxx2, [PROPERTIES_KEY, selectorField, CONST_KEY])),
|
|
1090
|
+
data
|
|
1091
|
+
);
|
|
1092
|
+
});
|
|
1093
|
+
}
|
|
1094
|
+
}
|
|
1095
|
+
return void 0;
|
|
1096
|
+
}
|
|
1097
|
+
|
|
1098
|
+
// src/schema/getFromSchema.ts
|
|
1099
|
+
var import_get7 = __toESM(require("lodash/get"), 1);
|
|
1100
|
+
var import_has2 = __toESM(require("lodash/has"), 1);
|
|
1101
|
+
var import_isEmpty3 = __toESM(require("lodash/isEmpty"), 1);
|
|
1102
|
+
function getFromSchemaInternal(validator, rootSchema, schema, path, experimental_customMergeAllOf) {
|
|
1103
|
+
let fieldSchema = schema;
|
|
1104
|
+
if ((0, import_has2.default)(schema, REF_KEY)) {
|
|
1105
|
+
fieldSchema = retrieveSchema(validator, schema, rootSchema, void 0, experimental_customMergeAllOf);
|
|
1106
|
+
}
|
|
1107
|
+
if ((0, import_isEmpty3.default)(path)) {
|
|
1108
|
+
return fieldSchema;
|
|
1109
|
+
}
|
|
1110
|
+
const pathList = Array.isArray(path) ? path : path.split(".");
|
|
1111
|
+
const [part, ...nestedPath] = pathList;
|
|
1112
|
+
if (part && (0, import_has2.default)(fieldSchema, part)) {
|
|
1113
|
+
fieldSchema = (0, import_get7.default)(fieldSchema, part);
|
|
1114
|
+
return getFromSchemaInternal(
|
|
1115
|
+
validator,
|
|
1116
|
+
rootSchema,
|
|
1117
|
+
fieldSchema,
|
|
1118
|
+
nestedPath,
|
|
1119
|
+
experimental_customMergeAllOf
|
|
1120
|
+
);
|
|
1121
|
+
}
|
|
1122
|
+
return void 0;
|
|
1123
|
+
}
|
|
1124
|
+
function getFromSchema(validator, rootSchema, schema, path, defaultValue, experimental_customMergeAllOf) {
|
|
1125
|
+
const result = getFromSchemaInternal(validator, rootSchema, schema, path, experimental_customMergeAllOf);
|
|
1126
|
+
if (result === void 0) {
|
|
1127
|
+
return defaultValue;
|
|
1128
|
+
}
|
|
1129
|
+
return result;
|
|
1130
|
+
}
|
|
1131
|
+
|
|
1132
|
+
// src/schema/findFieldInSchema.ts
|
|
1133
|
+
var NOT_FOUND_SCHEMA = { title: "!@#$_UNKNOWN_$#@!" };
|
|
1134
|
+
function findFieldInSchema(validator, rootSchema, schema, path, formData = {}, experimental_customMergeAllOf) {
|
|
1135
|
+
const pathList = Array.isArray(path) ? [...path] : path.split(".");
|
|
1136
|
+
let parentField = schema;
|
|
1137
|
+
const fieldName = pathList.pop();
|
|
1138
|
+
if (pathList.length) {
|
|
1139
|
+
pathList.forEach((subPath) => {
|
|
1140
|
+
parentField = getFromSchema(
|
|
1141
|
+
validator,
|
|
1142
|
+
rootSchema,
|
|
1143
|
+
parentField,
|
|
1144
|
+
[PROPERTIES_KEY, subPath],
|
|
1145
|
+
{},
|
|
1146
|
+
experimental_customMergeAllOf
|
|
1147
|
+
);
|
|
1148
|
+
if ((0, import_has3.default)(parentField, ONE_OF_KEY)) {
|
|
1149
|
+
parentField = findSelectedOptionInXxxOf(
|
|
1150
|
+
validator,
|
|
1151
|
+
rootSchema,
|
|
1152
|
+
parentField,
|
|
1153
|
+
fieldName,
|
|
1154
|
+
ONE_OF_KEY,
|
|
1155
|
+
(0, import_get8.default)(formData, subPath),
|
|
1156
|
+
experimental_customMergeAllOf
|
|
1157
|
+
);
|
|
1158
|
+
} else if ((0, import_has3.default)(parentField, ANY_OF_KEY)) {
|
|
1159
|
+
parentField = findSelectedOptionInXxxOf(
|
|
1160
|
+
validator,
|
|
1161
|
+
rootSchema,
|
|
1162
|
+
parentField,
|
|
1163
|
+
fieldName,
|
|
1164
|
+
ANY_OF_KEY,
|
|
1165
|
+
(0, import_get8.default)(formData, subPath),
|
|
1166
|
+
experimental_customMergeAllOf
|
|
1167
|
+
);
|
|
1168
|
+
}
|
|
1169
|
+
});
|
|
1170
|
+
}
|
|
1171
|
+
if ((0, import_has3.default)(parentField, ONE_OF_KEY)) {
|
|
1172
|
+
parentField = findSelectedOptionInXxxOf(
|
|
1173
|
+
validator,
|
|
1174
|
+
rootSchema,
|
|
1175
|
+
parentField,
|
|
1176
|
+
fieldName,
|
|
1177
|
+
ONE_OF_KEY,
|
|
1178
|
+
formData,
|
|
1179
|
+
experimental_customMergeAllOf
|
|
1180
|
+
);
|
|
1181
|
+
} else if ((0, import_has3.default)(parentField, ANY_OF_KEY)) {
|
|
1182
|
+
parentField = findSelectedOptionInXxxOf(
|
|
1183
|
+
validator,
|
|
1184
|
+
rootSchema,
|
|
1185
|
+
parentField,
|
|
1186
|
+
fieldName,
|
|
1187
|
+
ANY_OF_KEY,
|
|
1188
|
+
formData,
|
|
1189
|
+
experimental_customMergeAllOf
|
|
1190
|
+
);
|
|
1191
|
+
}
|
|
1192
|
+
let field = getFromSchema(
|
|
1193
|
+
validator,
|
|
1194
|
+
rootSchema,
|
|
1195
|
+
parentField,
|
|
1196
|
+
[PROPERTIES_KEY, fieldName],
|
|
1197
|
+
NOT_FOUND_SCHEMA,
|
|
1198
|
+
experimental_customMergeAllOf
|
|
1199
|
+
);
|
|
1200
|
+
if (field === NOT_FOUND_SCHEMA) {
|
|
1201
|
+
field = void 0;
|
|
1202
|
+
}
|
|
1203
|
+
const requiredArray = getFromSchema(
|
|
1204
|
+
validator,
|
|
1205
|
+
rootSchema,
|
|
1206
|
+
parentField,
|
|
1207
|
+
REQUIRED_KEY,
|
|
1208
|
+
[],
|
|
1209
|
+
experimental_customMergeAllOf
|
|
1210
|
+
);
|
|
1211
|
+
let isRequired;
|
|
1212
|
+
if (field && Array.isArray(requiredArray)) {
|
|
1213
|
+
isRequired = requiredArray.includes(fieldName);
|
|
1214
|
+
}
|
|
1215
|
+
return { field, isRequired };
|
|
1216
|
+
}
|
|
1217
|
+
|
|
1218
|
+
// src/schema/getDefaultFormState.ts
|
|
1219
|
+
var import_get12 = __toESM(require("lodash/get"), 1);
|
|
1220
|
+
var import_isEmpty4 = __toESM(require("lodash/isEmpty"), 1);
|
|
1221
|
+
|
|
900
1222
|
// src/schema/getClosestMatchingOption.ts
|
|
1223
|
+
var import_get9 = __toESM(require("lodash/get"), 1);
|
|
1224
|
+
var import_has4 = __toESM(require("lodash/has"), 1);
|
|
1225
|
+
var import_isNumber2 = __toESM(require("lodash/isNumber"), 1);
|
|
1226
|
+
var import_isObject6 = __toESM(require("lodash/isObject"), 1);
|
|
1227
|
+
var import_isString2 = __toESM(require("lodash/isString"), 1);
|
|
1228
|
+
var import_reduce = __toESM(require("lodash/reduce"), 1);
|
|
1229
|
+
var import_times2 = __toESM(require("lodash/times"), 1);
|
|
901
1230
|
var JUNK_OPTION = {
|
|
902
1231
|
type: "object",
|
|
903
1232
|
$id: JUNK_OPTION_ID,
|
|
@@ -907,35 +1236,51 @@ var JUNK_OPTION = {
|
|
|
907
1236
|
}
|
|
908
1237
|
}
|
|
909
1238
|
};
|
|
910
|
-
function calculateIndexScore(validator, rootSchema, schema, formData
|
|
1239
|
+
function calculateIndexScore(validator, rootSchema, schema, formData, experimental_customMergeAllOf) {
|
|
911
1240
|
let totalScore = 0;
|
|
912
1241
|
if (schema) {
|
|
913
|
-
if ((0,
|
|
1242
|
+
if ((0, import_isObject6.default)(schema.properties)) {
|
|
914
1243
|
totalScore += (0, import_reduce.default)(
|
|
915
1244
|
schema.properties,
|
|
916
1245
|
(score, value, key) => {
|
|
917
|
-
const formValue = (0,
|
|
1246
|
+
const formValue = (0, import_get9.default)(formData, key);
|
|
918
1247
|
if (typeof value === "boolean") {
|
|
919
1248
|
return score;
|
|
920
1249
|
}
|
|
921
|
-
if ((0,
|
|
922
|
-
const newSchema = retrieveSchema(
|
|
923
|
-
|
|
1250
|
+
if ((0, import_has4.default)(value, REF_KEY)) {
|
|
1251
|
+
const newSchema = retrieveSchema(
|
|
1252
|
+
validator,
|
|
1253
|
+
value,
|
|
1254
|
+
rootSchema,
|
|
1255
|
+
formValue,
|
|
1256
|
+
experimental_customMergeAllOf
|
|
1257
|
+
);
|
|
1258
|
+
return score + calculateIndexScore(
|
|
1259
|
+
validator,
|
|
1260
|
+
rootSchema,
|
|
1261
|
+
newSchema,
|
|
1262
|
+
formValue || {},
|
|
1263
|
+
experimental_customMergeAllOf
|
|
1264
|
+
);
|
|
924
1265
|
}
|
|
925
|
-
if (((0,
|
|
926
|
-
const key2 = (0,
|
|
1266
|
+
if (((0, import_has4.default)(value, ONE_OF_KEY) || (0, import_has4.default)(value, ANY_OF_KEY)) && formValue) {
|
|
1267
|
+
const key2 = (0, import_has4.default)(value, ONE_OF_KEY) ? ONE_OF_KEY : ANY_OF_KEY;
|
|
927
1268
|
const discriminator = getDiscriminatorFieldFromSchema(value);
|
|
928
1269
|
return score + getClosestMatchingOption(
|
|
929
1270
|
validator,
|
|
930
1271
|
rootSchema,
|
|
931
1272
|
formValue,
|
|
932
|
-
(0,
|
|
1273
|
+
(0, import_get9.default)(value, key2),
|
|
933
1274
|
-1,
|
|
934
|
-
discriminator
|
|
1275
|
+
discriminator,
|
|
1276
|
+
experimental_customMergeAllOf
|
|
935
1277
|
);
|
|
936
1278
|
}
|
|
937
1279
|
if (value.type === "object") {
|
|
938
|
-
|
|
1280
|
+
if ((0, import_isObject6.default)(formValue)) {
|
|
1281
|
+
score += 1;
|
|
1282
|
+
}
|
|
1283
|
+
return score + calculateIndexScore(validator, rootSchema, value, formValue, experimental_customMergeAllOf);
|
|
939
1284
|
}
|
|
940
1285
|
if (value.type === guessType(formValue)) {
|
|
941
1286
|
let newScore = score + 1;
|
|
@@ -956,7 +1301,7 @@ function calculateIndexScore(validator, rootSchema, schema, formData = {}) {
|
|
|
956
1301
|
}
|
|
957
1302
|
return totalScore;
|
|
958
1303
|
}
|
|
959
|
-
function getClosestMatchingOption(validator, rootSchema, formData, options, selectedOption = -1, discriminatorField) {
|
|
1304
|
+
function getClosestMatchingOption(validator, rootSchema, formData, options, selectedOption = -1, discriminatorField, experimental_customMergeAllOf) {
|
|
960
1305
|
const resolvedOptions = options.map((option) => {
|
|
961
1306
|
return resolveAllReferences(option, rootSchema, []);
|
|
962
1307
|
});
|
|
@@ -983,7 +1328,7 @@ function getClosestMatchingOption(validator, rootSchema, formData, options, sele
|
|
|
983
1328
|
(scoreData, index) => {
|
|
984
1329
|
const { bestScore } = scoreData;
|
|
985
1330
|
const option = resolvedOptions[index];
|
|
986
|
-
const score = calculateIndexScore(validator, rootSchema, option, formData);
|
|
1331
|
+
const score = calculateIndexScore(validator, rootSchema, option, formData, experimental_customMergeAllOf);
|
|
987
1332
|
scoreCount.add(score);
|
|
988
1333
|
if (score > bestScore) {
|
|
989
1334
|
return { bestIndex: index, bestScore: score };
|
|
@@ -1004,57 +1349,79 @@ function isFixedItems(schema) {
|
|
|
1004
1349
|
}
|
|
1005
1350
|
|
|
1006
1351
|
// src/mergeDefaultsWithFormData.ts
|
|
1007
|
-
var
|
|
1008
|
-
|
|
1352
|
+
var import_get10 = __toESM(require("lodash/get"), 1);
|
|
1353
|
+
var import_isNil = __toESM(require("lodash/isNil"), 1);
|
|
1354
|
+
function mergeDefaultsWithFormData(defaults, formData, mergeExtraArrayDefaults = false, defaultSupercedesUndefined = false, overrideFormDataWithDefaults = false) {
|
|
1009
1355
|
if (Array.isArray(formData)) {
|
|
1010
1356
|
const defaultsArray = Array.isArray(defaults) ? defaults : [];
|
|
1011
|
-
const
|
|
1012
|
-
|
|
1013
|
-
|
|
1357
|
+
const overrideArray = overrideFormDataWithDefaults ? defaultsArray : formData;
|
|
1358
|
+
const overrideOppositeArray = overrideFormDataWithDefaults ? formData : defaultsArray;
|
|
1359
|
+
const mapped = overrideArray.map((value, idx) => {
|
|
1360
|
+
if (overrideOppositeArray[idx] !== void 0) {
|
|
1361
|
+
return mergeDefaultsWithFormData(
|
|
1362
|
+
defaultsArray[idx],
|
|
1363
|
+
formData[idx],
|
|
1364
|
+
mergeExtraArrayDefaults,
|
|
1365
|
+
defaultSupercedesUndefined,
|
|
1366
|
+
overrideFormDataWithDefaults
|
|
1367
|
+
);
|
|
1014
1368
|
}
|
|
1015
1369
|
return value;
|
|
1016
1370
|
});
|
|
1017
|
-
if (mergeExtraArrayDefaults && mapped.length <
|
|
1018
|
-
mapped.push(...
|
|
1371
|
+
if ((mergeExtraArrayDefaults || overrideFormDataWithDefaults) && mapped.length < overrideOppositeArray.length) {
|
|
1372
|
+
mapped.push(...overrideOppositeArray.slice(mapped.length));
|
|
1019
1373
|
}
|
|
1020
1374
|
return mapped;
|
|
1021
1375
|
}
|
|
1022
1376
|
if (isObject(formData)) {
|
|
1023
1377
|
const acc = Object.assign({}, defaults);
|
|
1024
1378
|
return Object.keys(formData).reduce((acc2, key) => {
|
|
1379
|
+
const keyValue = (0, import_get10.default)(formData, key);
|
|
1380
|
+
const keyExistsInDefaults = isObject(defaults) && key in defaults;
|
|
1381
|
+
const keyExistsInFormData = key in formData;
|
|
1025
1382
|
acc2[key] = mergeDefaultsWithFormData(
|
|
1026
|
-
defaults ? (0,
|
|
1027
|
-
|
|
1028
|
-
mergeExtraArrayDefaults
|
|
1383
|
+
defaults ? (0, import_get10.default)(defaults, key) : {},
|
|
1384
|
+
keyValue,
|
|
1385
|
+
mergeExtraArrayDefaults,
|
|
1386
|
+
defaultSupercedesUndefined,
|
|
1387
|
+
// overrideFormDataWithDefaults can be true only when the key value exists in defaults
|
|
1388
|
+
// Or if the key value doesn't exist in formData
|
|
1389
|
+
overrideFormDataWithDefaults && (keyExistsInDefaults || !keyExistsInFormData)
|
|
1029
1390
|
);
|
|
1030
1391
|
return acc2;
|
|
1031
1392
|
}, acc);
|
|
1032
1393
|
}
|
|
1394
|
+
if (defaultSupercedesUndefined && (!(0, import_isNil.default)(defaults) && (0, import_isNil.default)(formData) || typeof formData === "number" && isNaN(formData)) || overrideFormDataWithDefaults && !(0, import_isNil.default)(formData)) {
|
|
1395
|
+
return defaults;
|
|
1396
|
+
}
|
|
1033
1397
|
return formData;
|
|
1034
1398
|
}
|
|
1035
1399
|
|
|
1036
1400
|
// src/mergeObjects.ts
|
|
1037
1401
|
function mergeObjects(obj1, obj2, concatArrays = false) {
|
|
1038
|
-
return Object.keys(obj2).reduce(
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1402
|
+
return Object.keys(obj2).reduce(
|
|
1403
|
+
(acc, key) => {
|
|
1404
|
+
const left = obj1 ? obj1[key] : {}, right = obj2[key];
|
|
1405
|
+
if (obj1 && key in obj1 && isObject(right)) {
|
|
1406
|
+
acc[key] = mergeObjects(left, right, concatArrays);
|
|
1407
|
+
} else if (concatArrays && Array.isArray(left) && Array.isArray(right)) {
|
|
1408
|
+
let toMerge = right;
|
|
1409
|
+
if (concatArrays === "preventDuplicates") {
|
|
1410
|
+
toMerge = right.reduce((result, value) => {
|
|
1411
|
+
if (!left.includes(value)) {
|
|
1412
|
+
result.push(value);
|
|
1413
|
+
}
|
|
1414
|
+
return result;
|
|
1415
|
+
}, []);
|
|
1416
|
+
}
|
|
1417
|
+
acc[key] = left.concat(toMerge);
|
|
1418
|
+
} else {
|
|
1419
|
+
acc[key] = right;
|
|
1051
1420
|
}
|
|
1052
|
-
acc
|
|
1053
|
-
}
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
return acc;
|
|
1057
|
-
}, Object.assign({}, obj1));
|
|
1421
|
+
return acc;
|
|
1422
|
+
},
|
|
1423
|
+
Object.assign({}, obj1)
|
|
1424
|
+
);
|
|
1058
1425
|
}
|
|
1059
1426
|
|
|
1060
1427
|
// src/isConstant.ts
|
|
@@ -1063,8 +1430,8 @@ function isConstant(schema) {
|
|
|
1063
1430
|
}
|
|
1064
1431
|
|
|
1065
1432
|
// src/schema/isSelect.ts
|
|
1066
|
-
function isSelect(validator, theSchema, rootSchema = {}) {
|
|
1067
|
-
const schema = retrieveSchema(validator, theSchema, rootSchema, void 0);
|
|
1433
|
+
function isSelect(validator, theSchema, rootSchema = {}, experimental_customMergeAllOf) {
|
|
1434
|
+
const schema = retrieveSchema(validator, theSchema, rootSchema, void 0, experimental_customMergeAllOf);
|
|
1068
1435
|
const altSchemas = schema.oneOf || schema.anyOf;
|
|
1069
1436
|
if (Array.isArray(schema.enum)) {
|
|
1070
1437
|
return true;
|
|
@@ -1076,14 +1443,85 @@ function isSelect(validator, theSchema, rootSchema = {}) {
|
|
|
1076
1443
|
}
|
|
1077
1444
|
|
|
1078
1445
|
// src/schema/isMultiSelect.ts
|
|
1079
|
-
function isMultiSelect(validator, schema, rootSchema) {
|
|
1446
|
+
function isMultiSelect(validator, schema, rootSchema, experimental_customMergeAllOf) {
|
|
1080
1447
|
if (!schema.uniqueItems || !schema.items || typeof schema.items === "boolean") {
|
|
1081
1448
|
return false;
|
|
1082
1449
|
}
|
|
1083
|
-
return isSelect(validator, schema.items, rootSchema);
|
|
1450
|
+
return isSelect(validator, schema.items, rootSchema, experimental_customMergeAllOf);
|
|
1451
|
+
}
|
|
1452
|
+
|
|
1453
|
+
// src/constIsAjvDataReference.ts
|
|
1454
|
+
var import_isString3 = __toESM(require("lodash/isString"), 1);
|
|
1455
|
+
function constIsAjvDataReference(schema) {
|
|
1456
|
+
const schemaConst = schema[CONST_KEY];
|
|
1457
|
+
const schemaType = getSchemaType(schema);
|
|
1458
|
+
return isObject(schemaConst) && (0, import_isString3.default)(schemaConst?.$data) && schemaType !== "object" && schemaType !== "array";
|
|
1459
|
+
}
|
|
1460
|
+
|
|
1461
|
+
// src/optionsList.ts
|
|
1462
|
+
var import_get11 = __toESM(require("lodash/get"), 1);
|
|
1463
|
+
|
|
1464
|
+
// src/toConstant.ts
|
|
1465
|
+
function toConstant(schema) {
|
|
1466
|
+
if (ENUM_KEY in schema && Array.isArray(schema.enum) && schema.enum.length === 1) {
|
|
1467
|
+
return schema.enum[0];
|
|
1468
|
+
}
|
|
1469
|
+
if (CONST_KEY in schema) {
|
|
1470
|
+
return schema.const;
|
|
1471
|
+
}
|
|
1472
|
+
throw new Error("schema cannot be inferred as a constant");
|
|
1473
|
+
}
|
|
1474
|
+
|
|
1475
|
+
// src/optionsList.ts
|
|
1476
|
+
function optionsList(schema, uiSchema) {
|
|
1477
|
+
if (schema.enum) {
|
|
1478
|
+
let enumNames;
|
|
1479
|
+
if (uiSchema) {
|
|
1480
|
+
const { enumNames: uiEnumNames } = getUiOptions(uiSchema);
|
|
1481
|
+
enumNames = uiEnumNames;
|
|
1482
|
+
}
|
|
1483
|
+
return schema.enum.map((value, i) => {
|
|
1484
|
+
const label = enumNames?.[i] || String(value);
|
|
1485
|
+
return { label, value };
|
|
1486
|
+
});
|
|
1487
|
+
}
|
|
1488
|
+
let altSchemas = void 0;
|
|
1489
|
+
let altUiSchemas = void 0;
|
|
1490
|
+
if (schema.anyOf) {
|
|
1491
|
+
altSchemas = schema.anyOf;
|
|
1492
|
+
altUiSchemas = uiSchema?.anyOf;
|
|
1493
|
+
} else if (schema.oneOf) {
|
|
1494
|
+
altSchemas = schema.oneOf;
|
|
1495
|
+
altUiSchemas = uiSchema?.oneOf;
|
|
1496
|
+
}
|
|
1497
|
+
let selectorField = getDiscriminatorFieldFromSchema(schema);
|
|
1498
|
+
if (uiSchema) {
|
|
1499
|
+
const { optionsSchemaSelector = selectorField } = getUiOptions(uiSchema);
|
|
1500
|
+
selectorField = optionsSchemaSelector;
|
|
1501
|
+
}
|
|
1502
|
+
return altSchemas && altSchemas.map((aSchemaDef, index) => {
|
|
1503
|
+
const { title } = getUiOptions(altUiSchemas?.[index]);
|
|
1504
|
+
const aSchema = aSchemaDef;
|
|
1505
|
+
let value;
|
|
1506
|
+
let label = title;
|
|
1507
|
+
if (selectorField) {
|
|
1508
|
+
const innerSchema = (0, import_get11.default)(aSchema, [PROPERTIES_KEY, selectorField], {});
|
|
1509
|
+
value = (0, import_get11.default)(innerSchema, DEFAULT_KEY, (0, import_get11.default)(innerSchema, CONST_KEY));
|
|
1510
|
+
label = label || innerSchema?.title || aSchema.title || String(value);
|
|
1511
|
+
} else {
|
|
1512
|
+
value = toConstant(aSchema);
|
|
1513
|
+
label = label || aSchema.title || String(value);
|
|
1514
|
+
}
|
|
1515
|
+
return {
|
|
1516
|
+
schema: aSchema,
|
|
1517
|
+
label,
|
|
1518
|
+
value
|
|
1519
|
+
};
|
|
1520
|
+
});
|
|
1084
1521
|
}
|
|
1085
1522
|
|
|
1086
1523
|
// src/schema/getDefaultFormState.ts
|
|
1524
|
+
var PRIMITIVE_TYPES = ["string", "number", "integer", "boolean", "null"];
|
|
1087
1525
|
function getInnerSchemaForArrayItem(schema, additionalItems = 0 /* Ignore */, idx = -1) {
|
|
1088
1526
|
if (idx >= 0) {
|
|
1089
1527
|
if (Array.isArray(schema.items) && idx < schema.items.length) {
|
|
@@ -1100,47 +1538,54 @@ function getInnerSchemaForArrayItem(schema, additionalItems = 0 /* Ignore */, id
|
|
|
1100
1538
|
}
|
|
1101
1539
|
return {};
|
|
1102
1540
|
}
|
|
1103
|
-
function maybeAddDefaultToObject(obj, key, computedDefault, includeUndefinedValues, isParentRequired, requiredFields = [], experimental_defaultFormStateBehavior = {}) {
|
|
1541
|
+
function maybeAddDefaultToObject(obj, key, computedDefault, includeUndefinedValues, isParentRequired, requiredFields = [], experimental_defaultFormStateBehavior = {}, isConst = false) {
|
|
1104
1542
|
const { emptyObjectFields = "populateAllDefaults" } = experimental_defaultFormStateBehavior;
|
|
1105
|
-
if (includeUndefinedValues) {
|
|
1543
|
+
if (includeUndefinedValues || isConst) {
|
|
1106
1544
|
obj[key] = computedDefault;
|
|
1107
1545
|
} else if (emptyObjectFields !== "skipDefaults") {
|
|
1546
|
+
const isSelfOrParentRequired = isParentRequired === void 0 ? requiredFields.includes(key) : isParentRequired;
|
|
1108
1547
|
if (isObject(computedDefault)) {
|
|
1109
|
-
const isSelfOrParentRequired = isParentRequired === void 0 ? requiredFields.includes(key) : isParentRequired;
|
|
1110
1548
|
if (emptyObjectFields === "skipEmptyDefaults") {
|
|
1111
|
-
if (!(0,
|
|
1549
|
+
if (!(0, import_isEmpty4.default)(computedDefault)) {
|
|
1112
1550
|
obj[key] = computedDefault;
|
|
1113
1551
|
}
|
|
1114
|
-
} else if ((!(0,
|
|
1552
|
+
} else if ((!(0, import_isEmpty4.default)(computedDefault) || requiredFields.includes(key)) && (isSelfOrParentRequired || emptyObjectFields !== "populateRequiredDefaults")) {
|
|
1115
1553
|
obj[key] = computedDefault;
|
|
1116
1554
|
}
|
|
1117
1555
|
} else if (
|
|
1118
1556
|
// Store computedDefault if it's a defined primitive (e.g., true) and satisfies certain conditions
|
|
1119
1557
|
// Condition 1: computedDefault is not undefined
|
|
1120
|
-
// Condition 2: If emptyObjectFields is 'populateAllDefaults' or 'skipEmptyDefaults)
|
|
1121
|
-
|
|
1558
|
+
// Condition 2: If emptyObjectFields is 'populateAllDefaults' or 'skipEmptyDefaults)
|
|
1559
|
+
// Or if isSelfOrParentRequired is 'true' and the key is a required field
|
|
1560
|
+
computedDefault !== void 0 && (emptyObjectFields === "populateAllDefaults" || emptyObjectFields === "skipEmptyDefaults" || isSelfOrParentRequired && requiredFields.includes(key))
|
|
1122
1561
|
) {
|
|
1123
1562
|
obj[key] = computedDefault;
|
|
1124
1563
|
}
|
|
1125
1564
|
}
|
|
1126
1565
|
}
|
|
1127
|
-
function computeDefaults(validator, rawSchema, {
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1566
|
+
function computeDefaults(validator, rawSchema, computeDefaultsProps = {}) {
|
|
1567
|
+
const {
|
|
1568
|
+
parentDefaults,
|
|
1569
|
+
rawFormData,
|
|
1570
|
+
rootSchema = {},
|
|
1571
|
+
includeUndefinedValues = false,
|
|
1572
|
+
_recurseList = [],
|
|
1573
|
+
experimental_defaultFormStateBehavior = void 0,
|
|
1574
|
+
experimental_customMergeAllOf = void 0,
|
|
1575
|
+
required,
|
|
1576
|
+
shouldMergeDefaultsIntoFormData = false
|
|
1577
|
+
} = computeDefaultsProps;
|
|
1578
|
+
let formData = isObject(rawFormData) ? rawFormData : {};
|
|
1137
1579
|
const schema = isObject(rawSchema) ? rawSchema : {};
|
|
1138
1580
|
let defaults = parentDefaults;
|
|
1139
1581
|
let schemaToCompute = null;
|
|
1582
|
+
let experimental_dfsb_to_compute = experimental_defaultFormStateBehavior;
|
|
1140
1583
|
let updatedRecurseList = _recurseList;
|
|
1141
|
-
if (
|
|
1584
|
+
if (schema[CONST_KEY] && experimental_defaultFormStateBehavior?.constAsDefaults !== "never" && !constIsAjvDataReference(schema)) {
|
|
1585
|
+
defaults = schema[CONST_KEY];
|
|
1586
|
+
} else if (isObject(defaults) && isObject(schema.default)) {
|
|
1142
1587
|
defaults = mergeObjects(defaults, schema.default);
|
|
1143
|
-
} else if (DEFAULT_KEY in schema) {
|
|
1588
|
+
} else if (DEFAULT_KEY in schema && !schema[ANY_OF_KEY] && !schema[ONE_OF_KEY] && !schema[REF_KEY]) {
|
|
1144
1589
|
defaults = schema.default;
|
|
1145
1590
|
} else if (REF_KEY in schema) {
|
|
1146
1591
|
const refName = schema[REF_KEY];
|
|
@@ -1148,8 +1593,26 @@ function computeDefaults(validator, rawSchema, {
|
|
|
1148
1593
|
updatedRecurseList = _recurseList.concat(refName);
|
|
1149
1594
|
schemaToCompute = findSchemaDefinition(refName, rootSchema);
|
|
1150
1595
|
}
|
|
1596
|
+
if (schemaToCompute && !defaults) {
|
|
1597
|
+
defaults = schema.default;
|
|
1598
|
+
}
|
|
1599
|
+
if (shouldMergeDefaultsIntoFormData && schemaToCompute && !isObject(rawFormData)) {
|
|
1600
|
+
formData = rawFormData;
|
|
1601
|
+
}
|
|
1151
1602
|
} else if (DEPENDENCIES_KEY in schema) {
|
|
1152
|
-
const
|
|
1603
|
+
const defaultFormData = {
|
|
1604
|
+
...getDefaultBasedOnSchemaType(validator, schema, computeDefaultsProps, defaults),
|
|
1605
|
+
...formData
|
|
1606
|
+
};
|
|
1607
|
+
const resolvedSchema = resolveDependencies(
|
|
1608
|
+
validator,
|
|
1609
|
+
schema,
|
|
1610
|
+
rootSchema,
|
|
1611
|
+
false,
|
|
1612
|
+
[],
|
|
1613
|
+
defaultFormData,
|
|
1614
|
+
experimental_customMergeAllOf
|
|
1615
|
+
);
|
|
1153
1616
|
schemaToCompute = resolvedSchema[0];
|
|
1154
1617
|
} else if (isFixedItems(schema)) {
|
|
1155
1618
|
defaults = schema.items.map(
|
|
@@ -1158,9 +1621,11 @@ function computeDefaults(validator, rawSchema, {
|
|
|
1158
1621
|
includeUndefinedValues,
|
|
1159
1622
|
_recurseList,
|
|
1160
1623
|
experimental_defaultFormStateBehavior,
|
|
1624
|
+
experimental_customMergeAllOf,
|
|
1161
1625
|
parentDefaults: Array.isArray(parentDefaults) ? parentDefaults[idx] : void 0,
|
|
1162
1626
|
rawFormData: formData,
|
|
1163
|
-
required
|
|
1627
|
+
required,
|
|
1628
|
+
shouldMergeDefaultsIntoFormData
|
|
1164
1629
|
})
|
|
1165
1630
|
);
|
|
1166
1631
|
} else if (ONE_OF_KEY in schema) {
|
|
@@ -1169,13 +1634,21 @@ function computeDefaults(validator, rawSchema, {
|
|
|
1169
1634
|
return void 0;
|
|
1170
1635
|
}
|
|
1171
1636
|
const discriminator = getDiscriminatorFieldFromSchema(schema);
|
|
1637
|
+
const { type = "null" } = remaining;
|
|
1638
|
+
if (!Array.isArray(type) && PRIMITIVE_TYPES.includes(type) && experimental_dfsb_to_compute?.constAsDefaults === "skipOneOf") {
|
|
1639
|
+
experimental_dfsb_to_compute = {
|
|
1640
|
+
...experimental_dfsb_to_compute,
|
|
1641
|
+
constAsDefaults: "never"
|
|
1642
|
+
};
|
|
1643
|
+
}
|
|
1172
1644
|
schemaToCompute = oneOf[getClosestMatchingOption(
|
|
1173
1645
|
validator,
|
|
1174
1646
|
rootSchema,
|
|
1175
|
-
|
|
1647
|
+
rawFormData ?? schema.default,
|
|
1176
1648
|
oneOf,
|
|
1177
1649
|
0,
|
|
1178
|
-
discriminator
|
|
1650
|
+
discriminator,
|
|
1651
|
+
experimental_customMergeAllOf
|
|
1179
1652
|
)];
|
|
1180
1653
|
schemaToCompute = mergeSchemas(remaining, schemaToCompute);
|
|
1181
1654
|
} else if (ANY_OF_KEY in schema) {
|
|
@@ -1187,10 +1660,11 @@ function computeDefaults(validator, rawSchema, {
|
|
|
1187
1660
|
schemaToCompute = anyOf[getClosestMatchingOption(
|
|
1188
1661
|
validator,
|
|
1189
1662
|
rootSchema,
|
|
1190
|
-
|
|
1663
|
+
rawFormData ?? schema.default,
|
|
1191
1664
|
anyOf,
|
|
1192
1665
|
0,
|
|
1193
|
-
discriminator
|
|
1666
|
+
discriminator,
|
|
1667
|
+
experimental_customMergeAllOf
|
|
1194
1668
|
)];
|
|
1195
1669
|
schemaToCompute = mergeSchemas(remaining, schemaToCompute);
|
|
1196
1670
|
}
|
|
@@ -1199,159 +1673,257 @@ function computeDefaults(validator, rawSchema, {
|
|
|
1199
1673
|
rootSchema,
|
|
1200
1674
|
includeUndefinedValues,
|
|
1201
1675
|
_recurseList: updatedRecurseList,
|
|
1202
|
-
experimental_defaultFormStateBehavior,
|
|
1676
|
+
experimental_defaultFormStateBehavior: experimental_dfsb_to_compute,
|
|
1677
|
+
experimental_customMergeAllOf,
|
|
1203
1678
|
parentDefaults: defaults,
|
|
1204
1679
|
rawFormData: formData,
|
|
1205
|
-
required
|
|
1680
|
+
required,
|
|
1681
|
+
shouldMergeDefaultsIntoFormData
|
|
1206
1682
|
});
|
|
1207
1683
|
}
|
|
1208
|
-
if (defaults === void 0) {
|
|
1209
|
-
defaults = schema.default;
|
|
1684
|
+
if (defaults === void 0) {
|
|
1685
|
+
defaults = schema.default;
|
|
1686
|
+
}
|
|
1687
|
+
const defaultBasedOnSchemaType = getDefaultBasedOnSchemaType(validator, schema, computeDefaultsProps, defaults);
|
|
1688
|
+
let defaultsWithFormData = defaultBasedOnSchemaType ?? defaults;
|
|
1689
|
+
if (shouldMergeDefaultsIntoFormData) {
|
|
1690
|
+
const { arrayMinItems = {} } = experimental_defaultFormStateBehavior || {};
|
|
1691
|
+
const { mergeExtraDefaults } = arrayMinItems;
|
|
1692
|
+
const matchingFormData = ensureFormDataMatchingSchema(
|
|
1693
|
+
validator,
|
|
1694
|
+
schema,
|
|
1695
|
+
rootSchema,
|
|
1696
|
+
rawFormData,
|
|
1697
|
+
experimental_defaultFormStateBehavior,
|
|
1698
|
+
experimental_customMergeAllOf
|
|
1699
|
+
);
|
|
1700
|
+
if (!isObject(rawFormData) || ALL_OF_KEY in schema) {
|
|
1701
|
+
defaultsWithFormData = mergeDefaultsWithFormData(
|
|
1702
|
+
defaultsWithFormData,
|
|
1703
|
+
matchingFormData,
|
|
1704
|
+
mergeExtraDefaults,
|
|
1705
|
+
true
|
|
1706
|
+
);
|
|
1707
|
+
}
|
|
1708
|
+
}
|
|
1709
|
+
return defaultsWithFormData;
|
|
1710
|
+
}
|
|
1711
|
+
function ensureFormDataMatchingSchema(validator, schema, rootSchema, formData, experimental_defaultFormStateBehavior, experimental_customMergeAllOf) {
|
|
1712
|
+
const isSelectField = !isConstant(schema) && isSelect(validator, schema, rootSchema, experimental_customMergeAllOf);
|
|
1713
|
+
let validFormData = formData;
|
|
1714
|
+
if (isSelectField) {
|
|
1715
|
+
const getOptionsList = optionsList(schema);
|
|
1716
|
+
const isValid = getOptionsList?.some((option) => deepEquals(option.value, formData));
|
|
1717
|
+
validFormData = isValid ? formData : void 0;
|
|
1718
|
+
}
|
|
1719
|
+
const constTakesPrecedence = schema[CONST_KEY] && experimental_defaultFormStateBehavior?.constAsDefaults === "always";
|
|
1720
|
+
if (constTakesPrecedence) {
|
|
1721
|
+
validFormData = schema.const;
|
|
1722
|
+
}
|
|
1723
|
+
return validFormData;
|
|
1724
|
+
}
|
|
1725
|
+
function getObjectDefaults(validator, rawSchema, {
|
|
1726
|
+
rawFormData,
|
|
1727
|
+
rootSchema = {},
|
|
1728
|
+
includeUndefinedValues = false,
|
|
1729
|
+
_recurseList = [],
|
|
1730
|
+
experimental_defaultFormStateBehavior = void 0,
|
|
1731
|
+
experimental_customMergeAllOf = void 0,
|
|
1732
|
+
required,
|
|
1733
|
+
shouldMergeDefaultsIntoFormData
|
|
1734
|
+
} = {}, defaults) {
|
|
1735
|
+
{
|
|
1736
|
+
const formData = isObject(rawFormData) ? rawFormData : {};
|
|
1737
|
+
const schema = rawSchema;
|
|
1738
|
+
const retrievedSchema = experimental_defaultFormStateBehavior?.allOf === "populateDefaults" && ALL_OF_KEY in schema ? retrieveSchema(validator, schema, rootSchema, formData, experimental_customMergeAllOf) : schema;
|
|
1739
|
+
const parentConst = retrievedSchema[CONST_KEY];
|
|
1740
|
+
const objectDefaults = Object.keys(retrievedSchema.properties || {}).reduce(
|
|
1741
|
+
(acc, key) => {
|
|
1742
|
+
const propertySchema = (0, import_get12.default)(retrievedSchema, [PROPERTIES_KEY, key], {});
|
|
1743
|
+
const hasParentConst = isObject(parentConst) && parentConst[key] !== void 0;
|
|
1744
|
+
const hasConst = (isObject(propertySchema) && CONST_KEY in propertySchema || hasParentConst) && experimental_defaultFormStateBehavior?.constAsDefaults !== "never" && !constIsAjvDataReference(propertySchema);
|
|
1745
|
+
const computedDefault = computeDefaults(validator, propertySchema, {
|
|
1746
|
+
rootSchema,
|
|
1747
|
+
_recurseList,
|
|
1748
|
+
experimental_defaultFormStateBehavior,
|
|
1749
|
+
experimental_customMergeAllOf,
|
|
1750
|
+
includeUndefinedValues: includeUndefinedValues === true,
|
|
1751
|
+
parentDefaults: (0, import_get12.default)(defaults, [key]),
|
|
1752
|
+
rawFormData: (0, import_get12.default)(formData, [key]),
|
|
1753
|
+
required: retrievedSchema.required?.includes(key),
|
|
1754
|
+
shouldMergeDefaultsIntoFormData
|
|
1755
|
+
});
|
|
1756
|
+
maybeAddDefaultToObject(
|
|
1757
|
+
acc,
|
|
1758
|
+
key,
|
|
1759
|
+
computedDefault,
|
|
1760
|
+
includeUndefinedValues,
|
|
1761
|
+
required,
|
|
1762
|
+
retrievedSchema.required,
|
|
1763
|
+
experimental_defaultFormStateBehavior,
|
|
1764
|
+
hasConst
|
|
1765
|
+
);
|
|
1766
|
+
return acc;
|
|
1767
|
+
},
|
|
1768
|
+
{}
|
|
1769
|
+
);
|
|
1770
|
+
if (retrievedSchema.additionalProperties) {
|
|
1771
|
+
const additionalPropertiesSchema = isObject(retrievedSchema.additionalProperties) ? retrievedSchema.additionalProperties : {};
|
|
1772
|
+
const keys2 = /* @__PURE__ */ new Set();
|
|
1773
|
+
if (isObject(defaults)) {
|
|
1774
|
+
Object.keys(defaults).filter((key) => !retrievedSchema.properties || !retrievedSchema.properties[key]).forEach((key) => keys2.add(key));
|
|
1775
|
+
}
|
|
1776
|
+
const formDataRequired = [];
|
|
1777
|
+
Object.keys(formData).filter((key) => !retrievedSchema.properties || !retrievedSchema.properties[key]).forEach((key) => {
|
|
1778
|
+
keys2.add(key);
|
|
1779
|
+
formDataRequired.push(key);
|
|
1780
|
+
});
|
|
1781
|
+
keys2.forEach((key) => {
|
|
1782
|
+
const computedDefault = computeDefaults(validator, additionalPropertiesSchema, {
|
|
1783
|
+
rootSchema,
|
|
1784
|
+
_recurseList,
|
|
1785
|
+
experimental_defaultFormStateBehavior,
|
|
1786
|
+
experimental_customMergeAllOf,
|
|
1787
|
+
includeUndefinedValues: includeUndefinedValues === true,
|
|
1788
|
+
parentDefaults: (0, import_get12.default)(defaults, [key]),
|
|
1789
|
+
rawFormData: (0, import_get12.default)(formData, [key]),
|
|
1790
|
+
required: retrievedSchema.required?.includes(key),
|
|
1791
|
+
shouldMergeDefaultsIntoFormData
|
|
1792
|
+
});
|
|
1793
|
+
maybeAddDefaultToObject(
|
|
1794
|
+
objectDefaults,
|
|
1795
|
+
key,
|
|
1796
|
+
computedDefault,
|
|
1797
|
+
includeUndefinedValues,
|
|
1798
|
+
required,
|
|
1799
|
+
formDataRequired
|
|
1800
|
+
);
|
|
1801
|
+
});
|
|
1802
|
+
}
|
|
1803
|
+
return objectDefaults;
|
|
1804
|
+
}
|
|
1805
|
+
}
|
|
1806
|
+
function getArrayDefaults(validator, rawSchema, {
|
|
1807
|
+
rawFormData,
|
|
1808
|
+
rootSchema = {},
|
|
1809
|
+
_recurseList = [],
|
|
1810
|
+
experimental_defaultFormStateBehavior = void 0,
|
|
1811
|
+
experimental_customMergeAllOf = void 0,
|
|
1812
|
+
required,
|
|
1813
|
+
shouldMergeDefaultsIntoFormData
|
|
1814
|
+
} = {}, defaults) {
|
|
1815
|
+
const schema = rawSchema;
|
|
1816
|
+
const arrayMinItemsStateBehavior = experimental_defaultFormStateBehavior?.arrayMinItems ?? {};
|
|
1817
|
+
const { populate: arrayMinItemsPopulate, mergeExtraDefaults: arrayMergeExtraDefaults } = arrayMinItemsStateBehavior;
|
|
1818
|
+
const neverPopulate = arrayMinItemsPopulate === "never";
|
|
1819
|
+
const ignoreMinItemsFlagSet = arrayMinItemsPopulate === "requiredOnly";
|
|
1820
|
+
const isPopulateAll = arrayMinItemsPopulate === "all" || !neverPopulate && !ignoreMinItemsFlagSet;
|
|
1821
|
+
const computeSkipPopulate = arrayMinItemsStateBehavior?.computeSkipPopulate ?? (() => false);
|
|
1822
|
+
const isSkipEmptyDefaults = experimental_defaultFormStateBehavior?.emptyObjectFields === "skipEmptyDefaults";
|
|
1823
|
+
const emptyDefault = isSkipEmptyDefaults ? void 0 : [];
|
|
1824
|
+
if (Array.isArray(defaults)) {
|
|
1825
|
+
defaults = defaults.map((item, idx) => {
|
|
1826
|
+
const schemaItem = getInnerSchemaForArrayItem(schema, 2 /* Fallback */, idx);
|
|
1827
|
+
return computeDefaults(validator, schemaItem, {
|
|
1828
|
+
rootSchema,
|
|
1829
|
+
_recurseList,
|
|
1830
|
+
experimental_defaultFormStateBehavior,
|
|
1831
|
+
experimental_customMergeAllOf,
|
|
1832
|
+
parentDefaults: item,
|
|
1833
|
+
required,
|
|
1834
|
+
shouldMergeDefaultsIntoFormData
|
|
1835
|
+
});
|
|
1836
|
+
});
|
|
1837
|
+
}
|
|
1838
|
+
if (Array.isArray(rawFormData)) {
|
|
1839
|
+
const schemaItem = getInnerSchemaForArrayItem(schema);
|
|
1840
|
+
if (neverPopulate) {
|
|
1841
|
+
defaults = rawFormData;
|
|
1842
|
+
} else {
|
|
1843
|
+
const itemDefaults = rawFormData.map((item, idx) => {
|
|
1844
|
+
return computeDefaults(validator, schemaItem, {
|
|
1845
|
+
rootSchema,
|
|
1846
|
+
_recurseList,
|
|
1847
|
+
experimental_defaultFormStateBehavior,
|
|
1848
|
+
experimental_customMergeAllOf,
|
|
1849
|
+
rawFormData: item,
|
|
1850
|
+
parentDefaults: (0, import_get12.default)(defaults, [idx]),
|
|
1851
|
+
required,
|
|
1852
|
+
shouldMergeDefaultsIntoFormData
|
|
1853
|
+
});
|
|
1854
|
+
});
|
|
1855
|
+
const mergeExtraDefaults = (ignoreMinItemsFlagSet && required || isPopulateAll) && arrayMergeExtraDefaults;
|
|
1856
|
+
defaults = mergeDefaultsWithFormData(defaults, itemDefaults, mergeExtraDefaults);
|
|
1857
|
+
}
|
|
1858
|
+
}
|
|
1859
|
+
const hasConst = isObject(schema) && CONST_KEY in schema && experimental_defaultFormStateBehavior?.constAsDefaults !== "never";
|
|
1860
|
+
if (hasConst === false) {
|
|
1861
|
+
if (neverPopulate) {
|
|
1862
|
+
return defaults ?? emptyDefault;
|
|
1863
|
+
}
|
|
1864
|
+
if (ignoreMinItemsFlagSet && !required) {
|
|
1865
|
+
return defaults ? defaults : void 0;
|
|
1866
|
+
}
|
|
1867
|
+
}
|
|
1868
|
+
const defaultsLength = Array.isArray(defaults) ? defaults.length : 0;
|
|
1869
|
+
if (!schema.minItems || isMultiSelect(validator, schema, rootSchema, experimental_customMergeAllOf) || computeSkipPopulate(validator, schema, rootSchema) || schema.minItems <= defaultsLength) {
|
|
1870
|
+
return defaults ? defaults : emptyDefault;
|
|
1210
1871
|
}
|
|
1211
|
-
|
|
1872
|
+
const defaultEntries = defaults || [];
|
|
1873
|
+
const fillerSchema = getInnerSchemaForArrayItem(schema, 1 /* Invert */);
|
|
1874
|
+
const fillerDefault = fillerSchema.default;
|
|
1875
|
+
const fillerEntries = new Array(schema.minItems - defaultsLength).fill(
|
|
1876
|
+
computeDefaults(validator, fillerSchema, {
|
|
1877
|
+
parentDefaults: fillerDefault,
|
|
1878
|
+
rootSchema,
|
|
1879
|
+
_recurseList,
|
|
1880
|
+
experimental_defaultFormStateBehavior,
|
|
1881
|
+
experimental_customMergeAllOf,
|
|
1882
|
+
required,
|
|
1883
|
+
shouldMergeDefaultsIntoFormData
|
|
1884
|
+
})
|
|
1885
|
+
);
|
|
1886
|
+
return defaultEntries.concat(fillerEntries);
|
|
1887
|
+
}
|
|
1888
|
+
function getDefaultBasedOnSchemaType(validator, rawSchema, computeDefaultsProps = {}, defaults) {
|
|
1889
|
+
switch (getSchemaType(rawSchema)) {
|
|
1890
|
+
// We need to recurse for object schema inner default values.
|
|
1212
1891
|
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;
|
|
1892
|
+
return getObjectDefaults(validator, rawSchema, computeDefaultsProps, defaults);
|
|
1270
1893
|
}
|
|
1271
1894
|
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);
|
|
1895
|
+
return getArrayDefaults(validator, rawSchema, computeDefaultsProps, defaults);
|
|
1329
1896
|
}
|
|
1330
1897
|
}
|
|
1331
|
-
return defaults;
|
|
1332
1898
|
}
|
|
1333
|
-
function getDefaultFormState(validator, theSchema, formData, rootSchema, includeUndefinedValues = false, experimental_defaultFormStateBehavior) {
|
|
1899
|
+
function getDefaultFormState(validator, theSchema, formData, rootSchema, includeUndefinedValues = false, experimental_defaultFormStateBehavior, experimental_customMergeAllOf) {
|
|
1334
1900
|
if (!isObject(theSchema)) {
|
|
1335
1901
|
throw new Error("Invalid schema: " + theSchema);
|
|
1336
1902
|
}
|
|
1337
|
-
const schema = retrieveSchema(validator, theSchema, rootSchema, formData);
|
|
1903
|
+
const schema = retrieveSchema(validator, theSchema, rootSchema, formData, experimental_customMergeAllOf);
|
|
1338
1904
|
const defaults = computeDefaults(validator, schema, {
|
|
1339
1905
|
rootSchema,
|
|
1340
1906
|
includeUndefinedValues,
|
|
1341
1907
|
experimental_defaultFormStateBehavior,
|
|
1342
|
-
|
|
1908
|
+
experimental_customMergeAllOf,
|
|
1909
|
+
rawFormData: formData,
|
|
1910
|
+
shouldMergeDefaultsIntoFormData: true
|
|
1343
1911
|
});
|
|
1344
|
-
if (formData
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1912
|
+
if (isObject(formData) || Array.isArray(formData)) {
|
|
1913
|
+
const { mergeDefaultsIntoFormData } = experimental_defaultFormStateBehavior || {};
|
|
1914
|
+
const defaultSupercedesUndefined = mergeDefaultsIntoFormData === "useDefaultIfFormDataUndefined";
|
|
1915
|
+
const result = mergeDefaultsWithFormData(
|
|
1916
|
+
defaults,
|
|
1917
|
+
formData,
|
|
1918
|
+
true,
|
|
1919
|
+
// set to true to add any additional default array entries.
|
|
1920
|
+
defaultSupercedesUndefined,
|
|
1921
|
+
true
|
|
1922
|
+
// set to true to override formData with defaults if they exist.
|
|
1923
|
+
);
|
|
1924
|
+
return result;
|
|
1353
1925
|
}
|
|
1354
|
-
return
|
|
1926
|
+
return defaults;
|
|
1355
1927
|
}
|
|
1356
1928
|
|
|
1357
1929
|
// src/isCustomWidget.ts
|
|
@@ -1364,25 +1936,31 @@ function isCustomWidget(uiSchema = {}) {
|
|
|
1364
1936
|
}
|
|
1365
1937
|
|
|
1366
1938
|
// src/schema/isFilesArray.ts
|
|
1367
|
-
function isFilesArray(validator, schema, uiSchema = {}, rootSchema) {
|
|
1939
|
+
function isFilesArray(validator, schema, uiSchema = {}, rootSchema, experimental_customMergeAllOf) {
|
|
1368
1940
|
if (uiSchema[UI_WIDGET_KEY] === "files") {
|
|
1369
1941
|
return true;
|
|
1370
1942
|
}
|
|
1371
1943
|
if (schema.items) {
|
|
1372
|
-
const itemsSchema = retrieveSchema(
|
|
1944
|
+
const itemsSchema = retrieveSchema(
|
|
1945
|
+
validator,
|
|
1946
|
+
schema.items,
|
|
1947
|
+
rootSchema,
|
|
1948
|
+
void 0,
|
|
1949
|
+
experimental_customMergeAllOf
|
|
1950
|
+
);
|
|
1373
1951
|
return itemsSchema.type === "string" && itemsSchema.format === "data-url";
|
|
1374
1952
|
}
|
|
1375
1953
|
return false;
|
|
1376
1954
|
}
|
|
1377
1955
|
|
|
1378
1956
|
// src/schema/getDisplayLabel.ts
|
|
1379
|
-
function getDisplayLabel(validator, schema, uiSchema = {}, rootSchema, globalOptions) {
|
|
1957
|
+
function getDisplayLabel(validator, schema, uiSchema = {}, rootSchema, globalOptions, experimental_customMergeAllOf) {
|
|
1380
1958
|
const uiOptions = getUiOptions(uiSchema, globalOptions);
|
|
1381
1959
|
const { label = true } = uiOptions;
|
|
1382
1960
|
let displayLabel = !!label;
|
|
1383
1961
|
const schemaType = getSchemaType(schema);
|
|
1384
1962
|
if (schemaType === "array") {
|
|
1385
|
-
displayLabel = isMultiSelect(validator, schema, rootSchema) || isFilesArray(validator, schema, uiSchema, rootSchema) || isCustomWidget(uiSchema);
|
|
1963
|
+
displayLabel = isMultiSelect(validator, schema, rootSchema, experimental_customMergeAllOf) || isFilesArray(validator, schema, uiSchema, rootSchema, experimental_customMergeAllOf) || isCustomWidget(uiSchema);
|
|
1386
1964
|
}
|
|
1387
1965
|
if (schemaType === "object") {
|
|
1388
1966
|
displayLabel = false;
|
|
@@ -1396,54 +1974,50 @@ function getDisplayLabel(validator, schema, uiSchema = {}, rootSchema, globalOpt
|
|
|
1396
1974
|
return displayLabel;
|
|
1397
1975
|
}
|
|
1398
1976
|
|
|
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
1977
|
// src/schema/sanitizeDataForNewSchema.ts
|
|
1416
|
-
var
|
|
1417
|
-
var
|
|
1978
|
+
var import_get13 = __toESM(require("lodash/get"), 1);
|
|
1979
|
+
var import_has5 = __toESM(require("lodash/has"), 1);
|
|
1418
1980
|
var NO_VALUE = Symbol("no Value");
|
|
1419
|
-
function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, data = {}) {
|
|
1981
|
+
function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, data = {}, experimental_customMergeAllOf) {
|
|
1420
1982
|
let newFormData;
|
|
1421
|
-
if ((0,
|
|
1983
|
+
if ((0, import_has5.default)(newSchema, PROPERTIES_KEY)) {
|
|
1422
1984
|
const removeOldSchemaData = {};
|
|
1423
|
-
if ((0,
|
|
1424
|
-
const properties = (0,
|
|
1985
|
+
if ((0, import_has5.default)(oldSchema, PROPERTIES_KEY)) {
|
|
1986
|
+
const properties = (0, import_get13.default)(oldSchema, PROPERTIES_KEY, {});
|
|
1425
1987
|
Object.keys(properties).forEach((key) => {
|
|
1426
|
-
if ((0,
|
|
1988
|
+
if ((0, import_has5.default)(data, key)) {
|
|
1427
1989
|
removeOldSchemaData[key] = void 0;
|
|
1428
1990
|
}
|
|
1429
1991
|
});
|
|
1430
1992
|
}
|
|
1431
|
-
const
|
|
1993
|
+
const keys2 = Object.keys((0, import_get13.default)(newSchema, PROPERTIES_KEY, {}));
|
|
1432
1994
|
const nestedData = {};
|
|
1433
|
-
|
|
1434
|
-
const formValue = (0,
|
|
1435
|
-
let oldKeyedSchema = (0,
|
|
1436
|
-
let newKeyedSchema = (0,
|
|
1437
|
-
if ((0,
|
|
1438
|
-
oldKeyedSchema = retrieveSchema(
|
|
1995
|
+
keys2.forEach((key) => {
|
|
1996
|
+
const formValue = (0, import_get13.default)(data, key);
|
|
1997
|
+
let oldKeyedSchema = (0, import_get13.default)(oldSchema, [PROPERTIES_KEY, key], {});
|
|
1998
|
+
let newKeyedSchema = (0, import_get13.default)(newSchema, [PROPERTIES_KEY, key], {});
|
|
1999
|
+
if ((0, import_has5.default)(oldKeyedSchema, REF_KEY)) {
|
|
2000
|
+
oldKeyedSchema = retrieveSchema(
|
|
2001
|
+
validator,
|
|
2002
|
+
oldKeyedSchema,
|
|
2003
|
+
rootSchema,
|
|
2004
|
+
formValue,
|
|
2005
|
+
experimental_customMergeAllOf
|
|
2006
|
+
);
|
|
1439
2007
|
}
|
|
1440
|
-
if ((0,
|
|
1441
|
-
newKeyedSchema = retrieveSchema(
|
|
2008
|
+
if ((0, import_has5.default)(newKeyedSchema, REF_KEY)) {
|
|
2009
|
+
newKeyedSchema = retrieveSchema(
|
|
2010
|
+
validator,
|
|
2011
|
+
newKeyedSchema,
|
|
2012
|
+
rootSchema,
|
|
2013
|
+
formValue,
|
|
2014
|
+
experimental_customMergeAllOf
|
|
2015
|
+
);
|
|
1442
2016
|
}
|
|
1443
|
-
const oldSchemaTypeForKey = (0,
|
|
1444
|
-
const newSchemaTypeForKey = (0,
|
|
2017
|
+
const oldSchemaTypeForKey = (0, import_get13.default)(oldKeyedSchema, "type");
|
|
2018
|
+
const newSchemaTypeForKey = (0, import_get13.default)(newKeyedSchema, "type");
|
|
1445
2019
|
if (!oldSchemaTypeForKey || oldSchemaTypeForKey === newSchemaTypeForKey) {
|
|
1446
|
-
if ((0,
|
|
2020
|
+
if ((0, import_has5.default)(removeOldSchemaData, key)) {
|
|
1447
2021
|
delete removeOldSchemaData[key];
|
|
1448
2022
|
}
|
|
1449
2023
|
if (newSchemaTypeForKey === "object" || newSchemaTypeForKey === "array" && Array.isArray(formValue)) {
|
|
@@ -1452,23 +2026,24 @@ function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, d
|
|
|
1452
2026
|
rootSchema,
|
|
1453
2027
|
newKeyedSchema,
|
|
1454
2028
|
oldKeyedSchema,
|
|
1455
|
-
formValue
|
|
2029
|
+
formValue,
|
|
2030
|
+
experimental_customMergeAllOf
|
|
1456
2031
|
);
|
|
1457
2032
|
if (itemData !== void 0 || newSchemaTypeForKey === "array") {
|
|
1458
2033
|
nestedData[key] = itemData;
|
|
1459
2034
|
}
|
|
1460
2035
|
} else {
|
|
1461
|
-
const newOptionDefault = (0,
|
|
1462
|
-
const oldOptionDefault = (0,
|
|
2036
|
+
const newOptionDefault = (0, import_get13.default)(newKeyedSchema, "default", NO_VALUE);
|
|
2037
|
+
const oldOptionDefault = (0, import_get13.default)(oldKeyedSchema, "default", NO_VALUE);
|
|
1463
2038
|
if (newOptionDefault !== NO_VALUE && newOptionDefault !== formValue) {
|
|
1464
2039
|
if (oldOptionDefault === formValue) {
|
|
1465
2040
|
removeOldSchemaData[key] = newOptionDefault;
|
|
1466
|
-
} else if ((0,
|
|
2041
|
+
} else if ((0, import_get13.default)(newKeyedSchema, "readOnly") === true) {
|
|
1467
2042
|
removeOldSchemaData[key] = void 0;
|
|
1468
2043
|
}
|
|
1469
2044
|
}
|
|
1470
|
-
const newOptionConst = (0,
|
|
1471
|
-
const oldOptionConst = (0,
|
|
2045
|
+
const newOptionConst = (0, import_get13.default)(newKeyedSchema, "const", NO_VALUE);
|
|
2046
|
+
const oldOptionConst = (0, import_get13.default)(oldKeyedSchema, "const", NO_VALUE);
|
|
1472
2047
|
if (newOptionConst !== NO_VALUE && newOptionConst !== formValue) {
|
|
1473
2048
|
removeOldSchemaData[key] = oldOptionConst === formValue ? newOptionConst : void 0;
|
|
1474
2049
|
}
|
|
@@ -1480,20 +2055,32 @@ function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, d
|
|
|
1480
2055
|
...removeOldSchemaData,
|
|
1481
2056
|
...nestedData
|
|
1482
2057
|
};
|
|
1483
|
-
} else if ((0,
|
|
1484
|
-
let oldSchemaItems = (0,
|
|
1485
|
-
let newSchemaItems = (0,
|
|
2058
|
+
} else if ((0, import_get13.default)(oldSchema, "type") === "array" && (0, import_get13.default)(newSchema, "type") === "array" && Array.isArray(data)) {
|
|
2059
|
+
let oldSchemaItems = (0, import_get13.default)(oldSchema, "items");
|
|
2060
|
+
let newSchemaItems = (0, import_get13.default)(newSchema, "items");
|
|
1486
2061
|
if (typeof oldSchemaItems === "object" && typeof newSchemaItems === "object" && !Array.isArray(oldSchemaItems) && !Array.isArray(newSchemaItems)) {
|
|
1487
|
-
if ((0,
|
|
1488
|
-
oldSchemaItems = retrieveSchema(
|
|
2062
|
+
if ((0, import_has5.default)(oldSchemaItems, REF_KEY)) {
|
|
2063
|
+
oldSchemaItems = retrieveSchema(
|
|
2064
|
+
validator,
|
|
2065
|
+
oldSchemaItems,
|
|
2066
|
+
rootSchema,
|
|
2067
|
+
data,
|
|
2068
|
+
experimental_customMergeAllOf
|
|
2069
|
+
);
|
|
1489
2070
|
}
|
|
1490
|
-
if ((0,
|
|
1491
|
-
newSchemaItems = retrieveSchema(
|
|
2071
|
+
if ((0, import_has5.default)(newSchemaItems, REF_KEY)) {
|
|
2072
|
+
newSchemaItems = retrieveSchema(
|
|
2073
|
+
validator,
|
|
2074
|
+
newSchemaItems,
|
|
2075
|
+
rootSchema,
|
|
2076
|
+
data,
|
|
2077
|
+
experimental_customMergeAllOf
|
|
2078
|
+
);
|
|
1492
2079
|
}
|
|
1493
|
-
const oldSchemaType = (0,
|
|
1494
|
-
const newSchemaType = (0,
|
|
2080
|
+
const oldSchemaType = (0, import_get13.default)(oldSchemaItems, "type");
|
|
2081
|
+
const newSchemaType = (0, import_get13.default)(newSchemaItems, "type");
|
|
1495
2082
|
if (!oldSchemaType || oldSchemaType === newSchemaType) {
|
|
1496
|
-
const maxItems = (0,
|
|
2083
|
+
const maxItems = (0, import_get13.default)(newSchema, "maxItems", -1);
|
|
1497
2084
|
if (newSchemaType === "object") {
|
|
1498
2085
|
newFormData = data.reduce((newValue, aValue) => {
|
|
1499
2086
|
const itemValue = sanitizeDataForNewSchema(
|
|
@@ -1501,7 +2088,8 @@ function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, d
|
|
|
1501
2088
|
rootSchema,
|
|
1502
2089
|
newSchemaItems,
|
|
1503
2090
|
oldSchemaItems,
|
|
1504
|
-
aValue
|
|
2091
|
+
aValue,
|
|
2092
|
+
experimental_customMergeAllOf
|
|
1505
2093
|
);
|
|
1506
2094
|
if (itemValue !== void 0 && (maxItems < 0 || newValue.length < maxItems)) {
|
|
1507
2095
|
newValue.push(itemValue);
|
|
@@ -1520,71 +2108,84 @@ function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, d
|
|
|
1520
2108
|
}
|
|
1521
2109
|
|
|
1522
2110
|
// src/schema/toIdSchema.ts
|
|
1523
|
-
var
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
2111
|
+
var import_get14 = __toESM(require("lodash/get"), 1);
|
|
2112
|
+
function toIdSchemaInternal(validator, schema, idPrefix, idSeparator, id, rootSchema, formData, _recurseList = [], experimental_customMergeAllOf) {
|
|
2113
|
+
const $id = id || idPrefix;
|
|
2114
|
+
const idSchema = { $id };
|
|
2115
|
+
if (typeof schema === "object") {
|
|
2116
|
+
if (REF_KEY in schema || DEPENDENCIES_KEY in schema || ALL_OF_KEY in schema) {
|
|
2117
|
+
const _schema = retrieveSchema(validator, schema, rootSchema, formData, experimental_customMergeAllOf);
|
|
2118
|
+
const sameSchemaIndex = _recurseList.findIndex((item) => deepEquals(item, _schema));
|
|
2119
|
+
if (sameSchemaIndex === -1) {
|
|
2120
|
+
return toIdSchemaInternal(
|
|
2121
|
+
validator,
|
|
2122
|
+
_schema,
|
|
2123
|
+
idPrefix,
|
|
2124
|
+
idSeparator,
|
|
2125
|
+
id,
|
|
2126
|
+
rootSchema,
|
|
2127
|
+
formData,
|
|
2128
|
+
_recurseList.concat(_schema),
|
|
2129
|
+
experimental_customMergeAllOf
|
|
2130
|
+
);
|
|
2131
|
+
}
|
|
2132
|
+
}
|
|
2133
|
+
if (ITEMS_KEY in schema && !(0, import_get14.default)(schema, [ITEMS_KEY, REF_KEY])) {
|
|
1530
2134
|
return toIdSchemaInternal(
|
|
1531
2135
|
validator,
|
|
1532
|
-
|
|
2136
|
+
(0, import_get14.default)(schema, ITEMS_KEY),
|
|
1533
2137
|
idPrefix,
|
|
1534
2138
|
idSeparator,
|
|
1535
2139
|
id,
|
|
1536
2140
|
rootSchema,
|
|
1537
2141
|
formData,
|
|
1538
|
-
_recurseList
|
|
2142
|
+
_recurseList,
|
|
2143
|
+
experimental_customMergeAllOf
|
|
1539
2144
|
);
|
|
1540
2145
|
}
|
|
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
|
-
);
|
|
2146
|
+
if (getSchemaType(schema) === "object" && PROPERTIES_KEY in schema) {
|
|
2147
|
+
for (const name in schema.properties) {
|
|
2148
|
+
const field = schema[PROPERTIES_KEY][name];
|
|
2149
|
+
const fieldId = idSchema[ID_KEY] + idSeparator + name;
|
|
2150
|
+
idSchema[name] = toIdSchemaInternal(
|
|
2151
|
+
validator,
|
|
2152
|
+
field,
|
|
2153
|
+
idPrefix,
|
|
2154
|
+
idSeparator,
|
|
2155
|
+
fieldId,
|
|
2156
|
+
rootSchema,
|
|
2157
|
+
// It's possible that formData is not an object -- this can happen if an
|
|
2158
|
+
// array item has just been added, but not populated with data yet
|
|
2159
|
+
(0, import_get14.default)(formData, [name]),
|
|
2160
|
+
_recurseList,
|
|
2161
|
+
experimental_customMergeAllOf
|
|
2162
|
+
);
|
|
2163
|
+
}
|
|
1572
2164
|
}
|
|
1573
2165
|
}
|
|
1574
2166
|
return idSchema;
|
|
1575
2167
|
}
|
|
1576
|
-
function toIdSchema(validator, schema, id, rootSchema, formData, idPrefix = "root", idSeparator = "_") {
|
|
1577
|
-
return toIdSchemaInternal(
|
|
2168
|
+
function toIdSchema(validator, schema, id, rootSchema, formData, idPrefix = "root", idSeparator = "_", experimental_customMergeAllOf) {
|
|
2169
|
+
return toIdSchemaInternal(
|
|
2170
|
+
validator,
|
|
2171
|
+
schema,
|
|
2172
|
+
idPrefix,
|
|
2173
|
+
idSeparator,
|
|
2174
|
+
id,
|
|
2175
|
+
rootSchema,
|
|
2176
|
+
formData,
|
|
2177
|
+
void 0,
|
|
2178
|
+
experimental_customMergeAllOf
|
|
2179
|
+
);
|
|
1578
2180
|
}
|
|
1579
2181
|
|
|
1580
2182
|
// src/schema/toPathSchema.ts
|
|
1581
|
-
var
|
|
1582
|
-
var
|
|
1583
|
-
|
|
1584
|
-
function toPathSchemaInternal(validator, schema, name, rootSchema, formData, _recurseList = []) {
|
|
2183
|
+
var import_get15 = __toESM(require("lodash/get"), 1);
|
|
2184
|
+
var import_set2 = __toESM(require("lodash/set"), 1);
|
|
2185
|
+
function toPathSchemaInternal(validator, schema, name, rootSchema, formData, _recurseList = [], experimental_customMergeAllOf) {
|
|
1585
2186
|
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) => (
|
|
2187
|
+
const _schema = retrieveSchema(validator, schema, rootSchema, formData, experimental_customMergeAllOf);
|
|
2188
|
+
const sameSchemaIndex = _recurseList.findIndex((item) => deepEquals(item, _schema));
|
|
1588
2189
|
if (sameSchemaIndex === -1) {
|
|
1589
2190
|
return toPathSchemaInternal(
|
|
1590
2191
|
validator,
|
|
@@ -1592,7 +2193,8 @@ function toPathSchemaInternal(validator, schema, name, rootSchema, formData, _re
|
|
|
1592
2193
|
name,
|
|
1593
2194
|
rootSchema,
|
|
1594
2195
|
formData,
|
|
1595
|
-
_recurseList.concat(_schema)
|
|
2196
|
+
_recurseList.concat(_schema),
|
|
2197
|
+
experimental_customMergeAllOf
|
|
1596
2198
|
);
|
|
1597
2199
|
}
|
|
1598
2200
|
}
|
|
@@ -1602,11 +2204,27 @@ function toPathSchemaInternal(validator, schema, name, rootSchema, formData, _re
|
|
|
1602
2204
|
if (ONE_OF_KEY in schema || ANY_OF_KEY in schema) {
|
|
1603
2205
|
const xxxOf = ONE_OF_KEY in schema ? schema.oneOf : schema.anyOf;
|
|
1604
2206
|
const discriminator = getDiscriminatorFieldFromSchema(schema);
|
|
1605
|
-
const index = getClosestMatchingOption(
|
|
2207
|
+
const index = getClosestMatchingOption(
|
|
2208
|
+
validator,
|
|
2209
|
+
rootSchema,
|
|
2210
|
+
formData,
|
|
2211
|
+
xxxOf,
|
|
2212
|
+
0,
|
|
2213
|
+
discriminator,
|
|
2214
|
+
experimental_customMergeAllOf
|
|
2215
|
+
);
|
|
1606
2216
|
const _schema = xxxOf[index];
|
|
1607
2217
|
pathSchema = {
|
|
1608
2218
|
...pathSchema,
|
|
1609
|
-
...toPathSchemaInternal(
|
|
2219
|
+
...toPathSchemaInternal(
|
|
2220
|
+
validator,
|
|
2221
|
+
_schema,
|
|
2222
|
+
name,
|
|
2223
|
+
rootSchema,
|
|
2224
|
+
formData,
|
|
2225
|
+
_recurseList,
|
|
2226
|
+
experimental_customMergeAllOf
|
|
2227
|
+
)
|
|
1610
2228
|
};
|
|
1611
2229
|
}
|
|
1612
2230
|
if (ADDITIONAL_PROPERTIES_KEY in schema && schema[ADDITIONAL_PROPERTIES_KEY] !== false) {
|
|
@@ -1623,7 +2241,8 @@ function toPathSchemaInternal(validator, schema, name, rootSchema, formData, _re
|
|
|
1623
2241
|
`${name}.${i}`,
|
|
1624
2242
|
rootSchema,
|
|
1625
2243
|
element,
|
|
1626
|
-
_recurseList
|
|
2244
|
+
_recurseList,
|
|
2245
|
+
experimental_customMergeAllOf
|
|
1627
2246
|
);
|
|
1628
2247
|
} else if (schemaAdditionalItems) {
|
|
1629
2248
|
pathSchema[i] = toPathSchemaInternal(
|
|
@@ -1632,7 +2251,8 @@ function toPathSchemaInternal(validator, schema, name, rootSchema, formData, _re
|
|
|
1632
2251
|
`${name}.${i}`,
|
|
1633
2252
|
rootSchema,
|
|
1634
2253
|
element,
|
|
1635
|
-
_recurseList
|
|
2254
|
+
_recurseList,
|
|
2255
|
+
experimental_customMergeAllOf
|
|
1636
2256
|
);
|
|
1637
2257
|
} else {
|
|
1638
2258
|
console.warn(`Unable to generate path schema for "${name}.${i}". No schema defined for it`);
|
|
@@ -1646,13 +2266,14 @@ function toPathSchemaInternal(validator, schema, name, rootSchema, formData, _re
|
|
|
1646
2266
|
`${name}.${i}`,
|
|
1647
2267
|
rootSchema,
|
|
1648
2268
|
element,
|
|
1649
|
-
_recurseList
|
|
2269
|
+
_recurseList,
|
|
2270
|
+
experimental_customMergeAllOf
|
|
1650
2271
|
);
|
|
1651
2272
|
});
|
|
1652
2273
|
}
|
|
1653
2274
|
} else if (PROPERTIES_KEY in schema) {
|
|
1654
2275
|
for (const property in schema.properties) {
|
|
1655
|
-
const field = (0,
|
|
2276
|
+
const field = (0, import_get15.default)(schema, [PROPERTIES_KEY, property], {});
|
|
1656
2277
|
pathSchema[property] = toPathSchemaInternal(
|
|
1657
2278
|
validator,
|
|
1658
2279
|
field,
|
|
@@ -1660,15 +2281,16 @@ function toPathSchemaInternal(validator, schema, name, rootSchema, formData, _re
|
|
|
1660
2281
|
rootSchema,
|
|
1661
2282
|
// It's possible that formData is not an object -- this can happen if an
|
|
1662
2283
|
// array item has just been added, but not populated with data yet
|
|
1663
|
-
(0,
|
|
1664
|
-
_recurseList
|
|
2284
|
+
(0, import_get15.default)(formData, [property]),
|
|
2285
|
+
_recurseList,
|
|
2286
|
+
experimental_customMergeAllOf
|
|
1665
2287
|
);
|
|
1666
2288
|
}
|
|
1667
2289
|
}
|
|
1668
2290
|
return pathSchema;
|
|
1669
2291
|
}
|
|
1670
|
-
function toPathSchema(validator, schema, name = "", rootSchema, formData) {
|
|
1671
|
-
return toPathSchemaInternal(validator, schema, name, rootSchema, formData);
|
|
2292
|
+
function toPathSchema(validator, schema, name = "", rootSchema, formData, experimental_customMergeAllOf) {
|
|
2293
|
+
return toPathSchemaInternal(validator, schema, name, rootSchema, formData, void 0, experimental_customMergeAllOf);
|
|
1672
2294
|
}
|
|
1673
2295
|
|
|
1674
2296
|
// src/createSchemaUtils.ts
|
|
@@ -1678,11 +2300,13 @@ var SchemaUtils = class {
|
|
|
1678
2300
|
* @param validator - An implementation of the `ValidatorType` interface that will be forwarded to all the APIs
|
|
1679
2301
|
* @param rootSchema - The root schema that will be forwarded to all the APIs
|
|
1680
2302
|
* @param experimental_defaultFormStateBehavior - Configuration flags to allow users to override default form state behavior
|
|
2303
|
+
* @param [experimental_customMergeAllOf] - Optional function that allows for custom merging of `allOf` schemas
|
|
1681
2304
|
*/
|
|
1682
|
-
constructor(validator, rootSchema, experimental_defaultFormStateBehavior) {
|
|
2305
|
+
constructor(validator, rootSchema, experimental_defaultFormStateBehavior, experimental_customMergeAllOf) {
|
|
1683
2306
|
this.rootSchema = rootSchema;
|
|
1684
2307
|
this.validator = validator;
|
|
1685
2308
|
this.experimental_defaultFormStateBehavior = experimental_defaultFormStateBehavior;
|
|
2309
|
+
this.experimental_customMergeAllOf = experimental_customMergeAllOf;
|
|
1686
2310
|
}
|
|
1687
2311
|
/** Returns the `ValidatorType` in the `SchemaUtilsType`
|
|
1688
2312
|
*
|
|
@@ -1698,13 +2322,55 @@ var SchemaUtils = class {
|
|
|
1698
2322
|
* @param validator - An implementation of the `ValidatorType` interface that will be compared against the current one
|
|
1699
2323
|
* @param rootSchema - The root schema that will be compared against the current one
|
|
1700
2324
|
* @param [experimental_defaultFormStateBehavior] Optional configuration object, if provided, allows users to override default form state behavior
|
|
2325
|
+
* @param [experimental_customMergeAllOf] - Optional function that allows for custom merging of `allOf` schemas
|
|
1701
2326
|
* @returns - True if the `SchemaUtilsType` differs from the given `validator` or `rootSchema`
|
|
1702
2327
|
*/
|
|
1703
|
-
doesSchemaUtilsDiffer(validator, rootSchema, experimental_defaultFormStateBehavior = {}) {
|
|
2328
|
+
doesSchemaUtilsDiffer(validator, rootSchema, experimental_defaultFormStateBehavior = {}, experimental_customMergeAllOf) {
|
|
1704
2329
|
if (!validator || !rootSchema) {
|
|
1705
2330
|
return false;
|
|
1706
2331
|
}
|
|
1707
|
-
return this.validator !== validator || !deepEquals(this.rootSchema, rootSchema) || !deepEquals(this.experimental_defaultFormStateBehavior, experimental_defaultFormStateBehavior);
|
|
2332
|
+
return this.validator !== validator || !deepEquals(this.rootSchema, rootSchema) || !deepEquals(this.experimental_defaultFormStateBehavior, experimental_defaultFormStateBehavior) || this.experimental_customMergeAllOf !== experimental_customMergeAllOf;
|
|
2333
|
+
}
|
|
2334
|
+
/** Finds the field specified by the `path` within the root or recursed `schema`. If there is no field for the specified
|
|
2335
|
+
* `path`, then the default `{ field: undefined, isRequired: undefined }` is returned. It determines whether a leaf
|
|
2336
|
+
* field is in the `required` list for its parent and if so, it is marked as required on return.
|
|
2337
|
+
*
|
|
2338
|
+
* @param schema - The current node within the JSON schema
|
|
2339
|
+
* @param path - The remaining keys in the path to the desired field
|
|
2340
|
+
* @param [formData] - The form data that is used to determine which oneOf option
|
|
2341
|
+
* @returns - An object that contains the field and its required state. If no field can be found then
|
|
2342
|
+
* `{ field: undefined, isRequired: undefined }` is returned.
|
|
2343
|
+
*/
|
|
2344
|
+
findFieldInSchema(schema, path, formData) {
|
|
2345
|
+
return findFieldInSchema(
|
|
2346
|
+
this.validator,
|
|
2347
|
+
this.rootSchema,
|
|
2348
|
+
schema,
|
|
2349
|
+
path,
|
|
2350
|
+
formData,
|
|
2351
|
+
this.experimental_customMergeAllOf
|
|
2352
|
+
);
|
|
2353
|
+
}
|
|
2354
|
+
/** Finds the oneOf option inside the `schema['any/oneOf']` list which has the `properties[selectorField].default` that
|
|
2355
|
+
* matches the `formData[selectorField]` value. For the purposes of this function, `selectorField` is either
|
|
2356
|
+
* `schema.discriminator.propertyName` or `fallbackField`.
|
|
2357
|
+
*
|
|
2358
|
+
* @param schema - The schema element in which to search for the selected oneOf option
|
|
2359
|
+
* @param fallbackField - The field to use as a backup selector field if the schema does not have a required field
|
|
2360
|
+
* @param xxx - Either `oneOf` or `anyOf`, defines which value is being sought
|
|
2361
|
+
* @param [formData={}] - The form data that is used to determine which oneOf option
|
|
2362
|
+
* @returns - The anyOf/oneOf option that matches the selector field in the schema or undefined if nothing is selected
|
|
2363
|
+
*/
|
|
2364
|
+
findSelectedOptionInXxxOf(schema, fallbackField, xxx, formData) {
|
|
2365
|
+
return findSelectedOptionInXxxOf(
|
|
2366
|
+
this.validator,
|
|
2367
|
+
this.rootSchema,
|
|
2368
|
+
schema,
|
|
2369
|
+
fallbackField,
|
|
2370
|
+
xxx,
|
|
2371
|
+
formData,
|
|
2372
|
+
this.experimental_customMergeAllOf
|
|
2373
|
+
);
|
|
1708
2374
|
}
|
|
1709
2375
|
/** Returns the superset of `formData` that includes the given set updated to include any missing fields that have
|
|
1710
2376
|
* computed to have defaults provided in the `schema`.
|
|
@@ -1723,7 +2389,8 @@ var SchemaUtils = class {
|
|
|
1723
2389
|
formData,
|
|
1724
2390
|
this.rootSchema,
|
|
1725
2391
|
includeUndefinedValues,
|
|
1726
|
-
this.experimental_defaultFormStateBehavior
|
|
2392
|
+
this.experimental_defaultFormStateBehavior,
|
|
2393
|
+
this.experimental_customMergeAllOf
|
|
1727
2394
|
);
|
|
1728
2395
|
}
|
|
1729
2396
|
/** Determines whether the combination of `schema` and `uiSchema` properties indicates that the label for the `schema`
|
|
@@ -1735,7 +2402,14 @@ var SchemaUtils = class {
|
|
|
1735
2402
|
* @returns - True if the label should be displayed or false if it should not
|
|
1736
2403
|
*/
|
|
1737
2404
|
getDisplayLabel(schema, uiSchema, globalOptions) {
|
|
1738
|
-
return getDisplayLabel(
|
|
2405
|
+
return getDisplayLabel(
|
|
2406
|
+
this.validator,
|
|
2407
|
+
schema,
|
|
2408
|
+
uiSchema,
|
|
2409
|
+
this.rootSchema,
|
|
2410
|
+
globalOptions,
|
|
2411
|
+
this.experimental_customMergeAllOf
|
|
2412
|
+
);
|
|
1739
2413
|
}
|
|
1740
2414
|
/** Determines which of the given `options` provided most closely matches the `formData`.
|
|
1741
2415
|
* Returns the index of the option that is valid and is the closest match, or 0 if there is no match.
|
|
@@ -1757,7 +2431,8 @@ var SchemaUtils = class {
|
|
|
1757
2431
|
formData,
|
|
1758
2432
|
options,
|
|
1759
2433
|
selectedOption,
|
|
1760
|
-
discriminatorField
|
|
2434
|
+
discriminatorField,
|
|
2435
|
+
this.experimental_customMergeAllOf
|
|
1761
2436
|
);
|
|
1762
2437
|
}
|
|
1763
2438
|
/** Given the `formData` and list of `options`, attempts to find the index of the first option that matches the data.
|
|
@@ -1772,18 +2447,16 @@ var SchemaUtils = class {
|
|
|
1772
2447
|
getFirstMatchingOption(formData, options, discriminatorField) {
|
|
1773
2448
|
return getFirstMatchingOption(this.validator, formData, options, this.rootSchema, discriminatorField);
|
|
1774
2449
|
}
|
|
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);
|
|
2450
|
+
getFromSchema(schema, path, defaultValue) {
|
|
2451
|
+
return getFromSchema(
|
|
2452
|
+
this.validator,
|
|
2453
|
+
this.rootSchema,
|
|
2454
|
+
schema,
|
|
2455
|
+
path,
|
|
2456
|
+
// @ts-expect-error TS2769: No overload matches this call
|
|
2457
|
+
defaultValue,
|
|
2458
|
+
this.experimental_customMergeAllOf
|
|
2459
|
+
);
|
|
1787
2460
|
}
|
|
1788
2461
|
/** Checks to see if the `schema` and `uiSchema` combination represents an array of files
|
|
1789
2462
|
*
|
|
@@ -1792,7 +2465,7 @@ var SchemaUtils = class {
|
|
|
1792
2465
|
* @returns - True if schema/uiSchema contains an array of files, otherwise false
|
|
1793
2466
|
*/
|
|
1794
2467
|
isFilesArray(schema, uiSchema) {
|
|
1795
|
-
return isFilesArray(this.validator, schema, uiSchema, this.rootSchema);
|
|
2468
|
+
return isFilesArray(this.validator, schema, uiSchema, this.rootSchema, this.experimental_customMergeAllOf);
|
|
1796
2469
|
}
|
|
1797
2470
|
/** Checks to see if the `schema` combination represents a multi-select
|
|
1798
2471
|
*
|
|
@@ -1800,7 +2473,7 @@ var SchemaUtils = class {
|
|
|
1800
2473
|
* @returns - True if schema contains a multi-select, otherwise false
|
|
1801
2474
|
*/
|
|
1802
2475
|
isMultiSelect(schema) {
|
|
1803
|
-
return isMultiSelect(this.validator, schema, this.rootSchema);
|
|
2476
|
+
return isMultiSelect(this.validator, schema, this.rootSchema, this.experimental_customMergeAllOf);
|
|
1804
2477
|
}
|
|
1805
2478
|
/** Checks to see if the `schema` combination represents a select
|
|
1806
2479
|
*
|
|
@@ -1808,21 +2481,7 @@ var SchemaUtils = class {
|
|
|
1808
2481
|
* @returns - True if schema contains a select, otherwise false
|
|
1809
2482
|
*/
|
|
1810
2483
|
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);
|
|
2484
|
+
return isSelect(this.validator, schema, this.rootSchema, this.experimental_customMergeAllOf);
|
|
1826
2485
|
}
|
|
1827
2486
|
/** Retrieves an expanded schema that has had all of its conditions, additional properties, references and
|
|
1828
2487
|
* dependencies resolved and merged into the `schema` given a `rawFormData` that is used to do the potentially
|
|
@@ -1833,7 +2492,13 @@ var SchemaUtils = class {
|
|
|
1833
2492
|
* @returns - The schema having its conditions, additional properties, references and dependencies resolved
|
|
1834
2493
|
*/
|
|
1835
2494
|
retrieveSchema(schema, rawFormData) {
|
|
1836
|
-
return retrieveSchema(
|
|
2495
|
+
return retrieveSchema(
|
|
2496
|
+
this.validator,
|
|
2497
|
+
schema,
|
|
2498
|
+
this.rootSchema,
|
|
2499
|
+
rawFormData,
|
|
2500
|
+
this.experimental_customMergeAllOf
|
|
2501
|
+
);
|
|
1837
2502
|
}
|
|
1838
2503
|
/** Sanitize the `data` associated with the `oldSchema` so it is considered appropriate for the `newSchema`. If the
|
|
1839
2504
|
* new schema does not contain any properties, then `undefined` is returned to clear all the form data. Due to the
|
|
@@ -1847,7 +2512,14 @@ var SchemaUtils = class {
|
|
|
1847
2512
|
* to `undefined`. Will return `undefined` if the new schema is not an object containing properties.
|
|
1848
2513
|
*/
|
|
1849
2514
|
sanitizeDataForNewSchema(newSchema, oldSchema, data) {
|
|
1850
|
-
return sanitizeDataForNewSchema(
|
|
2515
|
+
return sanitizeDataForNewSchema(
|
|
2516
|
+
this.validator,
|
|
2517
|
+
this.rootSchema,
|
|
2518
|
+
newSchema,
|
|
2519
|
+
oldSchema,
|
|
2520
|
+
data,
|
|
2521
|
+
this.experimental_customMergeAllOf
|
|
2522
|
+
);
|
|
1851
2523
|
}
|
|
1852
2524
|
/** Generates an `IdSchema` object for the `schema`, recursively
|
|
1853
2525
|
*
|
|
@@ -1859,7 +2531,16 @@ var SchemaUtils = class {
|
|
|
1859
2531
|
* @returns - The `IdSchema` object for the `schema`
|
|
1860
2532
|
*/
|
|
1861
2533
|
toIdSchema(schema, id, formData, idPrefix = "root", idSeparator = "_") {
|
|
1862
|
-
return toIdSchema(
|
|
2534
|
+
return toIdSchema(
|
|
2535
|
+
this.validator,
|
|
2536
|
+
schema,
|
|
2537
|
+
id,
|
|
2538
|
+
this.rootSchema,
|
|
2539
|
+
formData,
|
|
2540
|
+
idPrefix,
|
|
2541
|
+
idSeparator,
|
|
2542
|
+
this.experimental_customMergeAllOf
|
|
2543
|
+
);
|
|
1863
2544
|
}
|
|
1864
2545
|
/** Generates an `PathSchema` object for the `schema`, recursively
|
|
1865
2546
|
*
|
|
@@ -1869,11 +2550,23 @@ var SchemaUtils = class {
|
|
|
1869
2550
|
* @returns - The `PathSchema` object for the `schema`
|
|
1870
2551
|
*/
|
|
1871
2552
|
toPathSchema(schema, name, formData) {
|
|
1872
|
-
return toPathSchema(
|
|
2553
|
+
return toPathSchema(
|
|
2554
|
+
this.validator,
|
|
2555
|
+
schema,
|
|
2556
|
+
name,
|
|
2557
|
+
this.rootSchema,
|
|
2558
|
+
formData,
|
|
2559
|
+
this.experimental_customMergeAllOf
|
|
2560
|
+
);
|
|
1873
2561
|
}
|
|
1874
2562
|
};
|
|
1875
|
-
function createSchemaUtils(validator, rootSchema, experimental_defaultFormStateBehavior = {}) {
|
|
1876
|
-
return new SchemaUtils(
|
|
2563
|
+
function createSchemaUtils(validator, rootSchema, experimental_defaultFormStateBehavior = {}, experimental_customMergeAllOf) {
|
|
2564
|
+
return new SchemaUtils(
|
|
2565
|
+
validator,
|
|
2566
|
+
rootSchema,
|
|
2567
|
+
experimental_defaultFormStateBehavior,
|
|
2568
|
+
experimental_customMergeAllOf
|
|
2569
|
+
);
|
|
1877
2570
|
}
|
|
1878
2571
|
|
|
1879
2572
|
// src/dataURItoBlob.ts
|
|
@@ -1955,9 +2648,6 @@ function englishStringTranslator(stringToTranslate, params) {
|
|
|
1955
2648
|
return replaceStringParameters(stringToTranslate, params);
|
|
1956
2649
|
}
|
|
1957
2650
|
|
|
1958
|
-
// src/enumOptionsDeselectValue.ts
|
|
1959
|
-
var import_isEqual4 = __toESM(require("lodash/isEqual"));
|
|
1960
|
-
|
|
1961
2651
|
// src/enumOptionsValueForIndex.ts
|
|
1962
2652
|
function enumOptionsValueForIndex(valueIndex, allEnumOptions = [], emptyValue) {
|
|
1963
2653
|
if (Array.isArray(valueIndex)) {
|
|
@@ -1972,18 +2662,17 @@ function enumOptionsValueForIndex(valueIndex, allEnumOptions = [], emptyValue) {
|
|
|
1972
2662
|
function enumOptionsDeselectValue(valueIndex, selected, allEnumOptions = []) {
|
|
1973
2663
|
const value = enumOptionsValueForIndex(valueIndex, allEnumOptions);
|
|
1974
2664
|
if (Array.isArray(selected)) {
|
|
1975
|
-
return selected.filter((v) => !(
|
|
2665
|
+
return selected.filter((v) => !deepEquals(v, value));
|
|
1976
2666
|
}
|
|
1977
|
-
return (
|
|
2667
|
+
return deepEquals(value, selected) ? void 0 : selected;
|
|
1978
2668
|
}
|
|
1979
2669
|
|
|
1980
2670
|
// src/enumOptionsIsSelected.ts
|
|
1981
|
-
var import_isEqual5 = __toESM(require("lodash/isEqual"));
|
|
1982
2671
|
function enumOptionsIsSelected(value, selected) {
|
|
1983
2672
|
if (Array.isArray(selected)) {
|
|
1984
|
-
return selected.some((sel) => (
|
|
2673
|
+
return selected.some((sel) => deepEquals(sel, value));
|
|
1985
2674
|
}
|
|
1986
|
-
return (
|
|
2675
|
+
return deepEquals(selected, value);
|
|
1987
2676
|
}
|
|
1988
2677
|
|
|
1989
2678
|
// src/enumOptionsIndexForValue.ts
|
|
@@ -1996,10 +2685,10 @@ function enumOptionsIndexForValue(value, allEnumOptions = [], multiple = false)
|
|
|
1996
2685
|
}
|
|
1997
2686
|
|
|
1998
2687
|
// src/enumOptionsSelectValue.ts
|
|
1999
|
-
var
|
|
2688
|
+
var import_isNil2 = __toESM(require("lodash/isNil"), 1);
|
|
2000
2689
|
function enumOptionsSelectValue(valueIndex, selected, allEnumOptions = []) {
|
|
2001
2690
|
const value = enumOptionsValueForIndex(valueIndex, allEnumOptions);
|
|
2002
|
-
if (!(0,
|
|
2691
|
+
if (!(0, import_isNil2.default)(value)) {
|
|
2003
2692
|
const index = allEnumOptions.findIndex((opt) => value === opt.value);
|
|
2004
2693
|
const all = allEnumOptions.map(({ value: val }) => val);
|
|
2005
2694
|
const updated = selected.slice(0, index).concat(value, selected.slice(index));
|
|
@@ -2009,9 +2698,10 @@ function enumOptionsSelectValue(valueIndex, selected, allEnumOptions = []) {
|
|
|
2009
2698
|
}
|
|
2010
2699
|
|
|
2011
2700
|
// src/ErrorSchemaBuilder.ts
|
|
2012
|
-
var import_cloneDeep = __toESM(require("lodash/cloneDeep"));
|
|
2013
|
-
var
|
|
2014
|
-
var import_set3 = __toESM(require("lodash/set"));
|
|
2701
|
+
var import_cloneDeep = __toESM(require("lodash/cloneDeep"), 1);
|
|
2702
|
+
var import_get16 = __toESM(require("lodash/get"), 1);
|
|
2703
|
+
var import_set3 = __toESM(require("lodash/set"), 1);
|
|
2704
|
+
var import_setWith = __toESM(require("lodash/setWith"), 1);
|
|
2015
2705
|
var ErrorSchemaBuilder = class {
|
|
2016
2706
|
/** Construct an `ErrorSchemaBuilder` with an optional initial set of errors in an `ErrorSchema`.
|
|
2017
2707
|
*
|
|
@@ -2038,10 +2728,10 @@ var ErrorSchemaBuilder = class {
|
|
|
2038
2728
|
*/
|
|
2039
2729
|
getOrCreateErrorBlock(pathOfError) {
|
|
2040
2730
|
const hasPath = Array.isArray(pathOfError) && pathOfError.length > 0 || typeof pathOfError === "string";
|
|
2041
|
-
let errorBlock = hasPath ? (0,
|
|
2731
|
+
let errorBlock = hasPath ? (0, import_get16.default)(this.errorSchema, pathOfError) : this.errorSchema;
|
|
2042
2732
|
if (!errorBlock && pathOfError) {
|
|
2043
2733
|
errorBlock = {};
|
|
2044
|
-
(0,
|
|
2734
|
+
(0, import_setWith.default)(this.errorSchema, pathOfError, errorBlock, Object);
|
|
2045
2735
|
}
|
|
2046
2736
|
return errorBlock;
|
|
2047
2737
|
}
|
|
@@ -2064,15 +2754,15 @@ var ErrorSchemaBuilder = class {
|
|
|
2064
2754
|
*/
|
|
2065
2755
|
addErrors(errorOrList, pathOfError) {
|
|
2066
2756
|
const errorBlock = this.getOrCreateErrorBlock(pathOfError);
|
|
2067
|
-
let errorsList = (0,
|
|
2757
|
+
let errorsList = (0, import_get16.default)(errorBlock, ERRORS_KEY);
|
|
2068
2758
|
if (!Array.isArray(errorsList)) {
|
|
2069
2759
|
errorsList = [];
|
|
2070
2760
|
errorBlock[ERRORS_KEY] = errorsList;
|
|
2071
2761
|
}
|
|
2072
2762
|
if (Array.isArray(errorOrList)) {
|
|
2073
|
-
|
|
2763
|
+
(0, import_set3.default)(errorBlock, ERRORS_KEY, [.../* @__PURE__ */ new Set([...errorsList, ...errorOrList])]);
|
|
2074
2764
|
} else {
|
|
2075
|
-
|
|
2765
|
+
(0, import_set3.default)(errorBlock, ERRORS_KEY, [.../* @__PURE__ */ new Set([...errorsList, errorOrList])]);
|
|
2076
2766
|
}
|
|
2077
2767
|
return this;
|
|
2078
2768
|
}
|
|
@@ -2086,7 +2776,7 @@ var ErrorSchemaBuilder = class {
|
|
|
2086
2776
|
*/
|
|
2087
2777
|
setErrors(errorOrList, pathOfError) {
|
|
2088
2778
|
const errorBlock = this.getOrCreateErrorBlock(pathOfError);
|
|
2089
|
-
const listToAdd = Array.isArray(errorOrList) ? [...errorOrList] : [errorOrList];
|
|
2779
|
+
const listToAdd = Array.isArray(errorOrList) ? [.../* @__PURE__ */ new Set([...errorOrList])] : [errorOrList];
|
|
2090
2780
|
(0, import_set3.default)(errorBlock, ERRORS_KEY, listToAdd);
|
|
2091
2781
|
return this;
|
|
2092
2782
|
}
|
|
@@ -2171,6 +2861,9 @@ function getInputProps(schema, defaultType, options = {}, autoDefaultStepAny = t
|
|
|
2171
2861
|
if (options.autocomplete) {
|
|
2172
2862
|
inputProps.autoComplete = options.autocomplete;
|
|
2173
2863
|
}
|
|
2864
|
+
if (options.accept) {
|
|
2865
|
+
inputProps.accept = options.accept;
|
|
2866
|
+
}
|
|
2174
2867
|
return inputProps;
|
|
2175
2868
|
}
|
|
2176
2869
|
|
|
@@ -2197,6 +2890,10 @@ function getTemplate(name, registry, uiOptions = {}) {
|
|
|
2197
2890
|
if (name === "ButtonTemplates") {
|
|
2198
2891
|
return templates[name];
|
|
2199
2892
|
}
|
|
2893
|
+
if (Object.hasOwn(uiOptions, name) && typeof uiOptions[name] === "string" && Object.hasOwn(templates, uiOptions[name])) {
|
|
2894
|
+
const key = uiOptions[name];
|
|
2895
|
+
return templates[key];
|
|
2896
|
+
}
|
|
2200
2897
|
return (
|
|
2201
2898
|
// Evaluating uiOptions[name] results in TS2590: Expression produces a union type that is too complex to represent
|
|
2202
2899
|
// To avoid that, we cast uiOptions to `any` before accessing the name field
|
|
@@ -2204,11 +2901,32 @@ function getTemplate(name, registry, uiOptions = {}) {
|
|
|
2204
2901
|
);
|
|
2205
2902
|
}
|
|
2206
2903
|
|
|
2904
|
+
// src/getTestIds.ts
|
|
2905
|
+
var import_nanoid = require("nanoid");
|
|
2906
|
+
var import_get17 = __toESM(require("lodash/get"), 1);
|
|
2907
|
+
function getTestIds() {
|
|
2908
|
+
if (typeof process === "undefined" || (0, import_get17.default)(process, "env.NODE_ENV") !== "test") {
|
|
2909
|
+
return {};
|
|
2910
|
+
}
|
|
2911
|
+
const ids = /* @__PURE__ */ new Map();
|
|
2912
|
+
return new Proxy(
|
|
2913
|
+
{},
|
|
2914
|
+
{
|
|
2915
|
+
get(_obj, prop) {
|
|
2916
|
+
if (!ids.has(prop)) {
|
|
2917
|
+
ids.set(prop, (0, import_nanoid.nanoid)());
|
|
2918
|
+
}
|
|
2919
|
+
return ids.get(prop);
|
|
2920
|
+
}
|
|
2921
|
+
}
|
|
2922
|
+
);
|
|
2923
|
+
}
|
|
2924
|
+
|
|
2207
2925
|
// src/getWidget.tsx
|
|
2208
2926
|
var import_react = require("react");
|
|
2209
|
-
var import_react_is = __toESM(require("react-is"));
|
|
2210
|
-
var
|
|
2211
|
-
var import_set4 = __toESM(require("lodash/set"));
|
|
2927
|
+
var import_react_is = __toESM(require("react-is"), 1);
|
|
2928
|
+
var import_get18 = __toESM(require("lodash/get"), 1);
|
|
2929
|
+
var import_set4 = __toESM(require("lodash/set"), 1);
|
|
2212
2930
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
2213
2931
|
var widgetMap = {
|
|
2214
2932
|
boolean: {
|
|
@@ -2263,7 +2981,7 @@ var widgetMap = {
|
|
|
2263
2981
|
}
|
|
2264
2982
|
};
|
|
2265
2983
|
function mergeWidgetOptions(AWidget) {
|
|
2266
|
-
let MergedWidget = (0,
|
|
2984
|
+
let MergedWidget = (0, import_get18.default)(AWidget, "MergedWidget");
|
|
2267
2985
|
if (!MergedWidget) {
|
|
2268
2986
|
const defaultOptions = AWidget.defaultProps && AWidget.defaultProps.options || {};
|
|
2269
2987
|
MergedWidget = ({ options, ...props }) => {
|
|
@@ -2307,10 +3025,16 @@ function hashString(string) {
|
|
|
2307
3025
|
}
|
|
2308
3026
|
return hash.toString(16);
|
|
2309
3027
|
}
|
|
2310
|
-
function
|
|
3028
|
+
function sortedJSONStringify(object) {
|
|
2311
3029
|
const allKeys = /* @__PURE__ */ new Set();
|
|
2312
|
-
JSON.stringify(
|
|
2313
|
-
return
|
|
3030
|
+
JSON.stringify(object, (key, value) => (allKeys.add(key), value));
|
|
3031
|
+
return JSON.stringify(object, Array.from(allKeys).sort());
|
|
3032
|
+
}
|
|
3033
|
+
function hashObject(object) {
|
|
3034
|
+
return hashString(sortedJSONStringify(object));
|
|
3035
|
+
}
|
|
3036
|
+
function hashForSchema(schema) {
|
|
3037
|
+
return hashObject(schema);
|
|
2314
3038
|
}
|
|
2315
3039
|
|
|
2316
3040
|
// src/hasWidget.ts
|
|
@@ -2328,9 +3052,9 @@ function hasWidget(schema, widget, registeredWidgets = {}) {
|
|
|
2328
3052
|
}
|
|
2329
3053
|
|
|
2330
3054
|
// src/idGenerators.ts
|
|
2331
|
-
var
|
|
3055
|
+
var import_isString4 = __toESM(require("lodash/isString"), 1);
|
|
2332
3056
|
function idGenerator(id, suffix) {
|
|
2333
|
-
const theId = (0,
|
|
3057
|
+
const theId = (0, import_isString4.default)(id) ? id : id[ID_KEY];
|
|
2334
3058
|
return `${theId}__${suffix}`;
|
|
2335
3059
|
}
|
|
2336
3060
|
function descriptionId(id) {
|
|
@@ -2355,6 +3079,9 @@ function ariaDescribedByIds(id, includeExamples = false) {
|
|
|
2355
3079
|
function optionId(id, optionIndex) {
|
|
2356
3080
|
return `${id}-${optionIndex}`;
|
|
2357
3081
|
}
|
|
3082
|
+
function buttonId(id, btn) {
|
|
3083
|
+
return idGenerator(id, btn);
|
|
3084
|
+
}
|
|
2358
3085
|
|
|
2359
3086
|
// src/labelValue.ts
|
|
2360
3087
|
function labelValue(label, hideLabel, fallback) {
|
|
@@ -2366,59 +3093,15 @@ function localToUTC(dateString) {
|
|
|
2366
3093
|
return dateString ? new Date(dateString).toJSON() : void 0;
|
|
2367
3094
|
}
|
|
2368
3095
|
|
|
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;
|
|
3096
|
+
// src/lookupFromFormContext.ts
|
|
3097
|
+
var import_get19 = __toESM(require("lodash/get"), 1);
|
|
3098
|
+
var import_has6 = __toESM(require("lodash/has"), 1);
|
|
3099
|
+
function lookupFromFormContext(regOrFc, toLookup, fallback) {
|
|
3100
|
+
const lookupPath = [LOOKUP_MAP_NAME];
|
|
3101
|
+
if ((0, import_has6.default)(regOrFc, FORM_CONTEXT_NAME)) {
|
|
3102
|
+
lookupPath.unshift(FORM_CONTEXT_NAME);
|
|
2410
3103
|
}
|
|
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
|
-
});
|
|
3104
|
+
return (0, import_get19.default)(regOrFc, [...lookupPath, toLookup], fallback);
|
|
2422
3105
|
}
|
|
2423
3106
|
|
|
2424
3107
|
// src/orderProperties.ts
|
|
@@ -2513,7 +3196,7 @@ function toDateString(dateObject, time = true) {
|
|
|
2513
3196
|
}
|
|
2514
3197
|
|
|
2515
3198
|
// src/toErrorList.ts
|
|
2516
|
-
var import_isPlainObject2 = __toESM(require("lodash/isPlainObject"));
|
|
3199
|
+
var import_isPlainObject2 = __toESM(require("lodash/isPlainObject"), 1);
|
|
2517
3200
|
function toErrorList(errorSchema, fieldPath = []) {
|
|
2518
3201
|
if (!errorSchema) {
|
|
2519
3202
|
return [];
|
|
@@ -2543,7 +3226,7 @@ function toErrorList(errorSchema, fieldPath = []) {
|
|
|
2543
3226
|
}
|
|
2544
3227
|
|
|
2545
3228
|
// src/toErrorSchema.ts
|
|
2546
|
-
var import_toPath = __toESM(require("lodash/toPath"));
|
|
3229
|
+
var import_toPath = __toESM(require("lodash/toPath"), 1);
|
|
2547
3230
|
function toErrorSchema(errors) {
|
|
2548
3231
|
const builder = new ErrorSchemaBuilder();
|
|
2549
3232
|
if (errors.length) {
|
|
@@ -2562,7 +3245,7 @@ function toErrorSchema(errors) {
|
|
|
2562
3245
|
}
|
|
2563
3246
|
|
|
2564
3247
|
// src/unwrapErrorHandler.ts
|
|
2565
|
-
var import_isPlainObject3 = __toESM(require("lodash/isPlainObject"));
|
|
3248
|
+
var import_isPlainObject3 = __toESM(require("lodash/isPlainObject"), 1);
|
|
2566
3249
|
function unwrapErrorHandler(errorHandler) {
|
|
2567
3250
|
return Object.keys(errorHandler).reduce((acc, key) => {
|
|
2568
3251
|
if (key === "addError") {
|
|
@@ -2597,7 +3280,7 @@ function utcToLocal(jsonDate) {
|
|
|
2597
3280
|
}
|
|
2598
3281
|
|
|
2599
3282
|
// src/validationDataMerge.ts
|
|
2600
|
-
var
|
|
3283
|
+
var import_isEmpty5 = __toESM(require("lodash/isEmpty"), 1);
|
|
2601
3284
|
function validationDataMerge(validationData, additionalErrorSchema) {
|
|
2602
3285
|
if (!additionalErrorSchema) {
|
|
2603
3286
|
return validationData;
|
|
@@ -2605,7 +3288,7 @@ function validationDataMerge(validationData, additionalErrorSchema) {
|
|
|
2605
3288
|
const { errors: oldErrors, errorSchema: oldErrorSchema } = validationData;
|
|
2606
3289
|
let errors = toErrorList(additionalErrorSchema);
|
|
2607
3290
|
let errorSchema = additionalErrorSchema;
|
|
2608
|
-
if (!(0,
|
|
3291
|
+
if (!(0, import_isEmpty5.default)(oldErrorSchema)) {
|
|
2609
3292
|
errorSchema = mergeObjects(oldErrorSchema, additionalErrorSchema, true);
|
|
2610
3293
|
errors = [...oldErrors].concat(errors);
|
|
2611
3294
|
}
|
|
@@ -2613,7 +3296,7 @@ function validationDataMerge(validationData, additionalErrorSchema) {
|
|
|
2613
3296
|
}
|
|
2614
3297
|
|
|
2615
3298
|
// src/withIdRefPrefix.ts
|
|
2616
|
-
var import_isObject11 = __toESM(require("lodash/isObject"));
|
|
3299
|
+
var import_isObject11 = __toESM(require("lodash/isObject"), 1);
|
|
2617
3300
|
function withIdRefPrefixObject(node) {
|
|
2618
3301
|
for (const key in node) {
|
|
2619
3302
|
const realObj = node;
|
|
@@ -2642,10 +3325,34 @@ function withIdRefPrefix(schemaNode) {
|
|
|
2642
3325
|
return schemaNode;
|
|
2643
3326
|
}
|
|
2644
3327
|
|
|
3328
|
+
// src/getChangedFields.ts
|
|
3329
|
+
var import_keys = __toESM(require("lodash/keys"), 1);
|
|
3330
|
+
var import_pickBy = __toESM(require("lodash/pickBy"), 1);
|
|
3331
|
+
var import_isPlainObject4 = __toESM(require("lodash/isPlainObject"), 1);
|
|
3332
|
+
var import_get20 = __toESM(require("lodash/get"), 1);
|
|
3333
|
+
var import_difference = __toESM(require("lodash/difference"), 1);
|
|
3334
|
+
function getChangedFields(a, b) {
|
|
3335
|
+
const aIsPlainObject = (0, import_isPlainObject4.default)(a);
|
|
3336
|
+
const bIsPlainObject = (0, import_isPlainObject4.default)(b);
|
|
3337
|
+
if (a === b || !aIsPlainObject && !bIsPlainObject) {
|
|
3338
|
+
return [];
|
|
3339
|
+
}
|
|
3340
|
+
if (aIsPlainObject && !bIsPlainObject) {
|
|
3341
|
+
return (0, import_keys.default)(a);
|
|
3342
|
+
} else if (!aIsPlainObject && bIsPlainObject) {
|
|
3343
|
+
return (0, import_keys.default)(b);
|
|
3344
|
+
} else {
|
|
3345
|
+
const unequalFields = (0, import_keys.default)((0, import_pickBy.default)(a, (value, key) => !deepEquals(value, (0, import_get20.default)(b, key))));
|
|
3346
|
+
const diffFields = (0, import_difference.default)((0, import_keys.default)(b), (0, import_keys.default)(a));
|
|
3347
|
+
return [...unequalFields, ...diffFields];
|
|
3348
|
+
}
|
|
3349
|
+
}
|
|
3350
|
+
|
|
2645
3351
|
// src/enums.ts
|
|
2646
3352
|
var TranslatableString = /* @__PURE__ */ ((TranslatableString2) => {
|
|
2647
3353
|
TranslatableString2["ArrayItemTitle"] = "Item";
|
|
2648
3354
|
TranslatableString2["MissingItems"] = "Missing items definition";
|
|
3355
|
+
TranslatableString2["EmptyArray"] = "No items yet. Use the button below to add some.";
|
|
2649
3356
|
TranslatableString2["YesLabel"] = "Yes";
|
|
2650
3357
|
TranslatableString2["NoLabel"] = "No";
|
|
2651
3358
|
TranslatableString2["CloseLabel"] = "Close";
|
|
@@ -2677,12 +3384,10 @@ var TranslatableString = /* @__PURE__ */ ((TranslatableString2) => {
|
|
|
2677
3384
|
})(TranslatableString || {});
|
|
2678
3385
|
|
|
2679
3386
|
// src/parser/schemaParser.ts
|
|
2680
|
-
var import_forEach = __toESM(require("lodash/forEach"));
|
|
2681
|
-
var import_isEqual7 = __toESM(require("lodash/isEqual"));
|
|
3387
|
+
var import_forEach = __toESM(require("lodash/forEach"), 1);
|
|
2682
3388
|
|
|
2683
3389
|
// src/parser/ParserValidator.ts
|
|
2684
|
-
var
|
|
2685
|
-
var import_isEqual6 = __toESM(require("lodash/isEqual"));
|
|
3390
|
+
var import_get21 = __toESM(require("lodash/get"), 1);
|
|
2686
3391
|
var ParserValidator = class {
|
|
2687
3392
|
/** Construct the ParserValidator for the given `rootSchema`. This `rootSchema` will be stashed in the `schemaMap`
|
|
2688
3393
|
* first.
|
|
@@ -2708,12 +3413,12 @@ var ParserValidator = class {
|
|
|
2708
3413
|
* @param hash - The hash value at which to map the schema
|
|
2709
3414
|
*/
|
|
2710
3415
|
addSchema(schema, hash) {
|
|
2711
|
-
const key = (0,
|
|
3416
|
+
const key = (0, import_get21.default)(schema, ID_KEY, hash);
|
|
2712
3417
|
const identifiedSchema = { ...schema, [ID_KEY]: key };
|
|
2713
3418
|
const existing = this.schemaMap[key];
|
|
2714
3419
|
if (!existing) {
|
|
2715
3420
|
this.schemaMap[key] = identifiedSchema;
|
|
2716
|
-
} else if (!(
|
|
3421
|
+
} else if (!deepEquals(existing, identifiedSchema)) {
|
|
2717
3422
|
console.error("existing schema:", JSON.stringify(existing, null, 2));
|
|
2718
3423
|
console.error("new schema:", JSON.stringify(identifiedSchema, null, 2));
|
|
2719
3424
|
throw new Error(
|
|
@@ -2735,7 +3440,7 @@ var ParserValidator = class {
|
|
|
2735
3440
|
* @throws - Error when the given `rootSchema` differs from the root schema provided during construction
|
|
2736
3441
|
*/
|
|
2737
3442
|
isValid(schema, _formData, rootSchema) {
|
|
2738
|
-
if (!(
|
|
3443
|
+
if (!deepEquals(rootSchema, this.rootSchema)) {
|
|
2739
3444
|
throw new Error("Unexpectedly calling isValid() with a rootSchema that differs from the construction rootSchema");
|
|
2740
3445
|
}
|
|
2741
3446
|
this.addSchema(schema, hashForSchema(schema));
|
|
@@ -2775,7 +3480,7 @@ var ParserValidator = class {
|
|
|
2775
3480
|
function parseSchema(validator, recurseList, rootSchema, schema) {
|
|
2776
3481
|
const schemas = retrieveSchemaInternal(validator, schema, rootSchema, void 0, true);
|
|
2777
3482
|
schemas.forEach((schema2) => {
|
|
2778
|
-
const sameSchemaIndex = recurseList.findIndex((item) => (
|
|
3483
|
+
const sameSchemaIndex = recurseList.findIndex((item) => deepEquals(item, schema2));
|
|
2779
3484
|
if (sameSchemaIndex === -1) {
|
|
2780
3485
|
recurseList.push(schema2);
|
|
2781
3486
|
const allOptions = resolveAnyOrOneOfSchemas(validator, schema2, rootSchema, true);
|