import { useEffect, useRef } from 'react'; import { Viewer, DocumentGate } 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 { interactionPlugin, useInteraction, useInteractionState, } from '@embedpdf/react/interaction'; import { SelectionLayer, selectionPlugin } from '@embedpdf/react/selection'; import { AnnotationLayer, annotationPlugin, useAnnotationState } from '@embedpdf/react/annotation'; import { redactionPlugin, useRedaction, useRedactionState } from '@embedpdf/react/redaction'; import { cloudEngine } from '@cloudpdf/engine'; import './basic.css'; const engine = cloudEngine(); // The selection plugin lets the redact tool mark the text you select. const plugins = [ stagePlugin(), renderPlugin(), interactionPlugin(), selectionPlugin(), annotationPlugin(), redactionPlugin(), ]; const welcome: OpenInput = { kind: 'grant', grant: 'shr_gvpJcG1ULUMon19C0D1wODSY' }; // The cover's subtitle, in page coordinates. const SUBTITLE = { x: 44, y: 318, width: 206, height: 50 }; function RedactBar() { const interaction = useInteraction(); const { activeToolId } = useInteractionState(); const stage = useStage(); const redaction = useRedaction(); const { pendingCount, applying } = useRedactionState(); const ready = useAnnotationState((state) => state.status === 'ready'); const started = useRef(false); // On load: the cover's subtitle marked, and the redact tool on. useEffect(() => { if (!ready || started.current) return; started.current = true; void redaction.markArea(0, SUBTITLE).then(() => stage.reveal(0, { rect: SUBTITLE })); interaction.activateTool('redact'); }, [redaction, interaction, stage, ready]); const marking = activeToolId === 'redact'; return (
{marking ? 'Select text, or drag over an area' : 'Click a mark to move it'}
); } export default function App() { return ( Loading…

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