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 / resource-links / index.js

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

154 lines 12.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 Fragment = wp.element.Fragment;
4 var __ = wp.i18n.__;
5 var registerBlockType = wp.blocks.registerBlockType;
6 var InspectorControls = wp.blockEditor.InspectorControls;
7 var useBlockProps = wp.blockEditor.useBlockProps;
8 var RichText = wp.blockEditor.RichText;
9 var PanelBody = wp.components.PanelBody;
10 var PanelColorSettings = wp.blockEditor.PanelColorSettings;
11 var ToggleControl = wp.components.ToggleControl;
12 var RangeControl = wp.components.RangeControl;
13 var SelectControl = wp.components.SelectControl;
14 var TextControl = wp.components.TextControl;
15 var Button = wp.components.Button;
16
17 var _tc; function getTypoControl() { return _tc || (_tc = window.bkbgTypographyControl); }
18 var _tv; function getTypoCssVars() { return _tv || (_tv = window.bkbgTypoCssVars); }
19 var IP = function () { return window.bkbgIconPicker; };
20
21 function ResourceCard(item, attr, i, updateItem, removeItem, showArrow) {
22 var cardStyle = {
23 display: 'flex',
24 alignItems: 'center',
25 gap: 16,
26 background: attr.cardBg,
27 border: '1px solid ' + attr.cardBorder,
28 borderRadius: attr.borderRadius + 'px',
29 padding: '16px 20px',
30 textDecoration: 'none'
31 };
32 return el('div', { key: i, style: Object.assign({ marginBottom: 12 }, attr.layout === 'grid' ? {} : {}) },
33 el('div', { style: cardStyle },
34 el('span', { className: 'bkbg-rl-icon', style: { fontSize: attr.iconSize + 'px', flexShrink: 0 } },
35 IP().buildEditorIcon(item.iconType || 'custom-char', item.icon, item.iconDashicon, item.iconImageUrl, item.iconDashiconColor)
36 ),
37 el('div', { style: { flex: 1, minWidth: 0 } },
38 el('div', { style: { display: 'flex', alignItems: 'center', gap: 8, flexWrap: 'wrap', marginBottom: 4 } },
39 el(RichText, { tagName: 'strong', value: item.title, onChange: function (v) { updateItem(i, 'title', v); }, className: 'bkbg-rl-title', style: { color: attr.titleColor }, placeholder: __('Title', 'blockenberg') }),
40 item.tag && el('span', { style: { background: attr.tagBg, color: attr.tagColor, borderRadius: 4, padding: '1px 8px', fontSize: 11, fontWeight: 600 } }, item.tag)
41 ),
42 el(RichText, { tagName: 'p', value: item.description, onChange: function (v) { updateItem(i, 'description', v); }, className: 'bkbg-rl-desc', style: { color: attr.descColor, margin: 0 }, placeholder: __('Description', 'blockenberg') })
43 ),
44 showArrow && el('span', { style: { color: attr.arrowColor, fontSize: 20, flexShrink: 0 } }, '')
45 )
46 );
47 }
48
49 registerBlockType('blockenberg/resource-links', {
50 edit: function (props) {
51 var attr = props.attributes;
52 var setAttr = props.setAttributes;
53 var TC = getTypoControl();
54 var blockProps = useBlockProps((function () {
55 var _tvFn = getTypoCssVars();
56 var s = {};
57 if (_tvFn) {
58 Object.assign(s, _tvFn(attr.headingTypo || {}, '--bkrl-ht-'));
59 Object.assign(s, _tvFn(attr.titleTypo || {}, '--bkrl-tt-'));
60 Object.assign(s, _tvFn(attr.bodyTypo || {}, '--bkrl-bt-'));
61 }
62 return { className: 'bkbg-rl-editor', style: s };
63 })());
64
65 function updateItem(i, key, val) {
66 var next = attr.items.map(function (item, j) { return j === i ? Object.assign({}, item, { [key]: val }) : item; });
67 setAttr({ items: next });
68 }
69
70 function removeItem(i) {
71 setAttr({ items: attr.items.filter(function (_, j) { return j !== i; }) });
72 }
73
74 var previewStyle = { background: attr.bgColor, padding: attr.paddingTop + 'px 40px ' + attr.paddingBottom + 'px' };
75 var innerStyle = { maxWidth: attr.maxWidth + 'px', margin: '0 auto' };
76 var gridStyle = attr.layout === 'grid' ? { display: 'grid', gridTemplateColumns: 'repeat(' + attr.columns + ', 1fr)', gap: 16 } : {};
77
78 return el(Fragment, null,
79 el(InspectorControls, null,
80 el(PanelBody, { title: __('Section', 'blockenberg'), initialOpen: true },
81 el(ToggleControl, { label: __('Show Heading', 'blockenberg'), __nextHasNoMarginBottom: true, checked: attr.showHeading, onChange: function (v) { setAttr({ showHeading: v }); } }),
82 el(ToggleControl, { label: __('Show Subtext', 'blockenberg'), __nextHasNoMarginBottom: true, checked: attr.showSubtext, onChange: function (v) { setAttr({ showSubtext: v }); } }),
83 el(SelectControl, { label: __('Layout', 'blockenberg'), __nextHasNoMarginBottom: true, value: attr.layout,
84 options: [{ label: 'List', value: 'list' }, { label: 'Grid', value: 'grid' }],
85 onChange: function (v) { setAttr({ layout: v }); } }),
86 attr.layout === 'grid' && el(RangeControl, { label: __('Columns', 'blockenberg'), __nextHasNoMarginBottom: true, value: attr.columns, min: 1, max: 4, onChange: function (v) { setAttr({ columns: v }); } }),
87 el(ToggleControl, { label: __('Open Links in New Tab', 'blockenberg'), __nextHasNoMarginBottom: true, checked: attr.openNewTab, onChange: function (v) { setAttr({ openNewTab: v }); } }),
88 el(ToggleControl, { label: __('Show Arrow →', 'blockenberg'), __nextHasNoMarginBottom: true, checked: attr.showArrow, onChange: function (v) { setAttr({ showArrow: v }); } })
89 ),
90 el(PanelBody, { title: __('Items', 'blockenberg'), initialOpen: false },
91 attr.items.map(function (item, i) {
92 return el('div', { key: i, style: { borderLeft: '3px solid #7c3aed', paddingLeft: 8, marginBottom: 12 } },
93 el(IP().IconPickerControl, IP().iconPickerProps(item, function (key, val) { updateItem(i, key, val); }, { label: __('Icon', 'blockenberg') + ' ' + (i + 1), typeAttr: 'iconType', dashiconAttr: 'iconDashicon', imageUrlAttr: 'iconImageUrl' })),
94 el(TextControl, { label: __('Title', 'blockenberg'), __nextHasNoMarginBottom: true, value: item.title, onChange: function (v) { updateItem(i, 'title', v); } }),
95 el(TextControl, { label: __('Description', 'blockenberg'), __nextHasNoMarginBottom: true, value: item.description, onChange: function (v) { updateItem(i, 'description', v); } }),
96 el(TextControl, { label: __('URL', 'blockenberg'), __nextHasNoMarginBottom: true, value: item.url, onChange: function (v) { updateItem(i, 'url', v); } }),
97 el(TextControl, { label: __('Type Tag', 'blockenberg'), __nextHasNoMarginBottom: true, value: item.tag, onChange: function (v) { updateItem(i, 'tag', v); } }),
98 attr.items.length > 1 && el(Button, { onClick: function () { removeItem(i); }, variant: 'link', isDestructive: true, __nextHasNoMarginBottom: true }, __('Remove', 'blockenberg'))
99 );
100 }),
101 el(Button, { onClick: function () { setAttr({ items: attr.items.concat([{ icon: '🔗', iconType: 'custom-char', iconDashicon: '', iconImageUrl: '', title: 'New Resource', description: '', url: '#', tag: 'Link' }]) }); }, variant: 'secondary', __nextHasNoMarginBottom: true }, __('+ Add Item', 'blockenberg'))
102 ),
103 el(PanelBody, { title: __('Sizing', 'blockenberg'), initialOpen: false },
104 el(RangeControl, { label: __('Icon Size (px)', 'blockenberg'), __nextHasNoMarginBottom: true, value: attr.iconSize, min: 14, max: 48, onChange: function (v) { setAttr({ iconSize: v }); } }),
105 el(RangeControl, { label: __('Card Radius (px)', 'blockenberg'), __nextHasNoMarginBottom: true, value: attr.borderRadius, min: 0, max: 24, onChange: function (v) { setAttr({ borderRadius: v }); } }),
106 el(RangeControl, { label: __('Max Width (px)', 'blockenberg'), __nextHasNoMarginBottom: true, value: attr.maxWidth, min: 400, max: 1400, step: 10, onChange: function (v) { setAttr({ maxWidth: v }); } }),
107 el(RangeControl, { label: __('Padding Top (px)', 'blockenberg'), __nextHasNoMarginBottom: true, value: attr.paddingTop, min: 0, max: 200, onChange: function (v) { setAttr({ paddingTop: v }); } }),
108 el(RangeControl, { label: __('Padding Bottom (px)', 'blockenberg'), __nextHasNoMarginBottom: true, value: attr.paddingBottom, min: 0, max: 200, onChange: function (v) { setAttr({ paddingBottom: v }); } })
109 ),
110
111 el(PanelBody, { title: __('Typography', 'blockenberg'), initialOpen: false },
112 TC && el(TC, { label: __('Heading', 'blockenberg'), value: attr.headingTypo || {}, onChange: function(v) { setAttr({ headingTypo: v }); } }),
113 TC && el(TC, { label: __('Item Title', 'blockenberg'), value: attr.titleTypo || {}, onChange: function(v) { setAttr({ titleTypo: v }); } }),
114 TC && el(TC, { label: __('Description', 'blockenberg'), value: attr.bodyTypo || {}, onChange: function(v) { setAttr({ bodyTypo: v }); } })
115 ),
116 el(PanelColorSettings, {
117 title: __('Colors', 'blockenberg'), initialOpen: false,
118 colorSettings: [
119 { value: attr.bgColor, onChange: function (v) { setAttr({ bgColor: v || '#ffffff' }); }, label: __('Page Background', 'blockenberg') },
120 { value: attr.cardBg, onChange: function (v) { setAttr({ cardBg: v || '#f9fafb' }); }, label: __('Card Background', 'blockenberg') },
121 { value: attr.cardBorder, onChange: function (v) { setAttr({ cardBorder: v || '#e5e7eb' }); }, label: __('Card Border', 'blockenberg') },
122 { value: attr.headingColor, onChange: function (v) { setAttr({ headingColor: v || '#111827' }); }, label: __('Heading', 'blockenberg') },
123 { value: attr.subtextColor, onChange: function (v) { setAttr({ subtextColor: v || '#6b7280' }); }, label: __('Subtext', 'blockenberg') },
124 { value: attr.titleColor, onChange: function (v) { setAttr({ titleColor: v || '#111827' }); }, label: __('Item Title', 'blockenberg') },
125 { value: attr.descColor, onChange: function (v) { setAttr({ descColor: v || '#6b7280' }); }, label: __('Item Desc', 'blockenberg') },
126 { value: attr.tagBg, onChange: function (v) { setAttr({ tagBg: v || '#ede9fe' }); }, label: __('Tag Background', 'blockenberg') },
127 { value: attr.tagColor, onChange: function (v) { setAttr({ tagColor: v || '#7c3aed' }); }, label: __('Tag Text', 'blockenberg') },
128 { value: attr.arrowColor, onChange: function (v) { setAttr({ arrowColor: v || '#9ca3af' }); }, label: __('Arrow', 'blockenberg') },
129 { value: attr.hoverBg, onChange: function (v) { setAttr({ hoverBg: v || '#f3f0ff' }); }, label: __('Card Hover BG', 'blockenberg') }
130 ]
131 })
132 ),
133 el('div', blockProps,
134 el('div', { style: previewStyle },
135 el('div', { style: innerStyle },
136 attr.showHeading && el(RichText, { tagName: 'h2', value: attr.heading, onChange: function (v) { setAttr({ heading: v }); }, className: 'bkbg-rl-heading', style: { color: attr.headingColor, margin: '0 0 8px' }, placeholder: __('Section heading…', 'blockenberg') }),
137 attr.showSubtext && el(RichText, { tagName: 'p', value: attr.subtext, onChange: function (v) { setAttr({ subtext: v }); }, style: { fontSize: 16 + 'px', color: attr.subtextColor, margin: '0 0 32px', lineHeight: 1.6 }, placeholder: __('Subtitle…', 'blockenberg') }),
138 el('div', { style: gridStyle },
139 attr.items.map(function (item, i) { return ResourceCard(item, attr, i, updateItem, removeItem, attr.showArrow); })
140 )
141 )
142 )
143 )
144 );
145 },
146 save: function (props) {
147 var attr = props.attributes;
148 return el('div', useBlockProps.save(),
149 el('div', { className: 'bkbg-resource-links-app', 'data-opts': JSON.stringify(attr) })
150 );
151 }
152 });
153 }() );
154