triafly-ui-kit 1.0.53 → 1.0.54
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,27 @@
|
|
1
1
|
import { jsx as c } from "react/jsx-runtime";
|
2
2
|
import '../../../../assets/src/components/Ui/Form/FormRoot/Form.css';/* empty css */
|
3
|
-
import { useMemo as
|
4
|
-
import { FormContext as
|
5
|
-
import { FormItem as
|
6
|
-
import { useForm as
|
7
|
-
const
|
8
|
-
const
|
9
|
-
const t =
|
3
|
+
import { useMemo as s } from "react";
|
4
|
+
import { FormContext as u } from "../FormContext/FormContext.js";
|
5
|
+
import { FormItem as i } from "../FormItem/FormItem.js";
|
6
|
+
import { useForm as p, FormValidationError as d } from "../useForm/useForm.js";
|
7
|
+
const v = ({ form: m, children: f, onFinish: o, disabled: e = !1 }) => {
|
8
|
+
const a = p()[0], n = s(() => {
|
9
|
+
const t = m || a;
|
10
10
|
return t.disabled = e, t;
|
11
|
-
}, [
|
11
|
+
}, [m, a, e]), l = async (t) => {
|
12
12
|
t.preventDefault();
|
13
13
|
try {
|
14
14
|
if (e) return;
|
15
|
-
const r = await
|
15
|
+
const r = await n.validateFields();
|
16
16
|
await (o == null ? void 0 : o(r));
|
17
17
|
} catch (r) {
|
18
|
-
if (r instanceof
|
19
|
-
|
20
|
-
m.setFieldError(l, i);
|
21
|
-
});
|
22
|
-
else
|
23
|
-
throw r;
|
18
|
+
if (r instanceof d)
|
19
|
+
throw console.error(r), r;
|
24
20
|
}
|
25
21
|
};
|
26
|
-
return /* @__PURE__ */ c(
|
22
|
+
return /* @__PURE__ */ c(u.Provider, { value: n || null, children: /* @__PURE__ */ c("form", { onSubmit: l, children: f }) });
|
27
23
|
};
|
28
|
-
|
24
|
+
v.Item = i;
|
29
25
|
export {
|
30
|
-
|
26
|
+
v as Form
|
31
27
|
};
|
@@ -1,105 +1,114 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
var k = Object.defineProperty;
|
2
|
+
var O = (c, u, i) => u in c ? k(c, u, { enumerable: !0, configurable: !0, writable: !0, value: i }) : c[u] = i;
|
3
|
+
var b = (c, u, i) => O(c, typeof u != "symbol" ? u + "" : u, i);
|
4
|
+
import { useRef as y, useCallback as m } from "react";
|
5
|
+
import { normalizePath as l, validateRule as V, getFieldKey as h, getByPath as v, getNestedValue as P, setByPath as R } from "../utils/fn.js";
|
6
|
+
class S extends Error {
|
7
|
+
// { fieldName: "error1, error2" }
|
4
8
|
constructor(i) {
|
5
|
-
super("Form validation failed")
|
9
|
+
super("Form validation failed");
|
10
|
+
b(this, "errorMap");
|
11
|
+
this.errors = i, this.name = "FormValidationError", this.errorMap = i.reduce(
|
12
|
+
(o, { name: d, errors: g }) => (o[d] = g.join(", "), o),
|
13
|
+
{}
|
14
|
+
);
|
6
15
|
}
|
7
16
|
toString() {
|
8
|
-
return this.
|
17
|
+
return Object.entries(this.errorMap).map(([i, o]) => `${i}: ${o}`).join(`
|
9
18
|
`);
|
10
19
|
}
|
11
20
|
}
|
12
|
-
function
|
13
|
-
const
|
14
|
-
const t =
|
21
|
+
function B() {
|
22
|
+
const c = y({}), u = y({}), i = y({}), o = y({}), d = m((r) => {
|
23
|
+
const t = l(r), e = /* @__PURE__ */ new Set();
|
15
24
|
e.add(t.join("."));
|
16
25
|
for (let n = 1; n < t.length; n++)
|
17
26
|
e.add(t.slice(0, n).join("."));
|
18
27
|
e.forEach((n) => {
|
19
28
|
var s;
|
20
|
-
(s = o.current[n]) == null || s.forEach((
|
29
|
+
(s = o.current[n]) == null || s.forEach((a) => a());
|
21
30
|
});
|
22
|
-
}, []),
|
31
|
+
}, []), g = m(
|
23
32
|
async (r, t, e) => {
|
24
33
|
if (!e) return [];
|
25
|
-
const n = (await Promise.all(e.map((
|
26
|
-
return
|
34
|
+
const n = (await Promise.all(e.map((a) => V(a, t)))).filter(Boolean), s = h(r);
|
35
|
+
return u.current[s] = n, d(s), n;
|
27
36
|
},
|
28
37
|
[d]
|
29
|
-
), w =
|
38
|
+
), w = m(
|
30
39
|
async (r) => {
|
31
|
-
const t = r || Object.keys(
|
40
|
+
const t = r || Object.keys(i.current).map((n) => n.includes(".") ? n.split(".") : n), e = {};
|
32
41
|
if (await Promise.all(
|
33
42
|
t.map(async (n) => {
|
34
|
-
const s =
|
35
|
-
|
43
|
+
const s = l(n), a = h(s), f = i.current[a] || [], F = v(c.current, s), p = await g(s, F, f);
|
44
|
+
p.length && (e[a] = p);
|
36
45
|
})
|
37
46
|
), Object.keys(e).length)
|
38
|
-
throw new
|
47
|
+
throw new S(
|
39
48
|
Object.entries(e).map(([n, s]) => ({
|
40
49
|
name: n,
|
41
50
|
errors: s
|
42
51
|
}))
|
43
52
|
);
|
44
|
-
return { ...
|
53
|
+
return { ...c.current };
|
45
54
|
},
|
46
|
-
[
|
55
|
+
[g]
|
47
56
|
), E = (r) => Array.isArray(r) ? r : typeof r == "string" && r.includes(".") ? r.split(".") : [r], j = y({
|
48
57
|
resetFields: () => {
|
49
|
-
|
58
|
+
c.current = {}, u.current = {}, Object.keys(o.current).forEach(d);
|
50
59
|
},
|
51
60
|
setFieldsValue: (r) => {
|
52
|
-
const t = { ...
|
61
|
+
const t = { ...c.current };
|
53
62
|
Object.entries(r).forEach(([e, n]) => {
|
54
63
|
const s = E(e);
|
55
|
-
|
56
|
-
}),
|
64
|
+
R(t, s, n);
|
65
|
+
}), c.current = t, Object.keys(r).forEach((e) => {
|
57
66
|
d(Array.isArray(e) ? e.join(".") : e);
|
58
67
|
});
|
59
68
|
},
|
60
69
|
setFieldValue: (r, t) => {
|
61
|
-
const e =
|
70
|
+
const e = l(r), n = JSON.parse(JSON.stringify(c.current));
|
62
71
|
let s = n;
|
63
|
-
for (let
|
64
|
-
const
|
65
|
-
s[
|
72
|
+
for (let a = 0; a < e.length - 1; a++) {
|
73
|
+
const f = e[a];
|
74
|
+
s[f] || (s[f] = {}), s = s[f];
|
66
75
|
}
|
67
|
-
s[e[e.length - 1]] = t,
|
76
|
+
s[e[e.length - 1]] = t, c.current = n, d(e);
|
68
77
|
},
|
69
78
|
getFieldValue: (r) => {
|
70
|
-
const t =
|
71
|
-
return
|
79
|
+
const t = l(r);
|
80
|
+
return P(c.current, t);
|
72
81
|
},
|
73
|
-
getFieldsValue: () => ({ ...
|
82
|
+
getFieldsValue: () => ({ ...c.current }),
|
74
83
|
submit: async () => {
|
75
84
|
await j.validateFields();
|
76
85
|
},
|
77
86
|
validateFields: w,
|
78
87
|
getFieldError: (r) => {
|
79
|
-
const t =
|
80
|
-
return
|
88
|
+
const t = h(l(r));
|
89
|
+
return u.current[t] || [];
|
81
90
|
},
|
82
91
|
setFieldError: (r, t) => {
|
83
|
-
const e =
|
84
|
-
|
92
|
+
const e = h(l(r));
|
93
|
+
u.current[e] = t, d(e);
|
85
94
|
},
|
86
95
|
getFieldRules: (r) => {
|
87
|
-
const t =
|
88
|
-
return
|
96
|
+
const t = h(l(r));
|
97
|
+
return i.current[t] || [];
|
89
98
|
},
|
90
99
|
setFieldRules: (r, t) => {
|
91
|
-
const e =
|
92
|
-
|
100
|
+
const e = h(l(r));
|
101
|
+
i.current[e] = t;
|
93
102
|
},
|
94
103
|
subscribe: (r, t) => {
|
95
|
-
const e =
|
104
|
+
const e = l(r), n = e.join(".");
|
96
105
|
if (o.current[n] || (o.current[n] = /* @__PURE__ */ new Set()), o.current[n].add(t), e.length > 1) {
|
97
|
-
const
|
98
|
-
o.current[
|
99
|
-
const
|
100
|
-
return o.current[
|
101
|
-
var
|
102
|
-
(
|
106
|
+
const a = e.slice(0, -1).join(".");
|
107
|
+
o.current[a] || (o.current[a] = /* @__PURE__ */ new Set());
|
108
|
+
const f = () => t();
|
109
|
+
return o.current[a].add(f), () => {
|
110
|
+
var F, p;
|
111
|
+
(F = o.current[n]) == null || F.delete(t), (p = o.current[a]) == null || p.delete(f);
|
103
112
|
};
|
104
113
|
}
|
105
114
|
return () => {
|
@@ -111,6 +120,6 @@ function S() {
|
|
111
120
|
return [j];
|
112
121
|
}
|
113
122
|
export {
|
114
|
-
|
115
|
-
|
123
|
+
S as FormValidationError,
|
124
|
+
B as useForm
|
116
125
|
};
|