11/*!
22 *
3- * jsPDF AutoTable plugin v3.7.1
3+ * jsPDF AutoTable plugin v3.8.0
44 *
55 * Copyright (c) 2023 Simon Bengtsson, https://github.com/simonbengtsson/jsPDF-AutoTable
66 * Licensed under the MIT License.
@@ -933,7 +933,7 @@ function parseHooks(global, document, current) {
933933 return result ;
934934}
935935function parseSettings ( doc , options ) {
936- var _a , _b , _c , _d , _e , _f , _g , _h , _j , _k , _l ;
936+ var _a , _b , _c , _d , _e , _f , _g , _h , _j , _k , _l , _m ;
937937 var margin = ( 0 , common_1 . parseSpacing ) ( options . margin , 40 / doc . scaleFactor ( ) ) ;
938938 var startY = ( _a = getStartY ( doc , options . startY ) ) !== null && _a !== void 0 ? _a : margin . top ;
939939 var showFoot ;
@@ -958,9 +958,7 @@ function parseSettings(doc, options) {
958958 }
959959 var useCss = ( _d = options . useCss ) !== null && _d !== void 0 ? _d : false ;
960960 var theme = options . theme || ( useCss ? 'plain' : 'striped' ) ;
961- var horizontalPageBreak = options . horizontalPageBreak
962- ? true
963- : false ;
961+ var horizontalPageBreak = ! ! options . horizontalPageBreak ;
964962 var horizontalPageBreakRepeat = ( _e = options . horizontalPageBreakRepeat ) !== null && _e !== void 0 ? _e : null ;
965963 return {
966964 includeHiddenHtml : ( _f = options . includeHiddenHtml ) !== null && _f !== void 0 ? _f : false ,
@@ -977,6 +975,7 @@ function parseSettings(doc, options) {
977975 tableLineColor : ( _l = options . tableLineColor ) !== null && _l !== void 0 ? _l : 200 ,
978976 horizontalPageBreak : horizontalPageBreak ,
979977 horizontalPageBreakRepeat : horizontalPageBreakRepeat ,
978+ horizontalPageBreakBehaviour : ( _m = options . horizontalPageBreakBehaviour ) !== null && _m !== void 0 ? _m : 'afterAllRows' ,
980979 } ;
981980}
982981function getStartY ( doc , userStartY ) {
@@ -1681,20 +1680,55 @@ exports.drawTable = drawTable;
16811680function printTableWithHorizontalPageBreak ( doc , table , startPos , cursor ) {
16821681 // calculate width of columns and render only those which can fit into page
16831682 var allColumnsCanFitResult = ( 0 , tablePrinter_1 . calculateAllColumnsCanFitInPage ) ( doc , table ) ;
1684- allColumnsCanFitResult . map ( function ( colsAndIndexes , index ) {
1685- doc . applyStyles ( doc . userStyles ) ;
1686- // add page to print next columns in new page
1687- if ( index > 0 ) {
1688- addPage ( doc , table , startPos , cursor , colsAndIndexes . columns ) ;
1689- }
1690- else {
1691- // print head for selected columns
1692- printHead ( doc , table , cursor , colsAndIndexes . columns ) ;
1683+ var settings = table . settings ;
1684+ if ( settings . horizontalPageBreakBehaviour === 'afterAllRows' ) {
1685+ allColumnsCanFitResult . forEach ( function ( colsAndIndexes , index ) {
1686+ doc . applyStyles ( doc . userStyles ) ;
1687+ // add page to print next columns in new page
1688+ if ( index > 0 ) {
1689+ addPage ( doc , table , startPos , cursor , colsAndIndexes . columns ) ;
1690+ }
1691+ else {
1692+ // print head for selected columns
1693+ printHead ( doc , table , cursor , colsAndIndexes . columns ) ;
1694+ }
1695+ // print body & footer for selected columns
1696+ printBody ( doc , table , startPos , cursor , colsAndIndexes . columns ) ;
1697+ printFoot ( doc , table , cursor , colsAndIndexes . columns ) ;
1698+ } ) ;
1699+ }
1700+ else {
1701+ var lastRowIndexOfLastPage_1 = - 1 ;
1702+ var firstColumnsToFitResult = allColumnsCanFitResult [ 0 ] ;
1703+ var _loop_1 = function ( ) {
1704+ // Print the first columns, taking note of the last row printed
1705+ var lastPrintedRowIndex = lastRowIndexOfLastPage_1 ;
1706+ if ( firstColumnsToFitResult ) {
1707+ doc . applyStyles ( doc . userStyles ) ;
1708+ if ( lastRowIndexOfLastPage_1 >= 0 ) {
1709+ addPage ( doc , table , startPos , cursor , firstColumnsToFitResult . columns ) ;
1710+ }
1711+ else {
1712+ printHead ( doc , table , cursor , firstColumnsToFitResult . columns ) ;
1713+ }
1714+ lastPrintedRowIndex = printBodyWithoutPageBreaks ( doc , table , lastRowIndexOfLastPage_1 + 1 , cursor , firstColumnsToFitResult . columns ) ;
1715+ printFoot ( doc , table , cursor , firstColumnsToFitResult . columns ) ;
1716+ }
1717+ // Check how many rows were printed, so that the next columns would not print more rows than that
1718+ var maxNumberOfRows = lastPrintedRowIndex - lastRowIndexOfLastPage_1 ;
1719+ // Print the next columns, never exceding maxNumberOfRows
1720+ allColumnsCanFitResult . slice ( 1 ) . forEach ( function ( colsAndIndexes ) {
1721+ doc . applyStyles ( doc . userStyles ) ;
1722+ addPage ( doc , table , startPos , cursor , colsAndIndexes . columns ) ;
1723+ printBodyWithoutPageBreaks ( doc , table , lastRowIndexOfLastPage_1 + 1 , cursor , colsAndIndexes . columns , maxNumberOfRows ) ;
1724+ printFoot ( doc , table , cursor , colsAndIndexes . columns ) ;
1725+ } ) ;
1726+ lastRowIndexOfLastPage_1 = lastPrintedRowIndex ;
1727+ } ;
1728+ while ( lastRowIndexOfLastPage_1 < table . body . length - 1 ) {
1729+ _loop_1 ( ) ;
16931730 }
1694- // print body & footer for selected columns
1695- printBody ( doc , table , startPos , cursor , colsAndIndexes . columns ) ;
1696- printFoot ( doc , table , cursor , colsAndIndexes . columns ) ;
1697- } ) ;
1731+ }
16981732}
16991733function printHead ( doc , table , cursor , columns ) {
17001734 var settings = table . settings ;
@@ -1710,6 +1744,21 @@ function printBody(doc, table, startPos, cursor, columns) {
17101744 printFullRow ( doc , table , row , isLastRow , startPos , cursor , columns ) ;
17111745 } ) ;
17121746}
1747+ function printBodyWithoutPageBreaks ( doc , table , startRowIndex , cursor , columns , maxNumberOfRows ) {
1748+ doc . applyStyles ( doc . userStyles ) ;
1749+ maxNumberOfRows = maxNumberOfRows !== null && maxNumberOfRows !== void 0 ? maxNumberOfRows : table . body . length ;
1750+ var endRowIndex = Math . min ( startRowIndex + maxNumberOfRows , table . body . length ) ;
1751+ var lastPrintedRowIndex = - 1 ;
1752+ table . body . slice ( startRowIndex , endRowIndex ) . forEach ( function ( row , index ) {
1753+ var isLastRow = startRowIndex + index === table . body . length - 1 ;
1754+ var remainingSpace = getRemainingPageSpace ( doc , table , isLastRow , cursor ) ;
1755+ if ( row . canEntireRowFit ( remainingSpace , columns ) ) {
1756+ printRow ( doc , table , row , cursor , columns ) ;
1757+ lastPrintedRowIndex = startRowIndex + index ;
1758+ }
1759+ } ) ;
1760+ return lastPrintedRowIndex ;
1761+ }
17131762function printFoot ( doc , table , cursor , columns ) {
17141763 var settings = table . settings ;
17151764 doc . applyStyles ( doc . userStyles ) ;
@@ -1815,19 +1864,20 @@ function shouldPrintOnCurrentPage(doc, row, remainingPageSpace, table) {
18151864function printFullRow ( doc , table , row , isLastRow , startPos , cursor , columns ) {
18161865 var remainingSpace = getRemainingPageSpace ( doc , table , isLastRow , cursor ) ;
18171866 if ( row . canEntireRowFit ( remainingSpace , columns ) ) {
1867+ // The row fits in the current page
1868+ printRow ( doc , table , row , cursor , columns ) ;
1869+ }
1870+ else if ( shouldPrintOnCurrentPage ( doc , row , remainingSpace , table ) ) {
1871+ // The row gets split in two here, each piece in one page
1872+ var remainderRow = modifyRowToFit ( row , remainingSpace , table , doc ) ;
18181873 printRow ( doc , table , row , cursor , columns ) ;
1874+ addPage ( doc , table , startPos , cursor , columns ) ;
1875+ printFullRow ( doc , table , remainderRow , isLastRow , startPos , cursor , columns ) ;
18191876 }
18201877 else {
1821- if ( shouldPrintOnCurrentPage ( doc , row , remainingSpace , table ) ) {
1822- var remainderRow = modifyRowToFit ( row , remainingSpace , table , doc ) ;
1823- printRow ( doc , table , row , cursor , columns ) ;
1824- addPage ( doc , table , startPos , cursor , columns ) ;
1825- printFullRow ( doc , table , remainderRow , isLastRow , startPos , cursor , columns ) ;
1826- }
1827- else {
1828- addPage ( doc , table , startPos , cursor , columns ) ;
1829- printFullRow ( doc , table , row , isLastRow , startPos , cursor , columns ) ;
1830- }
1878+ // The row get printed entirelly on the next page
1879+ addPage ( doc , table , startPos , cursor , columns ) ;
1880+ printFullRow ( doc , table , row , isLastRow , startPos , cursor , columns ) ;
18311881 }
18321882}
18331883function printRow ( doc , table , row , cursor , columns ) {
0 commit comments