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 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";
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: 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();
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 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 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__ */ a(f.Provider, { value: s || null, children: /* @__PURE__ */ a("form", { onSubmit: u, children: c }) });
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 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,111 +1,125 @@
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";
3
- class O extends Error {
4
- constructor(l) {
5
- super("Form validation failed"), this.errorFields = l, this.name = "FormValidationError";
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 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("."));
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((c) => c());
29
+ (s = o.current[n]) == null || s.forEach((a) => a());
17
30
  });
18
- }, []), m = g(
19
- async (t, r, e) => {
31
+ }, []), g = m(
32
+ async (r, t, e) => {
20
33
  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;
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 = g(
26
- async (t) => {
27
- const r = t || Object.keys(p.current).map((n) => n.includes(".") ? n.split(".") : n), e = {};
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
- 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);
31
- h.length && (e[c] = h);
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 O(
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 { ...a.current };
53
+ return { ...c.current };
41
54
  },
42
- [m]
43
- ), E = (t) => Array.isArray(t) ? t : typeof t == "string" && t.includes(".") ? t.split(".") : [t], j = y({
55
+ [g]
56
+ ), E = (r) => Array.isArray(r) ? r : typeof r == "string" && r.includes(".") ? r.split(".") : [r], j = y({
44
57
  resetFields: () => {
45
- a.current = {}, l.current = {}, Object.keys(o.current).forEach(d);
58
+ c.current = {}, u.current = {}, Object.keys(o.current).forEach(d);
46
59
  },
47
- setFieldsValue: (t) => {
48
- const r = { ...a.current };
49
- Object.entries(t).forEach(([e, n]) => {
60
+ setFieldsValue: (r) => {
61
+ const t = { ...c.current };
62
+ Object.entries(r).forEach(([e, n]) => {
50
63
  const s = E(e);
51
- v(r, s, n);
52
- }), a.current = r, Object.keys(t).forEach((e) => {
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: (t, r) => {
57
- const e = i(t), n = JSON.parse(JSON.stringify(a.current));
69
+ setFieldValue: (r, t) => {
70
+ const e = l(r), n = JSON.parse(JSON.stringify(c.current));
58
71
  let s = n;
59
- for (let c = 0; c < e.length - 1; c++) {
60
- const u = e[c];
61
- s[u] || (s[u] = {}), s = s[u];
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]] = r, a.current = n, d(e);
76
+ s[e[e.length - 1]] = t, c.current = n, d(e);
64
77
  },
65
- getFieldValue: (t) => {
66
- const r = i(t);
67
- return V(a.current, r);
78
+ getFieldValue: (r) => {
79
+ const t = l(r);
80
+ return P(c.current, t);
68
81
  },
69
- getFieldsValue: () => ({ ...a.current }),
82
+ getFieldsValue: () => ({ ...c.current }),
70
83
  submit: async () => {
71
84
  await j.validateFields();
72
85
  },
73
86
  validateFields: w,
74
- getFieldError: (t) => {
75
- const r = f(i(t));
76
- return l.current[r] || [];
87
+ getFieldError: (r) => {
88
+ const t = h(l(r));
89
+ return u.current[t] || [];
77
90
  },
78
- setFieldError: (t, r) => {
79
- const e = f(i(t));
80
- l.current[e] = r, d(e);
91
+ setFieldError: (r, t) => {
92
+ const e = h(l(r));
93
+ u.current[e] = t, d(e);
81
94
  },
82
- getFieldRules: (t) => {
83
- const r = f(i(t));
84
- return p.current[r] || [];
95
+ getFieldRules: (r) => {
96
+ const t = h(l(r));
97
+ return i.current[t] || [];
85
98
  },
86
- setFieldRules: (t, r) => {
87
- const e = f(i(t));
88
- p.current[e] = r;
99
+ setFieldRules: (r, t) => {
100
+ const e = h(l(r));
101
+ i.current[e] = t;
89
102
  },
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) {
93
- const c = e.slice(0, -1).join(".");
94
- 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);
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(r);
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
- N as useForm
123
+ S as FormValidationError,
124
+ B as useForm
111
125
  };
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.54",
4
4
  "description": "UI Kit from Triafly",
5
5
  "main": "./dist/main.js",
6
6
  "module": "./dist/main.js",