@rjsf/utils 5.0.0-beta.9 → 5.0.1
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 +526 -199
- 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,12 +120,12 @@ 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 */
|
|
@@ -131,118 +133,120 @@ declare type FieldErrorProps<T = any, F = any> = {
|
|
|
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<T, F>>;
|
|
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<T, F>>;
|
|
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<T, F>>;
|
|
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<T, F>>;
|
|
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,13 +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;
|
|
399
|
-
/** The
|
|
400
|
-
|
|
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>;
|
|
401
421
|
/** The `registry` object */
|
|
402
|
-
registry: Registry<T, F>;
|
|
422
|
+
registry: Registry<T, S, F>;
|
|
403
423
|
};
|
|
404
424
|
/** The properties that are passed to an ArrayFieldTemplate implementation */
|
|
405
|
-
|
|
425
|
+
type ArrayFieldTemplateProps<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any> = {
|
|
406
426
|
/** A boolean value stating whether new elements can be added to the array */
|
|
407
427
|
canAdd?: boolean;
|
|
408
428
|
/** The className string */
|
|
@@ -412,7 +432,7 @@ declare type ArrayFieldTemplateProps<T = any, F = any> = {
|
|
|
412
432
|
/** An object containing the id for this object & ids for its properties */
|
|
413
433
|
idSchema: IdSchema<T>;
|
|
414
434
|
/** An array of objects representing the items in the array */
|
|
415
|
-
items: ArrayFieldTemplateItemType<T, F>[];
|
|
435
|
+
items: ArrayFieldTemplateItemType<T, S, F>[];
|
|
416
436
|
/** A function that adds a new item to the array */
|
|
417
437
|
onAddClick: (event?: any) => void;
|
|
418
438
|
/** A boolean value stating if the array is read-only */
|
|
@@ -422,22 +442,22 @@ declare type ArrayFieldTemplateProps<T = any, F = any> = {
|
|
|
422
442
|
/** A boolean value stating if the field is hiding its errors */
|
|
423
443
|
hideError?: boolean;
|
|
424
444
|
/** The schema object for this array */
|
|
425
|
-
schema:
|
|
445
|
+
schema: S;
|
|
426
446
|
/** The uiSchema object for this array field */
|
|
427
|
-
uiSchema?: UiSchema<T, F>;
|
|
447
|
+
uiSchema?: UiSchema<T, S, F>;
|
|
428
448
|
/** A string value containing the title for the array */
|
|
429
449
|
title: string;
|
|
430
450
|
/** The `formContext` object that was passed to Form */
|
|
431
451
|
formContext?: F;
|
|
432
452
|
/** The formData for this array */
|
|
433
|
-
formData
|
|
453
|
+
formData?: T;
|
|
434
454
|
/** An array of strings listing all generated error messages from encountered errors for this widget */
|
|
435
455
|
rawErrors?: string[];
|
|
436
456
|
/** The `registry` object */
|
|
437
|
-
registry: Registry<T, F>;
|
|
457
|
+
registry: Registry<T, S, F>;
|
|
438
458
|
};
|
|
439
459
|
/** The properties of each element in the ObjectFieldTemplateProps.properties array */
|
|
440
|
-
|
|
460
|
+
type ObjectFieldTemplatePropertyType = {
|
|
441
461
|
/** The html for the property's content */
|
|
442
462
|
content: React.ReactElement;
|
|
443
463
|
/** A string representing the property name */
|
|
@@ -450,7 +470,7 @@ declare type ObjectFieldTemplatePropertyType = {
|
|
|
450
470
|
hidden: boolean;
|
|
451
471
|
};
|
|
452
472
|
/** The properties that are passed to an ObjectFieldTemplate implementation */
|
|
453
|
-
|
|
473
|
+
type ObjectFieldTemplateProps<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any> = {
|
|
454
474
|
/** A string value containing the title for the object */
|
|
455
475
|
title: string;
|
|
456
476
|
/** A string value containing the description for the object */
|
|
@@ -460,7 +480,7 @@ declare type ObjectFieldTemplateProps<T = any, F = any> = {
|
|
|
460
480
|
/** An array of objects representing the properties in the object */
|
|
461
481
|
properties: ObjectFieldTemplatePropertyType[];
|
|
462
482
|
/** Returns a function that adds a new property to the object (to be used with additionalProperties) */
|
|
463
|
-
onAddClick: (schema:
|
|
483
|
+
onAddClick: (schema: S) => () => void;
|
|
464
484
|
/** A boolean value stating if the object is read-only */
|
|
465
485
|
readonly?: boolean;
|
|
466
486
|
/** A boolean value stating if the object is required */
|
|
@@ -468,26 +488,31 @@ declare type ObjectFieldTemplateProps<T = any, F = any> = {
|
|
|
468
488
|
/** A boolean value stating if the field is hiding its errors */
|
|
469
489
|
hideError?: boolean;
|
|
470
490
|
/** The schema object for this object */
|
|
471
|
-
schema:
|
|
491
|
+
schema: S;
|
|
472
492
|
/** The uiSchema object for this object field */
|
|
473
|
-
uiSchema?: UiSchema<T, F>;
|
|
493
|
+
uiSchema?: UiSchema<T, S, F>;
|
|
474
494
|
/** An object containing the id for this object & ids for its properties */
|
|
475
495
|
idSchema: IdSchema<T>;
|
|
476
496
|
/** The form data for the object */
|
|
477
|
-
formData
|
|
497
|
+
formData?: T;
|
|
478
498
|
/** The `formContext` object that was passed to Form */
|
|
479
499
|
formContext?: F;
|
|
480
500
|
/** The `registry` object */
|
|
481
|
-
registry: Registry<T, F>;
|
|
501
|
+
registry: Registry<T, S, F>;
|
|
482
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">;
|
|
483
508
|
/** The properties that are passed to a Widget implementation */
|
|
484
|
-
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">> {
|
|
485
510
|
/** The generated id for this widget */
|
|
486
511
|
id: string;
|
|
487
512
|
/** The JSONSchema subschema object for this widget */
|
|
488
|
-
schema:
|
|
513
|
+
schema: S;
|
|
489
514
|
/** The uiSchema for this widget */
|
|
490
|
-
uiSchema?: UiSchema<T, F>;
|
|
515
|
+
uiSchema?: UiSchema<T, S, F>;
|
|
491
516
|
/** The current value for this widget */
|
|
492
517
|
value: any;
|
|
493
518
|
/** The required status of this widget */
|
|
@@ -505,9 +530,9 @@ interface WidgetProps<T = any, F = any> extends GenericObjectType, Pick<React.HT
|
|
|
505
530
|
/** A map of UI Options passed as a prop to the component, including the optional `enumOptions`
|
|
506
531
|
* which is a special case on top of `UIOptionsType` needed only by widgets
|
|
507
532
|
*/
|
|
508
|
-
options: NonNullable<UIOptionsType<T, F>> & {
|
|
533
|
+
options: NonNullable<UIOptionsType<T, S, F>> & {
|
|
509
534
|
/** The enum options list for a type that supports them */
|
|
510
|
-
enumOptions?: EnumOptionsType[];
|
|
535
|
+
enumOptions?: EnumOptionsType<S>[];
|
|
511
536
|
};
|
|
512
537
|
/** The `formContext` object that you passed to `Form` */
|
|
513
538
|
formContext?: F;
|
|
@@ -524,26 +549,30 @@ interface WidgetProps<T = any, F = any> extends GenericObjectType, Pick<React.HT
|
|
|
524
549
|
/** An array of strings listing all generated error messages from encountered errors for this widget */
|
|
525
550
|
rawErrors?: string[];
|
|
526
551
|
/** The `registry` object */
|
|
527
|
-
registry: Registry<T, F>;
|
|
552
|
+
registry: Registry<T, S, F>;
|
|
528
553
|
}
|
|
529
554
|
/** The definition of a React-based Widget component */
|
|
530
|
-
|
|
555
|
+
type Widget<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any> = React.ComponentType<WidgetProps<T, S, F>>;
|
|
531
556
|
/** The type that defines the props used by the Submit button */
|
|
532
|
-
|
|
557
|
+
type SubmitButtonProps<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any> = {
|
|
533
558
|
/** The uiSchema for this widget */
|
|
534
|
-
uiSchema?: UiSchema<T, F>;
|
|
559
|
+
uiSchema?: UiSchema<T, S, F>;
|
|
560
|
+
/** The `registry` object */
|
|
561
|
+
registry: Registry<T, S, F>;
|
|
535
562
|
};
|
|
536
563
|
/** The type that defines the props for an Icon button, extending from a basic HTML button attributes */
|
|
537
|
-
|
|
564
|
+
type IconButtonProps<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any> = React.ButtonHTMLAttributes<HTMLButtonElement> & {
|
|
538
565
|
/** An alternative specification for the type of the icon button */
|
|
539
566
|
iconType?: string;
|
|
540
567
|
/** The name representation or actual react element implementation for the icon */
|
|
541
568
|
icon?: string | React.ReactElement;
|
|
542
569
|
/** The uiSchema for this widget */
|
|
543
|
-
uiSchema?: UiSchema<T, F>;
|
|
570
|
+
uiSchema?: UiSchema<T, S, F>;
|
|
571
|
+
/** The `registry` object */
|
|
572
|
+
registry: Registry<T, S, F>;
|
|
544
573
|
};
|
|
545
574
|
/** The type that defines how to change the behavior of the submit button for the form */
|
|
546
|
-
|
|
575
|
+
type UISchemaSubmitButtonOptions = {
|
|
547
576
|
/** The text of the submit button. Set to "Submit" by default */
|
|
548
577
|
submitText?: string;
|
|
549
578
|
/** Flag, if `true`, removes the submit button completely from the form */
|
|
@@ -557,24 +586,26 @@ declare type UISchemaSubmitButtonOptions = {
|
|
|
557
586
|
};
|
|
558
587
|
};
|
|
559
588
|
/** This type represents an element used to render an enum option */
|
|
560
|
-
|
|
589
|
+
type EnumOptionsType<S extends StrictRJSFSchema = RJSFSchema> = {
|
|
561
590
|
/** The value for the enum option */
|
|
562
591
|
value: any;
|
|
563
592
|
/** The label for the enum options */
|
|
564
593
|
label: string;
|
|
565
594
|
/** The schema associated with the enum option when the option represents a `oneOf` or `anyOf` choice */
|
|
566
|
-
schema?:
|
|
595
|
+
schema?: S;
|
|
567
596
|
};
|
|
568
597
|
/** This type remaps the keys of `Type` to prepend `ui:` onto them. As a result it does not need to be exported */
|
|
569
|
-
|
|
598
|
+
type MakeUIType<Type> = {
|
|
570
599
|
[Property in keyof Type as `ui:${string & Property}`]: Type[Property];
|
|
571
600
|
};
|
|
572
601
|
/** This type represents all the known supported options in the `ui:options` property, kept separate in order to
|
|
573
602
|
* remap the keys. It also contains all the properties, optionally, of `TemplatesType` except "ButtonTemplates"
|
|
574
603
|
*/
|
|
575
|
-
|
|
604
|
+
type UIOptionsBaseType<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any> = Partial<Omit<TemplatesType<T, S, F>, "ButtonTemplates">> & {
|
|
576
605
|
/** Any classnames that the user wants to be applied to a field in the ui */
|
|
577
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>;
|
|
578
609
|
/** We know that for title, it will be a string, if it is provided */
|
|
579
610
|
title?: string;
|
|
580
611
|
/** We know that for description, it will be a string, if it is provided */
|
|
@@ -620,40 +651,48 @@ declare type UIOptionsBaseType<T = any, F = any> = Partial<Omit<TemplatesType<T,
|
|
|
620
651
|
/** Allows RJSF to override the default widget implementation by specifying either the name of a widget that is used
|
|
621
652
|
* to look up an implementation from the `widgets` list or an actual one-off widget implementation itself
|
|
622
653
|
*/
|
|
623
|
-
widget?: Widget<T, F> | string;
|
|
654
|
+
widget?: Widget<T, S, F> | string;
|
|
624
655
|
/** When using `additionalProperties`, key collision is prevented by appending a unique integer to the duplicate key.
|
|
625
656
|
* This option allows you to change the separator between the original key name and the integer. Default is "-"
|
|
626
657
|
*/
|
|
627
658
|
duplicateKeySuffixSeparator?: string;
|
|
628
659
|
};
|
|
629
660
|
/** The type that represents the Options potentially provided by `ui:options` */
|
|
630
|
-
|
|
661
|
+
type UIOptionsType<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any> = UIOptionsBaseType<T, S, F> & {
|
|
631
662
|
/** Anything else will be one of these types */
|
|
632
663
|
[key: string]: boolean | number | string | object | any[] | null | undefined;
|
|
633
664
|
};
|
|
634
665
|
/** Type describing the well-known properties of the `UiSchema` while also supporting all user defined properties,
|
|
635
666
|
* starting with `ui:`.
|
|
636
667
|
*/
|
|
637
|
-
|
|
668
|
+
type UiSchema<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any> = GenericObjectType & MakeUIType<UIOptionsBaseType<T, S, F>> & {
|
|
638
669
|
/** Allows the form to generate a unique prefix for the `Form`'s root prefix */
|
|
639
670
|
"ui:rootFieldId"?: string;
|
|
640
671
|
/** Allows RJSF to override the default field implementation by specifying either the name of a field that is used
|
|
641
672
|
* to look up an implementation from the `fields` list or an actual one-off `Field` component implementation itself
|
|
642
673
|
*/
|
|
643
|
-
"ui:field"?: Field<T, F> | string;
|
|
644
|
-
/**
|
|
645
|
-
|
|
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>;
|
|
646
685
|
};
|
|
647
|
-
/** A `CustomValidator` function takes in a `formData` and `
|
|
648
|
-
* 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`
|
|
649
688
|
*/
|
|
650
|
-
|
|
651
|
-
/** An `ErrorTransformer` function will take in a list of `errors` and potentially return a
|
|
652
|
-
* 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
|
|
653
692
|
*/
|
|
654
|
-
|
|
693
|
+
type ErrorTransformer<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any> = (errors: RJSFValidationError[], uiSchema?: UiSchema<T, S, F>) => RJSFValidationError[];
|
|
655
694
|
/** The type that describes the data that is returned from the `ValidatorType.validateFormData()` function */
|
|
656
|
-
|
|
695
|
+
type ValidationData<T> = {
|
|
657
696
|
/** The validation errors as a list of `RJSFValidationError` objects */
|
|
658
697
|
errors: RJSFValidationError[];
|
|
659
698
|
/** The validation errors in the form of an `ErrorSchema` */
|
|
@@ -662,7 +701,7 @@ declare type ValidationData<T> = {
|
|
|
662
701
|
/** The interface that describes the validation functions that are provided by a Validator implementation used by the
|
|
663
702
|
* schema utilities.
|
|
664
703
|
*/
|
|
665
|
-
interface ValidatorType<T = any> {
|
|
704
|
+
interface ValidatorType<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any> {
|
|
666
705
|
/** This function processes the `formData` with an optional user contributed `customValidate` function, which receives
|
|
667
706
|
* the form data and a `errorHandler` function that will be used to add custom validation errors for each field. Also
|
|
668
707
|
* supports a `transformErrors` function that will take the raw AJV validation errors, prior to custom validation and
|
|
@@ -672,8 +711,9 @@ interface ValidatorType<T = any> {
|
|
|
672
711
|
* @param schema - The schema against which to validate the form data
|
|
673
712
|
* @param [customValidate] - An optional function that is used to perform custom validation
|
|
674
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`
|
|
675
715
|
*/
|
|
676
|
-
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>;
|
|
677
717
|
/** Converts an `errorSchema` into a list of `RJSFValidationErrors`
|
|
678
718
|
*
|
|
679
719
|
* @param errorSchema - The `ErrorSchema` instance to convert
|
|
@@ -685,22 +725,32 @@ interface ValidatorType<T = any> {
|
|
|
685
725
|
* false.
|
|
686
726
|
*
|
|
687
727
|
* @param schema - The schema against which to validate the form data * @param schema
|
|
688
|
-
* @param formData
|
|
728
|
+
* @param formData - The form data to validate
|
|
689
729
|
* @param rootSchema - The root schema used to provide $ref resolutions
|
|
690
730
|
*/
|
|
691
|
-
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
|
+
};
|
|
692
742
|
}
|
|
693
743
|
/** The `SchemaUtilsType` interface provides a wrapper around the publicly exported APIs in the `@rjsf/utils/schema`
|
|
694
744
|
* directory such that one does not have to explicitly pass the `validator` or `rootSchema` to each method. Since both
|
|
695
745
|
* the `validator` and `rootSchema` generally does not change across a `Form`, this allows for providing a simplified
|
|
696
746
|
* set of APIs to the `@rjsf/core` components and the various themes as well.
|
|
697
747
|
*/
|
|
698
|
-
interface SchemaUtilsType<T = any> {
|
|
748
|
+
interface SchemaUtilsType<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any> {
|
|
699
749
|
/** Returns the `ValidatorType` in the `SchemaUtilsType`
|
|
700
750
|
*
|
|
701
751
|
* @returns - The `ValidatorType`
|
|
702
752
|
*/
|
|
703
|
-
getValidator(): ValidatorType<T>;
|
|
753
|
+
getValidator(): ValidatorType<T, S, F>;
|
|
704
754
|
/** Determines whether either the `validator` and `rootSchema` differ from the ones associated with this instance of
|
|
705
755
|
* the `SchemaUtilsType`. If either `validator` or `rootSchema` are falsy, then return false to prevent the creation
|
|
706
756
|
* of a new `SchemaUtilsType` with incomplete properties.
|
|
@@ -709,16 +759,18 @@ interface SchemaUtilsType<T = any> {
|
|
|
709
759
|
* @param rootSchema - The root schema that will be compared against the current one
|
|
710
760
|
* @returns - True if the `SchemaUtilsType` differs from the given `validator` or `rootSchema`
|
|
711
761
|
*/
|
|
712
|
-
doesSchemaUtilsDiffer(validator: ValidatorType, rootSchema:
|
|
762
|
+
doesSchemaUtilsDiffer(validator: ValidatorType<T, S, F>, rootSchema: S): boolean;
|
|
713
763
|
/** Returns the superset of `formData` that includes the given set updated to include any missing fields that have
|
|
714
764
|
* computed to have defaults provided in the `schema`.
|
|
715
765
|
*
|
|
716
766
|
* @param schema - The schema for which the default state is desired
|
|
717
767
|
* @param [formData] - The current formData, if any, onto which to provide any missing defaults
|
|
718
|
-
* @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.
|
|
719
771
|
* @returns - The resulting `formData` with all the defaults provided
|
|
720
772
|
*/
|
|
721
|
-
getDefaultFormState(schema:
|
|
773
|
+
getDefaultFormState(schema: S, formData?: T, includeUndefinedValues?: boolean | "excludeObjectChildren"): T | T[] | undefined;
|
|
722
774
|
/** Determines whether the combination of `schema` and `uiSchema` properties indicates that the label for the `schema`
|
|
723
775
|
* should be displayed in a UI.
|
|
724
776
|
*
|
|
@@ -726,39 +778,60 @@ interface SchemaUtilsType<T = any> {
|
|
|
726
778
|
* @param [uiSchema] - The UI schema from which to derive potentially displayable information
|
|
727
779
|
* @returns - True if the label should be displayed or false if it should not
|
|
728
780
|
*/
|
|
729
|
-
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;
|
|
730
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.
|
|
731
804
|
*
|
|
732
805
|
* @param formData - The current formData, if any, onto which to provide any missing defaults
|
|
733
806
|
* @param options - The list of options to find a matching options from
|
|
734
807
|
* @returns - The index of the matched option or 0 if none is available
|
|
808
|
+
* @deprecated
|
|
735
809
|
*/
|
|
736
|
-
getMatchingOption(formData: T, options:
|
|
810
|
+
getMatchingOption(formData: T | undefined, options: S[]): number;
|
|
737
811
|
/** Checks to see if the `schema` and `uiSchema` combination represents an array of files
|
|
738
812
|
*
|
|
739
813
|
* @param schema - The schema for which check for array of files flag is desired
|
|
740
814
|
* @param [uiSchema] - The UI schema from which to check the widget
|
|
741
815
|
* @returns - True if schema/uiSchema contains an array of files, otherwise false
|
|
742
816
|
*/
|
|
743
|
-
isFilesArray
|
|
817
|
+
isFilesArray(schema: S, uiSchema?: UiSchema<T, S, F>): boolean;
|
|
744
818
|
/** Checks to see if the `schema` combination represents a multi-select
|
|
745
819
|
*
|
|
746
820
|
* @param schema - The schema for which check for a multi-select flag is desired
|
|
747
821
|
* @returns - True if schema contains a multi-select, otherwise false
|
|
748
822
|
*/
|
|
749
|
-
isMultiSelect(schema:
|
|
823
|
+
isMultiSelect(schema: S): boolean;
|
|
750
824
|
/** Checks to see if the `schema` combination represents a select
|
|
751
825
|
*
|
|
752
826
|
* @param schema - The schema for which check for a select flag is desired
|
|
753
827
|
* @returns - True if schema contains a select, otherwise false
|
|
754
828
|
*/
|
|
755
|
-
isSelect(schema:
|
|
829
|
+
isSelect(schema: S): boolean;
|
|
756
830
|
/** Merges the errors in `additionalErrorSchema` into the existing `validationData` by combining the hierarchies in the
|
|
757
831
|
* two `ErrorSchema`s and then appending the error list from the `additionalErrorSchema` obtained by calling
|
|
758
832
|
* `validator.toErrorList()` onto the `errors` in the `validationData`. If no `additionalErrorSchema` is passed, then
|
|
759
833
|
* `validationData` is returned.
|
|
760
834
|
*
|
|
761
|
-
* @param validator - The validator used to convert an ErrorSchema to a list of errors
|
|
762
835
|
* @param validationData - The current `ValidationData` into which to merge the additional errors
|
|
763
836
|
* @param [additionalErrorSchema] - The additional set of errors
|
|
764
837
|
* @returns - The `validationData` with the additional errors from `additionalErrorSchema` merged into it, if provided.
|
|
@@ -769,10 +842,22 @@ interface SchemaUtilsType<T = any> {
|
|
|
769
842
|
* recursive resolution.
|
|
770
843
|
*
|
|
771
844
|
* @param schema - The schema for which retrieving a schema is desired
|
|
772
|
-
* @param [
|
|
845
|
+
* @param [formData] - The current formData, if any, to assist retrieving a schema
|
|
773
846
|
* @returns - The schema having its conditions, additional properties, references and dependencies resolved
|
|
774
847
|
*/
|
|
775
|
-
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;
|
|
776
861
|
/** Generates an `IdSchema` object for the `schema`, recursively
|
|
777
862
|
*
|
|
778
863
|
* @param schema - The schema for which the display label flag is desired
|
|
@@ -782,7 +867,7 @@ interface SchemaUtilsType<T = any> {
|
|
|
782
867
|
* @param [idSeparator='_'] - The separator to use for the path segments in the id
|
|
783
868
|
* @returns - The `IdSchema` object for the `schema`
|
|
784
869
|
*/
|
|
785
|
-
toIdSchema(schema:
|
|
870
|
+
toIdSchema(schema: S, id?: string, formData?: T, idPrefix?: string, idSeparator?: string): IdSchema<T>;
|
|
786
871
|
/** Generates an `PathSchema` object for the `schema`, recursively
|
|
787
872
|
*
|
|
788
873
|
* @param schema - The schema for which the display label flag is desired
|
|
@@ -790,7 +875,7 @@ interface SchemaUtilsType<T = any> {
|
|
|
790
875
|
* @param [formData] - The current formData, if any, onto which to provide any missing defaults
|
|
791
876
|
* @returns - The `PathSchema` object for the `schema`
|
|
792
877
|
*/
|
|
793
|
-
toPathSchema(schema:
|
|
878
|
+
toPathSchema(schema: S, name?: string, formData?: T): PathSchema<T>;
|
|
794
879
|
}
|
|
795
880
|
|
|
796
881
|
/** Checks the schema to see if it is allowing additional items, by verifying that `schema.additionalItems` is an
|
|
@@ -799,7 +884,7 @@ interface SchemaUtilsType<T = any> {
|
|
|
799
884
|
* @param schema - The schema object to check
|
|
800
885
|
* @returns - True if additional items is allowed, otherwise false
|
|
801
886
|
*/
|
|
802
|
-
declare function allowAdditionalItems(schema:
|
|
887
|
+
declare function allowAdditionalItems<S extends StrictRJSFSchema = RJSFSchema>(schema: S): boolean;
|
|
803
888
|
|
|
804
889
|
/** Attempts to convert the string into a number. If an empty string is provided, then `undefined` is returned. If a
|
|
805
890
|
* `null` is provided, it is returned. If the string ends in a `.` then the string is returned because the user may be
|
|
@@ -821,7 +906,7 @@ declare function asNumber(value: string | null): string | number | null | undefi
|
|
|
821
906
|
* @param [formData] - The formData for the field
|
|
822
907
|
* @returns - True if the schema element has additionalProperties, is expandable, and not at the maxProperties limit
|
|
823
908
|
*/
|
|
824
|
-
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;
|
|
825
910
|
|
|
826
911
|
/** Creates a `SchemaUtilsType` interface that is based around the given `validator` and `rootSchema` parameters. The
|
|
827
912
|
* resulting interface implementation will forward the `validator` and `rootSchema` to all the wrapped APIs.
|
|
@@ -830,7 +915,7 @@ declare function canExpand<T = any, F = any>(schema: RJSFSchema, uiSchema?: UiSc
|
|
|
830
915
|
* @param rootSchema - The root schema that will be forwarded to all the APIs
|
|
831
916
|
* @returns - An implementation of a `SchemaUtilsType` interface
|
|
832
917
|
*/
|
|
833
|
-
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>;
|
|
834
919
|
|
|
835
920
|
/** Given the `FileReader.readAsDataURL()` based `dataURI` extracts that data into an actual Blob along with the name
|
|
836
921
|
* of that Blob if provided in the URL. If no name is provided, then the name falls back to `unknown`.
|
|
@@ -852,6 +937,124 @@ declare function dataURItoBlob(dataURI: string): {
|
|
|
852
937
|
*/
|
|
853
938
|
declare function deepEquals(a: any, b: any): boolean;
|
|
854
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
|
+
|
|
855
1058
|
/** Given the name of a `$ref` from within a schema, using the `rootSchema`, look up and return the sub-schema using the
|
|
856
1059
|
* path provided by that reference. If `#` is not the first character of the reference, or the path does not exist in
|
|
857
1060
|
* the schema, then throw an Error. Otherwise return the sub-schema. Also deals with nested `$ref`s in the sub-schema.
|
|
@@ -861,7 +1064,7 @@ declare function deepEquals(a: any, b: any): boolean;
|
|
|
861
1064
|
* @returns - The sub-schema within the `rootSchema` which matches the `$ref` if it exists
|
|
862
1065
|
* @throws - Error indicating that no schema for that reference exists
|
|
863
1066
|
*/
|
|
864
|
-
declare function findSchemaDefinition($ref?: string, rootSchema?:
|
|
1067
|
+
declare function findSchemaDefinition<S extends StrictRJSFSchema = RJSFSchema>($ref?: string, rootSchema?: S): S;
|
|
865
1068
|
|
|
866
1069
|
/** Using the `schema`, `defaultType` and `options`, extract out the props for the <input> element that make sense.
|
|
867
1070
|
*
|
|
@@ -871,7 +1074,7 @@ declare function findSchemaDefinition($ref?: string, rootSchema?: RJSFSchema): R
|
|
|
871
1074
|
* @param [autoDefaultStepAny=true] - Determines whether to auto-default step=any when the type is number and no step
|
|
872
1075
|
* @returns - The extracted `InputPropsType` object
|
|
873
1076
|
*/
|
|
874
|
-
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;
|
|
875
1078
|
|
|
876
1079
|
/** Gets the type of a given `schema`. If the type is not explicitly defined, then an attempt is made to infer it from
|
|
877
1080
|
* other elements of the schema as follows:
|
|
@@ -884,14 +1087,14 @@ declare function getInputProps<T = any, F = any>(schema: RJSFSchema, defaultType
|
|
|
884
1087
|
* @param schema - The schema for which to get the type
|
|
885
1088
|
* @returns - The type of the schema
|
|
886
1089
|
*/
|
|
887
|
-
declare function getSchemaType(schema:
|
|
1090
|
+
declare function getSchemaType<S extends StrictRJSFSchema = RJSFSchema>(schema: S): string | string[] | undefined;
|
|
888
1091
|
|
|
889
1092
|
/** Extracts any `ui:submitButtonOptions` from the `uiSchema` and merges them onto the `DEFAULT_OPTIONS`
|
|
890
1093
|
*
|
|
891
1094
|
* @param [uiSchema={}] - the UI Schema from which to extract submit button props
|
|
892
1095
|
* @returns - The merging of the `DEFAULT_OPTIONS` with any custom ones
|
|
893
1096
|
*/
|
|
894
|
-
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;
|
|
895
1098
|
|
|
896
1099
|
/** Returns the template with the given `name` from either the `uiSchema` if it is defined or from the `registry`
|
|
897
1100
|
* otherwise. NOTE, since `ButtonTemplates` are not overridden in `uiSchema` only those in the `registry` are returned.
|
|
@@ -901,15 +1104,15 @@ declare function getSubmitButtonOptions<T = any, F = any>(uiSchema?: UiSchema<T,
|
|
|
901
1104
|
* @param [uiOptions={}] - The `UIOptionsType` from which to read an alternate template
|
|
902
1105
|
* @returns - The template from either the `uiSchema` or `registry` for the `name`
|
|
903
1106
|
*/
|
|
904
|
-
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];
|
|
905
1108
|
|
|
906
1109
|
/** Get all passed options from ui:options, and ui:<optionName>, returning them in an object with the `ui:`
|
|
907
1110
|
* stripped off.
|
|
908
1111
|
*
|
|
909
1112
|
* @param [uiSchema={}] - The UI Schema from which to get any `ui:xxx` options
|
|
910
|
-
* @returns - An object containing all
|
|
1113
|
+
* @returns - An object containing all the `ui:xxx` options with the stripped off
|
|
911
1114
|
*/
|
|
912
|
-
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>;
|
|
913
1116
|
|
|
914
1117
|
/** Given a schema representing a field to render and either the name or actual `Widget` implementation, returns the
|
|
915
1118
|
* React component that is used to render the widget. If the `widget` is already a React component, then it is wrapped
|
|
@@ -922,7 +1125,7 @@ declare function getUiOptions<T = any, F = any>(uiSchema?: UiSchema<T, F>): UIOp
|
|
|
922
1125
|
* @returns - The `Widget` component to use
|
|
923
1126
|
* @throws - An error if there is no `Widget` component that can be returned
|
|
924
1127
|
*/
|
|
925
|
-
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>;
|
|
926
1129
|
|
|
927
1130
|
/** Given a specific `value` attempts to guess the type of a schema element. In the case where we have to implicitly
|
|
928
1131
|
* create a schema, it is useful to know what type to use based on the data we are defining.
|
|
@@ -940,7 +1143,54 @@ declare function guessType(value: any): "array" | "string" | "null" | "boolean"
|
|
|
940
1143
|
* @param [registeredWidgets={}] - A registry of widget name to `Widget` implementation
|
|
941
1144
|
* @returns - True if the widget exists, false otherwise
|
|
942
1145
|
*/
|
|
943
|
-
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;
|
|
944
1194
|
|
|
945
1195
|
/** This function checks if the given `schema` matches a single constant value. This happens when either the schema has
|
|
946
1196
|
* an `enum` array with a single value or there is a `const` defined.
|
|
@@ -948,14 +1198,14 @@ declare function hasWidget<T = any, F = any>(schema: RJSFSchema, widget: Widget<
|
|
|
948
1198
|
* @param schema - The schema for a field
|
|
949
1199
|
* @returns - True if the `schema` has a single constant value, false otherwise
|
|
950
1200
|
*/
|
|
951
|
-
declare function isConstant(schema:
|
|
1201
|
+
declare function isConstant<S extends StrictRJSFSchema = RJSFSchema>(schema: S): boolean;
|
|
952
1202
|
|
|
953
1203
|
/** Checks to see if the `uiSchema` contains the `widget` field and that the widget is not `hidden`
|
|
954
1204
|
*
|
|
955
1205
|
* @param uiSchema - The UI Schema from which to detect if it is customized
|
|
956
1206
|
* @returns - True if the `uiSchema` describes a custom widget, false otherwise
|
|
957
1207
|
*/
|
|
958
|
-
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;
|
|
959
1209
|
|
|
960
1210
|
/** Detects whether the given `schema` contains fixed items. This is the case when `schema.items` is a non-empty array
|
|
961
1211
|
* that only contains objects.
|
|
@@ -963,7 +1213,7 @@ declare function isCustomWidget<T = any, F = any>(uiSchema?: UiSchema<T, F>): bo
|
|
|
963
1213
|
* @param schema - The schema in which to check for fixed items
|
|
964
1214
|
* @returns - True if there are fixed items in the schema, false otherwise
|
|
965
1215
|
*/
|
|
966
|
-
declare function isFixedItems(schema:
|
|
1216
|
+
declare function isFixedItems<S extends StrictRJSFSchema = RJSFSchema>(schema: S): boolean;
|
|
967
1217
|
|
|
968
1218
|
/** Determines whether a `thing` is an object for the purposes of RSJF. In this case, `thing` is an object if it has
|
|
969
1219
|
* the type `object` but is NOT null, an array or a File.
|
|
@@ -990,20 +1240,22 @@ declare function localToUTC(dateString: string): string | undefined;
|
|
|
990
1240
|
* - when the array is not set in form data, the default is copied over
|
|
991
1241
|
* - scalars are overwritten/set by form data
|
|
992
1242
|
*
|
|
993
|
-
* @param defaults - The defaults to merge
|
|
994
|
-
* @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
|
|
995
1245
|
* @returns - The resulting merged form data with defaults
|
|
996
1246
|
*/
|
|
997
|
-
declare function mergeDefaultsWithFormData<T = any>(defaults
|
|
1247
|
+
declare function mergeDefaultsWithFormData<T = any>(defaults?: T, formData?: T): T | undefined;
|
|
998
1248
|
|
|
999
1249
|
/** Recursively merge deeply nested objects.
|
|
1000
1250
|
*
|
|
1001
1251
|
* @param obj1 - The first object to merge
|
|
1002
1252
|
* @param obj2 - The second object to merge
|
|
1003
|
-
* @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.
|
|
1004
1256
|
* @returns - A new object that is the merge of the two given objects
|
|
1005
1257
|
*/
|
|
1006
|
-
declare function mergeObjects(obj1: GenericObjectType, obj2: GenericObjectType, concatArrays?: boolean): GenericObjectType;
|
|
1258
|
+
declare function mergeObjects(obj1: GenericObjectType, obj2: GenericObjectType, concatArrays?: boolean | "preventDuplicates"): GenericObjectType;
|
|
1007
1259
|
|
|
1008
1260
|
/** Recursively merge deeply nested schemas. The difference between `mergeSchemas` and `mergeObjects` is that
|
|
1009
1261
|
* `mergeSchemas` only concats arrays for values under the 'required' keyword, and when it does, it doesn't include
|
|
@@ -1023,7 +1275,7 @@ declare function mergeSchemas(obj1: GenericObjectType, obj2: GenericObjectType):
|
|
|
1023
1275
|
* @param schema - The schema from which to extract the options list
|
|
1024
1276
|
* @returns - The list of options from the schema
|
|
1025
1277
|
*/
|
|
1026
|
-
declare function optionsList(schema:
|
|
1278
|
+
declare function optionsList<S extends StrictRJSFSchema = RJSFSchema>(schema: S): EnumOptionsType<S>[] | undefined;
|
|
1027
1279
|
|
|
1028
1280
|
/** Given a list of `properties` and an `order` list, returns a list that contains the `properties` ordered correctly.
|
|
1029
1281
|
* If `order` is not an array, then the untouched `properties` list is returned. Otherwise `properties` is ordered per
|
|
@@ -1054,24 +1306,13 @@ declare function pad(num: number, width: number): string;
|
|
|
1054
1306
|
*/
|
|
1055
1307
|
declare function parseDateString(dateString?: string, includeTime?: boolean): DateObject;
|
|
1056
1308
|
|
|
1057
|
-
/** Returns the real value for a select widget due to a silly limitation in the DOM which causes option change event
|
|
1058
|
-
* values to always be retrieved as strings. Uses the `schema` to help determine the value's true type. If the value is
|
|
1059
|
-
* an empty string, then the `emptyValue` from the `options` is returned, falling back to undefined.
|
|
1060
|
-
*
|
|
1061
|
-
* @param schema - The schema to used to determine the value's true type
|
|
1062
|
-
* @param [value] - The value to convert
|
|
1063
|
-
* @param [options] - The UIOptionsType from which to potentially extract the emptyValue
|
|
1064
|
-
* @returns - The `value` converted to the proper type
|
|
1065
|
-
*/
|
|
1066
|
-
declare function processSelectValue<T = any, F = any>(schema: RJSFSchema, value?: any, options?: UIOptionsType<T, F>): any;
|
|
1067
|
-
|
|
1068
1309
|
/** Extracts the range spec information `{ step?: number, min?: number, max?: number }` that can be spread onto an HTML
|
|
1069
1310
|
* input from the range analog in the schema `{ multipleOf?: number, minimum?: number, maximum?: number }`.
|
|
1070
1311
|
*
|
|
1071
1312
|
* @param schema - The schema from which to extract the range spec
|
|
1072
1313
|
* @returns - A range specification from the schema
|
|
1073
1314
|
*/
|
|
1074
|
-
declare function rangeSpec(schema:
|
|
1315
|
+
declare function rangeSpec<S extends StrictRJSFSchema = RJSFSchema>(schema: S): RangeSpecType;
|
|
1075
1316
|
|
|
1076
1317
|
/** Check to see if a `schema` specifies that a value must be true. This happens when:
|
|
1077
1318
|
* - `schema.const` is truthy
|
|
@@ -1082,7 +1323,7 @@ declare function rangeSpec(schema: RJSFSchema): RangeSpecType;
|
|
|
1082
1323
|
* @param schema - The schema to check
|
|
1083
1324
|
* @returns - True if the schema specifies a value that must be true, false otherwise
|
|
1084
1325
|
*/
|
|
1085
|
-
declare function schemaRequiresTrueValue(schema:
|
|
1326
|
+
declare function schemaRequiresTrueValue<S extends StrictRJSFSchema = RJSFSchema>(schema: S): boolean;
|
|
1086
1327
|
|
|
1087
1328
|
/** Determines whether the given `component` should be rerendered by comparing its current set of props and state
|
|
1088
1329
|
* against the next set. If either of those two sets are not the same, then the component should be rerendered.
|
|
@@ -1101,7 +1342,7 @@ declare function shouldRender(component: React.Component, nextProps: any, nextSt
|
|
|
1101
1342
|
* @returns - The constant value for the schema
|
|
1102
1343
|
* @throws - Error when the schema does not have a constant value
|
|
1103
1344
|
*/
|
|
1104
|
-
declare function toConstant(schema:
|
|
1345
|
+
declare function toConstant<S extends StrictRJSFSchema = RJSFSchema>(schema: S): json_schema.JSONSchema7Type | undefined;
|
|
1105
1346
|
|
|
1106
1347
|
/** Returns a UTC date string for the given `dateObject`. If `time` is false, then the time portion of the string is
|
|
1107
1348
|
* removed.
|
|
@@ -1154,10 +1395,12 @@ declare const UI_OPTIONS_KEY = "ui:options";
|
|
|
1154
1395
|
* @param theSchema - The schema for which the default state is desired
|
|
1155
1396
|
* @param [formData] - The current formData, if any, onto which to provide any missing defaults
|
|
1156
1397
|
* @param [rootSchema] - The root schema, used to primarily to look up `$ref`s
|
|
1157
|
-
* @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.
|
|
1158
1401
|
* @returns - The resulting `formData` with all the defaults provided
|
|
1159
1402
|
*/
|
|
1160
|
-
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;
|
|
1161
1404
|
|
|
1162
1405
|
/** Determines whether the combination of `schema` and `uiSchema` properties indicates that the label for the `schema`
|
|
1163
1406
|
* should be displayed in a UI.
|
|
@@ -1168,17 +1411,52 @@ declare function getDefaultFormState<T = any>(validator: ValidatorType, theSchem
|
|
|
1168
1411
|
* @param [rootSchema] - The root schema, used to primarily to look up `$ref`s
|
|
1169
1412
|
* @returns - True if the label should be displayed or false if it should not
|
|
1170
1413
|
*/
|
|
1171
|
-
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;
|
|
1172
1448
|
|
|
1173
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.
|
|
1174
1451
|
*
|
|
1175
1452
|
* @param validator - An implementation of the `ValidatorType` interface that will be used when necessary
|
|
1176
1453
|
* @param formData - The current formData, if any, used to figure out a match
|
|
1177
1454
|
* @param options - The list of options to find a matching options from
|
|
1178
1455
|
* @param rootSchema - The root schema, used to primarily to look up `$ref`s
|
|
1179
1456
|
* @returns - The index of the matched option or 0 if none is available
|
|
1457
|
+
* @deprecated
|
|
1180
1458
|
*/
|
|
1181
|
-
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;
|
|
1182
1460
|
|
|
1183
1461
|
/** Checks to see if the `schema` and `uiSchema` combination represents an array of files
|
|
1184
1462
|
*
|
|
@@ -1188,7 +1466,7 @@ declare function getMatchingOption<T = any>(validator: ValidatorType, formData:
|
|
|
1188
1466
|
* @param [rootSchema] - The root schema, used to primarily to look up `$ref`s
|
|
1189
1467
|
* @returns - True if schema/uiSchema contains an array of files, otherwise false
|
|
1190
1468
|
*/
|
|
1191
|
-
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;
|
|
1192
1470
|
|
|
1193
1471
|
/** Checks to see if the `schema` combination represents a multi-select
|
|
1194
1472
|
*
|
|
@@ -1197,7 +1475,7 @@ declare function isFilesArray<T = any, F = any>(validator: ValidatorType, schema
|
|
|
1197
1475
|
* @param [rootSchema] - The root schema, used to primarily to look up `$ref`s
|
|
1198
1476
|
* @returns - True if schema contains a multi-select, otherwise false
|
|
1199
1477
|
*/
|
|
1200
|
-
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;
|
|
1201
1479
|
|
|
1202
1480
|
/** Checks to see if the `schema` combination represents a select
|
|
1203
1481
|
*
|
|
@@ -1206,7 +1484,7 @@ declare function isMultiSelect<T = any>(validator: ValidatorType, schema: RJSFSc
|
|
|
1206
1484
|
* @param [rootSchema] - The root schema, used to primarily to look up `$ref`s
|
|
1207
1485
|
* @returns - True if schema contains a select, otherwise false
|
|
1208
1486
|
*/
|
|
1209
|
-
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;
|
|
1210
1488
|
|
|
1211
1489
|
/** Merges the errors in `additionalErrorSchema` into the existing `validationData` by combining the hierarchies in the
|
|
1212
1490
|
* two `ErrorSchema`s and then appending the error list from the `additionalErrorSchema` obtained by calling
|
|
@@ -1218,19 +1496,68 @@ declare function isSelect<T = any>(validator: ValidatorType, theSchema: RJSFSche
|
|
|
1218
1496
|
* @param [additionalErrorSchema] - The additional set of errors in an `ErrorSchema`
|
|
1219
1497
|
* @returns - The `validationData` with the additional errors from `additionalErrorSchema` merged into it, if provided.
|
|
1220
1498
|
*/
|
|
1221
|
-
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>;
|
|
1222
1500
|
|
|
1223
1501
|
/** Retrieves an expanded schema that has had all of its conditions, additional properties, references and dependencies
|
|
1224
1502
|
* resolved and merged into the `schema` given a `validator`, `rootSchema` and `rawFormData` that is used to do the
|
|
1225
1503
|
* potentially recursive resolution.
|
|
1226
1504
|
*
|
|
1227
|
-
* @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
|
|
1228
1506
|
* @param schema - The schema for which retrieving a schema is desired
|
|
1229
1507
|
* @param [rootSchema={}] - The root schema that will be forwarded to all the APIs
|
|
1230
1508
|
* @param [rawFormData] - The current formData, if any, to assist retrieving a schema
|
|
1231
1509
|
* @returns - The schema having its conditions, additional properties, references and dependencies resolved
|
|
1232
1510
|
*/
|
|
1233
|
-
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;
|
|
1234
1561
|
|
|
1235
1562
|
/** Generates an `IdSchema` object for the `schema`, recursively
|
|
1236
1563
|
*
|
|
@@ -1243,7 +1570,7 @@ declare function retrieveSchema<T = any>(validator: ValidatorType, schema: RJSFS
|
|
|
1243
1570
|
* @param [idSeparator='_'] - The separator to use for the path segments in the id
|
|
1244
1571
|
* @returns - The `IdSchema` object for the `schema`
|
|
1245
1572
|
*/
|
|
1246
|
-
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>;
|
|
1247
1574
|
|
|
1248
1575
|
/** Generates an `PathSchema` object for the `schema`, recursively
|
|
1249
1576
|
*
|
|
@@ -1254,6 +1581,6 @@ declare function toIdSchema<T = any>(validator: ValidatorType, schema: RJSFSchem
|
|
|
1254
1581
|
* @param [formData] - The current formData, if any, to assist retrieving a schema
|
|
1255
1582
|
* @returns - The `PathSchema` object for the `schema`
|
|
1256
1583
|
*/
|
|
1257
|
-
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>;
|
|
1258
1585
|
|
|
1259
|
-
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 };
|