| 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 |
var IP = function () { return window.bkbgIconPicker; }; |
| 20 |
|
| 21 |
function getTypographyControl() { |
| 22 |
return (window.bkbgTypographyControl || function () { return null; }); |
| 23 |
} |
| 24 |
|
| 25 |
registerBlockType('blockenberg/coming-soon', { |
| 26 |
edit: function (props) { |
| 27 |
var attr = props.attributes; |
| 28 |
var setAttr = props.setAttributes; |
| 29 |
var blockProps = useBlockProps({ className: 'bkbg-csn-editor' }); |
| 30 |
|
| 31 |
var bg = attr.bgGradient || attr.bgColor; |
| 32 |
var previewStyle = { background: bg, padding: attr.paddingTop + 'px 40px ' + attr.paddingBottom + 'px', textAlign: 'center' }; |
| 33 |
var innerStyle = { maxWidth: attr.maxWidth + 'px', margin: '0 auto', display: 'flex', flexDirection: 'column', alignItems: 'center', gap: 32 }; |
| 34 |
|
| 35 |
function updateSocial(i, key, val) { |
| 36 |
var next = attr.socialLinks.map(function (s, j) { return j === i ? Object.assign({}, s, { [key]: val }) : s; }); |
| 37 |
setAttr({ socialLinks: next }); |
| 38 |
} |
| 39 |
|
| 40 |
return el(Fragment, null, |
| 41 |
el(InspectorControls, null, |
| 42 |
el(PanelBody, { title: __('Content', 'blockenberg'), initialOpen: true }, |
| 43 |
el(ToggleControl, { label: __('Show Logo', 'blockenberg'), __nextHasNoMarginBottom: true, checked: attr.showLogo, onChange: function (v) { setAttr({ showLogo: v }); } }), |
| 44 |
attr.showLogo && el(Fragment, null, |
| 45 |
el(MediaUploadCheck, null, |
| 46 |
el(MediaUpload, { |
| 47 |
onSelect: function (m) { setAttr({ logoUrl: m.url, logoId: m.id, logoAlt: m.alt || '' }); }, |
| 48 |
allowedTypes: ['image'], value: attr.logoId, |
| 49 |
render: function (r) { |
| 50 |
return el(Fragment, null, |
| 51 |
attr.logoUrl && el('img', { src: attr.logoUrl, style: { maxWidth: 140, display: 'block', marginBottom: 8 } }), |
| 52 |
el(Button, { onClick: r.open, variant: 'secondary', __nextHasNoMarginBottom: true }, attr.logoUrl ? __('Change Logo', 'blockenberg') : __('Select Logo', 'blockenberg')), |
| 53 |
attr.logoUrl && el(Button, { onClick: function () { setAttr({ logoUrl: '', logoId: 0 }); }, variant: 'link', isDestructive: true, __nextHasNoMarginBottom: true, style: { marginLeft: 8 } }, __('Remove', 'blockenberg')) |
| 54 |
); |
| 55 |
} |
| 56 |
}) |
| 57 |
), |
| 58 |
el(RangeControl, { label: __('Logo Width (px)', 'blockenberg'), __nextHasNoMarginBottom: true, value: attr.logoWidth, min: 60, max: 300, onChange: function (v) { setAttr({ logoWidth: v }); } }) |
| 59 |
), |
| 60 |
el(ToggleControl, { label: __('Show Eyebrow', 'blockenberg'), __nextHasNoMarginBottom: true, checked: attr.showEyebrow, onChange: function (v) { setAttr({ showEyebrow: v }); } }), |
| 61 |
attr.showEyebrow && el(TextControl, { label: __('Eyebrow Text', 'blockenberg'), __nextHasNoMarginBottom: true, value: attr.eyebrow, onChange: function (v) { setAttr({ eyebrow: v }); } }), |
| 62 |
el(ToggleControl, { label: __('Show Countdown', 'blockenberg'), __nextHasNoMarginBottom: true, checked: attr.showCountdown, onChange: function (v) { setAttr({ showCountdown: v }); } }), |
| 63 |
attr.showCountdown && el(TextControl, { label: __('Launch Date (YYYY-MM-DD)', 'blockenberg'), __nextHasNoMarginBottom: true, value: attr.launchDate, placeholder: '2025-12-31', onChange: function (v) { setAttr({ launchDate: v }); } }), |
| 64 |
el(ToggleControl, { label: __('Show Email Form', 'blockenberg'), __nextHasNoMarginBottom: true, checked: attr.showEmail, onChange: function (v) { setAttr({ showEmail: v }); } }), |
| 65 |
attr.showEmail && el(TextControl, { label: __('Email Placeholder', 'blockenberg'), __nextHasNoMarginBottom: true, value: attr.emailPlaceholder, onChange: function (v) { setAttr({ emailPlaceholder: v }); } }), |
| 66 |
attr.showEmail && el(TextControl, { label: __('Button Label', 'blockenberg'), __nextHasNoMarginBottom: true, value: attr.emailBtnLabel, onChange: function (v) { setAttr({ emailBtnLabel: v }); } }), |
| 67 |
attr.showEmail && el(TextControl, { label: __('Form Action URL', 'blockenberg'), __nextHasNoMarginBottom: true, value: attr.emailAction, onChange: function (v) { setAttr({ emailAction: v }); } }) |
| 68 |
), |
| 69 |
el(PanelBody, { title: __('Social Links', 'blockenberg'), initialOpen: false }, |
| 70 |
el(ToggleControl, { label: __('Show Social Links', 'blockenberg'), __nextHasNoMarginBottom: true, checked: attr.showSocials, onChange: function (v) { setAttr({ showSocials: v }); } }), |
| 71 |
attr.showSocials && el(Fragment, null, |
| 72 |
attr.socialLinks.map(function (s, i) { |
| 73 |
return el('div', { key: i, style: { borderLeft: '3px solid #7c3aed', paddingLeft: 8, marginBottom: 12 } }, |
| 74 |
el(TextControl, { label: __('Platform', 'blockenberg'), __nextHasNoMarginBottom: true, value: s.platform, onChange: function (v) { updateSocial(i, 'platform', v); } }), |
| 75 |
el(TextControl, { label: __('URL', 'blockenberg'), __nextHasNoMarginBottom: true, value: s.url, onChange: function (v) { updateSocial(i, 'url', v); } }), |
| 76 |
el(IP().IconPickerControl, { |
| 77 |
iconType: s.iconType, customChar: s.icon, dashicon: s.iconDashicon, imageUrl: s.iconImageUrl, |
| 78 |
onChangeType: function (v) { updateSocial(i, 'iconType', v); }, |
| 79 |
onChangeChar: function (v) { updateSocial(i, 'icon', v); }, |
| 80 |
onChangeDashicon: function (v) { updateSocial(i, 'iconDashicon', v); }, |
| 81 |
onChangeImageUrl: function (v) { updateSocial(i, 'iconImageUrl', v); } |
| 82 |
}), |
| 83 |
attr.socialLinks.length > 1 && el(Button, { onClick: function () { setAttr({ socialLinks: attr.socialLinks.filter(function (_, j) { return j !== i; }) }); }, variant: 'link', isDestructive: true, __nextHasNoMarginBottom: true }, __('Remove', 'blockenberg')) |
| 84 |
); |
| 85 |
}), |
| 86 |
el(Button, { onClick: function () { setAttr({ socialLinks: attr.socialLinks.concat([{ platform: 'Social', url: '#', icon: '♦', iconType: 'custom-char', iconDashicon: '', iconImageUrl: '' }]) }); }, variant: 'secondary', __nextHasNoMarginBottom: true }, __('+ Add Link', 'blockenberg')) |
| 87 |
) |
| 88 |
), |
| 89 |
el(PanelBody, { title: __('Sizing', 'blockenberg'), initialOpen: false }, |
| 90 |
el(RangeControl, { label: __('Max Width (px)', 'blockenberg'), __nextHasNoMarginBottom: true, value: attr.maxWidth, min: 400, max: 1000, step: 10, onChange: function (v) { setAttr({ maxWidth: v }); } }), |
| 91 |
el(RangeControl, { label: __('Padding Top (px)', 'blockenberg'), __nextHasNoMarginBottom: true, value: attr.paddingTop, min: 0, max: 300, onChange: function (v) { setAttr({ paddingTop: v }); } }), |
| 92 |
el(RangeControl, { label: __('Padding Bottom (px)', 'blockenberg'), __nextHasNoMarginBottom: true, value: attr.paddingBottom, min: 0, max: 300, onChange: function (v) { setAttr({ paddingBottom: v }); } }) |
| 93 |
), |
| 94 |
|
| 95 |
el( PanelBody, { title: __( 'Typography', 'blockenberg' ), initialOpen: false }, |
| 96 |
(function () { |
| 97 |
var TC = getTypographyControl(); |
| 98 |
return el( Fragment, {}, |
| 99 |
el( TC, { label: __( 'Heading', 'blockenberg' ), value: attr.typoHeading || {}, onChange: function (v) { setAttr({ typoHeading: v }); } }), |
| 100 |
el( TC, { label: __( 'Body', 'blockenberg' ), value: attr.typoBody || {}, onChange: function (v) { setAttr({ typoBody: v }); } }), |
| 101 |
el( TC, { label: __( 'Eyebrow', 'blockenberg' ), value: attr.typoEyebrow || {}, onChange: function (v) { setAttr({ typoEyebrow: v }); } }) |
| 102 |
); |
| 103 |
})() |
| 104 |
), |
| 105 |
el(PanelColorSettings, { |
| 106 |
title: __('Colors', 'blockenberg'), initialOpen: false, |
| 107 |
colorSettings: [ |
| 108 |
{ value: attr.bgColor, onChange: function (v) { setAttr({ bgColor: v || '#0f172a' }); }, label: __('Background', 'blockenberg') }, |
| 109 |
{ value: attr.headingColor, onChange: function (v) { setAttr({ headingColor: v || '#ffffff' }); }, label: __('Heading', 'blockenberg') }, |
| 110 |
{ value: attr.textColor, onChange: function (v) { setAttr({ textColor: v || '#94a3b8' }); }, label: __('Body Text', 'blockenberg') }, |
| 111 |
{ value: attr.eyebrowBg, onChange: function (v) { setAttr({ eyebrowBg: v || 'rgba(255,255,255,.08)' }); }, label: __('Eyebrow BG', 'blockenberg') }, |
| 112 |
{ value: attr.eyebrowColor, onChange: function (v) { setAttr({ eyebrowColor: v || '#c4b5fd' }); }, label: __('Eyebrow Text', 'blockenberg') }, |
| 113 |
{ value: attr.timerBg, onChange: function (v) { setAttr({ timerBg: v || 'rgba(255,255,255,.07)' }); }, label: __('Timer Box BG', 'blockenberg') }, |
| 114 |
{ value: attr.timerColor, onChange: function (v) { setAttr({ timerColor: v || '#ffffff' }); }, label: __('Timer Number', 'blockenberg') }, |
| 115 |
{ value: attr.btnBg, onChange: function (v) { setAttr({ btnBg: v || '#7c3aed' }); }, label: __('Button Background', 'blockenberg') }, |
| 116 |
{ value: attr.btnColor, onChange: function (v) { setAttr({ btnColor: v || '#ffffff' }); }, label: __('Button Text', 'blockenberg') }, |
| 117 |
{ value: attr.accentColor, onChange: function (v) { setAttr({ accentColor: v || '#7c3aed' }); }, label: __('Accent', 'blockenberg') } |
| 118 |
] |
| 119 |
}) |
| 120 |
), |
| 121 |
el('div', blockProps, |
| 122 |
el('div', { style: previewStyle }, |
| 123 |
el('div', { style: innerStyle }, |
| 124 |
attr.showLogo && attr.logoUrl && el('img', { src: attr.logoUrl, alt: attr.logoAlt, style: { width: attr.logoWidth + 'px', display: 'block' } }), |
| 125 |
attr.showEyebrow && el('span', { className: 'bkbg-csn-eyebrow', style: { background: attr.eyebrowBg, color: attr.eyebrowColor } }, attr.eyebrow), |
| 126 |
el(RichText, { tagName: 'h1', className: 'bkbg-csn-heading', value: attr.heading, onChange: function (v) { setAttr({ heading: v }); }, style: { color: attr.headingColor, margin: 0 }, placeholder: __('Heading…', 'blockenberg') }), |
| 127 |
el(RichText, { tagName: 'p', className: 'bkbg-csn-body', value: attr.subtext, onChange: function (v) { setAttr({ subtext: v }); }, style: { color: attr.textColor, margin: 0, maxWidth: 560 }, placeholder: __('Subtitle…', 'blockenberg') }), |
| 128 |
attr.showCountdown && el('div', { style: { display: 'flex', gap: 16, justifyContent: 'center', flexWrap: 'wrap' } }, |
| 129 |
['Days', 'Hours', 'Mins', 'Secs'].map(function (unit) { |
| 130 |
return el('div', { key: unit, style: { background: attr.timerBg, borderRadius: 12, padding: '20px 28px', textAlign: 'center', minWidth: 80 } }, |
| 131 |
el('div', { style: { fontSize: 44, fontWeight: 800, color: attr.timerColor, lineHeight: 1 } }, unit === 'Days' ? '00' : unit === 'Hours' ? '00' : unit === 'Mins' ? '00' : '00'), |
| 132 |
el('div', { style: { fontSize: 12, color: attr.textColor, marginTop: 6, textTransform: 'uppercase', letterSpacing: '.08em' } }, unit) |
| 133 |
); |
| 134 |
}) |
| 135 |
), |
| 136 |
attr.showEmail && el('div', { style: { display: 'flex', gap: 12, flexWrap: 'wrap', justifyContent: 'center', width: '100%', maxWidth: 480 } }, |
| 137 |
el('input', { type: 'email', placeholder: attr.emailPlaceholder, readOnly: true, style: { flex: '1 1 220px', padding: '14px 20px', borderRadius: 8, border: '1px solid rgba(255,255,255,.15)', background: attr.inputBg, color: attr.inputColor, fontSize: 15 } }), |
| 138 |
el('button', { style: { flex: '0 0 auto', padding: '14px 28px', borderRadius: 8, background: attr.btnBg, color: attr.btnColor, fontWeight: 600, fontSize: 15, border: 'none', cursor: 'pointer' } }, attr.emailBtnLabel) |
| 139 |
), |
| 140 |
attr.showSocials && attr.socialLinks.length > 0 && el('div', { style: { display: 'flex', gap: 16, justifyContent: 'center', flexWrap: 'wrap' } }, |
| 141 |
attr.socialLinks.map(function (s, i) { |
| 142 |
return el('a', { key: i, href: '#', style: { display: 'inline-flex', alignItems: 'center', justifyContent: 'center', width: 44, height: 44, borderRadius: '50%', background: 'rgba(255,255,255,.1)', color: attr.textColor, fontSize: 18, textDecoration: 'none' } }, |
| 143 |
(s.iconType || 'custom-char') !== 'custom-char' ? IP().buildEditorIcon(s.iconType, s.icon, s.iconDashicon, s.iconImageUrl, s.iconDashiconColor) : s.icon |
| 144 |
); |
| 145 |
}) |
| 146 |
) |
| 147 |
) |
| 148 |
) |
| 149 |
) |
| 150 |
); |
| 151 |
}, |
| 152 |
save: function (props) { |
| 153 |
var attr = props.attributes; |
| 154 |
return el('div', useBlockProps.save(), |
| 155 |
el('div', { className: 'bkbg-coming-soon-app', 'data-opts': JSON.stringify(attr) }) |
| 156 |
); |
| 157 |
} |
| 158 |
}); |
| 159 |
}() ); |
| 160 |
|