| 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 |
var ALGOS = ['MD5', 'SHA-1', 'SHA-256', 'SHA-512']; |
| 18 |
|
| 19 |
/* ── Typography lazy getters ──────────────────────────────── */ |
| 20 |
var _ttTC, _ttTV, _stTC, _stTV; |
| 21 |
function _tc() { return _ttTC || (_ttTC = window.bkbgTypographyControl); } |
| 22 |
function _tv() { return _ttTV || (_ttTV = window.bkbgTypoCssVars); } |
| 23 |
|
| 24 |
// ── Editor preview ─────────────────────────────────────────────────── |
| 25 |
function EditorPreview(props) { |
| 26 |
var a = props.attributes; |
| 27 |
|
| 28 |
var wrapStyle = { |
| 29 |
background: a.sectionBg, |
| 30 |
borderRadius: '14px', |
| 31 |
padding: '32px 24px', |
| 32 |
maxWidth: a.contentMaxWidth + 'px', |
| 33 |
margin: '0 auto', |
| 34 |
fontFamily: 'inherit', |
| 35 |
boxSizing: 'border-box' |
| 36 |
}; |
| 37 |
|
| 38 |
var enabledAlgos = []; |
| 39 |
if (a.showMD5) enabledAlgos.push('MD5'); |
| 40 |
if (a.showSHA1) enabledAlgos.push('SHA-1'); |
| 41 |
if (a.showSHA256) enabledAlgos.push('SHA-256'); |
| 42 |
if (a.showSHA512) enabledAlgos.push('SHA-512'); |
| 43 |
|
| 44 |
var inputStyle = { |
| 45 |
width: '100%', |
| 46 |
boxSizing: 'border-box', |
| 47 |
border: '1.5px solid #e5e7eb', |
| 48 |
borderRadius: '10px', |
| 49 |
padding: '12px 14px', |
| 50 |
fontSize: '14px', |
| 51 |
background: a.inputBg, |
| 52 |
color: a.labelColor, |
| 53 |
resize: 'vertical', |
| 54 |
minHeight: '90px', |
| 55 |
fontFamily: 'inherit' |
| 56 |
}; |
| 57 |
|
| 58 |
var hashRowStyle = { |
| 59 |
background: a.hashBg, |
| 60 |
borderRadius: '8px', |
| 61 |
padding: '10px 14px', |
| 62 |
marginBottom: '10px', |
| 63 |
display: 'flex', |
| 64 |
alignItems: 'center', |
| 65 |
justifyContent: 'space-between', |
| 66 |
gap: '10px' |
| 67 |
}; |
| 68 |
|
| 69 |
var algoLabelStyle = { |
| 70 |
color: '#818cf8', |
| 71 |
fontSize: '11px', |
| 72 |
fontWeight: '700', |
| 73 |
letterSpacing:'0.07em', |
| 74 |
whiteSpace: 'nowrap', |
| 75 |
minWidth: '60px' |
| 76 |
}; |
| 77 |
|
| 78 |
var hashValueStyle = { |
| 79 |
color: a.hashColor, |
| 80 |
fontSize: '12px', |
| 81 |
fontFamily: 'monospace', |
| 82 |
wordBreak: 'break-all', |
| 83 |
flex: 1, |
| 84 |
opacity: 0.7 |
| 85 |
}; |
| 86 |
|
| 87 |
var placeholderHash = '— enter text to generate hash —'; |
| 88 |
|
| 89 |
return el('div', { style: wrapStyle }, |
| 90 |
el(RichText, { |
| 91 |
tagName: 'h3', |
| 92 |
className: 'bkbg-hg-title', |
| 93 |
value: a.title, |
| 94 |
onChange: function(v){ props.setAttributes({ title: v }); }, |
| 95 |
style: { color: a.titleColor, margin: '0 0 6px 0' }, |
| 96 |
placeholder: 'Block title...' |
| 97 |
}), |
| 98 |
el(RichText, { |
| 99 |
tagName: 'p', |
| 100 |
className: 'bkbg-hg-subtitle', |
| 101 |
value: a.subtitle, |
| 102 |
onChange: function(v){ props.setAttributes({ subtitle: v }); }, |
| 103 |
style: { color: a.subtitleColor, margin: '0 0 20px 0' }, |
| 104 |
placeholder: 'Subtitle...' |
| 105 |
}), |
| 106 |
|
| 107 |
// Text input preview |
| 108 |
el('div', { style: { marginBottom: '16px' } }, |
| 109 |
el('label', { style: { display:'block', fontSize:'13px', fontWeight:'600', color: a.labelColor, marginBottom:'6px' } }, 'Input text'), |
| 110 |
el('textarea', { style: inputStyle, readOnly: true, value: a.defaultInput || '', placeholder: 'Type or paste text here…' }) |
| 111 |
), |
| 112 |
|
| 113 |
// Algo selector preview |
| 114 |
el('div', { style: { display:'flex', gap:'8px', flexWrap:'wrap', marginBottom:'20px' } }, |
| 115 |
enabledAlgos.map(function(algo) { |
| 116 |
var active = algo === a.defaultAlgorithm; |
| 117 |
return el('button', { |
| 118 |
key: algo, |
| 119 |
style: { |
| 120 |
padding: '7px 16px', |
| 121 |
borderRadius: '8px', |
| 122 |
border: '2px solid ' + (active ? a.accentColor : '#e5e7eb'), |
| 123 |
background: active ? a.accentColor : a.cardBg, |
| 124 |
color: active ? '#fff' : a.labelColor, |
| 125 |
fontWeight: active ? '700' : '500', |
| 126 |
fontSize: '13px', |
| 127 |
cursor: 'pointer' |
| 128 |
} |
| 129 |
}, algo); |
| 130 |
}) |
| 131 |
), |
| 132 |
|
| 133 |
// Hash output rows preview |
| 134 |
el('div', { style: { marginBottom: '16px' } }, |
| 135 |
enabledAlgos.map(function(algo) { |
| 136 |
return el('div', { key: algo, style: hashRowStyle }, |
| 137 |
el('span', { style: algoLabelStyle }, algo), |
| 138 |
el('span', { style: hashValueStyle }, placeholderHash), |
| 139 |
el('button', { style: { background:'none', border:'none', color:'#6366f1', cursor:'pointer', fontSize:'18px', padding:'0 2px' } }, '⧉') |
| 140 |
); |
| 141 |
}) |
| 142 |
), |
| 143 |
|
| 144 |
// Compare section |
| 145 |
a.showCompare && el('div', { style: { background: a.cardBg, borderRadius:'10px', padding:'14px 16px', border:'1.5px solid #e5e7eb' } }, |
| 146 |
el('div', { style: { fontSize:'12px', fontWeight:'700', color: a.labelColor, marginBottom:'8px', textTransform:'uppercase', letterSpacing:'0.06em' } }, 'Verify / Compare Hash'), |
| 147 |
el('input', { type:'text', readOnly:true, placeholder:'Paste expected hash to compare…', style: { width:'100%', boxSizing:'border-box', border:'1.5px solid #e5e7eb', borderRadius:'8px', padding:'9px 12px', background: a.inputBg, color: a.labelColor, fontSize:'13px', fontFamily:'monospace' } }) |
| 148 |
) |
| 149 |
); |
| 150 |
} |
| 151 |
|
| 152 |
// ── Register ───────────────────────────────────────────────────────── |
| 153 |
registerBlockType('blockenberg/hash-generator', { |
| 154 |
edit: function(props) { |
| 155 |
var a = props.attributes; |
| 156 |
var set = props.setAttributes; |
| 157 |
|
| 158 |
var enabledAlgos = []; |
| 159 |
if (a.showMD5) enabledAlgos.push('MD5'); |
| 160 |
if (a.showSHA1) enabledAlgos.push('SHA-1'); |
| 161 |
if (a.showSHA256) enabledAlgos.push('SHA-256'); |
| 162 |
if (a.showSHA512) enabledAlgos.push('SHA-512'); |
| 163 |
|
| 164 |
var colorSettings = [ |
| 165 |
{ value: a.accentColor, onChange: function(v){ set({ accentColor: v||'#6366f1' }); }, label: 'Accent color' }, |
| 166 |
{ value: a.sectionBg, onChange: function(v){ set({ sectionBg: v||'#f5f3ff' }); }, label: 'Section background' }, |
| 167 |
{ value: a.cardBg, onChange: function(v){ set({ cardBg: v||'#ffffff' }); }, label: 'Card background' }, |
| 168 |
{ value: a.inputBg, onChange: function(v){ set({ inputBg: v||'#f9fafb' }); }, label: 'Input background' }, |
| 169 |
{ value: a.hashBg, onChange: function(v){ set({ hashBg: v||'#1e1b4b' }); }, label: 'Hash row background' }, |
| 170 |
{ value: a.hashColor, onChange: function(v){ set({ hashColor: v||'#a5b4fc' }); }, label: 'Hash text color' }, |
| 171 |
{ value: a.titleColor, onChange: function(v){ set({ titleColor: v||'#111827' }); }, label: 'Title color' }, |
| 172 |
{ value: a.subtitleColor, onChange: function(v){ set({ subtitleColor: v||'#6b7280' }); }, label: 'Subtitle color' }, |
| 173 |
{ value: a.labelColor, onChange: function(v){ set({ labelColor: v||'#374151' }); }, label: 'Label color' } |
| 174 |
]; |
| 175 |
|
| 176 |
return el(Fragment, null, |
| 177 |
el(InspectorControls, null, |
| 178 |
el(PanelBody, { title: 'Generator Settings', initialOpen: true }, |
| 179 |
el(SelectControl, { |
| 180 |
label: 'Default Algorithm', |
| 181 |
value: a.defaultAlgorithm, |
| 182 |
options: enabledAlgos.map(function(g){ return { label: g, value: g }; }), |
| 183 |
onChange: function(v){ set({ defaultAlgorithm: v }); } |
| 184 |
}), |
| 185 |
el(TextControl, { |
| 186 |
label: 'Placeholder Input Text', |
| 187 |
value: a.defaultInput, |
| 188 |
onChange: function(v){ set({ defaultInput: v }); } |
| 189 |
}), |
| 190 |
el(ToggleControl, { __nextHasNoMarginBottom:true, label:'Auto-hash on type', checked:a.autoHash, onChange:function(v){ set({ autoHash: v }); } }) |
| 191 |
), |
| 192 |
el(PanelBody, { title: 'Visible Algorithms', initialOpen: false }, |
| 193 |
el(ToggleControl, { __nextHasNoMarginBottom:true, label:'Show MD5', checked:a.showMD5, onChange:function(v){ set({ showMD5: v }); } }), |
| 194 |
el(ToggleControl, { __nextHasNoMarginBottom:true, label:'Show SHA-1', checked:a.showSHA1, onChange:function(v){ set({ showSHA1: v }); } }), |
| 195 |
el(ToggleControl, { __nextHasNoMarginBottom:true, label:'Show SHA-256', checked:a.showSHA256, onChange:function(v){ set({ showSHA256: v }); } }), |
| 196 |
el(ToggleControl, { __nextHasNoMarginBottom:true, label:'Show SHA-512', checked:a.showSHA512, onChange:function(v){ set({ showSHA512: v }); } }), |
| 197 |
el(ToggleControl, { __nextHasNoMarginBottom:true, label:'Show Compare / Verify field', checked:a.showCompare, onChange:function(v){ set({ showCompare: v }); } }) |
| 198 |
), |
| 199 |
el(PanelBody, { title: 'Sizing', initialOpen: false }, |
| 200 |
el(RangeControl, { label:'Max Width (px)', value:a.contentMaxWidth, min:400, max:1100, step:20, onChange:function(v){ set({ contentMaxWidth: v }); } }) |
| 201 |
), |
| 202 |
|
| 203 |
el( PanelBody, { title: __( 'Typography', 'blockenberg' ), initialOpen: false }, |
| 204 |
_tc() && _tc()({ label: __('Title','blockenberg'), value: a.typoTitle, onChange: function(v){ set({ typoTitle: v }); } }), |
| 205 |
_tc() && _tc()({ label: __('Subtitle','blockenberg'), value: a.typoSubtitle, onChange: function(v){ set({ typoSubtitle: v }); } }) |
| 206 |
), |
| 207 |
el(PanelColorSettings, { title:'Colors', initialOpen:false, disableCustomGradients:true, colorSettings: colorSettings }) |
| 208 |
), |
| 209 |
el('div', useBlockProps({ style: Object.assign({}, _tv() && _tv()(a.typoTitle, '--bkbg-hg-tt-'), _tv() && _tv()(a.typoSubtitle, '--bkbg-hg-st-')) }), |
| 210 |
el(EditorPreview, { attributes: a, setAttributes: set }) |
| 211 |
) |
| 212 |
); |
| 213 |
}, |
| 214 |
|
| 215 |
save: function(props) { |
| 216 |
var a = props.attributes; |
| 217 |
return el('div', useBlockProps.save(), |
| 218 |
el('div', { |
| 219 |
className: 'bkbg-hg-app', |
| 220 |
'data-opts': JSON.stringify({ |
| 221 |
title: a.title, |
| 222 |
subtitle: a.subtitle, |
| 223 |
defaultAlgorithm: a.defaultAlgorithm, |
| 224 |
defaultInput: a.defaultInput, |
| 225 |
showMD5: a.showMD5, |
| 226 |
showSHA1: a.showSHA1, |
| 227 |
showSHA256: a.showSHA256, |
| 228 |
showSHA512: a.showSHA512, |
| 229 |
showCompare: a.showCompare, |
| 230 |
autoHash: a.autoHash, |
| 231 |
accentColor: a.accentColor, |
| 232 |
sectionBg: a.sectionBg, |
| 233 |
cardBg: a.cardBg, |
| 234 |
inputBg: a.inputBg, |
| 235 |
hashBg: a.hashBg, |
| 236 |
hashColor: a.hashColor, |
| 237 |
titleColor: a.titleColor, |
| 238 |
subtitleColor: a.subtitleColor, |
| 239 |
labelColor: a.labelColor, |
| 240 |
titleFontSize: a.titleFontSize, |
| 241 |
titleFontWeight: a.titleFontWeight, |
| 242 |
titleLineHeight: a.titleLineHeight, |
| 243 |
subtitleFontSize: a.subtitleFontSize, |
| 244 |
subtitleFontWeight: a.subtitleFontWeight, |
| 245 |
subtitleLineHeight: a.subtitleLineHeight, |
| 246 |
contentMaxWidth: a.contentMaxWidth, |
| 247 |
typoTitle: a.typoTitle, |
| 248 |
typoSubtitle: a.typoSubtitle |
| 249 |
}) |
| 250 |
}) |
| 251 |
); |
| 252 |
} |
| 253 |
}); |
| 254 |
}() ); |
| 255 |
|