@solid-primitives/keyboard 1.2.4 → 1.2.5
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/dist/index.d.cts +147 -0
- package/package.json +5 -5
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { Accessor } from 'solid-js';
|
|
2
|
+
|
|
3
|
+
type ModifierKey = "Alt" | "Control" | "Meta" | "Shift";
|
|
4
|
+
type KbdKey = ModifierKey | (string & {});
|
|
5
|
+
/**
|
|
6
|
+
* Provides a signal with the last keydown event.
|
|
7
|
+
*
|
|
8
|
+
* The signal is `null` initially, and is reset to that after a timeout.
|
|
9
|
+
*
|
|
10
|
+
* @see https://github.com/solidjs-community/solid-primitives/tree/main/packages/keyboard#useKeyDownEvent
|
|
11
|
+
*
|
|
12
|
+
* @returns
|
|
13
|
+
* Returns a signal of the last keydown event
|
|
14
|
+
* ```ts
|
|
15
|
+
* Accessor<KeyboardEvent | null>
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* const event = useKeyDownEvent();
|
|
21
|
+
*
|
|
22
|
+
* createEffect(() => {
|
|
23
|
+
* const e = event();
|
|
24
|
+
* console.log(e) // => KeyboardEvent | null
|
|
25
|
+
*
|
|
26
|
+
* if (e) {
|
|
27
|
+
* console.log(e.key) // => "Q" | "ALT" | ... or null
|
|
28
|
+
* e.preventDefault(); // prevent default behavior or last keydown event
|
|
29
|
+
* }
|
|
30
|
+
* })
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
declare const useKeyDownEvent: () => Accessor<KeyboardEvent | null>;
|
|
34
|
+
/**
|
|
35
|
+
* Provides a signal with the list of currently held keys, ordered from least recent to most recent.
|
|
36
|
+
*
|
|
37
|
+
* This is a [singleton root primitive](https://github.com/solidjs-community/solid-primitives/tree/main/packages/rootless#createSingletonRoot). *(signals and event-listeners are reused across dependents)*
|
|
38
|
+
*
|
|
39
|
+
* @see https://github.com/solidjs-community/solid-primitives/tree/main/packages/keyboard#useKeyDownList
|
|
40
|
+
*
|
|
41
|
+
* @returns
|
|
42
|
+
* Returns a signal of a list of keys
|
|
43
|
+
* ```ts
|
|
44
|
+
* Accessor<string[]>
|
|
45
|
+
* ```
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```ts
|
|
49
|
+
* const keys = useKeyDownList();
|
|
50
|
+
* createEffect(() => {
|
|
51
|
+
* console.log(keys()) // => ["ALT", "CONTROL", "Q", "A"]
|
|
52
|
+
* })
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
declare const useKeyDownList: () => Accessor<string[]>;
|
|
56
|
+
/**
|
|
57
|
+
* Provides a signal with the currently held single key. Pressing any other key at the same time will reset the signal to `null`.
|
|
58
|
+
*
|
|
59
|
+
* This is a [singleton root primitive](https://github.com/solidjs-community/solid-primitives/tree/main/packages/rootless#createSingletonRoot). *(signals and event-listeners are reused across dependents)*
|
|
60
|
+
*
|
|
61
|
+
* @see https://github.com/solidjs-community/solid-primitives/tree/main/packages/keyboard#useCurrentlyHeldKey
|
|
62
|
+
*
|
|
63
|
+
* @returns
|
|
64
|
+
* ```ts
|
|
65
|
+
* Accessor<string | null>
|
|
66
|
+
* ```
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```ts
|
|
70
|
+
* const key = useCurrentlyHeldKey();
|
|
71
|
+
* createEffect(() => {
|
|
72
|
+
* console.log(key()) // => "Q" | "ALT" | ... or null
|
|
73
|
+
* })
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
76
|
+
declare const useCurrentlyHeldKey: () => Accessor<string | null>;
|
|
77
|
+
/**
|
|
78
|
+
* Provides a signal with a sequence of currently held keys, as they were pressed down and up.
|
|
79
|
+
*
|
|
80
|
+
* This is a [singleton root primitive](https://github.com/solidjs-community/solid-primitives/tree/main/packages/rootless#createSingletonRoot). *(signals and event-listeners are reused across dependents)*
|
|
81
|
+
*
|
|
82
|
+
* @see https://github.com/solidjs-community/solid-primitives/tree/main/packages/keyboard#useKeyDownSequence
|
|
83
|
+
*
|
|
84
|
+
* @returns
|
|
85
|
+
* ```ts
|
|
86
|
+
* Accessor<string[][]>
|
|
87
|
+
* // [["CONTROL"], ["CONTROL", "Q"], ["CONTROL", "Q", "A"]]
|
|
88
|
+
* ```
|
|
89
|
+
*
|
|
90
|
+
* @example
|
|
91
|
+
* ```ts
|
|
92
|
+
* const sequence = useKeyDownSequence();
|
|
93
|
+
* createEffect(() => {
|
|
94
|
+
* console.log(sequence()) // => string[][]
|
|
95
|
+
* })
|
|
96
|
+
* ```
|
|
97
|
+
*/
|
|
98
|
+
declare const useKeyDownSequence: () => Accessor<string[][]>;
|
|
99
|
+
/**
|
|
100
|
+
* Provides a `boolean` signal indicating if provided {@link key} is currently being held down.
|
|
101
|
+
* Holding multiple keys at the same time will return `false` — holding only the specified one will return `true`.
|
|
102
|
+
*
|
|
103
|
+
* @see https://github.com/solidjs-community/solid-primitives/tree/main/packages/keyboard#createKeyHold
|
|
104
|
+
*
|
|
105
|
+
* @param key The key to check for.
|
|
106
|
+
* @options The options for the key hold.
|
|
107
|
+
* - `preventDefault` — Controlls in the keydown event should have it's default action prevented. Enabled by default.
|
|
108
|
+
* @returns
|
|
109
|
+
* ```ts
|
|
110
|
+
* Accessor<boolean>
|
|
111
|
+
* ```
|
|
112
|
+
*
|
|
113
|
+
* @example
|
|
114
|
+
* ```ts
|
|
115
|
+
* const isHeld = createKeyHold("ALT");
|
|
116
|
+
* createEffect(() => {
|
|
117
|
+
* console.log(isHeld()) // => boolean
|
|
118
|
+
* })
|
|
119
|
+
* ```
|
|
120
|
+
*/
|
|
121
|
+
declare function createKeyHold(key: KbdKey, options?: {
|
|
122
|
+
preventDefault?: boolean;
|
|
123
|
+
}): Accessor<boolean>;
|
|
124
|
+
/**
|
|
125
|
+
* Creates a keyboard shotcut observer. The provided {@link callback} will be called when the specified {@link keys} are pressed.
|
|
126
|
+
*
|
|
127
|
+
* @see https://github.com/solidjs-community/solid-primitives/tree/main/packages/keyboard#createShortcut
|
|
128
|
+
*
|
|
129
|
+
* @param keys The sequence of keys to watch for.
|
|
130
|
+
* @param callback The callback to call when the keys are pressed.
|
|
131
|
+
* @options The options for the shortcut.
|
|
132
|
+
* - `preventDefault` — Controlls in the keydown event should have it's default action prevented. Enabled by default.
|
|
133
|
+
* - `requireReset` — If `true`, the shortcut will only be triggered once until all of the keys stop being pressed. Disabled by default.
|
|
134
|
+
*
|
|
135
|
+
* @example
|
|
136
|
+
* ```ts
|
|
137
|
+
* createShortcut(["CONTROL", "SHIFT", "C"], () => {
|
|
138
|
+
* console.log("Ctrl+Shift+C was pressed");
|
|
139
|
+
* });
|
|
140
|
+
* ```
|
|
141
|
+
*/
|
|
142
|
+
declare function createShortcut(keys: KbdKey[], callback: (event: KeyboardEvent | null) => void, options?: {
|
|
143
|
+
preventDefault?: boolean;
|
|
144
|
+
requireReset?: boolean;
|
|
145
|
+
}): void;
|
|
146
|
+
|
|
147
|
+
export { KbdKey, ModifierKey, createKeyHold, createShortcut, useCurrentlyHeldKey, useKeyDownEvent, useKeyDownList, useKeyDownSequence };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@solid-primitives/keyboard",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.5",
|
|
4
4
|
"description": "A library of reactive promitives helping handling user's keyboard input.",
|
|
5
5
|
"author": "Damian Tarnwski <gthetarnav@gmail.com>",
|
|
6
6
|
"contributors": [],
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"require": "./dist/index.cjs"
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
|
-
"@solid-primitives/event-listener": "^2.
|
|
53
|
+
"@solid-primitives/event-listener": "^2.3.0",
|
|
54
54
|
"@solid-primitives/rootless": "^1.4.2",
|
|
55
55
|
"@solid-primitives/utils": "^6.2.1"
|
|
56
56
|
},
|
|
@@ -58,12 +58,12 @@
|
|
|
58
58
|
"solid-js": "^1.6.12"
|
|
59
59
|
},
|
|
60
60
|
"devDependencies": {
|
|
61
|
-
"solid-js": "1.7.
|
|
61
|
+
"solid-js": "^1.7.11"
|
|
62
62
|
},
|
|
63
63
|
"typesVersions": {},
|
|
64
64
|
"scripts": {
|
|
65
|
-
"dev": "
|
|
66
|
-
"build": "
|
|
65
|
+
"dev": "tsx ../../scripts/dev.ts",
|
|
66
|
+
"build": "tsx ../../scripts/build.ts",
|
|
67
67
|
"vitest": "vitest -c ../../configs/vitest.config.ts",
|
|
68
68
|
"test": "pnpm run vitest",
|
|
69
69
|
"test:ssr": "pnpm run vitest --mode ssr"
|