| 1 |
( function () { |
| 2 |
var el = window.wp.element.createElement; |
| 3 |
var { registerBlockType } = window.wp.blocks; |
| 4 |
var { InspectorControls, PanelColorSettings, useBlockProps } = window.wp.blockEditor; |
| 5 |
var { PanelBody, RangeControl, SelectControl, TextControl, ToggleControl } = window.wp.components; |
| 6 |
var { __ } = window.wp.i18n; |
| 7 |
|
| 8 |
var _tc; function getTypoControl() { return _tc || (_tc = window.bkbgTypographyControl); } |
| 9 |
var _tv; function getTypoCssVars() { return _tv || (_tv = window.bkbgTypoCssVars); } |
| 10 |
|
| 11 |
var LINE_STYLES = [{label:'Solid',value:'solid'},{label:'Dashed',value:'dashed'},{label:'Dotted',value:'dotted'},{label:'Double',value:'double'}]; |
| 12 |
var LABEL_STYLES = [{label:'Text',value:'text'},{label:'Badge',value:'badge'},{label:'Icon',value:'icon'}]; |
| 13 |
var ALIGNS = [{label:'Left',value:'left'},{label:'Center',value:'center'},{label:'Right',value:'right'}]; |
| 14 |
var DASHICONS = ['star-filled','heart','yes','info','warning','tag','admin-links','minus','plus','arrow-right','arrow-down','format-quote'].map(i=>({label:i,value:i})); |
| 15 |
|
| 16 |
function renderDivider(a) { |
| 17 |
var lineStyle = { borderTopStyle: a.lineStyle, borderTopWidth: a.lineThickness+'px', borderTopColor: a.lineColor, flex: 1 }; |
| 18 |
|
| 19 |
var labelNode = null; |
| 20 |
if (a.showLabel) { |
| 21 |
var inner; |
| 22 |
if (a.labelStyle === 'icon' && a.showIcon) { |
| 23 |
inner = el('span',{className:'dashicons dashicons-'+a.icon,style:{fontSize:a.iconSize+'px',width:a.iconSize+'px',height:a.iconSize+'px',color:a.iconColor,lineHeight:1,verticalAlign:'middle'}}); |
| 24 |
} else { |
| 25 |
inner = el('span',{className:'bktd-text',style:{ |
| 26 |
color:a.labelColor,verticalAlign:'middle', |
| 27 |
}},a.label); |
| 28 |
} |
| 29 |
labelNode = el('span',{className:'bktd-label',style:{ |
| 30 |
display:'inline-flex',alignItems:'center',padding:a.labelPaddingY+'px '+a.labelPaddingX+'px', |
| 31 |
background:a.labelBg,borderRadius:a.labelRadius+'px', |
| 32 |
border: a.labelBorder ? '1px solid '+a.labelBorderColor : 'none', |
| 33 |
lineHeight:1.2, flexShrink:0, |
| 34 |
}},inner); |
| 35 |
} |
| 36 |
|
| 37 |
var wrapStyle = { display:'flex', alignItems:'center', gap:'12px', width: a.lineWidth+'%', |
| 38 |
marginTop: a.marginTop+'px', marginBottom: a.marginBottom+'px', |
| 39 |
marginLeft: a.align==='center'?'auto': a.align==='right'?'auto':'0', |
| 40 |
marginRight: a.align==='center'?'auto': a.align==='left'?'auto':'0', |
| 41 |
}; |
| 42 |
|
| 43 |
return el('div',{className:'bktd-wrap',style:wrapStyle}, |
| 44 |
a.showLabel && el('div',{style:{...lineStyle}}), |
| 45 |
labelNode, |
| 46 |
el('div',{style:{...lineStyle}}), |
| 47 |
); |
| 48 |
} |
| 49 |
|
| 50 |
registerBlockType('blockenberg/text-divider', { |
| 51 |
edit: function(props) { |
| 52 |
var a = props.attributes; |
| 53 |
var set = props.setAttributes; |
| 54 |
return el('div',useBlockProps((function () { |
| 55 |
var s = {}; |
| 56 |
var _tvf = getTypoCssVars(); |
| 57 |
if (_tvf) { Object.assign(s, _tvf(a.labelTypo, '--bktd-lb-')); } |
| 58 |
return { style: s }; |
| 59 |
})()), |
| 60 |
el(InspectorControls,null, |
| 61 |
el(PanelBody,{title:__('Label'),initialOpen:true}, |
| 62 |
el(ToggleControl,{label:__('Show Label'),checked:a.showLabel,onChange:v=>set({showLabel:v}),__nextHasNoMarginBottom:true}), |
| 63 |
a.showLabel && el(SelectControl,{label:__('Label Style'),value:a.labelStyle,options:LABEL_STYLES,onChange:v=>set({labelStyle:v})}), |
| 64 |
a.showLabel && a.labelStyle !== 'icon' && el(TextControl,{label:__('Label Text'),value:a.label,onChange:v=>set({label:v})}), |
| 65 |
a.showLabel && a.labelStyle === 'icon' && el(SelectControl,{label:__('Dashicon'),value:a.icon,options:DASHICONS,onChange:v=>set({icon:v})}), |
| 66 |
a.showLabel && a.labelStyle === 'icon' && el(RangeControl,{label:__('Icon Size (px)'),value:a.iconSize,min:10,max:60,onChange:v=>set({iconSize:v})}), |
| 67 |
a.showLabel && el(RangeControl,{label:__('Padding X (px)'),value:a.labelPaddingX,min:0,max:40,onChange:v=>set({labelPaddingX:v})}), |
| 68 |
a.showLabel && el(RangeControl,{label:__('Padding Y (px)'),value:a.labelPaddingY,min:0,max:20,onChange:v=>set({labelPaddingY:v})}), |
| 69 |
a.showLabel && el(RangeControl,{label:__('Border Radius (px)'),value:a.labelRadius,min:0,max:60,onChange:v=>set({labelRadius:v})}), |
| 70 |
a.showLabel && el(ToggleControl,{label:__('Show Border'),checked:a.labelBorder,onChange:v=>set({labelBorder:v}),__nextHasNoMarginBottom:true}), |
| 71 |
), |
| 72 |
el(PanelBody,{title:__('Line'),initialOpen:false}, |
| 73 |
el(SelectControl,{label:__('Line Style'),value:a.lineStyle,options:LINE_STYLES,onChange:v=>set({lineStyle:v})}), |
| 74 |
el(RangeControl,{label:__('Thickness (px)'),value:a.lineThickness,min:1,max:10,onChange:v=>set({lineThickness:v})}), |
| 75 |
el(RangeControl,{label:__('Width (%)'),value:a.lineWidth,min:10,max:100,onChange:v=>set({lineWidth:v})}), |
| 76 |
el(SelectControl,{label:__('Alignment'),value:a.align,options:ALIGNS,onChange:v=>set({align:v})}), |
| 77 |
), |
| 78 |
el(PanelBody,{title:__('Spacing'),initialOpen:false}, |
| 79 |
el(RangeControl,{label:__('Margin Top (px)'),value:a.marginTop,min:0,max:100,onChange:v=>set({marginTop:v})}), |
| 80 |
el(RangeControl,{label:__('Margin Bottom (px)'),value:a.marginBottom,min:0,max:100,onChange:v=>set({marginBottom:v})}), |
| 81 |
), |
| 82 |
|
| 83 |
el( PanelBody, { title: __( 'Typography', 'blockenberg' ), initialOpen: false }, |
| 84 |
getTypoControl() && getTypoControl()({ |
| 85 |
label: __('Label', 'blockenberg'), |
| 86 |
value: a.labelTypo || {}, |
| 87 |
onChange: function (v) { set({ labelTypo: v }); } |
| 88 |
}) |
| 89 |
), |
| 90 |
el(PanelColorSettings,{title:__('Colors'),initialOpen:false,colorSettings:[ |
| 91 |
{label:__('Line Color'), value:a.lineColor, onChange:v=>set({lineColor:v||'#e5e7eb'})}, |
| 92 |
{label:__('Label Text Color'), value:a.labelColor, onChange:v=>set({labelColor:v||'#6b7280'})}, |
| 93 |
{label:__('Label Background'), value:a.labelBg, onChange:v=>set({labelBg:v||'#ffffff'})}, |
| 94 |
{label:__('Label Border Color'), value:a.labelBorderColor, onChange:v=>set({labelBorderColor:v||'#e5e7eb'})}, |
| 95 |
{label:__('Icon Color'), value:a.iconColor, onChange:v=>set({iconColor:v||'#9ca3af'})}, |
| 96 |
]}), |
| 97 |
), |
| 98 |
renderDivider(a), |
| 99 |
); |
| 100 |
}, |
| 101 |
|
| 102 |
save: function({attributes:a}) { |
| 103 |
var _tvf = getTypoCssVars(); |
| 104 |
var lineStyle = {borderTopStyle:a.lineStyle,borderTopWidth:a.lineThickness+'px',borderTopColor:a.lineColor,flex:1}; |
| 105 |
var showIcon = a.labelStyle === 'icon'; |
| 106 |
|
| 107 |
var wrapStyle = { |
| 108 |
display:'flex', alignItems:'center', gap:'12px', |
| 109 |
width:a.lineWidth+'%', |
| 110 |
marginTop:a.marginTop+'px', marginBottom:a.marginBottom+'px', |
| 111 |
marginLeft:a.align==='center'||a.align==='right'?'auto':'0', |
| 112 |
marginRight:a.align==='center'||a.align==='left'?'auto':'0', |
| 113 |
}; |
| 114 |
|
| 115 |
return el('div',useBlockProps.save((function () { |
| 116 |
var s = Object.assign({}, wrapStyle); |
| 117 |
if (_tvf) { Object.assign(s, _tvf(a.labelTypo, '--bktd-lb-')); } |
| 118 |
return { className: 'bktd-wrap', style: s }; |
| 119 |
})()), |
| 120 |
a.showLabel && el('div',{className:'bktd-line bktd-line-left',style:lineStyle}), |
| 121 |
a.showLabel && el('span',{className:'bktd-label',style:{ |
| 122 |
display:'inline-flex',alignItems:'center',padding:a.labelPaddingY+'px '+a.labelPaddingX+'px', |
| 123 |
background:a.labelBg,borderRadius:a.labelRadius+'px', |
| 124 |
border:a.labelBorder?'1px solid '+a.labelBorderColor:'none', |
| 125 |
lineHeight:1.2, flexShrink:0, |
| 126 |
}}, |
| 127 |
showIcon |
| 128 |
? el('span',{className:'dashicons dashicons-'+a.icon,style:{fontSize:a.iconSize+'px',width:a.iconSize+'px',height:a.iconSize+'px',color:a.iconColor,lineHeight:1}}) |
| 129 |
: el('span',{className:'bktd-text',style:{color:a.labelColor}},a.label) |
| 130 |
), |
| 131 |
el('div',{className:'bktd-line bktd-line-right',style:lineStyle}), |
| 132 |
); |
| 133 |
} |
| 134 |
}); |
| 135 |
}() ); |
| 136 |
|