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 / content-upgrade / index.js

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

177 lines 11.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 __ = wp.i18n.__;
4 var registerBlockType = wp.blocks.registerBlockType;
5 var InspectorControls = wp.blockEditor.InspectorControls;
6 var MediaUpload = wp.blockEditor.MediaUpload;
7 var MediaUploadCheck = wp.blockEditor.MediaUploadCheck;
8 var useBlockProps = wp.blockEditor.useBlockProps;
9 var RichText = wp.blockEditor.RichText;
10 var PanelColorSettings = wp.blockEditor.PanelColorSettings;
11 var PanelBody = wp.components.PanelBody;
12 var SelectControl = wp.components.SelectControl;
13 var TextControl = wp.components.TextControl;
14 var TextareaControl = wp.components.TextareaControl;
15 var RangeControl = wp.components.RangeControl;
16 var Button = wp.components.Button;
17
18 var _tcCUP, _tvCUP;
19 function getCupTC() { return _tcCUP || (_tcCUP = window.bkbgTypographyControl); }
20 function getCupTV() { return _tvCUP || (_tvCUP = window.bkbgTypoCssVars); }
21
22 registerBlockType('blockenberg/content-upgrade', {
23 edit: function (props) {
24 var attr = props.attributes;
25 var set = props.setAttributes;
26
27 var tv = getCupTV();
28 var blockProps = useBlockProps({ style: Object.assign({ background: attr.bgColor }, tv(attr.typoHeading, '--bkcup-head-'), tv(attr.typoDesc, '--bkcup-desc-')) });
29
30 /* Preview wrapper */
31 var isBoxed = attr.style === 'boxed';
32 var isMinimal = attr.style === 'minimal';
33
34 var previewStyle = {
35 display: 'flex', gap: '32px', alignItems: 'center',
36 padding: attr.paddingTop + 'px 32px ' + attr.paddingBottom + 'px',
37 background: isMinimal ? 'transparent' : attr.bgColor,
38 border: isBoxed ? '2px solid ' + attr.borderColor : (isMinimal ? '2px dashed ' + attr.borderColor : 'none'),
39 borderRadius: isBoxed ? attr.borderRadius + 'px' : (isMinimal ? '0' : attr.borderRadius + 'px'),
40 borderLeft: isMinimal ? '4px solid ' + attr.accentColor : undefined
41 };
42
43 /* Left: image */
44 var leftCol = attr.imageUrl
45 ? el('div', { style: { flexShrink: 0 } },
46 el('img', { src: attr.imageUrl, alt: attr.imageAlt, style: { width: '140px', height: '140px', objectFit: 'cover', borderRadius: '8px', display: 'block' } })
47 )
48 : el('div', { style: { flexShrink: 0, width: '100px', height: '100px', background: attr.accentColor + '22', borderRadius: '8px', display: 'flex', alignItems: 'center', justifyContent: 'center', fontSize: '36px' } }, '🎁');
49
50 /* Right: text + form */
51 var rightCol = el('div', { style: { flex: 1 } },
52 el(RichText, {
53 tagName: 'p', className: 'bkbg-cup-heading',
54 style: { margin: '0 0 8px', color: attr.headingColor },
55 value: attr.heading, placeholder: __('Heading…', 'blockenberg'),
56 onChange: function (v) { set({ heading: v }); }
57 }),
58 el(RichText, {
59 tagName: 'p', className: 'bkbg-cup-desc',
60 style: { margin: '0 0 16px', color: attr.descColor },
61 value: attr.description, placeholder: __('Description…', 'blockenberg'),
62 onChange: function (v) { set({ description: v }); }
63 }),
64 el('div', { style: { display: 'flex', gap: '8px' } },
65 el('input', { type: 'email', placeholder: attr.formPlaceholder, readOnly: true, style: { flex: 1, padding: '10px 14px', background: attr.inputBg, border: '1px solid ' + attr.inputBorder, color: attr.inputColor, borderRadius: '6px', fontSize: '14px' } }),
66 el('button', { style: { padding: '10px 20px', background: attr.submitBg, color: attr.submitColor, border: 'none', borderRadius: '6px', fontWeight: 600, fontSize: '14px', cursor: 'pointer', whiteSpace: 'nowrap' } }, attr.formSubmitLabel)
67 )
68 );
69
70 var controls = el(InspectorControls, {},
71 el(PanelBody, { title: __('Content', 'blockenberg'), initialOpen: true },
72 el(SelectControl, {
73 label: __('Style', 'blockenberg'), value: attr.style, __nextHasNoMarginBottom: true,
74 options: [
75 { label: 'Boxed', value: 'boxed' },
76 { label: 'Inline (no border)', value: 'inline' },
77 { label: 'Minimal (left accent bar)', value: 'minimal' }
78 ],
79 onChange: function (v) { set({ style: v }); }
80 }),
81 el('div', { style: { marginTop: '12px' } },
82 el(TextControl, {
83 label: __('Form Placeholder', 'blockenberg'), value: attr.formPlaceholder, __nextHasNoMarginBottom: true,
84 onChange: function (v) { set({ formPlaceholder: v }); }
85 })
86 ),
87 el('div', { style: { marginTop: '12px' } },
88 el(TextControl, {
89 label: __('Submit Button Label', 'blockenberg'), value: attr.formSubmitLabel, __nextHasNoMarginBottom: true,
90 onChange: function (v) { set({ formSubmitLabel: v }); }
91 })
92 ),
93 el('div', { style: { marginTop: '12px' } },
94 el(TextControl, {
95 label: __('Form Action URL', 'blockenberg'), value: attr.formAction, __nextHasNoMarginBottom: true,
96 onChange: function (v) { set({ formAction: v }); }
97 })
98 ),
99 el('div', { style: { marginTop: '12px' } },
100 el(TextareaControl, {
101 label: __('Success Message', 'blockenberg'), value: attr.successMessage, __nextHasNoMarginBottom: true,
102 onChange: function (v) { set({ successMessage: v }); }
103 })
104 )
105 ),
106 el(PanelBody, { title: __('Image', 'blockenberg'), initialOpen: false },
107 el(MediaUploadCheck, {},
108 el(MediaUpload, {
109 onSelect: function (m) { set({ imageUrl: m.url, imageId: m.id, imageAlt: m.alt || '' }); },
110 allowedTypes: ['image'], value: attr.imageId,
111 render: function (rp) {
112 return el('div', {},
113 attr.imageUrl && el('img', { src: attr.imageUrl, style: { width: '100%', borderRadius: '6px', marginBottom: '8px' } }),
114 el(Button, { onClick: rp.open, variant: 'secondary', __nextHasNoMarginBottom: true }, attr.imageUrl ? __('Replace Image', 'blockenberg') : __('Upload Image', 'blockenberg')),
115 attr.imageUrl && el(Button, { onClick: function () { set({ imageUrl: '', imageId: 0, imageAlt: '' }); }, variant: 'link', isDestructive: true, style: { marginLeft: '8px' } }, __('Remove', 'blockenberg'))
116 );
117 }
118 })
119 )
120 ),
121 el(PanelBody, { title: __('Spacing', 'blockenberg'), initialOpen: false },
122 el(RangeControl, {
123 label: __('Padding Top', 'blockenberg'), value: attr.paddingTop, min: 0, max: 120, __nextHasNoMarginBottom: true,
124 onChange: function (v) { set({ paddingTop: v }); }
125 }),
126 el('div', { style: { marginTop: '12px' } },
127 el(RangeControl, {
128 label: __('Padding Bottom', 'blockenberg'), value: attr.paddingBottom, min: 0, max: 120, __nextHasNoMarginBottom: true,
129 onChange: function (v) { set({ paddingBottom: v }); }
130 })
131 ),
132 el('div', { style: { marginTop: '12px' } },
133 el(RangeControl, {
134 label: __('Border Radius', 'blockenberg'), value: attr.borderRadius, min: 0, max: 32, __nextHasNoMarginBottom: true,
135 onChange: function (v) { set({ borderRadius: v }); }
136 })
137 )
138 ),
139 el(PanelColorSettings, {
140 title: __('Colors', 'blockenberg'), initialOpen: false,
141 colorSettings: [
142 { label: __('Background', 'blockenberg'), value: attr.bgColor, onChange: function (v) { set({ bgColor: v || '#f5f3ff' }); } },
143 { label: __('Border', 'blockenberg'), value: attr.borderColor, onChange: function (v) { set({ borderColor: v || '#ddd6fe' }); } },
144 { label: __('Accent', 'blockenberg'), value: attr.accentColor, onChange: function (v) { set({ accentColor: v || '#6366f1' }); } },
145 { label: __('Heading', 'blockenberg'), value: attr.headingColor, onChange: function (v) { set({ headingColor: v || '#1e1b4b' }); } },
146 { label: __('Description', 'blockenberg'), value: attr.descColor, onChange: function (v) { set({ descColor: v || '#4b5563' }); } },
147 { label: __('Input Background', 'blockenberg'), value: attr.inputBg, onChange: function (v) { set({ inputBg: v || '#ffffff' }); } },
148 { label: __('Input Border', 'blockenberg'), value: attr.inputBorder, onChange: function (v) { set({ inputBorder: v || '#d1d5db' }); } },
149 { label: __('Input Text', 'blockenberg'), value: attr.inputColor, onChange: function (v) { set({ inputColor: v || '#111827' }); } },
150 { label: __('Submit Button', 'blockenberg'), value: attr.submitBg, onChange: function (v) { set({ submitBg: v || '#6366f1' }); } },
151 { label: __('Submit Text', 'blockenberg'), value: attr.submitColor, onChange: function (v) { set({ submitColor: v || '#ffffff' }); } }
152 ]
153 }),
154 el(PanelBody, { title: __('Typography', 'blockenberg'), initialOpen: false },
155 getCupTC() && el(getCupTC(), { label: __('Heading', 'blockenberg'), value: attr.typoHeading, onChange: function (v) { set({ typoHeading: v }); } }),
156 getCupTC() && el(getCupTC(), { label: __('Description', 'blockenberg'), value: attr.typoDesc, onChange: function (v) { set({ typoDesc: v }); } })
157 )
158 );
159
160 return el('div', blockProps,
161 controls,
162 el('div', { className: 'bkbg-cup-preview', style: previewStyle },
163 leftCol,
164 rightCol
165 )
166 );
167 },
168 save: function (props) {
169 var attr = props.attributes;
170 var useBlockProps = wp.blockEditor.useBlockProps;
171 return el('div', useBlockProps.save(),
172 el('div', { className: 'bkbg-cup-app', 'data-opts': JSON.stringify(attr) })
173 );
174 }
175 });
176 }() );
177