ats-form-react-pdf-layout 4.4.8 → 4.4.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/lib/index.js +24 -11
  2. package/package.json +1 -1
package/lib/index.js CHANGED
@@ -2668,6 +2668,18 @@ const splitNodes = (height, contentArea, nodes) => {
2668
2668
  nextChildren.push(next, ...futureNodes);
2669
2669
  break;
2670
2670
  }
2671
+ // Element fits on a full page but not in remaining space - move to next page to keep together
2672
+ // This handles the case where wrap is true (default) but we still want to avoid splitting
2673
+ // if the element would fit entirely on the next page
2674
+ const remainingSpace = height - nodeTop;
2675
+ const wouldBarelyFitOnCurrentPage = remainingSpace < nodeHeight * 0.3; // Less than 30% fits
2676
+ if (fitsInsidePage && shouldSplit && wouldBarelyFitOnCurrentPage && currentChildren.length > 0) {
2677
+ const box = Object.assign({}, child.box, { top: child.box.top - height });
2678
+ const next = Object.assign({}, child, { box });
2679
+ currentChildren.push(...futureFixedNodes);
2680
+ nextChildren.push(next, ...futureNodes);
2681
+ break;
2682
+ }
2671
2683
  if (shouldBreak$1) {
2672
2684
  const box = Object.assign({}, child.box, { top: child.box.top - height });
2673
2685
  const props = Object.assign({}, child.props, {
@@ -2681,20 +2693,21 @@ const splitNodes = (height, contentArea, nodes) => {
2681
2693
  }
2682
2694
  if (shouldSplit || firstBreakableViewChild) {
2683
2695
  const [currentChild, nextChild] = split(child, height, contentArea);
2684
- // All children are moved to the next page, it doesn't make sense to show the parent on the current page
2685
- if (child.children.length > 0 && currentChild.children.length === 0) {
2686
- // But if the current page is empty then we can just include the parent on the current page
2687
- // if (currentChildren.length === 0) {
2688
- // currentChildren.push(child, ...futureFixedNodes);
2689
- // nextChildren.push(...futureNodes);
2690
- // } else {
2691
- const box = Object.assign({}, nextChild.box, {
2692
- top: nextChild.box.top - height,
2696
+ // Check if all non-fixed children are moved to the next page
2697
+ const currentNonFixedChildren = currentChild.children
2698
+ ? currentChild.children.filter((c) => !isFixed(c))
2699
+ : [];
2700
+ const hasNonFixedChildren = child.children
2701
+ ? child.children.filter((c) => !isFixed(c)).length > 0
2702
+ : false;
2703
+ // All meaningful children are moved to the next page, move the parent too
2704
+ if (hasNonFixedChildren && currentNonFixedChildren.length === 0) {
2705
+ const box = Object.assign({}, child.box, {
2706
+ top: child.box.top - height,
2693
2707
  });
2694
- const next = Object.assign({}, nextChild, { box });
2708
+ const next = Object.assign({}, child, { box });
2695
2709
  currentChildren.push(...futureFixedNodes);
2696
2710
  nextChildren.push(next, ...futureNodes);
2697
- // }
2698
2711
  break;
2699
2712
  }
2700
2713
  if (currentChild)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ats-form-react-pdf-layout",
3
- "version": "4.4.8",
3
+ "version": "4.4.9",
4
4
  "license": "MIT",
5
5
  "description": "Resolve document component's layout",
6
6
  "author": "Atharva System",