@peter.naydenov/shortcuts 4.0.0 → 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.
Files changed (40) hide show
  1. package/Changelog.md +7 -1
  2. package/README.md +1 -1
  3. package/dist/src/main.d.ts +172 -0
  4. package/dist/src/methods/_normalizeWithPlugins.d.ts +64 -0
  5. package/dist/src/methods/_readShortcutWithPlugins.d.ts +9 -0
  6. package/dist/src/methods/_setupPlugin.d.ts +9 -0
  7. package/dist/src/methods/_systemAction.d.ts +9 -0
  8. package/dist/src/methods/changeContext.d.ts +9 -0
  9. package/dist/src/methods/index.d.ts +19 -0
  10. package/dist/src/methods/listShortcuts.d.ts +2 -0
  11. package/dist/src/methods/load.d.ts +9 -0
  12. package/dist/src/methods/unload.d.ts +9 -0
  13. package/dist/src/plugins/click/_findTarget.d.ts +10 -0
  14. package/dist/src/plugins/click/_listenDOM.d.ts +78 -0
  15. package/dist/src/plugins/click/_normalizeShortcutName.d.ts +8 -0
  16. package/dist/src/plugins/click/_readClickEvent.d.ts +2 -0
  17. package/dist/src/plugins/click/_registerShortcutEvents.d.ts +28 -0
  18. package/dist/src/plugins/click/index.d.ts +16 -0
  19. package/dist/src/plugins/form/_defaults.d.ts +17 -0
  20. package/dist/src/plugins/form/_listenDOM.d.ts +68 -0
  21. package/dist/src/plugins/form/_normalizeShortcutName.d.ts +2 -0
  22. package/dist/src/plugins/form/_registerShortcutEvents.d.ts +96 -0
  23. package/dist/src/plugins/form/index.d.ts +9 -0
  24. package/dist/src/plugins/hover/_findTarget.d.ts +10 -0
  25. package/dist/src/plugins/hover/_listenDOM.d.ts +68 -0
  26. package/dist/src/plugins/hover/_normalizeShortcutName.d.ts +2 -0
  27. package/dist/src/plugins/hover/_registerShortcutEvents.d.ts +28 -0
  28. package/dist/src/plugins/hover/index.d.ts +14 -0
  29. package/dist/src/plugins/key/_listenDOM.d.ts +63 -0
  30. package/dist/src/plugins/key/_normalizeShortcutName.d.ts +2 -0
  31. package/dist/src/plugins/key/_readKeyEvent.d.ts +2 -0
  32. package/dist/src/plugins/key/_registerShortcutEvents.d.ts +28 -0
  33. package/dist/src/plugins/key/_specialChars.d.ts +7 -0
  34. package/dist/src/plugins/key/index.d.ts +14 -0
  35. package/dist/src/plugins/scroll/_listenDOM.d.ts +58 -0
  36. package/dist/src/plugins/scroll/_normalizeShortcutName.d.ts +2 -0
  37. package/dist/src/plugins/scroll/_registerShortcutEvents.d.ts +28 -0
  38. package/dist/src/plugins/scroll/index.d.ts +16 -0
  39. package/package.json +17 -16
  40. package/tsconfig.json +2 -1
package/Changelog.md CHANGED
@@ -2,7 +2,13 @@
2
2
 
3
3
 
4
4
 
5
- ### 4.0.0 ( 2025-11-?? )
5
+ ### 4.0.1 ( 2026-03-24 )
6
+ - [x] Dev deps update. TypeScript to v.6.0.2;
7
+ - [x] Types update according to TypeScript v.6.0.2;
8
+
9
+
10
+
11
+ ### 4.0.0 ( 2025-11-08 )
6
12
  - [x] New plugin 'hover';
7
13
  - [x] New plugin 'scroll';
8
14
  - [x] Refactoring on plugin API. New method for building plugin interface;
package/README.md CHANGED
@@ -1,4 +1,4 @@
1
- <img src="shortcuts.png" width="100%" alt="Notice" align="center" />
1
+ <img src="shortcuts.png" width="100%" alt="Shortcuts" align="center" />
2
2
 
3
3
 
4
4
 
