@peter.naydenov/shortcuts 3.5.2 → 4.0.0

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 (98) hide show
  1. package/API.md +939 -0
  2. package/CODE_OF_CONDUCT.md +84 -0
  3. package/CONTRIBUTING.md +476 -0
  4. package/Changelog.md +26 -2
  5. package/How.to.create.plugins.md +929 -0
  6. package/Migration.guide.md +48 -0
  7. package/README.md +396 -24
  8. package/dist/main.d.ts +54 -2
  9. package/dist/methods/_normalizeWithPlugins.d.ts +63 -1
  10. package/dist/methods/_readShortcutWithPlugins.d.ts +8 -1
  11. package/dist/methods/_setupPlugin.d.ts +9 -0
  12. package/dist/methods/_systemAction.d.ts +8 -1
  13. package/dist/methods/changeContext.d.ts +8 -1
  14. package/dist/methods/index.d.ts +2 -0
  15. package/dist/methods/listShortcuts.d.ts +1 -16
  16. package/dist/methods/load.d.ts +8 -1
  17. package/dist/methods/unload.d.ts +8 -1
  18. package/dist/plugins/click/_findTarget.d.ts +9 -1
  19. package/dist/plugins/click/_listenDOM.d.ts +76 -3
  20. package/dist/plugins/click/_normalizeShortcutName.d.ts +7 -1
  21. package/dist/plugins/click/_registerShortcutEvents.d.ts +26 -0
  22. package/dist/plugins/click/index.d.ts +6 -31
  23. package/dist/plugins/form/_defaults.d.ts +13 -1
  24. package/dist/plugins/form/_listenDOM.d.ts +66 -3
  25. package/dist/plugins/form/_registerShortcutEvents.d.ts +95 -1
  26. package/dist/plugins/form/index.d.ts +2 -29
  27. package/dist/plugins/hover/_findTarget.d.ts +10 -0
  28. package/dist/plugins/hover/_listenDOM.d.ts +68 -0
  29. package/dist/plugins/hover/_normalizeShortcutName.d.ts +2 -0
  30. package/dist/plugins/hover/_registerShortcutEvents.d.ts +28 -0
  31. package/dist/plugins/hover/index.d.ts +14 -0
  32. package/dist/plugins/key/_listenDOM.d.ts +61 -3
  33. package/dist/plugins/key/_registerShortcutEvents.d.ts +26 -0
  34. package/dist/plugins/key/_specialChars.d.ts +6 -31
  35. package/dist/plugins/key/index.d.ts +2 -29
  36. package/dist/plugins/scroll/_listenDOM.d.ts +58 -0
  37. package/dist/plugins/scroll/_normalizeShortcutName.d.ts +2 -0
  38. package/dist/plugins/scroll/_registerShortcutEvents.d.ts +28 -0
  39. package/dist/plugins/scroll/index.d.ts +16 -0
  40. package/dist/shortcuts.cjs +1 -1
  41. package/dist/shortcuts.esm.mjs +1 -1
  42. package/dist/shortcuts.umd.js +1 -1
  43. package/eslint.config.js +80 -0
  44. package/html/assets/index-COTh6lXR.css +1 -0
  45. package/html/assets/index-DOkKC3NI.js +53 -0
  46. package/html/bg.png +0 -0
  47. package/html/favicon.ico +0 -0
  48. package/html/favicon.svg +5 -0
  49. package/html/html.meta.json.gz +0 -0
  50. package/html/index.html +32 -0
  51. package/package.json +16 -12
  52. package/shortcuts.png +0 -0
  53. package/src/main.js +52 -22
  54. package/src/methods/_normalizeWithPlugins.js +26 -2
  55. package/src/methods/_readShortcutWithPlugins.js +9 -2
  56. package/src/methods/_setupPlugin.js +93 -0
  57. package/src/methods/_systemAction.js +12 -4
  58. package/src/methods/changeContext.js +11 -3
  59. package/src/methods/index.js +2 -0
  60. package/src/methods/listShortcuts.js +5 -12
  61. package/src/methods/load.js +11 -4
  62. package/src/methods/unload.js +8 -1
  63. package/src/plugins/click/_findTarget.js +11 -5
  64. package/src/plugins/click/_listenDOM.js +58 -20
  65. package/src/plugins/click/_normalizeShortcutName.js +11 -4
  66. package/src/plugins/click/_readClickEvent.js +1 -1
  67. package/src/plugins/click/_registerShortcutEvents.js +33 -5
  68. package/src/plugins/click/index.js +33 -60
  69. package/src/plugins/form/_defaults.js +13 -3
  70. package/src/plugins/form/_listenDOM.js +46 -9
  71. package/src/plugins/form/_normalizeShortcutName.js +2 -2
  72. package/src/plugins/form/_registerShortcutEvents.js +93 -17
  73. package/src/plugins/form/index.js +25 -56
  74. package/src/plugins/hover/_findTarget.js +26 -0
  75. package/src/plugins/hover/_listenDOM.js +154 -0
  76. package/src/plugins/hover/_normalizeShortcutName.js +21 -0
  77. package/src/plugins/hover/_registerShortcutEvents.js +51 -0
  78. package/src/plugins/hover/index.js +71 -0
  79. package/src/plugins/key/_listenDOM.js +67 -33
  80. package/src/plugins/key/_normalizeShortcutName.js +4 -3
  81. package/src/plugins/key/_readKeyEvent.js +1 -1
  82. package/src/plugins/key/_registerShortcutEvents.js +34 -5
  83. package/src/plugins/key/_specialChars.js +5 -0
  84. package/src/plugins/key/index.js +34 -59
  85. package/src/plugins/scroll/_listenDOM.js +141 -0
  86. package/src/plugins/scroll/_normalizeShortcutName.js +21 -0
  87. package/src/plugins/scroll/_registerShortcutEvents.js +50 -0
  88. package/src/plugins/scroll/index.js +61 -0
  89. package/test/01-general.test.js +92 -23
  90. package/test/02-key.test.js +241 -40
  91. package/test/03-click.test.js +291 -47
  92. package/test/04-form.test.js +241 -47
  93. package/test/05-hover.test.js +463 -0
  94. package/test/06-scroll.test.js +374 -0
  95. package/test-helpers/Block.jsx +3 -2
  96. package/test-helpers/style.css +6 -1
  97. package/vitest.config.js +13 -11
  98. package/How..to.make.plugins.md +0 -41
