PluginProbe
User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor / 4.0.3
User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor v4.0.3
4.0.3 4.0.2 4.0.1 4.0.0 3.16.6 3.16.5 3.16.4 3.16.3 3.16.2 3.16.1 3.16.0 3.15.9 3.9.9 3.9.5 3.9.6 3.9.7 3.9.8 1.1.7 1.1.8 1.1.9 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 All 341 releases
profile-builder / form-builder / blocks / src / lib / stepBoundaries.js

stepBoundaries.js in User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor 4.0.3, at form-builder/blocks/src/lib/stepBoundaries.js

33 lines 1.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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