| 1 |
(function () { |
| 2 |
var el = wp.element.createElement; |
| 3 |
var Fragment = wp.element.Fragment; |
| 4 |
var registerBlockType = wp.blocks.registerBlockType; |
| 5 |
var __ = wp.i18n.__; |
| 6 |
var InspectorControls = wp.blockEditor.InspectorControls; |
| 7 |
var PanelColorSettings = wp.blockEditor.PanelColorSettings; |
| 8 |
var useBlockProps = wp.blockEditor.useBlockProps; |
| 9 |
var MediaUpload = wp.blockEditor.MediaUpload; |
| 10 |
var MediaUploadCheck = wp.blockEditor.MediaUploadCheck; |
| 11 |
var PanelBody = wp.components.PanelBody; |
| 12 |
var RangeControl = wp.components.RangeControl; |
| 13 |
var ToggleControl = wp.components.ToggleControl; |
| 14 |
var TextControl = wp.components.TextControl; |
| 15 |
var TextareaControl = wp.components.TextareaControl; |
| 16 |
var SelectControl = wp.components.SelectControl; |
| 17 |
var Button = wp.components.Button; |
| 18 |
|
| 19 |
var _tc, _tv; |
| 20 |
function getTypoControl() { return _tc || (_tc = window.bkbgTypographyControl); } |
| 21 |
function getTypoCssVars() { return _tv || (_tv = window.bkbgTypoCssVars); } |
| 22 |
|
| 23 |
var BTN_STYLE_OPTIONS = [ |
| 24 |
{ label: 'Solid fill', value: 'solid' }, |
| 25 |
{ label: 'Outlined', value: 'outlined' }, |
| 26 |
{ label: 'Text link', value: 'link' }, |
| 27 |
]; |
| 28 |
|
| 29 |
function makeId() { return 'r' + Math.random().toString(36).substr(2, 6); } |
| 30 |
|
| 31 |
function renderBtnPreview(row, attrs) { |
| 32 |
if (!attrs.showButton || !row.btnLabel) return null; |
| 33 |
var s = attrs.btnStyle; |
| 34 |
var bg = s === 'solid' ? (row.accentColor || attrs.btnBg) : 'transparent'; |
| 35 |
var color = s === 'solid' ? '#ffffff' : (row.accentColor || attrs.btnBg); |
| 36 |
var border = s === 'outlined' ? ('2px solid ' + (row.accentColor || attrs.btnBg)) : 'none'; |
| 37 |
return el('span', { style: { display: 'inline-block', marginTop: '14px', padding: s === 'link' ? '0' : '9px 22px', background: bg, color: color, border: border, borderRadius: attrs.btnBorderRadius + 'px', fontSize: '14px', fontWeight: 600, textDecoration: s === 'link' ? 'underline' : 'none' } }, row.btnLabel); |
| 38 |
} |
| 39 |
|
| 40 |
registerBlockType('blockenberg/media-text', { |
| 41 |
edit: function (props) { |
| 42 |
var attributes = props.attributes; |
| 43 |
var setAttributes = props.setAttributes; |
| 44 |
var rows = attributes.rows; |
| 45 |
|
| 46 |
var blockProps = (function(p){ |
| 47 |
var vf = getTypoCssVars() || function () { return {}; }; |
| 48 |
p.style = Object.assign(p.style||{}, |
| 49 |
vf(attributes.eyebrowTypo,'--bkbg-mt-ey-'), |
| 50 |
vf(attributes.titleTypo,'--bkbg-mt-tt-'), |
| 51 |
vf(attributes.descTypo,'--bkbg-mt-ds-') |
| 52 |
); return p; |
| 53 |
})(useBlockProps({ |
| 54 |
style: { paddingTop: attributes.paddingTop + 'px', paddingBottom: attributes.paddingBottom + 'px', backgroundColor: attributes.bgColor || undefined } |
| 55 |
})); |
| 56 |
|
| 57 |
function setRow(id, patch) { |
| 58 |
setAttributes({ rows: rows.map(function (r) { return r.id === id ? Object.assign({}, r, patch) : r; }) }); |
| 59 |
} |
| 60 |
function addRow() { |
| 61 |
setAttributes({ rows: rows.concat([{ id: makeId(), eyebrow: 'New', title: 'New section', desc: 'Describe your feature here.', btnLabel: 'Learn more', btnUrl: '', btnNewTab: false, flipRow: rows.length % 2 !== 0, imageUrl: '', imageId: 0, imageAlt: '', accentColor: '#6c3fb5' }]) }); |
| 62 |
} |
| 63 |
function removeRow(id) { |
| 64 |
if (rows.length <= 1) return; |
| 65 |
setAttributes({ rows: rows.filter(function (r) { return r.id !== id; }) }); |
| 66 |
} |
| 67 |
|
| 68 |
return el(Fragment, null, |
| 69 |
el(InspectorControls, null, |
| 70 |
el(PanelBody, { title: __('Layout', 'blockenberg'), initialOpen: true }, |
| 71 |
el(RangeControl, { label: __('Image width (%)', 'blockenberg'), value: attributes.imageWidthPercent, min: 30, max: 70, onChange: function (v) { setAttributes({ imageWidthPercent: v }); } }), |
| 72 |
el(RangeControl, { label: __('Column gap (px)', 'blockenberg'), value: attributes.columnGap, min: 16, max: 160, onChange: function (v) { setAttributes({ columnGap: v }); } }), |
| 73 |
el(RangeControl, { label: __('Row gap (px)', 'blockenberg'), value: attributes.rowGap, min: 0, max: 200, onChange: function (v) { setAttributes({ rowGap: v }); } }), |
| 74 |
el(RangeControl, { label: __('Image border radius (px)', 'blockenberg'), value: attributes.imageRadius, min: 0, max: 48, onChange: function (v) { setAttributes({ imageRadius: v }); } }), |
| 75 |
el(ToggleControl, { label: __('Image shadow', 'blockenberg'), checked: attributes.imageShadow, onChange: function (v) { setAttributes({ imageShadow: v }); }, __nextHasNoMarginBottom: true }), |
| 76 |
el(ToggleControl, { label: __('Show eyebrow', 'blockenberg'), checked: attributes.showEyebrow, onChange: function (v) { setAttributes({ showEyebrow: v }); }, __nextHasNoMarginBottom: true }), |
| 77 |
el(ToggleControl, { label: __('Show button', 'blockenberg'), checked: attributes.showButton, onChange: function (v) { setAttributes({ showButton: v }); }, __nextHasNoMarginBottom: true }) |
| 78 |
), |
| 79 |
attributes.showButton && el(PanelBody, { title: __('Button', 'blockenberg'), initialOpen: false }, |
| 80 |
el(SelectControl, { label: __('Button style', 'blockenberg'), value: attributes.btnStyle, options: BTN_STYLE_OPTIONS, onChange: function (v) { setAttributes({ btnStyle: v }); } }), |
| 81 |
el(RangeControl, { label: __('Button border radius (px)', 'blockenberg'), value: attributes.btnBorderRadius, min: 0, max: 50, onChange: function (v) { setAttributes({ btnBorderRadius: v }); } }) |
| 82 |
), |
| 83 |
el(PanelBody, { title: __('Typography', 'blockenberg'), initialOpen: false }, |
| 84 |
getTypoControl() && el(getTypoControl(), { label: __('Eyebrow','blockenberg'), value: attributes.eyebrowTypo || {}, onChange: function(v){ setAttributes({ eyebrowTypo: v }); } }), |
| 85 |
getTypoControl() && el(getTypoControl(), { label: __('Title','blockenberg'), value: attributes.titleTypo || {}, onChange: function(v){ setAttributes({ titleTypo: v }); } }), |
| 86 |
getTypoControl() && el(getTypoControl(), { label: __('Description','blockenberg'), value: attributes.descTypo || {}, onChange: function(v){ setAttributes({ descTypo: v }); } }) |
| 87 |
), |
| 88 |
el(PanelBody, { title: __('Spacing', 'blockenberg'), initialOpen: false }, |
| 89 |
el(RangeControl, { label: __('Padding top (px)', 'blockenberg'), value: attributes.paddingTop, min: 0, max: 200, onChange: function (v) { setAttributes({ paddingTop: v }); } }), |
| 90 |
el(RangeControl, { label: __('Padding bottom (px)', 'blockenberg'), value: attributes.paddingBottom, min: 0, max: 200, onChange: function (v) { setAttributes({ paddingBottom: v }); } }) |
| 91 |
), |
| 92 |
el(PanelColorSettings, { |
| 93 |
title: __('Colors', 'blockenberg'), |
| 94 |
initialOpen: false, |
| 95 |
colorSettings: [ |
| 96 |
{ value: attributes.eyebrowColor, onChange: function (v) { setAttributes({ eyebrowColor: v || '' }); }, label: __('Eyebrow', 'blockenberg') }, |
| 97 |
{ value: attributes.titleColor, onChange: function (v) { setAttributes({ titleColor: v || '' }); }, label: __('Title', 'blockenberg') }, |
| 98 |
{ value: attributes.descColor, onChange: function (v) { setAttributes({ descColor: v || '' }); }, label: __('Description', 'blockenberg') }, |
| 99 |
{ value: attributes.btnBg, onChange: function (v) { setAttributes({ btnBg: v || '' }); }, label: __('Button background', 'blockenberg') }, |
| 100 |
{ value: attributes.btnColor, onChange: function (v) { setAttributes({ btnColor: v || '' }); }, label: __('Button text', 'blockenberg') }, |
| 101 |
{ value: attributes.bgColor, onChange: function (v) { setAttributes({ bgColor: v || '' }); }, label: __('Section background', 'blockenberg') }, |
| 102 |
] |
| 103 |
}), |
| 104 |
el(PanelBody, { title: __('Rows', 'blockenberg'), initialOpen: false }, |
| 105 |
rows.map(function (row, idx) { |
| 106 |
return el(PanelBody, { key: row.id, title: (row.title || __('Row', 'blockenberg')) + ' #' + (idx + 1), initialOpen: false }, |
| 107 |
el(ToggleControl, { label: __('Flip (image on right)', 'blockenberg'), checked: row.flipRow, onChange: function (v) { setRow(row.id, { flipRow: v }); }, __nextHasNoMarginBottom: true }), |
| 108 |
el(TextControl, { label: __('Eyebrow', 'blockenberg'), value: row.eyebrow, onChange: function (v) { setRow(row.id, { eyebrow: v }); } }), |
| 109 |
el(TextControl, { label: __('Title', 'blockenberg'), value: row.title, onChange: function (v) { setRow(row.id, { title: v }); } }), |
| 110 |
el(TextareaControl, { label: __('Description', 'blockenberg'), value: row.desc, rows: 3, onChange: function (v) { setRow(row.id, { desc: v }); } }), |
| 111 |
attributes.showButton && el(TextControl, { label: __('Button label', 'blockenberg'), value: row.btnLabel, onChange: function (v) { setRow(row.id, { btnLabel: v }); } }), |
| 112 |
attributes.showButton && el(TextControl, { label: __('Button URL', 'blockenberg'), value: row.btnUrl, type: 'url', onChange: function (v) { setRow(row.id, { btnUrl: v }); } }), |
| 113 |
attributes.showButton && el(ToggleControl, { label: __('Open in new tab', 'blockenberg'), checked: row.btnNewTab, onChange: function (v) { setRow(row.id, { btnNewTab: v }); }, __nextHasNoMarginBottom: true }), |
| 114 |
el('p', { style: { margin: '8px 0 4px', fontWeight: 600, fontSize: '11px', textTransform: 'uppercase', letterSpacing: '0.06em' } }, __('Row image', 'blockenberg')), |
| 115 |
el(MediaUploadCheck, null, |
| 116 |
el(MediaUpload, { |
| 117 |
onSelect: function (media) { setRow(row.id, { imageUrl: media.url, imageId: media.id, imageAlt: media.alt || '' }); }, |
| 118 |
allowedTypes: ['image'], |
| 119 |
value: row.imageId, |
| 120 |
render: function (ref) { |
| 121 |
return el(Button, { onClick: ref.open, variant: 'secondary', size: 'compact', style: { marginBottom: '6px' } }, |
| 122 |
row.imageUrl ? __('Change image', 'blockenberg') : __('Add image', 'blockenberg') |
| 123 |
); |
| 124 |
} |
| 125 |
}) |
| 126 |
), |
| 127 |
row.imageUrl && el(Button, { onClick: function () { setRow(row.id, { imageUrl: '', imageId: 0 }); }, variant: 'tertiary', size: 'compact', isDestructive: true, style: { display: 'block', marginBottom: '6px' } }, __('Remove image', 'blockenberg')), |
| 128 |
el(PanelColorSettings, { |
| 129 |
title: __('Row accent', 'blockenberg'), |
| 130 |
initialOpen: false, |
| 131 |
colorSettings: [{ value: row.accentColor, onChange: function (v) { setRow(row.id, { accentColor: v || '' }); }, label: __('Accent / Button color', 'blockenberg') }] |
| 132 |
}), |
| 133 |
el(Button, { onClick: function () { removeRow(row.id); }, variant: 'tertiary', isDestructive: true, size: 'compact' }, __('Remove row', 'blockenberg')) |
| 134 |
); |
| 135 |
}), |
| 136 |
el(Button, { onClick: addRow, variant: 'primary', style: { marginTop: '8px' } }, __('+ Add Row', 'blockenberg')) |
| 137 |
) |
| 138 |
), |
| 139 |
el('div', blockProps, |
| 140 |
el('div', { className: 'bkbg-media-text', style: { display: 'flex', flexDirection: 'column', gap: attributes.rowGap + 'px' } }, |
| 141 |
rows.map(function (row) { |
| 142 |
var imgW = attributes.imageWidthPercent + '%'; |
| 143 |
var txtW = (100 - attributes.imageWidthPercent) + '%'; |
| 144 |
return el('div', { |
| 145 |
key: row.id, |
| 146 |
className: 'bkbg-media-text__row' + (row.flipRow ? ' bkbg-media-text__row--flip' : ''), |
| 147 |
style: { display: 'flex', flexDirection: row.flipRow ? 'row-reverse' : 'row', alignItems: 'center', gap: attributes.columnGap + 'px', flexWrap: 'wrap' } |
| 148 |
}, |
| 149 |
el('div', { className: 'bkbg-media-text__image', style: { flex: '0 0 ' + imgW, maxWidth: imgW } }, |
| 150 |
row.imageUrl |
| 151 |
? el('img', { src: row.imageUrl, alt: row.imageAlt, style: { width: '100%', height: 'auto', borderRadius: attributes.imageRadius + 'px', display: 'block', boxShadow: attributes.imageShadow ? '0 20px 60px rgba(0,0,0,0.12)' : 'none' } }) |
| 152 |
: el('div', { style: { background: '#f3f4f6', borderRadius: attributes.imageRadius + 'px', aspectRatio: '4/3', display: 'flex', alignItems: 'center', justifyContent: 'center', color: '#9ca3af', fontSize: '14px', boxShadow: attributes.imageShadow ? '0 20px 60px rgba(0,0,0,0.08)' : 'none' } }, __('Add image ↑', 'blockenberg')) |
| 153 |
), |
| 154 |
el('div', { className: 'bkbg-media-text__text', style: { flex: '0 0 ' + txtW, maxWidth: txtW } }, |
| 155 |
attributes.showEyebrow && row.eyebrow && el('p', { className: 'bkbg-media-text__eyebrow', style: { color: row.accentColor || attributes.eyebrowColor, marginBottom: '10px' } }, row.eyebrow), |
| 156 |
el('h2', { className: 'bkbg-media-text__title', style: { color: attributes.titleColor, margin: '0 0 16px' } }, row.title), |
| 157 |
el('p', { className: 'bkbg-media-text__desc', style: { color: attributes.descColor, margin: '0' } }, row.desc), |
| 158 |
renderBtnPreview(row, attributes) |
| 159 |
) |
| 160 |
); |
| 161 |
}) |
| 162 |
) |
| 163 |
) |
| 164 |
); |
| 165 |
}, |
| 166 |
|
| 167 |
deprecated: [{ |
| 168 |
save: function (props) { |
| 169 |
var attributes = props.attributes; |
| 170 |
var rows = attributes.rows; |
| 171 |
var blockProps = wp.blockEditor.useBlockProps.save({ className: 'bkbg-media-text-wrap' }); |
| 172 |
|
| 173 |
return el('div', Object.assign({}, blockProps, { style: { paddingTop: attributes.paddingTop + 'px', paddingBottom: attributes.paddingBottom + 'px', backgroundColor: attributes.bgColor || undefined } }), |
| 174 |
el('div', { className: 'bkbg-media-text', style: { display: 'flex', flexDirection: 'column', gap: attributes.rowGap + 'px' } }, |
| 175 |
rows.map(function (row) { |
| 176 |
var imgW = attributes.imageWidthPercent + '%'; |
| 177 |
var txtW = (100 - attributes.imageWidthPercent) + '%'; |
| 178 |
var s = attributes.btnStyle; |
| 179 |
var bg = s === 'solid' ? (row.accentColor || attributes.btnBg) : 'transparent'; |
| 180 |
var color = s === 'solid' ? '#ffffff' : (row.accentColor || attributes.btnBg); |
| 181 |
var border = s === 'outlined' ? ('2px solid ' + (row.accentColor || attributes.btnBg)) : 'none'; |
| 182 |
return el('div', { |
| 183 |
key: row.id, |
| 184 |
className: 'bkbg-media-text__row' + (row.flipRow ? ' bkbg-media-text__row--flip' : ''), |
| 185 |
style: { display: 'flex', flexDirection: row.flipRow ? 'row-reverse' : 'row', alignItems: 'center', gap: attributes.columnGap + 'px', flexWrap: 'wrap' } |
| 186 |
}, |
| 187 |
el('div', { className: 'bkbg-media-text__image', style: { flex: '0 0 ' + imgW, maxWidth: imgW } }, |
| 188 |
row.imageUrl && el('img', { src: row.imageUrl, alt: row.imageAlt, style: { width: '100%', height: 'auto', borderRadius: attributes.imageRadius + 'px', display: 'block', boxShadow: attributes.imageShadow ? '0 20px 60px rgba(0,0,0,0.12)' : 'none' } }) |
| 189 |
), |
| 190 |
el('div', { className: 'bkbg-media-text__text', style: { flex: '0 0 ' + txtW, maxWidth: txtW } }, |
| 191 |
attributes.showEyebrow && row.eyebrow && el('p', { className: 'bkbg-media-text__eyebrow', style: { fontSize: attributes.eyebrowSize + 'px', fontWeight: attributes.eyebrowFontWeight || 600, textTransform: 'uppercase', letterSpacing: '0.08em', color: row.accentColor || attributes.eyebrowColor, marginBottom: '10px' } }, row.eyebrow), |
| 192 |
el('h2', { className: 'bkbg-media-text__title', style: { fontSize: attributes.titleSize + 'px', fontWeight: attributes.titleFontWeight || 700, color: attributes.titleColor, margin: '0 0 16px', lineHeight: attributes.titleLineHeight || 1.2 } }, row.title), |
| 193 |
el('p', { className: 'bkbg-media-text__desc', style: { fontSize: attributes.descSize + 'px', color: attributes.descColor, lineHeight: attributes.descLineHeight || 1.6, margin: 0 } }, row.desc), |
| 194 |
attributes.showButton && row.btnLabel && el('a', { href: row.btnUrl || '#', target: row.btnNewTab ? '_blank' : undefined, rel: row.btnNewTab ? 'noopener noreferrer' : undefined, className: 'bkbg-media-text__btn', style: { display: 'inline-block', marginTop: '14px', padding: s === 'link' ? '0' : '9px 22px', background: bg, color: color, border: border, borderRadius: attributes.btnBorderRadius + 'px', fontSize: attributes.descSize + 'px', fontWeight: 600, textDecoration: s === 'link' ? 'underline' : 'none' } }, row.btnLabel) |
| 195 |
) |
| 196 |
); |
| 197 |
}) |
| 198 |
) |
| 199 |
); |
| 200 |
} |
| 201 |
}], |
| 202 |
|
| 203 |
save: function (props) { |
| 204 |
var a = props.attributes; |
| 205 |
var rows = a.rows; |
| 206 |
var vf = (typeof window.bkbgTypoCssVars === 'function') ? window.bkbgTypoCssVars : function () { return {}; }; |
| 207 |
var st = Object.assign({}, |
| 208 |
vf(a.eyebrowTypo,'--bkbg-mt-ey-'), |
| 209 |
vf(a.titleTypo,'--bkbg-mt-tt-'), |
| 210 |
vf(a.descTypo,'--bkbg-mt-ds-'), |
| 211 |
{ paddingTop: a.paddingTop + 'px', paddingBottom: a.paddingBottom + 'px', backgroundColor: a.bgColor || undefined } |
| 212 |
); |
| 213 |
|
| 214 |
return el('div', (function(p){p.style=Object.assign(p.style||{},st);return p;})(wp.blockEditor.useBlockProps.save({className:'bkbg-media-text-wrap'})), |
| 215 |
el('div', { className: 'bkbg-media-text', style: { display: 'flex', flexDirection: 'column', gap: a.rowGap + 'px' } }, |
| 216 |
rows.map(function (row) { |
| 217 |
var imgW = a.imageWidthPercent + '%'; |
| 218 |
var txtW = (100 - a.imageWidthPercent) + '%'; |
| 219 |
var s = a.btnStyle; |
| 220 |
var bg = s === 'solid' ? (row.accentColor || a.btnBg) : 'transparent'; |
| 221 |
var color = s === 'solid' ? '#ffffff' : (row.accentColor || a.btnBg); |
| 222 |
var border = s === 'outlined' ? ('2px solid ' + (row.accentColor || a.btnBg)) : 'none'; |
| 223 |
return el('div', { |
| 224 |
key: row.id, |
| 225 |
className: 'bkbg-media-text__row' + (row.flipRow ? ' bkbg-media-text__row--flip' : ''), |
| 226 |
style: { display: 'flex', flexDirection: row.flipRow ? 'row-reverse' : 'row', alignItems: 'center', gap: a.columnGap + 'px', flexWrap: 'wrap' } |
| 227 |
}, |
| 228 |
el('div', { className: 'bkbg-media-text__image', style: { flex: '0 0 ' + imgW, maxWidth: imgW } }, |
| 229 |
row.imageUrl && el('img', { src: row.imageUrl, alt: row.imageAlt, style: { width: '100%', height: 'auto', borderRadius: a.imageRadius + 'px', display: 'block', boxShadow: a.imageShadow ? '0 20px 60px rgba(0,0,0,0.12)' : 'none' } }) |
| 230 |
), |
| 231 |
el('div', { className: 'bkbg-media-text__text', style: { flex: '0 0 ' + txtW, maxWidth: txtW } }, |
| 232 |
a.showEyebrow && row.eyebrow && el('p', { className: 'bkbg-media-text__eyebrow', style: { color: row.accentColor || a.eyebrowColor, marginBottom: '10px' } }, row.eyebrow), |
| 233 |
el('h2', { className: 'bkbg-media-text__title', style: { color: a.titleColor, margin: '0 0 16px' } }, row.title), |
| 234 |
el('p', { className: 'bkbg-media-text__desc', style: { color: a.descColor, margin: 0 } }, row.desc), |
| 235 |
a.showButton && row.btnLabel && el('a', { href: row.btnUrl || '#', target: row.btnNewTab ? '_blank' : undefined, rel: row.btnNewTab ? 'noopener noreferrer' : undefined, className: 'bkbg-media-text__btn', style: { display: 'inline-block', marginTop: '14px', padding: s === 'link' ? '0' : '9px 22px', background: bg, color: color, border: border, borderRadius: a.btnBorderRadius + 'px', fontSize: a.descSize + 'px', fontWeight: 600, textDecoration: s === 'link' ? 'underline' : 'none' } }, row.btnLabel) |
| 236 |
) |
| 237 |
); |
| 238 |
}) |
| 239 |
) |
| 240 |
); |
| 241 |
} |
| 242 |
}); |
| 243 |
}()); |
| 244 |
|