@rjsf/utils 5.0.0-beta.8 → 5.0.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 +528 -197
- package/dist/utils.cjs.development.js +1285 -827
- package/dist/utils.cjs.development.js.map +1 -1
- package/dist/utils.cjs.production.min.js +1 -1
- package/dist/utils.cjs.production.min.js.map +1 -1
- package/dist/utils.esm.js +1263 -827
- package/dist/utils.esm.js.map +1 -1
- package/dist/utils.umd.development.js +1282 -831
- package/dist/utils.umd.development.js.map +1 -1
- package/dist/utils.umd.production.min.js +1 -1
- package/dist/utils.umd.production.min.js.map +1 -1
- package/package.json +12 -12
package/dist/index.d.ts
CHANGED
|
@@ -1,21 +1,23 @@
|
|
|
1
|
-
import React from 'react';
|
|
1
|
+
import React, { StyleHTMLAttributes } from 'react';
|
|
2
2
|
import * as json_schema from 'json-schema';
|
|
3
|
-
import { JSONSchema7
|
|
3
|
+
import { JSONSchema7 } from 'json-schema';
|
|
4
4
|
|
|
5
5
|
/** The representation of any generic object type, usually used as an intersection on other types to make them more
|
|
6
6
|
* flexible in the properties they support (i.e. anything else)
|
|
7
7
|
*/
|
|
8
|
-
|
|
8
|
+
type GenericObjectType = {
|
|
9
9
|
[name: string]: any;
|
|
10
10
|
};
|
|
11
|
-
/** Map the JSONSchema7 to our own type so that we can easily bump to
|
|
12
|
-
* update this one type.
|
|
11
|
+
/** Map the JSONSchema7 to our own type so that we can easily bump to a more recent version at some future date and only
|
|
12
|
+
* have to update this one type.
|
|
13
13
|
*/
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* date and only have to update this one type.
|
|
14
|
+
type StrictRJSFSchema = JSONSchema7;
|
|
15
|
+
/** Allow for more flexible schemas (i.e. draft-2019) than the strict JSONSchema7
|
|
17
16
|
*/
|
|
18
|
-
|
|
17
|
+
type RJSFSchema = StrictRJSFSchema & GenericObjectType;
|
|
18
|
+
/** Alias GenericObjectType as FormContextType to allow us to remap this at some future date
|
|
19
|
+
*/
|
|
20
|
+
type FormContextType = GenericObjectType;
|
|
19
21
|
/** The interface representing a Date object that contains an optional time */
|
|
20
22
|
interface DateObject {
|
|
21
23
|
/** The year of the Date */
|
|
@@ -32,7 +34,7 @@ interface DateObject {
|
|
|
32
34
|
second?: number;
|
|
33
35
|
}
|
|
34
36
|
/** Properties describing a Range specification in terms of attribute that can be added to the `HTML` `<input>` */
|
|
35
|
-
|
|
37
|
+
type RangeSpecType = {
|
|
36
38
|
/** Specifies the interval between legal numbers in an input field */
|
|
37
39
|
step?: number;
|
|
38
40
|
/** Specifies a minimum value for an <input> element */
|
|
@@ -41,7 +43,7 @@ declare type RangeSpecType = {
|
|
|
41
43
|
max?: number;
|
|
42
44
|
};
|
|
43
45
|
/** Properties describing a Range specification in terms of attribute that can be added to the `HTML` `<input>` */
|
|
44
|
-
|
|
46
|
+
type InputPropsType = Omit<RangeSpecType, "step"> & {
|
|
45
47
|
/** Specifies the type of the <input> element */
|
|
46
48
|
type: string;
|
|
47
49
|
/** Specifies the interval between legal numbers in an input field or "any" */
|
|
@@ -50,25 +52,25 @@ declare type InputPropsType = Omit<RangeSpecType, "step"> & {
|
|
|
50
52
|
autoComplete?: HTMLInputElement["autocomplete"];
|
|
51
53
|
};
|
|
52
54
|
/** Type describing an id used for a field in the `IdSchema` */
|
|
53
|
-
|
|
55
|
+
type FieldId = {
|
|
54
56
|
/** The id for a field */
|
|
55
57
|
$id: string;
|
|
56
58
|
};
|
|
57
59
|
/** Type describing a recursive structure of `FieldId`s for an object with a non-empty set of keys */
|
|
58
|
-
|
|
60
|
+
type IdSchema<T = any> = FieldId & {
|
|
59
61
|
[key in keyof T]?: IdSchema<T[key]>;
|
|
60
62
|
};
|
|
61
63
|
/** Type describing a name used for a field in the `PathSchema` */
|
|
62
|
-
|
|
64
|
+
type FieldPath = {
|
|
63
65
|
/** The name of a field */
|
|
64
66
|
$name: string;
|
|
65
67
|
};
|
|
66
68
|
/** Type describing a recursive structure of `FieldPath`s for an object with a non-empty set of keys */
|
|
67
|
-
|
|
69
|
+
type PathSchema<T = any> = FieldPath & {
|
|
68
70
|
[key in keyof T]?: PathSchema<T[key]>;
|
|
69
71
|
};
|
|
70
72
|
/** The type for error produced by RJSF schema validation */
|
|
71
|
-
|
|
73
|
+
type RJSFValidationError = {
|
|
72
74
|
/** Name of the error, for example, "required" or "minLength" */
|
|
73
75
|
name?: string;
|
|
74
76
|
/** Message, for example, "is a required property" or "should NOT be shorter than 3 characters" */
|
|
@@ -90,27 +92,27 @@ declare type RJSFValidationError = {
|
|
|
90
92
|
stack: string;
|
|
91
93
|
};
|
|
92
94
|
/** The type that describes an error in a field */
|
|
93
|
-
|
|
95
|
+
type FieldError = string;
|
|
94
96
|
/** The type that describes the list of errors for a field */
|
|
95
|
-
|
|
97
|
+
type FieldErrors = {
|
|
96
98
|
/** The list of errors for the field */
|
|
97
99
|
__errors?: FieldError[];
|
|
98
100
|
};
|
|
99
101
|
/** Type describing a recursive structure of `FieldErrors`s for an object with a non-empty set of keys */
|
|
100
|
-
|
|
102
|
+
type ErrorSchema<T = any> = FieldErrors & {
|
|
101
103
|
[key in keyof T]?: ErrorSchema<T[key]>;
|
|
102
104
|
};
|
|
103
105
|
/** Type that describes the list of errors for a field being actively validated by a custom validator */
|
|
104
|
-
|
|
106
|
+
type FieldValidation = FieldErrors & {
|
|
105
107
|
/** Function that will add a new `message` to the list of errors */
|
|
106
108
|
addError: (message: string) => void;
|
|
107
109
|
};
|
|
108
110
|
/** Type describing a recursive structure of `FieldValidation`s for an object with a non-empty set of keys */
|
|
109
|
-
|
|
111
|
+
type FormValidation<T = any> = FieldValidation & {
|
|
110
112
|
[key in keyof T]?: FormValidation<T[key]>;
|
|
111
113
|
};
|
|
112
114
|
/** The properties that are passed to an `ErrorListTemplate` implementation */
|
|
113
|
-
|
|
115
|
+
type ErrorListProps<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any> = {
|
|
114
116
|
/** The errorSchema constructed by `Form` */
|
|
115
117
|
errorSchema: ErrorSchema<T>;
|
|
116
118
|
/** An array of the errors */
|
|
@@ -118,131 +120,133 @@ declare type ErrorListProps<T = any, F = any> = {
|
|
|
118
120
|
/** The `formContext` object that was passed to `Form` */
|
|
119
121
|
formContext?: F;
|
|
120
122
|
/** The schema that was passed to `Form` */
|
|
121
|
-
schema:
|
|
123
|
+
schema: S;
|
|
122
124
|
/** The uiSchema that was passed to `Form` */
|
|
123
|
-
uiSchema?: UiSchema<T, F>;
|
|
125
|
+
uiSchema?: UiSchema<T, S, F>;
|
|
124
126
|
};
|
|
125
127
|
/** The properties that are passed to an `FieldErrorTemplate` implementation */
|
|
126
|
-
|
|
128
|
+
type FieldErrorProps<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any> = {
|
|
127
129
|
/** The errorSchema constructed by `Form` */
|
|
128
130
|
errorSchema?: ErrorSchema<T>;
|
|
129
131
|
/** An array of the errors */
|
|
130
|
-
errors?: string
|
|
132
|
+
errors?: Array<string | React.ReactElement>;
|
|
131
133
|
/** The tree of unique ids for every child field */
|
|
132
134
|
idSchema: IdSchema<T>;
|
|
133
135
|
/** The schema that was passed to field */
|
|
134
|
-
schema:
|
|
136
|
+
schema: S;
|
|
135
137
|
/** The uiSchema that was passed to field */
|
|
136
|
-
uiSchema?: UiSchema<T, F>;
|
|
138
|
+
uiSchema?: UiSchema<T, S, F>;
|
|
137
139
|
/** The `registry` object */
|
|
138
|
-
registry: Registry<T, F>;
|
|
140
|
+
registry: Registry<T, S, F>;
|
|
139
141
|
};
|
|
140
142
|
/** The properties that are passed to an `FieldHelpTemplate` implementation */
|
|
141
|
-
|
|
143
|
+
type FieldHelpProps<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any> = {
|
|
142
144
|
/** The help information to be rendered */
|
|
143
145
|
help?: string | React.ReactElement;
|
|
144
146
|
/** The tree of unique ids for every child field */
|
|
145
147
|
idSchema: IdSchema<T>;
|
|
146
148
|
/** The schema that was passed to field */
|
|
147
|
-
schema:
|
|
149
|
+
schema: S;
|
|
148
150
|
/** The uiSchema that was passed to field */
|
|
149
|
-
uiSchema?: UiSchema<T, F>;
|
|
151
|
+
uiSchema?: UiSchema<T, S, F>;
|
|
150
152
|
/** Flag indicating whether there are errors associated with this field */
|
|
151
153
|
hasErrors?: boolean;
|
|
152
154
|
/** The `registry` object */
|
|
153
|
-
registry: Registry<T, F>;
|
|
155
|
+
registry: Registry<T, S, F>;
|
|
154
156
|
};
|
|
155
157
|
/** The set of `Fields` stored in the `Registry` */
|
|
156
|
-
|
|
158
|
+
type RegistryFieldsType<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any> = {
|
|
157
159
|
/** A `Field` indexed by `name` */
|
|
158
|
-
[name: string]: Field<T, F>;
|
|
160
|
+
[name: string]: Field<T, S, F>;
|
|
159
161
|
};
|
|
160
162
|
/** The set of `Widgets` stored in the `Registry` */
|
|
161
|
-
|
|
163
|
+
type RegistryWidgetsType<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any> = {
|
|
162
164
|
/** A `Widget` indexed by `name` */
|
|
163
|
-
[name: string]: Widget<T, F>;
|
|
165
|
+
[name: string]: Widget<T, S, F>;
|
|
164
166
|
};
|
|
165
167
|
/** The set of RJSF templates that can be overridden by themes or users */
|
|
166
|
-
interface TemplatesType<T = any, F = any> {
|
|
168
|
+
interface TemplatesType<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any> {
|
|
167
169
|
/** The template to use while rendering normal or fixed array fields */
|
|
168
|
-
ArrayFieldTemplate: React.ComponentType<ArrayFieldTemplateProps<T, F>>;
|
|
170
|
+
ArrayFieldTemplate: React.ComponentType<ArrayFieldTemplateProps<T, S, F>>;
|
|
169
171
|
/** The template to use while rendering the description for an array field */
|
|
170
|
-
ArrayFieldDescriptionTemplate: React.ComponentType<ArrayFieldDescriptionProps<T, F>>;
|
|
172
|
+
ArrayFieldDescriptionTemplate: React.ComponentType<ArrayFieldDescriptionProps<T, S, F>>;
|
|
171
173
|
/** The template to use while rendering an item in an array field */
|
|
172
|
-
ArrayFieldItemTemplate: React.ComponentType<ArrayFieldTemplateItemType<T, F>>;
|
|
174
|
+
ArrayFieldItemTemplate: React.ComponentType<ArrayFieldTemplateItemType<T, S, F>>;
|
|
173
175
|
/** The template to use while rendering the title for an array field */
|
|
174
|
-
ArrayFieldTitleTemplate: React.ComponentType<ArrayFieldTitleProps<T, F>>;
|
|
176
|
+
ArrayFieldTitleTemplate: React.ComponentType<ArrayFieldTitleProps<T, S, F>>;
|
|
175
177
|
/** The template to use while rendering the standard html input */
|
|
176
|
-
BaseInputTemplate: React.ComponentType<WidgetProps<T, F>>;
|
|
178
|
+
BaseInputTemplate: React.ComponentType<WidgetProps<T, S, F>>;
|
|
177
179
|
/** The template to use for rendering the description of a field */
|
|
178
|
-
DescriptionFieldTemplate: React.ComponentType<DescriptionFieldProps<T, F>>;
|
|
180
|
+
DescriptionFieldTemplate: React.ComponentType<DescriptionFieldProps<T, S, F>>;
|
|
179
181
|
/** The template to use while rendering the errors for the whole form */
|
|
180
|
-
ErrorListTemplate: React.ComponentType<ErrorListProps<T, F>>;
|
|
182
|
+
ErrorListTemplate: React.ComponentType<ErrorListProps<T, S, F>>;
|
|
181
183
|
/** The template to use while rendering the errors for a single field */
|
|
182
|
-
FieldErrorTemplate: React.ComponentType<FieldErrorProps<T, F>>;
|
|
184
|
+
FieldErrorTemplate: React.ComponentType<FieldErrorProps<T, S, F>>;
|
|
183
185
|
/** The template to use while rendering the errors for a single field */
|
|
184
|
-
FieldHelpTemplate: React.ComponentType<FieldHelpProps<T, F>>;
|
|
186
|
+
FieldHelpTemplate: React.ComponentType<FieldHelpProps<T, S, F>>;
|
|
185
187
|
/** The template to use while rendering a field */
|
|
186
|
-
FieldTemplate: React.ComponentType<FieldTemplateProps<T, F>>;
|
|
188
|
+
FieldTemplate: React.ComponentType<FieldTemplateProps<T, S, F>>;
|
|
187
189
|
/** The template to use while rendering an object */
|
|
188
|
-
ObjectFieldTemplate: React.ComponentType<ObjectFieldTemplateProps<T, F>>;
|
|
190
|
+
ObjectFieldTemplate: React.ComponentType<ObjectFieldTemplateProps<T, S, F>>;
|
|
189
191
|
/** The template to use for rendering the title of a field */
|
|
190
|
-
TitleFieldTemplate: React.ComponentType<TitleFieldProps<T, F>>;
|
|
192
|
+
TitleFieldTemplate: React.ComponentType<TitleFieldProps<T, S, F>>;
|
|
191
193
|
/** The template to use for rendering information about an unsupported field type in the schema */
|
|
192
|
-
UnsupportedFieldTemplate: React.ComponentType<UnsupportedFieldProps<T, F>>;
|
|
194
|
+
UnsupportedFieldTemplate: React.ComponentType<UnsupportedFieldProps<T, S, F>>;
|
|
195
|
+
/** The template to use for rendering a field that allows a user to add additional properties */
|
|
196
|
+
WrapIfAdditionalTemplate: React.ComponentType<WrapIfAdditionalTemplateProps<T, S, F>>;
|
|
193
197
|
/** The set of templates associated with buttons in the form */
|
|
194
198
|
ButtonTemplates: {
|
|
195
199
|
/** The template to use for the main `Submit` button */
|
|
196
|
-
SubmitButton: React.ComponentType<SubmitButtonProps<T, F>>;
|
|
200
|
+
SubmitButton: React.ComponentType<SubmitButtonProps<T, S, F>>;
|
|
197
201
|
/** The template to use for the Add button used for AdditionalProperties and Array items */
|
|
198
|
-
AddButton: React.ComponentType<IconButtonProps
|
|
202
|
+
AddButton: React.ComponentType<IconButtonProps<T, S, F>>;
|
|
199
203
|
/** The template to use for the Move Down button used for Array items */
|
|
200
|
-
MoveDownButton: React.ComponentType<IconButtonProps
|
|
204
|
+
MoveDownButton: React.ComponentType<IconButtonProps<T, S, F>>;
|
|
201
205
|
/** The template to use for the Move Up button used for Array items */
|
|
202
|
-
MoveUpButton: React.ComponentType<IconButtonProps
|
|
206
|
+
MoveUpButton: React.ComponentType<IconButtonProps<T, S, F>>;
|
|
203
207
|
/** The template to use for the Remove button used for AdditionalProperties and Array items */
|
|
204
|
-
RemoveButton: React.ComponentType<IconButtonProps
|
|
208
|
+
RemoveButton: React.ComponentType<IconButtonProps<T, S, F>>;
|
|
205
209
|
};
|
|
206
210
|
}
|
|
207
211
|
/** The object containing the registered core, theme and custom fields and widgets as well as the root schema, form
|
|
208
212
|
* context, schema utils and templates.
|
|
209
213
|
*/
|
|
210
|
-
interface Registry<T = any, F = any> {
|
|
214
|
+
interface Registry<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any> {
|
|
211
215
|
/** The set of all fields used by the `Form`. Includes fields from `core`, theme-specific fields and any custom
|
|
212
216
|
* registered fields
|
|
213
217
|
*/
|
|
214
|
-
fields: RegistryFieldsType<T, F>;
|
|
218
|
+
fields: RegistryFieldsType<T, S, F>;
|
|
215
219
|
/** The set of templates used by the `Form`. Includes templates from `core`, theme-specific fields and any custom
|
|
216
220
|
* registered templates
|
|
217
221
|
*/
|
|
218
|
-
templates: TemplatesType<T, F>;
|
|
222
|
+
templates: TemplatesType<T, S, F>;
|
|
219
223
|
/** The set of all widgets used by the `Form`. Includes widgets from `core`, theme-specific widgets and any custom
|
|
220
224
|
* registered widgets
|
|
221
225
|
*/
|
|
222
|
-
widgets: RegistryWidgetsType<T, F>;
|
|
226
|
+
widgets: RegistryWidgetsType<T, S, F>;
|
|
223
227
|
/** The `formContext` object that was passed to `Form` */
|
|
224
228
|
formContext: F;
|
|
225
229
|
/** The root schema, as passed to the `Form`, which can contain referenced definitions */
|
|
226
|
-
rootSchema:
|
|
230
|
+
rootSchema: S;
|
|
227
231
|
/** The current implementation of the `SchemaUtilsType` (from `@rjsf/utils`) in use by the `Form`. Used to call any
|
|
228
232
|
* of the validation-schema-based utility functions
|
|
229
233
|
*/
|
|
230
|
-
schemaUtils: SchemaUtilsType<T>;
|
|
234
|
+
schemaUtils: SchemaUtilsType<T, S>;
|
|
231
235
|
}
|
|
232
236
|
/** The properties that are passed to a Field implementation */
|
|
233
|
-
interface FieldProps<T = any, F = any> extends GenericObjectType, Pick<React.HTMLAttributes<HTMLElement>, Exclude<keyof React.HTMLAttributes<HTMLElement>, "onBlur" | "onFocus" | "onChange">> {
|
|
237
|
+
interface FieldProps<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any> extends GenericObjectType, Pick<React.HTMLAttributes<HTMLElement>, Exclude<keyof React.HTMLAttributes<HTMLElement>, "onBlur" | "onFocus" | "onChange">> {
|
|
234
238
|
/** The JSON subschema object for this field */
|
|
235
|
-
schema:
|
|
239
|
+
schema: S;
|
|
236
240
|
/** The uiSchema for this field */
|
|
237
|
-
uiSchema?: UiSchema<T, F>;
|
|
241
|
+
uiSchema?: UiSchema<T, S, F>;
|
|
238
242
|
/** The tree of unique ids for every child field */
|
|
239
243
|
idSchema: IdSchema<T>;
|
|
240
244
|
/** The data for this field */
|
|
241
|
-
formData
|
|
245
|
+
formData?: T;
|
|
242
246
|
/** The tree of errors for this field and its children */
|
|
243
247
|
errorSchema?: ErrorSchema<T>;
|
|
244
248
|
/** The field change event handler; called with the updated form data and an optional `ErrorSchema` */
|
|
245
|
-
onChange: (newFormData: T, es?: ErrorSchema<T
|
|
249
|
+
onChange: (newFormData: T | undefined, es?: ErrorSchema<T>, id?: string) => any;
|
|
246
250
|
/** The input blur event handler; call it with the field id and value */
|
|
247
251
|
onBlur: (id: string, value: any) => void;
|
|
248
252
|
/** The input focus event handler; call it with the field id and value */
|
|
@@ -262,16 +266,18 @@ interface FieldProps<T = any, F = any> extends GenericObjectType, Pick<React.HTM
|
|
|
262
266
|
/** The unique name of the field, usually derived from the name of the property in the JSONSchema */
|
|
263
267
|
name: string;
|
|
264
268
|
/** The `registry` object */
|
|
265
|
-
registry: Registry<T, F>;
|
|
269
|
+
registry: Registry<T, S, F>;
|
|
266
270
|
}
|
|
267
271
|
/** The definition of a React-based Field component */
|
|
268
|
-
|
|
272
|
+
type Field<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any> = React.ComponentType<FieldProps<T, S, F>>;
|
|
269
273
|
/** The properties that are passed to a FieldTemplate implementation */
|
|
270
|
-
|
|
274
|
+
type FieldTemplateProps<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any> = {
|
|
271
275
|
/** The id of the field in the hierarchy. You can use it to render a label targeting the wrapped widget */
|
|
272
276
|
id: string;
|
|
273
277
|
/** A string containing the base CSS classes, merged with any custom ones defined in your uiSchema */
|
|
274
278
|
classNames?: string;
|
|
279
|
+
/** An object containing the style as defined in the `uiSchema` */
|
|
280
|
+
style?: StyleHTMLAttributes<any>;
|
|
275
281
|
/** The computed label for this field, as a string */
|
|
276
282
|
label: string;
|
|
277
283
|
/** A component instance rendering the field description, if one is defined (this will use any custom
|
|
@@ -307,75 +313,85 @@ declare type FieldTemplateProps<T = any, F = any> = {
|
|
|
307
313
|
*/
|
|
308
314
|
displayLabel?: boolean;
|
|
309
315
|
/** The schema object for this field */
|
|
310
|
-
schema:
|
|
316
|
+
schema: S;
|
|
311
317
|
/** The uiSchema object for this field */
|
|
312
|
-
uiSchema?: UiSchema<T, F>;
|
|
318
|
+
uiSchema?: UiSchema<T, S, F>;
|
|
313
319
|
/** The `formContext` object that was passed to `Form` */
|
|
314
320
|
formContext?: F;
|
|
315
321
|
/** The formData for this field */
|
|
316
|
-
formData
|
|
322
|
+
formData?: T;
|
|
317
323
|
/** The value change event handler; Can be called with a new value to change the value for this field */
|
|
318
|
-
onChange:
|
|
324
|
+
onChange: FieldProps["onChange"];
|
|
319
325
|
/** The key change event handler; Called when the key associated with a field is changed for an additionalProperty */
|
|
320
326
|
onKeyChange: (value: string) => () => void;
|
|
321
327
|
/** The property drop/removal event handler; Called when a field is removed in an additionalProperty context */
|
|
322
328
|
onDropPropertyClick: (value: string) => () => void;
|
|
323
329
|
/** The `registry` object */
|
|
324
|
-
registry: Registry<T, F>;
|
|
330
|
+
registry: Registry<T, S, F>;
|
|
325
331
|
};
|
|
326
332
|
/** The properties that are passed to the `UnsupportedFieldTemplate` implementation */
|
|
327
|
-
|
|
333
|
+
type UnsupportedFieldProps<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any> = {
|
|
328
334
|
/** The schema object for this field */
|
|
329
|
-
schema:
|
|
335
|
+
schema: S;
|
|
330
336
|
/** The tree of unique ids for every child field */
|
|
331
337
|
idSchema?: IdSchema<T>;
|
|
332
338
|
/** The reason why the schema field has an unsupported type */
|
|
333
339
|
reason: string;
|
|
334
340
|
/** The `registry` object */
|
|
335
|
-
registry: Registry<T, F>;
|
|
341
|
+
registry: Registry<T, S, F>;
|
|
336
342
|
};
|
|
337
343
|
/** The properties that are passed to a `TitleFieldTemplate` implementation */
|
|
338
|
-
|
|
344
|
+
type TitleFieldProps<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any> = {
|
|
339
345
|
/** The id of the field title in the hierarchy */
|
|
340
346
|
id: string;
|
|
341
347
|
/** The title for the field being rendered */
|
|
342
348
|
title: string;
|
|
349
|
+
/** The schema object for the field being titled */
|
|
350
|
+
schema: S;
|
|
343
351
|
/** The uiSchema object for this title field */
|
|
344
|
-
uiSchema?: UiSchema<T, F>;
|
|
352
|
+
uiSchema?: UiSchema<T, S, F>;
|
|
345
353
|
/** A boolean value stating if the field is required */
|
|
346
354
|
required?: boolean;
|
|
347
355
|
/** The `registry` object */
|
|
348
|
-
registry: Registry<T, F>;
|
|
356
|
+
registry: Registry<T, S, F>;
|
|
349
357
|
};
|
|
350
358
|
/** The properties that are passed to a `DescriptionFieldTemplate` implementation */
|
|
351
|
-
|
|
359
|
+
type DescriptionFieldProps<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any> = {
|
|
352
360
|
/** The id of the field description in the hierarchy */
|
|
353
361
|
id: string;
|
|
362
|
+
/** The schema object for the field being described */
|
|
363
|
+
schema: S;
|
|
364
|
+
/** The uiSchema object for this description field */
|
|
365
|
+
uiSchema?: UiSchema<T, S, F>;
|
|
354
366
|
/** The description of the field being rendered */
|
|
355
367
|
description: string | React.ReactElement;
|
|
356
368
|
/** The `registry` object */
|
|
357
|
-
registry: Registry<T, F>;
|
|
369
|
+
registry: Registry<T, S, F>;
|
|
358
370
|
};
|
|
359
371
|
/** The properties that are passed to a `ArrayFieldTitleTemplate` implementation */
|
|
360
|
-
|
|
372
|
+
type ArrayFieldTitleProps<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any> = Omit<TitleFieldProps<T, S, F>, "id" | "title"> & {
|
|
373
|
+
/** The title for the field being rendered */
|
|
374
|
+
title?: string;
|
|
361
375
|
/** The idSchema of the field in the hierarchy */
|
|
362
376
|
idSchema: IdSchema<T>;
|
|
363
377
|
};
|
|
364
378
|
/** The properties that are passed to a `ArrayFieldDescriptionTemplate` implementation */
|
|
365
|
-
|
|
379
|
+
type ArrayFieldDescriptionProps<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any> = Omit<DescriptionFieldProps<T, S, F>, "id" | "description"> & {
|
|
380
|
+
/** The description of the field being rendered */
|
|
381
|
+
description?: string | React.ReactElement;
|
|
366
382
|
/** The idSchema of the field in the hierarchy */
|
|
367
383
|
idSchema: IdSchema<T>;
|
|
368
|
-
/** The uiSchema object for this description field */
|
|
369
|
-
uiSchema?: UiSchema<T, F>;
|
|
370
384
|
};
|
|
371
385
|
/** The properties of each element in the ArrayFieldTemplateProps.items array */
|
|
372
|
-
|
|
386
|
+
type ArrayFieldTemplateItemType<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any> = {
|
|
373
387
|
/** The html for the item's content */
|
|
374
388
|
children: React.ReactElement;
|
|
375
389
|
/** The className string */
|
|
376
390
|
className: string;
|
|
377
391
|
/** A boolean value stating if the array item is disabled */
|
|
378
392
|
disabled: boolean;
|
|
393
|
+
/** A boolean value stating whether new items can be added to the array */
|
|
394
|
+
canAdd: boolean;
|
|
379
395
|
/** A boolean value stating whether the array item can be moved down */
|
|
380
396
|
hasMoveDown: boolean;
|
|
381
397
|
/** A boolean value stating whether the array item can be moved up */
|
|
@@ -386,6 +402,8 @@ declare type ArrayFieldTemplateItemType<T = any, F = any> = {
|
|
|
386
402
|
hasToolbar: boolean;
|
|
387
403
|
/** A number stating the index the array item occurs in `items` */
|
|
388
404
|
index: number;
|
|
405
|
+
/** A number stating the total number `items` in the array */
|
|
406
|
+
totalItems: number;
|
|
389
407
|
/** Returns a function that adds a new item at `index` */
|
|
390
408
|
onAddIndexClick: (index: number) => (event?: any) => void;
|
|
391
409
|
/** Returns a function that removes the item at `index` */
|
|
@@ -396,11 +414,15 @@ declare type ArrayFieldTemplateItemType<T = any, F = any> = {
|
|
|
396
414
|
readonly: boolean;
|
|
397
415
|
/** A stable, unique key for the array item */
|
|
398
416
|
key: string;
|
|
417
|
+
/** The schema object for this array item */
|
|
418
|
+
schema: S;
|
|
419
|
+
/** The uiSchema object for this array item */
|
|
420
|
+
uiSchema?: UiSchema<T, S, F>;
|
|
399
421
|
/** The `registry` object */
|
|
400
|
-
registry: Registry<T, F>;
|
|
422
|
+
registry: Registry<T, S, F>;
|
|
401
423
|
};
|
|
402
424
|
/** The properties that are passed to an ArrayFieldTemplate implementation */
|
|
403
|
-
|
|
425
|
+
type ArrayFieldTemplateProps<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any> = {
|
|
404
426
|
/** A boolean value stating whether new elements can be added to the array */
|
|
405
427
|
canAdd?: boolean;
|
|
406
428
|
/** The className string */
|
|
@@ -410,7 +432,7 @@ declare type ArrayFieldTemplateProps<T = any, F = any> = {
|
|
|
410
432
|
/** An object containing the id for this object & ids for its properties */
|
|
411
433
|
idSchema: IdSchema<T>;
|
|
412
434
|
/** An array of objects representing the items in the array */
|
|
413
|
-
items: ArrayFieldTemplateItemType<T, F>[];
|
|
435
|
+
items: ArrayFieldTemplateItemType<T, S, F>[];
|
|
414
436
|
/** A function that adds a new item to the array */
|
|
415
437
|
onAddClick: (event?: any) => void;
|
|
416
438
|
/** A boolean value stating if the array is read-only */
|
|
@@ -420,22 +442,22 @@ declare type ArrayFieldTemplateProps<T = any, F = any> = {
|
|
|
420
442
|
/** A boolean value stating if the field is hiding its errors */
|
|
421
443
|
hideError?: boolean;
|
|
422
444
|
/** The schema object for this array */
|
|
423
|
-
schema:
|
|
445
|
+
schema: S;
|
|
424
446
|
/** The uiSchema object for this array field */
|
|
425
|
-
uiSchema?: UiSchema<T, F>;
|
|
447
|
+
uiSchema?: UiSchema<T, S, F>;
|
|
426
448
|
/** A string value containing the title for the array */
|
|
427
449
|
title: string;
|
|
428
450
|
/** The `formContext` object that was passed to Form */
|
|
429
451
|
formContext?: F;
|
|
430
452
|
/** The formData for this array */
|
|
431
|
-
formData
|
|
453
|
+
formData?: T;
|
|
432
454
|
/** An array of strings listing all generated error messages from encountered errors for this widget */
|
|
433
455
|
rawErrors?: string[];
|
|
434
456
|
/** The `registry` object */
|
|
435
|
-
registry: Registry<T, F>;
|
|
457
|
+
registry: Registry<T, S, F>;
|
|
436
458
|
};
|
|
437
459
|
/** The properties of each element in the ObjectFieldTemplateProps.properties array */
|
|
438
|
-
|
|
460
|
+
type ObjectFieldTemplatePropertyType = {
|
|
439
461
|
/** The html for the property's content */
|
|
440
462
|
content: React.ReactElement;
|
|
441
463
|
/** A string representing the property name */
|
|
@@ -448,7 +470,7 @@ declare type ObjectFieldTemplatePropertyType = {
|
|
|
448
470
|
hidden: boolean;
|
|
449
471
|
};
|
|
450
472
|
/** The properties that are passed to an ObjectFieldTemplate implementation */
|
|
451
|
-
|
|
473
|
+
type ObjectFieldTemplateProps<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any> = {
|
|
452
474
|
/** A string value containing the title for the object */
|
|
453
475
|
title: string;
|
|
454
476
|
/** A string value containing the description for the object */
|
|
@@ -458,7 +480,7 @@ declare type ObjectFieldTemplateProps<T = any, F = any> = {
|
|
|
458
480
|
/** An array of objects representing the properties in the object */
|
|
459
481
|
properties: ObjectFieldTemplatePropertyType[];
|
|
460
482
|
/** Returns a function that adds a new property to the object (to be used with additionalProperties) */
|
|
461
|
-
onAddClick: (schema:
|
|
483
|
+
onAddClick: (schema: S) => () => void;
|
|
462
484
|
/** A boolean value stating if the object is read-only */
|
|
463
485
|
readonly?: boolean;
|
|
464
486
|
/** A boolean value stating if the object is required */
|
|
@@ -466,26 +488,31 @@ declare type ObjectFieldTemplateProps<T = any, F = any> = {
|
|
|
466
488
|
/** A boolean value stating if the field is hiding its errors */
|
|
467
489
|
hideError?: boolean;
|
|
468
490
|
/** The schema object for this object */
|
|
469
|
-
schema:
|
|
491
|
+
schema: S;
|
|
470
492
|
/** The uiSchema object for this object field */
|
|
471
|
-
uiSchema?: UiSchema<T, F>;
|
|
493
|
+
uiSchema?: UiSchema<T, S, F>;
|
|
472
494
|
/** An object containing the id for this object & ids for its properties */
|
|
473
495
|
idSchema: IdSchema<T>;
|
|
474
496
|
/** The form data for the object */
|
|
475
|
-
formData
|
|
497
|
+
formData?: T;
|
|
476
498
|
/** The `formContext` object that was passed to Form */
|
|
477
499
|
formContext?: F;
|
|
478
500
|
/** The `registry` object */
|
|
479
|
-
registry: Registry<T, F>;
|
|
501
|
+
registry: Registry<T, S, F>;
|
|
480
502
|
};
|
|
503
|
+
/** The properties that are passed to a WrapIfAdditionalTemplate implementation */
|
|
504
|
+
type WrapIfAdditionalTemplateProps<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any> = {
|
|
505
|
+
/** The field or widget component instance for this field row */
|
|
506
|
+
children: React.ReactNode;
|
|
507
|
+
} & Pick<FieldTemplateProps<T, S, F>, "id" | "classNames" | "style" | "label" | "required" | "readonly" | "disabled" | "schema" | "uiSchema" | "onKeyChange" | "onDropPropertyClick" | "registry">;
|
|
481
508
|
/** The properties that are passed to a Widget implementation */
|
|
482
|
-
interface WidgetProps<T = any, F = any> extends GenericObjectType, Pick<React.HTMLAttributes<HTMLElement>, Exclude<keyof React.HTMLAttributes<HTMLElement>, "onBlur" | "onFocus">> {
|
|
509
|
+
interface WidgetProps<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any> extends GenericObjectType, Pick<React.HTMLAttributes<HTMLElement>, Exclude<keyof React.HTMLAttributes<HTMLElement>, "onBlur" | "onFocus">> {
|
|
483
510
|
/** The generated id for this widget */
|
|
484
511
|
id: string;
|
|
485
512
|
/** The JSONSchema subschema object for this widget */
|
|
486
|
-
schema:
|
|
513
|
+
schema: S;
|
|
487
514
|
/** The uiSchema for this widget */
|
|
488
|
-
uiSchema?: UiSchema<T, F>;
|
|
515
|
+
uiSchema?: UiSchema<T, S, F>;
|
|
489
516
|
/** The current value for this widget */
|
|
490
517
|
value: any;
|
|
491
518
|
/** The required status of this widget */
|
|
@@ -503,9 +530,9 @@ interface WidgetProps<T = any, F = any> extends GenericObjectType, Pick<React.HT
|
|
|
503
530
|
/** A map of UI Options passed as a prop to the component, including the optional `enumOptions`
|
|
504
531
|
* which is a special case on top of `UIOptionsType` needed only by widgets
|
|
505
532
|
*/
|
|
506
|
-
options: NonNullable<UIOptionsType<T, F>> & {
|
|
533
|
+
options: NonNullable<UIOptionsType<T, S, F>> & {
|
|
507
534
|
/** The enum options list for a type that supports them */
|
|
508
|
-
enumOptions?: EnumOptionsType[];
|
|
535
|
+
enumOptions?: EnumOptionsType<S>[];
|
|
509
536
|
};
|
|
510
537
|
/** The `formContext` object that you passed to `Form` */
|
|
511
538
|
formContext?: F;
|
|
@@ -522,24 +549,30 @@ interface WidgetProps<T = any, F = any> extends GenericObjectType, Pick<React.HT
|
|
|
522
549
|
/** An array of strings listing all generated error messages from encountered errors for this widget */
|
|
523
550
|
rawErrors?: string[];
|
|
524
551
|
/** The `registry` object */
|
|
525
|
-
registry: Registry<T, F>;
|
|
552
|
+
registry: Registry<T, S, F>;
|
|
526
553
|
}
|
|
527
554
|
/** The definition of a React-based Widget component */
|
|
528
|
-
|
|
555
|
+
type Widget<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any> = React.ComponentType<WidgetProps<T, S, F>>;
|
|
529
556
|
/** The type that defines the props used by the Submit button */
|
|
530
|
-
|
|
557
|
+
type SubmitButtonProps<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any> = {
|
|
531
558
|
/** The uiSchema for this widget */
|
|
532
|
-
uiSchema?: UiSchema<T, F>;
|
|
559
|
+
uiSchema?: UiSchema<T, S, F>;
|
|
560
|
+
/** The `registry` object */
|
|
561
|
+
registry: Registry<T, S, F>;
|
|
533
562
|
};
|
|
534
563
|
/** The type that defines the props for an Icon button, extending from a basic HTML button attributes */
|
|
535
|
-
|
|
564
|
+
type IconButtonProps<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any> = React.ButtonHTMLAttributes<HTMLButtonElement> & {
|
|
536
565
|
/** An alternative specification for the type of the icon button */
|
|
537
566
|
iconType?: string;
|
|
538
567
|
/** The name representation or actual react element implementation for the icon */
|
|
539
568
|
icon?: string | React.ReactElement;
|
|
569
|
+
/** The uiSchema for this widget */
|
|
570
|
+
uiSchema?: UiSchema<T, S, F>;
|
|
571
|
+
/** The `registry` object */
|
|
572
|
+
registry: Registry<T, S, F>;
|
|
540
573
|
};
|
|
541
574
|
/** The type that defines how to change the behavior of the submit button for the form */
|
|
542
|
-
|
|
575
|
+
type UISchemaSubmitButtonOptions = {
|
|
543
576
|
/** The text of the submit button. Set to "Submit" by default */
|
|
544
577
|
submitText?: string;
|
|
545
578
|
/** Flag, if `true`, removes the submit button completely from the form */
|
|
@@ -553,24 +586,26 @@ declare type UISchemaSubmitButtonOptions = {
|
|
|
553
586
|
};
|
|
554
587
|
};
|
|
555
588
|
/** This type represents an element used to render an enum option */
|
|
556
|
-
|
|
589
|
+
type EnumOptionsType<S extends StrictRJSFSchema = RJSFSchema> = {
|
|
557
590
|
/** The value for the enum option */
|
|
558
591
|
value: any;
|
|
559
592
|
/** The label for the enum options */
|
|
560
593
|
label: string;
|
|
561
594
|
/** The schema associated with the enum option when the option represents a `oneOf` or `anyOf` choice */
|
|
562
|
-
schema?:
|
|
595
|
+
schema?: S;
|
|
563
596
|
};
|
|
564
597
|
/** This type remaps the keys of `Type` to prepend `ui:` onto them. As a result it does not need to be exported */
|
|
565
|
-
|
|
598
|
+
type MakeUIType<Type> = {
|
|
566
599
|
[Property in keyof Type as `ui:${string & Property}`]: Type[Property];
|
|
567
600
|
};
|
|
568
601
|
/** This type represents all the known supported options in the `ui:options` property, kept separate in order to
|
|
569
602
|
* remap the keys. It also contains all the properties, optionally, of `TemplatesType` except "ButtonTemplates"
|
|
570
603
|
*/
|
|
571
|
-
|
|
604
|
+
type UIOptionsBaseType<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any> = Partial<Omit<TemplatesType<T, S, F>, "ButtonTemplates">> & {
|
|
572
605
|
/** Any classnames that the user wants to be applied to a field in the ui */
|
|
573
606
|
classNames?: string;
|
|
607
|
+
/** Any custom style that the user wants to apply to a field in the ui, applied on the same element as classNames */
|
|
608
|
+
style?: StyleHTMLAttributes<any>;
|
|
574
609
|
/** We know that for title, it will be a string, if it is provided */
|
|
575
610
|
title?: string;
|
|
576
611
|
/** We know that for description, it will be a string, if it is provided */
|
|
@@ -616,40 +651,48 @@ declare type UIOptionsBaseType<T = any, F = any> = Partial<Omit<TemplatesType<T,
|
|
|
616
651
|
/** Allows RJSF to override the default widget implementation by specifying either the name of a widget that is used
|
|
617
652
|
* to look up an implementation from the `widgets` list or an actual one-off widget implementation itself
|
|
618
653
|
*/
|
|
619
|
-
widget?: Widget<T, F> | string;
|
|
654
|
+
widget?: Widget<T, S, F> | string;
|
|
620
655
|
/** When using `additionalProperties`, key collision is prevented by appending a unique integer to the duplicate key.
|
|
621
656
|
* This option allows you to change the separator between the original key name and the integer. Default is "-"
|
|
622
657
|
*/
|
|
623
658
|
duplicateKeySuffixSeparator?: string;
|
|
624
659
|
};
|
|
625
660
|
/** The type that represents the Options potentially provided by `ui:options` */
|
|
626
|
-
|
|
661
|
+
type UIOptionsType<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any> = UIOptionsBaseType<T, S, F> & {
|
|
627
662
|
/** Anything else will be one of these types */
|
|
628
663
|
[key: string]: boolean | number | string | object | any[] | null | undefined;
|
|
629
664
|
};
|
|
630
665
|
/** Type describing the well-known properties of the `UiSchema` while also supporting all user defined properties,
|
|
631
666
|
* starting with `ui:`.
|
|
632
667
|
*/
|
|
633
|
-
|
|
668
|
+
type UiSchema<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any> = GenericObjectType & MakeUIType<UIOptionsBaseType<T, S, F>> & {
|
|
634
669
|
/** Allows the form to generate a unique prefix for the `Form`'s root prefix */
|
|
635
670
|
"ui:rootFieldId"?: string;
|
|
636
671
|
/** Allows RJSF to override the default field implementation by specifying either the name of a field that is used
|
|
637
672
|
* to look up an implementation from the `fields` list or an actual one-off `Field` component implementation itself
|
|
638
673
|
*/
|
|
639
|
-
"ui:field"?: Field<T, F> | string;
|
|
640
|
-
/**
|
|
641
|
-
|
|
674
|
+
"ui:field"?: Field<T, S, F> | string;
|
|
675
|
+
/** By default, any field that is rendered for an `anyOf`/`oneOf` schema will be wrapped inside the `AnyOfField` or
|
|
676
|
+
* `OneOfField` component. This default behavior may be undesirable if your custom field already handles behavior
|
|
677
|
+
* related to choosing one or more subschemas contained in the `anyOf`/`oneOf` schema.
|
|
678
|
+
* By providing a `true` value for this flag in association with a custom `ui:field`, the wrapped components will be
|
|
679
|
+
* omitted, so just one instance of the custom field will be rendered. If the flag is omitted or set to `false`,
|
|
680
|
+
* your custom field will be wrapped by `AnyOfField`/`OneOfField`.
|
|
681
|
+
*/
|
|
682
|
+
"ui:fieldReplacesAnyOrOneOf"?: boolean;
|
|
683
|
+
/** An object that contains all the potential UI options in a single object */
|
|
684
|
+
"ui:options"?: UIOptionsType<T, S, F>;
|
|
642
685
|
};
|
|
643
|
-
/** A `CustomValidator` function takes in a `formData` and `
|
|
644
|
-
* while potentially adding additional messages to the `errors`
|
|
686
|
+
/** A `CustomValidator` function takes in a `formData`, `errors` and `uiSchema` objects and returns the given `errors`
|
|
687
|
+
* object back, while potentially adding additional messages to the `errors`
|
|
645
688
|
*/
|
|
646
|
-
|
|
647
|
-
/** An `ErrorTransformer` function will take in a list of `errors` and potentially return a
|
|
648
|
-
* errors in what ever way it deems necessary
|
|
689
|
+
type CustomValidator<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any> = (formData: T | undefined, errors: FormValidation<T>, uiSchema?: UiSchema<T, S, F>) => FormValidation<T>;
|
|
690
|
+
/** An `ErrorTransformer` function will take in a list of `errors` & a `uiSchema` and potentially return a
|
|
691
|
+
* transformation of those errors in what ever way it deems necessary
|
|
649
692
|
*/
|
|
650
|
-
|
|
693
|
+
type ErrorTransformer<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any> = (errors: RJSFValidationError[], uiSchema?: UiSchema<T, S, F>) => RJSFValidationError[];
|
|
651
694
|
/** The type that describes the data that is returned from the `ValidatorType.validateFormData()` function */
|
|
652
|
-
|
|
695
|
+
type ValidationData<T> = {
|
|
653
696
|
/** The validation errors as a list of `RJSFValidationError` objects */
|
|
654
697
|
errors: RJSFValidationError[];
|
|
655
698
|
/** The validation errors in the form of an `ErrorSchema` */
|
|
@@ -658,7 +701,7 @@ declare type ValidationData<T> = {
|
|
|
658
701
|
/** The interface that describes the validation functions that are provided by a Validator implementation used by the
|
|
659
702
|
* schema utilities.
|
|
660
703
|
*/
|
|
661
|
-
interface ValidatorType<T = any> {
|
|
704
|
+
interface ValidatorType<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any> {
|
|
662
705
|
/** This function processes the `formData` with an optional user contributed `customValidate` function, which receives
|
|
663
706
|
* the form data and a `errorHandler` function that will be used to add custom validation errors for each field. Also
|
|
664
707
|
* supports a `transformErrors` function that will take the raw AJV validation errors, prior to custom validation and
|
|
@@ -668,8 +711,9 @@ interface ValidatorType<T = any> {
|
|
|
668
711
|
* @param schema - The schema against which to validate the form data
|
|
669
712
|
* @param [customValidate] - An optional function that is used to perform custom validation
|
|
670
713
|
* @param [transformErrors] - An optional function that is used to transform errors after AJV validation
|
|
714
|
+
* @param [uiSchema] - An optional uiSchema that is passed to `transformErrors` and `customValidate`
|
|
671
715
|
*/
|
|
672
|
-
validateFormData(formData: T, schema:
|
|
716
|
+
validateFormData(formData: T | undefined, schema: S, customValidate?: CustomValidator<T, S, F>, transformErrors?: ErrorTransformer<T, S, F>, uiSchema?: UiSchema<T, S, F>): ValidationData<T>;
|
|
673
717
|
/** Converts an `errorSchema` into a list of `RJSFValidationErrors`
|
|
674
718
|
*
|
|
675
719
|
* @param errorSchema - The `ErrorSchema` instance to convert
|
|
@@ -681,22 +725,32 @@ interface ValidatorType<T = any> {
|
|
|
681
725
|
* false.
|
|
682
726
|
*
|
|
683
727
|
* @param schema - The schema against which to validate the form data * @param schema
|
|
684
|
-
* @param formData
|
|
728
|
+
* @param formData - The form data to validate
|
|
685
729
|
* @param rootSchema - The root schema used to provide $ref resolutions
|
|
686
730
|
*/
|
|
687
|
-
isValid(schema:
|
|
731
|
+
isValid(schema: S, formData: T | undefined, rootSchema: S): boolean;
|
|
732
|
+
/** Runs the pure validation of the `schema` and `formData` without any of the RJSF functionality. Provided for use
|
|
733
|
+
* by the playground. Returns the `errors` from the validation
|
|
734
|
+
*
|
|
735
|
+
* @param schema - The schema against which to validate the form data * @param schema
|
|
736
|
+
* @param formData - The form data to validate
|
|
737
|
+
*/
|
|
738
|
+
rawValidation<Result = any>(schema: S, formData?: T): {
|
|
739
|
+
errors?: Result[];
|
|
740
|
+
validationError?: Error;
|
|
741
|
+
};
|
|
688
742
|
}
|
|
689
743
|
/** The `SchemaUtilsType` interface provides a wrapper around the publicly exported APIs in the `@rjsf/utils/schema`
|
|
690
744
|
* directory such that one does not have to explicitly pass the `validator` or `rootSchema` to each method. Since both
|
|
691
745
|
* the `validator` and `rootSchema` generally does not change across a `Form`, this allows for providing a simplified
|
|
692
746
|
* set of APIs to the `@rjsf/core` components and the various themes as well.
|
|
693
747
|
*/
|
|
694
|
-
interface SchemaUtilsType<T = any> {
|
|
748
|
+
interface SchemaUtilsType<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any> {
|
|
695
749
|
/** Returns the `ValidatorType` in the `SchemaUtilsType`
|
|
696
750
|
*
|
|
697
751
|
* @returns - The `ValidatorType`
|
|
698
752
|
*/
|
|
699
|
-
getValidator(): ValidatorType<T>;
|
|
753
|
+
getValidator(): ValidatorType<T, S, F>;
|
|
700
754
|
/** Determines whether either the `validator` and `rootSchema` differ from the ones associated with this instance of
|
|
701
755
|
* the `SchemaUtilsType`. If either `validator` or `rootSchema` are falsy, then return false to prevent the creation
|
|
702
756
|
* of a new `SchemaUtilsType` with incomplete properties.
|
|
@@ -705,16 +759,18 @@ interface SchemaUtilsType<T = any> {
|
|
|
705
759
|
* @param rootSchema - The root schema that will be compared against the current one
|
|
706
760
|
* @returns - True if the `SchemaUtilsType` differs from the given `validator` or `rootSchema`
|
|
707
761
|
*/
|
|
708
|
-
doesSchemaUtilsDiffer(validator: ValidatorType, rootSchema:
|
|
762
|
+
doesSchemaUtilsDiffer(validator: ValidatorType<T, S, F>, rootSchema: S): boolean;
|
|
709
763
|
/** Returns the superset of `formData` that includes the given set updated to include any missing fields that have
|
|
710
764
|
* computed to have defaults provided in the `schema`.
|
|
711
765
|
*
|
|
712
766
|
* @param schema - The schema for which the default state is desired
|
|
713
767
|
* @param [formData] - The current formData, if any, onto which to provide any missing defaults
|
|
714
|
-
* @param [includeUndefinedValues=false] - Optional flag, if true, cause undefined values to be added as defaults
|
|
768
|
+
* @param [includeUndefinedValues=false] - Optional flag, if true, cause undefined values to be added as defaults.
|
|
769
|
+
* If "excludeObjectChildren", pass `includeUndefinedValues` as false when computing defaults for any nested
|
|
770
|
+
* object properties.
|
|
715
771
|
* @returns - The resulting `formData` with all the defaults provided
|
|
716
772
|
*/
|
|
717
|
-
getDefaultFormState(schema:
|
|
773
|
+
getDefaultFormState(schema: S, formData?: T, includeUndefinedValues?: boolean | "excludeObjectChildren"): T | T[] | undefined;
|
|
718
774
|
/** Determines whether the combination of `schema` and `uiSchema` properties indicates that the label for the `schema`
|
|
719
775
|
* should be displayed in a UI.
|
|
720
776
|
*
|
|
@@ -722,39 +778,60 @@ interface SchemaUtilsType<T = any> {
|
|
|
722
778
|
* @param [uiSchema] - The UI schema from which to derive potentially displayable information
|
|
723
779
|
* @returns - True if the label should be displayed or false if it should not
|
|
724
780
|
*/
|
|
725
|
-
getDisplayLabel
|
|
781
|
+
getDisplayLabel(schema: S, uiSchema?: UiSchema<T, S, F>): boolean;
|
|
782
|
+
/** Determines which of the given `options` provided most closely matches the `formData`.
|
|
783
|
+
* Returns the index of the option that is valid and is the closest match, or 0 if there is no match.
|
|
784
|
+
*
|
|
785
|
+
* The closest match is determined using the number of matching properties, and more heavily favors options with
|
|
786
|
+
* matching readOnly, default, or const values.
|
|
787
|
+
*
|
|
788
|
+
* @param formData - The form data associated with the schema
|
|
789
|
+
* @param options - The list of options that can be selected from
|
|
790
|
+
* @param [selectedOption] - The index of the currently selected option, defaulted to -1 if not specified
|
|
791
|
+
* @returns - The index of the option that is the closest match to the `formData` or the `selectedOption` if no match
|
|
792
|
+
*/
|
|
793
|
+
getClosestMatchingOption(formData: T | undefined, options: S[], selectedOption?: number): number;
|
|
794
|
+
/** Given the `formData` and list of `options`, attempts to find the index of the first option that matches the data.
|
|
795
|
+
* Always returns the first option if there is nothing that matches.
|
|
796
|
+
*
|
|
797
|
+
* @param formData - The current formData, if any, used to figure out a match
|
|
798
|
+
* @param options - The list of options to find a matching options from
|
|
799
|
+
* @returns - The firstindex of the matched option or 0 if none is available
|
|
800
|
+
*/
|
|
801
|
+
getFirstMatchingOption(formData: T | undefined, options: S[]): number;
|
|
726
802
|
/** Given the `formData` and list of `options`, attempts to find the index of the option that best matches the data.
|
|
803
|
+
* Deprecated, use `getFirstMatchingOption()` instead.
|
|
727
804
|
*
|
|
728
805
|
* @param formData - The current formData, if any, onto which to provide any missing defaults
|
|
729
806
|
* @param options - The list of options to find a matching options from
|
|
730
807
|
* @returns - The index of the matched option or 0 if none is available
|
|
808
|
+
* @deprecated
|
|
731
809
|
*/
|
|
732
|
-
getMatchingOption(formData: T, options:
|
|
810
|
+
getMatchingOption(formData: T | undefined, options: S[]): number;
|
|
733
811
|
/** Checks to see if the `schema` and `uiSchema` combination represents an array of files
|
|
734
812
|
*
|
|
735
813
|
* @param schema - The schema for which check for array of files flag is desired
|
|
736
814
|
* @param [uiSchema] - The UI schema from which to check the widget
|
|
737
815
|
* @returns - True if schema/uiSchema contains an array of files, otherwise false
|
|
738
816
|
*/
|
|
739
|
-
isFilesArray
|
|
817
|
+
isFilesArray(schema: S, uiSchema?: UiSchema<T, S, F>): boolean;
|
|
740
818
|
/** Checks to see if the `schema` combination represents a multi-select
|
|
741
819
|
*
|
|
742
820
|
* @param schema - The schema for which check for a multi-select flag is desired
|
|
743
821
|
* @returns - True if schema contains a multi-select, otherwise false
|
|
744
822
|
*/
|
|
745
|
-
isMultiSelect(schema:
|
|
823
|
+
isMultiSelect(schema: S): boolean;
|
|
746
824
|
/** Checks to see if the `schema` combination represents a select
|
|
747
825
|
*
|
|
748
826
|
* @param schema - The schema for which check for a select flag is desired
|
|
749
827
|
* @returns - True if schema contains a select, otherwise false
|
|
750
828
|
*/
|
|
751
|
-
isSelect(schema:
|
|
829
|
+
isSelect(schema: S): boolean;
|
|
752
830
|
/** Merges the errors in `additionalErrorSchema` into the existing `validationData` by combining the hierarchies in the
|
|
753
831
|
* two `ErrorSchema`s and then appending the error list from the `additionalErrorSchema` obtained by calling
|
|
754
832
|
* `validator.toErrorList()` onto the `errors` in the `validationData`. If no `additionalErrorSchema` is passed, then
|
|
755
833
|
* `validationData` is returned.
|
|
756
834
|
*
|
|
757
|
-
* @param validator - The validator used to convert an ErrorSchema to a list of errors
|
|
758
835
|
* @param validationData - The current `ValidationData` into which to merge the additional errors
|
|
759
836
|
* @param [additionalErrorSchema] - The additional set of errors
|
|
760
837
|
* @returns - The `validationData` with the additional errors from `additionalErrorSchema` merged into it, if provided.
|
|
@@ -765,10 +842,22 @@ interface SchemaUtilsType<T = any> {
|
|
|
765
842
|
* recursive resolution.
|
|
766
843
|
*
|
|
767
844
|
* @param schema - The schema for which retrieving a schema is desired
|
|
768
|
-
* @param [
|
|
845
|
+
* @param [formData] - The current formData, if any, to assist retrieving a schema
|
|
769
846
|
* @returns - The schema having its conditions, additional properties, references and dependencies resolved
|
|
770
847
|
*/
|
|
771
|
-
retrieveSchema(schema:
|
|
848
|
+
retrieveSchema(schema: S, formData?: T): S;
|
|
849
|
+
/** Sanitize the `data` associated with the `oldSchema` so it is considered appropriate for the `newSchema`. If the
|
|
850
|
+
* new schema does not contain any properties, then `undefined` is returned to clear all the form data. Due to the
|
|
851
|
+
* nature of schemas, this sanitization happens recursively for nested objects of data. Also, any properties in the
|
|
852
|
+
* old schema that are non-existent in the new schema are set to `undefined`.
|
|
853
|
+
*
|
|
854
|
+
* @param [newSchema] - The new schema for which the data is being sanitized
|
|
855
|
+
* @param [oldSchema] - The old schema from which the data originated
|
|
856
|
+
* @param [data={}] - The form data associated with the schema, defaulting to an empty object when undefined
|
|
857
|
+
* @returns - The new form data, with all of the fields uniquely associated with the old schema set
|
|
858
|
+
* to `undefined`. Will return `undefined` if the new schema is not an object containing properties.
|
|
859
|
+
*/
|
|
860
|
+
sanitizeDataForNewSchema(newSchema?: S, oldSchema?: S, data?: any): T;
|
|
772
861
|
/** Generates an `IdSchema` object for the `schema`, recursively
|
|
773
862
|
*
|
|
774
863
|
* @param schema - The schema for which the display label flag is desired
|
|
@@ -778,7 +867,7 @@ interface SchemaUtilsType<T = any> {
|
|
|
778
867
|
* @param [idSeparator='_'] - The separator to use for the path segments in the id
|
|
779
868
|
* @returns - The `IdSchema` object for the `schema`
|
|
780
869
|
*/
|
|
781
|
-
toIdSchema(schema:
|
|
870
|
+
toIdSchema(schema: S, id?: string, formData?: T, idPrefix?: string, idSeparator?: string): IdSchema<T>;
|
|
782
871
|
/** Generates an `PathSchema` object for the `schema`, recursively
|
|
783
872
|
*
|
|
784
873
|
* @param schema - The schema for which the display label flag is desired
|
|
@@ -786,7 +875,7 @@ interface SchemaUtilsType<T = any> {
|
|
|
786
875
|
* @param [formData] - The current formData, if any, onto which to provide any missing defaults
|
|
787
876
|
* @returns - The `PathSchema` object for the `schema`
|
|
788
877
|
*/
|
|
789
|
-
toPathSchema(schema:
|
|
878
|
+
toPathSchema(schema: S, name?: string, formData?: T): PathSchema<T>;
|
|
790
879
|
}
|
|
791
880
|
|
|
792
881
|
/** Checks the schema to see if it is allowing additional items, by verifying that `schema.additionalItems` is an
|
|
@@ -795,7 +884,7 @@ interface SchemaUtilsType<T = any> {
|
|
|
795
884
|
* @param schema - The schema object to check
|
|
796
885
|
* @returns - True if additional items is allowed, otherwise false
|
|
797
886
|
*/
|
|
798
|
-
declare function allowAdditionalItems(schema:
|
|
887
|
+
declare function allowAdditionalItems<S extends StrictRJSFSchema = RJSFSchema>(schema: S): boolean;
|
|
799
888
|
|
|
800
889
|
/** Attempts to convert the string into a number. If an empty string is provided, then `undefined` is returned. If a
|
|
801
890
|
* `null` is provided, it is returned. If the string ends in a `.` then the string is returned because the user may be
|
|
@@ -817,7 +906,7 @@ declare function asNumber(value: string | null): string | number | null | undefi
|
|
|
817
906
|
* @param [formData] - The formData for the field
|
|
818
907
|
* @returns - True if the schema element has additionalProperties, is expandable, and not at the maxProperties limit
|
|
819
908
|
*/
|
|
820
|
-
declare function canExpand<T = any, F = any>(schema: RJSFSchema, uiSchema?: UiSchema<T, F>, formData?: T): boolean;
|
|
909
|
+
declare function canExpand<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(schema: RJSFSchema, uiSchema?: UiSchema<T, S, F>, formData?: T): boolean;
|
|
821
910
|
|
|
822
911
|
/** Creates a `SchemaUtilsType` interface that is based around the given `validator` and `rootSchema` parameters. The
|
|
823
912
|
* resulting interface implementation will forward the `validator` and `rootSchema` to all the wrapped APIs.
|
|
@@ -826,7 +915,7 @@ declare function canExpand<T = any, F = any>(schema: RJSFSchema, uiSchema?: UiSc
|
|
|
826
915
|
* @param rootSchema - The root schema that will be forwarded to all the APIs
|
|
827
916
|
* @returns - An implementation of a `SchemaUtilsType` interface
|
|
828
917
|
*/
|
|
829
|
-
declare function createSchemaUtils<T = any>(validator: ValidatorType, rootSchema:
|
|
918
|
+
declare function createSchemaUtils<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(validator: ValidatorType<T, S, F>, rootSchema: S): SchemaUtilsType<T, S, F>;
|
|
830
919
|
|
|
831
920
|
/** Given the `FileReader.readAsDataURL()` based `dataURI` extracts that data into an actual Blob along with the name
|
|
832
921
|
* of that Blob if provided in the URL. If no name is provided, then the name falls back to `unknown`.
|
|
@@ -848,6 +937,124 @@ declare function dataURItoBlob(dataURI: string): {
|
|
|
848
937
|
*/
|
|
849
938
|
declare function deepEquals(a: any, b: any): boolean;
|
|
850
939
|
|
|
940
|
+
/** Removes the enum option value at the `valueIndex` from the currently `selected` (list of) value(s). If `selected` is
|
|
941
|
+
* a list, then that list is updated to remove the enum option value with the `valueIndex` in `allEnumOptions`. If it is
|
|
942
|
+
* a single value, then if the enum option value with the `valueIndex` in `allEnumOptions` matches `selected`, undefined
|
|
943
|
+
* is returned, otherwise the `selected` value is returned.
|
|
944
|
+
*
|
|
945
|
+
* @param valueIndex - The index of the value to be removed from the selected list or single value
|
|
946
|
+
* @param selected - The current (list of) selected value(s)
|
|
947
|
+
* @param [allEnumOptions=[]] - The list of all the known enumOptions
|
|
948
|
+
* @returns - The updated `selected` with the enum option value at `valueIndex` in `allEnumOptions` removed from it,
|
|
949
|
+
* unless `selected` is a single value. In that case, if the `valueIndex` value matches `selected`, returns
|
|
950
|
+
* undefined, otherwise `selected`.
|
|
951
|
+
*/
|
|
952
|
+
declare function enumOptionsDeselectValue<S extends StrictRJSFSchema = RJSFSchema>(valueIndex: string | number, selected?: EnumOptionsType<S>["value"] | EnumOptionsType<S>["value"][], allEnumOptions?: EnumOptionsType<S>[]): EnumOptionsType<S>["value"] | EnumOptionsType<S>["value"][] | undefined;
|
|
953
|
+
|
|
954
|
+
/** Returns the index(es) of the options in `allEnumOptions` whose value(s) match the ones in `value`. All the
|
|
955
|
+
* `enumOptions` are filtered based on whether they are a "selected" `value` and the index of each selected one is then
|
|
956
|
+
* stored in an array. If `multiple` is true, that array is returned, otherwise the first element in the array is
|
|
957
|
+
* returned.
|
|
958
|
+
*
|
|
959
|
+
* @param value - The single value or list of values for which indexes are desired
|
|
960
|
+
* @param [allEnumOptions=[]] - The list of all the known enumOptions
|
|
961
|
+
* @param [multiple=false] - Optional flag, if true will return a list of index, otherwise a single one
|
|
962
|
+
* @returns - A single string index for the first `value` in `allEnumOptions`, if not `multiple`. Otherwise, the list
|
|
963
|
+
* of indexes for (each of) the value(s) in `value`.
|
|
964
|
+
*/
|
|
965
|
+
declare function enumOptionsIndexForValue<S extends StrictRJSFSchema = RJSFSchema>(value: EnumOptionsType<S>["value"] | EnumOptionsType<S>["value"][], allEnumOptions?: EnumOptionsType<S>[], multiple?: boolean): string | string[] | undefined;
|
|
966
|
+
|
|
967
|
+
/** Determines whether the given `value` is (one of) the `selected` value(s).
|
|
968
|
+
*
|
|
969
|
+
* @param value - The value being checked to see if it is selected
|
|
970
|
+
* @param selected - The current selected value or list of values
|
|
971
|
+
* @returns - true if the `value` is one of the `selected` ones, false otherwise
|
|
972
|
+
*/
|
|
973
|
+
declare function enumOptionsIsSelected<S extends StrictRJSFSchema = RJSFSchema>(value: EnumOptionsType<S>["value"], selected: EnumOptionsType<S>["value"] | EnumOptionsType<S>["value"][]): boolean;
|
|
974
|
+
|
|
975
|
+
/** Add the enum option value at the `valueIndex` to the list of `selected` values in the proper order as defined by
|
|
976
|
+
* `allEnumOptions`
|
|
977
|
+
*
|
|
978
|
+
* @param valueIndex - The index of the value that should be selected
|
|
979
|
+
* @param selected - The current list of selected values
|
|
980
|
+
* @param [allEnumOptions=[]] - The list of all the known enumOptions
|
|
981
|
+
* @returns - The updated list of selected enum values with enum value at the `valueIndex` added to it
|
|
982
|
+
*/
|
|
983
|
+
declare function enumOptionsSelectValue<S extends StrictRJSFSchema = RJSFSchema>(valueIndex: string | number, selected: EnumOptionsType<S>["value"][], allEnumOptions?: EnumOptionsType<S>[]): any[];
|
|
984
|
+
|
|
985
|
+
/** Returns the value(s) from `allEnumOptions` at the index(es) provided by `valueIndex`. If `valueIndex` is not an
|
|
986
|
+
* array AND the index is not valid for `allEnumOptions`, `emptyValue` is returned. If `valueIndex` is an array, AND it
|
|
987
|
+
* contains an invalid index, the returned array will have the resulting undefined values filtered out, leaving only
|
|
988
|
+
* valid values or in the worst case, an empty array.
|
|
989
|
+
*
|
|
990
|
+
* @param valueIndex - The index(es) of the value(s) that should be returned
|
|
991
|
+
* @param [allEnumOptions=[]] - The list of all the known enumOptions
|
|
992
|
+
* @param [emptyValue] - The value to return when the non-array `valueIndex` does not refer to a real option
|
|
993
|
+
* @returns - The single or list of values specified by the single or list of indexes if they are valid. Otherwise,
|
|
994
|
+
* `emptyValue` or an empty list.
|
|
995
|
+
*/
|
|
996
|
+
declare function enumOptionsValueForIndex<S extends StrictRJSFSchema = RJSFSchema>(valueIndex: string | number | Array<string | number>, allEnumOptions?: EnumOptionsType<S>[], emptyValue?: EnumOptionsType<S>["value"]): EnumOptionsType<S>["value"] | EnumOptionsType<S>["value"][] | undefined;
|
|
997
|
+
|
|
998
|
+
/** The `ErrorSchemaBuilder<T>` is used to build an `ErrorSchema<T>` since the definition of the `ErrorSchema` type is
|
|
999
|
+
* designed for reading information rather than writing it. Use this class to add, replace or clear errors in an error
|
|
1000
|
+
* schema by using either dotted path or an array of path names. Once you are done building the `ErrorSchema`, you can
|
|
1001
|
+
* get the result and/or reset all the errors back to an initial set and start again.
|
|
1002
|
+
*/
|
|
1003
|
+
declare class ErrorSchemaBuilder<T = any> {
|
|
1004
|
+
/** The error schema being built
|
|
1005
|
+
*
|
|
1006
|
+
* @private
|
|
1007
|
+
*/
|
|
1008
|
+
private errorSchema;
|
|
1009
|
+
/** Construct an `ErrorSchemaBuilder` with an optional initial set of errors in an `ErrorSchema`.
|
|
1010
|
+
*
|
|
1011
|
+
* @param [initialSchema] - The optional set of initial errors, that will be cloned into the class
|
|
1012
|
+
*/
|
|
1013
|
+
constructor(initialSchema?: ErrorSchema<T>);
|
|
1014
|
+
/** Returns the `ErrorSchema` that has been updated by the methods of the `ErrorSchemaBuilder`
|
|
1015
|
+
*/
|
|
1016
|
+
get ErrorSchema(): ErrorSchema<T>;
|
|
1017
|
+
/** Will get an existing `ErrorSchema` at the specified `pathOfError` or create and return one.
|
|
1018
|
+
*
|
|
1019
|
+
* @param [pathOfError] - The optional path into the `ErrorSchema` at which to add the error(s)
|
|
1020
|
+
* @returns - The error block for the given `pathOfError` or the root if not provided
|
|
1021
|
+
* @private
|
|
1022
|
+
*/
|
|
1023
|
+
private getOrCreateErrorBlock;
|
|
1024
|
+
/** Resets all errors in the `ErrorSchemaBuilder` back to the `initialSchema` if provided, otherwise an empty set.
|
|
1025
|
+
*
|
|
1026
|
+
* @param [initialSchema] - The optional set of initial errors, that will be cloned into the class
|
|
1027
|
+
* @returns - The `ErrorSchemaBuilder` object for chaining purposes
|
|
1028
|
+
*/
|
|
1029
|
+
resetAllErrors(initialSchema?: ErrorSchema<T>): this;
|
|
1030
|
+
/** Adds the `errorOrList` to the list of errors in the `ErrorSchema` at either the root level or the location within
|
|
1031
|
+
* the schema described by the `pathOfError`. For more information about how to specify the path see the
|
|
1032
|
+
* [eslint lodash plugin docs](https://github.com/wix/eslint-plugin-lodash/blob/master/docs/rules/path-style.md).
|
|
1033
|
+
*
|
|
1034
|
+
* @param errorOrList - The error or list of errors to add into the `ErrorSchema`
|
|
1035
|
+
* @param [pathOfError] - The optional path into the `ErrorSchema` at which to add the error(s)
|
|
1036
|
+
* @returns - The `ErrorSchemaBuilder` object for chaining purposes
|
|
1037
|
+
*/
|
|
1038
|
+
addErrors(errorOrList: string | string[], pathOfError?: string | string[]): this;
|
|
1039
|
+
/** Sets/replaces the `errorOrList` as the error(s) in the `ErrorSchema` at either the root level or the location
|
|
1040
|
+
* within the schema described by the `pathOfError`. For more information about how to specify the path see the
|
|
1041
|
+
* [eslint lodash plugin docs](https://github.com/wix/eslint-plugin-lodash/blob/master/docs/rules/path-style.md).
|
|
1042
|
+
*
|
|
1043
|
+
* @param errorOrList - The error or list of errors to set into the `ErrorSchema`
|
|
1044
|
+
* @param [pathOfError] - The optional path into the `ErrorSchema` at which to set the error(s)
|
|
1045
|
+
* @returns - The `ErrorSchemaBuilder` object for chaining purposes
|
|
1046
|
+
*/
|
|
1047
|
+
setErrors(errorOrList: string | string[], pathOfError?: string | string[]): this;
|
|
1048
|
+
/** Clears the error(s) in the `ErrorSchema` at either the root level or the location within the schema described by
|
|
1049
|
+
* the `pathOfError`. For more information about how to specify the path see the
|
|
1050
|
+
* [eslint lodash plugin docs](https://github.com/wix/eslint-plugin-lodash/blob/master/docs/rules/path-style.md).
|
|
1051
|
+
*
|
|
1052
|
+
* @param [pathOfError] - The optional path into the `ErrorSchema` at which to clear the error(s)
|
|
1053
|
+
* @returns - The `ErrorSchemaBuilder` object for chaining purposes
|
|
1054
|
+
*/
|
|
1055
|
+
clearErrors(pathOfError?: string | string[]): this;
|
|
1056
|
+
}
|
|
1057
|
+
|
|
851
1058
|
/** Given the name of a `$ref` from within a schema, using the `rootSchema`, look up and return the sub-schema using the
|
|
852
1059
|
* path provided by that reference. If `#` is not the first character of the reference, or the path does not exist in
|
|
853
1060
|
* the schema, then throw an Error. Otherwise return the sub-schema. Also deals with nested `$ref`s in the sub-schema.
|
|
@@ -857,7 +1064,7 @@ declare function deepEquals(a: any, b: any): boolean;
|
|
|
857
1064
|
* @returns - The sub-schema within the `rootSchema` which matches the `$ref` if it exists
|
|
858
1065
|
* @throws - Error indicating that no schema for that reference exists
|
|
859
1066
|
*/
|
|
860
|
-
declare function findSchemaDefinition($ref?: string, rootSchema?:
|
|
1067
|
+
declare function findSchemaDefinition<S extends StrictRJSFSchema = RJSFSchema>($ref?: string, rootSchema?: S): S;
|
|
861
1068
|
|
|
862
1069
|
/** Using the `schema`, `defaultType` and `options`, extract out the props for the <input> element that make sense.
|
|
863
1070
|
*
|
|
@@ -867,7 +1074,7 @@ declare function findSchemaDefinition($ref?: string, rootSchema?: RJSFSchema): R
|
|
|
867
1074
|
* @param [autoDefaultStepAny=true] - Determines whether to auto-default step=any when the type is number and no step
|
|
868
1075
|
* @returns - The extracted `InputPropsType` object
|
|
869
1076
|
*/
|
|
870
|
-
declare function getInputProps<T = any, F = any>(schema: RJSFSchema, defaultType?: string, options?: UIOptionsType<T, F>, autoDefaultStepAny?: boolean): InputPropsType;
|
|
1077
|
+
declare function getInputProps<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(schema: RJSFSchema, defaultType?: string, options?: UIOptionsType<T, S, F>, autoDefaultStepAny?: boolean): InputPropsType;
|
|
871
1078
|
|
|
872
1079
|
/** Gets the type of a given `schema`. If the type is not explicitly defined, then an attempt is made to infer it from
|
|
873
1080
|
* other elements of the schema as follows:
|
|
@@ -880,14 +1087,14 @@ declare function getInputProps<T = any, F = any>(schema: RJSFSchema, defaultType
|
|
|
880
1087
|
* @param schema - The schema for which to get the type
|
|
881
1088
|
* @returns - The type of the schema
|
|
882
1089
|
*/
|
|
883
|
-
declare function getSchemaType(schema:
|
|
1090
|
+
declare function getSchemaType<S extends StrictRJSFSchema = RJSFSchema>(schema: S): string | string[] | undefined;
|
|
884
1091
|
|
|
885
1092
|
/** Extracts any `ui:submitButtonOptions` from the `uiSchema` and merges them onto the `DEFAULT_OPTIONS`
|
|
886
1093
|
*
|
|
887
1094
|
* @param [uiSchema={}] - the UI Schema from which to extract submit button props
|
|
888
1095
|
* @returns - The merging of the `DEFAULT_OPTIONS` with any custom ones
|
|
889
1096
|
*/
|
|
890
|
-
declare function getSubmitButtonOptions<T = any, F = any>(uiSchema?: UiSchema<T, F>): UISchemaSubmitButtonOptions;
|
|
1097
|
+
declare function getSubmitButtonOptions<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(uiSchema?: UiSchema<T, S, F>): UISchemaSubmitButtonOptions;
|
|
891
1098
|
|
|
892
1099
|
/** Returns the template with the given `name` from either the `uiSchema` if it is defined or from the `registry`
|
|
893
1100
|
* otherwise. NOTE, since `ButtonTemplates` are not overridden in `uiSchema` only those in the `registry` are returned.
|
|
@@ -897,15 +1104,15 @@ declare function getSubmitButtonOptions<T = any, F = any>(uiSchema?: UiSchema<T,
|
|
|
897
1104
|
* @param [uiOptions={}] - The `UIOptionsType` from which to read an alternate template
|
|
898
1105
|
* @returns - The template from either the `uiSchema` or `registry` for the `name`
|
|
899
1106
|
*/
|
|
900
|
-
declare function getTemplate<Name extends keyof TemplatesType<T, F>, T = any, F = any>(name: Name, registry: Registry<T, F>, uiOptions?: UIOptionsType<T, F>): TemplatesType<T, F>[Name];
|
|
1107
|
+
declare function getTemplate<Name extends keyof TemplatesType<T, S, F>, T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(name: Name, registry: Registry<T, S, F>, uiOptions?: UIOptionsType<T, S, F>): TemplatesType<T, S, F>[Name];
|
|
901
1108
|
|
|
902
1109
|
/** Get all passed options from ui:options, and ui:<optionName>, returning them in an object with the `ui:`
|
|
903
1110
|
* stripped off.
|
|
904
1111
|
*
|
|
905
1112
|
* @param [uiSchema={}] - The UI Schema from which to get any `ui:xxx` options
|
|
906
|
-
* @returns - An object containing all
|
|
1113
|
+
* @returns - An object containing all the `ui:xxx` options with the stripped off
|
|
907
1114
|
*/
|
|
908
|
-
declare function getUiOptions<T = any, F = any>(uiSchema?: UiSchema<T, F>): UIOptionsType<T, F>;
|
|
1115
|
+
declare function getUiOptions<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(uiSchema?: UiSchema<T, S, F>): UIOptionsType<T, S, F>;
|
|
909
1116
|
|
|
910
1117
|
/** Given a schema representing a field to render and either the name or actual `Widget` implementation, returns the
|
|
911
1118
|
* React component that is used to render the widget. If the `widget` is already a React component, then it is wrapped
|
|
@@ -918,7 +1125,7 @@ declare function getUiOptions<T = any, F = any>(uiSchema?: UiSchema<T, F>): UIOp
|
|
|
918
1125
|
* @returns - The `Widget` component to use
|
|
919
1126
|
* @throws - An error if there is no `Widget` component that can be returned
|
|
920
1127
|
*/
|
|
921
|
-
declare function getWidget<T = any, F = any>(schema: RJSFSchema, widget?: Widget<T, F> | string, registeredWidgets?: RegistryWidgetsType<T, F>): Widget<T, F>;
|
|
1128
|
+
declare function getWidget<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(schema: RJSFSchema, widget?: Widget<T, S, F> | string, registeredWidgets?: RegistryWidgetsType<T, S, F>): Widget<T, S, F>;
|
|
922
1129
|
|
|
923
1130
|
/** Given a specific `value` attempts to guess the type of a schema element. In the case where we have to implicitly
|
|
924
1131
|
* create a schema, it is useful to know what type to use based on the data we are defining.
|
|
@@ -936,7 +1143,54 @@ declare function guessType(value: any): "array" | "string" | "null" | "boolean"
|
|
|
936
1143
|
* @param [registeredWidgets={}] - A registry of widget name to `Widget` implementation
|
|
937
1144
|
* @returns - True if the widget exists, false otherwise
|
|
938
1145
|
*/
|
|
939
|
-
declare function hasWidget<T = any, F = any>(schema: RJSFSchema, widget: Widget<T, F> | string, registeredWidgets?: RegistryWidgetsType<T, F>): boolean;
|
|
1146
|
+
declare function hasWidget<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(schema: RJSFSchema, widget: Widget<T, S, F> | string, registeredWidgets?: RegistryWidgetsType<T, S, F>): boolean;
|
|
1147
|
+
|
|
1148
|
+
/** Return a consistent `id` for the field description element
|
|
1149
|
+
*
|
|
1150
|
+
* @param id - Either simple string id or an IdSchema from which to extract it
|
|
1151
|
+
* @returns - The consistent id for the field description element from the given `id`
|
|
1152
|
+
*/
|
|
1153
|
+
declare function descriptionId<T = any>(id: IdSchema<T> | string): string;
|
|
1154
|
+
/** Return a consistent `id` for the field error element
|
|
1155
|
+
*
|
|
1156
|
+
* @param id - Either simple string id or an IdSchema from which to extract it
|
|
1157
|
+
* @returns - The consistent id for the field error element from the given `id`
|
|
1158
|
+
*/
|
|
1159
|
+
declare function errorId<T = any>(id: IdSchema<T> | string): string;
|
|
1160
|
+
/** Return a consistent `id` for the field examples element
|
|
1161
|
+
*
|
|
1162
|
+
* @param id - Either simple string id or an IdSchema from which to extract it
|
|
1163
|
+
* @returns - The consistent id for the field examples element from the given `id`
|
|
1164
|
+
*/
|
|
1165
|
+
declare function examplesId<T = any>(id: IdSchema<T> | string): string;
|
|
1166
|
+
/** Return a consistent `id` for the field help element
|
|
1167
|
+
*
|
|
1168
|
+
* @param id - Either simple string id or an IdSchema from which to extract it
|
|
1169
|
+
* @returns - The consistent id for the field help element from the given `id`
|
|
1170
|
+
*/
|
|
1171
|
+
declare function helpId<T = any>(id: IdSchema<T> | string): string;
|
|
1172
|
+
/** Return a consistent `id` for the field title element
|
|
1173
|
+
*
|
|
1174
|
+
* @param id - Either simple string id or an IdSchema from which to extract it
|
|
1175
|
+
* @returns - The consistent id for the field title element from the given `id`
|
|
1176
|
+
*/
|
|
1177
|
+
declare function titleId<T = any>(id: IdSchema<T> | string): string;
|
|
1178
|
+
/** Return a list of element ids that contain additional information about the field that can be used to as the aria
|
|
1179
|
+
* description of the field. This is correctly omitting `titleId` which would be "labeling" rather than "describing" the
|
|
1180
|
+
* element.
|
|
1181
|
+
*
|
|
1182
|
+
* @param id - Either simple string id or an IdSchema from which to extract it
|
|
1183
|
+
* @param [includeExamples=false] - Optional flag, if true, will add the `examplesId` into the list
|
|
1184
|
+
* @returns - The string containing the list of ids for use in an `aria-describedBy` attribute
|
|
1185
|
+
*/
|
|
1186
|
+
declare function ariaDescribedByIds<T = any>(id: IdSchema<T> | string, includeExamples?: boolean): string;
|
|
1187
|
+
/** Return a consistent `id` for the `optionIndex`s of a `Radio` or `Checkboxes` widget
|
|
1188
|
+
*
|
|
1189
|
+
* @param id - The id of the parent component for the option
|
|
1190
|
+
* @param optionIndex - The index of the option for which the id is desired
|
|
1191
|
+
* @returns - An id for the option index based on the parent `id`
|
|
1192
|
+
*/
|
|
1193
|
+
declare function optionId(id: string, optionIndex: number): string;
|
|
940
1194
|
|
|
941
1195
|
/** This function checks if the given `schema` matches a single constant value. This happens when either the schema has
|
|
942
1196
|
* an `enum` array with a single value or there is a `const` defined.
|
|
@@ -944,14 +1198,14 @@ declare function hasWidget<T = any, F = any>(schema: RJSFSchema, widget: Widget<
|
|
|
944
1198
|
* @param schema - The schema for a field
|
|
945
1199
|
* @returns - True if the `schema` has a single constant value, false otherwise
|
|
946
1200
|
*/
|
|
947
|
-
declare function isConstant(schema:
|
|
1201
|
+
declare function isConstant<S extends StrictRJSFSchema = RJSFSchema>(schema: S): boolean;
|
|
948
1202
|
|
|
949
1203
|
/** Checks to see if the `uiSchema` contains the `widget` field and that the widget is not `hidden`
|
|
950
1204
|
*
|
|
951
1205
|
* @param uiSchema - The UI Schema from which to detect if it is customized
|
|
952
1206
|
* @returns - True if the `uiSchema` describes a custom widget, false otherwise
|
|
953
1207
|
*/
|
|
954
|
-
declare function isCustomWidget<T = any, F = any>(uiSchema?: UiSchema<T, F>): boolean;
|
|
1208
|
+
declare function isCustomWidget<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(uiSchema?: UiSchema<T, S, F>): boolean;
|
|
955
1209
|
|
|
956
1210
|
/** Detects whether the given `schema` contains fixed items. This is the case when `schema.items` is a non-empty array
|
|
957
1211
|
* that only contains objects.
|
|
@@ -959,7 +1213,7 @@ declare function isCustomWidget<T = any, F = any>(uiSchema?: UiSchema<T, F>): bo
|
|
|
959
1213
|
* @param schema - The schema in which to check for fixed items
|
|
960
1214
|
* @returns - True if there are fixed items in the schema, false otherwise
|
|
961
1215
|
*/
|
|
962
|
-
declare function isFixedItems(schema:
|
|
1216
|
+
declare function isFixedItems<S extends StrictRJSFSchema = RJSFSchema>(schema: S): boolean;
|
|
963
1217
|
|
|
964
1218
|
/** Determines whether a `thing` is an object for the purposes of RSJF. In this case, `thing` is an object if it has
|
|
965
1219
|
* the type `object` but is NOT null, an array or a File.
|
|
@@ -986,20 +1240,22 @@ declare function localToUTC(dateString: string): string | undefined;
|
|
|
986
1240
|
* - when the array is not set in form data, the default is copied over
|
|
987
1241
|
* - scalars are overwritten/set by form data
|
|
988
1242
|
*
|
|
989
|
-
* @param defaults - The defaults to merge
|
|
990
|
-
* @param formData - The form data into which the defaults will be merged
|
|
1243
|
+
* @param [defaults] - The defaults to merge
|
|
1244
|
+
* @param [formData] - The form data into which the defaults will be merged
|
|
991
1245
|
* @returns - The resulting merged form data with defaults
|
|
992
1246
|
*/
|
|
993
|
-
declare function mergeDefaultsWithFormData<T = any>(defaults
|
|
1247
|
+
declare function mergeDefaultsWithFormData<T = any>(defaults?: T, formData?: T): T | undefined;
|
|
994
1248
|
|
|
995
1249
|
/** Recursively merge deeply nested objects.
|
|
996
1250
|
*
|
|
997
1251
|
* @param obj1 - The first object to merge
|
|
998
1252
|
* @param obj2 - The second object to merge
|
|
999
|
-
* @param [concatArrays=false] - Optional flag that, when true, will cause arrays to be concatenated
|
|
1253
|
+
* @param [concatArrays=false] - Optional flag that, when true, will cause arrays to be concatenated. Use
|
|
1254
|
+
* "preventDuplicates" to merge arrays in a manner that prevents any duplicate entries from being merged.
|
|
1255
|
+
* NOTE: Uses shallow comparison for the duplicate checking.
|
|
1000
1256
|
* @returns - A new object that is the merge of the two given objects
|
|
1001
1257
|
*/
|
|
1002
|
-
declare function mergeObjects(obj1: GenericObjectType, obj2: GenericObjectType, concatArrays?: boolean): GenericObjectType;
|
|
1258
|
+
declare function mergeObjects(obj1: GenericObjectType, obj2: GenericObjectType, concatArrays?: boolean | "preventDuplicates"): GenericObjectType;
|
|
1003
1259
|
|
|
1004
1260
|
/** Recursively merge deeply nested schemas. The difference between `mergeSchemas` and `mergeObjects` is that
|
|
1005
1261
|
* `mergeSchemas` only concats arrays for values under the 'required' keyword, and when it does, it doesn't include
|
|
@@ -1019,7 +1275,7 @@ declare function mergeSchemas(obj1: GenericObjectType, obj2: GenericObjectType):
|
|
|
1019
1275
|
* @param schema - The schema from which to extract the options list
|
|
1020
1276
|
* @returns - The list of options from the schema
|
|
1021
1277
|
*/
|
|
1022
|
-
declare function optionsList(schema:
|
|
1278
|
+
declare function optionsList<S extends StrictRJSFSchema = RJSFSchema>(schema: S): EnumOptionsType<S>[] | undefined;
|
|
1023
1279
|
|
|
1024
1280
|
/** Given a list of `properties` and an `order` list, returns a list that contains the `properties` ordered correctly.
|
|
1025
1281
|
* If `order` is not an array, then the untouched `properties` list is returned. Otherwise `properties` is ordered per
|
|
@@ -1050,24 +1306,13 @@ declare function pad(num: number, width: number): string;
|
|
|
1050
1306
|
*/
|
|
1051
1307
|
declare function parseDateString(dateString?: string, includeTime?: boolean): DateObject;
|
|
1052
1308
|
|
|
1053
|
-
/** Returns the real value for a select widget due to a silly limitation in the DOM which causes option change event
|
|
1054
|
-
* values to always be retrieved as strings. Uses the `schema` to help determine the value's true type. If the value is
|
|
1055
|
-
* an empty string, then the `emptyValue` from the `options` is returned, falling back to undefined.
|
|
1056
|
-
*
|
|
1057
|
-
* @param schema - The schema to used to determine the value's true type
|
|
1058
|
-
* @param [value] - The value to convert
|
|
1059
|
-
* @param [options] - The UIOptionsType from which to potentially extract the emptyValue
|
|
1060
|
-
* @returns - The `value` converted to the proper type
|
|
1061
|
-
*/
|
|
1062
|
-
declare function processSelectValue<T = any, F = any>(schema: RJSFSchema, value?: any, options?: UIOptionsType<T, F>): any;
|
|
1063
|
-
|
|
1064
1309
|
/** Extracts the range spec information `{ step?: number, min?: number, max?: number }` that can be spread onto an HTML
|
|
1065
1310
|
* input from the range analog in the schema `{ multipleOf?: number, minimum?: number, maximum?: number }`.
|
|
1066
1311
|
*
|
|
1067
1312
|
* @param schema - The schema from which to extract the range spec
|
|
1068
1313
|
* @returns - A range specification from the schema
|
|
1069
1314
|
*/
|
|
1070
|
-
declare function rangeSpec(schema:
|
|
1315
|
+
declare function rangeSpec<S extends StrictRJSFSchema = RJSFSchema>(schema: S): RangeSpecType;
|
|
1071
1316
|
|
|
1072
1317
|
/** Check to see if a `schema` specifies that a value must be true. This happens when:
|
|
1073
1318
|
* - `schema.const` is truthy
|
|
@@ -1078,7 +1323,7 @@ declare function rangeSpec(schema: RJSFSchema): RangeSpecType;
|
|
|
1078
1323
|
* @param schema - The schema to check
|
|
1079
1324
|
* @returns - True if the schema specifies a value that must be true, false otherwise
|
|
1080
1325
|
*/
|
|
1081
|
-
declare function schemaRequiresTrueValue(schema:
|
|
1326
|
+
declare function schemaRequiresTrueValue<S extends StrictRJSFSchema = RJSFSchema>(schema: S): boolean;
|
|
1082
1327
|
|
|
1083
1328
|
/** Determines whether the given `component` should be rerendered by comparing its current set of props and state
|
|
1084
1329
|
* against the next set. If either of those two sets are not the same, then the component should be rerendered.
|
|
@@ -1097,7 +1342,7 @@ declare function shouldRender(component: React.Component, nextProps: any, nextSt
|
|
|
1097
1342
|
* @returns - The constant value for the schema
|
|
1098
1343
|
* @throws - Error when the schema does not have a constant value
|
|
1099
1344
|
*/
|
|
1100
|
-
declare function toConstant(schema:
|
|
1345
|
+
declare function toConstant<S extends StrictRJSFSchema = RJSFSchema>(schema: S): json_schema.JSONSchema7Type | undefined;
|
|
1101
1346
|
|
|
1102
1347
|
/** Returns a UTC date string for the given `dateObject`. If `time` is false, then the time portion of the string is
|
|
1103
1348
|
* removed.
|
|
@@ -1150,10 +1395,12 @@ declare const UI_OPTIONS_KEY = "ui:options";
|
|
|
1150
1395
|
* @param theSchema - The schema for which the default state is desired
|
|
1151
1396
|
* @param [formData] - The current formData, if any, onto which to provide any missing defaults
|
|
1152
1397
|
* @param [rootSchema] - The root schema, used to primarily to look up `$ref`s
|
|
1153
|
-
* @param [includeUndefinedValues=false] - Optional flag, if true, cause undefined values to be added as defaults
|
|
1398
|
+
* @param [includeUndefinedValues=false] - Optional flag, if true, cause undefined values to be added as defaults.
|
|
1399
|
+
* If "excludeObjectChildren", pass `includeUndefinedValues` as false when computing defaults for any nested
|
|
1400
|
+
* object properties.
|
|
1154
1401
|
* @returns - The resulting `formData` with all the defaults provided
|
|
1155
1402
|
*/
|
|
1156
|
-
declare function getDefaultFormState<T = any>(validator: ValidatorType, theSchema:
|
|
1403
|
+
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;
|
|
1157
1404
|
|
|
1158
1405
|
/** Determines whether the combination of `schema` and `uiSchema` properties indicates that the label for the `schema`
|
|
1159
1406
|
* should be displayed in a UI.
|
|
@@ -1164,17 +1411,52 @@ declare function getDefaultFormState<T = any>(validator: ValidatorType, theSchem
|
|
|
1164
1411
|
* @param [rootSchema] - The root schema, used to primarily to look up `$ref`s
|
|
1165
1412
|
* @returns - True if the label should be displayed or false if it should not
|
|
1166
1413
|
*/
|
|
1167
|
-
declare function getDisplayLabel<T = any, F = any>(validator: ValidatorType, schema:
|
|
1414
|
+
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;
|
|
1415
|
+
|
|
1416
|
+
/** Determines which of the given `options` provided most closely matches the `formData`. Using
|
|
1417
|
+
* `getFirstMatchingOption()` to match two schemas that differ only by the readOnly, default or const value of a field
|
|
1418
|
+
* based on the `formData` and returns 0 when there is no match. Rather than passing in all the `options` at once to
|
|
1419
|
+
* this utility, instead an array of valid option indexes is created by iterating over the list of options, call
|
|
1420
|
+
* `getFirstMatchingOptions` with a list of one junk option and one good option, seeing if the good option is considered
|
|
1421
|
+
* matched.
|
|
1422
|
+
*
|
|
1423
|
+
* Once the list of valid indexes is created, if there is only one valid index, just return it. Otherwise, if there are
|
|
1424
|
+
* no valid indexes, then fill the valid indexes array with the indexes of all the options. Next, the index of the
|
|
1425
|
+
* option with the highest score is determined by iterating over the list of valid options, calling
|
|
1426
|
+
* `calculateIndexScore()` on each, comparing it against the current best score, and returning the index of the one that
|
|
1427
|
+
* eventually has the best score.
|
|
1428
|
+
*
|
|
1429
|
+
* @param validator - An implementation of the `ValidatorType` interface that will be used when necessary
|
|
1430
|
+
* @param rootSchema - The root JSON schema of the entire form
|
|
1431
|
+
* @param formData - The form data associated with the schema
|
|
1432
|
+
* @param options - The list of options that can be selected from
|
|
1433
|
+
* @param [selectedOption=-1] - The index of the currently selected option, defaulted to -1 if not specified
|
|
1434
|
+
* @returns - The index of the option that is the closest match to the `formData` or the `selectedOption` if no match
|
|
1435
|
+
*/
|
|
1436
|
+
declare function getClosestMatchingOption<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(validator: ValidatorType<T, S, F>, rootSchema: S, formData: T | undefined, options: S[], selectedOption?: number): number;
|
|
1437
|
+
|
|
1438
|
+
/** Given the `formData` and list of `options`, attempts to find the index of the first option that matches the data.
|
|
1439
|
+
* Always returns the first option if there is nothing that matches.
|
|
1440
|
+
*
|
|
1441
|
+
* @param validator - An implementation of the `ValidatorType` interface that will be used when necessary
|
|
1442
|
+
* @param formData - The current formData, if any, used to figure out a match
|
|
1443
|
+
* @param options - The list of options to find a matching options from
|
|
1444
|
+
* @param rootSchema - The root schema, used to primarily to look up `$ref`s
|
|
1445
|
+
* @returns - The index of the first matched option or 0 if none is available
|
|
1446
|
+
*/
|
|
1447
|
+
declare function getFirstMatchingOption<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(validator: ValidatorType<T, S, F>, formData: T | undefined, options: S[], rootSchema: S): number;
|
|
1168
1448
|
|
|
1169
1449
|
/** Given the `formData` and list of `options`, attempts to find the index of the option that best matches the data.
|
|
1450
|
+
* Deprecated, use `getFirstMatchingOption()` instead.
|
|
1170
1451
|
*
|
|
1171
1452
|
* @param validator - An implementation of the `ValidatorType` interface that will be used when necessary
|
|
1172
1453
|
* @param formData - The current formData, if any, used to figure out a match
|
|
1173
1454
|
* @param options - The list of options to find a matching options from
|
|
1174
1455
|
* @param rootSchema - The root schema, used to primarily to look up `$ref`s
|
|
1175
1456
|
* @returns - The index of the matched option or 0 if none is available
|
|
1457
|
+
* @deprecated
|
|
1176
1458
|
*/
|
|
1177
|
-
declare function getMatchingOption<T = any>(validator: ValidatorType, formData: T | undefined, options:
|
|
1459
|
+
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;
|
|
1178
1460
|
|
|
1179
1461
|
/** Checks to see if the `schema` and `uiSchema` combination represents an array of files
|
|
1180
1462
|
*
|
|
@@ -1184,7 +1466,7 @@ declare function getMatchingOption<T = any>(validator: ValidatorType, formData:
|
|
|
1184
1466
|
* @param [rootSchema] - The root schema, used to primarily to look up `$ref`s
|
|
1185
1467
|
* @returns - True if schema/uiSchema contains an array of files, otherwise false
|
|
1186
1468
|
*/
|
|
1187
|
-
declare function isFilesArray<T = any, F = any>(validator: ValidatorType, schema:
|
|
1469
|
+
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;
|
|
1188
1470
|
|
|
1189
1471
|
/** Checks to see if the `schema` combination represents a multi-select
|
|
1190
1472
|
*
|
|
@@ -1193,7 +1475,7 @@ declare function isFilesArray<T = any, F = any>(validator: ValidatorType, schema
|
|
|
1193
1475
|
* @param [rootSchema] - The root schema, used to primarily to look up `$ref`s
|
|
1194
1476
|
* @returns - True if schema contains a multi-select, otherwise false
|
|
1195
1477
|
*/
|
|
1196
|
-
declare function isMultiSelect<T = any>(validator: ValidatorType, schema:
|
|
1478
|
+
declare function isMultiSelect<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(validator: ValidatorType<T, S, F>, schema: S, rootSchema?: S): boolean;
|
|
1197
1479
|
|
|
1198
1480
|
/** Checks to see if the `schema` combination represents a select
|
|
1199
1481
|
*
|
|
@@ -1202,7 +1484,7 @@ declare function isMultiSelect<T = any>(validator: ValidatorType, schema: RJSFSc
|
|
|
1202
1484
|
* @param [rootSchema] - The root schema, used to primarily to look up `$ref`s
|
|
1203
1485
|
* @returns - True if schema contains a select, otherwise false
|
|
1204
1486
|
*/
|
|
1205
|
-
declare function isSelect<T = any>(validator: ValidatorType, theSchema:
|
|
1487
|
+
declare function isSelect<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(validator: ValidatorType<T, S, F>, theSchema: S, rootSchema?: S): boolean;
|
|
1206
1488
|
|
|
1207
1489
|
/** Merges the errors in `additionalErrorSchema` into the existing `validationData` by combining the hierarchies in the
|
|
1208
1490
|
* two `ErrorSchema`s and then appending the error list from the `additionalErrorSchema` obtained by calling
|
|
@@ -1214,19 +1496,68 @@ declare function isSelect<T = any>(validator: ValidatorType, theSchema: RJSFSche
|
|
|
1214
1496
|
* @param [additionalErrorSchema] - The additional set of errors in an `ErrorSchema`
|
|
1215
1497
|
* @returns - The `validationData` with the additional errors from `additionalErrorSchema` merged into it, if provided.
|
|
1216
1498
|
*/
|
|
1217
|
-
declare function mergeValidationData<T = any>(validator: ValidatorType<T>, validationData: ValidationData<T>, additionalErrorSchema?: ErrorSchema<T>): ValidationData<T>;
|
|
1499
|
+
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>;
|
|
1218
1500
|
|
|
1219
1501
|
/** Retrieves an expanded schema that has had all of its conditions, additional properties, references and dependencies
|
|
1220
1502
|
* resolved and merged into the `schema` given a `validator`, `rootSchema` and `rawFormData` that is used to do the
|
|
1221
1503
|
* potentially recursive resolution.
|
|
1222
1504
|
*
|
|
1223
|
-
* @param validator - An implementation of the `ValidatorType
|
|
1505
|
+
* @param validator - An implementation of the `ValidatorType<T, S>` interface that will be forwarded to all the APIs
|
|
1224
1506
|
* @param schema - The schema for which retrieving a schema is desired
|
|
1225
1507
|
* @param [rootSchema={}] - The root schema that will be forwarded to all the APIs
|
|
1226
1508
|
* @param [rawFormData] - The current formData, if any, to assist retrieving a schema
|
|
1227
1509
|
* @returns - The schema having its conditions, additional properties, references and dependencies resolved
|
|
1228
1510
|
*/
|
|
1229
|
-
declare function retrieveSchema<T = any>(validator: ValidatorType, schema:
|
|
1511
|
+
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;
|
|
1512
|
+
|
|
1513
|
+
/** Sanitize the `data` associated with the `oldSchema` so it is considered appropriate for the `newSchema`. If the new
|
|
1514
|
+
* schema does not contain any properties, then `undefined` is returned to clear all the form data. Due to the nature
|
|
1515
|
+
* of schemas, this sanitization happens recursively for nested objects of data. Also, any properties in the old schema
|
|
1516
|
+
* that are non-existent in the new schema are set to `undefined`. The data sanitization process has the following flow:
|
|
1517
|
+
*
|
|
1518
|
+
* - If the new schema is an object that contains a `properties` object then:
|
|
1519
|
+
* - Create a `removeOldSchemaData` object, setting each key in the `oldSchema.properties` having `data` to undefined
|
|
1520
|
+
* - Create an empty `nestedData` object for use in the key filtering below:
|
|
1521
|
+
* - Iterate over each key in the `newSchema.properties` as follows:
|
|
1522
|
+
* - Get the `formValue` of the key from the `data`
|
|
1523
|
+
* - Get the `oldKeySchema` and `newKeyedSchema` for the key, defaulting to `{}` when it doesn't exist
|
|
1524
|
+
* - Retrieve the schema for any refs within each `oldKeySchema` and/or `newKeySchema`
|
|
1525
|
+
* - Get the types of the old and new keyed schemas and if the old doesn't exist or the old & new are the same then:
|
|
1526
|
+
* - If `removeOldSchemaData` has an entry for the key, delete it since the new schema has the same property
|
|
1527
|
+
* - If type of the key in the new schema is `object`:
|
|
1528
|
+
* - Store the value from the recursive `sanitizeDataForNewSchema` call in `nestedData[key]`
|
|
1529
|
+
* - Otherwise, check for default or const values:
|
|
1530
|
+
* - Get the old and new `default` values from the schema and check:
|
|
1531
|
+
* - If the new `default` value does not match the form value:
|
|
1532
|
+
* - If the old `default` value DOES match the form value, then:
|
|
1533
|
+
* - Replace `removeOldSchemaData[key]` with the new `default`
|
|
1534
|
+
* - Otherwise, if the new schema is `readOnly` then replace `removeOldSchemaData[key]` with undefined
|
|
1535
|
+
* - Get the old and new `const` values from the schema and check:
|
|
1536
|
+
* - If the new `const` value does not match the form value:
|
|
1537
|
+
* - If the old `const` value DOES match the form value, then:
|
|
1538
|
+
* - Replace `removeOldSchemaData[key]` with the new `const`
|
|
1539
|
+
* - Otherwise, replace `removeOldSchemaData[key]` with undefined
|
|
1540
|
+
* - Once all keys have been processed, return an object built as follows:
|
|
1541
|
+
* - `{ ...removeOldSchemaData, ...nestedData, ...pick(data, keysToKeep) }`
|
|
1542
|
+
* - If the new and old schema types are array and the `data` is an array then:
|
|
1543
|
+
* - If the type of the old and new schema `items` are a non-array objects:
|
|
1544
|
+
* - Retrieve the schema for any refs within each `oldKeySchema.items` and/or `newKeySchema.items`
|
|
1545
|
+
* - If the `type`s of both items are the same (or the old does not have a type):
|
|
1546
|
+
* - If the type is "object", then:
|
|
1547
|
+
* - For each element in the `data` recursively sanitize the data, stopping at `maxItems` if specified
|
|
1548
|
+
* - Otherwise, just return the `data` removing any values after `maxItems` if it is set
|
|
1549
|
+
* - If the type of the old and new schema `items` are booleans of the same value, return `data` as is
|
|
1550
|
+
* - Otherwise return `undefined`
|
|
1551
|
+
*
|
|
1552
|
+
* @param validator - An implementation of the `ValidatorType` interface that will be used when necessary
|
|
1553
|
+
* @param rootSchema - The root JSON schema of the entire form
|
|
1554
|
+
* @param [newSchema] - The new schema for which the data is being sanitized
|
|
1555
|
+
* @param [oldSchema] - The old schema from which the data originated
|
|
1556
|
+
* @param [data={}] - The form data associated with the schema, defaulting to an empty object when undefined
|
|
1557
|
+
* @returns - The new form data, with all the fields uniquely associated with the old schema set
|
|
1558
|
+
* to `undefined`. Will return `undefined` if the new schema is not an object containing properties.
|
|
1559
|
+
*/
|
|
1560
|
+
declare function sanitizeDataForNewSchema<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(validator: ValidatorType<T, S, F>, rootSchema: S, newSchema?: S, oldSchema?: S, data?: any): T;
|
|
1230
1561
|
|
|
1231
1562
|
/** Generates an `IdSchema` object for the `schema`, recursively
|
|
1232
1563
|
*
|
|
@@ -1239,7 +1570,7 @@ declare function retrieveSchema<T = any>(validator: ValidatorType, schema: RJSFS
|
|
|
1239
1570
|
* @param [idSeparator='_'] - The separator to use for the path segments in the id
|
|
1240
1571
|
* @returns - The `IdSchema` object for the `schema`
|
|
1241
1572
|
*/
|
|
1242
|
-
declare function toIdSchema<T = any>(validator: ValidatorType, schema:
|
|
1573
|
+
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>;
|
|
1243
1574
|
|
|
1244
1575
|
/** Generates an `PathSchema` object for the `schema`, recursively
|
|
1245
1576
|
*
|
|
@@ -1250,6 +1581,6 @@ declare function toIdSchema<T = any>(validator: ValidatorType, schema: RJSFSchem
|
|
|
1250
1581
|
* @param [formData] - The current formData, if any, to assist retrieving a schema
|
|
1251
1582
|
* @returns - The `PathSchema` object for the `schema`
|
|
1252
1583
|
*/
|
|
1253
|
-
declare function toPathSchema<T = any>(validator: ValidatorType, schema:
|
|
1584
|
+
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>;
|
|
1254
1585
|
|
|
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,
|
|
1586
|
+
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, ariaDescribedByIds, asNumber, canExpand, createSchemaUtils, dataURItoBlob, deepEquals, descriptionId, 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, localToUTC, mergeDefaultsWithFormData, mergeObjects, mergeSchemas, mergeValidationData, optionId, optionsList, orderProperties, pad, parseDateString, rangeSpec, retrieveSchema, sanitizeDataForNewSchema, schemaRequiresTrueValue, shouldRender, titleId, toConstant, toDateString, toIdSchema, toPathSchema, utcToLocal };
|