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

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

296 lines 26.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 registerBlockType = wp.blocks.registerBlockType;
5 var __ = wp.i18n.__;
6 var InspectorControls = wp.blockEditor.InspectorControls;
7 var PanelColorSettings = wp.blockEditor.PanelColorSettings;
8 var useBlockProps = wp.blockEditor.useBlockProps;
9 var PanelBody = wp.components.PanelBody;
10 var RangeControl = wp.components.RangeControl;
11 var ToggleControl = wp.components.ToggleControl;
12 var TextControl = wp.components.TextControl;
13 var SelectControl = wp.components.SelectControl;
14 var Button = wp.components.Button;
15
16 function getTypographyControl() { return (window.bkbgTypographyControl || function () { return null; }); }
17 function getTypoCssVars() { return (window.bkbgTypoCssVars || function () { return {}; }); }
18 function _tv(typo, prefix) { var fn = getTypoCssVars(); return fn(typo || {}, prefix); }
19
20 var LAYOUT_OPTIONS = [
21 { label: 'Timeline (left line)', value: 'timeline' },
22 { label: 'Cards', value: 'cards' },
23 { label: 'Minimal list', value: 'list' },
24 ];
25
26 var CATEGORY_OPTIONS = [
27 { label: '✦ New', value: 'new' },
28 { label: '↑ Improved', value: 'improved' },
29 { label: '✔ Fixed', value: 'fixed' },
30 { label: '⚠ Deprecated', value: 'deprecated' },
31 { label: '✕ Removed', value: 'removed' },
32 ];
33
34 var CATEGORY_LABELS = { new: 'New', improved: 'Improved', fixed: 'Fixed', deprecated: 'Deprecated', removed: 'Removed' };
35
36 function makeId() { return 'x' + Math.random().toString(36).substr(2, 6); }
37
38 function getCategoryColor(cat, a) {
39 if (cat === 'new') return a.newColor;
40 if (cat === 'improved') return a.improvedColor;
41 if (cat === 'fixed') return a.fixedColor;
42 if (cat === 'deprecated') return a.deprecatedColor;
43 return a.removedColor;
44 }
45
46 function renderBadge(text, bg, color, size) {
47 return el('span', { className: 'bkbg-changelog-badge', style: { display: 'inline-block', padding: '2px 8px', background: bg + '22', color: bg, borderRadius: '4px', whiteSpace: 'nowrap' } }, text);
48 }
49
50 function renderEntry(entry, a, inEditor, onUpdate) {
51 var isTimeline = a.layout === 'timeline';
52 var isCard = a.layout === 'cards';
53 return el('div', {
54 key: entry.id,
55 className: 'bkbg-changelog-entry bkbg-changelog-entry--' + a.layout,
56 style: { display: 'flex', gap: '24px', position: 'relative', marginBottom: isCard ? '0' : '36px' }
57 },
58 isTimeline && el('div', { className: 'bkbg-changelog-connector', style: { display: 'flex', flexDirection: 'column', alignItems: 'center', flexShrink: 0 } },
59 el('div', { style: { width: '12px', height: '12px', borderRadius: '50%', background: a.versionBadgeBg, flexShrink: 0, marginTop: '3px' } }),
60 el('div', { className: 'bkbg-changelog-line', style: { flex: 1, width: '2px', background: a.connectorColor, minHeight: '40px' } })
61 ),
62 el('div', { className: 'bkbg-changelog-content', style: Object.assign({ flex: 1, paddingBottom: isTimeline ? '12px' : '0' }, isCard ? { background: '#fff', border: '1px solid #e5e7eb', borderRadius: '10px', padding: '20px' } : {}) },
63 el('div', { style: { display: 'flex', alignItems: 'center', gap: '10px', flexWrap: 'wrap', marginBottom: '4px' } },
64 el('span', { className: 'bkbg-changelog-version', style: { color: a.versionColor } }, 'v' + entry.version),
65 entry.badge && a.showBadge && renderBadge(entry.badge, a.versionBadgeBg, a.versionBadgeColor, 11),
66 a.showDate && entry.date && el('span', { className: 'bkbg-changelog-date', style: { color: a.dateColor } }, entry.date)
67 ),
68 el('ul', { className: 'bkbg-changelog-items', style: { listStyle: 'none', padding: 0, margin: '10px 0 0', display: 'flex', flexDirection: 'column', gap: '6px' } },
69 entry.items.map(function (item) {
70 var catColor = getCategoryColor(item.category, a);
71 return el('li', { key: item.id, className: 'bkbg-changelog-item', style: { display: 'flex', alignItems: 'flex-start', gap: '8px', color: a.itemColor } },
72 renderBadge(CATEGORY_LABELS[item.category] || item.category, catColor, '#fff', 10),
73 el('span', null, item.text)
74 );
75 })
76 )
77 )
78 );
79 }
80
81 registerBlockType('blockenberg/changelog', {
82 edit: function (props) {
83 var attributes = props.attributes;
84 var setAttributes = props.setAttributes;
85 var entries = attributes.entries;
86
87 var blockProps = useBlockProps({
88 style: Object.assign({ paddingTop: attributes.paddingTop + 'px', paddingBottom: attributes.paddingBottom + 'px', backgroundColor: attributes.bgColor || undefined }, _tv(attributes.typoTitle, '--bkbg-cl-tt-'), _tv(attributes.typoVersion, '--bkbg-cl-v-'), _tv(attributes.typoItem, '--bkbg-cl-i-'), _tv(attributes.typoDate, '--bkbg-cl-d-'), _tv(attributes.typoBadge, '--bkbg-cl-bg-'))
89 });
90
91 function setEntry(id, patch) {
92 setAttributes({ entries: entries.map(function (e) { return e.id === id ? Object.assign({}, e, patch) : e; }) });
93 }
94 function setItem(entryId, itemId, patch) {
95 setAttributes({ entries: entries.map(function (e) {
96 if (e.id !== entryId) return e;
97 return Object.assign({}, e, { items: e.items.map(function (i) { return i.id === itemId ? Object.assign({}, i, patch) : i; }) });
98 }) });
99 }
100 function addEntry() {
101 setAttributes({ entries: [{ id: makeId(), version: '0.0.0', date: '', badge: '', items: [{ id: makeId(), category: 'new', text: 'New feature' }] }].concat(entries) });
102 }
103 function removeEntry(id) {
104 if (entries.length <= 1) return;
105 setAttributes({ entries: entries.filter(function (e) { return e.id !== id; }) });
106 }
107 function addItem(entryId) {
108 setAttributes({ entries: entries.map(function (e) {
109 if (e.id !== entryId) return e;
110 return Object.assign({}, e, { items: e.items.concat([{ id: makeId(), category: 'new', text: '' }]) });
111 }) });
112 }
113 function removeItem(entryId, itemId) {
114 setAttributes({ entries: entries.map(function (e) {
115 if (e.id !== entryId) return e;
116 return Object.assign({}, e, { items: e.items.filter(function (i) { return i.id !== itemId; }) });
117 }) });
118 }
119
120 return el(Fragment, null,
121 el(InspectorControls, null,
122 el(PanelBody, { title: __('Settings', 'blockenberg'), initialOpen: true },
123 el(SelectControl, { label: __('Layout', 'blockenberg'), value: attributes.layout, options: LAYOUT_OPTIONS, onChange: function (v) { setAttributes({ layout: v }); } }),
124 el(ToggleControl, { label: __('Show section title', 'blockenberg'), checked: attributes.showTitle, onChange: function (v) { setAttributes({ showTitle: v }); }, __nextHasNoMarginBottom: true }),
125 attributes.showTitle && el(TextControl, { label: __('Section title', 'blockenberg'), value: attributes.sectionTitle, onChange: function (v) { setAttributes({ sectionTitle: v }); } }),
126 el(ToggleControl, { label: __('Show date', 'blockenberg'), checked: attributes.showDate, onChange: function (v) { setAttributes({ showDate: v }); }, __nextHasNoMarginBottom: true }),
127 el(ToggleControl, { label: __('Show version badge', 'blockenberg'), checked: attributes.showBadge, onChange: function (v) { setAttributes({ showBadge: v }); }, __nextHasNoMarginBottom: true }),
128 el(RangeControl, { label: __('Max width (px)', 'blockenberg'), value: attributes.maxWidth, min: 400, max: 1200, onChange: function (v) { setAttributes({ maxWidth: v }); } })
129 ),
130 el(PanelBody, { title: __('Typography', 'blockenberg'), initialOpen: false },
131 el(getTypographyControl(), { label: __('Title', 'blockenberg'), value: attributes.typoTitle, onChange: function (v) { setAttributes({ typoTitle: v }); } }),
132 el(getTypographyControl(), { label: __('Version', 'blockenberg'), value: attributes.typoVersion, onChange: function (v) { setAttributes({ typoVersion: v }); } }),
133 el(getTypographyControl(), { label: __('Item', 'blockenberg'), value: attributes.typoItem, onChange: function (v) { setAttributes({ typoItem: v }); } }),
134 el(getTypographyControl(), { label: __('Date', 'blockenberg'), value: attributes.typoDate, onChange: function (v) { setAttributes({ typoDate: v }); } }),
135 el(getTypographyControl(), { label: __('Badge', 'blockenberg'), value: attributes.typoBadge, onChange: function (v) { setAttributes({ typoBadge: v }); } })
136 ),
137 el(PanelColorSettings, {
138 title: __('Category Colors', 'blockenberg'),
139 initialOpen: false,
140 colorSettings: [
141 { value: attributes.newColor, onChange: function (v) { setAttributes({ newColor: v || '' }); }, label: __('New', 'blockenberg') },
142 { value: attributes.improvedColor, onChange: function (v) { setAttributes({ improvedColor: v || '' }); }, label: __('Improved', 'blockenberg') },
143 { value: attributes.fixedColor, onChange: function (v) { setAttributes({ fixedColor: v || '' }); }, label: __('Fixed', 'blockenberg') },
144 { value: attributes.deprecatedColor, onChange: function (v) { setAttributes({ deprecatedColor: v || '' }); }, label: __('Deprecated', 'blockenberg') },
145 { value: attributes.removedColor, onChange: function (v) { setAttributes({ removedColor: v || '' }); }, label: __('Removed', 'blockenberg') },
146 ]
147 }),
148 el(PanelColorSettings, {
149 title: __('Colors', 'blockenberg'),
150 initialOpen: false,
151 colorSettings: [
152 { value: attributes.versionBadgeBg, onChange: function (v) { setAttributes({ versionBadgeBg: v || '' }); }, label: __('Version badge', 'blockenberg') },
153 { value: attributes.connectorColor, onChange: function (v) { setAttributes({ connectorColor: v || '' }); }, label: __('Timeline line', 'blockenberg') },
154 { value: attributes.versionColor, onChange: function (v) { setAttributes({ versionColor: v || '' }); }, label: __('Version text', 'blockenberg') },
155 { value: attributes.dateColor, onChange: function (v) { setAttributes({ dateColor: v || '' }); }, label: __('Date text', 'blockenberg') },
156 { value: attributes.itemColor, onChange: function (v) { setAttributes({ itemColor: v || '' }); }, label: __('Item text', 'blockenberg') },
157 { value: attributes.bgColor, onChange: function (v) { setAttributes({ bgColor: v || '' }); }, label: __('Section background', 'blockenberg') },
158 ]
159 }),
160 el(PanelBody, { title: __('Spacing', 'blockenberg'), initialOpen: false },
161 el(RangeControl, { label: __('Padding top (px)', 'blockenberg'), value: attributes.paddingTop, min: 0, max: 200, onChange: function (v) { setAttributes({ paddingTop: v }); } }),
162 el(RangeControl, { label: __('Padding bottom (px)', 'blockenberg'), value: attributes.paddingBottom, min: 0, max: 200, onChange: function (v) { setAttributes({ paddingBottom: v }); } })
163 ),
164 el(PanelBody, { title: __('Entries', 'blockenberg'), initialOpen: false },
165 entries.map(function (entry, eIdx) {
166 return el(PanelBody, { key: entry.id, title: 'v' + entry.version + (entry.date ? '' + entry.date : '') + ' #' + (eIdx + 1), initialOpen: eIdx === 0 },
167 el(TextControl, { label: __('Version number', 'blockenberg'), value: entry.version, placeholder: '1.0.0', onChange: function (v) { setEntry(entry.id, { version: v }); } }),
168 el(TextControl, { label: __('Date', 'blockenberg'), value: entry.date, placeholder: 'Jan 2026', onChange: function (v) { setEntry(entry.id, { date: v }); } }),
169 el(TextControl, { label: __('Badge label (optional)', 'blockenberg'), value: entry.badge, placeholder: 'Latest', onChange: function (v) { setEntry(entry.id, { badge: v }); } }),
170 el('p', { style: { margin: '12px 0 6px', fontWeight: 600, fontSize: '11px', textTransform: 'uppercase', letterSpacing: '0.06em' } }, __('Items', 'blockenberg')),
171 entry.items.map(function (item, iIdx) {
172 return el('div', { key: item.id, style: { display: 'flex', flexDirection: 'column', gap: '4px', marginBottom: '10px', padding: '8px', background: '#f9fafb', borderRadius: '6px' } },
173 el(SelectControl, { label: __('Category', 'blockenberg'), value: item.category, options: CATEGORY_OPTIONS, onChange: function (v) { setItem(entry.id, item.id, { category: v }); } }),
174 el(TextControl, { label: __('Description', 'blockenberg'), value: item.text, onChange: function (v) { setItem(entry.id, item.id, { text: v }); } }),
175 entry.items.length > 1 && el(Button, { onClick: function () { removeItem(entry.id, item.id); }, variant: 'tertiary', size: 'compact', isDestructive: true }, __('Remove item', 'blockenberg'))
176 );
177 }),
178 el(Button, { onClick: function () { addItem(entry.id); }, variant: 'secondary', size: 'compact', style: { marginBottom: '8px' } }, __('+ Add item', 'blockenberg')),
179 entries.length > 1 && el(Button, { onClick: function () { removeEntry(entry.id); }, variant: 'tertiary', size: 'compact', isDestructive: true, style: { display: 'block' } }, __('Remove entry', 'blockenberg'))
180 );
181 }),
182 el(Button, { onClick: addEntry, variant: 'primary', style: { marginTop: '8px' } }, __('+ Add Version Entry', 'blockenberg'))
183 )
184 ),
185
186 el('div', blockProps,
187 el('div', { style: { maxWidth: attributes.maxWidth + 'px', margin: '0 auto' } },
188 attributes.showTitle && attributes.sectionTitle && el('h2', { className: 'bkbg-changelog-title', style: { marginBottom: '40px' } }, attributes.sectionTitle),
189 el('div', { className: 'bkbg-changelog-list bkbg-changelog-list--' + attributes.layout, style: attributes.layout === 'cards' ? { display: 'grid', gridTemplateColumns: 'repeat(auto-fill, minmax(300px, 1fr))', gap: '20px' } : {} },
190 entries.map(function (entry) {
191 return renderEntry(entry, attributes, true, null);
192 })
193 )
194 )
195 )
196 );
197 },
198
199 deprecated: [{
200 save: function (props) {
201 var a = props.attributes;
202 var blockProps = wp.blockEditor.useBlockProps.save({ className: 'bkbg-changelog-wrap' });
203
204 return el('div', Object.assign({}, blockProps, { style: Object.assign({ paddingTop: a.paddingTop + 'px', paddingBottom: a.paddingBottom + 'px', backgroundColor: a.bgColor || undefined }, _tv(a.typoTitle, '--bkbg-cl-tt-'), _tv(a.typoVersion, '--bkbg-cl-v-'), _tv(a.typoItem, '--bkbg-cl-i-')) }),
205 el('div', { style: { maxWidth: a.maxWidth + 'px', margin: '0 auto' } },
206 a.showTitle && a.sectionTitle && el('h2', { className: 'bkbg-changelog-title', style: { marginBottom: '40px' } }, a.sectionTitle),
207 el('div', { className: 'bkbg-changelog-list bkbg-changelog-list--' + a.layout, style: a.layout === 'cards' ? { display: 'grid', gridTemplateColumns: 'repeat(auto-fill, minmax(300px, 1fr))', gap: '20px' } : {} },
208 a.entries.map(function (entry) {
209 var isTimeline = a.layout === 'timeline';
210 var isCard = a.layout === 'cards';
211 return el('div', { key: entry.id, className: 'bkbg-changelog-entry bkbg-changelog-entry--' + a.layout, style: { display: 'flex', gap: '24px', position: 'relative', marginBottom: isCard ? '0' : '36px' } },
212 isTimeline && el('div', { className: 'bkbg-changelog-connector', style: { display: 'flex', flexDirection: 'column', alignItems: 'center', flexShrink: 0 } },
213 el('div', { style: { width: '12px', height: '12px', borderRadius: '50%', background: a.versionBadgeBg, flexShrink: 0, marginTop: '3px' } }),
214 el('div', { className: 'bkbg-changelog-line', style: { flex: 1, width: '2px', background: a.connectorColor, minHeight: '40px' } })
215 ),
216 el('div', { className: 'bkbg-changelog-content', style: Object.assign({ flex: 1, paddingBottom: isTimeline ? '12px' : '0' }, isCard ? { background: '#fff', border: '1px solid #e5e7eb', borderRadius: '10px', padding: '20px' } : {}) },
217 el('div', { style: { display: 'flex', alignItems: 'center', gap: '10px', flexWrap: 'wrap', marginBottom: '4px' } },
218 el('span', { className: 'bkbg-changelog-version', style: { color: a.versionColor } }, 'v' + entry.version),
219 entry.badge && a.showBadge && el('span', { style: { display: 'inline-block', padding: '2px 8px', background: a.versionBadgeBg + '22', color: a.versionBadgeBg, borderRadius: '4px', fontSize: '11px', fontWeight: 700 } }, entry.badge),
220 a.showDate && entry.date && el('span', { style: { fontSize: a.dateSize + 'px', color: a.dateColor } }, entry.date)
221 ),
222 el('ul', { className: 'bkbg-changelog-items', style: { listStyle: 'none', padding: 0, margin: '10px 0 0', display: 'flex', flexDirection: 'column', gap: '6px' } },
223 entry.items.map(function (item) {
224 var catColor = getCategoryColor(item.category, a);
225 return el('li', { key: item.id, className: 'bkbg-changelog-item', style: { display: 'flex', alignItems: 'flex-start', gap: '8px', color: a.itemColor } },
226 el('span', { className: 'bkbg-changelog-badge bkbg-changelog-badge--' + item.category, style: { display: 'inline-block', padding: '2px 8px', background: catColor + '22', color: catColor, borderRadius: '4px', fontSize: '10px', fontWeight: 700, whiteSpace: 'nowrap', flexShrink: 0 } }, CATEGORY_LABELS[item.category] || item.category),
227 el('span', null, item.text)
228 );
229 })
230 )
231 )
232 );
233 })
234 )
235 )
236 );
237
238 function getCategoryColor(cat, a) {
239 if (cat === 'new') return a.newColor;
240 if (cat === 'improved') return a.improvedColor;
241 if (cat === 'fixed') return a.fixedColor;
242 if (cat === 'deprecated') return a.deprecatedColor;
243 return a.removedColor;
244 }
245 }
246 }],
247
248 save: function (props) {
249 var a = props.attributes;
250 var blockProps = wp.blockEditor.useBlockProps.save({ className: 'bkbg-changelog-wrap' });
251
252 return el('div', Object.assign({}, blockProps, { style: Object.assign({ paddingTop: a.paddingTop + 'px', paddingBottom: a.paddingBottom + 'px', backgroundColor: a.bgColor || undefined }, _tv(a.typoTitle, '--bkbg-cl-tt-'), _tv(a.typoVersion, '--bkbg-cl-v-'), _tv(a.typoItem, '--bkbg-cl-i-'), _tv(a.typoDate, '--bkbg-cl-d-'), _tv(a.typoBadge, '--bkbg-cl-bg-')) }),
253 el('div', { style: { maxWidth: a.maxWidth + 'px', margin: '0 auto' } },
254 a.showTitle && a.sectionTitle && el('h2', { className: 'bkbg-changelog-title', style: { marginBottom: '40px' } }, a.sectionTitle),
255 el('div', { className: 'bkbg-changelog-list bkbg-changelog-list--' + a.layout, style: a.layout === 'cards' ? { display: 'grid', gridTemplateColumns: 'repeat(auto-fill, minmax(300px, 1fr))', gap: '20px' } : {} },
256 a.entries.map(function (entry) {
257 var isTimeline = a.layout === 'timeline';
258 var isCard = a.layout === 'cards';
259 return el('div', { key: entry.id, className: 'bkbg-changelog-entry bkbg-changelog-entry--' + a.layout, style: { display: 'flex', gap: '24px', position: 'relative', marginBottom: isCard ? '0' : '36px' } },
260 isTimeline && el('div', { className: 'bkbg-changelog-connector', style: { display: 'flex', flexDirection: 'column', alignItems: 'center', flexShrink: 0 } },
261 el('div', { style: { width: '12px', height: '12px', borderRadius: '50%', background: a.versionBadgeBg, flexShrink: 0, marginTop: '3px' } }),
262 el('div', { className: 'bkbg-changelog-line', style: { flex: 1, width: '2px', background: a.connectorColor, minHeight: '40px' } })
263 ),
264 el('div', { className: 'bkbg-changelog-content', style: Object.assign({ flex: 1, paddingBottom: isTimeline ? '12px' : '0' }, isCard ? { background: '#fff', border: '1px solid #e5e7eb', borderRadius: '10px', padding: '20px' } : {}) },
265 el('div', { style: { display: 'flex', alignItems: 'center', gap: '10px', flexWrap: 'wrap', marginBottom: '4px' } },
266 el('span', { className: 'bkbg-changelog-version', style: { color: a.versionColor } }, 'v' + entry.version),
267 entry.badge && a.showBadge && el('span', { className: 'bkbg-changelog-badge', style: { display: 'inline-block', padding: '2px 8px', background: a.versionBadgeBg + '22', color: a.versionBadgeBg, borderRadius: '4px', whiteSpace: 'nowrap' } }, entry.badge),
268 a.showDate && entry.date && el('span', { className: 'bkbg-changelog-date', style: { color: a.dateColor } }, entry.date)
269 ),
270 el('ul', { className: 'bkbg-changelog-items', style: { listStyle: 'none', padding: 0, margin: '10px 0 0', display: 'flex', flexDirection: 'column', gap: '6px' } },
271 entry.items.map(function (item) {
272 var catColor = getCategoryColor(item.category, a);
273 return el('li', { key: item.id, className: 'bkbg-changelog-item', style: { display: 'flex', alignItems: 'flex-start', gap: '8px', color: a.itemColor } },
274 el('span', { className: 'bkbg-changelog-badge bkbg-changelog-badge--' + item.category, style: { display: 'inline-block', padding: '2px 8px', background: catColor + '22', color: catColor, borderRadius: '4px', whiteSpace: 'nowrap', flexShrink: 0 } }, CATEGORY_LABELS[item.category] || item.category),
275 el('span', null, item.text)
276 );
277 })
278 )
279 )
280 );
281 })
282 )
283 )
284 );
285
286 function getCategoryColor(cat, a) {
287 if (cat === 'new') return a.newColor;
288 if (cat === 'improved') return a.improvedColor;
289 if (cat === 'fixed') return a.fixedColor;
290 if (cat === 'deprecated') return a.deprecatedColor;
291 return a.removedColor;
292 }
293 }
294 });
295 }());
296