ngx-keys 1.0.0 → 1.0.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.
Files changed (2) hide show
  1. package/README.md +92 -20
  2. package/package.json +3 -3
package/README.md CHANGED
@@ -19,14 +19,21 @@ npm install ngx-keys
19
19
  ```
20
20
 
21
21
  ## Quick Start
22
- ### Displaying Shortcuts
22
+
23
+ ### Register and Display Shortcuts
24
+ >[!NOTE]
25
+ For related shortcuts, use groups for easier management (*[See group management section](#group-management)*).
23
26
 
24
27
  ```typescript
25
- import { Component, inject } from '@angular/core';
28
+ import { Component, DestroyRef, inject } from '@angular/core';
26
29
  import { KeyboardShortcuts } from 'ngx-keys';
27
30
 
28
31
  @Component({
29
32
  template: `
33
+ <h3>My App</h3>
34
+ <p>Last action: {{ lastAction }}</p>
35
+
36
+ <h4>Available Shortcuts:</h4>
30
37
  @for (shortcut of activeShortcuts(); track shortcut.id) {
31
38
  <div>
32
39
  <kbd>{{ shortcut.keys }}</kbd> - {{ shortcut.description }}
@@ -34,11 +41,69 @@ import { KeyboardShortcuts } from 'ngx-keys';
34
41
  }
35
42
  `
36
43
  })
