@rjsf/core 5.11.2 → 5.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/core.umd.js +3464 -0
- package/dist/index.esm.js +3814 -0
- package/dist/index.esm.js.map +7 -0
- package/dist/index.js +3714 -5
- package/dist/index.js.map +7 -0
- package/{dist/index.d.ts → lib/components/Form.d.ts} +321 -337
- package/lib/components/Form.js +474 -0
- package/lib/components/Form.js.map +1 -0
- package/lib/components/fields/ArrayField.d.ts +179 -0
- package/lib/components/fields/ArrayField.js +568 -0
- package/lib/components/fields/ArrayField.js.map +1 -0
- package/lib/components/fields/BooleanField.d.ts +9 -0
- package/lib/components/fields/BooleanField.js +62 -0
- package/lib/components/fields/BooleanField.js.map +1 -0
- package/lib/components/fields/MultiSchemaField.d.ts +47 -0
- package/lib/components/fields/MultiSchemaField.js +129 -0
- package/lib/components/fields/MultiSchemaField.js.map +1 -0
- package/lib/components/fields/NullField.d.ts +8 -0
- package/lib/components/fields/NullField.js +17 -0
- package/lib/components/fields/NullField.js.map +1 -0
- package/lib/components/fields/NumberField.d.ts +21 -0
- package/lib/components/fields/NumberField.js +70 -0
- package/lib/components/fields/NumberField.js.map +1 -0
- package/lib/components/fields/ObjectField.d.ts +73 -0
- package/lib/components/fields/ObjectField.js +222 -0
- package/lib/components/fields/ObjectField.js.map +1 -0
- package/lib/components/fields/SchemaField.d.ts +10 -0
- package/lib/components/fields/SchemaField.js +172 -0
- package/lib/components/fields/SchemaField.js.map +1 -0
- package/lib/components/fields/StringField.d.ts +8 -0
- package/lib/components/fields/StringField.js +25 -0
- package/lib/components/fields/StringField.js.map +1 -0
- package/lib/components/fields/index.d.ts +3 -0
- package/lib/components/fields/index.js +24 -0
- package/lib/components/fields/index.js.map +1 -0
- package/lib/components/templates/ArrayFieldDescriptionTemplate.d.ts +8 -0
- package/lib/components/templates/ArrayFieldDescriptionTemplate.js +18 -0
- package/lib/components/templates/ArrayFieldDescriptionTemplate.js.map +1 -0
- package/lib/components/templates/ArrayFieldItemTemplate.d.ts +7 -0
- package/lib/components/templates/ArrayFieldItemTemplate.js +20 -0
- package/lib/components/templates/ArrayFieldItemTemplate.js.map +1 -0
- package/lib/components/templates/ArrayFieldTemplate.d.ts +7 -0
- package/lib/components/templates/ArrayFieldTemplate.js +22 -0
- package/lib/components/templates/ArrayFieldTemplate.js.map +1 -0
- package/lib/components/templates/ArrayFieldTitleTemplate.d.ts +8 -0
- package/lib/components/templates/ArrayFieldTitleTemplate.js +18 -0
- package/lib/components/templates/ArrayFieldTitleTemplate.js.map +1 -0
- package/lib/components/templates/BaseInputTemplate.d.ts +9 -0
- package/lib/components/templates/BaseInputTemplate.js +39 -0
- package/lib/components/templates/BaseInputTemplate.js.map +1 -0
- package/lib/components/templates/ButtonTemplates/AddButton.d.ts +5 -0
- package/lib/components/templates/ButtonTemplates/AddButton.js +10 -0
- package/lib/components/templates/ButtonTemplates/AddButton.js.map +1 -0
- package/lib/components/templates/ButtonTemplates/IconButton.d.ts +7 -0
- package/lib/components/templates/ButtonTemplates/IconButton.js +24 -0
- package/lib/components/templates/ButtonTemplates/IconButton.js.map +1 -0
- package/lib/components/templates/ButtonTemplates/SubmitButton.d.ts +5 -0
- package/lib/components/templates/ButtonTemplates/SubmitButton.js +12 -0
- package/lib/components/templates/ButtonTemplates/SubmitButton.js.map +1 -0
- package/lib/components/templates/ButtonTemplates/index.d.ts +3 -0
- package/lib/components/templates/ButtonTemplates/index.js +15 -0
- package/lib/components/templates/ButtonTemplates/index.js.map +1 -0
- package/lib/components/templates/DescriptionField.d.ts +7 -0
- package/lib/components/templates/DescriptionField.js +18 -0
- package/lib/components/templates/DescriptionField.js.map +1 -0
- package/lib/components/templates/ErrorList.d.ts +7 -0
- package/lib/components/templates/ErrorList.js +13 -0
- package/lib/components/templates/ErrorList.js.map +1 -0
- package/lib/components/templates/FieldErrorTemplate.d.ts +7 -0
- package/lib/components/templates/FieldErrorTemplate.js +19 -0
- package/lib/components/templates/FieldErrorTemplate.js.map +1 -0
- package/lib/components/templates/FieldHelpTemplate.d.ts +7 -0
- package/lib/components/templates/FieldHelpTemplate.js +18 -0
- package/lib/components/templates/FieldHelpTemplate.js.map +1 -0
- package/lib/components/templates/FieldTemplate/FieldTemplate.d.ts +8 -0
- package/lib/components/templates/FieldTemplate/FieldTemplate.js +18 -0
- package/lib/components/templates/FieldTemplate/FieldTemplate.js.map +1 -0
- package/lib/components/templates/FieldTemplate/Label.d.ts +14 -0
- package/lib/components/templates/FieldTemplate/Label.js +14 -0
- package/lib/components/templates/FieldTemplate/Label.js.map +1 -0
- package/lib/components/templates/FieldTemplate/index.d.ts +2 -0
- package/lib/components/templates/FieldTemplate/index.js +3 -0
- package/lib/components/templates/FieldTemplate/index.js.map +1 -0
- package/lib/components/templates/ObjectFieldTemplate.d.ts +9 -0
- package/lib/components/templates/ObjectFieldTemplate.js +18 -0
- package/lib/components/templates/ObjectFieldTemplate.js.map +1 -0
- package/lib/components/templates/TitleField.d.ts +7 -0
- package/lib/components/templates/TitleField.js +11 -0
- package/lib/components/templates/TitleField.js.map +1 -0
- package/lib/components/templates/UnsupportedField.d.ts +9 -0
- package/lib/components/templates/UnsupportedField.js +28 -0
- package/lib/components/templates/UnsupportedField.js.map +1 -0
- package/lib/components/templates/WrapIfAdditionalTemplate.d.ts +8 -0
- package/lib/components/templates/WrapIfAdditionalTemplate.js +21 -0
- package/lib/components/templates/WrapIfAdditionalTemplate.js.map +1 -0
- package/lib/components/templates/index.d.ts +3 -0
- package/lib/components/templates/index.js +36 -0
- package/lib/components/templates/index.js.map +1 -0
- package/lib/components/widgets/AltDateTimeWidget.d.ts +9 -0
- package/lib/components/widgets/AltDateTimeWidget.js +14 -0
- package/lib/components/widgets/AltDateTimeWidget.js.map +1 -0
- package/lib/components/widgets/AltDateWidget.d.ts +7 -0
- package/lib/components/widgets/AltDateWidget.js +77 -0
- package/lib/components/widgets/AltDateWidget.js.map +1 -0
- package/lib/components/widgets/CheckboxWidget.d.ts +9 -0
- package/lib/components/widgets/CheckboxWidget.js +23 -0
- package/lib/components/widgets/CheckboxWidget.js.map +1 -0
- package/lib/components/widgets/CheckboxesWidget.d.ts +9 -0
- package/lib/components/widgets/CheckboxesWidget.js +31 -0
- package/lib/components/widgets/CheckboxesWidget.js.map +1 -0
- package/lib/components/widgets/ColorWidget.d.ts +8 -0
- package/lib/components/widgets/ColorWidget.js +13 -0
- package/lib/components/widgets/ColorWidget.js.map +1 -0
- package/lib/components/widgets/DateTimeWidget.d.ts +8 -0
- package/lib/components/widgets/DateTimeWidget.js +13 -0
- package/lib/components/widgets/DateTimeWidget.js.map +1 -0
- package/lib/components/widgets/DateWidget.d.ts +8 -0
- package/lib/components/widgets/DateWidget.js +15 -0
- package/lib/components/widgets/DateWidget.js.map +1 -0
- package/lib/components/widgets/EmailWidget.d.ts +7 -0
- package/lib/components/widgets/EmailWidget.js +12 -0
- package/lib/components/widgets/EmailWidget.js.map +1 -0
- package/lib/components/widgets/FileWidget.d.ts +8 -0
- package/lib/components/widgets/FileWidget.js +105 -0
- package/lib/components/widgets/FileWidget.js.map +1 -0
- package/lib/components/widgets/HiddenWidget.d.ts +9 -0
- package/lib/components/widgets/HiddenWidget.js +11 -0
- package/lib/components/widgets/HiddenWidget.js.map +1 -0
- package/lib/components/widgets/PasswordWidget.d.ts +7 -0
- package/lib/components/widgets/PasswordWidget.js +12 -0
- package/lib/components/widgets/PasswordWidget.js.map +1 -0
- package/lib/components/widgets/RadioWidget.d.ts +9 -0
- package/lib/components/widgets/RadioWidget.js +24 -0
- package/lib/components/widgets/RadioWidget.js.map +1 -0
- package/lib/components/widgets/RangeWidget.d.ts +8 -0
- package/lib/components/widgets/RangeWidget.js +11 -0
- package/lib/components/widgets/RangeWidget.js.map +1 -0
- package/lib/components/widgets/SelectWidget.d.ts +9 -0
- package/lib/components/widgets/SelectWidget.js +41 -0
- package/lib/components/widgets/SelectWidget.js.map +1 -0
- package/lib/components/widgets/TextWidget.d.ts +7 -0
- package/lib/components/widgets/TextWidget.js +12 -0
- package/lib/components/widgets/TextWidget.js.map +1 -0
- package/lib/components/widgets/TextareaWidget.d.ts +14 -0
- package/lib/components/widgets/TextareaWidget.js +19 -0
- package/lib/components/widgets/TextareaWidget.js.map +1 -0
- package/lib/components/widgets/TimeWidget.d.ts +8 -0
- package/lib/components/widgets/TimeWidget.js +15 -0
- package/lib/components/widgets/TimeWidget.js.map +1 -0
- package/lib/components/widgets/URLWidget.d.ts +7 -0
- package/lib/components/widgets/URLWidget.js +12 -0
- package/lib/components/widgets/URLWidget.js.map +1 -0
- package/lib/components/widgets/UpDownWidget.d.ts +7 -0
- package/lib/components/widgets/UpDownWidget.js +12 -0
- package/lib/components/widgets/UpDownWidget.js.map +1 -0
- package/lib/components/widgets/index.d.ts +3 -0
- package/lib/components/widgets/index.js +44 -0
- package/lib/components/widgets/index.js.map +1 -0
- package/lib/getDefaultRegistry.d.ts +6 -0
- package/lib/getDefaultRegistry.js +19 -0
- package/lib/getDefaultRegistry.js.map +1 -0
- package/lib/index.d.ts +6 -0
- package/lib/index.js +6 -0
- package/lib/index.js.map +1 -0
- package/lib/withTheme.d.ts +9 -0
- package/lib/withTheme.js +16 -0
- package/lib/withTheme.js.map +1 -0
- package/package.json +23 -16
- package/src/components/Form.tsx +853 -0
- package/src/components/fields/ArrayField.tsx +875 -0
- package/src/components/fields/BooleanField.tsx +114 -0
- package/src/components/fields/MultiSchemaField.tsx +221 -0
- package/src/components/fields/NullField.tsx +22 -0
- package/src/components/fields/NumberField.tsx +86 -0
- package/src/components/fields/ObjectField.tsx +331 -0
- package/src/components/fields/SchemaField.tsx +360 -0
- package/src/components/fields/StringField.tsx +71 -0
- package/src/components/fields/index.ts +31 -0
- package/src/components/templates/ArrayFieldDescriptionTemplate.tsx +41 -0
- package/src/components/templates/ArrayFieldItemTemplate.tsx +90 -0
- package/src/components/templates/ArrayFieldTemplate.tsx +88 -0
- package/src/components/templates/ArrayFieldTitleTemplate.tsx +43 -0
- package/src/components/templates/BaseInputTemplate.tsx +102 -0
- package/src/components/templates/ButtonTemplates/AddButton.tsx +29 -0
- package/src/components/templates/ButtonTemplates/IconButton.tsx +77 -0
- package/src/components/templates/ButtonTemplates/SubmitButton.tsx +21 -0
- package/src/components/templates/ButtonTemplates/index.ts +22 -0
- package/src/components/templates/DescriptionField.tsx +29 -0
- package/src/components/templates/ErrorList.tsx +35 -0
- package/src/components/templates/FieldErrorTemplate.tsx +33 -0
- package/src/components/templates/FieldHelpTemplate.tsx +29 -0
- package/src/components/templates/FieldTemplate/FieldTemplate.tsx +41 -0
- package/src/components/templates/FieldTemplate/Label.tsx +27 -0
- package/src/components/templates/FieldTemplate/index.ts +3 -0
- package/src/components/templates/ObjectFieldTemplate.tsx +83 -0
- package/src/components/templates/TitleField.tsx +19 -0
- package/src/components/templates/UnsupportedField.tsx +37 -0
- package/src/components/templates/WrapIfAdditionalTemplate.tsx +80 -0
- package/src/components/templates/index.ts +43 -0
- package/src/components/widgets/AltDateTimeWidget.tsx +16 -0
- package/src/components/widgets/AltDateWidget.tsx +198 -0
- package/src/components/widgets/CheckboxWidget.tsx +92 -0
- package/src/components/widgets/CheckboxesWidget.tsx +92 -0
- package/src/components/widgets/ColorWidget.tsx +14 -0
- package/src/components/widgets/DateTimeWidget.tsx +31 -0
- package/src/components/widgets/DateWidget.tsx +17 -0
- package/src/components/widgets/EmailWidget.tsx +13 -0
- package/src/components/widgets/FileWidget.tsx +178 -0
- package/src/components/widgets/HiddenWidget.tsx +15 -0
- package/src/components/widgets/PasswordWidget.tsx +15 -0
- package/src/components/widgets/RadioWidget.tsx +88 -0
- package/src/components/widgets/RangeWidget.tsx +23 -0
- package/src/components/widgets/SelectWidget.tsx +100 -0
- package/src/components/widgets/TextWidget.tsx +13 -0
- package/src/components/widgets/TextareaWidget.tsx +61 -0
- package/src/components/widgets/TimeWidget.tsx +17 -0
- package/src/components/widgets/URLWidget.tsx +13 -0
- package/src/components/widgets/UpDownWidget.tsx +13 -0
- package/src/components/widgets/index.ts +51 -0
- package/src/getDefaultRegistry.ts +24 -0
- package/src/index.ts +8 -0
- package/src/withTheme.tsx +42 -0
- package/dist/core.cjs.development.js +0 -4403
- package/dist/core.cjs.development.js.map +0 -1
- package/dist/core.cjs.production.min.js +0 -2
- package/dist/core.cjs.production.min.js.map +0 -1
- package/dist/core.esm.js +0 -4383
- package/dist/core.esm.js.map +0 -1
- package/dist/core.umd.development.js +0 -4393
- package/dist/core.umd.development.js.map +0 -1
- package/dist/core.umd.production.min.js +0 -2
- package/dist/core.umd.production.min.js.map +0 -1
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { errorId, FieldErrorProps, FormContextType, RJSFSchema, StrictRJSFSchema } from '@rjsf/utils';
|
|
2
|
+
|
|
3
|
+
/** The `FieldErrorTemplate` component renders the errors local to the particular field
|
|
4
|
+
*
|
|
5
|
+
* @param props - The `FieldErrorProps` for the errors being rendered
|
|
6
|
+
*/
|
|
7
|
+
export default function FieldErrorTemplate<
|
|
8
|
+
T = any,
|
|
9
|
+
S extends StrictRJSFSchema = RJSFSchema,
|
|
10
|
+
F extends FormContextType = any
|
|
11
|
+
>(props: FieldErrorProps<T, S, F>) {
|
|
12
|
+
const { errors = [], idSchema } = props;
|
|
13
|
+
if (errors.length === 0) {
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
const id = errorId<T>(idSchema);
|
|
17
|
+
|
|
18
|
+
return (
|
|
19
|
+
<div>
|
|
20
|
+
<ul id={id} className='error-detail bs-callout bs-callout-info'>
|
|
21
|
+
{errors
|
|
22
|
+
.filter((elem) => !!elem)
|
|
23
|
+
.map((error, index: number) => {
|
|
24
|
+
return (
|
|
25
|
+
<li className='text-danger' key={index}>
|
|
26
|
+
{error}
|
|
27
|
+
</li>
|
|
28
|
+
);
|
|
29
|
+
})}
|
|
30
|
+
</ul>
|
|
31
|
+
</div>
|
|
32
|
+
);
|
|
33
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { helpId, FieldHelpProps, FormContextType, RJSFSchema, StrictRJSFSchema } from '@rjsf/utils';
|
|
2
|
+
|
|
3
|
+
/** The `FieldHelpTemplate` component renders any help desired for a field
|
|
4
|
+
*
|
|
5
|
+
* @param props - The `FieldHelpProps` to be rendered
|
|
6
|
+
*/
|
|
7
|
+
export default function FieldHelpTemplate<
|
|
8
|
+
T = any,
|
|
9
|
+
S extends StrictRJSFSchema = RJSFSchema,
|
|
10
|
+
F extends FormContextType = any
|
|
11
|
+
>(props: FieldHelpProps<T, S, F>) {
|
|
12
|
+
const { idSchema, help } = props;
|
|
13
|
+
if (!help) {
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
const id = helpId<T>(idSchema);
|
|
17
|
+
if (typeof help === 'string') {
|
|
18
|
+
return (
|
|
19
|
+
<p id={id} className='help-block'>
|
|
20
|
+
{help}
|
|
21
|
+
</p>
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
return (
|
|
25
|
+
<div id={id} className='help-block'>
|
|
26
|
+
{help}
|
|
27
|
+
</div>
|
|
28
|
+
);
|
|
29
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import {
|
|
2
|
+
FieldTemplateProps,
|
|
3
|
+
FormContextType,
|
|
4
|
+
RJSFSchema,
|
|
5
|
+
StrictRJSFSchema,
|
|
6
|
+
getTemplate,
|
|
7
|
+
getUiOptions,
|
|
8
|
+
} from '@rjsf/utils';
|
|
9
|
+
|
|
10
|
+
import Label from './Label';
|
|
11
|
+
|
|
12
|
+
/** The `FieldTemplate` component is the template used by `SchemaField` to render any field. It renders the field
|
|
13
|
+
* content, (label, description, children, errors and help) inside of a `WrapIfAdditional` component.
|
|
14
|
+
*
|
|
15
|
+
* @param props - The `FieldTemplateProps` for this component
|
|
16
|
+
*/
|
|
17
|
+
export default function FieldTemplate<
|
|
18
|
+
T = any,
|
|
19
|
+
S extends StrictRJSFSchema = RJSFSchema,
|
|
20
|
+
F extends FormContextType = any
|
|
21
|
+
>(props: FieldTemplateProps<T, S, F>) {
|
|
22
|
+
const { id, label, children, errors, help, description, hidden, required, displayLabel, registry, uiSchema } = props;
|
|
23
|
+
const uiOptions = getUiOptions(uiSchema);
|
|
24
|
+
const WrapIfAdditionalTemplate = getTemplate<'WrapIfAdditionalTemplate', T, S, F>(
|
|
25
|
+
'WrapIfAdditionalTemplate',
|
|
26
|
+
registry,
|
|
27
|
+
uiOptions
|
|
28
|
+
);
|
|
29
|
+
if (hidden) {
|
|
30
|
+
return <div className='hidden'>{children}</div>;
|
|
31
|
+
}
|
|
32
|
+
return (
|
|
33
|
+
<WrapIfAdditionalTemplate {...props}>
|
|
34
|
+
{displayLabel && <Label label={label} required={required} id={id} />}
|
|
35
|
+
{displayLabel && description ? description : null}
|
|
36
|
+
{children}
|
|
37
|
+
{errors}
|
|
38
|
+
{help}
|
|
39
|
+
</WrapIfAdditionalTemplate>
|
|
40
|
+
);
|
|
41
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
const REQUIRED_FIELD_SYMBOL = '*';
|
|
2
|
+
|
|
3
|
+
export type LabelProps = {
|
|
4
|
+
/** The label for the field */
|
|
5
|
+
label?: string;
|
|
6
|
+
/** A boolean value stating if the field is required */
|
|
7
|
+
required?: boolean;
|
|
8
|
+
/** The id of the input field being labeled */
|
|
9
|
+
id?: string;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
/** Renders a label for a field
|
|
13
|
+
*
|
|
14
|
+
* @param props - The `LabelProps` for this component
|
|
15
|
+
*/
|
|
16
|
+
export default function Label(props: LabelProps) {
|
|
17
|
+
const { label, required, id } = props;
|
|
18
|
+
if (!label) {
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
return (
|
|
22
|
+
<label className='control-label' htmlFor={id}>
|
|
23
|
+
{label}
|
|
24
|
+
{required && <span className='required'>{REQUIRED_FIELD_SYMBOL}</span>}
|
|
25
|
+
</label>
|
|
26
|
+
);
|
|
27
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import {
|
|
2
|
+
FormContextType,
|
|
3
|
+
ObjectFieldTemplatePropertyType,
|
|
4
|
+
ObjectFieldTemplateProps,
|
|
5
|
+
RJSFSchema,
|
|
6
|
+
StrictRJSFSchema,
|
|
7
|
+
canExpand,
|
|
8
|
+
descriptionId,
|
|
9
|
+
getTemplate,
|
|
10
|
+
getUiOptions,
|
|
11
|
+
titleId,
|
|
12
|
+
} from '@rjsf/utils';
|
|
13
|
+
|
|
14
|
+
/** The `ObjectFieldTemplate` is the template to use to render all the inner properties of an object along with the
|
|
15
|
+
* title and description if available. If the object is expandable, then an `AddButton` is also rendered after all
|
|
16
|
+
* the properties.
|
|
17
|
+
*
|
|
18
|
+
* @param props - The `ObjectFieldTemplateProps` for this component
|
|
19
|
+
*/
|
|
20
|
+
export default function ObjectFieldTemplate<
|
|
21
|
+
T = any,
|
|
22
|
+
S extends StrictRJSFSchema = RJSFSchema,
|
|
23
|
+
F extends FormContextType = any
|
|
24
|
+
>(props: ObjectFieldTemplateProps<T, S, F>) {
|
|
25
|
+
const {
|
|
26
|
+
description,
|
|
27
|
+
disabled,
|
|
28
|
+
formData,
|
|
29
|
+
idSchema,
|
|
30
|
+
onAddClick,
|
|
31
|
+
properties,
|
|
32
|
+
readonly,
|
|
33
|
+
registry,
|
|
34
|
+
required,
|
|
35
|
+
schema,
|
|
36
|
+
title,
|
|
37
|
+
uiSchema,
|
|
38
|
+
} = props;
|
|
39
|
+
const options = getUiOptions<T, S, F>(uiSchema);
|
|
40
|
+
const TitleFieldTemplate = getTemplate<'TitleFieldTemplate', T, S, F>('TitleFieldTemplate', registry, options);
|
|
41
|
+
const DescriptionFieldTemplate = getTemplate<'DescriptionFieldTemplate', T, S, F>(
|
|
42
|
+
'DescriptionFieldTemplate',
|
|
43
|
+
registry,
|
|
44
|
+
options
|
|
45
|
+
);
|
|
46
|
+
// Button templates are not overridden in the uiSchema
|
|
47
|
+
const {
|
|
48
|
+
ButtonTemplates: { AddButton },
|
|
49
|
+
} = registry.templates;
|
|
50
|
+
return (
|
|
51
|
+
<fieldset id={idSchema.$id}>
|
|
52
|
+
{title && (
|
|
53
|
+
<TitleFieldTemplate
|
|
54
|
+
id={titleId<T>(idSchema)}
|
|
55
|
+
title={title}
|
|
56
|
+
required={required}
|
|
57
|
+
schema={schema}
|
|
58
|
+
uiSchema={uiSchema}
|
|
59
|
+
registry={registry}
|
|
60
|
+
/>
|
|
61
|
+
)}
|
|
62
|
+
{description && (
|
|
63
|
+
<DescriptionFieldTemplate
|
|
64
|
+
id={descriptionId<T>(idSchema)}
|
|
65
|
+
description={description}
|
|
66
|
+
schema={schema}
|
|
67
|
+
uiSchema={uiSchema}
|
|
68
|
+
registry={registry}
|
|
69
|
+
/>
|
|
70
|
+
)}
|
|
71
|
+
{properties.map((prop: ObjectFieldTemplatePropertyType) => prop.content)}
|
|
72
|
+
{canExpand<T, S, F>(schema, uiSchema, formData) && (
|
|
73
|
+
<AddButton
|
|
74
|
+
className='object-property-expand'
|
|
75
|
+
onClick={onAddClick(schema)}
|
|
76
|
+
disabled={disabled || readonly}
|
|
77
|
+
uiSchema={uiSchema}
|
|
78
|
+
registry={registry}
|
|
79
|
+
/>
|
|
80
|
+
)}
|
|
81
|
+
</fieldset>
|
|
82
|
+
);
|
|
83
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { FormContextType, TitleFieldProps, RJSFSchema, StrictRJSFSchema } from '@rjsf/utils';
|
|
2
|
+
|
|
3
|
+
const REQUIRED_FIELD_SYMBOL = '*';
|
|
4
|
+
|
|
5
|
+
/** The `TitleField` is the template to use to render the title of a field
|
|
6
|
+
*
|
|
7
|
+
* @param props - The `TitleFieldProps` for this component
|
|
8
|
+
*/
|
|
9
|
+
export default function TitleField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(
|
|
10
|
+
props: TitleFieldProps<T, S, F>
|
|
11
|
+
) {
|
|
12
|
+
const { id, title, required } = props;
|
|
13
|
+
return (
|
|
14
|
+
<legend id={id}>
|
|
15
|
+
{title}
|
|
16
|
+
{required && <span className='required'>{REQUIRED_FIELD_SYMBOL}</span>}
|
|
17
|
+
</legend>
|
|
18
|
+
);
|
|
19
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { FormContextType, RJSFSchema, StrictRJSFSchema, TranslatableString, UnsupportedFieldProps } from '@rjsf/utils';
|
|
2
|
+
import Markdown from 'markdown-to-jsx';
|
|
3
|
+
|
|
4
|
+
/** The `UnsupportedField` component is used to render a field in the schema is one that is not supported by
|
|
5
|
+
* react-jsonschema-form.
|
|
6
|
+
*
|
|
7
|
+
* @param props - The `FieldProps` for this template
|
|
8
|
+
*/
|
|
9
|
+
function UnsupportedField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(
|
|
10
|
+
props: UnsupportedFieldProps<T, S, F>
|
|
11
|
+
) {
|
|
12
|
+
const { schema, idSchema, reason, registry } = props;
|
|
13
|
+
const { translateString } = registry;
|
|
14
|
+
let translateEnum: TranslatableString = TranslatableString.UnsupportedField;
|
|
15
|
+
const translateParams: string[] = [];
|
|
16
|
+
if (idSchema && idSchema.$id) {
|
|
17
|
+
translateEnum = TranslatableString.UnsupportedFieldWithId;
|
|
18
|
+
translateParams.push(idSchema.$id);
|
|
19
|
+
}
|
|
20
|
+
if (reason) {
|
|
21
|
+
translateEnum =
|
|
22
|
+
translateEnum === TranslatableString.UnsupportedField
|
|
23
|
+
? TranslatableString.UnsupportedFieldWithReason
|
|
24
|
+
: TranslatableString.UnsupportedFieldWithIdAndReason;
|
|
25
|
+
translateParams.push(reason);
|
|
26
|
+
}
|
|
27
|
+
return (
|
|
28
|
+
<div className='unsupported-field'>
|
|
29
|
+
<p>
|
|
30
|
+
<Markdown>{translateString(translateEnum, translateParams)}</Markdown>
|
|
31
|
+
</p>
|
|
32
|
+
{schema && <pre>{JSON.stringify(schema, null, 2)}</pre>}
|
|
33
|
+
</div>
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export default UnsupportedField;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ADDITIONAL_PROPERTY_FLAG,
|
|
3
|
+
FormContextType,
|
|
4
|
+
RJSFSchema,
|
|
5
|
+
StrictRJSFSchema,
|
|
6
|
+
TranslatableString,
|
|
7
|
+
WrapIfAdditionalTemplateProps,
|
|
8
|
+
} from '@rjsf/utils';
|
|
9
|
+
|
|
10
|
+
import Label from './FieldTemplate/Label';
|
|
11
|
+
|
|
12
|
+
/** The `WrapIfAdditional` component is used by the `FieldTemplate` to rename, or remove properties that are
|
|
13
|
+
* part of an `additionalProperties` part of a schema.
|
|
14
|
+
*
|
|
15
|
+
* @param props - The `WrapIfAdditionalProps` for this component
|
|
16
|
+
*/
|
|
17
|
+
export default function WrapIfAdditionalTemplate<
|
|
18
|
+
T = any,
|
|
19
|
+
S extends StrictRJSFSchema = RJSFSchema,
|
|
20
|
+
F extends FormContextType = any
|
|
21
|
+
>(props: WrapIfAdditionalTemplateProps<T, S, F>) {
|
|
22
|
+
const {
|
|
23
|
+
id,
|
|
24
|
+
classNames,
|
|
25
|
+
style,
|
|
26
|
+
disabled,
|
|
27
|
+
label,
|
|
28
|
+
onKeyChange,
|
|
29
|
+
onDropPropertyClick,
|
|
30
|
+
readonly,
|
|
31
|
+
required,
|
|
32
|
+
schema,
|
|
33
|
+
children,
|
|
34
|
+
uiSchema,
|
|
35
|
+
registry,
|
|
36
|
+
} = props;
|
|
37
|
+
const { templates, translateString } = registry;
|
|
38
|
+
// Button templates are not overridden in the uiSchema
|
|
39
|
+
const { RemoveButton } = templates.ButtonTemplates;
|
|
40
|
+
const keyLabel = translateString(TranslatableString.KeyLabel, [label]);
|
|
41
|
+
const additional = ADDITIONAL_PROPERTY_FLAG in schema;
|
|
42
|
+
|
|
43
|
+
if (!additional) {
|
|
44
|
+
return (
|
|
45
|
+
<div className={classNames} style={style}>
|
|
46
|
+
{children}
|
|
47
|
+
</div>
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return (
|
|
52
|
+
<div className={classNames} style={style}>
|
|
53
|
+
<div className='row'>
|
|
54
|
+
<div className='col-xs-5 form-additional'>
|
|
55
|
+
<div className='form-group'>
|
|
56
|
+
<Label label={keyLabel} required={required} id={`${id}-key`} />
|
|
57
|
+
<input
|
|
58
|
+
className='form-control'
|
|
59
|
+
type='text'
|
|
60
|
+
id={`${id}-key`}
|
|
61
|
+
onBlur={(event) => onKeyChange(event.target.value)}
|
|
62
|
+
defaultValue={label}
|
|
63
|
+
/>
|
|
64
|
+
</div>
|
|
65
|
+
</div>
|
|
66
|
+
<div className='form-additional form-group col-xs-5'>{children}</div>
|
|
67
|
+
<div className='col-xs-2'>
|
|
68
|
+
<RemoveButton
|
|
69
|
+
className='array-item-remove btn-block'
|
|
70
|
+
style={{ border: '0' }}
|
|
71
|
+
disabled={disabled || readonly}
|
|
72
|
+
onClick={onDropPropertyClick(label)}
|
|
73
|
+
uiSchema={uiSchema}
|
|
74
|
+
registry={registry}
|
|
75
|
+
/>
|
|
76
|
+
</div>
|
|
77
|
+
</div>
|
|
78
|
+
</div>
|
|
79
|
+
);
|
|
80
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { FormContextType, RJSFSchema, StrictRJSFSchema, TemplatesType } from '@rjsf/utils';
|
|
2
|
+
|
|
3
|
+
import ArrayFieldDescriptionTemplate from './ArrayFieldDescriptionTemplate';
|
|
4
|
+
import ArrayFieldItemTemplate from './ArrayFieldItemTemplate';
|
|
5
|
+
import ArrayFieldTemplate from './ArrayFieldTemplate';
|
|
6
|
+
import ArrayFieldTitleTemplate from './ArrayFieldTitleTemplate';
|
|
7
|
+
import BaseInputTemplate from './BaseInputTemplate';
|
|
8
|
+
import ButtonTemplates from './ButtonTemplates';
|
|
9
|
+
import DescriptionField from './DescriptionField';
|
|
10
|
+
import ErrorList from './ErrorList';
|
|
11
|
+
import FieldTemplate from './FieldTemplate';
|
|
12
|
+
import FieldErrorTemplate from './FieldErrorTemplate';
|
|
13
|
+
import FieldHelpTemplate from './FieldHelpTemplate';
|
|
14
|
+
import ObjectFieldTemplate from './ObjectFieldTemplate';
|
|
15
|
+
import TitleField from './TitleField';
|
|
16
|
+
import UnsupportedField from './UnsupportedField';
|
|
17
|
+
import WrapIfAdditionalTemplate from './WrapIfAdditionalTemplate';
|
|
18
|
+
|
|
19
|
+
function templates<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(): TemplatesType<
|
|
20
|
+
T,
|
|
21
|
+
S,
|
|
22
|
+
F
|
|
23
|
+
> {
|
|
24
|
+
return {
|
|
25
|
+
ArrayFieldDescriptionTemplate,
|
|
26
|
+
ArrayFieldItemTemplate,
|
|
27
|
+
ArrayFieldTemplate,
|
|
28
|
+
ArrayFieldTitleTemplate,
|
|
29
|
+
ButtonTemplates: ButtonTemplates<T, S, F>(),
|
|
30
|
+
BaseInputTemplate,
|
|
31
|
+
DescriptionFieldTemplate: DescriptionField,
|
|
32
|
+
ErrorListTemplate: ErrorList,
|
|
33
|
+
FieldTemplate,
|
|
34
|
+
FieldErrorTemplate,
|
|
35
|
+
FieldHelpTemplate,
|
|
36
|
+
ObjectFieldTemplate,
|
|
37
|
+
TitleFieldTemplate: TitleField,
|
|
38
|
+
UnsupportedFieldTemplate: UnsupportedField,
|
|
39
|
+
WrapIfAdditionalTemplate,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export default templates;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { FormContextType, RJSFSchema, StrictRJSFSchema, WidgetProps } from '@rjsf/utils';
|
|
2
|
+
|
|
3
|
+
/** The `AltDateTimeWidget` is an alternative widget for rendering datetime properties.
|
|
4
|
+
* It uses the AltDateWidget for rendering, with the `time` prop set to true by default.
|
|
5
|
+
*
|
|
6
|
+
* @param props - The `WidgetProps` for this component
|
|
7
|
+
*/
|
|
8
|
+
function AltDateTimeWidget<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>({
|
|
9
|
+
time = true,
|
|
10
|
+
...props
|
|
11
|
+
}: WidgetProps<T, S, F>) {
|
|
12
|
+
const { AltDateWidget } = props.registry.widgets;
|
|
13
|
+
return <AltDateWidget time={time} {...props} />;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export default AltDateTimeWidget;
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import { MouseEvent, useCallback, useEffect, useReducer, useState } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
ariaDescribedByIds,
|
|
4
|
+
parseDateString,
|
|
5
|
+
toDateString,
|
|
6
|
+
pad,
|
|
7
|
+
DateObject,
|
|
8
|
+
FormContextType,
|
|
9
|
+
RJSFSchema,
|
|
10
|
+
StrictRJSFSchema,
|
|
11
|
+
TranslatableString,
|
|
12
|
+
WidgetProps,
|
|
13
|
+
} from '@rjsf/utils';
|
|
14
|
+
|
|
15
|
+
function rangeOptions(start: number, stop: number) {
|
|
16
|
+
const options = [];
|
|
17
|
+
for (let i = start; i <= stop; i++) {
|
|
18
|
+
options.push({ value: i, label: pad(i, 2) });
|
|
19
|
+
}
|
|
20
|
+
return options;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function readyForChange(state: DateObject) {
|
|
24
|
+
return Object.values(state).every((value) => value !== -1);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function dateElementProps(
|
|
28
|
+
state: DateObject,
|
|
29
|
+
time: boolean,
|
|
30
|
+
yearsRange: [number, number] = [1900, new Date().getFullYear() + 2]
|
|
31
|
+
) {
|
|
32
|
+
const { year, month, day, hour, minute, second } = state;
|
|
33
|
+
const data = [
|
|
34
|
+
{
|
|
35
|
+
type: 'year',
|
|
36
|
+
range: yearsRange,
|
|
37
|
+
value: year,
|
|
38
|
+
},
|
|
39
|
+
{ type: 'month', range: [1, 12], value: month },
|
|
40
|
+
{ type: 'day', range: [1, 31], value: day },
|
|
41
|
+
] as { type: string; range: [number, number]; value: number | undefined }[];
|
|
42
|
+
if (time) {
|
|
43
|
+
data.push(
|
|
44
|
+
{ type: 'hour', range: [0, 23], value: hour },
|
|
45
|
+
{ type: 'minute', range: [0, 59], value: minute },
|
|
46
|
+
{ type: 'second', range: [0, 59], value: second }
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
return data;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
type DateElementProps<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any> = Pick<
|
|
53
|
+
WidgetProps<T, S, F>,
|
|
54
|
+
'value' | 'name' | 'disabled' | 'readonly' | 'autofocus' | 'registry' | 'onBlur' | 'onFocus'
|
|
55
|
+
> & {
|
|
56
|
+
rootId: string;
|
|
57
|
+
select: (property: keyof DateObject, value: any) => void;
|
|
58
|
+
type: string;
|
|
59
|
+
range: [number, number];
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
function DateElement<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>({
|
|
63
|
+
type,
|
|
64
|
+
range,
|
|
65
|
+
value,
|
|
66
|
+
select,
|
|
67
|
+
rootId,
|
|
68
|
+
name,
|
|
69
|
+
disabled,
|
|
70
|
+
readonly,
|
|
71
|
+
autofocus,
|
|
72
|
+
registry,
|
|
73
|
+
onBlur,
|
|
74
|
+
onFocus,
|
|
75
|
+
}: DateElementProps<T, S, F>) {
|
|
76
|
+
const id = rootId + '_' + type;
|
|
77
|
+
const { SelectWidget } = registry.widgets;
|
|
78
|
+
return (
|
|
79
|
+
<SelectWidget
|
|
80
|
+
schema={{ type: 'integer' } as S}
|
|
81
|
+
id={id}
|
|
82
|
+
name={name}
|
|
83
|
+
className='form-control'
|
|
84
|
+
options={{ enumOptions: rangeOptions(range[0], range[1]) }}
|
|
85
|
+
placeholder={type}
|
|
86
|
+
value={value}
|
|
87
|
+
disabled={disabled}
|
|
88
|
+
readonly={readonly}
|
|
89
|
+
autofocus={autofocus}
|
|
90
|
+
onChange={(value: any) => select(type as keyof DateObject, value)}
|
|
91
|
+
onBlur={onBlur}
|
|
92
|
+
onFocus={onFocus}
|
|
93
|
+
registry={registry}
|
|
94
|
+
label=''
|
|
95
|
+
aria-describedby={ariaDescribedByIds<T>(rootId)}
|
|
96
|
+
/>
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** The `AltDateWidget` is an alternative widget for rendering date properties.
|
|
101
|
+
* @param props - The `WidgetProps` for this component
|
|
102
|
+
*/
|
|
103
|
+
function AltDateWidget<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>({
|
|
104
|
+
time = false,
|
|
105
|
+
disabled = false,
|
|
106
|
+
readonly = false,
|
|
107
|
+
autofocus = false,
|
|
108
|
+
options,
|
|
109
|
+
id,
|
|
110
|
+
name,
|
|
111
|
+
registry,
|
|
112
|
+
onBlur,
|
|
113
|
+
onFocus,
|
|
114
|
+
onChange,
|
|
115
|
+
value,
|
|
116
|
+
}: WidgetProps<T, S, F>) {
|
|
117
|
+
const { translateString } = registry;
|
|
118
|
+
const [lastValue, setLastValue] = useState(value);
|
|
119
|
+
const [state, setState] = useReducer((state: DateObject, action: Partial<DateObject>) => {
|
|
120
|
+
return { ...state, ...action };
|
|
121
|
+
}, parseDateString(value, time));
|
|
122
|
+
|
|
123
|
+
useEffect(() => {
|
|
124
|
+
const stateValue = toDateString(state, time);
|
|
125
|
+
if (readyForChange(state) && stateValue !== value) {
|
|
126
|
+
// The user changed the date to a new valid data via the comboboxes, so call onChange
|
|
127
|
+
onChange(stateValue);
|
|
128
|
+
} else if (lastValue !== value) {
|
|
129
|
+
// We got a new value in the props
|
|
130
|
+
setLastValue(value);
|
|
131
|
+
setState(parseDateString(value, time));
|
|
132
|
+
}
|
|
133
|
+
}, [time, value, onChange, state, lastValue]);
|
|
134
|
+
|
|
135
|
+
const handleChange = useCallback((property: keyof DateObject, value: string) => {
|
|
136
|
+
setState({ [property]: value });
|
|
137
|
+
}, []);
|
|
138
|
+
|
|
139
|
+
const handleSetNow = useCallback(
|
|
140
|
+
(event: MouseEvent<HTMLAnchorElement>) => {
|
|
141
|
+
event.preventDefault();
|
|
142
|
+
if (disabled || readonly) {
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
const nextState = parseDateString(new Date().toJSON(), time);
|
|
146
|
+
onChange(toDateString(nextState, time));
|
|
147
|
+
},
|
|
148
|
+
[disabled, readonly, time]
|
|
149
|
+
);
|
|
150
|
+
|
|
151
|
+
const handleClear = useCallback(
|
|
152
|
+
(event: MouseEvent<HTMLAnchorElement>) => {
|
|
153
|
+
event.preventDefault();
|
|
154
|
+
if (disabled || readonly) {
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
onChange(undefined);
|
|
158
|
+
},
|
|
159
|
+
[disabled, readonly, onChange]
|
|
160
|
+
);
|
|
161
|
+
|
|
162
|
+
return (
|
|
163
|
+
<ul className='list-inline'>
|
|
164
|
+
{dateElementProps(state, time, options.yearsRange as [number, number] | undefined).map((elemProps, i) => (
|
|
165
|
+
<li className='list-inline-item' key={i}>
|
|
166
|
+
<DateElement
|
|
167
|
+
rootId={id}
|
|
168
|
+
name={name}
|
|
169
|
+
select={handleChange}
|
|
170
|
+
{...elemProps}
|
|
171
|
+
disabled={disabled}
|
|
172
|
+
readonly={readonly}
|
|
173
|
+
registry={registry}
|
|
174
|
+
onBlur={onBlur}
|
|
175
|
+
onFocus={onFocus}
|
|
176
|
+
autofocus={autofocus && i === 0}
|
|
177
|
+
/>
|
|
178
|
+
</li>
|
|
179
|
+
))}
|
|
180
|
+
{(options.hideNowButton !== 'undefined' ? !options.hideNowButton : true) && (
|
|
181
|
+
<li className='list-inline-item'>
|
|
182
|
+
<a href='#' className='btn btn-info btn-now' onClick={handleSetNow}>
|
|
183
|
+
{translateString(TranslatableString.NowLabel)}
|
|
184
|
+
</a>
|
|
185
|
+
</li>
|
|
186
|
+
)}
|
|
187
|
+
{(options.hideClearButton !== 'undefined' ? !options.hideClearButton : true) && (
|
|
188
|
+
<li className='list-inline-item'>
|
|
189
|
+
<a href='#' className='btn btn-warning btn-clear' onClick={handleClear}>
|
|
190
|
+
{translateString(TranslatableString.ClearLabel)}
|
|
191
|
+
</a>
|
|
192
|
+
</li>
|
|
193
|
+
)}
|
|
194
|
+
</ul>
|
|
195
|
+
);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
export default AltDateWidget;
|