ats-form-react-pdf-layout 4.4.4 → 4.4.5

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 +27 -5
  2. package/package.json +1 -1
package/lib/index.js CHANGED
@@ -2577,6 +2577,24 @@ const warnUnavailableSpace = (node) => {
2577
2577
  // eslint-disable-next-line no-console
2578
2578
  console.warn(`Node of type ${node.type} can't wrap between pages and it's bigger than available page height`);
2579
2579
  };
2580
+ const breakableViewChild = (children, height, path = '', currentChildren) => {
2581
+ for (let i = 0; i < children.length; i += 1) {
2582
+ if (children[i].type !== 'VIEW')
2583
+ continue;
2584
+ if (shouldBreak(children[i], children.slice(i + 1, height), height, currentChildren)) {
2585
+ return {
2586
+ child: children[i],
2587
+ path: `${path}/${i}`,
2588
+ };
2589
+ }
2590
+ if (children[i].children && children[i].children.length > 0) {
2591
+ const breakable = breakableViewChild(children[i].children, height, `${path}/${i}`, currentChildren);
2592
+ if (breakable)
2593
+ return breakable;
2594
+ }
2595
+ }
2596
+ return null;
2597
+ };
2580
2598
  const splitNodes = (height, contentArea, nodes) => {
2581
2599
  const currentChildren = [];
2582
2600
  const nextChildren = [];
@@ -2588,6 +2606,9 @@ const splitNodes = (height, contentArea, nodes) => {
2588
2606
  const nodeHeight = child.box.height;
2589
2607
  const isOutside = height <= nodeTop;
2590
2608
  const shouldBreak$1 = shouldBreak(child, futureNodes, height, currentChildren);
2609
+ const firstBreakableViewChild = child.children &&
2610
+ child.children.length > 0 &&
2611
+ breakableViewChild(child.children, height, '', currentChildren);
2591
2612
  const prevChild = nodes.length > 0 && i > 0 ? nodes[i - 1] : undefined;
2592
2613
  const shouldSplit = height + SAFETY_THRESHOLD < nodeTop + nodeHeight;
2593
2614
  const canWrap = getWrap(child, prevChild, currentChildren);
@@ -2608,6 +2629,7 @@ const splitNodes = (height, contentArea, nodes) => {
2608
2629
  currentChildren.push(child);
2609
2630
  nextChildren.push(...futureNodes);
2610
2631
  warnUnavailableSpace(child);
2632
+ break;
2611
2633
  }
2612
2634
  else {
2613
2635
  // We don't want to break non wrapable nodes, so we just let them be.
@@ -2621,8 +2643,8 @@ const splitNodes = (height, contentArea, nodes) => {
2621
2643
  const next = Object.assign({}, child, { box, props });
2622
2644
  currentChildren.push(...futureFixedNodes);
2623
2645
  nextChildren.push(next, ...futureNodes);
2646
+ break;
2624
2647
  }
2625
- break;
2626
2648
  }
2627
2649
  if (shouldBreak$1) {
2628
2650
  const box = Object.assign({}, child.box, { top: child.box.top - height });
@@ -2635,7 +2657,7 @@ const splitNodes = (height, contentArea, nodes) => {
2635
2657
  nextChildren.push(next, ...futureNodes);
2636
2658
  break;
2637
2659
  }
2638
- if (shouldSplit) {
2660
+ if (shouldSplit || firstBreakableViewChild) {
2639
2661
  const [currentChild, nextChild] = split(child, height, contentArea);
2640
2662
  // All children are moved to the next page, it doesn't make sense to show the parent on the current page
2641
2663
  if (child.children.length > 0 && currentChild.children.length === 0) {
@@ -2644,10 +2666,10 @@ const splitNodes = (height, contentArea, nodes) => {
2644
2666
  // currentChildren.push(child, ...futureFixedNodes);
2645
2667
  // nextChildren.push(...futureNodes);
2646
2668
  // } else {
2647
- const box = Object.assign({}, child.box, {
2648
- top: child.box.top - height,
2669
+ const box = Object.assign({}, nextChild.box, {
2670
+ top: nextChild.box.top - height,
2649
2671
  });
2650
- const next = Object.assign({}, child, { box });
2672
+ const next = Object.assign({}, nextChild, { box });
2651
2673
  currentChildren.push(...futureFixedNodes);
2652
2674
  nextChildren.push(next, ...futureNodes);
2653
2675
  // }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ats-form-react-pdf-layout",
3
- "version": "4.4.4",
3
+ "version": "4.4.5",
4
4
  "license": "MIT",
5
5
  "description": "Resolve document component's layout",
6
6
  "author": "Diego Muracciole <diegomuracciole@gmail.com>",