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 / author-profile / index.js

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

202 lines 16.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 ( function () {
2 const el = window.wp.element.createElement;
3 const { registerBlockType } = window.wp.blocks;
4 const { InspectorControls, useBlockProps, PanelColorSettings } = window.wp.blockEditor;
5 const { PanelBody, RangeControl, ToggleControl, TextControl, Button, SelectControl } = window.wp.components;
6 const { __ } = window.wp.i18n;
7 var IP = function () { return window.bkbgIconPicker; };
8
9 function getTypographyControl() {
10 return (typeof window.bkbgTypographyControl !== 'undefined') ? window.bkbgTypographyControl : null;
11 }
12 function getTypoCssVars() {
13 return (typeof window.bkbgTypoCssVars !== 'undefined') ? window.bkbgTypoCssVars : function() { return {}; };
14 }
15
16 function buildWrapStyle( a ) {
17 var _tv = getTypoCssVars();
18 var s = { background: a.bgColor || undefined };
19 Object.assign( s, _tv( a.nameTypo || {}, '--bkbg-ap-name-' ) );
20 Object.assign( s, _tv( a.roleTypo || {}, '--bkbg-ap-role-' ) );
21 Object.assign( s, _tv( a.bioTypo || {}, '--bkbg-ap-bio-' ) );
22 Object.assign( s, _tv( a.statValueTypo || {}, '--bkbg-ap-stat-val-' ) );
23 Object.assign( s, _tv( a.statLabelTypo || {}, '--bkbg-ap-stat-lbl-' ) );
24 return s;
25 }
26
27 // ── Avatar ────────────────────────────────────────────────────────────────
28 function Avatar( { avatarUrl, avatarInitials, avatarColor, avatarSize } ) {
29 const circle = { width: avatarSize, height: avatarSize, borderRadius: '50%', flexShrink: 0, overflow: 'hidden', background: avatarColor, display: 'flex', alignItems: 'center', justifyContent: 'center' };
30 if ( avatarUrl ) {
31 return el( 'div', { style: circle }, el( 'img', { src: avatarUrl, alt: avatarInitials, style: { width: '100%', height: '100%', objectFit: 'cover' } } ) );
32 }
33 return el( 'div', { style: circle },
34 el( 'span', { style: { color: '#fff', fontWeight: 700, fontSize: ( avatarSize * 0.35 ) + 'px', letterSpacing: 1 } }, avatarInitials )
35 );
36 }
37
38 // ── Stats row ─────────────────────────────────────────────────────────────
39 function StatsRow( { stats, statValueColor, statLabelColor, fontSize, borderColor } ) {
40 return el( 'div', { className: 'bkbg-ap-stats', style: { display: 'flex', gap: 0, margin: '16px 0 0', borderTop: '1px solid ' + borderColor, paddingTop: 16 } },
41 ( stats || [] ).map( ( s, i ) =>
42 el( 'div', { key: i, style: { flex: 1, textAlign: 'center', borderRight: i < ( stats.length - 1 ) ? '1px solid ' + borderColor : 'none' } },
43 el( 'div', { className: 'bkbg-ap-stat-val', style: { color: statValueColor } }, s.value ),
44 el( 'div', { className: 'bkbg-ap-stat-lbl', style: { color: statLabelColor, marginTop: 2 } }, s.label ),
45 )
46 ),
47 );
48 }
49
50 // ── Social links ──────────────────────────────────────────────────────────
51 function SocialLinks( { socialLinks, textColor, fontSize, forSave } ) {
52 return el( 'div', { className: 'bkbg-ap-social', style: { display: 'flex', flexWrap: 'wrap', gap: 8, marginTop: 14 } },
53 ( socialLinks || [] ).map( ( link, i ) =>
54 el( 'a', { key: i, href: link.url || '#', style: { display: 'flex', alignItems: 'center', gap: 5, fontSize: fontSize + 'px', color: textColor, textDecoration: 'none', padding: '4px 10px', borderRadius: 99, background: 'rgba(0,0,0,0.05)' } },
55 el( 'span', { className: 'bkbg-ap-social-icon' }, (link.iconType || 'custom-char') !== 'custom-char' ? (forSave ? IP().buildSaveIcon(link.iconType, link.icon, link.iconDashicon, link.iconImageUrl, link.iconDashiconColor) : IP().buildEditorIcon(link.iconType, link.icon, link.iconDashicon, link.iconImageUrl, link.iconDashiconColor)) : link.icon ),
56 el( 'span', {}, link.label ),
57 )
58 ),
59 );
60 }
61
62 // ── Renderer ──────────────────────────────────────────────────────────────
63 function renderAuthorProfile( a, forSave ) {
64 const isHoriz = a.layout === 'horizontal';
65 return el( 'div', {
66 className: 'bkbg-ap-card',
67 style: {
68 background: a.cardBg,
69 border: '1px solid ' + a.borderColor,
70 borderRadius: a.borderRadius + 'px',
71 padding: a.padding + 'px',
72 display: 'flex',
73 flexDirection: isHoriz ? 'row' : 'column',
74 alignItems: isHoriz ? 'flex-start' : 'center',
75 gap: isHoriz ? 24 : 16,
76 boxSizing: 'border-box',
77 }
78 },
79 // Avatar
80 a.showAvatar && el( Avatar, { avatarUrl: a.avatarUrl, avatarInitials: a.avatarInitials, avatarColor: a.avatarColor, avatarSize: a.avatarSize } ),
81
82 // Body column
83 el( 'div', { style: { flex: 1, textAlign: isHoriz ? 'left' : 'center', minWidth: 0 } },
84 el( 'div', { className: 'bkbg-ap-name', style: { color: a.nameColor } }, a.name ),
85 a.showRole && el( 'div', { className: 'bkbg-ap-role', style: { color: a.roleColor, marginTop: 4 } }, a.role ),
86 a.showBio && el( 'p', { className: 'bkbg-ap-bio', style: { color: a.textColor, margin: '10px 0 0' } }, a.bio ),
87 a.showSocial && el( SocialLinks, { socialLinks: a.socialLinks, textColor: a.textColor, fontSize: a.fontSize, forSave: forSave } ),
88 a.showStats && el( StatsRow, { stats: a.stats, statValueColor: a.statValueColor, statLabelColor: a.statLabelColor, fontSize: a.fontSize, borderColor: a.borderColor } ),
89 ),
90 );
91 }
92
93 // ── Helpers for array editing ─────────────────────────────────────────────
94 function updItem( setAttributes, arr, key, idx, field, val ) {
95 setAttributes( { [key]: arr.map( ( x, i ) => i === idx ? { ...x, [field]: val } : x ) } );
96 }
97
98 // ── Block ─────────────────────────────────────────────────────────────────
99 registerBlockType( 'blockenberg/author-profile', {
100 edit: function ( props ) {
101 const { attributes: a, setAttributes } = props;
102 const blockProps = useBlockProps( { className: 'bkbg-ap-wrap', style: buildWrapStyle( a ) } );
103
104 return el( 'div', blockProps,
105 el( InspectorControls, {},
106
107 el( PanelBody, { title: __( 'Author', 'blockenberg' ), initialOpen: true },
108 el( TextControl, { label: __( 'Name', 'blockenberg' ), value: a.name, onChange: v => setAttributes( { name: v } ) } ),
109 el( TextControl, { label: __( 'Role', 'blockenberg' ), value: a.role, onChange: v => setAttributes( { role: v } ) } ),
110 el( TextControl, { label: __( 'Bio', 'blockenberg' ), value: a.bio, onChange: v => setAttributes( { bio: v } ) } ),
111 el( SelectControl, { label: __( 'Layout', 'blockenberg' ), value: a.layout, options: [ { label: 'Horizontal', value: 'horizontal' }, { label: 'Vertical', value: 'vertical' } ], onChange: v => setAttributes( { layout: v } ) } ),
112 el( ToggleControl, { label: __( 'Show Avatar', 'blockenberg' ), checked: a.showAvatar, onChange: v => setAttributes( { showAvatar: v } ) } ),
113 el( ToggleControl, { label: __( 'Show Role', 'blockenberg' ), checked: a.showRole, onChange: v => setAttributes( { showRole: v } ) } ),
114 el( ToggleControl, { label: __( 'Show Bio', 'blockenberg' ), checked: a.showBio, onChange: v => setAttributes( { showBio: v } ) } ),
115 el( ToggleControl, { label: __( 'Show Stats', 'blockenberg' ), checked: a.showStats, onChange: v => setAttributes( { showStats: v } ) } ),
116 el( ToggleControl, { label: __( 'Show Social', 'blockenberg' ), checked: a.showSocial, onChange: v => setAttributes( { showSocial: v } ) } ),
117 ),
118
119 el( PanelBody, { title: __( 'Avatar', 'blockenberg' ), initialOpen: false },
120 el( TextControl, { label: __( 'Avatar URL (optional)', 'blockenberg' ), value: a.avatarUrl, onChange: v => setAttributes( { avatarUrl: v } ) } ),
121 el( TextControl, { label: __( 'Initials', 'blockenberg' ), value: a.avatarInitials, onChange: v => setAttributes( { avatarInitials: v } ) } ),
122 el( 'div', { style: { display: 'flex', alignItems: 'center', gap: 8, marginBottom: 8 } },
123 el( 'label', { style: { fontSize: 12 } }, __( 'Avatar Color', 'blockenberg' ) ),
124 el( 'input', { type: 'color', value: a.avatarColor, style: { width: 40, height: 28, border: 'none', borderRadius: 4, cursor: 'pointer' }, onChange: e => setAttributes( { avatarColor: e.target.value } ) } ),
125 ),
126 el( RangeControl, { label: __( 'Avatar Size', 'blockenberg' ), value: a.avatarSize, onChange: v => setAttributes( { avatarSize: v } ), min: 40, max: 160 } ),
127 ),
128
129 el( PanelBody, { title: __( 'Style', 'blockenberg' ), initialOpen: false },
130 el( RangeControl, { label: __( 'Border Radius', 'blockenberg' ), value: a.borderRadius, onChange: v => setAttributes( { borderRadius: v } ), min: 0, max: 32 } ),
131 el( RangeControl, { label: __( 'Padding', 'blockenberg' ), value: a.padding, onChange: v => setAttributes( { padding: v } ), min: 12, max: 60 } ),
132 ),
133
134
135 el( PanelBody, { title: __( 'Typography', 'blockenberg' ), initialOpen: false },
136 (function () {
137 var TC = getTypographyControl();
138 if (!TC) return el('p', { style: { color: '#999', fontSize: '12px', padding: '8px 0' } }, __('Typography control loading…', 'blockenberg'));
139 return el(window.wp.element.Fragment, {},
140 el(TC, { label: __('Name', 'blockenberg'), value: a.nameTypo || {}, onChange: function (v) { setAttributes({ nameTypo: v }); } }),
141 el(TC, { label: __('Role', 'blockenberg'), value: a.roleTypo || {}, onChange: function (v) { setAttributes({ roleTypo: v }); } }),
142 el(TC, { label: __('Bio', 'blockenberg'), value: a.bioTypo || {}, onChange: function (v) { setAttributes({ bioTypo: v }); } }),
143 el(TC, { label: __('Stat Value', 'blockenberg'), value: a.statValueTypo || {}, onChange: function (v) { setAttributes({ statValueTypo: v }); } }),
144 el(TC, { label: __('Stat Label', 'blockenberg'), value: a.statLabelTypo || {}, onChange: function (v) { setAttributes({ statLabelTypo: v }); } })
145 );
146 })()
147 ),
148 el( PanelColorSettings, {
149 title: __( 'Colors', 'blockenberg' ), initialOpen: false,
150 colorSettings: [
151 { label: __( 'Page Background', 'blockenberg' ), value: a.bgColor, onChange: v => setAttributes( { bgColor: v || '#ffffff' } ) },
152 { label: __( 'Card Background', 'blockenberg' ), value: a.cardBg, onChange: v => setAttributes( { cardBg: v || '#f9fafb' } ) },
153 { label: __( 'Border', 'blockenberg' ), value: a.borderColor, onChange: v => setAttributes( { borderColor: v || '#e5e7eb' } ) },
154 { label: __( 'Name', 'blockenberg' ), value: a.nameColor, onChange: v => setAttributes( { nameColor: v || '#111827' } ) },
155 { label: __( 'Role', 'blockenberg' ), value: a.roleColor, onChange: v => setAttributes( { roleColor: v || '#6366f1' } ) },
156 { label: __( 'Body Text', 'blockenberg' ), value: a.textColor, onChange: v => setAttributes( { textColor: v || '#374151' } ) },
157 { label: __( 'Stat Value', 'blockenberg' ), value: a.statValueColor, onChange: v => setAttributes( { statValueColor: v || '#111827' } ) },
158 { label: __( 'Stat Label', 'blockenberg' ), value: a.statLabelColor, onChange: v => setAttributes( { statLabelColor: v || '#6b7280' } ) },
159 ]
160 } ),
161
162 el( PanelBody, { title: __( 'Stats', 'blockenberg' ), initialOpen: false },
163 el( Button, { variant: 'secondary', style: { marginBottom: 8 }, onClick: () => setAttributes( { stats: [ ...( a.stats || [] ), { label: 'Label', value: '0' } ] } ) }, __( '+ Add Stat', 'blockenberg' ) ),
164 a.stats.map( ( s, i ) =>
165 el( 'div', { key: i, style: { marginBottom: 12, padding: '10px', background: '#f3f4f6', borderRadius: 8 } },
166 el( TextControl, { label: __( 'Value', 'blockenberg' ), value: s.value, onChange: v => updItem( setAttributes, a.stats, 'stats', i, 'value', v ) } ),
167 el( TextControl, { label: __( 'Label', 'blockenberg' ), value: s.label, onChange: v => updItem( setAttributes, a.stats, 'stats', i, 'label', v ) } ),
168 el( Button, { isDestructive: true, isSmall: true, onClick: () => setAttributes( { stats: a.stats.filter( ( _, j ) => j !== i ) } ) }, __( 'Remove', 'blockenberg' ) ),
169 )
170 ),
171 ),
172
173 el( PanelBody, { title: __( 'Social Links', 'blockenberg' ), initialOpen: false },
174 el( Button, { variant: 'secondary', style: { marginBottom: 8 }, onClick: () => setAttributes( { socialLinks: [ ...( a.socialLinks || [] ), { icon: '🔗', iconType: 'custom-char', iconDashicon: '', iconImageUrl: '', label: 'Link', url: '' } ] } ) }, __( '+ Add Link', 'blockenberg' ) ),
175 a.socialLinks.map( ( link, i ) =>
176 el( 'div', { key: i, style: { marginBottom: 12, padding: '10px', background: '#f3f4f6', borderRadius: 8 } },
177 el(IP().IconPickerControl, {
178 iconType: link.iconType, customChar: link.icon, dashicon: link.iconDashicon, imageUrl: link.iconImageUrl,
179 onChangeType: function(v) { updItem(setAttributes, a.socialLinks, 'socialLinks', i, 'iconType', v); },
180 onChangeChar: function(v) { updItem(setAttributes, a.socialLinks, 'socialLinks', i, 'icon', v); },
181 onChangeDashicon: function(v) { updItem(setAttributes, a.socialLinks, 'socialLinks', i, 'iconDashicon', v); },
182 onChangeImageUrl: function(v) { updItem(setAttributes, a.socialLinks, 'socialLinks', i, 'iconImageUrl', v); }
183 }),
184 el( TextControl, { label: __( 'Label', 'blockenberg' ), value: link.label, onChange: v => updItem( setAttributes, a.socialLinks, 'socialLinks', i, 'label', v ) } ),
185 el( TextControl, { label: __( 'URL', 'blockenberg' ), value: link.url, onChange: v => updItem( setAttributes, a.socialLinks, 'socialLinks', i, 'url', v ) } ),
186 el( Button, { isDestructive: true, isSmall: true, onClick: () => setAttributes( { socialLinks: a.socialLinks.filter( ( _, j ) => j !== i ) } ) }, __( 'Remove', 'blockenberg' ) ),
187 )
188 ),
189 ),
190 ),
191
192 renderAuthorProfile( a ),
193 );
194 },
195
196 save: function ( { attributes: a } ) {
197 const blockProps = useBlockProps.save( { className: 'bkbg-ap-wrap', style: buildWrapStyle( a ) } );
198 return el( 'div', blockProps, renderAuthorProfile( a, true ) );
199 },
200 } );
201 }() );
202