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

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

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