@peter.naydenov/shortcuts 1.0.1 → 1.1.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.
- package/Changelog.md +3 -0
- package/README.md +9 -0
- package/package.json +4 -4
- package/src/changeContext.js +0 -4
- package/src/main.js +2 -0
- package/test/01-general.cy.js +17 -0
package/Changelog.md
CHANGED
package/README.md
CHANGED
|
@@ -3,10 +3,18 @@
|
|
|
3
3
|

|
|
4
4
|

|
|
5
5
|
|
|
6
|
+
|
|
7
|
+
|
|
6
8
|
Define a context based keyboard-shortcuts and describe a mouse clicks. Switch among contexts.
|
|
7
9
|
|
|
8
10
|
|
|
9
11
|
|
|
12
|
+
|
|
13
|
+
## What's new?
|
|
14
|
+
Version 1.1.0 is coming with new method `emit` that make possible to trigger context functions also programmatically. In `shortcuts` you can mix keyboard, mouse and programmatical events that is prity everything that can happen in a web page.
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
10
18
|
## Shortcut Description Rules
|
|
11
19
|
The shortcuts definition includes a context name and a set of rules(object). The rules are a set of key-value pairs. The key is a shortcut name and the value is a function or array of functions, to be executed when the shortcut is triggered (action function).
|
|
12
20
|
|
|
@@ -233,6 +241,7 @@ Description of the methods of shortcut instance:
|
|
|
233
241
|
load : 'Load and extend a shortcut definition.'
|
|
234
242
|
, unload : 'Remove a shortcut context with all its shortcuts.'
|
|
235
243
|
, changeContext : 'Switch to existing shortcut context.'
|
|
244
|
+
, emit : 'Trigger a shortcut or custom event programmatically.'
|
|
236
245
|
, pause : 'Stop listening for shortcuts.'
|
|
237
246
|
, resume : 'Resume listening for shortcuts.'
|
|
238
247
|
, listContexts : 'Return list of available contexts.'
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@peter.naydenov/shortcuts",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "Context control of shortcuts based on keyboard and mouse events",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"shortcut",
|
|
@@ -24,9 +24,9 @@
|
|
|
24
24
|
"@peter.naydenov/notice": "^2.2.1"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
|
-
"@vitejs/plugin-react": "^4.0
|
|
28
|
-
"chai": "^4.3.
|
|
29
|
-
"cypress": "^13.
|
|
27
|
+
"@vitejs/plugin-react": "^4.1.0",
|
|
28
|
+
"chai": "^4.3.10",
|
|
29
|
+
"cypress": "^13.3.0",
|
|
30
30
|
"mocha": "^10.2.0",
|
|
31
31
|
"react": "^18.2.0",
|
|
32
32
|
"react-dom": "^18.2.0",
|
package/src/changeContext.js
CHANGED
package/src/main.js
CHANGED
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
* History notes:
|
|
10
10
|
* - Development was started on June 21st, 2023
|
|
11
11
|
* - First version was published on August 14th, 2023
|
|
12
|
+
* - Method 'emit' was added on September 30st, 2023
|
|
12
13
|
*/
|
|
13
14
|
|
|
14
15
|
|
|
@@ -67,6 +68,7 @@ function main ( options = {} ) {
|
|
|
67
68
|
, changeContext : changeContext ( shortcuts, listenOptions, ev, currentContext )
|
|
68
69
|
, pause : () => ev.stop ()
|
|
69
70
|
, resume : () => ev.start ()
|
|
71
|
+
, emit : (x,...args) => ev.emit ( readShortcut(x), ...args )
|
|
70
72
|
, listContexts : () => Object.keys ( shortcuts )
|
|
71
73
|
, getContext
|
|
72
74
|
, getNote
|
package/test/01-general.cy.js
CHANGED
|
@@ -26,6 +26,8 @@ beforeEach ( () => {
|
|
|
26
26
|
a = false, b = false
|
|
27
27
|
}) // beforeEach
|
|
28
28
|
|
|
29
|
+
|
|
30
|
+
|
|
29
31
|
it ( 'Simple shortcut', done => {
|
|
30
32
|
let res = false;
|
|
31
33
|
short.changeContext ( 'general' )
|
|
@@ -108,4 +110,19 @@ it ( 'Double mouse click', done => {
|
|
|
108
110
|
})
|
|
109
111
|
}) // it double mouse click
|
|
110
112
|
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
it ( 'Emit custom event', () => {
|
|
116
|
+
let result = null;
|
|
117
|
+
const myAllContext = {
|
|
118
|
+
myAll: {
|
|
119
|
+
'mouse-click-leff-1' : () => console.log ( 'nothing' )
|
|
120
|
+
, 'yo' : r => result = r
|
|
121
|
+
}}
|
|
122
|
+
short.load ( myAllContext )
|
|
123
|
+
short.changeContext ( 'myAll' )
|
|
124
|
+
short.emit ( 'yo', 'hello' )
|
|
125
|
+
expect ( result ).to.be.equal ( 'hello' )
|
|
126
|
+
}) // it emit custom event
|
|
127
|
+
|
|
111
128
|
}) // describe
|