@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,352 @@
|
|
|
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 { isEmptyTextLike as r } from "./visibility.js";
|
|
5
|
+
import i from "../styles/Form.module.js";
|
|
6
|
+
import a from "react";
|
|
7
|
+
import { Fragment as o, jsx as s, jsxs as c } from "react/jsx-runtime";
|
|
8
|
+
import { createPortal as l } from "react-dom";
|
|
9
|
+
//#region src/lib/fields/Date.tsx
|
|
10
|
+
function u(e, t, n, r) {
|
|
11
|
+
let i = new Date(e, t - 1, 1);
|
|
12
|
+
return !(n && new Date(e, t, 0) < n || r && i > r);
|
|
13
|
+
}
|
|
14
|
+
function d(e, t, n) {
|
|
15
|
+
return !(t && e < t.getFullYear() || n && e > n.getFullYear());
|
|
16
|
+
}
|
|
17
|
+
function f(e, t, n) {
|
|
18
|
+
let r = e;
|
|
19
|
+
if (t) {
|
|
20
|
+
let e = t.getFullYear();
|
|
21
|
+
r + 11 < e && (r = e - 11), r < e && (r = e);
|
|
22
|
+
}
|
|
23
|
+
if (n) {
|
|
24
|
+
let e = n.getFullYear();
|
|
25
|
+
r > e && (r = e - 11), r + 11 > e && (r = e - 11);
|
|
26
|
+
}
|
|
27
|
+
return r;
|
|
28
|
+
}
|
|
29
|
+
function p({ label: i = "", error: u, hidden: d = !1, className: f, placeholder: p, disabled: h = !1, onValue: g, max: v, min: y, form: b, icon: x, name: S = "", value: C, after: w = "", before: T = "" }) {
|
|
30
|
+
let E = a.useCallback((e) => e == null ? /* @__PURE__ */ new Date() : e instanceof Date || typeof e == "string" || typeof e == "number" ? e : /* @__PURE__ */ new Date(), []), { value: D, version: O } = n(b, S, C), [k, A] = a.useState(E(D)), j = a.useRef({
|
|
31
|
+
x: 0,
|
|
32
|
+
y: 0,
|
|
33
|
+
b: 0
|
|
34
|
+
}), [M, N] = a.useState(!1);
|
|
35
|
+
a.useEffect(() => {
|
|
36
|
+
A(E(D));
|
|
37
|
+
}, [
|
|
38
|
+
D,
|
|
39
|
+
O,
|
|
40
|
+
E
|
|
41
|
+
]);
|
|
42
|
+
let P = (e) => {
|
|
43
|
+
let t = {
|
|
44
|
+
value: e,
|
|
45
|
+
name: S
|
|
46
|
+
};
|
|
47
|
+
b && S ? b.setValue(t) : A(e), g && g !== b?.onValue && g(t);
|
|
48
|
+
}, F = (e) => {
|
|
49
|
+
if (h) return;
|
|
50
|
+
let t = e.currentTarget.getBoundingClientRect();
|
|
51
|
+
j.current = {
|
|
52
|
+
x: t.left,
|
|
53
|
+
b: t.bottom,
|
|
54
|
+
y: t.top
|
|
55
|
+
}, N(!0);
|
|
56
|
+
}, I = {};
|
|
57
|
+
p && (I.placeholder = p);
|
|
58
|
+
let L = D == null || D === "" || typeof D == "string" && r(D);
|
|
59
|
+
return d && L ? /* @__PURE__ */ s(o, {}) : /* @__PURE__ */ c(o, { children: [x ? x() : /* @__PURE__ */ c(t, {
|
|
60
|
+
type: "date",
|
|
61
|
+
label: i,
|
|
62
|
+
error: u,
|
|
63
|
+
element_blok: { className: [f || ""] },
|
|
64
|
+
element_input: {
|
|
65
|
+
className: [e.w],
|
|
66
|
+
props: { "data-disabled": h ? "true" : void 0 }
|
|
67
|
+
},
|
|
68
|
+
children: [
|
|
69
|
+
T,
|
|
70
|
+
/* @__PURE__ */ s("div", {
|
|
71
|
+
onClick: F,
|
|
72
|
+
onKeyDown: (e) => {
|
|
73
|
+
(e.key === "Enter" || e.key === " ") && (e.preventDefault(), F(e));
|
|
74
|
+
},
|
|
75
|
+
tabIndex: h ? -1 : 0,
|
|
76
|
+
role: "button",
|
|
77
|
+
"aria-haspopup": "dialog",
|
|
78
|
+
"aria-expanded": M,
|
|
79
|
+
"aria-label": i || p || "Дата",
|
|
80
|
+
"data-edit": h ? void 0 : "true",
|
|
81
|
+
...I,
|
|
82
|
+
style: { cursor: h ? "not-allowed" : "pointer" },
|
|
83
|
+
children: _(k, "dd.mm.yyyy")
|
|
84
|
+
}, O),
|
|
85
|
+
w
|
|
86
|
+
]
|
|
87
|
+
}), M && l(/* @__PURE__ */ s(m, {
|
|
88
|
+
position: j.current,
|
|
89
|
+
onValue: P,
|
|
90
|
+
date: k,
|
|
91
|
+
max: v,
|
|
92
|
+
min: y,
|
|
93
|
+
onOpen: N,
|
|
94
|
+
className: f
|
|
95
|
+
}, (/* @__PURE__ */ new Date()).getTime()), document.body)] });
|
|
96
|
+
}
|
|
97
|
+
p.displayName = "DateField";
|
|
98
|
+
var m = ({ date: e, onValue: t, position: n, max: r, min: l, className: p, onOpen: m }) => {
|
|
99
|
+
let _ = /* @__PURE__ */ new Date(), v = new Date(e), y = {
|
|
100
|
+
y: _.getFullYear(),
|
|
101
|
+
d: _.getDate(),
|
|
102
|
+
m: _.getMonth() + 1
|
|
103
|
+
}, b = {
|
|
104
|
+
y: v.getFullYear(),
|
|
105
|
+
d: v.getDate(),
|
|
106
|
+
m: v.getMonth() + 1
|
|
107
|
+
}, [x, S] = a.useState({
|
|
108
|
+
y: b.y,
|
|
109
|
+
m: b.m
|
|
110
|
+
}), [C, w] = a.useState("days"), [T, E] = a.useState(() => f(b.y - 5, l, r)), D = (e) => {
|
|
111
|
+
let t = e.getDay();
|
|
112
|
+
return t === 0 && (t = 7), t - 1;
|
|
113
|
+
}, O = [
|
|
114
|
+
"пн",
|
|
115
|
+
"вт",
|
|
116
|
+
"ср",
|
|
117
|
+
"чт",
|
|
118
|
+
"пт",
|
|
119
|
+
"сб",
|
|
120
|
+
"вс"
|
|
121
|
+
], k = x.m - 1, A = new Date(x.y, k), j = [];
|
|
122
|
+
for (let e = 0; e < D(A); e++) j.push(0);
|
|
123
|
+
for (; A.getMonth() === k;) j.push(A.getDate()), A.setDate(A.getDate() + 1);
|
|
124
|
+
let M = () => {
|
|
125
|
+
m(!1);
|
|
126
|
+
}, N = () => {
|
|
127
|
+
V(x.m + 1, x.y);
|
|
128
|
+
}, P = () => {
|
|
129
|
+
V(x.m - 1, x.y);
|
|
130
|
+
}, F = () => {
|
|
131
|
+
C === "days" ? P() : C === "months" ? V(x.m, x.y - 1) : E((e) => f(e - 12, l, r));
|
|
132
|
+
}, I = () => {
|
|
133
|
+
C === "days" ? N() : C === "months" ? V(x.m, x.y + 1) : E((e) => f(e + 12, l, r));
|
|
134
|
+
}, L = (e) => {
|
|
135
|
+
e.stopPropagation(), E(f(x.y - 5, l, r)), w("years");
|
|
136
|
+
}, R = (e) => {
|
|
137
|
+
u(x.y, e, l, r) && (S({
|
|
138
|
+
y: x.y,
|
|
139
|
+
m: e
|
|
140
|
+
}), w("days"));
|
|
141
|
+
}, z = (e) => {
|
|
142
|
+
d(e, l, r) && (S({
|
|
143
|
+
y: e,
|
|
144
|
+
m: x.m
|
|
145
|
+
}), w("days"));
|
|
146
|
+
}, B = (e) => {
|
|
147
|
+
t(x.y + "-" + g(2, x.m) + "-" + g(2, e)), M();
|
|
148
|
+
}, V = (e, t) => {
|
|
149
|
+
t = e > 12 ? t + 1 : e < 1 ? t - 1 : t, e = e > 12 ? 1 : e < 1 ? 12 : e, S({
|
|
150
|
+
y: t,
|
|
151
|
+
m: e
|
|
152
|
+
});
|
|
153
|
+
}, H = (e) => y.y === x.y && y.m === x.m && y.d === e ? { "data-active": "true" } : {}, U = (e) => b.y === x.y && b.m === x.m && b.d === e ? { "data-current": "true" } : {}, W = (e) => {
|
|
154
|
+
let t = !0;
|
|
155
|
+
return r && r.getTime() < new Date(x.y, x.m - 1, e).getTime() && (t = !1), l && l.getTime() > new Date(x.y, x.m - 1, e).getTime() && (t = !1), t;
|
|
156
|
+
}, G = window.innerHeight - n.b < 360 ? Math.max(8, n.y - 360) : n.b, K = window.innerWidth - n.x < 270 ? n.x - 246 : n.x;
|
|
157
|
+
return /* @__PURE__ */ c(o, { children: [/* @__PURE__ */ s("div", {
|
|
158
|
+
className: i.o,
|
|
159
|
+
onClick: () => M()
|
|
160
|
+
}), /* @__PURE__ */ c("div", {
|
|
161
|
+
className: [i.c, p && p + "-backdrop"].join(" "),
|
|
162
|
+
style: {
|
|
163
|
+
top: G + "px",
|
|
164
|
+
left: K + "px"
|
|
165
|
+
},
|
|
166
|
+
onClick: (e) => e.stopPropagation(),
|
|
167
|
+
children: [
|
|
168
|
+
/* @__PURE__ */ c("s", { children: [
|
|
169
|
+
/* @__PURE__ */ s("i", {
|
|
170
|
+
onClick: (e) => {
|
|
171
|
+
e.stopPropagation(), F();
|
|
172
|
+
},
|
|
173
|
+
children: /* @__PURE__ */ s("svg", {
|
|
174
|
+
width: "16",
|
|
175
|
+
height: "16",
|
|
176
|
+
fill: "currentColor",
|
|
177
|
+
viewBox: "0 0 24 24",
|
|
178
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
179
|
+
children: /* @__PURE__ */ s("path", { d: "m15.09 4.594-7.646 6.553a1.126 1.126 0 0 0 0 1.708l7.647 6.552c.73.625 1.857.107 1.857-.854V5.447c0-.961-1.127-1.48-1.857-.853Z" })
|
|
180
|
+
})
|
|
181
|
+
}),
|
|
182
|
+
/* @__PURE__ */ c("h2", { children: [/* @__PURE__ */ s("span", {
|
|
183
|
+
className: i.dateHeaderMonth,
|
|
184
|
+
onClick: (e) => {
|
|
185
|
+
e.stopPropagation(), w(C === "years" ? "months" : C === "months" ? "days" : "months");
|
|
186
|
+
},
|
|
187
|
+
title: C === "years" ? "К списку месяцев" : C === "months" ? "К календарю" : "Выбрать месяц",
|
|
188
|
+
children: h(x.m).name
|
|
189
|
+
}), /* @__PURE__ */ s("span", {
|
|
190
|
+
className: i.dateHeaderYear,
|
|
191
|
+
onClick: (e) => {
|
|
192
|
+
e.stopPropagation(), C === "years" ? w("days") : L(e);
|
|
193
|
+
},
|
|
194
|
+
title: C === "years" ? "К календарю" : "Выбрать год",
|
|
195
|
+
children: x.y
|
|
196
|
+
})] }),
|
|
197
|
+
/* @__PURE__ */ s("i", {
|
|
198
|
+
onClick: (e) => {
|
|
199
|
+
e.stopPropagation(), I();
|
|
200
|
+
},
|
|
201
|
+
children: /* @__PURE__ */ s("svg", {
|
|
202
|
+
width: "16",
|
|
203
|
+
height: "16",
|
|
204
|
+
fill: "currentColor",
|
|
205
|
+
viewBox: "0 0 24 24",
|
|
206
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
207
|
+
children: /* @__PURE__ */ s("path", { d: "m8.91 19.406 7.646-6.552a1.125 1.125 0 0 0 0-1.709L8.91 4.593c-.73-.625-1.857-.107-1.857.854v13.107c0 .96 1.127 1.479 1.857.852Z" })
|
|
208
|
+
})
|
|
209
|
+
})
|
|
210
|
+
] }),
|
|
211
|
+
C === "days" && /* @__PURE__ */ c("div", {
|
|
212
|
+
"grid-calendar": "",
|
|
213
|
+
children: [O.map((e, t) => /* @__PURE__ */ s("p", { children: e }, "v" + t)), j.map((e, t) => /* @__PURE__ */ s("span", { children: e !== 0 && W(e) ? /* @__PURE__ */ s("b", {
|
|
214
|
+
...H(e),
|
|
215
|
+
...U(e),
|
|
216
|
+
onClick: () => B(e),
|
|
217
|
+
children: e
|
|
218
|
+
}) : /* @__PURE__ */ s("p", {
|
|
219
|
+
...H(e),
|
|
220
|
+
...U(e),
|
|
221
|
+
children: e === 0 ? "" : e
|
|
222
|
+
}) }, t))]
|
|
223
|
+
}),
|
|
224
|
+
C === "months" && /* @__PURE__ */ s("div", {
|
|
225
|
+
"grid-month": "",
|
|
226
|
+
children: Array.from({ length: 12 }, (e, t) => {
|
|
227
|
+
let n = t + 1, a = u(x.y, n, l, r), o = y.y === x.y && y.m === n ? { "data-active": "true" } : {}, c = b.y === x.y && b.m === n ? { "data-current": "true" } : {};
|
|
228
|
+
return /* @__PURE__ */ s("b", {
|
|
229
|
+
className: a ? "" : i.dateHeaderDisabled,
|
|
230
|
+
...o,
|
|
231
|
+
...c,
|
|
232
|
+
onClick: () => a && R(n),
|
|
233
|
+
children: h(n).abc
|
|
234
|
+
}, n);
|
|
235
|
+
})
|
|
236
|
+
}),
|
|
237
|
+
C === "years" && /* @__PURE__ */ s("div", {
|
|
238
|
+
"grid-month": "",
|
|
239
|
+
children: Array.from({ length: 12 }, (e, t) => {
|
|
240
|
+
let n = T + t, a = d(n, l, r), o = y.y === n ? { "data-active": "true" } : {}, c = b.y === n ? { "data-current": "true" } : {};
|
|
241
|
+
return /* @__PURE__ */ s("b", {
|
|
242
|
+
className: a ? "" : i.dateHeaderDisabled,
|
|
243
|
+
...o,
|
|
244
|
+
...c,
|
|
245
|
+
onClick: () => a && z(n),
|
|
246
|
+
children: n
|
|
247
|
+
}, n);
|
|
248
|
+
})
|
|
249
|
+
})
|
|
250
|
+
]
|
|
251
|
+
})] });
|
|
252
|
+
};
|
|
253
|
+
function h(e) {
|
|
254
|
+
return e = typeof e == "number" ? e : new Date(e).getMonth() + 1, {
|
|
255
|
+
1: {
|
|
256
|
+
val: "01",
|
|
257
|
+
name: "Январь",
|
|
258
|
+
names: "Января",
|
|
259
|
+
abc: "Янв"
|
|
260
|
+
},
|
|
261
|
+
2: {
|
|
262
|
+
val: "02",
|
|
263
|
+
name: "Февраль",
|
|
264
|
+
names: "Февраля",
|
|
265
|
+
abc: "Февр"
|
|
266
|
+
},
|
|
267
|
+
3: {
|
|
268
|
+
val: "03",
|
|
269
|
+
name: "Март",
|
|
270
|
+
names: "Марта",
|
|
271
|
+
abc: "Март"
|
|
272
|
+
},
|
|
273
|
+
4: {
|
|
274
|
+
val: "04",
|
|
275
|
+
name: "Апрель",
|
|
276
|
+
names: "Апреля",
|
|
277
|
+
abc: "Апр"
|
|
278
|
+
},
|
|
279
|
+
5: {
|
|
280
|
+
val: "05",
|
|
281
|
+
name: "Май",
|
|
282
|
+
names: "Мая",
|
|
283
|
+
abc: "Май"
|
|
284
|
+
},
|
|
285
|
+
6: {
|
|
286
|
+
val: "06",
|
|
287
|
+
name: "Июнь",
|
|
288
|
+
names: "Июня",
|
|
289
|
+
abc: "Июнь"
|
|
290
|
+
},
|
|
291
|
+
7: {
|
|
292
|
+
val: "07",
|
|
293
|
+
name: "Июль",
|
|
294
|
+
names: "Июля",
|
|
295
|
+
abc: "Июль"
|
|
296
|
+
},
|
|
297
|
+
8: {
|
|
298
|
+
val: "08",
|
|
299
|
+
name: "Август",
|
|
300
|
+
names: "Августа",
|
|
301
|
+
abc: "Авг"
|
|
302
|
+
},
|
|
303
|
+
9: {
|
|
304
|
+
val: "09",
|
|
305
|
+
name: "Сентябрь",
|
|
306
|
+
names: "Сентября",
|
|
307
|
+
abc: "Сент"
|
|
308
|
+
},
|
|
309
|
+
10: {
|
|
310
|
+
val: "10",
|
|
311
|
+
name: "Октябрь",
|
|
312
|
+
names: "Октября",
|
|
313
|
+
abc: "Окт"
|
|
314
|
+
},
|
|
315
|
+
11: {
|
|
316
|
+
val: "11",
|
|
317
|
+
name: "Ноябрь",
|
|
318
|
+
names: "Ноября",
|
|
319
|
+
abc: "Нояб"
|
|
320
|
+
},
|
|
321
|
+
12: {
|
|
322
|
+
val: "12",
|
|
323
|
+
name: "Декабрь",
|
|
324
|
+
names: "Декабря",
|
|
325
|
+
abc: "Дек"
|
|
326
|
+
}
|
|
327
|
+
}[e];
|
|
328
|
+
}
|
|
329
|
+
function g(e, t) {
|
|
330
|
+
let n = t + "";
|
|
331
|
+
for (; n.length < e;) n = "0" + n;
|
|
332
|
+
return n;
|
|
333
|
+
}
|
|
334
|
+
function _(e, t) {
|
|
335
|
+
let n, r;
|
|
336
|
+
t === void 0 ? (r = String(e), n = /* @__PURE__ */ new Date()) : (r = t, n = new Date(e));
|
|
337
|
+
let i = r, a = {
|
|
338
|
+
yyyy: n.getFullYear(),
|
|
339
|
+
yy: ("" + n.getFullYear()).slice(-2),
|
|
340
|
+
mm: ("0" + (n.getMonth() + 1)).slice(-2),
|
|
341
|
+
dd: ("0" + n.getDate()).slice(-2),
|
|
342
|
+
HH: ("0" + n.getHours()).slice(-2),
|
|
343
|
+
MM: ("0" + n.getMinutes()).slice(-2),
|
|
344
|
+
SS: ("0" + n.getSeconds()).slice(-2),
|
|
345
|
+
__: " \xA0\xA0\xA0\xA0 ",
|
|
346
|
+
_: " \xA0\xA0 "
|
|
347
|
+
};
|
|
348
|
+
for (let e in a) i = i.replace(e, String(a[e]));
|
|
349
|
+
return i;
|
|
350
|
+
}
|
|
351
|
+
//#endregion
|
|
352
|
+
export { p as default };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { TInput } from './type';
|
|
2
|
+
/**
|
|
3
|
+
* StringField — текстовое поле (по умолчанию contentEditable).
|
|
4
|
+
*
|
|
5
|
+
* **Автозаполнение (логин + пароль):** менеджеры паролей опираются на нативные `<input>`.
|
|
6
|
+
* У `contentEditable` автозаполнение **не работает** как у поля логина.
|
|
7
|
+
* Включите **`native`** и задайте **`autoComplete="username"`** (и оберните поля в `<form>`, при необходимости).
|
|
8
|
+
*
|
|
9
|
+
* @param hidden — при true скрывает поле, только если значение пустое
|
|
10
|
+
*/
|
|
11
|
+
declare function StringField({ value, form, onValue, name, placeholder, label, hidden, disabled, onBlur: onBlurField, className, after, before, error, inputmode, maxLength, spellCheck, native, autoComplete, inputType, id, }: TInput): import("react/jsx-runtime").JSX.Element | "";
|
|
12
|
+
export default StringField;
|
|
@@ -0,0 +1,127 @@
|
|
|
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 "react";
|
|
7
|
+
import { jsx as s, jsxs as c } from "react/jsx-runtime";
|
|
8
|
+
//#region src/lib/fields/Input.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 = "text", maxLength: C, spellCheck: w = !0, native: T = !1, autoComplete: E, inputType: D = "text", id: O }) {
|
|
10
|
+
let { value: k, version: A } = n(u, f, l), j = !g, M = typeof k == "string" || typeof k == "number" ? String(k) : "", N = o.useRef(null);
|
|
11
|
+
o.useEffect(() => {
|
|
12
|
+
if (!T) return;
|
|
13
|
+
let e = N.current;
|
|
14
|
+
e && e.value !== M && (e.value = M);
|
|
15
|
+
}, [T, M]);
|
|
16
|
+
let P = (e) => {
|
|
17
|
+
let t = {
|
|
18
|
+
value: (e.target.textContent || "").trim(),
|
|
19
|
+
name: f
|
|
20
|
+
};
|
|
21
|
+
u && f && u.onValue(t), d && d !== u?.onValue && d(t);
|
|
22
|
+
}, F = (e) => {
|
|
23
|
+
let t = {
|
|
24
|
+
value: e.target.value,
|
|
25
|
+
name: f
|
|
26
|
+
};
|
|
27
|
+
u && f && u.onValue(t), d && d !== u?.onValue && d(t);
|
|
28
|
+
}, I = (e) => {
|
|
29
|
+
let t = e.target;
|
|
30
|
+
C && (t.textContent || "").trim().length >= C && e.key !== "Backspace" && e.preventDefault(), e.key === "Enter" && e.preventDefault();
|
|
31
|
+
}, L = (e) => {
|
|
32
|
+
e.key === "Enter" && e.preventDefault();
|
|
33
|
+
}, R = (e) => r.Paste(C || 0, i(e));
|
|
34
|
+
if (h && a(k)) return "";
|
|
35
|
+
let z = (e) => {
|
|
36
|
+
r.Blur(e), _?.({
|
|
37
|
+
value: (e.target.textContent || "").trim(),
|
|
38
|
+
name: f
|
|
39
|
+
});
|
|
40
|
+
}, B = (e) => {
|
|
41
|
+
_?.({
|
|
42
|
+
value: (e.target.value || "").trim(),
|
|
43
|
+
name: f
|
|
44
|
+
});
|
|
45
|
+
}, V = (e) => {
|
|
46
|
+
r.Focus({ target: e.currentTarget });
|
|
47
|
+
}, H = {};
|
|
48
|
+
return p && (H.placeholder = p), j && (H.edit = ""), T ? /* @__PURE__ */ c(t, {
|
|
49
|
+
type: "input",
|
|
50
|
+
label: m,
|
|
51
|
+
error: x,
|
|
52
|
+
element_blok: { className: [v || ""] },
|
|
53
|
+
element_input: {
|
|
54
|
+
className: [e.w],
|
|
55
|
+
props: { "data-disabled": g || !j ? "true" : void 0 }
|
|
56
|
+
},
|
|
57
|
+
children: [
|
|
58
|
+
b,
|
|
59
|
+
/* @__PURE__ */ s("div", {
|
|
60
|
+
style: {
|
|
61
|
+
flex: 1,
|
|
62
|
+
minWidth: 0,
|
|
63
|
+
display: "flex",
|
|
64
|
+
alignItems: "center"
|
|
65
|
+
},
|
|
66
|
+
children: /* @__PURE__ */ s("input", {
|
|
67
|
+
id: O,
|
|
68
|
+
ref: N,
|
|
69
|
+
type: D,
|
|
70
|
+
name: f || void 0,
|
|
71
|
+
defaultValue: M,
|
|
72
|
+
placeholder: p,
|
|
73
|
+
maxLength: C,
|
|
74
|
+
spellCheck: w,
|
|
75
|
+
disabled: g,
|
|
76
|
+
readOnly: g,
|
|
77
|
+
autoComplete: E,
|
|
78
|
+
inputMode: S || "text",
|
|
79
|
+
"aria-label": m || p || "Текст",
|
|
80
|
+
"aria-disabled": g || !j ? !0 : void 0,
|
|
81
|
+
tabIndex: g ? -1 : 0,
|
|
82
|
+
onChange: F,
|
|
83
|
+
onBlur: B,
|
|
84
|
+
onKeyDown: L,
|
|
85
|
+
style: {
|
|
86
|
+
width: "100%",
|
|
87
|
+
border: "none",
|
|
88
|
+
outline: "none",
|
|
89
|
+
background: "transparent",
|
|
90
|
+
font: "inherit",
|
|
91
|
+
color: "inherit",
|
|
92
|
+
padding: 0,
|
|
93
|
+
margin: 0,
|
|
94
|
+
boxSizing: "border-box"
|
|
95
|
+
}
|
|
96
|
+
})
|
|
97
|
+
}),
|
|
98
|
+
y
|
|
99
|
+
]
|
|
100
|
+
}) : /* @__PURE__ */ c(t, {
|
|
101
|
+
type: "input",
|
|
102
|
+
label: m,
|
|
103
|
+
error: x,
|
|
104
|
+
element_blok: { className: [v] },
|
|
105
|
+
element_input: { className: [e.w] },
|
|
106
|
+
children: [
|
|
107
|
+
b,
|
|
108
|
+
/* @__PURE__ */ s("div", {
|
|
109
|
+
id: O,
|
|
110
|
+
onBlur: z,
|
|
111
|
+
onFocus: V,
|
|
112
|
+
onPaste: R,
|
|
113
|
+
onInput: P,
|
|
114
|
+
onKeyDown: I,
|
|
115
|
+
spellCheck: w,
|
|
116
|
+
inputMode: S || "text",
|
|
117
|
+
contentEditable: j ? "plaintext-only" : !1,
|
|
118
|
+
suppressContentEditableWarning: !0,
|
|
119
|
+
...H,
|
|
120
|
+
children: typeof k == "string" || typeof k == "number" ? String(k) : ""
|
|
121
|
+
}, A),
|
|
122
|
+
y
|
|
123
|
+
]
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
//#endregion
|
|
127
|
+
export { l as default };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { TInput } from './type';
|
|
2
|
+
type TMask = TInput & {
|
|
3
|
+
format?: string;
|
|
4
|
+
};
|
|
5
|
+
declare function MaskField({ value, form, onValue, onBlur: onBlurField, name, format, placeholder, label, error, hidden, disabled, className, after, before, inputmode, view, }: TMask): import("react/jsx-runtime").JSX.Element;
|
|
6
|
+
declare namespace MaskField {
|
|
7
|
+
var displayName: string;
|
|
8
|
+
}
|
|
9
|
+
export default MaskField;
|
|
@@ -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, { 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/Mask.tsx
|
|
9
|
+
function l(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 u(e, t) {
|
|
18
|
+
if (t <= 0) return 0;
|
|
19
|
+
let n = 0;
|
|
20
|
+
for (let r = 0; r < e.length; r++) if (/\d/.test(e[r]) && (n++, n === t)) return r + 1;
|
|
21
|
+
return e.length;
|
|
22
|
+
}
|
|
23
|
+
function d({ value: d = "", form: f, onValue: p, onBlur: m, name: h = "", format: g = "+_(___) ___-__-__", placeholder: _ = "", label: v = "", error: y = "", hidden: b = !1, disabled: x = !1, className: S = "", after: C = "", before: w = "", inputmode: T = "numeric", view: E }) {
|
|
24
|
+
let D = !x, { value: O, version: k } = n(f, h, d), A = g, j = !0, M = 0, N = (e, t) => {
|
|
25
|
+
let n = t.firstChild;
|
|
26
|
+
if (!n || n.nodeType !== Node.TEXT_NODE) return;
|
|
27
|
+
let r = n.textContent?.length ?? 0, i = Math.max(0, Math.min(e, r)), a = document.createRange(), o = window.getSelection();
|
|
28
|
+
o && (a.setStart(n, i), a.collapse(!0), o.removeAllRanges(), o.addRange(a), t.focus());
|
|
29
|
+
}, P = (e) => r.PasteOne(i(e)), F = (e) => {
|
|
30
|
+
A = g, j = !0, M = 0;
|
|
31
|
+
let t = 0, n = "", r = e.replace(/\D/g, "");
|
|
32
|
+
r === "" && (j = !0);
|
|
33
|
+
let i = r.split(""), a = "";
|
|
34
|
+
i.forEach((e) => {
|
|
35
|
+
j && (a += e, j && (M = ("" + a).length, A = g.replace(/* @__PURE__ */ RegExp("[0-9]", "g"), "_"), n = ""), M > ("" + a).length && (j = !0, A = g.replace(/* @__PURE__ */ RegExp("[0-9]", "g"), "_"), n = ""));
|
|
36
|
+
});
|
|
37
|
+
let o = A.replace(/\D/g, "");
|
|
38
|
+
return o.length >= r.length && (r = o), {
|
|
39
|
+
q: A.replace(/[_\d]/g, function() {
|
|
40
|
+
return r.charAt(t++) || "_";
|
|
41
|
+
}),
|
|
42
|
+
i: t,
|
|
43
|
+
v: r,
|
|
44
|
+
f: n
|
|
45
|
+
};
|
|
46
|
+
}, I = F(String(O || "")), L = (e) => {
|
|
47
|
+
let t = e.target, n = t.textContent || "", r = l(t), i = n.slice(0, r).replace(/\D/g, "").length, a = F(n);
|
|
48
|
+
t.textContent = a.q;
|
|
49
|
+
let o = u(a.q, i);
|
|
50
|
+
a.q.length > 0 && queueMicrotask(() => {
|
|
51
|
+
N(Math.min(o, a.q.length), t);
|
|
52
|
+
});
|
|
53
|
+
let s = {
|
|
54
|
+
value: a.q.replace(/\D/g, ""),
|
|
55
|
+
name: h
|
|
56
|
+
};
|
|
57
|
+
f && h && f.onValue(s), p && p !== f?.onValue && p(s);
|
|
58
|
+
}, R = (e) => {
|
|
59
|
+
e.key === "Enter" && e.preventDefault();
|
|
60
|
+
}, z = (e) => {
|
|
61
|
+
r.Blur(e), m && m({
|
|
62
|
+
value: (e.target.textContent ?? "").replace(/\D/g, ""),
|
|
63
|
+
name: h
|
|
64
|
+
});
|
|
65
|
+
}, B = (e) => {
|
|
66
|
+
r.Focus({ target: e.currentTarget });
|
|
67
|
+
}, V = {};
|
|
68
|
+
_ && (V.placeholder = _), V.inputMode = T ?? "numeric";
|
|
69
|
+
let H = String(O ?? "").replace(/\D/g, "");
|
|
70
|
+
return b && a(H) ? /* @__PURE__ */ s(o, {}) : /* @__PURE__ */ c(t, {
|
|
71
|
+
type: "input",
|
|
72
|
+
label: v,
|
|
73
|
+
error: y,
|
|
74
|
+
element_blok: { className: [S] },
|
|
75
|
+
element_input: { className: [e.w] },
|
|
76
|
+
children: [
|
|
77
|
+
w,
|
|
78
|
+
/* @__PURE__ */ s("div", {
|
|
79
|
+
onPaste: P,
|
|
80
|
+
onInput: L,
|
|
81
|
+
onKeyDown: R,
|
|
82
|
+
onBlur: z,
|
|
83
|
+
onFocus: B,
|
|
84
|
+
role: "textbox",
|
|
85
|
+
spellCheck: !1,
|
|
86
|
+
"aria-label": v || _ || h || "Маска",
|
|
87
|
+
"aria-disabled": !D,
|
|
88
|
+
tabIndex: x ? -1 : 0,
|
|
89
|
+
"data-disabled": !D,
|
|
90
|
+
contentEditable: D ? "plaintext-only" : !1,
|
|
91
|
+
suppressContentEditableWarning: !0,
|
|
92
|
+
...V,
|
|
93
|
+
children: I.q
|
|
94
|
+
}, k),
|
|
95
|
+
C
|
|
96
|
+
]
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
d.displayName = "MaskField";
|
|
100
|
+
//#endregion
|
|
101
|
+
export { d as default };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
import { UseFormApi } from '../hooks/use';
|
|
3
|
+
import { TValue } from './type';
|
|
4
|
+
interface Input {
|
|
5
|
+
value?: string | [string | number, string];
|
|
6
|
+
form?: UseFormApi;
|
|
7
|
+
onValue?: (data: TValue) => void | Promise<void>;
|
|
8
|
+
name: string;
|
|
9
|
+
placeholder?: string;
|
|
10
|
+
label?: string;
|
|
11
|
+
error?: string;
|
|
12
|
+
hidden?: boolean;
|
|
13
|
+
disabled?: boolean;
|
|
14
|
+
after?: ReactNode;
|
|
15
|
+
before?: ReactNode;
|
|
16
|
+
view?: string;
|
|
17
|
+
className?: string;
|
|
18
|
+
modal: string;
|
|
19
|
+
options?: Record<string | number, unknown>;
|
|
20
|
+
}
|
|
21
|
+
declare function ModalField({ value, form, onValue, name, placeholder, label, error, hidden, disabled, after, before, view, modal, options, className, }: Input): import("react/jsx-runtime").JSX.Element;
|
|
22
|
+
declare namespace ModalField {
|
|
23
|
+
var displayName: string;
|
|
24
|
+
}
|
|
25
|
+
export default ModalField;
|
|
@@ -0,0 +1,62 @@
|
|
|
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 { isEmptyTextLike as r } from "./visibility.js";
|
|
5
|
+
import { useFormInit as i } from "../FormInitContext.js";
|
|
6
|
+
import "react";
|
|
7
|
+
import { Fragment as a, jsx as o, jsxs as s } from "react/jsx-runtime";
|
|
8
|
+
//#region src/lib/fields/Modal.tsx
|
|
9
|
+
function c({ value: c, form: l, onValue: u, name: d, placeholder: f = "", label: p, error: m, hidden: h = !1, disabled: g = !1, after: _, before: v, view: y, modal: b, options: x, className: S }) {
|
|
10
|
+
let { onModal: C } = i(), { value: w } = n(l, d, c), T = w, E = (e) => e ? Array.isArray(e) ? e[1] || "" : e : "", D = (e) => {
|
|
11
|
+
if (Array.isArray(e) && e.length >= 2) return [e[0], String(e[1] ?? "")];
|
|
12
|
+
if (typeof e == "object" && e) {
|
|
13
|
+
let t = e;
|
|
14
|
+
if (t.id !== void 0 && t.name !== void 0) return [t.id, t.name];
|
|
15
|
+
}
|
|
16
|
+
return String(e ?? "");
|
|
17
|
+
}, O = (e) => {
|
|
18
|
+
let t = {
|
|
19
|
+
value: D(e),
|
|
20
|
+
name: d
|
|
21
|
+
};
|
|
22
|
+
l && d && l.setValue(t), u && u !== l?.onValue && u(t);
|
|
23
|
+
}, k = () => {
|
|
24
|
+
if (g) return;
|
|
25
|
+
if (!b) return console.error("modal - empty");
|
|
26
|
+
let e = b.split(".");
|
|
27
|
+
if (e.length < 2) return console.error("modal должен быть в формате 'module.name'");
|
|
28
|
+
let t = Array.isArray(T) ? T[0] : T;
|
|
29
|
+
C({
|
|
30
|
+
module: e[0],
|
|
31
|
+
modalName: e[1],
|
|
32
|
+
callback: O,
|
|
33
|
+
onValue: O,
|
|
34
|
+
options: x,
|
|
35
|
+
fieldName: d,
|
|
36
|
+
value: t
|
|
37
|
+
});
|
|
38
|
+
}, A = {};
|
|
39
|
+
f && (A.placeholder = f);
|
|
40
|
+
let j = r(E(T));
|
|
41
|
+
return h && j ? /* @__PURE__ */ o(a, {}) : /* @__PURE__ */ s(t, {
|
|
42
|
+
type: "input",
|
|
43
|
+
label: p,
|
|
44
|
+
element_blok: { className: [S || ""] },
|
|
45
|
+
error: m,
|
|
46
|
+
element_input: {
|
|
47
|
+
className: [e.w],
|
|
48
|
+
props: { onClick: k }
|
|
49
|
+
},
|
|
50
|
+
children: [
|
|
51
|
+
v,
|
|
52
|
+
/* @__PURE__ */ o("div", {
|
|
53
|
+
...A,
|
|
54
|
+
children: E(T)
|
|
55
|
+
}),
|
|
56
|
+
_
|
|
57
|
+
]
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
c.displayName = "ModalField";
|
|
61
|
+
//#endregion
|
|
62
|
+
export { c as default };
|