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