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 a } from "react/jsx-runtime";
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 l } from "react";
4
- import { FormContext as f } from "../FormContext/FormContext.js";
5
- import { FormItem as i } from "../FormItem/FormItem.js";
6
- import { useForm as p } from "../useForm/useForm.js";
7
- const v = ({ form: m, children: c, onFinish: t, disabled: e = !1 }) => {
8
- const n = p()[0], s = l(() => {
9
- const r = m || n;
10
- return r.disabled = e, r;
11
- }, [m, n, e]), u = async (r) => {
12
- r.preventDefault();
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 o = await s.validateFields();
16
- t == null || t(o);
17
- } catch (o) {
18
- throw console.error("Form submission error:", o), o;
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__ */ a(f.Provider, { value: s || null, children: /* @__PURE__ */ a("form", { onSubmit: u, children: c }) });
26
+ return /* @__PURE__ */ c(p.Provider, { value: m || null, children: /* @__PURE__ */ c("form", { onSubmit: f, children: s }) });
22
27
  };
23
- v.Item = i;
28
+ w.Item = d;
24
29
  export {
25
- v as Form
30
+ w as Form
26
31
  };
@@ -1,6 +1,7 @@
1
1
  import { Form as m } from "./FormRoot/FormRoot.js";
2
- import { useForm as f } from "./useForm/useForm.js";
2
+ import { FormValidationError as t, useForm as F } from "./useForm/useForm.js";
3
3
  export {
4
4
  m as Form,
5
- f as useForm
5
+ t as FormValidationError,
6
+ F as useForm
6
7
  };
@@ -1,4 +1,5 @@
1
- import { useForm as e } from "./useForm.js";
1
+ import { FormValidationError as m, useForm as a } from "./useForm.js";
2
2
  export {
3
- e as useForm
3
+ m as FormValidationError,
4
+ a as useForm
4
5
  };
@@ -1,33 +1,37 @@
1
- import { useRef as y, useCallback as g } from "react";
2
- import { normalizePath as i, validateRule as b, getFieldKey as f, getByPath as k, getNestedValue as V, setByPath as v } from "../utils/fn.js";
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(l) {
5
- super("Form validation failed"), this.errorFields = l, this.name = "FormValidationError";
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 N() {
9
- const a = y({}), l = y({}), p = y({}), o = y({}), d = g((t) => {
10
- const r = i(t), e = /* @__PURE__ */ new Set();
11
- e.add(r.join("."));
12
- for (let n = 1; n < r.length; n++)
13
- e.add(r.slice(0, n).join("."));
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 = g(
19
- async (t, r, e) => {
22
+ }, []), m = F(
23
+ async (r, t, e) => {
20
24
  if (!e) return [];
21
- const n = (await Promise.all(e.map((c) => b(c, r)))).filter(Boolean), s = f(t);
22
- return l.current[s] = n, d(s), n;
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 = g(
26
- async (t) => {
27
- const r = t || Object.keys(p.current).map((n) => n.includes(".") ? n.split(".") : n), e = {};
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
- r.map(async (n) => {
30
- const s = i(n), c = f(s), u = p.current[c] || [], F = k(a.current, s), h = await m(s, F, u);
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 = (t) => Array.isArray(t) ? t : typeof t == "string" && t.includes(".") ? t.split(".") : [t], j = y({
47
+ ), E = (r) => Array.isArray(r) ? r : typeof r == "string" && r.includes(".") ? r.split(".") : [r], j = y({
44
48
  resetFields: () => {
45
- a.current = {}, l.current = {}, Object.keys(o.current).forEach(d);
49
+ a.current = {}, i.current = {}, Object.keys(o.current).forEach(d);
46
50
  },
47
- setFieldsValue: (t) => {
48
- const r = { ...a.current };
49
- Object.entries(t).forEach(([e, n]) => {
51
+ setFieldsValue: (r) => {
52
+ const t = { ...a.current };
53
+ Object.entries(r).forEach(([e, n]) => {
50
54
  const s = E(e);
51
- v(r, s, n);
52
- }), a.current = r, Object.keys(t).forEach((e) => {
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: (t, r) => {
57
- const e = i(t), n = JSON.parse(JSON.stringify(a.current));
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 u = e[c];
61
- s[u] || (s[u] = {}), s = s[u];
64
+ const l = e[c];
65
+ s[l] || (s[l] = {}), s = s[l];
62
66
  }
63
- s[e[e.length - 1]] = r, a.current = n, d(e);
67
+ s[e[e.length - 1]] = t, a.current = n, d(e);
64
68
  },
65
- getFieldValue: (t) => {
66
- const r = i(t);
67
- return V(a.current, r);
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: (t) => {
75
- const r = f(i(t));
76
- return l.current[r] || [];
78
+ getFieldError: (r) => {
79
+ const t = f(u(r));
80
+ return i.current[t] || [];
77
81
  },
78
- setFieldError: (t, r) => {
79
- const e = f(i(t));
80
- l.current[e] = r, d(e);
82
+ setFieldError: (r, t) => {
83
+ const e = f(u(r));
84
+ i.current[e] = t, d(e);
81
85
  },
82
- getFieldRules: (t) => {
83
- const r = f(i(t));
84
- return p.current[r] || [];
86
+ getFieldRules: (r) => {
87
+ const t = f(u(r));
88
+ return p.current[t] || [];
85
89
  },
86
- setFieldRules: (t, r) => {
87
- const e = f(i(t));
88
- p.current[e] = r;
90
+ setFieldRules: (r, t) => {
91
+ const e = f(u(r));
92
+ p.current[e] = t;
89
93
  },
90
- subscribe: (t, r) => {
91
- const e = i(t), n = e.join(".");
92
- if (o.current[n] || (o.current[n] = /* @__PURE__ */ new Set()), o.current[n].add(r), e.length > 1) {
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 u = () => r();
96
- return o.current[c].add(u), () => {
97
- var F, h;
98
- (F = o.current[n]) == null || F.delete(r), (h = o.current[c]) == null || h.delete(u);
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(r);
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
- N as useForm
114
+ O as FormValidationError,
115
+ S as useForm
111
116
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "triafly-ui-kit",
3
- "version": "1.0.52",
3
+ "version": "1.0.53",
4
4
  "description": "UI Kit from Triafly",
5
5
  "main": "./dist/main.js",
6
6
  "module": "./dist/main.js",