feat(builder): add dedicated PDF design mode#110
Open
lattln wants to merge 7 commits into
Open
Conversation
7 tasks
Deploying esheet with
|
| Latest commit: |
b18bfe3
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://6b72f9e8.esheet.pages.dev |
| Branch Preview URL: | https://70-pdf-viewer-add-dedicated.esheet.pages.dev |
- Add @esheet/pdf for generating, importing, enhancing, and round-tripping AcroForm PDFs with eSheet definitions, mappings, metadata, and responses - Add builder PDF canvas with source import, page navigation, field placement, resizing, duplication, deletion, required state, field names, and options - Support adding text, checkbox, radio, and dropdown fields directly on PDFs - Separate PDF authoring in Build from response entry in Preview - Add EsheetRenderer PDF representation with async PDF import, PDF.js canvas overlays, response synchronization, and exportPdf() handle API - Export eSheet responses, labels, required state, dropdown options, and complete radio widget groups back to mapped AcroForm fields - Preserve custom PDF field names and radio option mappings during round-trips - Add renderer PDF demo route with upload and completed-PDF download flow - Expand focused PDF import/export, builder, and renderer test coverage - Wire renderer PDF dependencies and worker-compatible TypeScript configuration
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This branch adds a dedicated PDF workflow to eSheet. It introduces a new
@esheet/pdfpackage for generating fillable AcroForm PDFs from eSheet form definitions, visually editing their layouts in the builder, importing existing PDF forms, completing them throughEsheetRenderer, and exporting completed or enhanced PDFs.The original work adds a standalone builder PDF mode for generating and designing PDFs from eSheet definitions. The current uncommitted work extends that foundation into a broader PDF representation: Build supports authoring and editing PDF-backed forms, while Preview and
EsheetRenderersupport filling imported or generated PDFs using normal eSheet response state.At a high level, this provides a PDF-oriented output and round-trip path alongside the existing build, code, and preview experiences:
EsheetRenderer.What Changed
Added
@esheet/pdfA new pdf library provides generation, import, mapping, and layout-editing utilities.
The package provides:
generatePdf(definition, options)for creating fillable PDFs fromFormDefinitionobjects.importPdf(source)for importing an existingUint8Array,ArrayBuffer, orBlobPDF into an eSheet form session.applyPdfFieldLayout(source, mappings, options)for writing edited AcroForm field rectangles, metadata, and responses back into a PDF.PDF Generation
generatePdfconverts eSheet definitions into fillable AcroForm PDFs and returns deterministicPdfFieldMappingrecords. A mapping connects an eSheet field ID to its PDF field name, AcroForm kind, page number, rectangle, and, where relevant, radio option ID.The generator supports:
textandlongtextas AcroForm text fields.booleanas a checkbox.radio,rating, andslideras radio groups.checkandmultiselectdropdownas checkbox groups.dropdownas an AcroForm dropdown.multitextas one text field per option.display,section, and pages as static PDF content.It also handles:
_sourceData.esheet.pdf.fieldName.PDF Import and Round-Tripping
importPdfimports supported AcroForm controls into an eSheetFormDefinitionand preserves existing PDF values as eSheet response state.Importing a PDF:
PdfFieldMappingrecords for each supported widget.This enables eSheet to begin with an existing PDF template, not just PDFs generated from an eSheet definition.
Dedicated PDF Builder Workflow
The committed branch adds a fourth builder mode,
pdf, alongsidebuild,code, andpreview.The builder header adds a PDF tab and
PdfIcon. Selecting it renders the PDF workflow instead of the normal builder canvas, code editor, or preview layout.The current local work refines this approach: rather than retaining PDF as a separate top-level activity, PDF becomes a representation within the existing Build and Preview workflows:
This preserves the existing builder activity model while making authoring and answer entry distinct.
PDF Designer UI
The PDF designer generates or imports a PDF and renders pages through
pdfjs-dist.It includes:
Interactive Field Layout Editing
PdfCanvasPage.tsx overlays generated or imported mappings above the rendered PDF canvas.
Users can:
Edits are stored as updated
PdfFieldMappingrectangles. Export then applies those mappings to the PDF.Custom PDF Fields
The PDF designer supports editor-added fields on the active page.
Users can add and manage:
The builder supports:
New mappings are tracked separately from generated/imported fields and passed to
applyPdfFieldLayoutso the exported PDF creates the corresponding AcroForm widgets.Applying Layout, Metadata, and Responses
applyPdfFieldLayoutnow updates both mapping geometry and PDF form content.It can:
PDF Representation in
EsheetRendererEsheetRenderernow supports PDF representation in addition to standard eSheet rendering.The renderer props are now a discriminated union:
formDataInput, withrepresentationomitted or set to'esheet'.representation: 'pdf'and requirespdfSource.In PDF representation, the renderer:
initialResponses.FormStore.setResponse.The initial overlay supports:
PDF Export From
EsheetRendererEsheetRendererHandlenow exposes:For imported PDFs, this writes current responses and mappings into the original source PDF. For ordinary eSheet rendering, it generates a PDF from the eSheet definition and applies the resulting mappings before returning PDF bytes.
This creates an end-to-end response flow:
PDF Thumbnails
PdfPageThumbnailrenders PDF.js canvas thumbnails for multi-page documents.The thumbnail rail:
HTML Field Iframe Sizing and Sandboxing
HtmlFieldwas updated so embedded HTML can report its height from inside the sandboxed iframe throughpostMessage.Changes include:
allow-same-origintoallow-scripts.esheet-iframe-heightmessages and adjusts preview height.Demo Application
The demo application now includes a renderer PDF page.
Users can:
EsheetRenderer representation="pdf".exportPdf().This demonstrates the import, fill, and export flow independently from the builder.
Tests Added
PDF tests cover:
Builder tests cover:
Renderer tests cover:
Package and Build Configuration
The branch wires PDF support into the Nx workspace:
@esheet/pdf.scope:pdf.scope:pdfdependency constraints.@esheet/pdf,pdf-lib, andpdfjs-distdependencies where required.@esheet/pdfexternalization.