@keybindy/react 1.0.0 → 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.
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @keybindy/react
2
2
 
3
- @keybindy/react is the official React integration for the [Keybindy](https://www.npmjs.com/package/@keybindy/core) keyboard shortcut system. Built on top of `@keybindy/core`, this package brings powerful and scoped keyboard bindings to your React applications — with components and hooks tailored to React’s architecture.
3
+ `@keybindy/react` is the official React integration for the [Keybindy](https://www.npmjs.com/package/@keybindy/core) keyboard shortcut system. Built on top of `@keybindy/core`, this package brings powerful and scoped keyboard bindings to your React applications — with components and hooks tailored to React’s architecture.
4
4
 
5
5
  [![npm version](https://badge.fury.io/js/@keybindy%2Freact.svg)](https://www.npmjs.com/package/@keybindy/react)
6
6
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
@@ -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
@@ -1,5 +1,6 @@
1
1
  import React from 'react';
2
2
  import ShortcutManager, { Keys, ShortcutHandler, ShortcutOptions, Shortcut } from '@keybindy/core';
3
+ export { KeyBinding, Keys, Shortcut, ShortcutHandler, ShortcutOptions } from '@keybindy/core';
3
4
  import * as react_jsx_runtime from 'react/jsx-runtime';
4
5
 
5
6
  /**
@@ -28,7 +29,7 @@ type KeybindyProps = {
28
29
  * The scope under which the shortcuts should be active.
29
30
  * This allows managing different contexts for shortcuts.
30
31
  */
31
- scope: string;
32
+ scope?: 'global' | string;
32
33
  /**
33
34
  * Array of shortcut definitions to register for this scope.
34
35
  */
@@ -142,6 +143,33 @@ interface ShortcutLabelProps extends React.DetailedHTMLProps<React.HTMLAttribute
142
143
  */
143
144
  declare const ShortcutLabel: ({ keys, renderKey, style, ...props }: ShortcutLabelProps) => react_jsx_runtime.JSX.Element;
144
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
+ };
145
173
  /**
146
174
  * React hook to manage keyboard shortcuts using a shared instance of `ShortcutManager`.
147
175
  * Automatically cleans up shortcuts registered by the component on unmount.
@@ -166,51 +194,9 @@ declare const ShortcutLabel: ({ keys, renderKey, style, ...props }: ShortcutLabe
166
194
  * setScope('editor');
167
195
  * }, []);
168
196
  */
169
- declare function useKeybindy({ logs, onShortcutFired, }?: {
197
+ declare const useKeybindy: ({ logs, onShortcutFired, }?: {
170
198
  logs?: boolean;
171
199
  onShortcutFired?: (info: Shortcut) => void;
172
- }): {
173
- register: (keys: Keys[] | Keys[][], handler: ShortcutHandler, options?: ShortcutOptions) => void;
174
- unregister: (keys: Keys[], scope?: string) => void;
175
- enable: (keys: Keys[], scope?: string) => void;
176
- disable: (keys: Keys[], scope?: string) => void;
177
- toggle: (keys: Keys[], scope?: string) => void;
178
- setScope: (scope: string) => void;
179
- getCheatSheet: (scope?: string) => {
180
- keys: string[];
181
- }[] | undefined;
182
- destroy: () => void;
183
- getScopeInfo: (scope?: string) => {
184
- shortcuts: {
185
- keys: string[];
186
- id: string;
187
- enabled: boolean;
188
- data?: Record<string, string>;
189
- }[];
190
- isActive?: boolean;
191
- } | Record<string, {
192
- shortcuts: {
193
- keys: string[];
194
- id: string;
195
- enabled: boolean;
196
- data?: Record<string, string>;
197
- }[];
198
- isActive?: boolean;
199
- }> | undefined;
200
- getActiveScope: () => string | undefined;
201
- popScope: () => void;
202
- pushScope: (scope: string) => void;
203
- resetScope: () => void;
204
- getScopes: () => string[] | undefined;
205
- isScopeActive: (scope: string) => boolean | undefined;
206
- onTyping: (callback: (payload: {
207
- key: string;
208
- event: KeyboardEvent;
209
- }) => void) => void;
210
- enableAll: (scope?: string) => void;
211
- clear: () => void;
212
- disableAll: (scope?: string) => void;
213
- manager: ShortcutManager;
214
- };
200
+ }) => UseKeybindyReturn;
215
201
 
216
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.0",
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
+ }