@uiwwsw/virtual-keyboard 0.5.6 → 0.5.7
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
|
@@ -13,22 +13,23 @@ import {
|
|
|
13
13
|
import { useEffect, useState, memo } from "react";
|
|
14
14
|
import ReactDOM from "react-dom";
|
|
15
15
|
import { jsxDEV, Fragment } from "react/jsx-dev-runtime";
|
|
16
|
-
var ShadowWrapper = memo(({
|
|
17
|
-
children,
|
|
18
|
-
css,
|
|
19
|
-
tagName
|
|
20
|
-
}) => {
|
|
16
|
+
var ShadowWrapper = memo((props) => {
|
|
21
17
|
const [host, setHost] = useState(null);
|
|
22
18
|
const [shadowRoot, setShadowRoot] = useState(null);
|
|
19
|
+
const { tagName, css, children, hostRef, ...rest } = props;
|
|
23
20
|
const Component = tagName;
|
|
24
21
|
useEffect(() => {
|
|
25
22
|
if (host && !shadowRoot) {
|
|
26
23
|
const shadow = host.attachShadow({ mode: "open" });
|
|
27
24
|
setShadowRoot(shadow);
|
|
28
25
|
}
|
|
29
|
-
|
|
26
|
+
if (hostRef) {
|
|
27
|
+
hostRef.current = host;
|
|
28
|
+
}
|
|
29
|
+
}, [host, shadowRoot, hostRef]);
|
|
30
30
|
return /* @__PURE__ */ jsxDEV(Component, {
|
|
31
31
|
ref: setHost,
|
|
32
|
+
...rest,
|
|
32
33
|
children: shadowRoot && ReactDOM.createPortal(/* @__PURE__ */ jsxDEV(Fragment, {
|
|
33
34
|
children: [
|
|
34
35
|
css && /* @__PURE__ */ jsxDEV("style", {
|
|
@@ -875,36 +876,42 @@ function VirtualInput({
|
|
|
875
876
|
}, [isFocused, handleKeyDown, inputRef]);
|
|
876
877
|
return /* @__PURE__ */ jsxDEV2(ShadowWrapper, {
|
|
877
878
|
tagName: "virtual-input-canvas",
|
|
879
|
+
hostRef: containerRef,
|
|
880
|
+
id,
|
|
881
|
+
className: props.className,
|
|
882
|
+
role: "textbox",
|
|
883
|
+
tabIndex: 0,
|
|
884
|
+
...props,
|
|
885
|
+
style: {
|
|
886
|
+
display: "inline-block",
|
|
887
|
+
minHeight: "1.5em",
|
|
888
|
+
height: "1.5em",
|
|
889
|
+
outline: "none",
|
|
890
|
+
font: "inherit",
|
|
891
|
+
width: "100%",
|
|
892
|
+
position: "relative",
|
|
893
|
+
cursor: "text",
|
|
894
|
+
...props.style
|
|
895
|
+
},
|
|
896
|
+
onFocus: () => onFocus(id, containerRef.current),
|
|
897
|
+
onBlur: (e) => onBlur(e),
|
|
898
|
+
onKeyDown: handleKeyDown,
|
|
899
|
+
onClick: handleCanvasClick,
|
|
900
|
+
"data-virtual-input": "true",
|
|
878
901
|
css: `
|
|
902
|
+
:host {
|
|
903
|
+
display: inline-block;
|
|
904
|
+
position: relative;
|
|
905
|
+
}
|
|
879
906
|
canvas {
|
|
880
907
|
width: 100%;
|
|
881
908
|
height: 100%;
|
|
882
|
-
cursor: text;
|
|
883
909
|
display: block;
|
|
884
910
|
}
|
|
885
911
|
`,
|
|
886
|
-
children: /* @__PURE__ */ jsxDEV2("
|
|
887
|
-
ref:
|
|
888
|
-
|
|
889
|
-
role: "textbox",
|
|
890
|
-
tabIndex: 0,
|
|
891
|
-
style: {
|
|
892
|
-
minHeight: "1.5em",
|
|
893
|
-
height: "1.5em",
|
|
894
|
-
outline: "none",
|
|
895
|
-
font: "inherit",
|
|
896
|
-
width: "100%",
|
|
897
|
-
position: "relative",
|
|
898
|
-
...props.style
|
|
899
|
-
},
|
|
900
|
-
onFocus: () => onFocus(id),
|
|
901
|
-
onBlur: (e) => onBlur(e),
|
|
902
|
-
onKeyDown: handleKeyDown,
|
|
903
|
-
onClick: handleCanvasClick,
|
|
904
|
-
"data-virtual-input": "true",
|
|
905
|
-
children: /* @__PURE__ */ jsxDEV2("canvas", {
|
|
906
|
-
ref: canvasRef
|
|
907
|
-
}, undefined, false, undefined, this)
|
|
912
|
+
children: /* @__PURE__ */ jsxDEV2("canvas", {
|
|
913
|
+
ref: canvasRef,
|
|
914
|
+
style: { width: "100%", height: "100%", display: "block" }
|
|
908
915
|
}, undefined, false, undefined, this)
|
|
909
916
|
}, undefined, false, undefined, this);
|
|
910
917
|
}
|
|
@@ -917,11 +924,8 @@ import {
|
|
|
917
924
|
} from "react";
|
|
918
925
|
|
|
919
926
|
// src/components/Keypad.tsx
|
|
920
|
-
import {
|
|
921
|
-
|
|
922
|
-
useEffect as useEffect4,
|
|
923
|
-
useRef as useRef4
|
|
924
|
-
} from "react";
|
|
927
|
+
import { useRef as useRef4, useEffect as useEffect4, useCallback as useCallback4 } from "react";
|
|
928
|
+
import { createPortal } from "react-dom";
|
|
925
929
|
|
|
926
930
|
// src/utils/isMobileAgent.ts
|
|
927
931
|
function isMobileAgent(userAgent = navigator.userAgent) {
|
|
@@ -1331,61 +1335,59 @@ function VirtualKeypad({
|
|
|
1331
1335
|
}, [draw]);
|
|
1332
1336
|
if (!focusId || !isMobileAgent())
|
|
1333
1337
|
return null;
|
|
1334
|
-
return /* @__PURE__ */ jsxDEV3(ShadowWrapper, {
|
|
1338
|
+
return createPortal(/* @__PURE__ */ jsxDEV3(ShadowWrapper, {
|
|
1335
1339
|
tagName: "virtual-keypad-canvas",
|
|
1340
|
+
hostRef: containerRef,
|
|
1341
|
+
style: {
|
|
1342
|
+
position: "fixed",
|
|
1343
|
+
bottom: 0,
|
|
1344
|
+
left: 0,
|
|
1345
|
+
right: 0,
|
|
1346
|
+
margin: "0 auto",
|
|
1347
|
+
width: viewport.width,
|
|
1348
|
+
height: Math.round(200 / viewport.scale),
|
|
1349
|
+
backgroundColor: theme === "dark" ? "#0f172a" : "#e2e8f0",
|
|
1350
|
+
borderRadius: `calc(18px / ${viewport.scale}) calc(18px / ${viewport.scale}) 0 0`,
|
|
1351
|
+
boxShadow: `0 calc(-6px / ${viewport.scale}) calc(30px / ${viewport.scale}) rgba(15, 23, 42, 0.2)`,
|
|
1352
|
+
zIndex: 9999,
|
|
1353
|
+
overflow: "hidden",
|
|
1354
|
+
userSelect: "none",
|
|
1355
|
+
touchAction: "none",
|
|
1356
|
+
"--scale-factor": viewport.scale,
|
|
1357
|
+
"--keypad-bg": theme === "dark" ? "#0f172a" : "#e2e8f0"
|
|
1358
|
+
},
|
|
1359
|
+
onFocus: () => {
|
|
1360
|
+
if (focusId)
|
|
1361
|
+
onFocus(focusId);
|
|
1362
|
+
},
|
|
1363
|
+
onBlur,
|
|
1364
|
+
onContextMenu: (e) => e.preventDefault(),
|
|
1365
|
+
onPointerDown: (e) => e.preventDefault(),
|
|
1366
|
+
onClickCapture: (e) => {
|
|
1367
|
+
e.preventDefault();
|
|
1368
|
+
e.stopPropagation();
|
|
1369
|
+
},
|
|
1336
1370
|
css: `
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
}
|
|
1356
|
-
`,
|
|
1357
|
-
children: /* @__PURE__ */ jsxDEV3("div", {
|
|
1358
|
-
ref: containerRef,
|
|
1359
|
-
className: "keypad-wrapper",
|
|
1360
|
-
onFocus: () => {
|
|
1361
|
-
if (focusId)
|
|
1362
|
-
onFocus(focusId);
|
|
1363
|
-
},
|
|
1364
|
-
onBlur,
|
|
1365
|
-
onContextMenu: (e) => e.preventDefault(),
|
|
1366
|
-
onPointerDown: (e) => e.preventDefault(),
|
|
1367
|
-
onClickCapture: (e) => {
|
|
1368
|
-
e.preventDefault();
|
|
1369
|
-
e.stopPropagation();
|
|
1370
|
-
},
|
|
1371
|
-
style: {
|
|
1372
|
-
left: viewport.offsetLeft,
|
|
1373
|
-
width: viewport.width,
|
|
1374
|
-
top: Math.round(viewport.offsetTop + viewport.height - 200 / viewport.scale),
|
|
1375
|
-
height: Math.round(200 / viewport.scale),
|
|
1376
|
-
"--scale-factor": viewport.scale,
|
|
1377
|
-
"--keypad-bg": theme === "dark" ? "#0f172a" : "#e2e8f0"
|
|
1378
|
-
},
|
|
1379
|
-
children: /* @__PURE__ */ jsxDEV3("canvas", {
|
|
1380
|
-
ref: canvasRef,
|
|
1381
|
-
onPointerDown: handlePointerDown,
|
|
1382
|
-
onPointerMove: handlePointerMove,
|
|
1383
|
-
onPointerUp: handlePointerUp,
|
|
1384
|
-
onPointerLeave: handlePointerUp,
|
|
1385
|
-
onPointerCancel: handlePointerCancel
|
|
1386
|
-
}, undefined, false, undefined, this)
|
|
1371
|
+
:host {
|
|
1372
|
+
display: block;
|
|
1373
|
+
}
|
|
1374
|
+
canvas {
|
|
1375
|
+
display: block;
|
|
1376
|
+
width: 100%;
|
|
1377
|
+
height: 100%;
|
|
1378
|
+
touch-action: none;
|
|
1379
|
+
}
|
|
1380
|
+
`,
|
|
1381
|
+
children: /* @__PURE__ */ jsxDEV3("canvas", {
|
|
1382
|
+
ref: canvasRef,
|
|
1383
|
+
onPointerDown: handlePointerDown,
|
|
1384
|
+
onPointerMove: handlePointerMove,
|
|
1385
|
+
onPointerUp: handlePointerUp,
|
|
1386
|
+
onPointerLeave: handlePointerUp,
|
|
1387
|
+
onPointerCancel: handlePointerCancel,
|
|
1388
|
+
style: { width: "100%", height: "100%", display: "block" }
|
|
1387
1389
|
}, undefined, false, undefined, this)
|
|
1388
|
-
}, undefined, false, undefined, this);
|
|
1390
|
+
}, undefined, false, undefined, this), document.body);
|
|
1389
1391
|
}
|
|
1390
1392
|
|
|
1391
1393
|
// src/hooks/useStorage.ts
|
|
@@ -1587,21 +1589,36 @@ function VirtualInputProvider({
|
|
|
1587
1589
|
const viewport = useVisualViewport();
|
|
1588
1590
|
const systemTheme = useSystemTheme();
|
|
1589
1591
|
const effectiveTheme = theme ?? systemTheme;
|
|
1592
|
+
const focusedElementRef = useRef5(null);
|
|
1590
1593
|
useEffect8(() => {
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1594
|
+
if (focusId && focusedElementRef.current) {
|
|
1595
|
+
const paddingBottom = Math.round(200 / viewport.scale);
|
|
1596
|
+
document.body.style.paddingBottom = `${paddingBottom}px`;
|
|
1597
|
+
setTimeout(() => {
|
|
1598
|
+
const el = focusedElementRef.current;
|
|
1599
|
+
if (el) {
|
|
1600
|
+
const rect = el.getBoundingClientRect();
|
|
1601
|
+
const scrollTop = window.scrollY || document.documentElement.scrollTop;
|
|
1602
|
+
const elementTop = rect.top + scrollTop;
|
|
1603
|
+
const availableHeight = viewport.height - paddingBottom;
|
|
1604
|
+
const targetScroll = elementTop - availableHeight / 2 + rect.height / 2;
|
|
1605
|
+
window.scrollTo({
|
|
1606
|
+
top: targetScroll,
|
|
1607
|
+
behavior: "smooth"
|
|
1608
|
+
});
|
|
1609
|
+
}
|
|
1610
|
+
}, 100);
|
|
1596
1611
|
} else {
|
|
1597
1612
|
document.body.style.paddingBottom = "0px";
|
|
1598
1613
|
}
|
|
1599
1614
|
return () => {
|
|
1600
1615
|
document.body.style.paddingBottom = "0px";
|
|
1601
1616
|
};
|
|
1602
|
-
}, [focusId, viewport.scale]);
|
|
1603
|
-
const onFocus = (id) => {
|
|
1617
|
+
}, [focusId, viewport.scale, viewport.height, viewport.offsetTop]);
|
|
1618
|
+
const onFocus = (id, target) => {
|
|
1604
1619
|
clearTimeout(sti.current);
|
|
1620
|
+
if (target)
|
|
1621
|
+
focusedElementRef.current = target;
|
|
1605
1622
|
setFocusId(id);
|
|
1606
1623
|
};
|
|
1607
1624
|
const onBlur = useCallback6((e) => {
|
|
@@ -3,7 +3,7 @@ import type { VirtualInputHandle } from "./Input";
|
|
|
3
3
|
interface VirtualInputContextValue {
|
|
4
4
|
inputRef: RefObject<VirtualInputHandle | null>;
|
|
5
5
|
isCompositionRef: RefObject<boolean | undefined>;
|
|
6
|
-
onFocus: (id: string) => void;
|
|
6
|
+
onFocus: (id: string, target?: HTMLElement | null) => void;
|
|
7
7
|
onBlur: (e?: React.FocusEvent | boolean) => void;
|
|
8
8
|
focusId: string | undefined;
|
|
9
9
|
setHangulMode: Dispatch<SetStateAction<boolean>>;
|
|
@@ -4,8 +4,9 @@
|
|
|
4
4
|
* @param css 스타일을 문자열로 받아서 <style>로 삽입
|
|
5
5
|
* @returns Shadow DOM 안에 children과 style을 렌더링
|
|
6
6
|
*/
|
|
7
|
-
export declare const ShadowWrapper: import("react").MemoExoticComponent<(
|
|
7
|
+
export declare const ShadowWrapper: import("react").MemoExoticComponent<(props: {
|
|
8
8
|
children: React.ReactNode;
|
|
9
9
|
css?: string;
|
|
10
|
-
tagName:
|
|
11
|
-
|
|
10
|
+
tagName: string;
|
|
11
|
+
hostRef?: React.MutableRefObject<HTMLElement | null>;
|
|
12
|
+
} & React.HTMLAttributes<HTMLElement>) => import("react/jsx-runtime").JSX.Element>;
|