@rjsf/utils 5.6.2 → 5.7.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 CHANGED
@@ -92,6 +92,14 @@ type RJSFSchema = StrictRJSFSchema & GenericObjectType;
92
92
  /** Alias GenericObjectType as FormContextType to allow us to remap this at some future date
93
93
  */
94
94
  type FormContextType = GenericObjectType;
95
+ /** Experimental features to specify different form state behavior. Currently, this affects the
96
+ * handling of optional array fields where `minItems` is set and handling of setting defaults based on the
97
+ * value of `emptyObjectFields`
98
+ */
99
+ type Experimental_DefaultFormStateBehavior = {
100
+ arrayMinItems?: 'populate' | 'requiredOnly';
101
+ emptyObjectFields?: 'populateAllDefaults' | 'populateRequiredDefaults' | 'skipDefaults';
102
+ };
95
103
  /** The interface representing a Date object that contains an optional time */
96
104
  interface DateObject {
97
105
  /** The year of the Date */
@@ -888,9 +896,10 @@ interface SchemaUtilsType<T = any, S extends StrictRJSFSchema = RJSFSchema, F ex
888
896
  *
889
897
  * @param validator - An implementation of the `ValidatorType` interface that will be compared against the current one
890
898
  * @param rootSchema - The root schema that will be compared against the current one
899
+ * @param [experimental_defaultFormStateBehavior] - Optional configuration object, if provided, allows users to override default form state behavior
891
900
  * @returns - True if the `SchemaUtilsType` differs from the given `validator` or `rootSchema`
892
901
  */
893
- doesSchemaUtilsDiffer(validator: ValidatorType<T, S, F>, rootSchema: S): boolean;
902
+ doesSchemaUtilsDiffer(validator: ValidatorType<T, S, F>, rootSchema: S, experimental_defaultFormStateBehavior?: Experimental_DefaultFormStateBehavior): boolean;
894
903
  /** Returns the superset of `formData` that includes the given set updated to include any missing fields that have
895
904
  * computed to have defaults provided in the `schema`.
896
905
  *
@@ -1060,9 +1069,10 @@ declare function createErrorHandler<T = any>(formData: T): FormValidation<T>;
1060
1069
  *
1061
1070
  * @param validator - an implementation of the `ValidatorType` interface that will be forwarded to all the APIs
1062
1071
  * @param rootSchema - The root schema that will be forwarded to all the APIs
1072
+ * @param [experimental_defaultFormStateBehavior] Optional configuration object, if provided, allows users to override default form state behavior
1063
1073
  * @returns - An implementation of a `SchemaUtilsType` interface
1064
1074
  */
1065
- declare function createSchemaUtils<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(validator: ValidatorType<T, S, F>, rootSchema: S): SchemaUtilsType<T, S, F>;
1075
+ declare function createSchemaUtils<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(validator: ValidatorType<T, S, F>, rootSchema: S, experimental_defaultFormStateBehavior?: {}): SchemaUtilsType<T, S, F>;
1066
1076
 
1067
1077
  /** Given the `FileReader.readAsDataURL()` based `dataURI` extracts that data into an actual Blob along with the name
1068
1078
  * of that Blob if provided in the URL. If no name is provided, then the name falls back to `unknown`.
@@ -1229,6 +1239,14 @@ declare class ErrorSchemaBuilder<T = any> {
1229
1239
  */
1230
1240
  declare function findSchemaDefinition<S extends StrictRJSFSchema = RJSFSchema>($ref?: string, rootSchema?: S): S;
1231
1241
 
1242
+ /** Returns the `discriminator.propertyName` when defined in the `schema` if it is a string. A warning is generated when
1243
+ * it is not a string. Returns `undefined` when a valid discriminator is not present.
1244
+ *
1245
+ * @param schema - The schema from which the discriminator is potentially obtained
1246
+ * @returns - The `discriminator.propertyName` if it exists in the schema, otherwise `undefined`
1247
+ */
1248
+ declare function getDiscriminatorFieldFromSchema<S extends StrictRJSFSchema = RJSFSchema>(schema: S): string | undefined;
1249
+
1232
1250
  /** Using the `schema`, `defaultType` and `options`, extract out the props for the <input> element that make sense.
1233
1251
  *
1234
1252
  * @param schema - The schema for the field provided by the widget
@@ -1299,6 +1317,13 @@ declare function getWidget<T = any, S extends StrictRJSFSchema = RJSFSchema, F e
1299
1317
  */
1300
1318
  declare function guessType(value: any): "array" | "string" | "null" | "boolean" | "number" | "object";
1301
1319
 
1320
+ /** Stringifies the schema and returns the hash of the resulting string.
1321
+ *
1322
+ * @param schema - The schema for which the hash is desired
1323
+ * @returns - The string obtained from the hash of the stringified schema
1324
+ */
1325
+ declare function hashForSchema<S extends StrictRJSFSchema = RJSFSchema>(schema: S): string;
1326
+
1302
1327
  /** Detects whether the `widget` exists for the `schema` with the associated `registryWidgets` and returns true if it
1303
1328
  * does, or false if it doesn't.
1304
1329
  *
@@ -1618,6 +1643,7 @@ declare const DEPENDENCIES_KEY = "dependencies";
1618
1643
  declare const ENUM_KEY = "enum";
1619
1644
  declare const ERRORS_KEY = "__errors";
1620
1645
  declare const ID_KEY = "$id";
1646
+ declare const IF_KEY = "if";
1621
1647
  declare const ITEMS_KEY = "items";
1622
1648
  declare const NAME_KEY = "$name";
1623
1649
  declare const ONE_OF_KEY = "oneOf";
@@ -1632,6 +1658,20 @@ declare const UI_WIDGET_KEY = "ui:widget";
1632
1658
  declare const UI_OPTIONS_KEY = "ui:options";
1633
1659
  declare const UI_GLOBAL_OPTIONS_KEY = "ui:globalOptions";
1634
1660
 
1661
+ /** The type of the map of schema hash to schema
1662
+ */
1663
+ type SchemaMap<S extends StrictRJSFSchema = RJSFSchema> = {
1664
+ [hash: string]: S;
1665
+ };
1666
+
1667
+ /** Parses the given `rootSchema` to extract out all the sub-schemas that maybe contained within it. Returns a map of
1668
+ * the hash of the schema to schema/sub-schema.
1669
+ *
1670
+ * @param rootSchema - The root schema to parse for sub-schemas used by `isValid()` calls
1671
+ * @returns - The `SchemaMap` of all schemas that were parsed
1672
+ */
1673
+ declare function schemaParser<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(rootSchema: S): SchemaMap<S>;
1674
+
1635
1675
  /** Returns the superset of `formData` that includes the given set updated to include any missing fields that have
1636
1676
  * computed to have defaults provided in the `schema`.
1637
1677
  *
@@ -1642,9 +1682,10 @@ declare const UI_GLOBAL_OPTIONS_KEY = "ui:globalOptions";
1642
1682
  * @param [includeUndefinedValues=false] - Optional flag, if true, cause undefined values to be added as defaults.
1643
1683
  * If "excludeObjectChildren", cause undefined values for this object and pass `includeUndefinedValues` as
1644
1684
  * false when computing defaults for any nested object properties.
1685
+ * @param [experimental_defaultFormStateBehavior] Optional configuration object, if provided, allows users to override default form state behavior
1645
1686
  * @returns - The resulting `formData` with all the defaults provided
1646
1687
  */
1647
- declare 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'): T | T[] | undefined;
1688
+ declare 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;
1648
1689
 
1649
1690
  /** Determines whether the combination of `schema` and `uiSchema` properties indicates that the label for the `schema`
1650
1691
  * should be displayed in a UI.
@@ -1755,7 +1796,7 @@ declare function mergeValidationData<T = any, S extends StrictRJSFSchema = RJSFS
1755
1796
  * resolved and merged into the `schema` given a `validator`, `rootSchema` and `rawFormData` that is used to do the
1756
1797
  * potentially recursive resolution.
1757
1798
  *
1758
- * @param validator - An implementation of the `ValidatorType<T, S>` interface that will be forwarded to all the APIs
1799
+ * @param validator - An implementation of the `ValidatorType` interface that will be forwarded to all the APIs
1759
1800
  * @param schema - The schema for which retrieving a schema is desired
1760
1801
  * @param [rootSchema={}] - The root schema that will be forwarded to all the APIs
1761
1802
  * @param [rawFormData] - The current formData, if any, to assist retrieving a schema
@@ -1836,4 +1877,4 @@ declare function toIdSchema<T = any, S extends StrictRJSFSchema = RJSFSchema, F
1836
1877
  */
1837
1878
  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>;
1838
1879
 
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 };
1880
+ 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, Experimental_DefaultFormStateBehavior, Field, FieldError, FieldErrorProps, FieldErrors, FieldHelpProps, FieldId, FieldPath, FieldProps, FieldTemplateProps, FieldValidation, FormContextType, FormValidation, GenericObjectType, GlobalUISchemaOptions, ID_KEY, IF_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, SchemaMap, 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, getDiscriminatorFieldFromSchema, getDisplayLabel, getFirstMatchingOption, getInputProps, getMatchingOption, getSchemaType, getSubmitButtonOptions, getTemplate, getUiOptions, getWidget, guessType, hasWidget, hashForSchema, helpId, isConstant, isCustomWidget, isFilesArray, isFixedItems, isMultiSelect, isObject, isSelect, labelValue, localToUTC, mergeDefaultsWithFormData, mergeObjects, mergeSchemas, mergeValidationData, optionId, optionsList, orderProperties, pad, parseDateString, rangeSpec, replaceStringParameters, retrieveSchema, sanitizeDataForNewSchema, schemaParser, schemaRequiresTrueValue, shouldRender, titleId, toConstant, toDateString, toErrorList, toErrorSchema, toIdSchema, toPathSchema, unwrapErrorHandler, utcToLocal, validationDataMerge, withIdRefPrefix };