@tanstack/solid-hotkeys 0.0.1
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/README.md +305 -0
- package/dist/HotkeysProvider.cjs +27 -0
- package/dist/HotkeysProvider.cjs.map +1 -0
- package/dist/HotkeysProvider.d.cts +24 -0
- package/dist/HotkeysProvider.d.ts +24 -0
- package/dist/HotkeysProvider.js +25 -0
- package/dist/HotkeysProvider.js.map +1 -0
- package/dist/createHeldKeyCodes.cjs +42 -0
- package/dist/createHeldKeyCodes.cjs.map +1 -0
- package/dist/createHeldKeyCodes.d.cts +36 -0
- package/dist/createHeldKeyCodes.d.ts +36 -0
- package/dist/createHeldKeyCodes.js +42 -0
- package/dist/createHeldKeyCodes.js.map +1 -0
- package/dist/createHeldKeys.cjs +33 -0
- package/dist/createHeldKeys.cjs.map +1 -0
- package/dist/createHeldKeys.d.cts +27 -0
- package/dist/createHeldKeys.d.ts +27 -0
- package/dist/createHeldKeys.js +33 -0
- package/dist/createHeldKeys.js.map +1 -0
- package/dist/createHotkey.cjs +100 -0
- package/dist/createHotkey.cjs.map +1 -0
- package/dist/createHotkey.d.cts +72 -0
- package/dist/createHotkey.d.ts +72 -0
- package/dist/createHotkey.js +100 -0
- package/dist/createHotkey.js.map +1 -0
- package/dist/createHotkeyRecorder.cjs +78 -0
- package/dist/createHotkeyRecorder.cjs.map +1 -0
- package/dist/createHotkeyRecorder.d.cts +60 -0
- package/dist/createHotkeyRecorder.d.ts +60 -0
- package/dist/createHotkeyRecorder.js +78 -0
- package/dist/createHotkeyRecorder.js.map +1 -0
- package/dist/createHotkeySequence.cjs +58 -0
- package/dist/createHotkeySequence.cjs.map +1 -0
- package/dist/createHotkeySequence.d.cts +43 -0
- package/dist/createHotkeySequence.d.ts +43 -0
- package/dist/createHotkeySequence.js +58 -0
- package/dist/createHotkeySequence.js.map +1 -0
- package/dist/createKeyHold.cjs +56 -0
- package/dist/createKeyHold.cjs.map +1 -0
- package/dist/createKeyHold.d.cts +47 -0
- package/dist/createKeyHold.d.ts +47 -0
- package/dist/createKeyHold.js +56 -0
- package/dist/createKeyHold.js.map +1 -0
- package/dist/index.cjs +25 -0
- package/dist/index.d.cts +9 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +11 -0
- package/package.json +67 -0
- package/src/HotkeysProvider.tsx +47 -0
- package/src/createHeldKeyCodes.ts +38 -0
- package/src/createHeldKeys.ts +29 -0
- package/src/createHotkey.ts +154 -0
- package/src/createHotkeyRecorder.ts +103 -0
- package/src/createHotkeySequence.ts +93 -0
- package/src/createKeyHold.ts +57 -0
- package/src/index.ts +13 -0
package/README.md
ADDED
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
# @tanstack/solid-hotkeys
|
|
2
|
+
|
|
3
|
+
> SolidJS adapter for [TanStack Hotkeys](https://tanstack.com/hotkeys) - keyboard shortcuts made easy
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/@tanstack/solid-hotkeys)
|
|
6
|
+
[](https://opensource.org/licenses/MIT)
|
|
7
|
+
|
|
8
|
+
## Features
|
|
9
|
+
|
|
10
|
+
✅ **Type-safe hotkey bindings** - Template strings (`Mod+Shift+S`, `Escape`) or parsed objects
|
|
11
|
+
✅ **Cross-platform** - `Mod` key automatically maps to Cmd on macOS, Ctrl on Windows/Linux
|
|
12
|
+
✅ **Sequence support** - Vim-style multi-key sequences (`g g`, `d d`)
|
|
13
|
+
✅ **Key state tracking** - Track which keys are currently held down
|
|
14
|
+
✅ **Hotkey recording** - Built-in UI helpers for letting users define their own shortcuts
|
|
15
|
+
✅ **SolidJS primitives** - Reactive primitives that work seamlessly with SolidJS
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npm install @tanstack/solid-hotkeys @tanstack/hotkeys
|
|
21
|
+
# or
|
|
22
|
+
bun add @tanstack/solid-hotkeys @tanstack/hotkeys
|
|
23
|
+
# or
|
|
24
|
+
pnpm add @tanstack/solid-hotkeys @tanstack/hotkeys
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Quick Start
|
|
28
|
+
|
|
29
|
+
```tsx
|
|
30
|
+
import { createHotkey } from '@tanstack/solid-hotkeys'
|
|
31
|
+
|
|
32
|
+
function App() {
|
|
33
|
+
createHotkey('Mod+S', (event) => {
|
|
34
|
+
event.preventDefault()
|
|
35
|
+
console.log('Save!')
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
return <div>Press Cmd/Ctrl+S to save</div>
|
|
39
|
+
}
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Usage
|
|
43
|
+
|
|
44
|
+
### Basic Hotkey
|
|
45
|
+
|
|
46
|
+
```tsx
|
|
47
|
+
import { createHotkey } from '@tanstack/solid-hotkeys'
|
|
48
|
+
|
|
49
|
+
function SaveButton() {
|
|
50
|
+
createHotkey('Mod+S', (event, { hotkey }) => {
|
|
51
|
+
event.preventDefault()
|
|
52
|
+
handleSave()
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
return <button>Save (Cmd/Ctrl+S)</button>
|
|
56
|
+
}
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### Conditional Hotkeys
|
|
60
|
+
|
|
61
|
+
```tsx
|
|
62
|
+
import { createHotkey } from '@tanstack/solid-hotkeys'
|
|
63
|
+
import { Show, createSignal } from 'solid-js'
|
|
64
|
+
|
|
65
|
+
function Modal(props) {
|
|
66
|
+
// Hotkey only active when modal is open
|
|
67
|
+
createHotkey(
|
|
68
|
+
'Escape',
|
|
69
|
+
() => props.onClose(),
|
|
70
|
+
() => ({
|
|
71
|
+
enabled: props.isOpen,
|
|
72
|
+
}),
|
|
73
|
+
)
|
|
74
|
+
|
|
75
|
+
return (
|
|
76
|
+
<Show when={props.isOpen}>
|
|
77
|
+
<div class="modal">Press Escape to close</div>
|
|
78
|
+
</Show>
|
|
79
|
+
)
|
|
80
|
+
}
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### Scoped Hotkeys
|
|
84
|
+
|
|
85
|
+
```tsx
|
|
86
|
+
import { createHotkey } from '@tanstack/solid-hotkeys'
|
|
87
|
+
|
|
88
|
+
function Editor() {
|
|
89
|
+
let editorRef: HTMLDivElement | undefined
|
|
90
|
+
|
|
91
|
+
// Hotkey only works when editor is focused
|
|
92
|
+
createHotkey(
|
|
93
|
+
'Mod+B',
|
|
94
|
+
() => {
|
|
95
|
+
toggleBold()
|
|
96
|
+
},
|
|
97
|
+
{ target: editorRef },
|
|
98
|
+
)
|
|
99
|
+
|
|
100
|
+
return <div ref={editorRef} contentEditable />
|
|
101
|
+
}
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
### Hotkey Sequences (Vim-style)
|
|
105
|
+
|
|
106
|
+
```tsx
|
|
107
|
+
import { createHotkeySequence } from '@tanstack/solid-hotkeys'
|
|
108
|
+
|
|
109
|
+
function VimEditor() {
|
|
110
|
+
// 'g g' to go to top
|
|
111
|
+
createHotkeySequence(['G', 'G'], () => {
|
|
112
|
+
scrollToTop()
|
|
113
|
+
})
|
|
114
|
+
|
|
115
|
+
// 'd d' to delete line
|
|
116
|
+
createHotkeySequence(['D', 'D'], () => {
|
|
117
|
+
deleteLine()
|
|
118
|
+
})
|
|
119
|
+
|
|
120
|
+
// 'd i w' to delete inner word
|
|
121
|
+
createHotkeySequence(
|
|
122
|
+
['D', 'I', 'W'],
|
|
123
|
+
() => {
|
|
124
|
+
deleteInnerWord()
|
|
125
|
+
},
|
|
126
|
+
{ timeout: 500 },
|
|
127
|
+
)
|
|
128
|
+
|
|
129
|
+
return <div>Try Vim shortcuts!</div>
|
|
130
|
+
}
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
### Track Held Keys
|
|
134
|
+
|
|
135
|
+
```tsx
|
|
136
|
+
import { createHeldKeys, createKeyHold } from '@tanstack/solid-hotkeys'
|
|
137
|
+
import { For } from 'solid-js'
|
|
138
|
+
|
|
139
|
+
function KeyTracker() {
|
|
140
|
+
const heldKeys = createHeldKeys()
|
|
141
|
+
const shiftHeld = createKeyHold('Shift')
|
|
142
|
+
|
|
143
|
+
return (
|
|
144
|
+
<div>
|
|
145
|
+
<div>Shift: {shiftHeld() ? 'Pressed' : 'Not pressed'}</div>
|
|
146
|
+
<div>
|
|
147
|
+
All held keys:
|
|
148
|
+
<For each={heldKeys()}>{(key) => <kbd>{key}</kbd>}</For>
|
|
149
|
+
</div>
|
|
150
|
+
</div>
|
|
151
|
+
)
|
|
152
|
+
}
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
### Hotkey Recorder
|
|
156
|
+
|
|
157
|
+
```tsx
|
|
158
|
+
import { createHotkeyRecorder } from '@tanstack/solid-hotkeys'
|
|
159
|
+
import { createSignal, Show } from 'solid-js'
|
|
160
|
+
|
|
161
|
+
function ShortcutSettings() {
|
|
162
|
+
const [shortcut, setShortcut] = createSignal('Mod+S')
|
|
163
|
+
|
|
164
|
+
const recorder = createHotkeyRecorder({
|
|
165
|
+
onRecord: (hotkey) => {
|
|
166
|
+
setShortcut(hotkey)
|
|
167
|
+
},
|
|
168
|
+
onCancel: () => {
|
|
169
|
+
console.log('Recording cancelled')
|
|
170
|
+
},
|
|
171
|
+
})
|
|
172
|
+
|
|
173
|
+
return (
|
|
174
|
+
<div>
|
|
175
|
+
<div>Current shortcut: {shortcut()}</div>
|
|
176
|
+
<button onClick={recorder.startRecording}>
|
|
177
|
+
{recorder.isRecording() ? 'Recording...' : 'Edit Shortcut'}
|
|
178
|
+
</button>
|
|
179
|
+
<Show when={recorder.recordedHotkey()}>
|
|
180
|
+
<div>Preview: {recorder.recordedHotkey()}</div>
|
|
181
|
+
</Show>
|
|
182
|
+
</div>
|
|
183
|
+
)
|
|
184
|
+
}
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
### Global Configuration
|
|
188
|
+
|
|
189
|
+
```tsx
|
|
190
|
+
import { HotkeysProvider } from '@tanstack/solid-hotkeys'
|
|
191
|
+
|
|
192
|
+
function App() {
|
|
193
|
+
return (
|
|
194
|
+
<HotkeysProvider
|
|
195
|
+
defaultOptions={{
|
|
196
|
+
hotkey: {
|
|
197
|
+
preventDefault: true,
|
|
198
|
+
enabled: true,
|
|
199
|
+
},
|
|
200
|
+
hotkeySequence: {
|
|
201
|
+
timeout: 1000,
|
|
202
|
+
},
|
|
203
|
+
}}
|
|
204
|
+
>
|
|
205
|
+
<YourApp />
|
|
206
|
+
</HotkeysProvider>
|
|
207
|
+
)
|
|
208
|
+
}
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
## API
|
|
212
|
+
|
|
213
|
+
### `createHotkey(hotkey, callback, options?)`
|
|
214
|
+
|
|
215
|
+
Register a keyboard hotkey.
|
|
216
|
+
|
|
217
|
+
- `hotkey`: String like `"Mod+S"` or `"Escape"`, or accessor function
|
|
218
|
+
- `callback`: Function called when hotkey is pressed
|
|
219
|
+
- `options`: Optional configuration (or accessor function for reactive options)
|
|
220
|
+
|
|
221
|
+
**Options:**
|
|
222
|
+
|
|
223
|
+
- `enabled`: Whether the hotkey is active (default: `true`)
|
|
224
|
+
- `preventDefault`: Prevent default browser behavior (default: `false`)
|
|
225
|
+
- `stopPropagation`: Stop event propagation (default: `false`)
|
|
226
|
+
- `target`: DOM element to attach listener to (default: `document`)
|
|
227
|
+
- `platform`: Override platform detection
|
|
228
|
+
|
|
229
|
+
### `createHotkeySequence(sequence, callback, options?)`
|
|
230
|
+
|
|
231
|
+
Register a multi-key sequence (Vim-style).
|
|
232
|
+
|
|
233
|
+
- `sequence`: Array of hotkey strings like `["G", "G"]`, or accessor function
|
|
234
|
+
- `callback`: Function called when sequence completes
|
|
235
|
+
- `options`: Optional configuration (or accessor function)
|
|
236
|
+
|
|
237
|
+
**Options:**
|
|
238
|
+
|
|
239
|
+
- `enabled`: Whether sequence detection is active (default: `true`)
|
|
240
|
+
- `timeout`: Max time between keys in ms (default: `1000`)
|
|
241
|
+
- `platform`: Override platform detection
|
|
242
|
+
|
|
243
|
+
### `createHeldKeys()`
|
|
244
|
+
|
|
245
|
+
Returns a signal accessor for array of currently held keys.
|
|
246
|
+
|
|
247
|
+
```tsx
|
|
248
|
+
const heldKeys = createHeldKeys()
|
|
249
|
+
// heldKeys() => ["Shift", "A"]
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
### `createHeldKeyCodes()`
|
|
253
|
+
|
|
254
|
+
Returns a signal accessor for map of held keys to their physical key codes.
|
|
255
|
+
|
|
256
|
+
```tsx
|
|
257
|
+
const heldCodes = createHeldKeyCodes()
|
|
258
|
+
// heldCodes() => { "Shift": "ShiftLeft", "A": "KeyA" }
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
### `createKeyHold(key)`
|
|
262
|
+
|
|
263
|
+
Returns a signal accessor that's true when specific key is held.
|
|
264
|
+
|
|
265
|
+
```tsx
|
|
266
|
+
const isShiftHeld = createKeyHold('Shift')
|
|
267
|
+
// isShiftHeld() => true/false
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
### `createHotkeyRecorder(options)`
|
|
271
|
+
|
|
272
|
+
Hotkey recording interface.
|
|
273
|
+
|
|
274
|
+
**Options:**
|
|
275
|
+
|
|
276
|
+
- `onRecord`: Callback when hotkey is recorded
|
|
277
|
+
- `onCancel`: Callback when recording is cancelled
|
|
278
|
+
|
|
279
|
+
**Returns:**
|
|
280
|
+
|
|
281
|
+
- `isRecording`: Signal accessor for recording state
|
|
282
|
+
- `recordedHotkey`: Signal accessor for current hotkey preview
|
|
283
|
+
- `startRecording`: Function to start recording
|
|
284
|
+
- `stopRecording`: Function to stop recording
|
|
285
|
+
- `cancelRecording`: Function to cancel recording
|
|
286
|
+
|
|
287
|
+
### `HotkeysProvider`
|
|
288
|
+
|
|
289
|
+
Optional provider for global configuration.
|
|
290
|
+
|
|
291
|
+
## Cross-Platform Keys
|
|
292
|
+
|
|
293
|
+
Use `Mod` for cross-platform modifier:
|
|
294
|
+
|
|
295
|
+
- `Mod+S` → `Cmd+S` on macOS, `Ctrl+S` on Windows/Linux
|
|
296
|
+
- `Mod+Shift+P` → `Cmd+Shift+P` on macOS, `Ctrl+Shift+P` elsewhere
|
|
297
|
+
|
|
298
|
+
## Related
|
|
299
|
+
|
|
300
|
+
- [TanStack Hotkeys](https://tanstack.com/hotkeys) - The core library
|
|
301
|
+
- [@tanstack/react-hotkeys](https://tanstack.com/hotkeys) - React adapter
|
|
302
|
+
|
|
303
|
+
## License
|
|
304
|
+
|
|
305
|
+
MIT
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
let solid_js_web = require("solid-js/web");
|
|
2
|
+
let solid_js = require("solid-js");
|
|
3
|
+
|
|
4
|
+
//#region src/HotkeysProvider.tsx
|
|
5
|
+
const HotkeysContext = (0, solid_js.createContext)(null);
|
|
6
|
+
const DEFAULT_OPTIONS = {};
|
|
7
|
+
const HotkeysProvider = (props) => {
|
|
8
|
+
const contextValue = { defaultOptions: props.defaultOptions ?? DEFAULT_OPTIONS };
|
|
9
|
+
return (0, solid_js_web.createComponent)(HotkeysContext.Provider, {
|
|
10
|
+
value: contextValue,
|
|
11
|
+
get children() {
|
|
12
|
+
return props.children;
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
};
|
|
16
|
+
function useHotkeysContext() {
|
|
17
|
+
return (0, solid_js.useContext)(HotkeysContext);
|
|
18
|
+
}
|
|
19
|
+
function useDefaultHotkeysOptions() {
|
|
20
|
+
return (0, solid_js.useContext)(HotkeysContext)?.defaultOptions ?? {};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
//#endregion
|
|
24
|
+
exports.HotkeysProvider = HotkeysProvider;
|
|
25
|
+
exports.useDefaultHotkeysOptions = useDefaultHotkeysOptions;
|
|
26
|
+
exports.useHotkeysContext = useHotkeysContext;
|
|
27
|
+
//# sourceMappingURL=HotkeysProvider.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HotkeysProvider.cjs","names":["createContext","useContext","JSX","ParentComponent","HotkeyRecorderOptions","CreateHotkeyOptions","CreateHotkeySequenceOptions","HotkeysProviderOptions","hotkey","Partial","hotkeyRecorder","hotkeySequence","HotkeysContextValue","defaultOptions","HotkeysContext","HotkeysProviderProps","children","Element","DEFAULT_OPTIONS","HotkeysProvider","props","contextValue","_$createComponent","Provider","value","useHotkeysContext","useDefaultHotkeysOptions","context"],"sources":["../src/HotkeysProvider.tsx"],"sourcesContent":["import { createContext, useContext } from 'solid-js'\nimport type { JSX, ParentComponent } from 'solid-js'\nimport type { HotkeyRecorderOptions } from '@tanstack/hotkeys'\nimport type { CreateHotkeyOptions } from './createHotkey'\nimport type { CreateHotkeySequenceOptions } from './createHotkeySequence'\n\nexport interface HotkeysProviderOptions {\n hotkey?: Partial<CreateHotkeyOptions>\n hotkeyRecorder?: Partial<HotkeyRecorderOptions>\n hotkeySequence?: Partial<CreateHotkeySequenceOptions>\n}\n\ninterface HotkeysContextValue {\n defaultOptions: HotkeysProviderOptions\n}\n\nconst HotkeysContext = createContext<HotkeysContextValue | null>(null)\n\nexport interface HotkeysProviderProps {\n children: JSX.Element\n defaultOptions?: HotkeysProviderOptions\n}\n\nconst DEFAULT_OPTIONS: HotkeysProviderOptions = {}\n\nexport const HotkeysProvider: ParentComponent<HotkeysProviderProps> = (\n props,\n) => {\n const contextValue: HotkeysContextValue = {\n defaultOptions: props.defaultOptions ?? DEFAULT_OPTIONS,\n }\n\n return (\n <HotkeysContext.Provider value={contextValue}>\n {props.children}\n </HotkeysContext.Provider>\n )\n}\n\nexport function useHotkeysContext() {\n return useContext(HotkeysContext)\n}\n\nexport function useDefaultHotkeysOptions() {\n const context = useContext(HotkeysContext)\n return context?.defaultOptions ?? {}\n}\n"],"mappings":";;;;AAgBA,MAAMc,6CAA2D,KAAK;AAOtE,MAAMI,kBAA0C,EAAE;AAElD,MAAaC,mBACXC,UACG;CACH,MAAMC,eAAoC,EACxCR,gBAAgBO,MAAMP,kBAAkBK,iBACzC;AAED,0CACGJ,eAAeS,UAAQ;EAACC,OAAOH;EAAY,IAAAL,WAAA;AAAA,UACzCI,MAAMJ;;EAAQ,CAAA;;AAKrB,SAAgBS,oBAAoB;AAClC,iCAAkBX,eAAe;;AAGnC,SAAgBY,2BAA2B;AAEzC,iCAD2BZ,eAAe,EAC1BD,kBAAkB,EAAE"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { CreateHotkeyOptions } from "./createHotkey.cjs";
|
|
2
|
+
import { CreateHotkeySequenceOptions } from "./createHotkeySequence.cjs";
|
|
3
|
+
import { HotkeyRecorderOptions } from "@tanstack/hotkeys";
|
|
4
|
+
import { JSX, ParentComponent } from "solid-js";
|
|
5
|
+
|
|
6
|
+
//#region src/HotkeysProvider.d.ts
|
|
7
|
+
interface HotkeysProviderOptions {
|
|
8
|
+
hotkey?: Partial<CreateHotkeyOptions>;
|
|
9
|
+
hotkeyRecorder?: Partial<HotkeyRecorderOptions>;
|
|
10
|
+
hotkeySequence?: Partial<CreateHotkeySequenceOptions>;
|
|
11
|
+
}
|
|
12
|
+
interface HotkeysContextValue {
|
|
13
|
+
defaultOptions: HotkeysProviderOptions;
|
|
14
|
+
}
|
|
15
|
+
interface HotkeysProviderProps {
|
|
16
|
+
children: JSX.Element;
|
|
17
|
+
defaultOptions?: HotkeysProviderOptions;
|
|
18
|
+
}
|
|
19
|
+
declare const HotkeysProvider: ParentComponent<HotkeysProviderProps>;
|
|
20
|
+
declare function useHotkeysContext(): HotkeysContextValue | null;
|
|
21
|
+
declare function useDefaultHotkeysOptions(): HotkeysProviderOptions;
|
|
22
|
+
//#endregion
|
|
23
|
+
export { HotkeysProvider, HotkeysProviderOptions, HotkeysProviderProps, useDefaultHotkeysOptions, useHotkeysContext };
|
|
24
|
+
//# sourceMappingURL=HotkeysProvider.d.cts.map
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { CreateHotkeyOptions } from "./createHotkey.js";
|
|
2
|
+
import { CreateHotkeySequenceOptions } from "./createHotkeySequence.js";
|
|
3
|
+
import { HotkeyRecorderOptions } from "@tanstack/hotkeys";
|
|
4
|
+
import { JSX, ParentComponent } from "solid-js";
|
|
5
|
+
|
|
6
|
+
//#region src/HotkeysProvider.d.ts
|
|
7
|
+
interface HotkeysProviderOptions {
|
|
8
|
+
hotkey?: Partial<CreateHotkeyOptions>;
|
|
9
|
+
hotkeyRecorder?: Partial<HotkeyRecorderOptions>;
|
|
10
|
+
hotkeySequence?: Partial<CreateHotkeySequenceOptions>;
|
|
11
|
+
}
|
|
12
|
+
interface HotkeysContextValue {
|
|
13
|
+
defaultOptions: HotkeysProviderOptions;
|
|
14
|
+
}
|
|
15
|
+
interface HotkeysProviderProps {
|
|
16
|
+
children: JSX.Element;
|
|
17
|
+
defaultOptions?: HotkeysProviderOptions;
|
|
18
|
+
}
|
|
19
|
+
declare const HotkeysProvider: ParentComponent<HotkeysProviderProps>;
|
|
20
|
+
declare function useHotkeysContext(): HotkeysContextValue | null;
|
|
21
|
+
declare function useDefaultHotkeysOptions(): HotkeysProviderOptions;
|
|
22
|
+
//#endregion
|
|
23
|
+
export { HotkeysProvider, HotkeysProviderOptions, HotkeysProviderProps, useDefaultHotkeysOptions, useHotkeysContext };
|
|
24
|
+
//# sourceMappingURL=HotkeysProvider.d.ts.map
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { createComponent } from "solid-js/web";
|
|
2
|
+
import { createContext, useContext } from "solid-js";
|
|
3
|
+
|
|
4
|
+
//#region src/HotkeysProvider.tsx
|
|
5
|
+
const HotkeysContext = createContext(null);
|
|
6
|
+
const DEFAULT_OPTIONS = {};
|
|
7
|
+
const HotkeysProvider = (props) => {
|
|
8
|
+
const contextValue = { defaultOptions: props.defaultOptions ?? DEFAULT_OPTIONS };
|
|
9
|
+
return createComponent(HotkeysContext.Provider, {
|
|
10
|
+
value: contextValue,
|
|
11
|
+
get children() {
|
|
12
|
+
return props.children;
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
};
|
|
16
|
+
function useHotkeysContext() {
|
|
17
|
+
return useContext(HotkeysContext);
|
|
18
|
+
}
|
|
19
|
+
function useDefaultHotkeysOptions() {
|
|
20
|
+
return useContext(HotkeysContext)?.defaultOptions ?? {};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
//#endregion
|
|
24
|
+
export { HotkeysProvider, useDefaultHotkeysOptions, useHotkeysContext };
|
|
25
|
+
//# sourceMappingURL=HotkeysProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HotkeysProvider.js","names":["createContext","useContext","JSX","ParentComponent","HotkeyRecorderOptions","CreateHotkeyOptions","CreateHotkeySequenceOptions","HotkeysProviderOptions","hotkey","Partial","hotkeyRecorder","hotkeySequence","HotkeysContextValue","defaultOptions","HotkeysContext","HotkeysProviderProps","children","Element","DEFAULT_OPTIONS","HotkeysProvider","props","contextValue","_$createComponent","Provider","value","useHotkeysContext","useDefaultHotkeysOptions","context"],"sources":["../src/HotkeysProvider.tsx"],"sourcesContent":["import { createContext, useContext } from 'solid-js'\nimport type { JSX, ParentComponent } from 'solid-js'\nimport type { HotkeyRecorderOptions } from '@tanstack/hotkeys'\nimport type { CreateHotkeyOptions } from './createHotkey'\nimport type { CreateHotkeySequenceOptions } from './createHotkeySequence'\n\nexport interface HotkeysProviderOptions {\n hotkey?: Partial<CreateHotkeyOptions>\n hotkeyRecorder?: Partial<HotkeyRecorderOptions>\n hotkeySequence?: Partial<CreateHotkeySequenceOptions>\n}\n\ninterface HotkeysContextValue {\n defaultOptions: HotkeysProviderOptions\n}\n\nconst HotkeysContext = createContext<HotkeysContextValue | null>(null)\n\nexport interface HotkeysProviderProps {\n children: JSX.Element\n defaultOptions?: HotkeysProviderOptions\n}\n\nconst DEFAULT_OPTIONS: HotkeysProviderOptions = {}\n\nexport const HotkeysProvider: ParentComponent<HotkeysProviderProps> = (\n props,\n) => {\n const contextValue: HotkeysContextValue = {\n defaultOptions: props.defaultOptions ?? DEFAULT_OPTIONS,\n }\n\n return (\n <HotkeysContext.Provider value={contextValue}>\n {props.children}\n </HotkeysContext.Provider>\n )\n}\n\nexport function useHotkeysContext() {\n return useContext(HotkeysContext)\n}\n\nexport function useDefaultHotkeysOptions() {\n const context = useContext(HotkeysContext)\n return context?.defaultOptions ?? {}\n}\n"],"mappings":";;;;AAgBA,MAAMc,iBAAiBd,cAA0C,KAAK;AAOtE,MAAMkB,kBAA0C,EAAE;AAElD,MAAaC,mBACXC,UACG;CACH,MAAMC,eAAoC,EACxCR,gBAAgBO,MAAMP,kBAAkBK,iBACzC;AAED,QAAAI,gBACGR,eAAeS,UAAQ;EAACC,OAAOH;EAAY,IAAAL,WAAA;AAAA,UACzCI,MAAMJ;;EAAQ,CAAA;;AAKrB,SAAgBS,oBAAoB;AAClC,QAAOxB,WAAWa,eAAe;;AAGnC,SAAgBY,2BAA2B;AAEzC,QADgBzB,WAAWa,eAAe,EAC1BD,kBAAkB,EAAE"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
let _tanstack_hotkeys = require("@tanstack/hotkeys");
|
|
2
|
+
let _tanstack_solid_store = require("@tanstack/solid-store");
|
|
3
|
+
|
|
4
|
+
//#region src/createHeldKeyCodes.ts
|
|
5
|
+
/**
|
|
6
|
+
* SolidJS primitive that returns a signal of a map from currently held key names to their physical `event.code` values.
|
|
7
|
+
*
|
|
8
|
+
* This is useful for debugging which physical key was pressed (e.g. distinguishing
|
|
9
|
+
* left vs right Shift via "ShiftLeft" / "ShiftRight").
|
|
10
|
+
*
|
|
11
|
+
* This primitive uses `useStore` from `@tanstack/solid-store` to subscribe
|
|
12
|
+
* to the global KeyStateTracker.
|
|
13
|
+
*
|
|
14
|
+
* @returns Signal accessor for record mapping normalized key names to their `event.code` values
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```tsx
|
|
18
|
+
* function KeyDebugDisplay() {
|
|
19
|
+
* const heldKeys = createHeldKeys()
|
|
20
|
+
* const heldCodes = createHeldKeyCodes()
|
|
21
|
+
*
|
|
22
|
+
* return (
|
|
23
|
+
* <div>
|
|
24
|
+
* <For each={heldKeys()}>
|
|
25
|
+
* {(key) => (
|
|
26
|
+
* <kbd>
|
|
27
|
+
* {key} <small>{heldCodes()[key]}</small>
|
|
28
|
+
* </kbd>
|
|
29
|
+
* )}
|
|
30
|
+
* </For>
|
|
31
|
+
* </div>
|
|
32
|
+
* )
|
|
33
|
+
* }
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
function createHeldKeyCodes() {
|
|
37
|
+
return (0, _tanstack_solid_store.useStore)((0, _tanstack_hotkeys.getKeyStateTracker)().store, (state) => state.heldCodes);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
//#endregion
|
|
41
|
+
exports.createHeldKeyCodes = createHeldKeyCodes;
|
|
42
|
+
//# sourceMappingURL=createHeldKeyCodes.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createHeldKeyCodes.cjs","names":[],"sources":["../src/createHeldKeyCodes.ts"],"sourcesContent":["import { useStore } from '@tanstack/solid-store'\nimport { getKeyStateTracker } from '@tanstack/hotkeys'\n\n/**\n * SolidJS primitive that returns a signal of a map from currently held key names to their physical `event.code` values.\n *\n * This is useful for debugging which physical key was pressed (e.g. distinguishing\n * left vs right Shift via \"ShiftLeft\" / \"ShiftRight\").\n *\n * This primitive uses `useStore` from `@tanstack/solid-store` to subscribe\n * to the global KeyStateTracker.\n *\n * @returns Signal accessor for record mapping normalized key names to their `event.code` values\n *\n * @example\n * ```tsx\n * function KeyDebugDisplay() {\n * const heldKeys = createHeldKeys()\n * const heldCodes = createHeldKeyCodes()\n *\n * return (\n * <div>\n * <For each={heldKeys()}>\n * {(key) => (\n * <kbd>\n * {key} <small>{heldCodes()[key]}</small>\n * </kbd>\n * )}\n * </For>\n * </div>\n * )\n * }\n * ```\n */\nexport function createHeldKeyCodes(): () => Record<string, string> {\n const tracker = getKeyStateTracker()\n return useStore(tracker.store, (state) => state.heldCodes)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCA,SAAgB,qBAAmD;AAEjE,uFADoC,CACZ,QAAQ,UAAU,MAAM,UAAU"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
//#region src/createHeldKeyCodes.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* SolidJS primitive that returns a signal of a map from currently held key names to their physical `event.code` values.
|
|
4
|
+
*
|
|
5
|
+
* This is useful for debugging which physical key was pressed (e.g. distinguishing
|
|
6
|
+
* left vs right Shift via "ShiftLeft" / "ShiftRight").
|
|
7
|
+
*
|
|
8
|
+
* This primitive uses `useStore` from `@tanstack/solid-store` to subscribe
|
|
9
|
+
* to the global KeyStateTracker.
|
|
10
|
+
*
|
|
11
|
+
* @returns Signal accessor for record mapping normalized key names to their `event.code` values
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```tsx
|
|
15
|
+
* function KeyDebugDisplay() {
|
|
16
|
+
* const heldKeys = createHeldKeys()
|
|
17
|
+
* const heldCodes = createHeldKeyCodes()
|
|
18
|
+
*
|
|
19
|
+
* return (
|
|
20
|
+
* <div>
|
|
21
|
+
* <For each={heldKeys()}>
|
|
22
|
+
* {(key) => (
|
|
23
|
+
* <kbd>
|
|
24
|
+
* {key} <small>{heldCodes()[key]}</small>
|
|
25
|
+
* </kbd>
|
|
26
|
+
* )}
|
|
27
|
+
* </For>
|
|
28
|
+
* </div>
|
|
29
|
+
* )
|
|
30
|
+
* }
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
declare function createHeldKeyCodes(): () => Record<string, string>;
|
|
34
|
+
//#endregion
|
|
35
|
+
export { createHeldKeyCodes };
|
|
36
|
+
//# sourceMappingURL=createHeldKeyCodes.d.cts.map
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
//#region src/createHeldKeyCodes.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* SolidJS primitive that returns a signal of a map from currently held key names to their physical `event.code` values.
|
|
4
|
+
*
|
|
5
|
+
* This is useful for debugging which physical key was pressed (e.g. distinguishing
|
|
6
|
+
* left vs right Shift via "ShiftLeft" / "ShiftRight").
|
|
7
|
+
*
|
|
8
|
+
* This primitive uses `useStore` from `@tanstack/solid-store` to subscribe
|
|
9
|
+
* to the global KeyStateTracker.
|
|
10
|
+
*
|
|
11
|
+
* @returns Signal accessor for record mapping normalized key names to their `event.code` values
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```tsx
|
|
15
|
+
* function KeyDebugDisplay() {
|
|
16
|
+
* const heldKeys = createHeldKeys()
|
|
17
|
+
* const heldCodes = createHeldKeyCodes()
|
|
18
|
+
*
|
|
19
|
+
* return (
|
|
20
|
+
* <div>
|
|
21
|
+
* <For each={heldKeys()}>
|
|
22
|
+
* {(key) => (
|
|
23
|
+
* <kbd>
|
|
24
|
+
* {key} <small>{heldCodes()[key]}</small>
|
|
25
|
+
* </kbd>
|
|
26
|
+
* )}
|
|
27
|
+
* </For>
|
|
28
|
+
* </div>
|
|
29
|
+
* )
|
|
30
|
+
* }
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
declare function createHeldKeyCodes(): () => Record<string, string>;
|
|
34
|
+
//#endregion
|
|
35
|
+
export { createHeldKeyCodes };
|
|
36
|
+
//# sourceMappingURL=createHeldKeyCodes.d.ts.map
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { getKeyStateTracker } from "@tanstack/hotkeys";
|
|
2
|
+
import { useStore } from "@tanstack/solid-store";
|
|
3
|
+
|
|
4
|
+
//#region src/createHeldKeyCodes.ts
|
|
5
|
+
/**
|
|
6
|
+
* SolidJS primitive that returns a signal of a map from currently held key names to their physical `event.code` values.
|
|
7
|
+
*
|
|
8
|
+
* This is useful for debugging which physical key was pressed (e.g. distinguishing
|
|
9
|
+
* left vs right Shift via "ShiftLeft" / "ShiftRight").
|
|
10
|
+
*
|
|
11
|
+
* This primitive uses `useStore` from `@tanstack/solid-store` to subscribe
|
|
12
|
+
* to the global KeyStateTracker.
|
|
13
|
+
*
|
|
14
|
+
* @returns Signal accessor for record mapping normalized key names to their `event.code` values
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```tsx
|
|
18
|
+
* function KeyDebugDisplay() {
|
|
19
|
+
* const heldKeys = createHeldKeys()
|
|
20
|
+
* const heldCodes = createHeldKeyCodes()
|
|
21
|
+
*
|
|
22
|
+
* return (
|
|
23
|
+
* <div>
|
|
24
|
+
* <For each={heldKeys()}>
|
|
25
|
+
* {(key) => (
|
|
26
|
+
* <kbd>
|
|
27
|
+
* {key} <small>{heldCodes()[key]}</small>
|
|
28
|
+
* </kbd>
|
|
29
|
+
* )}
|
|
30
|
+
* </For>
|
|
31
|
+
* </div>
|
|
32
|
+
* )
|
|
33
|
+
* }
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
function createHeldKeyCodes() {
|
|
37
|
+
return useStore(getKeyStateTracker().store, (state) => state.heldCodes);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
//#endregion
|
|
41
|
+
export { createHeldKeyCodes };
|
|
42
|
+
//# sourceMappingURL=createHeldKeyCodes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createHeldKeyCodes.js","names":[],"sources":["../src/createHeldKeyCodes.ts"],"sourcesContent":["import { useStore } from '@tanstack/solid-store'\nimport { getKeyStateTracker } from '@tanstack/hotkeys'\n\n/**\n * SolidJS primitive that returns a signal of a map from currently held key names to their physical `event.code` values.\n *\n * This is useful for debugging which physical key was pressed (e.g. distinguishing\n * left vs right Shift via \"ShiftLeft\" / \"ShiftRight\").\n *\n * This primitive uses `useStore` from `@tanstack/solid-store` to subscribe\n * to the global KeyStateTracker.\n *\n * @returns Signal accessor for record mapping normalized key names to their `event.code` values\n *\n * @example\n * ```tsx\n * function KeyDebugDisplay() {\n * const heldKeys = createHeldKeys()\n * const heldCodes = createHeldKeyCodes()\n *\n * return (\n * <div>\n * <For each={heldKeys()}>\n * {(key) => (\n * <kbd>\n * {key} <small>{heldCodes()[key]}</small>\n * </kbd>\n * )}\n * </For>\n * </div>\n * )\n * }\n * ```\n */\nexport function createHeldKeyCodes(): () => Record<string, string> {\n const tracker = getKeyStateTracker()\n return useStore(tracker.store, (state) => state.heldCodes)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCA,SAAgB,qBAAmD;AAEjE,QAAO,SADS,oBAAoB,CACZ,QAAQ,UAAU,MAAM,UAAU"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
let _tanstack_hotkeys = require("@tanstack/hotkeys");
|
|
2
|
+
let _tanstack_solid_store = require("@tanstack/solid-store");
|
|
3
|
+
|
|
4
|
+
//#region src/createHeldKeys.ts
|
|
5
|
+
/**
|
|
6
|
+
* SolidJS primitive that returns a signal of currently held keyboard keys.
|
|
7
|
+
*
|
|
8
|
+
* This primitive uses `useStore` from `@tanstack/solid-store` to subscribe
|
|
9
|
+
* to the global KeyStateTracker and updates whenever keys are pressed
|
|
10
|
+
* or released.
|
|
11
|
+
*
|
|
12
|
+
* @returns Signal accessor for array of currently held key names
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```tsx
|
|
16
|
+
* function KeyDisplay() {
|
|
17
|
+
* const heldKeys = createHeldKeys()
|
|
18
|
+
*
|
|
19
|
+
* return (
|
|
20
|
+
* <div>
|
|
21
|
+
* Currently pressed: {heldKeys().join(' + ') || 'None'}
|
|
22
|
+
* </div>
|
|
23
|
+
* )
|
|
24
|
+
* }
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
function createHeldKeys() {
|
|
28
|
+
return (0, _tanstack_solid_store.useStore)((0, _tanstack_hotkeys.getKeyStateTracker)().store, (state) => state.heldKeys);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
//#endregion
|
|
32
|
+
exports.createHeldKeys = createHeldKeys;
|
|
33
|
+
//# sourceMappingURL=createHeldKeys.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createHeldKeys.cjs","names":[],"sources":["../src/createHeldKeys.ts"],"sourcesContent":["import { useStore } from '@tanstack/solid-store'\nimport { getKeyStateTracker } from '@tanstack/hotkeys'\n\n/**\n * SolidJS primitive that returns a signal of currently held keyboard keys.\n *\n * This primitive uses `useStore` from `@tanstack/solid-store` to subscribe\n * to the global KeyStateTracker and updates whenever keys are pressed\n * or released.\n *\n * @returns Signal accessor for array of currently held key names\n *\n * @example\n * ```tsx\n * function KeyDisplay() {\n * const heldKeys = createHeldKeys()\n *\n * return (\n * <div>\n * Currently pressed: {heldKeys().join(' + ') || 'None'}\n * </div>\n * )\n * }\n * ```\n */\nexport function createHeldKeys(): () => Array<string> {\n const tracker = getKeyStateTracker()\n return useStore(tracker.store, (state) => state.heldKeys)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAyBA,SAAgB,iBAAsC;AAEpD,uFADoC,CACZ,QAAQ,UAAU,MAAM,SAAS"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
//#region src/createHeldKeys.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* SolidJS primitive that returns a signal of currently held keyboard keys.
|
|
4
|
+
*
|
|
5
|
+
* This primitive uses `useStore` from `@tanstack/solid-store` to subscribe
|
|
6
|
+
* to the global KeyStateTracker and updates whenever keys are pressed
|
|
7
|
+
* or released.
|
|
8
|
+
*
|
|
9
|
+
* @returns Signal accessor for array of currently held key names
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```tsx
|
|
13
|
+
* function KeyDisplay() {
|
|
14
|
+
* const heldKeys = createHeldKeys()
|
|
15
|
+
*
|
|
16
|
+
* return (
|
|
17
|
+
* <div>
|
|
18
|
+
* Currently pressed: {heldKeys().join(' + ') || 'None'}
|
|
19
|
+
* </div>
|
|
20
|
+
* )
|
|
21
|
+
* }
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
declare function createHeldKeys(): () => Array<string>;
|
|
25
|
+
//#endregion
|
|
26
|
+
export { createHeldKeys };
|
|
27
|
+
//# sourceMappingURL=createHeldKeys.d.cts.map
|