@rjsf/utils 5.0.0-beta.5 → 5.0.0-beta.8

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/README.md CHANGED
@@ -8,13 +8,13 @@
8
8
  <br />
9
9
  <p align="center">
10
10
  <a href="https://github.com/rjsf-team/react-jsonschema-form">
11
- <img src="https://raw.githubusercontent.com/rjsf-team/react-jsonschema-form/59a8206e148474bea854bbb004f624143fbcbac8/packages/utils/logo.png" alt="Logo" width="120" height="120">
11
+ <img src="https://raw.githubusercontent.com/rjsf-team/react-jsonschema-form/7ebc86621d8df8c21f0c39bcca6d476f6f7a2051/packages/utils/logo.png" alt="Logo" width="120" height="120">
12
12
  </a>
13
13
 
14
14
  <h3 align="center">@rjsf/utils</h3>
15
15
 
16
16
  <p align="center">
17
- AJV-6 based validator plugin for <a href="https://github.com/rjsf-team/react-jsonschema-form/"><code>react-jsonschema-form</code></a>.
17
+ Utility functions for <a href="https://github.com/rjsf-team/react-jsonschema-form/"><code>react-jsonschema-form</code></a>.
18
18
  <br />
19
19
  <a href="https://react-jsonschema-form.readthedocs.io/en/stable/"><strong>Explore the docs »</strong></a>
20
20
  <br />
@@ -46,12 +46,11 @@
46
46
 
47
47
  ## About The Project
48
48
 
49
- Exports `utils` plugin for `react-jsonschema-form`.
49
+ Exports `utils` functions for `react-jsonschema-form`.
50
50
 
51
51
  ### Built With
52
52
 
