Skip to content

Commit 0c1839b

Browse files
author
LFRW2K\lecmil2
committed
[FIX] Templates typing
1 parent 485cce7 commit 0c1839b

File tree

1 file changed

+43
-8
lines changed

1 file changed

+43
-8
lines changed

packages/utils/src/types.ts

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ export type TemplatesType<T = any, S extends StrictRJSFSchema = RJSFSchema, F ex
332332
};
333333
} & {
334334
/** Allow this to support any named `ComponentType` or an object of named `ComponentType`s */
335-
[key: string]: ComponentType<RJSFBaseProps<T, S, F>> | { [key: string]: ComponentType<RJSFBaseProps<T, S, F>> };
335+
[key: string]: ComponentType<any> | { [key: string]: ComponentType<any> };
336336
};
337337

338338
/** The set of UiSchema options that can be set globally and used as fallbacks at an individual template, field or
@@ -785,19 +785,20 @@ export interface BaseInputTemplateProps<
785785
}
786786

787787
/** The type that defines the props used by the Submit button */
788-
export type SubmitButtonProps<
789-
T = any,
790-
S extends StrictRJSFSchema = RJSFSchema,
791-
F extends FormContextType = any
792-
> = RJSFBaseProps<T, S, F>;
788+
export type SubmitButtonProps<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any> = {
789+
/** The uiSchema for this widget */
790+
uiSchema?: UiSchema<T, S, F>;
791+
/** The `registry` object */
792+
registry: Registry<T, S, F>;
793+
};
793794

