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 / app-download / index.js

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

165 lines 14.5 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 Fragment = wp.element.Fragment;
4 var __ = wp.i18n.__;
5 var registerBlockType = wp.blocks.registerBlockType;
6 var InspectorControls = wp.blockEditor.InspectorControls;
7 var MediaUpload = wp.blockEditor.MediaUpload;
8 var MediaUploadCheck = wp.blockEditor.MediaUploadCheck;
9 var useBlockProps = wp.blockEditor.useBlockProps;
10 var RichText = wp.blockEditor.RichText;
11 var PanelBody = wp.components.PanelBody;
12 var PanelColorSettings = wp.blockEditor.PanelColorSettings;
13 var ToggleControl = wp.components.ToggleControl;
14 var RangeControl = wp.components.RangeControl;
15 var SelectControl = wp.components.SelectControl;
16 var TextControl = wp.components.TextControl;
17 var Button = wp.components.Button;
18
19 var _TypographyControl, _typoCssVars;
20 function getTypographyControl() { return _TypographyControl || (_TypographyControl = window.bkbgTypographyControl); }
21 function getTypoCssVars() { return _typoCssVars || (_typoCssVars = window.bkbgTypoCssVars); }
22
23 function AppleBadge(style) {
24 return el('div', { style: { display: 'inline-flex', alignItems: 'center', gap: 12, background: style === 'black' ? '#000' : '#fff', border: style === 'white' ? '1.5px solid #ccc' : 'none', borderRadius: 12, padding: '10px 20px', cursor: 'pointer', minWidth: 160 } },
25 el('svg', { width: 28, height: 28, viewBox: '0 0 24 24', fill: style === 'black' ? '#fff' : '#000' },
26 el('path', { d: 'M18.71 19.5c-.83 1.24-1.71 2.45-3.05 2.47-1.34.03-1.77-.79-3.29-.79-1.53 0-2 .77-3.27.82-1.31.05-2.3-1.32-3.14-2.53C4.25 17 2.94 12.45 4.7 9.39c.87-1.52 2.43-2.48 4.12-2.51 1.28-.02 2.5.87 3.29.87.78 0 2.26-1.07 3.8-.91.65.03 2.47.26 3.64 1.98-.09.06-2.17 1.28-2.15 3.81.03 3.02 2.65 4.03 2.68 4.04-.03.07-.42 1.44-1.38 2.83M13 3.5c.73-.83 1.94-1.46 2.94-1.5.13 1.17-.34 2.35-1.04 3.19-.69.85-1.83 1.51-2.95 1.42-.15-1.15.41-2.35 1.05-3.11z' })
27 ),
28 el('div', null,
29 el('div', { style: { fontSize: 9, color: style === 'black' ? '#fff' : '#555', letterSpacing: '.05em' } }, 'Download on the'),
30 el('div', { style: { fontSize: 17, fontWeight: 700, color: style === 'black' ? '#fff' : '#000', lineHeight: 1.1 } }, 'App Store')
31 )
32 );
33 }
34
35 function GoogleBadge(style) {
36 return el('div', { style: { display: 'inline-flex', alignItems: 'center', gap: 12, background: style === 'black' ? '#000' : '#fff', border: style === 'white' ? '1.5px solid #ccc' : 'none', borderRadius: 12, padding: '10px 20px', cursor: 'pointer', minWidth: 160 } },
37 el('svg', { width: 28, height: 28, viewBox: '0 0 24 24' },
38 el('path', { d: 'M3.18 23.76A2 2 0 0 1 2 22V2A2 2 0 0 1 3.18.24L13.26 10.3l-10.08 13.46z', fill: '#4285F4' }),
39 el('path', { d: 'M16.93 13.97l-3.67-3.67 3.67-3.67 4.1 2.36a2.05 2.05 0 0 1 0 2.62l-4.1 2.36z', fill: '#FBBC04' }),
40 el('path', { d: 'M3.18.24L13.26 10.3l3.67-3.67L4.96.3A2.1 2.1 0 0 0 3.18.24z', fill: '#34A853' }),
41 el('path', { d: 'M3.18 23.76L13.26 13.7l3.67 3.67-11.97 6.33c-.6.31-1.32.27-1.78-.24z', fill: '#EA4335' })
42 ),
43 el('div', null,
44 el('div', { style: { fontSize: 9, color: style === 'black' ? '#fff' : '#555', letterSpacing: '.05em' } }, 'GET IT ON'),
45 el('div', { style: { fontSize: 17, fontWeight: 700, color: style === 'black' ? '#fff' : '#000', lineHeight: 1.1 } }, 'Google Play')
46 )
47 );
48 }
49
50 registerBlockType('blockenberg/app-download', {
51 edit: function (props) {
52 var attr = props.attributes;
53 var setAttr = props.setAttributes;
54 var blockProps = useBlockProps({ className: 'bkbg-app-download-editor' });
55
56 var bg = attr.bgGradient || attr.bgColor;
57 var _tv = getTypoCssVars();
58 var previewStyle = { background: bg, padding: attr.paddingTop + 'px 40px ' + attr.paddingBottom + 'px' };
59 Object.assign(previewStyle, _tv(attr.headingTypo || {}, '--bkbg-ad-heading-'));
60 Object.assign(previewStyle, _tv(attr.bodyTypo || {}, '--bkbg-ad-body-'));
61 if (attr.headingSize && attr.headingSize !== 44) previewStyle['--bkbg-ad-heading-sz'] = attr.headingSize + 'px';
62 if (attr.textSize && attr.textSize !== 18) previewStyle['--bkbg-ad-body-sz'] = attr.textSize + 'px';
63 var innerStyle = { maxWidth: attr.maxWidth + 'px', margin: '0 auto', display: 'grid', gridTemplateColumns: attr.layout === 'split' ? '1fr 1fr' : '1fr', gap: 64, alignItems: 'center' };
64
65 return el(Fragment, null,
66 el(InspectorControls, null,
67 el(PanelBody, { title: __('Content', 'blockenberg'), initialOpen: true },
68 el(ToggleControl, { label: __('Show Tag', 'blockenberg'), __nextHasNoMarginBottom: true, checked: attr.showTag, onChange: function (v) { setAttr({ showTag: v }); } }),
69 attr.showTag && el(TextControl, { label: __('Tag Text', 'blockenberg'), __nextHasNoMarginBottom: true, value: attr.tag, onChange: function (v) { setAttr({ tag: v }); } }),
70 el(ToggleControl, { label: __('Show Rating', 'blockenberg'), __nextHasNoMarginBottom: true, checked: attr.showRating, onChange: function (v) { setAttr({ showRating: v }); } }),
71 attr.showRating && el(TextControl, { label: __('Rating (e.g. 4.9)', 'blockenberg'), __nextHasNoMarginBottom: true, value: attr.rating, onChange: function (v) { setAttr({ rating: v }); } }),
72 attr.showRating && el(TextControl, { label: __('Rating Count', 'blockenberg'), __nextHasNoMarginBottom: true, value: attr.ratingCount, onChange: function (v) { setAttr({ ratingCount: v }); } }),
73 el(ToggleControl, { label: __('Show App Store Badge', 'blockenberg'), __nextHasNoMarginBottom: true, checked: attr.showApple, onChange: function (v) { setAttr({ showApple: v }); } }),
74 attr.showApple && el(TextControl, { label: __('App Store URL', 'blockenberg'), __nextHasNoMarginBottom: true, value: attr.appleUrl, onChange: function (v) { setAttr({ appleUrl: v }); } }),
75 el(ToggleControl, { label: __('Show Google Play Badge', 'blockenberg'), __nextHasNoMarginBottom: true, checked: attr.showGoogle, onChange: function (v) { setAttr({ showGoogle: v }); } }),
76 attr.showGoogle && el(TextControl, { label: __('Google Play URL', 'blockenberg'), __nextHasNoMarginBottom: true, value: attr.googleUrl, onChange: function (v) { setAttr({ googleUrl: v }); } }),
77 el(SelectControl, { label: __('Badge Style', 'blockenberg'), __nextHasNoMarginBottom: true, value: attr.badgeStyle,
78 options: [{ label: 'Black', value: 'black' }, { label: 'White', value: 'white' }],
79 onChange: function (v) { setAttr({ badgeStyle: v }); } })
80 ),
81 el(PanelBody, { title: __('Device Image', 'blockenberg'), initialOpen: false },
82 el(MediaUploadCheck, null,
83 el(MediaUpload, {
84 onSelect: function (m) { setAttr({ deviceImageUrl: m.url, deviceImageId: m.id, deviceAlt: m.alt || '' }); },
85 allowedTypes: ['image'],
86 value: attr.deviceImageId,
87 render: function (r) {
88 return el(Fragment, null,
89 attr.deviceImageUrl && el('img', { src: attr.deviceImageUrl, style: { width: '100%', borderRadius: 8, marginBottom: 8 } }),
90 el(Button, { onClick: r.open, variant: 'secondary', __nextHasNoMarginBottom: true }, attr.deviceImageUrl ? __('Change Image', 'blockenberg') : __('Select Device Image', 'blockenberg')),
91 attr.deviceImageUrl && el(Button, { onClick: function () { setAttr({ deviceImageUrl: '', deviceImageId: 0 }); }, variant: 'link', isDestructive: true, __nextHasNoMarginBottom: true, style: { marginLeft: 8 } }, __('Remove', 'blockenberg'))
92 );
93 }
94 })
95 ),
96 el(SelectControl, { label: __('Layout', 'blockenberg'), __nextHasNoMarginBottom: true, value: attr.layout,
97 options: [{ label: 'Split (text + image)', value: 'split' }, { label: 'Centered (text only)', value: 'centered' }],
98 onChange: function (v) { setAttr({ layout: v }); } }),
99 el(SelectControl, { label: __('Image Side', 'blockenberg'), __nextHasNoMarginBottom: true, value: attr.imageLayout,
100 options: [{ label: 'Right', value: 'right' }, { label: 'Left', value: 'left' }],
101 onChange: function (v) { setAttr({ imageLayout: v }); } })
102 ),
103 el(PanelBody, { title: __('Sizing', 'blockenberg'), initialOpen: false },
104 el(RangeControl, { label: __('Max Width (px)', 'blockenberg'), __nextHasNoMarginBottom: true, value: attr.maxWidth, min: 600, max: 1600, step: 10, onChange: function (v) { setAttr({ maxWidth: v }); } }),
105 el(RangeControl, { label: __('Padding Top (px)', 'blockenberg'), __nextHasNoMarginBottom: true, value: attr.paddingTop, min: 0, max: 200, onChange: function (v) { setAttr({ paddingTop: v }); } }),
106 el(RangeControl, { label: __('Padding Bottom (px)', 'blockenberg'), __nextHasNoMarginBottom: true, value: attr.paddingBottom, min: 0, max: 200, onChange: function (v) { setAttr({ paddingBottom: v }); } })
107 ),
108
109 el( PanelBody, { title: __( 'Typography', 'blockenberg' ), initialOpen: false },
110 el(getTypographyControl(), { label: __('Heading Typography', 'blockenberg'), value: attr.headingTypo || {}, onChange: function (v) { setAttr({ headingTypo: v }); } }),
111 el(getTypographyControl(), { label: __('Body Typography', 'blockenberg'), value: attr.bodyTypo || {}, onChange: function (v) { setAttr({ bodyTypo: v }); } })
112 ),
113 el(PanelColorSettings, {
114 title: __('Colors', 'blockenberg'), initialOpen: false,
115 colorSettings: [
116 { value: attr.bgColor, onChange: function (v) { setAttr({ bgColor: v || '#0f172a' }); }, label: __('Background', 'blockenberg') },
117 { value: attr.headingColor, onChange: function (v) { setAttr({ headingColor: v || '#ffffff' }); }, label: __('Heading', 'blockenberg') },
118 { value: attr.textColor, onChange: function (v) { setAttr({ textColor: v || '#94a3b8' }); }, label: __('Body Text', 'blockenberg') },
119 { value: attr.tagBg, onChange: function (v) { setAttr({ tagBg: v || 'rgba(255,255,255,.1)' }); }, label: __('Tag Background', 'blockenberg') },
120 { value: attr.tagColor, onChange: function (v) { setAttr({ tagColor: v || '#ffffff' }); }, label: __('Tag Text', 'blockenberg') },
121 { value: attr.starColor, onChange: function (v) { setAttr({ starColor: v || '#f59e0b' }); }, label: __('Stars', 'blockenberg') },
122 { value: attr.accentColor, onChange: function (v) { setAttr({ accentColor: v || '#818cf8' }); }, label: __('Accent', 'blockenberg') }
123 ]
124 })
125 ),
126 el('div', blockProps,
127 el('div', { style: previewStyle },
128 el('div', { style: innerStyle },
129 el('div', { style: { order: attr.imageLayout === 'right' ? 0 : 1, display: 'flex', flexDirection: 'column', gap: 24 } },
130 attr.showTag && el('span', { style: { display: 'inline-block', background: attr.tagBg, color: attr.tagColor, borderRadius: 100, padding: '4px 16px', fontSize: 12, fontWeight: 600, letterSpacing: '.08em', textTransform: 'uppercase', alignSelf: 'flex-start' } }, attr.tag),
131 el(RichText, { tagName: 'h2', value: attr.heading, onChange: function (v) { setAttr({ heading: v }); }, className: 'bkbg-app-dl-heading', style: { color: attr.headingColor, margin: 0 }, placeholder: __('App heading…', 'blockenberg') }),
132 el(RichText, { tagName: 'p', value: attr.subtext, onChange: function (v) { setAttr({ subtext: v }); }, className: 'bkbg-app-dl-body', style: { color: attr.textColor, margin: 0 }, placeholder: __('Subtitle…', 'blockenberg') }),
133 attr.showRating && el('div', { style: { display: 'flex', alignItems: 'center', gap: 8 } },
134 el('div', { style: { color: attr.starColor, fontSize: 20 } }, '�
135
136
137
138
139 '),
140 el('div', { style: { color: attr.textColor, fontSize: 14 } }, attr.rating + ' · ' + attr.ratingCount)
141 ),
142 (attr.showApple || attr.showGoogle) && el('div', { style: { display: 'flex', flexWrap: 'wrap', gap: 16 } },
143 attr.showApple && AppleBadge(attr.badgeStyle),
144 attr.showGoogle && GoogleBadge(attr.badgeStyle)
145 )
146 ),
147 attr.layout === 'split' && el('div', { style: { order: attr.imageLayout === 'right' ? 1 : 0, display: 'flex', justifyContent: 'center' } },
148 attr.deviceImageUrl
149 ? el('img', { src: attr.deviceImageUrl, alt: attr.deviceAlt, style: { maxHeight: 480, width: 'auto', display: 'block', filter: 'drop-shadow(0 30px 60px rgba(0,0,0,.5))' } })
150 : el('div', { style: { width: 240, height: 480, background: 'rgba(255,255,255,.08)', borderRadius: 32, display: 'flex', alignItems: 'center', justifyContent: 'center', color: 'rgba(255,255,255,.4)', fontSize: 13 } }, __('Device screenshot', 'blockenberg'))
151 )
152 )
153 )
154 )
155 );
156 },
157 save: function (props) {
158 var attr = props.attributes;
159 return el('div', useBlockProps.save(),
160 el('div', { className: 'bkbg-app-download-app', 'data-opts': JSON.stringify(attr) })
161 );
162 }
163 });
164 }() );
165