mirror of
https://github.com/hodgef/simple-keyboard.git
synced 2026-07-14 00:00:06 +08:00
Compare commits
@@ -0,0 +1,17 @@
|
|||||||
|
# Number of days of inactivity before an issue becomes stale
|
||||||
|
daysUntilStale: 5
|
||||||
|
# Number of days of inactivity before a stale issue is closed
|
||||||
|
daysUntilClose: 2
|
||||||
|
# Issues with these labels will never be considered stale
|
||||||
|
exemptLabels:
|
||||||
|
- pinned
|
||||||
|
- security
|
||||||
|
# Label to use when marking an issue as stale
|
||||||
|
staleLabel: Stale
|
||||||
|
# Comment to post when marking an issue as stale. Set to `false` to disable
|
||||||
|
markComment: >
|
||||||
|
This issue has been automatically marked as stale because it has not had
|
||||||
|
recent activity. It will be closed if no further activity occurs. Thank you
|
||||||
|
for your contributions.
|
||||||
|
# Comment to post when closing a stale issue. Set to `false` to disable
|
||||||
|
closeComment: false
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
<p>
|
<p>
|
||||||
<a href="https://simple-keyboard.com/demo">
|
<a href="https://simple-keyboard.com/demo">
|
||||||
<img alt="simple-keyboard: Javscript Virtual Keyboard" src="https://i.imgur.com/Po6659n.gif">
|
<img alt="simple-keyboard: Javascript Virtual Keyboard" src="https://i.imgur.com/Po6659n.gif">
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
<a href="https://www.npmjs.com/package/simple-keyboard">
|
<a href="https://www.npmjs.com/package/simple-keyboard">
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
/*!
|
/*!
|
||||||
*
|
*
|
||||||
* simple-keyboard v2.30.1
|
* simple-keyboard v2.32.0
|
||||||
* https://github.com/hodgef/simple-keyboard
|
* https://github.com/hodgef/simple-keyboard
|
||||||
*
|
*
|
||||||
* Copyright (c) Francisco Hodge (https://github.com/hodgef)
|
* Copyright (c) Francisco Hodge (https://github.com/hodgef)
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
Vendored
+27
-7
@@ -88,14 +88,9 @@ declare module 'simple-keyboard' {
|
|||||||
physicalKeyboardHighlight?: boolean;
|
physicalKeyboardHighlight?: boolean;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calling preventDefault for the mousedown events keeps the focus on the input.
|
* Presses keys highlighted by physicalKeyboardHighlight
|
||||||
*/
|
*/
|
||||||
preventMouseDownDefault?: boolean;
|
physicalKeyboardHighlightPress?: boolean;
|
||||||
|
|
||||||
/**
|
|
||||||
* Stops pointer down events on simple-keyboard buttons from bubbling to parent elements.
|
|
||||||
*/
|
|
||||||
stopMouseDownPropagation?: boolean;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Define the text color that the physical keyboard highlighted key should have.
|
* Define the text color that the physical keyboard highlighted key should have.
|
||||||
@@ -107,6 +102,26 @@ declare module 'simple-keyboard' {
|
|||||||
*/
|
*/
|
||||||
physicalKeyboardHighlightBgColor?: string;
|
physicalKeyboardHighlightBgColor?: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calling preventDefault for the mousedown events keeps the focus on the input.
|
||||||
|
*/
|
||||||
|
preventMouseDownDefault?: boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calling preventDefault for the mouseup events.
|
||||||
|
*/
|
||||||
|
preventMouseUpDefault?: boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stops pointer down events on simple-keyboard buttons from bubbling to parent elements.
|
||||||
|
*/
|
||||||
|
stopMouseDownPropagation?: boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stops pointer up events on simple-keyboard buttons from bubbling to parent elements.
|
||||||
|
*/
|
||||||
|
stopMouseUpPropagation?: boolean;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Render buttons as a button element instead of a div element.
|
* Render buttons as a button element instead of a div element.
|
||||||
*/
|
*/
|
||||||
@@ -142,6 +157,11 @@ declare module 'simple-keyboard' {
|
|||||||
*/
|
*/
|
||||||
disableButtonHold?: boolean;
|
disableButtonHold?: boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds unicode right-to-left control characters to input return values.
|
||||||
|
*/
|
||||||
|
rtl?: boolean;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Executes the callback function on key press. Returns button layout name (i.e.: "{shift}").
|
* Executes the callback function on key press. Returns button layout name (i.e.: "{shift}").
|
||||||
*/
|
*/
|
||||||
|
|||||||
+2
-2
File diff suppressed because one or more lines are too long
+1
-1
File diff suppressed because one or more lines are too long
Generated
+3619
-1883
File diff suppressed because it is too large
Load Diff
+30
-30
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "simple-keyboard",
|
"name": "simple-keyboard",
|
||||||
"version": "2.30.1",
|
"version": "2.32.0",
|
||||||
"description": "On-screen Javascript Virtual Keyboard",
|
"description": "On-screen Javascript Virtual Keyboard",
|
||||||
"main": "build/index.js",
|
"main": "build/index.js",
|
||||||
"types": "build/index.d.ts",
|
"types": "build/index.d.ts",
|
||||||
@@ -40,70 +40,70 @@
|
|||||||
],
|
],
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@babel/core": "7.9.0",
|
"@babel/core": "7.12.3",
|
||||||
"@babel/plugin-proposal-class-properties": "^7.10.4",
|
"@babel/plugin-proposal-class-properties": "^7.12.1",
|
||||||
"@babel/preset-env": "^7.11.5",
|
"@babel/preset-env": "^7.12.1",
|
||||||
"@babel/preset-react": "^7.10.4",
|
"@babel/preset-react": "^7.12.1",
|
||||||
"@svgr/webpack": "5.4.0",
|
"@svgr/webpack": "5.4.0",
|
||||||
"@testing-library/jest-dom": "^4.2.4",
|
"@testing-library/jest-dom": "^5.11.4",
|
||||||
"@testing-library/react": "^9.3.2",
|
"@testing-library/react": "^11.1.0",
|
||||||
"@testing-library/user-event": "^7.1.2",
|
"@testing-library/user-event": "^12.1.8",
|
||||||
"@typescript-eslint/eslint-plugin": "^2.10.0",
|
"@typescript-eslint/eslint-plugin": "^2.10.0",
|
||||||
"@typescript-eslint/parser": "^2.10.0",
|
"@typescript-eslint/parser": "^2.10.0",
|
||||||
"babel-eslint": "^10.1.0",
|
"babel-eslint": "^10.1.0",
|
||||||
"babel-jest": "^26.3.0",
|
"babel-jest": "^26.6.0",
|
||||||
"babel-loader": "8.1.0",
|
"babel-loader": "8.1.0",
|
||||||
"babel-plugin-named-asset-import": "^0.3.6",
|
"babel-plugin-named-asset-import": "^0.3.6",
|
||||||
"babel-preset-react-app": "^9.1.2",
|
"babel-preset-react-app": "^9.1.2",
|
||||||
"camelcase": "^6.0.0",
|
"camelcase": "^6.1.0",
|
||||||
"case-sensitive-paths-webpack-plugin": "2.3.0",
|
"case-sensitive-paths-webpack-plugin": "2.3.0",
|
||||||
"copy-webpack-plugin": "^5.1.2",
|
"copy-webpack-plugin": "^5.1.2",
|
||||||
"css-loader": "4.2.2",
|
"css-loader": "5.0.0",
|
||||||
"dotenv": "8.2.0",
|
"dotenv": "8.2.0",
|
||||||
"dotenv-expand": "5.1.0",
|
"dotenv-expand": "5.1.0",
|
||||||
"eslint": "^6.8.0",
|
"eslint": "^6.8.0",
|
||||||
"eslint-config-react-app": "^5.0.1",
|
"eslint-config-react-app": "^5.0.1",
|
||||||
"eslint-loader": "4.0.2",
|
"eslint-loader": "4.0.2",
|
||||||
"eslint-plugin-flowtype": "4.7.0",
|
"eslint-plugin-flowtype": "4.7.0",
|
||||||
"eslint-plugin-import": "2.22.0",
|
"eslint-plugin-import": "2.22.1",
|
||||||
"eslint-plugin-jsx-a11y": "6.3.1",
|
"eslint-plugin-jsx-a11y": "6.3.1",
|
||||||
"eslint-plugin-react": "7.20.6",
|
"eslint-plugin-react": "7.21.4",
|
||||||
"eslint-plugin-react-hooks": "^4.1.0",
|
"eslint-plugin-react-hooks": "^4.1.2",
|
||||||
"file-loader": "6.1.0",
|
"file-loader": "6.1.1",
|
||||||
"fs-extra": "9.0.1",
|
"fs-extra": "9.0.1",
|
||||||
"html-webpack-plugin": "4.4.1",
|
"html-webpack-plugin": "4.5.0",
|
||||||
"identity-obj-proxy": "3.0.0",
|
"identity-obj-proxy": "3.0.0",
|
||||||
"jest": "26.4.2",
|
"jest": "26.6.0",
|
||||||
"jest-environment-jsdom-fourteen": "1.0.1",
|
"jest-environment-jsdom-fourteen": "1.0.1",
|
||||||
"jest-resolve": "26.4.0",
|
"jest-resolve": "26.6.0",
|
||||||
"jest-watch-typeahead": "0.6.0",
|
"jest-watch-typeahead": "0.6.1",
|
||||||
"mini-css-extract-plugin": "0.11.0",
|
"mini-css-extract-plugin": "1.1.0",
|
||||||
"optimize-css-assets-webpack-plugin": "5.0.4",
|
"optimize-css-assets-webpack-plugin": "5.0.4",
|
||||||
"pnp-webpack-plugin": "1.6.4",
|
"pnp-webpack-plugin": "1.6.4",
|
||||||
"postcss-flexbugs-fixes": "4.2.1",
|
"postcss-flexbugs-fixes": "4.2.1",
|
||||||
"postcss-loader": "3.0.0",
|
"postcss-loader": "3.0.0",
|
||||||
"postcss-normalize": "9.0.0",
|
"postcss-normalize": "9.0.0",
|
||||||
"postcss-preset-env": "6.7.0",
|
"postcss-preset-env": "6.7.0",
|
||||||
"postcss-safe-parser": "4.0.2",
|
"postcss-safe-parser": "5.0.2",
|
||||||
"prettier": "^1.19.1",
|
"prettier": "^1.19.1",
|
||||||
"prettier-webpack-plugin": "^1.2.0",
|
"prettier-webpack-plugin": "^1.2.0",
|
||||||
"react": "^16.13.1",
|
"react": "^16.14.0",
|
||||||
"react-app-polyfill": "^1.0.6",
|
"react-app-polyfill": "^1.0.6",
|
||||||
"react-dev-utils": "^10.2.1",
|
"react-dev-utils": "^10.2.1",
|
||||||
"react-dom": "^16.13.1",
|
"react-dom": "^16.14.0",
|
||||||
"resolve": "1.17.0",
|
"resolve": "1.18.1",
|
||||||
"resolve-url-loader": "3.1.1",
|
"resolve-url-loader": "3.1.1",
|
||||||
"sass-loader": "10.0.1",
|
"sass-loader": "10.0.3",
|
||||||
"semver": "7.3.2",
|
"semver": "7.3.2",
|
||||||
"style-loader": "1.2.1",
|
"style-loader": "2.0.0",
|
||||||
"terser-webpack-plugin": "4.1.0",
|
"terser-webpack-plugin": "4.2.3",
|
||||||
"ts-pnp": "1.2.0",
|
"ts-pnp": "1.2.0",
|
||||||
"uglifyjs-webpack-plugin": "^2.2.0",
|
"uglifyjs-webpack-plugin": "^2.2.0",
|
||||||
"url-loader": "4.1.0",
|
"url-loader": "4.1.1",
|
||||||
"webpack": "4.44.1",
|
"webpack": "4.44.2",
|
||||||
"webpack-dev-server": "3.11.0",
|
"webpack-dev-server": "3.11.0",
|
||||||
"webpack-manifest-plugin": "2.2.0",
|
"webpack-manifest-plugin": "2.2.0",
|
||||||
"workbox-webpack-plugin": "5.1.3"
|
"workbox-webpack-plugin": "5.1.4"
|
||||||
},
|
},
|
||||||
"eslintConfig": {
|
"eslintConfig": {
|
||||||
"extends": "react-app"
|
"extends": "react-app"
|
||||||
|
|||||||
@@ -0,0 +1,72 @@
|
|||||||
|
import Keyboard from "../lib";
|
||||||
|
import "./css/RTLDemo.css";
|
||||||
|
|
||||||
|
const setDOM = () => {
|
||||||
|
document.querySelector("#root").innerHTML = `
|
||||||
|
<input class="input" placeholder="Tap on the virtual keyboard to start" />
|
||||||
|
<div class="simple-keyboard"></div>
|
||||||
|
`;
|
||||||
|
};
|
||||||
|
|
||||||
|
class Demo {
|
||||||
|
constructor() {
|
||||||
|
setDOM();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Demo Start
|
||||||
|
*/
|
||||||
|
this.keyboard = new Keyboard({
|
||||||
|
onChange: input => this.onChange(input),
|
||||||
|
onKeyPress: button => this.onKeyPress(button),
|
||||||
|
rtl: true,
|
||||||
|
layout: {
|
||||||
|
default: [
|
||||||
|
"\u05e5 1 2 3 4 5 6 7 8 9 0 - = {bksp}",
|
||||||
|
"{tab} \u05e3 \u05df \u05e7 \u05e8 \u05d0 \u05d8 \u05d5 \u05ea \u05dd \u05e4 ] [ \\",
|
||||||
|
"{lock} \u05e9 \u05d3 \u05d2 \u05db \u05e2 \u05d9 \u05d7 \u05dc \u05da : ' {enter}",
|
||||||
|
"{shift} \u05d6 \u05e1 \u05d1 \u05d4 \u05e0 \u05de \u05e6 , . / {shift}",
|
||||||
|
".com @ {space}"
|
||||||
|
],
|
||||||
|
shift: [
|
||||||
|
"~ ! @ # $ % ^ & * ( ) _ + {bksp}",
|
||||||
|
"{tab} Q W E R T Y U I O P { } |",
|
||||||
|
'{lock} A S D F G H J K L : " {enter}',
|
||||||
|
"{shift} Z X C V B N M < > ? {shift}",
|
||||||
|
".com @ {space}"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update simple-keyboard when input is changed directly
|
||||||
|
*/
|
||||||
|
document.querySelector(".input").addEventListener("input", event => {
|
||||||
|
this.keyboard.setInput(event.target.value);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
onChange(input) {
|
||||||
|
document.querySelector(".input").value = input;
|
||||||
|
console.log("Input changed", input, input.split(""));
|
||||||
|
}
|
||||||
|
|
||||||
|
onKeyPress(button) {
|
||||||
|
console.log("Button pressed", button);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If you want to handle the shift and caps lock buttons
|
||||||
|
*/
|
||||||
|
if (button === "{shift}" || button === "{lock}") this.handleShift();
|
||||||
|
}
|
||||||
|
|
||||||
|
handleShift() {
|
||||||
|
const currentLayout = this.keyboard.options.layoutName;
|
||||||
|
const shiftToggle = currentLayout === "default" ? "shift" : "default";
|
||||||
|
|
||||||
|
this.keyboard.setOptions({
|
||||||
|
layoutName: shiftToggle
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default Demo;
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
input {
|
||||||
|
width: 100%;
|
||||||
|
height: 100px;
|
||||||
|
padding: 20px;
|
||||||
|
font-size: 20px;
|
||||||
|
border: none;
|
||||||
|
box-sizing: border-box;
|
||||||
|
direction: rtl;
|
||||||
|
}
|
||||||
|
|
||||||
|
.simple-keyboard {
|
||||||
|
max-width: 850px;
|
||||||
|
}
|
||||||
@@ -4,6 +4,7 @@ import "./css/index.css";
|
|||||||
* Demos
|
* Demos
|
||||||
*/
|
*/
|
||||||
import BasicDemo from "./BasicDemo";
|
import BasicDemo from "./BasicDemo";
|
||||||
|
//import RTLDemo from "./RTLDemo";
|
||||||
//import ButtonThemeDemo from "./ButtonThemeDemo";
|
//import ButtonThemeDemo from "./ButtonThemeDemo";
|
||||||
//import DOMElementDemo from "./DOMElementDemo";
|
//import DOMElementDemo from "./DOMElementDemo";
|
||||||
//import FullKeyboardDemo from "./FullKeyboardDemo";
|
//import FullKeyboardDemo from "./FullKeyboardDemo";
|
||||||
|
|||||||
@@ -0,0 +1,72 @@
|
|||||||
|
import { setDOM, removeRTLControls } from '../../utils/TestUtility';
|
||||||
|
import RTLDemo from '../RTLDemo';
|
||||||
|
|
||||||
|
it('Demo will load', () => {
|
||||||
|
setDOM();
|
||||||
|
|
||||||
|
new RTLDemo();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Demo onDOMLoaded will work', () => {
|
||||||
|
setDOM();
|
||||||
|
|
||||||
|
const demo = new RTLDemo();
|
||||||
|
|
||||||
|
expect(demo.keyboard).toBeTruthy();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Demo onChange will work', () => {
|
||||||
|
setDOM();
|
||||||
|
|
||||||
|
const demo = new RTLDemo();
|
||||||
|
|
||||||
|
demo.onChange("test");
|
||||||
|
|
||||||
|
expect(removeRTLControls(document.body.querySelector('.input').value)).toBe("test");
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Demo onChange will work', () => {
|
||||||
|
setDOM();
|
||||||
|
|
||||||
|
const demo = new RTLDemo();
|
||||||
|
|
||||||
|
demo.keyboard.getButtonElement(".").onclick();
|
||||||
|
|
||||||
|
expect(removeRTLControls(document.body.querySelector('.input').value)).toBe(".");
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Demo input change will work', () => {
|
||||||
|
setDOM();
|
||||||
|
|
||||||
|
const demo = new RTLDemo();
|
||||||
|
|
||||||
|
document.body.querySelector('.input').value = "test";
|
||||||
|
document.body.querySelector('.input').dispatchEvent(new Event('input'));
|
||||||
|
|
||||||
|
expect(removeRTLControls(demo.keyboard.getInput())).toBe("test");
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Demo handleShiftButton will work', () => {
|
||||||
|
setDOM();
|
||||||
|
|
||||||
|
const demo = new RTLDemo();
|
||||||
|
|
||||||
|
demo.keyboard.getButtonElement("{shift}")[0].onclick();
|
||||||
|
expect(demo.keyboard.options.layoutName).toBe("shift");
|
||||||
|
|
||||||
|
demo.keyboard.getButtonElement("{shift}")[0].onclick();
|
||||||
|
expect(demo.keyboard.options.layoutName).toBe("default");
|
||||||
|
});
|
||||||
|
|
||||||
|
it('RTL control caracters will be added to ', () => {
|
||||||
|
setDOM();
|
||||||
|
|
||||||
|
const demo = new RTLDemo();
|
||||||
|
|
||||||
|
demo.keyboard.getButtonElement("פ").onclick();
|
||||||
|
demo.keyboard.getButtonElement("ם").onclick();
|
||||||
|
demo.keyboard.getButtonElement("[").onclick();
|
||||||
|
|
||||||
|
expect(demo.keyboard.getInput()).toBe("פם[");
|
||||||
|
expect(demo.keyboard.input[demo.keyboard.options.inputName]).toBe("פם[");
|
||||||
|
});
|
||||||
Vendored
+27
-7
@@ -88,14 +88,9 @@ declare module 'simple-keyboard' {
|
|||||||
physicalKeyboardHighlight?: boolean;
|
physicalKeyboardHighlight?: boolean;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calling preventDefault for the mousedown events keeps the focus on the input.
|
* Presses keys highlighted by physicalKeyboardHighlight
|
||||||
*/
|
*/
|
||||||
preventMouseDownDefault?: boolean;
|
physicalKeyboardHighlightPress?: boolean;
|
||||||
|
|
||||||
/**
|
|
||||||
* Stops pointer down events on simple-keyboard buttons from bubbling to parent elements.
|
|
||||||
*/
|
|
||||||
stopMouseDownPropagation?: boolean;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Define the text color that the physical keyboard highlighted key should have.
|
* Define the text color that the physical keyboard highlighted key should have.
|
||||||
@@ -107,6 +102,26 @@ declare module 'simple-keyboard' {
|
|||||||
*/
|
*/
|
||||||
physicalKeyboardHighlightBgColor?: string;
|
physicalKeyboardHighlightBgColor?: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calling preventDefault for the mousedown events keeps the focus on the input.
|
||||||
|
*/
|
||||||
|
preventMouseDownDefault?: boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calling preventDefault for the mouseup events.
|
||||||
|
*/
|
||||||
|
preventMouseUpDefault?: boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stops pointer down events on simple-keyboard buttons from bubbling to parent elements.
|
||||||
|
*/
|
||||||
|
stopMouseDownPropagation?: boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stops pointer up events on simple-keyboard buttons from bubbling to parent elements.
|
||||||
|
*/
|
||||||
|
stopMouseUpPropagation?: boolean;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Render buttons as a button element instead of a div element.
|
* Render buttons as a button element instead of a div element.
|
||||||
*/
|
*/
|
||||||
@@ -142,6 +157,11 @@ declare module 'simple-keyboard' {
|
|||||||
*/
|
*/
|
||||||
disableButtonHold?: boolean;
|
disableButtonHold?: boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds unicode right-to-left control characters to input return values.
|
||||||
|
*/
|
||||||
|
rtl?: boolean;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Executes the callback function on key press. Returns button layout name (i.e.: "{shift}").
|
* Executes the callback function on key press. Returns button layout name (i.e.: "{shift}").
|
||||||
*/
|
*/
|
||||||
|
|||||||
+121
-125
@@ -64,10 +64,13 @@ class SimpleKeyboard {
|
|||||||
* @property {object} maxLength Restrains simple-keyboard’s individual inputs to a certain length. This should be used in addition to the input element’s maxlengthattribute.
|
* @property {object} maxLength Restrains simple-keyboard’s individual inputs to a certain length. This should be used in addition to the input element’s maxlengthattribute.
|
||||||
* @property {boolean} syncInstanceInputs When set to true, this option synchronizes the internal input of every simple-keyboard instance.
|
* @property {boolean} syncInstanceInputs When set to true, this option synchronizes the internal input of every simple-keyboard instance.
|
||||||
* @property {boolean} physicalKeyboardHighlight Enable highlighting of keys pressed on physical keyboard.
|
* @property {boolean} physicalKeyboardHighlight Enable highlighting of keys pressed on physical keyboard.
|
||||||
* @property {boolean} preventMouseDownDefault Calling preventDefault for the mousedown events keeps the focus on the input.
|
* @property {boolean} physicalKeyboardHighlightPress Presses keys highlighted by physicalKeyboardHighlight
|
||||||
* @property {boolean} stopMouseDownPropagation Stops pointer down events on simple-keyboard buttons from bubbling to parent elements.
|
|
||||||
* @property {string} physicalKeyboardHighlightTextColor Define the text color that the physical keyboard highlighted key should have.
|
* @property {string} physicalKeyboardHighlightTextColor Define the text color that the physical keyboard highlighted key should have.
|
||||||
* @property {string} physicalKeyboardHighlightBgColor Define the background color that the physical keyboard highlighted key should have.
|
* @property {string} physicalKeyboardHighlightBgColor Define the background color that the physical keyboard highlighted key should have.
|
||||||
|
* @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.
|
||||||
|
* @property {boolean} stopMouseUpPropagation Stops pointer up events on simple-keyboard buttons from bubbling to parent elements.
|
||||||
* @property {function(button: string):string} onKeyPress Executes the callback function on key press. Returns button layout name (i.e.: “{shift}”).
|
* @property {function(button: string):string} onKeyPress Executes the callback function on key press. Returns button layout name (i.e.: “{shift}”).
|
||||||
* @property {function(input: string):string} onChange Executes the callback function on input change. Returns the current input’s string.
|
* @property {function(input: string):string} onChange Executes the callback function on input change. Returns the current input’s string.
|
||||||
* @property {function} onRender Executes the callback function every time simple-keyboard is rendered (e.g: when you change layouts).
|
* @property {function} onRender Executes the callback function every time simple-keyboard is rendered (e.g: when you change layouts).
|
||||||
@@ -81,6 +84,7 @@ class SimpleKeyboard {
|
|||||||
* @property {boolean} useMouseEvents Opt out of PointerEvents handling, falling back to the prior mouse event logic.
|
* @property {boolean} useMouseEvents Opt out of PointerEvents handling, falling back to the prior mouse event logic.
|
||||||
* @property {function} destroy Clears keyboard listeners and DOM elements.
|
* @property {function} destroy Clears keyboard listeners and DOM elements.
|
||||||
* @property {boolean} disableButtonHold Disable button hold action.
|
* @property {boolean} disableButtonHold Disable button hold action.
|
||||||
|
* @property {boolean} rtl Adds unicode right-to-left control characters to input return values.
|
||||||
* @property {function} onKeyReleased Executes the callback function on key release.
|
* @property {function} onKeyReleased Executes the callback function on key release.
|
||||||
* @property {array} modules Module classes to be loaded by simple-keyboard.
|
* @property {array} modules Module classes to be loaded by simple-keyboard.
|
||||||
*/
|
*/
|
||||||
@@ -290,7 +294,7 @@ class SimpleKeyboard {
|
|||||||
true
|
true
|
||||||
);
|
);
|
||||||
|
|
||||||
if (debug) console.log("Input changed:", this.input);
|
if (debug) console.log("Input changed:", this.getAllInputs());
|
||||||
|
|
||||||
if (this.options.debug) {
|
if (this.options.debug) {
|
||||||
console.log(
|
console.log(
|
||||||
@@ -310,13 +314,13 @@ class SimpleKeyboard {
|
|||||||
* Calling onChange
|
* Calling onChange
|
||||||
*/
|
*/
|
||||||
if (typeof this.options.onChange === "function")
|
if (typeof this.options.onChange === "function")
|
||||||
this.options.onChange(this.input[this.options.inputName]);
|
this.options.onChange(this.getInput(this.options.inputName, true));
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calling onChangeAll
|
* Calling onChangeAll
|
||||||
*/
|
*/
|
||||||
if (typeof this.options.onChangeAll === "function")
|
if (typeof this.options.onChangeAll === "function")
|
||||||
this.options.onChangeAll(this.input);
|
this.options.onChangeAll(this.getAllInputs());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (debug) {
|
if (debug) {
|
||||||
@@ -379,19 +383,24 @@ class SimpleKeyboard {
|
|||||||
/**
|
/**
|
||||||
* Handles button mouseup
|
* Handles button mouseup
|
||||||
*/
|
*/
|
||||||
handleButtonMouseUp(button) {
|
handleButtonMouseUp(button = null, e = null) {
|
||||||
this.dispatch(instance => {
|
if (e) {
|
||||||
|
/**
|
||||||
|
* Handle event options
|
||||||
|
*/
|
||||||
|
if (this.options.preventMouseUpDefault) e.preventDefault();
|
||||||
|
if (this.options.stopMouseUpPropagation) e.stopPropagation();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove active class
|
* Remove active class
|
||||||
*/
|
*/
|
||||||
instance.recurseButtons(buttonElement => {
|
this.recurseButtons(buttonElement => {
|
||||||
buttonElement.classList.remove(this.activeButtonClass);
|
buttonElement.classList.remove(this.activeButtonClass);
|
||||||
});
|
});
|
||||||
|
|
||||||
instance.isMouseHold = false;
|
this.isMouseHold = false;
|
||||||
if (instance.holdInteractionTimeout)
|
if (this.holdInteractionTimeout) clearTimeout(this.holdInteractionTimeout);
|
||||||
clearTimeout(instance.holdInteractionTimeout);
|
|
||||||
});
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calling onKeyReleased
|
* Calling onKeyReleased
|
||||||
@@ -463,16 +472,39 @@ class SimpleKeyboard {
|
|||||||
* Get the keyboard’s input (You can also get it from the onChange prop).
|
* Get the keyboard’s input (You can also get it from the onChange prop).
|
||||||
* @param {string} [inputName] optional - the internal input to select
|
* @param {string} [inputName] optional - the internal input to select
|
||||||
*/
|
*/
|
||||||
getInput(inputName) {
|
getInput(inputName, skipSync = false) {
|
||||||
inputName = inputName || this.options.inputName;
|
inputName = inputName || this.options.inputName;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enforce syncInstanceInputs, if set
|
* Enforce syncInstanceInputs, if set
|
||||||
*/
|
*/
|
||||||
if (this.options.syncInstanceInputs) this.syncInstanceInputs();
|
if (this.options.syncInstanceInputs && !skipSync) this.syncInstanceInputs();
|
||||||
|
|
||||||
|
if (this.options.rtl) {
|
||||||
|
// Remove existing control chars
|
||||||
|
const inputWithoutRTLControl = this.input[inputName]
|
||||||
|
.replace("\u202B", "")
|
||||||
|
.replace("\u202C", "");
|
||||||
|
|
||||||
|
return "\u202B" + inputWithoutRTLControl + "\u202C";
|
||||||
|
} else {
|
||||||
return this.input[inputName];
|
return this.input[inputName];
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get all simple-keyboard inputs
|
||||||
|
*/
|
||||||
|
getAllInputs() {
|
||||||
|
const output = {};
|
||||||
|
const inputNames = Object.keys(this.input);
|
||||||
|
|
||||||
|
inputNames.forEach(inputName => {
|
||||||
|
output[inputName] = this.getInput(inputName, true);
|
||||||
|
});
|
||||||
|
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the keyboard’s input.
|
* Set the keyboard’s input.
|
||||||
@@ -543,7 +575,6 @@ class SimpleKeyboard {
|
|||||||
/**
|
/**
|
||||||
* inputName changed. This requires a caretPosition reset
|
* inputName changed. This requires a caretPosition reset
|
||||||
*/
|
*/
|
||||||
// TODO: Review side-effects
|
|
||||||
if (this.options.debug) {
|
if (this.options.debug) {
|
||||||
console.log("inputName changed. caretPosition reset.");
|
console.log("inputName changed. caretPosition reset.");
|
||||||
}
|
}
|
||||||
@@ -741,8 +772,6 @@ class SimpleKeyboard {
|
|||||||
* Handles simple-keyboard event listeners
|
* Handles simple-keyboard event listeners
|
||||||
*/
|
*/
|
||||||
setEventListeners() {
|
setEventListeners() {
|
||||||
const { useTouchEvents, useMouseEvents } = this.options;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Only first instance should set the event listeners
|
* Only first instance should set the event listeners
|
||||||
*/
|
*/
|
||||||
@@ -754,42 +783,10 @@ class SimpleKeyboard {
|
|||||||
/**
|
/**
|
||||||
* Event Listeners
|
* Event Listeners
|
||||||
*/
|
*/
|
||||||
document.onkeyup = this.handleKeyUp;
|
document.addEventListener("keyup", this.handleKeyUp);
|
||||||
document.onkeydown = this.handleKeyDown;
|
document.addEventListener("keydown", this.handleKeyDown);
|
||||||
|
document.addEventListener("mouseup", this.handleMouseUp);
|
||||||
/**
|
document.addEventListener("touchend", this.handleTouchEnd);
|
||||||
* Pointer events
|
|
||||||
*/
|
|
||||||
if (
|
|
||||||
this.utilities.pointerEventsSupported() &&
|
|
||||||
!useTouchEvents &&
|
|
||||||
!useMouseEvents
|
|
||||||
) {
|
|
||||||
document.onpointerdown = this.handlePointerDown;
|
|
||||||
document.onpointerup = this.handlePointerUp;
|
|
||||||
document.onpointercancel = this.handlePointerUp;
|
|
||||||
|
|
||||||
this.keyboardDOM.onpointerdown = this.handleKeyboardContainerMouseDown;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Touch events
|
|
||||||
*/
|
|
||||||
} else if (useTouchEvents) {
|
|
||||||
document.ontouchstart = this.handlePointerDown;
|
|
||||||
document.ontouchend = this.handlePointerUp;
|
|
||||||
document.ontouchcancel = this.handlePointerUp;
|
|
||||||
|
|
||||||
this.keyboardDOM.ontouchstart = this.handleKeyboardContainerMouseDown;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Mouse events
|
|
||||||
*/
|
|
||||||
} else if (!useTouchEvents) {
|
|
||||||
document.onmousedown = this.handlePointerDown;
|
|
||||||
document.onmouseup = this.handlePointerUp;
|
|
||||||
|
|
||||||
this.keyboardDOM.onmousedown = this.handleKeyboardContainerMouseDown;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -814,17 +811,17 @@ class SimpleKeyboard {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Event Handler: PointerDown
|
* Event Handler: MouseUp
|
||||||
*/
|
*/
|
||||||
handlePointerDown(event) {
|
handleMouseUp(event) {
|
||||||
this.caretEventHandler(event);
|
this.caretEventHandler(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Event Handler: PointerUp
|
* Event Handler: TouchEnd
|
||||||
*/
|
*/
|
||||||
handlePointerUp(event) {
|
/* istanbul ignore next */
|
||||||
this.handleButtonMouseUp();
|
handleTouchEnd(event) {
|
||||||
this.caretEventHandler(event);
|
this.caretEventHandler(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -832,28 +829,24 @@ class SimpleKeyboard {
|
|||||||
* Called by {@link setEventListeners} when an event that warrants a cursor position update is triggered
|
* Called by {@link setEventListeners} when an event that warrants a cursor position update is triggered
|
||||||
*/
|
*/
|
||||||
caretEventHandler(event) {
|
caretEventHandler(event) {
|
||||||
if (this.options.disableCaretPositioning) {
|
|
||||||
this.setCaretPosition(null);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
let targetTagName;
|
let targetTagName;
|
||||||
|
|
||||||
if (event.target.tagName) {
|
if (event.target.tagName) {
|
||||||
targetTagName = event.target.tagName.toLowerCase();
|
targetTagName = event.target.tagName.toLowerCase();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* istanbul ignore next */
|
|
||||||
this.dispatch(instance => {
|
this.dispatch(instance => {
|
||||||
const isKeyboard =
|
const isKeyboard =
|
||||||
event.target === instance.keyboardDOM ||
|
event.target === instance.keyboardDOM ||
|
||||||
(event.target && instance.keyboardDOM.contains(event.target));
|
(event.target && instance.keyboardDOM.contains(event.target));
|
||||||
|
|
||||||
// if (!this.isMouseHold) {
|
if (instance.isMouseHold) {
|
||||||
// instance.isMouseHold = false;
|
instance.isMouseHold = false;
|
||||||
// }
|
}
|
||||||
|
|
||||||
if (targetTagName === "textarea" || targetTagName === "input") {
|
if (
|
||||||
|
(targetTagName === "textarea" || targetTagName === "input") &&
|
||||||
|
!instance.options.disableCaretPositioning
|
||||||
|
) {
|
||||||
/**
|
/**
|
||||||
* Tracks current cursor position
|
* Tracks current cursor position
|
||||||
* As keys are pressed, text will be added/removed at that position within the input.
|
* As keys are pressed, text will be added/removed at that position within the input.
|
||||||
@@ -872,9 +865,10 @@ class SimpleKeyboard {
|
|||||||
`(${instance.keyboardDOMClass})`
|
`(${instance.keyboardDOMClass})`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
} else if (instance.options.disableCaretPositioning || !isKeyboard) {
|
||||||
// TODO: Review side-effects
|
/**
|
||||||
} else if (!isKeyboard) {
|
* If we toggled off disableCaretPositioning, we must ensure caretPosition doesn't persist once reactivated.
|
||||||
|
*/
|
||||||
instance.setCaretPosition(null);
|
instance.setCaretPosition(null);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -900,6 +894,18 @@ class SimpleKeyboard {
|
|||||||
`Destroying simple-keyboard instance: ${this.currentInstanceName}`
|
`Destroying simple-keyboard instance: ${this.currentInstanceName}`
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove document listeners
|
||||||
|
*/
|
||||||
|
document.removeEventListener("keyup", this.handleKeyUp);
|
||||||
|
document.removeEventListener("keydown", this.handleKeyDown);
|
||||||
|
document.removeEventListener("mouseup", this.handleMouseUp);
|
||||||
|
document.removeEventListener("touchend", this.handleTouchEnd);
|
||||||
|
document.onpointerup = null;
|
||||||
|
document.ontouchend = null;
|
||||||
|
document.ontouchcancel = null;
|
||||||
|
document.onmouseup = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove buttons
|
* Remove buttons
|
||||||
*/
|
*/
|
||||||
@@ -919,6 +925,8 @@ class SimpleKeyboard {
|
|||||||
};
|
};
|
||||||
|
|
||||||
this.recurseButtons(deleteButton);
|
this.recurseButtons(deleteButton);
|
||||||
|
|
||||||
|
this.recurseButtons = null;
|
||||||
deleteButton = null;
|
deleteButton = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -933,55 +941,12 @@ class SimpleKeyboard {
|
|||||||
*/
|
*/
|
||||||
this.clear();
|
this.clear();
|
||||||
|
|
||||||
/**
|
|
||||||
* Remove timouts
|
|
||||||
*/
|
|
||||||
/* istanbul ignore next */
|
|
||||||
if (this.holdInteractionTimeout) clearTimeout(this.holdInteractionTimeout);
|
|
||||||
/* istanbul ignore next */
|
|
||||||
if (this.holdTimeout) clearTimeout(this.holdTimeout);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove instance
|
* Remove instance
|
||||||
*/
|
*/
|
||||||
window["SimpleKeyboardInstances"][this.currentInstanceName] = null;
|
window["SimpleKeyboardInstances"][this.currentInstanceName] = null;
|
||||||
delete window["SimpleKeyboardInstances"][this.currentInstanceName];
|
delete window["SimpleKeyboardInstances"][this.currentInstanceName];
|
||||||
|
|
||||||
/**
|
|
||||||
* Removing document listeners if there are no more instances
|
|
||||||
*/
|
|
||||||
if (!Object.keys(window["SimpleKeyboardInstances"]).length) {
|
|
||||||
/**
|
|
||||||
* Remove document listeners
|
|
||||||
*/
|
|
||||||
document.onkeydown = null;
|
|
||||||
document.onkeyup = null;
|
|
||||||
|
|
||||||
document.onpointerdown = null;
|
|
||||||
document.onpointerup = null;
|
|
||||||
|
|
||||||
document.onmousedown = null;
|
|
||||||
document.onmouseup = null;
|
|
||||||
|
|
||||||
document.ontouchstart = null;
|
|
||||||
document.ontouchend = null;
|
|
||||||
document.ontouchcancel = null;
|
|
||||||
|
|
||||||
if (this.options.debug) {
|
|
||||||
console.log(
|
|
||||||
"Destroy: No instances remaining. Document listeners removed",
|
|
||||||
window["SimpleKeyboardInstances"]
|
|
||||||
);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (this.options.debug) {
|
|
||||||
console.log(
|
|
||||||
"Destroy: Instances remaining! Document listeners not removed",
|
|
||||||
window["SimpleKeyboardInstances"]
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reset initialized flag
|
* Reset initialized flag
|
||||||
*/
|
*/
|
||||||
@@ -1466,11 +1431,11 @@ class SimpleKeyboard {
|
|||||||
this.handleButtonClicked(button);
|
this.handleButtonClicked(button);
|
||||||
this.handleButtonMouseDown(button, e);
|
this.handleButtonMouseDown(button, e);
|
||||||
};
|
};
|
||||||
buttonDOM.onpointerup = () => {
|
buttonDOM.onpointerup = e => {
|
||||||
this.handleButtonMouseUp(button);
|
this.handleButtonMouseUp(button, e);
|
||||||
};
|
};
|
||||||
buttonDOM.onpointercancel = () => {
|
buttonDOM.onpointercancel = e => {
|
||||||
this.handleButtonMouseUp(button);
|
this.handleButtonMouseUp(button, e);
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
/**
|
/**
|
||||||
@@ -1484,24 +1449,25 @@ class SimpleKeyboard {
|
|||||||
this.handleButtonClicked(button);
|
this.handleButtonClicked(button);
|
||||||
this.handleButtonMouseDown(button, e);
|
this.handleButtonMouseDown(button, e);
|
||||||
};
|
};
|
||||||
buttonDOM.ontouchend = () => {
|
buttonDOM.ontouchend = e => {
|
||||||
this.handleButtonMouseUp(button);
|
this.handleButtonMouseUp(button, e);
|
||||||
};
|
};
|
||||||
buttonDOM.ontouchcancel = () => {
|
buttonDOM.ontouchcancel = e => {
|
||||||
this.handleButtonMouseUp(button);
|
this.handleButtonMouseUp(button, e);
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
/**
|
/**
|
||||||
* Handle mouse events
|
* Handle mouse events
|
||||||
*/
|
*/
|
||||||
buttonDOM.onclick = () => {
|
buttonDOM.onclick = () => {
|
||||||
|
this.isMouseHold = false;
|
||||||
this.handleButtonClicked(button);
|
this.handleButtonClicked(button);
|
||||||
};
|
};
|
||||||
buttonDOM.onmousedown = e => {
|
buttonDOM.onmousedown = e => {
|
||||||
this.handleButtonMouseDown(button, e);
|
this.handleButtonMouseDown(button, e);
|
||||||
};
|
};
|
||||||
buttonDOM.onmouseup = () => {
|
buttonDOM.onmouseup = e => {
|
||||||
this.handleButtonMouseUp(button);
|
this.handleButtonMouseUp(button, e);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1565,6 +1531,36 @@ class SimpleKeyboard {
|
|||||||
*/
|
*/
|
||||||
this.initialized = true;
|
this.initialized = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handling parent events
|
||||||
|
*/
|
||||||
|
/* istanbul ignore next */
|
||||||
|
if (
|
||||||
|
this.utilities.pointerEventsSupported() &&
|
||||||
|
!useTouchEvents &&
|
||||||
|
!useMouseEvents
|
||||||
|
) {
|
||||||
|
document.onpointerup = () => this.handleButtonMouseUp();
|
||||||
|
this.keyboardDOM.onpointerdown = e =>
|
||||||
|
this.handleKeyboardContainerMouseDown(e);
|
||||||
|
} else if (useTouchEvents) {
|
||||||
|
/**
|
||||||
|
* Handling ontouchend, ontouchcancel
|
||||||
|
*/
|
||||||
|
document.ontouchend = () => this.handleButtonMouseUp();
|
||||||
|
document.ontouchcancel = () => this.handleButtonMouseUp();
|
||||||
|
|
||||||
|
this.keyboardDOM.ontouchstart = e =>
|
||||||
|
this.handleKeyboardContainerMouseDown(e);
|
||||||
|
} else if (!useTouchEvents) {
|
||||||
|
/**
|
||||||
|
* Handling mouseup
|
||||||
|
*/
|
||||||
|
document.onmouseup = () => this.handleButtonMouseUp();
|
||||||
|
this.keyboardDOM.onmousedown = e =>
|
||||||
|
this.handleKeyboardContainerMouseDown(e);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calling onInit
|
* Calling onInit
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -590,13 +590,15 @@ it('Keyboard will receive physical keyboard events', () => {
|
|||||||
physicalKeyboardHighlight: true
|
physicalKeyboardHighlight: true
|
||||||
});
|
});
|
||||||
|
|
||||||
document.onkeyup({
|
document.dispatchEvent(new KeyboardEvent('keyup', {
|
||||||
charCode: 0,
|
charCode: 0,
|
||||||
code: "KeyF",
|
code: "KeyF",
|
||||||
key: "f",
|
key: "f",
|
||||||
which: 70,
|
which: 70,
|
||||||
target: document.createElement('input')
|
target: {
|
||||||
});
|
tagName: "input"
|
||||||
|
}
|
||||||
|
}));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Keyboard caretEventHandler will detect input, textarea focus', () => {
|
it('Keyboard caretEventHandler will detect input, textarea focus', () => {
|
||||||
@@ -927,14 +929,23 @@ it('Keyboard handleButtonMouseDown will work', () => {
|
|||||||
it('Keyboard handleButtonMouseDown will work with preventMouseDownDefault', () => {
|
it('Keyboard handleButtonMouseDown will work with preventMouseDownDefault', () => {
|
||||||
setDOM();
|
setDOM();
|
||||||
|
|
||||||
const keyboard = new Keyboard();
|
const keyboard = new Keyboard({
|
||||||
|
preventMouseDownDefault: true,
|
||||||
|
stopMouseDownPropagation: true
|
||||||
|
});
|
||||||
|
let called = false;
|
||||||
|
let called2 = false;
|
||||||
|
|
||||||
keyboard.options.preventMouseDownDefault = true;
|
keyboard.options.preventMouseDownDefault = true;
|
||||||
|
|
||||||
keyboard.handleButtonMouseDown("q", {
|
keyboard.handleButtonMouseDown("q", {
|
||||||
target: keyboard.getButtonElement("q"),
|
target: keyboard.getButtonElement("q"),
|
||||||
preventDefault: () => {},
|
preventDefault: () => {
|
||||||
stopPropagation: () => {}
|
called = true;
|
||||||
|
},
|
||||||
|
stopPropagation: () => {
|
||||||
|
called2 = true;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
keyboard.getButtonElement("q").onclick();
|
keyboard.getButtonElement("q").onclick();
|
||||||
@@ -942,6 +953,37 @@ it('Keyboard handleButtonMouseDown will work with preventMouseDownDefault', () =
|
|||||||
target: document.body
|
target: document.body
|
||||||
});
|
});
|
||||||
|
|
||||||
|
expect(called).toBe(true);
|
||||||
|
expect(called2).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Keyboard handleButtonMouseUp will work with preventMouseUpDefault and stopMouseUpPropagation', () => {
|
||||||
|
setDOM();
|
||||||
|
|
||||||
|
const keyboard = new Keyboard({
|
||||||
|
preventMouseUpDefault: true,
|
||||||
|
stopMouseUpPropagation: true
|
||||||
|
});
|
||||||
|
let called = false;
|
||||||
|
let called2 = false;
|
||||||
|
|
||||||
|
keyboard.handleButtonMouseUp("q", {
|
||||||
|
target: keyboard.getButtonElement("q"),
|
||||||
|
preventDefault: () => {
|
||||||
|
called = true
|
||||||
|
},
|
||||||
|
stopPropagation: () => {
|
||||||
|
called2 = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
keyboard.getButtonElement("q").onclick();
|
||||||
|
document.onmouseup({
|
||||||
|
target: document.body
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(called).toBe(true);
|
||||||
|
expect(called2).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Keyboard onModulesLoaded will work', () => {
|
it('Keyboard onModulesLoaded will work', () => {
|
||||||
@@ -1224,15 +1266,15 @@ it('Keyboard destroy will work', () => {
|
|||||||
expect(document.onkeydown).toBe(null);
|
expect(document.onkeydown).toBe(null);
|
||||||
expect(document.onkeyup).toBe(null);
|
expect(document.onkeyup).toBe(null);
|
||||||
|
|
||||||
expect(document.onpointerdown).toBe(null);
|
// expect(document.onpointerdown).toBe(null);
|
||||||
expect(document.onpointerup).toBe(null);
|
// expect(document.onpointerup).toBe(null);
|
||||||
|
|
||||||
expect(document.onmousedown).toBe(null);
|
// expect(document.onmousedown).toBe(null);
|
||||||
expect(document.onmouseup).toBe(null);
|
// expect(document.onmouseup).toBe(null);
|
||||||
|
|
||||||
expect(document.ontouchstart).toBe(null);
|
// expect(document.ontouchstart).toBe(null);
|
||||||
expect(document.ontouchend).toBe(null);
|
// expect(document.ontouchend).toBe(null);
|
||||||
expect(document.ontouchcancel).toBe(null);
|
// expect(document.ontouchcancel).toBe(null);
|
||||||
|
|
||||||
expect(keyboard.initialized).toBe(false);
|
expect(keyboard.initialized).toBe(false);
|
||||||
});
|
});
|
||||||
@@ -1263,7 +1305,6 @@ it('Keyboard caretEventHandler will be triggered on mouseup and ontouchend', ()
|
|||||||
});
|
});
|
||||||
|
|
||||||
keyboard.setCaretPosition(6);
|
keyboard.setCaretPosition(6);
|
||||||
|
|
||||||
expect(keyboard.getCaretPosition()).toBe(6);
|
expect(keyboard.getCaretPosition()).toBe(6);
|
||||||
|
|
||||||
const event = {
|
const event = {
|
||||||
@@ -1380,17 +1421,32 @@ it('Keyboard handleKeyboardContainerMouseDown will respect preventMouseDownDefau
|
|||||||
expect(works).toBe(true);
|
expect(works).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Keyboard handlePointerDown will work', () => {
|
it('Keyboard caret positioning will work', () => {
|
||||||
setDOM();
|
setDOM();
|
||||||
|
|
||||||
const keyboard = new Keyboard();
|
const keyboard = new Keyboard({
|
||||||
|
onKeyPress: (button) => {
|
||||||
|
if (button === "{shift}" || button === "{lock}") handleShift();
|
||||||
|
else if (keyboard.options.layoutName === "shift") handleShift();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
keyboard.setCaretPosition(3);
|
function handleShift() {
|
||||||
expect(keyboard.getCaretPosition()).toBe(3);
|
const currentLayout = keyboard.options.layoutName;
|
||||||
|
const shiftToggle = currentLayout === "default" ? "shift" : "default";
|
||||||
|
|
||||||
triggerDocumentPointerDown({
|
keyboard.setOptions({
|
||||||
target: document.body
|
layoutName: shiftToggle
|
||||||
})
|
});
|
||||||
|
}
|
||||||
|
|
||||||
expect(keyboard.getCaretPosition()).toBe(null);
|
keyboard.getButtonElement("h").onpointerdown();
|
||||||
|
keyboard.getButtonElement("o").onpointerdown();
|
||||||
|
keyboard.setCaretPosition(1);
|
||||||
|
keyboard.getButtonElement("{shift}")[0].onpointerdown();
|
||||||
|
keyboard.getButtonElement("E").onpointerdown();
|
||||||
|
keyboard.getButtonElement("l").onpointerdown();
|
||||||
|
keyboard.getButtonElement("l").onpointerdown();
|
||||||
|
|
||||||
|
expect(keyboard.getInput()).toBe("hEllo");
|
||||||
});
|
});
|
||||||
@@ -34,11 +34,24 @@ class PhysicalKeyboard {
|
|||||||
options.physicalKeyboardHighlightBgColor || "#dadce4";
|
options.physicalKeyboardHighlightBgColor || "#dadce4";
|
||||||
buttonDOM.style.color =
|
buttonDOM.style.color =
|
||||||
options.physicalKeyboardHighlightTextColor || "black";
|
options.physicalKeyboardHighlightTextColor || "black";
|
||||||
|
|
||||||
|
if (options.physicalKeyboardHighlightPress) {
|
||||||
|
/**
|
||||||
|
* Trigger mousedown
|
||||||
|
*/
|
||||||
|
(
|
||||||
|
buttonDOM.onpointerdown ||
|
||||||
|
buttonDOM.onmousedown ||
|
||||||
|
buttonDOM.ontouchstart ||
|
||||||
|
Utilities.noop
|
||||||
|
)();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
handleHighlightKeyUp(event) {
|
handleHighlightKeyUp(event) {
|
||||||
|
const options = this.getOptions();
|
||||||
const buttonPressed = this.getSimpleKeyboardLayoutKey(event);
|
const buttonPressed = this.getSimpleKeyboardLayoutKey(event);
|
||||||
|
|
||||||
this.dispatch(instance => {
|
this.dispatch(instance => {
|
||||||
@@ -48,6 +61,18 @@ class PhysicalKeyboard {
|
|||||||
|
|
||||||
if (buttonDOM && buttonDOM.removeAttribute) {
|
if (buttonDOM && buttonDOM.removeAttribute) {
|
||||||
buttonDOM.removeAttribute("style");
|
buttonDOM.removeAttribute("style");
|
||||||
|
|
||||||
|
if (options.physicalKeyboardHighlightPress) {
|
||||||
|
/**
|
||||||
|
* Trigger mousedown
|
||||||
|
*/
|
||||||
|
(
|
||||||
|
buttonDOM.onpointerup ||
|
||||||
|
buttonDOM.onmouseup ||
|
||||||
|
buttonDOM.ontouchend ||
|
||||||
|
Utilities.noop
|
||||||
|
)();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -430,6 +430,8 @@ class Utilities {
|
|||||||
word.length ? str + word[0].toUpperCase() + word.slice(1) : str
|
word.length ? str + word[0].toUpperCase() + word.slice(1) : str
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static noop = () => {};
|
||||||
}
|
}
|
||||||
|
|
||||||
export default Utilities;
|
export default Utilities;
|
||||||
|
|||||||
@@ -114,3 +114,56 @@ it('PhysicalKeyboard will work with F1-F12 keys', () => {
|
|||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('PhysicalKeyboard will work with physicalKeyboardHighlightPress', () => {
|
||||||
|
setDOM();
|
||||||
|
|
||||||
|
new Keyboard({
|
||||||
|
physicalKeyboardHighlight: true,
|
||||||
|
physicalKeyboardHighlightPress: true,
|
||||||
|
debug: true
|
||||||
|
});
|
||||||
|
|
||||||
|
document.dispatchEvent(new KeyboardEvent('keydown', {
|
||||||
|
code: "KeyF",
|
||||||
|
key: "f",
|
||||||
|
target: {
|
||||||
|
tagName: "input"
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
|
||||||
|
document.dispatchEvent(new KeyboardEvent('keyup', {
|
||||||
|
code: "KeyF",
|
||||||
|
key: "f",
|
||||||
|
target: {
|
||||||
|
tagName: "input"
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
|
||||||
|
it('PhysicalKeyboard will work with physicalKeyboardHighlightPress (touch)', () => {
|
||||||
|
setDOM();
|
||||||
|
|
||||||
|
new Keyboard({
|
||||||
|
physicalKeyboardHighlight: true,
|
||||||
|
physicalKeyboardHighlightPress: true,
|
||||||
|
useTouchEvents: true,
|
||||||
|
debug: true
|
||||||
|
});
|
||||||
|
|
||||||
|
document.dispatchEvent(new KeyboardEvent('keydown', {
|
||||||
|
code: "KeyF",
|
||||||
|
key: "f",
|
||||||
|
target: {
|
||||||
|
tagName: "input"
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
|
||||||
|
document.dispatchEvent(new KeyboardEvent('keyup', {
|
||||||
|
code: "KeyF",
|
||||||
|
key: "f",
|
||||||
|
target: {
|
||||||
|
tagName: "input"
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
});
|
||||||
@@ -26,12 +26,16 @@
|
|||||||
/**
|
/**
|
||||||
* Trigger pointerup
|
* Trigger pointerup
|
||||||
*/
|
*/
|
||||||
export const triggerDocumentPointerUp = (e = {}) => (document.onpointerup || document.onmouseup || document.ontouchstart)(e);
|
export const triggerDocumentPointerUp = (e = {}) => {
|
||||||
|
document.dispatchEvent(new MouseEvent('mouseup', e));
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Trigger pointerdown
|
* Trigger pointerdown
|
||||||
*/
|
*/
|
||||||
export const triggerDocumentPointerDown = (e = {}) => (document.onpointerdown || document.onmousedown || document.ontouchend)(e);
|
export const triggerDocumentPointerDown = (e = {}) => {
|
||||||
|
document.dispatchEvent(new MouseEvent('mousedown', e));
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test if standard buttons respect maxLength and do input a value
|
* Test if standard buttons respect maxLength and do input a value
|
||||||
@@ -118,3 +122,10 @@
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove RTL control chars
|
||||||
|
*/
|
||||||
|
export const removeRTLControls = (input) => {
|
||||||
|
return input.replace("\u202B", "").replace("\u202C", "");
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user