-
-
Notifications
You must be signed in to change notification settings - Fork 626
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[v4-breaking] Propose new exporting API for better ESM & Typescript support #997
Comments
Sounds great! Time for a proper modernization! 🎉 |
I played around with this a bit now in the newly pushed v4 branch and I think I were able to implement everything exactly as your proposal above @mmghv. Great stuff!
|
Remaining is also to change so that autoTable returns a Table instance and remove assignment of jspdf.lastAutotable etc. Something else you have thought of @mmghv? |
Sorry been busy for a while, just need one week to finish a task then I'll test & review the changes along with the list of todos I was planning for v4, I was hopping to take the chance to plan any breaking changes we need to do for other features/fixes/changes to introduce with this major version bump. |
Sounds great. No rush 👍 |
Really looking forward to this as my dev environment broke with one of the last vite updates... |
We currently target ES6 adds support for const/let, classes, arrow functions and more, this results in a cleaner and a little bit smaller code:
But IE11 doesn't fully support ES6: I'm not actually sure if jsPDF or autoTable fully supports IE11, and everyone is dropping support for it. |
Sounds good to me! If there is anyone who still supports IE11 they can always tick with v3. |
Hey @hrueger, you can test v4 right now to verify that it solves the problem you're having with v3. 1- Clone the v4 repo:
2- Edit 3- Link autotable v4 as a global package, inside the repo run:
4- Inside your project, install the linked v4 package:
Now you can test v4 in your project, just remember to import from import { jsPDF } from 'jspdf'
import { autoTable } from 'jspdf-autotable4'
const doc = new jsPDF()
const table = autoTable(doc, {/* options */})
console.log(table.finalY)
doc.save() After you're done testing, unlink the v4 package, Inside your project, run these two commands:
|
Hi @mmghv, |
@hrueger Forgot to add instructions to build the dist files because they were not updated yet, the module system should have worked with you but the return table ( Either re-clone the repo or run |
@mmghv Thanks for the clarification. I actually did not follow your instructions one by one, because I had some trouble with |
@hrueger Great! thanks for taking the time 👍 |
Hi, is there any plan to release an alpha version on v4 soon? |
I believe an alpha release would be beneficial for testing v4 and for early adopters as long as they expect some breaking changing before the stable release. All of the v4 goals have been met, however, there is still significant work to be done in the colspan/rowspan area and possibly @simonbengtsson What are your thoughts? |
I was looking into fixing some of the
autoTable is not defined
issues and improving ESM support, and also typescript issues, It all came down to the hack we do to apply the plugin to the currentjspdf
instance, we are usingrequire()
here to wrap it with a try-catch, this cannot be transpiled toimport
so it causes a problem with rollup in some version of vite/vue/angular and requires setting a flag (vitejs/vite#5759)The solution
I propose we don't apply the plugin to jsPDF, we don't even supply
applyPlugin()
, so there will be nodoc.autoTable*
we just export the functions needed to work on a jspdf doc, currently there'sautoTable(doc, ...)
we make this the only way and export any other function needed likesetDefaults()
, so the proposed API is like this :What makes this a breaking change is instead of default export
import autoTable from 'jspdf-autotable'
we change to named exportsimport { autoTable } from 'jspdf-autotable'
to allow us to export other parts likesetDefault
so we don't need to extend jspdf (doc.autoTable*
) and importing become consistent in all environments, That's actually also whatjspdf
did from v1 to v2 :The benefits
This solves many problems :
require()
hacks, so the source code is pure ESM which makes it much easier to transpile to any format without problems (fixes TypeError: c.autoTable is not a function #860 and many more).jspdf
, you just pass thedoc
created toautoTable
.(doc as any).autoTable
problem (Improve TypeScript Compatibility #994, lastAutoTable not part of index.d.ts #848) because we won't extend jspdf, we just import the correctdoc
type from jspdf and use it, and we have a type for the returned table which can be used to access any info regarding the table likefinalY
so no need fordoc.lastAutotable
The downside
doc.autoTable()
.But we could use this opportunity and remove the deprecated parts and improve the other parts, we can study the other improvements that could be done, if some need API breaking changes we do it so we don't have to do breaking changes again in the future.
@simonbengtsson What do you think? I'm ready to tackle this, if this is going to happen, I think we should create a
v4
branch, do all the work there and merge when we are ready. but first I'll work a bit on the current version, go through the issues, fix what I can and take notes of things need breaking changes to do it in v4.The text was updated successfully, but these errors were encountered: