@elcrm/form 0.0.69 → 0.0.70
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.
- package/dist/fields/Date.js +24 -28
- package/dist/fields/Input.js +32 -24
- package/dist/fields/Mask.js +62 -50
- package/dist/fields/Money.js +65 -52
- package/dist/fields/Numeric.js +49 -42
- package/dist/fields/Phone.js +63 -53
- package/dist/fields/Textarea.js +40 -31
- package/dist/fields/Time.js +4 -4
- package/dist/index.umd.js +1 -1
- package/dist/package.js +1 -1
- package/package.json +1 -1
package/dist/fields/Phone.js
CHANGED
|
@@ -5,10 +5,10 @@ import r, { asEditableClipboard as i } from "../events/onEvent.js";
|
|
|
5
5
|
import { isEmptyTextLike as a } from "./visibility.js";
|
|
6
6
|
import o from "../mask/MaskPhone.js";
|
|
7
7
|
import { useFormInit as s } from "../FormInitContext.js";
|
|
8
|
-
import "react";
|
|
9
|
-
import { Fragment as
|
|
8
|
+
import c from "react";
|
|
9
|
+
import { Fragment as l, jsx as u, jsxs as d } from "react/jsx-runtime";
|
|
10
10
|
//#region src/lib/fields/Phone.tsx
|
|
11
|
-
function
|
|
11
|
+
function f(e) {
|
|
12
12
|
let t = window.getSelection();
|
|
13
13
|
if (!t || t.rangeCount === 0) return 0;
|
|
14
14
|
let n = t.getRangeAt(0);
|
|
@@ -16,97 +16,107 @@ function d(e) {
|
|
|
16
16
|
let r = document.createRange();
|
|
17
17
|
return r.selectNodeContents(e), r.setEnd(n.startContainer, n.startOffset), r.toString().length;
|
|
18
18
|
}
|
|
19
|
-
function
|
|
19
|
+
function p(e, t) {
|
|
20
20
|
if (t <= 0) return 0;
|
|
21
21
|
let n = 0;
|
|
22
22
|
for (let r = 0; r < e.length; r++) if (/\d/.test(e[r]) && (n++, n === t)) return r + 1;
|
|
23
23
|
return e.length;
|
|
24
24
|
}
|
|
25
|
-
function
|
|
26
|
-
let { onNotice:
|
|
25
|
+
function m({ value: m, form: h, onValue: g, onBlur: _, name: v = "", placeholder: y = "", label: b = "", error: x = "", hidden: S = !1, disabled: C = !1, className: w = "", after: T = "", before: E = "", inputmode: D = "tel", view: O }) {
|
|
26
|
+
let { onNotice: k } = s(), A = !C, { value: j, version: M } = n(h, v, m), N = c.useRef(null), P = c.useRef(!1), F = "+_(___) ___-__-__", I = !0, L = 0, R = (e, t) => {
|
|
27
27
|
let n = t.firstChild;
|
|
28
28
|
if (!n || n.nodeType !== Node.TEXT_NODE) return;
|
|
29
29
|
let r = n.textContent?.length ?? 0, i = Math.max(0, Math.min(e, r)), a = document.createRange(), o = window.getSelection();
|
|
30
30
|
o && (a.setStart(n, i), a.collapse(!0), o.removeAllRanges(), o.addRange(a), t.focus());
|
|
31
|
-
},
|
|
32
|
-
let t = e.target, n = t.textContent || "", r =
|
|
31
|
+
}, z = (e) => {
|
|
32
|
+
let t = e.target, n = t.textContent || "", r = f(t), i = n.slice(0, r).replace(/\D/g, "").length, a = V(n);
|
|
33
33
|
t.textContent = a.q;
|
|
34
|
-
let o =
|
|
34
|
+
let o = p(a.q, i);
|
|
35
35
|
a.q.length > 0 && queueMicrotask(() => {
|
|
36
|
-
|
|
36
|
+
R(Math.min(o, a.q.length), t);
|
|
37
37
|
});
|
|
38
38
|
let s = {
|
|
39
39
|
value: a.q.replace(/\D/g, ""),
|
|
40
|
-
name:
|
|
40
|
+
name: v || ""
|
|
41
41
|
};
|
|
42
|
-
|
|
43
|
-
},
|
|
44
|
-
|
|
42
|
+
h && v && h.onValue(s), g && g !== h?.onValue && g(s);
|
|
43
|
+
}, B = (e) => r.PasteOne(i(e)), V = (e) => {
|
|
44
|
+
F = "+_(___) ___-__-__", I = !0, L = 0;
|
|
45
45
|
let t = 0, n = "", r = e.replace(/\D/g, "");
|
|
46
|
-
r === "" && (
|
|
46
|
+
r === "" && (I = !0);
|
|
47
47
|
let i = r.split(""), a = "";
|
|
48
48
|
i.forEach((e) => {
|
|
49
|
-
|
|
49
|
+
I && (a += e, o[a] !== void 0 && I ? (I = !1, F = o[a].mask.replace(/* @__PURE__ */ RegExp("[0-9]", "g"), "_"), n = o[a].code) : (I && (L = ("" + a).length, F = `+${a}_(___) ___-__-__`.replace(/* @__PURE__ */ RegExp("[0-9]", "g"), "_"), n = ""), L > ("" + a).length && (I = !0, F = `+${a}_(___) ___-__-__`.replace(/* @__PURE__ */ RegExp("[0-9]", "g"), "_"), n = "")));
|
|
50
50
|
});
|
|
51
|
-
let s =
|
|
51
|
+
let s = F.replace(/\D/g, "");
|
|
52
52
|
return s.length >= r.length && (r = s), {
|
|
53
|
-
q:
|
|
53
|
+
q: F.replace(/[_\d]/g, function() {
|
|
54
54
|
return r.charAt(t++) || "_";
|
|
55
55
|
}),
|
|
56
56
|
i: t,
|
|
57
57
|
v: r,
|
|
58
58
|
f: n
|
|
59
59
|
};
|
|
60
|
-
}
|
|
60
|
+
};
|
|
61
|
+
c.useLayoutEffect(() => {
|
|
62
|
+
if (P.current) return;
|
|
63
|
+
let e = N.current;
|
|
64
|
+
if (!e) return;
|
|
65
|
+
let t = V(String(j || ""));
|
|
66
|
+
e.textContent !== t.q && (e.textContent = t.q);
|
|
67
|
+
}, [j, M]);
|
|
68
|
+
let H = (e) => {
|
|
61
69
|
e.preventDefault();
|
|
62
70
|
let t = e.target;
|
|
63
71
|
navigator.clipboard.writeText((t.textContent || "").replace(/\D/g, "")).then(function() {
|
|
64
|
-
|
|
72
|
+
k("Данные в буфер обмене");
|
|
65
73
|
}, function(e) {
|
|
66
74
|
console.error("Async: Could not copy text: ", e);
|
|
67
75
|
});
|
|
68
|
-
}
|
|
76
|
+
};
|
|
77
|
+
V(String(j || ""));
|
|
78
|
+
let U = (e) => {
|
|
69
79
|
e.key === "Enter" && e.preventDefault();
|
|
70
|
-
},
|
|
71
|
-
r.Blur(e),
|
|
80
|
+
}, W = (e) => {
|
|
81
|
+
r.Blur(e), _ && _({
|
|
72
82
|
value: (e.target.textContent || "").replace(/\D/g, ""),
|
|
73
|
-
name:
|
|
74
|
-
});
|
|
75
|
-
},
|
|
76
|
-
r.Focus({ target: e.currentTarget });
|
|
77
|
-
},
|
|
78
|
-
|
|
79
|
-
let
|
|
80
|
-
return
|
|
83
|
+
name: v || ""
|
|
84
|
+
}), P.current = !1;
|
|
85
|
+
}, G = (e) => {
|
|
86
|
+
P.current = !0, r.Focus({ target: e.currentTarget });
|
|
87
|
+
}, K = {};
|
|
88
|
+
y && (K.placeholder = y), K.inputMode = D ?? "tel";
|
|
89
|
+
let q = String(j ?? "").replace(/\D/g, "");
|
|
90
|
+
return S && a(q) ? /* @__PURE__ */ u(l, {}) : /* @__PURE__ */ d(t, {
|
|
81
91
|
type: "input",
|
|
82
|
-
label:
|
|
83
|
-
error:
|
|
84
|
-
element_blok: { className: [
|
|
92
|
+
label: b,
|
|
93
|
+
error: x,
|
|
94
|
+
element_blok: { className: [w] },
|
|
85
95
|
element_input: { className: [e.w] },
|
|
86
96
|
children: [
|
|
87
|
-
|
|
88
|
-
/* @__PURE__ */
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
97
|
+
E,
|
|
98
|
+
/* @__PURE__ */ u("div", {
|
|
99
|
+
ref: N,
|
|
100
|
+
onPaste: B,
|
|
101
|
+
onInput: z,
|
|
102
|
+
onKeyDown: U,
|
|
103
|
+
onContextMenu: H,
|
|
104
|
+
onBlur: W,
|
|
105
|
+
onFocus: G,
|
|
95
106
|
spellCheck: !1,
|
|
96
107
|
role: "textbox",
|
|
97
|
-
"aria-label":
|
|
98
|
-
"aria-disabled": !
|
|
99
|
-
tabIndex:
|
|
100
|
-
"data-disabled": !
|
|
101
|
-
contentEditable:
|
|
108
|
+
"aria-label": b || y || "Телефон",
|
|
109
|
+
"aria-disabled": !A,
|
|
110
|
+
tabIndex: C ? -1 : 0,
|
|
111
|
+
"data-disabled": !A,
|
|
112
|
+
contentEditable: A ? "plaintext-only" : !1,
|
|
102
113
|
suppressContentEditableWarning: !0,
|
|
103
|
-
...
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
w
|
|
114
|
+
...K
|
|
115
|
+
}),
|
|
116
|
+
T
|
|
107
117
|
]
|
|
108
118
|
});
|
|
109
119
|
}
|
|
110
|
-
|
|
120
|
+
m.displayName = "PhoneField";
|
|
111
121
|
//#endregion
|
|
112
|
-
export {
|
|
122
|
+
export { m as default };
|
package/dist/fields/Textarea.js
CHANGED
|
@@ -3,50 +3,59 @@ import t from "../core/Field.js";
|
|
|
3
3
|
import { useFormFieldState as n } from "../hooks/use.js";
|
|
4
4
|
import r, { asEditableClipboard as i } from "../events/onEvent.js";
|
|
5
5
|
import { isEmptyTextLike as a } from "./visibility.js";
|
|
6
|
-
import "react";
|
|
7
|
-
import { Fragment as
|
|
6
|
+
import o from "react";
|
|
7
|
+
import { Fragment as s, jsx as c, jsxs as l } from "react/jsx-runtime";
|
|
8
8
|
//#region src/lib/fields/Textarea.tsx
|
|
9
|
-
function
|
|
10
|
-
let { value:
|
|
9
|
+
function u({ value: u, form: d, onValue: f, name: p = "", placeholder: m = "", label: h = "", hidden: g = !1, disabled: _ = !1, onBlur: v, className: y = "", after: b = "", before: x = "", error: S = "", inputmode: C = "text", maxLength: w, spellCheck: T = !0 }) {
|
|
10
|
+
let { value: E, version: D } = n(d, p || "", u), O = !_, k = String(E ?? ""), A = o.useRef(null), j = o.useRef(!1);
|
|
11
|
+
o.useLayoutEffect(() => {
|
|
12
|
+
if (j.current) return;
|
|
13
|
+
let e = A.current;
|
|
14
|
+
e && e.innerText !== k && (e.innerText = k);
|
|
15
|
+
}, [k, D]);
|
|
16
|
+
let M = (e) => {
|
|
11
17
|
let t = {
|
|
12
18
|
value: e.currentTarget.innerText,
|
|
13
|
-
name:
|
|
19
|
+
name: p || ""
|
|
14
20
|
};
|
|
15
|
-
|
|
16
|
-
},
|
|
21
|
+
d && p && d.onValue(t), f && f !== d?.onValue && f(t);
|
|
22
|
+
}, N = (e) => {
|
|
17
23
|
let t = (e.currentTarget.textContent ?? "").trim();
|
|
18
|
-
|
|
19
|
-
},
|
|
20
|
-
if (
|
|
21
|
-
let
|
|
22
|
-
return
|
|
24
|
+
w && t.length >= w && e.key !== "Backspace" && e.preventDefault(), e.key === "Enter" && !e.shiftKey && e.preventDefault();
|
|
25
|
+
}, P = (e) => r.Paste(w || 0, i(e));
|
|
26
|
+
if (g && a(E)) return /* @__PURE__ */ c(s, {});
|
|
27
|
+
let F = {};
|
|
28
|
+
return m && (F.placeholder = m), O && (F.edit = ""), F.inputMode = C || "text", /* @__PURE__ */ l(t, {
|
|
23
29
|
type: "note",
|
|
24
|
-
label:
|
|
25
|
-
error:
|
|
26
|
-
element_blok: { className: [
|
|
30
|
+
label: h,
|
|
31
|
+
error: S,
|
|
32
|
+
element_blok: { className: [y || ""] },
|
|
27
33
|
element_input: { className: [e.n] },
|
|
28
34
|
children: [
|
|
29
|
-
|
|
30
|
-
/* @__PURE__ */
|
|
31
|
-
|
|
32
|
-
|
|
35
|
+
x,
|
|
36
|
+
/* @__PURE__ */ c("div", {
|
|
37
|
+
ref: A,
|
|
38
|
+
onPaste: P,
|
|
39
|
+
onInput: M,
|
|
40
|
+
onFocus: () => {
|
|
41
|
+
j.current = !0;
|
|
42
|
+
},
|
|
33
43
|
onBlur: (e) => {
|
|
34
|
-
r.Blur(e),
|
|
44
|
+
r.Blur(e), v?.({
|
|
35
45
|
value: (e.currentTarget.textContent ?? "").trim(),
|
|
36
|
-
name:
|
|
37
|
-
});
|
|
46
|
+
name: p || ""
|
|
47
|
+
}), j.current = !1;
|
|
38
48
|
},
|
|
39
|
-
onKeyDown:
|
|
40
|
-
spellCheck:
|
|
41
|
-
contentEditable:
|
|
49
|
+
onKeyDown: N,
|
|
50
|
+
spellCheck: T,
|
|
51
|
+
contentEditable: O ? "plaintext-only" : !1,
|
|
42
52
|
suppressContentEditableWarning: !0,
|
|
43
|
-
...
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
y
|
|
53
|
+
...F
|
|
54
|
+
}),
|
|
55
|
+
b
|
|
47
56
|
]
|
|
48
57
|
});
|
|
49
58
|
}
|
|
50
|
-
|
|
59
|
+
u.displayName = "TextareaField";
|
|
51
60
|
//#endregion
|
|
52
|
-
export {
|
|
61
|
+
export { u as default };
|
package/dist/fields/Time.js
CHANGED
|
@@ -82,7 +82,7 @@ function _(e, t, n) {
|
|
|
82
82
|
}
|
|
83
83
|
return p(Math.floor(i / 60), i % 60);
|
|
84
84
|
}
|
|
85
|
-
function v({ value: h = "", form: v, onValue: ee, onBlur: y, name: b = "", placeholder: x = "", label: S = "", hidden: C = !1, disabled: w = !1, error: T = "", className: E = "", after:
|
|
85
|
+
function v({ value: h = "", form: v, onValue: ee, onBlur: y, name: b = "", placeholder: x = "", label: S = "", hidden: C = !1, disabled: w = !1, error: T = "", className: E = "", after: te = "", before: D = "", step: O = 60, min: k, max: A, id: j, spellCheck: M = !1, align: N = "start" }) {
|
|
86
86
|
let { value: P, version: F } = n(v, b, h), I = d(P), L = !w, R = i.useRef(null), z = i.useRef(null), B = i.useRef(null), [V, H] = i.useState(!1);
|
|
87
87
|
i.useLayoutEffect(() => {
|
|
88
88
|
if (!V || !L) return;
|
|
@@ -198,7 +198,7 @@ function v({ value: h = "", form: v, onValue: ee, onBlur: y, name: b = "", place
|
|
|
198
198
|
props: { "data-disabled": w || !L ? "true" : void 0 }
|
|
199
199
|
},
|
|
200
200
|
children: [
|
|
201
|
-
|
|
201
|
+
D,
|
|
202
202
|
/* @__PURE__ */ o("div", {
|
|
203
203
|
ref: B,
|
|
204
204
|
className: e.timeInner,
|
|
@@ -244,8 +244,8 @@ function v({ value: h = "", form: v, onValue: ee, onBlur: y, name: b = "", place
|
|
|
244
244
|
children: !L || !V ? Q === null ? "" : l(Q) : null
|
|
245
245
|
})
|
|
246
246
|
]
|
|
247
|
-
}
|
|
248
|
-
|
|
247
|
+
}),
|
|
248
|
+
te
|
|
249
249
|
]
|
|
250
250
|
});
|
|
251
251
|
}
|