@elcrm/form 0.0.63 → 0.0.65
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/README.md +139 -0
- package/dist/Form.d.ts +20 -0
- package/dist/Form.js +11 -0
- package/dist/FormInitContext.d.ts +25 -0
- package/dist/FormInitContext.js +20 -0
- package/dist/assets/styles/Field.module.css +1 -0
- package/dist/assets/styles/Form.module.css +1 -0
- package/dist/assets/styles/Select.module.css +1 -0
- package/dist/core/Field.d.ts +19 -0
- package/dist/core/Field.js +33 -0
- package/dist/events/onEvent.d.ts +55 -0
- package/dist/events/onEvent.js +67 -0
- package/dist/fields/Date.d.ts +13 -0
- package/dist/fields/Date.js +352 -0
- package/dist/fields/Input.d.ts +12 -0
- package/dist/fields/Input.js +127 -0
- package/dist/fields/Mask.d.ts +9 -0
- package/dist/fields/Mask.js +101 -0
- package/dist/fields/Modal.d.ts +25 -0
- package/dist/fields/Modal.js +62 -0
- package/dist/fields/Money.d.ts +14 -0
- package/dist/fields/Money.js +100 -0
- package/dist/fields/Numeric.d.ts +9 -0
- package/dist/fields/Numeric.js +73 -0
- package/dist/fields/Options.d.ts +32 -0
- package/dist/fields/Options.js +69 -0
- package/dist/fields/Password.d.ts +6 -0
- package/dist/fields/Password.js +153 -0
- package/dist/fields/Phone.d.ts +7 -0
- package/dist/fields/Phone.js +112 -0
- package/dist/fields/Range.d.ts +16 -0
- package/dist/fields/Range.js +103 -0
- package/dist/fields/Select.d.ts +21 -0
- package/dist/fields/Select.js +146 -0
- package/dist/fields/Textarea.d.ts +7 -0
- package/dist/fields/Textarea.js +52 -0
- package/dist/fields/Time.d.ts +26 -0
- package/dist/fields/Time.js +254 -0
- package/dist/fields/type.d.ts +77 -0
- package/dist/fields/visibility.d.ts +6 -0
- package/dist/fields/visibility.js +6 -0
- package/dist/hooks/use.d.ts +41 -0
- package/dist/hooks/use.js +57 -0
- package/dist/index.d.ts +26 -2
- package/dist/index.js +26 -0
- package/dist/mask/MaskPhone.d.ts +8 -0
- package/dist/mask/MaskPhone.js +1384 -0
- package/dist/package.js +96 -0
- package/dist/styles/Field.module.js +22 -0
- package/dist/styles/Form.module.js +12 -0
- package/dist/styles/Select.module.js +8 -0
- package/package.json +72 -11
- package/src/lib/styles/Field.module.scss +315 -0
- package/src/lib/styles/Form.module.scss +313 -0
- package/src/lib/styles/Select.module.scss +90 -0
- package/src/lib/styles/dark.css +47 -0
- package/src/lib/styles/light.css +51 -0
- package/dist/index.css +0 -1
- package/dist/index.es.js +0 -5045
- package/dist/index.umd.js +0 -89
- package/dist/src/lib/Captcha.d.ts +0 -1
- package/dist/src/lib/Check.d.ts +0 -13
- package/dist/src/lib/Code.d.ts +0 -22
- package/dist/src/lib/Color.d.ts +0 -22
- package/dist/src/lib/Field.d.ts +0 -13
- package/dist/src/lib/Files.d.ts +0 -20
- package/dist/src/lib/Generator.d.ts +0 -1
- package/dist/src/lib/Group.d.ts +0 -21
- package/dist/src/lib/Image.d.ts +0 -22
- package/dist/src/lib/Init.d.ts +0 -1
- package/dist/src/lib/MaskPhone.d.ts +0 -2
- package/dist/src/lib/Message.d.ts +0 -15
- package/dist/src/lib/Money.d.ts +0 -22
- package/dist/src/lib/Month.d.ts +0 -18
- package/dist/src/lib/Palette.d.ts +0 -9
- package/dist/src/lib/Progress.d.ts +0 -9
- package/dist/src/lib/Toogle.d.ts +0 -8
- package/dist/src/lib/Users.d.ts +0 -1
- package/dist/src/lib/_Time.d.ts +0 -0
- package/dist/src/lib/fields/Date.d.ts +0 -18
- package/dist/src/lib/fields/Input.d.ts +0 -27
- package/dist/src/lib/fields/Mask.d.ts +0 -19
- package/dist/src/lib/fields/Modal.d.ts +0 -19
- package/dist/src/lib/fields/Numeric.d.ts +0 -6
- package/dist/src/lib/fields/Options.d.ts +0 -22
- package/dist/src/lib/fields/Password.d.ts +0 -23
- package/dist/src/lib/fields/Phone.d.ts +0 -21
- package/dist/src/lib/fields/Select copy.d.ts +0 -23
- package/dist/src/lib/fields/Select.d.ts +0 -28
- package/dist/src/lib/fields/Textarea.d.ts +0 -23
- package/dist/src/lib/fields/type.d.ts +0 -30
- package/dist/src/lib/index.d.ts +0 -16
- package/dist/src/lib/onEvent.d.ts +0 -2
- package/dist/src/lib/use.d.ts +0 -10
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { TInput } from './type';
|
|
2
|
+
type TMoney = TInput & {
|
|
3
|
+
/** Курс для отображения (множитель при записи в форму) */
|
|
4
|
+
course?: number;
|
|
5
|
+
/** Кнопка очистки */
|
|
6
|
+
isClear?: boolean;
|
|
7
|
+
/** Режим фильтра символов при вводе */
|
|
8
|
+
type?: string;
|
|
9
|
+
};
|
|
10
|
+
declare function MoneyField({ value, form, onValue, name, placeholder, label, error, hidden, disabled, onBlur: onBlurField, className, after, before, inputmode, course, view, type, isClear, }: TMoney): import("react/jsx-runtime").JSX.Element | "";
|
|
11
|
+
declare namespace MoneyField {
|
|
12
|
+
var displayName: string;
|
|
13
|
+
}
|
|
14
|
+
export default MoneyField;
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import e from "../styles/Field.module.js";
|
|
2
|
+
import t from "../core/Field.js";
|
|
3
|
+
import { useFormFieldState as n } from "../hooks/use.js";
|
|
4
|
+
import r, { pastePlainTextIntoSelection as i } from "../events/onEvent.js";
|
|
5
|
+
import { isEmptyTextLike as a } from "./visibility.js";
|
|
6
|
+
import "react";
|
|
7
|
+
import { jsx as o, jsxs as s } from "react/jsx-runtime";
|
|
8
|
+
//#region src/lib/fields/Money.tsx
|
|
9
|
+
function c(e) {
|
|
10
|
+
let t = window.getSelection();
|
|
11
|
+
if (!t || t.rangeCount === 0) return 0;
|
|
12
|
+
let n = t.getRangeAt(0);
|
|
13
|
+
if (!e.contains(n.startContainer)) return 0;
|
|
14
|
+
let r = document.createRange();
|
|
15
|
+
return r.selectNodeContents(e), r.setEnd(n.startContainer, n.startOffset), r.toString().length;
|
|
16
|
+
}
|
|
17
|
+
function l(e, t, n) {
|
|
18
|
+
let r = Math.max(0, Math.min(t, e.length));
|
|
19
|
+
return n(e.slice(0, r)).length;
|
|
20
|
+
}
|
|
21
|
+
function u({ value: u, form: f, onValue: p, name: m = "", placeholder: h = "", label: g = "", error: _ = "", hidden: v = !1, disabled: y = !1, onBlur: b, className: x = "", after: S = "", before: C = "", inputmode: w = "decimal", course: T = 100, view: E, type: D, isClear: O = !1 }) {
|
|
22
|
+
let { value: k, version: A } = n(f, m || "", u), j = f && m ? k : u, M = (e) => D === "multi" ? e.replace(/[^+\d.+-]/g, "") : e.replace(/[^+\d.]/g, ""), N = (e, t) => {
|
|
23
|
+
let n = t.firstChild;
|
|
24
|
+
if (!n || n.nodeType !== Node.TEXT_NODE) return;
|
|
25
|
+
let r = n.textContent?.length ?? 0, i = Math.max(0, Math.min(e, r)), a = document.createRange(), o = window.getSelection();
|
|
26
|
+
o && (a.setStart(n, i), a.collapse(!0), o.removeAllRanges(), o.addRange(a), t.focus());
|
|
27
|
+
}, P = (e) => {
|
|
28
|
+
let t = e.target, n = t.textContent || "", r = c(t), i = M(n), a = l(n, r, M), o = {
|
|
29
|
+
value: Number(i || 0) * T,
|
|
30
|
+
name: m
|
|
31
|
+
};
|
|
32
|
+
f && m && f.onValue(o), p && p !== f?.onValue && p(o), t.textContent = i, i.length > 0 && queueMicrotask(() => {
|
|
33
|
+
N(Math.min(a, i.length), t);
|
|
34
|
+
});
|
|
35
|
+
}, F = (e) => {
|
|
36
|
+
let t = e.target;
|
|
37
|
+
r.Blur(e), (t.textContent || "") === "" && (t.textContent = "0");
|
|
38
|
+
let n = {
|
|
39
|
+
value: Number(M(t.textContent || "")) * T,
|
|
40
|
+
name: m
|
|
41
|
+
};
|
|
42
|
+
b?.(n), f && m && f.setValue(n), p && p !== f?.onValue && p(n), t.textContent = d(t.textContent || "");
|
|
43
|
+
}, I = (e) => {
|
|
44
|
+
let t = e.target;
|
|
45
|
+
t.textContent = M(t.textContent || ""), r.Focus({ target: e.currentTarget });
|
|
46
|
+
}, L = (e) => {
|
|
47
|
+
let t = e.currentTarget.previousElementSibling;
|
|
48
|
+
t && (t.textContent = "");
|
|
49
|
+
let n = {
|
|
50
|
+
value: 0,
|
|
51
|
+
name: m
|
|
52
|
+
};
|
|
53
|
+
f && m && f.setValue(n), p && p !== f?.onValue && p(n);
|
|
54
|
+
}, R = (e) => {
|
|
55
|
+
e.key === "Enter" && e.preventDefault();
|
|
56
|
+
}, z = (e) => {
|
|
57
|
+
e.preventDefault(), i(M(e.clipboardData?.getData("text/plain") ?? ""), e.currentTarget);
|
|
58
|
+
}, B = !y, V = j == null || (typeof j == "number" ? !1 : a(String(j ?? "")));
|
|
59
|
+
if (v && V) return "";
|
|
60
|
+
let H = {};
|
|
61
|
+
return H.inputMode = w ?? "decimal", h && (H.placeholder = h), B && (H.edit = ""), /* @__PURE__ */ s(t, {
|
|
62
|
+
type: "input",
|
|
63
|
+
label: g,
|
|
64
|
+
error: _,
|
|
65
|
+
element_blok: { className: [x] },
|
|
66
|
+
element_input: { className: [e.w] },
|
|
67
|
+
children: [
|
|
68
|
+
C,
|
|
69
|
+
/* @__PURE__ */ o("div", {
|
|
70
|
+
...H,
|
|
71
|
+
onInput: P,
|
|
72
|
+
onPaste: z,
|
|
73
|
+
onBlur: F,
|
|
74
|
+
onKeyDown: R,
|
|
75
|
+
onFocus: I,
|
|
76
|
+
role: "textbox",
|
|
77
|
+
spellCheck: !1,
|
|
78
|
+
"aria-label": g || h || "Сумма",
|
|
79
|
+
"aria-disabled": !B,
|
|
80
|
+
tabIndex: y ? -1 : 0,
|
|
81
|
+
contentEditable: B ? "plaintext-only" : !1,
|
|
82
|
+
suppressContentEditableWarning: !0,
|
|
83
|
+
children: !h || j ? d(j ?? "") : ""
|
|
84
|
+
}, A),
|
|
85
|
+
O && /* @__PURE__ */ o("button", {
|
|
86
|
+
type: "button",
|
|
87
|
+
onClick: L,
|
|
88
|
+
"aria-label": "Очистить поле",
|
|
89
|
+
children: "x"
|
|
90
|
+
}),
|
|
91
|
+
S
|
|
92
|
+
]
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
u.displayName = "MoneyField";
|
|
96
|
+
function d(e, t) {
|
|
97
|
+
return t && (e = Number(e) / t), parseFloat(String(e || 0)).toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, "$1 ");
|
|
98
|
+
}
|
|
99
|
+
//#endregion
|
|
100
|
+
export { u as default };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { TInput } from './type';
|
|
2
|
+
type TNumeric = TInput & {
|
|
3
|
+
max?: number;
|
|
4
|
+
};
|
|
5
|
+
declare function NumberField({ value, form, onValue, name, placeholder, label, hidden, disabled, onBlur: onBlurField, className, after, before, error, inputmode, maxLength, max, view, }: TNumeric): import("react/jsx-runtime").JSX.Element;
|
|
6
|
+
declare namespace NumberField {
|
|
7
|
+
var displayName: string;
|
|
8
|
+
}
|
|
9
|
+
export default NumberField;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import e from "../styles/Field.module.js";
|
|
2
|
+
import t from "../core/Field.js";
|
|
3
|
+
import { useFormFieldState as n } from "../hooks/use.js";
|
|
4
|
+
import r, { asEditableClipboard as i } from "../events/onEvent.js";
|
|
5
|
+
import { isEmptyTextLike as a } from "./visibility.js";
|
|
6
|
+
import "react";
|
|
7
|
+
import { Fragment as o, jsx as s, jsxs as c } from "react/jsx-runtime";
|
|
8
|
+
//#region src/lib/fields/Numeric.tsx
|
|
9
|
+
function l({ value: l, form: u, onValue: d, name: f = "", placeholder: p = "", label: m = "", hidden: h = !1, disabled: g = !1, onBlur: _, className: v = "", after: y = "", before: b = "", error: x = "", inputmode: S = "numeric", maxLength: C, max: w, view: T }) {
|
|
10
|
+
let E = !g, { value: D, version: O } = n(u, f, l);
|
|
11
|
+
p = p === void 0 ? "" : p, w = w === void 0 ? 99 : w;
|
|
12
|
+
let k = C ?? w, A = !1, j = (e) => {
|
|
13
|
+
let t = e.currentTarget, n = (t.textContent || "").replace(/\D/g, "");
|
|
14
|
+
n.length > k && (n = n.slice(0, k), t.textContent = n, queueMicrotask(() => {
|
|
15
|
+
let e = t.firstChild;
|
|
16
|
+
if (e && e.nodeType === Node.TEXT_NODE) {
|
|
17
|
+
let t = n.length, r = window.getSelection(), i = document.createRange();
|
|
18
|
+
i.setStart(e, t), i.collapse(!0), r?.removeAllRanges(), r?.addRange(i);
|
|
19
|
+
}
|
|
20
|
+
}));
|
|
21
|
+
let r = {
|
|
22
|
+
value: n,
|
|
23
|
+
name: f
|
|
24
|
+
};
|
|
25
|
+
u && f && u.onValue(r), d && d !== u?.onValue && d(r);
|
|
26
|
+
}, M = (e) => {
|
|
27
|
+
let t = e.currentTarget;
|
|
28
|
+
t.textContent = (t.textContent || "").replace(/\D/g, ""), r.Focus({ target: e.currentTarget });
|
|
29
|
+
}, N = (e) => {
|
|
30
|
+
if (A && e.which === 86) return;
|
|
31
|
+
if (e.which === 17 || e.which === 91) return A = !0;
|
|
32
|
+
if (e.key === "Backspace") return;
|
|
33
|
+
let t = (e.currentTarget.textContent ?? "").replace(/\D/g, "").length;
|
|
34
|
+
k > 0 && t >= k && e.key.length === 1 && /\d/.test(e.key) && e.preventDefault(), e.key === "Enter" && e.preventDefault(), e.key.length === 1 && !/\d/.test(e.key) && e.preventDefault();
|
|
35
|
+
}, P = (e) => {
|
|
36
|
+
if (e.which === 17 || e.which === 91) return A = !1;
|
|
37
|
+
}, F = (e) => r.PasteDigits(k, i(e)), I = (e) => {
|
|
38
|
+
r.Blur(e), _?.({
|
|
39
|
+
value: e.currentTarget.textContent,
|
|
40
|
+
name: f
|
|
41
|
+
});
|
|
42
|
+
}, L = {};
|
|
43
|
+
return E && (L.edit = ""), L.inputMode = S ?? "numeric", p && (L.placeholder = p), h && a(D) ? /* @__PURE__ */ s(o, {}) : /* @__PURE__ */ c(t, {
|
|
44
|
+
type: "numeric",
|
|
45
|
+
label: m,
|
|
46
|
+
error: x,
|
|
47
|
+
element_blok: { className: [v || ""] },
|
|
48
|
+
element_input: { className: [e.w] },
|
|
49
|
+
children: [
|
|
50
|
+
b,
|
|
51
|
+
/* @__PURE__ */ s("div", {
|
|
52
|
+
onPaste: F,
|
|
53
|
+
onInput: j,
|
|
54
|
+
onFocus: M,
|
|
55
|
+
onBlur: I,
|
|
56
|
+
onKeyDown: N,
|
|
57
|
+
onKeyUp: P,
|
|
58
|
+
spellCheck: !1,
|
|
59
|
+
role: "textbox",
|
|
60
|
+
tabIndex: E ? 0 : -1,
|
|
61
|
+
"aria-label": m || p || "Число",
|
|
62
|
+
contentEditable: E ? "plaintext-only" : !1,
|
|
63
|
+
suppressContentEditableWarning: !0,
|
|
64
|
+
...L,
|
|
65
|
+
children: D
|
|
66
|
+
}, O),
|
|
67
|
+
y
|
|
68
|
+
]
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
l.displayName = "NumberField";
|
|
72
|
+
//#endregion
|
|
73
|
+
export { l as default };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
import { UseFormApi } from '../hooks/use';
|
|
3
|
+
import { TValue } from './type';
|
|
4
|
+
interface Input {
|
|
5
|
+
value?: string;
|
|
6
|
+
form?: UseFormApi;
|
|
7
|
+
onValue?: (data: TValue) => void | Promise<void>;
|
|
8
|
+
name: string;
|
|
9
|
+
placeholder?: string;
|
|
10
|
+
/** Подпись поля */
|
|
11
|
+
label?: string;
|
|
12
|
+
error?: string;
|
|
13
|
+
hidden?: boolean;
|
|
14
|
+
/** true — блок выбора не открывается */
|
|
15
|
+
disabled?: boolean;
|
|
16
|
+
after?: ReactNode;
|
|
17
|
+
before?: ReactNode;
|
|
18
|
+
view?: string;
|
|
19
|
+
className?: string;
|
|
20
|
+
module?: string;
|
|
21
|
+
modal?: string;
|
|
22
|
+
options?: Record<string, {
|
|
23
|
+
label?: string;
|
|
24
|
+
}>;
|
|
25
|
+
outFormat?: "array" | "string" | "object";
|
|
26
|
+
separator?: string;
|
|
27
|
+
}
|
|
28
|
+
declare function OptionsField({ value, form, onValue, name, placeholder, separator, label, error, hidden, disabled, outFormat, after, before, modal, options, className, }: Input): import("react/jsx-runtime").JSX.Element;
|
|
29
|
+
declare namespace OptionsField {
|
|
30
|
+
var displayName: string;
|
|
31
|
+
}
|
|
32
|
+
export default OptionsField;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import e from "../styles/Field.module.js";
|
|
2
|
+
import t from "../core/Field.js";
|
|
3
|
+
import { useFormFieldState as n } from "../hooks/use.js";
|
|
4
|
+
import { useFormInit as r } from "../FormInitContext.js";
|
|
5
|
+
import { Fragment as i, jsx as a, jsxs as o } from "react/jsx-runtime";
|
|
6
|
+
//#region src/lib/fields/Options.tsx
|
|
7
|
+
var s = (e, t = ",") => (e !== void 0 && e !== "" ? e.split(t) : []).filter((e) => e !== "").reduce((e, t) => (e[t] = !0, e), {});
|
|
8
|
+
function c({ value: c, form: l, onValue: u, name: d, placeholder: f = "", separator: p = ",", label: m, error: h, hidden: g = !1, disabled: _ = !1, outFormat: v = "object", after: y, before: b, modal: x, options: S, className: C }) {
|
|
9
|
+
let { onModal: w } = r(), { value: T } = n(l, d, c), E = T, D = typeof E == "string" ? s(E, p) : E && typeof E == "object" ? E : {}, O = () => {
|
|
10
|
+
if (_) return;
|
|
11
|
+
if (!x) return console.error("modal - empty");
|
|
12
|
+
let e = x.split(".");
|
|
13
|
+
w({
|
|
14
|
+
module: e[0],
|
|
15
|
+
modalName: e[1],
|
|
16
|
+
callback: (e) => {
|
|
17
|
+
let t = e;
|
|
18
|
+
if (u) {
|
|
19
|
+
let e = {
|
|
20
|
+
value: v === "array" ? Object.keys(t) : v === "string" ? Object.keys(t).filter((e) => t[e]).join(p) : t,
|
|
21
|
+
name: d
|
|
22
|
+
};
|
|
23
|
+
switch (l && d && l.setValue(e), v) {
|
|
24
|
+
case "array":
|
|
25
|
+
u !== l?.onValue && u({
|
|
26
|
+
value: Object.keys(t),
|
|
27
|
+
name: d
|
|
28
|
+
});
|
|
29
|
+
break;
|
|
30
|
+
case "string":
|
|
31
|
+
u !== l?.onValue && u({
|
|
32
|
+
value: Object.keys(t).filter((e) => t[e]).join(p),
|
|
33
|
+
name: d
|
|
34
|
+
});
|
|
35
|
+
break;
|
|
36
|
+
default: u !== l?.onValue && u({
|
|
37
|
+
value: t,
|
|
38
|
+
name: d
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
onValue: u,
|
|
44
|
+
options: S,
|
|
45
|
+
fieldName: d,
|
|
46
|
+
value: D
|
|
47
|
+
});
|
|
48
|
+
}, k = {};
|
|
49
|
+
f && (k.placeholder = f);
|
|
50
|
+
let A = Object.keys(D).length === 0;
|
|
51
|
+
return g && A ? /* @__PURE__ */ a(i, {}) : /* @__PURE__ */ o(t, {
|
|
52
|
+
type: "group",
|
|
53
|
+
label: m,
|
|
54
|
+
error: h,
|
|
55
|
+
element_blok: { className: [C || ""] },
|
|
56
|
+
element_input: {
|
|
57
|
+
className: [e.g],
|
|
58
|
+
props: { onClick: O }
|
|
59
|
+
},
|
|
60
|
+
children: [
|
|
61
|
+
b,
|
|
62
|
+
Object.keys(D).map((e) => /* @__PURE__ */ a("div", { children: S?.[e]?.label }, e)),
|
|
63
|
+
y
|
|
64
|
+
]
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
c.displayName = "OptionsField";
|
|
68
|
+
//#endregion
|
|
69
|
+
export { c as default };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { TPasswordField } from './type';
|
|
2
|
+
declare function PasswordField({ value, form, onValue, name, placeholder, label, error, hidden, disabled, onBlur: onBlurField, className, after, before, native, maxLength, eyes, }: TPasswordField): import("react/jsx-runtime").JSX.Element | "";
|
|
3
|
+
declare namespace PasswordField {
|
|
4
|
+
var displayName: string;
|
|
5
|
+
}
|
|
6
|
+
export default PasswordField;
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import e from "../styles/Field.module.js";
|
|
2
|
+
import t from "../core/Field.js";
|
|
3
|
+
import { useFormFieldState as n } from "../hooks/use.js";
|
|
4
|
+
import r from "../events/onEvent.js";
|
|
5
|
+
import { isEmptyTextLike as i } from "./visibility.js";
|
|
6
|
+
import a from "react";
|
|
7
|
+
import { jsx as o, jsxs as s } from "react/jsx-runtime";
|
|
8
|
+
//#region src/lib/fields/Password.tsx
|
|
9
|
+
function c() {
|
|
10
|
+
return /* @__PURE__ */ s("svg", {
|
|
11
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
12
|
+
width: "1.25em",
|
|
13
|
+
height: "1.25em",
|
|
14
|
+
viewBox: "0 0 24 24",
|
|
15
|
+
fill: "none",
|
|
16
|
+
stroke: "currentColor",
|
|
17
|
+
strokeWidth: "2",
|
|
18
|
+
strokeLinecap: "round",
|
|
19
|
+
strokeLinejoin: "round",
|
|
20
|
+
"aria-hidden": !0,
|
|
21
|
+
children: [/* @__PURE__ */ o("path", { d: "M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z" }), /* @__PURE__ */ o("circle", {
|
|
22
|
+
cx: "12",
|
|
23
|
+
cy: "12",
|
|
24
|
+
r: "3"
|
|
25
|
+
})]
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
function l() {
|
|
29
|
+
return /* @__PURE__ */ s("svg", {
|
|
30
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
31
|
+
width: "1.25em",
|
|
32
|
+
height: "1.25em",
|
|
33
|
+
viewBox: "0 0 24 24",
|
|
34
|
+
fill: "none",
|
|
35
|
+
stroke: "currentColor",
|
|
36
|
+
strokeWidth: "2",
|
|
37
|
+
strokeLinecap: "round",
|
|
38
|
+
strokeLinejoin: "round",
|
|
39
|
+
"aria-hidden": !0,
|
|
40
|
+
children: [/* @__PURE__ */ o("path", { d: "M17.94 17.94A10.07 10.07 0 0 1 12 20c-7 0-11-8-11-8a18.45 18.45 0 0 1 5.06-5.94M9.9 4.24A9.12 9.12 0 0 1 12 4c7 0 11 8 11 8a18.5 18.5 0 0 1-2.16 3.19m-6.72-1.07a3 3 0 1 1-4.24-4.24" }), /* @__PURE__ */ o("line", {
|
|
41
|
+
x1: "1",
|
|
42
|
+
y1: "1",
|
|
43
|
+
x2: "23",
|
|
44
|
+
y2: "23"
|
|
45
|
+
})]
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
function u({ value: u, form: d, onValue: f, name: p = "", placeholder: m = "", label: h, error: g, hidden: _ = !1, disabled: v = !1, onBlur: y, className: b, after: x = "", before: S = "", native: C = !1, maxLength: w, eyes: T }) {
|
|
49
|
+
let [E, D] = a.useState(!1), { value: O } = n(d, p, u), k = a.useRef(null), A = typeof O == "string" ? O : O == null ? "" : String(O);
|
|
50
|
+
a.useEffect(() => {
|
|
51
|
+
let e = k.current;
|
|
52
|
+
e && e.value !== A && (e.value = A);
|
|
53
|
+
}, [A]);
|
|
54
|
+
let j = (e) => {
|
|
55
|
+
let t = {
|
|
56
|
+
value: e,
|
|
57
|
+
name: p
|
|
58
|
+
};
|
|
59
|
+
d && p && d.onValue(t), f && f !== d?.onValue && f(t);
|
|
60
|
+
}, M = (e) => {
|
|
61
|
+
j(e.target.value);
|
|
62
|
+
}, N = (e) => {
|
|
63
|
+
e.key === "Enter" && e.preventDefault();
|
|
64
|
+
}, P = (e) => {
|
|
65
|
+
r.Blur(e), y?.({
|
|
66
|
+
value: (e.target.value || "").trim(),
|
|
67
|
+
name: p || ""
|
|
68
|
+
});
|
|
69
|
+
};
|
|
70
|
+
if (C) return "";
|
|
71
|
+
let F = !v;
|
|
72
|
+
if (_ && i(A)) return "";
|
|
73
|
+
let I = T?.[0] ?? /* @__PURE__ */ o(c, {}), L = T?.[1] ?? /* @__PURE__ */ o(l, {});
|
|
74
|
+
return /* @__PURE__ */ s(t, {
|
|
75
|
+
type: "input",
|
|
76
|
+
label: h,
|
|
77
|
+
error: g,
|
|
78
|
+
element_blok: { className: [b || ""] },
|
|
79
|
+
element_input: {
|
|
80
|
+
className: [e.w],
|
|
81
|
+
props: { "data-disabled": v || !F ? "true" : void 0 }
|
|
82
|
+
},
|
|
83
|
+
children: [
|
|
84
|
+
S,
|
|
85
|
+
/* @__PURE__ */ o("div", {
|
|
86
|
+
style: {
|
|
87
|
+
flex: 1,
|
|
88
|
+
minWidth: 0,
|
|
89
|
+
display: "flex",
|
|
90
|
+
alignItems: "center"
|
|
91
|
+
},
|
|
92
|
+
children: /* @__PURE__ */ o("input", {
|
|
93
|
+
type: E ? "text" : "password",
|
|
94
|
+
defaultValue: A,
|
|
95
|
+
ref: k,
|
|
96
|
+
onChange: M,
|
|
97
|
+
onKeyDown: N,
|
|
98
|
+
onBlur: P,
|
|
99
|
+
disabled: v,
|
|
100
|
+
readOnly: v,
|
|
101
|
+
maxLength: w,
|
|
102
|
+
spellCheck: !1,
|
|
103
|
+
autoComplete: "current-password",
|
|
104
|
+
"aria-label": h || m || "Пароль",
|
|
105
|
+
"aria-disabled": v || !F,
|
|
106
|
+
tabIndex: v ? -1 : 0,
|
|
107
|
+
placeholder: m,
|
|
108
|
+
style: {
|
|
109
|
+
width: "100%",
|
|
110
|
+
border: "none",
|
|
111
|
+
outline: "none",
|
|
112
|
+
background: "transparent",
|
|
113
|
+
font: "inherit",
|
|
114
|
+
color: "inherit",
|
|
115
|
+
padding: 0,
|
|
116
|
+
margin: 0,
|
|
117
|
+
boxSizing: "border-box"
|
|
118
|
+
}
|
|
119
|
+
})
|
|
120
|
+
}),
|
|
121
|
+
/* @__PURE__ */ o("button", {
|
|
122
|
+
type: "button",
|
|
123
|
+
tabIndex: v ? -1 : 0,
|
|
124
|
+
"aria-label": E ? "Скрыть пароль" : "Показать пароль",
|
|
125
|
+
"aria-pressed": E,
|
|
126
|
+
disabled: v,
|
|
127
|
+
onClick: () => !v && D(!E),
|
|
128
|
+
onKeyDown: (e) => {
|
|
129
|
+
v || (e.key === "Enter" || e.key === " ") && (e.preventDefault(), D(!E));
|
|
130
|
+
},
|
|
131
|
+
style: {
|
|
132
|
+
cursor: v ? "not-allowed" : "pointer",
|
|
133
|
+
alignSelf: "center",
|
|
134
|
+
display: "inline-flex",
|
|
135
|
+
alignItems: "center",
|
|
136
|
+
justifyContent: "center",
|
|
137
|
+
padding: "4px",
|
|
138
|
+
margin: 0,
|
|
139
|
+
marginRight: "8px",
|
|
140
|
+
border: "none",
|
|
141
|
+
background: "transparent",
|
|
142
|
+
color: "inherit",
|
|
143
|
+
font: "inherit"
|
|
144
|
+
},
|
|
145
|
+
children: E ? L : I
|
|
146
|
+
}),
|
|
147
|
+
x
|
|
148
|
+
]
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
u.displayName = "PasswordField";
|
|
152
|
+
//#endregion
|
|
153
|
+
export { u as default };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { TInput } from './type';
|
|
2
|
+
/** PhoneField — телефон с маской и копированием в буфер (через Form.Init → onNotice). */
|
|
3
|
+
declare function PhoneField({ value, form, onValue, onBlur: onBlurField, name, placeholder, label, error, hidden, disabled, className, after, before, inputmode, view, }: TInput): import("react/jsx-runtime").JSX.Element;
|
|
4
|
+
declare namespace PhoneField {
|
|
5
|
+
var displayName: string;
|
|
6
|
+
}
|
|
7
|
+
export default PhoneField;
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import e from "../styles/Field.module.js";
|
|
2
|
+
import t from "../core/Field.js";
|
|
3
|
+
import { useFormFieldState as n } from "../hooks/use.js";
|
|
4
|
+
import r, { asEditableClipboard as i } from "../events/onEvent.js";
|
|
5
|
+
import { isEmptyTextLike as a } from "./visibility.js";
|
|
6
|
+
import o from "../mask/MaskPhone.js";
|
|
7
|
+
import { useFormInit as s } from "../FormInitContext.js";
|
|
8
|
+
import "react";
|
|
9
|
+
import { Fragment as c, jsx as l, jsxs as u } from "react/jsx-runtime";
|
|
10
|
+
//#region src/lib/fields/Phone.tsx
|
|
11
|
+
function d(e) {
|
|
12
|
+
let t = window.getSelection();
|
|
13
|
+
if (!t || t.rangeCount === 0) return 0;
|
|
14
|
+
let n = t.getRangeAt(0);
|
|
15
|
+
if (!e.contains(n.startContainer)) return 0;
|
|
16
|
+
let r = document.createRange();
|
|
17
|
+
return r.selectNodeContents(e), r.setEnd(n.startContainer, n.startOffset), r.toString().length;
|
|
18
|
+
}
|
|
19
|
+
function f(e, t) {
|
|
20
|
+
if (t <= 0) return 0;
|
|
21
|
+
let n = 0;
|
|
22
|
+
for (let r = 0; r < e.length; r++) if (/\d/.test(e[r]) && (n++, n === t)) return r + 1;
|
|
23
|
+
return e.length;
|
|
24
|
+
}
|
|
25
|
+
function p({ value: p, form: m, onValue: h, onBlur: g, name: _ = "", placeholder: v = "", label: y = "", error: b = "", hidden: x = !1, disabled: S = !1, className: C = "", after: w = "", before: T = "", inputmode: E = "tel", view: D }) {
|
|
26
|
+
let { onNotice: O } = s(), k = !S, { value: A, version: j } = n(m, _, p), M = "+_(___) ___-__-__", N = !0, P = 0, F = (e, t) => {
|
|
27
|
+
let n = t.firstChild;
|
|
28
|
+
if (!n || n.nodeType !== Node.TEXT_NODE) return;
|
|
29
|
+
let r = n.textContent?.length ?? 0, i = Math.max(0, Math.min(e, r)), a = document.createRange(), o = window.getSelection();
|
|
30
|
+
o && (a.setStart(n, i), a.collapse(!0), o.removeAllRanges(), o.addRange(a), t.focus());
|
|
31
|
+
}, I = (e) => {
|
|
32
|
+
let t = e.target, n = t.textContent || "", r = d(t), i = n.slice(0, r).replace(/\D/g, "").length, a = R(n);
|
|
33
|
+
t.textContent = a.q;
|
|
34
|
+
let o = f(a.q, i);
|
|
35
|
+
a.q.length > 0 && queueMicrotask(() => {
|
|
36
|
+
F(Math.min(o, a.q.length), t);
|
|
37
|
+
});
|
|
38
|
+
let s = {
|
|
39
|
+
value: a.q.replace(/\D/g, ""),
|
|
40
|
+
name: _ || ""
|
|
41
|
+
};
|
|
42
|
+
m && _ && m.onValue(s), h && h !== m?.onValue && h(s);
|
|
43
|
+
}, L = (e) => r.PasteOne(i(e)), R = (e) => {
|
|
44
|
+
M = "+_(___) ___-__-__", N = !0, P = 0;
|
|
45
|
+
let t = 0, n = "", r = e.replace(/\D/g, "");
|
|
46
|
+
r === "" && (N = !0);
|
|
47
|
+
let i = r.split(""), a = "";
|
|
48
|
+
i.forEach((e) => {
|
|
49
|
+
N && (a += e, o[a] !== void 0 && N ? (N = !1, M = o[a].mask.replace(/* @__PURE__ */ RegExp("[0-9]", "g"), "_"), n = o[a].code) : (N && (P = ("" + a).length, M = `+${a}_(___) ___-__-__`.replace(/* @__PURE__ */ RegExp("[0-9]", "g"), "_"), n = ""), P > ("" + a).length && (N = !0, M = `+${a}_(___) ___-__-__`.replace(/* @__PURE__ */ RegExp("[0-9]", "g"), "_"), n = "")));
|
|
50
|
+
});
|
|
51
|
+
let s = M.replace(/\D/g, "");
|
|
52
|
+
return s.length >= r.length && (r = s), {
|
|
53
|
+
q: M.replace(/[_\d]/g, function() {
|
|
54
|
+
return r.charAt(t++) || "_";
|
|
55
|
+
}),
|
|
56
|
+
i: t,
|
|
57
|
+
v: r,
|
|
58
|
+
f: n
|
|
59
|
+
};
|
|
60
|
+
}, z = (e) => {
|
|
61
|
+
e.preventDefault();
|
|
62
|
+
let t = e.target;
|
|
63
|
+
navigator.clipboard.writeText((t.textContent || "").replace(/\D/g, "")).then(function() {
|
|
64
|
+
O("Данные в буфер обмене");
|
|
65
|
+
}, function(e) {
|
|
66
|
+
console.error("Async: Could not copy text: ", e);
|
|
67
|
+
});
|
|
68
|
+
}, B = R(String(A || "")), V = (e) => {
|
|
69
|
+
e.key === "Enter" && e.preventDefault();
|
|
70
|
+
}, H = (e) => {
|
|
71
|
+
r.Blur(e), g && g({
|
|
72
|
+
value: (e.target.textContent || "").replace(/\D/g, ""),
|
|
73
|
+
name: _ || ""
|
|
74
|
+
});
|
|
75
|
+
}, U = (e) => {
|
|
76
|
+
r.Focus({ target: e.currentTarget });
|
|
77
|
+
}, W = {};
|
|
78
|
+
v && (W.placeholder = v), W.inputMode = E ?? "tel";
|
|
79
|
+
let G = String(A ?? "").replace(/\D/g, "");
|
|
80
|
+
return x && a(G) ? /* @__PURE__ */ l(c, {}) : /* @__PURE__ */ u(t, {
|
|
81
|
+
type: "input",
|
|
82
|
+
label: y,
|
|
83
|
+
error: b,
|
|
84
|
+
element_blok: { className: [C] },
|
|
85
|
+
element_input: { className: [e.w] },
|
|
86
|
+
children: [
|
|
87
|
+
T,
|
|
88
|
+
/* @__PURE__ */ l("div", {
|
|
89
|
+
onPaste: L,
|
|
90
|
+
onInput: I,
|
|
91
|
+
onKeyDown: V,
|
|
92
|
+
onContextMenu: z,
|
|
93
|
+
onBlur: H,
|
|
94
|
+
onFocus: U,
|
|
95
|
+
spellCheck: !1,
|
|
96
|
+
role: "textbox",
|
|
97
|
+
"aria-label": y || v || "Телефон",
|
|
98
|
+
"aria-disabled": !k,
|
|
99
|
+
tabIndex: S ? -1 : 0,
|
|
100
|
+
"data-disabled": !k,
|
|
101
|
+
contentEditable: k ? "plaintext-only" : !1,
|
|
102
|
+
suppressContentEditableWarning: !0,
|
|
103
|
+
...W,
|
|
104
|
+
children: B.q
|
|
105
|
+
}, j),
|
|
106
|
+
w
|
|
107
|
+
]
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
p.displayName = "PhoneField";
|
|
111
|
+
//#endregion
|
|
112
|
+
export { p as default };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { TInput } from './type';
|
|
2
|
+
/** Поле «диапазон»: кастомный трек (div), визуально как «таблетка» с заливкой, без нативного range */
|
|
3
|
+
export type TRange = TInput & {
|
|
4
|
+
min?: number;
|
|
5
|
+
max?: number;
|
|
6
|
+
step?: number;
|
|
7
|
+
};
|
|
8
|
+
/** @deprecated — используйте `TRange` */
|
|
9
|
+
export type TProgress = TRange;
|
|
10
|
+
declare function RangeField({ value, form, onValue, onBlur: onBlurField, name, placeholder, label, error, hidden, disabled, className, after, before, min, max, step, }: TRange): import("react/jsx-runtime").JSX.Element | null;
|
|
11
|
+
declare namespace RangeField {
|
|
12
|
+
var displayName: string;
|
|
13
|
+
}
|
|
14
|
+
export default RangeField;
|
|
15
|
+
/** Псевдоним для обратной совместимости */
|
|
16
|
+
export { RangeField as ProgressField };
|