| 1 |
/* ==================================================== |
| 2 |
Problem / Solution Block — editor (index.js) |
| 3 |
Block: blockenberg/problem-solution |
| 4 |
==================================================== */ |
| 5 |
( function () { |
| 6 |
var el = wp.element.createElement; |
| 7 |
var Fragment = wp.element.Fragment; |
| 8 |
var useState = wp.element.useState; |
| 9 |
var RichText = wp.blockEditor.RichText; |
| 10 |
var registerBlockType = wp.blocks.registerBlockType; |
| 11 |
var InspectorControls = wp.blockEditor.InspectorControls; |
| 12 |
var useBlockProps = wp.blockEditor.useBlockProps; |
| 13 |
var PanelBody = wp.components.PanelBody; |
| 14 |
var PanelColorSettings = wp.blockEditor.PanelColorSettings; |
| 15 |
var RangeControl = wp.components.RangeControl; |
| 16 |
var SelectControl = wp.components.SelectControl; |
| 17 |
var ToggleControl = wp.components.ToggleControl; |
| 18 |
var TextControl = wp.components.TextControl; |
| 19 |
var Button = wp.components.Button; |
| 20 |
var __ = wp.i18n.__; |
| 21 |
|
| 22 |
var _tc; function getTypoControl() { return _tc || (_tc = window.bkbgTypographyControl); } |
| 23 |
var _tv; function getTypoCssVars() { return _tv || (_tv = window.bkbgTypoCssVars); } |
| 24 |
var IP = function () { return window.bkbgIconPicker; }; |
| 25 |
|
| 26 |
function buildTypoVars(a) { |
| 27 |
var fn = getTypoCssVars(); |
| 28 |
if (!fn) return {}; |
| 29 |
var v = {}; |
| 30 |
Object.assign(v, fn(a.titleTypo || {}, '--bkbg-psol-tt-')); |
| 31 |
Object.assign(v, fn(a.itemTypo || {}, '--bkbg-psol-it-')); |
| 32 |
Object.assign(v, fn(a.labelTypo || {}, '--bkbg-psol-lb-')); |
| 33 |
return v; |
| 34 |
} |
| 35 |
|
| 36 |
function uid() { return 'p' + Math.random().toString(36).slice(2, 7); } |
| 37 |
|
| 38 |
function buildWrapStyle(a) { |
| 39 |
return { |
| 40 |
'--bkbg-psol-gap': a.gap + 'px', |
| 41 |
'--bkbg-psol-radius': a.borderRadius + 'px', |
| 42 |
'--bkbg-psol-icon-size': a.iconSize + 'px', |
| 43 |
'--bkbg-psol-pv': a.paddingV + 'px', |
| 44 |
'--bkbg-psol-ph': a.paddingH + 'px', |
| 45 |
'--bkbg-psol-spacing': a.itemSpacing + 'px', |
| 46 |
'--bkbg-psol-prob-bg': a.problemBg, |
| 47 |
'--bkbg-psol-prob-color':a.problemColor, |
| 48 |
'--bkbg-psol-prob-icbg': a.problemIconBg, |
| 49 |
'--bkbg-psol-sol-bg': a.solutionBg, |
| 50 |
'--bkbg-psol-sol-color': a.solutionColor, |
| 51 |
'--bkbg-psol-sol-icbg': a.solutionIconBg, |
| 52 |
'--bkbg-psol-div-bg': a.dividerBg, |
| 53 |
'--bkbg-psol-div-text': a.dividerTextColor, |
| 54 |
}; |
| 55 |
} |
| 56 |
|
| 57 |
/* ── Items editor inside inspector ── */ |
| 58 |
function ItemsEditor(props) { |
| 59 |
var items = props.items; |
| 60 |
var onChange = props.onChange; |
| 61 |
var label = props.label; |
| 62 |
return el('div', null, |
| 63 |
el('strong', { style:{ display:'block', marginBottom:'6px', fontSize:'12px' }}, label), |
| 64 |
items.map(function(item, i) { |
| 65 |
return el('div', { key: item.id, style:{ display:'flex', gap:'4px', marginBottom:'4px', alignItems:'center' } }, |
| 66 |
el(TextControl, { value: item.text, onChange:function(v){ var n=items.slice(); n[i]=Object.assign({},item,{text:v}); onChange(n); }, style:{ flex:1 } }), |
| 67 |
el(Button, { icon:'no-alt', isSmall:true, isDestructive:true, label:__('Remove','blockenberg'), onClick:function(){ onChange(items.filter(function(_,j){ return j!==i; })); } }) |
| 68 |
); |
| 69 |
}), |
| 70 |
el(Button, { variant:'secondary', isSmall:true, style:{ marginTop:'4px', width:'100%' }, |
| 71 |
onClick:function(){ onChange(items.concat([{id:uid(),text:'New item'}])); } |
| 72 |
}, __('+ Add item','blockenberg')) |
| 73 |
); |
| 74 |
} |
| 75 |
|
| 76 |
/* ── Column render ── */ |
| 77 |
function PanelCol(props) { |
| 78 |
var a = props.a; |
| 79 |
var side = props.side; /* 'problem' | 'solution' */ |
| 80 |
var isEdit = props.isEdit; |
| 81 |
var setAttr = props.setAttr; |
| 82 |
|
| 83 |
var icon = side === 'problem' ? a.problemIcon : a.solutionIcon; |
| 84 |
var iconType = side === 'problem' ? (a.problemIconType || 'custom-char') : (a.solutionIconType || 'custom-char'); |
| 85 |
var iconDash = side === 'problem' ? a.problemIconDashicon : a.solutionIconDashicon; |
| 86 |
var iconImg = side === 'problem' ? a.problemIconImageUrl : a.solutionIconImageUrl; |
| 87 |
var label = side === 'problem' ? a.problemLabel : a.solutionLabel; |
| 88 |
var title = side === 'problem' ? a.problemTitle : a.solutionTitle; |
| 89 |
var items = side === 'problem' ? a.problemItems : a.solutionItems; |
| 90 |
var itemIcon = side === 'problem' ? a.problemItemIcon : a.solutionItemIcon; |
| 91 |
var itemIconType = side === 'problem' ? (a.problemItemIconType || 'custom-char') : (a.solutionItemIconType || 'custom-char'); |
| 92 |
var itemIconDash = side === 'problem' ? a.problemItemIconDashicon : a.solutionItemIconDashicon; |
| 93 |
var itemIconImg = side === 'problem' ? a.problemItemIconImageUrl : a.solutionItemIconImageUrl; |
| 94 |
var iconDashColor = side === 'problem' ? a.problemIconDashiconColor : a.solutionIconDashiconColor; |
| 95 |
var itemIconDashColor = side === 'problem' ? a.problemItemIconDashiconColor : a.solutionItemIconDashiconColor; |
| 96 |
var colorCls = 'bkbg-psol-col bkbg-psol-col--' + side; |
| 97 |
|
| 98 |
var itemEls = items.map(function(item) { |
| 99 |
return el('li', { key: item.id, className: 'bkbg-psol-item' }, |
| 100 |
el('span', { className: 'bkbg-psol-item-icon' }, itemIconType !== 'custom-char' ? IP().buildEditorIcon(itemIconType, itemIcon, itemIconDash, itemIconImg, itemIconDashColor) : itemIcon), |
| 101 |
el('span', { className: 'bkbg-psol-item-text' }, item.text) |
| 102 |
); |
| 103 |
}); |
| 104 |
|
| 105 |
var labelEl = a.showLabels ? el('span', { className: 'bkbg-psol-label' }, label) : null; |
| 106 |
var iconEl = el('span', { className: 'bkbg-psol-col-icon' }, iconType !== 'custom-char' ? IP().buildEditorIcon(iconType, icon, iconDash, iconImg, iconDashColor) : icon); |
| 107 |
var titleEl = isEdit |
| 108 |
? el(RichText, { tagName:'h3', className:'bkbg-psol-title', value:title, onChange:function(v){ var p={}; p[side==='problem'?'problemTitle':'solutionTitle']=v; setAttr(p); }, placeholder:__('Title…','blockenberg') }) |
| 109 |
: el(RichText.Content, { tagName:'h3', className:'bkbg-psol-title', value:title }); |
| 110 |
|
| 111 |
return el('div', { className: colorCls }, |
| 112 |
el('div', { className: 'bkbg-psol-col-header' }, |
| 113 |
iconEl, |
| 114 |
el('div', { className: 'bkbg-psol-col-meta' }, |
| 115 |
labelEl, |
| 116 |
titleEl |
| 117 |
) |
| 118 |
), |
| 119 |
el('ul', { className: 'bkbg-psol-list' }, itemEls) |
| 120 |
); |
| 121 |
} |
| 122 |
|
| 123 |
/* ── REGISTER ── */ |
| 124 |
registerBlockType('blockenberg/problem-solution', { |
| 125 |
edit: function (props) { |
| 126 |
var a = props.attributes; |
| 127 |
var setAttr = props.setAttributes; |
| 128 |
var style = buildWrapStyle(a); |
| 129 |
var blockProps = useBlockProps({ className:'bkbg-psol-wrap bkbg-psol-style--' + a.style, style: Object.assign({}, style, buildTypoVars(a)) }); |
| 130 |
|
| 131 |
var inspector = el(InspectorControls, null, |
| 132 |
/* Style */ |
| 133 |
el(PanelBody, { title:__('Style','blockenberg'), initialOpen:true }, |
| 134 |
el(SelectControl, { label:__('Visual style','blockenberg'), value:a.style, options:[ |
| 135 |
{label:__('Split (full-color columns)','blockenberg'), value:'split'}, |
| 136 |
{label:__('Cards (white bg + border)','blockenberg'), value:'cards'}, |
| 137 |
{label:__('Bordered (outline only)','blockenberg'), value:'bordered'}, |
| 138 |
{label:__('Minimal (subtle tint)','blockenberg'), value:'minimal'}, |
| 139 |
], onChange:function(v){ setAttr({style:v}); } }), |
| 140 |
el(ToggleControl, { label:__('Show column labels','blockenberg'), checked:a.showLabels, onChange:function(v){ setAttr({showLabels:v}); } }), |
| 141 |
el(ToggleControl, { label:__('Show "vs" divider','blockenberg'), checked:a.showDivider, onChange:function(v){ setAttr({showDivider:v}); } }), |
| 142 |
a.showDivider ? el(TextControl, { label:__('Divider label','blockenberg'), value:a.dividerLabel, onChange:function(v){ setAttr({dividerLabel:v}); } }) : null, |
| 143 |
a.showDivider ? el(ToggleControl, { label:__('Rotate divider text vertically','blockenberg'), checked:a.dividerVertical, onChange:function(v){ setAttr({dividerVertical:v}); } }) : null, |
| 144 |
a.showDivider ? el(ToggleControl, { label:__('Rotate divider on mobile only','blockenberg'), checked:a.dividerMobileRotate, onChange:function(v){ setAttr({dividerMobileRotate:v}); } }) : null |
| 145 |
), |
| 146 |
|
| 147 |
/* Problem column */ |
| 148 |
el(PanelBody, { title:__('Problem column','blockenberg'), initialOpen:false }, |
| 149 |
el(IP().IconPickerControl, IP().iconPickerProps(attr, setAttr, { charAttr: 'problemIcon', typeAttr: 'problemIconType', dashiconAttr: 'problemIconDashicon', imageUrlAttr: 'problemIconImageUrl', colorAttr: 'problemIconDashiconColor' })), |
| 150 |
el(TextControl, { label:__('Label text','blockenberg'), value:a.problemLabel, onChange:function(v){ setAttr({problemLabel:v}); } }), |
| 151 |
el(IP().IconPickerControl, IP().iconPickerProps(attr, setAttr, { charAttr: 'problemItemIcon', typeAttr: 'problemItemIconType', dashiconAttr: 'problemItemIconDashicon', imageUrlAttr: 'problemItemIconImageUrl', colorAttr: 'problemItemIconDashiconColor' })), |
| 152 |
el(ItemsEditor, { items:a.problemItems, onChange:function(v){ setAttr({problemItems:v}); }, label:__('Problem items','blockenberg') }) |
| 153 |
), |
| 154 |
|
| 155 |
/* Solution column */ |
| 156 |
el(PanelBody, { title:__('Solution column','blockenberg'), initialOpen:false }, |
| 157 |
el(IP().IconPickerControl, IP().iconPickerProps(attr, setAttr, { charAttr: 'solutionIcon', typeAttr: 'solutionIconType', dashiconAttr: 'solutionIconDashicon', imageUrlAttr: 'solutionIconImageUrl', colorAttr: 'solutionIconDashiconColor' })), |
| 158 |
el(TextControl, { label:__('Label text','blockenberg'), value:a.solutionLabel, onChange:function(v){ setAttr({solutionLabel:v}); } }), |
| 159 |
el(IP().IconPickerControl, IP().iconPickerProps(attr, setAttr, { charAttr: 'solutionItemIcon', typeAttr: 'solutionItemIconType', dashiconAttr: 'solutionItemIconDashicon', imageUrlAttr: 'solutionItemIconImageUrl', colorAttr: 'solutionItemIconDashiconColor' })), |
| 160 |
el(ItemsEditor, { items:a.solutionItems, onChange:function(v){ setAttr({solutionItems:v}); }, label:__('Solution items','blockenberg') }) |
| 161 |
), |
| 162 |
|
| 163 |
/* Spacing */ |
| 164 |
el(PanelBody, { title:__('Spacing','blockenberg'), initialOpen:false }, |
| 165 |
el(RangeControl, { label:__('Column gap (px)','blockenberg'), value:a.gap, min:0, max:60, onChange:function(v){ setAttr({gap:v}); } }), |
| 166 |
el(RangeControl, { label:__('Column padding V (px)','blockenberg'), value:a.paddingV, min:0, max:80, onChange:function(v){ setAttr({paddingV:v}); } }), |
| 167 |
el(RangeControl, { label:__('Column padding H (px)','blockenberg'), value:a.paddingH, min:0, max:80, onChange:function(v){ setAttr({paddingH:v}); } }), |
| 168 |
el(RangeControl, { label:__('Item spacing (px)','blockenberg'), value:a.itemSpacing, min:4, max:32, onChange:function(v){ setAttr({itemSpacing:v}); } }), |
| 169 |
el(RangeControl, { label:__('Border radius (px)','blockenberg'), value:a.borderRadius, min:0, max:40, onChange:function(v){ setAttr({borderRadius:v}); } }) |
| 170 |
), |
| 171 |
|
| 172 |
/* Typography */ |
| 173 |
el(PanelBody, { title:__('Typography','blockenberg'), initialOpen:false }, |
| 174 |
(function () { |
| 175 |
var TC = getTypoControl(); |
| 176 |
if (!TC) return el('p', null, 'Loading…'); |
| 177 |
return el(Fragment, null, |
| 178 |
el(TC, { label: 'Title', value: a.titleTypo, onChange: function (v) { setAttr({ titleTypo: v }); } }), |
| 179 |
el(TC, { label: 'Item', value: a.itemTypo, onChange: function (v) { setAttr({ itemTypo: v }); } }), |
| 180 |
el(TC, { label: 'Label', value: a.labelTypo, onChange: function (v) { setAttr({ labelTypo: v }); } }) |
| 181 |
); |
| 182 |
})(), |
| 183 |
el(RangeControl, { label:__('Icon size (px)','blockenberg'), value:a.iconSize, min:20, max:80, onChange:function(v){ setAttr({iconSize:v}); } }) |
| 184 |
), |
| 185 |
|
| 186 |
/* Colors */ |
| 187 |
el(PanelColorSettings, { title:__('Colors','blockenberg'), initialOpen:false, colorSettings:[ |
| 188 |
{label:__('Problem bg','blockenberg'), value:a.problemBg, onChange:function(v){ setAttr({problemBg:v||''}); }}, |
| 189 |
{label:__('Problem text','blockenberg'), value:a.problemColor, onChange:function(v){ setAttr({problemColor:v||''}); }}, |
| 190 |
{label:__('Problem icon bg','blockenberg'), value:a.problemIconBg, onChange:function(v){ setAttr({problemIconBg:v||''}); }}, |
| 191 |
{label:__('Solution bg','blockenberg'), value:a.solutionBg, onChange:function(v){ setAttr({solutionBg:v||''}); }}, |
| 192 |
{label:__('Solution text','blockenberg'), value:a.solutionColor, onChange:function(v){ setAttr({solutionColor:v||''}); }}, |
| 193 |
{label:__('Solution icon bg','blockenberg'), value:a.solutionIconBg, onChange:function(v){ setAttr({solutionIconBg:v||''}); }}, |
| 194 |
{label:__('Divider bg','blockenberg'), value:a.dividerBg, onChange:function(v){ setAttr({dividerBg:v||''}); }}, |
| 195 |
{label:__('Divider text','blockenberg'), value:a.dividerTextColor,onChange:function(v){ setAttr({dividerTextColor:v||''}); }}, |
| 196 |
] }) |
| 197 |
); |
| 198 |
|
| 199 |
var dividerCls = 'bkbg-psol-divider' + (a.dividerVertical ? ' bkbg-psol-divider--vertical' : '') + (a.dividerMobileRotate ? ' bkbg-psol-divider--mobile-rotate' : ''); |
| 200 |
var dividerEl = a.showDivider ? el('div', { className: dividerCls }, |
| 201 |
el('span', { className:'bkbg-psol-divider-label', style: a.dividerVertical ? { writingMode:'vertical-rl', textOrientation:'mixed' } : {} }, a.dividerLabel) |
| 202 |
) : null; |
| 203 |
|
| 204 |
return el(Fragment, null, |
| 205 |
inspector, |
| 206 |
el('div', blockProps, |
| 207 |
el(PanelCol, { a:a, side:'problem', isEdit:true, setAttr:setAttr }), |
| 208 |
dividerEl, |
| 209 |
el(PanelCol, { a:a, side:'solution', isEdit:true, setAttr:setAttr }) |
| 210 |
) |
| 211 |
); |
| 212 |
}, |
| 213 |
|
| 214 |
save: function (props) { |
| 215 |
var a = props.attributes; |
| 216 |
var blockProps = wp.blockEditor.useBlockProps.save({ className:'bkbg-psol-wrap bkbg-psol-style--' + a.style, style: Object.assign({}, buildWrapStyle(a), buildTypoVars(a)) }); |
| 217 |
|
| 218 |
function saveCol(side) { |
| 219 |
var icon = side === 'problem' ? a.problemIcon : a.solutionIcon; |
| 220 |
var iconType = side === 'problem' ? (a.problemIconType || 'custom-char') : (a.solutionIconType || 'custom-char'); |
| 221 |
var iconDash = side === 'problem' ? a.problemIconDashicon : a.solutionIconDashicon; |
| 222 |
var iconImg = side === 'problem' ? a.problemIconImageUrl : a.solutionIconImageUrl; |
| 223 |
var iconDashColor = side === 'problem' ? a.problemIconDashiconColor : a.solutionIconDashiconColor; |
| 224 |
var label = side === 'problem' ? a.problemLabel : a.solutionLabel; |
| 225 |
var title = side === 'problem' ? a.problemTitle : a.solutionTitle; |
| 226 |
var items = side === 'problem' ? a.problemItems : a.solutionItems; |
| 227 |
var itemIcon = side === 'problem' ? a.problemItemIcon : a.solutionItemIcon; |
| 228 |
var itemIconType = side === 'problem' ? (a.problemItemIconType || 'custom-char') : (a.solutionItemIconType || 'custom-char'); |
| 229 |
var itemIconDash = side === 'problem' ? a.problemItemIconDashicon : a.solutionItemIconDashicon; |
| 230 |
var itemIconImg = side === 'problem' ? a.problemItemIconImageUrl : a.solutionItemIconImageUrl; |
| 231 |
var itemIconDashColor = side === 'problem' ? a.problemItemIconDashiconColor : a.solutionItemIconDashiconColor; |
| 232 |
return el('div', { className:'bkbg-psol-col bkbg-psol-col--' + side }, |
| 233 |
el('div', { className:'bkbg-psol-col-header' }, |
| 234 |
el('span', { className:'bkbg-psol-col-icon' }, iconType !== 'custom-char' ? IP().buildSaveIcon(iconType, icon, iconDash, iconImg, iconDashColor) : icon), |
| 235 |
el('div', { className:'bkbg-psol-col-meta' }, |
| 236 |
a.showLabels ? el('span', { className:'bkbg-psol-label' }, label) : null, |
| 237 |
el(RichText.Content, { tagName:'h3', className:'bkbg-psol-title', value:title }) |
| 238 |
) |
| 239 |
), |
| 240 |
el('ul', { className:'bkbg-psol-list' }, |
| 241 |
items.map(function(item) { |
| 242 |
return el('li', { key:item.id, className:'bkbg-psol-item' }, |
| 243 |
el('span', { className:'bkbg-psol-item-icon' }, itemIconType !== 'custom-char' ? IP().buildSaveIcon(itemIconType, itemIcon, itemIconDash, itemIconImg, itemIconDashColor) : itemIcon), |
| 244 |
el('span', { className:'bkbg-psol-item-text' }, item.text) |
| 245 |
); |
| 246 |
}) |
| 247 |
) |
| 248 |
); |
| 249 |
} |
| 250 |
|
| 251 |
return el('div', blockProps, |
| 252 |
saveCol('problem'), |
| 253 |
a.showDivider ? el('div', { className:'bkbg-psol-divider' + (a.dividerVertical ? ' bkbg-psol-divider--vertical' : '') + (a.dividerMobileRotate ? ' bkbg-psol-divider--mobile-rotate' : '') }, el('span', { className:'bkbg-psol-divider-label', style: a.dividerVertical ? { writingMode:'vertical-rl', textOrientation:'mixed' } : {} }, a.dividerLabel)) : null, |
| 254 |
saveCol('solution') |
| 255 |
); |
| 256 |
}, |
| 257 |
|
| 258 |
deprecated: [{ |
| 259 |
attributes: { |
| 260 |
style: { type: "string", default: "split" }, |
| 261 |
problemIcon: { type: "string", default: "😩" }, |
| 262 |
problemLabel: { type: "string", default: "The Problem" }, |
| 263 |
problemTitle: { type: "string", default: "Struggling with the old way?" }, |
| 264 |
problemItems: { type: "array", default: [ |
| 265 |
{ id: "pi1", text: "Wasted hours on repetitive manual tasks" }, |
| 266 |
{ id: "pi2", text: "Disconnected tools that don't work together" }, |
| 267 |
{ id: "pi3", text: "Teams burned out from context-switching" }, |
| 268 |
{ id: "pi4", text: "Unreliable results and missed deadlines" }, |
| 269 |
{ id: "pi5", text: "No clear visibility into project status" } |
| 270 |
]}, |
| 271 |
problemBg: { type: "string", default: "#fff1f2" }, |
| 272 |
problemColor: { type: "string", default: "#9f1239" }, |
| 273 |
problemIconBg: { type: "string", default: "#fecdd3" }, |
| 274 |
problemItemIcon: { type: "string", default: "✕" }, |
| 275 |
solutionIcon: { type: "string", default: "🎯" }, |
| 276 |
solutionLabel: { type: "string", default: "The Solution" }, |
| 277 |
solutionTitle: { type: "string", default: "Meet a smarter way forward." }, |
| 278 |
solutionItems: { type: "array", default: [ |
| 279 |
{ id: "si1", text: "Automate workflows in minutes, not months" }, |
| 280 |
{ id: "si2", text: "All your tools, unified in one platform" }, |
| 281 |
{ id: "si3", text: "Teams focus on what actually moves the needle" }, |
| 282 |
{ id: "si4", text: "Consistent, predictable results every time" }, |
| 283 |
{ id: "si5", text: "Real-time dashboards with full transparency" } |
| 284 |
]}, |
| 285 |
solutionBg: { type: "string", default: "#f0fdf4" }, |
| 286 |
solutionColor: { type: "string", default: "#14532d" }, |
| 287 |
solutionIconBg: { type: "string", default: "#bbf7d0" }, |
| 288 |
solutionItemIcon: { type: "string", default: "✓" }, |
| 289 |
dividerLabel: { type: "string", default: "vs" }, |
| 290 |
dividerVertical: { type: "boolean", default: false }, |
| 291 |
dividerMobileRotate: { type: "boolean", default: true }, |
| 292 |
showDivider: { type: "boolean", default: true }, |
| 293 |
showLabels: { type: "boolean", default: true }, |
| 294 |
gap: { type: "number", default: 24 }, |
| 295 |
borderRadius: { type: "number", default: 20 }, |
| 296 |
itemFontSize: { type: "number", default: 15 }, |
| 297 |
titleFontSize: { type: "number", default: 22 }, |
| 298 |
labelFontSize: { type: "number", default: 11 }, |
| 299 |
iconSize: { type: "number", default: 40 }, |
| 300 |
paddingV: { type: "number", default: 40 }, |
| 301 |
paddingH: { type: "number", default: 40 }, |
| 302 |
itemSpacing: { type: "number", default: 12 }, |
| 303 |
dividerBg: { type: "string", default: "#ffffff" }, |
| 304 |
dividerTextColor: { type: "string", default: "#334155" }, |
| 305 |
titleFontWeight: { type: "string", default: "700" }, |
| 306 |
itemFontWeight: { type: "string", default: "400" }, |
| 307 |
labelFontWeight: { type: "string", default: "700" } |
| 308 |
}, |
| 309 |
save: function (props) { |
| 310 |
var a = props.attributes; |
| 311 |
function oldBuildWrapStyle(a) { |
| 312 |
return { |
| 313 |
'--bkbg-psol-gap': a.gap + 'px', |
| 314 |
'--bkbg-psol-radius': a.borderRadius + 'px', |
| 315 |
'--bkbg-psol-item-font': a.itemFontSize + 'px', |
| 316 |
'--bkbg-psol-title-font':a.titleFontSize + 'px', |
| 317 |
'--bkbg-psol-label-font':a.labelFontSize + 'px', |
| 318 |
'--bkbg-psol-icon-size': a.iconSize + 'px', |
| 319 |
'--bkbg-psol-pv': a.paddingV + 'px', |
| 320 |
'--bkbg-psol-ph': a.paddingH + 'px', |
| 321 |
'--bkbg-psol-spacing': a.itemSpacing + 'px', |
| 322 |
'--bkbg-psol-prob-bg': a.problemBg, |
| 323 |
'--bkbg-psol-prob-color':a.problemColor, |
| 324 |
'--bkbg-psol-prob-icbg': a.problemIconBg, |
| 325 |
'--bkbg-psol-sol-bg': a.solutionBg, |
| 326 |
'--bkbg-psol-sol-color': a.solutionColor, |
| 327 |
'--bkbg-psol-sol-icbg': a.solutionIconBg, |
| 328 |
'--bkbg-psol-div-bg': a.dividerBg, |
| 329 |
'--bkbg-psol-div-text': a.dividerTextColor, |
| 330 |
}; |
| 331 |
} |
| 332 |
var blockProps = wp.blockEditor.useBlockProps.save({ className:'bkbg-psol-wrap bkbg-psol-style--' + a.style, style: oldBuildWrapStyle(a) }); |
| 333 |
function saveCol(side) { |
| 334 |
var icon = side === 'problem' ? a.problemIcon : a.solutionIcon; |
| 335 |
var label = side === 'problem' ? a.problemLabel : a.solutionLabel; |
| 336 |
var title = side === 'problem' ? a.problemTitle : a.solutionTitle; |
| 337 |
var items = side === 'problem' ? a.problemItems : a.solutionItems; |
| 338 |
var itemIcon = side === 'problem' ? a.problemItemIcon : a.solutionItemIcon; |
| 339 |
return el('div', { className:'bkbg-psol-col bkbg-psol-col--' + side }, |
| 340 |
el('div', { className:'bkbg-psol-col-header' }, |
| 341 |
el('span', { className:'bkbg-psol-col-icon' }, icon), |
| 342 |
el('div', { className:'bkbg-psol-col-meta' }, |
| 343 |
a.showLabels ? el('span', { className:'bkbg-psol-label' }, label) : null, |
| 344 |
el(RichText.Content, { tagName:'h3', className:'bkbg-psol-title', value:title }) |
| 345 |
) |
| 346 |
), |
| 347 |
el('ul', { className:'bkbg-psol-list' }, |
| 348 |
items.map(function(item) { |
| 349 |
return el('li', { key:item.id, className:'bkbg-psol-item' }, |
| 350 |
el('span', { className:'bkbg-psol-item-icon' }, itemIcon), |
| 351 |
el('span', { className:'bkbg-psol-item-text' }, item.text) |
| 352 |
); |
| 353 |
}) |
| 354 |
) |
| 355 |
); |
| 356 |
} |
| 357 |
return el('div', blockProps, |
| 358 |
saveCol('problem'), |
| 359 |
a.showDivider ? el('div', { className:'bkbg-psol-divider' + (a.dividerVertical ? ' bkbg-psol-divider--vertical' : '') + (a.dividerMobileRotate ? ' bkbg-psol-divider--mobile-rotate' : '') }, el('span', { className:'bkbg-psol-divider-label', style: a.dividerVertical ? { writingMode:'vertical-rl', textOrientation:'mixed' } : {} }, a.dividerLabel)) : null, |
| 360 |
saveCol('solution') |
| 361 |
); |
| 362 |
}, |
| 363 |
migrate: function (attrs) { |
| 364 |
var n = Object.assign({}, attrs); |
| 365 |
n.titleTypo = { sizeDesktop: attrs.titleFontSize || 22, weight: attrs.titleFontWeight || '700' }; |
| 366 |
n.itemTypo = { sizeDesktop: attrs.itemFontSize || 15, weight: attrs.itemFontWeight || '400' }; |
| 367 |
n.labelTypo = { sizeDesktop: attrs.labelFontSize || 11, weight: attrs.labelFontWeight || '700' }; |
| 368 |
delete n.titleFontSize; delete n.titleFontWeight; |
| 369 |
delete n.itemFontSize; delete n.itemFontWeight; |
| 370 |
delete n.labelFontSize; delete n.labelFontWeight; |
| 371 |
return n; |
| 372 |
} |
| 373 |
}] |
| 374 |
}); |
| 375 |
}() ); |
| 376 |
|