@peter.naydenov/shortcuts 3.1.3 → 3.2.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 +7 -0
- package/README.md +64 -2
- package/dist/shortcuts.cjs +1 -1
- package/dist/shortcuts.esm.mjs +1 -1
- package/dist/shortcuts.umd.js +1 -1
- package/index.html +68 -16
- package/package.json +14 -12
- package/src/main.js +7 -4
- package/src/methods/changeContext.js +3 -1
- package/src/plugins/form/_defaults.js +18 -0
- package/src/plugins/form/_listenDOM.js +90 -0
- package/src/plugins/form/_normalizeShortcutName.js +21 -0
- package/src/plugins/form/_registerShortcutEvents.js +71 -0
- package/src/plugins/form/index.js +84 -0
- package/src/plugins/key/_listenDOM.js +1 -1
- package/test/01-general.test.js +299 -0
- package/test-components/Block.jsx +2 -0
- package/vitest-example/HelloWorld.js +9 -0
- package/vitest-example/HelloWorld.test.js +11 -0
- package/vitest.workspace.js +19 -0
- package/cypress/fixtures/example.json +0 -5
- package/cypress/support/commands.js +0 -25
- package/cypress/support/component-index.html +0 -14
- package/cypress/support/component.js +0 -27
- package/cypress/support/e2e.js +0 -20
- package/cypress.config.js +0 -10
- package/test/01-general.cy.js +0 -246
package/test/01-general.cy.js
DELETED
|
@@ -1,246 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import Block from '../test-components/Block.jsx'
|
|
3
|
-
import '../test-components/style.css'
|
|
4
|
-
import {
|
|
5
|
-
pluginClick,
|
|
6
|
-
pluginKey
|
|
7
|
-
, shortcuts
|
|
8
|
-
} from '../src/main.js'
|
|
9
|
-
import { expect } from 'chai'
|
|
10
|
-
|
|
11
|
-
import askForPromise from 'ask-for-promise'
|
|
12
|
-
|
|
13
|
-
let
|
|
14
|
-
a = false
|
|
15
|
-
, b = false
|
|
16
|
-
;
|
|
17
|
-
|
|
18
|
-
const short = shortcuts ({onShortcut : ( shortcut, {context,note,type}) => console.log (shortcut, context, note, type) });
|
|
19
|
-
|
|
20
|
-
short.load ({
|
|
21
|
-
general : {
|
|
22
|
-
' key : shift+a': [ () => a = true ]
|
|
23
|
-
}
|
|
24
|
-
, extra : {
|
|
25
|
-
'key:shift+a,p,r,o,b,a,ctrl+m' : () => b = true
|
|
26
|
-
}
|
|
27
|
-
})
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
describe ( 'Shortcuts', () => {
|
|
32
|
-
|
|
33
|
-
beforeEach ( () => {
|
|
34
|
-
cy.mount ( Block () )
|
|
35
|
-
a = false, b = false
|
|
36
|
-
}) // beforeEach
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
it ( 'Shortcut if no plugin installed', done => {
|
|
41
|
-
short.changeContext ( 'general' )
|
|
42
|
-
let r = short.listShortcuts ('general')
|
|
43
|
-
expect ( r[0]).to.equal ( ' key : shift+a' ) // Shortcut name is the same as it was set
|
|
44
|
-
done ()
|
|
45
|
-
}) // it no plugin installed
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
it ( 'Key plugin, no context selected', done => {
|
|
50
|
-
short.enablePlugin ( pluginKey )
|
|
51
|
-
const r = short.listShortcuts ( 'general' )
|
|
52
|
-
expect ( r[0] ).to.equal ( 'KEY:A+SHIFT' ) // Shortcut name is recognized by plugin and is normalized
|
|
53
|
-
done ()
|
|
54
|
-
}) // it key plugin installed, no context selected
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
it ( 'Key plugin with context selected', done => {
|
|
59
|
-
short.enablePlugin ( pluginKey )
|
|
60
|
-
short.changeContext ( 'general' )
|
|
61
|
-
const r = short.listShortcuts ('general')
|
|
62
|
-
expect ( r[0] ).to.equal ( 'KEY:A+SHIFT' ) // Shortcut name is recognized by plugin and is normalized
|
|
63
|
-
cy.wait ( 1 )
|
|
64
|
-
.then ( () => done () )
|
|
65
|
-
}) // it key plugin installed with context selected
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
it ( 'Simple shortcut', done => {
|
|
70
|
-
short.enablePlugin ( pluginKey )
|
|
71
|
-
short.changeContext ( )
|
|
72
|
-
short.changeContext ( 'general' )
|
|
73
|
-
cy.get('body').type ( '{shift}a' )
|
|
74
|
-
cy.wait ( 1 ) // Default wait sequence timeout is 480 ms, but maxSequence is 1, so we don't need to wait for timeout
|
|
75
|
-
.then ( () => {
|
|
76
|
-
expect ( a ).to.be.true
|
|
77
|
-
done ()
|
|
78
|
-
})
|
|
79
|
-
}) // it simple shortcut
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
it ( 'Call sequence shortcut', done => {
|
|
84
|
-
b = false
|
|
85
|
-
short.enablePlugin ( pluginKey )
|
|
86
|
-
short.changeContext ( 'general' )
|
|
87
|
-
short.changeContext ( 'extra' )
|
|
88
|
-
|
|
89
|
-
cy.get('body')
|
|
90
|
-
.type ( '{shift}a' )
|
|
91
|
-
.type ( 'proba' )
|
|
92
|
-
.type ( '{ctrl}M' )
|
|
93
|
-
|
|
94
|
-
cy.wait ( 1 ) // Default wait sequence timeout is 480 ms, but maxSequence is 1, so we don't need to wait for timeout
|
|
95
|
-
.then ( () => {
|
|
96
|
-
expect ( b ).to.be.true
|
|
97
|
-
done ()
|
|
98
|
-
})
|
|
99
|
-
}) // it call sequence shortcut
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
it ( 'Single mouse click', done => {
|
|
104
|
-
expect ( a ).to.be.false
|
|
105
|
-
expect ( b ).to.be.false
|
|
106
|
-
short.enablePlugin ( pluginClick )
|
|
107
|
-
|
|
108
|
-
short.load ({ 'extra' : {
|
|
109
|
-
' cLIck : left - 1 ' : () => a = true // Check if spaces, letter case can break the shortcut recognition
|
|
110
|
-
}
|
|
111
|
-
})
|
|
112
|
-
short.changeContext ( 'extra' )
|
|
113
|
-
cy.get('#rspan').click ()
|
|
114
|
-
cy.wait ( 10 ) // Default wait mouse timeout is 320 ms, but maxClicks is 1, so we don't need to wait for timeout
|
|
115
|
-
.then ( () => {
|
|
116
|
-
expect ( a ).to.be.true
|
|
117
|
-
})
|
|
118
|
-
cy.wait ( 1 ) // ...but mouseIgnore still active, so we better wait to not interfere with next test
|
|
119
|
-
.then ( () => done() )
|
|
120
|
-
}) // it mouse click
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
it ( 'Double mouse click', done => {
|
|
125
|
-
expect ( a ).to.be.false
|
|
126
|
-
expect ( b ).to.be.false
|
|
127
|
-
|
|
128
|
-
short.enablePlugin ( pluginClick )
|
|
129
|
-
short.changeContext ( 'extra' )
|
|
130
|
-
|
|
131
|
-
short.load ({
|
|
132
|
-
'extra' : { // load will overwrite existing 'extra' context definition
|
|
133
|
-
'click: left-2' : () => a = true
|
|
134
|
-
}
|
|
135
|
-
}) // load will restart the selected context
|
|
136
|
-
|
|
137
|
-
cy.get('#rspan').click().click ().click () // Third click is ignored. Max clicks according definition is 2.
|
|
138
|
-
cy.wait ( 1 ) // Default wait mouse timeout is 320 ms
|
|
139
|
-
.then ( () => {
|
|
140
|
-
expect ( a ).to.be.true
|
|
141
|
-
done ()
|
|
142
|
-
})
|
|
143
|
-
}) // it double mouse click
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
it ( 'Dependencies on shortcuts', done => {
|
|
148
|
-
const task = askForPromise ();
|
|
149
|
-
expect ( a ).to.be.false
|
|
150
|
-
expect ( b ).to.be.false
|
|
151
|
-
|
|
152
|
-
short.enablePlugin ( pluginClick )
|
|
153
|
-
short.setDependencies ({ task })
|
|
154
|
-
|
|
155
|
-
short.load ({
|
|
156
|
-
'extra' : { // load will overwrite existing 'extra' context definition
|
|
157
|
-
'click: left-1' : ({dependencies}) => {
|
|
158
|
-
const { task } = dependencies;
|
|
159
|
-
expect ( task ).to.have.property ( 'done' )
|
|
160
|
-
expect ( task ).to.have.property ( 'promise' )
|
|
161
|
-
a = true
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
}) // load will restart the selected context
|
|
165
|
-
|
|
166
|
-
short.changeContext ( 'extra' )
|
|
167
|
-
cy.get('#rspan').click ()
|
|
168
|
-
cy.wait ( 350 ) // Default wait mouse timeout is 320 ms
|
|
169
|
-
.then ( () => {
|
|
170
|
-
expect ( a ).to.be.true
|
|
171
|
-
done ()
|
|
172
|
-
})
|
|
173
|
-
}) // it dependencies on shortcuts
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
it ( 'Emit custom event', done => {
|
|
178
|
-
let result = null;
|
|
179
|
-
short.changeContext ()
|
|
180
|
-
short.enablePlugin ( pluginClick )
|
|
181
|
-
const myAllContext = {
|
|
182
|
-
myAll: {
|
|
183
|
-
'click : leff-1' : () => console.log ( 'nothing' )
|
|
184
|
-
, 'yo' : ({msg}) => result = msg
|
|
185
|
-
}}
|
|
186
|
-
short.load ( myAllContext )
|
|
187
|
-
short.changeContext ( 'myAll' )
|
|
188
|
-
short.emit ( 'yo', { context: short.getContext(), note: 'tt', type:'custom', msg:'hello' })
|
|
189
|
-
expect ( result ).to.be.equal ( 'hello' )
|
|
190
|
-
short.changeContext ( 'general' )
|
|
191
|
-
short.unload ( 'myAll' )
|
|
192
|
-
done ()
|
|
193
|
-
}) // it emit custom event
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
it ( 'List shortcuts', () => {
|
|
198
|
-
let general = short.listShortcuts ('general');
|
|
199
|
-
expect ( general ).to.be.an('array')
|
|
200
|
-
expect ( general ).to.have.lengthOf ( 1 )
|
|
201
|
-
expect ( general[0] ).to.be.equal ( 'KEY:A+SHIFT' )
|
|
202
|
-
|
|
203
|
-
let fail = short.listShortcuts ('somethingNotExisting');
|
|
204
|
-
expect ( fail ).to.be.null
|
|
205
|
-
|
|
206
|
-
let all = short.listShortcuts ();
|
|
207
|
-
expect ( all ).to.be.an('array')
|
|
208
|
-
|
|
209
|
-
expect ( all ).to.have.lengthOf ( 2 )
|
|
210
|
-
expect ( all[0] ).to.have.property ( 'context' )
|
|
211
|
-
expect ( all[0] ).to.have.property ( 'shortcuts' )
|
|
212
|
-
expect ( all[0].shortcuts ).to.be.an('array')
|
|
213
|
-
expect ( all[0].shortcuts ).to.have.lengthOf ( 1 )
|
|
214
|
-
expect ( all[0].shortcuts[0] ).to.be.equal ( 'KEY:A+SHIFT' )
|
|
215
|
-
expect ( all[0].context ).to.be.equal ( 'general' )
|
|
216
|
-
}) // it list shortcuts
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
it ( 'Click on anchor', done => {
|
|
221
|
-
// Click on anchor that don't have click-data attribute.
|
|
222
|
-
let result = 'none';
|
|
223
|
-
short.load ({ 'extra' : {
|
|
224
|
-
'click: 1 - left' : ({target, context, event }) => { // Order of button name and number of click is not important
|
|
225
|
-
event.preventDefault ()
|
|
226
|
-
expect ( context ).to.be.equal ( 'extra' )
|
|
227
|
-
expect ( target.nodeName ).to.be.equal ( 'A' )
|
|
228
|
-
result = target.nodeName
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
})
|
|
232
|
-
short.changeContext ( 'extra' )
|
|
233
|
-
cy.get ( '#anchor' ).click ()
|
|
234
|
-
cy.wait ( 3 ) // Consider mouse click has some latency
|
|
235
|
-
// According Cypress documentation:
|
|
236
|
-
// It is unsafe to chain further commands that rely on the subject after .click().
|
|
237
|
-
// source docs: https://docs.cypress.io/api/commands/click
|
|
238
|
-
.then ( () => {
|
|
239
|
-
short.changeContext ( 'general' )
|
|
240
|
-
expect ( result ).to.be.equal ( 'A' )
|
|
241
|
-
done ()
|
|
242
|
-
})
|
|
243
|
-
}) // it click on anchor
|
|
244
|
-
}) // describe
|
|
245
|
-
|
|
246
|
-
|