@loopr-ai/craft 0.8.0 → 0.8.2
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.
|
@@ -1,31 +1,32 @@
|
|
|
1
1
|
import { jsx as C, jsxs as F } from "react/jsx-runtime";
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
import { g as
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
import * as u from "react";
|
|
3
|
+
import { forwardRef as U } from "react";
|
|
4
|
+
import { getColorToHex as b } from "../../../global/colors.js";
|
|
5
|
+
import { g as D, c as s, a as t, e as g, _ as H, P as a } from "../../../createTheme-759a022d.js";
|
|
6
|
+
import { g as A, s as y, r as q, e as J, a as K, c as R, b as Q } from "../../../styled-78608e1f.js";
|
|
7
|
+
import { B as X } from "../../../ButtonBase-08b16b61.js";
|
|
8
|
+
function Y(o) {
|
|
9
|
+
return D("MuiButton", o);
|
|
9
10
|
}
|
|
10
|
-
const
|
|
11
|
+
const Z = A("MuiButton", ["root", "text", "textInherit", "textPrimary", "textSecondary", "textSuccess", "textError", "textInfo", "textWarning", "outlined", "outlinedInherit", "outlinedPrimary", "outlinedSecondary", "outlinedSuccess", "outlinedError", "outlinedInfo", "outlinedWarning", "contained", "containedInherit", "containedPrimary", "containedSecondary", "containedSuccess", "containedError", "containedInfo", "containedWarning", "disableElevation", "focusVisible", "disabled", "colorInherit", "textSizeSmall", "textSizeMedium", "textSizeLarge", "outlinedSizeSmall", "outlinedSizeMedium", "outlinedSizeLarge", "containedSizeSmall", "containedSizeMedium", "containedSizeLarge", "sizeMedium", "sizeSmall", "sizeLarge", "fullWidth", "startIcon", "endIcon", "iconSizeSmall", "iconSizeMedium", "iconSizeLarge"]), x = Z, k = /* @__PURE__ */ u.createContext({});
|
|
11
12
|
process.env.NODE_ENV !== "production" && (k.displayName = "ButtonGroupContext");
|
|
12
|
-
const
|
|
13
|
+
const w = k, N = /* @__PURE__ */ u.createContext(void 0);
|
|
13
14
|
process.env.NODE_ENV !== "production" && (N.displayName = "ButtonGroupButtonContext");
|
|
14
|
-
const
|
|
15
|
+
const oo = N, no = ["children", "color", "component", "className", "disabled", "disableElevation", "disableFocusRipple", "endIcon", "focusVisibleClassName", "fullWidth", "size", "startIcon", "type", "variant"], ao = (o) => {
|
|
15
16
|
const {
|
|
16
17
|
color: n,
|
|
17
18
|
disableElevation: i,
|
|
18
|
-
fullWidth:
|
|
19
|
+
fullWidth: e,
|
|
19
20
|
size: r,
|
|
20
|
-
variant:
|
|
21
|
-
classes:
|
|
22
|
-
} = o,
|
|
23
|
-
root: ["root",
|
|
21
|
+
variant: l,
|
|
22
|
+
classes: c
|
|
23
|
+
} = o, d = {
|
|
24
|
+
root: ["root", l, `${l}${s(n)}`, `size${s(r)}`, `${l}Size${s(r)}`, n === "inherit" && "colorInherit", i && "disableElevation", e && "fullWidth"],
|
|
24
25
|
label: ["label"],
|
|
25
|
-
startIcon: ["startIcon", `iconSize${
|
|
26
|
-
endIcon: ["endIcon", `iconSize${
|
|
27
|
-
}, f =
|
|
28
|
-
return t({},
|
|
26
|
+
startIcon: ["startIcon", `iconSize${s(r)}`],
|
|
27
|
+
endIcon: ["endIcon", `iconSize${s(r)}`]
|
|
28
|
+
}, f = Q(d, Y, c);
|
|
29
|
+
return t({}, c, f);
|
|
29
30
|
}, E = (o) => t({}, o.size === "small" && {
|
|
30
31
|
"& > *:nth-of-type(1)": {
|
|
31
32
|
fontSize: 18
|
|
@@ -38,22 +39,22 @@ const w = N, oo = ["children", "color", "component", "className", "disabled", "d
|
|
|
38
39
|
"& > *:nth-of-type(1)": {
|
|
39
40
|
fontSize: 22
|
|
40
41
|
}
|
|
41
|
-
}),
|
|
42
|
-
shouldForwardProp: (o) =>
|
|
42
|
+
}), io = y(X, {
|
|
43
|
+
shouldForwardProp: (o) => q(o) || o === "classes",
|
|
43
44
|
name: "MuiButton",
|
|
44
45
|
slot: "Root",
|
|
45
46
|
overridesResolver: (o, n) => {
|
|
46
47
|
const {
|
|
47
48
|
ownerState: i
|
|
48
49
|
} = o;
|
|
49
|
-
return [n.root, n[i.variant], n[`${i.variant}${
|
|
50
|
+
return [n.root, n[i.variant], n[`${i.variant}${s(i.color)}`], n[`size${s(i.size)}`], n[`${i.variant}Size${s(i.size)}`], i.color === "inherit" && n.colorInherit, i.disableElevation && n.disableElevation, i.fullWidth && n.fullWidth];
|
|
50
51
|
}
|
|
51
52
|
})(({
|
|
52
53
|
theme: o,
|
|
53
54
|
ownerState: n
|
|
54
55
|
}) => {
|
|
55
|
-
var i,
|
|
56
|
-
const r = o.palette.mode === "light" ? o.palette.grey[300] : o.palette.grey[800],
|
|
56
|
+
var i, e;
|
|
57
|
+
const r = o.palette.mode === "light" ? o.palette.grey[300] : o.palette.grey[800], l = o.palette.mode === "light" ? o.palette.grey.A100 : o.palette.grey[700];
|
|
57
58
|
return t({}, o.typography.button, {
|
|
58
59
|
minWidth: 64,
|
|
59
60
|
padding: "6px 16px",
|
|
@@ -63,26 +64,26 @@ const w = N, oo = ["children", "color", "component", "className", "disabled", "d
|
|
|
63
64
|
}),
|
|
64
65
|
"&:hover": t({
|
|
65
66
|
textDecoration: "none",
|
|
66
|
-
backgroundColor: o.vars ? `rgba(${o.vars.palette.text.primaryChannel} / ${o.vars.palette.action.hoverOpacity})` :
|
|
67
|
+
backgroundColor: o.vars ? `rgba(${o.vars.palette.text.primaryChannel} / ${o.vars.palette.action.hoverOpacity})` : g(o.palette.text.primary, o.palette.action.hoverOpacity),
|
|
67
68
|
// Reset on touch devices, it doesn't add specificity
|
|
68
69
|
"@media (hover: none)": {
|
|
69
70
|
backgroundColor: "transparent"
|
|
70
71
|
}
|
|
71
72
|
}, n.variant === "text" && n.color !== "inherit" && {
|
|
72
|
-
backgroundColor: o.vars ? `rgba(${o.vars.palette[n.color].mainChannel} / ${o.vars.palette.action.hoverOpacity})` :
|
|
73
|
+
backgroundColor: o.vars ? `rgba(${o.vars.palette[n.color].mainChannel} / ${o.vars.palette.action.hoverOpacity})` : g(o.palette[n.color].main, o.palette.action.hoverOpacity),
|
|
73
74
|
// Reset on touch devices, it doesn't add specificity
|
|
74
75
|
"@media (hover: none)": {
|
|
75
76
|
backgroundColor: "transparent"
|
|
76
77
|
}
|
|
77
78
|
}, n.variant === "outlined" && n.color !== "inherit" && {
|
|
78
79
|
border: `1px solid ${(o.vars || o).palette[n.color].main}`,
|
|
79
|
-
backgroundColor: o.vars ? `rgba(${o.vars.palette[n.color].mainChannel} / ${o.vars.palette.action.hoverOpacity})` :
|
|
80
|
+
backgroundColor: o.vars ? `rgba(${o.vars.palette[n.color].mainChannel} / ${o.vars.palette.action.hoverOpacity})` : g(o.palette[n.color].main, o.palette.action.hoverOpacity),
|
|
80
81
|
// Reset on touch devices, it doesn't add specificity
|
|
81
82
|
"@media (hover: none)": {
|
|
82
83
|
backgroundColor: "transparent"
|
|
83
84
|
}
|
|
84
85
|
}, n.variant === "contained" && {
|
|
85
|
-
backgroundColor: o.vars ? o.vars.palette.Button.inheritContainedHoverBg :
|
|
86
|
+
backgroundColor: o.vars ? o.vars.palette.Button.inheritContainedHoverBg : l,
|
|
86
87
|
boxShadow: (o.vars || o).shadows[4],
|
|
87
88
|
// Reset on touch devices, it doesn't add specificity
|
|
88
89
|
"@media (hover: none)": {
|
|
@@ -99,10 +100,10 @@ const w = N, oo = ["children", "color", "component", "className", "disabled", "d
|
|
|
99
100
|
"&:active": t({}, n.variant === "contained" && {
|
|
100
101
|
boxShadow: (o.vars || o).shadows[8]
|
|
101
102
|
}),
|
|
102
|
-
[`&.${
|
|
103
|
+
[`&.${x.focusVisible}`]: t({}, n.variant === "contained" && {
|
|
103
104
|
boxShadow: (o.vars || o).shadows[6]
|
|
104
105
|
}),
|
|
105
|
-
[`&.${
|
|
106
|
+
[`&.${x.disabled}`]: t({
|
|
106
107
|
color: (o.vars || o).palette.action.disabled
|
|
107
108
|
}, n.variant === "outlined" && {
|
|
108
109
|
border: `1px solid ${(o.vars || o).palette.action.disabledBackground}`
|
|
@@ -120,12 +121,12 @@ const w = N, oo = ["children", "color", "component", "className", "disabled", "d
|
|
|
120
121
|
border: "1px solid currentColor"
|
|
121
122
|
}, n.variant === "outlined" && n.color !== "inherit" && {
|
|
122
123
|
color: (o.vars || o).palette[n.color].main,
|
|
123
|
-
border: o.vars ? `1px solid rgba(${o.vars.palette[n.color].mainChannel} / 0.5)` : `1px solid ${
|
|
124
|
+
border: o.vars ? `1px solid rgba(${o.vars.palette[n.color].mainChannel} / 0.5)` : `1px solid ${g(o.palette[n.color].main, 0.5)}`
|
|
124
125
|
}, n.variant === "contained" && {
|
|
125
126
|
color: o.vars ? (
|
|
126
127
|
// this is safe because grey does not change between default light/dark mode
|
|
127
128
|
o.vars.palette.text.primary
|
|
128
|
-
) : (i = (
|
|
129
|
+
) : (i = (e = o.palette).getContrastText) == null ? void 0 : i.call(e, o.palette.grey[300]),
|
|
129
130
|
backgroundColor: o.vars ? o.vars.palette.Button.inheritContainedBg : r,
|
|
130
131
|
boxShadow: (o.vars || o).shadows[2]
|
|
131
132
|
}, n.variant === "contained" && n.color !== "inherit" && {
|
|
@@ -162,23 +163,23 @@ const w = N, oo = ["children", "color", "component", "className", "disabled", "d
|
|
|
162
163
|
"&:hover": {
|
|
163
164
|
boxShadow: "none"
|
|
164
165
|
},
|
|
165
|
-
[`&.${
|
|
166
|
+
[`&.${x.focusVisible}`]: {
|
|
166
167
|
boxShadow: "none"
|
|
167
168
|
},
|
|
168
169
|
"&:active": {
|
|
169
170
|
boxShadow: "none"
|
|
170
171
|
},
|
|
171
|
-
[`&.${
|
|
172
|
+
[`&.${x.disabled}`]: {
|
|
172
173
|
boxShadow: "none"
|
|
173
174
|
}
|
|
174
|
-
}),
|
|
175
|
+
}), ro = y("span", {
|
|
175
176
|
name: "MuiButton",
|
|
176
177
|
slot: "StartIcon",
|
|
177
178
|
overridesResolver: (o, n) => {
|
|
178
179
|
const {
|
|
179
180
|
ownerState: i
|
|
180
181
|
} = o;
|
|
181
|
-
return [n.startIcon, n[`iconSize${
|
|
182
|
+
return [n.startIcon, n[`iconSize${s(i.size)}`]];
|
|
182
183
|
}
|
|
183
184
|
})(({
|
|
184
185
|
ownerState: o
|
|
@@ -188,14 +189,14 @@ const w = N, oo = ["children", "color", "component", "className", "disabled", "d
|
|
|
188
189
|
marginLeft: -4
|
|
189
190
|
}, o.size === "small" && {
|
|
190
191
|
marginLeft: -2
|
|
191
|
-
}, E(o))),
|
|
192
|
+
}, E(o))), to = y("span", {
|
|
192
193
|
name: "MuiButton",
|
|
193
194
|
slot: "EndIcon",
|
|
194
195
|
overridesResolver: (o, n) => {
|
|
195
196
|
const {
|
|
196
197
|
ownerState: i
|
|
197
198
|
} = o;
|
|
198
|
-
return [n.endIcon, n[`iconSize${
|
|
199
|
+
return [n.endIcon, n[`iconSize${s(i.size)}`]];
|
|
199
200
|
}
|
|
200
201
|
})(({
|
|
201
202
|
ownerState: o
|
|
@@ -205,12 +206,12 @@ const w = N, oo = ["children", "color", "component", "className", "disabled", "d
|
|
|
205
206
|
marginLeft: 8
|
|
206
207
|
}, o.size === "small" && {
|
|
207
208
|
marginRight: -2
|
|
208
|
-
}, E(o))), O = /* @__PURE__ */
|
|
209
|
-
const
|
|
210
|
-
props:
|
|
209
|
+
}, E(o))), O = /* @__PURE__ */ u.forwardRef(function(n, i) {
|
|
210
|
+
const e = u.useContext(w), r = u.useContext(oo), l = J(e, n), c = K({
|
|
211
|
+
props: l,
|
|
211
212
|
name: "MuiButton"
|
|
212
213
|
}), {
|
|
213
|
-
children:
|
|
214
|
+
children: d,
|
|
214
215
|
color: f = "primary",
|
|
215
216
|
component: z = "button",
|
|
216
217
|
className: T,
|
|
@@ -224,7 +225,7 @@ const w = N, oo = ["children", "color", "component", "className", "disabled", "d
|
|
|
224
225
|
startIcon: $,
|
|
225
226
|
type: h,
|
|
226
227
|
variant: V = "text"
|
|
227
|
-
} =
|
|
228
|
+
} = c, L = H(c, no), v = t({}, c, {
|
|
228
229
|
color: f,
|
|
229
230
|
component: z,
|
|
230
231
|
disabled: m,
|
|
@@ -234,27 +235,27 @@ const w = N, oo = ["children", "color", "component", "className", "disabled", "d
|
|
|
234
235
|
size: S,
|
|
235
236
|
type: h,
|
|
236
237
|
variant: V
|
|
237
|
-
}),
|
|
238
|
-
className:
|
|
239
|
-
ownerState:
|
|
238
|
+
}), p = ao(v), _ = $ && /* @__PURE__ */ C(ro, {
|
|
239
|
+
className: p.startIcon,
|
|
240
|
+
ownerState: v,
|
|
240
241
|
children: $
|
|
241
|
-
}), G = I && /* @__PURE__ */ C(
|
|
242
|
-
className:
|
|
243
|
-
ownerState:
|
|
242
|
+
}), G = I && /* @__PURE__ */ C(to, {
|
|
243
|
+
className: p.endIcon,
|
|
244
|
+
ownerState: v,
|
|
244
245
|
children: I
|
|
245
246
|
}), j = r || "";
|
|
246
|
-
return /* @__PURE__ */ F(
|
|
247
|
-
ownerState:
|
|
248
|
-
className: R(
|
|
247
|
+
return /* @__PURE__ */ F(io, t({
|
|
248
|
+
ownerState: v,
|
|
249
|
+
className: R(e.className, p.root, T, j),
|
|
249
250
|
component: z,
|
|
250
251
|
disabled: m,
|
|
251
252
|
focusRipple: !B,
|
|
252
|
-
focusVisibleClassName: R(
|
|
253
|
+
focusVisibleClassName: R(p.focusVisible, W),
|
|
253
254
|
ref: i,
|
|
254
255
|
type: h
|
|
255
256
|
}, L, {
|
|
256
|
-
classes:
|
|
257
|
-
children: [_,
|
|
257
|
+
classes: p,
|
|
258
|
+
children: [_, d, G]
|
|
258
259
|
}));
|
|
259
260
|
});
|
|
260
261
|
process.env.NODE_ENV !== "production" && (O.propTypes = {
|
|
@@ -351,35 +352,47 @@ process.env.NODE_ENV !== "production" && (O.propTypes = {
|
|
|
351
352
|
*/
|
|
352
353
|
variant: a.oneOfType([a.oneOf(["contained", "outlined", "text"]), a.string])
|
|
353
354
|
});
|
|
354
|
-
const
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
"
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
}
|
|
355
|
+
const so = O, bo = U(
|
|
356
|
+
({
|
|
357
|
+
variant: o = "contained",
|
|
358
|
+
disabled: n = !1,
|
|
359
|
+
look: i = "normal",
|
|
360
|
+
children: e,
|
|
361
|
+
sx: r,
|
|
362
|
+
...l
|
|
363
|
+
}, c) => {
|
|
364
|
+
let d = {};
|
|
365
|
+
return i === "modified" ? (n === !1 && (d = {
|
|
366
|
+
border: "0rem",
|
|
367
|
+
backgroundColor: b("modify"),
|
|
368
|
+
color: b("primary"),
|
|
369
|
+
"&:hover": {
|
|
370
|
+
border: "0.0625rem solid",
|
|
371
|
+
borderColor: b("primary"),
|
|
372
|
+
backgroundColor: b("modify")
|
|
373
|
+
}
|
|
374
|
+
}), o = "outlined") : o === "contained" && n === !0 && (d = {
|
|
375
|
+
"&.Mui-disabled": {
|
|
376
|
+
backgroundColor: "#C4C4C4",
|
|
377
|
+
color: "#000000",
|
|
378
|
+
boxShadow: "none"
|
|
379
|
+
}
|
|
380
|
+
}), r = {
|
|
381
|
+
...d,
|
|
382
|
+
...r
|
|
383
|
+
}, /* @__PURE__ */ C(
|
|
384
|
+
so,
|
|
385
|
+
{
|
|
386
|
+
ref: c,
|
|
387
|
+
variant: o,
|
|
388
|
+
disabled: n,
|
|
389
|
+
sx: r,
|
|
390
|
+
...l,
|
|
391
|
+
children: e
|
|
392
|
+
}
|
|
393
|
+
);
|
|
394
|
+
}
|
|
395
|
+
);
|
|
383
396
|
export {
|
|
384
|
-
|
|
397
|
+
bo as default
|
|
385
398
|
};
|
|
@@ -8,7 +8,7 @@ interface FormProps {
|
|
|
8
8
|
handleSubmit: (data: any) => void;
|
|
9
9
|
handleInvalidData?: (data: Array<InvalidData>) => void;
|
|
10
10
|
cancelText?: string;
|
|
11
|
-
handleCancel
|
|
11
|
+
handleCancel?: () => void;
|
|
12
12
|
onChange?: (key: string, value: string) => void;
|
|
13
13
|
customFields?: CustomFields;
|
|
14
14
|
formWrapperStyles?: SxProps;
|
|
@@ -20,15 +20,20 @@ interface FormProps {
|
|
|
20
20
|
}
|
|
21
21
|
/**
|
|
22
22
|
* Form component
|
|
23
|
-
* @param config - Array of
|
|
23
|
+
* @param config - Array of form fields
|
|
24
24
|
* @param submitText - Text for submit button
|
|
25
25
|
* @param handleSubmit - Function to handle form submission
|
|
26
|
-
* @param handleInvalidData - Function to handle invalid
|
|
26
|
+
* @param handleInvalidData - Function to handle invalid data
|
|
27
27
|
* @param cancelText - Text for cancel button
|
|
28
28
|
* @param handleCancel - Function to handle form cancel
|
|
29
29
|
* @param onChange - Function to handle form field change
|
|
30
|
-
* @param customFields -
|
|
31
|
-
* @param
|
|
30
|
+
* @param customFields - Object containing custom fields
|
|
31
|
+
* @param formWrapperStyles - Styles for form wrapper
|
|
32
|
+
* @param formFieldsWrapperStyles - Styles for form fields wrapper
|
|
33
|
+
* @param formStyles - Styles for form
|
|
34
|
+
* @param buttonWrapperStyles - Styles for button wrapper
|
|
35
|
+
* @param preFillValues - Object containing pre-fill values
|
|
36
|
+
* @param formAdornments - Object containing form adornments
|
|
32
37
|
*/
|
|
33
38
|
declare const Form: CraftFC<FormProps>;
|
|
34
39
|
export default Form;
|
|
@@ -1,200 +1,228 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import { useState as
|
|
3
|
-
import
|
|
4
|
-
import { T as
|
|
1
|
+
import { jsx as l, jsxs as E } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef as X, useState as O, useRef as _, useCallback as V, useEffect as Y, useImperativeHandle as Z } from "react";
|
|
3
|
+
import A from "../../cell/Button/index.js";
|
|
4
|
+
import { T as K } from "../../../index-c9c32237.js";
|
|
5
5
|
import d from "./Form.styles.js";
|
|
6
|
-
import { getLocalDateTime as
|
|
7
|
-
import
|
|
8
|
-
import { s as
|
|
9
|
-
import { B as
|
|
10
|
-
const
|
|
6
|
+
import { getLocalDateTime as C, createNestedObject as ee, deepMergeObjects as te } from "./Form.utils.js";
|
|
7
|
+
import se from "./FormInput.js";
|
|
8
|
+
import { s as re } from "../../../styled-78608e1f.js";
|
|
9
|
+
import { B as v } from "../../../Tooltip-e797a425.js";
|
|
10
|
+
const ne = re("div")({
|
|
11
11
|
marginTop: "0.75rem"
|
|
12
|
-
}),
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
t[e.name] = e.defaultValue || M[e.name] || "";
|
|
43
|
-
}), b(t), f([]);
|
|
44
|
-
}
|
|
45
|
-
function I() {
|
|
46
|
-
const t = [];
|
|
47
|
-
return i == null || i.forEach((e) => {
|
|
48
|
-
const { name: n, label: r, type: p, validation: s, required: a } = e, o = l[n], m = n;
|
|
49
|
-
if (s)
|
|
50
|
-
if (p === "number") {
|
|
51
|
-
const c = parseInt(o);
|
|
52
|
-
s.min && c < s.min && t.push({
|
|
53
|
-
field: m,
|
|
54
|
-
value: o,
|
|
55
|
-
message: s.invalid_message
|
|
56
|
-
}), s.max && c > s.max && t.push({
|
|
57
|
-
field: m,
|
|
58
|
-
value: o,
|
|
59
|
-
message: s.invalid_message
|
|
60
|
-
}), isNaN(c) && t.push({
|
|
61
|
-
field: m,
|
|
62
|
-
value: o,
|
|
63
|
-
message: "Invalid number"
|
|
64
|
-
});
|
|
12
|
+
}), he = X(
|
|
13
|
+
({
|
|
14
|
+
config: i,
|
|
15
|
+
submitText: B = "Submit",
|
|
16
|
+
handleSubmit: T,
|
|
17
|
+
handleInvalidData: h,
|
|
18
|
+
cancelText: R = "Cancel",
|
|
19
|
+
handleCancel: g,
|
|
20
|
+
onChange: a,
|
|
21
|
+
formStyles: k = {},
|
|
22
|
+
formWrapperStyles: I = {},
|
|
23
|
+
formFieldsWrapperStyles: M = {},
|
|
24
|
+
buttonWrapperStyles: N = {},
|
|
25
|
+
customFields: F = {},
|
|
26
|
+
preFillValues: x = {},
|
|
27
|
+
formAdornments: w = {}
|
|
28
|
+
}, D) => {
|
|
29
|
+
const [c, b] = O({}), [W, y] = O([]), S = _(null), j = _(null);
|
|
30
|
+
function q(t, e) {
|
|
31
|
+
b((r) => ({
|
|
32
|
+
...r,
|
|
33
|
+
[t]: e
|
|
34
|
+
})), a == null || a(t, e), y([]);
|
|
35
|
+
}
|
|
36
|
+
const H = V(() => {
|
|
37
|
+
const t = {};
|
|
38
|
+
i == null || i.forEach((e) => {
|
|
39
|
+
if (e.preFillWithDateTime && e.type === "text") {
|
|
40
|
+
const r = C();
|
|
41
|
+
t[e.name] = r, a == null || a(e.name, r);
|
|
65
42
|
} else
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
if (m.indexOf(".") !== -1) {
|
|
93
|
-
const c = Q(
|
|
94
|
-
m,
|
|
95
|
-
p,
|
|
96
|
-
l[r]
|
|
97
|
-
);
|
|
98
|
-
e = U(e, c);
|
|
43
|
+
t[e.name] = e.defaultValue || x[e.name] || "", a == null || a(
|
|
44
|
+
e.name,
|
|
45
|
+
e.defaultValue || x[e.name] || ""
|
|
46
|
+
);
|
|
47
|
+
}), b(t), y([]);
|
|
48
|
+
}, [x]);
|
|
49
|
+
function P() {
|
|
50
|
+
const t = [];
|
|
51
|
+
return i == null || i.forEach((e) => {
|
|
52
|
+
const { name: r, label: n, type: p, validation: s, required: u } = e, m = c[r], o = r;
|
|
53
|
+
if (s)
|
|
54
|
+
if (p === "number") {
|
|
55
|
+
const f = parseInt(m);
|
|
56
|
+
s.min && f < s.min && t.push({
|
|
57
|
+
field: o,
|
|
58
|
+
value: m,
|
|
59
|
+
message: s.invalid_message
|
|
60
|
+
}), s.max && f > s.max && t.push({
|
|
61
|
+
field: o,
|
|
62
|
+
value: m,
|
|
63
|
+
message: s.invalid_message
|
|
64
|
+
}), isNaN(f) && t.push({
|
|
65
|
+
field: o,
|
|
66
|
+
value: m,
|
|
67
|
+
message: "Invalid number"
|
|
68
|
+
});
|
|
99
69
|
} else
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
70
|
+
p === "text" && (s.min_length && m.length < s.min_length && t.push({
|
|
71
|
+
field: o,
|
|
72
|
+
value: m,
|
|
73
|
+
message: s.invalid_message
|
|
74
|
+
}), s.max_length && m.length > s.max_length && t.push({
|
|
75
|
+
field: o,
|
|
76
|
+
value: m,
|
|
77
|
+
message: s.invalid_message
|
|
78
|
+
}), s.pattern && !new RegExp(s.pattern).test(m) && t.push({
|
|
79
|
+
field: o,
|
|
80
|
+
value: m,
|
|
81
|
+
message: s.invalid_message
|
|
82
|
+
}));
|
|
83
|
+
u && !m && t.push({
|
|
84
|
+
field: o,
|
|
85
|
+
value: m,
|
|
86
|
+
message: `${n} is required`
|
|
87
|
+
});
|
|
88
|
+
}), y(t), t.length && (h == null || h(t)), !t.length;
|
|
113
89
|
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
90
|
+
const $ = V(
|
|
91
|
+
(t) => {
|
|
92
|
+
let e = {};
|
|
93
|
+
return t == null || t.forEach((r) => {
|
|
94
|
+
const { name: n, type: p, submitDataKey: s } = r, u = p === "number" ? parseInt(c[n]) : c[n];
|
|
95
|
+
function m(o) {
|
|
96
|
+
if (o.indexOf(".") !== -1) {
|
|
97
|
+
const f = ee(
|
|
98
|
+
o,
|
|
99
|
+
p,
|
|
100
|
+
c[n]
|
|
101
|
+
);
|
|
102
|
+
e = te(
|
|
103
|
+
e,
|
|
104
|
+
f
|
|
105
|
+
);
|
|
106
|
+
} else
|
|
107
|
+
e[o] = u;
|
|
108
|
+
}
|
|
109
|
+
typeof s != "string" && (s != null && s.length) ? s.forEach((o) => {
|
|
110
|
+
m(o);
|
|
111
|
+
}) : typeof s == "string" && s ? m(s) : e[n] = u;
|
|
112
|
+
}), e;
|
|
113
|
+
},
|
|
114
|
+
[c]
|
|
115
|
+
);
|
|
116
|
+
function L(t) {
|
|
117
|
+
if (t.preventDefault(), P()) {
|
|
118
|
+
const r = $(i);
|
|
119
|
+
T(r);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
function z() {
|
|
123
|
+
b((t) => {
|
|
124
|
+
const e = { ...t };
|
|
125
|
+
return Object.keys(e).forEach((r) => {
|
|
126
|
+
e[r] = "";
|
|
127
|
+
}), e;
|
|
128
|
+
}), g == null || g();
|
|
129
|
+
}
|
|
130
|
+
function G(t) {
|
|
131
|
+
const e = W.find(
|
|
132
|
+
(n) => n.field === t.name
|
|
133
|
+
), r = {
|
|
134
|
+
...t,
|
|
135
|
+
value: c[t.name],
|
|
136
|
+
handleChange: q,
|
|
137
|
+
error: !!e,
|
|
138
|
+
helperText: e == null ? void 0 : e.message,
|
|
139
|
+
inputAdornments: w[t.name] || {}
|
|
135
140
|
};
|
|
136
|
-
if (
|
|
137
|
-
return
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
const
|
|
152
|
-
|
|
141
|
+
if (t.hidden)
|
|
142
|
+
return null;
|
|
143
|
+
if (t.type === "custom" && t.customComponent && F[t.customComponent]) {
|
|
144
|
+
const { component: n, props: p } = F[t.customComponent], s = n, u = {
|
|
145
|
+
...r,
|
|
146
|
+
...p
|
|
147
|
+
};
|
|
148
|
+
if (s && u)
|
|
149
|
+
return /* @__PURE__ */ l(s, { ...u }, t.name);
|
|
150
|
+
} else
|
|
151
|
+
return /* @__PURE__ */ l(se, { ...r }, t.name);
|
|
152
|
+
}
|
|
153
|
+
function J() {
|
|
154
|
+
return i.reduce(
|
|
155
|
+
(e, r) => {
|
|
156
|
+
const { groupName: n } = r;
|
|
157
|
+
if (!e.length)
|
|
158
|
+
e.push(n ? [n, r] : [r]);
|
|
159
|
+
else if (n) {
|
|
160
|
+
const s = e.findIndex((u) => u[0] === n);
|
|
161
|
+
s === -1 ? e.push([n, r]) : e[s].push(r);
|
|
162
|
+
} else {
|
|
163
|
+
const s = e[e.length - 1];
|
|
164
|
+
typeof s[0] == "string" ? e.push([r]) : s.push(r);
|
|
165
|
+
}
|
|
166
|
+
return e;
|
|
167
|
+
},
|
|
168
|
+
[]
|
|
169
|
+
).map(
|
|
170
|
+
(e) => {
|
|
171
|
+
const r = typeof e[0] == "string";
|
|
172
|
+
return /* @__PURE__ */ l(
|
|
173
|
+
ne,
|
|
174
|
+
{
|
|
175
|
+
children: e.map((n) => typeof n == "string" ? /* @__PURE__ */ l(
|
|
176
|
+
K,
|
|
177
|
+
{
|
|
178
|
+
type: "headingSmall",
|
|
179
|
+
sx: d.heading,
|
|
180
|
+
children: n
|
|
181
|
+
},
|
|
182
|
+
n
|
|
183
|
+
) : G(n))
|
|
184
|
+
},
|
|
185
|
+
`group-${r ? e[0] : e[0].name}`
|
|
186
|
+
);
|
|
153
187
|
}
|
|
154
|
-
|
|
155
|
-
|
|
188
|
+
);
|
|
189
|
+
}
|
|
190
|
+
Y(() => {
|
|
191
|
+
H();
|
|
192
|
+
}, []);
|
|
193
|
+
const Q = {
|
|
194
|
+
...d.alignVertical,
|
|
195
|
+
...k
|
|
196
|
+
}, U = {
|
|
197
|
+
...d.alignVertical,
|
|
198
|
+
marginTop: "1rem",
|
|
199
|
+
gap: "0.5rem",
|
|
200
|
+
...N
|
|
201
|
+
};
|
|
202
|
+
return Z(
|
|
203
|
+
D,
|
|
204
|
+
() => ({
|
|
205
|
+
submitButtonRef: S,
|
|
206
|
+
cancelButtonRef: j
|
|
207
|
+
}),
|
|
156
208
|
[]
|
|
157
|
-
)
|
|
158
|
-
(
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
209
|
+
), /* @__PURE__ */ l(v, { sx: I, children: /* @__PURE__ */ E("form", { style: Q, children: [
|
|
210
|
+
/* @__PURE__ */ l(v, { sx: M, children: Object.keys(c).length && J() }),
|
|
211
|
+
/* @__PURE__ */ E(v, { sx: U, children: [
|
|
212
|
+
/* @__PURE__ */ l(
|
|
213
|
+
A,
|
|
162
214
|
{
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
},
|
|
173
|
-
`group-${n ? e[0] : e[0].name}`
|
|
174
|
-
);
|
|
175
|
-
}
|
|
176
|
-
);
|
|
215
|
+
ref: S,
|
|
216
|
+
type: "submit",
|
|
217
|
+
onClick: L,
|
|
218
|
+
children: B
|
|
219
|
+
}
|
|
220
|
+
),
|
|
221
|
+
/* @__PURE__ */ l(A, { ref: j, onClick: z, children: R })
|
|
222
|
+
] })
|
|
223
|
+
] }) });
|
|
177
224
|
}
|
|
178
|
-
|
|
179
|
-
F();
|
|
180
|
-
}, []);
|
|
181
|
-
const H = {
|
|
182
|
-
...d.alignVertical,
|
|
183
|
-
...A
|
|
184
|
-
}, L = {
|
|
185
|
-
...d.alignVertical,
|
|
186
|
-
marginTop: "1rem",
|
|
187
|
-
gap: "0.5rem",
|
|
188
|
-
...B
|
|
189
|
-
};
|
|
190
|
-
return /* @__PURE__ */ u(x, { sx: C, children: /* @__PURE__ */ v("form", { style: H, children: [
|
|
191
|
-
/* @__PURE__ */ u(x, { sx: T, children: Object.keys(l).length && w() }),
|
|
192
|
-
/* @__PURE__ */ v(x, { sx: L, children: [
|
|
193
|
-
/* @__PURE__ */ u(j, { type: "submit", onClick: q, children: V }),
|
|
194
|
-
/* @__PURE__ */ u(j, { onClick: P, children: E })
|
|
195
|
-
] })
|
|
196
|
-
] }) });
|
|
197
|
-
};
|
|
225
|
+
);
|
|
198
226
|
export {
|
|
199
|
-
|
|
227
|
+
he as default
|
|
200
228
|
};
|