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