@rjsf/utils 5.0.0-beta.13 → 5.0.0-beta.15

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 CHANGED
@@ -408,7 +408,9 @@ declare type ArrayFieldTemplateItemType<T = any, S extends StrictRJSFSchema = RJ
408
408
  readonly: boolean;
409
409
  /** A stable, unique key for the array item */
410
410
  key: string;
411
- /** The uiSchema object for this field */
411
+ /** The schema object for this array item */
412
+ schema: S;
413
+ /** The uiSchema object for this array item */
412
414
  uiSchema?: UiSchema<T, S, F>;
413
415
  /** The `registry` object */
414
416
  registry: Registry<T, S, F>;
@@ -742,10 +744,12 @@ interface SchemaUtilsType<T = any, S extends StrictRJSFSchema = RJSFSchema, F ex
742
744
  *
743
745
  * @param schema - The schema for which the default state is desired
744
746
  * @param [formData] - The current formData, if any, onto which to provide any missing defaults
745
- * @param [includeUndefinedValues=false] - Optional flag, if true, cause undefined values to be added as defaults
747
+ * @param [includeUndefinedValues=false] - Optional flag, if true, cause undefined values to be added as defaults.
748
+ * If "excludeObjectChildren", pass `includeUndefinedValues` as false when computing defaults for any nested
749
+ * object properties.
746
750
  * @returns - The resulting `formData` with all the defaults provided
747
751
  */
748
- getDefaultFormState(schema: S, formData?: T, includeUndefinedValues?: boolean): T | T[] | undefined;
752
+ getDefaultFormState(schema: S, formData?: T, includeUndefinedValues?: boolean | "excludeObjectChildren"): T | T[] | undefined;
749
753
  /** Determines whether the combination of `schema` and `uiSchema` properties indicates that the label for the `schema`
750
754
  * should be displayed in a UI.
751
755
  *
@@ -878,6 +882,66 @@ declare function dataURItoBlob(dataURI: string): {
878
882
  */
879
883
  declare function deepEquals(a: any, b: any): boolean;
880
884
 
885
+ /** The `ErrorSchemaBuilder<T>` is used to build an `ErrorSchema<T>` since the definition of the `ErrorSchema` type is
886
+ * designed for reading information rather than writing it. Use this class to add, replace or clear errors in an error
887
+ * schema by using either dotted path or an array of path names. Once you are done building the `ErrorSchema`, you can
888
+ * get the result and/or reset all the errors back to an initial set and start again.
889
+ */
890
+ declare class ErrorSchemaBuilder<T = any> {
891
+ /** The error schema being built
892
+ *
893
+ * @private
894
+ */
895
+ private errorSchema;
896
+ /** Construct an `ErrorSchemaBuilder` with an optional initial set of errors in an `ErrorSchema`.
897
+ *
898
+ * @param [initialSchema] - The optional set of initial errors, that will be cloned into the class
899
+ */
900
+ constructor(initialSchema?: ErrorSchema<T>);
901
+ /** Returns the `ErrorSchema` that has been updated by the methods of the `ErrorSchemaBuilder`
902
+ */
903
+ get ErrorSchema(): ErrorSchema<T>;
904
+ /** Will get an existing `ErrorSchema` at the specified `pathOfError` or create and return one.
905
+ *
906
+ * @param [pathOfError] - The optional path into the `ErrorSchema` at which to add the error(s)
907
+ * @returns - The error block for the given `pathOfError` or the root if not provided
908
+ * @private
909
+ */
910
+ private getOrCreateErrorBlock;
911
+ /** Resets all errors in the `ErrorSchemaBuilder` back to the `initialSchema` if provided, otherwise an empty set.
912
+ *
913
+ * @param [initialSchema] - The optional set of initial errors, that will be cloned into the class
914
+ * @returns - The `ErrorSchemaBuilder` object for chaining purposes
915
+ */
916
+ resetAllErrors(initialSchema?: ErrorSchema<T>): this;
917
+ /** Adds the `errorOrList` to the list of errors in the `ErrorSchema` at either the root level or the location within
918
+ * the schema described by the `pathOfError`. For more information about how to specify the path see the
919
+ * [eslint lodash plugin docs](https://github.com/wix/eslint-plugin-lodash/blob/master/docs/rules/path-style.md).
920
+ *
921
+ * @param errorOrList - The error or list of errors to add into the `ErrorSchema`
922
+ * @param [pathOfError] - The optional path into the `ErrorSchema` at which to add the error(s)
923
+ * @returns - The `ErrorSchemaBuilder` object for chaining purposes
924
+ */
925
+ addErrors(errorOrList: string | string[], pathOfError?: string | string[]): this;
926
+ /** Sets/replaces the `errorOrList` as the error(s) in the `ErrorSchema` at either the root level or the location
927
+ * within the schema described by the `pathOfError`. For more information about how to specify the path see the
928
+ * [eslint lodash plugin docs](https://github.com/wix/eslint-plugin-lodash/blob/master/docs/rules/path-style.md).
929
+ *
930
+ * @param errorOrList - The error or list of errors to set into the `ErrorSchema`
931
+ * @param [pathOfError] - The optional path into the `ErrorSchema` at which to set the error(s)
932
+ * @returns - The `ErrorSchemaBuilder` object for chaining purposes
933
+ */
934
+ setErrors(errorOrList: string | string[], pathOfError?: string | string[]): this;
935
+ /** Clears the error(s) in the `ErrorSchema` at either the root level or the location within the schema described by
936
+ * the `pathOfError`. For more information about how to specify the path see the
937
+ * [eslint lodash plugin docs](https://github.com/wix/eslint-plugin-lodash/blob/master/docs/rules/path-style.md).
938
+ *
939
+ * @param [pathOfError] - The optional path into the `ErrorSchema` at which to clear the error(s)
940
+ * @returns - The `ErrorSchemaBuilder` object for chaining purposes
941
+ */
942
+ clearErrors(pathOfError?: string | string[]): this;
943
+ }
944
+
881
945
  /** Given the name of a `$ref` from within a schema, using the `rootSchema`, look up and return the sub-schema using the
882
946
  * path provided by that reference. If `#` is not the first character of the reference, or the path does not exist in
883
947
  * the schema, then throw an Error. Otherwise return the sub-schema. Also deals with nested `$ref`s in the sub-schema.
@@ -1026,10 +1090,12 @@ declare function mergeDefaultsWithFormData<T = any>(defaults: T, formData: T): T
1026
1090
  *
1027
1091
  * @param obj1 - The first object to merge
1028
1092
  * @param obj2 - The second object to merge
1029
- * @param [concatArrays=false] - Optional flag that, when true, will cause arrays to be concatenated
1093
+ * @param [concatArrays=false] - Optional flag that, when true, will cause arrays to be concatenated. Use
1094
+ * "preventDuplicates" to merge arrays in a manner that prevents any duplicate entries from being merged.
1095
+ * NOTE: Uses shallow comparison for the duplicate checking.
1030
1096
  * @returns - A new object that is the merge of the two given objects
1031
1097
  */
