@springmicro/forms 0.6.4 → 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.
Files changed (78) hide show
  1. package/.eslintrc.cjs +22 -22
  2. package/README.md +11 -11
  3. package/dist/index.d.ts +0 -0
  4. package/dist/index.js +0 -0
  5. package/dist/index.umd.cjs +0 -0
  6. package/package.json +3 -3
  7. package/src/builder/bottom-drawer.tsx +429 -429
  8. package/src/builder/form-builder.tsx +256 -256
  9. package/src/builder/modal.tsx +39 -39
  10. package/src/builder/nodes/node-base.tsx +94 -94
  11. package/src/builder/nodes/node-child-helpers.tsx +273 -273
  12. package/src/builder/nodes/node-parent.tsx +187 -187
  13. package/src/builder/nodes/node-types/array-node.tsx +134 -134
  14. package/src/builder/nodes/node-types/date-node.tsx +60 -60
  15. package/src/builder/nodes/node-types/file-node.tsx +67 -67
  16. package/src/builder/nodes/node-types/integer-node.tsx +60 -60
  17. package/src/builder/nodes/node-types/object-node.tsx +67 -67
  18. package/src/builder/nodes/node-types/text-node.tsx +66 -66
  19. package/src/fields/ArrayField.tsx +875 -875
  20. package/src/fields/BooleanField.tsx +110 -110
  21. package/src/fields/MultiSchemaField.tsx +236 -236
  22. package/src/fields/NullField.tsx +22 -22
  23. package/src/fields/NumberField.tsx +87 -87
  24. package/src/fields/ObjectField.tsx +338 -338
  25. package/src/fields/SchemaField.tsx +402 -402
  26. package/src/fields/StringField.tsx +67 -67
  27. package/src/fields/index.ts +24 -24
  28. package/src/index.tsx +26 -26
  29. package/src/interfaces/MessagesProps.interface.ts +5 -5
  30. package/src/interfaces/Option.interface.ts +4 -4
  31. package/src/styles/select.styles.ts +28 -28
  32. package/src/templates/ArrayFieldDescriptionTemplate.tsx +42 -42
  33. package/src/templates/ArrayFieldItemTemplate.tsx +78 -78
  34. package/src/templates/ArrayFieldTemplate.tsx +90 -90
  35. package/src/templates/ArrayFieldTitleTemplate.tsx +44 -44
  36. package/src/templates/BaseInputTemplate.tsx +94 -94
  37. package/src/templates/ButtonTemplates/AddButton.tsx +29 -29
  38. package/src/templates/ButtonTemplates/IconButton.tsx +49 -49
  39. package/src/templates/ButtonTemplates/SubmitButton.tsx +29 -29
  40. package/src/templates/ButtonTemplates/index.ts +16 -16
  41. package/src/templates/DescriptionField.tsx +29 -29
  42. package/src/templates/ErrorList.tsx +25 -25
  43. package/src/templates/FieldTemplate/FieldTemplate.tsx +39 -39
  44. package/src/templates/FieldTemplate/Label.tsx +29 -29
  45. package/src/templates/FieldTemplate/WrapIfAdditional.tsx +85 -85
  46. package/src/templates/FieldTemplate/index.ts +3 -3
  47. package/src/templates/ObjectFieldTemplate.tsx +79 -79
  48. package/src/templates/TitleField.tsx +20 -20
  49. package/src/templates/UnsupportedField.tsx +29 -29
  50. package/src/templates/index.ts +32 -32
  51. package/src/types/Message.type.ts +6 -6
  52. package/src/types/RawMessage.type.ts +15 -15
  53. package/src/types/form-builder.ts +135 -135
  54. package/src/types/utils.type.ts +1 -1
  55. package/src/utils/form-builder.ts +424 -424
  56. package/src/utils/processSelectValue.ts +50 -50
  57. package/src/widgets/AltDateTimeWidget.tsx +17 -17
  58. package/src/widgets/AltDateWidget.tsx +216 -216
  59. package/src/widgets/CheckboxWidget.tsx +80 -80
  60. package/src/widgets/CheckboxesWidget.tsx +74 -74
  61. package/src/widgets/ColorWidget.tsx +26 -26
  62. package/src/widgets/DateTimeWidget.tsx +28 -28
  63. package/src/widgets/DateWidget.tsx +36 -36
  64. package/src/widgets/EmailWidget.tsx +19 -19
  65. package/src/widgets/FileWidget.tsx +144 -144
  66. package/src/widgets/HiddenWidget.tsx +22 -22
  67. package/src/widgets/PasswordWidget.tsx +20 -20
  68. package/src/widgets/RadioWidget.tsx +87 -87
  69. package/src/widgets/RangeWidget.tsx +24 -24
  70. package/src/widgets/SelectWidget.tsx +99 -99
  71. package/src/widgets/TextWidget.tsx +19 -19
  72. package/src/widgets/TextareaWidget.tsx +64 -64
  73. package/src/widgets/URLWidget.tsx +19 -19
  74. package/src/widgets/UpDownWidget.tsx +20 -20
  75. package/src/widgets/index.ts +43 -43
  76. package/tsconfig.json +24 -24
  77. package/tsconfig.node.json +10 -10
  78. package/vite.config.ts +25 -25
