PluginProbe
Blockenberg — 600+ Advanced Gutenberg Blocks & AI Agent for WordPress Block Editor / 2.0.11
Blockenberg — 600+ Advanced Gutenberg Blocks & AI Agent for WordPress Block Editor v2.0.11
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 / tutorial-card / index.js

index.js in Blockenberg — 600+ Advanced Gutenberg Blocks & AI Agent for WordPress Block Editor 2.0.11, at blocks/tutorial-card/index.js

324 lines 25.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 registerBlockType = wp.blocks.registerBlockType;
5 var InspectorControls = wp.blockEditor.InspectorControls;
6 var useBlockProps = wp.blockEditor.useBlockProps;
7 var PanelBody = wp.components.PanelBody;
8 var PanelColorSettings = wp.blockEditor.PanelColorSettings;
9 var ToggleControl = wp.components.ToggleControl;
10 var RangeControl = wp.components.RangeControl;
11 var SelectControl = wp.components.SelectControl;
12 var TextControl = wp.components.TextControl;
13 var TextareaControl = wp.components.TextareaControl;
14 var Button = wp.components.Button;
15
16 var _tc, _tvf;
17 Object.defineProperty(window, '_tc', { get: function () { return _tc || (_tc = window.bkbgTypographyControl); } });
18 Object.defineProperty(window, '_tvf', { get: function () { return _tvf || (_tvf = window.bkbgTypoCssVars); } });
19 function getTypoControl(p, key, label) { return _tc ? _tc(p, key, label) : null; }
20 function getTypoCssVars(a) {
21 if (!_tvf) return {};
22 var v = {};
23 Object.assign(v, _tvf(a.titleTypo || {}, '--bktc-tt-'));
24 Object.assign(v, _tvf(a.bodyTypo || {}, '--bktc-bt-'));
25 return v;
26 }
27
28 // ── helpers ───────────────────────────────────────────────────
29 function upd(arr, idx, field, val) {
30 return arr.map(function (e, i) {
31 if (i !== idx) return e;
32 var u = {}; u[field] = val;
33 return Object.assign({}, e, u);
34 });
35 }
36
37 var difficultyOptions = [
38 { label: '🟢 Beginner', value: 'beginner' },
39 { label: '🟡 Intermediate', value: 'intermediate' },
40 { label: '🔴 Advanced', value: 'advanced' }
41 ];
42
43 function difficultyInfo(d) {
44 if (d === 'beginner') return { label: '🟢 Beginner', bg: '#dcfce7', color: '#14532d' };
45 if (d === 'advanced') return { label: '🔴 Advanced', bg: '#fee2e2', color: '#991b1b' };
46 return { label: '🟡 Intermediate', bg: '#fef9c3', color: '#854d0e' };
47 }
48
49 function sectionHead(label, a) {
50 return el('div', { style: { display: 'flex', alignItems: 'center', gap: 8, marginBottom: 12 } },
51 el('span', { style: { fontWeight: 700, fontSize: 11, textTransform: 'uppercase', letterSpacing: '0.07em', color: a.accentColor } }, label),
52 el('div', { style: { flex: 1, height: 1, background: a.borderColor } })
53 );
54 }
55
56 registerBlockType('blockenberg/tutorial-card', {
57 edit: function (props) {
58 var a = props.attributes;
59 var set = props.setAttributes;
60 var blockProps = useBlockProps((function () {
61 var _tv = getTypoCssVars(a);
62 var s = {};
63 Object.assign(s, _tv);
64 return { className: 'bkbg-tc-editor-wrap', style: s };
65 })());
66 var diff = difficultyInfo(a.difficulty);
67
68 // ── preview ───────────────────────────────────────────
69 var preview = el('div', { style: { border: '1px solid ' + a.borderColor, borderRadius: a.borderRadius + 'px', overflow: 'hidden', background: a.bgColor } },
70 // Header
71 el('div', { style: { background: a.headerBg, color: a.headerColor, padding: '20px 24px' } },
72 el('div', { style: { display: 'flex', flexWrap: 'wrap', gap: 6, alignItems: 'center', marginBottom: 10 } },
73 el('span', { style: { background: diff.bg, color: diff.color, padding: '3px 10px', borderRadius: 100, fontSize: (a.subtitleSize || 11), fontWeight: 700 } }, diff.label),
74 a.showDuration && a.duration && el('span', { style: { fontSize: 12, opacity: .8 } }, '' + a.duration),
75 a.showAuthor && a.author && el('span', { style: { fontSize: (a.authorSize || 12), opacity: .8 } }, '✍️ ' + a.author)
76 ),
77 el('h2', { className: 'bkbg-tc-title', style: { margin: '0 0 6px', color: a.headerColor, lineHeight: 1.25 } }, a.tutorialTitle),
78 a.subtitle && el('p', { className: 'bkbg-tc-subtitle', style: { margin: 0, opacity: .8, color: a.headerColor } }, a.subtitle),
79 a.showProgress && el('div', { style: { marginTop: 14 } },
80 el('div', { style: { display: 'flex', justifyContent: 'space-between', fontSize: 11, marginBottom: 4, opacity: .8 } },
81 el('span', null, 'Progress'),
82 el('span', null, a.completionRate + '%')
83 ),
84 el('div', { style: { background: 'rgba(255,255,255,.2)', borderRadius: 100, height: 6 } },
85 el('div', { style: { background: a.progressFill, borderRadius: 100, height: '100%', width: a.completionRate + '%' } })
86 )
87 )
88 ),
89 // Body
90 el('div', { style: { padding: '20px 24px' } },
91 // Outcomes
92 a.showOutcomes && a.outcomes.length > 0 && el('div', { style: { marginBottom: 18 } },
93 sectionHead(a.outcomesLabel || "What you'll learn", a),
94 el('ul', { style: { margin: 0, padding: 0, listStyle: 'none' } },
95 a.outcomes.map(function (item, i) {
96 return el('li', { key: i, style: { display: 'flex', gap: 8, alignItems: 'flex-start', marginBottom: 5 } },
97 el('span', { style: { background: a.outcomeBg, color: a.outcomeColor, borderRadius: '50%', width: 18, height: 18, display: 'flex', alignItems: 'center', justifyContent: 'center', fontSize: 10, fontWeight: 700, flexShrink: 0, marginTop: 2 } }, ''),
98 el('span', { className: 'bkbg-tc-body-text', style: { color: '#374151' } }, item.text)
99 );
100 })
101 )
102 ),
103 // Prerequisites & Materials row
104 (a.showPrerequisites || a.showMaterials) && el('div', { style: { display: 'flex', gap: 16, flexWrap: 'wrap', marginBottom: 18 } },
105 a.showPrerequisites && a.prerequisites.length > 0 && el('div', { style: { flex: '1 1 200px' } },
106 sectionHead(a.prerequisitesLabel || 'Prerequisites', a),
107 el('ul', { style: { margin: 0, padding: 0, listStyle: 'none' } },
108 a.prerequisites.map(function (item, i) {
109 return el('li', { key: i, style: { background: a.prerequisiteBg, color: a.prerequisiteColor, padding: '4px 10px', borderRadius: 6, marginBottom: 4 } }, '' + item.text);
110 })
111 )
112 ),
113 a.showMaterials && a.materials.length > 0 && el('div', { style: { flex: '1 1 200px' } },
114 sectionHead(a.materialsLabel || "What you'll need", a),
115 el('ul', { style: { margin: 0, padding: 0, listStyle: 'none' } },
116 a.materials.map(function (item, i) {
117 return el('li', { key: i, style: { background: a.materialBg, color: a.materialColor, padding: '4px 10px', borderRadius: 6, marginBottom: 4 } }, '' + item.text);
118 })
119 )
120 )
121 ),
122 // Steps
123 a.showSteps && a.steps.length > 0 && el('div', null,
124 sectionHead(a.stepsLabel || 'Steps', a),
125 a.steps.map(function (step, i) {
126 return el('div', { key: i, style: { display: 'flex', gap: 14, marginBottom: 16, paddingBottom: 16, borderBottom: i < a.steps.length - 1 ? '1px solid ' + a.stepBorderColor : 'none' } },
127 // Step number circle
128 el('div', { style: { background: a.stepNumberBg, color: a.stepNumberColor, width: 30, height: 30, borderRadius: '50%', display: 'flex', alignItems: 'center', justifyContent: 'center', fontWeight: 700, fontSize: 13, flexShrink: 0 } }, i + 1),
129 el('div', { style: { flex: 1 } },
130 el('div', { style: { display: 'flex', justifyContent: 'space-between', alignItems: 'baseline', gap: 8, marginBottom: 4 } },
131 el('strong', { className: 'bkbg-tc-step-title', style: { color: '#0f172a' } }, step.title || 'Step ' + (i + 1)),
132 a.showStepDurations && step.duration && el('span', { style: { fontSize: 11, color: '#6b7280', whiteSpace: 'nowrap' } }, '' + step.duration)
133 ),
134 el('p', { className: 'bkbg-tc-step-content', style: { margin: '0 0 8px', color: '#374151' } }, step.content),
135 a.showTips && step.tip && el('div', { style: { background: a.stepTipBg, color: a.stepTipColor, borderLeft: '3px solid ' + a.stepTipBorderColor, padding: '6px 10px', borderRadius: '0 6px 6px 0' } },
136 el('strong', null, '💡 Tip: '), step.tip
137 )
138 )
139 );
140 })
141 )
142 )
143 );
144
145 // ── Inspector ─────────────────────────────────────────
146 return el(Fragment, null,
147 el('div', blockProps, preview),
148 el(InspectorControls, null,
149 // Tutorial Info
150 el(PanelBody, { title: 'Tutorial Info', initialOpen: true },
151 el(TextControl, { label: 'Title', value: a.tutorialTitle, __nextHasNoMarginBottom: true, onChange: function (v) { set({ tutorialTitle: v }); } }),
152 el('div', { style: { marginTop: 8 } },
153 el(TextControl, { label: 'Subtitle', value: a.subtitle, __nextHasNoMarginBottom: true, onChange: function (v) { set({ subtitle: v }); } })
154 ),
155 el('div', { style: { marginTop: 8 } },
156 el(TextControl, { label: 'Author', value: a.author, __nextHasNoMarginBottom: true, onChange: function (v) { set({ author: v }); } })
157 ),
158 el('div', { style: { marginTop: 8 } },
159 el(TextControl, { label: 'Duration', value: a.duration, __nextHasNoMarginBottom: true, onChange: function (v) { set({ duration: v }); } })
160 ),
161 el('div', { style: { marginTop: 8 } },
162 el(SelectControl, { label: 'Difficulty', value: a.difficulty, options: difficultyOptions, __nextHasNoMarginBottom: true, onChange: function (v) { set({ difficulty: v }); } })
163 ),
164 el('div', { style: { marginTop: 8, display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 4 } },
165 el(ToggleControl, { label: 'Show Author', checked: a.showAuthor, __nextHasNoMarginBottom: true, onChange: function (v) { set({ showAuthor: v }); } }),
166 el(ToggleControl, { label: 'Show Duration', checked: a.showDuration, __nextHasNoMarginBottom: true, onChange: function (v) { set({ showDuration: v }); } }),
167 el(ToggleControl, { label: 'Show Progress', checked: a.showProgress, __nextHasNoMarginBottom: true, onChange: function (v) { set({ showProgress: v }); } })
168 ),
169 a.showProgress && el('div', { style: { marginTop: 8 } },
170 el(RangeControl, { label: 'Completion (%)', value: a.completionRate, min: 0, max: 100, __nextHasNoMarginBottom: true, onChange: function (v) { set({ completionRate: v }); } })
171 )
172 ),
173 // Learning Outcomes
174 el(PanelBody, { title: 'Learning Outcomes', initialOpen: false },
175 el(ToggleControl, { label: 'Show Outcomes', checked: a.showOutcomes, __nextHasNoMarginBottom: true, onChange: function (v) { set({ showOutcomes: v }); } }),
176 el('div', { style: { marginTop: 8 } },
177 el(TextControl, { label: 'Section Label', value: a.outcomesLabel, __nextHasNoMarginBottom: true, onChange: function (v) { set({ outcomesLabel: v }); } })
178 ),
179 a.outcomes.map(function (item, i) {
180 return el('div', { key: i, style: { display: 'flex', gap: 4, alignItems: 'center', marginTop: 8 } },
181 el('div', { style: { flex: 1 } },
182 el(TextControl, { value: item.text, __nextHasNoMarginBottom: true, onChange: function (v) { set({ outcomes: upd(a.outcomes, i, 'text', v) }); } })
183 ),
184 el(Button, { isDestructive: true, variant: 'link', style: { fontSize: 11 }, onClick: function () { set({ outcomes: a.outcomes.filter(function (_, j) { return j !== i; }) }); } }, '')
185 );
186 }),
187 el(Button, { variant: 'secondary', style: { marginTop: 8 }, onClick: function () { set({ outcomes: a.outcomes.concat([{ text: 'New learning outcome' }]) }); } }, '+ Add Outcome')
188 ),
189 // Prerequisites
190 el(PanelBody, { title: 'Prerequisites', initialOpen: false },
191 el(ToggleControl, { label: 'Show Prerequisites', checked: a.showPrerequisites, __nextHasNoMarginBottom: true, onChange: function (v) { set({ showPrerequisites: v }); } }),
192 el('div', { style: { marginTop: 8 } },
193 el(TextControl, { label: 'Section Label', value: a.prerequisitesLabel, __nextHasNoMarginBottom: true, onChange: function (v) { set({ prerequisitesLabel: v }); } })
194 ),
195 a.prerequisites.map(function (item, i) {
196 return el('div', { key: i, style: { display: 'flex', gap: 4, alignItems: 'center', marginTop: 8 } },
197 el('div', { style: { flex: 1 } },
198 el(TextControl, { value: item.text, __nextHasNoMarginBottom: true, onChange: function (v) { set({ prerequisites: upd(a.prerequisites, i, 'text', v) }); } })
199 ),
200 el(Button, { isDestructive: true, variant: 'link', style: { fontSize: 11 }, onClick: function () { set({ prerequisites: a.prerequisites.filter(function (_, j) { return j !== i; }) }); } }, '')
201 );
202 }),
203 el(Button, { variant: 'secondary', style: { marginTop: 8 }, onClick: function () { set({ prerequisites: a.prerequisites.concat([{ text: 'New prerequisite' }]) }); } }, '+ Add Prerequisite')
204 ),
205 // Materials
206 el(PanelBody, { title: 'Materials', initialOpen: false },
207 el(ToggleControl, { label: 'Show Materials', checked: a.showMaterials, __nextHasNoMarginBottom: true, onChange: function (v) { set({ showMaterials: v }); } }),
208 el('div', { style: { marginTop: 8 } },
209 el(TextControl, { label: 'Section Label', value: a.materialsLabel, __nextHasNoMarginBottom: true, onChange: function (v) { set({ materialsLabel: v }); } })
210 ),
211 a.materials.map(function (item, i) {
212 return el('div', { key: i, style: { display: 'flex', gap: 4, alignItems: 'center', marginTop: 8 } },
213 el('div', { style: { flex: 1 } },
214 el(TextControl, { value: item.text, __nextHasNoMarginBottom: true, onChange: function (v) { set({ materials: upd(a.materials, i, 'text', v) }); } })
215 ),
216 el(Button, { isDestructive: true, variant: 'link', style: { fontSize: 11 }, onClick: function () { set({ materials: a.materials.filter(function (_, j) { return j !== i; }) }); } }, '')
217 );
218 }),
219 el(Button, { variant: 'secondary', style: { marginTop: 8 }, onClick: function () { set({ materials: a.materials.concat([{ text: 'New material' }]) }); } }, '+ Add Material')
220 ),
221 // Steps
222 el(PanelBody, { title: 'Steps', initialOpen: false },
223 el(ToggleControl, { label: 'Show Steps', checked: a.showSteps, __nextHasNoMarginBottom: true, onChange: function (v) { set({ showSteps: v }); } }),
224 el('div', { style: { marginTop: 8, display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 4 } },
225 el(ToggleControl, { label: 'Show Durations', checked: a.showStepDurations, __nextHasNoMarginBottom: true, onChange: function (v) { set({ showStepDurations: v }); } }),
226 el(ToggleControl, { label: 'Show Tips', checked: a.showTips, __nextHasNoMarginBottom: true, onChange: function (v) { set({ showTips: v }); } })
227 ),
228 el('div', { style: { marginTop: 8 } },
229 el(TextControl, { label: 'Section Label', value: a.stepsLabel, __nextHasNoMarginBottom: true, onChange: function (v) { set({ stepsLabel: v }); } })
230 ),
231 a.steps.map(function (step, i) {
232 return el('div', { key: i, style: { marginTop: 14, padding: '12px', background: '#f8fafc', borderRadius: 6, border: '1px solid #e5e7eb' } },
233 el('div', { style: { display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: 8 } },
234 el('strong', { style: { fontSize: 12, color: '#374151' } }, 'Step ' + (i + 1)),
235 el(Button, { isDestructive: true, variant: 'link', style: { fontSize: 11 }, onClick: function () { set({ steps: a.steps.filter(function (_, j) { return j !== i; }) }); } }, '✕ Remove')
236 ),
237 el(TextControl, { label: 'Title', value: step.title, __nextHasNoMarginBottom: true, onChange: function (v) { set({ steps: upd(a.steps, i, 'title', v) }); } }),
238 el('div', { style: { marginTop: 8 } },
239 el(TextareaControl, { label: 'Content', value: step.content, rows: 3, __nextHasNoMarginBottom: true, onChange: function (v) { set({ steps: upd(a.steps, i, 'content', v) }); } })
240 ),
241 el('div', { style: { marginTop: 8, display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 8 } },
242 el(TextControl, { label: 'Duration', value: step.duration, __nextHasNoMarginBottom: true, onChange: function (v) { set({ steps: upd(a.steps, i, 'duration', v) }); } }),
243 el(TextControl, { label: 'Tip (optional)', value: step.tip, __nextHasNoMarginBottom: true, onChange: function (v) { set({ steps: upd(a.steps, i, 'tip', v) }); } })
244 )
245 );
246 }),
247 el(Button, { variant: 'secondary', style: { marginTop: 10 }, onClick: function () { set({ steps: a.steps.concat([{ title: 'New Step', content: 'Describe this step...', duration: '5 min', tip: '' }]) }); } }, '+ Add Step')
248 ),
249 // Typography
250 el(PanelBody, { title: 'Typography', initialOpen: false },
251 getTypoControl(props, 'titleTypo', 'Title'),
252 getTypoControl(props, 'bodyTypo', 'Body'),
253 el('div', { style: { marginTop: 8 } },
254 el(RangeControl, { label: 'Badge Size (px)', value: a.subtitleSize, min: 10, max: 24, __nextHasNoMarginBottom: true, onChange: function (v) { set({ subtitleSize: v }); } })
255 ),
256 el('div', { style: { marginTop: 8 } },
257 el(RangeControl, { label: 'Author Size (px)', value: a.authorSize, min: 8, max: 20, __nextHasNoMarginBottom: true, onChange: function (v) { set({ authorSize: v }); } })
258 )
259 ),
260 // Colors: Header & Structure
261 el(PanelBody, { title: 'Spacing', initialOpen: false },
262 el(RangeControl, { label: 'Border Radius (px)', value: a.borderRadius, min: 0, max: 24, __nextHasNoMarginBottom: true, onChange: function (v) { set({ borderRadius: v }); } })
263 ),
264 el(PanelColorSettings, {
265 title: 'Header & Structure Colors',
266 initialOpen: false,
267 colorSettings: [
268 { label: 'Block Background', value: a.bgColor, onChange: function (v) { set({ bgColor: v || '#ffffff' }); } },
269 { label: 'Border', value: a.borderColor, onChange: function (v) { set({ borderColor: v || '#e5e7eb' }); } },
270 { label: 'Header Background',value: a.headerBg, onChange: function (v) { set({ headerBg: v || '#0f172a' }); } },
271 { label: 'Header Text', value: a.headerColor, onChange: function (v) { set({ headerColor: v || '#ffffff' }); } },
272 { label: 'Accent Color', value: a.accentColor, onChange: function (v) { set({ accentColor: v || '#3b82f6' }); } },
273 { label: 'Progress Fill', value: a.progressFill, onChange: function (v) { set({ progressFill: v || '#3b82f6' }); } }
274 ]
275 }),
276 // Colors: Steps
277 el(PanelColorSettings, {
278 title: 'Step Colors',
279 initialOpen: false,
280 colorSettings: [
281 { label: 'Step Number BG', value: a.stepNumberBg, onChange: function (v) { set({ stepNumberBg: v || '#3b82f6' }); } },
282 { label: 'Step Number Text', value: a.stepNumberColor, onChange: function (v) { set({ stepNumberColor: v || '#ffffff' }); } },
283 { label: 'Step Divider', value: a.stepBorderColor, onChange: function (v) { set({ stepBorderColor: v || '#e5e7eb' }); } },
284 { label: 'Tip Background', value: a.stepTipBg, onChange: function (v) { set({ stepTipBg: v || '#fffbeb' }); } },
285 { label: 'Tip Text', value: a.stepTipColor, onChange: function (v) { set({ stepTipColor: v || '#92400e' }); } },
286 { label: 'Tip Border', value: a.stepTipBorderColor, onChange: function (v) { set({ stepTipBorderColor: v || '#fcd34d' }); } }
287 ]
288 }),
289 // Colors: Lists
290 el(PanelColorSettings, {
291 title: 'List Item Colors',
292 initialOpen: false,
293 colorSettings: [
294 { label: 'Prerequisite BG', value: a.prerequisiteBg, onChange: function (v) { set({ prerequisiteBg: v || '#f1f5f9' }); } },
295 { label: 'Prerequisite Text', value: a.prerequisiteColor, onChange: function (v) { set({ prerequisiteColor: v || '#334155' }); } },
296 { label: 'Material BG', value: a.materialBg, onChange: function (v) { set({ materialBg: v || '#f0f9ff' }); } },
297 { label: 'Material Text', value: a.materialColor, onChange: function (v) { set({ materialColor: v || '#0c4a6e' }); } },
298 { label: 'Outcome BG', value: a.outcomeBg, onChange: function (v) { set({ outcomeBg: v || '#f0fdf4' }); } },
299 { label: 'Outcome Text', value: a.outcomeColor, onChange: function (v) { set({ outcomeColor: v || '#14532d' }); } }
300 ]
301 })
302 )
303 );
304 },
305
306 save: function (props) {
307 var useBlockProps = wp.blockEditor.useBlockProps;
308 var a = props.attributes;
309 var bp = useBlockProps.save((function () {
310 var _tv = getTypoCssVars(a);
311 var s = {};
312 Object.assign(s, _tv);
313 return { style: s };
314 })());
315 return wp.element.createElement('div', bp,
316 wp.element.createElement('div', {
317 className: 'bkbg-tutorial-card-app',
318 'data-opts': JSON.stringify(a)
319 })
320 );
321 }
322 });
323 }() );
324