@loopr-ai/craft 0.7.3 → 0.7.4
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.
|
@@ -11,6 +11,8 @@ interface FormProps {
|
|
|
11
11
|
handleCancel: () => void;
|
|
12
12
|
onChange?: (key: string, value: string) => void;
|
|
13
13
|
customFields?: CustomFields;
|
|
14
|
+
formWrapperStyles?: SxProps;
|
|
15
|
+
formFieldsWrapperStyles?: SxProps;
|
|
14
16
|
formStyles?: React.CSSProperties;
|
|
15
17
|
buttonWrapperStyles?: SxProps;
|
|
16
18
|
}
|
|
@@ -1,134 +1,136 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { useState as
|
|
3
|
-
import
|
|
4
|
-
import { T as
|
|
5
|
-
import
|
|
6
|
-
import { createNestedObject as
|
|
7
|
-
import
|
|
8
|
-
import { s as
|
|
9
|
-
import { B as
|
|
10
|
-
const
|
|
1
|
+
import { jsx as u, jsxs as j } from "react/jsx-runtime";
|
|
2
|
+
import { useState as v, useCallback as H, useEffect as K } from "react";
|
|
3
|
+
import S from "../../cell/Button/index.js";
|
|
4
|
+
import { T as L } from "../../../index-03287c17.js";
|
|
5
|
+
import f from "./Form.styles.js";
|
|
6
|
+
import { createNestedObject as R, deepMergeObjects as z, getLocalDateTime as G } from "./Form.utils.js";
|
|
7
|
+
import J from "./FormInput.js";
|
|
8
|
+
import { s as Q } from "../../../styled-126c6a62.js";
|
|
9
|
+
import { B as b } from "../../../Tooltip-b926c320.js";
|
|
10
|
+
const U = Q("div")({
|
|
11
11
|
marginTop: "0.75rem"
|
|
12
|
-
}),
|
|
12
|
+
}), oe = ({
|
|
13
13
|
config: o,
|
|
14
|
-
submitText:
|
|
15
|
-
handleSubmit:
|
|
14
|
+
submitText: V = "Submit",
|
|
15
|
+
handleSubmit: _,
|
|
16
16
|
handleInvalidData: c,
|
|
17
|
-
cancelText:
|
|
18
|
-
handleCancel:
|
|
17
|
+
cancelText: C = "Cancel",
|
|
18
|
+
handleCancel: E,
|
|
19
19
|
onChange: h,
|
|
20
|
-
formStyles:
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
formStyles: O = {},
|
|
21
|
+
formWrapperStyles: T = {},
|
|
22
|
+
formFieldsWrapperStyles: A = {},
|
|
23
|
+
buttonWrapperStyles: D = {},
|
|
24
|
+
customFields: x = {}
|
|
23
25
|
}) => {
|
|
24
|
-
const [
|
|
25
|
-
function
|
|
26
|
+
const [p, y] = v({}), [B, g] = v([]);
|
|
27
|
+
function M(e, t) {
|
|
26
28
|
y((n) => ({
|
|
27
29
|
...n,
|
|
28
30
|
[e]: t
|
|
29
31
|
})), h == null || h(e, t), g([]);
|
|
30
32
|
}
|
|
31
|
-
function
|
|
33
|
+
function F() {
|
|
32
34
|
const e = {};
|
|
33
35
|
o == null || o.forEach((t) => {
|
|
34
36
|
if (t.preFillWithDateTime && t.type === "text") {
|
|
35
|
-
const n =
|
|
37
|
+
const n = G();
|
|
36
38
|
e[t.name] = n;
|
|
37
39
|
} else
|
|
38
40
|
e[t.name] = t.defaultValue || "";
|
|
39
41
|
}), y(e), g([]);
|
|
40
42
|
}
|
|
41
|
-
function
|
|
43
|
+
function N() {
|
|
42
44
|
const e = [];
|
|
43
45
|
return o == null || o.forEach((t) => {
|
|
44
|
-
const { name: n, label: r, type: a, validation: s, required: i } = t, m =
|
|
46
|
+
const { name: n, label: r, type: a, validation: s, required: i } = t, m = p[n], l = n;
|
|
45
47
|
if (s)
|
|
46
48
|
if (a === "number") {
|
|
47
|
-
const
|
|
48
|
-
s.min &&
|
|
49
|
-
field:
|
|
49
|
+
const d = parseInt(m);
|
|
50
|
+
s.min && d < s.min && e.push({
|
|
51
|
+
field: l,
|
|
50
52
|
value: m,
|
|
51
53
|
message: s.invalid_message
|
|
52
|
-
}), s.max &&
|
|
53
|
-
field:
|
|
54
|
+
}), s.max && d > s.max && e.push({
|
|
55
|
+
field: l,
|
|
54
56
|
value: m,
|
|
55
57
|
message: s.invalid_message
|
|
56
|
-
}), isNaN(
|
|
57
|
-
field:
|
|
58
|
+
}), isNaN(d) && e.push({
|
|
59
|
+
field: l,
|
|
58
60
|
value: m,
|
|
59
61
|
message: "Invalid number"
|
|
60
62
|
});
|
|
61
63
|
} else
|
|
62
64
|
a === "text" && (s.min_length && m.length < s.min_length && e.push({
|
|
63
|
-
field:
|
|
65
|
+
field: l,
|
|
64
66
|
value: m,
|
|
65
67
|
message: s.invalid_message
|
|
66
68
|
}), s.max_length && m.length > s.max_length && e.push({
|
|
67
|
-
field:
|
|
69
|
+
field: l,
|
|
68
70
|
value: m,
|
|
69
71
|
message: s.invalid_message
|
|
70
72
|
}), s.pattern && !new RegExp(s.pattern).test(m) && e.push({
|
|
71
|
-
field:
|
|
73
|
+
field: l,
|
|
72
74
|
value: m,
|
|
73
75
|
message: s.invalid_message
|
|
74
76
|
}));
|
|
75
77
|
i && !m && e.push({
|
|
76
|
-
field:
|
|
78
|
+
field: l,
|
|
77
79
|
value: m,
|
|
78
80
|
message: `${r} is required`
|
|
79
81
|
});
|
|
80
82
|
}), g(e), e.length && (c == null || c(e)), !e.length;
|
|
81
83
|
}
|
|
82
|
-
const
|
|
84
|
+
const k = H(
|
|
83
85
|
(e) => {
|
|
84
86
|
let t = {};
|
|
85
87
|
return e == null || e.forEach((n) => {
|
|
86
88
|
const { name: r, type: a, submitDataKey: s } = n;
|
|
87
89
|
if (s) {
|
|
88
|
-
const i =
|
|
90
|
+
const i = R(
|
|
89
91
|
s,
|
|
90
92
|
a,
|
|
91
|
-
|
|
93
|
+
p[r]
|
|
92
94
|
);
|
|
93
|
-
t =
|
|
95
|
+
t = z(t, i);
|
|
94
96
|
} else
|
|
95
|
-
t[r] = a === "number" ? parseInt(
|
|
97
|
+
t[r] = a === "number" ? parseInt(p[r]) : p[r];
|
|
96
98
|
}), t;
|
|
97
99
|
},
|
|
98
|
-
[
|
|
100
|
+
[p]
|
|
99
101
|
);
|
|
100
|
-
function
|
|
101
|
-
if (e.preventDefault(),
|
|
102
|
-
const n =
|
|
103
|
-
|
|
102
|
+
function I(e) {
|
|
103
|
+
if (e.preventDefault(), N()) {
|
|
104
|
+
const n = k(o);
|
|
105
|
+
_(n);
|
|
104
106
|
}
|
|
105
107
|
}
|
|
106
|
-
function
|
|
107
|
-
|
|
108
|
+
function W() {
|
|
109
|
+
F(), E();
|
|
108
110
|
}
|
|
109
|
-
function
|
|
110
|
-
const t =
|
|
111
|
+
function q(e) {
|
|
112
|
+
const t = B.find(
|
|
111
113
|
(r) => r.field === e.name
|
|
112
114
|
), n = {
|
|
113
115
|
...e,
|
|
114
|
-
value:
|
|
115
|
-
handleChange:
|
|
116
|
+
value: p[e.name],
|
|
117
|
+
handleChange: M,
|
|
116
118
|
error: !!t,
|
|
117
119
|
helperText: t == null ? void 0 : t.message
|
|
118
120
|
};
|
|
119
121
|
if (e.hidden)
|
|
120
122
|
return null;
|
|
121
|
-
if (e.type === "custom" && e.customComponent &&
|
|
122
|
-
const { component: r, props: a } =
|
|
123
|
+
if (e.type === "custom" && e.customComponent && x[e.customComponent]) {
|
|
124
|
+
const { component: r, props: a } = x[e.customComponent], s = r, i = {
|
|
123
125
|
...n,
|
|
124
126
|
...a
|
|
125
127
|
};
|
|
126
128
|
if (s && i)
|
|
127
|
-
return /* @__PURE__ */
|
|
129
|
+
return /* @__PURE__ */ u(s, { ...i }, e.name);
|
|
128
130
|
} else
|
|
129
|
-
return /* @__PURE__ */
|
|
131
|
+
return /* @__PURE__ */ u(J, { ...n }, e.name);
|
|
130
132
|
}
|
|
131
|
-
function
|
|
133
|
+
function P() {
|
|
132
134
|
return o.reduce(
|
|
133
135
|
(t, n) => {
|
|
134
136
|
const { groupName: r } = n;
|
|
@@ -147,44 +149,44 @@ const J = z("div")({
|
|
|
147
149
|
).map(
|
|
148
150
|
(t) => {
|
|
149
151
|
const n = typeof t[0] == "string";
|
|
150
|
-
return /* @__PURE__ */
|
|
151
|
-
|
|
152
|
+
return /* @__PURE__ */ u(
|
|
153
|
+
U,
|
|
152
154
|
{
|
|
153
|
-
children: t.map((r) => typeof r == "string" ? /* @__PURE__ */
|
|
154
|
-
|
|
155
|
+
children: t.map((r) => typeof r == "string" ? /* @__PURE__ */ u(
|
|
156
|
+
L,
|
|
155
157
|
{
|
|
156
158
|
type: "headingSmall",
|
|
157
|
-
sx:
|
|
159
|
+
sx: f.heading,
|
|
158
160
|
children: r
|
|
159
161
|
},
|
|
160
162
|
r
|
|
161
|
-
) :
|
|
163
|
+
) : q(r))
|
|
162
164
|
},
|
|
163
165
|
`group-${n ? t[0] : t[0].name}`
|
|
164
166
|
);
|
|
165
167
|
}
|
|
166
168
|
);
|
|
167
169
|
}
|
|
168
|
-
|
|
169
|
-
|
|
170
|
+
K(() => {
|
|
171
|
+
F();
|
|
170
172
|
}, []);
|
|
171
|
-
const
|
|
172
|
-
...
|
|
173
|
-
...
|
|
174
|
-
},
|
|
175
|
-
...
|
|
173
|
+
const $ = {
|
|
174
|
+
...f.alignVertical,
|
|
175
|
+
...O
|
|
176
|
+
}, w = {
|
|
177
|
+
...f.alignVertical,
|
|
176
178
|
marginTop: "1rem",
|
|
177
179
|
gap: "0.5rem",
|
|
178
|
-
...
|
|
180
|
+
...D
|
|
179
181
|
};
|
|
180
|
-
return /* @__PURE__ */
|
|
181
|
-
Object.keys(
|
|
182
|
-
/* @__PURE__ */
|
|
183
|
-
/* @__PURE__ */
|
|
184
|
-
/* @__PURE__ */
|
|
182
|
+
return /* @__PURE__ */ u(b, { sx: T, children: /* @__PURE__ */ j("form", { style: $, children: [
|
|
183
|
+
/* @__PURE__ */ u(b, { sx: A, children: Object.keys(p).length && P() }),
|
|
184
|
+
/* @__PURE__ */ j(b, { sx: w, children: [
|
|
185
|
+
/* @__PURE__ */ u(S, { type: "submit", onClick: I, children: V }),
|
|
186
|
+
/* @__PURE__ */ u(S, { onClick: W, children: C })
|
|
185
187
|
] })
|
|
186
|
-
] });
|
|
188
|
+
] }) });
|
|
187
189
|
};
|
|
188
190
|
export {
|
|
189
|
-
|
|
191
|
+
oe as default
|
|
190
192
|
};
|