| 1 |
( function () { |
| 2 |
var el = wp.element.createElement; |
| 3 |
var Fragment = wp.element.Fragment; |
| 4 |
var __ = wp.i18n.__; |
| 5 |
var registerBlockType = wp.blocks.registerBlockType; |
| 6 |
var InspectorControls = wp.blockEditor.InspectorControls; |
| 7 |
var MediaUpload = wp.blockEditor.MediaUpload; |
| 8 |
var MediaUploadCheck = wp.blockEditor.MediaUploadCheck; |
| 9 |
var useBlockProps = wp.blockEditor.useBlockProps; |
| 10 |
var RichText = wp.blockEditor.RichText; |
| 11 |
var PanelBody = wp.components.PanelBody; |
| 12 |
var PanelColorSettings = wp.blockEditor.PanelColorSettings; |
| 13 |
var ToggleControl = wp.components.ToggleControl; |
| 14 |
var RangeControl = wp.components.RangeControl; |
| 15 |
var SelectControl = wp.components.SelectControl; |
| 16 |
var TextControl = wp.components.TextControl; |
| 17 |
var Button = wp.components.Button; |
| 18 |
|
| 19 |
var _tc; function getTypoControl() { return _tc || (_tc = window.bkbgTypographyControl); } |
| 20 |
var _tv; function getTypoCssVars() { return _tv || (_tv = window.bkbgTypoCssVars); } |
| 21 |
|
| 22 |
registerBlockType('blockenberg/spotlight-reveal', { |
| 23 |
edit: function (props) { |
| 24 |
var attr = props.attributes; |
| 25 |
var setAttr = props.setAttributes; |
| 26 |
var blockProps = useBlockProps({ className: 'bkbg-sr-editor' }); |
| 27 |
|
| 28 |
var overlayRgba = (function () { |
| 29 |
var hex = attr.overlayColor.replace('#', ''); |
| 30 |
if (hex.length === 3) { hex = hex[0]+hex[0]+hex[1]+hex[1]+hex[2]+hex[2]; } |
| 31 |
var r = parseInt(hex.substr(0,2),16); |
| 32 |
var g = parseInt(hex.substr(2,2),16); |
| 33 |
var b = parseInt(hex.substr(4,2),16); |
| 34 |
return 'rgba(' + r + ',' + g + ',' + b + ',' + (attr.overlayOpacity / 100) + ')'; |
| 35 |
})(); |
| 36 |
|
| 37 |
var wrapStyle = (function () { |
| 38 |
var tv = getTypoCssVars(); |
| 39 |
var s = { |
| 40 |
position: 'relative', |
| 41 |
overflow: 'hidden', |
| 42 |
background: attr.bgImageUrl |
| 43 |
? 'url(' + attr.bgImageUrl + ') center/cover no-repeat' |
| 44 |
: attr.revealColor, |
| 45 |
paddingTop: attr.paddingTop + 'px', |
| 46 |
paddingBottom: attr.paddingBottom + 'px', |
| 47 |
'--bksr-hd-sz': attr.headingSize + 'px', |
| 48 |
'--bksr-hd-w': String(attr.headingFontWeight || '700'), |
| 49 |
'--bksr-hd-lh': String(attr.headingLineHeight || 1.2), |
| 50 |
'--bksr-tx-sz': attr.textSize + 'px', |
| 51 |
'--bksr-tx-lh': String(attr.textLineHeight || 1.6), |
| 52 |
'--bksr-ey-sz': attr.eyebrowSize + 'px', |
| 53 |
}; |
| 54 |
Object.assign(s, tv(attr.headingTypo, '--bksr-hd-')); |
| 55 |
Object.assign(s, tv(attr.textTypo, '--bksr-tx-')); |
| 56 |
Object.assign(s, tv(attr.eyebrowTypo, '--bksr-ey-')); |
| 57 |
Object.assign(s, tv(attr.ctaTypo, '--bksr-ct-')); |
| 58 |
return s; |
| 59 |
})(); |
| 60 |
var overlayStyle = { |
| 61 |
position: 'absolute', inset: 0, |
| 62 |
background: overlayRgba, |
| 63 |
pointerEvents: 'none' |
| 64 |
}; |
| 65 |
var innerStyle = { |
| 66 |
position: 'relative', |
| 67 |
zIndex: 2, |
| 68 |
maxWidth: attr.maxWidth + 'px', |
| 69 |
margin: '0 auto', |
| 70 |
textAlign: 'center', |
| 71 |
padding: '0 24px' |
| 72 |
}; |
| 73 |
|
| 74 |
return el(Fragment, null, |
| 75 |
el(InspectorControls, null, |
| 76 |
el(PanelBody, { title: __('Content', 'blockenberg'), initialOpen: true }, |
| 77 |
el(ToggleControl, { label: __('Show Eyebrow', 'blockenberg'), __nextHasNoMarginBottom: true, checked: attr.showEyebrow, onChange: function (v) { setAttr({ showEyebrow: v }); } }), |
| 78 |
el(ToggleControl, { label: __('Show CTA Button', 'blockenberg'), __nextHasNoMarginBottom: true, checked: attr.showCta, onChange: function (v) { setAttr({ showCta: v }); } }), |
| 79 |
attr.showCta && el(TextControl, { label: __('CTA Label', 'blockenberg'), __nextHasNoMarginBottom: true, value: attr.ctaLabel, onChange: function (v) { setAttr({ ctaLabel: v }); } }), |
| 80 |
attr.showCta && el(TextControl, { label: __('CTA URL', 'blockenberg'), __nextHasNoMarginBottom: true, value: attr.ctaUrl, onChange: function (v) { setAttr({ ctaUrl: v }); } }) |
| 81 |
), |
| 82 |
el(PanelBody, { title: __('Background Image', 'blockenberg'), initialOpen: false }, |
| 83 |
el(MediaUploadCheck, null, |
| 84 |
el(MediaUpload, { |
| 85 |
onSelect: function (m) { setAttr({ bgImageUrl: m.url, bgImageId: m.id }); }, |
| 86 |
allowedTypes: ['image'], value: attr.bgImageId, |
| 87 |
render: function (r) { |
| 88 |
return el(Fragment, null, |
| 89 |
attr.bgImageUrl && el('img', { src: attr.bgImageUrl, style: { width: '100%', height: 80, objectFit: 'cover', borderRadius: 4, marginBottom: 8 } }), |
| 90 |
el(Button, { onClick: r.open, variant: 'secondary', __nextHasNoMarginBottom: true }, attr.bgImageUrl ? __('Change Image', 'blockenberg') : __('Select Background', 'blockenberg')), |
| 91 |
attr.bgImageUrl && el(Button, { onClick: function () { setAttr({ bgImageUrl: '', bgImageId: 0 }); }, variant: 'link', isDestructive: true, __nextHasNoMarginBottom: true }, __('Remove', 'blockenberg')) |
| 92 |
); |
| 93 |
} |
| 94 |
}) |
| 95 |
) |
| 96 |
), |
| 97 |
el(PanelBody, { title: __('Spotlight', 'blockenberg'), initialOpen: false }, |
| 98 |
el(SelectControl, { label: __('Trigger Mode', 'blockenberg'), __nextHasNoMarginBottom: true, value: attr.triggerMode, |
| 99 |
options: [{ label: __('Cursor follow', 'blockenberg'), value: 'cursor' }, { label: __('Scan animation', 'blockenberg'), value: 'scan' }], |
| 100 |
onChange: function (v) { setAttr({ triggerMode: v }); } }), |
| 101 |
el(RangeControl, { label: __('Spotlight Size (px)', 'blockenberg'), __nextHasNoMarginBottom: true, value: attr.spotlightSize, min: 100, max: 800, onChange: function (v) { setAttr({ spotlightSize: v }); } }), |
| 102 |
el(RangeControl, { label: __('Softness (%)', 'blockenberg'), __nextHasNoMarginBottom: true, value: attr.spotlightSoft, min: 0, max: 100, onChange: function (v) { setAttr({ spotlightSoft: v }); } }), |
| 103 |
el(RangeControl, { label: __('Overlay Opacity (%)', 'blockenberg'), __nextHasNoMarginBottom: true, value: attr.overlayOpacity, min: 10, max: 100, onChange: function (v) { setAttr({ overlayOpacity: v }); } }) |
| 104 |
), |
| 105 |
el(PanelBody, { title: __('Sizing', 'blockenberg'), initialOpen: false }, |
| 106 |
el(RangeControl, { label: __('Max Width (px)', 'blockenberg'), __nextHasNoMarginBottom: true, value: attr.maxWidth, min: 400, max: 1400, step: 10, onChange: function (v) { setAttr({ maxWidth: v }); } }), |
| 107 |
el(RangeControl, { label: __('Padding Top (px)', 'blockenberg'), __nextHasNoMarginBottom: true, value: attr.paddingTop, min: 0, max: 300, onChange: function (v) { setAttr({ paddingTop: v }); } }), |
| 108 |
el(RangeControl, { label: __('Padding Bottom (px)', 'blockenberg'), __nextHasNoMarginBottom: true, value: attr.paddingBottom, min: 0, max: 300, onChange: function (v) { setAttr({ paddingBottom: v }); } }) |
| 109 |
), |
| 110 |
|
| 111 |
el( PanelBody, { title: __( 'Typography', 'blockenberg' ), initialOpen: false }, |
| 112 |
getTypoControl()({ label: __('Heading', 'blockenberg'), value: attr.headingTypo, onChange: function (v) { setAttr({ headingTypo: v }); } }), |
| 113 |
getTypoControl()({ label: __('Subtext', 'blockenberg'), value: attr.textTypo, onChange: function (v) { setAttr({ textTypo: v }); } }), |
| 114 |
getTypoControl()({ label: __('Eyebrow', 'blockenberg'), value: attr.eyebrowTypo, onChange: function (v) { setAttr({ eyebrowTypo: v }); } }), |
| 115 |
getTypoControl()({ label: __('CTA Button', 'blockenberg'), value: attr.ctaTypo, onChange: function (v) { setAttr({ ctaTypo: v }); } }) |
| 116 |
), |
| 117 |
el(PanelColorSettings, { |
| 118 |
title: __('Colors', 'blockenberg'), initialOpen: false, |
| 119 |
colorSettings: [ |
| 120 |
{ value: attr.overlayColor, onChange: function (v) { setAttr({ overlayColor: v || '#000000' }); }, label: __('Overlay Color', 'blockenberg') }, |
| 121 |
{ value: attr.revealColor, onChange: function (v) { setAttr({ revealColor: v || '#7c3aed' }); }, label: __('Reveal/BG Color', 'blockenberg') }, |
| 122 |
{ value: attr.headingColor, onChange: function (v) { setAttr({ headingColor: v || '#ffffff' }); }, label: __('Heading', 'blockenberg') }, |
| 123 |
{ value: attr.subtextColor, onChange: function (v) { setAttr({ subtextColor: v || '#e5e7eb' }); }, label: __('Subtext', 'blockenberg') }, |
| 124 |
{ value: attr.eyebrowColor, onChange: function (v) { setAttr({ eyebrowColor: v || '#a78bfa' }); }, label: __('Eyebrow', 'blockenberg') }, |
| 125 |
{ value: attr.ctaBg, onChange: function (v) { setAttr({ ctaBg: v || '#7c3aed' }); }, label: __('Button BG', 'blockenberg') }, |
| 126 |
{ value: attr.ctaColor, onChange: function (v) { setAttr({ ctaColor: v || '#ffffff' }); }, label: __('Button Text', 'blockenberg') } |
| 127 |
] |
| 128 |
}) |
| 129 |
), |
| 130 |
el('div', blockProps, |
| 131 |
el('div', { style: wrapStyle }, |
| 132 |
el('div', { style: overlayStyle }), |
| 133 |
el('div', { style: innerStyle }, |
| 134 |
attr.showEyebrow && el(RichText, { tagName: 'span', value: attr.eyebrow, onChange: function (v) { setAttr({ eyebrow: v }); }, |
| 135 |
className: 'bkbg-sr-eyebrow', |
| 136 |
style: { color: attr.eyebrowColor, marginBottom: 16 }, |
| 137 |
placeholder: 'Eyebrow…' }), |
| 138 |
el('br'), |
| 139 |
el(RichText, { tagName: 'h2', value: attr.heading, onChange: function (v) { setAttr({ heading: v }); }, |
| 140 |
className: 'bkbg-sr-heading', |
| 141 |
style: { color: attr.headingColor, margin: '0 0 20px' }, |
| 142 |
placeholder: __('Section heading…', 'blockenberg') }), |
| 143 |
el(RichText, { tagName: 'p', value: attr.subtext, onChange: function (v) { setAttr({ subtext: v }); }, |
| 144 |
className: 'bkbg-sr-text', |
| 145 |
style: { color: attr.subtextColor, margin: '0 0 32px' }, |
| 146 |
placeholder: __('Subtext…', 'blockenberg') }), |
| 147 |
attr.showCta && el('a', { |
| 148 |
href: '#', onClick: function (e) { e.preventDefault(); }, |
| 149 |
className: 'bkbg-sr-btn', |
| 150 |
style: { background: attr.ctaBg, color: attr.ctaColor } |
| 151 |
}, attr.ctaLabel) |
| 152 |
), |
| 153 |
el('div', { style: { textAlign: 'center', marginTop: 24, position: 'relative', zIndex: 2 } }, |
| 154 |
el('span', { style: { display: 'inline-block', background: 'rgba(255,255,255,0.15)', color: '#fff', borderRadius: 20, padding: '6px 16px', fontSize: 12, backdropFilter: 'blur(4px)' } }, |
| 155 |
'🔦 ' + __('Cursor spotlight active on frontend', 'blockenberg')) |
| 156 |
) |
| 157 |
) |
| 158 |
) |
| 159 |
); |
| 160 |
}, |
| 161 |
save: function (props) { |
| 162 |
var attr = props.attributes; |
| 163 |
return el('div', useBlockProps.save(), |
| 164 |
el('div', { className: 'bkbg-spotlight-reveal-app', 'data-opts': JSON.stringify(attr) }) |
| 165 |
); |
| 166 |
} |
| 167 |
}); |
| 168 |
}() ); |
| 169 |
|