import { useEffect, useRef } from 'react'; import { Viewer, DocumentGate, DocumentScope, useDocumentsState } 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 { useViewManager, useViewManagerState, viewManagerPlugin, type PaneInfo, } from '@embedpdf/react/view-manager'; import { localEngine } from '@embedpdf/engine'; import './panes.css'; const engine = localEngine(); const plugins = [stagePlugin(), renderPlugin(), viewManagerPlugin()]; // [!doc-source welcome] const welcome = async (): Promise => { const response = await fetch('https://www.embedpdf.com/pdfs/welcome.pdf'); return { kind: 'bytes', bytes: new Uint8Array(await response.arrayBuffer()) }; }; // [!/doc-source] // [!doc-source article] const article = async (): Promise => { const response = await fetch('https://www.embedpdf.com/pdfs/article.pdf'); return { kind: 'bytes', bytes: new Uint8Array(await response.arrayBuffer()) }; }; // [!/doc-source] function Pane({ pane, canRemove }: { pane: PaneInfo; canRemove: boolean }) { const views = useViewManager(); const focusedPaneId = useViewManagerState((state) => state.focusedPaneId); const { documents } = useDocumentsState(); const nameOf = (id: string) => documents.find((document) => document.id === id)?.name ?? id; return (
views.setFocusedPane(pane.id)} >
{pane.documentIds.map((id) => ( ))}
{pane.activeDocumentId ? ( Opening…

}> {() => }
) : (

No document in this pane.

)}
); } function Panes() { const views = useViewManager(); const { panes } = useViewManagerState(); // On load, both documents land in the first pane: put the second one beside it, once. const splitOnLoad = useRef(true); useEffect(() => { if (splitOnLoad.current && panes.length === 1 && panes[0].documentIds.length === 2) { splitOnLoad.current = false; views.splitPane(panes[0].documentIds[1]); } }, [panes, views]); return (
{panes.map((pane) => ( 1} /> ))}
); } export default function App() { return ( ); }