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,
formPlugin,
toFieldRef,
useForm,
useFormEvent,
useFormState,
useFormValue,
} from '@embedpdf/react/form';
import type { FormField } from '@embedpdf/react/form';
import { cloudEngine } from '@cloudpdf/engine';
import './read.css';
const engine = cloudEngine();
const plugins = [stagePlugin(), renderPlugin(), interactionPlugin(), formPlugin()];
const forms: OpenInput = { kind: 'grant', grant: 'shr_eBRW5E3MpolzD8G36Alp30EF' };
/** On load: a name filled in. */
function useFilledInName() {
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.setValue(toFieldRef('name'), { value: 'Ada Lovelace' });
}, [form, status]);
}
/** A field's value as text, whatever its kind. */
function valueText(field: FormField): string {
switch (field.kind) {
case 'text':
case 'combobox':
return field.value || '—';
case 'checkbox':
return field.checked ? 'checked' : 'not checked';
case 'radio':
return field.value === 'Off' ? '—' : field.value;
case 'listbox':
return field.selectedValues.join(', ') || '—';
default:
return '';
}
}
function Greeting() {
useFilledInName();
const name = useFormValue(toFieldRef('name'));
const [changed, setChanged] = useState
{fields.map((field) => (
);
}
export default function App() {
return (