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

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

197 lines 17.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 useBlockProps = wp.blockEditor.useBlockProps;
7 var RichText = wp.blockEditor.RichText;
8 var PanelColorSettings = wp.blockEditor.PanelColorSettings;
9 var PanelBody = wp.components.PanelBody;
10 var ToggleControl = wp.components.ToggleControl;
11 var RangeControl = wp.components.RangeControl;
12 var TextControl = wp.components.TextControl;
13 var TextareaControl = wp.components.TextareaControl;
14 var Button = wp.components.Button;
15
16 var _tc, _tv;
17 function getTypoControl() { return _tc || (_tc = window.bkbgTypographyControl); }
18 function getTypoCssVars() { return _tv || (_tv = window.bkbgTypoCssVars); }
19
20 registerBlockType('blockenberg/newsletter-section', {
21 edit: function (props) {
22 var attr = props.attributes;
23 var set = props.setAttributes;
24
25 var blockProps = useBlockProps((function () {
26 var _tvf = getTypoCssVars();
27 var s = { background: attr.bgColor };
28 if (_tvf) {
29 Object.assign(s, _tvf(attr.headingTypo, '--bkbg-nls-ht-'));
30 Object.assign(s, _tvf(attr.subtextTypo, '--bkbg-nls-st-'));
31 }
32 return { className: 'bkbg-nls-wrap', style: s };
33 })());
34
35 /* Issue editor */
36 function IssuesEditor() {
37 return el('div', {},
38 el('label', { style: { display: 'block', fontSize: '11px', fontWeight: 500, textTransform: 'uppercase', marginBottom: '8px', color: '#1e1e1e' } }, __('Sample Issues', 'blockenberg')),
39 (attr.sampleIssues || []).map(function (issue, idx) {
40 return el('div', { key: idx, style: { border: '1px solid #e2e8f0', borderRadius: '6px', padding: '10px', marginBottom: '8px', background: '#f8fafc' } },
41 el(TextControl, { label: __('Title', 'blockenberg'), value: issue.title, __nextHasNoMarginBottom: true, onChange: function (v) { var arr = attr.sampleIssues.map(function (s, i) { return i === idx ? Object.assign({}, s, { title: v }) : s; }); set({ sampleIssues: arr }); } }),
42 el('div', { style: { marginTop: '6px' } },
43 el(TextControl, { label: __('Date', 'blockenberg'), value: issue.date, __nextHasNoMarginBottom: true, onChange: function (v) { var arr = attr.sampleIssues.map(function (s, i) { return i === idx ? Object.assign({}, s, { date: v }) : s; }); set({ sampleIssues: arr }); } })
44 ),
45 el('div', { style: { marginTop: '6px' } },
46 el(TextareaControl, { label: __('Excerpt', 'blockenberg'), value: issue.excerpt, __nextHasNoMarginBottom: true, rows: 2, onChange: function (v) { var arr = attr.sampleIssues.map(function (s, i) { return i === idx ? Object.assign({}, s, { excerpt: v }) : s; }); set({ sampleIssues: arr }); } })
47 ),
48 el(Button, { variant: 'link', isDestructive: true, __nextHasNoMarginBottom: true, style: { marginTop: '4px' }, onClick: function () { set({ sampleIssues: attr.sampleIssues.filter(function (_, i) { return i !== idx; }) }); } }, __('Remove Issue', 'blockenberg'))
49 );
50 }),
51 el(Button, { variant: 'secondary', __nextHasNoMarginBottom: true, style: { marginTop: '4px' }, onClick: function () { set({ sampleIssues: (attr.sampleIssues || []).concat([{ title: 'Issue Title', date: 'Apr 1, 2024', excerpt: 'A brief excerpt from this issue...' }]) }); } }, __('+ Add Issue', 'blockenberg'))
52 );
53 }
54
55 /* Benefits editor */
56 function BenefitsEditor() {
57 return el('div', {},
58 el('label', { style: { display: 'block', fontSize: '11px', fontWeight: 500, textTransform: 'uppercase', marginBottom: '8px', color: '#1e1e1e' } }, __('Benefits', 'blockenberg')),
59 (attr.benefits || []).map(function (b, idx) {
60 return el('div', { key: idx, style: { display: 'flex', gap: '6px', marginBottom: '6px' } },
61 el(TextControl, { value: b, __nextHasNoMarginBottom: true, onChange: function (v) { var arr = attr.benefits.slice(); arr[idx] = v; set({ benefits: arr }); } }),
62 el(Button, { variant: 'tertiary', isDestructive: true, onClick: function () { set({ benefits: attr.benefits.filter(function (_, i) { return i !== idx; }) }); } }, '')
63 );
64 }),
65 el(Button, { variant: 'secondary', __nextHasNoMarginBottom: true, style: { marginTop: '4px' }, onClick: function () { set({ benefits: (attr.benefits || []).concat(['New benefit']) }); } }, __('+ Add Benefit', 'blockenberg'))
66 );
67 }
68
69 /* Preview */
70 var previewStyle = {
71 padding: attr.paddingTop + 'px 32px ' + attr.paddingBottom + 'px',
72 maxWidth: attr.maxWidth + 'px', margin: '0 auto'
73 };
74
75 var controls = el(InspectorControls, {},
76 el(PanelBody, { title: __('Copy', 'blockenberg'), initialOpen: true },
77 el(TextControl, { label: __('Eyebrow', 'blockenberg'), value: attr.eyebrow, __nextHasNoMarginBottom: true, onChange: function (v) { set({ eyebrow: v }); } }),
78 el('div', { style: { marginTop: '12px' } },
79 el(TextControl, { label: __('Subscriber Count Badge', 'blockenberg'), value: attr.subscriberCount, __nextHasNoMarginBottom: true, onChange: function (v) { set({ subscriberCount: v }); } })
80 ),
81 el('div', { style: { marginTop: '8px' } },
82 el(ToggleControl, { label: __('Show Subscriber Badge', 'blockenberg'), checked: attr.showSubscriberBadge, __nextHasNoMarginBottom: true, onChange: function (v) { set({ showSubscriberBadge: v }); } })
83 ),
84 el('div', { style: { marginTop: '12px' } },
85 el(TextControl, { label: __('Form Placeholder', 'blockenberg'), value: attr.formPlaceholder, __nextHasNoMarginBottom: true, onChange: function (v) { set({ formPlaceholder: v }); } })
86 ),
87 el('div', { style: { marginTop: '8px' } },
88 el(TextControl, { label: __('Submit Label', 'blockenberg'), value: attr.formSubmitLabel, __nextHasNoMarginBottom: true, onChange: function (v) { set({ formSubmitLabel: v }); } })
89 ),
90 el('div', { style: { marginTop: '8px' } },
91 el(TextControl, { label: __('Form Action URL', 'blockenberg'), value: attr.formAction, __nextHasNoMarginBottom: true, onChange: function (v) { set({ formAction: v }); } })
92 ),
93 el('div', { style: { marginTop: '8px' } },
94 el(TextControl, { label: __('Privacy Note', 'blockenberg'), value: attr.privacyNote, __nextHasNoMarginBottom: true, onChange: function (v) { set({ privacyNote: v }); } })
95 ),
96 el('div', { style: { marginTop: '8px' } },
97 el(TextareaControl, { label: __('Success Message', 'blockenberg'), value: attr.successMessage, __nextHasNoMarginBottom: true, onChange: function (v) { set({ successMessage: v }); } })
98 )
99 ),
100 el(PanelBody, { title: __('Benefits', 'blockenberg'), initialOpen: false },
101 el(ToggleControl, { label: __('Show Benefits', 'blockenberg'), checked: attr.showBenefits, __nextHasNoMarginBottom: true, onChange: function (v) { set({ showBenefits: v }); } }),
102 attr.showBenefits && BenefitsEditor()
103 ),
104 el(PanelBody, { title: __('Past Issues', 'blockenberg'), initialOpen: false },
105 el(ToggleControl, { label: __('Show Sample Issues', 'blockenberg'), checked: attr.showSamples, __nextHasNoMarginBottom: true, onChange: function (v) { set({ showSamples: v }); } }),
106 attr.showSamples && IssuesEditor()
107 ),
108 el(PanelBody, { title: __('Spacing', 'blockenberg'), initialOpen: false },
109 el(RangeControl, { label: __('Padding Top', 'blockenberg'), value: attr.paddingTop, min: 0, max: 200, __nextHasNoMarginBottom: true, onChange: function (v) { set({ paddingTop: v }); } }),
110 el('div', { style: { marginTop: '12px' } },
111 el(RangeControl, { label: __('Padding Bottom', 'blockenberg'), value: attr.paddingBottom, min: 0, max: 200, __nextHasNoMarginBottom: true, onChange: function (v) { set({ paddingBottom: v }); } })
112 ),
113 el('div', { style: { marginTop: '12px' } },
114 el(RangeControl, { label: __('Max Width (px)', 'blockenberg'), value: attr.maxWidth, min: 600, max: 1600, step: 20, __nextHasNoMarginBottom: true, onChange: function (v) { set({ maxWidth: v }); } })
115 )
116 ),
117 el(PanelColorSettings, {
118 title: __('Colors', 'blockenberg'), initialOpen: false,
119 colorSettings: [
120 { label: __('Background', 'blockenberg'), value: attr.bgColor, onChange: function (v) { set({ bgColor: v || '#0f172a' }); } },
121 { label: __('Accent', 'blockenberg'), value: attr.accentColor, onChange: function (v) { set({ accentColor: v || '#6366f1' }); } },
122 { label: __('Eyebrow', 'blockenberg'), value: attr.eyebrowColor, onChange: function (v) { set({ eyebrowColor: v || '#818cf8' }); } },
123 { label: __('Heading', 'blockenberg'), value: attr.headingColor, onChange: function (v) { set({ headingColor: v || '#f8fafc' }); } },
124 { label: __('Subtext', 'blockenberg'), value: attr.subColor, onChange: function (v) { set({ subColor: v || '#94a3b8' }); } },
125 { label: __('Benefit Text', 'blockenberg'), value: attr.benefitColor, onChange: function (v) { set({ benefitColor: v || '#cbd5e1' }); } },
126 { label: __('Check Icon', 'blockenberg'), value: attr.checkColor, onChange: function (v) { set({ checkColor: v || '#22d3ee' }); } },
127 { label: __('Input Background', 'blockenberg'), value: attr.inputBg, onChange: function (v) { set({ inputBg: v || '#1e293b' }); } },
128 { label: __('Input Border', 'blockenberg'), value: attr.inputBorder, onChange: function (v) { set({ inputBorder: v || '#334155' }); } },
129 { label: __('Input Text', 'blockenberg'), value: attr.inputColor, onChange: function (v) { set({ inputColor: v || '#f1f5f9' }); } },
130 { label: __('Submit Button', 'blockenberg'), value: attr.submitBg, onChange: function (v) { set({ submitBg: v || '#6366f1' }); } },
131 { label: __('Submit Text', 'blockenberg'), value: attr.submitColor, onChange: function (v) { set({ submitColor: v || '#ffffff' }); } },
132 { label: __('Privacy Note', 'blockenberg'), value: attr.privacyColor, onChange: function (v) { set({ privacyColor: v || '#64748b' }); } },
133 { label: __('Issue Card Background', 'blockenberg'), value: attr.issueBg, onChange: function (v) { set({ issueBg: v || '#1e293b' }); } },
134 { label: __('Issue Card Border', 'blockenberg'), value: attr.issueBorder, onChange: function (v) { set({ issueBorder: v || '#334155' }); } },
135 { label: __('Issue Title', 'blockenberg'), value: attr.issueTitleColor, onChange: function (v) { set({ issueTitleColor: v || '#f1f5f9' }); } },
136 { label: __('Issue Date', 'blockenberg'), value: attr.issueDateColor, onChange: function (v) { set({ issueDateColor: v || '#818cf8' }); } },
137 { label: __('Issue Excerpt', 'blockenberg'), value: attr.issueExcerptColor, onChange: function (v) { set({ issueExcerptColor: v || '#94a3b8' }); } }
138 ]
139 }),
140 el(PanelBody, { title: __('Typography', 'blockenberg'), initialOpen: false },
141 getTypoControl() && el(getTypoControl(), { label: __('Heading Typography', 'blockenberg'), value: attr.headingTypo, onChange: function (v) { set({ headingTypo: v }); } }),
142 getTypoControl() && el(getTypoControl(), { label: __('Subtext Typography', 'blockenberg'), value: attr.subtextTypo, onChange: function (v) { set({ subtextTypo: v }); } })
143 )
144 );
145
146 return el('div', blockProps,
147 controls,
148 el('div', { className: 'bkbg-nls-inner', style: previewStyle },
149 /* Header */
150 el('div', { className: 'bkbg-nls-header', style: { textAlign: 'center', marginBottom: '48px' } },
151 el('p', { style: { color: attr.eyebrowColor, fontSize: '13px', fontWeight: 700, textTransform: 'uppercase', letterSpacing: '0.08em', margin: '0 0 12px' } }, attr.eyebrow),
152 attr.showSubscriberBadge && el('div', { style: { display: 'inline-flex', alignItems: 'center', gap: '6px', background: attr.subscriberBadgeBg, color: attr.subscriberBadgeColor, borderRadius: '20px', padding: '4px 14px', fontSize: '13px', fontWeight: 600, marginBottom: '16px' } }, '👥 ', attr.subscriberCount),
153 el(RichText, { tagName: 'h2', value: attr.heading, className: 'bkbg-nls-heading', style: { color: attr.headingColor, margin: '0 0 16px' }, placeholder: __('Heading…', 'blockenberg'), onChange: function (v) { set({ heading: v }); } }),
154 el(RichText, { tagName: 'p', value: attr.subtext, className: 'bkbg-nls-sub', style: { color: attr.subColor, margin: '0', maxWidth: '640px', marginLeft: 'auto', marginRight: 'auto' }, placeholder: __('Subtext…', 'blockenberg'), onChange: function (v) { set({ subtext: v }); } })
155 ),
156 /* Main grid */
157 el('div', { style: { display: 'grid', gridTemplateColumns: '1fr 1fr', gap: '48px', alignItems: 'start' } },
158 /* Left: form + benefits */
159 el('div', {},
160 attr.showBenefits && el('ul', { style: { listStyle: 'none', padding: 0, margin: '0 0 28px' } },
161 (attr.benefits || []).map(function (b, i) {
162 return el('li', { key: i, style: { display: 'flex', gap: '10px', marginBottom: '12px', color: attr.benefitColor, fontSize: '16px', alignItems: 'flex-start' } },
163 el('span', { style: { color: attr.checkColor, fontWeight: 700, flexShrink: 0 } }, ''), b
164 );
165 })
166 ),
167 el('div', { style: { display: 'flex', gap: '10px', marginBottom: '10px' } },
168 el('input', { type: 'email', readOnly: true, placeholder: attr.formPlaceholder, style: { flex: 1, padding: '14px 16px', background: attr.inputBg, border: '1px solid ' + attr.inputBorder, color: attr.inputColor, borderRadius: '8px', fontSize: '15px' } }),
169 el('button', { style: { padding: '14px 22px', background: attr.submitBg, color: attr.submitColor, border: 'none', borderRadius: '8px', fontWeight: 700, fontSize: '15px', cursor: 'pointer', whiteSpace: 'nowrap' } }, attr.formSubmitLabel)
170 ),
171 el('p', { style: { color: attr.privacyColor, fontSize: '13px', margin: 0 } }, attr.privacyNote)
172 ),
173 /* Right: sample issues */
174 attr.showSamples && el('div', {},
175 el('p', { style: { color: attr.eyebrowColor, fontSize: '12px', fontWeight: 700, textTransform: 'uppercase', letterSpacing: '0.06em', margin: '0 0 16px' } }, __('Recent Issues', 'blockenberg')),
176 (attr.sampleIssues || []).map(function (issue, i) {
177 return el('div', { key: i, style: { background: attr.issueBg, border: '1px solid ' + attr.issueBorder, borderRadius: '8px', padding: '16px', marginBottom: '10px' } },
178 el('p', { style: { color: attr.issueDateColor, fontSize: '11px', fontWeight: 700, textTransform: 'uppercase', margin: '0 0 4px' } }, issue.date),
179 el('p', { style: { color: attr.issueTitleColor, fontWeight: 700, fontSize: '14px', margin: '0 0 6px', lineHeight: '1.4' } }, issue.title),
180 el('p', { style: { color: attr.issueExcerptColor, fontSize: '13px', margin: 0, lineHeight: '1.5' } }, issue.excerpt)
181 );
182 })
183 )
184 )
185 )
186 );
187 },
188 save: function (props) {
189 var attr = props.attributes;
190 var useBlockProps = wp.blockEditor.useBlockProps;
191 return el('div', useBlockProps.save(),
192 el('div', { className: 'bkbg-nls-app', 'data-opts': JSON.stringify(attr) })
193 );
194 }
195 });
196 }() );
197