| 1 |
( function () { |
| 2 |
const el = window.wp.element.createElement; |
| 3 |
const { registerBlockType } = window.wp.blocks; |
| 4 |
const { InspectorControls, useBlockProps, PanelColorSettings } = window.wp.blockEditor; |
| 5 |
const { PanelBody, RangeControl, ToggleControl, TextControl, Button } = window.wp.components; |
| 6 |
const { __ } = window.wp.i18n; |
| 7 |
const Fragment = window.wp.element.Fragment; |
| 8 |
|
| 9 |
// Lazy lookup so the typography control is resolved at render time |
| 10 |
function getTypographyControl() { |
| 11 |
return (typeof window.bkbgTypographyControl !== 'undefined') ? window.bkbgTypographyControl : null; |
| 12 |
} |
| 13 |
function getTypoCssVars() { |
| 14 |
return (typeof window.bkbgTypoCssVars !== 'undefined') ? window.bkbgTypoCssVars : function() { return {}; }; |
| 15 |
} |
| 16 |
|
| 17 |
// ── Row component ───────────────────────────────────────────────────────── |
| 18 |
function InfoRow( { icon, children, accentColor, textColor, labelColor, fontSize } ) { |
| 19 |
return el( 'div', { className: 'bkbg-ac-row', style: { display: 'flex', alignItems: 'flex-start', gap: 12, padding: '10px 0', borderBottom: '1px solid rgba(0,0,0,0.06)' } }, |
| 20 |
el( 'div', { className: 'bkbg-ac-icon', style: { |
| 21 |
width: 34, height: 34, borderRadius: 8, background: accentColor + '15', |
| 22 |
display: 'flex', alignItems: 'center', justifyContent: 'center', |
| 23 |
fontSize: 16, flexShrink: 0, color: accentColor, |
| 24 |
} }, icon ), |
| 25 |
el( 'div', { className: 'bkbg-ac-row-text', style: { flex: 1, color: textColor, paddingTop: 6 } }, children ), |
| 26 |
); |
| 27 |
} |
| 28 |
|
| 29 |
// ── Full render ─────────────────────────────────────────────────────────── |
| 30 |
function renderAddressCard( a ) { |
| 31 |
return el( 'div', { className: 'bkbg-ac-card', style: { |
| 32 |
background: a.cardBg, |
| 33 |
border: '1px solid ' + a.borderColor, |
| 34 |
borderRadius: a.borderRadius + 'px', |
| 35 |
padding: a.padding + 'px', |
| 36 |
borderTop: '3px solid ' + a.accentColor, |
| 37 |
boxSizing: 'border-box', |
| 38 |
} }, |
| 39 |
// Header |
| 40 |
el( 'div', { className: 'bkbg-ac-header', style: { marginBottom: 16 } }, |
| 41 |
a.showCompany && el( 'div', { className: 'bkbg-ac-company', style: { color: a.headingColor } }, a.companyName ), |
| 42 |
a.showTagline && el( 'div', { className: 'bkbg-ac-tagline-text', style: { color: a.taglineColor, marginTop: 4 } }, a.tagline ), |
| 43 |
), |
| 44 |
|
| 45 |
// Info rows |
| 46 |
a.showAddress && el( InfoRow, { icon: '📍', accentColor: a.accentColor, textColor: a.textColor, labelColor: a.labelColor, fontSize: a.fontSize }, |
| 47 |
el( 'span', {}, a.address1 ), |
| 48 |
a.address2 && el( 'span', { style: { display: 'block' } }, a.address2 ), |
| 49 |
a.country && el( 'span', { style: { display: 'block', color: a.labelColor } }, a.country ), |
| 50 |
), |
| 51 |
a.showPhone && el( InfoRow, { icon: '📞', accentColor: a.accentColor, textColor: a.textColor, labelColor: a.labelColor, fontSize: a.fontSize }, |
| 52 |
el( 'a', { href: 'tel:' + a.phone, style: { color: a.textColor, textDecoration: 'none' } }, a.phone ), |
| 53 |
), |
| 54 |
a.showEmail && el( InfoRow, { icon: '✉️', accentColor: a.accentColor, textColor: a.textColor, labelColor: a.labelColor, fontSize: a.fontSize }, |
| 55 |
el( 'a', { href: 'mailto:' + a.email, style: { color: a.linkColor, textDecoration: 'none' } }, a.email ), |
| 56 |
), |
| 57 |
a.showWebsite && el( InfoRow, { icon: '🌐', accentColor: a.accentColor, textColor: a.textColor, labelColor: a.labelColor, fontSize: a.fontSize }, |
| 58 |
el( 'a', { href: a.website, style: { color: a.linkColor, textDecoration: 'none' } }, a.website.replace( /^https?:\/\//, '' ) ), |
| 59 |
), |
| 60 |
a.showHours && el( InfoRow, { icon: '🕐', accentColor: a.accentColor, textColor: a.textColor, labelColor: a.labelColor, fontSize: a.fontSize }, |
| 61 |
a.hours, |
| 62 |
), |
| 63 |
|
| 64 |
// Map link |
| 65 |
a.showMapLink && el( 'a', { |
| 66 |
href: a.mapUrl || '#', |
| 67 |
className: 'bkbg-ac-maplink', |
| 68 |
style: { |
| 69 |
display: 'inline-flex', alignItems: 'center', gap: 6, |
| 70 |
marginTop: 16, padding: '8px 16px', |
| 71 |
background: a.accentColor, color: '#fff', |
| 72 |
borderRadius: 99, |
| 73 |
fontWeight: 600, textDecoration: 'none', |
| 74 |
boxShadow: '0 2px 6px ' + a.accentColor + '44', |
| 75 |
} |
| 76 |
}, '🗺️ ', a.mapLinkLabel ), |
| 77 |
); |
| 78 |
} |
| 79 |
|
| 80 |
// ── Block ───────────────────────────────────────────────────────────────── |
| 81 |
registerBlockType( 'blockenberg/address-card', { |
| 82 |
edit: function ( props ) { |
| 83 |
const { attributes: a, setAttributes } = props; |
| 84 |
var _tv = getTypoCssVars(); |
| 85 |
var wrapStyle = { background: a.bgColor, |
| 86 |
'--bkbg-ac-heading-sz': a.headingFontSize + 'px', |
| 87 |
'--bkbg-ac-body-sz': a.fontSize + 'px', |
| 88 |
}; |
| 89 |
Object.assign(wrapStyle, _tv(a.headingTypo || {}, '--bkbg-ac-heading-')); |
| 90 |
Object.assign(wrapStyle, _tv(a.bodyTypo || {}, '--bkbg-ac-body-')); |
| 91 |
const blockProps = useBlockProps( { className: 'bkbg-ac-wrap', style: wrapStyle } ); |
| 92 |
|
| 93 |
return el( 'div', blockProps, |
| 94 |
el( InspectorControls, {}, |
| 95 |
|
| 96 |
el( PanelBody, { title: __( 'Company', 'blockenberg' ), initialOpen: true }, |
| 97 |
el( ToggleControl, { label: __( 'Show Company Name', 'blockenberg' ), checked: a.showCompany, onChange: v => setAttributes( { showCompany: v } ) } ), |
| 98 |
el( TextControl, { label: __( 'Company Name', 'blockenberg' ), value: a.companyName, onChange: v => setAttributes( { companyName: v } ) } ), |
| 99 |
el( ToggleControl, { label: __( 'Show Tagline', 'blockenberg' ), checked: a.showTagline, onChange: v => setAttributes( { showTagline: v } ) } ), |
| 100 |
el( TextControl, { label: __( 'Tagline', 'blockenberg' ), value: a.tagline, onChange: v => setAttributes( { tagline: v } ) } ), |
| 101 |
), |
| 102 |
|
| 103 |
el( PanelBody, { title: __( 'Contact Details', 'blockenberg' ), initialOpen: false }, |
| 104 |
el( ToggleControl, { label: __( 'Show Address', 'blockenberg' ), checked: a.showAddress, onChange: v => setAttributes( { showAddress: v } ) } ), |
| 105 |
el( TextControl, { label: __( 'Address Line 1', 'blockenberg' ), value: a.address1, onChange: v => setAttributes( { address1: v } ) } ), |
| 106 |
el( TextControl, { label: __( 'Address Line 2', 'blockenberg' ), value: a.address2, onChange: v => setAttributes( { address2: v } ) } ), |
| 107 |
el( TextControl, { label: __( 'Country', 'blockenberg' ), value: a.country, onChange: v => setAttributes( { country: v } ) } ), |
| 108 |
el( ToggleControl, { label: __( 'Show Phone', 'blockenberg' ), checked: a.showPhone, onChange: v => setAttributes( { showPhone: v } ) } ), |
| 109 |
el( TextControl, { label: __( 'Phone', 'blockenberg' ), value: a.phone, onChange: v => setAttributes( { phone: v } ) } ), |
| 110 |
el( ToggleControl, { label: __( 'Show Email', 'blockenberg' ), checked: a.showEmail, onChange: v => setAttributes( { showEmail: v } ) } ), |
| 111 |
el( TextControl, { label: __( 'Email', 'blockenberg' ), value: a.email, onChange: v => setAttributes( { email: v } ) } ), |
| 112 |
el( ToggleControl, { label: __( 'Show Website', 'blockenberg' ),checked: a.showWebsite, onChange: v => setAttributes( { showWebsite: v } ) } ), |
| 113 |
el( TextControl, { label: __( 'Website URL', 'blockenberg' ), value: a.website, onChange: v => setAttributes( { website: v } ) } ), |
| 114 |
el( ToggleControl, { label: __( 'Show Hours', 'blockenberg' ), checked: a.showHours, onChange: v => setAttributes( { showHours: v } ) } ), |
| 115 |
el( TextControl, { label: __( 'Opening Hours', 'blockenberg' ),value: a.hours, onChange: v => setAttributes( { hours: v } ) } ), |
| 116 |
), |
| 117 |
|
| 118 |
el( PanelBody, { title: __( 'Map Link', 'blockenberg' ), initialOpen: false }, |
| 119 |
el( ToggleControl, { label: __( 'Show Map Link', 'blockenberg' ), checked: a.showMapLink, onChange: v => setAttributes( { showMapLink: v } ) } ), |
| 120 |
el( TextControl, { label: __( 'Map URL', 'blockenberg' ), value: a.mapUrl, onChange: v => setAttributes( { mapUrl: v } ) } ), |
| 121 |
el( TextControl, { label: __( 'Link Label', 'blockenberg' ), value: a.mapLinkLabel, onChange: v => setAttributes( { mapLinkLabel: v } ) } ), |
| 122 |
), |
| 123 |
|
| 124 |
el( PanelBody, { title: __( 'Style', 'blockenberg' ), initialOpen: false }, |
| 125 |
el( RangeControl, { label: __( 'Border Radius', 'blockenberg' ), value: a.borderRadius, onChange: v => setAttributes( { borderRadius: v } ), min: 0, max: 32 } ), |
| 126 |
el( RangeControl, { label: __( 'Padding', 'blockenberg' ), value: a.padding, onChange: v => setAttributes( { padding: v } ), min: 12, max: 60 } ), |
| 127 |
), |
| 128 |
|
| 129 |
|
| 130 |
el( PanelBody, { title: __( 'Typography', 'blockenberg' ), initialOpen: false }, |
| 131 |
(function () { |
| 132 |
var TC = getTypographyControl(); |
| 133 |
if (!TC) return el('p', { style: { color: '#999', fontSize: '12px', padding: '8px 0' } }, __('Typography control loading…', 'blockenberg')); |
| 134 |
return el(Fragment, {}, |
| 135 |
el(TC, { label: __('Heading', 'blockenberg'), value: a.headingTypo || {}, onChange: function (v) { setAttributes({ headingTypo: v }); } }), |
| 136 |
el(TC, { label: __('Body Text', 'blockenberg'), value: a.bodyTypo || {}, onChange: function (v) { setAttributes({ bodyTypo: v }); } }) |
| 137 |
); |
| 138 |
})() |
| 139 |
), |
| 140 |
el( PanelColorSettings, { |
| 141 |
title: __( 'Colors', 'blockenberg' ), initialOpen: false, |
| 142 |
colorSettings: [ |
| 143 |
{ label: __( 'Accent / Top Border', 'blockenberg' ), value: a.accentColor, onChange: v => setAttributes( { accentColor: v || '#6366f1' } ) }, |
| 144 |
{ label: __( 'Page Background', 'blockenberg' ), value: a.bgColor, onChange: v => setAttributes( { bgColor: v || '#ffffff' } ) }, |
| 145 |
{ label: __( 'Card Background', 'blockenberg' ), value: a.cardBg, onChange: v => setAttributes( { cardBg: v || '#f9fafb' } ) }, |
| 146 |
{ label: __( 'Border', 'blockenberg' ), value: a.borderColor, onChange: v => setAttributes( { borderColor: v || '#e5e7eb' } ) }, |
| 147 |
{ label: __( 'Heading', 'blockenberg' ), value: a.headingColor, onChange: v => setAttributes( { headingColor: v || '#111827' } ) }, |
| 148 |
{ label: __( 'Tagline', 'blockenberg' ), value: a.taglineColor, onChange: v => setAttributes( { taglineColor: v || '#6b7280' } ) }, |
| 149 |
{ label: __( 'Body Text', 'blockenberg' ), value: a.textColor, onChange: v => setAttributes( { textColor: v || '#374151' } ) }, |
| 150 |
{ label: __( 'Links', 'blockenberg' ), value: a.linkColor, onChange: v => setAttributes( { linkColor: v || '#6366f1' } ) }, |
| 151 |
] |
| 152 |
} ), |
| 153 |
), |
| 154 |
|
| 155 |
renderAddressCard( a ), |
| 156 |
); |
| 157 |
}, |
| 158 |
|
| 159 |
save: function ( { attributes: a } ) { |
| 160 |
var _tv = getTypoCssVars(); |
| 161 |
var wrapStyle = { background: a.bgColor, |
| 162 |
'--bkbg-ac-heading-sz': a.headingFontSize + 'px', |
| 163 |
'--bkbg-ac-body-sz': a.fontSize + 'px', |
| 164 |
}; |
| 165 |
Object.assign(wrapStyle, _tv(a.headingTypo || {}, '--bkbg-ac-heading-')); |
| 166 |
Object.assign(wrapStyle, _tv(a.bodyTypo || {}, '--bkbg-ac-body-')); |
| 167 |
const blockProps = useBlockProps.save( { className: 'bkbg-ac-wrap', style: wrapStyle } ); |
| 168 |
return el( 'div', blockProps, renderAddressCard( a ) ); |
| 169 |
}, |
| 170 |
} ); |
| 171 |
}() ); |
| 172 |
|