@elcrm/form 0.0.88 → 0.1.1

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 -171
  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 -5
@@ -1,82 +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 r from "react";
5
- import { jsx as i, jsxs as a } from "react/jsx-runtime";
6
- //#region src/lib/fields/Rating.tsx
7
- function o(e, t) {
8
- return Number.isFinite(e) ? Math.min(t, Math.max(0, Math.round(e))) : 0;
9
- }
10
- function s({ value: s = 0, form: c, onValue: l, onBlur: u, name: d = "", placeholder: f = "", label: p = "", error: m = "", hidden: h = !1, disabled: g = !1, className: _ = "", after: v = "", before: y = "", max: b = 5, allowClear: x = !0 }) {
11
- let { value: S } = n(c, d, s), C = o(Number(S), b), w = !g, [T, E] = r.useState(0), D = (e) => {
12
- let t = {
13
- value: e,
14
- name: d
15
- };
16
- c && d && c.setValue(t), l && l !== c?.onValue && l(t);
17
- };
18
- if (h && !C) return null;
19
- let O = T || C;
20
- return /* @__PURE__ */ a(t, {
21
- type: "rating",
22
- label: p,
23
- error: m,
24
- element_blok: { className: [_ || ""] },
25
- element_input: {
26
- className: [e.rating],
27
- props: { "data-disabled": g || !w ? "true" : void 0 }
28
- },
29
- children: [
30
- y ? /* @__PURE__ */ i("span", {
31
- className: e.affix,
32
- children: y
33
- }) : null,
34
- /* @__PURE__ */ i("div", {
35
- role: "slider",
36
- "aria-label": p || f || "Оценка",
37
- "aria-valuemin": 0,
38
- "aria-valuemax": b,
39
- "aria-valuenow": C,
40
- tabIndex: w ? 0 : -1,
41
- onMouseLeave: () => E(0),
42
- onBlur: () => {
43
- E(0), u?.({
44
- value: C,
45
- name: d
46
- });
47
- },
48
- onKeyDown: (e) => {
49
- if (!w) return;
50
- let t = C;
51
- if (e.key === "ArrowRight" || e.key === "ArrowUp") t = Math.min(b, C + 1);
52
- else if (e.key === "ArrowLeft" || e.key === "ArrowDown") t = Math.max(0, C - 1);
53
- else if (e.key === "Home") t = 0;
54
- else if (e.key === "End") t = b;
55
- else return;
56
- e.preventDefault(), D(t);
57
- },
58
- children: Array.from({ length: b }, (t, n) => {
59
- let r = n + 1;
60
- return /* @__PURE__ */ i("button", {
61
- type: "button",
62
- className: r <= O ? `${e.ratingStar} ${e.ratingStarOn}` : e.ratingStar,
63
- "aria-label": `${r} из ${b}`,
64
- disabled: !w,
65
- onMouseEnter: () => w && E(r),
66
- onClick: () => {
67
- w && D(x && C === r ? 0 : r);
68
- },
69
- children: "★"
70
- }, r);
71
- })
72
- }),
73
- v ? /* @__PURE__ */ i("span", {
74
- className: e.affix,
75
- children: v
76
- }) : null
77
- ]
78
- });
79
- }
80
- s.displayName = "RatingField";
81
- //#endregion
82
- 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 r from"react";import{jsx as i,jsxs as a}from"react/jsx-runtime";function o(e,t){return Number.isFinite(e)?Math.min(t,Math.max(0,Math.round(e))):0}function s({value:s=0,form:c,onValue:l,onBlur:u,name:d=``,placeholder:f=``,label:p=``,error:m=``,hidden:h=!1,disabled:g=!1,className:_=``,after:v=``,before:y=``,max:b=5,allowClear:x=!0}){let{value:S}=n(c,d,s),C=o(Number(S),b),w=!g,[T,E]=r.useState(0),D=e=>{let t={value:e,name:d};c&&d&&c.setValue(t),l&&l!==c?.onValue&&l(t)};if(h&&!C)return null;let O=T||C;return a(t,{type:`rating`,label:p,error:m,element_blok:{className:[_||``]},element_input:{className:[e.rating],props:{"data-disabled":g||!w?`true`:void 0}},children:[y?i(`span`,{className:e.affix,children:y}):null,i(`div`,{role:`slider`,"aria-label":p||f||`Оценка`,"aria-valuemin":0,"aria-valuemax":b,"aria-valuenow":C,tabIndex:w?0:-1,onMouseLeave:()=>E(0),onBlur:()=>{E(0),u?.({value:C,name:d})},onKeyDown:e=>{if(!w)return;let t=C;if(e.key===`ArrowRight`||e.key===`ArrowUp`)t=Math.min(b,C+1);else if(e.key===`ArrowLeft`||e.key===`ArrowDown`)t=Math.max(0,C-1);else if(e.key===`Home`)t=0;else if(e.key===`End`)t=b;else return;e.preventDefault(),D(t)},children:Array.from({length:b},(t,n)=>{let r=n+1;return i(`button`,{type:`button`,className:r<=O?`${e.ratingStar} ${e.ratingStarOn}`:e.ratingStar,"aria-label":`${r} из ${b}`,disabled:!w,onMouseEnter:()=>w&&E(r),onClick:()=>{w&&D(x&&C===r?0:r)},children:`★`},r)})}),v?i(`span`,{className:e.affix,children:v}):null]})}s.displayName=`RatingField`;export{s as default};
@@ -1,134 +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 "react";
6
- import { jsx as a, jsxs as o } from "react/jsx-runtime";
7
- //#region src/lib/fields/RichText.tsx
8
- function s({ value: s = "", form: c, onValue: l, onBlur: u, name: d = "", placeholder: f = "", label: p = "", error: m = "", hidden: h = !1, disabled: g = !1, className: _ = "", after: v = "", before: y = "", maxLength: b, spellCheck: x = !0, toolbar: S = !0 }) {
9
- let { value: C, version: w } = n(c, d, s), T = !g, E = typeof C == "string" ? C : "", D = i.useRef(null), O = i.useRef(!1);
10
- i.useLayoutEffect(() => {
11
- if (O.current) return;
12
- let e = D.current;
13
- e && e.innerHTML !== E && (e.innerHTML = E || "");
14
- }, [E, w]);
15
- let k = (e, t = !1) => {
16
- let n = e;
17
- if (b && n.replace(/<[^>]+>/g, "").length > b) return;
18
- let r = {
19
- value: n,
20
- name: d
21
- };
22
- c && d && (t ? c.setValue(r) : c.onValue(r)), l && l !== c?.onValue && l(r);
23
- }, A = (e) => {
24
- if (T) {
25
- D.current?.focus();
26
- try {
27
- document.execCommand(e, !1);
28
- } catch {}
29
- k(D.current?.innerHTML || "");
30
- }
31
- };
32
- if (h && r(E.replace(/<[^>]+>/g, ""))) return null;
33
- let j = {};
34
- return f && !E && (j.placeholder = f), T && (j.edit = ""), /* @__PURE__ */ o(t, {
35
- type: "richtext",
36
- label: p,
37
- error: m,
38
- element_blok: { className: [_ || ""] },
39
- element_input: {
40
- className: [e.rich],
41
- props: { "data-disabled": g || !T ? "true" : void 0 }
42
- },
43
- children: [
44
- y ? /* @__PURE__ */ a("span", {
45
- className: e.affix,
46
- children: y
47
- }) : null,
48
- /* @__PURE__ */ o("div", {
49
- className: e.richWrap,
50
- children: [S ? /* @__PURE__ */ o("div", {
51
- className: e.richToolbar,
52
- role: "toolbar",
53
- children: [
54
- /* @__PURE__ */ a("button", {
55
- type: "button",
56
- className: e.richBtn,
57
- disabled: !T,
58
- "aria-label": "Жирный",
59
- onMouseDown: (e) => e.preventDefault(),
60
- onClick: () => A("bold"),
61
- children: "B"
62
- }),
63
- /* @__PURE__ */ a("button", {
64
- type: "button",
65
- className: e.richBtn,
66
- disabled: !T,
67
- "aria-label": "Курсив",
68
- onMouseDown: (e) => e.preventDefault(),
69
- onClick: () => A("italic"),
70
- children: /* @__PURE__ */ a("em", { children: "I" })
71
- }),
72
- /* @__PURE__ */ a("button", {
73
- type: "button",
74
- className: e.richBtn,
75
- disabled: !T,
76
- "aria-label": "Подчёркивание",
77
- onMouseDown: (e) => e.preventDefault(),
78
- onClick: () => A("underline"),
79
- children: /* @__PURE__ */ a("u", { children: "U" })
80
- }),
81
- /* @__PURE__ */ a("button", {
82
- type: "button",
83
- className: e.richBtn,
84
- disabled: !T,
85
- "aria-label": "Маркированный список",
86
- onMouseDown: (e) => e.preventDefault(),
87
- onClick: () => A("insertUnorderedList"),
88
- children: "•"
89
- }),
90
- /* @__PURE__ */ a("button", {
91
- type: "button",
92
- className: e.richBtn,
93
- disabled: !T,
94
- "aria-label": "Нумерованный список",
95
- onMouseDown: (e) => e.preventDefault(),
96
- onClick: () => A("insertOrderedList"),
97
- children: "1."
98
- })
99
- ]
100
- }) : null, /* @__PURE__ */ a("div", {
101
- ref: D,
102
- className: e.richEditor,
103
- contentEditable: T,
104
- suppressContentEditableWarning: !0,
105
- spellCheck: x,
106
- role: "textbox",
107
- "aria-multiline": !0,
108
- "aria-label": p || f || "Текст",
109
- tabIndex: T ? 0 : -1,
110
- onFocus: () => {
111
- O.current = !0;
112
- },
113
- onInput: () => k(D.current?.innerHTML || ""),
114
- onBlur: () => {
115
- O.current = !1;
116
- let e = D.current?.innerHTML || "";
117
- k(e, !0), u?.({
118
- value: e,
119
- name: d
120
- });
121
- },
122
- ...j
123
- })]
124
- }),
125
- v ? /* @__PURE__ */ a("span", {
126
- className: e.affix,
127
- children: v
128
- }) : null
129
- ]
130
- });
131
- }
132
- s.displayName = "RichTextField";
133
- //#endregion
134
- 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 i from"react";import{jsx as a,jsxs as o}from"react/jsx-runtime";function s({value:s=``,form:c,onValue:l,onBlur:u,name:d=``,placeholder:f=``,label:p=``,error:m=``,hidden:h=!1,disabled:g=!1,className:_=``,after:v=``,before:y=``,maxLength:b,spellCheck:x=!0,toolbar:S=!0}){let{value:C,version:w}=n(c,d,s),T=!g,E=typeof C==`string`?C:``,D=i.useRef(null),O=i.useRef(!1);i.useLayoutEffect(()=>{if(O.current)return;let e=D.current;e&&e.innerHTML!==E&&(e.innerHTML=E||``)},[E,w]);let k=(e,t=!1)=>{let n=e;if(b&&n.replace(/<[^>]+>/g,``).length>b)return;let r={value:n,name:d};c&&d&&(t?c.setValue(r):c.onValue(r)),l&&l!==c?.onValue&&l(r)},A=e=>{if(T){D.current?.focus();try{document.execCommand(e,!1)}catch{}k(D.current?.innerHTML||``)}};if(h&&r(E.replace(/<[^>]+>/g,``)))return null;let j={};return f&&!E&&(j.placeholder=f),T&&(j.edit=``),o(t,{type:`richtext`,label:p,error:m,element_blok:{className:[_||``]},element_input:{className:[e.rich],props:{"data-disabled":g||!T?`true`:void 0}},children:[y?a(`span`,{className:e.affix,children:y}):null,o(`div`,{className:e.richWrap,children:[S?o(`div`,{className:e.richToolbar,role:`toolbar`,children:[a(`button`,{type:`button`,className:e.richBtn,disabled:!T,"aria-label":`Жирный`,onMouseDown:e=>e.preventDefault(),onClick:()=>A(`bold`),children:`B`}),a(`button`,{type:`button`,className:e.richBtn,disabled:!T,"aria-label":`Курсив`,onMouseDown:e=>e.preventDefault(),onClick:()=>A(`italic`),children:a(`em`,{children:`I`})}),a(`button`,{type:`button`,className:e.richBtn,disabled:!T,"aria-label":`Подчёркивание`,onMouseDown:e=>e.preventDefault(),onClick:()=>A(`underline`),children:a(`u`,{children:`U`})}),a(`button`,{type:`button`,className:e.richBtn,disabled:!T,"aria-label":`Маркированный список`,onMouseDown:e=>e.preventDefault(),onClick:()=>A(`insertUnorderedList`),children:`•`}),a(`button`,{type:`button`,className:e.richBtn,disabled:!T,"aria-label":`Нумерованный список`,onMouseDown:e=>e.preventDefault(),onClick:()=>A(`insertOrderedList`),children:`1.`})]}):null,a(`div`,{ref:D,className:e.richEditor,contentEditable:T,suppressContentEditableWarning:!0,spellCheck:x,role:`textbox`,"aria-multiline":!0,"aria-label":p||f||`Текст`,tabIndex:T?0:-1,onFocus:()=>{O.current=!0},onInput:()=>k(D.current?.innerHTML||``),onBlur:()=>{O.current=!1;let e=D.current?.innerHTML||``;k(e,!0),u?.({value:e,name:d})},...j})]}),v?a(`span`,{className:e.affix,children:v}):null]})}s.displayName=`RichTextField`;export{s as default};
@@ -1,3 +1,4 @@
1
+ import { default as React } from 'react';
1
2
  import { TInput } from './type';
