Skip to content

Commit f231184

Browse files
fix table break to new page
1 parent 30a9232 commit f231184

19 files changed

Lines changed: 46974 additions & 9 deletions

packages/layout/src/node/getWrap.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ const getWrap = (
3131

3232
if (!node.props) return true;
3333

34+
// Check wrap prop first - if explicitly set to false, respect that
35+
// This allows elements to move to the next page instead of splitting
36+
if ('wrap' in node.props && node.props.wrap === false) return false;
37+
3438
if (canCauseBlankSpace(node, prevNode, currentChildren)) return true;
3539

3640
return 'wrap' in node.props ? node.props.wrap : true;

packages/layout/src/node/shouldBreak.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,12 @@ const shouldBreak = (
3737
if ('fixed' in child.props) return false;
3838

3939
const shouldSplit = height < child.box.top + child.box.height;
40-
const canWrap = getWrap(child, child, []);
40+
// Use consistent parameters with splitNodes for wrap calculation
41+
const prevNode =
42+
previousElements.length > 0
43+
? previousElements[previousElements.length - 1]
44+
: undefined;
45+
const canWrap = getWrap(child, prevNode, previousElements);
4146

4247
// Calculate the y coordinate where the desired presence of the child ends
4348
const endOfPresence = getEndOfPresence(child, futureElements);

packages/layout/src/steps/resolvePagination.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ const breakableViewChild = (children, height, path = '', currentChildren) => {
6363
if (
6464
shouldNodeBreak(
6565
children[i],
66-
children.slice(i + 1, height),
66+
children.slice(i + 1),
6767
height,
6868
currentChildren,
6969
)
@@ -136,7 +136,8 @@ const splitNodes = (height: number, contentArea: number, nodes: SafeNode[]) => {
136136
warnUnavailableSpace(child);
137137
break;
138138
} else {
139-
// We don't want to break non wrapable nodes, so we just let them be.
139+
// Element is larger than a page and has wrap=false
140+
// Move to next page and enable wrapping so it can flow across pages
140141
const box = Object.assign({}, child.box, {
141142
top: child.box.top - height,
142143
});
@@ -152,6 +153,21 @@ const splitNodes = (height: number, contentArea: number, nodes: SafeNode[]) => {
152153
}
153154
}
154155

156+
// Element fits on a full page but not in remaining space - move to next page
157+
// This keeps sections together when they can fit on a fresh page
158+
if (fitsInsidePage && shouldSplit && !canWrap) {
159+
const box = Object.assign({}, child.box, { top: child.box.top - height });
160+
const props = Object.assign({}, child.props, {
161+
wrap: true,
162+
break: false,
163+
});
164+
const next = Object.assign({}, child, { box, props });
165+
166+
currentChildren.push(...futureFixedNodes);
167+
nextChildren.push(next, ...futureNodes);
168+
break;
169+
}
170+
155171
if (shouldBreak) {
156172
const box = Object.assign({}, child.box, { top: child.box.top - height });
157173
const props = Object.assign({}, child.props, {

packages/renderer/.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +0,0 @@
1-
lib

0 commit comments

Comments
 (0)