import { useEffect, useState } from 'react'; import { Viewer, DocumentGate, usePageList } from '@embedpdf/react/runtime'; import type { OpenInput } from '@embedpdf/react/runtime'; import { Stage, stagePlugin } from '@embedpdf/react/stage'; import { RenderLayer, renderPlugin } from '@embedpdf/react/render'; import { interactionPlugin } from '@embedpdf/react/interaction'; import { SelectionClipboard, SelectionLayer, copySelection, selectionPlugin, useSelection, useSelectionState, } from '@embedpdf/react/selection'; import { cloudEngine } from '@cloudpdf/engine'; import './copy.css'; const engine = cloudEngine(); const plugins = [stagePlugin(), renderPlugin(), interactionPlugin(), selectionPlugin()]; const welcome: OpenInput = { kind: 'grant', grant: 'shr_gvpJcG1ULUMon19C0D1wODSY' }; function CopyButton() { const selection = useSelection(); const hasSelection = useSelectionState((state) => state.hasSelection); const [status, setStatus] = useState(''); const copy = () => { copySelection(selection).then( (text) => setStatus(`Copied ${text.length} characters`), // The browser can refuse the clipboard, for example in a frame that doesn't allow it. () => setStatus("The browser didn't allow copying"), ); }; return (
{text || 'Select some text to read it here.'}
; } // Something selected on load: "Documents", the first word on the cover. function SelectTitle() { const selection = useSelection(); const cover = usePageList()[0]?.ref; useEffect(() => { if (cover) selection.select({ page: cover, start: 36, count: 9 }); }, [selection, cover]); return null; } export default function App() { return (