| 1 |
( function () { |
| 2 |
var el = wp.element.createElement; |
| 3 |
var Fragment = wp.element.Fragment; |
| 4 |
var useState = wp.element.useState; |
| 5 |
var useEffect = wp.element.useEffect; |
| 6 |
var __ = wp.i18n.__; |
| 7 |
var registerBlockType = wp.blocks.registerBlockType; |
| 8 |
var InspectorControls = wp.blockEditor.InspectorControls; |
| 9 |
var useBlockProps = wp.blockEditor.useBlockProps; |
| 10 |
var RichText = wp.blockEditor.RichText; |
| 11 |
var PanelBody = wp.components.PanelBody; |
| 12 |
var ColorPicker = wp.components.ColorPicker; |
| 13 |
var Popover = wp.components.Popover; |
| 14 |
var Button = wp.components.Button; |
| 15 |
var ToggleControl = wp.components.ToggleControl; |
| 16 |
var RangeControl = wp.components.RangeControl; |
| 17 |
var SelectControl = wp.components.SelectControl; |
| 18 |
|
| 19 |
var _TC, _tv; |
| 20 |
function getTC() { return _TC || (_TC = window.bkbgTypographyControl); } |
| 21 |
function getTV() { return _tv || (_tv = window.bkbgTypoCssVars); } |
| 22 |
|
| 23 |
// ── SVG icon paths (24×24 viewBox) ────────────────────────────────────────── |
| 24 |
var ICONS = { |
| 25 |
star: 'M12 2l3.09 6.26L22 9.27l-5 4.87 1.18 6.88L12 17.77l-6.18 3.25L7 14.14 2 9.27l6.91-1.01L12 2z', |
| 26 |
heart: 'M12 21.35l-1.45-1.32C5.4 15.36 2 12.28 2 8.5 2 5.42 4.42 3 7.5 3c1.74 0 3.41.81 4.5 2.09C13.09 3.81 14.76 3 16.5 3 19.58 3 22 5.42 22 8.5c0 3.78-3.4 6.86-8.55 11.54L12 21.35z', |
| 27 |
diamond: 'M12 2l9 10-9 10L3 12z', |
| 28 |
bolt: 'M13 2L4.5 13.5H11L10 22l9.5-12H13z', |
| 29 |
moon: 'M12 3a9 9 0 0 0 0 18 9 9 0 0 0 7.13-14.47A7 7 0 0 1 12 3z', |
| 30 |
star8: 'M12 2l2.4 7.4H22l-6.2 4.5 2.4 7.4L12 17l-6.2 4.3 2.4-7.4L2 9.4h7.6z', |
| 31 |
cross: 'M19 11H13V5h-2v6H5v2h6v6h2v-6h6z', |
| 32 |
leaf: 'M17 8C8 10 5.9 16.17 3.82 21.34L5.71 22 7 19.46c.61.34 1.3.54 2 .54 9 0 12-8 12-8s-3.5.5-5.5-2.5S17 8 17 8z', |
| 33 |
snowflake: 'M22 11h-4.17l3.24-3.24-1.41-1.42L15 11h-2V9l4.66-4.66-1.42-1.41L13 6.17V2h-2v4.17L7.76 2.93 6.34 4.34 11 9v2H9L4.34 6.34 2.93 7.76 6.17 11H2v2h4.17l-3.24 3.24 1.41 1.42L9 13h2v2l-4.66 4.66 1.42 1.41L11 17.83V22h2v-4.17l3.24 3.24 1.42-1.41L13 15v-2h2l4.66 4.66 1.41-1.42L17.83 13H22z', |
| 34 |
circle: null // handled separately with <circle> element |
| 35 |
}; |
| 36 |
|
| 37 |
// ── Generate unique block ID ───────────────────────────────────────────────── |
| 38 |
function generateId() { |
| 39 |
return 'sep' + Math.random().toString(36).substr(2, 8); |
| 40 |
} |
| 41 |
|
| 42 |
// ── Build icon SVG element ─────────────────────────────────────────────────── |
| 43 |
function buildIconSVG(iconName, iconColor, iconSize) { |
| 44 |
var isCircle = iconName === 'circle'; |
| 45 |
var shape = isCircle |
| 46 |
? el('circle', { cx: '12', cy: '12', r: '10', fill: iconColor }) |
| 47 |
: el('path', { d: ICONS[iconName] || ICONS.star, fill: iconColor }); |
| 48 |
return el('svg', { |
| 49 |
viewBox: '0 0 24 24', |
| 50 |
xmlns: 'http://www.w3.org/2000/svg', |
| 51 |
width: iconSize, |
| 52 |
height: iconSize, |
| 53 |
'aria-hidden': 'true', |
| 54 |
style: { display: 'block', flexShrink: 0 } |
| 55 |
}, shape); |
| 56 |
} |
| 57 |
|
| 58 |
// ── Build wave path string ─────────────────────────────────────────────────── |
| 59 |
function buildWavePath(svgH) { |
| 60 |
var mid = svgH / 2; |
| 61 |
var amp = Math.max(1, mid - 2); |
| 62 |
return 'M0,' + mid |
| 63 |
+ ' C100,' + (mid - amp) + ' 200,' + (mid + amp) + ' 300,' + mid |
| 64 |
+ ' C400,' + (mid - amp) + ' 500,' + (mid + amp) + ' 600,' + mid |
| 65 |
+ ' C700,' + (mid - amp) + ' 800,' + (mid + amp) + ' 900,' + mid |
| 66 |
+ ' C1000,' + (mid - amp) + ' 1100,' + (mid + amp) + ' 1200,' + mid; |
| 67 |
} |
| 68 |
|
| 69 |
// ── Build zigzag path string ───────────────────────────────────────────────── |
| 70 |
function buildZigzagPath(svgH) { |
| 71 |
var mid = svgH / 2; |
| 72 |
var amp = Math.max(1, mid - 2); |
| 73 |
var d = 'M0,' + mid; |
| 74 |
for (var i = 1; i <= 20; i++) { |
| 75 |
d += ' L' + (i * 60) + ',' + (i % 2 === 1 ? (mid - amp) : (mid + amp)); |
| 76 |
} |
| 77 |
d += ' L1200,' + mid; |
| 78 |
return d; |
| 79 |
} |
| 80 |
|
| 81 |
// ── Scallop: repeated arcs pointing up (fish-scale / petal pattern) ────────── |
| 82 |
function buildScallopPath(svgH) { |
| 83 |
var d = 'M0,' + svgH; |
| 84 |
for (var i = 0; i < 20; i++) { |
| 85 |
var x1 = i * 60 + 30; |
| 86 |
var x2 = (i + 1) * 60; |
| 87 |
d += ' Q' + x1 + ',0 ' + x2 + ',' + svgH; |
| 88 |
} |
| 89 |
return d; |
| 90 |
} |
| 91 |
|
| 92 |
// ── Arrows: open right-pointing chevrons >>>> ──────────────────────────────── |
| 93 |
function buildArrowsPath(svgH) { |
| 94 |
var mid = svgH / 2; |
| 95 |
var amp = Math.max(2, mid - 2); |
| 96 |
// Each chevron: 24px wide, 55px pitch → 22 chevrons across 1200px |
| 97 |
var d = ''; |
| 98 |
for (var i = 0; i < 22; i++) { |
| 99 |
var x = i * 55 + 3; |
| 100 |
d += (d ? ' ' : '') + 'M' + x + ',' + (mid - amp) |
| 101 |
+ ' L' + (x + 24) + ',' + mid |
| 102 |
+ ' L' + x + ',' + (mid + amp); |
| 103 |
} |
| 104 |
return d; |
| 105 |
} |
| 106 |
|
| 107 |
// ── Brush: organic calligraphy-style stroke ─────────────────────────────────── |
| 108 |
function buildBrushPath(svgH) { |
| 109 |
var mid = svgH / 2; |
| 110 |
var amp = mid * 0.85; |
| 111 |
return 'M0,' + mid |
| 112 |
+ ' C60,' + (mid - amp * 0.9) + ' 110,' + (mid + amp * 0.5) + ' 170,' + (mid - amp * 0.15) |
| 113 |
+ ' C230,' + (mid + amp * 0.8) + ' 280,' + (mid - amp * 0.6) + ' 340,' + (mid + amp * 0.3) |
| 114 |
+ ' C400,' + (mid - amp * 0.4) + ' 450,' + (mid + amp * 0.75) + ' 510,' + (mid - amp * 0.1) |
| 115 |
+ ' C570,' + (mid - amp * 0.7) + ' 620,' + (mid + amp * 0.55) + ' 680,' + (mid + amp * 0.2) |
| 116 |
+ ' C740,' + (mid - amp * 0.85)+ ' 790,' + (mid - amp * 0.3) + ' 850,' + (mid + amp * 0.65) |
| 117 |
+ ' C910,' + (mid + amp * 0.4) + ' 960,' + (mid - amp * 0.8) + ' 1020,'+ (mid - amp * 0.05) |
| 118 |
+ ' C1080,'+ (mid + amp * 0.6) + ' 1130,'+ (mid - amp * 0.45) + ' 1200,'+ mid; |
| 119 |
} |
| 120 |
|
| 121 |
// ── Heartbeat / EKG ────────────────────────────────────────────────────────── |
| 122 |
function buildHeartbeatPath(svgH) { |
| 123 |
var mid = svgH / 2; |
| 124 |
var amp = Math.max(3, svgH * 0.46); |
| 125 |
// Period = 200px, 6 full cycles in 1200px |
| 126 |
var d = 'M0,' + mid; |
| 127 |
for (var i = 0; i < 6; i++) { |
| 128 |
var o = i * 200; // offset |
| 129 |
d += ' L'+(o+25)+','+mid // flat |
| 130 |
+ ' L'+(o+35)+','+(mid - amp*0.28) // P-wave up |
| 131 |
+ ' L'+(o+45)+','+mid // baseline |
| 132 |
+ ' L'+(o+58)+','+(mid + amp*0.18) // Q dip |
| 133 |
+ ' L'+(o+68)+','+(mid - amp) // R spike (tall) |
| 134 |
+ ' L'+(o+80)+','+(mid + amp*0.55) // S dip below |
| 135 |
+ ' L'+(o+95)+','+mid // baseline |
| 136 |
+ ' L'+(o+110)+','+(mid - amp*0.22) // T-wave bump |
| 137 |
+ ' L'+(o+130)+','+mid; // flat exit |
| 138 |
} |
| 139 |
d += ' L1200,' + mid; |
| 140 |
return d; |
| 141 |
} |
| 142 |
|
| 143 |
// ── Build one line segment ─────────────────────────────────────────────────── |
| 144 |
// side: 'l' | 'r' | 'full' |
| 145 |
// flexValue: CSS flex shorthand string |
| 146 |
var SVG_TYPES = ['wave', 'zigzag', 'scallop', 'arrows', 'brush', 'heartbeat']; |
| 147 |
|
| 148 |
function buildLineSeg(a, side, flexValue) { |
| 149 |
var type = a.dividerType; |
| 150 |
var segStyle = { flex: flexValue || '1', minWidth: 0 }; |
| 151 |
var isSvgType = SVG_TYPES.indexOf(type) !== -1; |
| 152 |
|
| 153 |
var svgEl = null; |
| 154 |
if (isSvgType) { |
| 155 |
var d; |
| 156 |
if (type === 'wave') { d = buildWavePath(a.svgHeight); } |
| 157 |
else if (type === 'zigzag') { d = buildZigzagPath(a.svgHeight); } |
| 158 |
else if (type === 'scallop') { d = buildScallopPath(a.svgHeight); } |
| 159 |
else if (type === 'arrows') { d = buildArrowsPath(a.svgHeight); } |
| 160 |
else if (type === 'brush') { d = buildBrushPath(a.svgHeight); } |
| 161 |
else { d = buildHeartbeatPath(a.svgHeight); } |
| 162 |
svgEl = el('svg', { |
| 163 |
viewBox: '0 0 1200 ' + a.svgHeight, |
| 164 |
preserveAspectRatio: 'none', |
| 165 |
xmlns: 'http://www.w3.org/2000/svg', |
| 166 |
width: '100%', |
| 167 |
height: a.svgHeight, |
| 168 |
style: { display: 'block', overflow: 'visible' } |
| 169 |
}, el('path', { |
| 170 |
d: d, |
| 171 |
fill: 'none', |
| 172 |
stroke: a.lineColor, |
| 173 |
strokeWidth: a.lineThickness, |
| 174 |
strokeLinecap: 'round', |
| 175 |
strokeLinejoin: 'round' |
| 176 |
})); |
| 177 |
} |
| 178 |
|
| 179 |
if (isSvgType) { |
| 180 |
Object.assign(segStyle, { display: 'block', overflow: 'hidden' }); |
| 181 |
} |
| 182 |
|
| 183 |
return el('span', { |
| 184 |
key: 'seg-' + side, |
| 185 |
className: 'bkbg-div-seg bkbg-div-seg--' + side, |
| 186 |
'aria-hidden': 'true', |
| 187 |
style: segStyle |
| 188 |
}, svgEl); |
| 189 |
} |
| 190 |
|
| 191 |
// ── Build middle element (icon or text) ──────────────────────────────────── |
| 192 |
// In edit mode, text uses RichText; in save mode, caller passes a pre-built element. |
| 193 |
function buildIconMiddle(a) { |
| 194 |
var iconSvg = buildIconSVG(a.iconName, a.iconColor, a.iconSize); |
| 195 |
var hasBg = a.iconBgShape !== 'none'; |
| 196 |
|
| 197 |
if (!hasBg) { |
| 198 |
return el('span', { |
| 199 |
className: 'bkbg-div-mid-icon', |
| 200 |
'aria-hidden': 'true' |
| 201 |
}, iconSvg); |
| 202 |
} |
| 203 |
|
| 204 |
var radius = a.iconBgShape === 'circle' ? '50%' : '8px'; |
| 205 |
return el('span', { |
| 206 |
className: 'bkbg-div-mid-icon bkbg-div-mid-icon--bg', |
| 207 |
'aria-hidden': 'true', |
| 208 |
style: { |
| 209 |
display: 'inline-flex', |
| 210 |
alignItems: 'center', |
| 211 |
justifyContent: 'center', |
| 212 |
width: a.iconBgSize + 'px', |
| 213 |
height: a.iconBgSize + 'px', |
| 214 |
borderRadius: radius, |
| 215 |
background: a.iconBgColor, |
| 216 |
flexShrink: 0 |
| 217 |
} |
| 218 |
}, iconSvg); |
| 219 |
} |
| 220 |
|
| 221 |
// ── CSS vars for wrapper ───────────────────────────────────────────────────── |
| 222 |
function buildWrapStyle(a) { |
| 223 |
return { |
| 224 |
'--bkbg-div-color': a.lineColor, |
| 225 |
'--bkbg-div-thickness': a.lineThickness + 'px', |
| 226 |
'--bkbg-div-svgh': a.svgHeight + 'px', |
| 227 |
'--bkbg-div-dot-spacing': a.dotSpacing + 'px', |
| 228 |
'--bkbg-div-gap': a.gapAroundMiddle + 'px', |
| 229 |
'--bkbg-div-width': a.widthPercent + '%', |
| 230 |
'--bkbg-div-mt': a.marginTop + 'px', |
| 231 |
'--bkbg-div-mb': a.marginBottom + 'px', |
| 232 |
'--bkbg-div-text-size': a.textSize + 'px', |
| 233 |
'--bkbg-div-text-weight': a.textWeight, |
| 234 |
'--bkbg-div-text-color': a.textColor, |
| 235 |
'--bkbg-div-text-bg': a.textBgColor, |
| 236 |
'--bkbg-div-text-ph': a.textPaddingH + 'px', |
| 237 |
'--bkbg-div-text-pv': a.textPaddingV + 'px', |
| 238 |
'--bkbg-div-text-radius': a.textRadius + 'px' |
| 239 |
}; |
| 240 |
} |
| 241 |
|
| 242 |
registerBlockType('blockenberg/separator', { |
| 243 |
title: __('Separator / Divider', 'blockenberg'), |
| 244 |
icon: 'minus', |
| 245 |
category: 'bkbg-layout', |
| 246 |
description: __('Decorative divider: line, wave, zigzag or dot pattern — optionally with an icon or text in the centre.', 'blockenberg'), |
| 247 |
|
| 248 |
edit: function (props) { |
| 249 |
var a = props.attributes; |
| 250 |
var setAttributes = props.setAttributes; |
| 251 |
|
| 252 |
// ── Generate blockId on first mount ────────────────────────────── |
| 253 |
useEffect(function () { |
| 254 |
if (!a.blockId) { setAttributes({ blockId: generateId() }); } |
| 255 |
}, []); |
| 256 |
|
| 257 |
// ── Color picker state (one open at a time) ─────────────────────── |
| 258 |
var openColorKeyState = useState(null); |
| 259 |
var openColorKey = openColorKeyState[0]; |
| 260 |
var setOpenColorKey = openColorKeyState[1]; |
| 261 |
|
| 262 |
// ── Alpha-enabled color control ─────────────────────────────────── |
| 263 |
function renderColorControl(key, label, value, onChange) { |
| 264 |
var isOpen = openColorKey === key; |
| 265 |
return el('div', { key: key, style: { display: 'flex', alignItems: 'center', justifyContent: 'space-between', padding: '4px 0', gap: '8px' } }, |
| 266 |
el('span', { style: { fontSize: '12px', color: '#1e1e1e', flex: 1, lineHeight: 1.4 } }, label), |
| 267 |
el('div', { style: { position: 'relative', flexShrink: 0 } }, |
| 268 |
el('button', { |
| 269 |
type: 'button', |
| 270 |
title: value || 'none', |
| 271 |
onClick: function () { setOpenColorKey(isOpen ? null : key); }, |
| 272 |
style: { |
| 273 |
width: '28px', height: '28px', borderRadius: '4px', |
| 274 |
border: isOpen ? '2px solid #007cba' : '2px solid #ddd', |
| 275 |
cursor: 'pointer', padding: 0, display: 'block', |
| 276 |
background: value || '#ffffff', flexShrink: 0 |
| 277 |
} |
| 278 |
}), |
| 279 |
isOpen && el(Popover, { |
| 280 |
position: 'bottom left', |
| 281 |
onClose: function () { setOpenColorKey(null); } |
| 282 |
}, |
| 283 |
el('div', { |
| 284 |
style: { padding: '8px' }, |
| 285 |
onMouseDown: function (e) { e.stopPropagation(); } |
| 286 |
}, |
| 287 |
el('div', { style: { display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: '6px' } }, |
| 288 |
el('strong', { style: { fontSize: '12px' } }, label), |
| 289 |
el(Button, { icon: 'no-alt', isSmall: true, onClick: function () { setOpenColorKey(null); } }) |
| 290 |
), |
| 291 |
el(ColorPicker, { |
| 292 |
color: value, |
| 293 |
enableAlpha: true, |
| 294 |
onChange: function (c) { onChange(c); } |
| 295 |
}) |
| 296 |
) |
| 297 |
) |
| 298 |
) |
| 299 |
); |
| 300 |
} |
| 301 |
|
| 302 |
// ── Option lists ────────────────────────────────────────────────── |
| 303 |
var dividerTypeOptions = [ |
| 304 |
{ label: __('Line', 'blockenberg'), value: 'line' }, |
| 305 |
{ label: __('Dashed', 'blockenberg'), value: 'dashed' }, |
| 306 |
{ label: __('Dotted', 'blockenberg'), value: 'dotted' }, |
| 307 |
{ label: __('Double', 'blockenberg'), value: 'double' }, |
| 308 |
{ label: __('Triple', 'blockenberg'), value: 'triple' }, |
| 309 |
{ label: __('Gradient', 'blockenberg'), value: 'gradient' }, |
| 310 |
{ label: __('Dots', 'blockenberg'), value: 'dots' }, |
| 311 |
{ label: __('Wave', 'blockenberg'), value: 'wave' }, |
| 312 |
{ label: __('Zigzag', 'blockenberg'), value: 'zigzag' }, |
| 313 |
{ label: __('Scallop', 'blockenberg'), value: 'scallop' }, |
| 314 |
{ label: __('Arrows', 'blockenberg'), value: 'arrows' }, |
| 315 |
{ label: __('Brush', 'blockenberg'), value: 'brush' }, |
| 316 |
{ label: __('Heartbeat', 'blockenberg'), value: 'heartbeat' } |
| 317 |
]; |
| 318 |
|
| 319 |
var middleTypeOptions = [ |
| 320 |
{ label: __('None', 'blockenberg'), value: 'none' }, |
| 321 |
{ label: __('Icon', 'blockenberg'), value: 'icon' }, |
| 322 |
{ label: __('Text', 'blockenberg'), value: 'text' } |
| 323 |
]; |
| 324 |
|
| 325 |
var middlePosOptions = [ |
| 326 |
{ label: __('Left', 'blockenberg'), value: 'left' }, |
| 327 |
{ label: __('Center', 'blockenberg'), value: 'center' }, |
| 328 |
{ label: __('Right', 'blockenberg'), value: 'right' } |
| 329 |
]; |
| 330 |
|
| 331 |
var iconOptions = [ |
| 332 |
{ label: __('Star', 'blockenberg'), value: 'star' }, |
| 333 |
{ label: __('Heart', 'blockenberg'), value: 'heart' }, |
| 334 |
{ label: __('Diamond', 'blockenberg'), value: 'diamond' }, |
| 335 |
{ label: __('Bolt', 'blockenberg'), value: 'bolt' }, |
| 336 |
{ label: __('Moon', 'blockenberg'), value: 'moon' }, |
| 337 |
{ label: __('8-Point Star', 'blockenberg'), value: 'star8' }, |
| 338 |
{ label: __('Cross (+)', 'blockenberg'), value: 'cross' }, |
| 339 |
{ label: __('Leaf', 'blockenberg'), value: 'leaf' }, |
| 340 |
{ label: __('Snowflake', 'blockenberg'), value: 'snowflake' }, |
| 341 |
{ label: __('Circle', 'blockenberg'), value: 'circle' } |
| 342 |
]; |
| 343 |
|
| 344 |
var iconBgShapeOptions = [ |
| 345 |
{ label: __('None', 'blockenberg'), value: 'none' }, |
| 346 |
{ label: __('Circle', 'blockenberg'), value: 'circle' }, |
| 347 |
{ label: __('Square', 'blockenberg'), value: 'square' } |
| 348 |
]; |
| 349 |
|
| 350 |
var fontWeightOptions = [ |
| 351 |
{ label: '300 — Light', value: 300 }, |
| 352 |
{ label: '400 — Regular', value: 400 }, |
| 353 |
{ label: '500 — Medium', value: 500 }, |
| 354 |
{ label: '600 — Semi Bold', value: 600 }, |
| 355 |
{ label: '700 — Bold', value: 700 }, |
| 356 |
{ label: '800 — Extra Bold', value: 800 } |
| 357 |
]; |
| 358 |
|
| 359 |
var isSvgType = SVG_TYPES.indexOf(a.dividerType) !== -1; |
| 360 |
var isDotsType = a.dividerType === 'dots'; |
| 361 |
var hasMiddle = a.middleType !== 'none'; |
| 362 |
|
| 363 |
// ── Inspector ───────────────────────────────────────────────────── |
| 364 |
var inspector = el(InspectorControls, {}, |
| 365 |
|
| 366 |
// ── Divider ─────────────────────────────────────────────────── |
| 367 |
el(PanelBody, { title: __('Divider', 'blockenberg'), initialOpen: true }, |
| 368 |
el(SelectControl, { |
| 369 |
label: __('Type', 'blockenberg'), |
| 370 |
value: a.dividerType, |
| 371 |
options: dividerTypeOptions, |
| 372 |
onChange: function (v) { setAttributes({ dividerType: v }); } |
| 373 |
}), |
| 374 |
el(RangeControl, { |
| 375 |
label: isSvgType |
| 376 |
? __('Stroke Width (px)', 'blockenberg') |
| 377 |
: (isDotsType ? __('Dot Radius (px)', 'blockenberg') : __('Thickness (px)', 'blockenberg')), |
| 378 |
value: a.lineThickness, |
| 379 |
min: 1, |
| 380 |
max: isSvgType ? 8 : 12, |
| 381 |
onChange: function (v) { setAttributes({ lineThickness: v }); } |
| 382 |
}), |
| 383 |
(isSvgType || isDotsType) && el(RangeControl, { |
| 384 |
label: isSvgType |
| 385 |
? __('Height (px)', 'blockenberg') |
| 386 |
: __('Row Height (px)', 'blockenberg'), |
| 387 |
value: a.svgHeight, |
| 388 |
min: 8, |
| 389 |
max: 80, |
| 390 |
onChange: function (v) { setAttributes({ svgHeight: v }); } |
| 391 |
}), |
| 392 |
isDotsType && el(RangeControl, { |
| 393 |
label: __('Dot Spacing (px)', 'blockenberg'), |
| 394 |
value: a.dotSpacing, |
| 395 |
min: 4, |
| 396 |
max: 60, |
| 397 |
onChange: function (v) { setAttributes({ dotSpacing: v }); } |
| 398 |
}) |
| 399 |
), |
| 400 |
|
| 401 |
// ── Layout ──────────────────────────────────────────────────── |
| 402 |
el(PanelBody, { title: __('Layout', 'blockenberg'), initialOpen: false }, |
| 403 |
el(RangeControl, { |
| 404 |
label: __('Width (%)', 'blockenberg'), |
| 405 |
value: a.widthPercent, |
| 406 |
min: 10, |
| 407 |
max: 100, |
| 408 |
onChange: function (v) { setAttributes({ widthPercent: v }); } |
| 409 |
}), |
| 410 |
el(RangeControl, { |
| 411 |
label: __('Margin Top (px)', 'blockenberg'), |
| 412 |
value: a.marginTop, |
| 413 |
min: 0, |
| 414 |
max: 120, |
| 415 |
onChange: function (v) { setAttributes({ marginTop: v }); } |
| 416 |
}), |
| 417 |
el(RangeControl, { |
| 418 |
label: __('Margin Bottom (px)', 'blockenberg'), |
| 419 |
value: a.marginBottom, |
| 420 |
min: 0, |
| 421 |
max: 120, |
| 422 |
onChange: function (v) { setAttributes({ marginBottom: v }); } |
| 423 |
}) |
| 424 |
), |
| 425 |
|
| 426 |
// ── Centrepiece ─────────────────────────────────────────────── |
| 427 |
el(PanelBody, { title: __('Centrepiece', 'blockenberg'), initialOpen: false }, |
| 428 |
el(SelectControl, { |
| 429 |
label: __('Centrepiece', 'blockenberg'), |
| 430 |
value: a.middleType, |
| 431 |
options: middleTypeOptions, |
| 432 |
onChange: function (v) { setAttributes({ middleType: v }); } |
| 433 |
}), |
| 434 |
|
| 435 |
hasMiddle && el(Fragment, {}, |
| 436 |
el(SelectControl, { |
| 437 |
label: __('Position', 'blockenberg'), |
| 438 |
value: a.middlePosition, |
| 439 |
options: middlePosOptions, |
| 440 |
onChange: function (v) { setAttributes({ middlePosition: v }); } |
| 441 |
}), |
| 442 |
el(RangeControl, { |
| 443 |
label: __('Gap around centrepiece (px)', 'blockenberg'), |
| 444 |
value: a.gapAroundMiddle, |
| 445 |
min: 0, |
| 446 |
max: 60, |
| 447 |
onChange: function (v) { setAttributes({ gapAroundMiddle: v }); } |
| 448 |
}), |
| 449 |
|
| 450 |
// Icon-specific controls |
| 451 |
a.middleType === 'icon' && el(Fragment, {}, |
| 452 |
el('hr', {}), |
| 453 |
el('p', { style: { margin: '4px 0 6px', fontWeight: 600, fontSize: '11px', textTransform: 'uppercase', color: '#888' } }, |
| 454 |
__('Icon', 'blockenberg') |
| 455 |
), |
| 456 |
el(SelectControl, { |
| 457 |
label: __('Icon', 'blockenberg'), |
| 458 |
value: a.iconName, |
| 459 |
options: iconOptions, |
| 460 |
onChange: function (v) { setAttributes({ iconName: v }); } |
| 461 |
}), |
| 462 |
el(RangeControl, { |
| 463 |
label: __('Icon Size (px)', 'blockenberg'), |
| 464 |
value: a.iconSize, |
| 465 |
min: 12, |
| 466 |
max: 80, |
| 467 |
onChange: function (v) { setAttributes({ iconSize: v }); } |
| 468 |
}), |
| 469 |
el('hr', {}), |
| 470 |
el('p', { style: { margin: '4px 0 6px', fontWeight: 600, fontSize: '11px', textTransform: 'uppercase', color: '#888' } }, |
| 471 |
__('Icon Background', 'blockenberg') |
| 472 |
), |
| 473 |
el(SelectControl, { |
| 474 |
label: __('Shape', 'blockenberg'), |
| 475 |
value: a.iconBgShape, |
| 476 |
options: iconBgShapeOptions, |
| 477 |
onChange: function (v) { setAttributes({ iconBgShape: v }); } |
| 478 |
}), |
| 479 |
a.iconBgShape !== 'none' && el(RangeControl, { |
| 480 |
label: __('Background Size (px)', 'blockenberg'), |
| 481 |
value: a.iconBgSize, |
| 482 |
min: a.iconSize, |
| 483 |
max: 120, |
| 484 |
onChange: function (v) { setAttributes({ iconBgSize: v }); } |
| 485 |
}) |
| 486 |
), |
| 487 |
|
| 488 |
// Text-specific controls |
| 489 |
a.middleType === 'text' && el(Fragment, {}, |
| 490 |
el('hr', {}), |
| 491 |
el('p', { style: { margin: '4px 0 6px', fontWeight: 600, fontSize: '11px', textTransform: 'uppercase', color: '#888' } }, |
| 492 |
__('Text Style', 'blockenberg') |
| 493 |
), |
| 494 |
el(RangeControl, { |
| 495 |
label: __('Padding Horizontal (px)', 'blockenberg'), |
| 496 |
value: a.textPaddingH, |
| 497 |
min: 0, |
| 498 |
max: 48, |
| 499 |
onChange: function (v) { setAttributes({ textPaddingH: v }); } |
| 500 |
}), |
| 501 |
el(RangeControl, { |
| 502 |
label: __('Padding Vertical (px)', 'blockenberg'), |
| 503 |
value: a.textPaddingV, |
| 504 |
min: 0, |
| 505 |
max: 32, |
| 506 |
onChange: function (v) { setAttributes({ textPaddingV: v }); } |
| 507 |
}), |
| 508 |
el(RangeControl, { |
| 509 |
label: __('Border Radius (px)', 'blockenberg'), |
| 510 |
value: a.textRadius, |
| 511 |
min: 0, |
| 512 |
max: 50, |
| 513 |
onChange: function (v) { setAttributes({ textRadius: v }); } |
| 514 |
}) |
| 515 |
) |
| 516 |
) |
| 517 |
), |
| 518 |
|
| 519 |
// ── Colors ──────────────────────────────────────────────────── |
| 520 |
el(PanelBody, { title: __('Colors', 'blockenberg'), initialOpen: false }, |
| 521 |
el('p', { style: { margin: '4px 0 6px', fontWeight: 600, fontSize: '11px', textTransform: 'uppercase', color: '#888' } }, |
| 522 |
__('Line', 'blockenberg') |
| 523 |
), |
| 524 |
renderColorControl('lineColor', __('Line / stroke color', 'blockenberg'), a.lineColor, |
| 525 |
function (c) { setAttributes({ lineColor: c }); } |
| 526 |
), |
| 527 |
|
| 528 |
a.middleType === 'icon' && el(Fragment, {}, |
| 529 |
el('hr', {}), |
| 530 |
el('p', { style: { margin: '4px 0 6px', fontWeight: 600, fontSize: '11px', textTransform: 'uppercase', color: '#888' } }, |
| 531 |
__('Icon', 'blockenberg') |
| 532 |
), |
| 533 |
renderColorControl('iconColor', __('Icon fill', 'blockenberg'), a.iconColor, |
| 534 |
function (c) { setAttributes({ iconColor: c }); } |
| 535 |
), |
| 536 |
a.iconBgShape !== 'none' && renderColorControl('iconBgColor', __('Icon background', 'blockenberg'), a.iconBgColor, |
| 537 |
function (c) { setAttributes({ iconBgColor: c }); } |
| 538 |
) |
| 539 |
), |
| 540 |
|
| 541 |
a.middleType === 'text' && el(Fragment, {}, |
| 542 |
el('hr', {}), |
| 543 |
el('p', { style: { margin: '4px 0 6px', fontWeight: 600, fontSize: '11px', textTransform: 'uppercase', color: '#888' } }, |
| 544 |
__('Text', 'blockenberg') |
| 545 |
), |
| 546 |
renderColorControl('textColor', __('Text color', 'blockenberg'), a.textColor, |
| 547 |
function (c) { setAttributes({ textColor: c }); } |
| 548 |
), |
| 549 |
renderColorControl('textBgColor', __('Text background', 'blockenberg'), a.textBgColor, |
| 550 |
function (c) { setAttributes({ textBgColor: c }); } |
| 551 |
) |
| 552 |
) |
| 553 |
), |
| 554 |
|
| 555 |
// ── Typography ─────────────────────────────────────────────── |
| 556 |
el(PanelBody, { title: __('Typography', 'blockenberg'), initialOpen: false }, |
| 557 |
el(getTC(), { label: __('Centrepiece Text', 'blockenberg'), value: a.textTypo, onChange: function (v) { setAttributes({ textTypo: v }); } }) |
| 558 |
) |
| 559 |
); |
| 560 |
|
| 561 |
// ── Build line segments ─────────────────────────────────────────── |
| 562 |
var segLFlex = !hasMiddle ? '1' |
| 563 |
: a.middlePosition === 'left' ? '0 0 20px' |
| 564 |
: '1'; |
| 565 |
var segRFlex = !hasMiddle ? '0 0 0px' |
| 566 |
: a.middlePosition === 'right' ? '0 0 20px' |
| 567 |
: '1'; |
| 568 |
|
| 569 |
// When no middle: single full-width segment |
| 570 |
var segments; |
| 571 |
if (!hasMiddle) { |
| 572 |
segments = [buildLineSeg(a, 'full', '1')]; |
| 573 |
} else { |
| 574 |
var leftSeg = buildLineSeg(a, 'l', segLFlex); |
| 575 |
var rightSeg = buildLineSeg(a, 'r', segRFlex); |
| 576 |
|
| 577 |
var middleEl; |
| 578 |
if (a.middleType === 'icon') { |
| 579 |
middleEl = el('span', { key: 'middle', className: 'bkbg-div-middle' }, |
| 580 |
buildIconMiddle(a) |
| 581 |
); |
| 582 |
} else { |
| 583 |
// text — RichText in edit |
| 584 |
middleEl = el('span', { key: 'middle', className: 'bkbg-div-middle' }, |
| 585 |
el(RichText, { |
| 586 |
tagName: 'span', |
| 587 |
className: 'bkbg-div-mid-text', |
| 588 |
value: a.middleText, |
| 589 |
onChange: function (v) { setAttributes({ middleText: v }); }, |
| 590 |
placeholder: __('Text…', 'blockenberg'), |
| 591 |
allowedFormats: ['core/bold', 'core/italic', 'core/text-color'] |
| 592 |
}) |
| 593 |
); |
| 594 |
} |
| 595 |
segments = [leftSeg, middleEl, rightSeg]; |
| 596 |
} |
| 597 |
|
| 598 |
// ── Edit render ─────────────────────────────────────────────────── |
| 599 |
var blockProps = useBlockProps((function () { |
| 600 |
var _tvFn = getTV(); |
| 601 |
var s = {}; |
| 602 |
Object.assign(s, _tvFn(a.textTypo, '--bkdv-tt-')); |
| 603 |
return { |
| 604 |
className: 'bkbg-editor-wrap', |
| 605 |
'data-block-label': 'Separator', |
| 606 |
style: s |
| 607 |
}; |
| 608 |
})()); |
| 609 |
|
| 610 |
return el('div', blockProps, |
| 611 |
inspector, |
| 612 |
el('div', { |
| 613 |
className: 'bkbg-div-outer', |
| 614 |
style: { marginTop: a.marginTop + 'px', marginBottom: a.marginBottom + 'px' } |
| 615 |
}, |
| 616 |
el('div', Object.assign( |
| 617 |
{ className: 'bkbg-div-wrap', style: buildWrapStyle(a) }, |
| 618 |
{ 'data-type': a.dividerType, 'data-middle': a.middleType } |
| 619 |
), segments) |
| 620 |
) |
| 621 |
); |
| 622 |
}, |
| 623 |
|
| 624 |
deprecated: [{ |
| 625 |
attributes: {"blockId":{"type":"string","default":""},"dividerType":{"type":"string","default":"line"},"lineColor":{"type":"string","default":"#d1d5db"},"lineThickness":{"type":"number","default":1},"svgHeight":{"type":"number","default":24},"dotSpacing":{"type":"number","default":14},"marginTop":{"type":"number","default":24},"marginBottom":{"type":"number","default":24},"widthPercent":{"type":"number","default":100},"middleType":{"type":"string","default":"none"},"middlePosition":{"type":"string","default":"center"},"gapAroundMiddle":{"type":"number","default":16},"iconName":{"type":"string","default":"star"},"iconSize":{"type":"number","default":20},"iconColor":{"type":"string","default":"#9ca3af"},"iconBgColor":{"type":"string","default":"transparent"},"iconBgShape":{"type":"string","default":"none"},"iconBgSize":{"type":"number","default":36},"middleText":{"type":"string","default":"§"},"textSize":{"type":"number","default":14},"textWeight":{"type":"number","default":400},"textColor":{"type":"string","default":"#9ca3af"},"textBgColor":{"type":"string","default":"transparent"},"textPaddingH":{"type":"number","default":12},"textPaddingV":{"type":"number","default":4},"textRadius":{"type":"number","default":4}}, |
| 626 |
save: function (props) { |
| 627 |
var a = props.attributes; |
| 628 |
var RichTextContent = wp.blockEditor.RichText.Content; |
| 629 |
var hasMiddle = a.middleType !== 'none'; |
| 630 |
var segLFlex = !hasMiddle ? '1' : a.middlePosition === 'left' ? '0 0 20px' : '1'; |
| 631 |
var segRFlex = !hasMiddle ? '0 0 0px' : a.middlePosition === 'right' ? '0 0 20px' : '1'; |
| 632 |
var segments; |
| 633 |
if (!hasMiddle) { |
| 634 |
segments = [buildLineSeg(a, 'full', '1')]; |
| 635 |
} else { |
| 636 |
var leftSeg = buildLineSeg(a, 'l', segLFlex); |
| 637 |
var rightSeg = buildLineSeg(a, 'r', segRFlex); |
| 638 |
var middleEl; |
| 639 |
if (a.middleType === 'icon') { |
| 640 |
middleEl = el('span', { key: 'middle', className: 'bkbg-div-middle' }, buildIconMiddle(a)); |
| 641 |
} else { |
| 642 |
middleEl = el('span', { key: 'middle', className: 'bkbg-div-middle' }, |
| 643 |
el(RichTextContent, { tagName: 'span', className: 'bkbg-div-mid-text', value: a.middleText }) |
| 644 |
); |
| 645 |
} |
| 646 |
segments = [leftSeg, middleEl, rightSeg]; |
| 647 |
} |
| 648 |
return el('div', { |
| 649 |
className: 'bkbg-div-outer', |
| 650 |
style: { marginTop: a.marginTop + 'px', marginBottom: a.marginBottom + 'px' } |
| 651 |
}, |
| 652 |
el('div', Object.assign( |
| 653 |
{ className: 'bkbg-div-wrap', style: buildWrapStyle(a) }, |
| 654 |
{ 'data-type': a.dividerType, 'data-middle': a.middleType } |
| 655 |
), segments) |
| 656 |
); |
| 657 |
} |
| 658 |
}], |
| 659 |
|
| 660 |
// ── Save ───────────────────────────────────────────────────────────────── |
| 661 |
save: function (props) { |
| 662 |
var a = props.attributes; |
| 663 |
var RichTextContent = wp.blockEditor.RichText.Content; |
| 664 |
|
| 665 |
var hasMiddle = a.middleType !== 'none'; |
| 666 |
var segLFlex = !hasMiddle ? '1' |
| 667 |
: a.middlePosition === 'left' ? '0 0 20px' |
| 668 |
: '1'; |
| 669 |
var segRFlex = !hasMiddle ? '0 0 0px' |
| 670 |
: a.middlePosition === 'right' ? '0 0 20px' |
| 671 |
: '1'; |
| 672 |
|
| 673 |
var segments; |
| 674 |
if (!hasMiddle) { |
| 675 |
segments = [buildLineSeg(a, 'full', '1')]; |
| 676 |
} else { |
| 677 |
var leftSeg = buildLineSeg(a, 'l', segLFlex); |
| 678 |
var rightSeg = buildLineSeg(a, 'r', segRFlex); |
| 679 |
|
| 680 |
var middleEl; |
| 681 |
if (a.middleType === 'icon') { |
| 682 |
middleEl = el('span', { key: 'middle', className: 'bkbg-div-middle' }, |
| 683 |
buildIconMiddle(a) |
| 684 |
); |
| 685 |
} else { |
| 686 |
// text: use RichText.Content |
| 687 |
middleEl = el('span', { key: 'middle', className: 'bkbg-div-middle' }, |
| 688 |
el(RichTextContent, { |
| 689 |
tagName: 'span', |
| 690 |
className: 'bkbg-div-mid-text', |
| 691 |
value: a.middleText |
| 692 |
}) |
| 693 |
); |
| 694 |
} |
| 695 |
segments = [leftSeg, middleEl, rightSeg]; |
| 696 |
} |
| 697 |
|
| 698 |
var wStyle = buildWrapStyle(a); |
| 699 |
var _tvFn = window.bkbgTypoCssVars; |
| 700 |
if (_tvFn) { |
| 701 |
Object.assign(wStyle, _tvFn(a.textTypo || {}, '--bkdv-tt-')); |
| 702 |
} |
| 703 |
|
| 704 |
return el('div', { |
| 705 |
className: 'bkbg-div-outer', |
| 706 |
style: { marginTop: a.marginTop + 'px', marginBottom: a.marginBottom + 'px' } |
| 707 |
}, |
| 708 |
el('div', Object.assign( |
| 709 |
{ className: 'bkbg-div-wrap', style: wStyle }, |
| 710 |
{ 'data-type': a.dividerType, 'data-middle': a.middleType } |
| 711 |
), segments) |
| 712 |
); |
| 713 |
} |
| 714 |
}); |
| 715 |
}() ); |
| 716 |
|