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

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

145 lines 9.4 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 useState = wp.element.useState;
4 var Fragment = wp.element.Fragment;
5 var registerBlockType = wp.blocks.registerBlockType;
6 var __ = wp.i18n.__;
7 var InspectorControls = wp.blockEditor.InspectorControls;
8 var PanelColorSettings = wp.blockEditor.PanelColorSettings;
9 var useBlockProps = wp.blockEditor.useBlockProps;
10 var PanelBody = wp.components.PanelBody;
11 var TextControl = wp.components.TextControl;
12 var TextareaControl = wp.components.TextareaControl;
13 var RangeControl = wp.components.RangeControl;
14 var ToggleControl = wp.components.ToggleControl;
15
16 var _tc, _tv;
17 function getTypoControl() { return _tc || (_tc = window.bkbgTypographyControl); }
18 function getTypoCssVars() { return _tv || (_tv = window.bkbgTypoCssVars); }
19
20 registerBlockType('blockenberg/markdown-preview', {
21 edit: function (props) {
22 var a = props.attributes;
23 var set = props.setAttributes;
24 var blockProps = useBlockProps((function () {
25 var tv = getTypoCssVars();
26 var s = {};
27 Object.assign(s, tv(a.titleTypo, '--bkbg-mdp-tt-'));
28 return { className: 'bkbg-mdp-root', style: s };
29 })());
30
31 var state = useState(0);
32 var tick = state[0], setTick = state[1];
33
34 function editorPreview() {
35 return el('div', {
36 style: {
37 background: a.sectionBg,
38 borderRadius: '10px',
39 overflow: 'hidden',
40 border: '1px solid ' + a.borderColor,
41 maxWidth: a.contentMaxWidth + 'px',
42 fontFamily: 'system-ui,sans-serif'
43 }
44 },
45 /* Toolbar */
46 a.showToolbar && el('div', {
47 style: { background: a.toolbarBg, padding: '8px 14px', display: 'flex', gap: '6px', flexWrap: 'wrap', alignItems: 'center' }
48 },
49 ['B', 'I', 'H', '', '{ }', '🔗', '', ''].map(function (t, i) {
50 return el('button', {
51 key: i,
52 style: { background: 'rgba(255,255,255,0.1)', color: a.toolbarColor, border: 'none', borderRadius: '5px', padding: '4px 9px', cursor: 'pointer', fontSize: '13px', fontWeight: 600 }
53 }, t);
54 }),
55 el('div', { style: { flex: 1 } }),
56 a.showCopyBtn && el('button', {
57 style: { background: a.accentColor, color: '#fff', border: 'none', borderRadius: '5px', padding: '4px 12px', cursor: 'pointer', fontSize: '12px' }
58 }, 'Copy Markdown')
59 ),
60
61 /* Split panes */
62 el('div', { style: { display: 'flex', height: a.editorHeight + 'px' } },
63 /* Editor pane */
64 el('div', { style: { flex: 1, background: a.editorBg, display: 'flex', flexDirection: 'column', borderRight: '1px solid rgba(255,255,255,0.08)' } },
65 el('div', { style: { padding: '6px 12px', fontSize: '11px', color: a.toolbarColor, borderBottom: '1px solid rgba(255,255,255,0.08)', background: a.toolbarBg } }, 'Markdown'),
66 el('textarea', {
67 value: a.defaultContent,
68 onChange: function (e) { set({ defaultContent: e.target.value }); },
69 style: { flex: 1, width: '100%', background: a.editorBg, color: a.editorColor, border: 'none', padding: '14px', fontFamily: '"Fira Mono","Consolas",monospace', fontSize: '13px', lineHeight: '1.6', resize: 'none', outline: 'none', boxSizing: 'border-box' }
70 })
71 ),
72 /* Preview pane */
73 el('div', { style: { flex: 1, background: a.previewBg, display: 'flex', flexDirection: 'column', overflow: 'hidden' } },
74 el('div', { style: { padding: '6px 12px', fontSize: '11px', color: '#6b7280', borderBottom: '1px solid ' + a.borderColor } }, 'Preview'),
75 el('div', {
76 className: 'bkbg-mdp-preview-pane',
77 style: { flex: 1, overflow: 'auto', padding: '14px', color: a.previewColor, fontSize: '14px', lineHeight: '1.7' },
78 dangerouslySetInnerHTML: { __html: '<em style="color:#9ca3af">Live preview will render here on the frontend…</em>' }
79 })
80 )
81 )
82 );
83 }
84
85 return el(Fragment, null,
86 el(InspectorControls, null,
87 el(PanelBody, { title: 'Content', initialOpen: true },
88 el(TextControl, { label: 'Title', value: a.title, onChange: function (v) { set({ title: v }); }, __nextHasNoMarginBottom: true }),
89 el('div', { style: { marginBottom: '16px' } }),
90 el(ToggleControl, { label: 'Show Title', checked: a.showTitle, onChange: function (v) { set({ showTitle: v }); }, __nextHasNoMarginBottom: true }),
91 el('div', { style: { marginBottom: '16px' } }),
92 el(TextareaControl, { label: 'Default Markdown Content', value: a.defaultContent, onChange: function (v) { set({ defaultContent: v }); }, rows: 6, __nextHasNoMarginBottom: true })
93 ),
94 el(PanelBody, { title: 'Features', initialOpen: false },
95 el(ToggleControl, { label: 'Show Toolbar', checked: a.showToolbar, onChange: function (v) { set({ showToolbar: v }); }, __nextHasNoMarginBottom: true }),
96 el(ToggleControl, { label: 'Show Word Count', checked: a.showWordCount, onChange: function (v) { set({ showWordCount: v }); }, __nextHasNoMarginBottom: true }),
97 el(ToggleControl, { label: 'Show Copy Buttons', checked: a.showCopyBtn, onChange: function (v) { set({ showCopyBtn: v }); }, __nextHasNoMarginBottom: true }),
98 el(ToggleControl, { label: 'Sync Scroll', checked: a.syncScroll, onChange: function (v) { set({ syncScroll: v }); }, __nextHasNoMarginBottom: true })
99 ),
100 el(PanelBody, { title: 'Layout', initialOpen: false },
101 el(RangeControl, { label: 'Editor Height (px)', value: a.editorHeight, min: 200, max: 800, step: 20, onChange: function (v) { set({ editorHeight: v }); }, __nextHasNoMarginBottom: true }),
102 el('div', { style: { marginBottom: '16px' } }),
103 el(RangeControl, { label: 'Max Width (px)', value: a.contentMaxWidth, min: 500, max: 1400, step: 20, onChange: function (v) { set({ contentMaxWidth: v }); }, __nextHasNoMarginBottom: true }),
104 el('div', { style: { marginBottom: '16px' } }),
105 ),
106
107 el( PanelBody, { title: __( 'Typography', 'blockenberg' ), initialOpen: false },
108 getTypoControl() && el(getTypoControl(), { label: 'Title', value: a.titleTypo || {}, onChange: function (v) { set({ titleTypo: v }); } })
109 ),
110 el(PanelColorSettings, {
111 title: 'Colors',
112 initialOpen: false,
113 colorSettings: [
114 { label: 'Accent Color', value: a.accentColor, onChange: function (v) { set({ accentColor: v || '#0ea5e9' }); } },
115 { label: 'Editor Background', value: a.editorBg, onChange: function (v) { set({ editorBg: v || '#1e293b' }); } },
116 { label: 'Editor Text', value: a.editorColor, onChange: function (v) { set({ editorColor: v || '#e2e8f0' }); } },
117 { label: 'Preview Background', value: a.previewBg, onChange: function (v) { set({ previewBg: v || '#ffffff' }); } },
118 { label: 'Preview Text', value: a.previewColor, onChange: function (v) { set({ previewColor: v || '#1f2937' }); } },
119 { label: 'Toolbar Background', value: a.toolbarBg, onChange: function (v) { set({ toolbarBg: v || '#0f172a' }); } },
120 { label: 'Section Background', value: a.sectionBg, onChange: function (v) { set({ sectionBg: v || '#f8fafc' }); } },
121 { label: 'Title Color', value: a.titleColor, onChange: function (v) { set({ titleColor: v || '#0f172a' }); } }
122 ]
123 })
124 ),
125 el('div', blockProps,
126 a.showTitle && el('div', { className: 'bkbg-mdp-title', style: { color: a.titleColor } }, a.title),
127 editorPreview()
128 )
129 );
130 },
131 save: function (props) {
132 var a = props.attributes;
133 var useBlockProps = wp.blockEditor.useBlockProps;
134 return el('div', useBlockProps.save((function () {
135 var tv = getTypoCssVars();
136 var s = {};
137 Object.assign(s, tv(a.titleTypo, '--bkbg-mdp-tt-'));
138 return { style: s };
139 })()),
140 el('div', { className: 'bkbg-mdp-app', 'data-opts': JSON.stringify(a) })
141 );
142 }
143 });
144 }() );
145