| 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 |
var Button = wp.components.Button; |
| 17 |
|
| 18 |
var _tc, _tvf; |
| 19 |
Object.defineProperty(window, '_tc', { get: function () { return _tc || (_tc = window.bkbgTypographyControl); } }); |
| 20 |
Object.defineProperty(window, '_tvf', { get: function () { return _tvf || (_tvf = window.bkbgTypoCssVars); } }); |
| 21 |
function getTypoControl(label, key, attrs, setA) { return _tc(label, key, attrs, setA); } |
| 22 |
function getTypoCssVars(attrs) { |
| 23 |
var v = {}; |
| 24 |
_tvf(v, 'titleTypo', attrs, '--bkuuid-tt-'); |
| 25 |
_tvf(v, 'subtitleTypo', attrs, '--bkuuid-st-'); |
| 26 |
return v; |
| 27 |
} |
| 28 |
|
| 29 |
function uuidV4Preview() { |
| 30 |
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) { |
| 31 |
var r = Math.random() * 16 | 0, v = c === 'x' ? r : (r & 0x3 | 0x8); |
| 32 |
return v.toString(16); |
| 33 |
}); |
| 34 |
} |
| 35 |
|
| 36 |
var SAMPLE_UUIDS = [ |
| 37 |
uuidV4Preview(), |
| 38 |
uuidV4Preview(), |
| 39 |
uuidV4Preview(), |
| 40 |
uuidV4Preview(), |
| 41 |
uuidV4Preview() |
| 42 |
]; |
| 43 |
|
| 44 |
registerBlockType('blockenberg/uuid-generator', { |
| 45 |
edit: function (props) { |
| 46 |
var a = props.attributes; |
| 47 |
var setAttributes = props.setAttributes; |
| 48 |
var blockProps = useBlockProps((function () { var _tv = getTypoCssVars(a); return { style: _tv, className: 'bkbg-uuid-editor-wrap' }; })()); |
| 49 |
|
| 50 |
var containerStyle = { |
| 51 |
background: a.sectionBg, |
| 52 |
borderRadius: '12px', |
| 53 |
padding: '28px', |
| 54 |
maxWidth: a.contentMaxWidth + 'px', |
| 55 |
margin: '0 auto', |
| 56 |
fontFamily: 'system-ui, sans-serif' |
| 57 |
}; |
| 58 |
|
| 59 |
var uuidItemStyle = { |
| 60 |
background: a.uuidBg, |
| 61 |
color: a.uuidColor, |
| 62 |
borderRadius: '6px', |
| 63 |
padding: '10px 14px', |
| 64 |
fontFamily: 'monospace', |
| 65 |
fontSize: '14px', |
| 66 |
marginBottom: '6px', |
| 67 |
letterSpacing: '0.03em', |
| 68 |
display: 'flex', |
| 69 |
justifyContent: 'space-between', |
| 70 |
alignItems: 'center' |
| 71 |
}; |
| 72 |
|
| 73 |
var btnStyle = { |
| 74 |
background: a.accentColor, |
| 75 |
color: '#fff', |
| 76 |
border: 'none', |
| 77 |
borderRadius: '8px', |
| 78 |
padding: '10px 22px', |
| 79 |
cursor: 'pointer', |
| 80 |
fontWeight: '600', |
| 81 |
fontSize: '14px' |
| 82 |
}; |
| 83 |
|
| 84 |
return el( |
| 85 |
Fragment, |
| 86 |
null, |
| 87 |
el( |
| 88 |
InspectorControls, |
| 89 |
null, |
| 90 |
el( |
| 91 |
PanelBody, |
| 92 |
{ title: __('Content', 'blockenberg'), initialOpen: true }, |
| 93 |
el(TextControl, { |
| 94 |
label: __('Title', 'blockenberg'), |
| 95 |
value: a.title, |
| 96 |
onChange: function (v) { setAttributes({ title: v }); } |
| 97 |
}), |
| 98 |
el(TextControl, { |
| 99 |
label: __('Subtitle', 'blockenberg'), |
| 100 |
value: a.subtitle, |
| 101 |
onChange: function (v) { setAttributes({ subtitle: v }); } |
| 102 |
}), |
| 103 |
el(ToggleControl, { |
| 104 |
label: __('Show Title', 'blockenberg'), |
| 105 |
checked: a.showTitle, |
| 106 |
onChange: function (v) { setAttributes({ showTitle: v }); }, |
| 107 |
__nextHasNoMarginBottom: true |
| 108 |
}), |
| 109 |
el(ToggleControl, { |
| 110 |
label: __('Show Subtitle', 'blockenberg'), |
| 111 |
checked: a.showSubtitle, |
| 112 |
onChange: function (v) { setAttributes({ showSubtitle: v }); }, |
| 113 |
__nextHasNoMarginBottom: true |
| 114 |
}) |
| 115 |
), |
| 116 |
el( |
| 117 |
PanelBody, |
| 118 |
{ title: __('Generator Settings', 'blockenberg'), initialOpen: false }, |
| 119 |
el(SelectControl, { |
| 120 |
label: __('Default UUID Version', 'blockenberg'), |
| 121 |
value: a.defaultVersion, |
| 122 |
options: [ |
| 123 |
{ value: 'v4', label: __('UUID v4 (random)', 'blockenberg') }, |
| 124 |
{ value: 'v1', label: __('UUID v1 (timestamp)', 'blockenberg') } |
| 125 |
], |
| 126 |
onChange: function (v) { setAttributes({ defaultVersion: v }); } |
| 127 |
}), |
| 128 |
el(RangeControl, { |
| 129 |
label: __('Default Count', 'blockenberg'), |
| 130 |
value: a.defaultCount, |
| 131 |
min: 1, |
| 132 |
max: 50, |
| 133 |
onChange: function (v) { setAttributes({ defaultCount: v }); } |
| 134 |
}), |
| 135 |
el(ToggleControl, { |
| 136 |
label: __('Default Uppercase', 'blockenberg'), |
| 137 |
checked: a.showUppercase, |
| 138 |
onChange: function (v) { setAttributes({ showUppercase: v }); }, |
| 139 |
__nextHasNoMarginBottom: true |
| 140 |
}), |
| 141 |
el(ToggleControl, { |
| 142 |
label: __('Show History', 'blockenberg'), |
| 143 |
checked: a.showHistory, |
| 144 |
onChange: function (v) { setAttributes({ showHistory: v }); }, |
| 145 |
__nextHasNoMarginBottom: true |
| 146 |
}) |
| 147 |
), |
| 148 |
el( |
| 149 |
PanelBody, |
| 150 |
{ title: __('Typography', 'blockenberg'), initialOpen: false }, |
| 151 |
getTypoControl(__('Title', 'blockenberg'), 'titleTypo', a, setAttributes), |
| 152 |
getTypoControl(__('Subtitle', 'blockenberg'), 'subtitleTypo', a, setAttributes) |
| 153 |
), |
| 154 |
el( |
| 155 |
PanelBody, |
| 156 |
{ title: __('Appearance', 'blockenberg'), initialOpen: false }, |
| 157 |
el(RangeControl, { |
| 158 |
label: __('Max Width (px)', 'blockenberg'), |
| 159 |
value: a.contentMaxWidth, |
| 160 |
min: 320, |
| 161 |
max: 1200, |
| 162 |
onChange: function (v) { setAttributes({ contentMaxWidth: v }); } |
| 163 |
}) |
| 164 |
), |
| 165 |
el( |
| 166 |
PanelColorSettings, |
| 167 |
{ |
| 168 |
title: __('Colors', 'blockenberg'), |
| 169 |
initialOpen: false, |
| 170 |
colorSettings: [ |
| 171 |
{ value: a.accentColor, onChange: function (v) { setAttributes({ accentColor: v || '#0ea5e9' }); }, label: __('Accent / Button', 'blockenberg') }, |
| 172 |
{ value: a.uuidBg, onChange: function (v) { setAttributes({ uuidBg: v || '#0f172a' }); }, label: __('UUID Background', 'blockenberg') }, |
| 173 |
{ value: a.uuidColor, onChange: function (v) { setAttributes({ uuidColor: v || '#7dd3fc' }); }, label: __('UUID Text', 'blockenberg') }, |
| 174 |
{ value: a.sectionBg, onChange: function (v) { setAttributes({ sectionBg: v || '#f0f9ff' }); }, label: __('Section Background', 'blockenberg') }, |
| 175 |
{ value: a.cardBg, onChange: function (v) { setAttributes({ cardBg: v || '#ffffff' }); }, label: __('Card Background', 'blockenberg') }, |
| 176 |
{ value: a.titleColor, onChange: function (v) { setAttributes({ titleColor: v || '#0c4a6e' }); }, label: __('Title Color', 'blockenberg') }, |
| 177 |
{ value: a.subtitleColor, onChange: function (v) { setAttributes({ subtitleColor: v || '#6b7280' }); }, label: __('Subtitle Color', 'blockenberg') }, |
| 178 |
{ value: a.labelColor, onChange: function (v) { setAttributes({ labelColor: v || '#374151' }); }, label: __('Label Color', 'blockenberg') } |
| 179 |
] |
| 180 |
} |
| 181 |
) |
| 182 |
), |
| 183 |
el( |
| 184 |
'div', |
| 185 |
blockProps, |
| 186 |
el( |
| 187 |
'div', |
| 188 |
{ style: containerStyle }, |
| 189 |
a.showTitle && el('div', { |
| 190 |
className: 'bkbg-uuid-title', style: { color: a.titleColor, marginBottom: '6px' } |
| 191 |
}, a.title), |
| 192 |
a.showSubtitle && el('div', { |
| 193 |
className: 'bkbg-uuid-subtitle', style: { color: a.subtitleColor, marginBottom: '20px' } |
| 194 |
}, a.subtitle), |
| 195 |
el( |
| 196 |
'div', |
| 197 |
{ style: { background: a.cardBg, borderRadius: '10px', padding: '20px', marginBottom: '16px', boxShadow: '0 2px 8px rgba(0,0,0,0.06)' } }, |
| 198 |
el('div', { style: { display: 'flex', gap: '10px', marginBottom: '16px', flexWrap: 'wrap' } }, |
| 199 |
el('button', { style: Object.assign({}, btnStyle, { background: a.defaultVersion === 'v4' ? a.accentColor : '#e5e7eb', color: a.defaultVersion === 'v4' ? '#fff' : '#374151' }) }, 'v4'), |
| 200 |
el('button', { style: Object.assign({}, btnStyle, { background: a.defaultVersion === 'v1' ? a.accentColor : '#e5e7eb', color: a.defaultVersion === 'v1' ? '#fff' : '#374151' }) }, 'v1') |
| 201 |
), |
| 202 |
el('div', { style: { display: 'flex', gap: '8px', marginBottom: '16px', flexWrap: 'wrap' } }, |
| 203 |
[1, 5, 10, 25, 50].map(function (n) { |
| 204 |
return el('button', { |
| 205 |
key: n, |
| 206 |
style: Object.assign({}, btnStyle, { background: n === a.defaultCount ? a.accentColor : '#e5e7eb', color: n === a.defaultCount ? '#fff' : '#374151', padding: '6px 14px', fontSize: '13px' }) |
| 207 |
}, n); |
| 208 |
}) |
| 209 |
), |
| 210 |
SAMPLE_UUIDS.slice(0, a.defaultCount > 5 ? 5 : a.defaultCount).map(function (uuid, i) { |
| 211 |
var display = a.showUppercase ? uuid.toUpperCase() : uuid; |
| 212 |
return el('div', { key: i, style: uuidItemStyle }, |
| 213 |
el('span', null, display), |
| 214 |
el('button', { style: { background: 'rgba(125,211,252,0.1)', border: '1px solid rgba(125,211,252,0.3)', color: a.uuidColor, borderRadius: '4px', padding: '2px 8px', cursor: 'pointer', fontSize: '11px' } }, __('Copy', 'blockenberg')) |
| 215 |
); |
| 216 |
}), |
| 217 |
a.defaultCount > 5 && el('div', { style: { color: a.subtitleColor, fontSize: '13px', paddingTop: '6px' } }, '+ ' + (a.defaultCount - 5) + ' more UUID' + (a.defaultCount - 5 > 1 ? 's' : '') + ' on the frontend'), |
| 218 |
el('div', { style: { display: 'flex', gap: '10px', marginTop: '16px' } }, |
| 219 |
el('button', { style: btnStyle }, __('Generate', 'blockenberg')), |
| 220 |
el('button', { style: Object.assign({}, btnStyle, { background: 'transparent', color: a.accentColor, border: '2px solid ' + a.accentColor }) }, __('Copy All', 'blockenberg')) |
| 221 |
) |
| 222 |
) |
| 223 |
) |
| 224 |
) |
| 225 |
); |
| 226 |
}, |
| 227 |
save: function (props) { |
| 228 |
var a = props.attributes; |
| 229 |
var blockProps = wp.blockEditor.useBlockProps.save((function () { var _tv = getTypoCssVars(a); return { style: _tv }; })()); |
| 230 |
return el('div', blockProps, |
| 231 |
el('div', { |
| 232 |
className: 'bkbg-uuid-app', |
| 233 |
'data-opts': JSON.stringify(a) |
| 234 |
}) |
| 235 |
); |
| 236 |
} |
| 237 |
}); |
| 238 |
}() ); |
| 239 |
|