@elcrm/form 0.0.87 → 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.
Files changed (68) hide show
  1. package/README.md +87 -47
  2. package/dist/Form.js +1 -11
  3. package/dist/FormInitContext.js +1 -20
  4. package/dist/assets/styles/Field.module.css +1 -1
  5. package/dist/assets/styles/Form.module.css +1 -1
  6. package/dist/assets/styles/Select.module.css +1 -1
  7. package/dist/core/Field.d.ts +14 -2
  8. package/dist/core/Field.js +2 -35
  9. package/dist/dark.css +22 -3
  10. package/dist/events/onEvent.js +1 -67
  11. package/dist/fields/Check.js +1 -86
  12. package/dist/fields/Code.js +1 -94
  13. package/dist/fields/Color.js +1 -495
  14. package/dist/fields/Date.js +1 -450
  15. package/dist/fields/Display.d.ts +1 -1
  16. package/dist/fields/Display.js +1 -49
  17. package/dist/fields/DragDrop.js +1 -189
  18. package/dist/fields/Email.d.ts +4 -2
  19. package/dist/fields/Email.js +1 -80
  20. package/dist/fields/File.js +1 -115
  21. package/dist/fields/Hidden.js +1 -33
  22. package/dist/fields/Input.d.ts +3 -1
  23. package/dist/fields/Input.js +1 -149
  24. package/dist/fields/Mask.js +1 -119
  25. package/dist/fields/Modal.js +1 -68
  26. package/dist/fields/Money.js +1 -125
  27. package/dist/fields/NativeTextField.d.ts +15 -0
  28. package/dist/fields/NativeTextField.js +1 -0
  29. package/dist/fields/Numeric.d.ts +12 -1
  30. package/dist/fields/Numeric.js +1 -105
  31. package/dist/fields/Options.js +1 -69
  32. package/dist/fields/Password.d.ts +1 -1
  33. package/dist/fields/Password.js +1 -143
  34. package/dist/fields/Percent.d.ts +8 -1
  35. package/dist/fields/Percent.js +1 -100
  36. package/dist/fields/Phone.d.ts +2 -2
  37. package/dist/fields/Phone.js +1 -128
  38. package/dist/fields/Radio.js +1 -88
  39. package/dist/fields/Range.js +1 -109
  40. package/dist/fields/Rating.js +1 -82
  41. package/dist/fields/RichText.js +1 -134
  42. package/dist/fields/Select.d.ts +3 -1
  43. package/dist/fields/Select.js +1 -159
  44. package/dist/fields/Tags.js +1 -97
  45. package/dist/fields/Textarea.d.ts +1 -1
  46. package/dist/fields/Textarea.js +1 -68
  47. package/dist/fields/Time.js +1 -444
  48. package/dist/fields/Url.d.ts +4 -2
  49. package/dist/fields/Url.js +1 -80
  50. package/dist/fields/emit.d.ts +9 -0
  51. package/dist/fields/emit.js +1 -0
  52. package/dist/fields/type.d.ts +1 -1
  53. package/dist/fields/visibility.js +1 -6
  54. package/dist/hooks/use.js +1 -57
  55. package/dist/index.js +2 -42
  56. package/dist/index.umd.js +2 -2
  57. package/dist/light.css +23 -3
  58. package/dist/mask/MaskPhone.js +1 -1384
  59. package/dist/mask/phoneDefaults.d.ts +8 -0
  60. package/dist/mask/phoneDefaults.js +1 -0
  61. package/dist/overlayZ.js +1 -25
  62. package/dist/package.js +1 -130
  63. package/dist/style.css +3 -3
  64. package/dist/styles/Color.module.js +1 -27
  65. package/dist/styles/Field.module.js +1 -77
  66. package/dist/styles/Form.module.js +1 -12
  67. package/dist/styles/Select.module.js +1 -9
  68. package/package.json +2 -2
@@ -1,450 +1 @@
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 { acquireOverlayZIndex as a, releaseOverlayZIndex as o } from "../overlayZ.js";
7
- import s from "react";
8
- import { Fragment as c, jsx as l, jsxs as u } from "react/jsx-runtime";
9
- import { createPortal as d } from "react-dom";
10
- //#region src/lib/fields/Date.tsx
11
- function f(e) {
12
- return !!(e == null || typeof e == "string" && r(e) || e instanceof Date && Number.isNaN(e.getTime()));
13
- }
14
- function p(e, t, n, r) {
15
- let i = new Date(e, t - 1, 1);
16
- return !(n && new Date(e, t, 0) < n || r && i > r);
17
- }
18
- function m(e, t, n) {
19
- return !(t && e < t.getFullYear() || n && e > n.getFullYear());
20
- }
21
- function h(e, t, n) {
22
- let r = e;
23
- if (t) {
24
- let e = t.getFullYear();
25
- r + 11 < e && (r = e - 11), r < e && (r = e);
26
- }
27
- if (n) {
28
- let e = n.getFullYear();
29
- r > e && (r = e - 11), r + 11 > e && (r = e - 11);
30
- }
31
- return r;
32
- }
33
- function g(e) {
34
- if (!(e instanceof HTMLElement)) return !1;
35
- let t = e.tagName;
36
- return t === "INPUT" || t === "TEXTAREA" || t === "SELECT" ? !0 : !!e.isContentEditable;
37
- }
38
- function _(e) {
39
- let t = (e || "").trim();
40
- if (!t) return null;
41
- let n = t.split(/\s+/)[0].replace(/,/g, "."), r = (e, t, n) => {
42
- if (t < 1 || t > 12 || n < 1 || n > 31) return null;
43
- let r = e < 100 ? 2e3 + e : e, i = new Date(r, t - 1, n);
44
- return Number.isNaN(i.getTime()) || i.getFullYear() !== r || i.getMonth() !== t - 1 || i.getDate() !== n ? null : i;
45
- }, i = /^(\d{1,2})[./](\d{1,2})[./](\d{2,4})$/.exec(n);
46
- if (i) return r(parseInt(i[3], 10), parseInt(i[2], 10), parseInt(i[1], 10));
47
- if (i = /^(\d{4})-(\d{1,2})-(\d{1,2})$/.exec(n), i) return r(parseInt(i[1], 10), parseInt(i[2], 10), parseInt(i[3], 10));
48
- if (i = /^(\d{1,2})\/(\d{1,2})\/(\d{2,4})$/.exec(n), i) return r(parseInt(i[3], 10), parseInt(i[2], 10), parseInt(i[1], 10));
49
- let a = n.replace(/\D/g, "");
50
- return a.length === 8 ? r(parseInt(a.slice(4, 8), 10), parseInt(a.slice(2, 4), 10), parseInt(a.slice(0, 2), 10)) || r(parseInt(a.slice(0, 4), 10), parseInt(a.slice(4, 6), 10), parseInt(a.slice(6, 8), 10)) : null;
51
- }
52
- function v(e, t, n) {
53
- let r = e.getTime();
54
- return t && r < t.getTime() && (r = t.getTime()), n && r > n.getTime() && (r = n.getTime()), new Date(r);
55
- }
56
- function y(e) {
57
- return e.getFullYear() + "-" + w(2, e.getMonth() + 1) + "-" + w(2, e.getDate());
58
- }
59
- function b({ label: i = "", error: a, hidden: o = !1, className: p, placeholder: m, disabled: h = !1, onValue: b, max: S, min: C, form: w, icon: E, name: D = "", value: O, after: k = "", before: A = "" }) {
60
- let j = s.useCallback((e) => {
61
- if (e == null || typeof e == "string" && r(e)) return "";
62
- if (e instanceof Date) return Number.isNaN(e.getTime()) ? "" : e;
63
- if (typeof e == "string" || typeof e == "number") {
64
- let t = new Date(e);
65
- return Number.isNaN(t.getTime()) ? "" : e;
66
- }
67
- return "";
68
- }, []), { value: M } = n(w, D, O), [N, P] = s.useState(j(M)), F = s.useRef(null), [I, L] = s.useState(null), [R, z] = s.useState(!1), B = s.useCallback(() => {
69
- let e = F.current;
70
- if (!e) return;
71
- let t = e.getBoundingClientRect();
72
- L({
73
- x: t.left,
74
- y: t.top,
75
- b: t.bottom
76
- });
77
- }, []);
78
- s.useEffect(() => {
79
- if (!R) return;
80
- B();
81
- let e = () => {
82
- B();
83
- };
84
- return window.addEventListener("scroll", e, !0), window.addEventListener("resize", e), () => {
85
- window.removeEventListener("scroll", e, !0), window.removeEventListener("resize", e);
86
- };
87
- }, [R, B]), s.useEffect(() => {
88
- P(j(M));
89
- }, [M, j]);
90
- let V = s.useCallback((e) => {
91
- let t = {
92
- value: e,
93
- name: D
94
- };
95
- P(e), w && D && w.setValue(t), b && b !== w?.onValue && b(t);
96
- }, [
97
- w,
98
- D,
99
- b
100
- ]);
101
- s.useEffect(() => {
102
- if (!R || h) return;
103
- let e = "", t = (t) => {
104
- let n = _(t);
105
- if (!n) return !1;
106
- let r = y(v(n, C, S));
107
- return r === e ? !0 : (e = r, V(r), z(!1), !0);
108
- }, n = (e) => {
109
- g(e.target) || t(e.clipboardData?.getData("text/plain") ?? "") && (e.preventDefault(), e.stopPropagation());
110
- }, r = (e) => {
111
- (e.ctrlKey || e.metaKey) && (e.key !== "v" && e.key !== "V" || g(e.target) || navigator.clipboard?.readText && (e.preventDefault(), navigator.clipboard.readText().then((e) => {
112
- t(e);
113
- })));
114
- };
115
- return document.addEventListener("paste", n, !0), window.addEventListener("keydown", r, !0), () => {
116
- document.removeEventListener("paste", n, !0), window.removeEventListener("keydown", r, !0);
117
- };
118
- }, [
119
- R,
120
- h,
121
- C,
122
- S,
123
- V
124
- ]);
125
- let H = (e) => {
126
- if (h) return;
127
- let t = e.currentTarget.getBoundingClientRect();
128
- L({
129
- x: t.left,
130
- y: t.top,
131
- b: t.bottom
132
- }), z(!0);
133
- }, U = {};
134
- m && (U.placeholder = m);
135
- let W = M == null || M === "" || typeof M == "string" && r(M);
136
- return o && W ? /* @__PURE__ */ l(c, {}) : /* @__PURE__ */ u(c, { children: [E ? E() : /* @__PURE__ */ u(t, {
137
- type: "date",
138
- label: i,
139
- error: a,
140
- element_blok: { className: [p || ""] },
141
- element_input: {
142
- className: [e.w],
143
- props: { "data-disabled": h ? "true" : void 0 }
144
- },
145
- children: [
146
- A ? /* @__PURE__ */ l("span", {
147
- className: e.affix,
148
- children: A
149
- }) : null,
150
- /* @__PURE__ */ l("div", {
151
- ref: F,
152
- onClick: H,
153
- onKeyDown: (e) => {
154
- (e.key === "Enter" || e.key === " ") && (e.preventDefault(), H(e));
155
- },
156
- tabIndex: h ? -1 : 0,
157
- role: "button",
158
- "aria-haspopup": "dialog",
159
- "aria-expanded": R,
160
- "aria-label": i || m || "Дата",
161
- "data-edit": h ? void 0 : "true",
162
- ...U,
163
- style: { cursor: h ? "not-allowed" : "pointer" },
164
- children: f(N) ? "" : T(N, "dd.mm.yyyy")
165
- }),
166
- k ? /* @__PURE__ */ l("span", {
167
- className: e.affix,
168
- children: k
169
- }) : null
170
- ]
171
- }), R && I && d(/* @__PURE__ */ l(x, {
172
- position: I,
173
- onValue: V,
174
- date: N,
175
- max: S,
176
- min: C,
177
- onOpen: z,
178
- className: p
179
- }, "elcrm-date-popup"), document.body)] });
180
- }
181
- b.displayName = "DateField";
182
- var x = ({ date: e, onValue: t, position: n, max: r, min: d, className: f, onOpen: g }) => {
183
- let [_] = s.useState(() => a());
184
- s.useEffect(() => () => o(_), [_]);
185
- let v = /* @__PURE__ */ new Date(), y = new Date(e);
186
- Number.isNaN(y.getTime()) && (y = /* @__PURE__ */ new Date());
187
- let b = {
188
- y: v.getFullYear(),
189
- d: v.getDate(),
190
- m: v.getMonth() + 1
191
- }, x = {
192
- y: y.getFullYear(),
193
- d: y.getDate(),
194
- m: y.getMonth() + 1
195
- }, [S, T] = s.useState({
196
- y: x.y,
197
- m: x.m
198
- }), [E, D] = s.useState("days"), [O, k] = s.useState(() => h(x.y - 5, d, r)), A = (e) => {
199
- let t = e.getDay();
200
- return t === 0 && (t = 7), t - 1;
201
- }, j = [
202
- "пн",
203
- "вт",
204
- "ср",
205
- "чт",
206
- "пт",
207
- "сб",
208
- "вс"
209
- ], M = S.m - 1, N = new Date(S.y, M), P = [];
210
- for (let e = 0; e < A(N); e++) P.push(0);
211
- for (; N.getMonth() === M;) P.push(N.getDate()), N.setDate(N.getDate() + 1);
212
- let F = () => {
213
- g(!1);
214
- }, I = () => {
215
- W(S.m + 1, S.y);
216
- }, L = () => {
217
- W(S.m - 1, S.y);
218
- }, R = () => {
219
- E === "days" ? L() : E === "months" ? W(S.m, S.y - 1) : k((e) => h(e - 12, d, r));
220
- }, z = () => {
221
- E === "days" ? I() : E === "months" ? W(S.m, S.y + 1) : k((e) => h(e + 12, d, r));
222
- }, B = (e) => {
223
- e.stopPropagation(), k(h(S.y - 5, d, r)), D("years");
224
- }, V = (e) => {
225
- p(S.y, e, d, r) && (T({
226
- y: S.y,
227
- m: e
228
- }), D("days"));
229
- }, H = (e) => {
230
- m(e, d, r) && (T({
231
- y: e,
232
- m: S.m
233
- }), D("days"));
234
- }, U = (e) => {
235
- t(S.y + "-" + w(2, S.m) + "-" + w(2, e)), F();
236
- }, W = (e, t) => {
237
- t = e > 12 ? t + 1 : e < 1 ? t - 1 : t, e = e > 12 ? 1 : e < 1 ? 12 : e, T({
238
- y: t,
239
- m: e
240
- });
241
- }, G = (e) => b.y === S.y && b.m === S.m && b.d === e ? { "data-active": "true" } : {}, K = (e) => x.y === S.y && x.m === S.m && x.d === e ? { "data-current": "true" } : {}, q = (e) => {
242
- let t = !0;
243
- return r && r.getTime() < new Date(S.y, S.m - 1, e).getTime() && (t = !1), d && d.getTime() > new Date(S.y, S.m - 1, e).getTime() && (t = !1), t;
244
- }, J = window.innerHeight - n.b < 360 ? Math.max(8, n.y - 360) : n.b;
245
- J = Math.min(J, window.innerHeight - 360 - 8), J = Math.max(8, J);
246
- let Y = window.innerWidth - n.x < 270 ? n.x - 246 : n.x;
247
- return Y = Math.max(8, Math.min(Y, window.innerWidth - 270 - 8)), /* @__PURE__ */ u(c, { children: [/* @__PURE__ */ l("div", {
248
- className: i.o,
249
- style: { zIndex: _ },
250
- onClick: () => F()
251
- }), /* @__PURE__ */ u("div", {
252
- className: [i.c, f && f + "-backdrop"].join(" "),
253
- style: {
254
- top: J + "px",
255
- left: Y + "px",
256
- zIndex: _ + 1
257
- },
258
- onClick: (e) => e.stopPropagation(),
259
- children: [
260
- /* @__PURE__ */ u("s", { children: [
261
- /* @__PURE__ */ l("i", {
262
- onClick: (e) => {
263
- e.stopPropagation(), R();
264
- },
265
- children: /* @__PURE__ */ l("svg", {
266
- width: "16",
267
- height: "16",
268
- fill: "currentColor",
269
- viewBox: "0 0 24 24",
270
- xmlns: "http://www.w3.org/2000/svg",
271
- children: /* @__PURE__ */ l("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" })
272
- })
273
- }),
274
- /* @__PURE__ */ u("h2", { children: [/* @__PURE__ */ l("span", {
275
- className: i.dateHeaderMonth,
276
- onClick: (e) => {
277
- e.stopPropagation(), D(E === "years" ? "months" : E === "months" ? "days" : "months");
278
- },
279
- title: E === "years" ? "К списку месяцев" : E === "months" ? "К календарю" : "Выбрать месяц",
280
- children: C(S.m).name
281
- }), /* @__PURE__ */ l("span", {
282
- className: i.dateHeaderYear,
283
- onClick: (e) => {
284
- e.stopPropagation(), E === "years" ? D("days") : B(e);
285
- },
286
- title: E === "years" ? "К календарю" : "Выбрать год",
287
- children: S.y
288
- })] }),
289
- /* @__PURE__ */ l("i", {
290
- onClick: (e) => {
291
- e.stopPropagation(), z();
292
- },
293
- children: /* @__PURE__ */ l("svg", {
294
- width: "16",
295
- height: "16",
296
- fill: "currentColor",
297
- viewBox: "0 0 24 24",
298
- xmlns: "http://www.w3.org/2000/svg",
299
- children: /* @__PURE__ */ l("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" })
300
- })
301
- })
302
- ] }),
303
- E === "days" && /* @__PURE__ */ u("div", {
304
- "grid-calendar": "",
305
- children: [j.map((e, t) => /* @__PURE__ */ l("p", { children: e }, "v" + t)), P.map((e, t) => /* @__PURE__ */ l("span", { children: e !== 0 && q(e) ? /* @__PURE__ */ l("b", {
306
- ...G(e),
307
- ...K(e),
308
- onClick: () => U(e),
309
- children: e
310
- }) : /* @__PURE__ */ l("p", {
311
- ...G(e),
312
- ...K(e),
313
- children: e === 0 ? "" : e
314
- }) }, t))]
315
- }),
316
- E === "months" && /* @__PURE__ */ l("div", {
317
- "grid-month": "",
318
- children: Array.from({ length: 12 }, (e, t) => {
319
- let n = t + 1, a = p(S.y, n, d, r), o = b.y === S.y && b.m === n ? { "data-active": "true" } : {}, s = x.y === S.y && x.m === n ? { "data-current": "true" } : {};
320
- return /* @__PURE__ */ l("b", {
321
- className: a ? "" : i.dateHeaderDisabled,
322
- ...o,
323
- ...s,
324
- onClick: () => a && V(n),
325
- children: C(n).abc
326
- }, n);
327
- })
328
- }),
329
- E === "years" && /* @__PURE__ */ l("div", {
330
- "grid-month": "",
331
- children: Array.from({ length: 12 }, (e, t) => {
332
- let n = O + t, a = m(n, d, r), o = b.y === n ? { "data-active": "true" } : {}, s = x.y === n ? { "data-current": "true" } : {};
333
- return /* @__PURE__ */ l("b", {
334
- className: a ? "" : i.dateHeaderDisabled,
335
- ...o,
336
- ...s,
337
- onClick: () => a && H(n),
338
- children: n
339
- }, n);
340
- })
341
- })
342
- ]
343
- })] });
344
- }, S = {
345
- val: "01",
346
- name: "—",
347
- names: "—",
348
- abc: "—"
349
- };
350
- function C(e) {
351
- let t = typeof e == "number" ? e : new Date(e).getMonth() + 1;
352
- return (!Number.isFinite(t) || t < 1 || t > 12) && (t = (/* @__PURE__ */ new Date()).getMonth() + 1), {
353
- 1: {
354
- val: "01",
355
- name: "Январь",
356
- names: "Января",
357
- abc: "Янв"
358
- },
359
- 2: {
360
- val: "02",
361
- name: "Февраль",
362
- names: "Февраля",
363
- abc: "Февр"
364
- },
365
- 3: {
366
- val: "03",
367
- name: "Март",
368
- names: "Марта",
369
- abc: "Март"
370
- },
371
- 4: {
372
- val: "04",
373
- name: "Апрель",
374
- names: "Апреля",
375
- abc: "Апр"
376
- },
377
- 5: {
378
- val: "05",
379
- name: "Май",
380
- names: "Мая",
381
- abc: "Май"
382
- },
383
- 6: {
384
- val: "06",
385
- name: "Июнь",
386
- names: "Июня",
387
- abc: "Июнь"
388
- },
389
- 7: {
390
- val: "07",
391
- name: "Июль",
392
- names: "Июля",
393
- abc: "Июль"
394
- },
395
- 8: {
396
- val: "08",
397
- name: "Август",
398
- names: "Августа",
399
- abc: "Авг"
400
- },
401
- 9: {
402
- val: "09",
403
- name: "Сентябрь",
404
- names: "Сентября",
405
- abc: "Сент"
406
- },
407
- 10: {
408
- val: "10",
409
- name: "Октябрь",
410
- names: "Октября",
411
- abc: "Окт"
412
- },
413
- 11: {
414
- val: "11",
415
- name: "Ноябрь",
416
- names: "Ноября",
417
- abc: "Нояб"
418
- },
419
- 12: {
420
- val: "12",
421
- name: "Декабрь",
422
- names: "Декабря",
423
- abc: "Дек"
424
- }
425
- }[t] ?? S;
426
- }
427
- function w(e, t) {
428
- let n = t + "";
429
- for (; n.length < e;) n = "0" + n;
430
- return n;
431
- }
432
- function T(e, t) {
433
- let n, r;
434
- t === void 0 ? (r = String(e), n = /* @__PURE__ */ new Date()) : (r = t, n = new Date(e)), Number.isNaN(n.getTime()) && (n = /* @__PURE__ */ new Date());
435
- let i = r, a = {
436
- yyyy: n.getFullYear(),
437
- yy: ("" + n.getFullYear()).slice(-2),
438
- mm: ("0" + (n.getMonth() + 1)).slice(-2),
439
- dd: ("0" + n.getDate()).slice(-2),
440
- HH: ("0" + n.getHours()).slice(-2),
441
- MM: ("0" + n.getMinutes()).slice(-2),
442
- SS: ("0" + n.getSeconds()).slice(-2),
443
- __: " \xA0\xA0\xA0\xA0 ",
444
- _: " \xA0\xA0 "
445
- };
446
- for (let e in a) i = i.replace(e, String(a[e]));
447
- return i;
448
- }
449
- //#endregion
450
- export { b 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{isEmptyTextLike as r}from"./visibility.js";import i from"../styles/Form.module.js";import{acquireOverlayZIndex as a,releaseOverlayZIndex as o}from"../overlayZ.js";import s from"react";import{Fragment as c,jsx as l,jsxs as u}from"react/jsx-runtime";import{createPortal as d}from"react-dom";function f(e){return!!(e==null||typeof e==`string`&&r(e)||e instanceof Date&&Number.isNaN(e.getTime()))}function p(e,t,n,r){let i=new Date(e,t-1,1);return!(n&&new Date(e,t,0)<n||r&&i>r)}function m(e,t,n){return!(t&&e<t.getFullYear()||n&&e>n.getFullYear())}function h(e,t,n){let r=e;if(t){let e=t.getFullYear();r+11<e&&(r=e-11),r<e&&(r=e)}if(n){let e=n.getFullYear();r>e&&(r=e-11),r+11>e&&(r=e-11)}return r}function g(e){if(!(e instanceof HTMLElement))return!1;let t=e.tagName;return t===`INPUT`||t===`TEXTAREA`||t===`SELECT`?!0:!!e.isContentEditable}function _(e){let t=(e||``).trim();if(!t)return null;let n=t.split(/\s+/)[0].replace(/,/g,`.`),r=(e,t,n)=>{if(t<1||t>12||n<1||n>31)return null;let r=e<100?2e3+e:e,i=new Date(r,t-1,n);return Number.isNaN(i.getTime())||i.getFullYear()!==r||i.getMonth()!==t-1||i.getDate()!==n?null:i},i=/^(\d{1,2})[./](\d{1,2})[./](\d{2,4})$/.exec(n);if(i)return r(parseInt(i[3],10),parseInt(i[2],10),parseInt(i[1],10));if(i=/^(\d{4})-(\d{1,2})-(\d{1,2})$/.exec(n),i)return r(parseInt(i[1],10),parseInt(i[2],10),parseInt(i[3],10));if(i=/^(\d{1,2})\/(\d{1,2})\/(\d{2,4})$/.exec(n),i)return r(parseInt(i[3],10),parseInt(i[2],10),parseInt(i[1],10));let a=n.replace(/\D/g,``);return a.length===8?r(parseInt(a.slice(4,8),10),parseInt(a.slice(2,4),10),parseInt(a.slice(0,2),10))||r(parseInt(a.slice(0,4),10),parseInt(a.slice(4,6),10),parseInt(a.slice(6,8),10)):null}function v(e,t,n){let r=e.getTime();return t&&r<t.getTime()&&(r=t.getTime()),n&&r>n.getTime()&&(r=n.getTime()),new Date(r)}function y(e){return e.getFullYear()+`-`+w(2,e.getMonth()+1)+`-`+w(2,e.getDate())}function b({label:i=``,error:a,hidden:o=!1,className:p,placeholder:m,disabled:h=!1,onValue:b,max:S,min:C,form:w,icon:E,name:D=``,value:O,after:k=``,before:A=``}){let j=s.useCallback(e=>{if(e==null||typeof e==`string`&&r(e))return``;if(e instanceof Date)return Number.isNaN(e.getTime())?``:e;if(typeof e==`string`||typeof e==`number`){let t=new Date(e);return Number.isNaN(t.getTime())?``:e}return``},[]),{value:M}=n(w,D,O),[N,P]=s.useState(j(M)),F=s.useRef(null),[I,L]=s.useState(null),[R,z]=s.useState(!1),B=s.useCallback(()=>{let e=F.current;if(!e)return;let t=e.getBoundingClientRect();L({x:t.left,y:t.top,b:t.bottom})},[]);s.useEffect(()=>{if(!R)return;B();let e=()=>{B()};return window.addEventListener(`scroll`,e,!0),window.addEventListener(`resize`,e),()=>{window.removeEventListener(`scroll`,e,!0),window.removeEventListener(`resize`,e)}},[R,B]),s.useEffect(()=>{P(j(M))},[M,j]);let V=s.useCallback(e=>{let t={value:e,name:D};P(e),w&&D&&w.setValue(t),b&&b!==w?.onValue&&b(t)},[w,D,b]);s.useEffect(()=>{if(!R||h)return;let e=``,t=t=>{let n=_(t);if(!n)return!1;let r=y(v(n,C,S));return r===e?!0:(e=r,V(r),z(!1),!0)},n=e=>{g(e.target)||t(e.clipboardData?.getData(`text/plain`)??``)&&(e.preventDefault(),e.stopPropagation())},r=e=>{(e.ctrlKey||e.metaKey)&&(e.key!==`v`&&e.key!==`V`||g(e.target)||navigator.clipboard?.readText&&(e.preventDefault(),navigator.clipboard.readText().then(e=>{t(e)})))};return document.addEventListener(`paste`,n,!0),window.addEventListener(`keydown`,r,!0),()=>{document.removeEventListener(`paste`,n,!0),window.removeEventListener(`keydown`,r,!0)}},[R,h,C,S,V]);let H=e=>{if(h)return;let t=e.currentTarget.getBoundingClientRect();L({x:t.left,y:t.top,b:t.bottom}),z(!0)},U={};m&&(U.placeholder=m);let W=M==null||M===``||typeof M==`string`&&r(M);return o&&W?l(c,{}):u(c,{children:[E?E():u(t,{type:`date`,label:i,error:a,element_blok:{className:[p||``]},element_input:{className:[e.w],props:{"data-disabled":h?`true`:void 0}},children:[A?l(`span`,{className:e.affix,children:A}):null,l(`div`,{ref:F,onClick:H,onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),H(e))},tabIndex:h?-1:0,role:`button`,"aria-haspopup":`dialog`,"aria-expanded":R,"aria-label":i||m||`Дата`,"data-edit":h?void 0:`true`,...U,style:{cursor:h?`not-allowed`:`pointer`},children:f(N)?``:T(N,`dd.mm.yyyy`)}),k?l(`span`,{className:e.affix,children:k}):null]}),R&&I&&d(l(x,{position:I,onValue:V,date:N,max:S,min:C,onOpen:z,className:p},`elcrm-date-popup`),document.body)]})}b.displayName=`DateField`;var x=({date:e,onValue:t,position:n,max:r,min:d,className:f,onOpen:g})=>{let[_]=s.useState(()=>a());s.useEffect(()=>()=>o(_),[_]);let v=new Date,y=new Date(e);Number.isNaN(y.getTime())&&(y=new Date);let b={y:v.getFullYear(),d:v.getDate(),m:v.getMonth()+1},x={y:y.getFullYear(),d:y.getDate(),m:y.getMonth()+1},[S,T]=s.useState({y:x.y,m:x.m}),[E,D]=s.useState(`days`),[O,k]=s.useState(()=>h(x.y-5,d,r)),A=e=>{let t=e.getDay();return t===0&&(t=7),t-1},j=[`пн`,`вт`,`ср`,`чт`,`пт`,`сб`,`вс`],M=S.m-1,N=new Date(S.y,M),P=[];for(let e=0;e<A(N);e++)P.push(0);for(;N.getMonth()===M;)P.push(N.getDate()),N.setDate(N.getDate()+1);let F=()=>{g(!1)},I=()=>{W(S.m+1,S.y)},L=()=>{W(S.m-1,S.y)},R=()=>{E===`days`?L():E===`months`?W(S.m,S.y-1):k(e=>h(e-12,d,r))},z=()=>{E===`days`?I():E===`months`?W(S.m,S.y+1):k(e=>h(e+12,d,r))},B=e=>{e.stopPropagation(),k(h(S.y-5,d,r)),D(`years`)},V=e=>{p(S.y,e,d,r)&&(T({y:S.y,m:e}),D(`days`))},H=e=>{m(e,d,r)&&(T({y:e,m:S.m}),D(`days`))},U=e=>{t(S.y+`-`+w(2,S.m)+`-`+w(2,e)),F()},W=(e,t)=>{t=e>12?t+1:e<1?t-1:t,e=e>12?1:e<1?12:e,T({y:t,m:e})},G=e=>b.y===S.y&&b.m===S.m&&b.d===e?{"data-active":`true`}:{},K=e=>x.y===S.y&&x.m===S.m&&x.d===e?{"data-current":`true`}:{},q=e=>{let t=!0;return r&&r.getTime()<new Date(S.y,S.m-1,e).getTime()&&(t=!1),d&&d.getTime()>new Date(S.y,S.m-1,e).getTime()&&(t=!1),t},J=window.innerHeight-n.b<360?Math.max(8,n.y-360):n.b;J=Math.min(J,window.innerHeight-360-8),J=Math.max(8,J);let Y=window.innerWidth-n.x<270?n.x-246:n.x;return Y=Math.max(8,Math.min(Y,window.innerWidth-270-8)),u(c,{children:[l(`div`,{className:i.o,style:{zIndex:_},onClick:()=>F()}),u(`div`,{className:[i.c,f&&f+`-backdrop`].join(` `),style:{top:J+`px`,left:Y+`px`,zIndex:_+1},onClick:e=>e.stopPropagation(),children:[u(`s`,{children:[l(`i`,{onClick:e=>{e.stopPropagation(),R()},children:l(`svg`,{width:`16`,height:`16`,fill:`currentColor`,viewBox:`0 0 24 24`,xmlns:`http://www.w3.org/2000/svg`,children:l(`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`})})}),u(`h2`,{children:[l(`span`,{className:i.dateHeaderMonth,onClick:e=>{e.stopPropagation(),D(E===`years`?`months`:E===`months`?`days`:`months`)},title:E===`years`?`К списку месяцев`:E===`months`?`К календарю`:`Выбрать месяц`,children:C(S.m).name}),l(`span`,{className:i.dateHeaderYear,onClick:e=>{e.stopPropagation(),E===`years`?D(`days`):B(e)},title:E===`years`?`К календарю`:`Выбрать год`,children:S.y})]}),l(`i`,{onClick:e=>{e.stopPropagation(),z()},children:l(`svg`,{width:`16`,height:`16`,fill:`currentColor`,viewBox:`0 0 24 24`,xmlns:`http://www.w3.org/2000/svg`,children:l(`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`})})})]}),E===`days`&&u(`div`,{"grid-calendar":``,role:`grid`,"aria-label":`Календарь`,children:[j.map((e,t)=>l(`p`,{role:`columnheader`,children:e},`v`+t)),P.map((e,t)=>l(`span`,{role:`gridcell`,children:e!==0&&q(e)?l(`b`,{role:`button`,tabIndex:0,"aria-label":`${e}`,...G(e),...K(e),"aria-selected":K(e)[`data-current`]?`true`:void 0,onClick:()=>U(e),onKeyDown:t=>{(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),U(e))},children:e}):l(`p`,{"aria-disabled":e===0?void 0:!0,...G(e),...K(e),children:e===0?``:e})},t))]}),E===`months`&&l(`div`,{"grid-month":``,role:`listbox`,"aria-label":`Месяц`,children:Array.from({length:12},(e,t)=>{let n=t+1,a=p(S.y,n,d,r),o=b.y===S.y&&b.m===n?{"data-active":`true`}:{},s=x.y===S.y&&x.m===n?{"data-current":`true`}:{};return l(`b`,{role:`option`,tabIndex:a?0:-1,"aria-selected":s[`data-current`]?`true`:`false`,"aria-disabled":a?void 0:!0,className:a?``:i.dateHeaderDisabled,...o,...s,onClick:()=>a&&V(n),onKeyDown:e=>{a&&(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),V(n))},children:C(n).abc},n)})}),E===`years`&&l(`div`,{"grid-month":``,role:`listbox`,"aria-label":`Год`,children:Array.from({length:12},(e,t)=>{let n=O+t,a=m(n,d,r),o=b.y===n?{"data-active":`true`}:{},s=x.y===n?{"data-current":`true`}:{};return l(`b`,{role:`option`,tabIndex:a?0:-1,"aria-selected":s[`data-current`]?`true`:`false`,"aria-disabled":a?void 0:!0,className:a?``:i.dateHeaderDisabled,...o,...s,onClick:()=>a&&H(n),onKeyDown:e=>{a&&(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),H(n))},children:n},n)})})]})]})},S={val:`01`,name:`—`,names:`—`,abc:`—`};function C(e){let t=typeof e==`number`?e:new Date(e).getMonth()+1;return(!Number.isFinite(t)||t<1||t>12)&&(t=new Date().getMonth()+1),{1:{val:`01`,name:`Январь`,names:`Января`,abc:`Янв`},2:{val:`02`,name:`Февраль`,names:`Февраля`,abc:`Февр`},3:{val:`03`,name:`Март`,names:`Марта`,abc:`Март`},4:{val:`04`,name:`Апрель`,names:`Апреля`,abc:`Апр`},5:{val:`05`,name:`Май`,names:`Мая`,abc:`Май`},6:{val:`06`,name:`Июнь`,names:`Июня`,abc:`Июнь`},7:{val:`07`,name:`Июль`,names:`Июля`,abc:`Июль`},8:{val:`08`,name:`Август`,names:`Августа`,abc:`Авг`},9:{val:`09`,name:`Сентябрь`,names:`Сентября`,abc:`Сент`},10:{val:`10`,name:`Октябрь`,names:`Октября`,abc:`Окт`},11:{val:`11`,name:`Ноябрь`,names:`Ноября`,abc:`Нояб`},12:{val:`12`,name:`Декабрь`,names:`Декабря`,abc:`Дек`}}[t]??S}function w(e,t){let n=t+``;for(;n.length<e;)n=`0`+n;return n}function T(e,t){let n,r;t===void 0?(r=String(e),n=new Date):(r=t,n=new Date(e)),Number.isNaN(n.getTime())&&(n=new Date);let i=r,a={yyyy:n.getFullYear(),yy:(``+n.getFullYear()).slice(-2),mm:(`0`+(n.getMonth()+1)).slice(-2),dd:(`0`+n.getDate()).slice(-2),HH:(`0`+n.getHours()).slice(-2),MM:(`0`+n.getMinutes()).slice(-2),SS:(`0`+n.getSeconds()).slice(-2),__:` \xA0\xA0\xA0\xA0 `,_:` \xA0\xA0 `};for(let e in a)i=i.replace(e,String(a[e]));return i}export{b as default};
@@ -8,7 +8,7 @@ export type TDisplay = TInput & {
8
8
  format?: (value: unknown) => string;
9
9
  emptyText?: string;
10
10
  };
