@rjsf/utils 6.0.0-alpha.0 → 6.0.0-beta.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +1347 -642
- package/dist/index.js.map +4 -4
- package/dist/utils.esm.js +1324 -619
- package/dist/utils.esm.js.map +4 -4
- package/dist/utils.umd.js +1266 -590
- package/lib/ErrorSchemaBuilder.d.ts +8 -4
- package/lib/ErrorSchemaBuilder.js +10 -8
- package/lib/ErrorSchemaBuilder.js.map +1 -1
- package/lib/allowAdditionalItems.d.ts +1 -1
- package/lib/allowAdditionalItems.js +1 -1
- package/lib/allowAdditionalItems.js.map +1 -1
- package/lib/asNumber.js.map +1 -1
- package/lib/canExpand.d.ts +2 -2
- package/lib/canExpand.js +2 -2
- package/lib/canExpand.js.map +1 -1
- package/lib/constIsAjvDataReference.d.ts +9 -0
- package/lib/constIsAjvDataReference.js +15 -0
- package/lib/constIsAjvDataReference.js.map +1 -0
- package/lib/constants.d.ts +15 -3
- package/lib/constants.js +15 -3
- package/lib/constants.js.map +1 -1
- package/lib/createErrorHandler.d.ts +1 -1
- package/lib/createErrorHandler.js +2 -2
- package/lib/createErrorHandler.js.map +1 -1
- package/lib/createSchemaUtils.d.ts +3 -2
- package/lib/createSchemaUtils.js +56 -46
- package/lib/createSchemaUtils.js.map +1 -1
- package/lib/dataURItoBlob.js.map +1 -1
- package/lib/dateRangeOptions.d.ts +1 -1
- package/lib/dateRangeOptions.js +1 -1
- package/lib/dateRangeOptions.js.map +1 -1
- package/lib/deepEquals.js +1 -1
- package/lib/deepEquals.js.map +1 -1
- package/lib/englishStringTranslator.d.ts +1 -1
- package/lib/englishStringTranslator.js +1 -1
- package/lib/enumOptionsDeselectValue.d.ts +1 -1
- package/lib/enumOptionsDeselectValue.js +4 -4
- package/lib/enumOptionsDeselectValue.js.map +1 -1
- package/lib/enumOptionsIndexForValue.d.ts +1 -1
- package/lib/enumOptionsIndexForValue.js +1 -1
- package/lib/enumOptionsIndexForValue.js.map +1 -1
- package/lib/enumOptionsIsSelected.d.ts +1 -1
- package/lib/enumOptionsIsSelected.js +3 -3
- package/lib/enumOptionsIsSelected.js.map +1 -1
- package/lib/enumOptionsSelectValue.d.ts +1 -1
- package/lib/enumOptionsSelectValue.js +2 -2
- package/lib/enumOptionsSelectValue.js.map +1 -1
- package/lib/enumOptionsValueForIndex.d.ts +1 -1
- package/lib/enumOptionsValueForIndex.js.map +1 -1
- package/lib/enums.d.ts +2 -0
- package/lib/enums.js +2 -0
- package/lib/enums.js.map +1 -1
- package/lib/findSchemaDefinition.d.ts +5 -3
- package/lib/findSchemaDefinition.js +54 -11
- package/lib/findSchemaDefinition.js.map +1 -1
- package/lib/getChangedFields.d.ts +17 -0
- package/lib/getChangedFields.js +42 -0
- package/lib/getChangedFields.js.map +1 -0
- package/lib/getDateElementProps.d.ts +1 -1
- package/lib/getDateElementProps.js.map +1 -1
- package/lib/getDiscriminatorFieldFromSchema.d.ts +1 -1
- package/lib/getDiscriminatorFieldFromSchema.js +4 -3
- package/lib/getDiscriminatorFieldFromSchema.js.map +1 -1
- package/lib/getInputProps.d.ts +1 -1
- package/lib/getInputProps.js +4 -1
- package/lib/getInputProps.js.map +1 -1
- package/lib/getOptionMatchingSimpleDiscriminator.d.ts +1 -1
- package/lib/getOptionMatchingSimpleDiscriminator.js +2 -2
- package/lib/getOptionMatchingSimpleDiscriminator.js.map +1 -1
- package/lib/getSchemaType.d.ts +2 -1
- package/lib/getSchemaType.js +3 -2
- package/lib/getSchemaType.js.map +1 -1
- package/lib/getSubmitButtonOptions.d.ts +1 -1
- package/lib/getSubmitButtonOptions.js +2 -2
- package/lib/getSubmitButtonOptions.js.map +1 -1
- package/lib/getTemplate.d.ts +1 -1
- package/lib/getTemplate.js +9 -0
- package/lib/getTemplate.js.map +1 -1
- package/lib/getTestIds.d.ts +17 -0
- package/lib/getTestIds.js +34 -0
- package/lib/getTestIds.js.map +1 -0
- package/lib/getUiOptions.d.ts +1 -1
- package/lib/getUiOptions.js +2 -2
- package/lib/getUiOptions.js.map +1 -1
- package/lib/getWidget.d.ts +1 -1
- package/lib/getWidget.js +3 -3
- package/lib/getWidget.js.map +1 -1
- package/lib/guessType.d.ts +1 -1
- package/lib/guessType.js.map +1 -1
- package/lib/hasWidget.d.ts +1 -1
- package/lib/hasWidget.js +1 -1
- package/lib/hasWidget.js.map +1 -1
- package/lib/hashForSchema.d.ts +23 -1
- package/lib/hashForSchema.js +24 -6
- package/lib/hashForSchema.js.map +1 -1
- package/lib/idGenerators.d.ts +8 -1
- package/lib/idGenerators.js +11 -2
- package/lib/idGenerators.js.map +1 -1
- package/lib/index.d.ts +63 -60
- package/lib/index.js +63 -60
- package/lib/index.js.map +1 -1
- package/lib/isConstant.d.ts +1 -1
- package/lib/isConstant.js +1 -1
- package/lib/isCustomWidget.d.ts +1 -1
- package/lib/isCustomWidget.js +1 -1
- package/lib/isFixedItems.d.ts +1 -1
- package/lib/isFixedItems.js +1 -1
- package/lib/isObject.d.ts +2 -2
- package/lib/isObject.js +11 -4
- package/lib/isObject.js.map +1 -1
- package/lib/lookupFromFormContext.d.ts +11 -0
- package/lib/lookupFromFormContext.js +20 -0
- package/lib/lookupFromFormContext.js.map +1 -0
- package/lib/mergeDefaultsWithFormData.d.ts +8 -2
- package/lib/mergeDefaultsWithFormData.js +39 -10
- package/lib/mergeDefaultsWithFormData.js.map +1 -1
- package/lib/mergeObjects.d.ts +1 -1
- package/lib/mergeObjects.js +1 -1
- package/lib/mergeObjects.js.map +1 -1
- package/lib/mergeSchemas.d.ts +1 -1
- package/lib/mergeSchemas.js +4 -4
- package/lib/mergeSchemas.js.map +1 -1
- package/lib/optionsList.d.ts +9 -7
- package/lib/optionsList.js +30 -19
- package/lib/optionsList.js.map +1 -1
- package/lib/orderProperties.js.map +1 -1
- package/lib/pad.js.map +1 -1
- package/lib/parseDateString.d.ts +1 -1
- package/lib/parseDateString.js +1 -1
- package/lib/parseDateString.js.map +1 -1
- package/lib/parser/ParserValidator.d.ts +1 -1
- package/lib/parser/ParserValidator.js +6 -6
- package/lib/parser/ParserValidator.js.map +1 -1
- package/lib/parser/index.d.ts +2 -2
- package/lib/parser/index.js +1 -1
- package/lib/parser/schemaParser.d.ts +2 -2
- package/lib/parser/schemaParser.js +6 -6
- package/lib/parser/schemaParser.js.map +1 -1
- package/lib/rangeSpec.d.ts +2 -2
- package/lib/rangeSpec.js.map +1 -1
- package/lib/replaceStringParameters.js.map +1 -1
- package/lib/schema/findFieldInSchema.d.ts +19 -0
- package/lib/schema/findFieldInSchema.js +61 -0
- package/lib/schema/findFieldInSchema.js.map +1 -0
- package/lib/schema/findSelectedOptionInXxxOf.d.ts +16 -0
- package/lib/schema/findSelectedOptionInXxxOf.js +34 -0
- package/lib/schema/findSelectedOptionInXxxOf.js.map +1 -0
- package/lib/schema/getClosestMatchingOption.d.ts +5 -3
- package/lib/schema/getClosestMatchingOption.js +28 -20
- package/lib/schema/getClosestMatchingOption.js.map +1 -1
- package/lib/schema/getDefaultFormState.d.ts +60 -13
- package/lib/schema/getDefaultFormState.js +316 -167
- package/lib/schema/getDefaultFormState.js.map +1 -1
- package/lib/schema/getDisplayLabel.d.ts +3 -2
- package/lib/schema/getDisplayLabel.js +10 -9
- package/lib/schema/getDisplayLabel.js.map +1 -1
- package/lib/schema/getFirstMatchingOption.d.ts +1 -1
- package/lib/schema/getFirstMatchingOption.js +70 -2
- package/lib/schema/getFirstMatchingOption.js.map +1 -1
- package/lib/schema/getFromSchema.d.ts +14 -0
- package/lib/schema/getFromSchema.js +39 -0
- package/lib/schema/getFromSchema.js.map +1 -0
- package/lib/schema/index.d.ts +15 -14
- package/lib/schema/index.js +15 -14
- package/lib/schema/index.js.map +1 -1
- package/lib/schema/isFilesArray.d.ts +3 -2
- package/lib/schema/isFilesArray.js +5 -4
- package/lib/schema/isFilesArray.js.map +1 -1
- package/lib/schema/isMultiSelect.d.ts +3 -2
- package/lib/schema/isMultiSelect.js +4 -3
- package/lib/schema/isMultiSelect.js.map +1 -1
- package/lib/schema/isSelect.d.ts +3 -2
- package/lib/schema/isSelect.js +5 -4
- package/lib/schema/isSelect.js.map +1 -1
- package/lib/schema/retrieveSchema.d.ts +30 -12
- package/lib/schema/retrieveSchema.js +153 -70
- package/lib/schema/retrieveSchema.js.map +1 -1
- package/lib/schema/sanitizeDataForNewSchema.d.ts +3 -2
- package/lib/schema/sanitizeDataForNewSchema.js +12 -11
- package/lib/schema/sanitizeDataForNewSchema.js.map +1 -1
- package/lib/schema/toIdSchema.d.ts +3 -2
- package/lib/schema/toIdSchema.js +30 -27
- package/lib/schema/toIdSchema.js.map +1 -1
- package/lib/schema/toPathSchema.d.ts +3 -2
- package/lib/schema/toPathSchema.js +22 -20
- package/lib/schema/toPathSchema.js.map +1 -1
- package/lib/schemaRequiresTrueValue.d.ts +1 -1
- package/lib/schemaRequiresTrueValue.js.map +1 -1
- package/lib/shouldRender.js +1 -1
- package/lib/toConstant.d.ts +1 -1
- package/lib/toConstant.js +1 -1
- package/lib/toConstant.js.map +1 -1
- package/lib/toDateString.d.ts +1 -1
- package/lib/toErrorList.d.ts +1 -1
- package/lib/toErrorList.js +2 -2
- package/lib/toErrorList.js.map +1 -1
- package/lib/toErrorSchema.d.ts +1 -1
- package/lib/toErrorSchema.js +2 -2
- package/lib/toErrorSchema.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/types.d.ts +172 -142
- package/lib/unwrapErrorHandler.d.ts +1 -1
- package/lib/unwrapErrorHandler.js +1 -1
- package/lib/unwrapErrorHandler.js.map +1 -1
- package/lib/utcToLocal.js +1 -1
- package/lib/utcToLocal.js.map +1 -1
- package/lib/validationDataMerge.d.ts +1 -1
- package/lib/validationDataMerge.js +3 -3
- package/lib/validationDataMerge.js.map +1 -1
- package/lib/withIdRefPrefix.d.ts +1 -1
- package/lib/withIdRefPrefix.js +2 -2
- package/lib/withIdRefPrefix.js.map +1 -1
- package/package.json +37 -26
- package/src/ErrorSchemaBuilder.ts +15 -8
- package/src/canExpand.ts +2 -2
- package/src/constIsAjvDataReference.ts +17 -0
- package/src/constants.ts +17 -3
- package/src/createSchemaUtils.ts +140 -50
- package/src/dataURItoBlob.ts +1 -1
- package/src/dateRangeOptions.ts +1 -1
- package/src/enumOptionsDeselectValue.ts +4 -5
- package/src/enumOptionsIndexForValue.ts +1 -1
- package/src/enumOptionsIsSelected.ts +4 -5
- package/src/enumOptionsSelectValue.ts +1 -1
- package/src/enumOptionsValueForIndex.ts +1 -1
- package/src/enums.ts +2 -0
- package/src/findSchemaDefinition.ts +55 -10
- package/src/getChangedFields.ts +40 -0
- package/src/getDateElementProps.ts +2 -2
- package/src/getDiscriminatorFieldFromSchema.ts +2 -1
- package/src/getInputProps.ts +6 -2
- package/src/getOptionMatchingSimpleDiscriminator.ts +2 -2
- package/src/getSchemaType.ts +3 -2
- package/src/getSubmitButtonOptions.ts +1 -1
- package/src/getTemplate.ts +12 -1
- package/src/getTestIds.ts +40 -0
- package/src/getUiOptions.ts +2 -2
- package/src/getWidget.tsx +2 -2
- package/src/hasWidget.ts +1 -1
- package/src/hashForSchema.ts +26 -6
- package/src/idGenerators.ts +10 -0
- package/src/index.ts +21 -2
- package/src/isCustomWidget.ts +1 -1
- package/src/isObject.ts +12 -5
- package/src/labelValue.ts +2 -2
- package/src/lookupFromFormContext.ts +26 -0
- package/src/mergeDefaultsWithFormData.ts +54 -9
- package/src/mergeObjects.ts +24 -21
- package/src/optionsList.ts +31 -22
- package/src/parser/ParserValidator.ts +5 -5
- package/src/parser/schemaParser.ts +6 -6
- package/src/schema/findFieldInSchema.ts +138 -0
- package/src/schema/findSelectedOptionInXxxOf.ts +53 -0
- package/src/schema/getClosestMatchingOption.ts +38 -11
- package/src/schema/getDefaultFormState.ts +461 -193
- package/src/schema/getDisplayLabel.ts +7 -4
- package/src/schema/getFirstMatchingOption.ts +79 -4
- package/src/schema/getFromSchema.ts +100 -0
- package/src/schema/index.ts +6 -4
- package/src/schema/isFilesArray.ts +18 -3
- package/src/schema/isMultiSelect.ts +10 -4
- package/src/schema/isSelect.ts +5 -3
- package/src/schema/retrieveSchema.ts +268 -78
- package/src/schema/sanitizeDataForNewSchema.ts +52 -11
- package/src/schema/toIdSchema.ts +69 -43
- package/src/schema/toPathSchema.ts +49 -16
- package/src/toErrorList.ts +2 -2
- package/src/types.ts +278 -184
- package/src/validationDataMerge.ts +1 -1
- package/src/withIdRefPrefix.ts +1 -1
- package/LICENSE.md +0 -201
- package/lib/schema/getMatchingOption.d.ts +0 -14
- package/lib/schema/getMatchingOption.js +0 -85
- package/lib/schema/getMatchingOption.js.map +0 -1
- package/lib/schema/mergeValidationData.d.ts +0 -14
- package/lib/schema/mergeValidationData.js +0 -28
- package/lib/schema/mergeValidationData.js.map +0 -1
- package/src/schema/getMatchingOption.ts +0 -103
- package/src/schema/mergeValidationData.ts +0 -38
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import get from 'lodash-es/get.js';
|
|
2
|
+
import has from 'lodash-es/has.js';
|
|
3
|
+
import findSelectedOptionInXxxOf from './findSelectedOptionInXxxOf.js';
|
|
4
|
+
import getFromSchema from './getFromSchema.js';
|
|
5
|
+
import { ANY_OF_KEY, ONE_OF_KEY, PROPERTIES_KEY, REQUIRED_KEY } from '../constants.js';
|
|
6
|
+
/** Unique schema that represents no schema was found, exported for testing purposes */
|
|
7
|
+
export const NOT_FOUND_SCHEMA = { title: '!@#$_UNKNOWN_$#@!' };
|
|
8
|
+
/** Finds the field specified by the `path` within the root or recursed `schema`. If there is no field for the specified
|
|
9
|
+
* `path`, then the default `{ field: undefined, isRequired: undefined }` is returned. It determines whether a leaf
|
|
10
|
+
* field is in the `required` list for its parent and if so, it is marked as required on return.
|
|
11
|
+
*
|
|
12
|
+
* @param validator - An implementation of the `ValidatorType` interface that will be forwarded to all the APIs
|
|
13
|
+
* @param rootSchema - The root schema that will be forwarded to all the APIs
|
|
14
|
+
* @param schema - The node within the JSON schema in which to search
|
|
15
|
+
* @param path - The keys in the path to the desired field
|
|
16
|
+
* @param [formData={}] - The form data that is used to determine which anyOf/oneOf option to descend
|
|
17
|
+
* @param [experimental_customMergeAllOf] - Optional function that allows for custom merging of `allOf` schemas
|
|
18
|
+
* @returns - An object that contains the field and its required state. If no field can be found then
|
|
19
|
+
* `{ field: undefined, isRequired: undefined }` is returned.
|
|
20
|
+
*/
|
|
21
|
+
export default function findFieldInSchema(validator, rootSchema, schema, path, formData = {}, experimental_customMergeAllOf) {
|
|
22
|
+
const pathList = Array.isArray(path) ? [...path] : path.split('.');
|
|
23
|
+
let parentField = schema;
|
|
24
|
+
// store the desired field into a variable and removing it from the `pathList`
|
|
25
|
+
const fieldName = pathList.pop();
|
|
26
|
+
if (pathList.length) {
|
|
27
|
+
// drilling into the schema for each sub-path and taking into account of the any/oneOfs
|
|
28
|
+
pathList.forEach((subPath) => {
|
|
29
|
+
parentField = getFromSchema(validator, rootSchema, parentField, [PROPERTIES_KEY, subPath], {}, experimental_customMergeAllOf);
|
|
30
|
+
if (has(parentField, ONE_OF_KEY)) {
|
|
31
|
+
// if this sub-path has a `oneOf` then use the formData to drill into the schema with the selected option
|
|
32
|
+
parentField = findSelectedOptionInXxxOf(validator, rootSchema, parentField, fieldName, ONE_OF_KEY, get(formData, subPath), experimental_customMergeAllOf);
|
|
33
|
+
}
|
|
34
|
+
else if (has(parentField, ANY_OF_KEY)) {
|
|
35
|
+
// if this sub-path has a `anyOf` then use the formData to drill into the schema with the selected option
|
|
36
|
+
parentField = findSelectedOptionInXxxOf(validator, rootSchema, parentField, fieldName, ANY_OF_KEY, get(formData, subPath), experimental_customMergeAllOf);
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
if (has(parentField, ONE_OF_KEY)) {
|
|
41
|
+
// When oneOf is in the root schema, use the formData to drill into the schema with the selected option
|
|
42
|
+
parentField = findSelectedOptionInXxxOf(validator, rootSchema, parentField, fieldName, ONE_OF_KEY, formData, experimental_customMergeAllOf);
|
|
43
|
+
}
|
|
44
|
+
else if (has(parentField, ANY_OF_KEY)) {
|
|
45
|
+
// When anyOf is in the root schema, use the formData to drill into the schema with the selected option
|
|
46
|
+
parentField = findSelectedOptionInXxxOf(validator, rootSchema, parentField, fieldName, ANY_OF_KEY, formData, experimental_customMergeAllOf);
|
|
47
|
+
}
|
|
48
|
+
// taking the most updated `parentField`, get our desired field
|
|
49
|
+
let field = getFromSchema(validator, rootSchema, parentField, [PROPERTIES_KEY, fieldName], NOT_FOUND_SCHEMA, experimental_customMergeAllOf);
|
|
50
|
+
if (field === NOT_FOUND_SCHEMA) {
|
|
51
|
+
field = undefined;
|
|
52
|
+
}
|
|
53
|
+
// check to see if our desired field is in the `required` list for its parent
|
|
54
|
+
const requiredArray = getFromSchema(validator, rootSchema, parentField, REQUIRED_KEY, [], experimental_customMergeAllOf);
|
|
55
|
+
let isRequired;
|
|
56
|
+
if (field && Array.isArray(requiredArray)) {
|
|
57
|
+
isRequired = requiredArray.includes(fieldName);
|
|
58
|
+
}
|
|
59
|
+
return { field, isRequired };
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=findFieldInSchema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"findFieldInSchema.js","sourceRoot":"","sources":["../../src/schema/findFieldInSchema.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,YAAY,CAAC;AAC7B,OAAO,GAAG,MAAM,YAAY,CAAC;AAE7B,OAAO,yBAAyB,MAAM,6BAA6B,CAAC;AACpE,OAAO,aAAa,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAUpF,uFAAuF;AACvF,MAAM,CAAC,MAAM,gBAAgB,GAAG,EAAE,KAAK,EAAE,mBAAmB,EAAE,CAAC;AAE/D;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,OAAO,UAAU,iBAAiB,CAKvC,SAA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AW,EACX,SAAS,EACT,UAAU,EACV,QAAQ,EACR,6BAA6B,CAC7B,CAAC;IACL,CAAC;SAAM,IAAI,GAAG,CAAC,WAAW,EAAE,UAAU,CAAC,EAAE,CAAC;QACxC,uGAAuG;QACvG,WAAW,GAAG,yBAAyB,CACrC,SAAS,EACT,UAAU,EACV,WAAW,EACX,SAAS,EACT,UAAU,EACV,QAAQ,EACR,6BAA6B,CAC7B,CAAC;IACL,CAAC;IAED,+DAA+D;IAC/D,IAAI,KAAK,GAAkB,aAAa,CACtC,SAAS,EACT,UAAU,EACV,WAAW,EACX,CAAC,cAAc,EAAE,SAAS,CAAC,EAC3B,gBAAqB,EACrB,6BAA6B,CAC9B,CAAC;IACF,IAAI,KAAK,KAAK,gBAAgB,EAAE,CAAC;QAC/B,KAAK,GAAG,SAAS,CAAC;IACpB,CAAC;IACD,6EAA6E;IAC7E,MAAM,aAAa,GAAG,aAAa,CACjC,SAAS,EACT,UAAU,EACV,WAAW,EACX,YAAY,EACZ,EAAO,EACP,6BAA6B,CAC9B,CAAC;IACF,IAAI,UAA+B,CAAC;IACpC,IAAI,KAAK,IAAI,KAAK,CAAC,OAAO,CAAC,aAAa,CAAC,EAAE,CAAC;QAC1C,UAAU,GAAG,aAAa,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;IACjD,CAAC;IAED,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,CAAC;AAC/B,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Experimental_CustomMergeAllOf, FormContextType, RJSFSchema, StrictRJSFSchema, ValidatorType } from '../types.js';
|
|
2
|
+
/** Finds the option inside the `schema['any/oneOf']` list which has the `properties[selectorField].default` or
|
|
3
|
+
* `properties[selectorField].const` that matches the `formData[selectorField]` value. For the purposes of this
|
|
4
|
+
* function, `selectorField` is either `schema.discriminator.propertyName` or `fallbackField`. The `LayoutGridField`
|
|
5
|
+
* works directly with schemas in a recursive manner, making this faster than `getFirstMatchingOption()`.
|
|
6
|
+
*
|
|
7
|
+
* @param validator - An implementation of the `ValidatorType` interface that will be forwarded to all the APIs
|
|
8
|
+
* @param rootSchema - The root schema that will be forwarded to all the APIs
|
|
9
|
+
* @param schema - The schema element in which to search for the selected anyOf/oneOf option
|
|
10
|
+
* @param fallbackField - The field to use as a backup selector field if the schema does not have a required field
|
|
11
|
+
* @param xxx - Either `anyOf` or `oneOf`, defines which value is being sought
|
|
12
|
+
* @param [formData={}] - The form data that is used to determine which anyOf/oneOf option to descend
|
|
13
|
+
* @param [experimental_customMergeAllOf] - Optional function that allows for custom merging of `allOf` schemas
|
|
14
|
+
* @returns - The anyOf/oneOf option that matches the selector field in the schema or undefined if nothing is selected
|
|
15
|
+
*/
|
|
16
|
+
export default function findSelectedOptionInXxxOf<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(validator: ValidatorType<T, S, F>, rootSchema: S, schema: S, fallbackField: string, xxx: 'anyOf' | 'oneOf', formData?: T, experimental_customMergeAllOf?: Experimental_CustomMergeAllOf<S>): S | undefined;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import get from 'lodash-es/get.js';
|
|
2
|
+
import isEqual from 'lodash-es/isEqual.js';
|
|
3
|
+
import { CONST_KEY, DEFAULT_KEY, PROPERTIES_KEY } from '../constants.js';
|
|
4
|
+
import retrieveSchema from './retrieveSchema.js';
|
|
5
|
+
import getDiscriminatorFieldFromSchema from '../getDiscriminatorFieldFromSchema.js';
|
|
6
|
+
/** Finds the option inside the `schema['any/oneOf']` list which has the `properties[selectorField].default` or
|
|
7
|
+
* `properties[selectorField].const` that matches the `formData[selectorField]` value. For the purposes of this
|
|
8
|
+
* function, `selectorField` is either `schema.discriminator.propertyName` or `fallbackField`. The `LayoutGridField`
|
|
9
|
+
* works directly with schemas in a recursive manner, making this faster than `getFirstMatchingOption()`.
|
|
10
|
+
*
|
|
11
|
+
* @param validator - An implementation of the `ValidatorType` interface that will be forwarded to all the APIs
|
|
12
|
+
* @param rootSchema - The root schema that will be forwarded to all the APIs
|
|
13
|
+
* @param schema - The schema element in which to search for the selected anyOf/oneOf option
|
|
14
|
+
* @param fallbackField - The field to use as a backup selector field if the schema does not have a required field
|
|
15
|
+
* @param xxx - Either `anyOf` or `oneOf`, defines which value is being sought
|
|
16
|
+
* @param [formData={}] - The form data that is used to determine which anyOf/oneOf option to descend
|
|
17
|
+
* @param [experimental_customMergeAllOf] - Optional function that allows for custom merging of `allOf` schemas
|
|
18
|
+
* @returns - The anyOf/oneOf option that matches the selector field in the schema or undefined if nothing is selected
|
|
19
|
+
*/
|
|
20
|
+
export default function findSelectedOptionInXxxOf(validator, rootSchema, schema, fallbackField, xxx, formData = {}, experimental_customMergeAllOf) {
|
|
21
|
+
if (Array.isArray(schema[xxx])) {
|
|
22
|
+
const discriminator = getDiscriminatorFieldFromSchema(schema);
|
|
23
|
+
const selectorField = discriminator || fallbackField;
|
|
24
|
+
const xxxOfs = schema[xxx].map((xxxOf) => retrieveSchema(validator, xxxOf, rootSchema, formData, experimental_customMergeAllOf));
|
|
25
|
+
const data = get(formData, selectorField);
|
|
26
|
+
if (data !== undefined) {
|
|
27
|
+
return xxxOfs.find((xxx) => {
|
|
28
|
+
return isEqual(get(xxx, [PROPERTIES_KEY, selectorField, DEFAULT_KEY], get(xxx, [PROPERTIES_KEY, selectorField, CONST_KEY])), data);
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return undefined;
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=findSelectedOptionInXxxOf.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"findSelectedOptionInXxxOf.js","sourceRoot":"","sources":["../../src/schema/findSelectedOptionInXxxOf.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,YAAY,CAAC;AAC7B,OAAO,OAAO,MAAM,gBAAgB,CAAC;AAErC,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAEtE,OAAO,cAAc,MAAM,kBAAkB,CAAC;AAC9C,OAAO,+BAA+B,MAAM,oCAAoC,CAAC;AAEjF;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,OAAO,UAAU,yBAAyB,CAK/C,SAAiC,EACjC,UAAa,EACb,MAAS,EACT,aAAqB,EACrB,GAAsB,EACtB,WAAc,EAAO,EACrB,6BAAgE;IAEhE,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC;QAC/B,MAAM,aAAa,GAAG,+BAA+B,CAAI,MAAM,CAAC,CAAC;QACjE,MAAM,aAAa,GAAG,aAAa,IAAI,aAAa,CAAC;QACrD,MAAM,MAAM,GAAG,MAAM,CAAC,GAAG,CAAE,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CACxC,cAAc,CAAU,SAAS,EAAE,KAAU,EAAE,UAAU,EAAE,QAAQ,EAAE,6BAA6B,CAAC,CACpG,CAAC;QACF,MAAM,IAAI,GAAG,GAAG,CAAC,QAAQ,EAAE,aAAa,CAAC,CAAC;QAC1C,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;YACvB,OAAO,MAAM,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE;gBACzB,OAAO,OAAO,CACZ,GAAG,CAAC,GAAG,EAAE,CAAC,cAAc,EAAE,aAAa,EAAE,WAAW,CAAC,EAAE,GAAG,CAAC,GAAG,EAAE,CAAC,cAAc,EAAE,aAAa,EAAE,SAAS,CAAC,CAAC,CAAC,EAC5G,IAAI,CACL,CAAC;YACJ,CAAC,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FormContextType, RJSFSchema, StrictRJSFSchema, ValidatorType } from '../types';
|
|
1
|
+
import { Experimental_CustomMergeAllOf, FormContextType, RJSFSchema, StrictRJSFSchema, ValidatorType } from '../types.js';
|
|
2
2
|
/** A junk option used to determine when the getFirstMatchingOption call really matches an option rather than returning
|
|
3
3
|
* the first item
|
|
4
4
|
*/
|
|
@@ -21,9 +21,10 @@ export declare const JUNK_OPTION: StrictRJSFSchema;
|
|
|
21
21
|
* @param rootSchema - The root JSON schema of the entire form
|
|
22
22
|
* @param schema - The schema for which the score is being calculated
|
|
23
23
|
* @param formData - The form data associated with the schema, used to calculate the score
|
|
24
|
+
* @param [experimental_customMergeAllOf] - Optional function that allows for custom merging of `allOf` schemas
|
|
24
25
|
* @returns - The score a schema against the formData
|
|
25
26
|
*/
|
|
26
|
-
export declare function calculateIndexScore<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(validator: ValidatorType<T, S, F>, rootSchema: S, schema?: S, formData?: any): number;
|
|
27
|
+
export declare function calculateIndexScore<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(validator: ValidatorType<T, S, F>, rootSchema: S, schema?: S, formData?: any, experimental_customMergeAllOf?: Experimental_CustomMergeAllOf<S>): number;
|
|
27
28
|
/** Determines which of the given `options` provided most closely matches the `formData`. Using
|
|
28
29
|
* `getFirstMatchingOption()` to match two schemas that differ only by the readOnly, default or const value of a field
|
|
29
30
|
* based on the `formData` and returns 0 when there is no match. Rather than passing in all the `options` at once to
|
|
@@ -44,6 +45,7 @@ export declare function calculateIndexScore<T = any, S extends StrictRJSFSchema
|
|
|
44
45
|
* @param [selectedOption=-1] - The index of the currently selected option, defaulted to -1 if not specified
|
|
45
46
|
* @param [discriminatorField] - The optional name of the field within the options object whose value is used to
|
|
46
47
|
* determine which option is selected
|
|
48
|
+
* @param [experimental_customMergeAllOf] - Optional function that allows for custom merging of `allOf` schemas
|
|
47
49
|
* @returns - The index of the option that is the closest match to the `formData` or the `selectedOption` if no match
|
|
48
50
|
*/
|
|
49
|
-
export default function getClosestMatchingOption<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(validator: ValidatorType<T, S, F>, rootSchema: S, formData: T | undefined, options: S[], selectedOption?: number, discriminatorField?: string): number;
|
|
51
|
+
export default function getClosestMatchingOption<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(validator: ValidatorType<T, S, F>, rootSchema: S, formData: T | undefined, options: S[], selectedOption?: number, discriminatorField?: string, experimental_customMergeAllOf?: Experimental_CustomMergeAllOf<S>): number;
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import get from 'lodash/get';
|
|
2
|
-
import has from 'lodash/has';
|
|
3
|
-
import isNumber from 'lodash/isNumber';
|
|
4
|
-
import isObject from 'lodash/isObject';
|
|
5
|
-
import isString from 'lodash/isString';
|
|
6
|
-
import reduce from 'lodash/reduce';
|
|
7
|
-
import times from 'lodash/times';
|
|
8
|
-
import getFirstMatchingOption from './getFirstMatchingOption';
|
|
9
|
-
import retrieveSchema, { resolveAllReferences } from './retrieveSchema';
|
|
10
|
-
import { ONE_OF_KEY, REF_KEY, JUNK_OPTION_ID, ANY_OF_KEY } from '../constants';
|
|
11
|
-
import guessType from '../guessType';
|
|
12
|
-
import getDiscriminatorFieldFromSchema from '../getDiscriminatorFieldFromSchema';
|
|
13
|
-
import getOptionMatchingSimpleDiscriminator from '../getOptionMatchingSimpleDiscriminator';
|
|
1
|
+
import get from 'lodash-es/get.js';
|
|
2
|
+
import has from 'lodash-es/has.js';
|
|
3
|
+
import isNumber from 'lodash-es/isNumber.js';
|
|
4
|
+
import isObject from 'lodash-es/isObject.js';
|
|
5
|
+
import isString from 'lodash-es/isString.js';
|
|
6
|
+
import reduce from 'lodash-es/reduce.js';
|
|
7
|
+
import times from 'lodash-es/times.js';
|
|
8
|
+
import getFirstMatchingOption from './getFirstMatchingOption.js';
|
|
9
|
+
import retrieveSchema, { resolveAllReferences } from './retrieveSchema.js';
|
|
10
|
+
import { ONE_OF_KEY, REF_KEY, JUNK_OPTION_ID, ANY_OF_KEY } from '../constants.js';
|
|
11
|
+
import guessType from '../guessType.js';
|
|
12
|
+
import getDiscriminatorFieldFromSchema from '../getDiscriminatorFieldFromSchema.js';
|
|
13
|
+
import getOptionMatchingSimpleDiscriminator from '../getOptionMatchingSimpleDiscriminator.js';
|
|
14
14
|
/** A junk option used to determine when the getFirstMatchingOption call really matches an option rather than returning
|
|
15
15
|
* the first item
|
|
16
16
|
*/
|
|
@@ -41,9 +41,10 @@ export const JUNK_OPTION = {
|
|
|
41
41
|
* @param rootSchema - The root JSON schema of the entire form
|
|
42
42
|
* @param schema - The schema for which the score is being calculated
|
|
43
43
|
* @param formData - The form data associated with the schema, used to calculate the score
|
|
44
|
+
* @param [experimental_customMergeAllOf] - Optional function that allows for custom merging of `allOf` schemas
|
|
44
45
|
* @returns - The score a schema against the formData
|
|
45
46
|
*/
|
|
46
|
-
export function calculateIndexScore(validator, rootSchema, schema, formData
|
|
47
|
+
export function calculateIndexScore(validator, rootSchema, schema, formData, experimental_customMergeAllOf) {
|
|
47
48
|
let totalScore = 0;
|
|
48
49
|
if (schema) {
|
|
49
50
|
if (isObject(schema.properties)) {
|
|
@@ -53,17 +54,23 @@ export function calculateIndexScore(validator, rootSchema, schema, formData = {}
|
|
|
53
54
|
return score;
|
|
54
55
|
}
|
|
55
56
|
if (has(value, REF_KEY)) {
|
|
56
|
-
const newSchema = retrieveSchema(validator, value, rootSchema, formValue);
|
|
57
|
-
return score +
|
|
57
|
+
const newSchema = retrieveSchema(validator, value, rootSchema, formValue, experimental_customMergeAllOf);
|
|
58
|
+
return (score +
|
|
59
|
+
calculateIndexScore(validator, rootSchema, newSchema, formValue || {}, experimental_customMergeAllOf));
|
|
58
60
|
}
|
|
59
61
|
if ((has(value, ONE_OF_KEY) || has(value, ANY_OF_KEY)) && formValue) {
|
|
60
62
|
const key = has(value, ONE_OF_KEY) ? ONE_OF_KEY : ANY_OF_KEY;
|
|
61
63
|
const discriminator = getDiscriminatorFieldFromSchema(value);
|
|
62
64
|
return (score +
|
|
63
|
-
getClosestMatchingOption(validator, rootSchema, formValue, get(value, key), -1, discriminator));
|
|
65
|
+
getClosestMatchingOption(validator, rootSchema, formValue, get(value, key), -1, discriminator, experimental_customMergeAllOf));
|
|
64
66
|
}
|
|
65
67
|
if (value.type === 'object') {
|
|
66
|
-
|
|
68
|
+
if (isObject(formValue)) {
|
|
69
|
+
// If the structure is matching then give it a little boost in score
|
|
70
|
+
score += 1;
|
|
71
|
+
}
|
|
72
|
+
return (score +
|
|
73
|
+
calculateIndexScore(validator, rootSchema, value, formValue, experimental_customMergeAllOf));
|
|
67
74
|
}
|
|
68
75
|
if (value.type === guessType(formValue)) {
|
|
69
76
|
// If the types match, then we bump the score by one
|
|
@@ -110,9 +117,10 @@ export function calculateIndexScore(validator, rootSchema, schema, formData = {}
|
|
|
110
117
|
* @param [selectedOption=-1] - The index of the currently selected option, defaulted to -1 if not specified
|
|
111
118
|
* @param [discriminatorField] - The optional name of the field within the options object whose value is used to
|
|
112
119
|
* determine which option is selected
|
|
120
|
+
* @param [experimental_customMergeAllOf] - Optional function that allows for custom merging of `allOf` schemas
|
|
113
121
|
* @returns - The index of the option that is the closest match to the `formData` or the `selectedOption` if no match
|
|
114
122
|
*/
|
|
115
|
-
export default function getClosestMatchingOption(validator, rootSchema, formData, options, selectedOption = -1, discriminatorField) {
|
|
123
|
+
export default function getClosestMatchingOption(validator, rootSchema, formData, options, selectedOption = -1, discriminatorField, experimental_customMergeAllOf) {
|
|
116
124
|
// First resolve any refs in the options
|
|
117
125
|
const resolvedOptions = options.map((option) => {
|
|
118
126
|
return resolveAllReferences(option, rootSchema, []);
|
|
@@ -144,7 +152,7 @@ export default function getClosestMatchingOption(validator, rootSchema, formData
|
|
|
144
152
|
const { bestIndex } = allValidIndexes.reduce((scoreData, index) => {
|
|
145
153
|
const { bestScore } = scoreData;
|
|
146
154
|
const option = resolvedOptions[index];
|
|
147
|
-
const score = calculateIndexScore(validator, rootSchema, option, formData);
|
|
155
|
+
const score = calculateIndexScore(validator, rootSchema, option, formData, experimental_customMergeAllOf);
|
|
148
156
|
scoreCount.add(score);
|
|
149
157
|
if (score > bestScore) {
|
|
150
158
|
return { bestIndex: index, bestScore: score };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getClosestMatchingOption.js","sourceRoot":"","sources":["../../src/schema/getClosestMatchingOption.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,YAAY,CAAC;AAC7B,OAAO,GAAG,MAAM,YAAY,CAAC;AAC7B,OAAO,QAAQ,MAAM,iBAAiB,CAAC;AACvC,OAAO,QAAQ,MAAM,iBAAiB,CAAC;AACvC,OAAO,QAAQ,MAAM,iBAAiB,CAAC;AACvC,OAAO,MAAM,MAAM,eAAe,CAAC;AACnC,OAAO,KAAK,MAAM,cAAc,CAAC;AAEjC,OAAO,sBAAsB,MAAM,0BAA0B,CAAC;AAC9D,OAAO,cAAc,EAAE,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AACxE,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC/E,OAAO,SAAS,MAAM,cAAc,CAAC;AAErC,OAAO,+BAA+B,MAAM,oCAAoC,CAAC;AACjF,OAAO,oCAAoC,MAAM,yCAAyC,CAAC;AAE3F;;GAEG;AACH,MAAM,CAAC,MAAM,WAAW,GAAqB;IAC3C,IAAI,EAAE,QAAQ;IACd,GAAG,EAAE,cAAc;IACnB,UAAU,EAAE;QACV,oBAAoB,EAAE;YACpB,IAAI,EAAE,QAAQ;SACf;KACF;CACF,CAAC;AAEF
|
|
1
|
+
{"version":3,"file":"getClosestMatchingOption.js","sourceRoot":"","sources":["../../src/schema/getClosestMatchingOption.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,YAAY,CAAC;AAC7B,OAAO,GAAG,MAAM,YAAY,CAAC;AAC7B,OAAO,QAAQ,MAAM,iBAAiB,CAAC;AACvC,OAAO,QAAQ,MAAM,iBAAiB,CAAC;AACvC,OAAO,QAAQ,MAAM,iBAA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,CAAC;IACnB,CAAC,EACD,EAAE,SAAS,EAAE,cAAc,EAAE,SAAS,EAAE,CAAC,EAAE,CAC5C,CAAC;IACF,oDAAoD;IACpD,IAAI,UAAU,CAAC,IAAI,KAAK,CAAC,IAAI,cAAc,IAAI,CAAC,EAAE,CAAC;QACjD,OAAO,cAAc,CAAC;IACxB,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Experimental_DefaultFormStateBehavior, FormContextType, RJSFSchema, StrictRJSFSchema, ValidatorType } from '../types';
|
|
1
|
+
import { Experimental_CustomMergeAllOf, Experimental_DefaultFormStateBehavior, FormContextType, RJSFSchema, StrictRJSFSchema, ValidatorType } from '../types.js';
|
|
2
2
|
/** Enum that indicates how `schema.additionalItems` should be handled by the `getInnerSchemaForArrayItem()` function.
|
|
3
3
|
*/
|
|
4
4
|
export declare enum AdditionalItemsHandling {
|
|
@@ -23,32 +23,78 @@ export declare enum AdditionalItemsHandling {
|
|
|
23
23
|
*/
|
|
24
24
|
export declare function getInnerSchemaForArrayItem<S extends StrictRJSFSchema = RJSFSchema>(schema: S, additionalItems?: AdditionalItemsHandling, idx?: number): S;
|
|
25
25
|
interface ComputeDefaultsProps<T = any, S extends StrictRJSFSchema = RJSFSchema> {
|
|
26
|
+
/** Any defaults provided by the parent field in the schema */
|
|
26
27
|
parentDefaults?: T;
|
|
28
|
+
/** The options root schema, used to primarily to look up `$ref`s */
|
|
27
29
|
rootSchema?: S;
|
|
30
|
+
/** The current formData, if any, onto which to provide any missing defaults */
|
|
28
31
|
rawFormData?: T;
|
|
32
|
+
/** Optional flag, if true, cause undefined values to be added as defaults.
|
|
33
|
+
* If "excludeObjectChildren", cause undefined values for this object and pass `includeUndefinedValues` as
|
|
34
|
+
* false when computing defaults for any nested object properties.
|
|
35
|
+
*/
|
|
29
36
|
includeUndefinedValues?: boolean | 'excludeObjectChildren';
|
|
37
|
+
/** The list of ref names currently being recursed, used to prevent infinite recursion */
|
|
30
38
|
_recurseList?: string[];
|
|
39
|
+
/** Optional configuration object, if provided, allows users to override default form state behavior */
|
|
31
40
|
experimental_defaultFormStateBehavior?: Experimental_DefaultFormStateBehavior;
|
|
41
|
+
/** Optional function that allows for custom merging of `allOf` schemas */
|
|
42
|
+
experimental_customMergeAllOf?: Experimental_CustomMergeAllOf<S>;
|
|
43
|
+
/** Optional flag, if true, indicates this schema was required in the parent schema. */
|
|
32
44
|
required?: boolean;
|
|
45
|
+
/** Optional flag, if true, It will merge defaults into formData.
|
|
46
|
+
* The formData should take precedence unless it's not valid. This is useful when for example the value from formData does not exist in the schema 'enum' property, in such cases we take the value from the defaults because the value from the formData is not valid.
|
|
47
|
+
*/
|
|
48
|
+
shouldMergeDefaultsIntoFormData?: boolean;
|
|
33
49
|
}
|
|
34
50
|
/** Computes the defaults for the current `schema` given the `rawFormData` and `parentDefaults` if any. This drills into
|
|
35
51
|
* each level of the schema, recursively, to fill out every level of defaults provided by the schema.
|
|
36
52
|
*
|
|
37
53
|
* @param validator - an implementation of the `ValidatorType` interface that will be used when necessary
|
|
38
54
|
* @param rawSchema - The schema for which the default state is desired
|
|
39
|
-
* @param
|
|
40
|
-
* @param [props.parentDefaults] - Any defaults provided by the parent field in the schema
|
|
41
|
-
* @param [props.rootSchema] - The options root schema, used to primarily to look up `$ref`s
|
|
42
|
-
* @param [props.rawFormData] - The current formData, if any, onto which to provide any missing defaults
|
|
43
|
-
* @param [props.includeUndefinedValues=false] - Optional flag, if true, cause undefined values to be added as defaults.
|
|
44
|
-
* If "excludeObjectChildren", cause undefined values for this object and pass `includeUndefinedValues` as
|
|
45
|
-
* false when computing defaults for any nested object properties.
|
|
46
|
-
* @param [props._recurseList=[]] - The list of ref names currently being recursed, used to prevent infinite recursion
|
|
47
|
-
* @param [props.experimental_defaultFormStateBehavior] Optional configuration object, if provided, allows users to override default form state behavior
|
|
48
|
-
* @param [props.required] - Optional flag, if true, indicates this schema was required in the parent schema.
|
|
55
|
+
* @param {ComputeDefaultsProps} computeDefaultsProps - Optional props for this function
|
|
49
56
|
* @returns - The resulting `formData` with all the defaults provided
|
|
50
57
|
*/
|
|
51
|
-
export declare function computeDefaults<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(validator: ValidatorType<T, S, F>, rawSchema: S,
|
|
58
|
+
export declare function computeDefaults<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(validator: ValidatorType<T, S, F>, rawSchema: S, computeDefaultsProps?: ComputeDefaultsProps<T, S>): T | T[] | undefined;
|
|
59
|
+
/**
|
|
60
|
+
* Ensure that the formData matches the given schema. If it's not matching in the case of a selectField, we change it to match the schema.
|
|
61
|
+
*
|
|
62
|
+
* @param validator - an implementation of the `ValidatorType` interface that will be used when necessary
|
|
63
|
+
* @param schema - The schema for which the formData state is desired
|
|
64
|
+
* @param rootSchema - The root schema, used to primarily to look up `$ref`s
|
|
65
|
+
* @param formData - The current formData
|
|
66
|
+
* @param [experimental_defaultFormStateBehavior] - Optional configuration object, if provided, allows users to override default form state behavior
|
|
67
|
+
* @param [experimental_customMergeAllOf] - Optional function that allows for custom merging of `allOf` schemas
|
|
68
|
+
* @returns - valid formData that matches schema
|
|
69
|
+
*/
|
|
70
|
+
export declare function ensureFormDataMatchingSchema<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(validator: ValidatorType<T, S, F>, schema: S, rootSchema: S, formData: T | undefined, experimental_defaultFormStateBehavior?: Experimental_DefaultFormStateBehavior, experimental_customMergeAllOf?: Experimental_CustomMergeAllOf<S>): T | T[] | undefined;
|
|
71
|
+
/** Computes the default value for objects.
|
|
72
|
+
*
|
|
73
|
+
* @param validator - an implementation of the `ValidatorType` interface that will be used when necessary
|
|
74
|
+
* @param rawSchema - The schema for which the default state is desired
|
|
75
|
+
* @param {ComputeDefaultsProps} computeDefaultsProps - Optional props for this function
|
|
76
|
+
* @param defaults - Optional props for this function
|
|
77
|
+
* @returns - The default value based on the schema type if they are defined for object or array schemas.
|
|
78
|
+
*/
|
|
79
|
+
export declare function getObjectDefaults<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(validator: ValidatorType<T, S, F>, rawSchema: S, { rawFormData, rootSchema, includeUndefinedValues, _recurseList, experimental_defaultFormStateBehavior, experimental_customMergeAllOf, required, shouldMergeDefaultsIntoFormData, }?: ComputeDefaultsProps<T, S>, defaults?: T | T[] | undefined): T;
|
|
80
|
+
/** Computes the default value for arrays.
|
|
81
|
+
*
|
|
82
|
+
* @param validator - an implementation of the `ValidatorType` interface that will be used when necessary
|
|
83
|
+
* @param rawSchema - The schema for which the default state is desired
|
|
84
|
+
* @param {ComputeDefaultsProps} computeDefaultsProps - Optional props for this function
|
|
85
|
+
* @param defaults - Optional props for this function
|
|
86
|
+
* @returns - The default value based on the schema type if they are defined for object or array schemas.
|
|
87
|
+
*/
|
|
88
|
+
export declare function getArrayDefaults<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(validator: ValidatorType<T, S, F>, rawSchema: S, { rawFormData, rootSchema, _recurseList, experimental_defaultFormStateBehavior, experimental_customMergeAllOf, required, shouldMergeDefaultsIntoFormData, }?: ComputeDefaultsProps<T, S>, defaults?: T | T[] | undefined): T | T[] | undefined;
|
|
89
|
+
/** Computes the default value based on the schema type.
|
|
90
|
+
*
|
|
91
|
+
* @param validator - an implementation of the `ValidatorType` interface that will be used when necessary
|
|
92
|
+
* @param rawSchema - The schema for which the default state is desired
|
|
93
|
+
* @param {ComputeDefaultsProps} computeDefaultsProps - Optional props for this function
|
|
94
|
+
* @param defaults - Optional props for this function
|
|
95
|
+
* @returns - The default value based on the schema type if they are defined for object or array schemas.
|
|
96
|
+
*/
|
|
97
|
+
export declare function getDefaultBasedOnSchemaType<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(validator: ValidatorType<T, S, F>, rawSchema: S, computeDefaultsProps?: ComputeDefaultsProps<T, S>, defaults?: T | T[] | undefined): T | T[] | void;
|
|
52
98
|
/** Returns the superset of `formData` that includes the given set updated to include any missing fields that have
|
|
53
99
|
* computed to have defaults provided in the `schema`.
|
|
54
100
|
*
|
|
@@ -60,7 +106,8 @@ export declare function computeDefaults<T = any, S extends StrictRJSFSchema = RJ
|
|
|
60
106
|
* If "excludeObjectChildren", cause undefined values for this object and pass `includeUndefinedValues` as
|
|
61
107
|
* false when computing defaults for any nested object properties.
|
|
62
108
|
* @param [experimental_defaultFormStateBehavior] Optional configuration object, if provided, allows users to override default form state behavior
|
|
109
|
+
* @param [experimental_customMergeAllOf] - Optional function that allows for custom merging of `allOf` schemas
|
|
63
110
|
* @returns - The resulting `formData` with all the defaults provided
|
|
64
111
|
*/
|
|
65
|
-
export default function getDefaultFormState<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(validator: ValidatorType<T, S, F>, theSchema: S, formData?: T, rootSchema?: S, includeUndefinedValues?: boolean | 'excludeObjectChildren', experimental_defaultFormStateBehavior?: Experimental_DefaultFormStateBehavior): T | T[] | undefined;
|
|
112
|
+
export default function getDefaultFormState<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(validator: ValidatorType<T, S, F>, theSchema: S, formData?: T, rootSchema?: S, includeUndefinedValues?: boolean | 'excludeObjectChildren', experimental_defaultFormStateBehavior?: Experimental_DefaultFormStateBehavior, experimental_customMergeAllOf?: Experimental_CustomMergeAllOf<S>): T | T[] | undefined;
|
|
66
113
|
export {};
|