@elcrm/form 0.0.69 → 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.
@@ -5,10 +5,10 @@ import r, { asEditableClipboard as i } from "../events/onEvent.js";
5
5
  import { isEmptyTextLike as a } from "./visibility.js";
6
6
  import o from "../mask/MaskPhone.js";
7
7
  import { useFormInit as s } from "../FormInitContext.js";
8
- import "react";
9
- import { Fragment as c, jsx as l, jsxs as u } from "react/jsx-runtime";
8
+ import c from "react";
9
+ import { Fragment as l, jsx as u, jsxs as d } from "react/jsx-runtime";
10
10
  //#region src/lib/fields/Phone.tsx
11
- function d(e) {
11
+ function f(e) {
12
12
  let t = window.getSelection();
13
13
  if (!t || t.rangeCount === 0) return 0;
14
14
  let n = t.getRangeAt(0);
@@ -16,97 +16,107 @@ function d(e) {
16
16
  let r = document.createRange();
17
17
  return r.selectNodeContents(e), r.setEnd(n.startContainer, n.startOffset), r.toString().length;
18
18
  }
19
- function f(e, t) {
19
+ function p(e, t) {
20
20
  if (t <= 0) return 0;
21
21
  let n = 0;
22
22
  for (let r = 0; r < e.length; r++) if (/\d/.test(e[r]) && (n++, n === t)) return r + 1;
23
23
  return e.length;
24
24
  }
25
- function p({ value: p, form: m, onValue: h, onBlur: g, name: _ = "", placeholder: v = "", label: y = "", error: b = "", hidden: x = !1, disabled: S = !1, className: C = "", after: w = "", before: T = "", inputmode: E = "tel", view: D }) {
26
- let { onNotice: O } = s(), k = !S, { value: A, version: j } = n(m, _, p), M = "+_(___) ___-__-__", N = !0, P = 0, F = (e, t) => {
25
+ function m({ value: m, form: h, onValue: g, onBlur: _, name: v = "", placeholder: y = "", label: b = "", error: x = "", hidden: S = !1, disabled: C = !1, className: w = "", after: T = "", before: E = "", inputmode: D = "tel", view: O }) {
26
+ let { onNotice: k } = s(), A = !C, { value: j, version: M } = n(h, v, m), N = c.useRef(null), P = c.useRef(!1), F = "+_(___) ___-__-__", I = !0, L = 0, R = (e, t) => {
27
27
  let n = t.firstChild;
28
28
  if (!n || n.nodeType !== Node.TEXT_NODE) return;
29
29
  let r = n.textContent?.length ?? 0, i = Math.max(0, Math.min(e, r)), a = document.createRange(), o = window.getSelection();
30
30
  o && (a.setStart(n, i), a.collapse(!0), o.removeAllRanges(), o.addRange(a), t.focus());
31
- }, I = (e) => {
32
- let t = e.target, n = t.textContent || "", r = d(t), i = n.slice(0, r).replace(/\D/g, "").length, a = R(n);
31
+ }, z = (e) => {
32
+ let t = e.target, n = t.textContent || "", r = f(t), i = n.slice(0, r).replace(/\D/g, "").length, a = V(n);
33
33
  t.textContent = a.q;
34
- let o = f(a.q, i);
34
+ let o = p(a.q, i);
35
35
  a.q.length > 0 && queueMicrotask(() => {
36
- F(Math.min(o, a.q.length), t);
36
+ R(Math.min(o, a.q.length), t);
37
37
  });
38
38
  let s = {
39
39
  value: a.q.replace(/\D/g, ""),
40
- name: _ || ""
40
+ name: v || ""
41
41
  };
42
- m && _ && m.onValue(s), h && h !== m?.onValue && h(s);
43
- }, L = (e) => r.PasteOne(i(e)), R = (e) => {
44
- M = "+_(___) ___-__-__", N = !0, P = 0;
42
+ h && v && h.onValue(s), g && g !== h?.onValue && g(s);
43
+ }, B = (e) => r.PasteOne(i(e)), V = (e) => {
44
+ F = "+_(___) ___-__-__", I = !0, L = 0;
45
45
  let t = 0, n = "", r = e.replace(/\D/g, "");
46
- r === "" && (N = !0);
46
+ r === "" && (I = !0);
47
47
  let i = r.split(""), a = "";
48
48
  i.forEach((e) => {
49
- N && (a += e, o[a] !== void 0 && N ? (N = !1, M = o[a].mask.replace(/* @__PURE__ */ RegExp("[0-9]", "g"), "_"), n = o[a].code) : (N && (P = ("" + a).length, M = `+${a}_(___) ___-__-__`.replace(/* @__PURE__ */ RegExp("[0-9]", "g"), "_"), n = ""), P > ("" + a).length && (N = !0, M = `+${a}_(___) ___-__-__`.replace(/* @__PURE__ */ RegExp("[0-9]", "g"), "_"), n = "")));
49
+ I && (a += e, o[a] !== void 0 && I ? (I = !1, F = o[a].mask.replace(/* @__PURE__ */ RegExp("[0-9]", "g"), "_"), n = o[a].code) : (I && (L = ("" + a).length, F = `+${a}_(___) ___-__-__`.replace(/* @__PURE__ */ RegExp("[0-9]", "g"), "_"), n = ""), L > ("" + a).length && (I = !0, F = `+${a}_(___) ___-__-__`.replace(/* @__PURE__ */ RegExp("[0-9]", "g"), "_"), n = "")));
50
50
  });
51
- let s = M.replace(/\D/g, "");
51
+ let s = F.replace(/\D/g, "");
52
52
  return s.length >= r.length && (r = s), {
53
- q: M.replace(/[_\d]/g, function() {
53
+ q: F.replace(/[_\d]/g, function() {
54
54
  return r.charAt(t++) || "_";
55
55
  }),
56
56
  i: t,
57
57
  v: r,
58
58
  f: n
59
59
  };
60
- }, z = (e) => {
60
+ };
61
+ c.useLayoutEffect(() => {
62
+ if (P.current) return;
63
+ let e = N.current;
64
+ if (!e) return;
65
+ let t = V(String(j || ""));
66
+ e.textContent !== t.q && (e.textContent = t.q);
67
+ }, [j, M]);
68
+ let H = (e) => {
61
69
  e.preventDefault();
62
70
  let t = e.target;
63
71
  navigator.clipboard.writeText((t.textContent || "").replace(/\D/g, "")).then(function() {
64
- O("Данные в буфер обмене");
72
+ k("Данные в буфер обмене");
65
73
  }, function(e) {
66
74
  console.error("Async: Could not copy text: ", e);
67
75
  });
68
- }, B = R(String(A || "")), V = (e) => {
76
+ };
77
+ V(String(j || ""));
78
+ let U = (e) => {
69
79
  e.key === "Enter" && e.preventDefault();
70
- }, H = (e) => {
71
- r.Blur(e), g && g({
80
+ }, W = (e) => {
81
+ r.Blur(e), _ && _({
72
82
  value: (e.target.textContent || "").replace(/\D/g, ""),
73
- name: _ || ""
74
- });
75
- }, U = (e) => {
76
- r.Focus({ target: e.currentTarget });
77
- }, W = {};
78
- v && (W.placeholder = v), W.inputMode = E ?? "tel";
79
- let G = String(A ?? "").replace(/\D/g, "");
80
- return x && a(G) ? /* @__PURE__ */ l(c, {}) : /* @__PURE__ */ u(t, {
83
+ name: v || ""
84
+ }), P.current = !1;
85
+ }, G = (e) => {
86
+ P.current = !0, r.Focus({ target: e.currentTarget });
87
+ }, K = {};
88
+ y && (K.placeholder = y), K.inputMode = D ?? "tel";
89
+ let q = String(j ?? "").replace(/\D/g, "");
90
+ return S && a(q) ? /* @__PURE__ */ u(l, {}) : /* @__PURE__ */ d(t, {
81
91
  type: "input",
82
- label: y,
83
- error: b,
84
- element_blok: { className: [C] },
92
+ label: b,
93
+ error: x,
94
+ element_blok: { className: [w] },
85
95
  element_input: { className: [e.w] },
86
96
  children: [
87
- T,
88
- /* @__PURE__ */ l("div", {
89
- onPaste: L,
90
- onInput: I,
91
- onKeyDown: V,
92
- onContextMenu: z,
93
- onBlur: H,
94
- onFocus: U,
97
+ E,
98
+ /* @__PURE__ */ u("div", {
99
+ ref: N,
100
+ onPaste: B,
101
+ onInput: z,
102
+ onKeyDown: U,
103
+ onContextMenu: H,
104
+ onBlur: W,
105
+ onFocus: G,
95
106
  spellCheck: !1,
96
107
  role: "textbox",
97
- "aria-label": y || v || "Телефон",
98
- "aria-disabled": !k,
99
- tabIndex: S ? -1 : 0,
100
- "data-disabled": !k,
101
- contentEditable: k ? "plaintext-only" : !1,
108
+ "aria-label": b || y || "Телефон",
109
+ "aria-disabled": !A,
110
+ tabIndex: C ? -1 : 0,
111
+ "data-disabled": !A,
112
+ contentEditable: A ? "plaintext-only" : !1,
102
113
  suppressContentEditableWarning: !0,
103
- ...W,
104
- children: B.q
105
- }, j),
106
- w
114
+ ...K
115
+ }),
116
+ T
107
117
  ]
108
118
  });
109
119
  }
110
- p.displayName = "PhoneField";
120
+ m.displayName = "PhoneField";
111
121
  //#endregion
112
- export { p as default };
122
+ export { m as default };
@@ -3,50 +3,59 @@ 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/Textarea.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 }) {
10
- let { value: T, version: E } = n(u, f || "", l), D = !g, O = (e) => {
9
+ function u({ value: u, form: d, onValue: f, name: p = "", placeholder: m = "", label: h = "", hidden: g = !1, disabled: _ = !1, onBlur: v, className: y = "", after: b = "", before: x = "", error: S = "", inputmode: C = "text", maxLength: w, spellCheck: T = !0 }) {
10
+ let { value: E, version: D } = n(d, p || "", u), O = !_, k = String(E ?? ""), A = o.useRef(null), j = o.useRef(!1);
11
+ o.useLayoutEffect(() => {
12
+ if (j.current) return;
13
+ let e = A.current;
14
+ e && e.innerText !== k && (e.innerText = k);
15
+ }, [k, D]);
16
+ let M = (e) => {
11
17
  let t = {
12
18
  value: e.currentTarget.innerText,
13
- name: f || ""
19
+ name: p || ""
14
20
  };
15
- u && f && u.onValue(t), d && d !== u?.onValue && d(t);
16
- }, k = (e) => {
21
+ d && p && d.onValue(t), f && f !== d?.onValue && f(t);
22
+ }, N = (e) => {
17
23
  let t = (e.currentTarget.textContent ?? "").trim();
18
- C && t.length >= C && e.key !== "Backspace" && e.preventDefault(), e.key === "Enter" && !e.shiftKey && e.preventDefault();
19
- }, A = (e) => r.Paste(C || 0, i(e));
20
- if (h && a(T)) return /* @__PURE__ */ s(o, {});
21
- let j = {};
22
- return p && (j.placeholder = p), D && (j.edit = ""), j.inputMode = S || "text", /* @__PURE__ */ c(t, {
24
+ w && t.length >= w && e.key !== "Backspace" && e.preventDefault(), e.key === "Enter" && !e.shiftKey && e.preventDefault();
25
+ }, P = (e) => r.Paste(w || 0, i(e));
26
+ if (g && a(E)) return /* @__PURE__ */ c(s, {});
27
+ let F = {};
28
+ return m && (F.placeholder = m), O && (F.edit = ""), F.inputMode = C || "text", /* @__PURE__ */ l(t, {
23
29
  type: "note",
24
- label: m,
25
- error: x,
26
- element_blok: { className: [v || ""] },
30
+ label: h,
31
+ error: S,
32
+ element_blok: { className: [y || ""] },
27
33
  element_input: { className: [e.n] },
28
34
  children: [
29
- b,
30
- /* @__PURE__ */ s("div", {
31
- onPaste: A,
32
- onInput: O,
35
+ x,
36
+ /* @__PURE__ */ c("div", {
37
+ ref: A,
38
+ onPaste: P,
39
+ onInput: M,
40
+ onFocus: () => {
41
+ j.current = !0;
42
+ },
33
43
  onBlur: (e) => {
34
- r.Blur(e), _?.({
44
+ r.Blur(e), v?.({
35
45
  value: (e.currentTarget.textContent ?? "").trim(),
36
- name: f || ""
37
- });
46
+ name: p || ""
47
+ }), j.current = !1;
38
48
  },
39
- onKeyDown: k,
40
- spellCheck: w,
41
- contentEditable: D ? "plaintext-only" : !1,
49
+ onKeyDown: N,
50
+ spellCheck: T,
51
+ contentEditable: O ? "plaintext-only" : !1,
42
52
  suppressContentEditableWarning: !0,
43
- ...j,
44
- children: T
45
- }, E),
46
- y
53
+ ...F
54
+ }),
55
+ b
47
56
  ]
48
57
  });
49
58
  }
50
- l.displayName = "TextareaField";
59
+ u.displayName = "TextareaField";
51
60
  //#endregion
52
- export { l as default };
61
+ export { u as default };
@@ -82,7 +82,7 @@ function _(e, t, n) {
82
82
  }
83
83
  return p(Math.floor(i / 60), i % 60);
84
84
  }
85
- function v({ value: h = "", form: v, onValue: ee, onBlur: y, name: b = "", placeholder: x = "", label: S = "", hidden: C = !1, disabled: w = !1, error: T = "", className: E = "", after: D = "", before: te = "", step: O = 60, min: k, max: A, id: j, spellCheck: M = !1, align: N = "start" }) {
85
+ function v({ value: h = "", form: v, onValue: ee, onBlur: y, name: b = "", placeholder: x = "", label: S = "", hidden: C = !1, disabled: w = !1, error: T = "", className: E = "", after: te = "", before: D = "", step: O = 60, min: k, max: A, id: j, spellCheck: M = !1, align: N = "start" }) {
86
86
  let { value: P, version: F } = n(v, b, h), I = d(P), L = !w, R = i.useRef(null), z = i.useRef(null), B = i.useRef(null), [V, H] = i.useState(!1);
87
87
  i.useLayoutEffect(() => {
88
88
  if (!V || !L) return;
@@ -198,7 +198,7 @@ function v({ value: h = "", form: v, onValue: ee, onBlur: y, name: b = "", place
198
198
  props: { "data-disabled": w || !L ? "true" : void 0 }
199
199
  },
200
200
  children: [
201
- te,
201
+ D,
202
202
  /* @__PURE__ */ o("div", {
203
203
  ref: B,
204
204
  className: e.timeInner,
@@ -244,8 +244,8 @@ function v({ value: h = "", form: v, onValue: ee, onBlur: y, name: b = "", place
244
244
  children: !L || !V ? Q === null ? "" : l(Q) : null
245
245
  })
246
246
  ]
247
- }, F),
248
- D
247
+ }),
248
+ te
249
249
  ]
250
250
  });
251
251
  }