@peter.naydenov/shortcuts 1.0.1 → 1.1.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/Changelog.md +13 -0
- package/README.md +11 -1
- package/package.json +5 -4
- package/src/changeContext.js +0 -4
- package/src/listen.js +7 -7
- package/src/main.js +2 -0
- package/test/01-general.cy.js +22 -6
package/Changelog.md
CHANGED
|
@@ -1,10 +1,23 @@
|
|
|
1
1
|
## Release History
|
|
2
2
|
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
### 1.1.1 (2023-09-30)
|
|
6
|
+
- [x] Mouse faster response when maxClicks achived. (maxClicks is automatically calculated according shortcut definitions);
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
### 1.1.0 (2023-09-30)
|
|
11
|
+
- [x] Method `emit` was added. Not documented yet;
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
3
15
|
### 1.0.1 (2023-09-23)
|
|
4
16
|
- [x] Mouse click: preventDefault();
|
|
5
17
|
- [x] Dependencies update: @peter.naydenov/notice - v.2.2.1
|
|
6
18
|
|
|
7
19
|
|
|
20
|
+
|
|
8
21
|
### 1.0.0 (2023-08-14)
|
|
9
22
|
|
|
10
23
|
- [x] Initial code;
|
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
|
|
|
@@ -14,7 +22,7 @@ The shortcuts definition includes a context name and a set of rules(object). The
|
|
|
14
22
|
// { context: { shortcutName: actionFunction } }
|
|
15
23
|
// or
|
|
16
24
|
// { context: { shortcutName: [ actionFunction1, actionFunction2 ] }}
|
|
17
|
-
|
|
25
|
+
|
|
18
26
|
// Shortcut definition object:
|
|
19
27
|
{
|
|
20
28
|
contextName : {
|
|
@@ -32,6 +40,7 @@ The shortcuts definition includes a context name and a set of rules(object). The
|
|
|
32
40
|
}
|
|
33
41
|
}
|
|
34
42
|
```
|
|
43
|
+
|
|
35
44
|
Load a shortcut definition by calling `load` method.
|
|
36
45
|
|
|
37
46
|
```js
|
|
@@ -233,6 +242,7 @@ Description of the methods of shortcut instance:
|
|
|
233
242
|
load : 'Load and extend a shortcut definition.'
|
|
234
243
|
, unload : 'Remove a shortcut context with all its shortcuts.'
|
|
235
244
|
, changeContext : 'Switch to existing shortcut context.'
|
|
245
|
+
, emit : 'Trigger a shortcut or custom event programmatically.'
|
|
236
246
|
, pause : 'Stop listening for shortcuts.'
|
|
237
247
|
, resume : 'Resume listening for shortcuts.'
|
|
238
248
|
, 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.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"description": "Context control of shortcuts based on keyboard and mouse events",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"shortcut",
|
|
@@ -24,9 +24,10 @@
|
|
|
24
24
|
"@peter.naydenov/notice": "^2.2.1"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
|
-
"@vitejs/plugin-react": "^4.0
|
|
28
|
-
"
|
|
29
|
-
"
|
|
27
|
+
"@vitejs/plugin-react": "^4.1.0",
|
|
28
|
+
"ask-for-promise": "^1.3.1",
|
|
29
|
+
"chai": "^4.3.10",
|
|
30
|
+
"cypress": "^13.3.0",
|
|
30
31
|
"mocha": "^10.2.0",
|
|
31
32
|
"react": "^18.2.0",
|
|
32
33
|
"react-dom": "^18.2.0",
|
package/src/changeContext.js
CHANGED
package/src/listen.js
CHANGED
|
@@ -100,14 +100,14 @@ function listen ( dependencies, options, currentContext ) { // Listen for inpu
|
|
|
100
100
|
mouseIgnore = setTimeout ( () => mouseIgnore=null, mouseWait )
|
|
101
101
|
return
|
|
102
102
|
}
|
|
103
|
+
mouseTarget = findTarget (event.target, clickTarget )
|
|
104
|
+
mouseDomEvent = event
|
|
105
|
+
count++
|
|
103
106
|
if ( count === options.maxClicks ) {
|
|
104
107
|
mouseSequenceEnd ()
|
|
105
108
|
mouseIgnore = setTimeout ( () => mouseIgnore=null, mouseWait )
|
|
106
109
|
return
|
|
107
110
|
}
|
|
108
|
-
mouseTarget = findTarget (event.target, clickTarget )
|
|
109
|
-
mouseDomEvent = event
|
|
110
|
-
count++
|
|
111
111
|
mouseTimer = setTimeout ( mouseSequenceEnd, mouseWait )
|
|
112
112
|
})
|
|
113
113
|
|
|
@@ -119,14 +119,14 @@ function listen ( dependencies, options, currentContext ) { // Listen for inpu
|
|
|
119
119
|
mouseIgnore = setTimeout ( () => mouseIgnore=null, mouseWait )
|
|
120
120
|
return
|
|
121
121
|
}
|
|
122
|
-
|
|
122
|
+
mouseTarget = findTarget ( event.target, clickTarget )
|
|
123
|
+
mouseDomEvent = event
|
|
124
|
+
count++
|
|
125
|
+
if ( count >= options.maxClicks ) {
|
|
123
126
|
mouseSequenceEnd ()
|
|
124
127
|
mouseIgnore = setTimeout ( () => mouseIgnore=null, mouseWait )
|
|
125
128
|
return
|
|
126
129
|
}
|
|
127
|
-
mouseTarget = findTarget ( event.target, clickTarget )
|
|
128
|
-
mouseDomEvent = event
|
|
129
|
-
count++
|
|
130
130
|
mouseTimer = setTimeout ( mouseSequenceEnd, mouseWait )
|
|
131
131
|
})
|
|
132
132
|
} // listenMouse func.
|
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,11 +26,13 @@ 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' )
|
|
32
34
|
cy.get('body').type ( '{shift}a' )
|
|
33
|
-
cy.wait (
|
|
35
|
+
cy.wait ( 30 ) // Default wait sequence timeout is 480 ms, but maxSequence is 1, so we don't need to wait for timeout
|
|
34
36
|
.then ( () => {
|
|
35
37
|
expect ( a ).to.be.true
|
|
36
38
|
done ()
|
|
@@ -79,11 +81,10 @@ it ( 'Single mouse click', done => {
|
|
|
79
81
|
})
|
|
80
82
|
short.changeContext ( 'extra' )
|
|
81
83
|
cy.get('#rspan').click ()
|
|
82
|
-
cy.wait (
|
|
83
|
-
.then ( () =>
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
})
|
|
84
|
+
cy.wait ( 10 ) // Default wait mouse timeout is 320 ms, but maxClicks is 1, so we don't need to wait for timeout
|
|
85
|
+
.then ( () => expect ( a ).to.be.true )
|
|
86
|
+
cy.wait ( 300 ) // ...but mouseIgnore still active, so we better wait to not interfere with next test
|
|
87
|
+
.then ( () => done() )
|
|
87
88
|
}) // it mouse click
|
|
88
89
|
|
|
89
90
|
|
|
@@ -108,4 +109,19 @@ it ( 'Double mouse click', done => {
|
|
|
108
109
|
})
|
|
109
110
|
}) // it double mouse click
|
|
110
111
|
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
it ( 'Emit custom event', () => {
|
|
115
|
+
let result = null;
|
|
116
|
+
const myAllContext = {
|
|
117
|
+
myAll: {
|
|
118
|
+
'mouse-click-leff-1' : () => console.log ( 'nothing' )
|
|
119
|
+
, 'yo' : r => result = r
|
|
120
|
+
}}
|
|
121
|
+
short.load ( myAllContext )
|
|
122
|
+
short.changeContext ( 'myAll' )
|
|
123
|
+
short.emit ( 'yo', 'hello' )
|
|
124
|
+
expect ( result ).to.be.equal ( 'hello' )
|
|
125
|
+
}) // it emit custom event
|
|
126
|
+
|
|
111
127
|
}) // describe
|