@loopr-ai/craft 0.8.0 → 0.8.1
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.
|
@@ -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;
|
|
@@ -1,48 +1,48 @@
|
|
|
1
|
-
import { jsx as u, jsxs as
|
|
2
|
-
import { useState as
|
|
3
|
-
import
|
|
1
|
+
import { jsx as u, jsxs as j } from "react/jsx-runtime";
|
|
2
|
+
import { useState as v, useCallback as E, useEffect as z } from "react";
|
|
3
|
+
import O from "../../cell/Button/index.js";
|
|
4
4
|
import { T as G } from "../../../index-c9c32237.js";
|
|
5
|
-
import
|
|
5
|
+
import y from "./Form.styles.js";
|
|
6
6
|
import { getLocalDateTime as J, createNestedObject as Q, deepMergeObjects as U } from "./Form.utils.js";
|
|
7
7
|
import X from "./FormInput.js";
|
|
8
8
|
import { s as Y } from "../../../styled-78608e1f.js";
|
|
9
|
-
import { B as
|
|
9
|
+
import { B as b } from "../../../Tooltip-e797a425.js";
|
|
10
10
|
const Z = Y("div")({
|
|
11
11
|
marginTop: "0.75rem"
|
|
12
12
|
}), ie = ({
|
|
13
13
|
config: i,
|
|
14
|
-
submitText:
|
|
15
|
-
handleSubmit:
|
|
14
|
+
submitText: _ = "Submit",
|
|
15
|
+
handleSubmit: V,
|
|
16
16
|
handleInvalidData: h,
|
|
17
|
-
cancelText:
|
|
18
|
-
handleCancel:
|
|
19
|
-
onChange:
|
|
20
|
-
formStyles:
|
|
21
|
-
formWrapperStyles:
|
|
22
|
-
formFieldsWrapperStyles:
|
|
23
|
-
buttonWrapperStyles:
|
|
24
|
-
customFields:
|
|
25
|
-
preFillValues:
|
|
17
|
+
cancelText: A = "Cancel",
|
|
18
|
+
handleCancel: g,
|
|
19
|
+
onChange: f,
|
|
20
|
+
formStyles: T = {},
|
|
21
|
+
formWrapperStyles: B = {},
|
|
22
|
+
formFieldsWrapperStyles: k = {},
|
|
23
|
+
buttonWrapperStyles: M = {},
|
|
24
|
+
customFields: F = {},
|
|
25
|
+
preFillValues: S = {},
|
|
26
26
|
formAdornments: N = {}
|
|
27
27
|
}) => {
|
|
28
|
-
const [l,
|
|
28
|
+
const [l, x] = v({}), [C, d] = v([]);
|
|
29
29
|
function D(t, e) {
|
|
30
|
-
|
|
30
|
+
x((n) => ({
|
|
31
31
|
...n,
|
|
32
32
|
[t]: e
|
|
33
|
-
})),
|
|
33
|
+
})), f == null || f(t, e), d([]);
|
|
34
34
|
}
|
|
35
|
-
|
|
35
|
+
const I = E(() => {
|
|
36
36
|
const t = {};
|
|
37
37
|
i == null || i.forEach((e) => {
|
|
38
38
|
if (e.preFillWithDateTime && e.type === "text") {
|
|
39
39
|
const n = J();
|
|
40
40
|
t[e.name] = n;
|
|
41
41
|
} else
|
|
42
|
-
t[e.name] = e.defaultValue ||
|
|
43
|
-
}),
|
|
44
|
-
}
|
|
45
|
-
function
|
|
42
|
+
t[e.name] = e.defaultValue || S[e.name] || "";
|
|
43
|
+
}), x(t), d([]);
|
|
44
|
+
}, [S]);
|
|
45
|
+
function W() {
|
|
46
46
|
const t = [];
|
|
47
47
|
return i == null || i.forEach((e) => {
|
|
48
48
|
const { name: n, label: r, type: p, validation: s, required: a } = e, o = l[n], m = n;
|
|
@@ -81,9 +81,9 @@ const Z = Y("div")({
|
|
|
81
81
|
value: o,
|
|
82
82
|
message: `${r} is required`
|
|
83
83
|
});
|
|
84
|
-
}),
|
|
84
|
+
}), d(t), t.length && (h == null || h(t)), !t.length;
|
|
85
85
|
}
|
|
86
|
-
const
|
|
86
|
+
const q = E(
|
|
87
87
|
(t) => {
|
|
88
88
|
let e = {};
|
|
89
89
|
return t == null || t.forEach((n) => {
|
|
@@ -106,17 +106,22 @@ const Z = Y("div")({
|
|
|
106
106
|
},
|
|
107
107
|
[l]
|
|
108
108
|
);
|
|
109
|
-
function
|
|
110
|
-
if (t.preventDefault(),
|
|
111
|
-
const n =
|
|
112
|
-
|
|
109
|
+
function w(t) {
|
|
110
|
+
if (t.preventDefault(), W()) {
|
|
111
|
+
const n = q(i);
|
|
112
|
+
V(n);
|
|
113
113
|
}
|
|
114
114
|
}
|
|
115
115
|
function P() {
|
|
116
|
-
|
|
116
|
+
x((t) => {
|
|
117
|
+
const e = { ...t };
|
|
118
|
+
return Object.keys(e).forEach((n) => {
|
|
119
|
+
e[n] = "";
|
|
120
|
+
}), e;
|
|
121
|
+
}), g == null || g();
|
|
117
122
|
}
|
|
118
123
|
function $(t) {
|
|
119
|
-
const e =
|
|
124
|
+
const e = C.find(
|
|
120
125
|
(r) => r.field === t.name
|
|
121
126
|
), n = {
|
|
122
127
|
...t,
|
|
@@ -128,8 +133,8 @@ const Z = Y("div")({
|
|
|
128
133
|
};
|
|
129
134
|
if (t.hidden)
|
|
130
135
|
return null;
|
|
131
|
-
if (t.type === "custom" && t.customComponent &&
|
|
132
|
-
const { component: r, props: p } =
|
|
136
|
+
if (t.type === "custom" && t.customComponent && F[t.customComponent]) {
|
|
137
|
+
const { component: r, props: p } = F[t.customComponent], s = r, a = {
|
|
133
138
|
...n,
|
|
134
139
|
...p
|
|
135
140
|
};
|
|
@@ -138,7 +143,7 @@ const Z = Y("div")({
|
|
|
138
143
|
} else
|
|
139
144
|
return /* @__PURE__ */ u(X, { ...n }, t.name);
|
|
140
145
|
}
|
|
141
|
-
function
|
|
146
|
+
function H() {
|
|
142
147
|
return i.reduce(
|
|
143
148
|
(e, n) => {
|
|
144
149
|
const { groupName: r } = n;
|
|
@@ -164,7 +169,7 @@ const Z = Y("div")({
|
|
|
164
169
|
G,
|
|
165
170
|
{
|
|
166
171
|
type: "headingSmall",
|
|
167
|
-
sx:
|
|
172
|
+
sx: y.heading,
|
|
168
173
|
children: r
|
|
169
174
|
},
|
|
170
175
|
r
|
|
@@ -176,22 +181,22 @@ const Z = Y("div")({
|
|
|
176
181
|
);
|
|
177
182
|
}
|
|
178
183
|
z(() => {
|
|
179
|
-
|
|
184
|
+
I();
|
|
180
185
|
}, []);
|
|
181
|
-
const
|
|
182
|
-
...
|
|
183
|
-
...
|
|
184
|
-
},
|
|
185
|
-
...
|
|
186
|
+
const L = {
|
|
187
|
+
...y.alignVertical,
|
|
188
|
+
...T
|
|
189
|
+
}, R = {
|
|
190
|
+
...y.alignVertical,
|
|
186
191
|
marginTop: "1rem",
|
|
187
192
|
gap: "0.5rem",
|
|
188
|
-
...
|
|
193
|
+
...M
|
|
189
194
|
};
|
|
190
|
-
return /* @__PURE__ */ u(
|
|
191
|
-
/* @__PURE__ */ u(
|
|
192
|
-
/* @__PURE__ */
|
|
193
|
-
/* @__PURE__ */ u(
|
|
194
|
-
/* @__PURE__ */ u(
|
|
195
|
+
return /* @__PURE__ */ u(b, { sx: B, children: /* @__PURE__ */ j("form", { style: L, children: [
|
|
196
|
+
/* @__PURE__ */ u(b, { sx: k, children: Object.keys(l).length && H() }),
|
|
197
|
+
/* @__PURE__ */ j(b, { sx: R, children: [
|
|
198
|
+
/* @__PURE__ */ u(O, { type: "submit", onClick: w, children: _ }),
|
|
199
|
+
/* @__PURE__ */ u(O, { onClick: P, children: A })
|
|
195
200
|
] })
|
|
196
201
|
] }) });
|
|
197
202
|
};
|