@elcrm/form 0.0.68 → 0.0.70

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 CHANGED
@@ -12,7 +12,7 @@ npm install @elcrm/form
12
12
 
13
13
  ## Стили и темы
14
14
 
15
- - **Базовые стили полей** (Field / Form / Select) встраиваются **в JS** при первом импорте компонента: **`dist/embedBaseStyles.js`** вставляет склеённый CSS в `<head>` (настройки **css-loader** в приложении **не нужны**). Срабатывает и при импорте с **корня** (`@elcrm/form`), и при **подпутях** (`@elcrm/form/fields/Date` и т.д.) — через **`core/Field`**.
15
+ - **Базовые стили полей** (Field / Form / Select) **вшиты в начало** `dist/index.js` и `dist/core/Field.js` (скрипт сборки): при загрузке модуля в `<head>` добавляется один `<style>` — **отдельные CSS-файлы и настройка css-loader в приложении не нужны**. Работает и с **корня** (`@elcrm/form`), и с **подпутями** стили подхватывает **`Field`**.
16
16
  - **Опционально** можно по-прежнему подключить **`@elcrm/form/style.css`** вручную (тот же текст, что во встраивании) — например для SSR без клиентского JS.
17
17
  - **Темы** (светлая / тёмная): **`@elcrm/form/light.css`**, **`@elcrm/form/dark.css`** — атрибут **`data-theme`** на контейнере (подключаются вручную).
18
18
 
