@tanstack/svelte-hotkeys 0.10.0 → 0.12.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/README.md +15 -1
- package/dist/createHotkeyRecorder.svelte.js +22 -32
- package/dist/createHotkeySequenceRecorder.svelte.js +28 -37
- package/dist/getHeldKeyCodesMap.svelte.js +4 -13
- package/dist/getHeldKeys.svelte.js +4 -13
- package/dist/getHotkeyHint.svelte.d.ts +13 -0
- package/dist/getHotkeyHint.svelte.js +36 -0
- package/dist/getHotkeyRegistrations.svelte.js +8 -17
- package/dist/getIsKeyHeld.svelte.js +6 -19
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/package.json +12 -10
- package/src/HotkeysCtx.ts +0 -61
- package/src/HotkeysProvider.svelte +0 -12
- package/src/createHotkey.svelte.ts +0 -179
- package/src/createHotkeyRecorder.svelte.ts +0 -118
- package/src/createHotkeySequence.svelte.ts +0 -207
- package/src/createHotkeySequenceRecorder.svelte.ts +0 -93
- package/src/createHotkeySequences.svelte.ts +0 -274
- package/src/createHotkeys.svelte.ts +0 -276
- package/src/getHeldKeyCodesMap.svelte.ts +0 -44
- package/src/getHeldKeys.svelte.ts +0 -40
- package/src/getHotkeyRegistrations.svelte.ts +0 -60
- package/src/getIsKeyHeld.svelte.ts +0 -68
- package/src/index.ts +0 -21
- package/src/internal.svelte.ts +0 -26
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import { getKeyStateTracker } from '@tanstack/hotkeys'
|
|
2
|
-
import { createStoreSubscriber } from './internal.svelte'
|
|
3
|
-
import type { IndividualKey } from '@tanstack/hotkeys'
|
|
4
|
-
|
|
5
|
-
export interface SvelteHeldKeyState {
|
|
6
|
-
readonly held: boolean
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
class HeldKeyState implements SvelteHeldKeyState {
|
|
10
|
-
#tracker = getKeyStateTracker()
|
|
11
|
-
#normalizedKey: string
|
|
12
|
-
#subscribe = createStoreSubscriber(this.#tracker.store)
|
|
13
|
-
|
|
14
|
-
constructor(key: IndividualKey) {
|
|
15
|
-
this.#normalizedKey = key.toLowerCase()
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
get held(): boolean {
|
|
19
|
-
this.#subscribe()
|
|
20
|
-
return this.#tracker.store.state.heldKeys.some(
|
|
21
|
-
(heldKey) => heldKey.toLowerCase() === this.#normalizedKey,
|
|
22
|
-
)
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Svelte function that returns reactive access to whether a specific key is currently being held.
|
|
28
|
-
*
|
|
29
|
-
* This function uses the global KeyStateTracker and updates whenever keys are pressed
|
|
30
|
-
* or released.
|
|
31
|
-
*
|
|
32
|
-
* @param key - The key to check (e.g., 'Shift', 'Control', 'A')
|
|
33
|
-
* @returns Object with a reactive `held` property
|
|
34
|
-
*
|
|
35
|
-
* @example
|
|
36
|
-
* ```svelte
|
|
37
|
-
* <script>
|
|
38
|
-
* import { getIsKeyHeld } from '@tanstack/svelte-hotkeys'
|
|
39
|
-
*
|
|
40
|
-
* const isShiftHeld = getIsKeyHeld('Shift')
|
|
41
|
-
* </script>
|
|
42
|
-
*
|
|
43
|
-
* <div>
|
|
44
|
-
* {isShiftHeld.held ? 'Shift is pressed!' : 'Press Shift'}
|
|
45
|
-
* </div>
|
|
46
|
-
* ```
|
|
47
|
-
*
|
|
48
|
-
* @example
|
|
49
|
-
* ```svelte
|
|
50
|
-
* <script>
|
|
51
|
-
* import { getIsKeyHeld } from '@tanstack/svelte-hotkeys'
|
|
52
|
-
*
|
|
53
|
-
* const isCtrlHeld = getIsKeyHeld('Control')
|
|
54
|
-
* const isShiftHeld = getIsKeyHeld('Shift')
|
|
55
|
-
* const isAltHeld = getIsKeyHeld('Alt')
|
|
56
|
-
* </script>
|
|
57
|
-
*
|
|
58
|
-
* <div>
|
|
59
|
-
* <span style:opacity={isCtrlHeld.held ? 1 : 0.3}>Ctrl</span>
|
|
60
|
-
* <span style:opacity={isShiftHeld.held ? 1 : 0.3}>Shift</span>
|
|
61
|
-
* <span style:opacity={isAltHeld.held ? 1 : 0.3}>Alt</span>
|
|
62
|
-
* </div>
|
|
63
|
-
* ```
|
|
64
|
-
*/
|
|
65
|
-
|
|
66
|
-
export function getIsKeyHeld(key: IndividualKey): SvelteHeldKeyState {
|
|
67
|
-
return new HeldKeyState(key)
|
|
68
|
-
}
|
package/src/index.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
// Re-export everything from the core package
|
|
2
|
-
export * from '@tanstack/hotkeys'
|
|
3
|
-
|
|
4
|
-
export * from './createHotkey.svelte'
|
|
5
|
-
export * from './createHotkeys.svelte'
|
|
6
|
-
export * from './createHotkeySequence.svelte'
|
|
7
|
-
export * from './createHotkeySequences.svelte'
|
|
8
|
-
export * from './createHotkeyRecorder.svelte'
|
|
9
|
-
export * from './createHotkeySequenceRecorder.svelte'
|
|
10
|
-
export * from './getHeldKeys.svelte'
|
|
11
|
-
export * from './getHotkeyRegistrations.svelte'
|
|
12
|
-
export * from './getHeldKeyCodesMap.svelte'
|
|
13
|
-
export * from './getIsKeyHeld.svelte'
|
|
14
|
-
export { default as HotkeysProvider } from './HotkeysProvider.svelte'
|
|
15
|
-
export {
|
|
16
|
-
DEFAULT_OPTIONS,
|
|
17
|
-
getDefaultHotkeysOptions,
|
|
18
|
-
getHotkeysContext,
|
|
19
|
-
setHotkeysContext,
|
|
20
|
-
} from './HotkeysCtx'
|
|
21
|
-
export type { HotkeysProviderOptions, HotkeysProviderProps } from './HotkeysCtx'
|
package/src/internal.svelte.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { createSubscriber } from 'svelte/reactivity'
|
|
2
|
-
|
|
3
|
-
export type MaybeGetter<T> = T | (() => T)
|
|
4
|
-
|
|
5
|
-
interface SubscribableStore<TState> {
|
|
6
|
-
state: TState
|
|
7
|
-
subscribe: (
|
|
8
|
-
listener: () => void,
|
|
9
|
-
) => (() => void) | { unsubscribe: () => void }
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export function resolveMaybeGetter<T>(value: MaybeGetter<T>): T {
|
|
13
|
-
return typeof value === 'function' ? (value as () => T)() : value
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export function createStoreSubscriber<TState>(
|
|
17
|
-
store: SubscribableStore<TState>,
|
|
18
|
-
): () => void {
|
|
19
|
-
return createSubscriber((update) => {
|
|
20
|
-
const subscription = store.subscribe(update)
|
|
21
|
-
|
|
22
|
-
return typeof subscription === 'function'
|
|
23
|
-
? subscription
|
|
24
|
-
: () => subscription.unsubscribe()
|
|
25
|
-
})
|
|
26
|
-
}
|