|
|
@@ -1,4 +1,5 @@
|
|
1
|
1
|
import { batch } from 'react-redux';
|
|
|
2
|
+import { AnyAction } from 'redux';
|
|
2
|
3
|
|
|
3
|
4
|
import { ACTION_SHORTCUT_PRESSED, ACTION_SHORTCUT_RELEASED, createShortcutEvent } from '../analytics/AnalyticsEvents';
|
|
4
|
5
|
import { sendAnalytics } from '../analytics/functions';
|
|
|
@@ -8,13 +9,67 @@ import { openSettingsDialog } from '../settings/actions.web';
|
|
8
|
9
|
import { SETTINGS_TABS } from '../settings/constants';
|
|
9
|
10
|
import { iAmVisitor } from '../visitors/functions';
|
|
10
|
11
|
|
|
11
|
|
-import { registerShortcut, unregisterShortcut } from './actions.any';
|
|
|
12
|
+import {
|
|
|
13
|
+ DISABLE_KEYBOARD_SHORTCUTS,
|
|
|
14
|
+ ENABLE_KEYBOARD_SHORTCUTS,
|
|
|
15
|
+ REGISTER_KEYBOARD_SHORTCUT,
|
|
|
16
|
+ UNREGISTER_KEYBOARD_SHORTCUT
|
|
|
17
|
+} from './actionTypes';
|
|
12
|
18
|
import { areKeyboardShortcutsEnabled, getKeyboardShortcuts } from './functions';
|
|
13
|
19
|
import logger from './logger';
|
|
|
20
|
+import { IKeyboardShortcut } from './types';
|
|
14
|
21
|
import { getKeyboardKey, getPriorityFocusedElement } from './utils';
|
|
15
|
22
|
|
|
16
|
|
-export * from './actions.any';
|
|
|
23
|
+/**
|
|
|
24
|
+ * Action to register a new shortcut.
|
|
|
25
|
+ *
|
|
|
26
|
+ * @param {IKeyboardShortcut} shortcut - The shortcut to register.
|
|
|
27
|
+ * @returns {AnyAction}
|
|
|
28
|
+*/
|
|
|
29
|
+export const registerShortcut = (shortcut: IKeyboardShortcut): AnyAction => {
|
|
|
30
|
+ return {
|
|
|
31
|
+ type: REGISTER_KEYBOARD_SHORTCUT,
|
|
|
32
|
+ shortcut
|
|
|
33
|
+ };
|
|
|
34
|
+};
|
|
|
35
|
+
|
|
|
36
|
+/**
|
|
|
37
|
+* Action to unregister a shortcut.
|
|
|
38
|
+*
|
|
|
39
|
+* @param {string} character - The character of the shortcut to unregister.
|
|
|
40
|
+* @param {boolean} altKey - Whether the shortcut used altKey.
|
|
|
41
|
+* @returns {AnyAction}
|
|
|
42
|
+*/
|
|
|
43
|
+export const unregisterShortcut = (character: string, altKey = false): AnyAction => {
|
|
|
44
|
+ return {
|
|
|
45
|
+ alt: altKey,
|
|
|
46
|
+ type: UNREGISTER_KEYBOARD_SHORTCUT,
|
|
|
47
|
+ character
|
|
|
48
|
+ };
|
|
|
49
|
+};
|
|
|
50
|
+
|
|
|
51
|
+/**
|
|
|
52
|
+ * Action to enable keyboard shortcuts.
|
|
|
53
|
+ *
|
|
|
54
|
+ * @returns {AnyAction}
|
|
|
55
|
+ */
|
|
|
56
|
+export const enableKeyboardShortcuts = (): AnyAction => {
|
|
|
57
|
+ return {
|
|
|
58
|
+ type: ENABLE_KEYBOARD_SHORTCUTS
|
|
|
59
|
+ };
|
|
|
60
|
+};
|
|
|
61
|
+
|
|
17
|
62
|
|
|
|
63
|
+/**
|
|
|
64
|
+ * Action to enable keyboard shortcuts.
|
|
|
65
|
+ *
|
|
|
66
|
+ * @returns {AnyAction}
|
|
|
67
|
+ */
|
|
|
68
|
+export const disableKeyboardShortcuts = (): AnyAction => {
|
|
|
69
|
+ return {
|
|
|
70
|
+ type: DISABLE_KEYBOARD_SHORTCUTS
|
|
|
71
|
+ };
|
|
|
72
|
+};
|
|
18
|
73
|
|
|
19
|
74
|
type KeyHandler = ((e: KeyboardEvent) => void) | undefined;
|
|
20
|
75
|
|