@@ -1,273 +1,273 @@
1
- import { FieldArrayType, FormNodeType } from "../../types/form-builder";
2
- import {
3
- Checkbox,
4
- FormControlLabel,
5
- IconButton,
6
- TextField,
7
- Tooltip,
8
- } from "@mui/material";
9
- import { Box, SxProps } from "@mui/material";
10
- import CloseIcon from "@mui/icons-material/Close";
11
- import React from "react";
12
- import { formatTitle } from "../../utils/form-builder";
13
- import DeleteOutlineIcon from "@mui/icons-material/DeleteOutline";
14
-
15
- /**
16
- * ---------------------- NODE CHILD BASE ----------------------
17
- */
18
-
19
- export type NodeChildBaseProps = {
20
- children?: React.ReactNode;
21
- };
22
-
23
- export function NodeChildBase({ children }: NodeChildBaseProps) {
24
- return (
25
- <Box sx={{ display: "flex", flexDirection: "column", width: "100%" }}>
26
- {children}
27
- </Box>
28
- );
29
- }
30
-
31
- /**
32
- * ---------------------- NODE ACCORDIAN ----------------------
33
- */
34
-
35
- export type NodeAccordianProps = {
36
- open?: boolean;
37
- children?: React.ReactNode;
38
- close: () => void;
39
- deleteNode: () => void;
40
- };
41
-
42
- export function NodeAccordian({
43
- open,
44
- children,
45
- close,
46
- deleteNode,
47
- }: NodeAccordianProps) {
48
- return (
49
- <Box
50
- className={open ? "open" : ""}
51
- sx={{
52
- overflow: "hidden",
53
- transition: "max-height .45s cubic-bezier(0, 1, 0, 1) -.1s",
54
- maxHeight: 0,
55
- "&.open": {
56
- maxHeight: 9999,
57
- transitionTimingFunction: "cubic-bezier(0.5, 0, 1, 0)",
58
- transitionDelay: "0s",
59
- },
60
- width: "100%",
61
- }}
62
- >
63
- <Box
64
- sx={{
65
- pt: 2,
66
- display: "flex",
67
- flexDirection: "column",
68
- }}
69
- >
70
- {children}
71
- </Box>
72
- <Box sx={{ pt: 1 }}>
73
- <BottomSection close={close} deleteNode={deleteNode} />
74
- </Box>
75
- </Box>
76
- );
77
- }
78
-
79
- /**
80
- * ---------------------- NODE TITLE ----------------------
81
- */
82
-
83
- export function NodeTitle({
84
- children,
85
- isPropname,
86
- isEditing,
87
- onClick,
88
- }: {
89
- children: React.ReactNode;
90
- isPropname?: boolean;
91
- isEditing?: boolean;
92
- onClick: () => void;
93
- }) {
94
- return (
95
- <Box
96
- sx={{
97
- width: "100%",
98
- pt: 2,
99
- cursor: "pointer",
100
- transition: "background-color 0.5s",
101
- borderBottomLeftRadius: 10,
102
- borderBottomRightRadius: 10,
103
- ":hover": {
104
- backgroundColor: isEditing ? "#dddddd" : "transparent",
105
- },
106
- }}
107
- onClick={isEditing ? onClick : () => {}}
108
- >
109
- <Box
110
- sx={{
111
- fontWeight: 400,
112
- fontSize: 18,
113
- backgroundColor: !isPropname ? "transparent" : "#d5d5d5",
114
- borderRadius: 2,
115
- px: 1,
116
- display: "inline-block",
117
- }}
118
- >
119
- {children}
120
- </Box>
121
- </Box>
122
- );
123
- }
124
-
125
- /**
126
- * ---------------------- STYLED TEXT FIELD ----------------------
127
- */
128
-
129
- export const textfieldStyle = (sx?: SxProps) => ({
130
- minWidth: 250,
131
- flexGrow: 1,
132
- ...{
133
- "& .MuiOutlinedInput-root": {
134
- "& fieldset": {
135
- borderColor: "#C0C3C7",
136
- },
137
- "&:hover fieldset": {
138
- borderColor: "#A2AAB2",
139
- },
140
- "&.Mui-focused fieldset": {
141
- borderColor: "#6F7E8C",
142
- },
143
- },
144
- },
145
- ...(sx ?? {}),
146
- });
147
-
148
- export function StyledTextField(props?: any, children?: React.ReactNode) {
149
- return (
150
- <TextField {...props} sx={textfieldStyle(props.sx)}>
151
- {children}
152
- </TextField>
153
- );
154
- }
155
-
156
- /**
157
- * ---------------------- BOTTOM SECTION ----------------------
158
- */
159
-
160
- export function BottomSection({
161
- close,
162
- deleteNode,
163
- }: {
164
- close: () => void;
165
- deleteNode: () => void;
166
- }) {
167
- return (
168
- <Box
169
- sx={{
170
- width: "100%",
171
- display: "flex",
172
- justifyContent: "space-between",
173
- backgroundColor: "#00000009",
174
- borderRadius: 1,
175
- py: 0.5,
176
- }}
177
- >
178
- <Box>
179
- <IconButton onClick={deleteNode}>
180
- <DeleteOutlineIcon sx={{ color: "red" }} />
181
- </IconButton>
182
- </Box>
183
- <Box>
184
- <IconButton onClick={close}>
185
- <CloseIcon />
186
- </IconButton>
187
- </Box>
188
- </Box>
189
- );
190
- }
191
-
192
- /**
193
- * ---------------------- FIELD INPUTS ----------------------
194
- */
195
-
196
- export function NodeField({
197
- field,
198
- node,
199
- update,
200
- }: {
201
- field: FieldArrayType<any>[0];
202
- node: FormNodeType;
203
- update: (
204
- key: string,
205
- e: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>,
206
- type?: string
207
- ) => void;
208
- }) {
209
- const prop = field.prop as keyof FormNodeType;
210
- const textfield = (
211
- <StyledTextField
212
- label={field.title ?? formatTitle(prop)}
213
- value={node[prop] as string}
214
- onChange={(e: any) => update(prop, e)}
215
- {...field.props}
216
- />
217
- );
218
- if (!field.tooltip) return textfield;
219
- return (
220
- <Tooltip title={field.tooltip} arrow>
221
- {textfield}
222
- </Tooltip>
223
- );
224
- }
225
-
226
- export function NodeCheckbox({
227
- field,
228
- node,
229
- update,
230
- }: {
231
- field: FieldArrayType<any>[0];
232
- node: FormNodeType;
233
- update: (
234
- key: string,
235
- e: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>,
236
- type?: string
237
- ) => void;
238
- }) {
239
- const prop = field.prop as keyof FormNodeType;
240
- const checkbox = (
241
- <FormControlLabel
242
- control={
243
- <Checkbox
244
- checked={node[prop] as boolean}
245
- onChange={(e: React.ChangeEvent<HTMLInputElement>) => {
246
- update(prop, e, "check");
247
- }}
248
- />
249
- }
250
- label={field.title ?? formatTitle(prop)}
251
- />
252
- );
253
- if (!field.tooltip) return checkbox;
254
- return (
255
- <Tooltip title={field.tooltip} arrow>
256
- {checkbox}
257
- </Tooltip>
258
- );
259
- }
260
-
261
- /**
262
- * ---------------------- FIELD CONTAINERS ----------------------
263
- */
264
-
265
- export function FieldContainer({ children }: { children?: React.ReactNode }) {
266
- return (
267
- <Box
268
- sx={{ display: "flex", flexDirection: "row", gap: 2, flexWrap: "wrap" }}
269
- >
270
- {children}
271
- </Box>
272
- );
273
- }
1
+ import { FieldArrayType, FormNodeType } from "../../types/form-builder";
2
+ import {
3
+ Checkbox,
4
+ FormControlLabel,
5
+ IconButton,
6
+ TextField,
7
+ Tooltip,
8
+ } from "@mui/material";
9
+ import { Box, SxProps } from "@mui/material";
10
+ import CloseIcon from "@mui/icons-material/Close";
11
+ import React from "react";
12
+ import { formatTitle } from "../../utils/form-builder";
13
+ import DeleteOutlineIcon from "@mui/icons-material/DeleteOutline";
14
+
15
+ /**
16
+ * ---------------------- NODE CHILD BASE ----------------------
17
+ */
18
+
19
+ export type NodeChildBaseProps = {
20
+ children?: React.ReactNode;
21
+ };
22
+
23
+ export function NodeChildBase({ children }: NodeChildBaseProps) {
24
+ return (
25
+ <Box sx={{ display: "flex", flexDirection: "column", width: "100%" }}>
26
+ {children}
27
+ </Box>
28
+ );
29
+ }
30
+
31
+ /**
32
+ * ---------------------- NODE ACCORDIAN ----------------------
33
+ */
34
+
35
+ export type NodeAccordianProps = {
36
+ open?: boolean;
37
+ children?: React.ReactNode;
38
+ close: () => void;
39
+ deleteNode: () => void;
40
+ };
41
+
42
+ export function NodeAccordian({
43
+ open,
44
+ children,
45
+ close,
46
+ deleteNode,
47
+ }: NodeAccordianProps) {
48
+ return (
49
+ <Box
50
+ className={open ? "open" : ""}
51
+ sx={{
52
+ overflow: "hidden",
53
+ transition: "max-height .45s cubic-bezier(0, 1, 0, 1) -.1s",
54
+ maxHeight: 0,
55
+ "&.open": {
56
+ maxHeight: 9999,
57
+ transitionTimingFunction: "cubic-bezier(0.5, 0, 1, 0)",
58
+ transitionDelay: "0s",
59
+ },
60
+ width: "100%",
61
+ }}
62
+ >
63
+ <Box
64
+ sx={{
65
+ pt: 2,
66
+ display: "flex",
67
+ flexDirection: "column",
68
+ }}
69
+ >
70
+ {children}
71
+ </Box>
72
+ <Box sx={{ pt: 1 }}>
73
+ <BottomSection close={close} deleteNode={deleteNode} />
74
+ </Box>
75
+ </Box>
76
+ );
77
+ }
78
+
79
+ /**
80
+ * ---------------------- NODE TITLE ----------------------
81
+ */
82
+
83
+ export function NodeTitle({
84
+ children,
85
+ isPropname,
86
+ isEditing,
87
+ onClick,
88
+ }: {
89
+ children: React.ReactNode;
90
+ isPropname?: boolean;
91
+ isEditing?: boolean;
92
+ onClick: () => void;
93
+ }) {
94
+ return (
95
+ <Box
96
+ sx={{
97
+ width: "100%",
98
+ pt: 2,
99
+ cursor: "pointer",
100
+ transition: "background-color 0.5s",
101
+ borderBottomLeftRadius: 10,
102
+ borderBottomRightRadius: 10,
103
+ ":hover": {
104
+ backgroundColor: isEditing ? "#dddddd" : "transparent",
105
+ },
106
+ }}
107
+ onClick={isEditing ? onClick : () => {}}
108
+ >
109
+ <Box
110
+ sx={{
111
+ fontWeight: 400,
112
+ fontSize: 18,
113
+ backgroundColor: !isPropname ? "transparent" : "#d5d5d5",
114
+ borderRadius: 2,
115
+ px: 1,
116
+ display: "inline-block",
117
+ }}
118
+ >
119
+ {children}
120
+ </Box>
121
+ </Box>
122
+ );
123
+ }
124
+
125
+ /**
126
+ * ---------------------- STYLED TEXT FIELD ----------------------
127
+ */
128
+
129
+ export const textfieldStyle = (sx?: SxProps) => ({
130
+ minWidth: 250,
131
+ flexGrow: 1,
132
+ ...{
133
+ "& .MuiOutlinedInput-root": {
134
+ "& fieldset": {
135
+ borderColor: "#C0C3C7",
136
+ },
137
+ "&:hover fieldset": {
138
+ borderColor: "#A2AAB2",
139
+ },
140
+ "&.Mui-focused fieldset": {
141
+ borderColor: "#6F7E8C",
142
+ },
143
+ },
144
+ },
145
+ ...(sx ?? {}),
146
+ });
147
+
148
+ export function StyledTextField(props?: any, children?: React.ReactNode) {
149
+ return (
150
+ <TextField {...props} sx={textfieldStyle(props.sx)}>
151
+ {children}
152
+ </TextField>
153
+ );
154
+ }
155
+
156
+ /**
157
+ * ---------------------- BOTTOM SECTION ----------------------
158
+ */
159
+
160
+ export function BottomSection({
161
+ close,
162
+ deleteNode,
163
+ }: {
164
+ close: () => void;
165
+ deleteNode: () => void;
166
+ }) {
167
+ return (
168
+ <Box
169
+ sx={{
170
+ width: "100%",
171
+ display: "flex",
172
+ justifyContent: "space-between",
173
+ backgroundColor: "#00000009",
174
+ borderRadius: 1,
175
+ py: 0.5,
176
+ }}
177
+ >
178
+ <Box>
179
+ <IconButton onClick={deleteNode}>
180
+ <DeleteOutlineIcon sx={{ color: "red" }} />
181
+ </IconButton>
182
+ </Box>
183
+ <Box>
184
+ <IconButton onClick={close}>
185
+ <CloseIcon />
186
+ </IconButton>
187
+ </Box>
188
+ </Box>
189
+ );
190
+ }
191
+
192
+ /**
193
+ * ---------------------- FIELD INPUTS ----------------------
194
+ */
195
+
196
+ export function NodeField({
197
+ field,
198
+ node,
199
+ update,
200
+ }: {
201
+ field: FieldArrayType<any>[0];
202
+ node: FormNodeType;
203
+ update: (
204
+ key: string,
205
+ e: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>,
206
+ type?: string
207
+ ) => void;
208
+ }) {
209
+ const prop = field.prop as keyof FormNodeType;
210
+ const textfield = (
211
+ <StyledTextField
212
+ label={field.title ?? formatTitle(prop)}
213
+ value={node[prop] as string}
214
+ onChange={(e: any) => update(prop, e)}
215
+ {...field.props}
216
+ />
217
+ );
218
+ if (!field.tooltip) return textfield;
219
+ return (
220
+ <Tooltip title={field.tooltip} arrow>
221
+ {textfield}
222
+ </Tooltip>
223
+ );
224
+ }
225
+
226
+ export function NodeCheckbox({
227
+ field,
228
+ node,
229
+ update,
230
+ }: {
231
+ field: FieldArrayType<any>[0];
232
+ node: FormNodeType;
233
+ update: (
234
+ key: string,
235
+ e: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>,
236
+ type?: string
237
+ ) => void;
238
+ }) {
239
+ const prop = field.prop as keyof FormNodeType;
240
+ const checkbox = (
241
+ <FormControlLabel
242
+ control={
243
+ <Checkbox
244
+ checked={node[prop] as boolean}
245
+ onChange={(e: React.ChangeEvent<HTMLInputElement>) => {
246
+ update(prop, e, "check");
247
+ }}
248
+ />
249
+ }
250
+ label={field.title ?? formatTitle(prop)}
251
+ />
252
+ );
253
+ if (!field.tooltip) return checkbox;
254
+ return (
255
+ <Tooltip title={field.tooltip} arrow>
256
+ {checkbox}
257
+ </Tooltip>
258
+ );
259
+ }
260
+
261
+ /**
262
+ * ---------------------- FIELD CONTAINERS ----------------------
263
+ */
264
+
265
+ export function FieldContainer({ children }: { children?: React.ReactNode }) {
266
+ return (
267
+ <Box
268
+ sx={{ display: "flex", flexDirection: "row", gap: 2, flexWrap: "wrap" }}
269
+ >
270
+ {children}
271
+ </Box>
272
+ );
273
+ }