@peter.naydenov/shortcuts 3.5.2 → 4.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/API.md +939 -0
- package/CODE_OF_CONDUCT.md +84 -0
- package/CONTRIBUTING.md +476 -0
- package/Changelog.md +32 -2
- package/How.to.create.plugins.md +929 -0
- package/Migration.guide.md +48 -0
- package/README.md +396 -24
- package/dist/main.d.ts +54 -2
- package/dist/methods/_normalizeWithPlugins.d.ts +63 -1
- package/dist/methods/_readShortcutWithPlugins.d.ts +8 -1
- package/dist/methods/_setupPlugin.d.ts +9 -0
- package/dist/methods/_systemAction.d.ts +8 -1
- package/dist/methods/changeContext.d.ts +8 -1
- package/dist/methods/index.d.ts +2 -0
- package/dist/methods/listShortcuts.d.ts +1 -16
- package/dist/methods/load.d.ts +8 -1
- package/dist/methods/unload.d.ts +8 -1
- package/dist/plugins/click/_findTarget.d.ts +9 -1
- package/dist/plugins/click/_listenDOM.d.ts +76 -3
- package/dist/plugins/click/_normalizeShortcutName.d.ts +7 -1
- package/dist/plugins/click/_registerShortcutEvents.d.ts +26 -0
- package/dist/plugins/click/index.d.ts +6 -31
- package/dist/plugins/form/_defaults.d.ts +13 -1
- package/dist/plugins/form/_listenDOM.d.ts +66 -3
- package/dist/plugins/form/_registerShortcutEvents.d.ts +95 -1
- package/dist/plugins/form/index.d.ts +2 -29
- package/dist/plugins/hover/_findTarget.d.ts +10 -0
- package/dist/plugins/hover/_listenDOM.d.ts +68 -0
- package/dist/plugins/hover/_normalizeShortcutName.d.ts +2 -0
- package/dist/plugins/hover/_registerShortcutEvents.d.ts +28 -0
- package/dist/plugins/hover/index.d.ts +14 -0
- package/dist/plugins/key/_listenDOM.d.ts +61 -3
- package/dist/plugins/key/_registerShortcutEvents.d.ts +26 -0
- package/dist/plugins/key/_specialChars.d.ts +6 -31
- package/dist/plugins/key/index.d.ts +2 -29
- package/dist/plugins/scroll/_listenDOM.d.ts +58 -0
- package/dist/plugins/scroll/_normalizeShortcutName.d.ts +2 -0
- package/dist/plugins/scroll/_registerShortcutEvents.d.ts +28 -0
- package/dist/plugins/scroll/index.d.ts +16 -0
- package/dist/shortcuts.cjs +1 -1
- package/dist/shortcuts.esm.mjs +1 -1
- package/dist/shortcuts.umd.js +1 -1
- package/dist/src/main.d.ts +172 -0
- package/dist/src/methods/_normalizeWithPlugins.d.ts +64 -0
- package/dist/src/methods/_readShortcutWithPlugins.d.ts +9 -0
- package/dist/src/methods/_setupPlugin.d.ts +9 -0
- package/dist/src/methods/_systemAction.d.ts +9 -0
- package/dist/src/methods/changeContext.d.ts +9 -0
- package/dist/src/methods/index.d.ts +19 -0
- package/dist/src/methods/listShortcuts.d.ts +2 -0
- package/dist/src/methods/load.d.ts +9 -0
- package/dist/src/methods/unload.d.ts +9 -0
- package/dist/src/plugins/click/_findTarget.d.ts +10 -0
- package/dist/src/plugins/click/_listenDOM.d.ts +78 -0
- package/dist/src/plugins/click/_normalizeShortcutName.d.ts +8 -0
- package/dist/src/plugins/click/_readClickEvent.d.ts +2 -0
- package/dist/src/plugins/click/_registerShortcutEvents.d.ts +28 -0
- package/dist/src/plugins/click/index.d.ts +16 -0
- package/dist/src/plugins/form/_defaults.d.ts +17 -0
- package/dist/src/plugins/form/_listenDOM.d.ts +68 -0
- package/dist/src/plugins/form/_normalizeShortcutName.d.ts +2 -0
- package/dist/src/plugins/form/_registerShortcutEvents.d.ts +96 -0
- package/dist/src/plugins/form/index.d.ts +9 -0
- package/dist/src/plugins/hover/_findTarget.d.ts +10 -0
- package/dist/src/plugins/hover/_listenDOM.d.ts +68 -0
- package/dist/src/plugins/hover/_normalizeShortcutName.d.ts +2 -0
- package/dist/src/plugins/hover/_registerShortcutEvents.d.ts +28 -0
- package/dist/src/plugins/hover/index.d.ts +14 -0
- package/dist/src/plugins/key/_listenDOM.d.ts +63 -0
- package/dist/src/plugins/key/_normalizeShortcutName.d.ts +2 -0
- package/dist/src/plugins/key/_readKeyEvent.d.ts +2 -0
- package/dist/src/plugins/key/_registerShortcutEvents.d.ts +28 -0
- package/dist/src/plugins/key/_specialChars.d.ts +7 -0
- package/dist/src/plugins/key/index.d.ts +14 -0
- package/dist/src/plugins/scroll/_listenDOM.d.ts +58 -0
- package/dist/src/plugins/scroll/_normalizeShortcutName.d.ts +2 -0
- package/dist/src/plugins/scroll/_registerShortcutEvents.d.ts +28 -0
- package/dist/src/plugins/scroll/index.d.ts +16 -0
- package/eslint.config.js +80 -0
- package/html/assets/index-COTh6lXR.css +1 -0
- package/html/assets/index-DOkKC3NI.js +53 -0
- package/html/bg.png +0 -0
- package/html/favicon.ico +0 -0
- package/html/favicon.svg +5 -0
- package/html/html.meta.json.gz +0 -0
- package/html/index.html +32 -0
- package/package.json +24 -19
- package/shortcuts.png +0 -0
- package/src/main.js +52 -22
- package/src/methods/_normalizeWithPlugins.js +26 -2
- package/src/methods/_readShortcutWithPlugins.js +9 -2
- package/src/methods/_setupPlugin.js +93 -0
- package/src/methods/_systemAction.js +12 -4
- package/src/methods/changeContext.js +11 -3
- package/src/methods/index.js +2 -0
- package/src/methods/listShortcuts.js +5 -12
- package/src/methods/load.js +11 -4
- package/src/methods/unload.js +8 -1
- package/src/plugins/click/_findTarget.js +11 -5
- package/src/plugins/click/_listenDOM.js +58 -20
- package/src/plugins/click/_normalizeShortcutName.js +11 -4
- package/src/plugins/click/_readClickEvent.js +1 -1
- package/src/plugins/click/_registerShortcutEvents.js +33 -5
- package/src/plugins/click/index.js +33 -60
- package/src/plugins/form/_defaults.js +13 -3
- package/src/plugins/form/_listenDOM.js +46 -9
- package/src/plugins/form/_normalizeShortcutName.js +2 -2
- package/src/plugins/form/_registerShortcutEvents.js +93 -17
- package/src/plugins/form/index.js +25 -56
- package/src/plugins/hover/_findTarget.js +26 -0
- package/src/plugins/hover/_listenDOM.js +154 -0
- package/src/plugins/hover/_normalizeShortcutName.js +21 -0
- package/src/plugins/hover/_registerShortcutEvents.js +51 -0
- package/src/plugins/hover/index.js +71 -0
- package/src/plugins/key/_listenDOM.js +67 -33
- package/src/plugins/key/_normalizeShortcutName.js +4 -3
- package/src/plugins/key/_readKeyEvent.js +1 -1
- package/src/plugins/key/_registerShortcutEvents.js +34 -5
- package/src/plugins/key/_specialChars.js +5 -0
- package/src/plugins/key/index.js +34 -59
- package/src/plugins/scroll/_listenDOM.js +141 -0
- package/src/plugins/scroll/_normalizeShortcutName.js +21 -0
- package/src/plugins/scroll/_registerShortcutEvents.js +50 -0
- package/src/plugins/scroll/index.js +61 -0
- package/test/01-general.test.js +92 -23
- package/test/02-key.test.js +241 -40
- package/test/03-click.test.js +291 -47
- package/test/04-form.test.js +241 -47
- package/test/05-hover.test.js +463 -0
- package/test/06-scroll.test.js +374 -0
- package/test-helpers/Block.jsx +3 -2
- package/test-helpers/style.css +6 -1
- package/tsconfig.json +2 -1
- package/vitest.config.js +13 -11
- package/How..to.make.plugins.md +0 -41
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
export type dependencies = {
|
|
2
|
+
/**
|
|
3
|
+
* - Event emitter instance
|
|
4
|
+
*/
|
|
5
|
+
ev: any;
|
|
6
|
+
/**
|
|
7
|
+
* - Internal API object
|
|
8
|
+
*/
|
|
9
|
+
inAPI: any;
|
|
10
|
+
/**
|
|
11
|
+
* - Public API object
|
|
12
|
+
*/
|
|
13
|
+
API: any;
|
|
14
|
+
/**
|
|
15
|
+
* - Extra dependencies object
|
|
16
|
+
*/
|
|
17
|
+
extra: any;
|
|
18
|
+
};
|
|
19
|
+
export type state = {
|
|
20
|
+
/**
|
|
21
|
+
* - Current context data container with name and note properties
|
|
22
|
+
*/
|
|
23
|
+
currentContext: any;
|
|
24
|
+
/**
|
|
25
|
+
* - Shortcuts object: { contextName : { shortcut : callback[] } }
|
|
26
|
+
*/
|
|
27
|
+
shortcuts: any;
|
|
28
|
+
/**
|
|
29
|
+
* - Array of active plugins
|
|
30
|
+
*/
|
|
31
|
+
plugins: any[];
|
|
32
|
+
/**
|
|
33
|
+
* - Keyboard shortcut log function
|
|
34
|
+
*/
|
|
35
|
+
exposeShortcut: Function | null;
|
|
36
|
+
/**
|
|
37
|
+
* - Name for error events
|
|
38
|
+
*/
|
|
39
|
+
ERROR_EVENT_NAME: string;
|
|
40
|
+
};
|
|
41
|
+
export type PluginAPI = {
|
|
42
|
+
/**
|
|
43
|
+
* - Get plugin prefix
|
|
44
|
+
*/
|
|
45
|
+
getPrefix: () => string;
|
|
46
|
+
/**
|
|
47
|
+
* - Format shortcut name
|
|
48
|
+
*/
|
|
49
|
+
shortcutName: (arg0: string) => string;
|
|
50
|
+
/**
|
|
51
|
+
* - Handle context change
|
|
52
|
+
*/
|
|
53
|
+
contextChange: (arg0: string) => void;
|
|
54
|
+
/**
|
|
55
|
+
* - Mute the plugin
|
|
56
|
+
*/
|
|
57
|
+
mute: () => void;
|
|
58
|
+
/**
|
|
59
|
+
* - Unmute the plugin
|
|
60
|
+
*/
|
|
61
|
+
unmute: () => void;
|
|
62
|
+
/**
|
|
63
|
+
* - Destroy the plugin
|
|
64
|
+
*/
|
|
65
|
+
destroy: () => void;
|
|
66
|
+
};
|
|
67
|
+
export type contextShortcuts = {
|
|
68
|
+
/**
|
|
69
|
+
* - Context name
|
|
70
|
+
*/
|
|
71
|
+
context: string;
|
|
72
|
+
/**
|
|
73
|
+
* - List of shortcuts in a context
|
|
74
|
+
*/
|
|
75
|
+
shortcuts: string[];
|
|
76
|
+
};
|
|
77
|
+
export type ShortcutsAPI = {
|
|
78
|
+
/**
|
|
79
|
+
* - Enable a plugin
|
|
80
|
+
*/
|
|
81
|
+
enablePlugin: (arg0: Function, arg1: any) => void;
|
|
82
|
+
/**
|
|
83
|
+
* - Disable a plugin
|
|
84
|
+
*/
|
|
85
|
+
disablePlugin: (arg0: string) => void;
|
|
86
|
+
/**
|
|
87
|
+
* - Mute a plugin
|
|
88
|
+
*/
|
|
89
|
+
mutePlugin: (arg0: string) => number;
|
|
90
|
+
/**
|
|
91
|
+
* - Unmute a plugin
|
|
92
|
+
*/
|
|
93
|
+
unmutePlugin: (arg0: string) => number;
|
|
94
|
+
/**
|
|
95
|
+
* - List enabled plugins
|
|
96
|
+
*/
|
|
97
|
+
listPlugins: () => string[];
|
|
98
|
+
/**
|
|
99
|
+
* - Get current context name
|
|
100
|
+
*/
|
|
101
|
+
getContext: () => string | null;
|
|
102
|
+
/**
|
|
103
|
+
* - Get current context note
|
|
104
|
+
*/
|
|
105
|
+
getNote: () => string | null;
|
|
106
|
+
/**
|
|
107
|
+
* - Set current context note
|
|
108
|
+
*/
|
|
109
|
+
setNote: (arg0: string | null) => void;
|
|
110
|
+
/**
|
|
111
|
+
* - Pause shortcuts in current context
|
|
112
|
+
*/
|
|
113
|
+
pause: (arg0: string) => void;
|
|
114
|
+
/**
|
|
115
|
+
* - Resume shortcuts in current context
|
|
116
|
+
*/
|
|
117
|
+
resume: (arg0: string) => void;
|
|
118
|
+
/**
|
|
119
|
+
* - Emit event for shortcut
|
|
120
|
+
*/
|
|
121
|
+
emit: (arg0: string, ...args: any[]) => void;
|
|
122
|
+
/**
|
|
123
|
+
* - List all context names
|
|
124
|
+
*/
|
|
125
|
+
listContexts: () => string[];
|
|
126
|
+
/**
|
|
127
|
+
* - Set external dependencies
|
|
128
|
+
*/
|
|
129
|
+
setDependencies: (arg0: any) => void;
|
|
130
|
+
/**
|
|
131
|
+
* - Get external dependencies
|
|
132
|
+
*/
|
|
133
|
+
getDependencies: () => any;
|
|
134
|
+
/**
|
|
135
|
+
* - Reset the library instance
|
|
136
|
+
*/
|
|
137
|
+
reset: () => void;
|
|
138
|
+
/**
|
|
139
|
+
* - Change current context
|
|
140
|
+
*/
|
|
141
|
+
changeContext: (arg0: string | boolean) => void;
|
|
142
|
+
/**
|
|
143
|
+
* - List shortcuts
|
|
144
|
+
*/
|
|
145
|
+
listShortcuts: (arg0: string | null) => string[] | contextShortcuts[] | null;
|
|
146
|
+
/**
|
|
147
|
+
* - Load shortcuts into contexts
|
|
148
|
+
*/
|
|
149
|
+
load: (arg0: any) => void;
|
|
150
|
+
/**
|
|
151
|
+
* - Unload a context
|
|
152
|
+
*/
|
|
153
|
+
unload: (arg0: string) => void;
|
|
154
|
+
};
|
|
155
|
+
/**
|
|
156
|
+
* @function shortcuts
|
|
157
|
+
* @description Create a shortcuts instance
|
|
158
|
+
* @param {Object} [options={}] - Configuration options
|
|
159
|
+
* @param {function} [options.onShortcut] - Function to log shortcut events
|
|
160
|
+
* @param {string} [options.errorEventName='@shortcuts-error'] - Name for error events
|
|
161
|
+
* @returns {ShortcutsAPI} The shortcuts API
|
|
162
|
+
*/
|
|
163
|
+
declare function main(options?: {
|
|
164
|
+
onShortcut?: Function;
|
|
165
|
+
errorEventName?: string;
|
|
166
|
+
}): ShortcutsAPI;
|
|
167
|
+
import pluginKey from './plugins/key/index.js';
|
|
168
|
+
import pluginClick from './plugins/click/index.js';
|
|
169
|
+
import pluginForm from './plugins/form/index.js';
|
|
170
|
+
import pluginHover from './plugins/hover/index.js';
|
|
171
|
+
import pluginScroll from './plugins/scroll/index.js';
|
|
172
|
+
export { main as shortcuts, pluginKey, pluginClick, pluginForm, pluginHover, pluginScroll };
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
export default _normalizeWithPlugins;
|
|
2
|
+
export type dependencies = {
|
|
3
|
+
/**
|
|
4
|
+
* - Event emitter instance
|
|
5
|
+
*/
|
|
6
|
+
ev: any;
|
|
7
|
+
/**
|
|
8
|
+
* - Internal API object
|
|
9
|
+
*/
|
|
10
|
+
inAPI: any;
|
|
11
|
+
/**
|
|
12
|
+
* - Public API object
|
|
13
|
+
*/
|
|
14
|
+
API: any;
|
|
15
|
+
/**
|
|
16
|
+
* - Extra dependencies object
|
|
17
|
+
*/
|
|
18
|
+
extra: any;
|
|
19
|
+
};
|
|
20
|
+
export type state = {
|
|
21
|
+
/**
|
|
22
|
+
* - Current context data container
|
|
23
|
+
*/
|
|
24
|
+
currentContext: any;
|
|
25
|
+
/**
|
|
26
|
+
* - Shortcuts object: { contextName : { shortcut : callback[] } }
|
|
27
|
+
*/
|
|
28
|
+
shortcuts: any;
|
|
29
|
+
/**
|
|
30
|
+
* - Array of active plugins
|
|
31
|
+
*/
|
|
32
|
+
plugins: any[];
|
|
33
|
+
/**
|
|
34
|
+
* - Keyboard shortcut log function
|
|
35
|
+
*/
|
|
36
|
+
exposeShortcut: Function | null;
|
|
37
|
+
/**
|
|
38
|
+
* - Name for error events
|
|
39
|
+
*/
|
|
40
|
+
ERROR_EVENT_NAME: string;
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* @typedef {Object} dependencies
|
|
44
|
+
* @property {Object} ev - Event emitter instance
|
|
45
|
+
* @property {Object} inAPI - Internal API object
|
|
46
|
+
* @property {Object} API - Public API object
|
|
47
|
+
* @property {Object} extra - Extra dependencies object
|
|
48
|
+
*/
|
|
49
|
+
/**
|
|
50
|
+
* @typedef {Object} state
|
|
51
|
+
* @property {Object} currentContext - Current context data container
|
|
52
|
+
* @property {Object} shortcuts - Shortcuts object: { contextName : { shortcut : callback[] } }
|
|
53
|
+
* @property {Array} plugins - Array of active plugins
|
|
54
|
+
* @property {Function|null} exposeShortcut - Keyboard shortcut log function
|
|
55
|
+
* @property {string} ERROR_EVENT_NAME - Name for error events
|
|
56
|
+
*/
|
|
57
|
+
/**
|
|
58
|
+
* @function _normalizeWithPlugins
|
|
59
|
+
* @description Function used by plugins during the enable process to normalize the existing and related to the plugin shortcut names.
|
|
60
|
+
* @param {dependencies} dependencies - Dependencies object containing inAPI
|
|
61
|
+
* @param {state} state - State object containing shortcuts
|
|
62
|
+
* @returns {function} - Returns a function that takes a normalize function
|
|
63
|
+
*/
|
|
64
|
+
declare function _normalizeWithPlugins(dependencies: dependencies, state: state): Function;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export default _readShortcutWithPlugins;
|
|
2
|
+
/**
|
|
3
|
+
* @function _readShortcutWithPlugins
|
|
4
|
+
* @description Searches for belonging plugin and call the plugin method to normalize the shortcut name.
|
|
5
|
+
* @param {dependencies} dependencies - Dependencies object containing inAPI
|
|
6
|
+
* @param {state} state - State object containing plugins
|
|
7
|
+
* @returns {function} - Returns a function that processes shortcut names
|
|
8
|
+
*/
|
|
9
|
+
declare function _readShortcutWithPlugins(dependencies: any, state: any): Function;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export default _setupPlugin;
|
|
2
|
+
/**
|
|
3
|
+
* @function _setupPlugin
|
|
4
|
+
* @description Setup a plugin with provided settings and dependencies
|
|
5
|
+
* @param {dependencies} dependencies - Dependencies object containing ev, extra, inAPI, API
|
|
6
|
+
* @param {state} state - State object containing currentContext, shortcuts, exposeShortcut, ERROR_EVENT_NAME
|
|
7
|
+
* @returns {function} - Returns a function that takes plugin settings and returns plugin API
|
|
8
|
+
*/
|
|
9
|
+
declare function _setupPlugin(dependencies: any, state: any): Function;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export default _systemAction;
|
|
2
|
+
/**
|
|
3
|
+
* @function _systemAction
|
|
4
|
+
* @description Call a specific plugin method.
|
|
5
|
+
* @param {dependencies} dependencies - Dependencies object containing inAPI
|
|
6
|
+
* @param {state} state - State object containing plugins array
|
|
7
|
+
* @returns {function} - Returns a function that executes plugin actions
|
|
8
|
+
*/
|
|
9
|
+
declare function _systemAction(dependencies: any, state: any): Function;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export default changeContext;
|
|
2
|
+
/**
|
|
3
|
+
* @function changeContext
|
|
4
|
+
* @description Change current context with shortcuts belonging to it
|
|
5
|
+
* @param {dependencies} dependencies - Dependencies object containing ev
|
|
6
|
+
* @param {state} state - State object containing shortcuts, currentContext, ERROR_EVENT_NAME
|
|
7
|
+
* @returns {function} - Returns a function that changes context
|
|
8
|
+
*/
|
|
9
|
+
declare function changeContext(dependencies: any, state: any): Function;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
declare namespace _default {
|
|
2
|
+
export { _normalizeWithPlugins };
|
|
3
|
+
export { _readShortcutWithPlugins };
|
|
4
|
+
export { _setupPlugin };
|
|
5
|
+
export { _systemAction };
|
|
6
|
+
export { changeContext };
|
|
7
|
+
export { listShortcuts };
|
|
8
|
+
export { load };
|
|
9
|
+
export { unload };
|
|
10
|
+
}
|
|
11
|
+
export default _default;
|
|
12
|
+
import _normalizeWithPlugins from './_normalizeWithPlugins.js';
|
|
13
|
+
import _readShortcutWithPlugins from './_readShortcutWithPlugins.js';
|
|
14
|
+
import _setupPlugin from './_setupPlugin.js';
|
|
15
|
+
import _systemAction from './_systemAction.js';
|
|
16
|
+
import changeContext from './changeContext.js';
|
|
17
|
+
import listShortcuts from './listShortcuts.js';
|
|
18
|
+
import load from './load.js';
|
|
19
|
+
import unload from './unload.js';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export default load;
|
|
2
|
+
/**
|
|
3
|
+
* @function load
|
|
4
|
+
* @description Load a context with shortcuts object
|
|
5
|
+
* @param {dependencies} dependencies - Dependencies object containing API with changeContext and getContext
|
|
6
|
+
* @param {state} state - State object containing shortcuts and plugins
|
|
7
|
+
* @returns {function} - Returns a function that loads shortcuts
|
|
8
|
+
*/
|
|
9
|
+
declare function load(dependencies: any, state: any): Function;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export default unload;
|
|
2
|
+
/**
|
|
3
|
+
* @function unload
|
|
4
|
+
* @description Unload a non-active context with shortcuts
|
|
5
|
+
* @param {dependencies} dependencies - Dependencies object containing ev
|
|
6
|
+
* @param {state} state - State object containing currentContext, shortcuts, ERROR_EVENT_NAME
|
|
7
|
+
* @returns {function} - Returns a function that unloads contexts
|
|
8
|
+
*/
|
|
9
|
+
declare function unload(dependencies: any, state: any): Function;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export default _findTarget;
|
|
2
|
+
/**
|
|
3
|
+
* @function _findTarget
|
|
4
|
+
* @description Find the appropriate click target element by checking if element has any of the target attributes
|
|
5
|
+
* @param {Object} dependencies - Dependencies object
|
|
6
|
+
* @param {Object} state - Plugin state containing listenOptions with clickTarget array
|
|
7
|
+
* @param {Element} target - DOM element to start searching from
|
|
8
|
+
* @returns {Element|null} - Target element or null if not found
|
|
9
|
+
*/
|
|
10
|
+
declare function _findTarget(dependencies: any, state: any, target: Element): Element | null;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
export default _listenDOM;
|
|
2
|
+
export type ClickEventData = {
|
|
3
|
+
/**
|
|
4
|
+
* - The DOM element that was clicked
|
|
5
|
+
*/
|
|
6
|
+
target: Element;
|
|
7
|
+
/**
|
|
8
|
+
* - X coordinate of the click event
|
|
9
|
+
*/
|
|
10
|
+
x: number;
|
|
11
|
+
/**
|
|
12
|
+
* - Y coordinate of the click event
|
|
13
|
+
*/
|
|
14
|
+
y: number;
|
|
15
|
+
/**
|
|
16
|
+
* - Current context name
|
|
17
|
+
*/
|
|
18
|
+
context: string;
|
|
19
|
+
/**
|
|
20
|
+
* - Current context note
|
|
21
|
+
*/
|
|
22
|
+
note: string | null;
|
|
23
|
+
/**
|
|
24
|
+
* - Plugin state listenOptions (reference to pluginState.listenOptions)
|
|
25
|
+
*/
|
|
26
|
+
options: any;
|
|
27
|
+
/**
|
|
28
|
+
* - The original DOM event
|
|
29
|
+
*/
|
|
30
|
+
event: Event;
|
|
31
|
+
/**
|
|
32
|
+
* - Extra dependencies object
|
|
33
|
+
*/
|
|
34
|
+
dependencies: any;
|
|
35
|
+
/**
|
|
36
|
+
* - Viewport information with X, Y, width, height
|
|
37
|
+
*/
|
|
38
|
+
viewport: any;
|
|
39
|
+
/**
|
|
40
|
+
* - Element dimensions with width, height
|
|
41
|
+
*/
|
|
42
|
+
sizes: any;
|
|
43
|
+
/**
|
|
44
|
+
* - Element position relative to viewport with x, y
|
|
45
|
+
*/
|
|
46
|
+
position: any;
|
|
47
|
+
/**
|
|
48
|
+
* - Element position relative to page with x, y
|
|
49
|
+
*/
|
|
50
|
+
pagePosition: any;
|
|
51
|
+
/**
|
|
52
|
+
* - Event type ('click')
|
|
53
|
+
*/
|
|
54
|
+
type: string;
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* @function _listenDOM
|
|
58
|
+
* @description Set up DOM event listeners for click events
|
|
59
|
+
* @param {Object} dependencies - Dependencies object containing ev, _findTarget, _readClickEvent, extra, resetState
|
|
60
|
+
* @param {Object} state - Plugin state containing listenOptions and currentContext
|
|
61
|
+
* @returns {Object} - Object containing start and stop methods
|
|
62
|
+
*
|
|
63
|
+
* @typedef {Object} ClickEventData
|
|
64
|
+
* @property {Element} target - The DOM element that was clicked
|
|
65
|
+
* @property {number} x - X coordinate of the click event
|
|
66
|
+
* @property {number} y - Y coordinate of the click event
|
|
67
|
+
* @property {string} context - Current context name
|
|
68
|
+
* @property {string|null} note - Current context note
|
|
69
|
+
* @property {Object} options - Plugin state listenOptions (reference to pluginState.listenOptions)
|
|
70
|
+
* @property {Event} event - The original DOM event
|
|
71
|
+
* @property {Object} dependencies - Extra dependencies object
|
|
72
|
+
* @property {Object} viewport - Viewport information with X, Y, width, height
|
|
73
|
+
* @property {Object} sizes - Element dimensions with width, height
|
|
74
|
+
* @property {Object} position - Element position relative to viewport with x, y
|
|
75
|
+
* @property {Object} pagePosition - Element position relative to page with x, y
|
|
76
|
+
* @property {string} type - Event type ('click')
|
|
77
|
+
*/
|
|
78
|
+
declare function _listenDOM(dependencies: any, state: any): any;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export default _normalizeShortcutName;
|
|
2
|
+
/**
|
|
3
|
+
* @function _normalizeShortcutName
|
|
4
|
+
* @description Normalize click shortcut name to standard format
|
|
5
|
+
* @param {string} name - Raw shortcut name
|
|
6
|
+
* @returns {string} - Normalized shortcut name
|
|
7
|
+
*/
|
|
8
|
+
declare function _normalizeShortcutName(name: string): string;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export default _registerShortcutEvents;
|
|
2
|
+
export type ClickSetupData = {
|
|
3
|
+
/**
|
|
4
|
+
* - Extra dependencies object
|
|
5
|
+
*/
|
|
6
|
+
dependencies: any;
|
|
7
|
+
/**
|
|
8
|
+
* - Default options (clone of pluginState.defaultOptions)
|
|
9
|
+
*/
|
|
10
|
+
defaults: any;
|
|
11
|
+
/**
|
|
12
|
+
* - Plugin state listenOptions (reference to pluginState.listenOptions)
|
|
13
|
+
*/
|
|
14
|
+
options: any;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* @function _registerShortcutEvents
|
|
18
|
+
* @description Register click shortcut events and handle setup
|
|
19
|
+
* @param {Object} dependencies - Dependencies object containing regex
|
|
20
|
+
* @param {Object} pluginState - Plugin state containing listenOptions, currentContext, shortcuts, etc.
|
|
21
|
+
* @returns {number} - Number of registered shortcuts
|
|
22
|
+
*
|
|
23
|
+
* @typedef {Object} ClickSetupData
|
|
24
|
+
* @property {Object} dependencies - Extra dependencies object
|
|
25
|
+
* @property {Object} defaults - Default options (clone of pluginState.defaultOptions)
|
|
26
|
+
* @property {Object} options - Plugin state listenOptions (reference to pluginState.listenOptions)
|
|
27
|
+
*/
|
|
28
|
+
declare function _registerShortcutEvents(dependencies: any, pluginState: any): number;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export default pluginClick;
|
|
2
|
+
/**
|
|
3
|
+
* @function pluginClick
|
|
4
|
+
* @description Plugin for mouse click shortcuts
|
|
5
|
+
* @param {function} setupPlugin - Plugin setup function from the library
|
|
6
|
+
* @param {Object} [options={}] - Plugin options
|
|
7
|
+
* @param {number} [options.mouseWait=320] - Time to wait for click sequence in ms
|
|
8
|
+
* @param {string[]} [options.clickTarget=['data-click', 'href']] - Array of attribute names for click targets
|
|
9
|
+
* @param {function} [options.streamKeys] - Function to stream key presses
|
|
10
|
+
* @returns {PluginAPI} Plugin API
|
|
11
|
+
*/
|
|
12
|
+
declare function pluginClick(setupPlugin: Function, options?: {
|
|
13
|
+
mouseWait?: number;
|
|
14
|
+
clickTarget?: string[];
|
|
15
|
+
streamKeys?: Function;
|
|
16
|
+
}): PluginAPI;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export default _defaults;
|
|
2
|
+
export type _defaults = {
|
|
3
|
+
/**
|
|
4
|
+
* - Function that returns CSS selector for form elements to watch
|
|
5
|
+
*/
|
|
6
|
+
watch: Function;
|
|
7
|
+
/**
|
|
8
|
+
* - Function that determines the type of form element
|
|
9
|
+
*/
|
|
10
|
+
define: Function;
|
|
11
|
+
};
|
|
12
|
+
declare namespace _defaults {
|
|
13
|
+
function watch(): string;
|
|
14
|
+
function define({ target }: {
|
|
15
|
+
target: any;
|
|
16
|
+
}): "input" | "checkbox" | "button";
|
|
17
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
export default _listenDOM;
|
|
2
|
+
export type FormEventData = {
|
|
3
|
+
/**
|
|
4
|
+
* - The DOM element that triggered the form event
|
|
5
|
+
*/
|
|
6
|
+
target: Element;
|
|
7
|
+
/**
|
|
8
|
+
* - Current context name
|
|
9
|
+
*/
|
|
10
|
+
context: string;
|
|
11
|
+
/**
|
|
12
|
+
* - Current context note
|
|
13
|
+
*/
|
|
14
|
+
note: string | null;
|
|
15
|
+
/**
|
|
16
|
+
* - The original DOM event
|
|
17
|
+
*/
|
|
18
|
+
event: Event;
|
|
19
|
+
/**
|
|
20
|
+
* - Extra dependencies object
|
|
21
|
+
*/
|
|
22
|
+
dependencies: any;
|
|
23
|
+
/**
|
|
24
|
+
* - Plugin state listenOptions (reference to pluginState.listenOptions)
|
|
25
|
+
*/
|
|
26
|
+
options: any;
|
|
27
|
+
/**
|
|
28
|
+
* - Viewport information with X, Y, width, height
|
|
29
|
+
*/
|
|
30
|
+
viewport: any;
|
|
31
|
+
/**
|
|
32
|
+
* - Element dimensions with width, height
|
|
33
|
+
*/
|
|
34
|
+
sizes: any;
|
|
35
|
+
/**
|
|
36
|
+
* - Element position relative to viewport with x, y
|
|
37
|
+
*/
|
|
38
|
+
position: any;
|
|
39
|
+
/**
|
|
40
|
+
* - Element position relative to page with x, y
|
|
41
|
+
*/
|
|
42
|
+
pagePosition: any;
|
|
43
|
+
/**
|
|
44
|
+
* - Event type ('form-in', 'form-out', 'form-instant')
|
|
45
|
+
*/
|
|
46
|
+
type: string;
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* @function _listenDOM
|
|
50
|
+
* @description Set up DOM event listeners for form events
|
|
51
|
+
* @param {Object} dependencies - Dependencies object containing ev
|
|
52
|
+
* @param {Object} state - Plugin state containing listenOptions and currentContext
|
|
53
|
+
* @returns {Object} - Object containing start and stop methods
|
|
54
|
+
*
|
|
55
|
+
* @typedef {Object} FormEventData
|
|
56
|
+
* @property {Element} target - The DOM element that triggered the form event
|
|
57
|
+
* @property {string} context - Current context name
|
|
58
|
+
* @property {string|null} note - Current context note
|
|
59
|
+
* @property {Event} event - The original DOM event
|
|
60
|
+
* @property {Object} dependencies - Extra dependencies object
|
|
61
|
+
* @property {Object} options - Plugin state listenOptions (reference to pluginState.listenOptions)
|
|
62
|
+
* @property {Object} viewport - Viewport information with X, Y, width, height
|
|
63
|
+
* @property {Object} sizes - Element dimensions with width, height
|
|
64
|
+
* @property {Object} position - Element position relative to viewport with x, y
|
|
65
|
+
* @property {Object} pagePosition - Element position relative to page with x, y
|
|
66
|
+
* @property {string} type - Event type ('form-in', 'form-out', 'form-instant')
|
|
67
|
+
*/
|
|
68
|
+
declare function _listenDOM(dependencies: any, state: any): any;
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
export default _registerShortcutEvents;
|
|
2
|
+
export type FormWatchData = {
|
|
3
|
+
/**
|
|
4
|
+
* - Extra dependencies object
|
|
5
|
+
*/
|
|
6
|
+
dependencies: any;
|
|
7
|
+
/**
|
|
8
|
+
* - Current context name
|
|
9
|
+
*/
|
|
10
|
+
context: string;
|
|
11
|
+
/**
|
|
12
|
+
* - Current context note
|
|
13
|
+
*/
|
|
14
|
+
note: string | null;
|
|
15
|
+
/**
|
|
16
|
+
* - Plugin state listenOptions (reference to pluginState.listenOptions)
|
|
17
|
+
*/
|
|
18
|
+
options: any;
|
|
19
|
+
};
|
|
20
|
+
export type FormDefineData = {
|
|
21
|
+
/**
|
|
22
|
+
* - The DOM element being watched
|
|
23
|
+
*/
|
|
24
|
+
target: Element;
|
|
25
|
+
/**
|
|
26
|
+
* - Current context name
|
|
27
|
+
*/
|
|
28
|
+
context: string;
|
|
29
|
+
/**
|
|
30
|
+
* - Current context note
|
|
31
|
+
*/
|
|
32
|
+
note: string | null;
|
|
33
|
+
/**
|
|
34
|
+
* - Extra dependencies object
|
|
35
|
+
*/
|
|
36
|
+
dependencies: any;
|
|
37
|
+
/**
|
|
38
|
+
* - Viewport information with X, Y, width, height
|
|
39
|
+
*/
|
|
40
|
+
viewport: any;
|
|
41
|
+
/**
|
|
42
|
+
* - Element dimensions with width, height
|
|
43
|
+
*/
|
|
44
|
+
sizes: any;
|
|
45
|
+
/**
|
|
46
|
+
* - Element position relative to viewport with x, y
|
|
47
|
+
*/
|
|
48
|
+
position: any;
|
|
49
|
+
/**
|
|
50
|
+
* - Element position relative to page with x, y
|
|
51
|
+
*/
|
|
52
|
+
pagePosition: any;
|
|
53
|
+
/**
|
|
54
|
+
* - Plugin state listenOptions (reference to pluginState.listenOptions)
|
|
55
|
+
*/
|
|
56
|
+
options: any;
|
|
57
|
+
};
|
|
58
|
+
export type FormActionData = {
|
|
59
|
+
/**
|
|
60
|
+
* - Extra dependencies object
|
|
61
|
+
*/
|
|
62
|
+
dependencies: any;
|
|
63
|
+
/**
|
|
64
|
+
* - Plugin state listenOptions (reference to pluginState.listenOptions)
|
|
65
|
+
*/
|
|
66
|
+
options: any;
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* @function _registerShortcutEvents
|
|
70
|
+
* @description Register form shortcut events and handle setup
|
|
71
|
+
* @param {Object} dependencies - Dependencies object containing regex, _defaults, ev
|
|
72
|
+
* @param {Object} pluginState - Plugin state containing currentContext, shortcuts, callbacks, etc.
|
|
73
|
+
* @returns {number|false} - Number of registered shortcuts or false if no actions
|
|
74
|
+
*
|
|
75
|
+
* @typedef {Object} FormWatchData
|
|
76
|
+
* @property {Object} dependencies - Extra dependencies object
|
|
77
|
+
* @property {string} context - Current context name
|
|
78
|
+
* @property {string|null} note - Current context note
|
|
79
|
+
* @property {Object} options - Plugin state listenOptions (reference to pluginState.listenOptions)
|
|
80
|
+
*
|
|
81
|
+
* @typedef {Object} FormDefineData
|
|
82
|
+
* @property {Element} target - The DOM element being watched
|
|
83
|
+
* @property {string} context - Current context name
|
|
84
|
+
* @property {string|null} note - Current context note
|
|
85
|
+
* @property {Object} dependencies - Extra dependencies object
|
|
86
|
+
* @property {Object} viewport - Viewport information with X, Y, width, height
|
|
87
|
+
* @property {Object} sizes - Element dimensions with width, height
|
|
88
|
+
* @property {Object} position - Element position relative to viewport with x, y
|
|
89
|
+
* @property {Object} pagePosition - Element position relative to page with x, y
|
|
90
|
+
* @property {Object} options - Plugin state listenOptions (reference to pluginState.listenOptions)
|
|
91
|
+
*
|
|
92
|
+
* @typedef {Object} FormActionData
|
|
93
|
+
* @property {Object} dependencies - Extra dependencies object
|
|
94
|
+
* @property {Object} options - Plugin state listenOptions (reference to pluginState.listenOptions)
|
|
95
|
+
*/
|
|
96
|
+
declare function _registerShortcutEvents(dependencies: any, pluginState: any): number | false;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export default pluginForm;
|
|
2
|
+
/**
|
|
3
|
+
* @function pluginForm
|
|
4
|
+
* @description Plugin for form element shortcuts
|
|
5
|
+
* @param {function} setupPlugin - Plugin setup function from the library
|
|
6
|
+
* @param {Object} [options={}] - Plugin options
|
|
7
|
+
* @returns {PluginAPI} Plugin API
|
|
8
|
+
*/
|
|
9
|
+
declare function pluginForm(setupPlugin: Function, options?: any): PluginAPI;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export default _findTarget;
|
|
2
|
+
/**
|
|
3
|
+
* @function _findTarget
|
|
4
|
+
* @description Find the appropriate hover target element by checking if element has any of the target attributes
|
|
5
|
+
* @param {Object} dependencies - Dependencies object
|
|
6
|
+
* @param {Object} state - Plugin state containing listenOptions with hoverTarget array
|
|
7
|
+
* @param {Element} target - DOM element to start searching from
|
|
8
|
+
* @returns {Element|false} - Target element or false if not found
|
|
9
|
+
*/
|
|
10
|
+
declare function _findTarget(dependencies: any, state: any, target: Element): Element | false;
|