();
protected readonly command = inject(EpdfCommands).commandOf(() => this.commandId());
protected readonly key = computed(() => formatShortcut(this.shortcut()));
}
// The sheet lists every shortcut, and shows the last command a key ran.
@Component({
selector: 'aside[demoKeyboardHelp]',
imports: [ShortcutRow],
changeDetection: ChangeDetectionStrategy.OnPush,
host: { class: 'sheet' },
template: `
{{ last() ? 'Ran: ' + last() : 'Click the viewer, then press a key, such as → for the next page' }}
@for (row of shortcuts; track row.commandId + ' ' + row.shortcut) {
}
`,
})
export class KeyboardHelp {
private readonly commands = inject(EpdfCommands);
protected readonly shortcuts = this.commands.listShortcuts();
protected readonly last = signal(null);
constructor() {
this.commands.executed$
.pipe(takeUntilDestroyed())
.subscribe(({ commandId }) =>
this.last.set(this.commands.resolveCommand(commandId)?.label ?? commandId),
);
}
}
// The keys work while focus is inside this viewer, so they leave the rest of the page alone. A
// click anywhere in it gives it focus: `tabindex="-1"` makes it a place for keys, not a stop in the
// Tab order.
@Component({
selector: 'demo-root',
imports: [
EpdfDocumentGate,
EpdfStage,
EpdfPageTemplate,
EpdfRenderLayer,
EpdfCommandShortcuts,
KeyboardHelp,
],
providers: [
provideEmbedPdf(
{ engine: () => cloudEngine(), initialDocuments: [{ source: welcome }] },
withStage(),
withRender(),
withInteraction(),
withCommands({ commands: standardCommands }),
),
],
changeDetection: ChangeDetectionStrategy.OnPush,
styleUrl: './shortcuts.css',
encapsulation: ViewEncapsulation.None,
template: `
Loading…
`,
})
export class App {}