@tanstack/solid-hotkeys 0.22.0 → 0.22.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/dist/HotkeysProvider.d.ts +3 -2
- package/dist/HotkeysProvider.js +20 -18
- package/dist/appHotkeys.js +10 -9
- package/dist/defaultOptions.js +13 -6
- package/package.json +2 -2
|
@@ -27,8 +27,9 @@ interface HotkeysContextValue {
|
|
|
27
27
|
export interface HotkeysProviderProps extends HotkeysProviderScopeProps {
|
|
28
28
|
children: JSX.Element;
|
|
29
29
|
/**
|
|
30
|
-
* Every app hotkey, from `defineAppHotkeys`.
|
|
31
|
-
*
|
|
30
|
+
* Every app hotkey, from `defineAppHotkeys`. Listed by `createAppHotkeyList`
|
|
31
|
+
* whether or not they are registered. It can start as `undefined` and arrive
|
|
32
|
+
* later, such as from a lazy import.
|
|
32
33
|
*/
|
|
33
34
|
appHotkeys?: AppHotkeys;
|
|
34
35
|
/**
|
package/dist/HotkeysProvider.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { publishAppHotkeysStore } from "@tanstack/hotkeys";
|
|
2
2
|
import { createComponent } from "solid-js/web";
|
|
3
3
|
import { activateHotkeysProviderScope, createAppHotkeysStore, getHotkeysProviderScopeKey, mergeHotkeysProviderDefaults } from "@tanstack/hotkeys/adapter";
|
|
4
|
-
import { createContext, createEffect, createMemo, onCleanup,
|
|
4
|
+
import { createContext, createEffect, createMemo, onCleanup, untrack, useContext } from "solid-js";
|
|
5
5
|
|
|
6
6
|
// src/HotkeysProvider.tsx
|
|
7
7
|
const HotkeysContext = createContext(null);
|
|
@@ -35,23 +35,24 @@ const DEFAULT_OPTIONS = {};
|
|
|
35
35
|
*/
|
|
36
36
|
const HotkeysProvider = (props) => {
|
|
37
37
|
const parent = useContext(HotkeysContext);
|
|
38
|
-
const store = props.appHotkeys ? createAppHotkeysStore(props.appHotkeys, {
|
|
38
|
+
const store = createMemo((created) => created ?? (props.appHotkeys ? untrack(() => createAppHotkeysStore(props.appHotkeys, {
|
|
39
39
|
customHotkeys: props.customHotkeys,
|
|
40
40
|
onCustomHotkeysChange: (custom) => props.onCustomHotkeysChange?.(custom),
|
|
41
41
|
platform: props.defaultOptions?.platform ?? parent?.defaultOptions.platform
|
|
42
|
-
}) : null;
|
|
42
|
+
})) : null), null);
|
|
43
43
|
createEffect(() => {
|
|
44
|
-
if (props.appHotkeys) store?.setAppHotkeys(props.appHotkeys);
|
|
44
|
+
if (props.appHotkeys) store()?.setAppHotkeys(props.appHotkeys);
|
|
45
45
|
});
|
|
46
|
-
|
|
47
|
-
|
|
46
|
+
createEffect(() => {
|
|
47
|
+
const created = store();
|
|
48
|
+
if (created) onCleanup(publishAppHotkeysStore(created));
|
|
48
49
|
});
|
|
49
50
|
const active = () => (parent?.enabled ?? true) && props.enabled !== false;
|
|
50
51
|
const defaultOptions = createMemo(() => mergeHotkeysProviderDefaults(parent?.defaultOptions, props.defaultOptions, props.scope));
|
|
51
|
-
|
|
52
|
+
createEffect(() => {
|
|
52
53
|
const customHotkeys = props.customHotkeys;
|
|
53
54
|
const platform = defaultOptions().platform;
|
|
54
|
-
store
|
|
55
|
+
store()?.setOptions({
|
|
55
56
|
customHotkeys,
|
|
56
57
|
platform
|
|
57
58
|
});
|
|
@@ -66,17 +67,18 @@ const HotkeysProvider = (props) => {
|
|
|
66
67
|
const key = scopeKey();
|
|
67
68
|
if (key) onCleanup(activateHotkeysProviderScope(key));
|
|
68
69
|
});
|
|
69
|
-
const contextValue = {
|
|
70
|
-
appHotkeysStore: store ?? parent?.appHotkeysStore ?? null,
|
|
71
|
-
get defaultOptions() {
|
|
72
|
-
return defaultOptions();
|
|
73
|
-
},
|
|
74
|
-
get enabled() {
|
|
75
|
-
return active();
|
|
76
|
-
}
|
|
77
|
-
};
|
|
78
70
|
return createComponent(HotkeysContext.Provider, {
|
|
79
|
-
value:
|
|
71
|
+
value: {
|
|
72
|
+
get appHotkeysStore() {
|
|
73
|
+
return store() ?? parent?.appHotkeysStore ?? null;
|
|
74
|
+
},
|
|
75
|
+
get defaultOptions() {
|
|
76
|
+
return defaultOptions();
|
|
77
|
+
},
|
|
78
|
+
get enabled() {
|
|
79
|
+
return active();
|
|
80
|
+
}
|
|
81
|
+
},
|
|
80
82
|
get children() {
|
|
81
83
|
return props.children;
|
|
82
84
|
}
|
package/dist/appHotkeys.js
CHANGED
|
@@ -5,9 +5,10 @@ import { createMemo } from "solid-js";
|
|
|
5
5
|
// src/appHotkeys.ts
|
|
6
6
|
function useRequiredStore(name) {
|
|
7
7
|
const source = useAppHotkeysStoreSource();
|
|
8
|
-
|
|
8
|
+
const initial = source.store;
|
|
9
|
+
if (!initial) throw new Error(`[hotkeys] ${name} requires a HotkeysProvider with an appHotkeys prop`);
|
|
9
10
|
return {
|
|
10
|
-
store: source.store,
|
|
11
|
+
store: () => source.store ?? initial,
|
|
11
12
|
state: source.state
|
|
12
13
|
};
|
|
13
14
|
}
|
|
@@ -25,7 +26,7 @@ function useAppHotkeys() {
|
|
|
25
26
|
const { store, state } = useRequiredStore("useAppHotkeys");
|
|
26
27
|
return createMemo(() => {
|
|
27
28
|
state();
|
|
28
|
-
return store.appHotkeys;
|
|
29
|
+
return store().appHotkeys;
|
|
29
30
|
});
|
|
30
31
|
}
|
|
31
32
|
/**
|
|
@@ -38,7 +39,7 @@ function createAppHotkeyList() {
|
|
|
38
39
|
const registrations = createHotkeyRegistrations();
|
|
39
40
|
return createMemo(() => {
|
|
40
41
|
state();
|
|
41
|
-
return store.getList(registrations());
|
|
42
|
+
return store().getList(registrations());
|
|
42
43
|
});
|
|
43
44
|
}
|
|
44
45
|
/**
|
|
@@ -51,12 +52,12 @@ function useCustomHotkeys() {
|
|
|
51
52
|
return {
|
|
52
53
|
customHotkeys: createMemo(() => {
|
|
53
54
|
state();
|
|
54
|
-
return store.customHotkeys;
|
|
55
|
+
return store().customHotkeys;
|
|
55
56
|
}),
|
|
56
|
-
setCustomHotkey: (id, hotkey) => store.setCustomHotkey(id, hotkey),
|
|
57
|
-
resetCustomHotkey: (id) => store.resetCustomHotkey(id),
|
|
58
|
-
resetCustomHotkeys: () => store.resetCustomHotkeys(),
|
|
59
|
-
findConflicts: (id, hotkey) => store.findConflicts(id, hotkey)
|
|
57
|
+
setCustomHotkey: (id, hotkey) => store().setCustomHotkey(id, hotkey),
|
|
58
|
+
resetCustomHotkey: (id) => store().resetCustomHotkey(id),
|
|
59
|
+
resetCustomHotkeys: () => store().resetCustomHotkeys(),
|
|
60
|
+
findConflicts: (id, hotkey) => store().findConflicts(id, hotkey)
|
|
60
61
|
};
|
|
61
62
|
}
|
|
62
63
|
|
package/dist/defaultOptions.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useHotkeysContext } from "./HotkeysProvider.js";
|
|
2
2
|
import { useSelector } from "./_useSelector.js";
|
|
3
|
-
import {
|
|
3
|
+
import { createMemo } from "solid-js";
|
|
4
4
|
|
|
5
5
|
// src/defaultOptions.ts
|
|
6
6
|
/** Captures the context once and reads current defaults inside reactive computations. */
|
|
@@ -8,16 +8,23 @@ function useDefaultHotkeysOptionsSource() {
|
|
|
8
8
|
const context = useHotkeysContext();
|
|
9
9
|
return () => context?.defaultOptions ?? {};
|
|
10
10
|
}
|
|
11
|
-
const NO_APP_HOTKEYS = createStore(null);
|
|
12
11
|
/**
|
|
13
12
|
* The provider's app hotkeys store and an accessor that tracks its state, so
|
|
14
|
-
* computations re-run when app hotkeys or custom hotkeys change.
|
|
13
|
+
* computations re-run when app hotkeys or custom hotkeys change. `store` is a
|
|
14
|
+
* getter: a provider creates its store when its app hotkeys arrive, which can
|
|
15
|
+
* be after this is called.
|
|
15
16
|
*/
|
|
16
17
|
function useAppHotkeysStoreSource() {
|
|
17
|
-
const
|
|
18
|
+
const context = useHotkeysContext();
|
|
19
|
+
const state = createMemo(() => {
|
|
20
|
+
const store = context?.appHotkeysStore;
|
|
21
|
+
return store ? useSelector(store.store, (value) => value) : null;
|
|
22
|
+
});
|
|
18
23
|
return {
|
|
19
|
-
store
|
|
20
|
-
|
|
24
|
+
get store() {
|
|
25
|
+
return context?.appHotkeysStore ?? null;
|
|
26
|
+
},
|
|
27
|
+
state: () => state()?.() ?? null
|
|
21
28
|
};
|
|
22
29
|
}
|
|
23
30
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/solid-hotkeys",
|
|
3
|
-
"version": "0.22.
|
|
3
|
+
"version": "0.22.1",
|
|
4
4
|
"description": "SolidJS adapter for TanStack Hotkeys",
|
|
5
5
|
"author": "Tanner Linsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"skills"
|
|
39
39
|
],
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@tanstack/hotkeys": "0.27.
|
|
41
|
+
"@tanstack/hotkeys": "0.27.1"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"@solidjs/testing-library": "^0.8.10",
|