@@ -1,4 +1,14 @@
1
- import '../embedBaseStyles.js';
1
+ /* @elcrm/form:base-styles-inline */
2
+ (function () {
3
+ if (typeof document === "undefined") return;
4
+ if (document.getElementById("elcrm-form-base-styles")) return;
5
+ var el = document.createElement("style");
6
+ el.id = "elcrm-form-base-styles";
7
+ el.setAttribute("data-elcrm", "form");
8
+ el.textContent = "._l_zzcgd_2{min-width:var(--field-width);gap:var(--field-block-gap,0);flex-direction:column;margin:0;padding:0;display:flex;position:relative}._l_zzcgd_2>dt,._l_zzcgd_2>dd{margin:0;padding:0}._l_zzcgd_2[data-field=group] div{cursor:pointer;border-bottom:var(--field-border);padding:var(--field-padding);margin:0}._l_zzcgd_2[data-field=group] div:last-child{border-bottom:0}._l_zzcgd_2 [placeholder]:empty:before{content:attr(placeholder);color:var(--field-placeholder);display:block}._l_zzcgd_2 [placeholder]:focus:before{display:none}._f_zzcgd_33{box-sizing:border-box;align-items:center;gap:var(--field-icon-gap,10px);border:var(--field-border);border-radius:var(--field-radius);background:var(--field-background);color:var(--field-color);padding:0 var(--field-side-padding,14px);transition:border-color .16s,box-shadow .16s,background-color .16s,opacity .16s;display:flex;overflow:hidden}._f_zzcgd_33:hover{border-color:var(--field-border-hover,var(--field-border))}._f_zzcgd_33:focus-within{border-color:var(--field-border-focus,var(--field-border));box-shadow:0 0 0 3px var(--field-focus-ring,#0000);background:var(--field-background-focus,var(--field-background))}._f_zzcgd_33._e_zzcgd_57:focus-within{background:var(--field-error-background);color:var(--field-error-color)}._f_zzcgd_33[data-disabled=true]{background:var(--field-background-disabled,var(--field-background));border-color:var(--field-border-disabled,var(--field-border));color:var(--field-color-disabled,var(--field-placeholder));cursor:not-allowed;opacity:.85}._f_zzcgd_33[data-disabled=true]>*{cursor:not-allowed}._f_zzcgd_33>div{min-height:var(--field-height);line-height:calc(var(--field-height) - 2px);padding:var(--field-inner-padding,0 2px);font-size:var(--control-font-size,14px);text-wrap:pretty;outline:0;flex:1;margin:0}._f_zzcgd_33>div::selection{background:var(--field-selection-bg,#b3d4fc);color:var(--field-selection-color,inherit)}._f_zzcgd_33>:not(div){color:var(--field-icon-color,var(--field-placeholder));flex:none;justify-content:center;align-items:center;display:inline-flex}._f_zzcgd_33>:not(div) svg{width:20px;height:20px}._n_zzcgd_97 div{min-height:var(--field-note-height);line-height:var(--field-note-line-height);padding-top:var(--field-note-padding,var(--field-note-padding-top,8px));padding-bottom:var(--field-note-padding,var(--field-note-padding-top,8px))}._w_zzcgd_104>div{text-wrap:nowrap;overflow:scroll hidden}._w_zzcgd_104>div::-webkit-scrollbar{width:0;height:0}._time_zzcgd_114>div{text-wrap:nowrap;align-items:center;min-width:0;display:flex;overflow:visible}._time_zzcgd_114 ._timeInner_zzcgd_121{justify-content:flex-start;align-items:center;gap:4px;width:100%;min-width:0;display:flex}._time_zzcgd_114._timeAlignCenter_zzcgd_132 ._timeInner_zzcgd_121{justify-content:center}._time_zzcgd_114 ._timeSep_zzcgd_135{opacity:.65;-webkit-user-select:none;user-select:none;flex:none;padding:0 2px;font-weight:500;transform:translateY(-1px)}._time_zzcgd_114 ._timePart_zzcgd_146{box-sizing:border-box;width:1em;min-width:0;color:inherit;font:inherit;line-height:inherit;text-align:left;min-height:var(--field-height);cursor:text;background:0 0;border:0;border-radius:6px;outline:none;flex:none;margin:0;padding:0}._time_zzcgd_114 ._timePart_zzcgd_146[contenteditable=false]{cursor:not-allowed;opacity:.7}._time_zzcgd_114 ._timePart_zzcgd_146:empty:before{content:attr(placeholder);color:var(--field-placeholder);opacity:.6}._time_zzcgd_114 ._timePart_zzcgd_146:focus:empty:before{content:none}._time_zzcgd_114 ._timePart_zzcgd_146:focus-visible{background:0 0}._time_zzcgd_114._timeAlignCenter_zzcgd_132 ._timePart_zzcgd_146{text-align:center}._t_zzcgd_114{color:var(--field-label-color);font-size:var(--field-label-size);padding-bottom:10px}._g_zzcgd_192{flex-direction:column}._range_zzcgd_196>div{box-sizing:border-box;min-width:0;min-height:var(--field-height);flex:1;align-items:center;line-height:normal;display:flex}._range_zzcgd_196 ._rangeTrack_zzcgd_205{box-sizing:border-box;width:100%;height:var(--field-range-bar-height,14px);background:var(--field-range-track,#e0e0e0);cursor:pointer;touch-action:none;border-radius:999px;outline:none;flex-shrink:0;position:relative;overflow:hidden}._range_zzcgd_196 ._rangeTrack_zzcgd_205:focus-visible{box-shadow:0 0 0 3px var(--field-focus-ring,#0000)}._range_zzcgd_196 ._rangeTrack_zzcgd_205[data-disabled=true]{cursor:not-allowed;opacity:.55;pointer-events:none}._range_zzcgd_196 ._rangeFill_zzcgd_226{background:var(--field-range-fill,#00b5ad);pointer-events:none;border-radius:999px 0 0 999px;width:0;min-width:0;height:100%}._range_zzcgd_196 ._rangeFillFull_zzcgd_237{border-radius:999px}._h_zzcgd_241{--field-border:0}._h_zzcgd_241 div{border:var(--field-check-box-border,--field-border);width:var(--field-height);height:var(--field-height);border-radius:var(--field-radius);background:var(--field-background);cursor:pointer;flex:none;gap:10px;margin:0;position:relative}._h_zzcgd_241 div[aria-checked=true]{background:var(--field-background-active)}._h_zzcgd_241 div:after{content:\"\";background:0 0;border-top:none;border-bottom:3px solid #fcfff4;border-left:3px solid #fcfff4;border-right:none;width:9px;height:5px;margin:4px;position:absolute;top:5px;left:4px;transform:rotate(-45deg)}._e_zzcgd_57{border-color:var(--field-error-border);background:var(--field-error-background);color:var(--field-error-color)}._m_zzcgd_280{color:var(--field-error-color);margin-top:6px;font-size:12px;font-style:normal}\n\n._o_j48yg_2{z-index:98;background:0 0;position:fixed;inset:0}._c_j48yg_13{background:var(--select-background);z-index:99;color:#fff;box-sizing:border-box;border-radius:10px;min-width:259px;max-height:min(92vh,480px);margin:0;padding:10px 12px 12px;display:block;position:absolute;overflow:hidden auto;box-shadow:5px 7px 18px #000000a8}._c_j48yg_13 [grid-calendar]{grid-template-columns:repeat(7,1fr);grid-auto-rows:34px;gap:2px;display:grid}._c_j48yg_13 [grid-calendar]>p{color:var(--color-placeholder);box-sizing:border-box;justify-content:center;align-items:center;margin:0;padding:0;font-size:.75rem;font-weight:500;line-height:1;display:flex}._c_j48yg_13 [grid-month]{grid-template-columns:1fr 1fr 1fr 1fr;width:250px;display:grid}._c_j48yg_13 b{cursor:pointer;text-align:center;border-radius:5px;padding:8px 5px;font-weight:400;display:block}._c_j48yg_13 b.__active_j48yg_64{background:var(--bg-select-active)}._c_j48yg_13 b:hover{background:var(--bg-select-hover)}._c_j48yg_13 p{color:var(--color-placeholder);text-align:center;cursor:default;pointer-events:none;padding:0}._c_j48yg_13 i{text-align:center;cursor:pointer;border-radius:5px;flex:0 30px;padding:9px}._c_j48yg_13 i:hover{background:var(--bg-select-hover)}._c_j48yg_13 i:before{cursor:pointer;display:block}._c_j48yg_13 s{align-items:center;gap:4px;padding-bottom:6px;font-style:normal;text-decoration:none;display:flex}._c_j48yg_13 s h2{text-align:center;color:#fff;cursor:default;flex-wrap:nowrap;flex:auto;justify-content:center;align-items:center;gap:8px;min-width:0;margin:0;padding:0;font-size:16px;font-weight:400;line-height:1.25;display:flex}._c_j48yg_13 ._dateHeaderMonth_j48yg_119,._c_j48yg_13 ._dateHeaderYear_j48yg_119{cursor:pointer;-webkit-user-select:none;user-select:none;white-space:nowrap;border-radius:6px;padding:2px 8px}._c_j48yg_13 ._dateHeaderMonth_j48yg_119:hover,._c_j48yg_13 ._dateHeaderYear_j48yg_119:hover{background:var(--bg-select-hover)}._c_j48yg_13 ._dateHeaderDisabled_j48yg_129{cursor:not-allowed;opacity:.45;pointer-events:none}._c_j48yg_13 ._dateHeaderDisabled_j48yg_129[data-active=true],._c_j48yg_13 ._dateHeaderDisabled_j48yg_129[data-current=true]{opacity:.45}._c_j48yg_13 [grid-calendar] b[data-current=true],._c_j48yg_13 [grid-month] b[data-current=true]{background:color-mix(in srgb, var(--field-background-active) 52%, transparent);font-weight:600}._c_j48yg_13 [grid-calendar] b[data-active=true]:not([data-current=true]),._c_j48yg_13 [grid-month] b[data-active=true]:not([data-current=true]){outline:2px solid var(--field-background-active);outline-offset:-2px}._c_j48yg_13 [grid-calendar] b[data-active=true][data-current=true],._c_j48yg_13 [grid-month] b[data-active=true][data-current=true]{box-shadow:inset 0 0 0 2px var(--field-background-active)}._c_j48yg_13 [grid-calendar] p[data-current=true]{background:color-mix(in srgb, var(--field-background-active) 52%, transparent);color:inherit;border-radius:5px;font-weight:600}._c_j48yg_13 [grid-calendar] p[data-active=true]:not([data-current=true]){outline:2px solid var(--field-background-active);outline-offset:-2px;opacity:.85}._c_j48yg_13 [grid-calendar] p[data-active=true][data-current=true]{box-shadow:inset 0 0 0 2px var(--field-background-active)}._c_j48yg_13 span{text-align:center;padding:2px}._c_j48yg_13 span p{color:var(--color-placeholder);padding:8px 5px}._c_j48yg_13 [grid-calendar]>span{box-sizing:border-box;justify-content:stretch;align-items:stretch;min-height:0;padding:0;display:flex}._c_j48yg_13 [grid-calendar]>span>b,._c_j48yg_13 [grid-calendar]>span>p{box-sizing:border-box;border-radius:5px;flex:auto;justify-content:center;align-items:center;width:100%;min-height:0;margin:0;padding:0;display:flex}._c_j48yg_13 ._as_j48yg_196{cursor:ns-resize}._c_j48yg_13 ._ap_j48yg_199{cursor:pointer}[field=password] dd{white-space:nowrap;font-style:unset;-webkit-text-security:disc;-webkit-user-select:text;user-select:text}[field=password][show] dd,[field=password] dd:before{-webkit-text-security:none}[field=code] div{gap:8px;display:flex}[field=select] dd{cursor:pointer}[field] dd:before{pointer-events:none}[field=check] dd{cursor:pointer;max-width:35px;padding:0}[field=check] [active]:after{content:\"\";background:#394264;border-radius:5px;width:15px;height:15px;display:block}[field=file] input{display:none}[field=file] dd{aspect-ratio:16/9;cursor:pointer;position:relative}[field=file] img{aspect-ratio:16/9;object-fit:contain;cursor:pointer;width:-webkit-fill-available;display:block}[field=file] label{aspect-ratio:16/9;object-fit:contain;cursor:pointer;width:-webkit-fill-available;display:block;position:absolute}[field=color] dd{border:0;gap:3px;padding:0;display:flex}[field=color] dd s{cursor:pointer;opacity:.6;border:1px solid #dde2e4;border-radius:6px;flex:1}[field=color] dd s:hover{opacity:.9}[field=color] dd s[active=true]{opacity:1}\n\n:root{--select-overlay:#0000;--select-height:52px;--select-separator:1px solid #40434c;--select-color:#e8e8eb;--select-background:#26282e;--select-icon:calc(--select-height / 1.5);--select-icon-padding:calc((--select-height - --select-icon) / 2);--select-font-size:13px}._o_1q26w_12{z-index:98;background:var(--select-overlay);position:fixed;inset:0}._l_1q26w_22{background:var(--select-background);z-index:99;border-radius:20px;max-height:300px;margin:0;padding:0;display:block;position:fixed;overflow:scroll}._l_1q26w_22::-webkit-scrollbar{width:0;height:0}._l_1q26w_22 ul{width:100%;max-height:300px;margin:0;padding:0;list-style:none;display:block;overflow:hidden auto}._l_1q26w_22 li{border-bottom:var(--select-separator);cursor:pointer;color:var(--select-color);height:var(--select-height);line-height:var(--select-height);font-size:var(--select-font-size);white-space:nowrap;text-overflow:ellipsis;opacity:1;margin:0;padding:0 14px;display:block;overflow:hidden;text-align:left!important;border-left:0!important}._l_1q26w_22 li:hover,._l_1q26w_22 li[data-focus=true]{background:#2f323a}._l_1q26w_22 li:last-child{border-bottom:0}._i_1q26w_80{width:var(--select-icon);height:var(--select-icon);color:var(--field-color);right:var(--select-icon-padding);top:var(--select-icon-padding);position:absolute}._f_1q26w_89{cursor:pointer}._f_1q26w_89[aria-disabled=true]{cursor:not-allowed}\n";
9
+ document.head.appendChild(el);
10
+ })();
11
+
2
12
  import e from "../styles/Field.module.js";
