pdfme / pdfme

A TypeScript based PDF generator library, made with React.
https://pdfme.com
MIT License
2.16k stars 192 forks source link

Multi-var text plugin (V4) #466

Closed peteward closed 1 month ago

peteward commented 1 month ago

This plugin is functionally ready for review. The behaviour is shown below:

https://github.com/pdfme/pdfme/assets/7068515/84d5164e-da7b-47e6-be99-15006aba58bd

The idea is to store the variables as a JSON string in content and the typed input as text.

This plugin will allow n variables to be added to a single text field, where n can be >= 0 (so this will also achieve a read-only schema). These variables are automatically detected as you type, and done so in an optimally efficient way that is usable even with dynamic font sizing enabled, as shown in the video above.

This plugin does not support the Form mode. Some thought would be needed as to the UI but it would be doable if people were interested. It would probably need an overlay.

TODO:

vercel[bot] commented 1 month ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

2 Ignored Deployments | Name | Status | Preview | Updated (UTC) | | :--- | :----- | :------ | :------ | | **pdfme-playground** | ⬜️ Ignored ([Inspect](https://vercel.com/labelmake/pdfme-playground/4XMe57uo4K6wLM2XKVMa68RHoWJ5)) | | Mar 31, 2024 8:26am | | **pdfme-playground-v4** | ⬜️ Ignored ([Inspect](https://vercel.com/labelmake/pdfme-playground-v4/Gtu1uhtzBMZf26nWS2jc44LrkLwE)) | | Mar 31, 2024 8:26am |
peteward commented 1 month ago

Hi @hand-dot,

Just looking at the Form UI for this plugin.

There are 2 options.

1). Add an overlay for filling in the variables that becomes visible when you select the schema, similar to the prop panel:

Screenshot 2024-04-11 at 08 33 47

This approach would be easier to implement and it would likely require minimal or no modifications to the existing text plugin. However, the UX isn't ideal.

2). Create content-editable sections for all of the variables within the schema:

https://github.com/pdfme/pdfme/assets/7068515/b6ee5412-262a-4c3e-8e7f-5880e1a2a089

This feels like better UX, but it will either require significant duplication of the existing text plugin or refactoring the existing text plugin into smaller functions so that aspects of it can be reused. There will be complexity here as typing within each field will need to consider dynamic font sizing of the overall text area.

It is achievable, but let me know what you think and if you think I should continue the work.

hand-dot commented 1 month ago

@peteward


peteward commented 1 month ago

Hi @hand-dot,

Thanks for the feedback!

I have a deadline for the end of this week, but once I am passed this I can continue with this implementation.

I agree that the additional outline in form mode is not ideal - this was just a quick visual proof of concept. I will think how we can make it better.

Page breaking is an interesting challenge. Let's consider this extension once the main implementation has been done. I can see more use-cases for this with the existing text schema, so hopefully we can find a solution that works for both schema types.