PluginProbe
Blockenberg — 600+ Advanced Gutenberg Blocks & AI Agent for WordPress Block Editor / 2.0.7
Blockenberg — 600+ Advanced Gutenberg Blocks & AI Agent for WordPress Block Editor v2.0.7
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 / expert-roundup / index.js

index.js in Blockenberg — 600+ Advanced Gutenberg Blocks & AI Agent for WordPress Block Editor 2.0.7, at blocks/expert-roundup/index.js

200 lines 16.0 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 MediaUpload = wp.blockEditor.MediaUpload;
7 var MediaUploadCheck = wp.blockEditor.MediaUploadCheck;
8 var useBlockProps = wp.blockEditor.useBlockProps;
9 var RichText = wp.blockEditor.RichText;
10 var PanelColorSettings = wp.blockEditor.PanelColorSettings;
11 var PanelBody = wp.components.PanelBody;
12 var ToggleControl = wp.components.ToggleControl;
13 var RangeControl = wp.components.RangeControl;
14 var SelectControl = wp.components.SelectControl;
15 var TextControl = wp.components.TextControl;
16 var TextareaControl = wp.components.TextareaControl;
17 var Button = wp.components.Button;
18
19 var _erpTC, _erpTV;
20 function _tc() { return _erpTC || (_erpTC = window.bkbgTypographyControl); }
21 function _tv(t, p) { return (_erpTV || (_erpTV = window.bkbgTypoCssVars)) ? _erpTV(t, p) : {}; }
22
23 registerBlockType('blockenberg/expert-roundup', {
24 edit: function (props) {
25 var attr = props.attributes;
26 var set = props.setAttributes;
27
28 var blockProps = useBlockProps({ className: 'bkbg-erp-wrap', style: Object.assign({ background: attr.bgColor },
29 _tv(attr.typoEyebrow || {}, '--bkbg-erp-ey-'),
30 _tv(attr.typoHeading || {}, '--bkbg-erp-hd-'),
31 _tv(attr.typoSubtext || {}, '--bkbg-erp-st-'),
32 _tv(attr.typoQuote || {}, '--bkbg-erp-qt-')
33 ) });
34
35 function updateExpert(idx, key, value) {
36 var arr = attr.experts.map(function (e, i) {
37 if (i !== idx) return e;
38 var copy = Object.assign({}, e);
39 copy[key] = value;
40 return copy;
41 });
42 set({ experts: arr });
43 }
44
45 function ExpertCard(expert, idx) {
46 var initials = (expert.name || 'E').split(' ').map(function (w) { return w[0]; }).slice(0, 2).join('').toUpperCase();
47 return el('div', {
48 key: idx, style: {
49 background: attr.cardBg, border: '1px solid ' + attr.cardBorder,
50 borderRadius: attr.borderRadius + 'px', padding: '24px', position: 'relative'
51 }
52 },
53 attr.showNumber && el('div', { style: { position: 'absolute', top: '-12px', left: '20px', background: attr.numberBg, color: attr.numberColor, borderRadius: '50%', width: '26px', height: '26px', display: 'flex', alignItems: 'center', justifyContent: 'center', fontSize: '12px', fontWeight: 700 } }, String(idx + 1)),
54 el('div', { style: { display: 'flex', alignItems: 'center', gap: '12px', marginBottom: '16px' } },
55 expert.avatarUrl
56 ? el('img', { src: expert.avatarUrl, alt: expert.name, style: { width: '48px', height: '48px', borderRadius: '50%', objectFit: 'cover', flexShrink: 0 } })
57 : el('div', { style: { width: '48px', height: '48px', borderRadius: '50%', background: attr.avatarBg, display: 'flex', alignItems: 'center', justifyContent: 'center', fontWeight: 700, fontSize: '16px', color: attr.avatarColor, flexShrink: 0 } }, initials),
58 el('div', {},
59 el('div', { style: { fontWeight: 700, fontSize: '15px', color: attr.nameColor } }, expert.name),
60 el('div', { style: { fontSize: '12px', color: attr.titleColor } }, expert.title),
61 attr.showCompany && el('div', { style: { fontSize: '12px', color: attr.companyColor, fontWeight: 600 } }, expert.company)
62 )
63 ),
64 attr.quoteStyle === 'block' && el('div', { className: 'bkbg-erp-quote-block', style: { borderLeftColor: attr.accentColor, color: attr.quoteColor } }, expert.contribution),
65 attr.quoteStyle === 'plain' && el('p', { className: 'bkbg-erp-quote-plain', style: { margin: 0, color: attr.quoteColor } }, expert.contribution),
66 attr.quoteStyle === 'bubble' && el('div', { className: 'bkbg-erp-quote-bubble', style: { background: attr.cardBorder, color: attr.quoteColor } }, '\u201C', expert.contribution, '\u201D')
67 );
68 }
69
70 function ExpertEditorPanel(expert, idx) {
71 return el('div', { key: idx, style: { border: '1px solid #e2e8f0', borderRadius: '6px', padding: '12px', marginBottom: '10px', background: '#f8fafc' } },
72 el('strong', { style: { fontSize: '12px', color: '#374151' } }, String(idx + 1) + '. ' + (expert.name || 'Expert')),
73 el('div', { style: { marginTop: '8px' } },
74 el(TextControl, { label: __('Name', 'blockenberg'), value: expert.name, __nextHasNoMarginBottom: true, onChange: function (v) { updateExpert(idx, 'name', v); } })
75 ),
76 el('div', { style: { marginTop: '8px' } },
77 el(TextControl, { label: __('Title', 'blockenberg'), value: expert.title, __nextHasNoMarginBottom: true, onChange: function (v) { updateExpert(idx, 'title', v); } })
78 ),
79 el('div', { style: { marginTop: '8px' } },
80 el(TextControl, { label: __('Company', 'blockenberg'), value: expert.company, __nextHasNoMarginBottom: true, onChange: function (v) { updateExpert(idx, 'company', v); } })
81 ),
82 el('div', { style: { marginTop: '8px' } },
83 el(TextareaControl, { label: __('Contribution / Insight', 'blockenberg'), value: expert.contribution, rows: 4, __nextHasNoMarginBottom: true, onChange: function (v) { updateExpert(idx, 'contribution', v); } })
84 ),
85 el('div', { style: { marginTop: '8px' } },
86 el(MediaUploadCheck, {},
87 el(MediaUpload, {
88 onSelect: function (m) { updateExpert(idx, 'avatarUrl', m.url); },
89 allowedTypes: ['image'], value: expert.avatarId || 0,
90 render: function (rp) {
91 return el('div', { style: { display: 'flex', alignItems: 'center', gap: '8px' } },
92 expert.avatarUrl && el('img', { src: expert.avatarUrl, style: { width: '36px', height: '36px', borderRadius: '50%', objectFit: 'cover' } }),
93 el(Button, { onClick: rp.open, variant: 'secondary', __nextHasNoMarginBottom: true }, expert.avatarUrl ? __('Change Photo', 'blockenberg') : __('Add Photo', 'blockenberg')),
94 expert.avatarUrl && el(Button, { onClick: function () { updateExpert(idx, 'avatarUrl', ''); }, variant: 'link', isDestructive: true }, __('Remove', 'blockenberg'))
95 );
96 }
97 })
98 )
99 ),
100 el(Button, { variant: 'link', isDestructive: true, style: { marginTop: '8px' }, onClick: function () { set({ experts: attr.experts.filter(function (_, i) { return i !== idx; }) }); } }, __('Remove Expert', 'blockenberg'))
101 );
102 }
103
104 var controls = el(InspectorControls, {},
105 el(PanelBody, { title: __('Experts', 'blockenberg'), initialOpen: true },
106 (attr.experts || []).map(function (e, i) { return ExpertEditorPanel(e, i); }),
107 el(Button, {
108 variant: 'secondary', __nextHasNoMarginBottom: true, style: { marginTop: '8px' },
109 onClick: function () { set({ experts: (attr.experts || []).concat([{ name: 'Expert Name', title: 'Job Title', company: 'Company', avatarUrl: '', contribution: 'Their expert insight here...' }]) }); }
110 }, __('+ Add Expert', 'blockenberg'))
111 ),
112 el(PanelBody, { title: __('Layout & Display', 'blockenberg'), initialOpen: false },
113 el(SelectControl, {
114 label: __('Layout', 'blockenberg'), value: attr.layout, __nextHasNoMarginBottom: true,
115 options: [{ label: 'Cards Grid', value: 'cards' }, { label: 'Vertical List', value: 'list' }],
116 onChange: function (v) { set({ layout: v }); }
117 }),
118 el('div', { style: { marginTop: '12px' } },
119 el(RangeControl, { label: __('Columns (grid layout)', 'blockenberg'), value: attr.columns, min: 1, max: 3, __nextHasNoMarginBottom: true, onChange: function (v) { set({ columns: v }); } })
120 ),
121 el('div', { style: { marginTop: '12px' } },
122 el(SelectControl, {
123 label: __('Quote Style', 'blockenberg'), value: attr.quoteStyle, __nextHasNoMarginBottom: true,
124 options: [{ label: 'Block (left border)', value: 'block' }, { label: 'Plain text', value: 'plain' }, { label: 'Speech bubble', value: 'bubble' }],
125 onChange: function (v) { set({ quoteStyle: v }); }
126 })
127 ),
128 el('div', { style: { marginTop: '12px' } },
129 el(ToggleControl, { label: __('Show Number Badge', 'blockenberg'), checked: attr.showNumber, __nextHasNoMarginBottom: true, onChange: function (v) { set({ showNumber: v }); } })
130 ),
131 el('div', { style: { marginTop: '4px' } },
132 el(ToggleControl, { label: __('Show Company', 'blockenberg'), checked: attr.showCompany, __nextHasNoMarginBottom: true, onChange: function (v) { set({ showCompany: v }); } })
133 ),
134 el('div', { style: { marginTop: '12px' } },
135 el(RangeControl, { label: __('Border Radius', 'blockenberg'), value: attr.borderRadius, min: 0, max: 24, __nextHasNoMarginBottom: true, onChange: function (v) { set({ borderRadius: v }); } })
136 )
137 ),
138 el(PanelBody, { title: __('Spacing', 'blockenberg'), initialOpen: false },
139 el(RangeControl, { label: __('Padding Top', 'blockenberg'), value: attr.paddingTop, min: 0, max: 200, __nextHasNoMarginBottom: true, onChange: function (v) { set({ paddingTop: v }); } }),
140 el('div', { style: { marginTop: '12px' } },
141 el(RangeControl, { label: __('Padding Bottom', 'blockenberg'), value: attr.paddingBottom, min: 0, max: 200, __nextHasNoMarginBottom: true, onChange: function (v) { set({ paddingBottom: v }); } })
142 ),
143 el('div', { style: { marginTop: '12px' } },
144 el(RangeControl, { label: __('Max Width (px)', 'blockenberg'), value: attr.maxWidth, min: 600, max: 1600, step: 20, __nextHasNoMarginBottom: true, onChange: function (v) { set({ maxWidth: v }); } })
145 )
146 ),
147 el(PanelBody, { title: __('Typography', 'blockenberg'), initialOpen: false },
148 _tc() && el(_tc(), { label: 'Eyebrow', typo: attr.typoEyebrow || {}, onChange: function (v) { set({ typoEyebrow: v }); } }),
149 _tc() && el(_tc(), { label: 'Heading', typo: attr.typoHeading || {}, onChange: function (v) { set({ typoHeading: v }); } }),
150 _tc() && el(_tc(), { label: 'Subtext', typo: attr.typoSubtext || {}, onChange: function (v) { set({ typoSubtext: v }); } }),
151 _tc() && el(_tc(), { label: 'Quote', typo: attr.typoQuote || {}, onChange: function (v) { set({ typoQuote: v }); } })
152 ),
153 el(PanelColorSettings, {
154 title: __('Colors', 'blockenberg'), initialOpen: false,
155 colorSettings: [
156 { label: __('Background', 'blockenberg'), value: attr.bgColor, onChange: function (v) { set({ bgColor: v || '#f8fafc' }); } },
157 { label: __('Accent', 'blockenberg'), value: attr.accentColor, onChange: function (v) { set({ accentColor: v || '#6366f1' }); } },
158 { label: __('Eyebrow', 'blockenberg'), value: attr.eyebrowColor, onChange: function (v) { set({ eyebrowColor: v || '#6366f1' }); } },
159 { label: __('Heading', 'blockenberg'), value: attr.headingColor, onChange: function (v) { set({ headingColor: v || '#111827' }); } },
160 { label: __('Subtext', 'blockenberg'), value: attr.subColor, onChange: function (v) { set({ subColor: v || '#6b7280' }); } },
161 { label: __('Card Background', 'blockenberg'), value: attr.cardBg, onChange: function (v) { set({ cardBg: v || '#ffffff' }); } },
162 { label: __('Card Border', 'blockenberg'), value: attr.cardBorder, onChange: function (v) { set({ cardBorder: v || '#e2e8f0' }); } },
163 { label: __('Expert Name', 'blockenberg'), value: attr.nameColor, onChange: function (v) { set({ nameColor: v || '#111827' }); } },
164 { label: __('Expert Title', 'blockenberg'), value: attr.titleColor, onChange: function (v) { set({ titleColor: v || '#6b7280' }); } },
165 { label: __('Company', 'blockenberg'), value: attr.companyColor, onChange: function (v) { set({ companyColor: v || '#6366f1' }); } },
166 { label: __('Quote / Contribution', 'blockenberg'), value: attr.quoteColor, onChange: function (v) { set({ quoteColor: v || '#374151' }); } },
167 { label: __('Number Badge BG', 'blockenberg'), value: attr.numberBg, onChange: function (v) { set({ numberBg: v || '#6366f1' }); } },
168 { label: __('Number Badge Text', 'blockenberg'), value: attr.numberColor, onChange: function (v) { set({ numberColor: v || '#ffffff' }); } },
169 { label: __('Avatar Background', 'blockenberg'), value: attr.avatarBg, onChange: function (v) { set({ avatarBg: v || '#ede9fe' }); } },
170 { label: __('Avatar Initials', 'blockenberg'), value: attr.avatarColor, onChange: function (v) { set({ avatarColor: v || '#6366f1' }); } }
171 ]
172 })
173 );
174
175 return el('div', blockProps,
176 controls,
177 el('div', { style: { maxWidth: attr.maxWidth + 'px', margin: '0 auto', padding: attr.paddingTop + 'px 24px ' + attr.paddingBottom + 'px' } },
178 el('div', { style: { textAlign: 'center', marginBottom: '48px' } },
179 el('p', { className: 'bkbg-erp-eyebrow', style: { color: attr.eyebrowColor, margin: '0 0 12px' } }, attr.eyebrow),
180 el(RichText, { tagName: 'h2', className: 'bkbg-erp-heading', value: attr.heading, style: { color: attr.headingColor, margin: '0 0 12px' }, placeholder: __('Heading\u2026', 'blockenberg'), onChange: function (v) { set({ heading: v }); } }),
181 el(RichText, { tagName: 'p', className: 'bkbg-erp-sub', value: attr.subtext, style: { color: attr.subColor, margin: '0 auto', maxWidth: '680px' }, placeholder: __('Subtext\u2026', 'blockenberg'), onChange: function (v) { set({ subtext: v }); } })
182 ),
183 el('div', {
184 style: attr.layout === 'cards'
185 ? { display: 'grid', gridTemplateColumns: 'repeat(' + attr.columns + ',1fr)', gap: '24px' }
186 : { display: 'flex', flexDirection: 'column', gap: '24px' }
187 }, (attr.experts || []).map(function (e, i) { return ExpertCard(e, i); }))
188 )
189 );
190 },
191 save: function (props) {
192 var attr = props.attributes;
193 var useBlockProps = wp.blockEditor.useBlockProps;
194 return el('div', useBlockProps.save(),
195 el('div', { className: 'bkbg-erp-app', 'data-opts': JSON.stringify(attr) })
196 );
197 }
198 });
199 }() );
200