@peter.naydenov/shortcuts 3.4.0 → 3.5.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 +6 -0
- package/README.md +2 -0
- package/dist/main.d.ts +120 -0
- package/dist/methods/_normalizeWithPlugins.d.ts +2 -0
- package/dist/methods/_readShortcutWithPlugins.d.ts +2 -0
- package/dist/methods/_systemAction.d.ts +2 -0
- package/dist/methods/changeContext.d.ts +2 -0
- package/dist/methods/index.d.ts +17 -0
- package/dist/methods/listShortcuts.d.ts +17 -0
- package/dist/methods/load.d.ts +2 -0
- package/dist/methods/unload.d.ts +2 -0
- package/dist/plugins/click/_findTarget.d.ts +2 -0
- package/dist/plugins/click/_listenDOM.d.ts +5 -0
- package/dist/plugins/click/_normalizeShortcutName.d.ts +2 -0
- package/dist/plugins/click/_readClickEvent.d.ts +2 -0
- package/dist/plugins/click/_registerShortcutEvents.d.ts +2 -0
- package/dist/plugins/click/index.d.ts +15 -0
- package/dist/plugins/form/_defaults.d.ts +5 -0
- package/dist/plugins/form/_listenDOM.d.ts +5 -0
- package/dist/plugins/form/_normalizeShortcutName.d.ts +2 -0
- package/dist/plugins/form/_registerShortcutEvents.d.ts +2 -0
- package/dist/plugins/form/index.d.ts +10 -0
- package/dist/plugins/key/_listenDOM.d.ts +5 -0
- package/dist/plugins/key/_normalizeShortcutName.d.ts +2 -0
- package/dist/plugins/key/_readKeyEvent.d.ts +2 -0
- package/dist/plugins/key/_registerShortcutEvents.d.ts +2 -0
- package/dist/plugins/key/_specialChars.d.ts +32 -0
- package/dist/plugins/key/index.d.ts +15 -0
- package/dist/shortcuts.cjs +1 -1
- package/dist/shortcuts.esm.mjs +1 -1
- package/dist/shortcuts.umd.js +1 -1
- package/package.json +6 -3
- package/src/main.js +74 -20
- package/src/methods/changeContext.js +2 -1
- package/src/methods/load.js +4 -3
- package/src/methods/unload.js +3 -3
- package/src/plugins/click/_listenDOM.js +1 -1
- package/src/plugins/click/index.js +10 -0
- package/src/plugins/form/index.js +8 -13
- package/src/plugins/key/index.js +10 -0
- package/test/01-general.test.js +64 -5
- package/test/02-key.test.js +136 -38
- package/test/03-click.test.js +88 -56
- package/tsconfig.json +23 -0
package/test/03-click.test.js
CHANGED
|
@@ -256,65 +256,97 @@ describe ( 'Click plugin', () => {
|
|
|
256
256
|
|
|
257
257
|
|
|
258
258
|
it ( 'Click on anchor', async () => {
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
259
|
+
// Click on anchor that don't have click-data attribute.
|
|
260
|
+
let result = 'none';
|
|
261
|
+
short.enablePlugin ( pluginClick )
|
|
262
|
+
short.load ({ 'extra' : {
|
|
263
|
+
'click: 1 - left' : ({target, context, event }) => { // Order of button name and number of click is not important
|
|
264
|
+
event.preventDefault ()
|
|
265
|
+
expect ( context ).to.be.equal ( 'extra' )
|
|
266
|
+
expect ( target.nodeName ).to.be.equal ( 'A' )
|
|
267
|
+
result = target.nodeName
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
})
|
|
271
|
+
short.changeContext ( 'extra' )
|
|
272
|
+
let loc = document.querySelector ( '#anchor' ) || false;
|
|
273
|
+
if ( loc ) await userEvent.click ( loc )
|
|
274
|
+
expect ( result ).to.be.equal ( 'A' )
|
|
275
275
|
}) // it click on anchor
|
|
276
276
|
|
|
277
277
|
|
|
278
278
|
|
|
279
|
-
it ( 'Mute click plugin', async () => {
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
279
|
+
it ( 'Mute and unmute click plugin', async () => {
|
|
280
|
+
const
|
|
281
|
+
result = []
|
|
282
|
+
, trg = document.querySelector ( '#rspan' )
|
|
283
|
+
;
|
|
284
|
+
|
|
285
|
+
let i = 0;
|
|
286
|
+
result.push ( 'init' )
|
|
287
|
+
|
|
288
|
+
|
|
289
|
+
short.load ({
|
|
290
|
+
'local' : {
|
|
291
|
+
'click: left-1 ' : ({dependencies}) => {
|
|
292
|
+
let { result } = dependencies;
|
|
293
|
+
result.push ( i++ )
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
})
|
|
297
|
+
short.setDependencies ({ result })
|
|
298
|
+
short.enablePlugin ( pluginClick )
|
|
299
|
+
short.changeContext ( 'local' )
|
|
300
|
+
|
|
301
|
+
|
|
302
|
+
await userEvent.click ( trg )
|
|
303
|
+
await wait( 330 )
|
|
304
|
+
await waitFor ( () => {
|
|
305
|
+
// We checking if the shortcut works
|
|
306
|
+
expect ( result ).to.have.lengthOf ( 2 )
|
|
307
|
+
expect ( i ).to.equal ( 1 )
|
|
308
|
+
}, { timeout: 1000, interval: 12 })
|
|
309
|
+
|
|
310
|
+
short.mutePlugin ( 'click' )
|
|
311
|
+
|
|
312
|
+
await userEvent.click ( trg )
|
|
313
|
+
await waitFor ( () => {
|
|
314
|
+
// Plugin is muted, so we don't expect any changes
|
|
315
|
+
expect ( result ).to.have.lengthOf ( 2 )
|
|
316
|
+
expect ( i ).to.equal ( 1 )
|
|
317
|
+
}, { timeout: 1000, interval: 12 })
|
|
318
|
+
|
|
319
|
+
short.unmutePlugin ( 'click' )
|
|
320
|
+
|
|
321
|
+
await userEvent.click ( trg )
|
|
322
|
+
await wait ( 330 )
|
|
323
|
+
await waitFor ( () => {
|
|
324
|
+
// Plugin is unmuted, should work again
|
|
325
|
+
expect ( result ).to.have.lengthOf ( 3 )
|
|
326
|
+
expect ( i ).to.equal ( 2 )
|
|
327
|
+
}, { timeout: 1000, interval: 12 })
|
|
328
|
+
}) // it mute and unmute click plugin
|
|
329
|
+
|
|
330
|
+
|
|
331
|
+
|
|
332
|
+
it ( 'Pause and resume', async () => {
|
|
333
|
+
let target = document.querySelector ( '#rspan' )
|
|
334
|
+
short.enablePlugin ( pluginClick )
|
|
335
|
+
expect ( b ).to.be.equal ( false )
|
|
336
|
+
short.changeContext ( 'touch' )
|
|
337
|
+
short.pause ( 'click: left-1' )
|
|
338
|
+
await userEvent.click ( target )
|
|
339
|
+
await wait ( 400 )
|
|
340
|
+
await waitFor ( () => {
|
|
341
|
+
expect ( b ).to.be.equal ( false )
|
|
342
|
+
}, { timeout: 1000, interval: 30 })
|
|
343
|
+
short.resume ( 'click: left-1' )
|
|
344
|
+
await userEvent.click ( target )
|
|
345
|
+
await wait ( 400 )
|
|
346
|
+
await waitFor ( () => {
|
|
347
|
+
expect ( b ).to.be.equal ( true )
|
|
348
|
+
expect ( c ).to.be.equal ( 'red' )
|
|
349
|
+
}, { timeout: 1000, interval: 30 })
|
|
350
|
+
}) // it pause and resume
|
|
319
351
|
|
|
320
352
|
}) // describe
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"allowJs": true,
|
|
4
|
+
"declaration": true,
|
|
5
|
+
"emitDeclarationOnly": true,
|
|
6
|
+
"outDir": "dist",
|
|
7
|
+
"target": "ES2020",
|
|
8
|
+
"module": "ESNext",
|
|
9
|
+
"moduleResolution": "node",
|
|
10
|
+
"esModuleInterop": true,
|
|
11
|
+
"allowSyntheticDefaultImports": true,
|
|
12
|
+
"strict": false,
|
|
13
|
+
"skipLibCheck": true
|
|
14
|
+
},
|
|
15
|
+
"include": [
|
|
16
|
+
"src/**/*.js"
|
|
17
|
+
],
|
|
18
|
+
"exclude": [
|
|
19
|
+
"node_modules",
|
|
20
|
+
"dist",
|
|
21
|
+
"test"
|
|
22
|
+
]
|
|
23
|
+
}
|