@springmicro/forms 0.6.3 → 0.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/.eslintrc.cjs +22 -22
- package/README.md +11 -11
- package/dist/index.d.ts +0 -0
- package/dist/index.js +0 -0
- package/dist/index.umd.cjs +0 -0
- package/package.json +3 -3
- package/src/builder/bottom-drawer.tsx +429 -429
- package/src/builder/form-builder.tsx +256 -256
- package/src/builder/modal.tsx +39 -39
- package/src/builder/nodes/node-base.tsx +94 -94
- package/src/builder/nodes/node-child-helpers.tsx +273 -273
- package/src/builder/nodes/node-parent.tsx +187 -187
- package/src/builder/nodes/node-types/array-node.tsx +134 -134
- package/src/builder/nodes/node-types/date-node.tsx +60 -60
- package/src/builder/nodes/node-types/file-node.tsx +67 -67
- package/src/builder/nodes/node-types/integer-node.tsx +60 -60
- package/src/builder/nodes/node-types/object-node.tsx +67 -67
- package/src/builder/nodes/node-types/text-node.tsx +66 -66
- package/src/fields/ArrayField.tsx +875 -875
- package/src/fields/BooleanField.tsx +110 -110
- package/src/fields/MultiSchemaField.tsx +236 -236
- package/src/fields/NullField.tsx +22 -22
- package/src/fields/NumberField.tsx +87 -87
- package/src/fields/ObjectField.tsx +338 -338
- package/src/fields/SchemaField.tsx +402 -402
- package/src/fields/StringField.tsx +67 -67
- package/src/fields/index.ts +24 -24
- package/src/index.tsx +26 -26
- package/src/interfaces/MessagesProps.interface.ts +5 -5
- package/src/interfaces/Option.interface.ts +4 -4
- package/src/styles/select.styles.ts +28 -28
- package/src/templates/ArrayFieldDescriptionTemplate.tsx +42 -42
- package/src/templates/ArrayFieldItemTemplate.tsx +78 -78
- package/src/templates/ArrayFieldTemplate.tsx +90 -90
- package/src/templates/ArrayFieldTitleTemplate.tsx +44 -44
- package/src/templates/BaseInputTemplate.tsx +94 -94
- package/src/templates/ButtonTemplates/AddButton.tsx +29 -29
- package/src/templates/ButtonTemplates/IconButton.tsx +49 -49
- package/src/templates/ButtonTemplates/SubmitButton.tsx +29 -29
- package/src/templates/ButtonTemplates/index.ts +16 -16
- package/src/templates/DescriptionField.tsx +29 -29
- package/src/templates/ErrorList.tsx +25 -25
- package/src/templates/FieldTemplate/FieldTemplate.tsx +39 -39
- package/src/templates/FieldTemplate/Label.tsx +29 -29
- package/src/templates/FieldTemplate/WrapIfAdditional.tsx +85 -85
- package/src/templates/FieldTemplate/index.ts +3 -3
- package/src/templates/ObjectFieldTemplate.tsx +79 -79
- package/src/templates/TitleField.tsx +20 -20
- package/src/templates/UnsupportedField.tsx +29 -29
- package/src/templates/index.ts +32 -32
- package/src/types/Message.type.ts +6 -6
- package/src/types/RawMessage.type.ts +15 -15
- package/src/types/form-builder.ts +135 -135
- package/src/types/utils.type.ts +1 -1
- package/src/utils/form-builder.ts +424 -424
- package/src/utils/processSelectValue.ts +50 -50
- package/src/widgets/AltDateTimeWidget.tsx +17 -17
- package/src/widgets/AltDateWidget.tsx +216 -216
- package/src/widgets/CheckboxWidget.tsx +80 -80
- package/src/widgets/CheckboxesWidget.tsx +74 -74
- package/src/widgets/ColorWidget.tsx +26 -26
- package/src/widgets/DateTimeWidget.tsx +28 -28
- package/src/widgets/DateWidget.tsx +36 -36
- package/src/widgets/EmailWidget.tsx +19 -19
- package/src/widgets/FileWidget.tsx +144 -144
- package/src/widgets/HiddenWidget.tsx +22 -22
- package/src/widgets/PasswordWidget.tsx +20 -20
- package/src/widgets/RadioWidget.tsx +87 -87
- package/src/widgets/RangeWidget.tsx +24 -24
- package/src/widgets/SelectWidget.tsx +99 -99
- package/src/widgets/TextWidget.tsx +19 -19
- package/src/widgets/TextareaWidget.tsx +64 -64
- package/src/widgets/URLWidget.tsx +19 -19
- package/src/widgets/UpDownWidget.tsx +20 -20
- package/src/widgets/index.ts +43 -43
- package/tsconfig.json +24 -24
- package/tsconfig.node.json +10 -10
- package/vite.config.ts +25 -25
|
@@ -1,110 +1,110 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import type {
|
|
3
|
-
FieldProps,
|
|
4
|
-
EnumOptionsType,
|
|
5
|
-
RJSFSchema,
|
|
6
|
-
GenericObjectType,
|
|
7
|
-
} from "@rjsf/utils";
|
|
8
|
-
import { getWidget, getUiOptions, optionsList } from "@rjsf/utils";
|
|
9
|
-
import isObject from "lodash/isObject";
|
|
10
|
-
|
|
11
|
-
/** The `BooleanField` component is used to render a field in the schema is boolean. It constructs `enumOptions` for the
|
|
12
|
-
* two boolean values based on the various alternatives in the schema.
|
|
13
|
-
*
|
|
14
|
-
* @param props - The `FieldProps` for this template
|
|
15
|
-
*/
|
|
16
|
-
function BooleanField<T = any, F extends GenericObjectType = any>(
|
|
17
|
-
props: FieldProps<T, F>
|
|
18
|
-
) {
|
|
19
|
-
const {
|
|
20
|
-
schema,
|
|
21
|
-
name,
|
|
22
|
-
uiSchema,
|
|
23
|
-
idSchema,
|
|
24
|
-
formData,
|
|
25
|
-
registry,
|
|
26
|
-
required,
|
|
27
|
-
disabled,
|
|
28
|
-
readonly,
|
|
29
|
-
autofocus,
|
|
30
|
-
onChange,
|
|
31
|
-
onFocus,
|
|
32
|
-
onBlur,
|
|
33
|
-
rawErrors,
|
|
34
|
-
} = props;
|
|
35
|
-
const { title } = schema;
|
|
36
|
-
const { widgets, formContext } = registry;
|
|
37
|
-
const { widget = "checkbox", ...options } = getUiOptions<T, F>(uiSchema);
|
|
38
|
-
const Widget = getWidget(schema, widget, widgets);
|
|
39
|
-
|
|
40
|
-
let enumOptions: EnumOptionsType<any>[] | undefined;
|
|
41
|
-
|
|
42
|
-
if (Array.isArray(schema.oneOf)) {
|
|
43
|
-
enumOptions = optionsList({
|
|
44
|
-
oneOf: schema.oneOf
|
|
45
|
-
.map((option) => {
|
|
46
|
-
if (isObject(option)) {
|
|
47
|
-
return {
|
|
48
|
-
...option,
|
|
49
|
-
// @ts-ignore
|
|
50
|
-
title: option.title || (option.const === true ? "Yes" : "No"),
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
return undefined;
|
|
54
|
-
})
|
|
55
|
-
.filter((o) => o) as any[], // cast away the error that typescript can't grok is fixed
|
|
56
|
-
}) as EnumOptionsType<any>[] | undefined;
|
|
57
|
-
} else {
|
|
58
|
-
// We deprecated enumNames in v5. It's intentionally omitted from RSJFSchema type, so we need to cast here.
|
|
59
|
-
const schemaWithEnumNames = schema as RJSFSchema & { enumNames?: string[] };
|
|
60
|
-
// @ts-ignore
|
|
61
|
-
schema.enum = schema.enum ?? [true, false];
|
|
62
|
-
if (
|
|
63
|
-
!schemaWithEnumNames.enumNames &&
|
|
64
|
-
schema.enum &&
|
|
65
|
-
schema.enum.length === 2 &&
|
|
66
|
-
schema.enum.every((v: any) => typeof v === "boolean")
|
|
67
|
-
) {
|
|
68
|
-
enumOptions = [
|
|
69
|
-
{
|
|
70
|
-
value: schema.enum[0],
|
|
71
|
-
label: schema.enum[0] ? "Yes" : "No",
|
|
72
|
-
},
|
|
73
|
-
{
|
|
74
|
-
value: schema.enum[1],
|
|
75
|
-
label: schema.enum[1] ? "Yes" : "No",
|
|
76
|
-
},
|
|
77
|
-
];
|
|
78
|
-
} else {
|
|
79
|
-
enumOptions = optionsList({
|
|
80
|
-
enum: schema.enum,
|
|
81
|
-
// NOTE: enumNames is deprecated, but still supported for now.
|
|
82
|
-
enumNames: schemaWithEnumNames.enumNames,
|
|
83
|
-
}) as EnumOptionsType<any>[] | undefined;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
return (
|
|
88
|
-
<Widget
|
|
89
|
-
name={name}
|
|
90
|
-
options={{ ...options, enumOptions }}
|
|
91
|
-
schema={schema}
|
|
92
|
-
uiSchema={uiSchema}
|
|
93
|
-
id={idSchema && idSchema.$id}
|
|
94
|
-
onChange={onChange}
|
|
95
|
-
onFocus={onFocus}
|
|
96
|
-
onBlur={onBlur}
|
|
97
|
-
label={title === undefined ? name : title}
|
|
98
|
-
value={formData}
|
|
99
|
-
required={required}
|
|
100
|
-
disabled={disabled}
|
|
101
|
-
readonly={readonly}
|
|
102
|
-
registry={registry}
|
|
103
|
-
formContext={formContext}
|
|
104
|
-
autofocus={autofocus}
|
|
105
|
-
rawErrors={rawErrors}
|
|
106
|
-
/>
|
|
107
|
-
);
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
export default BooleanField;
|
|
1
|
+
import React from "react";
|
|
2
|
+
import type {
|
|
3
|
+
FieldProps,
|
|
4
|
+
EnumOptionsType,
|
|
5
|
+
RJSFSchema,
|
|
6
|
+
GenericObjectType,
|
|
7
|
+
} from "@rjsf/utils";
|
|
8
|
+
import { getWidget, getUiOptions, optionsList } from "@rjsf/utils";
|
|
9
|
+
import isObject from "lodash/isObject";
|
|
10
|
+
|
|
11
|
+
/** The `BooleanField` component is used to render a field in the schema is boolean. It constructs `enumOptions` for the
|
|
12
|
+
* two boolean values based on the various alternatives in the schema.
|
|
13
|
+
*
|
|
14
|
+
* @param props - The `FieldProps` for this template
|
|
15
|
+
*/
|
|
16
|
+
function BooleanField<T = any, F extends GenericObjectType = any>(
|
|
17
|
+
props: FieldProps<T, F>
|
|
18
|
+
) {
|
|
19
|
+
const {
|
|
20
|
+
schema,
|
|
21
|
+
name,
|
|
22
|
+
uiSchema,
|
|
23
|
+
idSchema,
|
|
24
|
+
formData,
|
|
25
|
+
registry,
|
|
26
|
+
required,
|
|
27
|
+
disabled,
|
|
28
|
+
readonly,
|
|
29
|
+
autofocus,
|
|
30
|
+
onChange,
|
|
31
|
+
onFocus,
|
|
32
|
+
onBlur,
|
|
33
|
+
rawErrors,
|
|
34
|
+
} = props;
|
|
35
|
+
const { title } = schema;
|
|
36
|
+
const { widgets, formContext } = registry;
|
|
37
|
+
const { widget = "checkbox", ...options } = getUiOptions<T, F>(uiSchema);
|
|
38
|
+
const Widget = getWidget(schema, widget, widgets);
|
|
39
|
+
|
|
40
|
+
let enumOptions: EnumOptionsType<any>[] | undefined;
|
|
41
|
+
|
|
42
|
+
if (Array.isArray(schema.oneOf)) {
|
|
43
|
+
enumOptions = optionsList({
|
|
44
|
+
oneOf: schema.oneOf
|
|
45
|
+
.map((option) => {
|
|
46
|
+
if (isObject(option)) {
|
|
47
|
+
return {
|
|
48
|
+
...option,
|
|
49
|
+
// @ts-ignore
|
|
50
|
+
title: option.title || (option.const === true ? "Yes" : "No"),
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
return undefined;
|
|
54
|
+
})
|
|
55
|
+
.filter((o) => o) as any[], // cast away the error that typescript can't grok is fixed
|
|
56
|
+
}) as EnumOptionsType<any>[] | undefined;
|
|
57
|
+
} else {
|
|
58
|
+
// We deprecated enumNames in v5. It's intentionally omitted from RSJFSchema type, so we need to cast here.
|
|
59
|
+
const schemaWithEnumNames = schema as RJSFSchema & { enumNames?: string[] };
|
|
60
|
+
// @ts-ignore
|
|
61
|
+
schema.enum = schema.enum ?? [true, false];
|
|
62
|
+
if (
|
|
63
|
+
!schemaWithEnumNames.enumNames &&
|
|
64
|
+
schema.enum &&
|
|
65
|
+
schema.enum.length === 2 &&
|
|
66
|
+
schema.enum.every((v: any) => typeof v === "boolean")
|
|
67
|
+
) {
|
|
68
|
+
enumOptions = [
|
|
69
|
+
{
|
|
70
|
+
value: schema.enum[0],
|
|
71
|
+
label: schema.enum[0] ? "Yes" : "No",
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
value: schema.enum[1],
|
|
75
|
+
label: schema.enum[1] ? "Yes" : "No",
|
|
76
|
+
},
|
|
77
|
+
];
|
|
78
|
+
} else {
|
|
79
|
+
enumOptions = optionsList({
|
|
80
|
+
enum: schema.enum,
|
|
81
|
+
// NOTE: enumNames is deprecated, but still supported for now.
|
|
82
|
+
enumNames: schemaWithEnumNames.enumNames,
|
|
83
|
+
}) as EnumOptionsType<any>[] | undefined;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
return (
|
|
88
|
+
<Widget
|
|
89
|
+
name={name}
|
|
90
|
+
options={{ ...options, enumOptions }}
|
|
91
|
+
schema={schema}
|
|
92
|
+
uiSchema={uiSchema}
|
|
93
|
+
id={idSchema && idSchema.$id}
|
|
94
|
+
onChange={onChange}
|
|
95
|
+
onFocus={onFocus}
|
|
96
|
+
onBlur={onBlur}
|
|
97
|
+
label={title === undefined ? name : title}
|
|
98
|
+
value={formData}
|
|
99
|
+
required={required}
|
|
100
|
+
disabled={disabled}
|
|
101
|
+
readonly={readonly}
|
|
102
|
+
registry={registry}
|
|
103
|
+
formContext={formContext}
|
|
104
|
+
autofocus={autofocus}
|
|
105
|
+
rawErrors={rawErrors}
|
|
106
|
+
/>
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export default BooleanField;
|