@elcrm/form 0.0.62 → 0.0.64
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 +113 -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 +18 -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/{src/lib/fields → fields}/Date.d.ts +7 -3
- package/dist/fields/Date.js +345 -0
- package/dist/{src/lib/fields → fields}/Input.d.ts +2 -2
- package/dist/fields/Input.js +55 -0
- package/dist/fields/Mask.d.ts +9 -0
- package/dist/fields/Mask.js +95 -0
- package/dist/fields/Modal.d.ts +25 -0
- package/dist/fields/Modal.js +55 -0
- package/dist/fields/Money.d.ts +35 -0
- package/dist/fields/Money.js +93 -0
- package/dist/fields/Numeric.d.ts +9 -0
- package/dist/fields/Numeric.js +69 -0
- package/dist/fields/Options.d.ts +30 -0
- package/dist/fields/Options.js +63 -0
- package/dist/fields/Password.d.ts +6 -0
- package/dist/fields/Password.js +100 -0
- package/dist/{src/lib/fields → fields}/Phone.d.ts +5 -1
- package/dist/fields/Phone.js +109 -0
- package/dist/fields/Range.d.ts +16 -0
- package/dist/fields/Range.js +101 -0
- package/dist/fields/Select.d.ts +21 -0
- package/dist/fields/Select.js +143 -0
- package/dist/{src/lib/fields → fields}/Textarea.d.ts +5 -1
- package/dist/fields/Textarea.js +47 -0
- package/dist/fields/Time.d.ts +26 -0
- package/dist/fields/Time.js +252 -0
- package/dist/fields/type.d.ts +42 -0
- package/dist/hooks/use.d.ts +42 -0
- package/dist/hooks/use.js +57 -0
- package/dist/index.d.ts +26 -2
- package/dist/index.js +26 -0
- package/dist/index.umd.js +2 -89
- package/dist/mask/MaskPhone.d.ts +8 -0
- package/dist/mask/MaskPhone.js +1384 -0
- package/dist/package.js +96 -0
- package/dist/style.css +5 -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/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/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/Select copy.d.ts +0 -23
- package/dist/src/lib/fields/Select.d.ts +0 -28
- 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,93 @@
|
|
|
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 "react";
|
|
6
|
+
import { jsx as a, jsxs as o } from "react/jsx-runtime";
|
|
7
|
+
//#region src/lib/fields/Money.tsx
|
|
8
|
+
function s(e) {
|
|
9
|
+
let t = window.getSelection();
|
|
10
|
+
if (!t || t.rangeCount === 0) return 0;
|
|
11
|
+
let n = t.getRangeAt(0);
|
|
12
|
+
if (!e.contains(n.startContainer)) return 0;
|
|
13
|
+
let r = document.createRange();
|
|
14
|
+
return r.selectNodeContents(e), r.setEnd(n.startContainer, n.startOffset), r.toString().length;
|
|
15
|
+
}
|
|
16
|
+
function c(e, t, n) {
|
|
17
|
+
let r = Math.max(0, Math.min(t, e.length));
|
|
18
|
+
return n(e.slice(0, r)).length;
|
|
19
|
+
}
|
|
20
|
+
function l({ value: l, form: d, onValue: f, name: p, placeholder: m = "", title: h = "", error: g = "", hide: _ = !1, edit: v = !0, active: y = !0, after: b = "", show: x = !0, course: S = 100, view: C, type: w, onSave: T, className: E = "", isClear: D = !1, disabled: O = !1 }) {
|
|
21
|
+
let { value: k, version: A } = n(d, p || "", l), j = d && p ? k : l, M = !!(_ && (j === "" || j == null)), N = (e) => w === "multi" ? e.replace(/[^+\d.+-]/g, "") : e.replace(/[^+\d.]/g, ""), P = (e, t) => {
|
|
22
|
+
let n = t.firstChild;
|
|
23
|
+
if (!n || n.nodeType !== Node.TEXT_NODE) return;
|
|
24
|
+
let r = n.textContent?.length ?? 0, i = Math.max(0, Math.min(e, r)), a = document.createRange(), o = window.getSelection();
|
|
25
|
+
o && (a.setStart(n, i), a.collapse(!0), o.removeAllRanges(), o.addRange(a), t.focus());
|
|
26
|
+
}, F = (e) => {
|
|
27
|
+
let t = e.target, n = t.textContent || "", r = s(t), i = N(n), a = c(n, r, N), o = {
|
|
28
|
+
value: Number(i || 0) * S,
|
|
29
|
+
name: p
|
|
30
|
+
};
|
|
31
|
+
d && p && d.onValue(o), f && f !== d?.onValue && f(o), t.textContent = i, i.length > 0 && queueMicrotask(() => {
|
|
32
|
+
P(Math.min(a, i.length), t);
|
|
33
|
+
});
|
|
34
|
+
}, I = (e) => {
|
|
35
|
+
let t = e.target;
|
|
36
|
+
r.Blur(e), (t.textContent || "") === "" && (t.textContent = "0");
|
|
37
|
+
let n = {
|
|
38
|
+
value: Number(N(t.textContent || "")) * S,
|
|
39
|
+
name: p
|
|
40
|
+
};
|
|
41
|
+
T?.(n), d && p && d.setValue(n), f && f !== d?.onValue && f(n), t.textContent = u(t.textContent || "");
|
|
42
|
+
}, L = (e) => {
|
|
43
|
+
let t = e.target;
|
|
44
|
+
t.textContent = N(t.textContent || ""), r.Focus({ target: e.currentTarget });
|
|
45
|
+
}, R = (e) => {
|
|
46
|
+
let t = e.currentTarget.previousElementSibling;
|
|
47
|
+
t && (t.textContent = "");
|
|
48
|
+
let n = {
|
|
49
|
+
value: 0,
|
|
50
|
+
name: p
|
|
51
|
+
};
|
|
52
|
+
d && p && d.setValue(n), f && f !== d?.onValue && f(n);
|
|
53
|
+
}, z = (e) => {
|
|
54
|
+
e.key === "Enter" && e.preventDefault();
|
|
55
|
+
}, B = (e) => {
|
|
56
|
+
e.preventDefault(), i(N(e.clipboardData?.getData("text/plain") ?? ""), e.currentTarget);
|
|
57
|
+
};
|
|
58
|
+
if (!(v && y) && !x || !(v && y) && M) return "";
|
|
59
|
+
let V = {};
|
|
60
|
+
return V.inputMode = "decimal", m && (V.placeholder = m), v && y && (V.edit = ""), /* @__PURE__ */ o(t, {
|
|
61
|
+
type: "input",
|
|
62
|
+
title: h,
|
|
63
|
+
element_blok: { className: [E] },
|
|
64
|
+
element_input: { className: [e.w] },
|
|
65
|
+
children: [/* @__PURE__ */ a("div", {
|
|
66
|
+
...V,
|
|
67
|
+
onInput: F,
|
|
68
|
+
onPaste: B,
|
|
69
|
+
onBlur: I,
|
|
70
|
+
onKeyDown: z,
|
|
71
|
+
onFocus: L,
|
|
72
|
+
role: "textbox",
|
|
73
|
+
"aria-label": h || m || "Сумма",
|
|
74
|
+
"aria-disabled": O || !(v && y),
|
|
75
|
+
tabIndex: O ? -1 : 0,
|
|
76
|
+
contentEditable: v && y && !O ? "plaintext-only" : !1,
|
|
77
|
+
suppressContentEditableWarning: !0,
|
|
78
|
+
"data-after": b,
|
|
79
|
+
children: !m || j ? u(j ?? "") : ""
|
|
80
|
+
}, A), D && /* @__PURE__ */ a("button", {
|
|
81
|
+
type: "button",
|
|
82
|
+
onClick: R,
|
|
83
|
+
"aria-label": "Очистить поле",
|
|
84
|
+
children: "x"
|
|
85
|
+
})]
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
l.displayName = "MoneyField";
|
|
89
|
+
function u(e, t) {
|
|
90
|
+
return t && (e = Number(e) / t), parseFloat(String(e || 0)).toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, "$1 ");
|
|
91
|
+
}
|
|
92
|
+
//#endregion
|
|
93
|
+
export { l as default };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { TInput } from './type';
|
|
2
|
+
type TNumeric = TInput & {
|
|
3
|
+
max?: number;
|
|
4
|
+
};
|
|
5
|
+
declare function NumberField({ form, onValue, onSave, active, max, edit, title, error, show, hide, value, placeholder, className, maxLength, name, after, before, view, }: TNumeric): import("react/jsx-runtime").JSX.Element;
|
|
6
|
+
declare namespace NumberField {
|
|
7
|
+
var displayName: string;
|
|
8
|
+
}
|
|
9
|
+
export default NumberField;
|
|
@@ -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 r, { asEditableClipboard as i } from "../events/onEvent.js";
|
|
5
|
+
import "react";
|
|
6
|
+
import { Fragment as a, jsx as o } from "react/jsx-runtime";
|
|
7
|
+
//#region src/lib/fields/Numeric.tsx
|
|
8
|
+
function s({ form: s, onValue: c, onSave: l, active: u, max: d, edit: f, title: p, error: m, show: h, hide: g, value: _, placeholder: v, className: y, maxLength: b, name: x = "", after: S = "", before: C = "", view: w }) {
|
|
9
|
+
f = f === void 0 ? !0 : f, u = u === void 0 ? !0 : u;
|
|
10
|
+
let { value: T, version: E } = n(s, x, _);
|
|
11
|
+
g = !!(g && (T === "" || T === void 0)) && !(f && u), v = v === void 0 ? "" : v, d = d === void 0 ? 99 : d;
|
|
12
|
+
let D = b ?? d, O = !1, k = (e) => {
|
|
13
|
+
let t = e.currentTarget, n = (t.textContent || "").replace(/\D/g, "");
|
|
14
|
+
n.length > D && (n = n.slice(0, D), 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: x
|
|
24
|
+
};
|
|
25
|
+
s && x && s.onValue(r), c && c !== s?.onValue && c(r);
|
|
26
|
+
}, A = (e) => {
|
|
27
|
+
let t = e.currentTarget;
|
|
28
|
+
t.textContent = (t.textContent || "").replace(/\D/g, ""), r.Focus({ target: e.currentTarget });
|
|
29
|
+
}, j = (e) => {
|
|
30
|
+
if (O && e.which === 86) return;
|
|
31
|
+
if (e.which === 17 || e.which === 91) return O = !0;
|
|
32
|
+
if (e.key === "Backspace") return;
|
|
33
|
+
let t = (e.currentTarget.textContent ?? "").replace(/\D/g, "").length;
|
|
34
|
+
D > 0 && t >= D && 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
|
+
}, M = (e) => {
|
|
36
|
+
if (e.which === 17 || e.which === 91) return O = !1;
|
|
37
|
+
}, N = (e) => r.PasteDigits(D, i(e)), P = (e) => {
|
|
38
|
+
r.Blur(e), l?.({
|
|
39
|
+
value: e.currentTarget.textContent,
|
|
40
|
+
name: x
|
|
41
|
+
});
|
|
42
|
+
}, F = {};
|
|
43
|
+
return f && u && (F.edit = ""), F.inputMode = "decimal", v && (F.placeholder = v), g ? /* @__PURE__ */ o(a, {}) : /* @__PURE__ */ o(t, {
|
|
44
|
+
type: "numeric",
|
|
45
|
+
title: p,
|
|
46
|
+
error: m,
|
|
47
|
+
element_blok: { className: [y || ""] },
|
|
48
|
+
element_input: { className: [e.w] },
|
|
49
|
+
children: /* @__PURE__ */ o("div", {
|
|
50
|
+
onPaste: N,
|
|
51
|
+
onInput: k,
|
|
52
|
+
onFocus: A,
|
|
53
|
+
onBlur: P,
|
|
54
|
+
onKeyDown: j,
|
|
55
|
+
onKeyUp: M,
|
|
56
|
+
spellCheck: !0,
|
|
57
|
+
role: "textbox",
|
|
58
|
+
tabIndex: f && u ? 0 : -1,
|
|
59
|
+
"aria-label": p || v || "Число",
|
|
60
|
+
contentEditable: f && u ? "plaintext-only" : !1,
|
|
61
|
+
suppressContentEditableWarning: !0,
|
|
62
|
+
...F,
|
|
63
|
+
children: T
|
|
64
|
+
}, E)
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
s.displayName = "NumberField";
|
|
68
|
+
//#endregion
|
|
69
|
+
export { s as default };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { UseFormApi } from '../hooks/use';
|
|
2
|
+
import { TValue } from './type';
|
|
3
|
+
interface Input {
|
|
4
|
+
value?: string;
|
|
5
|
+
form?: UseFormApi;
|
|
6
|
+
onValue?: (data: TValue) => void | Promise<void>;
|
|
7
|
+
name: string;
|
|
8
|
+
placeholder?: string;
|
|
9
|
+
title?: string;
|
|
10
|
+
error?: string;
|
|
11
|
+
hide?: boolean;
|
|
12
|
+
edit?: boolean;
|
|
13
|
+
show?: boolean;
|
|
14
|
+
active?: boolean;
|
|
15
|
+
after?: string;
|
|
16
|
+
view?: string;
|
|
17
|
+
className?: string;
|
|
18
|
+
module?: string;
|
|
19
|
+
modal?: string;
|
|
20
|
+
options?: Record<string, {
|
|
21
|
+
label?: string;
|
|
22
|
+
}>;
|
|
23
|
+
outFormat?: "array" | "string" | "object";
|
|
24
|
+
separator?: string;
|
|
25
|
+
}
|
|
26
|
+
declare function OptionsField({ value, form, onValue, name, placeholder, separator, title, error, hide, edit, active, outFormat, after, modal, options, className, }: Input): import("react/jsx-runtime").JSX.Element;
|
|
27
|
+
declare namespace OptionsField {
|
|
28
|
+
var displayName: string;
|
|
29
|
+
}
|
|
30
|
+
export default OptionsField;
|
|
@@ -0,0 +1,63 @@
|
|
|
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 } from "react/jsx-runtime";
|
|
6
|
+
//#region src/lib/fields/Options.tsx
|
|
7
|
+
var o = (e, t = ",") => (e !== void 0 && e !== "" ? e.split(t) : []).filter((e) => e !== "").reduce((e, t) => (e[t] = !0, e), {});
|
|
8
|
+
function s({ value: s, form: c, onValue: l, name: u, placeholder: d = "", separator: f = ",", title: p, error: m, hide: h = !1, edit: g = !0, active: _ = !0, outFormat: v = "object", after: y = "", modal: b, options: x, className: S }) {
|
|
9
|
+
let { onModal: C } = r(), { value: w } = n(c, u, s), T = w, E = typeof T == "string" ? o(T, f) : T && typeof T == "object" ? T : {}, D = () => {
|
|
10
|
+
if (!(g && _)) return;
|
|
11
|
+
if (!b) return console.error("modal - empty");
|
|
12
|
+
let e = b.split(".");
|
|
13
|
+
C({
|
|
14
|
+
module: e[0],
|
|
15
|
+
modalName: e[1],
|
|
16
|
+
callback: (e) => {
|
|
17
|
+
let t = e;
|
|
18
|
+
if (l) {
|
|
19
|
+
let e = {
|
|
20
|
+
value: v === "array" ? Object.keys(t) : v === "string" ? Object.keys(t).filter((e) => t[e]).join(f) : t,
|
|
21
|
+
name: u
|
|
22
|
+
};
|
|
23
|
+
switch (c && u && c.setValue(e), v) {
|
|
24
|
+
case "array":
|
|
25
|
+
l !== c?.onValue && l({
|
|
26
|
+
value: Object.keys(t),
|
|
27
|
+
name: u
|
|
28
|
+
});
|
|
29
|
+
break;
|
|
30
|
+
case "string":
|
|
31
|
+
l !== c?.onValue && l({
|
|
32
|
+
value: Object.keys(t).filter((e) => t[e]).join(f),
|
|
33
|
+
name: u
|
|
34
|
+
});
|
|
35
|
+
break;
|
|
36
|
+
default: l !== c?.onValue && l({
|
|
37
|
+
value: t,
|
|
38
|
+
name: u
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
onValue: l,
|
|
44
|
+
options: x,
|
|
45
|
+
fieldName: u,
|
|
46
|
+
value: E
|
|
47
|
+
});
|
|
48
|
+
}, O = {};
|
|
49
|
+
return d && (O.placeholder = d), h ? /* @__PURE__ */ a(i, {}) : /* @__PURE__ */ a(t, {
|
|
50
|
+
type: "group",
|
|
51
|
+
title: p,
|
|
52
|
+
error: m,
|
|
53
|
+
element_blok: { className: [S || ""] },
|
|
54
|
+
element_input: {
|
|
55
|
+
className: [e.g],
|
|
56
|
+
props: { onClick: D }
|
|
57
|
+
},
|
|
58
|
+
children: Object.keys(E).map((e) => /* @__PURE__ */ a("div", { children: x?.[e]?.label }, e))
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
s.displayName = "OptionsField";
|
|
62
|
+
//#endregion
|
|
63
|
+
export { s as default };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { TPasswordField } from './type';
|
|
2
|
+
declare function PasswordField({ value, form, onValue, onSave, name, placeholder, className, title, label, error, edit, active, isReload, native, isShow, maxLength, eyes, after, disabled, }: TPasswordField): import("react/jsx-runtime").JSX.Element | "";
|
|
3
|
+
declare namespace PasswordField {
|
|
4
|
+
var displayName: string;
|
|
5
|
+
}
|
|
6
|
+
export default PasswordField;
|
|
@@ -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 from "../events/onEvent.js";
|
|
5
|
+
import i from "react";
|
|
6
|
+
import { jsx as a, jsxs as o } from "react/jsx-runtime";
|
|
7
|
+
//#region src/lib/fields/Password.tsx
|
|
8
|
+
function s({ value: s, form: c, onValue: l, onSave: u, name: d = "", placeholder: f = "", className: p, title: m, label: h, error: g, edit: _ = !0, active: v = !0, isReload: y = !1, native: b = !1, isShow: x = !1, maxLength: S, eyes: C = [], after: w = "", disabled: T = !1 }) {
|
|
9
|
+
let [E, D] = i.useState(x), { value: O } = n(c, d, s), k = i.useRef(null), A = typeof O == "string" ? O : O == null ? "" : String(O);
|
|
10
|
+
i.useEffect(() => {
|
|
11
|
+
let e = k.current;
|
|
12
|
+
e && e.value !== A && (e.value = A);
|
|
13
|
+
}, [A]);
|
|
14
|
+
let j = (e) => {
|
|
15
|
+
let t = {
|
|
16
|
+
value: e,
|
|
17
|
+
name: d,
|
|
18
|
+
reload: y
|
|
19
|
+
};
|
|
20
|
+
c && d && c.onValue(t), l && l !== c?.onValue && l(t);
|
|
21
|
+
}, M = (e) => {
|
|
22
|
+
j(e.target.value);
|
|
23
|
+
}, N = (e) => {
|
|
24
|
+
e.key === "Enter" && e.preventDefault();
|
|
25
|
+
}, P = (e) => {
|
|
26
|
+
r.Blur(e), u?.({
|
|
27
|
+
value: (e.target.value || "").trim(),
|
|
28
|
+
name: d || ""
|
|
29
|
+
});
|
|
30
|
+
};
|
|
31
|
+
if (b) return "";
|
|
32
|
+
let F = _ && v && !T;
|
|
33
|
+
return /* @__PURE__ */ o(t, {
|
|
34
|
+
type: "input",
|
|
35
|
+
title: m || h,
|
|
36
|
+
error: g,
|
|
37
|
+
element_blok: { className: [p || ""] },
|
|
38
|
+
element_input: {
|
|
39
|
+
className: [e.w],
|
|
40
|
+
props: { "data-disabled": T || !F ? "true" : void 0 }
|
|
41
|
+
},
|
|
42
|
+
children: [
|
|
43
|
+
/* @__PURE__ */ a("div", {
|
|
44
|
+
style: {
|
|
45
|
+
flex: 1,
|
|
46
|
+
minWidth: 0,
|
|
47
|
+
display: "flex",
|
|
48
|
+
alignItems: "center"
|
|
49
|
+
},
|
|
50
|
+
children: /* @__PURE__ */ a("input", {
|
|
51
|
+
type: E ? "text" : "password",
|
|
52
|
+
defaultValue: A,
|
|
53
|
+
ref: k,
|
|
54
|
+
onChange: M,
|
|
55
|
+
onKeyDown: N,
|
|
56
|
+
onBlur: P,
|
|
57
|
+
disabled: T,
|
|
58
|
+
readOnly: !_ || !v,
|
|
59
|
+
maxLength: S,
|
|
60
|
+
spellCheck: !1,
|
|
61
|
+
autoComplete: "current-password",
|
|
62
|
+
"aria-label": m || h || f || "Пароль",
|
|
63
|
+
"aria-disabled": T || !F,
|
|
64
|
+
tabIndex: T ? -1 : 0,
|
|
65
|
+
placeholder: f,
|
|
66
|
+
style: {
|
|
67
|
+
width: "100%",
|
|
68
|
+
border: "none",
|
|
69
|
+
outline: "none",
|
|
70
|
+
background: "transparent",
|
|
71
|
+
font: "inherit",
|
|
72
|
+
color: "inherit",
|
|
73
|
+
padding: 0,
|
|
74
|
+
margin: 0,
|
|
75
|
+
boxSizing: "border-box"
|
|
76
|
+
}
|
|
77
|
+
})
|
|
78
|
+
}),
|
|
79
|
+
C[0] ? /* @__PURE__ */ a("i", {
|
|
80
|
+
role: "button",
|
|
81
|
+
tabIndex: T ? -1 : 0,
|
|
82
|
+
"aria-label": E ? "Скрыть пароль" : "Показать пароль",
|
|
83
|
+
"aria-pressed": E,
|
|
84
|
+
onClick: () => !T && D(!E),
|
|
85
|
+
onKeyDown: (e) => {
|
|
86
|
+
T || (e.key === "Enter" || e.key === " ") && (e.preventDefault(), D(!E));
|
|
87
|
+
},
|
|
88
|
+
style: {
|
|
89
|
+
cursor: T ? "not-allowed" : "pointer",
|
|
90
|
+
alignSelf: "center"
|
|
91
|
+
},
|
|
92
|
+
children: E ? C[1] : C[0]
|
|
93
|
+
}) : null,
|
|
94
|
+
w
|
|
95
|
+
]
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
s.displayName = "PasswordField";
|
|
99
|
+
//#endregion
|
|
100
|
+
export { s as default };
|
|
@@ -18,4 +18,8 @@ import { TInput } from './type';
|
|
|
18
18
|
* @param {string} [view] - тип view
|
|
19
19
|
* @param {string} [className] - css class
|
|
20
20
|
*/
|
|
21
|
-
|
|
21
|
+
declare function PhoneField({ value, form, onValue, onSave, name, placeholder, title, label, error, hide, edit, active, after, show, view, className, disabled, }: TInput): import("react/jsx-runtime").JSX.Element;
|
|
22
|
+
declare namespace PhoneField {
|
|
23
|
+
var displayName: string;
|
|
24
|
+
}
|
|
25
|
+
export default PhoneField;
|
|
@@ -0,0 +1,109 @@
|
|
|
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 a from "../mask/MaskPhone.js";
|
|
6
|
+
import { useFormInit as o } from "../FormInitContext.js";
|
|
7
|
+
import "react";
|
|
8
|
+
import { Fragment as s, jsx as c } from "react/jsx-runtime";
|
|
9
|
+
//#region src/lib/fields/Phone.tsx
|
|
10
|
+
function l(e) {
|
|
11
|
+
let t = window.getSelection();
|
|
12
|
+
if (!t || t.rangeCount === 0) return 0;
|
|
13
|
+
let n = t.getRangeAt(0);
|
|
14
|
+
if (!e.contains(n.startContainer)) return 0;
|
|
15
|
+
let r = document.createRange();
|
|
16
|
+
return r.selectNodeContents(e), r.setEnd(n.startContainer, n.startOffset), r.toString().length;
|
|
17
|
+
}
|
|
18
|
+
function u(e, t) {
|
|
19
|
+
if (t <= 0) return 0;
|
|
20
|
+
let n = 0;
|
|
21
|
+
for (let r = 0; r < e.length; r++) if (/\d/.test(e[r]) && (n++, n === t)) return r + 1;
|
|
22
|
+
return e.length;
|
|
23
|
+
}
|
|
24
|
+
function d({ value: d, form: f, onValue: p, onSave: m, name: h = "", placeholder: g = "", title: _ = "", label: v = "", error: y = "", hide: b = !1, edit: x = !0, active: S = !0, after: C = "", show: w = !0, view: T, className: E = "", disabled: D = !1 }) {
|
|
25
|
+
let { onNotice: O } = o();
|
|
26
|
+
x = x === void 0 ? !0 : x, S = S === void 0 ? !0 : S;
|
|
27
|
+
let { value: k, version: A } = n(f, h, d);
|
|
28
|
+
b = !!(b && (k === "" || k === void 0)) && !(x && S);
|
|
29
|
+
let j = "+_(___) ___-__-__", M = !0, N = 0, P = (e, t) => {
|
|
30
|
+
let n = t.firstChild;
|
|
31
|
+
if (!n || n.nodeType !== Node.TEXT_NODE) return;
|
|
32
|
+
let r = n.textContent?.length ?? 0, i = Math.max(0, Math.min(e, r)), a = document.createRange(), o = window.getSelection();
|
|
33
|
+
o && (a.setStart(n, i), a.collapse(!0), o.removeAllRanges(), o.addRange(a), t.focus());
|
|
34
|
+
}, F = (e) => {
|
|
35
|
+
let t = e.target, n = t.textContent || "", r = l(t), i = n.slice(0, r).replace(/\D/g, "").length, a = L(n);
|
|
36
|
+
t.textContent = a.q;
|
|
37
|
+
let o = u(a.q, i);
|
|
38
|
+
a.q.length > 0 && queueMicrotask(() => {
|
|
39
|
+
P(Math.min(o, a.q.length), t);
|
|
40
|
+
});
|
|
41
|
+
let s = {
|
|
42
|
+
value: a.q.replace(/\D/g, ""),
|
|
43
|
+
name: h || ""
|
|
44
|
+
};
|
|
45
|
+
f && h && f.onValue(s), p && p !== f?.onValue && p(s);
|
|
46
|
+
}, I = (e) => r.PasteOne(i(e)), L = (e) => {
|
|
47
|
+
j = "+_(___) ___-__-__", M = !0, N = 0;
|
|
48
|
+
let t = 0, n = "", r = e.replace(/\D/g, "");
|
|
49
|
+
r === "" && (M = !0);
|
|
50
|
+
let i = r.split(""), o = "";
|
|
51
|
+
i.forEach((e) => {
|
|
52
|
+
M && (o += e, a[o] !== void 0 && M ? (M = !1, j = a[o].mask.replace(/* @__PURE__ */ RegExp("[0-9]", "g"), "_"), n = a[o].code) : (M && (N = ("" + o).length, j = `+${o}_(___) ___-__-__`.replace(/* @__PURE__ */ RegExp("[0-9]", "g"), "_"), n = ""), N > ("" + o).length && (M = !0, j = `+${o}_(___) ___-__-__`.replace(/* @__PURE__ */ RegExp("[0-9]", "g"), "_"), n = "")));
|
|
53
|
+
});
|
|
54
|
+
let s = j.replace(/\D/g, "");
|
|
55
|
+
return s.length >= r.length && (r = s), {
|
|
56
|
+
q: j.replace(/[_\d]/g, function() {
|
|
57
|
+
return r.charAt(t++) || "_";
|
|
58
|
+
}),
|
|
59
|
+
i: t,
|
|
60
|
+
v: r,
|
|
61
|
+
f: n
|
|
62
|
+
};
|
|
63
|
+
}, R = (e) => {
|
|
64
|
+
e.preventDefault();
|
|
65
|
+
let t = e.target;
|
|
66
|
+
navigator.clipboard.writeText((t.textContent || "").replace(/\D/g, "")).then(function() {
|
|
67
|
+
O("Данные в буфер обмене");
|
|
68
|
+
}, function(e) {
|
|
69
|
+
console.error("Async: Could not copy text: ", e);
|
|
70
|
+
});
|
|
71
|
+
}, z = L(String(k || "")), B = (e) => {
|
|
72
|
+
e.key === "Enter" && e.preventDefault();
|
|
73
|
+
}, V = (e) => {
|
|
74
|
+
r.Blur(e), m && m({
|
|
75
|
+
value: (e.target.textContent || "").replace(/\D/g, ""),
|
|
76
|
+
name: h || ""
|
|
77
|
+
});
|
|
78
|
+
}, H = (e) => {
|
|
79
|
+
r.Focus({ target: e.currentTarget });
|
|
80
|
+
}, U = {};
|
|
81
|
+
return g && (U.placeholder = g), b ? /* @__PURE__ */ c(s, {}) : /* @__PURE__ */ c(t, {
|
|
82
|
+
type: "input",
|
|
83
|
+
title: _ || v,
|
|
84
|
+
error: y,
|
|
85
|
+
element_blok: { className: [E] },
|
|
86
|
+
element_input: { className: [e.w] },
|
|
87
|
+
children: /* @__PURE__ */ c("div", {
|
|
88
|
+
onPaste: I,
|
|
89
|
+
onInput: F,
|
|
90
|
+
onKeyDown: B,
|
|
91
|
+
onContextMenu: R,
|
|
92
|
+
onBlur: V,
|
|
93
|
+
onFocus: H,
|
|
94
|
+
inputMode: "tel",
|
|
95
|
+
role: "textbox",
|
|
96
|
+
"aria-label": _ || v || g || "Телефон",
|
|
97
|
+
"aria-disabled": D || !(x && S),
|
|
98
|
+
tabIndex: D ? -1 : 0,
|
|
99
|
+
"data-disabled": D || !(x && S),
|
|
100
|
+
contentEditable: x && S && !D ? "plaintext-only" : !1,
|
|
101
|
+
suppressContentEditableWarning: !0,
|
|
102
|
+
...U,
|
|
103
|
+
children: z.q
|
|
104
|
+
}, A)
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
d.displayName = "PhoneField";
|
|
108
|
+
//#endregion
|
|
109
|
+
export { d 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, onSave, name, title, label, error, min, max, step, edit, active, disabled, className, isReload, }: TRange): import("react/jsx-runtime").JSX.Element;
|
|
11
|
+
declare namespace RangeField {
|
|
12
|
+
var displayName: string;
|
|
13
|
+
}
|
|
14
|
+
export default RangeField;
|
|
15
|
+
/** Псевдоним для обратной совместимости */
|
|
16
|
+
export { RangeField as ProgressField };
|
|
@@ -0,0 +1,101 @@
|
|
|
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 "react";
|
|
5
|
+
import { jsx as i } from "react/jsx-runtime";
|
|
6
|
+
//#region src/lib/fields/Range.tsx
|
|
7
|
+
function a(e, t, n) {
|
|
8
|
+
let r = e;
|
|
9
|
+
return Number.isFinite(r) || (r = t), Math.min(n, Math.max(t, r));
|
|
10
|
+
}
|
|
11
|
+
function o(e, t, n, r) {
|
|
12
|
+
return a(!Number.isFinite(r) || r <= 0 ? e : t + Math.round((e - t) / r) * r, t, n);
|
|
13
|
+
}
|
|
14
|
+
function s({ value: s = 0, form: c, onValue: l, onSave: u, name: d = "", title: f = "", label: p = "", error: m = "", min: h = 0, max: g = 100, step: _ = 1, edit: v = !0, active: y = !0, disabled: b = !1, className: x = "", isReload: S = !1 }) {
|
|
15
|
+
let { value: C } = n(c, d, s), w = a(Number(C), h, g), T = g === h ? 0 : (w - h) / (g - h) * 100, E = T >= 99.999, D = v && y && !b, O = r.useRef(null), k = r.useCallback((e) => {
|
|
16
|
+
let t = {
|
|
17
|
+
value: o(e, h, g, _),
|
|
18
|
+
name: d || "",
|
|
19
|
+
reload: S
|
|
20
|
+
};
|
|
21
|
+
c && d && c.setValue(t), l && l !== c?.onValue && l(t);
|
|
22
|
+
}, [
|
|
23
|
+
c,
|
|
24
|
+
d,
|
|
25
|
+
S,
|
|
26
|
+
l,
|
|
27
|
+
h,
|
|
28
|
+
g,
|
|
29
|
+
_
|
|
30
|
+
]), A = r.useCallback((e) => {
|
|
31
|
+
let t = O.current;
|
|
32
|
+
if (!t) return h;
|
|
33
|
+
let n = t.getBoundingClientRect(), r = n.width || 1;
|
|
34
|
+
return o(h + (e - n.left) / r * (g - h), h, g, _);
|
|
35
|
+
}, [
|
|
36
|
+
h,
|
|
37
|
+
g,
|
|
38
|
+
_
|
|
39
|
+
]), j = (e) => {
|
|
40
|
+
D && (e.preventDefault(), e.currentTarget.setPointerCapture(e.pointerId), k(A(e.clientX)));
|
|
41
|
+
}, M = (e) => {
|
|
42
|
+
D && e.currentTarget.hasPointerCapture(e.pointerId) && k(A(e.clientX));
|
|
43
|
+
}, N = (e) => {
|
|
44
|
+
try {
|
|
45
|
+
e.currentTarget.releasePointerCapture(e.pointerId);
|
|
46
|
+
} catch {}
|
|
47
|
+
}, P = (e) => {
|
|
48
|
+
if (!D) return;
|
|
49
|
+
let t = w;
|
|
50
|
+
if (e.key === "ArrowRight" || e.key === "ArrowUp") t = w + _;
|
|
51
|
+
else if (e.key === "ArrowLeft" || e.key === "ArrowDown") t = w - _;
|
|
52
|
+
else if (e.key === "Home") t = h;
|
|
53
|
+
else if (e.key === "End") t = g;
|
|
54
|
+
else if (e.key === "PageUp") t = w + _ * 10;
|
|
55
|
+
else if (e.key === "PageDown") t = w - _ * 10;
|
|
56
|
+
else return;
|
|
57
|
+
e.preventDefault(), k(o(t, h, g, _));
|
|
58
|
+
}, F = () => {
|
|
59
|
+
if (!u || !d) return;
|
|
60
|
+
let e = c && d ? c.getValue(d, s) : w;
|
|
61
|
+
u({
|
|
62
|
+
value: a(Number(e), h, g),
|
|
63
|
+
name: d
|
|
64
|
+
});
|
|
65
|
+
};
|
|
66
|
+
return /* @__PURE__ */ i(t, {
|
|
67
|
+
type: "range",
|
|
68
|
+
title: f || p,
|
|
69
|
+
error: m,
|
|
70
|
+
element_blok: { className: [x || ""] },
|
|
71
|
+
element_input: {
|
|
72
|
+
className: [e.w, e.range],
|
|
73
|
+
props: { "data-disabled": b || !D ? "true" : void 0 }
|
|
74
|
+
},
|
|
75
|
+
children: /* @__PURE__ */ i("div", { children: /* @__PURE__ */ i("div", {
|
|
76
|
+
ref: O,
|
|
77
|
+
className: e.rangeTrack,
|
|
78
|
+
role: "slider",
|
|
79
|
+
tabIndex: D ? 0 : -1,
|
|
80
|
+
"aria-label": f || p || "Диапазон",
|
|
81
|
+
"aria-valuemin": h,
|
|
82
|
+
"aria-valuemax": g,
|
|
83
|
+
"aria-valuenow": w,
|
|
84
|
+
"data-disabled": b || !D ? "true" : void 0,
|
|
85
|
+
onPointerDown: j,
|
|
86
|
+
onPointerMove: M,
|
|
87
|
+
onPointerUp: N,
|
|
88
|
+
onPointerCancel: N,
|
|
89
|
+
onKeyDown: P,
|
|
90
|
+
onBlur: F,
|
|
91
|
+
children: /* @__PURE__ */ i("div", {
|
|
92
|
+
className: E ? `${e.rangeFill} ${e.rangeFillFull}` : e.rangeFill,
|
|
93
|
+
style: { width: `${T}%` },
|
|
94
|
+
"aria-hidden": !0
|
|
95
|
+
})
|
|
96
|
+
}) })
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
s.displayName = "RangeField";
|
|
100
|
+
//#endregion
|
|
101
|
+
export { s as default };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { TInput } from './type';
|
|
2
|
+
type SelectOptionObject = Record<number, {
|
|
3
|
+
n: string;
|
|
4
|
+
s: number;
|
|
5
|
+
}>;
|
|
6
|
+
type SelectOptionArrayItem = {
|
|
7
|
+
id?: number;
|
|
8
|
+
i?: number;
|
|
9
|
+
n: string;
|
|
10
|
+
s?: number;
|
|
11
|
+
};
|
|
12
|
+
type SelectOptions = SelectOptionObject | SelectOptionArrayItem[];
|
|
13
|
+
export type TSelect = TInput & {
|
|
14
|
+
options?: SelectOptions;
|
|
15
|
+
order?: number[];
|
|
16
|
+
};
|
|
17
|
+
declare function SelectField({ form, title, error, edit, active, hide, value, onValue, options, placeholder, className, name, order, isReload, disabled, }: TSelect): import("react/jsx-runtime").JSX.Element | "";
|
|
18
|
+
declare namespace SelectField {
|
|
19
|
+
var displayName: string;
|
|
20
|
+
}
|
|
21
|
+
export default SelectField;
|