/** * WPBC BFB: Section Renderer (WP-template–driven, slim version) * --------------------------------------------------------------------------------- * - Delegates column-style logic to UI.WPBC_BFB_Column_Styles (separate module) * - Inspector glue is moved to: /_out/core/bfb-inspector-patches.js * * Contracts: * - Registry: Registry.register( 'section', WPBC_BFB_Section ); * - Class API: static get_defaults(), static render(el, data, ctx), static on_field_drop(data, el, ctx?) * * File: /includes/page-form-builder/field-packs/section/_out/section-wptpl.js * * @since 11.0.0 * @modified 2025-09-16 11:24 * @version 1.1.0 */ (function ( w ) { 'use strict'; var Core = w.WPBC_BFB_Core || {}; var Registry = Core.WPBC_BFB_Field_Renderer_Registry; var Base = Core.WPBC_BFB_Field_Base; var UI = ( Core.UI = Core.UI || {} ); if ( ! Registry || typeof Registry.register !== 'function' || ! Base ) { w._wpbc && w._wpbc.dev && w._wpbc.dev.error && w._wpbc.dev.error( 'WPBC_BFB_Section', 'Core registry/base missing' ); return; } // Shortcuts. var S = Core.WPBC_BFB_Sanitize; var ColStyles = UI.WPBC_BFB_Column_Styles || null; /** * Clamp number of columns to supported range. * * @param {number|string} n * @returns {number} */ function clamp_cols( n ) { return S.clamp( Number( n ) || 1, 1, 4 ); } class WPBC_BFB_Section extends Base { static template_id = 'wpbc-bfb-section'; /** * Default data for a new Section. * NOTE: Keep in sync with PHP schema. */ static get_defaults() { return { type : 'section', label : 'Section', columns : 1, id : '', html_id : '', cssclass : '', col_styles : '' // JSON string, empty by default to avoid activation }; } /** * Render section preview into element. * * @param {HTMLElement} el * @param {object} data * @param {object} ctx */ static render( el, data, ctx ) { if ( ! el ) { return; } var d = this.normalize_data( data ); var html_id = d.html_id ? S.sanitize_html_id( String( d.html_id ) ) : ''; var next_class = S.sanitize_css_classlist( String( d.cssclass || '' ) ); var col_styles = ( d.col_styles != null ) ? String( d.col_styles ) : ''; // Treat legacy "[]" as empty / inactive. if ( col_styles.trim() === '[]' ) { col_styles = ''; } el.classList.add( 'wpbc_bfb__section' ); el.dataset.type = 'section'; el.dataset.label = ( d.label != null ? String( d.label ) : '' ); el.dataset.columns = ( d.columns != null ? String( clamp_cols( d.columns ) ) : '1' ); el.dataset.html_id = html_id; el.dataset.cssclass = next_class || ''; el.dataset.col_styles = col_styles; // Replace previous custom classes. var prev = ( el.__wpbc_prev_classes || '' ); if ( prev ) { prev.split( /\s+/ ).filter( Boolean ).forEach( function ( cls ) { el.classList.remove( cls ); } ); } if ( next_class ) { next_class.split( /\s+/ ).filter( Boolean ).forEach( function ( cls ) { el.classList.add( cls ); } ); } el.__wpbc_prev_classes = next_class || ''; // Render wp.template. var tpl = this.get_template( this.template_id ); if ( typeof tpl !== 'function' ) { w._wpbc && w._wpbc.dev && w._wpbc.dev.error && w._wpbc.dev.error( 'section_wptpl.tpl.missing', 'Template not found: ' + this.template_id ); el.innerHTML = '