@tanstack/react-hotkeys 0.17.0 → 0.19.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/dist/HotkeysProvider.d.ts +2 -2
- package/dist/HotkeysProvider.js +5 -3
- package/dist/_appHotkeysStore.js +5 -2
- package/dist/_useSelector.js +29 -0
- package/dist/useAppHotkeys.js +2 -0
- package/dist/useHeldKeyCodes.js +3 -1
- package/dist/useHeldKeys.d.ts +1 -2
- package/dist/useHeldKeys.js +4 -3
- package/dist/useHotkey.js +2 -0
- package/dist/useHotkeyHint.js +3 -1
- package/dist/useHotkeyRecorder.js +3 -1
- package/dist/useHotkeyRegistrations.js +3 -1
- package/dist/useHotkeyScopesState.js +3 -1
- package/dist/useHotkeys.js +2 -0
- package/dist/useKeyHold.d.ts +1 -2
- package/dist/useKeyHold.js +4 -3
- package/package.json +5 -5
- package/skills/react-hotkeys/SKILL.md +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { UseHotkeyCommonOptions } from "./useHotkey.js";
|
|
2
2
|
import { AppHotkeys, AppHotkeysStore, CustomHotkeys, HotkeyChordRecorderOptions, HotkeySequenceRecorderOptions } from "@tanstack/hotkeys";
|
|
3
|
-
import
|
|
3
|
+
import { ReactElement, ReactNode } from "react";
|
|
4
4
|
import { HotkeysProviderScopeProps } from "@tanstack/hotkeys/adapter";
|
|
5
5
|
//#region src/HotkeysProvider.d.ts
|
|
6
6
|
export interface HotkeysProviderOptions {
|
|
@@ -67,7 +67,7 @@ export interface HotkeysProviderProps<T extends AppHotkeys = AppHotkeys> extends
|
|
|
67
67
|
* }
|
|
68
68
|
* ```
|
|
69
69
|
*/
|
|
70
|
-
export declare function HotkeysProvider<T extends AppHotkeys = AppHotkeys>({ children, appHotkeys, customHotkeys, onCustomHotkeysChange, defaultOptions, scope, exclusive, enabled }: HotkeysProviderProps<T>):
|
|
70
|
+
export declare function HotkeysProvider<T extends AppHotkeys = AppHotkeys>({ children, appHotkeys, customHotkeys, onCustomHotkeysChange, defaultOptions, scope, exclusive, enabled }: HotkeysProviderProps<T>): ReactElement;
|
|
71
71
|
export declare function useHotkeysContext(): HotkeysContextValue | null;
|
|
72
72
|
export declare function useDefaultHotkeysOptions(): HotkeysProviderOptions;
|
|
73
73
|
//#endregion
|
package/dist/HotkeysProvider.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { publishAppHotkeysStore } from "@tanstack/hotkeys";
|
|
2
4
|
import React, { createContext, useContext, useEffect, useMemo, useState } from "react";
|
|
3
|
-
import { activateHotkeysProviderScope, getHotkeysProviderScopeKey, mergeHotkeysProviderDefaults } from "@tanstack/hotkeys/adapter";
|
|
5
|
+
import { activateHotkeysProviderScope, createAppHotkeysStore, getHotkeysProviderScopeKey, mergeHotkeysProviderDefaults } from "@tanstack/hotkeys/adapter";
|
|
4
6
|
|
|
5
7
|
//#region src/HotkeysProvider.tsx
|
|
6
8
|
const HotkeysContext = createContext(null);
|
|
@@ -43,7 +45,7 @@ const NO_PARENT = {
|
|
|
43
45
|
*/
|
|
44
46
|
function HotkeysProvider({ children, appHotkeys, customHotkeys, onCustomHotkeysChange, defaultOptions = DEFAULT_OPTIONS, scope, exclusive = false, enabled = true }) {
|
|
45
47
|
const parent = useContext(HotkeysContext) ?? NO_PARENT;
|
|
46
|
-
const [store] = useState(() => appHotkeys ?
|
|
48
|
+
const [store] = useState(() => appHotkeys ? createAppHotkeysStore(appHotkeys, {
|
|
47
49
|
customHotkeys,
|
|
48
50
|
onCustomHotkeysChange
|
|
49
51
|
}) : null);
|
package/dist/_appHotkeysStore.js
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
1
3
|
import { useHotkeysContext } from "./HotkeysProvider.js";
|
|
2
|
-
import {
|
|
4
|
+
import { useSelector } from "./_useSelector.js";
|
|
5
|
+
import { createStore } from "@tanstack/hotkeys/adapter";
|
|
3
6
|
|
|
4
7
|
//#region src/_appHotkeysStore.ts
|
|
5
|
-
const NO_APP_HOTKEYS =
|
|
8
|
+
const NO_APP_HOTKEYS = createStore(null);
|
|
6
9
|
/**
|
|
7
10
|
* The provider's app hotkeys store, re-rendering when app hotkeys or custom
|
|
8
11
|
* hotkeys change. Null outside a provider with `appHotkeys`.
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { useCallback, useRef, useSyncExternalStore } from "react";
|
|
4
|
+
|
|
5
|
+
//#region src/_useSelector.ts
|
|
6
|
+
/**
|
|
7
|
+
* Subscribes to a store and returns the selected value, re-rendering when it
|
|
8
|
+
* changes (by `Object.is`). The selector runs again only when the store's
|
|
9
|
+
* state or the selector itself changes.
|
|
10
|
+
*/
|
|
11
|
+
function useSelector(store, selector) {
|
|
12
|
+
const subscribe = useCallback((onChange) => store.subscribe(onChange).unsubscribe, [store]);
|
|
13
|
+
const memo = useRef(null);
|
|
14
|
+
const getSelection = () => {
|
|
15
|
+
const state = store.get();
|
|
16
|
+
const last = memo.current;
|
|
17
|
+
if (last && last.selector === selector && Object.is(last.state, state)) return last.selected;
|
|
18
|
+
memo.current = {
|
|
19
|
+
state,
|
|
20
|
+
selector,
|
|
21
|
+
selected: selector(state)
|
|
22
|
+
};
|
|
23
|
+
return memo.current.selected;
|
|
24
|
+
};
|
|
25
|
+
return useSyncExternalStore(subscribe, getSelection, getSelection);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
//#endregion
|
|
29
|
+
export { useSelector };
|
package/dist/useAppHotkeys.js
CHANGED
package/dist/useHeldKeyCodes.js
CHANGED
package/dist/useHeldKeys.d.ts
CHANGED
|
@@ -2,8 +2,7 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* React hook that returns an array of currently held keyboard keys.
|
|
4
4
|
*
|
|
5
|
-
* This hook
|
|
6
|
-
* to the global KeyStateTracker and updates whenever keys are pressed
|
|
5
|
+
* This hook subscribes to the global KeyStateTracker and updates whenever keys are pressed
|
|
7
6
|
* or released.
|
|
8
7
|
*
|
|
9
8
|
* @returns Array of currently held key names
|
package/dist/useHeldKeys.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { useSelector } from "./_useSelector.js";
|
|
1
4
|
import { getKeyStateTracker } from "@tanstack/hotkeys";
|
|
2
|
-
import { useSelector } from "@tanstack/react-store";
|
|
3
5
|
|
|
4
6
|
//#region src/useHeldKeys.ts
|
|
5
7
|
/**
|
|
6
8
|
* React hook that returns an array of currently held keyboard keys.
|
|
7
9
|
*
|
|
8
|
-
* This hook
|
|
9
|
-
* to the global KeyStateTracker and updates whenever keys are pressed
|
|
10
|
+
* This hook subscribes to the global KeyStateTracker and updates whenever keys are pressed
|
|
10
11
|
* or released.
|
|
11
12
|
*
|
|
12
13
|
* @returns Array of currently held key names
|
package/dist/useHotkey.js
CHANGED
package/dist/useHotkeyHint.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { useSelector } from "./_useSelector.js";
|
|
1
4
|
import { useAppHotkeysStoreState } from "./_appHotkeysStore.js";
|
|
2
5
|
import { getHotkeyManager, getKeyStateTracker, isAppHotkey, matchesHeldModifiers, resolveAppHotkey } from "@tanstack/hotkeys";
|
|
3
|
-
import { useSelector } from "@tanstack/react-store";
|
|
4
6
|
|
|
5
7
|
//#region src/useHotkeyHint.ts
|
|
6
8
|
/**
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
1
3
|
import { useDefaultHotkeysOptions } from "./HotkeysProvider.js";
|
|
4
|
+
import { useSelector } from "./_useSelector.js";
|
|
2
5
|
import { HotkeyRecorder } from "@tanstack/hotkeys";
|
|
3
6
|
import { useEffect, useRef } from "react";
|
|
4
|
-
import { useSelector } from "@tanstack/react-store";
|
|
5
7
|
|
|
6
8
|
//#region src/useHotkeyRecorder.ts
|
|
7
9
|
function useHotkeyRecorder(options) {
|
package/dist/useHotkeys.js
CHANGED
package/dist/useKeyHold.d.ts
CHANGED
|
@@ -3,8 +3,7 @@ import { IndividualKey } from "@tanstack/hotkeys";
|
|
|
3
3
|
/**
|
|
4
4
|
* React hook that returns whether a specific key is currently being held.
|
|
5
5
|
*
|
|
6
|
-
* This hook uses
|
|
7
|
-
* to the global KeyStateTracker and uses a selector to determine if
|
|
6
|
+
* This hook subscribes to the global KeyStateTracker and uses a selector to determine if
|
|
8
7
|
* the specified key is held.
|
|
9
8
|
*
|
|
10
9
|
* @param key - The key to check (e.g., 'Shift', 'Control', 'A')
|
package/dist/useKeyHold.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { useSelector } from "./_useSelector.js";
|
|
1
4
|
import { getKeyStateTracker } from "@tanstack/hotkeys";
|
|
2
|
-
import { useSelector } from "@tanstack/react-store";
|
|
3
5
|
|
|
4
6
|
//#region src/useKeyHold.ts
|
|
5
7
|
/**
|
|
6
8
|
* React hook that returns whether a specific key is currently being held.
|
|
7
9
|
*
|
|
8
|
-
* This hook uses
|
|
9
|
-
* to the global KeyStateTracker and uses a selector to determine if
|
|
10
|
+
* This hook subscribes to the global KeyStateTracker and uses a selector to determine if
|
|
10
11
|
* the specified key is held.
|
|
11
12
|
*
|
|
12
13
|
* @param key - The key to check (e.g., 'Shift', 'Control', 'A')
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/react-hotkeys",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.19.0",
|
|
4
4
|
"description": "React adapter for TanStack Hotkeys",
|
|
5
5
|
"author": "Tanner Linsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -35,11 +35,11 @@
|
|
|
35
35
|
"skills"
|
|
36
36
|
],
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@tanstack/hotkeys": "0.
|
|
39
|
-
"@tanstack/react-store": "^0.11.2"
|
|
38
|
+
"@tanstack/hotkeys": "0.20.0"
|
|
40
39
|
},
|
|
41
40
|
"devDependencies": {
|
|
42
41
|
"@eslint-react/eslint-plugin": "^4.2.3",
|
|
42
|
+
"@tanstack/react-store": "^0.11.2",
|
|
43
43
|
"@testing-library/react": "^16.3.3",
|
|
44
44
|
"@types/react": "^19.3.0",
|
|
45
45
|
"@vitejs/plugin-react": "^6.1.1",
|
|
@@ -49,8 +49,8 @@
|
|
|
49
49
|
"react-dom": "^19.3.0"
|
|
50
50
|
},
|
|
51
51
|
"peerDependencies": {
|
|
52
|
-
"react": ">=
|
|
53
|
-
"react-dom": ">=
|
|
52
|
+
"react": ">=18.0.0",
|
|
53
|
+
"react-dom": ">=18.0.0"
|
|
54
54
|
},
|
|
55
55
|
"scripts": {
|
|
56
56
|
"clean": "premove ./build ./dist",
|
|
@@ -68,7 +68,7 @@ export function SaveButton({ onSave }: { onSave: () => void }) {
|
|
|
68
68
|
|
|
69
69
|
The package also re-exports `@tanstack/hotkeys`, such as `formatForDisplay`, `matchesKeyboardEvent`, and `defineAppHotkeys`.
|
|
70
70
|
|
|
71
|
-
No provider is required. In React Server Components frameworks,
|
|
71
|
+
No provider is required. In React Server Components frameworks, call the hooks from client components. The package marks `HotkeysProvider` as a client component, so a server layout can render it without a `'use client'` wrapper.
|
|
72
72
|
|
|
73
73
|
## A dialog that owns the keyboard
|
|
74
74
|
|