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 / ebook-section / index.js

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

237 lines 19.0 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 ToggleControl = wp.components.ToggleControl;
13 var RangeControl = wp.components.RangeControl;
14 var SelectControl = wp.components.SelectControl;
15 var TextControl = wp.components.TextControl;
16 var TextareaControl = wp.components.TextareaControl;
17 var Button = wp.components.Button;
18
19 var _ebkTC, _ebkTV;
20 function _tc() { return _ebkTC || (_ebkTC = window.bkbgTypographyControl); }
21 function _tv(t, p) { return (_ebkTV || (_ebkTV = window.bkbgTypoCssVars)) ? _ebkTV(t, p) : {}; }
22 var IP = function () { return window.bkbgIconPicker; };
23
24 var FORMAT_LABELS = { pdf: 'PDF', epub: 'EPUB', course: 'Course', template: 'Template', toolkit: 'Toolkit', guide: 'Guide', checklist: 'Checklist' };
25
26 registerBlockType('blockenberg/ebook-section', {
27 edit: function (props) {
28 var attr = props.attributes;
29 var set = props.setAttributes;
30
31 var blockProps = useBlockProps({ style: Object.assign({ background: attr.bgColor, padding: attr.paddingTop + 'px 0 ' + attr.paddingBottom + 'px' }, _tv(attr.typoTitle || {}, '--bkbg-ebk-ttl-'), _tv(attr.typoSubtitle || {}, '--bkbg-ebk-sub-'), _tv(attr.typoPrice || {}, '--bkbg-ebk-prc-'), _tv(attr.typoCta || {}, '--bkbg-ebk-cta-')) });
32
33 function updateItem(idx, key, value) {
34 var arr = attr.whatInside.map(function (it, i) {
35 if (i !== idx) return it;
36 var c = Object.assign({}, it); c[key] = value; return c;
37 });
38 set({ whatInside: arr });
39 }
40
41 var fmtLabel = attr.formatLabel || FORMAT_LABELS[attr.format] || attr.format.toUpperCase();
42
43 /* Cover element */
44 var coverEl = el('div', { style: { position: 'relative', perspective: '600px' } },
45 el(MediaUploadCheck, {},
46 el(MediaUpload, {
47 onSelect: function (m) { set({ coverUrl: m.url, coverId: m.id, coverAlt: m.alt || '' }); },
48 allowedTypes: ['image'],
49 value: attr.coverId,
50 render: function (ref) {
51 return attr.coverUrl
52 ? el('div', { style: { position: 'relative', cursor: 'pointer' }, onClick: ref.open },
53 el('img', { src: attr.coverUrl, alt: attr.coverAlt, style: { width: '220px', maxWidth: '100%', borderRadius: '6px', display: 'block', boxShadow: '8px 8px 24px ' + attr.coverShadow, transform: attr.show3D ? 'rotateY(-8deg)' : 'none', transition: 'transform .3s' } }),
54 el('div', { style: { position: 'absolute', top: '6px', right: '6px', background: attr.formatBadgeBg, color: attr.formatBadgeColor, fontSize: '11px', padding: '2px 8px', borderRadius: '4px', fontWeight: 700 } }, fmtLabel)
55 )
56 : el(Button, { onClick: ref.open, variant: 'secondary', style: { width: '220px', height: '300px', display: 'flex', alignItems: 'center', justifyContent: 'center', flexDirection: 'column', gap: '8px', border: '2px dashed #d1d5db', borderRadius: '6px' } },
57 el('span', { style: { fontSize: '24px' } }, '📚'),
58 el('span', {}, __('Upload Cover', 'blockenberg'))
59 );
60 }
61 })
62 )
63 );
64
65 /* Content column */
66 var formatBadgeEl = el('span', { style: { background: attr.formatBadgeBg, color: attr.formatBadgeColor, fontSize: '12px', padding: '3px 10px', borderRadius: '20px', fontWeight: 700, display: 'inline-block', marginBottom: '8px' } }, fmtLabel);
67 var titleEl = el(RichText, { tagName: 'h2', className: 'bkbg-ebk-title', value: attr.title, allowedFormats: ['core/bold', 'core/italic'], placeholder: __('Ebook title…', 'blockenberg'), style: { color: attr.titleColor, margin: '0 0 8px' }, onChange: function (v) { set({ title: v }); } });
68 var subtitleEl = el(RichText, { tagName: 'p', className: 'bkbg-ebk-subtitle', value: attr.subtitle, allowedFormats: ['core/bold', 'core/italic'], placeholder: __('Subtitle or tagline…', 'blockenberg'), style: { color: attr.subtitleColor, margin: '0 0 16px' }, onChange: function (v) { set({ subtitle: v }); } });
69
70 var priceEl = el('div', { style: { display: 'flex', alignItems: 'center', gap: '10px', marginBottom: '16px' } },
71 el('span', { className: 'bkbg-ebk-price', style: { color: attr.priceColor } }, attr.price || 'Free'),
72 attr.originalPrice && el('span', { style: { fontSize: '16px', color: attr.origPriceColor, textDecoration: 'line-through' } }, attr.originalPrice),
73 attr.pageCount && el('span', { style: { fontSize: '12px', color: attr.authorColor } }, '· ' + attr.pageCount)
74 );
75
76 var whatInsideEl = el('ul', { style: { listStyle: 'none', padding: 0, margin: '0 0 16px' } },
77 (attr.whatInside || []).map(function (it, i) {
78 return el('li', { key: i, style: { display: 'flex', alignItems: 'flex-start', gap: '8px', marginBottom: '6px', fontSize: '14px', color: attr.itemColor } },
79 el('span', { style: { fontSize: '15px', flexShrink: 0 } }, (it.iconType || 'custom-char') !== 'custom-char' ? IP().buildEditorIcon(it.iconType, it.icon, it.iconDashicon, it.iconImageUrl, it.iconDashiconColor) : (it.icon || '�
80 ')),
81 el('span', {}, it.item)
82 );
83 })
84 );
85
86 var testimonialEl = attr.showTestimonial && el('div', { style: { background: attr.testimonialBg, borderRadius: '8px', padding: '14px 16px', marginBottom: '16px' } },
87 el('div', { style: { fontSize: '24px', color: attr.quoteColor, lineHeight: 1 } }, '"'),
88 el('p', { style: { margin: '4px 0 8px', fontSize: '13px', fontStyle: 'italic', color: attr.testimonialColor } }, attr.testimonialQuote),
89 el('div', { style: { fontSize: '12px', fontWeight: 600, color: attr.authorColor } }, attr.testimonialName)
90 );
91
92 var ctaEl = el('a', { href: '#', className: 'bkbg-ebk-cta', style: { background: attr.ctaBg, color: attr.ctaColor } }, attr.ctaLabel);
93
94 var isSplit = attr.layout === 'split';
95 var isCentered = attr.layout === 'centered';
96
97 var innerStyle = isSplit
98 ? { display: 'flex', gap: '40px', alignItems: 'center', flexWrap: 'wrap' }
99 : { display: 'flex', flexDirection: 'column', alignItems: 'center', textAlign: 'center', maxWidth: '520px', margin: '0 auto' };
100
101 var coverWrap = el('div', { style: isSplit ? { flexShrink: 0 } : { marginBottom: '24px' } }, coverEl);
102 var contentWrap = el('div', { style: isSplit ? { flex: 1, minWidth: '280px' } : {} },
103 formatBadgeEl, titleEl, subtitleEl, priceEl, whatInsideEl, testimonialEl, ctaEl
104 );
105
106 var controls = el(InspectorControls, {},
107 el(PanelBody, { title: __('Content', 'blockenberg'), initialOpen: false },
108 el(TextControl, { label: __('Author Name', 'blockenberg'), value: attr.authorName, __nextHasNoMarginBottom: true, onChange: function (v) { set({ authorName: v }); } }),
109 el('div', { style: { marginTop: '8px' } },
110 el(SelectControl, {
111 label: __('Format', 'blockenberg'), value: attr.format, __nextHasNoMarginBottom: true,
112 options: [
113 { label: 'PDF', value: 'pdf' }, { label: 'EPUB', value: 'epub' }, { label: 'Course', value: 'course' },
114 { label: 'Template', value: 'template' }, { label: 'Toolkit', value: 'toolkit' }, { label: 'Guide', value: 'guide' }, { label: 'Checklist', value: 'checklist' }
115 ],
116 onChange: function (v) { set({ format: v }); }
117 })
118 ),
119 el('div', { style: { marginTop: '8px' } },
120 el(TextControl, { label: __('Custom Format Label (override)', 'blockenberg'), value: attr.formatLabel, __nextHasNoMarginBottom: true, onChange: function (v) { set({ formatLabel: v }); } })
121 ),
122 el('div', { style: { marginTop: '8px' } },
123 el(TextControl, { label: __('Page Count / Size', 'blockenberg'), value: attr.pageCount, __nextHasNoMarginBottom: true, onChange: function (v) { set({ pageCount: v }); } })
124 ),
125 el('div', { style: { marginTop: '8px' } },
126 el(TextControl, { label: __('Price', 'blockenberg'), value: attr.price, __nextHasNoMarginBottom: true, onChange: function (v) { set({ price: v }); } })
127 ),
128 el('div', { style: { marginTop: '8px' } },
129 el(TextControl, { label: __('Original Price (crossed out)', 'blockenberg'), value: attr.originalPrice, __nextHasNoMarginBottom: true, onChange: function (v) { set({ originalPrice: v }); } })
130 )
131 ),
132 el(PanelBody, { title: __('What\'s Inside List', 'blockenberg'), initialOpen: false },
133 (attr.whatInside || []).map(function (it, idx) {
134 return el('div', { key: idx, style: { display: 'flex', gap: '6px', marginBottom: '8px', alignItems: 'flex-start' } },
135 el('div', { style: { flexShrink: 0 } },
136 el(IP().IconPickerControl, {
137 iconType: it.iconType, customChar: it.icon, dashicon: it.iconDashicon, imageUrl: it.iconImageUrl,
138 onChangeType: function (v) { updateItem(idx, 'iconType', v); },
139 onChangeChar: function (v) { updateItem(idx, 'icon', v); },
140 onChangeDashicon: function (v) { updateItem(idx, 'iconDashicon', v); },
141 onChangeImageUrl: function (v) { updateItem(idx, 'iconImageUrl', v); }
142 })
143 ),
144 el('div', { style: { flex: 1 } },
145 el(TextControl, { label: '', value: it.item, placeholder: 'Feature…', __nextHasNoMarginBottom: true, onChange: function (v) { updateItem(idx, 'item', v); } })
146 ),
147 el(Button, { variant: 'link', isDestructive: true, onClick: function () { set({ whatInside: attr.whatInside.filter(function (_, i) { return i !== idx; }) }); } }, '')
148 );
149 }),
150 el(Button, { variant: 'secondary', style: { marginTop: '4px' }, onClick: function () { set({ whatInside: (attr.whatInside || []).concat([{ icon: '�
151 ', item: '', iconType: 'custom-char', iconDashicon: '', iconImageUrl: '' }]) }); } }, __('+ Add Item', 'blockenberg'))
152 ),
153 el(PanelBody, { title: __('Testimonial', 'blockenberg'), initialOpen: false },
154 el(ToggleControl, { label: __('Show Testimonial', 'blockenberg'), checked: attr.showTestimonial, __nextHasNoMarginBottom: true, onChange: function (v) { set({ showTestimonial: v }); } }),
155 attr.showTestimonial && el('div', { style: { marginTop: '8px' } },
156 el(TextareaControl, { label: __('Quote', 'blockenberg'), value: attr.testimonialQuote, rows: 3, __nextHasNoMarginBottom: true, onChange: function (v) { set({ testimonialQuote: v }); } }),
157 el('div', { style: { marginTop: '6px' } },
158 el(TextControl, { label: __('Name', 'blockenberg'), value: attr.testimonialName, __nextHasNoMarginBottom: true, onChange: function (v) { set({ testimonialName: v }); } })
159 )
160 )
161 ),
162 el(PanelBody, { title: __('CTA Button', 'blockenberg'), initialOpen: false },
163 el(TextControl, { label: __('Button Text', 'blockenberg'), value: attr.ctaLabel, __nextHasNoMarginBottom: true, onChange: function (v) { set({ ctaLabel: v }); } }),
164 el('div', { style: { marginTop: '8px' } },
165 el(TextControl, { label: __('Button URL', 'blockenberg'), value: attr.ctaUrl, placeholder: 'https://...', __nextHasNoMarginBottom: true, onChange: function (v) { set({ ctaUrl: v }); } })
166 ),
167 el('div', { style: { marginTop: '8px' } },
168 el(ToggleControl, { label: __('Open in New Tab', 'blockenberg'), checked: attr.openInNewTab, __nextHasNoMarginBottom: true, onChange: function (v) { set({ openInNewTab: v }); } })
169 )
170 ),
171 el(PanelBody, { title: __('Layout & Style', 'blockenberg'), initialOpen: false },
172 el(SelectControl, {
173 label: __('Layout', 'blockenberg'), value: attr.layout, __nextHasNoMarginBottom: true,
174 options: [{ label: 'Split (cover left)', value: 'split' }, { label: 'Centered', value: 'centered' }, { label: 'Minimal (no cover)', value: 'minimal' }],
175 onChange: function (v) { set({ layout: v }); }
176 }),
177 el('div', { style: { marginTop: '8px' } },
178 el(ToggleControl, { label: __('3D Cover Tilt Effect', 'blockenberg'), checked: attr.show3D, __nextHasNoMarginBottom: true, onChange: function (v) { set({ show3D: v }); } })
179 ),
180 el('div', { style: { marginTop: '12px' } },
181 el(RangeControl, { label: __('Border Radius', 'blockenberg'), value: attr.borderRadius, min: 0, max: 24, __nextHasNoMarginBottom: true, onChange: function (v) { set({ borderRadius: v }); } })
182 ),
183 el('div', { style: { marginTop: '12px' } },
184 el(RangeControl, { label: __('Padding Top', 'blockenberg'), value: attr.paddingTop, min: 0, max: 160, __nextHasNoMarginBottom: true, onChange: function (v) { set({ paddingTop: v }); } })
185 ),
186 el('div', { style: { marginTop: '12px' } },
187 el(RangeControl, { label: __('Padding Bottom', 'blockenberg'), value: attr.paddingBottom, min: 0, max: 160, __nextHasNoMarginBottom: true, onChange: function (v) { set({ paddingBottom: v }); } })
188 )
189 ),
190 el(PanelBody, { title: __('Typography', 'blockenberg'), initialOpen: false },
191 _tc() && el(_tc(), { label: __('Title'), typo: attr.typoTitle || {}, onChange: function (v) { set({ typoTitle: v }); }, defaultSize: attr.titleFontSize || 28 }),
192 _tc() && el(_tc(), { label: __('Subtitle'), typo: attr.typoSubtitle || {}, onChange: function (v) { set({ typoSubtitle: v }); }, defaultSize: attr.subtitleFontSize || 15 }),
193 _tc() && el(_tc(), { label: __('Price'), typo: attr.typoPrice || {}, onChange: function (v) { set({ typoPrice: v }); }, defaultSize: attr.priceFontSize || 22 }),
194 _tc() && el(_tc(), { label: __('CTA Button'), typo: attr.typoCta || {}, onChange: function (v) { set({ typoCta: v }); }, defaultSize: attr.ctaFontSize || 15 })
195 ),
196 el(PanelColorSettings, {
197 title: __('Colors', 'blockenberg'), initialOpen: false,
198 colorSettings: [
199 { label: __('Section BG', 'blockenberg'), value: attr.bgColor, onChange: function (v) { set({ bgColor: v || '#f0f4ff' }); } },
200 { label: __('Title', 'blockenberg'), value: attr.titleColor, onChange: function (v) { set({ titleColor: v || '#111827' }); } },
201 { label: __('Subtitle', 'blockenberg'), value: attr.subtitleColor, onChange: function (v) { set({ subtitleColor: v || '#374151' }); } },
202 { label: __('Author / Meta', 'blockenberg'), value: attr.authorColor, onChange: function (v) { set({ authorColor: v || '#6b7280' }); } },
203 { label: __('Format Badge BG', 'blockenberg'), value: attr.formatBadgeBg, onChange: function (v) { set({ formatBadgeBg: v || '#6366f1' }); } },
204 { label: __('Format Badge Text', 'blockenberg'), value: attr.formatBadgeColor, onChange: function (v) { set({ formatBadgeColor: v || '#ffffff' }); } },
205 { label: __('Feature Item Text', 'blockenberg'), value: attr.itemColor, onChange: function (v) { set({ itemColor: v || '#374151' }); } },
206 { label: __('Testimonial BG', 'blockenberg'), value: attr.testimonialBg, onChange: function (v) { set({ testimonialBg: v || '#ffffff' }); } },
207 { label: __('Testimonial Text', 'blockenberg'), value: attr.testimonialColor, onChange: function (v) { set({ testimonialColor: v || '#374151' }); } },
208 { label: __('Quote Mark', 'blockenberg'), value: attr.quoteColor, onChange: function (v) { set({ quoteColor: v || '#6366f1' }); } },
209 { label: __('CTA Button BG', 'blockenberg'), value: attr.ctaBg, onChange: function (v) { set({ ctaBg: v || '#6366f1' }); } },
210 { label: __('CTA Button Text', 'blockenberg'), value: attr.ctaColor, onChange: function (v) { set({ ctaColor: v || '#ffffff' }); } },
211 { label: __('Price', 'blockenberg'), value: attr.priceColor, onChange: function (v) { set({ priceColor: v || '#16a34a' }); } },
212 { label: __('Orig Price', 'blockenberg'), value: attr.origPriceColor, onChange: function (v) { set({ origPriceColor: v || '#9ca3af' }); } },
213 { label: __('Cover Shadow', 'blockenberg'), value: attr.coverShadow, onChange: function (v) { set({ coverShadow: v || '#6366f160' }); } }
214 ]
215 })
216 );
217
218 return el('div', blockProps,
219 controls,
220 el('div', { style: { maxWidth: '960px', margin: '0 auto', padding: '0 20px' } },
221 el('div', { style: innerStyle },
222 attr.layout !== 'minimal' && coverWrap,
223 contentWrap
224 )
225 )
226 );
227 },
228 save: function (props) {
229 var attr = props.attributes;
230 var useBlockProps = wp.blockEditor.useBlockProps;
231 return el('div', useBlockProps.save(),
232 el('div', { className: 'bkbg-ebk-app', 'data-opts': JSON.stringify(attr) })
233 );
234 }
235 });
236 }() );
237