@rjsf/core 6.0.0-beta.8 → 6.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/README.md +2 -0
- package/dist/core.umd.js +2042 -1987
- package/dist/index.cjs +4909 -0
- package/dist/index.cjs.map +7 -0
- package/dist/index.esm.js +2509 -2389
- package/dist/index.esm.js.map +4 -4
- package/lib/components/Form.d.ts +137 -34
- package/lib/components/Form.d.ts.map +1 -1
- package/lib/components/Form.js +318 -173
- package/lib/components/fields/ArrayField.d.ts +2 -187
- package/lib/components/fields/ArrayField.d.ts.map +1 -1
- package/lib/components/fields/ArrayField.js +526 -492
- package/lib/components/fields/BooleanField.d.ts.map +1 -1
- package/lib/components/fields/BooleanField.js +8 -3
- package/lib/components/fields/FallbackField.d.ts +7 -0
- package/lib/components/fields/FallbackField.d.ts.map +1 -0
- package/lib/components/fields/FallbackField.js +72 -0
- package/lib/components/fields/LayoutGridField.d.ts +109 -186
- package/lib/components/fields/LayoutGridField.d.ts.map +1 -1
- package/lib/components/fields/LayoutGridField.js +426 -426
- package/lib/components/fields/LayoutHeaderField.d.ts +1 -1
- package/lib/components/fields/LayoutHeaderField.js +3 -3
- package/lib/components/fields/LayoutMultiSchemaField.d.ts.map +1 -1
- package/lib/components/fields/LayoutMultiSchemaField.js +6 -6
- package/lib/components/fields/MultiSchemaField.d.ts.map +1 -1
- package/lib/components/fields/MultiSchemaField.js +16 -10
- 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 +2 -68
- package/lib/components/fields/ObjectField.d.ts.map +1 -1
- package/lib/components/fields/ObjectField.js +163 -163
- package/lib/components/fields/OptionalDataControlsField.d.ts +8 -0
- package/lib/components/fields/OptionalDataControlsField.d.ts.map +1 -0
- package/lib/components/fields/OptionalDataControlsField.js +43 -0
- package/lib/components/fields/SchemaField.d.ts.map +1 -1
- package/lib/components/fields/SchemaField.js +52 -30
- package/lib/components/fields/StringField.d.ts.map +1 -1
- package/lib/components/fields/StringField.js +8 -3
- package/lib/components/fields/index.d.ts.map +1 -1
- package/lib/components/fields/index.js +4 -0
- package/lib/components/templates/ArrayFieldDescriptionTemplate.d.ts +1 -1
- package/lib/components/templates/ArrayFieldDescriptionTemplate.js +3 -3
- package/lib/components/templates/ArrayFieldItemButtonsTemplate.d.ts +3 -3
- package/lib/components/templates/ArrayFieldItemButtonsTemplate.d.ts.map +1 -1
- package/lib/components/templates/ArrayFieldItemButtonsTemplate.js +3 -8
- package/lib/components/templates/ArrayFieldItemTemplate.d.ts +3 -3
- 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 +1 -1
- package/lib/components/templates/ArrayFieldTemplate.d.ts.map +1 -1
- package/lib/components/templates/ArrayFieldTemplate.js +4 -5
- package/lib/components/templates/ArrayFieldTitleTemplate.d.ts +1 -1
- package/lib/components/templates/ArrayFieldTitleTemplate.d.ts.map +1 -1
- package/lib/components/templates/ArrayFieldTitleTemplate.js +3 -3
- package/lib/components/templates/BaseInputTemplate.js +2 -2
- package/lib/components/templates/ButtonTemplates/AddButton.d.ts +1 -1
- package/lib/components/templates/ButtonTemplates/AddButton.d.ts.map +1 -1
- package/lib/components/templates/ButtonTemplates/AddButton.js +2 -2
- package/lib/components/templates/FallbackFieldTemplate.d.ts +7 -0
- package/lib/components/templates/FallbackFieldTemplate.d.ts.map +1 -0
- package/lib/components/templates/FallbackFieldTemplate.js +12 -0
- 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.d.ts.map +1 -1
- package/lib/components/templates/ObjectFieldTemplate.js +3 -2
- package/lib/components/templates/OptionalDataControlsTemplate.d.ts +11 -0
- package/lib/components/templates/OptionalDataControlsTemplate.d.ts.map +1 -0
- package/lib/components/templates/OptionalDataControlsTemplate.js +20 -0
- package/lib/components/templates/TitleField.d.ts.map +1 -1
- package/lib/components/templates/TitleField.js +2 -2
- package/lib/components/templates/UnsupportedField.js +3 -3
- package/lib/components/templates/WrapIfAdditionalTemplate.js +2 -2
- package/lib/components/templates/index.d.ts.map +1 -1
- package/lib/components/templates/index.js +6 -0
- package/lib/components/widgets/AltDateWidget.d.ts +1 -1
- package/lib/components/widgets/AltDateWidget.d.ts.map +1 -1
- package/lib/components/widgets/AltDateWidget.js +5 -46
- package/lib/components/widgets/CheckboxWidget.d.ts +1 -1
- package/lib/components/widgets/CheckboxWidget.d.ts.map +1 -1
- package/lib/components/widgets/CheckboxWidget.js +2 -2
- package/lib/components/widgets/CheckboxesWidget.d.ts +1 -1
- package/lib/components/widgets/CheckboxesWidget.d.ts.map +1 -1
- package/lib/components/widgets/CheckboxesWidget.js +4 -4
- package/lib/components/widgets/FileWidget.d.ts.map +1 -1
- package/lib/components/widgets/FileWidget.js +7 -87
- package/lib/components/widgets/HiddenWidget.d.ts +1 -1
- package/lib/components/widgets/HiddenWidget.d.ts.map +1 -1
- package/lib/components/widgets/HiddenWidget.js +2 -2
- package/lib/components/widgets/RadioWidget.d.ts +1 -1
- package/lib/components/widgets/RadioWidget.d.ts.map +1 -1
- package/lib/components/widgets/RadioWidget.js +2 -2
- package/lib/components/widgets/RatingWidget.d.ts +1 -1
- package/lib/components/widgets/RatingWidget.d.ts.map +1 -1
- package/lib/components/widgets/RatingWidget.js +2 -2
- package/lib/components/widgets/SelectWidget.d.ts +1 -1
- package/lib/components/widgets/SelectWidget.d.ts.map +1 -1
- package/lib/components/widgets/SelectWidget.js +2 -2
- package/lib/components/widgets/TextareaWidget.d.ts +1 -1
- package/lib/components/widgets/TextareaWidget.d.ts.map +1 -1
- package/lib/components/widgets/TextareaWidget.js +2 -2
- package/lib/getDefaultRegistry.d.ts.map +1 -1
- package/lib/getDefaultRegistry.js +6 -1
- package/lib/getTestRegistry.d.ts +5 -0
- package/lib/getTestRegistry.d.ts.map +1 -0
- package/lib/getTestRegistry.js +23 -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 +35 -20
- package/src/components/Form.tsx +468 -206
- package/src/components/fields/ArrayField.tsx +871 -723
- package/src/components/fields/BooleanField.tsx +14 -5
- package/src/components/fields/FallbackField.tsx +157 -0
- package/src/components/fields/LayoutGridField.tsx +626 -603
- package/src/components/fields/LayoutHeaderField.tsx +3 -3
- package/src/components/fields/LayoutMultiSchemaField.tsx +9 -10
- package/src/components/fields/MultiSchemaField.tsx +57 -36
- package/src/components/fields/NullField.tsx +3 -3
- package/src/components/fields/NumberField.tsx +11 -3
- package/src/components/fields/ObjectField.tsx +308 -239
- package/src/components/fields/OptionalDataControlsField.tsx +84 -0
- package/src/components/fields/SchemaField.tsx +75 -94
- package/src/components/fields/StringField.tsx +14 -5
- package/src/components/fields/index.ts +4 -0
- package/src/components/templates/ArrayFieldDescriptionTemplate.tsx +3 -3
- package/src/components/templates/ArrayFieldItemButtonsTemplate.tsx +16 -21
- package/src/components/templates/ArrayFieldItemTemplate.tsx +3 -3
- package/src/components/templates/ArrayFieldTemplate.tsx +11 -18
- package/src/components/templates/ArrayFieldTitleTemplate.tsx +4 -3
- package/src/components/templates/BaseInputTemplate.tsx +5 -5
- package/src/components/templates/ButtonTemplates/AddButton.tsx +2 -0
- package/src/components/templates/FallbackFieldTemplate.tsx +28 -0
- 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 +12 -7
- package/src/components/templates/OptionalDataControlsTemplate.tsx +43 -0
- package/src/components/templates/TitleField.tsx +6 -1
- package/src/components/templates/UnsupportedField.tsx +3 -3
- package/src/components/templates/WrapIfAdditionalTemplate.tsx +5 -5
- package/src/components/templates/index.ts +6 -0
- package/src/components/widgets/AltDateWidget.tsx +8 -126
- package/src/components/widgets/CheckboxWidget.tsx +4 -3
- package/src/components/widgets/CheckboxesWidget.tsx +5 -4
- package/src/components/widgets/FileWidget.tsx +11 -102
- package/src/components/widgets/HiddenWidget.tsx +2 -1
- package/src/components/widgets/RadioWidget.tsx +3 -2
- package/src/components/widgets/RatingWidget.tsx +2 -1
- package/src/components/widgets/SelectWidget.tsx +3 -2
- package/src/components/widgets/TextareaWidget.tsx +3 -2
- package/src/getDefaultRegistry.ts +14 -1
- package/src/getTestRegistry.tsx +38 -0
- package/src/index.ts +2 -1
- package/dist/index.js +0 -4834
- package/dist/index.js.map +0 -7
|
@@ -27,19 +27,20 @@ function CheckboxesWidget<T = any, S extends StrictRJSFSchema = RJSFSchema, F ex
|
|
|
27
27
|
onChange,
|
|
28
28
|
onBlur,
|
|
29
29
|
onFocus,
|
|
30
|
+
htmlName,
|
|
30
31
|
}: WidgetProps<T, S, F>) {
|
|
31
32
|
const checkboxesValues = Array.isArray(value) ? value : [value];
|
|
32
33
|
|
|
33
34
|
const handleBlur = useCallback(
|
|
34
35
|
({ target }: FocusEvent<HTMLInputElement>) =>
|
|
35
36
|
onBlur(id, enumOptionsValueForIndex<S>(target && target.value, enumOptions, emptyValue)),
|
|
36
|
-
[onBlur, id],
|
|
37
|
+
[onBlur, id, enumOptions, emptyValue],
|
|
37
38
|
);
|
|
38
39
|
|
|
39
40
|
const handleFocus = useCallback(
|
|
40
41
|
({ target }: FocusEvent<HTMLInputElement>) =>
|
|
41
42
|
onFocus(id, enumOptionsValueForIndex<S>(target && target.value, enumOptions, emptyValue)),
|
|
42
|
-
[onFocus, id],
|
|
43
|
+
[onFocus, id, enumOptions, emptyValue],
|
|
43
44
|
);
|
|
44
45
|
return (
|
|
45
46
|
<div className='checkboxes' id={id}>
|
|
@@ -62,7 +63,7 @@ function CheckboxesWidget<T = any, S extends StrictRJSFSchema = RJSFSchema, F ex
|
|
|
62
63
|
<input
|
|
63
64
|
type='checkbox'
|
|
64
65
|
id={optionId(id, index)}
|
|
65
|
-
name={id}
|
|
66
|
+
name={htmlName || id}
|
|
66
67
|
checked={checked}
|
|
67
68
|
value={String(index)}
|
|
68
69
|
disabled={disabled || itemDisabled || readonly}
|
|
@@ -70,7 +71,7 @@ function CheckboxesWidget<T = any, S extends StrictRJSFSchema = RJSFSchema, F ex
|
|
|
70
71
|
onChange={handleChange}
|
|
71
72
|
onBlur={handleBlur}
|
|
72
73
|
onFocus={handleFocus}
|
|
73
|
-
aria-describedby={ariaDescribedByIds
|
|
74
|
+
aria-describedby={ariaDescribedByIds(id)}
|
|
74
75
|
/>
|
|
75
76
|
<span>{option.label}</span>
|
|
76
77
|
</span>
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { ChangeEvent
|
|
1
|
+
import { ChangeEvent } from 'react';
|
|
2
2
|
import {
|
|
3
|
-
|
|
3
|
+
FileInfoType,
|
|
4
4
|
FormContextType,
|
|
5
5
|
getTemplate,
|
|
6
6
|
Registry,
|
|
@@ -8,54 +8,11 @@ import {
|
|
|
8
8
|
StrictRJSFSchema,
|
|
9
9
|
TranslatableString,
|
|
10
10
|
UIOptionsType,
|
|
11
|
+
useFileWidgetProps,
|
|
11
12
|
WidgetProps,
|
|
12
13
|
} from '@rjsf/utils';
|
|
13
14
|
import Markdown from 'markdown-to-jsx';
|
|
14
15
|
|
|
15
|
-
function addNameToDataURL(dataURL: string, name: string) {
|
|
16
|
-
if (dataURL === null) {
|
|
17
|
-
return null;
|
|
18
|
-
}
|
|
19
|
-
return dataURL.replace(';base64', `;name=${encodeURIComponent(name)};base64`);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
type FileInfoType = {
|
|
23
|
-
dataURL?: string | null;
|
|
24
|
-
name: string;
|
|
25
|
-
size: number;
|
|
26
|
-
type: string;
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
function processFile(file: File): Promise<FileInfoType> {
|
|
30
|
-
const { name, size, type } = file;
|
|
31
|
-
return new Promise((resolve, reject) => {
|
|
32
|
-
const reader = new window.FileReader();
|
|
33
|
-
reader.onerror = reject;
|
|
34
|
-
reader.onload = (event) => {
|
|
35
|
-
if (typeof event.target?.result === 'string') {
|
|
36
|
-
resolve({
|
|
37
|
-
dataURL: addNameToDataURL(event.target.result, name),
|
|
38
|
-
name,
|
|
39
|
-
size,
|
|
40
|
-
type,
|
|
41
|
-
});
|
|
42
|
-
} else {
|
|
43
|
-
resolve({
|
|
44
|
-
dataURL: null,
|
|
45
|
-
name,
|
|
46
|
-
size,
|
|
47
|
-
type,
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
reader.readAsDataURL(file);
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
function processFiles(files: FileList) {
|
|
56
|
-
return Promise.all(Array.from(files).map(processFile));
|
|
57
|
-
}
|
|
58
|
-
|
|
59
16
|
function FileInfoPreview<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>({
|
|
60
17
|
fileInfo,
|
|
61
18
|
registry,
|
|
@@ -125,29 +82,6 @@ function FilesInfo<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends F
|
|
|
125
82
|
);
|
|
126
83
|
}
|
|
127
84
|
|
|
128
|
-
function extractFileInfo(dataURLs: string[]): FileInfoType[] {
|
|
129
|
-
return dataURLs.reduce((acc, dataURL) => {
|
|
130
|
-
if (!dataURL) {
|
|
131
|
-
return acc;
|
|
132
|
-
}
|
|
133
|
-
try {
|
|
134
|
-
const { blob, name } = dataURItoBlob(dataURL);
|
|
135
|
-
return [
|
|
136
|
-
...acc,
|
|
137
|
-
{
|
|
138
|
-
dataURL,
|
|
139
|
-
name: name,
|
|
140
|
-
size: blob.size,
|
|
141
|
-
type: blob.type,
|
|
142
|
-
},
|
|
143
|
-
];
|
|
144
|
-
} catch {
|
|
145
|
-
// Invalid dataURI, so just ignore it.
|
|
146
|
-
return acc;
|
|
147
|
-
}
|
|
148
|
-
}, [] as FileInfoType[]);
|
|
149
|
-
}
|
|
150
|
-
|
|
151
85
|
/**
|
|
152
86
|
* The `FileWidget` is a widget for rendering file upload fields.
|
|
153
87
|
* It is typically used with a string property with data-url format.
|
|
@@ -156,40 +90,15 @@ function FileWidget<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends
|
|
|
156
90
|
props: WidgetProps<T, S, F>,
|
|
157
91
|
) {
|
|
158
92
|
const { disabled, readonly, required, multiple, onChange, value, options, registry } = props;
|
|
93
|
+
const { filesInfo, handleChange, handleRemove } = useFileWidgetProps(value, onChange, multiple);
|
|
159
94
|
const BaseInputTemplate = getTemplate<'BaseInputTemplate', T, S, F>('BaseInputTemplate', registry, options);
|
|
160
95
|
|
|
161
|
-
const
|
|
162
|
-
(event
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
// Due to variances in themes, dealing with multiple files for the array case now happens one file at a time.
|
|
167
|
-
// This is because we don't pass `multiple` into the `BaseInputTemplate` anymore. Instead, we deal with the single
|
|
168
|
-
// file in each event and concatenate them together ourselves
|
|
169
|
-
processFiles(event.target.files).then((filesInfoEvent) => {
|
|
170
|
-
const newValue = filesInfoEvent.map((fileInfo) => fileInfo.dataURL);
|
|
171
|
-
if (multiple) {
|
|
172
|
-
onChange(value.concat(newValue));
|
|
173
|
-
} else {
|
|
174
|
-
onChange(newValue[0]);
|
|
175
|
-
}
|
|
176
|
-
});
|
|
177
|
-
},
|
|
178
|
-
[multiple, value, onChange],
|
|
179
|
-
);
|
|
96
|
+
const handleOnChangeEvent = (event: ChangeEvent<HTMLInputElement>) => {
|
|
97
|
+
if (event.target.files) {
|
|
98
|
+
handleChange(event.target.files);
|
|
99
|
+
}
|
|
100
|
+
};
|
|
180
101
|
|
|
181
|
-
const filesInfo = useMemo(() => extractFileInfo(Array.isArray(value) ? value : [value]), [value]);
|
|
182
|
-
const rmFile = useCallback(
|
|
183
|
-
(index: number) => {
|
|
184
|
-
if (multiple) {
|
|
185
|
-
const newValue = value.filter((_: any, i: number) => i !== index);
|
|
186
|
-
onChange(newValue);
|
|
187
|
-
} else {
|
|
188
|
-
onChange(undefined);
|
|
189
|
-
}
|
|
190
|
-
},
|
|
191
|
-
[multiple, value, onChange],
|
|
192
|
-
);
|
|
193
102
|
return (
|
|
194
103
|
<div>
|
|
195
104
|
<BaseInputTemplate
|
|
@@ -197,13 +106,13 @@ function FileWidget<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends
|
|
|
197
106
|
disabled={disabled || readonly}
|
|
198
107
|
type='file'
|
|
199
108
|
required={value ? false : required} // this turns off HTML required validation when a value exists
|
|
200
|
-
onChangeOverride={
|
|
109
|
+
onChangeOverride={handleOnChangeEvent}
|
|
201
110
|
value=''
|
|
202
111
|
accept={options.accept ? String(options.accept) : undefined}
|
|
203
112
|
/>
|
|
204
113
|
<FilesInfo<T, S, F>
|
|
205
114
|
filesInfo={filesInfo}
|
|
206
|
-
onRemove={
|
|
115
|
+
onRemove={handleRemove}
|
|
207
116
|
registry={registry}
|
|
208
117
|
preview={options.filePreview}
|
|
209
118
|
options={options}
|
|
@@ -8,8 +8,9 @@ import { FormContextType, RJSFSchema, StrictRJSFSchema, WidgetProps } from '@rjs
|
|
|
8
8
|
function HiddenWidget<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>({
|
|
9
9
|
id,
|
|
10
10
|
value,
|
|
11
|
+
htmlName,
|
|
11
12
|
}: WidgetProps<T, S, F>) {
|
|
12
|
-
return <input type='hidden' id={id} name={id} value={typeof value === 'undefined' ? '' : value} />;
|
|
13
|
+
return <input type='hidden' id={id} name={htmlName || id} value={typeof value === 'undefined' ? '' : value} />;
|
|
13
14
|
}
|
|
14
15
|
|
|
15
16
|
export default HiddenWidget;
|
|
@@ -26,6 +26,7 @@ function RadioWidget<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends
|
|
|
26
26
|
onFocus,
|
|
27
27
|
onChange,
|
|
28
28
|
id,
|
|
29
|
+
htmlName,
|
|
29
30
|
}: WidgetProps<T, S, F>) {
|
|
30
31
|
const { enumOptions, enumDisabled, inline, emptyValue } = options;
|
|
31
32
|
|
|
@@ -57,7 +58,7 @@ function RadioWidget<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends
|
|
|
57
58
|
type='radio'
|
|
58
59
|
id={optionId(id, i)}
|
|
59
60
|
checked={checked}
|
|
60
|
-
name={id}
|
|
61
|
+
name={htmlName || id}
|
|
61
62
|
required={required}
|
|
62
63
|
value={String(i)}
|
|
63
64
|
disabled={disabled || itemDisabled || readonly}
|
|
@@ -65,7 +66,7 @@ function RadioWidget<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends
|
|
|
65
66
|
onChange={handleChange}
|
|
66
67
|
onBlur={handleBlur}
|
|
67
68
|
onFocus={handleFocus}
|
|
68
|
-
aria-describedby={ariaDescribedByIds
|
|
69
|
+
aria-describedby={ariaDescribedByIds(id)}
|
|
69
70
|
/>
|
|
70
71
|
<span>{option.label}</span>
|
|
71
72
|
</span>
|
|
@@ -29,6 +29,7 @@ export default function RatingWidget<
|
|
|
29
29
|
onBlur,
|
|
30
30
|
schema,
|
|
31
31
|
options,
|
|
32
|
+
htmlName,
|
|
32
33
|
}: WidgetProps<T, S, F>) {
|
|
33
34
|
const { stars = 5, shape = 'star' } = options;
|
|
34
35
|
|
|
@@ -117,7 +118,7 @@ export default function RatingWidget<
|
|
|
117
118
|
<input
|
|
118
119
|
type='hidden'
|
|
119
120
|
id={id}
|
|
120
|
-
name={id}
|
|
121
|
+
name={htmlName || id}
|
|
121
122
|
value={value || ''}
|
|
122
123
|
required={required}
|
|
123
124
|
disabled={disabled || readonly}
|
|
@@ -38,6 +38,7 @@ function SelectWidget<T = any, S extends StrictRJSFSchema = RJSFSchema, F extend
|
|
|
38
38
|
onBlur,
|
|
39
39
|
onFocus,
|
|
40
40
|
placeholder,
|
|
41
|
+
htmlName,
|
|
41
42
|
}: WidgetProps<T, S, F>) {
|
|
42
43
|
const { enumOptions, enumDisabled, emptyValue: optEmptyVal } = options;
|
|
43
44
|
const emptyValue = multiple ? [] : '';
|
|
@@ -72,7 +73,7 @@ function SelectWidget<T = any, S extends StrictRJSFSchema = RJSFSchema, F extend
|
|
|
72
73
|
return (
|
|
73
74
|
<select
|
|
74
75
|
id={id}
|
|
75
|
-
name={id}
|
|
76
|
+
name={htmlName || id}
|
|
76
77
|
multiple={multiple}
|
|
77
78
|
role='combobox'
|
|
78
79
|
className='form-control'
|
|
@@ -83,7 +84,7 @@ function SelectWidget<T = any, S extends StrictRJSFSchema = RJSFSchema, F extend
|
|
|
83
84
|
onBlur={handleBlur}
|
|
84
85
|
onFocus={handleFocus}
|
|
85
86
|
onChange={handleChange}
|
|
86
|
-
aria-describedby={ariaDescribedByIds
|
|
87
|
+
aria-describedby={ariaDescribedByIds(id)}
|
|
87
88
|
>
|
|
88
89
|
{showPlaceholderOption && <option value=''>{placeholder}</option>}
|
|
89
90
|
{Array.isArray(enumOptions) &&
|
|
@@ -17,6 +17,7 @@ function TextareaWidget<T = any, S extends StrictRJSFSchema = RJSFSchema, F exte
|
|
|
17
17
|
onChange,
|
|
18
18
|
onBlur,
|
|
19
19
|
onFocus,
|
|
20
|
+
htmlName,
|
|
20
21
|
}: WidgetProps<T, S, F>) {
|
|
21
22
|
const handleChange = useCallback(
|
|
22
23
|
({ target: { value } }: ChangeEvent<HTMLTextAreaElement>) => onChange(value === '' ? options.emptyValue : value),
|
|
@@ -36,7 +37,7 @@ function TextareaWidget<T = any, S extends StrictRJSFSchema = RJSFSchema, F exte
|
|
|
36
37
|
return (
|
|
37
38
|
<textarea
|
|
38
39
|
id={id}
|
|
39
|
-
name={id}
|
|
40
|
+
name={htmlName || id}
|
|
40
41
|
className='form-control'
|
|
41
42
|
value={value ? value : ''}
|
|
42
43
|
placeholder={placeholder}
|
|
@@ -48,7 +49,7 @@ function TextareaWidget<T = any, S extends StrictRJSFSchema = RJSFSchema, F exte
|
|
|
48
49
|
onBlur={handleBlur}
|
|
49
50
|
onFocus={handleFocus}
|
|
50
51
|
onChange={handleChange}
|
|
51
|
-
aria-describedby={ariaDescribedByIds
|
|
52
|
+
aria-describedby={ariaDescribedByIds(id)}
|
|
52
53
|
/>
|
|
53
54
|
);
|
|
54
55
|
}
|
|
@@ -1,4 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
DEFAULT_ID_PREFIX,
|
|
3
|
+
DEFAULT_ID_SEPARATOR,
|
|
4
|
+
englishStringTranslator,
|
|
5
|
+
FormContextType,
|
|
6
|
+
Registry,
|
|
7
|
+
RJSFSchema,
|
|
8
|
+
StrictRJSFSchema,
|
|
9
|
+
} from '@rjsf/utils';
|
|
2
10
|
|
|
3
11
|
import fields from './components/fields';
|
|
4
12
|
import templates from './components/templates';
|
|
@@ -20,5 +28,10 @@ export default function getDefaultRegistry<
|
|
|
20
28
|
rootSchema: {} as S,
|
|
21
29
|
formContext: {} as F,
|
|
22
30
|
translateString: englishStringTranslator,
|
|
31
|
+
globalFormOptions: {
|
|
32
|
+
idPrefix: DEFAULT_ID_PREFIX,
|
|
33
|
+
idSeparator: DEFAULT_ID_SEPARATOR,
|
|
34
|
+
useFallbackUiForUnsupportedType: false,
|
|
35
|
+
},
|
|
23
36
|
};
|
|
24
37
|
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DEFAULT_ID_PREFIX,
|
|
3
|
+
DEFAULT_ID_SEPARATOR,
|
|
4
|
+
createSchemaUtils,
|
|
5
|
+
englishStringTranslator,
|
|
6
|
+
Registry,
|
|
7
|
+
} from '@rjsf/utils';
|
|
8
|
+
import validator from '@rjsf/validator-ajv8';
|
|
9
|
+
|
|
10
|
+
import getDefaultRegistry from './getDefaultRegistry';
|
|
11
|
+
|
|
12
|
+
/** Use for react testing library tests where we directly test the component rather than testing inside a Form
|
|
13
|
+
*/
|
|
14
|
+
export default function getTestRegistry(
|
|
15
|
+
rootSchema: Registry['rootSchema'],
|
|
16
|
+
fields: Registry['fields'] = {},
|
|
17
|
+
templates: Partial<Registry['templates']> = {},
|
|
18
|
+
widgets: Registry['widgets'] = {},
|
|
19
|
+
formContext: Registry['formContext'] = {},
|
|
20
|
+
globalFormOptions: Registry['globalFormOptions'] = {
|
|
21
|
+
idPrefix: DEFAULT_ID_PREFIX,
|
|
22
|
+
idSeparator: DEFAULT_ID_SEPARATOR,
|
|
23
|
+
useFallbackUiForUnsupportedType: false,
|
|
24
|
+
},
|
|
25
|
+
): Registry {
|
|
26
|
+
const defaults = getDefaultRegistry();
|
|
27
|
+
const schemaUtils = createSchemaUtils(validator, rootSchema);
|
|
28
|
+
return {
|
|
29
|
+
fields: { ...defaults.fields, ...fields },
|
|
30
|
+
templates: { ...defaults.templates, ...templates },
|
|
31
|
+
widgets: { ...defaults.widgets, ...widgets },
|
|
32
|
+
formContext,
|
|
33
|
+
rootSchema,
|
|
34
|
+
schemaUtils,
|
|
35
|
+
translateString: englishStringTranslator,
|
|
36
|
+
globalFormOptions,
|
|
37
|
+
};
|
|
38
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -2,8 +2,9 @@ import Form, { FormProps, FormState, IChangeEvent } from './components/Form';
|
|
|
2
2
|
import RichDescription, { RichDescriptionProps } from './components/RichDescription';
|
|
3
3
|
import withTheme, { ThemeProps } from './withTheme';
|
|
4
4
|
import getDefaultRegistry from './getDefaultRegistry';
|
|
5
|
+
import getTestRegistry from './getTestRegistry';
|
|
5
6
|
|
|
6
7
|
export type { FormProps, FormState, IChangeEvent, ThemeProps, RichDescriptionProps };
|
|
7
8
|
|
|
8
|
-
export { withTheme, getDefaultRegistry, RichDescription };
|
|
9
|
+
export { withTheme, getDefaultRegistry, getTestRegistry, RichDescription };
|
|
9
10
|
export default Form;
|