| 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 useBlockProps = wp.blockEditor.useBlockProps; |
| 7 |
var RichText = wp.blockEditor.RichText; |
| 8 |
var PanelColorSettings = wp.blockEditor.PanelColorSettings; |
| 9 |
var PanelBody = wp.components.PanelBody; |
| 10 |
var ToggleControl = wp.components.ToggleControl; |
| 11 |
var RangeControl = wp.components.RangeControl; |
| 12 |
var SelectControl = wp.components.SelectControl; |
| 13 |
var TextControl = wp.components.TextControl; |
| 14 |
var TextareaControl = wp.components.TextareaControl; |
| 15 |
var Button = wp.components.Button; |
| 16 |
|
| 17 |
var _tc, _tv; |
| 18 |
function getTypoControl() { return _tc || (_tc = window.bkbgTypographyControl); } |
| 19 |
function getTypoCssVars() { return _tv || (_tv = window.bkbgTypoCssVars); } |
| 20 |
var IP = function () { return window.bkbgIconPicker; }; |
| 21 |
|
| 22 |
registerBlockType('blockenberg/persona-section', { |
| 23 |
edit: function (props) { |
| 24 |
var attr = props.attributes; |
| 25 |
var set = props.setAttributes; |
| 26 |
|
| 27 |
var blockProps = useBlockProps((function(){ |
| 28 |
var s = { background: attr.bgColor }; |
| 29 |
var tv = getTypoCssVars(); |
| 30 |
if (tv) { |
| 31 |
Object.assign(s, tv(attr.eyebrowTypo || {}, '--bkbg-per-eyebrow')); |
| 32 |
Object.assign(s, tv(attr.headingTypo || {}, '--bkbg-per-heading')); |
| 33 |
Object.assign(s, tv(attr.subtextTypo || {}, '--bkbg-per-subtext')); |
| 34 |
Object.assign(s, tv(attr.roleTypo || {}, '--bkbg-per-role')); |
| 35 |
Object.assign(s, tv(attr.descTypo || {}, '--bkbg-per-desc')); |
| 36 |
Object.assign(s, tv(attr.itemTypo || {}, '--bkbg-per-item')); |
| 37 |
} |
| 38 |
return { style: s }; |
| 39 |
})()); |
| 40 |
|
| 41 |
/* Persona editor helpers */ |
| 42 |
function updatePersona(idx, key, value) { |
| 43 |
var arr = attr.personas.map(function (p, i) { return i === idx ? Object.assign({}, p, JSON.parse('{' + JSON.stringify(key) + ':' + JSON.stringify(value) + '}')) : p; }); |
| 44 |
set({ personas: arr }); |
| 45 |
} |
| 46 |
function updatePersonaArray(idx, key, arrValue) { |
| 47 |
var arr = attr.personas.map(function (p, i) { if (i !== idx) return p; var copy = Object.assign({}, p); copy[key] = arrValue; return copy; }); |
| 48 |
set({ personas: arr }); |
| 49 |
} |
| 50 |
|
| 51 |
function PersonaEditor(persona, idx) { |
| 52 |
return el('div', { key: idx, style: { border: '1px solid #e2e8f0', borderRadius: '6px', padding: '12px', marginBottom: '10px', background: '#f8fafc' } }, |
| 53 |
el('strong', { style: { fontSize: '12px', color: '#374151' } }, ((persona.iconType || 'custom-char') === 'custom-char' ? (persona.icon || '?') : '⬡') + ' ' + (persona.role || __('Persona', 'blockenberg'))), |
| 54 |
el('div', { style: { marginTop: '8px' } }, |
| 55 |
el(IP().IconPickerControl, { |
| 56 |
iconType: persona.iconType || 'custom-char', |
| 57 |
customChar: persona.icon, |
| 58 |
dashicon: persona.iconDashicon || '', |
| 59 |
imageUrl: persona.iconImageUrl || '', |
| 60 |
onChangeType: function (v) { updatePersona(idx, 'iconType', v); }, |
| 61 |
onChangeChar: function (v) { updatePersona(idx, 'icon', v); }, |
| 62 |
onChangeDashicon: function (v) { updatePersona(idx, 'iconDashicon', v); }, |
| 63 |
onChangeImageUrl: function (v) { updatePersona(idx, 'iconImageUrl', v); } |
| 64 |
}) |
| 65 |
), |
| 66 |
el('div', { style: { marginTop: '8px' } }, |
| 67 |
el(TextControl, { label: __('Role Title', 'blockenberg'), value: persona.role, __nextHasNoMarginBottom: true, onChange: function (v) { updatePersona(idx, 'role', v); } }) |
| 68 |
), |
| 69 |
el('div', { style: { marginTop: '8px' } }, |
| 70 |
el(TextareaControl, { label: __('Description', 'blockenberg'), value: persona.description, __nextHasNoMarginBottom: true, rows: 2, onChange: function (v) { updatePersona(idx, 'description', v); } }) |
| 71 |
), |
| 72 |
el('div', { style: { marginTop: '10px' } }, |
| 73 |
el('label', { style: { display: 'block', fontSize: '11px', fontWeight: 500, textTransform: 'uppercase', marginBottom: '6px', color: '#374151' } }, __('Pain Points', 'blockenberg')), |
| 74 |
(persona.painPoints || []).map(function (pt, pi) { |
| 75 |
return el('div', { key: pi, style: { display: 'flex', gap: '6px', marginBottom: '4px' } }, |
| 76 |
el(TextControl, { value: pt, __nextHasNoMarginBottom: true, onChange: function (v) { var arr = (persona.painPoints || []).slice(); arr[pi] = v; updatePersonaArray(idx, 'painPoints', arr); } }), |
| 77 |
el(Button, { variant: 'tertiary', isDestructive: true, onClick: function () { updatePersonaArray(idx, 'painPoints', (persona.painPoints || []).filter(function (_, i) { return i !== pi; })); } }, '✕') |
| 78 |
); |
| 79 |
}), |
| 80 |
el(Button, { variant: 'secondary', __nextHasNoMarginBottom: true, style: { marginTop: '4px' }, onClick: function () { updatePersonaArray(idx, 'painPoints', (persona.painPoints || []).concat(['New pain point'])); } }, __('+ Pain Point', 'blockenberg')) |
| 81 |
), |
| 82 |
el('div', { style: { marginTop: '10px' } }, |
| 83 |
el('label', { style: { display: 'block', fontSize: '11px', fontWeight: 500, textTransform: 'uppercase', marginBottom: '6px', color: '#374151' } }, __('Benefits', 'blockenberg')), |
| 84 |
(persona.benefits || []).map(function (b, bi) { |
| 85 |
return el('div', { key: bi, style: { display: 'flex', gap: '6px', marginBottom: '4px' } }, |
| 86 |
el(TextControl, { value: b, __nextHasNoMarginBottom: true, onChange: function (v) { var arr = (persona.benefits || []).slice(); arr[bi] = v; updatePersonaArray(idx, 'benefits', arr); } }), |
| 87 |
el(Button, { variant: 'tertiary', isDestructive: true, onClick: function () { updatePersonaArray(idx, 'benefits', (persona.benefits || []).filter(function (_, i) { return i !== bi; })); } }, '✕') |
| 88 |
); |
| 89 |
}), |
| 90 |
el(Button, { variant: 'secondary', __nextHasNoMarginBottom: true, style: { marginTop: '4px' }, onClick: function () { updatePersonaArray(idx, 'benefits', (persona.benefits || []).concat(['New benefit'])); } }, __('+ Benefit', 'blockenberg')) |
| 91 |
), |
| 92 |
el(Button, { variant: 'link', isDestructive: true, style: { marginTop: '8px' }, onClick: function () { set({ personas: attr.personas.filter(function (_, i) { return i !== idx; }) }); } }, __('Remove Persona', 'blockenberg')) |
| 93 |
); |
| 94 |
} |
| 95 |
|
| 96 |
/* Card preview */ |
| 97 |
function PersonaCard(p) { |
| 98 |
return el('div', { |
| 99 |
key: p.role, style: { |
| 100 |
background: attr.cardBg, border: '1px solid ' + attr.cardBorder, |
| 101 |
borderRadius: attr.borderRadius + 'px', padding: '28px' |
| 102 |
} |
| 103 |
}, |
| 104 |
el('div', { className: 'bkbg-per-icon', style: { width: '56px', height: '56px', borderRadius: '12px', background: attr.iconBg, display: 'flex', alignItems: 'center', justifyContent: 'center', fontSize: '28px', marginBottom: '16px' } }, (p.iconType || 'custom-char') !== 'custom-char' ? IP().buildEditorIcon(p.iconType, p.icon, p.iconDashicon, p.iconImageUrl, p.iconDashiconColor) : p.icon), |
| 105 |
el('h3', { className: 'bkbg-per-role', style: { margin: '0 0 8px', color: attr.roleColor } }, p.role), |
| 106 |
el('p', { className: 'bkbg-per-desc', style: { margin: '0 0 16px', color: attr.descColor } }, p.description), |
| 107 |
attr.showPainPoints && p.painPoints && p.painPoints.length && el('div', { style: { marginBottom: '16px' } }, |
| 108 |
el('p', { style: { margin: '0 0 8px', fontSize: '11px', fontWeight: 700, textTransform: 'uppercase', color: attr.accentColor } }, attr.painLabel), |
| 109 |
el('ul', { style: { listStyle: 'none', padding: 0, margin: 0 } }, |
| 110 |
p.painPoints.slice(0, 3).map(function (pt, i) { |
| 111 |
return el('li', { key: i, style: { display: 'flex', gap: '8px', fontSize: '13px', marginBottom: '6px', color: attr.painColor } }, |
| 112 |
el('span', { style: { color: attr.painIconColor, flexShrink: 0 } }, '✕'), pt |
| 113 |
); |
| 114 |
}) |
| 115 |
) |
| 116 |
), |
| 117 |
attr.showBenefits && p.benefits && p.benefits.length && el('div', {}, |
| 118 |
el('p', { style: { margin: '0 0 8px', fontSize: '11px', fontWeight: 700, textTransform: 'uppercase', color: attr.accentColor } }, attr.benefitLabel), |
| 119 |
el('ul', { style: { listStyle: 'none', padding: 0, margin: 0 } }, |
| 120 |
p.benefits.slice(0, 3).map(function (b, i) { |
| 121 |
return el('li', { key: i, style: { display: 'flex', gap: '8px', fontSize: '13px', marginBottom: '6px', color: attr.benefitColor } }, |
| 122 |
el('span', { style: { color: attr.benefitIconColor, flexShrink: 0 } }, '✓'), b |
| 123 |
); |
| 124 |
}) |
| 125 |
) |
| 126 |
) |
| 127 |
); |
| 128 |
} |
| 129 |
|
| 130 |
var controls = el(InspectorControls, {}, |
| 131 |
el(PanelBody, { title: __('Personas', 'blockenberg'), initialOpen: true }, |
| 132 |
(attr.personas || []).map(function (p, idx) { return PersonaEditor(p, idx); }), |
| 133 |
el(Button, { variant: 'secondary', __nextHasNoMarginBottom: true, style: { marginTop: '8px' }, onClick: function () { set({ personas: (attr.personas || []).concat([{ icon: '⭐', iconType: 'custom-char', iconDashicon: '', iconImageUrl: '', role: 'New Audience', description: 'Describe this audience.', painPoints: ['Pain point 1', 'Pain point 2'], benefits: ['Benefit 1', 'Benefit 2'] }]) }); } }, __('+ Add Persona', 'blockenberg')) |
| 134 |
), |
| 135 |
el(PanelBody, { title: __('Labels', 'blockenberg'), initialOpen: false }, |
| 136 |
el(TextControl, { label: __('Pain Points Label', 'blockenberg'), value: attr.painLabel, __nextHasNoMarginBottom: true, onChange: function (v) { set({ painLabel: v }); } }), |
| 137 |
el('div', { style: { marginTop: '12px' } }, |
| 138 |
el(TextControl, { label: __('Benefits Label', 'blockenberg'), value: attr.benefitLabel, __nextHasNoMarginBottom: true, onChange: function (v) { set({ benefitLabel: v }); } }) |
| 139 |
) |
| 140 |
), |
| 141 |
el(PanelBody, { title: __('Layout', 'blockenberg'), initialOpen: false }, |
| 142 |
el(SelectControl, { |
| 143 |
label: __('Layout', 'blockenberg'), value: attr.layout, __nextHasNoMarginBottom: true, |
| 144 |
options: [{ label: 'Grid', value: 'grid' }, { label: 'Cards (auto columns)', value: 'cards' }], |
| 145 |
onChange: function (v) { set({ layout: v }); } |
| 146 |
}), |
| 147 |
el('div', { style: { marginTop: '12px' } }, |
| 148 |
el(RangeControl, { label: __('Columns', 'blockenberg'), value: attr.columns, min: 1, max: 4, __nextHasNoMarginBottom: true, onChange: function (v) { set({ columns: v }); } }) |
| 149 |
), |
| 150 |
el('div', { style: { marginTop: '12px' } }, |
| 151 |
el(RangeControl, { label: __('Border Radius', 'blockenberg'), value: attr.borderRadius, min: 0, max: 32, __nextHasNoMarginBottom: true, onChange: function (v) { set({ borderRadius: v }); } }) |
| 152 |
), |
| 153 |
el('div', { style: { marginTop: '12px' } }, |
| 154 |
el(ToggleControl, { label: __('Show Pain Points', 'blockenberg'), checked: attr.showPainPoints, __nextHasNoMarginBottom: true, onChange: function (v) { set({ showPainPoints: v }); } }) |
| 155 |
), |
| 156 |
el('div', { style: { marginTop: '4px' } }, |
| 157 |
el(ToggleControl, { label: __('Show Benefits', 'blockenberg'), checked: attr.showBenefits, __nextHasNoMarginBottom: true, onChange: function (v) { set({ showBenefits: v }); } }) |
| 158 |
) |
| 159 |
), |
| 160 |
el(PanelBody, { title: __('Spacing', 'blockenberg'), initialOpen: false }, |
| 161 |
el(RangeControl, { label: __('Padding Top', 'blockenberg'), value: attr.paddingTop, min: 0, max: 200, __nextHasNoMarginBottom: true, onChange: function (v) { set({ paddingTop: v }); } }), |
| 162 |
el('div', { style: { marginTop: '12px' } }, |
| 163 |
el(RangeControl, { label: __('Padding Bottom', 'blockenberg'), value: attr.paddingBottom, min: 0, max: 200, __nextHasNoMarginBottom: true, onChange: function (v) { set({ paddingBottom: v }); } }) |
| 164 |
), |
| 165 |
el('div', { style: { marginTop: '12px' } }, |
| 166 |
el(RangeControl, { label: __('Max Width (px)', 'blockenberg'), value: attr.maxWidth, min: 600, max: 1600, step: 20, __nextHasNoMarginBottom: true, onChange: function (v) { set({ maxWidth: v }); } }) |
| 167 |
) |
| 168 |
), |
| 169 |
el(PanelBody, { title: __('Typography', 'blockenberg'), initialOpen: false }, |
| 170 |
(function(){ var C = getTypoControl(); return C ? [ |
| 171 |
el(C, { key: 'eyebrow', label: __('Eyebrow', 'blockenberg'), value: attr.eyebrowTypo || {}, onChange: function(v){ set({eyebrowTypo: v}); } }), |
| 172 |
el(C, { key: 'heading', label: __('Heading', 'blockenberg'), value: attr.headingTypo || {}, onChange: function(v){ set({headingTypo: v}); } }), |
| 173 |
el(C, { key: 'subtext', label: __('Subtext', 'blockenberg'), value: attr.subtextTypo || {}, onChange: function(v){ set({subtextTypo: v}); } }), |
| 174 |
el(C, { key: 'role', label: __('Role Title', 'blockenberg'), value: attr.roleTypo || {}, onChange: function(v){ set({roleTypo: v}); } }), |
| 175 |
el(C, { key: 'desc', label: __('Description', 'blockenberg'), value: attr.descTypo || {}, onChange: function(v){ set({descTypo: v}); } }), |
| 176 |
el(C, { key: 'item', label: __('List Items', 'blockenberg'), value: attr.itemTypo || {}, onChange: function(v){ set({itemTypo: v}); } }) |
| 177 |
] : null; })() |
| 178 |
), |
| 179 |
el(PanelColorSettings, { |
| 180 |
title: __('Colors', 'blockenberg'), initialOpen: false, |
| 181 |
colorSettings: [ |
| 182 |
{ label: __('Background', 'blockenberg'), value: attr.bgColor, onChange: function (v) { set({ bgColor: v || '#ffffff' }); } }, |
| 183 |
{ label: __('Accent', 'blockenberg'), value: attr.accentColor, onChange: function (v) { set({ accentColor: v || '#6366f1' }); } }, |
| 184 |
{ label: __('Eyebrow', 'blockenberg'), value: attr.eyebrowColor, onChange: function (v) { set({ eyebrowColor: v || '#6366f1' }); } }, |
| 185 |
{ label: __('Heading', 'blockenberg'), value: attr.headingColor, onChange: function (v) { set({ headingColor: v || '#111827' }); } }, |
| 186 |
{ label: __('Subtext', 'blockenberg'), value: attr.subColor, onChange: function (v) { set({ subColor: v || '#6b7280' }); } }, |
| 187 |
{ label: __('Card Background', 'blockenberg'), value: attr.cardBg, onChange: function (v) { set({ cardBg: v || '#f8fafc' }); } }, |
| 188 |
{ label: __('Card Border', 'blockenberg'), value: attr.cardBorder, onChange: function (v) { set({ cardBorder: v || '#e2e8f0' }); } }, |
| 189 |
{ label: __('Icon Background', 'blockenberg'), value: attr.iconBg, onChange: function (v) { set({ iconBg: v || '#ede9fe' }); } }, |
| 190 |
{ label: __('Role Title', 'blockenberg'), value: attr.roleColor, onChange: function (v) { set({ roleColor: v || '#111827' }); } }, |
| 191 |
{ label: __('Description', 'blockenberg'), value: attr.descColor, onChange: function (v) { set({ descColor: v || '#6b7280' }); } }, |
| 192 |
{ label: __('Pain Point Text', 'blockenberg'), value: attr.painColor, onChange: function (v) { set({ painColor: v || '#374151' }); } }, |
| 193 |
{ label: __('Pain Point Icon', 'blockenberg'), value: attr.painIconColor, onChange: function (v) { set({ painIconColor: v || '#ef4444' }); } }, |
| 194 |
{ label: __('Benefit Text', 'blockenberg'), value: attr.benefitColor, onChange: function (v) { set({ benefitColor: v || '#374151' }); } }, |
| 195 |
{ label: __('Benefit Icon', 'blockenberg'), value: attr.benefitIconColor, onChange: function (v) { set({ benefitIconColor: v || '#22c55e' }); } } |
| 196 |
] |
| 197 |
}) |
| 198 |
); |
| 199 |
|
| 200 |
return el('div', blockProps, |
| 201 |
controls, |
| 202 |
el('div', { style: { padding: attr.paddingTop + 'px 32px ' + attr.paddingBottom + 'px', maxWidth: attr.maxWidth + 'px', margin: '0 auto' } }, |
| 203 |
el('div', { style: { textAlign: 'center', marginBottom: '48px' } }, |
| 204 |
el('p', { className: 'bkbg-per-eyebrow', style: { color: attr.eyebrowColor, margin: '0 0 12px' } }, attr.eyebrow), |
| 205 |
el(RichText, { tagName: 'h2', className: 'bkbg-per-heading', value: attr.heading, style: { color: attr.headingColor, margin: '0 0 16px' }, placeholder: __('Heading…', 'blockenberg'), onChange: function (v) { set({ heading: v }); } }), |
| 206 |
el(RichText, { tagName: 'p', className: 'bkbg-per-sub', value: attr.subtext, style: { color: attr.subColor, margin: '0 auto', maxWidth: '640px' }, placeholder: __('Subtext…', 'blockenberg'), onChange: function (v) { set({ subtext: v }); } }) |
| 207 |
), |
| 208 |
el('div', { style: { display: 'grid', gridTemplateColumns: 'repeat(' + attr.columns + ',1fr)', gap: '24px' } }, |
| 209 |
(attr.personas || []).map(function (p) { return PersonaCard(p); }) |
| 210 |
) |
| 211 |
) |
| 212 |
); |
| 213 |
}, |
| 214 |
save: function (props) { |
| 215 |
var attr = props.attributes; |
| 216 |
var useBlockProps = wp.blockEditor.useBlockProps; |
| 217 |
return el('div', useBlockProps.save(), |
| 218 |
el('div', { className: 'bkbg-per-app', 'data-opts': JSON.stringify(attr) }) |
| 219 |
); |
| 220 |
} |
| 221 |
}); |
| 222 |
}() ); |
| 223 |
|