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 / error-page / index.js

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

118 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 Fragment = wp.element.Fragment;
4 var __ = wp.i18n.__;
5 var registerBlockType = wp.blocks.registerBlockType;
6 var InspectorControls = wp.blockEditor.InspectorControls;
7 var MediaUpload = wp.blockEditor.MediaUpload;
8 var MediaUploadCheck = wp.blockEditor.MediaUploadCheck;
9 var useBlockProps = wp.blockEditor.useBlockProps;
10 var RichText = wp.blockEditor.RichText;
11 var PanelBody = wp.components.PanelBody;
12 var PanelColorSettings = wp.blockEditor.PanelColorSettings;
13 var ToggleControl = wp.components.ToggleControl;
14 var RangeControl = wp.components.RangeControl;
15 var TextControl = wp.components.TextControl;
16 var Button = wp.components.Button;
17
18 var _epgTC, _epgTV;
19 function _tc() { return _epgTC || (_epgTC = window.bkbgTypographyControl); }
20 function _tv(t, p) { return (_epgTV || (_epgTV = window.bkbgTypoCssVars)) ? _epgTV(t, p) : {}; }
21
22 registerBlockType('blockenberg/error-page', {
23 edit: function (props) {
24 var attr = props.attributes;
25 var setAttr = props.setAttributes;
26 var blockProps = useBlockProps({ className: 'bkbg-ep-editor', style: Object.assign({},
27 _tv(attr.typoCode || {}, '--bkbg-ep-cd-'),
28 _tv(attr.typoHeading || {}, '--bkbg-ep-hd-'),
29 _tv(attr.typoBody || {}, '--bkbg-ep-bd-')
30 ) });
31
32 var previewStyle = { background: attr.bgColor, padding: attr.paddingTop + 'px 40px ' + attr.paddingBottom + 'px', textAlign: 'center' };
33 var innerStyle = { maxWidth: attr.maxWidth + 'px', margin: '0 auto', display: 'flex', flexDirection: 'column', alignItems: 'center', gap: 24 };
34
35 return el(Fragment, null,
36 el(InspectorControls, null,
37 el(PanelBody, { title: __('Content', 'blockenberg'), initialOpen: true },
38 el(ToggleControl, { label: __('Show Error Code', 'blockenberg'), __nextHasNoMarginBottom: true, checked: attr.showError, onChange: function (v) { setAttr({ showError: v }); } }),
39 attr.showError && el(TextControl, { label: __('Error Code', 'blockenberg'), __nextHasNoMarginBottom: true, value: attr.errorCode, onChange: function (v) { setAttr({ errorCode: v }); } }),
40 el(TextControl, { label: __('Primary Button Label', 'blockenberg'), __nextHasNoMarginBottom: true, value: attr.primaryLabel, onChange: function (v) { setAttr({ primaryLabel: v }); } }),
41 el(TextControl, { label: __('Primary Button URL', 'blockenberg'), __nextHasNoMarginBottom: true, value: attr.primaryUrl, onChange: function (v) { setAttr({ primaryUrl: v }); } }),
42 el(ToggleControl, { label: __('Show Secondary Button', 'blockenberg'), __nextHasNoMarginBottom: true, checked: attr.showSecondary, onChange: function (v) { setAttr({ showSecondary: v }); } }),
43 attr.showSecondary && el(TextControl, { label: __('Secondary Button Label', 'blockenberg'), __nextHasNoMarginBottom: true, value: attr.secondaryLabel, onChange: function (v) { setAttr({ secondaryLabel: v }); } }),
44 attr.showSecondary && el(TextControl, { label: __('Secondary Button URL', 'blockenberg'), __nextHasNoMarginBottom: true, value: attr.secondaryUrl, onChange: function (v) { setAttr({ secondaryUrl: v }); } }),
45 el(ToggleControl, { label: __('Show Search Bar', 'blockenberg'), __nextHasNoMarginBottom: true, checked: attr.showSearch, onChange: function (v) { setAttr({ showSearch: v }); } })
46 ),
47 el(PanelBody, { title: __('Illustration', 'blockenberg'), initialOpen: false },
48 el(ToggleControl, { label: __('Show Illustration Image', 'blockenberg'), __nextHasNoMarginBottom: true, checked: attr.showImage, onChange: function (v) { setAttr({ showImage: v }); } }),
49 attr.showImage && el(Fragment, null,
50 el(MediaUploadCheck, null,
51 el(MediaUpload, {
52 onSelect: function (m) { setAttr({ imageUrl: m.url, imageId: m.id, imageAlt: m.alt || '' }); },
53 allowedTypes: ['image'], value: attr.imageId,
54 render: function (r) {
55 return el(Fragment, null,
56 attr.imageUrl && el('img', { src: attr.imageUrl, style: { maxWidth: 160, display: 'block', marginBottom: 8 } }),
57 el(Button, { onClick: r.open, variant: 'secondary', __nextHasNoMarginBottom: true }, attr.imageUrl ? __('Change Image', 'blockenberg') : __('Select Illustration', 'blockenberg')),
58 attr.imageUrl && el(Button, { onClick: function () { setAttr({ imageUrl: '', imageId: 0 }); }, variant: 'link', isDestructive: true, __nextHasNoMarginBottom: true, style: { marginLeft: 8 } }, __('Remove', 'blockenberg'))
59 );
60 }
61 })
62 ),
63 el(RangeControl, { label: __('Image Width (px)', 'blockenberg'), __nextHasNoMarginBottom: true, value: attr.imageWidth, min: 100, max: 600, onChange: function (v) { setAttr({ imageWidth: v }); } })
64 )
65 ),
66 el(PanelBody, { title: __('Sizing', 'blockenberg'), initialOpen: false },
67 el(RangeControl, { label: __('Max Width (px)', 'blockenberg'), __nextHasNoMarginBottom: true, value: attr.maxWidth, min: 400, max: 1200, step: 10, onChange: function (v) { setAttr({ maxWidth: v }); } }),
68 el(RangeControl, { label: __('Padding Top (px)', 'blockenberg'), __nextHasNoMarginBottom: true, value: attr.paddingTop, min: 0, max: 300, onChange: function (v) { setAttr({ paddingTop: v }); } }),
69 el(RangeControl, { label: __('Padding Bottom (px)', 'blockenberg'), __nextHasNoMarginBottom: true, value: attr.paddingBottom, min: 0, max: 300, onChange: function (v) { setAttr({ paddingBottom: v }); } })
70 ),
71
72 el( PanelBody, { title: __( 'Typography', 'blockenberg' ), initialOpen: false },
73 _tc() && el(_tc(), { label: __('Error Code', 'blockenberg'), typo: attr.typoCode || {}, onChange: function (v) { setAttr({ typoCode: v }); } }),
74 _tc() && el(_tc(), { label: __('Heading', 'blockenberg'), typo: attr.typoHeading || {}, onChange: function (v) { setAttr({ typoHeading: v }); } }),
75 _tc() && el(_tc(), { label: __('Body / Buttons', 'blockenberg'), typo: attr.typoBody || {}, onChange: function (v) { setAttr({ typoBody: v }); } })
76 ),
77 el(PanelColorSettings, {
78 title: __('Colors', 'blockenberg'), initialOpen: false,
79 colorSettings: [
80 { value: attr.bgColor, onChange: function (v) { setAttr({ bgColor: v || '#ffffff' }); }, label: __('Background', 'blockenberg') },
81 { value: attr.errorCodeColor, onChange: function (v) { setAttr({ errorCodeColor: v || '#f3f0ff' }); }, label: __('Error Code Color', 'blockenberg') },
82 { value: attr.headingColor, onChange: function (v) { setAttr({ headingColor: v || '#111827' }); }, label: __('Heading', 'blockenberg') },
83 { value: attr.textColor, onChange: function (v) { setAttr({ textColor: v || '#6b7280' }); }, label: __('Body Text', 'blockenberg') },
84 { value: attr.primaryBg, onChange: function (v) { setAttr({ primaryBg: v || '#7c3aed' }); }, label: __('Primary Button BG', 'blockenberg') },
85 { value: attr.primaryColor, onChange: function (v) { setAttr({ primaryColor: v || '#ffffff' }); }, label: __('Primary Button Text', 'blockenberg') },
86 { value: attr.secondaryColor, onChange: function (v) { setAttr({ secondaryColor: v || '#374151' }); }, label: __('Secondary Button Text', 'blockenberg') }
87 ]
88 })
89 ),
90 el('div', blockProps,
91 el('div', { style: previewStyle },
92 el('div', { style: innerStyle },
93 attr.showImage && attr.imageUrl && el('img', { src: attr.imageUrl, alt: attr.imageAlt, style: { width: attr.imageWidth + 'px', display: 'block' } }),
94 attr.showError && el('div', { className: 'bkbg-ep-code', style: { color: attr.errorCodeColor, userSelect: 'none' } }, attr.errorCode),
95 el(RichText, { tagName: 'h1', className: 'bkbg-ep-heading', value: attr.heading, onChange: function (v) { setAttr({ heading: v }); }, style: { color: attr.headingColor, margin: 0 }, placeholder: __('Error heading…', 'blockenberg') }),
96 el(RichText, { tagName: 'p', className: 'bkbg-ep-body', value: attr.subtext, onChange: function (v) { setAttr({ subtext: v }); }, style: { color: attr.textColor, margin: 0, maxWidth: 520 }, placeholder: __('Explanation…', 'blockenberg') }),
97 attr.showSearch && el('div', { style: { display: 'flex', gap: 8, width: '100%', maxWidth: 420 } },
98 el('input', { type: 'search', placeholder: __('Search…', 'blockenberg'), readOnly: true, style: { flex: 1, padding: '12px 20px', borderRadius: 8, border: '1px solid #e5e7eb', fontSize: 15 } }),
99 el('button', { style: { padding: '12px 20px', borderRadius: 8, background: attr.primaryBg, color: attr.primaryColor, border: 'none', fontWeight: 600, cursor: 'pointer' } }, __('Search', 'blockenberg'))
100 ),
101 el('div', { style: { display: 'flex', gap: 16, flexWrap: 'wrap', justifyContent: 'center' } },
102 el('a', { href: '#', className: 'bkbg-ep-primary', style: { background: attr.primaryBg, color: attr.primaryColor } }, '' + attr.primaryLabel),
103 attr.showSecondary && el('a', { href: '#', className: 'bkbg-ep-secondary', style: { color: attr.secondaryColor } }, attr.secondaryLabel)
104 )
105 )
106 )
107 )
108 );
109 },
110 save: function (props) {
111 var attr = props.attributes;
112 return el('div', useBlockProps.save(),
113 el('div', { className: 'bkbg-error-page-app', 'data-opts': JSON.stringify(attr) })
114 );
115 }
116 });
117 }() );
118