@rjsf/core 5.0.0-beta.9 → 5.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/core.cjs.development.js +2037 -2328
- package/dist/core.cjs.development.js.map +1 -1
- package/dist/core.cjs.production.min.js +1 -1
- package/dist/core.cjs.production.min.js.map +1 -1
- package/dist/core.esm.js +2034 -2325
- package/dist/core.esm.js.map +1 -1
- package/dist/core.umd.development.js +2037 -2328
- package/dist/core.umd.development.js.map +1 -1
- package/dist/core.umd.production.min.js +1 -1
- package/dist/core.umd.production.min.js.map +1 -1
- package/dist/index.d.ts +46 -41
- package/package.json +18 -17
package/dist/index.d.ts
CHANGED
|
@@ -1,17 +1,16 @@
|
|
|
1
|
-
import * as json_schema from 'json-schema';
|
|
2
1
|
import React, { Component } from 'react';
|
|
3
|
-
import { RJSFSchema, ValidatorType, UiSchema, RegistryFieldsType, TemplatesType, RegistryWidgetsType, RJSFValidationError, CustomValidator, ErrorSchema, ErrorTransformer, IdSchema, SchemaUtilsType, ValidationData, Registry, PathSchema } from '@rjsf/utils';
|
|
2
|
+
import { StrictRJSFSchema, RJSFSchema, FormContextType, ValidatorType, UiSchema, RegistryFieldsType, TemplatesType, RegistryWidgetsType, RJSFValidationError, CustomValidator, ErrorSchema, ErrorTransformer, IdSchema, SchemaUtilsType, ValidationData, Registry, PathSchema } from '@rjsf/utils';
|
|
4
3
|
|
|
5
4
|
/** The properties that are passed to the `Form` */
|
|
6
|
-
interface FormProps<T = any, F = any> {
|
|
5
|
+
interface FormProps<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any> {
|
|
7
6
|
/** The JSON schema object for the form */
|
|
8
|
-
schema:
|
|
7
|
+
schema: S;
|
|
9
8
|
/** An implementation of the `ValidatorType` interface that is needed for form validation to work */
|
|
10
|
-
validator: ValidatorType<T>;
|
|
9
|
+
validator: ValidatorType<T, S, F>;
|
|
11
10
|
/** The optional children for the form, if provided, it will replace the default `SubmitButton` */
|
|
12
11
|
children?: React.ReactNode;
|
|
13
12
|
/** The uiSchema for the form */
|
|
14
|
-
uiSchema?: UiSchema<T, F>;
|
|
13
|
+
uiSchema?: UiSchema<T, S, F>;
|
|
15
14
|
/** The data for the form, used to prefill a form with existing data */
|
|
16
15
|
formData?: T;
|
|
17
16
|
/** You can provide a `formContext` object to the form, which is passed down to all fields and widgets. Useful for
|
|
@@ -39,17 +38,18 @@ interface FormProps<T = any, F = any> {
|
|
|
39
38
|
*/
|
|
40
39
|
readonly?: boolean;
|
|
41
40
|
/** The dictionary of registered fields in the form */
|
|
42
|
-
fields?: RegistryFieldsType<T, F>;
|
|
41
|
+
fields?: RegistryFieldsType<T, S, F>;
|
|
43
42
|
/** The dictionary of registered templates in the form; Partial allows a subset to be provided beyond the defaults */
|
|
44
|
-
templates?: Partial<Omit<TemplatesType<T, F>, "ButtonTemplates">> & {
|
|
45
|
-
ButtonTemplates?: Partial<TemplatesType<T, F>["ButtonTemplates"]>;
|
|
43
|
+
templates?: Partial<Omit<TemplatesType<T, S, F>, "ButtonTemplates">> & {
|
|
44
|
+
ButtonTemplates?: Partial<TemplatesType<T, S, F>["ButtonTemplates"]>;
|
|
46
45
|
};
|
|
47
46
|
/** The dictionary of registered widgets in the form */
|
|
48
|
-
widgets?: RegistryWidgetsType<T, F>;
|
|
47
|
+
widgets?: RegistryWidgetsType<T, S, F>;
|
|
49
48
|
/** If you plan on being notified every time the form data are updated, you can pass an `onChange` handler, which will
|
|
50
|
-
* receive the same args as `onSubmit` any time a value is updated in the form
|
|
49
|
+
* receive the same args as `onSubmit` any time a value is updated in the form. Can also return the `id` of the field
|
|
50
|
+
* that caused the change
|
|
51
51
|
*/
|
|
52
|
-
onChange?: (data: IChangeEvent<T, F
|
|
52
|
+
onChange?: (data: IChangeEvent<T, S, F>, id?: string) => void;
|
|
53
53
|
/** To react when submitted form data are invalid, pass an `onError` handler. It will be passed the list of
|
|
54
54
|
* encountered errors
|
|
55
55
|
*/
|
|
@@ -58,7 +58,7 @@ interface FormProps<T = any, F = any> {
|
|
|
58
58
|
* and its data are valid. It will be passed a result object having a `formData` attribute, which is the valid form
|
|
59
59
|
* data you're usually after. The original event will also be passed as a second parameter
|
|
60
60
|
*/
|
|
61
|
-
onSubmit?: (data: IChangeEvent<T, F>, event: React.FormEvent<any>) => void;
|
|
61
|
+
onSubmit?: (data: IChangeEvent<T, S, F>, event: React.FormEvent<any>) => void;
|
|
62
62
|
/** Sometimes you may want to trigger events or modify external state when a field has been touched, so you can pass
|
|
63
63
|
* an `onBlur` handler, which will receive the id of the input that was blurred and the field value
|
|
64
64
|
*/
|
|
@@ -96,7 +96,7 @@ interface FormProps<T = any, F = any> {
|
|
|
96
96
|
/** The value of this prop will be passed to the `target` HTML attribute on the form */
|
|
97
97
|
target?: string;
|
|
98
98
|
/** Formerly the `validate` prop; Takes a function that specifies custom validation rules for the form */
|
|
99
|
-
customValidate?: CustomValidator<T>;
|
|
99
|
+
customValidate?: CustomValidator<T, S, F>;
|
|
100
100
|
/** This prop allows passing in custom errors that are augmented with the existing JSON Schema errors on the form; it
|
|
101
101
|
* can be used to implement asynchronous validation
|
|
102
102
|
*/
|
|
@@ -120,14 +120,14 @@ interface FormProps<T = any, F = any> {
|
|
|
120
120
|
* called. Set to `false` by default.
|
|
121
121
|
*/
|
|
122
122
|
omitExtraData?: boolean;
|
|
123
|
-
/** When this prop is set to
|
|
124
|
-
* show. When set to false, only inline input validation errors will be shown. Set to `
|
|
123
|
+
/** When this prop is set to `top` or 'bottom', a list of errors (or the custom error list defined in the `ErrorList`) will also
|
|
124
|
+
* show. When set to false, only inline input validation errors will be shown. Set to `top` by default
|
|
125
125
|
*/
|
|
126
|
-
showErrorList?:
|
|
126
|
+
showErrorList?: false | "top" | "bottom";
|
|
127
127
|
/** A function can be passed to this prop in order to make modifications to the default errors resulting from JSON
|
|
128
128
|
* Schema validation
|
|
129
129
|
*/
|
|
130
|
-
transformErrors?: ErrorTransformer
|
|
130
|
+
transformErrors?: ErrorTransformer<T, S, F>;
|
|
131
131
|
/**
|
|
132
132
|
* _internalFormWrapper is currently used by the semantic-ui theme to provide a custom wrapper around `<Form />`
|
|
133
133
|
* that supports the proper rendering of those themes. To use this prop, one must pass a component that takes two
|
|
@@ -144,21 +144,24 @@ interface FormProps<T = any, F = any> {
|
|
|
144
144
|
* Use at your own risk as this prop is private and may change at any time without notice.
|
|
145
145
|
*/
|
|
146
146
|
_internalFormWrapper?: React.ElementType;
|
|
147
|
+
/** Support receiving a React ref to the Form
|
|
148
|
+
*/
|
|
149
|
+
ref?: React.Ref<Form<T, S, F>>;
|
|
147
150
|
}
|
|
148
151
|
/** The data that is contained within the state for the `Form` */
|
|
149
|
-
interface FormState<T = any, F = any> {
|
|
152
|
+
interface FormState<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any> {
|
|
150
153
|
/** The JSON schema object for the form */
|
|
151
|
-
schema:
|
|
154
|
+
schema: S;
|
|
152
155
|
/** The uiSchema for the form */
|
|
153
|
-
uiSchema: UiSchema<T, F>;
|
|
156
|
+
uiSchema: UiSchema<T, S, F>;
|
|
154
157
|
/** The `IdSchema` for the form, computed from the `schema`, the `rootFieldId`, the `formData` and the `idPrefix` and
|
|
155
158
|
* `idSeparator` props.
|
|
156
159
|
*/
|
|
157
160
|
idSchema: IdSchema<T>;
|
|
158
161
|
/** The schemaUtils implementation used by the `Form`, created from the `validator` and the `schema` */
|
|
159
|
-
schemaUtils: SchemaUtilsType<T>;
|
|
162
|
+
schemaUtils: SchemaUtilsType<T, S, F>;
|
|
160
163
|
/** The current data for the form, computed from the `formData` prop and the changes made by the user */
|
|
161
|
-
formData
|
|
164
|
+
formData?: T;
|
|
162
165
|
/** Flag indicating whether the form is in edit mode, true when `formData` is passed to the form, otherwise false */
|
|
163
166
|
edit: boolean;
|
|
164
167
|
/** The current list of errors for the form, includes `extraErrors` */
|
|
@@ -175,12 +178,12 @@ interface FormState<T = any, F = any> {
|
|
|
175
178
|
/** The event data passed when changes have been made to the form, includes everything from the `FormState` except
|
|
176
179
|
* the schema validation errors. An additional `status` is added when returned from `onSubmit`
|
|
177
180
|
*/
|
|
178
|
-
interface IChangeEvent<T = any, F = any> extends Omit<FormState<T, F>, "schemaValidationErrors" | "schemaValidationErrorSchema"> {
|
|
181
|
+
interface IChangeEvent<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any> extends Omit<FormState<T, S, F>, "schemaValidationErrors" | "schemaValidationErrorSchema"> {
|
|
179
182
|
/** The status of the form when submitted */
|
|
180
183
|
status?: "submitted";
|
|
181
184
|
}
|
|
182
185
|
/** The `Form` component renders the outer form and all the fields defined in the `schema` */
|
|
183
|
-
declare class Form<T = any, F = any> extends Component<FormProps<T, F>, FormState<T, F>> {
|
|
186
|
+
declare class Form<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any> extends Component<FormProps<T, S, F>, FormState<T, S, F>> {
|
|
184
187
|
/** The ref used to hold the `form` element, this needs to be `any` because `tagName` or `_internalFormWrapper` can
|
|
185
188
|
* provide any possible type here
|
|
186
189
|
*/
|
|
@@ -191,14 +194,14 @@ declare class Form<T = any, F = any> extends Component<FormProps<T, F>, FormStat
|
|
|
191
194
|
*
|
|
192
195
|
* @param props - The initial props for the `Form`
|
|
193
196
|
*/
|
|
194
|
-
constructor(props: FormProps<T, F>);
|
|
197
|
+
constructor(props: FormProps<T, S, F>);
|
|
195
198
|
/** React lifecycle method that gets called before new props are provided, updates the state based on new props. It
|
|
196
199
|
* will also call the`onChange` handler if the `formData` is modified to add missing default values as part of the
|
|
197
200
|
* state construction.
|
|
198
201
|
*
|
|
199
202
|
* @param nextProps - The new set of props about to be applied to the `Form`
|
|
200
203
|
*/
|
|
201
|
-
UNSAFE_componentWillReceiveProps(nextProps: FormProps<T, F>): void;
|
|
204
|
+
UNSAFE_componentWillReceiveProps(nextProps: FormProps<T, S, F>): void;
|
|
202
205
|
/** Extracts the updated state from the given `props` and `inputFormData`. As part of this process, the
|
|
203
206
|
* `inputFormData` is first processed to add any missing required defaults. After that, the data is run through the
|
|
204
207
|
* validation process IF required by the `props`.
|
|
@@ -207,35 +210,36 @@ declare class Form<T = any, F = any> extends Component<FormProps<T, F>, FormStat
|
|
|
207
210
|
* @param inputFormData - The new or current data for the `Form`
|
|
208
211
|
* @returns - The new state for the `Form`
|
|
209
212
|
*/
|
|
210
|
-
getStateFromProps(props: FormProps<T, F>, inputFormData?: T): FormState<T, F>;
|
|
213
|
+
getStateFromProps(props: FormProps<T, S, F>, inputFormData?: T): FormState<T, S, F>;
|
|
211
214
|
/** React lifecycle method that is used to determine whether component should be updated.
|
|
212
215
|
*
|
|
213
216
|
* @param nextProps - The next version of the props
|
|
214
217
|
* @param nextState - The next version of the state
|
|
215
218
|
* @returns - True if the component should be updated, false otherwise
|
|
216
219
|
*/
|
|
217
|
-
shouldComponentUpdate(nextProps: FormProps<T, F>, nextState: FormState<T, F>): boolean;
|
|
218
|
-
/** Validates the `formData` against the `schema` using the `
|
|
220
|
+
shouldComponentUpdate(nextProps: FormProps<T, S, F>, nextState: FormState<T, S, F>): boolean;
|
|
221
|
+
/** Validates the `formData` against the `schema` using the `altSchemaUtils` (if provided otherwise it uses the
|
|
222
|
+
* `schemaUtils` in the state), returning the results.
|
|
219
223
|
*
|
|
220
|
-
* @param schemaUtils - The schemaUtils to use for validation
|
|
221
224
|
* @param formData - The new form data to validate
|
|
222
225
|
* @param schema - The schema used to validate against
|
|
226
|
+
* @param altSchemaUtils - The alternate schemaUtils to use for validation
|
|
223
227
|
*/
|
|
224
|
-
validate(
|
|
228
|
+
validate(formData: T | undefined, schema?: S, altSchemaUtils?: SchemaUtilsType<T, S, F>): ValidationData<T>;
|
|
225
229
|
/** Renders any errors contained in the `state` in using the `ErrorList`, if not disabled by `showErrorList`. */
|
|
226
|
-
renderErrors(registry: Registry<T, F>): JSX.Element | null;
|
|
230
|
+
renderErrors(registry: Registry<T, S, F>): JSX.Element | null;
|
|
227
231
|
/** Returns the `formData` with only the elements specified in the `fields` list
|
|
228
232
|
*
|
|
229
233
|
* @param formData - The data for the `Form`
|
|
230
234
|
* @param fields - The fields to keep while filtering
|
|
231
235
|
*/
|
|
232
|
-
getUsedFormData: (formData: T, fields: string[]) => T;
|
|
236
|
+
getUsedFormData: (formData: T | undefined, fields: string[][]) => T | undefined;
|
|
233
237
|
/** Returns the list of field names from inspecting the `pathSchema` as well as using the `formData`
|
|
234
238
|
*
|
|
235
239
|
* @param pathSchema - The `PathSchema` object for the form
|
|
236
|
-
* @param formData - The form data to use while checking for empty objects/arrays
|
|
240
|
+
* @param [formData] - The form data to use while checking for empty objects/arrays
|
|
237
241
|
*/
|
|
238
|
-
getFieldNames: (pathSchema: PathSchema<T>, formData
|
|
242
|
+
getFieldNames: (pathSchema: PathSchema<T>, formData?: T) => string[][];
|
|
239
243
|
/** Function to handle changes made to a field in the `Form`. This handler receives an entirely new copy of the
|
|
240
244
|
* `formData` along with a new `ErrorSchema`. It will first update the `formData` with any missing default fields and
|
|
241
245
|
* then, if `omitExtraData` and `liveOmit` are turned on, the `formData` will be filterer to remove any extra data not
|
|
@@ -245,8 +249,9 @@ declare class Form<T = any, F = any> extends Component<FormProps<T, F>, FormStat
|
|
|
245
249
|
*
|
|
246
250
|
* @param formData - The new form data from a change to a field
|
|
247
251
|
* @param newErrorSchema - The new `ErrorSchema` based on the field change
|
|
252
|
+
* @param id - The id of the field that caused the change
|
|
248
253
|
*/
|
|
249
|
-
onChange: (formData: T, newErrorSchema?: ErrorSchema<T
|
|
254
|
+
onChange: (formData: T | undefined, newErrorSchema?: ErrorSchema<T>, id?: string) => void;
|
|
250
255
|
/** Callback function to handle when a field on the form is blurred. Calls the `onBlur` callback for the `Form` if it
|
|
251
256
|
* was provided.
|
|
252
257
|
*
|
|
@@ -271,7 +276,7 @@ declare class Form<T = any, F = any> extends Component<FormProps<T, F>, FormStat
|
|
|
271
276
|
*/
|
|
272
277
|
onSubmit: (event: React.FormEvent<any>) => void;
|
|
273
278
|
/** Returns the registry for the form */
|
|
274
|
-
getRegistry(): Registry<T, F>;
|
|
279
|
+
getRegistry(): Registry<T, S, F>;
|
|
275
280
|
/** Provides a function that can be used to programmatically submit the `Form` */
|
|
276
281
|
submit(): void;
|
|
277
282
|
/** Programmatically validate the form. If `onError` is provided, then it will be called with the list of errors the
|
|
@@ -289,14 +294,14 @@ declare class Form<T = any, F = any> extends Component<FormProps<T, F>, FormStat
|
|
|
289
294
|
/** The properties for the `withTheme` function, essentially a subset of properties from the `FormProps` that can be
|
|
290
295
|
* overridden while creating a theme
|
|
291
296
|
*/
|
|
292
|
-
|
|
297
|
+
type ThemeProps<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any> = Pick<FormProps<T, S, F>, "fields" | "templates" | "widgets" | "_internalFormWrapper">;
|
|
293
298
|
/** A Higher-Order component that creates a wrapper around a `Form` with the overrides from the `WithThemeProps` */
|
|
294
|
-
declare function withTheme<T = any, F = any>(themeProps: ThemeProps<T, F>): React.
|
|
299
|
+
declare function withTheme<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(themeProps: ThemeProps<T, S, F>): React.ComponentType<FormProps<T, S, F>>;
|
|
295
300
|
|
|
296
301
|
/** The default registry consists of all the fields, templates and widgets provided in the core implementation,
|
|
297
302
|
* plus an empty `rootSchema` and `formContext. We omit schemaUtils here because it cannot be defaulted without a
|
|
298
303
|
* rootSchema and validator. It will be added into the computed registry later in the Form.
|
|
299
304
|
*/
|
|
300
|
-
declare function getDefaultRegistry<T = any, F = any>(): Omit<Registry<T, F>, "schemaUtils">;
|
|
305
|
+
declare function getDefaultRegistry<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(): Omit<Registry<T, S, F>, "schemaUtils">;
|
|
301
306
|
|
|
302
307
|
export { FormProps, FormState, IChangeEvent, ThemeProps, Form as default, getDefaultRegistry, withTheme };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rjsf/core",
|
|
3
|
-
"version": "5.0.0
|
|
3
|
+
"version": "5.0.0",
|
|
4
4
|
"description": "A simple React component capable of building HTML forms out of a JSON schema.",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "rimraf dist && dts build --rollupTypes --format cjs,esm,umd",
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
"publish-to-npm": "npm run build && npm publish",
|
|
12
12
|
"start": "dts watch",
|
|
13
13
|
"test": "dts test",
|
|
14
|
+
"test:debug": "node --inspect-brk node_modules/.bin/dts test",
|
|
14
15
|
"test:watch": "dts test --watch",
|
|
15
16
|
"test-coverage": "dts test --coverage"
|
|
16
17
|
},
|
|
@@ -42,33 +43,33 @@
|
|
|
42
43
|
"prop-types": "^15.7.2"
|
|
43
44
|
},
|
|
44
45
|
"devDependencies": {
|
|
45
|
-
"@babel/cli": "^7.
|
|
46
|
-
"@babel/core": "^7.
|
|
46
|
+
"@babel/cli": "^7.20.7",
|
|
47
|
+
"@babel/core": "^7.20.12",
|
|
47
48
|
"@babel/plugin-proposal-class-properties": "^7.18.6",
|
|
48
|
-
"@babel/plugin-proposal-optional-chaining": "^7.
|
|
49
|
+
"@babel/plugin-proposal-optional-chaining": "^7.20.7",
|
|
49
50
|
"@babel/plugin-transform-object-assign": "^7.18.6",
|
|
50
|
-
"@babel/plugin-transform-react-jsx": "^7.
|
|
51
|
-
"@babel/preset-env": "^7.
|
|
51
|
+
"@babel/plugin-transform-react-jsx": "^7.20.7",
|
|
52
|
+
"@babel/preset-env": "^7.20.2",
|
|
52
53
|
"@babel/preset-react": "^7.18.6",
|
|
53
54
|
"@babel/register": "^7.18.9",
|
|
54
|
-
"@rjsf/utils": "^5.0.0
|
|
55
|
-
"@rjsf/validator-ajv6": "^5.0.0
|
|
56
|
-
"@rjsf/validator-ajv8": "^5.0.0
|
|
57
|
-
"@types/lodash": "^4.14.
|
|
55
|
+
"@rjsf/utils": "^5.0.0",
|
|
56
|
+
"@rjsf/validator-ajv6": "^5.0.0",
|
|
57
|
+
"@rjsf/validator-ajv8": "^5.0.0",
|
|
58
|
+
"@types/lodash": "^4.14.191",
|
|
58
59
|
"@types/react": "^17.0.39",
|
|
59
60
|
"@types/react-dom": "^17.0.11",
|
|
60
|
-
"ajv": "^
|
|
61
|
+
"ajv": "^8.12.0",
|
|
61
62
|
"atob": "^2.1.2",
|
|
62
63
|
"chai": "^3.3.0",
|
|
63
|
-
"dts-cli": "^1.6.
|
|
64
|
-
"eslint": "^8.
|
|
64
|
+
"dts-cli": "^1.6.3",
|
|
65
|
+
"eslint": "^8.31.0",
|
|
65
66
|
"html": "^1.0.0",
|
|
66
|
-
"jsdom": "^20.0.
|
|
67
|
-
"mocha": "^10.
|
|
67
|
+
"jsdom": "^20.0.1",
|
|
68
|
+
"mocha": "^10.2.0",
|
|
68
69
|
"react": "^17.0.2",
|
|
69
70
|
"react-dom": "^17.0.2",
|
|
70
71
|
"react-portal": "^4.2.2",
|
|
71
|
-
"rimraf": "^
|
|
72
|
+
"rimraf": "^4.0.4",
|
|
72
73
|
"sinon": "^9.0.2"
|
|
73
74
|
},
|
|
74
75
|
"directories": {
|
|
@@ -92,5 +93,5 @@
|
|
|
92
93
|
"publishConfig": {
|
|
93
94
|
"access": "public"
|
|
94
95
|
},
|
|
95
|
-
"gitHead": "
|
|
96
|
+
"gitHead": "251bdbc60d2efdbab3a2b4058a2338d0d4794942"
|
|
96
97
|
}
|