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 / press-release / index.js

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

279 lines 18.2 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 Fragment = wp.element.Fragment;
4 var __ = wp.i18n.__;
5 var registerBlockType = wp.blocks.registerBlockType;
6 var InspectorControls = wp.blockEditor.InspectorControls;
7 var useBlockProps = wp.blockEditor.useBlockProps;
8 var PanelColorSettings = wp.blockEditor.PanelColorSettings;
9 var SelectControl = wp.components.SelectControl;
10 var PanelBody = wp.components.PanelBody;
11 var ToggleControl = wp.components.ToggleControl;
12 var RangeControl = wp.components.RangeControl;
13 var TextControl = wp.components.TextControl;
14 var Button = wp.components.Button;
15
16 var _tc; function getTypoControl() { return _tc || (_tc = window.bkbgTypographyControl); }
17 var _tv; function getTypoCssVars() { return _tv || (_tv = window.bkbgTypoCssVars); }
18
19 /* ── ES5 update helpers ──────────────────────────── */
20 function updateParagraph(paras, idx, val) {
21 return paras.map(function (p, i) { return i === idx ? val : p; });
22 }
23 function addParagraph(paras) { return paras.concat(['New paragraph text here.']); }
24 function removeParagraph(paras, idx) { return paras.filter(function (_, i) { return i !== idx; }); }
25
26 registerBlockType('blockenberg/press-release', {
27 edit: function (props) {
28 var a = props.attributes;
29 var set = props.setAttributes;
30 var blockProps = useBlockProps((function () {
31 var _tvFn = getTypoCssVars();
32 var s = {};
33 if (_tvFn) {
34 Object.assign(s, _tvFn(a.headlineTypo, '--bkbg-pr-hl-'));
35 Object.assign(s, _tvFn(a.bodyTypo, '--bkbg-pr-bd-'));
36 }
37 return { className: 'bkbg-pr-editor', style: s };
38 })());
39
40 function renderPreview() {
41 var bodyStyle = {
42 background: a.bgColor, boxSizing: 'border-box',
43 maxWidth: a.maxWidth + 'px', margin: '0 auto',
44 color: a.textColor,
45 padding: '40px 48px',
46 border: '1px solid ' + a.dateBorderColor,
47 borderRadius: a.borderRadius + 'px'
48 };
49
50 return el('div', { className: 'bkbg-pr-block', style: bodyStyle },
51 /* Release label */
52 a.showReleaseLabel && el('div', {
53 className: 'bkbg-pr-release-label',
54 style: {
55 fontFamily: 'inherit', fontSize: '11px', fontWeight: 700,
56 textTransform: 'uppercase', letterSpacing: '.12em',
57 color: a.releaseLabelColor, marginBottom: '8px'
58 }
59 }, a.releaseLabel),
60
61 /* Dateline */
62 a.showDateline && el('div', {
63 className: 'bkbg-pr-dateline',
64 style: {
65 fontSize: '13px', color: a.subheadlineColor,
66 marginBottom: '24px', paddingBottom: '16px',
67 borderBottom: '1px solid ' + a.dateBorderColor
68 }
69 }, (a.city ? a.city + ', ' : '') + a.releaseDate),
70
71 /* Headline */
72 el('h1', {
73 className: 'bkbg-pr-headline',
74 style: {
75 color: a.headlineColor,
76 margin: '0 0 12px'
77 }
78 }, a.headline),
79
80 /* Subheadline */
81 a.showSubheadline && a.subheadline && el('h2', {
82 className: 'bkbg-pr-subheadline',
83 style: {
84 color: a.subheadlineColor,
85 margin: '0 0 28px'
86 }
87 }, a.subheadline),
88
89 /* Intro paragraph (dateline-style bold first para) */
90 a.introParagraph && el('p', {
91 className: 'bkbg-pr-intro',
92 style: { margin: '0 0 18px', color: a.textColor }
93 }, a.introParagraph),
94
95 /* Body paragraphs */
96 a.bodyParagraphs.map(function (para, idx) {
97 return el('p', {
98 key: idx, className: 'bkbg-pr-para',
99 style: { margin: '0 0 18px', color: a.textColor }
100 }, para);
101 }),
102
103 /* End marker */
104 a.showEndMarker && el('p', {
105 className: 'bkbg-pr-end',
106 style: { textAlign: 'center', color: a.textColor, margin: '24px 0' }
107 }, a.endMarker),
108
109 /* Boilerplate */
110 a.showBoilerplate && el('div', {
111 className: 'bkbg-pr-boilerplate',
112 style: {
113 background: a.boilerplateBg, border: '1px solid ' + a.boilerplateBorderColor,
114 borderRadius: (a.borderRadius - 2) + 'px',
115 padding: '18px 20px', marginBottom: '16px'
116 }
117 },
118 el('strong', {
119 style: { fontSize: '13px', fontWeight: 700, display: 'block', marginBottom: '6px', color: a.textColor }
120 }, a.boilerplateTitle),
121 el('p', {
122 style: { margin: 0, color: a.boilerplateTextColor }
123 }, a.boilerplateText)
124 ),
125
126 /* Media contact */
127 a.showMediaContact && el('div', {
128 className: 'bkbg-pr-contact',
129 style: {
130 background: a.contactBg, border: '1px solid ' + a.contactBorderColor,
131 borderRadius: (a.borderRadius - 2) + 'px',
132 padding: '14px 20px', fontSize: '13px', fontFamily: 'Arial, sans-serif'
133 }
134 },
135 el('div', { style: { fontWeight: 700, marginBottom: '4px', color: a.contactColor } }, 'Media Contact'),
136 el('div', { style: { color: a.contactColor } }, a.mediaContactName + (a.mediaContactTitle ? ', ' + a.mediaContactTitle : '')),
137 a.mediaContactCompany && el('div', { style: { color: a.contactColor, opacity: '.85' } }, a.mediaContactCompany),
138 a.mediaContactEmail && el('div', { style: { marginTop: '4px' } },
139 el('a', { href: 'mailto:' + a.mediaContactEmail, style: { color: a.accentColor, textDecoration: 'none' } }, a.mediaContactEmail)
140 ),
141 a.mediaContactPhone && el('div', { style: { color: a.contactColor } }, a.mediaContactPhone)
142 )
143 );
144 }
145
146 var inspector = el(InspectorControls, {},
147 /* Release Info */
148 el(PanelBody, { title: 'Release Info', initialOpen: true },
149 el(ToggleControl, { __nextHasNoMarginBottom: true, label: 'Show Release Label', checked: a.showReleaseLabel, onChange: function (v) { set({ showReleaseLabel: v }); } }),
150 a.showReleaseLabel && el(TextControl, { __nextHasNoMarginBottom: true, label: 'Label', value: a.releaseLabel, onChange: function (v) { set({ releaseLabel: v }); } }),
151 el(ToggleControl, { __nextHasNoMarginBottom: true, label: 'Show Dateline', checked: a.showDateline, onChange: function (v) { set({ showDateline: v }); } }),
152 a.showDateline && el(TextControl, { __nextHasNoMarginBottom: true, label: 'City', value: a.city, onChange: function (v) { set({ city: v }); } }),
153 a.showDateline && el(TextControl, { __nextHasNoMarginBottom: true, label: 'Date', value: a.releaseDate, onChange: function (v) { set({ releaseDate: v }); } })
154 ),
155 /* Headline */
156 el(PanelBody, { title: 'Headline', initialOpen: true },
157 el('div', { style: { marginBottom: 8 } },
158 el('label', { style: { fontSize: 11, fontWeight: 600, display: 'block', marginBottom: 4 } }, 'Headline'),
159 el('textarea', {
160 value: a.headline, rows: 3,
161 style: { width: '100%', fontSize: 12, padding: '5px 7px', border: '1px solid #ddd', borderRadius: 4, boxSizing: 'border-box', fontFamily: 'inherit' },
162 onChange: function (e) { set({ headline: e.target.value }); }
163 })
164 ),
165 el(ToggleControl, { __nextHasNoMarginBottom: true, label: 'Show Subheadline', checked: a.showSubheadline, onChange: function (v) { set({ showSubheadline: v }); } }),
166 a.showSubheadline && el('div', { style: { marginBottom: 8 } },
167 el('label', { style: { fontSize: 11, fontWeight: 600, display: 'block', marginBottom: 4 } }, 'Subheadline'),
168 el('textarea', {
169 value: a.subheadline, rows: 2,
170 style: { width: '100%', fontSize: 12, padding: '5px 7px', border: '1px solid #ddd', borderRadius: 4, boxSizing: 'border-box', fontFamily: 'inherit' },
171 onChange: function (e) { set({ subheadline: e.target.value }); }
172 })
173 )
174 ),
175 /* Body Content */
176 el(PanelBody, { title: 'Body Content', initialOpen: true },
177 el('div', { style: { marginBottom: 10 } },
178 el('label', { style: { fontSize: 11, fontWeight: 600, display: 'block', marginBottom: 4 } }, 'Opening Paragraph (Dateline Lead)'),
179 el('textarea', {
180 value: a.introParagraph, rows: 4,
181 style: { width: '100%', fontSize: 12, padding: '5px 7px', border: '1px solid #ddd', borderRadius: 4, boxSizing: 'border-box', fontFamily: 'inherit' },
182 onChange: function (e) { set({ introParagraph: e.target.value }); }
183 })
184 ),
185 el('div', { style: { fontSize: 11, fontWeight: 600, marginBottom: 6 } }, 'Body Paragraphs:'),
186 a.bodyParagraphs.map(function (para, idx) {
187 return el('div', {
188 key: idx,
189 style: { marginBottom: 10, border: '1px solid #e2e8f0', borderRadius: 6, padding: 8, background: '#f8fafc' }
190 },
191 el('div', { style: { display: 'flex', justifyContent: 'space-between', marginBottom: 4 } },
192 el('span', { style: { fontSize: 11, color: '#64748b' } }, 'Paragraph ' + (idx + 1)),
193 el(Button, { isSmall: true, isDestructive: true, onClick: function () { set({ bodyParagraphs: removeParagraph(a.bodyParagraphs, idx) }); } }, '')
194 ),
195 el('textarea', {
196 value: para, rows: 4,
197 style: { width: '100%', fontSize: 12, padding: '5px 7px', border: '1px solid #ddd', borderRadius: 4, boxSizing: 'border-box', fontFamily: 'inherit' },
198 onChange: function (e) { set({ bodyParagraphs: updateParagraph(a.bodyParagraphs, idx, e.target.value) }); }
199 })
200 );
201 }),
202 el(Button, { variant: 'secondary', style: { width: '100%', justifyContent: 'center', marginTop: 4 }, onClick: function () { set({ bodyParagraphs: addParagraph(a.bodyParagraphs) }); } }, '+ Add Paragraph')
203 ),
204 /* End Marker */
205 el(PanelBody, { title: 'End Marker & Boilerplate', initialOpen: false },
206 el(ToggleControl, { __nextHasNoMarginBottom: true, label: 'Show End Marker (###)', checked: a.showEndMarker, onChange: function (v) { set({ showEndMarker: v }); } }),
207 a.showEndMarker && el(TextControl, { __nextHasNoMarginBottom: true, label: 'End Marker Text', value: a.endMarker, onChange: function (v) { set({ endMarker: v }); } }),
208 el(ToggleControl, { __nextHasNoMarginBottom: true, label: 'Show Boilerplate', checked: a.showBoilerplate, onChange: function (v) { set({ showBoilerplate: v }); } }),
209 a.showBoilerplate && el(TextControl, { __nextHasNoMarginBottom: true, label: 'Boilerplate Title', value: a.boilerplateTitle, onChange: function (v) { set({ boilerplateTitle: v }); } }),
210 a.showBoilerplate && el('div', { style: { marginBottom: 8 } },
211 el('label', { style: { fontSize: 11, fontWeight: 600, display: 'block', marginBottom: 4 } }, 'Boilerplate Text'),
212 el('textarea', {
213 value: a.boilerplateText, rows: 4,
214 style: { width: '100%', fontSize: 12, padding: '5px 7px', border: '1px solid #ddd', borderRadius: 4, boxSizing: 'border-box', fontFamily: 'inherit' },
215 onChange: function (e) { set({ boilerplateText: e.target.value }); }
216 })
217 )
218 ),
219 /* Media Contact */
220 el(PanelBody, { title: 'Media Contact', initialOpen: false },
221 el(ToggleControl, { __nextHasNoMarginBottom: true, label: 'Show Media Contact', checked: a.showMediaContact, onChange: function (v) { set({ showMediaContact: v }); } }),
222 a.showMediaContact && Fragment && el(Fragment, {},
223 el(TextControl, { __nextHasNoMarginBottom: true, label: 'Name', value: a.mediaContactName, onChange: function (v) { set({ mediaContactName: v }); } }),
224 el(TextControl, { __nextHasNoMarginBottom: true, label: 'Title / Role', value: a.mediaContactTitle, onChange: function (v) { set({ mediaContactTitle: v }); } }),
225 el(TextControl, { __nextHasNoMarginBottom: true, label: 'Company', value: a.mediaContactCompany, onChange: function (v) { set({ mediaContactCompany: v }); } }),
226 el(TextControl, { __nextHasNoMarginBottom: true, label: 'Email', value: a.mediaContactEmail, onChange: function (v) { set({ mediaContactEmail: v }); } }),
227 el(TextControl, { __nextHasNoMarginBottom: true, label: 'Phone', value: a.mediaContactPhone, onChange: function (v) { set({ mediaContactPhone: v }); } })
228 )
229 ),
230 /* Typography */
231 el(PanelBody, { title: 'Typography', initialOpen: false },
232 (function () {
233 var TC = getTypoControl();
234 if (!TC) return el('p', null, 'Loading\u2026');
235 return el(Fragment, null,
236 el(TC, { label: __('Headline', 'blockenberg'), value: a.headlineTypo, onChange: function (v) { set({ headlineTypo: v }); } }),
237 el(TC, { label: __('Body Text', 'blockenberg'), value: a.bodyTypo, onChange: function (v) { set({ bodyTypo: v }); } })
238 );
239 })()
240 ),
241 /* Appearance */
242 el(PanelBody, { title: 'Appearance', initialOpen: false },
243 el(RangeControl, { __nextHasNoMarginBottom: true, label: 'Max Width (px)', value: a.maxWidth, min: 480, max: 1200, onChange: function (v) { set({ maxWidth: v }); } }),
244 el(RangeControl, { __nextHasNoMarginBottom: true, label: 'Border Radius', value: a.borderRadius, min: 0, max: 20, onChange: function (v) { set({ borderRadius: v }); } })
245 ),
246 /* Colors */
247 el(PanelColorSettings, {
248 title: 'Colors', initialOpen: false,
249 colorSettings: [
250 { label: 'Background', value: a.bgColor, onChange: function (v) { set({ bgColor: v || '#ffffff' }); } },
251 { label: 'Body Text Color', value: a.textColor, onChange: function (v) { set({ textColor: v || '#1a1a2e' }); } },
252 { label: 'Headline Color', value: a.headlineColor, onChange: function (v) { set({ headlineColor: v || '#0f172a' }); } },
253 { label: 'Subheadline / Dateline Color', value: a.subheadlineColor, onChange: function (v) { set({ subheadlineColor: v || '#475569' }); } },
254 { label: 'Release Label Color', value: a.releaseLabelColor, onChange: function (v) { set({ releaseLabelColor: v || '#dc2626' }); } },
255 { label: 'Border Color', value: a.dateBorderColor, onChange: function (v) { set({ dateBorderColor: v || '#e2e8f0' }); } },
256 { label: 'Boilerplate Background', value: a.boilerplateBg, onChange: function (v) { set({ boilerplateBg: v || '#f8fafc' }); } },
257 { label: 'Boilerplate Text Color', value: a.boilerplateTextColor, onChange: function (v) { set({ boilerplateTextColor: v || '#64748b' }); } },
258 { label: 'Contact Background', value: a.contactBg, onChange: function (v) { set({ contactBg: v || '#f1f5f9' }); } },
259 { label: 'Contact Text Color', value: a.contactColor, onChange: function (v) { set({ contactColor: v || '#334155' }); } },
260 { label: 'Link / Accent Color', value: a.accentColor, onChange: function (v) { set({ accentColor: v || '#2563eb' }); } }
261 ]
262 })
263 );
264
265 return el(Fragment, {}, inspector, el('div', blockProps, renderPreview()));
266 },
267
268 save: function (props) {
269 var useBlockProps = wp.blockEditor.useBlockProps;
270 return el('div', useBlockProps.save(),
271 el('div', {
272 className: 'bkbg-press-release-app',
273 'data-opts': JSON.stringify(props.attributes)
274 })
275 );
276 }
277 });
278 }() );
279