@@ -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,2 @@
1
+ export default listShortcuts;
2
+ declare function listShortcuts(dependencies: any, state: any): (contextName?: string | null) => string[] | contextShortcuts[] | null;
@@ -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,2 @@
1
+ export default _readClickEvent;
2
+ declare function _readClickEvent(event: any, count: any): 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,2 @@
1
+ export default _normalizeShortcutName;
2
+ declare function _normalizeShortcutName(name: 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;
@@ -0,0 +1,68 @@
1
+ export default _listenDOM;
2
+ export type HoverEventData = {
3
+ /**
4
+ * - The DOM element that is being hovered
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 ('hover')
45
+ */
46
+ type: string;
47
+ };
48
+ /**
49
+ * @function _listenDOM
50
+ * @description Set up DOM event listeners for hover events
51
+ * @param {Object} dependencies - Dependencies object containing ev, _findTarget, resetState, extra
52
+ * @param {Object} state - Plugin state containing listenOptions and currentContext
53
+ * @returns {Object} - Object containing start and stop methods
54
+ *
55
+ * @typedef {Object} HoverEventData
56
+ * @property {Element} target - The DOM element that is being hovered
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 ('hover')
67
+ */
68
+ declare function _listenDOM(dependencies: any, state: any): any;
@@ -0,0 +1,2 @@
1
+ export default _normalizeShortcutName;
2
+ declare function _normalizeShortcutName(name: any): any;
@@ -0,0 +1,28 @@
1
+ export default _registerShortcutEvents;
2
+ export type HoverSetupData = {
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 hover shortcut events and handle setup
19
+ * @param {Object} dependencies - Dependencies object containing regex, _defaults, ev
20
+ * @param {Object} pluginState - Plugin state containing currentContext, shortcuts, ERROR_EVENT_NAME
21
+ * @returns {number} - Number of registered shortcuts
22
+ *
23
+ * @typedef {Object} HoverSetupData
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,14 @@
1
+ export default pluginHover;
2
+ /**
3
+ * @function pluginHover
4
+ * @description Plugin for mouse hover shortcuts
5
+ * @param {function} setupPlugin - Plugin setup function from the library
6
+ * @param {Object} [options={}] - Plugin options
7
+ * @param {string[]} [options.hoverTarget=['data-hover']] - Array of attribute names for hover targets
8
+ * @param {number} [options.wait=320] - Time to wait for hover sequence in ms
9
+ * @returns {PluginAPI} Plugin API
10
+ */
11
+ declare function pluginHover(setupPlugin: Function, options?: {
12
+ hoverTarget?: string[];
13
+ wait?: number;
14
+ }): PluginAPI;
@@ -0,0 +1,63 @@
1
+ export default _listenDOM;
2
+ export type KeyEventData = {
3
+ /**
4
+ * - Function to wait for keys (disables key sequence)
5
+ */
6
+ wait: Function;
7
+ /**
8
+ * - Function to end waiting for keys (enables key sequence)
9
+ */
10
+ end: Function;
11
+ /**
12
+ * - Function to ignore the last key in sequence
13
+ */
14
+ ignore: Function;
15
+ /**
16
+ * - Function to check if currently waiting for keys
17
+ */
18
+ isWaiting: Function;
19
+ /**
20
+ * - Current context note
21
+ */
22
+ note: string | null;
23
+ /**
24
+ * - Current context name
25
+ */
26
+ context: string;
27
+ /**
28
+ * - Extra dependencies object
29
+ */
30
+ dependencies: any;
31
+ /**
32
+ * - Plugin state listenOptions (reference to pluginState.listenOptions)
33
+ */
34
+ options: any;
35
+ /**
36
+ * - Viewport information with X, Y, width, height
37
+ */
38
+ viewport: any;
39
+ /**
40
+ * - Event type ('key')
41
+ */
42
+ type: string;
43
+ };
44
+ /**
45
+ * @function _listenDOM
46
+ * @description Set up DOM event listeners for keyboard events
47
+ * @param {Object} dependencies - Dependencies object containing ev, _specialChars, _readKeyEvent, extra, resetState
48
+ * @param {Object} state - Plugin state containing listenOptions and currentContext
49
+ * @returns {Object} - Object containing start and stop methods
50
+ *
51
+ * @typedef {Object} KeyEventData
52
+ * @property {Function} wait - Function to wait for keys (disables key sequence)
53
+ * @property {Function} end - Function to end waiting for keys (enables key sequence)
54
+ * @property {Function} ignore - Function to ignore the last key in sequence
55
+ * @property {Function} isWaiting - Function to check if currently waiting for keys
56
+ * @property {string|null} note - Current context note
57
+ * @property {string} context - Current context name
58
+ * @property {Object} dependencies - Extra dependencies object
59
+ * @property {Object} options - Plugin state listenOptions (reference to pluginState.listenOptions)
60
+ * @property {Object} viewport - Viewport information with X, Y, width, height
61
+ * @property {string} type - Event type ('key')
62
+ */
63
+ declare function _listenDOM(dependencies: any, state: any): any;
@@ -0,0 +1,2 @@
1
+ export default _normalizeShortcutName;
2
+ declare function _normalizeShortcutName(name: any): any;
@@ -0,0 +1,2 @@
1
+ export default _readKeyEvent;
2
+ declare function _readKeyEvent(event: any, _specialChars: any): any[];
@@ -0,0 +1,28 @@
1
+ export default _registerShortcutEvents;
2
+ export type KeySetupData = {
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 keyboard shortcut events and handle setup
19
+ * @param {Object} dependencies - Dependencies object containing regex
20
+ * @param {Object} pluginState - Plugin state containing currentContext, shortcuts
21
+ * @returns {number} - Number of registered shortcuts
22
+ *
23
+ * @typedef {Object} KeySetupData
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,7 @@
1
+ export default _specialChars;
2
+ /**
3
+ * @function _specialChars
4
+ * @description Get mapping of special keyboard characters to their normalized names
5
+ * @returns {Object} - Object mapping keyboard event keys to normalized names
6
+ */
7
+ declare function _specialChars(): any;
@@ -0,0 +1,14 @@
1
+ export default pluginKey;
2
+ /**
3
+ * @function pluginKey
4
+ * @description Plugin for keyboard shortcuts
5
+ * @param {function} setupPlugin - Plugin setup function from the library
6
+ * @param {Object} [options={}] - Plugin options
7
+ * @param {number} [options.keyWait=480] - Time to wait for key sequence in ms
8
+ * @param {function} [options.streamKeys] - Function to stream key presses
9
+ * @returns {PluginAPI} Plugin API
10
+ */
11
+ declare function pluginKey(setupPlugin: Function, options?: {
12
+ keyWait?: number;
13
+ streamKeys?: Function;
14
+ }): PluginAPI;
@@ -0,0 +1,58 @@
1
+ export default _listenDOM;
2
+ export type ScrollEventData = {
3
+ /**
4
+ * - Current scroll X position
5
+ */
6
+ x: number;
7
+ /**
8
+ * - Current scroll Y position
9
+ */
10
+ y: number;
11
+ /**
12
+ * - Scroll direction ('up', 'down', 'left', 'right')
13
+ */
14
+ direction: string;
15
+ /**
16
+ * - Current context name
17
+ */
18
+ context: string;
19
+ /**
20
+ * - Current context note
21
+ */
22
+ note: string | null;
23
+ /**
24
+ * - Extra dependencies object
25
+ */
26
+ dependencies: any;
27
+ /**
28
+ * - Plugin state listenOptions (reference to pluginState.listenOptions)
29
+ */
30
+ options: any;
31
+ /**
32
+ * - Viewport information with X, Y, width, height
33
+ */
34
+ viewport: any;
35
+ /**
36
+ * - Event type ('scroll')
37
+ */
38
+ type: string;
39
+ };
40
+ /**
41
+ * @function _listenDOM
42
+ * @description Set up DOM event listeners for scroll events
43
+ * @param {Object} dependencies - Dependencies object containing ev, resetState, extra
44
+ * @param {Object} state - Plugin state containing listenOptions and currentContext
45
+ * @returns {Object} - Object containing start and stop methods
46
+ *
47
+ * @typedef {Object} ScrollEventData
48
+ * @property {number} x - Current scroll X position
49
+ * @property {number} y - Current scroll Y position
50
+ * @property {string} direction - Scroll direction ('up', 'down', 'left', 'right')
51
+ * @property {string} context - Current context name
52
+ * @property {string|null} note - Current context note
53
+ * @property {Object} dependencies - Extra dependencies object
54
+ * @property {Object} options - Plugin state listenOptions (reference to pluginState.listenOptions)
55
+ * @property {Object} viewport - Viewport information with X, Y, width, height
56
+ * @property {string} type - Event type ('scroll')
57
+ */
58
+ declare function _listenDOM(dependencies: any, state: any): any;
@@ -0,0 +1,2 @@
1
+ export default _normalizeShortcutName;
2
+ declare function _normalizeShortcutName(name: any): any;
@@ -0,0 +1,28 @@
1
+ export default _registerShortcutEvents;
2
+ export type ScrollSetupData = {
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 scroll shortcut events and handle setup
19
+ * @param {Object} dependencies - Dependencies object containing regex
20
+ * @param {Object} pluginState - Plugin state containing currentContext, shortcuts
21
+ * @returns {number} - Number of registered shortcuts
22
+ *
23
+ * @typedef {Object} ScrollSetupData
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 pluginScroll;
2
+ /**
3
+ * @function pluginScroll
4
+ * @description Plugin for scroll event shortcuts
5
+ * @param {function} setupPlugin - Plugin setup function from the library
6
+ * @param {Object} [options={}] - Plugin options
7
+ * @param {number} [options.scrollWait=50] - Delay between scroll events in ms
8
+ * @param {number} [options.endScrollWait=400] - Delay when scroll was stopped in ms
9
+ * @param {number} [options.minSpace=40] - Minimum distance between scroll events in px
10
+ * @returns {PluginAPI} Plugin API
11
+ */
12
+ declare function pluginScroll(setupPlugin: Function, options?: {
13
+ scrollWait?: number;
14
+ endScrollWait?: number;
15
+ minSpace?: number;
16
+ }): PluginAPI;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@peter.naydenov/shortcuts",
3
3
  "description": "Context control of shortcuts based on keyboard and mouse events",
4
- "version": "4.0.0",
4
+ "version": "4.0.1",
5
5
  "license": "MIT",
6
6
  "author": "Peter Naydenov",
7
7
  "main": "./src/main.js",
@@ -38,24 +38,25 @@
38
38
  "@peter.naydenov/visual-controller-for-react": "^3.0.2",
39
39
  "@rollup/plugin-commonjs": "^29.0.0",
40
40
  "@rollup/plugin-node-resolve": "^16.0.3",
41
- "@rollup/plugin-terser": "^0.4.4",
41
+ "@rollup/plugin-terser": "^1.0.0",
42
42
  "@testing-library/dom": "^10.4.1",
43
43
  "@testing-library/user-event": "^14.6.1",
44
- "@vitejs/plugin-react": "^5.1.0",
45
- "@vitest/browser": "^4.0.8",
46
- "@vitest/browser-playwright": "^4.0.8",
47
- "@vitest/coverage-v8": "^4.0.8",
48
- "@vitest/ui": "^4.0.8",
44
+ "@vitejs/plugin-react": "^6.0.1",
45
+ "@vitest/browser": "^4.0.18",
46
+ "@vitest/browser-playwright": "^4.0.18",
47
+ "@vitest/coverage-v8": "^4.0.18",
48
+ "@vitest/ui": "^4.0.18",
49
49
  "ask-for-promise": "^3.1.0",
50
- "chai": "^6.2.0",
51
- "eslint": "^9.39.1",
52
- "mocha": "^11.7.4",
53
- "playwright": "^1.56.1",
54
- "react": "^19.2.0",
55
- "react-dom": "^19.2.0",
56
- "typescript": "^5.9.3",
57
- "vite": "^7.2.2",
58
- "vitest": "^4.0.8"
50
+ "chai": "^6.2.2",
51
+ "eslint": "^10.1.0",
52
+ "mocha": "^12.0.0-beta-9",
53
+ "playwright": "^1.58.2",
54
+ "react": "^19.2.4",
55
+ "react-dom": "^19.2.4",
56
+ "rollup": "^4.60.0",
57
+ "typescript": "^6.0.2",
58
+ "vite": "^8.0.2",
59
+ "vitest": "^4.0.18"
59
60
  },
60
61
  "keywords": [
61
62
  "shortcut",
package/tsconfig.json CHANGED
@@ -4,9 +4,10 @@
4
4
  "declaration": true,
5
5
  "emitDeclarationOnly": true,
6
6
  "outDir": "dist",
7
+ "rootDir": "src",
7
8
  "target": "ES2020",
8
9
  "module": "ESNext",
9
- "moduleResolution": "node",
10
+ "moduleResolution": "bundler",
10
11
  "esModuleInterop": true,
11
12
  "allowSyntheticDefaultImports": true,
12
13
  "strict": false,