import { useEffect } from 'react'; import { Viewer, DocumentGate } 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 { SearchLayer, searchPlugin, useSearch, useSearchHits } from '@embedpdf/react/search'; import { shellPlugin, useShell, useSurface } from '@embedpdf/react/shell'; import { cloudEngine } from '@cloudpdf/engine'; import './props.css'; const engine = cloudEngine(); const plugins = [stagePlugin(), renderPlugin(), searchPlugin(), shellPlugin()]; const welcome: OpenInput = { kind: 'grant', grant: 'shr_gvpJcG1ULUMon19C0D1wODSY' }; // The panel shows the match its props name, and steps to the next one without reopening. function MatchPanel() { const panel = useSurface('match'); const shell = useShell(); const search = useSearch(); const hits = useSearchHits(); const index = typeof panel.props.index === 'number' ? panel.props.index : 0; const hit = hits[index]; if (!panel.isOpen) return null; const show = (next: number) => { shell.updateSurfaceProps('match', { index: next }); search.goToHit(hits[next]); }; return ( ); } function Workspace() { const shell = useShell(); const search = useSearch(); const hits = useSearchHits(); // Every "PDF" on the pages, and the first one open in the panel. useEffect(() => { void search.search({ text: 'PDF' }); shell.open('match', { exclusive: 'right', props: { index: 0 } }); }, [search, shell]); return (
{() => ( <> {/* A click on a match opens it in the panel. */} shell.open('match', { exclusive: 'right', props: { index: hits.indexOf(hit) } }) } /> )}
); } export default function App() { return ( Loading…

}>
); }