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