| 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 |
function getTypographyControl() { |
| 19 |
return (window.bkbgTypographyControl || function () { return null; }); |
| 20 |
} |
| 21 |
|
| 22 |
function _tv(typo, prefix) { |
| 23 |
if (!typo) return {}; |
| 24 |
var s = {}; |
| 25 |
if (typo.family) s[prefix + 'font-family'] = "'" + typo.family + "', sans-serif"; |
| 26 |
if (typo.weight) s[prefix + 'font-weight'] = typo.weight; |
| 27 |
if (typo.transform) s[prefix + 'text-transform'] = typo.transform; |
| 28 |
if (typo.style) s[prefix + 'font-style'] = typo.style; |
| 29 |
if (typo.decoration) s[prefix + 'text-decoration'] = typo.decoration; |
| 30 |
var su = typo.sizeUnit || 'px'; |
| 31 |
if (typo.sizeDesktop !== '' && typo.sizeDesktop != null) s[prefix + 'font-size-d'] = typo.sizeDesktop + su; |
| 32 |
if (typo.sizeTablet !== '' && typo.sizeTablet != null) s[prefix + 'font-size-t'] = typo.sizeTablet + su; |
| 33 |
if (typo.sizeMobile !== '' && typo.sizeMobile != null) s[prefix + 'font-size-m'] = typo.sizeMobile + su; |
| 34 |
var lhu = typo.lineHeightUnit || ''; |
| 35 |
if (typo.lineHeightDesktop !== '' && typo.lineHeightDesktop != null) s[prefix + 'line-height-d'] = typo.lineHeightDesktop + lhu; |
| 36 |
if (typo.lineHeightTablet !== '' && typo.lineHeightTablet != null) s[prefix + 'line-height-t'] = typo.lineHeightTablet + lhu; |
| 37 |
if (typo.lineHeightMobile !== '' && typo.lineHeightMobile != null) s[prefix + 'line-height-m'] = typo.lineHeightMobile + lhu; |
| 38 |
var lsu = typo.letterSpacingUnit || 'px'; |
| 39 |
if (typo.letterSpacingDesktop !== '' && typo.letterSpacingDesktop != null) s[prefix + 'letter-spacing-d'] = typo.letterSpacingDesktop + lsu; |
| 40 |
if (typo.letterSpacingTablet !== '' && typo.letterSpacingTablet != null) s[prefix + 'letter-spacing-t'] = typo.letterSpacingTablet + lsu; |
| 41 |
if (typo.letterSpacingMobile !== '' && typo.letterSpacingMobile != null) s[prefix + 'letter-spacing-m'] = typo.letterSpacingMobile + lsu; |
| 42 |
var wsu = typo.wordSpacingUnit || 'px'; |
| 43 |
if (typo.wordSpacingDesktop !== '' && typo.wordSpacingDesktop != null) s[prefix + 'word-spacing-d'] = typo.wordSpacingDesktop + wsu; |
| 44 |
if (typo.wordSpacingTablet !== '' && typo.wordSpacingTablet != null) s[prefix + 'word-spacing-t'] = typo.wordSpacingTablet + wsu; |
| 45 |
if (typo.wordSpacingMobile !== '' && typo.wordSpacingMobile != null) s[prefix + 'word-spacing-m'] = typo.wordSpacingMobile + wsu; |
| 46 |
return s; |
| 47 |
} |
| 48 |
|
| 49 |
var SOCIAL_ICONS = { twitter: '𝕏', linkedin: 'in', instagram: '◉', website: '🌐', youtube: '▶', tiktok: '♪', facebook: 'f' }; |
| 50 |
|
| 51 |
registerBlockType('blockenberg/bio-section', { |
| 52 |
edit: function (props) { |
| 53 |
var a = props.attributes; |
| 54 |
var set = props.setAttributes; |
| 55 |
var blockProps = useBlockProps(); |
| 56 |
|
| 57 |
var isCentered = a.layout === 'centered'; |
| 58 |
var isRight = a.layout === 'image-right'; |
| 59 |
|
| 60 |
function updateCredential(idx, val) { |
| 61 |
var next = a.credentials.map(function (c, i) { return i === idx ? { text: val } : c; }); |
| 62 |
set({ credentials: next }); |
| 63 |
} |
| 64 |
|
| 65 |
function updateSocial(idx, key, val) { |
| 66 |
var next = a.socials.map(function (s, i) { return i === idx ? Object.assign({}, s, { [key]: val }) : s; }); |
| 67 |
set({ socials: next }); |
| 68 |
} |
| 69 |
|
| 70 |
/* Photo */ |
| 71 |
var shapeStyle = {}; |
| 72 |
if (a.imageShape === 'circle') shapeStyle.borderRadius = '50%'; |
| 73 |
else if (a.imageShape === 'rounded') shapeStyle.borderRadius = a.imageRadius + 'px'; |
| 74 |
|
| 75 |
var imageEl = el(MediaUploadCheck, {}, |
| 76 |
el(MediaUpload, { |
| 77 |
onSelect: function (media) { set({ imageUrl: media.url, imageId: media.id, imageAlt: media.alt || '' }); }, |
| 78 |
allowedTypes: ['image'], |
| 79 |
value: a.imageId, |
| 80 |
render: function (ref) { |
| 81 |
return el('div', { |
| 82 |
className: 'bkbg-bios-photo-wrap', |
| 83 |
onClick: ref.open, |
| 84 |
style: { position: 'relative', width: isCentered ? '280px' : a.imageWidth + 'px', margin: isCentered ? '0 auto 32px' : '0', cursor: 'pointer', flexShrink: 0 } |
| 85 |
}, |
| 86 |
a.showDecorator && el('div', { className: 'bkbg-bios-decorator', style: { position: 'absolute', inset: '-16px', background: a.decoratorColor, borderRadius: (a.imageRadius + 16) + 'px', zIndex: 0 } }), |
| 87 |
a.imageUrl |
| 88 |
? el('img', { src: a.imageUrl, alt: a.imageAlt, style: Object.assign({ width: '100%', display: 'block', position: 'relative', zIndex: 1 }, shapeStyle) }) |
| 89 |
: el('div', { style: Object.assign({ background: '#e5e7eb', display: 'flex', alignItems: 'center', justifyContent: 'center', fontSize: '48px', aspectRatio: '3/4', position: 'relative', zIndex: 1 }, shapeStyle) }, '🧑') |
| 90 |
); |
| 91 |
} |
| 92 |
}) |
| 93 |
); |
| 94 |
|
| 95 |
/* Text content */ |
| 96 |
var textContent = el('div', { className: 'bkbg-bios-text', style: { flex: 1 } }, |
| 97 |
el(RichText, { tagName: 'h2', className: 'bkbg-bios-name', value: a.name, style: { color: a.nameColor, margin: '0 0 6px' }, onChange: function (v) { set({ name: v }); } }), |
| 98 |
el(RichText, { tagName: 'p', className: 'bkbg-bios-title', value: a.title, style: { color: a.titleColor, margin: '0 0 8px' }, onChange: function (v) { set({ title: v }); } }), |
| 99 |
a.showSubtitle && el(RichText, { tagName: 'p', className: 'bkbg-bios-subtitle', value: a.subtitle, style: { color: a.subtitleColor, margin: '0 0 20px' }, onChange: function (v) { set({ subtitle: v }); } }), |
| 100 |
a.showCredentials && el('div', { style: { display: 'flex', flexWrap: 'wrap', gap: '8px', marginBottom: '20px' } }, |
| 101 |
a.credentials.map(function (c, idx) { |
| 102 |
return el('span', { key: idx, style: { background: a.credentialBg, color: a.credentialColor, fontSize: '12px', fontWeight: '600', padding: '4px 12px', borderRadius: '999px' } }, |
| 103 |
el(RichText, { tagName: 'span', value: c.text, onChange: function (v) { updateCredential(idx, v); } }) |
| 104 |
) }), |
| 105 |
el(Button, { isSmall: true, isSecondary: true, onClick: function () { set({ credentials: a.credentials.concat([{ text: 'New badge' }]) }); } }, '+') |
| 106 |
), |
| 107 |
el(RichText, { tagName: 'div', className: 'bkbg-bios-bio', multiline: 'p', value: a.bio, style: { color: a.bioColor, marginBottom: '20px' }, onChange: function (v) { set({ bio: v }); } }), |
| 108 |
a.showQuote && el('blockquote', { className: 'bkbg-bios-quote', style: { borderLeft: '4px solid ' + a.quoteBorderColor, paddingLeft: '20px', margin: '0 0 20px' } }, |
| 109 |
el(RichText, { tagName: 'p', value: a.highlightQuote, style: { color: a.quoteColor, margin: 0 }, onChange: function (v) { set({ highlightQuote: v }); } }) |
| 110 |
), |
| 111 |
el('div', { style: { display: 'flex', alignItems: 'center', gap: '16px', flexWrap: 'wrap' } }, |
| 112 |
a.ctaEnabled && el('a', { href: '#editor', style: { background: a.ctaBg, color: a.ctaColor, padding: '12px 24px', borderRadius: '8px', fontWeight: '700', fontSize: '15px', textDecoration: 'none', display: 'inline-block' } }, |
| 113 |
el(RichText, { tagName: 'span', value: a.ctaLabel, onChange: function (v) { set({ ctaLabel: v }); } }) |
| 114 |
), |
| 115 |
a.showSocials && el('div', { style: { display: 'flex', gap: '10px' } }, |
| 116 |
a.socials.map(function (s, idx) { |
| 117 |
return el('span', { key: idx, title: s.label, style: { display: 'inline-flex', alignItems: 'center', justifyContent: 'center', width: '36px', height: '36px', borderRadius: '8px', border: '1.5px solid #e5e7eb', color: a.socialColor, fontSize: '13px', fontWeight: '700', cursor: 'pointer' } }, SOCIAL_ICONS[s.platform] || s.platform[0].toUpperCase()) }) |
| 118 |
) |
| 119 |
) |
| 120 |
); |
| 121 |
|
| 122 |
var layoutStyles = { display: 'flex', gap: '60px', alignItems: 'center' }; |
| 123 |
if (isCentered) layoutStyles = { display: 'flex', flexDirection: 'column', alignItems: 'center', textAlign: 'center' }; |
| 124 |
if (isRight) layoutStyles.flexDirection = 'row-reverse'; |
| 125 |
|
| 126 |
var controls = el(InspectorControls, {}, |
| 127 |
el(PanelBody, { title: __('Layout', 'blockenberg'), initialOpen: true }, |
| 128 |
el(SelectControl, { label: __('Layout', 'blockenberg'), value: a.layout, options: [{ label: 'Image Left', value: 'image-left' }, { label: 'Image Right', value: 'image-right' }, { label: 'Centered', value: 'centered' }], onChange: function (v) { set({ layout: v }); }, __nextHasNoMarginBottom: true }), |
| 129 |
el(SelectControl, { label: __('Image Shape', 'blockenberg'), value: a.imageShape, options: [{ label: 'Rounded', value: 'rounded' }, { label: 'Circle', value: 'circle' }, { label: 'Square', value: 'square' }], onChange: function (v) { set({ imageShape: v }); }, __nextHasNoMarginBottom: true }), |
| 130 |
el(RangeControl, { label: __('Image Width (px)', 'blockenberg'), value: a.imageWidth, min: 200, max: 600, onChange: function (v) { set({ imageWidth: v }); }, __nextHasNoMarginBottom: true }), |
| 131 |
el(RangeControl, { label: __('Image Radius (px)', 'blockenberg'), value: a.imageRadius, min: 0, max: 40, onChange: function (v) { set({ imageRadius: v }); }, __nextHasNoMarginBottom: true }), |
| 132 |
el(ToggleControl, { label: __('Show Decorator', 'blockenberg'), checked: a.showDecorator, onChange: function (v) { set({ showDecorator: v }); }, __nextHasNoMarginBottom: true }), |
| 133 |
el(ToggleControl, { label: __('Show Subtitle', 'blockenberg'), checked: a.showSubtitle, onChange: function (v) { set({ showSubtitle: v }); }, __nextHasNoMarginBottom: true }), |
| 134 |
el(ToggleControl, { label: __('Show Credentials', 'blockenberg'), checked: a.showCredentials, onChange: function (v) { set({ showCredentials: v }); }, __nextHasNoMarginBottom: true }), |
| 135 |
el(ToggleControl, { label: __('Show Quote', 'blockenberg'), checked: a.showQuote, onChange: function (v) { set({ showQuote: v }); }, __nextHasNoMarginBottom: true }), |
| 136 |
el(ToggleControl, { label: __('Show CTA', 'blockenberg'), checked: a.ctaEnabled, onChange: function (v) { set({ ctaEnabled: v }); }, __nextHasNoMarginBottom: true }), |
| 137 |
a.ctaEnabled && el(TextControl, { label: __('CTA URL', 'blockenberg'), value: a.ctaUrl, onChange: function (v) { set({ ctaUrl: v }); }, __nextHasNoMarginBottom: true }), |
| 138 |
a.ctaEnabled && el(ToggleControl, { label: __('Open in new tab', 'blockenberg'), checked: a.ctaIsExternal, onChange: function (v) { set({ ctaIsExternal: v }); }, __nextHasNoMarginBottom: true }), |
| 139 |
el(ToggleControl, { label: __('Show Social Links', 'blockenberg'), checked: a.showSocials, onChange: function (v) { set({ showSocials: v }); }, __nextHasNoMarginBottom: true }), |
| 140 |
el(RangeControl, { label: __('Max Width (px)', 'blockenberg'), value: a.maxWidth, min: 600, max: 1400, onChange: function (v) { set({ maxWidth: v }); }, __nextHasNoMarginBottom: true }), |
| 141 |
el(RangeControl, { label: __('Padding Top', 'blockenberg'), value: a.paddingTop, min: 0, max: 160, onChange: function (v) { set({ paddingTop: v }); }, __nextHasNoMarginBottom: true }), |
| 142 |
el(RangeControl, { label: __('Padding Bottom', 'blockenberg'), value: a.paddingBottom, min: 0, max: 160, onChange: function (v) { set({ paddingBottom: v }); }, __nextHasNoMarginBottom: true }) |
| 143 |
), |
| 144 |
a.showSocials && el(PanelBody, { title: __('Social Links', 'blockenberg'), initialOpen: false }, |
| 145 |
a.socials.map(function (s, idx) { |
| 146 |
return el('div', { key: idx, style: { borderBottom: '1px solid #eee', paddingBottom: '8px', marginBottom: '8px' } }, |
| 147 |
el(TextControl, { label: s.platform.charAt(0).toUpperCase() + s.platform.slice(1) + ' URL', value: s.url, onChange: function (v) { updateSocial(idx, 'url', v); }, __nextHasNoMarginBottom: true }) |
| 148 |
) }) |
| 149 |
), |
| 150 |
|
| 151 |
el( PanelBody, { title: __( 'Typography', 'blockenberg' ), initialOpen: false }, |
| 152 |
el(getTypographyControl(), { label: __('Name', 'blockenberg'), value: a.typoName, onChange: function (v) { set({ typoName: v }); } }), |
| 153 |
el(getTypographyControl(), { label: __('Title', 'blockenberg'), value: a.typoTitle, onChange: function (v) { set({ typoTitle: v }); } }), |
| 154 |
el(getTypographyControl(), { label: __('Subtitle', 'blockenberg'), value: a.typoSubtitle, onChange: function (v) { set({ typoSubtitle: v }); } }), |
| 155 |
el(getTypographyControl(), { label: __('Bio Text', 'blockenberg'), value: a.typoBio, onChange: function (v) { set({ typoBio: v }); } }), |
| 156 |
el(getTypographyControl(), { label: __('Quote', 'blockenberg'), value: a.typoQuote, onChange: function (v) { set({ typoQuote: v }); } }) |
| 157 |
), |
| 158 |
el(PanelColorSettings, { |
| 159 |
title: __('Colors', 'blockenberg'), initialOpen: false, |
| 160 |
colorSettings: [ |
| 161 |
{ label: __('Background', 'blockenberg'), value: a.bgColor, onChange: function (v) { set({ bgColor: v || '#ffffff' }); } }, |
| 162 |
{ label: __('Name', 'blockenberg'), value: a.nameColor, onChange: function (v) { set({ nameColor: v || '#111827' }); } }, |
| 163 |
{ label: __('Title', 'blockenberg'), value: a.titleColor, onChange: function (v) { set({ titleColor: v || '#7c3aed' }); } }, |
| 164 |
{ label: __('Bio Text', 'blockenberg'), value: a.bioColor, onChange: function (v) { set({ bioColor: v || '#374151' }); } }, |
| 165 |
{ label: __('Credential BG', 'blockenberg'), value: a.credentialBg, onChange: function (v) { set({ credentialBg: v || '#f3f0ff' }); } }, |
| 166 |
{ label: __('Credential Text', 'blockenberg'), value: a.credentialColor, onChange: function (v) { set({ credentialColor: v || '#5b21b6' }); } }, |
| 167 |
{ label: __('Quote', 'blockenberg'), value: a.quoteColor, onChange: function (v) { set({ quoteColor: v || '#111827' }); } }, |
| 168 |
{ label: __('Quote Border', 'blockenberg'), value: a.quoteBorderColor, onChange: function (v) { set({ quoteBorderColor: v || '#7c3aed' }); } }, |
| 169 |
{ label: __('Decorator', 'blockenberg'), value: a.decoratorColor, onChange: function (v) { set({ decoratorColor: v || '#f3f0ff' }); } }, |
| 170 |
{ label: __('CTA BG', 'blockenberg'), value: a.ctaBg, onChange: function (v) { set({ ctaBg: v || '#7c3aed' }); } }, |
| 171 |
{ label: __('CTA Text', 'blockenberg'), value: a.ctaColor, onChange: function (v) { set({ ctaColor: v || '#ffffff' }); } }, |
| 172 |
{ label: __('Social Icons', 'blockenberg'), value: a.socialColor, onChange: function (v) { set({ socialColor: v || '#6b7280' }); } } |
| 173 |
] |
| 174 |
}) |
| 175 |
); |
| 176 |
|
| 177 |
return el('div', blockProps, |
| 178 |
controls, |
| 179 |
el('div', { style: Object.assign({ background: a.bgColor, paddingTop: a.paddingTop + 'px', paddingBottom: a.paddingBottom + 'px' }, _tv(a.typoName, '--bkbg-bios-name-'), _tv(a.typoTitle, '--bkbg-bios-title-'), _tv(a.typoSubtitle, '--bkbg-bios-subtitle-'), _tv(a.typoBio, '--bkbg-bios-bio-'), _tv(a.typoQuote, '--bkbg-bios-quote-')) }, |
| 180 |
el('div', { style: Object.assign({ maxWidth: a.maxWidth + 'px', margin: '0 auto', padding: '0 24px' }, layoutStyles) }, |
| 181 |
imageEl, |
| 182 |
textContent |
| 183 |
) |
| 184 |
) |
| 185 |
); |
| 186 |
}, |
| 187 |
|
| 188 |
save: function (props) { |
| 189 |
return el('div', wp.blockEditor.useBlockProps.save(), |
| 190 |
el('div', { className: 'bkbg-bios-app', 'data-opts': JSON.stringify(props.attributes) }) |
| 191 |
); |
| 192 |
} |
| 193 |
}); |
| 194 |
}() ); |
| 195 |
|