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 / json-formatter / index.js

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

174 lines 11.3 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 RangeControl = wp.components.RangeControl;
12 var TextControl = wp.components.TextControl;
13 var ToggleControl = wp.components.ToggleControl;
14 var SelectControl = wp.components.SelectControl;
15
16 var _TypographyControl, _typoCssVars;
17 function getTypographyControl() { return _TypographyControl || (_TypographyControl = window.bkbgTypographyControl); }
18 function getTypoCssVars() { return _typoCssVars || (_typoCssVars = window.bkbgTypoCssVars); }
19
20 registerBlockType('blockenberg/json-formatter', {
21 edit: function (props) {
22 var attributes = props.attributes;
23 var setAttributes = props.setAttributes;
24
25 var blockProps = useBlockProps((function () {
26 var _tv = getTypoCssVars();
27 var s = {
28 background: attributes.sectionBg,
29 paddingTop: attributes.paddingTop + 'px',
30 paddingBottom: attributes.paddingBottom + 'px'
31 };
32 Object.assign(s, _tv(attributes.titleTypo, '--bkbg-jf-tt-'));
33 return { style: s };
34 })());
35
36 function togCtrl(label, key) {
37 return el(ToggleControl, {
38 __nextHasNoMarginBottom: true,
39 label: label, checked: attributes[key],
40 onChange: function (v) { var o = {}; o[key] = v; setAttributes(o); }
41 });
42 }
43 function rng(label, key, min, max, step) {
44 return el(RangeControl, {
45 __nextHasNoMarginBottom: true,
46 label: label, value: attributes[key], min: min, max: max, step: step || 1,
47 onChange: function (v) { var o = {}; o[key] = v; setAttributes(o); }
48 });
49 }
50
51 var colors = [
52 { label: 'Accent / buttons', value: attributes.accentColor, onChange: function (v) { setAttributes({ accentColor: v }); } },
53 { label: 'Key color', value: attributes.keyColor, onChange: function (v) { setAttributes({ keyColor: v }); } },
54 { label: 'String color', value: attributes.stringColor, onChange: function (v) { setAttributes({ stringColor: v }); } },
55 { label: 'Number color', value: attributes.numberColor, onChange: function (v) { setAttributes({ numberColor: v }); } },
56 { label: 'Bool / null color', value: attributes.boolNullColor, onChange: function (v) { setAttributes({ boolNullColor: v }); } },
57 { label: 'Punctuation', value: attributes.punctColor, onChange: function (v) { setAttributes({ punctColor: v }); } },
58 { label: 'Section BG', value: attributes.sectionBg, onChange: function (v) { setAttributes({ sectionBg: v }); } },
59 { label: 'Card BG', value: attributes.cardBg, onChange: function (v) { setAttributes({ cardBg: v }); } },
60 { label: 'Editor BG', value: attributes.editorBg, onChange: function (v) { setAttributes({ editorBg: v }); } },
61 { label: 'Editor text', value: attributes.editorText, onChange: function (v) { setAttributes({ editorText: v }); } },
62 { label: 'Line num BG', value: attributes.lineNumBg, onChange: function (v) { setAttributes({ lineNumBg: v }); } },
63 { label: 'Line num color', value: attributes.lineNumColor, onChange: function (v) { setAttributes({ lineNumColor: v }); } },
64 { label: 'Error BG', value: attributes.errorBg, onChange: function (v) { setAttributes({ errorBg: v }); } },
65 { label: 'Error text', value: attributes.errorColor, onChange: function (v) { setAttributes({ errorColor: v }); } },
66 { label: 'Success', value: attributes.successColor, onChange: function (v) { setAttributes({ successColor: v }); } },
67 { label: 'Title', value: attributes.titleColor, onChange: function (v) { setAttributes({ titleColor: v }); } },
68 { label: 'Subtitle', value: attributes.subtitleColor, onChange: function (v) { setAttributes({ subtitleColor: v }); } }
69 ];
70
71 /* Editor preview */
72 var sampleOutput = '{\n "name": "Blockenberg",\n "version": 1,\n "features": [\n "WYSIWYG",\n "rich settings",\n "frontend rendering"\n ]\n}';
73
74 return el(Fragment, null,
75 el(InspectorControls, null,
76 el(PanelBody, { title: 'Content', initialOpen: true },
77 togCtrl('Show title', 'showTitle'),
78 attributes.showTitle && el(TextControl, {
79 __nextHasNoMarginBottom: true, label: 'Title', value: attributes.title,
80 onChange: function (v) { setAttributes({ title: v }); }
81 }),
82 togCtrl('Show subtitle', 'showSubtitle'),
83 attributes.showSubtitle && el(TextControl, {
84 __nextHasNoMarginBottom: true, label: 'Subtitle', value: attributes.subtitle,
85 onChange: function (v) { setAttributes({ subtitle: v }); }
86 }),
87 el(SelectControl, {
88 __nextHasNoMarginBottom: true, label: 'Indent size',
89 value: attributes.indentSize.toString(),
90 options: [
91 { label: '2 spaces', value: '2' },
92 { label: '4 spaces', value: '4' },
93 { label: '1 tab', value: '1' }
94 ],
95 onChange: function (v) { setAttributes({ indentSize: parseInt(v) }); }
96 })
97 ),
98 el(PanelBody, { title: 'Display', initialOpen: false },
99 togCtrl('Show line numbers', 'showLineNums'),
100 togCtrl('Show stats bar', 'showStats'),
101 rng('Editor font size (px)', 'editorFontSize', 10, 20),
102 rng('Editor height (px)', 'editorHeight', 180, 800, 10)
103 ),
104 el(PanelColorSettings, { title: 'Colors', initialOpen: false, colorSettings: colors }),
105 el(PanelBody, { title: 'Sizing', initialOpen: false },
106 rng('Max width (px)', 'maxWidth', 400, 1400, 10),
107 rng('Card radius (px)', 'cardRadius', 0, 32),
108 rng('Editor radius (px)', 'editorRadius', 0, 20),
109 rng('Title size (px)', 'titleSize', 18, 48),
110 rng('Padding top (px)', 'paddingTop', 0, 160, 4),
111 rng('Padding bottom (px)', 'paddingBottom', 0, 160, 4)
112 ),
113 el(PanelBody, { title: 'Typography', initialOpen: false },
114 el(getTypographyControl(), { label: 'Title', value: attributes.titleTypo, onChange: function (v) { setAttributes({ titleTypo: v }); } }),
115 el('p', { style: { margin: '16px 0 4px', fontSize: '11px', fontWeight: 600, textTransform: 'uppercase', color: '#1e1e1e' } }, 'Output / Code'),
116 el(RangeControl, { __nextHasNoMarginBottom: true, label: 'Size (px)', value: attributes.outputFontSize, min: 8, max: 72, onChange: function(v){ setAttributes({ outputFontSize: v }); } }),
117 el(RangeControl, { __nextHasNoMarginBottom: true, label: 'Weight', value: attributes.outputFontWeight, min: 100, max: 900, step: 100, onChange: function(v){ setAttributes({ outputFontWeight: v }); } }),
118 el(RangeControl, { __nextHasNoMarginBottom: true, label: 'Line Height', value: attributes.outputLineHeight, min: 0.8, max: 3, step: 0.1, onChange: function(v){ setAttributes({ outputLineHeight: v }); } })
119 ),
120
121 ),
122 el('div', blockProps,
123 el('div', {
124 style: {
125 background: attributes.cardBg, borderRadius: attributes.cardRadius + 'px',
126 maxWidth: attributes.maxWidth + 'px', margin: '0 auto', padding: '36px 32px',
127 boxShadow: '0 4px 32px rgba(0,0,0,0.08)'
128 }
129 },
130 attributes.showTitle && el('div', {
131 className: 'bkbg-jf-title',
132 style: { color: attributes.titleColor, marginBottom: '6px', textAlign: 'center' }
133 }, attributes.title),
134 attributes.showSubtitle && el('div', {
135 style: { fontSize: '14px', color: attributes.subtitleColor, marginBottom: '24px', textAlign: 'center' }
136 }, attributes.subtitle),
137 /* Toolbar buttons preview */
138 el('div', { style: { display: 'flex', gap: '8px', marginBottom: '12px', flexWrap: 'wrap' } },
139 ['Format', 'Minify', 'Validate', 'Copy', 'Clear'].map(function (t, i) {
140 var isPrimary = i <= 1;
141 return el('div', {
142 key: t,
143 style: {
144 padding: '8px 18px', borderRadius: '8px', fontSize: '13px', fontWeight: '700',
145 background: isPrimary ? attributes.accentColor : '#f3f4f6',
146 color: isPrimary ? '#fff' : '#374151',
147 display: 'inline-block'
148 }
149 }, t);
150 })
151 ),
152 /* Editor preview */
153 el('div', {
154 style: {
155 background: attributes.editorBg, borderRadius: attributes.editorRadius + 'px',
156 padding: '16px', fontFamily: 'monospace', fontSize: attributes.editorFontSize + 'px',
157 color: attributes.editorText, height: '160px', overflow: 'hidden',
158 whiteSpace: 'pre', lineHeight: '1.6'
159 }
160 }, sampleOutput)
161 )
162 )
163 );
164 },
165
166 save: function (props) {
167 var a = props.attributes;
168 return el('div', wp.blockEditor.useBlockProps.save(),
169 el('div', { className: 'bkbg-jf-app', 'data-opts': JSON.stringify(a) })
170 );
171 }
172 });
173 }() );
174