11
- declare function DisplayField({ value, form, name, placeholder, label, error, hidden, className, after, before, format, emptyText, }: TDisplay): import("react/jsx-runtime").JSX.Element | null;
11
+ declare function DisplayField({ value, form, name, placeholder, label, error, hidden, className, after, before, format, emptyText, size, }: TDisplay): import("react/jsx-runtime").JSX.Element | null;
12
12
  declare namespace DisplayField {
13
13
  var displayName: string;
14
14
  }
@@ -1,49 +1 @@
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 "react";
6
- import { jsx as i, jsxs as a } from "react/jsx-runtime";
7
- //#region src/lib/fields/Display.tsx
8
- function o(e) {
9
- if (e == null) return "";
10
- if (typeof e == "string") return e;
11
- if (typeof e == "number" || typeof e == "boolean") return String(e);
12
- if (Array.isArray(e)) return e.map(String).join(", ");
13
- try {
14
- return JSON.stringify(e);
15
- } catch {
16
- return String(e);
17
- }
18
- }
19
- function s({ value: s = "", form: c, name: l = "", placeholder: u = "", label: d = "", error: f = "", hidden: p = !1, className: m = "", after: h = "", before: g = "", format: _ = o, emptyText: v }) {
20
- let { value: y } = n(c, l, s), b = _(y), x = !b.trim(), S = x ? v || u || "—" : b;
21
- return p && r(y) ? null : /* @__PURE__ */ a(t, {
22
- type: "display",
23
- label: d,
24
- error: f,
25
- element_blok: { className: [m || ""] },
26
- element_input: {
27
- className: [e.w, e.display],
28
- props: { "data-readonly": "true" }
29
- },
30
- children: [
31
- g ? /* @__PURE__ */ i("span", {
32
- className: e.affix,
33
- children: g
34
- }) : null,
35
- /* @__PURE__ */ i("div", {
36
- className: x ? e.displayEmpty : void 0,
37
- "aria-label": d || "Значение",
38
- children: S
39
- }),
40
- h ? /* @__PURE__ */ i("span", {
41
- className: e.affix,
42
- children: h
43
- }) : null
44
- ]
45
- });
46
- }
47
- s.displayName = "DisplayField";
48
- //#endregion
49
- export { s 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{isEmptyTextLike as r}from"./visibility.js";import"react";import{jsx as i,jsxs as a}from"react/jsx-runtime";function o(e){if(e==null)return``;if(typeof e==`string`)return e;if(typeof e==`number`||typeof e==`boolean`)return String(e);if(Array.isArray(e))return e.map(String).join(`, `);try{return JSON.stringify(e)}catch{return String(e)}}function s({value:s=``,form:c,name:l=``,placeholder:u=``,label:d=``,error:f=``,hidden:p=!1,className:m=``,after:h=``,before:g=``,format:_=o,emptyText:v,size:y=`md`}){let{value:b}=n(c,l,s),x=_(b),S=!x.trim(),C=S?v||u||`—`:x;return p&&r(b)?null:a(t,{type:`display`,label:d,error:f,size:y,element_blok:{className:[m||``]},element_input:{className:[e.w,e.display],props:{"data-readonly":`true`}},children:[g?i(`span`,{className:e.affix,children:g}):null,i(`div`,{className:S?e.displayEmpty:void 0,"aria-label":d||`Значение`,children:C}),h?i(`span`,{className:e.affix,children:h}):null]})}s.displayName=`DisplayField`;export{s as default};