From 8ba6f879d0eda6891f7b07e974c6a9a0d7d2e81e Mon Sep 17 00:00:00 2001 From: Francisco Hodge Date: Sun, 14 Jul 2019 11:27:18 -0400 Subject: [PATCH] Code optimization, added onKeyReleased. Fixes #144, #145 --- build/css/index.css | 2 +- build/css/index.css.map | 2 +- build/css/simple-keyboard.css | 2 +- build/index.d.ts | 5 + build/index.js | 4 +- build/index.js.map | 2 +- build/simple-keyboard.js | 499 ++++++++++-------- package-lock.json | 109 ++-- package.json | 4 +- public/index.html | 4 +- src/demo/App.js | 87 --- src/demo/BasicDemo.js | 55 ++ src/demo/FullKeyboardDemo.js | 157 ++++++ src/demo/css/App.css | 33 -- src/demo/css/BasicDemo.css | 12 + src/demo/css/FullKeyboardDemo.css | 132 +++++ src/demo/css/index.css | 3 + src/demo/index.js | 17 +- .../tests/{App.test.js => BasicDemo.test.js} | 20 +- src/demo/tests/FullKeyboardDemo.test.js | 62 +++ src/lib/@types/index.d.ts | 5 + src/lib/components/Keyboard.js | 136 +++-- src/lib/components/tests/Keyboard.test.js | 53 ++ src/lib/services/PhysicalKeyboard.js | 71 +-- src/lib/services/Utilities.js | 58 +- src/lib/services/tests/Utilities.test.js | 63 ++- src/utils/TestUtility.js | 11 +- 27 files changed, 1024 insertions(+), 584 deletions(-) delete mode 100644 src/demo/App.js create mode 100644 src/demo/BasicDemo.js create mode 100644 src/demo/FullKeyboardDemo.js delete mode 100644 src/demo/css/App.css create mode 100644 src/demo/css/BasicDemo.css create mode 100644 src/demo/css/FullKeyboardDemo.css create mode 100644 src/demo/css/index.css rename src/demo/tests/{App.test.js => BasicDemo.test.js} (78%) create mode 100644 src/demo/tests/FullKeyboardDemo.test.js diff --git a/build/css/index.css b/build/css/index.css index 60439879..a231ea1a 100644 --- a/build/css/index.css +++ b/build/css/index.css @@ -1,6 +1,6 @@ /*! * - * simple-keyboard v2.23.3 + * simple-keyboard v2.24.0 * https://github.com/hodgef/simple-keyboard * * Copyright (c) Francisco Hodge (https://github.com/hodgef) diff --git a/build/css/index.css.map b/build/css/index.css.map index 9b9f4e14..7454817d 100644 --- a/build/css/index.css.map +++ b/build/css/index.css.map @@ -1 +1 @@ -{"version":3,"sources":["index.css","Keyboard.css"],"names":[],"mappings":"AAAA;;;;;;;;;;EAUE,CCVF,UAEE,QAAS,CACT,SACF,CAEA,iBACE,4GAC+C,CAC/C,UAAW,CACX,wBAAiB,CAAjB,qBAAiB,CAAjB,oBAAiB,CAAjB,gBAAiB,CACjB,qBAAsB,CACtB,eAAgB,CAChB,yBACF,CAEA,yBACE,YACF,CAEA,0CACE,iBACF,CAMA,mGACE,gBACF,CAEA,wCACE,cACF,CAEA,8CACE,YACF,CAEA,4BACE,oBAAqB,CACrB,WAAY,CACZ,cACF,CAEA,iCACE,mBACF,CAKA,kCACE,+BAAoC,CACpC,WAAY,CACZ,iBACF,CAEA,6CACE,sCAA+C,CAC/C,WAAY,CACZ,iBAAkB,CAClB,qBAAsB,CACtB,WAAY,CACZ,eAAiB,CACjB,+BAAgC,CAChC,cAAe,CACf,YAAa,CACb,kBAAmB,CACnB,sBACF,CAGA,kCACE,cAAe,CACf,SAAU,CACV,iBACF,CAEA,+DACE,WAAY,CACZ,WAAY,CACZ,kBAAmB,CACnB,YAAa,CACb,sBACF,CAMA,oIACE,WACF,CAEA,+DACE,WACF,CAEA,2DACE,cACF,CAEA,yEACE,cACF,CAEA,+DACE,4BAAiC,CACjC,UACF,CAEA,+EACE,cACF,CAEA,4EACE,cACF","file":"index.css","sourcesContent":["/*!\n * \n * simple-keyboard v2.23.3\n * https://github.com/hodgef/simple-keyboard\n * \n * Copyright (c) Francisco Hodge (https://github.com/hodgef)\n * \n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n * \n */\nbody,\r\nhtml {\r\n margin: 0;\r\n padding: 0;\r\n}\r\n\r\n.simple-keyboard {\r\n font-family: \"HelveticaNeue-Light\", \"Helvetica Neue Light\", \"Helvetica Neue\",\r\n Helvetica, Arial, \"Lucida Grande\", sans-serif;\r\n width: 100%;\r\n -webkit-user-select: none;\r\n -moz-user-select: none;\r\n -ms-user-select: none;\r\n user-select: none;\r\n box-sizing: border-box;\r\n overflow: hidden;\r\n touch-action: manipulation;\r\n}\r\n\r\n.simple-keyboard .hg-row {\r\n display: flex;\r\n}\r\n\r\n.simple-keyboard .hg-row:not(:last-child) {\r\n margin-bottom: 5px;\r\n}\r\n\r\n.simple-keyboard .hg-row .hg-button:not(:last-child) {\r\n margin-right: 5px;\r\n}\r\n\r\n.simple-keyboard .hg-row .hg-button-container {\r\n margin-right: 5px;\r\n}\r\n\r\n.simple-keyboard .hg-row > div:last-child {\r\n margin-right: 0;\r\n}\r\n\r\n.simple-keyboard .hg-row .hg-button-container {\r\n display: flex;\r\n}\r\n\r\n.simple-keyboard .hg-button {\r\n display: inline-block;\r\n flex-grow: 1;\r\n cursor: pointer;\r\n}\r\n\r\n.simple-keyboard .hg-button span {\r\n pointer-events: none;\r\n}\r\n\r\n/**\r\n * hg-theme-default theme\r\n */\r\n.simple-keyboard.hg-theme-default {\r\n background-color: rgba(0, 0, 0, 0.1);\r\n padding: 5px;\r\n border-radius: 5px;\r\n}\r\n\r\n.simple-keyboard.hg-theme-default .hg-button {\r\n box-shadow: 0px 0px 3px -1px rgba(0, 0, 0, 0.3);\r\n height: 40px;\r\n border-radius: 5px;\r\n box-sizing: border-box;\r\n padding: 5px;\r\n background: white;\r\n border-bottom: 1px solid #b5b5b5;\r\n cursor: pointer;\r\n display: flex;\r\n align-items: center;\r\n justify-content: center;\r\n}\r\n\r\n/* When using option \"useButtonTag\" */\r\n.simple-keyboard button.hg-button {\r\n border-width: 0;\r\n outline: 0;\r\n font-size: inherit;\r\n}\r\n\r\n.simple-keyboard.hg-theme-default.hg-layout-numeric .hg-button {\r\n width: 33.3%;\r\n height: 60px;\r\n align-items: center;\r\n display: flex;\r\n justify-content: center;\r\n}\r\n\r\n.simple-keyboard.hg-theme-default .hg-button.hg-button-numpadadd {\r\n height: 85px;\r\n}\r\n\r\n.simple-keyboard.hg-theme-default .hg-button.hg-button-numpadenter {\r\n height: 85px;\r\n}\r\n\r\n.simple-keyboard.hg-theme-default .hg-button.hg-button-numpad0 {\r\n width: 105px;\r\n}\r\n\r\n.simple-keyboard.hg-theme-default .hg-button.hg-button-com {\r\n max-width: 85px;\r\n}\r\n\r\n.simple-keyboard.hg-theme-default .hg-button.hg-standardBtn.hg-button-at {\r\n max-width: 45px;\r\n}\r\n\r\n.simple-keyboard.hg-theme-default .hg-button.hg-selectedButton {\r\n background: rgba(5, 25, 70, 0.53);\r\n color: white;\r\n}\r\n\r\n.simple-keyboard.hg-theme-default .hg-button.hg-standardBtn[data-skbtn=\".com\"] {\r\n max-width: 82px;\r\n}\r\n\r\n.simple-keyboard.hg-theme-default .hg-button.hg-standardBtn[data-skbtn=\"@\"] {\r\n max-width: 60px;\r\n}\r\n\n","body,\r\nhtml {\r\n margin: 0;\r\n padding: 0;\r\n}\r\n\r\n.simple-keyboard {\r\n font-family: \"HelveticaNeue-Light\", \"Helvetica Neue Light\", \"Helvetica Neue\",\r\n Helvetica, Arial, \"Lucida Grande\", sans-serif;\r\n width: 100%;\r\n user-select: none;\r\n box-sizing: border-box;\r\n overflow: hidden;\r\n touch-action: manipulation;\r\n}\r\n\r\n.simple-keyboard .hg-row {\r\n display: flex;\r\n}\r\n\r\n.simple-keyboard .hg-row:not(:last-child) {\r\n margin-bottom: 5px;\r\n}\r\n\r\n.simple-keyboard .hg-row .hg-button:not(:last-child) {\r\n margin-right: 5px;\r\n}\r\n\r\n.simple-keyboard .hg-row .hg-button-container {\r\n margin-right: 5px;\r\n}\r\n\r\n.simple-keyboard .hg-row > div:last-child {\r\n margin-right: 0;\r\n}\r\n\r\n.simple-keyboard .hg-row .hg-button-container {\r\n display: flex;\r\n}\r\n\r\n.simple-keyboard .hg-button {\r\n display: inline-block;\r\n flex-grow: 1;\r\n cursor: pointer;\r\n}\r\n\r\n.simple-keyboard .hg-button span {\r\n pointer-events: none;\r\n}\r\n\r\n/**\r\n * hg-theme-default theme\r\n */\r\n.simple-keyboard.hg-theme-default {\r\n background-color: rgba(0, 0, 0, 0.1);\r\n padding: 5px;\r\n border-radius: 5px;\r\n}\r\n\r\n.simple-keyboard.hg-theme-default .hg-button {\r\n box-shadow: 0px 0px 3px -1px rgba(0, 0, 0, 0.3);\r\n height: 40px;\r\n border-radius: 5px;\r\n box-sizing: border-box;\r\n padding: 5px;\r\n background: white;\r\n border-bottom: 1px solid #b5b5b5;\r\n cursor: pointer;\r\n display: flex;\r\n align-items: center;\r\n justify-content: center;\r\n}\r\n\r\n/* When using option \"useButtonTag\" */\r\n.simple-keyboard button.hg-button {\r\n border-width: 0;\r\n outline: 0;\r\n font-size: inherit;\r\n}\r\n\r\n.simple-keyboard.hg-theme-default.hg-layout-numeric .hg-button {\r\n width: 33.3%;\r\n height: 60px;\r\n align-items: center;\r\n display: flex;\r\n justify-content: center;\r\n}\r\n\r\n.simple-keyboard.hg-theme-default .hg-button.hg-button-numpadadd {\r\n height: 85px;\r\n}\r\n\r\n.simple-keyboard.hg-theme-default .hg-button.hg-button-numpadenter {\r\n height: 85px;\r\n}\r\n\r\n.simple-keyboard.hg-theme-default .hg-button.hg-button-numpad0 {\r\n width: 105px;\r\n}\r\n\r\n.simple-keyboard.hg-theme-default .hg-button.hg-button-com {\r\n max-width: 85px;\r\n}\r\n\r\n.simple-keyboard.hg-theme-default .hg-button.hg-standardBtn.hg-button-at {\r\n max-width: 45px;\r\n}\r\n\r\n.simple-keyboard.hg-theme-default .hg-button.hg-selectedButton {\r\n background: rgba(5, 25, 70, 0.53);\r\n color: white;\r\n}\r\n\r\n.simple-keyboard.hg-theme-default .hg-button.hg-standardBtn[data-skbtn=\".com\"] {\r\n max-width: 82px;\r\n}\r\n\r\n.simple-keyboard.hg-theme-default .hg-button.hg-standardBtn[data-skbtn=\"@\"] {\r\n max-width: 60px;\r\n}\r\n"]} \ No newline at end of file +{"version":3,"sources":["index.css","Keyboard.css"],"names":[],"mappings":"AAAA;;;;;;;;;;EAUE,CCVF,UAEE,QAAS,CACT,SACF,CAEA,iBACE,4GAC+C,CAC/C,UAAW,CACX,wBAAiB,CAAjB,qBAAiB,CAAjB,oBAAiB,CAAjB,gBAAiB,CACjB,qBAAsB,CACtB,eAAgB,CAChB,yBACF,CAEA,yBACE,YACF,CAEA,0CACE,iBACF,CAMA,mGACE,gBACF,CAEA,wCACE,cACF,CAEA,8CACE,YACF,CAEA,4BACE,oBAAqB,CACrB,WAAY,CACZ,cACF,CAEA,iCACE,mBACF,CAKA,kCACE,+BAAoC,CACpC,WAAY,CACZ,iBACF,CAEA,6CACE,sCAA+C,CAC/C,WAAY,CACZ,iBAAkB,CAClB,qBAAsB,CACtB,WAAY,CACZ,eAAiB,CACjB,+BAAgC,CAChC,cAAe,CACf,YAAa,CACb,kBAAmB,CACnB,sBACF,CAGA,kCACE,cAAe,CACf,SAAU,CACV,iBACF,CAEA,+DACE,WAAY,CACZ,WAAY,CACZ,kBAAmB,CACnB,YAAa,CACb,sBACF,CAMA,oIACE,WACF,CAEA,+DACE,WACF,CAEA,2DACE,cACF,CAEA,yEACE,cACF,CAEA,+DACE,4BAAiC,CACjC,UACF,CAEA,+EACE,cACF,CAEA,4EACE,cACF","file":"index.css","sourcesContent":["/*!\n * \n * simple-keyboard v2.24.0\n * https://github.com/hodgef/simple-keyboard\n * \n * Copyright (c) Francisco Hodge (https://github.com/hodgef)\n * \n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n * \n */\nbody,\r\nhtml {\r\n margin: 0;\r\n padding: 0;\r\n}\r\n\r\n.simple-keyboard {\r\n font-family: \"HelveticaNeue-Light\", \"Helvetica Neue Light\", \"Helvetica Neue\",\r\n Helvetica, Arial, \"Lucida Grande\", sans-serif;\r\n width: 100%;\r\n -webkit-user-select: none;\r\n -moz-user-select: none;\r\n -ms-user-select: none;\r\n user-select: none;\r\n box-sizing: border-box;\r\n overflow: hidden;\r\n touch-action: manipulation;\r\n}\r\n\r\n.simple-keyboard .hg-row {\r\n display: flex;\r\n}\r\n\r\n.simple-keyboard .hg-row:not(:last-child) {\r\n margin-bottom: 5px;\r\n}\r\n\r\n.simple-keyboard .hg-row .hg-button:not(:last-child) {\r\n margin-right: 5px;\r\n}\r\n\r\n.simple-keyboard .hg-row .hg-button-container {\r\n margin-right: 5px;\r\n}\r\n\r\n.simple-keyboard .hg-row > div:last-child {\r\n margin-right: 0;\r\n}\r\n\r\n.simple-keyboard .hg-row .hg-button-container {\r\n display: flex;\r\n}\r\n\r\n.simple-keyboard .hg-button {\r\n display: inline-block;\r\n flex-grow: 1;\r\n cursor: pointer;\r\n}\r\n\r\n.simple-keyboard .hg-button span {\r\n pointer-events: none;\r\n}\r\n\r\n/**\r\n * hg-theme-default theme\r\n */\r\n.simple-keyboard.hg-theme-default {\r\n background-color: rgba(0, 0, 0, 0.1);\r\n padding: 5px;\r\n border-radius: 5px;\r\n}\r\n\r\n.simple-keyboard.hg-theme-default .hg-button {\r\n box-shadow: 0px 0px 3px -1px rgba(0, 0, 0, 0.3);\r\n height: 40px;\r\n border-radius: 5px;\r\n box-sizing: border-box;\r\n padding: 5px;\r\n background: white;\r\n border-bottom: 1px solid #b5b5b5;\r\n cursor: pointer;\r\n display: flex;\r\n align-items: center;\r\n justify-content: center;\r\n}\r\n\r\n/* When using option \"useButtonTag\" */\r\n.simple-keyboard button.hg-button {\r\n border-width: 0;\r\n outline: 0;\r\n font-size: inherit;\r\n}\r\n\r\n.simple-keyboard.hg-theme-default.hg-layout-numeric .hg-button {\r\n width: 33.3%;\r\n height: 60px;\r\n align-items: center;\r\n display: flex;\r\n justify-content: center;\r\n}\r\n\r\n.simple-keyboard.hg-theme-default .hg-button.hg-button-numpadadd {\r\n height: 85px;\r\n}\r\n\r\n.simple-keyboard.hg-theme-default .hg-button.hg-button-numpadenter {\r\n height: 85px;\r\n}\r\n\r\n.simple-keyboard.hg-theme-default .hg-button.hg-button-numpad0 {\r\n width: 105px;\r\n}\r\n\r\n.simple-keyboard.hg-theme-default .hg-button.hg-button-com {\r\n max-width: 85px;\r\n}\r\n\r\n.simple-keyboard.hg-theme-default .hg-button.hg-standardBtn.hg-button-at {\r\n max-width: 45px;\r\n}\r\n\r\n.simple-keyboard.hg-theme-default .hg-button.hg-selectedButton {\r\n background: rgba(5, 25, 70, 0.53);\r\n color: white;\r\n}\r\n\r\n.simple-keyboard.hg-theme-default .hg-button.hg-standardBtn[data-skbtn=\".com\"] {\r\n max-width: 82px;\r\n}\r\n\r\n.simple-keyboard.hg-theme-default .hg-button.hg-standardBtn[data-skbtn=\"@\"] {\r\n max-width: 60px;\r\n}\r\n\n","body,\r\nhtml {\r\n margin: 0;\r\n padding: 0;\r\n}\r\n\r\n.simple-keyboard {\r\n font-family: \"HelveticaNeue-Light\", \"Helvetica Neue Light\", \"Helvetica Neue\",\r\n Helvetica, Arial, \"Lucida Grande\", sans-serif;\r\n width: 100%;\r\n user-select: none;\r\n box-sizing: border-box;\r\n overflow: hidden;\r\n touch-action: manipulation;\r\n}\r\n\r\n.simple-keyboard .hg-row {\r\n display: flex;\r\n}\r\n\r\n.simple-keyboard .hg-row:not(:last-child) {\r\n margin-bottom: 5px;\r\n}\r\n\r\n.simple-keyboard .hg-row .hg-button:not(:last-child) {\r\n margin-right: 5px;\r\n}\r\n\r\n.simple-keyboard .hg-row .hg-button-container {\r\n margin-right: 5px;\r\n}\r\n\r\n.simple-keyboard .hg-row > div:last-child {\r\n margin-right: 0;\r\n}\r\n\r\n.simple-keyboard .hg-row .hg-button-container {\r\n display: flex;\r\n}\r\n\r\n.simple-keyboard .hg-button {\r\n display: inline-block;\r\n flex-grow: 1;\r\n cursor: pointer;\r\n}\r\n\r\n.simple-keyboard .hg-button span {\r\n pointer-events: none;\r\n}\r\n\r\n/**\r\n * hg-theme-default theme\r\n */\r\n.simple-keyboard.hg-theme-default {\r\n background-color: rgba(0, 0, 0, 0.1);\r\n padding: 5px;\r\n border-radius: 5px;\r\n}\r\n\r\n.simple-keyboard.hg-theme-default .hg-button {\r\n box-shadow: 0px 0px 3px -1px rgba(0, 0, 0, 0.3);\r\n height: 40px;\r\n border-radius: 5px;\r\n box-sizing: border-box;\r\n padding: 5px;\r\n background: white;\r\n border-bottom: 1px solid #b5b5b5;\r\n cursor: pointer;\r\n display: flex;\r\n align-items: center;\r\n justify-content: center;\r\n}\r\n\r\n/* When using option \"useButtonTag\" */\r\n.simple-keyboard button.hg-button {\r\n border-width: 0;\r\n outline: 0;\r\n font-size: inherit;\r\n}\r\n\r\n.simple-keyboard.hg-theme-default.hg-layout-numeric .hg-button {\r\n width: 33.3%;\r\n height: 60px;\r\n align-items: center;\r\n display: flex;\r\n justify-content: center;\r\n}\r\n\r\n.simple-keyboard.hg-theme-default .hg-button.hg-button-numpadadd {\r\n height: 85px;\r\n}\r\n\r\n.simple-keyboard.hg-theme-default .hg-button.hg-button-numpadenter {\r\n height: 85px;\r\n}\r\n\r\n.simple-keyboard.hg-theme-default .hg-button.hg-button-numpad0 {\r\n width: 105px;\r\n}\r\n\r\n.simple-keyboard.hg-theme-default .hg-button.hg-button-com {\r\n max-width: 85px;\r\n}\r\n\r\n.simple-keyboard.hg-theme-default .hg-button.hg-standardBtn.hg-button-at {\r\n max-width: 45px;\r\n}\r\n\r\n.simple-keyboard.hg-theme-default .hg-button.hg-selectedButton {\r\n background: rgba(5, 25, 70, 0.53);\r\n color: white;\r\n}\r\n\r\n.simple-keyboard.hg-theme-default .hg-button.hg-standardBtn[data-skbtn=\".com\"] {\r\n max-width: 82px;\r\n}\r\n\r\n.simple-keyboard.hg-theme-default .hg-button.hg-standardBtn[data-skbtn=\"@\"] {\r\n max-width: 60px;\r\n}\r\n"]} \ No newline at end of file diff --git a/build/css/simple-keyboard.css b/build/css/simple-keyboard.css index 9e5f6502..cc10512b 100644 --- a/build/css/simple-keyboard.css +++ b/build/css/simple-keyboard.css @@ -1,6 +1,6 @@ /*! * - * simple-keyboard v2.23.3 (Non-minified build) + * simple-keyboard v2.24.0 (Non-minified build) * https://github.com/hodgef/simple-keyboard * * Copyright (c) Francisco Hodge (https://github.com/hodgef) diff --git a/build/index.d.ts b/build/index.d.ts index a4a703eb..4a71d527 100644 --- a/build/index.d.ts +++ b/build/index.d.ts @@ -162,6 +162,11 @@ declare module 'simple-keyboard' { * Executes the callback function on input change. Returns the input object with all defined inputs. */ onChangeAll?: (inputs: any) => any; + + /** + * Executes the callback function on key release. + */ + onKeyReleased?: () => void; } class Keyboard { diff --git a/build/index.js b/build/index.js index a949fe3f..3308a5e3 100644 --- a/build/index.js +++ b/build/index.js @@ -1,6 +1,6 @@ /*! * - * simple-keyboard v2.23.3 + * simple-keyboard v2.24.0 * https://github.com/hodgef/simple-keyboard * * Copyright (c) Francisco Hodge (https://github.com/hodgef) @@ -9,5 +9,5 @@ * LICENSE file in the root directory of this source tree. * */ -!function(t,e){"object"===typeof exports&&"object"===typeof module?module.exports=e():"function"===typeof define&&define.amd?define("SimpleKeyboard",[],e):"object"===typeof exports?exports.SimpleKeyboard=e():t.SimpleKeyboard=e()}(window,function(){return function(t){var e={};function n(o){if(e[o])return e[o].exports;var i=e[o]={i:o,l:!1,exports:{}};return t[o].call(i.exports,i,i.exports,n),i.l=!0,i.exports}return n.m=t,n.c=e,n.d=function(t,e,o){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:o})},n.r=function(t){"undefined"!==typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"===typeof t&&t&&t.__esModule)return t;var o=Object.create(null);if(n.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var i in t)n.d(o,i,function(e){return t[e]}.bind(null,i));return o},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=0)}([function(t,e,n){t.exports=n(2)},function(t,e,n){},function(t,e,n){"use strict";n.r(e);n(1);function o(t,e){for(var n=0;n ? {shift}",".com @ {space}"]}}}],(n=null)&&s(e.prototype,n),o&&s(e,o),t}();function u(t){return(u="function"===typeof Symbol&&"symbol"===typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"===typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function r(t,e){for(var n=0;n0?s=this.removeAt(s,o,i):"{space}"===t?s=this.addStringAt(s," ",o,i):"{tab}"!==t||"boolean"===typeof n.tabCharOnTab&&!1===n.tabCharOnTab?"{enter}"!==t&&"{numpadenter}"!==t||!n.newLineOnEnter?t.includes("numpad")&&Number.isInteger(Number(t[t.length-2]))?s=this.addStringAt(s,t[t.length-2],o,i):"{numpaddivide}"===t?s=this.addStringAt(s,"/",o,i):"{numpadmultiply}"===t?s=this.addStringAt(s,"*",o,i):"{numpadsubtract}"===t?s=this.addStringAt(s,"-",o,i):"{numpadadd}"===t?s=this.addStringAt(s,"+",o,i):"{numpaddecimal}"===t?s=this.addStringAt(s,".",o,i):"{"===t||"}"===t?s=this.addStringAt(s,t,o,i):t.includes("{")||t.includes("}")||(s=this.addStringAt(s,t,o,i)):s=this.addStringAt(s,"\n",o,i):s=this.addStringAt(s,"\t",o,i),s}},{key:"updateCaretPos",value:function(t,e){var n=this.updateCaretPosAction(this.simpleKeyboardInstance,t,e);this.simpleKeyboardInstance.options.syncInstanceInputs&&this.simpleKeyboardInstance.dispatch(function(t){t.caretPosition=n})}},{key:"updateCaretPosAction",value:function(t,e,n){return n?t.caretPosition>0&&(t.caretPosition=t.caretPosition-e):t.caretPosition=t.caretPosition+e,this.simpleKeyboardInstance.options.debug&&console.log("Caret at:",t.caretPosition,"(".concat(t.keyboardDOMClass,")")),t.caretPosition}},{key:"addStringAt",value:function(t,e,n,o){var i;return n||0===n?(i=[t.slice(0,n),e,t.slice(n)].join(""),this.isMaxLengthReached()||o&&this.updateCaretPos(e.length)):i=t+e,i}},{key:"removeAt",value:function(t,e,n){if(0===this.simpleKeyboardInstance.caretPosition)return t;var o,i=/([\uD800-\uDBFF][\uDC00-\uDFFF])/g;return e&&e>=0?t.substring(e-2,e).match(i)?(o=t.substr(0,e-2)+t.substr(e),n&&this.updateCaretPos(2,!0)):(o=t.substr(0,e-1)+t.substr(e),n&&this.updateCaretPos(1,!0)):t.slice(-2).match(i)?(o=t.slice(0,-2),n&&this.updateCaretPos(2,!0)):(o=t.slice(0,-1),n&&this.updateCaretPos(1,!0)),o}},{key:"handleMaxLength",value:function(t,e,n){var o=e.maxLength,i=t[e.inputName],s=i.length===o;if(n.length<=i.length)return!1;if(Number.isInteger(o))return e.debug&&console.log("maxLength (num) reached:",s),s?(this.maxLengthReached=!0,!0):(this.maxLengthReached=!1,!1);if("object"===u(o)){var a=i.length===o[e.inputName];return e.debug&&console.log("maxLength (obj) reached:",a),a?(this.maxLengthReached=!0,!0):(this.maxLengthReached=!1,!1)}}},{key:"isMaxLengthReached",value:function(){return Boolean(this.maxLengthReached)}},{key:"isTouchDevice",value:function(){return"ontouchstart"in window||navigator.maxTouchPoints}},{key:"pointerEventsSupported",value:function(){return window.PointerEvent}},{key:"camelCase",value:function(t){return t.toLowerCase().trim().split(/[.\-_\s]/g).reduce(function(t,e){return e.length?t+e[0].toUpperCase()+e.slice(1):t})}},{key:"countInArray",value:function(t,e){return t.reduce(function(t,n){return t+(n===e)},0)}}])&&r(e.prototype,n),o&&r(e,o),t}();function l(t){return(l="function"===typeof Symbol&&"symbol"===typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"===typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function h(t,e){for(var n=0;n1?n:n[0]),e}},{key:"inputPatternIsValid",value:function(t){var e,n=this.options.inputPattern;if((e=n instanceof RegExp?n:n[this.options.inputName])&&t){var o=e.test(t);return this.options.debug&&console.log('inputPattern ("'.concat(e,'"): ').concat(o?"passed":"did not pass!")),o}return!0}},{key:"handleCaret",value:function(){this.caretPosition=null;var t=window.SimpleKeyboardInstances;(t&&Object.keys(t)[0]===this.utilities.camelCase(this.keyboardDOMClass)||!t)&&(this.options.debug&&console.log("Caret handling started (".concat(this.keyboardDOMClass,")")),document.addEventListener("keyup",this.caretEventHandler),document.addEventListener("mouseup",this.caretEventHandler),document.addEventListener("touchend",this.caretEventHandler))}},{key:"caretEventHandler",value:function(t){var e;t.target.tagName&&(e=t.target.tagName.toLowerCase()),this.dispatch(function(n){n.isMouseHold&&(n.isMouseHold=!1),"textarea"!==e&&"input"!==e||n.options.disableCaretPositioning?n.options.disableCaretPositioning&&(n.caretPosition=null):(n.caretPosition=t.target.selectionStart,n.options.debug&&console.log("Caret at: ",t.target.selectionStart,t.target.tagName.toLowerCase(),"(".concat(n.keyboardDOMClass,")")))})}},{key:"destroy",value:function(){document.removeEventListener("keyup",this.caretEventHandler),document.removeEventListener("mouseup",this.caretEventHandler),document.removeEventListener("touchend",this.caretEventHandler),this.clear()}},{key:"getButtonTheme",value:function(){var t=this,e={};return this.options.buttonTheme.forEach(function(n){var o;n.buttons&&n.class?("string"===typeof n.buttons&&(o=n.buttons.split(" ")),o&&o.forEach(function(o){var i=e[o];i?t.utilities.countInArray(i.split(" "),n.class)||(e[o]="".concat(i," ").concat(n.class)):e[o]=n.class})):console.warn('buttonTheme row is missing the "buttons" or the "class". Please check the documentation.')}),e}},{key:"onTouchDeviceDetected",value:function(){this.processAutoTouchEvents(),this.disableContextualWindow()}},{key:"disableContextualWindow",value:function(){window.oncontextmenu=function(t){if(t.target.classList.contains("hg-button"))return t.preventDefault(),t.stopPropagation(),!1}}},{key:"processAutoTouchEvents",value:function(){this.options.autoUseTouchEvents&&(this.options.useTouchEvents=!0,this.options.debug&&console.log("autoUseTouchEvents: Touch device detected, useTouchEvents enabled."))}},{key:"onInit",value:function(){this.options.debug&&console.log("".concat(this.keyboardDOMClass," Initialized")),this.handleCaret(),"function"===typeof this.options.onInit&&this.options.onInit()}},{key:"beforeFirstRender",value:function(){this.utilities.isTouchDevice()&&this.onTouchDeviceDetected(),"function"===typeof this.options.beforeFirstRender&&this.options.beforeFirstRender(),!this.utilities.pointerEventsSupported()||this.options.useTouchEvents||this.options.useMouseEvents||this.options.debug&&console.log("Using PointerEvents as it is supported by this browser"),this.options.useTouchEvents&&this.options.debug&&console.log("useTouchEvents has been enabled. Only touch events will be used.")}},{key:"beforeRender",value:function(){"function"===typeof this.options.beforeRender&&this.options.beforeRender()}},{key:"onRender",value:function(){"function"===typeof this.options.onRender&&this.options.onRender()}},{key:"onModulesLoaded",value:function(){"function"===typeof this.options.onModulesLoaded&&this.options.onModulesLoaded()}},{key:"loadModules",value:function(){var t=this;Array.isArray(this.options.modules)&&(this.options.modules.forEach(function(e){var n=new e;if(n.constructor.name&&"Function"!==n.constructor.name){var o="module-".concat(t.utilities.camelCase(n.constructor.name));t.keyboardPluginClasses=t.keyboardPluginClasses+" ".concat(o)}n.init(t)}),this.keyboardPluginClasses=this.keyboardPluginClasses+" modules-loaded",this.render(),this.onModulesLoaded())}},{key:"getModuleProp",value:function(t,e){return!!this.modules[t]&&this.modules[t][e]}},{key:"getModulesList",value:function(){return Object.keys(this.modules)}},{key:"parseRowDOMContainers",value:function(t,e,n,o){var i=this,s=Array.from(t.children),a=0;return s.length&&n.forEach(function(n,u){var r=o[u];if(!r||!(r>n))return!1;var c=n-a,l=r-a,h=document.createElement("div");h.className+="hg-button-container";var d="".concat(i.options.layoutName,"-r").concat(e,"c").concat(u);h.setAttribute("data-skUID",d);var p=s.splice(c,l-c+1);a=l-c,p.forEach(function(t){return h.appendChild(t)}),s.splice(c,0,h),t.innerHTML="",s.forEach(function(e){return t.appendChild(e)}),i.options.debug&&console.log("rowDOMContainer",p,c,l,a+1)}),t}},{key:"render",value:function(){var t=this;this.clear(),this.initialized||this.beforeFirstRender(),this.beforeRender();var e="hg-layout-".concat(this.options.layoutName),n=this.options.layout||a.getDefaultLayout(),o=this.options.useTouchEvents||!1,i=o?"hg-touch-events":"",s=this.options.useMouseEvents||!1,u=this.options.disableRowButtonContainers,r=Array.isArray(this.options.buttonTheme)?this.getButtonTheme():{};this.keyboardDOM.className+=" ".concat(this.options.theme," ").concat(e," ").concat(this.keyboardPluginClasses," ").concat(i),n[this.options.layoutName].forEach(function(e,n){var i=e.split(" "),a=document.createElement("div");a.className+="hg-row";var c=[],l=[];i.forEach(function(e,i){var h=!u&&e.includes("[")&&e.length>1,d=!u&&e.includes("]")&&e.length>1;h&&(c.push(i),e=e.replace(/\[/g,"")),d&&(l.push(i),e=e.replace(/\]/g,""));var p=t.utilities.getButtonClass(e),f=r[e],m=t.utilities.getButtonDisplayName(e,t.options.display,t.options.mergeDisplay),y=t.options.useButtonTag?"button":"div",b=document.createElement(y);b.className+="hg-button ".concat(p).concat(f?" "+f:""),!t.utilities.pointerEventsSupported()||o||s?o?(b.ontouchstart=function(n){t.handleButtonClicked(e),t.handleButtonMouseDown(e,n)},b.ontouchend=function(e){return t.handleButtonMouseUp()},b.ontouchcancel=function(e){return t.handleButtonMouseUp()}):(b.onclick=function(){t.isMouseHold=!1,t.handleButtonClicked(e)},b.onmousedown=function(n){t.handleButtonMouseDown(e,n)}):(b.onpointerdown=function(n){t.handleButtonClicked(e),t.handleButtonMouseDown(e,n)},b.onpointerup=function(e){t.handleButtonMouseUp()},b.onpointercancel=function(e){return t.handleButtonMouseUp()}),b.setAttribute("data-skBtn",e);var v="".concat(t.options.layoutName,"-r").concat(n,"b").concat(i);b.setAttribute("data-skBtnUID",v),b.setAttribute("data-displayLabel",m);var g=document.createElement("span");g.innerHTML=m,b.appendChild(g),t.buttonElements[e]||(t.buttonElements[e]=[]),t.buttonElements[e].push(b),a.appendChild(b)}),a=t.parseRowDOMContainers(a,n,c,l),t.keyboardDOM.appendChild(a)}),this.onRender(),this.initialized||(this.initialized=!0,!this.utilities.pointerEventsSupported()||o||s?o?(document.ontouchend=function(e){return t.handleButtonMouseUp()},document.ontouchcancel=function(e){return t.handleButtonMouseUp()}):o||(document.onmouseup=function(){return t.handleButtonMouseUp()}):document.onpointerup=function(){return t.handleButtonMouseUp()},this.onInit())}}])&&h(e.prototype,n),o&&h(e,o),t}();e.default=d}])}); +!function(t,e){"object"===typeof exports&&"object"===typeof module?module.exports=e():"function"===typeof define&&define.amd?define("SimpleKeyboard",[],e):"object"===typeof exports?exports.SimpleKeyboard=e():t.SimpleKeyboard=e()}(window,function(){return function(t){var e={};function n(o){if(e[o])return e[o].exports;var i=e[o]={i:o,l:!1,exports:{}};return t[o].call(i.exports,i,i.exports,n),i.l=!0,i.exports}return n.m=t,n.c=e,n.d=function(t,e,o){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:o})},n.r=function(t){"undefined"!==typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"===typeof t&&t&&t.__esModule)return t;var o=Object.create(null);if(n.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var i in t)n.d(o,i,function(e){return t[e]}.bind(null,i));return o},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=0)}([function(t,e,n){t.exports=n(2)},function(t,e,n){},function(t,e,n){"use strict";n.r(e);n(1);function o(t){return(o="function"===typeof Symbol&&"symbol"===typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"===typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function i(t,e){for(var n=0;n0?s=this.removeAt(s,n,o):"{space}"===t?s=this.addStringAt(s," ",n,o):"{tab}"!==t||"boolean"===typeof i.tabCharOnTab&&!1===i.tabCharOnTab?"{enter}"!==t&&"{numpadenter}"!==t||!i.newLineOnEnter?t.includes("numpad")&&Number.isInteger(Number(t[t.length-2]))?s=this.addStringAt(s,t[t.length-2],n,o):"{numpaddivide}"===t?s=this.addStringAt(s,"/",n,o):"{numpadmultiply}"===t?s=this.addStringAt(s,"*",n,o):"{numpadsubtract}"===t?s=this.addStringAt(s,"-",n,o):"{numpadadd}"===t?s=this.addStringAt(s,"+",n,o):"{numpaddecimal}"===t?s=this.addStringAt(s,".",n,o):"{"===t||"}"===t?s=this.addStringAt(s,t,n,o):t.includes("{")||t.includes("}")||(s=this.addStringAt(s,t,n,o)):s=this.addStringAt(s,"\n",n,o):s=this.addStringAt(s,"\t",n,o),s}},{key:"updateCaretPos",value:function(t,e){var n=this.updateCaretPosAction(t,e);this.dispatch(function(t){t.caretPosition=n})}},{key:"updateCaretPosAction",value:function(t,e){var n=this.getOptions(),o=this.getCaretPosition();return e?o>0&&(o-=t):o+=t,n.debug&&console.log("Caret at:",o,"(".concat(this.keyboardDOMClass,")")),o}},{key:"addStringAt",value:function(t,e,n,o){var i;return n||0===n?(i=[t.slice(0,n),e,t.slice(n)].join(""),this.isMaxLengthReached()||o&&this.updateCaretPos(e.length)):i=t+e,i}},{key:"removeAt",value:function(t,e,n){var o;if(0===this.getCaretPosition())return t;var i=/([\uD800-\uDBFF][\uDC00-\uDFFF])/g;return e&&e>=0?t.substring(e-2,e).match(i)?(o=t.substr(0,e-2)+t.substr(e),n&&this.updateCaretPos(2,!0)):(o=t.substr(0,e-1)+t.substr(e),n&&this.updateCaretPos(1,!0)):t.slice(-2).match(i)?(o=t.slice(0,-2),n&&this.updateCaretPos(2,!0)):(o=t.slice(0,-1),n&&this.updateCaretPos(1,!0)),o}},{key:"handleMaxLength",value:function(t,e){var n=this.getOptions(),i=n.maxLength,s=t[n.inputName],a=s.length===i;if(e.length<=s.length)return!1;if(Number.isInteger(i))return n.debug&&console.log("maxLength (num) reached:",a),a?(this.maxLengthReached=!0,!0):(this.maxLengthReached=!1,!1);if("object"===o(i)){var u=s.length===i[n.inputName];return n.debug&&console.log("maxLength (obj) reached:",u),u?(this.maxLengthReached=!0,!0):(this.maxLengthReached=!1,!1)}}},{key:"isMaxLengthReached",value:function(){return Boolean(this.maxLengthReached)}},{key:"isTouchDevice",value:function(){return"ontouchstart"in window||navigator.maxTouchPoints}},{key:"pointerEventsSupported",value:function(){return window.PointerEvent}},{key:"camelCase",value:function(t){return!!t&&t.toLowerCase().trim().split(/[.\-_\s]/g).reduce(function(t,e){return e.length?t+e[0].toUpperCase()+e.slice(1):t})}},{key:"countInArray",value:function(t,e){return t.reduce(function(t,n){return t+(n===e)},0)}}])&&i(e.prototype,n),s&&i(e,s),t}();function a(t,e){for(var n=0;n ? {shift}",".com @ {space}"]}}}],(n=null)&&r(e.prototype,n),o&&r(e,o),t}();function l(t){return(l="function"===typeof Symbol&&"symbol"===typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"===typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function h(t,e){for(var n=0;n1?n:n[0]),e}},{key:"inputPatternIsValid",value:function(t){var e,n=this.options.inputPattern;if((e=n instanceof RegExp?n:n[this.options.inputName])&&t){var o=e.test(t);return this.options.debug&&console.log('inputPattern ("'.concat(e,'"): ').concat(o?"passed":"did not pass!")),o}return!0}},{key:"setEventListeners",value:function(){!this.isFirstKeyboardInstance&&this.allKeyboardInstances||(this.options.debug&&console.log("Caret handling started (".concat(this.keyboardDOMClass,")")),document.addEventListener("keyup",this.handleKeyUp),document.addEventListener("keydown",this.handleKeyDown),document.addEventListener("mouseup",this.handleMouseUp),document.addEventListener("touchend",this.handleTouchEnd))}},{key:"handleKeyUp",value:function(t){this.caretEventHandler(t),this.options.physicalKeyboardHighlight&&this.physicalKeyboard.handleHighlightKeyUp(t)}},{key:"handleKeyDown",value:function(t){this.options.physicalKeyboardHighlight&&this.physicalKeyboard.handleHighlightKeyDown(t)}},{key:"handleMouseUp",value:function(t){this.caretEventHandler(t)}},{key:"handleTouchEnd",value:function(t){this.caretEventHandler(t)}},{key:"caretEventHandler",value:function(t){var e;t.target.tagName&&(e=t.target.tagName.toLowerCase()),this.dispatch(function(n){n.isMouseHold&&(n.isMouseHold=!1),"textarea"!==e&&"input"!==e||n.options.disableCaretPositioning?n.options.disableCaretPositioning&&(n.caretPosition=null):(n.caretPosition=t.target.selectionStart,n.options.debug&&console.log("Caret at: ",t.target.selectionStart,t.target.tagName.toLowerCase(),"(".concat(n.keyboardDOMClass,")")))})}},{key:"destroy",value:function(){document.removeEventListener("keyup",this.handleKeyUp),document.removeEventListener("keydown",this.handleKeyDown),document.removeEventListener("mouseup",this.handleMouseUp),document.removeEventListener("touchend",this.handleTouchEnd),this.clear()}},{key:"getButtonTheme",value:function(){var t=this,e={};return this.options.buttonTheme.forEach(function(n){var o;n.buttons&&n.class?("string"===typeof n.buttons&&(o=n.buttons.split(" ")),o&&o.forEach(function(o){var i=e[o];i?t.utilities.countInArray(i.split(" "),n.class)||(e[o]="".concat(i," ").concat(n.class)):e[o]=n.class})):console.warn('buttonTheme row is missing the "buttons" or the "class". Please check the documentation.')}),e}},{key:"onTouchDeviceDetected",value:function(){this.processAutoTouchEvents(),this.disableContextualWindow()}},{key:"disableContextualWindow",value:function(){window.oncontextmenu=function(t){if(t.target.classList.contains("hg-button"))return t.preventDefault(),t.stopPropagation(),!1}}},{key:"processAutoTouchEvents",value:function(){this.options.autoUseTouchEvents&&(this.options.useTouchEvents=!0,this.options.debug&&console.log("autoUseTouchEvents: Touch device detected, useTouchEvents enabled."))}},{key:"onInit",value:function(){this.options.debug&&console.log("".concat(this.keyboardDOMClass," Initialized")),this.setEventListeners(),"function"===typeof this.options.onInit&&this.options.onInit()}},{key:"beforeFirstRender",value:function(){this.utilities.isTouchDevice()&&this.onTouchDeviceDetected(),"function"===typeof this.options.beforeFirstRender&&this.options.beforeFirstRender(),this.isFirstKeyboardInstance&&this.utilities.pointerEventsSupported()&&!this.options.useTouchEvents&&!this.options.useMouseEvents&&this.options.debug&&console.log("Using PointerEvents as it is supported by this browser"),this.options.useTouchEvents&&this.options.debug&&console.log("useTouchEvents has been enabled. Only touch events will be used.")}},{key:"beforeRender",value:function(){"function"===typeof this.options.beforeRender&&this.options.beforeRender()}},{key:"onRender",value:function(){"function"===typeof this.options.onRender&&this.options.onRender()}},{key:"onModulesLoaded",value:function(){"function"===typeof this.options.onModulesLoaded&&this.options.onModulesLoaded()}},{key:"loadModules",value:function(){var t=this;Array.isArray(this.options.modules)&&(this.options.modules.forEach(function(e){var n=new e;if(n.constructor.name&&"Function"!==n.constructor.name){var o="module-".concat(t.utilities.camelCase(n.constructor.name));t.keyboardPluginClasses=t.keyboardPluginClasses+" ".concat(o)}n.init(t)}),this.keyboardPluginClasses=this.keyboardPluginClasses+" modules-loaded",this.render(),this.onModulesLoaded())}},{key:"getModuleProp",value:function(t,e){return!!this.modules[t]&&this.modules[t][e]}},{key:"getModulesList",value:function(){return Object.keys(this.modules)}},{key:"parseRowDOMContainers",value:function(t,e,n,o){var i=this,s=Array.from(t.children),a=0;return s.length&&n.forEach(function(n,u){var r=o[u];if(!r||!(r>n))return!1;var c=n-a,l=r-a,h=document.createElement("div");h.className+="hg-button-container";var d="".concat(i.options.layoutName,"-r").concat(e,"c").concat(u);h.setAttribute("data-skUID",d);var p=s.splice(c,l-c+1);a=l-c,p.forEach(function(t){return h.appendChild(t)}),s.splice(c,0,h),t.innerHTML="",s.forEach(function(e){return t.appendChild(e)}),i.options.debug&&console.log("rowDOMContainer",p,c,l,a+1)}),t}},{key:"render",value:function(){var t=this;this.clear(),this.initialized||this.beforeFirstRender(),this.beforeRender();var e="hg-layout-".concat(this.options.layoutName),n=this.options.layout||c.getDefaultLayout(),o=this.options.useTouchEvents||!1,i=o?"hg-touch-events":"",s=this.options.useMouseEvents||!1,a=this.options.disableRowButtonContainers,u=Array.isArray(this.options.buttonTheme)?this.getButtonTheme():{};this.keyboardDOM.className+=" ".concat(this.options.theme," ").concat(e," ").concat(this.keyboardPluginClasses," ").concat(i),n[this.options.layoutName].forEach(function(e,n){var i=e.split(" "),r=document.createElement("div");r.className+="hg-row";var c=[],l=[];i.forEach(function(e,i){var h=!a&&e.includes("[")&&e.length>1,d=!a&&e.includes("]")&&e.length>1;h&&(c.push(i),e=e.replace(/\[/g,"")),d&&(l.push(i),e=e.replace(/\]/g,""));var p=t.utilities.getButtonClass(e),f=u[e],y=t.utilities.getButtonDisplayName(e,t.options.display,t.options.mergeDisplay),m=t.options.useButtonTag?"button":"div",b=document.createElement(m);b.className+="hg-button ".concat(p).concat(f?" "+f:""),!t.utilities.pointerEventsSupported()||o||s?o?(b.ontouchstart=function(n){t.handleButtonClicked(e),t.handleButtonMouseDown(e,n)},b.ontouchend=function(e){return t.handleButtonMouseUp()},b.ontouchcancel=function(e){return t.handleButtonMouseUp()}):(b.onclick=function(){t.isMouseHold=!1,t.handleButtonClicked(e)},b.onmousedown=function(n){t.handleButtonMouseDown(e,n)}):(b.onpointerdown=function(n){t.handleButtonClicked(e),t.handleButtonMouseDown(e,n)},b.onpointerup=function(e){t.handleButtonMouseUp()},b.onpointercancel=function(e){return t.handleButtonMouseUp()}),b.setAttribute("data-skBtn",e);var g="".concat(t.options.layoutName,"-r").concat(n,"b").concat(i);b.setAttribute("data-skBtnUID",g),b.setAttribute("data-displayLabel",y);var v=document.createElement("span");v.innerHTML=y,b.appendChild(v),t.buttonElements[e]||(t.buttonElements[e]=[]),t.buttonElements[e].push(b),r.appendChild(b)}),r=t.parseRowDOMContainers(r,n,c,l),t.keyboardDOM.appendChild(r)}),this.onRender(),this.initialized||(this.initialized=!0,!this.utilities.pointerEventsSupported()||o||s?o?(document.ontouchend=function(e){return t.handleButtonMouseUp()},document.ontouchcancel=function(e){return t.handleButtonMouseUp()}):o||(document.onmouseup=function(){return t.handleButtonMouseUp()}):document.onpointerup=function(){return t.handleButtonMouseUp()},this.onInit())}}])&&h(e.prototype,n),o&&h(e,o),t}();e.default=d}])}); //# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/build/index.js.map b/build/index.js.map index c51f23e8..debd7da3 100644 --- a/build/index.js.map +++ b/build/index.js.map @@ -1 +1 @@ -{"version":3,"sources":["../../webpack/universalModuleDefinition","../../webpack/bootstrap","services/PhysicalKeyboard.js","services/KeyboardLayout.js","services/Utilities.js","components/Keyboard.js","index.js"],"names":["root","factory","exports","module","define","amd","window","installedModules","__webpack_require__","moduleId","i","l","modules","call","m","c","d","name","getter","o","Object","defineProperty","enumerable","get","r","Symbol","toStringTag","value","t","mode","__esModule","ns","create","key","bind","n","object","property","prototype","hasOwnProperty","p","s","PhysicalKeyboard","simpleKeyboardInstance","_classCallCheck","this","initKeyboardListener","getSimpleKeyboardLayoutKey","_this","document","addEventListener","event","options","physicalKeyboardHighlight","buttonPressed","dispatch","instance","buttonDOM","getButtonElement","concat","style","backgroundColor","physicalKeyboardHighlightBgColor","color","physicalKeyboardHighlightTextColor","removeAttribute","output","code","includes","toUpperCase","Number","isInteger","length","toLowerCase","KeyboardLayout","default","shift","Utilities","Utilities_classCallCheck","bindMethods","myClass","_iteratorNormalCompletion","_didIteratorError","_iteratorError","undefined","_step","_iterator","getOwnPropertyNames","iterator","next","done","myMethod","err","return","button","buttonTypeClass","buttonWithoutBraces","replace","buttonNormalized","{bksp}","{backspace}","{enter}","{shift}","{shiftleft}","{shiftright}","{alt}","{s}","{tab}","{lock}","{capslock}","{accept}","{space}","{//}","{esc}","{escape}","{f1}","{f2}","{f3}","{f4}","{f5}","{f6}","{f7}","{f8}","{f9}","{f10}","{f11}","{f12}","{numpaddivide}","{numlock}","{arrowup}","{arrowleft}","{arrowdown}","{arrowright}","{prtscr}","{scrolllock}","{pause}","{insert}","{home}","{pageup}","{delete}","{end}","{pagedown}","{numpadmultiply}","{numpadsubtract}","{numpadadd}","{numpadenter}","{period}","{numpaddecimal}","{numpad0}","{numpad1}","{numpad2}","{numpad3}","{numpad4}","{numpad5}","{numpad6}","{numpad7}","{numpad8}","{numpad9}","display","mergeDisplay","assign","getDefaultDiplay","input","caretPos","moveCaret","removeAt","addStringAt","tabCharOnTab","newLineOnEnter","minus","newCaretPos","updateCaretPosAction","syncInstanceInputs","caretPosition","debug","console","log","keyboardDOMClass","source","string","position","slice","join","isMaxLengthReached","updateCaretPos","emojiMatchedReg","substring","match","substr","inputObj","updatedInput","maxLength","currentInput","inputName","condition","maxLengthReached","_typeof","Boolean","navigator","maxTouchPoints","PointerEvent","trim","split","reduce","word","array","x","SimpleKeyboard","Keyboard_classCallCheck","registerModule","initCallback","keyboardDOMQuery","arguments","Keyboard_typeof","utilities","keyboardDOM","querySelector","layoutName","theme","preventMouseDownDefault","keyboardPluginClasses","buttonElements","warn","Error","render","camelCase","physicalKeyboardInterface","loadModules","onKeyPress","getUpdatedInput","inputPattern","inputPatternIsValid","handleMaxLength","onChange","onChangeAll","e","_this2","preventDefault","stopMouseDownPropagation","stopPropagation","isMouseHold","holdInteractionTimeout","clearTimeout","holdTimeout","disableButtonHold","setTimeout","handleButtonHold","_this3","handleButtonClicked","_this4","replaceInput","onSetOptions","innerHTML","className","callback","keys","forEach","buttons","_this5","classNameItem","buttonTheme","classNameFound","map","class","buttonThemeArray","push","_this6","Array","isArray","index","filteredButtonArray","filter","item","splice","buttonArr","inputVal","inputPatternRaw","RegExp","didInputMatch","test","simpleKeyboardInstances","caretEventHandler","targetTagName","target","tagName","disableCaretPositioning","selectionStart","removeEventListener","clear","_this7","buttonThemesParsed","themeObj","themeButtons","themeButton","themeParsed","countInArray","processAutoTouchEvents","disableContextualWindow","oncontextmenu","classList","contains","autoUseTouchEvents","useTouchEvents","handleCaret","onInit","isTouchDevice","onTouchDeviceDetected","beforeFirstRender","pointerEventsSupported","useMouseEvents","beforeRender","onRender","onModulesLoaded","_this8","Module","constructor","classStr","init","prop","rowDOM","rowIndex","containerStartIndexes","containerEndIndexes","_this9","rowDOMArray","from","children","removedElements","startIndex","arrIndex","endIndex","updated_startIndex","updated_endIndex","containerDOM","createElement","containerUID","setAttribute","containedElements","element","appendChild","_this10","initialized","layoutClass","layout","getDefaultLayout","useTouchEventsClass","disableRowButtonContainers","getButtonTheme","row","rIndex","rowArray","bIndex","buttonHasContainerStart","buttonHasContainerEnd","fctBtnClass","getButtonClass","buttonThemeClass","buttonDisplayName","getButtonDisplayName","buttonType","useButtonTag","ontouchstart","handleButtonMouseDown","ontouchend","handleButtonMouseUp","ontouchcancel","onclick","onmousedown","onpointerdown","onpointerup","onpointercancel","buttonUID","buttonSpanDOM","parseRowDOMContainers","onmouseup"],"mappings":";;;;;;;;;;;CAAA,SAAAA,EAAAC,GACA,kBAAAC,SAAA,kBAAAC,OACAA,OAAAD,QAAAD,IACA,oBAAAG,eAAAC,IACAD,OAAA,oBAAAH,GACA,kBAAAC,QACAA,QAAA,eAAAD,IAEAD,EAAA,eAAAC,IARA,CASCK,OAAA,WACD,mBCTA,IAAAC,EAAA,GAGA,SAAAC,EAAAC,GAGA,GAAAF,EAAAE,GACA,OAAAF,EAAAE,GAAAP,QAGA,IAAAC,EAAAI,EAAAE,GAAA,CACAC,EAAAD,EACAE,GAAA,EACAT,QAAA,IAUA,OANAU,EAAAH,GAAAI,KAAAV,EAAAD,QAAAC,IAAAD,QAAAM,GAGAL,EAAAQ,GAAA,EAGAR,EAAAD,QA0DA,OArDAM,EAAAM,EAAAF,EAGAJ,EAAAO,EAAAR,EAGAC,EAAAQ,EAAA,SAAAd,EAAAe,EAAAC,GACAV,EAAAW,EAAAjB,EAAAe,IACAG,OAAAC,eAAAnB,EAAAe,EAAA,CAA0CK,YAAA,EAAAC,IAAAL,KAK1CV,EAAAgB,EAAA,SAAAtB,GACA,qBAAAuB,eAAAC,aACAN,OAAAC,eAAAnB,EAAAuB,OAAAC,YAAA,CAAwDC,MAAA,WAExDP,OAAAC,eAAAnB,EAAA,cAAiDyB,OAAA,KAQjDnB,EAAAoB,EAAA,SAAAD,EAAAE,GAEA,GADA,EAAAA,IAAAF,EAAAnB,EAAAmB,IACA,EAAAE,EAAA,OAAAF,EACA,KAAAE,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C/T,KAAKmQ,+CC3sCIjG","file":"index.js","sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine(\"SimpleKeyboard\", [], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"SimpleKeyboard\"] = factory();\n\telse\n\t\troot[\"SimpleKeyboard\"] = factory();\n})(window, function() {\nreturn "," \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId]) {\n \t\t\treturn installedModules[moduleId].exports;\n \t\t}\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.l = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// define getter function for harmony exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tif(!__webpack_require__.o(exports, name)) {\n \t\t\tObject.defineProperty(exports, name, { enumerable: true, get: getter });\n \t\t}\n \t};\n\n \t// define __esModule on exports\n \t__webpack_require__.r = function(exports) {\n \t\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n \t\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n \t\t}\n \t\tObject.defineProperty(exports, '__esModule', { value: true });\n \t};\n\n \t// create a fake namespace object\n \t// mode & 1: value is a module id, require it\n \t// mode & 2: merge all properties of value into the ns\n \t// mode & 4: return value when already ns object\n \t// mode & 8|1: behave like require\n \t__webpack_require__.t = function(value, mode) {\n \t\tif(mode & 1) value = __webpack_require__(value);\n \t\tif(mode & 8) return value;\n \t\tif((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;\n \t\tvar ns = Object.create(null);\n \t\t__webpack_require__.r(ns);\n \t\tObject.defineProperty(ns, 'default', { enumerable: true, value: value });\n \t\tif(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));\n \t\treturn ns;\n \t};\n\n \t// getDefaultExport function for compatibility with non-harmony modules\n \t__webpack_require__.n = function(module) {\n \t\tvar getter = module && module.__esModule ?\n \t\t\tfunction getDefault() { return module['default']; } :\n \t\t\tfunction getModuleExports() { return module; };\n \t\t__webpack_require__.d(getter, 'a', getter);\n \t\treturn getter;\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = 0);\n","/**\r\n * Physical Keyboard Service\r\n */\r\nclass PhysicalKeyboard {\r\n /**\r\n * Creates an instance of the PhysicalKeyboard service\r\n */\r\n constructor(simpleKeyboardInstance) {\r\n /**\r\n * @type {object} A simple-keyboard instance\r\n */\r\n this.simpleKeyboardInstance = simpleKeyboardInstance;\r\n\r\n /**\r\n * Bindings\r\n */\r\n this.initKeyboardListener = this.initKeyboardListener.bind(this);\r\n this.getSimpleKeyboardLayoutKey = this.getSimpleKeyboardLayoutKey.bind(\r\n this\r\n );\r\n\r\n /**\r\n * Initialize key listeners\r\n */\r\n this.initKeyboardListener();\r\n }\r\n\r\n /**\r\n * Initializes key event listeners\r\n */\r\n initKeyboardListener() {\r\n // Adding button style on keydown\r\n document.addEventListener(\"keydown\", event => {\r\n if (this.simpleKeyboardInstance.options.physicalKeyboardHighlight) {\r\n let buttonPressed = this.getSimpleKeyboardLayoutKey(event);\r\n\r\n this.simpleKeyboardInstance.dispatch(instance => {\r\n let buttonDOM =\r\n instance.getButtonElement(buttonPressed) ||\r\n instance.getButtonElement(`{${buttonPressed}}`);\r\n\r\n if (buttonDOM) {\r\n buttonDOM.style.backgroundColor =\r\n this.simpleKeyboardInstance.options\r\n .physicalKeyboardHighlightBgColor || \"#9ab4d0\";\r\n buttonDOM.style.color =\r\n this.simpleKeyboardInstance.options\r\n .physicalKeyboardHighlightTextColor || \"white\";\r\n }\r\n });\r\n }\r\n });\r\n\r\n // Removing button style on keyup\r\n document.addEventListener(\"keyup\", event => {\r\n if (this.simpleKeyboardInstance.options.physicalKeyboardHighlight) {\r\n let buttonPressed = this.getSimpleKeyboardLayoutKey(event);\r\n\r\n this.simpleKeyboardInstance.dispatch(instance => {\r\n let buttonDOM =\r\n instance.getButtonElement(buttonPressed) ||\r\n instance.getButtonElement(`{${buttonPressed}}`);\r\n\r\n if (buttonDOM && buttonDOM.removeAttribute) {\r\n buttonDOM.removeAttribute(\"style\");\r\n }\r\n });\r\n }\r\n });\r\n }\r\n\r\n /**\r\n * Transforms a KeyboardEvent's \"key.code\" string into a simple-keyboard layout format\r\n * @param {object} event The KeyboardEvent\r\n */\r\n getSimpleKeyboardLayoutKey(event) {\r\n let output;\r\n\r\n if (\r\n event.code.includes(\"Numpad\") ||\r\n event.code.includes(\"Shift\") ||\r\n event.code.includes(\"Space\") ||\r\n event.code.includes(\"Backspace\") ||\r\n event.code.includes(\"Control\") ||\r\n event.code.includes(\"Alt\") ||\r\n event.code.includes(\"Meta\")\r\n ) {\r\n output = event.code;\r\n } else {\r\n output = event.key;\r\n }\r\n\r\n /**\r\n * If button is not uppercase, casting to lowercase\r\n */\r\n if (\r\n output !== output.toUpperCase() ||\r\n (event.code[0] === \"F\" &&\r\n Number.isInteger(Number(event.code[1])) &&\r\n event.code.length <= 3)\r\n ) {\r\n output = output.toLowerCase();\r\n }\r\n\r\n return output;\r\n }\r\n}\r\n\r\nexport default PhysicalKeyboard;\r\n","/**\r\n * Keyboard Layout Service\r\n */\r\nclass KeyboardLayout {\r\n /**\r\n * Get default simple-keyboard layout\r\n * @return {object} The default layout (US-QWERTY)\r\n */\r\n static getDefaultLayout() {\r\n return {\r\n default: [\r\n \"` 1 2 3 4 5 6 7 8 9 0 - = {bksp}\",\r\n \"{tab} q w e r t y u i o p [ ] \\\\\",\r\n \"{lock} a s d f g h j k l ; ' {enter}\",\r\n \"{shift} z x c v b n m , . / {shift}\",\r\n \".com @ {space}\"\r\n ],\r\n shift: [\r\n \"~ ! @ # $ % ^ & * ( ) _ + {bksp}\",\r\n \"{tab} Q W E R T Y U I O P { } |\",\r\n '{lock} A S D F G H J K L : \" {enter}',\r\n \"{shift} Z X C V B N M < > ? {shift}\",\r\n \".com @ {space}\"\r\n ]\r\n };\r\n }\r\n}\r\n\r\nexport default KeyboardLayout;\r\n","/**\r\n * Utility Service\r\n */\r\nclass Utilities {\r\n /**\r\n * Creates an instance of the Utility service\r\n */\r\n constructor(simpleKeyboardInstance) {\r\n /**\r\n * @type {object} A simple-keyboard instance\r\n */\r\n this.simpleKeyboardInstance = simpleKeyboardInstance;\r\n\r\n /**\r\n * Bindings\r\n */\r\n Utilities.bindMethods(Utilities, this);\r\n }\r\n\r\n /**\r\n * Adds default classes to a given button\r\n *\r\n * @param {string} button The button's layout name\r\n * @return {string} The classes to be added to the button\r\n */\r\n getButtonClass(button) {\r\n let buttonTypeClass =\r\n button.includes(\"{\") && button.includes(\"}\") && button !== \"{//}\"\r\n ? \"functionBtn\"\r\n : \"standardBtn\";\r\n let buttonWithoutBraces = button.replace(\"{\", \"\").replace(\"}\", \"\");\r\n let buttonNormalized = \"\";\r\n\r\n if (buttonTypeClass !== \"standardBtn\")\r\n buttonNormalized = ` hg-button-${buttonWithoutBraces}`;\r\n\r\n return `hg-${buttonTypeClass}${buttonNormalized}`;\r\n }\r\n\r\n /**\r\n * Default button display labels\r\n */\r\n getDefaultDiplay() {\r\n return {\r\n \"{bksp}\": \"backspace\",\r\n \"{backspace}\": \"backspace\",\r\n \"{enter}\": \"< enter\",\r\n \"{shift}\": \"shift\",\r\n \"{shiftleft}\": \"shift\",\r\n \"{shiftright}\": \"shift\",\r\n \"{alt}\": \"alt\",\r\n \"{s}\": \"shift\",\r\n \"{tab}\": \"tab\",\r\n \"{lock}\": \"caps\",\r\n \"{capslock}\": \"caps\",\r\n \"{accept}\": \"Submit\",\r\n \"{space}\": \" \",\r\n \"{//}\": \" \",\r\n \"{esc}\": \"esc\",\r\n \"{escape}\": \"esc\",\r\n \"{f1}\": \"f1\",\r\n \"{f2}\": \"f2\",\r\n \"{f3}\": \"f3\",\r\n \"{f4}\": \"f4\",\r\n \"{f5}\": \"f5\",\r\n \"{f6}\": \"f6\",\r\n \"{f7}\": \"f7\",\r\n \"{f8}\": \"f8\",\r\n \"{f9}\": \"f9\",\r\n \"{f10}\": \"f10\",\r\n \"{f11}\": \"f11\",\r\n \"{f12}\": \"f12\",\r\n \"{numpaddivide}\": \"/\",\r\n \"{numlock}\": \"lock\",\r\n \"{arrowup}\": \"↑\",\r\n \"{arrowleft}\": \"←\",\r\n \"{arrowdown}\": \"↓\",\r\n \"{arrowright}\": \"→\",\r\n \"{prtscr}\": \"print\",\r\n \"{scrolllock}\": \"scroll\",\r\n \"{pause}\": \"pause\",\r\n \"{insert}\": \"ins\",\r\n \"{home}\": \"home\",\r\n \"{pageup}\": \"up\",\r\n \"{delete}\": \"del\",\r\n \"{end}\": \"end\",\r\n \"{pagedown}\": \"down\",\r\n \"{numpadmultiply}\": \"*\",\r\n \"{numpadsubtract}\": \"-\",\r\n \"{numpadadd}\": \"+\",\r\n \"{numpadenter}\": \"enter\",\r\n \"{period}\": \".\",\r\n \"{numpaddecimal}\": \".\",\r\n \"{numpad0}\": \"0\",\r\n \"{numpad1}\": \"1\",\r\n \"{numpad2}\": \"2\",\r\n \"{numpad3}\": \"3\",\r\n \"{numpad4}\": \"4\",\r\n \"{numpad5}\": \"5\",\r\n \"{numpad6}\": \"6\",\r\n \"{numpad7}\": \"7\",\r\n \"{numpad8}\": \"8\",\r\n \"{numpad9}\": \"9\"\r\n };\r\n }\r\n /**\r\n * Returns the display (label) name for a given button\r\n *\r\n * @param {string} button The button's layout name\r\n * @param {object} display The provided display option\r\n * @param {boolean} mergeDisplay Whether the provided param value should be merged with the default one.\r\n */\r\n getButtonDisplayName(button, display, mergeDisplay) {\r\n if (mergeDisplay) {\r\n display = Object.assign({}, this.getDefaultDiplay(), display);\r\n } else {\r\n display = display || this.getDefaultDiplay();\r\n }\r\n\r\n return display[button] || button;\r\n }\r\n\r\n /**\r\n * Returns the updated input resulting from clicking a given button\r\n *\r\n * @param {string} button The button's layout name\r\n * @param {string} input The input string\r\n * @param {object} options The simple-keyboard options object\r\n * @param {number} caretPos The cursor's current position\r\n * @param {boolean} moveCaret Whether to update simple-keyboard's cursor\r\n */\r\n getUpdatedInput(button, input, options, caretPos, moveCaret) {\r\n let output = input;\r\n\r\n if (\r\n (button === \"{bksp}\" || button === \"{backspace}\") &&\r\n output.length > 0\r\n ) {\r\n output = this.removeAt(output, caretPos, moveCaret);\r\n } else if (button === \"{space}\")\r\n output = this.addStringAt(output, \" \", caretPos, moveCaret);\r\n else if (\r\n button === \"{tab}\" &&\r\n !(\r\n typeof options.tabCharOnTab === \"boolean\" &&\r\n options.tabCharOnTab === false\r\n )\r\n ) {\r\n output = this.addStringAt(output, \"\\t\", caretPos, moveCaret);\r\n } else if (\r\n (button === \"{enter}\" || button === \"{numpadenter}\") &&\r\n options.newLineOnEnter\r\n )\r\n output = this.addStringAt(output, \"\\n\", caretPos, moveCaret);\r\n else if (\r\n button.includes(\"numpad\") &&\r\n Number.isInteger(Number(button[button.length - 2]))\r\n ) {\r\n output = this.addStringAt(\r\n output,\r\n button[button.length - 2],\r\n caretPos,\r\n moveCaret\r\n );\r\n } else if (button === \"{numpaddivide}\")\r\n output = this.addStringAt(output, \"/\", caretPos, moveCaret);\r\n else if (button === \"{numpadmultiply}\")\r\n output = this.addStringAt(output, \"*\", caretPos, moveCaret);\r\n else if (button === \"{numpadsubtract}\")\r\n output = this.addStringAt(output, \"-\", caretPos, moveCaret);\r\n else if (button === \"{numpadadd}\")\r\n output = this.addStringAt(output, \"+\", caretPos, moveCaret);\r\n else if (button === \"{numpaddecimal}\")\r\n output = this.addStringAt(output, \".\", caretPos, moveCaret);\r\n else if (button === \"{\" || button === \"}\")\r\n output = this.addStringAt(output, button, caretPos, moveCaret);\r\n else if (!button.includes(\"{\") && !button.includes(\"}\"))\r\n output = this.addStringAt(output, button, caretPos, moveCaret);\r\n\r\n return output;\r\n }\r\n\r\n /**\r\n * Moves the cursor position by a given amount\r\n *\r\n * @param {number} length Represents by how many characters the input should be moved\r\n * @param {boolean} minus Whether the cursor should be moved to the left or not.\r\n */\r\n updateCaretPos(length, minus) {\r\n let newCaretPos = this.updateCaretPosAction(\r\n this.simpleKeyboardInstance,\r\n length,\r\n minus\r\n );\r\n\r\n if (this.simpleKeyboardInstance.options.syncInstanceInputs) {\r\n this.simpleKeyboardInstance.dispatch(instance => {\r\n instance.caretPosition = newCaretPos;\r\n });\r\n }\r\n }\r\n\r\n /**\r\n * Action method of updateCaretPos\r\n *\r\n * @param {object} instance The instance whose position should be updated\r\n * @param {number} length Represents by how many characters the input should be moved\r\n * @param {boolean} minus Whether the cursor should be moved to the left or not.\r\n */\r\n updateCaretPosAction(instance, length, minus) {\r\n if (minus) {\r\n if (instance.caretPosition > 0)\r\n instance.caretPosition = instance.caretPosition - length;\r\n } else {\r\n instance.caretPosition = instance.caretPosition + length;\r\n }\r\n\r\n if (this.simpleKeyboardInstance.options.debug) {\r\n console.log(\r\n \"Caret at:\",\r\n instance.caretPosition,\r\n `(${instance.keyboardDOMClass})`\r\n );\r\n }\r\n\r\n return instance.caretPosition;\r\n }\r\n\r\n /**\r\n * Adds a string to the input at a given position\r\n *\r\n * @param {string} source The source input\r\n * @param {string} string The string to add\r\n * @param {number} position The (cursor) position where the string should be added\r\n * @param {boolean} moveCaret Whether to update simple-keyboard's cursor\r\n */\r\n addStringAt(source, string, position, moveCaret) {\r\n let output;\r\n\r\n if (!position && position !== 0) {\r\n output = source + string;\r\n } else {\r\n output = [source.slice(0, position), string, source.slice(position)].join(\r\n \"\"\r\n );\r\n\r\n /**\r\n * Avoid caret position change when maxLength is set\r\n */\r\n if (!this.isMaxLengthReached()) {\r\n if (moveCaret) this.updateCaretPos(string.length);\r\n }\r\n }\r\n\r\n return output;\r\n }\r\n\r\n /**\r\n * Removes an amount of characters at a given position\r\n *\r\n * @param {string} source The source input\r\n * @param {number} position The (cursor) position from where the characters should be removed\r\n * @param {boolean} moveCaret Whether to update simple-keyboard's cursor\r\n */\r\n removeAt(source, position, moveCaret) {\r\n if (this.simpleKeyboardInstance.caretPosition === 0) {\r\n return source;\r\n }\r\n\r\n let output;\r\n let prevTwoChars;\r\n let emojiMatched;\r\n let emojiMatchedReg = /([\\uD800-\\uDBFF][\\uDC00-\\uDFFF])/g;\r\n\r\n /**\r\n * Emojis are made out of two characters, so we must take a custom approach to trim them.\r\n * For more info: https://mathiasbynens.be/notes/javascript-unicode\r\n */\r\n if (position && position >= 0) {\r\n prevTwoChars = source.substring(position - 2, position);\r\n emojiMatched = prevTwoChars.match(emojiMatchedReg);\r\n\r\n if (emojiMatched) {\r\n output = source.substr(0, position - 2) + source.substr(position);\r\n if (moveCaret) this.updateCaretPos(2, true);\r\n } else {\r\n output = source.substr(0, position - 1) + source.substr(position);\r\n if (moveCaret) this.updateCaretPos(1, true);\r\n }\r\n } else {\r\n prevTwoChars = source.slice(-2);\r\n emojiMatched = prevTwoChars.match(emojiMatchedReg);\r\n\r\n if (emojiMatched) {\r\n output = source.slice(0, -2);\r\n if (moveCaret) this.updateCaretPos(2, true);\r\n } else {\r\n output = source.slice(0, -1);\r\n if (moveCaret) this.updateCaretPos(1, true);\r\n }\r\n }\r\n\r\n return output;\r\n }\r\n /**\r\n * Determines whether the maxLength has been reached. This function is called when the maxLength option it set.\r\n *\r\n * @param {object} inputObj\r\n * @param {object} options\r\n * @param {string} updatedInput\r\n */\r\n handleMaxLength(inputObj, options, updatedInput) {\r\n let maxLength = options.maxLength;\r\n let currentInput = inputObj[options.inputName];\r\n let condition = currentInput.length === maxLength;\r\n\r\n if (\r\n /**\r\n * If pressing this button won't add more characters\r\n * We exit out of this limiter function\r\n */\r\n updatedInput.length <= currentInput.length\r\n ) {\r\n return false;\r\n }\r\n\r\n if (Number.isInteger(maxLength)) {\r\n if (options.debug) {\r\n console.log(\"maxLength (num) reached:\", condition);\r\n }\r\n\r\n if (condition) {\r\n /**\r\n * @type {boolean} Boolean value that shows whether maxLength has been reached\r\n */\r\n this.maxLengthReached = true;\r\n return true;\r\n } else {\r\n this.maxLengthReached = false;\r\n return false;\r\n }\r\n }\r\n\r\n if (typeof maxLength === \"object\") {\r\n let condition = currentInput.length === maxLength[options.inputName];\r\n\r\n if (options.debug) {\r\n console.log(\"maxLength (obj) reached:\", condition);\r\n }\r\n\r\n if (condition) {\r\n this.maxLengthReached = true;\r\n return true;\r\n } else {\r\n this.maxLengthReached = false;\r\n return false;\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Gets the current value of maxLengthReached\r\n */\r\n isMaxLengthReached() {\r\n return Boolean(this.maxLengthReached);\r\n }\r\n\r\n /**\r\n * Determines whether a touch device is being used\r\n */\r\n isTouchDevice() {\r\n return \"ontouchstart\" in window || navigator.maxTouchPoints;\r\n }\r\n\r\n /**\r\n * Determines whether pointer events are supported\r\n */\r\n pointerEventsSupported() {\r\n return window.PointerEvent;\r\n }\r\n\r\n /**\r\n * Bind all methods in a given class\r\n */\r\n\r\n static bindMethods(myClass, instance) {\r\n for (let myMethod of Object.getOwnPropertyNames(myClass.prototype)) {\r\n let excludeMethod =\r\n myMethod === \"constructor\" || myMethod === \"bindMethods\";\r\n if (!excludeMethod) {\r\n instance[myMethod] = instance[myMethod].bind(instance);\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Transforms an arbitrary string to camelCase\r\n *\r\n * @param {string} string The string to transform.\r\n */\r\n camelCase(string) {\r\n return string\r\n .toLowerCase()\r\n .trim()\r\n .split(/[.\\-_\\s]/g)\r\n .reduce((string, word) =>\r\n word.length ? string + word[0].toUpperCase() + word.slice(1) : string\r\n );\r\n }\r\n\r\n /**\r\n * Counts the number of duplicates in a given array\r\n *\r\n * @param {Array} array The haystack to search in\r\n * @param {string} value The needle to search for\r\n */\r\n countInArray(array, value) {\r\n return array.reduce((n, x) => n + (x === value), 0);\r\n }\r\n}\r\n\r\nexport default Utilities;\r\n","import \"./Keyboard.css\";\r\n\r\n// Services\r\nimport PhysicalKeyboard from \"../services/PhysicalKeyboard\";\r\nimport KeyboardLayout from \"../services/KeyboardLayout\";\r\nimport Utilities from \"../services/Utilities\";\r\n\r\n/**\r\n * Root class for simple-keyboard\r\n * This class:\r\n * - Parses the options\r\n * - Renders the rows and buttons\r\n * - Handles button functionality\r\n */\r\nclass SimpleKeyboard {\r\n /**\r\n * Creates an instance of SimpleKeyboard\r\n * @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.\r\n */\r\n constructor(...params) {\r\n let keyboardDOMQuery =\r\n typeof params[0] === \"string\" ? params[0] : \".simple-keyboard\";\r\n let options = typeof params[0] === \"object\" ? params[0] : params[1];\r\n\r\n if (!options) options = {};\r\n\r\n /**\r\n * Initializing Utilities\r\n */\r\n this.utilities = new Utilities(this);\r\n\r\n /**\r\n * Processing options\r\n */\r\n this.keyboardDOM = document.querySelector(keyboardDOMQuery);\r\n\r\n /**\r\n * @type {object}\r\n * @property {object} layout Modify the keyboard layout.\r\n * @property {string} layoutName Specifies which layout should be used.\r\n * @property {object} display Replaces variable buttons (such as {bksp}) with a human-friendly name (e.g.: “backspace”).\r\n * @property {boolean} mergeDisplay By default, when you set the display property, you replace the default one. This setting merges them instead.\r\n * @property {string} theme A prop to add your own css classes to the keyboard wrapper. You can add multiple classes separated by a space.\r\n * @property {Array} buttonTheme A prop to add your own css classes to one or several buttons.\r\n * @property {boolean} debug Runs a console.log every time a key is pressed. Displays the buttons pressed and the current input.\r\n * @property {boolean} newLineOnEnter Specifies whether clicking the “ENTER” button will input a newline (\\n) or not.\r\n * @property {boolean} tabCharOnTab Specifies whether clicking the “TAB” button will input a tab character (\\t) or not.\r\n * @property {string} inputName Allows you to use a single simple-keyboard instance for several inputs.\r\n * @property {number} maxLength Restrains all of simple-keyboard inputs to a certain length. This should be used in addition to the input element’s maxlengthattribute.\r\n * @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.\r\n * @property {boolean} syncInstanceInputs When set to true, this option synchronizes the internal input of every simple-keyboard instance.\r\n * @property {boolean} physicalKeyboardHighlight Enable highlighting of keys pressed on physical keyboard.\r\n * @property {boolean} preventMouseDownDefault Calling preventDefault for the mousedown events keeps the focus on the input.\r\n * @property {string} physicalKeyboardHighlightTextColor Define the text color that the physical keyboard highlighted key should have.\r\n * @property {string} physicalKeyboardHighlightBgColor Define the background color that the physical keyboard highlighted key should have.\r\n * @property {function(button: string):string} onKeyPress Executes the callback function on key press. Returns button layout name (i.e.: “{shift}”).\r\n * @property {function(input: string):string} onChange Executes the callback function on input change. Returns the current input’s string.\r\n * @property {function} onRender Executes the callback function every time simple-keyboard is rendered (e.g: when you change layouts).\r\n * @property {function} onInit Executes the callback function once simple-keyboard is rendered for the first time (on initialization).\r\n * @property {function(inputs: object):object} onChangeAll Executes the callback function on input change. Returns the input object with all defined inputs.\r\n * @property {boolean} useButtonTag Render buttons as a button element instead of a div element.\r\n * @property {boolean} disableCaretPositioning A prop to ensure characters are always be added/removed at the end of the string.\r\n * @property {object} inputPattern Restrains input(s) change to the defined regular expression pattern.\r\n * @property {boolean} useTouchEvents Instructs simple-keyboard to use touch events instead of click events.\r\n * @property {boolean} autoUseTouchEvents Enable useTouchEvents automatically when touch device is detected.\r\n * @property {boolean} useMouseEvents Opt out of PointerEvents handling, falling back to the prior mouse event logic.\r\n * @property {function} destroy Clears keyboard listeners and DOM elements.\r\n * @property {boolean} disableButtonHold Disable button hold action.\r\n */\r\n this.options = options;\r\n this.options.layoutName = this.options.layoutName || \"default\";\r\n this.options.theme = this.options.theme || \"hg-theme-default\";\r\n this.options.inputName = this.options.inputName || \"default\";\r\n this.options.preventMouseDownDefault =\r\n this.options.preventMouseDownDefault || false;\r\n\r\n /**\r\n * @type {object} Classes identifying loaded plugins\r\n */\r\n this.keyboardPluginClasses = \"\";\r\n\r\n /**\r\n * Bindings\r\n */\r\n Utilities.bindMethods(SimpleKeyboard, this);\r\n\r\n /**\r\n * simple-keyboard uses a non-persistent internal input to keep track of the entered string (the variable `keyboard.input`).\r\n * This removes any dependency to input DOM elements. You can type and directly display the value in a div element, for example.\r\n * @example\r\n * // To get entered input\r\n * let input = keyboard.getInput();\r\n *\r\n * // To clear entered input.\r\n * keyboard.clearInput();\r\n *\r\n * @type {object}\r\n * @property {object} default Default SimpleKeyboard internal input.\r\n * @property {object} myInputName Example input that can be set through `options.inputName:\"myInputName\"`.\r\n */\r\n this.input = {};\r\n this.input[this.options.inputName] = \"\";\r\n\r\n /**\r\n * @type {string} DOM class of the keyboard wrapper, normally \"simple-keyboard\" by default.\r\n */\r\n this.keyboardDOMClass = keyboardDOMQuery.split(\".\").join(\"\");\r\n\r\n /**\r\n * @type {object} Contains the DOM elements of every rendered button, the key being the button's layout name (e.g.: \"{enter}\").\r\n */\r\n this.buttonElements = {};\r\n\r\n /**\r\n * Rendering keyboard\r\n */\r\n if (this.keyboardDOM) this.render();\r\n else {\r\n console.warn(`\"${keyboardDOMQuery}\" was not found in the DOM.`);\r\n throw new Error(\"KEYBOARD_DOM_ERROR\");\r\n }\r\n\r\n /**\r\n * Saving instance\r\n * This enables multiple simple-keyboard support with easier management\r\n */\r\n if (!window[\"SimpleKeyboardInstances\"])\r\n window[\"SimpleKeyboardInstances\"] = {};\r\n\r\n window[\"SimpleKeyboardInstances\"][\r\n this.utilities.camelCase(this.keyboardDOMClass)\r\n ] = this;\r\n\r\n /**\r\n * Physical Keyboard support\r\n */\r\n this.physicalKeyboardInterface = new PhysicalKeyboard(this);\r\n\r\n /**\r\n * Modules\r\n */\r\n this.modules = {};\r\n this.loadModules();\r\n }\r\n\r\n /**\r\n * Handles clicks made to keyboard buttons\r\n * @param {string} button The button's layout name.\r\n */\r\n handleButtonClicked(button) {\r\n let debug = this.options.debug;\r\n\r\n /**\r\n * Ignoring placeholder buttons\r\n */\r\n if (button === \"{//}\") return false;\r\n\r\n /**\r\n * Calling onKeyPress\r\n */\r\n if (typeof this.options.onKeyPress === \"function\")\r\n this.options.onKeyPress(button);\r\n\r\n if (!this.input[this.options.inputName])\r\n this.input[this.options.inputName] = \"\";\r\n\r\n let updatedInput = this.utilities.getUpdatedInput(\r\n button,\r\n this.input[this.options.inputName],\r\n this.options,\r\n this.caretPosition\r\n );\r\n\r\n if (\r\n // If input will change as a result of this button press\r\n this.input[this.options.inputName] !== updatedInput &&\r\n // This pertains to the \"inputPattern\" option:\r\n // If inputPattern isn't set\r\n (!this.options.inputPattern ||\r\n // Or, if it is set and if the pattern is valid - we proceed.\r\n (this.options.inputPattern && this.inputPatternIsValid(updatedInput)))\r\n ) {\r\n /**\r\n * If maxLength and handleMaxLength yield true, halting\r\n */\r\n if (\r\n this.options.maxLength &&\r\n this.utilities.handleMaxLength(this.input, this.options, updatedInput)\r\n ) {\r\n return false;\r\n }\r\n\r\n this.input[this.options.inputName] = this.utilities.getUpdatedInput(\r\n button,\r\n this.input[this.options.inputName],\r\n this.options,\r\n this.caretPosition,\r\n true\r\n );\r\n\r\n if (debug) console.log(\"Input changed:\", this.input);\r\n\r\n /**\r\n * Enforce syncInstanceInputs, if set\r\n */\r\n if (this.options.syncInstanceInputs) this.syncInstanceInputs(this.input);\r\n\r\n /**\r\n * Calling onChange\r\n */\r\n if (typeof this.options.onChange === \"function\")\r\n this.options.onChange(this.input[this.options.inputName]);\r\n\r\n /**\r\n * Calling onChangeAll\r\n */\r\n if (typeof this.options.onChangeAll === \"function\")\r\n this.options.onChangeAll(this.input);\r\n }\r\n\r\n if (debug) {\r\n console.log(\"Key pressed:\", button);\r\n }\r\n }\r\n\r\n /**\r\n * Handles button mousedown\r\n */\r\n /* istanbul ignore next */\r\n handleButtonMouseDown(button, e) {\r\n /**\r\n * Handle event options\r\n */\r\n if (this.options.preventMouseDownDefault) e.preventDefault();\r\n if (this.options.stopMouseDownPropagation) e.stopPropagation();\r\n\r\n /**\r\n * @type {boolean} Whether the mouse is being held onKeyPress\r\n */\r\n this.isMouseHold = true;\r\n\r\n if (this.holdInteractionTimeout) clearTimeout(this.holdInteractionTimeout);\r\n\r\n if (this.holdTimeout) clearTimeout(this.holdTimeout);\r\n\r\n /**\r\n * @type {object} Time to wait until a key hold is detected\r\n */\r\n if (!this.options.disableButtonHold) {\r\n this.holdTimeout = setTimeout(() => {\r\n if (\r\n this.isMouseHold &&\r\n ((!button.includes(\"{\") && !button.includes(\"}\")) ||\r\n button === \"{delete}\" ||\r\n button === \"{backspace}\" ||\r\n button === \"{bksp}\" ||\r\n button === \"{space}\" ||\r\n button === \"{tab}\")\r\n ) {\r\n if (this.options.debug) console.log(\"Button held:\", button);\r\n\r\n this.handleButtonHold(button, e);\r\n }\r\n clearTimeout(this.holdTimeout);\r\n }, 500);\r\n }\r\n }\r\n\r\n /**\r\n * Handles button mouseup\r\n */\r\n handleButtonMouseUp() {\r\n this.isMouseHold = false;\r\n if (this.holdInteractionTimeout) clearTimeout(this.holdInteractionTimeout);\r\n }\r\n\r\n /**\r\n * Handles button hold\r\n */\r\n /* istanbul ignore next */\r\n handleButtonHold(button) {\r\n if (this.holdInteractionTimeout) clearTimeout(this.holdInteractionTimeout);\r\n\r\n /**\r\n * @type {object} Timeout dictating the speed of key hold iterations\r\n */\r\n this.holdInteractionTimeout = setTimeout(() => {\r\n if (this.isMouseHold) {\r\n this.handleButtonClicked(button);\r\n this.handleButtonHold(button);\r\n } else {\r\n clearTimeout(this.holdInteractionTimeout);\r\n }\r\n }, 100);\r\n }\r\n\r\n /**\r\n * Send a command to all simple-keyboard instances (if you have several instances).\r\n */\r\n syncInstanceInputs() {\r\n this.dispatch(instance => {\r\n instance.replaceInput(this.input);\r\n instance.caretPosition = this.caretPosition;\r\n });\r\n }\r\n\r\n /**\r\n * Clear the keyboard’s input.\r\n * @param {string} [inputName] optional - the internal input to select\r\n */\r\n clearInput(inputName) {\r\n inputName = inputName || this.options.inputName;\r\n this.input[inputName] = \"\";\r\n\r\n /**\r\n * Reset caretPosition\r\n */\r\n this.caretPosition = 0;\r\n\r\n /**\r\n * Enforce syncInstanceInputs, if set\r\n */\r\n if (this.options.syncInstanceInputs) this.syncInstanceInputs(this.input);\r\n }\r\n\r\n /**\r\n * Get the keyboard’s input (You can also get it from the onChange prop).\r\n * @param {string} [inputName] optional - the internal input to select\r\n */\r\n getInput(inputName) {\r\n inputName = inputName || this.options.inputName;\r\n\r\n /**\r\n * Enforce syncInstanceInputs, if set\r\n */\r\n if (this.options.syncInstanceInputs) this.syncInstanceInputs(this.input);\r\n\r\n return this.input[inputName];\r\n }\r\n\r\n /**\r\n * Set the keyboard’s input.\r\n * @param {string} input the input value\r\n * @param {string} inputName optional - the internal input to select\r\n */\r\n setInput(input, inputName) {\r\n inputName = inputName || this.options.inputName;\r\n this.input[inputName] = input;\r\n\r\n /**\r\n * Enforce syncInstanceInputs, if set\r\n */\r\n if (this.options.syncInstanceInputs) this.syncInstanceInputs(this.input);\r\n }\r\n\r\n /**\r\n * Replace the input object (`keyboard.input`)\r\n * @param {object} inputObj The input object\r\n */\r\n replaceInput(inputObj) {\r\n this.input = inputObj;\r\n }\r\n\r\n /**\r\n * Set new option or modify existing ones after initialization.\r\n * @param {object} options The options to set\r\n */\r\n setOptions(options) {\r\n options = options || {};\r\n this.options = Object.assign(this.options, options);\r\n\r\n /**\r\n * Some option changes require adjustments before re-render\r\n */\r\n this.onSetOptions(options);\r\n\r\n /**\r\n * Rendering\r\n */\r\n this.render();\r\n }\r\n\r\n /**\r\n * Executing actions depending on changed options\r\n * @param {object} options The options to set\r\n */\r\n onSetOptions(options) {\r\n if (options.inputName) {\r\n /**\r\n * inputName changed. This requires a caretPosition reset\r\n */\r\n if (this.options.debug) {\r\n console.log(\"inputName changed. caretPosition reset.\");\r\n }\r\n\r\n this.caretPosition = null;\r\n }\r\n }\r\n\r\n /**\r\n * Remove all keyboard rows and reset keyboard values.\r\n * Used interally between re-renders.\r\n */\r\n clear() {\r\n this.keyboardDOM.innerHTML = \"\";\r\n this.keyboardDOM.className = this.keyboardDOMClass;\r\n this.buttonElements = {};\r\n }\r\n\r\n /**\r\n * Send a command to all simple-keyboard instances at once (if you have multiple instances).\r\n * @param {function(instance: object, key: string)} callback Function to run on every instance\r\n */\r\n dispatch(callback) {\r\n if (!window[\"SimpleKeyboardInstances\"]) {\r\n console.warn(\r\n `SimpleKeyboardInstances is not defined. Dispatch cannot be called.`\r\n );\r\n throw new Error(\"INSTANCES_VAR_ERROR\");\r\n }\r\n\r\n return Object.keys(window[\"SimpleKeyboardInstances\"]).forEach(key => {\r\n callback(window[\"SimpleKeyboardInstances\"][key], key);\r\n });\r\n }\r\n\r\n /**\r\n * Adds/Modifies an entry to the `buttonTheme`. Basically a way to add a class to a button.\r\n * @param {string} buttons List of buttons to select (separated by a space).\r\n * @param {string} className Classes to give to the selected buttons (separated by space).\r\n */\r\n addButtonTheme(buttons, className) {\r\n if (!className || !buttons) return false;\r\n\r\n buttons.split(\" \").forEach(button => {\r\n className.split(\" \").forEach(classNameItem => {\r\n if (!this.options.buttonTheme) this.options.buttonTheme = [];\r\n\r\n let classNameFound = false;\r\n\r\n /**\r\n * If class is already defined, we add button to class definition\r\n */\r\n this.options.buttonTheme.map(buttonTheme => {\r\n if (buttonTheme.class.split(\" \").includes(classNameItem)) {\r\n classNameFound = true;\r\n\r\n let buttonThemeArray = buttonTheme.buttons.split(\" \");\r\n if (!buttonThemeArray.includes(button)) {\r\n classNameFound = true;\r\n buttonThemeArray.push(button);\r\n buttonTheme.buttons = buttonThemeArray.join(\" \");\r\n }\r\n }\r\n return buttonTheme;\r\n });\r\n\r\n /**\r\n * If class is not defined, we create a new entry\r\n */\r\n if (!classNameFound) {\r\n this.options.buttonTheme.push({\r\n class: classNameItem,\r\n buttons: buttons\r\n });\r\n }\r\n });\r\n });\r\n\r\n this.render();\r\n }\r\n\r\n /**\r\n * Removes/Amends an entry to the `buttonTheme`. Basically a way to remove a class previously added to a button through buttonTheme or addButtonTheme.\r\n * @param {string} buttons List of buttons to select (separated by a space).\r\n * @param {string} className Classes to give to the selected buttons (separated by space).\r\n */\r\n removeButtonTheme(buttons, className) {\r\n /**\r\n * When called with empty parameters, remove all button themes\r\n */\r\n if (!buttons && !className) {\r\n this.options.buttonTheme = [];\r\n this.render();\r\n return false;\r\n }\r\n\r\n /**\r\n * If buttons are passed and buttonTheme has items\r\n */\r\n if (\r\n buttons &&\r\n Array.isArray(this.options.buttonTheme) &&\r\n this.options.buttonTheme.length\r\n ) {\r\n let buttonArray = buttons.split(\" \");\r\n buttonArray.forEach((button, key) => {\r\n this.options.buttonTheme.map((buttonTheme, index) => {\r\n /**\r\n * If className is set, we affect the buttons only for that class\r\n * Otherwise, we afect all classes\r\n */\r\n if (\r\n (className && className.includes(buttonTheme.class)) ||\r\n !className\r\n ) {\r\n let filteredButtonArray = buttonTheme.buttons\r\n .split(\" \")\r\n .filter(item => item !== button);\r\n\r\n /**\r\n * If buttons left, return them, otherwise, remove button Theme\r\n */\r\n if (filteredButtonArray.length) {\r\n buttonTheme.buttons = filteredButtonArray.join(\" \");\r\n } else {\r\n this.options.buttonTheme.splice(index, 1);\r\n buttonTheme = null;\r\n }\r\n }\r\n\r\n return buttonTheme;\r\n });\r\n });\r\n\r\n this.render();\r\n }\r\n }\r\n\r\n /**\r\n * Get the DOM Element of a button. If there are several buttons with the same name, an array of the DOM Elements is returned.\r\n * @param {string} button The button layout name to select\r\n */\r\n getButtonElement(button) {\r\n let output;\r\n\r\n let buttonArr = this.buttonElements[button];\r\n if (buttonArr) {\r\n if (buttonArr.length > 1) {\r\n output = buttonArr;\r\n } else {\r\n output = buttonArr[0];\r\n }\r\n }\r\n\r\n return output;\r\n }\r\n\r\n /**\r\n * This handles the \"inputPattern\" option\r\n * by checking if the provided inputPattern passes\r\n */\r\n inputPatternIsValid(inputVal) {\r\n let inputPatternRaw = this.options.inputPattern;\r\n let inputPattern;\r\n\r\n /**\r\n * Check if input pattern is global or targeted to individual inputs\r\n */\r\n if (inputPatternRaw instanceof RegExp) {\r\n inputPattern = inputPatternRaw;\r\n } else {\r\n inputPattern = inputPatternRaw[this.options.inputName];\r\n }\r\n\r\n if (inputPattern && inputVal) {\r\n let didInputMatch = inputPattern.test(inputVal);\r\n\r\n if (this.options.debug) {\r\n console.log(\r\n `inputPattern (\"${inputPattern}\"): ${\r\n didInputMatch ? \"passed\" : \"did not pass!\"\r\n }`\r\n );\r\n }\r\n\r\n return didInputMatch;\r\n } else {\r\n /**\r\n * inputPattern doesn't seem to be set for the current input, or input is empty. Pass.\r\n */\r\n return true;\r\n }\r\n }\r\n\r\n /**\r\n * Retrieves the current cursor position within a input or textarea (if any)\r\n */\r\n handleCaret() {\r\n /**\r\n * Only first instance should insall the caret handling events\r\n */\r\n this.caretPosition = null;\r\n let simpleKeyboardInstances = window[\"SimpleKeyboardInstances\"];\r\n\r\n if (\r\n (simpleKeyboardInstances &&\r\n Object.keys(simpleKeyboardInstances)[0] ===\r\n this.utilities.camelCase(this.keyboardDOMClass)) ||\r\n !simpleKeyboardInstances\r\n ) {\r\n if (this.options.debug) {\r\n console.log(`Caret handling started (${this.keyboardDOMClass})`);\r\n }\r\n\r\n document.addEventListener(\"keyup\", this.caretEventHandler);\r\n document.addEventListener(\"mouseup\", this.caretEventHandler);\r\n document.addEventListener(\"touchend\", this.caretEventHandler);\r\n }\r\n }\r\n\r\n /**\r\n * Called by {@link handleCaret} when an event that warrants a cursor position update is triggered\r\n */\r\n caretEventHandler(event) {\r\n let targetTagName;\r\n if (event.target.tagName) {\r\n targetTagName = event.target.tagName.toLowerCase();\r\n }\r\n\r\n this.dispatch(instance => {\r\n if (instance.isMouseHold) {\r\n instance.isMouseHold = false;\r\n }\r\n\r\n if (\r\n (targetTagName === \"textarea\" || targetTagName === \"input\") &&\r\n !instance.options.disableCaretPositioning\r\n ) {\r\n /**\r\n * Tracks current cursor position\r\n * As keys are pressed, text will be added/removed at that position within the input.\r\n */\r\n instance.caretPosition = event.target.selectionStart;\r\n\r\n if (instance.options.debug) {\r\n console.log(\r\n \"Caret at: \",\r\n event.target.selectionStart,\r\n event.target.tagName.toLowerCase(),\r\n `(${instance.keyboardDOMClass})`\r\n );\r\n }\r\n } else if (instance.options.disableCaretPositioning) {\r\n /**\r\n * If we toggled off disableCaretPositioning, we must ensure caretPosition doesn't persist once reactivated.\r\n */\r\n instance.caretPosition = null;\r\n }\r\n });\r\n }\r\n\r\n /**\r\n * Destroy keyboard listeners and DOM elements\r\n */\r\n destroy() {\r\n /**\r\n * Remove listeners\r\n */\r\n document.removeEventListener(\"keyup\", this.caretEventHandler);\r\n document.removeEventListener(\"mouseup\", this.caretEventHandler);\r\n document.removeEventListener(\"touchend\", this.caretEventHandler);\r\n\r\n /**\r\n * Clear DOM\r\n */\r\n this.clear();\r\n }\r\n\r\n /**\r\n * Process buttonTheme option\r\n */\r\n getButtonTheme() {\r\n let buttonThemesParsed = {};\r\n\r\n this.options.buttonTheme.forEach(themeObj => {\r\n if (themeObj.buttons && themeObj.class) {\r\n let themeButtons;\r\n\r\n if (typeof themeObj.buttons === \"string\") {\r\n themeButtons = themeObj.buttons.split(\" \");\r\n }\r\n\r\n if (themeButtons) {\r\n themeButtons.forEach(themeButton => {\r\n let themeParsed = buttonThemesParsed[themeButton];\r\n\r\n // If the button has already been added\r\n if (themeParsed) {\r\n // Making sure we don't add duplicate classes, even when buttonTheme has duplicates\r\n if (\r\n !this.utilities.countInArray(\r\n themeParsed.split(\" \"),\r\n themeObj.class\r\n )\r\n ) {\r\n buttonThemesParsed[\r\n themeButton\r\n ] = `${themeParsed} ${themeObj.class}`;\r\n }\r\n } else {\r\n buttonThemesParsed[themeButton] = themeObj.class;\r\n }\r\n });\r\n }\r\n } else {\r\n console.warn(\r\n `buttonTheme row is missing the \"buttons\" or the \"class\". Please check the documentation.`\r\n );\r\n }\r\n });\r\n\r\n return buttonThemesParsed;\r\n }\r\n\r\n onTouchDeviceDetected() {\r\n /**\r\n * Processing autoTouchEvents\r\n */\r\n this.processAutoTouchEvents();\r\n\r\n /**\r\n * Disabling contextual window on touch devices\r\n */\r\n this.disableContextualWindow();\r\n }\r\n\r\n /**\r\n * Disabling contextual window for hg-button\r\n */\r\n /* istanbul ignore next */\r\n disableContextualWindow() {\r\n window.oncontextmenu = event => {\r\n if (event.target.classList.contains(\"hg-button\")) {\r\n event.preventDefault();\r\n event.stopPropagation();\r\n return false;\r\n }\r\n };\r\n }\r\n\r\n /**\r\n * Process autoTouchEvents option\r\n */\r\n processAutoTouchEvents() {\r\n if (this.options.autoUseTouchEvents) {\r\n this.options.useTouchEvents = true;\r\n\r\n if (this.options.debug) {\r\n console.log(\r\n `autoUseTouchEvents: Touch device detected, useTouchEvents enabled.`\r\n );\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Executes the callback function once simple-keyboard is rendered for the first time (on initialization).\r\n */\r\n onInit() {\r\n if (this.options.debug) {\r\n console.log(`${this.keyboardDOMClass} Initialized`);\r\n }\r\n\r\n /**\r\n * Caret handling\r\n */\r\n this.handleCaret();\r\n\r\n if (typeof this.options.onInit === \"function\") this.options.onInit();\r\n }\r\n\r\n /**\r\n * Executes the callback function before a simple-keyboard render.\r\n */\r\n beforeFirstRender() {\r\n /**\r\n * Performing actions when touch device detected\r\n */\r\n if (this.utilities.isTouchDevice()) {\r\n this.onTouchDeviceDetected();\r\n }\r\n\r\n if (typeof this.options.beforeFirstRender === \"function\")\r\n this.options.beforeFirstRender();\r\n\r\n /**\r\n * Notify about PointerEvents usage\r\n */\r\n if (\r\n this.utilities.pointerEventsSupported() &&\r\n !this.options.useTouchEvents &&\r\n !this.options.useMouseEvents\r\n ) {\r\n if (this.options.debug) {\r\n console.log(\"Using PointerEvents as it is supported by this browser\");\r\n }\r\n }\r\n\r\n /**\r\n * Notify about touch events usage\r\n */\r\n if (this.options.useTouchEvents) {\r\n if (this.options.debug) {\r\n console.log(\r\n \"useTouchEvents has been enabled. Only touch events will be used.\"\r\n );\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Executes the callback function before a simple-keyboard render.\r\n */\r\n beforeRender() {\r\n if (typeof this.options.beforeRender === \"function\")\r\n this.options.beforeRender();\r\n }\r\n\r\n /**\r\n * Executes the callback function every time simple-keyboard is rendered (e.g: when you change layouts).\r\n */\r\n onRender() {\r\n if (typeof this.options.onRender === \"function\") this.options.onRender();\r\n }\r\n\r\n /**\r\n * Executes the callback function once all modules have been loaded\r\n */\r\n onModulesLoaded() {\r\n if (typeof this.options.onModulesLoaded === \"function\")\r\n this.options.onModulesLoaded();\r\n }\r\n\r\n /**\r\n * Register module\r\n */\r\n registerModule = (name, initCallback) => {\r\n if (!this.modules[name]) this.modules[name] = {};\r\n\r\n initCallback(this.modules[name]);\r\n };\r\n\r\n /**\r\n * Load modules\r\n */\r\n loadModules() {\r\n if (Array.isArray(this.options.modules)) {\r\n this.options.modules.forEach(Module => {\r\n let module = new Module();\r\n\r\n /* istanbul ignore next */\r\n if (module.constructor.name && module.constructor.name !== \"Function\") {\r\n let classStr = `module-${this.utilities.camelCase(\r\n module.constructor.name\r\n )}`;\r\n this.keyboardPluginClasses =\r\n this.keyboardPluginClasses + ` ${classStr}`;\r\n }\r\n\r\n module.init(this);\r\n });\r\n\r\n this.keyboardPluginClasses =\r\n this.keyboardPluginClasses + \" modules-loaded\";\r\n\r\n this.render();\r\n this.onModulesLoaded();\r\n }\r\n }\r\n\r\n /**\r\n * Get module prop\r\n */\r\n getModuleProp(name, prop) {\r\n if (!this.modules[name]) return false;\r\n\r\n return this.modules[name][prop];\r\n }\r\n\r\n /**\r\n * getModulesList\r\n */\r\n getModulesList() {\r\n return Object.keys(this.modules);\r\n }\r\n\r\n /**\r\n * Parse Row DOM containers\r\n */\r\n parseRowDOMContainers(\r\n rowDOM,\r\n rowIndex,\r\n containerStartIndexes,\r\n containerEndIndexes\r\n ) {\r\n let rowDOMArray = Array.from(rowDOM.children);\r\n let removedElements = 0;\r\n\r\n if (rowDOMArray.length) {\r\n containerStartIndexes.forEach((startIndex, arrIndex) => {\r\n let endIndex = containerEndIndexes[arrIndex];\r\n\r\n /**\r\n * If there exists a respective end index\r\n * if end index comes after start index\r\n */\r\n if (!endIndex || !(endIndex > startIndex)) {\r\n return false;\r\n }\r\n\r\n /**\r\n * Updated startIndex, endIndex\r\n * This is since the removal of buttons to place a single button container\r\n * results in a modified array size\r\n */\r\n let updated_startIndex = startIndex - removedElements;\r\n let updated_endIndex = endIndex - removedElements;\r\n\r\n /**\r\n * Create button container\r\n */\r\n let containerDOM = document.createElement(\"div\");\r\n containerDOM.className += \"hg-button-container\";\r\n let containerUID = `${this.options.layoutName}-r${rowIndex}c${arrIndex}`;\r\n containerDOM.setAttribute(\"data-skUID\", containerUID);\r\n\r\n /**\r\n * Taking elements due to be inserted into container\r\n */\r\n let containedElements = rowDOMArray.splice(\r\n updated_startIndex,\r\n updated_endIndex - updated_startIndex + 1\r\n );\r\n removedElements = updated_endIndex - updated_startIndex;\r\n\r\n /**\r\n * Inserting elements to container\r\n */\r\n containedElements.forEach(element => containerDOM.appendChild(element));\r\n\r\n /**\r\n * Adding container at correct position within rowDOMArray\r\n */\r\n rowDOMArray.splice(updated_startIndex, 0, containerDOM);\r\n\r\n /**\r\n * Clearing old rowDOM children structure\r\n */\r\n rowDOM.innerHTML = \"\";\r\n\r\n /**\r\n * Appending rowDOM new children list\r\n */\r\n rowDOMArray.forEach(element => rowDOM.appendChild(element));\r\n\r\n if (this.options.debug) {\r\n console.log(\r\n \"rowDOMContainer\",\r\n containedElements,\r\n updated_startIndex,\r\n updated_endIndex,\r\n removedElements + 1\r\n );\r\n }\r\n });\r\n }\r\n\r\n return rowDOM;\r\n }\r\n\r\n /**\r\n * Renders rows and buttons as per options\r\n */\r\n render() {\r\n /**\r\n * Clear keyboard\r\n */\r\n this.clear();\r\n\r\n /**\r\n * Calling beforeFirstRender\r\n */\r\n if (!this.initialized) {\r\n this.beforeFirstRender();\r\n }\r\n\r\n /**\r\n * Calling beforeRender\r\n */\r\n this.beforeRender();\r\n\r\n let layoutClass = `hg-layout-${this.options.layoutName}`;\r\n let layout = this.options.layout || KeyboardLayout.getDefaultLayout();\r\n let useTouchEvents = this.options.useTouchEvents || false;\r\n let useTouchEventsClass = useTouchEvents ? \"hg-touch-events\" : \"\";\r\n let useMouseEvents = this.options.useMouseEvents || false;\r\n let disableRowButtonContainers = this.options.disableRowButtonContainers;\r\n\r\n /**\r\n * Account for buttonTheme, if set\r\n */\r\n let buttonThemesParsed = Array.isArray(this.options.buttonTheme)\r\n ? this.getButtonTheme()\r\n : {};\r\n\r\n /**\r\n * Adding themeClass, layoutClass to keyboardDOM\r\n */\r\n this.keyboardDOM.className += ` ${this.options.theme} ${layoutClass} ${this.keyboardPluginClasses} ${useTouchEventsClass}`;\r\n\r\n /**\r\n * Iterating through each row\r\n */\r\n layout[this.options.layoutName].forEach((row, rIndex) => {\r\n let rowArray = row.split(\" \");\r\n\r\n /**\r\n * Creating empty row\r\n */\r\n let rowDOM = document.createElement(\"div\");\r\n rowDOM.className += \"hg-row\";\r\n\r\n /**\r\n * Tracking container indicators in rows\r\n */\r\n let containerStartIndexes = [];\r\n let containerEndIndexes = [];\r\n\r\n /**\r\n * Iterating through each button in row\r\n */\r\n rowArray.forEach((button, bIndex) => {\r\n /**\r\n * Check if button has a container indicator\r\n */\r\n let buttonHasContainerStart =\r\n !disableRowButtonContainers &&\r\n button.includes(\"[\") &&\r\n button.length > 1;\r\n let buttonHasContainerEnd =\r\n !disableRowButtonContainers &&\r\n button.includes(\"]\") &&\r\n button.length > 1;\r\n\r\n /**\r\n * Save container start index, if applicable\r\n */\r\n if (buttonHasContainerStart) {\r\n containerStartIndexes.push(bIndex);\r\n\r\n /**\r\n * Removing indicator\r\n */\r\n button = button.replace(/\\[/g, \"\");\r\n }\r\n\r\n if (buttonHasContainerEnd) {\r\n containerEndIndexes.push(bIndex);\r\n\r\n /**\r\n * Removing indicator\r\n */\r\n button = button.replace(/\\]/g, \"\");\r\n }\r\n\r\n /**\r\n * Processing button options\r\n */\r\n let fctBtnClass = this.utilities.getButtonClass(button);\r\n let buttonThemeClass = buttonThemesParsed[button];\r\n let buttonDisplayName = this.utilities.getButtonDisplayName(\r\n button,\r\n this.options.display,\r\n this.options.mergeDisplay\r\n );\r\n\r\n /**\r\n * Creating button\r\n */\r\n let buttonType = this.options.useButtonTag ? \"button\" : \"div\";\r\n let buttonDOM = document.createElement(buttonType);\r\n buttonDOM.className += `hg-button ${fctBtnClass}${\r\n buttonThemeClass ? \" \" + buttonThemeClass : \"\"\r\n }`;\r\n\r\n /**\r\n * Handle button click event\r\n */\r\n /* istanbul ignore next */\r\n if (\r\n this.utilities.pointerEventsSupported() &&\r\n !useTouchEvents &&\r\n !useMouseEvents\r\n ) {\r\n /**\r\n * Handle PointerEvents\r\n */\r\n buttonDOM.onpointerdown = e => {\r\n this.handleButtonClicked(button);\r\n this.handleButtonMouseDown(button, e);\r\n };\r\n buttonDOM.onpointerup = e => {\r\n this.handleButtonMouseUp();\r\n };\r\n buttonDOM.onpointercancel = e => this.handleButtonMouseUp();\r\n } else {\r\n /**\r\n * Fallback for browsers not supporting PointerEvents\r\n */\r\n if (useTouchEvents) {\r\n /**\r\n * Handle touch events\r\n */\r\n buttonDOM.ontouchstart = e => {\r\n this.handleButtonClicked(button);\r\n this.handleButtonMouseDown(button, e);\r\n };\r\n buttonDOM.ontouchend = e => this.handleButtonMouseUp();\r\n buttonDOM.ontouchcancel = e => this.handleButtonMouseUp();\r\n } else {\r\n /**\r\n * Handle mouse events\r\n */\r\n buttonDOM.onclick = () => {\r\n this.isMouseHold = false;\r\n this.handleButtonClicked(button);\r\n };\r\n buttonDOM.onmousedown = e => {\r\n this.handleButtonMouseDown(button, e);\r\n };\r\n }\r\n }\r\n\r\n /**\r\n * Adding identifier\r\n */\r\n buttonDOM.setAttribute(\"data-skBtn\", button);\r\n\r\n /**\r\n * Adding unique id\r\n * Since there's no limit on spawning same buttons, the unique id ensures you can style every button\r\n */\r\n let buttonUID = `${this.options.layoutName}-r${rIndex}b${bIndex}`;\r\n buttonDOM.setAttribute(\"data-skBtnUID\", buttonUID);\r\n\r\n /**\r\n * Adding display label\r\n */\r\n buttonDOM.setAttribute(\"data-displayLabel\", buttonDisplayName);\r\n\r\n /**\r\n * Adding button label to button\r\n */\r\n let buttonSpanDOM = document.createElement(\"span\");\r\n buttonSpanDOM.innerHTML = buttonDisplayName;\r\n buttonDOM.appendChild(buttonSpanDOM);\r\n\r\n /**\r\n * Adding to buttonElements\r\n */\r\n if (!this.buttonElements[button]) this.buttonElements[button] = [];\r\n\r\n this.buttonElements[button].push(buttonDOM);\r\n\r\n /**\r\n * Appending button to row\r\n */\r\n rowDOM.appendChild(buttonDOM);\r\n });\r\n\r\n /**\r\n * Parse containers in row\r\n */\r\n rowDOM = this.parseRowDOMContainers(\r\n rowDOM,\r\n rIndex,\r\n containerStartIndexes,\r\n containerEndIndexes\r\n );\r\n\r\n /**\r\n * Appending row to keyboard\r\n */\r\n this.keyboardDOM.appendChild(rowDOM);\r\n });\r\n\r\n /**\r\n * Calling onRender\r\n */\r\n this.onRender();\r\n\r\n if (!this.initialized) {\r\n /**\r\n * Ensures that onInit and beforeFirstRender are only called once per instantiation\r\n */\r\n this.initialized = true;\r\n\r\n /**\r\n * Handling onpointerup\r\n */\r\n /* istanbul ignore next */\r\n if (\r\n this.utilities.pointerEventsSupported() &&\r\n !useTouchEvents &&\r\n !useMouseEvents\r\n ) {\r\n document.onpointerup = () => this.handleButtonMouseUp();\r\n } else if (useTouchEvents) {\r\n /**\r\n * Handling ontouchend, ontouchcancel\r\n */\r\n document.ontouchend = e => this.handleButtonMouseUp();\r\n document.ontouchcancel = e => this.handleButtonMouseUp();\r\n } else if (!useTouchEvents) {\r\n /**\r\n * Handling mouseup\r\n */\r\n document.onmouseup = () => this.handleButtonMouseUp();\r\n }\r\n\r\n /**\r\n * Calling onInit\r\n */\r\n this.onInit();\r\n }\r\n }\r\n}\r\n\r\nexport default SimpleKeyboard;\r\n","import SimpleKeyboard from \"./components/Keyboard\";\r\nexport default SimpleKeyboard;\r\n"],"sourceRoot":""} \ No newline at end of file +{"version":3,"sources":["../../webpack/universalModuleDefinition","../../webpack/bootstrap","services/Utilities.js","services/PhysicalKeyboard.js","services/KeyboardLayout.js","components/Keyboard.js","index.js"],"names":["root","factory","exports","module","define","amd","window","installedModules","__webpack_require__","moduleId","i","l","modules","call","m","c","d","name","getter","o","Object","defineProperty","enumerable","get","r","Symbol","toStringTag","value","t","mode","__esModule","ns","create","key","bind","n","object","property","prototype","hasOwnProperty","p","s","Utilities","_ref","getOptions","getCaretPosition","dispatch","_classCallCheck","this","bindMethods","myClass","instance","_iteratorNormalCompletion","_didIteratorError","_iteratorError","undefined","_step","_iterator","getOwnPropertyNames","iterator","next","done","myMethod","err","return","button","buttonTypeClass","includes","buttonWithoutBraces","replace","buttonNormalized","concat","{bksp}","{backspace}","{enter}","{shift}","{shiftleft}","{shiftright}","{alt}","{s}","{tab}","{lock}","{capslock}","{accept}","{space}","{//}","{esc}","{escape}","{f1}","{f2}","{f3}","{f4}","{f5}","{f6}","{f7}","{f8}","{f9}","{f10}","{f11}","{f12}","{numpaddivide}","{numlock}","{arrowup}","{arrowleft}","{arrowdown}","{arrowright}","{prtscr}","{scrolllock}","{pause}","{insert}","{home}","{pageup}","{delete}","{end}","{pagedown}","{numpadmultiply}","{numpadsubtract}","{numpadadd}","{numpadenter}","{period}","{numpaddecimal}","{numpad0}","{numpad1}","{numpad2}","{numpad3}","{numpad4}","{numpad5}","{numpad6}","{numpad7}","{numpad8}","{numpad9}","display","mergeDisplay","assign","getDefaultDiplay","input","caretPos","moveCaret","options","output","length","removeAt","addStringAt","tabCharOnTab","newLineOnEnter","Number","isInteger","minus","newCaretPos","updateCaretPosAction","caretPosition","debug","console","log","keyboardDOMClass","source","string","position","slice","join","isMaxLengthReached","updateCaretPos","emojiMatchedReg","substring","match","substr","inputObj","updatedInput","maxLength","currentInput","inputName","condition","maxLengthReached","_typeof","Boolean","navigator","maxTouchPoints","PointerEvent","toLowerCase","trim","split","reduce","word","toUpperCase","array","x","PhysicalKeyboard","PhysicalKeyboard_classCallCheck","event","buttonPressed","getSimpleKeyboardLayoutKey","buttonDOM","getButtonElement","style","backgroundColor","physicalKeyboardHighlightBgColor","color","physicalKeyboardHighlightTextColor","removeAttribute","code","KeyboardLayout","default","shift","SimpleKeyboard","_this","Keyboard_classCallCheck","registerModule","initCallback","keyboardDOMQuery","arguments","Keyboard_typeof","utilities","keyboardDOM","document","querySelector","layoutName","theme","preventMouseDownDefault","keyboardPluginClasses","buttonElements","camelCase","allKeyboardInstances","currentInstanceName","keyboardInstanceNames","keys","isFirstKeyboardInstance","physicalKeyboard","warn","Error","render","loadModules","onKeyPress","getUpdatedInput","inputPattern","inputPatternIsValid","handleMaxLength","syncInstanceInputs","onChange","onChangeAll","e","_this2","preventDefault","stopMouseDownPropagation","stopPropagation","isMouseHold","holdInteractionTimeout","clearTimeout","holdTimeout","disableButtonHold","setTimeout","handleButtonHold","onKeyReleased","_this3","handleButtonClicked","_this4","replaceInput","onSetOptions","innerHTML","className","callback","forEach","buttons","_this5","classNameItem","buttonTheme","classNameFound","map","class","buttonThemeArray","push","_this6","Array","isArray","index","filteredButtonArray","filter","item","splice","buttonArr","inputVal","inputPatternRaw","RegExp","didInputMatch","test","addEventListener","handleKeyUp","handleKeyDown","handleMouseUp","handleTouchEnd","caretEventHandler","physicalKeyboardHighlight","handleHighlightKeyUp","handleHighlightKeyDown","targetTagName","target","tagName","disableCaretPositioning","selectionStart","removeEventListener","clear","_this7","buttonThemesParsed","themeObj","themeButtons","themeButton","themeParsed","countInArray","processAutoTouchEvents","disableContextualWindow","oncontextmenu","classList","contains","autoUseTouchEvents","useTouchEvents","setEventListeners","onInit","isTouchDevice","onTouchDeviceDetected","beforeFirstRender","pointerEventsSupported","useMouseEvents","beforeRender","onRender","onModulesLoaded","_this8","Module","constructor","classStr","init","prop","rowDOM","rowIndex","containerStartIndexes","containerEndIndexes","_this9","rowDOMArray","from","children","removedElements","startIndex","arrIndex","endIndex","updated_startIndex","updated_endIndex","containerDOM","createElement","containerUID","setAttribute","containedElements","element","appendChild","_this10","initialized","layoutClass","layout","getDefaultLayout","useTouchEventsClass","disableRowButtonContainers","getButtonTheme","row","rIndex","rowArray","bIndex","buttonHasContainerStart","buttonHasContainerEnd","fctBtnClass","getButtonClass","buttonThemeClass","buttonDisplayName","getButtonDisplayName","buttonType","useButtonTag","ontouchstart","handleButtonMouseDown","ontouchend","handleButtonMouseUp","ontouchcancel","onclick","onmousedown","onpointerdown","onpointerup","onpointercancel","buttonUID","buttonSpanDOM","parseRowDOMContainers","onmouseup"],"mappings":";;;;;;;;;;;CAAA,SAAAA,EAAAC,GACA,kBAAAC,SAAA,kBAAAC,OACAA,OAAAD,QAAAD,IACA,oBAAAG,eAAAC,IACAD,OAAA,oBAAAH,GACA,kBAAAC,QACAA,QAAA,eAAAD,IAEAD,EAAA,eAAAC,IARA,CASCK,OAAA,WACD,mBCTA,IAAAC,EAAA,GAGA,SAAAC,EAAAC,GAGA,GAAAF,EAAAE,GACA,OAAAF,EAAAE,GAAAP,QAGA,IAAAC,EAAAI,EAAAE,GAAA,CACAC,EAAAD,EACAE,GAAA,EACAT,QAAA,IAUA,OANAU,EAAAH,GAAAI,KAAAV,EAAAD,QAAAC,IAAAD,QAAAM,GAGAL,EAAAQ,GAAA,EAGAR,EAAAD,QA0DA,OArDAM,EAAAM,EAAAF,EAGAJ,EAAAO,EAAAR,EAGAC,EAAAQ,EAAA,SAAAd,EAAAe,EAAAC,GACAV,EAAA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9I,GAAC,OAAIgH,EAAKwB,wBAgCxCxL,EAAU4J,aAAa,aAAc1R,GAMrC,IAAI6T,EAAS,GAAAvT,OAAMwR,EAAKrN,QAAQ6E,WAAnB,MAAAhJ,OAAkCiS,EAAlC,KAAAjS,OAA4CmS,GACzD3K,EAAU4J,aAAa,gBAAiBmC,GAKxC/L,EAAU4J,aAAa,oBAAqBqB,GAK5C,IAAIe,EAAgB1K,SAASoI,cAAc,QAC3CsC,EAAc9H,UAAY+G,EAC1BjL,EAAU+J,YAAYiC,GAKjBhC,EAAKpI,eAAe1J,KAAS8R,EAAKpI,eAAe1J,GAAU,IAEhE8R,EAAKpI,eAAe1J,GAAQ4M,KAAK9E,GAKjC2I,EAAOoB,YAAY/J,KAMrB2I,EAASqB,EAAKiC,sBACZtD,EACA8B,EACA5B,EACAC,GAMFkB,EAAK3I,YAAY0I,YAAYpB,KAM/B1R,KAAKkR,WAEAlR,KAAKgT,cAIRhT,KAAKgT,aAAc,GAOjBhT,KAAKmK,UAAU4G,0BACdN,GACAO,EAGQP,GAITpG,SAASiK,WAAa,SAAAvI,GAAC,OAAIgH,EAAKwB,uBAChClK,SAASmK,cAAgB,SAAAzI,GAAC,OAAIgH,EAAKwB,wBACzB9D,IAIVpG,SAAS4K,UAAY,kBAAMlC,EAAKwB,wBAXhClK,SAASuK,YAAc,kBAAM7B,EAAKwB,uBAiBpCvU,KAAK2Q,+CC3wCIhH","file":"index.js","sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine(\"SimpleKeyboard\", [], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"SimpleKeyboard\"] = factory();\n\telse\n\t\troot[\"SimpleKeyboard\"] = factory();\n})(window, function() {\nreturn "," \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId]) {\n \t\t\treturn installedModules[moduleId].exports;\n \t\t}\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.l = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// define getter function for harmony exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tif(!__webpack_require__.o(exports, name)) {\n \t\t\tObject.defineProperty(exports, name, { enumerable: true, get: getter });\n \t\t}\n \t};\n\n \t// define __esModule on exports\n \t__webpack_require__.r = function(exports) {\n \t\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n \t\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n \t\t}\n \t\tObject.defineProperty(exports, '__esModule', { value: true });\n \t};\n\n \t// create a fake namespace object\n \t// mode & 1: value is a module id, require it\n \t// mode & 2: merge all properties of value into the ns\n \t// mode & 4: return value when already ns object\n \t// mode & 8|1: behave like require\n \t__webpack_require__.t = function(value, mode) {\n \t\tif(mode & 1) value = __webpack_require__(value);\n \t\tif(mode & 8) return value;\n \t\tif((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;\n \t\tvar ns = Object.create(null);\n \t\t__webpack_require__.r(ns);\n \t\tObject.defineProperty(ns, 'default', { enumerable: true, value: value });\n \t\tif(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));\n \t\treturn ns;\n \t};\n\n \t// getDefaultExport function for compatibility with non-harmony modules\n \t__webpack_require__.n = function(module) {\n \t\tvar getter = module && module.__esModule ?\n \t\t\tfunction getDefault() { return module['default']; } :\n \t\t\tfunction getModuleExports() { return module; };\n \t\t__webpack_require__.d(getter, 'a', getter);\n \t\treturn getter;\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = 0);\n","/**\r\n * Utility Service\r\n */\r\nclass Utilities {\r\n /**\r\n * Creates an instance of the Utility service\r\n */\r\n constructor({ getOptions, getCaretPosition, dispatch }) {\r\n this.getOptions = getOptions;\r\n this.getCaretPosition = getCaretPosition;\r\n this.dispatch = dispatch;\r\n\r\n /**\r\n * Bindings\r\n */\r\n Utilities.bindMethods(Utilities, this);\r\n }\r\n\r\n /**\r\n * Adds default classes to a given button\r\n *\r\n * @param {string} button The button's layout name\r\n * @return {string} The classes to be added to the button\r\n */\r\n getButtonClass(button) {\r\n let buttonTypeClass =\r\n button.includes(\"{\") && button.includes(\"}\") && button !== \"{//}\"\r\n ? \"functionBtn\"\r\n : \"standardBtn\";\r\n let buttonWithoutBraces = button.replace(\"{\", \"\").replace(\"}\", \"\");\r\n let buttonNormalized = \"\";\r\n\r\n if (buttonTypeClass !== \"standardBtn\")\r\n buttonNormalized = ` hg-button-${buttonWithoutBraces}`;\r\n\r\n return `hg-${buttonTypeClass}${buttonNormalized}`;\r\n }\r\n\r\n /**\r\n * Default button display labels\r\n */\r\n getDefaultDiplay() {\r\n return {\r\n \"{bksp}\": \"backspace\",\r\n \"{backspace}\": \"backspace\",\r\n \"{enter}\": \"< enter\",\r\n \"{shift}\": \"shift\",\r\n \"{shiftleft}\": \"shift\",\r\n \"{shiftright}\": \"shift\",\r\n \"{alt}\": \"alt\",\r\n \"{s}\": \"shift\",\r\n \"{tab}\": \"tab\",\r\n \"{lock}\": \"caps\",\r\n \"{capslock}\": \"caps\",\r\n \"{accept}\": \"Submit\",\r\n \"{space}\": \" \",\r\n \"{//}\": \" \",\r\n \"{esc}\": \"esc\",\r\n \"{escape}\": \"esc\",\r\n \"{f1}\": \"f1\",\r\n \"{f2}\": \"f2\",\r\n \"{f3}\": \"f3\",\r\n \"{f4}\": \"f4\",\r\n \"{f5}\": \"f5\",\r\n \"{f6}\": \"f6\",\r\n \"{f7}\": \"f7\",\r\n \"{f8}\": \"f8\",\r\n \"{f9}\": \"f9\",\r\n \"{f10}\": \"f10\",\r\n \"{f11}\": \"f11\",\r\n \"{f12}\": \"f12\",\r\n \"{numpaddivide}\": \"/\",\r\n \"{numlock}\": \"lock\",\r\n \"{arrowup}\": \"↑\",\r\n \"{arrowleft}\": \"←\",\r\n \"{arrowdown}\": \"↓\",\r\n \"{arrowright}\": \"→\",\r\n \"{prtscr}\": \"print\",\r\n \"{scrolllock}\": \"scroll\",\r\n \"{pause}\": \"pause\",\r\n \"{insert}\": \"ins\",\r\n \"{home}\": \"home\",\r\n \"{pageup}\": \"up\",\r\n \"{delete}\": \"del\",\r\n \"{end}\": \"end\",\r\n \"{pagedown}\": \"down\",\r\n \"{numpadmultiply}\": \"*\",\r\n \"{numpadsubtract}\": \"-\",\r\n \"{numpadadd}\": \"+\",\r\n \"{numpadenter}\": \"enter\",\r\n \"{period}\": \".\",\r\n \"{numpaddecimal}\": \".\",\r\n \"{numpad0}\": \"0\",\r\n \"{numpad1}\": \"1\",\r\n \"{numpad2}\": \"2\",\r\n \"{numpad3}\": \"3\",\r\n \"{numpad4}\": \"4\",\r\n \"{numpad5}\": \"5\",\r\n \"{numpad6}\": \"6\",\r\n \"{numpad7}\": \"7\",\r\n \"{numpad8}\": \"8\",\r\n \"{numpad9}\": \"9\"\r\n };\r\n }\r\n /**\r\n * Returns the display (label) name for a given button\r\n *\r\n * @param {string} button The button's layout name\r\n * @param {object} display The provided display option\r\n * @param {boolean} mergeDisplay Whether the provided param value should be merged with the default one.\r\n */\r\n getButtonDisplayName(button, display, mergeDisplay) {\r\n if (mergeDisplay) {\r\n display = Object.assign({}, this.getDefaultDiplay(), display);\r\n } else {\r\n display = display || this.getDefaultDiplay();\r\n }\r\n\r\n return display[button] || button;\r\n }\r\n\r\n /**\r\n * Returns the updated input resulting from clicking a given button\r\n *\r\n * @param {string} button The button's layout name\r\n * @param {string} input The input string\r\n * @param {number} caretPos The cursor's current position\r\n * @param {boolean} moveCaret Whether to update simple-keyboard's cursor\r\n */\r\n getUpdatedInput(button, input, caretPos, moveCaret) {\r\n let options = this.getOptions();\r\n let output = input;\r\n\r\n if (\r\n (button === \"{bksp}\" || button === \"{backspace}\") &&\r\n output.length > 0\r\n ) {\r\n output = this.removeAt(output, caretPos, moveCaret);\r\n } else if (button === \"{space}\")\r\n output = this.addStringAt(output, \" \", caretPos, moveCaret);\r\n else if (\r\n button === \"{tab}\" &&\r\n !(\r\n typeof options.tabCharOnTab === \"boolean\" &&\r\n options.tabCharOnTab === false\r\n )\r\n ) {\r\n output = this.addStringAt(output, \"\\t\", caretPos, moveCaret);\r\n } else if (\r\n (button === \"{enter}\" || button === \"{numpadenter}\") &&\r\n options.newLineOnEnter\r\n )\r\n output = this.addStringAt(output, \"\\n\", caretPos, moveCaret);\r\n else if (\r\n button.includes(\"numpad\") &&\r\n Number.isInteger(Number(button[button.length - 2]))\r\n ) {\r\n output = this.addStringAt(\r\n output,\r\n button[button.length - 2],\r\n caretPos,\r\n moveCaret\r\n );\r\n } else if (button === \"{numpaddivide}\")\r\n output = this.addStringAt(output, \"/\", caretPos, moveCaret);\r\n else if (button === \"{numpadmultiply}\")\r\n output = this.addStringAt(output, \"*\", caretPos, moveCaret);\r\n else if (button === \"{numpadsubtract}\")\r\n output = this.addStringAt(output, \"-\", caretPos, moveCaret);\r\n else if (button === \"{numpadadd}\")\r\n output = this.addStringAt(output, \"+\", caretPos, moveCaret);\r\n else if (button === \"{numpaddecimal}\")\r\n output = this.addStringAt(output, \".\", caretPos, moveCaret);\r\n else if (button === \"{\" || button === \"}\")\r\n output = this.addStringAt(output, button, caretPos, moveCaret);\r\n else if (!button.includes(\"{\") && !button.includes(\"}\"))\r\n output = this.addStringAt(output, button, caretPos, moveCaret);\r\n\r\n return output;\r\n }\r\n\r\n /**\r\n * Moves the cursor position by a given amount\r\n *\r\n * @param {number} length Represents by how many characters the input should be moved\r\n * @param {boolean} minus Whether the cursor should be moved to the left or not.\r\n */\r\n updateCaretPos(length, minus) {\r\n let newCaretPos = this.updateCaretPosAction(length, minus);\r\n\r\n this.dispatch(instance => {\r\n instance.caretPosition = newCaretPos;\r\n });\r\n }\r\n\r\n /**\r\n * Action method of updateCaretPos\r\n *\r\n * @param {number} length Represents by how many characters the input should be moved\r\n * @param {boolean} minus Whether the cursor should be moved to the left or not.\r\n */\r\n updateCaretPosAction(length, minus) {\r\n let options = this.getOptions();\r\n let caretPosition = this.getCaretPosition();\r\n\r\n if (minus) {\r\n if (caretPosition > 0) caretPosition = caretPosition - length;\r\n } else {\r\n caretPosition = caretPosition + length;\r\n }\r\n\r\n if (options.debug) {\r\n console.log(\"Caret at:\", caretPosition, `(${this.keyboardDOMClass})`);\r\n }\r\n\r\n return caretPosition;\r\n }\r\n\r\n /**\r\n * Adds a string to the input at a given position\r\n *\r\n * @param {string} source The source input\r\n * @param {string} string The string to add\r\n * @param {number} position The (cursor) position where the string should be added\r\n * @param {boolean} moveCaret Whether to update simple-keyboard's cursor\r\n */\r\n addStringAt(source, string, position, moveCaret) {\r\n let output;\r\n\r\n if (!position && position !== 0) {\r\n output = source + string;\r\n } else {\r\n output = [source.slice(0, position), string, source.slice(position)].join(\r\n \"\"\r\n );\r\n\r\n /**\r\n * Avoid caret position change when maxLength is set\r\n */\r\n if (!this.isMaxLengthReached()) {\r\n if (moveCaret) this.updateCaretPos(string.length);\r\n }\r\n }\r\n\r\n return output;\r\n }\r\n\r\n /**\r\n * Removes an amount of characters at a given position\r\n *\r\n * @param {string} source The source input\r\n * @param {number} position The (cursor) position from where the characters should be removed\r\n * @param {boolean} moveCaret Whether to update simple-keyboard's cursor\r\n */\r\n removeAt(source, position, moveCaret) {\r\n let caretPosition = this.getCaretPosition();\r\n\r\n if (caretPosition === 0) {\r\n return source;\r\n }\r\n\r\n let output;\r\n let prevTwoChars;\r\n let emojiMatched;\r\n let emojiMatchedReg = /([\\uD800-\\uDBFF][\\uDC00-\\uDFFF])/g;\r\n\r\n /**\r\n * Emojis are made out of two characters, so we must take a custom approach to trim them.\r\n * For more info: https://mathiasbynens.be/notes/javascript-unicode\r\n */\r\n if (position && position >= 0) {\r\n prevTwoChars = source.substring(position - 2, position);\r\n emojiMatched = prevTwoChars.match(emojiMatchedReg);\r\n\r\n if (emojiMatched) {\r\n output = source.substr(0, position - 2) + source.substr(position);\r\n if (moveCaret) this.updateCaretPos(2, true);\r\n } else {\r\n output = source.substr(0, position - 1) + source.substr(position);\r\n if (moveCaret) this.updateCaretPos(1, true);\r\n }\r\n } else {\r\n prevTwoChars = source.slice(-2);\r\n emojiMatched = prevTwoChars.match(emojiMatchedReg);\r\n\r\n if (emojiMatched) {\r\n output = source.slice(0, -2);\r\n if (moveCaret) this.updateCaretPos(2, true);\r\n } else {\r\n output = source.slice(0, -1);\r\n if (moveCaret) this.updateCaretPos(1, true);\r\n }\r\n }\r\n\r\n return output;\r\n }\r\n /**\r\n * Determines whether the maxLength has been reached. This function is called when the maxLength option it set.\r\n *\r\n * @param {object} inputObj\r\n * @param {string} updatedInput\r\n */\r\n handleMaxLength(inputObj, updatedInput) {\r\n let options = this.getOptions();\r\n let maxLength = options.maxLength;\r\n let currentInput = inputObj[options.inputName];\r\n let condition = currentInput.length === maxLength;\r\n\r\n if (\r\n /**\r\n * If pressing this button won't add more characters\r\n * We exit out of this limiter function\r\n */\r\n updatedInput.length <= currentInput.length\r\n ) {\r\n return false;\r\n }\r\n\r\n if (Number.isInteger(maxLength)) {\r\n if (options.debug) {\r\n console.log(\"maxLength (num) reached:\", condition);\r\n }\r\n\r\n if (condition) {\r\n /**\r\n * @type {boolean} Boolean value that shows whether maxLength has been reached\r\n */\r\n this.maxLengthReached = true;\r\n return true;\r\n } else {\r\n this.maxLengthReached = false;\r\n return false;\r\n }\r\n }\r\n\r\n if (typeof maxLength === \"object\") {\r\n let condition = currentInput.length === maxLength[options.inputName];\r\n\r\n if (options.debug) {\r\n console.log(\"maxLength (obj) reached:\", condition);\r\n }\r\n\r\n if (condition) {\r\n this.maxLengthReached = true;\r\n return true;\r\n } else {\r\n this.maxLengthReached = false;\r\n return false;\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Gets the current value of maxLengthReached\r\n */\r\n isMaxLengthReached() {\r\n return Boolean(this.maxLengthReached);\r\n }\r\n\r\n /**\r\n * Determines whether a touch device is being used\r\n */\r\n isTouchDevice() {\r\n return \"ontouchstart\" in window || navigator.maxTouchPoints;\r\n }\r\n\r\n /**\r\n * Determines whether pointer events are supported\r\n */\r\n pointerEventsSupported() {\r\n return window.PointerEvent;\r\n }\r\n\r\n /**\r\n * Bind all methods in a given class\r\n */\r\n\r\n static bindMethods(myClass, instance) {\r\n for (let myMethod of Object.getOwnPropertyNames(myClass.prototype)) {\r\n let excludeMethod =\r\n myMethod === \"constructor\" || myMethod === \"bindMethods\";\r\n if (!excludeMethod) {\r\n instance[myMethod] = instance[myMethod].bind(instance);\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Transforms an arbitrary string to camelCase\r\n *\r\n * @param {string} string The string to transform.\r\n */\r\n camelCase(string) {\r\n if (!string) return false;\r\n\r\n return string\r\n .toLowerCase()\r\n .trim()\r\n .split(/[.\\-_\\s]/g)\r\n .reduce((string, word) =>\r\n word.length ? string + word[0].toUpperCase() + word.slice(1) : string\r\n );\r\n }\r\n\r\n /**\r\n * Counts the number of duplicates in a given array\r\n *\r\n * @param {Array} array The haystack to search in\r\n * @param {string} value The needle to search for\r\n */\r\n countInArray(array, value) {\r\n return array.reduce((n, x) => n + (x === value), 0);\r\n }\r\n}\r\n\r\nexport default Utilities;\r\n","import Utilities from \"../services/Utilities\";\r\n\r\n/**\r\n * Physical Keyboard Service\r\n */\r\nclass PhysicalKeyboard {\r\n /**\r\n * Creates an instance of the PhysicalKeyboard service\r\n */\r\n constructor({ dispatch, getOptions }) {\r\n /**\r\n * @type {object} A simple-keyboard instance\r\n */\r\n this.dispatch = dispatch;\r\n this.getOptions = getOptions;\r\n\r\n /**\r\n * Bindings\r\n */\r\n Utilities.bindMethods(PhysicalKeyboard, this);\r\n }\r\n\r\n handleHighlightKeyDown(event) {\r\n let options = this.getOptions();\r\n let buttonPressed = this.getSimpleKeyboardLayoutKey(event);\r\n\r\n this.dispatch(instance => {\r\n let buttonDOM =\r\n instance.getButtonElement(buttonPressed) ||\r\n instance.getButtonElement(`{${buttonPressed}}`);\r\n\r\n if (buttonDOM) {\r\n buttonDOM.style.backgroundColor =\r\n options.physicalKeyboardHighlightBgColor || \"#9ab4d0\";\r\n buttonDOM.style.color =\r\n options.physicalKeyboardHighlightTextColor || \"white\";\r\n }\r\n });\r\n }\r\n\r\n handleHighlightKeyUp(event) {\r\n let buttonPressed = this.getSimpleKeyboardLayoutKey(event);\r\n\r\n this.dispatch(instance => {\r\n let buttonDOM =\r\n instance.getButtonElement(buttonPressed) ||\r\n instance.getButtonElement(`{${buttonPressed}}`);\r\n\r\n if (buttonDOM && buttonDOM.removeAttribute) {\r\n buttonDOM.removeAttribute(\"style\");\r\n }\r\n });\r\n }\r\n\r\n /**\r\n * Transforms a KeyboardEvent's \"key.code\" string into a simple-keyboard layout format\r\n * @param {object} event The KeyboardEvent\r\n */\r\n getSimpleKeyboardLayoutKey(event) {\r\n let output;\r\n\r\n if (\r\n event.code.includes(\"Numpad\") ||\r\n event.code.includes(\"Shift\") ||\r\n event.code.includes(\"Space\") ||\r\n event.code.includes(\"Backspace\") ||\r\n event.code.includes(\"Control\") ||\r\n event.code.includes(\"Alt\") ||\r\n event.code.includes(\"Meta\")\r\n ) {\r\n output = event.code;\r\n } else {\r\n output = event.key;\r\n }\r\n\r\n /**\r\n * If button is not uppercase, casting to lowercase\r\n */\r\n if (\r\n output !== output.toUpperCase() ||\r\n (event.code[0] === \"F\" &&\r\n Number.isInteger(Number(event.code[1])) &&\r\n event.code.length <= 3)\r\n ) {\r\n output = output.toLowerCase();\r\n }\r\n\r\n return output;\r\n }\r\n}\r\n\r\nexport default PhysicalKeyboard;\r\n","/**\r\n * Keyboard Layout Service\r\n */\r\nclass KeyboardLayout {\r\n /**\r\n * Get default simple-keyboard layout\r\n * @return {object} The default layout (US-QWERTY)\r\n */\r\n static getDefaultLayout() {\r\n return {\r\n default: [\r\n \"` 1 2 3 4 5 6 7 8 9 0 - = {bksp}\",\r\n \"{tab} q w e r t y u i o p [ ] \\\\\",\r\n \"{lock} a s d f g h j k l ; ' {enter}\",\r\n \"{shift} z x c v b n m , . / {shift}\",\r\n \".com @ {space}\"\r\n ],\r\n shift: [\r\n \"~ ! @ # $ % ^ & * ( ) _ + {bksp}\",\r\n \"{tab} Q W E R T Y U I O P { } |\",\r\n '{lock} A S D F G H J K L : \" {enter}',\r\n \"{shift} Z X C V B N M < > ? {shift}\",\r\n \".com @ {space}\"\r\n ]\r\n };\r\n }\r\n}\r\n\r\nexport default KeyboardLayout;\r\n","import \"./Keyboard.css\";\r\n\r\n// Services\r\nimport PhysicalKeyboard from \"../services/PhysicalKeyboard\";\r\nimport KeyboardLayout from \"../services/KeyboardLayout\";\r\nimport Utilities from \"../services/Utilities\";\r\n\r\n/**\r\n * Root class for simple-keyboard\r\n * This class:\r\n * - Parses the options\r\n * - Renders the rows and buttons\r\n * - Handles button functionality\r\n */\r\nclass SimpleKeyboard {\r\n /**\r\n * Creates an instance of SimpleKeyboard\r\n * @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.\r\n */\r\n constructor(...params) {\r\n let keyboardDOMQuery =\r\n typeof params[0] === \"string\" ? params[0] : \".simple-keyboard\";\r\n let options = typeof params[0] === \"object\" ? params[0] : params[1];\r\n\r\n if (!options) options = {};\r\n\r\n /**\r\n * Initializing Utilities\r\n */\r\n this.utilities = new Utilities({\r\n getOptions: this.getOptions,\r\n getCaretPosition: this.getCaretPosition,\r\n dispatch: this.dispatch\r\n });\r\n\r\n /**\r\n * Caret position\r\n */\r\n this.caretPosition = null;\r\n\r\n /**\r\n * Processing options\r\n */\r\n this.keyboardDOM = document.querySelector(keyboardDOMQuery);\r\n\r\n /**\r\n * @type {object}\r\n * @property {object} layout Modify the keyboard layout.\r\n * @property {string} layoutName Specifies which layout should be used.\r\n * @property {object} display Replaces variable buttons (such as {bksp}) with a human-friendly name (e.g.: “backspace”).\r\n * @property {boolean} mergeDisplay By default, when you set the display property, you replace the default one. This setting merges them instead.\r\n * @property {string} theme A prop to add your own css classes to the keyboard wrapper. You can add multiple classes separated by a space.\r\n * @property {Array} buttonTheme A prop to add your own css classes to one or several buttons.\r\n * @property {boolean} debug Runs a console.log every time a key is pressed. Displays the buttons pressed and the current input.\r\n * @property {boolean} newLineOnEnter Specifies whether clicking the “ENTER” button will input a newline (\\n) or not.\r\n * @property {boolean} tabCharOnTab Specifies whether clicking the “TAB” button will input a tab character (\\t) or not.\r\n * @property {string} inputName Allows you to use a single simple-keyboard instance for several inputs.\r\n * @property {number} maxLength Restrains all of simple-keyboard inputs to a certain length. This should be used in addition to the input element’s maxlengthattribute.\r\n * @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.\r\n * @property {boolean} syncInstanceInputs When set to true, this option synchronizes the internal input of every simple-keyboard instance.\r\n * @property {boolean} physicalKeyboardHighlight Enable highlighting of keys pressed on physical keyboard.\r\n * @property {boolean} preventMouseDownDefault Calling preventDefault for the mousedown events keeps the focus on the input.\r\n * @property {string} physicalKeyboardHighlightTextColor Define the text color that the physical keyboard highlighted key should have.\r\n * @property {string} physicalKeyboardHighlightBgColor Define the background color that the physical keyboard highlighted key should have.\r\n * @property {function(button: string):string} onKeyPress Executes the callback function on key press. Returns button layout name (i.e.: “{shift}”).\r\n * @property {function(input: string):string} onChange Executes the callback function on input change. Returns the current input’s string.\r\n * @property {function} onRender Executes the callback function every time simple-keyboard is rendered (e.g: when you change layouts).\r\n * @property {function} onInit Executes the callback function once simple-keyboard is rendered for the first time (on initialization).\r\n * @property {function(inputs: object):object} onChangeAll Executes the callback function on input change. Returns the input object with all defined inputs.\r\n * @property {boolean} useButtonTag Render buttons as a button element instead of a div element.\r\n * @property {boolean} disableCaretPositioning A prop to ensure characters are always be added/removed at the end of the string.\r\n * @property {object} inputPattern Restrains input(s) change to the defined regular expression pattern.\r\n * @property {boolean} useTouchEvents Instructs simple-keyboard to use touch events instead of click events.\r\n * @property {boolean} autoUseTouchEvents Enable useTouchEvents automatically when touch device is detected.\r\n * @property {boolean} useMouseEvents Opt out of PointerEvents handling, falling back to the prior mouse event logic.\r\n * @property {function} destroy Clears keyboard listeners and DOM elements.\r\n * @property {boolean} disableButtonHold Disable button hold action.\r\n * @property {function} onKeyReleased Executes the callback function on key release.\r\n */\r\n this.options = options;\r\n this.options.layoutName = this.options.layoutName || \"default\";\r\n this.options.theme = this.options.theme || \"hg-theme-default\";\r\n this.options.inputName = this.options.inputName || \"default\";\r\n this.options.preventMouseDownDefault =\r\n this.options.preventMouseDownDefault || false;\r\n\r\n /**\r\n * @type {object} Classes identifying loaded plugins\r\n */\r\n this.keyboardPluginClasses = \"\";\r\n\r\n /**\r\n * Bindings\r\n */\r\n Utilities.bindMethods(SimpleKeyboard, this);\r\n\r\n /**\r\n * simple-keyboard uses a non-persistent internal input to keep track of the entered string (the variable `keyboard.input`).\r\n * This removes any dependency to input DOM elements. You can type and directly display the value in a div element, for example.\r\n * @example\r\n * // To get entered input\r\n * let input = keyboard.getInput();\r\n *\r\n * // To clear entered input.\r\n * keyboard.clearInput();\r\n *\r\n * @type {object}\r\n * @property {object} default Default SimpleKeyboard internal input.\r\n * @property {object} myInputName Example input that can be set through `options.inputName:\"myInputName\"`.\r\n */\r\n this.input = {};\r\n this.input[this.options.inputName] = \"\";\r\n\r\n /**\r\n * @type {string} DOM class of the keyboard wrapper, normally \"simple-keyboard\" by default.\r\n */\r\n this.keyboardDOMClass = keyboardDOMQuery.split(\".\").join(\"\");\r\n\r\n /**\r\n * @type {object} Contains the DOM elements of every rendered button, the key being the button's layout name (e.g.: \"{enter}\").\r\n */\r\n this.buttonElements = {};\r\n\r\n /**\r\n * Simple-keyboard Instances\r\n * This enables multiple simple-keyboard support with easier management\r\n */\r\n if (!window[\"SimpleKeyboardInstances\"])\r\n window[\"SimpleKeyboardInstances\"] = {};\r\n\r\n window[\"SimpleKeyboardInstances\"][\r\n this.utilities.camelCase(this.keyboardDOMClass)\r\n ] = this;\r\n\r\n /**\r\n * Instance vars\r\n */\r\n this.allKeyboardInstances = window[\"SimpleKeyboardInstances\"];\r\n this.currentInstanceName = this.utilities.camelCase(this.keyboardDOMClass);\r\n this.keyboardInstanceNames = Object.keys(window[\"SimpleKeyboardInstances\"]);\r\n this.isFirstKeyboardInstance =\r\n this.keyboardInstanceNames[0] === this.currentInstanceName;\r\n\r\n /**\r\n * Physical Keyboard support\r\n */\r\n this.physicalKeyboard = new PhysicalKeyboard({\r\n dispatch: this.dispatch,\r\n getOptions: this.getOptions\r\n });\r\n\r\n /**\r\n * Rendering keyboard\r\n */\r\n if (this.keyboardDOM) this.render();\r\n else {\r\n console.warn(`\"${keyboardDOMQuery}\" was not found in the DOM.`);\r\n throw new Error(\"KEYBOARD_DOM_ERROR\");\r\n }\r\n\r\n /**\r\n * Modules\r\n */\r\n this.modules = {};\r\n this.loadModules();\r\n }\r\n\r\n /**\r\n * Getters\r\n */\r\n getOptions = () => this.options;\r\n getCaretPosition = () => this.caretPosition;\r\n\r\n /**\r\n * Handles clicks made to keyboard buttons\r\n * @param {string} button The button's layout name.\r\n */\r\n handleButtonClicked(button) {\r\n let debug = this.options.debug;\r\n\r\n /**\r\n * Ignoring placeholder buttons\r\n */\r\n if (button === \"{//}\") return false;\r\n\r\n /**\r\n * Calling onKeyPress\r\n */\r\n if (typeof this.options.onKeyPress === \"function\")\r\n this.options.onKeyPress(button);\r\n\r\n if (!this.input[this.options.inputName])\r\n this.input[this.options.inputName] = \"\";\r\n\r\n let updatedInput = this.utilities.getUpdatedInput(\r\n button,\r\n this.input[this.options.inputName],\r\n this.caretPosition\r\n );\r\n\r\n if (\r\n // If input will change as a result of this button press\r\n this.input[this.options.inputName] !== updatedInput &&\r\n // This pertains to the \"inputPattern\" option:\r\n // If inputPattern isn't set\r\n (!this.options.inputPattern ||\r\n // Or, if it is set and if the pattern is valid - we proceed.\r\n (this.options.inputPattern && this.inputPatternIsValid(updatedInput)))\r\n ) {\r\n /**\r\n * If maxLength and handleMaxLength yield true, halting\r\n */\r\n if (\r\n this.options.maxLength &&\r\n this.utilities.handleMaxLength(this.input, updatedInput)\r\n ) {\r\n return false;\r\n }\r\n\r\n this.input[this.options.inputName] = this.utilities.getUpdatedInput(\r\n button,\r\n this.input[this.options.inputName],\r\n this.caretPosition,\r\n true\r\n );\r\n\r\n if (debug) console.log(\"Input changed:\", this.input);\r\n\r\n /**\r\n * Enforce syncInstanceInputs, if set\r\n */\r\n if (this.options.syncInstanceInputs) this.syncInstanceInputs(this.input);\r\n\r\n /**\r\n * Calling onChange\r\n */\r\n if (typeof this.options.onChange === \"function\")\r\n this.options.onChange(this.input[this.options.inputName]);\r\n\r\n /**\r\n * Calling onChangeAll\r\n */\r\n if (typeof this.options.onChangeAll === \"function\")\r\n this.options.onChangeAll(this.input);\r\n }\r\n\r\n if (debug) {\r\n console.log(\"Key pressed:\", button);\r\n }\r\n }\r\n\r\n /**\r\n * Handles button mousedown\r\n */\r\n /* istanbul ignore next */\r\n handleButtonMouseDown(button, e) {\r\n /**\r\n * Handle event options\r\n */\r\n if (this.options.preventMouseDownDefault) e.preventDefault();\r\n if (this.options.stopMouseDownPropagation) e.stopPropagation();\r\n\r\n /**\r\n * @type {boolean} Whether the mouse is being held onKeyPress\r\n */\r\n this.isMouseHold = true;\r\n\r\n if (this.holdInteractionTimeout) clearTimeout(this.holdInteractionTimeout);\r\n\r\n if (this.holdTimeout) clearTimeout(this.holdTimeout);\r\n\r\n /**\r\n * @type {object} Time to wait until a key hold is detected\r\n */\r\n if (!this.options.disableButtonHold) {\r\n this.holdTimeout = setTimeout(() => {\r\n if (\r\n this.isMouseHold &&\r\n ((!button.includes(\"{\") && !button.includes(\"}\")) ||\r\n button === \"{delete}\" ||\r\n button === \"{backspace}\" ||\r\n button === \"{bksp}\" ||\r\n button === \"{space}\" ||\r\n button === \"{tab}\")\r\n ) {\r\n if (this.options.debug) console.log(\"Button held:\", button);\r\n\r\n this.handleButtonHold(button, e);\r\n }\r\n clearTimeout(this.holdTimeout);\r\n }, 500);\r\n }\r\n }\r\n\r\n /**\r\n * Handles button mouseup\r\n */\r\n handleButtonMouseUp() {\r\n this.isMouseHold = false;\r\n if (this.holdInteractionTimeout) clearTimeout(this.holdInteractionTimeout);\r\n\r\n /**\r\n * Calling onKeyReleased\r\n */\r\n if (typeof this.options.onKeyReleased === \"function\")\r\n this.options.onKeyReleased();\r\n }\r\n\r\n /**\r\n * Handles button hold\r\n */\r\n /* istanbul ignore next */\r\n handleButtonHold(button) {\r\n if (this.holdInteractionTimeout) clearTimeout(this.holdInteractionTimeout);\r\n\r\n /**\r\n * @type {object} Timeout dictating the speed of key hold iterations\r\n */\r\n this.holdInteractionTimeout = setTimeout(() => {\r\n if (this.isMouseHold) {\r\n this.handleButtonClicked(button);\r\n this.handleButtonHold(button);\r\n } else {\r\n clearTimeout(this.holdInteractionTimeout);\r\n }\r\n }, 100);\r\n }\r\n\r\n /**\r\n * Send a command to all simple-keyboard instances (if you have several instances).\r\n */\r\n syncInstanceInputs() {\r\n this.dispatch(instance => {\r\n instance.replaceInput(this.input);\r\n instance.caretPosition = this.caretPosition;\r\n });\r\n }\r\n\r\n /**\r\n * Clear the keyboard’s input.\r\n * @param {string} [inputName] optional - the internal input to select\r\n */\r\n clearInput(inputName) {\r\n inputName = inputName || this.options.inputName;\r\n this.input[inputName] = \"\";\r\n\r\n /**\r\n * Reset caretPosition\r\n */\r\n this.caretPosition = 0;\r\n\r\n /**\r\n * Enforce syncInstanceInputs, if set\r\n */\r\n if (this.options.syncInstanceInputs) this.syncInstanceInputs(this.input);\r\n }\r\n\r\n /**\r\n * Get the keyboard’s input (You can also get it from the onChange prop).\r\n * @param {string} [inputName] optional - the internal input to select\r\n */\r\n getInput(inputName) {\r\n inputName = inputName || this.options.inputName;\r\n\r\n /**\r\n * Enforce syncInstanceInputs, if set\r\n */\r\n if (this.options.syncInstanceInputs) this.syncInstanceInputs(this.input);\r\n\r\n return this.input[inputName];\r\n }\r\n\r\n /**\r\n * Set the keyboard’s input.\r\n * @param {string} input the input value\r\n * @param {string} inputName optional - the internal input to select\r\n */\r\n setInput(input, inputName) {\r\n inputName = inputName || this.options.inputName;\r\n this.input[inputName] = input;\r\n\r\n /**\r\n * Enforce syncInstanceInputs, if set\r\n */\r\n if (this.options.syncInstanceInputs) this.syncInstanceInputs(this.input);\r\n }\r\n\r\n /**\r\n * Replace the input object (`keyboard.input`)\r\n * @param {object} inputObj The input object\r\n */\r\n replaceInput(inputObj) {\r\n this.input = inputObj;\r\n }\r\n\r\n /**\r\n * Set new option or modify existing ones after initialization.\r\n * @param {object} options The options to set\r\n */\r\n setOptions(options) {\r\n options = options || {};\r\n this.options = Object.assign(this.options, options);\r\n\r\n /**\r\n * Some option changes require adjustments before re-render\r\n */\r\n this.onSetOptions(options);\r\n\r\n /**\r\n * Rendering\r\n */\r\n this.render();\r\n }\r\n\r\n /**\r\n * Executing actions depending on changed options\r\n * @param {object} options The options to set\r\n */\r\n onSetOptions(options) {\r\n if (options.inputName) {\r\n /**\r\n * inputName changed. This requires a caretPosition reset\r\n */\r\n if (this.options.debug) {\r\n console.log(\"inputName changed. caretPosition reset.\");\r\n }\r\n\r\n this.caretPosition = null;\r\n }\r\n }\r\n\r\n /**\r\n * Remove all keyboard rows and reset keyboard values.\r\n * Used interally between re-renders.\r\n */\r\n clear() {\r\n this.keyboardDOM.innerHTML = \"\";\r\n this.keyboardDOM.className = this.keyboardDOMClass;\r\n this.buttonElements = {};\r\n }\r\n\r\n /**\r\n * Send a command to all simple-keyboard instances at once (if you have multiple instances).\r\n * @param {function(instance: object, key: string)} callback Function to run on every instance\r\n */\r\n dispatch(callback) {\r\n if (!window[\"SimpleKeyboardInstances\"]) {\r\n console.warn(\r\n `SimpleKeyboardInstances is not defined. Dispatch cannot be called.`\r\n );\r\n throw new Error(\"INSTANCES_VAR_ERROR\");\r\n }\r\n\r\n return Object.keys(window[\"SimpleKeyboardInstances\"]).forEach(key => {\r\n callback(window[\"SimpleKeyboardInstances\"][key], key);\r\n });\r\n }\r\n\r\n /**\r\n * Adds/Modifies an entry to the `buttonTheme`. Basically a way to add a class to a button.\r\n * @param {string} buttons List of buttons to select (separated by a space).\r\n * @param {string} className Classes to give to the selected buttons (separated by space).\r\n */\r\n addButtonTheme(buttons, className) {\r\n if (!className || !buttons) return false;\r\n\r\n buttons.split(\" \").forEach(button => {\r\n className.split(\" \").forEach(classNameItem => {\r\n if (!this.options.buttonTheme) this.options.buttonTheme = [];\r\n\r\n let classNameFound = false;\r\n\r\n /**\r\n * If class is already defined, we add button to class definition\r\n */\r\n this.options.buttonTheme.map(buttonTheme => {\r\n if (buttonTheme.class.split(\" \").includes(classNameItem)) {\r\n classNameFound = true;\r\n\r\n let buttonThemeArray = buttonTheme.buttons.split(\" \");\r\n if (!buttonThemeArray.includes(button)) {\r\n classNameFound = true;\r\n buttonThemeArray.push(button);\r\n buttonTheme.buttons = buttonThemeArray.join(\" \");\r\n }\r\n }\r\n return buttonTheme;\r\n });\r\n\r\n /**\r\n * If class is not defined, we create a new entry\r\n */\r\n if (!classNameFound) {\r\n this.options.buttonTheme.push({\r\n class: classNameItem,\r\n buttons: buttons\r\n });\r\n }\r\n });\r\n });\r\n\r\n this.render();\r\n }\r\n\r\n /**\r\n * Removes/Amends an entry to the `buttonTheme`. Basically a way to remove a class previously added to a button through buttonTheme or addButtonTheme.\r\n * @param {string} buttons List of buttons to select (separated by a space).\r\n * @param {string} className Classes to give to the selected buttons (separated by space).\r\n */\r\n removeButtonTheme(buttons, className) {\r\n /**\r\n * When called with empty parameters, remove all button themes\r\n */\r\n if (!buttons && !className) {\r\n this.options.buttonTheme = [];\r\n this.render();\r\n return false;\r\n }\r\n\r\n /**\r\n * If buttons are passed and buttonTheme has items\r\n */\r\n if (\r\n buttons &&\r\n Array.isArray(this.options.buttonTheme) &&\r\n this.options.buttonTheme.length\r\n ) {\r\n let buttonArray = buttons.split(\" \");\r\n buttonArray.forEach((button, key) => {\r\n this.options.buttonTheme.map((buttonTheme, index) => {\r\n /**\r\n * If className is set, we affect the buttons only for that class\r\n * Otherwise, we afect all classes\r\n */\r\n if (\r\n (className && className.includes(buttonTheme.class)) ||\r\n !className\r\n ) {\r\n let filteredButtonArray = buttonTheme.buttons\r\n .split(\" \")\r\n .filter(item => item !== button);\r\n\r\n /**\r\n * If buttons left, return them, otherwise, remove button Theme\r\n */\r\n if (filteredButtonArray.length) {\r\n buttonTheme.buttons = filteredButtonArray.join(\" \");\r\n } else {\r\n this.options.buttonTheme.splice(index, 1);\r\n buttonTheme = null;\r\n }\r\n }\r\n\r\n return buttonTheme;\r\n });\r\n });\r\n\r\n this.render();\r\n }\r\n }\r\n\r\n /**\r\n * Get the DOM Element of a button. If there are several buttons with the same name, an array of the DOM Elements is returned.\r\n * @param {string} button The button layout name to select\r\n */\r\n getButtonElement(button) {\r\n let output;\r\n\r\n let buttonArr = this.buttonElements[button];\r\n if (buttonArr) {\r\n if (buttonArr.length > 1) {\r\n output = buttonArr;\r\n } else {\r\n output = buttonArr[0];\r\n }\r\n }\r\n\r\n return output;\r\n }\r\n\r\n /**\r\n * This handles the \"inputPattern\" option\r\n * by checking if the provided inputPattern passes\r\n */\r\n inputPatternIsValid(inputVal) {\r\n let inputPatternRaw = this.options.inputPattern;\r\n let inputPattern;\r\n\r\n /**\r\n * Check if input pattern is global or targeted to individual inputs\r\n */\r\n if (inputPatternRaw instanceof RegExp) {\r\n inputPattern = inputPatternRaw;\r\n } else {\r\n inputPattern = inputPatternRaw[this.options.inputName];\r\n }\r\n\r\n if (inputPattern && inputVal) {\r\n let didInputMatch = inputPattern.test(inputVal);\r\n\r\n if (this.options.debug) {\r\n console.log(\r\n `inputPattern (\"${inputPattern}\"): ${\r\n didInputMatch ? \"passed\" : \"did not pass!\"\r\n }`\r\n );\r\n }\r\n\r\n return didInputMatch;\r\n } else {\r\n /**\r\n * inputPattern doesn't seem to be set for the current input, or input is empty. Pass.\r\n */\r\n return true;\r\n }\r\n }\r\n\r\n /**\r\n * Handles simple-keyboard event listeners\r\n */\r\n setEventListeners() {\r\n /**\r\n * Only first instance should set the event listeners\r\n */\r\n if (this.isFirstKeyboardInstance || !this.allKeyboardInstances) {\r\n if (this.options.debug) {\r\n console.log(`Caret handling started (${this.keyboardDOMClass})`);\r\n }\r\n\r\n /**\r\n * Event Listeners\r\n */\r\n document.addEventListener(\"keyup\", this.handleKeyUp);\r\n document.addEventListener(\"keydown\", this.handleKeyDown);\r\n document.addEventListener(\"mouseup\", this.handleMouseUp);\r\n document.addEventListener(\"touchend\", this.handleTouchEnd);\r\n }\r\n }\r\n\r\n /**\r\n * Event Handler: KeyUp\r\n */\r\n handleKeyUp(event) {\r\n this.caretEventHandler(event);\r\n\r\n if (this.options.physicalKeyboardHighlight) {\r\n this.physicalKeyboard.handleHighlightKeyUp(event);\r\n }\r\n }\r\n\r\n /**\r\n * Event Handler: KeyDown\r\n */\r\n handleKeyDown(event) {\r\n if (this.options.physicalKeyboardHighlight) {\r\n this.physicalKeyboard.handleHighlightKeyDown(event);\r\n }\r\n }\r\n\r\n /**\r\n * Event Handler: MouseUp\r\n */\r\n handleMouseUp(event) {\r\n this.caretEventHandler(event);\r\n }\r\n\r\n /**\r\n * Event Handler: TouchEnd\r\n */\r\n handleTouchEnd(event) {\r\n this.caretEventHandler(event);\r\n }\r\n\r\n /**\r\n * Called by {@link caretEventHandler} when an event that warrants a cursor position update is triggered\r\n */\r\n caretEventHandler(event) {\r\n let targetTagName;\r\n if (event.target.tagName) {\r\n targetTagName = event.target.tagName.toLowerCase();\r\n }\r\n\r\n this.dispatch(instance => {\r\n if (instance.isMouseHold) {\r\n instance.isMouseHold = false;\r\n }\r\n\r\n if (\r\n (targetTagName === \"textarea\" || targetTagName === \"input\") &&\r\n !instance.options.disableCaretPositioning\r\n ) {\r\n /**\r\n * Tracks current cursor position\r\n * As keys are pressed, text will be added/removed at that position within the input.\r\n */\r\n instance.caretPosition = event.target.selectionStart;\r\n\r\n if (instance.options.debug) {\r\n console.log(\r\n \"Caret at: \",\r\n event.target.selectionStart,\r\n event.target.tagName.toLowerCase(),\r\n `(${instance.keyboardDOMClass})`\r\n );\r\n }\r\n } else if (instance.options.disableCaretPositioning) {\r\n /**\r\n * If we toggled off disableCaretPositioning, we must ensure caretPosition doesn't persist once reactivated.\r\n */\r\n instance.caretPosition = null;\r\n }\r\n });\r\n }\r\n\r\n /**\r\n * Destroy keyboard listeners and DOM elements\r\n */\r\n destroy() {\r\n /**\r\n * Remove listeners\r\n */\r\n document.removeEventListener(\"keyup\", this.handleKeyUp);\r\n document.removeEventListener(\"keydown\", this.handleKeyDown);\r\n document.removeEventListener(\"mouseup\", this.handleMouseUp);\r\n document.removeEventListener(\"touchend\", this.handleTouchEnd);\r\n\r\n /**\r\n * Clear DOM\r\n */\r\n this.clear();\r\n }\r\n\r\n /**\r\n * Process buttonTheme option\r\n */\r\n getButtonTheme() {\r\n let buttonThemesParsed = {};\r\n\r\n this.options.buttonTheme.forEach(themeObj => {\r\n if (themeObj.buttons && themeObj.class) {\r\n let themeButtons;\r\n\r\n if (typeof themeObj.buttons === \"string\") {\r\n themeButtons = themeObj.buttons.split(\" \");\r\n }\r\n\r\n if (themeButtons) {\r\n themeButtons.forEach(themeButton => {\r\n let themeParsed = buttonThemesParsed[themeButton];\r\n\r\n // If the button has already been added\r\n if (themeParsed) {\r\n // Making sure we don't add duplicate classes, even when buttonTheme has duplicates\r\n if (\r\n !this.utilities.countInArray(\r\n themeParsed.split(\" \"),\r\n themeObj.class\r\n )\r\n ) {\r\n buttonThemesParsed[\r\n themeButton\r\n ] = `${themeParsed} ${themeObj.class}`;\r\n }\r\n } else {\r\n buttonThemesParsed[themeButton] = themeObj.class;\r\n }\r\n });\r\n }\r\n } else {\r\n console.warn(\r\n `buttonTheme row is missing the \"buttons\" or the \"class\". Please check the documentation.`\r\n );\r\n }\r\n });\r\n\r\n return buttonThemesParsed;\r\n }\r\n\r\n onTouchDeviceDetected() {\r\n /**\r\n * Processing autoTouchEvents\r\n */\r\n this.processAutoTouchEvents();\r\n\r\n /**\r\n * Disabling contextual window on touch devices\r\n */\r\n this.disableContextualWindow();\r\n }\r\n\r\n /**\r\n * Disabling contextual window for hg-button\r\n */\r\n /* istanbul ignore next */\r\n disableContextualWindow() {\r\n window.oncontextmenu = event => {\r\n if (event.target.classList.contains(\"hg-button\")) {\r\n event.preventDefault();\r\n event.stopPropagation();\r\n return false;\r\n }\r\n };\r\n }\r\n\r\n /**\r\n * Process autoTouchEvents option\r\n */\r\n processAutoTouchEvents() {\r\n if (this.options.autoUseTouchEvents) {\r\n this.options.useTouchEvents = true;\r\n\r\n if (this.options.debug) {\r\n console.log(\r\n `autoUseTouchEvents: Touch device detected, useTouchEvents enabled.`\r\n );\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Executes the callback function once simple-keyboard is rendered for the first time (on initialization).\r\n */\r\n onInit() {\r\n if (this.options.debug) {\r\n console.log(`${this.keyboardDOMClass} Initialized`);\r\n }\r\n\r\n /**\r\n * setEventListeners\r\n */\r\n this.setEventListeners();\r\n\r\n if (typeof this.options.onInit === \"function\") this.options.onInit();\r\n }\r\n\r\n /**\r\n * Executes the callback function before a simple-keyboard render.\r\n */\r\n beforeFirstRender() {\r\n /**\r\n * Performing actions when touch device detected\r\n */\r\n if (this.utilities.isTouchDevice()) {\r\n this.onTouchDeviceDetected();\r\n }\r\n\r\n if (typeof this.options.beforeFirstRender === \"function\")\r\n this.options.beforeFirstRender();\r\n\r\n /**\r\n * Notify about PointerEvents usage\r\n */\r\n if (\r\n this.isFirstKeyboardInstance &&\r\n this.utilities.pointerEventsSupported() &&\r\n !this.options.useTouchEvents &&\r\n !this.options.useMouseEvents\r\n ) {\r\n if (this.options.debug) {\r\n console.log(\"Using PointerEvents as it is supported by this browser\");\r\n }\r\n }\r\n\r\n /**\r\n * Notify about touch events usage\r\n */\r\n if (this.options.useTouchEvents) {\r\n if (this.options.debug) {\r\n console.log(\r\n \"useTouchEvents has been enabled. Only touch events will be used.\"\r\n );\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Executes the callback function before a simple-keyboard render.\r\n */\r\n beforeRender() {\r\n if (typeof this.options.beforeRender === \"function\")\r\n this.options.beforeRender();\r\n }\r\n\r\n /**\r\n * Executes the callback function every time simple-keyboard is rendered (e.g: when you change layouts).\r\n */\r\n onRender() {\r\n if (typeof this.options.onRender === \"function\") this.options.onRender();\r\n }\r\n\r\n /**\r\n * Executes the callback function once all modules have been loaded\r\n */\r\n onModulesLoaded() {\r\n if (typeof this.options.onModulesLoaded === \"function\")\r\n this.options.onModulesLoaded();\r\n }\r\n\r\n /**\r\n * Register module\r\n */\r\n registerModule = (name, initCallback) => {\r\n if (!this.modules[name]) this.modules[name] = {};\r\n\r\n initCallback(this.modules[name]);\r\n };\r\n\r\n /**\r\n * Load modules\r\n */\r\n loadModules() {\r\n if (Array.isArray(this.options.modules)) {\r\n this.options.modules.forEach(Module => {\r\n let module = new Module();\r\n\r\n /* istanbul ignore next */\r\n if (module.constructor.name && module.constructor.name !== \"Function\") {\r\n let classStr = `module-${this.utilities.camelCase(\r\n module.constructor.name\r\n )}`;\r\n this.keyboardPluginClasses =\r\n this.keyboardPluginClasses + ` ${classStr}`;\r\n }\r\n\r\n module.init(this);\r\n });\r\n\r\n this.keyboardPluginClasses =\r\n this.keyboardPluginClasses + \" modules-loaded\";\r\n\r\n this.render();\r\n this.onModulesLoaded();\r\n }\r\n }\r\n\r\n /**\r\n * Get module prop\r\n */\r\n getModuleProp(name, prop) {\r\n if (!this.modules[name]) return false;\r\n\r\n return this.modules[name][prop];\r\n }\r\n\r\n /**\r\n * getModulesList\r\n */\r\n getModulesList() {\r\n return Object.keys(this.modules);\r\n }\r\n\r\n /**\r\n * Parse Row DOM containers\r\n */\r\n parseRowDOMContainers(\r\n rowDOM,\r\n rowIndex,\r\n containerStartIndexes,\r\n containerEndIndexes\r\n ) {\r\n let rowDOMArray = Array.from(rowDOM.children);\r\n let removedElements = 0;\r\n\r\n if (rowDOMArray.length) {\r\n containerStartIndexes.forEach((startIndex, arrIndex) => {\r\n let endIndex = containerEndIndexes[arrIndex];\r\n\r\n /**\r\n * If there exists a respective end index\r\n * if end index comes after start index\r\n */\r\n if (!endIndex || !(endIndex > startIndex)) {\r\n return false;\r\n }\r\n\r\n /**\r\n * Updated startIndex, endIndex\r\n * This is since the removal of buttons to place a single button container\r\n * results in a modified array size\r\n */\r\n let updated_startIndex = startIndex - removedElements;\r\n let updated_endIndex = endIndex - removedElements;\r\n\r\n /**\r\n * Create button container\r\n */\r\n let containerDOM = document.createElement(\"div\");\r\n containerDOM.className += \"hg-button-container\";\r\n let containerUID = `${this.options.layoutName}-r${rowIndex}c${arrIndex}`;\r\n containerDOM.setAttribute(\"data-skUID\", containerUID);\r\n\r\n /**\r\n * Taking elements due to be inserted into container\r\n */\r\n let containedElements = rowDOMArray.splice(\r\n updated_startIndex,\r\n updated_endIndex - updated_startIndex + 1\r\n );\r\n removedElements = updated_endIndex - updated_startIndex;\r\n\r\n /**\r\n * Inserting elements to container\r\n */\r\n containedElements.forEach(element => containerDOM.appendChild(element));\r\n\r\n /**\r\n * Adding container at correct position within rowDOMArray\r\n */\r\n rowDOMArray.splice(updated_startIndex, 0, containerDOM);\r\n\r\n /**\r\n * Clearing old rowDOM children structure\r\n */\r\n rowDOM.innerHTML = \"\";\r\n\r\n /**\r\n * Appending rowDOM new children list\r\n */\r\n rowDOMArray.forEach(element => rowDOM.appendChild(element));\r\n\r\n if (this.options.debug) {\r\n console.log(\r\n \"rowDOMContainer\",\r\n containedElements,\r\n updated_startIndex,\r\n updated_endIndex,\r\n removedElements + 1\r\n );\r\n }\r\n });\r\n }\r\n\r\n return rowDOM;\r\n }\r\n\r\n /**\r\n * Renders rows and buttons as per options\r\n */\r\n render() {\r\n /**\r\n * Clear keyboard\r\n */\r\n this.clear();\r\n\r\n /**\r\n * Calling beforeFirstRender\r\n */\r\n if (!this.initialized) {\r\n this.beforeFirstRender();\r\n }\r\n\r\n /**\r\n * Calling beforeRender\r\n */\r\n this.beforeRender();\r\n\r\n let layoutClass = `hg-layout-${this.options.layoutName}`;\r\n let layout = this.options.layout || KeyboardLayout.getDefaultLayout();\r\n let useTouchEvents = this.options.useTouchEvents || false;\r\n let useTouchEventsClass = useTouchEvents ? \"hg-touch-events\" : \"\";\r\n let useMouseEvents = this.options.useMouseEvents || false;\r\n let disableRowButtonContainers = this.options.disableRowButtonContainers;\r\n\r\n /**\r\n * Account for buttonTheme, if set\r\n */\r\n let buttonThemesParsed = Array.isArray(this.options.buttonTheme)\r\n ? this.getButtonTheme()\r\n : {};\r\n\r\n /**\r\n * Adding themeClass, layoutClass to keyboardDOM\r\n */\r\n this.keyboardDOM.className += ` ${this.options.theme} ${layoutClass} ${this.keyboardPluginClasses} ${useTouchEventsClass}`;\r\n\r\n /**\r\n * Iterating through each row\r\n */\r\n layout[this.options.layoutName].forEach((row, rIndex) => {\r\n let rowArray = row.split(\" \");\r\n\r\n /**\r\n * Creating empty row\r\n */\r\n let rowDOM = document.createElement(\"div\");\r\n rowDOM.className += \"hg-row\";\r\n\r\n /**\r\n * Tracking container indicators in rows\r\n */\r\n let containerStartIndexes = [];\r\n let containerEndIndexes = [];\r\n\r\n /**\r\n * Iterating through each button in row\r\n */\r\n rowArray.forEach((button, bIndex) => {\r\n /**\r\n * Check if button has a container indicator\r\n */\r\n let buttonHasContainerStart =\r\n !disableRowButtonContainers &&\r\n button.includes(\"[\") &&\r\n button.length > 1;\r\n let buttonHasContainerEnd =\r\n !disableRowButtonContainers &&\r\n button.includes(\"]\") &&\r\n button.length > 1;\r\n\r\n /**\r\n * Save container start index, if applicable\r\n */\r\n if (buttonHasContainerStart) {\r\n containerStartIndexes.push(bIndex);\r\n\r\n /**\r\n * Removing indicator\r\n */\r\n button = button.replace(/\\[/g, \"\");\r\n }\r\n\r\n if (buttonHasContainerEnd) {\r\n containerEndIndexes.push(bIndex);\r\n\r\n /**\r\n * Removing indicator\r\n */\r\n button = button.replace(/\\]/g, \"\");\r\n }\r\n\r\n /**\r\n * Processing button options\r\n */\r\n let fctBtnClass = this.utilities.getButtonClass(button);\r\n let buttonThemeClass = buttonThemesParsed[button];\r\n let buttonDisplayName = this.utilities.getButtonDisplayName(\r\n button,\r\n this.options.display,\r\n this.options.mergeDisplay\r\n );\r\n\r\n /**\r\n * Creating button\r\n */\r\n let buttonType = this.options.useButtonTag ? \"button\" : \"div\";\r\n let buttonDOM = document.createElement(buttonType);\r\n buttonDOM.className += `hg-button ${fctBtnClass}${\r\n buttonThemeClass ? \" \" + buttonThemeClass : \"\"\r\n }`;\r\n\r\n /**\r\n * Handle button click event\r\n */\r\n /* istanbul ignore next */\r\n if (\r\n this.utilities.pointerEventsSupported() &&\r\n !useTouchEvents &&\r\n !useMouseEvents\r\n ) {\r\n /**\r\n * Handle PointerEvents\r\n */\r\n buttonDOM.onpointerdown = e => {\r\n this.handleButtonClicked(button);\r\n this.handleButtonMouseDown(button, e);\r\n };\r\n buttonDOM.onpointerup = e => {\r\n this.handleButtonMouseUp();\r\n };\r\n buttonDOM.onpointercancel = e => this.handleButtonMouseUp();\r\n } else {\r\n /**\r\n * Fallback for browsers not supporting PointerEvents\r\n */\r\n if (useTouchEvents) {\r\n /**\r\n * Handle touch events\r\n */\r\n buttonDOM.ontouchstart = e => {\r\n this.handleButtonClicked(button);\r\n this.handleButtonMouseDown(button, e);\r\n };\r\n buttonDOM.ontouchend = e => this.handleButtonMouseUp();\r\n buttonDOM.ontouchcancel = e => this.handleButtonMouseUp();\r\n } else {\r\n /**\r\n * Handle mouse events\r\n */\r\n buttonDOM.onclick = () => {\r\n this.isMouseHold = false;\r\n this.handleButtonClicked(button);\r\n };\r\n buttonDOM.onmousedown = e => {\r\n this.handleButtonMouseDown(button, e);\r\n };\r\n }\r\n }\r\n\r\n /**\r\n * Adding identifier\r\n */\r\n buttonDOM.setAttribute(\"data-skBtn\", button);\r\n\r\n /**\r\n * Adding unique id\r\n * Since there's no limit on spawning same buttons, the unique id ensures you can style every button\r\n */\r\n let buttonUID = `${this.options.layoutName}-r${rIndex}b${bIndex}`;\r\n buttonDOM.setAttribute(\"data-skBtnUID\", buttonUID);\r\n\r\n /**\r\n * Adding display label\r\n */\r\n buttonDOM.setAttribute(\"data-displayLabel\", buttonDisplayName);\r\n\r\n /**\r\n * Adding button label to button\r\n */\r\n let buttonSpanDOM = document.createElement(\"span\");\r\n buttonSpanDOM.innerHTML = buttonDisplayName;\r\n buttonDOM.appendChild(buttonSpanDOM);\r\n\r\n /**\r\n * Adding to buttonElements\r\n */\r\n if (!this.buttonElements[button]) this.buttonElements[button] = [];\r\n\r\n this.buttonElements[button].push(buttonDOM);\r\n\r\n /**\r\n * Appending button to row\r\n */\r\n rowDOM.appendChild(buttonDOM);\r\n });\r\n\r\n /**\r\n * Parse containers in row\r\n */\r\n rowDOM = this.parseRowDOMContainers(\r\n rowDOM,\r\n rIndex,\r\n containerStartIndexes,\r\n containerEndIndexes\r\n );\r\n\r\n /**\r\n * Appending row to keyboard\r\n */\r\n this.keyboardDOM.appendChild(rowDOM);\r\n });\r\n\r\n /**\r\n * Calling onRender\r\n */\r\n this.onRender();\r\n\r\n if (!this.initialized) {\r\n /**\r\n * Ensures that onInit and beforeFirstRender are only called once per instantiation\r\n */\r\n this.initialized = true;\r\n\r\n /**\r\n * Handling onpointerup\r\n */\r\n /* istanbul ignore next */\r\n if (\r\n this.utilities.pointerEventsSupported() &&\r\n !useTouchEvents &&\r\n !useMouseEvents\r\n ) {\r\n document.onpointerup = () => this.handleButtonMouseUp();\r\n } else if (useTouchEvents) {\r\n /**\r\n * Handling ontouchend, ontouchcancel\r\n */\r\n document.ontouchend = e => this.handleButtonMouseUp();\r\n document.ontouchcancel = e => this.handleButtonMouseUp();\r\n } else if (!useTouchEvents) {\r\n /**\r\n * Handling mouseup\r\n */\r\n document.onmouseup = () => this.handleButtonMouseUp();\r\n }\r\n\r\n /**\r\n * Calling onInit\r\n */\r\n this.onInit();\r\n }\r\n }\r\n}\r\n\r\nexport default SimpleKeyboard;\r\n","import SimpleKeyboard from \"./components/Keyboard\";\r\nexport default SimpleKeyboard;\r\n"],"sourceRoot":""} \ No newline at end of file diff --git a/build/simple-keyboard.js b/build/simple-keyboard.js index 77c03616..414b4b3d 100644 --- a/build/simple-keyboard.js +++ b/build/simple-keyboard.js @@ -1,6 +1,6 @@ /*! * - * simple-keyboard v2.23.3 (Non-minified build) + * simple-keyboard v2.24.0 (Non-minified build) * https://github.com/hodgef/simple-keyboard * * Copyright (c) Francisco Hodge (https://github.com/hodgef) @@ -151,8 +151,20 @@ __webpack_require__.r(__webpack_exports__); // EXTERNAL MODULE: ./src/lib/components/Keyboard.css var Keyboard = __webpack_require__(1); - // CONCATENATED MODULE: ./src/lib/services/PhysicalKeyboard.js - function _classCallCheck(instance, Constructor) { + // CONCATENATED MODULE: ./src/lib/services/Utilities.js + function _typeof(obj) { + if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { + _typeof = function _typeof(obj) { + return typeof obj; + }; + } else { + _typeof = function _typeof(obj) { + return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; + }; + } + return _typeof(obj); + } + function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } @@ -178,173 +190,16 @@ return Constructor; } /** - * Physical Keyboard Service - */ var PhysicalKeyboard = /* */ function() { - /** - * Creates an instance of the PhysicalKeyboard service - */ function PhysicalKeyboard(simpleKeyboardInstance) { - _classCallCheck(this, PhysicalKeyboard); - /** - * @type {object} A simple-keyboard instance - */ this.simpleKeyboardInstance = simpleKeyboardInstance; - /** - * Bindings - */ this.initKeyboardListener = this.initKeyboardListener.bind(this); - this.getSimpleKeyboardLayoutKey = this.getSimpleKeyboardLayoutKey.bind(this); - /** - * Initialize key listeners - */ this.initKeyboardListener(); - } - /** - * Initializes key event listeners - */ _createClass(PhysicalKeyboard, [ { - key: "initKeyboardListener", - value: function initKeyboardListener() { - var _this = this; - // Adding button style on keydown - document.addEventListener("keydown", function(event) { - if (_this.simpleKeyboardInstance.options.physicalKeyboardHighlight) { - var buttonPressed = _this.getSimpleKeyboardLayoutKey(event); - _this.simpleKeyboardInstance.dispatch(function(instance) { - var buttonDOM = instance.getButtonElement(buttonPressed) || instance.getButtonElement("{".concat(buttonPressed, "}")); - if (buttonDOM) { - buttonDOM.style.backgroundColor = _this.simpleKeyboardInstance.options.physicalKeyboardHighlightBgColor || "#9ab4d0"; - buttonDOM.style.color = _this.simpleKeyboardInstance.options.physicalKeyboardHighlightTextColor || "white"; - } - }); - } - }); - // Removing button style on keyup - document.addEventListener("keyup", function(event) { - if (_this.simpleKeyboardInstance.options.physicalKeyboardHighlight) { - var buttonPressed = _this.getSimpleKeyboardLayoutKey(event); - _this.simpleKeyboardInstance.dispatch(function(instance) { - var buttonDOM = instance.getButtonElement(buttonPressed) || instance.getButtonElement("{".concat(buttonPressed, "}")); - if (buttonDOM && buttonDOM.removeAttribute) { - buttonDOM.removeAttribute("style"); - } - }); - } - }); - } - /** - * Transforms a KeyboardEvent's "key.code" string into a simple-keyboard layout format - * @param {object} event The KeyboardEvent - */ }, { - key: "getSimpleKeyboardLayoutKey", - value: function getSimpleKeyboardLayoutKey(event) { - var output; - if (event.code.includes("Numpad") || event.code.includes("Shift") || event.code.includes("Space") || event.code.includes("Backspace") || event.code.includes("Control") || event.code.includes("Alt") || event.code.includes("Meta")) { - output = event.code; - } else { - output = event.key; - } - /** - * If button is not uppercase, casting to lowercase - */ if (output !== output.toUpperCase() || event.code[0] === "F" && Number.isInteger(Number(event.code[1])) && event.code.length <= 3) { - output = output.toLowerCase(); - } - return output; - } - } ]); - return PhysicalKeyboard; - }(); - /* harmony default export */ var services_PhysicalKeyboard = PhysicalKeyboard; - // CONCATENATED MODULE: ./src/lib/services/KeyboardLayout.js - function KeyboardLayout_classCallCheck(instance, Constructor) { - if (!(instance instanceof Constructor)) { - throw new TypeError("Cannot call a class as a function"); - } - } - function KeyboardLayout_defineProperties(target, props) { - for (var i = 0; i < props.length; i++) { - var descriptor = props[i]; - descriptor.enumerable = descriptor.enumerable || false; - descriptor.configurable = true; - if ("value" in descriptor) { - descriptor.writable = true; - } - Object.defineProperty(target, descriptor.key, descriptor); - } - } - function KeyboardLayout_createClass(Constructor, protoProps, staticProps) { - if (protoProps) { - KeyboardLayout_defineProperties(Constructor.prototype, protoProps); - } - if (staticProps) { - KeyboardLayout_defineProperties(Constructor, staticProps); - } - return Constructor; - } - /** - * Keyboard Layout Service - */ var KeyboardLayout = /* */ function() { - function KeyboardLayout() { - KeyboardLayout_classCallCheck(this, KeyboardLayout); - } - KeyboardLayout_createClass(KeyboardLayout, null, [ { - key: "getDefaultLayout", - /** - * Get default simple-keyboard layout - * @return {object} The default layout (US-QWERTY) - */ value: function getDefaultLayout() { - return { - default: [ "` 1 2 3 4 5 6 7 8 9 0 - = {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}" ], - 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}" ] - }; - } - } ]); - return KeyboardLayout; - }(); - /* harmony default export */ var services_KeyboardLayout = KeyboardLayout; - // CONCATENATED MODULE: ./src/lib/services/Utilities.js - function _typeof(obj) { - if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { - _typeof = function _typeof(obj) { - return typeof obj; - }; - } else { - _typeof = function _typeof(obj) { - return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; - }; - } - return _typeof(obj); - } - function Utilities_classCallCheck(instance, Constructor) { - if (!(instance instanceof Constructor)) { - throw new TypeError("Cannot call a class as a function"); - } - } - function Utilities_defineProperties(target, props) { - for (var i = 0; i < props.length; i++) { - var descriptor = props[i]; - descriptor.enumerable = descriptor.enumerable || false; - descriptor.configurable = true; - if ("value" in descriptor) { - descriptor.writable = true; - } - Object.defineProperty(target, descriptor.key, descriptor); - } - } - function Utilities_createClass(Constructor, protoProps, staticProps) { - if (protoProps) { - Utilities_defineProperties(Constructor.prototype, protoProps); - } - if (staticProps) { - Utilities_defineProperties(Constructor, staticProps); - } - return Constructor; - } - /** * Utility Service */ var Utilities = /* */ function() { /** * Creates an instance of the Utility service - */ function Utilities(simpleKeyboardInstance) { - Utilities_classCallCheck(this, Utilities); - /** - * @type {object} A simple-keyboard instance - */ this.simpleKeyboardInstance = simpleKeyboardInstance; + */ function Utilities(_ref) { + var getOptions = _ref.getOptions, getCaretPosition = _ref.getCaretPosition, dispatch = _ref.dispatch; + _classCallCheck(this, Utilities); + this.getOptions = getOptions; + this.getCaretPosition = getCaretPosition; + this.dispatch = dispatch; /** * Bindings */ Utilities.bindMethods(Utilities, this); @@ -354,7 +209,7 @@ * * @param {string} button The button's layout name * @return {string} The classes to be added to the button - */ Utilities_createClass(Utilities, [ { + */ _createClass(Utilities, [ { key: "getButtonClass", value: function getButtonClass(button) { var buttonTypeClass = button.includes("{") && button.includes("}") && button !== "{//}" ? "functionBtn" : "standardBtn"; @@ -453,12 +308,12 @@ * * @param {string} button The button's layout name * @param {string} input The input string - * @param {object} options The simple-keyboard options object * @param {number} caretPos The cursor's current position * @param {boolean} moveCaret Whether to update simple-keyboard's cursor */ }, { key: "getUpdatedInput", - value: function getUpdatedInput(button, input, options, caretPos, moveCaret) { + value: function getUpdatedInput(button, input, caretPos, moveCaret) { + var options = this.getOptions(); var output = input; if ((button === "{bksp}" || button === "{backspace}") && output.length > 0) { output = this.removeAt(output, caretPos, moveCaret); @@ -495,33 +350,32 @@ */ }, { key: "updateCaretPos", value: function updateCaretPos(length, minus) { - var newCaretPos = this.updateCaretPosAction(this.simpleKeyboardInstance, length, minus); - if (this.simpleKeyboardInstance.options.syncInstanceInputs) { - this.simpleKeyboardInstance.dispatch(function(instance) { - instance.caretPosition = newCaretPos; - }); - } + var newCaretPos = this.updateCaretPosAction(length, minus); + this.dispatch(function(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. */ }, { key: "updateCaretPosAction", - value: function updateCaretPosAction(instance, length, minus) { + value: function updateCaretPosAction(length, minus) { + var options = this.getOptions(); + var caretPosition = this.getCaretPosition(); if (minus) { - if (instance.caretPosition > 0) { - instance.caretPosition = instance.caretPosition - length; + if (caretPosition > 0) { + caretPosition = caretPosition - length; } } else { - instance.caretPosition = instance.caretPosition + length; + caretPosition = caretPosition + length; } - if (this.simpleKeyboardInstance.options.debug) { - console.log("Caret at:", instance.caretPosition, "(".concat(instance.keyboardDOMClass, ")")); + if (options.debug) { + console.log("Caret at:", caretPosition, "(".concat(this.keyboardDOMClass, ")")); } - return instance.caretPosition; + return caretPosition; } /** * Adds a string to the input at a given position @@ -557,7 +411,8 @@ */ }, { key: "removeAt", value: function removeAt(source, position, moveCaret) { - if (this.simpleKeyboardInstance.caretPosition === 0) { + var caretPosition = this.getCaretPosition(); + if (caretPosition === 0) { return source; } var output; @@ -602,11 +457,11 @@ * Determines whether the maxLength has been reached. This function is called when the maxLength option it set. * * @param {object} inputObj - * @param {object} options * @param {string} updatedInput */ }, { key: "handleMaxLength", - value: function handleMaxLength(inputObj, options, updatedInput) { + value: function handleMaxLength(inputObj, updatedInput) { + var options = this.getOptions(); var maxLength = options.maxLength; var currentInput = inputObj[options.inputName]; var condition = currentInput.length === maxLength; @@ -675,6 +530,9 @@ * * @param {string} string The string to transform. */ value: function camelCase(string) { + if (!string) { + return false; + } return string.toLowerCase().trim().split(/[.\-_\s]/g).reduce(function(string, word) { return word.length ? string + word[0].toUpperCase() + word.slice(1) : string; }); @@ -724,6 +582,142 @@ return Utilities; }(); /* harmony default export */ var services_Utilities = Utilities; + // CONCATENATED MODULE: ./src/lib/services/PhysicalKeyboard.js + function PhysicalKeyboard_classCallCheck(instance, Constructor) { + if (!(instance instanceof Constructor)) { + throw new TypeError("Cannot call a class as a function"); + } + } + function PhysicalKeyboard_defineProperties(target, props) { + for (var i = 0; i < props.length; i++) { + var descriptor = props[i]; + descriptor.enumerable = descriptor.enumerable || false; + descriptor.configurable = true; + if ("value" in descriptor) { + descriptor.writable = true; + } + Object.defineProperty(target, descriptor.key, descriptor); + } + } + function PhysicalKeyboard_createClass(Constructor, protoProps, staticProps) { + if (protoProps) { + PhysicalKeyboard_defineProperties(Constructor.prototype, protoProps); + } + if (staticProps) { + PhysicalKeyboard_defineProperties(Constructor, staticProps); + } + return Constructor; + } + /** + * Physical Keyboard Service + */ var PhysicalKeyboard_PhysicalKeyboard = /* */ function() { + /** + * Creates an instance of the PhysicalKeyboard service + */ function PhysicalKeyboard(_ref) { + var dispatch = _ref.dispatch, getOptions = _ref.getOptions; + PhysicalKeyboard_classCallCheck(this, PhysicalKeyboard); + /** + * @type {object} A simple-keyboard instance + */ this.dispatch = dispatch; + this.getOptions = getOptions; + /** + * Bindings + */ services_Utilities.bindMethods(PhysicalKeyboard, this); + } + PhysicalKeyboard_createClass(PhysicalKeyboard, [ { + key: "handleHighlightKeyDown", + value: function handleHighlightKeyDown(event) { + var options = this.getOptions(); + var buttonPressed = this.getSimpleKeyboardLayoutKey(event); + this.dispatch(function(instance) { + var buttonDOM = instance.getButtonElement(buttonPressed) || instance.getButtonElement("{".concat(buttonPressed, "}")); + if (buttonDOM) { + buttonDOM.style.backgroundColor = options.physicalKeyboardHighlightBgColor || "#9ab4d0"; + buttonDOM.style.color = options.physicalKeyboardHighlightTextColor || "white"; + } + }); + } + }, { + key: "handleHighlightKeyUp", + value: function handleHighlightKeyUp(event) { + var buttonPressed = this.getSimpleKeyboardLayoutKey(event); + this.dispatch(function(instance) { + var buttonDOM = instance.getButtonElement(buttonPressed) || instance.getButtonElement("{".concat(buttonPressed, "}")); + if (buttonDOM && buttonDOM.removeAttribute) { + buttonDOM.removeAttribute("style"); + } + }); + } + /** + * Transforms a KeyboardEvent's "key.code" string into a simple-keyboard layout format + * @param {object} event The KeyboardEvent + */ }, { + key: "getSimpleKeyboardLayoutKey", + value: function getSimpleKeyboardLayoutKey(event) { + var output; + if (event.code.includes("Numpad") || event.code.includes("Shift") || event.code.includes("Space") || event.code.includes("Backspace") || event.code.includes("Control") || event.code.includes("Alt") || event.code.includes("Meta")) { + output = event.code; + } else { + output = event.key; + } + /** + * If button is not uppercase, casting to lowercase + */ if (output !== output.toUpperCase() || event.code[0] === "F" && Number.isInteger(Number(event.code[1])) && event.code.length <= 3) { + output = output.toLowerCase(); + } + return output; + } + } ]); + return PhysicalKeyboard; + }(); + /* harmony default export */ var services_PhysicalKeyboard = PhysicalKeyboard_PhysicalKeyboard; + // CONCATENATED MODULE: ./src/lib/services/KeyboardLayout.js + function KeyboardLayout_classCallCheck(instance, Constructor) { + if (!(instance instanceof Constructor)) { + throw new TypeError("Cannot call a class as a function"); + } + } + function KeyboardLayout_defineProperties(target, props) { + for (var i = 0; i < props.length; i++) { + var descriptor = props[i]; + descriptor.enumerable = descriptor.enumerable || false; + descriptor.configurable = true; + if ("value" in descriptor) { + descriptor.writable = true; + } + Object.defineProperty(target, descriptor.key, descriptor); + } + } + function KeyboardLayout_createClass(Constructor, protoProps, staticProps) { + if (protoProps) { + KeyboardLayout_defineProperties(Constructor.prototype, protoProps); + } + if (staticProps) { + KeyboardLayout_defineProperties(Constructor, staticProps); + } + return Constructor; + } + /** + * Keyboard Layout Service + */ var KeyboardLayout = /* */ function() { + function KeyboardLayout() { + KeyboardLayout_classCallCheck(this, KeyboardLayout); + } + KeyboardLayout_createClass(KeyboardLayout, null, [ { + key: "getDefaultLayout", + /** + * Get default simple-keyboard layout + * @return {object} The default layout (US-QWERTY) + */ value: function getDefaultLayout() { + return { + default: [ "` 1 2 3 4 5 6 7 8 9 0 - = {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}" ], + 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}" ] + }; + } + } ]); + return KeyboardLayout; + }(); + /* harmony default export */ var services_KeyboardLayout = KeyboardLayout; // CONCATENATED MODULE: ./src/lib/components/Keyboard.js function Keyboard_typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { @@ -776,6 +770,12 @@ */ function SimpleKeyboard() { var _this = this; Keyboard_classCallCheck(this, SimpleKeyboard); + this.getOptions = function() { + return _this.options; + }; + this.getCaretPosition = function() { + return _this.caretPosition; + }; this.registerModule = function(name, initCallback) { if (!_this.modules[name]) { _this.modules[name] = {}; @@ -789,7 +789,14 @@ /** * Initializing Utilities */ } - this.utilities = new services_Utilities(this); + this.utilities = new services_Utilities({ + getOptions: this.getOptions, + getCaretPosition: this.getCaretPosition, + dispatch: this.dispatch + }); + /** + * Caret position + */ this.caretPosition = null; /** * Processing options */ this.keyboardDOM = document.querySelector(keyboardDOMQuery); @@ -825,6 +832,7 @@ * @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 {boolean} disableButtonHold Disable button hold action. + * @property {function} onKeyReleased Executes the callback function on key release. */ this.options = options; this.options.layoutName = this.options.layoutName || "default"; this.options.theme = this.options.theme || "hg-theme-default"; @@ -858,6 +866,25 @@ * @type {object} Contains the DOM elements of every rendered button, the key being the button's layout name (e.g.: "{enter}"). */ this.buttonElements = {}; /** + * Simple-keyboard Instances + * This enables multiple simple-keyboard support with easier management + */ if (!window["SimpleKeyboardInstances"]) { + window["SimpleKeyboardInstances"] = {}; + } + window["SimpleKeyboardInstances"][this.utilities.camelCase(this.keyboardDOMClass)] = this; + /** + * Instance vars + */ this.allKeyboardInstances = window["SimpleKeyboardInstances"]; + this.currentInstanceName = this.utilities.camelCase(this.keyboardDOMClass); + this.keyboardInstanceNames = Object.keys(window["SimpleKeyboardInstances"]); + this.isFirstKeyboardInstance = this.keyboardInstanceNames[0] === this.currentInstanceName; + /** + * Physical Keyboard support + */ this.physicalKeyboard = new services_PhysicalKeyboard({ + dispatch: this.dispatch, + getOptions: this.getOptions + }); + /** * Rendering keyboard */ if (this.keyboardDOM) { this.render(); @@ -866,26 +893,18 @@ throw new Error("KEYBOARD_DOM_ERROR"); } /** - * Saving instance - * This enables multiple simple-keyboard support with easier management - */ if (!window["SimpleKeyboardInstances"]) { - window["SimpleKeyboardInstances"] = {}; - } - window["SimpleKeyboardInstances"][this.utilities.camelCase(this.keyboardDOMClass)] = this; - /** - * Physical Keyboard support - */ this.physicalKeyboardInterface = new services_PhysicalKeyboard(this); - /** * Modules */ this.modules = {}; this.loadModules(); } /** - * Handles clicks made to keyboard buttons - * @param {string} button The button's layout name. + * Getters */ Keyboard_createClass(SimpleKeyboard, [ { key: "handleButtonClicked", - value: function handleButtonClicked(button) { + /** + * Handles clicks made to keyboard buttons + * @param {string} button The button's layout name. + */ value: function handleButtonClicked(button) { var debug = this.options.debug; /** * Ignoring placeholder buttons @@ -900,7 +919,7 @@ if (!this.input[this.options.inputName]) { this.input[this.options.inputName] = ""; } - var updatedInput = this.utilities.getUpdatedInput(button, this.input[this.options.inputName], this.options, this.caretPosition); + var updatedInput = this.utilities.getUpdatedInput(button, this.input[this.options.inputName], this.caretPosition); 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 @@ -908,10 +927,10 @@ this.options.inputPattern && this.inputPatternIsValid(updatedInput))) { /** * If maxLength and handleMaxLength yield true, halting - */ if (this.options.maxLength && this.utilities.handleMaxLength(this.input, this.options, updatedInput)) { + */ if (this.options.maxLength && this.utilities.handleMaxLength(this.input, updatedInput)) { return false; } - this.input[this.options.inputName] = this.utilities.getUpdatedInput(button, this.input[this.options.inputName], this.options, this.caretPosition, true); + this.input[this.options.inputName] = this.utilities.getUpdatedInput(button, this.input[this.options.inputName], this.caretPosition, true); if (debug) { console.log("Input changed:", this.input); /** @@ -980,6 +999,11 @@ this.isMouseHold = false; if (this.holdInteractionTimeout) { clearTimeout(this.holdInteractionTimeout); + /** + * Calling onKeyReleased + */ } + if (typeof this.options.onKeyReleased === "function") { + this.options.onKeyReleased(); } } /** @@ -1252,25 +1276,59 @@ } } /** - * Retrieves the current cursor position within a input or textarea (if any) + * Handles simple-keyboard event listeners */ }, { - key: "handleCaret", - value: function handleCaret() { + key: "setEventListeners", + value: function setEventListeners() { /** - * Only first instance should insall the caret handling events - */ this.caretPosition = null; - var simpleKeyboardInstances = window["SimpleKeyboardInstances"]; - if (simpleKeyboardInstances && Object.keys(simpleKeyboardInstances)[0] === this.utilities.camelCase(this.keyboardDOMClass) || !simpleKeyboardInstances) { + * Only first instance should set the event listeners + */ if (this.isFirstKeyboardInstance || !this.allKeyboardInstances) { if (this.options.debug) { console.log("Caret handling started (".concat(this.keyboardDOMClass, ")")); } - document.addEventListener("keyup", this.caretEventHandler); - document.addEventListener("mouseup", this.caretEventHandler); - document.addEventListener("touchend", this.caretEventHandler); + /** + * Event Listeners + */ document.addEventListener("keyup", this.handleKeyUp); + document.addEventListener("keydown", this.handleKeyDown); + document.addEventListener("mouseup", this.handleMouseUp); + document.addEventListener("touchend", this.handleTouchEnd); } } /** - * Called by {@link handleCaret} when an event that warrants a cursor position update is triggered + * Event Handler: KeyUp + */ }, { + key: "handleKeyUp", + value: function handleKeyUp(event) { + this.caretEventHandler(event); + if (this.options.physicalKeyboardHighlight) { + this.physicalKeyboard.handleHighlightKeyUp(event); + } + } + /** + * Event Handler: KeyDown + */ }, { + key: "handleKeyDown", + value: function handleKeyDown(event) { + if (this.options.physicalKeyboardHighlight) { + this.physicalKeyboard.handleHighlightKeyDown(event); + } + } + /** + * Event Handler: MouseUp + */ }, { + key: "handleMouseUp", + value: function handleMouseUp(event) { + this.caretEventHandler(event); + } + /** + * Event Handler: TouchEnd + */ }, { + key: "handleTouchEnd", + value: function handleTouchEnd(event) { + this.caretEventHandler(event); + } + /** + * Called by {@link caretEventHandler} when an event that warrants a cursor position update is triggered */ }, { key: "caretEventHandler", value: function caretEventHandler(event) { @@ -1304,9 +1362,10 @@ value: function destroy() { /** * Remove listeners - */ document.removeEventListener("keyup", this.caretEventHandler); - document.removeEventListener("mouseup", this.caretEventHandler); - document.removeEventListener("touchend", this.caretEventHandler); + */ document.removeEventListener("keyup", this.handleKeyUp); + document.removeEventListener("keydown", this.handleKeyDown); + document.removeEventListener("mouseup", this.handleMouseUp); + document.removeEventListener("touchend", this.handleTouchEnd); /** * Clear DOM */ this.clear(); @@ -1388,8 +1447,8 @@ console.log("".concat(this.keyboardDOMClass, " Initialized")); } /** - * Caret handling - */ this.handleCaret(); + * setEventListeners + */ this.setEventListeners(); if (typeof this.options.onInit === "function") { this.options.onInit(); } @@ -1409,7 +1468,7 @@ /** * Notify about PointerEvents usage */ } - if (this.utilities.pointerEventsSupported() && !this.options.useTouchEvents && !this.options.useMouseEvents) { + if (this.isFirstKeyboardInstance && this.utilities.pointerEventsSupported() && !this.options.useTouchEvents && !this.options.useMouseEvents) { if (this.options.debug) { console.log("Using PointerEvents as it is supported by this browser"); } diff --git a/package-lock.json b/package-lock.json index ac704876..c4eda65c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "simple-keyboard", - "version": "2.23.3", + "version": "2.24.0", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -2244,7 +2244,7 @@ }, "util": { "version": "0.10.3", - "resolved": "https://registry.npmjs.org/util/-/util-0.10.3.tgz", + "resolved": "http://registry.npmjs.org/util/-/util-0.10.3.tgz", "integrity": "sha1-evsa/lCAUkZInj23/g7TeTNqwPk=", "dev": true, "requires": { @@ -2414,7 +2414,7 @@ }, "chalk": { "version": "1.1.3", - "resolved": "https://registry.npmjs.org/chalk/-/chalk-1.1.3.tgz", + "resolved": "http://registry.npmjs.org/chalk/-/chalk-1.1.3.tgz", "integrity": "sha1-qBFcVeSnAv5NFQq9OHKCKn4J/Jg=", "dev": true, "requires": { @@ -4298,7 +4298,7 @@ "dependencies": { "globby": { "version": "6.1.0", - "resolved": "https://registry.npmjs.org/globby/-/globby-6.1.0.tgz", + "resolved": "http://registry.npmjs.org/globby/-/globby-6.1.0.tgz", "integrity": "sha1-9abXDoOV4hyFj7BInWTfAkJNUGw=", "dev": true, "requires": { @@ -4311,7 +4311,7 @@ "dependencies": { "pify": { "version": "2.3.0", - "resolved": "https://registry.npmjs.org/pify/-/pify-2.3.0.tgz", + "resolved": "http://registry.npmjs.org/pify/-/pify-2.3.0.tgz", "integrity": "sha1-7RQaasBDqEnqWISY59yosVMw6Qw=", "dev": true } @@ -4974,7 +4974,7 @@ }, "load-json-file": { "version": "2.0.0", - "resolved": "https://registry.npmjs.org/load-json-file/-/load-json-file-2.0.0.tgz", + "resolved": "http://registry.npmjs.org/load-json-file/-/load-json-file-2.0.0.tgz", "integrity": "sha1-eUfkIUmvgNaWy/eXvKq8/h/inKg=", "dev": true, "requires": { @@ -5875,8 +5875,7 @@ "ansi-regex": { "version": "2.1.1", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "aproba": { "version": "1.2.0", @@ -5897,14 +5896,12 @@ "balanced-match": { "version": "1.0.0", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "brace-expansion": { "version": "1.1.11", "bundled": true, "dev": true, - "optional": true, "requires": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -5919,20 +5916,17 @@ "code-point-at": { "version": "1.1.0", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "concat-map": { "version": "0.0.1", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "console-control-strings": { "version": "1.1.0", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "core-util-is": { "version": "1.0.2", @@ -6049,8 +6043,7 @@ "inherits": { "version": "2.0.3", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "ini": { "version": "1.3.5", @@ -6062,7 +6055,6 @@ "version": "1.0.0", "bundled": true, "dev": true, - "optional": true, "requires": { "number-is-nan": "^1.0.0" } @@ -6077,7 +6069,6 @@ "version": "3.0.4", "bundled": true, "dev": true, - "optional": true, "requires": { "brace-expansion": "^1.1.7" } @@ -6085,14 +6076,12 @@ "minimist": { "version": "0.0.8", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "minipass": { "version": "2.3.5", "bundled": true, "dev": true, - "optional": true, "requires": { "safe-buffer": "^5.1.2", "yallist": "^3.0.0" @@ -6111,7 +6100,6 @@ "version": "0.5.1", "bundled": true, "dev": true, - "optional": true, "requires": { "minimist": "0.0.8" } @@ -6192,8 +6180,7 @@ "number-is-nan": { "version": "1.0.1", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "object-assign": { "version": "4.1.1", @@ -6205,7 +6192,6 @@ "version": "1.4.0", "bundled": true, "dev": true, - "optional": true, "requires": { "wrappy": "1" } @@ -6291,8 +6277,7 @@ "safe-buffer": { "version": "5.1.2", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "safer-buffer": { "version": "2.1.2", @@ -6328,7 +6313,6 @@ "version": "1.0.2", "bundled": true, "dev": true, - "optional": true, "requires": { "code-point-at": "^1.0.0", "is-fullwidth-code-point": "^1.0.0", @@ -6348,7 +6332,6 @@ "version": "3.0.1", "bundled": true, "dev": true, - "optional": true, "requires": { "ansi-regex": "^2.0.0" } @@ -6392,14 +6375,12 @@ "wrappy": { "version": "1.0.2", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "yallist": { "version": "3.0.3", "bundled": true, - "dev": true, - "optional": true + "dev": true } } }, @@ -8785,9 +8766,9 @@ } }, "mixin-deep": { - "version": "1.3.1", - "resolved": "https://registry.npmjs.org/mixin-deep/-/mixin-deep-1.3.1.tgz", - "integrity": "sha512-8ZItLHeEgaqEvd5lYBXfm4EZSFCX29Jb9K+lAHhDKzReKBQKj3R+7NOF6tjqYi9t4oI8VUfaWITJQm86wnXGNQ==", + "version": "1.3.2", + "resolved": "https://registry.npmjs.org/mixin-deep/-/mixin-deep-1.3.2.tgz", + "integrity": "sha512-WRoDn//mXBiJ1H40rqa3vH0toePwSsGb45iInWlTySa+Uu4k3tYUSxa2v1KqAiLtvlrSzaExqS1gtk96A9zvEA==", "dev": true, "requires": { "for-in": "^1.0.2", @@ -11254,7 +11235,7 @@ }, "readable-stream": { "version": "2.3.6", - "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.6.tgz", + "resolved": "http://registry.npmjs.org/readable-stream/-/readable-stream-2.3.6.tgz", "integrity": "sha512-tQtKA9WIAhBF3+VLAseyMqZeBjW0AHJoxOtYqSUZNJxauErmLbVm2FW1y+J/YA9dUrAC39ITejlZWhVIwawkKw==", "dev": true, "requires": { @@ -11429,7 +11410,7 @@ }, "css-select": { "version": "1.2.0", - "resolved": "https://registry.npmjs.org/css-select/-/css-select-1.2.0.tgz", + "resolved": "http://registry.npmjs.org/css-select/-/css-select-1.2.0.tgz", "integrity": "sha1-KzoRBTnFNV8c2NMUYj6HCxIeyFg=", "dev": true, "requires": { @@ -11974,9 +11955,9 @@ "dev": true }, "set-value": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/set-value/-/set-value-2.0.0.tgz", - "integrity": "sha512-hw0yxk9GT/Hr5yJEYnHNKYXkIA8mVJgd9ditYZCe16ZczcaELYYcfvaXesNACk2O8O0nTiPQcQhGUQj8JLzeeg==", + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/set-value/-/set-value-2.0.1.tgz", + "integrity": "sha512-JxHc1weCN68wRY0fhCoXpyK55m/XPHafOmK4UWD7m2CI14GMcFypt4w/0+NV5f/ZMby2F6S2wwA7fgynh9gWSw==", "dev": true, "requires": { "extend-shallow": "^2.0.1", @@ -12038,7 +12019,7 @@ }, "kind-of": { "version": "2.0.1", - "resolved": "https://registry.npmjs.org/kind-of/-/kind-of-2.0.1.tgz", + "resolved": "http://registry.npmjs.org/kind-of/-/kind-of-2.0.1.tgz", "integrity": "sha1-AY7HpM5+OobLkUG+UZ0kyPqpgbU=", "dev": true, "requires": { @@ -13035,6 +13016,7 @@ "resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.4.10.tgz", "integrity": "sha512-Y2VsbPVs0FIshJztycsO2SfPk7/KAF/T72qzv9u5EpQ4kB2hQoHlhNQTsNyy6ul7lQtqJN/AoWeS23OzEiEFxw==", "dev": true, + "optional": true, "requires": { "commander": "~2.19.0", "source-map": "~0.6.1" @@ -13044,13 +13026,15 @@ "version": "2.19.0", "resolved": "https://registry.npmjs.org/commander/-/commander-2.19.0.tgz", "integrity": "sha512-6tvAOO+D6OENvRAh524Dh9jcfKTYDQAqvqezbCW82xj5X0pSrcpxtvRKHLG0yBY6SD7PSDrJaj+0AiOcKVd1Xg==", - "dev": true + "dev": true, + "optional": true }, "source-map": { "version": "0.6.1", "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==", - "dev": true + "dev": true, + "optional": true } } }, @@ -13154,38 +13138,15 @@ } }, "union-value": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/union-value/-/union-value-1.0.0.tgz", - "integrity": "sha1-XHHDTLW61dzr4+oM0IIHulqhrqQ=", + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/union-value/-/union-value-1.0.1.tgz", + "integrity": "sha512-tJfXmxMeWYnczCVs7XAEvIV7ieppALdyepWMkHkwciRpZraG/xwT+s2JN8+pr1+8jCRf80FFzvr+MpQeeoF4Xg==", "dev": true, "requires": { "arr-union": "^3.1.0", "get-value": "^2.0.6", "is-extendable": "^0.1.1", - "set-value": "^0.4.3" - }, - "dependencies": { - "extend-shallow": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/extend-shallow/-/extend-shallow-2.0.1.tgz", - "integrity": "sha1-Ua99YUrZqfYQ6huvu5idaxxWiQ8=", - "dev": true, - "requires": { - "is-extendable": "^0.1.0" - } - }, - "set-value": { - "version": "0.4.3", - "resolved": "https://registry.npmjs.org/set-value/-/set-value-0.4.3.tgz", - "integrity": "sha1-fbCPnT0i3H945Trzw79GZuzfzPE=", - "dev": true, - "requires": { - "extend-shallow": "^2.0.1", - "is-extendable": "^0.1.1", - "is-plain-object": "^2.0.1", - "to-object-path": "^0.3.0" - } - } + "set-value": "^2.0.1" } }, "uniq": { diff --git a/package.json b/package.json index 52060f57..f59e0efa 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "simple-keyboard", - "version": "2.23.3", + "version": "2.24.0", "description": "On-screen Javascript Virtual Keyboard", "main": "build/index.js", "types": "build/index.d.ts", @@ -126,7 +126,7 @@ "jest": { "collectCoverageFrom": [ "src/**/*.{js,jsx,ts,tsx}", - "!src/lib/index.js", + "!src/**/index.js", "!src/utils/**", "!src/**/*.d.ts", "!**/tests/**" diff --git a/public/index.html b/public/index.html index a077458c..757ef4a9 100644 --- a/public/index.html +++ b/public/index.html @@ -23,8 +23,6 @@ -
-
-
+
diff --git a/src/demo/App.js b/src/demo/App.js deleted file mode 100644 index ebdd12c8..00000000 --- a/src/demo/App.js +++ /dev/null @@ -1,87 +0,0 @@ -import Keyboard from "../lib"; -import "./css/App.css"; - -/** - * simple-keyboard demo - */ -class App { - /** - * Instantiates the demo class - */ - constructor() { - document.addEventListener("DOMContentLoaded", this.onDOMLoaded); - - /** - * Default input name - * @type {string} - */ - this.layoutName = "default"; - } - - /** - * Executed when the DOM is ready - */ - onDOMLoaded = () => { - /** - * Creates a new simple-keyboard instance - */ - this.keyboard = new Keyboard({ - debug: true, - layoutName: this.layoutName, - onChange: input => this.onChange(input), - onKeyPress: button => this.onKeyPress(button), - newLineOnEnter: true, - physicalKeyboardHighlight: true - }); - - /** - * Adding preview (demo only) - */ - document.querySelector(".simple-keyboard").insertAdjacentHTML( - "beforebegin", - ` -
- -
- ` - ); - - document.querySelector(".input").addEventListener("input", event => { - this.keyboard.setInput(event.target.value); - }); - }; - - /** - * Handles shift functionality - */ - handleShiftButton = () => { - let layoutName = this.layoutName; - let shiftToggle = (this.layoutName = - layoutName === "default" ? "shift" : "default"); - - this.keyboard.setOptions({ - layoutName: shiftToggle - }); - }; - - /** - * Called when simple-keyboard input has changed - */ - onChange = input => { - document.querySelector(".input").value = input; - }; - - /** - * Called when a simple-keyboard key is pressed - */ - onKeyPress = button => { - console.log("Button pressed", button); - - /** - * Shift functionality - */ - if (button === "{lock}" || button === "{shift}") this.handleShiftButton(); - }; -} - -export default App; diff --git a/src/demo/BasicDemo.js b/src/demo/BasicDemo.js new file mode 100644 index 00000000..89bd5bc9 --- /dev/null +++ b/src/demo/BasicDemo.js @@ -0,0 +1,55 @@ +import Keyboard from "../lib"; +import "./css/BasicDemo.css"; + +const setDOM = () => { + document.querySelector("#root").innerHTML = ` + +
+ `; +}; + +class Demo { + constructor() { + setDOM(); + + /** + * Demo Start + */ + this.keyboard = new Keyboard({ + onChange: input => this.onChange(input), + onKeyPress: button => this.onKeyPress(button) + }); + + /** + * 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); + } + + 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() { + let currentLayout = this.keyboard.options.layoutName; + let shiftToggle = currentLayout === "default" ? "shift" : "default"; + + this.keyboard.setOptions({ + layoutName: shiftToggle + }); + } +} + +export default Demo; diff --git a/src/demo/FullKeyboardDemo.js b/src/demo/FullKeyboardDemo.js new file mode 100644 index 00000000..e4ff3714 --- /dev/null +++ b/src/demo/FullKeyboardDemo.js @@ -0,0 +1,157 @@ +import Keyboard from "../lib"; +import "./css/FullKeyboardDemo.css"; + +const setDOM = () => { + document.querySelector("#root").innerHTML = ` + +
+
+ +
+
+
+
+ +
+
+
+
+
+ `; +}; + +class Demo { + constructor() { + setDOM(); + + /** + * Demo Start + */ + let commonKeyboardOptions = { + onChange: input => this.onChange(input), + onKeyPress: button => this.onKeyPress(button), + theme: "simple-keyboard hg-theme-default hg-layout-default", + physicalKeyboardHighlight: true, + syncInstanceInputs: true, + mergeDisplay: true, + debug: true + }; + + this.keyboard = new Keyboard(".simple-keyboard-main", { + ...commonKeyboardOptions, + /** + * Layout by: + * Sterling Butters (https://github.com/SterlingButters) + */ + layout: { + default: [ + "{escape} {f1} {f2} {f3} {f4} {f5} {f6} {f7} {f8} {f9} {f10} {f11} {f12}", + "` 1 2 3 4 5 6 7 8 9 0 - = {backspace}", + "{tab} q w e r t y u i o p [ ] \\", + "{capslock} a s d f g h j k l ; ' {enter}", + "{shiftleft} z x c v b n m , . / {shiftright}", + "{controlleft} {altleft} {metaleft} {space} {metaright} {altright}" + ], + shift: [ + "{escape} {f1} {f2} {f3} {f4} {f5} {f6} {f7} {f8} {f9} {f10} {f11} {f12}", + "~ ! @ # $ % ^ & * ( ) _ + {backspace}", + "{tab} Q W E R T Y U I O P { } |", + '{capslock} A S D F G H J K L : " {enter}', + "{shiftleft} Z X C V B N M < > ? {shiftright}", + "{controlleft} {altleft} {metaleft} {space} {metaright} {altright}" + ] + }, + display: { + "{escape}": "esc ⎋", + "{tab}": "tab ⇥", + "{backspace}": "backspace ⌫", + "{enter}": "enter ↵", + "{capslock}": "caps lock ⇪", + "{shiftleft}": "shift ⇧", + "{shiftright}": "shift ⇧", + "{controlleft}": "ctrl ⌃", + "{controlright}": "ctrl ⌃", + "{altleft}": "alt ⌥", + "{altright}": "alt ⌥", + "{metaleft}": "cmd ⌘", + "{metaright}": "cmd ⌘" + } + }); + + this.keyboardControlPad = new Keyboard(".simple-keyboard-control", { + ...commonKeyboardOptions, + layout: { + default: [ + "{prtscr} {scrolllock} {pause}", + "{insert} {home} {pageup}", + "{delete} {end} {pagedown}" + ] + } + }); + + this.keyboardArrows = new Keyboard(".simple-keyboard-arrows", { + ...commonKeyboardOptions, + layout: { + default: ["{arrowup}", "{arrowleft} {arrowdown} {arrowright}"] + } + }); + + this.keyboardNumPad = new Keyboard(".simple-keyboard-numpad", { + ...commonKeyboardOptions, + layout: { + default: [ + "{numlock} {numpaddivide} {numpadmultiply}", + "{numpad7} {numpad8} {numpad9}", + "{numpad4} {numpad5} {numpad6}", + "{numpad1} {numpad2} {numpad3}", + "{numpad0} {numpaddecimal}" + ] + } + }); + + this.keyboardNumPadEnd = new Keyboard(".simple-keyboard-numpadEnd", { + ...commonKeyboardOptions, + layout: { + default: ["{numpadsubtract}", "{numpadadd}", "{numpadenter}"] + } + }); + + document.querySelector(".input").addEventListener("input", event => { + let input = document.querySelector(".input").value; + this.keyboard.setInput(input); + }); + } + + onChange(input) { + document.querySelector(".input").value = input; + this.keyboard.setInput(input); + + console.log("Input changed", input); + } + + onKeyPress(button) { + console.log("Button pressed", button); + + /** + * If you want to handle the shift and caps lock buttons + */ + if ( + button === "{shift}" || + button === "{shiftleft}" || + button === "{shiftright}" || + button === "{capslock}" + ) + this.handleShift(); + } + + handleShift() { + let currentLayout = this.keyboard.options.layoutName; + let shiftToggle = currentLayout === "default" ? "shift" : "default"; + + this.keyboard.setOptions({ + layoutName: shiftToggle + }); + } +} + +export default Demo; diff --git a/src/demo/css/App.css b/src/demo/css/App.css deleted file mode 100644 index 2cf112f2..00000000 --- a/src/demo/css/App.css +++ /dev/null @@ -1,33 +0,0 @@ -#root { - font-family: "HelveticaNeue-Light", "Helvetica Neue Light", "Helvetica Neue", - Helvetica, Arial, "Lucida Grande", sans-serif; - max-width: 850px; - margin: 0 auto; - padding-top: 20px; -} - -#root .simple-keyboard-preview { - background: rgba(0, 0, 0, 0.8); - border: 20px solid rgba(0, 0, 0, 0.1); - height: 200px; - border-top-right-radius: 5px; - border-top-left-radius: 5px; - padding: 10px; - box-sizing: border-box; -} - -#root .input { - color: rgba(255, 255, 255, 0.9); - background: transparent; - border: none; - outline: none; - font-family: monospace; - width: 100%; - height: 100%; - font-size: 18px; -} - -.simple-keyboard.hg-layout-custom { - border-top-left-radius: 0px; - border-top-right-radius: 0px; -} diff --git a/src/demo/css/BasicDemo.css b/src/demo/css/BasicDemo.css new file mode 100644 index 00000000..575ed60e --- /dev/null +++ b/src/demo/css/BasicDemo.css @@ -0,0 +1,12 @@ +input { + width: 100%; + height: 100px; + padding: 20px; + font-size: 20px; + border: none; + box-sizing: border-box; +} + +.simple-keyboard { + max-width: 850px; +} diff --git a/src/demo/css/FullKeyboardDemo.css b/src/demo/css/FullKeyboardDemo.css new file mode 100644 index 00000000..7fd3ab23 --- /dev/null +++ b/src/demo/css/FullKeyboardDemo.css @@ -0,0 +1,132 @@ +input { + width: 100%; + height: 100px; + padding: 20px; + font-size: 20px; + border: none; + box-sizing: border-box; +} + +.keyboardContainer { + display: flex; + background-color: rgba(0, 0, 0, 0.1); + justify-content: center; + width: 1024px; + border-radius: 5px; +} + +.simple-keyboard.hg-theme-default { + display: inline-block; +} + +.simple-keyboard-main.simple-keyboard { + width: 640px; + min-width: 640px; + background: none; +} + +.simple-keyboard-main.simple-keyboard .hg-row:first-child { + margin-bottom: 10px; +} + +.simple-keyboard-arrows.simple-keyboard { + align-self: flex-end; + background: none; +} + +.simple-keyboard .hg-button.selectedButton { + background: rgba(5, 25, 70, 0.53); + color: white; +} + +.simple-keyboard .hg-button.emptySpace { + pointer-events: none; + background: none; + border: none; + box-shadow: none; +} + +.simple-keyboard-arrows .hg-row { + justify-content: center; +} + +.simple-keyboard-arrows .hg-button { + width: 50px; + flex-grow: 0; + justify-content: center; + display: flex; + align-items: center; +} + +.controlArrows { + display: flex; + align-items: center; + justify-content: space-between; + flex-flow: column; +} + +.simple-keyboard-control.simple-keyboard { + background: none; +} + +.simple-keyboard-control.simple-keyboard .hg-row:first-child { + margin-bottom: 10px; +} + +.simple-keyboard-control .hg-button { + width: 50px; + flex-grow: 0; + justify-content: center; + display: flex; + align-items: center; +} + +.numPad { + display: flex; + align-items: flex-end; +} + +.simple-keyboard-numpad.simple-keyboard { + background: none; +} + +.simple-keyboard-numpad.simple-keyboard { + width: 160px; +} + +.simple-keyboard-numpad.simple-keyboard .hg-button { + width: 50px; + justify-content: center; + display: flex; + align-items: center; +} + +.simple-keyboard-numpadEnd.simple-keyboard { + width: 50px; + background: none; + margin: 0; + padding: 5px 5px 5px 0; +} + +.simple-keyboard-numpadEnd.simple-keyboard .hg-button { + align-items: center; + justify-content: center; + display: flex; +} + +.simple-keyboard-numpadEnd .hg-button.hg-standardBtn.hg-button-plus { + height: 85px; +} + +.simple-keyboard-numpadEnd.simple-keyboard .hg-button.hg-button-enter { + height: 85px; +} + +.simple-keyboard.hg-theme-default .hg-button.hg-selectedButton { + background: rgba(5, 25, 70, 0.53); + color: white; +} + +.hg-button.hg-functionBtn.hg-button-space { + width: 350px; +} diff --git a/src/demo/css/index.css b/src/demo/css/index.css new file mode 100644 index 00000000..188e8f13 --- /dev/null +++ b/src/demo/css/index.css @@ -0,0 +1,3 @@ +#root { + padding: 0px 40px; +} diff --git a/src/demo/index.js b/src/demo/index.js index 564c3e81..14d258fb 100644 --- a/src/demo/index.js +++ b/src/demo/index.js @@ -1,6 +1,17 @@ -import App from "./App"; +import "./css/index.css"; /** - * Initializing demo + * Demos */ -new App(); +import BasicDemo from "./BasicDemo"; +//import FullKeyboardDemo from "./FullKeyboardDemo"; + +/** + * Selected demo + */ +const SELECTED_DEMO = BasicDemo; + +/** + * Bootstrap + */ +new SELECTED_DEMO(); diff --git a/src/demo/tests/App.test.js b/src/demo/tests/BasicDemo.test.js similarity index 78% rename from src/demo/tests/App.test.js rename to src/demo/tests/BasicDemo.test.js index 9fd6a704..61c76455 100644 --- a/src/demo/tests/App.test.js +++ b/src/demo/tests/BasicDemo.test.js @@ -1,20 +1,18 @@ import TestUtility from '../../utils/TestUtility'; -import Index from '../index'; -import App from '../App'; +import BasicDemo from '../BasicDemo'; let testUtil = new TestUtility(); it('Demo will load', () => { testUtil.setDOM(); - let demo = new App(); + let demo = new BasicDemo(); }); it('Demo onDOMLoaded will work', () => { testUtil.setDOM(); - let demo = new App(); - demo.onDOMLoaded(); + let demo = new BasicDemo(); expect(demo.keyboard).toBeTruthy(); }); @@ -22,8 +20,7 @@ it('Demo onDOMLoaded will work', () => { it('Demo onChange will work', () => { testUtil.setDOM(); - let demo = new App(); - demo.onDOMLoaded(); + let demo = new BasicDemo(); demo.onChange("test"); @@ -33,8 +30,7 @@ it('Demo onChange will work', () => { it('Demo onChange will work', () => { testUtil.setDOM(); - let demo = new App(); - demo.onDOMLoaded(); + let demo = new BasicDemo(); demo.keyboard.getButtonElement("q").onclick(); @@ -44,8 +40,7 @@ it('Demo onChange will work', () => { it('Demo input change will work', () => { testUtil.setDOM(); - let demo = new App(); - demo.onDOMLoaded(); + let demo = new BasicDemo(); document.body.querySelector('.input').value = "test"; document.body.querySelector('.input').dispatchEvent(new Event('input')); @@ -56,8 +51,7 @@ it('Demo input change will work', () => { it('Demo handleShiftButton will work', () => { testUtil.setDOM(); - let demo = new App(); - demo.onDOMLoaded(); + let demo = new BasicDemo(); demo.keyboard.getButtonElement("{shift}")[0].onclick(); expect(demo.keyboard.options.layoutName).toBe("shift"); diff --git a/src/demo/tests/FullKeyboardDemo.test.js b/src/demo/tests/FullKeyboardDemo.test.js new file mode 100644 index 00000000..1d70f214 --- /dev/null +++ b/src/demo/tests/FullKeyboardDemo.test.js @@ -0,0 +1,62 @@ +import TestUtility from '../../utils/TestUtility'; +import FullKeyboardDemo from '../FullKeyboardDemo'; + +let testUtil = new TestUtility(); + +it('Demo will load', () => { + testUtil.setDOM(); + + let demo = new FullKeyboardDemo(); +}); + +it('Demo onDOMLoaded will work', () => { + testUtil.setDOM(); + + let demo = new FullKeyboardDemo(); + + expect(demo.keyboard).toBeTruthy(); +}); + +it('Demo onChange will work', () => { + testUtil.setDOM(); + + let demo = new FullKeyboardDemo(); + + demo.onChange("test"); + + expect(document.body.querySelector('.input').value).toBe("test"); +}); + +it('Demo onChange will work', () => { + testUtil.setDOM(); + + let demo = new FullKeyboardDemo(); + + demo.keyboard.getButtonElement("q").onclick(); + + expect(document.body.querySelector('.input').value).toBe("q"); +}); + +it('Demo input change will work', () => { + testUtil.setDOM(); + + let demo = new FullKeyboardDemo(); + + document.body.querySelector('.input').value = "test"; + document.body.querySelector('.input').dispatchEvent(new Event('input')); + + expect(demo.keyboard.getInput()).toBe("test"); + expect(demo.keyboardNumPad.getInput()).toBe("test"); +}); + +it('Demo handleShiftButton will work', () => { + testUtil.setDOM(); + + let demo = new FullKeyboardDemo(); + + demo.keyboard.getButtonElement("{shiftleft}").onclick(); + expect(demo.keyboard.options.layoutName).toBe("shift"); + + demo.keyboard.getButtonElement("{shiftright}").onclick(); + expect(demo.keyboard.options.layoutName).toBe("default"); +}); \ No newline at end of file diff --git a/src/lib/@types/index.d.ts b/src/lib/@types/index.d.ts index a4a703eb..4a71d527 100644 --- a/src/lib/@types/index.d.ts +++ b/src/lib/@types/index.d.ts @@ -162,6 +162,11 @@ declare module 'simple-keyboard' { * Executes the callback function on input change. Returns the input object with all defined inputs. */ onChangeAll?: (inputs: any) => any; + + /** + * Executes the callback function on key release. + */ + onKeyReleased?: () => void; } class Keyboard { diff --git a/src/lib/components/Keyboard.js b/src/lib/components/Keyboard.js index 4a871fa4..9deccb4c 100644 --- a/src/lib/components/Keyboard.js +++ b/src/lib/components/Keyboard.js @@ -27,7 +27,16 @@ class SimpleKeyboard { /** * Initializing Utilities */ - this.utilities = new Utilities(this); + this.utilities = new Utilities({ + getOptions: this.getOptions, + getCaretPosition: this.getCaretPosition, + dispatch: this.dispatch + }); + + /** + * Caret position + */ + this.caretPosition = null; /** * Processing options @@ -66,6 +75,7 @@ class SimpleKeyboard { * @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 {boolean} disableButtonHold Disable button hold action. + * @property {function} onKeyReleased Executes the callback function on key release. */ this.options = options; this.options.layoutName = this.options.layoutName || "default"; @@ -112,16 +122,7 @@ class SimpleKeyboard { this.buttonElements = {}; /** - * Rendering keyboard - */ - if (this.keyboardDOM) this.render(); - else { - console.warn(`"${keyboardDOMQuery}" was not found in the DOM.`); - throw new Error("KEYBOARD_DOM_ERROR"); - } - - /** - * Saving instance + * Simple-keyboard Instances * This enables multiple simple-keyboard support with easier management */ if (!window["SimpleKeyboardInstances"]) @@ -131,10 +132,31 @@ class SimpleKeyboard { this.utilities.camelCase(this.keyboardDOMClass) ] = this; + /** + * Instance vars + */ + this.allKeyboardInstances = window["SimpleKeyboardInstances"]; + this.currentInstanceName = this.utilities.camelCase(this.keyboardDOMClass); + this.keyboardInstanceNames = Object.keys(window["SimpleKeyboardInstances"]); + this.isFirstKeyboardInstance = + this.keyboardInstanceNames[0] === this.currentInstanceName; + /** * Physical Keyboard support */ - this.physicalKeyboardInterface = new PhysicalKeyboard(this); + this.physicalKeyboard = new PhysicalKeyboard({ + dispatch: this.dispatch, + getOptions: this.getOptions + }); + + /** + * Rendering keyboard + */ + if (this.keyboardDOM) this.render(); + else { + console.warn(`"${keyboardDOMQuery}" was not found in the DOM.`); + throw new Error("KEYBOARD_DOM_ERROR"); + } /** * Modules @@ -143,6 +165,12 @@ class SimpleKeyboard { this.loadModules(); } + /** + * Getters + */ + getOptions = () => this.options; + getCaretPosition = () => this.caretPosition; + /** * Handles clicks made to keyboard buttons * @param {string} button The button's layout name. @@ -167,7 +195,6 @@ class SimpleKeyboard { let updatedInput = this.utilities.getUpdatedInput( button, this.input[this.options.inputName], - this.options, this.caretPosition ); @@ -185,7 +212,7 @@ class SimpleKeyboard { */ if ( this.options.maxLength && - this.utilities.handleMaxLength(this.input, this.options, updatedInput) + this.utilities.handleMaxLength(this.input, updatedInput) ) { return false; } @@ -193,7 +220,6 @@ class SimpleKeyboard { this.input[this.options.inputName] = this.utilities.getUpdatedInput( button, this.input[this.options.inputName], - this.options, this.caretPosition, true ); @@ -272,6 +298,12 @@ class SimpleKeyboard { handleButtonMouseUp() { this.isMouseHold = false; if (this.holdInteractionTimeout) clearTimeout(this.holdInteractionTimeout); + + /** + * Calling onKeyReleased + */ + if (typeof this.options.onKeyReleased === "function") + this.options.onKeyReleased(); } /** @@ -584,33 +616,63 @@ class SimpleKeyboard { } /** - * Retrieves the current cursor position within a input or textarea (if any) + * Handles simple-keyboard event listeners */ - handleCaret() { + setEventListeners() { /** - * Only first instance should insall the caret handling events + * Only first instance should set the event listeners */ - this.caretPosition = null; - let simpleKeyboardInstances = window["SimpleKeyboardInstances"]; - - if ( - (simpleKeyboardInstances && - Object.keys(simpleKeyboardInstances)[0] === - this.utilities.camelCase(this.keyboardDOMClass)) || - !simpleKeyboardInstances - ) { + if (this.isFirstKeyboardInstance || !this.allKeyboardInstances) { if (this.options.debug) { console.log(`Caret handling started (${this.keyboardDOMClass})`); } - document.addEventListener("keyup", this.caretEventHandler); - document.addEventListener("mouseup", this.caretEventHandler); - document.addEventListener("touchend", this.caretEventHandler); + /** + * Event Listeners + */ + document.addEventListener("keyup", this.handleKeyUp); + document.addEventListener("keydown", this.handleKeyDown); + document.addEventListener("mouseup", this.handleMouseUp); + document.addEventListener("touchend", this.handleTouchEnd); } } /** - * Called by {@link handleCaret} when an event that warrants a cursor position update is triggered + * Event Handler: KeyUp + */ + handleKeyUp(event) { + this.caretEventHandler(event); + + if (this.options.physicalKeyboardHighlight) { + this.physicalKeyboard.handleHighlightKeyUp(event); + } + } + + /** + * Event Handler: KeyDown + */ + handleKeyDown(event) { + if (this.options.physicalKeyboardHighlight) { + this.physicalKeyboard.handleHighlightKeyDown(event); + } + } + + /** + * Event Handler: MouseUp + */ + handleMouseUp(event) { + this.caretEventHandler(event); + } + + /** + * Event Handler: TouchEnd + */ + handleTouchEnd(event) { + this.caretEventHandler(event); + } + + /** + * Called by {@link caretEventHandler} when an event that warrants a cursor position update is triggered */ caretEventHandler(event) { let targetTagName; @@ -657,9 +719,10 @@ class SimpleKeyboard { /** * Remove listeners */ - document.removeEventListener("keyup", this.caretEventHandler); - document.removeEventListener("mouseup", this.caretEventHandler); - document.removeEventListener("touchend", this.caretEventHandler); + document.removeEventListener("keyup", this.handleKeyUp); + document.removeEventListener("keydown", this.handleKeyDown); + document.removeEventListener("mouseup", this.handleMouseUp); + document.removeEventListener("touchend", this.handleTouchEnd); /** * Clear DOM @@ -763,9 +826,9 @@ class SimpleKeyboard { } /** - * Caret handling + * setEventListeners */ - this.handleCaret(); + this.setEventListeners(); if (typeof this.options.onInit === "function") this.options.onInit(); } @@ -788,6 +851,7 @@ class SimpleKeyboard { * Notify about PointerEvents usage */ if ( + this.isFirstKeyboardInstance && this.utilities.pointerEventsSupported() && !this.options.useTouchEvents && !this.options.useMouseEvents diff --git a/src/lib/components/tests/Keyboard.test.js b/src/lib/components/tests/Keyboard.test.js index b37f6e0e..34fd7dd9 100644 --- a/src/lib/components/tests/Keyboard.test.js +++ b/src/lib/components/tests/Keyboard.test.js @@ -1242,4 +1242,57 @@ it('Keyboard disableButtonHold will work', () => { }); expect(keyboard.options.disableButtonHold).toBe(true); +}); + +it('Keyboard caretEventHandler will be triggered on mouseup and ontouchend', () => { + testUtil.setDOM(); + + let keyboard = new Keyboard({ + disableCaretPositioning: true + }); + + keyboard.caretPosition = 6; + + document.dispatchEvent(new MouseEvent('mouseup', { + target: { + tagName: "input" + } + })); + + expect(keyboard.caretPosition).toBe(null); + + keyboard.setOptions({ + disableCaretPositioning: false + }) + + keyboard.caretPosition = 10; + + document.dispatchEvent(new TouchEvent('touchend', { + target: { + tagName: "input" + } + })); + + expect(keyboard.caretPosition).toBe(10); +}); + +it('Keyboard onKeyReleased will work', () => { + testUtil.setDOM(); + + let pressed = false; + let firedTimes = 0; + + let keyboard = new Keyboard({ + onKeyReleased: () => { + pressed = true; + firedTimes++; + }, + debug: true + }); + + keyboard.getButtonElement("q").onpointerdown(); + keyboard.getButtonElement("q").onpointerup(); + + expect(pressed).toBeTruthy(); + expect(firedTimes).toBe(1); }); \ No newline at end of file diff --git a/src/lib/services/PhysicalKeyboard.js b/src/lib/services/PhysicalKeyboard.js index 10672215..ca713783 100644 --- a/src/lib/services/PhysicalKeyboard.js +++ b/src/lib/services/PhysicalKeyboard.js @@ -1,3 +1,5 @@ +import Utilities from "../services/Utilities"; + /** * Physical Keyboard Service */ @@ -5,66 +7,47 @@ class PhysicalKeyboard { /** * Creates an instance of the PhysicalKeyboard service */ - constructor(simpleKeyboardInstance) { + constructor({ dispatch, getOptions }) { /** * @type {object} A simple-keyboard instance */ - this.simpleKeyboardInstance = simpleKeyboardInstance; + this.dispatch = dispatch; + this.getOptions = getOptions; /** * Bindings */ - this.initKeyboardListener = this.initKeyboardListener.bind(this); - this.getSimpleKeyboardLayoutKey = this.getSimpleKeyboardLayoutKey.bind( - this - ); - - /** - * Initialize key listeners - */ - this.initKeyboardListener(); + Utilities.bindMethods(PhysicalKeyboard, this); } - /** - * Initializes key event listeners - */ - initKeyboardListener() { - // Adding button style on keydown - document.addEventListener("keydown", event => { - if (this.simpleKeyboardInstance.options.physicalKeyboardHighlight) { - let buttonPressed = this.getSimpleKeyboardLayoutKey(event); + handleHighlightKeyDown(event) { + let options = this.getOptions(); + let buttonPressed = this.getSimpleKeyboardLayoutKey(event); - this.simpleKeyboardInstance.dispatch(instance => { - let buttonDOM = - instance.getButtonElement(buttonPressed) || - instance.getButtonElement(`{${buttonPressed}}`); + this.dispatch(instance => { + let buttonDOM = + instance.getButtonElement(buttonPressed) || + instance.getButtonElement(`{${buttonPressed}}`); - if (buttonDOM) { - buttonDOM.style.backgroundColor = - this.simpleKeyboardInstance.options - .physicalKeyboardHighlightBgColor || "#9ab4d0"; - buttonDOM.style.color = - this.simpleKeyboardInstance.options - .physicalKeyboardHighlightTextColor || "white"; - } - }); + if (buttonDOM) { + buttonDOM.style.backgroundColor = + options.physicalKeyboardHighlightBgColor || "#9ab4d0"; + buttonDOM.style.color = + options.physicalKeyboardHighlightTextColor || "white"; } }); + } - // Removing button style on keyup - document.addEventListener("keyup", event => { - if (this.simpleKeyboardInstance.options.physicalKeyboardHighlight) { - let buttonPressed = this.getSimpleKeyboardLayoutKey(event); + handleHighlightKeyUp(event) { + let buttonPressed = this.getSimpleKeyboardLayoutKey(event); - this.simpleKeyboardInstance.dispatch(instance => { - let buttonDOM = - instance.getButtonElement(buttonPressed) || - instance.getButtonElement(`{${buttonPressed}}`); + this.dispatch(instance => { + let buttonDOM = + instance.getButtonElement(buttonPressed) || + instance.getButtonElement(`{${buttonPressed}}`); - if (buttonDOM && buttonDOM.removeAttribute) { - buttonDOM.removeAttribute("style"); - } - }); + if (buttonDOM && buttonDOM.removeAttribute) { + buttonDOM.removeAttribute("style"); } }); } diff --git a/src/lib/services/Utilities.js b/src/lib/services/Utilities.js index b7f4584c..3cee6e8b 100644 --- a/src/lib/services/Utilities.js +++ b/src/lib/services/Utilities.js @@ -5,11 +5,10 @@ class Utilities { /** * Creates an instance of the Utility service */ - constructor(simpleKeyboardInstance) { - /** - * @type {object} A simple-keyboard instance - */ - this.simpleKeyboardInstance = simpleKeyboardInstance; + constructor({ getOptions, getCaretPosition, dispatch }) { + this.getOptions = getOptions; + this.getCaretPosition = getCaretPosition; + this.dispatch = dispatch; /** * Bindings @@ -125,11 +124,11 @@ class Utilities { * * @param {string} button The button's layout name * @param {string} input The input string - * @param {object} options The simple-keyboard options object * @param {number} caretPos The cursor's current position * @param {boolean} moveCaret Whether to update simple-keyboard's cursor */ - getUpdatedInput(button, input, options, caretPos, moveCaret) { + getUpdatedInput(button, input, caretPos, moveCaret) { + let options = this.getOptions(); let output = input; if ( @@ -187,43 +186,34 @@ class Utilities { * @param {boolean} minus Whether the cursor should be moved to the left or not. */ updateCaretPos(length, minus) { - let newCaretPos = this.updateCaretPosAction( - this.simpleKeyboardInstance, - length, - minus - ); + let newCaretPos = this.updateCaretPosAction(length, minus); - if (this.simpleKeyboardInstance.options.syncInstanceInputs) { - this.simpleKeyboardInstance.dispatch(instance => { - instance.caretPosition = newCaretPos; - }); - } + this.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) { + updateCaretPosAction(length, minus) { + let options = this.getOptions(); + let caretPosition = this.getCaretPosition(); + if (minus) { - if (instance.caretPosition > 0) - instance.caretPosition = instance.caretPosition - length; + if (caretPosition > 0) caretPosition = caretPosition - length; } else { - instance.caretPosition = instance.caretPosition + length; + caretPosition = caretPosition + length; } - if (this.simpleKeyboardInstance.options.debug) { - console.log( - "Caret at:", - instance.caretPosition, - `(${instance.keyboardDOMClass})` - ); + if (options.debug) { + console.log("Caret at:", caretPosition, `(${this.keyboardDOMClass})`); } - return instance.caretPosition; + return caretPosition; } /** @@ -263,7 +253,9 @@ class Utilities { * @param {boolean} moveCaret Whether to update simple-keyboard's cursor */ removeAt(source, position, moveCaret) { - if (this.simpleKeyboardInstance.caretPosition === 0) { + let caretPosition = this.getCaretPosition(); + + if (caretPosition === 0) { return source; } @@ -306,10 +298,10 @@ class Utilities { * Determines whether the maxLength has been reached. This function is called when the maxLength option it set. * * @param {object} inputObj - * @param {object} options * @param {string} updatedInput */ - handleMaxLength(inputObj, options, updatedInput) { + handleMaxLength(inputObj, updatedInput) { + let options = this.getOptions(); let maxLength = options.maxLength; let currentInput = inputObj[options.inputName]; let condition = currentInput.length === maxLength; @@ -399,6 +391,8 @@ class Utilities { * @param {string} string The string to transform. */ camelCase(string) { + if (!string) return false; + return string .toLowerCase() .trim() diff --git a/src/lib/services/tests/Utilities.test.js b/src/lib/services/tests/Utilities.test.js index 5d1af730..b846526e 100644 --- a/src/lib/services/tests/Utilities.test.js +++ b/src/lib/services/tests/Utilities.test.js @@ -31,7 +31,7 @@ it('Keyboard {bksp} button will work', () => { let keyboard = new Keyboard(); - let output = keyboard.utilities.getUpdatedInput("{bksp}", "test", keyboard.options); + let output = keyboard.utilities.getUpdatedInput("{bksp}", "test"); expect(output).toBe("tes"); }); @@ -41,7 +41,7 @@ it('Keyboard {space} button will work', () => { let keyboard = new Keyboard(); - let output = keyboard.utilities.getUpdatedInput("{space}", "test", keyboard.options); + let output = keyboard.utilities.getUpdatedInput("{space}", "test"); expect(output).toBe("test "); }); @@ -51,7 +51,7 @@ it('Keyboard {tab} button will work', () => { let keyboard = new Keyboard(); - let output = keyboard.utilities.getUpdatedInput("{tab}", "test", keyboard.options); + let output = keyboard.utilities.getUpdatedInput("{tab}", "test"); expect(output).toBe("test\t"); }); @@ -63,7 +63,7 @@ it('Keyboard {tab} button will work with tabCharOnTab:false', () => { tabCharOnTab: false }); - let output = keyboard.utilities.getUpdatedInput("{tab}", "test", keyboard.options); + let output = keyboard.utilities.getUpdatedInput("{tab}", "test"); expect(output).toBe("test"); }); @@ -73,7 +73,7 @@ it('Keyboard {enter} button will work', () => { let keyboard = new Keyboard(); - let output = keyboard.utilities.getUpdatedInput("{enter}", "test", keyboard.options); + let output = keyboard.utilities.getUpdatedInput("{enter}", "test"); expect(output).toBe("test"); }); @@ -85,7 +85,7 @@ it('Keyboard {enter} button will work with newLineOnEnter:true', () => { newLineOnEnter: true }); - let output = keyboard.utilities.getUpdatedInput("{enter}", "test", keyboard.options); + let output = keyboard.utilities.getUpdatedInput("{enter}", "test"); expect(output).toBe("test\n"); }); @@ -96,7 +96,7 @@ it('Keyboard {numpadX} buttons will work', () => { let keyboard = new Keyboard(); for(let i = 0;i<=9;i++){ - let output = keyboard.utilities.getUpdatedInput(`{numpad${i}}`, "test", keyboard.options); + let output = keyboard.utilities.getUpdatedInput(`{numpad${i}}`, "test"); expect(output).toBe(`test${i}`); } }); @@ -106,7 +106,7 @@ it('Keyboard {numpaddivide} button will work', () => { let keyboard = new Keyboard(); - let output = keyboard.utilities.getUpdatedInput("{numpaddivide}", "test", keyboard.options); + let output = keyboard.utilities.getUpdatedInput("{numpaddivide}", "test"); expect(output).toBe("test/"); }); @@ -116,7 +116,7 @@ it('Keyboard {numpadmultiply} button will work', () => { let keyboard = new Keyboard(); - let output = keyboard.utilities.getUpdatedInput("{numpadmultiply}", "test", keyboard.options); + let output = keyboard.utilities.getUpdatedInput("{numpadmultiply}", "test"); expect(output).toBe("test*"); }); @@ -126,7 +126,7 @@ it('Keyboard {numpadsubtract} button will work', () => { let keyboard = new Keyboard(); - let output = keyboard.utilities.getUpdatedInput("{numpadsubtract}", "test", keyboard.options); + let output = keyboard.utilities.getUpdatedInput("{numpadsubtract}", "test"); expect(output).toBe("test-"); }); @@ -136,7 +136,7 @@ it('Keyboard {numpadadd} button will work', () => { let keyboard = new Keyboard(); - let output = keyboard.utilities.getUpdatedInput("{numpadadd}", "test", keyboard.options); + let output = keyboard.utilities.getUpdatedInput("{numpadadd}", "test"); expect(output).toBe("test+"); }); @@ -146,7 +146,7 @@ it('Keyboard {numpadadd} button will work', () => { let keyboard = new Keyboard(); - let output = keyboard.utilities.getUpdatedInput("{numpadadd}", "test", keyboard.options); + let output = keyboard.utilities.getUpdatedInput("{numpadadd}", "test"); expect(output).toBe("test+"); }); @@ -156,7 +156,7 @@ it('Keyboard {numpaddecimal} button will work', () => { let keyboard = new Keyboard(); - let output = keyboard.utilities.getUpdatedInput("{numpaddecimal}", "test", keyboard.options); + let output = keyboard.utilities.getUpdatedInput("{numpaddecimal}", "test"); expect(output).toBe("test."); }); @@ -172,7 +172,7 @@ it('Keyboard custom function buttons will work', () => { } }); - let output = keyboard.utilities.getUpdatedInput("{randombuttontest}", "test", keyboard.options); + let output = keyboard.utilities.getUpdatedInput("{randombuttontest}", "test"); expect(output).toBe("test"); expect(keyboard.getButtonElement("{randombuttontest}").onclick).toBeTruthy(); @@ -183,7 +183,7 @@ it('Keyboard "{" button will work', () => { let keyboard = new Keyboard(); - let output = keyboard.utilities.getUpdatedInput("{", "test", keyboard.options); + let output = keyboard.utilities.getUpdatedInput("{", "test"); expect(output).toBe("test{"); }); @@ -193,7 +193,7 @@ it('Keyboard "}" button will work', () => { let keyboard = new Keyboard(); - let output = keyboard.utilities.getUpdatedInput("}", "test", keyboard.options); + let output = keyboard.utilities.getUpdatedInput("}", "test"); expect(output).toBe("test}"); }); @@ -205,7 +205,7 @@ it('Keyboard standard button will affect input', () => { for (let i = 65; i <= 90; i++) { let char = String.fromCharCode(i); - let output = keyboard.utilities.getUpdatedInput(char, "test", keyboard.options); + let output = keyboard.utilities.getUpdatedInput(char, "test"); expect(output).toBe(`test${char}`); } }); @@ -213,8 +213,9 @@ it('Keyboard standard button will affect input', () => { it('Keyboard updateCaretPos will work with minus', () => { testUtil.setDOM(); - let keyboard = new Keyboard(); - keyboard.options.syncInstanceInputs = true; + let keyboard = new Keyboard({ + syncInstanceInputs: true + }); keyboard.caretPosition = 5; keyboard.utilities.updateCaretPos(2, true); @@ -282,7 +283,7 @@ it('Keyboard addStringAt will respect maxLength', () => { keyboard.setInput("test"); keyboard.caretPosition = 4; - keyboard.utilities.handleMaxLength(keyboard.input, keyboard.options, "testq") + keyboard.utilities.handleMaxLength(keyboard.input, "testq") keyboard.utilities.addStringAt("test", "q", 4); expect(keyboard.caretPosition).toBe(4); @@ -297,7 +298,7 @@ it('Keyboard handleMaxLength will exit out on same updatedInput', () => { keyboard.setInput("test"); - let output = keyboard.utilities.handleMaxLength(keyboard.input, keyboard.options, "test") + let output = keyboard.utilities.handleMaxLength(keyboard.input, "test") expect(output).toBeFalsy(); }); @@ -313,7 +314,7 @@ it('Keyboard handleMaxLength will work with object maxLength', () => { keyboard.setInput("test"); - let output = keyboard.utilities.handleMaxLength(keyboard.input, keyboard.options, "testq"); + let output = keyboard.utilities.handleMaxLength(keyboard.input, "testq"); expect(output).toBeTruthy(); }); @@ -330,7 +331,7 @@ it('Keyboard handleMaxLength will work with object maxLength and debug', () => { keyboard.setInput("test"); - let output = keyboard.utilities.handleMaxLength(keyboard.input, keyboard.options, "testq"); + let output = keyboard.utilities.handleMaxLength(keyboard.input, "testq"); expect(output).toBeTruthy(); }); @@ -346,7 +347,7 @@ it('Keyboard handleMaxLength will return false if obj maxLength not reached', () keyboard.setInput("test"); - let output = keyboard.utilities.handleMaxLength(keyboard.input, keyboard.options, "testq"); + let output = keyboard.utilities.handleMaxLength(keyboard.input, "testq"); expect(output).toBeFalsy(); }); @@ -361,7 +362,7 @@ it('Keyboard handleMaxLength will work without debug', () => { keyboard.setInput("test"); - let output = keyboard.utilities.handleMaxLength(keyboard.input, keyboard.options, "testq"); + let output = keyboard.utilities.handleMaxLength(keyboard.input, "testq"); expect(output).toBeTruthy(); }); @@ -376,7 +377,7 @@ it('Keyboard handleMaxLength will work with numeric maxLength', () => { keyboard.setInput("test"); - let output = keyboard.utilities.handleMaxLength(keyboard.input, keyboard.options, "testq"); + let output = keyboard.utilities.handleMaxLength(keyboard.input, "testq"); expect(output).toBeFalsy(); }); @@ -390,7 +391,7 @@ it('Keyboard handleMaxLength wont work with non numeric or object maxLength', () keyboard.setInput("test"); - let output = keyboard.utilities.handleMaxLength(keyboard.input, keyboard.options, "testq"); + let output = keyboard.utilities.handleMaxLength(keyboard.input, "testq"); expect(output).toBeFalsy(); }); @@ -405,7 +406,7 @@ it('Keyboard handleMaxLength wont work with non numeric or object maxLength (wit keyboard.setInput("test"); - let output = keyboard.utilities.handleMaxLength(keyboard.input, keyboard.options, "testq"); + let output = keyboard.utilities.handleMaxLength(keyboard.input, "testq"); expect(output).toBeFalsy(); }); @@ -483,4 +484,10 @@ 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"); +}); + +it('Keyboard camelCase will work with empty strings', () => { + testUtil.setDOM(); + let keyboard = new Keyboard(); + expect(keyboard.utilities.camelCase()).toBeFalsy(); }); \ No newline at end of file diff --git a/src/utils/TestUtility.js b/src/utils/TestUtility.js index 1f6c2953..b41b951a 100644 --- a/src/utils/TestUtility.js +++ b/src/utils/TestUtility.js @@ -7,9 +7,14 @@ export default class TestUtility { */ setDOM = (divClass) => { this.clear(); - const div = document.createElement('div'); - div.className += divClass || "simple-keyboard"; - document.body.appendChild(div); + const wrapperDOM = document.createElement('div'); + wrapperDOM.setAttribute("id", "root"); + + const keyboardDOM = document.createElement('div'); + keyboardDOM.className = divClass || "simple-keyboard"; + + wrapperDOM.appendChild(keyboardDOM); + document.body.appendChild(wrapperDOM); } /**