PluginProbe
Blockenberg — 600+ Advanced Gutenberg Blocks & AI Agent for WordPress Block Editor / 2.0.14
Blockenberg — 600+ Advanced Gutenberg Blocks & AI Agent for WordPress Block Editor v2.0.14
2.0.14 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 / tldr-box / index.js

index.js in Blockenberg — 600+ Advanced Gutenberg Blocks & AI Agent for WordPress Block Editor 2.0.14, at blocks/tldr-box/index.js

194 lines 12.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 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 SelectControl = wp.components.SelectControl;
13 var TextControl = wp.components.TextControl;
14 var Button = wp.components.Button;
15
16 // Resolve the shared components lazily without defining globals for each block.
17 function _tc(props, key, label) {
18 var Control = window.bkbgTypographyControl;
19 return Control ? el(Control, {
20 label: label,
21 value: props.attributes[key] || {},
22 onChange: function (value) { var update = {}; update[key] = value; props.setAttributes(update); }
23 }) : null;
24 }
25 function _tvf(typo, prefix) {
26 var cssVars = window.bkbgTypoCssVars;
27 return cssVars ? cssVars(typo || {}, prefix) : {};
28 }
29 function getTypoControl(props, attrName, label) { return _tc(props, attrName, label); }
30
31 var _IP;
32 function IP() { return _IP || (_IP = window.bkbgIconPicker); }
33
34 var STYLE_OPTIONS = [
35 { value: 'highlight', label: 'Highlight (accent fill)' },
36 { value: 'minimal', label: 'Minimal (clean border)' },
37 { value: 'card', label: 'Card (shadow)' },
38 { value: 'sidebar', label: 'Sidebar (left stripe)' }
39 ];
40
41 registerBlockType('blockenberg/tldr-box', {
42 edit: function (props) {
43 var attr = props.attributes;
44 var set = props.setAttributes;
45 var points = attr.points || [{ text: '' }];
46
47 var blockProps = (function () {
48 var s = { paddingTop: attr.paddingTop + 'px', paddingBottom: attr.paddingBottom + 'px' };
49 var tv = Object.assign({}, _tvf(attr.headingTypo, '--bktldr-ht-'), _tvf(attr.summaryTypo, '--bktldr-st-'));
50 for (var k in tv) s[k] = tv[k];
51 return useBlockProps({ style: s });
52 }());
53
54 function updatePoint(idx, val) {
55 set({ points: points.map(function (p, i) { return i === idx ? { text: val } : p; }) });
56 }
57
58 var wrapStyle = {
59 background: attr.bgColor,
60 borderRadius: attr.borderRadius + 'px',
61 overflow: 'hidden',
62 position: 'relative'
63 };
64 if (attr.style === 'highlight') {
65 wrapStyle.border = '1px solid ' + attr.borderColor;
66 wrapStyle.padding = '18px 22px';
67 } else if (attr.style === 'minimal') {
68 wrapStyle.border = '1px solid ' + attr.borderColor;
69 wrapStyle.padding = '18px 22px';
70 wrapStyle.background = 'transparent';
71 } else if (attr.style === 'card') {
72 wrapStyle.border = '1px solid ' + attr.borderColor;
73 wrapStyle.padding = '20px 24px';
74 wrapStyle.boxShadow = '0 4px 14px rgba(0,0,0,0.08)';
75 } else if (attr.style === 'sidebar') {
76 wrapStyle.borderLeft = '5px solid ' + attr.accentColor;
77 wrapStyle.borderTop = '1px solid ' + attr.borderColor;
78 wrapStyle.borderRight = '1px solid ' + attr.borderColor;
79 wrapStyle.borderBottom = '1px solid ' + attr.borderColor;
80 wrapStyle.padding = '18px 22px';
81 }
82
83 var controls = el(InspectorControls, {},
84 el(PanelBody, { title: __('Content', 'blockenberg'), initialOpen: true },
85 el(ToggleControl, { label: __('Show Icon', 'blockenberg'), checked: attr.showIcon, __nextHasNoMarginBottom: true, onChange: function (v) { set({ showIcon: v }); } }),
86 attr.showIcon && el('div', { style: { marginTop: '8px' } },
87 el(IP().IconPickerControl, IP().iconPickerProps(attr, set, { charAttr: 'headingIcon' }))
88 ),
89 el('div', { style: { marginTop: '8px' } },
90 el(TextControl, { label: __('Heading Text', 'blockenberg'), value: attr.heading, __nextHasNoMarginBottom: true, onChange: function (v) { set({ heading: v }); } })
91 ),
92 el('div', { style: { marginTop: '8px' } },
93 el(ToggleControl, { label: __('Show Bullet Points', 'blockenberg'), checked: attr.showPoints, __nextHasNoMarginBottom: true, onChange: function (v) { set({ showPoints: v }); } })
94 ),
95 el('div', { style: { marginTop: '8px' } },
96 el(ToggleControl, { label: __('Show Read Time', 'blockenberg'), checked: attr.showReadTime, __nextHasNoMarginBottom: true, onChange: function (v) { set({ showReadTime: v }); } })
97 ),
98 attr.showReadTime && el('div', { style: { marginTop: '8px' } },
99 el(TextControl, { label: __('Read Time', 'blockenberg'), value: attr.readTime, placeholder: '8 min read', __nextHasNoMarginBottom: true, onChange: function (v) { set({ readTime: v }); } })
100 ),
101 el('div', { style: { marginTop: '8px' } },
102 el(ToggleControl, { label: __('Expandable (show/hide toggle)', 'blockenberg'), checked: attr.expandable, __nextHasNoMarginBottom: true, onChange: function (v) { set({ expandable: v }); } })
103 ),
104 attr.expandable && el('div', { style: { marginTop: '8px' } },
105 el(TextControl, { label: __('Collapse Label', 'blockenberg'), value: attr.collapseLabel, __nextHasNoMarginBottom: true, onChange: function (v) { set({ collapseLabel: v }); } })
106 ),
107 attr.expandable && el('div', { style: { marginTop: '8px' } },
108 el(TextControl, { label: __('Expand Label', 'blockenberg'), value: attr.expandLabel, __nextHasNoMarginBottom: true, onChange: function (v) { set({ expandLabel: v }); } })
109 )
110 ),
111 el(PanelBody, { title: __('Style & Spacing', 'blockenberg'), initialOpen: false },
112 el(SelectControl, { label: __('Style', 'blockenberg'), value: attr.style, options: STYLE_OPTIONS, __nextHasNoMarginBottom: true, onChange: function (v) { set({ style: v }); } }),
113 el('div', { style: { marginTop: '10px' } },
114 el(RangeControl, { label: __('Border Radius', 'blockenberg'), value: attr.borderRadius, min: 0, max: 30, __nextHasNoMarginBottom: true, onChange: function (v) { set({ borderRadius: v }); } })
115 ),
116 el('div', { style: { marginTop: '10px' } },
117 el(RangeControl, { label: __('Padding Top', 'blockenberg'), value: attr.paddingTop, min: 0, max: 100, __nextHasNoMarginBottom: true, onChange: function (v) { set({ paddingTop: v }); } })
118 ),
119 el('div', { style: { marginTop: '10px' } },
120 el(RangeControl, { label: __('Padding Bottom', 'blockenberg'), value: attr.paddingBottom, min: 0, max: 100, __nextHasNoMarginBottom: true, onChange: function (v) { set({ paddingBottom: v }); } })
121 )
122 ),
123 el(PanelBody, { title: __('Typography', 'blockenberg'), initialOpen: false },
124 getTypoControl(props, 'headingTypo', __('Heading', 'blockenberg')),
125 getTypoControl(props, 'summaryTypo', __('Summary', 'blockenberg'))
126 ),
127 el(PanelColorSettings, {
128 title: __('Colors', 'blockenberg'), initialOpen: false,
129 colorSettings: [
130 { label: __('Background', 'blockenberg'), value: attr.bgColor, onChange: function (v) { set({ bgColor: v || '#fef9c3' }); } },
131 { label: __('Border', 'blockenberg'), value: attr.borderColor, onChange: function (v) { set({ borderColor: v || '#fde047' }); } },
132 { label: __('Accent', 'blockenberg'), value: attr.accentColor, onChange: function (v) { set({ accentColor: v || '#ca8a04' }); } },
133 { label: __('Heading', 'blockenberg'), value: attr.headingColor, onChange: function (v) { set({ headingColor: v || '#713f12' }); } },
134 { label: __('Icon', 'blockenberg'), value: attr.iconColor, onChange: function (v) { set({ iconColor: v || '#ca8a04' }); } },
135 { label: __('Summary', 'blockenberg'), value: attr.summaryColor, onChange: function (v) { set({ summaryColor: v || '#1c1917' }); } },
136 { label: __('Bullet Points', 'blockenberg'), value: attr.pointColor, onChange: function (v) { set({ pointColor: v || '#292524' }); } },
137 { label: __('Meta / Read Time', 'blockenberg'), value: attr.metaColor, onChange: function (v) { set({ metaColor: v || '#a8a29e' }); } }
138 ]
139 })
140 );
141
142 /* header row */
143 var headerRow = el('div', { style: { display: 'flex', alignItems: 'center', gap: '8px', marginBottom: '10px', flexWrap: 'wrap' } },
144 attr.showIcon && IP().buildEditorIcon(attr.iconType, attr.headingIcon, attr.iconDashicon, attr.iconImageUrl, { dashiconColor: attr.iconDashiconColor, style: { fontSize: '20px', lineHeight: 1, display: 'inline-flex', alignItems: 'center', justifyContent: 'center', color: attr.iconColor } }),
145 el('span', { className: 'bkbg-tldr-heading', style: { color: attr.headingColor } }, attr.heading),
146 attr.showReadTime && attr.readTime && el('span', { style: { marginLeft: 'auto', fontSize: '12px', color: attr.metaColor, fontWeight: 500 } }, attr.readTime)
147 );
148
149 /* summary */
150 var summaryEl = el(RichText, {
151 tagName: 'p', value: attr.summary, className: 'bkbg-tldr-summary',
152 allowedFormats: ['core/bold', 'core/italic', 'core/link'],
153 placeholder: __('One or two sentence summary of the article…', 'blockenberg'),
154 style: { color: attr.summaryColor },
155 onChange: function (v) { set({ summary: v }); }
156 });
157
158 /* point list */
159 var pointList = attr.showPoints && el('div', {},
160 el('div', { style: { borderTop: '1px solid ' + attr.borderColor + '80', marginBottom: '10px', marginTop: '8px' } }),
161 points.map(function (p, idx) {
162 return el('div', { key: idx, style: { display: 'flex', alignItems: 'center', gap: '8px', marginBottom: '5px' } },
163 el('span', { style: { color: attr.accentColor, fontWeight: 700, fontSize: '16px', flexShrink: 0, lineHeight: 1 } }, '✓'),
164 el(TextControl, { value: p.text, label: '', placeholder: __('Bullet point…', 'blockenberg'), __nextHasNoMarginBottom: true, style: { flex: 1, fontSize: '14px' }, onChange: function (v) { updatePoint(idx, v); } }),
165 el(Button, { isSmall: true, isDestructive: true, variant: 'tertiary', onClick: function () { set({ points: points.filter(function (_, i) { return i !== idx; }) }); } }, '×')
166 ) }),
167 el(Button, { variant: 'link', style: { fontSize: '11px' }, onClick: function () { set({ points: points.concat([{ text: '' }]) }); } }, '+ Add Point')
168 );
169
170 return el('div', blockProps,
171 controls,
172 el('div', { style: wrapStyle },
173 headerRow,
174 summaryEl,
175 pointList,
176 attr.expandable && el('div', { style: { marginTop: '10px', fontSize: '12px', color: attr.accentColor, fontWeight: 600, cursor: 'pointer' } }, '▼ ' + attr.collapseLabel)
177 )
178 );
179 },
180 save: function (props) {
181 var attr = props.attributes;
182 var useBlockProps = wp.blockEditor.useBlockProps;
183 return el('div', (function () {
184 var s = {};
185 var tv = Object.assign({}, _tvf(attr.headingTypo, '--bktldr-ht-'), _tvf(attr.summaryTypo, '--bktldr-st-'));
186 for (var k in tv) s[k] = tv[k];
187 return useBlockProps.save({ style: s });
188 }()),
189 el('div', { className: 'bkbg-tldr-app', 'data-opts': JSON.stringify(attr) })
190 );
191 }
192 });
193 }() );
194