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 / base64-encoder / index.js

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

197 lines 11.1 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 RichText = wp.blockEditor.RichText;
11 var PanelBody = wp.components.PanelBody;
12 var RangeControl = wp.components.RangeControl;
13 var TextControl = wp.components.TextControl;
14 var ToggleControl = wp.components.ToggleControl;
15 var SelectControl = wp.components.SelectControl;
16
17 function getTypographyControl() {
18 return (typeof window.bkbgTypographyControl !== 'undefined') ? window.bkbgTypographyControl : null;
19 }
20 function getTypoCssVars() {
21 return (typeof window.bkbgTypoCssVars !== 'undefined') ? window.bkbgTypoCssVars : function() { return {}; };
22 }
23
24 function EditorPreview(props) {
25 var a = props.attributes;
26 var mode = a.defaultMode;
27
28 var _tv = getTypoCssVars();
29 var wrapStyle = {
30 background: a.sectionBg,
31 borderRadius: '14px',
32 padding: '32px 24px',
33 maxWidth: a.contentMaxWidth + 'px',
34 margin: '0 auto',
35 fontFamily: 'inherit',
36 boxSizing: 'border-box'
37 };
38 Object.assign(wrapStyle, _tv(a.titleTypo || {}, '--bkbg-b64-title-'));
39 Object.assign(wrapStyle, _tv(a.subtitleTypo || {}, '--bkbg-b64-sub-'));
40
41 var tabStyle = function(m) {
42 var active = m === mode;
43 return {
44 padding: '8px 22px', borderRadius: '8px',
45 border: '2px solid ' + (active ? a.accentColor : '#e5e7eb'),
46 background: active ? a.accentColor : a.cardBg,
47 color: active ? '#fff' : a.labelColor,
48 fontWeight: active ? '700' : '500', fontSize:'14px', cursor:'pointer'
49 };
50 };
51
52 var textareaStyle = {
53 width:'100%', boxSizing:'border-box', border:'1.5px solid #e5e7eb',
54 borderRadius:'10px', padding:'12px 14px', fontSize:'14px',
55 background: a.inputBg, color: a.labelColor,
56 resize:'vertical', minHeight:'100px', fontFamily:'inherit', marginBottom:'14px'
57 };
58
59 var outputStyle = {
60 background: a.outputBg,
61 borderRadius: '10px',
62 padding: '14px 16px',
63 fontFamily: 'monospace',
64 fontSize: '13px',
65 color: a.outputColor,
66 wordBreak: 'break-all',
67 lineHeight: '1.7',
68 minHeight: '70px'
69 };
70
71 return el('div', { style: wrapStyle },
72 el(RichText, { tagName:'h3', className:'bkbg-b64-title', value:a.title, onChange:function(v){ props.setAttributes({title:v}); },
73 style:{ color:a.titleColor, margin:'0 0 6px 0' }, placeholder:'Block title...' }),
74 el(RichText, { tagName:'p', className:'bkbg-b64-subtitle', value:a.subtitle, onChange:function(v){ props.setAttributes({subtitle:v}); },
75 style:{ color:a.subtitleColor, margin:'0 0 20px 0' }, placeholder:'Subtitle...' }),
76
77 // Mode tabs
78 el('div', { style:{ display:'flex', gap:'8px', marginBottom:'20px' } },
79 el('button', { style: tabStyle('encode') }, '⬆ Encode'),
80 el('button', { style: tabStyle('decode') }, '⬇ Decode')
81 ),
82
83 // Input
84 el('label', { style:{ display:'block', fontSize:'13px', fontWeight:'600', color:a.labelColor, marginBottom:'6px' } },
85 mode === 'encode' ? 'Plain Text' : 'Base64 String'),
86 el('textarea', { style: textareaStyle, readOnly:true, placeholder: mode==='encode' ? 'Enter text to encode…' : 'Enter Base64 to decode…' }),
87
88 // Options row
89 el('div', { style:{ display:'flex', gap:'12px', flexWrap:'wrap', marginBottom:'16px', alignItems:'center' } },
90 a.showUrlSafe && el('label', { style:{ display:'flex', alignItems:'center', gap:'6px', fontSize:'13px', color:a.labelColor, cursor:'pointer' } },
91 el('input', { type:'checkbox', readOnly:true, style:{ accentColor:a.accentColor } }),
92 'URL-safe Base64'
93 ),
94 a.showLineBreaks && el('label', { style:{ display:'flex', alignItems:'center', gap:'6px', fontSize:'13px', color:a.labelColor, cursor:'pointer' } },
95 el('input', { type:'checkbox', readOnly:true, defaultChecked:false, style:{ accentColor:a.accentColor } }),
96 'Add line breaks (76 chars)'
97 )
98 ),
99
100 // Output
101 el('div', { style:{ display:'flex', justifyContent:'space-between', alignItems:'center', marginBottom:'6px' } },
102 el('span', { style:{ fontSize:'13px', fontWeight:'600', color:a.labelColor } }, mode==='encode' ? 'Base64 Output' : 'Decoded Text'),
103 el('button', { style:{ background:'none', border:'1.5px solid '+a.accentColor, borderRadius:'7px', padding:'4px 12px', color:a.accentColor, fontSize:'12px', cursor:'pointer', fontWeight:'600' } }, '⧉ Copy')
104 ),
105 el('div', { style: outputStyle }, mode==='encode' ? 'Base64 output will appear here…' : 'Decoded text will appear here…'),
106
107 // Stats
108 a.showStats && el('div', { style:{ display:'flex', gap:'20px', marginTop:'14px', flexWrap:'wrap' } },
109 el('span', { style:{ fontSize:'12px', color:a.labelColor } }, 'Input length: 0 chars'),
110 el('span', { style:{ fontSize:'12px', color:a.labelColor } }, 'Output length: 0 chars'),
111 el('span', { style:{ fontSize:'12px', color:a.labelColor } }, 'Size ratio: —')
112 )
113 );
114 }
115
116 registerBlockType('blockenberg/base64-encoder', {
117 edit: function(props) {
118 var a = props.attributes;
119 var set = props.setAttributes;
120 var TC = getTypographyControl();
121
122 var colorSettings = [
123 { value:a.accentColor, onChange:function(v){ set({accentColor: v||'#0ea5e9'}); }, label:'Accent color' },
124 { value:a.sectionBg, onChange:function(v){ set({sectionBg: v||'#f0f9ff'}); }, label:'Section background' },
125 { value:a.cardBg, onChange:function(v){ set({cardBg: v||'#ffffff'}); }, label:'Card background' },
126 { value:a.inputBg, onChange:function(v){ set({inputBg: v||'#f8fafc'}); }, label:'Input background' },
127 { value:a.outputBg, onChange:function(v){ set({outputBg: v||'#0f172a'}); }, label:'Output background' },
128 { value:a.outputColor, onChange:function(v){ set({outputColor: v||'#7dd3fc'}); }, label:'Output text color' },
129 { value:a.titleColor, onChange:function(v){ set({titleColor: v||'#0c4a6e'}); }, label:'Title color' },
130 { value:a.subtitleColor, onChange:function(v){ set({subtitleColor: v||'#6b7280'}); }, label:'Subtitle color' },
131 { value:a.labelColor, onChange:function(v){ set({labelColor: v||'#374151'}); }, label:'Label color' }
132 ];
133
134 return el(Fragment, null,
135 el(InspectorControls, null,
136 el(PanelBody, { title:'Tool Settings', initialOpen:true },
137 el(SelectControl, {
138 label:'Default Mode', value:a.defaultMode,
139 options:[ {label:'Encode (Text → Base64)', value:'encode'}, {label:'Decode (Base64 → Text)', value:'decode'} ],
140 onChange:function(v){ set({defaultMode:v}); }
141 }),
142 el(TextControl, { label:'Prefilled Input', value:a.defaultInput, onChange:function(v){ set({defaultInput:v}); } })
143 ),
144 el(PanelBody, { title:'Display Options', initialOpen:false },
145 el(ToggleControl, { __nextHasNoMarginBottom:true, label:'Show URL-safe option', checked:a.showUrlSafe, onChange:function(v){ set({showUrlSafe: v}); } }),
146 el(ToggleControl, { __nextHasNoMarginBottom:true, label:'Show line-break option', checked:a.showLineBreaks, onChange:function(v){ set({showLineBreaks:v}); } }),
147 el(ToggleControl, { __nextHasNoMarginBottom:true, label:'Show character stats', checked:a.showStats, onChange:function(v){ set({showStats: v}); } })
148 ),
149 el(PanelBody, { title:'Sizing', initialOpen:false },
150 el(RangeControl, { label:'Max Width (px)', value:a.contentMaxWidth, min:400, max:1100, step:20, onChange:function(v){ set({contentMaxWidth:v}); } })
151 ),
152
153 el( PanelBody, { title: __( 'Typography', 'blockenberg' ), initialOpen: false },
154 TC && el(TC, { label: __('Title', 'blockenberg'), value: a.titleTypo || {}, onChange: function(v){ set({titleTypo: v}); } }),
155 TC && el(TC, { label: __('Subtitle', 'blockenberg'), value: a.subtitleTypo || {}, onChange: function(v){ set({subtitleTypo: v}); } })
156 ),
157 el(PanelColorSettings, { title:'Colors', initialOpen:false, disableCustomGradients:true, colorSettings:colorSettings })
158 ),
159 el('div', useBlockProps(),
160 el(EditorPreview, { attributes:a, setAttributes:set })
161 )
162 );
163 },
164
165 save: function(props) {
166 var a = props.attributes;
167 return el('div', useBlockProps.save(),
168 el('div', {
169 className: 'bkbg-b64-app',
170 'data-opts': JSON.stringify({
171 title: a.title,
172 subtitle: a.subtitle,
173 defaultMode: a.defaultMode,
174 defaultInput: a.defaultInput,
175 showUrlSafe: a.showUrlSafe,
176 showLineBreaks: a.showLineBreaks,
177 showStats: a.showStats,
178 accentColor: a.accentColor,
179 sectionBg: a.sectionBg,
180 cardBg: a.cardBg,
181 inputBg: a.inputBg,
182 outputBg: a.outputBg,
183 outputColor: a.outputColor,
184 titleColor: a.titleColor,
185 subtitleColor: a.subtitleColor,
186 labelColor: a.labelColor,
187 titleFontSize: a.titleFontSize,
188 contentMaxWidth:a.contentMaxWidth,
189 titleTypo: a.titleTypo || {},
190 subtitleTypo: a.subtitleTypo || {}
191 })
192 })
193 );
194 }
195 });
196 }() );
197