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

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

312 lines 19.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 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 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 Button = wp.components.Button;
15
16 // Resolve the shared components lazily without defining globals for each block.
17 function _tc(props, key, label) {
18 var Control = window.bkbgTypographyControl;
19 return Control ? el(Control, {
20 label: label,
21 value: props.attributes[key] || {},
22 onChange: function (value) { var update = {}; update[key] = value; props.setAttributes(update); }
23 }) : null;
24 }
25 function _tvf(typo, prefix) {
26 var cssVars = window.bkbgTypoCssVars;
27 return cssVars ? cssVars(typo || {}, prefix) : {};
28 }
29 function getTypoControl(props, attrName, label) { return _tc(props, attrName, label); }
30
31 var SEVERITY_OPTIONS = [
32 { label: 'Critical', value: 'critical' },
33 { label: 'High', value: 'high' },
34 { label: 'Medium', value: 'medium' },
35 { label: 'Low', value: 'low' }
36 ];
37
38 function severityLabel(s) {
39 if (s === 'critical') return '🔴 Critical';
40 if (s === 'high') return '🟠 High';
41 if (s === 'medium') return '🟡 Medium';
42 return '🟢 Low';
43 }
44
45 function getSevStyle(s, a) {
46 if (s === 'critical') return { background: a.criticalBg, color: a.criticalColor };
47 if (s === 'high') return { background: a.highBg, color: a.highColor };
48 if (s === 'medium') return { background: a.mediumBg, color: a.mediumColor };
49 return { background: a.lowBg, color: a.lowColor };
50 }
51
52 /* ── ES5-safe update helpers ─────────────────────────── */
53 function updateIssue(issues, idx, field, val) {
54 return issues.map(function (iss, i) {
55 if (i !== idx) return iss;
56 var u = {}; u[field] = val;
57 return Object.assign({}, iss, u);
58 });
59 }
60
61 function addIssue(issues) {
62 return issues.concat([{
63 problem: 'New Issue',
64 cause: 'Root cause description',
65 solution: 'Step-by-step solution to resolve this issue.',
66 severity: 'medium'
67 }]);
68 }
69
70 function removeIssue(issues, idx) {
71 return issues.filter(function (_, i) { return i !== idx; });
72 }
73
74 registerBlockType('blockenberg/troubleshooting-guide', {
75 edit: function (props) {
76 var a = props.attributes;
77 var set = props.setAttributes;
78 var blockProps = (function () {
79 var s = {};
80 Object.assign(s, _tvf(a.titleTypo, '--bktsg-tt-'), _tvf(a.problemTypo, '--bktsg-pt-'), _tvf(a.bodyTypo, '--bktsg-bt-'));
81 return useBlockProps({ className: 'bkbg-tg-editor', style: Object.keys(s).length ? s : undefined });
82 })();
83
84 /* ── Preview rendering ───────────────────────── */
85 function renderPreview() {
86 return el('div', {
87 className: 'bkbg-tg-block',
88 style: {
89 background: a.bgColor || undefined,
90 boxSizing: 'border-box'
91 }
92 },
93 /* Header */
94 (a.showTitle || a.showSubtitle) && el('div', {
95 className: 'bkbg-tg-header',
96 style: { marginBottom: '20px' }
97 },
98 a.showTitle && el('h3', {
99 className: 'bkbg-tg-title',
100 style: { color: a.titleColor, margin: '0 0 8px' }
101 }, a.blockTitle),
102 a.showSubtitle && a.blockSubtitle && el('p', {
103 className: 'bkbg-tg-subtitle',
104 style: { fontSize: '15px', color: a.subtitleColor, margin: 0 }
105 }, a.blockSubtitle)
106 ),
107 /* Search bar placeholder */
108 a.enableSearch && el('div', {
109 className: 'bkbg-tg-search-wrap',
110 style: { marginBottom: a.gap + 'px' }
111 },
112 el('input', {
113 type: 'text',
114 placeholder: a.searchPlaceholder,
115 className: 'bkbg-tg-search',
116 readOnly: true,
117 style: {
118 width: '100%', padding: '10px 14px 10px 38px',
119 border: '1px solid ' + a.borderColor,
120 borderRadius: a.borderRadius + 'px',
121 fontSize: '14px', boxSizing: 'border-box'
122 }
123 })
124 ),
125 /* Issues */
126 el('div', {
127 className: 'bkbg-tg-list',
128 style: {
129 display: 'flex', flexDirection: 'column', gap: a.gap + 'px'
130 }
131 },
132 a.issues.map(function (iss, idx) {
133 var sevStyle = getSevStyle(iss.severity, a);
134 var cardStyle = {
135 background: a.cardBg,
136 border: '1px solid ' + a.borderColor,
137 borderRadius: a.borderRadius + 'px',
138 overflow: 'hidden'
139 };
140 if (a.style === 'left-accent') {
141 cardStyle.borderLeft = '4px solid ' + sevStyle.color;
142 }
143 return el('div', { className: 'bkbg-tg-issue', key: idx, style: cardStyle },
144 /* Problem row */
145 el('div', {
146 className: 'bkbg-tg-problem-row',
147 style: {
148 display: 'flex', alignItems: 'center', gap: '10px',
149 padding: '14px 18px',
150 borderBottom: (a.showCause || true) ? '1px solid ' + a.borderColor : 'none'
151 }
152 },
153 a.showNumbers && el('span', {
154 style: {
155 minWidth: '26px', height: '26px', borderRadius: '50%',
156 background: a.borderColor, color: a.problemColor,
157 display: 'flex', alignItems: 'center', justifyContent: 'center',
158 fontSize: '12px', fontWeight: 700, flexShrink: 0
159 }
160 }, String(idx + 1)),
161 el('span', {
162 className: 'bkbg-tg-problem-text',
163 style: {
164 color: a.problemColor, flex: 1
165 }
166 }, iss.problem),
167 a.showSeverity && el('span', {
168 className: 'bkbg-tg-severity',
169 style: Object.assign({ padding: '3px 10px', borderRadius: '100px', fontSize: '11px', fontWeight: 600, whiteSpace: 'nowrap' }, sevStyle)
170 }, severityLabel(iss.severity))
171 ),
172 /* Cause */
173 a.showCause && iss.cause && el('div', {
174 style: { padding: '10px 18px', borderBottom: '1px solid ' + a.borderColor }
175 },
176 el('span', { style: { fontSize: '11px', fontWeight: 700, color: a.labelColor, textTransform: 'uppercase', letterSpacing: '.05em', display: 'block', marginBottom: '4px' } }, 'Cause'),
177 el('span', { className: 'bkbg-tg-cause-text', style: { color: a.causeColor } }, iss.cause)
178 ),
179 /* Solution */
180 el('div', {
181 style: {
182 padding: '10px 18px',
183 background: a.solutionBg,
184 borderTop: '1px solid ' + a.solutionBorderColor
185 }
186 },
187 el('span', { style: { fontSize: '11px', fontWeight: 700, color: '#166534', textTransform: 'uppercase', letterSpacing: '.05em', display: 'block', marginBottom: '4px' } }, '✔ Solution'),
188 el('span', { className: 'bkbg-tg-solution-text', style: { color: a.solutionColor } }, iss.solution)
189 )
190 );
191 })
192 )
193 );
194 }
195
196 /* ── Inspector ───────────────────────────────── */
197 var inspector = el(InspectorControls, {},
198 /* Title & Subtitle */
199 el(PanelBody, { title: 'Title & Subtitle', initialOpen: true },
200 el(ToggleControl, { __nextHasNoMarginBottom: true, label: 'Show Title', checked: a.showTitle, onChange: function (v) { set({ showTitle: v }); } }),
201 a.showTitle && el(TextControl, { __nextHasNoMarginBottom: true, label: 'Title', value: a.blockTitle, onChange: function (v) { set({ blockTitle: v }); } }),
202 el(ToggleControl, { __nextHasNoMarginBottom: true, label: 'Show Subtitle', checked: a.showSubtitle, onChange: function (v) { set({ showSubtitle: v }); } }),
203 a.showSubtitle && el(TextControl, { __nextHasNoMarginBottom: true, label: 'Subtitle', value: a.blockSubtitle, onChange: function (v) { set({ blockSubtitle: v }); } })
204 ),
205 /* Issues Manager */
206 el(PanelBody, { title: 'Issues (' + a.issues.length + ')', initialOpen: true },
207 a.issues.map(function (iss, idx) {
208 return el('div', {
209 key: idx,
210 style: { border: '1px solid #e2e8f0', borderRadius: 8, padding: 12, marginBottom: 10, background: '#f8fafc' }
211 },
212 el('div', { style: { display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: 8 } },
213 el('strong', { style: { fontSize: 12 } }, '#' + (idx + 1) + ' ' + (iss.problem.slice(0, 30) || 'Issue')),
214 el(Button, {
215 isSmall: true, isDestructive: true,
216 onClick: function () { set({ issues: removeIssue(a.issues, idx) }); }
217 }, '✕')
218 ),
219 el(TextControl, { __nextHasNoMarginBottom: true, label: 'Problem', value: iss.problem, onChange: function (v) { set({ issues: updateIssue(a.issues, idx, 'problem', v) }); } }),
220 el(TextControl, { __nextHasNoMarginBottom: true, label: 'Cause', value: iss.cause, onChange: function (v) { set({ issues: updateIssue(a.issues, idx, 'cause', v) }); } }),
221 el('div', { style: { marginBottom: 8 } },
222 el('label', { style: { fontSize: 11, fontWeight: 600, display: 'block', marginBottom: 4 } }, 'Solution'),
223 el('textarea', {
224 value: iss.solution, rows: 3,
225 style: { width: '100%', fontSize: 12, padding: '6px 8px', border: '1px solid #ddd', borderRadius: 4, boxSizing: 'border-box' },
226 onChange: function (e) { set({ issues: updateIssue(a.issues, idx, 'solution', e.target.value) }); }
227 })
228 ),
229 el(SelectControl, {
230 __nextHasNoMarginBottom: true, label: 'Severity',
231 value: iss.severity, options: SEVERITY_OPTIONS,
232 onChange: function (v) { set({ issues: updateIssue(a.issues, idx, 'severity', v) }); }
233 })
234 );
235 }),
236 el(Button, {
237 variant: 'secondary', style: { width: '100%', justifyContent: 'center', marginTop: 4 },
238 onClick: function () { set({ issues: addIssue(a.issues) }); }
239 }, '+ Add Issue')
240 ),
241 /* Display */
242 el(PanelBody, { title: 'Display', initialOpen: false },
243 el(SelectControl, { __nextHasNoMarginBottom: true, label: 'Layout', value: a.layout, options: [{ label: 'Cards', value: 'cards' }, { label: 'Compact List', value: 'compact' }], onChange: function (v) { set({ layout: v }); } }),
244 el(SelectControl, { __nextHasNoMarginBottom: true, label: 'Style', value: a.style, options: [{ label: 'Bordered', value: 'bordered' }, { label: 'Left Accent', value: 'left-accent' }, { label: 'Flat', value: 'flat' }], onChange: function (v) { set({ style: v }); } }),
245 el(ToggleControl, { __nextHasNoMarginBottom: true, label: 'Show Cause Column', checked: a.showCause, onChange: function (v) { set({ showCause: v }); } }),
246 el(ToggleControl, { __nextHasNoMarginBottom: true, label: 'Show Severity Badges', checked: a.showSeverity, onChange: function (v) { set({ showSeverity: v }); } }),
247 el(ToggleControl, { __nextHasNoMarginBottom: true, label: 'Show Numbers', checked: a.showNumbers, onChange: function (v) { set({ showNumbers: v }); } }),
248 el(ToggleControl, { __nextHasNoMarginBottom: true, label: 'Search Bar', checked: a.enableSearch, onChange: function (v) { set({ enableSearch: v }); } }),
249 a.enableSearch && el(TextControl, { __nextHasNoMarginBottom: true, label: 'Search Placeholder', value: a.searchPlaceholder, onChange: function (v) { set({ searchPlaceholder: v }); } }),
250 el(ToggleControl, { __nextHasNoMarginBottom: true, label: 'Collapsible Issues', checked: a.collapsible, onChange: function (v) { set({ collapsible: v }); } })
251 ),
252 /* Typography */
253 el(PanelBody, { title: 'Typography', initialOpen: false },
254 getTypoControl(props, 'titleTypo', __('Title', 'blockenberg')),
255 getTypoControl(props, 'problemTypo', __('Problem', 'blockenberg')),
256 getTypoControl(props, 'bodyTypo', __('Body', 'blockenberg'))
257 ),
258 /* Spacing */
259 el(PanelBody, { title: 'Spacing', initialOpen: false },
260 el(RangeControl, { __nextHasNoMarginBottom: true, label: 'Gap Between Issues', value: a.gap, min: 4, max: 40, onChange: function (v) { set({ gap: v }); } }),
261 el(RangeControl, { __nextHasNoMarginBottom: true, label: 'Border Radius', value: a.borderRadius, min: 0, max: 24, onChange: function (v) { set({ borderRadius: v }); } })
262 ),
263 /* Colors */
264 el(PanelColorSettings, {
265 title: 'Colors', initialOpen: false,
266 colorSettings: [
267 { label: 'Block Background', value: a.bgColor, onChange: function (v) { set({ bgColor: v || '' }); } },
268 { label: 'Card Background', value: a.cardBg, onChange: function (v) { set({ cardBg: v || '#ffffff' }); } },
269 { label: 'Border Color', value: a.borderColor, onChange: function (v) { set({ borderColor: v || '#e2e8f0' }); } },
270 { label: 'Title Color', value: a.titleColor, onChange: function (v) { set({ titleColor: v || '#0f172a' }); } },
271 { label: 'Problem Color', value: a.problemColor, onChange: function (v) { set({ problemColor: v || '#1e293b' }); } },
272 { label: 'Cause Color', value: a.causeColor, onChange: function (v) { set({ causeColor: v || '#475569' }); } },
273 { label: 'Solution Text Color', value: a.solutionColor, onChange: function (v) { set({ solutionColor: v || '#374151' }); } },
274 { label: 'Solution Background', value: a.solutionBg, onChange: function (v) { set({ solutionBg: v || '#f0fdf4' }); } }
275 ]
276 }),
277 el(PanelColorSettings, {
278 title: 'Severity Colors', initialOpen: false,
279 colorSettings: [
280 { label: 'Critical Background', value: a.criticalBg, onChange: function (v) { set({ criticalBg: v || '#fee2e2' }); } },
281 { label: 'Critical Text', value: a.criticalColor, onChange: function (v) { set({ criticalColor: v || '#991b1b' }); } },
282 { label: 'High Background', value: a.highBg, onChange: function (v) { set({ highBg: v || '#ffedd5' }); } },
283 { label: 'High Text', value: a.highColor, onChange: function (v) { set({ highColor: v || '#9a3412' }); } },
284 { label: 'Medium Background', value: a.mediumBg, onChange: function (v) { set({ mediumBg: v || '#fef9c3' }); } },
285 { label: 'Medium Text', value: a.mediumColor, onChange: function (v) { set({ mediumColor: v || '#854d0e' }); } },
286 { label: 'Low Background', value: a.lowBg, onChange: function (v) { set({ lowBg: v || '#f0fdf4' }); } },
287 { label: 'Low Text', value: a.lowColor, onChange: function (v) { set({ lowColor: v || '#166534' }); } }
288 ]
289 })
290 );
291
292 return el(Fragment, {}, inspector, el('div', blockProps, renderPreview()));
293 },
294
295 save: function (props) {
296 var useBlockProps = wp.blockEditor.useBlockProps;
297 var a = props.attributes;
298 var bp = (function () {
299 var tv = Object.assign({}, _tvf(a.titleTypo, '--bktsg-tt-'), _tvf(a.problemTypo, '--bktsg-pt-'), _tvf(a.bodyTypo, '--bktsg-bt-'));
300 var parts = []; Object.keys(tv).forEach(function (k) { parts.push(k + ':' + tv[k]); });
301 return useBlockProps.save(parts.length ? { style: parts.join(';') } : {});
302 })();
303 return el('div', bp,
304 el('div', {
305 className: 'bkbg-troubleshooting-guide-app',
306 'data-opts': JSON.stringify(props.attributes)
307 })
308 );
309 }
310 });
311 }() );
312