| 1 |
(function () { |
| 2 |
var el = window.wp.element.createElement; |
| 3 |
var __ = function (s) { return s; }; |
| 4 |
var registerBlockType = window.wp.blocks.registerBlockType; |
| 5 |
var InspectorControls = window.wp.blockEditor.InspectorControls; |
| 6 |
var PanelBody = window.wp.components.PanelBody; |
| 7 |
var ToggleControl = window.wp.components.ToggleControl; |
| 8 |
var SelectControl = window.wp.components.SelectControl; |
| 9 |
var RangeControl = window.wp.components.RangeControl; |
| 10 |
var PanelColorSettings = window.wp.blockEditor.PanelColorSettings; |
| 11 |
var useBlockProps = window.wp.blockEditor.useBlockProps; |
| 12 |
|
| 13 |
var _tc; function getTypoControl() { return _tc || (_tc = window.bkbgTypographyControl); } |
| 14 |
var _tv; function getTypoCssVars() { return _tv || (_tv = window.bkbgTypoCssVars); } |
| 15 |
|
| 16 |
var v1Attributes = { |
| 17 |
height: { type: 'number', default: 4 }, |
| 18 |
position: { type: 'string', default: 'top' }, |
| 19 |
color: { type: 'string', default: '#2563eb' }, |
| 20 |
bgColor: { type: 'string', default: '#e5e7eb' }, |
| 21 |
showPercentage: { type: 'boolean', default: false }, |
| 22 |
zIndex: { type: 'number', default: 9999 }, |
| 23 |
animation: { type: 'string', default: 'smooth' }, |
| 24 |
gradientEnd: { type: 'string', default: '' }, |
| 25 |
useGradient: { type: 'boolean', default: false }, |
| 26 |
fontSize: { type: 'number', default: 11 }, |
| 27 |
fontWeight: { type: 'number', default: 600 }, |
| 28 |
lineHeight: { type: 'number', default: 1.2 } |
| 29 |
}; |
| 30 |
|
| 31 |
registerBlockType('blockenberg/reading-progress', { |
| 32 |
title: __('Reading Progress'), |
| 33 |
description: __('A fixed reading progress bar that fills as the visitor scrolls.'), |
| 34 |
category: 'bkbg-blog', |
| 35 |
icon: el('svg', { viewBox: '0 0 24 24', fill: 'currentColor', width: 24, height: 24 }, |
| 36 |
el('rect', { x: 2, y: 10, width: 20, height: 4, rx: 2, fill: '#e5e7eb' }), |
| 37 |
el('rect', { x: 2, y: 10, width: 13, height: 4, rx: 2, fill: '#2563eb' }) |
| 38 |
), |
| 39 |
|
| 40 |
edit: function (props) { |
| 41 |
var a = props.attributes; |
| 42 |
var setA = props.setAttributes; |
| 43 |
var TC = getTypoControl(); |
| 44 |
|
| 45 |
var blockProps = useBlockProps((function() { |
| 46 |
var _tvFn = getTypoCssVars(); |
| 47 |
var s = {}; |
| 48 |
if (_tvFn) Object.assign(s, _tvFn(a.labelTypo || {}, '--bkrp-lt-')); |
| 49 |
return { style: s, className: 'bkbg-rp-editor-preview' }; |
| 50 |
})()); |
| 51 |
|
| 52 |
var inspector = el(InspectorControls, null, |
| 53 |
el(PanelBody, { title: __('Position & Size'), initialOpen: true }, |
| 54 |
el(SelectControl, { |
| 55 |
label: __('Position'), |
| 56 |
value: a.position, |
| 57 |
options: [ |
| 58 |
{ label: 'Top of viewport', value: 'top' }, |
| 59 |
{ label: 'Bottom of viewport', value: 'bottom' }, |
| 60 |
], |
| 61 |
onChange: function (v) { setA({ position: v }); }, |
| 62 |
}), |
| 63 |
el(RangeControl, { |
| 64 |
label: __('Bar Height (px)'), |
| 65 |
value: a.height, |
| 66 |
min: 1, max: 20, |
| 67 |
onChange: function (v) { setA({ height: v }); }, |
| 68 |
}), |
| 69 |
el(RangeControl, { |
| 70 |
label: __('Z-Index'), |
| 71 |
value: a.zIndex, |
| 72 |
min: 100, max: 99999, step: 100, |
| 73 |
onChange: function (v) { setA({ zIndex: v }); }, |
| 74 |
}) |
| 75 |
), |
| 76 |
el(PanelBody, { title: __('Appearance'), initialOpen: false }, |
| 77 |
el(SelectControl, { |
| 78 |
label: __('Animation'), |
| 79 |
value: a.animation, |
| 80 |
options: [ |
| 81 |
{ label: 'Smooth', value: 'smooth' }, |
| 82 |
{ label: 'None', value: 'none' }, |
| 83 |
], |
| 84 |
onChange: function (v) { setA({ animation: v }); }, |
| 85 |
}), |
| 86 |
el(ToggleControl, { |
| 87 |
label: __('Use gradient color'), |
| 88 |
checked: a.useGradient, |
| 89 |
onChange: function (v) { setA({ useGradient: v }); }, |
| 90 |
__nextHasNoMarginBottom: true, |
| 91 |
}), |
| 92 |
el(ToggleControl, { |
| 93 |
label: __('Show percentage label'), |
| 94 |
checked: a.showPercentage, |
| 95 |
onChange: function (v) { setA({ showPercentage: v }); }, |
| 96 |
__nextHasNoMarginBottom: true, |
| 97 |
}) |
| 98 |
), |
| 99 |
el(PanelBody, { title: __('Typography', 'blockenberg'), initialOpen: false }, |
| 100 |
TC && el(TC, { label: __('Percentage Label', 'blockenberg'), value: a.labelTypo || {}, onChange: function(v) { setA({ labelTypo: v }); } }) |
| 101 |
), |
| 102 |
el(PanelBody, { title: __('Colors'), initialOpen: false }, |
| 103 |
el(PanelColorSettings, { |
| 104 |
title: __('Bar Colors'), |
| 105 |
initialOpen: false, |
| 106 |
colorSettings: [ |
| 107 |
{ label: __('Progress Color'), value: a.color, onChange: function (v) { setA({ color: v || '#2563eb' }); } }, |
| 108 |
{ label: __('Gradient End'), value: a.gradientEnd, onChange: function (v) { setA({ gradientEnd: v || '' }); } }, |
| 109 |
{ label: __('Background Track'), value: a.bgColor, onChange: function (v) { setA({ bgColor: v || '#e5e7eb' }); } }, |
| 110 |
], |
| 111 |
}) |
| 112 |
) |
| 113 |
); |
| 114 |
|
| 115 |
/* Editor preview — static bar inside the content area */ |
| 116 |
var previewBar = el('div', { |
| 117 |
style: { |
| 118 |
position: 'relative', |
| 119 |
width: '100%', |
| 120 |
background: a.bgColor, |
| 121 |
height: a.height + 'px', |
| 122 |
borderRadius: (a.height / 2) + 'px', |
| 123 |
overflow: 'hidden', |
| 124 |
} |
| 125 |
}, |
| 126 |
el('div', { |
| 127 |
style: { |
| 128 |
width: '60%', |
| 129 |
height: '100%', |
| 130 |
background: a.useGradient && a.gradientEnd |
| 131 |
? 'linear-gradient(90deg,' + a.color + ',' + a.gradientEnd + ')' |
| 132 |
: a.color, |
| 133 |
borderRadius: 'inherit', |
| 134 |
} |
| 135 |
}) |
| 136 |
); |
| 137 |
|
| 138 |
return el('div', blockProps, |
| 139 |
inspector, |
| 140 |
el('div', { |
| 141 |
style: { |
| 142 |
padding: '12px 16px', |
| 143 |
background: '#f9fafb', |
| 144 |
border: '1px solid #e5e7eb', |
| 145 |
borderRadius: 8, |
| 146 |
textAlign: 'center', |
| 147 |
} |
| 148 |
}, |
| 149 |
el('p', { style: { margin: '0 0 10px', fontSize: 12, color: '#6b7280', fontWeight: 600 } }, |
| 150 |
'Reading Progress Bar — ' + a.position.charAt(0).toUpperCase() + a.position.slice(1) + ' of Viewport' |
| 151 |
), |
| 152 |
previewBar, |
| 153 |
el('p', { className: 'bkbg-rp-info', style: { margin: '8px 0 0', color: '#9ca3af' } }, |
| 154 |
'The bar will be fixed to the ' + a.position + ' of the screen on the front end.' |
| 155 |
) |
| 156 |
) |
| 157 |
); |
| 158 |
}, |
| 159 |
|
| 160 |
save: function (props) { |
| 161 |
var a = props.attributes; |
| 162 |
return el('div', { |
| 163 |
className: 'bkbg-rp-anchor', |
| 164 |
'data-height': a.height, |
| 165 |
'data-position': a.position, |
| 166 |
'data-color': a.color, |
| 167 |
'data-bg': a.bgColor, |
| 168 |
'data-pct': a.showPercentage ? '1' : '0', |
| 169 |
'data-zindex': a.zIndex, |
| 170 |
'data-animation': a.animation, |
| 171 |
'data-gradient': a.useGradient && a.gradientEnd ? a.gradientEnd : '', |
| 172 |
'data-label-typo': JSON.stringify(a.labelTypo || {}), |
| 173 |
}); |
| 174 |
}, |
| 175 |
|
| 176 |
deprecated: [ |
| 177 |
{ |
| 178 |
attributes: v1Attributes, |
| 179 |
save: function (props) { |
| 180 |
var a = props.attributes; |
| 181 |
return el('div', { |
| 182 |
className: 'bkbg-rp-anchor', |
| 183 |
'data-height': a.height, |
| 184 |
'data-position': a.position, |
| 185 |
'data-color': a.color, |
| 186 |
'data-bg': a.bgColor, |
| 187 |
'data-pct': a.showPercentage ? '1' : '0', |
| 188 |
'data-zindex': a.zIndex, |
| 189 |
'data-animation': a.animation, |
| 190 |
'data-gradient': a.useGradient && a.gradientEnd ? a.gradientEnd : '', |
| 191 |
}); |
| 192 |
}, |
| 193 |
} |
| 194 |
], |
| 195 |
}); |
| 196 |
})(); |
| 197 |
|