@code0-tech/pictor 0.6.3 → 0.6.4

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,55 +1,55 @@
1
- import { jsxs as l, Fragment as M, jsx as t } from "react/jsx-runtime";
2
- import p from "react";
1
+ import { jsxs as i, Fragment as M, jsx as t } from "react/jsx-runtime";
2
+ import u from "react";
3
3
  import { Input as V } from "./Input.js";
4
4
  import { IconX as s, IconCheck as c, IconEye as x } from "@tabler/icons-react";
5
- import { Button as u } from "../button/Button.js";
6
- import { clearInputElement as D } from "./Input.utils.js";
5
+ import { Button as p } from "../button/Button.js";
6
+ import { clearInputElement as w } from "./Input.utils.js";
7
7
  import { Flex as o } from "../flex/Flex.js";
8
8
  import { Text as a } from "../text/Text.js";
9
- const E = p.forwardRef((n, e) => {
10
- e = e || p.useRef(null);
9
+ const A = u.forwardRef((n, e) => {
10
+ e = e || u.useRef(null);
11
11
  const {
12
12
  clearable: m = !0,
13
- visible: g = !0,
14
- right: h,
13
+ visible: h = !0,
14
+ right: g,
15
15
  formValidation: r,
16
16
  ...f
17
- } = n, z = (i) => (D(e.current), i.stopPropagation(), i.preventDefault(), !1), y = (i) => (e.current instanceof HTMLInputElement && (e.current.type === "password" ? e.current.type = "text" : e.current.type === "text" && (e.current.type = "password")), i.stopPropagation(), i.preventDefault(), !1), d = [h];
18
- return g && d.push(/* @__PURE__ */ t(u, { variant: "none", onClick: (i) => y(i), children: /* @__PURE__ */ t(x, { size: 13 }) })), m && d.push(/* @__PURE__ */ t(u, { variant: "none", onClick: (i) => z(i), children: /* @__PURE__ */ t(s, { size: 13 }) })), /* @__PURE__ */ l(M, { children: [
17
+ } = n, z = (l) => (w(e.current), l.stopPropagation(), l.preventDefault(), !1), y = (l) => (e.current instanceof HTMLInputElement && (e.current.type === "password" ? e.current.type = "text" : e.current.type === "text" && (e.current.type = "password")), !1), d = [g];
18
+ return h && d.push(/* @__PURE__ */ t(p, { variant: "none", onClick: (l) => y(), children: /* @__PURE__ */ t(x, { size: 13 }) })), m && d.push(/* @__PURE__ */ t(p, { variant: "none", onClick: (l) => z(l), children: /* @__PURE__ */ t(s, { size: 13 }) })), /* @__PURE__ */ i(M, { children: [
19
19
  /* @__PURE__ */ t(V, { right: d, rightType: "action", type: "password", ref: e, ...r ? {
20
20
  formValidation: {
21
21
  setValue: r.setValue,
22
22
  valid: r.valid
23
23
  }
24
24
  } : {}, ...f }),
25
- !r?.valid && /* @__PURE__ */ l(o, { mt: 0.7, style: {
25
+ !r?.valid && /* @__PURE__ */ i(o, { mt: 0.7, style: {
26
26
  flexDirection: "column"
27
27
  }, children: [
28
- /* @__PURE__ */ l(o, { align: "center", style: {
28
+ /* @__PURE__ */ i(o, { align: "center", style: {
29
29
  gap: "0.35rem"
30
30
  }, children: [
31
31
  r?.notValidMessage?.includes("1") ? /* @__PURE__ */ t(s, { color: "#D90429", size: 16 }) : /* @__PURE__ */ t(c, { color: "#29BF12", size: 16 }),
32
32
  /* @__PURE__ */ t(a, { children: "Must be at least 8 characters" })
33
33
  ] }),
34
- /* @__PURE__ */ l(o, { align: "center", style: {
34
+ /* @__PURE__ */ i(o, { align: "center", style: {
35
35
  gap: "0.35rem"
36
36
  }, children: [
37
37
  r?.notValidMessage?.includes("2") ? /* @__PURE__ */ t(s, { color: "#D90429", size: 16 }) : /* @__PURE__ */ t(c, { color: "#29BF12", size: 16 }),
38
38
  /* @__PURE__ */ t(a, { children: "Must include a lowercase letter" })
39
39
  ] }),
40
- /* @__PURE__ */ l(o, { align: "center", style: {
40
+ /* @__PURE__ */ i(o, { align: "center", style: {
41
41
  gap: "0.35rem"
42
42
  }, children: [
43
43
  r?.notValidMessage?.includes("3") ? /* @__PURE__ */ t(s, { color: "#D90429", size: 16 }) : /* @__PURE__ */ t(c, { color: "#29BF12", size: 16 }),
44
44
  /* @__PURE__ */ t(a, { children: "Must include an uppercase letter" })
45
45
  ] }),
46
- /* @__PURE__ */ l(o, { align: "center", style: {
46
+ /* @__PURE__ */ i(o, { align: "center", style: {
47
47
  gap: "0.35rem"
48
48
  }, children: [
49
49
  r?.notValidMessage?.includes("4") ? /* @__PURE__ */ t(s, { color: "#D90429", size: 16 }) : /* @__PURE__ */ t(c, { color: "#29BF12", size: 16 }),
50
50
  /* @__PURE__ */ t(a, { children: "Must include a number" })
51
51
  ] }),
52
- /* @__PURE__ */ l(o, { align: "center", style: {
52
+ /* @__PURE__ */ i(o, { align: "center", style: {
53
53
  gap: "0.35rem"
54
54
  }, children: [
55
55
  r?.notValidMessage?.includes("5") ? /* @__PURE__ */ t(s, { color: "#D90429", size: 16 }) : /* @__PURE__ */ t(c, { color: "#29BF12", size: 16 }),
@@ -57,12 +57,12 @@ const E = p.forwardRef((n, e) => {
57
57
  ] })
58
58
  ] })
59
59
  ] });
60
- }), P = (n) => {
60
+ }), E = (n) => {
61
61
  if (!n) return "12345";
62
62
  let e = null;
63
63
  return n.length < 8 && (e = (e ?? "") + "1"), /[a-z]/.test(n) || (e = (e ?? "") + "2"), /[A-Z]/.test(n) || (e = (e ?? "") + "3"), /[0-9]/.test(n) || (e = (e ?? "") + "4"), /[^A-Za-z0-9]/.test(n) || (e = (e ?? "") + "5"), e;
64
64
  };
65
65
  export {
66
- E as PasswordInput,
67
- P as passwordValidation
66
+ A as PasswordInput,
67
+ E as passwordValidation
68
68
  };
@@ -1,41 +1,41 @@
1
- import { useState as g, useRef as p, useCallback as m, useEffect as j } from "react";
2
- function o(i, t, e) {
3
- return (t = P(t)) in i ? Object.defineProperty(i, t, { value: e, enumerable: !0, configurable: !0, writable: !0 }) : i[t] = e, i;
1
+ import { useState as m, useRef as w, useCallback as b, useEffect as j } from "react";
2
+ function c(a, e, t) {
3
+ return (e = y(e)) in a ? Object.defineProperty(a, e, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : a[e] = t, a;
4
4
  }
5
- function P(i) {
6
- var t = y(i, "string");
7
- return typeof t == "symbol" ? t : t + "";
5
+ function y(a) {
6
+ var e = P(a, "string");
7
+ return typeof e == "symbol" ? e : e + "";
8
8
  }
9
- function y(i, t) {
10
- if (typeof i != "object" || !i) return i;
11
- var e = i[Symbol.toPrimitive];
12
- if (e !== void 0) {
13
- var a = e.call(i, t);
14
- if (typeof a != "object") return a;
9
+ function P(a, e) {
10
+ if (typeof a != "object" || !a) return a;
11
+ var t = a[Symbol.toPrimitive];
12
+ if (t !== void 0) {
13
+ var i = t.call(a, e);
14
+ if (typeof i != "object") return i;
15
15
  throw new TypeError("@@toPrimitive must return a primitive value.");
16
16
  }
17
- return (t === "string" ? String : Number)(i);
17
+ return (e === "string" ? String : Number)(a);
18
18
  }
19
- class b {
20
- constructor(t, e, a, u = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Map()) {
21
- o(this, "changeValue", void 0), o(this, "currentValues", void 0), o(this, "currentValidations", void 0), o(this, "shouldValidate", void 0), o(this, "cachedMessages", void 0), this.changeValue = t, this.currentValues = e, this.currentValidations = a, this.shouldValidate = u, this.cachedMessages = r;
19
+ class v {
20
+ constructor(e, t, i, u = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Map()) {
21
+ c(this, "changeValue", void 0), c(this, "currentValues", void 0), c(this, "currentValidations", void 0), c(this, "shouldValidate", void 0), c(this, "cachedMessages", void 0), this.changeValue = e, this.currentValues = t, this.currentValidations = i, this.shouldValidate = u, this.cachedMessages = r;
22
22
  }
23
23
  isValid() {
24
24
  if (!this.currentValidations) return !0;
25
- for (const t in this.currentValidations) {
26
- const e = this.currentValidations[t];
27
- if (e && e(this.currentValues[t], this.currentValues) !== null)
25
+ for (const e in this.currentValidations) {
26
+ const t = this.currentValidations[e];
27
+ if (t && t(this.currentValues[e], this.currentValues) !== null)
28
28
  return !1;
29
29
  }
30
30
  return !0;
31
31
  }
32
- getInputProps(t) {
33
- const e = this.currentValues[t], a = e ?? null, u = t, r = this.currentValidations && this.currentValidations[t] ? this.currentValidations[t] : (l) => null;
32
+ getInputProps(e) {
33
+ const t = this.currentValues[e], i = t ?? null, u = e, r = this.currentValidations && this.currentValidations[e] ? this.currentValidations[e] : (l) => null;
34
34
  let s = null;
35
- return this.shouldValidate.has(t) ? (s = r(e, this.currentValues), this.cachedMessages.set(t, s)) : s = this.cachedMessages.get(t) ?? null, {
35
+ return this.shouldValidate.has(e) ? (s = r(t, this.currentValues), this.cachedMessages.set(e, s)) : s = this.cachedMessages.get(e) ?? null, {
36
36
  // @ts-ignore – z.B. wenn dein Input `defaultValue` kennt
37
- defaultValue: a,
38
- initialValue: a ?? void 0,
37
+ defaultValue: i,
38
+ initialValue: i ?? void 0,
39
39
  formValidation: {
40
40
  setValue: (l) => {
41
41
  this.changeValue(u, l);
@@ -43,36 +43,36 @@ class b {
43
43
  notValidMessage: s,
44
44
  valid: s === null
45
45
  },
46
- ...this.currentValidations && this.currentValidations[t] ? {
46
+ ...this.currentValidations && this.currentValidations[e] ? {
47
47
  required: !0
48
48
  } : {}
49
49
  };
50
50
  }
51
51
  }
52
- const F = (i) => {
52
+ const F = (a) => {
53
53
  const {
54
- initialValues: t,
55
- validate: e = {},
56
- truthyValidationBeforeSubmit: a = !0,
54
+ initialValues: e,
55
+ validate: t = {},
56
+ truthyValidationBeforeSubmit: i = !0,
57
57
  useInitialValidation: u = !0,
58
58
  onSubmit: r
59
- } = i, [s, l] = g(t), c = p(t), v = p(/* @__PURE__ */ new Map()), V = m((n, f) => {
60
- l((d) => {
61
- const h = {
62
- ...d,
63
- [n]: f
59
+ } = a, [s, l] = m(e), o = w(e), f = w(/* @__PURE__ */ new Map()), d = b((n, p) => {
60
+ l((h) => {
61
+ const V = {
62
+ ...h,
63
+ [n]: p
64
64
  };
65
- return c.current = h, h;
65
+ return o.current = V, V;
66
66
  });
67
- }, []), [w, M] = g(new b(V, s, e, u ? new Map(Object.keys(t).map((n) => [n, !0])) : /* @__PURE__ */ new Map(), v.current));
67
+ }, []), [M, g] = m(new v(d, s, t, u ? new Map(Object.keys(e).map((n) => [n, !0])) : /* @__PURE__ */ new Map(), f.current));
68
68
  j(() => {
69
- l(t), c.current = t;
70
- }, [t]);
71
- const S = m((n) => {
72
- const f = n && new Set(Object.keys(t)).has(String(n)) ? /* @__PURE__ */ new Map([[n, !0]]) : new Map(Object.keys(t).map((h) => [String(h), !0])), d = new b(V, c.current, e, f, v.current);
73
- M(d), !new Set(Object.keys(t)).has(String(n)) && r && (!a || d.isValid()) && r(c.current);
74
- }, [V, e, r, a, t]);
75
- return [w, S];
69
+ l(e), o.current = e, g(new v(d, e, t, u ? new Map(Object.keys(e).map((n) => [n, !0])) : /* @__PURE__ */ new Map(), f.current));
70
+ }, [e]);
71
+ const S = b((n) => {
72
+ const p = n && new Set(Object.keys(e)).has(String(n)) ? /* @__PURE__ */ new Map([[n, !0]]) : new Map(Object.keys(e).map((V) => [String(V), !0])), h = new v(d, o.current, t, p, f.current);
73
+ g(h), !new Set(Object.keys(e)).has(String(n)) && r && (!i || h.isValid()) && r(o.current);
74
+ }, [d, t, r, i, e]);
75
+ return [M, S];
76
76
  };
77
77
  export {
78
78
  F as useForm
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@code0-tech/pictor",
3
- "version": "0.6.3",
3
+ "version": "0.6.4",
4
4
  "type": "module",
5
5
  "description": "A simple template for a custom React component library",
6
6
  "scripts": {