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

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

203 lines 20.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 __ = 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 Button = wp.components.Button;
17 var IP = function () { return window.bkbgIconPicker; };
18
19 var _dmsTC, _dmsTV;
20 function _tc() { return _dmsTC || (_dmsTC = window.bkbgTypographyControl); }
21 function _tv(typo, prefix) { return (_dmsTV || (_dmsTV = window.bkbgTypoCssVars))(typo, prefix); }
22
23 function setItem(items, idx, key, val, setAttr, attrKey) {
24 var next = items.map(function (it, i) { return i === idx ? Object.assign({}, it, { [key]: val }) : it; });
25 setAttr({ [attrKey]: next });
26 }
27 function addItem(items, template, setAttr, attrKey) { setAttr({ [attrKey]: items.concat([template]) }); }
28 function removeItem(items, idx, setAttr, attrKey) { setAttr({ [attrKey]: items.filter(function (_, i) { return i !== idx; }) }); }
29
30 registerBlockType('blockenberg/demo-section', {
31 edit: function (props) {
32 var attr = props.attributes;
33 var setAttr = props.setAttributes;
34 var isSplit = attr.layout === 'split-left' || attr.layout === 'split-right';
35
36 return el(wp.element.Fragment, null,
37 el(InspectorControls, null,
38 /* Content */
39 el(PanelBody, { title: __('Content', 'blockenberg'), initialOpen: true },
40 el(TextControl, { label: __('Badge Text', 'blockenberg'), value: attr.badge, onChange: function (v) { setAttr({ badge: v }); }, __nextHasNoMarginBottom: true }),
41 el(TextControl, { label: __('Heading', 'blockenberg'), value: attr.heading, onChange: function (v) { setAttr({ heading: v }); }, __nextHasNoMarginBottom: true }),
42 el(TextControl, { label: __('Subtext', 'blockenberg'), value: attr.subtext, onChange: function (v) { setAttr({ subtext: v }); }, __nextHasNoMarginBottom: true })
43 ),
44 /* CTA */
45 el(PanelBody, { title: __('CTA', 'blockenberg'), initialOpen: false },
46 el(SelectControl, { label: __('CTA Mode', 'blockenberg'), value: attr.ctaMode, options: [{ label: 'Button', value: 'button' }, { label: 'Email Form', value: 'form' }], onChange: function (v) { setAttr({ ctaMode: v }); }, __nextHasNoMarginBottom: true }),
47 attr.ctaMode === 'button' && el(TextControl, { label: __('Primary Button Label', 'blockenberg'), value: attr.ctaLabel, onChange: function (v) { setAttr({ ctaLabel: v }); }, __nextHasNoMarginBottom: true }),
48 attr.ctaMode === 'button' && el(TextControl, { label: __('Primary Button URL', 'blockenberg'), value: attr.ctaUrl, onChange: function (v) { setAttr({ ctaUrl: v }); }, __nextHasNoMarginBottom: true }),
49 attr.ctaMode === 'button' && el(ToggleControl, { label: __('Show Secondary Button', 'blockenberg'), checked: attr.showCtaSec, onChange: function (v) { setAttr({ showCtaSec: v }); }, __nextHasNoMarginBottom: true }),
50 attr.ctaMode === 'button' && attr.showCtaSec && el(TextControl, { label: __('Secondary Label', 'blockenberg'), value: attr.ctaSecLabel, onChange: function (v) { setAttr({ ctaSecLabel: v }); }, __nextHasNoMarginBottom: true }),
51 attr.ctaMode === 'button' && attr.showCtaSec && el(TextControl, { label: __('Secondary URL', 'blockenberg'), value: attr.ctaSecUrl, onChange: function (v) { setAttr({ ctaSecUrl: v }); }, __nextHasNoMarginBottom: true }),
52 attr.ctaMode === 'form' && el(TextControl, { label: __('Form Placeholder', 'blockenberg'), value: attr.formPlaceholder, onChange: function (v) { setAttr({ formPlaceholder: v }); }, __nextHasNoMarginBottom: true }),
53 attr.ctaMode === 'form' && el(TextControl, { label: __('Submit Label', 'blockenberg'), value: attr.formSubmitLabel, onChange: function (v) { setAttr({ formSubmitLabel: v }); }, __nextHasNoMarginBottom: true }),
54 attr.ctaMode === 'form' && el(TextControl, { label: __('Form Action URL', 'blockenberg'), value: attr.formAction, onChange: function (v) { setAttr({ formAction: v }); }, __nextHasNoMarginBottom: true })
55 ),
56 /* Trust items */
57 el(PanelBody, { title: __('Trust Signals', 'blockenberg'), initialOpen: false },
58 el(ToggleControl, { label: __('Show Trust Signals', 'blockenberg'), checked: attr.showTrust, onChange: function (v) { setAttr({ showTrust: v }); }, __nextHasNoMarginBottom: true }),
59 attr.showTrust && attr.trustItems.map(function (item, idx) {
60 return el(PanelBody, { key: idx, title: (item.text || 'Trust ' + (idx + 1)), initialOpen: false },
61 el(IP().IconPickerControl, {
62 iconType: item.iconType, customChar: item.icon, dashicon: item.iconDashicon, imageUrl: item.iconImageUrl,
63 onChangeType: function (v) { setItem(attr.trustItems, idx, 'iconType', v, setAttr, 'trustItems'); },
64 onChangeChar: function (v) { setItem(attr.trustItems, idx, 'icon', v, setAttr, 'trustItems'); },
65 onChangeDashicon: function (v) { setItem(attr.trustItems, idx, 'iconDashicon', v, setAttr, 'trustItems'); },
66 onChangeImageUrl: function (v) { setItem(attr.trustItems, idx, 'iconImageUrl', v, setAttr, 'trustItems'); }
67 }),
68 el(TextControl, { label: __('Text', 'blockenberg'), value: item.text, onChange: function (v) { setItem(attr.trustItems, idx, 'text', v, setAttr, 'trustItems'); }, __nextHasNoMarginBottom: true }),
69 el(Button, { onClick: function () { removeItem(attr.trustItems, idx, setAttr, 'trustItems'); }, variant: 'link', isDestructive: true, __nextHasNoMarginBottom: true }, __('Remove', 'blockenberg'))
70 );
71 }),
72 attr.showTrust && el(Button, { onClick: function () { addItem(attr.trustItems, { icon: '�
73 ', iconType: 'custom-char', iconDashicon: '', iconImageUrl: '', text: 'New signal' }, setAttr, 'trustItems'); }, variant: 'secondary', style: { marginTop: 8 } }, __('+ Add Trust Signal', 'blockenberg'))
74 ),
75 /* Stats */
76 el(PanelBody, { title: __('Social Proof Stats', 'blockenberg'), initialOpen: false },
77 el(ToggleControl, { label: __('Show Stats', 'blockenberg'), checked: attr.showStats, onChange: function (v) { setAttr({ showStats: v }); }, __nextHasNoMarginBottom: true }),
78 attr.showStats && attr.socialStats.map(function (stat, idx) {
79 return el(PanelBody, { key: idx, title: (stat.number + ' ' + stat.label), initialOpen: false },
80 el(TextControl, { label: __('Number', 'blockenberg'), value: stat.number, onChange: function (v) { setItem(attr.socialStats, idx, 'number', v, setAttr, 'socialStats'); }, __nextHasNoMarginBottom: true }),
81 el(TextControl, { label: __('Label', 'blockenberg'), value: stat.label, onChange: function (v) { setItem(attr.socialStats, idx, 'label', v, setAttr, 'socialStats'); }, __nextHasNoMarginBottom: true }),
82 el(Button, { onClick: function () { removeItem(attr.socialStats, idx, setAttr, 'socialStats'); }, variant: 'link', isDestructive: true, __nextHasNoMarginBottom: true }, __('Remove', 'blockenberg'))
83 );
84 }),
85 attr.showStats && el(Button, { onClick: function () { addItem(attr.socialStats, { number: '0', label: 'Label' }, setAttr, 'socialStats'); }, variant: 'secondary', style: { marginTop: 8 } }, __('+ Add Stat', 'blockenberg'))
86 ),
87 /* Image */
88 el(PanelBody, { title: __('Product Image', 'blockenberg'), initialOpen: false },
89 el(ToggleControl, { label: __('Show Image', 'blockenberg'), checked: attr.showImage, onChange: function (v) { setAttr({ showImage: v }); }, __nextHasNoMarginBottom: true }),
90 attr.showImage && el(MediaUploadCheck, null,
91 el(MediaUpload, {
92 onSelect: function (m) { setAttr({ imageUrl: m.url, imageId: m.id }); },
93 allowedTypes: ['image'], value: attr.imageId,
94 render: function (rp) {
95 return el('div', null,
96 attr.imageUrl && el('img', { src: attr.imageUrl, style: { maxWidth: '100%', borderRadius: 6, marginBottom: 6 } }),
97 el(Button, { onClick: rp.open, variant: 'secondary', size: 'small' }, attr.imageUrl ? __('Change Image', 'blockenberg') : __('Upload Image', 'blockenberg')),
98 attr.imageUrl && el(Button, { onClick: function () { setAttr({ imageUrl: '', imageId: 0 }); }, variant: 'link', isDestructive: true, size: 'small', style: { marginLeft: 8 } }, __('Remove', 'blockenberg'))
99 );
100 }
101 })
102 )
103 ),
104 /* Layout */
105 el(PanelBody, { title: __('Layout', 'blockenberg'), initialOpen: false },
106 el(SelectControl, { label: __('Layout', 'blockenberg'), value: attr.layout, options: [{ label: 'Centered', value: 'centered' }, { label: 'Split – Text Left', value: 'split-left' }, { label: 'Split – Text Right', value: 'split-right' }], onChange: function (v) { setAttr({ layout: v }); }, __nextHasNoMarginBottom: true }),
107 el(RangeControl, { label: __('Max Width', 'blockenberg'), value: attr.maxWidth, min: 600, max: 1600, step: 20, onChange: function (v) { setAttr({ maxWidth: v }); }, __nextHasNoMarginBottom: true }),
108 el(RangeControl, { label: __('Padding Top', 'blockenberg'), value: attr.paddingTop, min: 0, max: 200, onChange: function (v) { setAttr({ paddingTop: v }); }, __nextHasNoMarginBottom: true }),
109 el(RangeControl, { label: __('Padding Bottom', 'blockenberg'), value: attr.paddingBottom, min: 0, max: 200, onChange: function (v) { setAttr({ paddingBottom: v }); }, __nextHasNoMarginBottom: true })
110 ),
111 el(PanelColorSettings, {
112 title: __('Colors', 'blockenberg'), initialOpen: false,
113 colorSettings: [
114 { label: __('Background', 'blockenberg'), value: attr.bgColor, onChange: function (v) { setAttr({ bgColor: v || '#0f172a' }); } },
115 { label: __('Heading', 'blockenberg'), value: attr.headingColor, onChange: function (v) { setAttr({ headingColor: v || '#f8fafc' }); } },
116 { label: __('Subtext', 'blockenberg'), value: attr.subColor, onChange: function (v) { setAttr({ subColor: v || '#94a3b8' }); } },
117 { label: __('Badge Background', 'blockenberg'), value: attr.badgeBg, onChange: function (v) { setAttr({ badgeBg: v || 'rgba(99,102,241,0.15)' }); } },
118 { label: __('Badge Text', 'blockenberg'), value: attr.badgeColor, onChange: function (v) { setAttr({ badgeColor: v || '#a5b4fc' }); } },
119 { label: __('CTA Button', 'blockenberg'), value: attr.ctaBg, onChange: function (v) { setAttr({ ctaBg: v || '#6366f1' }); } },
120 { label: __('CTA Text', 'blockenberg'), value: attr.ctaColor, onChange: function (v) { setAttr({ ctaColor: v || '#ffffff' }); } },
121 { label: __('Secondary Button Text', 'blockenberg'), value: attr.ctaSecColor, onChange: function (v) { setAttr({ ctaSecColor: v || '#a5b4fc' }); } },
122 { label: __('Trust Text', 'blockenberg'), value: attr.trustColor, onChange: function (v) { setAttr({ trustColor: v || '#94a3b8' }); } },
123 { label: __('Stat Number', 'blockenberg'), value: attr.statNumColor, onChange: function (v) { setAttr({ statNumColor: v || '#f8fafc' }); } },
124 { label: __('Stat Label', 'blockenberg'), value: attr.statLabelColor, onChange: function (v) { setAttr({ statLabelColor: v || '#64748b' }); } },
125 { label: __('Accent', 'blockenberg'), value: attr.accentColor, onChange: function (v) { setAttr({ accentColor: v || '#6366f1' }); } }
126 ]
127 }),
128 el(PanelBody, { title: __('Typography', 'blockenberg'), initialOpen: false },
129 el(RangeControl, { label: __('Badge font size (px)', 'blockenberg'), value: attr.badgeFontSize, min: 10, max: 20, onChange: function (v) { setAttr({ badgeFontSize: v }); }, __nextHasNoMarginBottom: true }),
130 _tc() && el(_tc(), { label: __('Heading'), typo: attr.typoHeading || {}, onChange: function (v) { setAttr({ typoHeading: v }); }, defaultSize: attr.headingFontSize || 36 }),
131 _tc() && el(_tc(), { label: __('Subtext'), typo: attr.typoSubtext || {}, onChange: function (v) { setAttr({ typoSubtext: v }); }, defaultSize: attr.subtextFontSize || 18 }),
132 el(RangeControl, { label: __('CTA button font size (px)', 'blockenberg'), value: attr.ctaFontSize, min: 11, max: 24, onChange: function (v) { setAttr({ ctaFontSize: v }); }, __nextHasNoMarginBottom: true }),
133 el(RangeControl, { label: __('Stat number font size (px)', 'blockenberg'), value: attr.statNumFontSize, min: 16, max: 48, onChange: function (v) { setAttr({ statNumFontSize: v }); }, __nextHasNoMarginBottom: true }),
134 el(RangeControl, { label: __('Stat label font size (px)', 'blockenberg'), value: attr.statLabelFontSize, min: 10, max: 18, onChange: function (v) { setAttr({ statLabelFontSize: v }); }, __nextHasNoMarginBottom: true })
135 )
136 ),
137 /* Editor Preview */
138 el('div', Object.assign(useBlockProps({ className: 'bkbg-dms-editor', style: Object.assign({ background: attr.bgColor, '--bkbg-dms-hdg-fs': (attr.headingFontSize || 36) + 'px', '--bkbg-dms-sub-fs': (attr.subtextFontSize || 18) + 'px' }, _tv(attr.typoHeading || {}, '--bkbg-dms-hdg-'), _tv(attr.typoSubtext || {}, '--bkbg-dms-sub-')) })),
139 el('div', { className: 'bkbg-dms-inner layout-' + attr.layout, style: { maxWidth: attr.maxWidth + 'px', margin: '0 auto', padding: attr.paddingTop + 'px 24px ' + attr.paddingBottom + 'px' } },
140 /* Text column */
141 el('div', { className: 'bkbg-dms-text' },
142 attr.badge && el('div', { className: 'bkbg-dms-badge', style: { background: attr.badgeBg, color: attr.badgeColor, fontSize: (attr.badgeFontSize || 13) + 'px' } }, attr.badge),
143 el(RichText, { tagName: 'h2', className: 'bkbg-dms-heading', style: { color: attr.headingColor }, value: attr.heading, onChange: function (v) { setAttr({ heading: v }); }, placeholder: __('Heading…', 'blockenberg') }),
144 el(RichText, { tagName: 'p', className: 'bkbg-dms-sub', style: { color: attr.subColor }, value: attr.subtext, onChange: function (v) { setAttr({ subtext: v }); }, placeholder: __('Subtext…', 'blockenberg') }),
145 /* CTA */
146 el('div', { className: 'bkbg-dms-cta-row' },
147 attr.ctaMode === 'button'
148 ? el(wp.element.Fragment, null,
149 el('a', { className: 'bkbg-dms-btn-primary', style: { background: attr.ctaBg, color: attr.ctaColor, fontSize: (attr.ctaFontSize || 16) + 'px' }, href: '#' }, attr.ctaLabel),
150 attr.showCtaSec && el('a', { className: 'bkbg-dms-btn-sec', style: { color: attr.ctaSecColor, border: '1px solid ' + attr.ctaSecColor + '88', fontSize: (attr.ctaFontSize || 16) + 'px' }, href: '#' }, attr.ctaSecLabel)
151 )
152 : el('div', { className: 'bkbg-dms-form-preview' },
153 el('div', { className: 'bkbg-dms-input-fake', style: { color: attr.trustColor } }, attr.formPlaceholder),
154 el('div', { className: 'bkbg-dms-submit-fake', style: { background: attr.ctaBg, color: attr.ctaColor } }, attr.formSubmitLabel)
155 )
156 ),
157 /* Trust */
158 attr.showTrust && el('div', { className: 'bkbg-dms-trust' },
159 attr.trustItems.map(function (item, idx) {
160 return el('span', { key: idx, className: 'bkbg-dms-trust-item', style: { color: attr.trustColor } },
161 el('span', { className: 'bkbg-dms-trust-icon' },
162 (item.iconType || 'custom-char') !== 'custom-char' ? IP().buildEditorIcon(item.iconType, item.icon, item.iconDashicon, item.iconImageUrl, item.iconDashiconColor) : item.icon
163 ),
164 item.text
165 );
166 })
167 ),
168 /* Stats */
169 attr.showStats && el('div', { className: 'bkbg-dms-stats' },
170 attr.socialStats.map(function (stat, idx) {
171 return el('div', { key: idx, className: 'bkbg-dms-stat' },
172 el('div', { className: 'bkbg-dms-stat-num', style: { color: attr.statNumColor, fontSize: (attr.statNumFontSize || 28) + 'px' } }, stat.number),
173 el('div', { className: 'bkbg-dms-stat-label', style: { color: attr.statLabelColor, fontSize: (attr.statLabelFontSize || 13) + 'px' } }, stat.label)
174 );
175 })
176 )
177 ),
178 /* Image column */
179 attr.showImage && isSplit && el('div', { className: 'bkbg-dms-image-col', style: { background: attr.imageBg } },
180 attr.imageUrl
181 ? el('img', { src: attr.imageUrl, className: 'bkbg-dms-screenshot', alt: '' })
182 : el('div', { className: 'bkbg-dms-img-placeholder', style: { background: attr.accentColor + '22', color: attr.accentColor } }, '🖥')
183 ),
184 /* Centered image (below content) */
185 attr.showImage && !isSplit && el('div', { className: 'bkbg-dms-image-centered', style: { background: attr.imageBg } },
186 attr.imageUrl
187 ? el('img', { src: attr.imageUrl, className: 'bkbg-dms-screenshot', alt: '' })
188 : el('div', { className: 'bkbg-dms-img-placeholder', style: { background: attr.accentColor + '22', color: attr.accentColor } }, '🖥')
189 )
190 )
191 )
192 );
193 },
194 save: function (props) {
195 var attr = props.attributes;
196 var useBlockProps = wp.blockEditor.useBlockProps;
197 return el('div', useBlockProps.save(),
198 el('div', { className: 'bkbg-dms-app', 'data-opts': JSON.stringify(attr) })
199 );
200 }
201 });
202 }() );
203