mirror of
https://github.com/hodgef/simple-keyboard.git
synced 2026-08-02 00:00:07 +08:00
Compare commits
@@ -0,0 +1,17 @@
|
|||||||
|
---
|
||||||
|
name: Bug report
|
||||||
|
about: Create a report to help improve simple-keyboard
|
||||||
|
title: ''
|
||||||
|
labels: ''
|
||||||
|
assignees: hodgef
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
**Simple-keyboard version**
|
||||||
|
As some bugs have been addressed in later versions, please ensure you are running the latest.
|
||||||
|
|
||||||
|
**Describe the bug**
|
||||||
|
A clear and concise description of what the bug is. Providing a [sandbox example](https://codesandbox.io/s/vanilla) or code depicting the issue is important, as this will help us reproduce the issue.
|
||||||
|
|
||||||
|
**Screenshots**
|
||||||
|
If applicable, add screenshots to help explain your problem.
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
---
|
||||||
|
name: Feature request
|
||||||
|
about: Suggest an idea you'd like to see in simple-keyboard
|
||||||
|
title: ''
|
||||||
|
labels: ''
|
||||||
|
assignees: ''
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
**Is your feature request related to a problem? Please describe.**
|
||||||
|
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
|
||||||
|
|
||||||
|
**Describe the solution you'd like**
|
||||||
|
A clear and concise description of what you want to happen.
|
||||||
|
|
||||||
|
**Describe alternatives you've considered**
|
||||||
|
A clear and concise description of any alternative solutions or features you've considered.
|
||||||
|
|
||||||
|
**Additional context**
|
||||||
|
Add any other context or screenshots about the feature request here.
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
# About .github
|
||||||
|
|
||||||
|
This directory handles special features to be used on simple-keyboard's Github repository.
|
||||||
|
It is not needed for simple-keyboard to run and can be safely removed.
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
## Description
|
||||||
|
|
||||||
|
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%
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
name: Build
|
||||||
|
on: [push, pull_request]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
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: 'simple-keyboard - CI Build Passed'
|
||||||
|
|
||||||
|
- name: Discord notification
|
||||||
|
if: failure()
|
||||||
|
env:
|
||||||
|
DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }}
|
||||||
|
uses: Ilshidur/action-discord@master
|
||||||
|
with:
|
||||||
|
args: 'simple-keyboard - CI Build Failed'
|
||||||
|
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
name: Publish
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
publish:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v1
|
||||||
|
- uses: actions/setup-node@v1
|
||||||
|
with:
|
||||||
|
node-version: 12
|
||||||
|
- run: npm install
|
||||||
|
- run: npm run test -- --coverage --watchAll=false
|
||||||
|
|
||||||
|
- name: Setup GIT
|
||||||
|
run: |
|
||||||
|
git config --local --list
|
||||||
|
git checkout master
|
||||||
|
git config user.email "$GH_EMAIL"
|
||||||
|
git config user.name "Francisco Hodge"
|
||||||
|
env:
|
||||||
|
GH_EMAIL: ${{secrets.GH_EMAIL}}
|
||||||
|
|
||||||
|
- name: Bump version
|
||||||
|
run: |
|
||||||
|
git reset --hard
|
||||||
|
npm version patch
|
||||||
|
npm run build
|
||||||
|
git add . || true
|
||||||
|
git commit -m "Build update" || true
|
||||||
|
git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$GITHUB_REPOSITORY"
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
|
||||||
|
|
||||||
|
- name: npm publish
|
||||||
|
run: |
|
||||||
|
npm config set //registry.npmjs.org/:_authToken=$NODE_AUTH_TOKEN
|
||||||
|
npm run trypublish
|
||||||
|
env:
|
||||||
|
NODE_AUTH_TOKEN: ${{secrets.NODE_AUTH_TOKEN}}
|
||||||
+4
-1
@@ -1,7 +1,9 @@
|
|||||||
# See https://help.github.com/ignore-files/ for more about ignoring files.
|
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
|
||||||
|
|
||||||
# dependencies
|
# dependencies
|
||||||
/node_modules
|
/node_modules
|
||||||
|
/.pnp
|
||||||
|
.pnp.js
|
||||||
|
|
||||||
# production
|
# production
|
||||||
/demo
|
/demo
|
||||||
@@ -15,6 +17,7 @@
|
|||||||
.env.development.local
|
.env.development.local
|
||||||
.env.test.local
|
.env.test.local
|
||||||
.env.production.local
|
.env.production.local
|
||||||
|
.vscode
|
||||||
|
|
||||||
npm-debug.log*
|
npm-debug.log*
|
||||||
yarn-debug.log*
|
yarn-debug.log*
|
||||||
|
|||||||
@@ -4,6 +4,9 @@
|
|||||||
# testing
|
# testing
|
||||||
/coverage
|
/coverage
|
||||||
|
|
||||||
|
# docs
|
||||||
|
/docs
|
||||||
|
|
||||||
# misc
|
# misc
|
||||||
.DS_Store
|
.DS_Store
|
||||||
.env.local
|
.env.local
|
||||||
@@ -14,6 +17,8 @@
|
|||||||
npm-debug.log*
|
npm-debug.log*
|
||||||
yarn-debug.log*
|
yarn-debug.log*
|
||||||
yarn-error.log*
|
yarn-error.log*
|
||||||
|
/.github
|
||||||
|
/demo
|
||||||
|
|
||||||
# Development folders and files
|
# Development folders and files
|
||||||
public
|
public
|
||||||
|
|||||||
+16
-2
@@ -1,5 +1,19 @@
|
|||||||
language: node_js
|
language: node_js
|
||||||
node_js:
|
node_js:
|
||||||
- "node"
|
- node
|
||||||
|
install:
|
||||||
|
- npm install -g codecov
|
||||||
|
- npm install
|
||||||
script:
|
script:
|
||||||
- npm run test
|
- npm run start -- --testMode
|
||||||
|
- npm run demo
|
||||||
|
- npm run coverage
|
||||||
|
- codecov
|
||||||
|
after_success:
|
||||||
|
- wget https://raw.githubusercontent.com/DiscordHooks/travis-ci-discord-webhook/master/send.sh
|
||||||
|
- chmod +x send.sh
|
||||||
|
- ./send.sh success $WEBHOOK_URL
|
||||||
|
after_failure:
|
||||||
|
- wget https://raw.githubusercontent.com/DiscordHooks/travis-ci-discord-webhook/master/send.sh
|
||||||
|
- chmod +x send.sh
|
||||||
|
- ./send.sh failure $WEBHOOK_URL
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
MIT License
|
MIT License
|
||||||
|
|
||||||
Copyright (c) 2018 Francisco Hodge
|
Copyright (c) 2019 Francisco Hodge
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
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
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
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
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
SOFTWARE.
|
SOFTWARE.
|
||||||
@@ -1,358 +1,48 @@
|
|||||||
# simple-keyboard
|
<p>
|
||||||
|
<a href="https://simple-keyboard.com/demo">
|
||||||
|
<img alt="simple-keyboard: Javscript Virtual Keyboard" src="https://i.imgur.com/Po6659n.gif">
|
||||||
|
</a>
|
||||||
|
|
||||||
|
<a href="https://www.npmjs.com/package/simple-keyboard">
|
||||||
|
<img src="https://badgen.net/npm/v/simple-keyboard?color=blue" alt="npm version">
|
||||||
|
</a>
|
||||||
|
|
||||||
|
<a href="https://github.com/hodgef/simple-keyboard/actions">
|
||||||
|
<img alt="Build Status" src="https://github.com/hodgef/simple-keyboard/workflows/Build/badge.svg?color=green" />
|
||||||
|
</a>
|
||||||
|
|
||||||
|
<a href="https://github.com/hodgef/simple-keyboard/actions">
|
||||||
|
<img alt="Publish Status" src="https://github.com/hodgef/simple-keyboard/workflows/Publish/badge.svg?color=green" />
|
||||||
|
</a>
|
||||||
|
|
||||||
|
<a href="https://bundlephobia.com/result?p=simple-keyboard">
|
||||||
|
<img src="https://badgen.net/bundlephobia/minzip/simple-keyboard/?color=green" alt="install size">
|
||||||
|
</a>
|
||||||
|
|
||||||
|
<a href="https://david-dm.org/hodgef/simple-keyboard">
|
||||||
|
<img src="https://badgen.net/david/dep/hodgef/simple-keyboard" alt="coverage">
|
||||||
|
</a>
|
||||||
|
|
||||||
|
<a href="https://codecov.io/gh/hodgef/simple-keyboard">
|
||||||
|
<img src="https://badgen.net/codecov/c/github/hodgef/simple-keyboard" alt="coverage">
|
||||||
|
</a>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
> The slick virtual keyboard for Javascript. Compatible with your JS, React, Angular or Vue projects.
|
||||||
|
|
||||||
|
## 🚀 Demo
|
||||||
|
[Demo Showcase (Vanilla, Angular, React, Vue)](https://simple-keyboard.com/demo)
|
||||||
|
|
||||||
|
## 📦 Installation & Usage
|
||||||
|
You can use simple-keyboard as a `<script>` tag from a CDN, or install it from npm.
|
||||||
|
|
||||||
|
Check out the [Getting Started](https://simple-keyboard.com/getting-started) docs to begin.
|
||||||
|
|
||||||
|
## 📖 Documentation
|
||||||
|
Check out the [simple-keyboard documentation](https://simple-keyboard.com/documentation) site.
|
||||||
|
|
||||||
|
Feel free to browse the [Questions & Answers (FAQ)](https://simple-keyboard.com/qa-use-cases/) page for common use-cases.
|
||||||
|
|
||||||
[](https://www.npmjs.com/package/simple-keyboard)
|
|
||||||
|
|
||||||
<a href="https://franciscohodge.com/projects/simple-keyboard/"><img src="https://franciscohodge.com/project-pages/simple-keyboard/images/simple-keyboard.png" align="center"></a>
|
|
||||||
> The easily customisable and responsive on-screen virtual keyboard for Javascript projects.
|
|
||||||
|
|
||||||
<img src="https://franciscohodge.com/project-pages/simple-keyboard/images/k2.png" align="center" width="100%">
|
|
||||||
|
|
||||||
|
|
||||||
## Installation
|
|
||||||
|
|
||||||
### npm
|
|
||||||
|
|
||||||
`npm install simple-keyboard --save`
|
|
||||||
|
|
||||||
### zip file (self-hosted)
|
|
||||||
|
|
||||||
[Click here to download the latest release (zip format).](https://github.com/hodgef/simple-keyboard/zipball/master)
|
|
||||||
|
|
||||||
> Want to use a CDN instead of self-host? Scroll down to the "Usage from CDN" instructions below.
|
|
||||||
|
|
||||||
## Usage with npm
|
|
||||||
|
|
||||||
### js
|
|
||||||
|
|
||||||
````js
|
|
||||||
import Keyboard from 'simple-keyboard';
|
|
||||||
import 'simple-keyboard/build/css/index.css';
|
|
||||||
|
|
||||||
let keyboard = new Keyboard({
|
|
||||||
onChange: input => this.onChange(input),
|
|
||||||
onKeyPress: button => this.onKeyPress(button)
|
|
||||||
});
|
|
||||||
|
|
||||||
function onChange(input){
|
|
||||||
document.querySelector(".input").value = input;
|
|
||||||
console.log("Input changed", input);
|
|
||||||
}
|
|
||||||
|
|
||||||
function onKeyPress(button){
|
|
||||||
console.log("Button pressed", button);
|
|
||||||
}
|
|
||||||
````
|
|
||||||
|
|
||||||
### html
|
|
||||||
|
|
||||||
````html
|
|
||||||
<input class="input" />
|
|
||||||
<div class="simple-keyboard"></div>
|
|
||||||
````
|
|
||||||
|
|
||||||
[](https://codesandbox.io/s/krzkx19rr)
|
|
||||||
|
|
||||||
> Need a more extensive example? [Click here](https://github.com/hodgef/simple-keyboard/blob/master/src/demo/App.js).
|
|
||||||
|
|
||||||
## Usage from CDN
|
|
||||||
|
|
||||||
### html
|
|
||||||
|
|
||||||
````html
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<link rel="stylesheet" href="https://cdn.rawgit.com/hodgef/simple-keyboard/d477c35c/build/css/index.css">
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<input class="input" placeholder="Tap on the virtual keyboard to start" />
|
|
||||||
<div class="simple-keyboard"></div>
|
|
||||||
|
|
||||||
<script src="https://cdn.rawgit.com/hodgef/simple-keyboard/3b75d11b9c1d782d92103d1df0970734e6d6df83/build/index.js"></script>
|
|
||||||
<script src="src/index.js"></script>
|
|
||||||
</body>
|
|
||||||
|
|
||||||
</html>
|
|
||||||
````
|
|
||||||
|
|
||||||
### js (index.js)
|
|
||||||
|
|
||||||
````js
|
|
||||||
let Keyboard = window.SimpleKeyboard.default;
|
|
||||||
|
|
||||||
let myKeyboard = new Keyboard({
|
|
||||||
onChange: input => onChange(input),
|
|
||||||
onKeyPress: button => onKeyPress(button)
|
|
||||||
});
|
|
||||||
|
|
||||||
function onChange(input) {
|
|
||||||
document.querySelector(".input").value = input;
|
|
||||||
console.log("Input changed", input);
|
|
||||||
}
|
|
||||||
|
|
||||||
function onKeyPress(button) {
|
|
||||||
console.log("Button pressed", button);
|
|
||||||
}
|
|
||||||
````
|
|
||||||
|
|
||||||
[](https://codesandbox.io/s/6n0wzxjmjk)
|
|
||||||
|
|
||||||
## Options
|
|
||||||
|
|
||||||
You can customize the Keyboard by passing options to it.
|
|
||||||
Here are the available options (the code examples are the defaults):
|
|
||||||
|
|
||||||
### layout
|
|
||||||
|
|
||||||
> Modify the keyboard layout
|
|
||||||
|
|
||||||
```js
|
|
||||||
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}'
|
|
||||||
]
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### layoutName
|
|
||||||
|
|
||||||
> Specifies which layout should be used.
|
|
||||||
|
|
||||||
```js
|
|
||||||
layoutName: "default"
|
|
||||||
```
|
|
||||||
|
|
||||||
### display
|
|
||||||
|
|
||||||
> Replaces variable buttons (such as `{bksp}`) with a human-friendly name (e.g.: "delete").
|
|
||||||
|
|
||||||
```js
|
|
||||||
display: {
|
|
||||||
'{bksp}': 'delete',
|
|
||||||
'{enter}': '< enter',
|
|
||||||
'{shift}': 'shift',
|
|
||||||
'{s}': 'shift',
|
|
||||||
'{tab}': 'tab',
|
|
||||||
'{lock}': 'caps',
|
|
||||||
'{accept}': 'Submit',
|
|
||||||
'{space}': ' ',
|
|
||||||
'{//}': ' '
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### theme
|
|
||||||
|
|
||||||
> A prop to add your own css classes _to the keyboard wrapper_. You can add multiple classes separated by a space.
|
|
||||||
|
|
||||||
```js
|
|
||||||
theme: "hg-theme-default"
|
|
||||||
```
|
|
||||||
|
|
||||||
### buttonTheme
|
|
||||||
|
|
||||||
> A prop to add your own css classes _to one or several buttons_. You can add multiple classes separated by a space.
|
|
||||||
|
|
||||||
```js
|
|
||||||
buttonTheme: [
|
|
||||||
{
|
|
||||||
class: "myCustomClass",
|
|
||||||
buttons: "Q W E R T Y q w e r t y"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
class: "anotherCustomClass",
|
|
||||||
buttons: "Q q"
|
|
||||||
},
|
|
||||||
...
|
|
||||||
]
|
|
||||||
```
|
|
||||||
|
|
||||||
[](https://codesandbox.io/s/vj8jvz2q4l?module=%2Fsrc%2Findex.js)
|
|
||||||
|
|
||||||
|
|
||||||
### debug
|
|
||||||
|
|
||||||
> Runs a console.log every time a key is pressed. Displays the buttons pressed and the current input.
|
|
||||||
|
|
||||||
```js
|
|
||||||
debug: false
|
|
||||||
```
|
|
||||||
|
|
||||||
### newLineOnEnter
|
|
||||||
|
|
||||||
> Specifies whether clicking the "ENTER" button will input a newline (`\n`) or not.
|
|
||||||
|
|
||||||
```js
|
|
||||||
newLineOnEnter: false
|
|
||||||
```
|
|
||||||
|
|
||||||
### inputName
|
|
||||||
|
|
||||||
> Allows you to use a single simple-keyboard instance for several inputs.
|
|
||||||
|
|
||||||
```js
|
|
||||||
inputName: "default"
|
|
||||||
```
|
|
||||||
|
|
||||||
### onKeyPress
|
|
||||||
|
|
||||||
> Executes the callback function on key press. Returns button layout name (i.e.: "{shift}").
|
|
||||||
|
|
||||||
```js
|
|
||||||
onKeyPress: (button) => console.log(button)
|
|
||||||
```
|
|
||||||
|
|
||||||
### onChange
|
|
||||||
|
|
||||||
> Executes the callback function on input change. Returns the current input's string.
|
|
||||||
|
|
||||||
```js
|
|
||||||
onChange: (input) => console.log(input)
|
|
||||||
```
|
|
||||||
|
|
||||||
### onChangeAll
|
|
||||||
|
|
||||||
> Executes the callback function on input change. Returns the input object with all defined inputs. This is useful if you're handling several inputs with simple-keyboard, as specified in the "*[Using several inputs](#using-several-inputs)*" guide.
|
|
||||||
|
|
||||||
```js
|
|
||||||
onChangeAll: (inputs) => console.log(inputs)
|
|
||||||
```
|
|
||||||
|
|
||||||
## Methods
|
|
||||||
|
|
||||||
simple-keyboard has a few methods you can use to further control it's behavior.
|
|
||||||
To access these functions, you need the instance the simple-keyboard component, like so:
|
|
||||||
|
|
||||||
```js
|
|
||||||
var keyboard = new Keyboard({
|
|
||||||
...
|
|
||||||
});
|
|
||||||
/>
|
|
||||||
|
|
||||||
// Then, use as follows...
|
|
||||||
keyboard.methodName(params);
|
|
||||||
```
|
|
||||||
|
|
||||||
### clearInput
|
|
||||||
|
|
||||||
> Clear the keyboard's input.
|
|
||||||
|
|
||||||
```js
|
|
||||||
// For default input (i.e. if you have only one)
|
|
||||||
keyboard.clearInput();
|
|
||||||
|
|
||||||
// For specific input
|
|
||||||
// Must have been previously set using the "inputName" prop.
|
|
||||||
keyboard.clearInput("inputName");
|
|
||||||
```
|
|
||||||
|
|
||||||
### getInput
|
|
||||||
|
|
||||||
> Get the keyboard's input (You can also get it from the _onChange_ prop).
|
|
||||||
|
|
||||||
```js
|
|
||||||
// For default input (i.e. if you have only one)
|
|
||||||
let input = keyboard.getInput();
|
|
||||||
|
|
||||||
// For specific input
|
|
||||||
// Must have been previously set using the "inputName" prop.
|
|
||||||
let input = keyboard.getInput("inputName");
|
|
||||||
```
|
|
||||||
|
|
||||||
### setInput
|
|
||||||
|
|
||||||
> Set the keyboard's input. Useful if you want the keybord to initialize with a default value, for example.
|
|
||||||
|
|
||||||
```js
|
|
||||||
// For default input (i.e. if you have only one)
|
|
||||||
keyboard.setInput("Hello World!");
|
|
||||||
|
|
||||||
// For specific input
|
|
||||||
// Must have been previously set using the "inputName" prop.
|
|
||||||
keyboard.setInput("Hello World!", "inputName");
|
|
||||||
```
|
|
||||||
|
|
||||||
### setOptions
|
|
||||||
|
|
||||||
> Set new option or modify existing ones after initialization. The changes are applied immediately.
|
|
||||||
|
|
||||||
```js
|
|
||||||
keyboard.setOptions({
|
|
||||||
theme: "my-custom-theme"
|
|
||||||
});
|
|
||||||
```
|
|
||||||
|
|
||||||
## Use-cases
|
|
||||||
|
|
||||||
### Using several inputs
|
|
||||||
|
|
||||||
Set the *[inputName](#inputname)* option for each input you want to handle with simple-keyboard.
|
|
||||||
|
|
||||||
For example:
|
|
||||||
|
|
||||||
```html
|
|
||||||
<input class="input" id="input1" value=""/>
|
|
||||||
<input class="input" id="input2" value=""/>
|
|
||||||
```
|
|
||||||
|
|
||||||
```js
|
|
||||||
// Here we'll store the input id that simple-keyboard will be using.
|
|
||||||
var selectedInput;
|
|
||||||
|
|
||||||
// Initialize simple-keyboard as usual
|
|
||||||
var keyboard = new Keyboard({
|
|
||||||
onChange: input => onChange(input)
|
|
||||||
});
|
|
||||||
|
|
||||||
// Add an event listener for the inputs to be tracked
|
|
||||||
document.querySelectorAll('.input')
|
|
||||||
.forEach(input => input.addEventListener('focus', onInputFocus));
|
|
||||||
|
|
||||||
/**
|
|
||||||
* When an input is focused, it will be marked as selected (selectedInput)
|
|
||||||
* This is so we can replace it's value on the onChange function
|
|
||||||
*
|
|
||||||
* Also, we will set the inputName option to a unique string identifying the input (id)
|
|
||||||
* simple-keyboard save the input in this key and report changes through onChange
|
|
||||||
*/
|
|
||||||
onInputFocus = event => {
|
|
||||||
// Setting input as selected
|
|
||||||
selectedInput = `#${event.target.id}`;
|
|
||||||
|
|
||||||
// Set the inputName option on the fly !
|
|
||||||
keyboard.setOptions({
|
|
||||||
inputName: event.target.id
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// When the current input is changed, this is called
|
|
||||||
onChange = input => {
|
|
||||||
// If the input is not defined, grabbing the first ".input".
|
|
||||||
let currentInput = selectedInput || '.input';
|
|
||||||
|
|
||||||
// Updating the selected input's value
|
|
||||||
document.querySelector(currentInput).value = input;
|
|
||||||
}
|
|
||||||
|
|
||||||
```
|
|
||||||
|
|
||||||
> [See full example](https://github.com/hodgef/simple-keyboard/blob/master/src/demo/MultipleInputsDemo.js).
|
|
||||||
|
|
||||||
## Demo
|
|
||||||
|
|
||||||
[https://franciscohodge.com/simple-keyboard/demo](https://franciscohodge.com/simple-keyboard/demo)
|
|
||||||
|
|
||||||
[](https://codesandbox.io/s/krzkx19rr)
|
|
||||||
|
|
||||||
### To run demo on your own computer
|
### To run demo on your own computer
|
||||||
|
|
||||||
@@ -363,9 +53,33 @@ For example:
|
|||||||
|
|
||||||
### Other versions
|
### Other versions
|
||||||
|
|
||||||
* ReactJS - [react-simple-keyboard](https://github.com/hodgef/react-simple-keyboard)
|
* [React.js](https://github.com/hodgef/react-simple-keyboard)
|
||||||
|
* [Angular](https://simple-keyboard.com/demo)
|
||||||
|
* [Vue.js](https://simple-keyboard.com/demo)
|
||||||
|
|
||||||
## Contributing
|
### Questions?
|
||||||
|
|
||||||
|
<a href="http://franciscohodge.com/simple-keyboard/chat/join" title="Join our Discord chat" target="_blank"><img src="https://franciscohodge.com/project-pages/simple-keyboard/images/discord.png" align="center" width="200"></a>
|
||||||
|
|
||||||
|
## ✳️ Modules
|
||||||
|
|
||||||
|
You can extend simple-keyboard's functionality with [modules](https://franciscohodge.com/projects/simple-keyboard/modules/). Such as:
|
||||||
|
|
||||||
|
* [Autocorrect](https://franciscohodge.com/projects/simple-keyboard/demo-showcase/module-autocorrect/)
|
||||||
|
* [Input Mask](https://franciscohodge.com/projects/simple-keyboard/demo-showcase/module-input-mask/)
|
||||||
|
* [Key Navigation](https://franciscohodge.com/projects/simple-keyboard/demo-showcase/module-key-navigation/)
|
||||||
|
* [Swipe Keyboard](https://franciscohodge.com/projects/simple-keyboard/demo-showcase/module-swipe-keyboard/)
|
||||||
|
|
||||||
|
Want to create your own module? Check out the [Modules page](https://franciscohodge.com/projects/simple-keyboard/modules/) for instructions.
|
||||||
|
|
||||||
|
## 🎯 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.
|
||||||
|
>
|
||||||
|
> To learn more about the rationale for not supporting IE, check out [this link](https://techcommunity.microsoft.com/t5/Windows-IT-Pro-Blog/The-perils-of-using-Internet-Explorer-as-your-default-browser/ba-p/331732).
|
||||||
|
|
||||||
|
## ✅ Contributing
|
||||||
|
|
||||||
PR's and issues are welcome. Feel free to submit any issues you have at:
|
PR's and issues are welcome. Feel free to submit any issues you have at:
|
||||||
[https://github.com/hodgef/simple-keyboard/issues](https://github.com/hodgef/simple-keyboard/issues)
|
[https://github.com/hodgef/simple-keyboard/issues](https://github.com/hodgef/simple-keyboard/issues)
|
||||||
|
|||||||
+12
-2
@@ -1,2 +1,12 @@
|
|||||||
body,html{margin:0;padding:0}.simple-keyboard{font-family:HelveticaNeue-Light,Helvetica Neue Light,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif;width:100%;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;-webkit-box-sizing:border-box;box-sizing:border-box;overflow:hidden}.simple-keyboard .hg-row{display:-ms-flexbox;display:flex}.simple-keyboard .hg-row:not(:last-child){margin-bottom:5px}.simple-keyboard .hg-row .hg-button:not(:last-child){margin-right:5px}.simple-keyboard .hg-button{display:inline-block;-ms-flex-positive:1;flex-grow:1;cursor:pointer}.simple-keyboard.hg-layout-default .hg-button.hg-standardBtn{max-width:100px}.simple-keyboard.hg-theme-default{background-color:rgba(0,0,0,.1);padding:5px;border-radius:5px}.simple-keyboard.hg-theme-default .hg-button{-webkit-box-shadow:0 0 3px -1px rgba(0,0,0,.3);box-shadow:0 0 3px -1px rgba(0,0,0,.3);height:40px;border-radius:5px;-webkit-box-sizing:border-box;box-sizing:border-box;padding:5px;background:#fff;border-bottom:1px solid #b5b5b5}.simple-keyboard.hg-theme-default .hg-button:active{background:#e4e4e4}.simple-keyboard.hg-theme-default.hg-layout-numeric .hg-button{width:33.3%;height:60px;-ms-flex-align:center;align-items:center;display:-ms-flexbox;display:flex;-ms-flex-pack:center;justify-content:center}
|
/*!
|
||||||
/*# sourceMappingURL=index.css.map*/
|
*
|
||||||
|
* simple-keyboard v2.27.1
|
||||||
|
* https://github.com/hodgef/simple-keyboard
|
||||||
|
*
|
||||||
|
* Copyright (c) Francisco Hodge (https://github.com/hodgef)
|
||||||
|
*
|
||||||
|
* This source code is licensed under the MIT license found in the
|
||||||
|
* LICENSE file in the root directory of this source tree.
|
||||||
|
*
|
||||||
|
*/body,html{margin:0;padding:0}.simple-keyboard{font-family:HelveticaNeue-Light,Helvetica Neue Light,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif;width:100%;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;box-sizing:border-box;overflow:hidden;touch-action:manipulation}.simple-keyboard .hg-row{display:flex}.simple-keyboard .hg-row:not(:last-child){margin-bottom:5px}.simple-keyboard .hg-row .hg-button-container,.simple-keyboard .hg-row .hg-button:not(:last-child){margin-right:5px}.simple-keyboard .hg-row>div:last-child{margin-right:0}.simple-keyboard .hg-row .hg-button-container{display:flex}.simple-keyboard .hg-button{display:inline-block;flex-grow:1;cursor:pointer}.simple-keyboard .hg-button span{pointer-events:none}.simple-keyboard.hg-theme-default{background-color:rgba(0,0,0,.1);padding:5px;border-radius:5px}.simple-keyboard.hg-theme-default .hg-button{box-shadow:0 0 3px -1px rgba(0,0,0,.3);height:40px;border-radius:5px;box-sizing:border-box;padding:5px;background:#fff;border-bottom:1px solid #b5b5b5;cursor:pointer;display:flex;align-items:center;justify-content:center;-webkit-tap-highlight-color:rgba(0,0,0,0)}.simple-keyboard.hg-theme-default .hg-button.hg-activeButton{background:#efefef}.simple-keyboard button.hg-button{border-width:0;outline:0;font-size:inherit}.simple-keyboard.hg-theme-default.hg-layout-numeric .hg-button{width:33.3%;height:60px;align-items:center;display:flex;justify-content:center}.simple-keyboard.hg-theme-default .hg-button.hg-button-numpadadd,.simple-keyboard.hg-theme-default .hg-button.hg-button-numpadenter{height:85px}.simple-keyboard.hg-theme-default .hg-button.hg-button-numpad0{width:105px}.simple-keyboard.hg-theme-default .hg-button.hg-button-com{max-width:85px}.simple-keyboard.hg-theme-default .hg-button.hg-standardBtn.hg-button-at{max-width:45px}.simple-keyboard.hg-theme-default .hg-button.hg-selectedButton{background:rgba(5,25,70,.53);color:#fff}.simple-keyboard.hg-theme-default .hg-button.hg-standardBtn[data-skbtn=".com"]{max-width:82px}.simple-keyboard.hg-theme-default .hg-button.hg-standardBtn[data-skbtn="@"]{max-width:60px}
|
||||||
|
/*# sourceMappingURL=index.css.map */
|
||||||
File diff suppressed because one or more lines are too long
Vendored
+261
@@ -0,0 +1,261 @@
|
|||||||
|
declare module 'simple-keyboard' {
|
||||||
|
interface KeyboardLayoutObject {
|
||||||
|
default: string[];
|
||||||
|
shift?: any;
|
||||||
|
[key: string]: string[];
|
||||||
|
}
|
||||||
|
|
||||||
|
interface KeyboardButtonTheme {
|
||||||
|
class: string;
|
||||||
|
buttons: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface KeyboardButtonAttributes {
|
||||||
|
attribute: string;
|
||||||
|
value: string;
|
||||||
|
buttons: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface KeyboardOptions {
|
||||||
|
/**
|
||||||
|
* Modify the keyboard layout.
|
||||||
|
*/
|
||||||
|
layout?: KeyboardLayoutObject;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Specifies which layout should be used.
|
||||||
|
*/
|
||||||
|
layoutName?: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Replaces variable buttons (such as `{bksp}`) with a human-friendly name (e.g.: `backspace`).
|
||||||
|
*/
|
||||||
|
display?: { [button: string]: string };
|
||||||
|
|
||||||
|
/**
|
||||||
|
* By default, when you set the display property, you replace the default one. This setting merges them instead.
|
||||||
|
*/
|
||||||
|
mergeDisplay?: boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A prop to add your own css classes to the keyboard wrapper. You can add multiple classes separated by a space.
|
||||||
|
*/
|
||||||
|
theme?: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A prop to add your own css classes to one or several buttons.
|
||||||
|
*/
|
||||||
|
buttonTheme?: KeyboardButtonTheme[];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
class Keyboard {
|
||||||
|
constructor(selector: string, options: KeyboardOptions);
|
||||||
|
constructor(options: KeyboardOptions);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Options
|
||||||
|
*/
|
||||||
|
options: KeyboardOptions;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Utilities
|
||||||
|
*/
|
||||||
|
utilities?: any;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* caretPosition
|
||||||
|
*/
|
||||||
|
caretPosition?: number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds/Modifies an entry to the `buttonTheme`. Basically a way to add a class to a button.
|
||||||
|
* @param {string} buttons List of buttons to select (separated by a space).
|
||||||
|
* @param {string} className Classes to give to the selected buttons (separated by space).
|
||||||
|
*/
|
||||||
|
addButtonTheme(buttons: string, className: string): void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes/Amends an entry to the `buttonTheme`. Basically a way to remove a class previously added to a button through buttonTheme or addButtonTheme.
|
||||||
|
* @param {string} buttons List of buttons to select (separated by a space).
|
||||||
|
* @param {string} className Classes to give to the selected buttons (separated by space).
|
||||||
|
*/
|
||||||
|
removeButtonTheme(buttons: string, className: string): void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clear the keyboard's input.
|
||||||
|
*
|
||||||
|
* @param {string} [inputName] optional - the internal input to select
|
||||||
|
*/
|
||||||
|
clearInput(inputName?: string): void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the keyboard’s input (You can also get it from the onChange prop).
|
||||||
|
* @param {string} [inputName] optional - the internal input to select
|
||||||
|
*/
|
||||||
|
getInput(inputName?: string): string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the keyboard’s input.
|
||||||
|
* @param {string} input the input value
|
||||||
|
* @param {string} inputName optional - the internal input to select
|
||||||
|
*/
|
||||||
|
setInput(input: string, inputName?: string): void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set new option or modify existing ones after initialization.
|
||||||
|
* @param {KeyboardOptions} option The option to set
|
||||||
|
*/
|
||||||
|
setOptions(options: KeyboardOptions): void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send a command to all simple-keyboard instances at once (if you have multiple instances).
|
||||||
|
* @param {function(instance: object, key: string)} callback Function to run on every instance
|
||||||
|
*/
|
||||||
|
dispatch(callback: (instance: any, key: string) => void): void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the DOM Element of a button. If there are several buttons with the same name, an array of the DOM Elements is returned.
|
||||||
|
* @param {string} button The button layout name to select
|
||||||
|
*/
|
||||||
|
getButtonElement(button: string): HTMLElement | HTMLElement[];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clears keyboard listeners and DOM elements.
|
||||||
|
*/
|
||||||
|
destroy(): void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default Keyboard;
|
||||||
|
}
|
||||||
+12
-1
File diff suppressed because one or more lines are too long
+1
-1
File diff suppressed because one or more lines are too long
+9
-6
@@ -27,24 +27,27 @@ var dotenvFiles = [
|
|||||||
|
|
||||||
// Load environment variables from .env* files. Suppress warnings using silent
|
// Load environment variables from .env* files. Suppress warnings using silent
|
||||||
// if this file is missing. dotenv will never modify any environment variables
|
// if this file is missing. dotenv will never modify any environment variables
|
||||||
// that have already been set.
|
// that have already been set. Variable expansion is supported in .env files.
|
||||||
// https://github.com/motdotla/dotenv
|
// https://github.com/motdotla/dotenv
|
||||||
|
// https://github.com/motdotla/dotenv-expand
|
||||||
dotenvFiles.forEach(dotenvFile => {
|
dotenvFiles.forEach(dotenvFile => {
|
||||||
if (fs.existsSync(dotenvFile)) {
|
if (fs.existsSync(dotenvFile)) {
|
||||||
require('dotenv').config({
|
require('dotenv-expand')(
|
||||||
path: dotenvFile,
|
require('dotenv').config({
|
||||||
});
|
path: dotenvFile,
|
||||||
|
})
|
||||||
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// We support resolving modules according to `NODE_PATH`.
|
// We support resolving modules according to `NODE_PATH`.
|
||||||
// This lets you use absolute paths in imports inside large monorepos:
|
// This lets you use absolute paths in imports inside large monorepos:
|
||||||
// https://github.com/facebookincubator/create-react-app/issues/253.
|
// https://github.com/facebook/create-react-app/issues/253.
|
||||||
// It works similar to `NODE_PATH` in Node itself:
|
// It works similar to `NODE_PATH` in Node itself:
|
||||||
// https://nodejs.org/api/modules.html#modules_loading_from_the_global_folders
|
// https://nodejs.org/api/modules.html#modules_loading_from_the_global_folders
|
||||||
// Note that unlike in Node, only *relative* paths from `NODE_PATH` are honored.
|
// Note that unlike in Node, only *relative* paths from `NODE_PATH` are honored.
|
||||||
// Otherwise, we risk importing Node.js core modules into an app instead of Webpack shims.
|
// Otherwise, we risk importing Node.js core modules into an app instead of Webpack shims.
|
||||||
// https://github.com/facebookincubator/create-react-app/issues/1023#issuecomment-265344421
|
// https://github.com/facebook/create-react-app/issues/1023#issuecomment-265344421
|
||||||
// We also resolve them to make sure all tools using them work consistently.
|
// We also resolve them to make sure all tools using them work consistently.
|
||||||
const appDirectory = fs.realpathSync(process.cwd());
|
const appDirectory = fs.realpathSync(process.cwd());
|
||||||
process.env.NODE_PATH = (process.env.NODE_PATH || '')
|
process.env.NODE_PATH = (process.env.NODE_PATH || '')
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
const fs = require('fs');
|
||||||
|
const path = require('path');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A module to get package informations from package.json
|
||||||
|
* @module getPackageJson
|
||||||
|
* @param {...string} keys from package.json if no arguments passed it returns package.json content as object
|
||||||
|
* @returns {object} with given keys or content of package.json as object
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns package info
|
||||||
|
*/
|
||||||
|
const getPackageJson = function(...args) {
|
||||||
|
const packageJSON = JSON.parse(fs.readFileSync(path.join(__dirname, '../package.json')));
|
||||||
|
if (!args.length) {
|
||||||
|
return packageJSON;
|
||||||
|
}
|
||||||
|
return args.reduce((out, key) => {
|
||||||
|
out[key] = packageJSON[key];
|
||||||
|
return out;
|
||||||
|
}, {});
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = getPackageJson;
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
// This is a custom Jest transformer turning style imports into empty objects.
|
// This is a custom Jest transformer turning style imports into empty objects.
|
||||||
// http://facebook.github.io/jest/docs/tutorial-webpack.html
|
// http://facebook.github.io/jest/docs/en/webpack.html
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
process() {
|
process() {
|
||||||
|
|||||||
@@ -1,12 +1,40 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
const camelcase = require('camelcase');
|
||||||
|
|
||||||
// This is a custom Jest transformer turning file imports into filenames.
|
// This is a custom Jest transformer turning file imports into filenames.
|
||||||
// http://facebook.github.io/jest/docs/tutorial-webpack.html
|
// http://facebook.github.io/jest/docs/en/webpack.html
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
process(src, filename) {
|
process(src, filename) {
|
||||||
return `module.exports = ${JSON.stringify(path.basename(filename))};`;
|
const assetFilename = JSON.stringify(path.basename(filename));
|
||||||
|
|
||||||
|
if (filename.match(/\.svg$/)) {
|
||||||
|
// Based on how SVGR generates a component name:
|
||||||
|
// https://github.com/smooth-code/svgr/blob/01b194cf967347d43d4cbe6b434404731b87cf27/packages/core/src/state.js#L6
|
||||||
|
const pascalCaseFileName = camelcase(path.parse(filename).name, {
|
||||||
|
pascalCase: true,
|
||||||
|
});
|
||||||
|
const componentName = `Svg${pascalCaseFileName}`;
|
||||||
|
return `const React = require('react');
|
||||||
|
module.exports = {
|
||||||
|
__esModule: true,
|
||||||
|
default: ${assetFilename},
|
||||||
|
ReactComponent: React.forwardRef(function ${componentName}(props, ref) {
|
||||||
|
return {
|
||||||
|
$$typeof: Symbol.for('react.element'),
|
||||||
|
type: 'svg',
|
||||||
|
ref: ref,
|
||||||
|
key: null,
|
||||||
|
props: Object.assign({}, props, {
|
||||||
|
children: ${assetFilename}
|
||||||
|
})
|
||||||
|
};
|
||||||
|
}),
|
||||||
|
};`;
|
||||||
|
}
|
||||||
|
|
||||||
|
return `module.exports = ${assetFilename};`;
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -0,0 +1,88 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
const fs = require('fs');
|
||||||
|
const path = require('path');
|
||||||
|
const paths = require('./paths');
|
||||||
|
const chalk = require('react-dev-utils/chalk');
|
||||||
|
const resolve = require('resolve');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the baseUrl of a compilerOptions object.
|
||||||
|
*
|
||||||
|
* @param {Object} options
|
||||||
|
*/
|
||||||
|
function getAdditionalModulePaths(options = {}) {
|
||||||
|
const baseUrl = options.baseUrl;
|
||||||
|
|
||||||
|
// We need to explicitly check for null and undefined (and not a falsy value) because
|
||||||
|
// TypeScript treats an empty string as `.`.
|
||||||
|
if (baseUrl == null) {
|
||||||
|
// If there's no baseUrl set we respect NODE_PATH
|
||||||
|
// Note that NODE_PATH is deprecated and will be removed
|
||||||
|
// in the next major release of create-react-app.
|
||||||
|
|
||||||
|
const nodePath = process.env.NODE_PATH || '';
|
||||||
|
return nodePath.split(path.delimiter).filter(Boolean);
|
||||||
|
}
|
||||||
|
|
||||||
|
const baseUrlResolved = path.resolve(paths.appPath, baseUrl);
|
||||||
|
|
||||||
|
// We don't need to do anything if `baseUrl` is set to `node_modules`. This is
|
||||||
|
// the default behavior.
|
||||||
|
if (path.relative(paths.appNodeModules, baseUrlResolved) === '') {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Allow the user set the `baseUrl` to `appSrc`.
|
||||||
|
if (path.relative(paths.appSrc, baseUrlResolved) === '') {
|
||||||
|
return [paths.appSrc];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Otherwise, throw an error.
|
||||||
|
throw new Error(
|
||||||
|
chalk.red.bold(
|
||||||
|
"Your project's `baseUrl` can only be set to `src` or `node_modules`." +
|
||||||
|
' Create React App does not support other values at this time.'
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function getModules() {
|
||||||
|
// Check if TypeScript is setup
|
||||||
|
const hasTsConfig = fs.existsSync(paths.appTsConfig);
|
||||||
|
const hasJsConfig = fs.existsSync(paths.appJsConfig);
|
||||||
|
|
||||||
|
if (hasTsConfig && hasJsConfig) {
|
||||||
|
throw new Error(
|
||||||
|
'You have both a tsconfig.json and a jsconfig.json. If you are using TypeScript please remove your jsconfig.json file.'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
let config;
|
||||||
|
|
||||||
|
// If there's a tsconfig.json we assume it's a
|
||||||
|
// TypeScript project and set up the config
|
||||||
|
// based on tsconfig.json
|
||||||
|
if (hasTsConfig) {
|
||||||
|
const ts = require(resolve.sync('typescript', {
|
||||||
|
basedir: paths.appNodeModules,
|
||||||
|
}));
|
||||||
|
config = ts.readConfigFile(paths.appTsConfig, ts.sys.readFile).config;
|
||||||
|
// Otherwise we'll check if there is jsconfig.json
|
||||||
|
// for non TS projects.
|
||||||
|
} else if (hasJsConfig) {
|
||||||
|
config = require(paths.appJsConfig);
|
||||||
|
}
|
||||||
|
|
||||||
|
config = config || {};
|
||||||
|
const options = config.compilerOptions || {};
|
||||||
|
|
||||||
|
const additionalModulePaths = getAdditionalModulePaths(options);
|
||||||
|
|
||||||
|
return {
|
||||||
|
additionalModulePaths: additionalModulePaths,
|
||||||
|
hasTsConfig,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = getModules();
|
||||||
+49
-18
@@ -5,20 +5,20 @@ const fs = require('fs');
|
|||||||
const url = require('url');
|
const url = require('url');
|
||||||
|
|
||||||
// Make sure any symlinks in the project folder are resolved:
|
// Make sure any symlinks in the project folder are resolved:
|
||||||
// https://github.com/facebookincubator/create-react-app/issues/637
|
// https://github.com/facebook/create-react-app/issues/637
|
||||||
const appDirectory = fs.realpathSync(process.cwd());
|
const appDirectory = fs.realpathSync(process.cwd());
|
||||||
const resolveApp = relativePath => path.resolve(appDirectory, relativePath);
|
const resolveApp = relativePath => path.resolve(appDirectory, relativePath);
|
||||||
|
|
||||||
const envPublicUrl = process.env.PUBLIC_URL;
|
const envPublicUrl = process.env.PUBLIC_URL;
|
||||||
|
|
||||||
function ensureSlash(path, needsSlash) {
|
function ensureSlash(inputPath, needsSlash) {
|
||||||
const hasSlash = path.endsWith('/');
|
const hasSlash = inputPath.endsWith('/');
|
||||||
if (hasSlash && !needsSlash) {
|
if (hasSlash && !needsSlash) {
|
||||||
return path.substr(path, path.length - 1);
|
return inputPath.substr(0, inputPath.length - 1);
|
||||||
} else if (!hasSlash && needsSlash) {
|
} else if (!hasSlash && needsSlash) {
|
||||||
return `${path}/`;
|
return `${inputPath}/`;
|
||||||
} else {
|
} else {
|
||||||
return path;
|
return inputPath;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -38,27 +38,58 @@ function getServedPath(appPackageJson) {
|
|||||||
return ensureSlash(servedUrl, true);
|
return ensureSlash(servedUrl, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const moduleFileExtensions = [
|
||||||
|
'web.mjs',
|
||||||
|
'mjs',
|
||||||
|
'web.js',
|
||||||
|
'js',
|
||||||
|
'web.ts',
|
||||||
|
'ts',
|
||||||
|
'web.tsx',
|
||||||
|
'tsx',
|
||||||
|
'json',
|
||||||
|
'web.jsx',
|
||||||
|
'jsx',
|
||||||
|
];
|
||||||
|
|
||||||
|
// Resolve file paths in the same order as webpack
|
||||||
|
const resolveModule = (resolveFn, filePath) => {
|
||||||
|
const extension = moduleFileExtensions.find(extension =>
|
||||||
|
fs.existsSync(resolveFn(`${filePath}.${extension}`))
|
||||||
|
);
|
||||||
|
|
||||||
|
if (extension) {
|
||||||
|
return resolveFn(`${filePath}.${extension}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
return resolveFn(`${filePath}.js`);
|
||||||
|
};
|
||||||
|
|
||||||
// config after eject: we're in ./config/
|
// config after eject: we're in ./config/
|
||||||
module.exports = {
|
module.exports = {
|
||||||
dotenv: resolveApp('.env'),
|
dotenv: resolveApp('.env'),
|
||||||
|
appPath: resolveApp('.'),
|
||||||
appBuild: resolveApp('build'),
|
appBuild: resolveApp('build'),
|
||||||
appDemoBuild: resolveApp('demo'),
|
appDemo: resolveApp('demo'),
|
||||||
appPublic: resolveApp('public'),
|
appPublic: resolveApp('public'),
|
||||||
appHtml: resolveApp('public/index.html'),
|
appHtml: resolveApp('public/index.html'),
|
||||||
appIndexJs: resolveApp('src/demo/index.js'), // CRL: Updated for demo purposes
|
appIndexJs: resolveModule(resolveApp, 'src/demo/index'),
|
||||||
|
appLibIndexJs: resolveModule(resolveApp, 'src/lib/index'),
|
||||||
|
appDemoIndexJs: resolveModule(resolveApp, 'src/demo/index'),
|
||||||
appPackageJson: resolveApp('package.json'),
|
appPackageJson: resolveApp('package.json'),
|
||||||
appSrc: resolveApp('src'),
|
appSrc: resolveApp('src'),
|
||||||
|
appSrcLib: resolveApp('src/lib'),
|
||||||
|
appSrcLibTypes: resolveApp('src/lib/@types'),
|
||||||
|
appSrcDemo: resolveApp('src/demo'),
|
||||||
|
appTsConfig: resolveApp('tsconfig.json'),
|
||||||
|
appJsConfig: resolveApp('jsconfig.json'),
|
||||||
yarnLockFile: resolveApp('yarn.lock'),
|
yarnLockFile: resolveApp('yarn.lock'),
|
||||||
testsSetup: resolveApp('src/setupTests.js'),
|
testsSetup: resolveModule(resolveApp, 'src/setupTests'),
|
||||||
|
proxySetup: resolveApp('src/setupProxy.js'),
|
||||||
appNodeModules: resolveApp('node_modules'),
|
appNodeModules: resolveApp('node_modules'),
|
||||||
publicUrl: getPublicUrl(resolveApp('package.json')),
|
publicUrl: getPublicUrl(resolveApp('package.json')),
|
||||||
servedPath: getServedPath(resolveApp('package.json')),
|
//servedPath: getServedPath(resolveApp('package.json')),
|
||||||
|
servedPath: ''
|
||||||
// CRL: New paths for demo build
|
|
||||||
appDemoIndexJs: resolveApp('src/demo/index.js'),
|
|
||||||
appDemoSrc: resolveApp('src/demo'),
|
|
||||||
|
|
||||||
// CRL: New paths for library
|
|
||||||
appLibIndexJs: resolveApp('src/lib/index.js'),
|
|
||||||
appLibSrc: resolveApp('src/lib'),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
module.exports.moduleFileExtensions = moduleFileExtensions;
|
||||||
|
|||||||
@@ -0,0 +1,35 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
const { resolveModuleName } = require('ts-pnp');
|
||||||
|
|
||||||
|
exports.resolveModuleName = (
|
||||||
|
typescript,
|
||||||
|
moduleName,
|
||||||
|
containingFile,
|
||||||
|
compilerOptions,
|
||||||
|
resolutionHost
|
||||||
|
) => {
|
||||||
|
return resolveModuleName(
|
||||||
|
moduleName,
|
||||||
|
containingFile,
|
||||||
|
compilerOptions,
|
||||||
|
resolutionHost,
|
||||||
|
typescript.resolveModuleName
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.resolveTypeReferenceDirective = (
|
||||||
|
typescript,
|
||||||
|
moduleName,
|
||||||
|
containingFile,
|
||||||
|
compilerOptions,
|
||||||
|
resolutionHost
|
||||||
|
) => {
|
||||||
|
return resolveModuleName(
|
||||||
|
moduleName,
|
||||||
|
containingFile,
|
||||||
|
compilerOptions,
|
||||||
|
resolutionHost,
|
||||||
|
typescript.resolveTypeReferenceDirective
|
||||||
|
);
|
||||||
|
};
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
'use strict';
|
|
||||||
|
|
||||||
if (typeof Promise === 'undefined') {
|
|
||||||
// Rejection tracking prevents a common issue where React gets into an
|
|
||||||
// inconsistent state due to an error, but it gets swallowed by a Promise,
|
|
||||||
// and the user has no idea what causes React's erratic future behavior.
|
|
||||||
require('promise/lib/rejection-tracking').enable();
|
|
||||||
window.Promise = require('promise/lib/es6-extensions.js');
|
|
||||||
}
|
|
||||||
|
|
||||||
// fetch() polyfill for making API calls.
|
|
||||||
require('whatwg-fetch');
|
|
||||||
|
|
||||||
// Object.assign() is commonly used with React.
|
|
||||||
// It will use the native implementation if it's present and isn't buggy.
|
|
||||||
Object.assign = require('object-assign');
|
|
||||||
|
|
||||||
// In tests, polyfill requestAnimationFrame since jsdom doesn't provide it yet.
|
|
||||||
// We don't polyfill it in the browser--this is user's responsibility.
|
|
||||||
if (process.env.NODE_ENV === 'test') {
|
|
||||||
require('raf').polyfill(global);
|
|
||||||
}
|
|
||||||
+630
-259
@@ -1,280 +1,651 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
const fs = require('fs');
|
||||||
const autoprefixer = require('autoprefixer');
|
const isWsl = require('is-wsl');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const webpack = require('webpack');
|
const webpack = require('webpack');
|
||||||
|
const resolve = require('resolve');
|
||||||
|
const PnpWebpackPlugin = require('pnp-webpack-plugin');
|
||||||
const HtmlWebpackPlugin = require('html-webpack-plugin');
|
const HtmlWebpackPlugin = require('html-webpack-plugin');
|
||||||
const CopyWebpackPlugin = require('copy-webpack-plugin');
|
const CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin');
|
||||||
|
const InlineChunkHtmlPlugin = require('react-dev-utils/InlineChunkHtmlPlugin');
|
||||||
|
const TerserPlugin = require('terser-webpack-plugin');
|
||||||
|
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
|
||||||
|
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
|
||||||
|
const safePostCssParser = require('postcss-safe-parser');
|
||||||
|
const ManifestPlugin = require('webpack-manifest-plugin');
|
||||||
const InterpolateHtmlPlugin = require('react-dev-utils/InterpolateHtmlPlugin');
|
const InterpolateHtmlPlugin = require('react-dev-utils/InterpolateHtmlPlugin');
|
||||||
const ExtractTextPlugin = require('extract-text-webpack-plugin');
|
const WorkboxWebpackPlugin = require('workbox-webpack-plugin');
|
||||||
const eslintFormatter = require('react-dev-utils/eslintFormatter');
|
const WatchMissingNodeModulesPlugin = require('react-dev-utils/WatchMissingNodeModulesPlugin');
|
||||||
const ModuleScopePlugin = require('react-dev-utils/ModuleScopePlugin');
|
const ModuleScopePlugin = require('react-dev-utils/ModuleScopePlugin');
|
||||||
|
const getCSSModuleLocalIdent = require('react-dev-utils/getCSSModuleLocalIdent');
|
||||||
const paths = require('./paths');
|
const paths = require('./paths');
|
||||||
|
const modules = require('./modules');
|
||||||
const getClientEnvironment = require('./env');
|
const getClientEnvironment = require('./env');
|
||||||
|
const ModuleNotFoundPlugin = require('react-dev-utils/ModuleNotFoundPlugin');
|
||||||
|
const ForkTsCheckerWebpackPlugin = require('react-dev-utils/ForkTsCheckerWebpackPlugin');
|
||||||
|
const typescriptFormatter = require('react-dev-utils/typescriptFormatter');
|
||||||
|
const getPackageJson = require('./getPackageJson');
|
||||||
|
const eslint = require('eslint');
|
||||||
|
|
||||||
|
const postcssNormalize = require('postcss-normalize');
|
||||||
|
|
||||||
|
const appPackageJson = require(paths.appPackageJson);
|
||||||
|
|
||||||
// Webpack uses `publicPath` to determine where the app is being served from.
|
|
||||||
// It requires a trailing slash, or the file assets will get an incorrect path.
|
|
||||||
const publicPath = paths.servedPath;
|
|
||||||
// Some apps do not use client-side routing with pushState.
|
|
||||||
// For these, "homepage" can be set to "." to enable relative asset paths.
|
|
||||||
const shouldUseRelativeAssetPaths = publicPath === './';
|
|
||||||
// Source maps are resource heavy and can cause out of memory issue for large source files.
|
// Source maps are resource heavy and can cause out of memory issue for large source files.
|
||||||
const shouldUseSourceMap = process.env.GENERATE_SOURCEMAP !== 'false';
|
const shouldUseSourceMap = process.env.GENERATE_SOURCEMAP !== 'false';
|
||||||
// `publicUrl` is just like `publicPath`, but we will provide it to our app
|
// Some apps do not need the benefits of saving a web request, so not inlining the chunk
|
||||||
// as %PUBLIC_URL% in `index.html` and `process.env.PUBLIC_URL` in JavaScript.
|
// makes for a smoother build process.
|
||||||
// Omit trailing slash as %PUBLIC_URL%/xyz looks better than %PUBLIC_URL%xyz.
|
const shouldInlineRuntimeChunk = process.env.INLINE_RUNTIME_CHUNK !== 'false';
|
||||||
const publicUrl = '.';
|
|
||||||
// Get environment variables to inject into our app.
|
|
||||||
const env = getClientEnvironment(publicUrl);
|
|
||||||
|
|
||||||
// Assert this just to be safe.
|
const imageInlineSizeLimit = parseInt(
|
||||||
// Development builds of React are slow and not intended for production.
|
process.env.IMAGE_INLINE_SIZE_LIMIT || '10000'
|
||||||
if (env.stringified['process.env'].NODE_ENV !== '"production"') {
|
);
|
||||||
throw new Error('Production builds must have NODE_ENV=production.');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Note: defined here because it will be used more than once.
|
// Check if TypeScript is setup
|
||||||
const cssFilename = 'css/index.css';
|
const useTypeScript = fs.existsSync(paths.appTsConfig);
|
||||||
|
|
||||||
// ExtractTextPlugin expects the build output to be flat.
|
// style files regexes
|
||||||
// (See https://github.com/webpack-contrib/extract-text-webpack-plugin/issues/27)
|
const cssRegex = /\.css$/;
|
||||||
// However, our output is structured with css, js and media folders.
|
const cssModuleRegex = /\.module\.css$/;
|
||||||
// To have this structure working with relative paths, we have to use custom options.
|
const sassRegex = /\.(scss|sass)$/;
|
||||||
const extractTextPluginOptions = shouldUseRelativeAssetPaths
|
const sassModuleRegex = /\.module\.(scss|sass)$/;
|
||||||
? // Making sure that the publicPath goes back to to build folder.
|
|
||||||
{ publicPath: Array(cssFilename.split('/').length).join('../') }
|
|
||||||
: {};
|
|
||||||
|
|
||||||
// This is the production configuration.
|
// This is the production and development configuration.
|
||||||
// It compiles slowly and is focused on producing a fast and minimal bundle.
|
// It is focused on developer experience, fast rebuilds, and a minimal bundle.
|
||||||
// The development configuration is different and lives in a separate file.
|
module.exports = function(webpackEnv) {
|
||||||
module.exports = {
|
const isEnvDevelopment = webpackEnv === 'development';
|
||||||
// Don't attempt to continue if there are any errors.
|
const isEnvProduction = webpackEnv === 'production';
|
||||||
bail: true,
|
|
||||||
// We generate sourcemaps in production. This is slow but gives good results.
|
// Webpack uses `publicPath` to determine where the app is being served from.
|
||||||
// You can exclude the *.map files from the build during deployment.
|
// It requires a trailing slash, or the file assets will get an incorrect path.
|
||||||
devtool: shouldUseSourceMap ? 'source-map' : false,
|
// In development, we always serve from the root. This makes config easier.
|
||||||
// In production, we only want to load the app code.
|
const publicPath = paths.servedPath
|
||||||
entry: [paths.appDemoIndexJs], // CRL: library index file instead of app index
|
// Some apps do not use client-side routing with pushState.
|
||||||
output: {
|
// For these, "homepage" can be set to "." to enable relative asset paths.
|
||||||
// CRL: Updated whole block with library specific info
|
const shouldUseRelativeAssetPaths = publicPath === './';
|
||||||
path: paths.appDemoBuild,
|
|
||||||
filename: 'index.js',
|
// `publicUrl` is just like `publicPath`, but we will provide it to our app
|
||||||
libraryTarget: 'umd',
|
// as %PUBLIC_URL% in `index.html` and `process.env.PUBLIC_URL` in JavaScript.
|
||||||
library: 'SimpleKeyboard'
|
// Omit trailing slash as %PUBLIC_URL%/xyz looks better than %PUBLIC_URL%xyz.
|
||||||
},
|
const publicUrl = publicPath.slice(0, -1);
|
||||||
resolve: {
|
// Get environment variables to inject into our app.
|
||||||
// This allows you to set a fallback for where Webpack should look for modules.
|
const env = getClientEnvironment(publicUrl);
|
||||||
// We placed these paths second because we want `node_modules` to "win"
|
|
||||||
// if there are any conflicts. This matches Node resolution mechanism.
|
// common function to get style loaders
|
||||||
// https://github.com/facebookincubator/create-react-app/issues/253
|
const getStyleLoaders = (cssOptions, preProcessor) => {
|
||||||
modules: ['node_modules', paths.appNodeModules].concat(
|
const loaders = [
|
||||||
// It is guaranteed to exist because we tweak it in `env.js`
|
isEnvDevelopment && require.resolve('style-loader'),
|
||||||
process.env.NODE_PATH.split(path.delimiter).filter(Boolean)
|
isEnvProduction && {
|
||||||
),
|
loader: MiniCssExtractPlugin.loader,
|
||||||
// These are the reasonable defaults supported by the Node ecosystem.
|
options: shouldUseRelativeAssetPaths ? { publicPath: '../../' } : {},
|
||||||
// We also include JSX as a common component filename extension to support
|
},
|
||||||
// some tools, although we do not recommend using it, see:
|
{
|
||||||
// https://github.com/facebookincubator/create-react-app/issues/290
|
loader: require.resolve('css-loader'),
|
||||||
// `web` extension prefixes have been added for better support
|
options: cssOptions,
|
||||||
// for React Native Web.
|
},
|
||||||
extensions: ['.web.js', '.mjs', '.js', '.json', '.web.jsx', '.jsx'],
|
{
|
||||||
alias: {
|
// Options for PostCSS as we reference these options twice
|
||||||
// Support React Native Web
|
// Adds vendor prefixing based on your specified browser support in
|
||||||
// https://www.smashingmagazine.com/2016/08/a-glimpse-into-the-future-with-react-native-for-web/
|
// package.json
|
||||||
'react-native': 'react-native-web'
|
loader: require.resolve('postcss-loader'),
|
||||||
|
options: {
|
||||||
|
// Necessary for external CSS imports to work
|
||||||
|
// https://github.com/facebook/create-react-app/issues/2677
|
||||||
|
ident: 'postcss',
|
||||||
|
plugins: () => [
|
||||||
|
require('postcss-flexbugs-fixes'),
|
||||||
|
require('postcss-preset-env')({
|
||||||
|
autoprefixer: {
|
||||||
|
flexbox: 'no-2009',
|
||||||
|
},
|
||||||
|
stage: 3,
|
||||||
|
}),
|
||||||
|
// Adds PostCSS Normalize as the reset css with default options,
|
||||||
|
// so that it honors browserslist config in package.json
|
||||||
|
// which in turn let's users customize the target behavior as per their needs.
|
||||||
|
postcssNormalize(),
|
||||||
|
],
|
||||||
|
sourceMap: isEnvProduction && shouldUseSourceMap,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
].filter(Boolean);
|
||||||
|
if (preProcessor) {
|
||||||
|
loaders.push(
|
||||||
|
{
|
||||||
|
loader: require.resolve('resolve-url-loader'),
|
||||||
|
options: {
|
||||||
|
sourceMap: isEnvProduction && shouldUseSourceMap,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
loader: require.resolve(preProcessor),
|
||||||
|
options: {
|
||||||
|
sourceMap: true,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return loaders;
|
||||||
|
};
|
||||||
|
|
||||||
|
return {
|
||||||
|
mode: 'production',
|
||||||
|
// Stop compilation early in production
|
||||||
|
bail: isEnvProduction,
|
||||||
|
devtool: isEnvProduction
|
||||||
|
? shouldUseSourceMap
|
||||||
|
? 'source-map'
|
||||||
|
: false
|
||||||
|
: isEnvDevelopment && 'cheap-module-source-map',
|
||||||
|
// These are the "entry points" to our application.
|
||||||
|
// This means they will be the "root" imports that are included in JS bundle.
|
||||||
|
entry: isEnvProduction ? [paths.appDemoIndexJs] : [
|
||||||
|
// Include an alternative client for WebpackDevServer. A client's job is to
|
||||||
|
// connect to WebpackDevServer by a socket and get notified about changes.
|
||||||
|
// When you save a file, the client will either apply hot updates (in case
|
||||||
|
// of CSS changes), or refresh the page (in case of JS changes). When you
|
||||||
|
// make a syntax error, this client will display a syntax error overlay.
|
||||||
|
// Note: instead of the default WebpackDevServer client, we use a custom one
|
||||||
|
// to bring better experience for Create React App users. You can replace
|
||||||
|
// the line below with these two lines if you prefer the stock client:
|
||||||
|
// require.resolve('webpack-dev-server/client') + '?/',
|
||||||
|
// require.resolve('webpack/hot/dev-server'),
|
||||||
|
isEnvDevelopment &&
|
||||||
|
require.resolve('react-dev-utils/webpackHotDevClient'),
|
||||||
|
// Finally, this is your app's code:
|
||||||
|
paths.appDemoIndexJs,
|
||||||
|
// We include the app code last so that if there is a runtime error during
|
||||||
|
// initialization, it doesn't blow up the WebpackDevServer client, and
|
||||||
|
// changing JS code would still trigger a refresh.
|
||||||
|
].filter(Boolean),
|
||||||
|
output: {
|
||||||
|
// The build folder.
|
||||||
|
path: isEnvProduction ? paths.appDemo : undefined,
|
||||||
|
// Add /* filename */ comments to generated require()s in the output.
|
||||||
|
pathinfo: isEnvDevelopment,
|
||||||
|
// There will be one main bundle, and one file per asynchronous chunk.
|
||||||
|
// In development, it does not produce real files.
|
||||||
|
filename: 'index.js',
|
||||||
|
// TODO: remove this when upgrading to webpack 5
|
||||||
|
futureEmitAssets: true,
|
||||||
|
// There are also additional JS chunk files if you use code splitting.
|
||||||
|
chunkFilename: 'static/js/[name].[contenthash:8].chunk.js',
|
||||||
|
// We inferred the "public path" (such as / or /my-project) from homepage.
|
||||||
|
// We use "/" in development.
|
||||||
|
publicPath: publicPath,
|
||||||
|
// Point sourcemap entries to original disk location (format as URL on Windows)
|
||||||
|
devtoolModuleFilenameTemplate: isEnvProduction
|
||||||
|
? info =>
|
||||||
|
path
|
||||||
|
.relative(paths.appSrcDemo, info.absoluteResourcePath)
|
||||||
|
.replace(/\\/g, '/')
|
||||||
|
: isEnvDevelopment &&
|
||||||
|
(info => path.resolve(info.absoluteResourcePath).replace(/\\/g, '/')),
|
||||||
|
// Prevents conflicts when multiple Webpack runtimes (from different apps)
|
||||||
|
// are used on the same page.
|
||||||
|
jsonpFunction: `webpackJsonp${appPackageJson.name}`,
|
||||||
|
},
|
||||||
|
optimization: {
|
||||||
|
minimize: isEnvProduction,
|
||||||
|
minimizer: [
|
||||||
|
// This is only used in production mode
|
||||||
|
new TerserPlugin({
|
||||||
|
terserOptions: {
|
||||||
|
parse: {
|
||||||
|
// We want terser to parse ecma 8 code. However, we don't want it
|
||||||
|
// to apply any minification steps that turns valid ecma 5 code
|
||||||
|
// into invalid ecma 5 code. This is why the 'compress' and 'output'
|
||||||
|
// sections only apply transformations that are ecma 5 safe
|
||||||
|
// https://github.com/facebook/create-react-app/pull/4234
|
||||||
|
ecma: 8,
|
||||||
|
},
|
||||||
|
compress: {
|
||||||
|
ecma: 5,
|
||||||
|
warnings: false,
|
||||||
|
// Disabled because of an issue with Uglify breaking seemingly valid code:
|
||||||
|
// https://github.com/facebook/create-react-app/issues/2376
|
||||||
|
// Pending further investigation:
|
||||||
|
// https://github.com/mishoo/UglifyJS2/issues/2011
|
||||||
|
comparisons: false,
|
||||||
|
// Disabled because of an issue with Terser breaking valid code:
|
||||||
|
// https://github.com/facebook/create-react-app/issues/5250
|
||||||
|
// Pending further investigation:
|
||||||
|
// https://github.com/terser-js/terser/issues/120
|
||||||
|
inline: 2,
|
||||||
|
},
|
||||||
|
mangle: {
|
||||||
|
safari10: true,
|
||||||
|
keep_classnames: true,
|
||||||
|
keep_fnames: true,
|
||||||
|
module: true
|
||||||
|
},
|
||||||
|
output: {
|
||||||
|
ecma: 5,
|
||||||
|
comments: false,
|
||||||
|
// Turned on because emoji and regex is not minified properly using default
|
||||||
|
// https://github.com/facebook/create-react-app/issues/2488
|
||||||
|
ascii_only: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
// Use multi-process parallel running to improve the build speed
|
||||||
|
// Default number of concurrent runs: os.cpus().length - 1
|
||||||
|
// Disabled on WSL (Windows Subsystem for Linux) due to an issue with Terser
|
||||||
|
// https://github.com/webpack-contrib/terser-webpack-plugin/issues/21
|
||||||
|
parallel: !isWsl,
|
||||||
|
// Enable file caching
|
||||||
|
cache: true,
|
||||||
|
sourceMap: shouldUseSourceMap,
|
||||||
|
}),
|
||||||
|
new OptimizeCSSAssetsPlugin({
|
||||||
|
cssProcessorOptions: {
|
||||||
|
parser: safePostCssParser,
|
||||||
|
map: shouldUseSourceMap
|
||||||
|
? {
|
||||||
|
// `inline: false` forces the sourcemap to be output into a
|
||||||
|
// separate file
|
||||||
|
inline: false,
|
||||||
|
// `annotation: true` appends the sourceMappingURL to the end of
|
||||||
|
// the css file, helping the browser find the sourcemap
|
||||||
|
annotation: true,
|
||||||
|
}
|
||||||
|
: false,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
// Automatically split vendor and commons
|
||||||
|
// https://twitter.com/wSokra/status/969633336732905474
|
||||||
|
// https://medium.com/webpack/webpack-4-code-splitting-chunk-graph-and-the-splitchunks-optimization-be739a861366
|
||||||
|
splitChunks: {
|
||||||
|
/*chunks: 'all',
|
||||||
|
name: false,*/
|
||||||
|
cacheGroups: {
|
||||||
|
default: false,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
// Keep the runtime chunk separated to enable long term caching
|
||||||
|
// https://twitter.com/wSokra/status/969679223278505985
|
||||||
|
runtimeChunk: false,
|
||||||
|
},
|
||||||
|
resolve: {
|
||||||
|
// This allows you to set a fallback for where Webpack should look for modules.
|
||||||
|
// We placed these paths second because we want `node_modules` to "win"
|
||||||
|
// if there are any conflicts. This matches Node resolution mechanism.
|
||||||
|
// https://github.com/facebook/create-react-app/issues/253
|
||||||
|
modules: ['node_modules', paths.appNodeModules].concat(
|
||||||
|
modules.additionalModulePaths || []
|
||||||
|
),
|
||||||
|
// These are the reasonable defaults supported by the Node ecosystem.
|
||||||
|
// We also include JSX as a common component filename extension to support
|
||||||
|
// some tools, although we do not recommend using it, see:
|
||||||
|
// https://github.com/facebook/create-react-app/issues/290
|
||||||
|
// `web` extension prefixes have been added for better support
|
||||||
|
// for React Native Web.
|
||||||
|
extensions: paths.moduleFileExtensions
|
||||||
|
.map(ext => `.${ext}`)
|
||||||
|
.filter(ext => useTypeScript || !ext.includes('ts')),
|
||||||
|
alias: {
|
||||||
|
// Support React Native Web
|
||||||
|
// https://www.smashingmagazine.com/2016/08/a-glimpse-into-the-future-with-react-native-for-web/
|
||||||
|
'react-native': 'react-native-web',
|
||||||
|
},
|
||||||
|
plugins: [
|
||||||
|
// Adds support for installing with Plug'n'Play, leading to faster installs and adding
|
||||||
|
// guards against forgotten dependencies and such.
|
||||||
|
PnpWebpackPlugin,
|
||||||
|
// Prevents users from importing files from outside of src/ (or node_modules/).
|
||||||
|
// This often causes confusion because we only process files within src/ with babel.
|
||||||
|
// To fix this, we prevent you from importing files out of src/ -- if you'd like to,
|
||||||
|
// please link the files into your node_modules/ and let module-resolution kick in.
|
||||||
|
// Make sure your source files are compiled, as they will not be processed in any way.
|
||||||
|
new ModuleScopePlugin(paths.appSrc, [paths.appPackageJson]),
|
||||||
|
],
|
||||||
|
},
|
||||||
|
resolveLoader: {
|
||||||
|
plugins: [
|
||||||
|
// Also related to Plug'n'Play, but this time it tells Webpack to load its loaders
|
||||||
|
// from the current package.
|
||||||
|
PnpWebpackPlugin.moduleLoader(module),
|
||||||
|
],
|
||||||
|
},
|
||||||
|
module: {
|
||||||
|
strictExportPresence: true,
|
||||||
|
rules: [
|
||||||
|
// Disable require.ensure as it's not a standard language feature.
|
||||||
|
{ parser: { requireEnsure: false } },
|
||||||
|
|
||||||
|
// First, run the linter.
|
||||||
|
// It's important to do this before Babel processes the JS.
|
||||||
|
{
|
||||||
|
test: /\.(js|mjs|jsx|ts|tsx)$/,
|
||||||
|
enforce: 'pre',
|
||||||
|
use: [
|
||||||
|
{
|
||||||
|
options: {
|
||||||
|
formatter: require.resolve('react-dev-utils/eslintFormatter'),
|
||||||
|
eslintPath: require.resolve('eslint'),
|
||||||
|
resolvePluginsRelativeTo: __dirname,
|
||||||
|
|
||||||
|
},
|
||||||
|
loader: require.resolve('eslint-loader'),
|
||||||
|
},
|
||||||
|
],
|
||||||
|
include: paths.appSrcDemo,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
// "oneOf" will traverse all following loaders until one will
|
||||||
|
// match the requirements. When no loader matches it will fall
|
||||||
|
// back to the "file" loader at the end of the loader list.
|
||||||
|
oneOf: [
|
||||||
|
// "url" loader works like "file" loader except that it embeds assets
|
||||||
|
// smaller than specified limit in bytes as data URLs to avoid requests.
|
||||||
|
// A missing `test` is equivalent to a match.
|
||||||
|
{
|
||||||
|
test: [/\.bmp$/, /\.gif$/, /\.jpe?g$/, /\.png$/],
|
||||||
|
loader: require.resolve('url-loader'),
|
||||||
|
options: {
|
||||||
|
limit: imageInlineSizeLimit,
|
||||||
|
name: 'static/media/[name].[hash:8].[ext]',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
// Process application JS with Babel.
|
||||||
|
// The preset includes JSX, Flow, TypeScript, and some ESnext features.
|
||||||
|
{
|
||||||
|
test: /\.(js|mjs|jsx|ts|tsx)$/,
|
||||||
|
include: paths.appSrcDemo,
|
||||||
|
loader: require.resolve('babel-loader'),
|
||||||
|
options: {
|
||||||
|
customize: require.resolve(
|
||||||
|
'babel-preset-react-app/webpack-overrides'
|
||||||
|
),
|
||||||
|
|
||||||
|
plugins: [
|
||||||
|
[
|
||||||
|
require.resolve('babel-plugin-named-asset-import'),
|
||||||
|
{
|
||||||
|
loaderMap: {
|
||||||
|
svg: {
|
||||||
|
ReactComponent: '@svgr/webpack?-prettier,-svgo,+ref![path]',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
],
|
||||||
|
// This is a feature of `babel-loader` for webpack (not Babel itself).
|
||||||
|
// It enables caching results in ./node_modules/.cache/babel-loader/
|
||||||
|
// directory for faster rebuilds.
|
||||||
|
cacheDirectory: true,
|
||||||
|
cacheCompression: isEnvProduction,
|
||||||
|
compact: isEnvProduction,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
// Process any JS outside of the app with Babel.
|
||||||
|
// Unlike the application JS, we only compile the standard ES features.
|
||||||
|
{
|
||||||
|
test: /\.(js|mjs)$/,
|
||||||
|
exclude: /@babel(?:\/|\\{1,2})runtime/,
|
||||||
|
loader: require.resolve('babel-loader'),
|
||||||
|
options: {
|
||||||
|
babelrc: false,
|
||||||
|
configFile: false,
|
||||||
|
compact: false,
|
||||||
|
presets: [
|
||||||
|
[
|
||||||
|
require.resolve('babel-preset-react-app/dependencies'),
|
||||||
|
{ helpers: true },
|
||||||
|
],
|
||||||
|
"@babel/preset-env",
|
||||||
|
"@babel/preset-react"
|
||||||
|
],
|
||||||
|
plugins: [
|
||||||
|
[
|
||||||
|
"@babel/plugin-proposal-class-properties"
|
||||||
|
]
|
||||||
|
],
|
||||||
|
cacheDirectory: true,
|
||||||
|
cacheCompression: isEnvProduction,
|
||||||
|
|
||||||
|
// If an error happens in a package, it's possible to be
|
||||||
|
// because it was compiled. Thus, we don't want the browser
|
||||||
|
// debugger to show the original code. Instead, the code
|
||||||
|
// being evaluated would be much more helpful.
|
||||||
|
sourceMaps: false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
// "postcss" loader applies autoprefixer to our CSS.
|
||||||
|
// "css" loader resolves paths in CSS and adds assets as dependencies.
|
||||||
|
// "style" loader turns CSS into JS modules that inject <style> tags.
|
||||||
|
// In production, we use MiniCSSExtractPlugin to extract that CSS
|
||||||
|
// to a file, but in development "style" loader enables hot editing
|
||||||
|
// of CSS.
|
||||||
|
// By default we support CSS Modules with the extension .module.css
|
||||||
|
{
|
||||||
|
test: cssRegex,
|
||||||
|
exclude: cssModuleRegex,
|
||||||
|
use: getStyleLoaders({
|
||||||
|
importLoaders: 1,
|
||||||
|
sourceMap: isEnvProduction && shouldUseSourceMap,
|
||||||
|
}),
|
||||||
|
// Don't consider CSS imports dead code even if the
|
||||||
|
// containing package claims to have no side effects.
|
||||||
|
// Remove this when webpack adds a warning or an error for this.
|
||||||
|
// See https://github.com/webpack/webpack/issues/6571
|
||||||
|
sideEffects: true,
|
||||||
|
},
|
||||||
|
// Adds support for CSS Modules (https://github.com/css-modules/css-modules)
|
||||||
|
// using the extension .module.css
|
||||||
|
{
|
||||||
|
test: cssModuleRegex,
|
||||||
|
use: getStyleLoaders({
|
||||||
|
importLoaders: 1,
|
||||||
|
sourceMap: isEnvProduction && shouldUseSourceMap,
|
||||||
|
modules: true,
|
||||||
|
getLocalIdent: getCSSModuleLocalIdent,
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
// Opt-in support for SASS (using .scss or .sass extensions).
|
||||||
|
// By default we support SASS Modules with the
|
||||||
|
// extensions .module.scss or .module.sass
|
||||||
|
{
|
||||||
|
test: sassRegex,
|
||||||
|
exclude: sassModuleRegex,
|
||||||
|
use: getStyleLoaders(
|
||||||
|
{
|
||||||
|
importLoaders: 2,
|
||||||
|
sourceMap: isEnvProduction && shouldUseSourceMap,
|
||||||
|
},
|
||||||
|
'sass-loader'
|
||||||
|
),
|
||||||
|
// Don't consider CSS imports dead code even if the
|
||||||
|
// containing package claims to have no side effects.
|
||||||
|
// Remove this when webpack adds a warning or an error for this.
|
||||||
|
// See https://github.com/webpack/webpack/issues/6571
|
||||||
|
sideEffects: true,
|
||||||
|
},
|
||||||
|
// Adds support for CSS Modules, but using SASS
|
||||||
|
// using the extension .module.scss or .module.sass
|
||||||
|
{
|
||||||
|
test: sassModuleRegex,
|
||||||
|
use: getStyleLoaders(
|
||||||
|
{
|
||||||
|
importLoaders: 2,
|
||||||
|
sourceMap: isEnvProduction && shouldUseSourceMap,
|
||||||
|
modules: true,
|
||||||
|
getLocalIdent: getCSSModuleLocalIdent,
|
||||||
|
},
|
||||||
|
'sass-loader'
|
||||||
|
),
|
||||||
|
},
|
||||||
|
// "file" loader makes sure those assets get served by WebpackDevServer.
|
||||||
|
// When you `import` an asset, you get its (virtual) filename.
|
||||||
|
// In production, they would get copied to the `build` folder.
|
||||||
|
// This loader doesn't use a "test" so it will catch all modules
|
||||||
|
// that fall through the other loaders.
|
||||||
|
{
|
||||||
|
loader: require.resolve('file-loader'),
|
||||||
|
// Exclude `js` files to keep "css" loader working as it injects
|
||||||
|
// its runtime that would otherwise be processed through "file" loader.
|
||||||
|
// Also exclude `html` and `json` extensions so they get processed
|
||||||
|
// by webpacks internal loaders.
|
||||||
|
exclude: [/\.(js|mjs|jsx|ts|tsx)$/, /\.html$/, /\.json$/],
|
||||||
|
options: {
|
||||||
|
name: 'static/media/[name].[hash:8].[ext]',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
// ** STOP ** Are you adding a new loader?
|
||||||
|
// Make sure to add the new loader(s) before the "file" loader.
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
},
|
},
|
||||||
plugins: [
|
plugins: [
|
||||||
// Prevents users from importing files from outside of src/ (or node_modules/).
|
// Generates an `index.html` file with the <script> injected.
|
||||||
// This often causes confusion because we only process files within src/ with babel.
|
new HtmlWebpackPlugin(
|
||||||
// To fix this, we prevent you from importing files out of src/ -- if you'd like to,
|
Object.assign(
|
||||||
// please link the files into your node_modules/ and let module-resolution kick in.
|
{},
|
||||||
// Make sure your source files are compiled, as they will not be processed in any way.
|
|
||||||
new ModuleScopePlugin(paths.appSrc, [paths.appPackageJson])
|
|
||||||
]
|
|
||||||
},
|
|
||||||
module: {
|
|
||||||
strictExportPresence: true,
|
|
||||||
rules: [
|
|
||||||
// TODO: Disable require.ensure as it's not a standard language feature.
|
|
||||||
// We are waiting for https://github.com/facebookincubator/create-react-app/issues/2176.
|
|
||||||
// { parser: { requireEnsure: false } },
|
|
||||||
|
|
||||||
// First, run the linter.
|
|
||||||
// It's important to do this before Babel processes the JS.
|
|
||||||
{
|
|
||||||
test: /\.(js|jsx|mjs)$/,
|
|
||||||
enforce: 'pre',
|
|
||||||
use: [
|
|
||||||
{
|
{
|
||||||
options: {
|
inject: true,
|
||||||
formatter: eslintFormatter,
|
template: paths.appHtml
|
||||||
eslintPath: require.resolve('eslint')
|
|
||||||
},
|
|
||||||
loader: require.resolve('eslint-loader')
|
|
||||||
}
|
|
||||||
],
|
|
||||||
include: paths.appDemoSrc // CRL: updated with library src folder
|
|
||||||
},
|
|
||||||
{
|
|
||||||
// "oneOf" will traverse all following loaders until one will
|
|
||||||
// match the requirements. When no loader matches it will fall
|
|
||||||
// back to the "file" loader at the end of the loader list.
|
|
||||||
oneOf: [
|
|
||||||
// "url" loader works just like "file" loader but it also embeds
|
|
||||||
// assets smaller than specified size as data URLs to avoid requests.
|
|
||||||
{
|
|
||||||
test: [/\.bmp$/, /\.gif$/, /\.jpe?g$/, /\.png$/],
|
|
||||||
loader: require.resolve('url-loader'),
|
|
||||||
options: {
|
|
||||||
limit: 10000,
|
|
||||||
name: 'media/[name].[ext]'
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
// Process JS with Babel.
|
isEnvProduction
|
||||||
{
|
? {
|
||||||
test: /\.(js|jsx|mjs)$/,
|
minify: {
|
||||||
include: [paths.appLibSrc, paths.appDemoSrc], // CRL: updated with library src folder
|
removeComments: true,
|
||||||
loader: require.resolve('babel-loader'),
|
collapseWhitespace: true,
|
||||||
options: {
|
removeRedundantAttributes: true,
|
||||||
compact: true
|
useShortDoctype: true,
|
||||||
}
|
removeEmptyAttributes: true,
|
||||||
},
|
removeStyleLinkTypeAttributes: true,
|
||||||
// The notation here is somewhat confusing.
|
keepClosingSlash: true,
|
||||||
// "postcss" loader applies autoprefixer to our CSS.
|
minifyJS: true,
|
||||||
// "css" loader resolves paths in CSS and adds assets as dependencies.
|
minifyCSS: true,
|
||||||
// "style" loader normally turns CSS into JS modules injecting <style>,
|
minifyURLs: true,
|
||||||
// but unlike in development configuration, we do something different.
|
|
||||||
// `ExtractTextPlugin` first applies the "postcss" and "css" loaders
|
|
||||||
// (second argument), then grabs the result CSS and puts it into a
|
|
||||||
// separate file in our build process. This way we actually ship
|
|
||||||
// a single CSS file in production instead of JS code injecting <style>
|
|
||||||
// tags. If you use code splitting, however, any async bundles will still
|
|
||||||
// use the "style" loader inside the async code so CSS from them won't be
|
|
||||||
// in the main CSS file.
|
|
||||||
{
|
|
||||||
test: /\.css$/,
|
|
||||||
loader: ExtractTextPlugin.extract(
|
|
||||||
Object.assign(
|
|
||||||
{
|
|
||||||
fallback: {
|
|
||||||
loader: require.resolve('style-loader'),
|
|
||||||
options: {
|
|
||||||
hmr: false
|
|
||||||
}
|
|
||||||
},
|
|
||||||
use: [
|
|
||||||
{
|
|
||||||
loader: require.resolve('css-loader'),
|
|
||||||
options: {
|
|
||||||
importLoaders: 1,
|
|
||||||
minimize: true,
|
|
||||||
sourceMap: shouldUseSourceMap
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
loader: require.resolve('postcss-loader'),
|
|
||||||
options: {
|
|
||||||
// Necessary for external CSS imports to work
|
|
||||||
// https://github.com/facebookincubator/create-react-app/issues/2677
|
|
||||||
ident: 'postcss',
|
|
||||||
plugins: () => [
|
|
||||||
require('postcss-flexbugs-fixes'),
|
|
||||||
autoprefixer({
|
|
||||||
browsers: [
|
|
||||||
'>1%',
|
|
||||||
'last 4 versions',
|
|
||||||
'Firefox ESR',
|
|
||||||
'not ie < 9' // React doesn't support IE8 anyway
|
|
||||||
],
|
|
||||||
flexbox: 'no-2009'
|
|
||||||
})
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
},
|
||||||
extractTextPluginOptions
|
}
|
||||||
)
|
: undefined
|
||||||
)
|
)
|
||||||
// Note: this won't work without `new ExtractTextPlugin()` in `plugins`.
|
),
|
||||||
},
|
// Inlines the webpack runtime script. This script is too small to warrant
|
||||||
// "file" loader makes sure assets end up in the `build` folder.
|
// a network request.
|
||||||
// When you `import` an asset, you get its filename.
|
isEnvProduction &&
|
||||||
// This loader doesn't use a "test" so it will catch all modules
|
shouldInlineRuntimeChunk &&
|
||||||
// that fall through the other loaders.
|
new InlineChunkHtmlPlugin(HtmlWebpackPlugin, [/runtime~.+[.]js/]),
|
||||||
{
|
// Makes some environment variables available in index.html.
|
||||||
loader: require.resolve('file-loader'),
|
// The public URL is available as %PUBLIC_URL% in index.html, e.g.:
|
||||||
// Exclude `js` files to keep "css" loader working as it injects
|
// <link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
|
||||||
// it's runtime that would otherwise processed through "file" loader.
|
// In production, it will be an empty string unless you specify "homepage"
|
||||||
// Also exclude `html` and `json` extensions so they get processed
|
// in `package.json`, in which case it will be the pathname of that URL.
|
||||||
// by webpacks internal loaders.
|
// In development, this will be an empty string.
|
||||||
exclude: [/\.js$/, /\.html$/, /\.json$/],
|
new InterpolateHtmlPlugin(HtmlWebpackPlugin, env.raw),
|
||||||
options: {
|
// This gives some necessary context to module not found errors, such as
|
||||||
name: 'media/[name].[ext]'
|
// the requesting resource.
|
||||||
}
|
new ModuleNotFoundPlugin(paths.appPath),
|
||||||
}
|
// Makes some environment variables available to the JS code, for example:
|
||||||
// ** STOP ** Are you adding a new loader?
|
// if (process.env.NODE_ENV === 'production') { ... }. See `./env.js`.
|
||||||
// Make sure to add the new loader(s) before the "file" loader.
|
// It is absolutely essential that NODE_ENV is set to production
|
||||||
]
|
// during a production build.
|
||||||
}
|
// Otherwise React will be compiled in the very slow development mode.
|
||||||
]
|
new webpack.DefinePlugin(env.stringified),
|
||||||
},
|
// This is necessary to emit hot updates (currently CSS only):
|
||||||
plugins: [
|
isEnvDevelopment && new webpack.HotModuleReplacementPlugin(),
|
||||||
// Makes some environment variables available to the JS code, for example:
|
// Watcher doesn't work well if you mistype casing in a path so we use
|
||||||
// if (process.env.NODE_ENV === 'production') { ... }. See `./env.js`.
|
// a plugin that prints an error when you attempt to do this.
|
||||||
// It is absolutely essential that NODE_ENV was set to production here.
|
// See https://github.com/facebook/create-react-app/issues/240
|
||||||
// Otherwise React will be compiled in the very slow development mode.
|
isEnvDevelopment && new CaseSensitivePathsPlugin(),
|
||||||
new InterpolateHtmlPlugin(env.raw),
|
// If you require a missing module and then `npm install` it, you still have
|
||||||
// Generates an `index.html` file with the <script> injected.
|
// to restart the development server for Webpack to discover it. This plugin
|
||||||
new HtmlWebpackPlugin({
|
// makes the discovery automatic so you don't have to restart.
|
||||||
inject: true,
|
// See https://github.com/facebook/create-react-app/issues/186
|
||||||
template: paths.appHtml
|
isEnvDevelopment &&
|
||||||
}),
|
new WatchMissingNodeModulesPlugin(paths.appNodeModules),
|
||||||
// Add module names to factory functions so they appear in browser profiler.
|
isEnvProduction &&
|
||||||
new webpack.NamedModulesPlugin(),
|
new MiniCssExtractPlugin({
|
||||||
new webpack.DefinePlugin(env.stringified),
|
// Options similar to the same options in webpackOptions.output
|
||||||
// Minify the code.
|
// both options are optional
|
||||||
new webpack.optimize.UglifyJsPlugin({
|
filename: 'index.css',
|
||||||
compress: false,
|
chunkFilename: 'index.[contenthash:8].chunk.css',
|
||||||
mangle: {
|
}),
|
||||||
safari10: true
|
// Generate a manifest file which contains a mapping of all asset filenames
|
||||||
},
|
// to their corresponding output file so that tools can pick it up without
|
||||||
output: {
|
// having to parse `index.html`.
|
||||||
comments: false,
|
/*new ManifestPlugin({
|
||||||
// Turned on because emoji and regex is not minified properly using default
|
fileName: 'asset-manifest.json',
|
||||||
// https://github.com/facebookincubator/create-react-app/issues/2488
|
publicPath: publicPath,
|
||||||
ascii_only: true
|
generate: (seed, files) => {
|
||||||
},
|
const manifestFiles = files.reduce(function(manifest, file) {
|
||||||
sourceMap: shouldUseSourceMap
|
manifest[file.name] = file.path;
|
||||||
}),
|
return manifest;
|
||||||
// Note: this won't work without ExtractTextPlugin.extract(..) in `loaders`.
|
}, seed);
|
||||||
new ExtractTextPlugin({
|
|
||||||
filename: cssFilename
|
return {
|
||||||
}),
|
files: manifestFiles,
|
||||||
// Moment.js is an extremely popular library that bundles large locale files
|
};
|
||||||
// by default due to how Webpack interprets its code. This is a practical
|
},
|
||||||
// solution that requires the user to opt into importing specific locales.
|
}),*/
|
||||||
// https://github.com/jmblog/how-to-optimize-momentjs-with-webpack
|
// Moment.js is an extremely popular library that bundles large locale files
|
||||||
// You can remove this if you don't use Moment.js:
|
// by default due to how Webpack interprets its code. This is a practical
|
||||||
new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
|
// solution that requires the user to opt into importing specific locales.
|
||||||
new CopyWebpackPlugin([
|
// https://github.com/jmblog/how-to-optimize-momentjs-with-webpack
|
||||||
{ from: `${paths.appPublic}/favicon.ico`, to: paths.appDemoBuild },
|
// You can remove this if you don't use Moment.js:
|
||||||
{ from: `${paths.appPublic}/manifest.json`, to: paths.appDemoBuild }
|
new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
|
||||||
])
|
// Generate a service worker script that will precache, and keep up to date,
|
||||||
],
|
// the HTML & assets that are part of the Webpack build.
|
||||||
// CRL: added externals block for library
|
/*isEnvProduction &&
|
||||||
// externals: {
|
new WorkboxWebpackPlugin.GenerateSW({
|
||||||
// 'react': 'react',
|
clientsClaim: true,
|
||||||
// 'react-dom': 'react-dom'
|
exclude: [/\.map$/, /asset-manifest\.json$/],
|
||||||
// },
|
importWorkboxFrom: 'cdn',
|
||||||
// Some libraries import Node modules but don't use them in the browser.
|
navigateFallback: publicUrl + '/index.html',
|
||||||
// Tell Webpack to provide empty mocks for them so importing them works.
|
navigateFallbackBlacklist: [
|
||||||
node: {
|
// Exclude URLs starting with /_, as they're likely an API call
|
||||||
dgram: 'empty',
|
new RegExp('^/_'),
|
||||||
fs: 'empty',
|
// Exclude URLs containing a dot, as they're likely a resource in
|
||||||
net: 'empty',
|
// public/ and not a SPA route
|
||||||
tls: 'empty',
|
new RegExp('/[^/]+\\.[^/]+$'),
|
||||||
child_process: 'empty'
|
],
|
||||||
}
|
}),*/
|
||||||
|
// TypeScript type checking
|
||||||
|
useTypeScript &&
|
||||||
|
new ForkTsCheckerWebpackPlugin({
|
||||||
|
typescript: resolve.sync('typescript', {
|
||||||
|
basedir: paths.appNodeModules,
|
||||||
|
}),
|
||||||
|
useTypescriptIncrementalApi: true,
|
||||||
|
checkSyntacticErrors: true,
|
||||||
|
resolveModuleNameModule: process.versions.pnp
|
||||||
|
? `${__dirname}/pnpTs.js`
|
||||||
|
: undefined,
|
||||||
|
resolveTypeReferenceDirectiveModule: process.versions.pnp
|
||||||
|
? `${__dirname}/pnpTs.js`
|
||||||
|
: undefined,
|
||||||
|
tsconfig: paths.appTsConfig,
|
||||||
|
reportFiles: [
|
||||||
|
'**',
|
||||||
|
'!**/__tests__/**',
|
||||||
|
'!**/?(*.)(spec|test).*',
|
||||||
|
'!**/src/setupProxy.*',
|
||||||
|
'!**/src/setupTests.*',
|
||||||
|
],
|
||||||
|
watch: paths.appSrcDemo,
|
||||||
|
silent: true,
|
||||||
|
// The formatter is invoked directly in WebpackDevServerUtils during development
|
||||||
|
formatter: isEnvProduction ? typescriptFormatter : undefined,
|
||||||
|
}),
|
||||||
|
].filter(Boolean),
|
||||||
|
// Some libraries import Node modules but don't use them in the browser.
|
||||||
|
// Tell Webpack to provide empty mocks for them so importing them works.
|
||||||
|
node: {
|
||||||
|
module: 'empty',
|
||||||
|
dgram: 'empty',
|
||||||
|
dns: 'mock',
|
||||||
|
fs: 'empty',
|
||||||
|
http2: 'empty',
|
||||||
|
net: 'empty',
|
||||||
|
tls: 'empty',
|
||||||
|
child_process: 'empty',
|
||||||
|
},
|
||||||
|
// Turn off performance processing because we utilize
|
||||||
|
// our own hints via the FileSizeReporter
|
||||||
|
performance: false,
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,259 +0,0 @@
|
|||||||
'use strict';
|
|
||||||
|
|
||||||
const autoprefixer = require('autoprefixer');
|
|
||||||
const path = require('path');
|
|
||||||
const webpack = require('webpack');
|
|
||||||
const HtmlWebpackPlugin = require('html-webpack-plugin');
|
|
||||||
const CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin');
|
|
||||||
const InterpolateHtmlPlugin = require('react-dev-utils/InterpolateHtmlPlugin');
|
|
||||||
const WatchMissingNodeModulesPlugin = require('react-dev-utils/WatchMissingNodeModulesPlugin');
|
|
||||||
const eslintFormatter = require('react-dev-utils/eslintFormatter');
|
|
||||||
const ModuleScopePlugin = require('react-dev-utils/ModuleScopePlugin');
|
|
||||||
const getClientEnvironment = require('./env');
|
|
||||||
const paths = require('./paths');
|
|
||||||
|
|
||||||
// Webpack uses `publicPath` to determine where the app is being served from.
|
|
||||||
// In development, we always serve from the root. This makes config easier.
|
|
||||||
const publicPath = '/';
|
|
||||||
// `publicUrl` is just like `publicPath`, but we will provide it to our app
|
|
||||||
// as %PUBLIC_URL% in `index.html` and `process.env.PUBLIC_URL` in JavaScript.
|
|
||||||
// Omit trailing slash as %PUBLIC_PATH%/xyz looks better than %PUBLIC_PATH%xyz.
|
|
||||||
const publicUrl = '';
|
|
||||||
// Get environment variables to inject into our app.
|
|
||||||
const env = getClientEnvironment(publicUrl);
|
|
||||||
|
|
||||||
// This is the development configuration.
|
|
||||||
// It is focused on developer experience and fast rebuilds.
|
|
||||||
// The production configuration is different and lives in a separate file.
|
|
||||||
module.exports = {
|
|
||||||
// You may want 'eval' instead if you prefer to see the compiled output in DevTools.
|
|
||||||
// See the discussion in https://github.com/facebookincubator/create-react-app/issues/343.
|
|
||||||
devtool: 'cheap-module-source-map',
|
|
||||||
// These are the "entry points" to our application.
|
|
||||||
// This means they will be the "root" imports that are included in JS bundle.
|
|
||||||
// The first two entry points enable "hot" CSS and auto-refreshes for JS.
|
|
||||||
entry: [
|
|
||||||
// Include an alternative client for WebpackDevServer. A client's job is to
|
|
||||||
// connect to WebpackDevServer by a socket and get notified about changes.
|
|
||||||
// When you save a file, the client will either apply hot updates (in case
|
|
||||||
// of CSS changes), or refresh the page (in case of JS changes). When you
|
|
||||||
// make a syntax error, this client will display a syntax error overlay.
|
|
||||||
// Note: instead of the default WebpackDevServer client, we use a custom one
|
|
||||||
// to bring better experience for Create React App users. You can replace
|
|
||||||
// the line below with these two lines if you prefer the stock client:
|
|
||||||
// require.resolve('webpack-dev-server/client') + '?/',
|
|
||||||
// require.resolve('webpack/hot/dev-server'),
|
|
||||||
require.resolve('react-dev-utils/webpackHotDevClient'),
|
|
||||||
// Finally, this is your app's code:
|
|
||||||
paths.appIndexJs,
|
|
||||||
// We include the app code last so that if there is a runtime error during
|
|
||||||
// initialization, it doesn't blow up the WebpackDevServer client, and
|
|
||||||
// changing JS code would still trigger a refresh.
|
|
||||||
],
|
|
||||||
output: {
|
|
||||||
// Add /* filename */ comments to generated require()s in the output.
|
|
||||||
pathinfo: true,
|
|
||||||
// This does not produce a real file. It's just the virtual path that is
|
|
||||||
// served by WebpackDevServer in development. This is the JS bundle
|
|
||||||
// containing code from all our entry points, and the Webpack runtime.
|
|
||||||
filename: 'static/js/bundle.js',
|
|
||||||
// There are also additional JS chunk files if you use code splitting.
|
|
||||||
chunkFilename: 'static/js/[name].chunk.js',
|
|
||||||
// This is the URL that app is served from. We use "/" in development.
|
|
||||||
publicPath: publicPath,
|
|
||||||
// Point sourcemap entries to original disk location (format as URL on Windows)
|
|
||||||
devtoolModuleFilenameTemplate: info =>
|
|
||||||
path.resolve(info.absoluteResourcePath).replace(/\\/g, '/'),
|
|
||||||
},
|
|
||||||
resolve: {
|
|
||||||
// This allows you to set a fallback for where Webpack should look for modules.
|
|
||||||
// We placed these paths second because we want `node_modules` to "win"
|
|
||||||
// if there are any conflicts. This matches Node resolution mechanism.
|
|
||||||
// https://github.com/facebookincubator/create-react-app/issues/253
|
|
||||||
modules: ['node_modules', paths.appNodeModules].concat(
|
|
||||||
// It is guaranteed to exist because we tweak it in `env.js`
|
|
||||||
process.env.NODE_PATH.split(path.delimiter).filter(Boolean)
|
|
||||||
),
|
|
||||||
// These are the reasonable defaults supported by the Node ecosystem.
|
|
||||||
// We also include JSX as a common component filename extension to support
|
|
||||||
// some tools, although we do not recommend using it, see:
|
|
||||||
// https://github.com/facebookincubator/create-react-app/issues/290
|
|
||||||
// `web` extension prefixes have been added for better support
|
|
||||||
// for React Native Web.
|
|
||||||
extensions: ['.web.js', '.mjs', '.js', '.json', '.web.jsx', '.jsx'],
|
|
||||||
alias: {
|
|
||||||
|
|
||||||
// Support React Native Web
|
|
||||||
// https://www.smashingmagazine.com/2016/08/a-glimpse-into-the-future-with-react-native-for-web/
|
|
||||||
'react-native': 'react-native-web',
|
|
||||||
},
|
|
||||||
plugins: [
|
|
||||||
// Prevents users from importing files from outside of src/ (or node_modules/).
|
|
||||||
// This often causes confusion because we only process files within src/ with babel.
|
|
||||||
// To fix this, we prevent you from importing files out of src/ -- if you'd like to,
|
|
||||||
// please link the files into your node_modules/ and let module-resolution kick in.
|
|
||||||
// Make sure your source files are compiled, as they will not be processed in any way.
|
|
||||||
new ModuleScopePlugin(paths.appSrc, [paths.appPackageJson]),
|
|
||||||
],
|
|
||||||
},
|
|
||||||
module: {
|
|
||||||
strictExportPresence: true,
|
|
||||||
rules: [
|
|
||||||
// TODO: Disable require.ensure as it's not a standard language feature.
|
|
||||||
// We are waiting for https://github.com/facebookincubator/create-react-app/issues/2176.
|
|
||||||
// { parser: { requireEnsure: false } },
|
|
||||||
|
|
||||||
// First, run the linter.
|
|
||||||
// It's important to do this before Babel processes the JS.
|
|
||||||
{
|
|
||||||
test: /\.(js|jsx|mjs)$/,
|
|
||||||
enforce: 'pre',
|
|
||||||
use: [
|
|
||||||
{
|
|
||||||
options: {
|
|
||||||
formatter: eslintFormatter,
|
|
||||||
eslintPath: require.resolve('eslint'),
|
|
||||||
|
|
||||||
},
|
|
||||||
loader: require.resolve('eslint-loader'),
|
|
||||||
},
|
|
||||||
],
|
|
||||||
include: paths.appSrc,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
// "oneOf" will traverse all following loaders until one will
|
|
||||||
// match the requirements. When no loader matches it will fall
|
|
||||||
// back to the "file" loader at the end of the loader list.
|
|
||||||
oneOf: [
|
|
||||||
// "url" loader works like "file" loader except that it embeds assets
|
|
||||||
// smaller than specified limit in bytes as data URLs to avoid requests.
|
|
||||||
// A missing `test` is equivalent to a match.
|
|
||||||
{
|
|
||||||
test: [/\.bmp$/, /\.gif$/, /\.jpe?g$/, /\.png$/],
|
|
||||||
loader: require.resolve('url-loader'),
|
|
||||||
options: {
|
|
||||||
limit: 10000,
|
|
||||||
name: 'static/media/[name].[hash:8].[ext]',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
// Process JS with Babel.
|
|
||||||
{
|
|
||||||
test: /\.(js|jsx|mjs)$/,
|
|
||||||
include: paths.appSrc,
|
|
||||||
loader: require.resolve('babel-loader'),
|
|
||||||
options: {
|
|
||||||
// This is a feature of `babel-loader` for webpack (not Babel itself).
|
|
||||||
// It enables caching results in ./node_modules/.cache/babel-loader/
|
|
||||||
// directory for faster rebuilds.
|
|
||||||
cacheDirectory: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
// "postcss" loader applies autoprefixer to our CSS.
|
|
||||||
// "css" loader resolves paths in CSS and adds assets as dependencies.
|
|
||||||
// "style" loader turns CSS into JS modules that inject <style> tags.
|
|
||||||
// In production, we use a plugin to extract that CSS to a file, but
|
|
||||||
// in development "style" loader enables hot editing of CSS.
|
|
||||||
{
|
|
||||||
test: /\.css$/,
|
|
||||||
use: [
|
|
||||||
require.resolve('style-loader'),
|
|
||||||
{
|
|
||||||
loader: require.resolve('css-loader'),
|
|
||||||
options: {
|
|
||||||
importLoaders: 1,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
loader: require.resolve('postcss-loader'),
|
|
||||||
options: {
|
|
||||||
// Necessary for external CSS imports to work
|
|
||||||
// https://github.com/facebookincubator/create-react-app/issues/2677
|
|
||||||
ident: 'postcss',
|
|
||||||
plugins: () => [
|
|
||||||
require('postcss-flexbugs-fixes'),
|
|
||||||
autoprefixer({
|
|
||||||
browsers: [
|
|
||||||
'>1%',
|
|
||||||
'last 4 versions',
|
|
||||||
'Firefox ESR',
|
|
||||||
'not ie < 9', // React doesn't support IE8 anyway
|
|
||||||
],
|
|
||||||
flexbox: 'no-2009',
|
|
||||||
}),
|
|
||||||
],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
// "file" loader makes sure those assets get served by WebpackDevServer.
|
|
||||||
// When you `import` an asset, you get its (virtual) filename.
|
|
||||||
// In production, they would get copied to the `build` folder.
|
|
||||||
// This loader doesn't use a "test" so it will catch all modules
|
|
||||||
// that fall through the other loaders.
|
|
||||||
{
|
|
||||||
// Exclude `js` files to keep "css" loader working as it injects
|
|
||||||
// it's runtime that would otherwise processed through "file" loader.
|
|
||||||
// Also exclude `html` and `json` extensions so they get processed
|
|
||||||
// by webpacks internal loaders.
|
|
||||||
exclude: [/\.js$/, /\.html$/, /\.json$/],
|
|
||||||
loader: require.resolve('file-loader'),
|
|
||||||
options: {
|
|
||||||
name: 'static/media/[name].[hash:8].[ext]',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
// ** STOP ** Are you adding a new loader?
|
|
||||||
// Make sure to add the new loader(s) before the "file" loader.
|
|
||||||
],
|
|
||||||
},
|
|
||||||
plugins: [
|
|
||||||
// Makes some environment variables available in index.html.
|
|
||||||
// The public URL is available as %PUBLIC_URL% in index.html, e.g.:
|
|
||||||
// <link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
|
|
||||||
// In development, this will be an empty string.
|
|
||||||
new InterpolateHtmlPlugin(env.raw),
|
|
||||||
// Generates an `index.html` file with the <script> injected.
|
|
||||||
new HtmlWebpackPlugin({
|
|
||||||
inject: true,
|
|
||||||
template: paths.appHtml,
|
|
||||||
}),
|
|
||||||
// Add module names to factory functions so they appear in browser profiler.
|
|
||||||
new webpack.NamedModulesPlugin(),
|
|
||||||
// Makes some environment variables available to the JS code, for example:
|
|
||||||
// if (process.env.NODE_ENV === 'development') { ... }. See `./env.js`.
|
|
||||||
new webpack.DefinePlugin(env.stringified),
|
|
||||||
// This is necessary to emit hot updates (currently CSS only):
|
|
||||||
new webpack.HotModuleReplacementPlugin(),
|
|
||||||
// Watcher doesn't work well if you mistype casing in a path so we use
|
|
||||||
// a plugin that prints an error when you attempt to do this.
|
|
||||||
// See https://github.com/facebookincubator/create-react-app/issues/240
|
|
||||||
new CaseSensitivePathsPlugin(),
|
|
||||||
// If you require a missing module and then `npm install` it, you still have
|
|
||||||
// to restart the development server for Webpack to discover it. This plugin
|
|
||||||
// makes the discovery automatic so you don't have to restart.
|
|
||||||
// See https://github.com/facebookincubator/create-react-app/issues/186
|
|
||||||
new WatchMissingNodeModulesPlugin(paths.appNodeModules),
|
|
||||||
// Moment.js is an extremely popular library that bundles large locale files
|
|
||||||
// by default due to how Webpack interprets its code. This is a practical
|
|
||||||
// solution that requires the user to opt into importing specific locales.
|
|
||||||
// https://github.com/jmblog/how-to-optimize-momentjs-with-webpack
|
|
||||||
// You can remove this if you don't use Moment.js:
|
|
||||||
new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
|
|
||||||
],
|
|
||||||
// Some libraries import Node modules but don't use them in the browser.
|
|
||||||
// Tell Webpack to provide empty mocks for them so importing them works.
|
|
||||||
node: {
|
|
||||||
dgram: 'empty',
|
|
||||||
fs: 'empty',
|
|
||||||
net: 'empty',
|
|
||||||
tls: 'empty',
|
|
||||||
child_process: 'empty',
|
|
||||||
},
|
|
||||||
// Turn off performance hints during development because we don't do any
|
|
||||||
// splitting or minification in interest of speed. These warnings become
|
|
||||||
// cumbersome.
|
|
||||||
performance: {
|
|
||||||
hints: false,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
@@ -0,0 +1,694 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
const fs = require('fs');
|
||||||
|
const isWsl = require('is-wsl');
|
||||||
|
const path = require('path');
|
||||||
|
const webpack = require('webpack');
|
||||||
|
const resolve = require('resolve');
|
||||||
|
const PnpWebpackPlugin = require('pnp-webpack-plugin');
|
||||||
|
const HtmlWebpackPlugin = require('html-webpack-plugin');
|
||||||
|
const CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin');
|
||||||
|
const InlineChunkHtmlPlugin = require('react-dev-utils/InlineChunkHtmlPlugin');
|
||||||
|
const TerserPlugin = require('terser-webpack-plugin');
|
||||||
|
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
|
||||||
|
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
|
||||||
|
const safePostCssParser = require('postcss-safe-parser');
|
||||||
|
const ManifestPlugin = require('webpack-manifest-plugin');
|
||||||
|
const InterpolateHtmlPlugin = require('react-dev-utils/InterpolateHtmlPlugin');
|
||||||
|
const WorkboxWebpackPlugin = require('workbox-webpack-plugin');
|
||||||
|
const WatchMissingNodeModulesPlugin = require('react-dev-utils/WatchMissingNodeModulesPlugin');
|
||||||
|
const ModuleScopePlugin = require('react-dev-utils/ModuleScopePlugin');
|
||||||
|
const getCSSModuleLocalIdent = require('react-dev-utils/getCSSModuleLocalIdent');
|
||||||
|
const paths = require('./paths');
|
||||||
|
const modules = require('./modules');
|
||||||
|
const getClientEnvironment = require('./env');
|
||||||
|
const ModuleNotFoundPlugin = require('react-dev-utils/ModuleNotFoundPlugin');
|
||||||
|
const ForkTsCheckerWebpackPlugin = require('react-dev-utils/ForkTsCheckerWebpackPlugin');
|
||||||
|
const typescriptFormatter = require('react-dev-utils/typescriptFormatter');
|
||||||
|
const CopyWebpackPlugin = require('copy-webpack-plugin');
|
||||||
|
const getPackageJson = require('./getPackageJson');
|
||||||
|
const PrettierPlugin = require("prettier-webpack-plugin");
|
||||||
|
const eslint = require('eslint');
|
||||||
|
|
||||||
|
const postcssNormalize = require('postcss-normalize');
|
||||||
|
|
||||||
|
const appPackageJson = require(paths.appPackageJson);
|
||||||
|
|
||||||
|
// Source maps are resource heavy and can cause out of memory issue for large source files.
|
||||||
|
const shouldUseSourceMap = process.env.GENERATE_SOURCEMAP !== 'false';
|
||||||
|
// Some apps do not need the benefits of saving a web request, so not inlining the chunk
|
||||||
|
// makes for a smoother build process.
|
||||||
|
const shouldInlineRuntimeChunk = process.env.INLINE_RUNTIME_CHUNK !== 'false';
|
||||||
|
|
||||||
|
const imageInlineSizeLimit = parseInt(
|
||||||
|
process.env.IMAGE_INLINE_SIZE_LIMIT || '10000'
|
||||||
|
);
|
||||||
|
|
||||||
|
// Check if TypeScript is setup
|
||||||
|
const useTypeScript = fs.existsSync(paths.appTsConfig);
|
||||||
|
|
||||||
|
// style files regexes
|
||||||
|
const cssRegex = /\.css$/;
|
||||||
|
const cssModuleRegex = /\.module\.css$/;
|
||||||
|
const sassRegex = /\.(scss|sass)$/;
|
||||||
|
const sassModuleRegex = /\.module\.(scss|sass)$/;
|
||||||
|
|
||||||
|
const {
|
||||||
|
version,
|
||||||
|
name,
|
||||||
|
license,
|
||||||
|
repository,
|
||||||
|
author,
|
||||||
|
} = getPackageJson('version', 'name', 'license', 'repository', 'author');
|
||||||
|
|
||||||
|
const banner = `
|
||||||
|
${name} v${version}
|
||||||
|
${repository.url}
|
||||||
|
|
||||||
|
Copyright (c) ${author.replace(/ *\<[^)]*\> */g, " ")}
|
||||||
|
|
||||||
|
This source code is licensed under the ${license} license found in the
|
||||||
|
LICENSE file in the root directory of this source tree.
|
||||||
|
`;
|
||||||
|
|
||||||
|
// This is the production and development configuration.
|
||||||
|
// It is focused on developer experience, fast rebuilds, and a minimal bundle.
|
||||||
|
module.exports = function(webpackEnv) {
|
||||||
|
const isEnvDevelopment = webpackEnv === 'development';
|
||||||
|
const isEnvProduction = webpackEnv === 'production';
|
||||||
|
|
||||||
|
// Webpack uses `publicPath` to determine where the app is being served from.
|
||||||
|
// It requires a trailing slash, or the file assets will get an incorrect path.
|
||||||
|
// In development, we always serve from the root. This makes config easier.
|
||||||
|
const publicPath = isEnvProduction
|
||||||
|
? paths.servedPath
|
||||||
|
: isEnvDevelopment && '/';
|
||||||
|
// Some apps do not use client-side routing with pushState.
|
||||||
|
// For these, "homepage" can be set to "." to enable relative asset paths.
|
||||||
|
const shouldUseRelativeAssetPaths = publicPath === './';
|
||||||
|
|
||||||
|
// `publicUrl` is just like `publicPath`, but we will provide it to our app
|
||||||
|
// as %PUBLIC_URL% in `index.html` and `process.env.PUBLIC_URL` in JavaScript.
|
||||||
|
// Omit trailing slash as %PUBLIC_URL%/xyz looks better than %PUBLIC_URL%xyz.
|
||||||
|
const publicUrl = isEnvProduction
|
||||||
|
? publicPath.slice(0, -1)
|
||||||
|
: isEnvDevelopment && '';
|
||||||
|
// Get environment variables to inject into our app.
|
||||||
|
const env = getClientEnvironment(publicUrl);
|
||||||
|
|
||||||
|
// common function to get style loaders
|
||||||
|
const getStyleLoaders = (cssOptions, preProcessor) => {
|
||||||
|
const loaders = [
|
||||||
|
isEnvDevelopment && require.resolve('style-loader'),
|
||||||
|
isEnvProduction && {
|
||||||
|
loader: MiniCssExtractPlugin.loader,
|
||||||
|
options: shouldUseRelativeAssetPaths ? { publicPath: '../../' } : {},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
loader: require.resolve('css-loader'),
|
||||||
|
options: cssOptions,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
// Options for PostCSS as we reference these options twice
|
||||||
|
// Adds vendor prefixing based on your specified browser support in
|
||||||
|
// package.json
|
||||||
|
loader: require.resolve('postcss-loader'),
|
||||||
|
options: {
|
||||||
|
// Necessary for external CSS imports to work
|
||||||
|
// https://github.com/facebook/create-react-app/issues/2677
|
||||||
|
ident: 'postcss',
|
||||||
|
plugins: () => [
|
||||||
|
require('postcss-flexbugs-fixes'),
|
||||||
|
require('postcss-preset-env')({
|
||||||
|
autoprefixer: {
|
||||||
|
flexbox: 'no-2009',
|
||||||
|
},
|
||||||
|
stage: 3,
|
||||||
|
}),
|
||||||
|
// Adds PostCSS Normalize as the reset css with default options,
|
||||||
|
// so that it honors browserslist config in package.json
|
||||||
|
// which in turn let's users customize the target behavior as per their needs.
|
||||||
|
postcssNormalize(),
|
||||||
|
],
|
||||||
|
sourceMap: isEnvProduction && shouldUseSourceMap,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
].filter(Boolean);
|
||||||
|
if (preProcessor) {
|
||||||
|
loaders.push(
|
||||||
|
{
|
||||||
|
loader: require.resolve('resolve-url-loader'),
|
||||||
|
options: {
|
||||||
|
sourceMap: isEnvProduction && shouldUseSourceMap,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
loader: require.resolve(preProcessor),
|
||||||
|
options: {
|
||||||
|
sourceMap: true,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return loaders;
|
||||||
|
};
|
||||||
|
|
||||||
|
return {
|
||||||
|
mode: isEnvProduction ? 'production' : isEnvDevelopment && 'development',
|
||||||
|
// Stop compilation early in production
|
||||||
|
bail: isEnvProduction,
|
||||||
|
devtool: isEnvProduction
|
||||||
|
? shouldUseSourceMap
|
||||||
|
? 'source-map'
|
||||||
|
: false
|
||||||
|
: isEnvDevelopment && 'cheap-module-source-map',
|
||||||
|
// These are the "entry points" to our application.
|
||||||
|
// This means they will be the "root" imports that are included in JS bundle.
|
||||||
|
entry: isEnvProduction ? [paths.appLibIndexJs] : [
|
||||||
|
// Include an alternative client for WebpackDevServer. A client's job is to
|
||||||
|
// connect to WebpackDevServer by a socket and get notified about changes.
|
||||||
|
// When you save a file, the client will either apply hot updates (in case
|
||||||
|
// of CSS changes), or refresh the page (in case of JS changes). When you
|
||||||
|
// make a syntax error, this client will display a syntax error overlay.
|
||||||
|
// Note: instead of the default WebpackDevServer client, we use a custom one
|
||||||
|
// to bring better experience for Create React App users. You can replace
|
||||||
|
// the line below with these two lines if you prefer the stock client:
|
||||||
|
// require.resolve('webpack-dev-server/client') + '?/',
|
||||||
|
// require.resolve('webpack/hot/dev-server'),
|
||||||
|
isEnvDevelopment &&
|
||||||
|
require.resolve('react-dev-utils/webpackHotDevClient'),
|
||||||
|
// Finally, this is your app's code:
|
||||||
|
paths.appIndexJs,
|
||||||
|
// We include the app code last so that if there is a runtime error during
|
||||||
|
// initialization, it doesn't blow up the WebpackDevServer client, and
|
||||||
|
// changing JS code would still trigger a refresh.
|
||||||
|
].filter(Boolean),
|
||||||
|
output: {
|
||||||
|
// The build folder.
|
||||||
|
path: isEnvProduction ? paths.appBuild : undefined,
|
||||||
|
// Add /* filename */ comments to generated require()s in the output.
|
||||||
|
pathinfo: isEnvDevelopment,
|
||||||
|
// There will be one main bundle, and one file per asynchronous chunk.
|
||||||
|
// In development, it does not produce real files.
|
||||||
|
filename: isEnvProduction
|
||||||
|
? 'index.js'
|
||||||
|
: isEnvDevelopment && 'static/js/bundle.js',
|
||||||
|
// TODO: remove this when upgrading to webpack 5
|
||||||
|
futureEmitAssets: true,
|
||||||
|
// There are also additional JS chunk files if you use code splitting.
|
||||||
|
chunkFilename: isEnvProduction
|
||||||
|
? 'static/js/[name].[contenthash:8].chunk.js'
|
||||||
|
: isEnvDevelopment && 'static/js/[name].chunk.js',
|
||||||
|
// We inferred the "public path" (such as / or /my-project) from homepage.
|
||||||
|
// We use "/" in development.
|
||||||
|
publicPath: publicPath,
|
||||||
|
library: "SimpleKeyboard",
|
||||||
|
libraryTarget: 'umd',
|
||||||
|
umdNamedDefine: true,
|
||||||
|
// Point sourcemap entries to original disk location (format as URL on Windows)
|
||||||
|
devtoolModuleFilenameTemplate: isEnvProduction
|
||||||
|
? info =>
|
||||||
|
path
|
||||||
|
.relative(paths.appSrcLib, info.absoluteResourcePath)
|
||||||
|
.replace(/\\/g, '/')
|
||||||
|
: isEnvDevelopment &&
|
||||||
|
(info => path.resolve(info.absoluteResourcePath).replace(/\\/g, '/')),
|
||||||
|
// Prevents conflicts when multiple Webpack runtimes (from different apps)
|
||||||
|
// are used on the same page.
|
||||||
|
jsonpFunction: `webpackJsonp${appPackageJson.name}`,
|
||||||
|
},
|
||||||
|
optimization: {
|
||||||
|
minimize: isEnvProduction,
|
||||||
|
minimizer: [
|
||||||
|
// This is only used in production mode
|
||||||
|
new TerserPlugin({
|
||||||
|
terserOptions: {
|
||||||
|
parse: {
|
||||||
|
// We want terser to parse ecma 8 code. However, we don't want it
|
||||||
|
// to apply any minification steps that turns valid ecma 5 code
|
||||||
|
// into invalid ecma 5 code. This is why the 'compress' and 'output'
|
||||||
|
// sections only apply transformations that are ecma 5 safe
|
||||||
|
// https://github.com/facebook/create-react-app/pull/4234
|
||||||
|
ecma: 8,
|
||||||
|
},
|
||||||
|
compress: {
|
||||||
|
ecma: 5,
|
||||||
|
warnings: false,
|
||||||
|
// Disabled because of an issue with Uglify breaking seemingly valid code:
|
||||||
|
// https://github.com/facebook/create-react-app/issues/2376
|
||||||
|
// Pending further investigation:
|
||||||
|
// https://github.com/mishoo/UglifyJS2/issues/2011
|
||||||
|
comparisons: false,
|
||||||
|
// Disabled because of an issue with Terser breaking valid code:
|
||||||
|
// https://github.com/facebook/create-react-app/issues/5250
|
||||||
|
// Pending further investigation:
|
||||||
|
// https://github.com/terser-js/terser/issues/120
|
||||||
|
inline: 2,
|
||||||
|
},
|
||||||
|
mangle: {
|
||||||
|
safari10: true,
|
||||||
|
keep_classnames: true,
|
||||||
|
keep_fnames: true,
|
||||||
|
module: true
|
||||||
|
},
|
||||||
|
output: {
|
||||||
|
ecma: 5,
|
||||||
|
comments: false,
|
||||||
|
// Turned on because emoji and regex is not minified properly using default
|
||||||
|
// https://github.com/facebook/create-react-app/issues/2488
|
||||||
|
ascii_only: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
// Use multi-process parallel running to improve the build speed
|
||||||
|
// Default number of concurrent runs: os.cpus().length - 1
|
||||||
|
// Disabled on WSL (Windows Subsystem for Linux) due to an issue with Terser
|
||||||
|
// https://github.com/webpack-contrib/terser-webpack-plugin/issues/21
|
||||||
|
parallel: !isWsl,
|
||||||
|
// Enable file caching
|
||||||
|
cache: true,
|
||||||
|
sourceMap: shouldUseSourceMap,
|
||||||
|
}),
|
||||||
|
new webpack.BannerPlugin({
|
||||||
|
banner: banner,
|
||||||
|
entryOnly: true
|
||||||
|
}),
|
||||||
|
new OptimizeCSSAssetsPlugin({
|
||||||
|
cssProcessorOptions: {
|
||||||
|
parser: safePostCssParser,
|
||||||
|
map: shouldUseSourceMap
|
||||||
|
? {
|
||||||
|
// `inline: false` forces the sourcemap to be output into a
|
||||||
|
// separate file
|
||||||
|
inline: false,
|
||||||
|
// `annotation: true` appends the sourceMappingURL to the end of
|
||||||
|
// the css file, helping the browser find the sourcemap
|
||||||
|
annotation: true,
|
||||||
|
}
|
||||||
|
: false,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
// Automatically split vendor and commons
|
||||||
|
// https://twitter.com/wSokra/status/969633336732905474
|
||||||
|
// https://medium.com/webpack/webpack-4-code-splitting-chunk-graph-and-the-splitchunks-optimization-be739a861366
|
||||||
|
splitChunks: {
|
||||||
|
//chunks: 'all',
|
||||||
|
cacheGroups: {
|
||||||
|
default: false,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
// Keep the runtime chunk separated to enable long term caching
|
||||||
|
// https://twitter.com/wSokra/status/969679223278505985
|
||||||
|
runtimeChunk: false,
|
||||||
|
},
|
||||||
|
resolve: {
|
||||||
|
// This allows you to set a fallback for where Webpack should look for modules.
|
||||||
|
// We placed these paths second because we want `node_modules` to "win"
|
||||||
|
// if there are any conflicts. This matches Node resolution mechanism.
|
||||||
|
// https://github.com/facebook/create-react-app/issues/253
|
||||||
|
modules: ['node_modules', paths.appNodeModules].concat(
|
||||||
|
modules.additionalModulePaths || []
|
||||||
|
),
|
||||||
|
// These are the reasonable defaults supported by the Node ecosystem.
|
||||||
|
// We also include JSX as a common component filename extension to support
|
||||||
|
// some tools, although we do not recommend using it, see:
|
||||||
|
// https://github.com/facebook/create-react-app/issues/290
|
||||||
|
// `web` extension prefixes have been added for better support
|
||||||
|
// for React Native Web.
|
||||||
|
extensions: paths.moduleFileExtensions
|
||||||
|
.map(ext => `.${ext}`)
|
||||||
|
.filter(ext => useTypeScript || !ext.includes('ts')),
|
||||||
|
alias: {
|
||||||
|
// Support React Native Web
|
||||||
|
// https://www.smashingmagazine.com/2016/08/a-glimpse-into-the-future-with-react-native-for-web/
|
||||||
|
'react-native': 'react-native-web',
|
||||||
|
},
|
||||||
|
plugins: [
|
||||||
|
// Adds support for installing with Plug'n'Play, leading to faster installs and adding
|
||||||
|
// guards against forgotten dependencies and such.
|
||||||
|
PnpWebpackPlugin,
|
||||||
|
// Prevents users from importing files from outside of src/ (or node_modules/).
|
||||||
|
// This often causes confusion because we only process files within src/ with babel.
|
||||||
|
// To fix this, we prevent you from importing files out of src/ -- if you'd like to,
|
||||||
|
// please link the files into your node_modules/ and let module-resolution kick in.
|
||||||
|
// Make sure your source files are compiled, as they will not be processed in any way.
|
||||||
|
new ModuleScopePlugin(paths.appSrc, [paths.appPackageJson]),
|
||||||
|
],
|
||||||
|
},
|
||||||
|
resolveLoader: {
|
||||||
|
plugins: [
|
||||||
|
// Also related to Plug'n'Play, but this time it tells Webpack to load its loaders
|
||||||
|
// from the current package.
|
||||||
|
PnpWebpackPlugin.moduleLoader(module),
|
||||||
|
],
|
||||||
|
},
|
||||||
|
module: {
|
||||||
|
strictExportPresence: true,
|
||||||
|
rules: [
|
||||||
|
// Disable require.ensure as it's not a standard language feature.
|
||||||
|
{ parser: { requireEnsure: false } },
|
||||||
|
|
||||||
|
// First, run the linter.
|
||||||
|
// It's important to do this before Babel processes the JS.
|
||||||
|
{
|
||||||
|
test: /\.(js|mjs|jsx|ts|tsx)$/,
|
||||||
|
enforce: 'pre',
|
||||||
|
use: [
|
||||||
|
{
|
||||||
|
options: {
|
||||||
|
formatter: require.resolve('react-dev-utils/eslintFormatter'),
|
||||||
|
eslintPath: require.resolve('eslint'),
|
||||||
|
resolvePluginsRelativeTo: __dirname,
|
||||||
|
|
||||||
|
},
|
||||||
|
loader: require.resolve('eslint-loader'),
|
||||||
|
},
|
||||||
|
],
|
||||||
|
include: paths.appSrcLib,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
// "oneOf" will traverse all following loaders until one will
|
||||||
|
// match the requirements. When no loader matches it will fall
|
||||||
|
// back to the "file" loader at the end of the loader list.
|
||||||
|
oneOf: [
|
||||||
|
// "url" loader works like "file" loader except that it embeds assets
|
||||||
|
// smaller than specified limit in bytes as data URLs to avoid requests.
|
||||||
|
// A missing `test` is equivalent to a match.
|
||||||
|
{
|
||||||
|
test: [/\.bmp$/, /\.gif$/, /\.jpe?g$/, /\.png$/],
|
||||||
|
loader: require.resolve('url-loader'),
|
||||||
|
options: {
|
||||||
|
limit: imageInlineSizeLimit,
|
||||||
|
name: 'static/media/[name].[hash:8].[ext]',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
// Process application JS with Babel.
|
||||||
|
// The preset includes JSX, Flow, TypeScript, and some ESnext features.
|
||||||
|
{
|
||||||
|
test: /\.(js|mjs|jsx|ts|tsx)$/,
|
||||||
|
include: paths.appSrcLib,
|
||||||
|
loader: require.resolve('babel-loader'),
|
||||||
|
options: {
|
||||||
|
customize: require.resolve(
|
||||||
|
'babel-preset-react-app/webpack-overrides'
|
||||||
|
),
|
||||||
|
|
||||||
|
plugins: [
|
||||||
|
[
|
||||||
|
require.resolve('babel-plugin-named-asset-import'),
|
||||||
|
{
|
||||||
|
loaderMap: {
|
||||||
|
svg: {
|
||||||
|
ReactComponent: '@svgr/webpack?-prettier,-svgo,+ref![path]',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
],
|
||||||
|
// This is a feature of `babel-loader` for webpack (not Babel itself).
|
||||||
|
// It enables caching results in ./node_modules/.cache/babel-loader/
|
||||||
|
// directory for faster rebuilds.
|
||||||
|
cacheDirectory: true,
|
||||||
|
cacheCompression: isEnvProduction,
|
||||||
|
compact: isEnvProduction,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
// Process any JS outside of the app with Babel.
|
||||||
|
// Unlike the application JS, we only compile the standard ES features.
|
||||||
|
{
|
||||||
|
test: /\.(js|mjs)$/,
|
||||||
|
exclude: /@babel(?:\/|\\{1,2})runtime/,
|
||||||
|
loader: require.resolve('babel-loader'),
|
||||||
|
options: {
|
||||||
|
babelrc: false,
|
||||||
|
configFile: false,
|
||||||
|
compact: false,
|
||||||
|
presets: [
|
||||||
|
[
|
||||||
|
require.resolve('babel-preset-react-app/dependencies'),
|
||||||
|
{ helpers: true },
|
||||||
|
],
|
||||||
|
"@babel/preset-env",
|
||||||
|
"@babel/preset-react"
|
||||||
|
],
|
||||||
|
plugins: [
|
||||||
|
[
|
||||||
|
"@babel/plugin-proposal-class-properties"
|
||||||
|
]
|
||||||
|
],
|
||||||
|
cacheDirectory: true,
|
||||||
|
cacheCompression: isEnvProduction,
|
||||||
|
|
||||||
|
// If an error happens in a package, it's possible to be
|
||||||
|
// because it was compiled. Thus, we don't want the browser
|
||||||
|
// debugger to show the original code. Instead, the code
|
||||||
|
// being evaluated would be much more helpful.
|
||||||
|
sourceMaps: false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
// "postcss" loader applies autoprefixer to our CSS.
|
||||||
|
// "css" loader resolves paths in CSS and adds assets as dependencies.
|
||||||
|
// "style" loader turns CSS into JS modules that inject <style> tags.
|
||||||
|
// In production, we use MiniCSSExtractPlugin to extract that CSS
|
||||||
|
// to a file, but in development "style" loader enables hot editing
|
||||||
|
// of CSS.
|
||||||
|
// By default we support CSS Modules with the extension .module.css
|
||||||
|
{
|
||||||
|
test: cssRegex,
|
||||||
|
exclude: cssModuleRegex,
|
||||||
|
use: getStyleLoaders({
|
||||||
|
importLoaders: 1,
|
||||||
|
sourceMap: isEnvProduction && shouldUseSourceMap,
|
||||||
|
}),
|
||||||
|
// Don't consider CSS imports dead code even if the
|
||||||
|
// containing package claims to have no side effects.
|
||||||
|
// Remove this when webpack adds a warning or an error for this.
|
||||||
|
// See https://github.com/webpack/webpack/issues/6571
|
||||||
|
sideEffects: true,
|
||||||
|
},
|
||||||
|
// Adds support for CSS Modules (https://github.com/css-modules/css-modules)
|
||||||
|
// using the extension .module.css
|
||||||
|
{
|
||||||
|
test: cssModuleRegex,
|
||||||
|
use: getStyleLoaders({
|
||||||
|
importLoaders: 1,
|
||||||
|
sourceMap: isEnvProduction && shouldUseSourceMap,
|
||||||
|
modules: true,
|
||||||
|
getLocalIdent: getCSSModuleLocalIdent,
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
// Opt-in support for SASS (using .scss or .sass extensions).
|
||||||
|
// By default we support SASS Modules with the
|
||||||
|
// extensions .module.scss or .module.sass
|
||||||
|
{
|
||||||
|
test: sassRegex,
|
||||||
|
exclude: sassModuleRegex,
|
||||||
|
use: getStyleLoaders(
|
||||||
|
{
|
||||||
|
importLoaders: 2,
|
||||||
|
sourceMap: isEnvProduction && shouldUseSourceMap,
|
||||||
|
},
|
||||||
|
'sass-loader'
|
||||||
|
),
|
||||||
|
// Don't consider CSS imports dead code even if the
|
||||||
|
// containing package claims to have no side effects.
|
||||||
|
// Remove this when webpack adds a warning or an error for this.
|
||||||
|
// See https://github.com/webpack/webpack/issues/6571
|
||||||
|
sideEffects: true,
|
||||||
|
},
|
||||||
|
// Adds support for CSS Modules, but using SASS
|
||||||
|
// using the extension .module.scss or .module.sass
|
||||||
|
{
|
||||||
|
test: sassModuleRegex,
|
||||||
|
use: getStyleLoaders(
|
||||||
|
{
|
||||||
|
importLoaders: 2,
|
||||||
|
sourceMap: isEnvProduction && shouldUseSourceMap,
|
||||||
|
modules: true,
|
||||||
|
getLocalIdent: getCSSModuleLocalIdent,
|
||||||
|
},
|
||||||
|
'sass-loader'
|
||||||
|
),
|
||||||
|
},
|
||||||
|
// "file" loader makes sure those assets get served by WebpackDevServer.
|
||||||
|
// When you `import` an asset, you get its (virtual) filename.
|
||||||
|
// In production, they would get copied to the `build` folder.
|
||||||
|
// This loader doesn't use a "test" so it will catch all modules
|
||||||
|
// that fall through the other loaders.
|
||||||
|
{
|
||||||
|
loader: require.resolve('file-loader'),
|
||||||
|
// Exclude `js` files to keep "css" loader working as it injects
|
||||||
|
// its runtime that would otherwise be processed through "file" loader.
|
||||||
|
// Also exclude `html` and `json` extensions so they get processed
|
||||||
|
// by webpacks internal loaders.
|
||||||
|
exclude: [/\.(js|mjs|jsx|ts|tsx)$/, /\.html$/, /\.json$/],
|
||||||
|
options: {
|
||||||
|
name: 'static/media/[name].[hash:8].[ext]',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
// ** STOP ** Are you adding a new loader?
|
||||||
|
// Make sure to add the new loader(s) before the "file" loader.
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
plugins: [
|
||||||
|
isEnvDevelopment &&
|
||||||
|
// Generates an `index.html` file with the <script> injected.
|
||||||
|
new HtmlWebpackPlugin(
|
||||||
|
Object.assign(
|
||||||
|
{},
|
||||||
|
{
|
||||||
|
inject: true,
|
||||||
|
template: paths.appHtml,
|
||||||
|
},
|
||||||
|
isEnvProduction
|
||||||
|
? {
|
||||||
|
minify: {
|
||||||
|
removeComments: true,
|
||||||
|
collapseWhitespace: true,
|
||||||
|
removeRedundantAttributes: true,
|
||||||
|
useShortDoctype: true,
|
||||||
|
removeEmptyAttributes: true,
|
||||||
|
removeStyleLinkTypeAttributes: true,
|
||||||
|
keepClosingSlash: true,
|
||||||
|
minifyJS: true,
|
||||||
|
minifyCSS: true,
|
||||||
|
minifyURLs: true,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
: undefined
|
||||||
|
)
|
||||||
|
),
|
||||||
|
// Inlines the webpack runtime script. This script is too small to warrant
|
||||||
|
// a network request.
|
||||||
|
isEnvProduction &&
|
||||||
|
shouldInlineRuntimeChunk &&
|
||||||
|
new InlineChunkHtmlPlugin(HtmlWebpackPlugin, [/runtime~.+[.]js/]),
|
||||||
|
// Makes some environment variables available in index.html.
|
||||||
|
// The public URL is available as %PUBLIC_URL% in index.html, e.g.:
|
||||||
|
// <link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
|
||||||
|
// In production, it will be an empty string unless you specify "homepage"
|
||||||
|
// in `package.json`, in which case it will be the pathname of that URL.
|
||||||
|
// In development, this will be an empty string.
|
||||||
|
new InterpolateHtmlPlugin(HtmlWebpackPlugin, env.raw),
|
||||||
|
// This gives some necessary context to module not found errors, such as
|
||||||
|
// the requesting resource.
|
||||||
|
new ModuleNotFoundPlugin(paths.appPath),
|
||||||
|
// Makes some environment variables available to the JS code, for example:
|
||||||
|
// if (process.env.NODE_ENV === 'production') { ... }. See `./env.js`.
|
||||||
|
// It is absolutely essential that NODE_ENV is set to production
|
||||||
|
// during a production build.
|
||||||
|
// Otherwise React will be compiled in the very slow development mode.
|
||||||
|
new webpack.DefinePlugin(env.stringified),
|
||||||
|
// This is necessary to emit hot updates (currently CSS only):
|
||||||
|
isEnvDevelopment && new webpack.HotModuleReplacementPlugin(),
|
||||||
|
// Watcher doesn't work well if you mistype casing in a path so we use
|
||||||
|
// a plugin that prints an error when you attempt to do this.
|
||||||
|
// See https://github.com/facebook/create-react-app/issues/240
|
||||||
|
isEnvDevelopment && new CaseSensitivePathsPlugin(),
|
||||||
|
// If you require a missing module and then `npm install` it, you still have
|
||||||
|
// to restart the development server for Webpack to discover it. This plugin
|
||||||
|
// makes the discovery automatic so you don't have to restart.
|
||||||
|
// See https://github.com/facebook/create-react-app/issues/186
|
||||||
|
isEnvDevelopment &&
|
||||||
|
new WatchMissingNodeModulesPlugin(paths.appNodeModules),
|
||||||
|
isEnvProduction &&
|
||||||
|
new MiniCssExtractPlugin({
|
||||||
|
// Options similar to the same options in webpackOptions.output
|
||||||
|
// both options are optional
|
||||||
|
filename: 'css/index.css',
|
||||||
|
chunkFilename: 'css/index.[contenthash:8].chunk.css',
|
||||||
|
}),
|
||||||
|
// Generate a manifest file which contains a mapping of all asset filenames
|
||||||
|
// to their corresponding output file so that tools can pick it up without
|
||||||
|
// having to parse `index.html`.
|
||||||
|
/*new ManifestPlugin({
|
||||||
|
fileName: 'asset-manifest.json',
|
||||||
|
publicPath: publicPath,
|
||||||
|
generate: (seed, files) => {
|
||||||
|
const manifestFiles = files.reduce(function(manifest, file) {
|
||||||
|
manifest[file.name] = file.path;
|
||||||
|
return manifest;
|
||||||
|
}, seed);
|
||||||
|
|
||||||
|
return {
|
||||||
|
files: manifestFiles,
|
||||||
|
};
|
||||||
|
},
|
||||||
|
}),*/
|
||||||
|
// Moment.js is an extremely popular library that bundles large locale files
|
||||||
|
// by default due to how Webpack interprets its code. This is a practical
|
||||||
|
// solution that requires the user to opt into importing specific locales.
|
||||||
|
// https://github.com/jmblog/how-to-optimize-momentjs-with-webpack
|
||||||
|
// You can remove this if you don't use Moment.js:
|
||||||
|
new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
|
||||||
|
new CopyWebpackPlugin([
|
||||||
|
{
|
||||||
|
from: `${paths.appSrcLibTypes}`,
|
||||||
|
to: paths.appBuild
|
||||||
|
}
|
||||||
|
]),
|
||||||
|
new PrettierPlugin(),
|
||||||
|
// Generate a service worker script that will precache, and keep up to date,
|
||||||
|
// the HTML & assets that are part of the Webpack build.
|
||||||
|
/*isEnvProduction &&
|
||||||
|
new WorkboxWebpackPlugin.GenerateSW({
|
||||||
|
clientsClaim: true,
|
||||||
|
exclude: [/\.map$/, /asset-manifest\.json$/],
|
||||||
|
importWorkboxFrom: 'cdn',
|
||||||
|
navigateFallback: publicUrl + '/index.html',
|
||||||
|
navigateFallbackBlacklist: [
|
||||||
|
// Exclude URLs starting with /_, as they're likely an API call
|
||||||
|
new RegExp('^/_'),
|
||||||
|
// Exclude URLs containing a dot, as they're likely a resource in
|
||||||
|
// public/ and not a SPA route
|
||||||
|
new RegExp('/[^/]+\\.[^/]+$'),
|
||||||
|
],
|
||||||
|
}),*/
|
||||||
|
// TypeScript type checking
|
||||||
|
useTypeScript &&
|
||||||
|
new ForkTsCheckerWebpackPlugin({
|
||||||
|
typescript: resolve.sync('typescript', {
|
||||||
|
basedir: paths.appNodeModules,
|
||||||
|
}),
|
||||||
|
async: isEnvDevelopment,
|
||||||
|
useTypescriptIncrementalApi: true,
|
||||||
|
checkSyntacticErrors: true,
|
||||||
|
resolveModuleNameModule: process.versions.pnp
|
||||||
|
? `${__dirname}/pnpTs.js`
|
||||||
|
: undefined,
|
||||||
|
resolveTypeReferenceDirectiveModule: process.versions.pnp
|
||||||
|
? `${__dirname}/pnpTs.js`
|
||||||
|
: undefined,
|
||||||
|
tsconfig: paths.appTsConfig,
|
||||||
|
reportFiles: [
|
||||||
|
'**',
|
||||||
|
'!**/__tests__/**',
|
||||||
|
'!**/?(*.)(spec|test).*',
|
||||||
|
'!**/src/setupProxy.*',
|
||||||
|
'!**/src/setupTests.*',
|
||||||
|
],
|
||||||
|
watch: paths.appSrcLib,
|
||||||
|
silent: true,
|
||||||
|
// The formatter is invoked directly in WebpackDevServerUtils during development
|
||||||
|
formatter: isEnvProduction ? typescriptFormatter : undefined,
|
||||||
|
}),
|
||||||
|
].filter(Boolean),
|
||||||
|
// Some libraries import Node modules but don't use them in the browser.
|
||||||
|
// Tell Webpack to provide empty mocks for them so importing them works.
|
||||||
|
node: {
|
||||||
|
module: 'empty',
|
||||||
|
dgram: 'empty',
|
||||||
|
dns: 'mock',
|
||||||
|
fs: 'empty',
|
||||||
|
http2: 'empty',
|
||||||
|
net: 'empty',
|
||||||
|
tls: 'empty',
|
||||||
|
child_process: 'empty',
|
||||||
|
},
|
||||||
|
// Turn off performance processing because we utilize
|
||||||
|
// our own hints via the FileSizeReporter
|
||||||
|
performance: false,
|
||||||
|
};
|
||||||
|
};
|
||||||
@@ -1,275 +0,0 @@
|
|||||||
'use strict';
|
|
||||||
|
|
||||||
const autoprefixer = require('autoprefixer');
|
|
||||||
const path = require('path');
|
|
||||||
const webpack = require('webpack');
|
|
||||||
const ExtractTextPlugin = require('extract-text-webpack-plugin');
|
|
||||||
const eslintFormatter = require('react-dev-utils/eslintFormatter');
|
|
||||||
const ModuleScopePlugin = require('react-dev-utils/ModuleScopePlugin');
|
|
||||||
const paths = require('./paths');
|
|
||||||
const getClientEnvironment = require('./env');
|
|
||||||
|
|
||||||
// Webpack uses `publicPath` to determine where the app is being served from.
|
|
||||||
// It requires a trailing slash, or the file assets will get an incorrect path.
|
|
||||||
const publicPath = paths.servedPath;
|
|
||||||
// Some apps do not use client-side routing with pushState.
|
|
||||||
// For these, "homepage" can be set to "." to enable relative asset paths.
|
|
||||||
const shouldUseRelativeAssetPaths = publicPath === './';
|
|
||||||
// Source maps are resource heavy and can cause out of memory issue for large source files.
|
|
||||||
const shouldUseSourceMap = process.env.GENERATE_SOURCEMAP !== 'false';
|
|
||||||
// `publicUrl` is just like `publicPath`, but we will provide it to our app
|
|
||||||
// as %PUBLIC_URL% in `index.html` and `process.env.PUBLIC_URL` in JavaScript.
|
|
||||||
// Omit trailing slash as %PUBLIC_URL%/xyz looks better than %PUBLIC_URL%xyz.
|
|
||||||
const publicUrl = publicPath.slice(0, -1);
|
|
||||||
// Get environment variables to inject into our app.
|
|
||||||
const env = getClientEnvironment(publicUrl);
|
|
||||||
|
|
||||||
// Assert this just to be safe.
|
|
||||||
// Development builds of React are slow and not intended for production.
|
|
||||||
if (env.stringified['process.env'].NODE_ENV !== '"production"') {
|
|
||||||
throw new Error('Production builds must have NODE_ENV=production.');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Note: defined here because it will be used more than once.
|
|
||||||
const cssFilename = 'css/index.css';
|
|
||||||
|
|
||||||
// ExtractTextPlugin expects the build output to be flat.
|
|
||||||
// (See https://github.com/webpack-contrib/extract-text-webpack-plugin/issues/27)
|
|
||||||
// However, our output is structured with css, js and media folders.
|
|
||||||
// To have this structure working with relative paths, we have to use custom options.
|
|
||||||
const extractTextPluginOptions = shouldUseRelativeAssetPaths
|
|
||||||
? // Making sure that the publicPath goes back to to build folder.
|
|
||||||
{ publicPath: Array(cssFilename.split('/').length).join('../') }
|
|
||||||
: {};
|
|
||||||
|
|
||||||
// This is the production configuration.
|
|
||||||
// It compiles slowly and is focused on producing a fast and minimal bundle.
|
|
||||||
// The development configuration is different and lives in a separate file.
|
|
||||||
module.exports = {
|
|
||||||
// Don't attempt to continue if there are any errors.
|
|
||||||
bail: true,
|
|
||||||
// We generate sourcemaps in production. This is slow but gives good results.
|
|
||||||
// You can exclude the *.map files from the build during deployment.
|
|
||||||
devtool: shouldUseSourceMap ? 'source-map' : false,
|
|
||||||
// In production, we only want to load the app code.
|
|
||||||
entry: [paths.appLibIndexJs], // CRL: library index file instead of app index
|
|
||||||
output: {
|
|
||||||
// CRL: Updated whole block with library specific info
|
|
||||||
path: paths.appBuild,
|
|
||||||
filename: 'index.js',
|
|
||||||
libraryTarget: 'umd',
|
|
||||||
library: 'SimpleKeyboard'
|
|
||||||
},
|
|
||||||
resolve: {
|
|
||||||
// This allows you to set a fallback for where Webpack should look for modules.
|
|
||||||
// We placed these paths second because we want `node_modules` to "win"
|
|
||||||
// if there are any conflicts. This matches Node resolution mechanism.
|
|
||||||
// https://github.com/facebookincubator/create-react-app/issues/253
|
|
||||||
modules: ['node_modules', paths.appNodeModules].concat(
|
|
||||||
// It is guaranteed to exist because we tweak it in `env.js`
|
|
||||||
process.env.NODE_PATH.split(path.delimiter).filter(Boolean)
|
|
||||||
),
|
|
||||||
// These are the reasonable defaults supported by the Node ecosystem.
|
|
||||||
// We also include JSX as a common component filename extension to support
|
|
||||||
// some tools, although we do not recommend using it, see:
|
|
||||||
// https://github.com/facebookincubator/create-react-app/issues/290
|
|
||||||
// `web` extension prefixes have been added for better support
|
|
||||||
// for React Native Web.
|
|
||||||
extensions: ['.web.js', '.mjs', '.js', '.json', '.web.jsx', '.jsx'],
|
|
||||||
alias: {
|
|
||||||
|
|
||||||
// Support React Native Web
|
|
||||||
// https://www.smashingmagazine.com/2016/08/a-glimpse-into-the-future-with-react-native-for-web/
|
|
||||||
'react-native': 'react-native-web',
|
|
||||||
},
|
|
||||||
plugins: [
|
|
||||||
// Prevents users from importing files from outside of src/ (or node_modules/).
|
|
||||||
// This often causes confusion because we only process files within src/ with babel.
|
|
||||||
// To fix this, we prevent you from importing files out of src/ -- if you'd like to,
|
|
||||||
// please link the files into your node_modules/ and let module-resolution kick in.
|
|
||||||
// Make sure your source files are compiled, as they will not be processed in any way.
|
|
||||||
new ModuleScopePlugin(paths.appSrc, [paths.appPackageJson]),
|
|
||||||
],
|
|
||||||
},
|
|
||||||
module: {
|
|
||||||
strictExportPresence: true,
|
|
||||||
rules: [
|
|
||||||
// TODO: Disable require.ensure as it's not a standard language feature.
|
|
||||||
// We are waiting for https://github.com/facebookincubator/create-react-app/issues/2176.
|
|
||||||
// { parser: { requireEnsure: false } },
|
|
||||||
|
|
||||||
// First, run the linter.
|
|
||||||
// It's important to do this before Babel processes the JS.
|
|
||||||
{
|
|
||||||
test: /\.(js|jsx|mjs)$/,
|
|
||||||
enforce: 'pre',
|
|
||||||
use: [
|
|
||||||
{
|
|
||||||
options: {
|
|
||||||
formatter: eslintFormatter,
|
|
||||||
eslintPath: require.resolve('eslint'),
|
|
||||||
|
|
||||||
},
|
|
||||||
loader: require.resolve('eslint-loader'),
|
|
||||||
},
|
|
||||||
],
|
|
||||||
include: paths.appLibSrc, // CRL: updated with library src folder
|
|
||||||
},
|
|
||||||
{
|
|
||||||
// "oneOf" will traverse all following loaders until one will
|
|
||||||
// match the requirements. When no loader matches it will fall
|
|
||||||
// back to the "file" loader at the end of the loader list.
|
|
||||||
oneOf: [
|
|
||||||
// "url" loader works just like "file" loader but it also embeds
|
|
||||||
// assets smaller than specified size as data URLs to avoid requests.
|
|
||||||
{
|
|
||||||
test: [/\.bmp$/, /\.gif$/, /\.jpe?g$/, /\.png$/],
|
|
||||||
loader: require.resolve('url-loader'),
|
|
||||||
options: {
|
|
||||||
limit: 10000,
|
|
||||||
name: 'media/[name].[ext]',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
// Process JS with Babel.
|
|
||||||
{
|
|
||||||
test: /\.(js|jsx|mjs)$/,
|
|
||||||
include: paths.appLibSrc, // CRL: updated with library src folder
|
|
||||||
loader: require.resolve('babel-loader'),
|
|
||||||
options: {
|
|
||||||
|
|
||||||
compact: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
// The notation here is somewhat confusing.
|
|
||||||
// "postcss" loader applies autoprefixer to our CSS.
|
|
||||||
// "css" loader resolves paths in CSS and adds assets as dependencies.
|
|
||||||
// "style" loader normally turns CSS into JS modules injecting <style>,
|
|
||||||
// but unlike in development configuration, we do something different.
|
|
||||||
// `ExtractTextPlugin` first applies the "postcss" and "css" loaders
|
|
||||||
// (second argument), then grabs the result CSS and puts it into a
|
|
||||||
// separate file in our build process. This way we actually ship
|
|
||||||
// a single CSS file in production instead of JS code injecting <style>
|
|
||||||
// tags. If you use code splitting, however, any async bundles will still
|
|
||||||
// use the "style" loader inside the async code so CSS from them won't be
|
|
||||||
// in the main CSS file.
|
|
||||||
{
|
|
||||||
test: /\.css$/,
|
|
||||||
loader: ExtractTextPlugin.extract(
|
|
||||||
Object.assign(
|
|
||||||
{
|
|
||||||
fallback: {
|
|
||||||
loader: require.resolve('style-loader'),
|
|
||||||
options: {
|
|
||||||
hmr: false,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
use: [
|
|
||||||
{
|
|
||||||
loader: require.resolve('css-loader'),
|
|
||||||
options: {
|
|
||||||
importLoaders: 1,
|
|
||||||
minimize: true,
|
|
||||||
sourceMap: shouldUseSourceMap,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
loader: require.resolve('postcss-loader'),
|
|
||||||
options: {
|
|
||||||
// Necessary for external CSS imports to work
|
|
||||||
// https://github.com/facebookincubator/create-react-app/issues/2677
|
|
||||||
ident: 'postcss',
|
|
||||||
plugins: () => [
|
|
||||||
require('postcss-flexbugs-fixes'),
|
|
||||||
autoprefixer({
|
|
||||||
browsers: [
|
|
||||||
'>1%',
|
|
||||||
'last 4 versions',
|
|
||||||
'Firefox ESR',
|
|
||||||
'not ie < 9', // React doesn't support IE8 anyway
|
|
||||||
],
|
|
||||||
flexbox: 'no-2009',
|
|
||||||
}),
|
|
||||||
],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
extractTextPluginOptions
|
|
||||||
)
|
|
||||||
),
|
|
||||||
// Note: this won't work without `new ExtractTextPlugin()` in `plugins`.
|
|
||||||
},
|
|
||||||
// "file" loader makes sure assets end up in the `build` folder.
|
|
||||||
// When you `import` an asset, you get its filename.
|
|
||||||
// This loader doesn't use a "test" so it will catch all modules
|
|
||||||
// that fall through the other loaders.
|
|
||||||
{
|
|
||||||
loader: require.resolve('file-loader'),
|
|
||||||
// Exclude `js` files to keep "css" loader working as it injects
|
|
||||||
// it's runtime that would otherwise processed through "file" loader.
|
|
||||||
// Also exclude `html` and `json` extensions so they get processed
|
|
||||||
// by webpacks internal loaders.
|
|
||||||
exclude: [/\.js$/, /\.html$/, /\.json$/],
|
|
||||||
options: {
|
|
||||||
name: 'media/[name].[ext]',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
// ** STOP ** Are you adding a new loader?
|
|
||||||
// Make sure to add the new loader(s) before the "file" loader.
|
|
||||||
],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
plugins: [
|
|
||||||
// Makes some environment variables available to the JS code, for example:
|
|
||||||
// if (process.env.NODE_ENV === 'production') { ... }. See `./env.js`.
|
|
||||||
// It is absolutely essential that NODE_ENV was set to production here.
|
|
||||||
// Otherwise React will be compiled in the very slow development mode.
|
|
||||||
new webpack.DefinePlugin(env.stringified),
|
|
||||||
// Minify the code.
|
|
||||||
new webpack.optimize.UglifyJsPlugin({
|
|
||||||
compress: {
|
|
||||||
warnings: false,
|
|
||||||
// Disabled because of an issue with Uglify breaking seemingly valid code:
|
|
||||||
// https://github.com/facebookincubator/create-react-app/issues/2376
|
|
||||||
// Pending further investigation:
|
|
||||||
// https://github.com/mishoo/UglifyJS2/issues/2011
|
|
||||||
comparisons: false,
|
|
||||||
},
|
|
||||||
mangle: {
|
|
||||||
safari10: true,
|
|
||||||
},
|
|
||||||
output: {
|
|
||||||
comments: false,
|
|
||||||
// Turned on because emoji and regex is not minified properly using default
|
|
||||||
// https://github.com/facebookincubator/create-react-app/issues/2488
|
|
||||||
ascii_only: true,
|
|
||||||
},
|
|
||||||
sourceMap: shouldUseSourceMap,
|
|
||||||
}),
|
|
||||||
// Note: this won't work without ExtractTextPlugin.extract(..) in `loaders`.
|
|
||||||
new ExtractTextPlugin({
|
|
||||||
filename: cssFilename,
|
|
||||||
}),
|
|
||||||
// Moment.js is an extremely popular library that bundles large locale files
|
|
||||||
// by default due to how Webpack interprets its code. This is a practical
|
|
||||||
// solution that requires the user to opt into importing specific locales.
|
|
||||||
// https://github.com/jmblog/how-to-optimize-momentjs-with-webpack
|
|
||||||
// You can remove this if you don't use Moment.js:
|
|
||||||
new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
|
|
||||||
],
|
|
||||||
// CRL: added externals block for library
|
|
||||||
externals: {
|
|
||||||
'react': 'react',
|
|
||||||
'react-dom': 'react-dom'
|
|
||||||
},
|
|
||||||
// Some libraries import Node modules but don't use them in the browser.
|
|
||||||
// Tell Webpack to provide empty mocks for them so importing them works.
|
|
||||||
node: {
|
|
||||||
dgram: 'empty',
|
|
||||||
fs: 'empty',
|
|
||||||
net: 'empty',
|
|
||||||
tls: 'empty',
|
|
||||||
child_process: 'empty',
|
|
||||||
},
|
|
||||||
};
|
|
||||||
@@ -1,10 +1,11 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const errorOverlayMiddleware = require('react-dev-utils/errorOverlayMiddleware');
|
const errorOverlayMiddleware = require('react-dev-utils/errorOverlayMiddleware');
|
||||||
|
const evalSourceMapMiddleware = require('react-dev-utils/evalSourceMapMiddleware');
|
||||||
const noopServiceWorkerMiddleware = require('react-dev-utils/noopServiceWorkerMiddleware');
|
const noopServiceWorkerMiddleware = require('react-dev-utils/noopServiceWorkerMiddleware');
|
||||||
const path = require('path');
|
const ignoredFiles = require('react-dev-utils/ignoredFiles');
|
||||||
const config = require('./webpack.config.dev');
|
|
||||||
const paths = require('./paths');
|
const paths = require('./paths');
|
||||||
|
const fs = require('fs');
|
||||||
|
|
||||||
const protocol = process.env.HTTPS === 'true' ? 'https' : 'http';
|
const protocol = process.env.HTTPS === 'true' ? 'https' : 'http';
|
||||||
const host = process.env.HOST || '0.0.0.0';
|
const host = process.env.HOST || '0.0.0.0';
|
||||||
@@ -17,8 +18,8 @@ module.exports = function(proxy, allowedHost) {
|
|||||||
// https://medium.com/webpack/webpack-dev-server-middleware-security-issues-1489d950874a
|
// https://medium.com/webpack/webpack-dev-server-middleware-security-issues-1489d950874a
|
||||||
// However, it made several existing use cases such as development in cloud
|
// However, it made several existing use cases such as development in cloud
|
||||||
// environment or subdomains in development significantly more complicated:
|
// environment or subdomains in development significantly more complicated:
|
||||||
// https://github.com/facebookincubator/create-react-app/issues/2271
|
// https://github.com/facebook/create-react-app/issues/2271
|
||||||
// https://github.com/facebookincubator/create-react-app/issues/2233
|
// https://github.com/facebook/create-react-app/issues/2233
|
||||||
// While we're investigating better solutions, for now we will take a
|
// While we're investigating better solutions, for now we will take a
|
||||||
// compromise. Since our WDS configuration only serves files in the `public`
|
// compromise. Since our WDS configuration only serves files in the `public`
|
||||||
// folder we won't consider accessing them a vulnerability. However, if you
|
// folder we won't consider accessing them a vulnerability. However, if you
|
||||||
@@ -59,41 +60,44 @@ module.exports = function(proxy, allowedHost) {
|
|||||||
hot: true,
|
hot: true,
|
||||||
// It is important to tell WebpackDevServer to use the same "root" path
|
// It is important to tell WebpackDevServer to use the same "root" path
|
||||||
// as we specified in the config. In development, we always serve from /.
|
// as we specified in the config. In development, we always serve from /.
|
||||||
publicPath: config.output.publicPath,
|
publicPath: '/',
|
||||||
// WebpackDevServer is noisy by default so we emit custom message instead
|
// WebpackDevServer is noisy by default so we emit custom message instead
|
||||||
// by listening to the compiler events with `compiler.plugin` calls above.
|
// by listening to the compiler events with `compiler.hooks[...].tap` calls above.
|
||||||
quiet: true,
|
quiet: true,
|
||||||
// Reportedly, this avoids CPU overload on some systems.
|
// Reportedly, this avoids CPU overload on some systems.
|
||||||
// https://github.com/facebookincubator/create-react-app/issues/293
|
// https://github.com/facebook/create-react-app/issues/293
|
||||||
// src/node_modules is not ignored to support absolute imports
|
// src/node_modules is not ignored to support absolute imports
|
||||||
// https://github.com/facebookincubator/create-react-app/issues/1065
|
// https://github.com/facebook/create-react-app/issues/1065
|
||||||
watchOptions: {
|
watchOptions: {
|
||||||
ignored: new RegExp(
|
ignored: ignoredFiles(paths.appSrc),
|
||||||
`^(?!${path
|
|
||||||
.normalize(paths.appSrc + '/')
|
|
||||||
.replace(/[\\]+/g, '\\\\')}).+[\\\\/]node_modules[\\\\/]`,
|
|
||||||
'g'
|
|
||||||
),
|
|
||||||
},
|
},
|
||||||
// Enable HTTPS if the HTTPS environment variable is set to 'true'
|
// Enable HTTPS if the HTTPS environment variable is set to 'true'
|
||||||
https: protocol === 'https',
|
https: protocol === 'https',
|
||||||
host: host,
|
host,
|
||||||
overlay: false,
|
overlay: false,
|
||||||
historyApiFallback: {
|
historyApiFallback: {
|
||||||
// Paths with dots should still use the history fallback.
|
// Paths with dots should still use the history fallback.
|
||||||
// See https://github.com/facebookincubator/create-react-app/issues/387.
|
// See https://github.com/facebook/create-react-app/issues/387.
|
||||||
disableDotRule: true,
|
disableDotRule: true,
|
||||||
},
|
},
|
||||||
public: allowedHost,
|
public: allowedHost,
|
||||||
proxy,
|
proxy,
|
||||||
before(app) {
|
before(app, server) {
|
||||||
|
if (fs.existsSync(paths.proxySetup)) {
|
||||||
|
// This registers user provided middleware for proxy reasons
|
||||||
|
require(paths.proxySetup)(app);
|
||||||
|
}
|
||||||
|
|
||||||
|
// This lets us fetch source contents from webpack for the error overlay
|
||||||
|
app.use(evalSourceMapMiddleware(server));
|
||||||
// This lets us open files from the runtime error overlay.
|
// This lets us open files from the runtime error overlay.
|
||||||
app.use(errorOverlayMiddleware());
|
app.use(errorOverlayMiddleware());
|
||||||
|
|
||||||
// This service worker file is effectively a 'no-op' that will reset any
|
// This service worker file is effectively a 'no-op' that will reset any
|
||||||
// previous service worker registered for the same host:port combination.
|
// previous service worker registered for the same host:port combination.
|
||||||
// We do this in development to avoid hitting the production cache if
|
// We do this in development to avoid hitting the production cache if
|
||||||
// it used the same host and port.
|
// it used the same host and port.
|
||||||
// https://github.com/facebookincubator/create-react-app/issues/2272#issuecomment-302832432
|
// https://github.com/facebook/create-react-app/issues/2272#issuecomment-302832432
|
||||||
app.use(noopServiceWorkerMiddleware());
|
app.use(noopServiceWorkerMiddleware());
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
Generated
+9997
-7169
File diff suppressed because it is too large
Load Diff
+126
-65
@@ -1,14 +1,17 @@
|
|||||||
{
|
{
|
||||||
"name": "simple-keyboard",
|
"name": "simple-keyboard",
|
||||||
"version": "2.3.1",
|
"version": "2.27.1",
|
||||||
"description": "On-screen Virtual Keyboard",
|
"description": "On-screen Javascript Virtual Keyboard",
|
||||||
"main": "build/index.js",
|
"main": "build/index.js",
|
||||||
|
"types": "build/index.d.ts",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "node scripts/start.js",
|
"start": "node scripts/start.js",
|
||||||
"build": "node scripts/build.js",
|
"build": "node scripts/build.js",
|
||||||
"demo": "node scripts/demo.js",
|
"demo": "node scripts/demo.js",
|
||||||
"test": "node scripts/test.js --env=jsdom",
|
"test": "node scripts/test.js",
|
||||||
"prepublish": "npm run build"
|
"coverage": "node scripts/test.js --coverage --watchAll=false",
|
||||||
|
"prepare": "npm run build",
|
||||||
|
"trypublish": "npm publish || true"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@@ -18,7 +21,7 @@
|
|||||||
"bugs": {
|
"bugs": {
|
||||||
"url": "https://github.com/hodgef/simple-keyboard/issues"
|
"url": "https://github.com/hodgef/simple-keyboard/issues"
|
||||||
},
|
},
|
||||||
"homepage": "https://franciscohodge.com/simple-keyboard",
|
"homepage": "https://virtual-keyboard.js.org/",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"javascript",
|
"javascript",
|
||||||
"es6",
|
"es6",
|
||||||
@@ -26,99 +29,157 @@
|
|||||||
"keyboard",
|
"keyboard",
|
||||||
"onscreen",
|
"onscreen",
|
||||||
"virtual",
|
"virtual",
|
||||||
|
"screen-keyboard",
|
||||||
"component",
|
"component",
|
||||||
"virtual-keyboard",
|
"virtual-keyboard",
|
||||||
"touchscreen",
|
"touchscreen",
|
||||||
"touch-screen"
|
"touch-screen",
|
||||||
|
"kiosk",
|
||||||
|
"osk",
|
||||||
|
"js"
|
||||||
],
|
],
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {},
|
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"autoprefixer": "7.1.6",
|
"@babel/core": "7.7.2",
|
||||||
"babel-core": "^6.26.3",
|
"@babel/plugin-proposal-class-properties": "^7.7.0",
|
||||||
"babel-eslint": "7.2.3",
|
"@babel/preset-env": "^7.7.1",
|
||||||
"babel-jest": "20.0.3",
|
"@babel/preset-react": "^7.7.0",
|
||||||
"babel-loader": "7.1.2",
|
"@svgr/webpack": "4.3.3",
|
||||||
"babel-preset-react-app": "^3.1.2",
|
"@typescript-eslint/eslint-plugin": "1.13.0",
|
||||||
"babel-runtime": "6.26.0",
|
"@typescript-eslint/parser": "1.13.0",
|
||||||
"case-sensitive-paths-webpack-plugin": "2.1.1",
|
"babel-eslint": "10.0.3",
|
||||||
"chalk": "1.1.3",
|
"babel-jest": "^24.8.0",
|
||||||
"copy-webpack-plugin": "^4.3.1",
|
"babel-loader": "8.0.6",
|
||||||
"css-loader": "0.28.7",
|
"babel-plugin-named-asset-import": "^0.3.3",
|
||||||
"dotenv": "4.0.0",
|
"babel-preset-react-app": "^9.0.1",
|
||||||
"eslint": "4.10.0",
|
"camelcase": "^5.2.0",
|
||||||
"eslint-config-react-app": "^2.0.1",
|
"case-sensitive-paths-webpack-plugin": "2.2.0",
|
||||||
"eslint-loader": "1.9.0",
|
"copy-webpack-plugin": "^5.0.5",
|
||||||
"eslint-plugin-flowtype": "2.39.1",
|
"css-loader": "3.2.0",
|
||||||
"eslint-plugin-import": "2.8.0",
|
"dotenv": "8.2.0",
|
||||||
"eslint-plugin-jsx-a11y": "5.1.1",
|
"dotenv-expand": "5.1.0",
|
||||||
"eslint-plugin-react": "7.4.0",
|
"eslint": "^6.6.0",
|
||||||
"extract-text-webpack-plugin": "3.0.2",
|
"eslint-config-react-app": "^5.0.1",
|
||||||
"file-loader": "1.1.5",
|
"eslint-loader": "3.0.2",
|
||||||
"fs-extra": "3.0.1",
|
"eslint-plugin-flowtype": "3.13.0",
|
||||||
"html-webpack-plugin": "2.29.0",
|
"eslint-plugin-import": "2.18.2",
|
||||||
"jest": "20.0.4",
|
"eslint-plugin-jsx-a11y": "6.2.3",
|
||||||
"object-assign": "4.1.1",
|
"eslint-plugin-react": "7.16.0",
|
||||||
"postcss-flexbugs-fixes": "3.2.0",
|
"eslint-plugin-react-hooks": "^2.2.0",
|
||||||
"postcss-loader": "2.0.8",
|
"file-loader": "4.2.0",
|
||||||
"promise": "8.0.1",
|
"fs-extra": "8.1.0",
|
||||||
"prop-types": "^15.6.1",
|
"html-webpack-plugin": "4.0.0-beta.8",
|
||||||
"raf": "3.4.0",
|
"identity-obj-proxy": "3.0.0",
|
||||||
"react": "^16.2.0",
|
"is-wsl": "^2.1.0",
|
||||||
"react-dev-utils": "^4.2.1",
|
"jest": "24.9.0",
|
||||||
"react-dom": "^16.2.0",
|
"jest-environment-jsdom-fourteen": "0.1.0",
|
||||||
"style-loader": "0.19.0",
|
"jest-resolve": "24.9.0",
|
||||||
"sw-precache-webpack-plugin": "0.11.4",
|
"jest-watch-typeahead": "0.4.0",
|
||||||
"url-loader": "0.6.2",
|
"mini-css-extract-plugin": "0.8.0",
|
||||||
"webpack": "3.8.1",
|
"optimize-css-assets-webpack-plugin": "5.0.3",
|
||||||
"webpack-dev-server": "2.9.4",
|
"pnp-webpack-plugin": "1.5.0",
|
||||||
"webpack-manifest-plugin": "1.3.2",
|
"prettier": "^1.17.0",
|
||||||
"whatwg-fetch": "2.0.3"
|
"prettier-webpack-plugin": "^1.2.0",
|
||||||
|
"postcss-flexbugs-fixes": "4.1.0",
|
||||||
|
"postcss-loader": "3.0.0",
|
||||||
|
"postcss-normalize": "8.0.1",
|
||||||
|
"postcss-preset-env": "6.7.0",
|
||||||
|
"postcss-safe-parser": "4.0.1",
|
||||||
|
"react": "^16.11.0",
|
||||||
|
"react-app-polyfill": "^1.0.2",
|
||||||
|
"react-dev-utils": "^9.0.3",
|
||||||
|
"react-dom": "^16.11.0",
|
||||||
|
"resolve": "1.12.0",
|
||||||
|
"resolve-url-loader": "3.1.0",
|
||||||
|
"sass-loader": "7.3.1",
|
||||||
|
"semver": "6.3.0",
|
||||||
|
"style-loader": "1.0.0",
|
||||||
|
"terser-webpack-plugin": "2.2.1",
|
||||||
|
"ts-pnp": "1.1.4",
|
||||||
|
"uglifyjs-webpack-plugin": "^2.1.2",
|
||||||
|
"url-loader": "2.2.0",
|
||||||
|
"webpack": "4.41.2",
|
||||||
|
"webpack-dev-server": "3.9.0",
|
||||||
|
"webpack-manifest-plugin": "2.2.0",
|
||||||
|
"workbox-webpack-plugin": "4.3.1"
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"eslintConfig": {
|
||||||
"react": ">=0.14",
|
"extends": "react-app"
|
||||||
"react-dom": ">=0.14"
|
},
|
||||||
|
"browserslist": {
|
||||||
|
"production": [
|
||||||
|
">0.2%",
|
||||||
|
"not dead",
|
||||||
|
"not op_mini all"
|
||||||
|
],
|
||||||
|
"development": [
|
||||||
|
"last 1 chrome version",
|
||||||
|
"last 1 firefox version",
|
||||||
|
"last 1 safari version"
|
||||||
|
]
|
||||||
},
|
},
|
||||||
"jest": {
|
"jest": {
|
||||||
|
"roots": [
|
||||||
|
"<rootDir>/src"
|
||||||
|
],
|
||||||
"collectCoverageFrom": [
|
"collectCoverageFrom": [
|
||||||
"src/**/*.{js,jsx,mjs}"
|
"src/**/*.{js,jsx,ts,tsx}",
|
||||||
|
"!src/**/*.d.ts",
|
||||||
|
"!src/lib/index.js",
|
||||||
|
"!src/demo/index.js",
|
||||||
|
"!src/utils/**",
|
||||||
|
"!src/**/*.d.ts",
|
||||||
|
"!**/tests/**"
|
||||||
],
|
],
|
||||||
"setupFiles": [
|
"setupFiles": [
|
||||||
"<rootDir>/config/polyfills.js"
|
"react-app-polyfill/jsdom"
|
||||||
],
|
],
|
||||||
|
"setupFilesAfterEnv": [],
|
||||||
"testMatch": [
|
"testMatch": [
|
||||||
"<rootDir>/src/**/__tests__/**/*.{js,jsx,mjs}",
|
"<rootDir>/src/**/__tests__/**/*.{js,jsx,ts,tsx}",
|
||||||
"<rootDir>/src/**/?(*.)(spec|test).{js,jsx,mjs}"
|
"<rootDir>/src/**/*.{spec,test}.{js,jsx,ts,tsx}"
|
||||||
],
|
],
|
||||||
"testEnvironment": "node",
|
"testEnvironment": "jest-environment-jsdom-fourteen",
|
||||||
"testURL": "http://localhost",
|
|
||||||
"transform": {
|
"transform": {
|
||||||
"^.+\\.(js|jsx|mjs)$": "<rootDir>/node_modules/babel-jest",
|
"^.+\\.(js|jsx|ts|tsx)$": "<rootDir>/node_modules/babel-jest",
|
||||||
"^.+\\.css$": "<rootDir>/config/jest/cssTransform.js",
|
"^.+\\.css$": "<rootDir>/config/jest/cssTransform.js",
|
||||||
"^(?!.*\\.(js|jsx|mjs|css|json)$)": "<rootDir>/config/jest/fileTransform.js"
|
"^(?!.*\\.(js|jsx|ts|tsx|css|json)$)": "<rootDir>/config/jest/fileTransform.js"
|
||||||
},
|
},
|
||||||
"transformIgnorePatterns": [
|
"transformIgnorePatterns": [
|
||||||
"[/\\\\]node_modules[/\\\\].+\\.(js|jsx|mjs)$"
|
"[/\\\\]node_modules[/\\\\].+\\.(js|jsx|ts|tsx)$",
|
||||||
|
"^.+\\.module\\.(css|sass|scss)$"
|
||||||
],
|
],
|
||||||
|
"modulePaths": [],
|
||||||
"moduleNameMapper": {
|
"moduleNameMapper": {
|
||||||
"^react-native$": "react-native-web"
|
"^react-native$": "react-native-web",
|
||||||
|
"^.+\\.module\\.(css|sass|scss)$": "identity-obj-proxy"
|
||||||
},
|
},
|
||||||
"moduleFileExtensions": [
|
"moduleFileExtensions": [
|
||||||
"web.js",
|
"web.js",
|
||||||
"mjs",
|
|
||||||
"js",
|
"js",
|
||||||
|
"web.ts",
|
||||||
|
"ts",
|
||||||
|
"web.tsx",
|
||||||
|
"tsx",
|
||||||
"json",
|
"json",
|
||||||
"web.jsx",
|
"web.jsx",
|
||||||
"jsx",
|
"jsx",
|
||||||
"node"
|
"node"
|
||||||
|
],
|
||||||
|
"watchPlugins": [
|
||||||
|
"jest-watch-typeahead/filename",
|
||||||
|
"jest-watch-typeahead/testname"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"babel": {
|
"babel": {
|
||||||
"presets": [
|
"presets": [
|
||||||
"react-app"
|
"@babel/preset-env",
|
||||||
|
"@babel/preset-react"
|
||||||
|
],
|
||||||
|
"plugins": [
|
||||||
|
[
|
||||||
|
"@babel/plugin-proposal-class-properties"
|
||||||
|
]
|
||||||
]
|
]
|
||||||
},
|
|
||||||
"eslintConfig": {
|
|
||||||
"extends": "react-app"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+17
-33
@@ -1,44 +1,28 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
<meta
|
||||||
<meta name="theme-color" content="#000000">
|
name="viewport"
|
||||||
<!--
|
content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"
|
||||||
manifest.json provides metadata used when your web app is added to the
|
/>
|
||||||
homescreen on Android. See https://developers.google.com/web/fundamentals/engage-and-retain/web-app-manifest/
|
<meta name="theme-color" content="#000000" />
|
||||||
-->
|
|
||||||
<link rel="manifest" href="%PUBLIC_URL%/manifest.json">
|
|
||||||
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
|
|
||||||
<!--
|
|
||||||
Notice the use of %PUBLIC_URL% in the tags above.
|
|
||||||
It will be replaced with the URL of the `public` folder during the build.
|
|
||||||
Only files inside the `public` folder can be referenced from the HTML.
|
|
||||||
|
|
||||||
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
|
|
||||||
work correctly both with client-side routing and a non-root public URL.
|
|
||||||
Learn how to configure a non-root public URL by running `npm run build`.
|
|
||||||
-->
|
|
||||||
<title>simple-keyboard</title>
|
<title>simple-keyboard</title>
|
||||||
|
<style>
|
||||||
|
/**
|
||||||
|
* Disabling double-tap to zoom in iOS 10+
|
||||||
|
* as it interferes with simple-keyboard
|
||||||
|
*/
|
||||||
|
body,
|
||||||
|
html {
|
||||||
|
touch-action: manipulation;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<noscript>
|
<noscript>
|
||||||
You need to enable JavaScript to run this app.
|
You need to enable JavaScript to run this app.
|
||||||
</noscript>
|
</noscript>
|
||||||
<div id="root">
|
<div id="root"></div>
|
||||||
<div class="simple-keyboard"></div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
<!--
|
|
||||||
This HTML file is a template.
|
|
||||||
If you open it directly in the browser, you will see an empty page.
|
|
||||||
|
|
||||||
You can add webfonts, meta tags, or analytics to this file.
|
|
||||||
The build step will place the bundled scripts into the <body> tag.
|
|
||||||
|
|
||||||
To begin the development, run `npm start` or `yarn start`.
|
|
||||||
To create a production bundle, use `npm run build` or `yarn build`.
|
|
||||||
-->
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@@ -1,15 +0,0 @@
|
|||||||
{
|
|
||||||
"short_name": "React App",
|
|
||||||
"name": "Create React App Sample",
|
|
||||||
"icons": [
|
|
||||||
{
|
|
||||||
"src": "favicon.ico",
|
|
||||||
"sizes": "64x64 32x32 24x24 16x16",
|
|
||||||
"type": "image/x-icon"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"start_url": "./index.html",
|
|
||||||
"display": "standalone",
|
|
||||||
"theme_color": "#000000",
|
|
||||||
"background_color": "#ffffff"
|
|
||||||
}
|
|
||||||
+76
-12
@@ -14,37 +14,53 @@ process.on('unhandledRejection', err => {
|
|||||||
// Ensure environment variables are read.
|
// Ensure environment variables are read.
|
||||||
require('../config/env');
|
require('../config/env');
|
||||||
|
|
||||||
const chalk = require('chalk');
|
|
||||||
|
const path = require('path');
|
||||||
|
const chalk = require('react-dev-utils/chalk');
|
||||||
const fs = require('fs-extra');
|
const fs = require('fs-extra');
|
||||||
const webpack = require('webpack');
|
const webpack = require('webpack');
|
||||||
const config = require('../config/webpack.config.prod');
|
const configFactory = require('../config/webpack.config');
|
||||||
const paths = require('../config/paths');
|
const paths = require('../config/paths');
|
||||||
const checkRequiredFiles = require('react-dev-utils/checkRequiredFiles');
|
const checkRequiredFiles = require('react-dev-utils/checkRequiredFiles');
|
||||||
const formatWebpackMessages = require('react-dev-utils/formatWebpackMessages');
|
const formatWebpackMessages = require('react-dev-utils/formatWebpackMessages');
|
||||||
|
const printHostingInstructions = require('react-dev-utils/printHostingInstructions');
|
||||||
const FileSizeReporter = require('react-dev-utils/FileSizeReporter');
|
const FileSizeReporter = require('react-dev-utils/FileSizeReporter');
|
||||||
const printBuildError = require('react-dev-utils/printBuildError');
|
const printBuildError = require('react-dev-utils/printBuildError');
|
||||||
|
|
||||||
const measureFileSizesBeforeBuild =
|
const measureFileSizesBeforeBuild =
|
||||||
FileSizeReporter.measureFileSizesBeforeBuild;
|
FileSizeReporter.measureFileSizesBeforeBuild;
|
||||||
const printFileSizesAfterBuild = FileSizeReporter.printFileSizesAfterBuild;
|
const printFileSizesAfterBuild = FileSizeReporter.printFileSizesAfterBuild;
|
||||||
|
const useYarn = fs.existsSync(paths.yarnLockFile);
|
||||||
|
|
||||||
// These sizes are pretty large. We'll warn for bundles exceeding them.
|
// These sizes are pretty large. We'll warn for bundles exceeding them.
|
||||||
const WARN_AFTER_BUNDLE_GZIP_SIZE = 512 * 1024;
|
const WARN_AFTER_BUNDLE_GZIP_SIZE = 512 * 1024;
|
||||||
const WARN_AFTER_CHUNK_GZIP_SIZE = 1024 * 1024;
|
const WARN_AFTER_CHUNK_GZIP_SIZE = 1024 * 1024;
|
||||||
|
|
||||||
|
const isInteractive = process.stdout.isTTY;
|
||||||
|
|
||||||
// Warn and crash if required files are missing
|
// Warn and crash if required files are missing
|
||||||
if (!checkRequiredFiles([paths.appLibIndexJs])) { // CRL: Updated with library index file
|
if (!checkRequiredFiles([paths.appHtml, paths.appIndexJs])) {
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// First, read the current file sizes in build directory.
|
// Generate configuration
|
||||||
// This lets us display how much they changed later.
|
const config = configFactory('production');
|
||||||
measureFileSizesBeforeBuild(paths.appBuild)
|
|
||||||
|
// 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 => {
|
.then(previousFileSizes => {
|
||||||
// Remove all content but keep the directory so that
|
// Remove all content but keep the directory so that
|
||||||
// if you're in it, you don't end up in Trash
|
// if you're in it, you don't end up in Trash
|
||||||
fs.emptyDirSync(paths.appBuild);
|
fs.emptyDirSync(paths.appBuild);
|
||||||
|
// Merge with the public folder
|
||||||
|
//copyPublicFolder();
|
||||||
// Start the webpack build
|
// Start the webpack build
|
||||||
return build(previousFileSizes);
|
return build(previousFileSizes);
|
||||||
})
|
})
|
||||||
@@ -76,25 +92,65 @@ measureFileSizesBeforeBuild(paths.appBuild)
|
|||||||
WARN_AFTER_CHUNK_GZIP_SIZE
|
WARN_AFTER_CHUNK_GZIP_SIZE
|
||||||
);
|
);
|
||||||
console.log();
|
console.log();
|
||||||
|
|
||||||
|
const appPackage = require(paths.appPackageJson);
|
||||||
|
const publicUrl = paths.publicUrl;
|
||||||
|
const publicPath = config.output.publicPath;
|
||||||
|
const buildFolder = path.relative(process.cwd(), paths.appBuild);
|
||||||
|
printHostingInstructions(
|
||||||
|
appPackage,
|
||||||
|
publicUrl,
|
||||||
|
publicPath,
|
||||||
|
buildFolder,
|
||||||
|
useYarn
|
||||||
|
);
|
||||||
},
|
},
|
||||||
err => {
|
err => {
|
||||||
console.log(chalk.red('Failed to compile.\n'));
|
console.error('Failed to compile');
|
||||||
printBuildError(err);
|
printBuildError(err);
|
||||||
process.exit(1);
|
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.
|
// Create the production build and print the deployment instructions.
|
||||||
function build(previousFileSizes) {
|
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...');
|
console.log('Creating an optimized production build...');
|
||||||
|
|
||||||
let compiler = webpack(config);
|
const compiler = webpack(config);
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
compiler.run((err, stats) => {
|
compiler.run((err, stats) => {
|
||||||
|
let messages;
|
||||||
if (err) {
|
if (err) {
|
||||||
return reject(err);
|
if (!err.message) {
|
||||||
|
return reject(err);
|
||||||
|
}
|
||||||
|
messages = formatWebpackMessages({
|
||||||
|
errors: [err.message],
|
||||||
|
warnings: [],
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
messages = formatWebpackMessages(
|
||||||
|
stats.toJson({ all: false, warnings: true, errors: true })
|
||||||
|
);
|
||||||
}
|
}
|
||||||
const messages = formatWebpackMessages(stats.toJson({}, true));
|
|
||||||
if (messages.errors.length) {
|
if (messages.errors.length) {
|
||||||
// Only keep the first error. Others are often indicative
|
// Only keep the first error. Others are often indicative
|
||||||
// of the same problem, but confuse the reader with noise.
|
// of the same problem, but confuse the reader with noise.
|
||||||
@@ -117,6 +173,7 @@ function build(previousFileSizes) {
|
|||||||
);
|
);
|
||||||
return reject(new Error(messages.warnings.join('\n\n')));
|
return reject(new Error(messages.warnings.join('\n\n')));
|
||||||
}
|
}
|
||||||
|
|
||||||
return resolve({
|
return resolve({
|
||||||
stats,
|
stats,
|
||||||
previousFileSizes,
|
previousFileSizes,
|
||||||
@@ -125,3 +182,10 @@ function build(previousFileSizes) {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function copyPublicFolder() {
|
||||||
|
fs.copySync(paths.appPublic, paths.appBuild, {
|
||||||
|
dereference: true,
|
||||||
|
filter: file => file !== paths.appHtml,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|||||||
+79
-15
@@ -14,37 +14,53 @@ process.on('unhandledRejection', err => {
|
|||||||
// Ensure environment variables are read.
|
// Ensure environment variables are read.
|
||||||
require('../config/env');
|
require('../config/env');
|
||||||
|
|
||||||
const chalk = require('chalk');
|
|
||||||
|
const path = require('path');
|
||||||
|
const chalk = require('react-dev-utils/chalk');
|
||||||
const fs = require('fs-extra');
|
const fs = require('fs-extra');
|
||||||
const webpack = require('webpack');
|
const webpack = require('webpack');
|
||||||
const config = require('../config/webpack.config.demo');
|
const configFactory = require('../config/webpack.config.demo');
|
||||||
const paths = require('../config/paths');
|
const paths = require('../config/paths');
|
||||||
const checkRequiredFiles = require('react-dev-utils/checkRequiredFiles');
|
const checkRequiredFiles = require('react-dev-utils/checkRequiredFiles');
|
||||||
const formatWebpackMessages = require('react-dev-utils/formatWebpackMessages');
|
const formatWebpackMessages = require('react-dev-utils/formatWebpackMessages');
|
||||||
|
const printHostingInstructions = require('react-dev-utils/printHostingInstructions');
|
||||||
const FileSizeReporter = require('react-dev-utils/FileSizeReporter');
|
const FileSizeReporter = require('react-dev-utils/FileSizeReporter');
|
||||||
const printBuildError = require('react-dev-utils/printBuildError');
|
const printBuildError = require('react-dev-utils/printBuildError');
|
||||||
|
|
||||||
const measureFileSizesBeforeBuild =
|
const measureFileSizesBeforeBuild =
|
||||||
FileSizeReporter.measureFileSizesBeforeBuild;
|
FileSizeReporter.measureFileSizesBeforeBuild;
|
||||||
const printFileSizesAfterBuild = FileSizeReporter.printFileSizesAfterBuild;
|
const printFileSizesAfterBuild = FileSizeReporter.printFileSizesAfterBuild;
|
||||||
|
const useYarn = fs.existsSync(paths.yarnLockFile);
|
||||||
|
|
||||||
// These sizes are pretty large. We'll warn for bundles exceeding them.
|
// These sizes are pretty large. We'll warn for bundles exceeding them.
|
||||||
const WARN_AFTER_BUNDLE_GZIP_SIZE = 512 * 1024;
|
const WARN_AFTER_BUNDLE_GZIP_SIZE = 512 * 1024;
|
||||||
const WARN_AFTER_CHUNK_GZIP_SIZE = 1024 * 1024;
|
const WARN_AFTER_CHUNK_GZIP_SIZE = 1024 * 1024;
|
||||||
|
|
||||||
|
const isInteractive = process.stdout.isTTY;
|
||||||
|
|
||||||
// Warn and crash if required files are missing
|
// Warn and crash if required files are missing
|
||||||
if (!checkRequiredFiles([paths.appDemoIndexJs])) { // CRL: Updated with library index file
|
if (!checkRequiredFiles([paths.appHtml, paths.appDemoIndexJs])) {
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// First, read the current file sizes in build directory.
|
// Generate configuration
|
||||||
// This lets us display how much they changed later.
|
const config = configFactory('production');
|
||||||
measureFileSizesBeforeBuild(paths.appDemoBuild)
|
|
||||||
|
// 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 => {
|
.then(previousFileSizes => {
|
||||||
// Remove all content but keep the directory so that
|
// Remove all content but keep the directory so that
|
||||||
// if you're in it, you don't end up in Trash
|
// if you're in it, you don't end up in Trash
|
||||||
fs.emptyDirSync(paths.appDemoBuild);
|
fs.emptyDirSync(paths.appDemo);
|
||||||
|
// Merge with the public folder
|
||||||
|
copyPublicFolder();
|
||||||
// Start the webpack build
|
// Start the webpack build
|
||||||
return build(previousFileSizes);
|
return build(previousFileSizes);
|
||||||
})
|
})
|
||||||
@@ -71,30 +87,70 @@ measureFileSizesBeforeBuild(paths.appDemoBuild)
|
|||||||
printFileSizesAfterBuild(
|
printFileSizesAfterBuild(
|
||||||
stats,
|
stats,
|
||||||
previousFileSizes,
|
previousFileSizes,
|
||||||
paths.appDemoBuild,
|
paths.appDemo,
|
||||||
WARN_AFTER_BUNDLE_GZIP_SIZE,
|
WARN_AFTER_BUNDLE_GZIP_SIZE,
|
||||||
WARN_AFTER_CHUNK_GZIP_SIZE
|
WARN_AFTER_CHUNK_GZIP_SIZE
|
||||||
);
|
);
|
||||||
console.log();
|
console.log();
|
||||||
|
|
||||||
|
const appPackage = require(paths.appPackageJson);
|
||||||
|
const publicUrl = paths.publicUrl;
|
||||||
|
const publicPath = config.output.publicPath;
|
||||||
|
const buildFolder = path.relative(process.cwd(), paths.appDemo);
|
||||||
|
printHostingInstructions(
|
||||||
|
appPackage,
|
||||||
|
publicUrl,
|
||||||
|
publicPath,
|
||||||
|
buildFolder,
|
||||||
|
useYarn
|
||||||
|
);
|
||||||
},
|
},
|
||||||
err => {
|
err => {
|
||||||
console.log(chalk.red('Failed to compile.\n'));
|
console.error('Failed to compile');
|
||||||
printBuildError(err);
|
printBuildError(err);
|
||||||
process.exit(1);
|
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.
|
// Create the production build and print the deployment instructions.
|
||||||
function build(previousFileSizes) {
|
function build(previousFileSizes) {
|
||||||
console.log('Creating a build of the demo app...');
|
// 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();
|
||||||
|
}
|
||||||
|
|
||||||
let compiler = webpack(config);
|
console.log('Creating an optimized production build...');
|
||||||
|
|
||||||
|
const compiler = webpack(config);
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
compiler.run((err, stats) => {
|
compiler.run((err, stats) => {
|
||||||
|
let messages;
|
||||||
if (err) {
|
if (err) {
|
||||||
return reject(err);
|
if (!err.message) {
|
||||||
|
return reject(err);
|
||||||
|
}
|
||||||
|
messages = formatWebpackMessages({
|
||||||
|
errors: [err.message],
|
||||||
|
warnings: [],
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
messages = formatWebpackMessages(
|
||||||
|
stats.toJson({ all: false, warnings: true, errors: true })
|
||||||
|
);
|
||||||
}
|
}
|
||||||
const messages = formatWebpackMessages(stats.toJson({}, true));
|
|
||||||
if (messages.errors.length) {
|
if (messages.errors.length) {
|
||||||
// Only keep the first error. Others are often indicative
|
// Only keep the first error. Others are often indicative
|
||||||
// of the same problem, but confuse the reader with noise.
|
// of the same problem, but confuse the reader with noise.
|
||||||
@@ -117,6 +173,7 @@ function build(previousFileSizes) {
|
|||||||
);
|
);
|
||||||
return reject(new Error(messages.warnings.join('\n\n')));
|
return reject(new Error(messages.warnings.join('\n\n')));
|
||||||
}
|
}
|
||||||
|
|
||||||
return resolve({
|
return resolve({
|
||||||
stats,
|
stats,
|
||||||
previousFileSizes,
|
previousFileSizes,
|
||||||
@@ -125,3 +182,10 @@ function build(previousFileSizes) {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function copyPublicFolder() {
|
||||||
|
fs.copySync(paths.appPublic, paths.appDemo, {
|
||||||
|
dereference: true,
|
||||||
|
filter: file => file !== paths.appHtml,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|||||||
+85
-8
@@ -14,8 +14,9 @@ process.on('unhandledRejection', err => {
|
|||||||
// Ensure environment variables are read.
|
// Ensure environment variables are read.
|
||||||
require('../config/env');
|
require('../config/env');
|
||||||
|
|
||||||
|
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const chalk = require('chalk');
|
const chalk = require('react-dev-utils/chalk');
|
||||||
const webpack = require('webpack');
|
const webpack = require('webpack');
|
||||||
const WebpackDevServer = require('webpack-dev-server');
|
const WebpackDevServer = require('webpack-dev-server');
|
||||||
const clearConsole = require('react-dev-utils/clearConsole');
|
const clearConsole = require('react-dev-utils/clearConsole');
|
||||||
@@ -28,14 +29,14 @@ const {
|
|||||||
} = require('react-dev-utils/WebpackDevServerUtils');
|
} = require('react-dev-utils/WebpackDevServerUtils');
|
||||||
const openBrowser = require('react-dev-utils/openBrowser');
|
const openBrowser = require('react-dev-utils/openBrowser');
|
||||||
const paths = require('../config/paths');
|
const paths = require('../config/paths');
|
||||||
const config = require('../config/webpack.config.dev');
|
const configFactory = require('../config/webpack.config');
|
||||||
const createDevServerConfig = require('../config/webpackDevServer.config');
|
const createDevServerConfig = require('../config/webpackDevServer.config');
|
||||||
|
|
||||||
const useYarn = fs.existsSync(paths.yarnLockFile);
|
const useYarn = fs.existsSync(paths.yarnLockFile);
|
||||||
const isInteractive = process.stdout.isTTY;
|
const isInteractive = process.stdout.isTTY;
|
||||||
|
|
||||||
// Warn and crash if required files are missing
|
// Warn and crash if required files are missing
|
||||||
if (!checkRequiredFiles([paths.appHtml, paths.appIndexJs])) {
|
if (!checkRequiredFiles([paths.appHtml, paths.appDemoIndexJs])) {
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -43,23 +44,64 @@ if (!checkRequiredFiles([paths.appHtml, paths.appIndexJs])) {
|
|||||||
const DEFAULT_PORT = parseInt(process.env.PORT, 10) || 3000;
|
const DEFAULT_PORT = parseInt(process.env.PORT, 10) || 3000;
|
||||||
const HOST = process.env.HOST || '0.0.0.0';
|
const HOST = process.env.HOST || '0.0.0.0';
|
||||||
|
|
||||||
// We attempt to use the default port but if it is busy, we offer the user to
|
if (process.env.HOST) {
|
||||||
// run on a different port. `detect()` Promise resolves to the next free port.
|
console.log(
|
||||||
choosePort(HOST, DEFAULT_PORT)
|
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 => {
|
.then(port => {
|
||||||
if (port == null) {
|
if (port == null) {
|
||||||
// We have not found a port.
|
// We have not found a port.
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
const args = process.argv;
|
||||||
|
const testMode = args[2] === "--testMode";
|
||||||
|
const config = configFactory('development');
|
||||||
const protocol = process.env.HTTPS === 'true' ? 'https' : 'http';
|
const protocol = process.env.HTTPS === 'true' ? 'https' : 'http';
|
||||||
const appName = require(paths.appPackageJson).name;
|
const appName = require(paths.appPackageJson).name;
|
||||||
|
const useTypeScript = fs.existsSync(paths.appTsConfig);
|
||||||
const urls = prepareUrls(protocol, HOST, port);
|
const urls = prepareUrls(protocol, HOST, port);
|
||||||
|
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.
|
// Create a webpack compiler that is configured with custom messages.
|
||||||
const compiler = createCompiler(webpack, config, appName, urls, useYarn);
|
const compiler = createCompiler({
|
||||||
|
appName,
|
||||||
|
config,
|
||||||
|
devSocket,
|
||||||
|
urls,
|
||||||
|
useYarn,
|
||||||
|
useTypeScript,
|
||||||
|
webpack,
|
||||||
|
});
|
||||||
// Load proxy config
|
// Load proxy config
|
||||||
const proxySetting = require(paths.appPackageJson).proxy;
|
const proxySetting = require(paths.appPackageJson).proxy;
|
||||||
const proxyConfig = prepareProxy(proxySetting, paths.appPublic);
|
const proxyConfig = prepareProxy(proxySetting, paths.appPublic);
|
||||||
// Serve webpack assets generated by the compiler over a web sever.
|
// Serve webpack assets generated by the compiler over a web server.
|
||||||
const serverConfig = createDevServerConfig(
|
const serverConfig = createDevServerConfig(
|
||||||
proxyConfig,
|
proxyConfig,
|
||||||
urls.lanUrlForConfig
|
urls.lanUrlForConfig
|
||||||
@@ -73,8 +115,43 @@ choosePort(HOST, DEFAULT_PORT)
|
|||||||
if (isInteractive) {
|
if (isInteractive) {
|
||||||
clearConsole();
|
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'));
|
console.log(chalk.cyan('Starting the development server...\n'));
|
||||||
openBrowser(urls.localUrlForBrowser);
|
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);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
console.warn("App started in test mode. Closing in 5 seconds.");
|
||||||
|
let closeTimeout = setTimeout(() => {
|
||||||
|
clearTimeout(closeTimeout);
|
||||||
|
devServer.close();
|
||||||
|
process.exit();
|
||||||
|
}, 5000);
|
||||||
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
['SIGINT', 'SIGTERM'].forEach(function(sig) {
|
['SIGINT', 'SIGTERM'].forEach(function(sig) {
|
||||||
|
|||||||
+31
-5
@@ -15,12 +15,38 @@ process.on('unhandledRejection', err => {
|
|||||||
// Ensure environment variables are read.
|
// Ensure environment variables are read.
|
||||||
require('../config/env');
|
require('../config/env');
|
||||||
|
|
||||||
const jest = require('jest');
|
|
||||||
const argv = process.argv.slice(2);
|
|
||||||
|
|
||||||
// Watch unless on CI or in coverage mode
|
const jest = require('jest');
|
||||||
if (!process.env.CI && argv.indexOf('--coverage') < 0) {
|
const execSync = require('child_process').execSync;
|
||||||
argv.push('--watch');
|
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');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,59 +0,0 @@
|
|||||||
import Keyboard from '../lib';
|
|
||||||
import './css/App.css';
|
|
||||||
|
|
||||||
class App {
|
|
||||||
constructor(){
|
|
||||||
document.addEventListener('DOMContentLoaded', this.onDOMLoaded);
|
|
||||||
|
|
||||||
this.layoutName = "default";
|
|
||||||
}
|
|
||||||
|
|
||||||
onDOMLoaded = () => {
|
|
||||||
this.keyboard = new Keyboard({
|
|
||||||
debug: true,
|
|
||||||
layoutName: this.layoutName,
|
|
||||||
onChange: input => this.onChange(input),
|
|
||||||
onKeyPress: button => this.onKeyPress(button),
|
|
||||||
newLineOnEnter: true
|
|
||||||
});
|
|
||||||
|
|
||||||
this.keyboard.setInput("Hello World!");
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Adding preview (demo only)
|
|
||||||
*/
|
|
||||||
document.querySelector('.simple-keyboard').insertAdjacentHTML('beforebegin', `
|
|
||||||
<div class="simple-keyboard-preview">
|
|
||||||
<textarea class="input" readonly>Hello World!</textarea>
|
|
||||||
</div>
|
|
||||||
`);
|
|
||||||
|
|
||||||
console.log(this.keyboard);
|
|
||||||
}
|
|
||||||
|
|
||||||
handleShiftButton = () => {
|
|
||||||
let layoutName = this.layoutName;
|
|
||||||
let shiftToggle = this.layoutName = layoutName === "default" ? "shift" : "default";
|
|
||||||
|
|
||||||
this.keyboard.setOptions({
|
|
||||||
layoutName: shiftToggle
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
onChange = input => {
|
|
||||||
document.querySelector('.input').value = input;
|
|
||||||
}
|
|
||||||
|
|
||||||
onKeyPress = button => {
|
|
||||||
console.log("Button pressed", button);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Shift functionality
|
|
||||||
*/
|
|
||||||
if(button === "{lock}" || button === "{shift}")
|
|
||||||
this.handleShiftButton();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
export default App;
|
|
||||||
@@ -0,0 +1,55 @@
|
|||||||
|
import Keyboard from "../lib";
|
||||||
|
import "./css/BasicDemo.css";
|
||||||
|
|
||||||
|
const setDOM = () => {
|
||||||
|
document.querySelector("#root").innerHTML = `
|
||||||
|
<input class="input" placeholder="Tap on the virtual keyboard to start" />
|
||||||
|
<div class="simple-keyboard"></div>
|
||||||
|
`;
|
||||||
|
};
|
||||||
|
|
||||||
|
class Demo {
|
||||||
|
constructor() {
|
||||||
|
setDOM();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Demo Start
|
||||||
|
*/
|
||||||
|
this.keyboard = new Keyboard({
|
||||||
|
onChange: input => this.onChange(input),
|
||||||
|
onKeyPress: button => this.onKeyPress(button)
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update simple-keyboard when input is changed directly
|
||||||
|
*/
|
||||||
|
document.querySelector(".input").addEventListener("input", event => {
|
||||||
|
this.keyboard.setInput(event.target.value);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
onChange(input) {
|
||||||
|
document.querySelector(".input").value = input;
|
||||||
|
console.log("Input changed", input);
|
||||||
|
}
|
||||||
|
|
||||||
|
onKeyPress(button) {
|
||||||
|
console.log("Button pressed", button);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If you want to handle the shift and caps lock buttons
|
||||||
|
*/
|
||||||
|
if (button === "{shift}" || button === "{lock}") this.handleShift();
|
||||||
|
}
|
||||||
|
|
||||||
|
handleShift() {
|
||||||
|
let currentLayout = this.keyboard.options.layoutName;
|
||||||
|
let shiftToggle = currentLayout === "default" ? "shift" : "default";
|
||||||
|
|
||||||
|
this.keyboard.setOptions({
|
||||||
|
layoutName: shiftToggle
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default Demo;
|
||||||
@@ -0,0 +1,73 @@
|
|||||||
|
import Keyboard from "../lib";
|
||||||
|
import "./css/ButtonThemeDemo.css";
|
||||||
|
|
||||||
|
const setDOM = () => {
|
||||||
|
document.querySelector("#root").innerHTML = `
|
||||||
|
<input class="input" placeholder="Tap on the virtual keyboard to start" />
|
||||||
|
<div class="simple-keyboard"></div>
|
||||||
|
`;
|
||||||
|
};
|
||||||
|
|
||||||
|
class Demo {
|
||||||
|
constructor() {
|
||||||
|
setDOM();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Demo Start
|
||||||
|
*/
|
||||||
|
this.keyboard = new Keyboard({
|
||||||
|
theme: "hg-theme-default my-theme",
|
||||||
|
onChange: input => this.onChange(input),
|
||||||
|
onKeyPress: button => this.onKeyPress(button),
|
||||||
|
buttonTheme: [
|
||||||
|
{
|
||||||
|
class: "my-button",
|
||||||
|
buttons: "{enter} {bksp} q Q"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
class: "my-button-outline",
|
||||||
|
buttons: "q Q b B"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
buttonAttributes: [
|
||||||
|
{
|
||||||
|
attribute: "aria-label",
|
||||||
|
value: "bee",
|
||||||
|
buttons: "b B"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update simple-keyboard when input is changed directly
|
||||||
|
*/
|
||||||
|
document.querySelector(".input").addEventListener("input", event => {
|
||||||
|
this.keyboard.setInput(event.target.value);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
onChange(input) {
|
||||||
|
document.querySelector(".input").value = input;
|
||||||
|
console.log("Input changed", input);
|
||||||
|
}
|
||||||
|
|
||||||
|
onKeyPress(button) {
|
||||||
|
console.log("Button pressed", button);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If you want to handle the shift and caps lock buttons
|
||||||
|
*/
|
||||||
|
if (button === "{shift}" || button === "{lock}") this.handleShift();
|
||||||
|
}
|
||||||
|
|
||||||
|
handleShift() {
|
||||||
|
let currentLayout = this.keyboard.options.layoutName;
|
||||||
|
let shiftToggle = currentLayout === "default" ? "shift" : "default";
|
||||||
|
|
||||||
|
this.keyboard.setOptions({
|
||||||
|
layoutName: shiftToggle
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default Demo;
|
||||||
@@ -0,0 +1,157 @@
|
|||||||
|
import Keyboard from "../lib";
|
||||||
|
import "./css/FullKeyboardDemo.css";
|
||||||
|
|
||||||
|
const setDOM = () => {
|
||||||
|
document.querySelector("#root").innerHTML = `
|
||||||
|
<input class="input" placeholder="Tap on the virtual keyboard to start" />
|
||||||
|
<div class="keyboardContainer">
|
||||||
|
<div class="simple-keyboard-main"></div>
|
||||||
|
|
||||||
|
<div class="controlArrows">
|
||||||
|
<div class="simple-keyboard-control"></div>
|
||||||
|
<div class="simple-keyboard-arrows"></div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="numPad">
|
||||||
|
<div class="simple-keyboard-numpad"></div>
|
||||||
|
<div class="simple-keyboard-numpadEnd"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
};
|
||||||
|
|
||||||
|
class Demo {
|
||||||
|
constructor() {
|
||||||
|
setDOM();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Demo Start
|
||||||
|
*/
|
||||||
|
let commonKeyboardOptions = {
|
||||||
|
onChange: input => this.onChange(input),
|
||||||
|
onKeyPress: button => this.onKeyPress(button),
|
||||||
|
theme: "simple-keyboard hg-theme-default hg-layout-default",
|
||||||
|
physicalKeyboardHighlight: true,
|
||||||
|
syncInstanceInputs: true,
|
||||||
|
mergeDisplay: true,
|
||||||
|
debug: true
|
||||||
|
};
|
||||||
|
|
||||||
|
this.keyboard = new Keyboard(".simple-keyboard-main", {
|
||||||
|
...commonKeyboardOptions,
|
||||||
|
/**
|
||||||
|
* Layout by:
|
||||||
|
* Sterling Butters (https://github.com/SterlingButters)
|
||||||
|
*/
|
||||||
|
layout: {
|
||||||
|
default: [
|
||||||
|
"{escape} {f1} {f2} {f3} {f4} {f5} {f6} {f7} {f8} {f9} {f10} {f11} {f12}",
|
||||||
|
"` 1 2 3 4 5 6 7 8 9 0 - = {backspace}",
|
||||||
|
"{tab} q w e r t y u i o p [ ] \\",
|
||||||
|
"{capslock} a s d f g h j k l ; ' {enter}",
|
||||||
|
"{shiftleft} z x c v b n m , . / {shiftright}",
|
||||||
|
"{controlleft} {altleft} {metaleft} {space} {metaright} {altright}"
|
||||||
|
],
|
||||||
|
shift: [
|
||||||
|
"{escape} {f1} {f2} {f3} {f4} {f5} {f6} {f7} {f8} {f9} {f10} {f11} {f12}",
|
||||||
|
"~ ! @ # $ % ^ & * ( ) _ + {backspace}",
|
||||||
|
"{tab} Q W E R T Y U I O P { } |",
|
||||||
|
'{capslock} A S D F G H J K L : " {enter}',
|
||||||
|
"{shiftleft} Z X C V B N M < > ? {shiftright}",
|
||||||
|
"{controlleft} {altleft} {metaleft} {space} {metaright} {altright}"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
display: {
|
||||||
|
"{escape}": "esc ⎋",
|
||||||
|
"{tab}": "tab ⇥",
|
||||||
|
"{backspace}": "backspace ⌫",
|
||||||
|
"{enter}": "enter ↵",
|
||||||
|
"{capslock}": "caps lock ⇪",
|
||||||
|
"{shiftleft}": "shift ⇧",
|
||||||
|
"{shiftright}": "shift ⇧",
|
||||||
|
"{controlleft}": "ctrl ⌃",
|
||||||
|
"{controlright}": "ctrl ⌃",
|
||||||
|
"{altleft}": "alt ⌥",
|
||||||
|
"{altright}": "alt ⌥",
|
||||||
|
"{metaleft}": "cmd ⌘",
|
||||||
|
"{metaright}": "cmd ⌘"
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
this.keyboardControlPad = new Keyboard(".simple-keyboard-control", {
|
||||||
|
...commonKeyboardOptions,
|
||||||
|
layout: {
|
||||||
|
default: [
|
||||||
|
"{prtscr} {scrolllock} {pause}",
|
||||||
|
"{insert} {home} {pageup}",
|
||||||
|
"{delete} {end} {pagedown}"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
this.keyboardArrows = new Keyboard(".simple-keyboard-arrows", {
|
||||||
|
...commonKeyboardOptions,
|
||||||
|
layout: {
|
||||||
|
default: ["{arrowup}", "{arrowleft} {arrowdown} {arrowright}"]
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
this.keyboardNumPad = new Keyboard(".simple-keyboard-numpad", {
|
||||||
|
...commonKeyboardOptions,
|
||||||
|
layout: {
|
||||||
|
default: [
|
||||||
|
"{numlock} {numpaddivide} {numpadmultiply}",
|
||||||
|
"{numpad7} {numpad8} {numpad9}",
|
||||||
|
"{numpad4} {numpad5} {numpad6}",
|
||||||
|
"{numpad1} {numpad2} {numpad3}",
|
||||||
|
"{numpad0} {numpaddecimal}"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
this.keyboardNumPadEnd = new Keyboard(".simple-keyboard-numpadEnd", {
|
||||||
|
...commonKeyboardOptions,
|
||||||
|
layout: {
|
||||||
|
default: ["{numpadsubtract}", "{numpadadd}", "{numpadenter}"]
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
document.querySelector(".input").addEventListener("input", event => {
|
||||||
|
let input = document.querySelector(".input").value;
|
||||||
|
this.keyboard.setInput(input);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
onChange(input) {
|
||||||
|
document.querySelector(".input").value = input;
|
||||||
|
this.keyboard.setInput(input);
|
||||||
|
|
||||||
|
console.log("Input changed", input);
|
||||||
|
}
|
||||||
|
|
||||||
|
onKeyPress(button) {
|
||||||
|
console.log("Button pressed", button);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If you want to handle the shift and caps lock buttons
|
||||||
|
*/
|
||||||
|
if (
|
||||||
|
button === "{shift}" ||
|
||||||
|
button === "{shiftleft}" ||
|
||||||
|
button === "{shiftright}" ||
|
||||||
|
button === "{capslock}"
|
||||||
|
)
|
||||||
|
this.handleShift();
|
||||||
|
}
|
||||||
|
|
||||||
|
handleShift() {
|
||||||
|
let currentLayout = this.keyboard.options.layoutName;
|
||||||
|
let shiftToggle = currentLayout === "default" ? "shift" : "default";
|
||||||
|
|
||||||
|
this.keyboard.setOptions({
|
||||||
|
layoutName: shiftToggle
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default Demo;
|
||||||
@@ -1,77 +0,0 @@
|
|||||||
import Keyboard from '../lib';
|
|
||||||
import './css/MultipleInputsDemo.css';
|
|
||||||
|
|
||||||
class App {
|
|
||||||
constructor(){
|
|
||||||
document.addEventListener('DOMContentLoaded', this.onDOMLoaded);
|
|
||||||
|
|
||||||
this.layoutName = "default";
|
|
||||||
}
|
|
||||||
|
|
||||||
onDOMLoaded = () => {
|
|
||||||
this.keyboard = new Keyboard({
|
|
||||||
debug: true,
|
|
||||||
layoutName: this.layoutName,
|
|
||||||
onChange: input => this.onChange(input),
|
|
||||||
onKeyPress: button => this.onKeyPress(button)
|
|
||||||
});
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Adding preview (demo only)
|
|
||||||
* In production, this would be part of your HTML file
|
|
||||||
*/
|
|
||||||
document.querySelector('.simple-keyboard').insertAdjacentHTML('beforebegin', `
|
|
||||||
<div>
|
|
||||||
<label>Input 1</label>
|
|
||||||
<input class="input" id="input1" value=""/>
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<label>Input 2</label>
|
|
||||||
<input class="input" id="input2" value=""/>
|
|
||||||
</div>
|
|
||||||
`);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Changing active input onFocus
|
|
||||||
*/
|
|
||||||
document.querySelectorAll('.input')
|
|
||||||
.forEach(input => input.addEventListener('focus', this.onInputFocus));
|
|
||||||
|
|
||||||
console.log(this.keyboard);
|
|
||||||
}
|
|
||||||
|
|
||||||
onInputFocus = event => {
|
|
||||||
this.selectedInput = `#${event.target.id}`;
|
|
||||||
|
|
||||||
this.keyboard.setOptions({
|
|
||||||
inputName: event.target.id
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
onChange = input => {
|
|
||||||
let currentInput = this.selectedInput || '.input';
|
|
||||||
document.querySelector(currentInput).value = input;
|
|
||||||
}
|
|
||||||
|
|
||||||
onKeyPress = button => {
|
|
||||||
console.log("Button pressed", button);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Shift functionality
|
|
||||||
*/
|
|
||||||
if(button === "{lock}" || button === "{shift}")
|
|
||||||
this.handleShiftButton();
|
|
||||||
}
|
|
||||||
|
|
||||||
handleShiftButton = () => {
|
|
||||||
let layoutName = this.layoutName;
|
|
||||||
let shiftToggle = this.layoutName = layoutName === "default" ? "shift" : "default";
|
|
||||||
|
|
||||||
this.keyboard.setOptions({
|
|
||||||
layoutName: shiftToggle
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
export default App;
|
|
||||||
@@ -0,0 +1,75 @@
|
|||||||
|
import Keyboard from "../lib";
|
||||||
|
import "./css/MultipleKeyboardsDestroyDemo.css";
|
||||||
|
|
||||||
|
const setDOM = () => {
|
||||||
|
document.querySelector("#root").innerHTML = `
|
||||||
|
<input class="input" placeholder="Tap on the virtual keyboard to start" />
|
||||||
|
<div class="simple-keyboard"></div>
|
||||||
|
|
||||||
|
<input class="input2" placeholder="Tap on the virtual keyboard to start" />
|
||||||
|
<div class="keyboard2"></div>
|
||||||
|
`;
|
||||||
|
};
|
||||||
|
|
||||||
|
class Demo {
|
||||||
|
constructor() {
|
||||||
|
setDOM();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Demo Start
|
||||||
|
*/
|
||||||
|
this.keyboard = new Keyboard({
|
||||||
|
onChange: input => this.onChange(input),
|
||||||
|
onKeyPress: button => this.onKeyPress(button),
|
||||||
|
debug: true
|
||||||
|
});
|
||||||
|
|
||||||
|
this.keyboard2 = new Keyboard(".keyboard2", {
|
||||||
|
theme: "simple-keyboard hg-theme-default",
|
||||||
|
onChange: input => this.onChange(input, "input2"),
|
||||||
|
onKeyPress: button => this.onKeyPress(button, "keyboard2"),
|
||||||
|
debug: true
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log(this.keyboard);
|
||||||
|
setTimeout(this.keyboard.destroy, 10000);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update simple-keyboard when input is changed directly
|
||||||
|
*/
|
||||||
|
document.querySelector(".input").addEventListener("input", event => {
|
||||||
|
this.keyboard.setInput(event.target.value);
|
||||||
|
});
|
||||||
|
|
||||||
|
document.querySelector(".input2").addEventListener("input", event => {
|
||||||
|
this.keyboard2.setInput(event.target.value);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
onChange(input, inputClass) {
|
||||||
|
document.querySelector(`.${inputClass || "input"}`).value = input;
|
||||||
|
console.log("Input changed", input);
|
||||||
|
}
|
||||||
|
|
||||||
|
onKeyPress(button, keyboardInstanceKey) {
|
||||||
|
console.log("Button pressed", button);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If you want to handle the shift and caps lock buttons
|
||||||
|
*/
|
||||||
|
if (button === "{shift}" || button === "{lock}")
|
||||||
|
this.handleShift(keyboardInstanceKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
handleShift(keyboardInstanceKey) {
|
||||||
|
let keyboard = this[keyboardInstanceKey || "keyboard"];
|
||||||
|
let currentLayout = keyboard.options.layoutName;
|
||||||
|
let shiftToggle = currentLayout === "default" ? "shift" : "default";
|
||||||
|
|
||||||
|
keyboard.setOptions({
|
||||||
|
layoutName: shiftToggle
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default Demo;
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
#root {
|
|
||||||
font-family: "HelveticaNeue-Light", "Helvetica Neue Light", "Helvetica Neue", Helvetica, Arial, "Lucida Grande", sans-serif;
|
|
||||||
max-width: 1000px;
|
|
||||||
margin: 0 auto;
|
|
||||||
padding-top: 20px;
|
|
||||||
}
|
|
||||||
|
|
||||||
#root .simple-keyboard-preview {
|
|
||||||
background: rgba(0,0,0,0.8);
|
|
||||||
border: 20px solid rgba(0,0,0,0.1);
|
|
||||||
height: 300px;
|
|
||||||
border-top-right-radius: 5px;
|
|
||||||
border-top-left-radius: 5px;
|
|
||||||
padding: 10px;
|
|
||||||
box-sizing: border-box;
|
|
||||||
}
|
|
||||||
|
|
||||||
#root .input {
|
|
||||||
color: rgba(255,255,255,0.9);
|
|
||||||
background: transparent;
|
|
||||||
border: none;
|
|
||||||
outline: none;
|
|
||||||
font-family: monospace;
|
|
||||||
width: 100%;
|
|
||||||
height: 100%;
|
|
||||||
font-size: 18px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.simple-keyboard.hg-layout-custom {
|
|
||||||
border-top-left-radius: 0px;
|
|
||||||
border-top-right-radius: 0px;
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
input {
|
||||||
|
width: 100%;
|
||||||
|
height: 100px;
|
||||||
|
padding: 20px;
|
||||||
|
font-size: 20px;
|
||||||
|
border: none;
|
||||||
|
box-sizing: border-box;
|
||||||
|
}
|
||||||
|
|
||||||
|
.simple-keyboard {
|
||||||
|
max-width: 850px;
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
input {
|
||||||
|
width: 100%;
|
||||||
|
height: 100px;
|
||||||
|
padding: 20px;
|
||||||
|
font-size: 20px;
|
||||||
|
border: none;
|
||||||
|
box-sizing: border-box;
|
||||||
|
}
|
||||||
|
|
||||||
|
.simple-keyboard {
|
||||||
|
max-width: 850px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.simple-keyboard.my-theme .hg-button.my-button {
|
||||||
|
background: blue;
|
||||||
|
color: white;
|
||||||
|
}
|
||||||
|
|
||||||
|
.simple-keyboard.my-theme .hg-button[aria-label] {
|
||||||
|
background: black;
|
||||||
|
color: white;
|
||||||
|
}
|
||||||
|
|
||||||
|
.simple-keyboard.my-theme .hg-button.my-button-outline {
|
||||||
|
border: 2px solid red;
|
||||||
|
}
|
||||||
@@ -0,0 +1,132 @@
|
|||||||
|
input {
|
||||||
|
width: 100%;
|
||||||
|
height: 100px;
|
||||||
|
padding: 20px;
|
||||||
|
font-size: 20px;
|
||||||
|
border: none;
|
||||||
|
box-sizing: border-box;
|
||||||
|
}
|
||||||
|
|
||||||
|
.keyboardContainer {
|
||||||
|
display: flex;
|
||||||
|
background-color: rgba(0, 0, 0, 0.1);
|
||||||
|
justify-content: center;
|
||||||
|
width: 1024px;
|
||||||
|
border-radius: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.simple-keyboard.hg-theme-default {
|
||||||
|
display: inline-block;
|
||||||
|
}
|
||||||
|
|
||||||
|
.simple-keyboard-main.simple-keyboard {
|
||||||
|
width: 640px;
|
||||||
|
min-width: 640px;
|
||||||
|
background: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.simple-keyboard-main.simple-keyboard .hg-row:first-child {
|
||||||
|
margin-bottom: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.simple-keyboard-arrows.simple-keyboard {
|
||||||
|
align-self: flex-end;
|
||||||
|
background: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.simple-keyboard .hg-button.selectedButton {
|
||||||
|
background: rgba(5, 25, 70, 0.53);
|
||||||
|
color: white;
|
||||||
|
}
|
||||||
|
|
||||||
|
.simple-keyboard .hg-button.emptySpace {
|
||||||
|
pointer-events: none;
|
||||||
|
background: none;
|
||||||
|
border: none;
|
||||||
|
box-shadow: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.simple-keyboard-arrows .hg-row {
|
||||||
|
justify-content: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.simple-keyboard-arrows .hg-button {
|
||||||
|
width: 50px;
|
||||||
|
flex-grow: 0;
|
||||||
|
justify-content: center;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.controlArrows {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
flex-flow: column;
|
||||||
|
}
|
||||||
|
|
||||||
|
.simple-keyboard-control.simple-keyboard {
|
||||||
|
background: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.simple-keyboard-control.simple-keyboard .hg-row:first-child {
|
||||||
|
margin-bottom: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.simple-keyboard-control .hg-button {
|
||||||
|
width: 50px;
|
||||||
|
flex-grow: 0;
|
||||||
|
justify-content: center;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.numPad {
|
||||||
|
display: flex;
|
||||||
|
align-items: flex-end;
|
||||||
|
}
|
||||||
|
|
||||||
|
.simple-keyboard-numpad.simple-keyboard {
|
||||||
|
background: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.simple-keyboard-numpad.simple-keyboard {
|
||||||
|
width: 160px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.simple-keyboard-numpad.simple-keyboard .hg-button {
|
||||||
|
width: 50px;
|
||||||
|
justify-content: center;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.simple-keyboard-numpadEnd.simple-keyboard {
|
||||||
|
width: 50px;
|
||||||
|
background: none;
|
||||||
|
margin: 0;
|
||||||
|
padding: 5px 5px 5px 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.simple-keyboard-numpadEnd.simple-keyboard .hg-button {
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
display: flex;
|
||||||
|
}
|
||||||
|
|
||||||
|
.simple-keyboard-numpadEnd .hg-button.hg-standardBtn.hg-button-plus {
|
||||||
|
height: 85px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.simple-keyboard-numpadEnd.simple-keyboard .hg-button.hg-button-enter {
|
||||||
|
height: 85px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.simple-keyboard.hg-theme-default .hg-button.hg-selectedButton {
|
||||||
|
background: rgba(5, 25, 70, 0.53);
|
||||||
|
color: white;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hg-button.hg-functionBtn.hg-button-space {
|
||||||
|
width: 350px;
|
||||||
|
}
|
||||||
@@ -1,40 +0,0 @@
|
|||||||
#root {
|
|
||||||
font-family: "HelveticaNeue-Light", "Helvetica Neue Light", "Helvetica Neue", Helvetica, Arial, "Lucida Grande", sans-serif;
|
|
||||||
max-width: 1000px;
|
|
||||||
margin: 0 auto;
|
|
||||||
padding-top: 20px;
|
|
||||||
}
|
|
||||||
|
|
||||||
#root .screenContainer {
|
|
||||||
background: rgba(0,0,0,0.8);
|
|
||||||
border: 20px solid;
|
|
||||||
height: 300px;
|
|
||||||
border-top-right-radius: 5px;
|
|
||||||
border-top-left-radius: 5px;
|
|
||||||
padding: 10px;
|
|
||||||
box-sizing: border-box;
|
|
||||||
}
|
|
||||||
|
|
||||||
#root .inputContainer {
|
|
||||||
color: white;
|
|
||||||
background: transparent;
|
|
||||||
border: none;
|
|
||||||
outline: none;
|
|
||||||
font-family: monospace;
|
|
||||||
width: 100%;
|
|
||||||
height: 100%;
|
|
||||||
}
|
|
||||||
|
|
||||||
.simple-keyboard.hg-layout-custom {
|
|
||||||
border-top-left-radius: 0px;
|
|
||||||
border-top-right-radius: 0px;
|
|
||||||
}
|
|
||||||
|
|
||||||
input {
|
|
||||||
padding: 10px;
|
|
||||||
margin: 10px 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
label {
|
|
||||||
display: block;
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
input {
|
||||||
|
width: 100%;
|
||||||
|
height: 100px;
|
||||||
|
padding: 20px;
|
||||||
|
font-size: 20px;
|
||||||
|
border: none;
|
||||||
|
box-sizing: border-box;
|
||||||
|
}
|
||||||
|
|
||||||
|
.simple-keyboard {
|
||||||
|
max-width: 850px;
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
#root {
|
||||||
|
padding: 0px 40px;
|
||||||
|
}
|
||||||
+16
-3
@@ -1,6 +1,19 @@
|
|||||||
import App from './App';
|
import "./css/index.css";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializing demo
|
* Demos
|
||||||
*/
|
*/
|
||||||
new App();
|
import BasicDemo from "./BasicDemo";
|
||||||
|
//import FullKeyboardDemo from "./FullKeyboardDemo";
|
||||||
|
//import ButtonThemeDemo from "./ButtonThemeDemo";
|
||||||
|
//import MultipleKeyboardsDemo from "./MultipleKeyboardsDestroyDemo";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Selected demo
|
||||||
|
*/
|
||||||
|
const SELECTED_DEMO = BasicDemo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bootstrap
|
||||||
|
*/
|
||||||
|
new SELECTED_DEMO();
|
||||||
|
|||||||
@@ -0,0 +1,61 @@
|
|||||||
|
import TestUtility from '../../utils/TestUtility';
|
||||||
|
import BasicDemo from '../BasicDemo';
|
||||||
|
|
||||||
|
let testUtil = new TestUtility();
|
||||||
|
|
||||||
|
it('Demo will load', () => {
|
||||||
|
testUtil.setDOM();
|
||||||
|
|
||||||
|
let demo = new BasicDemo();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Demo onDOMLoaded will work', () => {
|
||||||
|
testUtil.setDOM();
|
||||||
|
|
||||||
|
let demo = new BasicDemo();
|
||||||
|
|
||||||
|
expect(demo.keyboard).toBeTruthy();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Demo onChange will work', () => {
|
||||||
|
testUtil.setDOM();
|
||||||
|
|
||||||
|
let demo = new BasicDemo();
|
||||||
|
|
||||||
|
demo.onChange("test");
|
||||||
|
|
||||||
|
expect(document.body.querySelector('.input').value).toBe("test");
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Demo onChange will work', () => {
|
||||||
|
testUtil.setDOM();
|
||||||
|
|
||||||
|
let demo = new BasicDemo();
|
||||||
|
|
||||||
|
demo.keyboard.getButtonElement("q").onclick();
|
||||||
|
|
||||||
|
expect(document.body.querySelector('.input').value).toBe("q");
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Demo input change will work', () => {
|
||||||
|
testUtil.setDOM();
|
||||||
|
|
||||||
|
let demo = new BasicDemo();
|
||||||
|
|
||||||
|
document.body.querySelector('.input').value = "test";
|
||||||
|
document.body.querySelector('.input').dispatchEvent(new Event('input'));
|
||||||
|
|
||||||
|
expect(demo.keyboard.getInput()).toBe("test");
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Demo handleShiftButton will work', () => {
|
||||||
|
testUtil.setDOM();
|
||||||
|
|
||||||
|
let demo = new BasicDemo();
|
||||||
|
|
||||||
|
demo.keyboard.getButtonElement("{shift}")[0].onclick();
|
||||||
|
expect(demo.keyboard.options.layoutName).toBe("shift");
|
||||||
|
|
||||||
|
demo.keyboard.getButtonElement("{shift}")[0].onclick();
|
||||||
|
expect(demo.keyboard.options.layoutName).toBe("default");
|
||||||
|
});
|
||||||
@@ -0,0 +1,77 @@
|
|||||||
|
import TestUtility from '../../utils/TestUtility';
|
||||||
|
import ButtonThemeDemo from '../ButtonThemeDemo';
|
||||||
|
|
||||||
|
let testUtil = new TestUtility();
|
||||||
|
|
||||||
|
it('Demo will load', () => {
|
||||||
|
testUtil.setDOM();
|
||||||
|
|
||||||
|
let demo = new ButtonThemeDemo();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Demo onDOMLoaded will work', () => {
|
||||||
|
testUtil.setDOM();
|
||||||
|
|
||||||
|
let demo = new ButtonThemeDemo();
|
||||||
|
|
||||||
|
expect(demo.keyboard).toBeTruthy();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Demo onChange will work', () => {
|
||||||
|
testUtil.setDOM();
|
||||||
|
|
||||||
|
let demo = new ButtonThemeDemo();
|
||||||
|
|
||||||
|
demo.onChange("test");
|
||||||
|
|
||||||
|
expect(document.body.querySelector('.input').value).toBe("test");
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Demo onChange will work', () => {
|
||||||
|
testUtil.setDOM();
|
||||||
|
|
||||||
|
let demo = new ButtonThemeDemo();
|
||||||
|
|
||||||
|
demo.keyboard.getButtonElement("q").onclick();
|
||||||
|
|
||||||
|
expect(document.body.querySelector('.input').value).toBe("q");
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Demo input change will work', () => {
|
||||||
|
testUtil.setDOM();
|
||||||
|
|
||||||
|
let demo = new ButtonThemeDemo();
|
||||||
|
|
||||||
|
document.body.querySelector('.input').value = "test";
|
||||||
|
document.body.querySelector('.input').dispatchEvent(new Event('input'));
|
||||||
|
|
||||||
|
expect(demo.keyboard.getInput()).toBe("test");
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Demo handleShiftButton will work', () => {
|
||||||
|
testUtil.setDOM();
|
||||||
|
|
||||||
|
let demo = new ButtonThemeDemo();
|
||||||
|
|
||||||
|
demo.keyboard.getButtonElement("{shift}")[0].onclick();
|
||||||
|
expect(demo.keyboard.options.layoutName).toBe("shift");
|
||||||
|
|
||||||
|
demo.keyboard.getButtonElement("{shift}")[0].onclick();
|
||||||
|
expect(demo.keyboard.options.layoutName).toBe("default");
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Demo buttons will have proper attributes and classes', () => {
|
||||||
|
testUtil.setDOM();
|
||||||
|
|
||||||
|
let demo = new ButtonThemeDemo();
|
||||||
|
|
||||||
|
let buttonDOM = demo.keyboard.getButtonElement("b");
|
||||||
|
|
||||||
|
console.log("buttonDOM", buttonDOM.outerHTML);
|
||||||
|
|
||||||
|
let hasAttribute = buttonDOM.hasAttribute("aria-label");
|
||||||
|
expect(hasAttribute).toBeTruthy();
|
||||||
|
|
||||||
|
let hasClass = buttonDOM.classList.contains("my-button-outline");
|
||||||
|
expect(hasClass).toBeTruthy();
|
||||||
|
});
|
||||||
@@ -0,0 +1,62 @@
|
|||||||
|
import TestUtility from '../../utils/TestUtility';
|
||||||
|
import FullKeyboardDemo from '../FullKeyboardDemo';
|
||||||
|
|
||||||
|
let testUtil = new TestUtility();
|
||||||
|
|
||||||
|
it('Demo will load', () => {
|
||||||
|
testUtil.setDOM();
|
||||||
|
|
||||||
|
let demo = new FullKeyboardDemo();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Demo onDOMLoaded will work', () => {
|
||||||
|
testUtil.setDOM();
|
||||||
|
|
||||||
|
let demo = new FullKeyboardDemo();
|
||||||
|
|
||||||
|
expect(demo.keyboard).toBeTruthy();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Demo onChange will work', () => {
|
||||||
|
testUtil.setDOM();
|
||||||
|
|
||||||
|
let demo = new FullKeyboardDemo();
|
||||||
|
|
||||||
|
demo.onChange("test");
|
||||||
|
|
||||||
|
expect(document.body.querySelector('.input').value).toBe("test");
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Demo onChange will work', () => {
|
||||||
|
testUtil.setDOM();
|
||||||
|
|
||||||
|
let demo = new FullKeyboardDemo();
|
||||||
|
|
||||||
|
demo.keyboard.getButtonElement("q").onclick();
|
||||||
|
|
||||||
|
expect(document.body.querySelector('.input').value).toBe("q");
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Demo input change will work', () => {
|
||||||
|
testUtil.setDOM();
|
||||||
|
|
||||||
|
let demo = new FullKeyboardDemo();
|
||||||
|
|
||||||
|
document.body.querySelector('.input').value = "test";
|
||||||
|
document.body.querySelector('.input').dispatchEvent(new Event('input'));
|
||||||
|
|
||||||
|
expect(demo.keyboard.getInput()).toBe("test");
|
||||||
|
expect(demo.keyboardNumPad.getInput()).toBe("test");
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Demo handleShiftButton will work', () => {
|
||||||
|
testUtil.setDOM();
|
||||||
|
|
||||||
|
let demo = new FullKeyboardDemo();
|
||||||
|
|
||||||
|
demo.keyboard.getButtonElement("{shiftleft}").onclick();
|
||||||
|
expect(demo.keyboard.options.layoutName).toBe("shift");
|
||||||
|
|
||||||
|
demo.keyboard.getButtonElement("{shiftright}").onclick();
|
||||||
|
expect(demo.keyboard.options.layoutName).toBe("default");
|
||||||
|
});
|
||||||
@@ -0,0 +1,67 @@
|
|||||||
|
import TestUtility from '../../utils/TestUtility';
|
||||||
|
import MultipleKeyboardsDestroyDemo from '../MultipleKeyboardsDestroyDemo';
|
||||||
|
|
||||||
|
let testUtil = new TestUtility();
|
||||||
|
|
||||||
|
it('Demo will load', () => {
|
||||||
|
testUtil.setDOM();
|
||||||
|
|
||||||
|
let demo = new MultipleKeyboardsDestroyDemo();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Demo onDOMLoaded will work', () => {
|
||||||
|
testUtil.setDOM();
|
||||||
|
|
||||||
|
let demo = new MultipleKeyboardsDestroyDemo();
|
||||||
|
|
||||||
|
expect(demo.keyboard).toBeTruthy();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Demo onChange will work', () => {
|
||||||
|
testUtil.setDOM();
|
||||||
|
|
||||||
|
let demo = new MultipleKeyboardsDestroyDemo();
|
||||||
|
|
||||||
|
demo.onChange("test");
|
||||||
|
demo.keyboard2.getButtonElement("q").click();
|
||||||
|
|
||||||
|
expect(document.body.querySelector('.input').value).toBe("test");
|
||||||
|
expect(document.body.querySelector('.input2').value).toBe("q");
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Demo onChange will work', () => {
|
||||||
|
testUtil.setDOM();
|
||||||
|
|
||||||
|
let demo = new MultipleKeyboardsDestroyDemo();
|
||||||
|
|
||||||
|
demo.keyboard.getButtonElement("q").onclick();
|
||||||
|
|
||||||
|
expect(document.body.querySelector('.input').value).toBe("q");
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Demo input change will work', () => {
|
||||||
|
testUtil.setDOM();
|
||||||
|
|
||||||
|
let demo = new MultipleKeyboardsDestroyDemo();
|
||||||
|
|
||||||
|
document.body.querySelector('.input').value = "test";
|
||||||
|
document.body.querySelector('.input').dispatchEvent(new Event('input'));
|
||||||
|
|
||||||
|
document.body.querySelector('.input2').value = "test2";
|
||||||
|
document.body.querySelector('.input2').dispatchEvent(new Event('input'));
|
||||||
|
|
||||||
|
expect(demo.keyboard.getInput()).toBe("test");
|
||||||
|
expect(demo.keyboard2.getInput()).toBe("test2");
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Demo handleShiftButton will work', () => {
|
||||||
|
testUtil.setDOM();
|
||||||
|
|
||||||
|
let demo = new MultipleKeyboardsDestroyDemo();
|
||||||
|
|
||||||
|
demo.keyboard.getButtonElement("{shift}")[0].onclick();
|
||||||
|
expect(demo.keyboard.options.layoutName).toBe("shift");
|
||||||
|
|
||||||
|
demo.keyboard.getButtonElement("{shift}")[0].onclick();
|
||||||
|
expect(demo.keyboard.options.layoutName).toBe("default");
|
||||||
|
});
|
||||||
Vendored
+261
@@ -0,0 +1,261 @@
|
|||||||
|
declare module 'simple-keyboard' {
|
||||||
|
interface KeyboardLayoutObject {
|
||||||
|
default: string[];
|
||||||
|
shift?: any;
|
||||||
|
[key: string]: string[];
|
||||||
|
}
|
||||||
|
|
||||||
|
interface KeyboardButtonTheme {
|
||||||
|
class: string;
|
||||||
|
buttons: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface KeyboardButtonAttributes {
|
||||||
|
attribute: string;
|
||||||
|
value: string;
|
||||||
|
buttons: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface KeyboardOptions {
|
||||||
|
/**
|
||||||
|
* Modify the keyboard layout.
|
||||||
|
*/
|
||||||
|
layout?: KeyboardLayoutObject;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Specifies which layout should be used.
|
||||||
|
*/
|
||||||
|
layoutName?: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Replaces variable buttons (such as `{bksp}`) with a human-friendly name (e.g.: `backspace`).
|
||||||
|
*/
|
||||||
|
display?: { [button: string]: string };
|
||||||
|
|
||||||
|
/**
|
||||||
|
* By default, when you set the display property, you replace the default one. This setting merges them instead.
|
||||||
|
*/
|
||||||
|
mergeDisplay?: boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A prop to add your own css classes to the keyboard wrapper. You can add multiple classes separated by a space.
|
||||||
|
*/
|
||||||
|
theme?: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A prop to add your own css classes to one or several buttons.
|
||||||
|
*/
|
||||||
|
buttonTheme?: KeyboardButtonTheme[];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
class Keyboard {
|
||||||
|
constructor(selector: string, options: KeyboardOptions);
|
||||||
|
constructor(options: KeyboardOptions);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Options
|
||||||
|
*/
|
||||||
|
options: KeyboardOptions;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Utilities
|
||||||
|
*/
|
||||||
|
utilities?: any;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* caretPosition
|
||||||
|
*/
|
||||||
|
caretPosition?: number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds/Modifies an entry to the `buttonTheme`. Basically a way to add a class to a button.
|
||||||
|
* @param {string} buttons List of buttons to select (separated by a space).
|
||||||
|
* @param {string} className Classes to give to the selected buttons (separated by space).
|
||||||
|
*/
|
||||||
|
addButtonTheme(buttons: string, className: string): void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes/Amends an entry to the `buttonTheme`. Basically a way to remove a class previously added to a button through buttonTheme or addButtonTheme.
|
||||||
|
* @param {string} buttons List of buttons to select (separated by a space).
|
||||||
|
* @param {string} className Classes to give to the selected buttons (separated by space).
|
||||||
|
*/
|
||||||
|
removeButtonTheme(buttons: string, className: string): void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clear the keyboard's input.
|
||||||
|
*
|
||||||
|
* @param {string} [inputName] optional - the internal input to select
|
||||||
|
*/
|
||||||
|
clearInput(inputName?: string): void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the keyboard’s input (You can also get it from the onChange prop).
|
||||||
|
* @param {string} [inputName] optional - the internal input to select
|
||||||
|
*/
|
||||||
|
getInput(inputName?: string): string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the keyboard’s input.
|
||||||
|
* @param {string} input the input value
|
||||||
|
* @param {string} inputName optional - the internal input to select
|
||||||
|
*/
|
||||||
|
setInput(input: string, inputName?: string): void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set new option or modify existing ones after initialization.
|
||||||
|
* @param {KeyboardOptions} option The option to set
|
||||||
|
*/
|
||||||
|
setOptions(options: KeyboardOptions): void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send a command to all simple-keyboard instances at once (if you have multiple instances).
|
||||||
|
* @param {function(instance: object, key: string)} callback Function to run on every instance
|
||||||
|
*/
|
||||||
|
dispatch(callback: (instance: any, key: string) => void): void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the DOM Element of a button. If there are several buttons with the same name, an array of the DOM Elements is returned.
|
||||||
|
* @param {string} button The button layout name to select
|
||||||
|
*/
|
||||||
|
getButtonElement(button: string): HTMLElement | HTMLElement[];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clears keyboard listeners and DOM elements.
|
||||||
|
*/
|
||||||
|
destroy(): void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default Keyboard;
|
||||||
|
}
|
||||||
@@ -1,14 +1,17 @@
|
|||||||
body, html {
|
body,
|
||||||
|
html {
|
||||||
margin: 0;
|
margin: 0;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.simple-keyboard {
|
.simple-keyboard {
|
||||||
font-family: "HelveticaNeue-Light", "Helvetica Neue Light", "Helvetica Neue", Helvetica, Arial, "Lucida Grande", sans-serif;
|
font-family: "HelveticaNeue-Light", "Helvetica Neue Light", "Helvetica Neue",
|
||||||
|
Helvetica, Arial, "Lucida Grande", sans-serif;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
user-select: none;
|
user-select: none;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
|
touch-action: manipulation;
|
||||||
}
|
}
|
||||||
|
|
||||||
.simple-keyboard .hg-row {
|
.simple-keyboard .hg-row {
|
||||||
@@ -23,38 +26,62 @@ body, html {
|
|||||||
margin-right: 5px;
|
margin-right: 5px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.simple-keyboard .hg-row .hg-button-container {
|
||||||
|
margin-right: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.simple-keyboard .hg-row > div:last-child {
|
||||||
|
margin-right: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.simple-keyboard .hg-row .hg-button-container {
|
||||||
|
display: flex;
|
||||||
|
}
|
||||||
|
|
||||||
.simple-keyboard .hg-button {
|
.simple-keyboard .hg-button {
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
flex-grow: 1;
|
flex-grow: 1;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
.simple-keyboard.hg-layout-default .hg-button.hg-standardBtn {
|
.simple-keyboard .hg-button span {
|
||||||
max-width: 100px;
|
pointer-events: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* hg-theme-default theme
|
* hg-theme-default theme
|
||||||
*/
|
*/
|
||||||
.simple-keyboard.hg-theme-default {
|
.simple-keyboard.hg-theme-default {
|
||||||
background-color: rgba(0,0,0,0.1);
|
background-color: rgba(0, 0, 0, 0.1);
|
||||||
padding: 5px;
|
padding: 5px;
|
||||||
border-radius: 5px;
|
border-radius: 5px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.simple-keyboard.hg-theme-default .hg-button {
|
.simple-keyboard.hg-theme-default .hg-button {
|
||||||
box-shadow: 0px 0px 3px -1px rgba(0,0,0,0.3);
|
box-shadow: 0px 0px 3px -1px rgba(0, 0, 0, 0.3);
|
||||||
height: 40px;
|
height: 40px;
|
||||||
border-radius: 5px;
|
border-radius: 5px;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
padding: 5px;
|
padding: 5px;
|
||||||
background: white;
|
background: white;
|
||||||
border-bottom: 1px solid #b5b5b5;
|
border-bottom: 1px solid #b5b5b5;
|
||||||
}
|
cursor: pointer;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
-webkit-tap-highlight-color: rgba(0, 0, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
.simple-keyboard.hg-theme-default .hg-button:active {
|
.simple-keyboard.hg-theme-default .hg-button.hg-activeButton {
|
||||||
background: #e4e4e4;
|
background: #efefef;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* When using option "useButtonTag" */
|
||||||
|
.simple-keyboard button.hg-button {
|
||||||
|
border-width: 0;
|
||||||
|
outline: 0;
|
||||||
|
font-size: inherit;
|
||||||
|
}
|
||||||
|
|
||||||
.simple-keyboard.hg-theme-default.hg-layout-numeric .hg-button {
|
.simple-keyboard.hg-theme-default.hg-layout-numeric .hg-button {
|
||||||
width: 33.3%;
|
width: 33.3%;
|
||||||
@@ -62,4 +89,37 @@ body, html {
|
|||||||
align-items: center;
|
align-items: center;
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.simple-keyboard.hg-theme-default .hg-button.hg-button-numpadadd {
|
||||||
|
height: 85px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.simple-keyboard.hg-theme-default .hg-button.hg-button-numpadenter {
|
||||||
|
height: 85px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.simple-keyboard.hg-theme-default .hg-button.hg-button-numpad0 {
|
||||||
|
width: 105px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.simple-keyboard.hg-theme-default .hg-button.hg-button-com {
|
||||||
|
max-width: 85px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.simple-keyboard.hg-theme-default .hg-button.hg-standardBtn.hg-button-at {
|
||||||
|
max-width: 45px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.simple-keyboard.hg-theme-default .hg-button.hg-selectedButton {
|
||||||
|
background: rgba(5, 25, 70, 0.53);
|
||||||
|
color: white;
|
||||||
|
}
|
||||||
|
|
||||||
|
.simple-keyboard.hg-theme-default .hg-button.hg-standardBtn[data-skbtn=".com"] {
|
||||||
|
max-width: 82px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.simple-keyboard.hg-theme-default .hg-button.hg-standardBtn[data-skbtn="@"] {
|
||||||
|
max-width: 60px;
|
||||||
|
}
|
||||||
|
|||||||
+1290
-91
File diff suppressed because it is too large
Load Diff
@@ -1,8 +0,0 @@
|
|||||||
import React from 'react';
|
|
||||||
import ReactDOM from 'react-dom';
|
|
||||||
import Keyboard from './Keyboard';
|
|
||||||
|
|
||||||
it('Keyboard renders without crashing', () => {
|
|
||||||
const div = document.createElement('div');
|
|
||||||
ReactDOM.render(<Keyboard />, div);
|
|
||||||
});
|
|
||||||
File diff suppressed because it is too large
Load Diff
+1
-1
@@ -1,2 +1,2 @@
|
|||||||
import SimpleKeyboard from './components/Keyboard';
|
import SimpleKeyboard from "./components/Keyboard";
|
||||||
export default SimpleKeyboard;
|
export default SimpleKeyboard;
|
||||||
|
|||||||
@@ -1,37 +1,29 @@
|
|||||||
|
/**
|
||||||
|
* Keyboard Layout Service
|
||||||
|
*/
|
||||||
class KeyboardLayout {
|
class KeyboardLayout {
|
||||||
|
/**
|
||||||
static getLayout = layout => {
|
* Get default simple-keyboard layout
|
||||||
if(layout === "qwerty"){
|
* @return {object} The default layout (US-QWERTY)
|
||||||
return {
|
*/
|
||||||
'default': [
|
static getDefaultLayout() {
|
||||||
'` 1 2 3 4 5 6 7 8 9 0 - = {bksp}',
|
return {
|
||||||
'{tab} q w e r t y u i o p [ ] \\',
|
default: [
|
||||||
'{lock} a s d f g h j k l ; \' {enter}',
|
"` 1 2 3 4 5 6 7 8 9 0 - = {bksp}",
|
||||||
'{shift} z x c v b n m , . / {shift}',
|
"{tab} q w e r t y u i o p [ ] \\",
|
||||||
'.com @ {space}'
|
"{lock} a s d f g h j k l ; ' {enter}",
|
||||||
],
|
"{shift} z x c v b n m , . / {shift}",
|
||||||
'shift': [
|
".com @ {space}"
|
||||||
'~ ! @ # $ % ^ & * ( ) _ + {bksp}',
|
],
|
||||||
'{tab} Q W E R T Y U I O P { } |',
|
shift: [
|
||||||
'{lock} A S D F G H J K L : " {enter}',
|
"~ ! @ # $ % ^ & * ( ) _ + {bksp}",
|
||||||
'{shift} Z X C V B N M < > ? {shift}',
|
"{tab} Q W E R T Y U I O P { } |",
|
||||||
'.com @ {space}'
|
'{lock} A S D F G H J K L : " {enter}',
|
||||||
]
|
"{shift} Z X C V B N M < > ? {shift}",
|
||||||
};
|
".com @ {space}"
|
||||||
} else if(layout === "numeric"){
|
]
|
||||||
return {
|
};
|
||||||
'default': [
|
|
||||||
'1 2 3',
|
|
||||||
'4 5 6',
|
|
||||||
'7 8 9',
|
|
||||||
'{//} 0 {bksp}'
|
|
||||||
]
|
|
||||||
};
|
|
||||||
} else {
|
|
||||||
return KeyboardLayout.getLayout("qwerty");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default KeyboardLayout;
|
export default KeyboardLayout;
|
||||||
|
|||||||
@@ -0,0 +1,92 @@
|
|||||||
|
import Utilities from "../services/Utilities";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Physical Keyboard Service
|
||||||
|
*/
|
||||||
|
class PhysicalKeyboard {
|
||||||
|
/**
|
||||||
|
* Creates an instance of the PhysicalKeyboard service
|
||||||
|
*/
|
||||||
|
constructor({ dispatch, getOptions }) {
|
||||||
|
/**
|
||||||
|
* @type {object} A simple-keyboard instance
|
||||||
|
*/
|
||||||
|
this.dispatch = dispatch;
|
||||||
|
this.getOptions = getOptions;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bindings
|
||||||
|
*/
|
||||||
|
Utilities.bindMethods(PhysicalKeyboard, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
handleHighlightKeyDown(event) {
|
||||||
|
let options = this.getOptions();
|
||||||
|
let buttonPressed = this.getSimpleKeyboardLayoutKey(event);
|
||||||
|
|
||||||
|
this.dispatch(instance => {
|
||||||
|
let buttonDOM =
|
||||||
|
instance.getButtonElement(buttonPressed) ||
|
||||||
|
instance.getButtonElement(`{${buttonPressed}}`);
|
||||||
|
|
||||||
|
if (buttonDOM) {
|
||||||
|
buttonDOM.style.backgroundColor =
|
||||||
|
options.physicalKeyboardHighlightBgColor || "#9ab4d0";
|
||||||
|
buttonDOM.style.color =
|
||||||
|
options.physicalKeyboardHighlightTextColor || "white";
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
handleHighlightKeyUp(event) {
|
||||||
|
let buttonPressed = this.getSimpleKeyboardLayoutKey(event);
|
||||||
|
|
||||||
|
this.dispatch(instance => {
|
||||||
|
let buttonDOM =
|
||||||
|
instance.getButtonElement(buttonPressed) ||
|
||||||
|
instance.getButtonElement(`{${buttonPressed}}`);
|
||||||
|
|
||||||
|
if (buttonDOM && buttonDOM.removeAttribute) {
|
||||||
|
buttonDOM.removeAttribute("style");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Transforms a KeyboardEvent's "key.code" string into a simple-keyboard layout format
|
||||||
|
* @param {object} event The KeyboardEvent
|
||||||
|
*/
|
||||||
|
getSimpleKeyboardLayoutKey(event) {
|
||||||
|
let output;
|
||||||
|
|
||||||
|
if (
|
||||||
|
event.code.includes("Numpad") ||
|
||||||
|
event.code.includes("Shift") ||
|
||||||
|
event.code.includes("Space") ||
|
||||||
|
event.code.includes("Backspace") ||
|
||||||
|
event.code.includes("Control") ||
|
||||||
|
event.code.includes("Alt") ||
|
||||||
|
event.code.includes("Meta")
|
||||||
|
) {
|
||||||
|
output = event.code;
|
||||||
|
} else {
|
||||||
|
output = event.key;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If button is not uppercase, casting to lowercase
|
||||||
|
*/
|
||||||
|
if (
|
||||||
|
output !== output.toUpperCase() ||
|
||||||
|
(event.code[0] === "F" &&
|
||||||
|
Number.isInteger(Number(event.code[1])) &&
|
||||||
|
event.code.length <= 3)
|
||||||
|
) {
|
||||||
|
output = output.toLowerCase();
|
||||||
|
}
|
||||||
|
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default PhysicalKeyboard;
|
||||||
+383
-68
@@ -1,92 +1,407 @@
|
|||||||
|
/**
|
||||||
|
* Utility Service
|
||||||
|
*/
|
||||||
class Utilities {
|
class Utilities {
|
||||||
static normalizeString(string){
|
/**
|
||||||
let output;
|
* Creates an instance of the Utility service
|
||||||
|
*/
|
||||||
|
constructor({ getOptions, getCaretPosition, dispatch }) {
|
||||||
|
this.getOptions = getOptions;
|
||||||
|
this.getCaretPosition = getCaretPosition;
|
||||||
|
this.dispatch = dispatch;
|
||||||
|
|
||||||
if(string === "@")
|
/**
|
||||||
output = 'at';
|
* Bindings
|
||||||
else if(string === ",")
|
*/
|
||||||
output = 'comma';
|
Utilities.bindMethods(Utilities, this);
|
||||||
else if(string === ".")
|
|
||||||
output = 'dot';
|
|
||||||
else if(string === "\\")
|
|
||||||
output = 'backslash';
|
|
||||||
else if(string === "/")
|
|
||||||
output = 'fordardslash';
|
|
||||||
else if(string === "*")
|
|
||||||
output = 'asterisk';
|
|
||||||
else if(string === "&")
|
|
||||||
output = 'ampersand';
|
|
||||||
else if(string === "$")
|
|
||||||
output = 'dollarsign';
|
|
||||||
else if(string === "=")
|
|
||||||
output = 'equals';
|
|
||||||
else if(string === "+")
|
|
||||||
output = 'plus';
|
|
||||||
else if(string === "-")
|
|
||||||
output = 'minus';
|
|
||||||
else if(string === "'")
|
|
||||||
output = 'apostrophe';
|
|
||||||
else if(string === ";")
|
|
||||||
output = 'colon';
|
|
||||||
else if(string === "[")
|
|
||||||
output = 'openbracket';
|
|
||||||
else if(string === "]")
|
|
||||||
output = 'closebracket';
|
|
||||||
else if(string === "//")
|
|
||||||
output = 'emptybutton';
|
|
||||||
else
|
|
||||||
output = '';
|
|
||||||
|
|
||||||
return output ? ` hg-button-${output}` : '';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static getButtonClass = button => {
|
/**
|
||||||
let buttonTypeClass = (button.includes("{") && button !== '{//}') ? "functionBtn" : "standardBtn";
|
* Adds default classes to a given button
|
||||||
|
*
|
||||||
|
* @param {string} button The button's layout name
|
||||||
|
* @return {string} The classes to be added to the button
|
||||||
|
*/
|
||||||
|
getButtonClass(button) {
|
||||||
|
let buttonTypeClass =
|
||||||
|
button.includes("{") && button.includes("}") && button !== "{//}"
|
||||||
|
? "functionBtn"
|
||||||
|
: "standardBtn";
|
||||||
let buttonWithoutBraces = button.replace("{", "").replace("}", "");
|
let buttonWithoutBraces = button.replace("{", "").replace("}", "");
|
||||||
|
let buttonNormalized = "";
|
||||||
|
|
||||||
let buttonNormalized =
|
if (buttonTypeClass !== "standardBtn")
|
||||||
buttonTypeClass === "standardBtn" ?
|
buttonNormalized = ` hg-button-${buttonWithoutBraces}`;
|
||||||
Utilities.normalizeString(buttonWithoutBraces) : ` hg-button-${buttonWithoutBraces}`;
|
|
||||||
|
|
||||||
return `hg-${buttonTypeClass}${buttonNormalized}`;
|
return `hg-${buttonTypeClass}${buttonNormalized}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
static getDefaultDiplay(){
|
/**
|
||||||
|
* Default button display labels
|
||||||
|
*/
|
||||||
|
getDefaultDiplay() {
|
||||||
return {
|
return {
|
||||||
'{bksp}': 'delete',
|
"{bksp}": "backspace",
|
||||||
'{enter}': '< enter',
|
"{backspace}": "backspace",
|
||||||
'{shift}': 'shift',
|
"{enter}": "< enter",
|
||||||
'{s}': 'shift',
|
"{shift}": "shift",
|
||||||
'{tab}': 'tab',
|
"{shiftleft}": "shift",
|
||||||
'{lock}': 'caps',
|
"{shiftright}": "shift",
|
||||||
'{accept}': 'Submit',
|
"{alt}": "alt",
|
||||||
'{space}': ' ',
|
"{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}": "↑",
|
||||||
|
"{arrowleft}": "←",
|
||||||
|
"{arrowdown}": "↓",
|
||||||
|
"{arrowright}": "→",
|
||||||
|
"{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"
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* Returns the display (label) name for a given button
|
||||||
|
*
|
||||||
|
* @param {string} button The button's layout name
|
||||||
|
* @param {object} display The provided display option
|
||||||
|
* @param {boolean} mergeDisplay Whether the provided param value should be merged with the default one.
|
||||||
|
*/
|
||||||
|
getButtonDisplayName(button, display, mergeDisplay) {
|
||||||
|
if (mergeDisplay) {
|
||||||
|
display = Object.assign({}, this.getDefaultDiplay(), display);
|
||||||
|
} else {
|
||||||
|
display = display || this.getDefaultDiplay();
|
||||||
|
}
|
||||||
|
|
||||||
static getButtonDisplayName = (button, display) => {
|
|
||||||
display = display || Utilities.getDefaultDiplay();
|
|
||||||
return display[button] || button;
|
return display[button] || button;
|
||||||
}
|
}
|
||||||
|
|
||||||
static getUpdatedInput = (button, input, options) => {
|
/**
|
||||||
|
* Returns the updated input resulting from clicking a given button
|
||||||
|
*
|
||||||
|
* @param {string} button The button's layout name
|
||||||
|
* @param {string} input The input string
|
||||||
|
* @param {number} caretPos The cursor's current position
|
||||||
|
* @param {boolean} moveCaret Whether to update simple-keyboard's cursor
|
||||||
|
*/
|
||||||
|
getUpdatedInput(button, input, caretPos, moveCaret) {
|
||||||
|
let options = this.getOptions();
|
||||||
let output = input;
|
let output = input;
|
||||||
let newLineOnEnter = options.newLineOnEnter;
|
|
||||||
|
|
||||||
if(button === "{bksp}" && output.length > 0)
|
if (
|
||||||
output = output.slice(0, -1);
|
(button === "{bksp}" || button === "{backspace}") &&
|
||||||
else if(button === "{space}")
|
output.length > 0
|
||||||
output = output + ' ';
|
) {
|
||||||
else if(button === "{tab}")
|
output = this.removeAt(output, caretPos, moveCaret);
|
||||||
output = output + "\t";
|
} else if (button === "{space}")
|
||||||
else if(button === "{enter}" && newLineOnEnter)
|
output = this.addStringAt(output, " ", caretPos, moveCaret);
|
||||||
output = output + "\n";
|
else if (
|
||||||
else if(!button.includes("{") && !button.includes("}"))
|
button === "{tab}" &&
|
||||||
output = output + button;
|
!(
|
||||||
|
typeof options.tabCharOnTab === "boolean" &&
|
||||||
|
options.tabCharOnTab === false
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
output = this.addStringAt(output, "\t", caretPos, moveCaret);
|
||||||
|
} else if (
|
||||||
|
(button === "{enter}" || button === "{numpadenter}") &&
|
||||||
|
options.newLineOnEnter
|
||||||
|
)
|
||||||
|
output = this.addStringAt(output, "\n", caretPos, moveCaret);
|
||||||
|
else if (
|
||||||
|
button.includes("numpad") &&
|
||||||
|
Number.isInteger(Number(button[button.length - 2]))
|
||||||
|
) {
|
||||||
|
output = this.addStringAt(
|
||||||
|
output,
|
||||||
|
button[button.length - 2],
|
||||||
|
caretPos,
|
||||||
|
moveCaret
|
||||||
|
);
|
||||||
|
} else if (button === "{numpaddivide}")
|
||||||
|
output = this.addStringAt(output, "/", caretPos, moveCaret);
|
||||||
|
else if (button === "{numpadmultiply}")
|
||||||
|
output = this.addStringAt(output, "*", caretPos, moveCaret);
|
||||||
|
else if (button === "{numpadsubtract}")
|
||||||
|
output = this.addStringAt(output, "-", caretPos, moveCaret);
|
||||||
|
else if (button === "{numpadadd}")
|
||||||
|
output = this.addStringAt(output, "+", caretPos, moveCaret);
|
||||||
|
else if (button === "{numpaddecimal}")
|
||||||
|
output = this.addStringAt(output, ".", caretPos, moveCaret);
|
||||||
|
else if (button === "{" || button === "}")
|
||||||
|
output = this.addStringAt(output, button, caretPos, moveCaret);
|
||||||
|
else if (!button.includes("{") && !button.includes("}"))
|
||||||
|
output = this.addStringAt(output, button, caretPos, moveCaret);
|
||||||
|
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Moves the cursor position by a given amount
|
||||||
|
*
|
||||||
|
* @param {number} length Represents by how many characters the input should be moved
|
||||||
|
* @param {boolean} minus Whether the cursor should be moved to the left or not.
|
||||||
|
*/
|
||||||
|
updateCaretPos(length, minus) {
|
||||||
|
let newCaretPos = this.updateCaretPosAction(length, minus);
|
||||||
|
|
||||||
|
this.dispatch(instance => {
|
||||||
|
instance.caretPosition = newCaretPos;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Action method of updateCaretPos
|
||||||
|
*
|
||||||
|
* @param {number} length Represents by how many characters the input should be moved
|
||||||
|
* @param {boolean} minus Whether the cursor should be moved to the left or not.
|
||||||
|
*/
|
||||||
|
updateCaretPosAction(length, minus) {
|
||||||
|
let options = this.getOptions();
|
||||||
|
let caretPosition = this.getCaretPosition();
|
||||||
|
|
||||||
|
if (minus) {
|
||||||
|
if (caretPosition > 0) caretPosition = caretPosition - length;
|
||||||
|
} else {
|
||||||
|
caretPosition = caretPosition + length;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (options.debug) {
|
||||||
|
console.log("Caret at:", caretPosition, `(${this.keyboardDOMClass})`);
|
||||||
|
}
|
||||||
|
|
||||||
|
return caretPosition;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a string to the input at a given position
|
||||||
|
*
|
||||||
|
* @param {string} source The source input
|
||||||
|
* @param {string} string The string to add
|
||||||
|
* @param {number} position The (cursor) position where the string should be added
|
||||||
|
* @param {boolean} moveCaret Whether to update simple-keyboard's cursor
|
||||||
|
*/
|
||||||
|
addStringAt(source, string, position, moveCaret) {
|
||||||
|
let output;
|
||||||
|
|
||||||
|
if (!position && position !== 0) {
|
||||||
|
output = source + string;
|
||||||
|
} else {
|
||||||
|
output = [source.slice(0, position), string, source.slice(position)].join(
|
||||||
|
""
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Avoid caret position change when maxLength is set
|
||||||
|
*/
|
||||||
|
if (!this.isMaxLengthReached()) {
|
||||||
|
if (moveCaret) this.updateCaretPos(string.length);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes an amount of characters at a given position
|
||||||
|
*
|
||||||
|
* @param {string} source The source input
|
||||||
|
* @param {number} position The (cursor) position from where the characters should be removed
|
||||||
|
* @param {boolean} moveCaret Whether to update simple-keyboard's cursor
|
||||||
|
*/
|
||||||
|
removeAt(source, position, moveCaret) {
|
||||||
|
let caretPosition = this.getCaretPosition();
|
||||||
|
|
||||||
|
if (caretPosition === 0) {
|
||||||
|
return source;
|
||||||
|
}
|
||||||
|
|
||||||
|
let output;
|
||||||
|
let prevTwoChars;
|
||||||
|
let emojiMatched;
|
||||||
|
let emojiMatchedReg = /([\uD800-\uDBFF][\uDC00-\uDFFF])/g;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Emojis are made out of two characters, so we must take a custom approach to trim them.
|
||||||
|
* For more info: https://mathiasbynens.be/notes/javascript-unicode
|
||||||
|
*/
|
||||||
|
if (position && position >= 0) {
|
||||||
|
prevTwoChars = source.substring(position - 2, position);
|
||||||
|
emojiMatched = prevTwoChars.match(emojiMatchedReg);
|
||||||
|
|
||||||
|
if (emojiMatched) {
|
||||||
|
output = source.substr(0, position - 2) + source.substr(position);
|
||||||
|
if (moveCaret) this.updateCaretPos(2, true);
|
||||||
|
} else {
|
||||||
|
output = source.substr(0, position - 1) + source.substr(position);
|
||||||
|
if (moveCaret) this.updateCaretPos(1, true);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
prevTwoChars = source.slice(-2);
|
||||||
|
emojiMatched = prevTwoChars.match(emojiMatchedReg);
|
||||||
|
|
||||||
|
if (emojiMatched) {
|
||||||
|
output = source.slice(0, -2);
|
||||||
|
if (moveCaret) this.updateCaretPos(2, true);
|
||||||
|
} else {
|
||||||
|
output = source.slice(0, -1);
|
||||||
|
if (moveCaret) this.updateCaretPos(1, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Determines whether the maxLength has been reached. This function is called when the maxLength option it set.
|
||||||
|
*
|
||||||
|
* @param {object} inputObj
|
||||||
|
* @param {string} updatedInput
|
||||||
|
*/
|
||||||
|
handleMaxLength(inputObj, updatedInput) {
|
||||||
|
let options = this.getOptions();
|
||||||
|
let maxLength = options.maxLength;
|
||||||
|
let currentInput = inputObj[options.inputName];
|
||||||
|
let condition = updatedInput.length - 1 >= maxLength;
|
||||||
|
|
||||||
|
if (
|
||||||
|
/**
|
||||||
|
* If pressing this button won't add more characters
|
||||||
|
* We exit out of this limiter function
|
||||||
|
*/
|
||||||
|
updatedInput.length <= currentInput.length
|
||||||
|
) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Number.isInteger(maxLength)) {
|
||||||
|
if (options.debug) {
|
||||||
|
console.log("maxLength (num) reached:", condition);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (condition) {
|
||||||
|
/**
|
||||||
|
* @type {boolean} Boolean value that shows whether maxLength has been reached
|
||||||
|
*/
|
||||||
|
this.maxLengthReached = true;
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
this.maxLengthReached = false;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof maxLength === "object") {
|
||||||
|
let condition = currentInput.length === maxLength[options.inputName];
|
||||||
|
|
||||||
|
if (options.debug) {
|
||||||
|
console.log("maxLength (obj) reached:", condition);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (condition) {
|
||||||
|
this.maxLengthReached = true;
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
this.maxLengthReached = false;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the current value of maxLengthReached
|
||||||
|
*/
|
||||||
|
isMaxLengthReached() {
|
||||||
|
return Boolean(this.maxLengthReached);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines whether a touch device is being used
|
||||||
|
*/
|
||||||
|
isTouchDevice() {
|
||||||
|
return "ontouchstart" in window || navigator.maxTouchPoints;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines whether pointer events are supported
|
||||||
|
*/
|
||||||
|
pointerEventsSupported() {
|
||||||
|
return window.PointerEvent;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bind all methods in a given class
|
||||||
|
*/
|
||||||
|
|
||||||
|
static bindMethods(myClass, instance) {
|
||||||
|
// eslint-disable-next-line no-unused-vars
|
||||||
|
for (let myMethod of Object.getOwnPropertyNames(myClass.prototype)) {
|
||||||
|
let excludeMethod =
|
||||||
|
myMethod === "constructor" || myMethod === "bindMethods";
|
||||||
|
if (!excludeMethod) {
|
||||||
|
instance[myMethod] = instance[myMethod].bind(instance);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Transforms an arbitrary string to camelCase
|
||||||
|
*
|
||||||
|
* @param {string} string The string to transform.
|
||||||
|
*/
|
||||||
|
camelCase(string) {
|
||||||
|
if (!string) return false;
|
||||||
|
|
||||||
|
return string
|
||||||
|
.toLowerCase()
|
||||||
|
.trim()
|
||||||
|
.split(/[.\-_\s]/g)
|
||||||
|
.reduce((string, word) =>
|
||||||
|
word.length ? string + word[0].toUpperCase() + word.slice(1) : string
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default Utilities;
|
export default Utilities;
|
||||||
|
|||||||
@@ -0,0 +1,118 @@
|
|||||||
|
import Keyboard from '../../components/Keyboard';
|
||||||
|
import TestUtility from '../../../utils/TestUtility';
|
||||||
|
|
||||||
|
let testUtil = new TestUtility();
|
||||||
|
|
||||||
|
it('PhysicalKeyboard keydown will be handled with physicalKeyboardHighlight', () => {
|
||||||
|
testUtil.setDOM();
|
||||||
|
|
||||||
|
let keyboard = new Keyboard({
|
||||||
|
physicalKeyboardHighlight: true
|
||||||
|
});
|
||||||
|
|
||||||
|
document.dispatchEvent(new KeyboardEvent('keydown', {
|
||||||
|
code: "KeyF",
|
||||||
|
key: "f",
|
||||||
|
target: {
|
||||||
|
tagName: "input"
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
|
||||||
|
it('PhysicalKeyboard keydown will be handled without physicalKeyboardHighlight', () => {
|
||||||
|
testUtil.setDOM();
|
||||||
|
|
||||||
|
let keyboard = new Keyboard({
|
||||||
|
physicalKeyboardHighlight: false
|
||||||
|
});
|
||||||
|
|
||||||
|
document.dispatchEvent(new KeyboardEvent('keydown', {
|
||||||
|
code: "KeyF",
|
||||||
|
key: "f",
|
||||||
|
target: {
|
||||||
|
tagName: "input"
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
|
||||||
|
it('PhysicalKeyboard keydown will not style non-existent buttons', () => {
|
||||||
|
testUtil.setDOM();
|
||||||
|
|
||||||
|
let keyboard = new Keyboard({
|
||||||
|
physicalKeyboardHighlight: true
|
||||||
|
});
|
||||||
|
|
||||||
|
document.dispatchEvent(new KeyboardEvent('keydown', {
|
||||||
|
code: "WRONG",
|
||||||
|
key: "WRONG",
|
||||||
|
target: {
|
||||||
|
tagName: "input"
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
|
||||||
|
it('PhysicalKeyboard keyup will be handled with physicalKeyboardHighlight', () => {
|
||||||
|
testUtil.setDOM();
|
||||||
|
|
||||||
|
let keyboard = new Keyboard({
|
||||||
|
physicalKeyboardHighlight: true
|
||||||
|
});
|
||||||
|
|
||||||
|
document.dispatchEvent(new KeyboardEvent('keyup', {
|
||||||
|
code: "KeyF",
|
||||||
|
key: "f",
|
||||||
|
target: {
|
||||||
|
tagName: "input"
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
|
||||||
|
it('PhysicalKeyboard keyup will be handle special buttons', () => {
|
||||||
|
testUtil.setDOM();
|
||||||
|
|
||||||
|
let keyboard = new Keyboard({
|
||||||
|
physicalKeyboardHighlight: true
|
||||||
|
});
|
||||||
|
|
||||||
|
document.dispatchEvent(new KeyboardEvent('keyup', {
|
||||||
|
code: "Shift",
|
||||||
|
key: "Shift",
|
||||||
|
target: {
|
||||||
|
tagName: "input"
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
|
||||||
|
it('PhysicalKeyboard keyup will not style non-existent buttons', () => {
|
||||||
|
testUtil.setDOM();
|
||||||
|
|
||||||
|
let keyboard = new Keyboard({
|
||||||
|
physicalKeyboardHighlight: true,
|
||||||
|
debug: true
|
||||||
|
});
|
||||||
|
|
||||||
|
document.dispatchEvent(new KeyboardEvent('keyup', {
|
||||||
|
code: "WRONG",
|
||||||
|
key: "WRONG",
|
||||||
|
target: {
|
||||||
|
tagName: "input"
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
|
||||||
|
it('PhysicalKeyboard will work with F1-F12 keys', () => {
|
||||||
|
testUtil.setDOM();
|
||||||
|
|
||||||
|
let keyboard = new Keyboard({
|
||||||
|
physicalKeyboardHighlight: true,
|
||||||
|
debug: true
|
||||||
|
});
|
||||||
|
|
||||||
|
document.dispatchEvent(new KeyboardEvent('keyup', {
|
||||||
|
code: "F12",
|
||||||
|
key: "F12",
|
||||||
|
target: {
|
||||||
|
tagName: "input"
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
});
|
||||||
@@ -0,0 +1,493 @@
|
|||||||
|
import Keyboard from '../../components/Keyboard';
|
||||||
|
import TestUtility from '../../../utils/TestUtility';
|
||||||
|
|
||||||
|
let testUtil = new TestUtility();
|
||||||
|
|
||||||
|
it('Keyboard mergeDisplay will work', () => {
|
||||||
|
testUtil.setDOM();
|
||||||
|
|
||||||
|
let keyboard = new Keyboard({
|
||||||
|
mergeDisplay: true,
|
||||||
|
display: {
|
||||||
|
"q": "qreplaced"
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(keyboard.getButtonElement("q").querySelector("span").innerHTML).toBe("qreplaced");
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Keyboard function buttons will work', () => {
|
||||||
|
testUtil.setDOM();
|
||||||
|
|
||||||
|
new Keyboard();
|
||||||
|
|
||||||
|
testUtil.testLayoutFctButtons((fctBtnCount, fctBtnHasOnclickCount) => {
|
||||||
|
expect(fctBtnCount).toBe(fctBtnHasOnclickCount);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Keyboard {bksp} button will work', () => {
|
||||||
|
testUtil.setDOM();
|
||||||
|
|
||||||
|
let keyboard = new Keyboard();
|
||||||
|
|
||||||
|
let output = keyboard.utilities.getUpdatedInput("{bksp}", "test");
|
||||||
|
|
||||||
|
expect(output).toBe("tes");
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Keyboard {space} button will work', () => {
|
||||||
|
testUtil.setDOM();
|
||||||
|
|
||||||
|
let keyboard = new Keyboard();
|
||||||
|
|
||||||
|
let output = keyboard.utilities.getUpdatedInput("{space}", "test");
|
||||||
|
|
||||||
|
expect(output).toBe("test ");
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Keyboard {tab} button will work', () => {
|
||||||
|
testUtil.setDOM();
|
||||||
|
|
||||||
|
let keyboard = new Keyboard();
|
||||||
|
|
||||||
|
let output = keyboard.utilities.getUpdatedInput("{tab}", "test");
|
||||||
|
|
||||||
|
expect(output).toBe("test\t");
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Keyboard {tab} button will work with tabCharOnTab:false', () => {
|
||||||
|
testUtil.setDOM();
|
||||||
|
|
||||||
|
let keyboard = new Keyboard({
|
||||||
|
tabCharOnTab: false
|
||||||
|
});
|
||||||
|
|
||||||
|
let output = keyboard.utilities.getUpdatedInput("{tab}", "test");
|
||||||
|
|
||||||
|
expect(output).toBe("test");
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Keyboard {enter} button will work', () => {
|
||||||
|
testUtil.setDOM();
|
||||||
|
|
||||||
|
let keyboard = new Keyboard();
|
||||||
|
|
||||||
|
let output = keyboard.utilities.getUpdatedInput("{enter}", "test");
|
||||||
|
|
||||||
|
expect(output).toBe("test");
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Keyboard {enter} button will work with newLineOnEnter:true', () => {
|
||||||
|
testUtil.setDOM();
|
||||||
|
|
||||||
|
let keyboard = new Keyboard({
|
||||||
|
newLineOnEnter: true
|
||||||
|
});
|
||||||
|
|
||||||
|
let output = keyboard.utilities.getUpdatedInput("{enter}", "test");
|
||||||
|
|
||||||
|
expect(output).toBe("test\n");
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Keyboard {numpadX} buttons will work', () => {
|
||||||
|
testUtil.setDOM();
|
||||||
|
|
||||||
|
let keyboard = new Keyboard();
|
||||||
|
|
||||||
|
for(let i = 0;i<=9;i++){
|
||||||
|
let output = keyboard.utilities.getUpdatedInput(`{numpad${i}}`, "test");
|
||||||
|
expect(output).toBe(`test${i}`);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Keyboard {numpaddivide} button will work', () => {
|
||||||
|
testUtil.setDOM();
|
||||||
|
|
||||||
|
let keyboard = new Keyboard();
|
||||||
|
|
||||||
|
let output = keyboard.utilities.getUpdatedInput("{numpaddivide}", "test");
|
||||||
|
|
||||||
|
expect(output).toBe("test/");
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Keyboard {numpadmultiply} button will work', () => {
|
||||||
|
testUtil.setDOM();
|
||||||
|
|
||||||
|
let keyboard = new Keyboard();
|
||||||
|
|
||||||
|
let output = keyboard.utilities.getUpdatedInput("{numpadmultiply}", "test");
|
||||||
|
|
||||||
|
expect(output).toBe("test*");
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Keyboard {numpadsubtract} button will work', () => {
|
||||||
|
testUtil.setDOM();
|
||||||
|
|
||||||
|
let keyboard = new Keyboard();
|
||||||
|
|
||||||
|
let output = keyboard.utilities.getUpdatedInput("{numpadsubtract}", "test");
|
||||||
|
|
||||||
|
expect(output).toBe("test-");
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Keyboard {numpadadd} button will work', () => {
|
||||||
|
testUtil.setDOM();
|
||||||
|
|
||||||
|
let keyboard = new Keyboard();
|
||||||
|
|
||||||
|
let output = keyboard.utilities.getUpdatedInput("{numpadadd}", "test");
|
||||||
|
|
||||||
|
expect(output).toBe("test+");
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Keyboard {numpadadd} button will work', () => {
|
||||||
|
testUtil.setDOM();
|
||||||
|
|
||||||
|
let keyboard = new Keyboard();
|
||||||
|
|
||||||
|
let output = keyboard.utilities.getUpdatedInput("{numpadadd}", "test");
|
||||||
|
|
||||||
|
expect(output).toBe("test+");
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Keyboard {numpaddecimal} button will work', () => {
|
||||||
|
testUtil.setDOM();
|
||||||
|
|
||||||
|
let keyboard = new Keyboard();
|
||||||
|
|
||||||
|
let output = keyboard.utilities.getUpdatedInput("{numpaddecimal}", "test");
|
||||||
|
|
||||||
|
expect(output).toBe("test.");
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Keyboard custom function buttons will work', () => {
|
||||||
|
testUtil.setDOM();
|
||||||
|
|
||||||
|
let keyboard = new Keyboard({
|
||||||
|
layout: {
|
||||||
|
default: [
|
||||||
|
"{randombuttontest}"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
let output = keyboard.utilities.getUpdatedInput("{randombuttontest}", "test");
|
||||||
|
|
||||||
|
expect(output).toBe("test");
|
||||||
|
expect(keyboard.getButtonElement("{randombuttontest}").onclick).toBeTruthy();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Keyboard "{" button will work', () => {
|
||||||
|
testUtil.setDOM();
|
||||||
|
|
||||||
|
let keyboard = new Keyboard();
|
||||||
|
|
||||||
|
let output = keyboard.utilities.getUpdatedInput("{", "test");
|
||||||
|
|
||||||
|
expect(output).toBe("test{");
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Keyboard "}" button will work', () => {
|
||||||
|
testUtil.setDOM();
|
||||||
|
|
||||||
|
let keyboard = new Keyboard();
|
||||||
|
|
||||||
|
let output = keyboard.utilities.getUpdatedInput("}", "test");
|
||||||
|
|
||||||
|
expect(output).toBe("test}");
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Keyboard standard button will affect input', () => {
|
||||||
|
testUtil.setDOM();
|
||||||
|
|
||||||
|
let keyboard = new Keyboard();
|
||||||
|
|
||||||
|
for (let i = 65; i <= 90; i++) {
|
||||||
|
let char = String.fromCharCode(i);
|
||||||
|
let output = keyboard.utilities.getUpdatedInput(char, "test");
|
||||||
|
expect(output).toBe(`test${char}`);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Keyboard updateCaretPos will work with minus', () => {
|
||||||
|
testUtil.setDOM();
|
||||||
|
|
||||||
|
let keyboard = new Keyboard({
|
||||||
|
syncInstanceInputs: true
|
||||||
|
});
|
||||||
|
|
||||||
|
keyboard.caretPosition = 5;
|
||||||
|
keyboard.utilities.updateCaretPos(2, true);
|
||||||
|
|
||||||
|
expect(keyboard.caretPosition).toBe(3);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Keyboard updateCaretPos will work with minus', () => {
|
||||||
|
testUtil.setDOM();
|
||||||
|
|
||||||
|
let keyboard = new Keyboard();
|
||||||
|
|
||||||
|
keyboard.caretPosition = 5;
|
||||||
|
keyboard.utilities.updateCaretPos(2, true);
|
||||||
|
|
||||||
|
expect(keyboard.caretPosition).toBe(3);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Keyboard updateCaretPos will work with plus', () => {
|
||||||
|
testUtil.setDOM();
|
||||||
|
|
||||||
|
let keyboard = new Keyboard();
|
||||||
|
|
||||||
|
keyboard.caretPosition = 5;
|
||||||
|
keyboard.utilities.updateCaretPos(2);
|
||||||
|
|
||||||
|
expect(keyboard.caretPosition).toBe(7);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Keyboard addStringAt will work with debug', () => {
|
||||||
|
testUtil.setDOM();
|
||||||
|
|
||||||
|
let keyboard = new Keyboard({
|
||||||
|
debug: true
|
||||||
|
});
|
||||||
|
|
||||||
|
keyboard.getButtonElement("q").onclick();
|
||||||
|
|
||||||
|
expect(keyboard.getInput()).toBe("q");
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Keyboard addStringAt will work with position', () => {
|
||||||
|
testUtil.setDOM();
|
||||||
|
|
||||||
|
let keyboard = new Keyboard({
|
||||||
|
debug: true
|
||||||
|
});
|
||||||
|
|
||||||
|
keyboard.setInput("test");
|
||||||
|
keyboard.caretPosition = 4;
|
||||||
|
|
||||||
|
keyboard.getButtonElement("q").onclick();
|
||||||
|
|
||||||
|
expect(keyboard.getInput()).toBe("testq");
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Keyboard addStringAt will respect maxLength', () => {
|
||||||
|
testUtil.setDOM();
|
||||||
|
|
||||||
|
let keyboard = new Keyboard({
|
||||||
|
debug: true,
|
||||||
|
maxLength: 4
|
||||||
|
});
|
||||||
|
|
||||||
|
keyboard.setInput("test");
|
||||||
|
keyboard.caretPosition = 4;
|
||||||
|
|
||||||
|
keyboard.utilities.handleMaxLength(keyboard.input, "testq")
|
||||||
|
keyboard.utilities.addStringAt("test", "q", 4);
|
||||||
|
|
||||||
|
expect(keyboard.caretPosition).toBe(4);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Keyboard handleMaxLength will exit out on same updatedInput', () => {
|
||||||
|
testUtil.setDOM();
|
||||||
|
|
||||||
|
let keyboard = new Keyboard({
|
||||||
|
debug: true
|
||||||
|
});
|
||||||
|
|
||||||
|
keyboard.setInput("test");
|
||||||
|
|
||||||
|
let output = keyboard.utilities.handleMaxLength(keyboard.input, "test")
|
||||||
|
|
||||||
|
expect(output).toBeFalsy();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Keyboard handleMaxLength will work with object maxLength', () => {
|
||||||
|
testUtil.setDOM();
|
||||||
|
|
||||||
|
let keyboard = new Keyboard({
|
||||||
|
maxLength: {
|
||||||
|
default: 4
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
keyboard.setInput("test");
|
||||||
|
|
||||||
|
let output = keyboard.utilities.handleMaxLength(keyboard.input, "testq");
|
||||||
|
|
||||||
|
expect(output).toBeTruthy();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Keyboard handleMaxLength will work with object maxLength and debug', () => {
|
||||||
|
testUtil.setDOM();
|
||||||
|
|
||||||
|
let keyboard = new Keyboard({
|
||||||
|
maxLength: {
|
||||||
|
default: 4
|
||||||
|
},
|
||||||
|
debug: true
|
||||||
|
});
|
||||||
|
|
||||||
|
keyboard.setInput("test");
|
||||||
|
|
||||||
|
let output = keyboard.utilities.handleMaxLength(keyboard.input, "testq");
|
||||||
|
|
||||||
|
expect(output).toBeTruthy();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Keyboard handleMaxLength will return false if obj maxLength not reached', () => {
|
||||||
|
testUtil.setDOM();
|
||||||
|
|
||||||
|
let keyboard = new Keyboard({
|
||||||
|
maxLength: {
|
||||||
|
default: 7
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
keyboard.setInput("test");
|
||||||
|
|
||||||
|
let output = keyboard.utilities.handleMaxLength(keyboard.input, "testq");
|
||||||
|
|
||||||
|
expect(output).toBeFalsy();
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
it('Keyboard handleMaxLength will work without debug', () => {
|
||||||
|
testUtil.setDOM();
|
||||||
|
|
||||||
|
let keyboard = new Keyboard({
|
||||||
|
maxLength: 4
|
||||||
|
});
|
||||||
|
|
||||||
|
keyboard.setInput("test");
|
||||||
|
|
||||||
|
let output = keyboard.utilities.handleMaxLength(keyboard.input, "testq");
|
||||||
|
|
||||||
|
expect(output).toBeTruthy();
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
it('Keyboard handleMaxLength will work with numeric maxLength', () => {
|
||||||
|
testUtil.setDOM();
|
||||||
|
|
||||||
|
let keyboard = new Keyboard({
|
||||||
|
maxLength: 3
|
||||||
|
});
|
||||||
|
|
||||||
|
keyboard.setInput("test");
|
||||||
|
|
||||||
|
let output = keyboard.utilities.handleMaxLength(keyboard.input, "testq");
|
||||||
|
|
||||||
|
expect(output).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Keyboard handleMaxLength wont work with non numeric or object maxLength', () => {
|
||||||
|
testUtil.setDOM();
|
||||||
|
|
||||||
|
let keyboard = new Keyboard({
|
||||||
|
maxLength: "wrong"
|
||||||
|
});
|
||||||
|
|
||||||
|
keyboard.setInput("test");
|
||||||
|
|
||||||
|
let output = keyboard.utilities.handleMaxLength(keyboard.input, "testq");
|
||||||
|
|
||||||
|
expect(output).toBeFalsy();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Keyboard handleMaxLength wont work with non numeric or object maxLength (with debug)', () => {
|
||||||
|
testUtil.setDOM();
|
||||||
|
|
||||||
|
let keyboard = new Keyboard({
|
||||||
|
maxLength: "wrong",
|
||||||
|
debug: true
|
||||||
|
});
|
||||||
|
|
||||||
|
keyboard.setInput("test");
|
||||||
|
|
||||||
|
let output = keyboard.utilities.handleMaxLength(keyboard.input, "testq");
|
||||||
|
|
||||||
|
expect(output).toBeFalsy();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Keyboard isMaxLengthReached will work', () => {
|
||||||
|
testUtil.setDOM();
|
||||||
|
|
||||||
|
let keyboard = new Keyboard({
|
||||||
|
maxLength: 5
|
||||||
|
});
|
||||||
|
|
||||||
|
let output = keyboard.utilities.isMaxLengthReached();
|
||||||
|
|
||||||
|
expect(output).toBeFalsy();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Keyboard removeAt will exit out on caretPosition:0', () => {
|
||||||
|
testUtil.setDOM();
|
||||||
|
|
||||||
|
let keyboard = new Keyboard();
|
||||||
|
|
||||||
|
keyboard.setInput("test");
|
||||||
|
keyboard.caretPosition = 0;
|
||||||
|
keyboard.utilities.removeAt(keyboard.getInput(), 0);
|
||||||
|
expect(keyboard.getInput()).toBe("test");
|
||||||
|
|
||||||
|
keyboard.setInput("test");
|
||||||
|
keyboard.caretPosition = 5;
|
||||||
|
keyboard.utilities.removeAt(keyboard.getInput(), 0, true);
|
||||||
|
expect(keyboard.caretPosition).toBe(4);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Keyboard removeAt will remove multi-byte unicodes with caretPos>0', () => {
|
||||||
|
testUtil.setDOM();
|
||||||
|
|
||||||
|
let keyboard = new Keyboard();
|
||||||
|
|
||||||
|
keyboard.caretPosition = 6;
|
||||||
|
let output = keyboard.utilities.removeAt("test\uD83D\uDE00", 6);
|
||||||
|
expect(output).toBe("test");
|
||||||
|
|
||||||
|
keyboard.caretPosition = 6;
|
||||||
|
output = keyboard.utilities.removeAt("test\uD83D\uDE00", 6, true);
|
||||||
|
expect(keyboard.caretPosition).toBe(4);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Keyboard removeAt will not remove multi-byte unicodes with caretPos:0', () => {
|
||||||
|
testUtil.setDOM();
|
||||||
|
|
||||||
|
let keyboard = new Keyboard();
|
||||||
|
let output = keyboard.utilities.removeAt("\uD83D\uDE00");
|
||||||
|
expect(output).toBeFalsy();
|
||||||
|
|
||||||
|
output = keyboard.utilities.removeAt("\uD83D\uDE00", 0, true);
|
||||||
|
expect(output).toBeFalsy();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Keyboard removeAt will remove regular strings', () => {
|
||||||
|
testUtil.setDOM();
|
||||||
|
|
||||||
|
let keyboard = new Keyboard({
|
||||||
|
debug: true
|
||||||
|
});
|
||||||
|
|
||||||
|
keyboard.caretPosition = 6;
|
||||||
|
let output = keyboard.utilities.removeAt("testie", 6);
|
||||||
|
expect(output).toBe("testi");
|
||||||
|
|
||||||
|
keyboard.caretPosition = 6;
|
||||||
|
output = keyboard.utilities.removeAt("testie", 6, true);
|
||||||
|
expect(keyboard.caretPosition).toBe(5);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Keyboard will work with custom (and weird) class', () => {
|
||||||
|
testUtil.setDOM("my--weird--class");
|
||||||
|
let keyboard = new Keyboard(".my--weird--class");
|
||||||
|
expect(keyboard.keyboardDOMClass).toBe("my--weird--class");
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Keyboard camelCase will work with empty strings', () => {
|
||||||
|
testUtil.setDOM();
|
||||||
|
let keyboard = new Keyboard();
|
||||||
|
expect(keyboard.utilities.camelCase()).toBeFalsy();
|
||||||
|
});
|
||||||
@@ -0,0 +1,112 @@
|
|||||||
|
/**
|
||||||
|
* Test Utility Functions
|
||||||
|
*/
|
||||||
|
export default class TestUtility {
|
||||||
|
/**
|
||||||
|
* Set's a basic DOM structure to test in
|
||||||
|
*/
|
||||||
|
setDOM = (divClass) => {
|
||||||
|
this.clear();
|
||||||
|
const wrapperDOM = document.createElement('div');
|
||||||
|
wrapperDOM.setAttribute("id", "root");
|
||||||
|
|
||||||
|
const keyboardDOM = document.createElement('div');
|
||||||
|
keyboardDOM.className = divClass || "simple-keyboard";
|
||||||
|
|
||||||
|
wrapperDOM.appendChild(keyboardDOM);
|
||||||
|
document.body.appendChild(wrapperDOM);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clears DOM structure
|
||||||
|
*/
|
||||||
|
clear = () => {
|
||||||
|
document.body.innerHTML = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test if standard buttons respect maxLength and do input a value
|
||||||
|
*/
|
||||||
|
testLayoutStdButtons = (keyboard) => {
|
||||||
|
let stdBtnCount = 0;
|
||||||
|
let fullInput = '';
|
||||||
|
|
||||||
|
this.iterateButtons((button) => {
|
||||||
|
let label = button.getAttribute("data-skbtn");
|
||||||
|
|
||||||
|
if(label.includes("{"))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// Click all standard buttons, respects maxLength
|
||||||
|
button.onclick();
|
||||||
|
|
||||||
|
// Recording fullInput, bypasses maxLength
|
||||||
|
fullInput = keyboard.utilities.getUpdatedInput(label, fullInput, keyboard.options, null);
|
||||||
|
|
||||||
|
stdBtnCount += label.length;
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if maxLength is respected
|
||||||
|
*/
|
||||||
|
if(
|
||||||
|
(
|
||||||
|
typeof keyboard.options.maxLength === "object" &&
|
||||||
|
keyboard.getInput().length !== keyboard.options.maxLength[keyboard.options.layoutName]
|
||||||
|
) ||
|
||||||
|
(
|
||||||
|
typeof keyboard.options.maxLength !== "object" &&
|
||||||
|
keyboard.getInput().length !== keyboard.options.maxLength
|
||||||
|
)
|
||||||
|
)
|
||||||
|
throw new Error("MAX_LENGTH_ISSUE");
|
||||||
|
else
|
||||||
|
console.log("MAX_LENGTH PASSED:", keyboard.options.layoutName, keyboard.getInput().length, keyboard.options.maxLength);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if all standard buttons are inputting something
|
||||||
|
* (Regardless of maxLength)
|
||||||
|
*/
|
||||||
|
if(stdBtnCount !== fullInput.length)
|
||||||
|
throw new Error("STANDARD_BUTTONS_ISSUE");
|
||||||
|
else
|
||||||
|
console.log("STANDARD_BUTTONS PASSED:", keyboard.options.layoutName, stdBtnCount, fullInput.length);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test if function buttons are interactive (have an onclick)
|
||||||
|
*/
|
||||||
|
testLayoutFctButtons = (callback) => {
|
||||||
|
let fctBtnCount = 0;
|
||||||
|
let fctBtnHasOnclickCount = 0;
|
||||||
|
|
||||||
|
this.iterateButtons((button) => {
|
||||||
|
let label = button.getAttribute("data-skbtn");
|
||||||
|
|
||||||
|
if(!label.includes("{") && !label.includes("}"))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
fctBtnCount++;
|
||||||
|
|
||||||
|
if(button.onclick){
|
||||||
|
button.onclick();
|
||||||
|
fctBtnHasOnclickCount++;
|
||||||
|
}
|
||||||
|
|
||||||
|
callback(fctBtnCount, fctBtnHasOnclickCount);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Iterates on the keyboard buttons
|
||||||
|
*/
|
||||||
|
iterateButtons = (callback, selector) => {
|
||||||
|
let rows = document.body.querySelector(selector || '.simple-keyboard').children;
|
||||||
|
|
||||||
|
Array.from(rows).forEach(row => {
|
||||||
|
Array.from(row.children).forEach((button) => {
|
||||||
|
callback(button);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user