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 / image-placeholder / index.js

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

129 lines 10.4 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 registerBlockType = wp.blocks.registerBlockType;
5 var __ = wp.i18n.__;
6 var InspectorControls = wp.blockEditor.InspectorControls;
7 var PanelColorSettings = wp.blockEditor.PanelColorSettings;
8 var useBlockProps = wp.blockEditor.useBlockProps;
9 var PanelBody = wp.components.PanelBody;
10 var TextControl = wp.components.TextControl;
11 var RangeControl = wp.components.RangeControl;
12 var ToggleControl = wp.components.ToggleControl;
13 var SelectControl = wp.components.SelectControl;
14
15 var _TypographyControl, _typoCssVars;
16 function getTypographyControl() { return _TypographyControl || (_TypographyControl = window.bkbgTypographyControl); }
17 function getTypoCssVars() { return _typoCssVars || (_typoCssVars = window.bkbgTypoCssVars); }
18
19 var PRESETS = [
20 { label: '1:1 Square', w: 400, h: 400 },
21 { label: '4:3', w: 800, h: 600 },
22 { label: '16:9', w: 1280, h: 720 },
23 { label: '3:2', w: 900, h: 600 },
24 { label: '2:3 Portrait',w: 400, h: 600 },
25 { label: '9:16 Story', w: 360, h: 640 }
26 ];
27
28 registerBlockType('blockenberg/image-placeholder', {
29 edit: function (props) {
30 var a = props.attributes;
31 var set = props.setAttributes;
32 var blockProps = useBlockProps({ className: 'bkbg-iph-root', style: (function() {
33 var s = {}; var _tv = getTypoCssVars();
34 Object.assign(s, _tv(a.titleTypo, '--bkbg-iph-tt-'));
35 return s;
36 })() });
37
38 function editorPreview() {
39 var previewW = 320, previewH = Math.round(320 * (a.defaultHeight / a.defaultWidth));
40 if (previewH > 280) { previewH = 280; previewW = Math.round(280 * (a.defaultWidth / a.defaultHeight)); }
41 var displayText = a.defaultText || (a.defaultWidth + ' × ' + a.defaultHeight);
42
43 return el('div', { style: { background: a.sectionBg, padding: '24px', borderRadius: '12px', maxWidth: a.contentMaxWidth + 'px', fontFamily: 'system-ui,sans-serif' } },
44 a.showTitle && el('h2', { className: 'bkbg-iph-title', style: { margin: '0 0 18px', color: a.titleColor } }, a.title),
45
46 /* Canvas preview */
47 el('div', { style: { display: 'flex', justifyContent: 'center', marginBottom: '20px' } },
48 el('div', { style: { width: previewW + 'px', height: previewH + 'px', background: a.defaultBgColor, display: 'flex', alignItems: 'center', justifyContent: 'center', borderRadius: '6px', flexDirection: 'column', boxShadow: '0 4px 16px rgba(0,0,0,0.1)', position: 'relative', overflow: 'hidden' } },
49 a.defaultTheme === 'gradient' && el('div', { style: { position: 'absolute', inset: 0, background: 'linear-gradient(135deg,' + a.defaultBgColor + ',' + a.accentColor + ')', opacity: 0.85 } }),
50 a.defaultTheme === 'pattern' && el('div', { style: { position: 'absolute', inset: 0, backgroundImage: 'repeating-linear-gradient(45deg,' + a.defaultBgColor + ' 0,' + a.defaultBgColor + ' 5px,' + a.accentColor + '22 5px,' + a.accentColor + '22 10px)' } }),
51 el('div', { style: { position: 'relative', zIndex: 1, color: a.defaultTextColor, fontWeight: 700, fontSize: '15px', textAlign: 'center', padding: '8px', wordBreak: 'break-word' } }, displayText),
52 el('div', { style: { position: 'relative', zIndex: 1, color: a.defaultTextColor, fontSize: '12px', opacity: 0.7 } }, a.defaultTheme !== 'flat' ? a.defaultTheme : '')
53 )
54 ),
55
56 /* Preset buttons */
57 a.showAspectPresets && el('div', { style: { display: 'flex', gap: '8px', flexWrap: 'wrap', marginBottom: '16px', justifyContent: 'center' } },
58 PRESETS.map(function (p) {
59 return el('button', {
60 key: p.label,
61 style: { padding: '5px 12px', borderRadius: '6px', border: '1px solid ' + a.accentColor, background: (a.defaultWidth === p.w && a.defaultHeight === p.h) ? a.accentColor : 'transparent', color: (a.defaultWidth === p.w && a.defaultHeight === p.h) ? '#fff' : a.accentColor, fontSize: '12px', fontWeight: 600, cursor: 'pointer' }
62 }, p.label);
63 })
64 ),
65
66 /* Action buttons */
67 el('div', { style: { display: 'flex', gap: '10px', flexWrap: 'wrap', justifyContent: 'center' } },
68 a.showDownloadBtn && el('button', { style: { background: a.accentColor, color: '#fff', border: 'none', borderRadius: '7px', padding: '10px 22px', fontWeight: 700, cursor: 'pointer', fontSize: '14px' } }, '⬇ Download PNG'),
69 a.showCopyUriBtn && el('button', { style: { background: 'transparent', border: '2px solid ' + a.accentColor, color: a.accentColor, borderRadius: '7px', padding: '8px 18px', fontWeight: 700, cursor: 'pointer', fontSize: '14px' } }, 'Copy Data URI'),
70 a.showCopyUrlBtn && el('button', { style: { background: 'transparent', border: '2px solid #6b7280', color: '#6b7280', borderRadius: '7px', padding: '8px 18px', fontWeight: 700, cursor: 'pointer', fontSize: '14px' } }, 'Copy URL')
71 )
72 );
73 }
74
75 return el(Fragment, null,
76 el(InspectorControls, null,
77 el(PanelBody, { title: 'Content', initialOpen: true },
78 el(ToggleControl, { label: 'Show Title', checked: a.showTitle, onChange: function (v) { set({ showTitle: v }); }, __nextHasNoMarginBottom: true }),
79 el('div', { style: { marginBottom: '16px' } }),
80 el(TextControl, { label: 'Title', value: a.title, onChange: function (v) { set({ title: v }); }, __nextHasNoMarginBottom: true })
81 ),
82 el(PanelBody, { title: 'Default Settings', initialOpen: false },
83 el(RangeControl, { label: 'Default Width (px)', value: a.defaultWidth, min: 50, max: 2000, step: 10, onChange: function (v) { set({ defaultWidth: v }); }, __nextHasNoMarginBottom: true }),
84 el('div', { style: { marginBottom: '16px' } }),
85 el(RangeControl, { label: 'Default Height (px)', value: a.defaultHeight, min: 50, max: 2000, step: 10, onChange: function (v) { set({ defaultHeight: v }); }, __nextHasNoMarginBottom: true }),
86 el('div', { style: { marginBottom: '16px' } }),
87 el(TextControl, { label: 'Default Text (blank = dimensions)', value: a.defaultText, onChange: function (v) { set({ defaultText: v }); }, __nextHasNoMarginBottom: true }),
88 el('div', { style: { marginBottom: '16px' } }),
89 el(SelectControl, { label: 'Default Theme', value: a.defaultTheme, options: [{ label: 'Flat', value: 'flat' }, { label: 'Gradient', value: 'gradient' }, { label: 'Pattern', value: 'pattern' }], onChange: function (v) { set({ defaultTheme: v }); }, __nextHasNoMarginBottom: true })
90 ),
91 el(PanelBody, { title: 'Features', initialOpen: false },
92 el(ToggleControl, { label: 'Show Aspect Ratio Presets', checked: a.showAspectPresets, onChange: function (v) { set({ showAspectPresets: v }); }, __nextHasNoMarginBottom: true }),
93 el(ToggleControl, { label: 'Show Theme Selector', checked: a.showThemeSelector, onChange: function (v) { set({ showThemeSelector: v }); }, __nextHasNoMarginBottom: true }),
94 el(ToggleControl, { label: 'Show Download Button', checked: a.showDownloadBtn, onChange: function (v) { set({ showDownloadBtn: v }); }, __nextHasNoMarginBottom: true }),
95 el(ToggleControl, { label: 'Show Copy Data URI', checked: a.showCopyUriBtn, onChange: function (v) { set({ showCopyUriBtn: v }); }, __nextHasNoMarginBottom: true }),
96 el(ToggleControl, { label: 'Show Copy URL Button', checked: a.showCopyUrlBtn, onChange: function (v) { set({ showCopyUrlBtn: v }); }, __nextHasNoMarginBottom: true })
97 ),
98 el(PanelBody, { title: 'Typography', initialOpen: false },
99 getTypographyControl() && el(getTypographyControl(), { label: __('Title', 'blockenberg'), value: a.titleTypo, onChange: function (v) { set({ titleTypo: v }); } }),
100 el('div', { style: { marginBottom: '16px' } }),
101 el(RangeControl, { label: 'Max Width (px)', value: a.contentMaxWidth, min: 400, max: 1200, step: 10, onChange: function (v) { set({ contentMaxWidth: v }); }, __nextHasNoMarginBottom: true })
102 ),
103 el(PanelColorSettings, {
104 title: 'Colors',
105 initialOpen: false,
106 colorSettings: [
107 { label: 'Accent Color', value: a.accentColor, onChange: function (v) { set({ accentColor: v || '#6366f1' }); } },
108 { label: 'Default BG Color', value: a.defaultBgColor, onChange: function (v) { set({ defaultBgColor: v || '#cccccc' }); } },
109 { label: 'Default Text Color', value: a.defaultTextColor, onChange: function (v) { set({ defaultTextColor: v || '#555555' }); } },
110 { label: 'Section Background', value: a.sectionBg, onChange: function (v) { set({ sectionBg: v || '#f5f3ff' }); } },
111 { label: 'Card Background', value: a.cardBg, onChange: function (v) { set({ cardBg: v || '#ffffff' }); } },
112 { label: 'Title Color', value: a.titleColor, onChange: function (v) { set({ titleColor: v || '#3730a3' }); } },
113 { label: 'Label Color', value: a.labelColor, onChange: function (v) { set({ labelColor: v || '#374151' }); } }
114 ]
115 })
116 ),
117 el('div', blockProps, editorPreview())
118 );
119 },
120 save: function (props) {
121 var a = props.attributes;
122 var useBlockProps = wp.blockEditor.useBlockProps;
123 return el('div', useBlockProps.save(),
124 el('div', { className: 'bkbg-iph-app', 'data-opts': JSON.stringify(a) })
125 );
126 }
127 });
128 }() );
129