import {
ChangeDetectionStrategy,
Component,
effect,
inject,
signal,
untracked,
ViewEncapsulation,
} from '@angular/core';
import { EpdfDocumentGate, provideEmbedPdf } from '@embedpdf/angular/runtime';
import type { OpenInput } from '@embedpdf/angular/runtime';
import { EpdfPageTemplate, EpdfStage, withStage } from '@embedpdf/angular/stage';
import { EpdfRenderLayer, withRender } from '@embedpdf/angular/render';
import { EpdfSearch, EpdfSearchLayer, withSearch } from '@embedpdf/angular/search';
import { EpdfShell, withShell } from '@embedpdf/angular/shell';
import { cloudEngine } from '@cloudpdf/engine';
const welcome: OpenInput = { kind: 'grant', grant: 'shr_gvpJcG1ULUMon19C0D1wODSY' };
@Component({
selector: 'demo-workspace',
imports: [EpdfStage, EpdfPageTemplate, EpdfRenderLayer, EpdfSearchLayer],
changeDetection: ChangeDetectionStrategy.OnPush,
template: `
@if (searchPanel.isOpen()) {
}
@if (notesPanel.isOpen()) {
}
`,
})
export class Workspace {
private readonly shell = inject(EpdfShell);
protected readonly search = inject(EpdfSearch);
protected readonly searchPanel = this.shell.surface('search');
protected readonly notesPanel = this.shell.surface('notes');
protected readonly text = signal('PDF');
// Your app's own data: it stays when the panel closes.
protected readonly notes = signal('');
constructor() {
effect(() => {
const text = this.text();
untracked(() => void this.search.search({ text }));
});
// The search panel is open when the document is.
this.shell.open('search', { exclusive: 'right' });
}
}
@Component({
selector: 'demo-root',
imports: [EpdfDocumentGate, Workspace],
providers: [
provideEmbedPdf(
{ engine: () => cloudEngine(), initialDocuments: [{ source: welcome }] },
withStage(),
withRender(),
withSearch(),
withShell(),
),
],
changeDetection: ChangeDetectionStrategy.OnPush,
styleUrl: './sidebars.css',
encapsulation: ViewEncapsulation.None,
template: `
Loading…
`,
})
export class App {}