@tanstack/solid-hotkeys 0.5.1 → 0.6.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.cjs.map +1 -1
- package/dist/HotkeysProvider.d.cts +2 -1
- package/dist/HotkeysProvider.d.ts +2 -1
- package/dist/HotkeysProvider.js.map +1 -1
- package/dist/createHotkeySequenceRecorder.cjs +43 -0
- package/dist/createHotkeySequenceRecorder.cjs.map +1 -0
- package/dist/createHotkeySequenceRecorder.d.cts +19 -0
- package/dist/createHotkeySequenceRecorder.d.ts +19 -0
- package/dist/createHotkeySequenceRecorder.js +43 -0
- package/dist/createHotkeySequenceRecorder.js.map +1 -0
- package/dist/index.cjs +2 -0
- package/dist/index.d.cts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/package.json +2 -2
- package/src/HotkeysProvider.tsx +5 -1
- package/src/createHotkeySequenceRecorder.ts +66 -0
- package/src/index.ts +1 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HotkeysProvider.cjs","names":["createContext","useContext","JSX","ParentComponent","HotkeyRecorderOptions","CreateHotkeyOptions","CreateHotkeySequenceOptions","HotkeysProviderOptions","hotkey","Partial","hotkeyRecorder","hotkeySequence","HotkeysContextValue","defaultOptions","HotkeysContext","HotkeysProviderProps","children","Element","DEFAULT_OPTIONS","HotkeysProvider","props","contextValue","_$createComponent","Provider","value","useHotkeysContext","useDefaultHotkeysOptions","context"],"sources":["../src/HotkeysProvider.tsx"],"sourcesContent":["import { createContext, useContext } from 'solid-js'\nimport type { JSX, ParentComponent } from 'solid-js'\nimport type {
|
|
1
|
+
{"version":3,"file":"HotkeysProvider.cjs","names":["createContext","useContext","JSX","ParentComponent","HotkeyRecorderOptions","HotkeySequenceRecorderOptions","CreateHotkeyOptions","CreateHotkeySequenceOptions","HotkeysProviderOptions","hotkey","Partial","hotkeyRecorder","hotkeySequenceRecorder","hotkeySequence","HotkeysContextValue","defaultOptions","HotkeysContext","HotkeysProviderProps","children","Element","DEFAULT_OPTIONS","HotkeysProvider","props","contextValue","_$createComponent","Provider","value","useHotkeysContext","useDefaultHotkeysOptions","context"],"sources":["../src/HotkeysProvider.tsx"],"sourcesContent":["import { createContext, useContext } from 'solid-js'\nimport type { JSX, ParentComponent } from 'solid-js'\nimport type {\n HotkeyRecorderOptions,\n HotkeySequenceRecorderOptions,\n} from '@tanstack/hotkeys'\nimport type { CreateHotkeyOptions } from './createHotkey'\nimport type { CreateHotkeySequenceOptions } from './createHotkeySequence'\n\nexport interface HotkeysProviderOptions {\n hotkey?: Partial<CreateHotkeyOptions>\n hotkeyRecorder?: Partial<HotkeyRecorderOptions>\n hotkeySequenceRecorder?: Partial<HotkeySequenceRecorderOptions>\n hotkeySequence?: Partial<CreateHotkeySequenceOptions>\n}\n\ninterface HotkeysContextValue {\n defaultOptions: HotkeysProviderOptions\n}\n\nconst HotkeysContext = createContext<HotkeysContextValue | null>(null)\n\nexport interface HotkeysProviderProps {\n children: JSX.Element\n defaultOptions?: HotkeysProviderOptions\n}\n\nconst DEFAULT_OPTIONS: HotkeysProviderOptions = {}\n\nexport const HotkeysProvider: ParentComponent<HotkeysProviderProps> = (\n props,\n) => {\n const contextValue: HotkeysContextValue = {\n defaultOptions: props.defaultOptions ?? DEFAULT_OPTIONS,\n }\n\n return (\n <HotkeysContext.Provider value={contextValue}>\n {props.children}\n </HotkeysContext.Provider>\n )\n}\n\nexport function useHotkeysContext() {\n return useContext(HotkeysContext)\n}\n\nexport function useDefaultHotkeysOptions() {\n const context = useContext(HotkeysContext)\n return context?.defaultOptions ?? {}\n}\n"],"mappings":";;;;AAoBA,MAAMgB,6CAA2D,KAAK;AAOtE,MAAMI,kBAA0C,EAAE;AAElD,MAAaC,mBACXC,UACG;CACH,MAAMC,eAAoC,EACxCR,gBAAgBO,MAAMP,kBAAkBK,iBACzC;AAED,0CACGJ,eAAeS,UAAQ;EAACC,OAAOH;EAAY,IAAAL,WAAA;AAAA,UACzCI,MAAMJ;;EAAQ,CAAA;;AAKrB,SAAgBS,oBAAoB;AAClC,iCAAkBX,eAAe;;AAGnC,SAAgBY,2BAA2B;AAEzC,iCAD2BZ,eAAe,EAC1BD,kBAAkB,EAAE"}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { CreateHotkeyOptions } from "./createHotkey.cjs";
|
|
2
2
|
import { CreateHotkeySequenceOptions } from "./createHotkeySequence.cjs";
|
|
3
|
-
import { HotkeyRecorderOptions } from "@tanstack/hotkeys";
|
|
3
|
+
import { HotkeyRecorderOptions, HotkeySequenceRecorderOptions } from "@tanstack/hotkeys";
|
|
4
4
|
import { JSX, ParentComponent } from "solid-js";
|
|
5
5
|
|
|
6
6
|
//#region src/HotkeysProvider.d.ts
|
|
7
7
|
interface HotkeysProviderOptions {
|
|
8
8
|
hotkey?: Partial<CreateHotkeyOptions>;
|
|
9
9
|
hotkeyRecorder?: Partial<HotkeyRecorderOptions>;
|
|
10
|
+
hotkeySequenceRecorder?: Partial<HotkeySequenceRecorderOptions>;
|
|
10
11
|
hotkeySequence?: Partial<CreateHotkeySequenceOptions>;
|
|
11
12
|
}
|
|
12
13
|
interface HotkeysContextValue {
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { CreateHotkeyOptions } from "./createHotkey.js";
|
|
2
2
|
import { CreateHotkeySequenceOptions } from "./createHotkeySequence.js";
|
|
3
|
-
import { HotkeyRecorderOptions } from "@tanstack/hotkeys";
|
|
3
|
+
import { HotkeyRecorderOptions, HotkeySequenceRecorderOptions } from "@tanstack/hotkeys";
|
|
4
4
|
import { JSX, ParentComponent } from "solid-js";
|
|
5
5
|
|
|
6
6
|
//#region src/HotkeysProvider.d.ts
|
|
7
7
|
interface HotkeysProviderOptions {
|
|
8
8
|
hotkey?: Partial<CreateHotkeyOptions>;
|
|
9
9
|
hotkeyRecorder?: Partial<HotkeyRecorderOptions>;
|
|
10
|
+
hotkeySequenceRecorder?: Partial<HotkeySequenceRecorderOptions>;
|
|
10
11
|
hotkeySequence?: Partial<CreateHotkeySequenceOptions>;
|
|
11
12
|
}
|
|
12
13
|
interface HotkeysContextValue {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HotkeysProvider.js","names":["createContext","useContext","JSX","ParentComponent","HotkeyRecorderOptions","CreateHotkeyOptions","CreateHotkeySequenceOptions","HotkeysProviderOptions","hotkey","Partial","hotkeyRecorder","hotkeySequence","HotkeysContextValue","defaultOptions","HotkeysContext","HotkeysProviderProps","children","Element","DEFAULT_OPTIONS","HotkeysProvider","props","contextValue","_$createComponent","Provider","value","useHotkeysContext","useDefaultHotkeysOptions","context"],"sources":["../src/HotkeysProvider.tsx"],"sourcesContent":["import { createContext, useContext } from 'solid-js'\nimport type { JSX, ParentComponent } from 'solid-js'\nimport type {
|
|
1
|
+
{"version":3,"file":"HotkeysProvider.js","names":["createContext","useContext","JSX","ParentComponent","HotkeyRecorderOptions","HotkeySequenceRecorderOptions","CreateHotkeyOptions","CreateHotkeySequenceOptions","HotkeysProviderOptions","hotkey","Partial","hotkeyRecorder","hotkeySequenceRecorder","hotkeySequence","HotkeysContextValue","defaultOptions","HotkeysContext","HotkeysProviderProps","children","Element","DEFAULT_OPTIONS","HotkeysProvider","props","contextValue","_$createComponent","Provider","value","useHotkeysContext","useDefaultHotkeysOptions","context"],"sources":["../src/HotkeysProvider.tsx"],"sourcesContent":["import { createContext, useContext } from 'solid-js'\nimport type { JSX, ParentComponent } from 'solid-js'\nimport type {\n HotkeyRecorderOptions,\n HotkeySequenceRecorderOptions,\n} from '@tanstack/hotkeys'\nimport type { CreateHotkeyOptions } from './createHotkey'\nimport type { CreateHotkeySequenceOptions } from './createHotkeySequence'\n\nexport interface HotkeysProviderOptions {\n hotkey?: Partial<CreateHotkeyOptions>\n hotkeyRecorder?: Partial<HotkeyRecorderOptions>\n hotkeySequenceRecorder?: Partial<HotkeySequenceRecorderOptions>\n hotkeySequence?: Partial<CreateHotkeySequenceOptions>\n}\n\ninterface HotkeysContextValue {\n defaultOptions: HotkeysProviderOptions\n}\n\nconst HotkeysContext = createContext<HotkeysContextValue | null>(null)\n\nexport interface HotkeysProviderProps {\n children: JSX.Element\n defaultOptions?: HotkeysProviderOptions\n}\n\nconst DEFAULT_OPTIONS: HotkeysProviderOptions = {}\n\nexport const HotkeysProvider: ParentComponent<HotkeysProviderProps> = (\n props,\n) => {\n const contextValue: HotkeysContextValue = {\n defaultOptions: props.defaultOptions ?? DEFAULT_OPTIONS,\n }\n\n return (\n <HotkeysContext.Provider value={contextValue}>\n {props.children}\n </HotkeysContext.Provider>\n )\n}\n\nexport function useHotkeysContext() {\n return useContext(HotkeysContext)\n}\n\nexport function useDefaultHotkeysOptions() {\n const context = useContext(HotkeysContext)\n return context?.defaultOptions ?? {}\n}\n"],"mappings":";;;;AAoBA,MAAMgB,iBAAiBhB,cAA0C,KAAK;AAOtE,MAAMoB,kBAA0C,EAAE;AAElD,MAAaC,mBACXC,UACG;CACH,MAAMC,eAAoC,EACxCR,gBAAgBO,MAAMP,kBAAkBK,iBACzC;AAED,QAAAI,gBACGR,eAAeS,UAAQ;EAACC,OAAOH;EAAY,IAAAL,WAAA;AAAA,UACzCI,MAAMJ;;EAAQ,CAAA;;AAKrB,SAAgBS,oBAAoB;AAClC,QAAO1B,WAAWe,eAAe;;AAGnC,SAAgBY,2BAA2B;AAEzC,QADgB3B,WAAWe,eAAe,EAC1BD,kBAAkB,EAAE"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
const require_HotkeysProvider = require('./HotkeysProvider.cjs');
|
|
2
|
+
let _tanstack_hotkeys = require("@tanstack/hotkeys");
|
|
3
|
+
let solid_js = require("solid-js");
|
|
4
|
+
let _tanstack_solid_store = require("@tanstack/solid-store");
|
|
5
|
+
|
|
6
|
+
//#region src/createHotkeySequenceRecorder.ts
|
|
7
|
+
/**
|
|
8
|
+
* SolidJS primitive for recording multi-chord sequences (Vim-style shortcuts).
|
|
9
|
+
*/
|
|
10
|
+
function createHotkeySequenceRecorder(options) {
|
|
11
|
+
const defaultOptions = require_HotkeysProvider.useDefaultHotkeysOptions();
|
|
12
|
+
const resolvedOptions = typeof options === "function" ? options() : options;
|
|
13
|
+
const recorder = new _tanstack_hotkeys.HotkeySequenceRecorder({
|
|
14
|
+
...defaultOptions.hotkeySequenceRecorder,
|
|
15
|
+
...resolvedOptions
|
|
16
|
+
});
|
|
17
|
+
const isRecording = (0, _tanstack_solid_store.useStore)(recorder.store, (state) => state.isRecording);
|
|
18
|
+
const steps = (0, _tanstack_solid_store.useStore)(recorder.store, (state) => state.steps);
|
|
19
|
+
const recordedSequence = (0, _tanstack_solid_store.useStore)(recorder.store, (state) => state.recordedSequence);
|
|
20
|
+
(0, solid_js.createEffect)(() => {
|
|
21
|
+
const resolved = typeof options === "function" ? options() : options;
|
|
22
|
+
recorder.setOptions({
|
|
23
|
+
...defaultOptions.hotkeySequenceRecorder,
|
|
24
|
+
...resolved
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
(0, solid_js.onCleanup)(() => {
|
|
28
|
+
recorder.destroy();
|
|
29
|
+
});
|
|
30
|
+
return {
|
|
31
|
+
isRecording,
|
|
32
|
+
steps,
|
|
33
|
+
recordedSequence,
|
|
34
|
+
startRecording: () => recorder.start(),
|
|
35
|
+
stopRecording: () => recorder.stop(),
|
|
36
|
+
cancelRecording: () => recorder.cancel(),
|
|
37
|
+
commitRecording: () => recorder.commit()
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
//#endregion
|
|
42
|
+
exports.createHotkeySequenceRecorder = createHotkeySequenceRecorder;
|
|
43
|
+
//# sourceMappingURL=createHotkeySequenceRecorder.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createHotkeySequenceRecorder.cjs","names":["useDefaultHotkeysOptions","HotkeySequenceRecorder"],"sources":["../src/createHotkeySequenceRecorder.ts"],"sourcesContent":["import { createEffect, onCleanup } from 'solid-js'\nimport { useStore } from '@tanstack/solid-store'\nimport { HotkeySequenceRecorder } from '@tanstack/hotkeys'\nimport { useDefaultHotkeysOptions } from './HotkeysProvider'\nimport type {\n HotkeySequence,\n HotkeySequenceRecorderOptions,\n} from '@tanstack/hotkeys'\n\nexport interface SolidHotkeySequenceRecorder {\n isRecording: () => boolean\n steps: () => HotkeySequence\n recordedSequence: () => HotkeySequence | null\n startRecording: () => void\n stopRecording: () => void\n cancelRecording: () => void\n commitRecording: () => void\n}\n\n/**\n * SolidJS primitive for recording multi-chord sequences (Vim-style shortcuts).\n */\nexport function createHotkeySequenceRecorder(\n options:\n | HotkeySequenceRecorderOptions\n | (() => HotkeySequenceRecorderOptions),\n): SolidHotkeySequenceRecorder {\n const defaultOptions = useDefaultHotkeysOptions()\n\n const resolvedOptions = typeof options === 'function' ? options() : options\n const mergedOptions = {\n ...defaultOptions.hotkeySequenceRecorder,\n ...resolvedOptions,\n } as HotkeySequenceRecorderOptions\n\n const recorder = new HotkeySequenceRecorder(mergedOptions)\n\n const isRecording = useStore(recorder.store, (state) => state.isRecording)\n const steps = useStore(recorder.store, (state) => state.steps)\n const recordedSequence = useStore(\n recorder.store,\n (state) => state.recordedSequence,\n )\n\n createEffect(() => {\n const resolved = typeof options === 'function' ? options() : options\n recorder.setOptions({\n ...defaultOptions.hotkeySequenceRecorder,\n ...resolved,\n } as HotkeySequenceRecorderOptions)\n })\n\n onCleanup(() => {\n recorder.destroy()\n })\n\n return {\n isRecording,\n steps,\n recordedSequence,\n startRecording: () => recorder.start(),\n stopRecording: () => recorder.stop(),\n cancelRecording: () => recorder.cancel(),\n commitRecording: () => recorder.commit(),\n }\n}\n"],"mappings":";;;;;;;;;AAsBA,SAAgB,6BACd,SAG6B;CAC7B,MAAM,iBAAiBA,kDAA0B;CAEjD,MAAM,kBAAkB,OAAO,YAAY,aAAa,SAAS,GAAG;CAMpE,MAAM,WAAW,IAAIC,yCALC;EACpB,GAAG,eAAe;EAClB,GAAG;EACJ,CAEyD;CAE1D,MAAM,kDAAuB,SAAS,QAAQ,UAAU,MAAM,YAAY;CAC1E,MAAM,4CAAiB,SAAS,QAAQ,UAAU,MAAM,MAAM;CAC9D,MAAM,uDACJ,SAAS,QACR,UAAU,MAAM,iBAClB;AAED,kCAAmB;EACjB,MAAM,WAAW,OAAO,YAAY,aAAa,SAAS,GAAG;AAC7D,WAAS,WAAW;GAClB,GAAG,eAAe;GAClB,GAAG;GACJ,CAAkC;GACnC;AAEF,+BAAgB;AACd,WAAS,SAAS;GAClB;AAEF,QAAO;EACL;EACA;EACA;EACA,sBAAsB,SAAS,OAAO;EACtC,qBAAqB,SAAS,MAAM;EACpC,uBAAuB,SAAS,QAAQ;EACxC,uBAAuB,SAAS,QAAQ;EACzC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { HotkeySequence, HotkeySequenceRecorderOptions } from "@tanstack/hotkeys";
|
|
2
|
+
|
|
3
|
+
//#region src/createHotkeySequenceRecorder.d.ts
|
|
4
|
+
interface SolidHotkeySequenceRecorder {
|
|
5
|
+
isRecording: () => boolean;
|
|
6
|
+
steps: () => HotkeySequence;
|
|
7
|
+
recordedSequence: () => HotkeySequence | null;
|
|
8
|
+
startRecording: () => void;
|
|
9
|
+
stopRecording: () => void;
|
|
10
|
+
cancelRecording: () => void;
|
|
11
|
+
commitRecording: () => void;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* SolidJS primitive for recording multi-chord sequences (Vim-style shortcuts).
|
|
15
|
+
*/
|
|
16
|
+
declare function createHotkeySequenceRecorder(options: HotkeySequenceRecorderOptions | (() => HotkeySequenceRecorderOptions)): SolidHotkeySequenceRecorder;
|
|
17
|
+
//#endregion
|
|
18
|
+
export { SolidHotkeySequenceRecorder, createHotkeySequenceRecorder };
|
|
19
|
+
//# sourceMappingURL=createHotkeySequenceRecorder.d.cts.map
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { HotkeySequence, HotkeySequenceRecorderOptions } from "@tanstack/hotkeys";
|
|
2
|
+
|
|
3
|
+
//#region src/createHotkeySequenceRecorder.d.ts
|
|
4
|
+
interface SolidHotkeySequenceRecorder {
|
|
5
|
+
isRecording: () => boolean;
|
|
6
|
+
steps: () => HotkeySequence;
|
|
7
|
+
recordedSequence: () => HotkeySequence | null;
|
|
8
|
+
startRecording: () => void;
|
|
9
|
+
stopRecording: () => void;
|
|
10
|
+
cancelRecording: () => void;
|
|
11
|
+
commitRecording: () => void;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* SolidJS primitive for recording multi-chord sequences (Vim-style shortcuts).
|
|
15
|
+
*/
|
|
16
|
+
declare function createHotkeySequenceRecorder(options: HotkeySequenceRecorderOptions | (() => HotkeySequenceRecorderOptions)): SolidHotkeySequenceRecorder;
|
|
17
|
+
//#endregion
|
|
18
|
+
export { SolidHotkeySequenceRecorder, createHotkeySequenceRecorder };
|
|
19
|
+
//# sourceMappingURL=createHotkeySequenceRecorder.d.ts.map
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { useDefaultHotkeysOptions } from "./HotkeysProvider.js";
|
|
2
|
+
import { HotkeySequenceRecorder } from "@tanstack/hotkeys";
|
|
3
|
+
import { createEffect, onCleanup } from "solid-js";
|
|
4
|
+
import { useStore } from "@tanstack/solid-store";
|
|
5
|
+
|
|
6
|
+
//#region src/createHotkeySequenceRecorder.ts
|
|
7
|
+
/**
|
|
8
|
+
* SolidJS primitive for recording multi-chord sequences (Vim-style shortcuts).
|
|
9
|
+
*/
|
|
10
|
+
function createHotkeySequenceRecorder(options) {
|
|
11
|
+
const defaultOptions = useDefaultHotkeysOptions();
|
|
12
|
+
const resolvedOptions = typeof options === "function" ? options() : options;
|
|
13
|
+
const recorder = new HotkeySequenceRecorder({
|
|
14
|
+
...defaultOptions.hotkeySequenceRecorder,
|
|
15
|
+
...resolvedOptions
|
|
16
|
+
});
|
|
17
|
+
const isRecording = useStore(recorder.store, (state) => state.isRecording);
|
|
18
|
+
const steps = useStore(recorder.store, (state) => state.steps);
|
|
19
|
+
const recordedSequence = useStore(recorder.store, (state) => state.recordedSequence);
|
|
20
|
+
createEffect(() => {
|
|
21
|
+
const resolved = typeof options === "function" ? options() : options;
|
|
22
|
+
recorder.setOptions({
|
|
23
|
+
...defaultOptions.hotkeySequenceRecorder,
|
|
24
|
+
...resolved
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
onCleanup(() => {
|
|
28
|
+
recorder.destroy();
|
|
29
|
+
});
|
|
30
|
+
return {
|
|
31
|
+
isRecording,
|
|
32
|
+
steps,
|
|
33
|
+
recordedSequence,
|
|
34
|
+
startRecording: () => recorder.start(),
|
|
35
|
+
stopRecording: () => recorder.stop(),
|
|
36
|
+
cancelRecording: () => recorder.cancel(),
|
|
37
|
+
commitRecording: () => recorder.commit()
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
//#endregion
|
|
42
|
+
export { createHotkeySequenceRecorder };
|
|
43
|
+
//# sourceMappingURL=createHotkeySequenceRecorder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createHotkeySequenceRecorder.js","names":[],"sources":["../src/createHotkeySequenceRecorder.ts"],"sourcesContent":["import { createEffect, onCleanup } from 'solid-js'\nimport { useStore } from '@tanstack/solid-store'\nimport { HotkeySequenceRecorder } from '@tanstack/hotkeys'\nimport { useDefaultHotkeysOptions } from './HotkeysProvider'\nimport type {\n HotkeySequence,\n HotkeySequenceRecorderOptions,\n} from '@tanstack/hotkeys'\n\nexport interface SolidHotkeySequenceRecorder {\n isRecording: () => boolean\n steps: () => HotkeySequence\n recordedSequence: () => HotkeySequence | null\n startRecording: () => void\n stopRecording: () => void\n cancelRecording: () => void\n commitRecording: () => void\n}\n\n/**\n * SolidJS primitive for recording multi-chord sequences (Vim-style shortcuts).\n */\nexport function createHotkeySequenceRecorder(\n options:\n | HotkeySequenceRecorderOptions\n | (() => HotkeySequenceRecorderOptions),\n): SolidHotkeySequenceRecorder {\n const defaultOptions = useDefaultHotkeysOptions()\n\n const resolvedOptions = typeof options === 'function' ? options() : options\n const mergedOptions = {\n ...defaultOptions.hotkeySequenceRecorder,\n ...resolvedOptions,\n } as HotkeySequenceRecorderOptions\n\n const recorder = new HotkeySequenceRecorder(mergedOptions)\n\n const isRecording = useStore(recorder.store, (state) => state.isRecording)\n const steps = useStore(recorder.store, (state) => state.steps)\n const recordedSequence = useStore(\n recorder.store,\n (state) => state.recordedSequence,\n )\n\n createEffect(() => {\n const resolved = typeof options === 'function' ? options() : options\n recorder.setOptions({\n ...defaultOptions.hotkeySequenceRecorder,\n ...resolved,\n } as HotkeySequenceRecorderOptions)\n })\n\n onCleanup(() => {\n recorder.destroy()\n })\n\n return {\n isRecording,\n steps,\n recordedSequence,\n startRecording: () => recorder.start(),\n stopRecording: () => recorder.stop(),\n cancelRecording: () => recorder.cancel(),\n commitRecording: () => recorder.commit(),\n }\n}\n"],"mappings":";;;;;;;;;AAsBA,SAAgB,6BACd,SAG6B;CAC7B,MAAM,iBAAiB,0BAA0B;CAEjD,MAAM,kBAAkB,OAAO,YAAY,aAAa,SAAS,GAAG;CAMpE,MAAM,WAAW,IAAI,uBALC;EACpB,GAAG,eAAe;EAClB,GAAG;EACJ,CAEyD;CAE1D,MAAM,cAAc,SAAS,SAAS,QAAQ,UAAU,MAAM,YAAY;CAC1E,MAAM,QAAQ,SAAS,SAAS,QAAQ,UAAU,MAAM,MAAM;CAC9D,MAAM,mBAAmB,SACvB,SAAS,QACR,UAAU,MAAM,iBAClB;AAED,oBAAmB;EACjB,MAAM,WAAW,OAAO,YAAY,aAAa,SAAS,GAAG;AAC7D,WAAS,WAAW;GAClB,GAAG,eAAe;GAClB,GAAG;GACJ,CAAkC;GACnC;AAEF,iBAAgB;AACd,WAAS,SAAS;GAClB;AAEF,QAAO;EACL;EACA;EACA;EACA,sBAAsB,SAAS,OAAO;EACtC,qBAAqB,SAAS,MAAM;EACpC,uBAAuB,SAAS,QAAQ;EACxC,uBAAuB,SAAS,QAAQ;EACzC"}
|
package/dist/index.cjs
CHANGED
|
@@ -7,6 +7,7 @@ const require_createHeldKeyCodes = require('./createHeldKeyCodes.cjs');
|
|
|
7
7
|
const require_createKeyHold = require('./createKeyHold.cjs');
|
|
8
8
|
const require_createHotkeySequence = require('./createHotkeySequence.cjs');
|
|
9
9
|
const require_createHotkeyRecorder = require('./createHotkeyRecorder.cjs');
|
|
10
|
+
const require_createHotkeySequenceRecorder = require('./createHotkeySequenceRecorder.cjs');
|
|
10
11
|
|
|
11
12
|
exports.HotkeysProvider = require_HotkeysProvider.HotkeysProvider;
|
|
12
13
|
exports.createHeldKeyCodes = require_createHeldKeyCodes.createHeldKeyCodes;
|
|
@@ -14,6 +15,7 @@ exports.createHeldKeys = require_createHeldKeys.createHeldKeys;
|
|
|
14
15
|
exports.createHotkey = require_createHotkey.createHotkey;
|
|
15
16
|
exports.createHotkeyRecorder = require_createHotkeyRecorder.createHotkeyRecorder;
|
|
16
17
|
exports.createHotkeySequence = require_createHotkeySequence.createHotkeySequence;
|
|
18
|
+
exports.createHotkeySequenceRecorder = require_createHotkeySequenceRecorder.createHotkeySequenceRecorder;
|
|
17
19
|
exports.createHotkeys = require_createHotkeys.createHotkeys;
|
|
18
20
|
exports.createKeyHold = require_createKeyHold.createKeyHold;
|
|
19
21
|
exports.useDefaultHotkeysOptions = require_HotkeysProvider.useDefaultHotkeysOptions;
|
package/dist/index.d.cts
CHANGED
|
@@ -6,5 +6,6 @@ import { createHeldKeys } from "./createHeldKeys.cjs";
|
|
|
6
6
|
import { createHeldKeyCodes } from "./createHeldKeyCodes.cjs";
|
|
7
7
|
import { createKeyHold } from "./createKeyHold.cjs";
|
|
8
8
|
import { SolidHotkeyRecorder, createHotkeyRecorder } from "./createHotkeyRecorder.cjs";
|
|
9
|
+
import { SolidHotkeySequenceRecorder, createHotkeySequenceRecorder } from "./createHotkeySequenceRecorder.cjs";
|
|
9
10
|
export * from "@tanstack/hotkeys";
|
|
10
|
-
export { CreateHotkeyDefinition, CreateHotkeyOptions, CreateHotkeySequenceOptions, HotkeysProvider, HotkeysProviderOptions, HotkeysProviderProps, SolidHotkeyRecorder, createHeldKeyCodes, createHeldKeys, createHotkey, createHotkeyRecorder, createHotkeySequence, createHotkeys, createKeyHold, useDefaultHotkeysOptions, useHotkeysContext };
|
|
11
|
+
export { CreateHotkeyDefinition, CreateHotkeyOptions, CreateHotkeySequenceOptions, HotkeysProvider, HotkeysProviderOptions, HotkeysProviderProps, SolidHotkeyRecorder, SolidHotkeySequenceRecorder, createHeldKeyCodes, createHeldKeys, createHotkey, createHotkeyRecorder, createHotkeySequence, createHotkeySequenceRecorder, createHotkeys, createKeyHold, useDefaultHotkeysOptions, useHotkeysContext };
|
package/dist/index.d.ts
CHANGED
|
@@ -6,5 +6,6 @@ import { createHeldKeys } from "./createHeldKeys.js";
|
|
|
6
6
|
import { createHeldKeyCodes } from "./createHeldKeyCodes.js";
|
|
7
7
|
import { createKeyHold } from "./createKeyHold.js";
|
|
8
8
|
import { SolidHotkeyRecorder, createHotkeyRecorder } from "./createHotkeyRecorder.js";
|
|
9
|
+
import { SolidHotkeySequenceRecorder, createHotkeySequenceRecorder } from "./createHotkeySequenceRecorder.js";
|
|
9
10
|
export * from "@tanstack/hotkeys";
|
|
10
|
-
export { CreateHotkeyDefinition, CreateHotkeyOptions, CreateHotkeySequenceOptions, HotkeysProvider, HotkeysProviderOptions, HotkeysProviderProps, SolidHotkeyRecorder, createHeldKeyCodes, createHeldKeys, createHotkey, createHotkeyRecorder, createHotkeySequence, createHotkeys, createKeyHold, useDefaultHotkeysOptions, useHotkeysContext };
|
|
11
|
+
export { CreateHotkeyDefinition, CreateHotkeyOptions, CreateHotkeySequenceOptions, HotkeysProvider, HotkeysProviderOptions, HotkeysProviderProps, SolidHotkeyRecorder, SolidHotkeySequenceRecorder, createHeldKeyCodes, createHeldKeys, createHotkey, createHotkeyRecorder, createHotkeySequence, createHotkeySequenceRecorder, createHotkeys, createKeyHold, useDefaultHotkeysOptions, useHotkeysContext };
|
package/dist/index.js
CHANGED
|
@@ -6,7 +6,8 @@ import { createHeldKeyCodes } from "./createHeldKeyCodes.js";
|
|
|
6
6
|
import { createKeyHold } from "./createKeyHold.js";
|
|
7
7
|
import { createHotkeySequence } from "./createHotkeySequence.js";
|
|
8
8
|
import { createHotkeyRecorder } from "./createHotkeyRecorder.js";
|
|
9
|
+
import { createHotkeySequenceRecorder } from "./createHotkeySequenceRecorder.js";
|
|
9
10
|
|
|
10
11
|
export * from "@tanstack/hotkeys"
|
|
11
12
|
|
|
12
|
-
export { HotkeysProvider, createHeldKeyCodes, createHeldKeys, createHotkey, createHotkeyRecorder, createHotkeySequence, createHotkeys, createKeyHold, useDefaultHotkeysOptions, useHotkeysContext };
|
|
13
|
+
export { HotkeysProvider, createHeldKeyCodes, createHeldKeys, createHotkey, createHotkeyRecorder, createHotkeySequence, createHotkeySequenceRecorder, createHotkeys, createKeyHold, useDefaultHotkeysOptions, useHotkeysContext };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/solid-hotkeys",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "SolidJS adapter for TanStack Hotkeys",
|
|
5
5
|
"author": "Tanner Linsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
],
|
|
44
44
|
"dependencies": {
|
|
45
45
|
"@tanstack/solid-store": "^0.9.2",
|
|
46
|
-
"@tanstack/hotkeys": "0.
|
|
46
|
+
"@tanstack/hotkeys": "0.5.0"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
49
|
"@solidjs/testing-library": "^0.8.10",
|
package/src/HotkeysProvider.tsx
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
import { createContext, useContext } from 'solid-js'
|
|
2
2
|
import type { JSX, ParentComponent } from 'solid-js'
|
|
3
|
-
import type {
|
|
3
|
+
import type {
|
|
4
|
+
HotkeyRecorderOptions,
|
|
5
|
+
HotkeySequenceRecorderOptions,
|
|
6
|
+
} from '@tanstack/hotkeys'
|
|
4
7
|
import type { CreateHotkeyOptions } from './createHotkey'
|
|
5
8
|
import type { CreateHotkeySequenceOptions } from './createHotkeySequence'
|
|
6
9
|
|
|
7
10
|
export interface HotkeysProviderOptions {
|
|
8
11
|
hotkey?: Partial<CreateHotkeyOptions>
|
|
9
12
|
hotkeyRecorder?: Partial<HotkeyRecorderOptions>
|
|
13
|
+
hotkeySequenceRecorder?: Partial<HotkeySequenceRecorderOptions>
|
|
10
14
|
hotkeySequence?: Partial<CreateHotkeySequenceOptions>
|
|
11
15
|
}
|
|
12
16
|
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { createEffect, onCleanup } from 'solid-js'
|
|
2
|
+
import { useStore } from '@tanstack/solid-store'
|
|
3
|
+
import { HotkeySequenceRecorder } from '@tanstack/hotkeys'
|
|
4
|
+
import { useDefaultHotkeysOptions } from './HotkeysProvider'
|
|
5
|
+
import type {
|
|
6
|
+
HotkeySequence,
|
|
7
|
+
HotkeySequenceRecorderOptions,
|
|
8
|
+
} from '@tanstack/hotkeys'
|
|
9
|
+
|
|
10
|
+
export interface SolidHotkeySequenceRecorder {
|
|
11
|
+
isRecording: () => boolean
|
|
12
|
+
steps: () => HotkeySequence
|
|
13
|
+
recordedSequence: () => HotkeySequence | null
|
|
14
|
+
startRecording: () => void
|
|
15
|
+
stopRecording: () => void
|
|
16
|
+
cancelRecording: () => void
|
|
17
|
+
commitRecording: () => void
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* SolidJS primitive for recording multi-chord sequences (Vim-style shortcuts).
|
|
22
|
+
*/
|
|
23
|
+
export function createHotkeySequenceRecorder(
|
|
24
|
+
options:
|
|
25
|
+
| HotkeySequenceRecorderOptions
|
|
26
|
+
| (() => HotkeySequenceRecorderOptions),
|
|
27
|
+
): SolidHotkeySequenceRecorder {
|
|
28
|
+
const defaultOptions = useDefaultHotkeysOptions()
|
|
29
|
+
|
|
30
|
+
const resolvedOptions = typeof options === 'function' ? options() : options
|
|
31
|
+
const mergedOptions = {
|
|
32
|
+
...defaultOptions.hotkeySequenceRecorder,
|
|
33
|
+
...resolvedOptions,
|
|
34
|
+
} as HotkeySequenceRecorderOptions
|
|
35
|
+
|
|
36
|
+
const recorder = new HotkeySequenceRecorder(mergedOptions)
|
|
37
|
+
|
|
38
|
+
const isRecording = useStore(recorder.store, (state) => state.isRecording)
|
|
39
|
+
const steps = useStore(recorder.store, (state) => state.steps)
|
|
40
|
+
const recordedSequence = useStore(
|
|
41
|
+
recorder.store,
|
|
42
|
+
(state) => state.recordedSequence,
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
createEffect(() => {
|
|
46
|
+
const resolved = typeof options === 'function' ? options() : options
|
|
47
|
+
recorder.setOptions({
|
|
48
|
+
...defaultOptions.hotkeySequenceRecorder,
|
|
49
|
+
...resolved,
|
|
50
|
+
} as HotkeySequenceRecorderOptions)
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
onCleanup(() => {
|
|
54
|
+
recorder.destroy()
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
return {
|
|
58
|
+
isRecording,
|
|
59
|
+
steps,
|
|
60
|
+
recordedSequence,
|
|
61
|
+
startRecording: () => recorder.start(),
|
|
62
|
+
stopRecording: () => recorder.stop(),
|
|
63
|
+
cancelRecording: () => recorder.cancel(),
|
|
64
|
+
commitRecording: () => recorder.commit(),
|
|
65
|
+
}
|
|
66
|
+
}
|
package/src/index.ts
CHANGED