PluginProbe
Blockenberg — 600+ Advanced Gutenberg Blocks & AI Agent for WordPress Block Editor / 2.0.14
Blockenberg — 600+ Advanced Gutenberg Blocks & AI Agent for WordPress Block Editor v2.0.14
2.0.14 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 / vertical-scroll-image / index.js

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

173 lines 11.6 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 SelectControl = wp.components.SelectControl;
16 var Button = wp.components.Button;
17
18 // Resolve the shared components lazily without defining globals for each block.
19 function _tc(label, key, attrs, setA) {
20 var Control = window.bkbgTypographyControl;
21 return Control ? el(Control, {
22 label: label,
23 value: attrs[key] || {},
24 onChange: function (value) { var update = {}; update[key] = value; setA(update); }
25 }) : null;
26 }
27 function _tvf(vars, key, attrs, prefix) {
28 var cssVars = window.bkbgTypoCssVars;
29 if (cssVars) Object.assign(vars, cssVars(attrs[key] || {}, prefix));
30 return vars;
31 }
32 function getTypoControl(label, key, attrs, setA) { return _tc(label, key, attrs, setA); }
33 function getTypoCssVars(attrs) {
34 var v = {};
35 _tvf(v, 'labelTypo', attrs, '--bkvsi-lb-');
36 _tvf(v, 'captionTypo', attrs, '--bkvsi-cp-');
37 return v;
38 }
39
40 var shadowMap = {
41 none: 'none',
42 sm: '0 2px 8px rgba(0,0,0,0.10)',
43 md: '0 8px 32px rgba(0,0,0,0.15)',
44 lg: '0 20px 60px rgba(0,0,0,0.22)'
45 };
46
47 registerBlockType('blockenberg/vertical-scroll-image', {
48 edit: function (props) {
49 var attr = props.attributes;
50 var setAttr = props.setAttributes;
51 var blockProps = useBlockProps((function () {
52 var s = getTypoCssVars(attr);
53 return { className: 'bkbg-vsi-editor', style: s };
54 })());
55
56 var containerStyle = {
57 position: 'relative',
58 overflow: 'hidden',
59 height: attr.containerHeight + 'px',
60 borderRadius: attr.borderRadius + 'px',
61 border: '1px solid ' + attr.borderColor,
62 boxShadow: shadowMap[attr.shadowSize] || shadowMap.md,
63 background: attr.bgColor,
64 cursor: 'ns-resize'
65 };
66
67 var imgStyle = {
68 width: attr.scrollDirection === 'horizontal' ? 'auto' : '100%',
69 height: attr.scrollDirection === 'horizontal' ? '100%' : 'auto',
70 display: 'block',
71 minHeight: attr.scrollDirection === 'vertical' ? attr.containerHeight + 'px' : undefined,
72 transition: 'object-position ' + attr.scrollDuration + 's ease',
73 objectFit: 'none',
74 objectPosition: attr.scrollDirection === 'vertical' ? 'center top' : 'left center'
75 };
76
77 var wrapStyle = {
78 background: '#fff',
79 paddingTop: attr.paddingTop + 'px',
80 paddingBottom: attr.paddingBottom + 'px'
81 };
82
83 return el(Fragment, null,
84 el(InspectorControls, null,
85 el(PanelBody, { title: __('Image', 'blockenberg'), initialOpen: true },
86 el(MediaUploadCheck, null,
87 el(MediaUpload, {
88 onSelect: function (m) { setAttr({ imageUrl: m.url, imageId: m.id, imageAlt: m.alt || '' }); },
89 allowedTypes: ['image'], value: attr.imageId,
90 render: function (r) {
91 return el(Fragment, null,
92 attr.imageUrl && el('img', { src: attr.imageUrl, style: { width: '100%', height: 80, objectFit: 'cover', borderRadius: 4, marginBottom: 8 } }),
93 el(Button, { onClick: r.open, variant: 'secondary', __nextHasNoMarginBottom: true }, attr.imageUrl ? __('Change Image', 'blockenberg') : __('Select Image', 'blockenberg')),
94 attr.imageUrl && el(Button, { onClick: function () { setAttr({ imageUrl: '', imageId: 0, imageAlt: '' }); }, variant: 'link', isDestructive: true, __nextHasNoMarginBottom: true }, __('Remove', 'blockenberg'))
95 );
96 }
97 })
98 ),
99 el(ToggleControl, { label: __('Show Caption', 'blockenberg'), __nextHasNoMarginBottom: true, checked: attr.showCaption, onChange: function (v) { setAttr({ showCaption: v }); } }),
100 el(ToggleControl, { label: __('Show Scroll Hint Label', 'blockenberg'), __nextHasNoMarginBottom: true, checked: attr.showLabel, onChange: function (v) { setAttr({ showLabel: v }); } })
101 ),
102 el(PanelBody, { title: __('Scroll Behavior', 'blockenberg'), initialOpen: false },
103 el(SelectControl, { label: __('Scroll Direction', 'blockenberg'), __nextHasNoMarginBottom: true, value: attr.scrollDirection,
104 options: [{ label: 'Vertical ↕', value: 'vertical' }, { label: 'Horizontal ↔', value: 'horizontal' }],
105 onChange: function (v) { setAttr({ scrollDirection: v }); } }),
106 el(SelectControl, { label: __('Trigger', 'blockenberg'), __nextHasNoMarginBottom: true, value: attr.scrollTrigger,
107 options: [{ label: __('Hover', 'blockenberg'), value: 'hover' }, { label: __('Auto (loop)', 'blockenberg'), value: 'auto' }],
108 onChange: function (v) { setAttr({ scrollTrigger: v }); } }),
109 el(RangeControl, { label: __('Scroll Duration (s)', 'blockenberg'), __nextHasNoMarginBottom: true, value: attr.scrollDuration, min: 1, max: 15, onChange: function (v) { setAttr({ scrollDuration: v }); } }),
110 el(RangeControl, { label: __('Container Height (px)', 'blockenberg'), __nextHasNoMarginBottom: true, value: attr.containerHeight, min: 150, max: 800, onChange: function (v) { setAttr({ containerHeight: v }); } })
111 ),
112 el(PanelBody, { title: __('Style', 'blockenberg'), initialOpen: false },
113 el(RangeControl, { label: __('Border Radius (px)', 'blockenberg'), __nextHasNoMarginBottom: true, value: attr.borderRadius, min: 0, max: 32, onChange: function (v) { setAttr({ borderRadius: v }); } }),
114 el(SelectControl, { label: __('Shadow', 'blockenberg'), __nextHasNoMarginBottom: true, value: attr.shadowSize,
115 options: [{ label: 'None', value: 'none' }, { label: 'Small', value: 'sm' }, { label: 'Medium', value: 'md' }, { label: 'Large', value: 'lg' }],
116 onChange: function (v) { setAttr({ shadowSize: v }); } }),
117 el(RangeControl, { label: __('Max Width (px)', 'blockenberg'), __nextHasNoMarginBottom: true, value: attr.maxWidth, min: 300, max: 1400, step: 10, onChange: function (v) { setAttr({ maxWidth: v }); } }),
118 el(RangeControl, { label: __('Padding Top (px)', 'blockenberg'), __nextHasNoMarginBottom: true, value: attr.paddingTop, min: 0, max: 150, onChange: function (v) { setAttr({ paddingTop: v }); } }),
119 el(RangeControl, { label: __('Padding Bottom (px)', 'blockenberg'), __nextHasNoMarginBottom: true, value: attr.paddingBottom, min: 0, max: 150, onChange: function (v) { setAttr({ paddingBottom: v }); } })
120 ),
121 el( PanelBody, { title: __( 'Typography', 'blockenberg' ), initialOpen: false },
122 getTypoControl(__('Label', 'blockenberg'), 'labelTypo', attr, setAttr),
123 getTypoControl(__('Caption', 'blockenberg'), 'captionTypo', attr, setAttr)
124 ),
125 el(PanelColorSettings, {
126 title: __('Colors', 'blockenberg'), initialOpen: false,
127 colorSettings: [
128 { value: attr.bgColor, onChange: function (v) { setAttr({ bgColor: v || '#f9fafb' }); }, label: __('Section Background', 'blockenberg') },
129 { value: attr.borderColor, onChange: function (v) { setAttr({ borderColor: v || '#e5e7eb' }); }, label: __('Image Border', 'blockenberg') },
130 { value: attr.captionColor, onChange: function (v) { setAttr({ captionColor: v || '#6b7280' }); }, label: __('Caption Text', 'blockenberg') },
131 { value: attr.labelColor, onChange: function (v) { setAttr({ labelColor: v || '#ffffff' }); }, label: __('Label Text', 'blockenberg') }
132 ]
133 })
134 ),
135 el('div', blockProps,
136 el('div', { style: wrapStyle },
137 el('div', { style: { maxWidth: attr.maxWidth + 'px', margin: '0 auto', padding: '0 20px' } },
138 el('div', { style: containerStyle },
139 attr.imageUrl
140 ? el('img', { src: attr.imageUrl, alt: attr.imageAlt, style: { width: '100%', height: 'auto', display: 'block' } })
141 : el('div', { style: { display: 'flex', alignItems: 'center', justifyContent: 'center', height: '100%', color: '#9ca3af', fontSize: 14 } },
142 el(MediaUploadCheck, null,
143 el(MediaUpload, {
144 onSelect: function (m) { setAttr({ imageUrl: m.url, imageId: m.id, imageAlt: m.alt || '' }); },
145 allowedTypes: ['image'], value: attr.imageId,
146 render: function (r) {
147 return el(Button, { onClick: r.open, variant: 'primary', __nextHasNoMarginBottom: true }, __('+ Select Image', 'blockenberg'));
148 }
149 })
150 )
151 ),
152 attr.showLabel && el('div', { className: 'bkbg-vsi-label', style: { background: attr.labelBg, color: attr.labelColor } },
153 (attr.scrollDirection === 'vertical' ? '↕ ' : '↔ ') + attr.label
154 )
155 ),
156 attr.showCaption && el(RichText, { tagName: 'p', className: 'bkbg-vsi-caption', value: attr.caption, onChange: function (v) { setAttr({ caption: v }); },
157 style: { color: attr.captionColor },
158 placeholder: __('Image caption…', 'blockenberg') })
159 )
160 )
161 )
162 );
163 },
164 save: function (props) {
165 var attr = props.attributes;
166 var blockProps = wp.blockEditor.useBlockProps.save((function () { var _tv = getTypoCssVars(attr); return { style: _tv }; })());
167 return el('div', blockProps,
168 el('div', { className: 'bkbg-vertical-scroll-image-app', 'data-opts': JSON.stringify(attr) })
169 );
170 }
171 });
172 }() );
173