import { useEffect, useRef } 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, useInteraction, useInteractionState } from '@embedpdf/react/interaction'; import { AnnotationLayer, annotationPlugin } from '@embedpdf/react/annotation'; import { FormLayer, formPlugin, useForm, useFormState } from '@embedpdf/react/form'; import { cloudEngine } from '@cloudpdf/engine'; import './designer.css'; const engine = cloudEngine(); // Building forms needs the annotation plugin: in design mode, fields are boxes like any annotation. const plugins = [ stagePlugin(), renderPlugin(), interactionPlugin(), annotationPlugin(), formPlugin(), ]; const registration: OpenInput = { kind: 'grant', grant: 'shr_sjOrUrwF2Sf0X5ADfySRG58L' }; const FIELD_TOOLS = [ ['form-text', 'Text'], ['form-checkbox', 'Checkbox'], ['form-radio', 'Radio button'], ['form-combobox', 'Dropdown'], ['form-listbox', 'List'], ['form-signature', 'Signature'], ] as const; /** Start with the text tool picked: the printed form has boxes, but no fields yet. */ function useStartDesigning() { const interaction = useInteraction(); const started = useRef(false); useEffect(() => { if (started.current) return; started.current = true; interaction.activateTool('form-text'); }, [interaction]); } function FieldPalette() { useStartDesigning(); const interaction = useInteraction(); const form = useForm(); const { activeToolId } = useInteractionState(); const { fields } = useFormState(); // The pointer fills the form in; every other tool here designs it. const filling = activeToolId === 'pointer'; if (!form.canDesign()) return
This document’s form can’t be changed.
; return (