mirror of
https://github.com/hodgef/simple-keyboard.git
synced 2026-02-03 00:06:50 +08:00
Compare commits
56 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
effee00b87 | ||
|
|
90b408eff6 | ||
|
|
21fa732b1f | ||
|
|
80f4307c36 | ||
|
|
681bb3d0ee | ||
|
|
e1fa685c6c | ||
|
|
2de7154128 | ||
|
|
c9afe43f5b | ||
|
|
c59f819db9 | ||
|
|
1f9efb0c66 | ||
|
|
32cbce8c8a | ||
|
|
6c2236f762 | ||
|
|
23a50e6f44 | ||
|
|
c316d493c7 | ||
|
|
70e7635f25 | ||
|
|
f5b73b09e7 | ||
|
|
7432e01740 | ||
|
|
459ab71c45 | ||
|
|
a5c177e41c | ||
|
|
d382945de7 | ||
|
|
4335f477a1 | ||
|
|
d03f00c0d1 | ||
|
|
9cea07dd41 | ||
|
|
efe18e7240 | ||
|
|
82e242a806 | ||
|
|
4a9d485d5b | ||
|
|
6ffd2e77ad | ||
|
|
7753bc5ba3 | ||
|
|
9c4fa00363 | ||
|
|
251af057d8 | ||
|
|
e60574d56d | ||
|
|
b3b482e864 | ||
|
|
ff037ad5b7 | ||
|
|
ede2ce04b1 | ||
|
|
10380099e6 | ||
|
|
058b6774da | ||
|
|
3b12b278f7 | ||
|
|
3523df1ef5 | ||
|
|
178c63cf98 | ||
|
|
ec452963fb | ||
|
|
b5cbfa780b | ||
|
|
5c40dd3109 | ||
|
|
7ab6baa0f4 | ||
|
|
0512e2c624 | ||
|
|
2693030203 | ||
|
|
3cbdf604fe | ||
|
|
d87cb82238 | ||
|
|
125f6b6504 | ||
|
|
97b475a2b7 | ||
|
|
682660d638 | ||
|
|
d8c1327eff | ||
|
|
b8fc9425ba | ||
|
|
5c42ae3fbb | ||
|
|
a8e826679f | ||
|
|
f78bfc0d02 | ||
|
|
9c12f410ed |
5
.github/ISSUE_TEMPLATE/bug_report.md
vendored
5
.github/ISSUE_TEMPLATE/bug_report.md
vendored
@@ -1,6 +1,9 @@
|
||||
---
|
||||
name: Bug report
|
||||
about: Create a report to help improve simple-keyboard
|
||||
title: ''
|
||||
labels: ''
|
||||
assignees: hodgef
|
||||
|
||||
---
|
||||
|
||||
@@ -8,7 +11,7 @@ about: Create a report to help improve simple-keyboard
|
||||
As some bugs have been addressed in later versions, please ensure you are running the latest.
|
||||
|
||||
**Describe the bug**
|
||||
A clear and concise description of what the bug is.
|
||||
A clear and concise description of what the bug is. Providing a [sandbox example](https://codesandbox.io/s/vanilla) or code depicting the issue is important, as this will help us reproduce the issue.
|
||||
|
||||
**Screenshots**
|
||||
If applicable, add screenshots to help explain your problem.
|
||||
|
||||
3
.github/ISSUE_TEMPLATE/feature_request.md
vendored
3
.github/ISSUE_TEMPLATE/feature_request.md
vendored
@@ -1,6 +1,9 @@
|
||||
---
|
||||
name: Feature request
|
||||
about: Suggest an idea you'd like to see in simple-keyboard
|
||||
title: ''
|
||||
labels: ''
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
<div align="center">
|
||||
<a href="https://simple-keyboard.com/demo" title="View Demo" target="_blank"><img src="https://franciscohodge.com/project-pages/simple-keyboard/images/simplekeyboard-banner_B.png" align="center" width="100%"></a>
|
||||
<a href="https://simple-keyboard.com/demo" title="View Demo" target="_blank"><img src="https://franciscohodge.com/project-pages/simple-keyboard/images/simple-keyboard-10172018.gif" align="center" width="100%"></a>
|
||||
<a href="https://simple-keyboard.com/demo" title="View Demo" target="_blank"><img src="https://franciscohodge.com/project-pages/simple-keyboard/images/skdemo-4x2.gif" align="center" width="100%"></a>
|
||||
<blockquote>The easily customisable and responsive on-screen virtual keyboard for Javascript projects.</blockquote>
|
||||
<p><a href="https://github.com/hodgef/simple-keyboard/blob/master/LICENSE" target="_blank"><img src="https://img.shields.io/badge/license-MIT-blue.svg" alt="License"></a>
|
||||
<a href="https://www.npmjs.com/package/simple-keyboard" target="_blank"><img src="https://img.shields.io/npm/v/simple-keyboard.svg?style=flat" alt="npm version"></a>
|
||||
<a href="https://travis-ci.org/hodgef/simple-keyboard" target="_blank"><img src="https://travis-ci.org/hodgef/simple-keyboard.svg?branch=master" alt="Build Status"></a>
|
||||
<a href="https://codecov.io/gh/hodgef/simple-keyboard" target="_blank"><img src="https://img.shields.io/codecov/c/github/hodgef/simple-keyboard/master.svg?style=flat" alt="Coverage Status"></a>
|
||||
<a href="https://doc.esdoc.org/github.com/hodgef/simple-keyboard" target="_blank"><img src="https://doc.esdoc.org/github.com/hodgef/simple-keyboard/badge.svg" alt="Documentation Status"></a>
|
||||
<img src="https://img.shields.io/david/dev/hodgef/simple-keyboard.svg" alt="Dev dependencies">
|
||||
<a href="https://www.codacy.com/app/hodgef/simple-keyboard?utm_source=github.com&utm_medium=referral&utm_content=hodgef/simple-keyboard&utm_campaign=Badge_Grade" target="_blank"><img src="https://api.codacy.com/project/badge/Grade/5778fccc6a894701853d9a1f2fb44a76" alt="Codacy Badge"></a>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
@@ -34,7 +35,9 @@ Feel free to browse the [Q&A / Use-cases](https://simple-keyboard.com/qa-use-cas
|
||||
|
||||
### Other versions
|
||||
|
||||
* ReactJS - [react-simple-keyboard](https://github.com/hodgef/react-simple-keyboard)
|
||||
* [React.js](https://github.com/hodgef/react-simple-keyboard)
|
||||
* [Angular](https://simple-keyboard.com/demo)
|
||||
* [Vue.js](https://simple-keyboard.com/demo)
|
||||
|
||||
### Questions?
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*!
|
||||
*
|
||||
* simple-keyboard v2.10.0
|
||||
* simple-keyboard v2.14.0
|
||||
* https://github.com/hodgef/simple-keyboard
|
||||
*
|
||||
* Copyright (c) Francisco Hodge (https://github.com/hodgef)
|
||||
@@ -8,5 +8,5 @@
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
*/body,html{margin:0;padding:0}.simple-keyboard{font-family:HelveticaNeue-Light,Helvetica Neue Light,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif;width:100%;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;box-sizing:border-box;overflow:hidden;touch-action:manipulation}.simple-keyboard .hg-row{display:flex}.simple-keyboard .hg-row:not(:last-child){margin-bottom:5px}.simple-keyboard .hg-row .hg-button:not(:last-child){margin-right:5px}.simple-keyboard .hg-button{display:inline-block;flex-grow:1;cursor:pointer}.hg-standardBtn{max-width:100px}.simple-keyboard.hg-theme-default{background-color:rgba(0,0,0,.1);padding:5px;border-radius:5px}.simple-keyboard.hg-theme-default .hg-button{box-shadow:0 0 3px -1px rgba(0,0,0,.3);height:40px;border-radius:5px;box-sizing:border-box;padding:5px;background:#fff;border-bottom:1px solid #b5b5b5;cursor:pointer;display:flex;align-items:center;justify-content:center}.simple-keyboard.hg-theme-default .hg-button:active{background:#e4e4e4}.simple-keyboard.hg-theme-default.hg-layout-numeric .hg-button{width:33.3%;height:60px;align-items:center;display:flex;justify-content:center}.simple-keyboard.hg-theme-default .hg-button.hg-button-numpadadd,.simple-keyboard.hg-theme-default .hg-button.hg-button-numpadenter{height:85px}.simple-keyboard.hg-theme-default .hg-button.hg-button-numpad0{width:105px}.simple-keyboard.hg-theme-default .hg-button.hg-button-com{max-width:85px}.simple-keyboard.hg-theme-default .hg-button.hg-standardBtn.hg-button-at{max-width:45px}.simple-keyboard.hg-theme-default .hg-button.hg-selectedButton{background:rgba(5,25,70,.53);color:#fff}.simple-keyboard.hg-theme-default .hg-button.hg-standardBtn[data-skbtn=".com"]{max-width:82px}.simple-keyboard.hg-theme-default .hg-button.hg-standardBtn[data-skbtn="@"]{max-width:60px}
|
||||
*/body,html{margin:0;padding:0}.simple-keyboard{font-family:HelveticaNeue-Light,Helvetica Neue Light,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif;width:100%;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;box-sizing:border-box;overflow:hidden;touch-action:manipulation}.simple-keyboard .hg-row{display:flex}.simple-keyboard .hg-row:not(:last-child){margin-bottom:5px}.simple-keyboard .hg-row .hg-button:not(:last-child){margin-right:5px}.simple-keyboard .hg-button{display:inline-block;flex-grow:1;cursor:pointer}.hg-standardBtn{max-width:100px}.simple-keyboard.hg-theme-default{background-color:rgba(0,0,0,.1);padding:5px;border-radius:5px}.simple-keyboard.hg-theme-default .hg-button{box-shadow:0 0 3px -1px rgba(0,0,0,.3);height:40px;border-radius:5px;box-sizing:border-box;padding:5px;background:#fff;border-bottom:1px solid #b5b5b5;cursor:pointer;display:flex;align-items:center;justify-content:center}.simple-keyboard button.hg-button{border-width:0;outline:0;font-size:inherit}.simple-keyboard.hg-theme-default .hg-button:active{background:#e4e4e4}.simple-keyboard.hg-theme-default.hg-layout-numeric .hg-button{width:33.3%;height:60px;align-items:center;display:flex;justify-content:center}.simple-keyboard.hg-theme-default .hg-button.hg-button-numpadadd,.simple-keyboard.hg-theme-default .hg-button.hg-button-numpadenter{height:85px}.simple-keyboard.hg-theme-default .hg-button.hg-button-numpad0{width:105px}.simple-keyboard.hg-theme-default .hg-button.hg-button-com{max-width:85px}.simple-keyboard.hg-theme-default .hg-button.hg-standardBtn.hg-button-at{max-width:45px}.simple-keyboard.hg-theme-default .hg-button.hg-selectedButton{background:rgba(5,25,70,.53);color:#fff}.simple-keyboard.hg-theme-default .hg-button.hg-standardBtn[data-skbtn=".com"]{max-width:82px}.simple-keyboard.hg-theme-default .hg-button.hg-standardBtn[data-skbtn="@"]{max-width:60px}
|
||||
/*# sourceMappingURL=index.css.map */
|
||||
File diff suppressed because one or more lines are too long
199
build/index.d.ts
vendored
Normal file
199
build/index.d.ts
vendored
Normal file
@@ -0,0 +1,199 @@
|
||||
declare module 'simple-keyboard' {
|
||||
interface KeyboardLayoutObject {
|
||||
default: string[];
|
||||
shift?: string[];
|
||||
}
|
||||
|
||||
interface KeyboardButtonTheme {
|
||||
class: string;
|
||||
buttons: string;
|
||||
}
|
||||
|
||||
interface KeyboardOptions {
|
||||
/**
|
||||
* Modify the keyboard layout.
|
||||
*/
|
||||
layout?: KeyboardLayoutObject;
|
||||
|
||||
/**
|
||||
* Specifies which layout should be used.
|
||||
*/
|
||||
layoutName?: string;
|
||||
|
||||
/**
|
||||
* Replaces variable buttons (such as `{bksp}`) with a human-friendly name (e.g.: `backspace`).
|
||||
*/
|
||||
display?: { [button: string]: string };
|
||||
|
||||
/**
|
||||
* By default, when you set the display property, you replace the default one. This setting merges them instead.
|
||||
*/
|
||||
mergeDisplay?: boolean;
|
||||
|
||||
/**
|
||||
* A prop to add your own css classes to the keyboard wrapper. You can add multiple classes separated by a space.
|
||||
*/
|
||||
theme?: string;
|
||||
|
||||
/**
|
||||
* A prop to add your own css classes to one or several buttons.
|
||||
*/
|
||||
buttonTheme?: KeyboardButtonTheme[];
|
||||
|
||||
/**
|
||||
* Runs a `console.log` every time a key is pressed. Displays the buttons pressed and the current input.
|
||||
*/
|
||||
debug?: boolean;
|
||||
|
||||
/**
|
||||
* Specifies whether clicking the "ENTER" button will input a newline (`\n`) or not.
|
||||
*/
|
||||
newLineOnEnter?: boolean;
|
||||
|
||||
/**
|
||||
* Specifies whether clicking the "TAB" button will input a tab character (`\t`) or not.
|
||||
*/
|
||||
tabCharOnTab?: boolean;
|
||||
|
||||
/**
|
||||
* Allows you to use a single simple-keyboard instance for several inputs.
|
||||
*/
|
||||
inputName?: string;
|
||||
|
||||
/**
|
||||
* `number`: Restrains all of simple-keyboard inputs to a certain length. This should be used in addition to the input element’s maxlengthattribute.
|
||||
*
|
||||
* `{ [inputName: string]: number }`: Restrains simple-keyboard’s individual inputs to a certain length. This should be used in addition to the input element’s maxlengthattribute.
|
||||
*/
|
||||
maxLength?:
|
||||
| number
|
||||
| {
|
||||
[inputName: string]: number;
|
||||
};
|
||||
|
||||
/**
|
||||
* When set to true, this option synchronizes the internal input of every simple-keyboard instance.
|
||||
*/
|
||||
syncInstanceInputs?: boolean;
|
||||
|
||||
/**
|
||||
* Enable highlighting of keys pressed on physical keyboard.
|
||||
*/
|
||||
physicalKeyboardHighlight?: boolean;
|
||||
|
||||
/**
|
||||
* Calling preventDefault for the mousedown events keeps the focus on the input.
|
||||
*/
|
||||
preventMouseDownDefault?: boolean;
|
||||
|
||||
/**
|
||||
* Define the text color that the physical keyboard highlighted key should have.
|
||||
*/
|
||||
physicalKeyboardHighlightTextColor?: string;
|
||||
|
||||
/**
|
||||
* Define the background color that the physical keyboard highlighted key should have.
|
||||
*/
|
||||
physicalKeyboardHighlightBgColor?: string;
|
||||
|
||||
/**
|
||||
* Render buttons as a button element instead of a div element.
|
||||
*/
|
||||
useButtonTag?: boolean;
|
||||
|
||||
/**
|
||||
* A prop to ensure characters are always be added/removed at the end of the string.
|
||||
*/
|
||||
disableCaretPositioning?: boolean;
|
||||
|
||||
/**
|
||||
* Restrains input(s) change to the defined regular expression pattern.
|
||||
*/
|
||||
inputPattern?: any;
|
||||
|
||||
/**
|
||||
* Executes the callback function on key press. Returns button layout name (i.e.: "{shift}").
|
||||
*/
|
||||
onKeyPress?: (button: string) => any;
|
||||
|
||||
/**
|
||||
* Executes the callback function on input change. Returns the current input's string.
|
||||
*/
|
||||
onChange?: (input: string) => any;
|
||||
|
||||
/**
|
||||
* Executes the callback function every time simple-keyboard is rendered (e.g: when you change layouts).
|
||||
*/
|
||||
onRender?: () => void;
|
||||
|
||||
/**
|
||||
* Executes the callback function once simple-keyboard is rendered for the first time (on initialization).
|
||||
*/
|
||||
onInit?: () => void;
|
||||
|
||||
/**
|
||||
* Executes the callback function on input change. Returns the input object with all defined inputs.
|
||||
*/
|
||||
onChangeAll?: (inputs: any) => any;
|
||||
}
|
||||
|
||||
class Keyboard {
|
||||
constructor(selector: string, options: KeyboardOptions);
|
||||
constructor(options: KeyboardOptions);
|
||||
options: KeyboardOptions;
|
||||
|
||||
/**
|
||||
* Adds/Modifies an entry to the `buttonTheme`. Basically a way to add a class to a button.
|
||||
* @param {string} buttons List of buttons to select (separated by a space).
|
||||
* @param {string} className Classes to give to the selected buttons (separated by space).
|
||||
*/
|
||||
addButtonTheme(buttons: string, className: string): void;
|
||||
|
||||
/**
|
||||
* Removes/Amends an entry to the `buttonTheme`. Basically a way to remove a class previously added to a button through buttonTheme or addButtonTheme.
|
||||
* @param {string} buttons List of buttons to select (separated by a space).
|
||||
* @param {string} className Classes to give to the selected buttons (separated by space).
|
||||
*/
|
||||
removeButtonTheme(buttons: string, className: string): void;
|
||||
|
||||
/**
|
||||
* Clear the keyboard's input.
|
||||
*
|
||||
* @param {string} [inputName] optional - the internal input to select
|
||||
*/
|
||||
clearInput(inputName?: string): void;
|
||||
|
||||
/**
|
||||
* Get the keyboard’s input (You can also get it from the onChange prop).
|
||||
* @param {string} [inputName] optional - the internal input to select
|
||||
*/
|
||||
getInput(inputName?: string): string;
|
||||
|
||||
/**
|
||||
* Set the keyboard’s input.
|
||||
* @param {string} input the input value
|
||||
* @param {string} inputName optional - the internal input to select
|
||||
*/
|
||||
setInput(input: string, inputName?: string): void;
|
||||
|
||||
/**
|
||||
* Set new option or modify existing ones after initialization.
|
||||
* @param {KeyboardOptions} option The option to set
|
||||
*/
|
||||
setOptions(options: KeyboardOptions): void;
|
||||
|
||||
/**
|
||||
* Send a command to all simple-keyboard instances at once (if you have multiple instances).
|
||||
* @param {function(instance: object, key: string)} callback Function to run on every instance
|
||||
*/
|
||||
dispatch(callback: (instance: any, key: string) => void): void;
|
||||
|
||||
/**
|
||||
* Get the DOM Element of a button. If there are several buttons with the same name, an array of the DOM Elements is returned.
|
||||
* @param {string} button The button layout name to select
|
||||
*/
|
||||
getButtonElement(button: string): HTMLElement | HTMLElement[];
|
||||
}
|
||||
|
||||
export default Keyboard;
|
||||
}
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -79,6 +79,7 @@ module.exports = {
|
||||
appPackageJson: resolveApp('package.json'),
|
||||
appSrc: resolveApp('src'),
|
||||
appSrcLib: resolveApp('src/lib'),
|
||||
appSrcLibTypes: resolveApp('src/lib/@types'),
|
||||
appSrcDemo: resolveApp('src/demo'),
|
||||
appTsConfig: resolveApp('tsconfig.json'),
|
||||
yarnLockFile: resolveApp('yarn.lock'),
|
||||
|
||||
@@ -21,6 +21,7 @@ const getClientEnvironment = require('./env');
|
||||
const ModuleNotFoundPlugin = require('react-dev-utils/ModuleNotFoundPlugin');
|
||||
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin-alt');
|
||||
const typescriptFormatter = require('react-dev-utils/typescriptFormatter');
|
||||
const CopyWebpackPlugin = require('copy-webpack-plugin');
|
||||
const getPackageJson = require('./getPackageJson');
|
||||
|
||||
|
||||
@@ -510,6 +511,12 @@ module.exports = {
|
||||
// https://github.com/jmblog/how-to-optimize-momentjs-with-webpack
|
||||
// You can remove this if you don't use Moment.js:
|
||||
new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
|
||||
new CopyWebpackPlugin([
|
||||
{
|
||||
from: `${paths.appSrcLibTypes}`,
|
||||
to: paths.appLayoutsBuild
|
||||
}
|
||||
]),
|
||||
// Generate a service worker script that will precache, and keep up to date,
|
||||
// the HTML & assets that are part of the Webpack build.
|
||||
/*new WorkboxWebpackPlugin.GenerateSW({
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -175,8 +175,7 @@ This class:</p>
|
||||
<div>
|
||||
|
||||
|
||||
<div data-ice="description"><p>Tracks current cursor position
|
||||
As keys are pressed, text will be added/removed at that position within the input.</p>
|
||||
<div data-ice="description"><p>Only first instance should insall the caret handling events</p>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
@@ -1388,15 +1387,14 @@ As keys are pressed, text will be added/removed at that position within the inpu
|
||||
<span class="right-info">
|
||||
|
||||
|
||||
<span data-ice="source"><span><a href="file/src/lib/components/Keyboard.js.html#lineNumber541">source</a></span></span>
|
||||
<span data-ice="source"><span><a href="file/src/lib/components/Keyboard.js.html#lineNumber512">source</a></span></span>
|
||||
</span>
|
||||
</h3>
|
||||
|
||||
|
||||
|
||||
|
||||
<div data-ice="description"><p>Tracks current cursor position
|
||||
As keys are pressed, text will be added/removed at that position within the input.</p>
|
||||
<div data-ice="description"><p>Only first instance should insall the caret handling events</p>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -1433,7 +1431,7 @@ As keys are pressed, text will be added/removed at that position within the inpu
|
||||
<span class="right-info">
|
||||
|
||||
|
||||
<span data-ice="source"><span><a href="file/src/lib/components/Keyboard.js.html#lineNumber619">source</a></span></span>
|
||||
<span data-ice="source"><span><a href="file/src/lib/components/Keyboard.js.html#lineNumber634">source</a></span></span>
|
||||
</span>
|
||||
</h3>
|
||||
|
||||
@@ -1477,7 +1475,7 @@ As keys are pressed, text will be added/removed at that position within the inpu
|
||||
<span class="right-info">
|
||||
|
||||
|
||||
<span data-ice="source"><span><a href="file/src/lib/components/Keyboard.js.html#lineNumber629">source</a></span></span>
|
||||
<span data-ice="source"><span><a href="file/src/lib/components/Keyboard.js.html#lineNumber644">source</a></span></span>
|
||||
</span>
|
||||
</h3>
|
||||
|
||||
@@ -1607,7 +1605,7 @@ As keys are pressed, text will be added/removed at that position within the inpu
|
||||
<span class="right-info">
|
||||
|
||||
|
||||
<span data-ice="source"><span><a href="file/src/lib/components/Keyboard.js.html#lineNumber783">source</a></span></span>
|
||||
<span data-ice="source"><span><a href="file/src/lib/components/Keyboard.js.html#lineNumber798">source</a></span></span>
|
||||
</span>
|
||||
</h3>
|
||||
|
||||
@@ -2199,7 +2197,7 @@ keyboard.clearInput();</code></pre>
|
||||
<span class="right-info">
|
||||
|
||||
|
||||
<span data-ice="source"><span><a href="file/src/lib/components/Keyboard.js.html#lineNumber585">source</a></span></span>
|
||||
<span data-ice="source"><span><a href="file/src/lib/components/Keyboard.js.html#lineNumber600">source</a></span></span>
|
||||
</span>
|
||||
</h3>
|
||||
|
||||
@@ -2414,7 +2412,7 @@ keyboard.clearInput();</code></pre>
|
||||
<span class="right-info">
|
||||
|
||||
|
||||
<span data-ice="source"><span><a href="file/src/lib/components/Keyboard.js.html#lineNumber521">source</a></span></span>
|
||||
<span data-ice="source"><span><a href="file/src/lib/components/Keyboard.js.html#lineNumber535">source</a></span></span>
|
||||
</span>
|
||||
</h3>
|
||||
|
||||
@@ -3086,7 +3084,7 @@ Used interally between re-renders.</p>
|
||||
<span class="right-info">
|
||||
|
||||
|
||||
<span data-ice="source"><span><a href="file/src/lib/components/Keyboard.js.html#lineNumber595">source</a></span></span>
|
||||
<span data-ice="source"><span><a href="file/src/lib/components/Keyboard.js.html#lineNumber610">source</a></span></span>
|
||||
</span>
|
||||
</h3>
|
||||
|
||||
@@ -3130,7 +3128,7 @@ Used interally between re-renders.</p>
|
||||
<span class="right-info">
|
||||
|
||||
|
||||
<span data-ice="source"><span><a href="file/src/lib/components/Keyboard.js.html#lineNumber552">source</a></span></span>
|
||||
<span data-ice="source"><span><a href="file/src/lib/components/Keyboard.js.html#lineNumber567">source</a></span></span>
|
||||
</span>
|
||||
</h3>
|
||||
|
||||
@@ -3174,7 +3172,7 @@ Used interally between re-renders.</p>
|
||||
<span class="right-info">
|
||||
|
||||
|
||||
<span data-ice="source"><span><a href="file/src/lib/components/Keyboard.js.html#lineNumber577">source</a></span></span>
|
||||
<span data-ice="source"><span><a href="file/src/lib/components/Keyboard.js.html#lineNumber592">source</a></span></span>
|
||||
</span>
|
||||
</h3>
|
||||
|
||||
@@ -3218,7 +3216,7 @@ Used interally between re-renders.</p>
|
||||
<span class="right-info">
|
||||
|
||||
|
||||
<span data-ice="source"><span><a href="file/src/lib/components/Keyboard.js.html#lineNumber569">source</a></span></span>
|
||||
<span data-ice="source"><span><a href="file/src/lib/components/Keyboard.js.html#lineNumber584">source</a></span></span>
|
||||
</span>
|
||||
</h3>
|
||||
|
||||
@@ -3342,7 +3340,7 @@ Used interally between re-renders.</p>
|
||||
<span class="right-info">
|
||||
|
||||
|
||||
<span data-ice="source"><span><a href="file/src/lib/components/Keyboard.js.html#lineNumber636">source</a></span></span>
|
||||
<span data-ice="source"><span><a href="file/src/lib/components/Keyboard.js.html#lineNumber651">source</a></span></span>
|
||||
</span>
|
||||
</h3>
|
||||
|
||||
|
||||
@@ -501,6 +501,35 @@
|
||||
<td>
|
||||
|
||||
|
||||
</td>
|
||||
</tr>
|
||||
<tr data-ice="target">
|
||||
<td>
|
||||
<span class="access" data-ice="access">public</span>
|
||||
|
||||
|
||||
|
||||
<span class="override" data-ice="override"></span>
|
||||
</td>
|
||||
<td>
|
||||
<div>
|
||||
<p>
|
||||
|
||||
|
||||
|
||||
<span class="code" data-ice="name"><span><a href="class/src/lib/services/Utilities.js~Utilities.html#instance-method-updateCaretPosAction">updateCaretPosAction</a></span></span><span class="code" data-ice="signature">(instance: <span><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object">object</a></span>, length: <span><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number">number</a></span>, minus: <span><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean">boolean</a></span>)</span>
|
||||
</p>
|
||||
</div>
|
||||
<div>
|
||||
|
||||
|
||||
<div data-ice="description"><p>Action method of updateCaretPos</p>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
|
||||
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
@@ -572,7 +601,7 @@
|
||||
<span class="right-info">
|
||||
|
||||
|
||||
<span data-ice="source"><span><a href="file/src/lib/services/Utilities.js.html#lineNumber308">source</a></span></span>
|
||||
<span data-ice="source"><span><a href="file/src/lib/services/Utilities.js.html#lineNumber322">source</a></span></span>
|
||||
</span>
|
||||
</h3>
|
||||
|
||||
@@ -661,7 +690,7 @@
|
||||
<span class="right-info">
|
||||
|
||||
|
||||
<span data-ice="source"><span><a href="file/src/lib/services/Utilities.js.html#lineNumber202">source</a></span></span>
|
||||
<span data-ice="source"><span><a href="file/src/lib/services/Utilities.js.html#lineNumber224">source</a></span></span>
|
||||
</span>
|
||||
</h3>
|
||||
|
||||
@@ -755,7 +784,7 @@
|
||||
<span class="right-info">
|
||||
|
||||
|
||||
<span data-ice="source"><span><a href="file/src/lib/services/Utilities.js.html#lineNumber345">source</a></span></span>
|
||||
<span data-ice="source"><span><a href="file/src/lib/services/Utilities.js.html#lineNumber359">source</a></span></span>
|
||||
</span>
|
||||
</h3>
|
||||
|
||||
@@ -828,7 +857,7 @@
|
||||
<span class="right-info">
|
||||
|
||||
|
||||
<span data-ice="source"><span><a href="file/src/lib/services/Utilities.js.html#lineNumber355">source</a></span></span>
|
||||
<span data-ice="source"><span><a href="file/src/lib/services/Utilities.js.html#lineNumber369">source</a></span></span>
|
||||
</span>
|
||||
</h3>
|
||||
|
||||
@@ -908,7 +937,7 @@
|
||||
<span class="right-info">
|
||||
|
||||
|
||||
<span data-ice="source"><span><a href="file/src/lib/services/Utilities.js.html#lineNumber32">source</a></span></span>
|
||||
<span data-ice="source"><span><a href="file/src/lib/services/Utilities.js.html#lineNumber33">source</a></span></span>
|
||||
</span>
|
||||
</h3>
|
||||
|
||||
@@ -982,7 +1011,7 @@
|
||||
<span class="right-info">
|
||||
|
||||
|
||||
<span data-ice="source"><span><a href="file/src/lib/services/Utilities.js.html#lineNumber116">source</a></span></span>
|
||||
<span data-ice="source"><span><a href="file/src/lib/services/Utilities.js.html#lineNumber117">source</a></span></span>
|
||||
</span>
|
||||
</h3>
|
||||
|
||||
@@ -1069,7 +1098,7 @@
|
||||
<span class="right-info">
|
||||
|
||||
|
||||
<span data-ice="source"><span><a href="file/src/lib/services/Utilities.js.html#lineNumber46">source</a></span></span>
|
||||
<span data-ice="source"><span><a href="file/src/lib/services/Utilities.js.html#lineNumber47">source</a></span></span>
|
||||
</span>
|
||||
</h3>
|
||||
|
||||
@@ -1125,7 +1154,7 @@
|
||||
<span class="right-info">
|
||||
|
||||
|
||||
<span data-ice="source"><span><a href="file/src/lib/services/Utilities.js.html#lineNumber136">source</a></span></span>
|
||||
<span data-ice="source"><span><a href="file/src/lib/services/Utilities.js.html#lineNumber137">source</a></span></span>
|
||||
</span>
|
||||
</h3>
|
||||
|
||||
@@ -1226,7 +1255,7 @@
|
||||
<span class="right-info">
|
||||
|
||||
|
||||
<span data-ice="source"><span><a href="file/src/lib/services/Utilities.js.html#lineNumber284">source</a></span></span>
|
||||
<span data-ice="source"><span><a href="file/src/lib/services/Utilities.js.html#lineNumber298">source</a></span></span>
|
||||
</span>
|
||||
</h3>
|
||||
|
||||
@@ -1310,7 +1339,7 @@
|
||||
<span class="right-info">
|
||||
|
||||
|
||||
<span data-ice="source"><span><a href="file/src/lib/services/Utilities.js.html#lineNumber336">source</a></span></span>
|
||||
<span data-ice="source"><span><a href="file/src/lib/services/Utilities.js.html#lineNumber350">source</a></span></span>
|
||||
</span>
|
||||
</h3>
|
||||
|
||||
@@ -1366,7 +1395,7 @@
|
||||
<span class="right-info">
|
||||
|
||||
|
||||
<span data-ice="source"><span><a href="file/src/lib/services/Utilities.js.html#lineNumber233">source</a></span></span>
|
||||
<span data-ice="source"><span><a href="file/src/lib/services/Utilities.js.html#lineNumber251">source</a></span></span>
|
||||
</span>
|
||||
</h3>
|
||||
|
||||
@@ -1453,7 +1482,7 @@
|
||||
<span class="right-info">
|
||||
|
||||
|
||||
<span data-ice="source"><span><a href="file/src/lib/services/Utilities.js.html#lineNumber185">source</a></span></span>
|
||||
<span data-ice="source"><span><a href="file/src/lib/services/Utilities.js.html#lineNumber186">source</a></span></span>
|
||||
</span>
|
||||
</h3>
|
||||
|
||||
@@ -1508,6 +1537,81 @@
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
<div class="detail" data-ice="detail">
|
||||
<h3 data-ice="anchor" id="instance-method-updateCaretPosAction">
|
||||
<span class="access" data-ice="access">public</span>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<span class="code" data-ice="name">updateCaretPosAction</span><span class="code" data-ice="signature">(instance: <span><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object">object</a></span>, length: <span><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number">number</a></span>, minus: <span><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean">boolean</a></span>)</span>
|
||||
<span class="right-info">
|
||||
|
||||
|
||||
<span data-ice="source"><span><a href="file/src/lib/services/Utilities.js.html#lineNumber203">source</a></span></span>
|
||||
</span>
|
||||
</h3>
|
||||
|
||||
|
||||
|
||||
|
||||
<div data-ice="description"><p>Action method of updateCaretPos</p>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<div data-ice="properties"><div data-ice="properties">
|
||||
<h4 data-ice="title">Params:</h4>
|
||||
<table class="params">
|
||||
<thead>
|
||||
<tr><td>Name</td><td>Type</td><td>Attribute</td><td>Description</td></tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
|
||||
<tr data-ice="property" data-depth="0">
|
||||
<td data-ice="name" class="code" data-depth="0">instance</td>
|
||||
<td data-ice="type" class="code"><span><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object">object</a></span></td>
|
||||
<td data-ice="appendix"></td>
|
||||
<td data-ice="description"><p>The instance whose position should be updated</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr data-ice="property" data-depth="0">
|
||||
<td data-ice="name" class="code" data-depth="0">length</td>
|
||||
<td data-ice="type" class="code"><span><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number">number</a></span></td>
|
||||
<td data-ice="appendix"></td>
|
||||
<td data-ice="description"><p>Represents by how many characters the input should be moved</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr data-ice="property" data-depth="0">
|
||||
<td data-ice="name" class="code" data-depth="0">minus</td>
|
||||
<td data-ice="type" class="code"><span><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean">boolean</a></span></td>
|
||||
<td data-ice="appendix"></td>
|
||||
<td data-ice="description"><p>Whether the cursor should be moved to the left or not.</p>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"coverage": "100%",
|
||||
"expectCount": 77,
|
||||
"actualCount": 77,
|
||||
"expectCount": 78,
|
||||
"actualCount": 78,
|
||||
"files": {
|
||||
"src/demo/App.js": {
|
||||
"expectCount": 8,
|
||||
@@ -24,8 +24,8 @@
|
||||
"undocumentLines": []
|
||||
},
|
||||
"src/lib/services/Utilities.js": {
|
||||
"expectCount": 15,
|
||||
"actualCount": 15,
|
||||
"expectCount": 16,
|
||||
"actualCount": 16,
|
||||
"undocumentLines": []
|
||||
},
|
||||
"src/lib/tests/TestUtility.js": {
|
||||
|
||||
@@ -85,7 +85,7 @@ class App {
|
||||
</div>
|
||||
`);
|
||||
|
||||
document.querySelector('.input').addEventListener('change', (event) => {
|
||||
document.querySelector('.input').addEventListener('input', (event) => {
|
||||
this.keyboard.setInput(event.target.value);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -548,44 +548,59 @@ class SimpleKeyboard {
|
||||
* Retrieves the current cursor position within a input or textarea (if any)
|
||||
*/
|
||||
handleCaret(){
|
||||
/**
|
||||
* Only first instance should insall the caret handling events
|
||||
*/
|
||||
this.caretPosition = null;
|
||||
let simpleKeyboardInstances = window['SimpleKeyboardInstances'];
|
||||
|
||||
if(
|
||||
(
|
||||
simpleKeyboardInstances &&
|
||||
Object.keys(simpleKeyboardInstances)[0] === this.utilities.camelCase(this.keyboardDOMClass)
|
||||
) ||
|
||||
!simpleKeyboardInstances
|
||||
){
|
||||
if(this.options.debug){
|
||||
console.log("Caret handling started");
|
||||
console.log(`Caret handling started (${this.keyboardDOMClass})`)
|
||||
}
|
||||
|
||||
document.addEventListener("keyup", this.caretEventHandler);
|
||||
document.addEventListener("mouseup", this.caretEventHandler);
|
||||
document.addEventListener("touchend", this.caretEventHandler);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called by {@link handleCaret} when an event that warrants a cursor position update is triggered
|
||||
*/
|
||||
caretEventHandler(event){
|
||||
let targetTagName;
|
||||
|
||||
if(this.isMouseHold){
|
||||
this.isMouseHold = false;
|
||||
}
|
||||
|
||||
if(event.target.tagName){
|
||||
targetTagName = event.target.tagName.toLowerCase();
|
||||
}
|
||||
|
||||
this.dispatch(instance => {
|
||||
if(instance.isMouseHold){
|
||||
instance.isMouseHold = false;
|
||||
}
|
||||
|
||||
if(
|
||||
(targetTagName === "textarea" ||
|
||||
targetTagName === "input") &&
|
||||
!this.options.disableCaretPositioning
|
||||
!instance.options.disableCaretPositioning
|
||||
){
|
||||
/**
|
||||
* Tracks current cursor position
|
||||
* As keys are pressed, text will be added/removed at that position within the input.
|
||||
*/
|
||||
this.caretPosition = event.target.selectionStart;
|
||||
instance.caretPosition = event.target.selectionStart;
|
||||
|
||||
if(this.options.debug){
|
||||
console.log('Caret at: ', event.target.selectionStart, event.target.tagName.toLowerCase());
|
||||
if(instance.options.debug){
|
||||
console.log('Caret at: ', event.target.selectionStart, event.target.tagName.toLowerCase(), `(${instance.keyboardDOMClass})`);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -593,7 +608,7 @@ class SimpleKeyboard {
|
||||
*/
|
||||
onInit(){
|
||||
if(this.options.debug){
|
||||
console.log("Initialized");
|
||||
console.log(`${this.keyboardDOMClass} Initialized`)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -60,6 +60,7 @@ class Utilities {
|
||||
this.getButtonDisplayName = this.getButtonDisplayName.bind(this);
|
||||
this.getUpdatedInput = this.getUpdatedInput.bind(this);
|
||||
this.updateCaretPos = this.updateCaretPos.bind(this);
|
||||
this.updateCaretPosAction = this.updateCaretPosAction.bind(this);
|
||||
this.isMaxLengthReached = this.isMaxLengthReached.bind(this);
|
||||
this.camelCase = this.camelCase.bind(this);
|
||||
this.countInArray = this.countInArray.bind(this);
|
||||
@@ -225,11 +226,32 @@ class Utilities {
|
||||
* @param {boolean} minus Whether the cursor should be moved to the left or not.
|
||||
*/
|
||||
updateCaretPos(length, minus){
|
||||
if(minus){
|
||||
if(this.simpleKeyboardInstance.caretPosition > 0)
|
||||
this.simpleKeyboardInstance.caretPosition = this.simpleKeyboardInstance.caretPosition - length;
|
||||
if(this.simpleKeyboardInstance.options.syncInstanceInputs){
|
||||
this.simpleKeyboardInstance.dispatch(instance => {
|
||||
this.updateCaretPosAction(instance, length, minus);
|
||||
});
|
||||
} else {
|
||||
this.simpleKeyboardInstance.caretPosition = this.simpleKeyboardInstance.caretPosition + length;
|
||||
this.updateCaretPosAction(this.simpleKeyboardInstance, length, minus);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Action method of updateCaretPos
|
||||
*
|
||||
* @param {object} instance The instance whose position should be updated
|
||||
* @param {number} length Represents by how many characters the input should be moved
|
||||
* @param {boolean} minus Whether the cursor should be moved to the left or not.
|
||||
*/
|
||||
updateCaretPosAction(instance, length, minus){
|
||||
if(minus){
|
||||
if(instance.caretPosition > 0)
|
||||
instance.caretPosition = instance.caretPosition - length;
|
||||
} else {
|
||||
instance.caretPosition = instance.caretPosition + length;
|
||||
}
|
||||
|
||||
if(this.simpleKeyboardInstance.options.debug){
|
||||
console.log("Caret at:", instance.caretPosition, `(${instance.keyboardDOMClass})`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -258,10 +280,6 @@ class Utilities {
|
||||
|
||||
}
|
||||
|
||||
if(this.simpleKeyboardInstance.options.debug && moveCaret){
|
||||
console.log("Caret at:", position);
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
@@ -310,10 +328,6 @@ class Utilities {
|
||||
}
|
||||
}
|
||||
|
||||
if(this.simpleKeyboardInstance.options.debug && moveCaret){
|
||||
console.log("Caret at:", this.simpleKeyboardInstance.caretPosition);
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
/**
|
||||
@@ -397,7 +411,6 @@ class Utilities {
|
||||
countInArray(array, value){
|
||||
return array.reduce((n, x) => n + (x === value), 0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default Utilities;</code></pre>
|
||||
|
||||
262
docs/index.json
262
docs/index.json
File diff suppressed because one or more lines are too long
@@ -755,6 +755,12 @@ window.esdocSearchIndex = [
|
||||
"src/lib/services/Utilities.js~Utilities#updateCaretPos",
|
||||
"method"
|
||||
],
|
||||
[
|
||||
"src/lib/services/utilities.js~utilities#updatecaretposaction",
|
||||
"class/src/lib/services/Utilities.js~Utilities.html#instance-method-updateCaretPosAction",
|
||||
"src/lib/services/Utilities.js~Utilities#updateCaretPosAction",
|
||||
"method"
|
||||
],
|
||||
[
|
||||
"src/lib/tests/testutility.js",
|
||||
"file/src/lib/tests/TestUtility.js.html",
|
||||
|
||||
@@ -39,7 +39,7 @@
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
<div class="content" data-ice="content"><h1>Source <img data-ice="coverageBadge" src="./badge.svg"><span data-ice="totalCoverageCount" class="total-coverage-count">77/77</span></h1>
|
||||
<div class="content" data-ice="content"><h1>Source <img data-ice="coverageBadge" src="./badge.svg"><span data-ice="totalCoverageCount" class="total-coverage-count">78/78</span></h1>
|
||||
|
||||
<table class="files-summary" data-ice="files" data-use-coverage="true">
|
||||
<thead>
|
||||
@@ -58,9 +58,9 @@
|
||||
<td data-ice="filePath"><span><a href="file/src/demo/App.js.html">src/demo/App.js</a></span></td>
|
||||
<td data-ice="identifier" class="identifiers"><span><a href="class/src/demo/App.js~App.html">App</a></span></td>
|
||||
<td class="coverage"><span data-ice="coverage">100 %</span><span data-ice="coverageCount" class="coverage-count">8/8</span></td>
|
||||
<td style="display: none;" data-ice="size">1919 byte</td>
|
||||
<td style="display: none;" data-ice="size">1918 byte</td>
|
||||
<td style="display: none;" data-ice="lines">84</td>
|
||||
<td style="display: none;" data-ice="updated">2018-11-01 00:54:03 (UTC)</td>
|
||||
<td style="display: none;" data-ice="updated">2018-11-01 01:59:07 (UTC)</td>
|
||||
</tr>
|
||||
<tr data-ice="file">
|
||||
<td data-ice="filePath"><span><a href="file/src/demo/index.js.html">src/demo/index.js</a></span></td>
|
||||
@@ -68,15 +68,15 @@
|
||||
<td class="coverage"><span data-ice="coverage">-</span></td>
|
||||
<td style="display: none;" data-ice="size">70 byte</td>
|
||||
<td style="display: none;" data-ice="lines">5</td>
|
||||
<td style="display: none;" data-ice="updated">2018-11-01 00:54:03 (UTC)</td>
|
||||
<td style="display: none;" data-ice="updated">2018-11-06 21:41:50 (UTC)</td>
|
||||
</tr>
|
||||
<tr data-ice="file">
|
||||
<td data-ice="filePath"><span><a href="file/src/lib/components/Keyboard.js.html">src/lib/components/Keyboard.js</a></span></td>
|
||||
<td data-ice="identifier" class="identifiers"><span><a href="class/src/lib/components/Keyboard.js~SimpleKeyboard.html">SimpleKeyboard</a></span></td>
|
||||
<td class="coverage"><span data-ice="coverage">100 %</span><span data-ice="coverageCount" class="coverage-count">41/41</span></td>
|
||||
<td style="display: none;" data-ice="size">25831 byte</td>
|
||||
<td style="display: none;" data-ice="lines">800</td>
|
||||
<td style="display: none;" data-ice="updated">2018-11-01 00:59:59 (UTC)</td>
|
||||
<td style="display: none;" data-ice="size">26391 byte</td>
|
||||
<td style="display: none;" data-ice="lines">815</td>
|
||||
<td style="display: none;" data-ice="updated">2018-11-01 01:52:55 (UTC)</td>
|
||||
</tr>
|
||||
<tr data-ice="file">
|
||||
<td data-ice="filePath"><span><a href="file/src/lib/index.js.html">src/lib/index.js</a></span></td>
|
||||
@@ -84,7 +84,7 @@
|
||||
<td class="coverage"><span data-ice="coverage">-</span></td>
|
||||
<td style="display: none;" data-ice="size">85 byte</td>
|
||||
<td style="display: none;" data-ice="lines">2</td>
|
||||
<td style="display: none;" data-ice="updated">2018-11-01 00:54:03 (UTC)</td>
|
||||
<td style="display: none;" data-ice="updated">2018-11-06 21:41:50 (UTC)</td>
|
||||
</tr>
|
||||
<tr data-ice="file">
|
||||
<td data-ice="filePath"><span><a href="file/src/lib/services/KeyboardLayout.js.html">src/lib/services/KeyboardLayout.js</a></span></td>
|
||||
@@ -92,7 +92,7 @@
|
||||
<td class="coverage"><span data-ice="coverage">100 %</span><span data-ice="coverageCount" class="coverage-count">2/2</span></td>
|
||||
<td style="display: none;" data-ice="size">746 byte</td>
|
||||
<td style="display: none;" data-ice="lines">28</td>
|
||||
<td style="display: none;" data-ice="updated">2018-11-01 00:54:03 (UTC)</td>
|
||||
<td style="display: none;" data-ice="updated">2018-11-06 21:41:48 (UTC)</td>
|
||||
</tr>
|
||||
<tr data-ice="file">
|
||||
<td data-ice="filePath"><span><a href="file/src/lib/services/PhysicalKeyboard.js.html">src/lib/services/PhysicalKeyboard.js</a></span></td>
|
||||
@@ -100,15 +100,15 @@
|
||||
<td class="coverage"><span data-ice="coverage">100 %</span><span data-ice="coverageCount" class="coverage-count">5/5</span></td>
|
||||
<td style="display: none;" data-ice="size">2908 byte</td>
|
||||
<td style="display: none;" data-ice="lines">96</td>
|
||||
<td style="display: none;" data-ice="updated">2018-11-01 00:54:03 (UTC)</td>
|
||||
<td style="display: none;" data-ice="updated">2018-11-06 21:41:48 (UTC)</td>
|
||||
</tr>
|
||||
<tr data-ice="file">
|
||||
<td data-ice="filePath"><span><a href="file/src/lib/services/Utilities.js.html">src/lib/services/Utilities.js</a></span></td>
|
||||
<td data-ice="identifier" class="identifiers"><span><a href="class/src/lib/services/Utilities.js~Utilities.html">Utilities</a></span></td>
|
||||
<td class="coverage"><span data-ice="coverage">100 %</span><span data-ice="coverageCount" class="coverage-count">15/15</span></td>
|
||||
<td style="display: none;" data-ice="size">11188 byte</td>
|
||||
<td style="display: none;" data-ice="lines">360</td>
|
||||
<td style="display: none;" data-ice="updated">2018-11-01 00:54:03 (UTC)</td>
|
||||
<td class="coverage"><span data-ice="coverage">100 %</span><span data-ice="coverageCount" class="coverage-count">16/16</span></td>
|
||||
<td style="display: none;" data-ice="size">11708 byte</td>
|
||||
<td style="display: none;" data-ice="lines">373</td>
|
||||
<td style="display: none;" data-ice="updated">2018-11-01 01:55:18 (UTC)</td>
|
||||
</tr>
|
||||
<tr data-ice="file">
|
||||
<td data-ice="filePath"><span><a href="file/src/lib/tests/TestUtility.js.html">src/lib/tests/TestUtility.js</a></span></td>
|
||||
@@ -116,7 +116,7 @@
|
||||
<td class="coverage"><span data-ice="coverage">100 %</span><span data-ice="coverageCount" class="coverage-count">6/6</span></td>
|
||||
<td style="display: none;" data-ice="size">2830 byte</td>
|
||||
<td style="display: none;" data-ice="lines">106</td>
|
||||
<td style="display: none;" data-ice="updated">2018-11-01 00:54:03 (UTC)</td>
|
||||
<td style="display: none;" data-ice="updated">2018-11-06 21:41:47 (UTC)</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
2793
package-lock.json
generated
2793
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
81
package.json
81
package.json
@@ -1,8 +1,9 @@
|
||||
{
|
||||
"name": "simple-keyboard",
|
||||
"version": "2.10.0",
|
||||
"version": "2.14.0",
|
||||
"description": "On-screen Javascript Virtual Keyboard",
|
||||
"main": "build/index.js",
|
||||
"types": "build/index.d.ts",
|
||||
"scripts": {
|
||||
"start": "node scripts/start.js",
|
||||
"build": "node scripts/build.js",
|
||||
@@ -34,73 +35,79 @@
|
||||
"touchscreen",
|
||||
"touch-screen",
|
||||
"kiosk",
|
||||
"osk"
|
||||
"osk",
|
||||
"js"
|
||||
],
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"@babel/core": "7.1.0",
|
||||
"@babel/plugin-proposal-class-properties": "^7.1.0",
|
||||
"@babel/preset-env": "^7.1.6",
|
||||
"@babel/core": "7.2.2",
|
||||
"@babel/plugin-proposal-class-properties": "^7.2.3",
|
||||
"@babel/preset-env": "^7.2.3",
|
||||
"@babel/preset-react": "^7.0.0",
|
||||
"@svgr/webpack": "4.0.3",
|
||||
"@svgr/webpack": "4.1.0",
|
||||
"babel-core": "7.0.0-bridge.0",
|
||||
"babel-eslint": "9.0.0",
|
||||
"babel-eslint": "10.0.1",
|
||||
"babel-jest": "23.6.0",
|
||||
"babel-loader": "8.0.4",
|
||||
"babel-plugin-named-asset-import": "^0.2.3",
|
||||
"babel-preset-react-app": "^6.1.0",
|
||||
"babel-loader": "8.0.5",
|
||||
"babel-plugin-named-asset-import": "^0.3.0",
|
||||
"babel-preset-react-app": "^7.0.0",
|
||||
"bfj": "6.1.1",
|
||||
"case-sensitive-paths-webpack-plugin": "2.1.2",
|
||||
"chalk": "2.4.1",
|
||||
"css-loader": "1.0.1",
|
||||
"dotenv": "6.0.0",
|
||||
"chalk": "2.4.2",
|
||||
"copy-webpack-plugin": "^4.6.0",
|
||||
"css-loader": "2.1.0",
|
||||
"dotenv": "6.2.0",
|
||||
"dotenv-expand": "4.2.0",
|
||||
"esdoc": "^1.1.0",
|
||||
"esdoc-ecmascript-proposal-plugin": "^1.0.0",
|
||||
"esdoc-standard-plugin": "^1.0.0",
|
||||
"eslint": "5.9.0",
|
||||
"eslint-config-react-app": "^3.0.5",
|
||||
"eslint": "5.12.0",
|
||||
"eslint-config-react-app": "^3.0.6",
|
||||
"eslint-loader": "2.1.1",
|
||||
"eslint-plugin-flowtype": "2.50.3",
|
||||
"eslint-plugin-flowtype": "3.2.0",
|
||||
"eslint-plugin-import": "2.14.0",
|
||||
"eslint-plugin-jsx-a11y": "6.1.2",
|
||||
"eslint-plugin-react": "7.11.1",
|
||||
"file-loader": "2.0.0",
|
||||
"eslint-plugin-react": "7.12.3",
|
||||
"file-loader": "3.0.1",
|
||||
"fork-ts-checker-webpack-plugin-alt": "0.4.14",
|
||||
"fs-extra": "7.0.0",
|
||||
"har-validator": "^5.1.3",
|
||||
"html-webpack-plugin": "4.0.0-beta.4",
|
||||
"fs-extra": "7.0.1",
|
||||
"html-webpack-plugin": "4.0.0-beta.5",
|
||||
"identity-obj-proxy": "3.0.0",
|
||||
"jest": "23.6.0",
|
||||
"jest-pnp-resolver": "1.0.1",
|
||||
"jest-pnp-resolver": "1.0.2",
|
||||
"jest-resolve": "23.6.0",
|
||||
"mini-css-extract-plugin": "0.4.4",
|
||||
"mini-css-extract-plugin": "0.5.0",
|
||||
"optimize-css-assets-webpack-plugin": "5.0.1",
|
||||
"pnp-webpack-plugin": "1.2.0",
|
||||
"pnp-webpack-plugin": "1.2.1",
|
||||
"postcss-flexbugs-fixes": "4.1.0",
|
||||
"postcss-loader": "3.0.0",
|
||||
"postcss-preset-env": "6.0.6",
|
||||
"postcss-preset-env": "6.5.0",
|
||||
"postcss-safe-parser": "4.0.1",
|
||||
"react": "^16.6.1",
|
||||
"react-app-polyfill": "^0.1.3",
|
||||
"react-dev-utils": "^6.1.1",
|
||||
"react-dom": "^16.6.1",
|
||||
"resolve": "1.8.1",
|
||||
"react": "^16.7.0",
|
||||
"react-app-polyfill": "^0.2.0",
|
||||
"react-dev-utils": "^7.0.1",
|
||||
"react-dom": "^16.7.0",
|
||||
"resolve": "1.9.0",
|
||||
"sass-loader": "7.1.0",
|
||||
"style-loader": "0.23.0",
|
||||
"terser-webpack-plugin": "1.1.0",
|
||||
"url-loader": "1.1.1",
|
||||
"webpack": "4.25.1",
|
||||
"webpack-dev-server": "3.1.10",
|
||||
"style-loader": "0.23.1",
|
||||
"terser-webpack-plugin": "1.2.1",
|
||||
"url-loader": "1.1.2",
|
||||
"webpack": "4.28.3",
|
||||
"webpack-dev-server": "3.1.14",
|
||||
"webpack-manifest-plugin": "2.0.4",
|
||||
"workbox-webpack-plugin": "3.6.3"
|
||||
},
|
||||
"eslintConfig": {
|
||||
"extends": "react-app"
|
||||
"extends": "react-app",
|
||||
"settings": {
|
||||
"react": {
|
||||
"pragma": "React",
|
||||
"version": "detect"
|
||||
}
|
||||
}
|
||||
},
|
||||
"browserslist": [
|
||||
">0.2%",
|
||||
"not dead",
|
||||
"not ie <= 11",
|
||||
"not op_mini all"
|
||||
],
|
||||
|
||||
@@ -31,7 +31,7 @@ class App {
|
||||
onChange: input => this.onChange(input),
|
||||
onKeyPress: button => this.onKeyPress(button),
|
||||
newLineOnEnter: true,
|
||||
physicalKeyboardHighlight: true,
|
||||
physicalKeyboardHighlight: true
|
||||
});
|
||||
|
||||
/**
|
||||
@@ -43,7 +43,7 @@ class App {
|
||||
</div>
|
||||
`);
|
||||
|
||||
document.querySelector('.input').addEventListener('change', (event) => {
|
||||
document.querySelector('.input').addEventListener('input', (event) => {
|
||||
this.keyboard.setInput(event.target.value);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
#root .simple-keyboard-preview {
|
||||
background: rgba(0,0,0,0.8);
|
||||
border: 20px solid rgba(0,0,0,0.1);
|
||||
height: 260px;
|
||||
height: 200px;
|
||||
border-top-right-radius: 5px;
|
||||
border-top-left-radius: 5px;
|
||||
padding: 10px;
|
||||
|
||||
@@ -48,7 +48,7 @@ it('Demo input change will work', () => {
|
||||
demo.onDOMLoaded();
|
||||
|
||||
document.body.querySelector('.input').value = "test";
|
||||
document.body.querySelector('.input').dispatchEvent(new Event('change'));
|
||||
document.body.querySelector('.input').dispatchEvent(new Event('input'));
|
||||
|
||||
expect(demo.keyboard.getInput()).toBe("test");
|
||||
});
|
||||
|
||||
199
src/lib/@types/index.d.ts
vendored
Normal file
199
src/lib/@types/index.d.ts
vendored
Normal file
@@ -0,0 +1,199 @@
|
||||
declare module 'simple-keyboard' {
|
||||
interface KeyboardLayoutObject {
|
||||
default: string[];
|
||||
shift?: string[];
|
||||
}
|
||||
|
||||
interface KeyboardButtonTheme {
|
||||
class: string;
|
||||
buttons: string;
|
||||
}
|
||||
|
||||
interface KeyboardOptions {
|
||||
/**
|
||||
* Modify the keyboard layout.
|
||||
*/
|
||||
layout?: KeyboardLayoutObject;
|
||||
|
||||
/**
|
||||
* Specifies which layout should be used.
|
||||
*/
|
||||
layoutName?: string;
|
||||
|
||||
/**
|
||||
* Replaces variable buttons (such as `{bksp}`) with a human-friendly name (e.g.: `backspace`).
|
||||
*/
|
||||
display?: { [button: string]: string };
|
||||
|
||||
/**
|
||||
* By default, when you set the display property, you replace the default one. This setting merges them instead.
|
||||
*/
|
||||
mergeDisplay?: boolean;
|
||||
|
||||
/**
|
||||
* A prop to add your own css classes to the keyboard wrapper. You can add multiple classes separated by a space.
|
||||
*/
|
||||
theme?: string;
|
||||
|
||||
/**
|
||||
* A prop to add your own css classes to one or several buttons.
|
||||
*/
|
||||
buttonTheme?: KeyboardButtonTheme[];
|
||||
|
||||
/**
|
||||
* Runs a `console.log` every time a key is pressed. Displays the buttons pressed and the current input.
|
||||
*/
|
||||
debug?: boolean;
|
||||
|
||||
/**
|
||||
* Specifies whether clicking the "ENTER" button will input a newline (`\n`) or not.
|
||||
*/
|
||||
newLineOnEnter?: boolean;
|
||||
|
||||
/**
|
||||
* Specifies whether clicking the "TAB" button will input a tab character (`\t`) or not.
|
||||
*/
|
||||
tabCharOnTab?: boolean;
|
||||
|
||||
/**
|
||||
* Allows you to use a single simple-keyboard instance for several inputs.
|
||||
*/
|
||||
inputName?: string;
|
||||
|
||||
/**
|
||||
* `number`: Restrains all of simple-keyboard inputs to a certain length. This should be used in addition to the input element’s maxlengthattribute.
|
||||
*
|
||||
* `{ [inputName: string]: number }`: Restrains simple-keyboard’s individual inputs to a certain length. This should be used in addition to the input element’s maxlengthattribute.
|
||||
*/
|
||||
maxLength?:
|
||||
| number
|
||||
| {
|
||||
[inputName: string]: number;
|
||||
};
|
||||
|
||||
/**
|
||||
* When set to true, this option synchronizes the internal input of every simple-keyboard instance.
|
||||
*/
|
||||
syncInstanceInputs?: boolean;
|
||||
|
||||
/**
|
||||
* Enable highlighting of keys pressed on physical keyboard.
|
||||
*/
|
||||
physicalKeyboardHighlight?: boolean;
|
||||
|
||||
/**
|
||||
* Calling preventDefault for the mousedown events keeps the focus on the input.
|
||||
*/
|
||||
preventMouseDownDefault?: boolean;
|
||||
|
||||
/**
|
||||
* Define the text color that the physical keyboard highlighted key should have.
|
||||
*/
|
||||
physicalKeyboardHighlightTextColor?: string;
|
||||
|
||||
/**
|
||||
* Define the background color that the physical keyboard highlighted key should have.
|
||||
*/
|
||||
physicalKeyboardHighlightBgColor?: string;
|
||||
|
||||
/**
|
||||
* Render buttons as a button element instead of a div element.
|
||||
*/
|
||||
useButtonTag?: boolean;
|
||||
|
||||
/**
|
||||
* A prop to ensure characters are always be added/removed at the end of the string.
|
||||
*/
|
||||
disableCaretPositioning?: boolean;
|
||||
|
||||
/**
|
||||
* Restrains input(s) change to the defined regular expression pattern.
|
||||
*/
|
||||
inputPattern?: any;
|
||||
|
||||
/**
|
||||
* Executes the callback function on key press. Returns button layout name (i.e.: "{shift}").
|
||||
*/
|
||||
onKeyPress?: (button: string) => any;
|
||||
|
||||
/**
|
||||
* Executes the callback function on input change. Returns the current input's string.
|
||||
*/
|
||||
onChange?: (input: string) => any;
|
||||
|
||||
/**
|
||||
* Executes the callback function every time simple-keyboard is rendered (e.g: when you change layouts).
|
||||
*/
|
||||
onRender?: () => void;
|
||||
|
||||
/**
|
||||
* Executes the callback function once simple-keyboard is rendered for the first time (on initialization).
|
||||
*/
|
||||
onInit?: () => void;
|
||||
|
||||
/**
|
||||
* Executes the callback function on input change. Returns the input object with all defined inputs.
|
||||
*/
|
||||
onChangeAll?: (inputs: any) => any;
|
||||
}
|
||||
|
||||
class Keyboard {
|
||||
constructor(selector: string, options: KeyboardOptions);
|
||||
constructor(options: KeyboardOptions);
|
||||
options: KeyboardOptions;
|
||||
|
||||
/**
|
||||
* Adds/Modifies an entry to the `buttonTheme`. Basically a way to add a class to a button.
|
||||
* @param {string} buttons List of buttons to select (separated by a space).
|
||||
* @param {string} className Classes to give to the selected buttons (separated by space).
|
||||
*/
|
||||
addButtonTheme(buttons: string, className: string): void;
|
||||
|
||||
/**
|
||||
* Removes/Amends an entry to the `buttonTheme`. Basically a way to remove a class previously added to a button through buttonTheme or addButtonTheme.
|
||||
* @param {string} buttons List of buttons to select (separated by a space).
|
||||
* @param {string} className Classes to give to the selected buttons (separated by space).
|
||||
*/
|
||||
removeButtonTheme(buttons: string, className: string): void;
|
||||
|
||||
/**
|
||||
* Clear the keyboard's input.
|
||||
*
|
||||
* @param {string} [inputName] optional - the internal input to select
|
||||
*/
|
||||
clearInput(inputName?: string): void;
|
||||
|
||||
/**
|
||||
* Get the keyboard’s input (You can also get it from the onChange prop).
|
||||
* @param {string} [inputName] optional - the internal input to select
|
||||
*/
|
||||
getInput(inputName?: string): string;
|
||||
|
||||
/**
|
||||
* Set the keyboard’s input.
|
||||
* @param {string} input the input value
|
||||
* @param {string} inputName optional - the internal input to select
|
||||
*/
|
||||
setInput(input: string, inputName?: string): void;
|
||||
|
||||
/**
|
||||
* Set new option or modify existing ones after initialization.
|
||||
* @param {KeyboardOptions} option The option to set
|
||||
*/
|
||||
setOptions(options: KeyboardOptions): void;
|
||||
|
||||
/**
|
||||
* Send a command to all simple-keyboard instances at once (if you have multiple instances).
|
||||
* @param {function(instance: object, key: string)} callback Function to run on every instance
|
||||
*/
|
||||
dispatch(callback: (instance: any, key: string) => void): void;
|
||||
|
||||
/**
|
||||
* Get the DOM Element of a button. If there are several buttons with the same name, an array of the DOM Elements is returned.
|
||||
* @param {string} button The button layout name to select
|
||||
*/
|
||||
getButtonElement(button: string): HTMLElement | HTMLElement[];
|
||||
}
|
||||
|
||||
export default Keyboard;
|
||||
}
|
||||
@@ -57,6 +57,13 @@ body, html {
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
/* When using option "useButtonTag" */
|
||||
.simple-keyboard button.hg-button {
|
||||
border-width: 0;
|
||||
outline: 0;
|
||||
font-size: inherit;
|
||||
}
|
||||
|
||||
.simple-keyboard.hg-theme-default .hg-button:active {
|
||||
background: #e4e4e4;
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ class SimpleKeyboard {
|
||||
* @param {Array} params If first parameter is a string, it is considered the container class. The second parameter is then considered the options object. If first parameter is an object, it is considered the options object.
|
||||
*/
|
||||
constructor(...params){
|
||||
let keyboardDOMQuery = typeof params[0] === "string" ? params[0] : '.simple-keyboard';
|
||||
let keyboardDOMQuery = typeof params[0] === "string" ? params[0] : ".simple-keyboard";
|
||||
let options = typeof params[0] === "object" ? params[0] : params[1];
|
||||
|
||||
if(!options)
|
||||
@@ -58,12 +58,15 @@ class SimpleKeyboard {
|
||||
* @property {function} onRender Executes the callback function every time simple-keyboard is rendered (e.g: when you change layouts).
|
||||
* @property {function} onInit Executes the callback function once simple-keyboard is rendered for the first time (on initialization).
|
||||
* @property {function(inputs: object):object} onChangeAll Executes the callback function on input change. Returns the input object with all defined inputs.
|
||||
* @property {boolean} useButtonTag Render buttons as a button element instead of a div element.
|
||||
* @property {boolean} disableCaretPositioning A prop to ensure characters are always be added/removed at the end of the string.
|
||||
* @property {object} inputPattern Restrains input(s) change to the defined regular expression pattern.
|
||||
*/
|
||||
this.options = options;
|
||||
this.options.layoutName = this.options.layoutName || "default";
|
||||
this.options.theme = this.options.theme || "hg-theme-default";
|
||||
this.options.inputName = this.options.inputName || "default";
|
||||
this.options.preventMouseDownDefault = this.options.preventMouseDownDefault === false ? false : true;
|
||||
this.options.preventMouseDownDefault = this.options.preventMouseDownDefault || false;
|
||||
|
||||
/**
|
||||
* @type {object} Classes identifying loaded plugins
|
||||
@@ -94,6 +97,7 @@ class SimpleKeyboard {
|
||||
this.handleButtonMouseDown = this.handleButtonMouseDown.bind(this);
|
||||
this.handleButtonHold = this.handleButtonHold.bind(this);
|
||||
this.onModulesLoaded = this.onModulesLoaded.bind(this);
|
||||
this.inputPatternIsValid = this.inputPatternIsValid.bind(this);
|
||||
|
||||
/**
|
||||
* simple-keyboard uses a non-persistent internal input to keep track of the entered string (the variable `keyboard.input`).
|
||||
@@ -179,7 +183,17 @@ class SimpleKeyboard {
|
||||
button, this.input[this.options.inputName], this.options, this.caretPosition
|
||||
);
|
||||
|
||||
if(this.input[this.options.inputName] !== updatedInput){
|
||||
if(
|
||||
// If input will change as a result of this button press
|
||||
this.input[this.options.inputName] !== updatedInput &&
|
||||
// This pertains to the "inputPattern" option:
|
||||
(
|
||||
// If inputPattern isn't set
|
||||
!this.options.inputPattern ||
|
||||
// Or, if it is set and if the pattern is valid - we proceed.
|
||||
(this.options.inputPattern && this.inputPatternIsValid(updatedInput))
|
||||
)
|
||||
){
|
||||
|
||||
/**
|
||||
* If maxLength and handleMaxLength yield true, halting
|
||||
@@ -502,48 +516,101 @@ class SimpleKeyboard {
|
||||
return output;
|
||||
}
|
||||
|
||||
/**
|
||||
* This handles the "inputPattern" option
|
||||
* by checking if the provided inputPattern passes
|
||||
*/
|
||||
inputPatternIsValid(inputVal){
|
||||
let inputPatternRaw = this.options.inputPattern;
|
||||
let inputPattern;
|
||||
|
||||
/**
|
||||
* Check if input pattern is global or targeted to individual inputs
|
||||
*/
|
||||
if(inputPatternRaw instanceof RegExp){
|
||||
inputPattern = inputPatternRaw;
|
||||
} else {
|
||||
inputPattern = inputPatternRaw[this.options.inputName];
|
||||
}
|
||||
|
||||
if(inputPattern && inputVal){
|
||||
let didInputMatch = inputPattern.test(inputVal);
|
||||
|
||||
if(this.options.debug){
|
||||
console.log(`inputPattern ("${inputPattern}"): ${didInputMatch ? "passed" : "did not pass!"}`);
|
||||
}
|
||||
|
||||
return didInputMatch;
|
||||
} else {
|
||||
/**
|
||||
* inputPattern doesn't seem to be set for the current input, or input is empty. Pass.
|
||||
*/
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the current cursor position within a input or textarea (if any)
|
||||
*/
|
||||
handleCaret(){
|
||||
/**
|
||||
* Only first instance should insall the caret handling events
|
||||
*/
|
||||
this.caretPosition = null;
|
||||
let simpleKeyboardInstances = window['SimpleKeyboardInstances'];
|
||||
|
||||
if(
|
||||
(
|
||||
simpleKeyboardInstances &&
|
||||
Object.keys(simpleKeyboardInstances)[0] === this.utilities.camelCase(this.keyboardDOMClass)
|
||||
) ||
|
||||
!simpleKeyboardInstances
|
||||
){
|
||||
if(this.options.debug){
|
||||
console.log("Caret handling started");
|
||||
console.log(`Caret handling started (${this.keyboardDOMClass})`)
|
||||
}
|
||||
|
||||
document.addEventListener("keyup", this.caretEventHandler);
|
||||
document.addEventListener("mouseup", this.caretEventHandler);
|
||||
document.addEventListener("touchend", this.caretEventHandler);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called by {@link handleCaret} when an event that warrants a cursor position update is triggered
|
||||
*/
|
||||
caretEventHandler(event){
|
||||
let targetTagName;
|
||||
|
||||
if(this.isMouseHold){
|
||||
this.isMouseHold = false;
|
||||
}
|
||||
|
||||
if(event.target.tagName){
|
||||
targetTagName = event.target.tagName.toLowerCase();
|
||||
}
|
||||
|
||||
if(
|
||||
(targetTagName === "textarea" ||
|
||||
targetTagName === "input") &&
|
||||
!this.options.disableCaretPositioning
|
||||
){
|
||||
/**
|
||||
* Tracks current cursor position
|
||||
* As keys are pressed, text will be added/removed at that position within the input.
|
||||
*/
|
||||
this.caretPosition = event.target.selectionStart;
|
||||
this.dispatch(instance => {
|
||||
if(instance.isMouseHold){
|
||||
instance.isMouseHold = false;
|
||||
}
|
||||
|
||||
if(this.options.debug){
|
||||
console.log('Caret at: ', event.target.selectionStart, event.target.tagName.toLowerCase());
|
||||
}
|
||||
}
|
||||
if(
|
||||
(targetTagName === "textarea" ||
|
||||
targetTagName === "input") &&
|
||||
!instance.options.disableCaretPositioning
|
||||
){
|
||||
/**
|
||||
* Tracks current cursor position
|
||||
* As keys are pressed, text will be added/removed at that position within the input.
|
||||
*/
|
||||
instance.caretPosition = event.target.selectionStart;
|
||||
|
||||
if(instance.options.debug){
|
||||
console.log("Caret at: ", event.target.selectionStart, event.target.tagName.toLowerCase(), `(${instance.keyboardDOMClass})`);
|
||||
}
|
||||
} else if(instance.options.disableCaretPositioning){
|
||||
/**
|
||||
* If we toggled off disableCaretPositioning, we must ensure caretPosition doesn't persist once reactivated.
|
||||
*/
|
||||
instance.caretPosition = null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -551,7 +618,7 @@ class SimpleKeyboard {
|
||||
*/
|
||||
onInit(){
|
||||
if(this.options.debug){
|
||||
console.log("Initialized");
|
||||
console.log(`${this.keyboardDOMClass} Initialized`)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -606,7 +673,7 @@ class SimpleKeyboard {
|
||||
module.init(this);
|
||||
});
|
||||
|
||||
this.keyboardPluginClasses = this.keyboardPluginClasses + ' modules-loaded';
|
||||
this.keyboardPluginClasses = this.keyboardPluginClasses + " modules-loaded";
|
||||
|
||||
this.render();
|
||||
this.onModulesLoaded();
|
||||
@@ -639,7 +706,7 @@ class SimpleKeyboard {
|
||||
*/
|
||||
this.clear();
|
||||
|
||||
let layoutClass = this.options.layout ? "hg-layout-custom" : `hg-layout-${this.options.layoutName}`;
|
||||
let layoutClass = `hg-layout-${this.options.layoutName}`;
|
||||
let layout = this.options.layout || KeyboardLayout.getDefaultLayout();
|
||||
let useTouchEvents = this.options.useTouchEvents || false
|
||||
|
||||
@@ -653,7 +720,7 @@ class SimpleKeyboard {
|
||||
let themeButtons;
|
||||
|
||||
if(typeof themeObj.buttons === "string"){
|
||||
themeButtons = themeObj.buttons.split(' ');
|
||||
themeButtons = themeObj.buttons.split(" ");
|
||||
}
|
||||
|
||||
if(themeButtons){
|
||||
@@ -686,12 +753,12 @@ class SimpleKeyboard {
|
||||
* Iterating through each row
|
||||
*/
|
||||
layout[this.options.layoutName].forEach((row, rIndex) => {
|
||||
let rowArray = row.split(' ');
|
||||
let rowArray = row.split(" ");
|
||||
|
||||
/**
|
||||
* Creating empty row
|
||||
*/
|
||||
var rowDOM = document.createElement('div');
|
||||
let rowDOM = document.createElement("div");
|
||||
rowDOM.className += "hg-row";
|
||||
|
||||
/**
|
||||
@@ -705,7 +772,8 @@ class SimpleKeyboard {
|
||||
/**
|
||||
* Creating button
|
||||
*/
|
||||
var buttonDOM = document.createElement('div');
|
||||
let buttonType = this.options.useButtonTag ? "button" : "div";
|
||||
let buttonDOM = document.createElement(buttonType);
|
||||
buttonDOM.className += `hg-button ${fctBtnClass}${buttonThemeClass ? " "+buttonThemeClass : ""}`;
|
||||
|
||||
if (useTouchEvents) {
|
||||
@@ -746,7 +814,7 @@ class SimpleKeyboard {
|
||||
/**
|
||||
* Adding button label to button
|
||||
*/
|
||||
var buttonSpanDOM = document.createElement('span');
|
||||
let buttonSpanDOM = document.createElement('span');
|
||||
buttonSpanDOM.innerHTML = buttonDisplayName;
|
||||
buttonDOM.appendChild(buttonSpanDOM);
|
||||
|
||||
|
||||
@@ -137,7 +137,9 @@ it('Keyboard onKeyPress will work', () => {
|
||||
it('Keyboard standard function buttons will not change input', () => {
|
||||
testUtil.setDOM();
|
||||
|
||||
let keyboard = new Keyboard();
|
||||
let keyboard = new Keyboard({
|
||||
useButtonTag: true
|
||||
});
|
||||
|
||||
testUtil.iterateButtons((button) => {
|
||||
if(button.getAttribute("data-skbtn") === "{shift}"){
|
||||
@@ -596,6 +598,42 @@ it('Keyboard caretEventHandler will detect input, textarea focus', () => {
|
||||
expect(keyboard.caretPosition).toBe(3);
|
||||
});
|
||||
|
||||
it('Keyboard caretEventHandler will not set caretPosition on disableCaretPositioning', () => {
|
||||
testUtil.setDOM();
|
||||
|
||||
let keyboard = new Keyboard();
|
||||
|
||||
keyboard.caretEventHandler({
|
||||
charCode: 0,
|
||||
code: "KeyF",
|
||||
key: "f",
|
||||
which: 70,
|
||||
target: {
|
||||
tagName: "input",
|
||||
selectionStart: 3
|
||||
}
|
||||
});
|
||||
|
||||
expect(keyboard.caretPosition).toBe(3);
|
||||
|
||||
keyboard.setOptions({
|
||||
disableCaretPositioning: true
|
||||
});
|
||||
|
||||
keyboard.caretEventHandler({
|
||||
charCode: 0,
|
||||
code: "KeyF",
|
||||
key: "f",
|
||||
which: 70,
|
||||
target: {
|
||||
tagName: "input",
|
||||
selectionStart: 3
|
||||
}
|
||||
});
|
||||
|
||||
expect(keyboard.caretPosition).toBeFalsy();
|
||||
});
|
||||
|
||||
it('Keyboard caretEventHandler ignore positioning if input, textarea is blur', () => {
|
||||
testUtil.setDOM();
|
||||
|
||||
@@ -870,6 +908,24 @@ it('Keyboard handleButtonMouseDown will work', () => {
|
||||
|
||||
});
|
||||
|
||||
it('Keyboard handleButtonMouseDown will work with preventMouseDownDefault', () => {
|
||||
testUtil.setDOM();
|
||||
|
||||
let keyboard = new Keyboard();
|
||||
|
||||
keyboard.options.preventMouseDownDefault = true;
|
||||
|
||||
keyboard.handleButtonMouseDown("q", {
|
||||
target: keyboard.getButtonElement("q")
|
||||
});
|
||||
|
||||
var clickEvent = document.createEvent('MouseEvents');
|
||||
clickEvent.initEvent('mousedown', true, true);
|
||||
keyboard.getButtonElement("q").dispatchEvent(clickEvent);
|
||||
document.onmouseup();
|
||||
|
||||
});
|
||||
|
||||
it('Keyboard onModulesLoaded will work', () => {
|
||||
testUtil.setDOM();
|
||||
|
||||
@@ -891,4 +947,46 @@ it('Keyboard onModulesLoaded will work', () => {
|
||||
});
|
||||
|
||||
expect(foo).toBe("bar");
|
||||
});
|
||||
|
||||
it('Keyboard inputPattern will work globally', () => {
|
||||
testUtil.setDOM();
|
||||
|
||||
let keyboard = new Keyboard({
|
||||
inputPattern: /^\d+$/
|
||||
});
|
||||
|
||||
keyboard.getButtonElement("q").onclick();
|
||||
|
||||
expect(keyboard.getInput()).toBeFalsy();
|
||||
|
||||
keyboard.getButtonElement("1").onclick();
|
||||
|
||||
expect(keyboard.getInput()).toBe("1");
|
||||
});
|
||||
|
||||
it('Keyboard inputPattern will work by input name', () => {
|
||||
testUtil.setDOM();
|
||||
|
||||
let keyboard = new Keyboard({
|
||||
debug: true,
|
||||
inputName: "test1",
|
||||
inputPattern: {
|
||||
test1: /^\d+$/
|
||||
}
|
||||
});
|
||||
|
||||
keyboard.getButtonElement("q").onclick();
|
||||
keyboard.getButtonElement("1").onclick();
|
||||
|
||||
expect(keyboard.getInput()).toBe("1");
|
||||
|
||||
keyboard.setOptions({
|
||||
inputName: "default"
|
||||
});
|
||||
|
||||
keyboard.getButtonElement("q").onclick();
|
||||
keyboard.getButtonElement("1").onclick();
|
||||
|
||||
expect(keyboard.getInput()).toBe("q1");
|
||||
});
|
||||
@@ -18,6 +18,7 @@ class Utilities {
|
||||
this.getButtonDisplayName = this.getButtonDisplayName.bind(this);
|
||||
this.getUpdatedInput = this.getUpdatedInput.bind(this);
|
||||
this.updateCaretPos = this.updateCaretPos.bind(this);
|
||||
this.updateCaretPosAction = this.updateCaretPosAction.bind(this);
|
||||
this.isMaxLengthReached = this.isMaxLengthReached.bind(this);
|
||||
this.camelCase = this.camelCase.bind(this);
|
||||
this.countInArray = this.countInArray.bind(this);
|
||||
@@ -150,7 +151,7 @@ class Utilities {
|
||||
output = this.addStringAt(output, "\n", caretPos, moveCaret);
|
||||
|
||||
else if(button.includes("numpad") && Number.isInteger(Number(button[button.length - 2]))){
|
||||
output = this.addStringAt(output, button[button.length - 2], caretPos);
|
||||
output = this.addStringAt(output, button[button.length - 2], caretPos, moveCaret);
|
||||
}
|
||||
else if(button === "{numpaddivide}")
|
||||
output = this.addStringAt(output, '/', caretPos, moveCaret);
|
||||
@@ -183,14 +184,37 @@ class Utilities {
|
||||
* @param {boolean} minus Whether the cursor should be moved to the left or not.
|
||||
*/
|
||||
updateCaretPos(length, minus){
|
||||
if(minus){
|
||||
if(this.simpleKeyboardInstance.caretPosition > 0)
|
||||
this.simpleKeyboardInstance.caretPosition = this.simpleKeyboardInstance.caretPosition - length;
|
||||
} else {
|
||||
this.simpleKeyboardInstance.caretPosition = this.simpleKeyboardInstance.caretPosition + length;
|
||||
let newCaretPos = this.updateCaretPosAction(this.simpleKeyboardInstance, length, minus);
|
||||
|
||||
if(this.simpleKeyboardInstance.options.syncInstanceInputs){
|
||||
this.simpleKeyboardInstance.dispatch(instance => {
|
||||
instance.caretPosition = newCaretPos;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Action method of updateCaretPos
|
||||
*
|
||||
* @param {object} instance The instance whose position should be updated
|
||||
* @param {number} length Represents by how many characters the input should be moved
|
||||
* @param {boolean} minus Whether the cursor should be moved to the left or not.
|
||||
*/
|
||||
updateCaretPosAction(instance, length, minus){
|
||||
if(minus){
|
||||
if(instance.caretPosition > 0)
|
||||
instance.caretPosition = instance.caretPosition - length;
|
||||
} else {
|
||||
instance.caretPosition = instance.caretPosition + length;
|
||||
}
|
||||
|
||||
if(this.simpleKeyboardInstance.options.debug){
|
||||
console.log("Caret at:", instance.caretPosition, `(${instance.keyboardDOMClass})`);
|
||||
}
|
||||
|
||||
return instance.caretPosition;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a string to the input at a given position
|
||||
*
|
||||
@@ -216,10 +240,6 @@ class Utilities {
|
||||
|
||||
}
|
||||
|
||||
if(this.simpleKeyboardInstance.options.debug && moveCaret){
|
||||
console.log("Caret at:", position);
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
@@ -268,10 +288,6 @@ class Utilities {
|
||||
}
|
||||
}
|
||||
|
||||
if(this.simpleKeyboardInstance.options.debug && moveCaret){
|
||||
console.log("Caret at:", this.simpleKeyboardInstance.caretPosition);
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
/**
|
||||
@@ -343,7 +359,14 @@ class Utilities {
|
||||
* @param {string} string The string to transform.
|
||||
*/
|
||||
camelCase(string){
|
||||
return string.toLowerCase().trim().split(/[.\-_\s]/g).reduce((string, word) => string + word[0].toUpperCase() + word.slice(1));
|
||||
return string
|
||||
.toLowerCase()
|
||||
.trim()
|
||||
.split(/[.\-_\s]/g)
|
||||
.reduce(
|
||||
(string, word) =>
|
||||
word.length ? string + word[0].toUpperCase() + word.slice(1) : string
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -355,7 +378,6 @@ class Utilities {
|
||||
countInArray(array, value){
|
||||
return array.reduce((n, x) => n + (x === value), 0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default Utilities;
|
||||
export default Utilities;
|
||||
|
||||
@@ -210,6 +210,18 @@ it('Keyboard standard button will affect input', () => {
|
||||
}
|
||||
});
|
||||
|
||||
it('Keyboard updateCaretPos will work with minus', () => {
|
||||
testUtil.setDOM();
|
||||
|
||||
let keyboard = new Keyboard();
|
||||
keyboard.options.syncInstanceInputs = true;
|
||||
|
||||
keyboard.caretPosition = 5;
|
||||
keyboard.utilities.updateCaretPos(2, true);
|
||||
|
||||
expect(keyboard.caretPosition).toBe(3);
|
||||
});
|
||||
|
||||
it('Keyboard updateCaretPos will work with minus', () => {
|
||||
testUtil.setDOM();
|
||||
|
||||
@@ -465,4 +477,10 @@ it('Keyboard removeAt will remove regular strings', () => {
|
||||
keyboard.caretPosition = 6;
|
||||
output = keyboard.utilities.removeAt("testie", 6, true);
|
||||
expect(keyboard.caretPosition).toBe(5);
|
||||
});
|
||||
|
||||
it('Keyboard will work with custom (and weird) class', () => {
|
||||
testUtil.setDOM("my--weird--class");
|
||||
let keyboard = new Keyboard(".my--weird--class");
|
||||
expect(keyboard.keyboardDOMClass).toBe("my--weird--class");
|
||||
});
|
||||
Reference in New Issue
Block a user