| 1 |
( function () { |
| 2 |
var el = wp.element.createElement; |
| 3 |
var __ = wp.i18n.__; |
| 4 |
var registerBlockType = wp.blocks.registerBlockType; |
| 5 |
var InspectorControls = wp.blockEditor.InspectorControls; |
| 6 |
var useBlockProps = wp.blockEditor.useBlockProps; |
| 7 |
var RichText = wp.blockEditor.RichText; |
| 8 |
var PanelColorSettings = wp.blockEditor.PanelColorSettings; |
| 9 |
var PanelBody = wp.components.PanelBody; |
| 10 |
var ToggleControl = wp.components.ToggleControl; |
| 11 |
var RangeControl = wp.components.RangeControl; |
| 12 |
var SelectControl = wp.components.SelectControl; |
| 13 |
var TextControl = wp.components.TextControl; |
| 14 |
var Button = wp.components.Button; |
| 15 |
|
| 16 |
var _tc, _tvf; |
| 17 |
Object.defineProperty(window, '_tc', { get: function () { return _tc || (_tc = window.bkbgTypographyControl); } }); |
| 18 |
Object.defineProperty(window, '_tvf', { get: function () { return _tvf || (_tvf = window.bkbgTypoCssVars); } }); |
| 19 |
function getTypoControl(label, key, attrs, setA) { return _tc(label, key, attrs, setA); } |
| 20 |
function getTypoCssVars(attrs) { |
| 21 |
var v = {}; |
| 22 |
_tvf(v, 'headingTypo', attrs, '--bkvms-hd-'); |
| 23 |
_tvf(v, 'eyebrowTypo', attrs, '--bkvms-ey-'); |
| 24 |
_tvf(v, 'statementTypo', attrs, '--bkvms-sm-'); |
| 25 |
_tvf(v, 'valueTitleTypo', attrs, '--bkvms-vt-'); |
| 26 |
_tvf(v, 'valueDescTypo', attrs, '--bkvms-vd-'); |
| 27 |
return v; |
| 28 |
} |
| 29 |
var IP = function () { return window.bkbgIconPicker; }; |
| 30 |
|
| 31 |
registerBlockType('blockenberg/vision-mission', { |
| 32 |
edit: function (props) { |
| 33 |
var attributes = props.attributes; |
| 34 |
var setAttributes = props.setAttributes; |
| 35 |
var a = attributes; |
| 36 |
|
| 37 |
function updateValue(idx, key, val) { |
| 38 |
setAttributes({ values: a.values.map(function (v, i) { return i === idx ? Object.assign({}, v, { [key]: val }) : v; }) }); |
| 39 |
} |
| 40 |
function addValue() { |
| 41 |
setAttributes({ values: a.values.concat([{ icon: '⭐', title: 'New Value', description: 'Describe this value…' }]) }); |
| 42 |
} |
| 43 |
function removeValue(idx) { |
| 44 |
setAttributes({ values: a.values.filter(function (_, i) { return i !== idx; }) }); |
| 45 |
} |
| 46 |
|
| 47 |
var wrapStyle = getTypoCssVars(a); |
| 48 |
wrapStyle.backgroundColor = a.bgColor; |
| 49 |
wrapStyle.paddingTop = a.paddingTop + 'px'; |
| 50 |
wrapStyle.paddingBottom = a.paddingBottom + 'px'; |
| 51 |
var innerStyle = { maxWidth: a.maxWidth + 'px', margin: '0 auto', padding: '0 24px' }; |
| 52 |
|
| 53 |
var isSplit = a.layout === 'split'; |
| 54 |
|
| 55 |
function missionBlock() { |
| 56 |
return a.showMission && el('div', { style: { background: a.missionBg, borderLeft: '4px solid ' + a.missionBorder, borderRadius: '0 12px 12px 0', padding: '28px 32px' } }, |
| 57 |
el('div', { style: { display: 'flex', alignItems: 'center', gap: 10, marginBottom: 12 } }, |
| 58 |
el('span', { className: 'bkbg-vms-statement-icon', style: { fontSize: 24 } }, (a.missionIconType || 'custom-char') !== 'custom-char' ? IP().buildEditorIcon(a.missionIconType, a.missionIcon, a.missionIconDashicon, a.missionIconImageUrl, a.missionIconDashiconColor) : a.missionIcon), |
| 59 |
el('span', { className: 'bkbg-vms-statement-label', style: { color: a.missionLabelColor } }, a.missionLabel) |
| 60 |
), |
| 61 |
el(RichText, { tagName: 'p', className: 'bkbg-vms-statement-text', value: a.missionText, onChange: function (v) { setAttributes({ missionText: v }); }, placeholder: __('Mission statement…', 'blockenberg'), style: { color: a.missionTextColor, margin: 0 } }) |
| 62 |
); |
| 63 |
} |
| 64 |
|
| 65 |
function visionBlock() { |
| 66 |
return a.showVision && el('div', { style: { background: a.visionBg, borderLeft: '4px solid ' + a.visionBorder, borderRadius: '0 12px 12px 0', padding: '28px 32px' } }, |
| 67 |
el('div', { style: { display: 'flex', alignItems: 'center', gap: 10, marginBottom: 12 } }, |
| 68 |
el('span', { className: 'bkbg-vms-statement-icon', style: { fontSize: 24 } }, (a.visionIconType || 'custom-char') !== 'custom-char' ? IP().buildEditorIcon(a.visionIconType, a.visionIcon, a.visionIconDashicon, a.visionIconImageUrl, a.visionIconDashiconColor) : a.visionIcon), |
| 69 |
el('span', { className: 'bkbg-vms-statement-label', style: { color: a.visionLabelColor } }, a.visionLabel) |
| 70 |
), |
| 71 |
el(RichText, { tagName: 'p', className: 'bkbg-vms-statement-text', value: a.visionText, onChange: function (v) { setAttributes({ visionText: v }); }, placeholder: __('Vision statement…', 'blockenberg'), style: { color: a.visionTextColor, margin: 0 } }) |
| 72 |
); |
| 73 |
} |
| 74 |
|
| 75 |
return el('div', useBlockProps({ className: 'bkbg-vms-wrap', style: wrapStyle }), |
| 76 |
el(InspectorControls, null, |
| 77 |
el(PanelBody, { title: __('Content', 'blockenberg'), initialOpen: true }, |
| 78 |
el(ToggleControl, { label: __('Show Eyebrow', 'blockenberg'), checked: a.showEyebrow, onChange: function (v) { setAttributes({ showEyebrow: v }); }, __nextHasNoMarginBottom: true }), |
| 79 |
a.showEyebrow && el(TextControl, { label: __('Eyebrow Text', 'blockenberg'), value: a.eyebrow, onChange: function (v) { setAttributes({ eyebrow: v }); }, __nextHasNoMarginBottom: true }), |
| 80 |
el(ToggleControl, { label: __('Show Heading', 'blockenberg'), checked: a.showHeading, onChange: function (v) { setAttributes({ showHeading: v }); }, __nextHasNoMarginBottom: true }), |
| 81 |
el(ToggleControl, { label: __('Show Mission', 'blockenberg'), checked: a.showMission, onChange: function (v) { setAttributes({ showMission: v }); }, __nextHasNoMarginBottom: true }), |
| 82 |
a.showMission && el(TextControl, { label: __('Mission Label', 'blockenberg'), value: a.missionLabel, onChange: function (v) { setAttributes({ missionLabel: v }); }, __nextHasNoMarginBottom: true }), |
| 83 |
a.showMission && el(IP().IconPickerControl, IP().iconPickerProps(a, setAttributes, { charAttr: 'missionIcon', typeAttr: 'missionIconType', dashiconAttr: 'missionIconDashicon', imageUrlAttr: 'missionIconImageUrl', colorAttr: 'missionIconDashiconColor' })), |
| 84 |
el(ToggleControl, { label: __('Show Vision', 'blockenberg'), checked: a.showVision, onChange: function (v) { setAttributes({ showVision: v }); }, __nextHasNoMarginBottom: true }), |
| 85 |
a.showVision && el(TextControl, { label: __('Vision Label', 'blockenberg'), value: a.visionLabel, onChange: function (v) { setAttributes({ visionLabel: v }); }, __nextHasNoMarginBottom: true }), |
| 86 |
a.showVision && el(IP().IconPickerControl, IP().iconPickerProps(a, setAttributes, { charAttr: 'visionIcon', typeAttr: 'visionIconType', dashiconAttr: 'visionIconDashicon', imageUrlAttr: 'visionIconImageUrl', colorAttr: 'visionIconDashiconColor' })), |
| 87 |
el(ToggleControl, { label: __('Show Values', 'blockenberg'), checked: a.showValues, onChange: function (v) { setAttributes({ showValues: v }); }, __nextHasNoMarginBottom: true }), |
| 88 |
a.showValues && el(TextControl, { label: __('Values Section Label', 'blockenberg'), value: a.valuesLabel, onChange: function (v) { setAttributes({ valuesLabel: v }); }, __nextHasNoMarginBottom: true }) |
| 89 |
), |
| 90 |
el(PanelBody, { title: __('Layout', 'blockenberg'), initialOpen: false }, |
| 91 |
el(SelectControl, { label: __('Layout', 'blockenberg'), value: a.layout, options: [{ label: 'Mission/Vision Top', value: 'mission-top' }, { label: 'Split (mission|vision + values)', value: 'split' }, { label: 'Cards (all)', value: 'cards' }], onChange: function (v) { setAttributes({ layout: v }); }, __nextHasNoMarginBottom: true }), |
| 92 |
el(RangeControl, { label: __('Values Columns', 'blockenberg'), value: a.valuesColumns, min: 1, max: 4, onChange: function (v) { setAttributes({ valuesColumns: v }); }, __nextHasNoMarginBottom: true }), |
| 93 |
el(RangeControl, { label: __('Max Width (px)', 'blockenberg'), value: a.maxWidth, min: 600, max: 1400, onChange: function (v) { setAttributes({ maxWidth: v }); }, __nextHasNoMarginBottom: true }), |
| 94 |
el(RangeControl, { label: __('Padding Top (px)', 'blockenberg'), value: a.paddingTop, min: 0, max: 200, onChange: function (v) { setAttributes({ paddingTop: v }); }, __nextHasNoMarginBottom: true }), |
| 95 |
el(RangeControl, { label: __('Padding Bottom (px)', 'blockenberg'), value: a.paddingBottom, min: 0, max: 200, onChange: function (v) { setAttributes({ paddingBottom: v }); }, __nextHasNoMarginBottom: true }) |
| 96 |
), |
| 97 |
|
| 98 |
el( PanelBody, { title: __( 'Typography', 'blockenberg' ), initialOpen: false }, |
| 99 |
getTypoControl(__('Heading', 'blockenberg'), 'headingTypo', a, setAttributes), |
| 100 |
getTypoControl(__('Eyebrow', 'blockenberg'), 'eyebrowTypo', a, setAttributes), |
| 101 |
getTypoControl(__('Statement Text', 'blockenberg'), 'statementTypo', a, setAttributes), |
| 102 |
getTypoControl(__('Value Title', 'blockenberg'), 'valueTitleTypo', a, setAttributes), |
| 103 |
getTypoControl(__('Value Description', 'blockenberg'), 'valueDescTypo', a, setAttributes) |
| 104 |
), |
| 105 |
el(PanelColorSettings, { |
| 106 |
title: __('Colors', 'blockenberg'), |
| 107 |
initialOpen: false, |
| 108 |
colorSettings: [ |
| 109 |
{ label: __('Background', 'blockenberg'), value: a.bgColor, onChange: function (v) { setAttributes({ bgColor: v || '#ffffff' }); } }, |
| 110 |
{ label: __('Heading', 'blockenberg'), value: a.headingColor, onChange: function (v) { setAttributes({ headingColor: v || '#111827' }); } }, |
| 111 |
{ label: __('Mission BG', 'blockenberg'), value: a.missionBg, onChange: function (v) { setAttributes({ missionBg: v || '#f8f5ff' }); } }, |
| 112 |
{ label: __('Mission Accent', 'blockenberg'), value: a.missionBorder, onChange: function (v) { setAttributes({ missionBorder: v || '#7c3aed' }); } }, |
| 113 |
{ label: __('Vision BG', 'blockenberg'), value: a.visionBg, onChange: function (v) { setAttributes({ visionBg: v || '#eff6ff' }); } }, |
| 114 |
{ label: __('Vision Accent', 'blockenberg'), value: a.visionBorder, onChange: function (v) { setAttributes({ visionBorder: v || '#3b82f6' }); } }, |
| 115 |
{ label: __('Value Card BG', 'blockenberg'), value: a.valueCardBg, onChange: function (v) { setAttributes({ valueCardBg: v || '#f9fafb' }); } }, |
| 116 |
{ label: __('Value Title', 'blockenberg'), value: a.valueTitleColor, onChange: function (v) { setAttributes({ valueTitleColor: v || '#111827' }); } } |
| 117 |
] |
| 118 |
}) |
| 119 |
), |
| 120 |
|
| 121 |
el('div', { style: innerStyle }, |
| 122 |
// Header |
| 123 |
el('div', { style: { textAlign: 'center', marginBottom: 48 } }, |
| 124 |
a.showEyebrow && el('span', { className: 'bkbg-vms-eyebrow', style: { display: 'inline-block', background: a.eyebrowBg, color: a.eyebrowColor, padding: '5px 14px', borderRadius: 999, marginBottom: 16 } }, a.eyebrow), |
| 125 |
a.showHeading && el(RichText, { tagName: 'h2', className: 'bkbg-vms-heading', value: a.heading, onChange: function (v) { setAttributes({ heading: v }); }, placeholder: __('Heading…', 'blockenberg'), style: { color: a.headingColor, margin: 0 } }) |
| 126 |
), |
| 127 |
|
| 128 |
// Mission / Vision |
| 129 |
isSplit |
| 130 |
? el('div', { style: { display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 24, marginBottom: 48 } }, missionBlock(), visionBlock()) |
| 131 |
: el('div', { style: { display: 'flex', flexDirection: 'column', gap: 24, marginBottom: 48 } }, missionBlock(), visionBlock()), |
| 132 |
|
| 133 |
// Values |
| 134 |
a.showValues && el('div', null, |
| 135 |
el('h3', { className: 'bkbg-vms-values-heading', style: { color: a.valuesLabelColor, margin: '0 0 28px' } }, a.valuesLabel), |
| 136 |
el('div', { style: { display: 'grid', gridTemplateColumns: 'repeat(' + a.valuesColumns + ', 1fr)', gap: 20 } }, |
| 137 |
a.values.map(function (v, idx) { |
| 138 |
var _iType = v.iconType || 'custom-char'; |
| 139 |
var _iconContent = (_iType !== 'custom-char' && IP()) ? IP().buildEditorIcon(_iType, v.icon, v.iconDashicon, v.iconImageUrl, v.iconDashiconColor) : v.icon; |
| 140 |
return el('div', { key: idx, style: { background: a.valueCardBg, border: '1px solid ' + a.valueCardBorder, borderRadius: 12, padding: '24px 20px', position: 'relative' } }, |
| 141 |
el(Button, { isDestructive: true, size: 'small', onClick: function () { removeValue(idx); }, style: { position: 'absolute', top: 10, right: 10, fontSize: 10 } }, '✕'), |
| 142 |
el(IP().IconPickerControl, IP().iconPickerProps(v, function(patch) { |
| 143 |
setAttributes({ values: a.values.map(function(val, i) { return i === idx ? Object.assign({}, val, patch) : val; }) }); |
| 144 |
}, { label: __('Icon', 'blockenberg'), charAttr: 'icon', typeAttr: 'iconType', dashiconAttr: 'iconDashicon', imageUrlAttr: 'iconImageUrl' })), |
| 145 |
el('span', { style: { fontSize: 28, display: 'block', marginBottom: 12 } }, _iconContent), |
| 146 |
el(RichText, { tagName: 'h4', className: 'bkbg-vms-value-title', value: v.title, onChange: function (val) { updateValue(idx, 'title', val); }, placeholder: __('Value title…', 'blockenberg'), style: { color: a.valueTitleColor, margin: '0 0 8px' } }), |
| 147 |
el(RichText, { tagName: 'p', className: 'bkbg-vms-value-desc', value: v.description, onChange: function (val) { updateValue(idx, 'description', val); }, placeholder: __('Value description…', 'blockenberg'), style: { color: a.valueDescColor, margin: 0 } }) |
| 148 |
); |
| 149 |
}), |
| 150 |
el('div', { onClick: addValue, style: { border: '2px dashed #d1d5db', borderRadius: 12, padding: 24, textAlign: 'center', cursor: 'pointer', display: 'flex', alignItems: 'center', justifyContent: 'center' } }, |
| 151 |
el('span', { style: { fontSize: 13, color: '#9ca3af' } }, '+ Add Value') |
| 152 |
) |
| 153 |
) |
| 154 |
) |
| 155 |
) |
| 156 |
); |
| 157 |
}, |
| 158 |
save: function (props) { |
| 159 |
var useBlockProps = wp.blockEditor.useBlockProps; |
| 160 |
var a = props.attributes; |
| 161 |
var s = getTypoCssVars(a); |
| 162 |
s.backgroundColor = a.bgColor; |
| 163 |
s.paddingTop = a.paddingTop + 'px'; |
| 164 |
s.paddingBottom = a.paddingBottom + 'px'; |
| 165 |
return el('div', useBlockProps.save({ style: s }), |
| 166 |
el('div', { className: 'bkbg-vms-app', 'data-opts': JSON.stringify(a) }) |
| 167 |
); |
| 168 |
} |
| 169 |
}); |
| 170 |
}() ); |
| 171 |
|