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

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

130 lines 7.9 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 RichText = wp.blockEditor.RichText;
10 var PanelBody = wp.components.PanelBody;
11 var RangeControl = wp.components.RangeControl;
12 var ToggleControl = wp.components.ToggleControl;
13 var SelectControl = wp.components.SelectControl;
14
15 function getTypographyControl() { return (window.bkbgTypographyControl || function () { return null; }); }
16 function _tv() { var fn = window.bkbgTypoCssVars; return fn ? fn.apply(null, arguments) : {}; }
17
18 var TAB_LABELS = { html: 'HTML', css: 'CSS', js: 'JS' };
19 var TAB_COLORS = { html: '#e34c26', css: '#264de4', js: '#f0db4f' };
20
21 function EditorPreview(props) {
22 var a = props.attributes;
23 var setAttributes = props.setAttributes;
24 var blockProps = useBlockProps({ style: Object.assign({ background: a.sectionBg || '#f8fafc', padding: '28px 20px' }, _tv(a.typoTitle, '--bkbg-cpg-tt'), _tv(a.typoSubtitle, '--bkbg-cpg-st')) });
25
26 // Mini code preview pane
27 function CodePanel(lang, code, color) {
28 return el('div', { style: { flex: 1, minWidth: 0, border: '1px solid #e5e7eb', borderRadius: 8, overflow: 'hidden', display: 'flex', flexDirection: 'column' } },
29 el('div', { style: { background: color, color: lang === 'js' ? '#1e1b4b' : '#fff', padding: '4px 12px', fontSize: 12, fontWeight: 700, letterSpacing: 1 } }, TAB_LABELS[lang]),
30 el('div', { style: {
31 background: a.editorBg, color: a.editorText, padding: 10, fontSize: 11,
32 fontFamily: "'Courier New', monospace", lineHeight: 1.6, overflow: 'hidden',
33 height: a.editorHeight, boxSizing: 'border-box', whiteSpace: 'pre', overflowX: 'auto'
34 } }, code)
35 );
36 }
37
38 var panels = el('div', { style: { display: 'flex', gap: 8, marginBottom: 8 } },
39 CodePanel('html', a.defaultHtml, TAB_COLORS.html),
40 CodePanel('css', a.defaultCss, TAB_COLORS.css),
41 CodePanel('js', a.defaultJs, TAB_COLORS.js)
42 );
43
44 var previewSection = el('div', { style: { border: '1px solid #e5e7eb', borderRadius: 8, overflow: 'hidden' } },
45 el('div', { style: { background: a.headerBg, color: '#e2e8f0', padding: '6px 12px', fontSize: 12, fontWeight: 600, display: 'flex', alignItems: 'center', gap: 8 } },
46 el('span', { style: { width: 10, height: 10, borderRadius: '50%', background: '#22c55e', display: 'inline-block' } }),
47 'Preview'
48 ),
49 el('div', { style: { background: a.previewBg, height: a.previewHeight, display: 'flex', alignItems: 'center', justifyContent: 'center', color: '#9ca3af', fontSize: 14, fontStyle: 'italic' } },
50 '↑ Live preview appears here on the frontend'
51 )
52 );
53
54 return el(Fragment, null,
55 el(InspectorControls, null,
56 el(PanelBody, { title: __('Content', 'blockenberg'), initialOpen: true },
57 ),
58 el(PanelBody, { title: __('Playground Settings', 'blockenberg'), initialOpen: false },
59 el(SelectControl, {
60 label: __('Layout', 'blockenberg'), value: a.layout,
61 options: [
62 { label: 'Horizontal (editors side by side)', value: 'horizontal' },
63 { label: 'Vertical (stacked)', value: 'vertical' },
64 { label: 'Tabbed (one editor at a time)', value: 'tabbed' }
65 ],
66 onChange: function (v) { setAttributes({ layout: v }); }
67 }),
68 el(RangeControl, {
69 label: __('Editor Height (px)', 'blockenberg'), value: a.editorHeight, min: 80, max: 500,
70 onChange: function (v) { setAttributes({ editorHeight: v }); }
71 }),
72 el(RangeControl, {
73 label: __('Preview Height (px)', 'blockenberg'), value: a.previewHeight, min: 100, max: 800,
74 onChange: function (v) { setAttributes({ previewHeight: v }); }
75 }),
76 el(ToggleControl, {
77 __nextHasNoMarginBottom: true, label: __('Auto-run on code change', 'blockenberg'),
78 checked: a.autoRun, onChange: function (v) { setAttributes({ autoRun: v }); }
79 })
80 ),
81
82 el( PanelBody, { title: __( 'Typography', 'blockenberg' ), initialOpen: false },
83 el(getTypographyControl(), { label: __('Title', 'blockenberg'), value: a.typoTitle, onChange: function (v) { setAttributes({ typoTitle: v }); } }),
84 el(getTypographyControl(), { label: __('Subtitle', 'blockenberg'), value: a.typoSubtitle, onChange: function (v) { setAttributes({ typoSubtitle: v }); } })
85 ),
86 el(PanelColorSettings, {
87 title: __('Colors', 'blockenberg'), initialOpen: false,
88 colorSettings: [
89 { label: __('Accent', 'blockenberg'), value: a.accentColor, onChange: function (v) { setAttributes({ accentColor: v || '#6366f1' }); } },
90 { label: __('Editor Background', 'blockenberg'), value: a.editorBg, onChange: function (v) { setAttributes({ editorBg: v || '#1e1b4b' }); } },
91 { label: __('Editor Text', 'blockenberg'), value: a.editorText, onChange: function (v) { setAttributes({ editorText: v || '#e2e8f0' }); } },
92 { label: __('Header Bar', 'blockenberg'), value: a.headerBg, onChange: function (v) { setAttributes({ headerBg: v || '#312e81' }); } },
93 { label: __('Preview Background', 'blockenberg'), value: a.previewBg, onChange: function (v) { setAttributes({ previewBg: v || '#ffffff' }); } },
94 { label: __('Section Background', 'blockenberg'), value: a.sectionBg, onChange: function (v) { setAttributes({ sectionBg: v || '#f8fafc' }); } },
95 { label: __('Title Color', 'blockenberg'), value: a.titleColor, onChange: function (v) { setAttributes({ titleColor: v || '#1e1b4b' }); } }
96 ]
97 })
98 ),
99 el('div', blockProps,
100 el(RichText, {
101 tagName: 'h3', className: 'bkbg-cpg-title', value: a.title,
102 onChange: function (v) { setAttributes({ title: v }); },
103 placeholder: __('Code Playground', 'blockenberg'),
104 style: { color: a.titleColor, margin: '0 0 4px' }
105 }),
106 el(RichText, {
107 tagName: 'p', className: 'bkbg-cpg-subtitle', value: a.subtitle,
108 onChange: function (v) { setAttributes({ subtitle: v }); },
109 placeholder: __('Optional subtitle…', 'blockenberg'),
110 style: { color: a.titleColor + 'aa', margin: '0 0 16px' }
111 }),
112 el('div', { style: { opacity: 0.85 } }, panels, previewSection)
113 )
114 );
115 }
116
117 registerBlockType('blockenberg/code-playground', {
118 edit: EditorPreview,
119 save: function (props) {
120 var a = props.attributes;
121 return el('div', useBlockProps.save(),
122 el('div', { className: 'bkbg-cpg-app', 'data-opts': JSON.stringify(a) },
123 el(RichText.Content, { tagName: 'h3', className: 'bkbg-cpg-title', value: a.title }),
124 el(RichText.Content, { tagName: 'p', className: 'bkbg-cpg-subtitle', value: a.subtitle })
125 )
126 );
127 }
128 });
129 }() );
130