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 / update-notice / index.js

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

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