53
53
  - [react-jsonschema-form](https://github.com/rjsf-team/react-jsonschema-form/)
54
- - [AJV](https://github.com/ajv-validator/ajv/)
55
54
  - [TypeScript](https://www.typescriptlang.org/)
56
55
 
57
56
  <!-- GETTING STARTED -->
@@ -72,6 +71,10 @@ yarn add @rjsf/utils
72
71
  import * as Utils from '@rjsf/utils';
73
72
  ```
74
73
 
74
+ ## Documentation
75
+
76
+ [Utility function documentation](https://react-jsonschema-form.readthedocs.io/en/stable/api-reference/utility-functions/)
77
+
75
78
  <!-- ROADMAP -->
76
79
 
77
80
  ## Roadmap
@@ -101,8 +104,7 @@ GitHub repository: [https://github.com/rjsf-team/react-jsonschema-form](https://
101
104
  [contributors-url]: https://github.com/rjsf-team/react-jsonschema-form/graphs/contributors
102
105
  [license-shield]: https://img.shields.io/badge/license-Apache%202.0-blue.svg?style=flat-square
103
106
  [license-url]: https://choosealicense.com/licenses/apache-2.0/
104
- [npm-shield]: https://img.shields.io/npm/v/@rjsf/material-ui/latest.svg?style=flat-square
105
- [npm-url]: https://www.npmjs.com/package/@rjsf/material-ui
106
- [npm-dl-shield]: https://img.shields.io/npm/dm/@rjsf/material-ui.svg?style=flat-square
107
- [npm-dl-url]: https://www.npmjs.com/package/@rjsf/material-ui
108
- [product-screenshot]: https://raw.githubusercontent.com/rjsf-team/react-jsonschema-form/e2e1181d1020f18cad0c80c661ddae28edb9794e/packages/material-ui/screenshot5.png
107
+ [npm-shield]: https://img.shields.io/npm/v/@rjsf/utils/latest.svg?style=flat-square
108
+ [npm-url]: https://www.npmjs.com/package/@rjsf/utils
109
+ [npm-dl-shield]: https://img.shields.io/npm/dm/@rjsf/utils.svg?style=flat-square
110
+ [npm-dl-url]: https://www.npmjs.com/package/@rjsf/utils
package/dist/index.d.ts CHANGED
@@ -109,7 +109,7 @@ declare type FieldValidation = FieldErrors & {
109
109
  declare type FormValidation<T = any> = FieldValidation & {
110
110
  [key in keyof T]?: FormValidation<T[key]>;
111
111
  };
112
- /** The properties that are passed to an `ErrorList` implementation */
112
+ /** The properties that are passed to an `ErrorListTemplate` implementation */
113
113
  declare type ErrorListProps<T = any, F = any> = {
114
114
  /** The errorSchema constructed by `Form` */
115
115
  errorSchema: ErrorSchema<T>;
@@ -122,6 +122,36 @@ declare type ErrorListProps<T = any, F = any> = {
122
122
  /** The uiSchema that was passed to `Form` */
123
123
  uiSchema?: UiSchema<T, F>;
124
124
  };
125
+ /** The properties that are passed to an `FieldErrorTemplate` implementation */
126
+ declare type FieldErrorProps<T = any, F = any> = {
127
+ /** The errorSchema constructed by `Form` */
128
+ errorSchema?: ErrorSchema<T>;
129
+ /** An array of the errors */
130
+ errors?: string[];
131
+ /** The tree of unique ids for every child field */
132
+ idSchema: IdSchema<T>;
133
+ /** The schema that was passed to field */
134
+ schema: RJSFSchema;
135
+ /** The uiSchema that was passed to field */
136
+ uiSchema?: UiSchema<T, F>;
137
+ /** The `registry` object */
138
+ registry: Registry<T, F>;
139
+ };
140
+ /** The properties that are passed to an `FieldHelpTemplate` implementation */
141
+ declare type FieldHelpProps<T = any, F = any> = {
142
+ /** The help information to be rendered */
143
+ help?: string | React.ReactElement;
144
+ /** The tree of unique ids for every child field */
145
+ idSchema: IdSchema<T>;
146
+ /** The schema that was passed to field */
147
+ schema: RJSFSchema;
148
+ /** The uiSchema that was passed to field */
149
+ uiSchema?: UiSchema<T, F>;
150
+ /** Flag indicating whether there are errors associated with this field */
151
+ hasErrors?: boolean;
152
+ /** The `registry` object */
153
+ registry: Registry<T, F>;
154
+ };
125
155
  /** The set of `Fields` stored in the `Registry` */
126
156
  declare type RegistryFieldsType<T = any, F = any> = {
127
157
  /** A `Field` indexed by `name` */
@@ -146,8 +176,12 @@ interface TemplatesType<T = any, F = any> {
146
176
  BaseInputTemplate: React.ComponentType<WidgetProps<T, F>>;
147
177
  /** The template to use for rendering the description of a field */
148
178
  DescriptionFieldTemplate: React.ComponentType<DescriptionFieldProps<T, F>>;
149
- /** The template to use while rendering form errors */
179
+ /** The template to use while rendering the errors for the whole form */
150
180
  ErrorListTemplate: React.ComponentType<ErrorListProps<T, F>>;
181
+ /** The template to use while rendering the errors for a single field */
182
+ FieldErrorTemplate: React.ComponentType<FieldErrorProps<T, F>>;
183
+ /** The template to use while rendering the errors for a single field */
184
+ FieldHelpTemplate: React.ComponentType<FieldHelpProps<T, F>>;
151
185
  /** The template to use while rendering a field */
152
186
  FieldTemplate: React.ComponentType<FieldTemplateProps<T, F>>;
153
187
  /** The template to use while rendering an object */
@@ -1218,4 +1252,4 @@ declare function toIdSchema<T = any>(validator: ValidatorType, schema: RJSFSchem
1218
1252
  */
1219
1253
  declare function toPathSchema<T = any>(validator: ValidatorType, schema: RJSFSchema, name?: string, rootSchema?: RJSFSchema, formData?: T): PathSchema<T>;
1220
1254
 
1221
- export { ADDITIONAL_PROPERTIES_KEY, ADDITIONAL_PROPERTY_FLAG, ALL_OF_KEY, ANY_OF_KEY, ArrayFieldDescriptionProps, ArrayFieldTemplateItemType, ArrayFieldTemplateProps, ArrayFieldTitleProps, CONST_KEY, CustomValidator, DEFAULT_KEY, DEFINITIONS_KEY, DEPENDENCIES_KEY, DateObject, DescriptionFieldProps, ENUM_KEY, ERRORS_KEY, EnumOptionsType, ErrorListProps, ErrorSchema, ErrorTransformer, Field, FieldError, FieldErrors, FieldId, FieldPath, FieldProps, FieldTemplateProps, FieldValidation, FormValidation, GenericObjectType, ID_KEY, ITEMS_KEY, IconButtonProps, IdSchema, InputPropsType, NAME_KEY, ONE_OF_KEY, ObjectFieldTemplatePropertyType, ObjectFieldTemplateProps, PROPERTIES_KEY, PathSchema, REF_KEY, REQUIRED_KEY, RJSFSchema, RJSFSchemaDefinition, RJSFValidationError, RJSF_ADDITONAL_PROPERTIES_FLAG, RangeSpecType, Registry, RegistryFieldsType, RegistryWidgetsType, SUBMIT_BTN_OPTIONS_KEY, SchemaUtilsType, SubmitButtonProps, TemplatesType, TitleFieldProps, UIOptionsType, UISchemaSubmitButtonOptions, UI_FIELD_KEY, UI_OPTIONS_KEY, UI_WIDGET_KEY, UiSchema, UnsupportedFieldProps, ValidationData, ValidatorType, Widget, WidgetProps, allowAdditionalItems, asNumber, canExpand, createSchemaUtils, dataURItoBlob, deepEquals, findSchemaDefinition, getDefaultFormState, getDisplayLabel, getInputProps, getMatchingOption, getSchemaType, getSubmitButtonOptions, getTemplate, getUiOptions, getWidget, guessType, hasWidget, isConstant, isCustomWidget, isFilesArray, isFixedItems, isMultiSelect, isObject, isSelect, localToUTC, mergeDefaultsWithFormData, mergeObjects, mergeSchemas, mergeValidationData, optionsList, orderProperties, pad, parseDateString, processSelectValue, rangeSpec, retrieveSchema, schemaRequiresTrueValue, shouldRender, toConstant, toDateString, toIdSchema, toPathSchema, utcToLocal };
1255
+ export { ADDITIONAL_PROPERTIES_KEY, ADDITIONAL_PROPERTY_FLAG, ALL_OF_KEY, ANY_OF_KEY, ArrayFieldDescriptionProps, ArrayFieldTemplateItemType, ArrayFieldTemplateProps, ArrayFieldTitleProps, CONST_KEY, CustomValidator, DEFAULT_KEY, DEFINITIONS_KEY, DEPENDENCIES_KEY, DateObject, DescriptionFieldProps, ENUM_KEY, ERRORS_KEY, EnumOptionsType, ErrorListProps, ErrorSchema, ErrorTransformer, Field, FieldError, FieldErrorProps, FieldErrors, FieldHelpProps, FieldId, FieldPath, FieldProps, FieldTemplateProps, FieldValidation, FormValidation, GenericObjectType, ID_KEY, ITEMS_KEY, IconButtonProps, IdSchema, InputPropsType, NAME_KEY, ONE_OF_KEY, ObjectFieldTemplatePropertyType, ObjectFieldTemplateProps, PROPERTIES_KEY, PathSchema, REF_KEY, REQUIRED_KEY, RJSFSchema, RJSFSchemaDefinition, RJSFValidationError, RJSF_ADDITONAL_PROPERTIES_FLAG, RangeSpecType, Registry, RegistryFieldsType, RegistryWidgetsType, SUBMIT_BTN_OPTIONS_KEY, SchemaUtilsType, SubmitButtonProps, TemplatesType, TitleFieldProps, UIOptionsType, UISchemaSubmitButtonOptions, UI_FIELD_KEY, UI_OPTIONS_KEY, UI_WIDGET_KEY, UiSchema, UnsupportedFieldProps, ValidationData, ValidatorType, Widget, WidgetProps, allowAdditionalItems, asNumber, canExpand, createSchemaUtils, dataURItoBlob, deepEquals, findSchemaDefinition, getDefaultFormState, getDisplayLabel, getInputProps, getMatchingOption, getSchemaType, getSubmitButtonOptions, getTemplate, getUiOptions, getWidget, guessType, hasWidget, isConstant, isCustomWidget, isFilesArray, isFixedItems, isMultiSelect, isObject, isSelect, localToUTC, mergeDefaultsWithFormData, mergeObjects, mergeSchemas, mergeValidationData, optionsList, orderProperties, pad, parseDateString, processSelectValue, rangeSpec, retrieveSchema, schemaRequiresTrueValue, shouldRender, toConstant, toDateString, toIdSchema, toPathSchema, utcToLocal };
@@ -4,12 +4,12 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var isEqualWith = require('lodash/isEqualWith');
6
6
  var get = require('lodash/get');
7
+ var isEmpty = require('lodash/isEmpty');
7
8
  var jsonpointer = require('jsonpointer');
8
9
  var omit = require('lodash/omit');
9
10
  var set = require('lodash/set');
10
11
  var mergeAllOf = require('json-schema-merge-allof');
11
12
  var union = require('lodash/union');
12
- var isEmpty = require('lodash/isEmpty');
13
13
  var React = require('react');
14
14
  var ReactIs = require('react-is');
15
15
 
@@ -17,12 +17,12 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
17
17
 
18
18
  var isEqualWith__default = /*#__PURE__*/_interopDefaultLegacy(isEqualWith);
19
19
  var get__default = /*#__PURE__*/_interopDefaultLegacy(get);
20
+ var isEmpty__default = /*#__PURE__*/_interopDefaultLegacy(isEmpty);
20
21
  var jsonpointer__default = /*#__PURE__*/_interopDefaultLegacy(jsonpointer);
21
22
  var omit__default = /*#__PURE__*/_interopDefaultLegacy(omit);
22
23
  var set__default = /*#__PURE__*/_interopDefaultLegacy(set);
23
24
  var mergeAllOf__default = /*#__PURE__*/_interopDefaultLegacy(mergeAllOf);
24
25
  var union__default = /*#__PURE__*/_interopDefaultLegacy(union);
25
- var isEmpty__default = /*#__PURE__*/_interopDefaultLegacy(isEmpty);
26
26
  var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
27
27
  var ReactIs__default = /*#__PURE__*/_interopDefaultLegacy(ReactIs);
28
28
 
@@ -991,7 +991,7 @@ function getInnerSchemaForArrayItem(schema, additionalItems, idx) {
991
991
  return {};
992
992
  }
993
993
  /** Computes the defaults for the current `schema` given the `rawFormData` and `parentDefaults` if any. This drills into
994
- * the each level of the schema, recursively, to fill out every level of defaults provided by the schema.
994
+ * each level of the schema, recursively, to fill out every level of defaults provided by the schema.
995
995
  *
996
996
  * @param validator - an implementation of the `ValidatorType` interface that will be used when necessary
997
997
  * @param schema - The schema for which the default state is desired
@@ -1031,9 +1031,9 @@ function computeDefaults(validator, schema, parentDefaults, rootSchema, rawFormD
1031
1031
  } else if (isFixedItems(schema)) {
1032
1032
  defaults = schema.items.map((itemSchema, idx) => computeDefaults(validator, itemSchema, Array.isArray(parentDefaults) ? parentDefaults[idx] : undefined, rootSchema, formData, includeUndefinedValues));
1033
1033
  } else if (ONE_OF_KEY in schema) {
1034
- schema = schema.oneOf[getMatchingOption(validator, undefined, schema.oneOf, rootSchema)];
1034
+ schema = schema.oneOf[getMatchingOption(validator, isEmpty__default["default"](formData) ? undefined : formData, schema.oneOf, rootSchema)];
1035
1035
  } else if (ANY_OF_KEY in schema) {
1036
- schema = schema.anyOf[getMatchingOption(validator, undefined, schema.anyOf, rootSchema)];
1036
+ schema = schema.anyOf[getMatchingOption(validator, isEmpty__default["default"](formData) ? undefined : formData, schema.anyOf, rootSchema)];
1037
1037
  } // Not defaults defined for this node, fallback to generic typed ones.
1038
1038
 
1039
1039