| 1 |
( function () { |
| 2 |
var el = wp.element.createElement; |
| 3 |
var __ = wp.i18n.__; |
| 4 |
var registerBlockType = wp.blocks.registerBlockType; |
| 5 |
var InspectorControls = wp.blockEditor.InspectorControls; |
| 6 |
var MediaUpload = wp.blockEditor.MediaUpload; |
| 7 |
var MediaUploadCheck = wp.blockEditor.MediaUploadCheck; |
| 8 |
var useBlockProps = wp.blockEditor.useBlockProps; |
| 9 |
var RichText = wp.blockEditor.RichText; |
| 10 |
var PanelColorSettings = wp.blockEditor.PanelColorSettings; |
| 11 |
var PanelBody = wp.components.PanelBody; |
| 12 |
var ToggleControl = wp.components.ToggleControl; |
| 13 |
var RangeControl = wp.components.RangeControl; |
| 14 |
var SelectControl = wp.components.SelectControl; |
| 15 |
var TextControl = wp.components.TextControl; |
| 16 |
var Button = wp.components.Button; |
| 17 |
|
| 18 |
var _tc, _tv; |
| 19 |
function getTypoControl() { return _tc || (_tc = window.bkbgTypographyControl); } |
| 20 |
function getTypoCssVars() { return _tv || (_tv = window.bkbgTypoCssVars); } |
| 21 |
|
| 22 |
registerBlockType('blockenberg/media-coverage', { |
| 23 |
edit: function (props) { |
| 24 |
var a = props.attributes; |
| 25 |
var set = props.setAttributes; |
| 26 |
var blockProps = useBlockProps((function () { |
| 27 |
var tv = getTypoCssVars(); |
| 28 |
var s = {}; |
| 29 |
Object.assign(s, tv(a.eyebrowTypo, '--bkbg-mdc-ey-')); |
| 30 |
Object.assign(s, tv(a.headingTypo, '--bkbg-mdc-hd-')); |
| 31 |
Object.assign(s, tv(a.quoteTypo, '--bkbg-mdc-qt-')); |
| 32 |
return { style: s }; |
| 33 |
})()); |
| 34 |
|
| 35 |
function updateLogo(idx, key, val) { |
| 36 |
var next = a.logos.map(function (l, i) { return i === idx ? Object.assign({}, l, { [key]: val }) : l; }); |
| 37 |
set({ logos: next }); |
| 38 |
} |
| 39 |
|
| 40 |
/* --- Logo items in editor --- */ |
| 41 |
var logosEl = el('div', { |
| 42 |
style: { |
| 43 |
display: 'flex', flexWrap: 'wrap', gap: a.logoGap + 'px', |
| 44 |
justifyContent: 'center', alignItems: 'center', |
| 45 |
margin: '0 0 32px' |
| 46 |
} |
| 47 |
}, |
| 48 |
a.logos.map(function (logo, idx) { |
| 49 |
return el('div', { key: idx, style: { display: 'flex', flexDirection: 'column', alignItems: 'center', gap: '4px' } }, |
| 50 |
el(MediaUploadCheck, {}, |
| 51 |
el(MediaUpload, { |
| 52 |
onSelect: function (media) { set({ logos: a.logos.map(function (l, i) { return i === idx ? Object.assign({}, l, { imageUrl: media.url, imageId: media.id }) : l; }) }); }, |
| 53 |
allowedTypes: ['image'], |
| 54 |
value: logo.imageId, |
| 55 |
render: function (ref) { |
| 56 |
return logo.imageUrl |
| 57 |
? el('img', { src: logo.imageUrl, alt: logo.name, onClick: ref.open, style: { height: a.logoHeight + 'px', objectFit: 'contain', cursor: 'pointer', filter: a.grayscale ? 'grayscale(' + a.grayscaleAmount + '%)' : 'none', opacity: 0.7 } }) |
| 58 |
: el('div', { |
| 59 |
onClick: ref.open, |
| 60 |
style: { height: a.logoHeight + 'px', padding: '0 16px', background: '#f3f4f6', border: '1px dashed #d1d5db', borderRadius: '6px', cursor: 'pointer', display: 'flex', alignItems: 'center', justifyContent: 'center', color: '#9ca3af', fontSize: '13px', fontWeight: '600', whiteSpace: 'nowrap' } |
| 61 |
}, logo.name || 'Logo ' + (idx + 1)) |
| 62 |
} |
| 63 |
}) |
| 64 |
), |
| 65 |
el(TextControl, { value: logo.name, placeholder: 'Publication name', onChange: function (v) { updateLogo(idx, 'name', v); }, style: { width: '100px', textAlign: 'center', fontSize: '11px' }, __nextHasNoMarginBottom: true }), |
| 66 |
el(Button, { isDestructive: true, isSmall: true, onClick: function () { set({ logos: a.logos.filter(function (_, i) { return i !== idx; }) }); } }, '✕') |
| 67 |
) }), |
| 68 |
el(Button, { isSecondary: true, isSmall: true, onClick: function () { set({ logos: a.logos.concat([{ name: 'Publication', imageUrl: '', imageId: 0, url: '#' }]) }); } }, '+ Add logo') |
| 69 |
); |
| 70 |
|
| 71 |
/* --- Featured quote --- */ |
| 72 |
var featuredQuoteEl = a.showFeaturedQuote && el('div', { |
| 73 |
style: { background: a.quoteBg, borderRadius: '12px', padding: '28px 32px', maxWidth: '720px', margin: '0 auto', borderLeft: '4px solid ' + a.quoteAccent } |
| 74 |
}, |
| 75 |
el(RichText, { tagName: 'p', className: 'bkbg-mdc-quote-text', value: a.featuredQuote, style: { color: a.quoteColor, margin: '0 0 12px' }, onChange: function (v) { set({ featuredQuote: v }); } }), |
| 76 |
el('span', { className: 'bkbg-mdc-quote-attribution', style: { color: a.quoteAccent } }, |
| 77 |
el(RichText, { tagName: 'span', value: '— ' + a.featuredPublication, onChange: function (v) { set({ featuredPublication: v.replace('— ', '') }); } }) |
| 78 |
) |
| 79 |
); |
| 80 |
|
| 81 |
var controls = el(InspectorControls, {}, |
| 82 |
el(PanelBody, { title: __('Layout', 'blockenberg'), initialOpen: true }, |
| 83 |
el(SelectControl, { label: __('Layout', 'blockenberg'), value: a.layout, options: [{ label: 'Logos only', value: 'logos-only' }, { label: 'Logos + Quote', value: 'logos-quote' }, { label: 'Quote above logos', value: 'quote-logos' }], onChange: function (v) { set({ layout: v }); }, __nextHasNoMarginBottom: true }), |
| 84 |
el(ToggleControl, { label: __('Show Eyebrow', 'blockenberg'), checked: a.showEyebrow, onChange: function (v) { set({ showEyebrow: v }); }, __nextHasNoMarginBottom: true }), |
| 85 |
el(ToggleControl, { label: __('Show Heading', 'blockenberg'), checked: a.showHeading, onChange: function (v) { set({ showHeading: v }); }, __nextHasNoMarginBottom: true }), |
| 86 |
el(ToggleControl, { label: __('Enable Grayscale', 'blockenberg'), checked: a.grayscale, onChange: function (v) { set({ grayscale: v }); }, __nextHasNoMarginBottom: true }), |
| 87 |
a.grayscale && el(RangeControl, { label: __('Grayscale Amount (%)', 'blockenberg'), value: a.grayscaleAmount, min: 0, max: 100, onChange: function (v) { set({ grayscaleAmount: v }); }, __nextHasNoMarginBottom: true }), |
| 88 |
el(RangeControl, { label: __('Logo Height (px)', 'blockenberg'), value: a.logoHeight, min: 20, max: 80, onChange: function (v) { set({ logoHeight: v }); }, __nextHasNoMarginBottom: true }), |
| 89 |
el(RangeControl, { label: __('Logo Gap (px)', 'blockenberg'), value: a.logoGap, min: 16, max: 96, onChange: function (v) { set({ logoGap: v }); }, __nextHasNoMarginBottom: true }), |
| 90 |
el(ToggleControl, { label: __('Show Featured Quote', 'blockenberg'), checked: a.showFeaturedQuote, onChange: function (v) { set({ showFeaturedQuote: v }); }, __nextHasNoMarginBottom: true }), |
| 91 |
a.showFeaturedQuote && el(TextControl, { label: __('Featured Publication Name', 'blockenberg'), value: a.featuredPublication, onChange: function (v) { set({ featuredPublication: v }); }, __nextHasNoMarginBottom: true }), |
| 92 |
a.showFeaturedQuote && el(TextControl, { label: __('Quote Link URL', 'blockenberg'), value: a.featuredLink, onChange: function (v) { set({ featuredLink: v }); }, __nextHasNoMarginBottom: true }), |
| 93 |
el(RangeControl, { label: __('Max Width (px)', 'blockenberg'), value: a.maxWidth, min: 600, max: 1400, onChange: function (v) { set({ maxWidth: v }); }, __nextHasNoMarginBottom: true }), |
| 94 |
el(RangeControl, { label: __('Padding Top', 'blockenberg'), value: a.paddingTop, min: 0, max: 160, onChange: function (v) { set({ paddingTop: v }); }, __nextHasNoMarginBottom: true }), |
| 95 |
el(RangeControl, { label: __('Padding Bottom', 'blockenberg'), value: a.paddingBottom, min: 0, max: 160, onChange: function (v) { set({ paddingBottom: v }); }, __nextHasNoMarginBottom: true }) |
| 96 |
), |
| 97 |
el(PanelBody, { title: __('Logo Links', 'blockenberg'), initialOpen: false }, |
| 98 |
a.logos.map(function (logo, idx) { |
| 99 |
return el('div', { key: idx, style: { marginBottom: '8px' } }, |
| 100 |
el(TextControl, { label: (logo.name || 'Logo ' + (idx + 1)) + ' URL', value: logo.url || '', onChange: function (v) { updateLogo(idx, 'url', v); }, __nextHasNoMarginBottom: true }) |
| 101 |
) }) |
| 102 |
), |
| 103 |
el(PanelColorSettings, { |
| 104 |
title: __('Colors', 'blockenberg'), initialOpen: false, |
| 105 |
colorSettings: [ |
| 106 |
{ label: __('Background', 'blockenberg'), value: a.bgColor, onChange: function (v) { set({ bgColor: v || '#ffffff' }); } }, |
| 107 |
{ label: __('Eyebrow', 'blockenberg'), value: a.eyebrowColor, onChange: function (v) { set({ eyebrowColor: v || '#9ca3af' }); } }, |
| 108 |
{ label: __('Quote BG', 'blockenberg'), value: a.quoteBg, onChange: function (v) { set({ quoteBg: v || '#f9fafb' }); } }, |
| 109 |
{ label: __('Quote Text', 'blockenberg'), value: a.quoteColor, onChange: function (v) { set({ quoteColor: v || '#374151' }); } }, |
| 110 |
{ label: __('Quote Accent', 'blockenberg'), value: a.quoteAccent, onChange: function (v) { set({ quoteAccent: v || '#7c3aed' }); } }, |
| 111 |
{ label: __('Divider', 'blockenberg'), value: a.dividerColor, onChange: function (v) { set({ dividerColor: v || '#e5e7eb' }); } } |
| 112 |
] |
| 113 |
}), |
| 114 |
el(PanelBody, { title: __('Typography', 'blockenberg'), initialOpen: false }, |
| 115 |
getTypoControl() && el(getTypoControl(), { label: 'Eyebrow', value: a.eyebrowTypo || {}, onChange: function (v) { set({ eyebrowTypo: v }); } }), |
| 116 |
getTypoControl() && el(getTypoControl(), { label: 'Heading', value: a.headingTypo || {}, onChange: function (v) { set({ headingTypo: v }); } }), |
| 117 |
getTypoControl() && el(getTypoControl(), { label: 'Quote', value: a.quoteTypo || {}, onChange: function (v) { set({ quoteTypo: v }); } }) |
| 118 |
) |
| 119 |
); |
| 120 |
|
| 121 |
var showQuote = a.showFeaturedQuote && a.layout !== 'logos-only'; |
| 122 |
var quoteAbove = a.layout === 'quote-logos'; |
| 123 |
|
| 124 |
return el('div', blockProps, |
| 125 |
controls, |
| 126 |
el('div', { style: { background: a.bgColor, paddingTop: a.paddingTop + 'px', paddingBottom: a.paddingBottom + 'px' } }, |
| 127 |
el('div', { style: { maxWidth: a.maxWidth + 'px', margin: '0 auto', padding: '0 24px' } }, |
| 128 |
a.showEyebrow && el('p', { className: 'bkbg-mdc-eyebrow', style: { textAlign: 'center', color: a.eyebrowColor, marginBottom: a.showHeading ? '8px' : '28px' } }, |
| 129 |
el(RichText, { tagName: 'span', value: a.eyebrow, onChange: function (v) { set({ eyebrow: v }); } }) |
| 130 |
), |
| 131 |
a.showHeading && el(RichText, { tagName: 'p', className: 'bkbg-mdc-heading', value: a.heading, style: { textAlign: 'center', color: a.headingColor || '#374151', marginBottom: '28px' }, onChange: function (v) { set({ heading: v }); } }), |
| 132 |
quoteAbove && showQuote && featuredQuoteEl, |
| 133 |
quoteAbove && showQuote && el('div', { style: { height: '32px' } }), |
| 134 |
logosEl, |
| 135 |
!quoteAbove && showQuote && featuredQuoteEl |
| 136 |
) |
| 137 |
) |
| 138 |
); |
| 139 |
}, |
| 140 |
|
| 141 |
save: function (props) { |
| 142 |
var a = props.attributes; |
| 143 |
return el('div', wp.blockEditor.useBlockProps.save((function () { |
| 144 |
var tv = getTypoCssVars(); |
| 145 |
var s = {}; |
| 146 |
Object.assign(s, tv(a.eyebrowTypo, '--bkbg-mdc-ey-')); |
| 147 |
Object.assign(s, tv(a.headingTypo, '--bkbg-mdc-hd-')); |
| 148 |
Object.assign(s, tv(a.quoteTypo, '--bkbg-mdc-qt-')); |
| 149 |
return { style: s }; |
| 150 |
})()), |
| 151 |
el('div', { className: 'bkbg-mdc-app', 'data-opts': JSON.stringify(a) }) |
| 152 |
); |
| 153 |
} |
| 154 |
}); |
| 155 |
}() ); |
| 156 |
|