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, SelectionMenu, copySelection, selectionPlugin, useSelection, } from '@embedpdf/react/selection'; import { localEngine } from '@embedpdf/engine'; import './menu.css'; const engine = localEngine(); const plugins = [stagePlugin(), renderPlugin(), interactionPlugin(), selectionPlugin()]; const PLACEMENTS = ['top', 'bottom', 'left', 'right'] as const; type Placement = (typeof PLACEMENTS)[number]; // [!doc-source welcome] const welcome = async (): Promise => { const response = await fetch('https://www.embedpdf.com/pdfs/welcome.pdf'); return { kind: 'bytes', id: 'welcome', bytes: new Uint8Array(await response.arrayBuffer()) }; }; // [!/doc-source] // What's in the menu is yours: here, copy and clear. function SelectionActions() { const selection = useSelection(); const copy = () => { void copySelection(selection).catch(() => { // Show your product's clipboard error message here. }); }; return (
{selection.canCopy() && ( )}
); } // Something selected on load, so the menu shows: "Documents", the first word on the cover. function SelectTitle() { const selection = useSelection(); const cover = usePageList()[0]?.ref; useEffect(() => { // [!doc-range welcome firstWord] if (cover) selection.select({ page: cover, start: 28, count: 9 }); // [!/doc-range] }, [selection, cover]); return null; } export default function App() { const [placement, setPlacement] = useState('top'); return ( Loading…

}>
{PLACEMENTS.map((name) => ( ))}
} > {() => ( <> )}
); }