@rjsf/utils 5.11.2 → 5.12.0
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 +2544 -5
- package/dist/index.js.map +7 -0
- package/dist/utils.esm.js +1228 -2113
- package/dist/utils.esm.js.map +7 -1
- package/dist/utils.umd.js +2414 -0
- package/lib/ErrorSchemaBuilder.d.ts +60 -0
- package/lib/ErrorSchemaBuilder.js +103 -0
- package/lib/ErrorSchemaBuilder.js.map +1 -0
- package/lib/allowAdditionalItems.d.ts +8 -0
- package/lib/allowAdditionalItems.js +14 -0
- package/lib/allowAdditionalItems.js.map +1 -0
- package/lib/asNumber.d.ts +10 -0
- package/lib/asNumber.js +36 -0
- package/lib/asNumber.js.map +1 -0
- package/lib/canExpand.d.ts +11 -0
- package/lib/canExpand.js +26 -0
- package/lib/canExpand.js.map +1 -0
- package/lib/constants.d.ts +31 -0
- package/lib/constants.js +32 -0
- package/lib/constants.js.map +1 -0
- package/lib/createErrorHandler.d.ts +7 -0
- package/lib/createErrorHandler.js +31 -0
- package/lib/createErrorHandler.js.map +1 -0
- package/lib/createSchemaUtils.d.ts +10 -0
- package/lib/createSchemaUtils.js +207 -0
- package/lib/createSchemaUtils.js.map +1 -0
- package/lib/dataURItoBlob.d.ts +16 -0
- package/lib/dataURItoBlob.js +43 -0
- package/lib/dataURItoBlob.js.map +1 -0
- package/lib/deepEquals.d.ts +8 -0
- package/lib/deepEquals.js +19 -0
- package/lib/deepEquals.js.map +1 -0
- package/lib/englishStringTranslator.d.ts +10 -0
- package/lib/englishStringTranslator.js +13 -0
- package/lib/englishStringTranslator.js.map +1 -0
- package/lib/enumOptionsDeselectValue.d.ts +14 -0
- package/lib/enumOptionsDeselectValue.js +22 -0
- package/lib/enumOptionsDeselectValue.js.map +1 -0
- package/lib/enumOptionsIndexForValue.d.ts +13 -0
- package/lib/enumOptionsIndexForValue.js +22 -0
- package/lib/enumOptionsIndexForValue.js.map +1 -0
- package/lib/enumOptionsIsSelected.d.ts +8 -0
- package/lib/enumOptionsIsSelected.js +14 -0
- package/lib/enumOptionsIsSelected.js.map +1 -0
- package/lib/enumOptionsSelectValue.d.ts +10 -0
- package/lib/enumOptionsSelectValue.js +23 -0
- package/lib/enumOptionsSelectValue.js.map +1 -0
- package/lib/enumOptionsValueForIndex.d.ts +13 -0
- package/lib/enumOptionsValueForIndex.js +21 -0
- package/lib/enumOptionsValueForIndex.js.map +1 -0
- package/lib/enums.d.ts +72 -0
- package/lib/enums.js +76 -0
- package/lib/enums.js.map +1 -0
- package/lib/findSchemaDefinition.d.ts +20 -0
- package/lib/findSchemaDefinition.js +49 -0
- package/lib/findSchemaDefinition.js.map +1 -0
- package/lib/getDiscriminatorFieldFromSchema.d.ts +8 -0
- package/lib/getDiscriminatorFieldFromSchema.js +20 -0
- package/lib/getDiscriminatorFieldFromSchema.js.map +1 -0
- package/lib/getInputProps.d.ts +10 -0
- package/lib/getInputProps.js +41 -0
- package/lib/getInputProps.js.map +1 -0
- package/lib/getSchemaType.d.ts +13 -0
- package/lib/getSchemaType.js +29 -0
- package/lib/getSchemaType.js.map +1 -0
- package/lib/getSubmitButtonOptions.d.ts +10 -0
- package/lib/getSubmitButtonOptions.js +25 -0
- package/lib/getSubmitButtonOptions.js.map +1 -0
- package/lib/getTemplate.d.ts +10 -0
- package/lib/getTemplate.js +19 -0
- package/lib/getTemplate.js.map +1 -0
- package/lib/getUiOptions.d.ts +9 -0
- package/lib/getUiOptions.js +25 -0
- package/lib/getUiOptions.js.map +1 -0
- package/lib/getWidget.d.ts +13 -0
- package/lib/getWidget.js +118 -0
- package/lib/getWidget.js.map +1 -0
- package/lib/guessType.d.ts +7 -0
- package/lib/guessType.js +29 -0
- package/lib/guessType.js.map +1 -0
- package/lib/hasWidget.d.ts +10 -0
- package/lib/hasWidget.js +23 -0
- package/lib/hasWidget.js.map +1 -0
- package/lib/hashForSchema.d.ts +8 -0
- package/lib/hashForSchema.js +29 -0
- package/lib/hashForSchema.js.map +1 -0
- package/lib/idGenerators.d.ts +47 -0
- package/lib/idGenerators.js +73 -0
- package/lib/idGenerators.js.map +1 -0
- package/lib/index.d.ts +57 -0
- package/lib/index.js +58 -0
- package/lib/index.js.map +1 -0
- package/lib/isConstant.d.ts +8 -0
- package/lib/isConstant.js +11 -0
- package/lib/isConstant.js.map +1 -0
- package/lib/isCustomWidget.d.ts +7 -0
- package/lib/isCustomWidget.js +13 -0
- package/lib/isCustomWidget.js.map +1 -0
- package/lib/isFixedItems.d.ts +8 -0
- package/lib/isFixedItems.js +11 -0
- package/lib/isFixedItems.js.map +1 -0
- package/lib/isObject.d.ts +7 -0
- package/lib/isObject.js +16 -0
- package/lib/isObject.js.map +1 -0
- package/lib/labelValue.d.ts +13 -0
- package/lib/labelValue.js +4 -0
- package/lib/labelValue.js.map +1 -0
- package/lib/localToUTC.d.ts +6 -0
- package/lib/localToUTC.js +9 -0
- package/lib/localToUTC.js.map +1 -0
- package/lib/mergeDefaultsWithFormData.d.ts +17 -0
- package/lib/mergeDefaultsWithFormData.js +43 -0
- package/lib/mergeDefaultsWithFormData.js.map +1 -0
- package/lib/mergeObjects.d.ts +11 -0
- package/lib/mergeObjects.js +35 -0
- package/lib/mergeObjects.js.map +1 -0
- package/lib/mergeSchemas.d.ts +10 -0
- package/lib/mergeSchemas.js +35 -0
- package/lib/mergeSchemas.js.map +1 -0
- package/lib/optionsList.d.ts +10 -0
- package/lib/optionsList.js +36 -0
- package/lib/optionsList.js.map +1 -0
- package/lib/orderProperties.d.ts +11 -0
- package/lib/orderProperties.js +38 -0
- package/lib/orderProperties.js.map +1 -0
- package/lib/pad.d.ts +7 -0
- package/lib/pad.js +14 -0
- package/lib/pad.js.map +1 -0
- package/lib/parseDateString.d.ts +9 -0
- package/lib/parseDateString.js +32 -0
- package/lib/parseDateString.js.map +1 -0
- package/lib/parser/ParserValidator.d.ts +70 -0
- package/lib/parser/ParserValidator.js +93 -0
- package/lib/parser/ParserValidator.js.map +1 -0
- package/lib/parser/index.d.ts +4 -0
- package/lib/parser/index.js +3 -0
- package/lib/parser/index.js.map +1 -0
- package/lib/parser/schemaParser.d.ts +9 -0
- package/lib/parser/schemaParser.js +48 -0
- package/lib/parser/schemaParser.js.map +1 -0
- package/lib/rangeSpec.d.ts +9 -0
- package/lib/rangeSpec.js +20 -0
- package/lib/rangeSpec.js.map +1 -0
- package/lib/replaceStringParameters.d.ts +9 -0
- package/lib/replaceStringParameters.js +23 -0
- package/lib/replaceStringParameters.js.map +1 -0
- package/lib/schema/getClosestMatchingOption.d.ts +49 -0
- package/lib/schema/getClosestMatchingOption.js +154 -0
- package/lib/schema/getClosestMatchingOption.js.map +1 -0
- package/lib/schema/getDefaultFormState.d.ts +66 -0
- package/lib/schema/getDefaultFormState.js +351 -0
- package/lib/schema/getDefaultFormState.js.map +1 -0
- package/lib/schema/getDisplayLabel.d.ts +12 -0
- package/lib/schema/getDisplayLabel.js +39 -0
- package/lib/schema/getDisplayLabel.js.map +1 -0
- package/lib/schema/getFirstMatchingOption.d.ts +13 -0
- package/lib/schema/getFirstMatchingOption.js +16 -0
- package/lib/schema/getFirstMatchingOption.js.map +1 -0
- package/lib/schema/getMatchingOption.d.ts +14 -0
- package/lib/schema/getMatchingOption.js +80 -0
- package/lib/schema/getMatchingOption.js.map +1 -0
- package/lib/schema/index.d.ts +14 -0
- package/lib/schema/index.js +15 -0
- package/lib/schema/index.js.map +1 -0
- package/lib/schema/isFilesArray.d.ts +10 -0
- package/lib/schema/isFilesArray.js +21 -0
- package/lib/schema/isFilesArray.js.map +1 -0
- package/lib/schema/isMultiSelect.d.ts +9 -0
- package/lib/schema/isMultiSelect.js +15 -0
- package/lib/schema/isMultiSelect.js.map +1 -0
- package/lib/schema/isSelect.d.ts +9 -0
- package/lib/schema/isSelect.js +21 -0
- package/lib/schema/isSelect.js.map +1 -0
- package/lib/schema/mergeValidationData.d.ts +14 -0
- package/lib/schema/mergeValidationData.js +28 -0
- package/lib/schema/mergeValidationData.js.map +1 -0
- package/lib/schema/retrieveSchema.d.ts +170 -0
- package/lib/schema/retrieveSchema.js +437 -0
- package/lib/schema/retrieveSchema.js.map +1 -0
- package/lib/schema/sanitizeDataForNewSchema.d.ts +49 -0
- package/lib/schema/sanitizeDataForNewSchema.js +173 -0
- package/lib/schema/sanitizeDataForNewSchema.js.map +1 -0
- package/lib/schema/toIdSchema.d.ts +13 -0
- package/lib/schema/toIdSchema.js +59 -0
- package/lib/schema/toIdSchema.js.map +1 -0
- package/lib/schema/toPathSchema.d.ts +11 -0
- package/lib/schema/toPathSchema.js +68 -0
- package/lib/schema/toPathSchema.js.map +1 -0
- package/lib/schemaRequiresTrueValue.d.ts +11 -0
- package/lib/schemaRequiresTrueValue.js +34 -0
- package/lib/schemaRequiresTrueValue.js.map +1 -0
- package/lib/shouldRender.d.ts +10 -0
- package/lib/shouldRender.js +14 -0
- package/lib/shouldRender.js.map +1 -0
- package/lib/toConstant.d.ts +9 -0
- package/lib/toConstant.js +18 -0
- package/lib/toConstant.js.map +1 -0
- package/lib/toDateString.d.ts +9 -0
- package/lib/toDateString.js +14 -0
- package/lib/toDateString.js.map +1 -0
- package/lib/toErrorList.d.ts +8 -0
- package/lib/toErrorList.js +34 -0
- package/lib/toErrorList.js.map +1 -0
- package/lib/toErrorSchema.d.ts +21 -0
- package/lib/toErrorSchema.js +41 -0
- package/lib/toErrorSchema.js.map +1 -0
- package/lib/types.d.ts +982 -0
- package/lib/types.js +2 -0
- package/lib/types.js.map +1 -0
- package/lib/unwrapErrorHandler.d.ts +7 -0
- package/lib/unwrapErrorHandler.js +21 -0
- package/lib/unwrapErrorHandler.js.map +1 -0
- package/lib/utcToLocal.d.ts +6 -0
- package/lib/utcToLocal.js +26 -0
- package/lib/utcToLocal.js.map +1 -0
- package/lib/validationDataMerge.d.ts +11 -0
- package/lib/validationDataMerge.js +26 -0
- package/lib/validationDataMerge.js.map +1 -0
- package/lib/withIdRefPrefix.d.ts +8 -0
- package/lib/withIdRefPrefix.js +47 -0
- package/lib/withIdRefPrefix.js.map +1 -0
- package/package.json +20 -13
- package/src/ErrorSchemaBuilder.ts +112 -0
- package/src/allowAdditionalItems.ts +15 -0
- package/src/asNumber.ts +38 -0
- package/src/canExpand.ts +31 -0
- package/src/constants.ts +31 -0
- package/src/createErrorHandler.ts +33 -0
- package/src/createSchemaUtils.ts +298 -0
- package/src/dataURItoBlob.ts +42 -0
- package/src/deepEquals.ts +19 -0
- package/src/englishStringTranslator.ts +14 -0
- package/src/enumOptionsDeselectValue.ts +28 -0
- package/src/enumOptionsIndexForValue.ts +27 -0
- package/src/enumOptionsIsSelected.ts +19 -0
- package/src/enumOptionsSelectValue.ts +28 -0
- package/src/enumOptionsValueForIndex.ts +26 -0
- package/src/enums.ts +74 -0
- package/src/findSchemaDefinition.ts +54 -0
- package/src/getDiscriminatorFieldFromSchema.ts +21 -0
- package/src/getInputProps.ts +55 -0
- package/src/getSchemaType.ts +37 -0
- package/src/getSubmitButtonOptions.ts +32 -0
- package/src/getTemplate.ts +26 -0
- package/src/getUiOptions.ts +32 -0
- package/src/getWidget.tsx +133 -0
- package/src/guessType.ts +28 -0
- package/src/hasWidget.ts +27 -0
- package/src/hashForSchema.ts +31 -0
- package/src/idGenerators.ts +81 -0
- package/src/index.ts +118 -0
- package/src/isConstant.ts +12 -0
- package/src/isCustomWidget.ts +19 -0
- package/src/isFixedItems.ts +12 -0
- package/src/isObject.ts +15 -0
- package/src/labelValue.ts +16 -0
- package/src/localToUTC.ts +8 -0
- package/src/mergeDefaultsWithFormData.ts +53 -0
- package/src/mergeObjects.ts +39 -0
- package/src/mergeSchemas.ts +38 -0
- package/src/optionsList.ts +41 -0
- package/src/orderProperties.ts +44 -0
- package/src/pad.ts +13 -0
- package/src/parseDateString.ts +33 -0
- package/src/parser/ParserValidator.ts +132 -0
- package/src/parser/index.ts +6 -0
- package/src/parser/schemaParser.ts +60 -0
- package/src/rangeSpec.ts +22 -0
- package/src/replaceStringParameters.ts +22 -0
- package/src/schema/getClosestMatchingOption.ts +191 -0
- package/src/schema/getDefaultFormState.ts +447 -0
- package/src/schema/getDisplayLabel.ts +59 -0
- package/src/schema/getFirstMatchingOption.ts +27 -0
- package/src/schema/getMatchingOption.ts +95 -0
- package/src/schema/index.ts +29 -0
- package/src/schema/isFilesArray.ts +27 -0
- package/src/schema/isMultiSelect.ts +21 -0
- package/src/schema/isSelect.ts +26 -0
- package/src/schema/mergeValidationData.ts +38 -0
- package/src/schema/retrieveSchema.ts +614 -0
- package/src/schema/sanitizeDataForNewSchema.ts +197 -0
- package/src/schema/toIdSchema.ts +105 -0
- package/src/schema/toPathSchema.ts +121 -0
- package/src/schemaRequiresTrueValue.ts +40 -0
- package/src/shouldRender.ts +16 -0
- package/src/toConstant.ts +19 -0
- package/src/toDateString.ts +15 -0
- package/src/toErrorList.ts +41 -0
- package/src/toErrorSchema.ts +43 -0
- package/src/types.ts +1139 -0
- package/src/unwrapErrorHandler.ts +25 -0
- package/src/utcToLocal.ts +30 -0
- package/src/validationDataMerge.ts +31 -0
- package/src/withIdRefPrefix.ts +49 -0
- package/dist/index.d.ts +0 -1911
- package/dist/utils.cjs.development.js +0 -3522
- package/dist/utils.cjs.development.js.map +0 -1
- package/dist/utils.cjs.production.min.js +0 -2
- package/dist/utils.cjs.production.min.js.map +0 -1
- package/dist/utils.umd.development.js +0 -3504
- package/dist/utils.umd.development.js.map +0 -1
- package/dist/utils.umd.production.min.js +0 -2
- package/dist/utils.umd.production.min.js.map +0 -1
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { Experimental_DefaultFormStateBehavior, FormContextType, RJSFSchema, StrictRJSFSchema, ValidatorType } from '../types';
|
|
2
|
+
/** Enum that indicates how `schema.additionalItems` should be handled by the `getInnerSchemaForArrayItem()` function.
|
|
3
|
+
*/
|
|
4
|
+
export declare enum AdditionalItemsHandling {
|
|
5
|
+
Ignore = 0,
|
|
6
|
+
Invert = 1,
|
|
7
|
+
Fallback = 2
|
|
8
|
+
}
|
|
9
|
+
/** Given a `schema` will return an inner schema that for an array item. This is computed differently based on the
|
|
10
|
+
* `additionalItems` enum and the value of `idx`. There are four possible returns:
|
|
11
|
+
* 1. If `idx` is >= 0, then if `schema.items` is an array the `idx`th element of the array is returned if it is a valid
|
|
12
|
+
* index and not a boolean, otherwise it falls through to 3.
|
|
13
|
+
* 2. If `schema.items` is not an array AND truthy and not a boolean, then `schema.items` is returned since it actually
|
|
14
|
+
* is a schema, otherwise it falls through to 3.
|
|
15
|
+
* 3. If `additionalItems` is not `AdditionalItemsHandling.Ignore` and `schema.additionalItems` is an object, then
|
|
16
|
+
* `schema.additionalItems` is returned since it actually is a schema, otherwise it falls through to 4.
|
|
17
|
+
* 4. {} is returned representing an empty schema
|
|
18
|
+
*
|
|
19
|
+
* @param schema - The schema from which to get the particular item
|
|
20
|
+
* @param [additionalItems=AdditionalItemsHandling.Ignore] - How do we want to handle additional items?
|
|
21
|
+
* @param [idx=-1] - Index, if non-negative, will be used to return the idx-th element in a `schema.items` array
|
|
22
|
+
* @returns - The best fit schema object from the `schema` given the `additionalItems` and `idx` modifiers
|
|
23
|
+
*/
|
|
24
|
+
export declare function getInnerSchemaForArrayItem<S extends StrictRJSFSchema = RJSFSchema>(schema: S, additionalItems?: AdditionalItemsHandling, idx?: number): S;
|
|
25
|
+
interface ComputeDefaultsProps<T = any, S extends StrictRJSFSchema = RJSFSchema> {
|
|
26
|
+
parentDefaults?: T;
|
|
27
|
+
rootSchema?: S;
|
|
28
|
+
rawFormData?: T;
|
|
29
|
+
includeUndefinedValues?: boolean | 'excludeObjectChildren';
|
|
30
|
+
_recurseList?: string[];
|
|
31
|
+
experimental_defaultFormStateBehavior?: Experimental_DefaultFormStateBehavior;
|
|
32
|
+
required?: boolean;
|
|
33
|
+
}
|
|
34
|
+
/** Computes the defaults for the current `schema` given the `rawFormData` and `parentDefaults` if any. This drills into
|
|
35
|
+
* each level of the schema, recursively, to fill out every level of defaults provided by the schema.
|
|
36
|
+
*
|
|
37
|
+
* @param validator - an implementation of the `ValidatorType` interface that will be used when necessary
|
|
38
|
+
* @param rawSchema - The schema for which the default state is desired
|
|
39
|
+
* @param [props] - Optional props for this function
|
|
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.
|
|
49
|
+
* @returns - The resulting `formData` with all the defaults provided
|
|
50
|
+
*/
|
|
51
|
+
export declare function computeDefaults<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(validator: ValidatorType<T, S, F>, rawSchema: S, { parentDefaults, rawFormData, rootSchema, includeUndefinedValues, _recurseList, experimental_defaultFormStateBehavior, required, }?: ComputeDefaultsProps<T, S>): T | T[] | undefined;
|
|
52
|
+
/** Returns the superset of `formData` that includes the given set updated to include any missing fields that have
|
|
53
|
+
* computed to have defaults provided in the `schema`.
|
|
54
|
+
*
|
|
55
|
+
* @param validator - An implementation of the `ValidatorType` interface that will be used when necessary
|
|
56
|
+
* @param theSchema - The schema for which the default state is desired
|
|
57
|
+
* @param [formData] - The current formData, if any, onto which to provide any missing defaults
|
|
58
|
+
* @param [rootSchema] - The root schema, used to primarily to look up `$ref`s
|
|
59
|
+
* @param [includeUndefinedValues=false] - Optional flag, if true, cause undefined values to be added as defaults.
|
|
60
|
+
* If "excludeObjectChildren", cause undefined values for this object and pass `includeUndefinedValues` as
|
|
61
|
+
* false when computing defaults for any nested object properties.
|
|
62
|
+
* @param [experimental_defaultFormStateBehavior] Optional configuration object, if provided, allows users to override default form state behavior
|
|
63
|
+
* @returns - The resulting `formData` with all the defaults provided
|
|
64
|
+
*/
|
|
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;
|
|
66
|
+
export {};
|
|
@@ -0,0 +1,351 @@
|
|
|
1
|
+
import { __rest } from "tslib";
|
|
2
|
+
import get from 'lodash/get';
|
|
3
|
+
import isEmpty from 'lodash/isEmpty';
|
|
4
|
+
import { ANY_OF_KEY, DEFAULT_KEY, DEPENDENCIES_KEY, PROPERTIES_KEY, ONE_OF_KEY, REF_KEY } from '../constants';
|
|
5
|
+
import findSchemaDefinition from '../findSchemaDefinition';
|
|
6
|
+
import getClosestMatchingOption from './getClosestMatchingOption';
|
|
7
|
+
import getDiscriminatorFieldFromSchema from '../getDiscriminatorFieldFromSchema';
|
|
8
|
+
import getSchemaType from '../getSchemaType';
|
|
9
|
+
import isObject from '../isObject';
|
|
10
|
+
import isFixedItems from '../isFixedItems';
|
|
11
|
+
import mergeDefaultsWithFormData from '../mergeDefaultsWithFormData';
|
|
12
|
+
import mergeObjects from '../mergeObjects';
|
|
13
|
+
import mergeSchemas from '../mergeSchemas';
|
|
14
|
+
import isMultiSelect from './isMultiSelect';
|
|
15
|
+
import retrieveSchema, { resolveDependencies } from './retrieveSchema';
|
|
16
|
+
/** Enum that indicates how `schema.additionalItems` should be handled by the `getInnerSchemaForArrayItem()` function.
|
|
17
|
+
*/
|
|
18
|
+
export var AdditionalItemsHandling;
|
|
19
|
+
(function (AdditionalItemsHandling) {
|
|
20
|
+
AdditionalItemsHandling[AdditionalItemsHandling["Ignore"] = 0] = "Ignore";
|
|
21
|
+
AdditionalItemsHandling[AdditionalItemsHandling["Invert"] = 1] = "Invert";
|
|
22
|
+
AdditionalItemsHandling[AdditionalItemsHandling["Fallback"] = 2] = "Fallback";
|
|
23
|
+
})(AdditionalItemsHandling || (AdditionalItemsHandling = {}));
|
|
24
|
+
/** Given a `schema` will return an inner schema that for an array item. This is computed differently based on the
|
|
25
|
+
* `additionalItems` enum and the value of `idx`. There are four possible returns:
|
|
26
|
+
* 1. If `idx` is >= 0, then if `schema.items` is an array the `idx`th element of the array is returned if it is a valid
|
|
27
|
+
* index and not a boolean, otherwise it falls through to 3.
|
|
28
|
+
* 2. If `schema.items` is not an array AND truthy and not a boolean, then `schema.items` is returned since it actually
|
|
29
|
+
* is a schema, otherwise it falls through to 3.
|
|
30
|
+
* 3. If `additionalItems` is not `AdditionalItemsHandling.Ignore` and `schema.additionalItems` is an object, then
|
|
31
|
+
* `schema.additionalItems` is returned since it actually is a schema, otherwise it falls through to 4.
|
|
32
|
+
* 4. {} is returned representing an empty schema
|
|
33
|
+
*
|
|
34
|
+
* @param schema - The schema from which to get the particular item
|
|
35
|
+
* @param [additionalItems=AdditionalItemsHandling.Ignore] - How do we want to handle additional items?
|
|
36
|
+
* @param [idx=-1] - Index, if non-negative, will be used to return the idx-th element in a `schema.items` array
|
|
37
|
+
* @returns - The best fit schema object from the `schema` given the `additionalItems` and `idx` modifiers
|
|
38
|
+
*/
|
|
39
|
+
export function getInnerSchemaForArrayItem(schema, additionalItems = AdditionalItemsHandling.Ignore, idx = -1) {
|
|
40
|
+
if (idx >= 0) {
|
|
41
|
+
if (Array.isArray(schema.items) && idx < schema.items.length) {
|
|
42
|
+
const item = schema.items[idx];
|
|
43
|
+
if (typeof item !== 'boolean') {
|
|
44
|
+
return item;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
else if (schema.items && !Array.isArray(schema.items) && typeof schema.items !== 'boolean') {
|
|
49
|
+
return schema.items;
|
|
50
|
+
}
|
|
51
|
+
if (additionalItems !== AdditionalItemsHandling.Ignore && isObject(schema.additionalItems)) {
|
|
52
|
+
return schema.additionalItems;
|
|
53
|
+
}
|
|
54
|
+
return {};
|
|
55
|
+
}
|
|
56
|
+
/** Either add `computedDefault` at `key` into `obj` or not add it based on its value, the value of
|
|
57
|
+
* `includeUndefinedValues`, the value of `emptyObjectFields` and if its parent field is required. Generally undefined
|
|
58
|
+
* `computedDefault` values are added only when `includeUndefinedValues` is either true/"excludeObjectChildren". If `
|
|
59
|
+
* includeUndefinedValues` is false and `emptyObjectFields` is not "skipDefaults", then non-undefined and non-empty-object
|
|
60
|
+
* values will be added based on certain conditions.
|
|
61
|
+
*
|
|
62
|
+
* @param obj - The object into which the computed default may be added
|
|
63
|
+
* @param key - The key into the object at which the computed default may be added
|
|
64
|
+
* @param computedDefault - The computed default value that maybe should be added to the obj
|
|
65
|
+
* @param includeUndefinedValues - Optional flag, if true, cause undefined values to be added as defaults.
|
|
66
|
+
* If "excludeObjectChildren", cause undefined values for this object and pass `includeUndefinedValues` as
|
|
67
|
+
* false when computing defaults for any nested object properties. If "allowEmptyObject", prevents undefined
|
|
68
|
+
* values in this object while allow the object itself to be empty and passing `includeUndefinedValues` as
|
|
69
|
+
* false when computing defaults for any nested object properties.
|
|
70
|
+
* @param isParentRequired - The optional boolean that indicates whether the parent field is required
|
|
71
|
+
* @param requiredFields - The list of fields that are required
|
|
72
|
+
* @param experimental_defaultFormStateBehavior - Optional configuration object, if provided, allows users to override
|
|
73
|
+
* default form state behavior
|
|
74
|
+
*/
|
|
75
|
+
function maybeAddDefaultToObject(obj, key, computedDefault, includeUndefinedValues, isParentRequired, requiredFields = [], experimental_defaultFormStateBehavior = {}) {
|
|
76
|
+
const { emptyObjectFields = 'populateAllDefaults' } = experimental_defaultFormStateBehavior;
|
|
77
|
+
if (includeUndefinedValues) {
|
|
78
|
+
obj[key] = computedDefault;
|
|
79
|
+
}
|
|
80
|
+
else if (emptyObjectFields !== 'skipDefaults') {
|
|
81
|
+
if (isObject(computedDefault)) {
|
|
82
|
+
// If isParentRequired is undefined, then we are at the root level of the schema so defer to the requiredness of
|
|
83
|
+
// the field key itself in the `requiredField` list
|
|
84
|
+
const isSelfOrParentRequired = isParentRequired === undefined ? requiredFields.includes(key) : isParentRequired;
|
|
85
|
+
// Store computedDefault if it's a non-empty object(e.g. not {}) and satisfies certain conditions
|
|
86
|
+
// Condition 1: If computedDefault is not empty or if the key is a required field
|
|
87
|
+
// Condition 2: If the parent object is required or emptyObjectFields is not 'populateRequiredDefaults'
|
|
88
|
+
if ((!isEmpty(computedDefault) || requiredFields.includes(key)) &&
|
|
89
|
+
(isSelfOrParentRequired || emptyObjectFields !== 'populateRequiredDefaults')) {
|
|
90
|
+
obj[key] = computedDefault;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
else if (
|
|
94
|
+
// Store computedDefault if it's a defined primitive (e.g., true) and satisfies certain conditions
|
|
95
|
+
// Condition 1: computedDefault is not undefined
|
|
96
|
+
// Condition 2: If emptyObjectFields is 'populateAllDefaults' or if the key is a required field
|
|
97
|
+
computedDefault !== undefined &&
|
|
98
|
+
(emptyObjectFields === 'populateAllDefaults' || requiredFields.includes(key))) {
|
|
99
|
+
obj[key] = computedDefault;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
/** Computes the defaults for the current `schema` given the `rawFormData` and `parentDefaults` if any. This drills into
|
|
104
|
+
* each level of the schema, recursively, to fill out every level of defaults provided by the schema.
|
|
105
|
+
*
|
|
106
|
+
* @param validator - an implementation of the `ValidatorType` interface that will be used when necessary
|
|
107
|
+
* @param rawSchema - The schema for which the default state is desired
|
|
108
|
+
* @param [props] - Optional props for this function
|
|
109
|
+
* @param [props.parentDefaults] - Any defaults provided by the parent field in the schema
|
|
110
|
+
* @param [props.rootSchema] - The options root schema, used to primarily to look up `$ref`s
|
|
111
|
+
* @param [props.rawFormData] - The current formData, if any, onto which to provide any missing defaults
|
|
112
|
+
* @param [props.includeUndefinedValues=false] - Optional flag, if true, cause undefined values to be added as defaults.
|
|
113
|
+
* If "excludeObjectChildren", cause undefined values for this object and pass `includeUndefinedValues` as
|
|
114
|
+
* false when computing defaults for any nested object properties.
|
|
115
|
+
* @param [props._recurseList=[]] - The list of ref names currently being recursed, used to prevent infinite recursion
|
|
116
|
+
* @param [props.experimental_defaultFormStateBehavior] Optional configuration object, if provided, allows users to override default form state behavior
|
|
117
|
+
* @param [props.required] - Optional flag, if true, indicates this schema was required in the parent schema.
|
|
118
|
+
* @returns - The resulting `formData` with all the defaults provided
|
|
119
|
+
*/
|
|
120
|
+
export function computeDefaults(validator, rawSchema, { parentDefaults, rawFormData, rootSchema = {}, includeUndefinedValues = false, _recurseList = [], experimental_defaultFormStateBehavior = undefined, required, } = {}) {
|
|
121
|
+
var _a, _b;
|
|
122
|
+
const formData = (isObject(rawFormData) ? rawFormData : {});
|
|
123
|
+
const schema = isObject(rawSchema) ? rawSchema : {};
|
|
124
|
+
// Compute the defaults recursively: give highest priority to deepest nodes.
|
|
125
|
+
let defaults = parentDefaults;
|
|
126
|
+
// If we get a new schema, then we need to recompute defaults again for the new schema found.
|
|
127
|
+
let schemaToCompute = null;
|
|
128
|
+
let updatedRecurseList = _recurseList;
|
|
129
|
+
if (isObject(defaults) && isObject(schema.default)) {
|
|
130
|
+
// For object defaults, only override parent defaults that are defined in
|
|
131
|
+
// schema.default.
|
|
132
|
+
defaults = mergeObjects(defaults, schema.default);
|
|
133
|
+
}
|
|
134
|
+
else if (DEFAULT_KEY in schema) {
|
|
135
|
+
defaults = schema.default;
|
|
136
|
+
}
|
|
137
|
+
else if (REF_KEY in schema) {
|
|
138
|
+
const refName = schema[REF_KEY];
|
|
139
|
+
// Use referenced schema defaults for this node.
|
|
140
|
+
if (!_recurseList.includes(refName)) {
|
|
141
|
+
updatedRecurseList = _recurseList.concat(refName);
|
|
142
|
+
schemaToCompute = findSchemaDefinition(refName, rootSchema);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
else if (DEPENDENCIES_KEY in schema) {
|
|
146
|
+
const resolvedSchema = resolveDependencies(validator, schema, rootSchema, false, formData);
|
|
147
|
+
schemaToCompute = resolvedSchema[0]; // pick the first element from resolve dependencies
|
|
148
|
+
}
|
|
149
|
+
else if (isFixedItems(schema)) {
|
|
150
|
+
defaults = schema.items.map((itemSchema, idx) => computeDefaults(validator, itemSchema, {
|
|
151
|
+
rootSchema,
|
|
152
|
+
includeUndefinedValues,
|
|
153
|
+
_recurseList,
|
|
154
|
+
experimental_defaultFormStateBehavior,
|
|
155
|
+
parentDefaults: Array.isArray(parentDefaults) ? parentDefaults[idx] : undefined,
|
|
156
|
+
rawFormData: formData,
|
|
157
|
+
required,
|
|
158
|
+
}));
|
|
159
|
+
}
|
|
160
|
+
else if (ONE_OF_KEY in schema) {
|
|
161
|
+
const { oneOf } = schema, remaining = __rest(schema, ["oneOf"]);
|
|
162
|
+
if (oneOf.length === 0) {
|
|
163
|
+
return undefined;
|
|
164
|
+
}
|
|
165
|
+
const discriminator = getDiscriminatorFieldFromSchema(schema);
|
|
166
|
+
schemaToCompute = oneOf[getClosestMatchingOption(validator, rootSchema, isEmpty(formData) ? undefined : formData, oneOf, 0, discriminator)];
|
|
167
|
+
schemaToCompute = mergeSchemas(remaining, schemaToCompute);
|
|
168
|
+
}
|
|
169
|
+
else if (ANY_OF_KEY in schema) {
|
|
170
|
+
const { anyOf } = schema, remaining = __rest(schema, ["anyOf"]);
|
|
171
|
+
if (anyOf.length === 0) {
|
|
172
|
+
return undefined;
|
|
173
|
+
}
|
|
174
|
+
const discriminator = getDiscriminatorFieldFromSchema(schema);
|
|
175
|
+
schemaToCompute = anyOf[getClosestMatchingOption(validator, rootSchema, isEmpty(formData) ? undefined : formData, anyOf, 0, discriminator)];
|
|
176
|
+
schemaToCompute = mergeSchemas(remaining, schemaToCompute);
|
|
177
|
+
}
|
|
178
|
+
if (schemaToCompute) {
|
|
179
|
+
return computeDefaults(validator, schemaToCompute, {
|
|
180
|
+
rootSchema,
|
|
181
|
+
includeUndefinedValues,
|
|
182
|
+
_recurseList: updatedRecurseList,
|
|
183
|
+
experimental_defaultFormStateBehavior,
|
|
184
|
+
parentDefaults: defaults,
|
|
185
|
+
rawFormData: formData,
|
|
186
|
+
required,
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
// No defaults defined for this node, fallback to generic typed ones.
|
|
190
|
+
if (defaults === undefined) {
|
|
191
|
+
defaults = schema.default;
|
|
192
|
+
}
|
|
193
|
+
switch (getSchemaType(schema)) {
|
|
194
|
+
// We need to recurse for object schema inner default values.
|
|
195
|
+
case 'object': {
|
|
196
|
+
const objectDefaults = Object.keys(schema.properties || {}).reduce((acc, key) => {
|
|
197
|
+
var _a;
|
|
198
|
+
// Compute the defaults for this node, with the parent defaults we might
|
|
199
|
+
// have from a previous run: defaults[key].
|
|
200
|
+
const computedDefault = computeDefaults(validator, get(schema, [PROPERTIES_KEY, key]), {
|
|
201
|
+
rootSchema,
|
|
202
|
+
_recurseList,
|
|
203
|
+
experimental_defaultFormStateBehavior,
|
|
204
|
+
includeUndefinedValues: includeUndefinedValues === true,
|
|
205
|
+
parentDefaults: get(defaults, [key]),
|
|
206
|
+
rawFormData: get(formData, [key]),
|
|
207
|
+
required: (_a = schema.required) === null || _a === void 0 ? void 0 : _a.includes(key),
|
|
208
|
+
});
|
|
209
|
+
maybeAddDefaultToObject(acc, key, computedDefault, includeUndefinedValues, required, schema.required, experimental_defaultFormStateBehavior);
|
|
210
|
+
return acc;
|
|
211
|
+
}, {});
|
|
212
|
+
if (schema.additionalProperties) {
|
|
213
|
+
// as per spec additionalProperties may be either schema or boolean
|
|
214
|
+
const additionalPropertiesSchema = isObject(schema.additionalProperties) ? schema.additionalProperties : {};
|
|
215
|
+
const keys = new Set();
|
|
216
|
+
if (isObject(defaults)) {
|
|
217
|
+
Object.keys(defaults)
|
|
218
|
+
.filter((key) => !schema.properties || !schema.properties[key])
|
|
219
|
+
.forEach((key) => keys.add(key));
|
|
220
|
+
}
|
|
221
|
+
let formDataRequired;
|
|
222
|
+
if (isObject(formData)) {
|
|
223
|
+
formDataRequired = [];
|
|
224
|
+
Object.keys(formData)
|
|
225
|
+
.filter((key) => !schema.properties || !schema.properties[key])
|
|
226
|
+
.forEach((key) => {
|
|
227
|
+
keys.add(key);
|
|
228
|
+
formDataRequired.push(key);
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
keys.forEach((key) => {
|
|
232
|
+
var _a;
|
|
233
|
+
const computedDefault = computeDefaults(validator, additionalPropertiesSchema, {
|
|
234
|
+
rootSchema,
|
|
235
|
+
_recurseList,
|
|
236
|
+
experimental_defaultFormStateBehavior,
|
|
237
|
+
includeUndefinedValues: includeUndefinedValues === true,
|
|
238
|
+
parentDefaults: get(defaults, [key]),
|
|
239
|
+
rawFormData: get(formData, [key]),
|
|
240
|
+
required: (_a = schema.required) === null || _a === void 0 ? void 0 : _a.includes(key),
|
|
241
|
+
});
|
|
242
|
+
// Since these are additional properties we don’t need to add the `experimental_defaultFormStateBehavior` prop
|
|
243
|
+
maybeAddDefaultToObject(objectDefaults, key, computedDefault, includeUndefinedValues, required, formDataRequired);
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
return objectDefaults;
|
|
247
|
+
}
|
|
248
|
+
case 'array': {
|
|
249
|
+
const neverPopulate = ((_a = experimental_defaultFormStateBehavior === null || experimental_defaultFormStateBehavior === void 0 ? void 0 : experimental_defaultFormStateBehavior.arrayMinItems) === null || _a === void 0 ? void 0 : _a.populate) === 'never';
|
|
250
|
+
const ignoreMinItemsFlagSet = ((_b = experimental_defaultFormStateBehavior === null || experimental_defaultFormStateBehavior === void 0 ? void 0 : experimental_defaultFormStateBehavior.arrayMinItems) === null || _b === void 0 ? void 0 : _b.populate) === 'requiredOnly';
|
|
251
|
+
// Inject defaults into existing array defaults
|
|
252
|
+
if (Array.isArray(defaults)) {
|
|
253
|
+
defaults = defaults.map((item, idx) => {
|
|
254
|
+
const schemaItem = getInnerSchemaForArrayItem(schema, AdditionalItemsHandling.Fallback, idx);
|
|
255
|
+
return computeDefaults(validator, schemaItem, {
|
|
256
|
+
rootSchema,
|
|
257
|
+
_recurseList,
|
|
258
|
+
experimental_defaultFormStateBehavior,
|
|
259
|
+
parentDefaults: item,
|
|
260
|
+
required,
|
|
261
|
+
});
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
// Deeply inject defaults into already existing form data
|
|
265
|
+
if (Array.isArray(rawFormData)) {
|
|
266
|
+
const schemaItem = getInnerSchemaForArrayItem(schema);
|
|
267
|
+
if (neverPopulate) {
|
|
268
|
+
defaults = rawFormData;
|
|
269
|
+
}
|
|
270
|
+
else {
|
|
271
|
+
defaults = rawFormData.map((item, idx) => {
|
|
272
|
+
return computeDefaults(validator, schemaItem, {
|
|
273
|
+
rootSchema,
|
|
274
|
+
_recurseList,
|
|
275
|
+
experimental_defaultFormStateBehavior,
|
|
276
|
+
rawFormData: item,
|
|
277
|
+
parentDefaults: get(defaults, [idx]),
|
|
278
|
+
required,
|
|
279
|
+
});
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
if (neverPopulate) {
|
|
284
|
+
return defaults !== null && defaults !== void 0 ? defaults : [];
|
|
285
|
+
}
|
|
286
|
+
if (ignoreMinItemsFlagSet && !required) {
|
|
287
|
+
// If no form data exists or defaults are set leave the field empty/non-existent, otherwise
|
|
288
|
+
// return form data/defaults
|
|
289
|
+
return defaults ? defaults : undefined;
|
|
290
|
+
}
|
|
291
|
+
const defaultsLength = Array.isArray(defaults) ? defaults.length : 0;
|
|
292
|
+
if (!schema.minItems ||
|
|
293
|
+
isMultiSelect(validator, schema, rootSchema) ||
|
|
294
|
+
schema.minItems <= defaultsLength) {
|
|
295
|
+
return defaults ? defaults : [];
|
|
296
|
+
}
|
|
297
|
+
const defaultEntries = (defaults || []);
|
|
298
|
+
const fillerSchema = getInnerSchemaForArrayItem(schema, AdditionalItemsHandling.Invert);
|
|
299
|
+
const fillerDefault = fillerSchema.default;
|
|
300
|
+
// Calculate filler entries for remaining items (minItems - existing raw data/defaults)
|
|
301
|
+
const fillerEntries = new Array(schema.minItems - defaultsLength).fill(computeDefaults(validator, fillerSchema, {
|
|
302
|
+
parentDefaults: fillerDefault,
|
|
303
|
+
rootSchema,
|
|
304
|
+
_recurseList,
|
|
305
|
+
experimental_defaultFormStateBehavior,
|
|
306
|
+
required,
|
|
307
|
+
}));
|
|
308
|
+
// then fill up the rest with either the item default or empty, up to minItems
|
|
309
|
+
return defaultEntries.concat(fillerEntries);
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
return defaults;
|
|
313
|
+
}
|
|
314
|
+
/** Returns the superset of `formData` that includes the given set updated to include any missing fields that have
|
|
315
|
+
* computed to have defaults provided in the `schema`.
|
|
316
|
+
*
|
|
317
|
+
* @param validator - An implementation of the `ValidatorType` interface that will be used when necessary
|
|
318
|
+
* @param theSchema - The schema for which the default state is desired
|
|
319
|
+
* @param [formData] - The current formData, if any, onto which to provide any missing defaults
|
|
320
|
+
* @param [rootSchema] - The root schema, used to primarily to look up `$ref`s
|
|
321
|
+
* @param [includeUndefinedValues=false] - Optional flag, if true, cause undefined values to be added as defaults.
|
|
322
|
+
* If "excludeObjectChildren", cause undefined values for this object and pass `includeUndefinedValues` as
|
|
323
|
+
* false when computing defaults for any nested object properties.
|
|
324
|
+
* @param [experimental_defaultFormStateBehavior] Optional configuration object, if provided, allows users to override default form state behavior
|
|
325
|
+
* @returns - The resulting `formData` with all the defaults provided
|
|
326
|
+
*/
|
|
327
|
+
export default function getDefaultFormState(validator, theSchema, formData, rootSchema, includeUndefinedValues = false, experimental_defaultFormStateBehavior) {
|
|
328
|
+
if (!isObject(theSchema)) {
|
|
329
|
+
throw new Error('Invalid schema: ' + theSchema);
|
|
330
|
+
}
|
|
331
|
+
const schema = retrieveSchema(validator, theSchema, rootSchema, formData);
|
|
332
|
+
const defaults = computeDefaults(validator, schema, {
|
|
333
|
+
rootSchema,
|
|
334
|
+
includeUndefinedValues,
|
|
335
|
+
experimental_defaultFormStateBehavior,
|
|
336
|
+
rawFormData: formData,
|
|
337
|
+
});
|
|
338
|
+
if (formData === undefined || formData === null || (typeof formData === 'number' && isNaN(formData))) {
|
|
339
|
+
// No form data? Use schema defaults.
|
|
340
|
+
return defaults;
|
|
341
|
+
}
|
|
342
|
+
const { mergeExtraDefaults } = (experimental_defaultFormStateBehavior === null || experimental_defaultFormStateBehavior === void 0 ? void 0 : experimental_defaultFormStateBehavior.arrayMinItems) || {};
|
|
343
|
+
if (isObject(formData)) {
|
|
344
|
+
return mergeDefaultsWithFormData(defaults, formData, mergeExtraDefaults);
|
|
345
|
+
}
|
|
346
|
+
if (Array.isArray(formData)) {
|
|
347
|
+
return mergeDefaultsWithFormData(defaults, formData, mergeExtraDefaults);
|
|
348
|
+
}
|
|
349
|
+
return formData;
|
|
350
|
+
}
|
|
351
|
+
//# sourceMappingURL=getDefaultFormState.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getDefaultFormState.js","sourceRoot":"","sources":["../../src/schema/getDefaultFormState.ts"],"names":[],"mappings":";AAAA,OAAO,GAAG,MAAM,YAAY,CAAC;AAC7B,OAAO,OAAO,MAAM,gBAAgB,CAAC;AAErC,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,gBAAgB,EAAE,cAAc,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC9G,OAAO,oBAAoB,MAAM,yBAAyB,CAAC;AAC3D,OAAO,wBAAwB,MAAM,4BAA4B,CAAC;AAClE,OAAO,+BAA+B,MAAM,oCAAoC,CAAC;AACjF,OAAO,aAAa,MAAM,kBAAkB,CAAC;AAC7C,OAAO,QAAQ,MAAM,aAAa,CAAC;AACnC,OAAO,YAAY,MAAM,iBAAiB,CAAC;AAC3C,OAAO,yBAAyB,MAAM,8BAA8B,CAAC;AACrE,OAAO,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I,QAAQ,CAAC,QAAQ,CAAC,EAAE;QACtB,OAAO,yBAAyB,CAAI,QAAa,EAAE,QAAQ,EAAE,kBAAkB,CAAC,CAAC;KAClF;IACD,IAAI,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE;QAC3B,OAAO,yBAAyB,CAAM,QAAe,EAAE,QAAQ,EAAE,kBAAkB,CAAC,CAAC;KACtF;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { FormContextType, GlobalUISchemaOptions, RJSFSchema, StrictRJSFSchema, UiSchema, ValidatorType } from '../types';
|
|
2
|
+
/** Determines whether the combination of `schema` and `uiSchema` properties indicates that the label for the `schema`
|
|
3
|
+
* should be displayed in a UI.
|
|
4
|
+
*
|
|
5
|
+
* @param validator - An implementation of the `ValidatorType` interface that will be used when necessary
|
|
6
|
+
* @param schema - The schema for which the display label flag is desired
|
|
7
|
+
* @param [uiSchema={}] - The UI schema from which to derive potentially displayable information
|
|
8
|
+
* @param [rootSchema] - The root schema, used to primarily to look up `$ref`s
|
|
9
|
+
* @param [globalOptions={}] - The optional Global UI Schema from which to get any fallback `xxx` options
|
|
10
|
+
* @returns - True if the label should be displayed or false if it should not
|
|
11
|
+
*/
|
|
12
|
+
export default function getDisplayLabel<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(validator: ValidatorType<T, S, F>, schema: S, uiSchema?: UiSchema<T, S, F>, rootSchema?: S, globalOptions?: GlobalUISchemaOptions): boolean;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { UI_FIELD_KEY, UI_WIDGET_KEY } from '../constants';
|
|
2
|
+
import getSchemaType from '../getSchemaType';
|
|
3
|
+
import getUiOptions from '../getUiOptions';
|
|
4
|
+
import isCustomWidget from '../isCustomWidget';
|
|
5
|
+
import isFilesArray from './isFilesArray';
|
|
6
|
+
import isMultiSelect from './isMultiSelect';
|
|
7
|
+
/** Determines whether the combination of `schema` and `uiSchema` properties indicates that the label for the `schema`
|
|
8
|
+
* should be displayed in a UI.
|
|
9
|
+
*
|
|
10
|
+
* @param validator - An implementation of the `ValidatorType` interface that will be used when necessary
|
|
11
|
+
* @param schema - The schema for which the display label flag is desired
|
|
12
|
+
* @param [uiSchema={}] - The UI schema from which to derive potentially displayable information
|
|
13
|
+
* @param [rootSchema] - The root schema, used to primarily to look up `$ref`s
|
|
14
|
+
* @param [globalOptions={}] - The optional Global UI Schema from which to get any fallback `xxx` options
|
|
15
|
+
* @returns - True if the label should be displayed or false if it should not
|
|
16
|
+
*/
|
|
17
|
+
export default function getDisplayLabel(validator, schema, uiSchema = {}, rootSchema, globalOptions) {
|
|
18
|
+
const uiOptions = getUiOptions(uiSchema, globalOptions);
|
|
19
|
+
const { label = true } = uiOptions;
|
|
20
|
+
let displayLabel = !!label;
|
|
21
|
+
const schemaType = getSchemaType(schema);
|
|
22
|
+
if (schemaType === 'array') {
|
|
23
|
+
displayLabel =
|
|
24
|
+
isMultiSelect(validator, schema, rootSchema) ||
|
|
25
|
+
isFilesArray(validator, schema, uiSchema, rootSchema) ||
|
|
26
|
+
isCustomWidget(uiSchema);
|
|
27
|
+
}
|
|
28
|
+
if (schemaType === 'object') {
|
|
29
|
+
displayLabel = false;
|
|
30
|
+
}
|
|
31
|
+
if (schemaType === 'boolean' && !uiSchema[UI_WIDGET_KEY]) {
|
|
32
|
+
displayLabel = false;
|
|
33
|
+
}
|
|
34
|
+
if (uiSchema[UI_FIELD_KEY]) {
|
|
35
|
+
displayLabel = false;
|
|
36
|
+
}
|
|
37
|
+
return displayLabel;
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=getDisplayLabel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getDisplayLabel.js","sourceRoot":"","sources":["../../src/schema/getDisplayLabel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC3D,OAAO,aAAa,MAAM,kBAAkB,CAAC;AAC7C,OAAO,YAAY,MAAM,iBAAiB,CAAC;AAC3C,OAAO,cAAc,MAAM,mBAAmB,CAAC;AAS/C,OAAO,YAAY,MAAM,gBAAgB,CAAC;AAC1C,OAAO,aAAa,MAAM,iBAAiB,CAAC;AAE5C;;;;;;;;;GASG;AACH,MAAM,CAAC,OAAO,UAAU,eAAe,CAKrC,SAAiC,EACjC,MAAS,EACT,WAA8B,EAAE,EAChC,UAAc,EACd,aAAqC;IAErC,MAAM,SAAS,GAAG,YAAY,CAAU,QAAQ,EAAE,aAAa,CAAC,CAAC;IACjE,MAAM,EAAE,KAAK,GAAG,IAAI,EAAE,GAAG,SAAS,CAAC;IACnC,IAAI,YAAY,GAAG,CAAC,CAAC,KAAK,CAAC;IAC3B,MAAM,UAAU,GAAG,aAAa,CAAI,MAAM,CAAC,CAAC;IAE5C,IAAI,UAAU,KAAK,OAAO,EAAE;QAC1B,YAAY;YACV,aAAa,CAAU,SAAS,EAAE,MAAM,EAAE,UAAU,CAAC;gBACrD,YAAY,CAAU,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,UAAU,CAAC;gBAC9D,cAAc,CAAC,QAAQ,CAAC,CAAC;KAC5B;IAED,IAAI,UAAU,KAAK,QAAQ,EAAE;QAC3B,YAAY,GAAG,KAAK,CAAC;KACtB;IACD,IAAI,UAAU,KAAK,SAAS,IAAI,CAAC,QAAQ,CAAC,aAAa,CAAC,EAAE;QACxD,YAAY,GAAG,KAAK,CAAC;KACtB;IACD,IAAI,QAAQ,CAAC,YAAY,CAAC,EAAE;QAC1B,YAAY,GAAG,KAAK,CAAC;KACtB;IACD,OAAO,YAAY,CAAC;AACtB,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { FormContextType, RJSFSchema, StrictRJSFSchema, ValidatorType } from '../types';
|
|
2
|
+
/** Given the `formData` and list of `options`, attempts to find the index of the first option that matches the data.
|
|
3
|
+
* Always returns the first option if there is nothing that matches.
|
|
4
|
+
*
|
|
5
|
+
* @param validator - An implementation of the `ValidatorType` interface that will be used when necessary
|
|
6
|
+
* @param formData - The current formData, if any, used to figure out a match
|
|
7
|
+
* @param options - The list of options to find a matching options from
|
|
8
|
+
* @param rootSchema - The root schema, used to primarily to look up `$ref`s
|
|
9
|
+
* @param [discriminatorField] - The optional name of the field within the options object whose value is used to
|
|
10
|
+
* determine which option is selected
|
|
11
|
+
* @returns - The index of the first matched option or 0 if none is available
|
|
12
|
+
*/
|
|
13
|
+
export default function getFirstMatchingOption<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(validator: ValidatorType<T, S, F>, formData: T | undefined, options: S[], rootSchema: S, discriminatorField?: string): number;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import getMatchingOption from './getMatchingOption';
|
|
2
|
+
/** Given the `formData` and list of `options`, attempts to find the index of the first option that matches the data.
|
|
3
|
+
* Always returns the first option if there is nothing that matches.
|
|
4
|
+
*
|
|
5
|
+
* @param validator - An implementation of the `ValidatorType` interface that will be used when necessary
|
|
6
|
+
* @param formData - The current formData, if any, used to figure out a match
|
|
7
|
+
* @param options - The list of options to find a matching options from
|
|
8
|
+
* @param rootSchema - The root schema, used to primarily to look up `$ref`s
|
|
9
|
+
* @param [discriminatorField] - The optional name of the field within the options object whose value is used to
|
|
10
|
+
* determine which option is selected
|
|
11
|
+
* @returns - The index of the first matched option or 0 if none is available
|
|
12
|
+
*/
|
|
13
|
+
export default function getFirstMatchingOption(validator, formData, options, rootSchema, discriminatorField) {
|
|
14
|
+
return getMatchingOption(validator, formData, options, rootSchema, discriminatorField);
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=getFirstMatchingOption.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getFirstMatchingOption.js","sourceRoot":"","sources":["../../src/schema/getFirstMatchingOption.ts"],"names":[],"mappings":"AAAA,OAAO,iBAAiB,MAAM,qBAAqB,CAAC;AAGpD;;;;;;;;;;GAUG;AACH,MAAM,CAAC,OAAO,UAAU,sBAAsB,CAK5C,SAAiC,EACjC,QAAuB,EACvB,OAAY,EACZ,UAAa,EACb,kBAA2B;IAE3B,OAAO,iBAAiB,CAAU,SAAS,EAAE,QAAQ,EAAE,OAAO,EAAE,UAAU,EAAE,kBAAkB,CAAC,CAAC;AAClG,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { FormContextType, RJSFSchema, StrictRJSFSchema, ValidatorType } from '../types';
|
|
2
|
+
/** Given the `formData` and list of `options`, attempts to find the index of the option that best matches the data.
|
|
3
|
+
* Deprecated, use `getFirstMatchingOption()` instead.
|
|
4
|
+
*
|
|
5
|
+
* @param validator - An implementation of the `ValidatorType` interface that will be used when necessary
|
|
6
|
+
* @param formData - The current formData, if any, used to figure out a match
|
|
7
|
+
* @param options - The list of options to find a matching options from
|
|
8
|
+
* @param rootSchema - The root schema, used to primarily to look up `$ref`s
|
|
9
|
+
* @param [discriminatorField] - The optional name of the field within the options object whose value is used to
|
|
10
|
+
* determine which option is selected
|
|
11
|
+
* @returns - The index of the matched option or 0 if none is available
|
|
12
|
+
* @deprecated
|
|
13
|
+
*/
|
|
14
|
+
export default function getMatchingOption<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(validator: ValidatorType<T, S, F>, formData: T | undefined, options: S[], rootSchema: S, discriminatorField?: string): number;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { __rest } from "tslib";
|
|
2
|
+
import get from 'lodash/get';
|
|
3
|
+
import has from 'lodash/has';
|
|
4
|
+
import { PROPERTIES_KEY } from '../constants';
|
|
5
|
+
/** Given the `formData` and list of `options`, attempts to find the index of the option that best matches the data.
|
|
6
|
+
* Deprecated, use `getFirstMatchingOption()` instead.
|
|
7
|
+
*
|
|
8
|
+
* @param validator - An implementation of the `ValidatorType` interface that will be used when necessary
|
|
9
|
+
* @param formData - The current formData, if any, used to figure out a match
|
|
10
|
+
* @param options - The list of options to find a matching options from
|
|
11
|
+
* @param rootSchema - The root schema, used to primarily to look up `$ref`s
|
|
12
|
+
* @param [discriminatorField] - The optional name of the field within the options object whose value is used to
|
|
13
|
+
* determine which option is selected
|
|
14
|
+
* @returns - The index of the matched option or 0 if none is available
|
|
15
|
+
* @deprecated
|
|
16
|
+
*/
|
|
17
|
+
export default function getMatchingOption(validator, formData, options, rootSchema, discriminatorField) {
|
|
18
|
+
// For performance, skip validating subschemas if formData is undefined. We just
|
|
19
|
+
// want to get the first option in that case.
|
|
20
|
+
if (formData === undefined) {
|
|
21
|
+
return 0;
|
|
22
|
+
}
|
|
23
|
+
for (let i = 0; i < options.length; i++) {
|
|
24
|
+
const option = options[i];
|
|
25
|
+
// If we have a discriminator field, then we will use this to make the determination
|
|
26
|
+
if (discriminatorField && has(option, [PROPERTIES_KEY, discriminatorField])) {
|
|
27
|
+
const value = get(formData, discriminatorField);
|
|
28
|
+
const discriminator = get(option, [PROPERTIES_KEY, discriminatorField], {});
|
|
29
|
+
if (validator.isValid(discriminator, value, rootSchema)) {
|
|
30
|
+
return i;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
else if (option[PROPERTIES_KEY]) {
|
|
34
|
+
// If the schema describes an object then we need to add slightly more
|
|
35
|
+
// strict matching to the schema, because unless the schema uses the
|
|
36
|
+
// "requires" keyword, an object will match the schema as long as it
|
|
37
|
+
// doesn't have matching keys with a conflicting type. To do this we use an
|
|
38
|
+
// "anyOf" with an array of requires. This augmentation expresses that the
|
|
39
|
+
// schema should match if any of the keys in the schema are present on the
|
|
40
|
+
// object and pass validation.
|
|
41
|
+
//
|
|
42
|
+
// Create an "anyOf" schema that requires at least one of the keys in the
|
|
43
|
+
// "properties" object
|
|
44
|
+
const requiresAnyOf = {
|
|
45
|
+
anyOf: Object.keys(option[PROPERTIES_KEY]).map((key) => ({
|
|
46
|
+
required: [key],
|
|
47
|
+
})),
|
|
48
|
+
};
|
|
49
|
+
let augmentedSchema;
|
|
50
|
+
// If the "anyOf" keyword already exists, wrap the augmentation in an "allOf"
|
|
51
|
+
if (option.anyOf) {
|
|
52
|
+
// Create a shallow clone of the option
|
|
53
|
+
const shallowClone = __rest(option, []);
|
|
54
|
+
if (!shallowClone.allOf) {
|
|
55
|
+
shallowClone.allOf = [];
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
// If "allOf" already exists, shallow clone the array
|
|
59
|
+
shallowClone.allOf = shallowClone.allOf.slice();
|
|
60
|
+
}
|
|
61
|
+
shallowClone.allOf.push(requiresAnyOf);
|
|
62
|
+
augmentedSchema = shallowClone;
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
augmentedSchema = Object.assign({}, option, requiresAnyOf);
|
|
66
|
+
}
|
|
67
|
+
// Remove the "required" field as it's likely that not all fields have
|
|
68
|
+
// been filled in yet, which will mean that the schema is not valid
|
|
69
|
+
delete augmentedSchema.required;
|
|
70
|
+
if (validator.isValid(augmentedSchema, formData, rootSchema)) {
|
|
71
|
+
return i;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
else if (validator.isValid(option, formData, rootSchema)) {
|
|
75
|
+
return i;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return 0;
|
|
79
|
+
}
|
|
80
|
+
//# sourceMappingURL=getMatchingOption.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getMatchingOption.js","sourceRoot":"","sources":["../../src/schema/getMatchingOption.ts"],"names":[],"mappings":";AAAA,OAAO,GAAG,MAAM,YAAY,CAAC;AAC7B,OAAO,GAAG,MAAM,YAAY,CAAC;AAE7B,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAG9C;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,OAAO,UAAU,iBAAiB,CAKvC,SAAiC,EACjC,QAAuB,EACvB,OAAY,EACZ,UAAa,EACb,kBAA2B;IAE3B,gFAAgF;IAChF,6CAA6C;IAC7C,IAAI,QAAQ,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