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