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 / text-columns / index.js

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

173 lines 10.7 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 useState = wp.element.useState;
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 PanelColorSettings = wp.blockEditor.PanelColorSettings;
10 var PanelBody = wp.components.PanelBody;
11 var ToggleControl = wp.components.ToggleControl;
12 var RangeControl = wp.components.RangeControl;
13 var SelectControl = wp.components.SelectControl;
14 var TextareaControl = wp.components.TextareaControl;
15 var Fragment = wp.element.Fragment;
16
17 var _tc; function getTypoControl() { return _tc || (_tc = window.bkbgTypographyControl); }
18 var _tv; function getTypoCssVars() { return _tv || (_tv = window.bkbgTypoCssVars); }
19
20 registerBlockType('blockenberg/text-columns', {
21 edit: function (props) {
22 var attr = props.attributes;
23 var set = props.setAttributes;
24 var cols = attr.columns || [];
25
26 /* Ensure cols array matches columnCount */
27 var count = attr.columnCount;
28 while (cols.length < count) { cols = cols.concat([{ content: '<p>Column text here…</p>' }]); }
29 if (cols.length !== count) { cols = cols.slice(0, count); }
30
31 function updateCol(idx, val) {
32 var updated = cols.map(function (c, i) { return i === idx ? { content: val } : c; });
33 set({ columns: updated });
34 }
35
36 var inspector = el(InspectorControls, {},
37 el(PanelBody, { title: __('Layout', 'blockenberg'), initialOpen: true },
38 el(RangeControl, { label: __('Number of Columns', 'blockenberg'), value: attr.columnCount, min: 2, max: 4, onChange: function (v) { set({ columnCount: v }); }, __nextHasNoMarginBottom: true }),
39 el(RangeControl, { label: __('Column Gap (px)', 'blockenberg'), value: attr.columnGap, min: 16, max: 100, onChange: function (v) { set({ columnGap: v }); }, __nextHasNoMarginBottom: true }),
40 el(SelectControl, {
41 label: __('Text Alignment', 'blockenberg'), value: attr.textAlign,
42 options: [{ label: 'Left', value: 'left' }, { label: 'Justify', value: 'justify' }, { label: 'Center', value: 'center' }],
43 onChange: function (v) { set({ textAlign: v }); }, __nextHasNoMarginBottom: true
44 })
45 ),
46 el(PanelBody, { title: __('Typography', 'blockenberg'), initialOpen: false },
47 getTypoControl() && getTypoControl()({
48 label: __('Body Text', 'blockenberg'),
49 value: attr.bodyTypo || {},
50 onChange: function (v) { set({ bodyTypo: v }); }
51 }),
52 getTypoControl() && getTypoControl()({
53 label: __('Pull Quote', 'blockenberg'),
54 value: attr.pullQuoteTypo || {},
55 onChange: function (v) { set({ pullQuoteTypo: v }); }
56 })
57 ),
58 el(PanelBody, { title: __('Drop Cap', 'blockenberg'), initialOpen: false },
59 el(ToggleControl, { label: __('Enable Drop Cap', 'blockenberg'), checked: attr.dropCap, onChange: function (v) { set({ dropCap: v }); }, __nextHasNoMarginBottom: true }),
60 attr.dropCap && el(RangeControl, { label: __('Drop Cap Size (lines)', 'blockenberg'), value: attr.dropCapSize, min: 2, max: 5, onChange: function (v) { set({ dropCapSize: v }); }, __nextHasNoMarginBottom: true })
61 ),
62 el(PanelBody, { title: __('Column Rule', 'blockenberg'), initialOpen: false },
63 el(ToggleControl, { label: __('Show Column Rule', 'blockenberg'), checked: attr.showRule, onChange: function (v) { set({ showRule: v }); }, __nextHasNoMarginBottom: true }),
64 attr.showRule && el(SelectControl, {
65 label: __('Rule Style', 'blockenberg'), value: attr.ruleStyle,
66 options: [{ label: 'Solid', value: 'solid' }, { label: 'Dashed', value: 'dashed' }, { label: 'Dotted', value: 'dotted' }, { label: 'Double', value: 'double' }],
67 onChange: function (v) { set({ ruleStyle: v }); }, __nextHasNoMarginBottom: true
68 }),
69 attr.showRule && el(RangeControl, { label: __('Rule Width (px)', 'blockenberg'), value: attr.ruleWidth, min: 1, max: 4, onChange: function (v) { set({ ruleWidth: v }); }, __nextHasNoMarginBottom: true })
70 ),
71 el(PanelBody, { title: __('Pull Quote', 'blockenberg'), initialOpen: false },
72 el(ToggleControl, { label: __('Show Pull Quote', 'blockenberg'), checked: attr.showPullQuote, onChange: function (v) { set({ showPullQuote: v }); }, __nextHasNoMarginBottom: true }),
73 attr.showPullQuote && el(TextareaControl, { label: __('Pull Quote Text', 'blockenberg'), value: attr.pullQuote, onChange: function (v) { set({ pullQuote: v }); }, rows: 3, __nextHasNoMarginBottom: true }),
74 attr.showPullQuote && el(SelectControl, {
75 label: __('Pull Quote Position', 'blockenberg'), value: attr.pullQuotePos,
76 options: [{ label: 'Above columns', value: 'above' }, { label: 'Between columns', value: 'between' }, { label: 'Below columns', value: 'below' }],
77 onChange: function (v) { set({ pullQuotePos: v }); }, __nextHasNoMarginBottom: true
78 })
79 ),
80 el(PanelBody, { title: __('Spacing', 'blockenberg'), initialOpen: false },
81 el(RangeControl, { label: __('Padding Top (px)', 'blockenberg'), value: attr.paddingTop, min: 0, max: 240, onChange: function (v) { set({ paddingTop: v }); }, __nextHasNoMarginBottom: true }),
82 el(RangeControl, { label: __('Padding Bottom (px)', 'blockenberg'), value: attr.paddingBottom, min: 0, max: 240, onChange: function (v) { set({ paddingBottom: v }); }, __nextHasNoMarginBottom: true })
83 ),
84 el(PanelColorSettings, {
85 title: __('Colors', 'blockenberg'), initialOpen: false,
86 colorSettings: [
87 { value: attr.bgColor, onChange: function (v) { set({ bgColor: v || '' }); }, label: __('Background', 'blockenberg') },
88 { value: attr.textColor, onChange: function (v) { set({ textColor: v || '#374151' }); }, label: __('Text', 'blockenberg') },
89 { value: attr.dropCapColor, onChange: function (v) { set({ dropCapColor: v || '#111827' }); }, label: __('Drop Cap', 'blockenberg') },
90 { value: attr.ruleColor, onChange: function (v) { set({ ruleColor: v || '#d1d5db' }); }, label: __('Column Rule', 'blockenberg') },
91 { value: attr.pullQuoteBorder, onChange: function (v) { set({ pullQuoteBorder: v || '#6366f1' }); }, label: __('Pull Quote Border', 'blockenberg') },
92 { value: attr.pullQuoteColor, onChange: function (v) { set({ pullQuoteColor: v || '#111827' }); }, label: __('Pull Quote Text', 'blockenberg') }
93 ]
94 })
95 );
96
97 var wrapStyle = {
98 background: attr.bgColor || 'transparent',
99 paddingTop: attr.paddingTop + 'px',
100 paddingBottom: attr.paddingBottom + 'px'
101 };
102 var _tvf = getTypoCssVars();
103 if (_tvf) { Object.assign(wrapStyle, _tvf(attr.bodyTypo, '--bktcl-bd-'), _tvf(attr.pullQuoteTypo, '--bktcl-pq-')); }
104
105 /* Drop cap CSS injected inline for editor preview */
106 var dropCapStyle = attr.dropCap ? el('style', { key: 'dc', dangerouslySetInnerHTML: { __html: '.bkbg-tc-col:first-child p:first-child::first-letter{float:left;font-size:' + attr.dropCapSize + 'em;line-height:0.75;padding-right:0.1em;color:' + attr.dropCapColor + ';font-weight:800;margin-top:0.1em}' } }) : null;
107
108 var colElStyle = {
109 flex: '1',
110 minWidth: 0,
111 color: attr.textColor,
112 textAlign: attr.textAlign,
113 borderLeft: attr.showRule ? (attr.ruleWidth + 'px ' + attr.ruleStyle + ' ' + attr.ruleColor) : 'none',
114 paddingLeft: attr.showRule ? (attr.columnGap / 2) + 'px' : '0'
115 };
116
117 var pullQuoteEl = attr.showPullQuote && attr.pullQuote ? el('blockquote', {
118 className: 'bkbg-tc-pullquote',
119 style: {
120 borderLeft: '4px solid ' + attr.pullQuoteBorder,
121 paddingLeft: '24px',
122 margin: '32px 0',
123 color: attr.pullQuoteColor,
124 }
125 }, attr.pullQuote) : null;
126
127 var gridStyle = {
128 display: 'flex',
129 gap: attr.columnGap + 'px',
130 alignItems: 'flex-start'
131 };
132
133 var colEls = cols.map(function (col, idx) {
134 var style = Object.assign({}, colElStyle);
135 if (idx === 0) { style.borderLeft = 'none'; style.paddingLeft = '0'; }
136 return el('div', { key: idx, className: 'bkbg-tc-col', style: style },
137 el(RichText, {
138 tagName: 'div', multiline: 'p',
139 identifier: 'column-' + idx,
140 value: col.content,
141 onChange: function (v) { updateCol(idx, v); },
142 placeholder: __('Column text…', 'blockenberg')
143 })
144 );
145 });
146
147 return el(Fragment, {},
148 dropCapStyle,
149 inspector,
150 el('div', useBlockProps({ style: wrapStyle }),
151 attr.showPullQuote && attr.pullQuotePos === 'above' && pullQuoteEl,
152 el('div', { style: gridStyle }, colEls),
153 attr.showPullQuote && attr.pullQuotePos !== 'above' && pullQuoteEl
154 )
155 );
156 },
157
158 save: function (props) {
159 var el2 = wp.element.createElement;
160 var ubp = wp.blockEditor.useBlockProps;
161 var a = props.attributes;
162 var _tvf = getTypoCssVars();
163 return el2('div', (function () {
164 var s = {};
165 if (_tvf) { Object.assign(s, _tvf(a.bodyTypo, '--bktcl-bd-'), _tvf(a.pullQuoteTypo, '--bktcl-pq-')); }
166 return ubp.save({ style: s });
167 })(),
168 el2('div', { className: 'bkbg-tc-app', 'data-opts': JSON.stringify(a) })
169 );
170 }
171 });
172 }() );
173