@tanstack/octane-hotkeys 0.7.1 → 0.8.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.js +3 -3
- package/dist/internal.js +25 -4
- package/dist/useHeldKeyCodes.js +1 -1
- package/dist/useHeldKeys.js +1 -1
- package/dist/useHotkeyHint.js +2 -2
- package/dist/useHotkeyRecorder.js +1 -1
- package/dist/useHotkeyRegistrations.js +1 -1
- package/dist/useHotkeyScopesState.js +1 -1
- package/dist/useKeyHold.js +1 -1
- package/package.json +2 -3
package/dist/HotkeysProvider.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { subSlot } from "./internal.js";
|
|
2
|
-
import {
|
|
2
|
+
import { publishAppHotkeysStore } from "@tanstack/hotkeys";
|
|
3
3
|
import { createContext, createElement, useContext, useLayoutEffect, useRef } from "octane";
|
|
4
|
-
import { activateHotkeysProviderScope, getHotkeysProviderScopeKey, mergeHotkeysProviderDefaults } from "@tanstack/hotkeys/adapter";
|
|
4
|
+
import { activateHotkeysProviderScope, createAppHotkeysStore, getHotkeysProviderScopeKey, mergeHotkeysProviderDefaults } from "@tanstack/hotkeys/adapter";
|
|
5
5
|
|
|
6
6
|
//#region src/HotkeysProvider.ts
|
|
7
7
|
const HotkeysContext = createContext(null);
|
|
@@ -25,7 +25,7 @@ function HotkeysProvider({ children, defaultOptions, appHotkeys, customHotkeys,
|
|
|
25
25
|
const callbackRef = useRef(onCustomHotkeysChange, subSlot(void 0, "provider-callback"));
|
|
26
26
|
callbackRef.current = onCustomHotkeysChange;
|
|
27
27
|
const storeRef = useRef(void 0, subSlot(void 0, "provider-store"));
|
|
28
|
-
storeRef.current ??= appHotkeys ?
|
|
28
|
+
storeRef.current ??= appHotkeys ? createAppHotkeysStore(appHotkeys, {
|
|
29
29
|
customHotkeys,
|
|
30
30
|
onCustomHotkeysChange: (custom) => callbackRef.current?.(custom)
|
|
31
31
|
}) : null;
|
package/dist/internal.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useCallback, useRef, useSyncExternalStore } from "octane";
|
|
2
|
+
import { createStore } from "@tanstack/hotkeys/adapter";
|
|
2
3
|
|
|
3
4
|
//#region src/internal.ts
|
|
4
5
|
const subSlotCache = /* @__PURE__ */ new Map();
|
|
@@ -29,14 +30,34 @@ function splitSlot(args) {
|
|
|
29
30
|
const slot = typeof tail === "symbol" ? tail : void 0;
|
|
30
31
|
return [slot === void 0 ? args : args.slice(0, -1), slot];
|
|
31
32
|
}
|
|
32
|
-
|
|
33
|
-
|
|
33
|
+
/**
|
|
34
|
+
* Subscribes to a store and returns the selected value, re-rendering when it
|
|
35
|
+
* changes (by `Object.is`). The selector runs again only when the store's
|
|
36
|
+
* state or the selector itself changes.
|
|
37
|
+
*/
|
|
38
|
+
function select(store, selector, slot) {
|
|
39
|
+
const subscribe = useCallback((onChange) => store.subscribe(onChange).unsubscribe, [store], subSlot(slot, "select:subscribe"));
|
|
40
|
+
const memo = useRef(null, subSlot(slot, "select:memo"));
|
|
41
|
+
const getSelection = () => {
|
|
42
|
+
const state = store.get();
|
|
43
|
+
const last = memo.current;
|
|
44
|
+
if (last && last.selector === selector && Object.is(last.state, state)) return last.selected;
|
|
45
|
+
memo.current = {
|
|
46
|
+
state,
|
|
47
|
+
selector,
|
|
48
|
+
selected: selector(state)
|
|
49
|
+
};
|
|
50
|
+
return memo.current.selected;
|
|
51
|
+
};
|
|
52
|
+
return useSyncExternalStore(subscribe, getSelection, getSelection, subSlot(slot, "select:store"));
|
|
53
|
+
}
|
|
54
|
+
const NO_APP_HOTKEYS = createStore(null);
|
|
34
55
|
/**
|
|
35
56
|
* Re-renders when the provider's app hotkeys or custom hotkeys change and
|
|
36
57
|
* returns the provider's store.
|
|
37
58
|
*/
|
|
38
59
|
function useAppHotkeysStore(store, slot) {
|
|
39
|
-
select(store?.store ?? NO_APP_HOTKEYS, (value) => value,
|
|
60
|
+
select(store?.store ?? NO_APP_HOTKEYS, (value) => value, slot);
|
|
40
61
|
return store;
|
|
41
62
|
}
|
|
42
63
|
|
package/dist/useHeldKeyCodes.js
CHANGED
|
@@ -3,7 +3,7 @@ import { getKeyStateTracker } from "@tanstack/hotkeys";
|
|
|
3
3
|
|
|
4
4
|
//#region src/useHeldKeyCodes.ts
|
|
5
5
|
function useHeldKeyCodes(slot) {
|
|
6
|
-
return select(getKeyStateTracker().store, (state) => state.heldCodes,
|
|
6
|
+
return select(getKeyStateTracker().store, (state) => state.heldCodes, subSlot(slot, "held-codes"));
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
//#endregion
|
package/dist/useHeldKeys.js
CHANGED
|
@@ -3,7 +3,7 @@ import { getKeyStateTracker } from "@tanstack/hotkeys";
|
|
|
3
3
|
|
|
4
4
|
//#region src/useHeldKeys.ts
|
|
5
5
|
function useHeldKeys(slot) {
|
|
6
|
-
return select(getKeyStateTracker().store, (state) => state.heldKeys,
|
|
6
|
+
return select(getKeyStateTracker().store, (state) => state.heldKeys, subSlot(slot, "held-keys"));
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
//#endregion
|
package/dist/useHotkeyHint.js
CHANGED
|
@@ -8,8 +8,8 @@ function useHotkeyHint(hotkey, ...rest) {
|
|
|
8
8
|
const store = useAppHotkeysStore(useHotkeysContext()?.appHotkeysStore ?? null, subSlot(slot, "app-hotkeys"));
|
|
9
9
|
const resolved = isAppHotkey(hotkey) ? resolveAppHotkey(hotkey, store).hotkey : hotkey;
|
|
10
10
|
const manager = getHotkeyManager();
|
|
11
|
-
const active = select(manager.registrations, () => resolved !== null && manager.hasActiveRegistration(hotkey),
|
|
12
|
-
const held = select(getKeyStateTracker().store, (state) => resolved !== null && matchesHeldModifiers(resolved, state.heldKeys, args[0]),
|
|
11
|
+
const active = select(manager.registrations, () => resolved !== null && manager.hasActiveRegistration(hotkey), subSlot(slot, "hint-active"));
|
|
12
|
+
const held = select(getKeyStateTracker().store, (state) => resolved !== null && matchesHeldModifiers(resolved, state.heldKeys, args[0]), subSlot(slot, "hint"));
|
|
13
13
|
return active && held;
|
|
14
14
|
}
|
|
15
15
|
|
|
@@ -17,7 +17,7 @@ function useHotkeyRecorder(options, slot) {
|
|
|
17
17
|
}, null, subSlot(slot, "options"));
|
|
18
18
|
useLayoutEffect(() => () => recorder.destroy(), [], subSlot(slot, "cleanup"));
|
|
19
19
|
return {
|
|
20
|
-
...select(recorder.store, (value) => value,
|
|
20
|
+
...select(recorder.store, (value) => value, subSlot(slot, "state")),
|
|
21
21
|
startRecording: () => recorder.start(),
|
|
22
22
|
stopRecording: () => recorder.stop(),
|
|
23
23
|
cancelRecording: () => recorder.cancel(),
|
|
@@ -3,7 +3,7 @@ import { getHotkeyManager, toHotkeyRegistrationView } from "@tanstack/hotkeys";
|
|
|
3
3
|
|
|
4
4
|
//#region src/useHotkeyRegistrations.ts
|
|
5
5
|
function useHotkeyRegistrations(slot) {
|
|
6
|
-
return { hotkeys: select(getHotkeyManager().registrations, (state) => Array.from(state.values()).map(toHotkeyRegistrationView),
|
|
6
|
+
return { hotkeys: select(getHotkeyManager().registrations, (state) => Array.from(state.values()).map(toHotkeyRegistrationView), subSlot(slot, "hotkeys")) };
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
//#endregion
|
|
@@ -3,7 +3,7 @@ import { getHotkeyManager } from "@tanstack/hotkeys";
|
|
|
3
3
|
|
|
4
4
|
//#region src/useHotkeyScopesState.ts
|
|
5
5
|
function useHotkeyScopesState(slot) {
|
|
6
|
-
return select(getHotkeyManager().scopes, (state) => state,
|
|
6
|
+
return select(getHotkeyManager().scopes, (state) => state, subSlot(slot, "hotkey-scopes-state"));
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
//#endregion
|
package/dist/useKeyHold.js
CHANGED
|
@@ -3,7 +3,7 @@ import { getKeyStateTracker } from "@tanstack/hotkeys";
|
|
|
3
3
|
|
|
4
4
|
//#region src/useKeyHold.ts
|
|
5
5
|
function useKeyHold(key, slot) {
|
|
6
|
-
return select(getKeyStateTracker().store, (state) => state.heldKeys.includes(key),
|
|
6
|
+
return select(getKeyStateTracker().store, (state) => state.heldKeys.includes(key), subSlot(slot, "key-hold"));
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
//#endregion
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/octane-hotkeys",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "Octane adapter for TanStack Hotkeys",
|
|
5
5
|
"author": "Tanner Linsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -35,8 +35,7 @@
|
|
|
35
35
|
"skills"
|
|
36
36
|
],
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@tanstack/hotkeys": "0.
|
|
39
|
-
"@tanstack/octane-store": "^0.13.0"
|
|
38
|
+
"@tanstack/hotkeys": "0.20.0"
|
|
40
39
|
},
|
|
41
40
|
"devDependencies": {
|
|
42
41
|
"@tsrx/oxc": "0.20.0",
|