@rjsf/core 6.0.0-beta.2 → 6.0.0-beta.20
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.umd.js +469 -360
- package/dist/{index.js → index.cjs} +640 -519
- package/dist/index.cjs.map +7 -0
- package/dist/index.esm.js +706 -566
- package/dist/index.esm.js.map +4 -4
- package/lib/components/Form.d.ts +66 -16
- package/lib/components/Form.d.ts.map +1 -1
- package/lib/components/Form.js +138 -59
- package/lib/components/fields/ArrayField.d.ts +17 -7
- package/lib/components/fields/ArrayField.d.ts.map +1 -1
- package/lib/components/fields/ArrayField.js +92 -59
- package/lib/components/fields/BooleanField.d.ts.map +1 -1
- package/lib/components/fields/BooleanField.js +7 -2
- package/lib/components/fields/LayoutGridField.d.ts +27 -25
- package/lib/components/fields/LayoutGridField.d.ts.map +1 -1
- package/lib/components/fields/LayoutGridField.js +83 -53
- package/lib/components/fields/LayoutHeaderField.d.ts +1 -1
- package/lib/components/fields/LayoutHeaderField.js +3 -3
- package/lib/components/fields/LayoutMultiSchemaField.js +6 -5
- package/lib/components/fields/MultiSchemaField.d.ts.map +1 -1
- package/lib/components/fields/MultiSchemaField.js +13 -9
- package/lib/components/fields/NullField.js +3 -3
- package/lib/components/fields/NumberField.d.ts.map +1 -1
- package/lib/components/fields/NumberField.js +3 -3
- package/lib/components/fields/ObjectField.d.ts +3 -3
- package/lib/components/fields/ObjectField.d.ts.map +1 -1
- package/lib/components/fields/ObjectField.js +18 -25
- package/lib/components/fields/SchemaField.d.ts.map +1 -1
- package/lib/components/fields/SchemaField.js +17 -17
- package/lib/components/fields/StringField.d.ts.map +1 -1
- package/lib/components/fields/StringField.js +7 -2
- package/lib/components/templates/ArrayFieldDescriptionTemplate.d.ts +1 -1
- package/lib/components/templates/ArrayFieldDescriptionTemplate.js +3 -3
- package/lib/components/templates/ArrayFieldItemButtonsTemplate.js +2 -2
- package/lib/components/templates/ArrayFieldTemplate.js +3 -3
- package/lib/components/templates/ArrayFieldTitleTemplate.d.ts +1 -1
- package/lib/components/templates/ArrayFieldTitleTemplate.js +3 -3
- package/lib/components/templates/FieldErrorTemplate.js +2 -2
- package/lib/components/templates/FieldHelpTemplate.js +2 -2
- package/lib/components/templates/MultiSchemaFieldTemplate.d.ts +8 -0
- package/lib/components/templates/MultiSchemaFieldTemplate.d.ts.map +1 -0
- package/lib/components/templates/MultiSchemaFieldTemplate.js +10 -0
- package/lib/components/templates/ObjectFieldTemplate.js +2 -2
- package/lib/components/templates/UnsupportedField.js +3 -3
- package/lib/components/templates/index.d.ts.map +1 -1
- package/lib/components/templates/index.js +2 -0
- package/lib/components/widgets/AltDateWidget.d.ts.map +1 -1
- package/lib/components/widgets/AltDateWidget.js +15 -18
- package/lib/components/widgets/CheckboxesWidget.js +2 -2
- package/lib/getDefaultRegistry.d.ts.map +1 -1
- package/lib/getDefaultRegistry.js +2 -1
- package/lib/getTestRegistry.d.ts +5 -0
- package/lib/getTestRegistry.d.ts.map +1 -0
- package/lib/getTestRegistry.js +19 -0
- package/lib/index.d.ts +2 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +2 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +18 -19
- package/src/components/Form.tsx +183 -73
- package/src/components/fields/ArrayField.tsx +99 -67
- package/src/components/fields/BooleanField.tsx +12 -3
- package/src/components/fields/LayoutGridField.tsx +95 -82
- package/src/components/fields/LayoutHeaderField.tsx +3 -3
- package/src/components/fields/LayoutMultiSchemaField.tsx +5 -5
- package/src/components/fields/MultiSchemaField.tsx +51 -35
- package/src/components/fields/NullField.tsx +3 -3
- package/src/components/fields/NumberField.tsx +11 -3
- package/src/components/fields/ObjectField.tsx +19 -36
- package/src/components/fields/SchemaField.tsx +24 -30
- package/src/components/fields/StringField.tsx +12 -3
- package/src/components/templates/ArrayFieldDescriptionTemplate.tsx +3 -3
- package/src/components/templates/ArrayFieldItemButtonsTemplate.tsx +5 -5
- package/src/components/templates/ArrayFieldTemplate.tsx +5 -5
- package/src/components/templates/ArrayFieldTitleTemplate.tsx +3 -3
- package/src/components/templates/BaseInputTemplate.tsx +3 -3
- package/src/components/templates/FieldErrorTemplate.tsx +2 -2
- package/src/components/templates/FieldHelpTemplate.tsx +2 -2
- package/src/components/templates/MultiSchemaFieldTemplate.tsx +20 -0
- package/src/components/templates/ObjectFieldTemplate.tsx +5 -5
- package/src/components/templates/UnsupportedField.tsx +3 -3
- package/src/components/templates/WrapIfAdditionalTemplate.tsx +1 -1
- package/src/components/templates/index.ts +2 -0
- package/src/components/widgets/AltDateWidget.tsx +21 -23
- package/src/components/widgets/CheckboxWidget.tsx +2 -2
- package/src/components/widgets/CheckboxesWidget.tsx +3 -3
- package/src/components/widgets/RadioWidget.tsx +1 -1
- package/src/components/widgets/SelectWidget.tsx +1 -1
- package/src/components/widgets/TextareaWidget.tsx +1 -1
- package/src/getDefaultRegistry.ts +10 -1
- package/src/getTestRegistry.tsx +34 -0
- package/src/index.ts +2 -1
- package/dist/index.js.map +0 -7
|
@@ -3,11 +3,12 @@ import {
|
|
|
3
3
|
getTemplate,
|
|
4
4
|
getUiOptions,
|
|
5
5
|
orderProperties,
|
|
6
|
+
toFieldPathId,
|
|
6
7
|
ErrorSchema,
|
|
8
|
+
FieldPathList,
|
|
7
9
|
FieldProps,
|
|
8
10
|
FormContextType,
|
|
9
11
|
GenericObjectType,
|
|
10
|
-
IdSchema,
|
|
11
12
|
RJSFSchema,
|
|
12
13
|
StrictRJSFSchema,
|
|
13
14
|
TranslatableString,
|
|
@@ -66,8 +67,8 @@ class ObjectField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends Fo
|
|
|
66
67
|
* @returns - The onPropertyChange callback for the `name` property
|
|
67
68
|
*/
|
|
68
69
|
onPropertyChange = (name: string, addedByAdditionalProperties = false) => {
|
|
69
|
-
return (value: T | undefined, newErrorSchema?: ErrorSchema<T>, id?: string) => {
|
|
70
|
-
const {
|
|
70
|
+
return (value: T | undefined, path: FieldPathList, newErrorSchema?: ErrorSchema<T>, id?: string) => {
|
|
71
|
+
const { onChange } = this.props;
|
|
71
72
|
if (value === undefined && addedByAdditionalProperties) {
|
|
72
73
|
// Don't set value = undefined for fields added by
|
|
73
74
|
// additionalProperties. Doing so removes them from the
|
|
@@ -78,16 +79,7 @@ class ObjectField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends Fo
|
|
|
78
79
|
// set empty values to the empty string.
|
|
79
80
|
value = '' as unknown as T;
|
|
80
81
|
}
|
|
81
|
-
|
|
82
|
-
onChange(
|
|
83
|
-
newFormData,
|
|
84
|
-
errorSchema &&
|
|
85
|
-
errorSchema && {
|
|
86
|
-
...errorSchema,
|
|
87
|
-
[name]: newErrorSchema,
|
|
88
|
-
},
|
|
89
|
-
id,
|
|
90
|
-
);
|
|
82
|
+
onChange(value, path, newErrorSchema, id);
|
|
91
83
|
};
|
|
92
84
|
};
|
|
93
85
|
|
|
@@ -100,10 +92,11 @@ class ObjectField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends Fo
|
|
|
100
92
|
onDropPropertyClick = (key: string) => {
|
|
101
93
|
return (event: DragEvent) => {
|
|
102
94
|
event.preventDefault();
|
|
103
|
-
const { onChange, formData } = this.props;
|
|
95
|
+
const { onChange, formData, fieldPathId } = this.props;
|
|
104
96
|
const copiedFormData = { ...formData } as T;
|
|
105
97
|
unset(copiedFormData, key);
|
|
106
|
-
|
|
98
|
+
// drop property will pass the name in `path` array
|
|
99
|
+
onChange(copiedFormData, fieldPathId.path);
|
|
107
100
|
};
|
|
108
101
|
};
|
|
109
102
|
|
|
@@ -133,11 +126,11 @@ class ObjectField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends Fo
|
|
|
133
126
|
* @returns - The key change callback function
|
|
134
127
|
*/
|
|
135
128
|
onKeyChange = (oldValue: any) => {
|
|
136
|
-
return (value: any
|
|
129
|
+
return (value: any) => {
|
|
137
130
|
if (oldValue === value) {
|
|
138
131
|
return;
|
|
139
132
|
}
|
|
140
|
-
const { formData, onChange,
|
|
133
|
+
const { formData, onChange, fieldPathId } = this.props;
|
|
141
134
|
|
|
142
135
|
value = this.getAvailableKey(value, formData);
|
|
143
136
|
const newFormData: GenericObjectType = {
|
|
@@ -152,14 +145,7 @@ class ObjectField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends Fo
|
|
|
152
145
|
|
|
153
146
|
this.setState({ wasPropertyKeyModified: true });
|
|
154
147
|
|
|
155
|
-
onChange(
|
|
156
|
-
renamedObj,
|
|
157
|
-
errorSchema &&
|
|
158
|
-
errorSchema && {
|
|
159
|
-
...errorSchema,
|
|
160
|
-
[value]: newErrorSchema,
|
|
161
|
-
},
|
|
162
|
-
);
|
|
148
|
+
onChange(renamedObj, fieldPathId.path);
|
|
163
149
|
};
|
|
164
150
|
};
|
|
165
151
|
|
|
@@ -198,7 +184,7 @@ class ObjectField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends Fo
|
|
|
198
184
|
if (!(schema.additionalProperties || schema.patternProperties)) {
|
|
199
185
|
return;
|
|
200
186
|
}
|
|
201
|
-
const { formData, onChange, registry } = this.props;
|
|
187
|
+
const { formData, onChange, registry, fieldPathId } = this.props;
|
|
202
188
|
const newFormData = { ...formData } as T;
|
|
203
189
|
const newKey = this.getAvailableKey('newKey', newFormData);
|
|
204
190
|
if (schema.patternProperties) {
|
|
@@ -230,7 +216,8 @@ class ObjectField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends Fo
|
|
|
230
216
|
set(newFormData as GenericObjectType, newKey, newValue);
|
|
231
217
|
}
|
|
232
218
|
|
|
233
|
-
|
|
219
|
+
// add will pass the name in `path` array
|
|
220
|
+
onChange(newFormData, fieldPathId.path);
|
|
234
221
|
};
|
|
235
222
|
|
|
236
223
|
/** Renders the `ObjectField` from the given props
|
|
@@ -241,21 +228,19 @@ class ObjectField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends Fo
|
|
|
241
228
|
uiSchema = {},
|
|
242
229
|
formData,
|
|
243
230
|
errorSchema,
|
|
244
|
-
|
|
231
|
+
fieldPathId,
|
|
245
232
|
name,
|
|
246
233
|
required = false,
|
|
247
234
|
disabled,
|
|
248
235
|
readonly,
|
|
249
236
|
hideError,
|
|
250
|
-
idPrefix,
|
|
251
|
-
idSeparator,
|
|
252
237
|
onBlur,
|
|
253
238
|
onFocus,
|
|
254
239
|
registry,
|
|
255
240
|
title,
|
|
256
241
|
} = this.props;
|
|
257
242
|
|
|
258
|
-
const { fields, formContext, schemaUtils, translateString, globalUiOptions } = registry;
|
|
243
|
+
const { fields, formContext, schemaUtils, translateString, globalFormOptions, globalUiOptions } = registry;
|
|
259
244
|
const { SchemaField } = fields;
|
|
260
245
|
const schema: S = schemaUtils.retrieveSchema(rawSchema, formData);
|
|
261
246
|
const uiOptions = getUiOptions<T, S, F>(uiSchema, globalUiOptions);
|
|
@@ -290,7 +275,7 @@ class ObjectField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends Fo
|
|
|
290
275
|
const addedByAdditionalProperties = has(schema, [PROPERTIES_KEY, name, ADDITIONAL_PROPERTY_FLAG]);
|
|
291
276
|
const fieldUiSchema = addedByAdditionalProperties ? uiSchema.additionalProperties : uiSchema[name];
|
|
292
277
|
const hidden = getUiOptions<T, S, F>(fieldUiSchema).widget === 'hidden';
|
|
293
|
-
const
|
|
278
|
+
const innerFieldIdPathId = toFieldPathId(name, globalFormOptions, fieldPathId);
|
|
294
279
|
|
|
295
280
|
return {
|
|
296
281
|
content: (
|
|
@@ -301,9 +286,7 @@ class ObjectField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends Fo
|
|
|
301
286
|
schema={get(schema, [PROPERTIES_KEY, name], {}) as S}
|
|
302
287
|
uiSchema={fieldUiSchema}
|
|
303
288
|
errorSchema={get(errorSchema, name)}
|
|
304
|
-
|
|
305
|
-
idPrefix={idPrefix}
|
|
306
|
-
idSeparator={idSeparator}
|
|
289
|
+
fieldPathId={innerFieldIdPathId}
|
|
307
290
|
formData={get(formData, name)}
|
|
308
291
|
formContext={formContext}
|
|
309
292
|
wasPropertyKeyModified={this.state.wasPropertyKeyModified}
|
|
@@ -328,7 +311,7 @@ class ObjectField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends Fo
|
|
|
328
311
|
readonly,
|
|
329
312
|
disabled,
|
|
330
313
|
required,
|
|
331
|
-
|
|
314
|
+
fieldPathId,
|
|
332
315
|
uiSchema,
|
|
333
316
|
errorSchema,
|
|
334
317
|
schema,
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { useCallback, Component, ComponentType } from 'react';
|
|
2
2
|
import {
|
|
3
3
|
ADDITIONAL_PROPERTY_FLAG,
|
|
4
|
-
deepEquals,
|
|
5
4
|
descriptionId,
|
|
6
5
|
ErrorSchema,
|
|
6
|
+
FieldPathId,
|
|
7
|
+
FieldPathList,
|
|
7
8
|
FieldProps,
|
|
8
9
|
FieldTemplateProps,
|
|
9
10
|
FormContextType,
|
|
@@ -11,10 +12,9 @@ import {
|
|
|
11
12
|
getTemplate,
|
|
12
13
|
getUiOptions,
|
|
13
14
|
ID_KEY,
|
|
14
|
-
IdSchema,
|
|
15
|
-
mergeObjects,
|
|
16
15
|
Registry,
|
|
17
16
|
RJSFSchema,
|
|
17
|
+
shouldRender,
|
|
18
18
|
StrictRJSFSchema,
|
|
19
19
|
TranslatableString,
|
|
20
20
|
UI_OPTIONS_KEY,
|
|
@@ -40,14 +40,14 @@ const COMPONENT_TYPES: { [key: string]: string } = {
|
|
|
40
40
|
*
|
|
41
41
|
* @param schema - The schema from which to obtain the type
|
|
42
42
|
* @param uiOptions - The UI Options that may affect the component decision
|
|
43
|
-
* @param
|
|
43
|
+
* @param fieldPathId - The id that is passed to the `UnsupportedFieldTemplate`
|
|
44
44
|
* @param registry - The registry from which fields and templates are obtained
|
|
45
45
|
* @returns - The `Field` component that is used to render the actual field data
|
|
46
46
|
*/
|
|
47
47
|
function getFieldComponent<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(
|
|
48
48
|
schema: S,
|
|
49
49
|
uiOptions: UIOptionsType<T, S, F>,
|
|
50
|
-
|
|
50
|
+
fieldPathId: FieldPathId,
|
|
51
51
|
registry: Registry<T, S, F>,
|
|
52
52
|
): ComponentType<FieldProps<T, S, F>> {
|
|
53
53
|
const field = uiOptions.field;
|
|
@@ -87,7 +87,7 @@ function getFieldComponent<T = any, S extends StrictRJSFSchema = RJSFSchema, F e
|
|
|
87
87
|
return (
|
|
88
88
|
<UnsupportedFieldTemplate
|
|
89
89
|
schema={schema}
|
|
90
|
-
|
|
90
|
+
fieldPathId={fieldPathId}
|
|
91
91
|
reason={translateString(TranslatableString.UnknownFieldType, [String(schema.type)])}
|
|
92
92
|
registry={registry}
|
|
93
93
|
/>
|
|
@@ -106,12 +106,10 @@ function SchemaFieldRender<T = any, S extends StrictRJSFSchema = RJSFSchema, F e
|
|
|
106
106
|
) {
|
|
107
107
|
const {
|
|
108
108
|
schema: _schema,
|
|
109
|
-
|
|
109
|
+
fieldPathId,
|
|
110
110
|
uiSchema,
|
|
111
111
|
formData,
|
|
112
112
|
errorSchema,
|
|
113
|
-
idPrefix,
|
|
114
|
-
idSeparator,
|
|
115
113
|
name,
|
|
116
114
|
onChange,
|
|
117
115
|
onKeyChange,
|
|
@@ -131,24 +129,20 @@ function SchemaFieldRender<T = any, S extends StrictRJSFSchema = RJSFSchema, F e
|
|
|
131
129
|
const FieldHelpTemplate = getTemplate<'FieldHelpTemplate', T, S, F>('FieldHelpTemplate', registry, uiOptions);
|
|
132
130
|
const FieldErrorTemplate = getTemplate<'FieldErrorTemplate', T, S, F>('FieldErrorTemplate', registry, uiOptions);
|
|
133
131
|
const schema = schemaUtils.retrieveSchema(_schema, formData);
|
|
134
|
-
const fieldId =
|
|
135
|
-
const idSchema = mergeObjects(
|
|
136
|
-
schemaUtils.toIdSchema(schema, fieldId, formData, idPrefix, idSeparator),
|
|
137
|
-
_idSchema,
|
|
138
|
-
) as IdSchema<T>;
|
|
132
|
+
const fieldId = fieldPathId[ID_KEY];
|
|
139
133
|
|
|
140
134
|
/** Intermediary `onChange` handler for field components that will inject the `id` of the current field into the
|
|
141
135
|
* `onChange` chain if it is not already being provided from a deeper level in the hierarchy
|
|
142
136
|
*/
|
|
143
137
|
const handleFieldComponentChange = useCallback(
|
|
144
|
-
(formData: T | undefined, newErrorSchema?: ErrorSchema<T>, id?: string) => {
|
|
138
|
+
(formData: T | undefined, path: FieldPathList, newErrorSchema?: ErrorSchema<T>, id?: string) => {
|
|
145
139
|
const theId = id || fieldId;
|
|
146
|
-
return onChange(formData, newErrorSchema, theId);
|
|
140
|
+
return onChange(formData, path, newErrorSchema, theId);
|
|
147
141
|
},
|
|
148
142
|
[fieldId, onChange],
|
|
149
143
|
);
|
|
150
144
|
|
|
151
|
-
const FieldComponent = getFieldComponent<T, S, F>(schema, uiOptions,
|
|
145
|
+
const FieldComponent = getFieldComponent<T, S, F>(schema, uiOptions, fieldPathId, registry);
|
|
152
146
|
const disabled = Boolean(uiOptions.disabled ?? props.disabled);
|
|
153
147
|
const readonly = Boolean(uiOptions.readonly ?? (props.readonly || props.schema.readOnly || schema.readOnly));
|
|
154
148
|
const uiSchemaHideError = uiOptions.hideError;
|
|
@@ -172,7 +166,7 @@ function SchemaFieldRender<T = any, S extends StrictRJSFSchema = RJSFSchema, F e
|
|
|
172
166
|
<FieldComponent
|
|
173
167
|
{...props}
|
|
174
168
|
onChange={handleFieldComponentChange}
|
|
175
|
-
|
|
169
|
+
fieldPathId={fieldPathId}
|
|
176
170
|
schema={schema}
|
|
177
171
|
uiSchema={fieldUiSchema}
|
|
178
172
|
disabled={disabled}
|
|
@@ -185,7 +179,7 @@ function SchemaFieldRender<T = any, S extends StrictRJSFSchema = RJSFSchema, F e
|
|
|
185
179
|
/>
|
|
186
180
|
);
|
|
187
181
|
|
|
188
|
-
const id =
|
|
182
|
+
const id = fieldPathId[ID_KEY];
|
|
189
183
|
|
|
190
184
|
// If this schema has a title defined, but the user has set a new key/label, retain their input.
|
|
191
185
|
let label;
|
|
@@ -213,7 +207,7 @@ function SchemaFieldRender<T = any, S extends StrictRJSFSchema = RJSFSchema, F e
|
|
|
213
207
|
const helpComponent = (
|
|
214
208
|
<FieldHelpTemplate
|
|
215
209
|
help={help}
|
|
216
|
-
|
|
210
|
+
fieldPathId={fieldPathId}
|
|
217
211
|
schema={schema}
|
|
218
212
|
uiSchema={uiSchema}
|
|
219
213
|
hasErrors={!hideError && __errors && __errors.length > 0}
|
|
@@ -229,7 +223,7 @@ function SchemaFieldRender<T = any, S extends StrictRJSFSchema = RJSFSchema, F e
|
|
|
229
223
|
<FieldErrorTemplate
|
|
230
224
|
errors={__errors}
|
|
231
225
|
errorSchema={errorSchema}
|
|
232
|
-
|
|
226
|
+
fieldPathId={fieldPathId}
|
|
233
227
|
schema={schema}
|
|
234
228
|
uiSchema={uiSchema}
|
|
235
229
|
registry={registry}
|
|
@@ -238,7 +232,7 @@ function SchemaFieldRender<T = any, S extends StrictRJSFSchema = RJSFSchema, F e
|
|
|
238
232
|
const fieldProps: Omit<FieldTemplateProps<T, S, F>, 'children'> = {
|
|
239
233
|
description: (
|
|
240
234
|
<DescriptionFieldTemplate
|
|
241
|
-
id={descriptionId
|
|
235
|
+
id={descriptionId(id)}
|
|
242
236
|
description={description}
|
|
243
237
|
schema={schema}
|
|
244
238
|
uiSchema={uiSchema}
|
|
@@ -263,7 +257,6 @@ function SchemaFieldRender<T = any, S extends StrictRJSFSchema = RJSFSchema, F e
|
|
|
263
257
|
displayLabel,
|
|
264
258
|
classNames: classNames.join(' ').trim(),
|
|
265
259
|
style: uiOptions.style,
|
|
266
|
-
formContext,
|
|
267
260
|
formData,
|
|
268
261
|
schema,
|
|
269
262
|
uiSchema,
|
|
@@ -292,9 +285,7 @@ function SchemaFieldRender<T = any, S extends StrictRJSFSchema = RJSFSchema, F e
|
|
|
292
285
|
errorSchema={errorSchema}
|
|
293
286
|
formData={formData}
|
|
294
287
|
formContext={formContext}
|
|
295
|
-
|
|
296
|
-
idSchema={idSchema}
|
|
297
|
-
idSeparator={idSeparator}
|
|
288
|
+
fieldPathId={fieldPathId}
|
|
298
289
|
onBlur={props.onBlur}
|
|
299
290
|
onChange={props.onChange}
|
|
300
291
|
onFocus={props.onFocus}
|
|
@@ -316,9 +307,7 @@ function SchemaFieldRender<T = any, S extends StrictRJSFSchema = RJSFSchema, F e
|
|
|
316
307
|
errorSchema={errorSchema}
|
|
317
308
|
formData={formData}
|
|
318
309
|
formContext={formContext}
|
|
319
|
-
|
|
320
|
-
idSchema={idSchema}
|
|
321
|
-
idSeparator={idSeparator}
|
|
310
|
+
fieldPathId={fieldPathId}
|
|
322
311
|
onBlur={props.onBlur}
|
|
323
312
|
onChange={props.onChange}
|
|
324
313
|
onFocus={props.onFocus}
|
|
@@ -343,7 +332,12 @@ class SchemaField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends Fo
|
|
|
343
332
|
FieldProps<T, S, F>
|
|
344
333
|
> {
|
|
345
334
|
shouldComponentUpdate(nextProps: Readonly<FieldProps<T, S, F>>) {
|
|
346
|
-
|
|
335
|
+
const {
|
|
336
|
+
registry: { globalFormOptions },
|
|
337
|
+
} = this.props;
|
|
338
|
+
const { experimental_componentUpdateStrategy = 'customDeep' } = globalFormOptions;
|
|
339
|
+
|
|
340
|
+
return shouldRender(this, nextProps, this.state, experimental_componentUpdateStrategy);
|
|
347
341
|
}
|
|
348
342
|
|
|
349
343
|
render() {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { useCallback } from 'react';
|
|
1
2
|
import {
|
|
2
3
|
getWidget,
|
|
3
4
|
getUiOptions,
|
|
@@ -7,6 +8,7 @@ import {
|
|
|
7
8
|
FormContextType,
|
|
8
9
|
RJSFSchema,
|
|
9
10
|
StrictRJSFSchema,
|
|
11
|
+
ErrorSchema,
|
|
10
12
|
} from '@rjsf/utils';
|
|
11
13
|
|
|
12
14
|
/** The `StringField` component is used to render a schema field that represents a string type
|
|
@@ -20,7 +22,7 @@ function StringField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends
|
|
|
20
22
|
schema,
|
|
21
23
|
name,
|
|
22
24
|
uiSchema,
|
|
23
|
-
|
|
25
|
+
fieldPathId,
|
|
24
26
|
formData,
|
|
25
27
|
required,
|
|
26
28
|
disabled = false,
|
|
@@ -44,18 +46,25 @@ function StringField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends
|
|
|
44
46
|
const displayLabel = schemaUtils.getDisplayLabel(schema, uiSchema, globalUiOptions);
|
|
45
47
|
const label = uiTitle ?? title ?? name;
|
|
46
48
|
const Widget = getWidget<T, S, F>(schema, widget, widgets);
|
|
49
|
+
const onWidgetChange = useCallback(
|
|
50
|
+
(value: T | undefined, errorSchema?: ErrorSchema, id?: string) => {
|
|
51
|
+
// String field change passes an empty path array to the parent field which adds the appropriate path
|
|
52
|
+
return onChange(value, fieldPathId.path, errorSchema, id);
|
|
53
|
+
},
|
|
54
|
+
[onChange, fieldPathId],
|
|
55
|
+
);
|
|
47
56
|
return (
|
|
48
57
|
<Widget
|
|
49
58
|
options={{ ...options, enumOptions }}
|
|
50
59
|
schema={schema}
|
|
51
60
|
uiSchema={uiSchema}
|
|
52
|
-
id={
|
|
61
|
+
id={fieldPathId.$id}
|
|
53
62
|
name={name}
|
|
54
63
|
label={label}
|
|
55
64
|
hideLabel={!displayLabel}
|
|
56
65
|
hideError={hideError}
|
|
57
66
|
value={formData}
|
|
58
|
-
onChange={
|
|
67
|
+
onChange={onWidgetChange}
|
|
59
68
|
onBlur={onBlur}
|
|
60
69
|
onFocus={onFocus}
|
|
61
70
|
required={required}
|
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
} from '@rjsf/utils';
|
|
10
10
|
|
|
11
11
|
/** The `ArrayFieldDescriptionTemplate` component renders a `DescriptionFieldTemplate` with an `id` derived from
|
|
12
|
-
* the `
|
|
12
|
+
* the `fieldPathId`.
|
|
13
13
|
*
|
|
14
14
|
* @param props - The `ArrayFieldDescriptionProps` for the component
|
|
15
15
|
*/
|
|
@@ -18,7 +18,7 @@ export default function ArrayFieldDescriptionTemplate<
|
|
|
18
18
|
S extends StrictRJSFSchema = RJSFSchema,
|
|
19
19
|
F extends FormContextType = any,
|
|
20
20
|
>(props: ArrayFieldDescriptionProps<T, S, F>) {
|
|
21
|
-
const {
|
|
21
|
+
const { fieldPathId, description, registry, schema, uiSchema } = props;
|
|
22
22
|
const options = getUiOptions<T, S, F>(uiSchema, registry.globalUiOptions);
|
|
23
23
|
const { label: displayLabel = true } = options;
|
|
24
24
|
if (!description || !displayLabel) {
|
|
@@ -31,7 +31,7 @@ export default function ArrayFieldDescriptionTemplate<
|
|
|
31
31
|
);
|
|
32
32
|
return (
|
|
33
33
|
<DescriptionFieldTemplate
|
|
34
|
-
id={descriptionId
|
|
34
|
+
id={descriptionId(fieldPathId)}
|
|
35
35
|
description={description}
|
|
36
36
|
schema={schema}
|
|
37
37
|
uiSchema={uiSchema}
|
|
@@ -23,7 +23,7 @@ export default function ArrayFieldItemButtonsTemplate<
|
|
|
23
23
|
hasMoveDown,
|
|
24
24
|
hasMoveUp,
|
|
25
25
|
hasRemove,
|
|
26
|
-
|
|
26
|
+
fieldPathId,
|
|
27
27
|
index,
|
|
28
28
|
onCopyIndexClick,
|
|
29
29
|
onDropIndexClick,
|
|
@@ -42,7 +42,7 @@ export default function ArrayFieldItemButtonsTemplate<
|
|
|
42
42
|
<>
|
|
43
43
|
{(hasMoveUp || hasMoveDown) && (
|
|
44
44
|
<MoveUpButton
|
|
45
|
-
id={buttonId
|
|
45
|
+
id={buttonId(fieldPathId, 'moveUp')}
|
|
46
46
|
className='rjsf-array-item-move-up'
|
|
47
47
|
disabled={disabled || readonly || !hasMoveUp}
|
|
48
48
|
onClick={onArrowUpClick}
|
|
@@ -52,7 +52,7 @@ export default function ArrayFieldItemButtonsTemplate<
|
|
|
52
52
|
)}
|
|
53
53
|
{(hasMoveUp || hasMoveDown) && (
|
|
54
54
|
<MoveDownButton
|
|
55
|
-
id={buttonId
|
|
55
|
+
id={buttonId(fieldPathId, 'moveDown')}
|
|
56
56
|
className='rjsf-array-item-move-down'
|
|
57
57
|
disabled={disabled || readonly || !hasMoveDown}
|
|
58
58
|
onClick={onArrowDownClick}
|
|
@@ -62,7 +62,7 @@ export default function ArrayFieldItemButtonsTemplate<
|
|
|
62
62
|
)}
|
|
63
63
|
{hasCopy && (
|
|
64
64
|
<CopyButton
|
|
65
|
-
id={buttonId
|
|
65
|
+
id={buttonId(fieldPathId, 'copy')}
|
|
66
66
|
className='rjsf-array-item-copy'
|
|
67
67
|
disabled={disabled || readonly}
|
|
68
68
|
onClick={onCopyClick}
|
|
@@ -72,7 +72,7 @@ export default function ArrayFieldItemButtonsTemplate<
|
|
|
72
72
|
)}
|
|
73
73
|
{hasRemove && (
|
|
74
74
|
<RemoveButton
|
|
75
|
-
id={buttonId
|
|
75
|
+
id={buttonId(fieldPathId, 'remove')}
|
|
76
76
|
className='rjsf-array-item-remove'
|
|
77
77
|
disabled={disabled || readonly}
|
|
78
78
|
onClick={onRemoveClick}
|
|
@@ -22,7 +22,7 @@ export default function ArrayFieldTemplate<
|
|
|
22
22
|
canAdd,
|
|
23
23
|
className,
|
|
24
24
|
disabled,
|
|
25
|
-
|
|
25
|
+
fieldPathId,
|
|
26
26
|
uiSchema,
|
|
27
27
|
items,
|
|
28
28
|
onAddClick,
|
|
@@ -53,9 +53,9 @@ export default function ArrayFieldTemplate<
|
|
|
53
53
|
ButtonTemplates: { AddButton },
|
|
54
54
|
} = registry.templates;
|
|
55
55
|
return (
|
|
56
|
-
<fieldset className={className} id={
|
|
56
|
+
<fieldset className={className} id={fieldPathId.$id}>
|
|
57
57
|
<ArrayFieldTitleTemplate
|
|
58
|
-
|
|
58
|
+
fieldPathId={fieldPathId}
|
|
59
59
|
title={uiOptions.title || title}
|
|
60
60
|
required={required}
|
|
61
61
|
schema={schema}
|
|
@@ -63,7 +63,7 @@ export default function ArrayFieldTemplate<
|
|
|
63
63
|
registry={registry}
|
|
64
64
|
/>
|
|
65
65
|
<ArrayFieldDescriptionTemplate
|
|
66
|
-
|
|
66
|
+
fieldPathId={fieldPathId}
|
|
67
67
|
description={uiOptions.description || schema.description}
|
|
68
68
|
schema={schema}
|
|
69
69
|
uiSchema={uiSchema}
|
|
@@ -77,7 +77,7 @@ export default function ArrayFieldTemplate<
|
|
|
77
77
|
</div>
|
|
78
78
|
{canAdd && (
|
|
79
79
|
<AddButton
|
|
80
|
-
id={buttonId
|
|
80
|
+
id={buttonId(fieldPathId, 'add')}
|
|
81
81
|
className='rjsf-array-item-add'
|
|
82
82
|
onClick={onAddClick}
|
|
83
83
|
disabled={disabled || readonly}
|
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
} from '@rjsf/utils';
|
|
11
11
|
|
|
12
12
|
/** The `ArrayFieldTitleTemplate` component renders a `TitleFieldTemplate` with an `id` derived from
|
|
13
|
-
* the `
|
|
13
|
+
* the `fieldPathId`.
|
|
14
14
|
*
|
|
15
15
|
* @param props - The `ArrayFieldTitleProps` for the component
|
|
16
16
|
*/
|
|
@@ -19,7 +19,7 @@ export default function ArrayFieldTitleTemplate<
|
|
|
19
19
|
S extends StrictRJSFSchema = RJSFSchema,
|
|
20
20
|
F extends FormContextType = any,
|
|
21
21
|
>(props: ArrayFieldTitleProps<T, S, F>) {
|
|
22
|
-
const {
|
|
22
|
+
const { fieldPathId, title, schema, uiSchema, required, registry } = props;
|
|
23
23
|
const options = getUiOptions<T, S, F>(uiSchema, registry.globalUiOptions);
|
|
24
24
|
const { label: displayLabel = true } = options;
|
|
25
25
|
if (!title || !displayLabel) {
|
|
@@ -32,7 +32,7 @@ export default function ArrayFieldTitleTemplate<
|
|
|
32
32
|
);
|
|
33
33
|
return (
|
|
34
34
|
<TitleFieldTemplate
|
|
35
|
-
id={titleId
|
|
35
|
+
id={titleId(fieldPathId)}
|
|
36
36
|
title={title}
|
|
37
37
|
required={required}
|
|
38
38
|
schema={schema}
|
|
@@ -85,14 +85,14 @@ export default function BaseInputTemplate<
|
|
|
85
85
|
autoFocus={autofocus}
|
|
86
86
|
value={inputValue}
|
|
87
87
|
{...inputProps}
|
|
88
|
-
list={schema.examples ? examplesId
|
|
88
|
+
list={schema.examples ? examplesId(id) : undefined}
|
|
89
89
|
onChange={onChangeOverride || _onChange}
|
|
90
90
|
onBlur={_onBlur}
|
|
91
91
|
onFocus={_onFocus}
|
|
92
|
-
aria-describedby={ariaDescribedByIds
|
|
92
|
+
aria-describedby={ariaDescribedByIds(id, !!schema.examples)}
|
|
93
93
|
/>
|
|
94
94
|
{Array.isArray(schema.examples) && (
|
|
95
|
-
<datalist key={`datalist_${id}`} id={examplesId
|
|
95
|
+
<datalist key={`datalist_${id}`} id={examplesId(id)}>
|
|
96
96
|
{(schema.examples as string[])
|
|
97
97
|
.concat(schema.default && !schema.examples.includes(schema.default) ? ([schema.default] as string[]) : [])
|
|
98
98
|
.map((example: any) => {
|
|
@@ -9,11 +9,11 @@ export default function FieldErrorTemplate<
|
|
|
9
9
|
S extends StrictRJSFSchema = RJSFSchema,
|
|
10
10
|
F extends FormContextType = any,
|
|
11
11
|
>(props: FieldErrorProps<T, S, F>) {
|
|
12
|
-
const { errors = [],
|
|
12
|
+
const { errors = [], fieldPathId } = props;
|
|
13
13
|
if (errors.length === 0) {
|
|
14
14
|
return null;
|
|
15
15
|
}
|
|
16
|
-
const id = errorId
|
|
16
|
+
const id = errorId(fieldPathId);
|
|
17
17
|
|
|
18
18
|
return (
|
|
19
19
|
<div>
|
|
@@ -9,11 +9,11 @@ export default function FieldHelpTemplate<
|
|
|
9
9
|
S extends StrictRJSFSchema = RJSFSchema,
|
|
10
10
|
F extends FormContextType = any,
|
|
11
11
|
>(props: FieldHelpProps<T, S, F>) {
|
|
12
|
-
const {
|
|
12
|
+
const { fieldPathId, help } = props;
|
|
13
13
|
if (!help) {
|
|
14
14
|
return null;
|
|
15
15
|
}
|
|
16
|
-
const id = helpId
|
|
16
|
+
const id = helpId(fieldPathId);
|
|
17
17
|
if (typeof help === 'string') {
|
|
18
18
|
return (
|
|
19
19
|
<p id={id} className='help-block'>
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { FormContextType, MultiSchemaFieldTemplateProps, RJSFSchema, StrictRJSFSchema } from '@rjsf/utils';
|
|
2
|
+
|
|
3
|
+
/** The `MultiSchemaFieldTemplate` component renders the layout for the MultiSchemaField, which supports choosing
|
|
4
|
+
* a schema from a list of schemas defined using `anyOf` or `oneOf`.
|
|
5
|
+
*
|
|
6
|
+
* @param props - The `MultiSchemaFieldTemplate` to be rendered
|
|
7
|
+
*/
|
|
8
|
+
export default function MultiSchemaFieldTemplate<
|
|
9
|
+
T = any,
|
|
10
|
+
S extends StrictRJSFSchema = RJSFSchema,
|
|
11
|
+
F extends FormContextType = any,
|
|
12
|
+
>(props: MultiSchemaFieldTemplateProps<T, S, F>) {
|
|
13
|
+
const { selector, optionSchemaField } = props;
|
|
14
|
+
return (
|
|
15
|
+
<div className='panel panel-default panel-body'>
|
|
16
|
+
<div className='form-group'>{selector}</div>
|
|
17
|
+
{optionSchemaField}
|
|
18
|
+
</div>
|
|
19
|
+
);
|
|
20
|
+
}
|
|
@@ -27,7 +27,7 @@ export default function ObjectFieldTemplate<
|
|
|
27
27
|
description,
|
|
28
28
|
disabled,
|
|
29
29
|
formData,
|
|
30
|
-
|
|
30
|
+
fieldPathId,
|
|
31
31
|
onAddClick,
|
|
32
32
|
properties,
|
|
33
33
|
readonly,
|
|
@@ -49,10 +49,10 @@ export default function ObjectFieldTemplate<
|
|
|
49
49
|
ButtonTemplates: { AddButton },
|
|
50
50
|
} = registry.templates;
|
|
51
51
|
return (
|
|
52
|
-
<fieldset id={
|
|
52
|
+
<fieldset id={fieldPathId.$id}>
|
|
53
53
|
{title && (
|
|
54
54
|
<TitleFieldTemplate
|
|
55
|
-
id={titleId
|
|
55
|
+
id={titleId(fieldPathId)}
|
|
56
56
|
title={title}
|
|
57
57
|
required={required}
|
|
58
58
|
schema={schema}
|
|
@@ -62,7 +62,7 @@ export default function ObjectFieldTemplate<
|
|
|
62
62
|
)}
|
|
63
63
|
{description && (
|
|
64
64
|
<DescriptionFieldTemplate
|
|
65
|
-
id={descriptionId
|
|
65
|
+
id={descriptionId(fieldPathId)}
|
|
66
66
|
description={description}
|
|
67
67
|
schema={schema}
|
|
68
68
|
uiSchema={uiSchema}
|
|
@@ -72,7 +72,7 @@ export default function ObjectFieldTemplate<
|
|
|
72
72
|
{properties.map((prop: ObjectFieldTemplatePropertyType) => prop.content)}
|
|
73
73
|
{canExpand<T, S, F>(schema, uiSchema, formData) && (
|
|
74
74
|
<AddButton
|
|
75
|
-
id={buttonId
|
|
75
|
+
id={buttonId(fieldPathId, 'add')}
|
|
76
76
|
className='rjsf-object-property-expand'
|
|
77
77
|
onClick={onAddClick(schema)}
|
|
78
78
|
disabled={disabled || readonly}
|
|
@@ -9,13 +9,13 @@ import Markdown from 'markdown-to-jsx';
|
|
|
9
9
|
function UnsupportedField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(
|
|
10
10
|
props: UnsupportedFieldProps<T, S, F>,
|
|
11
11
|
) {
|
|
12
|
-
const { schema,
|
|
12
|
+
const { schema, fieldPathId, reason, registry } = props;
|
|
13
13
|
const { translateString } = registry;
|
|
14
14
|
let translateEnum: TranslatableString = TranslatableString.UnsupportedField;
|
|
15
15
|
const translateParams: string[] = [];
|
|
16
|
-
if (
|
|
16
|
+
if (fieldPathId && fieldPathId.$id) {
|
|
17
17
|
translateEnum = TranslatableString.UnsupportedFieldWithId;
|
|
18
|
-
translateParams.push(
|
|
18
|
+
translateParams.push(fieldPathId.$id);
|
|
19
19
|
}
|
|
20
20
|
if (reason) {
|
|
21
21
|
translateEnum =
|
|
@@ -75,7 +75,7 @@ export default function WrapIfAdditionalTemplate<
|
|
|
75
75
|
<div className='form-additional form-group col-xs-5'>{children}</div>
|
|
76
76
|
<div className='col-xs-2'>
|
|
77
77
|
<RemoveButton
|
|
78
|
-
id={buttonId
|
|
78
|
+
id={buttonId(id, 'remove')}
|
|
79
79
|
className='rjsf-object-property-remove btn-block'
|
|
80
80
|
style={{ border: '0' }}
|
|
81
81
|
disabled={disabled || readonly}
|
|
@@ -13,6 +13,7 @@ import FieldTemplate from './FieldTemplate';
|
|
|
13
13
|
import FieldErrorTemplate from './FieldErrorTemplate';
|
|
14
14
|
import FieldHelpTemplate from './FieldHelpTemplate';
|
|
15
15
|
import GridTemplate from './GridTemplate';
|
|
16
|
+
import MultiSchemaFieldTemplate from './MultiSchemaFieldTemplate';
|
|
16
17
|
import ObjectFieldTemplate from './ObjectFieldTemplate';
|
|
17
18
|
import TitleField from './TitleField';
|
|
18
19
|
import UnsupportedField from './UnsupportedField';
|
|
@@ -37,6 +38,7 @@ function templates<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends F
|
|
|
37
38
|
FieldErrorTemplate,
|
|
38
39
|
FieldHelpTemplate,
|
|
39
40
|
GridTemplate,
|
|
41
|
+
MultiSchemaFieldTemplate,
|
|
40
42
|
ObjectFieldTemplate,
|
|
41
43
|
TitleFieldTemplate: TitleField,
|
|
42
44
|
UnsupportedFieldTemplate: UnsupportedField,
|