import { useState } from 'react'; import { Viewer, DocumentGate, usePageList } from '@embedpdf/react/runtime'; import type { OpenInput } from '@embedpdf/react/runtime'; import { Stage, stagePlugin, useStage } from '@embedpdf/react/stage'; import { RenderLayer, renderPlugin } from '@embedpdf/react/render'; import { SelectionLayer, selectionPlugin } from '@embedpdf/react/selection'; import { interactionPlugin } from '@embedpdf/react/interaction'; import { AnnotationLayer, annotationPlugin, useAnnotation, useAnnotationList, type AnnotationRef, } from '@embedpdf/react/annotation'; import { cloudEngine } from '@cloudpdf/engine'; import './create-update.css'; const engine = cloudEngine(); const plugins = [ stagePlugin(), renderPlugin(), interactionPlugin(), selectionPlugin(), annotationPlugin(), ]; const report: OpenInput = { kind: 'grant', grant: 'shr__TWhIGdJtaKlcnVgJdg--bcm' }; // Create a rectangle, then change, move and delete it, all from code. function SquareControls() { const annotation = useAnnotation(); const stage = useStage(); const page = usePageList()[1]?.ref; // page 2, which has room at the bottom const [ref, setRef] = useState(null); useAnnotationList(); // re-render as the annotations change, for the reads below const add = async () => { if (!page) return; const { annotation: square } = await annotation.create(page, { subtype: 'square', box: { x: 72, y: 592, width: 200, height: 100 }, color: '#0078ff', strokeWidth: 3, }); setRef(square.ref); stage.reveal(page, { rect: square.rect }); }; const square = ref ? annotation.get(ref) : null; const canUpdate = square !== null && annotation.canUpdate(square.ref); const canDelete = square !== null && annotation.canDelete(square.ref); let status = 'No rectangle'; if (square) status = annotation.isPending(square.ref) ? 'Saving…' : 'Saved'; return (
{status}
); } export default function App() { return ( Loading…

}> {() => ( <> )}
); }