@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.
@@ -3,10 +3,10 @@ import t from "../core/Field.js";
3
3
  import { useFormFieldState as n } from "../hooks/use.js";
4
4
  import r, { pastePlainTextIntoSelection as i } from "../events/onEvent.js";
5
5
  import { isEmptyTextLike as a } from "./visibility.js";
6
- import "react";
7
- import { jsx as o, jsxs as s } from "react/jsx-runtime";
6
+ import o from "react";
7
+ import { jsx as s, jsxs as c } from "react/jsx-runtime";
8
8
  //#region src/lib/fields/Money.tsx
9
- function c(e) {
9
+ function l(e) {
10
10
  let t = window.getSelection();
11
11
  if (!t || t.rangeCount === 0) return 0;
12
12
  let n = t.getRangeAt(0);
@@ -14,87 +14,100 @@ function c(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 l(e, t, n) {
17
+ function u(e, t, n) {
18
18
  let r = Math.max(0, Math.min(t, e.length));
19
19
  return n(e.slice(0, r)).length;
20
20
  }
21
- function u({ value: u, form: f, onValue: p, name: m = "", placeholder: h = "", label: g = "", error: _ = "", hidden: v = !1, disabled: y = !1, onBlur: b, className: x = "", after: S = "", before: C = "", inputmode: w = "decimal", course: T = 100, view: E, type: D, isClear: O = !1 }) {
22
- let { value: k, version: A } = n(f, m || "", u), j = f && m ? k : u, M = (e) => D === "multi" ? e.replace(/[^+\d.+-]/g, "") : e.replace(/[^+\d.]/g, ""), N = (e, t) => {
21
+ function d({ value: d, form: p, onValue: m, name: h = "", placeholder: g = "", label: _ = "", error: v = "", hidden: y = !1, disabled: b = !1, onBlur: x, className: S = "", after: C = "", before: w = "", inputmode: T = "decimal", course: E = 100, view: D, type: O, isClear: k = !1 }) {
22
+ let { value: A, version: j } = n(p, h || "", d), M = p && h ? A : d, N = o.useRef(null), P = o.useRef(!1);
23
+ o.useLayoutEffect(() => {
24
+ if (P.current) return;
25
+ let e = N.current;
26
+ if (!e) return;
27
+ let t = !g || M ? f(M ?? "") : "";
28
+ e.textContent !== t && (e.textContent = t);
29
+ }, [
30
+ M,
31
+ j,
32
+ g
33
+ ]);
34
+ let F = (e) => O === "multi" ? e.replace(/[^+\d.+-]/g, "") : e.replace(/[^+\d.]/g, ""), I = (e, t) => {
23
35
  let n = t.firstChild;
24
36
  if (!n || n.nodeType !== Node.TEXT_NODE) return;
25
37
  let r = n.textContent?.length ?? 0, i = Math.max(0, Math.min(e, r)), a = document.createRange(), o = window.getSelection();
26
38
  o && (a.setStart(n, i), a.collapse(!0), o.removeAllRanges(), o.addRange(a), t.focus());
27
- }, P = (e) => {
28
- let t = e.target, n = t.textContent || "", r = c(t), i = M(n), a = l(n, r, M), o = {
29
- value: Number(i || 0) * T,
30
- name: m
39
+ }, L = (e) => {
40
+ let t = e.target, n = t.textContent || "", r = l(t), i = F(n), a = u(n, r, F), o = {
41
+ value: Number(i || 0) * E,
42
+ name: h
31
43
  };
32
- f && m && f.onValue(o), p && p !== f?.onValue && p(o), t.textContent = i, i.length > 0 && queueMicrotask(() => {
33
- N(Math.min(a, i.length), t);
44
+ p && h && p.onValue(o), m && m !== p?.onValue && m(o), t.textContent = i, i.length > 0 && queueMicrotask(() => {
45
+ I(Math.min(a, i.length), t);
34
46
  });
35
- }, F = (e) => {
47
+ }, R = (e) => {
36
48
  let t = e.target;
37
49
  r.Blur(e), (t.textContent || "") === "" && (t.textContent = "0");
38
50
  let n = {
39
- value: Number(M(t.textContent || "")) * T,
40
- name: m
51
+ value: Number(F(t.textContent || "")) * E,
52
+ name: h
41
53
  };
42
- b?.(n), f && m && f.setValue(n), p && p !== f?.onValue && p(n), t.textContent = d(t.textContent || "");
43
- }, I = (e) => {
54
+ x?.(n), p && h && p.setValue(n), m && m !== p?.onValue && m(n), t.textContent = f(t.textContent || ""), P.current = !1;
55
+ }, z = (e) => {
56
+ P.current = !0;
44
57
  let t = e.target;
45
- t.textContent = M(t.textContent || ""), r.Focus({ target: e.currentTarget });
46
- }, L = (e) => {
58
+ t.textContent = F(t.textContent || ""), r.Focus({ target: e.currentTarget });
59
+ }, B = (e) => {
47
60
  let t = e.currentTarget.previousElementSibling;
48
61
  t && (t.textContent = "");
49
62
  let n = {
50
63
  value: 0,
51
- name: m
64
+ name: h
52
65
  };
53
- f && m && f.setValue(n), p && p !== f?.onValue && p(n);
54
- }, R = (e) => {
66
+ p && h && p.setValue(n), m && m !== p?.onValue && m(n);
67
+ }, V = (e) => {
55
68
  e.key === "Enter" && e.preventDefault();
56
- }, z = (e) => {
57
- e.preventDefault(), i(M(e.clipboardData?.getData("text/plain") ?? ""), e.currentTarget);
58
- }, B = !y, V = j == null || (typeof j == "number" ? !1 : a(String(j ?? "")));
59
- if (v && V) return "";
60
- let H = {};
61
- return H.inputMode = w ?? "decimal", h && (H.placeholder = h), B && (H.edit = ""), /* @__PURE__ */ s(t, {
69
+ }, H = (e) => {
70
+ e.preventDefault(), i(F(e.clipboardData?.getData("text/plain") ?? ""), e.currentTarget);
71
+ }, U = !b, W = M == null || (typeof M == "number" ? !1 : a(String(M ?? "")));
72
+ if (y && W) return "";
73
+ let G = {};
74
+ return G.inputMode = T ?? "decimal", g && (G.placeholder = g), U && (G.edit = ""), /* @__PURE__ */ c(t, {
62
75
  type: "input",
63
- label: g,
64
- error: _,
65
- element_blok: { className: [x] },
76
+ label: _,
77
+ error: v,
78
+ element_blok: { className: [S] },
66
79
  element_input: { className: [e.w] },
67
80
  children: [
68
- C,
69
- /* @__PURE__ */ o("div", {
70
- ...H,
71
- onInput: P,
72
- onPaste: z,
73
- onBlur: F,
74
- onKeyDown: R,
75
- onFocus: I,
81
+ w,
82
+ /* @__PURE__ */ s("div", {
83
+ ref: N,
84
+ ...G,
85
+ onInput: L,
86
+ onPaste: H,
87
+ onBlur: R,
88
+ onKeyDown: V,
89
+ onFocus: z,
76
90
  role: "textbox",
77
91
  spellCheck: !1,
78
- "aria-label": g || h || "Сумма",
79
- "aria-disabled": !B,
80
- tabIndex: y ? -1 : 0,
81
- contentEditable: B ? "plaintext-only" : !1,
82
- suppressContentEditableWarning: !0,
83
- children: !h || j ? d(j ?? "") : ""
84
- }, A),
85
- O && /* @__PURE__ */ o("button", {
92
+ "aria-label": _ || g || "Сумма",
93
+ "aria-disabled": !U,
94
+ tabIndex: b ? -1 : 0,
95
+ contentEditable: U ? "plaintext-only" : !1,
96
+ suppressContentEditableWarning: !0
97
+ }),
98
+ k && /* @__PURE__ */ s("button", {
86
99
  type: "button",
87
- onClick: L,
100
+ onClick: B,
88
101
  "aria-label": "Очистить поле",
89
102
  children: "x"
90
103
  }),
91
- S
104
+ C
92
105
  ]
93
106
  });
94
107
  }
95
- u.displayName = "MoneyField";
96
- function d(e, t) {
108
+ d.displayName = "MoneyField";
109
+ function f(e, t) {
97
110
  return t && (e = Number(e) / t), parseFloat(String(e || 0)).toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, "$1 ");
98
111
  }
99
112
  //#endregion
100
- export { u as default };
113
+ export { d as default };
@@ -3,15 +3,21 @@ 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/Numeric.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 = "numeric", maxLength: C, max: w, view: T }) {
10
- let E = !g, { value: D, version: O } = n(u, f, l);
11
- p = p === void 0 ? "" : p, w = w === void 0 ? 99 : w;
12
- let k = C ?? w, A = !1, j = (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 = "numeric", maxLength: w, max: T, view: E }) {
10
+ let D = !_, { value: O, version: k } = n(d, p, u);
11
+ m = m === void 0 ? "" : m, T = T === void 0 ? 99 : T;
12
+ let A = O != null && O !== "" ? String(O) : "", j = o.useRef(null), M = o.useRef(!1);
13
+ o.useLayoutEffect(() => {
14
+ if (M.current) return;
15
+ let e = j.current;
16
+ e && e.textContent !== A && (e.textContent = A);
17
+ }, [A, k]);
18
+ let N = w ?? T, P = !1, F = (e) => {
13
19
  let t = e.currentTarget, n = (t.textContent || "").replace(/\D/g, "");
14
- n.length > k && (n = n.slice(0, k), t.textContent = n, queueMicrotask(() => {
20
+ n.length > N && (n = n.slice(0, N), t.textContent = n, queueMicrotask(() => {
15
21
  let e = t.firstChild;
16
22
  if (e && e.nodeType === Node.TEXT_NODE) {
17
23
  let t = n.length, r = window.getSelection(), i = document.createRange();
@@ -20,54 +26,55 @@ function l({ value: l, form: u, onValue: d, name: f = "", placeholder: p = "", l
20
26
  }));
21
27
  let r = {
22
28
  value: n,
23
- name: f
29
+ name: p
24
30
  };
25
- u && f && u.onValue(r), d && d !== u?.onValue && d(r);
26
- }, M = (e) => {
31
+ d && p && d.onValue(r), f && f !== d?.onValue && f(r);
32
+ }, I = (e) => {
33
+ M.current = !0;
27
34
  let t = e.currentTarget;
28
35
  t.textContent = (t.textContent || "").replace(/\D/g, ""), r.Focus({ target: e.currentTarget });
29
- }, N = (e) => {
30
- if (A && e.which === 86) return;
31
- if (e.which === 17 || e.which === 91) return A = !0;
36
+ }, L = (e) => {
37
+ if (P && e.which === 86) return;
38
+ if (e.which === 17 || e.which === 91) return P = !0;
32
39
  if (e.key === "Backspace") return;
33
40
  let t = (e.currentTarget.textContent ?? "").replace(/\D/g, "").length;
34
- k > 0 && t >= k && e.key.length === 1 && /\d/.test(e.key) && e.preventDefault(), e.key === "Enter" && e.preventDefault(), e.key.length === 1 && !/\d/.test(e.key) && e.preventDefault();
35
- }, P = (e) => {
36
- if (e.which === 17 || e.which === 91) return A = !1;
37
- }, F = (e) => r.PasteDigits(k, i(e)), I = (e) => {
38
- r.Blur(e), _?.({
41
+ N > 0 && t >= N && e.key.length === 1 && /\d/.test(e.key) && e.preventDefault(), e.key === "Enter" && e.preventDefault(), e.key.length === 1 && !/\d/.test(e.key) && e.preventDefault();
42
+ }, R = (e) => {
43
+ if (e.which === 17 || e.which === 91) return P = !1;
44
+ }, z = (e) => r.PasteDigits(N, i(e)), B = (e) => {
45
+ r.Blur(e), v?.({
39
46
  value: e.currentTarget.textContent,
40
- name: f
41
- });
42
- }, L = {};
43
- return E && (L.edit = ""), L.inputMode = S ?? "numeric", p && (L.placeholder = p), h && a(D) ? /* @__PURE__ */ s(o, {}) : /* @__PURE__ */ c(t, {
47
+ name: p
48
+ }), M.current = !1;
49
+ }, V = {};
50
+ return D && (V.edit = ""), V.inputMode = C ?? "numeric", m && (V.placeholder = m), g && a(O) ? /* @__PURE__ */ c(s, {}) : /* @__PURE__ */ l(t, {
44
51
  type: "numeric",
45
- label: m,
46
- error: x,
47
- element_blok: { className: [v || ""] },
52
+ label: h,
53
+ error: S,
54
+ element_blok: { className: [y || ""] },
48
55
  element_input: { className: [e.w] },
49
56
  children: [
50
- b,
51
- /* @__PURE__ */ s("div", {
52
- onPaste: F,
53
- onInput: j,
54
- onFocus: M,
55
- onBlur: I,
56
- onKeyDown: N,
57
- onKeyUp: P,
57
+ x,
58
+ /* @__PURE__ */ c("div", {
59
+ ref: j,
60
+ onPaste: z,
61
+ onInput: F,
62
+ onFocus: I,
63
+ onBlur: B,
64
+ onKeyDown: L,
65
+ onKeyUp: R,
58
66
  spellCheck: !1,
59
67
  role: "textbox",
60
- tabIndex: E ? 0 : -1,
61
- "aria-label": m || p || "Число",
62
- contentEditable: E ? "plaintext-only" : !1,
68
+ tabIndex: D ? 0 : -1,
69
+ "aria-label": h || m || "Число",
70
+ contentEditable: D ? "plaintext-only" : !1,
63
71
  suppressContentEditableWarning: !0,
64
- ...L,
65
- children: D
66
- }, O),
67
- y
72
+ ...V
73
+ }),
74
+ b
68
75
  ]
69
76
  });
70
77
  }
71
- l.displayName = "NumberField";
78
+ u.displayName = "NumberField";
72
79
  //#endregion
73
- export { l as default };
80
+ export { u as default };
@@ -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
  }
package/dist/index.js CHANGED
@@ -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 "./package.js";
3
13
  import { useForm as t, useFormField as n, useFormFieldState as r } from "./hooks/use.js";
4
14
  import i from "./fields/Range.js";