Skip to content

Commit 81c0e1b

Browse files
committed
initial commit
1 parent 6c20390 commit 81c0e1b

34 files changed

+11203
-2
lines changed

.dockerignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
node_modules
2+
build
3+
dist
4+
npm-debug.log

.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
node_modules/
3+
build/
4+
.tscache/
5+
npm-debug.log

.size-snapshot.json

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"ctrltab.js": {
3+
"bundled": 10345,
4+
"minified": 5491,
5+
"gzipped": 1671,
6+
"treeshaked": {
7+
"rollup": {
8+
"code": 27,
9+
"import_statements": 27
10+
},
11+
"webpack": {
12+
"code": 1011
13+
}
14+
}
15+
},
16+
"ctrltab.iife.js": {
17+
"bundled": 13125,
18+
"minified": 5413,
19+
"gzipped": 1776
20+
}
21+
}

CHANGELOG.md

+111
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
# 2.3.0 (January 16th 2021)
2+
3+
- Krait.js becomes CtrlTab.js
4+
- Project transfered from LCluber to DWTechs
5+
6+
## Version 2.2.0 (June 13th 2020)
7+
8+
- New preventDefault option so you can decide if an input should trigger its default behavior when hit or not.
9+
10+
# [2.1.0](https://github.com/LCluber/Krait.js/compare/v2.0.2...v2.1.0) (2020-01-14)
11+
12+
### Features
13+
14+
- **logs:** delete Mouette.js dependency ([e4765d0](https://github.com/LCluber/Krait.js/commit/e4765d0))
15+
16+
## [2.0.2](https://github.com/LCluber/Krait.js/compare/v2.0.1...v2.0.2) (2020-01-04)
17+
18+
### Bug Fixes
19+
20+
- **dependency:** delete Weejs dependency ([a78dceb](https://github.com/LCluber/Krait.js/commit/a78dceb))
21+
22+
## [2.0.1](https://github.com/LCluber/Krait.js/compare/v2.0.0...v2.0.1) (2019-08-16)
23+
24+
### Bug Fixes
25+
26+
- **dependencies:** updated dependencies ([198e01c](https://github.com/LCluber/Krait.js/commit/198e01c))
27+
28+
# [2.0.0](https://github.com/LCluber/Krait.js/compare/v1.0.0...v2.0.0) (2019-08-10)
29+
30+
### Features
31+
32+
- **command:** added getInputsAscii() method to command class ([c8afdd8](https://github.com/LCluber/Krait.js/commit/c8afdd8))
33+
- **command:** added setinputs() methods to command class ([a72794e](https://github.com/LCluber/Krait.js/commit/a72794e))
34+
- **groups:** commands can be grouped ([fc57b71](https://github.com/LCluber/Krait.js/commit/fc57b71))
35+
- **isascii:** extended parameter set to false by default ([34fc772](https://github.com/LCluber/Krait.js/commit/34fc772))
36+
- **keyboard:** added start() et stop() methods ([d82ddd7](https://github.com/LCluber/Krait.js/commit/d82ddd7))
37+
38+
### BREAKING CHANGES
39+
40+
- **groups:** have to give a group name when adding commands
41+
- **keyboard:** must call Keyboard.start() after Keyboard initilisation in order to start listening
42+
to key events
43+
44+
# [1.0.0](https://github.com/LCluber/Krait.js/compare/v0.3.0...v1.0.0) (2019-07-27)
45+
46+
### Bug Fixes
47+
48+
- **command:** better behavior of chained inputs ([93a772d](https://github.com/LCluber/Krait.js/commit/93a772d))
49+
50+
### Code Refactoring
51+
52+
- **addcommand:** control keys parameters now sent in an object ([dccbea9](https://github.com/LCluber/Krait.js/commit/dccbea9))
53+
54+
### Features
55+
56+
- **callback:** now returns false on key up ([ba5ac0d](https://github.com/LCluber/Krait.js/commit/ba5ac0d))
57+
- **keyboard:** added getcommandinputsascii method ([5bb6504](https://github.com/LCluber/Krait.js/commit/5bb6504))
58+
59+
### BREAKING CHANGES
60+
61+
- **addcommand:** control keys sent as object
62+
63+
## Version 0.3.0 (October 21th 2018)
64+
65+
- Multiple keystroke detection
66+
- Ctrl, Alt, Shift detection
67+
- addInput method now called addCommand and accept an array of keys.
68+
- Krait.js published on NPM at @lcluber/kraitjs.
69+
- Updated README.md with NPM installation procedure.
70+
71+
## Version 0.2.5 (July 27th 2018)
72+
73+
- deleted useless method in Input class
74+
75+
## Version 0.2.4 (July 23th 2018)
76+
77+
- Library exported as ES6 and IIFE modules instead of UMD.
78+
- KRAIT namespace becomes Krait
79+
80+
## Version 0.2.3 (July 4th 2018)
81+
82+
- Documentation automatically generated in /doc folder
83+
- Typedoc and grunt-typedoc added in devDependencies
84+
- New "typedoc" task in Gruntfile.js
85+
- Typescript upgraded to version 2.9.2
86+
- INSTALL.md becomes NOTICE.md and RELEASE_NOTES.md becomes CHANGELOG.md
87+
88+
## Version 0.2.2 (April 28th 2018)
89+
90+
- Added Wee.js utility library
91+
92+
## Version 0.2.1 (March 19th 2018)
93+
94+
- Added logs with Mouette.js
95+
- Added TypeScript Declaration File
96+
97+
## Version 0.2.0 (January 1st 2018)
98+
99+
- Added setInput() method to the Keyboard class.
100+
- Added getLastLog() method to the Keyboard class.
101+
- Logged all kind of errors that can occur during the addInput or setInput processes.
102+
- An input object does not have a name anymore.
103+
- Library is written in TypeScript
104+
105+
## Version 0.1.1 (October 28th 2017)
106+
107+
- The 'addInput()' method of the 'Keyboard' class can now receive an ASCII code or a string as parameter. The string will then be converted as a valid ASCII code.
108+
109+
## Version 0.1.0 (August 25th 2017)
110+
111+
- initial version

README.md

100644100755
+136-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,136 @@
1-
# CtrlTab.js
2-
Key binding library with multiple keystroke detection for adding shortcuts to your app
1+
## Synopsis
2+
3+
CtrlTab.js is a shortcut key bindings library with multiple keystroke detection.
4+
5+
## Motivation
6+
7+
The purpose of this library is to provide a simple and easy to use key binding declaration.
8+
9+
## Installation
10+
11+
### npm
12+
13+
```bash
14+
$ npm install @dwtechs/ctrltab
15+
```
16+
17+
### Yarn
18+
19+
```bash
20+
$ yarn add @dwtechs/ctrltab
21+
```
22+
23+
## Usage
24+
25+
### ES6
26+
27+
```javascript
28+
import { Keyboard } from "@dwtechs/ctrltab";
29+
30+
let keyboard = new Keyboard();
31+
32+
keyboard.addCommand("group1", "action0", null, [32], action0, {
33+
preventDefault: true
34+
});
35+
keyboard.addCommand("group1", "action1", { ctrl: true }, ["G"], action1, null);
36+
// set another key for action1
37+
keyboard.setInputs(
38+
"group1",
39+
"action1",
40+
{ ctrl: false, alt: false, shift: false },
41+
["Z", "T"]
42+
);
43+
// Enable group1 commands
44+
keyboard.watch("group1");
45+
46+
function action0(isKeyDown) {
47+
if (isKeyDown) {
48+
// do something;
49+
}
50+
}
51+
52+
function action1(isKeyDown) {
53+
if (isKeyDown) {
54+
// do something;
55+
}
56+
}
57+
```
58+
59+
### IIFE
60+
61+
```javascript
62+
var keyboard = new Krait.Keyboard();
63+
64+
keyboard.addCommand("group1", "action0", null, [32], action0, {
65+
preventDefault: true
66+
});
67+
keyboard.addCommand("group1", "action1", { ctrl: true }, ["G"], action1, null);
68+
// set another key for action1
69+
keyboard.setInputs(
70+
"group1",
71+
"action1",
72+
{ ctrl: false, alt: false, shift: false },
73+
["Z", "T"]
74+
);
75+
// Enable group1 commands
76+
keyboard.watch("group1");
77+
78+
function action0(isKeyDown) {
79+
if (isKeyDown) {
80+
// do something;
81+
}
82+
}
83+
84+
function action1(isKeyDown) {
85+
if (isKeyDown) {
86+
// do something;
87+
}
88+
}
89+
```
90+
91+
## API Reference
92+
93+
```javascript
94+
interface CtrlKeys {
95+
ctrl?: boolean;
96+
alt?: boolean;
97+
shift?: boolean;
98+
}
99+
100+
interface Options {
101+
preventDefault?: boolean;
102+
scope?: this;
103+
}
104+
105+
addCommand(
106+
name: string,
107+
ctrlKeys: CtrlKeys | null,
108+
keys: Array<string | number>,
109+
callback: Function,
110+
options: Options | null
111+
): Command {}
112+
113+
setInputs(
114+
ctrlKeys: CtrlKeys,
115+
keys: Array<string | number>
116+
): boolean {}
117+
118+
watch(groupName: string): boolean {} //start watching a group of commands
119+
120+
ignore(groupName: string): boolean {} //stop watching a group of commands
121+
122+
default(groupName: string, commandName: string): boolean {} //set command to default settings
123+
124+
getCommand(groupName: string, commandName: string): Command | null {}
125+
126+
```
127+
128+
## Stack
129+
130+
| Purpose | Choice | Motivation |
131+
| :-------------- | :------------------------------------------: | -------------------------------------------------------------: |
132+
| repository | [Github](https://github.com/) | hosting for software development version control using Git |
133+
| package manager | [npm](https://www.npmjs.com/get-npm) | default node.js package manager |
134+
| language | [TypeScript](https://www.typescriptlang.org) | static type checking along with the latest ECMAScript features |
135+
| module bundler | [Rollup.js](https://rollupjs.org) | advanced module bundler for ES6 modules |
136+
| unit testing | [Jest](https://jestjs.io/) | delightful testing with a focus on simplicity |

babel.config.js

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
module.exports = api => {
2+
const isTest = api.env("test");
3+
if (isTest) {
4+
return {
5+
presets: [
6+
[
7+
"@babel/env",
8+
{
9+
targets: {
10+
node: "current"
11+
}
12+
}
13+
]
14+
]
15+
};
16+
} else {
17+
return {
18+
presets: [
19+
[
20+
"@babel/env",
21+
{
22+
debug: true,
23+
targets: {
24+
ie: 9,
25+
browsers: "cover 99.5%",
26+
esmodules: false
27+
},
28+
loose: true
29+
}
30+
]
31+
],
32+
plugins: [
33+
// "@babel/plugin-external-helpers"
34+
]
35+
};
36+
}
37+
};

contributor.md

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# Installation guide
2+
3+
## Clone the project :
4+
5+
```bash
6+
$ git clone https://github.com/DWTechs/CtrlTab.js.git
7+
```
8+
9+
## Launch with docker
10+
11+
### build image :
12+
```bash
13+
$ cd CtrlTab/
14+
$ docker-compose up -d
15+
```
16+
17+
### build lib :
18+
```bash
19+
$ cd CtrlTab/
20+
$ docker-compose run ctrltab
21+
```
22+
23+
OR
24+
25+
## Install project dependencies :
26+
27+
```bash
28+
$ cd CtrlTab/
29+
$ npm i
30+
```
31+
32+
# Workflow
33+
34+
- create a branch following [these instructions](https://lcluber.github.io/LeadDevToolkit/docs/git/branch.html)
35+
36+
- build the library :
37+
38+
```bash
39+
$ npm run build
40+
```
41+
42+
- test the library :
43+
44+
```bash
45+
$ npm run test
46+
```
47+
48+
- commit your work following [conventional commits rules](https://lcluber.github.io/LeadDevToolkit/docs/git/commit.html) :
49+
50+
51+
## Folders
52+
53+
- scripts/
54+
- dist/
55+
- src/
56+
- web/
57+

0 commit comments

Comments
 (0)