@elcrm/form 0.0.87 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +87 -47
- package/dist/Form.js +1 -11
- package/dist/FormInitContext.js +1 -20
- package/dist/assets/styles/Field.module.css +1 -1
- package/dist/assets/styles/Form.module.css +1 -1
- package/dist/assets/styles/Select.module.css +1 -1
- package/dist/core/Field.d.ts +14 -2
- package/dist/core/Field.js +2 -35
- package/dist/dark.css +22 -3
- package/dist/events/onEvent.js +1 -67
- package/dist/fields/Check.js +1 -86
- package/dist/fields/Code.js +1 -94
- package/dist/fields/Color.js +1 -495
- package/dist/fields/Date.js +1 -450
- package/dist/fields/Display.d.ts +1 -1
- package/dist/fields/Display.js +1 -49
- package/dist/fields/DragDrop.js +1 -189
- package/dist/fields/Email.d.ts +4 -2
- package/dist/fields/Email.js +1 -80
- package/dist/fields/File.js +1 -115
- package/dist/fields/Hidden.js +1 -33
- package/dist/fields/Input.d.ts +3 -1
- package/dist/fields/Input.js +1 -149
- package/dist/fields/Mask.js +1 -119
- package/dist/fields/Modal.js +1 -68
- package/dist/fields/Money.js +1 -125
- package/dist/fields/NativeTextField.d.ts +15 -0
- package/dist/fields/NativeTextField.js +1 -0
- package/dist/fields/Numeric.d.ts +12 -1
- package/dist/fields/Numeric.js +1 -105
- package/dist/fields/Options.js +1 -69
- package/dist/fields/Password.d.ts +1 -1
- package/dist/fields/Password.js +1 -143
- package/dist/fields/Percent.d.ts +8 -1
- package/dist/fields/Percent.js +1 -100
- package/dist/fields/Phone.d.ts +2 -2
- package/dist/fields/Phone.js +1 -128
- package/dist/fields/Radio.js +1 -88
- package/dist/fields/Range.js +1 -109
- package/dist/fields/Rating.js +1 -82
- package/dist/fields/RichText.js +1 -134
- package/dist/fields/Select.d.ts +3 -1
- package/dist/fields/Select.js +1 -159
- package/dist/fields/Tags.js +1 -97
- package/dist/fields/Textarea.d.ts +1 -1
- package/dist/fields/Textarea.js +1 -68
- package/dist/fields/Time.js +1 -444
- package/dist/fields/Url.d.ts +4 -2
- package/dist/fields/Url.js +1 -80
- package/dist/fields/emit.d.ts +9 -0
- package/dist/fields/emit.js +1 -0
- package/dist/fields/type.d.ts +1 -1
- package/dist/fields/visibility.js +1 -6
- package/dist/hooks/use.js +1 -57
- package/dist/index.js +2 -42
- package/dist/index.umd.js +2 -2
- package/dist/light.css +23 -3
- package/dist/mask/MaskPhone.js +1 -1384
- package/dist/mask/phoneDefaults.d.ts +8 -0
- package/dist/mask/phoneDefaults.js +1 -0
- package/dist/overlayZ.js +1 -25
- package/dist/package.js +1 -130
- package/dist/style.css +3 -3
- package/dist/styles/Color.module.js +1 -27
- package/dist/styles/Field.module.js +1 -77
- package/dist/styles/Form.module.js +1 -12
- package/dist/styles/Select.module.js +1 -9
- package/package.json +2 -2
package/dist/fields/Rating.js
CHANGED
|
@@ -1,82 +1 @@
|
|
|
1
|
-
import e from
|
|
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};
|
package/dist/fields/RichText.js
CHANGED
|
@@ -1,134 +1 @@
|
|
|
1
|
-
import e from
|
|
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};
|
package/dist/fields/Select.d.ts
CHANGED
|
@@ -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
|
-
|
|
22
|
+
declare const _default: React.MemoExoticComponent<typeof SelectField>;
|
|
23
|
+
export default _default;
|
package/dist/fields/Select.js
CHANGED
|
@@ -1,159 +1 @@
|
|
|
1
|
-
import e from
|
|
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: s, name: c = "", placeholder: p = "", label: h, error: g, hidden: _ = !1, disabled: v = !1, className: y, after: b = "", before: x = "", options: S, order: C, size: w = "md" }) {
|
|
11
|
-
let [T, E] = o.useState(!1), [D, O] = o.useState(0), [k, A] = o.useState(null), j = o.useId(), { value: M } = n(i, c, r ?? 0), N = Number(M), P = [];
|
|
12
|
-
S && (P = Array.isArray(S) ? S.map((e) => ({
|
|
13
|
-
id: e.id ?? e.i ?? 0,
|
|
14
|
-
label: e.n || "",
|
|
15
|
-
hidden: e.s === 0
|
|
16
|
-
})).filter((e) => e.id !== 0 && e.label.length > 0) : Object.keys(S).map((e) => {
|
|
17
|
-
let t = Number(e), n = S[t];
|
|
18
|
-
return {
|
|
19
|
-
id: t,
|
|
20
|
-
label: n?.n || "",
|
|
21
|
-
hidden: n?.s === 0
|
|
22
|
-
};
|
|
23
|
-
}).filter((e) => e.label.length > 0));
|
|
24
|
-
let F = (() => {
|
|
25
|
-
if (!C || C.length === 0) return P;
|
|
26
|
-
let e = new Map(P.map((e) => [e.id, e]));
|
|
27
|
-
return C.map((t) => e.get(t)).filter((e) => !!e);
|
|
28
|
-
})().filter((e) => !e.hidden), I = (e) => F.find((t) => t.id === e)?.label, L = T && F.length > 0 ? `${j}-opt-${D}` : void 0, R = (e) => {
|
|
29
|
-
let t = {
|
|
30
|
-
value: e,
|
|
31
|
-
name: c
|
|
32
|
-
};
|
|
33
|
-
i && c && i.onValue(t), s && s !== i?.onValue && s(t);
|
|
34
|
-
}, z = (e) => {
|
|
35
|
-
if (F.length === 0 || v) return;
|
|
36
|
-
let t = F.findIndex((e) => e.id === N);
|
|
37
|
-
A(e.getBoundingClientRect()), O(t >= 0 ? t : 0), E(!0);
|
|
38
|
-
}, B = (e) => {
|
|
39
|
-
z(e.currentTarget);
|
|
40
|
-
}, V = (e) => {
|
|
41
|
-
if (!v && F.length !== 0) {
|
|
42
|
-
if (!T && (e.key === "ArrowDown" || e.key === "Enter" || e.key === " ")) {
|
|
43
|
-
e.preventDefault(), z(e.currentTarget);
|
|
44
|
-
return;
|
|
45
|
-
}
|
|
46
|
-
if (T) {
|
|
47
|
-
if (e.key === "Escape") {
|
|
48
|
-
e.preventDefault(), E(!1);
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
if (e.key === "ArrowDown") {
|
|
52
|
-
e.preventDefault(), O((e) => (e + 1) % F.length);
|
|
53
|
-
return;
|
|
54
|
-
}
|
|
55
|
-
if (e.key === "ArrowUp") {
|
|
56
|
-
e.preventDefault(), O((e) => e - 1 < 0 ? F.length - 1 : e - 1);
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
if (e.key === "Enter") {
|
|
60
|
-
e.preventDefault();
|
|
61
|
-
let t = F[D];
|
|
62
|
-
t && R(t.id), E(!1);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
}, H = {};
|
|
67
|
-
p && (H.placeholder = p);
|
|
68
|
-
let U = I(N), W = (U === void 0 || U === "") && !!p, G = N === 0 || I(N) === void 0;
|
|
69
|
-
return _ && G ? "" : /* @__PURE__ */ d(l, { children: [/* @__PURE__ */ d(t, {
|
|
70
|
-
type: "select",
|
|
71
|
-
label: h,
|
|
72
|
-
element_blok: { className: [y || ""] },
|
|
73
|
-
error: g,
|
|
74
|
-
size: w,
|
|
75
|
-
element_input: {
|
|
76
|
-
className: [a.f],
|
|
77
|
-
props: {
|
|
78
|
-
onClick: B,
|
|
79
|
-
onKeyDown: V,
|
|
80
|
-
tabIndex: v ? -1 : 0,
|
|
81
|
-
role: "combobox",
|
|
82
|
-
"aria-expanded": T,
|
|
83
|
-
"aria-haspopup": "listbox",
|
|
84
|
-
"aria-controls": j,
|
|
85
|
-
...L ? { "aria-activedescendant": L } : {},
|
|
86
|
-
"aria-disabled": v,
|
|
87
|
-
"data-disabled": v
|
|
88
|
-
}
|
|
89
|
-
},
|
|
90
|
-
children: [
|
|
91
|
-
x ? /* @__PURE__ */ u("span", {
|
|
92
|
-
className: e.affix,
|
|
93
|
-
children: x
|
|
94
|
-
}) : null,
|
|
95
|
-
/* @__PURE__ */ u("div", {
|
|
96
|
-
...H,
|
|
97
|
-
className: W ? a.placeholderValue : void 0,
|
|
98
|
-
children: U ?? p ?? ""
|
|
99
|
-
}),
|
|
100
|
-
b ? /* @__PURE__ */ u("span", {
|
|
101
|
-
className: e.affix,
|
|
102
|
-
children: b
|
|
103
|
-
}) : null
|
|
104
|
-
]
|
|
105
|
-
}), T && f(/* @__PURE__ */ u(m, {
|
|
106
|
-
parent: k || void 0,
|
|
107
|
-
onValue: R,
|
|
108
|
-
className: y,
|
|
109
|
-
items: F,
|
|
110
|
-
setOpen: E,
|
|
111
|
-
listId: j,
|
|
112
|
-
activeIndex: D,
|
|
113
|
-
currentValue: N
|
|
114
|
-
}), document.body)] });
|
|
115
|
-
}
|
|
116
|
-
p.displayName = "SelectField";
|
|
117
|
-
var m = ({ onValue: e, parent: t, className: n, items: o, setOpen: f, listId: p, activeIndex: m, currentValue: g }) => {
|
|
118
|
-
let [_] = c(() => r());
|
|
119
|
-
if (s(() => () => i(_), [_]), !t) return null;
|
|
120
|
-
let v = () => {
|
|
121
|
-
f(!1);
|
|
122
|
-
}, y = (t) => {
|
|
123
|
-
f(!1), e(t);
|
|
124
|
-
}, b = window.innerHeight - t.bottom < 306 ? Math.max(6, t.top - 300 - 6) : Math.min(window.innerHeight - 300 - 6, t.bottom + 6), x = Math.max(t.width, 260), S = Math.min(Math.max(6, t.left), window.innerWidth - x - 6);
|
|
125
|
-
return /* @__PURE__ */ d(l, { children: [/* @__PURE__ */ u("div", {
|
|
126
|
-
className: a.o,
|
|
127
|
-
style: { zIndex: _ },
|
|
128
|
-
onClick: v,
|
|
129
|
-
"aria-hidden": !0
|
|
130
|
-
}), /* @__PURE__ */ u("div", {
|
|
131
|
-
className: [a.l, n].filter((e) => e !== void 0).join(" "),
|
|
132
|
-
style: {
|
|
133
|
-
top: b + "px",
|
|
134
|
-
left: S + "px",
|
|
135
|
-
width: x,
|
|
136
|
-
zIndex: _ + 1
|
|
137
|
-
},
|
|
138
|
-
children: /* @__PURE__ */ u(h, {
|
|
139
|
-
listId: p,
|
|
140
|
-
items: o,
|
|
141
|
-
link: y,
|
|
142
|
-
activeIndex: m,
|
|
143
|
-
currentValue: g
|
|
144
|
-
})
|
|
145
|
-
})] });
|
|
146
|
-
}, h = ({ listId: e, items: t, link: n, activeIndex: r, currentValue: i }) => /* @__PURE__ */ u("ul", {
|
|
147
|
-
id: e,
|
|
148
|
-
role: "listbox",
|
|
149
|
-
children: t.map((t, a) => /* @__PURE__ */ u("li", {
|
|
150
|
-
id: `${e}-opt-${a}`,
|
|
151
|
-
role: "option",
|
|
152
|
-
"aria-selected": i === t.id,
|
|
153
|
-
"data-focus": r === a ? "true" : "false",
|
|
154
|
-
onClick: () => n(t.id),
|
|
155
|
-
children: t.label
|
|
156
|
-
}, t.id))
|
|
157
|
-
});
|
|
158
|
-
//#endregion
|
|
159
|
-
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};
|
package/dist/fields/Tags.js
CHANGED
|
@@ -1,97 +1 @@
|
|
|
1
|
-
import e from
|
|
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
|
}
|
package/dist/fields/Textarea.js
CHANGED
|
@@ -1,68 +1 @@
|
|
|
1
|
-
import e from
|
|
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};
|