| 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 |
var MEDIA_ICONS = { video: '▶', audio: '🎙️', image: '🖼️' }; |
| 23 |
|
| 24 |
registerBlockType('blockenberg/media-quote', { |
| 25 |
edit: function (props) { |
| 26 |
var attr = props.attributes; |
| 27 |
var setAttr = props.setAttributes; |
| 28 |
var v = getTypoCssVars() || function () { return {}; }; |
| 29 |
var blockProps = (function(p){ |
| 30 |
p.style = Object.assign(p.style||{}, |
| 31 |
v(attr.quoteTypo,'--bkbg-mqu-qt-'), |
| 32 |
v(attr.speakerNameTypo,'--bkbg-mqu-sn-'), |
| 33 |
v(attr.speakerTitleTypo,'--bkbg-mqu-st-') |
| 34 |
); return p; |
| 35 |
})(useBlockProps({ className: 'bkbg-mqu-editor' })); |
| 36 |
|
| 37 |
var isTop = attr.layout === 'media-top'; |
| 38 |
var isRight = attr.layout === 'media-right'; |
| 39 |
var isOnly = attr.layout === 'quote-only'; |
| 40 |
|
| 41 |
/* media panel */ |
| 42 |
var mediaPanel = !isOnly && attr.showVideo && el('div', { className: 'bkbg-mqu-media-col', style: { flex: '0 0 45%', position: 'relative' } }, |
| 43 |
el(MediaUploadCheck, {}, |
| 44 |
el(MediaUpload, { |
| 45 |
onSelect: function (m) { setAttr({ thumbnailUrl: m.url, thumbnailId: m.id }); }, |
| 46 |
allowedTypes: ['image'], value: attr.thumbnailId, |
| 47 |
render: function (ref) { |
| 48 |
return el('div', { style: { position: 'relative', cursor: 'pointer' }, onClick: attr.thumbnailUrl ? undefined : ref.open }, |
| 49 |
attr.thumbnailUrl |
| 50 |
? el('div', { style: { position: 'relative' } }, |
| 51 |
el('img', { |
| 52 |
src: attr.thumbnailUrl, |
| 53 |
style: { width: '100%', maxHeight: '280px', objectFit: 'cover', borderRadius: attr.mediaRadius + 'px', display: 'block' } |
| 54 |
}), |
| 55 |
/* play button overlay */ |
| 56 |
el('div', { |
| 57 |
style: { |
| 58 |
position: 'absolute', inset: 0, display: 'flex', alignItems: 'center', justifyContent: 'center' |
| 59 |
} |
| 60 |
}, el('div', { |
| 61 |
style: { |
| 62 |
width: '56px', height: '56px', borderRadius: '50%', background: attr.playBtnBg, |
| 63 |
display: 'flex', alignItems: 'center', justifyContent: 'center', |
| 64 |
fontSize: '22px', color: attr.playBtnColor, boxShadow: '0 4px 20px rgba(0,0,0,0.25)' |
| 65 |
} |
| 66 |
}, MEDIA_ICONS[attr.mediaType] || '▶')), |
| 67 |
el('div', { style: { display: 'flex', gap: '8px', marginTop: '8px' } }, |
| 68 |
el(Button, { isSmall: true, isSecondary: true, onClick: ref.open }, __('Replace', 'blockenberg')), |
| 69 |
el(Button, { isSmall: true, isDestructive: true, onClick: function () { setAttr({ thumbnailUrl: '', thumbnailId: 0 }); } }, '✕') |
| 70 |
) |
| 71 |
) |
| 72 |
: el('div', { |
| 73 |
style: { background: '#f3f4f6', borderRadius: attr.mediaRadius + 'px', height: '200px', display: 'flex', flexDirection: 'column', alignItems: 'center', justifyContent: 'center', gap: '8px', color: '#9ca3af', fontSize: '36px', cursor: 'pointer' } |
| 74 |
}, MEDIA_ICONS[attr.mediaType] || '▶', el('span', { style: { fontSize: '13px' } }, __('Click to add thumbnail', 'blockenberg'))) |
| 75 |
); |
| 76 |
} |
| 77 |
}) |
| 78 |
), |
| 79 |
attr.showMediaLabel && attr.mediaLabel && el(TextControl, { |
| 80 |
value: attr.mediaLabel, onChange: function (v) { setAttr({ mediaLabel: v }); }, |
| 81 |
style: { marginTop: '6px', fontSize: '13px' }, __nextHasNoMarginBottom: true |
| 82 |
}) |
| 83 |
); |
| 84 |
|
| 85 |
/* quote panel */ |
| 86 |
var quotePanel = el('div', { style: { flex: 1, display: 'flex', flexDirection: 'column', justifyContent: 'center', gap: '16px' } }, |
| 87 |
attr.showQuoteIcon && el('span', { style: { fontSize: '48px', color: attr.accentColor, lineHeight: 1, fontFamily: 'Georgia, serif', marginBottom: '-8px', display: 'block' } }, '\u201c'), |
| 88 |
el(RichText, { |
| 89 |
tagName: 'blockquote', className: 'bkbg-mqu-blockquote', value: attr.quote, |
| 90 |
style: { color: attr.quoteColor, margin: 0, padding: 0, border: 'none' }, |
| 91 |
onChange: function (v) { setAttr({ quote: v }); } |
| 92 |
}), |
| 93 |
el('div', { style: { display: 'flex', alignItems: 'center', gap: '12px', marginTop: '4px' } }, |
| 94 |
el(MediaUploadCheck, {}, |
| 95 |
el(MediaUpload, { |
| 96 |
onSelect: function (m) { setAttr({ speakerAvatarUrl: m.url, speakerAvatarId: m.id }); }, |
| 97 |
allowedTypes: ['image'], value: attr.speakerAvatarId, |
| 98 |
render: function (ref) { |
| 99 |
return el('div', { onClick: ref.open, style: { cursor: 'pointer' } }, |
| 100 |
attr.speakerAvatarUrl |
| 101 |
? el('img', { src: attr.speakerAvatarUrl, style: { width: '44px', height: '44px', borderRadius: '50%', objectFit: 'cover', border: '2px solid ' + attr.borderColor } }) |
| 102 |
: el('div', { style: { width: '44px', height: '44px', borderRadius: '50%', background: '#e5e7eb', display: 'flex', alignItems: 'center', justifyContent: 'center', fontSize: '20px' } }, '👤') |
| 103 |
); |
| 104 |
} |
| 105 |
}) |
| 106 |
), |
| 107 |
el('div', {}, |
| 108 |
el(RichText, { |
| 109 |
tagName: 'p', className: 'bkbg-mqu-speaker-name', value: attr.speakerName, |
| 110 |
style: { margin: 0, color: attr.quoteColor }, |
| 111 |
onChange: function (v) { setAttr({ speakerName: v }); } |
| 112 |
}), |
| 113 |
el(RichText, { |
| 114 |
tagName: 'p', className: 'bkbg-mqu-speaker-title', value: attr.speakerTitle, |
| 115 |
style: { margin: 0, color: attr.speakerColor }, |
| 116 |
onChange: function (v) { setAttr({ speakerTitle: v }); } |
| 117 |
}) |
| 118 |
) |
| 119 |
) |
| 120 |
); |
| 121 |
|
| 122 |
var innerFlex = { |
| 123 |
display: 'flex', |
| 124 |
flexDirection: isTop ? 'column' : (isRight ? 'row-reverse' : 'row'), |
| 125 |
gap: '32px', alignItems: 'center' |
| 126 |
}; |
| 127 |
if (isOnly) innerFlex = { display: 'block' }; |
| 128 |
|
| 129 |
var cardStyle = {}; |
| 130 |
if (attr.style === 'card') { cardStyle = { background: attr.cardBg, borderRadius: attr.borderRadius + 'px', padding: '32px', boxShadow: '0 2px 20px rgba(0,0,0,0.07)' }; } |
| 131 |
if (attr.style === 'bordered') { cardStyle = { border: '2px solid ' + attr.borderColor, borderRadius: attr.borderRadius + 'px', padding: '32px' }; } |
| 132 |
if (attr.style === 'minimal') { cardStyle = { borderLeft: '4px solid ' + attr.accentColor, paddingLeft: '24px' }; } |
| 133 |
|
| 134 |
var controls = el(InspectorControls, {}, |
| 135 |
el(PanelBody, { title: __('Media', 'blockenberg'), initialOpen: true }, |
| 136 |
el(ToggleControl, { label: __('Show Media Panel', 'blockenberg'), checked: attr.showVideo, onChange: function (v) { setAttr({ showVideo: v }); }, __nextHasNoMarginBottom: true }), |
| 137 |
attr.showVideo && el(SelectControl, { |
| 138 |
label: __('Media Type', 'blockenberg'), value: attr.mediaType, |
| 139 |
options: [{ label: '▶ Video', value: 'video' }, { label: '🎙️ Podcast/Audio', value: 'audio' }, { label: '🖼️ Image', value: 'image' }], |
| 140 |
onChange: function (v) { setAttr({ mediaType: v }); }, __nextHasNoMarginBottom: true |
| 141 |
}), |
| 142 |
attr.showVideo && el(TextControl, { label: __('Video URL (for link)', 'blockenberg'), value: attr.videoUrl, onChange: function (v) { setAttr({ videoUrl: v }); }, __nextHasNoMarginBottom: true }), |
| 143 |
attr.showVideo && el(ToggleControl, { label: __('Show Media Label', 'blockenberg'), checked: attr.showMediaLabel, onChange: function (v) { setAttr({ showMediaLabel: v }); }, __nextHasNoMarginBottom: true }), |
| 144 |
attr.showVideo && attr.showMediaLabel && el(TextControl, { label: __('Media Label', 'blockenberg'), value: attr.mediaLabel, onChange: function (v) { setAttr({ mediaLabel: v }); }, __nextHasNoMarginBottom: true }), |
| 145 |
attr.showVideo && el(RangeControl, { label: __('Thumbnail Radius (px)', 'blockenberg'), value: attr.mediaRadius, min: 0, max: 32, onChange: function (v) { setAttr({ mediaRadius: v }); }, __nextHasNoMarginBottom: true }) |
| 146 |
), |
| 147 |
el(PanelBody, { title: __('Layout & Style', 'blockenberg'), initialOpen: false }, |
| 148 |
el(SelectControl, { |
| 149 |
label: __('Layout', 'blockenberg'), value: attr.layout, |
| 150 |
options: [ |
| 151 |
{ label: 'Media left, quote right', value: 'media-left' }, |
| 152 |
{ label: 'Media right, quote left', value: 'media-right' }, |
| 153 |
{ label: 'Media top, quote below', value: 'media-top' }, |
| 154 |
{ label: 'Quote only (no media)', value: 'quote-only' } |
| 155 |
], |
| 156 |
onChange: function (v) { setAttr({ layout: v }); }, __nextHasNoMarginBottom: true |
| 157 |
}), |
| 158 |
el(SelectControl, { |
| 159 |
label: __('Card Style', 'blockenberg'), value: attr.style, |
| 160 |
options: [{ label: 'Card (shadow bg)', value: 'card' }, { label: 'Bordered', value: 'bordered' }, { label: 'Minimal (accent bar)', value: 'minimal' }, { label: 'Flat', value: 'flat' }], |
| 161 |
onChange: function (v) { setAttr({ style: v }); }, __nextHasNoMarginBottom: true |
| 162 |
}), |
| 163 |
el(ToggleControl, { label: __('Show Opening Quote Mark', 'blockenberg'), checked: attr.showQuoteIcon, onChange: function (v) { setAttr({ showQuoteIcon: v }); }, __nextHasNoMarginBottom: true }), |
| 164 |
el(RangeControl, { label: __('Card Border Radius (px)', 'blockenberg'), value: attr.borderRadius, min: 0, max: 32, onChange: function (v) { setAttr({ borderRadius: v }); }, __nextHasNoMarginBottom: true }), |
| 165 |
el(RangeControl, { label: __('Max Width (px)', 'blockenberg'), value: attr.maxWidth, min: 400, max: 1400, onChange: function (v) { setAttr({ maxWidth: v }); }, __nextHasNoMarginBottom: true }), |
| 166 |
el(RangeControl, { label: __('Padding Top (px)', 'blockenberg'), value: attr.paddingTop, min: 0, max: 160, onChange: function (v) { setAttr({ paddingTop: v }); }, __nextHasNoMarginBottom: true }), |
| 167 |
el(RangeControl, { label: __('Padding Bottom (px)', 'blockenberg'), value: attr.paddingBottom, min: 0, max: 160, onChange: function (v) { setAttr({ paddingBottom: v }); }, __nextHasNoMarginBottom: true }) |
| 168 |
), |
| 169 |
|
| 170 |
el( PanelBody, { title: __( 'Typography', 'blockenberg' ), initialOpen: false }, |
| 171 |
getTypoControl() && el(getTypoControl(), { label: __('Quote','blockenberg'), value: attr.quoteTypo || {}, onChange: function(v){ setAttr({ quoteTypo: v }); } }), |
| 172 |
getTypoControl() && el(getTypoControl(), { label: __('Speaker Name','blockenberg'), value: attr.speakerNameTypo || {}, onChange: function(v){ setAttr({ speakerNameTypo: v }); } }), |
| 173 |
getTypoControl() && el(getTypoControl(), { label: __('Speaker Title','blockenberg'), value: attr.speakerTitleTypo || {}, onChange: function(v){ setAttr({ speakerTitleTypo: v }); } }) |
| 174 |
), |
| 175 |
el(PanelColorSettings, { |
| 176 |
title: __('Colors', 'blockenberg'), initialOpen: false, |
| 177 |
colorSettings: [ |
| 178 |
{ label: __('Section BG', 'blockenberg'), value: attr.bgColor, onChange: function (v) { setAttr({ bgColor: v || '#ffffff' }); } }, |
| 179 |
{ label: __('Card BG', 'blockenberg'), value: attr.cardBg, onChange: function (v) { setAttr({ cardBg: v || '#f9fafb' }); } }, |
| 180 |
{ label: __('Accent / Border', 'blockenberg'), value: attr.accentColor, onChange: function (v) { setAttr({ accentColor: v || '#7c3aed' }); } }, |
| 181 |
{ label: __('Border', 'blockenberg'), value: attr.borderColor, onChange: function (v) { setAttr({ borderColor: v || '#e5e7eb' }); } }, |
| 182 |
{ label: __('Quote Text', 'blockenberg'), value: attr.quoteColor, onChange: function (v) { setAttr({ quoteColor: v || '#111827' }); } }, |
| 183 |
{ label: __('Speaker Meta', 'blockenberg'), value: attr.speakerColor, onChange: function (v) { setAttr({ speakerColor: v || '#374151' }); } }, |
| 184 |
{ label: __('Play Button BG', 'blockenberg'), value: attr.playBtnBg, onChange: function (v) { setAttr({ playBtnBg: v || '#ffffff' }); } }, |
| 185 |
{ label: __('Play Button Icon', 'blockenberg'), value: attr.playBtnColor, onChange: function (v) { setAttr({ playBtnColor: v || '#7c3aed' }); } } |
| 186 |
] |
| 187 |
}) |
| 188 |
); |
| 189 |
|
| 190 |
return el('div', blockProps, controls, |
| 191 |
el('div', { style: { background: attr.bgColor, paddingTop: attr.paddingTop + 'px', paddingBottom: attr.paddingBottom + 'px' } }, |
| 192 |
el('div', { style: Object.assign({ maxWidth: attr.maxWidth + 'px', margin: '0 auto' }, cardStyle) }, |
| 193 |
el('div', { style: innerFlex }, mediaPanel, quotePanel) |
| 194 |
) |
| 195 |
) |
| 196 |
); |
| 197 |
}, |
| 198 |
|
| 199 |
save: function (props) { |
| 200 |
var a = props.attributes; |
| 201 |
var v = (typeof window.bkbgTypoCssVars === 'function') ? window.bkbgTypoCssVars : function () { return {}; }; |
| 202 |
var s = Object.assign({}, |
| 203 |
v(a.quoteTypo,'--bkbg-mqu-qt-'), |
| 204 |
v(a.speakerNameTypo,'--bkbg-mqu-sn-'), |
| 205 |
v(a.speakerTitleTypo,'--bkbg-mqu-st-') |
| 206 |
); |
| 207 |
return el('div', (function(p){p.style=Object.assign(p.style||{},s);return p;})(wp.blockEditor.useBlockProps.save()), |
| 208 |
el('div', { className: 'bkbg-mqu-app', 'data-opts': JSON.stringify(a) }) |
| 209 |
); |
| 210 |
} |
| 211 |
}); |
| 212 |
}() ); |
| 213 |
|