PluginProbe
Blockenberg — 600+ Advanced Gutenberg Blocks & AI Agent for WordPress Block Editor / 2.0.13
Blockenberg — 600+ Advanced Gutenberg Blocks & AI Agent for WordPress Block Editor v2.0.13
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 / split-panel / index.js

index.js in Blockenberg — 600+ Advanced Gutenberg Blocks & AI Agent for WordPress Block Editor 2.0.13, at blocks/split-panel/index.js

164 lines 12.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 ( function () {
2 const el = window.wp.element.createElement;
3 const { registerBlockType } = window.wp.blocks;
4 const { InspectorControls, useBlockProps, PanelColorSettings } = window.wp.blockEditor;
5 const { PanelBody, RangeControl, ToggleControl, TextControl, Button } = window.wp.components;
6 const { __ } = window.wp.i18n;
7
8 /* Lazy typography helpers */
9 let _tc, _tv;
10 function getTypoControl() { return _tc || (_tc = window.bkbgTypographyControl); }
11 function getTypoCssVars() { return _tv || (_tv = window.bkbgTypoCssVars); }
12 const IP = function () { return window.bkbgIconPicker; };
13
14 function renderIconPart(type, charVal, dashicon, imageUrl, dashiconColor, forSave) {
15 if (!type || type === 'custom-char') return charVal;
16 var fn = forSave ? IP().buildSaveIcon : IP().buildEditorIcon;
17 return fn(type, charVal, dashicon, imageUrl, dashiconColor);
18 }
19
20 function buildWrapStyle(a) {
21 const tv = getTypoCssVars();
22 const s = {
23 background: a.bgColor,
24 boxSizing: 'border-box',
25 '--bksp-hd-sz': (a.titleFontSize + 2) + 'px',
26 '--bksp-tt-sz': a.titleFontSize + 'px',
27 '--bksp-tt-w': String(a.titleFontWeight),
28 '--bksp-tt-lh': String(a.titleLineHeight),
29 '--bksp-bd-sz': a.fontSize + 'px',
30 '--bksp-it-sz': a.itemFontSize + 'px',
31 '--bksp-it-w': String(a.itemFontWeight),
32 '--bksp-it-lh': String(a.itemLineHeight),
33 };
34 if (tv) {
35 Object.assign(s, tv(a.headingTypo, '--bksp-hd-'));
36 Object.assign(s, tv(a.titleTypo, '--bksp-tt-'));
37 Object.assign(s, tv(a.bodyTypo, '--bksp-bd-'));
38 Object.assign(s, tv(a.itemTypo, '--bksp-it-'));
39 }
40 return s;
41 }
42
43 // ── Panel component ───────────────────────────────────────────────────────
44 function Panel( { icon, iconType, iconDashicon, iconImageUrl, iconDashiconColor, forSave, iconSize, title, body, items, bg, accent, textColor, titleColor, padding, borderRadius, side } ) {
45 return el( 'div', { className: 'bkbg-sp-panel bkbg-sp-panel--' + side, style: {
46 flex: '1 1 0',
47 background: bg,
48 borderRadius: borderRadius + 'px',
49 padding: padding + 'px',
50 borderLeft: '4px solid ' + accent,
51 boxSizing: 'border-box',
52 } },
53 // Icon + title
54 el( 'div', { style: { display: 'flex', alignItems: 'center', gap: 10, marginBottom: 14 } },
55 el( 'span', { className: 'bkbg-sp-icon', style: { fontSize: iconSize + 'px', lineHeight: 1 } }, renderIconPart(iconType, icon, iconDashicon, iconImageUrl, iconDashiconColor, forSave) ),
56 el( 'strong', { className: 'bkbg-sp-title', style: { color: titleColor } }, title ),
57 ),
58 // Body
59 body && el( 'p', { className: 'bkbg-sp-body', style: { color: textColor, margin: '0 0 14px' } }, body ),
60 // Items
61 items && items.length > 0 && el( 'ul', { style: { listStyle: 'none', margin: 0, padding: 0, display: 'flex', flexDirection: 'column', gap: 8 } },
62 items.map( ( item, i ) =>
63 el( 'li', { key: i, className: 'bkbg-sp-item', style: { display: 'flex', alignItems: 'flex-start', gap: 8, color: textColor } },
64 el( 'span', { style: { flexShrink: 0, width: 8, height: 8, borderRadius: '50%', background: accent, marginTop: 6 } } ),
65 el( 'span', {}, item ),
66 )
67 ),
68 ),
69 );
70 }
71
72 // ── Renderer ──────────────────────────────────────────────────────────────
73 function renderSplitPanel( a, forSave ) {
74 return el( 'div', { className: 'bkbg-sp-row', style: { display: 'flex', gap: a.showDivider ? 0 : 20, alignItems: 'stretch' } },
75 el( Panel, { side: 'left', icon: a.leftIcon, iconType: a.leftIconType, iconDashicon: a.leftIconDashicon, iconImageUrl: a.leftIconImageUrl, iconDashiconColor: a.leftIconDashiconColor, forSave: forSave, iconSize: a.iconSize, title: a.leftTitle, body: a.leftBody, items: a.leftItems, bg: a.leftBg, accent: a.leftAccent, textColor: a.textColor, titleColor: a.titleColor, padding: a.padding, borderRadius: a.borderRadius } ),
76 a.showDivider && el( 'div', { className: 'bkbg-sp-divider', style: { width: 1, margin: '0 20px', background: 'linear-gradient(to bottom, transparent, #d1d5db 30%, #d1d5db 70%, transparent)', flexShrink: 0, alignSelf: 'stretch' } } ),
77 el( Panel, { side: 'right', icon: a.rightIcon, iconType: a.rightIconType, iconDashicon: a.rightIconDashicon, iconImageUrl: a.rightIconImageUrl, iconDashiconColor: a.rightIconDashiconColor, forSave: forSave, iconSize: a.iconSize, title: a.rightTitle, body: a.rightBody, items: a.rightItems, bg: a.rightBg, accent: a.rightAccent, textColor: a.textColor, titleColor: a.titleColor, padding: a.padding, borderRadius: a.borderRadius } ),
78 );
79 }
80
81 // ── Item list helper ──────────────────────────────────────────────────────
82 function ItemListEditor( { label, items, setItems } ) {
83 return el( PanelBody, { title: label, initialOpen: false },
84 el( Button, { variant: 'secondary', style: { marginBottom: 8 }, onClick: () => setItems( [ ...( items || [] ), 'New item' ] ) }, __( '+ Add Item', 'blockenberg' ) ),
85 ( items || [] ).map( ( item, i ) =>
86 el( 'div', { key: i, style: { display: 'flex', gap: 4, marginBottom: 4, alignItems: 'center' } },
87 el( TextControl, { value: item, style: { flex: 1, margin: 0 }, onChange: v => setItems( items.map( ( x, j ) => j === i ? v : x ) ) } ),
88 el( Button, { isDestructive: true, isSmall: true, onClick: () => setItems( items.filter( ( _, j ) => j !== i ) ) }, '' ),
89 )
90 ),
91 );
92 }
93
94 // ── Block ─────────────────────────────────────────────────────────────────
95 registerBlockType( 'blockenberg/split-panel', {
96 edit: function ( props ) {
97 const { attributes: a, setAttributes } = props;
98 const blockProps = useBlockProps( { className: 'bkbg-sp-wrap', style: buildWrapStyle(a) } );
99
100 return el( 'div', blockProps,
101 el( InspectorControls, {},
102
103 el( PanelBody, { title: __( 'Settings', 'blockenberg' ), initialOpen: true },
104 el( ToggleControl, { label: __( 'Show Heading', 'blockenberg' ), checked: a.showTitle, onChange: v => setAttributes( { showTitle: v } ) } ),
105 a.showTitle && el( TextControl, { label: __( 'Heading', 'blockenberg' ), value: a.title, onChange: v => setAttributes( { title: v } ) } ),
106 el( ToggleControl, { label: __( 'Show Divider', 'blockenberg' ), checked: a.showDivider, onChange: v => setAttributes( { showDivider: v } ) } ),
107 ),
108
109 el( PanelBody, { title: __( 'Left Panel', 'blockenberg' ), initialOpen: false },
110 el( IP().IconPickerControl, IP().iconPickerProps( a, setAttributes, { charAttr: 'leftIcon', typeAttr: 'leftIconType', dashiconAttr: 'leftIconDashicon', imageUrlAttr: 'leftIconImageUrl', colorAttr: 'leftIconDashiconColor' } ) ),
111 el( TextControl, { label: __( 'Title', 'blockenberg' ), value: a.leftTitle, onChange: v => setAttributes( { leftTitle: v } ) } ),
112 el( TextControl, { label: __( 'Body Text', 'blockenberg' ), value: a.leftBody, onChange: v => setAttributes( { leftBody: v } ) } ),
113 el( ItemListEditor, { label: __( 'Bullet Items', 'blockenberg' ), items: a.leftItems, setItems: v => setAttributes( { leftItems: v } ) } ),
114 ),
115
116 el( PanelBody, { title: __( 'Right Panel', 'blockenberg' ), initialOpen: false },
117 el( IP().IconPickerControl, IP().iconPickerProps( a, setAttributes, { charAttr: 'rightIcon', typeAttr: 'rightIconType', dashiconAttr: 'rightIconDashicon', imageUrlAttr: 'rightIconImageUrl', colorAttr: 'rightIconDashiconColor' } ) ),
118 el( TextControl, { label: __( 'Title', 'blockenberg' ), value: a.rightTitle, onChange: v => setAttributes( { rightTitle: v } ) } ),
119 el( TextControl, { label: __( 'Body Text', 'blockenberg' ), value: a.rightBody, onChange: v => setAttributes( { rightBody: v } ) } ),
120 el( ItemListEditor, { label: __( 'Bullet Items', 'blockenberg' ), items: a.rightItems, setItems: v => setAttributes( { rightItems: v } ) } ),
121 ),
122
123 el( PanelBody, { title: __( 'Style', 'blockenberg' ), initialOpen: false },
124 el( RangeControl, { label: __( 'Border Radius', 'blockenberg' ), value: a.borderRadius, onChange: v => setAttributes( { borderRadius: v } ), min: 0, max: 32 } ),
125 el( RangeControl, { label: __( 'Padding', 'blockenberg' ), value: a.padding, onChange: v => setAttributes( { padding: v } ), min: 12, max: 56 } ),
126 el( RangeControl, { label: __( 'Icon Size', 'blockenberg' ), value: a.iconSize, onChange: v => setAttributes( { iconSize: v } ), min: 16, max: 64 } ),
127 ),
128
129
130 el( PanelBody, { title: __( 'Typography', 'blockenberg' ), initialOpen: false },
131 getTypoControl() && getTypoControl()({ label: __('Heading', 'blockenberg'), value: a.headingTypo, onChange: v => setAttributes({ headingTypo: v }) }),
132 getTypoControl() && getTypoControl()({ label: __('Panel title', 'blockenberg'), value: a.titleTypo, onChange: v => setAttributes({ titleTypo: v }) }),
133 getTypoControl() && getTypoControl()({ label: __('Body', 'blockenberg'), value: a.bodyTypo, onChange: v => setAttributes({ bodyTypo: v }) }),
134 getTypoControl() && getTypoControl()({ label: __('Item', 'blockenberg'), value: a.itemTypo, onChange: v => setAttributes({ itemTypo: v }) })
135 ),
136 el( PanelColorSettings, {
137 title: __( 'Colors', 'blockenberg' ), initialOpen: false,
138 colorSettings: [
139 { label: __( 'Outer Background', 'blockenberg' ), value: a.bgColor, onChange: v => setAttributes( { bgColor: v || '#ffffff' } ) },
140 { label: __( 'Text', 'blockenberg' ), value: a.textColor, onChange: v => setAttributes( { textColor: v || '#374151' } ) },
141 { label: __( 'Title', 'blockenberg' ), value: a.titleColor, onChange: v => setAttributes( { titleColor: v || '#111827' } ) },
142 { label: __( 'Left Background', 'blockenberg' ), value: a.leftBg, onChange: v => setAttributes( { leftBg: v || '#fef2f2' } ) },
143 { label: __( 'Left Accent', 'blockenberg' ), value: a.leftAccent, onChange: v => setAttributes( { leftAccent: v || '#ef4444' } ) },
144 { label: __( 'Right Background', 'blockenberg' ), value: a.rightBg, onChange: v => setAttributes( { rightBg: v || '#f0fdf4' } ) },
145 { label: __( 'Right Accent', 'blockenberg' ), value: a.rightAccent, onChange: v => setAttributes( { rightAccent: v || '#10b981' } ) },
146 ]
147 } ),
148 ),
149
150 a.showTitle && a.title && el( 'h3', { className: 'bkbg-sp-heading', style: { color: a.titleColor, margin: '0 0 20px' } }, a.title ),
151 renderSplitPanel( a ),
152 );
153 },
154
155 save: function ( { attributes: a } ) {
156 const blockProps = useBlockProps.save( { className: 'bkbg-sp-wrap', style: buildWrapStyle(a) } );
157 return el( 'div', blockProps,
158 ( a.showTitle && a.title ) ? el( 'h3', { className: 'bkbg-sp-heading', style: { color: a.titleColor, margin: '0 0 20px' } }, a.title ) : null,
159 renderSplitPanel( a, true ),
160 );
161 },
162 } );
163 }() );
164