| 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 _tc, _tvf; |
| 17 |
Object.defineProperty(window, '_bkbgTypoCtrlCache', { get: function () { if (!_tc) { _tc = window.bkbgTypographyControl; } return _tc; } }); |
| 18 |
Object.defineProperty(window, '_bkbgTypoVarsCache', { get: function () { if (!_tvf) { _tvf = window.bkbgTypoCssVars; } return _tvf; } }); |
| 19 |
function getTypoControl(props, attrName, label) { return window._bkbgTypoCtrlCache(props, attrName, label); } |
| 20 |
|
| 21 |
var _IP; |
| 22 |
function IP() { return _IP || (_IP = window.bkbgIconPicker); } |
| 23 |
|
| 24 |
var STYLE_OPTIONS = [ |
| 25 |
{ value: 'highlight', label: 'Highlight (accent fill)' }, |
| 26 |
{ value: 'minimal', label: 'Minimal (clean border)' }, |
| 27 |
{ value: 'card', label: 'Card (shadow)' }, |
| 28 |
{ value: 'sidebar', label: 'Sidebar (left stripe)' } |
| 29 |
]; |
| 30 |
|
| 31 |
registerBlockType('blockenberg/tldr-box', { |
| 32 |
edit: function (props) { |
| 33 |
var attr = props.attributes; |
| 34 |
var set = props.setAttributes; |
| 35 |
var points = attr.points || [{ text: '' }]; |
| 36 |
|
| 37 |
var blockProps = (function () { |
| 38 |
var s = { paddingTop: attr.paddingTop + 'px', paddingBottom: attr.paddingBottom + 'px' }; |
| 39 |
var tv = Object.assign({}, window._bkbgTypoVarsCache(attr.headingTypo, '--bktldr-ht-'), window._bkbgTypoVarsCache(attr.summaryTypo, '--bktldr-st-')); |
| 40 |
for (var k in tv) s[k] = tv[k]; |
| 41 |
return useBlockProps({ style: s }); |
| 42 |
}()); |
| 43 |
|
| 44 |
function updatePoint(idx, val) { |
| 45 |
set({ points: points.map(function (p, i) { return i === idx ? { text: val } : p; }) }); |
| 46 |
} |
| 47 |
|
| 48 |
var wrapStyle = { |
| 49 |
background: attr.bgColor, |
| 50 |
borderRadius: attr.borderRadius + 'px', |
| 51 |
overflow: 'hidden', |
| 52 |
position: 'relative' |
| 53 |
}; |
| 54 |
if (attr.style === 'highlight') { |
| 55 |
wrapStyle.border = '1px solid ' + attr.borderColor; |
| 56 |
wrapStyle.padding = '18px 22px'; |
| 57 |
} else if (attr.style === 'minimal') { |
| 58 |
wrapStyle.border = '1px solid ' + attr.borderColor; |
| 59 |
wrapStyle.padding = '18px 22px'; |
| 60 |
wrapStyle.background = 'transparent'; |
| 61 |
} else if (attr.style === 'card') { |
| 62 |
wrapStyle.border = '1px solid ' + attr.borderColor; |
| 63 |
wrapStyle.padding = '20px 24px'; |
| 64 |
wrapStyle.boxShadow = '0 4px 14px rgba(0,0,0,0.08)'; |
| 65 |
} else if (attr.style === 'sidebar') { |
| 66 |
wrapStyle.borderLeft = '5px solid ' + attr.accentColor; |
| 67 |
wrapStyle.borderTop = '1px solid ' + attr.borderColor; |
| 68 |
wrapStyle.borderRight = '1px solid ' + attr.borderColor; |
| 69 |
wrapStyle.borderBottom = '1px solid ' + attr.borderColor; |
| 70 |
wrapStyle.padding = '18px 22px'; |
| 71 |
} |
| 72 |
|
| 73 |
var controls = el(InspectorControls, {}, |
| 74 |
el(PanelBody, { title: __('Content', 'blockenberg'), initialOpen: true }, |
| 75 |
el(ToggleControl, { label: __('Show Icon', 'blockenberg'), checked: attr.showIcon, __nextHasNoMarginBottom: true, onChange: function (v) { set({ showIcon: v }); } }), |
| 76 |
attr.showIcon && el('div', { style: { marginTop: '8px' } }, |
| 77 |
el(IP().IconPickerControl, IP().iconPickerProps(attr, set, { charAttr: 'headingIcon' })) |
| 78 |
), |
| 79 |
el('div', { style: { marginTop: '8px' } }, |
| 80 |
el(TextControl, { label: __('Heading Text', 'blockenberg'), value: attr.heading, __nextHasNoMarginBottom: true, onChange: function (v) { set({ heading: v }); } }) |
| 81 |
), |
| 82 |
el('div', { style: { marginTop: '8px' } }, |
| 83 |
el(ToggleControl, { label: __('Show Bullet Points', 'blockenberg'), checked: attr.showPoints, __nextHasNoMarginBottom: true, onChange: function (v) { set({ showPoints: v }); } }) |
| 84 |
), |
| 85 |
el('div', { style: { marginTop: '8px' } }, |
| 86 |
el(ToggleControl, { label: __('Show Read Time', 'blockenberg'), checked: attr.showReadTime, __nextHasNoMarginBottom: true, onChange: function (v) { set({ showReadTime: v }); } }) |
| 87 |
), |
| 88 |
attr.showReadTime && el('div', { style: { marginTop: '8px' } }, |
| 89 |
el(TextControl, { label: __('Read Time', 'blockenberg'), value: attr.readTime, placeholder: '8 min read', __nextHasNoMarginBottom: true, onChange: function (v) { set({ readTime: v }); } }) |
| 90 |
), |
| 91 |
el('div', { style: { marginTop: '8px' } }, |
| 92 |
el(ToggleControl, { label: __('Expandable (show/hide toggle)', 'blockenberg'), checked: attr.expandable, __nextHasNoMarginBottom: true, onChange: function (v) { set({ expandable: v }); } }) |
| 93 |
), |
| 94 |
attr.expandable && el('div', { style: { marginTop: '8px' } }, |
| 95 |
el(TextControl, { label: __('Collapse Label', 'blockenberg'), value: attr.collapseLabel, __nextHasNoMarginBottom: true, onChange: function (v) { set({ collapseLabel: v }); } }) |
| 96 |
), |
| 97 |
attr.expandable && el('div', { style: { marginTop: '8px' } }, |
| 98 |
el(TextControl, { label: __('Expand Label', 'blockenberg'), value: attr.expandLabel, __nextHasNoMarginBottom: true, onChange: function (v) { set({ expandLabel: v }); } }) |
| 99 |
) |
| 100 |
), |
| 101 |
el(PanelBody, { title: __('Style & Spacing', 'blockenberg'), initialOpen: false }, |
| 102 |
el(SelectControl, { label: __('Style', 'blockenberg'), value: attr.style, options: STYLE_OPTIONS, __nextHasNoMarginBottom: true, onChange: function (v) { set({ style: v }); } }), |
| 103 |
el('div', { style: { marginTop: '10px' } }, |
| 104 |
el(RangeControl, { label: __('Border Radius', 'blockenberg'), value: attr.borderRadius, min: 0, max: 30, __nextHasNoMarginBottom: true, onChange: function (v) { set({ borderRadius: v }); } }) |
| 105 |
), |
| 106 |
el('div', { style: { marginTop: '10px' } }, |
| 107 |
el(RangeControl, { label: __('Padding Top', 'blockenberg'), value: attr.paddingTop, min: 0, max: 100, __nextHasNoMarginBottom: true, onChange: function (v) { set({ paddingTop: v }); } }) |
| 108 |
), |
| 109 |
el('div', { style: { marginTop: '10px' } }, |
| 110 |
el(RangeControl, { label: __('Padding Bottom', 'blockenberg'), value: attr.paddingBottom, min: 0, max: 100, __nextHasNoMarginBottom: true, onChange: function (v) { set({ paddingBottom: v }); } }) |
| 111 |
) |
| 112 |
), |
| 113 |
el(PanelBody, { title: __('Typography', 'blockenberg'), initialOpen: false }, |
| 114 |
getTypoControl(props, 'headingTypo', __('Heading', 'blockenberg')), |
| 115 |
getTypoControl(props, 'summaryTypo', __('Summary', 'blockenberg')) |
| 116 |
), |
| 117 |
el(PanelColorSettings, { |
| 118 |
title: __('Colors', 'blockenberg'), initialOpen: false, |
| 119 |
colorSettings: [ |
| 120 |
{ label: __('Background', 'blockenberg'), value: attr.bgColor, onChange: function (v) { set({ bgColor: v || '#fef9c3' }); } }, |
| 121 |
{ label: __('Border', 'blockenberg'), value: attr.borderColor, onChange: function (v) { set({ borderColor: v || '#fde047' }); } }, |
| 122 |
{ label: __('Accent', 'blockenberg'), value: attr.accentColor, onChange: function (v) { set({ accentColor: v || '#ca8a04' }); } }, |
| 123 |
{ label: __('Heading', 'blockenberg'), value: attr.headingColor, onChange: function (v) { set({ headingColor: v || '#713f12' }); } }, |
| 124 |
{ label: __('Icon', 'blockenberg'), value: attr.iconColor, onChange: function (v) { set({ iconColor: v || '#ca8a04' }); } }, |
| 125 |
{ label: __('Summary', 'blockenberg'), value: attr.summaryColor, onChange: function (v) { set({ summaryColor: v || '#1c1917' }); } }, |
| 126 |
{ label: __('Bullet Points', 'blockenberg'), value: attr.pointColor, onChange: function (v) { set({ pointColor: v || '#292524' }); } }, |
| 127 |
{ label: __('Meta / Read Time', 'blockenberg'), value: attr.metaColor, onChange: function (v) { set({ metaColor: v || '#a8a29e' }); } } |
| 128 |
] |
| 129 |
}) |
| 130 |
); |
| 131 |
|
| 132 |
/* header row */ |
| 133 |
var headerRow = el('div', { style: { display: 'flex', alignItems: 'center', gap: '8px', marginBottom: '10px', flexWrap: 'wrap' } }, |
| 134 |
attr.showIcon && IP().buildEditorIcon(attr.iconType, attr.headingIcon, attr.iconDashicon, attr.iconImageUrl, { dashiconColor: attr.iconDashiconColor, style: { fontSize: '20px', lineHeight: 1, display: 'inline-flex', alignItems: 'center', justifyContent: 'center', color: attr.iconColor } }), |
| 135 |
el('span', { className: 'bkbg-tldr-heading', style: { color: attr.headingColor } }, attr.heading), |
| 136 |
attr.showReadTime && attr.readTime && el('span', { style: { marginLeft: 'auto', fontSize: '12px', color: attr.metaColor, fontWeight: 500 } }, attr.readTime) |
| 137 |
); |
| 138 |
|
| 139 |
/* summary */ |
| 140 |
var summaryEl = el(RichText, { |
| 141 |
tagName: 'p', value: attr.summary, className: 'bkbg-tldr-summary', |
| 142 |
allowedFormats: ['core/bold', 'core/italic', 'core/link'], |
| 143 |
placeholder: __('One or two sentence summary of the article…', 'blockenberg'), |
| 144 |
style: { color: attr.summaryColor }, |
| 145 |
onChange: function (v) { set({ summary: v }); } |
| 146 |
}); |
| 147 |
|
| 148 |
/* point list */ |
| 149 |
var pointList = attr.showPoints && el('div', {}, |
| 150 |
el('div', { style: { borderTop: '1px solid ' + attr.borderColor + '80', marginBottom: '10px', marginTop: '8px' } }), |
| 151 |
points.map(function (p, idx) { |
| 152 |
return el('div', { key: idx, style: { display: 'flex', alignItems: 'center', gap: '8px', marginBottom: '5px' } }, |
| 153 |
el('span', { style: { color: attr.accentColor, fontWeight: 700, fontSize: '16px', flexShrink: 0, lineHeight: 1 } }, '✓'), |
| 154 |
el(TextControl, { value: p.text, label: '', placeholder: __('Bullet point…', 'blockenberg'), __nextHasNoMarginBottom: true, style: { flex: 1, fontSize: '14px' }, onChange: function (v) { updatePoint(idx, v); } }), |
| 155 |
el(Button, { isSmall: true, isDestructive: true, variant: 'tertiary', onClick: function () { set({ points: points.filter(function (_, i) { return i !== idx; }) }); } }, '×') |
| 156 |
) }), |
| 157 |
el(Button, { variant: 'link', style: { fontSize: '11px' }, onClick: function () { set({ points: points.concat([{ text: '' }]) }); } }, '+ Add Point') |
| 158 |
); |
| 159 |
|
| 160 |
return el('div', blockProps, |
| 161 |
controls, |
| 162 |
el('div', { style: wrapStyle }, |
| 163 |
headerRow, |
| 164 |
summaryEl, |
| 165 |
pointList, |
| 166 |
attr.expandable && el('div', { style: { marginTop: '10px', fontSize: '12px', color: attr.accentColor, fontWeight: 600, cursor: 'pointer' } }, '▼ ' + attr.collapseLabel) |
| 167 |
) |
| 168 |
); |
| 169 |
}, |
| 170 |
save: function (props) { |
| 171 |
var attr = props.attributes; |
| 172 |
var useBlockProps = wp.blockEditor.useBlockProps; |
| 173 |
return el('div', (function () { |
| 174 |
var s = {}; |
| 175 |
var tv = Object.assign({}, window._bkbgTypoVarsCache(attr.headingTypo, '--bktldr-ht-'), window._bkbgTypoVarsCache(attr.summaryTypo, '--bktldr-st-')); |
| 176 |
for (var k in tv) s[k] = tv[k]; |
| 177 |
return useBlockProps.save({ style: s }); |
| 178 |
}()), |
| 179 |
el('div', { className: 'bkbg-tldr-app', 'data-opts': JSON.stringify(attr) }) |
| 180 |
); |
| 181 |
} |
| 182 |
}); |
| 183 |
}() ); |
| 184 |
|