@uiwwsw/virtual-keyboard 0.5.1 → 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,9 +1051,16 @@ 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) => {
|
|
1063
|
+
e.preventDefault();
|
|
1046
1064
|
const press = activePresses.current.get(e.pointerId);
|
|
1047
1065
|
if (!press)
|
|
1048
1066
|
return;
|
|
@@ -1068,22 +1086,43 @@ function useKeypadInteraction({
|
|
|
1068
1086
|
startRepeat(newPress);
|
|
1069
1087
|
}
|
|
1070
1088
|
} else {
|
|
1071
|
-
|
|
1072
|
-
|
|
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
|
+
}
|
|
1073
1097
|
}
|
|
1074
1098
|
}, [clearRepeat, dispatchKeyEvent, startRepeat, keyBoundsRef]);
|
|
1075
1099
|
const handlePointerUp = useCallback3((e) => {
|
|
1100
|
+
e.preventDefault();
|
|
1076
1101
|
const press = activePresses.current.get(e.pointerId);
|
|
1077
1102
|
if (press) {
|
|
1078
1103
|
clearRepeat(press);
|
|
1079
1104
|
activePresses.current.delete(e.pointerId);
|
|
1080
1105
|
}
|
|
1081
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]);
|
|
1082
1120
|
return {
|
|
1083
1121
|
activePresses,
|
|
1084
1122
|
handlePointerDown,
|
|
1085
1123
|
handlePointerMove,
|
|
1086
|
-
handlePointerUp
|
|
1124
|
+
handlePointerUp,
|
|
1125
|
+
handlePointerCancel
|
|
1087
1126
|
};
|
|
1088
1127
|
}
|
|
1089
1128
|
|
|
@@ -1119,7 +1158,8 @@ function VirtualKeypad({
|
|
|
1119
1158
|
activePresses,
|
|
1120
1159
|
handlePointerDown,
|
|
1121
1160
|
handlePointerMove,
|
|
1122
|
-
handlePointerUp
|
|
1161
|
+
handlePointerUp,
|
|
1162
|
+
handlePointerCancel
|
|
1123
1163
|
} = useKeypadInteraction({
|
|
1124
1164
|
inputRef,
|
|
1125
1165
|
toggleShift,
|
|
@@ -1230,7 +1270,10 @@ function VirtualKeypad({
|
|
|
1230
1270
|
ctx.fillText(key.label, drawX + drawW / 2, drawY + drawH / 2);
|
|
1231
1271
|
});
|
|
1232
1272
|
}, [calculateLayout, hangulMode, shift, viewport.scale, activePresses, keyBoundsRef]);
|
|
1233
|
-
|
|
1273
|
+
useEffect4(() => {
|
|
1274
|
+
keyBoundsRef.current = [];
|
|
1275
|
+
}, [hangulMode, shift, keyBoundsRef]);
|
|
1276
|
+
useEffect4(() => {
|
|
1234
1277
|
let handle;
|
|
1235
1278
|
const loop = () => {
|
|
1236
1279
|
draw();
|
|
@@ -1251,7 +1294,9 @@ function VirtualKeypad({
|
|
|
1251
1294
|
box-shadow: 0 calc(-6px / var(--scale-factor)) calc(30px / var(--scale-factor)) rgba(15, 23, 42, 0.2);
|
|
1252
1295
|
user-select: none;
|
|
1253
1296
|
-webkit-user-select: none;
|
|
1254
|
-
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 */
|
|
1255
1300
|
z-index: 9999;
|
|
1256
1301
|
overflow: hidden; /* Canvas containment */
|
|
1257
1302
|
}
|
|
@@ -1259,6 +1304,7 @@ function VirtualKeypad({
|
|
|
1259
1304
|
display: block;
|
|
1260
1305
|
width: 100%;
|
|
1261
1306
|
height: 100%;
|
|
1307
|
+
touch-action: none; /* Extra safety */
|
|
1262
1308
|
}
|
|
1263
1309
|
`,
|
|
1264
1310
|
children: /* @__PURE__ */ jsxDEV3("div", {
|
|
@@ -1271,6 +1317,10 @@ function VirtualKeypad({
|
|
|
1271
1317
|
onBlur,
|
|
1272
1318
|
onContextMenu: (e) => e.preventDefault(),
|
|
1273
1319
|
onPointerDown: (e) => e.preventDefault(),
|
|
1320
|
+
onClickCapture: (e) => {
|
|
1321
|
+
e.preventDefault();
|
|
1322
|
+
e.stopPropagation();
|
|
1323
|
+
},
|
|
1274
1324
|
style: {
|
|
1275
1325
|
left: viewport.offsetLeft,
|
|
1276
1326
|
width: viewport.width,
|
|
@@ -1284,14 +1334,14 @@ function VirtualKeypad({
|
|
|
1284
1334
|
onPointerMove: handlePointerMove,
|
|
1285
1335
|
onPointerUp: handlePointerUp,
|
|
1286
1336
|
onPointerLeave: handlePointerUp,
|
|
1287
|
-
onPointerCancel:
|
|
1337
|
+
onPointerCancel: handlePointerCancel
|
|
1288
1338
|
}, undefined, false, undefined, this)
|
|
1289
1339
|
}, undefined, false, undefined, this)
|
|
1290
1340
|
}, undefined, false, undefined, this);
|
|
1291
1341
|
}
|
|
1292
1342
|
|
|
1293
1343
|
// src/hooks/useStorage.ts
|
|
1294
|
-
import { useState as useState3, useCallback as useCallback5, useEffect as
|
|
1344
|
+
import { useState as useState3, useCallback as useCallback5, useEffect as useEffect5 } from "react";
|
|
1295
1345
|
var isBrowser = typeof window !== "undefined";
|
|
1296
1346
|
function useStorage(key, initialValue) {
|
|
1297
1347
|
const [storedValue, setStoredValue] = useState3(() => {
|
|
@@ -1325,7 +1375,7 @@ function useStorage(key, initialValue) {
|
|
|
1325
1375
|
console.error(`Error setting localStorage key "${key}":`, error);
|
|
1326
1376
|
}
|
|
1327
1377
|
}, [key, storedValue]);
|
|
1328
|
-
|
|
1378
|
+
useEffect5(() => {
|
|
1329
1379
|
if (!isBrowser)
|
|
1330
1380
|
return;
|
|
1331
1381
|
const handleStorageChange = (event) => {
|
|
@@ -1393,7 +1443,7 @@ var qwerty_default = [
|
|
|
1393
1443
|
];
|
|
1394
1444
|
|
|
1395
1445
|
// src/hooks/useVisualViewport.ts
|
|
1396
|
-
import { useEffect as
|
|
1446
|
+
import { useEffect as useEffect6, useState as useState4 } from "react";
|
|
1397
1447
|
var getVisualViewport = () => {
|
|
1398
1448
|
if (typeof window !== "undefined" && window.visualViewport) {
|
|
1399
1449
|
return {
|
|
@@ -1415,7 +1465,7 @@ var getVisualViewport = () => {
|
|
|
1415
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;
|
|
1416
1466
|
var useVisualViewport = () => {
|
|
1417
1467
|
const [viewport, setViewport] = useState4(getVisualViewport);
|
|
1418
|
-
|
|
1468
|
+
useEffect6(() => {
|
|
1419
1469
|
if (typeof window === "undefined")
|
|
1420
1470
|
return;
|
|
1421
1471
|
let rafId = null;
|
|
@@ -1459,11 +1509,12 @@ function VirtualInputProvider({
|
|
|
1459
1509
|
}) {
|
|
1460
1510
|
const inputRef = useRef5(null);
|
|
1461
1511
|
const sti = useRef5(setTimeout(() => null, 0));
|
|
1512
|
+
const isCompositionRef = useRef5(undefined);
|
|
1462
1513
|
const [focusId, setFocusId] = useState5();
|
|
1463
1514
|
const [shift, setShift] = useState5(false);
|
|
1464
1515
|
const [hangulMode, setHangulMode] = useStorage("virtual-keyboard-hangul-mode", defaultHangulMode);
|
|
1465
1516
|
const viewport = useVisualViewport();
|
|
1466
|
-
|
|
1517
|
+
useEffect7(() => {
|
|
1467
1518
|
if (focusId) {
|
|
1468
1519
|
document.body.style.paddingBottom = `${Math.round(200 / viewport.scale)}px`;
|
|
1469
1520
|
} else {
|
|
@@ -1477,19 +1528,24 @@ function VirtualInputProvider({
|
|
|
1477
1528
|
clearTimeout(sti.current);
|
|
1478
1529
|
setFocusId(id);
|
|
1479
1530
|
};
|
|
1480
|
-
const onBlur = () => {
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
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]);
|
|
1486
1543
|
const toggleShift = useCallback6(() => {
|
|
1487
1544
|
setShift((prev) => !prev);
|
|
1488
1545
|
}, []);
|
|
1489
1546
|
const toggleKorean = useCallback6(() => {
|
|
1490
1547
|
setHangulMode((prev) => !prev);
|
|
1491
1548
|
}, [setHangulMode]);
|
|
1492
|
-
const isCompositionRef = useRef5(undefined);
|
|
1493
1549
|
return /* @__PURE__ */ jsxDEV4(VirtualInputContext.Provider, {
|
|
1494
1550
|
value: {
|
|
1495
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 {};
|