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 / clipboard-copy / index.js

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

208 lines 10.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 (function () {
2 var el = window.wp.element.createElement;
3 var __ = function (s) { return s; };
4 var registerBlockType = window.wp.blocks.registerBlockType;
5 var InspectorControls = window.wp.blockEditor.InspectorControls;
6 var PanelBody = window.wp.components.PanelBody;
7 var ToggleControl = window.wp.components.ToggleControl;
8 var SelectControl = window.wp.components.SelectControl;
9 var RangeControl = window.wp.components.RangeControl;
10 var TextControl = window.wp.components.TextControl;
11 var TextareaControl = window.wp.components.TextareaControl;
12 var PanelColorSettings = window.wp.blockEditor.PanelColorSettings;
13
14 function getTypographyControl() { return (window.bkbgTypographyControl || function () { return null; }); }
15 function _tv() { var fn = window.bkbgTypoCssVars; return fn ? fn.apply(null, arguments) : {}; }
16
17 var copyIcon = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor" width="14" height="14"><path d="M16 1H4c-1.1 0-2 .9-2 2v14h2V3h12V1zm3 4H8c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h11c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2zm0 16H8V7h11v14z"/></svg>';
18
19 registerBlockType('blockenberg/clipboard-copy', {
20 title: __('Clipboard Copy'),
21 description: __('Display a copyable code or text with a one-click copy button.'),
22 category: 'bkbg-dev',
23 icon: el('svg', { viewBox: '0 0 24 24', fill: 'currentColor', width: 24, height: 24 },
24 el('path', { d: 'M16 1H4c-1.1 0-2 .9-2 2v14h2V3h12V1zm3 4H8c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h11c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2zm0 16H8V7h11v14z' })
25 ),
26
27 edit: function (props) {
28 var a = props.attributes;
29 var setA = props.setAttributes;
30
31 var sizeMap = { sm: { fs: 12, h: 32, pad: '0 10px' }, md: { fs: 14, h: 40, pad: '0 14px' }, lg: { fs: 16, h: 48, pad: '0 18px' } };
32 var sz = sizeMap[a.size] || sizeMap.md;
33
34 var inspector = el(InspectorControls, null,
35 el(PanelBody, { title: __('Content'), initialOpen: true },
36 el(TextControl, {
37 label: __('Text to Copy'),
38 value: a.textToCopy,
39 onChange: function (v) { setA({ textToCopy: v }); },
40 }),
41 el(TextControl, {
42 label: __('Button Label'),
43 value: a.label,
44 onChange: function (v) { setA({ label: v }); },
45 }),
46 el(TextControl, {
47 label: __('Copied State Label'),
48 value: a.copiedLabel,
49 onChange: function (v) { setA({ copiedLabel: v }); },
50 }),
51 el(TextareaControl, {
52 label: __('Description text (optional)'),
53 value: a.description,
54 rows: 2,
55 onChange: function (v) { setA({ description: v }); },
56 }),
57 el(ToggleControl, {
58 label: __('Show code display area'),
59 checked: a.showCode,
60 onChange: function (v) { setA({ showCode: v }); },
61 __nextHasNoMarginBottom: true,
62 }),
63 el(ToggleControl, {
64 label: __('Show copy icon on button'),
65 checked: a.iconEnabled,
66 onChange: function (v) { setA({ iconEnabled: v }); },
67 __nextHasNoMarginBottom: true,
68 })
69 ),
70 el(PanelBody, { title: __('Layout'), initialOpen: false },
71 el(SelectControl, {
72 label: __('Card Style'),
73 value: a.style,
74 options: [
75 { label: 'Card (bordered)', value: 'card' },
76 { label: 'Inline', value: 'inline' },
77 { label: 'Minimal', value: 'minimal' },
78 ],
79 onChange: function (v) { setA({ style: v }); },
80 }),
81 el(SelectControl, {
82 label: __('Size'),
83 value: a.size,
84 options: [
85 { label: 'Small', value: 'sm' },
86 { label: 'Medium', value: 'md' },
87 { label: 'Large', value: 'lg' },
88 ],
89 onChange: function (v) { setA({ size: v }); },
90 }),
91 el(SelectControl, {
92 label: __('Alignment'),
93 value: a.alignment,
94 options: [
95 { label: 'Left', value: 'left' },
96 { label: 'Center', value: 'center' },
97 { label: 'Right', value: 'right' },
98 ],
99 onChange: function (v) { setA({ alignment: v }); },
100 }),
101 el(RangeControl, {
102 label: __('Border Radius'),
103 value: a.borderRadius,
104 min: 0, max: 30,
105 onChange: function (v) { setA({ borderRadius: v }); },
106 }),
107 el(RangeControl, {
108 label: __('Toast Duration (ms)'),
109 value: a.toastDuration,
110 min: 500, max: 5000, step: 100,
111 onChange: function (v) { setA({ toastDuration: v }); },
112 })
113 ),
114
115 el( PanelBody, { title: __( 'Typography', 'blockenberg' ), initialOpen: false },
116 el(getTypographyControl(), { label: __('Code Text', 'blockenberg'), value: a.typoCode, onChange: function (v) { setA({ typoCode: v }); } }),
117 el(getTypographyControl(), { label: __('Description', 'blockenberg'), value: a.typoDesc, onChange: function (v) { setA({ typoDesc: v }); } })
118 ),
119 el(PanelBody, { title: __('Colors'), initialOpen: false },
120 el(PanelColorSettings, {
121 title: __('Card Colors'),
122 initialOpen: false,
123 colorSettings: [
124 { label: __('Card Background'), value: a.bgColor, onChange: function (v) { setA({ bgColor: v || '#f9fafb' }); } },
125 { label: __('Border Color'), value: a.borderColor, onChange: function (v) { setA({ borderColor: v || '#e5e7eb' }); } },
126 { label: __('Code Area BG'), value: a.codeBg, onChange: function (v) { setA({ codeBg: v || '#f3f4f6' }); } },
127 { label: __('Code Text Color'), value: a.codeColor, onChange: function (v) { setA({ codeColor: v || '#111827' }); } },
128 { label: __('Button BG'), value: a.btnBg, onChange: function (v) { setA({ btnBg: v || '#111827' }); } },
129 { label: __('Button Text'), value: a.btnColor, onChange: function (v) { setA({ btnColor: v || '#ffffff' }); } },
130 ],
131 })
132 )
133 );
134
135 /* ── Editor preview ── */
136 var isCard = a.style === 'card';
137 var wrapStyle = {
138 background: isCard ? a.bgColor : 'transparent',
139 border: isCard ? '1px solid ' + a.borderColor : 'none',
140 borderRadius: a.borderRadius + 'px',
141 padding: isCard ? '16px' : '0',
142 display: 'flex',
143 alignItems: 'center',
144 gap: 12,
145 flexWrap: 'wrap',
146 };
147 var codeStyle = {
148 flex: 1, minWidth: 120,
149 background: a.codeBg,
150 color: a.codeColor,
151 borderRadius:a.borderRadius / 2 + 'px',
152 padding: '8px 14px',
153 };
154 var btnStyle = {
155 display: 'inline-flex', alignItems: 'center', gap: 6,
156 height: sz.h + 'px', padding: sz.pad,
157 background: a.btnBg, color: a.btnColor,
158 borderRadius:a.borderRadius / 2 + 'px',
159 fontSize: sz.fs + 'px', fontWeight: a.fontWeight,
160 cursor: 'pointer', whiteSpace: 'nowrap',
161 border: 'none',
162 };
163
164 var typoVars = Object.assign({}, _tv(a.typoCode, '--bkbg-cpc-cd'), _tv(a.typoDesc, '--bkbg-cpc-ds'));
165
166 return el('div', { className: 'bkbg-cpc-editor', style: typoVars },
167 inspector,
168 a.description && el('p', { className: 'bkbg-cpc-desc', style: { margin: '0 0 10px', color: '#6b7280' } }, a.description),
169 el('div', { style: wrapStyle },
170 a.showCode && el('span', { className: 'bkbg-cpc-code', style: codeStyle }, a.textToCopy),
171 el('button', { style: btnStyle, type: 'button' },
172 a.iconEnabled && el('span', { dangerouslySetInnerHTML: { __html: copyIcon }, style: { display: 'flex', alignItems: 'center' } }),
173 a.label
174 )
175 )
176 );
177 },
178
179 save: function (props) {
180 var a = props.attributes;
181 return el('div', {
182 className: 'bkbg-cpc-wrap bkbg-cpc-style--' + a.style + ' bkbg-cpc-align--' + a.alignment,
183 'data-text': a.textToCopy,
184 'data-label': a.label,
185 'data-copied-label':a.copiedLabel,
186 'data-show-code': a.showCode ? '1' : '0',
187 'data-icon': a.iconEnabled ? '1' : '0',
188 'data-size': a.size,
189 'data-bg': a.bgColor,
190 'data-border': a.borderColor,
191 'data-btn-bg': a.btnBg,
192 'data-btn-color': a.btnColor,
193 'data-code-bg': a.codeBg,
194 'data-code-color': a.codeColor,
195 'data-code-fs': a.codeFontSize,
196 'data-fs': a.fontSize,
197 'data-desc-size': a.descSize,
198 'data-fw': a.fontWeight,
199 'data-radius': a.borderRadius,
200 'data-toast': a.toastDuration,
201 'data-description': a.description,
202 'data-typo-code': JSON.stringify(a.typoCode || {}),
203 'data-typo-desc': JSON.stringify(a.typoDesc || {}),
204 });
205 },
206 });
207 })();
208