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 / integration-wall / index.js

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

153 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 __ = 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
18 var _TypographyControl, _typoCssVars;
19 function getTypographyControl() { return _TypographyControl || (_TypographyControl = window.bkbgTypographyControl); }
20 function getTypoCssVars() { return _typoCssVars || (_typoCssVars = window.bkbgTypoCssVars); }
21
22 function setInteg(arr, idx, key, val, setAttr) {
23 var next = arr.map(function (it, i) { return i === idx ? Object.assign({}, it, { [key]: val }) : it; });
24 setAttr({ integrations: next });
25 }
26
27 var LOGO_LETTERS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
28 function logoLetter(name) { return (name || '?').charAt(0).toUpperCase(); }
29
30 function renderCard(integ, o) {
31 return el('div', { className: 'bkbg-igw-card', style: { background: o.cardBg, borderColor: o.cardBorder } },
32 integ.logoUrl
33 ? el('img', { src: integ.logoUrl, className: 'bkbg-igw-logo-img', alt: integ.name })
34 : el('div', { className: 'bkbg-igw-logo-fallback', style: { background: o.logoBg, color: o.logoColor } }, logoLetter(integ.name)),
35 el('div', { className: 'bkbg-igw-card-body' },
36 el('div', { className: 'bkbg-igw-integ-name', style: { color: o.nameColor } }, integ.name),
37 o.showDesc && integ.description && el('div', { className: 'bkbg-igw-integ-desc', style: { color: o.descColor } }, integ.description)
38 )
39 );
40 }
41
42 registerBlockType('blockenberg/integration-wall', {
43 edit: function (props) {
44 var attr = props.attributes;
45 var setAttr = props.setAttributes;
46
47 /* Derive categories for filter preview */
48 var cats = ['All'];
49 attr.integrations.forEach(function (it) { if (it.category && cats.indexOf(it.category) === -1) cats.push(it.category); });
50
51 return el(wp.element.Fragment, null,
52 el(InspectorControls, null,
53 el(PanelBody, { title: __('Content', 'blockenberg'), initialOpen: true },
54 el(TextControl, { label: __('Eyebrow', 'blockenberg'), value: attr.eyebrow, onChange: function (v) { setAttr({ eyebrow: v }); }, __nextHasNoMarginBottom: true }),
55 el(TextControl, { label: __('Heading', 'blockenberg'), value: attr.heading, onChange: function (v) { setAttr({ heading: v }); }, __nextHasNoMarginBottom: true }),
56 el(TextControl, { label: __('Subtext', 'blockenberg'), value: attr.subtext, onChange: function (v) { setAttr({ subtext: v }); }, __nextHasNoMarginBottom: true })
57 ),
58 el(PanelBody, { title: __('Layout', 'blockenberg'), initialOpen: false },
59 el(SelectControl, { label: __('Card Style', 'blockenberg'), value: attr.cardStyle, options: [{ label: 'Card with description', value: 'card' }, { label: 'Logo & Name only', value: 'compact' }, { label: 'Pill tags', value: 'pill' }], onChange: function (v) { setAttr({ cardStyle: v }); }, __nextHasNoMarginBottom: true }),
60 el(RangeControl, { label: __('Columns', 'blockenberg'), value: attr.columns, min: 2, max: 8, onChange: function (v) { setAttr({ columns: v }); }, __nextHasNoMarginBottom: true }),
61 el(ToggleControl, { label: __('Show Category Filter', 'blockenberg'), checked: attr.showFilter, onChange: function (v) { setAttr({ showFilter: v }); }, __nextHasNoMarginBottom: true }),
62 el(ToggleControl, { label: __('Show Description', 'blockenberg'), checked: attr.showDesc, onChange: function (v) { setAttr({ showDesc: v }); }, __nextHasNoMarginBottom: true }),
63 el(ToggleControl, { label: __('Show Browse All CTA', 'blockenberg'), checked: attr.showCta, onChange: function (v) { setAttr({ showCta: v }); }, __nextHasNoMarginBottom: true }),
64 attr.showCta && el(TextControl, { label: __('CTA Label', 'blockenberg'), value: attr.ctaLabel, onChange: function (v) { setAttr({ ctaLabel: v }); }, __nextHasNoMarginBottom: true }),
65 attr.showCta && el(TextControl, { label: __('CTA URL', 'blockenberg'), value: attr.ctaUrl, onChange: function (v) { setAttr({ ctaUrl: v }); }, __nextHasNoMarginBottom: true }),
66 el(RangeControl, { label: __('Max Width', 'blockenberg'), value: attr.maxWidth, min: 600, max: 1600, step: 20, onChange: function (v) { setAttr({ maxWidth: v }); }, __nextHasNoMarginBottom: true }),
67 el(RangeControl, { label: __('Padding Top', 'blockenberg'), value: attr.paddingTop, min: 0, max: 200, onChange: function (v) { setAttr({ paddingTop: v }); }, __nextHasNoMarginBottom: true }),
68 el(RangeControl, { label: __('Padding Bottom', 'blockenberg'), value: attr.paddingBottom, min: 0, max: 200, onChange: function (v) { setAttr({ paddingBottom: v }); }, __nextHasNoMarginBottom: true })
69 ),
70 el(PanelColorSettings, {
71 title: __('Colors', 'blockenberg'), initialOpen: false,
72 colorSettings: [
73 { label: __('Background', 'blockenberg'), value: attr.bgColor, onChange: function (v) { setAttr({ bgColor: v || '#ffffff' }); } },
74 { label: __('Heading', 'blockenberg'), value: attr.headingColor, onChange: function (v) { setAttr({ headingColor: v || '#111827' }); } },
75 { label: __('Subtext', 'blockenberg'), value: attr.subColor, onChange: function (v) { setAttr({ subColor: v || '#6b7280' }); } },
76 { label: __('Eyebrow', 'blockenberg'), value: attr.eyebrowColor, onChange: function (v) { setAttr({ eyebrowColor: v || '#6366f1' }); } },
77 { label: __('Card Background', 'blockenberg'), value: attr.cardBg, onChange: function (v) { setAttr({ cardBg: v || '#f8fafc' }); } },
78 { label: __('Card Border', 'blockenberg'), value: attr.cardBorder, onChange: function (v) { setAttr({ cardBorder: v || '#e2e8f0' }); } },
79 { label: __('Integration Name', 'blockenberg'), value: attr.nameColor, onChange: function (v) { setAttr({ nameColor: v || '#111827' }); } },
80 { label: __('Description', 'blockenberg'), value: attr.descColor, onChange: function (v) { setAttr({ descColor: v || '#6b7280' }); } },
81 { label: __('Logo Background', 'blockenberg'), value: attr.logoBg, onChange: function (v) { setAttr({ logoBg: v || '#e0e7ff' }); } },
82 { label: __('Logo Letter', 'blockenberg'), value: attr.logoColor, onChange: function (v) { setAttr({ logoColor: v || '#4338ca' }); } },
83 { label: __('Filter Background', 'blockenberg'), value: attr.filterBg, onChange: function (v) { setAttr({ filterBg: v || '#f1f5f9' }); } },
84 { label: __('Active Filter', 'blockenberg'), value: attr.filterActiveBg, onChange: function (v) { setAttr({ filterActiveBg: v || '#6366f1' }); } },
85 { label: __('Accent', 'blockenberg'), value: attr.accentColor, onChange: function (v) { setAttr({ accentColor: v || '#6366f1' }); } }
86 ]
87 }),
88 /* Integration management */
89 el(PanelBody, { title: __('Integrations', 'blockenberg'), initialOpen: false },
90 attr.integrations.map(function (integ, idx) {
91 return el(PanelBody, { key: idx, title: (integ.name || 'Integration ' + (idx + 1)), initialOpen: false },
92 el(TextControl, { label: __('Name', 'blockenberg'), value: integ.name, onChange: function (v) { setInteg(attr.integrations, idx, 'name', v, setAttr); }, __nextHasNoMarginBottom: true }),
93 el(TextControl, { label: __('Category', 'blockenberg'), value: integ.category, onChange: function (v) { setInteg(attr.integrations, idx, 'category', v, setAttr); }, __nextHasNoMarginBottom: true }),
94 el(TextControl, { label: __('Description', 'blockenberg'), value: integ.description, onChange: function (v) { setInteg(attr.integrations, idx, 'description', v, setAttr); }, __nextHasNoMarginBottom: true }),
95 el(TextControl, { label: __('Link URL', 'blockenberg'), value: integ.url, onChange: function (v) { setInteg(attr.integrations, idx, 'url', v, setAttr); }, __nextHasNoMarginBottom: true }),
96 el('p', { style: { marginBottom: 4, fontSize: 11, textTransform: 'uppercase', color: '#888' } }, __('Logo Image', 'blockenberg')),
97 el(MediaUploadCheck, null,
98 el(MediaUpload, {
99 onSelect: function (m) { setInteg(attr.integrations, idx, 'logoUrl', m.url, setAttr); },
100 allowedTypes: ['image'], value: integ.logoUrl,
101 render: function (rp) {
102 return el('div', null,
103 integ.logoUrl && el('img', { src: integ.logoUrl, style: { maxHeight: 36, marginBottom: 6, display: 'block' } }),
104 el(Button, { onClick: rp.open, variant: 'secondary', size: 'small' }, integ.logoUrl ? __('Change', 'blockenberg') : __('Upload Logo', 'blockenberg')),
105 integ.logoUrl && el(Button, { onClick: function () { setInteg(attr.integrations, idx, 'logoUrl', '', setAttr); }, variant: 'link', isDestructive: true, size: 'small', style: { marginLeft: 8 } }, __('Remove', 'blockenberg'))
106 );
107 }
108 })
109 ),
110 el(Button, { onClick: function () { setAttr({ integrations: attr.integrations.filter(function (_, i) { return i !== idx; }) }); }, variant: 'link', isDestructive: true, __nextHasNoMarginBottom: true }, __('Remove Integration', 'blockenberg'))
111 );
112 }),
113 el(Button, { onClick: function () { setAttr({ integrations: attr.integrations.concat([{ name: 'New App', category: 'Category', logoUrl: '', url: '#', description: 'Short description' }]) }); }, variant: 'secondary', style: { marginTop: 8 } }, __('+ Add Integration', 'blockenberg'))
114 ),
115 el(PanelBody, { title: 'Typography', initialOpen: false },
116 el(getTypographyControl(), { label: 'Heading', value: attr.headingTypo, onChange: function(v){ setAttr({ headingTypo: v }); } }),
117 el(getTypographyControl(), { label: 'Subtext', value: attr.subtextTypo, onChange: function(v){ setAttr({ subtextTypo: v }); } }),
118 el(getTypographyControl(), { label: 'Item Name', value: attr.nameTypo, onChange: function(v){ setAttr({ nameTypo: v }); } })
119 )
120 ),
121 /* Editor Preview */
122 el('div', Object.assign(useBlockProps({ className: 'bkbg-igw-editor', style: (function(){ var _tv = getTypoCssVars(); var s = { background: attr.bgColor }; Object.assign(s, _tv(attr.headingTypo, '--bkbg-igw-h-')); Object.assign(s, _tv(attr.subtextTypo, '--bkbg-igw-st-')); Object.assign(s, _tv(attr.nameTypo, '--bkbg-igw-nm-')); return s; })() })),
123 el('div', { className: 'bkbg-igw-inner', style: { maxWidth: attr.maxWidth + 'px', margin: '0 auto', padding: attr.paddingTop + 'px 24px ' + attr.paddingBottom + 'px' } },
124 el('div', { className: 'bkbg-igw-header', style: { textAlign: 'center', marginBottom: 40 } },
125 el(RichText, { tagName: 'p', className: 'bkbg-igw-eyebrow', style: { color: attr.eyebrowColor }, value: attr.eyebrow, onChange: function (v) { setAttr({ eyebrow: v }); }, placeholder: __('Eyebrow…', 'blockenberg') }),
126 el(RichText, { tagName: 'h2', className: 'bkbg-igw-heading', style: { color: attr.headingColor }, value: attr.heading, onChange: function (v) { setAttr({ heading: v }); }, placeholder: __('Heading…', 'blockenberg') }),
127 el(RichText, { tagName: 'p', className: 'bkbg-igw-sub', style: { color: attr.subColor }, value: attr.subtext, onChange: function (v) { setAttr({ subtext: v }); }, placeholder: __('Subtext…', 'blockenberg') })
128 ),
129 attr.showFilter && el('div', { className: 'bkbg-igw-filter' },
130 cats.map(function (cat, idx) {
131 return el('button', { key: idx, className: 'bkbg-igw-pill', style: idx === 0 ? { background: attr.filterActiveBg, color: attr.filterActiveColor } : { background: attr.filterBg, color: attr.filterColor } }, cat);
132 })
133 ),
134 el('div', { className: 'bkbg-igw-grid card-style-' + attr.cardStyle, style: { gridTemplateColumns: 'repeat(' + attr.columns + ',1fr)' } },
135 attr.integrations.map(function (integ, idx) { return el(wp.element.Fragment, { key: idx }, renderCard(integ, attr)); })
136 ),
137 attr.showCta && el('div', { className: 'bkbg-igw-cta-row' },
138 el('a', { href: '#', className: 'bkbg-igw-cta', style: { color: attr.accentColor } }, attr.ctaLabel)
139 )
140 )
141 )
142 );
143 },
144 save: function (props) {
145 var attr = props.attributes;
146 var useBlockProps = wp.blockEditor.useBlockProps;
147 return el('div', useBlockProps.save(),
148 el('div', { className: 'bkbg-igw-app', 'data-opts': JSON.stringify(attr) })
149 );
150 }
151 });
152 }() );
153