-
-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathkeyboard-event.js
108 lines (103 loc) · 3.13 KB
/
keyboard-event.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import BaseEvent from "@pencil.js/base-event";
/**
* @module KeyboardEvent
*/
/**
* Keyboard event class
* @class
* @extends {module:BaseEvent}
*/
export default class KeyboardEvent extends BaseEvent {
/**
* MouseEvent constructor
* @param {String} name - Name of the event
* @param {EventEmitter} target - Component concerned by the event
* @param {UIEvent} [event] - Original HTML event
* For the complete list of key values:
* https://developer.mozilla.org/en/docs/Web/API/KeyboardEvent/key/Key_Values
*/
constructor (name, target, event) {
super(name, target, event);
this.key = event.key;
}
/**
* @inheritDoc
*/
getModifier () {
return this.key;
}
/**
* @typedef {Object} KeyboardEvents
* @prop {String} down - Keyboard key pressed
* @prop {String} up - Keyboard key released
*/
/**
* Set of supported event name for easy access
* @example component.on(KeyboardEvent.events.up, () => console.log("User release a key"));
* @type {KeyboardEvents}
*/
static get events () {
return {
down: "keydown",
up: "keyup",
};
}
/**
* @typedef {Object} ArrowKeys
* @prop {String} up - Up arrow
* @prop {String} right - Right arrow
* @prop {String} down - Down arrow
* @prop {String} left - Left arrow
*/
/**
* @typedef {Object} KeyboardKeys
* @prop {String} backspace - Remove last character or return previous screen
* @prop {String} enter - Add line-break or validate entry
* @prop {String} delete - Remove character in front
* @prop {String} escape - Cancel or leave screen
* @prop {String} control - Modifying key (control)
* @prop {String} shift - Modifying key (uppercase)
* @prop {String} fn - Modifying key (function)
* @prop {ArrowKeys}
* @prop {String} tab - Next input or toggle focus
* @prop {String} alt - Modifying key (alternative)
* @prop {String} altGr - Modifying key (alternative grapheme)
* @prop {String} pageUp - Move up one page
* @prop {String} pageDown - Move down one page
* @prop {String} start - Go to start
* @prop {String} end - Go to end
* @prop {String} insert - Insert here or toggle insert mode
*/
/**
* Set of keys for easy access
* @example if (key === KeyboardEvent.keys.enter) {
* console.log("This is the enter key");
* }
* @type {KeyboardKeys}
*/
static get keys () {
return {
backspace: "Backspace",
enter: "Enter",
delete: "Delete",
escape: "Escape",
control: "Control",
shift: "Shift",
fn: "Fn",
arrows: {
up: "ArrowUp",
right: "ArrowRight",
down: "ArrowDown",
left: "ArrowLeft",
},
tab: "Tab",
alt: "Alt",
altGr: "AltGraph",
pageUp: "PageUp",
pageDown: "PageDown",
start: "Home",
end: "End",
insert: "Insert",
};
}
}