@peter.naydenov/shortcuts 3.3.1 → 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.
Files changed (57) hide show
  1. package/Changelog.md +51 -1
  2. package/README.md +2 -0
  3. package/dist/main.d.ts +120 -0
  4. package/dist/methods/_normalizeWithPlugins.d.ts +2 -0
  5. package/dist/methods/_readShortcutWithPlugins.d.ts +2 -0
  6. package/dist/methods/_systemAction.d.ts +2 -0
  7. package/dist/methods/changeContext.d.ts +2 -0
  8. package/dist/methods/index.d.ts +17 -0
  9. package/dist/methods/listShortcuts.d.ts +17 -0
  10. package/dist/methods/load.d.ts +2 -0
  11. package/dist/methods/unload.d.ts +2 -0
  12. package/dist/plugins/click/_findTarget.d.ts +2 -0
  13. package/dist/plugins/click/_listenDOM.d.ts +5 -0
  14. package/dist/plugins/click/_normalizeShortcutName.d.ts +2 -0
  15. package/dist/plugins/click/_readClickEvent.d.ts +2 -0
  16. package/dist/plugins/click/_registerShortcutEvents.d.ts +2 -0
  17. package/dist/plugins/click/index.d.ts +15 -0
  18. package/dist/plugins/form/_defaults.d.ts +5 -0
  19. package/dist/plugins/form/_listenDOM.d.ts +5 -0
  20. package/dist/plugins/form/_normalizeShortcutName.d.ts +2 -0
  21. package/dist/plugins/form/_registerShortcutEvents.d.ts +2 -0
  22. package/dist/plugins/form/index.d.ts +10 -0
  23. package/dist/plugins/key/_listenDOM.d.ts +5 -0
  24. package/dist/plugins/key/_normalizeShortcutName.d.ts +2 -0
  25. package/dist/plugins/key/_readKeyEvent.d.ts +2 -0
  26. package/dist/plugins/key/_registerShortcutEvents.d.ts +2 -0
  27. package/dist/plugins/key/_specialChars.d.ts +32 -0
  28. package/dist/plugins/key/index.d.ts +15 -0
  29. package/dist/shortcuts.cjs +1 -1
  30. package/dist/shortcuts.esm.mjs +1 -1
  31. package/dist/shortcuts.umd.js +1 -1
  32. package/jsconfig.json +10 -0
  33. package/package.json +16 -7
  34. package/src/main.js +98 -28
  35. package/src/methods/_readShortcutWithPlugins.js +2 -1
  36. package/src/methods/changeContext.js +2 -1
  37. package/src/methods/listShortcuts.js +2 -1
  38. package/src/methods/load.js +10 -7
  39. package/src/methods/unload.js +3 -3
  40. package/src/plugins/click/_listenDOM.js +13 -3
  41. package/src/plugins/click/index.js +16 -6
  42. package/src/plugins/form/index.js +12 -17
  43. package/src/plugins/key/_listenDOM.js +13 -0
  44. package/src/plugins/key/index.js +11 -5
  45. package/test/01-general.test.js +158 -251
  46. package/test/02-key.test.js +272 -0
  47. package/test/03-click.test.js +352 -0
  48. package/test/04-form.test.js +90 -0
  49. package/test-helpers/setup.js +18 -0
  50. package/test-helpers/wait.js +8 -0
  51. package/tsconfig.json +23 -0
  52. package/vitest.config.js +21 -0
  53. package/vitest-example/HelloWorld.js +0 -9
  54. package/vitest-example/HelloWorld.test.js +0 -11
  55. package/vitest.workspace.js +0 -19
  56. /package/{test-components → test-helpers}/Block.jsx +0 -0
  57. /package/{test-components → test-helpers}/style.css +0 -0
