| 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 Button = wp.components.Button; |
| 15 |
|
| 16 |
var _evrTC, _evrTV; |
| 17 |
function _tc() { return _evrTC || (_evrTC = window.bkbgTypographyControl); } |
| 18 |
function _tv(t, p) { return (_evrTV || (_evrTV = window.bkbgTypoCssVars)) ? _evrTV(t, p) : {}; } |
| 19 |
var IP = function () { return window.bkbgIconPicker; }; |
| 20 |
|
| 21 |
function updateArr(arr, idx, key, val) { |
| 22 |
return arr.map(function (item, i) { |
| 23 |
if (i !== idx) return item; |
| 24 |
var c = Object.assign({}, item); c[key] = val; return c; |
| 25 |
}); |
| 26 |
} |
| 27 |
|
| 28 |
registerBlockType('blockenberg/event-recap', { |
| 29 |
edit: function (props) { |
| 30 |
var attr = props.attributes; |
| 31 |
var set = props.setAttributes; |
| 32 |
var stats = attr.stats || []; |
| 33 |
var highlights = attr.highlights || []; |
| 34 |
|
| 35 |
var blockProps = useBlockProps({ style: Object.assign({ padding: attr.paddingTop + 'px 0 ' + attr.paddingBottom + 'px', background: attr.bgColor, borderRadius: attr.borderRadius + 'px', overflow: 'hidden' }, |
| 36 |
_tv(attr.typoTitle || {}, '--bkbg-evr-ttl-'), |
| 37 |
_tv(attr.typoSummary || {}, '--bkbg-evr-sm-') |
| 38 |
) }); |
| 39 |
|
| 40 |
var controls = el(InspectorControls, {}, |
| 41 |
el(PanelBody, { title: __('Event Info', 'blockenberg'), initialOpen: true }, |
| 42 |
el(ToggleControl, { label: __('Show Date & Location', 'blockenberg'), checked: attr.showMeta, __nextHasNoMarginBottom: true, onChange: function (v) { set({ showMeta: v }); } }), |
| 43 |
el('div', { style: { marginTop: '8px' } }, |
| 44 |
el(ToggleControl, { label: __('Show Summary', 'blockenberg'), checked: attr.showSummary, __nextHasNoMarginBottom: true, onChange: function (v) { set({ showSummary: v }); } }) |
| 45 |
), |
| 46 |
el('div', { style: { marginTop: '8px' } }, |
| 47 |
el(ToggleControl, { label: __('Show Stats Bar', 'blockenberg'), checked: attr.showStats, __nextHasNoMarginBottom: true, onChange: function (v) { set({ showStats: v }); } }) |
| 48 |
), |
| 49 |
el('div', { style: { marginTop: '8px' } }, |
| 50 |
el(ToggleControl, { label: __('Show Highlights', 'blockenberg'), checked: attr.showHighlights, __nextHasNoMarginBottom: true, onChange: function (v) { set({ showHighlights: v }); } }) |
| 51 |
), |
| 52 |
attr.showHighlights && el('div', { style: { marginTop: '8px' } }, |
| 53 |
el(TextControl, { label: __('Highlights Label', 'blockenberg'), value: attr.highlightsLabel, __nextHasNoMarginBottom: true, onChange: function (v) { set({ highlightsLabel: v }); } }) |
| 54 |
), |
| 55 |
el('div', { style: { marginTop: '8px' } }, |
| 56 |
el(ToggleControl, { label: __('Show Next Event', 'blockenberg'), checked: attr.showNextEvent, __nextHasNoMarginBottom: true, onChange: function (v) { set({ showNextEvent: v }); } }) |
| 57 |
) |
| 58 |
), |
| 59 |
el(PanelBody, { title: __('Spacing', 'blockenberg'), initialOpen: false }, |
| 60 |
el(RangeControl, { label: __('Border Radius', 'blockenberg'), value: attr.borderRadius, min: 0, max: 30, __nextHasNoMarginBottom: true, onChange: function (v) { set({ borderRadius: v }); } }), |
| 61 |
el('div', { style: { marginTop: '12px' } }, |
| 62 |
el(RangeControl, { label: __('Padding Top', 'blockenberg'), value: attr.paddingTop, min: 0, max: 100, __nextHasNoMarginBottom: true, onChange: function (v) { set({ paddingTop: v }); } }) |
| 63 |
), |
| 64 |
el('div', { style: { marginTop: '12px' } }, |
| 65 |
el(RangeControl, { label: __('Padding Bottom', 'blockenberg'), value: attr.paddingBottom, min: 0, max: 100, __nextHasNoMarginBottom: true, onChange: function (v) { set({ paddingBottom: v }); } }) |
| 66 |
) |
| 67 |
), |
| 68 |
el(PanelBody, { title: __('Typography', 'blockenberg'), initialOpen: false }, |
| 69 |
_tc() && el(_tc(), { label: 'Event Title', typo: attr.typoTitle || {}, onChange: function (v) { set({ typoTitle: v }); } }), |
| 70 |
_tc() && el(_tc(), { label: 'Summary', typo: attr.typoSummary || {}, onChange: function (v) { set({ typoSummary: v }); } }) |
| 71 |
), |
| 72 |
el(PanelColorSettings, { |
| 73 |
title: __('Colors', 'blockenberg'), initialOpen: false, |
| 74 |
colorSettings: [ |
| 75 |
{ label: __('Background', 'blockenberg'), value: attr.bgColor, onChange: function (v) { set({ bgColor: v || '#f8fafc' }); } }, |
| 76 |
{ label: __('Border', 'blockenberg'), value: attr.borderColor, onChange: function (v) { set({ borderColor: v || '#e2e8f0' }); } }, |
| 77 |
{ label: __('Accent', 'blockenberg'), value: attr.accentColor, onChange: function (v) { set({ accentColor: v || '#7c3aed' }); } }, |
| 78 |
{ label: __('Header Background', 'blockenberg'), value: attr.headerBg, onChange: function (v) { set({ headerBg: v || '#7c3aed' }); } }, |
| 79 |
{ label: __('Event Title', 'blockenberg'), value: attr.titleColor, onChange: function (v) { set({ titleColor: v || '#ffffff' }); } }, |
| 80 |
{ label: __('Date / Location', 'blockenberg'), value: attr.metaColor, onChange: function (v) { set({ metaColor: v || '#ddd6fe' }); } }, |
| 81 |
{ label: __('Summary Text', 'blockenberg'), value: attr.summaryColor, onChange: function (v) { set({ summaryColor: v || '#374151' }); } }, |
| 82 |
{ label: __('Stats Bar BG', 'blockenberg'), value: attr.statsBg, onChange: function (v) { set({ statsBg: v || '#7c3aed' }); } }, |
| 83 |
{ label: __('Stat Number', 'blockenberg'), value: attr.statNumColor, onChange: function (v) { set({ statNumColor: v || '#ffffff' }); } }, |
| 84 |
{ label: __('Stat Label', 'blockenberg'), value: attr.statLabelColor, onChange: function (v) { set({ statLabelColor: v || '#ddd6fe' }); } }, |
| 85 |
{ label: __('Highlight BG', 'blockenberg'), value: attr.highlightBg, onChange: function (v) { set({ highlightBg: v || '#ffffff' }); } }, |
| 86 |
{ label: __('Highlight Border', 'blockenberg'), value: attr.highlightBorder, onChange: function (v) { set({ highlightBorder: v || '#e2e8f0' }); } }, |
| 87 |
{ label: __('Highlight Text', 'blockenberg'), value: attr.highlightColor, onChange: function (v) { set({ highlightColor: v || '#374151' }); } }, |
| 88 |
{ label: __('Next Event BG', 'blockenberg'), value: attr.nextBg, onChange: function (v) { set({ nextBg: v || '#ede9fe' }); } }, |
| 89 |
{ label: __('Next Event Text', 'blockenberg'), value: attr.nextTextColor, onChange: function (v) { set({ nextTextColor: v || '#5b21b6' }); } } |
| 90 |
] |
| 91 |
}) |
| 92 |
); |
| 93 |
|
| 94 |
/* Header */ |
| 95 |
var headerEl = el('div', { style: { background: attr.headerBg, padding: '24px 24px 20px' } }, |
| 96 |
el(RichText, { tagName: 'h2', className: 'bkbg-evr-title', value: attr.eventName, allowedFormats: ['core/bold'], placeholder: __('Event Name', 'blockenberg'), style: { margin: '0 0 8px', color: attr.titleColor }, onChange: function (v) { set({ eventName: v }); } }), |
| 97 |
attr.showMeta && el('div', { style: { display: 'flex', gap: '16px', flexWrap: 'wrap' } }, |
| 98 |
el(TextControl, { value: attr.eventDate, label: '', placeholder: '� |
| 99 |
Date', __nextHasNoMarginBottom: true, style: { color: attr.metaColor, fontSize: '14px', width: '180px' }, onChange: function (v) { set({ eventDate: v }); } }), |
| 100 |
el(TextControl, { value: attr.eventLocation, label: '', placeholder: '📍 Location', __nextHasNoMarginBottom: true, style: { color: attr.metaColor, fontSize: '14px', width: '200px' }, onChange: function (v) { set({ eventLocation: v }); } }) |
| 101 |
) |
| 102 |
); |
| 103 |
|
| 104 |
/* Stats */ |
| 105 |
var statsEl = attr.showStats && el('div', { style: { background: attr.statsBg, padding: '2px 24px' } }, |
| 106 |
el('div', { style: { display: 'grid', gridTemplateColumns: 'repeat(' + Math.min(stats.length, 4) + ', 1fr)', gap: '2px' } }, |
| 107 |
stats.map(function (s, idx) { |
| 108 |
return el('div', { key: idx, style: { textAlign: 'center', padding: '16px 8px' } }, |
| 109 |
el(TextControl, { value: s.number, label: '', placeholder: '0', __nextHasNoMarginBottom: true, style: { fontWeight: 800, fontSize: '26px', color: attr.statNumColor, textAlign: 'center' }, onChange: function (v) { set({ stats: updateArr(stats, idx, 'number', v) }); } }), |
| 110 |
el(TextControl, { value: s.label, label: '', placeholder: __('Label', 'blockenberg'), __nextHasNoMarginBottom: true, style: { fontSize: '11px', color: attr.statLabelColor, textTransform: 'uppercase', letterSpacing: '0.05em', textAlign: 'center' }, onChange: function (v) { set({ stats: updateArr(stats, idx, 'label', v) }); } }), |
| 111 |
el(Button, { variant: 'link', isDestructive: true, style: { fontSize: '10px', color: attr.statLabelColor }, onClick: function () { set({ stats: stats.filter(function (_, i) { return i !== idx; }) }); } }, '×') |
| 112 |
); |
| 113 |
}), |
| 114 |
el('div', { style: { textAlign: 'center', padding: '16px 8px' } }, |
| 115 |
el(Button, { variant: 'secondary', isSmall: true, onClick: function () { set({ stats: stats.concat([{ number: '0', label: 'Metric' }]) }); } }, '+') |
| 116 |
) |
| 117 |
) |
| 118 |
); |
| 119 |
|
| 120 |
/* Body */ |
| 121 |
var bodyEl = el('div', { style: { padding: '20px 24px' } }, |
| 122 |
attr.showSummary && el(RichText, { tagName: 'p', className: 'bkbg-evr-summary', value: attr.summary, allowedFormats: ['core/bold', 'core/italic', 'core/link'], placeholder: __('Event summary paragraph…', 'blockenberg'), style: { margin: '0 0 20px', color: attr.summaryColor }, onChange: function (v) { set({ summary: v }); } }), |
| 123 |
attr.showHighlights && el('div', {}, |
| 124 |
el('div', { style: { fontSize: '13px', fontWeight: 700, textTransform: 'uppercase', letterSpacing: '0.05em', color: attr.accentColor, marginBottom: '12px' } }, attr.highlightsLabel || 'Key Highlights'), |
| 125 |
el('div', { style: { display: 'flex', flexDirection: 'column', gap: '8px' } }, |
| 126 |
highlights.map(function (h, idx) { |
| 127 |
return el('div', { key: idx, style: { display: 'flex', alignItems: 'center', gap: '10px', background: attr.highlightBg, border: '1px solid ' + attr.highlightBorder, borderRadius: '8px', padding: '10px 14px' } }, |
| 128 |
el('div', { style: { flexShrink: 0 } }, |
| 129 |
el(IP().IconPickerControl, { |
| 130 |
iconType: h.iconType, customChar: h.icon, dashicon: h.iconDashicon, imageUrl: h.iconImageUrl, |
| 131 |
onChangeType: function (v) { set({ highlights: updateArr(highlights, idx, 'iconType', v) }); }, |
| 132 |
onChangeChar: function (v) { set({ highlights: updateArr(highlights, idx, 'icon', v) }); }, |
| 133 |
onChangeDashicon: function (v) { set({ highlights: updateArr(highlights, idx, 'iconDashicon', v) }); }, |
| 134 |
onChangeImageUrl: function (v) { set({ highlights: updateArr(highlights, idx, 'iconImageUrl', v) }); } |
| 135 |
}) |
| 136 |
), |
| 137 |
el(TextControl, { value: h.text, label: '', placeholder: __('Highlight text…', 'blockenberg'), __nextHasNoMarginBottom: true, style: { flex: '1', fontSize: '14px', color: attr.highlightColor }, onChange: function (v) { set({ highlights: updateArr(highlights, idx, 'text', v) }); } }), |
| 138 |
el(Button, { variant: 'link', isDestructive: true, style: { fontSize: '11px' }, onClick: function () { set({ highlights: highlights.filter(function (_, i) { return i !== idx; }) }); } }, '×') |
| 139 |
); |
| 140 |
}), |
| 141 |
el(Button, { variant: 'secondary', style: { marginTop: '6px' }, onClick: function () { set({ highlights: highlights.concat([{ icon: '⭐', text: '', iconType: 'custom-char', iconDashicon: '', iconImageUrl: '' }]) }); } }, __('+ Add Highlight', 'blockenberg')) |
| 142 |
) |
| 143 |
), |
| 144 |
attr.showNextEvent && el('div', { style: { marginTop: '20px', background: attr.nextBg, borderRadius: '8px', padding: '12px 16px' } }, |
| 145 |
el(TextControl, { value: attr.nextEventInfo, label: __('Next Event Info', 'blockenberg'), placeholder: __('Next event: March 2027 — Berlin', 'blockenberg'), __nextHasNoMarginBottom: true, style: { color: attr.nextTextColor, fontSize: '14px', fontWeight: 600 }, onChange: function (v) { set({ nextEventInfo: v }); } }) |
| 146 |
) |
| 147 |
); |
| 148 |
|
| 149 |
return el('div', blockProps, |
| 150 |
controls, |
| 151 |
headerEl, |
| 152 |
statsEl, |
| 153 |
bodyEl |
| 154 |
); |
| 155 |
}, |
| 156 |
save: function (props) { |
| 157 |
var attr = props.attributes; |
| 158 |
var useBlockProps = wp.blockEditor.useBlockProps; |
| 159 |
return el('div', useBlockProps.save(), |
| 160 |
el('div', { className: 'bkbg-evr-app', 'data-opts': JSON.stringify(attr) }) |
| 161 |
); |
| 162 |
} |
| 163 |
}); |
| 164 |
}() ); |
| 165 |
|