-
-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
216 additions
and
13 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/// <reference types="react" /> | ||
import "simple-keyboard/build/css/index.css"; | ||
import { KeyboardReactInterface } from "../interfaces"; | ||
declare const KeyboardReact: (props: KeyboardReactInterface["options"]) => JSX.Element; | ||
export default KeyboardReact; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import KeyboardReact from "./components/KeyboardModern"; | ||
export * from "./interfaces"; | ||
export default KeyboardReact; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = () => ""; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* eslint-disable no-unused-vars */ | ||
import * as React from "react"; | ||
import { parseProps, changedProps } from "../services/Utilities"; | ||
import "simple-keyboard/build/css/index.css"; | ||
import { KeyboardReactInterface } from "../interfaces"; | ||
|
||
const Keyboard = require("simple-keyboard/build/index.modern").default as { | ||
new ( | ||
selector: string, | ||
options: KeyboardReactInterface["options"] | ||
): KeyboardReactInterface["options"]; | ||
}; | ||
|
||
const KeyboardReact = (props: KeyboardReactInterface["options"]) => { | ||
const cssClass = props.baseClass || "react-simple-keyboard"; | ||
const initRef = React.useRef(null) as React.MutableRefObject<null | boolean>; | ||
const keyboardRef = React.useRef(null) as React.MutableRefObject< | ||
null | KeyboardReactInterface["options"] | ||
>; | ||
const previousProps = React.useRef(props); | ||
|
||
React.useEffect(() => { | ||
const parsedProps = parseProps(props); | ||
|
||
/** | ||
* Initialize simple-keyboard | ||
*/ | ||
if (!initRef.current) { | ||
initRef.current = true; | ||
parsedProps.debug && console.log("ReactSimpleKeyboard: Init"); | ||
keyboardRef.current = new Keyboard( | ||
`.${cssClass}`, | ||
parsedProps | ||
) as KeyboardReactInterface["options"]; | ||
parsedProps.keyboardRef && parsedProps.keyboardRef(keyboardRef.current); | ||
} | ||
|
||
const updatedProps = changedProps(previousProps.current, parsedProps); | ||
|
||
/** | ||
* Only trigger render if props changed | ||
*/ | ||
if (updatedProps.length) { | ||
const keyboard = keyboardRef.current; | ||
previousProps.current = parsedProps; | ||
keyboard?.setOptions(parsedProps); | ||
parsedProps.debug && | ||
console.log( | ||
"ReactSimpleKeyboard - setOptions called due to updated props:", | ||
updatedProps | ||
); | ||
} | ||
}, [initRef, cssClass, previousProps, props]); | ||
|
||
return <div className={cssClass} />; | ||
}; | ||
|
||
export default KeyboardReact; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import KeyboardReact from "./components/KeyboardModern"; | ||
export * from "./interfaces"; | ||
export default KeyboardReact; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
/** | ||
* Config to support modern browsers only (build/index.modern.js) | ||
*/ | ||
const path = require('path'); | ||
const webpack = require('webpack'); | ||
const TerserPlugin = require('terser-webpack-plugin'); | ||
const getPackageJson = require('./scripts/getPackageJson'); | ||
|
||
const { | ||
version, | ||
name, | ||
license, | ||
repository, | ||
author, | ||
} = getPackageJson('version', 'name', 'license', 'repository', 'author'); | ||
|
||
const banner = ` | ||
${name} v${version} (index.modern.js - Modern Browsers bundle) | ||
${repository.url} | ||
NOTE: This modern browsers bundle (index.modern.js) removes all polyfills | ||
included in the standard version. Use this if you are supporting | ||
modern browsers only. Otherwise, use the standard version (index.js). | ||
Copyright (c) ${author.replace(/ *<[^)]*> */g, " ")} and project contributors. | ||
This source code is licensed under the ${license} license found in the | ||
LICENSE file in the root directory of this source tree. | ||
`; | ||
|
||
module.exports = { | ||
mode: "production", | ||
entry: './src/lib/index.modern.ts', | ||
target: 'es5', | ||
output: { | ||
filename: 'index.modern.js', | ||
path: path.resolve(__dirname, 'build'), | ||
library: "ReactSimpleKeyboard", | ||
libraryTarget: 'umd', | ||
globalObject: 'this' | ||
}, | ||
optimization: { | ||
minimize: true, | ||
minimizer: [ | ||
new TerserPlugin({ extractComments: false }), | ||
], | ||
}, | ||
externals: { | ||
react: { | ||
root: 'React', | ||
commonjs2: 'react', | ||
commonjs: 'react', | ||
amd: 'react' | ||
}, | ||
'react-dom': { | ||
root: 'ReactDOM', | ||
commonjs2: 'react-dom', | ||
commonjs: 'react-dom', | ||
amd: 'react-dom' | ||
} | ||
}, | ||
module: { | ||
rules: [ | ||
{ | ||
test: /\.(js|json|ts|tsx)$/, | ||
exclude: /(node_modules|bower_components)/, | ||
use: { | ||
loader: 'babel-loader', | ||
options: { | ||
presets: [ | ||
"@babel/preset-react", | ||
"@babel/env", | ||
"@babel/preset-typescript" | ||
], | ||
plugins: [ | ||
["@babel/plugin-proposal-class-properties"], | ||
["@babel/plugin-transform-typescript"] | ||
] | ||
} | ||
} | ||
}, | ||
{ | ||
test: /\.(sa|sc|c)ss$/, | ||
use: path.resolve('scripts/loaderMock.js') | ||
} | ||
] | ||
}, | ||
plugins: [ | ||
new webpack.BannerPlugin(banner) | ||
], | ||
resolve: { | ||
extensions: ['.ts', '.tsx', '.js', '.json'] | ||
} | ||
}; |