| 1 |
/** |
| 2 |
* Shared rule for multi-step boundaries: drop progress bars first, then a |
| 3 |
* break counts only with a non-bar block on both sides. Keep in sync with the |
| 4 |
* PHP injector `wppb_pb_fb_inject_progress_bar_blocks()`. |
| 5 |
*/ |
| 6 |
|
| 7 |
export const STEP_BREAK_BLOCK = 'profile-builder/msf-step-break'; |
| 8 |
export const PROGRESS_BAR_BLOCK = 'profile-builder/progress-bar'; |
| 9 |
|
| 10 |
/** Drop injected progress bars from a top-level list. */ |
| 11 |
export function withoutProgressBars( blocks ) { |
| 12 |
return ( blocks || [] ).filter( ( b ) => b && b.name !== PROGRESS_BAR_BLOCK ); |
| 13 |
} |
| 14 |
|
| 15 |
/** True when index is a real step boundary (not leading/trailing). */ |
| 16 |
export function isStepBoundary( nonBarBlocks, index ) { |
| 17 |
const block = nonBarBlocks[ index ]; |
| 18 |
if ( ! block || block.name !== STEP_BREAK_BLOCK ) return false; |
| 19 |
|
| 20 |
return index !== 0 && index !== nonBarBlocks.length - 1; |
| 21 |
} |
| 22 |
|
| 23 |
/** Real step-boundary count (bars filtered). Step count = this + 1. */ |
| 24 |
export function countStepBoundaries( blocks ) { |
| 25 |
const nonBar = withoutProgressBars( blocks ); |
| 26 |
|
| 27 |
let n = 0; |
| 28 |
for ( let i = 0; i < nonBar.length; i++ ) { |
| 29 |
if ( isStepBoundary( nonBar, i ) ) n++; |
| 30 |
} |
| 31 |
return n; |
| 32 |
} |
| 33 |
|