mirror of
https://github.com/hodgef/simple-keyboard.git
synced 2026-08-02 00:00:07 +08:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5e3a0370fd | ||
|
|
48ea08bd54 | ||
|
|
a1eb827494 | ||
|
|
53a4e93ba7 | ||
|
|
91f5ba8112 | ||
|
|
057e5397ae | ||
|
|
9501b41e6f | ||
|
|
2e1606eff4 | ||
|
|
2644e29378 | ||
|
|
b99f834235 | ||
|
|
7c115f10b4 | ||
|
|
8d3ae7e9e2 | ||
|
|
36c4a3ac32 | ||
|
|
5658ad1c90 | ||
|
|
e0c795d87c | ||
|
|
0c8cbff3aa | ||
|
|
633c30cb2c | ||
|
|
5ef0ae458e | ||
|
|
97e6becd55 | ||
|
|
2276f0baab | ||
|
|
a7d0ff02d3 | ||
|
|
0e2409da63 | ||
|
|
7821adafe3 | ||
|
|
19a1d3827b | ||
|
|
ec66cfc007 | ||
|
|
cb1c598432 | ||
|
|
fe277755be | ||
|
|
4398d502cd | ||
|
|
74470295f7 | ||
|
|
507d4f9988 | ||
|
|
e91124abb6 | ||
|
|
6b9cb301fc | ||
|
|
74b2563e73 | ||
|
|
f0e7ec77c1 | ||
|
|
e0fb48c032 | ||
|
|
74d51cf174 | ||
|
|
30a0ffd785 | ||
|
|
d39ffae6d0 | ||
|
|
d919d3f110 | ||
|
|
ae788bb73b | ||
|
|
4a6e01ed43 | ||
|
|
9ce1ddc4ee | ||
|
|
caf8b08a43 | ||
|
|
fb0dbf1911 | ||
|
|
bf37ce784e | ||
|
|
3850d7f0af | ||
|
|
c0be6b2ff3 | ||
|
|
17167b7881 | ||
|
|
b6d2ee257c | ||
|
|
bd863e25ac | ||
|
|
66e43be7a7 | ||
|
|
70544c8349 | ||
|
|
1540abf99b | ||
|
|
8f4446ff26 | ||
|
|
e0e79c46e6 | ||
|
|
440bdf4ef7 | ||
|
|
90921a9556 | ||
|
|
43c8291e01 | ||
|
|
976b81b659 | ||
|
|
d649dd8810 | ||
|
|
9d0e44b654 | ||
|
|
d61033054c | ||
|
|
ba2fa568d0 | ||
|
|
704fba1572 | ||
|
|
a7e1331330 | ||
|
|
7e03dd977d | ||
|
|
af81b5a35a | ||
|
|
b05e6aad0b | ||
|
|
385b5f388e | ||
|
|
5031cf1baa | ||
|
|
866299fa63 | ||
|
|
8f8e9b3d5b | ||
|
|
6bde6f37a1 | ||
|
|
a69f7daa7b | ||
|
|
fe020e2927 | ||
|
|
6bd4a90dc3 | ||
|
|
82c55810de | ||
|
|
e9bff33b53 | ||
|
|
3a2d60406a | ||
|
|
08c0a8a16f | ||
|
|
6bafd8b4bf | ||
|
|
e168d21e4a | ||
|
|
2462321161 | ||
|
|
7f9955af67 | ||
|
|
3c788addca | ||
|
|
732817f393 | ||
|
|
6ce9f414f7 | ||
|
|
5ba1711468 | ||
|
|
3f6aaeed3f | ||
|
|
3b5e530c63 | ||
|
|
9fc0a37c76 | ||
|
|
1c989a0e3a | ||
|
|
8d864aae9c | ||
|
|
24c884f388 | ||
|
|
d6f28ce46b | ||
|
|
39ccb17932 | ||
|
|
17c037fdd8 | ||
|
|
61defe10fd | ||
|
|
62f4d6d5c5 | ||
|
|
4ff6b6e1a6 | ||
|
|
0a55bcfa4b | ||
|
|
ed2123ccda | ||
|
|
3eca344155 | ||
|
|
e99c3a9685 | ||
|
|
c71588409b | ||
|
|
9db070ee3c | ||
|
|
685f0849ce | ||
|
|
e9daeef42e | ||
|
|
84ce45f271 | ||
|
|
4b3edbe761 | ||
|
|
1debb72a69 | ||
|
|
929eabbf21 | ||
|
|
7964b0e82c | ||
|
|
b11ba77ade | ||
|
|
b04442db6e | ||
|
|
d8dc00ecd4 | ||
|
|
7a3c125d59 | ||
|
|
2d09f136e3 | ||
|
|
80aebf7858 | ||
|
|
f0bac6de96 | ||
|
|
4186f26f8c | ||
|
|
2092c69d29 | ||
|
|
c6fa2a79b0 | ||
|
|
00bfbee197 | ||
|
|
8e0fd65583 | ||
|
|
8b267d27fc | ||
|
|
46b2f81e64 | ||
|
|
f324bf6e70 | ||
|
|
507c18c0e6 | ||
|
|
42f755a4ca | ||
|
|
f020bd01b0 | ||
|
|
9c46c9f252 | ||
|
|
00fa9f70cb | ||
|
|
2aa7e86b5f | ||
|
|
3988d0056c | ||
|
|
c581a72f10 | ||
|
|
2b20524561 | ||
|
|
a1b9ad999e | ||
|
|
200de2be2e | ||
|
|
883a9db8c6 | ||
|
|
72cf32ef39 | ||
|
|
ed36cbbe8a | ||
|
|
c07555b290 | ||
|
|
3a010aa05a | ||
|
|
5cdcba23e0 | ||
|
|
d440ffc9c9 | ||
|
|
6a9aa9919c | ||
|
|
b9b07bd49a | ||
|
|
d82a4837cb | ||
|
|
e030f9de95 | ||
|
|
2bd2be0aa9 | ||
|
|
12e2da945f | ||
|
|
26c0966600 | ||
|
|
84fc05ea4e | ||
|
|
2374735e73 | ||
|
|
431d43c64e | ||
|
|
e0ef0c650d | ||
|
|
06f088f74c | ||
|
|
3548484576 | ||
|
|
ea655f5958 | ||
|
|
9ee5d15539 | ||
|
|
ea46030c7e | ||
|
|
f9a952e6e0 | ||
|
|
c51eaf3827 | ||
|
|
7414f7c4a7 | ||
|
|
67fa6604c6 | ||
|
|
20a8b6f5c7 | ||
|
|
52428ff158 | ||
|
|
2812742468 | ||
|
|
225b78b20a | ||
|
|
ed00a405e1 | ||
|
|
d933ea3e70 | ||
|
|
87166620b3 | ||
|
|
0b98a41d7f | ||
|
|
7cd55e66b5 | ||
|
|
8007f73ede | ||
|
|
7d439739f9 | ||
|
|
13ba7d6935 | ||
|
|
755ace09b3 | ||
|
|
468ef6a508 | ||
|
|
b8a838eb1b | ||
|
|
803a324d9c | ||
|
|
2688075807 | ||
|
|
d15050219f | ||
|
|
ab941c35e0 | ||
|
|
9a1f4420af | ||
|
|
f959dababd | ||
|
|
f0e59919ef | ||
|
|
629f49184e | ||
|
|
f787cbe282 | ||
|
|
4ba42e293d | ||
|
|
25dd574f45 | ||
|
|
d3e00b320a | ||
|
|
e65a7e7be9 | ||
|
|
ed83621332 | ||
|
|
3856693f41 | ||
|
|
376731b6bb | ||
|
|
6e76dc7814 | ||
|
|
2cd5094e58 | ||
|
|
fd16382d98 | ||
|
|
d7bba4ce08 | ||
|
|
669b9b3bf9 | ||
|
|
1a36c63576 | ||
|
|
98d389080c | ||
|
|
96b83b9840 | ||
|
|
ecaa9acad9 | ||
|
|
cecef66b07 | ||
|
|
190fdf888a | ||
|
|
cde371dd83 | ||
|
|
b2872b7809 | ||
|
|
a198d02259 | ||
|
|
63f59f0f95 | ||
|
|
7a69e80052 | ||
|
|
9c56bb7ab2 | ||
|
|
52a1e269b1 | ||
|
|
5d75b72c65 | ||
|
|
c5579f09cb | ||
|
|
96b7019a2e | ||
|
|
2a6d7586a2 | ||
|
|
5c04d6aed4 | ||
|
|
adf749095b | ||
|
|
bc1b371415 | ||
|
|
413ad5c676 | ||
|
|
25e976fa91 | ||
|
|
075e6b25e3 | ||
|
|
4fe1a8bef9 | ||
|
|
060f73eb58 | ||
|
|
3cab9089c2 | ||
|
|
4dd493ea73 | ||
|
|
c3fc9192fa | ||
|
|
1147601610 | ||
|
|
89e985c866 | ||
|
|
2f195c01da | ||
|
|
4a4ae0da27 | ||
|
|
5e041edee7 | ||
|
|
7880eaa922 | ||
|
|
8540a6cd92 | ||
|
|
91010e34ae | ||
|
|
aafc599e5c | ||
|
|
a87009efd3 | ||
|
|
3c3a5bb995 | ||
|
|
2aaa387fdc | ||
|
|
a903e74436 | ||
|
|
3e99438ced | ||
|
|
fa76353604 | ||
|
|
af36febf54 | ||
|
|
66f86cb8d1 | ||
|
|
f1c5282151 | ||
|
|
a40ea7ea75 | ||
|
|
57d7b06a2d | ||
|
|
09a13725a4 | ||
|
|
9ace69a5db | ||
|
|
418e890b2d | ||
|
|
e49f06089f | ||
|
|
abc034c3c8 | ||
|
|
f05be41a9c | ||
|
|
f9caf3cbf2 | ||
|
|
e3107bda64 | ||
|
|
b104a052af | ||
|
|
ca18d4bf30 | ||
|
|
d02e2fa8e0 | ||
|
|
ee1800fb59 | ||
|
|
67b20ec622 | ||
|
|
65a506a2a4 | ||
|
|
f6a72b27b2 | ||
|
|
c44d6e3472 | ||
|
|
72470cdea5 | ||
|
|
fe53a2c2a7 | ||
|
|
c607a36715 | ||
|
|
bee4f56625 | ||
|
|
ef432aabbd | ||
|
|
adf1fe53c2 | ||
|
|
35ce8a30bb | ||
|
|
3391cf87ba | ||
|
|
de65760cf5 | ||
|
|
b669e5b188 | ||
|
|
3ad8a9f7fe | ||
|
|
08d212d76e | ||
|
|
c48ea82c9d | ||
|
|
069650efb4 | ||
|
|
609cd8ac39 | ||
|
|
216b0db69b | ||
|
|
bcc74dbd51 | ||
|
|
810d084e21 | ||
|
|
4d366525c1 | ||
|
|
4e799f66ac | ||
|
|
efe5a85ba7 | ||
|
|
f7c4e77c1a | ||
|
|
ab42eb268a | ||
|
|
bed0dc9127 | ||
|
|
950fe904a7 | ||
|
|
901b5791e6 | ||
|
|
d84db6f08b | ||
|
|
5f51c9640b | ||
|
|
807566cbdf | ||
|
|
c60f932b83 | ||
|
|
5e1df22e59 |
@@ -12,7 +12,7 @@ jobs:
|
||||
if: contains(github.ref, 'master')
|
||||
strategy:
|
||||
matrix:
|
||||
node-version: [16.x]
|
||||
node-version: [20.x]
|
||||
os: [ubuntu-latest]
|
||||
steps:
|
||||
- uses: actions/checkout@v1
|
||||
@@ -22,6 +22,7 @@ jobs:
|
||||
node-version: ${{ matrix.node_version }}
|
||||
- name: npm install, build, and test
|
||||
run: |
|
||||
export NODE_OPTIONS=--openssl-legacy-provider
|
||||
npm install
|
||||
npm run coverage
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ on:
|
||||
|
||||
jobs:
|
||||
mirroring:
|
||||
runs-on: ubuntu-18.04
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v1
|
||||
- uses: pixta-dev/repository-mirroring-action@v1
|
||||
|
||||
@@ -14,7 +14,7 @@ jobs:
|
||||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
matrix:
|
||||
node-version: [16.x]
|
||||
node-version: [20.x]
|
||||
os: [ubuntu-latest]
|
||||
steps:
|
||||
- uses: actions/checkout@v1
|
||||
@@ -25,6 +25,7 @@ jobs:
|
||||
|
||||
- name: npm install, build, and test
|
||||
run: |
|
||||
export NODE_OPTIONS=--openssl-legacy-provider
|
||||
npm install
|
||||
npm run test -- --coverage --watchAll=false
|
||||
|
||||
@@ -40,6 +41,7 @@ jobs:
|
||||
|
||||
- name: Bump version
|
||||
run: |
|
||||
export NODE_OPTIONS=--openssl-legacy-provider
|
||||
git reset --hard
|
||||
npm version patch
|
||||
npm run build
|
||||
@@ -51,6 +53,7 @@ jobs:
|
||||
|
||||
- name: npm publish
|
||||
run: |
|
||||
export NODE_OPTIONS=--openssl-legacy-provider
|
||||
npm config set //registry.npmjs.org/:_authToken=$NODE_AUTH_TOKEN
|
||||
npm run trypublish
|
||||
env:
|
||||
|
||||
@@ -8,7 +8,7 @@ jobs:
|
||||
if: ${{ github.actor != 'dependabot[bot]' }}
|
||||
strategy:
|
||||
matrix:
|
||||
node-version: [16.x]
|
||||
node-version: [20.x]
|
||||
os: [ubuntu-latest]
|
||||
steps:
|
||||
- uses: actions/checkout@v1
|
||||
@@ -18,6 +18,7 @@ jobs:
|
||||
node-version: ${{ matrix.node_version }}
|
||||
- name: npm install, build, and test
|
||||
run: |
|
||||
export NODE_OPTIONS=--openssl-legacy-provider
|
||||
npm install
|
||||
npm run coverage
|
||||
env:
|
||||
|
||||
@@ -8,7 +8,7 @@ jobs:
|
||||
if: ${{ github.actor == 'dependabot[bot]' }}
|
||||
strategy:
|
||||
matrix:
|
||||
node-version: [16.x]
|
||||
node-version: [20.x]
|
||||
os: [ubuntu-latest]
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
@@ -20,6 +20,7 @@ jobs:
|
||||
node-version: ${{ matrix.node_version }}
|
||||
- name: npm install, build, and test
|
||||
run: |
|
||||
export NODE_OPTIONS=--openssl-legacy-provider
|
||||
npm install
|
||||
npm run coverage
|
||||
env:
|
||||
|
||||
@@ -30,6 +30,9 @@ config
|
||||
.travis.yml
|
||||
CHANGELOG.md
|
||||
README.md
|
||||
CODE_OF_CONDUCT.md
|
||||
CONTRIBUTING.md
|
||||
tsconfig.json
|
||||
.eslintignore
|
||||
.eslintrc.json
|
||||
webpack.config.js
|
||||
|
||||
Vendored
+3
-2
@@ -1,12 +1,13 @@
|
||||
import "./css/CandidateBox.css";
|
||||
import Utilities from "../services/Utilities";
|
||||
import { CandidateBoxParams, CandidateBoxRenderParams, CandidateBoxShowParams } from "./../interfaces";
|
||||
import { CandidateBoxParams, CandidateBoxRenderParams, CandidateBoxShowParams, KeyboardOptions } from "./../interfaces";
|
||||
declare class CandidateBox {
|
||||
utilities: Utilities;
|
||||
options: KeyboardOptions;
|
||||
candidateBoxElement: HTMLDivElement;
|
||||
pageIndex: number;
|
||||
pageSize: number;
|
||||
constructor({ utilities }: CandidateBoxParams);
|
||||
constructor({ utilities, options }: CandidateBoxParams);
|
||||
destroy(): void;
|
||||
show({ candidateValue, targetElement, onSelect, }: CandidateBoxShowParams): void;
|
||||
renderPage({ candidateListPages, targetElement, pageIndex, nbPages, onItemSelected, }: CandidateBoxRenderParams): void;
|
||||
|
||||
Vendored
+2
-1
@@ -1,5 +1,6 @@
|
||||
import "./css/Keyboard.css";
|
||||
import PhysicalKeyboard from "../services/PhysicalKeyboard";
|
||||
import Utilities from "../services/Utilities";
|
||||
import { KeyboardOptions, KeyboardInput, KeyboardButtonElements, KeyboardHandlerEvent, KeyboardElement } from "../interfaces";
|
||||
import CandidateBox from "./CandidateBox";
|
||||
/**
|
||||
@@ -12,7 +13,7 @@ import CandidateBox from "./CandidateBox";
|
||||
declare class SimpleKeyboard {
|
||||
input: KeyboardInput;
|
||||
options: KeyboardOptions;
|
||||
utilities: any;
|
||||
utilities: Utilities;
|
||||
caretPosition: number | null;
|
||||
caretPositionEnd: number | null;
|
||||
keyboardDOM: KeyboardElement;
|
||||
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
/*!
|
||||
*
|
||||
* simple-keyboard v3.4.210
|
||||
* simple-keyboard v3.5.64
|
||||
* https://github.com/hodgef/simple-keyboard
|
||||
*
|
||||
* Copyright (c) Francisco Hodge (https://github.com/hodgef) and project contributors.
|
||||
@@ -8,4 +8,4 @@
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
*/.hg-theme-default{background-color:#ececec;border-radius:5px;box-sizing:border-box;font-family:HelveticaNeue-Light,Helvetica Neue Light,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif;overflow:hidden;padding:5px;touch-action:manipulation;-webkit-user-select:none;-moz-user-select:none;user-select:none;width:100%}.hg-theme-default .hg-button span{pointer-events:none}.hg-theme-default button.hg-button{border-width:0;font-size:inherit;outline:0}.hg-theme-default .hg-button{display:inline-block;flex-grow:1}.hg-theme-default .hg-row{display:flex}.hg-theme-default .hg-row:not(:last-child){margin-bottom:5px}.hg-theme-default .hg-row .hg-button-container,.hg-theme-default .hg-row .hg-button:not(:last-child){margin-right:5px}.hg-theme-default .hg-row>div:last-child{margin-right:0}.hg-theme-default .hg-row .hg-button-container{display:flex}.hg-theme-default .hg-button{-webkit-tap-highlight-color:rgba(0,0,0,0);align-items:center;background:#fff;border-bottom:1px solid #b5b5b5;border-radius:5px;box-shadow:0 0 3px -1px rgba(0,0,0,.3);box-sizing:border-box;cursor:pointer;display:flex;height:40px;justify-content:center;padding:5px}.hg-theme-default .hg-button.hg-standardBtn{width:20px}.hg-theme-default .hg-button.hg-activeButton{background:#efefef}.hg-theme-default.hg-layout-numeric .hg-button{align-items:center;display:flex;height:60px;justify-content:center;width:33.3%}.hg-theme-default .hg-button.hg-button-numpadadd,.hg-theme-default .hg-button.hg-button-numpadenter{height:85px}.hg-theme-default .hg-button.hg-button-numpad0{width:105px}.hg-theme-default .hg-button.hg-button-com{max-width:85px}.hg-theme-default .hg-button.hg-standardBtn.hg-button-at{max-width:45px}.hg-theme-default .hg-button.hg-selectedButton{background:rgba(5,25,70,.53);color:#fff}.hg-theme-default .hg-button.hg-standardBtn[data-skbtn=".com"]{max-width:82px}.hg-theme-default .hg-button.hg-standardBtn[data-skbtn="@"]{max-width:60px}.hg-candidate-box{background:#ececec;border-bottom:2px solid #b5b5b5;border-radius:5px;display:inline-flex;margin-top:-10px;max-width:272px;position:absolute;transform:translateY(-100%);-webkit-user-select:none;-moz-user-select:none;user-select:none}ul.hg-candidate-box-list{display:flex;flex:1;list-style:none;margin:0;padding:0}li.hg-candidate-box-list-item{align-items:center;display:flex;height:40px;justify-content:center;width:40px}li.hg-candidate-box-list-item:hover{background:rgba(0,0,0,.03);cursor:pointer}li.hg-candidate-box-list-item:active{background:rgba(0,0,0,.1)}.hg-candidate-box-prev:before{content:"◄"}.hg-candidate-box-next:before{content:"►"}.hg-candidate-box-next,.hg-candidate-box-prev{align-items:center;background:#d0d0d0;color:#969696;cursor:pointer;display:flex;padding:0 10px}.hg-candidate-box-next{border-bottom-right-radius:5px;border-top-right-radius:5px}.hg-candidate-box-prev{border-bottom-left-radius:5px;border-top-left-radius:5px}.hg-candidate-box-btn-active{color:#444}
|
||||
*/.hg-theme-default{background-color:#ececec;border-radius:5px;box-sizing:border-box;font-family:HelveticaNeue-Light,Helvetica Neue Light,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif;overflow:hidden;padding:5px;touch-action:manipulation;-webkit-user-select:none;-moz-user-select:none;user-select:none;width:100%}.hg-theme-default .hg-button span{pointer-events:none}.hg-theme-default button.hg-button{border-width:0;font-size:inherit;outline:0}.hg-theme-default .hg-button{display:inline-block;flex-grow:1}.hg-theme-default .hg-row{display:flex}.hg-theme-default .hg-row:not(:last-child){margin-bottom:5px}.hg-theme-default .hg-row .hg-button-container,.hg-theme-default .hg-row .hg-button:not(:last-child){margin-right:5px}.hg-theme-default .hg-row>div:last-child{margin-right:0}.hg-theme-default .hg-row .hg-button-container{display:flex}.hg-theme-default .hg-button{-webkit-tap-highlight-color:rgba(0,0,0,0);align-items:center;background:#fff;border-bottom:1px solid #b5b5b5;border-radius:5px;box-shadow:0 0 3px -1px rgba(0,0,0,.3);box-sizing:border-box;cursor:pointer;display:flex;height:40px;justify-content:center;padding:5px}.hg-theme-default .hg-button.hg-standardBtn{width:20px}.hg-theme-default .hg-button.hg-activeButton{background:#efefef}.hg-theme-default.hg-layout-numeric .hg-button{align-items:center;display:flex;height:60px;justify-content:center;width:33.3%}.hg-theme-default .hg-button.hg-button-numpadadd,.hg-theme-default .hg-button.hg-button-numpadenter{height:85px}.hg-theme-default .hg-button.hg-button-numpad0{width:105px}.hg-theme-default .hg-button.hg-button-com{max-width:85px}.hg-theme-default .hg-button.hg-standardBtn.hg-button-at{max-width:45px}.hg-theme-default .hg-button.hg-selectedButton{background:rgba(5,25,70,.53);color:#fff}.hg-theme-default .hg-button.hg-standardBtn[data-skbtn=".com"]{max-width:82px}.hg-theme-default .hg-button.hg-standardBtn[data-skbtn="@"]{max-width:60px}.hg-candidate-box{background:#ececec;border-bottom:2px solid #b5b5b5;border-radius:5px;display:inline-flex;margin-top:-10px;max-width:272px;position:absolute;transform:translateY(-100%);-webkit-user-select:none;-moz-user-select:none;user-select:none}ul.hg-candidate-box-list{display:flex;flex:1;list-style:none;margin:0;padding:0}li.hg-candidate-box-list-item{align-items:center;display:flex;height:40px;justify-content:center;width:40px}li.hg-candidate-box-list-item:hover{background:rgba(0,0,0,.03);cursor:pointer}li.hg-candidate-box-list-item:active{background:rgba(0,0,0,.1)}.hg-candidate-box-prev:before{content:"◄"}.hg-candidate-box-next:before{content:"►"}.hg-candidate-box-next,.hg-candidate-box-prev{align-items:center;color:#969696;cursor:pointer;display:flex;padding:0 10px}.hg-candidate-box-next{border-bottom-right-radius:5px;border-top-right-radius:5px}.hg-candidate-box-prev{border-bottom-left-radius:5px;border-top-left-radius:5px}.hg-candidate-box-btn-active{color:#444}
|
||||
+2
-2
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Vendored
+17
@@ -17,6 +17,7 @@ export interface KeyboardInput {
|
||||
}
|
||||
export type CandidateBoxParams = {
|
||||
utilities: Utilities;
|
||||
options: KeyboardOptions;
|
||||
};
|
||||
export type CandidateBoxShowParams = {
|
||||
candidateValue: string;
|
||||
@@ -128,6 +129,10 @@ export interface KeyboardOptions {
|
||||
* Define the background color that the physical keyboard highlighted key should have.
|
||||
*/
|
||||
physicalKeyboardHighlightBgColor?: string;
|
||||
/**
|
||||
* Whether physicalKeyboardHighlight should use preventDefault to disable default browser actions.
|
||||
*/
|
||||
physicalKeyboardHighlightPreventDefault?: boolean;
|
||||
/**
|
||||
* Calling preventDefault for the mousedown events keeps the focus on the input.
|
||||
*/
|
||||
@@ -204,6 +209,10 @@ export interface KeyboardOptions {
|
||||
* Disables the automatic normalization for selected layout candidates
|
||||
*/
|
||||
disableCandidateNormalization?: boolean;
|
||||
/**
|
||||
* Enables onKeyPress triggering for layoutCandidate items
|
||||
*/
|
||||
enableLayoutCandidatesKeyPress?: boolean;
|
||||
/**
|
||||
* Executes the callback function every time simple-keyboard is rendered (e.g: when you change layouts).
|
||||
*/
|
||||
@@ -220,6 +229,14 @@ export interface KeyboardOptions {
|
||||
* Retrieves all inputs
|
||||
*/
|
||||
onChangeAll?: (inputObj: KeyboardInput, e?: MouseEvent) => any;
|
||||
/**
|
||||
* Retrieves the pressed key
|
||||
*/
|
||||
onKeyPress?: (button: string, e?: MouseEvent) => any;
|
||||
/**
|
||||
* Retrieves the released key
|
||||
*/
|
||||
onKeyReleased?: (button: string, e?: MouseEvent) => any;
|
||||
/**
|
||||
* Module options can have any format
|
||||
*/
|
||||
|
||||
Vendored
+6
-5
@@ -9,16 +9,17 @@ declare class PhysicalKeyboard {
|
||||
* Creates an instance of the PhysicalKeyboard service
|
||||
*/
|
||||
constructor({ dispatch, getOptions }: PhysicalKeyboardParams);
|
||||
handleHighlightKeyDown(event: KeyboardEvent): void;
|
||||
handleHighlightKeyUp(event: KeyboardEvent): void;
|
||||
handleHighlightKeyDown(e: KeyboardEvent): void;
|
||||
handleHighlightKeyUp(e: KeyboardEvent): void;
|
||||
/**
|
||||
* Transforms a KeyboardEvent's "key.code" string into a simple-keyboard layout format
|
||||
* @param {object} event The KeyboardEvent
|
||||
* @param {object} e The KeyboardEvent
|
||||
*/
|
||||
getSimpleKeyboardLayoutKey(event: KeyboardEvent): string;
|
||||
getSimpleKeyboardLayoutKey(e: KeyboardEvent): string;
|
||||
/**
|
||||
* Retrieve key from keyCode
|
||||
*/
|
||||
keyCodeToKey(keyCode: number): string | undefined;
|
||||
keyCodeToKey(keyCode: number): string;
|
||||
isMofifierKey: (e: KeyboardEvent) => boolean;
|
||||
}
|
||||
export default PhysicalKeyboard;
|
||||
|
||||
Vendored
+2
-2
@@ -99,7 +99,7 @@ declare class Utilities {
|
||||
* @param {object} display The provided display option
|
||||
* @param {boolean} mergeDisplay Whether the provided param value should be merged with the default one.
|
||||
*/
|
||||
getButtonDisplayName(button: string, display: KeyboardOptions["display"], mergeDisplay: boolean): string;
|
||||
getButtonDisplayName(button: string, display: KeyboardOptions["display"], mergeDisplay?: boolean): string;
|
||||
/**
|
||||
* Returns the updated input resulting from clicking a given button
|
||||
*
|
||||
@@ -109,7 +109,7 @@ declare class Utilities {
|
||||
* @param {number} caretPosEnd The cursor's current end position
|
||||
* @param {boolean} moveCaret Whether to update simple-keyboard's cursor
|
||||
*/
|
||||
getUpdatedInput(button: string, input: string, caretPos: number, caretPosEnd?: number, moveCaret?: boolean): string;
|
||||
getUpdatedInput(button: string, input: string, caretPos: any, caretPosEnd?: any, moveCaret?: boolean): string;
|
||||
/**
|
||||
* Moves the cursor position by a given amount
|
||||
*
|
||||
|
||||
Generated
+2568
-1984
File diff suppressed because it is too large
Load Diff
+22
-22
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "simple-keyboard",
|
||||
"version": "3.4.210",
|
||||
"version": "3.6.0",
|
||||
"description": "On-screen Javascript Virtual Keyboard",
|
||||
"main": "build/index.js",
|
||||
"scripts": {
|
||||
@@ -40,35 +40,35 @@
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"@babel/cli": "^7.20.7",
|
||||
"@babel/core": "^7.20.5",
|
||||
"@babel/core": "^7.21.8",
|
||||
"@babel/plugin-proposal-class-properties": "^7.17.12",
|
||||
"@babel/plugin-transform-typescript": "^7.20.7",
|
||||
"@babel/plugin-transform-typescript": "^7.21.3",
|
||||
"@babel/polyfill": "^7.12.1",
|
||||
"@babel/preset-env": "^7.20.2",
|
||||
"@babel/preset-env": "^7.21.5",
|
||||
"@types/jest": "^27.5.0",
|
||||
"@typescript-eslint/eslint-plugin": "^5.45.1",
|
||||
"@typescript-eslint/parser": "^5.48.0",
|
||||
"autoprefixer": "^10.4.13",
|
||||
"@typescript-eslint/eslint-plugin": "^5.59.6",
|
||||
"@typescript-eslint/parser": "^5.59.7",
|
||||
"autoprefixer": "^10.4.14",
|
||||
"babel-eslint": "^10.1.0",
|
||||
"babel-loader": "^9.1.0",
|
||||
"babel-loader": "^9.1.2",
|
||||
"babel-preset-minify": "^0.5.2",
|
||||
"core-js": "^3.27.1",
|
||||
"css-loader": "^6.7.3",
|
||||
"css-minimizer-webpack-plugin": "^4.2.2",
|
||||
"eslint": "^8.31.0",
|
||||
"core-js": "^3.30.2",
|
||||
"css-loader": "^6.7.4",
|
||||
"css-minimizer-webpack-plugin": "^5.0.0",
|
||||
"eslint": "^8.41.0",
|
||||
"file-loader": "^6.2.0",
|
||||
"html-webpack-plugin": "^5.5.0",
|
||||
"html-webpack-plugin": "^5.5.1",
|
||||
"jest": "^26.6.3",
|
||||
"mini-css-extract-plugin": "^2.7.2",
|
||||
"postcss": "^8.4.20",
|
||||
"postcss-loader": "^7.0.2",
|
||||
"style-loader": "^3.3.1",
|
||||
"terser-webpack-plugin": "^5.3.6",
|
||||
"typescript": "^4.9.4",
|
||||
"mini-css-extract-plugin": "^2.7.6",
|
||||
"postcss": "^8.4.23",
|
||||
"postcss-loader": "^7.3.0",
|
||||
"style-loader": "^3.3.3",
|
||||
"terser-webpack-plugin": "^5.3.9",
|
||||
"typescript": "^4.9.5",
|
||||
"url-loader": "^4.1.1",
|
||||
"webpack": "^5.40.0",
|
||||
"webpack-cli": "^5.0.1",
|
||||
"webpack-dev-server": "4.11.1"
|
||||
"webpack": "^5.84.0",
|
||||
"webpack-cli": "^5.1.1",
|
||||
"webpack-dev-server": "4.15.0"
|
||||
},
|
||||
"jest": {
|
||||
"roots": [
|
||||
|
||||
@@ -5,16 +5,19 @@ import {
|
||||
CandidateBoxParams,
|
||||
CandidateBoxRenderParams,
|
||||
CandidateBoxShowParams,
|
||||
KeyboardOptions,
|
||||
} from "./../interfaces";
|
||||
|
||||
class CandidateBox {
|
||||
utilities: Utilities;
|
||||
options: KeyboardOptions;
|
||||
candidateBoxElement!: HTMLDivElement;
|
||||
pageIndex = 0;
|
||||
pageSize;
|
||||
pageSize: number;
|
||||
|
||||
constructor({ utilities }: CandidateBoxParams) {
|
||||
constructor({ utilities, options }: CandidateBoxParams) {
|
||||
this.utilities = utilities;
|
||||
this.options = options;
|
||||
Utilities.bindMethods(CandidateBox, this);
|
||||
this.pageSize = this.utilities.getOptions().layoutCandidatesPageSize || 5;
|
||||
}
|
||||
@@ -74,7 +77,7 @@ class CandidateBox {
|
||||
candidateListPages[pageIndex].forEach((candidateListItem) => {
|
||||
const candidateListLIElement = document.createElement("li");
|
||||
const getMouseEvent = () => {
|
||||
const mouseEvent = new MouseEvent("click");
|
||||
const mouseEvent = new (this.options.useTouchEvents ? TouchEvent : MouseEvent)("click");
|
||||
Object.defineProperty(mouseEvent, "target", {
|
||||
value: candidateListLIElement,
|
||||
});
|
||||
@@ -82,9 +85,15 @@ class CandidateBox {
|
||||
};
|
||||
|
||||
candidateListLIElement.className = "hg-candidate-box-list-item";
|
||||
candidateListLIElement.textContent = candidateListItem;
|
||||
candidateListLIElement.onclick = (e = getMouseEvent()) =>
|
||||
onItemSelected(candidateListItem, e);
|
||||
candidateListLIElement.innerHTML = this.options.display?.[candidateListItem] || candidateListItem;
|
||||
|
||||
if(this.options.useTouchEvents) {
|
||||
candidateListLIElement.ontouchstart = (e: any) =>
|
||||
onItemSelected(candidateListItem, e || getMouseEvent());
|
||||
} else {
|
||||
candidateListLIElement.onclick = (e = getMouseEvent() as MouseEvent) =>
|
||||
onItemSelected(candidateListItem, e);
|
||||
}
|
||||
|
||||
// Append list item to ul
|
||||
candidateListULElement.appendChild(candidateListLIElement);
|
||||
@@ -96,7 +105,8 @@ class CandidateBox {
|
||||
prevBtnElement.classList.add("hg-candidate-box-prev");
|
||||
isPrevBtnElementActive &&
|
||||
prevBtnElement.classList.add("hg-candidate-box-btn-active");
|
||||
prevBtnElement.onclick = () => {
|
||||
|
||||
const prevBtnElementClickAction = () => {
|
||||
if (!isPrevBtnElementActive) return;
|
||||
this.renderPage({
|
||||
candidateListPages,
|
||||
@@ -106,6 +116,13 @@ class CandidateBox {
|
||||
onItemSelected,
|
||||
});
|
||||
};
|
||||
|
||||
if(this.options.useTouchEvents) {
|
||||
prevBtnElement.ontouchstart = prevBtnElementClickAction;
|
||||
} else {
|
||||
prevBtnElement.onclick = prevBtnElementClickAction;
|
||||
}
|
||||
|
||||
this.candidateBoxElement.appendChild(prevBtnElement);
|
||||
|
||||
// Add elements to container
|
||||
@@ -118,7 +135,7 @@ class CandidateBox {
|
||||
isNextBtnElementActive &&
|
||||
nextBtnElement.classList.add("hg-candidate-box-btn-active");
|
||||
|
||||
nextBtnElement.onclick = () => {
|
||||
const nextBtnElementClickAction = () => {
|
||||
if (!isNextBtnElementActive) return;
|
||||
this.renderPage({
|
||||
candidateListPages,
|
||||
@@ -128,6 +145,13 @@ class CandidateBox {
|
||||
onItemSelected,
|
||||
});
|
||||
};
|
||||
|
||||
if(this.options.useTouchEvents) {
|
||||
nextBtnElement.ontouchstart = nextBtnElementClickAction;
|
||||
} else {
|
||||
nextBtnElement.onclick = nextBtnElementClickAction;
|
||||
}
|
||||
|
||||
this.candidateBoxElement.appendChild(nextBtnElement);
|
||||
|
||||
// Append candidate box to target element
|
||||
|
||||
@@ -23,7 +23,7 @@ import CandidateBox from "./CandidateBox";
|
||||
class SimpleKeyboard {
|
||||
input!: KeyboardInput;
|
||||
options!: KeyboardOptions;
|
||||
utilities: any;
|
||||
utilities!: Utilities;
|
||||
caretPosition!: number | null;
|
||||
caretPositionEnd!: number | null;
|
||||
keyboardDOM!: KeyboardElement;
|
||||
@@ -109,6 +109,7 @@ class SimpleKeyboard {
|
||||
* @property {string} physicalKeyboardHighlightBgColor Define the background color that the physical keyboard highlighted key should have.
|
||||
* @property {boolean} physicalKeyboardHighlightPressUseClick Whether physicalKeyboardHighlightPress should use clicks to trigger buttons.
|
||||
* @property {boolean} physicalKeyboardHighlightPressUsePointerEvents Whether physicalKeyboardHighlightPress should use pointer events to trigger buttons.
|
||||
* @property {boolean} physicalKeyboardHighlightPreventDefault Whether physicalKeyboardHighlight should use preventDefault to disable default browser actions.
|
||||
* @property {boolean} preventMouseDownDefault Calling preventDefault for the mousedown events keeps the focus on the input.
|
||||
* @property {boolean} preventMouseUpDefault Calling preventDefault for the mouseup events.
|
||||
* @property {boolean} stopMouseDownPropagation Stops pointer down events on simple-keyboard buttons from bubbling to parent elements.
|
||||
@@ -134,6 +135,7 @@ class SimpleKeyboard {
|
||||
* @property {number} layoutCandidatesPageSize Determines size of layout candidate list
|
||||
* @property {boolean} layoutCandidatesCaseSensitiveMatch Determines whether layout candidate match should be case sensitive.
|
||||
* @property {boolean} disableCandidateNormalization Disables the automatic normalization for selected layout candidates
|
||||
* @property {boolean} enableLayoutCandidatesKeyPress Enables onKeyPress triggering for layoutCandidate items
|
||||
*/
|
||||
this.options = {
|
||||
layoutName: "default",
|
||||
@@ -215,6 +217,7 @@ class SimpleKeyboard {
|
||||
this.candidateBox = this.options.enableLayoutCandidates
|
||||
? new CandidateBox({
|
||||
utilities: this.utilities,
|
||||
options: this.options,
|
||||
})
|
||||
: null;
|
||||
|
||||
@@ -375,7 +378,11 @@ class SimpleKeyboard {
|
||||
candidateValue,
|
||||
targetElement,
|
||||
onSelect: (selectedCandidate: string, e: MouseEvent) => {
|
||||
const { layoutCandidatesCaseSensitiveMatch, disableCandidateNormalization } = this.options;
|
||||
const {
|
||||
layoutCandidatesCaseSensitiveMatch,
|
||||
disableCandidateNormalization,
|
||||
enableLayoutCandidatesKeyPress
|
||||
} = this.options;
|
||||
|
||||
let candidateStr = selectedCandidate;
|
||||
|
||||
@@ -411,6 +418,14 @@ class SimpleKeyboard {
|
||||
this.setInput(newInput, this.options.inputName, true);
|
||||
this.setCaretPosition(newCaretPosition);
|
||||
|
||||
/**
|
||||
* Calling onKeyPress
|
||||
* We pass in the composed candidate instead of the decomposed one
|
||||
* To prevent confusion for users
|
||||
*/
|
||||
if (enableLayoutCandidatesKeyPress && typeof this.options.onKeyPress === "function")
|
||||
this.options.onKeyPress(selectedCandidate, e);
|
||||
|
||||
if (typeof this.options.onChange === "function")
|
||||
this.options.onChange(
|
||||
this.getInput(this.options.inputName, true),
|
||||
@@ -518,7 +533,8 @@ class SimpleKeyboard {
|
||||
"Caret at: ",
|
||||
this.getCaretPosition(),
|
||||
this.getCaretPositionEnd(),
|
||||
`(${this.keyboardDOMClass})`
|
||||
`(${this.keyboardDOMClass})`,
|
||||
e?.type
|
||||
);
|
||||
}
|
||||
|
||||
@@ -558,6 +574,22 @@ class SimpleKeyboard {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* After a button is clicked the selection (if any) will disappear
|
||||
* we should reflect this in our state, as applicable
|
||||
*/
|
||||
if(this.caretPositionEnd && this.caretPosition !== this.caretPositionEnd){
|
||||
this.setCaretPosition(this.caretPositionEnd, this.caretPositionEnd);
|
||||
|
||||
if(this.activeInputElement){
|
||||
this.activeInputElement.setSelectionRange(this.caretPositionEnd, this.caretPositionEnd);
|
||||
}
|
||||
|
||||
if(this.options.debug){
|
||||
console.log("Caret position aligned", this.caretPosition);
|
||||
}
|
||||
}
|
||||
|
||||
if (debug) {
|
||||
console.log("Key pressed:", button);
|
||||
}
|
||||
@@ -682,7 +714,7 @@ class SimpleKeyboard {
|
||||
* Calling onKeyReleased
|
||||
*/
|
||||
if (button && typeof this.options.onKeyReleased === "function")
|
||||
this.options.onKeyReleased(button);
|
||||
this.options.onKeyReleased(button, e);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -878,6 +910,7 @@ class SimpleKeyboard {
|
||||
this.candidateBox.destroy();
|
||||
this.candidateBox = new CandidateBox({
|
||||
utilities: this.utilities,
|
||||
options: this.options,
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1091,15 +1124,17 @@ class SimpleKeyboard {
|
||||
console.log(`Caret handling started (${this.keyboardDOMClass})`);
|
||||
}
|
||||
|
||||
const { physicalKeyboardHighlightPreventDefault = false } = this.options;
|
||||
|
||||
/**
|
||||
* Event Listeners
|
||||
*/
|
||||
document.addEventListener("keyup", this.handleKeyUp);
|
||||
document.addEventListener("keydown", this.handleKeyDown);
|
||||
document.addEventListener("keyup", this.handleKeyUp, physicalKeyboardHighlightPreventDefault);
|
||||
document.addEventListener("keydown", this.handleKeyDown, physicalKeyboardHighlightPreventDefault);
|
||||
document.addEventListener("mouseup", this.handleMouseUp);
|
||||
document.addEventListener("touchend", this.handleTouchEnd);
|
||||
document.addEventListener("select", this.handleSelect);
|
||||
document.addEventListener("selectionchange", this.handleSelectionChange);
|
||||
document.addEventListener("select", this.handleSelect);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1151,6 +1186,13 @@ class SimpleKeyboard {
|
||||
*/
|
||||
/* istanbul ignore next */
|
||||
handleSelectionChange(event: KeyboardHandlerEvent): void {
|
||||
/**
|
||||
* Firefox is not reporting the correct caret position through this event
|
||||
* https://github.com/hodgef/simple-keyboard/issues/1839
|
||||
*/
|
||||
if(navigator.userAgent.includes('Firefox')){
|
||||
return;
|
||||
}
|
||||
this.caretEventHandler(event);
|
||||
}
|
||||
|
||||
@@ -1211,7 +1253,8 @@ class SimpleKeyboard {
|
||||
instance.getCaretPosition(),
|
||||
instance.getCaretPositionEnd(),
|
||||
event && event.target.tagName.toLowerCase(),
|
||||
`(${instance.keyboardDOMClass})`
|
||||
`(${instance.keyboardDOMClass})`,
|
||||
event?.type
|
||||
);
|
||||
}
|
||||
} else if (
|
||||
@@ -1258,11 +1301,13 @@ class SimpleKeyboard {
|
||||
`Destroying simple-keyboard instance: ${this.currentInstanceName}`
|
||||
);
|
||||
|
||||
const { physicalKeyboardHighlightPreventDefault = false } = this.options;
|
||||
|
||||
/**
|
||||
* Remove document listeners
|
||||
*/
|
||||
document.removeEventListener("keyup", this.handleKeyUp);
|
||||
document.removeEventListener("keydown", this.handleKeyDown);
|
||||
document.removeEventListener("keyup", this.handleKeyUp, physicalKeyboardHighlightPreventDefault);
|
||||
document.removeEventListener("keydown", this.handleKeyDown, physicalKeyboardHighlightPreventDefault);
|
||||
document.removeEventListener("mouseup", this.handleMouseUp);
|
||||
document.removeEventListener("touchend", this.handleTouchEnd);
|
||||
document.removeEventListener("select", this.handleSelect);
|
||||
@@ -1719,7 +1764,7 @@ class SimpleKeyboard {
|
||||
* Iterating through each row
|
||||
*/
|
||||
layout[this.options.layoutName || this.defaultName].forEach(
|
||||
(row, rIndex) => {
|
||||
(row: string, rIndex: number) => {
|
||||
let rowArray = row.split(" ");
|
||||
|
||||
/**
|
||||
|
||||
@@ -48,7 +48,6 @@ li.hg-candidate-box-list-item:active {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
padding: 0 10px;
|
||||
background: #d0d0d0;
|
||||
color: #969696;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
@@ -1353,6 +1353,43 @@ it('Keyboard will handle selected input with unchanged updatedInput edge case',
|
||||
expect(keyboard.getCaretPositionEnd()).toBe(2);
|
||||
});
|
||||
|
||||
// https://github.com/hodgef/simple-keyboard/issues/1868
|
||||
it('Keyboard will handle caret pos sync after partially selected input resolution', () => {
|
||||
const inputElem = document.createElement("input");
|
||||
const onChange = jest.fn();
|
||||
const keyboard = new Keyboard({ onChange });
|
||||
|
||||
keyboard.getButtonElement("q").onpointerdown();
|
||||
keyboard.getButtonElement("w").onpointerdown();
|
||||
keyboard.getButtonElement("e").onpointerdown();
|
||||
keyboard.getButtonElement("r").onpointerdown();
|
||||
keyboard.getButtonElement("t").onpointerdown();
|
||||
keyboard.getButtonElement("y").onpointerdown();
|
||||
|
||||
inputElem.setSelectionRange(1, 2);
|
||||
keyboard.setCaretPosition(1, 2);
|
||||
|
||||
keyboard.getButtonElement("d").onpointerdown();
|
||||
keyboard.getButtonElement("d").onpointerdown();
|
||||
keyboard.getButtonElement("d").onpointerdown();
|
||||
|
||||
expect(keyboard.getInput()).toBe("qddderty");
|
||||
|
||||
inputElem.setSelectionRange(1, 2);
|
||||
keyboard.setCaretPosition(1, 2);
|
||||
|
||||
keyboard.getButtonElement("d").onpointerdown();
|
||||
expect(keyboard.getInput()).toBe("qddderty");
|
||||
|
||||
// caret position should now be synced
|
||||
expect(keyboard.getCaretPosition()).toBe(keyboard.getCaretPositionEnd());
|
||||
|
||||
keyboard.getButtonElement("d").onpointerdown();
|
||||
|
||||
expect(keyboard.getInput()).toBe("qdddderty");
|
||||
expect(keyboard.getCaretPosition()).toBe(3);
|
||||
});
|
||||
|
||||
it('Ensure caret position is offset when rtl option is enabled', () => {
|
||||
const keyboard = new Keyboard({
|
||||
useMouseEvents: true,
|
||||
|
||||
+22
-1
@@ -22,7 +22,8 @@ export interface KeyboardInput {
|
||||
}
|
||||
|
||||
export type CandidateBoxParams = {
|
||||
utilities: Utilities
|
||||
utilities: Utilities,
|
||||
options: KeyboardOptions
|
||||
}
|
||||
|
||||
export type CandidateBoxShowParams = {
|
||||
@@ -160,6 +161,11 @@ export interface KeyboardOptions {
|
||||
*/
|
||||
physicalKeyboardHighlightBgColor?: string;
|
||||
|
||||
/**
|
||||
* Whether physicalKeyboardHighlight should use preventDefault to disable default browser actions.
|
||||
*/
|
||||
physicalKeyboardHighlightPreventDefault?: boolean;
|
||||
|
||||
/**
|
||||
* Calling preventDefault for the mousedown events keeps the focus on the input.
|
||||
*/
|
||||
@@ -250,6 +256,11 @@ export interface KeyboardOptions {
|
||||
*/
|
||||
disableCandidateNormalization?: boolean;
|
||||
|
||||
/**
|
||||
* Enables onKeyPress triggering for layoutCandidate items
|
||||
*/
|
||||
enableLayoutCandidatesKeyPress?: boolean;
|
||||
|
||||
/**
|
||||
* Executes the callback function every time simple-keyboard is rendered (e.g: when you change layouts).
|
||||
*/
|
||||
@@ -270,6 +281,16 @@ export interface KeyboardOptions {
|
||||
*/
|
||||
onChangeAll?: (inputObj: KeyboardInput, e?: MouseEvent) => any;
|
||||
|
||||
/**
|
||||
* Retrieves the pressed key
|
||||
*/
|
||||
onKeyPress?: (button: string, e?: MouseEvent) => any;
|
||||
|
||||
/**
|
||||
* Retrieves the released key
|
||||
*/
|
||||
onKeyReleased?: (button: string, e?: MouseEvent) => any;
|
||||
|
||||
/**
|
||||
* Module options can have any format
|
||||
*/
|
||||
|
||||
@@ -24,9 +24,15 @@ class PhysicalKeyboard {
|
||||
Utilities.bindMethods(PhysicalKeyboard, this);
|
||||
}
|
||||
|
||||
handleHighlightKeyDown(event: KeyboardEvent) {
|
||||
handleHighlightKeyDown(e: KeyboardEvent) {
|
||||
const options = this.getOptions();
|
||||
const buttonPressed = this.getSimpleKeyboardLayoutKey(event);
|
||||
|
||||
if(options.physicalKeyboardHighlightPreventDefault && this.isMofifierKey(e)){
|
||||
e.preventDefault();
|
||||
e.stopImmediatePropagation();
|
||||
}
|
||||
|
||||
const buttonPressed = this.getSimpleKeyboardLayoutKey(e);
|
||||
|
||||
this.dispatch((instance: any) => {
|
||||
const standardButtonPressed = instance.getButtonElement(buttonPressed);
|
||||
@@ -34,7 +40,7 @@ class PhysicalKeyboard {
|
||||
`{${buttonPressed}}`
|
||||
);
|
||||
let buttonDOM;
|
||||
let buttonName;
|
||||
let buttonName: string;
|
||||
|
||||
if (standardButtonPressed) {
|
||||
buttonDOM = standardButtonPressed;
|
||||
@@ -46,38 +52,79 @@ class PhysicalKeyboard {
|
||||
return;
|
||||
}
|
||||
|
||||
if (buttonDOM) {
|
||||
buttonDOM.style.background =
|
||||
const applyButtonStyle = (buttonElement: HTMLElement) => {
|
||||
buttonElement.style.background =
|
||||
options.physicalKeyboardHighlightBgColor || "#dadce4";
|
||||
buttonDOM.style.color =
|
||||
buttonElement.style.color =
|
||||
options.physicalKeyboardHighlightTextColor || "black";
|
||||
}
|
||||
|
||||
if (options.physicalKeyboardHighlightPress) {
|
||||
if (options.physicalKeyboardHighlightPressUsePointerEvents) {
|
||||
buttonDOM.onpointerdown();
|
||||
} else if (options.physicalKeyboardHighlightPressUseClick) {
|
||||
buttonDOM.click();
|
||||
} else {
|
||||
instance.handleButtonClicked(buttonName, event);
|
||||
if (buttonDOM) {
|
||||
if(Array.isArray(buttonDOM)){
|
||||
buttonDOM.forEach(buttonElement => applyButtonStyle(buttonElement));
|
||||
|
||||
// Even though we have an array of buttons, we just want to press one of them
|
||||
if (options.physicalKeyboardHighlightPress) {
|
||||
if (options.physicalKeyboardHighlightPressUsePointerEvents) {
|
||||
buttonDOM[0]?.onpointerdown();
|
||||
} else if (options.physicalKeyboardHighlightPressUseClick) {
|
||||
buttonDOM[0]?.click();
|
||||
} else {
|
||||
instance.handleButtonClicked(buttonName, e);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
applyButtonStyle(buttonDOM);
|
||||
|
||||
if (options.physicalKeyboardHighlightPress) {
|
||||
if (options.physicalKeyboardHighlightPressUsePointerEvents) {
|
||||
buttonDOM.onpointerdown();
|
||||
} else if (options.physicalKeyboardHighlightPressUseClick) {
|
||||
buttonDOM.click();
|
||||
} else {
|
||||
instance.handleButtonClicked(buttonName, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
handleHighlightKeyUp(event: KeyboardEvent) {
|
||||
handleHighlightKeyUp(e: KeyboardEvent) {
|
||||
const options = this.getOptions();
|
||||
const buttonPressed = this.getSimpleKeyboardLayoutKey(event);
|
||||
|
||||
if(options.physicalKeyboardHighlightPreventDefault && this.isMofifierKey(e)){
|
||||
e.preventDefault();
|
||||
e.stopImmediatePropagation();
|
||||
}
|
||||
|
||||
const buttonPressed = this.getSimpleKeyboardLayoutKey(e);
|
||||
|
||||
this.dispatch((instance: any) => {
|
||||
const buttonDOM =
|
||||
instance.getButtonElement(buttonPressed) ||
|
||||
instance.getButtonElement(`{${buttonPressed}}`);
|
||||
|
||||
if (buttonDOM && buttonDOM.removeAttribute) {
|
||||
buttonDOM.removeAttribute("style");
|
||||
if (options.physicalKeyboardHighlightPressUsePointerEvents) {
|
||||
buttonDOM.onpointerup();
|
||||
const applyButtonStyle = (buttonElement: HTMLElement) => {
|
||||
if(buttonElement.removeAttribute){
|
||||
buttonElement.removeAttribute("style");
|
||||
}
|
||||
};
|
||||
|
||||
if (buttonDOM) {
|
||||
if(Array.isArray(buttonDOM)){
|
||||
buttonDOM.forEach(buttonElement => applyButtonStyle(buttonElement));
|
||||
|
||||
// Even though we have an array of buttons, we just want to press one of them
|
||||
if (options.physicalKeyboardHighlightPressUsePointerEvents) {
|
||||
buttonDOM[0]?.onpointerup();
|
||||
}
|
||||
} else {
|
||||
applyButtonStyle(buttonDOM);
|
||||
|
||||
if (options.physicalKeyboardHighlightPressUsePointerEvents) {
|
||||
buttonDOM.onpointerup();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -85,11 +132,11 @@ class PhysicalKeyboard {
|
||||
|
||||
/**
|
||||
* Transforms a KeyboardEvent's "key.code" string into a simple-keyboard layout format
|
||||
* @param {object} event The KeyboardEvent
|
||||
* @param {object} e The KeyboardEvent
|
||||
*/
|
||||
getSimpleKeyboardLayoutKey(event: KeyboardEvent) {
|
||||
getSimpleKeyboardLayoutKey(e: KeyboardEvent) {
|
||||
let output = "";
|
||||
const keyId = event.code || event.key || this.keyCodeToKey(event?.keyCode);
|
||||
const keyId = e.code || e.key || this.keyCodeToKey(e?.keyCode);
|
||||
|
||||
if (
|
||||
keyId?.includes("Numpad") ||
|
||||
@@ -100,9 +147,9 @@ class PhysicalKeyboard {
|
||||
keyId?.includes("Alt") ||
|
||||
keyId?.includes("Meta")
|
||||
) {
|
||||
output = event.code || "";
|
||||
output = e.code || "";
|
||||
} else {
|
||||
output = event.key || this.keyCodeToKey(event?.keyCode) || "";
|
||||
output = e.key || this.keyCodeToKey(e?.keyCode) || "";
|
||||
}
|
||||
|
||||
return output.length > 1 ? output?.toLowerCase() : output;
|
||||
@@ -111,7 +158,7 @@ class PhysicalKeyboard {
|
||||
/**
|
||||
* Retrieve key from keyCode
|
||||
*/
|
||||
keyCodeToKey(keyCode: number) {
|
||||
keyCodeToKey(keyCode: number): string {
|
||||
return {
|
||||
8: "Backspace",
|
||||
9: "Tab",
|
||||
@@ -210,7 +257,18 @@ class PhysicalKeyboard {
|
||||
220: "\\",
|
||||
221: "]",
|
||||
222: "'",
|
||||
}[keyCode];
|
||||
}[keyCode] || "";
|
||||
}
|
||||
|
||||
isMofifierKey = (e: KeyboardEvent): boolean => {
|
||||
return (
|
||||
e.altKey
|
||||
|| e.ctrlKey
|
||||
|| e.shiftKey
|
||||
|| ["Tab", "CapsLock", "Esc", "ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight"].includes(
|
||||
e.code || e.key || this.keyCodeToKey(e?.keyCode)
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -137,7 +137,7 @@ class Utilities {
|
||||
getButtonDisplayName(
|
||||
button: string,
|
||||
display: KeyboardOptions["display"],
|
||||
mergeDisplay: boolean
|
||||
mergeDisplay = false
|
||||
) {
|
||||
if (mergeDisplay) {
|
||||
display = Object.assign({}, this.getDefaultDiplay(), display);
|
||||
@@ -160,12 +160,12 @@ class Utilities {
|
||||
getUpdatedInput(
|
||||
button: string,
|
||||
input: string,
|
||||
caretPos: number,
|
||||
caretPos: any,
|
||||
caretPosEnd = caretPos,
|
||||
moveCaret = false
|
||||
) {
|
||||
const options = this.getOptions();
|
||||
const commonParams: [number, number, boolean] = [
|
||||
const commonParams: [number | undefined, number | undefined, boolean] = [
|
||||
caretPos,
|
||||
caretPosEnd,
|
||||
moveCaret,
|
||||
@@ -222,6 +222,10 @@ class Utilities {
|
||||
else if (!button.includes("{") && !button.includes("}"))
|
||||
output = this.addStringAt(output, button, ...commonParams);
|
||||
|
||||
if(options.debug){
|
||||
console.log("Input will be: "+ output);
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
@@ -34,6 +34,8 @@ module.exports = {
|
||||
libraryTarget: 'umd',
|
||||
clean: true,
|
||||
globalObject: 'this',
|
||||
hashFunction: 'xxhash64',
|
||||
chunkFormat: 'module',
|
||||
environment: {
|
||||
arrowFunction: false
|
||||
}
|
||||
|
||||
@@ -38,7 +38,9 @@ module.exports = {
|
||||
path: path.resolve(__dirname, 'build'),
|
||||
library: "SimpleKeyboard",
|
||||
libraryTarget: 'umd',
|
||||
globalObject: 'this'
|
||||
globalObject: 'this',
|
||||
hashFunction: 'xxhash64',
|
||||
chunkFormat: 'module',
|
||||
},
|
||||
optimization: {
|
||||
minimize: true,
|
||||
|
||||
Reference in New Issue
Block a user