@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.
- package/Changelog.md +51 -1
- 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/jsconfig.json +10 -0
- package/package.json +16 -7
- package/src/main.js +98 -28
- package/src/methods/_readShortcutWithPlugins.js +2 -1
- package/src/methods/changeContext.js +2 -1
- package/src/methods/listShortcuts.js +2 -1
- package/src/methods/load.js +10 -7
- package/src/methods/unload.js +3 -3
- package/src/plugins/click/_listenDOM.js +13 -3
- package/src/plugins/click/index.js +16 -6
- package/src/plugins/form/index.js +12 -17
- package/src/plugins/key/_listenDOM.js +13 -0
- package/src/plugins/key/index.js +11 -5
- package/test/01-general.test.js +158 -251
- package/test/02-key.test.js +272 -0
- package/test/03-click.test.js +352 -0
- package/test/04-form.test.js +90 -0
- package/test-helpers/setup.js +18 -0
- package/test-helpers/wait.js +8 -0
- package/tsconfig.json +23 -0
- package/vitest.config.js +21 -0
- package/vitest-example/HelloWorld.js +0 -9
- package/vitest-example/HelloWorld.test.js +0 -11
- package/vitest.workspace.js +0 -19
- /package/{test-components → test-helpers}/Block.jsx +0 -0
- /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
|
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
|
+
}
|
package/vitest.config.js
ADDED
|
@@ -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,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
|
-
})
|
package/vitest.workspace.js
DELETED
|
@@ -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
|