@octanejs/tanstack-hotkeys 0.0.21 → 0.0.23
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/package.json +17 -5
- package/src/useHotkey.ts +3 -2
- package/src/useHotkeySequence.ts +3 -2
- package/src/useHotkeySequences.ts +5 -4
- package/src/useHotkeys.ts +6 -5
- package/src/utils.ts +13 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@octanejs/tanstack-hotkeys",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.23",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -33,13 +33,25 @@
|
|
|
33
33
|
"@tanstack/hotkeys": "0.8.0"
|
|
34
34
|
},
|
|
35
35
|
"peerDependencies": {
|
|
36
|
-
"@octanejs/tanstack-store": "0.0.
|
|
37
|
-
"octane": "0.1.
|
|
36
|
+
"@octanejs/tanstack-store": "0.0.28",
|
|
37
|
+
"octane": "0.1.34"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
|
+
"@tanstack/react-hotkeys": "0.10.0",
|
|
41
|
+
"@tsrx/react": "^0.2.56",
|
|
42
|
+
"esbuild": "^0.28.1",
|
|
43
|
+
"react": "^19.2.7",
|
|
44
|
+
"react-dom": "^19.2.7",
|
|
40
45
|
"vitest": "^4.1.10",
|
|
41
|
-
"@
|
|
42
|
-
"
|
|
46
|
+
"@testing-library/react": "16.3.2",
|
|
47
|
+
"@vitejs/plugin-react": "^6.0.3",
|
|
48
|
+
"happy-dom": "^20.11.0",
|
|
49
|
+
"@tanstack/react-store": "^0.11.0",
|
|
50
|
+
"@types/react": "^19.2.17",
|
|
51
|
+
"@types/react-dom": "^19.2.3",
|
|
52
|
+
"@octanejs/tanstack-store": "0.0.28",
|
|
53
|
+
"octane": "0.1.34",
|
|
54
|
+
"@octanejs/testing-library": "0.1.31"
|
|
43
55
|
},
|
|
44
56
|
"scripts": {
|
|
45
57
|
"test": "vitest run --project tanstack-hotkeys",
|
package/src/useHotkey.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useEffect, useRef } from 'octane';
|
|
2
2
|
import { detectPlatform, getHotkeyManager, normalizeRegisterableHotkey } from '@tanstack/hotkeys';
|
|
3
3
|
import { useDefaultHotkeysOptions } from './context';
|
|
4
|
-
import { isRef } from './utils';
|
|
4
|
+
import { isRef, withoutSlotOption } from './utils';
|
|
5
5
|
import type { RefObjectLike } from './utils';
|
|
6
6
|
import type {
|
|
7
7
|
HotkeyCallback,
|
|
@@ -55,9 +55,10 @@ export function useHotkey(
|
|
|
55
55
|
callback: HotkeyCallback,
|
|
56
56
|
options: UseHotkeyOptions = {},
|
|
57
57
|
): void {
|
|
58
|
+
const resolvedOptions = withoutSlotOption(options) ?? {};
|
|
58
59
|
const mergedOptions = {
|
|
59
60
|
...useDefaultHotkeysOptions().hotkey,
|
|
60
|
-
...
|
|
61
|
+
...resolvedOptions,
|
|
61
62
|
} as UseHotkeyOptions;
|
|
62
63
|
|
|
63
64
|
const manager = getHotkeyManager();
|
package/src/useHotkeySequence.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useEffect, useRef } from 'octane';
|
|
2
2
|
import { formatHotkeySequence, getSequenceManager } from '@tanstack/hotkeys';
|
|
3
3
|
import { useDefaultHotkeysOptions } from './context';
|
|
4
|
-
import { isRef } from './utils';
|
|
4
|
+
import { isRef, withoutSlotOption } from './utils';
|
|
5
5
|
import type { RefObjectLike } from './utils';
|
|
6
6
|
import type {
|
|
7
7
|
HotkeyCallback,
|
|
@@ -58,9 +58,10 @@ export function useHotkeySequence(
|
|
|
58
58
|
callback: HotkeyCallback,
|
|
59
59
|
options: UseHotkeySequenceOptions = {},
|
|
60
60
|
): void {
|
|
61
|
+
const resolvedOptions = withoutSlotOption(options) ?? {};
|
|
61
62
|
const mergedOptions = {
|
|
62
63
|
...useDefaultHotkeysOptions().hotkeySequence,
|
|
63
|
-
...
|
|
64
|
+
...resolvedOptions,
|
|
64
65
|
} as UseHotkeySequenceOptions;
|
|
65
66
|
|
|
66
67
|
const manager = getSequenceManager();
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useEffect, useRef } from 'octane';
|
|
2
2
|
import { formatHotkeySequence, getSequenceManager } from '@tanstack/hotkeys';
|
|
3
3
|
import { useDefaultHotkeysOptions } from './context';
|
|
4
|
-
import { isRef } from './utils';
|
|
4
|
+
import { isRef, withoutSlotOption } from './utils';
|
|
5
5
|
import type { UseHotkeySequenceOptions } from './useHotkeySequence';
|
|
6
6
|
import type { HotkeyCallback, HotkeySequence, SequenceRegistrationHandle } from '@tanstack/hotkeys';
|
|
7
7
|
|
|
@@ -56,13 +56,14 @@ export function useHotkeySequences(
|
|
|
56
56
|
target: Document | HTMLElement | Window;
|
|
57
57
|
};
|
|
58
58
|
|
|
59
|
+
const resolvedCommonOptions = withoutSlotOption(commonOptions) ?? {};
|
|
59
60
|
const defaultOptions = useDefaultHotkeysOptions().hotkeySequence;
|
|
60
61
|
const manager = getSequenceManager();
|
|
61
62
|
|
|
62
63
|
const registrationsRef = useRef<Map<string, RegistrationRecord>>(new Map());
|
|
63
64
|
const definitionsRef = useRef(definitions);
|
|
64
65
|
const sequenceStringsRef = useRef<Array<string>>([]);
|
|
65
|
-
const commonOptionsRef = useRef(
|
|
66
|
+
const commonOptionsRef = useRef(resolvedCommonOptions);
|
|
66
67
|
const defaultOptionsRef = useRef(defaultOptions);
|
|
67
68
|
const managerRef = useRef(manager);
|
|
68
69
|
|
|
@@ -70,7 +71,7 @@ export function useHotkeySequences(
|
|
|
70
71
|
|
|
71
72
|
definitionsRef.current = definitions;
|
|
72
73
|
sequenceStringsRef.current = sequenceStrings;
|
|
73
|
-
commonOptionsRef.current =
|
|
74
|
+
commonOptionsRef.current = resolvedCommonOptions;
|
|
74
75
|
defaultOptionsRef.current = defaultOptions;
|
|
75
76
|
managerRef.current = manager;
|
|
76
77
|
|
|
@@ -177,7 +178,7 @@ export function useHotkeySequences(
|
|
|
177
178
|
handle.callback = def.callback;
|
|
178
179
|
const mergedOptions = {
|
|
179
180
|
...defaultOptions,
|
|
180
|
-
...
|
|
181
|
+
...resolvedCommonOptions,
|
|
181
182
|
...def.options,
|
|
182
183
|
} as UseHotkeySequenceOptions;
|
|
183
184
|
const { target: _target, ...optionsWithoutTarget } = mergedOptions;
|
package/src/useHotkeys.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useEffect, useRef } from 'octane';
|
|
2
2
|
import { detectPlatform, getHotkeyManager, normalizeRegisterableHotkey } from '@tanstack/hotkeys';
|
|
3
3
|
import { useDefaultHotkeysOptions } from './context';
|
|
4
|
-
import { isRef } from './utils';
|
|
4
|
+
import { isRef, withoutSlotOption } from './utils';
|
|
5
5
|
import type { UseHotkeyOptions } from './useHotkey';
|
|
6
6
|
import type {
|
|
7
7
|
Hotkey,
|
|
@@ -60,14 +60,15 @@ export function useHotkeys(
|
|
|
60
60
|
target: Document | HTMLElement | Window;
|
|
61
61
|
};
|
|
62
62
|
|
|
63
|
+
const resolvedCommonOptions = withoutSlotOption(commonOptions) ?? {};
|
|
63
64
|
const defaultOptions = useDefaultHotkeysOptions().hotkey;
|
|
64
65
|
const manager = getHotkeyManager();
|
|
65
|
-
const platform =
|
|
66
|
+
const platform = resolvedCommonOptions.platform ?? defaultOptions?.platform ?? detectPlatform();
|
|
66
67
|
|
|
67
68
|
const registrationsRef = useRef<Map<string, RegistrationRecord>>(new Map());
|
|
68
69
|
const hotkeysRef = useRef(hotkeys);
|
|
69
70
|
const hotkeyStringsRef = useRef<Array<Hotkey>>([]);
|
|
70
|
-
const commonOptionsRef = useRef(
|
|
71
|
+
const commonOptionsRef = useRef(resolvedCommonOptions);
|
|
71
72
|
const defaultOptionsRef = useRef(defaultOptions);
|
|
72
73
|
const managerRef = useRef(manager);
|
|
73
74
|
|
|
@@ -75,7 +76,7 @@ export function useHotkeys(
|
|
|
75
76
|
|
|
76
77
|
hotkeysRef.current = hotkeys;
|
|
77
78
|
hotkeyStringsRef.current = hotkeyStrings;
|
|
78
|
-
commonOptionsRef.current =
|
|
79
|
+
commonOptionsRef.current = resolvedCommonOptions;
|
|
79
80
|
defaultOptionsRef.current = defaultOptions;
|
|
80
81
|
managerRef.current = manager;
|
|
81
82
|
|
|
@@ -176,7 +177,7 @@ export function useHotkeys(
|
|
|
176
177
|
handle.callback = def.callback;
|
|
177
178
|
const mergedOptions = {
|
|
178
179
|
...defaultOptions,
|
|
179
|
-
...
|
|
180
|
+
...resolvedCommonOptions,
|
|
180
181
|
...def.options,
|
|
181
182
|
} as UseHotkeyOptions;
|
|
182
183
|
const { target: _target, ...optionsWithoutTarget } = mergedOptions;
|
package/src/utils.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* A React-19-style ref object shape (Octane refs are ordinary objects with a
|
|
3
3
|
* mutable `current`).
|
|
4
|
+
*
|
|
5
|
+
* OCTANE DIVERGENCE[plain-ref-target][types:adapted-octane]
|
|
4
6
|
*/
|
|
5
7
|
export interface RefObjectLike<T> {
|
|
6
8
|
current: T;
|
|
@@ -12,3 +14,14 @@ export interface RefObjectLike<T> {
|
|
|
12
14
|
export function isRef(value: unknown): value is RefObjectLike<HTMLElement | null> {
|
|
13
15
|
return value !== null && typeof value === 'object' && 'current' in value;
|
|
14
16
|
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Octane call sites append a compiler slot Symbol after optional trailing
|
|
20
|
+
* parameters. Treat that Symbol as "argument omitted" so `= {}` defaults apply.
|
|
21
|
+
*/
|
|
22
|
+
export function withoutSlotOption<T extends object>(
|
|
23
|
+
options: T | symbol | undefined,
|
|
24
|
+
): T | undefined {
|
|
25
|
+
if (typeof options === 'symbol' || options === undefined) return undefined;
|
|
26
|
+
return options;
|
|
27
|
+
}
|