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