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 / link-card / index.js

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

189 lines 11.9 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 PanelColorSettings = wp.blockEditor.PanelColorSettings;
8 var PanelBody = wp.components.PanelBody;
9 var ToggleControl = wp.components.ToggleControl;
10 var RangeControl = wp.components.RangeControl;
11 var SelectControl = wp.components.SelectControl;
12 var TextControl = wp.components.TextControl;
13 var Button = wp.components.Button;
14
15 var _tc, _tv;
16 function getTypoControl() { return _tc || (_tc = window.bkbgTypographyControl); }
17 function getTypoCssVars() { return _tv || (_tv = window.bkbgTypoCssVars); }
18 var IP = function () { return window.bkbgIconPicker; };
19
20 function CardItem(props) {
21 var card = props.card;
22 var idx = props.idx;
23 var set = props.onChange;
24 var attr = props.attr;
25
26 return el('div', {
27 style: {
28 border: '1px solid ' + attr.borderColor,
29 borderRadius: attr.cardRadius + 'px',
30 padding: attr.cardPadding + 'px',
31 background: attr.cardBg,
32 position: 'relative', display: 'flex', flexDirection: 'column', gap: '8px'
33 }
34 },
35 el('div', { style: { display: 'flex', alignItems: 'center', gap: '10px' } },
36 attr.showIcon && el('span', { className: 'bkbg-lkc-icon', style: { fontSize: attr.iconSize + 'px', lineHeight: 1 } }, (card.iconType || 'custom-char') !== 'custom-char' && IP() ? IP().buildEditorIcon(card.iconType, card.icon, card.iconDashicon, card.iconImageUrl, card.iconDashiconColor) : (card.icon || '📄')),
37 el(TextControl, {
38 value: card.title, placeholder: __('Card title', 'blockenberg'),
39 style: { fontWeight: '700', margin: 0 },
40 onChange: function (v) { set('title', v); }, __nextHasNoMarginBottom: true
41 })
42 ),
43 el(TextControl, {
44 value: card.description, placeholder: __('Short description', 'blockenberg'),
45 style: { color: attr.descColor, margin: 0 },
46 onChange: function (v) { set('description', v); }, __nextHasNoMarginBottom: true
47 }),
48 el('div', { style: { display: 'flex', gap: '8px', flexWrap: 'wrap', marginTop: '4px' } },
49 IP() && el(IP().IconPickerControl, {
50 iconType: card.iconType || 'custom-char',
51 customChar: card.icon || '',
52 dashicon: card.iconDashicon || '',
53 imageUrl: card.iconImageUrl || '',
54 onChangeType: function (v) { set('iconType', v); },
55 onChangeChar: function (v) { set('icon', v); },
56 onChangeDashicon: function (v) { set('iconDashicon', v); },
57 onChangeImageUrl: function (v) { set('iconImageUrl', v); }
58 }),
59 el(TextControl, { label: __('URL', 'blockenberg'), value: card.url, onChange: function (v) { set('url', v); }, __nextHasNoMarginBottom: true })
60 ),
61 el(ToggleControl, { label: __('Open in new tab', 'blockenberg'), checked: card.isExternal, onChange: function (v) { set('isExternal', v); }, __nextHasNoMarginBottom: true }),
62 el(Button, { isSmall: true, isDestructive: true, onClick: props.onRemove, style: { alignSelf: 'flex-end' } }, __('Remove card', 'blockenberg'))
63 );
64 }
65
66 registerBlockType('blockenberg/link-card', {
67 edit: function (props) {
68 var attr = props.attributes;
69 var setAttr = props.setAttributes;
70 var blockProps = useBlockProps((function () {
71 var _tvFn = getTypoCssVars();
72 var s = {};
73 if (_tvFn) {
74 Object.assign(s, _tvFn(attr.titleTypo, '--bkbg-lkc-tt-'));
75 Object.assign(s, _tvFn(attr.descTypo, '--bkbg-lkc-d-'));
76 }
77 return { className: 'bkbg-lkc-editor', style: s };
78 })());
79
80 function updateCard(idx, key, value) {
81 var next = attr.cards.map(function (c, i) {
82 if (i !== idx) return c;
83 var obj = {};
84 Object.keys(c).forEach(function (k) { obj[k] = c[k]; });
85 obj[key] = value;
86 return obj;
87 });
88 setAttr({ cards: next });
89 }
90
91 function removeCard(idx) {
92 setAttr({ cards: attr.cards.filter(function (_, i) { return i !== idx; }) });
93 }
94
95 function addCard() {
96 setAttr({ cards: attr.cards.concat([{ icon: '', iconType: 'custom-char', iconDashicon: '', iconImageUrl: '', title: 'New Card', description: 'Add a short description.', url: '#', isExternal: false, accentColor: '' }]) });
97 }
98
99 var gridStyle = {
100 display: 'grid',
101 gridTemplateColumns: 'repeat(' + attr.columns + ', 1fr)',
102 gap: attr.gap + 'px'
103 };
104 if (attr.columns > 2) gridStyle.gridTemplateColumns = 'repeat(' + attr.columns + ', 1fr)';
105
106 var controls = el(InspectorControls, {},
107 el(PanelBody, { title: __('Grid Settings', 'blockenberg'), initialOpen: true },
108 el(SelectControl, {
109 label: __('Columns', 'blockenberg'), value: attr.columns,
110 options: [{ label: '2', value: 2 }, { label: '3', value: 3 }, { label: '4', value: 4 }],
111 onChange: function (v) { setAttr({ columns: parseInt(v) }); }, __nextHasNoMarginBottom: true
112 }),
113 el(RangeControl, { label: __('Gap (px)', 'blockenberg'), value: attr.gap, min: 8, max: 48, onChange: function (v) { setAttr({ gap: v }); }, __nextHasNoMarginBottom: true }),
114 el(SelectControl, {
115 label: __('Card Style', 'blockenberg'), value: attr.cardStyle,
116 options: [
117 { label: 'Bordered', value: 'bordered' },
118 { label: 'Filled', value: 'filled' },
119 { label: 'Gradient', value: 'gradient' },
120 { label: 'Minimal', value: 'minimal' }
121 ],
122 onChange: function (v) { setAttr({ cardStyle: v }); }, __nextHasNoMarginBottom: true
123 }),
124 el(SelectControl, {
125 label: __('Hover Effect', 'blockenberg'), value: attr.hoverEffect,
126 options: [
127 { label: 'Lift (shadow)', value: 'lift' },
128 { label: 'Glow (accent shadow)', value: 'glow' },
129 { label: 'Slide accent bar', value: 'slide' },
130 { label: 'None', value: 'none' }
131 ],
132 onChange: function (v) { setAttr({ hoverEffect: v }); }, __nextHasNoMarginBottom: true
133 }),
134 el(ToggleControl, { label: __('Show Arrow', 'blockenberg'), checked: attr.showArrow, onChange: function (v) { setAttr({ showArrow: v }); }, __nextHasNoMarginBottom: true }),
135 el(ToggleControl, { label: __('Show Icon', 'blockenberg'), checked: attr.showIcon, onChange: function (v) { setAttr({ showIcon: v }); }, __nextHasNoMarginBottom: true }),
136 el(RangeControl, { label: __('Icon Size (px)', 'blockenberg'), value: attr.iconSize, min: 16, max: 64, onChange: function (v) { setAttr({ iconSize: v }); }, __nextHasNoMarginBottom: true }),
137 el(RangeControl, { label: __('Card Border Radius (px)', 'blockenberg'), value: attr.cardRadius, min: 0, max: 32, onChange: function (v) { setAttr({ cardRadius: v }); }, __nextHasNoMarginBottom: true }),
138 el(RangeControl, { label: __('Card Padding (px)', 'blockenberg'), value: attr.cardPadding, min: 8, max: 64, onChange: function (v) { setAttr({ cardPadding: v }); }, __nextHasNoMarginBottom: true }),
139 el(RangeControl, { label: __('Max Width (px)', 'blockenberg'), value: attr.maxWidth, min: 400, max: 1600, onChange: function (v) { setAttr({ maxWidth: v }); }, __nextHasNoMarginBottom: true }),
140 el(RangeControl, { label: __('Padding Top (px)', 'blockenberg'), value: attr.paddingTop, min: 0, max: 120, onChange: function (v) { setAttr({ paddingTop: v }); }, __nextHasNoMarginBottom: true }),
141 el(RangeControl, { label: __('Padding Bottom (px)', 'blockenberg'), value: attr.paddingBottom, min: 0, max: 120, onChange: function (v) { setAttr({ paddingBottom: v }); }, __nextHasNoMarginBottom: true })
142 ),
143
144 el( PanelBody, { title: __( 'Typography', 'blockenberg' ), initialOpen: false },
145 getTypoControl() && el(getTypoControl(), { label: __('Title'), value: attr.titleTypo || {}, onChange: function (v) { setAttr({ titleTypo: v }); } }),
146 getTypoControl() && el(getTypoControl(), { label: __('Description'), value: attr.descTypo || {}, onChange: function (v) { setAttr({ descTypo: v }); } })
147 ),
148 el(PanelColorSettings, {
149 title: __('Colors', 'blockenberg'), initialOpen: false,
150 colorSettings: [
151 { label: __('Section Background', 'blockenberg'), value: attr.bgColor, onChange: function (v) { setAttr({ bgColor: v || '#ffffff' }); } },
152 { label: __('Card Background', 'blockenberg'), value: attr.cardBg, onChange: function (v) { setAttr({ cardBg: v || '#ffffff' }); } },
153 { label: __('Border', 'blockenberg'), value: attr.borderColor, onChange: function (v) { setAttr({ borderColor: v || '#e5e7eb' }); } },
154 { label: __('Accent', 'blockenberg'), value: attr.accentColor, onChange: function (v) { setAttr({ accentColor: v || '#7c3aed' }); } },
155 { label: __('Title', 'blockenberg'), value: attr.titleColor, onChange: function (v) { setAttr({ titleColor: v || '#111827' }); } },
156 { label: __('Description', 'blockenberg'), value: attr.descColor, onChange: function (v) { setAttr({ descColor: v || '#6b7280' }); } },
157 { label: __('Arrow', 'blockenberg'), value: attr.arrowColor, onChange: function (v) { setAttr({ arrowColor: v || '#7c3aed' }); } }
158 ]
159 })
160 );
161
162 return el('div', blockProps, controls,
163 el('div', { style: { background: attr.bgColor, paddingTop: attr.paddingTop + 'px', paddingBottom: attr.paddingBottom + 'px' } },
164 el('div', { style: { maxWidth: attr.maxWidth + 'px', margin: '0 auto' } },
165 el('div', { style: gridStyle },
166 attr.cards.map(function (card, idx) {
167 return el(CardItem, {
168 key: idx, card: card, idx: idx, attr: attr,
169 onChange: function (key, val) { updateCard(idx, key, val); },
170 onRemove: function () { removeCard(idx); }
171 });
172 })
173 ),
174 el('div', { style: { textAlign: 'center', marginTop: '16px' } },
175 el(Button, { isSecondary: true, onClick: addCard }, __('+ Add Card', 'blockenberg'))
176 )
177 )
178 )
179 );
180 },
181
182 save: function (props) {
183 return el('div', wp.blockEditor.useBlockProps.save(),
184 el('div', { className: 'bkbg-lkc-app', 'data-opts': JSON.stringify(props.attributes) })
185 );
186 }
187 });
188 }() );
189