| 1 |
( function () { |
| 2 |
var el = wp.element.createElement; |
| 3 |
var registerBlockType = wp.blocks.registerBlockType; |
| 4 |
var useBlockProps = wp.blockEditor.useBlockProps; |
| 5 |
var InspectorControls = wp.blockEditor.InspectorControls; |
| 6 |
var PanelColorSettings = wp.blockEditor.PanelColorSettings; |
| 7 |
var PanelBody = wp.components.PanelBody; |
| 8 |
var RangeControl = wp.components.RangeControl; |
| 9 |
var ToggleControl = wp.components.ToggleControl; |
| 10 |
var SelectControl = wp.components.SelectControl; |
| 11 |
var TextControl = wp.components.TextControl; |
| 12 |
var Button = wp.components.Button; |
| 13 |
|
| 14 |
var _bkbgCTKgetTC, _bkbgCTKgetTV; |
| 15 |
function getTC() { return _bkbgCTKgetTC || (_bkbgCTKgetTC = window.bkbgTypographyControl); } |
| 16 |
function getTV() { return _bkbgCTKgetTV || (_bkbgCTKgetTV = window.bkbgTypoCssVars); } |
| 17 |
function tv(obj, prefix) { var fn = getTV(); return fn ? fn(obj, prefix) : {}; } |
| 18 |
|
| 19 |
registerBlockType('blockenberg/content-ticker', { |
| 20 |
edit: function (props) { |
| 21 |
var a = props.attributes; |
| 22 |
var set = props.setAttributes; |
| 23 |
var blockProps = useBlockProps({ className: 'bkbg-ctk-editor-wrap', style: Object.assign({}, tv(a.typoText, '--bkctk-text-')) }); |
| 24 |
|
| 25 |
function updateItem(idx, field, val) { |
| 26 |
var ni = a.items.map(function (it, i) { |
| 27 |
return i === idx ? Object.assign({}, it, { [field]: val }) : it; |
| 28 |
}); |
| 29 |
set({ items: ni }); |
| 30 |
} |
| 31 |
function addItem() { |
| 32 |
set({ items: a.items.concat([{ text: 'New announcement here...', url: '' }]) }); |
| 33 |
} |
| 34 |
function removeItem(idx) { |
| 35 |
set({ items: a.items.filter(function (_, i) { return i !== idx; }) }); |
| 36 |
} |
| 37 |
|
| 38 |
var h = a.height || 44; |
| 39 |
var fz = a.fontSize || 14; |
| 40 |
var previewText = (a.items || []).map(function (it) { return it.text; }).join(' ' + (a.separator || ' ◉ ') + ' '); |
| 41 |
|
| 42 |
var preview = el('div', { |
| 43 |
className: 'bkbg-ctk-wrap', |
| 44 |
style: { |
| 45 |
display: 'flex', alignItems: 'stretch', |
| 46 |
height: h + 'px', |
| 47 |
borderRadius: (a.borderRadius || 6) + 'px', |
| 48 |
overflow: 'hidden' |
| 49 |
} |
| 50 |
}, |
| 51 |
a.showPrefix !== false && el('div', { |
| 52 |
className: 'bkbg-ctk-prefix', |
| 53 |
style: { |
| 54 |
background: a.prefixBg || '#ef4444', |
| 55 |
color: a.prefixColor || '#ffffff', |
| 56 |
padding: '0 ' + (a.prefixPadding || 20) + 'px', |
| 57 |
display: 'flex', alignItems: 'center', |
| 58 |
whiteSpace: 'nowrap', flexShrink: 0 |
| 59 |
} |
| 60 |
}, a.prefix || '📢 Breaking'), |
| 61 |
el('div', { |
| 62 |
style: { |
| 63 |
flex: 1, overflow: 'hidden', |
| 64 |
background: a.tickerBg || '#1e1b4b', |
| 65 |
color: a.tickerColor || '#e2e8f0', |
| 66 |
display: 'flex', alignItems: 'center', |
| 67 |
padding: '0 16px' |
| 68 |
} |
| 69 |
}, |
| 70 |
el('div', { |
| 71 |
style: { whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis' } |
| 72 |
}, previewText || 'Your ticker items will scroll here...') |
| 73 |
), |
| 74 |
el('div', { |
| 75 |
className: 'bkbg-ctk-arrow', |
| 76 |
style: { |
| 77 |
background: a.prefixBg || '#ef4444', |
| 78 |
color: a.prefixColor || '#ffffff', |
| 79 |
padding: '0 12px', |
| 80 |
display: 'flex', alignItems: 'center', |
| 81 |
flexShrink: 0 |
| 82 |
} |
| 83 |
}, a.direction === 'right' ? '◀' : '▶') |
| 84 |
); |
| 85 |
|
| 86 |
return el('div', blockProps, |
| 87 |
el(InspectorControls, {}, |
| 88 |
el(PanelBody, { title: 'Ticker Items', initialOpen: true }, |
| 89 |
(a.items || []).map(function (item, i) { |
| 90 |
return el('div', { key: i, style: { marginBottom: 12, padding: 10, |
| 91 |
background: '#f8fafc', borderRadius: 6, border: '1px solid #e5e7eb' } }, |
| 92 |
el(TextControl, { label: 'Headline text', value: item.text, |
| 93 |
onChange: function (v) { updateItem(i, 'text', v); }, __nextHasNoMarginBottom: true }), |
| 94 |
el(TextControl, { label: 'Link URL (optional)', value: item.url || '', |
| 95 |
onChange: function (v) { updateItem(i, 'url', v); }, __nextHasNoMarginBottom: true }), |
| 96 |
el(Button, { isDestructive: true, isSmall: true, |
| 97 |
onClick: function () { removeItem(i); } }, '✕ Remove') |
| 98 |
); |
| 99 |
}), |
| 100 |
el(Button, { isPrimary: true, isSmall: true, onClick: addItem, |
| 101 |
style: { marginTop: 4 } }, '+ Add Item') |
| 102 |
), |
| 103 |
el(PanelBody, { title: 'Ticker Settings', initialOpen: false }, |
| 104 |
el(ToggleControl, { label: 'Show prefix label', checked: a.showPrefix !== false, |
| 105 |
onChange: function (v) { set({ showPrefix: v }); }, __nextHasNoMarginBottom: true }), |
| 106 |
el(TextControl, { label: 'Prefix label', value: a.prefix || '', |
| 107 |
onChange: function (v) { set({ prefix: v }); }, __nextHasNoMarginBottom: true }), |
| 108 |
el(TextControl, { label: 'Item separator', value: a.separator || '', |
| 109 |
onChange: function (v) { set({ separator: v }); }, __nextHasNoMarginBottom: true }), |
| 110 |
el(SelectControl, { label: 'Scroll direction', value: a.direction || 'left', |
| 111 |
options: [ |
| 112 |
{ label: '← Scroll left', value: 'left' }, |
| 113 |
{ label: '→ Scroll right', value: 'right' } |
| 114 |
], |
| 115 |
onChange: function (v) { set({ direction: v }); }, __nextHasNoMarginBottom: true }), |
| 116 |
el(RangeControl, { label: 'Scroll speed (px/s)', value: a.speed || 60, |
| 117 |
onChange: function (v) { set({ speed: v }); }, min: 10, max: 300, __nextHasNoMarginBottom: true }), |
| 118 |
el(ToggleControl, { label: 'Pause on hover', checked: a.pauseOnHover !== false, |
| 119 |
onChange: function (v) { set({ pauseOnHover: v }); }, __nextHasNoMarginBottom: true }) |
| 120 |
), |
| 121 |
el(PanelBody, { title: 'Style', initialOpen: false }, |
| 122 |
el(RangeControl, { label: 'Height (px)', value: a.height || 44, |
| 123 |
onChange: function (v) { set({ height: v }); }, min: 28, max: 80, __nextHasNoMarginBottom: true }), |
| 124 |
el(RangeControl, { label: 'Border radius', value: a.borderRadius || 6, |
| 125 |
onChange: function (v) { set({ borderRadius: v }); }, min: 0, max: 40, __nextHasNoMarginBottom: true }), |
| 126 |
el(RangeControl, { label: 'Prefix padding', value: a.prefixPadding || 20, |
| 127 |
onChange: function (v) { set({ prefixPadding: v }); }, min: 8, max: 60, __nextHasNoMarginBottom: true }) |
| 128 |
), |
| 129 |
|
| 130 |
el( PanelBody, { title: 'Typography', initialOpen: false }, |
| 131 |
getTC() && el(getTC(), { label: 'Ticker Text', value: a.typoText, onChange: function (v) { set({ typoText: v }); } }) |
| 132 |
), |
| 133 |
el(PanelColorSettings, { |
| 134 |
title: 'Colors', initialOpen: false, |
| 135 |
colorSettings: [ |
| 136 |
{ label: 'Prefix background', value: a.prefixBg, onChange: function (v) { set({ prefixBg: v || '#ef4444' }); } }, |
| 137 |
{ label: 'Prefix text', value: a.prefixColor, onChange: function (v) { set({ prefixColor: v || '#ffffff' }); } }, |
| 138 |
{ label: 'Ticker background', value: a.tickerBg, onChange: function (v) { set({ tickerBg: v || '#1e1b4b' }); } }, |
| 139 |
{ label: 'Ticker text', value: a.tickerColor, onChange: function (v) { set({ tickerColor: v || '#e2e8f0' }); } }, |
| 140 |
{ label: 'Link color', value: a.linkColor, onChange: function (v) { set({ linkColor: v || '#a5b4fc' }); } }, |
| 141 |
{ label: 'Separator color', value: a.separatorColor, onChange: function (v) { set({ separatorColor: v || '#475569' }); } } |
| 142 |
], |
| 143 |
disableCustomGradients: true |
| 144 |
}) |
| 145 |
), |
| 146 |
preview |
| 147 |
); |
| 148 |
}, |
| 149 |
|
| 150 |
save: function (props) { |
| 151 |
var a = props.attributes; |
| 152 |
var blockProps = useBlockProps.save(); |
| 153 |
var opts = { |
| 154 |
items: a.items || [], |
| 155 |
prefix: a.prefix || '📢 Breaking', |
| 156 |
showPrefix: a.showPrefix !== false, |
| 157 |
speed: a.speed || 60, |
| 158 |
pauseOnHover: a.pauseOnHover !== false, |
| 159 |
separator: a.separator || ' ◉ ', |
| 160 |
direction: a.direction || 'left', |
| 161 |
height: a.height || 44, |
| 162 |
fontSize: a.fontSize || 14, |
| 163 |
fontWeight: a.fontWeight || 400, |
| 164 |
borderRadius: a.borderRadius || 6, |
| 165 |
prefixPadding: a.prefixPadding || 20, |
| 166 |
prefixBg: a.prefixBg || '#ef4444', |
| 167 |
prefixColor: a.prefixColor || '#ffffff', |
| 168 |
tickerBg: a.tickerBg || '#1e1b4b', |
| 169 |
tickerColor: a.tickerColor || '#e2e8f0', |
| 170 |
linkColor: a.linkColor || '#a5b4fc', |
| 171 |
separatorColor: a.separatorColor || '#475569', |
| 172 |
typoText: a.typoText || {} |
| 173 |
}; |
| 174 |
return el('div', blockProps, |
| 175 |
el('div', { className: 'bkbg-ctk-app', 'data-opts': JSON.stringify(opts) }) |
| 176 |
); |
| 177 |
} |
| 178 |
}); |
| 179 |
}() ); |
| 180 |
|