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 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;
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
- }, [a, n, e]), f = async (t) => {
11
+ }, [m, a, e]), l = async (t) => {
12
12
  t.preventDefault();
13
13
  try {
14
14
  if (e) return;
15
- const r = await m.validateFields();
15
+ const r = await n.validateFields();
16
16
  await (o == null ? void 0 : o(r));
17
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;
18
+ if (r instanceof d)
19
+ throw console.error(r), r;
24
20
  }
25
21
  };
26
- return /* @__PURE__ */ c(p.Provider, { value: m || null, children: /* @__PURE__ */ c("form", { onSubmit: f, children: s }) });
22
+ return /* @__PURE__ */ c(u.Provider, { value: n || null, children: /* @__PURE__ */ c("form", { onSubmit: l, children: f }) });
27
23
  };
28
- w.Item = d;
24
+ v.Item = i;
29
25
  export {
30
- w as Form
26
+ v as Form
31
27
  };
@@ -1,105 +1,114 @@
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
- class O extends Error {
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"), this.errors = i, this.name = "FormValidationError";
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.errors.map((i) => `${i.name}: ${i.errors.join(", ")}`).join(`
17
+ return Object.entries(this.errorMap).map(([i, o]) => `${i}: ${o}`).join(`
9
18
  `);
10
19
  }
11
20
  }
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();
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((c) => c());
29
+ (s = o.current[n]) == null || s.forEach((a) => a());
21
30
  });
22
- }, []), m = F(
31
+ }, []), g = m(
23
32
  async (r, t, e) => {
24
33
  if (!e) 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;
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 = F(
38
+ ), w = m(
30
39
  async (r) => {
31
- const t = r || Object.keys(p.current).map((n) => n.includes(".") ? n.split(".") : n), e = {};
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 = u(n), c = f(s), l = p.current[c] || [], g = k(a.current, s), h = await m(s, g, l);
35
- h.length && (e[c] = h);
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 O(
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 { ...a.current };
53
+ return { ...c.current };
45
54
  },
46
- [m]
55
+ [g]
47
56
  ), E = (r) => Array.isArray(r) ? r : typeof r == "string" && r.includes(".") ? r.split(".") : [r], j = y({
48
57
  resetFields: () => {
49
- a.current = {}, i.current = {}, Object.keys(o.current).forEach(d);
58
+ c.current = {}, u.current = {}, Object.keys(o.current).forEach(d);
50
59
  },
51
60
  setFieldsValue: (r) => {
52
- const t = { ...a.current };
61
+ const t = { ...c.current };
53
62
  Object.entries(r).forEach(([e, n]) => {
54
63
  const s = E(e);
55
- v(t, s, n);
56
- }), a.current = t, Object.keys(r).forEach((e) => {
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 = u(r), n = JSON.parse(JSON.stringify(a.current));
70
+ const e = l(r), n = JSON.parse(JSON.stringify(c.current));
62
71
  let s = n;
63
- for (let c = 0; c < e.length - 1; c++) {
64
- const l = e[c];
65
- s[l] || (s[l] = {}), s = s[l];
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, a.current = n, d(e);
76
+ s[e[e.length - 1]] = t, c.current = n, d(e);
68
77
  },
69
78
  getFieldValue: (r) => {
70
- const t = u(r);
71
- return V(a.current, t);
79
+ const t = l(r);
80
+ return P(c.current, t);
72
81
  },
73
- getFieldsValue: () => ({ ...a.current }),
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 = f(u(r));
80
- return i.current[t] || [];
88
+ const t = h(l(r));
89
+ return u.current[t] || [];
81
90
  },
82
91
  setFieldError: (r, t) => {
83
- const e = f(u(r));
84
- i.current[e] = t, d(e);
92
+ const e = h(l(r));
93
+ u.current[e] = t, d(e);
85
94
  },
86
95
  getFieldRules: (r) => {
87
- const t = f(u(r));
88
- return p.current[t] || [];
96
+ const t = h(l(r));
97
+ return i.current[t] || [];
89
98
  },
90
99
  setFieldRules: (r, t) => {
91
- const e = f(u(r));
92
- p.current[e] = t;
100
+ const e = h(l(r));
101
+ i.current[e] = t;
93
102
  },
94
103
  subscribe: (r, t) => {
95
- const e = u(r), n = e.join(".");
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 c = e.slice(0, -1).join(".");
98
- o.current[c] || (o.current[c] = /* @__PURE__ */ new Set());
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);
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
- O as FormValidationError,
115
- S as useForm
123
+ S as FormValidationError,
124
+ B as useForm
116
125
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "triafly-ui-kit",
3
- "version": "1.0.53",
3
+ "version": "1.0.54",
4
4
  "description": "UI Kit from Triafly",
5
5
  "main": "./dist/main.js",
6
6
  "module": "./dist/main.js",