| 1 |
( function () { |
| 2 |
var el = wp.element.createElement; |
| 3 |
var Fragment = wp.element.Fragment; |
| 4 |
var useState = wp.element.useState; |
| 5 |
var __ = wp.i18n.__; |
| 6 |
var registerBlockType = wp.blocks.registerBlockType; |
| 7 |
var InspectorControls = wp.blockEditor.InspectorControls; |
| 8 |
var MediaUpload = wp.blockEditor.MediaUpload; |
| 9 |
var MediaUploadCheck = wp.blockEditor.MediaUploadCheck; |
| 10 |
var useBlockProps = wp.blockEditor.useBlockProps; |
| 11 |
var RichText = wp.blockEditor.RichText; |
| 12 |
var PanelBody = wp.components.PanelBody; |
| 13 |
var PanelColorSettings = wp.blockEditor.PanelColorSettings; |
| 14 |
var ToggleControl = wp.components.ToggleControl; |
| 15 |
var RangeControl = wp.components.RangeControl; |
| 16 |
var SelectControl = wp.components.SelectControl; |
| 17 |
var TextControl = wp.components.TextControl; |
| 18 |
var Button = wp.components.Button; |
| 19 |
|
| 20 |
/* ── lazy typography helpers ── */ |
| 21 |
function _tc() { return window.bkbgTypographyControl || null; } |
| 22 |
Object.defineProperty(window, '__bkAS_tvf', { get: function () { delete window.__bkAS_tvf; return (window.__bkAS_tvf = window.bkbgTypoCssVars || function () { return {}; }); } }); |
| 23 |
function getTypoCssVars(a) { |
| 24 |
var o = {}; |
| 25 |
Object.assign(o, window.__bkAS_tvf(a.headingTypo || {}, '--bkas-hd-')); |
| 26 |
Object.assign(o, window.__bkAS_tvf(a.bodyTypo || {}, '--bkas-bd-')); |
| 27 |
Object.assign(o, window.__bkAS_tvf(a.labelTypo || {}, '--bkas-lb-')); |
| 28 |
Object.assign(o, window.__bkAS_tvf(a.statValueTypo || {}, '--bkas-sv-')); |
| 29 |
Object.assign(o, window.__bkAS_tvf(a.statLabelTypo || {}, '--bkas-sl-')); |
| 30 |
return o; |
| 31 |
} |
| 32 |
|
| 33 |
registerBlockType('blockenberg/about-section', { |
| 34 |
title: __('About Section', 'blockenberg'), |
| 35 |
icon: 'admin-home', |
| 36 |
description: __('Ready-made About Us section with split image/video + text layout, optional company stats row, badge label, CTA buttons, and full background/color controls.', 'blockenberg'), |
| 37 |
category: 'bkbg-business', |
| 38 |
edit: function (props) { |
| 39 |
var attr = props.attributes; |
| 40 |
var setAttr = props.setAttributes; |
| 41 |
|
| 42 |
function updateStat(idx, key, val) { |
| 43 |
var next = attr.stats.map(function (s, i) { |
| 44 |
return i === idx ? Object.assign({}, s, { [key]: val }) : s; |
| 45 |
}); |
| 46 |
setAttr({ stats: next }); |
| 47 |
} |
| 48 |
|
| 49 |
function addStat() { |
| 50 |
setAttr({ stats: attr.stats.concat([{ value: '100+', label: 'New stat' }]) }); |
| 51 |
} |
| 52 |
|
| 53 |
function removeStat(idx) { |
| 54 |
setAttr({ stats: attr.stats.filter(function (_, i) { return i !== idx; }) }); |
| 55 |
} |
| 56 |
|
| 57 |
var blockProps = useBlockProps((function () { |
| 58 |
var s = getTypoCssVars(attr); |
| 59 |
return { className: 'bkbg-about-section-editor', style: s }; |
| 60 |
})()); |
| 61 |
|
| 62 |
var previewStyle = { |
| 63 |
background: attr.bgColor, |
| 64 |
padding: attr.paddingTop + 'px 40px ' + attr.paddingBottom + 'px', |
| 65 |
fontFamily: 'inherit' |
| 66 |
}; |
| 67 |
var innerStyle = { |
| 68 |
maxWidth: attr.maxWidth + 'px', |
| 69 |
margin: '0 auto', |
| 70 |
display: 'grid', |
| 71 |
gridTemplateColumns: '1fr 1fr', |
| 72 |
gap: attr.colGap + 'px', |
| 73 |
alignItems: attr.verticalAlign |
| 74 |
}; |
| 75 |
var imgCol = { order: attr.imageLayout === 'left' ? 0 : 1 }; |
| 76 |
var txtCol = { order: attr.imageLayout === 'left' ? 1 : 0 }; |
| 77 |
|
| 78 |
return el(Fragment, null, |
| 79 |
el(InspectorControls, null, |
| 80 |
el(PanelBody, { title: __('Content', 'blockenberg'), initialOpen: true }, |
| 81 |
el(ToggleControl, { label: __('Show Label', 'blockenberg'), __nextHasNoMarginBottom: true, checked: attr.showLabel, onChange: function (v) { setAttr({ showLabel: v }); } }), |
| 82 |
el(ToggleControl, { label: __('Show Stats Row', 'blockenberg'), __nextHasNoMarginBottom: true, checked: attr.showStats, onChange: function (v) { setAttr({ showStats: v }); } }), |
| 83 |
el(ToggleControl, { label: __('Show Primary CTA', 'blockenberg'), __nextHasNoMarginBottom: true, checked: attr.showCta, onChange: function (v) { setAttr({ showCta: v }); } }), |
| 84 |
attr.showCta && el(TextControl, { label: __('CTA Label', 'blockenberg'), __nextHasNoMarginBottom: true, value: attr.ctaLabel, onChange: function (v) { setAttr({ ctaLabel: v }); } }), |
| 85 |
attr.showCta && el(TextControl, { label: __('CTA URL', 'blockenberg'), __nextHasNoMarginBottom: true, value: attr.ctaUrl, onChange: function (v) { setAttr({ ctaUrl: v }); } }), |
| 86 |
attr.showCta && el(SelectControl, { label: __('CTA Style', 'blockenberg'), __nextHasNoMarginBottom: true, value: attr.ctaStyle, |
| 87 |
options: [{ label: 'Filled', value: 'filled' }, { label: 'Outline', value: 'outline' }, { label: 'Ghost', value: 'ghost' }], |
| 88 |
onChange: function (v) { setAttr({ ctaStyle: v }); } }), |
| 89 |
el(ToggleControl, { label: __('Show Second CTA', 'blockenberg'), __nextHasNoMarginBottom: true, checked: attr.showCta2, onChange: function (v) { setAttr({ showCta2: v }); } }), |
| 90 |
attr.showCta2 && el(TextControl, { label: __('CTA 2 Label', 'blockenberg'), __nextHasNoMarginBottom: true, value: attr.cta2Label, onChange: function (v) { setAttr({ cta2Label: v }); } }), |
| 91 |
attr.showCta2 && el(TextControl, { label: __('CTA 2 URL', 'blockenberg'), __nextHasNoMarginBottom: true, value: attr.cta2Url, onChange: function (v) { setAttr({ cta2Url: v }); } }), |
| 92 |
el(ToggleControl, { label: __('Show Signature', 'blockenberg'), __nextHasNoMarginBottom: true, checked: attr.showSignature, onChange: function (v) { setAttr({ showSignature: v }); } }), |
| 93 |
attr.showSignature && el(TextControl, { label: __('Signature / Author', 'blockenberg'), __nextHasNoMarginBottom: true, value: attr.signatureName, onChange: function (v) { setAttr({ signatureName: v }); } }) |
| 94 |
), |
| 95 |
el(PanelBody, { title: __('Image', 'blockenberg'), initialOpen: false }, |
| 96 |
el(MediaUploadCheck, null, |
| 97 |
el(MediaUpload, { |
| 98 |
onSelect: function (m) { setAttr({ imageUrl: m.url, imageId: m.id, imageAlt: m.alt || '' }); }, |
| 99 |
allowedTypes: ['image'], |
| 100 |
value: attr.imageId, |
| 101 |
render: function (r) { |
| 102 |
return el(Fragment, null, |
| 103 |
attr.imageUrl && el('img', { src: attr.imageUrl, style: { width: '100%', borderRadius: 8, marginBottom: 8 } }), |
| 104 |
el(Button, { onClick: r.open, variant: 'secondary', __nextHasNoMarginBottom: true }, attr.imageUrl ? __('Change Image', 'blockenberg') : __('Select Image', 'blockenberg')), |
| 105 |
attr.imageUrl && el(Button, { onClick: function () { setAttr({ imageUrl: '', imageId: 0 }); }, variant: 'link', isDestructive: true, __nextHasNoMarginBottom: true, style: { marginLeft: 8 } }, __('Remove', 'blockenberg')) |
| 106 |
); |
| 107 |
} |
| 108 |
}) |
| 109 |
), |
| 110 |
el(SelectControl, { label: __('Image Side', 'blockenberg'), __nextHasNoMarginBottom: true, value: attr.imageLayout, |
| 111 |
options: [{ label: 'Left', value: 'left' }, { label: 'Right', value: 'right' }], |
| 112 |
onChange: function (v) { setAttr({ imageLayout: v }); } }), |
| 113 |
el(SelectControl, { label: __('Image Shape', 'blockenberg'), __nextHasNoMarginBottom: true, value: attr.imageStyle, |
| 114 |
options: [{ label: 'Rounded', value: 'rounded' }, { label: 'Square', value: 'square' }, { label: 'Circle', value: 'circle' }, { label: 'Clipped', value: 'clipped' }], |
| 115 |
onChange: function (v) { setAttr({ imageStyle: v }); } }), |
| 116 |
el(ToggleControl, { label: __('Image Shadow', 'blockenberg'), __nextHasNoMarginBottom: true, checked: attr.imageShadow, onChange: function (v) { setAttr({ imageShadow: v }); } }) |
| 117 |
), |
| 118 |
attr.showStats && el(PanelBody, { title: __('Stats', 'blockenberg'), initialOpen: false }, |
| 119 |
attr.stats.map(function (s, i) { |
| 120 |
return el('div', { key: i, style: { borderLeft: '3px solid #7c3aed', paddingLeft: 8, marginBottom: 12 } }, |
| 121 |
el(TextControl, { label: __('Value', 'blockenberg') + ' ' + (i + 1), __nextHasNoMarginBottom: true, value: s.value, onChange: function (v) { updateStat(i, 'value', v); } }), |
| 122 |
el(TextControl, { label: __('Label', 'blockenberg') + ' ' + (i + 1), __nextHasNoMarginBottom: true, value: s.label, onChange: function (v) { updateStat(i, 'label', v); } }), |
| 123 |
attr.stats.length > 1 && el(Button, { onClick: function () { removeStat(i); }, variant: 'link', isDestructive: true, __nextHasNoMarginBottom: true }, __('Remove', 'blockenberg')) |
| 124 |
); |
| 125 |
}), |
| 126 |
el(Button, { onClick: addStat, variant: 'secondary', __nextHasNoMarginBottom: true }, __('+ Add Stat', 'blockenberg')) |
| 127 |
), |
| 128 |
el(PanelBody, { title: __('Layout', 'blockenberg'), initialOpen: false }, |
| 129 |
el(SelectControl, { label: __('Vertical Align', 'blockenberg'), __nextHasNoMarginBottom: true, value: attr.verticalAlign, |
| 130 |
options: [{ label: 'Center', value: 'center' }, { label: 'Top', value: 'start' }, { label: 'Bottom', value: 'end' }], |
| 131 |
onChange: function (v) { setAttr({ verticalAlign: v }); } }), |
| 132 |
el(RangeControl, { label: __('Column Gap (px)', 'blockenberg'), __nextHasNoMarginBottom: true, value: attr.colGap, min: 16, max: 128, onChange: function (v) { setAttr({ colGap: v }); } }), |
| 133 |
el(RangeControl, { label: __('Max Width (px)', 'blockenberg'), __nextHasNoMarginBottom: true, value: attr.maxWidth, min: 600, max: 1600, step: 10, onChange: function (v) { setAttr({ maxWidth: v }); } }), |
| 134 |
el(RangeControl, { label: __('Padding Top (px)', 'blockenberg'), __nextHasNoMarginBottom: true, value: attr.paddingTop, min: 0, max: 200, onChange: function (v) { setAttr({ paddingTop: v }); } }), |
| 135 |
el(RangeControl, { label: __('Padding Bottom (px)', 'blockenberg'), __nextHasNoMarginBottom: true, value: attr.paddingBottom, min: 0, max: 200, onChange: function (v) { setAttr({ paddingBottom: v }); } }) |
| 136 |
), |
| 137 |
el(PanelBody, { title: __('Typography', 'blockenberg'), initialOpen: false }, |
| 138 |
_tc() && el(_tc(), { label: __('Heading', 'blockenberg'), value: attr.headingTypo || {}, onChange: function (v) { setAttr({ headingTypo: v }); } }), |
| 139 |
_tc() && el(_tc(), { label: __('Body Text', 'blockenberg'), value: attr.bodyTypo || {}, onChange: function (v) { setAttr({ bodyTypo: v }); } }), |
| 140 |
_tc() && el(_tc(), { label: __('Label', 'blockenberg'), value: attr.labelTypo || {}, onChange: function (v) { setAttr({ labelTypo: v }); } }), |
| 141 |
_tc() && el(_tc(), { label: __('Stat Value', 'blockenberg'), value: attr.statValueTypo || {}, onChange: function (v) { setAttr({ statValueTypo: v }); } }), |
| 142 |
_tc() && el(_tc(), { label: __('Stat Label', 'blockenberg'), value: attr.statLabelTypo || {}, onChange: function (v) { setAttr({ statLabelTypo: v }); } }) |
| 143 |
), |
| 144 |
el(PanelColorSettings, { |
| 145 |
title: __('Colors', 'blockenberg'), |
| 146 |
initialOpen: false, |
| 147 |
colorSettings: [ |
| 148 |
{ value: attr.bgColor, onChange: function (v) { setAttr({ bgColor: v || '#ffffff' }); }, label: __('Background', 'blockenberg') }, |
| 149 |
{ value: attr.accentColor, onChange: function (v) { setAttr({ accentColor: v || '#7c3aed' }); }, label: __('Accent', 'blockenberg') }, |
| 150 |
{ value: attr.headingColor, onChange: function (v) { setAttr({ headingColor: v || '#111827' }); }, label: __('Heading', 'blockenberg') }, |
| 151 |
{ value: attr.textColor, onChange: function (v) { setAttr({ textColor: v || '#6b7280' }); }, label: __('Body Text', 'blockenberg') }, |
| 152 |
{ value: attr.statValueColor, onChange: function (v) { setAttr({ statValueColor: v || '#111827' }); }, label: __('Stat Value', 'blockenberg') }, |
| 153 |
{ value: attr.statLabelColor, onChange: function (v) { setAttr({ statLabelColor: v || '#6b7280' }); }, label: __('Stat Label', 'blockenberg') }, |
| 154 |
{ value: attr.ctaBg, onChange: function (v) { setAttr({ ctaBg: v || '#7c3aed' }); }, label: __('CTA Background', 'blockenberg') }, |
| 155 |
{ value: attr.ctaColor, onChange: function (v) { setAttr({ ctaColor: v || '#ffffff' }); }, label: __('CTA Text', 'blockenberg') }, |
| 156 |
{ value: attr.labelBg, onChange: function (v) { setAttr({ labelBg: v || '#ede9fe' }); }, label: __('Label Background', 'blockenberg') }, |
| 157 |
{ value: attr.labelColor, onChange: function (v) { setAttr({ labelColor: v || '#7c3aed' }); }, label: __('Label Text', 'blockenberg') } |
| 158 |
] |
| 159 |
}) |
| 160 |
), |
| 161 |
el('div', blockProps, |
| 162 |
el('div', { style: previewStyle }, |
| 163 |
el('div', { style: innerStyle }, |
| 164 |
el('div', { className: 'bkbg-as-image-col', style: imgCol }, |
| 165 |
attr.imageUrl |
| 166 |
? el('img', { src: attr.imageUrl, alt: attr.imageAlt, style: { width: '100%', display: 'block', borderRadius: attr.imageStyle === 'rounded' ? 16 : attr.imageStyle === 'circle' ? '50%' : 0, boxShadow: attr.imageShadow ? '0 20px 60px rgba(0,0,0,.15)' : 'none' } }) |
| 167 |
: el('div', { style: { background: '#e5e7eb', borderRadius: 16, height: 360, display: 'flex', alignItems: 'center', justifyContent: 'center', color: '#9ca3af', fontSize: 14 } }, __('Select an image in the panel', 'blockenberg')) |
| 168 |
), |
| 169 |
el('div', { className: 'bkbg-as-text-col', style: Object.assign({}, txtCol, { display: 'flex', flexDirection: 'column', gap: 24 }) }, |
| 170 |
attr.showLabel && el('span', { className: 'bkbg-as-label', style: { background: attr.labelBg, color: attr.labelColor, alignSelf: 'flex-start' } }, attr.label), |
| 171 |
el(RichText, { tagName: 'h2', className: 'bkbg-as-heading', value: attr.heading, onChange: function (v) { setAttr({ heading: v }); }, style: { color: attr.headingColor, margin: 0 }, placeholder: __('Heading…', 'blockenberg') }), |
| 172 |
el(RichText, { tagName: 'p', className: 'bkbg-as-body', value: attr.subtext, onChange: function (v) { setAttr({ subtext: v }); }, style: { color: attr.textColor, margin: 0 }, placeholder: __('Describe your company or story…', 'blockenberg') }), |
| 173 |
attr.showStats && attr.stats.length > 0 && el('div', { style: { display: 'flex', gap: 32, flexWrap: 'wrap', paddingTop: 8 } }, |
| 174 |
attr.stats.map(function (s, i) { |
| 175 |
return el('div', { key: i }, |
| 176 |
el('div', { className: 'bkbg-as-stat-value', style: { color: attr.statValueColor } }, s.value), |
| 177 |
el('div', { className: 'bkbg-as-stat-label', style: { color: attr.statLabelColor } }, s.label) |
| 178 |
); |
| 179 |
}) |
| 180 |
), |
| 181 |
(attr.showCta || attr.showCta2 || attr.showSignature) && el('div', { style: { display: 'flex', flexWrap: 'wrap', alignItems: 'center', gap: 16 } }, |
| 182 |
attr.showCta && el('a', { href: '#', style: { display: 'inline-flex', alignItems: 'center', gap: 8, padding: '12px 28px', borderRadius: 8, fontWeight: 600, fontSize: 15, background: attr.ctaStyle === 'filled' ? attr.ctaBg : 'transparent', color: attr.ctaStyle === 'filled' ? attr.ctaColor : attr.accentColor, border: attr.ctaStyle === 'filled' ? 'none' : '2px solid ' + attr.accentColor, textDecoration: 'none' } }, attr.ctaLabel, el('span', null, '→')), |
| 183 |
attr.showCta2 && el('a', { href: '#', style: { display: 'inline-flex', alignItems: 'center', gap: 8, padding: '12px 28px', borderRadius: 8, fontWeight: 600, fontSize: 15, background: 'transparent', color: attr.headingColor, textDecoration: 'none' } }, attr.cta2Label), |
| 184 |
attr.showSignature && el('span', { style: { fontSize: 14, color: attr.textColor, fontStyle: 'italic' } }, '— ' + attr.signatureName) |
| 185 |
) |
| 186 |
) |
| 187 |
) |
| 188 |
) |
| 189 |
) |
| 190 |
); |
| 191 |
}, |
| 192 |
save: function (props) { |
| 193 |
var attr = props.attributes; |
| 194 |
var sv = getTypoCssVars(attr); |
| 195 |
return el('div', useBlockProps.save(), |
| 196 |
el('div', { className: 'bkbg-about-section-app', 'data-opts': JSON.stringify(attr), style: sv }) |
| 197 |
); |
| 198 |
} |
| 199 |
}); |
| 200 |
}() ); |
| 201 |
|