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 / community-section / index.js

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

197 lines 15.8 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 Button = wp.components.Button;
17
18 function getTypographyControl() { return (window.bkbgTypographyControl || function () { return null; }); }
19 function getTypoCssVars() { return (window.bkbgTypoCssVars || function () { return {}; }); }
20 function _tv(typo, prefix) { var fn = getTypoCssVars(); return fn(typo || {}, prefix); }
21
22 registerBlockType('blockenberg/community-section', {
23 edit: function (props) {
24 var attr = props.attributes;
25 var setAttr = props.setAttributes;
26 var blockProps = useBlockProps({ className: 'bkbg-coms-editor' });
27
28 function updateAvatar(idx, key, val) {
29 var next = attr.avatars.map(function (a, i) {
30 if (i !== idx) return a;
31 var obj = {}; Object.keys(a).forEach(function (k) { obj[k] = a[k]; });
32 obj[key] = val; return obj;
33 });
34 setAttr({ avatars: next });
35 }
36
37 function updateTrust(idx, val) {
38 var next = attr.trusts.map(function (t, i) { return i === idx ? { text: val } : t; });
39 setAttr({ trusts: next });
40 }
41
42 /* avatar strip */
43 var avatarStrip = el('div', { style: { display: 'flex', alignItems: 'center', justifyContent: 'center', marginBottom: '16px' } },
44 attr.avatars.map(function (av, idx) {
45 return el('div', {
46 key: idx,
47 style: { marginLeft: idx === 0 ? 0 : attr.avatarOverlap + 'px', position: 'relative', zIndex: attr.avatars.length - idx }
48 },
49 av.imageUrl
50 ? el('img', {
51 src: av.imageUrl, alt: av.alt,
52 style: { width: attr.avatarSize + 'px', height: attr.avatarSize + 'px', borderRadius: '50%', objectFit: 'cover', border: '3px solid ' + attr.avatarBorderColor, display: 'block' }
53 })
54 : el('div', {
55 style: { width: attr.avatarSize + 'px', height: attr.avatarSize + 'px', borderRadius: '50%', background: '#e5e7eb', border: '3px solid ' + attr.avatarBorderColor, display: 'flex', alignItems: 'center', justifyContent: 'center', fontSize: '18px' }
56 }, '👤')
57 );
58 })
59 );
60
61 var controls = el(InspectorControls, {},
62 el(PanelBody, { title: __('Avatars', 'blockenberg'), initialOpen: true },
63 el('p', { style: { color: '#6b7280', fontSize: '12px' } }, __('Click each avatar below to add images, or use the fields here:', 'blockenberg')),
64 attr.avatars.map(function (av, idx) {
65 return el('div', { key: idx, style: { border: '1px solid #e5e7eb', borderRadius: '6px', padding: '10px', marginBottom: '8px' } },
66 el(TextControl, { label: __('Name', 'blockenberg'), value: av.name, onChange: function (v) { updateAvatar(idx, 'name', v); }, __nextHasNoMarginBottom: true }),
67 el(MediaUploadCheck, {},
68 el(MediaUpload, {
69 onSelect: function (m) { updateAvatar(idx, 'imageUrl', m.url); updateAvatar(idx, 'imageId', m.id); },
70 allowedTypes: ['image'], value: av.imageId,
71 render: function (ref) {
72 return el('div', { style: { display: 'flex', gap: '8px', alignItems: 'center', marginTop: '6px' } },
73 av.imageUrl && el('img', { src: av.imageUrl, style: { width: '32px', height: '32px', borderRadius: '50%', objectFit: 'cover' } }),
74 el(Button, { isSmall: true, isSecondary: true, onClick: ref.open }, av.imageUrl ? __('Change', 'blockenberg') : __('Add Photo', 'blockenberg')),
75 av.imageUrl && el(Button, { isSmall: true, isDestructive: true, onClick: function () { updateAvatar(idx, 'imageUrl', ''); updateAvatar(idx, 'imageId', 0); } }, '')
76 );
77 }
78 })
79 ),
80 el(Button, { isSmall: true, isDestructive: true, style: { marginTop: '6px' }, onClick: function () { setAttr({ avatars: attr.avatars.filter(function (_, i) { return i !== idx; }) }); } }, __('Remove', 'blockenberg'))
81 );
82 }),
83 attr.avatars.length < 8 && el(Button, { isSecondary: true, isSmall: true, onClick: function () { setAttr({ avatars: attr.avatars.concat([{ imageUrl: '', imageId: 0, alt: 'Member', name: 'Member' }]) }); } }, '+ Add Avatar'),
84 el(RangeControl, { label: __('Avatar Size (px)', 'blockenberg'), value: attr.avatarSize, min: 28, max: 80, onChange: function (v) { setAttr({ avatarSize: v }); }, __nextHasNoMarginBottom: true }),
85 el(RangeControl, { label: __('Overlap (px, negative)', 'blockenberg'), value: attr.avatarOverlap, min: -40, max: 0, onChange: function (v) { setAttr({ avatarOverlap: v }); }, __nextHasNoMarginBottom: true })
86 ),
87 el(PanelBody, { title: __('Content', 'blockenberg'), initialOpen: false },
88 el(TextControl, { label: __('Member Count', 'blockenberg'), value: attr.memberCount, onChange: function (v) { setAttr({ memberCount: v }); }, __nextHasNoMarginBottom: true }),
89 el(TextControl, { label: __('Count Label', 'blockenberg'), value: attr.memberCountLabel, onChange: function (v) { setAttr({ memberCountLabel: v }); }, __nextHasNoMarginBottom: true }),
90 el(ToggleControl, { label: __('Show Heading', 'blockenberg'), checked: attr.showHeading, onChange: function (v) { setAttr({ showHeading: v }); }, __nextHasNoMarginBottom: true }),
91 el(ToggleControl, { label: __('Show CTA', 'blockenberg'), checked: attr.ctaEnabled, onChange: function (v) { setAttr({ ctaEnabled: v }); }, __nextHasNoMarginBottom: true }),
92 attr.ctaEnabled && el(TextControl, { label: __('CTA Label', 'blockenberg'), value: attr.ctaLabel, onChange: function (v) { setAttr({ ctaLabel: v }); }, __nextHasNoMarginBottom: true }),
93 attr.ctaEnabled && el(TextControl, { label: __('CTA URL', 'blockenberg'), value: attr.ctaUrl, onChange: function (v) { setAttr({ ctaUrl: v }); }, __nextHasNoMarginBottom: true }),
94 attr.ctaEnabled && el(ToggleControl, { label: __('Open in new tab', 'blockenberg'), checked: attr.ctaIsExternal, onChange: function (v) { setAttr({ ctaIsExternal: v }); }, __nextHasNoMarginBottom: true }),
95 el(ToggleControl, { label: __('Show Badge', 'blockenberg'), checked: attr.showBadge, onChange: function (v) { setAttr({ showBadge: v }); }, __nextHasNoMarginBottom: true }),
96 attr.showBadge && el(TextControl, { label: __('Badge Text', 'blockenberg'), value: attr.badgeText, onChange: function (v) { setAttr({ badgeText: v }); }, __nextHasNoMarginBottom: true }),
97 el(ToggleControl, { label: __('Show Trust Text', 'blockenberg'), checked: attr.showTrusts, onChange: function (v) { setAttr({ showTrusts: v }); }, __nextHasNoMarginBottom: true }),
98 attr.showTrusts && attr.trusts.map(function (t, idx) {
99 return el(TextControl, { key: idx, label: __('Trust item', 'blockenberg') + ' ' + (idx + 1), value: t.text, onChange: function (v) { updateTrust(idx, v); }, __nextHasNoMarginBottom: true });
100 })
101 ),
102 el(PanelBody, { title: __('Layout', 'blockenberg'), initialOpen: false },
103 el(SelectControl, {
104 label: __('Layout', 'blockenberg'), value: attr.layout,
105 options: [{ label: 'Centered', value: 'centered' }, { label: 'Split (left/right)', value: 'split' }],
106 onChange: function (v) { setAttr({ layout: v }); }, __nextHasNoMarginBottom: true
107 }),
108 el(RangeControl, { label: __('Max Width (px)', 'blockenberg'), value: attr.maxWidth, min: 400, max: 1400, onChange: function (v) { setAttr({ maxWidth: v }); }, __nextHasNoMarginBottom: true }),
109 el(RangeControl, { label: __('Padding Top (px)', 'blockenberg'), value: attr.paddingTop, min: 0, max: 160, onChange: function (v) { setAttr({ paddingTop: v }); }, __nextHasNoMarginBottom: true }),
110 el(RangeControl, { label: __('Padding Bottom (px)', 'blockenberg'), value: attr.paddingBottom, min: 0, max: 160, onChange: function (v) { setAttr({ paddingBottom: v }); }, __nextHasNoMarginBottom: true })
111 ),
112
113 el( PanelBody, { title: __( 'Typography', 'blockenberg' ), initialOpen: false },
114 el(getTypographyControl(), { label: __('Heading Typography', 'blockenberg'), value: attr.typoHeading, onChange: function (v) { setAttr({ typoHeading: v }); } }),
115 el(getTypographyControl(), { label: __('Body Typography', 'blockenberg'), value: attr.typoBody, onChange: function (v) { setAttr({ typoBody: v }); } })
116 ),
117 el(PanelColorSettings, {
118 title: __('Colors', 'blockenberg'), initialOpen: false,
119 colorSettings: [
120 { label: __('Background', 'blockenberg'), value: attr.bgColor, onChange: function (v) { setAttr({ bgColor: v || '#ffffff' }); } },
121 { label: __('Heading', 'blockenberg'), value: attr.headingColor, onChange: function (v) { setAttr({ headingColor: v || '#111827' }); } },
122 { label: __('Count', 'blockenberg'), value: attr.countColor, onChange: function (v) { setAttr({ countColor: v || '#111827' }); } },
123 { label: __('Subtext', 'blockenberg'), value: attr.textColor, onChange: function (v) { setAttr({ textColor: v || '#6b7280' }); } },
124 { label: __('CTA BG', 'blockenberg'), value: attr.ctaBg, onChange: function (v) { setAttr({ ctaBg: v || '#7c3aed' }); } },
125 { label: __('CTA Text', 'blockenberg'), value: attr.ctaColor, onChange: function (v) { setAttr({ ctaColor: v || '#ffffff' }); } },
126 { label: __('Badge BG', 'blockenberg'), value: attr.badgeBg, onChange: function (v) { setAttr({ badgeBg: v || '#f0fdf4' }); } },
127 { label: __('Badge Text', 'blockenberg'), value: attr.badgeColor, onChange: function (v) { setAttr({ badgeColor: v || '#15803d' }); } },
128 { label: __('Avatar Border', 'blockenberg'), value: attr.avatarBorderColor, onChange: function (v) { setAttr({ avatarBorderColor: v || '#ffffff' }); } },
129 { label: __('Trust Text', 'blockenberg'), value: attr.trustColor, onChange: function (v) { setAttr({ trustColor: v || '#9ca3af' }); } }
130 ]
131 })
132 );
133
134 var isSplit = attr.layout === 'split';
135
136 return el('div', blockProps, controls,
137 el('div', { style: Object.assign({ background: attr.bgColor, paddingTop: attr.paddingTop + 'px', paddingBottom: attr.paddingBottom + 'px' }, _tv(attr.typoHeading, '--bkcoms-heading-'), _tv(attr.typoBody, '--bkcoms-body-')) },
138 el('div', {
139 style: {
140 maxWidth: attr.maxWidth + 'px', margin: '0 auto',
141 display: isSplit ? 'flex' : 'block',
142 gap: isSplit ? '48px' : undefined, alignItems: isSplit ? 'center' : undefined,
143 textAlign: isSplit ? 'left' : 'center'
144 }
145 },
146 /* left/top side: avatars + count */
147 el('div', { style: isSplit ? { flex: '0 0 auto' } : {} },
148 avatarStrip,
149 el('div', { style: { textAlign: 'center', marginBottom: '4px' } },
150 el('span', { style: { fontSize: '28px', fontWeight: '800', color: attr.countColor } }, attr.memberCount),
151 el('span', { style: { fontSize: '14px', color: attr.textColor, marginLeft: '8px' } }, attr.memberCountLabel)
152 )
153 ),
154 /* right/bottom side: heading + CTA */
155 el('div', { style: { flex: 1 } },
156 attr.showHeading && el('div', {},
157 el(RichText, {
158 tagName: 'h2', value: attr.heading,
159 className: 'bkcoms-heading',
160 style: { color: attr.headingColor, margin: '0 0 12px' },
161 onChange: function (v) { setAttr({ heading: v }); }
162 }),
163 el(RichText, {
164 tagName: 'p', value: attr.subtext,
165 className: 'bkcoms-body',
166 style: { color: attr.textColor, margin: '0 0 20px' },
167 onChange: function (v) { setAttr({ subtext: v }); }
168 })
169 ),
170 attr.ctaEnabled && el('div', { style: { marginBottom: '16px', display: 'flex', gap: '12px', alignItems: 'center', justifyContent: isSplit ? 'flex-start' : 'center', flexWrap: 'wrap' } },
171 el('a', {
172 href: '#editor',
173 style: { background: attr.ctaBg, color: attr.ctaColor, padding: '14px 32px', borderRadius: '8px', fontWeight: '700', fontSize: '15px', textDecoration: 'none', display: 'inline-block' }
174 }, attr.ctaLabel),
175 attr.showBadge && el('span', { style: { background: attr.badgeBg, color: attr.badgeColor, fontSize: '12px', fontWeight: '600', padding: '4px 12px', borderRadius: '999px' } }, attr.badgeText)
176 ),
177 attr.showTrusts && el('div', { style: { display: 'flex', gap: '16px', justifyContent: isSplit ? 'flex-start' : 'center', flexWrap: 'wrap' } },
178 attr.trusts.map(function (t, i) {
179 return el('span', { key: i, style: { fontSize: '12px', color: attr.trustColor } }, '' + t.text);
180 })
181 )
182 )
183 )
184 )
185 );
186 },
187
188 save: function (props) {
189 var a = props.attributes;
190 var sv = Object.assign({}, _tv(a.typoHeading, '--bkcoms-heading-'), _tv(a.typoBody, '--bkcoms-body-'));
191 return el('div', wp.blockEditor.useBlockProps.save({ style: sv }),
192 el('div', { className: 'bkbg-coms-app', 'data-opts': JSON.stringify(a) })
193 );
194 }
195 });
196 }() );
197