@rjsf/utils 5.24.10 → 6.0.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +605 -330
- package/dist/index.js.map +4 -4
- package/dist/utils.esm.js +575 -300
- package/dist/utils.esm.js.map +4 -4
- package/dist/utils.umd.js +519 -268
- package/lib/ErrorSchemaBuilder.d.ts +7 -3
- package/lib/ErrorSchemaBuilder.js +1 -0
- package/lib/ErrorSchemaBuilder.js.map +1 -1
- package/lib/allowAdditionalItems.js.map +1 -1
- package/lib/asNumber.js.map +1 -1
- package/lib/canExpand.js +1 -1
- package/lib/canExpand.js.map +1 -1
- package/lib/constants.d.ts +11 -3
- package/lib/constants.js +11 -3
- package/lib/constants.js.map +1 -1
- package/lib/createErrorHandler.js.map +1 -1
- package/lib/createSchemaUtils.js +31 -27
- package/lib/createSchemaUtils.js.map +1 -1
- package/lib/dataURItoBlob.js.map +1 -1
- package/lib/dateRangeOptions.js.map +1 -1
- package/lib/deepEquals.js.map +1 -1
- package/lib/enumOptionsDeselectValue.js.map +1 -1
- package/lib/enumOptionsIndexForValue.js.map +1 -1
- package/lib/enumOptionsIsSelected.js.map +1 -1
- package/lib/enumOptionsSelectValue.js.map +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.js.map +1 -1
- package/lib/getChangedFields.js.map +1 -1
- package/lib/getDateElementProps.js.map +1 -1
- package/lib/getDiscriminatorFieldFromSchema.js +2 -1
- package/lib/getDiscriminatorFieldFromSchema.js.map +1 -1
- package/lib/getInputProps.js.map +1 -1
- package/lib/getOptionMatchingSimpleDiscriminator.js.map +1 -1
- package/lib/getSchemaType.d.ts +1 -0
- package/lib/getSchemaType.js +2 -1
- package/lib/getSchemaType.js.map +1 -1
- package/lib/getSubmitButtonOptions.js.map +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.js.map +1 -1
- package/lib/getWidget.js.map +1 -1
- package/lib/guessType.d.ts +1 -1
- package/lib/guessType.js.map +1 -1
- package/lib/hasWidget.js.map +1 -1
- package/lib/hashForSchema.d.ts +22 -0
- package/lib/hashForSchema.js +24 -6
- package/lib/hashForSchema.js.map +1 -1
- package/lib/idGenerators.d.ts +7 -0
- package/lib/idGenerators.js +9 -0
- package/lib/idGenerators.js.map +1 -1
- package/lib/index.d.ts +5 -3
- package/lib/index.js +5 -3
- package/lib/index.js.map +1 -1
- package/lib/isObject.d.ts +1 -1
- 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.js.map +1 -1
- package/lib/mergeObjects.js.map +1 -1
- package/lib/mergeSchemas.js.map +1 -1
- package/lib/optionsList.d.ts +8 -6
- package/lib/optionsList.js +29 -18
- package/lib/optionsList.js.map +1 -1
- package/lib/orderProperties.js.map +1 -1
- package/lib/pad.js.map +1 -1
- package/lib/parseDateString.js +1 -1
- package/lib/parseDateString.js.map +1 -1
- package/lib/parser/ParserValidator.js.map +1 -1
- package/lib/parser/schemaParser.js.map +1 -1
- 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.js.map +1 -1
- package/lib/schema/getDefaultFormState.js +2 -3
- package/lib/schema/getDefaultFormState.js.map +1 -1
- package/lib/schema/getDisplayLabel.js.map +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 +4 -3
- package/lib/schema/index.js +4 -3
- package/lib/schema/index.js.map +1 -1
- package/lib/schema/isFilesArray.js.map +1 -1
- package/lib/schema/isMultiSelect.js.map +1 -1
- package/lib/schema/isSelect.js.map +1 -1
- package/lib/schema/retrieveSchema.d.ts +7 -0
- package/lib/schema/retrieveSchema.js +65 -21
- package/lib/schema/retrieveSchema.js.map +1 -1
- package/lib/schema/sanitizeDataForNewSchema.js.map +1 -1
- package/lib/schema/toIdSchema.js +20 -19
- package/lib/schema/toIdSchema.js.map +1 -1
- package/lib/schema/toPathSchema.js +1 -1
- package/lib/schema/toPathSchema.js.map +1 -1
- package/lib/schemaRequiresTrueValue.js.map +1 -1
- package/lib/toConstant.js.map +1 -1
- package/lib/toErrorList.js.map +1 -1
- package/lib/toErrorSchema.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/types.d.ts +127 -128
- package/lib/unwrapErrorHandler.js.map +1 -1
- package/lib/utcToLocal.js.map +1 -1
- package/lib/validationDataMerge.js.map +1 -1
- package/lib/withIdRefPrefix.js.map +1 -1
- package/package.json +35 -25
- package/src/ErrorSchemaBuilder.ts +10 -4
- package/src/canExpand.ts +2 -2
- package/src/constants.ts +12 -3
- package/src/createSchemaUtils.ts +79 -43
- package/src/dataURItoBlob.ts +1 -1
- package/src/dateRangeOptions.ts +1 -1
- package/src/enumOptionsDeselectValue.ts +1 -1
- package/src/enumOptionsIndexForValue.ts +1 -1
- package/src/enumOptionsIsSelected.ts +1 -1
- package/src/enumOptionsSelectValue.ts +1 -1
- package/src/enumOptionsValueForIndex.ts +1 -1
- package/src/enums.ts +2 -0
- package/src/findSchemaDefinition.ts +2 -2
- package/src/getDateElementProps.ts +2 -2
- package/src/getDiscriminatorFieldFromSchema.ts +2 -1
- package/src/getInputProps.ts +2 -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 +19 -2
- package/src/isCustomWidget.ts +1 -1
- package/src/isObject.ts +1 -1
- package/src/labelValue.ts +2 -2
- package/src/lookupFromFormContext.ts +26 -0
- package/src/mergeDefaultsWithFormData.ts +3 -3
- package/src/mergeObjects.ts +24 -21
- package/src/optionsList.ts +31 -22
- package/src/parser/ParserValidator.ts +2 -2
- package/src/parser/schemaParser.ts +2 -2
- package/src/schema/findFieldInSchema.ts +138 -0
- package/src/schema/findSelectedOptionInXxxOf.ts +53 -0
- package/src/schema/getClosestMatchingOption.ts +8 -8
- package/src/schema/getDefaultFormState.ts +26 -25
- package/src/schema/getDisplayLabel.ts +2 -2
- 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 +2 -2
- package/src/schema/isMultiSelect.ts +2 -2
- package/src/schema/isSelect.ts +1 -1
- package/src/schema/retrieveSchema.ts +135 -69
- package/src/schema/sanitizeDataForNewSchema.ts +10 -10
- package/src/schema/toIdSchema.ts +45 -44
- package/src/schema/toPathSchema.ts +10 -10
- package/src/toErrorList.ts +2 -2
- package/src/types.ts +233 -173
- 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/utils.esm.js
CHANGED
|
@@ -59,11 +59,15 @@ var ITEMS_KEY = "items";
|
|
|
59
59
|
var JUNK_OPTION_ID = "_$junk_option_schema_id$_";
|
|
60
60
|
var NAME_KEY = "$name";
|
|
61
61
|
var ONE_OF_KEY = "oneOf";
|
|
62
|
+
var PATTERN_PROPERTIES_KEY = "patternProperties";
|
|
62
63
|
var PROPERTIES_KEY = "properties";
|
|
64
|
+
var READONLY_KEY = "readonly";
|
|
63
65
|
var REQUIRED_KEY = "required";
|
|
64
66
|
var SUBMIT_BTN_OPTIONS_KEY = "submitButtonOptions";
|
|
65
67
|
var REF_KEY = "$ref";
|
|
66
|
-
var
|
|
68
|
+
var DISCRIMINATOR_PATH = ["discriminator", "propertyName"];
|
|
69
|
+
var FORM_CONTEXT_NAME = "formContext";
|
|
70
|
+
var LOOKUP_MAP_NAME = "layoutGridLookupMap";
|
|
67
71
|
var RJSF_ADDITIONAL_PROPERTIES_FLAG = "__rjsf_additionalProperties";
|
|
68
72
|
var ROOT_SCHEMA_PREFIX = "__rjsf_rootSchema";
|
|
69
73
|
var UI_FIELD_KEY = "ui:field";
|
|
@@ -91,7 +95,7 @@ function getUiOptions(uiSchema = {}, globalOptions = {}) {
|
|
|
91
95
|
|
|
92
96
|
// src/canExpand.ts
|
|
93
97
|
function canExpand(schema, uiSchema = {}, formData) {
|
|
94
|
-
if (!schema.additionalProperties) {
|
|
98
|
+
if (!(schema.additionalProperties || schema.patternProperties)) {
|
|
95
99
|
return false;
|
|
96
100
|
}
|
|
97
101
|
const { expandable = true } = getUiOptions(uiSchema);
|
|
@@ -141,9 +145,23 @@ function deepEquals(a, b) {
|
|
|
141
145
|
});
|
|
142
146
|
}
|
|
143
147
|
|
|
144
|
-
// src/schema/
|
|
148
|
+
// src/schema/findFieldInSchema.ts
|
|
145
149
|
import get7 from "lodash/get";
|
|
146
|
-
import
|
|
150
|
+
import has3 from "lodash/has";
|
|
151
|
+
|
|
152
|
+
// src/schema/findSelectedOptionInXxxOf.ts
|
|
153
|
+
import get5 from "lodash/get";
|
|
154
|
+
import isEqual from "lodash/isEqual";
|
|
155
|
+
|
|
156
|
+
// src/schema/retrieveSchema.ts
|
|
157
|
+
import get4 from "lodash/get";
|
|
158
|
+
import set from "lodash/set";
|
|
159
|
+
import times from "lodash/times";
|
|
160
|
+
import transform from "lodash/transform";
|
|
161
|
+
import merge from "lodash/merge";
|
|
162
|
+
import flattenDeep from "lodash/flattenDeep";
|
|
163
|
+
import uniq from "lodash/uniq";
|
|
164
|
+
import mergeAllOf from "json-schema-merge-allof";
|
|
147
165
|
|
|
148
166
|
// src/findSchemaDefinition.ts
|
|
149
167
|
import jsonpointer from "jsonpointer";
|
|
@@ -189,113 +207,12 @@ function findSchemaDefinition($ref, rootSchema = {}) {
|
|
|
189
207
|
return findSchemaDefinitionRecursive($ref, rootSchema, recurseList);
|
|
190
208
|
}
|
|
191
209
|
|
|
192
|
-
// src/schema/getClosestMatchingOption.ts
|
|
193
|
-
import get5 from "lodash/get";
|
|
194
|
-
import has2 from "lodash/has";
|
|
195
|
-
import isNumber2 from "lodash/isNumber";
|
|
196
|
-
import isObject2 from "lodash/isObject";
|
|
197
|
-
import isString2 from "lodash/isString";
|
|
198
|
-
import reduce from "lodash/reduce";
|
|
199
|
-
import times2 from "lodash/times";
|
|
200
|
-
|
|
201
|
-
// src/schema/getMatchingOption.ts
|
|
202
|
-
import get2 from "lodash/get";
|
|
203
|
-
import has from "lodash/has";
|
|
204
|
-
import isNumber from "lodash/isNumber";
|
|
205
|
-
|
|
206
|
-
// src/getOptionMatchingSimpleDiscriminator.ts
|
|
207
|
-
import get from "lodash/get";
|
|
208
|
-
function getOptionMatchingSimpleDiscriminator(formData, options, discriminatorField) {
|
|
209
|
-
if (formData && discriminatorField) {
|
|
210
|
-
const value = get(formData, discriminatorField);
|
|
211
|
-
if (value === void 0) {
|
|
212
|
-
return;
|
|
213
|
-
}
|
|
214
|
-
for (let i = 0; i < options.length; i++) {
|
|
215
|
-
const option = options[i];
|
|
216
|
-
const discriminator = get(option, [PROPERTIES_KEY, discriminatorField], {});
|
|
217
|
-
if (discriminator.type === "object" || discriminator.type === "array") {
|
|
218
|
-
continue;
|
|
219
|
-
}
|
|
220
|
-
if (discriminator.const === value) {
|
|
221
|
-
return i;
|
|
222
|
-
}
|
|
223
|
-
if (discriminator.enum?.includes(value)) {
|
|
224
|
-
return i;
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
return;
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
// src/schema/getMatchingOption.ts
|
|
232
|
-
function getMatchingOption(validator, formData, options, rootSchema, discriminatorField) {
|
|
233
|
-
if (formData === void 0) {
|
|
234
|
-
return 0;
|
|
235
|
-
}
|
|
236
|
-
const simpleDiscriminatorMatch = getOptionMatchingSimpleDiscriminator(formData, options, discriminatorField);
|
|
237
|
-
if (isNumber(simpleDiscriminatorMatch)) {
|
|
238
|
-
return simpleDiscriminatorMatch;
|
|
239
|
-
}
|
|
240
|
-
for (let i = 0; i < options.length; i++) {
|
|
241
|
-
const option = options[i];
|
|
242
|
-
if (discriminatorField && has(option, [PROPERTIES_KEY, discriminatorField])) {
|
|
243
|
-
const value = get2(formData, discriminatorField);
|
|
244
|
-
const discriminator = get2(option, [PROPERTIES_KEY, discriminatorField], {});
|
|
245
|
-
if (validator.isValid(discriminator, value, rootSchema)) {
|
|
246
|
-
return i;
|
|
247
|
-
}
|
|
248
|
-
} else if (option[PROPERTIES_KEY]) {
|
|
249
|
-
const requiresAnyOf = {
|
|
250
|
-
anyOf: Object.keys(option[PROPERTIES_KEY]).map((key) => ({
|
|
251
|
-
required: [key]
|
|
252
|
-
}))
|
|
253
|
-
};
|
|
254
|
-
let augmentedSchema;
|
|
255
|
-
if (option.anyOf) {
|
|
256
|
-
const { ...shallowClone } = option;
|
|
257
|
-
if (!shallowClone.allOf) {
|
|
258
|
-
shallowClone.allOf = [];
|
|
259
|
-
} else {
|
|
260
|
-
shallowClone.allOf = shallowClone.allOf.slice();
|
|
261
|
-
}
|
|
262
|
-
shallowClone.allOf.push(requiresAnyOf);
|
|
263
|
-
augmentedSchema = shallowClone;
|
|
264
|
-
} else {
|
|
265
|
-
augmentedSchema = Object.assign({}, option, requiresAnyOf);
|
|
266
|
-
}
|
|
267
|
-
delete augmentedSchema.required;
|
|
268
|
-
if (validator.isValid(augmentedSchema, formData, rootSchema)) {
|
|
269
|
-
return i;
|
|
270
|
-
}
|
|
271
|
-
} else if (validator.isValid(option, formData, rootSchema)) {
|
|
272
|
-
return i;
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
return 0;
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
// src/schema/getFirstMatchingOption.ts
|
|
279
|
-
function getFirstMatchingOption(validator, formData, options, rootSchema, discriminatorField) {
|
|
280
|
-
return getMatchingOption(validator, formData, options, rootSchema, discriminatorField);
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
// src/schema/retrieveSchema.ts
|
|
284
|
-
import get4 from "lodash/get";
|
|
285
|
-
import set from "lodash/set";
|
|
286
|
-
import times from "lodash/times";
|
|
287
|
-
import transform from "lodash/transform";
|
|
288
|
-
import merge from "lodash/merge";
|
|
289
|
-
import flattenDeep from "lodash/flattenDeep";
|
|
290
|
-
import uniq from "lodash/uniq";
|
|
291
|
-
import mergeAllOf from "json-schema-merge-allof";
|
|
292
|
-
|
|
293
210
|
// src/getDiscriminatorFieldFromSchema.ts
|
|
294
|
-
import
|
|
211
|
+
import get from "lodash/get";
|
|
295
212
|
import isString from "lodash/isString";
|
|
296
213
|
function getDiscriminatorFieldFromSchema(schema) {
|
|
297
214
|
let discriminator;
|
|
298
|
-
const maybeString =
|
|
215
|
+
const maybeString = get(schema, DISCRIMINATOR_PATH);
|
|
299
216
|
if (isString(maybeString)) {
|
|
300
217
|
discriminator = maybeString;
|
|
301
218
|
} else if (maybeString !== void 0) {
|
|
@@ -339,7 +256,7 @@ function getSchemaType(schema) {
|
|
|
339
256
|
if (!type && schema.enum) {
|
|
340
257
|
return "string";
|
|
341
258
|
}
|
|
342
|
-
if (!type && (schema.properties || schema.additionalProperties)) {
|
|
259
|
+
if (!type && (schema.properties || schema.additionalProperties || schema.patternProperties)) {
|
|
343
260
|
return "object";
|
|
344
261
|
}
|
|
345
262
|
if (Array.isArray(type)) {
|
|
@@ -368,7 +285,85 @@ function mergeSchemas(obj1, obj2) {
|
|
|
368
285
|
}, acc);
|
|
369
286
|
}
|
|
370
287
|
|
|
288
|
+
// src/schema/getFirstMatchingOption.ts
|
|
289
|
+
import get3 from "lodash/get";
|
|
290
|
+
import has from "lodash/has";
|
|
291
|
+
import isNumber from "lodash/isNumber";
|
|
292
|
+
|
|
293
|
+
// src/getOptionMatchingSimpleDiscriminator.ts
|
|
294
|
+
import get2 from "lodash/get";
|
|
295
|
+
function getOptionMatchingSimpleDiscriminator(formData, options, discriminatorField) {
|
|
296
|
+
if (formData && discriminatorField) {
|
|
297
|
+
const value = get2(formData, discriminatorField);
|
|
298
|
+
if (value === void 0) {
|
|
299
|
+
return;
|
|
300
|
+
}
|
|
301
|
+
for (let i = 0; i < options.length; i++) {
|
|
302
|
+
const option = options[i];
|
|
303
|
+
const discriminator = get2(option, [PROPERTIES_KEY, discriminatorField], {});
|
|
304
|
+
if (discriminator.type === "object" || discriminator.type === "array") {
|
|
305
|
+
continue;
|
|
306
|
+
}
|
|
307
|
+
if (discriminator.const === value) {
|
|
308
|
+
return i;
|
|
309
|
+
}
|
|
310
|
+
if (discriminator.enum?.includes(value)) {
|
|
311
|
+
return i;
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
return;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
// src/schema/getFirstMatchingOption.ts
|
|
319
|
+
function getFirstMatchingOption(validator, formData, options, rootSchema, discriminatorField) {
|
|
320
|
+
if (formData === void 0) {
|
|
321
|
+
return 0;
|
|
322
|
+
}
|
|
323
|
+
const simpleDiscriminatorMatch = getOptionMatchingSimpleDiscriminator(formData, options, discriminatorField);
|
|
324
|
+
if (isNumber(simpleDiscriminatorMatch)) {
|
|
325
|
+
return simpleDiscriminatorMatch;
|
|
326
|
+
}
|
|
327
|
+
for (let i = 0; i < options.length; i++) {
|
|
328
|
+
const option = options[i];
|
|
329
|
+
if (discriminatorField && has(option, [PROPERTIES_KEY, discriminatorField])) {
|
|
330
|
+
const value = get3(formData, discriminatorField);
|
|
331
|
+
const discriminator = get3(option, [PROPERTIES_KEY, discriminatorField], {});
|
|
332
|
+
if (validator.isValid(discriminator, value, rootSchema)) {
|
|
333
|
+
return i;
|
|
334
|
+
}
|
|
335
|
+
} else if (option[PROPERTIES_KEY]) {
|
|
336
|
+
const requiresAnyOf = {
|
|
337
|
+
anyOf: Object.keys(option[PROPERTIES_KEY]).map((key) => ({
|
|
338
|
+
required: [key]
|
|
339
|
+
}))
|
|
340
|
+
};
|
|
341
|
+
let augmentedSchema;
|
|
342
|
+
if (option.anyOf) {
|
|
343
|
+
const { ...shallowClone } = option;
|
|
344
|
+
if (!shallowClone.allOf) {
|
|
345
|
+
shallowClone.allOf = [];
|
|
346
|
+
} else {
|
|
347
|
+
shallowClone.allOf = shallowClone.allOf.slice();
|
|
348
|
+
}
|
|
349
|
+
shallowClone.allOf.push(requiresAnyOf);
|
|
350
|
+
augmentedSchema = shallowClone;
|
|
351
|
+
} else {
|
|
352
|
+
augmentedSchema = Object.assign({}, option, requiresAnyOf);
|
|
353
|
+
}
|
|
354
|
+
delete augmentedSchema.required;
|
|
355
|
+
if (validator.isValid(augmentedSchema, formData, rootSchema)) {
|
|
356
|
+
return i;
|
|
357
|
+
}
|
|
358
|
+
} else if (validator.isValid(option, formData, rootSchema)) {
|
|
359
|
+
return i;
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
return 0;
|
|
363
|
+
}
|
|
364
|
+
|
|
371
365
|
// src/schema/retrieveSchema.ts
|
|
366
|
+
import isEmpty from "lodash/isEmpty";
|
|
372
367
|
function retrieveSchema(validator, schema, rootSchema = {}, rawFormData, experimental_customMergeAllOf) {
|
|
373
368
|
return retrieveSchemaInternal(
|
|
374
369
|
validator,
|
|
@@ -457,6 +452,15 @@ function getAllPermutationsOfXxxOf(listOfLists) {
|
|
|
457
452
|
);
|
|
458
453
|
return allPermutations;
|
|
459
454
|
}
|
|
455
|
+
function getMatchingPatternProperties(schema, key) {
|
|
456
|
+
return Object.keys(schema.patternProperties).filter((pattern) => RegExp(pattern).test(key)).reduce(
|
|
457
|
+
(obj, pattern) => {
|
|
458
|
+
set(obj, [pattern], schema.patternProperties[pattern]);
|
|
459
|
+
return obj;
|
|
460
|
+
},
|
|
461
|
+
{}
|
|
462
|
+
);
|
|
463
|
+
}
|
|
460
464
|
function resolveSchema(validator, schema, rootSchema, expandAllBranches, recurseList, formData, experimental_customMergeAllOf) {
|
|
461
465
|
const updatedSchemas = resolveReference(
|
|
462
466
|
validator,
|
|
@@ -571,31 +575,50 @@ function stubExistingAdditionalProperties(validator, theSchema, rootSchema, aFor
|
|
|
571
575
|
if (key in schema.properties) {
|
|
572
576
|
return;
|
|
573
577
|
}
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
if (
|
|
577
|
-
|
|
578
|
+
if (PATTERN_PROPERTIES_KEY in schema) {
|
|
579
|
+
const matchingProperties = getMatchingPatternProperties(schema, key);
|
|
580
|
+
if (!isEmpty(matchingProperties)) {
|
|
581
|
+
schema.properties[key] = retrieveSchema(
|
|
578
582
|
validator,
|
|
579
|
-
{
|
|
583
|
+
{ allOf: Object.values(matchingProperties) },
|
|
580
584
|
rootSchema,
|
|
581
585
|
formData,
|
|
582
586
|
experimental_customMergeAllOf
|
|
583
587
|
);
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
}
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
588
|
+
set(schema.properties, [key, ADDITIONAL_PROPERTY_FLAG], true);
|
|
589
|
+
return;
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
if (ADDITIONAL_PROPERTIES_KEY in schema && schema.additionalProperties !== false) {
|
|
593
|
+
let additionalProperties = {};
|
|
594
|
+
if (typeof schema.additionalProperties !== "boolean") {
|
|
595
|
+
if (REF_KEY in schema.additionalProperties) {
|
|
596
|
+
additionalProperties = retrieveSchema(
|
|
597
|
+
validator,
|
|
598
|
+
{ $ref: get4(schema.additionalProperties, [REF_KEY]) },
|
|
599
|
+
rootSchema,
|
|
600
|
+
formData,
|
|
601
|
+
experimental_customMergeAllOf
|
|
602
|
+
);
|
|
603
|
+
} else if ("type" in schema.additionalProperties) {
|
|
604
|
+
additionalProperties = { ...schema.additionalProperties };
|
|
605
|
+
} else if (ANY_OF_KEY in schema.additionalProperties || ONE_OF_KEY in schema.additionalProperties) {
|
|
606
|
+
additionalProperties = {
|
|
607
|
+
type: "object",
|
|
608
|
+
...schema.additionalProperties
|
|
609
|
+
};
|
|
610
|
+
} else {
|
|
611
|
+
additionalProperties = { type: guessType(get4(formData, [key])) };
|
|
612
|
+
}
|
|
591
613
|
} else {
|
|
592
614
|
additionalProperties = { type: guessType(get4(formData, [key])) };
|
|
593
615
|
}
|
|
616
|
+
schema.properties[key] = additionalProperties;
|
|
617
|
+
set(schema.properties, [key, ADDITIONAL_PROPERTY_FLAG], true);
|
|
594
618
|
} else {
|
|
595
|
-
|
|
619
|
+
schema.properties[key] = { type: "null" };
|
|
620
|
+
set(schema.properties, [key, ADDITIONAL_PROPERTY_FLAG], true);
|
|
596
621
|
}
|
|
597
|
-
schema.properties[key] = additionalProperties;
|
|
598
|
-
set(schema.properties, [key, ADDITIONAL_PROPERTY_FLAG], true);
|
|
599
622
|
});
|
|
600
623
|
return schema;
|
|
601
624
|
}
|
|
@@ -655,7 +678,28 @@ function retrieveSchemaInternal(validator, schema, rootSchema, rawFormData, expa
|
|
|
655
678
|
return resolvedSchemaWithoutAllOf;
|
|
656
679
|
}
|
|
657
680
|
}
|
|
658
|
-
|
|
681
|
+
if (PROPERTIES_KEY in resolvedSchema && PATTERN_PROPERTIES_KEY in resolvedSchema) {
|
|
682
|
+
resolvedSchema = Object.keys(resolvedSchema.properties).reduce(
|
|
683
|
+
(schema2, key) => {
|
|
684
|
+
const matchingProperties = getMatchingPatternProperties(schema2, key);
|
|
685
|
+
if (!isEmpty(matchingProperties)) {
|
|
686
|
+
schema2.properties[key] = retrieveSchema(
|
|
687
|
+
validator,
|
|
688
|
+
{ allOf: [schema2.properties[key], ...Object.values(matchingProperties)] },
|
|
689
|
+
rootSchema,
|
|
690
|
+
rawFormData,
|
|
691
|
+
experimental_customMergeAllOf
|
|
692
|
+
);
|
|
693
|
+
}
|
|
694
|
+
return schema2;
|
|
695
|
+
},
|
|
696
|
+
{
|
|
697
|
+
...resolvedSchema,
|
|
698
|
+
properties: { ...resolvedSchema.properties }
|
|
699
|
+
}
|
|
700
|
+
);
|
|
701
|
+
}
|
|
702
|
+
const hasAdditionalProperties = PATTERN_PROPERTIES_KEY in resolvedSchema || ADDITIONAL_PROPERTIES_KEY in resolvedSchema && resolvedSchema.additionalProperties !== false;
|
|
659
703
|
if (hasAdditionalProperties) {
|
|
660
704
|
return stubExistingAdditionalProperties(
|
|
661
705
|
validator,
|
|
@@ -838,7 +882,159 @@ function withExactlyOneSubschema(validator, schema, rootSchema, dependencyKey, o
|
|
|
838
882
|
});
|
|
839
883
|
}
|
|
840
884
|
|
|
885
|
+
// src/schema/findSelectedOptionInXxxOf.ts
|
|
886
|
+
function findSelectedOptionInXxxOf(validator, rootSchema, schema, fallbackField, xxx, formData = {}, experimental_customMergeAllOf) {
|
|
887
|
+
if (Array.isArray(schema[xxx])) {
|
|
888
|
+
const discriminator = getDiscriminatorFieldFromSchema(schema);
|
|
889
|
+
const selectorField = discriminator || fallbackField;
|
|
890
|
+
const xxxOfs = schema[xxx].map(
|
|
891
|
+
(xxxOf) => retrieveSchema(validator, xxxOf, rootSchema, formData, experimental_customMergeAllOf)
|
|
892
|
+
);
|
|
893
|
+
const data = get5(formData, selectorField);
|
|
894
|
+
if (data !== void 0) {
|
|
895
|
+
return xxxOfs.find((xxx2) => {
|
|
896
|
+
return isEqual(
|
|
897
|
+
get5(xxx2, [PROPERTIES_KEY, selectorField, DEFAULT_KEY], get5(xxx2, [PROPERTIES_KEY, selectorField, CONST_KEY])),
|
|
898
|
+
data
|
|
899
|
+
);
|
|
900
|
+
});
|
|
901
|
+
}
|
|
902
|
+
}
|
|
903
|
+
return void 0;
|
|
904
|
+
}
|
|
905
|
+
|
|
906
|
+
// src/schema/getFromSchema.ts
|
|
907
|
+
import get6 from "lodash/get";
|
|
908
|
+
import has2 from "lodash/has";
|
|
909
|
+
import isEmpty2 from "lodash/isEmpty";
|
|
910
|
+
function getFromSchemaInternal(validator, rootSchema, schema, path, experimental_customMergeAllOf) {
|
|
911
|
+
let fieldSchema = schema;
|
|
912
|
+
if (has2(schema, REF_KEY)) {
|
|
913
|
+
fieldSchema = retrieveSchema(validator, schema, rootSchema, void 0, experimental_customMergeAllOf);
|
|
914
|
+
}
|
|
915
|
+
if (isEmpty2(path)) {
|
|
916
|
+
return fieldSchema;
|
|
917
|
+
}
|
|
918
|
+
const pathList = Array.isArray(path) ? path : path.split(".");
|
|
919
|
+
const [part, ...nestedPath] = pathList;
|
|
920
|
+
if (part && has2(fieldSchema, part)) {
|
|
921
|
+
fieldSchema = get6(fieldSchema, part);
|
|
922
|
+
return getFromSchemaInternal(
|
|
923
|
+
validator,
|
|
924
|
+
rootSchema,
|
|
925
|
+
fieldSchema,
|
|
926
|
+
nestedPath,
|
|
927
|
+
experimental_customMergeAllOf
|
|
928
|
+
);
|
|
929
|
+
}
|
|
930
|
+
return void 0;
|
|
931
|
+
}
|
|
932
|
+
function getFromSchema(validator, rootSchema, schema, path, defaultValue, experimental_customMergeAllOf) {
|
|
933
|
+
const result = getFromSchemaInternal(validator, rootSchema, schema, path, experimental_customMergeAllOf);
|
|
934
|
+
if (result === void 0) {
|
|
935
|
+
return defaultValue;
|
|
936
|
+
}
|
|
937
|
+
return result;
|
|
938
|
+
}
|
|
939
|
+
|
|
940
|
+
// src/schema/findFieldInSchema.ts
|
|
941
|
+
var NOT_FOUND_SCHEMA = { title: "!@#$_UNKNOWN_$#@!" };
|
|
942
|
+
function findFieldInSchema(validator, rootSchema, schema, path, formData = {}, experimental_customMergeAllOf) {
|
|
943
|
+
const pathList = Array.isArray(path) ? [...path] : path.split(".");
|
|
944
|
+
let parentField = schema;
|
|
945
|
+
const fieldName = pathList.pop();
|
|
946
|
+
if (pathList.length) {
|
|
947
|
+
pathList.forEach((subPath) => {
|
|
948
|
+
parentField = getFromSchema(
|
|
949
|
+
validator,
|
|
950
|
+
rootSchema,
|
|
951
|
+
parentField,
|
|
952
|
+
[PROPERTIES_KEY, subPath],
|
|
953
|
+
{},
|
|
954
|
+
experimental_customMergeAllOf
|
|
955
|
+
);
|
|
956
|
+
if (has3(parentField, ONE_OF_KEY)) {
|
|
957
|
+
parentField = findSelectedOptionInXxxOf(
|
|
958
|
+
validator,
|
|
959
|
+
rootSchema,
|
|
960
|
+
parentField,
|
|
961
|
+
fieldName,
|
|
962
|
+
ONE_OF_KEY,
|
|
963
|
+
get7(formData, subPath),
|
|
964
|
+
experimental_customMergeAllOf
|
|
965
|
+
);
|
|
966
|
+
} else if (has3(parentField, ANY_OF_KEY)) {
|
|
967
|
+
parentField = findSelectedOptionInXxxOf(
|
|
968
|
+
validator,
|
|
969
|
+
rootSchema,
|
|
970
|
+
parentField,
|
|
971
|
+
fieldName,
|
|
972
|
+
ANY_OF_KEY,
|
|
973
|
+
get7(formData, subPath),
|
|
974
|
+
experimental_customMergeAllOf
|
|
975
|
+
);
|
|
976
|
+
}
|
|
977
|
+
});
|
|
978
|
+
}
|
|
979
|
+
if (has3(parentField, ONE_OF_KEY)) {
|
|
980
|
+
parentField = findSelectedOptionInXxxOf(
|
|
981
|
+
validator,
|
|
982
|
+
rootSchema,
|
|
983
|
+
parentField,
|
|
984
|
+
fieldName,
|
|
985
|
+
ONE_OF_KEY,
|
|
986
|
+
formData,
|
|
987
|
+
experimental_customMergeAllOf
|
|
988
|
+
);
|
|
989
|
+
} else if (has3(parentField, ANY_OF_KEY)) {
|
|
990
|
+
parentField = findSelectedOptionInXxxOf(
|
|
991
|
+
validator,
|
|
992
|
+
rootSchema,
|
|
993
|
+
parentField,
|
|
994
|
+
fieldName,
|
|
995
|
+
ANY_OF_KEY,
|
|
996
|
+
formData,
|
|
997
|
+
experimental_customMergeAllOf
|
|
998
|
+
);
|
|
999
|
+
}
|
|
1000
|
+
let field = getFromSchema(
|
|
1001
|
+
validator,
|
|
1002
|
+
rootSchema,
|
|
1003
|
+
parentField,
|
|
1004
|
+
[PROPERTIES_KEY, fieldName],
|
|
1005
|
+
NOT_FOUND_SCHEMA,
|
|
1006
|
+
experimental_customMergeAllOf
|
|
1007
|
+
);
|
|
1008
|
+
if (field === NOT_FOUND_SCHEMA) {
|
|
1009
|
+
field = void 0;
|
|
1010
|
+
}
|
|
1011
|
+
const requiredArray = getFromSchema(
|
|
1012
|
+
validator,
|
|
1013
|
+
rootSchema,
|
|
1014
|
+
parentField,
|
|
1015
|
+
REQUIRED_KEY,
|
|
1016
|
+
[],
|
|
1017
|
+
experimental_customMergeAllOf
|
|
1018
|
+
);
|
|
1019
|
+
let isRequired;
|
|
1020
|
+
if (field && Array.isArray(requiredArray)) {
|
|
1021
|
+
isRequired = requiredArray.includes(fieldName);
|
|
1022
|
+
}
|
|
1023
|
+
return { field, isRequired };
|
|
1024
|
+
}
|
|
1025
|
+
|
|
1026
|
+
// src/schema/getDefaultFormState.ts
|
|
1027
|
+
import get11 from "lodash/get";
|
|
1028
|
+
import isEmpty3 from "lodash/isEmpty";
|
|
1029
|
+
|
|
841
1030
|
// src/schema/getClosestMatchingOption.ts
|
|
1031
|
+
import get8 from "lodash/get";
|
|
1032
|
+
import has4 from "lodash/has";
|
|
1033
|
+
import isNumber2 from "lodash/isNumber";
|
|
1034
|
+
import isObject2 from "lodash/isObject";
|
|
1035
|
+
import isString2 from "lodash/isString";
|
|
1036
|
+
import reduce from "lodash/reduce";
|
|
1037
|
+
import times2 from "lodash/times";
|
|
842
1038
|
var JUNK_OPTION = {
|
|
843
1039
|
type: "object",
|
|
844
1040
|
$id: JUNK_OPTION_ID,
|
|
@@ -855,11 +1051,11 @@ function calculateIndexScore(validator, rootSchema, schema, formData, experiment
|
|
|
855
1051
|
totalScore += reduce(
|
|
856
1052
|
schema.properties,
|
|
857
1053
|
(score, value, key) => {
|
|
858
|
-
const formValue =
|
|
1054
|
+
const formValue = get8(formData, key);
|
|
859
1055
|
if (typeof value === "boolean") {
|
|
860
1056
|
return score;
|
|
861
1057
|
}
|
|
862
|
-
if (
|
|
1058
|
+
if (has4(value, REF_KEY)) {
|
|
863
1059
|
const newSchema = retrieveSchema(
|
|
864
1060
|
validator,
|
|
865
1061
|
value,
|
|
@@ -875,14 +1071,14 @@ function calculateIndexScore(validator, rootSchema, schema, formData, experiment
|
|
|
875
1071
|
experimental_customMergeAllOf
|
|
876
1072
|
);
|
|
877
1073
|
}
|
|
878
|
-
if ((
|
|
879
|
-
const key2 =
|
|
1074
|
+
if ((has4(value, ONE_OF_KEY) || has4(value, ANY_OF_KEY)) && formValue) {
|
|
1075
|
+
const key2 = has4(value, ONE_OF_KEY) ? ONE_OF_KEY : ANY_OF_KEY;
|
|
880
1076
|
const discriminator = getDiscriminatorFieldFromSchema(value);
|
|
881
1077
|
return score + getClosestMatchingOption(
|
|
882
1078
|
validator,
|
|
883
1079
|
rootSchema,
|
|
884
1080
|
formValue,
|
|
885
|
-
|
|
1081
|
+
get8(value, key2),
|
|
886
1082
|
-1,
|
|
887
1083
|
discriminator,
|
|
888
1084
|
experimental_customMergeAllOf
|
|
@@ -961,7 +1157,7 @@ function isFixedItems(schema) {
|
|
|
961
1157
|
}
|
|
962
1158
|
|
|
963
1159
|
// src/mergeDefaultsWithFormData.ts
|
|
964
|
-
import
|
|
1160
|
+
import get9 from "lodash/get";
|
|
965
1161
|
import isNil from "lodash/isNil";
|
|
966
1162
|
function mergeDefaultsWithFormData(defaults, formData, mergeExtraArrayDefaults = false, defaultSupercedesUndefined = false, overrideFormDataWithDefaults = false) {
|
|
967
1163
|
if (Array.isArray(formData)) {
|
|
@@ -988,11 +1184,11 @@ function mergeDefaultsWithFormData(defaults, formData, mergeExtraArrayDefaults =
|
|
|
988
1184
|
if (isObject(formData)) {
|
|
989
1185
|
const acc = Object.assign({}, defaults);
|
|
990
1186
|
return Object.keys(formData).reduce((acc2, key) => {
|
|
991
|
-
const keyValue =
|
|
1187
|
+
const keyValue = get9(formData, key);
|
|
992
1188
|
const keyExistsInDefaults = isObject(defaults) && key in defaults;
|
|
993
1189
|
const keyExistsInFormData = key in formData;
|
|
994
1190
|
acc2[key] = mergeDefaultsWithFormData(
|
|
995
|
-
defaults ?
|
|
1191
|
+
defaults ? get9(defaults, key) : {},
|
|
996
1192
|
keyValue,
|
|
997
1193
|
mergeExtraArrayDefaults,
|
|
998
1194
|
defaultSupercedesUndefined,
|
|
@@ -1011,26 +1207,29 @@ function mergeDefaultsWithFormData(defaults, formData, mergeExtraArrayDefaults =
|
|
|
1011
1207
|
|
|
1012
1208
|
// src/mergeObjects.ts
|
|
1013
1209
|
function mergeObjects(obj1, obj2, concatArrays = false) {
|
|
1014
|
-
return Object.keys(obj2).reduce(
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1210
|
+
return Object.keys(obj2).reduce(
|
|
1211
|
+
(acc, key) => {
|
|
1212
|
+
const left = obj1 ? obj1[key] : {}, right = obj2[key];
|
|
1213
|
+
if (obj1 && key in obj1 && isObject(right)) {
|
|
1214
|
+
acc[key] = mergeObjects(left, right, concatArrays);
|
|
1215
|
+
} else if (concatArrays && Array.isArray(left) && Array.isArray(right)) {
|
|
1216
|
+
let toMerge = right;
|
|
1217
|
+
if (concatArrays === "preventDuplicates") {
|
|
1218
|
+
toMerge = right.reduce((result, value) => {
|
|
1219
|
+
if (!left.includes(value)) {
|
|
1220
|
+
result.push(value);
|
|
1221
|
+
}
|
|
1222
|
+
return result;
|
|
1223
|
+
}, []);
|
|
1224
|
+
}
|
|
1225
|
+
acc[key] = left.concat(toMerge);
|
|
1226
|
+
} else {
|
|
1227
|
+
acc[key] = right;
|
|
1027
1228
|
}
|
|
1028
|
-
acc
|
|
1029
|
-
}
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
return acc;
|
|
1033
|
-
}, Object.assign({}, obj1));
|
|
1229
|
+
return acc;
|
|
1230
|
+
},
|
|
1231
|
+
Object.assign({}, obj1)
|
|
1232
|
+
);
|
|
1034
1233
|
}
|
|
1035
1234
|
|
|
1036
1235
|
// src/isConstant.ts
|
|
@@ -1067,6 +1266,9 @@ function constIsAjvDataReference(schema) {
|
|
|
1067
1266
|
return isObject(schemaConst) && isString3(schemaConst?.$data) && schemaType !== "object" && schemaType !== "array";
|
|
1068
1267
|
}
|
|
1069
1268
|
|
|
1269
|
+
// src/optionsList.ts
|
|
1270
|
+
import get10 from "lodash/get";
|
|
1271
|
+
|
|
1070
1272
|
// src/toConstant.ts
|
|
1071
1273
|
function toConstant(schema) {
|
|
1072
1274
|
if (ENUM_KEY in schema && Array.isArray(schema.enum) && schema.enum.length === 1) {
|
|
@@ -1080,21 +1282,12 @@ function toConstant(schema) {
|
|
|
1080
1282
|
|
|
1081
1283
|
// src/optionsList.ts
|
|
1082
1284
|
function optionsList(schema, uiSchema) {
|
|
1083
|
-
const schemaWithEnumNames = schema;
|
|
1084
1285
|
if (schema.enum) {
|
|
1085
1286
|
let enumNames;
|
|
1086
1287
|
if (uiSchema) {
|
|
1087
1288
|
const { enumNames: uiEnumNames } = getUiOptions(uiSchema);
|
|
1088
1289
|
enumNames = uiEnumNames;
|
|
1089
1290
|
}
|
|
1090
|
-
if (!enumNames && schemaWithEnumNames.enumNames) {
|
|
1091
|
-
if (true) {
|
|
1092
|
-
console.warn(
|
|
1093
|
-
'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.'
|
|
1094
|
-
);
|
|
1095
|
-
}
|
|
1096
|
-
enumNames = schemaWithEnumNames.enumNames;
|
|
1097
|
-
}
|
|
1098
1291
|
return schema.enum.map((value, i) => {
|
|
1099
1292
|
const label = enumNames?.[i] || String(value);
|
|
1100
1293
|
return { label, value };
|
|
@@ -1109,11 +1302,24 @@ function optionsList(schema, uiSchema) {
|
|
|
1109
1302
|
altSchemas = schema.oneOf;
|
|
1110
1303
|
altUiSchemas = uiSchema?.oneOf;
|
|
1111
1304
|
}
|
|
1305
|
+
let selectorField = getDiscriminatorFieldFromSchema(schema);
|
|
1306
|
+
if (uiSchema) {
|
|
1307
|
+
const { optionsSchemaSelector = selectorField } = getUiOptions(uiSchema);
|
|
1308
|
+
selectorField = optionsSchemaSelector;
|
|
1309
|
+
}
|
|
1112
1310
|
return altSchemas && altSchemas.map((aSchemaDef, index) => {
|
|
1113
1311
|
const { title } = getUiOptions(altUiSchemas?.[index]);
|
|
1114
1312
|
const aSchema = aSchemaDef;
|
|
1115
|
-
|
|
1116
|
-
|
|
1313
|
+
let value;
|
|
1314
|
+
let label = title;
|
|
1315
|
+
if (selectorField) {
|
|
1316
|
+
const innerSchema = get10(aSchema, [PROPERTIES_KEY, selectorField], {});
|
|
1317
|
+
value = get10(innerSchema, DEFAULT_KEY, get10(innerSchema, CONST_KEY));
|
|
1318
|
+
label = label || innerSchema?.title || aSchema.title || String(value);
|
|
1319
|
+
} else {
|
|
1320
|
+
value = toConstant(aSchema);
|
|
1321
|
+
label = label || aSchema.title || String(value);
|
|
1322
|
+
}
|
|
1117
1323
|
return {
|
|
1118
1324
|
schema: aSchema,
|
|
1119
1325
|
label,
|
|
@@ -1148,10 +1354,10 @@ function maybeAddDefaultToObject(obj, key, computedDefault, includeUndefinedValu
|
|
|
1148
1354
|
const isSelfOrParentRequired = isParentRequired === void 0 ? requiredFields.includes(key) : isParentRequired;
|
|
1149
1355
|
if (isObject(computedDefault)) {
|
|
1150
1356
|
if (emptyObjectFields === "skipEmptyDefaults") {
|
|
1151
|
-
if (!
|
|
1357
|
+
if (!isEmpty3(computedDefault)) {
|
|
1152
1358
|
obj[key] = computedDefault;
|
|
1153
1359
|
}
|
|
1154
|
-
} else if ((!
|
|
1360
|
+
} else if ((!isEmpty3(computedDefault) || requiredFields.includes(key)) && (isSelfOrParentRequired || emptyObjectFields !== "populateRequiredDefaults")) {
|
|
1155
1361
|
obj[key] = computedDefault;
|
|
1156
1362
|
}
|
|
1157
1363
|
} else if (
|
|
@@ -1335,7 +1541,7 @@ function getObjectDefaults(validator, rawSchema, {
|
|
|
1335
1541
|
const parentConst = retrievedSchema[CONST_KEY];
|
|
1336
1542
|
const objectDefaults = Object.keys(retrievedSchema.properties || {}).reduce(
|
|
1337
1543
|
(acc, key) => {
|
|
1338
|
-
const propertySchema =
|
|
1544
|
+
const propertySchema = get11(retrievedSchema, [PROPERTIES_KEY, key], {});
|
|
1339
1545
|
const hasParentConst = isObject(parentConst) && parentConst[key] !== void 0;
|
|
1340
1546
|
const hasConst = (isObject(propertySchema) && CONST_KEY in propertySchema || hasParentConst) && experimental_defaultFormStateBehavior?.constAsDefaults !== "never" && !constIsAjvDataReference(propertySchema);
|
|
1341
1547
|
const computedDefault = computeDefaults(validator, propertySchema, {
|
|
@@ -1344,8 +1550,8 @@ function getObjectDefaults(validator, rawSchema, {
|
|
|
1344
1550
|
experimental_defaultFormStateBehavior,
|
|
1345
1551
|
experimental_customMergeAllOf,
|
|
1346
1552
|
includeUndefinedValues: includeUndefinedValues === true,
|
|
1347
|
-
parentDefaults:
|
|
1348
|
-
rawFormData:
|
|
1553
|
+
parentDefaults: get11(defaults, [key]),
|
|
1554
|
+
rawFormData: get11(formData, [key]),
|
|
1349
1555
|
required: retrievedSchema.required?.includes(key),
|
|
1350
1556
|
shouldMergeDefaultsIntoFormData
|
|
1351
1557
|
});
|
|
@@ -1381,8 +1587,8 @@ function getObjectDefaults(validator, rawSchema, {
|
|
|
1381
1587
|
experimental_defaultFormStateBehavior,
|
|
1382
1588
|
experimental_customMergeAllOf,
|
|
1383
1589
|
includeUndefinedValues: includeUndefinedValues === true,
|
|
1384
|
-
parentDefaults:
|
|
1385
|
-
rawFormData:
|
|
1590
|
+
parentDefaults: get11(defaults, [key]),
|
|
1591
|
+
rawFormData: get11(formData, [key]),
|
|
1386
1592
|
required: retrievedSchema.required?.includes(key),
|
|
1387
1593
|
shouldMergeDefaultsIntoFormData
|
|
1388
1594
|
});
|
|
@@ -1443,7 +1649,7 @@ function getArrayDefaults(validator, rawSchema, {
|
|
|
1443
1649
|
experimental_defaultFormStateBehavior,
|
|
1444
1650
|
experimental_customMergeAllOf,
|
|
1445
1651
|
rawFormData: item,
|
|
1446
|
-
parentDefaults:
|
|
1652
|
+
parentDefaults: get11(defaults, [idx]),
|
|
1447
1653
|
required,
|
|
1448
1654
|
shouldMergeDefaultsIntoFormData
|
|
1449
1655
|
});
|
|
@@ -1483,6 +1689,7 @@ function getArrayDefaults(validator, rawSchema, {
|
|
|
1483
1689
|
}
|
|
1484
1690
|
function getDefaultBasedOnSchemaType(validator, rawSchema, computeDefaultsProps = {}, defaults) {
|
|
1485
1691
|
switch (getSchemaType(rawSchema)) {
|
|
1692
|
+
// We need to recurse for object schema inner default values.
|
|
1486
1693
|
case "object": {
|
|
1487
1694
|
return getObjectDefaults(validator, rawSchema, computeDefaultsProps, defaults);
|
|
1488
1695
|
}
|
|
@@ -1569,45 +1776,29 @@ function getDisplayLabel(validator, schema, uiSchema = {}, rootSchema, globalOpt
|
|
|
1569
1776
|
return displayLabel;
|
|
1570
1777
|
}
|
|
1571
1778
|
|
|
1572
|
-
// src/schema/mergeValidationData.ts
|
|
1573
|
-
import isEmpty2 from "lodash/isEmpty";
|
|
1574
|
-
function mergeValidationData(validator, validationData, additionalErrorSchema) {
|
|
1575
|
-
if (!additionalErrorSchema) {
|
|
1576
|
-
return validationData;
|
|
1577
|
-
}
|
|
1578
|
-
const { errors: oldErrors, errorSchema: oldErrorSchema } = validationData;
|
|
1579
|
-
let errors = validator.toErrorList(additionalErrorSchema);
|
|
1580
|
-
let errorSchema = additionalErrorSchema;
|
|
1581
|
-
if (!isEmpty2(oldErrorSchema)) {
|
|
1582
|
-
errorSchema = mergeObjects(oldErrorSchema, additionalErrorSchema, true);
|
|
1583
|
-
errors = [...oldErrors].concat(errors);
|
|
1584
|
-
}
|
|
1585
|
-
return { errorSchema, errors };
|
|
1586
|
-
}
|
|
1587
|
-
|
|
1588
1779
|
// src/schema/sanitizeDataForNewSchema.ts
|
|
1589
|
-
import
|
|
1590
|
-
import
|
|
1780
|
+
import get12 from "lodash/get";
|
|
1781
|
+
import has5 from "lodash/has";
|
|
1591
1782
|
var NO_VALUE = Symbol("no Value");
|
|
1592
1783
|
function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, data = {}, experimental_customMergeAllOf) {
|
|
1593
1784
|
let newFormData;
|
|
1594
|
-
if (
|
|
1785
|
+
if (has5(newSchema, PROPERTIES_KEY)) {
|
|
1595
1786
|
const removeOldSchemaData = {};
|
|
1596
|
-
if (
|
|
1597
|
-
const properties =
|
|
1787
|
+
if (has5(oldSchema, PROPERTIES_KEY)) {
|
|
1788
|
+
const properties = get12(oldSchema, PROPERTIES_KEY, {});
|
|
1598
1789
|
Object.keys(properties).forEach((key) => {
|
|
1599
|
-
if (
|
|
1790
|
+
if (has5(data, key)) {
|
|
1600
1791
|
removeOldSchemaData[key] = void 0;
|
|
1601
1792
|
}
|
|
1602
1793
|
});
|
|
1603
1794
|
}
|
|
1604
|
-
const keys2 = Object.keys(
|
|
1795
|
+
const keys2 = Object.keys(get12(newSchema, PROPERTIES_KEY, {}));
|
|
1605
1796
|
const nestedData = {};
|
|
1606
1797
|
keys2.forEach((key) => {
|
|
1607
|
-
const formValue =
|
|
1608
|
-
let oldKeyedSchema =
|
|
1609
|
-
let newKeyedSchema =
|
|
1610
|
-
if (
|
|
1798
|
+
const formValue = get12(data, key);
|
|
1799
|
+
let oldKeyedSchema = get12(oldSchema, [PROPERTIES_KEY, key], {});
|
|
1800
|
+
let newKeyedSchema = get12(newSchema, [PROPERTIES_KEY, key], {});
|
|
1801
|
+
if (has5(oldKeyedSchema, REF_KEY)) {
|
|
1611
1802
|
oldKeyedSchema = retrieveSchema(
|
|
1612
1803
|
validator,
|
|
1613
1804
|
oldKeyedSchema,
|
|
@@ -1616,7 +1807,7 @@ function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, d
|
|
|
1616
1807
|
experimental_customMergeAllOf
|
|
1617
1808
|
);
|
|
1618
1809
|
}
|
|
1619
|
-
if (
|
|
1810
|
+
if (has5(newKeyedSchema, REF_KEY)) {
|
|
1620
1811
|
newKeyedSchema = retrieveSchema(
|
|
1621
1812
|
validator,
|
|
1622
1813
|
newKeyedSchema,
|
|
@@ -1625,10 +1816,10 @@ function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, d
|
|
|
1625
1816
|
experimental_customMergeAllOf
|
|
1626
1817
|
);
|
|
1627
1818
|
}
|
|
1628
|
-
const oldSchemaTypeForKey =
|
|
1629
|
-
const newSchemaTypeForKey =
|
|
1819
|
+
const oldSchemaTypeForKey = get12(oldKeyedSchema, "type");
|
|
1820
|
+
const newSchemaTypeForKey = get12(newKeyedSchema, "type");
|
|
1630
1821
|
if (!oldSchemaTypeForKey || oldSchemaTypeForKey === newSchemaTypeForKey) {
|
|
1631
|
-
if (
|
|
1822
|
+
if (has5(removeOldSchemaData, key)) {
|
|
1632
1823
|
delete removeOldSchemaData[key];
|
|
1633
1824
|
}
|
|
1634
1825
|
if (newSchemaTypeForKey === "object" || newSchemaTypeForKey === "array" && Array.isArray(formValue)) {
|
|
@@ -1644,17 +1835,17 @@ function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, d
|
|
|
1644
1835
|
nestedData[key] = itemData;
|
|
1645
1836
|
}
|
|
1646
1837
|
} else {
|
|
1647
|
-
const newOptionDefault =
|
|
1648
|
-
const oldOptionDefault =
|
|
1838
|
+
const newOptionDefault = get12(newKeyedSchema, "default", NO_VALUE);
|
|
1839
|
+
const oldOptionDefault = get12(oldKeyedSchema, "default", NO_VALUE);
|
|
1649
1840
|
if (newOptionDefault !== NO_VALUE && newOptionDefault !== formValue) {
|
|
1650
1841
|
if (oldOptionDefault === formValue) {
|
|
1651
1842
|
removeOldSchemaData[key] = newOptionDefault;
|
|
1652
|
-
} else if (
|
|
1843
|
+
} else if (get12(newKeyedSchema, "readOnly") === true) {
|
|
1653
1844
|
removeOldSchemaData[key] = void 0;
|
|
1654
1845
|
}
|
|
1655
1846
|
}
|
|
1656
|
-
const newOptionConst =
|
|
1657
|
-
const oldOptionConst =
|
|
1847
|
+
const newOptionConst = get12(newKeyedSchema, "const", NO_VALUE);
|
|
1848
|
+
const oldOptionConst = get12(oldKeyedSchema, "const", NO_VALUE);
|
|
1658
1849
|
if (newOptionConst !== NO_VALUE && newOptionConst !== formValue) {
|
|
1659
1850
|
removeOldSchemaData[key] = oldOptionConst === formValue ? newOptionConst : void 0;
|
|
1660
1851
|
}
|
|
@@ -1666,11 +1857,11 @@ function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, d
|
|
|
1666
1857
|
...removeOldSchemaData,
|
|
1667
1858
|
...nestedData
|
|
1668
1859
|
};
|
|
1669
|
-
} else if (
|
|
1670
|
-
let oldSchemaItems =
|
|
1671
|
-
let newSchemaItems =
|
|
1860
|
+
} else if (get12(oldSchema, "type") === "array" && get12(newSchema, "type") === "array" && Array.isArray(data)) {
|
|
1861
|
+
let oldSchemaItems = get12(oldSchema, "items");
|
|
1862
|
+
let newSchemaItems = get12(newSchema, "items");
|
|
1672
1863
|
if (typeof oldSchemaItems === "object" && typeof newSchemaItems === "object" && !Array.isArray(oldSchemaItems) && !Array.isArray(newSchemaItems)) {
|
|
1673
|
-
if (
|
|
1864
|
+
if (has5(oldSchemaItems, REF_KEY)) {
|
|
1674
1865
|
oldSchemaItems = retrieveSchema(
|
|
1675
1866
|
validator,
|
|
1676
1867
|
oldSchemaItems,
|
|
@@ -1679,7 +1870,7 @@ function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, d
|
|
|
1679
1870
|
experimental_customMergeAllOf
|
|
1680
1871
|
);
|
|
1681
1872
|
}
|
|
1682
|
-
if (
|
|
1873
|
+
if (has5(newSchemaItems, REF_KEY)) {
|
|
1683
1874
|
newSchemaItems = retrieveSchema(
|
|
1684
1875
|
validator,
|
|
1685
1876
|
newSchemaItems,
|
|
@@ -1688,10 +1879,10 @@ function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, d
|
|
|
1688
1879
|
experimental_customMergeAllOf
|
|
1689
1880
|
);
|
|
1690
1881
|
}
|
|
1691
|
-
const oldSchemaType =
|
|
1692
|
-
const newSchemaType =
|
|
1882
|
+
const oldSchemaType = get12(oldSchemaItems, "type");
|
|
1883
|
+
const newSchemaType = get12(newSchemaItems, "type");
|
|
1693
1884
|
if (!oldSchemaType || oldSchemaType === newSchemaType) {
|
|
1694
|
-
const maxItems =
|
|
1885
|
+
const maxItems = get12(newSchema, "maxItems", -1);
|
|
1695
1886
|
if (newSchemaType === "object") {
|
|
1696
1887
|
newFormData = data.reduce((newValue, aValue) => {
|
|
1697
1888
|
const itemValue = sanitizeDataForNewSchema(
|
|
@@ -1719,58 +1910,60 @@ function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, d
|
|
|
1719
1910
|
}
|
|
1720
1911
|
|
|
1721
1912
|
// src/schema/toIdSchema.ts
|
|
1722
|
-
import
|
|
1913
|
+
import get13 from "lodash/get";
|
|
1723
1914
|
function toIdSchemaInternal(validator, schema, idPrefix, idSeparator, id, rootSchema, formData, _recurseList = [], experimental_customMergeAllOf) {
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
if (
|
|
1915
|
+
const $id = id || idPrefix;
|
|
1916
|
+
const idSchema = { $id };
|
|
1917
|
+
if (typeof schema === "object") {
|
|
1918
|
+
if (REF_KEY in schema || DEPENDENCIES_KEY in schema || ALL_OF_KEY in schema) {
|
|
1919
|
+
const _schema = retrieveSchema(validator, schema, rootSchema, formData, experimental_customMergeAllOf);
|
|
1920
|
+
const sameSchemaIndex = _recurseList.findIndex((item) => deepEquals(item, _schema));
|
|
1921
|
+
if (sameSchemaIndex === -1) {
|
|
1922
|
+
return toIdSchemaInternal(
|
|
1923
|
+
validator,
|
|
1924
|
+
_schema,
|
|
1925
|
+
idPrefix,
|
|
1926
|
+
idSeparator,
|
|
1927
|
+
id,
|
|
1928
|
+
rootSchema,
|
|
1929
|
+
formData,
|
|
1930
|
+
_recurseList.concat(_schema),
|
|
1931
|
+
experimental_customMergeAllOf
|
|
1932
|
+
);
|
|
1933
|
+
}
|
|
1934
|
+
}
|
|
1935
|
+
if (ITEMS_KEY in schema && !get13(schema, [ITEMS_KEY, REF_KEY])) {
|
|
1728
1936
|
return toIdSchemaInternal(
|
|
1729
1937
|
validator,
|
|
1730
|
-
|
|
1938
|
+
get13(schema, ITEMS_KEY),
|
|
1731
1939
|
idPrefix,
|
|
1732
1940
|
idSeparator,
|
|
1733
1941
|
id,
|
|
1734
1942
|
rootSchema,
|
|
1735
1943
|
formData,
|
|
1736
|
-
_recurseList.concat(_schema),
|
|
1737
|
-
experimental_customMergeAllOf
|
|
1738
|
-
);
|
|
1739
|
-
}
|
|
1740
|
-
}
|
|
1741
|
-
if (ITEMS_KEY in schema && !get9(schema, [ITEMS_KEY, REF_KEY])) {
|
|
1742
|
-
return toIdSchemaInternal(
|
|
1743
|
-
validator,
|
|
1744
|
-
get9(schema, ITEMS_KEY),
|
|
1745
|
-
idPrefix,
|
|
1746
|
-
idSeparator,
|
|
1747
|
-
id,
|
|
1748
|
-
rootSchema,
|
|
1749
|
-
formData,
|
|
1750
|
-
_recurseList,
|
|
1751
|
-
experimental_customMergeAllOf
|
|
1752
|
-
);
|
|
1753
|
-
}
|
|
1754
|
-
const $id = id || idPrefix;
|
|
1755
|
-
const idSchema = { $id };
|
|
1756
|
-
if (getSchemaType(schema) === "object" && PROPERTIES_KEY in schema) {
|
|
1757
|
-
for (const name in schema.properties) {
|
|
1758
|
-
const field = get9(schema, [PROPERTIES_KEY, name]);
|
|
1759
|
-
const fieldId = idSchema[ID_KEY] + idSeparator + name;
|
|
1760
|
-
idSchema[name] = toIdSchemaInternal(
|
|
1761
|
-
validator,
|
|
1762
|
-
isObject(field) ? field : {},
|
|
1763
|
-
idPrefix,
|
|
1764
|
-
idSeparator,
|
|
1765
|
-
fieldId,
|
|
1766
|
-
rootSchema,
|
|
1767
|
-
// It's possible that formData is not an object -- this can happen if an
|
|
1768
|
-
// array item has just been added, but not populated with data yet
|
|
1769
|
-
get9(formData, [name]),
|
|
1770
1944
|
_recurseList,
|
|
1771
1945
|
experimental_customMergeAllOf
|
|
1772
1946
|
);
|
|
1773
1947
|
}
|
|
1948
|
+
if (getSchemaType(schema) === "object" && PROPERTIES_KEY in schema) {
|
|
1949
|
+
for (const name in schema.properties) {
|
|
1950
|
+
const field = schema[PROPERTIES_KEY][name];
|
|
1951
|
+
const fieldId = idSchema[ID_KEY] + idSeparator + name;
|
|
1952
|
+
idSchema[name] = toIdSchemaInternal(
|
|
1953
|
+
validator,
|
|
1954
|
+
field,
|
|
1955
|
+
idPrefix,
|
|
1956
|
+
idSeparator,
|
|
1957
|
+
fieldId,
|
|
1958
|
+
rootSchema,
|
|
1959
|
+
// It's possible that formData is not an object -- this can happen if an
|
|
1960
|
+
// array item has just been added, but not populated with data yet
|
|
1961
|
+
get13(formData, [name]),
|
|
1962
|
+
_recurseList,
|
|
1963
|
+
experimental_customMergeAllOf
|
|
1964
|
+
);
|
|
1965
|
+
}
|
|
1966
|
+
}
|
|
1774
1967
|
}
|
|
1775
1968
|
return idSchema;
|
|
1776
1969
|
}
|
|
@@ -1789,7 +1982,7 @@ function toIdSchema(validator, schema, id, rootSchema, formData, idPrefix = "roo
|
|
|
1789
1982
|
}
|
|
1790
1983
|
|
|
1791
1984
|
// src/schema/toPathSchema.ts
|
|
1792
|
-
import
|
|
1985
|
+
import get14 from "lodash/get";
|
|
1793
1986
|
import set2 from "lodash/set";
|
|
1794
1987
|
function toPathSchemaInternal(validator, schema, name, rootSchema, formData, _recurseList = [], experimental_customMergeAllOf) {
|
|
1795
1988
|
if (REF_KEY in schema || DEPENDENCIES_KEY in schema || ALL_OF_KEY in schema) {
|
|
@@ -1882,7 +2075,7 @@ function toPathSchemaInternal(validator, schema, name, rootSchema, formData, _re
|
|
|
1882
2075
|
}
|
|
1883
2076
|
} else if (PROPERTIES_KEY in schema) {
|
|
1884
2077
|
for (const property in schema.properties) {
|
|
1885
|
-
const field =
|
|
2078
|
+
const field = get14(schema, [PROPERTIES_KEY, property], {});
|
|
1886
2079
|
pathSchema[property] = toPathSchemaInternal(
|
|
1887
2080
|
validator,
|
|
1888
2081
|
field,
|
|
@@ -1890,7 +2083,7 @@ function toPathSchemaInternal(validator, schema, name, rootSchema, formData, _re
|
|
|
1890
2083
|
rootSchema,
|
|
1891
2084
|
// It's possible that formData is not an object -- this can happen if an
|
|
1892
2085
|
// array item has just been added, but not populated with data yet
|
|
1893
|
-
|
|
2086
|
+
get14(formData, [property]),
|
|
1894
2087
|
_recurseList,
|
|
1895
2088
|
experimental_customMergeAllOf
|
|
1896
2089
|
);
|
|
@@ -1940,6 +2133,47 @@ var SchemaUtils = class {
|
|
|
1940
2133
|
}
|
|
1941
2134
|
return this.validator !== validator || !deepEquals(this.rootSchema, rootSchema) || !deepEquals(this.experimental_defaultFormStateBehavior, experimental_defaultFormStateBehavior) || this.experimental_customMergeAllOf !== experimental_customMergeAllOf;
|
|
1942
2135
|
}
|
|
2136
|
+
/** Finds the field specified by the `path` within the root or recursed `schema`. If there is no field for the specified
|
|
2137
|
+
* `path`, then the default `{ field: undefined, isRequired: undefined }` is returned. It determines whether a leaf
|
|
2138
|
+
* field is in the `required` list for its parent and if so, it is marked as required on return.
|
|
2139
|
+
*
|
|
2140
|
+
* @param schema - The current node within the JSON schema
|
|
2141
|
+
* @param path - The remaining keys in the path to the desired field
|
|
2142
|
+
* @param [formData] - The form data that is used to determine which oneOf option
|
|
2143
|
+
* @returns - An object that contains the field and its required state. If no field can be found then
|
|
2144
|
+
* `{ field: undefined, isRequired: undefined }` is returned.
|
|
2145
|
+
*/
|
|
2146
|
+
findFieldInSchema(schema, path, formData) {
|
|
2147
|
+
return findFieldInSchema(
|
|
2148
|
+
this.validator,
|
|
2149
|
+
this.rootSchema,
|
|
2150
|
+
schema,
|
|
2151
|
+
path,
|
|
2152
|
+
formData,
|
|
2153
|
+
this.experimental_customMergeAllOf
|
|
2154
|
+
);
|
|
2155
|
+
}
|
|
2156
|
+
/** Finds the oneOf option inside the `schema['any/oneOf']` list which has the `properties[selectorField].default` that
|
|
2157
|
+
* matches the `formData[selectorField]` value. For the purposes of this function, `selectorField` is either
|
|
2158
|
+
* `schema.discriminator.propertyName` or `fallbackField`.
|
|
2159
|
+
*
|
|
2160
|
+
* @param schema - The schema element in which to search for the selected oneOf option
|
|
2161
|
+
* @param fallbackField - The field to use as a backup selector field if the schema does not have a required field
|
|
2162
|
+
* @param xxx - Either `oneOf` or `anyOf`, defines which value is being sought
|
|
2163
|
+
* @param [formData={}] - The form data that is used to determine which oneOf option
|
|
2164
|
+
* @returns - The anyOf/oneOf option that matches the selector field in the schema or undefined if nothing is selected
|
|
2165
|
+
*/
|
|
2166
|
+
findSelectedOptionInXxxOf(schema, fallbackField, xxx, formData) {
|
|
2167
|
+
return findSelectedOptionInXxxOf(
|
|
2168
|
+
this.validator,
|
|
2169
|
+
this.rootSchema,
|
|
2170
|
+
schema,
|
|
2171
|
+
fallbackField,
|
|
2172
|
+
xxx,
|
|
2173
|
+
formData,
|
|
2174
|
+
this.experimental_customMergeAllOf
|
|
2175
|
+
);
|
|
2176
|
+
}
|
|
1943
2177
|
/** Returns the superset of `formData` that includes the given set updated to include any missing fields that have
|
|
1944
2178
|
* computed to have defaults provided in the `schema`.
|
|
1945
2179
|
*
|
|
@@ -2015,18 +2249,16 @@ var SchemaUtils = class {
|
|
|
2015
2249
|
getFirstMatchingOption(formData, options, discriminatorField) {
|
|
2016
2250
|
return getFirstMatchingOption(this.validator, formData, options, this.rootSchema, discriminatorField);
|
|
2017
2251
|
}
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
getMatchingOption(formData, options, discriminatorField) {
|
|
2029
|
-
return getMatchingOption(this.validator, formData, options, this.rootSchema, discriminatorField);
|
|
2252
|
+
getFromSchema(schema, path, defaultValue) {
|
|
2253
|
+
return getFromSchema(
|
|
2254
|
+
this.validator,
|
|
2255
|
+
this.rootSchema,
|
|
2256
|
+
schema,
|
|
2257
|
+
path,
|
|
2258
|
+
// @ts-expect-error TS2769: No overload matches this call
|
|
2259
|
+
defaultValue,
|
|
2260
|
+
this.experimental_customMergeAllOf
|
|
2261
|
+
);
|
|
2030
2262
|
}
|
|
2031
2263
|
/** Checks to see if the `schema` and `uiSchema` combination represents an array of files
|
|
2032
2264
|
*
|
|
@@ -2053,20 +2285,6 @@ var SchemaUtils = class {
|
|
|
2053
2285
|
isSelect(schema) {
|
|
2054
2286
|
return isSelect(this.validator, schema, this.rootSchema, this.experimental_customMergeAllOf);
|
|
2055
2287
|
}
|
|
2056
|
-
/** Merges the errors in `additionalErrorSchema` into the existing `validationData` by combining the hierarchies in
|
|
2057
|
-
* the two `ErrorSchema`s and then appending the error list from the `additionalErrorSchema` obtained by calling
|
|
2058
|
-
* `getValidator().toErrorList()` onto the `errors` in the `validationData`. If no `additionalErrorSchema` is passed,
|
|
2059
|
-
* then `validationData` is returned.
|
|
2060
|
-
*
|
|
2061
|
-
* @param validationData - The current `ValidationData` into which to merge the additional errors
|
|
2062
|
-
* @param [additionalErrorSchema] - The additional set of errors
|
|
2063
|
-
* @returns - The `validationData` with the additional errors from `additionalErrorSchema` merged into it, if provided.
|
|
2064
|
-
* @deprecated - Use the `validationDataMerge()` function exported from `@rjsf/utils` instead. This function will be
|
|
2065
|
-
* removed in the next major release.
|
|
2066
|
-
*/
|
|
2067
|
-
mergeValidationData(validationData, additionalErrorSchema) {
|
|
2068
|
-
return mergeValidationData(this.validator, validationData, additionalErrorSchema);
|
|
2069
|
-
}
|
|
2070
2288
|
/** Retrieves an expanded schema that has had all of its conditions, additional properties, references and
|
|
2071
2289
|
* dependencies resolved and merged into the `schema` given a `rawFormData` that is used to do the potentially
|
|
2072
2290
|
* recursive resolution.
|
|
@@ -2283,7 +2501,7 @@ function enumOptionsSelectValue(valueIndex, selected, allEnumOptions = []) {
|
|
|
2283
2501
|
|
|
2284
2502
|
// src/ErrorSchemaBuilder.ts
|
|
2285
2503
|
import cloneDeep from "lodash/cloneDeep";
|
|
2286
|
-
import
|
|
2504
|
+
import get15 from "lodash/get";
|
|
2287
2505
|
import set3 from "lodash/set";
|
|
2288
2506
|
import setWith from "lodash/setWith";
|
|
2289
2507
|
var ErrorSchemaBuilder = class {
|
|
@@ -2312,7 +2530,7 @@ var ErrorSchemaBuilder = class {
|
|
|
2312
2530
|
*/
|
|
2313
2531
|
getOrCreateErrorBlock(pathOfError) {
|
|
2314
2532
|
const hasPath = Array.isArray(pathOfError) && pathOfError.length > 0 || typeof pathOfError === "string";
|
|
2315
|
-
let errorBlock = hasPath ?
|
|
2533
|
+
let errorBlock = hasPath ? get15(this.errorSchema, pathOfError) : this.errorSchema;
|
|
2316
2534
|
if (!errorBlock && pathOfError) {
|
|
2317
2535
|
errorBlock = {};
|
|
2318
2536
|
setWith(this.errorSchema, pathOfError, errorBlock, Object);
|
|
@@ -2338,7 +2556,7 @@ var ErrorSchemaBuilder = class {
|
|
|
2338
2556
|
*/
|
|
2339
2557
|
addErrors(errorOrList, pathOfError) {
|
|
2340
2558
|
const errorBlock = this.getOrCreateErrorBlock(pathOfError);
|
|
2341
|
-
let errorsList =
|
|
2559
|
+
let errorsList = get15(errorBlock, ERRORS_KEY);
|
|
2342
2560
|
if (!Array.isArray(errorsList)) {
|
|
2343
2561
|
errorsList = [];
|
|
2344
2562
|
errorBlock[ERRORS_KEY] = errorsList;
|
|
@@ -2474,6 +2692,10 @@ function getTemplate(name, registry, uiOptions = {}) {
|
|
|
2474
2692
|
if (name === "ButtonTemplates") {
|
|
2475
2693
|
return templates[name];
|
|
2476
2694
|
}
|
|
2695
|
+
if (Object.hasOwn(uiOptions, name) && typeof uiOptions[name] === "string" && Object.hasOwn(templates, uiOptions[name])) {
|
|
2696
|
+
const key = uiOptions[name];
|
|
2697
|
+
return templates[key];
|
|
2698
|
+
}
|
|
2477
2699
|
return (
|
|
2478
2700
|
// Evaluating uiOptions[name] results in TS2590: Expression produces a union type that is too complex to represent
|
|
2479
2701
|
// To avoid that, we cast uiOptions to `any` before accessing the name field
|
|
@@ -2481,10 +2703,31 @@ function getTemplate(name, registry, uiOptions = {}) {
|
|
|
2481
2703
|
);
|
|
2482
2704
|
}
|
|
2483
2705
|
|
|
2706
|
+
// src/getTestIds.ts
|
|
2707
|
+
import { nanoid } from "nanoid";
|
|
2708
|
+
import get16 from "lodash/get";
|
|
2709
|
+
function getTestIds() {
|
|
2710
|
+
if (typeof process === "undefined" || get16(process, "env.NODE_ENV") !== "test") {
|
|
2711
|
+
return {};
|
|
2712
|
+
}
|
|
2713
|
+
const ids = /* @__PURE__ */ new Map();
|
|
2714
|
+
return new Proxy(
|
|
2715
|
+
{},
|
|
2716
|
+
{
|
|
2717
|
+
get(_obj, prop) {
|
|
2718
|
+
if (!ids.has(prop)) {
|
|
2719
|
+
ids.set(prop, nanoid());
|
|
2720
|
+
}
|
|
2721
|
+
return ids.get(prop);
|
|
2722
|
+
}
|
|
2723
|
+
}
|
|
2724
|
+
);
|
|
2725
|
+
}
|
|
2726
|
+
|
|
2484
2727
|
// src/getWidget.tsx
|
|
2485
2728
|
import { createElement } from "react";
|
|
2486
2729
|
import ReactIs from "react-is";
|
|
2487
|
-
import
|
|
2730
|
+
import get17 from "lodash/get";
|
|
2488
2731
|
import set4 from "lodash/set";
|
|
2489
2732
|
import { jsx } from "react/jsx-runtime";
|
|
2490
2733
|
var widgetMap = {
|
|
@@ -2540,7 +2783,7 @@ var widgetMap = {
|
|
|
2540
2783
|
}
|
|
2541
2784
|
};
|
|
2542
2785
|
function mergeWidgetOptions(AWidget) {
|
|
2543
|
-
let MergedWidget =
|
|
2786
|
+
let MergedWidget = get17(AWidget, "MergedWidget");
|
|
2544
2787
|
if (!MergedWidget) {
|
|
2545
2788
|
const defaultOptions = AWidget.defaultProps && AWidget.defaultProps.options || {};
|
|
2546
2789
|
MergedWidget = ({ options, ...props }) => {
|
|
@@ -2584,10 +2827,16 @@ function hashString(string) {
|
|
|
2584
2827
|
}
|
|
2585
2828
|
return hash.toString(16);
|
|
2586
2829
|
}
|
|
2587
|
-
function
|
|
2830
|
+
function sortedJSONStringify(object) {
|
|
2588
2831
|
const allKeys = /* @__PURE__ */ new Set();
|
|
2589
|
-
JSON.stringify(
|
|
2590
|
-
return
|
|
2832
|
+
JSON.stringify(object, (key, value) => (allKeys.add(key), value));
|
|
2833
|
+
return JSON.stringify(object, Array.from(allKeys).sort());
|
|
2834
|
+
}
|
|
2835
|
+
function hashObject(object) {
|
|
2836
|
+
return hashString(sortedJSONStringify(object));
|
|
2837
|
+
}
|
|
2838
|
+
function hashForSchema(schema) {
|
|
2839
|
+
return hashObject(schema);
|
|
2591
2840
|
}
|
|
2592
2841
|
|
|
2593
2842
|
// src/hasWidget.ts
|
|
@@ -2632,6 +2881,9 @@ function ariaDescribedByIds(id, includeExamples = false) {
|
|
|
2632
2881
|
function optionId(id, optionIndex) {
|
|
2633
2882
|
return `${id}-${optionIndex}`;
|
|
2634
2883
|
}
|
|
2884
|
+
function buttonId(id, btn) {
|
|
2885
|
+
return idGenerator(id, btn);
|
|
2886
|
+
}
|
|
2635
2887
|
|
|
2636
2888
|
// src/labelValue.ts
|
|
2637
2889
|
function labelValue(label, hideLabel, fallback) {
|
|
@@ -2643,6 +2895,17 @@ function localToUTC(dateString) {
|
|
|
2643
2895
|
return dateString ? new Date(dateString).toJSON() : void 0;
|
|
2644
2896
|
}
|
|
2645
2897
|
|
|
2898
|
+
// src/lookupFromFormContext.ts
|
|
2899
|
+
import get18 from "lodash/get";
|
|
2900
|
+
import has6 from "lodash/has";
|
|
2901
|
+
function lookupFromFormContext(regOrFc, toLookup, fallback) {
|
|
2902
|
+
const lookupPath = [LOOKUP_MAP_NAME];
|
|
2903
|
+
if (has6(regOrFc, FORM_CONTEXT_NAME)) {
|
|
2904
|
+
lookupPath.unshift(FORM_CONTEXT_NAME);
|
|
2905
|
+
}
|
|
2906
|
+
return get18(regOrFc, [...lookupPath, toLookup], fallback);
|
|
2907
|
+
}
|
|
2908
|
+
|
|
2646
2909
|
// src/orderProperties.ts
|
|
2647
2910
|
function orderProperties(properties, order) {
|
|
2648
2911
|
if (!Array.isArray(order)) {
|
|
@@ -2819,7 +3082,7 @@ function utcToLocal(jsonDate) {
|
|
|
2819
3082
|
}
|
|
2820
3083
|
|
|
2821
3084
|
// src/validationDataMerge.ts
|
|
2822
|
-
import
|
|
3085
|
+
import isEmpty4 from "lodash/isEmpty";
|
|
2823
3086
|
function validationDataMerge(validationData, additionalErrorSchema) {
|
|
2824
3087
|
if (!additionalErrorSchema) {
|
|
2825
3088
|
return validationData;
|
|
@@ -2827,7 +3090,7 @@ function validationDataMerge(validationData, additionalErrorSchema) {
|
|
|
2827
3090
|
const { errors: oldErrors, errorSchema: oldErrorSchema } = validationData;
|
|
2828
3091
|
let errors = toErrorList(additionalErrorSchema);
|
|
2829
3092
|
let errorSchema = additionalErrorSchema;
|
|
2830
|
-
if (!
|
|
3093
|
+
if (!isEmpty4(oldErrorSchema)) {
|
|
2831
3094
|
errorSchema = mergeObjects(oldErrorSchema, additionalErrorSchema, true);
|
|
2832
3095
|
errors = [...oldErrors].concat(errors);
|
|
2833
3096
|
}
|
|
@@ -2868,7 +3131,7 @@ function withIdRefPrefix(schemaNode) {
|
|
|
2868
3131
|
import keys from "lodash/keys";
|
|
2869
3132
|
import pickBy from "lodash/pickBy";
|
|
2870
3133
|
import isPlainObject4 from "lodash/isPlainObject";
|
|
2871
|
-
import
|
|
3134
|
+
import get19 from "lodash/get";
|
|
2872
3135
|
import difference from "lodash/difference";
|
|
2873
3136
|
function getChangedFields(a, b) {
|
|
2874
3137
|
const aIsPlainObject = isPlainObject4(a);
|
|
@@ -2881,7 +3144,7 @@ function getChangedFields(a, b) {
|
|
|
2881
3144
|
} else if (!aIsPlainObject && bIsPlainObject) {
|
|
2882
3145
|
return keys(b);
|
|
2883
3146
|
} else {
|
|
2884
|
-
const unequalFields = keys(pickBy(a, (value, key) => !deepEquals(value,
|
|
3147
|
+
const unequalFields = keys(pickBy(a, (value, key) => !deepEquals(value, get19(b, key))));
|
|
2885
3148
|
const diffFields = difference(keys(b), keys(a));
|
|
2886
3149
|
return [...unequalFields, ...diffFields];
|
|
2887
3150
|
}
|
|
@@ -2891,6 +3154,7 @@ function getChangedFields(a, b) {
|
|
|
2891
3154
|
var TranslatableString = /* @__PURE__ */ ((TranslatableString2) => {
|
|
2892
3155
|
TranslatableString2["ArrayItemTitle"] = "Item";
|
|
2893
3156
|
TranslatableString2["MissingItems"] = "Missing items definition";
|
|
3157
|
+
TranslatableString2["EmptyArray"] = "No items yet. Use the button below to add some.";
|
|
2894
3158
|
TranslatableString2["YesLabel"] = "Yes";
|
|
2895
3159
|
TranslatableString2["NoLabel"] = "No";
|
|
2896
3160
|
TranslatableString2["CloseLabel"] = "Close";
|
|
@@ -2925,7 +3189,7 @@ var TranslatableString = /* @__PURE__ */ ((TranslatableString2) => {
|
|
|
2925
3189
|
import forEach from "lodash/forEach";
|
|
2926
3190
|
|
|
2927
3191
|
// src/parser/ParserValidator.ts
|
|
2928
|
-
import
|
|
3192
|
+
import get20 from "lodash/get";
|
|
2929
3193
|
var ParserValidator = class {
|
|
2930
3194
|
/** Construct the ParserValidator for the given `rootSchema`. This `rootSchema` will be stashed in the `schemaMap`
|
|
2931
3195
|
* first.
|
|
@@ -2951,7 +3215,7 @@ var ParserValidator = class {
|
|
|
2951
3215
|
* @param hash - The hash value at which to map the schema
|
|
2952
3216
|
*/
|
|
2953
3217
|
addSchema(schema, hash) {
|
|
2954
|
-
const key =
|
|
3218
|
+
const key = get20(schema, ID_KEY, hash);
|
|
2955
3219
|
const identifiedSchema = { ...schema, [ID_KEY]: key };
|
|
2956
3220
|
const existing = this.schemaMap[key];
|
|
2957
3221
|
if (!existing) {
|
|
@@ -3050,20 +3314,24 @@ export {
|
|
|
3050
3314
|
DEFAULT_KEY,
|
|
3051
3315
|
DEFINITIONS_KEY,
|
|
3052
3316
|
DEPENDENCIES_KEY,
|
|
3317
|
+
DISCRIMINATOR_PATH,
|
|
3053
3318
|
ENUM_KEY,
|
|
3054
3319
|
ERRORS_KEY,
|
|
3055
3320
|
ErrorSchemaBuilder,
|
|
3321
|
+
FORM_CONTEXT_NAME,
|
|
3056
3322
|
ID_KEY,
|
|
3057
3323
|
IF_KEY,
|
|
3058
3324
|
ITEMS_KEY,
|
|
3059
3325
|
JUNK_OPTION_ID,
|
|
3326
|
+
LOOKUP_MAP_NAME,
|
|
3060
3327
|
NAME_KEY,
|
|
3061
3328
|
ONE_OF_KEY,
|
|
3329
|
+
PATTERN_PROPERTIES_KEY,
|
|
3062
3330
|
PROPERTIES_KEY,
|
|
3331
|
+
READONLY_KEY,
|
|
3063
3332
|
REF_KEY,
|
|
3064
3333
|
REQUIRED_KEY,
|
|
3065
3334
|
RJSF_ADDITIONAL_PROPERTIES_FLAG,
|
|
3066
|
-
RJSF_ADDITONAL_PROPERTIES_FLAG,
|
|
3067
3335
|
ROOT_SCHEMA_PREFIX,
|
|
3068
3336
|
SUBMIT_BTN_OPTIONS_KEY,
|
|
3069
3337
|
TranslatableString,
|
|
@@ -3074,6 +3342,7 @@ export {
|
|
|
3074
3342
|
allowAdditionalItems,
|
|
3075
3343
|
ariaDescribedByIds,
|
|
3076
3344
|
asNumber,
|
|
3345
|
+
buttonId,
|
|
3077
3346
|
canExpand,
|
|
3078
3347
|
createErrorHandler,
|
|
3079
3348
|
createSchemaUtils,
|
|
@@ -3089,7 +3358,9 @@ export {
|
|
|
3089
3358
|
enumOptionsValueForIndex,
|
|
3090
3359
|
errorId,
|
|
3091
3360
|
examplesId,
|
|
3361
|
+
findFieldInSchema,
|
|
3092
3362
|
findSchemaDefinition,
|
|
3363
|
+
findSelectedOptionInXxxOf,
|
|
3093
3364
|
getChangedFields,
|
|
3094
3365
|
getClosestMatchingOption,
|
|
3095
3366
|
getDateElementProps,
|
|
@@ -3097,17 +3368,20 @@ export {
|
|
|
3097
3368
|
getDiscriminatorFieldFromSchema,
|
|
3098
3369
|
getDisplayLabel,
|
|
3099
3370
|
getFirstMatchingOption,
|
|
3371
|
+
getFromSchema,
|
|
3100
3372
|
getInputProps,
|
|
3101
|
-
getMatchingOption,
|
|
3102
3373
|
getOptionMatchingSimpleDiscriminator,
|
|
3103
3374
|
getSchemaType,
|
|
3104
3375
|
getSubmitButtonOptions,
|
|
3105
3376
|
getTemplate,
|
|
3377
|
+
getTestIds,
|
|
3106
3378
|
getUiOptions,
|
|
3107
3379
|
getWidget,
|
|
3108
3380
|
guessType,
|
|
3109
3381
|
hasWidget,
|
|
3110
3382
|
hashForSchema,
|
|
3383
|
+
hashObject,
|
|
3384
|
+
hashString,
|
|
3111
3385
|
helpId,
|
|
3112
3386
|
isConstant,
|
|
3113
3387
|
isCustomWidget,
|
|
@@ -3118,10 +3392,10 @@ export {
|
|
|
3118
3392
|
isSelect,
|
|
3119
3393
|
labelValue,
|
|
3120
3394
|
localToUTC,
|
|
3395
|
+
lookupFromFormContext,
|
|
3121
3396
|
mergeDefaultsWithFormData,
|
|
3122
3397
|
mergeObjects,
|
|
3123
3398
|
mergeSchemas,
|
|
3124
|
-
mergeValidationData,
|
|
3125
3399
|
optionId,
|
|
3126
3400
|
optionsList,
|
|
3127
3401
|
orderProperties,
|
|
@@ -3134,6 +3408,7 @@ export {
|
|
|
3134
3408
|
schemaParser,
|
|
3135
3409
|
schemaRequiresTrueValue,
|
|
3136
3410
|
shouldRender,
|
|
3411
|
+
sortedJSONStringify,
|
|
3137
3412
|
titleId,
|
|
3138
3413
|
toConstant,
|
|
3139
3414
|
toDateString,
|