@@ -0,0 +1,90 @@
1
+ import { beforeEach, afterEach, describe, it, test, expect } from 'vitest'
2
+ import { userEvent } from '@vitest/browser/context'
3
+ import {
4
+ getByLabelText,
5
+ getByText,
6
+ getByTestId,
7
+ queryByTestId,
8
+ // Tip: all queries are also exposed on an object
9
+ // called "queries" which you could import here as well
10
+ waitFor
11
+ } from '@testing-library/dom'
12
+
13
+
14
+
15
+ import '../test-helpers/style.css'
16
+ import Block from '../test-helpers/Block.jsx'
17
+ import VisaulController from '@peter.naydenov/visual-controller-for-react'
18
+ import wait from '../test-helpers/wait.js'
19
+ import {
20
+ shortcuts
21
+ , pluginClick
22
+ , pluginKey
23
+ , pluginForm
24
+ } from '../src/main.js'
25
+
26
+
27
+
28
+ const html = new VisaulController ();
29
+ let
30
+ a = false
31
+ , b = false
32
+ , c = null
33
+ ;
34
+
35
+ const contextDefinition = {
36
+ general : {
37
+ ' key : shift+a': [
38
+ () => a = true,
39
+ () => c = 'triggered'
40
+ ]
41
+ }
42
+ , touch : {
43
+ // Single click with left button
44
+ 'click: left-1': () => b = true,
45
+ // Double click with left button
46
+ 'click: left-2': () => b = true,
47
+ // Single click with right button
48
+ 'click: right-1': () => b = true
49
+ }
50
+ , extra : {
51
+ 'key : p,r,o,b,a': () => b = true
52
+ }
53
+ , extend : {
54
+ 'form : watch' : () => 'input'
55
+ , 'form : define' : () => 'input'
56
+ , 'form : action' : () => [
57
+ {
58
+ fn : (e) => console.log ( e.target )
59
+ , type : 'input'
60
+ , mode : 'in'
61
+ }
62
+ ]
63
+ }
64
+ }
65
+
66
+ let short = shortcuts ();
67
+
68
+
69
+
70
+ describe.skip ( 'Form plugin', () => {
71
+
72
+ beforeEach ( async () => {
73
+ short.load ( contextDefinition )
74
+ let container = document.createElement ( 'div' )
75
+ container.id = 'app'
76
+ document.body.appendChild ( container )
77
+ await html.publish ( Block, {}, 'app' )
78
+ a = false, b = false
79
+ }) // beforeEach
80
+
81
+
82
+
83
+ afterEach ( async () => {
84
+ short.reset ()
85
+ a = false, b = false, c = null;
86
+ }) // afterEach
87
+
88
+
89
+
90
+ }) // describe
@@ -0,0 +1,18 @@
1
+ async function setup () {
2
+ let st = document.createElement ( 'style' )
3
+ st.textContent = cssCode
4
+ document.head.appendChild ( st )
5
+ await waitFor ( () => {
6
+ expect ( document.head ).to.have.property ( 'style' )
7
+ })
8
+
9
+
10
+ let container = document.createElement ( 'div' )
11
+ container.id = 'app'
12
+ document.body.appendChild ( container )
13
+ html.publish ( Block, {}, 'app' )
14
+ a = false, b = false
15
+ } // setup func.
16
+
17
+
18
+ export default setup
@@ -0,0 +1,8 @@
1
+ function wait (ms) {
2
+ return new Promise((resolve) => setTimeout(resolve, ms));
3
+ }
4
+
5
+
6
+ export default wait
7
+
8
+
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
+ }
@@ -0,0 +1,21 @@
1
+ import { defineConfig } from 'vitest/config'
2
+ import react from '@vitejs/plugin-react'
3
+
4
+ export default defineConfig ({
5
+ plugins: [react()],
6
+ test: {
7
+ coverage: {
8
+ reporter: ['lcov', 'text-summary']
9
+ },
10
+ browser: {
11
+ enabled: true,
12
+ headless: true,
13
+ provider: 'playwright',
14
+ instances: [
15
+ {
16
+ browser: 'chromium'
17
+ }
18
+ ]
19
+ }
20
+ }
21
+ })
@@ -1,9 +0,0 @@
1
- export default function HelloWorld({ name }) {
2
- const parent = document.createElement('div')
3
-
4
- const h1 = document.createElement('h1')
5
- h1.textContent = 'Hello ' + name + '!'
6
- parent.appendChild(h1)
7
-
8
- return parent
9
- }
@@ -1,11 +0,0 @@
1
- import { expect, test } from 'vitest'
2
- import { getByText } from '@testing-library/dom'
3
- import HelloWorld from './HelloWorld.js'
4
-
5
- test('renders name', () => {
6
- const parent = HelloWorld({ name: 'Vitest' })
7
- document.body.appendChild(parent)
8
-
9
- const element = getByText(parent, 'Hello Vitest!')
10
- expect(element).toBeInTheDocument()
11
- })
@@ -1,19 +0,0 @@
1
- import { defineWorkspace } from 'vitest/config'
2
-
3
- export default defineWorkspace([
4
- // If you want to keep running your existing tests in Node.js, uncomment the next line.
5
- // 'vite.config.js',
6
- {
7
- extends: 'vite.config.js',
8
- test: {
9
- environment: 'browser',
10
- browser: {
11
- enabled: true,
12
- name: 'chromium',
13
- provider: 'playwright',
14
- // https://vitest.dev/guide/browser/playwright
15
- configs: [],
16
- },
17
- },
18
- },
19
- ])
File without changes
File without changes