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

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
@@ -388,6 +388,8 @@ declare type ArrayFieldTemplateItemType<T = any, S extends StrictRJSFSchema = RJ
388
388
  className: string;
389
389
  /** A boolean value stating if the array item is disabled */
390
390
  disabled: boolean;
391
+ /** A boolean value stating whether new items can be added to the array */
392
+ canAdd: boolean;
391
393
  /** A boolean value stating whether the array item can be moved down */
392
394
  hasMoveDown: boolean;
393
395
  /** A boolean value stating whether the array item can be moved up */
@@ -398,6 +400,8 @@ declare type ArrayFieldTemplateItemType<T = any, S extends StrictRJSFSchema = RJ
398
400
  hasToolbar: boolean;
399
401
  /** A number stating the index the array item occurs in `items` */
400
402
  index: number;
403
+ /** A number stating the total number `items` in the array */
404
+ totalItems: number;
401
405
  /** Returns a function that adds a new item at `index` */
402
406
  onAddIndexClick: (index: number) => (event?: any) => void;
403
407
  /** Returns a function that removes the item at `index` */
@@ -526,7 +530,7 @@ interface WidgetProps<T = any, S extends StrictRJSFSchema = RJSFSchema, F extend
526
530
  */
527
531
  options: NonNullable<UIOptionsType<T, S, F>> & {
528
532
  /** The enum options list for a type that supports them */
529
- enumOptions?: EnumOptionsType[];
533
+ enumOptions?: EnumOptionsType<S>[];
530
534
  };
531
535
  /** The `formContext` object that you passed to `Form` */
532
536
  formContext?: F;
@@ -551,6 +555,8 @@ declare type Widget<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends
551
555
  declare type SubmitButtonProps<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any> = {
552
556
  /** The uiSchema for this widget */
553
557
  uiSchema?: UiSchema<T, S, F>;
558
+ /** The `registry` object */
559
+ registry: Registry<T, S, F>;
554
560
  };
555
561
  /** The type that defines the props for an Icon button, extending from a basic HTML button attributes */
556
562
  declare type IconButtonProps<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any> = React.ButtonHTMLAttributes<HTMLButtonElement> & {
@@ -560,6 +566,8 @@ declare type IconButtonProps<T = any, S extends StrictRJSFSchema = RJSFSchema, F
560
566
  icon?: string | React.ReactElement;
561
567
  /** The uiSchema for this widget */
562
568
  uiSchema?: UiSchema<T, S, F>;
569
+ /** The `registry` object */
570
+ registry: Registry<T, S, F>;
563
571
  };
564
572
  /** The type that defines how to change the behavior of the submit button for the form */
565
573
  declare type UISchemaSubmitButtonOptions = {
@@ -663,14 +671,14 @@ declare type UiSchema<T = any, S extends StrictRJSFSchema = RJSFSchema, F extend
663
671
  /** An object that contains all the potential UI options in a single object */
664
672
  "ui:options"?: UIOptionsType<T, S, F>;
665
673
  };
666
- /** A `CustomValidator` function takes in a `formData` and `errors` object and returns the given `errors` object back,
667
- * while potentially adding additional messages to the `errors`
674
+ /** A `CustomValidator` function takes in a `formData`, `errors` and `uiSchema` objects and returns the given `errors`
675
+ * object back, while potentially adding additional messages to the `errors`
668
676
  */
669
- declare type CustomValidator<T = any> = (formData: T, errors: FormValidation<T>) => FormValidation<T>;
670
- /** An `ErrorTransformer` function will take in a list of `errors` and potentially return a transformation of those
671
- * errors in what ever way it deems necessary
677
+ declare type CustomValidator<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any> = (formData: T, errors: FormValidation<T>, uiSchema?: UiSchema<T, S, F>) => FormValidation<T>;
678
+ /** An `ErrorTransformer` function will take in a list of `errors` & a `uiSchema` and potentially return a
679
+ * transformation of those errors in what ever way it deems necessary
672
680
  */
