PluginProbe
Blockenberg — 600+ Advanced Gutenberg Blocks & AI Agent for WordPress Block Editor / 2.0.14
Blockenberg — 600+ Advanced Gutenberg Blocks & AI Agent for WordPress Block Editor v2.0.14
2.0.14 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 / update-notice / index.js

index.js in Blockenberg — 600+ Advanced Gutenberg Blocks & AI Agent for WordPress Block Editor 2.0.14, at blocks/update-notice/index.js

196 lines 12.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 useBlockProps = wp.blockEditor.useBlockProps;
7 var RichText = wp.blockEditor.RichText;
8 var PanelColorSettings = wp.blockEditor.PanelColorSettings;
9 var PanelBody = wp.components.PanelBody;
10 var ToggleControl = wp.components.ToggleControl;
11 var RangeControl = wp.components.RangeControl;
12 var SelectControl = wp.components.SelectControl;
13 var TextControl = wp.components.TextControl;
14 var TextareaControl = wp.components.TextareaControl;
15 var Button = wp.components.Button;
16
17 // Resolve the shared components lazily without defining globals for each block.
18 function _tc(label, key, attrs, setA) {
19 var Control = window.bkbgTypographyControl;
20 return Control ? el(Control, {
21 label: label,
22 value: attrs[key] || {},
23 onChange: function (value) { var update = {}; update[key] = value; setA(update); }
24 }) : null;
25 }
26 function _tvf(vars, key, attrs, prefix) {
27 var cssVars = window.bkbgTypoCssVars;
28 if (cssVars) Object.assign(vars, cssVars(attrs[key] || {}, prefix));
29 return vars;
30 }
31 function getTypoControl(label, key, attrs, setA) { return _tc(label, key, attrs, setA); }
32 function getTypoCssVars(attrs) {
33 var v = {};
34 _tvf(v, 'labelTypo', attrs, '--bkupn-lb-');
35 _tvf(v, 'summaryTypo', attrs, '--bkupn-sm-');
36 return v;
37 }
38
39 var TYPES = [
40 { value: 'updated', icon: '🔄', label: 'Updated' },
41 { value: 'corrected', icon: '✏️', label: 'Correction' },
42 { value: 'added', icon: '➕', label: 'Addition' },
43 { value: 'deprecated', icon: '⚠️', label: 'Deprecated' },
44 { value: 'reviewed', icon: '�
45 ', label: 'Reviewed' }
46 ];
47
48 function getType(val) {
49 return TYPES.find(function (t) { return t.value === val; }) || TYPES[0];
50 }
51
52 registerBlockType('blockenberg/update-notice', {
53 edit: function (props) {
54 var attr = props.attributes;
55 var set = props.setAttributes;
56 var t = getType(attr.type);
57
58 var blockProps = useBlockProps((function () { var _tv = getTypoCssVars(attr); var s = {}; Object.assign(s, _tv); s.padding = attr.paddingTop + 'px 0 ' + attr.paddingBottom + 'px'; return { style: s }; })());
59
60 function updateHistory(idx, key, val) {
61 var arr = (attr.history || []).map(function (h, i) {
62 if (i !== idx) return h;
63 var c = Object.assign({}, h); c[key] = val; return c;
64 });
65 set({ history: arr });
66 }
67
68 var wrapStyle = {
69 background: attr.bgColor,
70 borderRadius: attr.borderRadius + 'px',
71 overflow: 'hidden'
72 };
73 if (attr.style === 'banner') {
74 wrapStyle.borderLeft = '4px solid ' + attr.accentColor;
75 wrapStyle.padding = '12px 16px';
76 } else if (attr.style === 'box') {
77 wrapStyle.border = '1px solid ' + attr.borderColor;
78 wrapStyle.borderLeft = '4px solid ' + attr.accentColor;
79 wrapStyle.padding = '14px 18px';
80 } else {
81 /* pill / inline */
82 wrapStyle.display = 'inline-flex';
83 wrapStyle.alignItems = 'center';
84 wrapStyle.gap = '8px';
85 wrapStyle.padding = '6px 14px';
86 wrapStyle.border = '1px solid ' + attr.borderColor;
87 }
88
89 var topRow = el('div', { style: { display: 'flex', alignItems: 'flex-start', gap: '10px', flexWrap: 'wrap' } },
90 el('div', { style: { display: 'flex', alignItems: 'center', gap: '6px', flexShrink: 0 } },
91 el('span', { style: { fontSize: '16px' } }, t.icon),
92 el('span', { className: 'bkbg-upn-label', style: { color: attr.labelColor } }, t.label + ':')
93 ),
94 attr.primaryDate && el('span', { className: 'bkbg-upn-date', style: { color: attr.dateColor } }, attr.primaryDate),
95 attr.showOriginalDate && attr.originalPublishDate && el('span', { style: { fontSize: '12px', color: attr.textColor, opacity: 0.7 } }, '(originally published ' + attr.originalPublishDate + ')')
96 );
97
98 var summaryEl = el(RichText, { tagName: 'p', className: 'bkbg-upn-summary', value: attr.primarySummary, allowedFormats: ['core/bold', 'core/italic', 'core/link'], placeholder: __('Describe what was updated or corrected…', 'blockenberg'), style: { margin: attr.style === 'pill' ? '0' : '8px 0 0', color: attr.textColor }, onChange: function (v) { set({ primarySummary: v }); } });
99
100 var historyEl = attr.showHistory && (attr.history || []).length > 0 && el('div', { style: { marginTop: '12px', paddingTop: '10px', borderTop: '1px solid ' + attr.borderColor } },
101 el('div', { style: { fontSize: '11px', fontWeight: 600, color: attr.labelColor, textTransform: 'uppercase', letterSpacing: '0.05em', marginBottom: '6px' } }, __('Change History', 'blockenberg')),
102 el('ul', { style: { margin: 0, paddingLeft: '16px' } },
103 (attr.history || []).map(function (h, i) {
104 return el('li', { key: i, style: { fontSize: '12px', color: attr.historyTextColor, marginBottom: '4px' } },
105 el('strong', {}, h.date + ': '),
106 h.summary
107 );
108 })
109 )
110 );
111
112 var controls = el(InspectorControls, {},
113 el(PanelBody, { title: __('Notice', 'blockenberg'), initialOpen: true },
114 el(SelectControl, {
115 label: __('Notice Type', 'blockenberg'), value: attr.type, __nextHasNoMarginBottom: true,
116 options: TYPES.map(function (t) { return { label: t.icon + ' ' + t.label, value: t.value }; }),
117 onChange: function (v) { set({ type: v }); }
118 }),
119 el('div', { style: { marginTop: '8px' } },
120 el(TextControl, { label: __('Update Date', 'blockenberg'), value: attr.primaryDate, placeholder: 'e.g. February 24, 2026', __nextHasNoMarginBottom: true, onChange: function (v) { set({ primaryDate: v }); } })
121 ),
122 el('div', { style: { marginTop: '12px' } },
123 el(ToggleControl, { label: __('Show Original Publish Date', 'blockenberg'), checked: attr.showOriginalDate, __nextHasNoMarginBottom: true, onChange: function (v) { set({ showOriginalDate: v }); } })
124 ),
125 attr.showOriginalDate && el('div', { style: { marginTop: '8px' } },
126 el(TextControl, { label: __('Original Publish Date', 'blockenberg'), value: attr.originalPublishDate, placeholder: 'e.g. January 10, 2025', __nextHasNoMarginBottom: true, onChange: function (v) { set({ originalPublishDate: v }); } })
127 )
128 ),
129 el(PanelBody, { title: __('Change History', 'blockenberg'), initialOpen: false },
130 el(ToggleControl, { label: __('Show Change History', 'blockenberg'), checked: attr.showHistory, __nextHasNoMarginBottom: true, onChange: function (v) { set({ showHistory: v }); } }),
131 attr.showHistory && el('div', { style: { marginTop: '10px' } },
132 (attr.history || []).map(function (h, idx) {
133 return el('div', { key: idx, style: { marginBottom: '10px', padding: '8px', background: '#f8fafc', borderRadius: '4px', border: '1px solid #e2e8f0' } },
134 el(TextControl, { label: __('Date', 'blockenberg'), value: h.date, placeholder: 'Feb 10, 2026', __nextHasNoMarginBottom: true, onChange: function (v) { updateHistory(idx, 'date', v); } }),
135 el('div', { style: { marginTop: '4px' } },
136 el(TextareaControl, { label: __('Summary', 'blockenberg'), value: h.summary, rows: 2, __nextHasNoMarginBottom: true, onChange: function (v) { updateHistory(idx, 'summary', v); } })
137 ),
138 el(Button, { variant: 'link', isDestructive: true, style: { fontSize: '11px' }, onClick: function () { set({ history: (attr.history || []).filter(function (_, i) { return i !== idx; }) }); } }, __('Remove', 'blockenberg'))
139 );
140 }),
141 el(Button, { variant: 'secondary', style: { marginTop: '4px' }, onClick: function () { set({ history: (attr.history || []).concat([{ date: '', summary: '' }]) }); } }, __('+ Add History Entry', 'blockenberg'))
142 )
143 ),
144 el(PanelBody, { title: __('Style', 'blockenberg'), initialOpen: false },
145 el(SelectControl, {
146 label: __('Style', 'blockenberg'), value: attr.style, __nextHasNoMarginBottom: true,
147 options: [{ label: 'Banner (left accent strip)', value: 'banner' }, { label: 'Box (full border)', value: 'box' }, { label: 'Pill (compact inline)', value: 'pill' }],
148 onChange: function (v) { set({ style: v }); }
149 }),
150 el('div', { style: { marginTop: '12px' } },
151 el(RangeControl, { label: __('Border Radius', 'blockenberg'), value: attr.borderRadius, min: 0, max: 20, __nextHasNoMarginBottom: true, onChange: function (v) { set({ borderRadius: v }); } })
152 ),
153 el('div', { style: { marginTop: '12px' } },
154 el(RangeControl, { label: __('Padding Top', 'blockenberg'), value: attr.paddingTop, min: 0, max: 80, __nextHasNoMarginBottom: true, onChange: function (v) { set({ paddingTop: v }); } })
155 ),
156 el('div', { style: { marginTop: '12px' } },
157 el(RangeControl, { label: __('Padding Bottom', 'blockenberg'), value: attr.paddingBottom, min: 0, max: 80, __nextHasNoMarginBottom: true, onChange: function (v) { set({ paddingBottom: v }); } })
158 )
159 ),
160 el(PanelBody, { title: __('Typography', 'blockenberg'), initialOpen: false },
161 getTypoControl(__('Label / Date', 'blockenberg'), 'labelTypo', attr, set),
162 getTypoControl(__('Summary', 'blockenberg'), 'summaryTypo', attr, set)
163 ),
164 el(PanelColorSettings, {
165 title: __('Colors', 'blockenberg'), initialOpen: false,
166 colorSettings: [
167 { label: __('Background', 'blockenberg'), value: attr.bgColor, onChange: function (v) { set({ bgColor: v || '#eff6ff' }); } },
168 { label: __('Border', 'blockenberg'), value: attr.borderColor, onChange: function (v) { set({ borderColor: v || '#bfdbfe' }); } },
169 { label: __('Accent', 'blockenberg'), value: attr.accentColor, onChange: function (v) { set({ accentColor: v || '#2563eb' }); } },
170 { label: __('Label', 'blockenberg'), value: attr.labelColor, onChange: function (v) { set({ labelColor: v || '#1d4ed8' }); } },
171 { label: __('Date', 'blockenberg'), value: attr.dateColor, onChange: function (v) { set({ dateColor: v || '#3b82f6' }); } },
172 { label: __('Text', 'blockenberg'), value: attr.textColor, onChange: function (v) { set({ textColor: v || '#1e3a8a' }); } },
173 { label: __('History Text', 'blockenberg'), value: attr.historyTextColor, onChange: function (v) { set({ historyTextColor: v || '#1e40af' }); } }
174 ]
175 })
176 );
177
178 return el('div', blockProps,
179 controls,
180 el('div', { style: wrapStyle },
181 topRow,
182 attr.style !== 'pill' && summaryEl,
183 attr.style !== 'pill' && historyEl
184 )
185 );
186 },
187 save: function (props) {
188 var attr = props.attributes;
189 var useBlockProps = wp.blockEditor.useBlockProps;
190 return el('div', useBlockProps.save((function () { var _tv = getTypoCssVars(attr); var s = {}; Object.assign(s, _tv); return { style: s }; })()),
191 el('div', { className: 'bkbg-upn-app', 'data-opts': JSON.stringify(attr) })
192 );
193 }
194 });
195 }() );
196