reactjs-virtual-keyboard 1.0.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.
- package/LICENSE +22 -0
- package/README.md +327 -0
- package/dist/index.d.ts +346 -0
- package/dist/index.esm.js +678 -0
- package/dist/index.esm.js.map +1 -0
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -0
- package/dist/styles.css +1 -0
- package/package.json +59 -0
|
@@ -0,0 +1,678 @@
|
|
|
1
|
+
import { jsx as a, jsxs as L } from "react/jsx-runtime";
|
|
2
|
+
import { useRef as A, useCallback as k, useEffect as $, useState as H } from "react";
|
|
3
|
+
const B = (e, r, n = {}) => {
|
|
4
|
+
var s;
|
|
5
|
+
const { skipValueAssignment: t = !1 } = n;
|
|
6
|
+
if (!t) {
|
|
7
|
+
const l = Object.getPrototypeOf(e), c = (s = Object.getOwnPropertyDescriptor(l, "value")) == null ? void 0 : s.set;
|
|
8
|
+
c && c.call(e, r);
|
|
9
|
+
}
|
|
10
|
+
e.dispatchEvent(new InputEvent("input", { bubbles: !0, cancelable: !0 })), e.dispatchEvent(new Event("change", { bubbles: !0, cancelable: !0 }));
|
|
11
|
+
};
|
|
12
|
+
function Y(e) {
|
|
13
|
+
return {
|
|
14
|
+
insertText: (t) => {
|
|
15
|
+
const s = e.current;
|
|
16
|
+
if (!s || s.readOnly || s.disabled) return;
|
|
17
|
+
const l = s.selectionStart, c = s.selectionEnd, o = l ?? s.value.length, u = c ?? s.value.length, f = s.scrollTop ?? 0, d = s.scrollLeft ?? 0, v = s.value.slice(0, o) + t + s.value.slice(u), m = o + t.length;
|
|
18
|
+
B(s, v), s.focus(), s.setSelectionRange(m, m), "scrollTop" in s && (s.scrollTop = f, s.scrollLeft = d);
|
|
19
|
+
},
|
|
20
|
+
backspace: () => {
|
|
21
|
+
const t = e.current;
|
|
22
|
+
if (!t || t.readOnly || t.disabled) return;
|
|
23
|
+
const s = t.selectionStart, l = t.selectionEnd, c = s ?? t.value.length, o = l ?? t.value.length, u = t.scrollTop ?? 0, f = t.scrollLeft ?? 0;
|
|
24
|
+
if (c !== o) {
|
|
25
|
+
const d = t.value.slice(0, c) + t.value.slice(o);
|
|
26
|
+
B(t, d), t.focus(), t.setSelectionRange(c, c);
|
|
27
|
+
} else if (c > 0) {
|
|
28
|
+
const d = t.value.slice(0, c - 1) + t.value.slice(c), v = c - 1;
|
|
29
|
+
B(t, d), t.focus(), t.setSelectionRange(v, v);
|
|
30
|
+
}
|
|
31
|
+
"scrollTop" in t && (t.scrollTop = u, t.scrollLeft = f);
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
function F(e, {
|
|
36
|
+
initialDelay: r = 500,
|
|
37
|
+
interval: n = 50,
|
|
38
|
+
shouldPreventDefault: t = !0
|
|
39
|
+
} = {}) {
|
|
40
|
+
const s = A(), l = A(), c = k(() => {
|
|
41
|
+
s.current && (clearTimeout(s.current), s.current = void 0), l.current && (clearInterval(l.current), l.current = void 0);
|
|
42
|
+
}, []), o = k(() => {
|
|
43
|
+
e(), s.current = setTimeout(() => {
|
|
44
|
+
l.current = setInterval(e, n);
|
|
45
|
+
}, r);
|
|
46
|
+
}, [e, r, n]);
|
|
47
|
+
return {
|
|
48
|
+
onMouseDown: (u) => {
|
|
49
|
+
u.preventDefault(), o();
|
|
50
|
+
},
|
|
51
|
+
onTouchStart: (u) => {
|
|
52
|
+
t && u.preventDefault(), o();
|
|
53
|
+
},
|
|
54
|
+
onMouseUp: c,
|
|
55
|
+
onMouseLeave: c,
|
|
56
|
+
onTouchEnd: (u) => {
|
|
57
|
+
t && u.preventDefault(), c();
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
function G({
|
|
62
|
+
isInputFocused: e,
|
|
63
|
+
onBackspace: r,
|
|
64
|
+
onEnter: n,
|
|
65
|
+
onSpace: t,
|
|
66
|
+
onCapsToggle: s,
|
|
67
|
+
onKeyClick: l
|
|
68
|
+
}) {
|
|
69
|
+
$(() => {
|
|
70
|
+
if (!e) return;
|
|
71
|
+
const c = (o) => {
|
|
72
|
+
const u = o.key;
|
|
73
|
+
switch (u) {
|
|
74
|
+
case "Backspace":
|
|
75
|
+
o.preventDefault(), o.stopPropagation(), r();
|
|
76
|
+
return;
|
|
77
|
+
case "Enter":
|
|
78
|
+
o.preventDefault(), n();
|
|
79
|
+
return;
|
|
80
|
+
case " ":
|
|
81
|
+
o.preventDefault(), t();
|
|
82
|
+
return;
|
|
83
|
+
case "CapsLock":
|
|
84
|
+
o.preventDefault(), s();
|
|
85
|
+
return;
|
|
86
|
+
default:
|
|
87
|
+
u.length === 1 && (o.preventDefault(), l(u));
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
return document.addEventListener("keydown", c), () => {
|
|
91
|
+
document.removeEventListener("keydown", c);
|
|
92
|
+
};
|
|
93
|
+
}, [e, r, n, t, s, l]);
|
|
94
|
+
}
|
|
95
|
+
const X = 38, Z = 20, _ = "vk-keyboard-shift-transition", R = 300;
|
|
96
|
+
let g = [], D = !1;
|
|
97
|
+
function q() {
|
|
98
|
+
if (D) return;
|
|
99
|
+
const e = document.createElement("style");
|
|
100
|
+
e.id = "vk-keyboard-shift-styles", e.textContent = `
|
|
101
|
+
.${_} {
|
|
102
|
+
transition: transform ${R}ms ease-out;
|
|
103
|
+
will-change: transform;
|
|
104
|
+
}
|
|
105
|
+
`, document.head.appendChild(e), D = !0;
|
|
106
|
+
}
|
|
107
|
+
function Q(e) {
|
|
108
|
+
var r;
|
|
109
|
+
return e ? Array.from(((r = e.parentElement) == null ? void 0 : r.children) ?? []).filter(
|
|
110
|
+
(n) => {
|
|
111
|
+
if (n === e) return !1;
|
|
112
|
+
const { position: t } = window.getComputedStyle(n);
|
|
113
|
+
return t !== "fixed" && t !== "absolute";
|
|
114
|
+
}
|
|
115
|
+
) : [];
|
|
116
|
+
}
|
|
117
|
+
function W(e) {
|
|
118
|
+
const r = e.getBoundingClientRect().bottom, n = window.innerHeight * (1 - X / 100), t = r + Z - n;
|
|
119
|
+
return t > 0 ? t : 0;
|
|
120
|
+
}
|
|
121
|
+
function J(e, r) {
|
|
122
|
+
g.length > 0 && C();
|
|
123
|
+
const n = W(e);
|
|
124
|
+
if (n === 0) return;
|
|
125
|
+
const t = Q(r);
|
|
126
|
+
if (t.length !== 0) {
|
|
127
|
+
q(), g = t;
|
|
128
|
+
for (const s of t)
|
|
129
|
+
s.classList.add(_), s.style.transform = `translateY(-${n}px)`;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
function C() {
|
|
133
|
+
if (g.length === 0) return;
|
|
134
|
+
for (const r of g)
|
|
135
|
+
document.body.contains(r) && (r.style.transform = "translateY(0)");
|
|
136
|
+
const e = [...g];
|
|
137
|
+
setTimeout(() => {
|
|
138
|
+
for (const r of e)
|
|
139
|
+
document.body.contains(r) && r.classList.remove(_);
|
|
140
|
+
}, R), g = [];
|
|
141
|
+
}
|
|
142
|
+
function V(e) {
|
|
143
|
+
const r = k((t) => {
|
|
144
|
+
setTimeout(() => {
|
|
145
|
+
e != null && e.current && J(t, e.current);
|
|
146
|
+
}, 0);
|
|
147
|
+
}, [e]), n = k(() => {
|
|
148
|
+
C();
|
|
149
|
+
}, []);
|
|
150
|
+
return $(() => () => {
|
|
151
|
+
C();
|
|
152
|
+
}, []), {
|
|
153
|
+
scrollInput: r,
|
|
154
|
+
resetScroll: n
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
const ee = (e, r) => {
|
|
158
|
+
switch (r) {
|
|
159
|
+
case "number":
|
|
160
|
+
return /^[0-9]*$/.test(e);
|
|
161
|
+
case "email":
|
|
162
|
+
return /^[a-zA-Z0-9@._+-]*$/.test(e);
|
|
163
|
+
case "tel":
|
|
164
|
+
return /^[0-9+\-() ]*$/.test(e);
|
|
165
|
+
case "url":
|
|
166
|
+
return /^[a-zA-Z0-9:/._-]*$/.test(e);
|
|
167
|
+
case "password":
|
|
168
|
+
return !0;
|
|
169
|
+
default:
|
|
170
|
+
return !0;
|
|
171
|
+
}
|
|
172
|
+
}, K = (e, r) => e === "number" ? "numbers" : r, te = (e) => {
|
|
173
|
+
var r;
|
|
174
|
+
if (e.current) {
|
|
175
|
+
const n = e.current;
|
|
176
|
+
n.blur(), (r = n.form) == null || r.submit();
|
|
177
|
+
}
|
|
178
|
+
}, me = (e, r) => {
|
|
179
|
+
const n = e.current;
|
|
180
|
+
n && B(n, r);
|
|
181
|
+
}, M = (e) => {
|
|
182
|
+
const r = e.target, n = r.tagName === "INPUT";
|
|
183
|
+
if (r.tagName === "TEXTAREA")
|
|
184
|
+
return r;
|
|
185
|
+
if (n) {
|
|
186
|
+
const s = r;
|
|
187
|
+
return [
|
|
188
|
+
"checkbox",
|
|
189
|
+
"radio",
|
|
190
|
+
"range",
|
|
191
|
+
"date",
|
|
192
|
+
"time",
|
|
193
|
+
"color",
|
|
194
|
+
"month",
|
|
195
|
+
"week",
|
|
196
|
+
"file",
|
|
197
|
+
"hidden",
|
|
198
|
+
"submit",
|
|
199
|
+
"reset",
|
|
200
|
+
"button",
|
|
201
|
+
"image"
|
|
202
|
+
].includes(s.type) ? null : s;
|
|
203
|
+
}
|
|
204
|
+
return null;
|
|
205
|
+
}, ne = [
|
|
206
|
+
["1", "2", "3", "4", "5", "6", "7", "8", "9", "0"],
|
|
207
|
+
["q", "w", "e", "r", "t", "y", "u", "i", "o", "p"],
|
|
208
|
+
["a", "s", "d", "f", "g", "h", "j", "k", "l"],
|
|
209
|
+
["z", "x", "c", "v", "b", "n", "m"]
|
|
210
|
+
], se = [
|
|
211
|
+
["1", "2", "3", "4", "5", "6", "7", "8", "9", "0"],
|
|
212
|
+
["!", "@", "#", "$", "%", "^", "&", "*", "(", ")"],
|
|
213
|
+
["-", "_", "=", "+", "[", "]", "{", "}", "\\", "|"],
|
|
214
|
+
[";", ":", '"', "'", ",", ".", "<", ">", "/", "?"]
|
|
215
|
+
], re = [
|
|
216
|
+
["7", "8", "9", "#"],
|
|
217
|
+
["4", "5", "6", "-"],
|
|
218
|
+
["1", "2", "3"],
|
|
219
|
+
[",", "0", "."]
|
|
220
|
+
], ve = {
|
|
221
|
+
backgroundColor: "#1a1a1a",
|
|
222
|
+
keyColor: "#444444",
|
|
223
|
+
keyTextColor: "#ffffff",
|
|
224
|
+
keyActiveColor: "#666666",
|
|
225
|
+
keyHoverColor: "#555555",
|
|
226
|
+
activeStateColor: "#4a90e2",
|
|
227
|
+
keyBorderRadius: "0.5vw",
|
|
228
|
+
keyFontSize: "32px",
|
|
229
|
+
keyHeight: "100%"
|
|
230
|
+
}, U = (e) => /* @__PURE__ */ a(
|
|
231
|
+
"svg",
|
|
232
|
+
{
|
|
233
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
234
|
+
viewBox: "0 0 24 24",
|
|
235
|
+
fill: "currentColor",
|
|
236
|
+
width: "1em",
|
|
237
|
+
height: "1em",
|
|
238
|
+
...e,
|
|
239
|
+
children: /* @__PURE__ */ a("path", { d: "M22 3H7c-.69 0-1.23.35-1.59.88L0 12l5.41 8.11c.36.53.9.89 1.59.89h15c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zm0 16H7.07L2.4 12l4.66-7H22v14zm-11.59-2L14 13.41 17.59 17 19 15.59 15.41 12 19 8.41 17.59 7 14 10.59 10.41 7 9 8.41 12.59 12 9 15.59z" })
|
|
240
|
+
}
|
|
241
|
+
), j = (e) => /* @__PURE__ */ a(
|
|
242
|
+
"svg",
|
|
243
|
+
{
|
|
244
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
245
|
+
viewBox: "0 0 24 24",
|
|
246
|
+
fill: "currentColor",
|
|
247
|
+
width: "1em",
|
|
248
|
+
height: "1em",
|
|
249
|
+
...e,
|
|
250
|
+
children: /* @__PURE__ */ a("path", { d: "M19 7v4H5.83l3.58-3.59L8 6l-6 6 6 6 1.41-1.41L5.83 13H21V7z" })
|
|
251
|
+
}
|
|
252
|
+
), ce = (e) => /* @__PURE__ */ a(
|
|
253
|
+
"svg",
|
|
254
|
+
{
|
|
255
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
256
|
+
viewBox: "0 0 24 24",
|
|
257
|
+
fill: "currentColor",
|
|
258
|
+
width: "1em",
|
|
259
|
+
height: "1em",
|
|
260
|
+
...e,
|
|
261
|
+
children: /* @__PURE__ */ a("path", { d: "M18 9v4H6V9H4v6h16V9z" })
|
|
262
|
+
}
|
|
263
|
+
), oe = (e) => /* @__PURE__ */ a(
|
|
264
|
+
"svg",
|
|
265
|
+
{
|
|
266
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
267
|
+
viewBox: "0 0 24 24",
|
|
268
|
+
fill: "currentColor",
|
|
269
|
+
width: "1em",
|
|
270
|
+
height: "1em",
|
|
271
|
+
style: { transform: "rotate(270deg)" },
|
|
272
|
+
...e,
|
|
273
|
+
children: /* @__PURE__ */ a("path", { d: "M12 4l-1.41 1.41L16.17 11H4v2h12.17l-5.58 5.59L12 20l8-8z" })
|
|
274
|
+
}
|
|
275
|
+
), T = ({
|
|
276
|
+
type: e,
|
|
277
|
+
icon: r,
|
|
278
|
+
onClick: n,
|
|
279
|
+
extraClass: t = "",
|
|
280
|
+
text: s,
|
|
281
|
+
capsLock: l = !1,
|
|
282
|
+
enableContinuousPress: c = !1
|
|
283
|
+
}) => {
|
|
284
|
+
const o = e === "caps" && l, u = [
|
|
285
|
+
"vk-key",
|
|
286
|
+
`vk-key--${t}`,
|
|
287
|
+
o ? "vk-key--caps-active" : ""
|
|
288
|
+
].filter(Boolean).join(" "), f = F(n, {
|
|
289
|
+
initialDelay: 500,
|
|
290
|
+
interval: 50
|
|
291
|
+
}), d = c ? f : { onClick: n };
|
|
292
|
+
return /* @__PURE__ */ L(
|
|
293
|
+
"button",
|
|
294
|
+
{
|
|
295
|
+
type: "button",
|
|
296
|
+
className: u,
|
|
297
|
+
"data-testid": `${e}${o ? "-active" : ""}`,
|
|
298
|
+
"data-key": o ? `${e}-active` : e,
|
|
299
|
+
...d,
|
|
300
|
+
children: [
|
|
301
|
+
r && r,
|
|
302
|
+
s && /* @__PURE__ */ a("span", { className: "vk-key__text", children: s })
|
|
303
|
+
]
|
|
304
|
+
}
|
|
305
|
+
);
|
|
306
|
+
}, z = ({ keyValue: e, onClick: r, className: n = "" }) => {
|
|
307
|
+
const t = ["vk-key", n].filter(Boolean).join(" ");
|
|
308
|
+
return /* @__PURE__ */ a(
|
|
309
|
+
"button",
|
|
310
|
+
{
|
|
311
|
+
type: "button",
|
|
312
|
+
className: t,
|
|
313
|
+
onClick: () => r(e),
|
|
314
|
+
"data-testid": e,
|
|
315
|
+
children: e
|
|
316
|
+
}
|
|
317
|
+
);
|
|
318
|
+
}, O = ({ children: e, className: r = "" }) => {
|
|
319
|
+
const n = ["vk-row", r].filter(Boolean).join(" ");
|
|
320
|
+
return /* @__PURE__ */ a("div", { className: n, children: e });
|
|
321
|
+
}, le = ({
|
|
322
|
+
currentLayoutData: e,
|
|
323
|
+
onBackspace: r,
|
|
324
|
+
onEnter: n,
|
|
325
|
+
onKeyClick: t,
|
|
326
|
+
capsLock: s
|
|
327
|
+
}) => /* @__PURE__ */ a("div", { className: "vk-layout vk-layout--numbers", "data-testid": "keyboard-layout", children: e == null ? void 0 : e.map((l, c) => /* @__PURE__ */ L(O, { children: [
|
|
328
|
+
l == null ? void 0 : l.map((o, u) => /* @__PURE__ */ a(
|
|
329
|
+
z,
|
|
330
|
+
{
|
|
331
|
+
keyValue: o,
|
|
332
|
+
onClick: t
|
|
333
|
+
},
|
|
334
|
+
`num-${c}-${u}-${o}`
|
|
335
|
+
)),
|
|
336
|
+
c === 3 && /* @__PURE__ */ a(
|
|
337
|
+
T,
|
|
338
|
+
{
|
|
339
|
+
type: "enter",
|
|
340
|
+
icon: /* @__PURE__ */ a(j, {}),
|
|
341
|
+
onClick: n,
|
|
342
|
+
extraClass: "enter-num",
|
|
343
|
+
text: "Enter",
|
|
344
|
+
capsLock: s
|
|
345
|
+
},
|
|
346
|
+
"enter-num"
|
|
347
|
+
),
|
|
348
|
+
c === 2 && /* @__PURE__ */ a(
|
|
349
|
+
T,
|
|
350
|
+
{
|
|
351
|
+
type: "backspace",
|
|
352
|
+
icon: /* @__PURE__ */ a(U, {}),
|
|
353
|
+
onClick: r,
|
|
354
|
+
extraClass: "backspace-num",
|
|
355
|
+
text: "Backspace",
|
|
356
|
+
capsLock: s,
|
|
357
|
+
enableContinuousPress: !0
|
|
358
|
+
},
|
|
359
|
+
"backspace-num"
|
|
360
|
+
)
|
|
361
|
+
] }, `num-row-${c}`)) }), ae = ({
|
|
362
|
+
inputType: e,
|
|
363
|
+
currentLayoutData: r,
|
|
364
|
+
onBackspace: n,
|
|
365
|
+
onEnter: t,
|
|
366
|
+
onSpace: s,
|
|
367
|
+
onCapsToggle: l,
|
|
368
|
+
onLayoutToggle: c,
|
|
369
|
+
onKeyClick: o,
|
|
370
|
+
capsLock: u,
|
|
371
|
+
currentLayout: f
|
|
372
|
+
}) => {
|
|
373
|
+
const d = (m) => {
|
|
374
|
+
switch (m) {
|
|
375
|
+
case 3:
|
|
376
|
+
return f === "letters" && /* @__PURE__ */ a(
|
|
377
|
+
T,
|
|
378
|
+
{
|
|
379
|
+
type: "caps",
|
|
380
|
+
icon: /* @__PURE__ */ a(oe, {}),
|
|
381
|
+
onClick: l,
|
|
382
|
+
extraClass: "capsLock",
|
|
383
|
+
text: "Caps Lock",
|
|
384
|
+
capsLock: u
|
|
385
|
+
},
|
|
386
|
+
"caps"
|
|
387
|
+
);
|
|
388
|
+
default:
|
|
389
|
+
return null;
|
|
390
|
+
}
|
|
391
|
+
}, v = (m) => {
|
|
392
|
+
switch (m) {
|
|
393
|
+
case 3:
|
|
394
|
+
return /* @__PURE__ */ a(
|
|
395
|
+
T,
|
|
396
|
+
{
|
|
397
|
+
type: "backspace",
|
|
398
|
+
icon: /* @__PURE__ */ a(U, {}),
|
|
399
|
+
onClick: n,
|
|
400
|
+
extraClass: "backspace",
|
|
401
|
+
text: "Backspace",
|
|
402
|
+
enableContinuousPress: !0
|
|
403
|
+
},
|
|
404
|
+
"backspace"
|
|
405
|
+
);
|
|
406
|
+
default:
|
|
407
|
+
return null;
|
|
408
|
+
}
|
|
409
|
+
};
|
|
410
|
+
return /* @__PURE__ */ L("div", { className: "vk-layout vk-layout--text", "data-testid": "keyboard-layout", children: [
|
|
411
|
+
r == null ? void 0 : r.map((m, h) => /* @__PURE__ */ L(O, { children: [
|
|
412
|
+
d(h),
|
|
413
|
+
m.map((w, y) => {
|
|
414
|
+
const b = u ? w.toUpperCase() : w.toLowerCase();
|
|
415
|
+
return /* @__PURE__ */ a(
|
|
416
|
+
z,
|
|
417
|
+
{
|
|
418
|
+
keyValue: b,
|
|
419
|
+
onClick: o
|
|
420
|
+
},
|
|
421
|
+
`${h}-${y}-${w}`
|
|
422
|
+
);
|
|
423
|
+
}),
|
|
424
|
+
v(h)
|
|
425
|
+
] }, `row-${h}`)),
|
|
426
|
+
/* @__PURE__ */ L(O, { children: [
|
|
427
|
+
/* @__PURE__ */ a(
|
|
428
|
+
T,
|
|
429
|
+
{
|
|
430
|
+
type: "layout",
|
|
431
|
+
icon: f === "letters" ? "&123" : "ABC",
|
|
432
|
+
onClick: c,
|
|
433
|
+
extraClass: "layout",
|
|
434
|
+
text: ""
|
|
435
|
+
},
|
|
436
|
+
"layout"
|
|
437
|
+
),
|
|
438
|
+
e === "email" && /* @__PURE__ */ a(
|
|
439
|
+
T,
|
|
440
|
+
{
|
|
441
|
+
type: "dot",
|
|
442
|
+
onClick: () => o("."),
|
|
443
|
+
extraClass: "dot",
|
|
444
|
+
icon: "."
|
|
445
|
+
},
|
|
446
|
+
"dot"
|
|
447
|
+
),
|
|
448
|
+
/* @__PURE__ */ a(
|
|
449
|
+
T,
|
|
450
|
+
{
|
|
451
|
+
type: "space",
|
|
452
|
+
icon: /* @__PURE__ */ a(ce, {}),
|
|
453
|
+
onClick: s,
|
|
454
|
+
extraClass: "space",
|
|
455
|
+
text: "Space"
|
|
456
|
+
},
|
|
457
|
+
"space"
|
|
458
|
+
),
|
|
459
|
+
e === "email" && /* @__PURE__ */ a(
|
|
460
|
+
T,
|
|
461
|
+
{
|
|
462
|
+
type: "at",
|
|
463
|
+
icon: "@",
|
|
464
|
+
onClick: () => o("@"),
|
|
465
|
+
extraClass: "at",
|
|
466
|
+
text: ""
|
|
467
|
+
},
|
|
468
|
+
"at"
|
|
469
|
+
),
|
|
470
|
+
/* @__PURE__ */ a(
|
|
471
|
+
T,
|
|
472
|
+
{
|
|
473
|
+
type: "enter",
|
|
474
|
+
icon: /* @__PURE__ */ a(j, {}),
|
|
475
|
+
onClick: t,
|
|
476
|
+
extraClass: "enter",
|
|
477
|
+
text: "Enter"
|
|
478
|
+
},
|
|
479
|
+
"enter"
|
|
480
|
+
)
|
|
481
|
+
] })
|
|
482
|
+
] });
|
|
483
|
+
}, ue = ({
|
|
484
|
+
currentLayout: e,
|
|
485
|
+
capsLock: r,
|
|
486
|
+
onKeyClick: n,
|
|
487
|
+
onBackspace: t,
|
|
488
|
+
onEnter: s,
|
|
489
|
+
onSpace: l,
|
|
490
|
+
onCapsToggle: c,
|
|
491
|
+
onLayoutToggle: o,
|
|
492
|
+
inputType: u
|
|
493
|
+
}) => {
|
|
494
|
+
const f = e === "letters" ? ne : e === "symbols" ? se : re;
|
|
495
|
+
return e === "numbers" ? /* @__PURE__ */ a(
|
|
496
|
+
le,
|
|
497
|
+
{
|
|
498
|
+
currentLayoutData: f,
|
|
499
|
+
onBackspace: t,
|
|
500
|
+
onEnter: s,
|
|
501
|
+
onKeyClick: n,
|
|
502
|
+
capsLock: r,
|
|
503
|
+
currentLayout: e
|
|
504
|
+
}
|
|
505
|
+
) : /* @__PURE__ */ a(
|
|
506
|
+
ae,
|
|
507
|
+
{
|
|
508
|
+
inputType: u,
|
|
509
|
+
currentLayoutData: f,
|
|
510
|
+
onBackspace: t,
|
|
511
|
+
onEnter: s,
|
|
512
|
+
onSpace: l,
|
|
513
|
+
onCapsToggle: c,
|
|
514
|
+
onLayoutToggle: o,
|
|
515
|
+
onKeyClick: n,
|
|
516
|
+
capsLock: r,
|
|
517
|
+
currentLayout: e
|
|
518
|
+
}
|
|
519
|
+
);
|
|
520
|
+
}, ie = ({
|
|
521
|
+
children: e,
|
|
522
|
+
className: r = ""
|
|
523
|
+
}) => {
|
|
524
|
+
const n = (l) => {
|
|
525
|
+
l.preventDefault();
|
|
526
|
+
}, t = (l) => {
|
|
527
|
+
l.preventDefault(), l.stopPropagation();
|
|
528
|
+
}, s = ["vk-container", r].filter(Boolean).join(" ");
|
|
529
|
+
return /* @__PURE__ */ a(
|
|
530
|
+
"div",
|
|
531
|
+
{
|
|
532
|
+
className: s,
|
|
533
|
+
onMouseDown: n,
|
|
534
|
+
onClick: t,
|
|
535
|
+
"data-testid": "keyboard-container",
|
|
536
|
+
children: e
|
|
537
|
+
}
|
|
538
|
+
);
|
|
539
|
+
}, de = ({
|
|
540
|
+
focusedInputRef: e,
|
|
541
|
+
isInputFocused: r,
|
|
542
|
+
inputType: n = "text",
|
|
543
|
+
onEnterClick: t,
|
|
544
|
+
onChange: s,
|
|
545
|
+
className: l,
|
|
546
|
+
defaultLayout: c = "letters",
|
|
547
|
+
validate: o
|
|
548
|
+
}) => {
|
|
549
|
+
const [u, f] = H(!1), { insertText: d, backspace: v } = Y(e), [m, h] = H(
|
|
550
|
+
() => K(n, c)
|
|
551
|
+
), w = k(
|
|
552
|
+
(p) => {
|
|
553
|
+
var x;
|
|
554
|
+
o && !o(p) || ee(p, n) && (d(p), s == null || s(((x = e.current) == null ? void 0 : x.value) ?? ""));
|
|
555
|
+
},
|
|
556
|
+
[e, n, d, s, o]
|
|
557
|
+
), y = k(
|
|
558
|
+
(p) => {
|
|
559
|
+
w(p);
|
|
560
|
+
},
|
|
561
|
+
[w]
|
|
562
|
+
), b = k(() => {
|
|
563
|
+
var p, x;
|
|
564
|
+
((p = e.current) == null ? void 0 : p.value.length) !== 0 && (v(), s == null || s(((x = e.current) == null ? void 0 : x.value) ?? ""));
|
|
565
|
+
}, [v, e, s]), S = k(() => {
|
|
566
|
+
t == null || t();
|
|
567
|
+
}, [t]), i = k(() => {
|
|
568
|
+
w(" ");
|
|
569
|
+
}, [w]), E = k(() => {
|
|
570
|
+
f((p) => !p);
|
|
571
|
+
}, []), I = k(() => {
|
|
572
|
+
n !== "number" && h((p) => p === "letters" ? "symbols" : "letters");
|
|
573
|
+
}, [n]);
|
|
574
|
+
$(() => {
|
|
575
|
+
h(K(n, c));
|
|
576
|
+
}, [n, c]);
|
|
577
|
+
const N = {
|
|
578
|
+
onBackspace: b,
|
|
579
|
+
onEnter: S,
|
|
580
|
+
onSpace: i,
|
|
581
|
+
onCapsToggle: E,
|
|
582
|
+
onKeyClick: y
|
|
583
|
+
};
|
|
584
|
+
return G({
|
|
585
|
+
isInputFocused: r,
|
|
586
|
+
...N
|
|
587
|
+
}), /* @__PURE__ */ a(ie, { className: l, children: /* @__PURE__ */ a(
|
|
588
|
+
ue,
|
|
589
|
+
{
|
|
590
|
+
currentLayout: m,
|
|
591
|
+
capsLock: u,
|
|
592
|
+
...N,
|
|
593
|
+
onLayoutToggle: I,
|
|
594
|
+
inputType: n
|
|
595
|
+
}
|
|
596
|
+
) });
|
|
597
|
+
}, he = ({
|
|
598
|
+
enabled: e = !0,
|
|
599
|
+
className: r,
|
|
600
|
+
onVisibilityChange: n,
|
|
601
|
+
onEnterClick: t,
|
|
602
|
+
onChange: s
|
|
603
|
+
}) => {
|
|
604
|
+
const l = A(null), [c, o] = H(!1), [u, f] = H("text"), d = A(null), v = A("text"), { scrollInput: m, resetScroll: h } = V(l);
|
|
605
|
+
$(() => {
|
|
606
|
+
if (!e) {
|
|
607
|
+
c && (setTimeout(() => {
|
|
608
|
+
o(!1);
|
|
609
|
+
}, 0), n == null || n(!1));
|
|
610
|
+
return;
|
|
611
|
+
}
|
|
612
|
+
const y = (S) => {
|
|
613
|
+
const i = M(S);
|
|
614
|
+
if (!i) return;
|
|
615
|
+
const E = i.tagName === "TEXTAREA", I = E ? "text" : i.type;
|
|
616
|
+
if (f(I), o(!0), n == null || n(!0), d.current = i, !E && (v.current = i.type, i.type !== "text")) {
|
|
617
|
+
const N = i.selectionStart, p = i.selectionEnd;
|
|
618
|
+
i.type = "text";
|
|
619
|
+
const x = N ?? i.value.length, P = p ?? x;
|
|
620
|
+
i.setSelectionRange(x, P);
|
|
621
|
+
}
|
|
622
|
+
m(i);
|
|
623
|
+
}, b = (S) => {
|
|
624
|
+
const i = M(S);
|
|
625
|
+
if (!i) return;
|
|
626
|
+
i.tagName === "TEXTAREA" || (i.type = v.current), d.current === i && (d.current = null, o(!1), n == null || n(!1), h());
|
|
627
|
+
};
|
|
628
|
+
return document.addEventListener("focusin", y, !0), document.addEventListener("focusout", b, !0), () => {
|
|
629
|
+
document.removeEventListener("focusin", y, !0), document.removeEventListener("focusout", b, !0);
|
|
630
|
+
};
|
|
631
|
+
}, [e, m, h, n]);
|
|
632
|
+
const w = () => {
|
|
633
|
+
o(!1), n == null || n(!1), te(d), t == null || t(), h();
|
|
634
|
+
};
|
|
635
|
+
return !c || !e ? null : /* @__PURE__ */ a("span", { ref: l, children: /* @__PURE__ */ a(
|
|
636
|
+
de,
|
|
637
|
+
{
|
|
638
|
+
focusedInputRef: d,
|
|
639
|
+
isInputFocused: c,
|
|
640
|
+
inputType: u,
|
|
641
|
+
onEnterClick: w,
|
|
642
|
+
onChange: s,
|
|
643
|
+
className: r
|
|
644
|
+
}
|
|
645
|
+
) });
|
|
646
|
+
};
|
|
647
|
+
export {
|
|
648
|
+
U as BackspaceIcon,
|
|
649
|
+
oe as CapsLockIcon,
|
|
650
|
+
ve as DEFAULT_THEME,
|
|
651
|
+
j as EnterIcon,
|
|
652
|
+
he as GlobalVirtualKeyboard,
|
|
653
|
+
ue as KeyboardLayout,
|
|
654
|
+
O as KeyboardRow,
|
|
655
|
+
re as NUMBERS_LAYOUT,
|
|
656
|
+
le as NumbersLayout,
|
|
657
|
+
ne as QWERTY_LAYOUT,
|
|
658
|
+
se as SYMBOLS_LAYOUT,
|
|
659
|
+
ce as SpacebarIcon,
|
|
660
|
+
T as SpecialKey,
|
|
661
|
+
ae as TextLayout,
|
|
662
|
+
z as VirtualKey,
|
|
663
|
+
de as VirtualKeyboard,
|
|
664
|
+
ie as VirtualKeyboardContainer,
|
|
665
|
+
K as getInitialLayout,
|
|
666
|
+
me as handleValueChangeUtil,
|
|
667
|
+
te as onEnterClickUtil,
|
|
668
|
+
C as resetScrollPosition,
|
|
669
|
+
J as scrollInputIntoView,
|
|
670
|
+
B as setInputValueAndDispatchEvents,
|
|
671
|
+
Y as useCaretManager,
|
|
672
|
+
F as useContinuousPress,
|
|
673
|
+
G as useHardwareKeyboard,
|
|
674
|
+
V as useKeyboardScroll,
|
|
675
|
+
M as validateFocusInputs,
|
|
676
|
+
ee as validateValueUtil
|
|
677
|
+
};
|
|
678
|
+
//# sourceMappingURL=index.esm.js.map
|