@rjsf/core 6.6.1 → 6.7.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/LICENSE.md +201 -0
- package/dist/core.umd.js +694 -584
- package/dist/index.cjs +1191 -1071
- package/dist/index.cjs.map +4 -4
- package/dist/index.esm.js +1030 -984
- package/dist/index.esm.js.map +4 -4
- package/lib/components/Form.d.ts +16 -13
- package/lib/components/Form.d.ts.map +1 -1
- package/lib/components/Form.js +126 -76
- package/lib/components/RichDescription.d.ts +3 -3
- package/lib/components/RichDescription.d.ts.map +1 -1
- package/lib/components/RichDescription.js +1 -1
- package/lib/components/RichHelp.d.ts +3 -3
- package/lib/components/RichHelp.d.ts.map +1 -1
- package/lib/components/RichHelp.js +1 -1
- package/lib/components/SchemaExamples.d.ts +2 -2
- package/lib/components/SchemaExamples.d.ts.map +1 -1
- package/lib/components/SchemaExamples.js +1 -3
- package/lib/components/fields/ArrayField.d.ts +2 -2
- package/lib/components/fields/ArrayField.d.ts.map +1 -1
- package/lib/components/fields/ArrayField.js +87 -88
- package/lib/components/fields/BooleanField.d.ts +2 -2
- package/lib/components/fields/BooleanField.d.ts.map +1 -1
- package/lib/components/fields/BooleanField.js +2 -5
- package/lib/components/fields/CyclicSchemaField.d.ts +8 -0
- package/lib/components/fields/CyclicSchemaField.d.ts.map +1 -0
- package/lib/components/fields/CyclicSchemaField.js +21 -0
- package/lib/components/fields/FallbackField.d.ts +2 -2
- package/lib/components/fields/FallbackField.d.ts.map +1 -1
- package/lib/components/fields/FallbackField.js +2 -2
- package/lib/components/fields/LayoutGridField.d.ts +8 -10
- package/lib/components/fields/LayoutGridField.d.ts.map +1 -1
- package/lib/components/fields/LayoutGridField.js +5 -4
- package/lib/components/fields/LayoutHeaderField.d.ts +2 -2
- package/lib/components/fields/LayoutHeaderField.d.ts.map +1 -1
- package/lib/components/fields/LayoutHeaderField.js +1 -1
- package/lib/components/fields/LayoutMultiSchemaField.d.ts +2 -2
- package/lib/components/fields/LayoutMultiSchemaField.d.ts.map +1 -1
- package/lib/components/fields/LayoutMultiSchemaField.js +4 -1
- package/lib/components/fields/MultiSchemaField.d.ts +2 -41
- package/lib/components/fields/MultiSchemaField.d.ts.map +1 -1
- package/lib/components/fields/MultiSchemaField.js +116 -122
- package/lib/components/fields/NullField.d.ts +1 -1
- package/lib/components/fields/NullField.d.ts.map +1 -1
- package/lib/components/fields/NumberField.d.ts +2 -2
- package/lib/components/fields/NumberField.d.ts.map +1 -1
- package/lib/components/fields/NumberField.js +7 -9
- package/lib/components/fields/ObjectField.d.ts +2 -2
- package/lib/components/fields/ObjectField.d.ts.map +1 -1
- package/lib/components/fields/ObjectField.js +28 -26
- package/lib/components/fields/OptionalDataControlsField.d.ts +2 -2
- package/lib/components/fields/OptionalDataControlsField.d.ts.map +1 -1
- package/lib/components/fields/SchemaField.d.ts +14 -8
- package/lib/components/fields/SchemaField.d.ts.map +1 -1
- package/lib/components/fields/SchemaField.js +43 -30
- package/lib/components/fields/StringField.d.ts +2 -2
- package/lib/components/fields/StringField.d.ts.map +1 -1
- package/lib/components/fields/StringField.js +2 -5
- package/lib/components/fields/index.d.ts +1 -1
- package/lib/components/fields/index.d.ts.map +1 -1
- package/lib/components/fields/index.js +2 -0
- package/lib/components/templates/ArrayFieldDescriptionTemplate.d.ts +2 -2
- package/lib/components/templates/ArrayFieldDescriptionTemplate.d.ts.map +1 -1
- package/lib/components/templates/ArrayFieldDescriptionTemplate.js +1 -1
- package/lib/components/templates/ArrayFieldItemButtonsTemplate.d.ts +2 -2
- package/lib/components/templates/ArrayFieldItemButtonsTemplate.d.ts.map +1 -1
- package/lib/components/templates/ArrayFieldItemButtonsTemplate.js +1 -1
- package/lib/components/templates/ArrayFieldItemTemplate.d.ts +2 -2
- package/lib/components/templates/ArrayFieldItemTemplate.d.ts.map +1 -1
- package/lib/components/templates/ArrayFieldItemTemplate.js +1 -1
- package/lib/components/templates/ArrayFieldTemplate.d.ts +2 -2
- package/lib/components/templates/ArrayFieldTemplate.d.ts.map +1 -1
- package/lib/components/templates/ArrayFieldTemplate.js +1 -1
- package/lib/components/templates/ArrayFieldTitleTemplate.d.ts +2 -2
- package/lib/components/templates/ArrayFieldTitleTemplate.d.ts.map +1 -1
- package/lib/components/templates/ArrayFieldTitleTemplate.js +1 -1
- package/lib/components/templates/BaseInputTemplate.d.ts +2 -2
- package/lib/components/templates/BaseInputTemplate.d.ts.map +1 -1
- package/lib/components/templates/BaseInputTemplate.js +7 -6
- package/lib/components/templates/ButtonTemplates/AddButton.d.ts +2 -2
- package/lib/components/templates/ButtonTemplates/AddButton.d.ts.map +1 -1
- package/lib/components/templates/ButtonTemplates/IconButton.d.ts +14 -7
- package/lib/components/templates/ButtonTemplates/IconButton.d.ts.map +1 -1
- package/lib/components/templates/ButtonTemplates/IconButton.js +14 -6
- package/lib/components/templates/ButtonTemplates/SubmitButton.d.ts +2 -2
- package/lib/components/templates/ButtonTemplates/SubmitButton.d.ts.map +1 -1
- package/lib/components/templates/ButtonTemplates/index.d.ts +1 -1
- package/lib/components/templates/ButtonTemplates/index.d.ts.map +1 -1
- package/lib/components/templates/CyclicSchemaExpandTemplate.d.ts +7 -0
- package/lib/components/templates/CyclicSchemaExpandTemplate.d.ts.map +1 -0
- package/lib/components/templates/CyclicSchemaExpandTemplate.js +12 -0
- package/lib/components/templates/DescriptionField.d.ts +2 -2
- package/lib/components/templates/DescriptionField.d.ts.map +1 -1
- package/lib/components/templates/ErrorList.d.ts +2 -2
- package/lib/components/templates/ErrorList.d.ts.map +1 -1
- package/lib/components/templates/ErrorList.js +2 -4
- package/lib/components/templates/FallbackFieldTemplate.d.ts +2 -2
- package/lib/components/templates/FallbackFieldTemplate.d.ts.map +1 -1
- package/lib/components/templates/FieldErrorTemplate.d.ts +2 -2
- package/lib/components/templates/FieldErrorTemplate.d.ts.map +1 -1
- package/lib/components/templates/FieldErrorTemplate.js +1 -3
- package/lib/components/templates/FieldHelpTemplate.d.ts +2 -2
- package/lib/components/templates/FieldHelpTemplate.d.ts.map +1 -1
- package/lib/components/templates/FieldTemplate/FieldTemplate.d.ts +2 -2
- package/lib/components/templates/FieldTemplate/FieldTemplate.d.ts.map +1 -1
- package/lib/components/templates/FieldTemplate/FieldTemplate.js +1 -1
- package/lib/components/templates/FieldTemplate/Label.d.ts +3 -3
- package/lib/components/templates/FieldTemplate/Label.d.ts.map +1 -1
- package/lib/components/templates/GridTemplate.d.ts +2 -2
- package/lib/components/templates/GridTemplate.d.ts.map +1 -1
- package/lib/components/templates/MultiSchemaFieldTemplate.d.ts +2 -2
- package/lib/components/templates/MultiSchemaFieldTemplate.d.ts.map +1 -1
- package/lib/components/templates/ObjectFieldTemplate.d.ts +2 -2
- package/lib/components/templates/ObjectFieldTemplate.d.ts.map +1 -1
- package/lib/components/templates/ObjectFieldTemplate.js +1 -1
- package/lib/components/templates/OptionalDataControlsTemplate.d.ts +2 -2
- package/lib/components/templates/OptionalDataControlsTemplate.d.ts.map +1 -1
- package/lib/components/templates/OptionalDataControlsTemplate.js +1 -1
- package/lib/components/templates/TitleField.d.ts +2 -2
- package/lib/components/templates/TitleField.d.ts.map +1 -1
- package/lib/components/templates/UnsupportedField.d.ts +2 -2
- package/lib/components/templates/UnsupportedField.d.ts.map +1 -1
- package/lib/components/templates/UnsupportedField.js +2 -2
- package/lib/components/templates/WrapIfAdditionalTemplate.d.ts +2 -2
- package/lib/components/templates/WrapIfAdditionalTemplate.d.ts.map +1 -1
- package/lib/components/templates/WrapIfAdditionalTemplate.js +1 -1
- package/lib/components/templates/index.d.ts +1 -1
- package/lib/components/templates/index.d.ts.map +1 -1
- package/lib/components/templates/index.js +2 -0
- package/lib/components/widgets/AltDateTimeWidget.d.ts +2 -2
- package/lib/components/widgets/AltDateTimeWidget.d.ts.map +1 -1
- package/lib/components/widgets/AltDateWidget.d.ts +2 -2
- package/lib/components/widgets/AltDateWidget.d.ts.map +1 -1
- package/lib/components/widgets/AltDateWidget.js +2 -2
- package/lib/components/widgets/CheckboxWidget.d.ts +2 -2
- package/lib/components/widgets/CheckboxWidget.d.ts.map +1 -1
- package/lib/components/widgets/CheckboxesWidget.d.ts +2 -2
- package/lib/components/widgets/CheckboxesWidget.d.ts.map +1 -1
- package/lib/components/widgets/CheckboxesWidget.js +4 -4
- package/lib/components/widgets/ColorWidget.d.ts +2 -2
- package/lib/components/widgets/ColorWidget.d.ts.map +1 -1
- package/lib/components/widgets/DateTimeWidget.d.ts +2 -2
- package/lib/components/widgets/DateTimeWidget.d.ts.map +1 -1
- package/lib/components/widgets/DateTimeWidget.js +2 -2
- package/lib/components/widgets/DateWidget.d.ts +2 -2
- package/lib/components/widgets/DateWidget.d.ts.map +1 -1
- package/lib/components/widgets/EmailWidget.d.ts +2 -2
- package/lib/components/widgets/EmailWidget.d.ts.map +1 -1
- package/lib/components/widgets/FileWidget.d.ts +2 -2
- package/lib/components/widgets/FileWidget.d.ts.map +1 -1
- package/lib/components/widgets/FileWidget.js +6 -4
- package/lib/components/widgets/HiddenWidget.d.ts +2 -2
- package/lib/components/widgets/HiddenWidget.d.ts.map +1 -1
- package/lib/components/widgets/PasswordWidget.d.ts +2 -2
- package/lib/components/widgets/PasswordWidget.d.ts.map +1 -1
- package/lib/components/widgets/RadioWidget.d.ts +2 -2
- package/lib/components/widgets/RadioWidget.d.ts.map +1 -1
- package/lib/components/widgets/RadioWidget.js +4 -4
- package/lib/components/widgets/RangeWidget.d.ts +2 -2
- package/lib/components/widgets/RangeWidget.d.ts.map +1 -1
- package/lib/components/widgets/RatingWidget.d.ts +2 -2
- package/lib/components/widgets/RatingWidget.d.ts.map +1 -1
- package/lib/components/widgets/RatingWidget.js +15 -15
- package/lib/components/widgets/SelectWidget.d.ts +2 -2
- package/lib/components/widgets/SelectWidget.d.ts.map +1 -1
- package/lib/components/widgets/SelectWidget.js +9 -8
- package/lib/components/widgets/TextWidget.d.ts +2 -2
- package/lib/components/widgets/TextWidget.d.ts.map +1 -1
- package/lib/components/widgets/TextareaWidget.d.ts +2 -2
- package/lib/components/widgets/TextareaWidget.d.ts.map +1 -1
- package/lib/components/widgets/TextareaWidget.js +5 -5
- package/lib/components/widgets/TimeWidget.d.ts +2 -2
- package/lib/components/widgets/TimeWidget.d.ts.map +1 -1
- package/lib/components/widgets/URLWidget.d.ts +2 -2
- package/lib/components/widgets/URLWidget.d.ts.map +1 -1
- package/lib/components/widgets/UpDownWidget.d.ts +2 -2
- package/lib/components/widgets/UpDownWidget.d.ts.map +1 -1
- package/lib/components/widgets/index.d.ts +1 -1
- package/lib/components/widgets/index.d.ts.map +1 -1
- package/lib/getDefaultRegistry.d.ts +1 -1
- package/lib/getDefaultRegistry.d.ts.map +1 -1
- package/lib/getDefaultRegistry.js +1 -1
- package/lib/getTestRegistry.d.ts +1 -1
- package/lib/getTestRegistry.d.ts.map +1 -1
- package/lib/getTestRegistry.js +1 -1
- package/lib/index.d.ts +10 -5
- package/lib/index.d.ts.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/withTheme.d.ts +3 -3
- package/lib/withTheme.d.ts.map +1 -1
- package/lib/withTheme.js +6 -6
- package/package.json +28 -28
- package/src/components/Form.tsx +197 -111
- package/src/components/RichDescription.tsx +3 -10
- package/src/components/RichHelp.tsx +3 -10
- package/src/components/SchemaExamples.tsx +6 -4
- package/src/components/fields/ArrayField.tsx +122 -108
- package/src/components/fields/BooleanField.tsx +4 -9
- package/src/components/fields/CyclicSchemaField.tsx +40 -0
- package/src/components/fields/FallbackField.tsx +4 -8
- package/src/components/fields/LayoutGridField.tsx +21 -19
- package/src/components/fields/LayoutHeaderField.tsx +2 -10
- package/src/components/fields/LayoutMultiSchemaField.tsx +15 -10
- package/src/components/fields/MultiSchemaField.tsx +202 -218
- package/src/components/fields/NullField.tsx +1 -1
- package/src/components/fields/NumberField.tsx +8 -10
- package/src/components/fields/ObjectField.tsx +52 -40
- package/src/components/fields/OptionalDataControlsField.tsx +6 -4
- package/src/components/fields/SchemaField.tsx +66 -51
- package/src/components/fields/StringField.tsx +4 -15
- package/src/components/fields/index.ts +3 -1
- package/src/components/templates/ArrayFieldDescriptionTemplate.tsx +2 -9
- package/src/components/templates/ArrayFieldItemButtonsTemplate.tsx +2 -7
- package/src/components/templates/ArrayFieldItemTemplate.tsx +3 -9
- package/src/components/templates/ArrayFieldTemplate.tsx +2 -9
- package/src/components/templates/ArrayFieldTitleTemplate.tsx +2 -10
- package/src/components/templates/BaseInputTemplate.tsx +16 -23
- package/src/components/templates/ButtonTemplates/AddButton.tsx +2 -1
- package/src/components/templates/ButtonTemplates/IconButton.tsx +16 -7
- package/src/components/templates/ButtonTemplates/SubmitButton.tsx +2 -1
- package/src/components/templates/ButtonTemplates/index.ts +1 -1
- package/src/components/templates/CyclicSchemaExpandTemplate.tsx +31 -0
- package/src/components/templates/DescriptionField.tsx +1 -1
- package/src/components/templates/ErrorList.tsx +8 -15
- package/src/components/templates/FallbackFieldTemplate.tsx +2 -1
- package/src/components/templates/FieldErrorTemplate.tsx +8 -8
- package/src/components/templates/FieldHelpTemplate.tsx +2 -1
- package/src/components/templates/FieldTemplate/FieldTemplate.tsx +2 -8
- package/src/components/templates/FieldTemplate/Label.tsx +2 -2
- package/src/components/templates/GridTemplate.tsx +1 -1
- package/src/components/templates/MultiSchemaFieldTemplate.tsx +1 -1
- package/src/components/templates/ObjectFieldTemplate.tsx +2 -7
- package/src/components/templates/OptionalDataControlsTemplate.tsx +3 -2
- package/src/components/templates/TitleField.tsx +1 -1
- package/src/components/templates/UnsupportedField.tsx +4 -3
- package/src/components/templates/WrapIfAdditionalTemplate.tsx +2 -9
- package/src/components/templates/index.ts +3 -1
- package/src/components/widgets/AltDateTimeWidget.tsx +1 -1
- package/src/components/widgets/AltDateWidget.tsx +7 -13
- package/src/components/widgets/CheckboxWidget.tsx +3 -5
- package/src/components/widgets/CheckboxesWidget.tsx +8 -10
- package/src/components/widgets/ColorWidget.tsx +2 -1
- package/src/components/widgets/DateTimeWidget.tsx +3 -10
- package/src/components/widgets/DateWidget.tsx +2 -1
- package/src/components/widgets/EmailWidget.tsx +2 -1
- package/src/components/widgets/FileWidget.tsx +9 -8
- package/src/components/widgets/HiddenWidget.tsx +1 -1
- package/src/components/widgets/PasswordWidget.tsx +2 -1
- package/src/components/widgets/RadioWidget.tsx +8 -10
- package/src/components/widgets/RangeWidget.tsx +1 -1
- package/src/components/widgets/RatingWidget.tsx +48 -47
- package/src/components/widgets/SelectWidget.tsx +48 -31
- package/src/components/widgets/TextWidget.tsx +2 -1
- package/src/components/widgets/TextareaWidget.tsx +10 -7
- package/src/components/widgets/TimeWidget.tsx +2 -1
- package/src/components/widgets/URLWidget.tsx +2 -1
- package/src/components/widgets/UpDownWidget.tsx +2 -1
- package/src/components/widgets/index.ts +1 -1
- package/src/getDefaultRegistry.ts +2 -9
- package/src/getTestRegistry.tsx +2 -7
- package/src/index.ts +10 -5
- package/src/withTheme.tsx +14 -9
|
@@ -1,4 +1,17 @@
|
|
|
1
|
-
import { FocusEvent
|
|
1
|
+
import type { FocusEvent } from 'react';
|
|
2
|
+
import { memo, useCallback, useMemo, useRef, useState } from 'react';
|
|
3
|
+
import type {
|
|
4
|
+
ErrorSchema,
|
|
5
|
+
FieldPathId,
|
|
6
|
+
FieldPathList,
|
|
7
|
+
FieldProps,
|
|
8
|
+
FormContextType,
|
|
9
|
+
GenericObjectType,
|
|
10
|
+
Registry,
|
|
11
|
+
RJSFMarkedSchema,
|
|
12
|
+
RJSFSchema,
|
|
13
|
+
StrictRJSFSchema,
|
|
14
|
+
} from '@rjsf/utils';
|
|
2
15
|
import {
|
|
3
16
|
ADDITIONAL_PROPERTY_FLAG,
|
|
4
17
|
ANY_OF_KEY,
|
|
@@ -9,25 +22,16 @@ import {
|
|
|
9
22
|
shouldRenderOptionalField,
|
|
10
23
|
toFieldPathId,
|
|
11
24
|
useDeepCompareMemo,
|
|
12
|
-
ErrorSchema,
|
|
13
|
-
FieldPathId,
|
|
14
|
-
FieldPathList,
|
|
15
|
-
FieldProps,
|
|
16
|
-
FormContextType,
|
|
17
|
-
GenericObjectType,
|
|
18
25
|
ONE_OF_KEY,
|
|
19
26
|
PROPERTIES_KEY,
|
|
20
27
|
REF_KEY,
|
|
21
|
-
Registry,
|
|
22
|
-
RJSFSchema,
|
|
23
|
-
StrictRJSFSchema,
|
|
24
28
|
TranslatableString,
|
|
25
29
|
} from '@rjsf/utils';
|
|
26
30
|
import get from 'lodash/get';
|
|
27
31
|
import has from 'lodash/has';
|
|
28
32
|
import isObject from 'lodash/isObject';
|
|
29
33
|
import set from 'lodash/set';
|
|
30
|
-
import { Markdown } from 'markdown-to-jsx';
|
|
34
|
+
import { Markdown } from 'markdown-to-jsx/react';
|
|
31
35
|
|
|
32
36
|
import { ADDITIONAL_PROPERTY_KEY_REMOVE } from '../constants';
|
|
33
37
|
|
|
@@ -38,7 +42,7 @@ import { ADDITIONAL_PROPERTY_KEY_REMOVE } from '../constants';
|
|
|
38
42
|
* @returns - True if the field `name` is required, false otherwise
|
|
39
43
|
*/
|
|
40
44
|
function isRequired<S extends StrictRJSFSchema = RJSFSchema>(schema: S, name: string) {
|
|
41
|
-
return Array.isArray(schema.required) && schema.required.
|
|
45
|
+
return Array.isArray(schema.required) && schema.required.includes(name);
|
|
42
46
|
}
|
|
43
47
|
|
|
44
48
|
/** Returns a default value to be used for a new additional schema property of the given `type`
|
|
@@ -86,7 +90,7 @@ interface ObjectFieldPropertyProps<
|
|
|
86
90
|
|
|
87
91
|
/** The `ObjectFieldProperty` component is used to render the `SchemaField` for a child property of an object
|
|
88
92
|
*/
|
|
89
|
-
function
|
|
93
|
+
function ObjectFieldPropertyFn<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(
|
|
90
94
|
props: ObjectFieldPropertyProps<T, S, F>,
|
|
91
95
|
) {
|
|
92
96
|
const {
|
|
@@ -125,14 +129,15 @@ function ObjectFieldProperty<T = any, S extends StrictRJSFSchema = RJSFSchema, F
|
|
|
125
129
|
*/
|
|
126
130
|
const onPropertyChange = useCallback(
|
|
127
131
|
(value: T | undefined, path: FieldPathList, newErrorSchema?: ErrorSchema<T>, id?: string) => {
|
|
132
|
+
// Don't set value = undefined for fields added by additionalProperties. Doing so removes them from the
|
|
133
|
+
// formData, which causes them to completely disappear (including the input field for the property name). Unlike
|
|
134
|
+
// fields which are "mandated" by the schema, these fields can be set to undefined by clicking a "delete field"
|
|
135
|
+
// button, so set empty values to the empty string.
|
|
136
|
+
let normalizedValue = value;
|
|
128
137
|
if (value === undefined && addedByAdditionalProperties) {
|
|
129
|
-
|
|
130
|
-
// formData, which causes them to completely disappear (including the input field for the property name). Unlike
|
|
131
|
-
// fields which are "mandated" by the schema, these fields can be set to undefined by clicking a "delete field"
|
|
132
|
-
// button, so set empty values to the empty string.
|
|
133
|
-
value = '' as unknown as T;
|
|
138
|
+
normalizedValue = '' as unknown as T;
|
|
134
139
|
}
|
|
135
|
-
onChange(
|
|
140
|
+
onChange(normalizedValue, path, newErrorSchema, id);
|
|
136
141
|
},
|
|
137
142
|
[onChange, addedByAdditionalProperties],
|
|
138
143
|
);
|
|
@@ -193,6 +198,8 @@ function ObjectFieldProperty<T = any, S extends StrictRJSFSchema = RJSFSchema, F
|
|
|
193
198
|
);
|
|
194
199
|
}
|
|
195
200
|
|
|
201
|
+
const ObjectFieldProperty = memo(ObjectFieldPropertyFn) as typeof ObjectFieldPropertyFn;
|
|
202
|
+
|
|
196
203
|
/** The `ObjectField` component is used to render a field in the schema that is of type `object`. It tracks whether an
|
|
197
204
|
* additional property key was modified and what it was modified to
|
|
198
205
|
*
|
|
@@ -222,8 +229,11 @@ export default function ObjectField<T = any, S extends StrictRJSFSchema = RJSFSc
|
|
|
222
229
|
const { OptionalDataControlsField } = fields;
|
|
223
230
|
const formDataRef = useRef(formData);
|
|
224
231
|
formDataRef.current = formData;
|
|
225
|
-
const schema: S =
|
|
226
|
-
|
|
232
|
+
const schema: S = useMemo(
|
|
233
|
+
() => schemaUtils.retrieveSchema(rawSchema, formData, true),
|
|
234
|
+
[schemaUtils, rawSchema, formData],
|
|
235
|
+
);
|
|
236
|
+
const uiOptions = useMemo(() => getUiOptions<T, S, F>(uiSchema, globalUiOptions), [uiSchema, globalUiOptions]);
|
|
227
237
|
const { properties: schemaProperties = {} } = schema;
|
|
228
238
|
// All the children will use childFieldPathId if present in the props, falling back to the fieldPathId
|
|
229
239
|
const childFieldPathId = props.childFieldPathId ?? fieldPathId;
|
|
@@ -243,13 +253,14 @@ export default function ObjectField<T = any, S extends StrictRJSFSchema = RJSFSc
|
|
|
243
253
|
* @returns - The name of the next available key from `preferredKey`
|
|
244
254
|
*/
|
|
245
255
|
const getAvailableKey = useCallback(
|
|
246
|
-
(preferredKey: string,
|
|
256
|
+
(preferredKey: string, existingFormData?: T) => {
|
|
247
257
|
const { duplicateKeySuffixSeparator = '-' } = getUiOptions<T, S, F>(uiSchema, globalUiOptions);
|
|
248
258
|
|
|
249
259
|
let index = 0;
|
|
250
260
|
let newKey = preferredKey;
|
|
251
|
-
while (has(
|
|
252
|
-
|
|
261
|
+
while (has(existingFormData, newKey)) {
|
|
262
|
+
index += 1;
|
|
263
|
+
newKey = `${preferredKey}${duplicateKeySuffixSeparator}${index}`;
|
|
253
264
|
}
|
|
254
265
|
return newKey;
|
|
255
266
|
},
|
|
@@ -263,7 +274,6 @@ export default function ObjectField<T = any, S extends StrictRJSFSchema = RJSFSc
|
|
|
263
274
|
if (!(schema.additionalProperties || schema.patternProperties)) {
|
|
264
275
|
return;
|
|
265
276
|
}
|
|
266
|
-
const { translateString } = registry;
|
|
267
277
|
const newFormData = { ...formData } as T;
|
|
268
278
|
const newKey = getAvailableKey('newKey', newFormData);
|
|
269
279
|
if (schema.patternProperties) {
|
|
@@ -279,11 +289,10 @@ export default function ObjectField<T = any, S extends StrictRJSFSchema = RJSFSc
|
|
|
279
289
|
defaultValue = schema.additionalProperties.default;
|
|
280
290
|
let apSchema = schema.additionalProperties;
|
|
281
291
|
if (REF_KEY in apSchema) {
|
|
282
|
-
const { schemaUtils } = registry;
|
|
283
292
|
apSchema = schemaUtils.retrieveSchema({ [REF_KEY]: apSchema[REF_KEY] } as S, formData);
|
|
284
293
|
type = apSchema.type;
|
|
285
294
|
constValue = apSchema.const;
|
|
286
|
-
defaultValue = apSchema
|
|
295
|
+
defaultValue = schemaUtils.getDefaultFormState(apSchema as S, defaultValue as T) as RJSFSchema['default'];
|
|
287
296
|
}
|
|
288
297
|
if (!type && (ANY_OF_KEY in apSchema || ONE_OF_KEY in apSchema)) {
|
|
289
298
|
type = 'object';
|
|
@@ -300,7 +309,7 @@ export default function ObjectField<T = any, S extends StrictRJSFSchema = RJSFSc
|
|
|
300
309
|
lastRenamedProperty.current.previousKey = getAvailableKey(newKey, newFormData);
|
|
301
310
|
}
|
|
302
311
|
onChange(newFormData, childFieldPathId.path);
|
|
303
|
-
}, [formData, onChange,
|
|
312
|
+
}, [formData, onChange, translateString, schemaUtils, childFieldPathId, getAvailableKey, schema]);
|
|
304
313
|
|
|
305
314
|
/** Returns a callback function that deals with the rename of a key for an additional property for a schema. That
|
|
306
315
|
* callback will attempt to rename the key and move the existing data to that key, calling `onChange` when it does.
|
|
@@ -319,8 +328,9 @@ export default function ObjectField<T = any, S extends StrictRJSFSchema = RJSFSc
|
|
|
319
328
|
};
|
|
320
329
|
const newKeys: GenericObjectType = { [oldKey]: actualNewKey };
|
|
321
330
|
const keyValues = Object.keys(newFormData).map((key) => {
|
|
322
|
-
|
|
323
|
-
|
|
331
|
+
// `Object.hasOwn` so a falsy rename target (e.g. `""`) isn't dropped.
|
|
332
|
+
const mappedKey = Object.hasOwn(newKeys, key) ? newKeys[key] : key;
|
|
333
|
+
return { [mappedKey]: newFormData[key] };
|
|
324
334
|
});
|
|
325
335
|
const renamedObj = Object.assign({}, ...keyValues);
|
|
326
336
|
|
|
@@ -384,20 +394,22 @@ export default function ObjectField<T = any, S extends StrictRJSFSchema = RJSFSc
|
|
|
384
394
|
// getDisplayLabel() always returns false for object types, so just check the `uiOptions.label`
|
|
385
395
|
title: uiOptions.label === false ? '' : templateTitle,
|
|
386
396
|
description: uiOptions.label === false ? undefined : description,
|
|
387
|
-
properties: orderedProperties.map((
|
|
388
|
-
const addedByAdditionalProperties =
|
|
389
|
-
|
|
397
|
+
properties: orderedProperties.map((propertyName) => {
|
|
398
|
+
const addedByAdditionalProperties = Boolean(
|
|
399
|
+
(schema.properties?.[propertyName] as RJSFMarkedSchema)?.[ADDITIONAL_PROPERTY_FLAG],
|
|
400
|
+
);
|
|
401
|
+
const fieldUiSchema = addedByAdditionalProperties ? uiSchema.additionalProperties : uiSchema[propertyName];
|
|
390
402
|
const hidden = getUiOptions<T, S, F>(fieldUiSchema).widget === 'hidden';
|
|
391
403
|
const content = (
|
|
392
404
|
<ObjectFieldProperty<T, S, F>
|
|
393
|
-
key={getStableKey(
|
|
394
|
-
propertyName={
|
|
395
|
-
required={isRequired<S>(schema,
|
|
396
|
-
schema={get(schema, [PROPERTIES_KEY,
|
|
405
|
+
key={getStableKey(propertyName)}
|
|
406
|
+
propertyName={propertyName}
|
|
407
|
+
required={isRequired<S>(schema, propertyName)}
|
|
408
|
+
schema={get(schema, [PROPERTIES_KEY, propertyName], {}) as S}
|
|
397
409
|
uiSchema={fieldUiSchema}
|
|
398
|
-
errorSchema={get(errorSchema, [
|
|
410
|
+
errorSchema={get(errorSchema, [propertyName])}
|
|
399
411
|
fieldPathId={childFieldPathId}
|
|
400
|
-
formData={get(formData, [
|
|
412
|
+
formData={get(formData, [propertyName])}
|
|
401
413
|
handleKeyRename={handleKeyRename}
|
|
402
414
|
handleRemoveProperty={handleRemoveProperty}
|
|
403
415
|
addedByAdditionalProperties={addedByAdditionalProperties}
|
|
@@ -412,7 +424,7 @@ export default function ObjectField<T = any, S extends StrictRJSFSchema = RJSFSc
|
|
|
412
424
|
);
|
|
413
425
|
return {
|
|
414
426
|
content,
|
|
415
|
-
name,
|
|
427
|
+
name: propertyName,
|
|
416
428
|
readonly,
|
|
417
429
|
disabled,
|
|
418
430
|
required,
|
|
@@ -1,14 +1,16 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type {
|
|
2
2
|
FieldProps,
|
|
3
3
|
FormContextType,
|
|
4
|
+
OptionalDataControlsTemplateProps,
|
|
5
|
+
RJSFSchema,
|
|
6
|
+
StrictRJSFSchema,
|
|
7
|
+
} from '@rjsf/utils';
|
|
8
|
+
import {
|
|
4
9
|
getSchemaType,
|
|
5
10
|
getTemplate,
|
|
6
11
|
getUiOptions,
|
|
7
12
|
isFormDataAvailable,
|
|
8
13
|
optionalControlsId,
|
|
9
|
-
OptionalDataControlsTemplateProps,
|
|
10
|
-
RJSFSchema,
|
|
11
|
-
StrictRJSFSchema,
|
|
12
14
|
TranslatableString,
|
|
13
15
|
} from '@rjsf/utils';
|
|
14
16
|
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
ANY_OF_KEY,
|
|
5
|
-
descriptionId,
|
|
1
|
+
import type { ComponentType } from 'react';
|
|
2
|
+
import { useCallback, memo } from 'react';
|
|
3
|
+
import type {
|
|
6
4
|
ErrorSchema,
|
|
7
5
|
Field,
|
|
8
6
|
FieldPathId,
|
|
@@ -10,28 +8,36 @@ import {
|
|
|
10
8
|
FieldProps,
|
|
11
9
|
FieldTemplateProps,
|
|
12
10
|
FormContextType,
|
|
11
|
+
Registry,
|
|
12
|
+
RJSFMarkedSchema,
|
|
13
|
+
RJSFSchema,
|
|
14
|
+
StrictRJSFSchema,
|
|
15
|
+
UIOptionsType,
|
|
16
|
+
} from '@rjsf/utils';
|
|
17
|
+
import {
|
|
18
|
+
ADDITIONAL_PROPERTY_FLAG,
|
|
19
|
+
ANY_OF_KEY,
|
|
20
|
+
deepEquals,
|
|
21
|
+
descriptionId,
|
|
13
22
|
getSchemaType,
|
|
14
23
|
getTemplate,
|
|
15
24
|
getUiOptions,
|
|
16
25
|
ID_KEY,
|
|
17
26
|
isFormDataAvailable,
|
|
18
27
|
ONE_OF_KEY,
|
|
19
|
-
Registry,
|
|
20
28
|
resolveUiSchema,
|
|
21
|
-
|
|
22
|
-
|
|
29
|
+
RJSF_REF_CYCLE_KEY,
|
|
30
|
+
shallowEquals,
|
|
23
31
|
shouldRenderOptionalField,
|
|
24
|
-
StrictRJSFSchema,
|
|
25
32
|
toFieldPathId,
|
|
26
33
|
TranslatableString,
|
|
27
34
|
UI_OPTIONS_KEY,
|
|
28
|
-
UIOptionsType,
|
|
29
35
|
} from '@rjsf/utils';
|
|
30
36
|
import isObject from 'lodash/isObject';
|
|
31
37
|
import omit from 'lodash/omit';
|
|
32
38
|
|
|
33
39
|
/** The map of component type to FieldName */
|
|
34
|
-
const COMPONENT_TYPES:
|
|
40
|
+
const COMPONENT_TYPES: Record<string, string> = {
|
|
35
41
|
array: 'ArrayField',
|
|
36
42
|
boolean: 'BooleanField',
|
|
37
43
|
integer: 'NumberField',
|
|
@@ -55,8 +61,8 @@ function getFieldComponent<T = any, S extends StrictRJSFSchema = RJSFSchema, F e
|
|
|
55
61
|
uiOptions: UIOptionsType<T, S, F>,
|
|
56
62
|
registry: Registry<T, S, F>,
|
|
57
63
|
): ComponentType<FieldProps<T, S, F>> {
|
|
58
|
-
const field = uiOptions
|
|
59
|
-
const { fields } = registry;
|
|
64
|
+
const { field } = uiOptions;
|
|
65
|
+
const { fields, schemaUtils } = registry;
|
|
60
66
|
if (typeof field === 'function') {
|
|
61
67
|
return field;
|
|
62
68
|
}
|
|
@@ -74,13 +80,17 @@ function getFieldComponent<T = any, S extends StrictRJSFSchema = RJSFSchema, F e
|
|
|
74
80
|
componentName = schemaId;
|
|
75
81
|
}
|
|
76
82
|
|
|
77
|
-
// If the
|
|
78
|
-
//
|
|
79
|
-
|
|
83
|
+
// If the schema uses 'anyOf' or 'oneOf' and is not a pure select (all-constant options),
|
|
84
|
+
// let the MultiSchemaField component handle the form display entirely.
|
|
85
|
+
// ObjectField is excluded: it renders shared properties (defined at the parent schema
|
|
86
|
+
// level) alongside the XxxOfField option selector.
|
|
87
|
+
// All other field types — including primitives and arrays — have no shared renderable
|
|
88
|
+
// properties, so the outer FieldComponent would only produce a spurious duplicate input.
|
|
89
|
+
if ((schema.anyOf || schema.oneOf) && !schemaUtils.isSelect(schema) && componentName !== 'ObjectField') {
|
|
80
90
|
return () => null;
|
|
81
91
|
}
|
|
82
92
|
|
|
83
|
-
return componentName in fields ? fields[componentName] : fields
|
|
93
|
+
return componentName in fields ? fields[componentName] : fields.FallbackField;
|
|
84
94
|
}
|
|
85
95
|
|
|
86
96
|
/** The `SchemaFieldRender` component is the work-horse of react-jsonschema-form, determining what kind of real field to
|
|
@@ -108,7 +118,26 @@ function SchemaFieldRender<T = any, S extends StrictRJSFSchema = RJSFSchema, F e
|
|
|
108
118
|
wasPropertyKeyModified = false,
|
|
109
119
|
} = props;
|
|
110
120
|
const { schemaUtils, globalFormOptions, globalUiOptions, fields } = registry;
|
|
111
|
-
const { AnyOfField: _AnyOfField, OneOfField: _OneOfField } = fields;
|
|
121
|
+
const { AnyOfField: _AnyOfField, OneOfField: _OneOfField, CyclicSchemaField } = fields;
|
|
122
|
+
const fieldId = fieldPathId[ID_KEY];
|
|
123
|
+
|
|
124
|
+
/** Intermediary `onChange` handler for field components that will inject the `id` of the current field into the
|
|
125
|
+
* `onChange` chain if it is not already being provided from a deeper level in the hierarchy
|
|
126
|
+
*/
|
|
127
|
+
const handleFieldComponentChange = useCallback(
|
|
128
|
+
(newFormData: T | undefined, path: FieldPathList, newErrorSchema?: ErrorSchema<T>, id?: string) => {
|
|
129
|
+
const theId = id || fieldId;
|
|
130
|
+
return onChange(newFormData, path, newErrorSchema, theId);
|
|
131
|
+
},
|
|
132
|
+
[fieldId, onChange],
|
|
133
|
+
);
|
|
134
|
+
|
|
135
|
+
// Stop $ref cycles: when resolveAllReferences detects a repeated property $ref it tags the schema with this flag.
|
|
136
|
+
// The check must come after all hook calls to satisfy React's rules of hooks.
|
|
137
|
+
if ((_schema as RJSFMarkedSchema)[RJSF_REF_CYCLE_KEY]) {
|
|
138
|
+
return <CyclicSchemaField {...props} />;
|
|
139
|
+
}
|
|
140
|
+
|
|
112
141
|
const uiSchema = resolveUiSchema<T, S, F>(_schema, _uiSchema, registry);
|
|
113
142
|
const uiOptions = getUiOptions<T, S, F>(uiSchema, globalUiOptions);
|
|
114
143
|
const FieldTemplate = getTemplate<'FieldTemplate', T, S, F>('FieldTemplate', registry, uiOptions);
|
|
@@ -120,18 +149,6 @@ function SchemaFieldRender<T = any, S extends StrictRJSFSchema = RJSFSchema, F e
|
|
|
120
149
|
const FieldHelpTemplate = getTemplate<'FieldHelpTemplate', T, S, F>('FieldHelpTemplate', registry, uiOptions);
|
|
121
150
|
const FieldErrorTemplate = getTemplate<'FieldErrorTemplate', T, S, F>('FieldErrorTemplate', registry, uiOptions);
|
|
122
151
|
const schema = schemaUtils.retrieveSchema(_schema, formData);
|
|
123
|
-
const fieldId = fieldPathId[ID_KEY];
|
|
124
|
-
|
|
125
|
-
/** Intermediary `onChange` handler for field components that will inject the `id` of the current field into the
|
|
126
|
-
* `onChange` chain if it is not already being provided from a deeper level in the hierarchy
|
|
127
|
-
*/
|
|
128
|
-
const handleFieldComponentChange = useCallback(
|
|
129
|
-
(formData: T | undefined, path: FieldPathList, newErrorSchema?: ErrorSchema<T>, id?: string) => {
|
|
130
|
-
const theId = id || fieldId;
|
|
131
|
-
return onChange(formData, path, newErrorSchema, theId);
|
|
132
|
-
},
|
|
133
|
-
[fieldId, onChange],
|
|
134
|
-
);
|
|
135
152
|
|
|
136
153
|
const FieldComponent = getFieldComponent<T, S, F>(schema, uiOptions, registry);
|
|
137
154
|
|
|
@@ -162,13 +179,13 @@ function SchemaFieldRender<T = any, S extends StrictRJSFSchema = RJSFSchema, F e
|
|
|
162
179
|
if ((ANY_OF_KEY in schema || ONE_OF_KEY in schema) && !isReplacingAnyOrOneOf && !schemaUtils.isSelect(schema)) {
|
|
163
180
|
if (schema[ANY_OF_KEY]) {
|
|
164
181
|
XxxOfField = _AnyOfField;
|
|
165
|
-
XxxOfOptions = schema[ANY_OF_KEY].map((
|
|
166
|
-
schemaUtils.retrieveSchema(isObject(
|
|
182
|
+
XxxOfOptions = schema[ANY_OF_KEY].map((xxxOfSchema) =>
|
|
183
|
+
schemaUtils.retrieveSchema(isObject(xxxOfSchema) ? (xxxOfSchema as S) : ({} as S), formData),
|
|
167
184
|
);
|
|
168
185
|
} else if (schema[ONE_OF_KEY]) {
|
|
169
186
|
XxxOfField = _OneOfField;
|
|
170
|
-
XxxOfOptions = schema[ONE_OF_KEY].map((
|
|
171
|
-
schemaUtils.retrieveSchema(isObject(
|
|
187
|
+
XxxOfOptions = schema[ONE_OF_KEY].map((xxxOfSchema) =>
|
|
188
|
+
schemaUtils.retrieveSchema(isObject(xxxOfSchema) ? (xxxOfSchema as S) : ({} as S), formData),
|
|
172
189
|
);
|
|
173
190
|
}
|
|
174
191
|
// When the anyOf/oneOf is an optional data control render AND it does not have form data, hide the label
|
|
@@ -224,7 +241,7 @@ function SchemaFieldRender<T = any, S extends StrictRJSFSchema = RJSFSchema, F e
|
|
|
224
241
|
}
|
|
225
242
|
|
|
226
243
|
const description = uiOptions.description || props.schema.description || schema.description || '';
|
|
227
|
-
const help = uiOptions
|
|
244
|
+
const { help } = uiOptions;
|
|
228
245
|
const hidden = uiOptions.widget === 'hidden' || deprecatedHandling === 'hide';
|
|
229
246
|
|
|
230
247
|
const classNames = ['rjsf-field', `rjsf-field-${getSchemaType(schema)}`];
|
|
@@ -324,24 +341,22 @@ function SchemaFieldRender<T = any, S extends StrictRJSFSchema = RJSFSchema, F e
|
|
|
324
341
|
);
|
|
325
342
|
}
|
|
326
343
|
|
|
327
|
-
/** The `SchemaField` component determines whether it is necessary to rerender the component based on any props changes
|
|
328
|
-
*
|
|
344
|
+
/** The `SchemaField` component wraps `SchemaFieldRender` with a custom memoization comparator that determines whether it is necessary to rerender the component based on any props changes
|
|
345
|
+
* using `experimental_componentUpdateStrategy`.
|
|
346
|
+
*
|
|
347
|
+
* The cast to `typeof SchemaFieldRender` preserves the generic type signature (<T, S, F>) for consumers,
|
|
348
|
+
* since React.memo's return type erases generic parameters.
|
|
329
349
|
*/
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
const {
|
|
335
|
-
registry: { globalFormOptions },
|
|
336
|
-
} = this.props;
|
|
337
|
-
const { experimental_componentUpdateStrategy = 'customDeep' } = globalFormOptions;
|
|
338
|
-
|
|
339
|
-
return shouldRender(this, nextProps, this.state, experimental_componentUpdateStrategy);
|
|
350
|
+
const SchemaField = memo(SchemaFieldRender, (prevProps, nextProps) => {
|
|
351
|
+
const { experimental_componentUpdateStrategy = 'customDeep' } = nextProps.registry.globalFormOptions;
|
|
352
|
+
if (experimental_componentUpdateStrategy === 'always') {
|
|
353
|
+
return false; // always re-render — never consider props equal
|
|
340
354
|
}
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
return <SchemaFieldRender<T, S, F> {...this.props} />;
|
|
355
|
+
if (experimental_componentUpdateStrategy === 'shallow') {
|
|
356
|
+
return shallowEquals(prevProps, nextProps);
|
|
344
357
|
}
|
|
345
|
-
|
|
358
|
+
// default: 'customDeep'
|
|
359
|
+
return deepEquals(prevProps, nextProps);
|
|
360
|
+
}) as unknown as typeof SchemaFieldRender;
|
|
346
361
|
|
|
347
362
|
export default SchemaField;
|
|
@@ -1,15 +1,6 @@
|
|
|
1
1
|
import { useCallback } from 'react';
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
getUiOptions,
|
|
5
|
-
optionsList,
|
|
6
|
-
hasWidget,
|
|
7
|
-
FieldProps,
|
|
8
|
-
FormContextType,
|
|
9
|
-
RJSFSchema,
|
|
10
|
-
StrictRJSFSchema,
|
|
11
|
-
ErrorSchema,
|
|
12
|
-
} from '@rjsf/utils';
|
|
2
|
+
import type { FieldProps, FormContextType, RJSFSchema, StrictRJSFSchema, ErrorSchema } from '@rjsf/utils';
|
|
3
|
+
import { getWidget, getUiOptions, optionsList, hasWidget } from '@rjsf/utils';
|
|
13
4
|
|
|
14
5
|
/** The `StringField` component is used to render a schema field that represents a string type
|
|
15
6
|
*
|
|
@@ -48,10 +39,8 @@ function StringField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends
|
|
|
48
39
|
const label = uiTitle ?? title ?? schemaTitle ?? name;
|
|
49
40
|
const Widget = getWidget<T, S, F>(schema, widget, widgets);
|
|
50
41
|
const onWidgetChange = useCallback(
|
|
51
|
-
(value: T | undefined, errorSchema?: ErrorSchema, id?: string) =>
|
|
52
|
-
|
|
53
|
-
return onChange(value, fieldPathId.path, errorSchema, id);
|
|
54
|
-
},
|
|
42
|
+
(value: T | undefined, errorSchema?: ErrorSchema, id?: string) =>
|
|
43
|
+
onChange(value, fieldPathId.path, errorSchema, id),
|
|
55
44
|
[onChange, fieldPathId],
|
|
56
45
|
);
|
|
57
46
|
return (
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { Field, FormContextType, RegistryFieldsType, RJSFSchema, StrictRJSFSchema } from '@rjsf/utils';
|
|
1
|
+
import type { Field, FormContextType, RegistryFieldsType, RJSFSchema, StrictRJSFSchema } from '@rjsf/utils';
|
|
2
2
|
|
|
3
3
|
import ArrayField from './ArrayField';
|
|
4
4
|
import BooleanField from './BooleanField';
|
|
5
|
+
import CyclicSchemaField from './CyclicSchemaField';
|
|
5
6
|
import FallbackField from './FallbackField';
|
|
6
7
|
import LayoutGridField from './LayoutGridField';
|
|
7
8
|
import LayoutHeaderField from './LayoutHeaderField';
|
|
@@ -24,6 +25,7 @@ function fields<
|
|
|
24
25
|
ArrayField: ArrayField as unknown as Field<T, S, F>,
|
|
25
26
|
// ArrayField falls back to SchemaField if ArraySchemaField is not defined, which it isn't by default
|
|
26
27
|
BooleanField,
|
|
28
|
+
CyclicSchemaField,
|
|
27
29
|
FallbackField,
|
|
28
30
|
LayoutGridField,
|
|
29
31
|
LayoutHeaderField,
|
|
@@ -1,12 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
getTemplate,
|
|
4
|
-
getUiOptions,
|
|
5
|
-
ArrayFieldDescriptionProps,
|
|
6
|
-
FormContextType,
|
|
7
|
-
RJSFSchema,
|
|
8
|
-
StrictRJSFSchema,
|
|
9
|
-
} from '@rjsf/utils';
|
|
1
|
+
import type { ArrayFieldDescriptionProps, FormContextType, RJSFSchema, StrictRJSFSchema } from '@rjsf/utils';
|
|
2
|
+
import { descriptionId, getTemplate, getUiOptions } from '@rjsf/utils';
|
|
10
3
|
|
|
11
4
|
/** The `ArrayFieldDescriptionTemplate` component renders a `DescriptionFieldTemplate` with an `id` derived from
|
|
12
5
|
* the `fieldPathId`.
|
|
@@ -1,10 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
buttonId,
|
|
4
|
-
FormContextType,
|
|
5
|
-
RJSFSchema,
|
|
6
|
-
StrictRJSFSchema,
|
|
7
|
-
} from '@rjsf/utils';
|
|
1
|
+
import type { ArrayFieldItemButtonsTemplateProps, FormContextType, RJSFSchema, StrictRJSFSchema } from '@rjsf/utils';
|
|
2
|
+
import { buttonId } from '@rjsf/utils';
|
|
8
3
|
|
|
9
4
|
/** The `ArrayFieldTemplateItemButtons` component is the template used to render the buttons associate3d with items of
|
|
10
5
|
* an array.
|
|
@@ -1,12 +1,6 @@
|
|
|
1
|
-
import { CSSProperties } from 'react';
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
FormContextType,
|
|
5
|
-
getTemplate,
|
|
6
|
-
getUiOptions,
|
|
7
|
-
RJSFSchema,
|
|
8
|
-
StrictRJSFSchema,
|
|
9
|
-
} from '@rjsf/utils';
|
|
1
|
+
import type { CSSProperties } from 'react';
|
|
2
|
+
import type { ArrayFieldItemTemplateProps, FormContextType, RJSFSchema, StrictRJSFSchema } from '@rjsf/utils';
|
|
3
|
+
import { getTemplate, getUiOptions } from '@rjsf/utils';
|
|
10
4
|
|
|
11
5
|
/** The `ArrayFieldItemTemplate` component is the template used to render an items of an array.
|
|
12
6
|
*
|
|
@@ -1,12 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
getUiOptions,
|
|
4
|
-
ArrayFieldTemplateProps,
|
|
5
|
-
FormContextType,
|
|
6
|
-
RJSFSchema,
|
|
7
|
-
StrictRJSFSchema,
|
|
8
|
-
buttonId,
|
|
9
|
-
} from '@rjsf/utils';
|
|
1
|
+
import type { ArrayFieldTemplateProps, FormContextType, RJSFSchema, StrictRJSFSchema } from '@rjsf/utils';
|
|
2
|
+
import { getTemplate, getUiOptions, buttonId } from '@rjsf/utils';
|
|
10
3
|
|
|
11
4
|
/** The `ArrayFieldTemplate` component is the template used to render all items in an array.
|
|
12
5
|
*
|
|
@@ -1,13 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
getUiOptions,
|
|
4
|
-
titleId,
|
|
5
|
-
ArrayFieldTitleProps,
|
|
6
|
-
FormContextType,
|
|
7
|
-
RJSFSchema,
|
|
8
|
-
StrictRJSFSchema,
|
|
9
|
-
TemplatesType,
|
|
10
|
-
} from '@rjsf/utils';
|
|
1
|
+
import type { ArrayFieldTitleProps, FormContextType, RJSFSchema, StrictRJSFSchema, TemplatesType } from '@rjsf/utils';
|
|
2
|
+
import { getTemplate, getUiOptions, titleId } from '@rjsf/utils';
|
|
11
3
|
|
|
12
4
|
/** The `ArrayFieldTitleTemplate` component renders a `TitleFieldTemplate` with an `id` derived from
|
|
13
5
|
* the `fieldPathId`.
|
|
@@ -1,13 +1,7 @@
|
|
|
1
|
-
import { ChangeEvent, FocusEvent, MouseEvent
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
examplesId,
|
|
6
|
-
getInputProps,
|
|
7
|
-
FormContextType,
|
|
8
|
-
RJSFSchema,
|
|
9
|
-
StrictRJSFSchema,
|
|
10
|
-
} from '@rjsf/utils';
|
|
1
|
+
import type { ChangeEvent, FocusEvent, MouseEvent } from 'react';
|
|
2
|
+
import { useCallback } from 'react';
|
|
3
|
+
import type { BaseInputTemplateProps, FormContextType, RJSFSchema, StrictRJSFSchema } from '@rjsf/utils';
|
|
4
|
+
import { ariaDescribedByIds, examplesId, getInputProps } from '@rjsf/utils';
|
|
11
5
|
|
|
12
6
|
import SchemaExamples from '../SchemaExamples';
|
|
13
7
|
|
|
@@ -49,6 +43,7 @@ export default function BaseInputTemplate<
|
|
|
49
43
|
// Note: since React 15.2.0 we can't forward unknown element attributes, so we
|
|
50
44
|
// exclude the "options" and "schema" ones here.
|
|
51
45
|
if (!id) {
|
|
46
|
+
// oxlint-disable-next-line no-console
|
|
52
47
|
console.log('No id for', props);
|
|
53
48
|
throw new Error(`no id for props ${JSON.stringify(props)}`);
|
|
54
49
|
}
|
|
@@ -64,19 +59,17 @@ export default function BaseInputTemplate<
|
|
|
64
59
|
inputValue = value == null ? '' : value;
|
|
65
60
|
}
|
|
66
61
|
|
|
67
|
-
const
|
|
68
|
-
({ target: { value } }: ChangeEvent<HTMLInputElement>) =>
|
|
62
|
+
const handleChange = useCallback(
|
|
63
|
+
({ target: { value: newValue } }: ChangeEvent<HTMLInputElement>) =>
|
|
64
|
+
onChange(newValue === '' ? options.emptyValue : newValue),
|
|
69
65
|
[onChange, options],
|
|
70
66
|
);
|
|
71
|
-
const
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
);
|
|
75
|
-
const _onFocus = useCallback(
|
|
76
|
-
({ target }: FocusEvent<HTMLInputElement>) => onFocus(id, target && target.value),
|
|
67
|
+
const handleBlur = useCallback(({ target }: FocusEvent<HTMLInputElement>) => onBlur(id, target?.value), [onBlur, id]);
|
|
68
|
+
const handleFocus = useCallback(
|
|
69
|
+
({ target }: FocusEvent<HTMLInputElement>) => onFocus(id, target?.value),
|
|
77
70
|
[onFocus, id],
|
|
78
71
|
);
|
|
79
|
-
const
|
|
72
|
+
const handleClear = useCallback(
|
|
80
73
|
(e: MouseEvent) => {
|
|
81
74
|
e.preventDefault();
|
|
82
75
|
e.stopPropagation();
|
|
@@ -97,13 +90,13 @@ export default function BaseInputTemplate<
|
|
|
97
90
|
value={inputValue}
|
|
98
91
|
{...inputProps}
|
|
99
92
|
list={schema.examples ? examplesId(id) : undefined}
|
|
100
|
-
onChange={onChangeOverride ||
|
|
101
|
-
onBlur={
|
|
102
|
-
onFocus={
|
|
93
|
+
onChange={onChangeOverride || handleChange}
|
|
94
|
+
onBlur={handleBlur}
|
|
95
|
+
onFocus={handleFocus}
|
|
103
96
|
aria-describedby={ariaDescribedByIds(id, !!schema.examples)}
|
|
104
97
|
/>
|
|
105
98
|
{options.allowClearTextInputs && !readonly && !disabled && inputValue && (
|
|
106
|
-
<ClearButton registry={registry} onClick={
|
|
99
|
+
<ClearButton registry={registry} onClick={handleClear} />
|
|
107
100
|
)}
|
|
108
101
|
<SchemaExamples id={id} schema={schema} />
|
|
109
102
|
</>
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { FormContextType, IconButtonProps, RJSFSchema, StrictRJSFSchema
|
|
1
|
+
import type { FormContextType, IconButtonProps, RJSFSchema, StrictRJSFSchema } from '@rjsf/utils';
|
|
2
|
+
import { TranslatableString } from '@rjsf/utils';
|
|
2
3
|
|
|
3
4
|
import IconButton from './IconButton';
|
|
4
5
|
|