2
3
  type SelectOptionObject = Record<number, {
3
4
  n: string;
@@ -18,4 +19,5 @@ declare function SelectField({ value, form, onValue, name, placeholder, label, e
18
19
  declare namespace SelectField {
19
20
  var displayName: string;
20
21
  }
21
- export default SelectField;
22
+ declare const _default: React.MemoExoticComponent<typeof SelectField>;
23
+ export default _default;
@@ -1,171 +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 { acquireOverlayZIndex as r, releaseOverlayZIndex as i } from "../overlayZ.js";
5
- import a from "../styles/Select.module.js";
6
- import o, { useEffect as s, useState as c } from "react";
7
- import { Fragment as l, jsx as u, jsxs as d } from "react/jsx-runtime";
8
- import { createPortal as f } from "react-dom";
9
- //#region src/lib/fields/Select.tsx
10
- function p({ value: r = 0, form: i, onValue: c, name: p = "", placeholder: h = "", label: g, error: _, hidden: v = !1, disabled: y = !1, className: b, after: x = "", before: S = "", options: C, order: w, size: T = "md" }) {
11
- let [E, D] = o.useState(!1), [O, k] = o.useState(0), [A, j] = o.useState(null), M = o.useRef(null), N = o.useId(), P = o.useCallback(() => {
12
- let e = M.current;
13
- e && j(e.getBoundingClientRect());
14
- }, []);
15
- s(() => {
16
- if (!E) return;
17
- P();
18
- let e = () => P();
19
- return window.addEventListener("scroll", e, !0), window.addEventListener("resize", e), () => {
20
- window.removeEventListener("scroll", e, !0), window.removeEventListener("resize", e);
21
- };
22
- }, [E, P]);
23
- let { value: F } = n(i, p, r ?? 0), I = Number(F), L = [];
24
- C && (L = Array.isArray(C) ? C.map((e) => ({
25
- id: e.id ?? e.i ?? 0,
26
- label: e.n || "",
27
- hidden: e.s === 0
28
- })).filter((e) => e.id !== 0 && e.label.length > 0) : Object.keys(C).map((e) => {
29
- let t = Number(e), n = C[t];
30
- return {
31
- id: t,
32
- label: n?.n || "",
33
- hidden: n?.s === 0
34
- };
35
- }).filter((e) => e.label.length > 0));
36
- let R = (() => {
37
- if (!w || w.length === 0) return L;
38
- let e = new Map(L.map((e) => [e.id, e]));
39
- return w.map((t) => e.get(t)).filter((e) => !!e);
40
- })().filter((e) => !e.hidden), z = (e) => R.find((t) => t.id === e)?.label, B = E && R.length > 0 ? `${N}-opt-${O}` : void 0, V = (e) => {
41
- let t = {
42
- value: e,
43
- name: p
44
- };
45
- i && p && i.onValue(t), c && c !== i?.onValue && c(t);
46
- }, H = (e) => {
47
- if (R.length === 0 || y) return;
48
- let t = R.findIndex((e) => e.id === I);
49
- M.current = e, j(e.getBoundingClientRect()), k(t >= 0 ? t : 0), D(!0);
50
- }, U = (e) => {
51
- H(e.currentTarget);
52
- }, W = (e) => {
53
- if (!y && R.length !== 0) {
54
- if (!E && (e.key === "ArrowDown" || e.key === "Enter" || e.key === " ")) {
55
- e.preventDefault(), H(e.currentTarget);
56
- return;
57
- }
58
- if (E) {
59
- if (e.key === "Escape") {
60
- e.preventDefault(), D(!1);
61
- return;
62
- }
63
- if (e.key === "ArrowDown") {
64
- e.preventDefault(), k((e) => (e + 1) % R.length);
65
- return;
66
- }
67
- if (e.key === "ArrowUp") {
68
- e.preventDefault(), k((e) => e - 1 < 0 ? R.length - 1 : e - 1);
69
- return;
70
- }
71
- if (e.key === "Enter") {
72
- e.preventDefault();
73
- let t = R[O];
74
- t && V(t.id), D(!1);
75
- }
76
- }
77
- }
78
- }, G = {};
79
- h && (G.placeholder = h);
80
- let K = z(I), q = (K === void 0 || K === "") && !!h, J = I === 0 || z(I) === void 0;
81
- return v && J ? "" : /* @__PURE__ */ d(l, { children: [/* @__PURE__ */ d(t, {
82
- type: "select",
83
- label: g,
84
- element_blok: { className: [b || ""] },
85
- error: _,
86
- size: T,
87
- element_input: {
88
- className: [a.f],
89
- props: {
90
- onClick: U,
91
- onKeyDown: W,
92
- tabIndex: y ? -1 : 0,
93
- role: "combobox",
94
- "aria-expanded": E,
95
- "aria-haspopup": "listbox",
96
- "aria-controls": N,
97
- ...B ? { "aria-activedescendant": B } : {},
98
- "aria-disabled": y,
99
- "data-disabled": y
100
- }
101
- },
102
- children: [
103
- S ? /* @__PURE__ */ u("span", {
104
- className: e.affix,
105
- children: S
106
- }) : null,
107
- /* @__PURE__ */ u("div", {
108
- ...G,
109
- className: q ? a.placeholderValue : void 0,
110
- children: K ?? h ?? ""
111
- }),
112
- x ? /* @__PURE__ */ u("span", {
113
- className: e.affix,
114
- children: x
115
- }) : null
116
- ]
117
- }), E && f(/* @__PURE__ */ u(m, {
118
- parent: A || void 0,
119
- onValue: V,
120
- className: b,
121
- items: R,
122
- setOpen: D,
123
- listId: N,
124
- activeIndex: O,
125
- currentValue: I
126
- }), document.body)] });
127
- }
128
- p.displayName = "SelectField";
129
- var m = ({ onValue: e, parent: t, className: n, items: o, setOpen: f, listId: p, activeIndex: m, currentValue: g }) => {
130
- let [_] = c(() => r());
131
- if (s(() => () => i(_), [_]), !t) return null;
132
- let v = () => {
133
- f(!1);
134
- }, y = (t) => {
135
- f(!1), e(t);
136
- }, b = Math.min(300, Math.max(52, o.length * 52 + 8)), x = window.innerHeight - t.bottom - 6 - 8, S = t.top - 6 - 8, C = x < Math.min(b, 160) && S > x, w = Math.max(t.width, 260), T = Math.min(Math.max(8, t.left), window.innerWidth - w - 8);
137
- return /* @__PURE__ */ d(l, { children: [/* @__PURE__ */ u("div", {
138
- className: a.o,
139
- style: { zIndex: _ },
140
- onClick: v,
141
- "aria-hidden": !0
142
- }), /* @__PURE__ */ u("div", {
143
- className: [a.l, n].filter((e) => e !== void 0).join(" "),
144
- style: {
145
- ...C ? { bottom: `${window.innerHeight - t.top + 6}px` } : { top: `${t.bottom + 6}px` },
146
- left: T + "px",
147
- width: w,
148
- zIndex: _ + 1
149
- },
150
- children: /* @__PURE__ */ u(h, {
151
- listId: p,
152
- items: o,
153
- link: y,
154
- activeIndex: m,
155
- currentValue: g
156
- })
157
- })] });
158
- }, h = ({ listId: e, items: t, link: n, activeIndex: r, currentValue: i }) => /* @__PURE__ */ u("ul", {
159
- id: e,
160
- role: "listbox",
161
- children: t.map((t, a) => /* @__PURE__ */ u("li", {
162
- id: `${e}-opt-${a}`,
163
- role: "option",
164
- "aria-selected": i === t.id,
165
- "data-focus": r === a ? "true" : "false",
166
- onClick: () => n(t.id),
167
- children: t.label
168
- }, t.id))
169
- });
170
- //#endregion
171
- export { p 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{acquireOverlayZIndex as r,releaseOverlayZIndex as i}from"../overlayZ.js";import a from"../styles/Select.module.js";import o,{useEffect as s,useState as c}from"react";import{Fragment as l,jsx as u,jsxs as d}from"react/jsx-runtime";import{createPortal as f}from"react-dom";function p({value:r=0,form:i,onValue:c,name:p=``,placeholder:m=``,label:g,error:_,hidden:v=!1,disabled:y=!1,className:b,after:x=``,before:S=``,options:C,order:w,size:T=`md`}){let[E,D]=o.useState(!1),[O,k]=o.useState(0),[A,j]=o.useState(null),M=o.useRef(null),N=o.useId(),P=o.useCallback(()=>{let e=M.current;if(!e)return;let t=e.getBoundingClientRect();j(e=>e&&e.top===t.top&&e.left===t.left&&e.width===t.width&&e.height===t.height&&e.bottom===t.bottom?e:t)},[]);s(()=>{if(!E)return;P();let e=()=>P();return window.addEventListener(`scroll`,e,!0),window.addEventListener(`resize`,e),()=>{window.removeEventListener(`scroll`,e,!0),window.removeEventListener(`resize`,e)}},[E,P]);let{value:F}=n(i,p,r??0),I=Number(F),L=[];C&&(L=Array.isArray(C)?C.map(e=>({id:e.id??e.i??0,label:e.n||``,hidden:e.s===0})).filter(e=>e.id!==0&&e.label.length>0):Object.keys(C).map(e=>{let t=Number(e),n=C[t];return{id:t,label:n?.n||``,hidden:n?.s===0}}).filter(e=>e.label.length>0));let R=(()=>{if(!w||w.length===0)return L;let e=new Map(L.map(e=>[e.id,e]));return w.map(t=>e.get(t)).filter(e=>!!e)})().filter(e=>!e.hidden),z=e=>R.find(t=>t.id===e)?.label,B=E&&R.length>0?`${N}-opt-${O}`:void 0,V=e=>{let t={value:e,name:p};i&&p&&i.setValue(t),c&&c!==i?.onValue&&c(t)},H=e=>{if(R.length===0||y)return;let t=R.findIndex(e=>e.id===I);M.current=e;let n=e.getBoundingClientRect(),r=t>=0?t:0;j(n),k(r),D(!0)},U=e=>{H(e.currentTarget)},W=e=>{if(!y&&R.length!==0){if(!E&&(e.key===`ArrowDown`||e.key===`Enter`||e.key===` `)){e.preventDefault(),H(e.currentTarget);return}if(E){if(e.key===`Escape`){e.preventDefault(),D(!1);return}if(e.key===`ArrowDown`){e.preventDefault(),k(e=>(e+1)%R.length);return}if(e.key===`ArrowUp`){e.preventDefault(),k(e=>e-1<0?R.length-1:e-1);return}if(e.key===`Enter`){e.preventDefault();let t=R[O];t&&V(t.id),D(!1)}}}},G={};m&&(G.placeholder=m);let K=z(I),q=(K===void 0||K===``)&&!!m,J=I===0||z(I)===void 0;return v&&J?``:d(l,{children:[d(t,{type:`select`,label:g,element_blok:{className:[b||``]},error:_,size:T,element_input:{className:[a.f],props:{onClick:U,onKeyDown:W,tabIndex:y?-1:0,role:`combobox`,"aria-expanded":E,"aria-haspopup":`listbox`,"aria-controls":N,...B?{"aria-activedescendant":B}:{},"aria-disabled":y,"data-disabled":y}},children:[S?u(`span`,{className:e.affix,children:S}):null,u(`div`,{...G,className:q?a.placeholderValue:void 0,children:K??m??``}),x?u(`span`,{className:e.affix,children:x}):null]}),E&&f(u(h,{parent:A||void 0,onValue:V,className:b,items:R,setOpen:D,listId:N,activeIndex:O,currentValue:I}),document.body)]})}p.displayName=`SelectField`;var m=o.memo(p),h=({onValue:e,parent:t,className:n,items:o,setOpen:f,listId:p,activeIndex:m,currentValue:h})=>{let[_]=c(()=>r());if(s(()=>()=>i(_),[_]),!t)return null;let v=()=>{f(!1)},y=t=>{f(!1),e(t)},b=Math.min(300,Math.max(52,o.length*52+8)),x=window.innerHeight-t.bottom-6-8,S=t.top-6-8,C=x<Math.min(b,160)&&S>x,w=Math.max(t.width,260),T=Math.min(Math.max(8,t.left),window.innerWidth-w-8);return d(l,{children:[u(`div`,{className:a.o,style:{zIndex:_},onClick:v,"aria-hidden":!0}),u(`div`,{className:[a.l,n].filter(e=>e!==void 0).join(` `),style:{...C?{bottom:`${window.innerHeight-t.top+6}px`}:{top:`${t.bottom+6}px`},left:T+`px`,width:w,zIndex:_+1},children:u(g,{listId:p,items:o,link:y,activeIndex:m,currentValue:h})})]})},g=({listId:e,items:t,link:n,activeIndex:r,currentValue:i})=>u(`ul`,{id:e,role:`listbox`,children:t.map((t,a)=>u(`li`,{id:`${e}-opt-${a}`,role:`option`,"aria-selected":i===t.id,"data-focus":r===a?`true`:`false`,onClick:()=>n(t.id),children:t.label},t.id))});export{m as default};
@@ -1,97 +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 r from "react";
5
- import { jsx as i, jsxs as a } from "react/jsx-runtime";
6
- //#region src/lib/fields/Tags.tsx
7
- function o(e) {
8
- return Array.isArray(e) ? e.map(String).map((e) => e.trim()).filter(Boolean) : typeof e == "string" && e.trim() ? e.split(",").map((e) => e.trim()).filter(Boolean) : [];
9
- }
10
- function s({ value: s = [], form: c, onValue: l, onBlur: u, name: d = "", placeholder: f = "Добавить…", label: p = "", error: m = "", hidden: h = !1, disabled: g = !1, className: _ = "", after: v = "", before: y = "", maxTags: b, maxLength: x, separators: S = [",", "Enter"] }) {
11
- let { value: C } = n(c, d, s), w = o(C), T = !g, [E, D] = r.useState(""), O = r.useRef(null), k = (e) => {
12
- let t = {
13
- value: e,
14
- name: d
15
- };
16
- c && d && c.setValue(t), l && l !== c?.onValue && l(t);
17
- }, A = (e) => {
18
- let t = e.trim();
19
- if (t && !(x && t.length > x)) {
20
- if (w.some((e) => e.toLowerCase() === t.toLowerCase())) {
21
- D("");
22
- return;
23
- }
24
- b !== void 0 && w.length >= b || (k([...w, t]), D(""));
25
- }
26
- }, j = (e) => {
27
- T && k(w.filter((t, n) => n !== e));
28
- }, M = (e) => {
29
- if (T) {
30
- if (S.includes(e.key) || e.key === "," && S.includes(",")) {
31
- e.preventDefault(), A(E);
32
- return;
33
- }
34
- e.key === "Backspace" && !E && w.length > 0 && (e.preventDefault(), j(w.length - 1));
35
- }
36
- }, N = w.length === 0;
37
- return h && N ? null : /* @__PURE__ */ a(t, {
38
- type: "tags",
39
- label: p,
40
- error: m,
41
- element_blok: { className: [_ || ""] },
42
- element_input: {
43
- className: [e.tags],
44
- props: {
45
- "data-disabled": g || !T ? "true" : void 0,
46
- onClick: () => O.current?.focus()
47
- }
48
- },
49
- children: [
50
- y ? /* @__PURE__ */ i("span", {
51
- className: e.affix,
52
- children: y
53
- }) : null,
54
- /* @__PURE__ */ a("div", {
55
- className: e.tagsInner,
56
- children: [w.map((t, n) => /* @__PURE__ */ a("span", {
57
- className: e.tagChip,
58
- children: [/* @__PURE__ */ i("span", {
59
- className: e.tagLabel,
60
- children: t
61
- }), T ? /* @__PURE__ */ i("button", {
62
- type: "button",
63
- className: e.tagRemove,
64
- "aria-label": `Удалить ${t}`,
65
- onClick: (e) => {
66
- e.stopPropagation(), j(n);
67
- },
68
- children: "×"
69
- }) : null]
70
- }, `${t}-${n}`)), T && (b === void 0 || w.length < b) ? /* @__PURE__ */ i("input", {
71
- ref: O,
72
- className: e.tagInput,
73
- value: E,
74
- placeholder: w.length === 0 ? f : "",
75
- disabled: g,
76
- maxLength: x,
77
- "aria-label": p || f || "Теги",
78
- onChange: (e) => D(e.target.value),
79
- onKeyDown: M,
80
- onBlur: () => {
81
- E.trim() && A(E), u?.({
82
- value: w,
83
- name: d
84
- });
85
- }
86
- }) : null]
87
- }),
88
- v ? /* @__PURE__ */ i("span", {
89
- className: e.affix,
90
- children: v
91
- }) : null
92
- ]
93
- });
94
- }
95
- s.displayName = "TagsField";
96
- //#endregion
97
- 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 r from"react";import{jsx as i,jsxs as a}from"react/jsx-runtime";function o(e){return Array.isArray(e)?e.map(String).map(e=>e.trim()).filter(Boolean):typeof e==`string`&&e.trim()?e.split(`,`).map(e=>e.trim()).filter(Boolean):[]}function s({value:s=[],form:c,onValue:l,onBlur:u,name:d=``,placeholder:f=`Добавить…`,label:p=``,error:m=``,hidden:h=!1,disabled:g=!1,className:_=``,after:v=``,before:y=``,maxTags:b,maxLength:x,separators:S=[`,`,`Enter`]}){let{value:C}=n(c,d,s),w=o(C),T=!g,[E,D]=r.useState(``),O=r.useRef(null),k=e=>{let t={value:e,name:d};c&&d&&c.setValue(t),l&&l!==c?.onValue&&l(t)},A=e=>{let t=e.trim();if(t&&!(x&&t.length>x)){if(w.some(e=>e.toLowerCase()===t.toLowerCase())){D(``);return}b!==void 0&&w.length>=b||(k([...w,t]),D(``))}},j=e=>{T&&k(w.filter((t,n)=>n!==e))},M=e=>{if(T){if(S.includes(e.key)||e.key===`,`&&S.includes(`,`)){e.preventDefault(),A(E);return}e.key===`Backspace`&&!E&&w.length>0&&(e.preventDefault(),j(w.length-1))}},N=w.length===0;return h&&N?null:a(t,{type:`tags`,label:p,error:m,element_blok:{className:[_||``]},element_input:{className:[e.tags],props:{"data-disabled":g||!T?`true`:void 0,onClick:()=>O.current?.focus()}},children:[y?i(`span`,{className:e.affix,children:y}):null,a(`div`,{className:e.tagsInner,children:[w.map((t,n)=>a(`span`,{className:e.tagChip,children:[i(`span`,{className:e.tagLabel,children:t}),T?i(`button`,{type:`button`,className:e.tagRemove,"aria-label":`Удалить ${t}`,onClick:e=>{e.stopPropagation(),j(n)},children:`×`}):null]},`${t}-${n}`)),T&&(b===void 0||w.length<b)?i(`input`,{ref:O,className:e.tagInput,value:E,placeholder:w.length===0?f:``,disabled:g,maxLength:x,"aria-label":p||f||`Теги`,onChange:e=>D(e.target.value),onKeyDown:M,onBlur:()=>{E.trim()&&A(E),u?.({value:w,name:d})}}):null]}),v?i(`span`,{className:e.affix,children:v}):null]})}s.displayName=`TagsField`;export{s as default};
@@ -1,6 +1,6 @@
1
1
  import { TInput } from './type';
2
2
  /** TextareaField — многострочное поле (contentEditable). */
3
- declare function TextareaField({ value, form, onValue, name, placeholder, label, hidden, disabled, onBlur: onBlurField, className, after, before, error, size, inputmode, maxLength, spellCheck, }: TInput): import("react/jsx-runtime").JSX.Element;
3
+ declare function TextareaField({ value, form, onValue, name, placeholder, label, hidden, disabled, onBlur: onBlurField, className, after, before, error, size, inputmode, maxLength, spellCheck, }: TInput): import("react/jsx-runtime").JSX.Element | null;
4
4
  declare namespace TextareaField {
5
5
  var displayName: string;
6
6
  }
@@ -1,68 +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 r, { asEditableClipboard as i } from "../events/onEvent.js";
5
- import { isEmptyTextLike as a } from "./visibility.js";
6
- import o from "react";
7
- import { Fragment as s, jsx as c, jsxs as l } from "react/jsx-runtime";
8
- //#region src/lib/fields/Textarea.tsx
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 = "", size: C = "md", inputmode: w = "text", maxLength: T, spellCheck: E = !0 }) {
10
- let { value: D, version: O } = n(d, p || "", u), k = !_, A = String(D ?? ""), j = o.useRef(null), M = o.useRef(!1);
11
- o.useLayoutEffect(() => {
12
- if (M.current) return;
13
- let e = j.current;
14
- e && e.innerText !== A && (e.innerText = A);
15
- }, [A, O]);
16
- let N = (e) => {
17
- let t = {
18
- value: e.currentTarget.innerText,
19
- name: p || ""
20
- };
21
- d && p && d.onValue(t), f && f !== d?.onValue && f(t);
22
- }, P = (e) => {
23
- let t = (e.currentTarget.textContent ?? "").trim();
24
- T && t.length >= T && e.key !== "Backspace" && e.preventDefault(), e.key === "Enter" && !e.shiftKey && e.preventDefault();
25
- }, F = (e) => r.Paste(T || 0, i(e));
26
- if (g && a(D)) return /* @__PURE__ */ c(s, {});
27
- let I = {};
28
- return m && (I.placeholder = m), k && (I.edit = ""), I.inputMode = w || "text", /* @__PURE__ */ l(t, {
29
- type: "note",
30
- label: h,
31
- error: S,
32
- size: C,
33
- element_blok: { className: [y || ""] },
34
- element_input: { className: [e.n] },
35
- children: [
36
- x ? /* @__PURE__ */ c("span", {
37
- className: e.affix,
38
- children: x
39
- }) : null,
40
- /* @__PURE__ */ c("div", {
41
- ref: j,
42
- onPaste: F,
43
- onInput: N,
44
- onFocus: () => {
45
- M.current = !0;
46
- },
47
- onBlur: (e) => {
48
- r.Blur(e), v?.({
49
- value: (e.currentTarget.textContent ?? "").trim(),
50
- name: p || ""
51
- }), M.current = !1;
52
- },
53
- onKeyDown: P,
54
- spellCheck: E,
55
- contentEditable: k ? "plaintext-only" : !1,
56
- suppressContentEditableWarning: !0,
57
- ...I
58
- }),
59
- b ? /* @__PURE__ */ c("span", {
60
- className: e.affix,
61
- children: b
62
- }) : null
63
- ]
64
- });
65
- }
66
- u.displayName = "TextareaField";
67
- //#endregion
68
- export { u as default };
1
+ import e from"../styles/Field.module.js";import t,{useFieldA11y as n}from"../core/Field.js";import{useFormFieldState as r}from"../hooks/use.js";import i,{asEditableClipboard as a}from"../events/onEvent.js";import{isEmptyTextLike as o}from"./visibility.js";import s from"react";import{jsx as c,jsxs as l}from"react/jsx-runtime";function u({value:n,form:u,onValue:f,name:p=``,placeholder:m=``,label:h=``,hidden:g=!1,disabled:_=!1,onBlur:v,className:y=``,after:b=``,before:x=``,error:S=``,size:C=`md`,inputmode:w=`text`,maxLength:T,spellCheck:E=!0}){let{value:D,version:O}=r(u,p||``,n),k=!_,A=String(D??``),j=s.useRef(null),M=s.useRef(!1);s.useLayoutEffect(()=>{if(M.current)return;let e=j.current;e&&e.innerText!==A&&(e.innerText=A)},[A,O]);let N=e=>{let t={value:e.currentTarget.innerText,name:p||``};u&&p&&u.onValue(t),f&&f!==u?.onValue&&f(t)},P=e=>{let t=(e.currentTarget.textContent??``).trim();T&&t.length>=T&&e.key!==`Backspace`&&e.preventDefault(),e.key===`Enter`&&!e.shiftKey&&e.preventDefault()},F=e=>i.Paste(T||0,a(e));if(g&&o(D))return null;let I={};return m&&(I.placeholder=m),k&&(I.edit=``),I.inputMode=w||`text`,l(t,{type:`note`,label:h,error:S,size:C,element_blok:{className:[y||``]},element_input:{className:[e.n]},children:[x?c(`span`,{className:e.affix,children:x}):null,c(d,{divRef:j,editable:k,label:h,placeholder:m,spellCheck:E,dd:I,onPaste:F,onInput:N,onFocus:()=>{M.current=!0},onBlur:e=>{i.Blur(e),v?.({value:(e.currentTarget.textContent??``).trim(),name:p||``}),M.current=!1},onKeyDown:P}),b?c(`span`,{className:e.affix,children:b}):null]})}function d({divRef:e,editable:t,label:r,placeholder:i,spellCheck:a,dd:o,onPaste:s,onInput:l,onFocus:u,onBlur:d,onKeyDown:f}){let p=n();return c(`div`,{ref:e,id:p?.controlId,role:`textbox`,"aria-multiline":`true`,"aria-label":r?void 0:i||`Текст`,"aria-describedby":p?.describedBy,"aria-invalid":p?.errorId?!0:void 0,tabIndex:t?0:-1,onPaste:s,onInput:l,onFocus:u,onBlur:d,onKeyDown:f,spellCheck:a,contentEditable:t?`plaintext-only`:!1,suppressContentEditableWarning:!0,...o})}u.displayName=`TextareaField`;export{u as default};