3
13
  import { jsx as t, jsxs as n } from "react/jsx-runtime";
4
14
  //#region src/lib/core/Field.tsx
@@ -26,37 +26,41 @@ function f(e, t, n) {
26
26
  }
27
27
  return r;
28
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({
29
+ function p({ label: i = "", error: u, hidden: d = !1, className: f, placeholder: p, disabled: h = !1, onValue: g, max: _, min: y, form: b, icon: x, name: S = "", value: C, after: w = "", before: T = "" }) {
30
+ let E = a.useCallback((e) => {
31
+ if (e == null) return /* @__PURE__ */ new Date();
32
+ if (e instanceof Date) return Number.isNaN(e.getTime()) ? /* @__PURE__ */ new Date() : e;
33
+ if (typeof e == "string" || typeof e == "number") {
34
+ let t = new Date(e);
35
+ return Number.isNaN(t.getTime()) ? /* @__PURE__ */ new Date() : e;
36
+ }
37
+ return /* @__PURE__ */ new Date();
38
+ }, []), { value: D } = n(b, S, C), [O, k] = a.useState(E(D)), A = a.useRef({
31
39
  x: 0,
32
40
  y: 0,
33
41
  b: 0
34
- }), [M, N] = a.useState(!1);
42
+ }), [j, M] = a.useState(!1);
35
43
  a.useEffect(() => {
36
- A(E(D));
37
- }, [
38
- D,
39
- O,
40
- E
41
- ]);
42
- let P = (e) => {
44
+ k(E(D));
45
+ }, [D, E]);
46
+ let N = (e) => {
43
47
  let t = {
44
48
  value: e,
45
49
  name: S
46
50
  };
47
- b && S ? b.setValue(t) : A(e), g && g !== b?.onValue && g(t);
48
- }, F = (e) => {
51
+ b && S ? b.setValue(t) : k(e), g && g !== b?.onValue && g(t);
52
+ }, P = (e) => {
49
53
  if (h) return;
50
54
  let t = e.currentTarget.getBoundingClientRect();
51
- j.current = {
55
+ A.current = {
52
56
  x: t.left,
53
57
  b: t.bottom,
54
58
  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, {
59
+ }, M(!0);
60
+ }, F = {};
61
+ p && (F.placeholder = p);
62
+ let I = D == null || D === "" || typeof D == "string" && r(D);
63
+ return d && I ? /* @__PURE__ */ s(o, {}) : /* @__PURE__ */ c(o, { children: [x ? x() : /* @__PURE__ */ c(t, {
60
64
  type: "date",
61
65
  label: i,
62
66
  error: u,
@@ -68,38 +72,40 @@ function p({ label: i = "", error: u, hidden: d = !1, className: f, placeholder:
68
72
  children: [
69
73
  T,
70
74
  /* @__PURE__ */ s("div", {
71
- onClick: F,
75
+ onClick: P,
72
76
  onKeyDown: (e) => {
73
- (e.key === "Enter" || e.key === " ") && (e.preventDefault(), F(e));
77
+ (e.key === "Enter" || e.key === " ") && (e.preventDefault(), P(e));
74
78
  },
75
79
  tabIndex: h ? -1 : 0,
76
80
  role: "button",
77
81
  "aria-haspopup": "dialog",
78
- "aria-expanded": M,
82
+ "aria-expanded": j,
79
83
  "aria-label": i || p || "Дата",
80
84
  "data-edit": h ? void 0 : "true",
81
- ...I,
85
+ ...F,
82
86
  style: { cursor: h ? "not-allowed" : "pointer" },
83
- children: _(k, "dd.mm.yyyy")
84
- }, O),
87
+ children: v(O, "dd.mm.yyyy")
88
+ }),
85
89
  w
86
90
  ]
87
- }), M && l(/* @__PURE__ */ s(m, {
88
- position: j.current,
89
- onValue: P,
90
- date: k,
91
- max: v,
91
+ }), j && l(/* @__PURE__ */ s(m, {
92
+ position: A.current,
93
+ onValue: N,
94
+ date: O,
95
+ max: _,
92
96
  min: y,
93
- onOpen: N,
97
+ onOpen: M,
94
98
  className: f
95
99
  }, (/* @__PURE__ */ new Date()).getTime()), document.body)] });
96
100
  }
97
101
  p.displayName = "DateField";
98
102
  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
+ let h = /* @__PURE__ */ new Date(), v = new Date(e);
104
+ Number.isNaN(v.getTime()) && (v = /* @__PURE__ */ new Date());
105
+ let y = {
106
+ y: h.getFullYear(),
107
+ d: h.getDate(),
108
+ m: h.getMonth() + 1
103
109
  }, b = {
104
110
  y: v.getFullYear(),
105
111
  d: v.getDate(),
@@ -144,7 +150,7 @@ var m = ({ date: e, onValue: t, position: n, max: r, min: l, className: p, onOpe
144
150
  m: x.m
145
151
  }), w("days"));
146
152
  }, B = (e) => {
147
- t(x.y + "-" + g(2, x.m) + "-" + g(2, e)), M();
153
+ t(x.y + "-" + _(2, x.m) + "-" + _(2, e)), M();
148
154
  }, V = (e, t) => {
149
155
  t = e > 12 ? t + 1 : e < 1 ? t - 1 : t, e = e > 12 ? 1 : e < 1 ? 12 : e, S({
150
156
  y: t,
@@ -185,7 +191,7 @@ var m = ({ date: e, onValue: t, position: n, max: r, min: l, className: p, onOpe
185
191
  e.stopPropagation(), w(C === "years" ? "months" : C === "months" ? "days" : "months");
186
192
  },
187
193
  title: C === "years" ? "К списку месяцев" : C === "months" ? "К календарю" : "Выбрать месяц",
188
- children: h(x.m).name
194
+ children: g(x.m).name
189
195
  }), /* @__PURE__ */ s("span", {
190
196
  className: i.dateHeaderYear,
191
197
  onClick: (e) => {
@@ -230,7 +236,7 @@ var m = ({ date: e, onValue: t, position: n, max: r, min: l, className: p, onOpe
230
236
  ...o,
231
237
  ...c,
232
238
  onClick: () => a && R(n),
233
- children: h(n).abc
239
+ children: g(n).abc
234
240
  }, n);
235
241
  })
236
242
  }),
@@ -249,9 +255,15 @@ var m = ({ date: e, onValue: t, position: n, max: r, min: l, className: p, onOpe
249
255
  })
250
256
  ]
251
257
  })] });
