PluginProbe
Blockenberg — 600+ Advanced Gutenberg Blocks & AI Agent for WordPress Block Editor / 2.0.14
Blockenberg — 600+ Advanced Gutenberg Blocks & AI Agent for WordPress Block Editor v2.0.14
2.0.14 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 / uuid-generator / index.js

index.js in Blockenberg — 600+ Advanced Gutenberg Blocks & AI Agent for WordPress Block Editor 2.0.14, at blocks/uuid-generator/index.js

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