Skip to content

Commit 4ef937b

Browse files
fix break-2
1 parent fddaabb commit 4ef937b

3 files changed

Lines changed: 35 additions & 14 deletions

File tree

packages/layout/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ats-form-react-pdf-layout",
3-
"version": "4.4.8",
3+
"version": "4.4.9",
44
"license": "MIT",
55
"description": "Resolve document component's layout",
66
"author": "Atharva System",

packages/layout/src/steps/resolvePagination.ts

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,25 @@ const splitNodes = (height: number, contentArea: number, nodes: SafeNode[]) => {
166166
break;
167167
}
168168

169+
// Element fits on a full page but not in remaining space - move to next page to keep together
170+
// This handles the case where wrap is true (default) but we still want to avoid splitting
171+
// if the element would fit entirely on the next page
172+
const remainingSpace = height - nodeTop;
173+
const wouldBarelyFitOnCurrentPage = remainingSpace < nodeHeight * 0.3; // Less than 30% fits
174+
if (
175+
fitsInsidePage &&
176+
shouldSplit &&
177+
wouldBarelyFitOnCurrentPage &&
178+
currentChildren.length > 0
179+
) {
180+
const box = Object.assign({}, child.box, { top: child.box.top - height });
181+
const next = Object.assign({}, child, { box });
182+
183+
currentChildren.push(...futureFixedNodes);
184+
nextChildren.push(next, ...futureNodes);
185+
break;
186+
}
187+
169188
if (shouldBreak) {
170189
const box = Object.assign({}, child.box, { top: child.box.top - height });
171190
const props = Object.assign({}, child.props, {
@@ -182,21 +201,23 @@ const splitNodes = (height: number, contentArea: number, nodes: SafeNode[]) => {
182201
if (shouldSplit || firstBreakableViewChild) {
183202
const [currentChild, nextChild] = split(child, height, contentArea);
184203

185-
// All children are moved to the next page, it doesn't make sense to show the parent on the current page
186-
if (child.children.length > 0 && currentChild.children.length === 0) {
187-
// But if the current page is empty then we can just include the parent on the current page
188-
// if (currentChildren.length === 0) {
189-
// currentChildren.push(child, ...futureFixedNodes);
190-
// nextChildren.push(...futureNodes);
191-
// } else {
192-
const box = Object.assign({}, nextChild.box, {
193-
top: nextChild.box.top - height,
204+
// Check if all non-fixed children are moved to the next page
205+
const currentNonFixedChildren = currentChild.children
206+
? currentChild.children.filter((c) => !isFixed(c))
207+
: [];
208+
const hasNonFixedChildren = child.children
209+
? child.children.filter((c) => !isFixed(c)).length > 0
210+
: false;
211+
212+
// All meaningful children are moved to the next page, move the parent too
213+
if (hasNonFixedChildren && currentNonFixedChildren.length === 0) {
214+
const box = Object.assign({}, child.box, {
215+
top: child.box.top - height,
194216
});
195-
const next = Object.assign({}, nextChild, { box });
217+
const next = Object.assign({}, child, { box });
196218

197219
currentChildren.push(...futureFixedNodes);
198220
nextChildren.push(next, ...futureNodes);
199-
// }
200221
break;
201222
}
202223

packages/renderer/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ats-form-react-pdf-renderer",
3-
"version": "4.3.8",
3+
"version": "4.3.9",
44
"license": "MIT",
55
"description": "Create PDF files on the browser and server",
66
"author": "Atharva System",
@@ -26,7 +26,7 @@
2626
"@babel/runtime": "^7.20.13",
2727
"@react-pdf/fns": "3.1.2",
2828
"@react-pdf/font": "^4.0.3",
29-
"ats-form-react-pdf-layout": "^4.4.8",
29+
"ats-form-react-pdf-layout": "^4.4.9",
3030
"@react-pdf/pdfkit": "^4.0.4",
3131
"@react-pdf/primitives": "^4.1.1",
3232
"@react-pdf/reconciler": "^1.1.4",

0 commit comments

Comments
 (0)