@@ -1,2 +1,64 @@
1
1
  export default _normalizeWithPlugins;
2
- declare function _normalizeWithPlugins(dependencies: any, state: any): (_normalizeShortcutName: Function) => void;
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;
@@ -1,2 +1,9 @@
1
1
  export default _readShortcutWithPlugins;
2
- declare function _readShortcutWithPlugins(dependencies: any, state: any): (shortcut: string) => string;
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;
@@ -1,2 +1,9 @@
1
1
  export default _systemAction;
2
- declare function _systemAction(dependencies: any, state: any): (pluginName: string, fn: string, params?: any) => any;
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;
@@ -1,2 +1,9 @@
1
1
  export default changeContext;
2
- declare function changeContext(dependencies: any, state: any): (contextName?: string) => void;
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;
@@ -1,6 +1,7 @@
1
1
  declare namespace _default {
2
2
  export { _normalizeWithPlugins };
3
3
  export { _readShortcutWithPlugins };
4
+ export { _setupPlugin };
4
5
  export { _systemAction };
5
6
  export { changeContext };
6
7
  export { listShortcuts };
@@ -10,6 +11,7 @@ declare namespace _default {
10
11
  export default _default;
11
12
  import _normalizeWithPlugins from './_normalizeWithPlugins.js';
12
13
  import _readShortcutWithPlugins from './_readShortcutWithPlugins.js';
14
+ import _setupPlugin from './_setupPlugin.js';
13
15
  import _systemAction from './_systemAction.js';
14
16
  import changeContext from './changeContext.js';
15
17
  import listShortcuts from './listShortcuts.js';
@@ -1,17 +1,2 @@
1
1
  export default listShortcuts;
2
- export type contextShortcuts = {
3
- /**
4
- * - Context name
5
- */
6
- context: string;
7
- /**
8
- * - List of shortcuts in a context
9
- */
10
- shortcuts: string[];
11
- };
12
- /**
13
- * @typedef {object} contextShortcuts
14
- * @property {string} context - Context name
15
- * @property {string[]} shortcuts - List of shortcuts in a context
16
- */
17
- declare function listShortcuts(dependencies: any, state: any): (contextName?: string) => string[] | contextShortcuts[];
2
+ declare function listShortcuts(dependencies: any, state: any): (contextName?: string | null) => string[] | contextShortcuts[] | null;
@@ -1,2 +1,9 @@
1
1
  export default load;
2
- declare function load(dependencies: any, state: any): (shortcutsUpdate: any) => void;
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;
@@ -1,2 +1,9 @@
1
1
  export default unload;
2
- declare function unload(dependencies: any, state: any): (contextName: string) => void;
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;
@@ -1,2 +1,10 @@
1
1
  export default _findTarget;
2
- declare function _findTarget(dependencies: any, state: any, target: any): any;
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;
@@ -1,5 +1,78 @@
1
1
  export default _listenDOM;
2
- declare function _listenDOM(dependencies: any, state: any): {
3
- start: () => void;
4
- stop: () => void;
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;
5
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;
@@ -1,2 +1,8 @@
1
1
  export default _normalizeShortcutName;
2
- declare function _normalizeShortcutName(name: any): any;
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;
@@ -1,2 +1,28 @@
1
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
+ */
2
28
  declare function _registerShortcutEvents(dependencies: any, pluginState: any): number;
@@ -1,41 +1,16 @@
1
1
  export default pluginClick;
2
- export type PluginAPI = {
3
- /**
4
- * - Get plugin prefix
5
- */
6
- getPrefix: () => string;
7
- /**
8
- * - Format shortcut name
9
- */
10
- shortcutName: (arg0: string) => string;
11
- /**
12
- * - Handle context change
13
- */
14
- contextChange: (arg0: string) => void;
15
- /**
16
- * - Mute the plugin
17
- */
18
- mute: () => void;
19
- /**
20
- * - Unmute the plugin
21
- */
22
- unmute: () => void;
23
- /**
24
- * - Destroy the plugin
25
- */
26
- destroy: () => void;
27
- };
28
2
  /**
29
3
  * @function pluginClick
30
4
  * @description Plugin for mouse click shortcuts
31
- * @param {Object} dependencies - Internal dependencies
32
- * @param {Object} state - Library state
5
+ * @param {function} setupPlugin - Plugin setup function from the library
33
6
  * @param {Object} [options={}] - Plugin options
34
7
  * @param {number} [options.mouseWait=320] - Time to wait for click sequence in ms
35
- * @param {string} [options.clickTarget='click'] - Data attribute name for click targets
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
36
10
  * @returns {PluginAPI} Plugin API
37
11
  */
38
- declare function pluginClick(dependencies: any, state: any, options?: {
12
+ declare function pluginClick(setupPlugin: Function, options?: {
39
13
  mouseWait?: number;
40
- clickTarget?: string;
14
+ clickTarget?: string[];
15
+ streamKeys?: Function;
41
16
  }): PluginAPI;
@@ -1,5 +1,17 @@
1
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
+ };
2
12
  declare namespace _defaults {
3
13
  function watch(): string;
4
- function define(el: any): "input" | "checkbox" | "button";
14
+ function define({ target }: {
15
+ target: any;
16
+ }): "input" | "checkbox" | "button";
5
17
  }
@@ -1,5 +1,68 @@
1
1
  export default _listenDOM;
2
- declare function _listenDOM(dependencies: any, state: any): {
3
- start: () => void;
4
- stop: () => void;
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;
5
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;
@@ -1,2 +1,96 @@
1
1
  export default _registerShortcutEvents;
2
- declare function _registerShortcutEvents(dependencies: any, pluginState: any): boolean;
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;
@@ -1,36 +1,9 @@
1
1
  export default pluginForm;
2
- export type PluginAPI = {
3
- /**
4
- * - Get plugin prefix
5
- */
6
- getPrefix: () => string;
7
- /**
8
- * - Format shortcut name
9
- */
10
- shortcutName: (arg0: string) => string;
11
- /**
12
- * - Handle context change
13
- */
14
- contextChange: (arg0: string) => void;
15
- /**
16
- * - Mute the plugin
17
- */
18
- mute: () => void;
19
- /**
20
- * - Unmute the plugin
21
- */
22
- unmute: () => void;
23
- /**
24
- * - Destroy the plugin
25
- */
26
- destroy: () => void;
27
- };
28
2
  /**
29
3
  * @function pluginForm
30
4
  * @description Plugin for form element shortcuts
31
- * @param {Object} dependencies - Internal dependencies
32
- * @param {Object} state - Library state
5
+ * @param {function} setupPlugin - Plugin setup function from the library
33
6
  * @param {Object} [options={}] - Plugin options
34
7
  * @returns {PluginAPI} Plugin API
35
8
  */
36
- declare function pluginForm(dependencies: any, state: any, options?: any): PluginAPI;
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;