import { ChangeDetectionStrategy, Component, computed, inject, input, signal, 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 { EpdfSelectionLayer, withSelection } from '@embedpdf/angular/selection'; import { withInteraction } from '@embedpdf/angular/interaction'; import { annotationKey, EpdfAnnotation, EpdfAnnotationLayer, EpdfComments, withAnnotation, type CommentThreadView, } from '@embedpdf/angular/annotation'; import { cloudEngine } from '@cloudpdf/engine'; const proposal: OpenInput = { kind: 'grant', grant: 'shr_qnqHtCNRpzz-s7DPFBIbuOAF' }; // One thread: the first comment, its replies, a reply box, and a button that shows it. @Component({ selector: 'article[demoThread]', changeDetection: ChangeDetectionStrategy.OnPush, host: { class: 'thread' }, template: `
Page {{ thread().pageLabel }}

{{ thread().root.author }} {{ thread().root.contents }}

@for (reply of thread().replies; track key(reply.ref)) {

{{ reply.author }} {{ reply.contents }}

} @if (comments.canReply(thread().root.ref)) {
} `, }) export class Thread { readonly thread = input.required(); readonly stage = input.required(); protected readonly comments = inject(EpdfComments); private readonly annotation = inject(EpdfAnnotation); protected readonly text = signal(''); protected readonly key = annotationKey; protected show() { const { page, root } = this.thread(); this.stage().reveal(page, { rect: root.rect }); this.annotation.selection.select([root.ref]); // and select it } protected reply() { const text = this.text().trim(); if (!text) return; void this.comments.reply(this.thread().root.ref, text); this.text.set(''); } } /** * Every thread in the document, in reading order. Next to ``: * `
`. */ @Component({ selector: 'div[demoComments]', imports: [Thread], changeDetection: ChangeDetectionStrategy.OnPush, host: { class: 'panel threads' }, template: ` @if (loading()) {

Loading comments…

} @else if (comments.threads().length === 0) {

No comments

} @for (thread of comments.threads(); track key(thread.root.ref)) {
} `, }) export class Comments { readonly stage = input.required(); protected readonly comments = inject(EpdfComments); private readonly annotation = inject(EpdfAnnotation); protected readonly loading = computed(() => this.annotation.status() === 'loading'); protected readonly key = annotationKey; } @Component({ selector: 'demo-root', imports: [ EpdfDocumentGate, EpdfStage, EpdfPageTemplate, EpdfRenderLayer, EpdfSelectionLayer, EpdfAnnotationLayer, Comments, ], providers: [ provideEmbedPdf( { engine: () => cloudEngine(), identity: { userId: 'u_381', displayName: 'Dana Smith' }, initialDocuments: [{ source: proposal }], }, withStage(), withRender(), withInteraction(), withSelection(), withAnnotation(), ), ], changeDetection: ChangeDetectionStrategy.OnPush, styleUrl: './comments.css', encapsulation: ViewEncapsulation.None, template: `

Loading…

`, }) export class App {}