@uiwwsw/virtual-keyboard 0.5.2 → 0.5.3
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/dist/index.js
CHANGED
|
@@ -832,7 +832,15 @@ function VirtualInput({
|
|
|
832
832
|
}, [hangulMode, setHangulMode, isCompositionRef, shift, updateValue, hasSelection, deleteSelectedText, clearSelection]);
|
|
833
833
|
useImperativeHandle(inputRef, () => {
|
|
834
834
|
if (isFocused) {
|
|
835
|
-
return {
|
|
835
|
+
return {
|
|
836
|
+
handleKeyDown,
|
|
837
|
+
scrollIntoView: () => {
|
|
838
|
+
containerRef.current?.scrollIntoView({
|
|
839
|
+
behavior: "smooth",
|
|
840
|
+
block: "nearest"
|
|
841
|
+
});
|
|
842
|
+
}
|
|
843
|
+
};
|
|
836
844
|
}
|
|
837
845
|
return inputRef.current;
|
|
838
846
|
}, [isFocused, handleKeyDown, inputRef]);
|
|
@@ -860,9 +868,10 @@ function VirtualInput({
|
|
|
860
868
|
position: "relative"
|
|
861
869
|
},
|
|
862
870
|
onFocus: () => onFocus(id),
|
|
863
|
-
onBlur,
|
|
871
|
+
onBlur: (e) => onBlur(e),
|
|
864
872
|
onKeyDown: handleKeyDown,
|
|
865
873
|
onClick: handleCanvasClick,
|
|
874
|
+
"data-virtual-input": "true",
|
|
866
875
|
children: /* @__PURE__ */ jsxDEV2("canvas", {
|
|
867
876
|
ref: canvasRef
|
|
868
877
|
}, undefined, false, undefined, this)
|
|
@@ -874,13 +883,13 @@ import {
|
|
|
874
883
|
useState as useState5,
|
|
875
884
|
useRef as useRef5,
|
|
876
885
|
useCallback as useCallback6,
|
|
877
|
-
useEffect as
|
|
886
|
+
useEffect as useEffect7
|
|
878
887
|
} from "react";
|
|
879
888
|
|
|
880
889
|
// src/components/Keypad.tsx
|
|
881
890
|
import {
|
|
882
891
|
useCallback as useCallback4,
|
|
883
|
-
useEffect as
|
|
892
|
+
useEffect as useEffect4,
|
|
884
893
|
useRef as useRef4
|
|
885
894
|
} from "react";
|
|
886
895
|
|
|
@@ -964,7 +973,7 @@ function useKeypadLayout({
|
|
|
964
973
|
}
|
|
965
974
|
|
|
966
975
|
// src/hooks/useKeypadInteraction.ts
|
|
967
|
-
import { useCallback as useCallback3, useRef as useRef3, useMemo as useMemo2 } from "react";
|
|
976
|
+
import { useCallback as useCallback3, useRef as useRef3, useMemo as useMemo2, useEffect as useEffect3 } from "react";
|
|
968
977
|
function useKeypadInteraction({
|
|
969
978
|
inputRef,
|
|
970
979
|
toggleShift,
|
|
@@ -997,6 +1006,7 @@ function useKeypadInteraction({
|
|
|
997
1006
|
shiftKey: shift
|
|
998
1007
|
});
|
|
999
1008
|
inputRef.current?.handleKeyDown(event);
|
|
1009
|
+
inputRef.current?.scrollIntoView();
|
|
1000
1010
|
}, [getTransformedValue, inputRef, shift, toggleKorean, toggleShift]);
|
|
1001
1011
|
const clearRepeat = useCallback3((press) => {
|
|
1002
1012
|
if (!press?.repeatTimeout)
|
|
@@ -1025,6 +1035,7 @@ function useKeypadInteraction({
|
|
|
1025
1035
|
const canvas = e.currentTarget;
|
|
1026
1036
|
if (!canvas)
|
|
1027
1037
|
return;
|
|
1038
|
+
canvas.setPointerCapture(e.pointerId);
|
|
1028
1039
|
const rect = canvas.getBoundingClientRect();
|
|
1029
1040
|
const x = e.clientX - rect.left;
|
|
1030
1041
|
const y = e.clientY - rect.top;
|
|
@@ -1040,6 +1051,12 @@ function useKeypadInteraction({
|
|
|
1040
1051
|
};
|
|
1041
1052
|
activePresses.current.set(e.pointerId, press);
|
|
1042
1053
|
startRepeat(press);
|
|
1054
|
+
} else {
|
|
1055
|
+
activePresses.current.set(e.pointerId, {
|
|
1056
|
+
pointerId: e.pointerId,
|
|
1057
|
+
value: "",
|
|
1058
|
+
keyIndex: -1
|
|
1059
|
+
});
|
|
1043
1060
|
}
|
|
1044
1061
|
}, [dispatchKeyEvent, startRepeat, keyBoundsRef]);
|
|
1045
1062
|
const handlePointerMove = useCallback3((e) => {
|
|
@@ -1069,8 +1086,14 @@ function useKeypadInteraction({
|
|
|
1069
1086
|
startRepeat(newPress);
|
|
1070
1087
|
}
|
|
1071
1088
|
} else {
|
|
1072
|
-
|
|
1073
|
-
|
|
1089
|
+
if (press.keyIndex !== -1) {
|
|
1090
|
+
clearRepeat(press);
|
|
1091
|
+
activePresses.current.set(e.pointerId, {
|
|
1092
|
+
pointerId: e.pointerId,
|
|
1093
|
+
value: "",
|
|
1094
|
+
keyIndex: -1
|
|
1095
|
+
});
|
|
1096
|
+
}
|
|
1074
1097
|
}
|
|
1075
1098
|
}, [clearRepeat, dispatchKeyEvent, startRepeat, keyBoundsRef]);
|
|
1076
1099
|
const handlePointerUp = useCallback3((e) => {
|
|
@@ -1081,11 +1104,25 @@ function useKeypadInteraction({
|
|
|
1081
1104
|
activePresses.current.delete(e.pointerId);
|
|
1082
1105
|
}
|
|
1083
1106
|
}, [clearRepeat]);
|
|
1107
|
+
useEffect3(() => {
|
|
1108
|
+
return () => {
|
|
1109
|
+
activePresses.current.forEach((press) => {
|
|
1110
|
+
if (press.repeatTimeout) {
|
|
1111
|
+
window.clearTimeout(press.repeatTimeout);
|
|
1112
|
+
}
|
|
1113
|
+
});
|
|
1114
|
+
activePresses.current.clear();
|
|
1115
|
+
};
|
|
1116
|
+
}, []);
|
|
1117
|
+
const handlePointerCancel = useCallback3((e) => {
|
|
1118
|
+
handlePointerUp(e);
|
|
1119
|
+
}, [handlePointerUp]);
|
|
1084
1120
|
return {
|
|
1085
1121
|
activePresses,
|
|
1086
1122
|
handlePointerDown,
|
|
1087
1123
|
handlePointerMove,
|
|
1088
|
-
handlePointerUp
|
|
1124
|
+
handlePointerUp,
|
|
1125
|
+
handlePointerCancel
|
|
1089
1126
|
};
|
|
1090
1127
|
}
|
|
1091
1128
|
|
|
@@ -1121,7 +1158,8 @@ function VirtualKeypad({
|
|
|
1121
1158
|
activePresses,
|
|
1122
1159
|
handlePointerDown,
|
|
1123
1160
|
handlePointerMove,
|
|
1124
|
-
handlePointerUp
|
|
1161
|
+
handlePointerUp,
|
|
1162
|
+
handlePointerCancel
|
|
1125
1163
|
} = useKeypadInteraction({
|
|
1126
1164
|
inputRef,
|
|
1127
1165
|
toggleShift,
|
|
@@ -1232,7 +1270,10 @@ function VirtualKeypad({
|
|
|
1232
1270
|
ctx.fillText(key.label, drawX + drawW / 2, drawY + drawH / 2);
|
|
1233
1271
|
});
|
|
1234
1272
|
}, [calculateLayout, hangulMode, shift, viewport.scale, activePresses, keyBoundsRef]);
|
|
1235
|
-
|
|
1273
|
+
useEffect4(() => {
|
|
1274
|
+
keyBoundsRef.current = [];
|
|
1275
|
+
}, [hangulMode, shift, keyBoundsRef]);
|
|
1276
|
+
useEffect4(() => {
|
|
1236
1277
|
let handle;
|
|
1237
1278
|
const loop = () => {
|
|
1238
1279
|
draw();
|
|
@@ -1253,7 +1294,9 @@ function VirtualKeypad({
|
|
|
1253
1294
|
box-shadow: 0 calc(-6px / var(--scale-factor)) calc(30px / var(--scale-factor)) rgba(15, 23, 42, 0.2);
|
|
1254
1295
|
user-select: none;
|
|
1255
1296
|
-webkit-user-select: none;
|
|
1256
|
-
touch-action: none;
|
|
1297
|
+
touch-action: none; /* Critical for iOS */
|
|
1298
|
+
-webkit-touch-callout: none; /* Disable magnifier/menu */
|
|
1299
|
+
-webkit-tap-highlight-color: transparent; /* No gray tap box */
|
|
1257
1300
|
z-index: 9999;
|
|
1258
1301
|
overflow: hidden; /* Canvas containment */
|
|
1259
1302
|
}
|
|
@@ -1261,6 +1304,7 @@ function VirtualKeypad({
|
|
|
1261
1304
|
display: block;
|
|
1262
1305
|
width: 100%;
|
|
1263
1306
|
height: 100%;
|
|
1307
|
+
touch-action: none; /* Extra safety */
|
|
1264
1308
|
}
|
|
1265
1309
|
`,
|
|
1266
1310
|
children: /* @__PURE__ */ jsxDEV3("div", {
|
|
@@ -1273,6 +1317,10 @@ function VirtualKeypad({
|
|
|
1273
1317
|
onBlur,
|
|
1274
1318
|
onContextMenu: (e) => e.preventDefault(),
|
|
1275
1319
|
onPointerDown: (e) => e.preventDefault(),
|
|
1320
|
+
onClickCapture: (e) => {
|
|
1321
|
+
e.preventDefault();
|
|
1322
|
+
e.stopPropagation();
|
|
1323
|
+
},
|
|
1276
1324
|
style: {
|
|
1277
1325
|
left: viewport.offsetLeft,
|
|
1278
1326
|
width: viewport.width,
|
|
@@ -1286,14 +1334,14 @@ function VirtualKeypad({
|
|
|
1286
1334
|
onPointerMove: handlePointerMove,
|
|
1287
1335
|
onPointerUp: handlePointerUp,
|
|
1288
1336
|
onPointerLeave: handlePointerUp,
|
|
1289
|
-
onPointerCancel:
|
|
1337
|
+
onPointerCancel: handlePointerCancel
|
|
1290
1338
|
}, undefined, false, undefined, this)
|
|
1291
1339
|
}, undefined, false, undefined, this)
|
|
1292
1340
|
}, undefined, false, undefined, this);
|
|
1293
1341
|
}
|
|
1294
1342
|
|
|
1295
1343
|
// src/hooks/useStorage.ts
|
|
1296
|
-
import { useState as useState3, useCallback as useCallback5, useEffect as
|
|
1344
|
+
import { useState as useState3, useCallback as useCallback5, useEffect as useEffect5 } from "react";
|
|
1297
1345
|
var isBrowser = typeof window !== "undefined";
|
|
1298
1346
|
function useStorage(key, initialValue) {
|
|
1299
1347
|
const [storedValue, setStoredValue] = useState3(() => {
|
|
@@ -1327,7 +1375,7 @@ function useStorage(key, initialValue) {
|
|
|
1327
1375
|
console.error(`Error setting localStorage key "${key}":`, error);
|
|
1328
1376
|
}
|
|
1329
1377
|
}, [key, storedValue]);
|
|
1330
|
-
|
|
1378
|
+
useEffect5(() => {
|
|
1331
1379
|
if (!isBrowser)
|
|
1332
1380
|
return;
|
|
1333
1381
|
const handleStorageChange = (event) => {
|
|
@@ -1395,7 +1443,7 @@ var qwerty_default = [
|
|
|
1395
1443
|
];
|
|
1396
1444
|
|
|
1397
1445
|
// src/hooks/useVisualViewport.ts
|
|
1398
|
-
import { useEffect as
|
|
1446
|
+
import { useEffect as useEffect6, useState as useState4 } from "react";
|
|
1399
1447
|
var getVisualViewport = () => {
|
|
1400
1448
|
if (typeof window !== "undefined" && window.visualViewport) {
|
|
1401
1449
|
return {
|
|
@@ -1417,7 +1465,7 @@ var getVisualViewport = () => {
|
|
|
1417
1465
|
var isSameViewport = (prev, next) => prev.width === next.width && prev.height === next.height && prev.scale === next.scale && prev.offsetLeft === next.offsetLeft && prev.offsetTop === next.offsetTop;
|
|
1418
1466
|
var useVisualViewport = () => {
|
|
1419
1467
|
const [viewport, setViewport] = useState4(getVisualViewport);
|
|
1420
|
-
|
|
1468
|
+
useEffect6(() => {
|
|
1421
1469
|
if (typeof window === "undefined")
|
|
1422
1470
|
return;
|
|
1423
1471
|
let rafId = null;
|
|
@@ -1461,11 +1509,12 @@ function VirtualInputProvider({
|
|
|
1461
1509
|
}) {
|
|
1462
1510
|
const inputRef = useRef5(null);
|
|
1463
1511
|
const sti = useRef5(setTimeout(() => null, 0));
|
|
1512
|
+
const isCompositionRef = useRef5(undefined);
|
|
1464
1513
|
const [focusId, setFocusId] = useState5();
|
|
1465
1514
|
const [shift, setShift] = useState5(false);
|
|
1466
1515
|
const [hangulMode, setHangulMode] = useStorage("virtual-keyboard-hangul-mode", defaultHangulMode);
|
|
1467
1516
|
const viewport = useVisualViewport();
|
|
1468
|
-
|
|
1517
|
+
useEffect7(() => {
|
|
1469
1518
|
if (focusId) {
|
|
1470
1519
|
document.body.style.paddingBottom = `${Math.round(200 / viewport.scale)}px`;
|
|
1471
1520
|
} else {
|
|
@@ -1479,19 +1528,24 @@ function VirtualInputProvider({
|
|
|
1479
1528
|
clearTimeout(sti.current);
|
|
1480
1529
|
setFocusId(id);
|
|
1481
1530
|
};
|
|
1482
|
-
const onBlur = () => {
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1531
|
+
const onBlur = useCallback6((e) => {
|
|
1532
|
+
if (e?.relatedTarget) {
|
|
1533
|
+
if (e.relatedTarget.getAttribute("data-virtual-input")) {
|
|
1534
|
+
return;
|
|
1535
|
+
}
|
|
1536
|
+
sti.current = setTimeout(() => {
|
|
1537
|
+
setFocusId(undefined);
|
|
1538
|
+
isCompositionRef.current = false;
|
|
1539
|
+
}, 0);
|
|
1540
|
+
return;
|
|
1541
|
+
}
|
|
1542
|
+
}, [setFocusId, isCompositionRef]);
|
|
1488
1543
|
const toggleShift = useCallback6(() => {
|
|
1489
1544
|
setShift((prev) => !prev);
|
|
1490
1545
|
}, []);
|
|
1491
1546
|
const toggleKorean = useCallback6(() => {
|
|
1492
1547
|
setHangulMode((prev) => !prev);
|
|
1493
1548
|
}, [setHangulMode]);
|
|
1494
|
-
const isCompositionRef = useRef5(undefined);
|
|
1495
1549
|
return /* @__PURE__ */ jsxDEV4(VirtualInputContext.Provider, {
|
|
1496
1550
|
value: {
|
|
1497
1551
|
inputRef,
|
|
@@ -4,7 +4,7 @@ interface VirtualInputContextValue {
|
|
|
4
4
|
inputRef: RefObject<VirtualInputHandle | null>;
|
|
5
5
|
isCompositionRef: RefObject<boolean | undefined>;
|
|
6
6
|
onFocus: (id: string) => void;
|
|
7
|
-
onBlur: () => void;
|
|
7
|
+
onBlur: (e?: React.FocusEvent) => void;
|
|
8
8
|
focusId: string | undefined;
|
|
9
9
|
setHangulMode: Dispatch<SetStateAction<boolean>>;
|
|
10
10
|
hangulMode: boolean;
|
|
@@ -25,5 +25,6 @@ export declare function useKeypadInteraction({ inputRef, toggleShift, toggleKore
|
|
|
25
25
|
handlePointerDown: (e: React.PointerEvent<HTMLCanvasElement>) => void;
|
|
26
26
|
handlePointerMove: (e: React.PointerEvent<HTMLCanvasElement>) => void;
|
|
27
27
|
handlePointerUp: (e: React.PointerEvent<HTMLCanvasElement>) => void;
|
|
28
|
+
handlePointerCancel: (e: React.PointerEvent<HTMLCanvasElement>) => void;
|
|
28
29
|
};
|
|
29
30
|
export {};
|