@rrstudioapps/ngx-command-palette 0.0.0-stage → 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 rrstudio
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,297 @@
1
- # Temporary Holding Version
1
+ # ngx-command-palette
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ An accessible **⌘K / Ctrl+K command palette for Angular**. A modern equivalent of
4
+ [cmdk](https://cmdk.paco.me) and [kbar](https://kbar.vercel.app), built the Angular way:
5
+ standalone components, signals, zoneless-ready and **no dependencies besides Angular**.
6
+
7
+ [![CI](https://github.com/rrstudioapps/ngx-command-palette/actions/workflows/ci.yml/badge.svg)](https://github.com/rrstudioapps/ngx-command-palette/actions/workflows/ci.yml)
8
+ [![npm](https://img.shields.io/npm/v/@rrstudioapps/ngx-command-palette)](https://www.npmjs.com/package/@rrstudioapps/ngx-command-palette)
9
+ [![license: MIT](https://img.shields.io/badge/license-MIT-blue)](LICENSE)
10
+
11
+ **[Live demo →](https://demo.rr-dev.eu/command-palette/)**
12
+
13
+ ![ngx-command-palette demo: fuzzy search, theme switch and async customer search](https://raw.githubusercontent.com/rrstudioapps/ngx-command-palette/main/docs/demo.gif)
14
+
15
+ ## Features
16
+
17
+ - Opens with **⌘K / Ctrl+K** (configurable, multiple shortcuts allowed), closes with **Esc** or a click outside
18
+ - **Fuzzy search** with highlighted matches, case and accent insensitive, smart ranking (word starts, consecutive letters)
19
+ - Commands grouped in **sections**, with optional **icon**, **description**, **shortcut hint** and extra **keywords**
20
+ - Each command either **navigates to a route** or **runs a function**
21
+ - Optional **Recent** section, stored in `localStorage`
22
+ - **Async providers** (e.g. customer search on your API) with debounce, loading state and request cancellation
23
+ - Register commands **from any component** with signals; they are **removed automatically** when the component is destroyed
24
+ - Full **keyboard navigation**: ↑ ↓, Home / End, Enter, Ctrl+N / Ctrl+P
25
+ - **Accessible**: dialog + combobox/listbox pattern, `aria-activedescendant`, focus trap, focus restore, live region, `prefers-reduced-motion`
26
+ - **Themeable** with CSS variables (`--rr-cp-*`), light and dark themes, no Tailwind required
27
+ - Custom **templates** for items and the empty state
28
+ - No browser globals at import time (SSR friendly), works with or without zone.js
29
+
30
+ | Light | Dark |
31
+ | --- | --- |
32
+ | ![Light theme](https://raw.githubusercontent.com/rrstudioapps/ngx-command-palette/main/docs/screenshot-light.png) | ![Dark theme](https://raw.githubusercontent.com/rrstudioapps/ngx-command-palette/main/docs/screenshot-dark.png) |
33
+
34
+ ## Installation
35
+
36
+ ```bash
37
+ npm install @rrstudioapps/ngx-command-palette
38
+ ```
39
+
40
+ Requires Angular 21 or 22 (`@angular/core`, `@angular/common`, `@angular/router`).
41
+
42
+ ## Quick start (5 minutes)
43
+
44
+ **1. Configure it** (optional: without this call the defaults are used).
45
+
46
+ ```ts
47
+ // app.config.ts
48
+ import { provideCommandPalette } from '@rrstudioapps/ngx-command-palette';
49
+
50
+ export const appConfig: ApplicationConfig = {
51
+ providers: [
52
+ provideRouter(routes),
53
+ provideCommandPalette({ shortcut: 'mod+k' }),
54
+ ],
55
+ };
56
+ ```
57
+
58
+ **2. Place the palette once** and register some commands.
59
+
60
+ ```ts
61
+ // app.ts
62
+ import { Component, inject } from '@angular/core';
63
+ import { CommandPaletteComponent, injectCommands } from '@rrstudioapps/ngx-command-palette';
64
+
65
+ @Component({
66
+ selector: 'app-root',
67
+ imports: [CommandPaletteComponent, RouterOutlet],
68
+ template: `
69
+ <router-outlet />
70
+ <rr-command-palette />
71
+ `,
72
+ })
73
+ export class App {
74
+ private auth = inject(AuthService);
75
+
76
+ constructor() {
77
+ injectCommands([
78
+ { id: 'home', label: 'Home', group: 'Navigation', route: '/' },
79
+ { id: 'settings', label: 'Settings', group: 'Navigation', route: '/settings', keywords: ['preferences'] },
80
+ { id: 'logout', label: 'Log out', icon: '🚪', run: () => this.auth.logout() },
81
+ ]);
82
+ }
83
+ }
84
+ ```
85
+
86
+ **3. Press ⌘K / Ctrl+K.** That's it.
87
+
88
+ **4. Add page commands** from any component. They exist only while the component is alive.
89
+ Pass a signal to keep them in sync with your state:
90
+
91
+ ```ts
92
+ @Component({ /* … */ })
93
+ export class ProjectsPage {
94
+ projects = signal<Project[]>([]);
95
+
96
+ constructor() {
97
+ injectCommands(
98
+ computed(() => [
99
+ { id: 'project-new', label: 'New project', group: 'Projects', run: () => this.create() },
100
+ ...this.projects().map((p) => ({
101
+ id: `project-${p.id}`,
102
+ label: `Open ${p.name}`,
103
+ group: 'Projects',
104
+ route: ['/projects', p.id],
105
+ })),
106
+ ]),
107
+ );
108
+ }
109
+ }
110
+ ```
111
+
112
+ **5. Search your API** with an async provider:
113
+
114
+ ```ts
115
+ injectCommandProvider({
116
+ id: 'customers',
117
+ group: 'Customers',
118
+ minQueryLength: 2,
119
+ search: async (query, signal) => {
120
+ const res = await fetch(`/api/customers?q=${encodeURIComponent(query)}`, { signal });
121
+ const customers: Customer[] = await res.json();
122
+ return customers.map((c) => ({
123
+ id: `customer-${c.id}`,
124
+ label: c.name,
125
+ description: c.email,
126
+ route: ['/customers', c.id],
127
+ }));
128
+ },
129
+ });
130
+ ```
131
+
132
+ `search` can also return an Observable (e.g. from `HttpClient`): anything with a `subscribe` method works.
133
+
134
+ ## API
135
+
136
+ ### `provideCommandPalette(options?)`
137
+
138
+ | Option | Type | Default | Description |
139
+ | --- | --- | --- | --- |
140
+ | `shortcut` | `string \| string[]` | `'mod+k'` | Toggle shortcut(s). `mod` is ⌘ on macOS/iOS and Ctrl elsewhere. Examples: `'ctrl+shift+p'`, `'/'`. Shortcuts without Ctrl/⌘/Alt are ignored while typing in a field. |
141
+ | `theme` | `'light' \| 'dark' \| 'auto'` | `'auto'` | `auto` follows `prefers-color-scheme`. |
142
+ | `recent` | `{ max?, storageKey? } \| false` | `{ max: 5, storageKey: 'rr-cp:recent' }` | "Recent" section shown when the query is empty. |
143
+ | `debounceMs` | `number` | `200` | Debounce for async providers. |
144
+ | `maxResults` | `number` | `50` | Max local results for a non-empty query. |
145
+ | `labels` | `Partial<CommandPaletteLabels>` | English | All texts, for translations: `placeholder`, `dialog`, `listbox`, `empty`, `loading`, `recent`, `defaultGroup`, `results` (`'{count} results'`), `closeHint`. |
146
+
147
+ ### `Command`
148
+
149
+ | Field | Type | Description |
150
+ | --- | --- | --- |
151
+ | `id` | `string` | Unique and stable (used for recents). |
152
+ | `label` | `string` | Shown and searched. |
153
+ | `group` | `string?` | Section. Default: `labels.defaultGroup`. |
154
+ | `description` | `string?` | Second line, searched with a lower weight. |
155
+ | `icon` | `string \| TemplateRef?` | Emoji/text/icon-font ligature, or a template (e.g. an SVG). |
156
+ | `shortcut` | `string[]?` | Keys shown on the right, e.g. `['⌘', 'S']`. Display only. |
157
+ | `keywords` | `string[]?` | Extra search terms, not shown. |
158
+ | `disabled` | `boolean?` | Shown but not selectable. |
159
+ | `route` + `navigationExtras` | `string \| any[]`, `NavigationExtras?` | Navigate with the Angular router… |
160
+ | `run` | `(ctx: { query }) => void \| Promise` | …or run a function. |
161
+
162
+ ### `CommandPaletteService`
163
+
164
+ | Member | Description |
165
+ | --- | --- |
166
+ | `isOpen`, `query`, `loading` | Read-only signals. |
167
+ | `commands`, `sections` | Registered commands and the filtered, grouped results (signals). |
168
+ | `open(query?)`, `close()`, `toggle()` | Open/close programmatically (e.g. from a "Search…" button). |
169
+ | `setQuery(query)` | Change the search text. |
170
+ | `register(commands \| signal, destroyRef?)` | Returns an unregister function. Inside an injection context it unregisters on destroy. |
171
+ | `registerProvider(provider, destroyRef?)` | Same, for async providers. |
172
+ | `execute(command)` | Run a command as if selected. |
173
+ | `clearRecent()` | Forget the recents. |
174
+
175
+ `injectCommands(commands)` and `injectCommandProvider(provider)` are shortcuts for
176
+ `register`/`registerProvider` bound to the current component.
177
+
178
+ ### `CommandProvider`
179
+
180
+ | Field | Type | Description |
181
+ | --- | --- | --- |
182
+ | `id`, `group` | `string` | Provider id and section title. |
183
+ | `search(query, signal)` | `Promise<Command[]> \| Observable<Command[]>` | `signal` is aborted when the query changes or the palette closes. |
184
+ | `minQueryLength` | `number?` | Default `1`. |
185
+ | `debounceMs` | `number?` | Overrides the global debounce. |
186
+
187
+ Async results keep the order returned by your API. Route commands from a provider are kept
188
+ in "Recent" even when they are no longer returned by the search.
189
+
190
+ ### `<rr-command-palette>`
191
+
192
+ | Input | Description |
193
+ | --- | --- |
194
+ | `theme` | Overrides the configured theme, e.g. `[theme]="appTheme()"` to follow your own toggle. |
195
+
196
+ The component also exposes `shortcutLabel` (`'⌘K'` or `'Ctrl+K'`) for your search button:
197
+ `<rr-command-palette #cp />` … `<kbd>{{ cp.shortcutLabel }}</kbd>`.
198
+
199
+ ### Custom templates
200
+
201
+ ```html
202
+ <rr-command-palette>
203
+ <ng-template rrCommandItem let-command let-segments="segments" let-active="active">
204
+ <my-icon [name]="command.id" />
205
+ <span>
206
+ @for (s of segments; track $index) {
207
+ @if (s.match) { <b>{{ s.text }}</b> } @else { {{ s.text }} }
208
+ }
209
+ </span>
210
+ @if (active) { <span class="hint">↵</span> }
211
+ </ng-template>
212
+
213
+ <ng-template rrCommandEmpty let-query>
214
+ No results for “{{ query }}”. <a href="/help">Need help?</a>
215
+ </ng-template>
216
+ </rr-command-palette>
217
+ ```
218
+
219
+ Import `CommandItemTemplate` and `CommandEmptyTemplate` next to `CommandPaletteComponent`.
220
+ The item context also has `result` (score and indices) and `query`.
221
+
222
+ ### Utilities
223
+
224
+ `fuzzyMatch(query, text)` returns `{ score, indices } | null`. `highlightSegments(text, indices)`
225
+ splits a string for highlighting. `parseShortcut`, `matchesShortcut` and `formatShortcut`
226
+ handle shortcut strings. All of them are exported if you want the same behaviour elsewhere.
227
+
228
+ ## Theming
229
+
230
+ The styles use CSS variables with zero-specificity defaults, so any rule of yours wins.
231
+ Set them on `.rr-cp` (the overlay), and on `.rr-cp[data-theme='dark']` for the dark theme:
232
+
233
+ ```css
234
+ .rr-cp {
235
+ --rr-cp-accent: #e11d48;
236
+ --rr-cp-highlight: #e11d48;
237
+ --rr-cp-radius: 16px;
238
+ --rr-cp-font: 'Inter', sans-serif;
239
+ }
240
+
241
+ .rr-cp[data-theme='dark'] {
242
+ --rr-cp-bg: #0f0f12;
243
+ }
244
+ ```
245
+
246
+ | Variable | Purpose |
247
+ | --- | --- |
248
+ | `--rr-cp-bg`, `--rr-cp-fg`, `--rr-cp-muted`, `--rr-cp-border` | Surface, text, secondary text, borders |
249
+ | `--rr-cp-accent` | Active row marker, spinner |
250
+ | `--rr-cp-item-active-bg` | Active row background |
251
+ | `--rr-cp-highlight`, `--rr-cp-highlight-bg` | Matched characters |
252
+ | `--rr-cp-kbd-bg`, `--rr-cp-kbd-fg` | Shortcut keys |
253
+ | `--rr-cp-backdrop`, `--rr-cp-shadow` | Overlay and dialog shadow |
254
+ | `--rr-cp-font`, `--rr-cp-font-size` | Typography |
255
+ | `--rr-cp-width`, `--rr-cp-max-height`, `--rr-cp-top` | Dialog size and position |
256
+ | `--rr-cp-radius`, `--rr-cp-item-radius` | Corners |
257
+ | `--rr-cp-z-index`, `--rr-cp-duration` | Stacking and animation length |
258
+
259
+ Class names (`rr-cp-dialog`, `rr-cp-item`, `rr-cp-item-active`, `rr-cp-match`, `rr-cp-group-label`,
260
+ `rr-cp-empty`, …) are stable too, if you need more than variables.
261
+
262
+ ## Accessibility
263
+
264
+ - The palette is a modal `role="dialog"` with `aria-modal="true"` and a label.
265
+ - The search field is a `role="combobox"` that controls a `role="listbox"`. Sections are
266
+ `role="group"` with a label. The active option is announced through `aria-activedescendant`,
267
+ so the focus never leaves the input.
268
+ - Disabled commands use `aria-disabled` and are skipped by the keyboard.
269
+ - Focus is trapped inside the dialog and **restored** to the previously focused element on close.
270
+ - A polite live region announces the number of results and the loading state.
271
+ - Animations are disabled with `prefers-reduced-motion: reduce`, and active rows and matches
272
+ stay visible in Windows high contrast mode (`forced-colors`).
273
+ - The demo is checked with axe-core: 0 violations in light and dark themes.
274
+
275
+ ## Development
276
+
277
+ ```bash
278
+ npm install
279
+ npm start # demo on http://localhost:4200
280
+ npm test # unit tests (Vitest)
281
+ npm run lint
282
+ npm run build # library (dist/ngx-command-palette) + demo
283
+ ```
284
+
285
+ See [CONTRIBUTING.md](CONTRIBUTING.md).
286
+
287
+ ## License
288
+
289
+ [MIT](LICENSE) © 2026 rrstudio
290
+
291
+ ## Need a full dashboard? Check out Providentia
292
+
293
+ **Providentia** is a complete Angular admin dashboard template by the same author: analytics,
294
+ customer tables, report builder, billing, roles, light and dark themes, and a command palette
295
+ built in.
296
+
297
+ **[See the Providentia live demo →](https://demo.rr-dev.eu/providentia/overview)**