| 1 |
( function () { |
| 2 |
var el = wp.element.createElement; |
| 3 |
var useState = wp.element.useState; |
| 4 |
var Fragment = wp.element.Fragment; |
| 5 |
var registerBlockType = wp.blocks.registerBlockType; |
| 6 |
var __ = wp.i18n.__; |
| 7 |
var InspectorControls = wp.blockEditor.InspectorControls; |
| 8 |
var PanelColorSettings = wp.blockEditor.PanelColorSettings; |
| 9 |
var useBlockProps = wp.blockEditor.useBlockProps; |
| 10 |
var PanelBody = wp.components.PanelBody; |
| 11 |
var RangeControl = wp.components.RangeControl; |
| 12 |
var SelectControl = wp.components.SelectControl; |
| 13 |
var TextControl = wp.components.TextControl; |
| 14 |
var ToggleControl = wp.components.ToggleControl; |
| 15 |
var Button = wp.components.Button; |
| 16 |
|
| 17 |
var _TypographyControl, _typoCssVars; |
| 18 |
function getTypographyControl() { return _TypographyControl || (_TypographyControl = window.bkbgTypographyControl); } |
| 19 |
function getTypoCssVars() { return _typoCssVars || (_typoCssVars = window.bkbgTypoCssVars); } |
| 20 |
|
| 21 |
var IP = function () { return window.bkbgIconPicker; }; |
| 22 |
|
| 23 |
/* ── Bullet symbols by style ─────────────────────────────────────────── */ |
| 24 |
var BULLET_SYMBOLS = { |
| 25 |
check: '✓', |
| 26 |
check2: '✔', |
| 27 |
arrow: '→', |
| 28 |
circle: '●', |
| 29 |
star: '� |
| 30 |
', |
| 31 |
diamond: '◆', |
| 32 |
dash: '—', |
| 33 |
custom: null, |
| 34 |
}; |
| 35 |
|
| 36 |
var BULLET_STYLE_OPTIONS = [ |
| 37 |
{ value: 'check', label: '✓ Checkmark' }, |
| 38 |
{ value: 'check2', label: '✔ Bold Check' }, |
| 39 |
{ value: 'arrow', label: '→ Arrow' }, |
| 40 |
{ value: 'circle', label: '● Circle' }, |
| 41 |
{ value: 'star', label: '� |
| 42 |
Star' }, |
| 43 |
{ value: 'diamond', label: '◆ Diamond' }, |
| 44 |
{ value: 'dash', label: '— Dash' }, |
| 45 |
{ value: 'custom', label: 'Custom Symbol' }, |
| 46 |
]; |
| 47 |
|
| 48 |
var BORDER_POSITION_OPTIONS = [ |
| 49 |
{ value: 'left', label: 'Left Border' }, |
| 50 |
{ value: 'top', label: 'Top Border' }, |
| 51 |
{ value: 'all', label: 'All Sides' }, |
| 52 |
{ value: 'none', label: 'No Border' }, |
| 53 |
]; |
| 54 |
|
| 55 |
function getBullet(attrs) { |
| 56 |
if (attrs.bulletStyle === 'custom') return attrs.customBullet || '→'; |
| 57 |
return BULLET_SYMBOLS[attrs.bulletStyle] || '✓'; |
| 58 |
} |
| 59 |
|
| 60 |
/* ── Preview component ────────────────────────────────────────────────── */ |
| 61 |
function TakeawaysPreview(props) { |
| 62 |
var a = props.attrs; |
| 63 |
var setA = props.setAttrs; |
| 64 |
var accent = a.accentColor || '#6c3fb5'; |
| 65 |
var cRadius= (a.cardRadius || 12) + 'px'; |
| 66 |
var bullet = getBullet(a); |
| 67 |
|
| 68 |
/* Card border style */ |
| 69 |
var borderStyle = {}; |
| 70 |
if (a.borderPosition === 'left') { |
| 71 |
borderStyle = { borderLeft: (a.borderWidth || 4) + 'px solid ' + (a.borderColor || accent) }; |
| 72 |
} else if (a.borderPosition === 'top') { |
| 73 |
borderStyle = { borderTop: (a.borderWidth || 4) + 'px solid ' + (a.borderColor || accent) }; |
| 74 |
} else if (a.borderPosition === 'all') { |
| 75 |
borderStyle = { border: (a.borderWidth || 4) + 'px solid ' + (a.borderColor || accent) }; |
| 76 |
} |
| 77 |
|
| 78 |
var cardStyle = Object.assign({ |
| 79 |
background: a.cardBg || '#f5f3ff', |
| 80 |
borderRadius: cRadius, |
| 81 |
padding: (a.paddingV || 28) + 'px ' + (a.paddingH || 28) + 'px', |
| 82 |
maxWidth: (a.maxWidth || 760) + 'px', |
| 83 |
margin: '0 auto', |
| 84 |
boxSizing: 'border-box', |
| 85 |
}, borderStyle); |
| 86 |
|
| 87 |
var items = a.items || []; |
| 88 |
|
| 89 |
return el('div', { style: cardStyle }, |
| 90 |
|
| 91 |
/* Heading row */ |
| 92 |
a.showHeading && el('div', { style: { display: 'flex', alignItems: 'center', gap: '10px', marginBottom: (a.showDivider ? '16px' : '20px') } }, |
| 93 |
a.showHeadingIcon && el('span', { |
| 94 |
className: 'bkbg-kt-icon', |
| 95 |
style: { |
| 96 |
display: 'inline-flex', alignItems: 'center', justifyContent: 'center', |
| 97 |
width: '32px', height: '32px', borderRadius: '50%', flexShrink: 0, |
| 98 |
background: a.iconBg || accent, color: a.iconColor || '#fff', |
| 99 |
fontSize: '14px', fontWeight: 700, |
| 100 |
} |
| 101 |
}, IP().buildEditorIcon(a.headingIconType, a.headingIcon, a.headingIconDashicon, a.headingIconImageUrl, a.headingIconDashiconColor)), |
| 102 |
el('span', { |
| 103 |
className: 'bkbg-kt-heading', |
| 104 |
style: { |
| 105 |
color: a.headingColor || '#1e1b4b', |
| 106 |
} |
| 107 |
}, a.heading || __('Key Takeaways', 'blockenberg')) |
| 108 |
), |
| 109 |
|
| 110 |
/* Divider */ |
| 111 |
a.showHeading && a.showDivider && el('hr', { style: { border: 'none', borderTop: '1.5px solid ' + (a.borderColor || accent), opacity: 0.25, margin: '0 0 18px 0' } }), |
| 112 |
|
| 113 |
/* Items list */ |
| 114 |
el('ul', { style: { listStyle: 'none', margin: 0, padding: 0, display: 'flex', flexDirection: 'column', gap: (a.itemGap || 14) + 'px' } }, |
| 115 |
items.map(function (item, idx) { |
| 116 |
return el('li', { key: idx, style: { display: 'flex', alignItems: 'flex-start', gap: '10px' } }, |
| 117 |
el('span', { |
| 118 |
className: 'bkbg-kt-bullet', |
| 119 |
style: { |
| 120 |
flexShrink: 0, |
| 121 |
color: a.bulletColor || accent, marginTop: '1px', |
| 122 |
} |
| 123 |
}, bullet), |
| 124 |
el('span', { |
| 125 |
className: 'bkbg-kt-text', |
| 126 |
contentEditable: true, |
| 127 |
suppressContentEditableWarning: true, |
| 128 |
onBlur: function (e) { |
| 129 |
var newItems = items.slice(); |
| 130 |
newItems[idx] = e.target.innerText; |
| 131 |
setA({ items: newItems }); |
| 132 |
}, |
| 133 |
style: { |
| 134 |
flex: 1, |
| 135 |
color: a.itemColor || '#374151', |
| 136 |
outline: 'none', borderBottom: '1px dashed transparent', |
| 137 |
cursor: 'text', |
| 138 |
}, |
| 139 |
'data-placeholder': 'Type takeaway…', |
| 140 |
}, item) |
| 141 |
); |
| 142 |
}), |
| 143 |
|
| 144 |
/* Add item button */ |
| 145 |
el('li', { style: { display: 'flex', justifyContent: 'flex-start', marginTop: '4px' } }, |
| 146 |
el(Button, { |
| 147 |
variant: 'tertiary', |
| 148 |
onClick: function () { setA({ items: items.concat('') }); }, |
| 149 |
style: { fontSize: '13px', padding: '4px 8px', color: accent }, |
| 150 |
}, '+ ' + __('Add Item', 'blockenberg')) |
| 151 |
) |
| 152 |
) |
| 153 |
); |
| 154 |
} |
| 155 |
|
| 156 |
registerBlockType('blockenberg/key-takeaways', { |
| 157 |
edit: function (props) { |
| 158 |
var a = props.attributes; |
| 159 |
var setAttr = props.setAttributes; |
| 160 |
var blockProps = useBlockProps((function () { |
| 161 |
var _tv = getTypoCssVars(); |
| 162 |
var s = {}; |
| 163 |
Object.assign(s, _tv(a.headingTypo, '--bkbg-kt-h-')); |
| 164 |
Object.assign(s, _tv(a.itemTypo, '--bkbg-kt-it-')); |
| 165 |
return { style: s }; |
| 166 |
})()); |
| 167 |
|
| 168 |
return el(Fragment, null, |
| 169 |
el(InspectorControls, null, |
| 170 |
|
| 171 |
el(PanelBody, { title: __('Content', 'blockenberg'), initialOpen: true }, |
| 172 |
el(ToggleControl, { label: __('Show Heading', 'blockenberg'), checked: a.showHeading, onChange: function (v) { setAttr({ showHeading: v }); }, __nextHasNoMarginBottom: true }), |
| 173 |
a.showHeading && el(TextControl, { label: __('Heading Text', 'blockenberg'), value: a.heading, onChange: function (v) { setAttr({ heading: v }); } }), |
| 174 |
a.showHeading && el(ToggleControl, { label: __('Show Heading Icon', 'blockenberg'), checked: a.showHeadingIcon, onChange: function (v) { setAttr({ showHeadingIcon: v }); }, __nextHasNoMarginBottom: true }), |
| 175 |
a.showHeading && a.showHeadingIcon && el(IP().IconPickerControl, IP().iconPickerProps(attr, setAttr, { charAttr: 'headingIcon', typeAttr: 'headingIconType', dashiconAttr: 'headingIconDashicon', imageUrlAttr: 'headingIconImageUrl', colorAttr: 'headingIconDashiconColor' })), |
| 176 |
a.showHeading && el(ToggleControl, { label: __('Divider Below Heading', 'blockenberg'), checked: a.showDivider, onChange: function (v) { setAttr({ showDivider: v }); }, __nextHasNoMarginBottom: true }) |
| 177 |
), |
| 178 |
|
| 179 |
el(PanelBody, { title: __('Bullet Style', 'blockenberg'), initialOpen: false }, |
| 180 |
el(SelectControl, { label: __('Bullet Style', 'blockenberg'), value: a.bulletStyle, options: BULLET_STYLE_OPTIONS, onChange: function (v) { setAttr({ bulletStyle: v }); } }), |
| 181 |
a.bulletStyle === 'custom' && el(TextControl, { label: __('Custom Symbol', 'blockenberg'), value: a.customBullet, onChange: function (v) { setAttr({ customBullet: v }); } }) |
| 182 |
), |
| 183 |
|
| 184 |
el(PanelBody, { title: __('Border', 'blockenberg'), initialOpen: false }, |
| 185 |
el(SelectControl, { label: __('Border Position', 'blockenberg'), value: a.borderPosition, options: BORDER_POSITION_OPTIONS, onChange: function (v) { setAttr({ borderPosition: v }); } }), |
| 186 |
a.borderPosition !== 'none' && el(RangeControl, { label: __('Border Width (px)', 'blockenberg'), value: a.borderWidth, min: 1, max: 12, onChange: function (v) { setAttr({ borderWidth: v }); } }) |
| 187 |
), |
| 188 |
|
| 189 |
|
| 190 |
el( PanelBody, { title: __( 'Typography', 'blockenberg' ), initialOpen: false }, |
| 191 |
el(getTypographyControl(), { label: __('Heading Typography', 'blockenberg'), value: a.headingTypo, onChange: function (v) { setAttr({ headingTypo: v }); } }), |
| 192 |
el(getTypographyControl(), { label: __('Item Typography', 'blockenberg'), value: a.itemTypo, onChange: function (v) { setAttr({ itemTypo: v }); } }) |
| 193 |
), |
| 194 |
el(PanelColorSettings, { |
| 195 |
title: __('Colors', 'blockenberg'), initialOpen: false, |
| 196 |
colorSettings: [ |
| 197 |
{ label: __('Accent Color', 'blockenberg'), value: a.accentColor, onChange: function (v) { setAttr({ accentColor: v || '#6c3fb5' }); } }, |
| 198 |
{ label: __('Card Background', 'blockenberg'), value: a.cardBg, onChange: function (v) { setAttr({ cardBg: v || '#f5f3ff' }); } }, |
| 199 |
{ label: __('Border Color', 'blockenberg'), value: a.borderColor, onChange: function (v) { setAttr({ borderColor: v || '#6c3fb5' }); } }, |
| 200 |
{ label: __('Heading Color', 'blockenberg'), value: a.headingColor, onChange: function (v) { setAttr({ headingColor: v || '#1e1b4b' }); } }, |
| 201 |
{ label: __('Item Text Color', 'blockenberg'), value: a.itemColor, onChange: function (v) { setAttr({ itemColor: v || '#374151' }); } }, |
| 202 |
{ label: __('Bullet Color', 'blockenberg'), value: a.bulletColor, onChange: function (v) { setAttr({ bulletColor: v || '#6c3fb5' }); } }, |
| 203 |
{ label: __('Icon Background', 'blockenberg'), value: a.iconBg, onChange: function (v) { setAttr({ iconBg: v || '#6c3fb5' }); } }, |
| 204 |
{ label: __('Icon Text Color', 'blockenberg'), value: a.iconColor, onChange: function (v) { setAttr({ iconColor: v || '#ffffff' }); } }, |
| 205 |
] |
| 206 |
}), |
| 207 |
|
| 208 |
el(PanelBody, { title: __('Sizing', 'blockenberg'), initialOpen: false }, |
| 209 |
el(RangeControl, { label: __('Item Gap (px)', 'blockenberg'), value: a.itemGap, min: 4, max: 40, onChange: function (v) { setAttr({ itemGap: v }); } }), |
| 210 |
el(RangeControl, { label: __('Padding Vertical (px)', 'blockenberg'), value: a.paddingV, min: 8, max: 80, onChange: function (v) { setAttr({ paddingV: v }); } }), |
| 211 |
el(RangeControl, { label: __('Padding Horizontal (px)', 'blockenberg'), value: a.paddingH,min: 8, max: 80, onChange: function (v) { setAttr({ paddingH: v }); } }), |
| 212 |
el(RangeControl, { label: __('Card Radius (px)', 'blockenberg'), value: a.cardRadius, min: 0, max: 40, onChange: function (v) { setAttr({ cardRadius: v }); } }), |
| 213 |
el(RangeControl, { label: __('Max Width (px)', 'blockenberg'), value: a.maxWidth, min: 320,max: 1400,onChange: function (v) { setAttr({ maxWidth: v }); } }) |
| 214 |
) |
| 215 |
), |
| 216 |
|
| 217 |
el('div', blockProps, |
| 218 |
el(TakeawaysPreview, { attrs: a, setAttrs: setAttr }) |
| 219 |
) |
| 220 |
); |
| 221 |
}, |
| 222 |
|
| 223 |
save: function (props) { |
| 224 |
var a = props.attributes; |
| 225 |
var blockProps = wp.blockEditor.useBlockProps.save(); |
| 226 |
return el('div', blockProps, |
| 227 |
el('div', { className: 'bkbg-kt-app', 'data-opts': JSON.stringify(a) }, |
| 228 |
el('p', { className: 'bkbg-kt-loading' }, '…') |
| 229 |
) |
| 230 |
); |
| 231 |
} |
| 232 |
}); |
| 233 |
}() ); |
| 234 |
|