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 / size-guide / index.js

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

281 lines 17.3 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 var _tc; function getTC() { return _tc || (_tc = window.bkbgTypographyControl); }
9 var _tv; function getTV() { return _tv || (_tv = window.bkbgTypoCssVars); }
10
11 function buildTypoVars( a ) {
12 var fn = getTV();
13 if ( !fn ) return {};
14 var v = {};
15 Object.assign( v, fn( a.titleTypo || {}, '--bksg-tt-' ) );
16 Object.assign( v, fn( a.bodyTypo || {}, '--bksg-bt-' ) );
17 return v;
18 }
19
20 // ── Renderer ──────────────────────────────────────────────────────────────
21 function renderTable( a ) {
22 const cols = a.columns || [];
23 const rows = a.rows || [];
24 const hlCol = a.showHighlight ? ( a.highlightCol || 0 ) : -1;
25 const P = a.cellPadding + 'px';
26 const FS = a.fontSize + 'px';
27
28 const thStyle = ( ci ) => ( {
29 background: ci === hlCol ? a.highlightBg : a.headerBg,
30 color: ci === hlCol ? a.highlightText : a.headerText,
31 padding: P,
32 fontSize: FS,
33 fontWeight: a.fontWeight||700,
34 textAlign: 'center',
35 whiteSpace: 'nowrap',
36 position: 'relative',
37 } );
38
39 const tdStyle = ( ci, ri ) => ( {
40 background: ci === hlCol ? a.highlightBg : ri % 2 === 0 ? '#ffffff' : a.rowAltBg,
41 color: ci === hlCol ? a.highlightText : a.textColor,
42 padding: P,
43 fontSize: FS,
44 textAlign: ci === 0 ? 'left' : 'center',
45 borderBottom: `1px solid ${ a.borderColor }`,
46 fontWeight: ci === 0 ? 600 : 400,
47 } );
48
49 return el( 'div', { className: 'bkbg-sg-table-wrap', style: { overflowX: 'auto' } },
50 el( 'table', { style: { borderCollapse: 'collapse', width: '100%', minWidth: 400, border: `1px solid ${ a.borderColor }`, borderRadius: a.borderRadius + 'px', overflow: 'hidden' } },
51 el( 'thead', {},
52 el( 'tr', {},
53 cols.map( ( col, ci ) =>
54 el( 'th', { key: ci, style: thStyle( ci ) },
55 ci === hlCol && a.showHighlight && a.highlightLabel && el( 'span', { style: { display: 'block', fontSize: 10, fontWeight: 700, textTransform: 'uppercase', letterSpacing: '0.05em', opacity: 0.8, marginBottom: 2 } }, a.highlightLabel ),
56 col,
57 )
58 )
59 )
60 ),
61 el( 'tbody', {},
62 rows.map( ( row, ri ) =>
63 el( 'tr', { key: ri },
64 Array.from( { length: cols.length } ).map( ( _, ci ) =>
65 el( 'td', { key: ci, style: tdStyle( ci, ri ) }, row[ ci ] || '' )
66 )
67 )
68 )
69 )
70 )
71 );
72 }
73
74 // ── Renderer (new – no inline font styles) ───────────────────────────────
75 function renderTableNew( a ) {
76 const cols = a.columns || [];
77 const rows = a.rows || [];
78 const hlCol = a.showHighlight ? ( a.highlightCol || 0 ) : -1;
79 const P = a.cellPadding + 'px';
80
81 const thStyle = ( ci ) => ( {
82 background: ci === hlCol ? a.highlightBg : a.headerBg,
83 color: ci === hlCol ? a.highlightText : a.headerText,
84 padding: P, textAlign: 'center', whiteSpace: 'nowrap', position: 'relative',
85 } );
86
87 const tdStyle = ( ci, ri ) => ( {
88 background: ci === hlCol ? a.highlightBg : ri % 2 === 0 ? '#ffffff' : a.rowAltBg,
89 color: ci === hlCol ? a.highlightText : a.textColor,
90 padding: P, textAlign: ci === 0 ? 'left' : 'center',
91 borderBottom: `1px solid ${ a.borderColor }`,
92 } );
93
94 return el( 'div', { className: 'bkbg-sg-table-wrap', style: { overflowX: 'auto' } },
95 el( 'table', { style: { borderCollapse: 'collapse', width: '100%', minWidth: 400, border: `1px solid ${ a.borderColor }`, borderRadius: a.borderRadius + 'px', overflow: 'hidden' } },
96 el( 'thead', {},
97 el( 'tr', {},
98 cols.map( ( col, ci ) =>
99 el( 'th', { key: ci, style: thStyle( ci ) },
100 ci === hlCol && a.showHighlight && a.highlightLabel && el( 'span', { style: { display: 'block', fontSize: 10, fontWeight: 700, textTransform: 'uppercase', letterSpacing: '0.05em', opacity: 0.8, marginBottom: 2 } }, a.highlightLabel ),
101 col,
102 )
103 )
104 )
105 ),
106 el( 'tbody', {},
107 rows.map( ( row, ri ) =>
108 el( 'tr', { key: ri },
109 Array.from( { length: cols.length } ).map( ( _, ci ) =>
110 el( 'td', { key: ci, style: tdStyle( ci, ri ) }, row[ ci ] || '' )
111 )
112 )
113 )
114 )
115 )
116 );
117 }
118
119 // ── Block ─────────────────────────────────────────────────────────────────
120 registerBlockType( 'blockenberg/size-guide', {
121 edit: function ( props ) {
122 const { attributes: a, setAttributes } = props;
123 const blockProps = useBlockProps( { className: 'bkbg-sg-wrap', style: buildTypoVars( a ) } );
124
125 const cols = a.columns || [];
126 const rows = a.rows || [];
127
128 function setCell( ri, ci, val ) {
129 const newRows = rows.map( ( r, i ) => {
130 if ( i !== ri ) return r;
131 const nr = [ ...r ];
132 nr[ ci ] = val;
133 return nr;
134 } );
135 setAttributes( { rows: newRows } );
136 }
137
138 function setColHeader( ci, val ) {
139 setAttributes( { columns: cols.map( ( c, i ) => i === ci ? val : c ) } );
140 }
141
142 function addColumn() {
143 setAttributes( {
144 columns: [ ...cols, 'New' ],
145 rows: rows.map( r => [ ...r, '' ] ),
146 } );
147 }
148
149 function removeColumn( ci ) {
150 setAttributes( {
151 columns: cols.filter( ( _, i ) => i !== ci ),
152 rows: rows.map( r => r.filter( ( _, i ) => i !== ci ) ),
153 } );
154 }
155
156 function addRow() {
157 setAttributes( { rows: [ ...rows, Array( cols.length ).fill( '' ) ] } );
158 }
159
160 function removeRow( ri ) {
161 setAttributes( { rows: rows.filter( ( _, i ) => i !== ri ) } );
162 }
163
164 return el( 'div', blockProps,
165 el( InspectorControls, {},
166
167 el( PanelBody, { title: __( 'Settings', 'blockenberg' ), initialOpen: true },
168 el( TextControl, { label: __( 'Title', 'blockenberg' ), value: a.title, onChange: v => setAttributes( { title: v } ) } ),
169 el( ToggleControl, { label: __( 'Show Title', 'blockenberg' ), checked: a.showTitle, onChange: v => setAttributes( { showTitle: v } ) } ),
170 el( ToggleControl, { label: __( 'Show Note', 'blockenberg' ), checked: a.showNote, onChange: v => setAttributes( { showNote: v } ) } ),
171 a.showNote && el( TextControl, { label: __( 'Note Text', 'blockenberg' ), value: a.note, onChange: v => setAttributes( { note: v } ) } ),
172 el( ToggleControl, { label: __( 'Highlight Column', 'blockenberg' ),checked: a.showHighlight, onChange: v => setAttributes( { showHighlight: v } ) } ),
173 a.showHighlight && el( RangeControl, { label: __( 'Highlight Col Index (0=first)', 'blockenberg' ), value: a.highlightCol, onChange: v => setAttributes( { highlightCol: v } ), min: 0, max: Math.max( 0, cols.length - 1 ) } ),
174 a.showHighlight && el( TextControl, { label: __( 'Highlight Badge Label', 'blockenberg' ), value: a.highlightLabel, onChange: v => setAttributes( { highlightLabel: v } ) } ),
175 ),
176
177 el( PanelBody, { title: __( 'Style', 'blockenberg' ), initialOpen: false },
178 el( RangeControl, { label: __( 'Cell Padding', 'blockenberg' ), value: a.cellPadding, onChange: v => setAttributes( { cellPadding: v } ), min: 4, max: 28 } ),
179 el( RangeControl, { label: __( 'Border Radius', 'blockenberg' ),value: a.borderRadius,onChange: v => setAttributes( { borderRadius: v } ), min: 0, max: 20 } ),
180 ),
181
182
183 el( PanelBody, { title: __( 'Typography', 'blockenberg' ), initialOpen: false },
184 el( getTC(), { label: __( 'Title', 'blockenberg' ), value: a.titleTypo || {}, onChange: function( v ) { setAttributes( { titleTypo: v } ); } } ),
185 el( getTC(), { label: __( 'Table', 'blockenberg' ), value: a.bodyTypo || {}, onChange: function( v ) { setAttributes( { bodyTypo: v } ); } } ),
186 ),
187 el( PanelColorSettings, {
188 title: __( 'Colors', 'blockenberg' ), initialOpen: false,
189 colorSettings: [
190 { label: __( 'BG', 'blockenberg' ), value: a.bgColor, onChange: v => setAttributes( { bgColor: v || '#ffffff' } ) },
191 { label: __( 'Header BG', 'blockenberg' ), value: a.headerBg, onChange: v => setAttributes( { headerBg: v || '#111827' } ) },
192 { label: __( 'Header Text', 'blockenberg' ), value: a.headerText, onChange: v => setAttributes( { headerText: v || '#ffffff' } ) },
193 { label: __( 'Highlight BG', 'blockenberg' ), value: a.highlightBg, onChange: v => setAttributes( { highlightBg: v || '#eef2ff' } ) },
194 { label: __( 'Highlight Text', 'blockenberg' ),value: a.highlightText,onChange: v => setAttributes( { highlightText: v || '#4338ca' } ) },
195 { label: __( 'Alt Row BG', 'blockenberg' ), value: a.rowAltBg, onChange: v => setAttributes( { rowAltBg: v || '#f9fafb' } ) },
196 { label: __( 'Border', 'blockenberg' ), value: a.borderColor, onChange: v => setAttributes( { borderColor: v || '#e5e7eb' } ) },
197 { label: __( 'Text', 'blockenberg' ), value: a.textColor, onChange: v => setAttributes( { textColor: v || '#374151' } ) },
198 { label: __( 'Title', 'blockenberg' ), value: a.titleColor, onChange: v => setAttributes( { titleColor: v || '#111827' } ) },
199 ]
200 } ),
201
202 el( PanelBody, { title: __( 'Columns & Rows', 'blockenberg' ), initialOpen: false },
203 el( 'p', { style: { fontSize: 12, color: '#6b7280', margin: '0 0 8px' } }, __( 'Edit table content directly in the block canvas below. Use these controls to add/remove columns and rows.', 'blockenberg' ) ),
204 el( 'div', { style: { display: 'flex', gap: 8, flexWrap: 'wrap' } },
205 el( Button, { variant: 'secondary', isSmall: true, onClick: addColumn }, __( '+ Column', 'blockenberg' ) ),
206 el( Button, { variant: 'secondary', isSmall: true, onClick: addRow }, __( '+ Row', 'blockenberg' ) ),
207 cols.length > 1 && el( Button, { isDestructive: true, isSmall: true, onClick: () => removeColumn( cols.length - 1 ) }, __( '- Last Col', 'blockenberg' ) ),
208 rows.length > 1 && el( Button, { isDestructive: true, isSmall: true, onClick: () => removeRow( rows.length - 1 ) }, __( '- Last Row', 'blockenberg' ) ),
209 )
210 ),
211 ),
212
213 a.showTitle && a.title && el( 'h3', { className: 'bkbg-sg-title', style: { color: a.titleColor, margin: '0 0 14px' } }, a.title ),
214
215 // Editable table in editor
216 el( 'div', { className: 'bkbg-sg-table-wrap', style: { overflowX: 'auto', background: a.bgColor, borderRadius: a.borderRadius + 'px', border: `1px solid ${ a.borderColor }`, overflow: 'hidden' } },
217 el( 'table', { style: { borderCollapse: 'collapse', width: '100%', minWidth: 400 } },
218 el( 'thead', {},
219 el( 'tr', {},
220 cols.map( ( col, ci ) =>
221 el( 'th', { key: ci, style: { background: ci === ( a.showHighlight ? a.highlightCol : -1 ) ? a.highlightBg : a.headerBg, padding: a.cellPadding + 'px', border: 'none', position: 'relative' } },
222 ci === a.highlightCol && a.showHighlight && a.highlightLabel && el( 'div', { style: { fontSize: 10, color: a.highlightText, fontWeight: 700, textTransform: 'uppercase', letterSpacing: '0.05em', opacity: 0.8, marginBottom: 2 } }, a.highlightLabel ),
223 el( 'input', {
224 value: col,
225 onChange: e => setColHeader( ci, e.target.value ),
226 style: { background: 'transparent', border: 'none', color: ci === ( a.showHighlight ? a.highlightCol : -1 ) ? a.highlightText : a.headerText, textAlign: 'center', width: '100%', cursor: 'text', outline: 'none', padding: 0 }
227 } ),
228 )
229 )
230 )
231 ),
232 el( 'tbody', {},
233 rows.map( ( row, ri ) =>
234 el( 'tr', { key: ri },
235 Array.from( { length: cols.length } ).map( ( _, ci ) =>
236 el( 'td', { key: ci, style: { background: ci === ( a.showHighlight ? a.highlightCol : -1 ) ? a.highlightBg : ri % 2 === 0 ? '#ffffff' : a.rowAltBg, padding: a.cellPadding + 'px', borderBottom: `1px solid ${ a.borderColor }` } },
237 el( 'input', {
238 value: row[ ci ] || '',
239 onChange: e => setCell( ri, ci, e.target.value ),
240 style: { background: 'transparent', border: 'none', width: '100%', textAlign: ci === 0 ? 'left' : 'center', color: ci === ( a.showHighlight ? a.highlightCol : -1 ) ? a.highlightText : ci === 0 ? a.textColor : a.textColor, cursor: 'text', outline: 'none', padding: 0 }
241 } )
242 )
243 )
244 )
245 )
246 )
247 )
248 ),
249
250 a.showNote && a.note && el( 'p', { className: 'bkbg-sg-note', style: { fontSize: 12, color: '#6b7280', marginTop: 10, marginBottom: 0 } }, a.note ),
251 );
252 },
253
254 save: function ( { attributes: a } ) {
255 const blockProps = useBlockProps.save( { className: 'bkbg-sg-wrap', style: buildTypoVars( a ) } );
256 return el( 'div', blockProps,
257 a.showTitle && a.title ? el( 'h3', { className: 'bkbg-sg-title', style: { color: a.titleColor, margin: '0 0 14px' } }, a.title ) : null,
258 renderTableNew( a ),
259 a.showNote && a.note ? el( 'p', { className: 'bkbg-sg-note', style: { fontSize: 12, color: '#6b7280', marginTop: 10, marginBottom: 0 } }, a.note ) : null,
260 );
261 },
262
263 deprecated: [ {
264 save: function ( { attributes: a } ) {
265 var bp = useBlockProps.save( { className: 'bkbg-sg-wrap' } );
266 return el( 'div', bp,
267 a.showTitle && a.title ? el( 'h3', { className: 'bkbg-sg-title', style: { color: a.titleColor, margin: '0 0 14px', fontSize: ( a.fontSize + 4 ) + 'px' } }, a.title ) : null,
268 renderTable( a ),
269 a.showNote && a.note ? el( 'p', { className: 'bkbg-sg-note', style: { fontSize: 12, color: '#6b7280', marginTop: 10, marginBottom: 0 } }, a.note ) : null,
270 );
271 },
272 migrate: function ( attrs ) {
273 var n = Object.assign( {}, attrs );
274 n.titleTypo = { sizeDesktop: ( attrs.fontSize || 14 ) + 4 };
275 n.bodyTypo = { sizeDesktop: attrs.fontSize || 14, weight: String( attrs.fontWeight || 700 ) };
276 return n;
277 },
278 } ],
279 } );
280 }() );
281