673
- declare type ErrorTransformer = (errors: RJSFValidationError[]) => RJSFValidationError[];
681
+ declare type ErrorTransformer<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any> = (errors: RJSFValidationError[], uiSchema?: UiSchema<T, S, F>) => RJSFValidationError[];
674
682
  /** The type that describes the data that is returned from the `ValidatorType.validateFormData()` function */
675
683
  declare type ValidationData<T> = {
676
684
  /** The validation errors as a list of `RJSFValidationError` objects */
@@ -681,7 +689,7 @@ declare type ValidationData<T> = {
681
689
  /** The interface that describes the validation functions that are provided by a Validator implementation used by the
682
690
  * schema utilities.
683
691
  */
684
- interface ValidatorType<T = any, S extends StrictRJSFSchema = RJSFSchema> {
692
+ interface ValidatorType<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any> {
685
693
  /** This function processes the `formData` with an optional user contributed `customValidate` function, which receives
686
694
  * the form data and a `errorHandler` function that will be used to add custom validation errors for each field. Also
687
695
  * supports a `transformErrors` function that will take the raw AJV validation errors, prior to custom validation and
@@ -691,8 +699,9 @@ interface ValidatorType<T = any, S extends StrictRJSFSchema = RJSFSchema> {
691
699
  * @param schema - The schema against which to validate the form data
692
700
  * @param [customValidate] - An optional function that is used to perform custom validation
693
701
  * @param [transformErrors] - An optional function that is used to transform errors after AJV validation
702
+ * @param [uiSchema] - An optional uiSchema that is passed to `transformErrors` and `customValidate`
694
703
  */
695
- validateFormData(formData: T | undefined, schema: S, customValidate?: CustomValidator<T>, transformErrors?: ErrorTransformer): ValidationData<T>;
704
+ validateFormData(formData: T | undefined, schema: S, customValidate?: CustomValidator<T, S, F>, transformErrors?: ErrorTransformer<T, S, F>, uiSchema?: UiSchema<T, S, F>): ValidationData<T>;
696
705
  /** Converts an `errorSchema` into a list of `RJSFValidationErrors`
697
706
  *
698
707
  * @param errorSchema - The `ErrorSchema` instance to convert
@@ -729,7 +738,7 @@ interface SchemaUtilsType<T = any, S extends StrictRJSFSchema = RJSFSchema, F ex
729
738
  *
730
739
  * @returns - The `ValidatorType`
731
740
  */
732
- getValidator(): ValidatorType<T, S>;
741
+ getValidator(): ValidatorType<T, S, F>;
733
742
  /** Determines whether either the `validator` and `rootSchema` differ from the ones associated with this instance of
734
743
  * the `SchemaUtilsType`. If either `validator` or `rootSchema` are falsy, then return false to prevent the creation
735
744
  * of a new `SchemaUtilsType` with incomplete properties.
@@ -738,7 +747,7 @@ interface SchemaUtilsType<T = any, S extends StrictRJSFSchema = RJSFSchema, F ex
738
747
  * @param rootSchema - The root schema that will be compared against the current one
739
748
  * @returns - True if the `SchemaUtilsType` differs from the given `validator` or `rootSchema`
740
749
  */
741
- doesSchemaUtilsDiffer(validator: ValidatorType<T, S>, rootSchema: S): boolean;
750
+ doesSchemaUtilsDiffer(validator: ValidatorType<T, S, F>, rootSchema: S): boolean;
742
751
  /** Returns the superset of `formData` that includes the given set updated to include any missing fields that have
743
752
  * computed to have defaults provided in the `schema`.
744
753
  *
@@ -860,7 +869,7 @@ declare function canExpand<T = any, S extends StrictRJSFSchema = RJSFSchema, F e
860
869
  * @param rootSchema - The root schema that will be forwarded to all the APIs
861
870
  * @returns - An implementation of a `SchemaUtilsType` interface
862
871
  */
863
- declare function createSchemaUtils<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(validator: ValidatorType<T, S>, rootSchema: S): SchemaUtilsType<T, S, F>;
872
+ declare function createSchemaUtils<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(validator: ValidatorType<T, S, F>, rootSchema: S): SchemaUtilsType<T, S, F>;
864
873
 
865
874
  /** Given the `FileReader.readAsDataURL()` based `dataURI` extracts that data into an actual Blob along with the name
866
875
  * of that Blob if provided in the URL. If no name is provided, then the name falls back to `unknown`.
@@ -1251,7 +1260,7 @@ declare const UI_OPTIONS_KEY = "ui:options";
1251
1260
  * object properties.
1252
1261
  * @returns - The resulting `formData` with all the defaults provided
1253
1262
  */
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;
1263
+ 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;
1255
1264
 
1256
1265
  /** Determines whether the combination of `schema` and `uiSchema` properties indicates that the label for the `schema`
1257
1266
  * should be displayed in a UI.
@@ -1262,7 +1271,7 @@ declare function getDefaultFormState<T = any, S extends StrictRJSFSchema = RJSFS
1262
1271
  * @param [rootSchema] - The root schema, used to primarily to look up `$ref`s
1263
1272
  * @returns - True if the label should be displayed or false if it should not
1264
1273
  */
1265
- declare function getDisplayLabel<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(validator: ValidatorType<T, S>, schema: S, uiSchema?: UiSchema<T, S, F>, rootSchema?: S): boolean;
1274
+ declare 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): boolean;
1266
1275
 
1267
1276
  /** Given the `formData` and list of `options`, attempts to find the index of the option that best matches the data.
1268
1277
  *
@@ -1272,7 +1281,7 @@ declare function getDisplayLabel<T = any, S extends StrictRJSFSchema = RJSFSchem
1272
1281
  * @param rootSchema - The root schema, used to primarily to look up `$ref`s
1273
1282
  * @returns - The index of the matched option or 0 if none is available
1274
1283
  */
1275
- declare function getMatchingOption<T = any, S extends StrictRJSFSchema = RJSFSchema>(validator: ValidatorType<T, S>, formData: T | undefined, options: S[], rootSchema: S): number;
1284
+ 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;
1276
1285
 
1277
1286
  /** Checks to see if the `schema` and `uiSchema` combination represents an array of files
1278
1287
  *
@@ -1282,7 +1291,7 @@ declare function getMatchingOption<T = any, S extends StrictRJSFSchema = RJSFSch
1282
1291
  * @param [rootSchema] - The root schema, used to primarily to look up `$ref`s
1283
1292
  * @returns - True if schema/uiSchema contains an array of files, otherwise false
1284
1293
  */
1285
- declare function isFilesArray<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(validator: ValidatorType<T, S>, schema: S, uiSchema?: UiSchema<T, S, F>, rootSchema?: S): boolean;
1294
+ declare function isFilesArray<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(validator: ValidatorType<T, S, F>, schema: S, uiSchema?: UiSchema<T, S, F>, rootSchema?: S): boolean;
1286
1295
 
1287
1296
  /** Checks to see if the `schema` combination represents a multi-select
1288
1297
  *
@@ -1291,7 +1300,7 @@ declare function isFilesArray<T = any, S extends StrictRJSFSchema = RJSFSchema,
1291
1300
  * @param [rootSchema] - The root schema, used to primarily to look up `$ref`s
1292
1301
  * @returns - True if schema contains a multi-select, otherwise false
1293
1302
  */
1294
- declare function isMultiSelect<T = any, S extends StrictRJSFSchema = RJSFSchema>(validator: ValidatorType<T, S>, schema: S, rootSchema?: S): boolean;
1303
+ declare function isMultiSelect<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(validator: ValidatorType<T, S, F>, schema: S, rootSchema?: S): boolean;
1295
1304
 
1296
1305
  /** Checks to see if the `schema` combination represents a select
1297
1306
  *
@@ -1300,7 +1309,7 @@ declare function isMultiSelect<T = any, S extends StrictRJSFSchema = RJSFSchema>
1300
1309
  * @param [rootSchema] - The root schema, used to primarily to look up `$ref`s
1301
1310
  * @returns - True if schema contains a select, otherwise false
1302
1311
  */
1303
- declare function isSelect<T = any, S extends StrictRJSFSchema = RJSFSchema>(validator: ValidatorType<T, S>, theSchema: S, rootSchema?: S): boolean;
1312
+ declare function isSelect<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(validator: ValidatorType<T, S, F>, theSchema: S, rootSchema?: S): boolean;
1304
1313
 
1305
1314
  /** Merges the errors in `additionalErrorSchema` into the existing `validationData` by combining the hierarchies in the
1306
1315
  * two `ErrorSchema`s and then appending the error list from the `additionalErrorSchema` obtained by calling
@@ -1312,7 +1321,7 @@ declare function isSelect<T = any, S extends StrictRJSFSchema = RJSFSchema>(vali
1312
1321
  * @param [additionalErrorSchema] - The additional set of errors in an `ErrorSchema`
1313
1322
  * @returns - The `validationData` with the additional errors from `additionalErrorSchema` merged into it, if provided.
1314
1323
  */
1315
- declare function mergeValidationData<T = any, S extends StrictRJSFSchema = RJSFSchema>(validator: ValidatorType<T, S>, validationData: ValidationData<T>, additionalErrorSchema?: ErrorSchema<T>): ValidationData<T>;
1324
+ 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>;
1316
1325
 
1317
1326
  /** Retrieves an expanded schema that has had all of its conditions, additional properties, references and dependencies
1318
1327
  * resolved and merged into the `schema` given a `validator`, `rootSchema` and `rawFormData` that is used to do the
@@ -1324,7 +1333,7 @@ declare function mergeValidationData<T = any, S extends StrictRJSFSchema = RJSFS
1324
1333
  * @param [rawFormData] - The current formData, if any, to assist retrieving a schema
1325
1334
  * @returns - The schema having its conditions, additional properties, references and dependencies resolved
1326
1335
  */
1327
- declare function retrieveSchema<T = any, S extends StrictRJSFSchema = RJSFSchema>(validator: ValidatorType<T, S>, schema: S, rootSchema?: S, rawFormData?: T): S;
1336
+ declare function retrieveSchema<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(validator: ValidatorType<T, S, F>, schema: S, rootSchema?: S, rawFormData?: T): S;
1328
1337
 
1329
1338
  /** Generates an `IdSchema` object for the `schema`, recursively
1330
1339
  *
@@ -1337,7 +1346,7 @@ declare function retrieveSchema<T = any, S extends StrictRJSFSchema = RJSFSchema
1337
1346
  * @param [idSeparator='_'] - The separator to use for the path segments in the id
1338
1347
  * @returns - The `IdSchema` object for the `schema`
1339
1348
  */
1340
- declare function toIdSchema<T = any, S extends StrictRJSFSchema = RJSFSchema>(validator: ValidatorType<T, S>, schema: S, id?: string | null, rootSchema?: S, formData?: T, idPrefix?: string, idSeparator?: string): IdSchema<T>;
1349
+ declare function toIdSchema<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(validator: ValidatorType<T, S, F>, schema: S, id?: string | null, rootSchema?: S, formData?: T, idPrefix?: string, idSeparator?: string): IdSchema<T>;
1341
1350
 
1342
1351
  /** Generates an `PathSchema` object for the `schema`, recursively
1343
1352
  *
@@ -1348,6 +1357,6 @@ declare function toIdSchema<T = any, S extends StrictRJSFSchema = RJSFSchema>(va
1348
1357
  * @param [formData] - The current formData, if any, to assist retrieving a schema
1349
1358
  * @returns - The `PathSchema` object for the `schema`
1350
1359
  */
1351
- declare function toPathSchema<T = any, S extends StrictRJSFSchema = RJSFSchema>(validator: ValidatorType<T, S>, schema: S, name?: string, rootSchema?: S, formData?: T): PathSchema<T>;
1360
+ 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>;
1352
1361
 
1353
1362
  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 };