Skip to content

Commit 5aee552

Browse files
committed
prevent default option
1 parent 7047626 commit 5aee552

37 files changed

+1833
-2876
lines changed

CHANGELOG.md

Lines changed: 70 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,111 +1,106 @@
1-
# [2.1.0](https://github.com/LCluber/Krait.js/compare/v2.0.2...v2.1.0) (2020-01-14)
1+
## Version 2.2.0 (June 13th 2020)
2+
3+
- New preventDefault option so you can decide if an input should trigger its default behavior when hit or not.
24

5+
# [2.1.0](https://github.com/LCluber/Krait.js/compare/v2.0.2...v2.1.0) (2020-01-14)
36

47
### Features
58

6-
* **logs:** delete Mouette.js dependency ([e4765d0](https://github.com/LCluber/Krait.js/commit/e4765d0))
9+
- **logs:** delete Mouette.js dependency ([e4765d0](https://github.com/LCluber/Krait.js/commit/e4765d0))
710

811
## [2.0.2](https://github.com/LCluber/Krait.js/compare/v2.0.1...v2.0.2) (2020-01-04)
912

10-
1113
### Bug Fixes
1214

13-
* **dependency:** delete Weejs dependency ([a78dceb](https://github.com/LCluber/Krait.js/commit/a78dceb))
15+
- **dependency:** delete Weejs dependency ([a78dceb](https://github.com/LCluber/Krait.js/commit/a78dceb))
1416

1517
## [2.0.1](https://github.com/LCluber/Krait.js/compare/v2.0.0...v2.0.1) (2019-08-16)
1618

17-
1819
### Bug Fixes
1920

20-
* **dependencies:** updated dependencies ([198e01c](https://github.com/LCluber/Krait.js/commit/198e01c))
21+
- **dependencies:** updated dependencies ([198e01c](https://github.com/LCluber/Krait.js/commit/198e01c))
2122

2223
# [2.0.0](https://github.com/LCluber/Krait.js/compare/v1.0.0...v2.0.0) (2019-08-10)
2324

24-
2525
### Features
2626

27-
* **command:** added getInputsAscii() method to command class ([c8afdd8](https://github.com/LCluber/Krait.js/commit/c8afdd8))
28-
* **command:** added setinputs() methods to command class ([a72794e](https://github.com/LCluber/Krait.js/commit/a72794e))
29-
* **groups:** commands can be grouped ([fc57b71](https://github.com/LCluber/Krait.js/commit/fc57b71))
30-
* **isascii:** extended parameter set to false by default ([34fc772](https://github.com/LCluber/Krait.js/commit/34fc772))
31-
* **keyboard:** added start() et stop() methods ([d82ddd7](https://github.com/LCluber/Krait.js/commit/d82ddd7))
32-
27+
- **command:** added getInputsAscii() method to command class ([c8afdd8](https://github.com/LCluber/Krait.js/commit/c8afdd8))
28+
- **command:** added setinputs() methods to command class ([a72794e](https://github.com/LCluber/Krait.js/commit/a72794e))
29+
- **groups:** commands can be grouped ([fc57b71](https://github.com/LCluber/Krait.js/commit/fc57b71))
30+
- **isascii:** extended parameter set to false by default ([34fc772](https://github.com/LCluber/Krait.js/commit/34fc772))
31+
- **keyboard:** added start() et stop() methods ([d82ddd7](https://github.com/LCluber/Krait.js/commit/d82ddd7))
3332

3433
### BREAKING CHANGES
3534

36-
* **groups:** have to give a group name when adding commands
37-
* **keyboard:** must call Keyboard.start() after Keyboard initilisation in order to start listening
38-
to key events
35+
- **groups:** have to give a group name when adding commands
36+
- **keyboard:** must call Keyboard.start() after Keyboard initilisation in order to start listening
37+
to key events
3938

4039
# [1.0.0](https://github.com/LCluber/Krait.js/compare/v0.3.0...v1.0.0) (2019-07-27)
4140

42-
4341
### Bug Fixes
4442

45-
* **command:** better behavior of chained inputs ([93a772d](https://github.com/LCluber/Krait.js/commit/93a772d))
46-
43+
- **command:** better behavior of chained inputs ([93a772d](https://github.com/LCluber/Krait.js/commit/93a772d))
4744

4845
### Code Refactoring
4946

50-
* **addcommand:** control keys parameters now sent in an object ([dccbea9](https://github.com/LCluber/Krait.js/commit/dccbea9))
51-
47+
- **addcommand:** control keys parameters now sent in an object ([dccbea9](https://github.com/LCluber/Krait.js/commit/dccbea9))
5248

5349
### Features
5450

55-
* **callback:** now returns false on key up ([ba5ac0d](https://github.com/LCluber/Krait.js/commit/ba5ac0d))
56-
* **keyboard:** added getcommandinputsascii method ([5bb6504](https://github.com/LCluber/Krait.js/commit/5bb6504))
57-
51+
- **callback:** now returns false on key up ([ba5ac0d](https://github.com/LCluber/Krait.js/commit/ba5ac0d))
52+
- **keyboard:** added getcommandinputsascii method ([5bb6504](https://github.com/LCluber/Krait.js/commit/5bb6504))
5853

5954
### BREAKING CHANGES
6055

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
56+
- **addcommand:** control keys sent as object
57+
58+
## Version 0.3.0 (October 21th 2018)
59+
60+
- Multiple keystroke detection
61+
- Ctrl, Alt, Shift detection
62+
- addInput method now called addCommand and accept an array of keys.
63+
- Krait.js published on NPM at @lcluber/kraitjs.
64+
- Updated README.md with NPM installation procedure.
65+
66+
## Version 0.2.5 (July 27th 2018)
67+
68+
- deleted useless method in Input class
69+
70+
## Version 0.2.4 (July 23th 2018)
71+
72+
- Library exported as ES6 and IIFE modules instead of UMD.
73+
- KRAIT namespace becomes Krait
74+
75+
## Version 0.2.3 (July 4th 2018)
76+
77+
- Documentation automatically generated in /doc folder
78+
- Typedoc and grunt-typedoc added in devDependencies
79+
- New "typedoc" task in Gruntfile.js
80+
- Typescript upgraded to version 2.9.2
81+
- INSTALL.md becomes NOTICE.md and RELEASE_NOTES.md becomes CHANGELOG.md
82+
83+
## Version 0.2.2 (April 28th 2018)
84+
85+
- Added Wee.js utility library
86+
87+
## Version 0.2.1 (March 19th 2018)
88+
89+
- Added logs with Mouette.js
90+
- Added TypeScript Declaration File
91+
92+
## Version 0.2.0 (January 1st 2018)
93+
94+
- Added setInput() method to the Keyboard class.
95+
- Added getLastLog() method to the Keyboard class.
96+
- Logged all kind of errors that can occur during the addInput or setInput processes.
97+
- An input object does not have a name anymore.
98+
- Library is written in TypeScript
99+
100+
## Version 0.1.1 (October 28th 2017)
101+
102+
- 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.
103+
104+
## Version 0.1.0 (August 25th 2017)
105+
106+
- initial version

Gruntfile.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -439,11 +439,6 @@ module.exports = function(grunt) {
439439
//'replace:declaration'
440440
]);
441441

442-
grunt.registerTask("doc", "Compile lib documentation", [
443-
"clean:doc",
444-
"typedoc"
445-
]);
446-
447442
grunt.registerTask(
448443
"serve",
449444
"launch server, open website and watch for changes",
@@ -484,8 +479,6 @@ module.exports = function(grunt) {
484479
grunt.task.run("lib");
485480
//build site
486481
grunt.task.run("website");
487-
//build documentation
488-
grunt.task.run("doc");
489482
// launch server and watch for changes
490483
grunt.task.run("serve");
491484
});

README.md

Lines changed: 22 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
## Synopsis
22

3-
[Krait.js](http://kraitjs.lcluber.com) is a key bindings library written in TypeScript with multiple keystroke detection.
3+
Krait.js is a key bindings library written in TypeScript with multiple keystroke detection.
44

55
## Motivation
66

@@ -20,10 +20,6 @@ $ npm install @lcluber/kraitjs
2020
$ yarn add @lcluber/kraitjs
2121
```
2222

23-
## Demo
24-
25-
See a basic example **[here](http://kraitjs.lcluber.com/#example)**.
26-
2723
## Usage
2824

2925
### ES6
@@ -33,22 +29,10 @@ import { Keyboard } from "@lcluber/kraitjs";
3329

3430
let keyboard = new Keyboard();
3531

36-
keyboard.addCommand(
37-
"group1",
38-
"action0",
39-
{ ctrl: true, alt: false, shift: false },
40-
[65],
41-
action0,
42-
null
43-
);
44-
keyboard.addCommand(
45-
"group1",
46-
"action1",
47-
{ ctrl: false, alt: false, shift: false },
48-
["G"],
49-
action1,
50-
null
51-
);
32+
keyboard.addCommand("group1", "action0", null, [32], action0, {
33+
preventDefault: true
34+
});
35+
keyboard.addCommand("group1", "action1", { ctrl: true }, ["G"], action1, null);
5236
// set another key for action1
5337
keyboard.setInputs(
5438
"group1",
@@ -58,7 +42,7 @@ keyboard.setInputs(
5842
);
5943

6044
// Enable group1 commands
61-
keyboard.start("group1");
45+
keyboard.startListening("group1");
6246

6347
function action0(isKeyDown) {
6448
if (isKeyDown) {
@@ -78,22 +62,10 @@ function action1(isKeyDown) {
7862
```javascript
7963
var keyboard = new Krait.Keyboard();
8064

81-
keyboard.addCommand(
82-
"group1",
83-
"action0",
84-
{ ctrl: true, alt: false, shift: false },
85-
[65],
86-
action0,
87-
null
88-
);
89-
keyboard.addCommand(
90-
"group1",
91-
"action1",
92-
{ ctrl: false, alt: false, shift: false },
93-
["G"],
94-
action1,
95-
null
96-
);
65+
keyboard.addCommand("group1", "action0", null, [32], action0, {
66+
preventDefault: true
67+
});
68+
keyboard.addCommand("group1", "action1", { ctrl: true }, ["G"], action1, null);
9769
// set another key for action1
9870
keyboard.setInputs(
9971
"group1",
@@ -127,32 +99,33 @@ interface CtrlKeys {
12799
shift?: boolean;
128100
}
129101

102+
export interface Options {
103+
preventDefault?: boolean;
104+
scope?: this;
105+
}
106+
130107
addCommand(
131108
name: string,
132-
controls: CtrlKeys,
109+
ctrlKeys: CtrlKeys | null,
133110
keys: Array<string | number>,
134111
callback: Function,
135-
scope: any
112+
options: Options | null
136113
): Command {}
137114

138115
setInputs(
139116
ctrlKeys: CtrlKeys,
140-
newKeys: Array<string | number>
117+
keys: Array<string | number>
141118
): boolean {}
142119

143-
start(a: KeyboardEvent): boolean {}
144-
145-
stop(key: number): boolean {}
146-
147-
default(): void {}
120+
watch(groupName: string): boolean {}
148121

149-
down(a: KeyboardEvent): void {}
122+
ignore(groupName: string): boolean {}
150123

151-
up(key: number): void {}
124+
default(groupName: string, commandName: string): boolean {}
152125

153126
getCommand(name: string): Command | null {}
154127

155-
getCommandInputsAscii(name: string): Array<string> | false {}
128+
getCommandInputs(name: string): string[] | false {}
156129

157130
```
158131

0 commit comments

Comments
 (0)