@elcrm/form 0.0.88 → 0.1.0
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 +87 -47
- package/dist/Form.js +1 -11
- package/dist/FormInitContext.js +1 -20
- package/dist/assets/styles/Field.module.css +1 -1
- package/dist/assets/styles/Form.module.css +1 -1
- package/dist/assets/styles/Select.module.css +1 -1
- package/dist/core/Field.d.ts +14 -2
- package/dist/core/Field.js +2 -35
- package/dist/dark.css +22 -3
- package/dist/events/onEvent.js +1 -67
- package/dist/fields/Check.js +1 -86
- package/dist/fields/Code.js +1 -94
- package/dist/fields/Color.js +1 -495
- package/dist/fields/Date.js +1 -450
- package/dist/fields/Display.d.ts +1 -1
- package/dist/fields/Display.js +1 -49
- package/dist/fields/DragDrop.js +1 -189
- package/dist/fields/Email.d.ts +4 -2
- package/dist/fields/Email.js +1 -80
- package/dist/fields/File.js +1 -115
- package/dist/fields/Hidden.js +1 -33
- package/dist/fields/Input.d.ts +3 -1
- package/dist/fields/Input.js +1 -149
- package/dist/fields/Mask.js +1 -119
- package/dist/fields/Modal.js +1 -68
- package/dist/fields/Money.js +1 -125
- package/dist/fields/NativeTextField.d.ts +15 -0
- package/dist/fields/NativeTextField.js +1 -0
- package/dist/fields/Numeric.d.ts +12 -1
- package/dist/fields/Numeric.js +1 -105
- package/dist/fields/Options.js +1 -69
- package/dist/fields/Password.d.ts +1 -1
- package/dist/fields/Password.js +1 -143
- package/dist/fields/Percent.d.ts +8 -1
- package/dist/fields/Percent.js +1 -100
- package/dist/fields/Phone.d.ts +2 -2
- package/dist/fields/Phone.js +1 -128
- package/dist/fields/Radio.js +1 -88
- package/dist/fields/Range.js +1 -109
- package/dist/fields/Rating.js +1 -82
- package/dist/fields/RichText.js +1 -134
- package/dist/fields/Select.d.ts +3 -1
- package/dist/fields/Select.js +1 -171
- package/dist/fields/Tags.js +1 -97
- package/dist/fields/Textarea.d.ts +1 -1
- package/dist/fields/Textarea.js +1 -68
- package/dist/fields/Time.js +1 -444
- package/dist/fields/Url.d.ts +4 -2
- package/dist/fields/Url.js +1 -80
- package/dist/fields/emit.d.ts +9 -0
- package/dist/fields/emit.js +1 -0
- package/dist/fields/type.d.ts +1 -1
- package/dist/fields/visibility.js +1 -6
- package/dist/hooks/use.js +1 -57
- package/dist/index.js +2 -42
- package/dist/index.umd.js +2 -2
- package/dist/light.css +23 -3
- package/dist/mask/MaskPhone.js +1 -1384
- package/dist/mask/phoneDefaults.d.ts +8 -0
- package/dist/mask/phoneDefaults.js +1 -0
- package/dist/overlayZ.js +1 -25
- package/dist/package.js +1 -130
- package/dist/style.css +3 -3
- package/dist/styles/Color.module.js +1 -27
- package/dist/styles/Field.module.js +1 -77
- package/dist/styles/Form.module.js +1 -12
- package/dist/styles/Select.module.js +1 -9
- package/package.json +2 -2
package/dist/fields/Password.js
CHANGED
|
@@ -1,143 +1 @@
|
|
|
1
|
-
import e from
|
|
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: "20",
|
|
13
|
-
height: "20",
|
|
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: "20",
|
|
32
|
-
height: "20",
|
|
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 { value: E } = n(d, p, u), [D, O] = a.useState(!1), k = a.useRef(null), A = typeof E == "string" ? E : E == null ? "" : String(E);
|
|
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 ? /* @__PURE__ */ o("span", {
|
|
85
|
-
className: e.affix,
|
|
86
|
-
children: S
|
|
87
|
-
}) : null,
|
|
88
|
-
/* @__PURE__ */ o("div", {
|
|
89
|
-
style: {
|
|
90
|
-
flex: 1,
|
|
91
|
-
minWidth: 0,
|
|
92
|
-
display: "flex",
|
|
93
|
-
alignItems: "center"
|
|
94
|
-
},
|
|
95
|
-
children: /* @__PURE__ */ o("input", {
|
|
96
|
-
type: D ? "text" : "password",
|
|
97
|
-
defaultValue: A,
|
|
98
|
-
ref: k,
|
|
99
|
-
onChange: M,
|
|
100
|
-
onKeyDown: N,
|
|
101
|
-
onBlur: P,
|
|
102
|
-
disabled: v,
|
|
103
|
-
readOnly: v,
|
|
104
|
-
maxLength: w,
|
|
105
|
-
spellCheck: !1,
|
|
106
|
-
autoComplete: "current-password",
|
|
107
|
-
"aria-label": h || m || "Пароль",
|
|
108
|
-
"aria-disabled": v || !F,
|
|
109
|
-
tabIndex: v ? -1 : 0,
|
|
110
|
-
placeholder: m,
|
|
111
|
-
style: {
|
|
112
|
-
width: "100%",
|
|
113
|
-
border: "none",
|
|
114
|
-
outline: "none",
|
|
115
|
-
background: "transparent",
|
|
116
|
-
font: "inherit",
|
|
117
|
-
color: "inherit",
|
|
118
|
-
padding: 0,
|
|
119
|
-
margin: 0,
|
|
120
|
-
boxSizing: "border-box"
|
|
121
|
-
}
|
|
122
|
-
})
|
|
123
|
-
}),
|
|
124
|
-
/* @__PURE__ */ o("button", {
|
|
125
|
-
type: "button",
|
|
126
|
-
className: e.affix,
|
|
127
|
-
tabIndex: v ? -1 : 0,
|
|
128
|
-
"aria-label": D ? "Скрыть пароль" : "Показать пароль",
|
|
129
|
-
"aria-pressed": D,
|
|
130
|
-
disabled: v,
|
|
131
|
-
onClick: () => !v && O(!D),
|
|
132
|
-
children: D ? L : I
|
|
133
|
-
}),
|
|
134
|
-
x ? /* @__PURE__ */ o("span", {
|
|
135
|
-
className: e.affix,
|
|
136
|
-
children: x
|
|
137
|
-
}) : null
|
|
138
|
-
]
|
|
139
|
-
});
|
|
140
|
-
}
|
|
141
|
-
u.displayName = "PasswordField";
|
|
142
|
-
//#endregion
|
|
143
|
-
export { u as default };
|
|
1
|
+
import e from"../styles/Field.module.js";import t,{useFieldA11y as n}from"../core/Field.js";import{useFormFieldState as r}from"../hooks/use.js";import i from"../events/onEvent.js";import{isEmptyTextLike as a}from"./visibility.js";import o from"react";import{jsx as s,jsxs as c}from"react/jsx-runtime";function l(){return c(`svg`,{xmlns:`http://www.w3.org/2000/svg`,width:`20`,height:`20`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":!0,children:[s(`path`,{d:`M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z`}),s(`circle`,{cx:`12`,cy:`12`,r:`3`})]})}function u(){return c(`svg`,{xmlns:`http://www.w3.org/2000/svg`,width:`20`,height:`20`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":!0,children:[s(`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`}),s(`line`,{x1:`1`,y1:`1`,x2:`23`,y2:`23`})]})}function d({value:n,form:d,onValue:p,name:m=``,placeholder:h=``,label:g,error:_,hidden:v=!1,disabled:y=!1,onBlur:b,className:x,after:S=``,before:C=``,native:w=!1,maxLength:T,eyes:E,id:D,size:O=`md`}){let{value:k}=r(d,m,n),[A,j]=o.useState(!1),M=o.useRef(null),N=typeof k==`string`?k:k==null?``:String(k);o.useEffect(()=>{let e=M.current;e&&e.value!==N&&(e.value=N)},[N]);let P=e=>{let t={value:e,name:m};d&&m&&d.onValue(t),p&&p!==d?.onValue&&p(t)},F=e=>{P(e.target.value)},I=e=>{e.key===`Enter`&&e.preventDefault()},L=e=>{i.Blur(e),b?.({value:(e.target.value||``).trim(),name:m||``})};if(w)return``;let R=!y;if(v&&a(N))return``;let z=E?.[0]??s(l,{}),B=E?.[1]??s(u,{});return c(t,{type:`input`,label:g,error:_,id:D,size:O,element_blok:{className:[x||``]},element_input:{className:[e.w],props:{"data-disabled":y||!R?`true`:void 0}},children:[C?s(`span`,{className:e.affix,children:C}):null,s(f,{inputRef:M,passwordVisible:A,currentValue:N,disabled:y,editable:R,maxLength:T,placeholder:h,label:g,onChangeInput:F,keyDown:I,handleBlur:L}),s(`button`,{type:`button`,className:e.affix,tabIndex:y?-1:0,"aria-label":A?`Скрыть пароль`:`Показать пароль`,"aria-pressed":A,disabled:y,onClick:()=>!y&&j(!A),children:A?B:z}),S?s(`span`,{className:e.affix,children:S}):null]})}function f({inputRef:t,passwordVisible:r,currentValue:i,disabled:a,editable:o,maxLength:c,placeholder:l,label:u,onChangeInput:d,keyDown:f,handleBlur:p}){let m=n();return s(`div`,{className:e.nativeWrap,children:s(`input`,{id:m?.controlId,className:e.nativeInput,type:r?`text`:`password`,defaultValue:i,ref:t,onChange:d,onKeyDown:f,onBlur:p,disabled:a,readOnly:a,maxLength:c,spellCheck:!1,autoComplete:`current-password`,"aria-label":u?void 0:l||`Пароль`,"aria-describedby":m?.describedBy,"aria-invalid":m?.errorId?!0:void 0,"aria-disabled":a||!o,tabIndex:a?-1:0,placeholder:l})})}d.displayName=`PasswordField`;export{d as default};
|
package/dist/fields/Percent.d.ts
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import { TInput } from './type';
|
|
2
|
-
/** PercentField — процент
|
|
2
|
+
/** PercentField — процент как **number** в форме (не строка).
|
|
3
|
+
*
|
|
4
|
+
* Отличия от NumberField:
|
|
5
|
+
* - значение: `number` (или `""` / пусто), не строка цифр;
|
|
6
|
+
* - `min`/`max` — границы **числа** (по умолчанию 0–100), clamp на blur;
|
|
7
|
+
* - `decimals` — дробная часть;
|
|
8
|
+
* - справа по умолчанию аффикс `%`.
|
|
9
|
+
*/
|
|
3
10
|
export type TPercent = TInput & {
|
|
4
11
|
min?: number;
|
|
5
12
|
max?: number;
|
package/dist/fields/Percent.js
CHANGED
|
@@ -1,100 +1 @@
|
|
|
1
|
-
import e from
|
|
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 "react";
|
|
6
|
-
import { jsx as o, jsxs as s } from "react/jsx-runtime";
|
|
7
|
-
//#region src/lib/fields/Percent.tsx
|
|
8
|
-
function c(e, t, n) {
|
|
9
|
-
return Number.isFinite(e) ? Math.min(n, Math.max(t, e)) : t;
|
|
10
|
-
}
|
|
11
|
-
function l(e, t) {
|
|
12
|
-
let n = e.replace(",", ".").replace(/[^\d.]/g, "");
|
|
13
|
-
if (!n) return null;
|
|
14
|
-
let r = Number(n);
|
|
15
|
-
if (!Number.isFinite(r)) return null;
|
|
16
|
-
if (t <= 0) return Math.round(r);
|
|
17
|
-
let i = 10 ** t;
|
|
18
|
-
return Math.round(r * i) / i;
|
|
19
|
-
}
|
|
20
|
-
function u(e, t) {
|
|
21
|
-
return Number.isFinite(e) ? String(t <= 0 ? Math.round(e) : Number(e.toFixed(t))) : "";
|
|
22
|
-
}
|
|
23
|
-
function d({ value: d = 0, form: f, onValue: p, onBlur: m, name: h = "", placeholder: g = "0", label: _ = "", error: v = "", hidden: y = !1, disabled: b = !1, className: x = "", after: S, before: C = "", min: w = 0, max: T = 100, decimals: E = 0, inputmode: D = "decimal" }) {
|
|
24
|
-
let { value: O, version: k } = n(f, h, d), A = !b, j = c(Number(O), w, T), M = O == null || O === "" ? "" : u(j, E), N = a.useRef(null), P = a.useRef(!1);
|
|
25
|
-
a.useLayoutEffect(() => {
|
|
26
|
-
if (P.current) return;
|
|
27
|
-
let e = N.current;
|
|
28
|
-
e && e.textContent !== M && (e.textContent = M);
|
|
29
|
-
}, [M, k]);
|
|
30
|
-
let F = (e, t = !1) => {
|
|
31
|
-
let n = {
|
|
32
|
-
value: e,
|
|
33
|
-
name: h
|
|
34
|
-
};
|
|
35
|
-
f && h && (t ? f.setValue(n) : f.onValue(n)), p && p !== f?.onValue && p(n);
|
|
36
|
-
}, I = (e) => {
|
|
37
|
-
let t = (e.currentTarget.textContent || "").replace(/[^\d.,]/g, "");
|
|
38
|
-
e.currentTarget.textContent !== t && (e.currentTarget.textContent = t);
|
|
39
|
-
let n = l(t, E);
|
|
40
|
-
if (n === null) {
|
|
41
|
-
F("");
|
|
42
|
-
return;
|
|
43
|
-
}
|
|
44
|
-
F(c(n, w, T));
|
|
45
|
-
}, L = (e) => {
|
|
46
|
-
r.Blur(e), P.current = !1;
|
|
47
|
-
let t = l(e.currentTarget.textContent || "", E), n = t === null ? w : c(t, w, T), i = u(n, E);
|
|
48
|
-
e.currentTarget.textContent !== i && (e.currentTarget.textContent = i), F(n, !0), m?.({
|
|
49
|
-
value: n,
|
|
50
|
-
name: h
|
|
51
|
-
});
|
|
52
|
-
};
|
|
53
|
-
if (y && (O == null || O === "")) return null;
|
|
54
|
-
let R = {};
|
|
55
|
-
return g && (R.placeholder = g), A && (R.edit = ""), R.inputMode = D || "decimal", /* @__PURE__ */ s(t, {
|
|
56
|
-
type: "percent",
|
|
57
|
-
label: _,
|
|
58
|
-
error: v,
|
|
59
|
-
element_blok: { className: [x || ""] },
|
|
60
|
-
element_input: {
|
|
61
|
-
className: [e.w],
|
|
62
|
-
props: { "data-disabled": b || !A ? "true" : void 0 }
|
|
63
|
-
},
|
|
64
|
-
children: [
|
|
65
|
-
C ? /* @__PURE__ */ o("span", {
|
|
66
|
-
className: e.affix,
|
|
67
|
-
children: C
|
|
68
|
-
}) : null,
|
|
69
|
-
/* @__PURE__ */ o("div", {
|
|
70
|
-
ref: N,
|
|
71
|
-
onInput: I,
|
|
72
|
-
onFocus: (e) => {
|
|
73
|
-
P.current = !0, r.Focus({ target: e.currentTarget });
|
|
74
|
-
},
|
|
75
|
-
onBlur: L,
|
|
76
|
-
onPaste: (e) => r.Paste(12, i(e)),
|
|
77
|
-
onKeyDown: (e) => {
|
|
78
|
-
e.key === "Enter" && e.preventDefault(), e.key.length === 1 && !/[\d.,]/.test(e.key) && !e.metaKey && !e.ctrlKey && e.preventDefault();
|
|
79
|
-
},
|
|
80
|
-
spellCheck: !1,
|
|
81
|
-
role: "textbox",
|
|
82
|
-
tabIndex: A ? 0 : -1,
|
|
83
|
-
"aria-label": _ || g || "Процент",
|
|
84
|
-
contentEditable: A ? "plaintext-only" : !1,
|
|
85
|
-
suppressContentEditableWarning: !0,
|
|
86
|
-
...R
|
|
87
|
-
}),
|
|
88
|
-
S === void 0 ? /* @__PURE__ */ o("span", {
|
|
89
|
-
className: e.affix,
|
|
90
|
-
children: "%"
|
|
91
|
-
}) : /* @__PURE__ */ o("span", {
|
|
92
|
-
className: e.affix,
|
|
93
|
-
children: S
|
|
94
|
-
})
|
|
95
|
-
]
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
d.displayName = "PercentField";
|
|
99
|
-
//#endregion
|
|
100
|
-
export { d as default };
|
|
1
|
+
import e from"../styles/Field.module.js";import t from"../core/Field.js";import{useFormFieldState as n}from"../hooks/use.js";import r,{asEditableClipboard as i}from"../events/onEvent.js";import a from"react";import{jsx as o,jsxs as s}from"react/jsx-runtime";function c(e,t,n){return Number.isFinite(e)?Math.min(n,Math.max(t,e)):t}function l(e,t){let n=e.replace(`,`,`.`).replace(/[^\d.]/g,``);if(!n)return null;let r=Number(n);if(!Number.isFinite(r))return null;if(t<=0)return Math.round(r);let i=10**t;return Math.round(r*i)/i}function u(e,t){return Number.isFinite(e)?String(t<=0?Math.round(e):Number(e.toFixed(t))):``}function d({value:d=0,form:f,onValue:p,onBlur:m,name:h=``,placeholder:g=`0`,label:_=``,error:v=``,hidden:y=!1,disabled:b=!1,className:x=``,after:S,before:C=``,min:w=0,max:T=100,decimals:E=0,inputmode:D=`decimal`}){let{value:O,version:k}=n(f,h,d),A=!b,j=c(Number(O),w,T),M=O==null||O===``?``:u(j,E),N=a.useRef(null),P=a.useRef(!1);a.useLayoutEffect(()=>{if(P.current)return;let e=N.current;e&&e.textContent!==M&&(e.textContent=M)},[M,k]);let F=(e,t=!1)=>{let n={value:e,name:h};if(f&&h)if(t){let t=f.getValue(h);Object.is(t,e)?f.onValue(n):f.setValue(n)}else f.onValue(n);p&&p!==f?.onValue&&p(n)},I=e=>{let t=(e.currentTarget.textContent||``).replace(/[^\d.,]/g,``);e.currentTarget.textContent!==t&&(e.currentTarget.textContent=t);let n=l(t,E);if(n===null){F(``);return}F(c(n,w,T))},L=e=>{r.Blur(e),P.current=!1;let t=l(e.currentTarget.textContent||``,E),n=t===null?w:c(t,w,T),i=u(n,E);e.currentTarget.textContent!==i&&(e.currentTarget.textContent=i),F(n,!0),m?.({value:n,name:h})};if(y&&(O==null||O===``))return null;let R={};return g&&(R.placeholder=g),A&&(R.edit=``),R.inputMode=D||`decimal`,s(t,{type:`percent`,label:_,error:v,element_blok:{className:[x||``]},element_input:{className:[e.w],props:{"data-disabled":b||!A?`true`:void 0}},children:[C?o(`span`,{className:e.affix,children:C}):null,o(`div`,{ref:N,onInput:I,onFocus:e=>{P.current=!0,r.Focus({target:e.currentTarget})},onBlur:L,onPaste:e=>r.Paste(12,i(e)),onKeyDown:e=>{e.key===`Enter`&&e.preventDefault(),e.key.length===1&&!/[\d.,]/.test(e.key)&&!e.metaKey&&!e.ctrlKey&&e.preventDefault()},spellCheck:!1,role:`textbox`,tabIndex:A?0:-1,"aria-label":_||g||`Процент`,contentEditable:A?`plaintext-only`:!1,suppressContentEditableWarning:!0,...R}),S===void 0?o(`span`,{className:e.affix,children:`%`}):o(`span`,{className:e.affix,children:S})]})}d.displayName=`PercentField`;export{d as default};
|
package/dist/fields/Phone.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { TInput } from './type';
|
|
2
|
-
/** PhoneField — телефон с
|
|
3
|
-
declare function PhoneField({ value, form, onValue, onBlur: onBlurField, name, placeholder, label, error, hidden, disabled, className, after, before, inputmode,
|
|
2
|
+
/** PhoneField — телефон с маской; полный каталог стран подгружается при фокусе. */
|
|
3
|
+
declare function PhoneField({ value, form, onValue, onBlur: onBlurField, name, placeholder, label, error, hidden, disabled, className, after, before, inputmode, id, }: TInput): import("react/jsx-runtime").JSX.Element | null;
|
|
4
4
|
declare namespace PhoneField {
|
|
5
5
|
var displayName: string;
|
|
6
6
|
}
|
package/dist/fields/Phone.js
CHANGED
|
@@ -1,128 +1 @@
|
|
|
1
|
-
import e from
|
|
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 c from "react";
|
|
9
|
-
import { Fragment as l, jsx as u, jsxs as d } from "react/jsx-runtime";
|
|
10
|
-
//#region src/lib/fields/Phone.tsx
|
|
11
|
-
function f(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 p(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 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
|
-
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
|
-
}, 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
|
-
t.textContent = a.q;
|
|
34
|
-
let o = p(a.q, i);
|
|
35
|
-
a.q.length > 0 && queueMicrotask(() => {
|
|
36
|
-
R(Math.min(o, a.q.length), t);
|
|
37
|
-
});
|
|
38
|
-
let s = {
|
|
39
|
-
value: a.q.replace(/\D/g, ""),
|
|
40
|
-
name: v || ""
|
|
41
|
-
};
|
|
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
|
-
let t = 0, n = "", r = e.replace(/\D/g, "");
|
|
46
|
-
r === "" && (I = !0);
|
|
47
|
-
let i = r.split(""), a = "";
|
|
48
|
-
i.forEach((e) => {
|
|
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
|
-
});
|
|
51
|
-
let s = F.replace(/\D/g, "");
|
|
52
|
-
return s.length >= r.length && (r = s), {
|
|
53
|
-
q: F.replace(/[_\d]/g, function() {
|
|
54
|
-
return r.charAt(t++) || "_";
|
|
55
|
-
}),
|
|
56
|
-
i: t,
|
|
57
|
-
v: r,
|
|
58
|
-
f: n
|
|
59
|
-
};
|
|
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) => {
|
|
69
|
-
e.preventDefault();
|
|
70
|
-
let t = e.target;
|
|
71
|
-
navigator.clipboard.writeText((t.textContent || "").replace(/\D/g, "")).then(function() {
|
|
72
|
-
k("Данные в буфер обмене");
|
|
73
|
-
}, function(e) {
|
|
74
|
-
console.error("Async: Could not copy text: ", e);
|
|
75
|
-
});
|
|
76
|
-
};
|
|
77
|
-
V(String(j || ""));
|
|
78
|
-
let U = (e) => {
|
|
79
|
-
e.key === "Enter" && e.preventDefault();
|
|
80
|
-
}, W = (e) => {
|
|
81
|
-
r.Blur(e), _ && _({
|
|
82
|
-
value: (e.target.textContent || "").replace(/\D/g, ""),
|
|
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, {
|
|
91
|
-
type: "input",
|
|
92
|
-
label: b,
|
|
93
|
-
error: x,
|
|
94
|
-
element_blok: { className: [w] },
|
|
95
|
-
element_input: { className: [e.w] },
|
|
96
|
-
children: [
|
|
97
|
-
E ? /* @__PURE__ */ u("span", {
|
|
98
|
-
className: e.affix,
|
|
99
|
-
children: E
|
|
100
|
-
}) : null,
|
|
101
|
-
/* @__PURE__ */ u("div", {
|
|
102
|
-
ref: N,
|
|
103
|
-
onPaste: B,
|
|
104
|
-
onInput: z,
|
|
105
|
-
onKeyDown: U,
|
|
106
|
-
onContextMenu: H,
|
|
107
|
-
onBlur: W,
|
|
108
|
-
onFocus: G,
|
|
109
|
-
spellCheck: !1,
|
|
110
|
-
role: "textbox",
|
|
111
|
-
"aria-label": b || y || "Телефон",
|
|
112
|
-
"aria-disabled": !A,
|
|
113
|
-
tabIndex: C ? -1 : 0,
|
|
114
|
-
"data-disabled": !A,
|
|
115
|
-
contentEditable: A ? "plaintext-only" : !1,
|
|
116
|
-
suppressContentEditableWarning: !0,
|
|
117
|
-
...K
|
|
118
|
-
}),
|
|
119
|
-
T ? /* @__PURE__ */ u("span", {
|
|
120
|
-
className: e.affix,
|
|
121
|
-
children: T
|
|
122
|
-
}) : null
|
|
123
|
-
]
|
|
124
|
-
});
|
|
125
|
-
}
|
|
126
|
-
m.displayName = "PhoneField";
|
|
127
|
-
//#endregion
|
|
128
|
-
export { m as default };
|
|
1
|
+
import e from"../styles/Field.module.js";import t,{useFieldA11y as n}from"../core/Field.js";import{useFormFieldState as r}from"../hooks/use.js";import i,{asEditableClipboard as a}from"../events/onEvent.js";import{isEmptyTextLike as o}from"./visibility.js";import{PHONE_MASK_DEFAULTS as s}from"../mask/phoneDefaults.js";import{useFormInit as c}from"../FormInitContext.js";import l from"react";import{jsx as u,jsxs as d}from"react/jsx-runtime";var f={...s},p=!1,m=null;function h(){return p?Promise.resolve(!1):m||(m=import(`../mask/MaskPhone.js`).then(e=>(f={...s,...e.default},p=!0,!0)),m)}function g(e){let t=window.getSelection();if(!t||t.rangeCount===0)return 0;let n=t.getRangeAt(0);if(!e.contains(n.startContainer))return 0;let r=document.createRange();return r.selectNodeContents(e),r.setEnd(n.startContainer,n.startOffset),r.toString().length}function _(e,t){if(t<=0)return 0;let n=0;for(let r=0;r<e.length;r++)if(/\d/.test(e[r])&&(n++,n===t))return r+1;return e.length}function v(e){let t=`+_(___) ___-__-__`,n=!0,r=0,i=0,a=``,o=e.replace(/\D/g,``);o===``&&(n=!0);let s=o.split(``),c=``;s.forEach(e=>{n&&(c+=e,f[c]!==void 0&&n?(n=!1,t=f[c].mask.replace(RegExp(`[0-9]`,`g`),`_`),a=f[c].code):(n&&(r=(``+c).length,t=`+${c}_(___) ___-__-__`.replace(RegExp(`[0-9]`,`g`),`_`),a=``),r>(``+c).length&&(n=!0,t=`+${c}_(___) ___-__-__`.replace(RegExp(`[0-9]`,`g`),`_`),a=``)))});let l=t.replace(/\D/g,``);return l.length>=o.length&&(o=l),{q:t.replace(/[_\d]/g,function(){return o.charAt(i++)||`_`}),i,v:o,f:a}}function y({value:n,form:s,onValue:f,onBlur:p,name:m=``,placeholder:y=``,label:x=``,error:S=``,hidden:C=!1,disabled:w=!1,className:T=``,after:E=``,before:D=``,inputmode:O=`tel`,id:k}){let{onNotice:A}=c(),j=!w,{value:M,version:N}=r(s,m,n),[,P]=l.useState(0),F=l.useRef(null),I=l.useRef(!1),L=(e,t)=>{let n=t.firstChild;if(!n||n.nodeType!==Node.TEXT_NODE)return;let r=n.textContent?.length??0,i=Math.max(0,Math.min(e,r)),a=document.createRange(),o=window.getSelection();o&&(a.setStart(n,i),a.collapse(!0),o.removeAllRanges(),o.addRange(a),t.focus())},R=e=>{let t=e.target,n=t.textContent||``,r=g(t),i=n.slice(0,r).replace(/\D/g,``).length,a=v(n);t.textContent=a.q;let o=_(a.q,i);a.q.length>0&&queueMicrotask(()=>{L(Math.min(o,a.q.length),t)});let c={value:a.q.replace(/\D/g,``),name:m||``};s&&m&&s.onValue(c),f&&f!==s?.onValue&&f(c)},z=e=>i.PasteOne(a(e));l.useLayoutEffect(()=>{if(I.current)return;let e=F.current;if(!e)return;let t=v(String(M||``));e.textContent!==t.q&&(e.textContent=t.q)},[M,N]);let B=e=>{e.preventDefault();let t=e.target;navigator.clipboard.writeText((t.textContent||``).replace(/\D/g,``)).then(function(){A(`Данные в буфер обмене`)},function(e){})},V=e=>{e.key===`Enter`&&e.preventDefault()},H=e=>{i.Blur(e),p&&p({value:(e.target.textContent||``).replace(/\D/g,``),name:m||``}),I.current=!1},U=e=>{I.current=!0,i.Focus({target:e.currentTarget}),h().then(e=>{if(!e)return;P(e=>e+1);let t=F.current;if(!t||document.activeElement!==t)return;let n=t.textContent||``,r=g(t),i=n.slice(0,r).replace(/\D/g,``).length,a=v(n);t.textContent!==a.q&&(t.textContent=a.q,queueMicrotask(()=>{L(Math.min(_(a.q,i),a.q.length),t)}))})},W={};y&&(W.placeholder=y),W.inputMode=O??`tel`;let G=String(M??``).replace(/\D/g,``);return C&&o(G)?null:d(t,{type:`input`,label:x,error:S,id:k,element_blok:{className:[T]},element_input:{className:[e.w]},children:[D?u(`span`,{className:e.affix,children:D}):null,u(b,{divRef:F,editable:j,disabled:w,label:x,placeholder:y,dd:W,onPaste:z,onInput:R,onKeyDown:V,onContextMenu:B,onBlur:H,onFocus:U}),E?u(`span`,{className:e.affix,children:E}):null]})}function b({divRef:e,editable:t,disabled:r,label:i,placeholder:a,dd:o,onPaste:s,onInput:c,onKeyDown:l,onContextMenu:d,onBlur:f,onFocus:p}){let m=n();return u(`div`,{ref:e,id:m?.controlId,onPaste:s,onInput:c,onKeyDown:l,onContextMenu:d,onBlur:f,onFocus:p,spellCheck:!1,role:`textbox`,"aria-label":i?void 0:a||`Телефон`,"aria-describedby":m?.describedBy,"aria-invalid":m?.errorId?!0:void 0,"aria-disabled":!t,tabIndex:r?-1:0,"data-disabled":!t,contentEditable:t?`plaintext-only`:!1,suppressContentEditableWarning:!0,...o})}y.displayName=`PhoneField`;export{y as default};
|
package/dist/fields/Radio.js
CHANGED
|
@@ -1,88 +1 @@
|
|
|
1
|
-
import e from
|
|
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, jsxs as a } from "react/jsx-runtime";
|
|
6
|
-
//#region src/lib/fields/Radio.tsx
|
|
7
|
-
function o(e) {
|
|
8
|
-
return e ? Array.isArray(e) ? e.map((e) => ({
|
|
9
|
-
id: e.id ?? e.i ?? "",
|
|
10
|
-
label: e.n || "",
|
|
11
|
-
hidden: e.s === 0
|
|
12
|
-
})).filter((e) => e.label.length > 0 && e.id !== "") : Object.keys(e).map((t) => {
|
|
13
|
-
let n = e[t], r = Number(t);
|
|
14
|
-
return {
|
|
15
|
-
id: Number.isFinite(r) && String(r) === t ? r : t,
|
|
16
|
-
label: n?.n || "",
|
|
17
|
-
hidden: n?.s === 0
|
|
18
|
-
};
|
|
19
|
-
}).filter((e) => e.label.length > 0) : [];
|
|
20
|
-
}
|
|
21
|
-
function s(e, t) {
|
|
22
|
-
return e === t ? !0 : String(e) === String(t);
|
|
23
|
-
}
|
|
24
|
-
function c({ value: c = "", form: l, onValue: u, onBlur: d, name: f = "", placeholder: p = "", label: m = "", error: h = "", hidden: g = !1, disabled: _ = !1, className: v = "", after: y = "", before: b = "", options: x, inline: S = !1 }) {
|
|
25
|
-
let { value: C } = n(l, f, c), w = !_, T = o(x).filter((e) => !e.hidden), E = r.useId(), D = (e) => {
|
|
26
|
-
let t = {
|
|
27
|
-
value: e,
|
|
28
|
-
name: f
|
|
29
|
-
};
|
|
30
|
-
l && f && l.setValue(t), u && u !== l?.onValue && u(t);
|
|
31
|
-
};
|
|
32
|
-
return g && (C == null || C === "") ? null : /* @__PURE__ */ a(t, {
|
|
33
|
-
type: "radio",
|
|
34
|
-
label: m,
|
|
35
|
-
error: h,
|
|
36
|
-
element_blok: { className: [v || ""] },
|
|
37
|
-
element_input: {
|
|
38
|
-
className: [e.radio, S ? e.radioInline : ""],
|
|
39
|
-
props: {
|
|
40
|
-
"data-disabled": _ || !w ? "true" : void 0,
|
|
41
|
-
role: "radiogroup",
|
|
42
|
-
"aria-label": m || p || "Выбор"
|
|
43
|
-
}
|
|
44
|
-
},
|
|
45
|
-
children: [
|
|
46
|
-
b ? /* @__PURE__ */ i("span", {
|
|
47
|
-
className: e.affix,
|
|
48
|
-
children: b
|
|
49
|
-
}) : null,
|
|
50
|
-
/* @__PURE__ */ i("div", { children: T.map((t) => {
|
|
51
|
-
let n = s(C, t.id);
|
|
52
|
-
return /* @__PURE__ */ a("button", {
|
|
53
|
-
type: "button",
|
|
54
|
-
className: e.radioItem,
|
|
55
|
-
role: "radio",
|
|
56
|
-
"aria-checked": n,
|
|
57
|
-
"aria-disabled": _ || !w ? !0 : void 0,
|
|
58
|
-
disabled: _ || !w,
|
|
59
|
-
name: E,
|
|
60
|
-
onClick: () => {
|
|
61
|
-
w && D(t.id);
|
|
62
|
-
},
|
|
63
|
-
onBlur: () => {
|
|
64
|
-
!d || !f || d({
|
|
65
|
-
value: l ? l.getValue(f, C) : C,
|
|
66
|
-
name: f
|
|
67
|
-
});
|
|
68
|
-
},
|
|
69
|
-
children: [/* @__PURE__ */ i("span", {
|
|
70
|
-
className: e.radioDot,
|
|
71
|
-
"aria-hidden": !0,
|
|
72
|
-
children: n ? /* @__PURE__ */ i("span", { className: e.radioDotFill }) : null
|
|
73
|
-
}), /* @__PURE__ */ i("span", {
|
|
74
|
-
className: e.radioText,
|
|
75
|
-
children: t.label
|
|
76
|
-
})]
|
|
77
|
-
}, String(t.id));
|
|
78
|
-
}) }),
|
|
79
|
-
y ? /* @__PURE__ */ i("span", {
|
|
80
|
-
className: e.affix,
|
|
81
|
-
children: y
|
|
82
|
-
}) : null
|
|
83
|
-
]
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
c.displayName = "RadioField";
|
|
87
|
-
//#endregion
|
|
88
|
-
export { c as default };
|
|
1
|
+
import e from"../styles/Field.module.js";import t from"../core/Field.js";import{useFormFieldState as n}from"../hooks/use.js";import r from"react";import{jsx as i,jsxs as a}from"react/jsx-runtime";function o(e){return e?Array.isArray(e)?e.map(e=>({id:e.id??e.i??``,label:e.n||``,hidden:e.s===0})).filter(e=>e.label.length>0&&e.id!==``):Object.keys(e).map(t=>{let n=e[t],r=Number(t);return{id:Number.isFinite(r)&&String(r)===t?r:t,label:n?.n||``,hidden:n?.s===0}}).filter(e=>e.label.length>0):[]}function s(e,t){return e===t?!0:String(e)===String(t)}function c({value:c=``,form:l,onValue:u,onBlur:d,name:f=``,placeholder:p=``,label:m=``,error:h=``,hidden:g=!1,disabled:_=!1,className:v=``,after:y=``,before:b=``,options:x,inline:S=!1}){let{value:C}=n(l,f,c),w=!_,T=o(x).filter(e=>!e.hidden),E=r.useId(),D=e=>{let t={value:e,name:f};l&&f&&l.setValue(t),u&&u!==l?.onValue&&u(t)};return g&&(C==null||C===``)?null:a(t,{type:`radio`,label:m,error:h,element_blok:{className:[v||``]},element_input:{className:[e.radio,S?e.radioInline:``],props:{"data-disabled":_||!w?`true`:void 0,role:`radiogroup`,"aria-label":m||p||`Выбор`}},children:[b?i(`span`,{className:e.affix,children:b}):null,i(`div`,{children:T.map(t=>{let n=s(C,t.id);return a(`button`,{type:`button`,className:e.radioItem,role:`radio`,"aria-checked":n,"aria-disabled":_||!w?!0:void 0,disabled:_||!w,name:E,onClick:()=>{w&&D(t.id)},onBlur:()=>{!d||!f||d({value:l?l.getValue(f,C):C,name:f})},children:[i(`span`,{className:e.radioDot,"aria-hidden":!0,children:n?i(`span`,{className:e.radioDotFill}):null}),i(`span`,{className:e.radioText,children:t.label})]},String(t.id))})}),y?i(`span`,{className:e.affix,children:y}):null]})}c.displayName=`RadioField`;export{c as default};
|
package/dist/fields/Range.js
CHANGED
|
@@ -1,109 +1 @@
|
|
|
1
|
-
import e from
|
|
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, jsxs as a } from "react/jsx-runtime";
|
|
6
|
-
//#region src/lib/fields/Range.tsx
|
|
7
|
-
function o(e, t, n) {
|
|
8
|
-
let r = e;
|
|
9
|
-
return Number.isFinite(r) || (r = t), Math.min(n, Math.max(t, r));
|
|
10
|
-
}
|
|
11
|
-
function s(e, t, n, r) {
|
|
12
|
-
return o(!Number.isFinite(r) || r <= 0 ? e : t + Math.round((e - t) / r) * r, t, n);
|
|
13
|
-
}
|
|
14
|
-
function c({ value: c = 0, form: l, onValue: u, onBlur: d, name: f = "", placeholder: p = "", label: m = "", error: h = "", hidden: g = !1, disabled: _ = !1, className: v = "", after: y = "", before: b = "", min: x = 0, max: S = 100, step: C = 1 }) {
|
|
15
|
-
let { value: w } = n(l, f, c), T = o(Number(w), x, S), E = S === x ? 0 : (T - x) / (S - x) * 100, D = E >= 99.999, O = !_, k = r.useRef(null), A = r.useCallback((e) => {
|
|
16
|
-
let t = {
|
|
17
|
-
value: s(e, x, S, C),
|
|
18
|
-
name: f || ""
|
|
19
|
-
};
|
|
20
|
-
l && f && l.setValue(t), u && u !== l?.onValue && u(t);
|
|
21
|
-
}, [
|
|
22
|
-
l,
|
|
23
|
-
f,
|
|
24
|
-
u,
|
|
25
|
-
x,
|
|
26
|
-
S,
|
|
27
|
-
C
|
|
28
|
-
]), j = r.useCallback((e) => {
|
|
29
|
-
let t = k.current;
|
|
30
|
-
if (!t) return x;
|
|
31
|
-
let n = t.getBoundingClientRect(), r = n.width || 1;
|
|
32
|
-
return s(x + (e - n.left) / r * (S - x), x, S, C);
|
|
33
|
-
}, [
|
|
34
|
-
x,
|
|
35
|
-
S,
|
|
36
|
-
C
|
|
37
|
-
]), M = (e) => {
|
|
38
|
-
O && (e.preventDefault(), e.currentTarget.setPointerCapture(e.pointerId), A(j(e.clientX)));
|
|
39
|
-
}, N = (e) => {
|
|
40
|
-
O && e.currentTarget.hasPointerCapture(e.pointerId) && A(j(e.clientX));
|
|
41
|
-
}, P = (e) => {
|
|
42
|
-
try {
|
|
43
|
-
e.currentTarget.releasePointerCapture(e.pointerId);
|
|
44
|
-
} catch {}
|
|
45
|
-
}, F = (e) => {
|
|
46
|
-
if (!O) return;
|
|
47
|
-
let t = T;
|
|
48
|
-
if (e.key === "ArrowRight" || e.key === "ArrowUp") t = T + C;
|
|
49
|
-
else if (e.key === "ArrowLeft" || e.key === "ArrowDown") t = T - C;
|
|
50
|
-
else if (e.key === "Home") t = x;
|
|
51
|
-
else if (e.key === "End") t = S;
|
|
52
|
-
else if (e.key === "PageUp") t = T + C * 10;
|
|
53
|
-
else if (e.key === "PageDown") t = T - C * 10;
|
|
54
|
-
else return;
|
|
55
|
-
e.preventDefault(), A(s(t, x, S, C));
|
|
56
|
-
}, I = () => {
|
|
57
|
-
if (!d || !f) return;
|
|
58
|
-
let e = l && f ? l.getValue(f, c) : T;
|
|
59
|
-
d({
|
|
60
|
-
value: o(Number(e), x, S),
|
|
61
|
-
name: f
|
|
62
|
-
});
|
|
63
|
-
};
|
|
64
|
-
return g && (w == null || w === "") ? null : /* @__PURE__ */ a(t, {
|
|
65
|
-
type: "range",
|
|
66
|
-
label: m,
|
|
67
|
-
error: h,
|
|
68
|
-
element_blok: { className: [v || ""] },
|
|
69
|
-
element_input: {
|
|
70
|
-
className: [e.w, e.range],
|
|
71
|
-
props: { "data-disabled": _ || !O ? "true" : void 0 }
|
|
72
|
-
},
|
|
73
|
-
children: [
|
|
74
|
-
b ? /* @__PURE__ */ i("span", {
|
|
75
|
-
className: e.affix,
|
|
76
|
-
children: b
|
|
77
|
-
}) : null,
|
|
78
|
-
/* @__PURE__ */ i("div", { children: /* @__PURE__ */ i("div", {
|
|
79
|
-
ref: k,
|
|
80
|
-
className: e.rangeTrack,
|
|
81
|
-
role: "slider",
|
|
82
|
-
tabIndex: O ? 0 : -1,
|
|
83
|
-
"aria-label": m || p || "Диапазон",
|
|
84
|
-
"aria-valuemin": x,
|
|
85
|
-
"aria-valuemax": S,
|
|
86
|
-
"aria-valuenow": T,
|
|
87
|
-
"data-disabled": _ || !O ? "true" : void 0,
|
|
88
|
-
onPointerDown: M,
|
|
89
|
-
onPointerMove: N,
|
|
90
|
-
onPointerUp: P,
|
|
91
|
-
onPointerCancel: P,
|
|
92
|
-
onKeyDown: F,
|
|
93
|
-
onBlur: I,
|
|
94
|
-
children: /* @__PURE__ */ i("div", {
|
|
95
|
-
className: D ? `${e.rangeFill} ${e.rangeFillFull}` : e.rangeFill,
|
|
96
|
-
style: { width: `${E}%` },
|
|
97
|
-
"aria-hidden": !0
|
|
98
|
-
})
|
|
99
|
-
}) }),
|
|
100
|
-
y ? /* @__PURE__ */ i("span", {
|
|
101
|
-
className: e.affix,
|
|
102
|
-
children: y
|
|
103
|
-
}) : null
|
|
104
|
-
]
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
c.displayName = "RangeField";
|
|
108
|
-
//#endregion
|
|
109
|
-
export { c as default };
|
|
1
|
+
import e from"../styles/Field.module.js";import t from"../core/Field.js";import{useFormFieldState as n}from"../hooks/use.js";import r from"react";import{jsx as i,jsxs as a}from"react/jsx-runtime";function o(e,t,n){let r=e;return Number.isFinite(r)||(r=t),Math.min(n,Math.max(t,r))}function s(e,t,n,r){return o(!Number.isFinite(r)||r<=0?e:t+Math.round((e-t)/r)*r,t,n)}function c({value:c=0,form:l,onValue:u,onBlur:d,name:f=``,placeholder:p=``,label:m=``,error:h=``,hidden:g=!1,disabled:_=!1,className:v=``,after:y=``,before:b=``,min:x=0,max:S=100,step:C=1}){let{value:w}=n(l,f,c),T=o(Number(w),x,S),E=S===x?0:(T-x)/(S-x)*100,D=E>=99.999,O=!_,k=r.useRef(null),A=r.useCallback(e=>{let t={value:s(e,x,S,C),name:f||``};l&&f&&l.setValue(t),u&&u!==l?.onValue&&u(t)},[l,f,u,x,S,C]),j=r.useCallback(e=>{let t=k.current;if(!t)return x;let n=t.getBoundingClientRect(),r=n.width||1;return s(x+(e-n.left)/r*(S-x),x,S,C)},[x,S,C]),M=e=>{O&&(e.preventDefault(),e.currentTarget.setPointerCapture(e.pointerId),A(j(e.clientX)))},N=e=>{O&&e.currentTarget.hasPointerCapture(e.pointerId)&&A(j(e.clientX))},P=e=>{try{e.currentTarget.releasePointerCapture(e.pointerId)}catch{}},F=e=>{if(!O)return;let t=T;if(e.key===`ArrowRight`||e.key===`ArrowUp`)t=T+C;else if(e.key===`ArrowLeft`||e.key===`ArrowDown`)t=T-C;else if(e.key===`Home`)t=x;else if(e.key===`End`)t=S;else if(e.key===`PageUp`)t=T+C*10;else if(e.key===`PageDown`)t=T-C*10;else return;e.preventDefault(),A(s(t,x,S,C))},I=()=>{if(!d||!f)return;let e=l&&f?l.getValue(f,c):T;d({value:o(Number(e),x,S),name:f})};return g&&(w==null||w===``)?null:a(t,{type:`range`,label:m,error:h,element_blok:{className:[v||``]},element_input:{className:[e.w,e.range],props:{"data-disabled":_||!O?`true`:void 0}},children:[b?i(`span`,{className:e.affix,children:b}):null,i(`div`,{children:i(`div`,{ref:k,className:e.rangeTrack,role:`slider`,tabIndex:O?0:-1,"aria-label":m||p||`Диапазон`,"aria-valuemin":x,"aria-valuemax":S,"aria-valuenow":T,"data-disabled":_||!O?`true`:void 0,onPointerDown:M,onPointerMove:N,onPointerUp:P,onPointerCancel:P,onKeyDown:F,onBlur:I,children:i(`div`,{className:D?`${e.rangeFill} ${e.rangeFillFull}`:e.rangeFill,style:{width:`${E}%`},"aria-hidden":!0})})}),y?i(`span`,{className:e.affix,children:y}):null]})}c.displayName=`RangeField`;export{c as default};
|