import { useEffect, useRef, useState } 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 { interactionPlugin } from '@embedpdf/react/interaction'; import { FormLayer, FormTransfer, formPlugin, useForm, useFormState, type FormBundle, } from '@embedpdf/react/form'; import { cloudEngine } from '@cloudpdf/engine'; import './data.css'; const engine = cloudEngine(); const plugins = [stagePlugin(), renderPlugin(), interactionPlugin(), formPlugin()]; const forms: OpenInput = { kind: 'grant', grant: 'shr_eBRW5E3MpolzD8G36Alp30EF' }; /** On load: the form filled in. */ function useFilledIn() { const form = useForm(); const status = useFormState((state) => state.status); const started = useRef(false); useEffect(() => { if (status !== 'ready' || started.current) return; started.current = true; void form.importValues({ name: 'Ada Lovelace', email: 'ada@example.com', framework: 'Svelte' }); }, [form, status]); } function DataToolbar() { useFilledIn(); const form = useForm(); const [bundle, setBundle] = useState(null); const [result, setResult] = useState(''); return (
{result && {result}}
); } /** The values as plain data, keyed by full name: what you'd send to your backend. */ function Values() { const form = useForm(); // The state changes with every value, so this reads them again each time. useFormState((state) => state.fields); return
{JSON.stringify(form.exportValues(), null, 2)}
; } export default function App() { return ( Loading…

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