import { BehaviorSubject, Observable } from 'rxjs'; import { EditableDesignSystemPrefix } from '../design-system/editable-elements'; import { ShortcutBlockedMessage } from './shortcut-events'; /** * A type which represents the disabled status and tooltip of an item * @public * */ export type ShortcutExecutionStatus = { disabled?: boolean; tooltip?: string; }; export type ShortcutDesignSystemPrefix = EditableDesignSystemPrefix; export type ShortcutEditableContextConfig = { /** * Which design systems should be considered when detecting editable custom elements. * @default ['rapid'] */ designSystems?: ShortcutDesignSystemPrefix[]; /** * Optional app-specific selectors for editable host elements. * @default [] */ customEditableSelectors?: string[]; }; export type ShortcutBlockedMessageConfig = { defaultMessage?: ShortcutBlockedMessage; inputMessage?: ShortcutBlockedMessage; pausedMessage?: ShortcutBlockedMessage; elementFocusMessage?: ShortcutBlockedMessage; emitPausedBlockedEvent?: boolean; }; /** * A definition of a keyboard shortcut * @public */ export interface ShortcutDefinition { id: string; key: string; ctrlKey?: boolean; altKey?: boolean; optionKey?: boolean; shiftKey?: boolean; metaKey?: boolean; description: string; action: () => void; context: string; priority?: number; elementRef?: HTMLElement; canExecute?: () => ShortcutExecutionStatus; /** * Optional per-shortcut blocked message override. * Set to '' to emit blocked events with an empty message. */ blockedMessage?: ShortcutBlockedMessage; /** * Controls whether blocked shortcut events should be emitted for this shortcut. * @default true */ emitBlockedEvent?: boolean; } /** * A result of registering a keyboard shortcut * @public */ export interface ShortcutRegistrationResult { shortcut: ShortcutDefinition; id: string; keyCombination: string; keyCombinationDisplay: string; disabled: () => boolean; tooltip: () => string | undefined; } /** * Interface of a manager for keyboard shortcuts * @public */ export interface ShortcutManager { registerShortcuts(shortcuts: ShortcutDefinition[]): void; registerShortcut(shortcut: ShortcutDefinition): ShortcutRegistrationResult; unregisterShortcut(context: string, id: string): void; unregisterShortcutsByContext(context: string): void; /** * Execute a shortcut by its id * @param id - The id of the shortcut to execute * @remarks This method will execute the shortcut in the active context */ executeShortcut(id: string, eventTarget?: EventTarget | null): void; /** * Execute a shortcut by its id and context * @param context - The context of the shortcut to execute * @param id - The id of the shortcut to execute */ executeShortcutByContext(context: string, id: string, eventTarget?: EventTarget | null): void; getShortcuts(): ShortcutDefinition[]; getShortcutsByContext(context: string): ShortcutDefinition[]; getContexts(): string[]; getShortcutsByContextMap(): Map>; registerContext(context: string): void; setActiveContext(context: string): void; getActiveContext(): string | undefined; clearActiveContext(): void; findShortcutByKeyCombination(key: string, ctrlKey?: boolean, altKey?: boolean, shiftKey?: boolean, metaKey?: boolean): ShortcutDefinition | undefined; pause(): void; resume(): void; isPaused: boolean; isPaused$: Observable; isPausedSubject: BehaviorSubject; /** * Register a global execution guard. * @remarks Guards are evaluated before shortcut-specific canExecute checks. */ registerExecutionGuard(id: string, guard: () => ShortcutExecutionStatus | boolean): void; unregisterExecutionGuard(id: string): void; clearExecutionGuards(): void; /** * Configure editable-context detection used by shortcut listeners. * @remarks This is intended to be set once during app startup. */ configureEditableContext(config?: ShortcutEditableContextConfig): void; getEditableContextConfig(): Required; getEditableSelector(): string; configureBlockedMessages(config?: ShortcutBlockedMessageConfig): void; getBlockedMessages(): Required; } /** * Default implementation of the ShortcutManager interface * @public */ export declare class DefaultShortcutManager implements ShortcutManager { private shortcuts; private shortcutLookup; private keyCombinationMap; private _isPausedSubject; private _activeContext; private executionGuards; private editableContextConfig; private editableSelector; private blockedMessageConfig; get isPaused(): boolean; get isPaused$(): Observable; get isPausedSubject(): BehaviorSubject; registerShortcuts(shortcuts: ShortcutDefinition[]): void; registerShortcut(shortcut: ShortcutDefinition): ShortcutRegistrationResult; unregisterShortcut(context: string, id: string): void; unregisterShortcutsByContext(context: string): void; executeShortcut(id: string, eventTarget?: EventTarget | null): void; private shouldEmitBlockedEvent; private resolveBlockedMessage; executeShortcutByContext(context: string, id: string, eventTarget?: EventTarget | null): void; getShortcuts(): ShortcutDefinition[]; getShortcutsByContext(context: string): ShortcutDefinition[]; findShortcutByKeyCombination(key: string, ctrlKey?: boolean, altKey?: boolean, shiftKey?: boolean, metaKey?: boolean): ShortcutDefinition | undefined; getContexts(): string[]; getShortcutsByContextMap(): Map>; registerContext(context: string): void; setActiveContext(context: string): void; getActiveContext(): string | undefined; clearActiveContext(): void; registerExecutionGuard(id: string, guard: () => ShortcutExecutionStatus | boolean): void; unregisterExecutionGuard(id: string): void; clearExecutionGuards(): void; configureEditableContext(config?: ShortcutEditableContextConfig): void; getEditableContextConfig(): Required; getEditableSelector(): string; configureBlockedMessages(config?: ShortcutBlockedMessageConfig): void; getBlockedMessages(): Required; pause(): void; resume(): void; /** * Normalizes a shortcut definition to handle option/alt equivalence * If optionKey is set, altKey will also be set to true (and vice versa) */ private normalizeShortcutDefinition; private createKeyCombinationKey; private isElementFocused; private getExecutionStatus; private getExecutionGuardStatus; private refreshEditableSelector; } /** * A dependency injection token for the ShortcutManager interface. * @public */ export declare const ShortcutManager: import("@microsoft/fast-foundation").InterfaceSymbol; //# sourceMappingURL=shortcut-manager.d.ts.map