Skip to content

Commit

Permalink
3.5.30
Browse files Browse the repository at this point in the history
  • Loading branch information
simonbengtsson committed Jul 13, 2023
1 parent 1968cfe commit 67f4175
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 12 deletions.
11 changes: 11 additions & 0 deletions dist/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export interface HookProps {
didParseCell: CellHook[];
willDrawCell: CellHook[];
didDrawCell: CellHook[];
willDrawPage: PageHook[];
didDrawPage: PageHook[];
}
export interface Settings {
Expand Down Expand Up @@ -135,6 +136,10 @@ export declare class Table {
x: number;
y: number;
}): void;
callWillDrawPageHooks(doc: DocHandler, cursor: {
x: number;
y: number;
}): void;
getWidth(pageWidth: number): number;
}
export declare class Row {
Expand Down Expand Up @@ -253,9 +258,15 @@ export interface UserOptions {
columnStyles?: {
[key: string]: Partial<Styles>;
};
/** Called when the plugin finished parsing cell content. Can be used to override content or styles for a specific cell. */
didParseCell?: CellHook;
/** Called before a cell or row is drawn. Can be used to call native jspdf styling functions such as `doc.setTextColor` or change position of text etc before it is drawn. */
willDrawCell?: CellHook;
/** Called after a cell has been added to the page. Can be used to draw additional cell content such as images with `doc.addImage`, additional text with `doc.addText` or other jspdf shapes. */
didDrawCell?: CellHook;
/** Called before starting to draw on a page. Can be used to add headers or any other content that you want on each page there is an autotable. */
willDrawPage?: PageHook;
/** Called after the plugin has finished drawing everything on a page. Can be used to add footers with page numbers or any other content that you want on each page there is an autotable. */
didDrawPage?: PageHook;
}
export type ColumnInput = string | number | {
Expand Down
20 changes: 17 additions & 3 deletions dist/jspdf.plugin.autotable.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*!
*
* jsPDF AutoTable plugin v3.5.29
* jsPDF AutoTable plugin v3.5.30
*
* Copyright (c) 2023 Simon Bengtsson, https://github.com/simonbengtsson/jsPDF-AutoTable
* Licensed under the MIT License.
Expand Down Expand Up @@ -864,6 +864,7 @@ function parseHooks(global, document, current) {
didParseCell: [],
willDrawCell: [],
didDrawCell: [],
willDrawPage: [],
didDrawPage: [],
};
for (var _i = 0, allOptions_1 = allOptions; _i < allOptions_1.length; _i++) {
Expand All @@ -874,6 +875,8 @@ function parseHooks(global, document, current) {
result.willDrawCell.push(options.willDrawCell);
if (options.didDrawCell)
result.didDrawCell.push(options.didDrawCell);
if (options.willDrawPage)
result.willDrawPage.push(options.willDrawPage);
if (options.didDrawPage)
result.didDrawPage.push(options.didDrawPage);
}
Expand Down Expand Up @@ -1185,6 +1188,12 @@ var Table = /** @class */ (function () {
handler(new HookData_1.HookData(doc, this, cursor));
}
};
Table.prototype.callWillDrawPageHooks = function (doc, cursor) {
for (var _i = 0, _a = this.hooks.willDrawPage; _i < _a.length; _i++) {
var handler = _a[_i];
handler(new HookData_1.HookData(doc, this, cursor));
}
};
Table.prototype.getWidth = function (pageWidth) {
if (typeof this.settings.tableWidth === 'number') {
return this.settings.tableWidth;
Expand Down Expand Up @@ -1579,7 +1588,7 @@ function drawTable(jsPDFDoc, table) {
var sectionsHeight = table.getHeadHeight(table.columns) + table.getFootHeight(table.columns);
var minTableBottomPos = startY + margin.bottom + sectionsHeight;
if (settings.pageBreak === 'avoid') {
var rows = table.allRows();
var rows = table.body;
var tableHeight = rows.reduce(function (acc, row) { return acc + row.height; }, 0);
minTableBottomPos += tableHeight;
}
Expand All @@ -1589,6 +1598,7 @@ function drawTable(jsPDFDoc, table) {
nextPage(doc);
cursor.y = margin.top;
}
table.callWillDrawPageHooks(doc, cursor);
var startPos = (0, polyfills_1.assign)({}, cursor);
table.startPageNumber = doc.pageNumber();
if (settings.horizontalPageBreak === true) {
Expand Down Expand Up @@ -1927,6 +1937,8 @@ function addPage(doc, table, startPos, cursor, columns) {
cursor.x = margin.left;
cursor.y = margin.top;
startPos.y = margin.top;
// call didAddPage hooks before any content is added to the page
table.callWillDrawPageHooks(doc, cursor);
if (table.settings.showHead === 'everyPage') {
table.head.forEach(function (row) { return printRow(doc, table, row, cursor, columns); });
doc.applyStyles(doc.userStyles);
Expand All @@ -1939,7 +1951,9 @@ function nextPage(doc) {
var newCurrent = doc.pageNumber();
if (newCurrent === current) {
doc.addPage();
return true;
}
return false;
}


Expand Down Expand Up @@ -2083,7 +2097,7 @@ function calculateWidths(doc, table) {
// reduce font size, increase page size or remove custom cell widths
// to allow more columns to be reduced in size
resizeWidth = resizeWidth < 1 ? resizeWidth : Math.round(resizeWidth);
console.error("Of the table content, ".concat(resizeWidth, " units width could not fit page"));
console.warn("Of the table content, ".concat(resizeWidth, " units width could not fit page"));
}
applyColSpans(table);
fitContent(table, doc);
Expand Down
4 changes: 2 additions & 2 deletions dist/jspdf.plugin.autotable.min.js

Large diffs are not rendered by default.

27 changes: 23 additions & 4 deletions dist/jspdf.plugin.autotable.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */
/* global Reflect, Promise */
/* global Reflect, Promise, SuppressedError, Symbol */

var extendStatics = function(d, b) {
extendStatics = Object.setPrototypeOf ||
Expand All @@ -244,7 +244,12 @@ function __spreadArray(to, from, pack) {
}
}
return to.concat(ar || Array.prototype.slice.call(from));
}
}

typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
var e = new Error(message);
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
};

/**
* Ratio between font size and font height. The number comes from jspdf's source code
Expand Down Expand Up @@ -779,6 +784,7 @@ function parseHooks(global, document, current) {
didParseCell: [],
willDrawCell: [],
didDrawCell: [],
willDrawPage: [],
didDrawPage: [],
};
for (var _i = 0, allOptions_1 = allOptions; _i < allOptions_1.length; _i++) {
Expand All @@ -789,6 +795,8 @@ function parseHooks(global, document, current) {
result.willDrawCell.push(options.willDrawCell);
if (options.didDrawCell)
result.didDrawCell.push(options.didDrawCell);
if (options.willDrawPage)
result.willDrawPage.push(options.willDrawPage);
if (options.didDrawPage)
result.didDrawPage.push(options.didDrawPage);
}
Expand Down Expand Up @@ -987,6 +995,12 @@ var Table = /** @class */ (function () {
handler(new HookData(doc, this, cursor));
}
};
Table.prototype.callWillDrawPageHooks = function (doc, cursor) {
for (var _i = 0, _a = this.hooks.willDrawPage; _i < _a.length; _i++) {
var handler = _a[_i];
handler(new HookData(doc, this, cursor));
}
};
Table.prototype.getWidth = function (pageWidth) {
if (typeof this.settings.tableWidth === 'number') {
return this.settings.tableWidth;
Expand Down Expand Up @@ -1240,7 +1254,7 @@ function drawTable(jsPDFDoc, table) {
var sectionsHeight = table.getHeadHeight(table.columns) + table.getFootHeight(table.columns);
var minTableBottomPos = startY + margin.bottom + sectionsHeight;
if (settings.pageBreak === 'avoid') {
var rows = table.allRows();
var rows = table.body;
var tableHeight = rows.reduce(function (acc, row) { return acc + row.height; }, 0);
minTableBottomPos += tableHeight;
}
Expand All @@ -1250,6 +1264,7 @@ function drawTable(jsPDFDoc, table) {
nextPage(doc);
cursor.y = margin.top;
}
table.callWillDrawPageHooks(doc, cursor);
var startPos = assign({}, cursor);
table.startPageNumber = doc.pageNumber();
if (settings.horizontalPageBreak === true) {
Expand Down Expand Up @@ -1587,6 +1602,8 @@ function addPage(doc, table, startPos, cursor, columns) {
cursor.x = margin.left;
cursor.y = margin.top;
startPos.y = margin.top;
// call didAddPage hooks before any content is added to the page
table.callWillDrawPageHooks(doc, cursor);
if (table.settings.showHead === 'everyPage') {
table.head.forEach(function (row) { return printRow(doc, table, row, cursor, columns); });
doc.applyStyles(doc.userStyles);
Expand All @@ -1598,7 +1615,9 @@ function nextPage(doc) {
var newCurrent = doc.pageNumber();
if (newCurrent === current) {
doc.addPage();
return true;
}
return false;
}

/**
Expand Down Expand Up @@ -1641,7 +1660,7 @@ function calculateWidths(doc, table) {
// reduce font size, increase page size or remove custom cell widths
// to allow more columns to be reduced in size
resizeWidth = resizeWidth < 1 ? resizeWidth : Math.round(resizeWidth);
console.error("Of the table content, ".concat(resizeWidth, " units width could not fit page"));
console.warn("Of the table content, ".concat(resizeWidth, " units width could not fit page"));
}
applyColSpans(table);
fitContent(table, doc);
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jspdf-autotable",
"version": "3.5.29",
"version": "3.5.30",
"description": "Generate pdf tables with javascript (jsPDF plugin)",
"main": "dist/jspdf.plugin.autotable.js",
"exports": {
Expand Down

0 comments on commit 67f4175

Please sign in to comment.