From 5e462fb4e4bb13e8b87c81a42d92eb79043db11b Mon Sep 17 00:00:00 2001 From: Francisco Hodge Date: Thu, 18 Mar 2021 22:42:48 -0400 Subject: [PATCH 1/3] Port to typescript --- .eslintrc.json | 24 +- .github/github.md | 2 +- .github/pull_request_template.md | 2 +- .github/workflows/main.yml | 63 +- .github/workflows/mirroring.yml | 12 +- .gitignore | 3 - .npmignore | 10 +- LICENSE | 4 +- README.md | 13 +- babel.config.js | 24 + build/css/index.css | 23 +- build/css/index.css.map | 1 - build/index.d.ts | 324 - build/index.js | 37 +- build/index.js.map | 1 - build/types/components/Keyboard.d.ts | 6 + build/types/index.d.ts | 4 + build/types/interfaces.d.ts | 6 + build/types/polyfills.d.ts | 0 build/types/services/Utilities.d.ts | 46 + config/env.js | 101 - config/getHttpsConfig.js | 66 - config/jest/cssTransform.js | 14 - config/jest/fileTransform.js | 40 - config/modules.js | 141 - config/paths.js | 73 - config/pnpTs.js | 35 - config/webpack.config.demo.js | 688 - config/webpack.config.js | 726 - config/webpackDevServer.config.js | 130 - package-lock.json | 43132 ++++++++-------- package.json | 153 +- public/favicon.ico | Bin 1150 -> 0 bytes public/index.html | 39 - scripts/build.js | 209 - scripts/demo.js | 209 - {config => scripts}/getPackageJson.js | 2 +- scripts/start.js | 187 - scripts/test.js | 53 - scripts/testMock.js | 1 + src/demo/{App.js => App.tsx} | 42 +- src/demo/{index.js => index.tsx} | 2 +- src/demo/tests/App.test.js | 48 - src/lib/@types/index.d.ts | 324 - .../components/{Keyboard.js => Keyboard.tsx} | 19 +- src/lib/components/tests/Keyboard.test.js | 155 - src/lib/components/tests/Keyboard.test.tsx | 176 + src/lib/index.js | 3 - src/lib/index.ts | 4 + src/lib/interfaces.ts | 8 + src/lib/polyfills.js | 252 + src/lib/services/Utilities.js | 19 - src/lib/services/Utilities.ts | 24 + src/setupTests.js | 5 - src/utils/TestUtility.js | 123 +- tsconfig.json | 19 + webpack.config.demo.js | 53 + webpack.config.js | 99 + 58 files changed, 22989 insertions(+), 24990 deletions(-) create mode 100644 babel.config.js delete mode 100644 build/css/index.css.map delete mode 100644 build/index.d.ts delete mode 100644 build/index.js.map create mode 100644 build/types/components/Keyboard.d.ts create mode 100644 build/types/index.d.ts create mode 100644 build/types/interfaces.d.ts create mode 100644 build/types/polyfills.d.ts create mode 100644 build/types/services/Utilities.d.ts delete mode 100644 config/env.js delete mode 100644 config/getHttpsConfig.js delete mode 100644 config/jest/cssTransform.js delete mode 100644 config/jest/fileTransform.js delete mode 100644 config/modules.js delete mode 100644 config/paths.js delete mode 100644 config/pnpTs.js delete mode 100644 config/webpack.config.demo.js delete mode 100644 config/webpack.config.js delete mode 100644 config/webpackDevServer.config.js delete mode 100644 public/favicon.ico delete mode 100644 public/index.html delete mode 100644 scripts/build.js delete mode 100644 scripts/demo.js rename {config => scripts}/getPackageJson.js (95%) delete mode 100644 scripts/start.js delete mode 100644 scripts/test.js create mode 100644 scripts/testMock.js rename src/demo/{App.js => App.tsx} (52%) rename src/demo/{index.js => index.tsx} (59%) delete mode 100644 src/demo/tests/App.test.js delete mode 100644 src/lib/@types/index.d.ts rename src/lib/components/{Keyboard.js => Keyboard.tsx} (77%) delete mode 100644 src/lib/components/tests/Keyboard.test.js create mode 100644 src/lib/components/tests/Keyboard.test.tsx delete mode 100644 src/lib/index.js create mode 100644 src/lib/index.ts create mode 100644 src/lib/interfaces.ts create mode 100644 src/lib/polyfills.js delete mode 100644 src/lib/services/Utilities.js create mode 100644 src/lib/services/Utilities.ts delete mode 100644 src/setupTests.js create mode 100644 tsconfig.json create mode 100644 webpack.config.demo.js create mode 100644 webpack.config.js diff --git a/.eslintrc.json b/.eslintrc.json index 61438f6c4..d614b0b2f 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,30 +1,26 @@ { - "parser": "babel-eslint", + "parser": "@typescript-eslint/parser", "parserOptions": { "ecmaVersion": 6, "sourceType": "module", "ecmaFeatures": { - "jsx": true, "modules": true, "experimentalObjectRestSpread": true } }, - "plugins": [ - "react" - ], - "extends": ["eslint:recommended", "plugin:react/recommended"], + "plugins": ["@typescript-eslint"], + "extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended"], "rules": { "comma-dangle": 0, "no-unused-vars": "warn", "no-unexpected-multiline": "warn", - "prefer-const": "warn" - }, - "settings": { - "react": { - "pragma": "React", - "version": "15.6.1" - } + "prefer-const": "warn", + "@typescript-eslint/no-empty-function": "off", + "@typescript-eslint/explicit-module-boundary-types": "off", + "@typescript-eslint/no-explicit-any": "off", + "@typescript-eslint/no-var-requires": "off" }, + "settings": {}, "env": { "browser": true, "node": true, @@ -32,4 +28,4 @@ "jest": true, "es6": true } -} \ No newline at end of file +} diff --git a/.github/github.md b/.github/github.md index ea3bb257e..d7f0436b0 100644 --- a/.github/github.md +++ b/.github/github.md @@ -1,4 +1,4 @@ # About .github This directory handles special features to be used on react-simple-keyboard's Github repository. -It is not needed for simple-keyboard to run and can be safely removed. \ No newline at end of file +It is not needed for simple-keyboard to run and can be safely removed. diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index 0242aadd1..3d37d3b5d 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -4,4 +4,4 @@ A few sentences describing the overall goals of the pull request's commits. ## Checks -- [ ] Tests ( `npm run test -- --coverage` ) Coverage at `./coverage/lcov-report/index.html` should be 100% \ No newline at end of file +- [ ] Tests ( `npm run coverage` ) Coverage at `./coverage/lcov-report/index.html` should be 100% diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 7b2bfdcc3..38fc6ca5e 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -9,36 +9,33 @@ jobs: node-version: [12.x] os: [ubuntu-latest] steps: - - uses: actions/checkout@v1 - - name: Use Node.js ${{ matrix.node_version }} - uses: actions/setup-node@v1 - with: - node-version: ${{ matrix.node_version }} - - name: npm install, build, and test - run: | - npm install - npm run start -- --testMode - npm run demo - npm run coverage - - uses: codecov/codecov-action@v1.0.2 - with: - token: ${{secrets.CODECOV_TOKEN}} - env: - CI: true - - - name: Discord notification - if: success() - env: - DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }} - uses: Ilshidur/action-discord@master - with: - args: 'react-simple-keyboard - CI Build Passed' - - - name: Discord notification - if: failure() - env: - DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }} - uses: Ilshidur/action-discord@master - with: - args: 'react-simple-keyboard - CI Build Failed' - + - uses: actions/checkout@v1 + - name: Use Node.js ${{ matrix.node_version }} + uses: actions/setup-node@v1 + with: + node-version: ${{ matrix.node_version }} + - name: npm install, build, and test + run: | + npm install + npm run coverage + - uses: codecov/codecov-action@v1.0.2 + with: + token: ${{secrets.CODECOV_TOKEN}} + env: + CI: true + + - name: Discord notification + if: success() + env: + DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }} + uses: Ilshidur/action-discord@master + with: + args: "react-simple-keyboard - CI Build Passed" + + - name: Discord notification + if: failure() + env: + DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }} + uses: Ilshidur/action-discord@master + with: + args: "react-simple-keyboard - CI Build Failed" diff --git a/.github/workflows/mirroring.yml b/.github/workflows/mirroring.yml index 0659ef6bf..6eb0f88f7 100644 --- a/.github/workflows/mirroring.yml +++ b/.github/workflows/mirroring.yml @@ -6,10 +6,8 @@ jobs: mirroring: runs-on: ubuntu-18.04 steps: - - uses: actions/checkout@v1 - - uses: pixta-dev/repository-mirroring-action@v1 - with: - target_repo_url: - git@gitlab.com:hodgef/react-simple-keyboard.git - ssh_private_key: - ${{ secrets.GL_KEY }} + - uses: actions/checkout@v1 + - uses: pixta-dev/repository-mirroring-action@v1 + with: + target_repo_url: git@gitlab.com:hodgef/react-simple-keyboard.git + ssh_private_key: ${{ secrets.GL_KEY }} diff --git a/.gitignore b/.gitignore index 624d579a0..a6b9b35fa 100644 --- a/.gitignore +++ b/.gitignore @@ -5,9 +5,6 @@ /.pnp .pnp.js -# production -/demo - # testing /coverage diff --git a/.npmignore b/.npmignore index 0e163ee84..d36841e97 100644 --- a/.npmignore +++ b/.npmignore @@ -2,6 +2,7 @@ /node_modules # testing +/tests /coverage # docs @@ -13,12 +14,13 @@ .env.development.local .env.test.local .env.production.local +/.github +/demo +.esdoc.json npm-debug.log* yarn-debug.log* yarn-error.log* -/.github -/demo # Development folders and files public @@ -29,4 +31,6 @@ config CHANGELOG.md README.md .eslintignore -.eslintrc.json \ No newline at end of file +.eslintrc.json +webpack.config.js +babel.config.js \ No newline at end of file diff --git a/LICENSE b/LICENSE index 8a5e1a792..90e3f8a4d 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2019 Francisco Hodge +Copyright (c) 2019 Francisco Hodge and project contributors. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. \ No newline at end of file +SOFTWARE. diff --git a/README.md b/README.md index 8f66e8d4c..75be6d292 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ simple-keyboard: Javscript Virtual Keyboard -
The slick virtual keyboard for React. Customizable, responsive and lightweight.
+
Virtual Keyboard for React. Customizable, responsive and lightweight.

@@ -63,10 +63,13 @@ Feel free to browse the [Questions & Answers](https://simple-keyboard.com/qa-use ## Compatibility 🎯 -> Simple-keyboard is intended for modern, standards-compliant browsers. -> Internet Explorer is sadly not one of them, and since its market-share is negligible (~2% for IE11), resources won't be spent in trying to support it. -> -> For more information, check out [this Q&A entry](https://hodgef.com/simple-keyboard/questions-answers/internet-explorer-not-supported/). +- Internet Explorer 11 +- Edge (Spartan) 16+ +- Edge (Anaheim/Edge Chromium) 79+ +- Chrome 49+ +- Safari 9+ +- Firefox 57+ +- iOS 9+ ## Contributing ✅ diff --git a/babel.config.js b/babel.config.js new file mode 100644 index 000000000..f61003583 --- /dev/null +++ b/babel.config.js @@ -0,0 +1,24 @@ +module.exports = { + presets: [ + "@babel/preset-react", + ["@babel/env", { + corejs:"3", + useBuiltIns: 'entry', + "targets": { + "browsers": [ + "edge >= 16", + "safari >= 9", + "firefox >= 57", + "ie >= 11", + "ios >= 9", + "chrome >= 49" + ] + }, + }], + "@babel/preset-typescript" + ], + plugins: [ + ["@babel/plugin-proposal-class-properties"], + ["@babel/plugin-transform-typescript"] + ] +}; \ No newline at end of file diff --git a/build/css/index.css b/build/css/index.css index bc5de27d0..d4f371d65 100644 --- a/build/css/index.css +++ b/build/css/index.css @@ -1,23 +1,22 @@ /*! * - * react-simple-keyboard v2.5.183 + * react-simple-keyboard v3.0.0-beta.1 * https://github.com/hodgef/react-simple-keyboard - * - * Copyright (c) Francisco Hodge (https://github.com/hodgef) - * + * + * Copyright (c) Francisco Hodge (https://github.com/hodgef) and project contributors. + * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. - * + * */ /*! * - * simple-keyboard v2.32.128 + * simple-keyboard v3.0.0-beta.1 * https://github.com/hodgef/simple-keyboard - * - * Copyright (c) Francisco Hodge (https://github.com/hodgef) - * + * + * Copyright (c) Francisco Hodge (https://github.com/hodgef) and project contributors. + * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. - * - */.hg-theme-default{width:100%;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;box-sizing:border-box;overflow:hidden;touch-action:manipulation}.hg-theme-default .hg-button span{pointer-events:none}.hg-theme-default button.hg-button{border-width:0;outline:0;font-size:inherit}.hg-theme-default{font-family:"HelveticaNeue-Light","Helvetica Neue Light","Helvetica Neue",Helvetica,Arial,"Lucida Grande",sans-serif;background-color:#ececec;padding:5px;border-radius:5px}.hg-theme-default .hg-button{display:inline-block;flex-grow:1}.hg-theme-default .hg-row{display:flex}.hg-theme-default .hg-row:not(:last-child){margin-bottom:5px}.hg-theme-default .hg-row .hg-button-container,.hg-theme-default .hg-row .hg-button:not(:last-child){margin-right:5px}.hg-theme-default .hg-row>div:last-child{margin-right:0}.hg-theme-default .hg-row .hg-button-container{display:flex}.hg-theme-default .hg-button{box-shadow:0 0 3px -1px rgba(0,0,0,.3);height:40px;border-radius:5px;box-sizing:border-box;padding:5px;background:#fff;border-bottom:1px solid #b5b5b5;cursor:pointer;display:flex;align-items:center;justify-content:center;-webkit-tap-highlight-color:rgba(0,0,0,0)}.hg-theme-default .hg-button.hg-activeButton{background:#efefef}.hg-theme-default.hg-layout-numeric .hg-button{width:33.3%;height:60px;align-items:center;display:flex;justify-content:center}.hg-theme-default .hg-button.hg-button-numpadadd,.hg-theme-default .hg-button.hg-button-numpadenter{height:85px}.hg-theme-default .hg-button.hg-button-numpad0{width:105px}.hg-theme-default .hg-button.hg-button-com{max-width:85px}.hg-theme-default .hg-button.hg-standardBtn.hg-button-at{max-width:45px}.hg-theme-default .hg-button.hg-selectedButton{background:rgba(5,25,70,.53);color:#fff}.hg-theme-default .hg-button.hg-standardBtn[data-skbtn=".com"]{max-width:82px}.hg-theme-default .hg-button.hg-standardBtn[data-skbtn="@"]{max-width:60px} -/*# sourceMappingURL=index.css.map */ \ No newline at end of file + * + */.hg-theme-default{width:100%;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;box-sizing:border-box;overflow:hidden;touch-action:manipulation;font-family:HelveticaNeue-Light,Helvetica Neue Light,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif;background-color:#ececec;padding:5px;border-radius:5px}.hg-theme-default .hg-button span{pointer-events:none}.hg-theme-default button.hg-button{border-width:0;outline:0;font-size:inherit}.hg-theme-default .hg-button{display:inline-block;flex-grow:1}.hg-theme-default .hg-row{display:flex}.hg-theme-default .hg-row:not(:last-child){margin-bottom:5px}.hg-theme-default .hg-row .hg-button-container,.hg-theme-default .hg-row .hg-button:not(:last-child){margin-right:5px}.hg-theme-default .hg-row>div:last-child{margin-right:0}.hg-theme-default .hg-row .hg-button-container{display:flex}.hg-theme-default .hg-button{box-shadow:0 0 3px -1px rgba(0,0,0,.3);height:40px;border-radius:5px;box-sizing:border-box;padding:5px;background:#fff;border-bottom:1px solid #b5b5b5;cursor:pointer;display:flex;align-items:center;justify-content:center;-webkit-tap-highlight-color:rgba(0,0,0,0)}.hg-theme-default .hg-button.hg-standardBtn{width:20px}.hg-theme-default .hg-button.hg-activeButton{background:#efefef}.hg-theme-default.hg-layout-numeric .hg-button{width:33.3%;height:60px;align-items:center;display:flex;justify-content:center}.hg-theme-default .hg-button.hg-button-numpadadd,.hg-theme-default .hg-button.hg-button-numpadenter{height:85px}.hg-theme-default .hg-button.hg-button-numpad0{width:105px}.hg-theme-default .hg-button.hg-button-com{max-width:85px}.hg-theme-default .hg-button.hg-standardBtn.hg-button-at{max-width:45px}.hg-theme-default .hg-button.hg-selectedButton{background:rgba(5,25,70,.53);color:#fff}.hg-theme-default .hg-button.hg-standardBtn[data-skbtn=".com"]{max-width:82px}.hg-theme-default .hg-button.hg-standardBtn[data-skbtn="@"]{max-width:60px}.hg-candidate-box{display:inline-flex;border-radius:5px;position:absolute;background:#ececec;border-bottom:2px solid #b5b5b5;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;min-width:272px;transform:translateY(-100%);margin-top:-10px}ul.hg-candidate-box-list{display:flex;list-style:none;padding:0;margin:0;flex:1}li.hg-candidate-box-list-item{height:40px;width:40px;display:flex;align-items:center;justify-content:center}li.hg-candidate-box-list-item:hover{background:rgba(0,0,0,.03);cursor:pointer}li.hg-candidate-box-list-item:active{background:rgba(0,0,0,.1)}.hg-candidate-box-prev:before{content:"◄"}.hg-candidate-box-next:before{content:"►"}.hg-candidate-box-next,.hg-candidate-box-prev{display:flex;align-items:center;padding:0 10px;background:#d0d0d0;color:#969696;cursor:pointer}.hg-candidate-box-next{border-top-right-radius:5px;border-bottom-right-radius:5px}.hg-candidate-box-prev{border-top-left-radius:5px;border-bottom-left-radius:5px}.hg-candidate-box-btn-active{color:#444} \ No newline at end of file diff --git a/build/css/index.css.map b/build/css/index.css.map deleted file mode 100644 index 929c03fdf..000000000 --- a/build/css/index.css.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"sources":["index.css","webpack://./node_modules/simple-keyboard/build/css/index.css","webpack://./webpack:/src/lib/components/Keyboard.css"],"names":[],"mappings":"AAAA;;;;;;;;;;EAUE;ACVF;;;;;;;;;;EAUE,CCNF,kBACE,UAAW,CACX,wBAAiB,CAAjB,qBAAiB,CAAjB,oBAAiB,CAAjB,gBAAiB,CACjB,qBAAsB,CACtB,eAAgB,CAChB,yBACF,CAEA,kCACE,mBACF,CAGA,mCACE,cAAe,CACf,SAAU,CACV,iBACF,CAEA,kBACE,oHAC+C,CAC/C,wBAAyB,CACzB,WAAY,CACZ,iBACF,CAEA,6BACE,oBAAqB,CACrB,WAEF,CAEA,0BACE,YACF,CAEA,2CACE,iBACF,CAMA,qGACE,gBACF,CAEA,yCACE,cACF,CAEA,+CACE,YACF,CAEA,6BACE,sCAA+C,CAC/C,WAAY,CACZ,iBAAkB,CAClB,qBAAsB,CACtB,WAAY,CACZ,eAAiB,CACjB,+BAAgC,CAChC,cAAe,CACf,YAAa,CACb,kBAAmB,CACnB,sBAAuB,CACvB,yCACF,CAEA,6CACE,kBACF,CAEA,+CACE,WAAY,CACZ,WAAY,CACZ,kBAAmB,CACnB,YAAa,CACb,sBACF,CAMA,oGACE,WACF,CAEA,+CACE,WACF,CAEA,2CACE,cACF,CAEA,yDACE,cACF,CAEA,+CACE,4BAAiC,CACjC,UACF,CAEA,+DACE,cACF,CAEA,4DACE,cACF","file":"index.css","sourcesContent":["/*!\n * \n * react-simple-keyboard v2.5.183\n * https://github.com/hodgef/react-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 */\n/*!\n * \n * simple-keyboard v2.32.128\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 */.hg-theme-default{width:100%;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;box-sizing:border-box;overflow:hidden;touch-action:manipulation}.hg-theme-default .hg-button span{pointer-events:none}.hg-theme-default button.hg-button{border-width:0;outline:0;font-size:inherit}.hg-theme-default{font-family:\"HelveticaNeue-Light\",\"Helvetica Neue Light\",\"Helvetica Neue\",Helvetica,Arial,\"Lucida Grande\",sans-serif;background-color:#ececec;padding:5px;border-radius:5px}.hg-theme-default .hg-button{display:inline-block;flex-grow:1}.hg-theme-default .hg-row{display:flex}.hg-theme-default .hg-row:not(:last-child){margin-bottom:5px}.hg-theme-default .hg-row .hg-button-container,.hg-theme-default .hg-row .hg-button:not(:last-child){margin-right:5px}.hg-theme-default .hg-row>div:last-child{margin-right:0}.hg-theme-default .hg-row .hg-button-container{display:flex}.hg-theme-default .hg-button{box-shadow:0 0 3px -1px rgba(0,0,0,.3);height:40px;border-radius:5px;box-sizing:border-box;padding:5px;background:#fff;border-bottom:1px solid #b5b5b5;cursor:pointer;display:flex;align-items:center;justify-content:center;-webkit-tap-highlight-color:rgba(0,0,0,0)}.hg-theme-default .hg-button.hg-activeButton{background:#efefef}.hg-theme-default.hg-layout-numeric .hg-button{width:33.3%;height:60px;align-items:center;display:flex;justify-content:center}.hg-theme-default .hg-button.hg-button-numpadadd,.hg-theme-default .hg-button.hg-button-numpadenter{height:85px}.hg-theme-default .hg-button.hg-button-numpad0{width:105px}.hg-theme-default .hg-button.hg-button-com{max-width:85px}.hg-theme-default .hg-button.hg-standardBtn.hg-button-at{max-width:45px}.hg-theme-default .hg-button.hg-selectedButton{background:rgba(5,25,70,.53);color:#fff}.hg-theme-default .hg-button.hg-standardBtn[data-skbtn=\".com\"]{max-width:82px}.hg-theme-default .hg-button.hg-standardBtn[data-skbtn=\"@\"]{max-width:60px}\n/*# sourceMappingURL=index.css.map */\n","/*!\n * \n * simple-keyboard v2.32.128\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 */\n/**\n * simple-keyboard\n * Theme: hg-theme-default\n */\n.hg-theme-default {\n width: 100%;\n -webkit-user-select: none;\n -moz-user-select: none;\n -ms-user-select: none;\n user-select: none;\n box-sizing: border-box;\n overflow: hidden;\n touch-action: manipulation;\n}\n\n.hg-theme-default .hg-button span {\n pointer-events: none;\n}\n\n/* When using option \"useButtonTag\" */\n.hg-theme-default button.hg-button {\n border-width: 0;\n outline: 0;\n font-size: inherit;\n}\n\n.hg-theme-default {\n font-family: \"HelveticaNeue-Light\", \"Helvetica Neue Light\", \"Helvetica Neue\",\n Helvetica, Arial, \"Lucida Grande\", sans-serif;\n background-color: #ececec;\n padding: 5px;\n border-radius: 5px;\n}\n\n.hg-theme-default .hg-button {\n display: inline-block;\n flex-grow: 1;\n cursor: pointer;\n}\n\n.hg-theme-default .hg-row {\n display: flex;\n}\n\n.hg-theme-default .hg-row:not(:last-child) {\n margin-bottom: 5px;\n}\n\n.hg-theme-default .hg-row .hg-button:not(:last-child) {\n margin-right: 5px;\n}\n\n.hg-theme-default .hg-row .hg-button-container {\n margin-right: 5px;\n}\n\n.hg-theme-default .hg-row > div:last-child {\n margin-right: 0;\n}\n\n.hg-theme-default .hg-row .hg-button-container {\n display: flex;\n}\n\n.hg-theme-default .hg-button {\n box-shadow: 0px 0px 3px -1px rgba(0, 0, 0, 0.3);\n height: 40px;\n border-radius: 5px;\n box-sizing: border-box;\n padding: 5px;\n background: white;\n border-bottom: 1px solid #b5b5b5;\n cursor: pointer;\n display: flex;\n align-items: center;\n justify-content: center;\n -webkit-tap-highlight-color: rgba(0, 0, 0, 0);\n}\n\n.hg-theme-default .hg-button.hg-activeButton {\n background: #efefef;\n}\n\n.hg-theme-default.hg-layout-numeric .hg-button {\n width: 33.3%;\n height: 60px;\n align-items: center;\n display: flex;\n justify-content: center;\n}\n\n.hg-theme-default .hg-button.hg-button-numpadadd {\n height: 85px;\n}\n\n.hg-theme-default .hg-button.hg-button-numpadenter {\n height: 85px;\n}\n\n.hg-theme-default .hg-button.hg-button-numpad0 {\n width: 105px;\n}\n\n.hg-theme-default .hg-button.hg-button-com {\n max-width: 85px;\n}\n\n.hg-theme-default .hg-button.hg-standardBtn.hg-button-at {\n max-width: 45px;\n}\n\n.hg-theme-default .hg-button.hg-selectedButton {\n background: rgba(5, 25, 70, 0.53);\n color: white;\n}\n\n.hg-theme-default .hg-button.hg-standardBtn[data-skbtn=\".com\"] {\n max-width: 82px;\n}\n\n.hg-theme-default .hg-button.hg-standardBtn[data-skbtn=\"@\"] {\n max-width: 60px;\n}\n\n","/**\n * simple-keyboard\n * Theme: hg-theme-default\n */\n.hg-theme-default {\n width: 100%;\n user-select: none;\n box-sizing: border-box;\n overflow: hidden;\n touch-action: manipulation;\n}\n\n.hg-theme-default .hg-button span {\n pointer-events: none;\n}\n\n/* When using option \"useButtonTag\" */\n.hg-theme-default button.hg-button {\n border-width: 0;\n outline: 0;\n font-size: inherit;\n}\n\n.hg-theme-default {\n font-family: \"HelveticaNeue-Light\", \"Helvetica Neue Light\", \"Helvetica Neue\",\n Helvetica, Arial, \"Lucida Grande\", sans-serif;\n background-color: #ececec;\n padding: 5px;\n border-radius: 5px;\n}\n\n.hg-theme-default .hg-button {\n display: inline-block;\n flex-grow: 1;\n cursor: pointer;\n}\n\n.hg-theme-default .hg-row {\n display: flex;\n}\n\n.hg-theme-default .hg-row:not(:last-child) {\n margin-bottom: 5px;\n}\n\n.hg-theme-default .hg-row .hg-button:not(:last-child) {\n margin-right: 5px;\n}\n\n.hg-theme-default .hg-row .hg-button-container {\n margin-right: 5px;\n}\n\n.hg-theme-default .hg-row > div:last-child {\n margin-right: 0;\n}\n\n.hg-theme-default .hg-row .hg-button-container {\n display: flex;\n}\n\n.hg-theme-default .hg-button {\n box-shadow: 0px 0px 3px -1px rgba(0, 0, 0, 0.3);\n height: 40px;\n border-radius: 5px;\n box-sizing: border-box;\n padding: 5px;\n background: white;\n border-bottom: 1px solid #b5b5b5;\n cursor: pointer;\n display: flex;\n align-items: center;\n justify-content: center;\n -webkit-tap-highlight-color: rgba(0, 0, 0, 0);\n}\n\n.hg-theme-default .hg-button.hg-activeButton {\n background: #efefef;\n}\n\n.hg-theme-default.hg-layout-numeric .hg-button {\n width: 33.3%;\n height: 60px;\n align-items: center;\n display: flex;\n justify-content: center;\n}\n\n.hg-theme-default .hg-button.hg-button-numpadadd {\n height: 85px;\n}\n\n.hg-theme-default .hg-button.hg-button-numpadenter {\n height: 85px;\n}\n\n.hg-theme-default .hg-button.hg-button-numpad0 {\n width: 105px;\n}\n\n.hg-theme-default .hg-button.hg-button-com {\n max-width: 85px;\n}\n\n.hg-theme-default .hg-button.hg-standardBtn.hg-button-at {\n max-width: 45px;\n}\n\n.hg-theme-default .hg-button.hg-selectedButton {\n background: rgba(5, 25, 70, 0.53);\n color: white;\n}\n\n.hg-theme-default .hg-button.hg-standardBtn[data-skbtn=\".com\"] {\n max-width: 82px;\n}\n\n.hg-theme-default .hg-button.hg-standardBtn[data-skbtn=\"@\"] {\n max-width: 60px;\n}\n"]} \ No newline at end of file diff --git a/build/index.d.ts b/build/index.d.ts deleted file mode 100644 index ef265503c..000000000 --- a/build/index.d.ts +++ /dev/null @@ -1,324 +0,0 @@ -declare module 'react-simple-keyboard' { - export interface KeyboardLayoutObject { - [key: string]: string[]; - } - - export interface KeyboardButtonTheme { - class: string; - buttons: string; - } - - export interface KeyboardButtonAttributes { - attribute: string; - value: string; - buttons: string; - } - - export interface KeyboardOptions { - /** - * Sets a personalized unique id - */ - baseClass?: string; - - /** - * Modify the keyboard layout. - */ - layout?: KeyboardLayoutObject; - - /** - * Specifies which layout should be used. - */ - layoutName?: string; - - /** - * Replaces variable buttons (such as `{bksp}`) with a human-friendly name (e.g.: `backspace`). - */ - display?: { [button: string]: string }; - - /** - * By default, when you set the display property, you replace the default one. This setting merges them instead. - */ - mergeDisplay?: boolean; - - /** - * A prop to add your own css classes to the keyboard wrapper. You can add multiple classes separated by a space. - */ - theme?: string; - - /** - * A prop to add your own css classes to one or several buttons. - */ - buttonTheme?: KeyboardButtonTheme[]; - - /** - * A prop to add your own attributes to one or several buttons. - */ - buttonAttributes?: KeyboardButtonAttributes[]; - - /** - * Runs a `console.log` every time a key is pressed. Displays the buttons pressed and the current input. - */ - debug?: boolean; - - /** - * Specifies whether clicking the "ENTER" button will input a newline (`\n`) or not. - */ - newLineOnEnter?: boolean; - - /** - * Specifies whether clicking the "TAB" button will input a tab character (`\t`) or not. - */ - tabCharOnTab?: boolean; - - /** - * Allows you to use a single simple-keyboard instance for several inputs. - */ - inputName?: string; - - /** - * `number`: Restrains all of simple-keyboard inputs to a certain length. This should be used in addition to the input element’s maxlengthattribute. - * - * `{ [inputName: string]: number }`: Restrains simple-keyboard’s individual inputs to a certain length. This should be used in addition to the input element’s maxlengthattribute. - */ - maxLength?: any; - - /** - * When set to true, this option synchronizes the internal input of every simple-keyboard instance. - */ - syncInstanceInputs?: boolean; - - /** - * Enable highlighting of keys pressed on physical keyboard. - */ - physicalKeyboardHighlight?: boolean; - - /** - * Calling preventDefault for the mousedown events keeps the focus on the input. - */ - preventMouseDownDefault?: boolean; - - /** - * Define the text color that the physical keyboard highlighted key should have. - */ - physicalKeyboardHighlightTextColor?: string; - - /** - * Define the background color that the physical keyboard highlighted key should have. - */ - physicalKeyboardHighlightBgColor?: string; - - /** - * Render buttons as a button element instead of a div element. - */ - useButtonTag?: boolean; - - /** - * A prop to ensure characters are always be added/removed at the end of the string. - */ - disableCaretPositioning?: boolean; - - /** - * Restrains input(s) change to the defined regular expression pattern. - */ - inputPattern?: any; - - /** - * Instructs simple-keyboard to use touch events instead of click events. - */ - useTouchEvents?: boolean; - - /** - * Enable useTouchEvents automatically when touch device is detected. - */ - autoUseTouchEvents?: boolean; - - /** - * Opt out of PointerEvents handling, falling back to the prior mouse event logic. - */ - useMouseEvents?: boolean; - - /** - * Disable button hold action. - */ - disableButtonHold?: boolean; - - /** - * Adds unicode right-to-left control characters to input return values. - */ - rtl?: boolean; - - /** - * keyboardRef - */ - keyboardRef?: (r: any) => void; - - /** - * Executes the callback function on key press. Returns button layout name (i.e.: "{shift}"). - */ - onKeyPress?: (button: string) => any; - - /** - * Executes the callback function on key release. - */ - onKeyReleased?: (button: string) => any; - - /** - * Executes the callback function on input change. Returns the current input's string. - */ - onChange?: (input: string) => any; - - /** - * Executes the callback function before the first simple-keyboard render. - */ - beforeFirstRender?: () => void; - - /** - * Executes the callback function before a simple-keyboard render. - */ - beforeRender?: () => void; - - /** - * Executes the callback function every time simple-keyboard is rendered (e.g: when you change layouts). - */ - onRender?: () => void; - - /** - * Executes the callback function once simple-keyboard is rendered for the first time (on initialization). - */ - onInit?: () => void; - - /** - * Executes the callback function on input change. Returns the input object with all defined inputs. - */ - onChangeAll?: (inputs: any) => any; - - /** - * Module classes to be loaded by simple-keyboard. - */ - modules?: any[]; - - /** - * Module options can have any format - */ - [name: string]: any; - } - - class KeyboardReact extends React.Component { - /** - * Keyboard instance - */ - constructor(options: KeyboardOptions); - - /** - * Options - */ - options: KeyboardOptions; - - /** - * Utilities - */ - utilities?: any; - - /** - * caretPosition - */ - caretPosition?: number; - - /** - * caretPositionEnd - */ - caretPositionEnd?: number; - - /** - * Changes the internal caret position - * @param {number} position The caret's start position - * @param {number} positionEnd The caret's end position - */ - setCaretPosition(position: number, positionEnd?: number): void; - - /** - * Retrieves the internal caret position - */ - getCaretPosition(): number; - - /** - * Retrieves the internal end caret position - */ - getCaretPositionEnd(): number; - - /** - * DOM Element - */ - keyboardDOM?: HTMLElement; - - /** - * Adds/Modifies an entry to the `buttonTheme`. Basically a way to add a class to a button. - * @param {string} buttons List of buttons to select (separated by a space). - * @param {string} className Classes to give to the selected buttons (separated by space). - */ - addButtonTheme(buttons: string, className: string): void; - - /** - * Removes/Amends an entry to the `buttonTheme`. Basically a way to remove a class previously added to a button through buttonTheme or addButtonTheme. - * @param {string} buttons List of buttons to select (separated by a space). - * @param {string} className Classes to give to the selected buttons (separated by space). - */ - removeButtonTheme(buttons: string, className: string): void; - - /** - * Clear the keyboard's input. - * - * @param {string} [inputName] optional - the internal input to select. - */ - clearInput(inputName?: string): void; - - /** - * Get the keyboard’s input (You can also get it from the onChange prop). - * @param {string} [inputName] optional - the internal input to select. - */ - getInput(inputName?: string): string; - - /** - * Set the keyboard’s input. - * @param {string} input the input value - * @param {string} inputName optional - the internal input to select. - */ - setInput(input: string, inputName?: string): void; - - /** - * Replaces the entire internal input object. - * @param {string} input the input object - */ - replaceInput(input: any): void; - - /** - * Set new option or modify existing ones after initialization. - * @param {KeyboardOptions} option The option to set - */ - setOptions(options: KeyboardOptions): void; - - /** - * Send a command to all simple-keyboard instances at once (if you have multiple instances). - * @param {function(instance: object, key: string)} callback Function to run on every instance - */ - dispatch(callback: (instance: any, key: string) => void): void; - - /** - * Get the DOM Element of a button. If there are several buttons with the same name, an array of the DOM Elements is returned. - * @param {string} button The button layout name to select. - */ - getButtonElement(button: string): HTMLElement | HTMLElement[]; - - /** - * Clears keyboard listeners and DOM elements. - */ - destroy(): void; - - /** - * Iterate on each button (ForEach) - */ - recurseButtons(fn: any): void; - } - - export default KeyboardReact; -} diff --git a/build/index.js b/build/index.js index 2b858f649..cdbade35f 100644 --- a/build/index.js +++ b/build/index.js @@ -1,13 +1,36 @@ /*! * - * react-simple-keyboard v2.5.183 + * react-simple-keyboard v3.0.0-beta.1 * https://github.com/hodgef/react-simple-keyboard - * - * Copyright (c) Francisco Hodge (https://github.com/hodgef) - * + * + * Copyright (c) Francisco Hodge (https://github.com/hodgef) and project contributors. + * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. - * + * */ -!function(t,e){"object"===typeof exports&&"object"===typeof module?module.exports=e(require("react")):"function"===typeof define&&define.amd?define("ReactSimpleKeyboard",["react"],e):"object"===typeof exports?exports.ReactSimpleKeyboard=e(require("react")):t.ReactSimpleKeyboard=e(t.React)}(this,(function(t){return function(t){var e={};function __webpack_require__(n){if(e[n])return e[n].exports;var o=e[n]={i:n,l:!1,exports:{}};return t[n].call(o.exports,o,o.exports,__webpack_require__),o.l=!0,o.exports}return __webpack_require__.m=t,__webpack_require__.c=e,__webpack_require__.d=function(t,e,n){__webpack_require__.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},__webpack_require__.r=function(t){"undefined"!==typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},__webpack_require__.t=function(t,e){if(1&e&&(t=__webpack_require__(t)),8&e)return t;if(4&e&&"object"===typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(__webpack_require__.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var o in t)__webpack_require__.d(n,o,function(e){return t[e]}.bind(null,o));return n},__webpack_require__.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return __webpack_require__.d(e,"a",e),e},__webpack_require__.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},__webpack_require__.p="/",__webpack_require__(__webpack_require__.s=3)}([function(e,n){e.exports=t},function(t,e,n){(function(t){var o,i,r,s,a=n(5);s=function(){return function(t){var e={};function __webpack_require__(n){if(e[n])return e[n].exports;var o=e[n]={i:n,l:!1,exports:{}};return t[n].call(o.exports,o,o.exports,__webpack_require__),o.l=!0,o.exports}return __webpack_require__.m=t,__webpack_require__.c=e,__webpack_require__.d=function(t,e,n){__webpack_require__.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},__webpack_require__.r=function(t){"undefined"!==typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},__webpack_require__.t=function(t,e){if(1&e&&(t=__webpack_require__(t)),8&e)return t;if(4&e&&"object"===a(t)&&t&&t.__esModule)return t;var n=Object.create(null);if(__webpack_require__.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var o in t)__webpack_require__.d(n,o,function(e){return t[e]}.bind(null,o));return n},__webpack_require__.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return __webpack_require__.d(e,"a",e),e},__webpack_require__.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},__webpack_require__.p="/",__webpack_require__(__webpack_require__.s=0)}([function(t,e,n){t.exports=n(1)},function(t,e,n){"use strict";function _arrayLikeToArray(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,o=new Array(e);n=t.length?{done:!0}:{done:!1,value:t[o++]}},e:function(t){throw t},f:F}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,r=!0,s=!1;return{s:function(){n=t[Symbol.iterator]()},n:function(){var t=n.next();return r=t.done,t},e:function(t){s=!0,i=t},f:function(){try{r||null==n.return||n.return()}finally{if(s)throw i}}}}(Object.getOwnPropertyNames(t.prototype));try{for(o.s();!(n=o.n()).done;){var i=n.value;"constructor"===i||"bindMethods"===i||(e[i]=e[i].bind(e))}}catch(r){o.e(r)}finally{o.f()}}}],(e=[{key:"getButtonClass",value:function(t){var e=t.includes("{")&&t.includes("}")&&"{//}"!==t?"functionBtn":"standardBtn",n=t.replace("{","").replace("}",""),o="";return"standardBtn"!==e&&(o=" hg-button-".concat(n)),"hg-".concat(e).concat(o)}},{key:"getDefaultDiplay",value:function(){return{"{bksp}":"backspace","{backspace}":"backspace","{enter}":"< enter","{shift}":"shift","{shiftleft}":"shift","{shiftright}":"shift","{alt}":"alt","{s}":"shift","{tab}":"tab","{lock}":"caps","{capslock}":"caps","{accept}":"Submit","{space}":" ","{//}":" ","{esc}":"esc","{escape}":"esc","{f1}":"f1","{f2}":"f2","{f3}":"f3","{f4}":"f4","{f5}":"f5","{f6}":"f6","{f7}":"f7","{f8}":"f8","{f9}":"f9","{f10}":"f10","{f11}":"f11","{f12}":"f12","{numpaddivide}":"/","{numlock}":"lock","{arrowup}":"\u2191","{arrowleft}":"\u2190","{arrowdown}":"\u2193","{arrowright}":"\u2192","{prtscr}":"print","{scrolllock}":"scroll","{pause}":"pause","{insert}":"ins","{home}":"home","{pageup}":"up","{delete}":"del","{end}":"end","{pagedown}":"down","{numpadmultiply}":"*","{numpadsubtract}":"-","{numpadadd}":"+","{numpadenter}":"enter","{period}":".","{numpaddecimal}":".","{numpad0}":"0","{numpad1}":"1","{numpad2}":"2","{numpad3}":"3","{numpad4}":"4","{numpad5}":"5","{numpad6}":"6","{numpad7}":"7","{numpad8}":"8","{numpad9}":"9"}}},{key:"getButtonDisplayName",value:function(t,e,n){return(e=n?Object.assign({},this.getDefaultDiplay(),e):e||this.getDefaultDiplay())[t]||t}},{key:"getUpdatedInput",value:function(t,e,n){var o=arguments.length>3&&void 0!==arguments[3]?arguments[3]:n,i=arguments.length>4&&void 0!==arguments[4]&&arguments[4],r=this.getOptions(),s=[n,o,i],a=e;return("{bksp}"===t||"{backspace}"===t)&&a.length>0?a=this.removeAt.apply(this,[a].concat(s)):"{space}"===t?a=this.addStringAt.apply(this,[a," "].concat(s)):"{tab}"!==t||"boolean"===typeof r.tabCharOnTab&&!1===r.tabCharOnTab?"{enter}"!==t&&"{numpadenter}"!==t||!r.newLineOnEnter?t.includes("numpad")&&Number.isInteger(Number(t[t.length-2]))?a=this.addStringAt.apply(this,[a,t[t.length-2]].concat(s)):"{numpaddivide}"===t?a=this.addStringAt.apply(this,[a,"/"].concat(s)):"{numpadmultiply}"===t?a=this.addStringAt.apply(this,[a,"*"].concat(s)):"{numpadsubtract}"===t?a=this.addStringAt.apply(this,[a,"-"].concat(s)):"{numpadadd}"===t?a=this.addStringAt.apply(this,[a,"+"].concat(s)):"{numpaddecimal}"===t?a=this.addStringAt.apply(this,[a,"."].concat(s)):"{"===t||"}"===t?a=this.addStringAt.apply(this,[a,t].concat(s)):t.includes("{")||t.includes("}")||(a=this.addStringAt.apply(this,[a,t].concat(s))):a=this.addStringAt.apply(this,[a,"\n"].concat(s)):a=this.addStringAt.apply(this,[a,"\t"].concat(s)),a}},{key:"updateCaretPos",value:function(t,e){var n=this.updateCaretPosAction(t,e);this.dispatch((function(t){t.setCaretPosition(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){var n,o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:t.length,i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:t.length,r=arguments.length>4&&void 0!==arguments[4]&&arguments[4];return o||0===o?(n=[t.slice(0,o),e,t.slice(i)].join(""),this.isMaxLengthReached()||r&&this.updateCaretPos(e.length)):n=t+e,n}},{key:"removeAt",value:function(t){var e,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:t.length,o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:t.length,i=arguments.length>3&&void 0!==arguments[3]&&arguments[3];if(0===n&&0===o)return t;if(n===o){var r=/([\uD800-\uDBFF][\uDC00-\uDFFF])/g;n&&n>=0?t.substring(n-2,n).match(r)?(e=t.substr(0,n-2)+t.substr(n),i&&this.updateCaretPos(2,!0)):(e=t.substr(0,n-1)+t.substr(n),i&&this.updateCaretPos(1,!0)):t.slice(-2).match(r)?(e=t.slice(0,-2),i&&this.updateCaretPos(2,!0)):(e=t.slice(0,-1),i&&this.updateCaretPos(1,!0))}else e=t.slice(0,n)+t.slice(o),i&&this.dispatch((function(t){t.setCaretPosition(n)}));return e}},{key:"handleMaxLength",value:function(t,e){var n=this.getOptions(),o=n.maxLength,i=t[n.inputName],r=e.length-1>=o;if(e.length<=i.length)return!1;if(Number.isInteger(o))return n.debug&&console.log("maxLength (num) reached:",r),r?(this.maxLengthReached=!0,!0):(this.maxLengthReached=!1,!1);if("object"===_typeof(o)){var s=e.length-1>=o[n.inputName];return n.debug&&console.log("maxLength (obj) reached:",s),s?(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}))}}])&&_defineProperties(t.prototype,e),n&&_defineProperties(t,n),Utilities}();r=function(){},(i="noop")in(o=s)?Object.defineProperty(o,i,{value:r,enumerable:!0,configurable:!0,writable:!0}):o[i]=r;var u=s;function PhysicalKeyboard_defineProperties(t,e){for(var n=0;nt.length)&&(e=t.length);for(var n=0,o=new Array(e);n0&&void 0!==arguments[0]?arguments[0]:null,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;n&&(this.options.preventMouseUpDefault&&n.preventDefault(),this.options.stopMouseUpPropagation&&n.stopPropagation()),this.recurseButtons((function(e){e.classList.remove(t.activeButtonClass)})),this.isMouseHold=!1,this.holdInteractionTimeout&&clearTimeout(this.holdInteractionTimeout),e&&"function"===typeof this.options.onKeyReleased&&this.options.onKeyReleased(e)}},{key:"handleKeyboardContainerMouseDown",value:function(t){this.options.preventMouseDownDefault&&t.preventDefault()}},{key:"handleButtonHold",value:function(t){var e=this;this.holdInteractionTimeout&&clearTimeout(this.holdInteractionTimeout),this.holdInteractionTimeout=setTimeout((function(){e.isMouseHold?(e.handleButtonClicked(t),e.handleButtonHold(t)):clearTimeout(e.holdInteractionTimeout)}),100)}},{key:"syncInstanceInputs",value:function(){var t=this;this.dispatch((function(e){e.replaceInput(t.input),e.setCaretPosition(t.caretPosition,t.caretPositionEnd)}))}},{key:"clearInput",value:function(t){t=t||this.options.inputName,this.input[t]="",this.setCaretPosition(0),this.options.syncInstanceInputs&&this.syncInstanceInputs()}},{key:"getInput",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]&&arguments[1];if(t=t||this.options.inputName,this.options.syncInstanceInputs&&!e&&this.syncInstanceInputs(),this.options.rtl){var n=this.input[t].replace("\u202b","").replace("\u202c","");return"\u202b"+n+"\u202c"}return this.input[t]}},{key:"getAllInputs",value:function(){var t=this,e={};return Object.keys(this.input).forEach((function(n){e[n]=t.getInput(n,!0)})),e}},{key:"setInput",value:function(t,e){e=e||this.options.inputName,this.input[e]=t,this.options.syncInstanceInputs&&this.syncInstanceInputs()}},{key:"replaceInput",value:function(t){this.input=t}},{key:"setOptions",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e=this.changedOptions(t);this.options=Object.assign(this.options,t),e.length&&(this.options.debug&&console.log("changedOptions",e),this.onSetOptions(t),this.render())}},{key:"changedOptions",value:function(t){var e=this;return Object.keys(t).filter((function(n){return JSON.stringify(t[n])!==JSON.stringify(e.options[n])}))}},{key:"onSetOptions",value:function(t){t.inputName&&(this.options.debug&&console.log("inputName changed. caretPosition reset."),this.setCaretPosition(null))}},{key:"clear",value:function(){this.keyboardDOM.innerHTML="",this.keyboardDOM.className=this.keyboardDOMClass,this.buttonElements={}}},{key:"dispatch",value:function(t){if(!window.SimpleKeyboardInstances)throw console.warn("SimpleKeyboardInstances is not defined. Dispatch cannot be called."),new Error("INSTANCES_VAR_ERROR");return Object.keys(window.SimpleKeyboardInstances).forEach((function(e){t(window.SimpleKeyboardInstances[e],e)}))}},{key:"addButtonTheme",value:function(t,e){var n=this;if(!e||!t)return!1;t.split(" ").forEach((function(o){e.split(" ").forEach((function(e){n.options.buttonTheme||(n.options.buttonTheme=[]);var i=!1;n.options.buttonTheme.map((function(t){if(t.class.split(" ").includes(e)){i=!0;var n=t.buttons.split(" ");n.includes(o)||(i=!0,n.push(o),t.buttons=n.join(" "))}return t})),i||n.options.buttonTheme.push({class:e,buttons:t})}))})),this.render()}},{key:"removeButtonTheme",value:function(t,e){var n=this;if(!t&&!e)return this.options.buttonTheme=[],this.render(),!1;t&&Array.isArray(this.options.buttonTheme)&&this.options.buttonTheme.length&&(t.split(" ").forEach((function(t){n.options.buttonTheme.map((function(o,i){if(e&&e.includes(o.class)||!e){var r=o.buttons.split(" ").filter((function(e){return e!==t}));r.length?o.buttons=r.join(" "):(n.options.buttonTheme.splice(i,1),o=null)}return o}))})),this.render())}},{key:"getButtonElement",value:function(t){var e,n=this.buttonElements[t];return n&&(e=n.length>1?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){var o=t.target===n.keyboardDOM||t.target&&n.keyboardDOM.contains(t.target);n.isMouseHold&&(n.isMouseHold=!1),"textarea"!==e&&"input"!==e||!["text","search","url","tel","password"].includes(t.target.type)||n.options.disableCaretPositioning?!n.options.disableCaretPositioning&&o||n.setCaretPosition(null):(n.setCaretPosition(t.target.selectionStart,t.target.selectionEnd),n.options.debug&&console.log("Caret at: ",n.getCaretPosition(),n.getCaretPositionEnd(),t&&t.target.tagName.toLowerCase(),"(".concat(n.keyboardDOMClass,")")))}))}},{key:"recurseButtons",value:function(t){var e=this;t&&Object.keys(this.buttonElements).forEach((function(n){return e.buttonElements[n].forEach(t)}))}},{key:"destroy",value:function(){this.options.debug&&console.log("Destroying simple-keyboard instance: ".concat(this.currentInstanceName)),document.removeEventListener("keyup",this.handleKeyUp),document.removeEventListener("keydown",this.handleKeyDown),document.removeEventListener("mouseup",this.handleMouseUp),document.removeEventListener("touchend",this.handleTouchEnd),document.onpointerup=null,document.ontouchend=null,document.ontouchcancel=null,document.onmouseup=null;var deleteButton=function(t){t.onpointerdown=null,t.onpointerup=null,t.onpointercancel=null,t.ontouchstart=null,t.ontouchend=null,t.ontouchcancel=null,t.onclick=null,t.onmousedown=null,t.onmouseup=null,t.remove(),t=null};this.recurseButtons(deleteButton),this.recurseButtons=null,deleteButton=null,this.keyboardDOM.onpointerdown=null,this.keyboardDOM.ontouchstart=null,this.keyboardDOM.onmousedown=null,this.clear(),window.SimpleKeyboardInstances[this.currentInstanceName]=null,delete window.SimpleKeyboardInstances[this.currentInstanceName],this.initialized=!1}},{key:"getButtonThemeClasses",value:function(t){var e=this.options.buttonTheme,n=[];return Array.isArray(e)&&e.forEach((function(e){if(e.class&&"string"===typeof e.class&&e.buttons&&"string"===typeof e.buttons){var o=e.class.split(" ");e.buttons.split(" ").includes(t)&&(n=[].concat(_toConsumableArray(n),_toConsumableArray(o)))}else console.warn('Incorrect "buttonTheme". Please check the documentation.',e)})),n}},{key:"setDOMButtonAttributes",value:function(t,e){var n=this.options.buttonAttributes;Array.isArray(n)&&n.forEach((function(n){n.attribute&&"string"===typeof n.attribute&&n.value&&"string"===typeof n.value&&n.buttons&&"string"===typeof n.buttons?n.buttons.split(" ").includes(t)&&e(n.attribute,n.value):console.warn('Incorrect "buttonAttributes". Please check the documentation.',n)}))}},{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(this)}},{key:"loadModules",value:function(){var t=this;Array.isArray(this.options.modules)&&(this.options.modules.forEach((function(e){(new e).init(t)})),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,r=Array.from(t.children),s=0;return r.length&&n.forEach((function(n,a){var u=o[a];if(!u||!(u>n))return!1;var c=n-s,l=u-s,p=document.createElement("div");p.className+="hg-button-container";var h="".concat(i.options.layoutName,"-r").concat(e,"c").concat(a);p.setAttribute("data-skUID",h);var d=r.splice(c,l-c+1);s=l-c,d.forEach((function(t){return p.appendChild(t)})),r.splice(c,0,p),t.innerHTML="",r.forEach((function(e){return t.appendChild(e)})),i.options.debug&&console.log("rowDOMContainer",d,c,l,s+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||{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}"]},o=this.options.useTouchEvents||!1,i=o?"hg-touch-events":"",r=this.options.useMouseEvents||!1,s=this.options.disableRowButtonContainers;this.keyboardDOM.className=this.getKeyboardClassString(this.options.theme,e,this.keyboardPluginClasses,i),n[this.options.layoutName].forEach((function(e,n){var i=e.split(" "),a=document.createElement("div");a.className+="hg-row";var u=[],c=[];i.forEach((function(e,i){var l,p=!s&&"string"===typeof e&&e.length>1&&0===e.indexOf("["),h=!s&&"string"===typeof e&&e.length>1&&e.indexOf("]")===e.length-1;p&&(u.push(i),e=e.replace(/\[/g,"")),h&&(c.push(i),e=e.replace(/\]/g,""));var d=t.utilities.getButtonClass(e),f=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(d),(l=b.classList).add.apply(l,_toConsumableArray(t.getButtonThemeClasses(e))),t.setDOMButtonAttributes(e,(function(t,e){b.setAttribute(t,e)})),t.activeButtonClass="hg-activeButton",!t.utilities.pointerEventsSupported()||o||r?o?(b.ontouchstart=function(n){t.handleButtonClicked(e),t.handleButtonMouseDown(e,n)},b.ontouchend=function(n){t.handleButtonMouseUp(e,n)},b.ontouchcancel=function(n){t.handleButtonMouseUp(e,n)}):(b.onclick=function(){t.isMouseHold=!1,t.handleButtonClicked(e)},b.onmousedown=function(n){t.handleButtonMouseDown(e,n)},b.onmouseup=function(n){t.handleButtonMouseUp(e,n)}):(b.onpointerdown=function(n){t.handleButtonClicked(e),t.handleButtonMouseDown(e,n)},b.onpointerup=function(n){t.handleButtonMouseUp(e,n)},b.onpointercancel=function(n){t.handleButtonMouseUp(e,n)}),b.setAttribute("data-skBtn",e);var m="".concat(t.options.layoutName,"-r").concat(n,"b").concat(i);b.setAttribute("data-skBtnUID",m);var g=document.createElement("span");g.innerHTML=f,b.appendChild(g),t.buttonElements[e]||(t.buttonElements[e]=[]),t.buttonElements[e].push(b),a.appendChild(b)})),a=t.parseRowDOMContainers(a,n,u,c),t.keyboardDOM.appendChild(a)})),this.onRender(),this.initialized||(this.initialized=!0,!this.utilities.pointerEventsSupported()||o||r?o?(document.ontouchend=function(){return t.handleButtonMouseUp()},document.ontouchcancel=function(){return t.handleButtonMouseUp()},this.keyboardDOM.ontouchstart=function(e){return t.handleKeyboardContainerMouseDown(e)}):o||(document.onmouseup=function(){return t.handleButtonMouseUp()},this.keyboardDOM.onmousedown=function(e){return t.handleKeyboardContainerMouseDown(e)}):(document.onpointerup=function(){return t.handleButtonMouseUp()},this.keyboardDOM.onpointerdown=function(e){return t.handleKeyboardContainerMouseDown(e)}),this.onInit())}}])&&Keyboard_defineProperties(t.prototype,e),SimpleKeyboard}();e.default=l}])},"object"===a(e)&&"object"===a(t)?t.exports=s():(i=[],void 0===(r="function"===typeof(o=s)?o.apply(e,i):o)||(t.exports=r))}).call(this,n(4)(t))},function(t,e,n){t.exports=n(6)()},function(t,e,n){t.exports=n(8)},function(t,e){t.exports=function(t){return t.webpackPolyfill||(t.deprecate=function(){},t.paths=[],t.children||(t.children=[]),Object.defineProperty(t,"loaded",{enumerable:!0,get:function(){return t.l}}),Object.defineProperty(t,"id",{enumerable:!0,get:function(){return t.i}}),t.webpackPolyfill=1),t}},function(t,e){function _typeof(e){return"function"===typeof Symbol&&"symbol"===typeof Symbol.iterator?t.exports=_typeof=function(t){return typeof t}:t.exports=_typeof=function(t){return t&&"function"===typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},_typeof(e)}t.exports=_typeof},function(t,e,n){"use strict";var o=n(7);function emptyFunction(){}function emptyFunctionWithReset(){}emptyFunctionWithReset.resetWarningCache=emptyFunction,t.exports=function(){function shim(t,e,n,i,r,s){if(s!==o){var a=new Error("Calling PropTypes validators directly is not supported by the `prop-types` package. Use PropTypes.checkPropTypes() to call them. Read more at http://fb.me/use-check-prop-types");throw a.name="Invariant Violation",a}}function getShim(){return shim}shim.isRequired=shim;var t={array:shim,bool:shim,func:shim,number:shim,object:shim,string:shim,symbol:shim,any:shim,arrayOf:getShim,element:shim,elementType:shim,instanceOf:getShim,node:shim,objectOf:getShim,oneOf:getShim,oneOfType:getShim,shape:getShim,exact:getShim,checkPropTypes:emptyFunctionWithReset,resetWarningCache:emptyFunction};return t.PropTypes=t,t}},function(t,e,n){"use strict";t.exports="SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED"},function(t,e,n){"use strict";n.r(e);var o=n(0),i=n.n(o),r=n(1),s=n.n(r);function ownKeys(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(t);e&&(o=o.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.push.apply(n,o)}return n}function _objectSpread(t){for(var e=1;e1?arguments[1]:void 0)}},8457:function(t,e,n){"use strict";var o=n(9974),r=n(7908),i=n(3411),a=n(7659),s=n(7466),u=n(6135),c=n(1246);t.exports=function(t){var e,n,l,f,p,d,h=r(t),y="function"==typeof this?this:Array,v=arguments.length,g=v>1?arguments[1]:void 0,m=void 0!==g,b=c(h),x=0;if(m&&(g=o(g,v>2?arguments[2]:void 0,2)),null==b||y==Array&&a(b))for(n=new y(e=s(h.length));e>x;x++)d=m?g(h[x],x):h[x],u(n,x,d);else for(p=(f=b.call(h)).next,n=new y;!(l=p.call(f)).done;x++)d=m?i(f,g,[l.value,x],!0):l.value,u(n,x,d);return n.length=x,n}},1318:function(t,e,n){var o=n(5656),r=n(7466),i=n(1400),a=function(t){return function(e,n,a){var s,u=o(e),c=r(u.length),l=i(a,c);if(t&&n!=n){for(;c>l;)if((s=u[l++])!=s)return!0}else for(;c>l;l++)if((t||l in u)&&u[l]===n)return t||l||0;return!t&&-1}};t.exports={includes:a(!0),indexOf:a(!1)}},2092:function(t,e,n){var o=n(9974),r=n(8361),i=n(7908),a=n(7466),s=n(5417),u=[].push,c=function(t){var e=1==t,n=2==t,c=3==t,l=4==t,f=6==t,p=7==t,d=5==t||f;return function(h,y,v,g){for(var m,b,x=i(h),w=r(x),O=o(y,v,3),E=a(w.length),S=0,k=g||s,P=e?k(h,E):n||p?k(h,0):void 0;E>S;S++)if((d||S in w)&&(b=O(m=w[S],S,x),t))if(e)P[S]=b;else if(b)switch(t){case 3:return!0;case 5:return m;case 6:return S;case 2:u.call(P,m)}else switch(t){case 4:return!1;case 7:u.call(P,m)}return f?-1:c||l?l:P}};t.exports={forEach:c(0),map:c(1),filter:c(2),some:c(3),every:c(4),find:c(5),findIndex:c(6),filterOut:c(7)}},1194:function(t,e,n){var o=n(7293),r=n(5112),i=n(7392),a=r("species");t.exports=function(t){return i>=51||!o((function(){var e=[];return(e.constructor={})[a]=function(){return{foo:1}},1!==e[t](Boolean).foo}))}},9341:function(t,e,n){"use strict";var o=n(7293);t.exports=function(t,e){var n=[][t];return!!n&&o((function(){n.call(null,e||function(){throw 1},1)}))}},3671:function(t,e,n){var o=n(3099),r=n(7908),i=n(8361),a=n(7466),s=function(t){return function(e,n,s,u){o(n);var c=r(e),l=i(c),f=a(c.length),p=t?f-1:0,d=t?-1:1;if(s<2)for(;;){if(p in l){u=l[p],p+=d;break}if(p+=d,t?p<0:f<=p)throw TypeError("Reduce of empty array with no initial value")}for(;t?p>=0:f>p;p+=d)p in l&&(u=n(u,l[p],p,c));return u}};t.exports={left:s(!1),right:s(!0)}},5417:function(t,e,n){var o=n(111),r=n(3157),i=n(5112)("species");t.exports=function(t,e){var n;return r(t)&&("function"!=typeof(n=t.constructor)||n!==Array&&!r(n.prototype)?o(n)&&null===(n=n[i])&&(n=void 0):n=void 0),new(void 0===n?Array:n)(0===e?0:e)}},3411:function(t,e,n){var o=n(9670),r=n(9212);t.exports=function(t,e,n,i){try{return i?e(o(n)[0],n[1]):e(n)}catch(e){throw r(t),e}}},7072:function(t,e,n){var o=n(5112)("iterator"),r=!1;try{var i=0,a={next:function(){return{done:!!i++}},return:function(){r=!0}};a[o]=function(){return this},Array.from(a,(function(){throw 2}))}catch(t){}t.exports=function(t,e){if(!e&&!r)return!1;var n=!1;try{var i={};i[o]=function(){return{next:function(){return{done:n=!0}}}},t(i)}catch(t){}return n}},4326:function(t){var e={}.toString;t.exports=function(t){return e.call(t).slice(8,-1)}},648:function(t,e,n){var o=n(1694),r=n(4326),i=n(5112)("toStringTag"),a="Arguments"==r(function(){return arguments}());t.exports=o?r:function(t){var e,n,o;return void 0===t?"Undefined":null===t?"Null":"string"==typeof(n=function(t,e){try{return t[e]}catch(t){}}(e=Object(t),i))?n:a?r(e):"Object"==(o=r(e))&&"function"==typeof e.callee?"Arguments":o}},9920:function(t,e,n){var o=n(6656),r=n(3887),i=n(1236),a=n(3070);t.exports=function(t,e){for(var n=r(e),s=a.f,u=i.f,c=0;c=74)&&(o=a.match(/Chrome\/(\d+)/))&&(r=o[1]),t.exports=r&&+r},748:function(t){t.exports=["constructor","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","toLocaleString","toString","valueOf"]},2109:function(t,e,n){var o=n(7854),r=n(1236).f,i=n(8880),a=n(1320),u=n(3505),c=n(9920),l=n(4705);t.exports=function(t,e){var n,f,p,d,h,y=t.target,v=t.global,g=t.stat;if(n=v?o:g?o[y]||u(y,{}):(o[y]||{}).prototype)for(f in e){if(d=e[f],p=t.noTargetGet?(h=r(n,f))&&h.value:n[f],!l(v?f:y+(g?".":"#")+f,t.forced)&&void 0!==p){if(s(d)==s(p))continue;c(d,p)}(t.sham||p&&p.sham)&&i(d,"sham",!0),a(n,f,d,t)}}},7293:function(t){t.exports=function(t){try{return!!t()}catch(t){return!0}}},7007:function(t,e,n){"use strict";n(4916);var o=n(1320),r=n(7293),i=n(5112),a=n(2261),s=n(8880),u=i("species"),c=!r((function(){var t=/./;return t.exec=function(){var t=[];return t.groups={a:"7"},t},"7"!=="".replace(t,"$")})),l="$0"==="a".replace(/./,"$0"),f=i("replace"),p=!!/./[f]&&""===/./[f]("a","$0"),d=!r((function(){var t=/(?:)/,e=t.exec;t.exec=function(){return e.apply(this,arguments)};var n="ab".split(t);return 2!==n.length||"a"!==n[0]||"b"!==n[1]}));t.exports=function(t,e,n,f){var h=i(t),y=!r((function(){var e={};return e[h]=function(){return 7},7!=""[t](e)})),v=y&&!r((function(){var e=!1,n=/a/;return"split"===t&&((n={}).constructor={},n.constructor[u]=function(){return n},n.flags="",n[h]=/./[h]),n.exec=function(){return e=!0,null},n[h](""),!e}));if(!y||!v||"replace"===t&&(!c||!l||p)||"split"===t&&!d){var g=/./[h],m=n(h,""[t],(function(t,e,n,o,r){return e.exec===a?y&&!r?{done:!0,value:g.call(e,n,o)}:{done:!0,value:t.call(n,e,o)}:{done:!1}}),{REPLACE_KEEPS_$0:l,REGEXP_REPLACE_SUBSTITUTES_UNDEFINED_CAPTURE:p}),b=m[0],x=m[1];o(String.prototype,t,b),o(RegExp.prototype,h,2==e?function(t,e){return x.call(t,this,e)}:function(t){return x.call(t,this)})}f&&s(RegExp.prototype[h],"sham",!0)}},9974:function(t,e,n){var o=n(3099);t.exports=function(t,e,n){if(o(t),void 0===e)return t;switch(n){case 0:return function(){return t.call(e)};case 1:return function(n){return t.call(e,n)};case 2:return function(n,o){return t.call(e,n,o)};case 3:return function(n,o,r){return t.call(e,n,o,r)}}return function(){return t.apply(e,arguments)}}},5005:function(t,e,n){var o=n(857),r=n(7854),i=function(t){return"function"==typeof t?t:void 0};t.exports=function(t,e){return arguments.length<2?i(o[t])||i(r[t]):o[t]&&o[t][e]||r[t]&&r[t][e]}},1246:function(t,e,n){var o=n(648),r=n(7497),i=n(5112)("iterator");t.exports=function(t){if(null!=t)return t[i]||t["@@iterator"]||r[o(t)]}},647:function(t,e,n){var o=n(7908),r=Math.floor,i="".replace,a=/\$([$&'`]|\d{1,2}|<[^>]*>)/g,s=/\$([$&'`]|\d{1,2})/g;t.exports=function(t,e,n,u,c,l){var f=n+t.length,p=u.length,d=s;return void 0!==c&&(c=o(c),d=a),i.call(l,d,(function(o,i){var a;switch(i.charAt(0)){case"$":return"$";case"&":return t;case"`":return e.slice(0,n);case"'":return e.slice(f);case"<":a=c[i.slice(1,-1)];break;default:var s=+i;if(0===s)return o;if(s>p){var l=r(s/10);return 0===l?o:l<=p?void 0===u[l-1]?i.charAt(1):u[l-1]+i.charAt(1):o}a=u[s-1]}return void 0===a?"":a}))}},7854:function(t,e,n){var o=function(t){return t&&t.Math==Math&&t};t.exports=o("object"==("undefined"==typeof globalThis?"undefined":s(globalThis))&&globalThis)||o("object"==("undefined"==typeof window?"undefined":s(window))&&window)||o("object"==("undefined"==typeof self?"undefined":s(self))&&self)||o("object"==s(n.g)&&n.g)||function(){return this}()||Function("return this")()},6656:function(t){var e={}.hasOwnProperty;t.exports=function(t,n){return e.call(t,n)}},3501:function(t){t.exports={}},490:function(t,e,n){var o=n(5005);t.exports=o("document","documentElement")},4664:function(t,e,n){var o=n(9781),r=n(7293),i=n(317);t.exports=!o&&!r((function(){return 7!=Object.defineProperty(i("div"),"a",{get:function(){return 7}}).a}))},8361:function(t,e,n){var o=n(7293),r=n(4326),i="".split;t.exports=o((function(){return!Object("z").propertyIsEnumerable(0)}))?function(t){return"String"==r(t)?i.call(t,""):Object(t)}:Object},9587:function(t,e,n){var o=n(111),r=n(7674);t.exports=function(t,e,n){var i,a;return r&&"function"==typeof(i=e.constructor)&&i!==n&&o(a=i.prototype)&&a!==n.prototype&&r(t,a),t}},2788:function(t,e,n){var o=n(5465),r=Function.toString;"function"!=typeof o.inspectSource&&(o.inspectSource=function(t){return r.call(t)}),t.exports=o.inspectSource},9909:function(t,e,n){var o,r,i,a=n(8536),s=n(7854),u=n(111),c=n(8880),l=n(6656),f=n(5465),p=n(6200),d=n(3501),h=s.WeakMap;if(a){var y=f.state||(f.state=new h),v=y.get,g=y.has,m=y.set;o=function(t,e){return e.facade=t,m.call(y,t,e),e},r=function(t){return v.call(y,t)||{}},i=function(t){return g.call(y,t)}}else{var b=p("state");d[b]=!0,o=function(t,e){return e.facade=t,c(t,b,e),e},r=function(t){return l(t,b)?t[b]:{}},i=function(t){return l(t,b)}}t.exports={set:o,get:r,has:i,enforce:function(t){return i(t)?r(t):o(t,{})},getterFor:function(t){return function(e){var n;if(!u(e)||(n=r(e)).type!==t)throw TypeError("Incompatible receiver, "+t+" required");return n}}}},7659:function(t,e,n){var o=n(5112),r=n(7497),i=o("iterator"),a=Array.prototype;t.exports=function(t){return void 0!==t&&(r.Array===t||a[i]===t)}},3157:function(t,e,n){var o=n(4326);t.exports=Array.isArray||function(t){return"Array"==o(t)}},4705:function(t,e,n){var o=n(7293),r=/#|\.prototype\./,i=function(t,e){var n=s[a(t)];return n==c||n!=u&&("function"==typeof e?o(e):!!e)},a=i.normalize=function(t){return String(t).replace(r,".").toLowerCase()},s=i.data={},u=i.NATIVE="N",c=i.POLYFILL="P";t.exports=i},8730:function(t,e,n){var o=n(111),r=Math.floor;t.exports=function(t){return!o(t)&&isFinite(t)&&r(t)===t}},111:function(t){t.exports=function(t){return"object"==s(t)?null!==t:"function"==typeof t}},1913:function(t){t.exports=!1},7850:function(t,e,n){var o=n(111),r=n(4326),i=n(5112)("match");t.exports=function(t){var e;return o(t)&&(void 0!==(e=t[i])?!!e:"RegExp"==r(t))}},9212:function(t,e,n){var o=n(9670);t.exports=function(t){var e=t.return;if(void 0!==e)return o(e.call(t)).value}},3383:function(t,e,n){"use strict";var o,r,i,a=n(7293),s=n(9518),u=n(8880),c=n(6656),l=n(5112),f=n(1913),p=l("iterator"),d=!1;[].keys&&("next"in(i=[].keys())?(r=s(s(i)))!==Object.prototype&&(o=r):d=!0);var h=null==o||a((function(){var t={};return o[p].call(t)!==t}));h&&(o={}),f&&!h||c(o,p)||u(o,p,(function(){return this})),t.exports={IteratorPrototype:o,BUGGY_SAFARI_ITERATORS:d}},7497:function(t){t.exports={}},133:function(t,e,n){var o=n(5268),r=n(7392),i=n(7293);t.exports=!!Object.getOwnPropertySymbols&&!i((function(){return!Symbol.sham&&(o?38===r:r>37&&r<41)}))},8536:function(t,e,n){var o=n(7854),r=n(2788),i=o.WeakMap;t.exports="function"==typeof i&&/native code/.test(r(i))},3929:function(t,e,n){var o=n(7850);t.exports=function(t){if(o(t))throw TypeError("The method doesn't accept regular expressions");return t}},1574:function(t,e,n){"use strict";var o=n(9781),r=n(7293),i=n(1956),a=n(5181),s=n(5296),u=n(7908),c=n(8361),l=Object.assign,f=Object.defineProperty;t.exports=!l||r((function(){if(o&&1!==l({b:1},l(f({},"a",{enumerable:!0,get:function(){f(this,"b",{value:3,enumerable:!1})}}),{b:2})).b)return!0;var t={},e={},n=Symbol(),r="abcdefghijklmnopqrst";return t[n]=7,r.split("").forEach((function(t){e[t]=t})),7!=l({},t)[n]||i(l({},e)).join("")!=r}))?function(t,e){for(var n=u(t),r=arguments.length,l=1,f=a.f,p=s.f;r>l;)for(var d,h=c(arguments[l++]),y=f?i(h).concat(f(h)):i(h),v=y.length,g=0;v>g;)d=y[g++],o&&!p.call(h,d)||(n[d]=h[d]);return n}:l},30:function(t,e,n){var o,r=n(9670),i=n(6048),a=n(748),s=n(3501),u=n(490),c=n(317),l=n(6200)("IE_PROTO"),f=function(){},p=function(t){return" - - - - - - simple-keyboard - - - - -

- - diff --git a/scripts/build.js b/scripts/build.js deleted file mode 100644 index d1100a905..000000000 --- a/scripts/build.js +++ /dev/null @@ -1,209 +0,0 @@ -// Do this as the first thing so that any code reading it knows the right env. -process.env.BABEL_ENV = 'production'; -process.env.NODE_ENV = 'production'; - -// Makes the script crash on unhandled rejections instead of silently -// ignoring them. In the future, promise rejections that are not handled will -// terminate the Node.js process with a non-zero exit code. -process.on('unhandledRejection', err => { - throw err; -}); - -// Ensure environment variables are read. -require('../config/env'); - - -const path = require('path'); -const chalk = require('react-dev-utils/chalk'); -const fs = require('fs-extra'); -const webpack = require('webpack'); -const configFactory = require('../config/webpack.config'); -const paths = require('../config/paths'); -const checkRequiredFiles = require('react-dev-utils/checkRequiredFiles'); -const formatWebpackMessages = require('react-dev-utils/formatWebpackMessages'); -const printHostingInstructions = require('react-dev-utils/printHostingInstructions'); -const FileSizeReporter = require('react-dev-utils/FileSizeReporter'); -const printBuildError = require('react-dev-utils/printBuildError'); - -const measureFileSizesBeforeBuild = - FileSizeReporter.measureFileSizesBeforeBuild; -const printFileSizesAfterBuild = FileSizeReporter.printFileSizesAfterBuild; -const useYarn = fs.existsSync(paths.yarnLockFile); - -// These sizes are pretty large. We'll warn for bundles exceeding them. -const WARN_AFTER_BUNDLE_GZIP_SIZE = 512 * 1024; -const WARN_AFTER_CHUNK_GZIP_SIZE = 1024 * 1024; - -const isInteractive = process.stdout.isTTY; - -// Warn and crash if required files are missing -if (!checkRequiredFiles([paths.appHtml, paths.appIndexJs])) { - process.exit(1); -} - -// Generate configuration -const config = configFactory('production'); - -// We require that you explicitly set browsers and do not fall back to -// browserslist defaults. -const { checkBrowsers } = require('react-dev-utils/browsersHelper'); -checkBrowsers(paths.appPath, isInteractive) - .then(() => { - // First, read the current file sizes in build directory. - // This lets us display how much they changed later. - return measureFileSizesBeforeBuild(paths.appBuild); - }) - .then(previousFileSizes => { - // Remove all content but keep the directory so that - // if you're in it, you don't end up in Trash - fs.emptyDirSync(paths.appBuild); - // Merge with the public folder - //copyPublicFolder(); - // Start the webpack build - return build(previousFileSizes); - }) - .then( - ({ stats, previousFileSizes, warnings }) => { - if (warnings.length) { - console.log(chalk.yellow('Compiled with warnings.\n')); - console.log(warnings.join('\n\n')); - console.log( - '\nSearch for the ' + - chalk.underline(chalk.yellow('keywords')) + - ' to learn more about each warning.' - ); - console.log( - 'To ignore, add ' + - chalk.cyan('// eslint-disable-next-line') + - ' to the line before.\n' - ); - } else { - console.log(chalk.green('Compiled successfully.\n')); - } - - console.log('File sizes after gzip:\n'); - printFileSizesAfterBuild( - stats, - previousFileSizes, - paths.appBuild, - WARN_AFTER_BUNDLE_GZIP_SIZE, - WARN_AFTER_CHUNK_GZIP_SIZE - ); - console.log(); - - const appPackage = require(paths.appPackageJson); - const publicUrl = paths.publicUrlOrPath; - const publicPath = config.output.publicPath; - const buildFolder = path.relative(process.cwd(), paths.appBuild); - printHostingInstructions( - appPackage, - publicUrl, - publicPath, - buildFolder, - useYarn - ); - }, - err => { - const tscCompileOnError = process.env.TSC_COMPILE_ON_ERROR === 'true'; - if (tscCompileOnError) { - console.log( - chalk.yellow( - 'Compiled with the following type errors (you may want to check these before deploying your app):\n' - ) - ); - printBuildError(err); - } else { - console.log(chalk.red('Failed to compile.\n')); - printBuildError(err); - process.exit(1); - } - } - ) - .catch(err => { - if (err && err.message) { - console.log(err.message); - } - process.exit(1); - }); - -// Create the production build and print the deployment instructions. -function build(previousFileSizes) { - // We used to support resolving modules according to `NODE_PATH`. - // This now has been deprecated in favor of jsconfig/tsconfig.json - // This lets you use absolute paths in imports inside large monorepos: - if (process.env.NODE_PATH) { - console.log( - chalk.yellow( - 'Setting NODE_PATH to resolve modules absolutely has been deprecated in favor of setting baseUrl in jsconfig.json (or tsconfig.json if you are using TypeScript) and will be removed in a future major release of create-react-app.' - ) - ); - console.log(); - } - - console.log('Creating an optimized production build...'); - - const compiler = webpack(config); - return new Promise((resolve, reject) => { - compiler.run((err, stats) => { - let messages; - if (err) { - if (!err.message) { - return reject(err); - } - - let errMessage = err.message; - - // Add additional information for postcss errors - if (Object.prototype.hasOwnProperty.call(err, 'postcssNode')) { - errMessage += - '\nCompileError: Begins at CSS selector ' + - err['postcssNode'].selector; - } - - messages = formatWebpackMessages({ - errors: [errMessage], - warnings: [], - }); - } else { - messages = formatWebpackMessages( - stats.toJson({ all: false, warnings: true, errors: true }) - ); - } - if (messages.errors.length) { - // Only keep the first error. Others are often indicative - // of the same problem, but confuse the reader with noise. - if (messages.errors.length > 1) { - messages.errors.length = 1; - } - return reject(new Error(messages.errors.join('\n\n'))); - } - if ( - process.env.CI && - (typeof process.env.CI !== 'string' || - process.env.CI.toLowerCase() !== 'false') && - messages.warnings.length - ) { - console.log( - chalk.yellow( - '\nTreating warnings as errors because process.env.CI = true.\n' + - 'Most CI servers set it automatically.\n' - ) - ); - return reject(new Error(messages.warnings.join('\n\n'))); - } - - return resolve({ - stats, - previousFileSizes, - warnings: messages.warnings, - }); - }); - }); -} - -function copyPublicFolder() { - fs.copySync(paths.appPublic, paths.appBuild, { - dereference: true, - filter: file => file !== paths.appHtml, - }); -} diff --git a/scripts/demo.js b/scripts/demo.js deleted file mode 100644 index ce4b56a4c..000000000 --- a/scripts/demo.js +++ /dev/null @@ -1,209 +0,0 @@ -// Do this as the first thing so that any code reading it knows the right env. -process.env.BABEL_ENV = 'production'; -process.env.NODE_ENV = 'production'; - -// Makes the script crash on unhandled rejections instead of silently -// ignoring them. In the future, promise rejections that are not handled will -// terminate the Node.js process with a non-zero exit code. -process.on('unhandledRejection', err => { - throw err; -}); - -// Ensure environment variables are read. -require('../config/env'); - - -const path = require('path'); -const chalk = require('react-dev-utils/chalk'); -const fs = require('fs-extra'); -const webpack = require('webpack'); -const configFactory = require('../config/webpack.config.demo'); -const paths = require('../config/paths'); -const checkRequiredFiles = require('react-dev-utils/checkRequiredFiles'); -const formatWebpackMessages = require('react-dev-utils/formatWebpackMessages'); -const printHostingInstructions = require('react-dev-utils/printHostingInstructions'); -const FileSizeReporter = require('react-dev-utils/FileSizeReporter'); -const printBuildError = require('react-dev-utils/printBuildError'); - -const measureFileSizesBeforeBuild = - FileSizeReporter.measureFileSizesBeforeBuild; -const printFileSizesAfterBuild = FileSizeReporter.printFileSizesAfterBuild; -const useYarn = fs.existsSync(paths.yarnLockFile); - -// These sizes are pretty large. We'll warn for bundles exceeding them. -const WARN_AFTER_BUNDLE_GZIP_SIZE = 512 * 1024; -const WARN_AFTER_CHUNK_GZIP_SIZE = 1024 * 1024; - -const isInteractive = process.stdout.isTTY; - -// Warn and crash if required files are missing -if (!checkRequiredFiles([paths.appHtml, paths.appDemoIndexJs])) { - process.exit(1); -} - -// Generate configuration -const config = configFactory('production'); - -// We require that you explicitly set browsers and do not fall back to -// browserslist defaults. -const { checkBrowsers } = require('react-dev-utils/browsersHelper'); -checkBrowsers(paths.appPath, isInteractive) - .then(() => { - // First, read the current file sizes in build directory. - // This lets us display how much they changed later. - return measureFileSizesBeforeBuild(paths.appDemo); - }) - .then(previousFileSizes => { - // Remove all content but keep the directory so that - // if you're in it, you don't end up in Trash - fs.emptyDirSync(paths.appDemo); - // Merge with the public folder - copyPublicFolder(); - // Start the webpack build - return build(previousFileSizes); - }) - .then( - ({ stats, previousFileSizes, warnings }) => { - if (warnings.length) { - console.log(chalk.yellow('Compiled with warnings.\n')); - console.log(warnings.join('\n\n')); - console.log( - '\nSearch for the ' + - chalk.underline(chalk.yellow('keywords')) + - ' to learn more about each warning.' - ); - console.log( - 'To ignore, add ' + - chalk.cyan('// eslint-disable-next-line') + - ' to the line before.\n' - ); - } else { - console.log(chalk.green('Compiled successfully.\n')); - } - - console.log('File sizes after gzip:\n'); - printFileSizesAfterBuild( - stats, - previousFileSizes, - paths.appDemo, - WARN_AFTER_BUNDLE_GZIP_SIZE, - WARN_AFTER_CHUNK_GZIP_SIZE - ); - console.log(); - - const appPackage = require(paths.appPackageJson); - const publicUrl = paths.publicUrlOrPath; - const publicPath = config.output.publicPath; - const buildFolder = path.relative(process.cwd(), paths.appDemo); - printHostingInstructions( - appPackage, - publicUrl, - publicPath, - buildFolder, - useYarn - ); - }, - err => { - const tscCompileOnError = process.env.TSC_COMPILE_ON_ERROR === 'true'; - if (tscCompileOnError) { - console.log( - chalk.yellow( - 'Compiled with the following type errors (you may want to check these before deploying your app):\n' - ) - ); - printBuildError(err); - } else { - console.log(chalk.red('Failed to compile.\n')); - printBuildError(err); - process.exit(1); - } - } - ) - .catch(err => { - if (err && err.message) { - console.log(err.message); - } - process.exit(1); - }); - -// Create the production build and print the deployment instructions. -function build(previousFileSizes) { - // We used to support resolving modules according to `NODE_PATH`. - // This now has been deprecated in favor of jsconfig/tsconfig.json - // This lets you use absolute paths in imports inside large monorepos: - if (process.env.NODE_PATH) { - console.log( - chalk.yellow( - 'Setting NODE_PATH to resolve modules absolutely has been deprecated in favor of setting baseUrl in jsconfig.json (or tsconfig.json if you are using TypeScript) and will be removed in a future major release of create-react-app.' - ) - ); - console.log(); - } - - console.log('Creating an optimized production build...'); - - const compiler = webpack(config); - return new Promise((resolve, reject) => { - compiler.run((err, stats) => { - let messages; - if (err) { - if (!err.message) { - return reject(err); - } - - let errMessage = err.message; - - // Add additional information for postcss errors - if (Object.prototype.hasOwnProperty.call(err, 'postcssNode')) { - errMessage += - '\nCompileError: Begins at CSS selector ' + - err['postcssNode'].selector; - } - - messages = formatWebpackMessages({ - errors: [errMessage], - warnings: [], - }); - } else { - messages = formatWebpackMessages( - stats.toJson({ all: false, warnings: true, errors: true }) - ); - } - if (messages.errors.length) { - // Only keep the first error. Others are often indicative - // of the same problem, but confuse the reader with noise. - if (messages.errors.length > 1) { - messages.errors.length = 1; - } - return reject(new Error(messages.errors.join('\n\n'))); - } - if ( - process.env.CI && - (typeof process.env.CI !== 'string' || - process.env.CI.toLowerCase() !== 'false') && - messages.warnings.length - ) { - console.log( - chalk.yellow( - '\nTreating warnings as errors because process.env.CI = true.\n' + - 'Most CI servers set it automatically.\n' - ) - ); - return reject(new Error(messages.warnings.join('\n\n'))); - } - - return resolve({ - stats, - previousFileSizes, - warnings: messages.warnings, - }); - }); - }); -} - -function copyPublicFolder() { - fs.copySync(paths.appPublic, paths.appDemo, { - dereference: true, - filter: file => file !== paths.appHtml, - }); -} diff --git a/config/getPackageJson.js b/scripts/getPackageJson.js similarity index 95% rename from config/getPackageJson.js rename to scripts/getPackageJson.js index 0f64d4d81..fe44d4b5d 100644 --- a/config/getPackageJson.js +++ b/scripts/getPackageJson.js @@ -22,4 +22,4 @@ const getPackageJson = function(...args) { }, {}); }; -module.exports = getPackageJson; +module.exports = getPackageJson; \ No newline at end of file diff --git a/scripts/start.js b/scripts/start.js deleted file mode 100644 index 12396e79e..000000000 --- a/scripts/start.js +++ /dev/null @@ -1,187 +0,0 @@ - - -// Do this as the first thing so that any code reading it knows the right env. -process.env.BABEL_ENV = 'development'; -process.env.NODE_ENV = 'development'; - -// Makes the script crash on unhandled rejections instead of silently -// ignoring them. In the future, promise rejections that are not handled will -// terminate the Node.js process with a non-zero exit code. -process.on('unhandledRejection', err => { - throw err; -}); - -// Ensure environment variables are read. -require('../config/env'); - - -const fs = require('fs'); -const chalk = require('react-dev-utils/chalk'); -const webpack = require('webpack'); -const WebpackDevServer = require('webpack-dev-server'); -const clearConsole = require('react-dev-utils/clearConsole'); -const checkRequiredFiles = require('react-dev-utils/checkRequiredFiles'); -const { - choosePort, - createCompiler, - prepareProxy, - prepareUrls, -} = require('react-dev-utils/WebpackDevServerUtils'); -const openBrowser = require('react-dev-utils/openBrowser'); -const paths = require('../config/paths'); -const configFactory = require('../config/webpack.config'); -const createDevServerConfig = require('../config/webpackDevServer.config'); - -const useYarn = fs.existsSync(paths.yarnLockFile); -const isInteractive = process.stdout.isTTY; - -// Warn and crash if required files are missing -if (!checkRequiredFiles([paths.appHtml, paths.appDemoIndexJs])) { - process.exit(1); -} - -// Tools like Cloud9 rely on this. -const DEFAULT_PORT = parseInt(process.env.PORT, 10) || 3000; -const HOST = process.env.HOST || '0.0.0.0'; - -if (process.env.HOST) { - console.log( - chalk.cyan( - `Attempting to bind to HOST environment variable: ${chalk.yellow( - chalk.bold(process.env.HOST) - )}` - ) - ); - console.log( - `If this was unintentional, check that you haven't mistakenly set it in your shell.` - ); - console.log( - `Learn more here: ${chalk.yellow('https://bit.ly/CRA-advanced-config')}` - ); - console.log(); -} - -// We require that you explicitly set browsers and do not fall back to -// browserslist defaults. -const { checkBrowsers } = require('react-dev-utils/browsersHelper'); -checkBrowsers(paths.appPath, isInteractive) - .then(() => { - // We attempt to use the default port but if it is busy, we offer the user to - // run on a different port. `choosePort()` Promise resolves to the next free port. - return choosePort(HOST, DEFAULT_PORT); - }) - .then(port => { - if (port == null) { - // We have not found a port. - return; - } - const args = process.argv; - const testMode = args[2] === "--testMode"; - const config = configFactory('development'); - const protocol = process.env.HTTPS === 'true' ? 'https' : 'http'; - const appName = require(paths.appPackageJson).name; - const useTypeScript = fs.existsSync(paths.appTsConfig); - const tscCompileOnError = process.env.TSC_COMPILE_ON_ERROR === 'true'; - const urls = prepareUrls( - protocol, - HOST, - port, - paths.publicUrlOrPath.slice(0, -1) - ); - const devSocket = { - warnings: warnings => - devServer.sockWrite(devServer.sockets, 'warnings', warnings), - errors: errors => - devServer.sockWrite(devServer.sockets, 'errors', errors), - }; - // Create a webpack compiler that is configured with custom messages. - const compiler = createCompiler({ - appName, - config, - devSocket, - urls, - useYarn, - useTypeScript, - tscCompileOnError, - webpack, - }); - // Load proxy config - const proxySetting = require(paths.appPackageJson).proxy; - const proxyConfig = prepareProxy( - proxySetting, - paths.appPublic - ); - // Serve webpack assets generated by the compiler over a web server. - const serverConfig = createDevServerConfig( - proxyConfig, - urls.lanUrlForConfig - ); - const devServer = new WebpackDevServer(compiler, serverConfig); - // Launch WebpackDevServer. - devServer.listen(port, HOST, err => { - if (err) { - return console.log(err); - } - if (isInteractive) { - clearConsole(); - } - - // We used to support resolving modules according to `NODE_PATH`. - // This now has been deprecated in favor of jsconfig/tsconfig.json - // This lets you use absolute paths in imports inside large monorepos: - if (process.env.NODE_PATH) { - console.log( - chalk.yellow( - 'Setting NODE_PATH to resolve modules absolutely has been deprecated in favor of setting baseUrl in jsconfig.json (or tsconfig.json if you are using TypeScript) and will be removed in a future major release of create-react-app.' - ) - ); - console.log(); - } - - console.log(chalk.cyan('Starting the development server...\n')); - openBrowser(urls.localUrlForBrowser); - - /** - * Handle testMode - */ - if(testMode){ - compiler.hooks.done.tap('done', (stats) => { - stats = stats.toJson(); - - if (stats.errors && stats.errors.length > 0) { - devServer.close(); - process.exit(1); - } - - console.warn("App started in test mode. Closing in 5 seconds."); - const closeTimeout = setTimeout(() => { - clearTimeout(closeTimeout); - devServer.close(); - process.exit(); - }, 5000); - }); - } - }); - - ['SIGINT', 'SIGTERM'].forEach(function(sig) { - process.on(sig, function() { - devServer.close(); - process.exit(); - }); - }); - - if (isInteractive || process.env.CI !== 'true') { - // Gracefully exit when stdin ends - process.stdin.on('end', function() { - devServer.close(); - process.exit(); - }); - process.stdin.resume(); - } - }) - .catch(err => { - if (err && err.message) { - console.log(err.message); - } - process.exit(1); - }); diff --git a/scripts/test.js b/scripts/test.js deleted file mode 100644 index b57cb3834..000000000 --- a/scripts/test.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -// Do this as the first thing so that any code reading it knows the right env. -process.env.BABEL_ENV = 'test'; -process.env.NODE_ENV = 'test'; -process.env.PUBLIC_URL = ''; - -// Makes the script crash on unhandled rejections instead of silently -// ignoring them. In the future, promise rejections that are not handled will -// terminate the Node.js process with a non-zero exit code. -process.on('unhandledRejection', err => { - throw err; -}); - -// Ensure environment variables are read. -require('../config/env'); - - -const jest = require('jest'); -const execSync = require('child_process').execSync; -let argv = process.argv.slice(2); - -function isInGitRepository() { - try { - execSync('git rev-parse --is-inside-work-tree', { stdio: 'ignore' }); - return true; - } catch (e) { - return false; - } -} - -function isInMercurialRepository() { - try { - execSync('hg --cwd . root', { stdio: 'ignore' }); - return true; - } catch (e) { - return false; - } -} - -// Watch unless on CI or explicitly running all tests -if ( - !process.env.CI && - argv.indexOf('--watchAll') === -1 && - argv.indexOf('--watchAll=false') === -1 -) { - // https://github.com/facebook/create-react-app/issues/5210 - const hasSourceControl = isInGitRepository() || isInMercurialRepository(); - argv.push(hasSourceControl ? '--watch' : '--watchAll'); -} - - -jest.run(argv); diff --git a/scripts/testMock.js b/scripts/testMock.js new file mode 100644 index 000000000..a09954537 --- /dev/null +++ b/scripts/testMock.js @@ -0,0 +1 @@ +module.exports = {}; \ No newline at end of file diff --git a/src/demo/App.js b/src/demo/App.tsx similarity index 52% rename from src/demo/App.js rename to src/demo/App.tsx index 710876b27..215f94574 100644 --- a/src/demo/App.js +++ b/src/demo/App.tsx @@ -1,4 +1,4 @@ -import React from "react"; +import * as React from "react"; import Keyboard from "../lib"; import "./css/App.css"; @@ -6,15 +6,14 @@ class App extends React.Component { state = { input: "", layoutName: "default", - buttonTheme: [] }; - keyboard = React.createRef(); + keyboard; - onChange = input => + onChange = (input) => this.setState({ input }, () => console.log("Input changed", input)); - onKeyPress = button => { + onKeyPress = (button) => { console.log("Button pressed", button); /** @@ -26,14 +25,14 @@ class App extends React.Component { handleShiftButton = () => { const { - state: { layoutName } + state: { layoutName }, } = this; const shiftToggle = layoutName === "default" ? "shift" : "default"; this.setState({ layoutName: shiftToggle }); }; - onChangeInput = event => { + onChangeInput = (event) => { const input = event.target.value; this.setState({ input: event.target.value }, () => @@ -43,47 +42,26 @@ class App extends React.Component { render() { const { - state: { input, layoutName, buttonTheme }, + state: { input, layoutName }, onChangeInput, onChange, - onKeyPress + onKeyPress, } = this; return (
-