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 / dual-heading / index.js

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

163 lines 11.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 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 RangeControl = wp.components.RangeControl;
12 var SelectControl = wp.components.SelectControl;
13 var ToggleControl = wp.components.ToggleControl;
14
15 var _dhTC, _dhTV;
16 function _tc() { return _dhTC || (_dhTC = window.bkbgTypographyControl); }
17 function _tv(t, p) { return (_dhTV || (_dhTV = window.bkbgTypoCssVars)) ? _dhTV(t, p) : {}; }
18
19 function buildLineStyle(color, effect, effectColor, effectColor2, strokeColor, strokeWidth) {
20 var base = {
21 display: 'block',
22 color: color
23 };
24 if (effect === 'gradient') {
25 base.background = 'linear-gradient(90deg, ' + effectColor + ', ' + effectColor2 + ')';
26 base.WebkitBackgroundClip = 'text';
27 base.WebkitTextFillColor = 'transparent';
28 base.backgroundClip = 'text';
29 } else if (effect === 'stroke') {
30 base.color = 'transparent';
31 base.WebkitTextStroke = strokeWidth + 'px ' + strokeColor;
32 } else if (effect === 'highlight') {
33 base.background = effectColor;
34 base.display = 'inline';
35 base.padding = '2px 8px';
36 base.borderRadius = '4px';
37 } else if (effect === 'marker') {
38 base.background = 'linear-gradient(transparent 60%, ' + effectColor + ' 60%)';
39 base.display = 'inline';
40 }
41 return base;
42 }
43
44 var effectOptions = [
45 { label: __('None', 'blockenberg'), value: 'none' },
46 { label: __('Gradient (color wash)', 'blockenberg'), value: 'gradient' },
47 { label: __('Highlight (box behind)', 'blockenberg'), value: 'highlight' },
48 { label: __('Marker (underline wash)', 'blockenberg'), value: 'marker' },
49 { label: __('Stroke (outline only)', 'blockenberg'), value: 'stroke' }
50 ];
51
52 var weightOptions = [
53 { label: '300 – Light', value: '300' },
54 { label: '400 – Regular', value: '400' },
55 { label: '500 – Medium', value: '500' },
56 { label: '600 – Semibold', value: '600' },
57 { label: '700 – Bold', value: '700' },
58 { label: '800 – Extrabold', value: '800' },
59 { label: '900 – Black', value: '900' }
60 ];
61
62 registerBlockType('blockenberg/dual-heading', {
63 edit: function (props) {
64 var attr = props.attributes;
65 var setAttr = props.setAttributes;
66 var blockProps = useBlockProps({ className: 'bkbg-dh-wrap bkbg-dh-editor', style: Object.assign(
67 { '--bkbg-dh-l1-fs': (attr.line1Size || 52) + 'px', '--bkbg-dh-l2-fs': (attr.line2Size || 52) + 'px', '--bkbg-dh-sub-fs': (attr.subtextSize || 18) + 'px' },
68 _tv(attr.typoLine1 || {}, '--bkbg-dh-l1-'),
69 _tv(attr.typoLine2 || {}, '--bkbg-dh-l2-'),
70 _tv(attr.typoSubtext || {}, '--bkbg-dh-sub-')
71 ) });
72
73 var line1Style = buildLineStyle(attr.line1Color, attr.line1Effect, attr.effectColor, attr.effectColor2, attr.strokeColor, attr.strokeWidth);
74 var line2Style = buildLineStyle(attr.line2Color, attr.line2Effect, attr.effectColor, attr.effectColor2, attr.strokeColor, attr.strokeWidth);
75
76 var wrapStyle = {
77 background: attr.bgColor || undefined,
78 paddingTop: attr.paddingTop + 'px',
79 paddingBottom: attr.paddingBottom + 'px'
80 };
81 var innerStyle = {
82 maxWidth: attr.maxWidth + 'px',
83 margin: '0 auto',
84 padding: '0 20px',
85 textAlign: attr.textAlign
86 };
87 var headingWrapStyle = attr.layout === 'inline'
88 ? { display: 'flex', flexWrap: 'wrap', gap: '0 12px', alignItems: 'baseline', justifyContent: attr.textAlign === 'center' ? 'center' : (attr.textAlign === 'right' ? 'flex-end' : 'flex-start') }
89 : { display: 'flex', flexDirection: 'column', gap: attr.lineGap + 'px' };
90
91 return el(Fragment, null,
92 el(InspectorControls, null,
93 el(PanelBody, { title: __('Layout', 'blockenberg'), initialOpen: true },
94 el(SelectControl, { label: __('Tag', 'blockenberg'), __nextHasNoMarginBottom: true, value: attr.tag,
95 options: ['h1','h2','h3','h4','h5','p'].map(function (t) { return { label: t.toUpperCase(), value: t }; }),
96 onChange: function (v) { setAttr({ tag: v }); } }),
97 el(SelectControl, { label: __('Arrangement', 'blockenberg'), __nextHasNoMarginBottom: true, value: attr.layout,
98 options: [{ label: __('Stacked (one line per row)', 'blockenberg'), value: 'stacked' }, { label: __('Inline (both on same line)', 'blockenberg'), value: 'inline' }],
99 onChange: function (v) { setAttr({ layout: v }); } }),
100 el(SelectControl, { label: __('Text Align', 'blockenberg'), __nextHasNoMarginBottom: true, value: attr.textAlign,
101 options: [{ label: 'Left', value: 'left' }, { label: 'Center', value: 'center' }, { label: 'Right', value: 'right' }],
102 onChange: function (v) { setAttr({ textAlign: v }); } }),
103 attr.layout === 'stacked' && el(RangeControl, { label: __('Gap Between Lines (px)', 'blockenberg'), __nextHasNoMarginBottom: true, value: attr.lineGap, min: 0, max: 40, onChange: function (v) { setAttr({ lineGap: v }); } })
104 ),
105 el(PanelBody, { title: __('Line 1 Typography', 'blockenberg'), initialOpen: false },
106 _tc() && el(_tc(), { label: __('Line 1', 'blockenberg'), typo: attr.typoLine1 || {}, onChange: function (v) { setAttr({ typoLine1: v }); }, defaultSize: attr.line1Size || 52 }),
107 el(SelectControl, { label: __('Effect', 'blockenberg'), __nextHasNoMarginBottom: true, value: attr.line1Effect, options: effectOptions, onChange: function (v) { setAttr({ line1Effect: v }); } })
108 ),
109 el(PanelBody, { title: __('Line 2 Typography', 'blockenberg'), initialOpen: false },
110 _tc() && el(_tc(), { label: __('Line 2', 'blockenberg'), typo: attr.typoLine2 || {}, onChange: function (v) { setAttr({ typoLine2: v }); }, defaultSize: attr.line2Size || 52 }),
111 el(SelectControl, { label: __('Effect', 'blockenberg'), __nextHasNoMarginBottom: true, value: attr.line2Effect, options: effectOptions, onChange: function (v) { setAttr({ line2Effect: v }); } })
112 ),
113 el(PanelBody, { title: __('Subtext Typography', 'blockenberg'), initialOpen: false },
114 _tc() && el(_tc(), { label: __('Subtext', 'blockenberg'), typo: attr.typoSubtext || {}, onChange: function (v) { setAttr({ typoSubtext: v }); }, defaultSize: attr.subtextSize || 18 }),
115 el(ToggleControl, { label: __('Show Subtext', 'blockenberg'), __nextHasNoMarginBottom: true, checked: attr.showSubtext, onChange: function (v) { setAttr({ showSubtext: v }); } })
116 ),
117 el(PanelBody, { title: __('Effect Colors', 'blockenberg'), initialOpen: false },
118 el(RangeControl, { label: __('Stroke Width (px)', 'blockenberg'), __nextHasNoMarginBottom: true, value: attr.strokeWidth, min: 1, max: 6, onChange: function (v) { setAttr({ strokeWidth: v }); } }),
119 el(RangeControl, { label: __('Max Width (px)', 'blockenberg'), __nextHasNoMarginBottom: true, value: attr.maxWidth, min: 300, max: 1400, step: 10, onChange: function (v) { setAttr({ maxWidth: v }); } }),
120 el(RangeControl, { label: __('Padding Top (px)', 'blockenberg'), __nextHasNoMarginBottom: true, value: attr.paddingTop, min: 0, max: 200, onChange: function (v) { setAttr({ paddingTop: v }); } }),
121 el(RangeControl, { label: __('Padding Bottom (px)', 'blockenberg'), __nextHasNoMarginBottom: true, value: attr.paddingBottom, min: 0, max: 200, onChange: function (v) { setAttr({ paddingBottom: v }); } }),
122 ),
123 el(PanelColorSettings, {
124 title: __('Colors', 'blockenberg'), initialOpen: false,
125 colorSettings: [
126 { value: attr.bgColor, onChange: function (v) { setAttr({ bgColor: v || '' }); }, label: __('Background', 'blockenberg') },
127 { value: attr.line1Color, onChange: function (v) { setAttr({ line1Color: v || '#111827' }); }, label: __('Line 1 Color', 'blockenberg') },
128 { value: attr.line2Color, onChange: function (v) { setAttr({ line2Color: v || '#7c3aed' }); }, label: __('Line 2 Color', 'blockenberg') },
129 { value: attr.effectColor, onChange: function (v) { setAttr({ effectColor: v || '#fef08a' }); }, label: __('Effect Color 1 (gradient/highlight)', 'blockenberg') },
130 { value: attr.effectColor2, onChange: function (v) { setAttr({ effectColor2: v || '#f97316' }); }, label: __('Effect Color 2 (gradient end)', 'blockenberg') },
131 { value: attr.strokeColor, onChange: function (v) { setAttr({ strokeColor: v || '#7c3aed' }); }, label: __('Stroke Color', 'blockenberg') },
132 { value: attr.subtextColor, onChange: function (v) { setAttr({ subtextColor: v || '#6b7280' }); }, label: __('Subtext', 'blockenberg') }
133 ]
134 })
135 ),
136 el('div', blockProps,
137 el('div', { style: wrapStyle },
138 el('div', { style: innerStyle },
139 el(attr.tag, { style: { margin: 0 } },
140 el('span', { style: headingWrapStyle },
141 el(RichText, { tagName: 'span', className: 'bkbg-dh-line bkbg-dh-line-1', value: attr.line1, onChange: function (v) { setAttr({ line1: v }); },
142 style: line1Style, placeholder: __('Line 1…', 'blockenberg') }),
143 el(RichText, { tagName: 'span', className: 'bkbg-dh-line bkbg-dh-line-2', value: attr.line2, onChange: function (v) { setAttr({ line2: v }); },
144 style: line2Style, placeholder: __('Line 2…', 'blockenberg') })
145 )
146 ),
147 attr.showSubtext && el(RichText, { tagName: 'p', className: 'bkbg-dh-subtext', value: attr.subtext, onChange: function (v) { setAttr({ subtext: v }); },
148 style: { color: attr.subtextColor, margin: '16px 0 0' },
149 placeholder: __('Subtext…', 'blockenberg') })
150 )
151 )
152 )
153 );
154 },
155 save: function (props) {
156 var attr = props.attributes;
157 return el('div', useBlockProps.save(),
158 el('div', { className: 'bkbg-dual-heading-app', 'data-opts': JSON.stringify(attr) })
159 );
160 }
161 });
162 }() );
163