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