258
+ }, h = {
259
+ val: "01",
260
+ name: "—",
261
+ names: "—",
262
+ abc: "—"
252
263
  };
253
- function h(e) {
254
- return e = typeof e == "number" ? e : new Date(e).getMonth() + 1, {
264
+ function g(e) {
265
+ let t = typeof e == "number" ? e : new Date(e).getMonth() + 1;
266
+ return (!Number.isFinite(t) || t < 1 || t > 12) && (t = (/* @__PURE__ */ new Date()).getMonth() + 1), {
255
267
  1: {
256
268
  val: "01",
257
269
  name: "Январь",
@@ -324,14 +336,14 @@ function h(e) {
324
336
  names: "Декабря",
325
337
  abc: "Дек"
326
338
  }
327
- }[e];
339
+ }[t] ?? h;
328
340
  }
329
- function g(e, t) {
341
+ function _(e, t) {
330
342
  let n = t + "";
331
343
  for (; n.length < e;) n = "0" + n;
332
344
  return n;
333
345
  }
334
- function _(e, t) {
346
+ function v(e, t) {
335
347
  let n, r;
336
348
  t === void 0 ? (r = String(e), n = /* @__PURE__ */ new Date()) : (r = t, n = new Date(e));
337
349
  let i = r, a = {
@@ -7,45 +7,53 @@ import o from "react";
7
7
  import { jsx as s, jsxs as c } from "react/jsx-runtime";
8
8
  //#region src/lib/fields/Input.tsx
9
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(() => {
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), P = o.useRef(null), F = o.useRef(!1);
11
+ o.useLayoutEffect(() => {
12
+ if (T || F.current) return;
13
+ let e = P.current;
14
+ e && e.textContent !== M && (e.textContent = M);
15
+ }, [
16
+ T,
17
+ M,
18
+ A
19
+ ]), o.useEffect(() => {
12
20
  if (!T) return;
13
21
  let e = N.current;
14
22
  e && e.value !== M && (e.value = M);
15
23
  }, [T, M]);
16
- let P = (e) => {
24
+ let I = (e) => {
17
25
  let t = {
18
26
  value: (e.target.textContent || "").trim(),
19
27
  name: f
20
28
  };
21
29
  u && f && u.onValue(t), d && d !== u?.onValue && d(t);
22
- }, F = (e) => {
30
+ }, L = (e) => {
23
31
  let t = {
24
32
  value: e.target.value,
25
33
  name: f
26
34
  };
27
35
  u && f && u.onValue(t), d && d !== u?.onValue && d(t);
28
- }, I = (e) => {
36
+ }, R = (e) => {
29
37
  let t = e.target;
30
38
  C && (t.textContent || "").trim().length >= C && e.key !== "Backspace" && e.preventDefault(), e.key === "Enter" && e.preventDefault();
31
- }, L = (e) => {
39
+ }, z = (e) => {
32
40
  e.key === "Enter" && e.preventDefault();
33
- }, R = (e) => r.Paste(C || 0, i(e));
41
+ }, B = (e) => r.Paste(C || 0, i(e));
34
42
  if (h && a(k)) return "";
35
- let z = (e) => {
43
+ let V = (e) => {
36
44
  r.Blur(e), _?.({
37
45
  value: (e.target.textContent || "").trim(),
38
46
  name: f
39
47
  });
40
- }, B = (e) => {
48
+ }, H = (e) => {
41
49
  _?.({
42
50
  value: (e.target.value || "").trim(),
43
51
  name: f
44
52
  });
45
- }, V = (e) => {
46
- r.Focus({ target: e.currentTarget });
47
- }, H = {};
48
- return p && (H.placeholder = p), j && (H.edit = ""), T ? /* @__PURE__ */ c(t, {
53
+ }, U = (e) => {
54
+ F.current = !0, r.Focus({ target: e.currentTarget });
55
+ }, W = {};
56
+ return p && (W.placeholder = p), j && (W.edit = ""), T ? /* @__PURE__ */ c(t, {
49
57
  type: "input",
50
58
  label: m,
51
59
  error: x,
@@ -79,9 +87,9 @@ function l({ value: l, form: u, onValue: d, name: f = "", placeholder: p = "", l
79
87
  "aria-label": m || p || "Текст",
80
88
  "aria-disabled": g || !j ? !0 : void 0,
81
89
  tabIndex: g ? -1 : 0,
82
- onChange: F,
83
- onBlur: B,
84
- onKeyDown: L,
90
+ onChange: L,
91
+ onBlur: H,
92
+ onKeyDown: z,
85
93
  style: {
86
94
  width: "100%",
87
95
  border: "none",
@@ -106,19 +114,19 @@ function l({ value: l, form: u, onValue: d, name: f = "", placeholder: p = "", l
106
114
  children: [
107
115
  b,
108
116
  /* @__PURE__ */ s("div", {
117
+ ref: P,
109
118
  id: O,
110
- onBlur: z,
111
- onFocus: V,
112
- onPaste: R,
113
- onInput: P,
114
- onKeyDown: I,
119
+ onBlur: V,
120
+ onFocus: U,
121
+ onPaste: B,
122
+ onInput: I,
123
+ onKeyDown: R,
115
124
  spellCheck: w,
116
125
  inputMode: S || "text",
117
126
  contentEditable: j ? "plaintext-only" : !1,
118
127
  suppressContentEditableWarning: !0,
119
- ...H,
120
- children: typeof k == "string" || typeof k == "number" ? String(k) : ""
121
- }, A),
128
+ ...W
129
+ }),
122
130
  y
123
131
  ]
124
132
  });
@@ -3,10 +3,10 @@ import t from "../core/Field.js";
3
3
  import { useFormFieldState as n } from "../hooks/use.js";
4
4
  import r, { asEditableClipboard as i } from "../events/onEvent.js";
5
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";
6
+ import o from "react";
7
+ import { Fragment as s, jsx as c, jsxs as l } from "react/jsx-runtime";
8
8
  //#region src/lib/fields/Mask.tsx
9
- function l(e) {
9
+ function u(e) {
10
10
  let t = window.getSelection();
11
11
  if (!t || t.rangeCount === 0) return 0;
12
12
  let n = t.getRangeAt(0);
@@ -14,88 +14,100 @@ function l(e) {
14
14
  let r = document.createRange();
15
15
  return r.selectNodeContents(e), r.setEnd(n.startContainer, n.startOffset), r.toString().length;
16
16
  }
17
- function u(e, t) {
17
+ function d(e, t) {
18
18
  if (t <= 0) return 0;
19
19
  let n = 0;
20
20
  for (let r = 0; r < e.length; r++) if (/\d/.test(e[r]) && (n++, n === t)) return r + 1;
21
21
  return e.length;
22
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) => {
23
+ function f({ value: f = "", form: p, onValue: m, onBlur: h, name: g = "", format: _ = "+_(___) ___-__-__", placeholder: v = "", label: y = "", error: b = "", hidden: x = !1, disabled: S = !1, className: C = "", after: w = "", before: T = "", inputmode: E = "numeric", view: D }) {
24
+ let O = !S, { value: k, version: A } = n(p, g, f), j = o.useRef(null), M = o.useRef(!1), N = _, P = !0, F = 0, I = (e, t) => {
25
25
  let n = t.firstChild;
26
26
  if (!n || n.nodeType !== Node.TEXT_NODE) return;
27
27
  let r = n.textContent?.length ?? 0, i = Math.max(0, Math.min(e, r)), a = document.createRange(), o = window.getSelection();
28
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;
29
+ }, L = (e) => r.PasteOne(i(e)), R = (e) => {
30
+ N = _, P = !0, F = 0;
31
31
  let t = 0, n = "", r = e.replace(/\D/g, "");
32
- r === "" && (j = !0);
32
+ r === "" && (P = !0);
33
33
  let i = r.split(""), a = "";
34
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 = ""));
35
+ P && (a += e, P && (F = ("" + a).length, N = _.replace(/* @__PURE__ */ RegExp("[0-9]", "g"), "_"), n = ""), F > ("" + a).length && (P = !0, N = _.replace(/* @__PURE__ */ RegExp("[0-9]", "g"), "_"), n = ""));
36
36
  });
37
- let o = A.replace(/\D/g, "");
37
+ let o = N.replace(/\D/g, "");
38
38
  return o.length >= r.length && (r = o), {
39
- q: A.replace(/[_\d]/g, function() {
39
+ q: N.replace(/[_\d]/g, function() {
40
40
  return r.charAt(t++) || "_";
41
41
  }),
42
42
  i: t,
43
43
  v: r,
44
44
  f: n
45
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);
46
+ };
47
+ o.useLayoutEffect(() => {
48
+ if (M.current) return;
49
+ let e = j.current;
50
+ if (!e) return;
51
+ let t = R(String(k || ""));
52
+ e.textContent !== t.q && (e.textContent = t.q);
53
+ }, [
54
+ k,
55
+ A,
56
+ _
57
+ ]), R(String(k || ""));
58
+ let z = (e) => {
59
+ let t = e.target, n = t.textContent || "", r = u(t), i = n.slice(0, r).replace(/\D/g, "").length, a = R(n);
48
60
  t.textContent = a.q;
49
- let o = u(a.q, i);
61
+ let o = d(a.q, i);
50
62
  a.q.length > 0 && queueMicrotask(() => {
51
- N(Math.min(o, a.q.length), t);
63
+ I(Math.min(o, a.q.length), t);
52
64
  });
53
65
  let s = {
54
66
  value: a.q.replace(/\D/g, ""),
55
- name: h
67
+ name: g
56
68
  };
57
- f && h && f.onValue(s), p && p !== f?.onValue && p(s);
58
- }, R = (e) => {
69
+ p && g && p.onValue(s), m && m !== p?.onValue && m(s);
70
+ }, B = (e) => {
59
71
  e.key === "Enter" && e.preventDefault();
60
- }, z = (e) => {
61
- r.Blur(e), m && m({
72
+ }, V = (e) => {
73
+ r.Blur(e), h && h({
62
74
  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, {
75
+ name: g
76
+ }), M.current = !1;
77
+ }, H = (e) => {
78
+ M.current = !0, r.Focus({ target: e.currentTarget });
79
+ }, U = {};
80
+ v && (U.placeholder = v), U.inputMode = E ?? "numeric";
81
+ let W = String(k ?? "").replace(/\D/g, "");
82
+ return x && a(W) ? /* @__PURE__ */ c(s, {}) : /* @__PURE__ */ l(t, {
71
83
  type: "input",
72
- label: v,
73
- error: y,
74
- element_blok: { className: [S] },
84
+ label: y,
85
+ error: b,
86
+ element_blok: { className: [C] },
75
87
  element_input: { className: [e.w] },
76
88
  children: [
77
- w,
78
- /* @__PURE__ */ s("div", {
79
- onPaste: P,
80
- onInput: L,
81
- onKeyDown: R,
82
- onBlur: z,
83
- onFocus: B,
89
+ T,
90
+ /* @__PURE__ */ c("div", {
91
+ ref: j,
92
+ onPaste: L,
93
+ onInput: z,
94
+ onKeyDown: B,
95
+ onBlur: V,
96
+ onFocus: H,
84
97
  role: "textbox",
85
98
  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,
99
+ "aria-label": y || v || g || "Маска",
100
+ "aria-disabled": !O,
101
+ tabIndex: S ? -1 : 0,
102
+ "data-disabled": !O,
103
+ contentEditable: O ? "plaintext-only" : !1,
91
104
  suppressContentEditableWarning: !0,
92
- ...V,
93
- children: I.q
94
- }, k),
95
- C
105
+ ...U
106
+ }),
107
+ w
96
108
  ]
97
109
  });
98
110
  }
99
- d.displayName = "MaskField";
111
+ f.displayName = "MaskField";
100
112
  //#endregion
101
- export { d as default };
113
+ export { f as default };