794795
/** The type that defines the props for an Icon button, extending from a basic HTML button attributes */
795796
export type IconButtonProps<
796797
T = any,
797798
S extends StrictRJSFSchema = RJSFSchema,
798799
F extends FormContextType = any
799800
> = ButtonHTMLAttributes<HTMLButtonElement> &
800-
RJSFBaseProps<T, S, F> & {
801+
Omit<RJSFBaseProps<T, S, F>, 'schema'> & {
801802
/** An alternative specification for the type of the icon button */
802803
iconType?: string;
803804
/** The name representation or actual react element implementation for the icon */
@@ -838,7 +839,23 @@ type MakeUIType<Type> = {
838839
* remap the keys. It also contains all the properties, optionally, of `TemplatesType` except "ButtonTemplates"
839840
*/
840841
type UIOptionsBaseType<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any> = Partial<
841-
Omit<TemplatesType<T, S, F>, 'ButtonTemplates'>
842+
Pick<
843+
TemplatesType<T, S, F>,
844+
| 'ArrayFieldDescriptionTemplate'
845+
| 'ArrayFieldItemTemplate'
846+
| 'ArrayFieldTemplate'
847+
| 'ArrayFieldTitleTemplate'
848+
| 'BaseInputTemplate'
849+
| 'DescriptionFieldTemplate'
850+
| 'ErrorListTemplate'
851+
| 'FieldErrorTemplate'
852+
| 'FieldHelpTemplate'
853+
| 'FieldTemplate'
854+
| 'ObjectFieldTemplate'
855+
| 'TitleFieldTemplate'
856+
| 'UnsupportedFieldTemplate'
857+
| 'WrapIfAdditionalTemplate'
858+
>
842859
> &
843860
GlobalUISchemaOptions & {
844861
/** Any classnames that the user wants to be applied to a field in the ui */
@@ -977,6 +994,7 @@ export interface ValidatorType<T = any, S extends StrictRJSFSchema = RJSFSchema,
977994
transformErrors?: ErrorTransformer<T, S, F>,
978995
uiSchema?: UiSchema<T, S, F>
979996
): ValidationData<T>;
997+
980998
/** Converts an `errorSchema` into a list of `RJSFValidationErrors`
981999
*
9821000
* @param errorSchema - The `ErrorSchema` instance to convert
@@ -985,6 +1003,7 @@ export interface ValidatorType<T = any, S extends StrictRJSFSchema = RJSFSchema,
9851003
* the next major release.
9861004
*/
9871005
toErrorList(errorSchema?: ErrorSchema<T>, fieldPath?: string[]): RJSFValidationError[];
1006+
9881007
/** Validates data against a schema, returning true if the data is valid, or
9891008
* false otherwise. If the schema is invalid, then this function will return
9901009
* false.
@@ -994,13 +1013,15 @@ export interface ValidatorType<T = any, S extends StrictRJSFSchema = RJSFSchema,
9941013
* @param rootSchema - The root schema used to provide $ref resolutions
9951014
*/
9961015
isValid(schema: S, formData: T | undefined, rootSchema: S): boolean;
1016+
9971017
/** Runs the pure validation of the `schema` and `formData` without any of the RJSF functionality. Provided for use
9981018
* by the playground. Returns the `errors` from the validation
9991019
*
10001020
* @param schema - The schema against which to validate the form data
10011021
* @param formData - The form data to validate
10021022
*/
10031023
rawValidation<Result = any>(schema: S, formData?: T): { errors?: Result[]; validationError?: Error };
1024+
10041025
/** An optional function that can be used to reset validator implementation. Useful for clear schemas in the AJV
10051026
* instance for tests.
10061027
*/
@@ -1018,6 +1039,7 @@ export interface SchemaUtilsType<T = any, S extends StrictRJSFSchema = RJSFSchem
10181039
* @returns - The `ValidatorType`
10191040
*/
10201041
getValidator(): ValidatorType<T, S, F>;
1042+
10211043
/** Determines whether either the `validator` and `rootSchema` differ from the ones associated with this instance of
10221044
* the `SchemaUtilsType`. If either `validator` or `rootSchema` are falsy, then return false to prevent the creation
10231045
* of a new `SchemaUtilsType` with incomplete properties.
@@ -1034,6 +1056,7 @@ export interface SchemaUtilsType<T = any, S extends StrictRJSFSchema = RJSFSchem
10341056
experimental_defaultFormStateBehavior?: Experimental_DefaultFormStateBehavior,
10351057
experimental_customMergeAllOf?: Experimental_CustomMergeAllOf<S>
10361058
): boolean;
1059+
10371060
/** Returns the superset of `formData` that includes the given set updated to include any missing fields that have
10381061
* computed to have defaults provided in the `schema`.
10391062
*
@@ -1049,6 +1072,7 @@ export interface SchemaUtilsType<T = any, S extends StrictRJSFSchema = RJSFSchem
10491072
formData?: T,
10501073
includeUndefinedValues?: boolean | 'excludeObjectChildren'
10511074
): T | T[] | undefined;
1075+
10521076
/** Determines whether the combination of `schema` and `uiSchema` properties indicates that the label for the `schema`
10531077
* should be displayed in a UI.
10541078
*
@@ -1058,6 +1082,7 @@ export interface SchemaUtilsType<T = any, S extends StrictRJSFSchema = RJSFSchem
10581082
* @returns - True if the label should be displayed or false if it should not
10591083
*/
10601084
getDisplayLabel(schema: S, uiSchema?: UiSchema<T, S, F>, globalOptions?: GlobalUISchemaOptions): boolean;
1085+
10611086
/** Determines which of the given `options` provided most closely matches the `formData`.
10621087
* Returns the index of the option that is valid and is the closest match, or 0 if there is no match.
10631088
*
@@ -1077,6 +1102,7 @@ export interface SchemaUtilsType<T = any, S extends StrictRJSFSchema = RJSFSchem
10771102
selectedOption?: number,
10781103
discriminatorField?: string
10791104
): number;
1105+
10801106
/** Given the `formData` and list of `options`, attempts to find the index of the first option that matches the data.
10811107
* Always returns the first option if there is nothing that matches.
10821108
*
@@ -1087,6 +1113,7 @@ export interface SchemaUtilsType<T = any, S extends StrictRJSFSchema = RJSFSchem
10871113
* @returns - The firstindex of the matched option or 0 if none is available
10881114
*/
10891115
getFirstMatchingOption(formData: T | undefined, options: S[], discriminatorField?: string): number;
1116+
10901117
/** Given the `formData` and list of `options`, attempts to find the index of the option that best matches the data.
10911118
* Deprecated, use `getFirstMatchingOption()` instead.
10921119
*
@@ -1098,25 +1125,29 @@ export interface SchemaUtilsType<T = any, S extends StrictRJSFSchema = RJSFSchem
10981125
* @deprecated
10991126
*/
11001127
getMatchingOption(formData: T | undefined, options: S[], discriminatorField?: string): number;
1128+
11011129
/** Checks to see if the `schema` and `uiSchema` combination represents an array of files
11021130
*
11031131
* @param schema - The schema for which check for array of files flag is desired
11041132
* @param [uiSchema] - The UI schema from which to check the widget
11051133
* @returns - True if schema/uiSchema contains an array of files, otherwise false
11061134
*/
11071135
isFilesArray(schema: S, uiSchema?: UiSchema<T, S, F>): boolean;
1136+
11081137
/** Checks to see if the `schema` combination represents a multi-select
11091138
*
11101139
* @param schema - The schema for which check for a multi-select flag is desired
11111140
* @returns - True if schema contains a multi-select, otherwise false
11121141
*/
11131142
isMultiSelect(schema: S): boolean;
1143+
11141144
/** Checks to see if the `schema` combination represents a select
11151145
*
11161146
* @param schema - The schema for which check for a select flag is desired
11171147
* @returns - True if schema contains a select, otherwise false
11181148
*/
11191149
isSelect(schema: S): boolean;
1150+
11201151
/** Merges the errors in `additionalErrorSchema` into the existing `validationData` by combining the hierarchies in
11211152
* the two `ErrorSchema`s and then appending the error list from the `additionalErrorSchema` obtained by calling
11221153
* `validator.toErrorList()` onto the `errors` in the `validationData`. If no `additionalErrorSchema` is passed, then
@@ -1129,6 +1160,7 @@ export interface SchemaUtilsType<T = any, S extends StrictRJSFSchema = RJSFSchem
11291160
* removed in the next major release.
11301161
*/
11311162
mergeValidationData(validationData: ValidationData<T>, additionalErrorSchema?: ErrorSchema<T>): ValidationData<T>;
1163+
11321164
/** Retrieves an expanded schema that has had all of its conditions, additional properties, references and
11331165
* dependencies resolved and merged into the `schema` given a `rawFormData` that is used to do the potentially
11341166
* recursive resolution.
@@ -1138,6 +1170,7 @@ export interface SchemaUtilsType<T = any, S extends StrictRJSFSchema = RJSFSchem
11381170
* @returns - The schema having its conditions, additional properties, references and dependencies resolved
11391171
*/
11401172
retrieveSchema(schema: S, formData?: T): S;
1173+
11411174
/** Sanitize the `data` associated with the `oldSchema` so it is considered appropriate for the `newSchema`. If the
11421175
* new schema does not contain any properties, then `undefined` is returned to clear all the form data. Due to the
11431176
* nature of schemas, this sanitization happens recursively for nested objects of data. Also, any properties in the
@@ -1150,6 +1183,7 @@ export interface SchemaUtilsType<T = any, S extends StrictRJSFSchema = RJSFSchem
11501183
* to `undefined`. Will return `undefined` if the new schema is not an object containing properties.
11511184
*/
11521185
sanitizeDataForNewSchema(newSchema?: S, oldSchema?: S, data?: any): T;
1186+
11531187
/** Generates an `IdSchema` object for the `schema`, recursively
11541188
*
11551189
* @param schema - The schema for which the display label flag is desired
@@ -1160,6 +1194,7 @@ export interface SchemaUtilsType<T = any, S extends StrictRJSFSchema = RJSFSchem
11601194
* @returns - The `IdSchema` object for the `schema`
11611195
*/
11621196
toIdSchema(schema: S, id?: string, formData?: T, idPrefix?: string, idSeparator?: string): IdSchema<T>;
1197+
11631198
/** Generates an `PathSchema` object for the `schema`, recursively
11641199
*
11651200
* @param schema - The schema for which the display label flag is desired

0 commit comments

Comments
 (0)