# @embedpdf/angular — ./commands BoundCommand [InterfaceDeclaration] (from packages/plugin/commands/src/contract.ts): export interface BoundCommand extends ResolvedCommand{ readonly run: () => Promise; readonly shortcutLabel: string | null; } COMMANDS_DEFAULTS [VariableDeclaration] (from packages/plugin/commands/src/contract.ts): COMMANDS_DEFAULTS: CommandsSettings ={ commands: [], appState: undefined, disabledCategories: [], disabledCommands: [], notAllowed: 'hide', } CommandContext [InterfaceDeclaration] (from packages/core/main/src/command-types.ts): export interface CommandContext{ readonly documentId: string | null; readonly appState: AppState; readonly args?: unknown; readonly signal?: AbortSignal; get(token: CapabilityToken): T; tryGet(token: CapabilityToken): T | null; } CommandDefinition [InterfaceDeclaration] (from packages/core/main/src/command-types.ts): export interface CommandDefinition{ readonly id: string; readonly label?: string; readonly labelKey?: string; readonly icon?: string; iconAccent?(context: CommandContext): IconAccent | null; readonly shortcut?: string | readonly string[]; readonly shortcutInTextFields?: boolean; readonly categories?: readonly string[]; readonly requires?: readonly Permission[]; allowed?(context: CommandContext): boolean; readonly notAllowedKey?: string; locked?(context: CommandContext): SettingLock | null; readonly menu?: string; readonly panel?: | string |{ readonly id: string; readonly exclusive?: string; readonly focus?: boolean} ; readonly modal?: string; enabled?(context: CommandContext): boolean; active?(context: CommandContext): boolean; visible?(context: CommandContext): boolean; labelParams?(context: CommandContext): Readonly>; run?(context: CommandContext): void | Promise; } CommandExecutedEvent [InterfaceDeclaration] (from packages/plugin/commands/src/contract.ts): export interface CommandExecutedEvent{ readonly commandId: CommandId; readonly documentId: string | null; readonly args: unknown; } CommandExecutionFailedEvent [InterfaceDeclaration] (from packages/plugin/commands/src/contract.ts): export interface CommandExecutionFailedEvent{ readonly commandId: CommandId; readonly documentId: string | null; readonly error: PluginErrorInfo; } CommandFamily [InterfaceDeclaration] (from packages/core/main/src/command-types.ts): export interface CommandFamily{ readonly prefix: string; readonly names: (context: CommandContext) => readonly string[]; readonly command: (name: string) => Omit; } CommandId [TypeAliasDeclaration] (from packages/plugin/commands/src/contract.ts): export type CommandId = string; CommandRefusal [InterfaceDeclaration] (from packages/plugin/commands/src/contract.ts): export interface CommandRefusal{ readonly reason: 'turned-off' | 'not-allowed' | 'locked'; readonly message: string; } CommandsCapability [InterfaceDeclaration] (from packages/plugin/commands/src/contract.ts): export interface CommandsCapability extends SettingsApi{ registerCommand(definition: CommandDefinition, options?: RegisterCommandOptions): Unsubscribe; registerCommands( definitions: readonly CommandDefinition[], options?: RegisterCommandOptions, ): Unsubscribe; hasCommand(id: CommandId): boolean; getCommand(id: CommandId): CommandDefinition | null; listCommandIds(): readonly CommandId[]; resolveCommand(id: CommandId, documentId?: string): ResolvedCommand | null; listCommands(documentId?: string): readonly ResolvedCommand[]; searchCommands(query: string, documentId?: string): readonly ResolvedCommand[]; listShortcuts(): readonly{ readonly commandId: CommandId; readonly shortcut: string} []; execute(id: CommandId, options?: ExecuteOptions): Promise; canExecute(id: CommandId, documentId?: string): boolean; getRefusal(id: CommandId, documentId?: string): CommandRefusal | null; getDisabledCategories(): readonly string[]; isCategoryDisabled(category: string): boolean; disableCategory(category: string): void; enableCategory(category: string): void; setDisabledCategories(categories: readonly string[]): void; getDisabledCommands(): readonly CommandId[]; isCommandDisabled(id: CommandId): boolean; disableCommand(id: CommandId): void; enableCommand(id: CommandId): void; setDisabledCommands(ids: readonly CommandId[]): void; readonly onExecuted: EventHook; readonly onExecutionFailed: EventHook; } CommandsConfig [TypeAliasDeclaration] (from packages/plugin/commands/src/contract.ts): export type CommandsConfig = Omit< DeepPartial, 'commands' | 'appState' > &{ readonly commands?: readonly (CommandDefinition | CommandFamily)[]; readonly appState?: AppState; } ; CommandsSettings [InterfaceDeclaration] (from packages/plugin/commands/src/contract.ts): export interface CommandsSettings{ readonly commands: readonly (CommandDefinition | CommandFamily)[]; readonly appState: unknown; readonly disabledCategories: readonly string[]; readonly disabledCommands: readonly CommandId[]; readonly notAllowed: NotAllowedMode; } CommandsToken [VariableDeclaration] (from packages/plugin/commands/src/token.ts): CommandsToken = createCapabilityToken('commands', { hint: `add commandsPlugin() from '@embedpdf/plugin-commands' to your plugins list`, } ) EpdfCommand [ClassDeclaration] (from packages/framework/angular/commands/src/commands.ts): @Directive({ selector: '[epdfCommand]', exportAs: 'epdfCommand', host:{ '(click)': 'onClick()', '[attr.disabled]': 'enabled() ? null : ""', '[attr.aria-pressed]': 'command().pressable ? active() : null', '[attr.aria-expanded]': 'command().menu ? active() : null', '[attr.title]': 'label() || null', '[hidden]': '!visible()', } , } ) export class EpdfCommand{ readonly id = input.required({ alias: 'epdfCommand'} ); readonly command: Signal = inject(EpdfCommands).commandOf(() => this.id()); readonly label: Signal = computed(() => this.command().label); readonly icon: Signal = computed(() => this.command().icon); readonly shortcutLabel: Signal = computed(() => this.command().shortcutLabel); readonly enabled: Signal = computed(() => this.command().enabled); readonly active: Signal = computed(() => this.command().active); readonly visible: Signal = computed(() => this.command().visible); run(): Promise{ return untracked(this.command).run(); } protected onClick(): void{ this.run().catch(() =>{ } ); } } EpdfCommandShortcuts [ClassDeclaration] (from packages/framework/angular/commands/src/commands.ts): @Directive({ selector: '[epdfCommandShortcuts]'} ) export class EpdfCommandShortcuts{ readonly refused = output(); constructor(){ const element = inject>(ElementRef).nativeElement; const commands = shortcutCommands(injectKernelHost('epdfCommandShortcuts')); if (!isPlatformBrowser(inject(PLATFORM_ID))) return; effect((onCleanup) =>{ const current = commands(); if (!current) return; onCleanup( bindCommandShortcuts(current, { target: element, onRefused: (commandId, refusal) => this.refused.emit({ commandId, refusal} ), } ), ); } ); } } EpdfCommands [ClassDeclaration] (from packages/framework/angular/commands/src/commands.ts): @Injectable({ providedIn: 'root'} ) export class EpdfCommands extends pluginService({ name: 'EpdfCommands', feature: 'withCommands()', token: CommandsToken, methods: [ 'execute', 'canExecute', 'resolveCommand', 'listCommands', 'searchCommands', 'listShortcuts', 'registerCommand', 'registerCommands', 'getCommand', 'hasCommand', 'listCommandIds', 'getDisabledCategories', 'isCategoryDisabled', 'disableCategory', 'enableCategory', 'setDisabledCategories', ], events: ['onExecuted', 'onExecutionFailed'], } ){ commandOf(id: string | (() => string)): Signal{ const idOf = typeof id === 'function' ? id : () => id; const resolved = this.binding.select( (commands) => commands.resolveCommand(idOf()), null, resolvedCommandsEqual, ); const execute = this.binding.method('execute'); return computed(() =>{ const command = resolved(); const requested = idOf(); const commands = this.binding.capability(); if (command === null && commands !== null){ devWarn( `commandOf:${ requested} `, `commandOf(): ${ unknownCommandWarning(requested, commands.listCommandIds())} `, ); } return boundCommandOf(command ?? unregisteredCommand(requested), execute, { isMac: isMacPlatform(), } ); } ); } } ExecuteOptions [InterfaceDeclaration] (from packages/plugin/commands/src/contract.ts): export interface ExecuteOptions extends OperationOptions{ documentId?: string; args?: unknown; } ExecuteResult [TypeAliasDeclaration] (from packages/plugin/commands/src/contract.ts): export type ExecuteResult = |{ readonly status: 'executed'} |{ readonly status: 'rejected'; readonly reason: 'not-found' | 'disabled' | 'hidden'} ; IconAccent [InterfaceDeclaration] (from packages/core/main/src/command-types.ts): export interface IconAccent{ readonly primary?: string; readonly secondary?: string; } NotAllowedMode [TypeAliasDeclaration] (from packages/plugin/commands/src/contract.ts): export type NotAllowedMode = 'hide' | 'disable'; RefusedShortcut [InterfaceDeclaration] (from packages/framework/angular/commands/src/commands.ts): export interface RefusedShortcut{ readonly commandId: CommandId; readonly refusal: CommandRefusal; } RegisterCommandOptions [InterfaceDeclaration] (from packages/plugin/commands/src/contract.ts): export interface RegisterCommandOptions{ replace?: boolean; } ResolvedCommand [InterfaceDeclaration] (from packages/plugin/commands/src/contract.ts): export interface ResolvedCommand{ readonly id: string; readonly label: string; readonly icon?: string; readonly iconAccent?: IconAccent; readonly shortcuts: readonly string[]; readonly menu?: string; readonly enabled: boolean; readonly active: boolean; readonly pressable: boolean; readonly visible: boolean; readonly categories: readonly string[]; readonly disabledReason?: string; } boundCommandOf [FunctionDeclaration] (from packages/plugin/commands/src/contract.ts): export function boundCommandOf( command: ResolvedCommand, execute: (id: CommandId) => Promise, options:{ readonly isMac: boolean} , ): BoundCommand{ const [first] = command.shortcuts; return{ ...command, run: () => execute(command.id), shortcutLabel: first === undefined ? null : formatShortcut(first, { isMac: options.isMac} ), } ; } commandsPlugin [VariableDeclaration] (from packages/plugin/commands/src/commands.plugin.ts): commandsPlugin = (config?: CommandsConfig) => definePlugin({ id: 'commands', scope: 'workspace', token: CommandsToken, optional: [I18nToken, ShellToken], resolvesAnyCapability: true, settings:{ defaults: COMMANDS_DEFAULTS, registered: config as CommandsConfig | undefined, whole: ['appState'], } , create: createCommandsController, inScope: (commands, documentId) => ({ ...commands, resolveCommand: (id, target = documentId) => commands.resolveCommand(id, target), listCommands: (target = documentId) => commands.listCommands(target), searchCommands: (query, target = documentId) => commands.searchCommands(query, target), execute: (id, options) => commands.execute(id, { ...options, documentId: options?.documentId ?? documentId} ), canExecute: (id, target = documentId) => commands.canExecute(id, target), getRefusal: (id, target = documentId) => commands.getRefusal(id, target), } ), } ) formatShortcut [FunctionDeclaration] (from packages/framework/angular/commands/src/commands.ts): export function formatShortcut(shortcut: string, options:{ isMac?: boolean} ={ } ): string{ return formatKeys(shortcut, { isMac: options.isMac ?? isMacPlatform()} ); } resolvedCommandsEqual [VariableDeclaration] (from packages/plugin/commands/src/contract.ts): resolvedCommandsEqual = ( left: ResolvedCommand | null, right: ResolvedCommand | null, ): boolean =>{ if (left === right) return true; if (!left || !right) return false; return ( left.id === right.id && left.label === right.label && left.icon === right.icon && left.iconAccent?.primary === right.iconAccent?.primary && left.iconAccent?.secondary === right.iconAccent?.secondary && left.menu === right.menu && left.enabled === right.enabled && left.active === right.active && left.pressable === right.pressable && left.visible === right.visible && left.disabledReason === right.disabledReason && left.shortcuts.length === right.shortcuts.length && left.shortcuts.every((shortcut, index) => shortcut === right.shortcuts[index]) ); } standardCommands [VariableDeclaration] (from packages/framework/angular/commands/src/standard.ts): standardCommands = join( createStageCommands(), createInteractionCommands(), createSelectionCommands(standardCommandsBrowser), createAnnotationCommands(), createHistoryCommands(), createRenderCommands(standardCommandsBrowser), createDocumentCommands(standardCommandsBrowser), ) unknownCommandWarning [VariableDeclaration] (from packages/plugin/commands/src/contract.ts): unknownCommandWarning = (id: CommandId, known: Iterable): string => `no command "${ id} "${ didYouMean(id, known)} : it shows as neither visible nor enabled` unregisteredCommand [VariableDeclaration] (from packages/plugin/commands/src/contract.ts): unregisteredCommand = (id: CommandId): ResolvedCommand => ({ id, label: id, shortcuts: [], enabled: false, active: false, pressable: false, visible: false, categories: [], } ) withCommandShortcuts [FunctionDeclaration] (from packages/framework/angular/commands/src/commands.ts): export function withCommandShortcuts(options?:{ isMac?: boolean; onRefused?: (commandId: CommandId, refusal: CommandRefusal) => void; } ): EmbedPdfFeature{ return{ plugins: [], setup: () =>{ const commands = shortcutCommands(inject(EpdfKernelHost)); effect((onCleanup) =>{ const current = commands(); if (current){ onCleanup( bindCommandShortcuts(current, { isMac: options?.isMac, onRefused: options?.onRefused, } ), ); } } ); } , } ; } withCommands [FunctionDeclaration] (from packages/framework/angular/commands/src/commands.ts): export function withCommands(options?: CommandsConfig): EmbedPdfFeature{ return{ plugins: [commandsPlugin(options)], services: [EpdfCommands]} ; }