@keybindy/react 1.0.1 → 1.0.2

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.
@@ -26,7 +26,7 @@ type KeybindyProps = {
26
26
  * The scope under which the shortcuts should be active.
27
27
  * This allows managing different contexts for shortcuts.
28
28
  */
29
- scope: string;
29
+ scope?: 'global' | string;
30
30
  /**
31
31
  * Array of shortcut definitions to register for this scope.
32
32
  */
package/dist/Keybindy.js CHANGED
@@ -35,7 +35,7 @@ import { useKeybindy } from './useKeybindy.js';
35
35
  *
36
36
  * @returns {JSX.Element} The rendered component with registered shortcuts within the provided scope.
37
37
  */
38
- const Keybindy = ({ scope, shortcuts = [], children, disabled, onShortcutFired, logs = false, }) => {
38
+ const Keybindy = ({ scope = 'global', shortcuts = [], children, disabled, onShortcutFired, logs = false, }) => {
39
39
  const { register, unregister, manager, pushScope, popScope, getScopes, setScope } = useKeybindy({
40
40
  onShortcutFired,
41
41
  logs,
package/dist/index.d.ts CHANGED
@@ -29,7 +29,7 @@ type KeybindyProps = {
29
29
  * The scope under which the shortcuts should be active.
30
30
  * This allows managing different contexts for shortcuts.
31
31
  */
32
- scope: string;
32
+ scope?: 'global' | string;
33
33
  /**
34
34
  * Array of shortcut definitions to register for this scope.
35
35
  */
@@ -143,6 +143,33 @@ interface ShortcutLabelProps extends React.DetailedHTMLProps<React.HTMLAttribute
143
143
  */
144
144
  declare const ShortcutLabel: ({ keys, renderKey, style, ...props }: ShortcutLabelProps) => react_jsx_runtime.JSX.Element;
145
145
 
146
+ type UseKeybindyReturn = {
147
+ register: (keys: Keys[] | Keys[][], handler: ShortcutHandler, options?: ShortcutOptions) => void;
148
+ unregister: (keys: Keys[], scope?: string) => void;
149
+ enable: (keys: Keys[], scope?: string) => void;
150
+ disable: (keys: Keys[], scope?: string) => void;
151
+ toggle: (keys: Keys[], scope?: string) => void;
152
+ setScope: (scope: string) => void;
153
+ getCheatSheet: (scope?: string) => {
154
+ keys: string[];
155
+ }[] | undefined;
156
+ destroy: () => void;
157
+ getScopeInfo: (scope?: string) => any;
158
+ getActiveScope: () => string;
159
+ popScope: () => void;
160
+ pushScope: (scope: string) => void;
161
+ resetScope: () => void;
162
+ getScopes: () => string[];
163
+ isScopeActive: (scope: string) => boolean | undefined;
164
+ onTyping: (callback: (payload: {
165
+ key: string;
166
+ event: KeyboardEvent;
167
+ }) => void) => void;
168
+ enableAll: (scope?: string) => void;
169
+ clear: () => void;
170
+ disableAll: (scope?: string) => void;
171
+ manager: ShortcutManager;
172
+ };
146
173
  /**
147
174
  * React hook to manage keyboard shortcuts using a shared instance of `ShortcutManager`.
148
175
  * Automatically cleans up shortcuts registered by the component on unmount.
@@ -167,51 +194,9 @@ declare const ShortcutLabel: ({ keys, renderKey, style, ...props }: ShortcutLabe
167
194
  * setScope('editor');
168
195
  * }, []);
169
196
  */
170
- declare function useKeybindy({ logs, onShortcutFired, }?: {
197
+ declare const useKeybindy: ({ logs, onShortcutFired, }?: {
171
198
  logs?: boolean;
172
199
  onShortcutFired?: (info: Shortcut) => void;
173
- }): {
174
- register: (keys: Keys[] | Keys[][], handler: ShortcutHandler, options?: ShortcutOptions) => void;
175
- unregister: (keys: Keys[], scope?: string) => void;
176
- enable: (keys: Keys[], scope?: string) => void;
177
- disable: (keys: Keys[], scope?: string) => void;
178
- toggle: (keys: Keys[], scope?: string) => void;
179
- setScope: (scope: string) => void;
180
- getCheatSheet: (scope?: string) => {
181
- keys: string[];
182
- }[] | undefined;
183
- destroy: () => void;
184
- getScopeInfo: (scope?: string) => {
185
- shortcuts: {
186
- keys: string[];
187
- id: string;
188
- enabled: boolean;
189
- data?: Record<string, string>;
190
- }[];
191
- isActive?: boolean;
192
- } | Record<string, {
193
- shortcuts: {
194
- keys: string[];
195
- id: string;
196
- enabled: boolean;
197
- data?: Record<string, string>;
198
- }[];
199
- isActive?: boolean;
200
- }> | undefined;
201
- getActiveScope: () => string | undefined;
202
- popScope: () => void;
203
- pushScope: (scope: string) => void;
204
- resetScope: () => void;
205
- getScopes: () => string[] | undefined;
206
- isScopeActive: (scope: string) => boolean | undefined;
207
- onTyping: (callback: (payload: {
208
- key: string;
209
- event: KeyboardEvent;
210
- }) => void) => void;
211
- enableAll: (scope?: string) => void;
212
- clear: () => void;
213
- disableAll: (scope?: string) => void;
214
- manager: ShortcutManager;
215
- };
200
+ }) => UseKeybindyReturn;
216
201
 
217
202
  export { Keybindy, ShortcutLabel, useKeybindy };
@@ -1,5 +1,32 @@
1
1
  import ShortcutManager from '@keybindy/core';
2
2
  import type { Keys, Shortcut, ShortcutHandler, ShortcutOptions } from '@keybindy/core';
3
+ type UseKeybindyReturn = {
4
+ register: (keys: Keys[] | Keys[][], handler: ShortcutHandler, options?: ShortcutOptions) => void;
5
+ unregister: (keys: Keys[], scope?: string) => void;
6
+ enable: (keys: Keys[], scope?: string) => void;
7
+ disable: (keys: Keys[], scope?: string) => void;
8
+ toggle: (keys: Keys[], scope?: string) => void;
9
+ setScope: (scope: string) => void;
10
+ getCheatSheet: (scope?: string) => {
11
+ keys: string[];
12
+ }[] | undefined;
13
+ destroy: () => void;
14
+ getScopeInfo: (scope?: string) => any;
15
+ getActiveScope: () => string;
16
+ popScope: () => void;
17
+ pushScope: (scope: string) => void;
18
+ resetScope: () => void;
19
+ getScopes: () => string[];
20
+ isScopeActive: (scope: string) => boolean | undefined;
21
+ onTyping: (callback: (payload: {
22
+ key: string;
23
+ event: KeyboardEvent;
24
+ }) => void) => void;
25
+ enableAll: (scope?: string) => void;
26
+ clear: () => void;
27
+ disableAll: (scope?: string) => void;
28
+ manager: ShortcutManager;
29
+ };
3
30
  /**
4
31
  * React hook to manage keyboard shortcuts using a shared instance of `ShortcutManager`.
5
32
  * Automatically cleans up shortcuts registered by the component on unmount.
@@ -24,49 +51,8 @@ import type { Keys, Shortcut, ShortcutHandler, ShortcutOptions } from '@keybindy
24
51
  * setScope('editor');
25
52
  * }, []);
26
53
  */
27
- export declare function useKeybindy({ logs, onShortcutFired, }?: {
54
+ export declare const useKeybindy: ({ logs, onShortcutFired, }?: {
28
55
  logs?: boolean;
29
56
  onShortcutFired?: (info: Shortcut) => void;
30
- }): {
31
- register: (keys: Keys[] | Keys[][], handler: ShortcutHandler, options?: ShortcutOptions) => void;
32
- unregister: (keys: Keys[], scope?: string) => void;
33
- enable: (keys: Keys[], scope?: string) => void;
34
- disable: (keys: Keys[], scope?: string) => void;
35
- toggle: (keys: Keys[], scope?: string) => void;
36
- setScope: (scope: string) => void;
37
- getCheatSheet: (scope?: string) => {
38
- keys: string[];
39
- }[] | undefined;
40
- destroy: () => void;
41
- getScopeInfo: (scope?: string) => {
42
- shortcuts: {
43
- keys: string[];
44
- id: string;
45
- enabled: boolean;
46
- data?: Record<string, string>;
47
- }[];
48
- isActive?: boolean;
49
- } | Record<string, {
50
- shortcuts: {
51
- keys: string[];
52
- id: string;
53
- enabled: boolean;
54
- data?: Record<string, string>;
55
- }[];
56
- isActive?: boolean;
57
- }> | undefined;
58
- getActiveScope: () => string | undefined;
59
- popScope: () => void;
60
- pushScope: (scope: string) => void;
61
- resetScope: () => void;
62
- getScopes: () => string[] | undefined;
63
- isScopeActive: (scope: string) => boolean | undefined;
64
- onTyping: (callback: (payload: {
65
- key: string;
66
- event: KeyboardEvent;
67
- }) => void) => void;
68
- enableAll: (scope?: string) => void;
69
- clear: () => void;
70
- disableAll: (scope?: string) => void;
71
- manager: ShortcutManager;
72
- };
57
+ }) => UseKeybindyReturn;
58
+ export {};
@@ -26,11 +26,11 @@ let sharedInstance = null;
26
26
  * setScope('editor');
27
27
  * }, []);
28
28
  */
29
- function useKeybindy({ logs = false, onShortcutFired, } = {}) {
29
+ const useKeybindy = ({ logs = false, onShortcutFired, } = {}) => {
30
30
  const managerRef = React.useRef(null);
31
31
  const registeredIds = React.useRef(new Set());
32
32
  if (!sharedInstance) {
33
- sharedInstance = new ShortcutManager(onShortcutFired);
33
+ sharedInstance = new ShortcutManager({ onShortcutFired, silent: !logs });
34
34
  }
35
35
  if (!managerRef.current) {
36
36
  managerRef.current = sharedInstance;
@@ -132,7 +132,7 @@ function useKeybindy({ logs = false, onShortcutFired, } = {}) {
132
132
  * @returns {string} The active scope.
133
133
  */
134
134
  const getActiveScope = React.useCallback(() => {
135
- return managerRef.current?.getActiveScope();
135
+ return managerRef.current?.getActiveScope() ?? '';
136
136
  }, []);
137
137
  /**
138
138
  * Disables all shortcuts in the specified scope or all scopes if no scope is provided.
@@ -171,7 +171,7 @@ function useKeybindy({ logs = false, onShortcutFired, } = {}) {
171
171
  * @returns An array of scopes.
172
172
  */
173
173
  const getScopes = React.useCallback(() => {
174
- return managerRef.current?.getScopes();
174
+ return managerRef.current?.getScopes() ?? [];
175
175
  }, []);
176
176
  /**
177
177
  * Checks if the given scope is active.
@@ -248,6 +248,6 @@ function useKeybindy({ logs = false, onShortcutFired, } = {}) {
248
248
  disableAll,
249
249
  manager: managerRef.current,
250
250
  };
251
- }
251
+ };
252
252
 
253
253
  export { useKeybindy };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@keybindy/react",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "Keybindy for React: Simple, scoped keyboard shortcuts that require little setup. designed to smoothly blend in with your React applications, allowing for robust keybinding functionality without the overhead.",
5
5
  "author": {
6
6
  "name": "PRASSamin",
@@ -49,7 +49,8 @@
49
49
  "format": "prettier --write \"src/**/*.{ts,tsx}\"",
50
50
  "publish": "npm publish --access public",
51
51
  "prebuild": "rm -rf dist",
52
- "build": "rollup -c"
52
+ "build": "rollup -c",
53
+ "dev": "rollup -c -w"
53
54
  },
54
55
  "devDependencies": {
55
56
  "@rollup/plugin-commonjs": "^28.0.3",
@@ -65,7 +66,7 @@
65
66
  "typescript": "^5.0.0"
66
67
  },
67
68
  "dependencies": {
68
- "@keybindy/core": "^1.0.0",
69
+ "@keybindy/core": "^1.0.2",
69
70
  "react": "^19.1.0"
70
71
  }
71
- }
72
+ }