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