@rrstudioapps/ngx-command-palette 1.0.0 → 1.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.
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as i0 from "@angular/core";
|
|
2
2
|
import { DestroyRef, EnvironmentProviders, InjectionToken, Signal, TemplateRef } from "@angular/core";
|
|
3
|
-
import { NavigationExtras } from "@angular/router";
|
|
3
|
+
import { NavigationExtras, Route } from "@angular/router";
|
|
4
4
|
/** Context passed to a command's `run` function. */
|
|
5
5
|
interface CommandRunContext {
|
|
6
6
|
/** The search text typed when the command was executed. */
|
|
@@ -148,6 +148,26 @@ type CommandPaletteTheme = 'light' | 'dark' | 'auto';
|
|
|
148
148
|
type CommandPalettePosition = 'top' | 'center';
|
|
149
149
|
/** Why the palette closed, as passed to `onClose`. */
|
|
150
150
|
type CommandPaletteCloseReason = 'escape' | 'overlay' | 'run' | 'toggle' | 'api';
|
|
151
|
+
/** How a route shows up in the palette (see the `routes` option and `Route.data.commandPalette`). */
|
|
152
|
+
interface CommandPaletteRouteInfo {
|
|
153
|
+
readonly label?: string;
|
|
154
|
+
readonly group?: string;
|
|
155
|
+
readonly description?: string;
|
|
156
|
+
readonly icon?: string | TemplateRef<unknown>;
|
|
157
|
+
readonly keywords?: readonly string[];
|
|
158
|
+
}
|
|
159
|
+
/** Options of the `routes` option: commands built from the router configuration. */
|
|
160
|
+
interface CommandPaletteRoutesOptions {
|
|
161
|
+
/** Section of the generated commands. Default: `labels.routesGroup`. */
|
|
162
|
+
readonly group?: string;
|
|
163
|
+
/**
|
|
164
|
+
* Return `false` to leave a route out. Called with the route and its full URL, each time the
|
|
165
|
+
* palette opens and in an injection context, so `inject()` works.
|
|
166
|
+
*/
|
|
167
|
+
readonly filter?: (route: Route, url: string) => boolean;
|
|
168
|
+
/** Overrides what is shown for a route; return `null` to leave it out. Same rules as `filter`. */
|
|
169
|
+
readonly describe?: (route: Route, url: string) => CommandPaletteRouteInfo | null;
|
|
170
|
+
}
|
|
151
171
|
/** Texts of the palette, for translations. */
|
|
152
172
|
interface CommandPaletteLabels {
|
|
153
173
|
readonly placeholder: string;
|
|
@@ -157,6 +177,14 @@ interface CommandPaletteLabels {
|
|
|
157
177
|
readonly loading: string;
|
|
158
178
|
readonly recent: string;
|
|
159
179
|
readonly pinned: string;
|
|
180
|
+
/** Section of the commands built from the routes (see the `routes` option). */
|
|
181
|
+
readonly routesGroup: string;
|
|
182
|
+
/** Accessible name of the row of prefix hints (see `showPrefixHints`). */
|
|
183
|
+
readonly prefixHints: string;
|
|
184
|
+
/** Hint name of a prefix with `kind: 'action'` and no `label` or `groups`. */
|
|
185
|
+
readonly prefixActions: string;
|
|
186
|
+
/** Hint name of a prefix with `kind: 'route'` and no `label` or `groups`. */
|
|
187
|
+
readonly prefixPages: string;
|
|
160
188
|
/** Announced when a command asks for a value. `{name}` is the command label. */
|
|
161
189
|
readonly prompt: string;
|
|
162
190
|
readonly defaultGroup: string;
|
|
@@ -190,6 +218,11 @@ interface CommandPrefix {
|
|
|
190
218
|
readonly groups?: readonly string[];
|
|
191
219
|
/** Only route commands or only commands that run a function. */
|
|
192
220
|
readonly kind?: 'route' | 'action';
|
|
221
|
+
/**
|
|
222
|
+
* Name shown in the prefix hints (see `showPrefixHints`). Default: the `groups` joined by a comma,
|
|
223
|
+
* else `labels.prefixActions` or `labels.prefixPages` for a `kind`, else only the prefix.
|
|
224
|
+
*/
|
|
225
|
+
readonly label?: string;
|
|
193
226
|
}
|
|
194
227
|
interface CommandPaletteRecentOptions {
|
|
195
228
|
/** Max number of recents shown. Default: 5. */
|
|
@@ -268,6 +301,12 @@ interface CommandPaletteConfig {
|
|
|
268
301
|
readonly sectionOrder: readonly string[];
|
|
269
302
|
/** `auto` follows `prefers-color-scheme`. Default: `auto`. */
|
|
270
303
|
readonly theme: CommandPaletteTheme;
|
|
304
|
+
/**
|
|
305
|
+
* Builds a navigation command for every route of the router configuration (`true` for the
|
|
306
|
+
* defaults, or an options object). Commands registered by hand win over generated ones with the
|
|
307
|
+
* same id or route. Routes are read each time the palette opens. Default: `false`.
|
|
308
|
+
*/
|
|
309
|
+
readonly routes: boolean | CommandPaletteRoutesOptions;
|
|
271
310
|
/** "Recent" section shown with an empty query; `false` disables it. */
|
|
272
311
|
readonly recent: CommandPaletteRecentOptions | false;
|
|
273
312
|
/** Debounce for async providers, in ms. Default: 200. */
|
|
@@ -289,6 +328,12 @@ interface CommandPaletteConfig {
|
|
|
289
328
|
* groups keep their accessible name. Default: `true`.
|
|
290
329
|
*/
|
|
291
330
|
readonly showSectionLabels: boolean;
|
|
331
|
+
/**
|
|
332
|
+
* Shows a row at the bottom with the search modes of `prefixes` (for example `>` Actions, `@`
|
|
333
|
+
* Customers). Selecting one types its prefix; selecting the active one removes it. Hidden inside
|
|
334
|
+
* a sub-palette and while a command asks for a value, and when there are no prefixes. Default: `false`.
|
|
335
|
+
*/
|
|
336
|
+
readonly showPrefixHints: boolean;
|
|
292
337
|
/** Shows the close key hint (`labels.closeHint`, Esc) in the search field. Default: `true`. */
|
|
293
338
|
readonly showCloseHint: boolean;
|
|
294
339
|
/** Highlights the characters matched by the search. Default: `true`. */
|
|
@@ -324,12 +369,15 @@ export declare class CommandPaletteService {
|
|
|
324
369
|
private readonly config;
|
|
325
370
|
private readonly router;
|
|
326
371
|
private readonly document;
|
|
372
|
+
private readonly injector;
|
|
327
373
|
/** The texts in use (see the `labels` option); follows a function or signal given there. */
|
|
328
374
|
readonly labels: Signal<import("@rrstudioapps/ngx-command-palette").CommandPaletteLabels>;
|
|
329
375
|
private readonly recentStore;
|
|
330
376
|
private readonly _isOpen;
|
|
331
377
|
private readonly _query;
|
|
332
378
|
private readonly registrations;
|
|
379
|
+
/** Commands built from the router configuration (`routes` option), refreshed on every open. */
|
|
380
|
+
private readonly routeSource;
|
|
333
381
|
private readonly providers;
|
|
334
382
|
private readonly providerState;
|
|
335
383
|
/** Recents on: not `recent: false` and `recent.enabled` (boolean, function or signal) not false. */
|
|
@@ -369,6 +417,8 @@ export declare class CommandPaletteService {
|
|
|
369
417
|
runHotkey(event: KeyboardEvent, apple: boolean): boolean;
|
|
370
418
|
/** Opens the palette, optionally with an initial query. */
|
|
371
419
|
open(query?: string): void;
|
|
420
|
+
/** Rebuilds the commands of the `routes` option from the current router configuration. */
|
|
421
|
+
private refreshRoutes;
|
|
372
422
|
/** Closes the palette, cancels pending searches and restores the focus. */
|
|
373
423
|
close(): void;
|
|
374
424
|
/** Gives the focus back as the `restoreFocus` option says. */
|
|
@@ -495,6 +545,17 @@ export declare class CommandPaletteComponent {
|
|
|
495
545
|
protected hasChildren(command: Command): boolean;
|
|
496
546
|
protected onBack(levels: number): void;
|
|
497
547
|
protected isTemplate(icon: unknown): icon is TemplateRef<unknown>;
|
|
548
|
+
/** Search modes shown in the footer (`showPrefixHints`): none in a sub-palette or a value step. */
|
|
549
|
+
protected readonly prefixHints: import("@angular/core").Signal<{
|
|
550
|
+
prefix: string;
|
|
551
|
+
label: string;
|
|
552
|
+
active: boolean;
|
|
553
|
+
}[]>;
|
|
554
|
+
/** Types the prefix of a hint in front of the search text, or removes it when it is the active one. */
|
|
555
|
+
protected onPrefixHint(hint: {
|
|
556
|
+
prefix: string;
|
|
557
|
+
active: boolean;
|
|
558
|
+
}): void;
|
|
498
559
|
protected onInput(event: Event): void;
|
|
499
560
|
protected onKeydown(event: KeyboardEvent): void;
|
|
500
561
|
protected onPointerMove(item: CommandResult): void;
|
|
@@ -533,4 +594,4 @@ type KeyEventLike = Pick<KeyboardEvent, 'key' | 'code' | 'ctrlKey' | 'metaKey' |
|
|
|
533
594
|
export declare function matchesShortcut(event: KeyEventLike, shortcut: ParsedShortcut, apple: boolean): boolean;
|
|
534
595
|
/** Human readable label, e.g. `⌘K` on macOS and `Ctrl+K` elsewhere. */
|
|
535
596
|
export declare function formatShortcut(shortcut: ParsedShortcut, apple: boolean): string;
|
|
536
|
-
export type { ActionCommand, Command, CommandEmptyContext, CommandFilter, CommandItemContext, CommandPaletteCloseReason, CommandPaletteConfig, CommandPaletteLabels, CommandPaletteOptions, CommandPalettePosition, CommandPaletteRecentOptions, CommandPaletteTheme, CommandPrefix, CommandProvider, CommandResult, CommandRunContext, CommandSection, CommandSubscribable, FuzzyMatch, HighlightSegment, ParentCommand, ParsedShortcut, RecentStorage, RouteCommand };
|
|
597
|
+
export type { ActionCommand, Command, CommandEmptyContext, CommandFilter, CommandItemContext, CommandPaletteCloseReason, CommandPaletteConfig, CommandPaletteLabels, CommandPaletteOptions, CommandPalettePosition, CommandPaletteRecentOptions, CommandPaletteRouteInfo, CommandPaletteRoutesOptions, CommandPaletteTheme, CommandPrefix, CommandProvider, CommandResult, CommandRunContext, CommandSection, CommandSubscribable, FuzzyMatch, HighlightSegment, ParentCommand, ParsedShortcut, RecentStorage, RouteCommand };
|