PluginProbe
Blockenberg — 600+ Advanced Gutenberg Blocks & AI Agent for WordPress Block Editor / 2.0.11
Blockenberg — 600+ Advanced Gutenberg Blocks & AI Agent for WordPress Block Editor v2.0.11
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 / article-header / index.js

index.js in Blockenberg — 600+ Advanced Gutenberg Blocks & AI Agent for WordPress Block Editor 2.0.11, at blocks/article-header/index.js

215 lines 14.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 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 /* ── Typography lazy getters ───────────────────────────────────────── */
19 var _Typo, _tv;
20 Object.defineProperty(window, '__bkbgArhTypoReady', { get: function () {
21 if (!_Typo) _Typo = window.bkbgTypographyControl;
22 if (!_tv) _tv = window.bkbgTypoCssVars;
23 return !!(_Typo && _tv);
24 }});
25 function getTypoCssVars() { window.__bkbgArhTypoReady; return _tv; }
26 function getTypoComponent() { window.__bkbgArhTypoReady; return _Typo; }
27
28 registerBlockType('blockenberg/article-header', {
29 edit: function (props) {
30 var attr = props.attributes;
31 var setAttr = props.setAttributes;
32 var blockProps = useBlockProps((function () {
33 var _tv = getTypoCssVars();
34 var s = {
35 '--bkbg-arh-headline-sz': attr.headlineSize + 'px',
36 '--bkbg-arh-sub-sz': attr.subSize + 'px'
37 };
38 if (_tv) {
39 Object.assign(s, _tv(attr.headlineTypo || {}, '--bkbg-arh-headline-'));
40 Object.assign(s, _tv(attr.subTypo || {}, '--bkbg-arh-sub-'));
41 }
42 return { className: 'bkbg-arh-editor', style: s };
43 })());
44
45 var isCentered = attr.layout === 'centered';
46
47 /* meta bar */
48 var metaBar = (attr.showAuthor || attr.showDate || attr.showReadingTime)
49 ? el('div', { className: 'bkbg-arh-meta', style: { display: 'flex', alignItems: 'center', gap: '16px', flexWrap: 'wrap', paddingTop: '20px', borderTop: '1px solid ' + attr.dividerColor } },
50 attr.showAuthor && el('div', { style: { display: 'flex', alignItems: 'center', gap: '10px' } },
51 el(MediaUploadCheck, {},
52 el(MediaUpload, {
53 onSelect: function (m) { setAttr({ authorAvatarUrl: m.url, authorAvatarId: m.id }); },
54 allowedTypes: ['image'], value: attr.authorAvatarId,
55 render: function (ref) {
56 return el('div', { onClick: ref.open, style: { cursor: 'pointer' } },
57 attr.authorAvatarUrl
58 ? el('img', { src: attr.authorAvatarUrl, style: { width: '40px', height: '40px', borderRadius: '50%', objectFit: 'cover' } })
59 : el('div', { style: { width: '40px', height: '40px', borderRadius: '50%', background: '#e5e7eb', display: 'flex', alignItems: 'center', justifyContent: 'center', fontSize: '18px' } }, '👤')
60 );
61 }
62 })
63 ),
64 el('div', {},
65 el(RichText, {
66 tagName: 'p', value: attr.authorName,
67 style: { margin: 0, fontSize: '14px', fontWeight: '600', color: attr.headlineColor },
68 onChange: function (v) { setAttr({ authorName: v }); }
69 }),
70 el(RichText, {
71 tagName: 'p', value: attr.authorRole,
72 style: { margin: 0, fontSize: '12px', color: attr.metaColor },
73 onChange: function (v) { setAttr({ authorRole: v }); }
74 })
75 )
76 ),
77 (attr.showDate || attr.showReadingTime) && el('div', { style: { display: 'flex', gap: '12px', alignItems: 'center', color: attr.metaColor, fontSize: '13px' } },
78 attr.showDate && el(RichText, {
79 tagName: 'span', value: attr.publishDate, onChange: function (v) { setAttr({ publishDate: v }); },
80 style: { color: attr.metaColor, fontSize: '13px' }
81 }),
82 attr.showDate && attr.showReadingTime && el('span', {}, '·'),
83 attr.showReadingTime && el(RichText, {
84 tagName: 'span', value: attr.readingTime, onChange: function (v) { setAttr({ readingTime: v }); },
85 style: { color: attr.metaColor, fontSize: '13px' }
86 })
87 )
88 ) : null;
89
90 /* hero image */
91 var heroImage = attr.showHeroImage
92 ? el('div', { style: { marginTop: '32px' } },
93 el(MediaUploadCheck, {},
94 el(MediaUpload, {
95 onSelect: function (m) { setAttr({ heroImageUrl: m.url, heroImageId: m.id, heroImageAlt: m.alt || '' }); },
96 allowedTypes: ['image'], value: attr.heroImageId,
97 render: function (ref) {
98 return attr.heroImageUrl
99 ? el('div', { style: { position: 'relative' } },
100 el('img', { src: attr.heroImageUrl, alt: attr.heroImageAlt, style: { width: '100%', borderRadius: attr.heroRadius + 'px', display: 'block', maxHeight: '480px', objectFit: 'cover' } }),
101 el(Button, {
102 isSmall: true, isDestructive: true,
103 style: { position: 'absolute', top: '8px', right: '8px' },
104 onClick: function () { setAttr({ heroImageUrl: '', heroImageId: 0 }); }
105 }, '✕ Remove')
106 )
107 : el('div', {
108 onClick: ref.open, style: {
109 border: '2px dashed #e5e7eb', borderRadius: attr.heroRadius + 'px', height: '220px',
110 display: 'flex', alignItems: 'center', justifyContent: 'center',
111 cursor: 'pointer', color: '#9ca3af', fontSize: '16px'
112 }
113 }, '🖼 Click to add hero image');
114 }
115 })
116 )
117 ) : null;
118
119 var controls = el(InspectorControls, {},
120 el(PanelBody, { title: __('Category & Headline', 'blockenberg'), initialOpen: true },
121 el(ToggleControl, { label: __('Show Category Badge', 'blockenberg'), checked: attr.showCategory, onChange: function (v) { setAttr({ showCategory: v }); }, __nextHasNoMarginBottom: true }),
122 el(ToggleControl, { label: __('Show Subheadline', 'blockenberg'), checked: attr.showSubheadline, onChange: function (v) { setAttr({ showSubheadline: v }); }, __nextHasNoMarginBottom: true }),
123 el(SelectControl, {
124 label: __('Headline Tag', 'blockenberg'), value: attr.headlineTag,
125 options: ['h1', 'h2', 'h3'].map(function (t) { return { label: t.toUpperCase(), value: t }; }),
126 onChange: function (v) { setAttr({ headlineTag: v }); }, __nextHasNoMarginBottom: true
127 }),
128 ),
129 el(PanelBody, { title: __('Author & Meta', 'blockenberg'), initialOpen: false },
130 el(ToggleControl, { label: __('Show Author', 'blockenberg'), checked: attr.showAuthor, onChange: function (v) { setAttr({ showAuthor: v }); }, __nextHasNoMarginBottom: true }),
131 el(ToggleControl, { label: __('Show Date', 'blockenberg'), checked: attr.showDate, onChange: function (v) { setAttr({ showDate: v }); }, __nextHasNoMarginBottom: true }),
132 el(ToggleControl, { label: __('Show Reading Time', 'blockenberg'), checked: attr.showReadingTime, onChange: function (v) { setAttr({ showReadingTime: v }); }, __nextHasNoMarginBottom: true })
133 ),
134 el(PanelBody, { title: __('Hero Image & Layout', 'blockenberg'), initialOpen: false },
135 el(ToggleControl, { label: __('Show Hero Image', 'blockenberg'), checked: attr.showHeroImage, onChange: function (v) { setAttr({ showHeroImage: v }); }, __nextHasNoMarginBottom: true }),
136 attr.showHeroImage && el(RangeControl, { label: __('Image Radius (px)', 'blockenberg'), value: attr.heroRadius, min: 0, max: 32, onChange: function (v) { setAttr({ heroRadius: v }); }, __nextHasNoMarginBottom: true }),
137 el(SelectControl, {
138 label: __('Layout', 'blockenberg'), value: attr.layout,
139 options: [{ label: 'Simple (left-aligned)', value: 'simple' }, { label: 'Centered', value: 'centered' }],
140 onChange: function (v) { setAttr({ layout: v }); }, __nextHasNoMarginBottom: true
141 }),
142 el(RangeControl, { label: __('Max Width (px)', 'blockenberg'), value: attr.maxWidth, min: 480, max: 1400, onChange: function (v) { setAttr({ maxWidth: v }); }, __nextHasNoMarginBottom: true }),
143 el(RangeControl, { label: __('Padding Top (px)', 'blockenberg'), value: attr.paddingTop, min: 0, max: 160, onChange: function (v) { setAttr({ paddingTop: v }); }, __nextHasNoMarginBottom: true }),
144 el(RangeControl, { label: __('Padding Bottom (px)', 'blockenberg'), value: attr.paddingBottom, min: 0, max: 160, onChange: function (v) { setAttr({ paddingBottom: v }); }, __nextHasNoMarginBottom: true })
145 ),
146
147 el( PanelBody, { title: __( 'Typography', 'blockenberg' ), initialOpen: false },
148 getTypoComponent() && el(getTypoComponent(), {
149 label: __('Headline Typography', 'blockenberg'),
150 value: attr.headlineTypo || {},
151 onChange: function (v) { setAttr({ headlineTypo: v }); }
152 }),
153 getTypoComponent() && el(getTypoComponent(), {
154 label: __('Subheadline Typography', 'blockenberg'),
155 value: attr.subTypo || {},
156 onChange: function (v) { setAttr({ subTypo: v }); }
157 })
158 ),
159 el(PanelColorSettings, {
160 title: __('Colors', 'blockenberg'), initialOpen: false,
161 colorSettings: [
162 { label: __('Background', 'blockenberg'), value: attr.bgColor, onChange: function (v) { setAttr({ bgColor: v || '#ffffff' }); } },
163 { label: __('Category BG', 'blockenberg'), value: attr.categoryBg, onChange: function (v) { setAttr({ categoryBg: v || '#7c3aed' }); } },
164 { label: __('Category Text', 'blockenberg'), value: attr.categoryColor, onChange: function (v) { setAttr({ categoryColor: v || '#ffffff' }); } },
165 { label: __('Headline', 'blockenberg'), value: attr.headlineColor, onChange: function (v) { setAttr({ headlineColor: v || '#111827' }); } },
166 { label: __('Subheadline', 'blockenberg'), value: attr.subColor, onChange: function (v) { setAttr({ subColor: v || '#6b7280' }); } },
167 { label: __('Meta / Date', 'blockenberg'), value: attr.metaColor, onChange: function (v) { setAttr({ metaColor: v || '#9ca3af' }); } },
168 { label: __('Divider', 'blockenberg'), value: attr.dividerColor, onChange: function (v) { setAttr({ dividerColor: v || '#e5e7eb' }); } }
169 ]
170 })
171 );
172
173 return el('div', blockProps, controls,
174 el('div', {
175 style: {
176 background: attr.bgColor,
177 paddingTop: attr.paddingTop + 'px',
178 paddingBottom: attr.paddingBottom + 'px'
179 }
180 },
181 el('div', { style: { maxWidth: attr.maxWidth + 'px', margin: '0 auto', textAlign: isCentered ? 'center' : 'left' } },
182 attr.showCategory && el('div', { style: { marginBottom: '16px' } },
183 el('span', {
184 style: { background: attr.categoryBg, color: attr.categoryColor, fontSize: '11px', fontWeight: '700', padding: '4px 12px', borderRadius: '999px', textTransform: 'uppercase', letterSpacing: '0.08em' }
185 }, el(RichText, {
186 tagName: 'span', value: attr.category, onChange: function (v) { setAttr({ category: v }); }
187 }))
188 ),
189 el(RichText, {
190 tagName: attr.headlineTag, value: attr.headline,
191 className: 'bkbg-arh-headline',
192 style: { color: attr.headlineColor, margin: '0 0 20px' },
193 onChange: function (v) { setAttr({ headline: v }); }
194 }),
195 attr.showSubheadline && el(RichText, {
196 tagName: 'p', value: attr.subheadline,
197 className: 'bkbg-arh-sub',
198 style: { color: attr.subColor, margin: '0 0 28px' },
199 onChange: function (v) { setAttr({ subheadline: v }); }
200 }),
201 metaBar,
202 heroImage
203 )
204 )
205 );
206 },
207
208 save: function (props) {
209 return el('div', wp.blockEditor.useBlockProps.save(),
210 el('div', { className: 'bkbg-arh-app', 'data-opts': JSON.stringify(props.attributes) })
211 );
212 }
213 });
214 }() );
215