@rjsf/utils 5.5.1 → 5.6.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.d.ts +91 -10
- package/dist/utils.cjs.development.js +250 -21
- package/dist/utils.cjs.development.js.map +1 -1
- package/dist/utils.cjs.production.min.js +1 -1
- package/dist/utils.cjs.production.min.js.map +1 -1
- package/dist/utils.esm.js +242 -22
- package/dist/utils.esm.js.map +1 -1
- package/dist/utils.umd.development.js +252 -25
- package/dist/utils.umd.development.js.map +1 -1
- package/dist/utils.umd.production.min.js +1 -1
- package/dist/utils.umd.production.min.js.map +1 -1
- package/package.json +6 -5
package/dist/index.d.ts
CHANGED
|
@@ -847,6 +847,8 @@ interface ValidatorType<T = any, S extends StrictRJSFSchema = RJSFSchema, F exte
|
|
|
847
847
|
*
|
|
848
848
|
* @param errorSchema - The `ErrorSchema` instance to convert
|
|
849
849
|
* @param [fieldPath=[]] - The current field path, defaults to [] if not specified
|
|
850
|
+
* @deprecated - Use the `toErrorList()` function provided by `@rjsf/utils` instead. This function will be removed in
|
|
851
|
+
* the next major release.
|
|
850
852
|
*/
|
|
851
853
|
toErrorList(errorSchema?: ErrorSchema<T>, fieldPath?: string[]): RJSFValidationError[];
|
|
852
854
|
/** Validates data against a schema, returning true if the data is valid, or
|
|
@@ -918,26 +920,32 @@ interface SchemaUtilsType<T = any, S extends StrictRJSFSchema = RJSFSchema, F ex
|
|
|
918
920
|
* @param formData - The form data associated with the schema
|
|
919
921
|
* @param options - The list of options that can be selected from
|
|
920
922
|
* @param [selectedOption] - The index of the currently selected option, defaulted to -1 if not specified
|
|
923
|
+
* @param [discriminatorField] - The optional name of the field within the options object whose value is used to
|
|
924
|
+
* determine which option is selected
|
|
921
925
|
* @returns - The index of the option that is the closest match to the `formData` or the `selectedOption` if no match
|
|
922
926
|
*/
|
|
923
|
-
getClosestMatchingOption(formData: T | undefined, options: S[], selectedOption?: number): number;
|
|
927
|
+
getClosestMatchingOption(formData: T | undefined, options: S[], selectedOption?: number, discriminatorField?: string): number;
|
|
924
928
|
/** Given the `formData` and list of `options`, attempts to find the index of the first option that matches the data.
|
|
925
929
|
* Always returns the first option if there is nothing that matches.
|
|
926
930
|
*
|
|
927
931
|
* @param formData - The current formData, if any, used to figure out a match
|
|
928
932
|
* @param options - The list of options to find a matching options from
|
|
933
|
+
* @param [discriminatorField] - The optional name of the field within the options object whose value is used to
|
|
934
|
+
* determine which option is selected
|
|
929
935
|
* @returns - The firstindex of the matched option or 0 if none is available
|
|
930
936
|
*/
|
|
931
|
-
getFirstMatchingOption(formData: T | undefined, options: S[]): number;
|
|
937
|
+
getFirstMatchingOption(formData: T | undefined, options: S[], discriminatorField?: string): number;
|
|
932
938
|
/** Given the `formData` and list of `options`, attempts to find the index of the option that best matches the data.
|
|
933
939
|
* Deprecated, use `getFirstMatchingOption()` instead.
|
|
934
940
|
*
|
|
935
941
|
* @param formData - The current formData, if any, onto which to provide any missing defaults
|
|
936
942
|
* @param options - The list of options to find a matching options from
|
|
943
|
+
* @param [discriminatorField] - The optional name of the field within the options object whose value is used to
|
|
944
|
+
* determine which option is selected
|
|
937
945
|
* @returns - The index of the matched option or 0 if none is available
|
|
938
946
|
* @deprecated
|
|
939
947
|
*/
|
|
940
|
-
getMatchingOption(formData: T | undefined, options: S[]): number;
|
|
948
|
+
getMatchingOption(formData: T | undefined, options: S[], discriminatorField?: string): number;
|
|
941
949
|
/** Checks to see if the `schema` and `uiSchema` combination represents an array of files
|
|
942
950
|
*
|
|
943
951
|
* @param schema - The schema for which check for array of files flag is desired
|
|
@@ -957,14 +965,16 @@ interface SchemaUtilsType<T = any, S extends StrictRJSFSchema = RJSFSchema, F ex
|
|
|
957
965
|
* @returns - True if schema contains a select, otherwise false
|
|
958
966
|
*/
|
|
959
967
|
isSelect(schema: S): boolean;
|
|
960
|
-
/** Merges the errors in `additionalErrorSchema` into the existing `validationData` by combining the hierarchies in
|
|
961
|
-
* two `ErrorSchema`s and then appending the error list from the `additionalErrorSchema` obtained by calling
|
|
968
|
+
/** Merges the errors in `additionalErrorSchema` into the existing `validationData` by combining the hierarchies in
|
|
969
|
+
* the two `ErrorSchema`s and then appending the error list from the `additionalErrorSchema` obtained by calling
|
|
962
970
|
* `validator.toErrorList()` onto the `errors` in the `validationData`. If no `additionalErrorSchema` is passed, then
|
|
963
971
|
* `validationData` is returned.
|
|
964
972
|
*
|
|
965
973
|
* @param validationData - The current `ValidationData` into which to merge the additional errors
|
|
966
974
|
* @param [additionalErrorSchema] - The additional set of errors
|
|
967
|
-
* @returns - The `validationData` with the additional errors from `additionalErrorSchema` merged into it, if provided
|
|
975
|
+
* @returns - The `validationData` with the additional errors from `additionalErrorSchema` merged into it, if provided
|
|
976
|
+
* @deprecated - Use the `validationDataMerge()` function exported from `@rjsf/utils` instead. This function will be
|
|
977
|
+
* removed in the next major release.
|
|
968
978
|
*/
|
|
969
979
|
mergeValidationData(validationData: ValidationData<T>, additionalErrorSchema?: ErrorSchema<T>): ValidationData<T>;
|
|
970
980
|
/** Retrieves an expanded schema that has had all of its conditions, additional properties, references and
|
|
@@ -1038,6 +1048,13 @@ declare function asNumber(value: string | null): string | number | null | undefi
|
|
|
1038
1048
|
*/
|
|
1039
1049
|
declare function canExpand<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(schema: RJSFSchema, uiSchema?: UiSchema<T, S, F>, formData?: T): boolean;
|
|
1040
1050
|
|
|
1051
|
+
/** Given a `formData` object, recursively creates a `FormValidation` error handling structure around it
|
|
1052
|
+
*
|
|
1053
|
+
* @param formData - The form data around which the error handler is created
|
|
1054
|
+
* @returns - A `FormValidation` object based on the `formData` structure
|
|
1055
|
+
*/
|
|
1056
|
+
declare function createErrorHandler<T = any>(formData: T): FormValidation<T>;
|
|
1057
|
+
|
|
1041
1058
|
/** Creates a `SchemaUtilsType` interface that is based around the given `validator` and `rootSchema` parameters. The
|
|
1042
1059
|
* resulting interface implementation will forward the `validator` and `rootSchema` to all the wrapped APIs.
|
|
1043
1060
|
*
|
|
@@ -1523,6 +1540,42 @@ declare function toConstant<S extends StrictRJSFSchema = RJSFSchema>(schema: S):
|
|
|
1523
1540
|
*/
|
|
1524
1541
|
declare function toDateString(dateObject: DateObject, time?: boolean): string;
|
|
1525
1542
|
|
|
1543
|
+
/** Converts an `errorSchema` into a list of `RJSFValidationErrors`
|
|
1544
|
+
*
|
|
1545
|
+
* @param errorSchema - The `ErrorSchema` instance to convert
|
|
1546
|
+
* @param [fieldPath=[]] - The current field path, defaults to [] if not specified
|
|
1547
|
+
* @returns - The list of `RJSFValidationErrors` extracted from the `errorSchema`
|
|
1548
|
+
*/
|
|
1549
|
+
declare function toErrorList<T = any>(errorSchema?: ErrorSchema<T>, fieldPath?: string[]): RJSFValidationError[];
|
|
1550
|
+
|
|
1551
|
+
/** Transforms a rjsf validation errors list:
|
|
1552
|
+
* [
|
|
1553
|
+
* {property: '.level1.level2[2].level3', message: 'err a'},
|
|
1554
|
+
* {property: '.level1.level2[2].level3', message: 'err b'},
|
|
1555
|
+
* {property: '.level1.level2[4].level3', message: 'err b'},
|
|
1556
|
+
* ]
|
|
1557
|
+
* Into an error tree:
|
|
1558
|
+
* {
|
|
1559
|
+
* level1: {
|
|
1560
|
+
* level2: {
|
|
1561
|
+
* 2: {level3: {errors: ['err a', 'err b']}},
|
|
1562
|
+
* 4: {level3: {errors: ['err b']}},
|
|
1563
|
+
* }
|
|
1564
|
+
* }
|
|
1565
|
+
* };
|
|
1566
|
+
*
|
|
1567
|
+
* @param errors - The list of RJSFValidationError objects
|
|
1568
|
+
* @returns - The `ErrorSchema` built from the list of `RJSFValidationErrors`
|
|
1569
|
+
*/
|
|
1570
|
+
declare function toErrorSchema<T = any>(errors: RJSFValidationError[]): ErrorSchema<T>;
|
|
1571
|
+
|
|
1572
|
+
/** Unwraps the `errorHandler` structure into the associated `ErrorSchema`, stripping the `addError()` functions from it
|
|
1573
|
+
*
|
|
1574
|
+
* @param errorHandler - The `FormValidation` error handling structure
|
|
1575
|
+
* @returns - The `ErrorSchema` resulting from the stripping of the `addError()` function
|
|
1576
|
+
*/
|
|
1577
|
+
declare function unwrapErrorHandler<T = any>(errorHandler: FormValidation<T>): ErrorSchema<T>;
|
|
1578
|
+
|
|
1526
1579
|
/** Converts a UTC date string into a local Date format
|
|
1527
1580
|
*
|
|
1528
1581
|
* @param jsonDate - A UTC date string
|
|
@@ -1530,6 +1583,25 @@ declare function toDateString(dateObject: DateObject, time?: boolean): string;
|
|
|
1530
1583
|
*/
|
|
1531
1584
|
declare function utcToLocal(jsonDate: string): string;
|
|
1532
1585
|
|
|
1586
|
+
/** Merges the errors in `additionalErrorSchema` into the existing `validationData` by combining the hierarchies in the
|
|
1587
|
+
* two `ErrorSchema`s and then appending the error list from the `additionalErrorSchema` obtained by calling
|
|
1588
|
+
* `toErrorList()` on the `errors` in the `validationData`. If no `additionalErrorSchema` is passed, then
|
|
1589
|
+
* `validationData` is returned.
|
|
1590
|
+
*
|
|
1591
|
+
* @param validationData - The current `ValidationData` into which to merge the additional errors
|
|
1592
|
+
* @param [additionalErrorSchema] - The optional additional set of errors in an `ErrorSchema`
|
|
1593
|
+
* @returns - The `validationData` with the additional errors from `additionalErrorSchema` merged into it, if provided.
|
|
1594
|
+
*/
|
|
1595
|
+
declare function validationDataMerge<T = any>(validationData: ValidationData<T>, additionalErrorSchema?: ErrorSchema<T>): ValidationData<T>;
|
|
1596
|
+
|
|
1597
|
+
/** Recursively prefixes all `$ref`s in a schema with the value of the `ROOT_SCHEMA_PREFIX` constant.
|
|
1598
|
+
* This is used in isValid to make references to the rootSchema
|
|
1599
|
+
*
|
|
1600
|
+
* @param schemaNode - The object node to which a ROOT_SCHEMA_PREFIX is added when a REF_KEY is part of it
|
|
1601
|
+
* @returns - A copy of the `schemaNode` with updated `$ref`s
|
|
1602
|
+
*/
|
|
1603
|
+
declare function withIdRefPrefix<S extends StrictRJSFSchema = RJSFSchema>(schemaNode: S): S | S[];
|
|
1604
|
+
|
|
1533
1605
|
/** Below are the list of all the keys into various elements of a RJSFSchema or UiSchema that are used by the various
|
|
1534
1606
|
* utility functions. In addition to those keys, there are the special `ADDITIONAL_PROPERTY_FLAG` and
|
|
1535
1607
|
* `RJSF_ADDITONAL_PROPERTIES_FLAG` flags that is added to a schema under certain conditions by the `retrieveSchema()`
|
|
@@ -1554,6 +1626,7 @@ declare const REQUIRED_KEY = "required";
|
|
|
1554
1626
|
declare const SUBMIT_BTN_OPTIONS_KEY = "submitButtonOptions";
|
|
1555
1627
|
declare const REF_KEY = "$ref";
|
|
1556
1628
|
declare const RJSF_ADDITONAL_PROPERTIES_FLAG = "__rjsf_additionalProperties";
|
|
1629
|
+
declare const ROOT_SCHEMA_PREFIX = "__rjsf_rootSchema";
|
|
1557
1630
|
declare const UI_FIELD_KEY = "ui:field";
|
|
1558
1631
|
declare const UI_WIDGET_KEY = "ui:widget";
|
|
1559
1632
|
declare const UI_OPTIONS_KEY = "ui:options";
|
|
@@ -1603,9 +1676,11 @@ declare function getDisplayLabel<T = any, S extends StrictRJSFSchema = RJSFSchem
|
|
|
1603
1676
|
* @param formData - The form data associated with the schema
|
|
1604
1677
|
* @param options - The list of options that can be selected from
|
|
1605
1678
|
* @param [selectedOption=-1] - The index of the currently selected option, defaulted to -1 if not specified
|
|
1679
|
+
* @param [discriminatorField] - The optional name of the field within the options object whose value is used to
|
|
1680
|
+
* determine which option is selected
|
|
1606
1681
|
* @returns - The index of the option that is the closest match to the `formData` or the `selectedOption` if no match
|
|
1607
1682
|
*/
|
|
1608
|
-
declare 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): number;
|
|
1683
|
+
declare 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;
|
|
1609
1684
|
|
|
1610
1685
|
/** Given the `formData` and list of `options`, attempts to find the index of the first option that matches the data.
|
|
1611
1686
|
* Always returns the first option if there is nothing that matches.
|
|
@@ -1614,9 +1689,11 @@ declare function getClosestMatchingOption<T = any, S extends StrictRJSFSchema =
|
|
|
1614
1689
|
* @param formData - The current formData, if any, used to figure out a match
|
|
1615
1690
|
* @param options - The list of options to find a matching options from
|
|
1616
1691
|
* @param rootSchema - The root schema, used to primarily to look up `$ref`s
|
|
1692
|
+
* @param [discriminatorField] - The optional name of the field within the options object whose value is used to
|
|
1693
|
+
* determine which option is selected
|
|
1617
1694
|
* @returns - The index of the first matched option or 0 if none is available
|
|
1618
1695
|
*/
|
|
1619
|
-
declare function getFirstMatchingOption<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(validator: ValidatorType<T, S, F>, formData: T | undefined, options: S[], rootSchema: S): number;
|
|
1696
|
+
declare 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;
|
|
1620
1697
|
|
|
1621
1698
|
/** Given the `formData` and list of `options`, attempts to find the index of the option that best matches the data.
|
|
1622
1699
|
* Deprecated, use `getFirstMatchingOption()` instead.
|
|
@@ -1625,10 +1702,12 @@ declare function getFirstMatchingOption<T = any, S extends StrictRJSFSchema = RJ
|
|
|
1625
1702
|
* @param formData - The current formData, if any, used to figure out a match
|
|
1626
1703
|
* @param options - The list of options to find a matching options from
|
|
1627
1704
|
* @param rootSchema - The root schema, used to primarily to look up `$ref`s
|
|
1705
|
+
* @param [discriminatorField] - The optional name of the field within the options object whose value is used to
|
|
1706
|
+
* determine which option is selected
|
|
1628
1707
|
* @returns - The index of the matched option or 0 if none is available
|
|
1629
1708
|
* @deprecated
|
|
1630
1709
|
*/
|
|
1631
|
-
declare function getMatchingOption<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(validator: ValidatorType<T, S, F>, formData: T | undefined, options: S[], rootSchema: S): number;
|
|
1710
|
+
declare 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;
|
|
1632
1711
|
|
|
1633
1712
|
/** Checks to see if the `schema` and `uiSchema` combination represents an array of files
|
|
1634
1713
|
*
|
|
@@ -1667,6 +1746,8 @@ declare function isSelect<T = any, S extends StrictRJSFSchema = RJSFSchema, F ex
|
|
|
1667
1746
|
* @param validationData - The current `ValidationData` into which to merge the additional errors
|
|
1668
1747
|
* @param [additionalErrorSchema] - The additional set of errors in an `ErrorSchema`
|
|
1669
1748
|
* @returns - The `validationData` with the additional errors from `additionalErrorSchema` merged into it, if provided.
|
|
1749
|
+
* @deprecated - Use the `validationDataMerge()` function exported from `@rjsf/utils` instead. This function will be
|
|
1750
|
+
* removed in the next major release.
|
|
1670
1751
|
*/
|
|
1671
1752
|
declare function mergeValidationData<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(validator: ValidatorType<T, S, F>, validationData: ValidationData<T>, additionalErrorSchema?: ErrorSchema<T>): ValidationData<T>;
|
|
1672
1753
|
|
|
@@ -1755,4 +1836,4 @@ declare function toIdSchema<T = any, S extends StrictRJSFSchema = RJSFSchema, F
|
|
|
1755
1836
|
*/
|
|
1756
1837
|
declare function toPathSchema<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(validator: ValidatorType<T, S, F>, schema: S, name?: string, rootSchema?: S, formData?: T): PathSchema<T>;
|
|
1757
1838
|
|
|
1758
|
-
export { ADDITIONAL_PROPERTIES_KEY, ADDITIONAL_PROPERTY_FLAG, ALL_OF_KEY, ANY_OF_KEY, ArrayFieldDescriptionProps, ArrayFieldTemplateItemType, ArrayFieldTemplateProps, ArrayFieldTitleProps, BaseInputTemplateProps, CONST_KEY, CustomValidator, DEFAULT_KEY, DEFINITIONS_KEY, DEPENDENCIES_KEY, DateObject, DescriptionFieldProps, ENUM_KEY, ERRORS_KEY, EnumOptionsType, ErrorListProps, ErrorSchema, ErrorSchemaBuilder, ErrorTransformer, Field, FieldError, FieldErrorProps, FieldErrors, FieldHelpProps, FieldId, FieldPath, FieldProps, FieldTemplateProps, FieldValidation, FormContextType, FormValidation, GenericObjectType, GlobalUISchemaOptions, ID_KEY, ITEMS_KEY, IconButtonProps, IdSchema, InputPropsType, NAME_KEY, ONE_OF_KEY, ObjectFieldTemplatePropertyType, ObjectFieldTemplateProps, PROPERTIES_KEY, PathSchema, REF_KEY, REQUIRED_KEY, RJSFSchema, RJSFValidationError, RJSF_ADDITONAL_PROPERTIES_FLAG, RangeSpecType, Registry, RegistryFieldsType, RegistryWidgetsType, SUBMIT_BTN_OPTIONS_KEY, SchemaUtilsType, StrictRJSFSchema, SubmitButtonProps, TemplatesType, TitleFieldProps, TranslatableString, UIOptionsType, UISchemaSubmitButtonOptions, UI_FIELD_KEY, UI_GLOBAL_OPTIONS_KEY, UI_OPTIONS_KEY, UI_WIDGET_KEY, UiSchema, UnsupportedFieldProps, ValidationData, ValidatorType, Widget, WidgetProps, WrapIfAdditionalTemplateProps, allowAdditionalItems, ariaDescribedByIds, asNumber, canExpand, createSchemaUtils, dataURItoBlob, deepEquals, descriptionId, englishStringTranslator, enumOptionsDeselectValue, enumOptionsIndexForValue, enumOptionsIsSelected, enumOptionsSelectValue, enumOptionsValueForIndex, errorId, examplesId, findSchemaDefinition, getClosestMatchingOption, getDefaultFormState, getDisplayLabel, getFirstMatchingOption, getInputProps, getMatchingOption, getSchemaType, getSubmitButtonOptions, getTemplate, getUiOptions, getWidget, guessType, hasWidget, helpId, isConstant, isCustomWidget, isFilesArray, isFixedItems, isMultiSelect, isObject, isSelect, labelValue, localToUTC, mergeDefaultsWithFormData, mergeObjects, mergeSchemas, mergeValidationData, optionId, optionsList, orderProperties, pad, parseDateString, rangeSpec, replaceStringParameters, retrieveSchema, sanitizeDataForNewSchema, schemaRequiresTrueValue, shouldRender, titleId, toConstant, toDateString, toIdSchema, toPathSchema, utcToLocal };
|
|
1839
|
+
export { ADDITIONAL_PROPERTIES_KEY, ADDITIONAL_PROPERTY_FLAG, ALL_OF_KEY, ANY_OF_KEY, ArrayFieldDescriptionProps, ArrayFieldTemplateItemType, ArrayFieldTemplateProps, ArrayFieldTitleProps, BaseInputTemplateProps, CONST_KEY, CustomValidator, DEFAULT_KEY, DEFINITIONS_KEY, DEPENDENCIES_KEY, DateObject, DescriptionFieldProps, ENUM_KEY, ERRORS_KEY, EnumOptionsType, ErrorListProps, ErrorSchema, ErrorSchemaBuilder, ErrorTransformer, Field, FieldError, FieldErrorProps, FieldErrors, FieldHelpProps, FieldId, FieldPath, FieldProps, FieldTemplateProps, FieldValidation, FormContextType, FormValidation, GenericObjectType, GlobalUISchemaOptions, ID_KEY, ITEMS_KEY, IconButtonProps, IdSchema, InputPropsType, NAME_KEY, ONE_OF_KEY, ObjectFieldTemplatePropertyType, ObjectFieldTemplateProps, PROPERTIES_KEY, PathSchema, REF_KEY, REQUIRED_KEY, RJSFSchema, RJSFValidationError, RJSF_ADDITONAL_PROPERTIES_FLAG, ROOT_SCHEMA_PREFIX, RangeSpecType, Registry, RegistryFieldsType, RegistryWidgetsType, SUBMIT_BTN_OPTIONS_KEY, SchemaUtilsType, StrictRJSFSchema, SubmitButtonProps, TemplatesType, TitleFieldProps, TranslatableString, UIOptionsType, UISchemaSubmitButtonOptions, UI_FIELD_KEY, UI_GLOBAL_OPTIONS_KEY, UI_OPTIONS_KEY, UI_WIDGET_KEY, UiSchema, UnsupportedFieldProps, ValidationData, ValidatorType, Widget, WidgetProps, WrapIfAdditionalTemplateProps, allowAdditionalItems, ariaDescribedByIds, asNumber, canExpand, createErrorHandler, createSchemaUtils, dataURItoBlob, deepEquals, descriptionId, englishStringTranslator, enumOptionsDeselectValue, enumOptionsIndexForValue, enumOptionsIsSelected, enumOptionsSelectValue, enumOptionsValueForIndex, errorId, examplesId, findSchemaDefinition, getClosestMatchingOption, getDefaultFormState, getDisplayLabel, getFirstMatchingOption, getInputProps, getMatchingOption, getSchemaType, getSubmitButtonOptions, getTemplate, getUiOptions, getWidget, guessType, hasWidget, helpId, isConstant, isCustomWidget, isFilesArray, isFixedItems, isMultiSelect, isObject, isSelect, labelValue, localToUTC, mergeDefaultsWithFormData, mergeObjects, mergeSchemas, mergeValidationData, optionId, optionsList, orderProperties, pad, parseDateString, rangeSpec, replaceStringParameters, retrieveSchema, sanitizeDataForNewSchema, schemaRequiresTrueValue, shouldRender, titleId, toConstant, toDateString, toErrorList, toErrorSchema, toIdSchema, toPathSchema, unwrapErrorHandler, utcToLocal, validationDataMerge, withIdRefPrefix };
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
+
var isPlainObject = require('lodash/isPlainObject');
|
|
5
6
|
var isEqualWith = require('lodash/isEqualWith');
|
|
6
7
|
var get = require('lodash/get');
|
|
7
8
|
var isEmpty = require('lodash/isEmpty');
|
|
@@ -20,9 +21,11 @@ var cloneDeep = require('lodash/cloneDeep');
|
|
|
20
21
|
var jsxRuntime = require('react/jsx-runtime');
|
|
21
22
|
var react = require('react');
|
|
22
23
|
var ReactIs = require('react-is');
|
|
24
|
+
var toPath = require('lodash/toPath');
|
|
23
25
|
|
|
24
26
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
25
27
|
|
|
28
|
+
var isPlainObject__default = /*#__PURE__*/_interopDefaultLegacy(isPlainObject);
|
|
26
29
|
var isEqualWith__default = /*#__PURE__*/_interopDefaultLegacy(isEqualWith);
|
|
27
30
|
var get__default = /*#__PURE__*/_interopDefaultLegacy(get);
|
|
28
31
|
var isEmpty__default = /*#__PURE__*/_interopDefaultLegacy(isEmpty);
|
|
@@ -39,6 +42,7 @@ var union__default = /*#__PURE__*/_interopDefaultLegacy(union);
|
|
|
39
42
|
var isEqual__default = /*#__PURE__*/_interopDefaultLegacy(isEqual);
|
|
40
43
|
var cloneDeep__default = /*#__PURE__*/_interopDefaultLegacy(cloneDeep);
|
|
41
44
|
var ReactIs__default = /*#__PURE__*/_interopDefaultLegacy(ReactIs);
|
|
45
|
+
var toPath__default = /*#__PURE__*/_interopDefaultLegacy(toPath);
|
|
42
46
|
|
|
43
47
|
/** Determines whether a `thing` is an object for the purposes of RSJF. In this case, `thing` is an object if it has
|
|
44
48
|
* the type `object` but is NOT null, an array or a File.
|
|
@@ -190,6 +194,7 @@ var REQUIRED_KEY = 'required';
|
|
|
190
194
|
var SUBMIT_BTN_OPTIONS_KEY = 'submitButtonOptions';
|
|
191
195
|
var REF_KEY = '$ref';
|
|
192
196
|
var RJSF_ADDITONAL_PROPERTIES_FLAG = '__rjsf_additionalProperties';
|
|
197
|
+
var ROOT_SCHEMA_PREFIX = '__rjsf_rootSchema';
|
|
193
198
|
var UI_FIELD_KEY = 'ui:field';
|
|
194
199
|
var UI_WIDGET_KEY = 'ui:widget';
|
|
195
200
|
var UI_OPTIONS_KEY = 'ui:options';
|
|
@@ -255,6 +260,32 @@ function canExpand(schema, uiSchema, formData) {
|
|
|
255
260
|
return true;
|
|
256
261
|
}
|
|
257
262
|
|
|
263
|
+
/** Given a `formData` object, recursively creates a `FormValidation` error handling structure around it
|
|
264
|
+
*
|
|
265
|
+
* @param formData - The form data around which the error handler is created
|
|
266
|
+
* @returns - A `FormValidation` object based on the `formData` structure
|
|
267
|
+
*/
|
|
268
|
+
function createErrorHandler(formData) {
|
|
269
|
+
var _handler;
|
|
270
|
+
var handler = (_handler = {}, _handler[ERRORS_KEY] = [], _handler.addError = function addError(message) {
|
|
271
|
+
this[ERRORS_KEY].push(message);
|
|
272
|
+
}, _handler);
|
|
273
|
+
if (Array.isArray(formData)) {
|
|
274
|
+
return formData.reduce(function (acc, value, key) {
|
|
275
|
+
var _extends2;
|
|
276
|
+
return _extends({}, acc, (_extends2 = {}, _extends2[key] = createErrorHandler(value), _extends2));
|
|
277
|
+
}, handler);
|
|
278
|
+
}
|
|
279
|
+
if (isPlainObject__default["default"](formData)) {
|
|
280
|
+
var formObject = formData;
|
|
281
|
+
return Object.keys(formObject).reduce(function (acc, key) {
|
|
282
|
+
var _extends3;
|
|
283
|
+
return _extends({}, acc, (_extends3 = {}, _extends3[key] = createErrorHandler(formObject[key]), _extends3));
|
|
284
|
+
}, handler);
|
|
285
|
+
}
|
|
286
|
+
return handler;
|
|
287
|
+
}
|
|
288
|
+
|
|
258
289
|
/** Implements a deep equals using the `lodash.isEqualWith` function, that provides a customized comparator that
|
|
259
290
|
* assumes all functions are equivalent.
|
|
260
291
|
*
|
|
@@ -330,10 +361,12 @@ function findSchemaDefinition($ref, rootSchema) {
|
|
|
330
361
|
* @param formData - The current formData, if any, used to figure out a match
|
|
331
362
|
* @param options - The list of options to find a matching options from
|
|
332
363
|
* @param rootSchema - The root schema, used to primarily to look up `$ref`s
|
|
364
|
+
* @param [discriminatorField] - The optional name of the field within the options object whose value is used to
|
|
365
|
+
* determine which option is selected
|
|
333
366
|
* @returns - The index of the matched option or 0 if none is available
|
|
334
367
|
* @deprecated
|
|
335
368
|
*/
|
|
336
|
-
function getMatchingOption(validator, formData, options, rootSchema) {
|
|
369
|
+
function getMatchingOption(validator, formData, options, rootSchema, discriminatorField) {
|
|
337
370
|
// For performance, skip validating subschemas if formData is undefined. We just
|
|
338
371
|
// want to get the first option in that case.
|
|
339
372
|
if (formData === undefined) {
|
|
@@ -341,18 +374,26 @@ function getMatchingOption(validator, formData, options, rootSchema) {
|
|
|
341
374
|
}
|
|
342
375
|
for (var i = 0; i < options.length; i++) {
|
|
343
376
|
var option = options[i];
|
|
344
|
-
// If
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
if (option
|
|
377
|
+
// If we have a discriminator field, then we will use this to make the determination
|
|
378
|
+
if (discriminatorField && has__default["default"](option, [PROPERTIES_KEY, discriminatorField])) {
|
|
379
|
+
var value = get__default["default"](formData, discriminatorField);
|
|
380
|
+
var discriminator = get__default["default"](option, [PROPERTIES_KEY, discriminatorField], {});
|
|
381
|
+
if (validator.isValid(discriminator, value, rootSchema)) {
|
|
382
|
+
return i;
|
|
383
|
+
}
|
|
384
|
+
} else if (option[PROPERTIES_KEY]) {
|
|
385
|
+
// If the schema describes an object then we need to add slightly more
|
|
386
|
+
// strict matching to the schema, because unless the schema uses the
|
|
387
|
+
// "requires" keyword, an object will match the schema as long as it
|
|
388
|
+
// doesn't have matching keys with a conflicting type. To do this we use an
|
|
389
|
+
// "anyOf" with an array of requires. This augmentation expresses that the
|
|
390
|
+
// schema should match if any of the keys in the schema are present on the
|
|
391
|
+
// object and pass validation.
|
|
392
|
+
//
|
|
352
393
|
// Create an "anyOf" schema that requires at least one of the keys in the
|
|
353
394
|
// "properties" object
|
|
354
395
|
var requiresAnyOf = {
|
|
355
|
-
anyOf: Object.keys(option
|
|
396
|
+
anyOf: Object.keys(option[PROPERTIES_KEY]).map(function (key) {
|
|
356
397
|
return {
|
|
357
398
|
required: [key]
|
|
358
399
|
};
|
|
@@ -394,10 +435,12 @@ function getMatchingOption(validator, formData, options, rootSchema) {
|
|
|
394
435
|
* @param formData - The current formData, if any, used to figure out a match
|
|
395
436
|
* @param options - The list of options to find a matching options from
|
|
396
437
|
* @param rootSchema - The root schema, used to primarily to look up `$ref`s
|
|
438
|
+
* @param [discriminatorField] - The optional name of the field within the options object whose value is used to
|
|
439
|
+
* determine which option is selected
|
|
397
440
|
* @returns - The index of the first matched option or 0 if none is available
|
|
398
441
|
*/
|
|
399
|
-
function getFirstMatchingOption(validator, formData, options, rootSchema) {
|
|
400
|
-
return getMatchingOption(validator, formData, options, rootSchema);
|
|
442
|
+
function getFirstMatchingOption(validator, formData, options, rootSchema, discriminatorField) {
|
|
443
|
+
return getMatchingOption(validator, formData, options, rootSchema, discriminatorField);
|
|
401
444
|
}
|
|
402
445
|
|
|
403
446
|
/** Given a specific `value` attempts to guess the type of a schema element. In the case where we have to implicitly
|
|
@@ -873,16 +916,18 @@ function calculateIndexScore(validator, rootSchema, schema, formData) {
|
|
|
873
916
|
* @param formData - The form data associated with the schema
|
|
874
917
|
* @param options - The list of options that can be selected from
|
|
875
918
|
* @param [selectedOption=-1] - The index of the currently selected option, defaulted to -1 if not specified
|
|
919
|
+
* @param [discriminatorField] - The optional name of the field within the options object whose value is used to
|
|
920
|
+
* determine which option is selected
|
|
876
921
|
* @returns - The index of the option that is the closest match to the `formData` or the `selectedOption` if no match
|
|
877
922
|
*/
|
|
878
|
-
function getClosestMatchingOption(validator, rootSchema, formData, options, selectedOption) {
|
|
923
|
+
function getClosestMatchingOption(validator, rootSchema, formData, options, selectedOption, discriminatorField) {
|
|
879
924
|
if (selectedOption === void 0) {
|
|
880
925
|
selectedOption = -1;
|
|
881
926
|
}
|
|
882
927
|
// Reduce the array of options down to a list of the indexes that are considered matching options
|
|
883
928
|
var allValidIndexes = options.reduce(function (validList, option, index) {
|
|
884
929
|
var testOptions = [JUNK_OPTION, option];
|
|
885
|
-
var match = getFirstMatchingOption(validator, formData, testOptions, rootSchema);
|
|
930
|
+
var match = getFirstMatchingOption(validator, formData, testOptions, rootSchema, discriminatorField);
|
|
886
931
|
// The match is the real option, so add its index to list of valid indexes
|
|
887
932
|
if (match === 1) {
|
|
888
933
|
validList.push(index);
|
|
@@ -1376,6 +1421,8 @@ function getDisplayLabel(validator, schema, uiSchema, rootSchema, globalOptions)
|
|
|
1376
1421
|
* @param validationData - The current `ValidationData` into which to merge the additional errors
|
|
1377
1422
|
* @param [additionalErrorSchema] - The additional set of errors in an `ErrorSchema`
|
|
1378
1423
|
* @returns - The `validationData` with the additional errors from `additionalErrorSchema` merged into it, if provided.
|
|
1424
|
+
* @deprecated - Use the `validationDataMerge()` function exported from `@rjsf/utils` instead. This function will be
|
|
1425
|
+
* removed in the next major release.
|
|
1379
1426
|
*/
|
|
1380
1427
|
function mergeValidationData(validator, validationData, additionalErrorSchema) {
|
|
1381
1428
|
if (!additionalErrorSchema) {
|
|
@@ -1591,7 +1638,7 @@ function toIdSchemaInternal(validator, schema, idPrefix, idSeparator, id, rootSc
|
|
|
1591
1638
|
var idSchema = {
|
|
1592
1639
|
$id: $id
|
|
1593
1640
|
};
|
|
1594
|
-
if (schema
|
|
1641
|
+
if (getSchemaType(schema) === 'object' && PROPERTIES_KEY in schema) {
|
|
1595
1642
|
for (var name in schema.properties) {
|
|
1596
1643
|
var field = get__default["default"](schema, [PROPERTIES_KEY, name]);
|
|
1597
1644
|
var fieldId = idSchema[ID_KEY] + idSeparator + name;
|
|
@@ -1769,31 +1816,37 @@ var SchemaUtils = /*#__PURE__*/function () {
|
|
|
1769
1816
|
* @param formData - The form data associated with the schema
|
|
1770
1817
|
* @param options - The list of options that can be selected from
|
|
1771
1818
|
* @param [selectedOption] - The index of the currently selected option, defaulted to -1 if not specified
|
|
1819
|
+
* @param [discriminatorField] - The optional name of the field within the options object whose value is used to
|
|
1820
|
+
* determine which option is selected
|
|
1772
1821
|
* @returns - The index of the option that is the closest match to the `formData` or the `selectedOption` if no match
|
|
1773
1822
|
*/;
|
|
1774
|
-
_proto.getClosestMatchingOption = function getClosestMatchingOption$1(formData, options, selectedOption) {
|
|
1775
|
-
return getClosestMatchingOption(this.validator, this.rootSchema, formData, options, selectedOption);
|
|
1823
|
+
_proto.getClosestMatchingOption = function getClosestMatchingOption$1(formData, options, selectedOption, discriminatorField) {
|
|
1824
|
+
return getClosestMatchingOption(this.validator, this.rootSchema, formData, options, selectedOption, discriminatorField);
|
|
1776
1825
|
}
|
|
1777
1826
|
/** Given the `formData` and list of `options`, attempts to find the index of the first option that matches the data.
|
|
1778
1827
|
* Always returns the first option if there is nothing that matches.
|
|
1779
1828
|
*
|
|
1780
1829
|
* @param formData - The current formData, if any, used to figure out a match
|
|
1781
1830
|
* @param options - The list of options to find a matching options from
|
|
1831
|
+
* @param [discriminatorField] - The optional name of the field within the options object whose value is used to
|
|
1832
|
+
* determine which option is selected
|
|
1782
1833
|
* @returns - The firstindex of the matched option or 0 if none is available
|
|
1783
1834
|
*/;
|
|
1784
|
-
_proto.getFirstMatchingOption = function getFirstMatchingOption$1(formData, options) {
|
|
1785
|
-
return getFirstMatchingOption(this.validator, formData, options, this.rootSchema);
|
|
1835
|
+
_proto.getFirstMatchingOption = function getFirstMatchingOption$1(formData, options, discriminatorField) {
|
|
1836
|
+
return getFirstMatchingOption(this.validator, formData, options, this.rootSchema, discriminatorField);
|
|
1786
1837
|
}
|
|
1787
1838
|
/** Given the `formData` and list of `options`, attempts to find the index of the option that best matches the data.
|
|
1788
1839
|
* Deprecated, use `getFirstMatchingOption()` instead.
|
|
1789
1840
|
*
|
|
1790
1841
|
* @param formData - The current formData, if any, onto which to provide any missing defaults
|
|
1791
1842
|
* @param options - The list of options to find a matching options from
|
|
1843
|
+
* @param [discriminatorField] - The optional name of the field within the options object whose value is used to
|
|
1844
|
+
* determine which option is selected
|
|
1792
1845
|
* @returns - The index of the matched option or 0 if none is available
|
|
1793
1846
|
* @deprecated
|
|
1794
1847
|
*/;
|
|
1795
|
-
_proto.getMatchingOption = function getMatchingOption$1(formData, options) {
|
|
1796
|
-
return getMatchingOption(this.validator, formData, options, this.rootSchema);
|
|
1848
|
+
_proto.getMatchingOption = function getMatchingOption$1(formData, options, discriminatorField) {
|
|
1849
|
+
return getMatchingOption(this.validator, formData, options, this.rootSchema, discriminatorField);
|
|
1797
1850
|
}
|
|
1798
1851
|
/** Checks to see if the `schema` and `uiSchema` combination represents an array of files
|
|
1799
1852
|
*
|
|
@@ -1828,6 +1881,8 @@ var SchemaUtils = /*#__PURE__*/function () {
|
|
|
1828
1881
|
* @param validationData - The current `ValidationData` into which to merge the additional errors
|
|
1829
1882
|
* @param [additionalErrorSchema] - The additional set of errors
|
|
1830
1883
|
* @returns - The `validationData` with the additional errors from `additionalErrorSchema` merged into it, if provided.
|
|
1884
|
+
* @deprecated - Use the `validationDataMerge()` function exported from `@rjsf/utils` instead. This function will be
|
|
1885
|
+
* removed in the next major release.
|
|
1831
1886
|
*/;
|
|
1832
1887
|
_proto.mergeValidationData = function mergeValidationData$1(validationData, additionalErrorSchema) {
|
|
1833
1888
|
return mergeValidationData(this.validator, validationData, additionalErrorSchema);
|
|
@@ -2785,6 +2840,102 @@ function toDateString(dateObject, time) {
|
|
|
2785
2840
|
return time ? datetime : datetime.slice(0, 10);
|
|
2786
2841
|
}
|
|
2787
2842
|
|
|
2843
|
+
/** Converts an `errorSchema` into a list of `RJSFValidationErrors`
|
|
2844
|
+
*
|
|
2845
|
+
* @param errorSchema - The `ErrorSchema` instance to convert
|
|
2846
|
+
* @param [fieldPath=[]] - The current field path, defaults to [] if not specified
|
|
2847
|
+
* @returns - The list of `RJSFValidationErrors` extracted from the `errorSchema`
|
|
2848
|
+
*/
|
|
2849
|
+
function toErrorList(errorSchema, fieldPath) {
|
|
2850
|
+
if (fieldPath === void 0) {
|
|
2851
|
+
fieldPath = [];
|
|
2852
|
+
}
|
|
2853
|
+
if (!errorSchema) {
|
|
2854
|
+
return [];
|
|
2855
|
+
}
|
|
2856
|
+
var errorList = [];
|
|
2857
|
+
if (ERRORS_KEY in errorSchema) {
|
|
2858
|
+
errorList = errorList.concat(errorSchema[ERRORS_KEY].map(function (message) {
|
|
2859
|
+
var property = "." + fieldPath.join('.');
|
|
2860
|
+
return {
|
|
2861
|
+
property: property,
|
|
2862
|
+
message: message,
|
|
2863
|
+
stack: property + " " + message
|
|
2864
|
+
};
|
|
2865
|
+
}));
|
|
2866
|
+
}
|
|
2867
|
+
return Object.keys(errorSchema).reduce(function (acc, key) {
|
|
2868
|
+
if (key !== ERRORS_KEY) {
|
|
2869
|
+
var childSchema = errorSchema[key];
|
|
2870
|
+
if (isPlainObject__default["default"](childSchema)) {
|
|
2871
|
+
acc = acc.concat(toErrorList(childSchema, [].concat(fieldPath, [key])));
|
|
2872
|
+
}
|
|
2873
|
+
}
|
|
2874
|
+
return acc;
|
|
2875
|
+
}, errorList);
|
|
2876
|
+
}
|
|
2877
|
+
|
|
2878
|
+
/** Transforms a rjsf validation errors list:
|
|
2879
|
+
* [
|
|
2880
|
+
* {property: '.level1.level2[2].level3', message: 'err a'},
|
|
2881
|
+
* {property: '.level1.level2[2].level3', message: 'err b'},
|
|
2882
|
+
* {property: '.level1.level2[4].level3', message: 'err b'},
|
|
2883
|
+
* ]
|
|
2884
|
+
* Into an error tree:
|
|
2885
|
+
* {
|
|
2886
|
+
* level1: {
|
|
2887
|
+
* level2: {
|
|
2888
|
+
* 2: {level3: {errors: ['err a', 'err b']}},
|
|
2889
|
+
* 4: {level3: {errors: ['err b']}},
|
|
2890
|
+
* }
|
|
2891
|
+
* }
|
|
2892
|
+
* };
|
|
2893
|
+
*
|
|
2894
|
+
* @param errors - The list of RJSFValidationError objects
|
|
2895
|
+
* @returns - The `ErrorSchema` built from the list of `RJSFValidationErrors`
|
|
2896
|
+
*/
|
|
2897
|
+
function toErrorSchema(errors) {
|
|
2898
|
+
var builder = new ErrorSchemaBuilder();
|
|
2899
|
+
if (errors.length) {
|
|
2900
|
+
errors.forEach(function (error) {
|
|
2901
|
+
var property = error.property,
|
|
2902
|
+
message = error.message;
|
|
2903
|
+
// When the property is the root element, just use an empty array for the path
|
|
2904
|
+
var path = property === '.' ? [] : toPath__default["default"](property);
|
|
2905
|
+
// If the property is at the root (.level1) then toPath creates
|
|
2906
|
+
// an empty array element at the first index. Remove it.
|
|
2907
|
+
if (path.length > 0 && path[0] === '') {
|
|
2908
|
+
path.splice(0, 1);
|
|
2909
|
+
}
|
|
2910
|
+
if (message) {
|
|
2911
|
+
builder.addErrors(message, path);
|
|
2912
|
+
}
|
|
2913
|
+
});
|
|
2914
|
+
}
|
|
2915
|
+
return builder.ErrorSchema;
|
|
2916
|
+
}
|
|
2917
|
+
|
|
2918
|
+
/** Unwraps the `errorHandler` structure into the associated `ErrorSchema`, stripping the `addError()` functions from it
|
|
2919
|
+
*
|
|
2920
|
+
* @param errorHandler - The `FormValidation` error handling structure
|
|
2921
|
+
* @returns - The `ErrorSchema` resulting from the stripping of the `addError()` function
|
|
2922
|
+
*/
|
|
2923
|
+
function unwrapErrorHandler(errorHandler) {
|
|
2924
|
+
return Object.keys(errorHandler).reduce(function (acc, key) {
|
|
2925
|
+
if (key === 'addError') {
|
|
2926
|
+
return acc;
|
|
2927
|
+
} else {
|
|
2928
|
+
var _extends3;
|
|
2929
|
+
var childSchema = errorHandler[key];
|
|
2930
|
+
if (isPlainObject__default["default"](childSchema)) {
|
|
2931
|
+
var _extends2;
|
|
2932
|
+
return _extends({}, acc, (_extends2 = {}, _extends2[key] = unwrapErrorHandler(childSchema), _extends2));
|
|
2933
|
+
}
|
|
2934
|
+
return _extends({}, acc, (_extends3 = {}, _extends3[key] = childSchema, _extends3));
|
|
2935
|
+
}
|
|
2936
|
+
}, {});
|
|
2937
|
+
}
|
|
2938
|
+
|
|
2788
2939
|
/** Converts a UTC date string into a local Date format
|
|
2789
2940
|
*
|
|
2790
2941
|
* @param jsonDate - A UTC date string
|
|
@@ -2810,6 +2961,77 @@ function utcToLocal(jsonDate) {
|
|
|
2810
2961
|
return yyyy + "-" + MM + "-" + dd + "T" + hh + ":" + mm + ":" + ss + "." + SSS;
|
|
2811
2962
|
}
|
|
2812
2963
|
|
|
2964
|
+
/** Merges the errors in `additionalErrorSchema` into the existing `validationData` by combining the hierarchies in the
|
|
2965
|
+
* two `ErrorSchema`s and then appending the error list from the `additionalErrorSchema` obtained by calling
|
|
2966
|
+
* `toErrorList()` on the `errors` in the `validationData`. If no `additionalErrorSchema` is passed, then
|
|
2967
|
+
* `validationData` is returned.
|
|
2968
|
+
*
|
|
2969
|
+
* @param validationData - The current `ValidationData` into which to merge the additional errors
|
|
2970
|
+
* @param [additionalErrorSchema] - The optional additional set of errors in an `ErrorSchema`
|
|
2971
|
+
* @returns - The `validationData` with the additional errors from `additionalErrorSchema` merged into it, if provided.
|
|
2972
|
+
*/
|
|
2973
|
+
function validationDataMerge(validationData, additionalErrorSchema) {
|
|
2974
|
+
if (!additionalErrorSchema) {
|
|
2975
|
+
return validationData;
|
|
2976
|
+
}
|
|
2977
|
+
var oldErrors = validationData.errors,
|
|
2978
|
+
oldErrorSchema = validationData.errorSchema;
|
|
2979
|
+
var errors = toErrorList(additionalErrorSchema);
|
|
2980
|
+
var errorSchema = additionalErrorSchema;
|
|
2981
|
+
if (!isEmpty__default["default"](oldErrorSchema)) {
|
|
2982
|
+
errorSchema = mergeObjects(oldErrorSchema, additionalErrorSchema, true);
|
|
2983
|
+
errors = [].concat(oldErrors).concat(errors);
|
|
2984
|
+
}
|
|
2985
|
+
return {
|
|
2986
|
+
errorSchema: errorSchema,
|
|
2987
|
+
errors: errors
|
|
2988
|
+
};
|
|
2989
|
+
}
|
|
2990
|
+
|
|
2991
|
+
/** Takes a `node` object and transforms any contained `$ref` node variables with a prefix, recursively calling
|
|
2992
|
+
* `withIdRefPrefix` for any other elements.
|
|
2993
|
+
*
|
|
2994
|
+
* @param node - The object node to which a ROOT_SCHEMA_PREFIX is added when a REF_KEY is part of it
|
|
2995
|
+
*/
|
|
2996
|
+
function withIdRefPrefixObject(node) {
|
|
2997
|
+
for (var key in node) {
|
|
2998
|
+
var realObj = node;
|
|
2999
|
+
var value = realObj[key];
|
|
3000
|
+
if (key === REF_KEY && typeof value === 'string' && value.startsWith('#')) {
|
|
3001
|
+
realObj[key] = ROOT_SCHEMA_PREFIX + value;
|
|
3002
|
+
} else {
|
|
3003
|
+
realObj[key] = withIdRefPrefix(value);
|
|
3004
|
+
}
|
|
3005
|
+
}
|
|
3006
|
+
return node;
|
|
3007
|
+
}
|
|
3008
|
+
/** Takes a `node` object list and transforms any contained `$ref` node variables with a prefix, recursively calling
|
|
3009
|
+
* `withIdRefPrefix` for any other elements.
|
|
3010
|
+
*
|
|
3011
|
+
* @param node - The list of object nodes to which a ROOT_SCHEMA_PREFIX is added when a REF_KEY is part of it
|
|
3012
|
+
*/
|
|
3013
|
+
function withIdRefPrefixArray(node) {
|
|
3014
|
+
for (var i = 0; i < node.length; i++) {
|
|
3015
|
+
node[i] = withIdRefPrefix(node[i]);
|
|
3016
|
+
}
|
|
3017
|
+
return node;
|
|
3018
|
+
}
|
|
3019
|
+
/** Recursively prefixes all `$ref`s in a schema with the value of the `ROOT_SCHEMA_PREFIX` constant.
|
|
3020
|
+
* This is used in isValid to make references to the rootSchema
|
|
3021
|
+
*
|
|
3022
|
+
* @param schemaNode - The object node to which a ROOT_SCHEMA_PREFIX is added when a REF_KEY is part of it
|
|
3023
|
+
* @returns - A copy of the `schemaNode` with updated `$ref`s
|
|
3024
|
+
*/
|
|
3025
|
+
function withIdRefPrefix(schemaNode) {
|
|
3026
|
+
if (schemaNode.constructor === Object) {
|
|
3027
|
+
return withIdRefPrefixObject(_extends({}, schemaNode));
|
|
3028
|
+
}
|
|
3029
|
+
if (Array.isArray(schemaNode)) {
|
|
3030
|
+
return withIdRefPrefixArray([].concat(schemaNode));
|
|
3031
|
+
}
|
|
3032
|
+
return schemaNode;
|
|
3033
|
+
}
|
|
3034
|
+
|
|
2813
3035
|
/** An enumeration of all the translatable strings used by `@rjsf/core` and its themes. The value of each of the
|
|
2814
3036
|
* enumeration keys is expected to be the actual english string. Some strings contain replaceable parameter values
|
|
2815
3037
|
* as indicated by `%1`, `%2`, etc. The number after the `%` indicates the order of the parameter. The ordering of
|
|
@@ -2905,6 +3127,7 @@ exports.PROPERTIES_KEY = PROPERTIES_KEY;
|
|
|
2905
3127
|
exports.REF_KEY = REF_KEY;
|
|
2906
3128
|
exports.REQUIRED_KEY = REQUIRED_KEY;
|
|
2907
3129
|
exports.RJSF_ADDITONAL_PROPERTIES_FLAG = RJSF_ADDITONAL_PROPERTIES_FLAG;
|
|
3130
|
+
exports.ROOT_SCHEMA_PREFIX = ROOT_SCHEMA_PREFIX;
|
|
2908
3131
|
exports.SUBMIT_BTN_OPTIONS_KEY = SUBMIT_BTN_OPTIONS_KEY;
|
|
2909
3132
|
exports.UI_FIELD_KEY = UI_FIELD_KEY;
|
|
2910
3133
|
exports.UI_GLOBAL_OPTIONS_KEY = UI_GLOBAL_OPTIONS_KEY;
|
|
@@ -2914,6 +3137,7 @@ exports.allowAdditionalItems = allowAdditionalItems;
|
|
|
2914
3137
|
exports.ariaDescribedByIds = ariaDescribedByIds;
|
|
2915
3138
|
exports.asNumber = asNumber;
|
|
2916
3139
|
exports.canExpand = canExpand;
|
|
3140
|
+
exports.createErrorHandler = createErrorHandler;
|
|
2917
3141
|
exports.createSchemaUtils = createSchemaUtils;
|
|
2918
3142
|
exports.dataURItoBlob = dataURItoBlob;
|
|
2919
3143
|
exports.deepEquals = deepEquals;
|
|
@@ -2968,7 +3192,12 @@ exports.shouldRender = shouldRender;
|
|
|
2968
3192
|
exports.titleId = titleId;
|
|
2969
3193
|
exports.toConstant = toConstant;
|
|
2970
3194
|
exports.toDateString = toDateString;
|
|
3195
|
+
exports.toErrorList = toErrorList;
|
|
3196
|
+
exports.toErrorSchema = toErrorSchema;
|
|
2971
3197
|
exports.toIdSchema = toIdSchema;
|
|
2972
3198
|
exports.toPathSchema = toPathSchema;
|
|
3199
|
+
exports.unwrapErrorHandler = unwrapErrorHandler;
|
|
2973
3200
|
exports.utcToLocal = utcToLocal;
|
|
3201
|
+
exports.validationDataMerge = validationDataMerge;
|
|
3202
|
+
exports.withIdRefPrefix = withIdRefPrefix;
|
|
2974
3203
|
//# sourceMappingURL=utils.cjs.development.js.map
|