PluginProbe
Blockenberg — 600+ Advanced Gutenberg Blocks & AI Agent for WordPress Block Editor / 2.0.14
Blockenberg — 600+ Advanced Gutenberg Blocks & AI Agent for WordPress Block Editor v2.0.14
2.0.14 2.0.13 2.0.12 2.0.11 2.0.10 2.0.9 trunk 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8
blockenberg / blocks / vision-mission / index.js

index.js in Blockenberg — 600+ Advanced Gutenberg Blocks & AI Agent for WordPress Block Editor 2.0.14, at blocks/vision-mission/index.js

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