37
- export class ShortcutsComponent {
44
+ export class MyComponent {
38
45
  private readonly keyboardService = inject(KeyboardShortcuts);
46
+ private readonly destroyRef = inject(DestroyRef);
47
+
48
+ protected lastAction = 'Try pressing Ctrl+S or Ctrl+H';
39
49
  protected readonly activeShortcuts = () => this.keyboardService.shortcutsUI$().active;
50
+
51
+ constructor() {
52
+ // Register individual shortcuts (automatically activated)
53
+ this.keyboardService.register({
54
+ id: 'save',
55
+ keys: ['ctrl', 's'],
56
+ macKeys: ['meta', 's'],
57
+ action: () => this.save(),
58
+ description: 'Save document'
59
+ });
60
+
61
+ this.keyboardService.register({
62
+ id: 'help',
63
+ keys: ['ctrl', 'h'],
64
+ macKeys: ['meta', 'h'],
65
+ action: () => this.showHelp(),
66
+ description: 'Show help'
67
+ });
68
+
69
+ // Clean up on component destroy
70
+ this.destroyRef.onDestroy(() => {
71
+ this.keyboardService.unregister('save');
72
+ this.keyboardService.unregister('help');
73
+ });
74
+ }
75
+
76
+ private save() {
77
+ this.lastAction = 'Document saved!';
78
+ }
79
+
80
+ private showHelp() {
81
+ this.lastAction = 'Help displayed!';
82
+ }
40
83
  }
41
84
  ```
85
+
86
+
87
+
88
+ ## Explore the Demo
89
+
90
+ Want to see ngx-keys in action? Check out our comprehensive [demo application](/projects/demo) with:
91
+
92
+ | Component | Purpose | Key Features |
93
+ | ---------------------------------------------------------------------------------- | -------------------------- | --------------------------------------------- |
94
+ | [**App Component**](/projects/demo/src/app/app.ts) | Global shortcuts | Single & group registration, cleanup patterns |
95
+ | [**Home Component**](/projects/demo/src/app/home/home.component.ts) | Reactive UI | Real-time status display, toggle controls |
96
+ | [**Feature Component**](/projects/demo/src/app/feature/feature.component.ts) | Route-specific shortcuts | Scoped shortcuts, lifecycle management |
97
+ | [**Customize Component**](/projects/demo/src/app/customize/customize.component.ts) | Dynamic shortcut recording | Real-time key capture, shortcut customization |
98
+
99
+ **Run the demo:**
100
+ ```bash
101
+ git clone https://github.com/mrivasperez/ngx-keys
102
+ cd ngx-keys
103
+ npm install
104
+ npm start
105
+ ```
106
+
42
107
  ## Key Concepts
43
108
 
44
109
  ### Automatic Activation
@@ -157,21 +222,21 @@ interface KeyboardShortcutGroup {
157
222
 
158
223
  ### Modifier Keys
159
224
 
160
- | PC/Linux | Mac | Description |
161
- |----------|-----|-------------|
162
- | `ctrl` | `meta` | Control/Command key |
163
- | `alt` | `alt` | Alt/Option key |
164
- | `shift` | `shift` | Shift key |
225
+ | PC/Linux | Mac | Description |
226
+ | -------- | ------- | ------------------- |
227
+ | `ctrl` | `meta` | Control/Command key |
228
+ | `alt` | `alt` | Alt/Option key |
229
+ | `shift` | `shift` | Shift key |
165
230
 
166
231
  ### Special Keys
167
232
 
168
- | Key | Value |
169
- |-----|-------|
170
- | Function keys | `f1`, `f2`, `f3`, ... `f12` |
171
- | Arrow keys | `arrowup`, `arrowdown`, `arrowleft`, `arrowright` |
172
- | Navigation | `home`, `end`, `pageup`, `pagedown` |
173
- | Editing | `insert`, `delete`, `backspace` |
174
- | Other | `escape`, `tab`, `enter`, `space` |
233
+ | Key | Value |
234
+ | ------------- | ------------------------------------------------- |
235
+ | Function keys | `f1`, `f2`, `f3`, ... `f12` |
236
+ | Arrow keys | `arrowup`, `arrowdown`, `arrowleft`, `arrowright` |
237
+ | Navigation | `home`, `end`, `pageup`, `pagedown` |
238
+ | Editing | `insert`, `delete`, `backspace` |
239
+ | Other | `escape`, `tab`, `enter`, `space` |
175
240
 
176
241
  ## Browser Conflicts Warning
177
242
 
@@ -187,18 +252,19 @@ interface KeyboardShortcutGroup {
187
252
  - `Ctrl+D` / `⌘+D` - Bookmark page
188
253
 
189
254
  ### Safer Alternatives
255
+ > [!TIP]
256
+ > Always test your shortcuts across different browsers and operating systems. Consider providing alternative key combinations or allow users to customize shortcuts.
190
257
  - Function keys: `F1`, `F2`, `F3`, etc.
191
258
  - Custom combinations: `Ctrl+Shift+S`, `Alt+Enter`
192
259
  - Arrow keys with modifiers: `Ctrl+ArrowUp`
193
260
  - Application-specific: `Ctrl+K`, `Ctrl+P` (if not conflicting)
194
261
 
195
- ### Testing Browser Conflicts
196
-
197
- > [!TIP]
198
- > Always test your shortcuts across different browsers and operating systems. Consider providing alternative key combinations or allow users to customize shortcuts.
199
262
 
200
263
  ## Advanced Usage
201
264
 
265
+ > [!TIP]
266
+ Check out our [demo application](/projects/demo/src/app) for full implementations of all patterns shown below.
267
+
202
268
  ### Reactive UI Integration
203
269
 
204
270
  ```typescript
@@ -239,6 +305,9 @@ export class ShortcutsDisplayComponent {
239
305
  ```
240
306
  ### Group Management
241
307
 
308
+ > [!NOTE]
309
+ > **Live Example**: See this pattern in action in [feature.component.ts](/projects/demo/src/app/feature/feature.component.ts)
310
+
242
311
  ```typescript
243
312
  import { Component, DestroyRef, inject } from '@angular/core';
244
313
  import { KeyboardShortcuts, KeyboardShortcut } from 'ngx-keys';
@@ -289,7 +358,7 @@ export class FeatureComponent {
289
358
 
290
359
  ### Batch Operations
291
360
 
292
- For better performance when making multiple changes, use the `batchUpdate` method:
361
+ For better performance when making multiple changes, use the `batchUpdate` method.
293
362
 
294
363
  ```typescript
295
364
  import { Component, inject } from '@angular/core';
@@ -331,6 +400,9 @@ export class BatchUpdateComponent {
331
400
 
332
401
  ### Checking Status
333
402
 
403
+ > [!NOTE]
404
+ > See status checking in [home.component.ts](/projects/demo/src/app/home/home.component.ts)
405
+
334
406
  ```typescript
335
407
  import { Component, inject } from '@angular/core';
336
408
  import { KeyboardShortcuts } from 'ngx-keys';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ngx-keys",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "A reactive Angular library for managing keyboard shortcuts with signals-based UI integration",
5
5
  "keywords": [
6
6
  "angular",
@@ -18,7 +18,7 @@
18
18
  "author": "NgxKeys Contributors",
19
19
  "repository": {
20
20
  "type": "git",
21
- "url": "git+https://github.com/mrivasperez/ngx-keys.git"
21
+ "url": "https://github.com/mrivasperez/ngx-keys.git"
22
22
  },
23
23
  "bugs": {
24
24
  "url": "https://github.com/mrivasperez/ngx-keys/issues"
@@ -43,4 +43,4 @@
43
43
  "default": "./fesm2022/ngx-keys.mjs"
44
44
  }
45
45
  }
46
- }
46
+ }