1032
- declare function mergeObjects(obj1: GenericObjectType, obj2: GenericObjectType, concatArrays?: boolean): GenericObjectType;
1098
+ declare function mergeObjects(obj1: GenericObjectType, obj2: GenericObjectType, concatArrays?: boolean | "preventDuplicates"): GenericObjectType;
1033
1099
 
1034
1100
  /** Recursively merge deeply nested schemas. The difference between `mergeSchemas` and `mergeObjects` is that
1035
1101
  * `mergeSchemas` only concats arrays for values under the 'required' keyword, and when it does, it doesn't include
@@ -1180,10 +1246,12 @@ declare const UI_OPTIONS_KEY = "ui:options";
1180
1246
  * @param theSchema - The schema for which the default state is desired
1181
1247
  * @param [formData] - The current formData, if any, onto which to provide any missing defaults
1182
1248
  * @param [rootSchema] - The root schema, used to primarily to look up `$ref`s
1183
- * @param [includeUndefinedValues=false] - Optional flag, if true, cause undefined values to be added as defaults
1249
+ * @param [includeUndefinedValues=false] - Optional flag, if true, cause undefined values to be added as defaults.
1250
+ * If "excludeObjectChildren", pass `includeUndefinedValues` as false when computing defaults for any nested
1251
+ * object properties.
1184
1252
  * @returns - The resulting `formData` with all the defaults provided
1185
1253
  */
1186
- declare function getDefaultFormState<T = any, S extends StrictRJSFSchema = RJSFSchema>(validator: ValidatorType<T, S>, theSchema: S, formData?: T, rootSchema?: S, includeUndefinedValues?: boolean): T | T[] | undefined;
1254
+ declare function getDefaultFormState<T = any, S extends StrictRJSFSchema = RJSFSchema>(validator: ValidatorType<T, S>, theSchema: S, formData?: T, rootSchema?: S, includeUndefinedValues?: boolean | "excludeObjectChildren"): T | T[] | undefined;
1187
1255
 
1188
1256
  /** Determines whether the combination of `schema` and `uiSchema` properties indicates that the label for the `schema`
1189
1257
  * should be displayed in a UI.
@@ -1282,4 +1350,4 @@ declare function toIdSchema<T = any, S extends StrictRJSFSchema = RJSFSchema>(va
1282
1350
  */
1283
1351
  declare function toPathSchema<T = any, S extends StrictRJSFSchema = RJSFSchema>(validator: ValidatorType<T, S>, schema: S, name?: string, rootSchema?: S, formData?: T): PathSchema<T>;
1284
1352
 
1285
- 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, FormContextType, FormValidation, GenericObjectType, 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, UIOptionsType, UISchemaSubmitButtonOptions, UI_FIELD_KEY, UI_OPTIONS_KEY, UI_WIDGET_KEY, UiSchema, UnsupportedFieldProps, ValidationData, ValidatorType, Widget, WidgetProps, WrapIfAdditionalTemplateProps, 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 };
1353
+ 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, ErrorSchemaBuilder, ErrorTransformer, Field, FieldError, FieldErrorProps, FieldErrors, FieldHelpProps, FieldId, FieldPath, FieldProps, FieldTemplateProps, FieldValidation, FormContextType, FormValidation, GenericObjectType, 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, UIOptionsType, UISchemaSubmitButtonOptions, UI_FIELD_KEY, UI_OPTIONS_KEY, UI_WIDGET_KEY, UiSchema, UnsupportedFieldProps, ValidationData, ValidatorType, Widget, WidgetProps, WrapIfAdditionalTemplateProps, 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 };