| 1 |
( function () { |
| 2 |
var el = wp.element.createElement; |
| 3 |
var registerBlockType = wp.blocks.registerBlockType; |
| 4 |
var useBlockProps = wp.blockEditor.useBlockProps; |
| 5 |
var InspectorControls = wp.blockEditor.InspectorControls; |
| 6 |
var PanelColorSettings = wp.blockEditor.PanelColorSettings; |
| 7 |
var RichText = wp.blockEditor.RichText; |
| 8 |
var PanelBody = wp.components.PanelBody; |
| 9 |
var RangeControl = wp.components.RangeControl; |
| 10 |
var ToggleControl = wp.components.ToggleControl; |
| 11 |
var SelectControl = wp.components.SelectControl; |
| 12 |
var TextControl = wp.components.TextControl; |
| 13 |
|
| 14 |
var _tc, _tvf; |
| 15 |
Object.defineProperty(window, '_tc', { get: function () { return _tc || (_tc = window.bkbgTypographyControl); } }); |
| 16 |
Object.defineProperty(window, '_tvf', { get: function () { return _tvf || (_tvf = window.bkbgTypoCssVars); } }); |
| 17 |
function getTypoControl(label, key, attrs, setA) { return _tc(label, key, attrs, setA); } |
| 18 |
function getTypoCssVars(attrs) { |
| 19 |
var v = {}; |
| 20 |
_tvf(v, 'contentTypo', attrs, '--bkufd-ct-'); |
| 21 |
_tvf(v, 'buttonTypo', attrs, '--bkufd-bt-'); |
| 22 |
return v; |
| 23 |
} |
| 24 |
|
| 25 |
registerBlockType('blockenberg/unfold', { |
| 26 |
edit: function (props) { |
| 27 |
var a = props.attributes; |
| 28 |
var set = props.setAttributes; |
| 29 |
var blockProps = useBlockProps((function () { var _tv = getTypoCssVars(a); var s = {}; Object.assign(s, _tv); return { style: s }; })()); |
| 30 |
|
| 31 |
var btnStyle = {}; |
| 32 |
if (a.buttonStyle === 'filled') { |
| 33 |
btnStyle = { |
| 34 |
background: a.buttonBg || '#6366f1', |
| 35 |
color: a.buttonColor || '#ffffff', |
| 36 |
border: 'none', |
| 37 |
borderRadius: (a.borderRadius || 8) + 'px', |
| 38 |
padding: '10px 24px', |
| 39 |
cursor: 'pointer', |
| 40 |
transition: 'opacity .2s, transform .15s', |
| 41 |
display: 'inline-block' |
| 42 |
}; |
| 43 |
} else if (a.buttonStyle === 'outline') { |
| 44 |
btnStyle = { |
| 45 |
background: 'transparent', |
| 46 |
color: a.accentColor || '#6366f1', |
| 47 |
border: '2px solid ' + (a.accentColor || '#6366f1'), |
| 48 |
borderRadius: (a.borderRadius || 8) + 'px', |
| 49 |
padding: '10px 24px', |
| 50 |
cursor: 'pointer', |
| 51 |
display: 'inline-block' |
| 52 |
}; |
| 53 |
} else { // text |
| 54 |
btnStyle = { |
| 55 |
background: 'none', |
| 56 |
border: 'none', |
| 57 |
color: a.accentColor || '#6366f1', |
| 58 |
cursor: 'pointer', |
| 59 |
padding: '4px 0', |
| 60 |
display: 'inline-block' |
| 61 |
}; |
| 62 |
} |
| 63 |
|
| 64 |
return el('div', blockProps, |
| 65 |
el(InspectorControls, {}, |
| 66 |
el(PanelBody, { title: 'Content', initialOpen: true }, |
| 67 |
el(RangeControl, { label: 'Preview height (px)', value: a.previewHeight || 200, |
| 68 |
onChange: function (v) { set({ previewHeight: v }); }, min: 60, max: 800, __nextHasNoMarginBottom: true }), |
| 69 |
el(RangeControl, { label: 'Fade gradient height (px)', value: a.gradientHeight || 60, |
| 70 |
onChange: function (v) { set({ gradientHeight: v }); }, min: 20, max: 200, __nextHasNoMarginBottom: true }), |
| 71 |
el(RangeControl, { label: 'Expand animation (ms)', value: a.animationDuration || 400, |
| 72 |
onChange: function (v) { set({ animationDuration: v }); }, min: 100, max: 1200, step: 50, __nextHasNoMarginBottom: true }) |
| 73 |
), |
| 74 |
el(PanelBody, { title: 'Button Settings', initialOpen: false }, |
| 75 |
el(TextControl, { label: 'Expand button text', value: a.expandText || '', |
| 76 |
onChange: function (v) { set({ expandText: v }); }, __nextHasNoMarginBottom: true }), |
| 77 |
el(TextControl, { label: 'Collapse button text', value: a.collapseText || '', |
| 78 |
onChange: function (v) { set({ collapseText: v }); }, __nextHasNoMarginBottom: true }), |
| 79 |
el(ToggleControl, { label: 'Show collapse button', checked: a.showCollapseBtn !== false, |
| 80 |
onChange: function (v) { set({ showCollapseBtn: v }); }, __nextHasNoMarginBottom: true }), |
| 81 |
el(SelectControl, { label: 'Button alignment', value: a.buttonAlign || 'center', |
| 82 |
options: [ |
| 83 |
{ label: 'Left', value: 'left' }, |
| 84 |
{ label: 'Center', value: 'center' }, |
| 85 |
{ label: 'Right', value: 'right' } |
| 86 |
], |
| 87 |
onChange: function (v) { set({ buttonAlign: v }); }, __nextHasNoMarginBottom: true }), |
| 88 |
el(SelectControl, { label: 'Button style', value: a.buttonStyle || 'filled', |
| 89 |
options: [ |
| 90 |
{ label: 'Filled', value: 'filled' }, |
| 91 |
{ label: 'Outline', value: 'outline' }, |
| 92 |
{ label: 'Text', value: 'text' } |
| 93 |
], |
| 94 |
onChange: function (v) { set({ buttonStyle: v }); }, __nextHasNoMarginBottom: true }), |
| 95 |
el(RangeControl, { label: 'Border radius', value: a.borderRadius || 8, |
| 96 |
onChange: function (v) { set({ borderRadius: v }); }, min: 0, max: 40, __nextHasNoMarginBottom: true }) |
| 97 |
), |
| 98 |
|
| 99 |
el( PanelBody, { title: 'Typography', initialOpen: false }, |
| 100 |
getTypoControl('Content', 'contentTypo', a, set), |
| 101 |
getTypoControl('Button', 'buttonTypo', a, set) |
| 102 |
), |
| 103 |
el(PanelColorSettings, { |
| 104 |
title: 'Colors', initialOpen: false, |
| 105 |
colorSettings: [ |
| 106 |
{ label: 'Section background', value: a.sectionBg, onChange: function (v) { set({ sectionBg: v || '#ffffff' }); } }, |
| 107 |
{ label: 'Content text', value: a.contentColor, onChange: function (v) { set({ contentColor: v || '#374151' }); } }, |
| 108 |
{ label: 'Gradient end color', value: a.gradientTo, onChange: function (v) { set({ gradientTo: v || '#ffffff' }); } }, |
| 109 |
{ label: 'Accent / focus', value: a.accentColor, onChange: function (v) { set({ accentColor: v || '#6366f1' }); } }, |
| 110 |
{ label: 'Button background', value: a.buttonBg, onChange: function (v) { set({ buttonBg: v || '#6366f1' }); } }, |
| 111 |
{ label: 'Button text', value: a.buttonColor, onChange: function (v) { set({ buttonColor: v || '#ffffff' }); } } |
| 112 |
], |
| 113 |
disableCustomGradients: true |
| 114 |
}) |
| 115 |
), |
| 116 |
|
| 117 |
// Editor preview |
| 118 |
el('div', { |
| 119 |
style: { |
| 120 |
background: a.sectionBg || '#ffffff', |
| 121 |
padding: '24px', |
| 122 |
borderRadius: (a.borderRadius || 8) + 'px', |
| 123 |
border: '1px solid #e5e7eb' |
| 124 |
} |
| 125 |
}, |
| 126 |
// Content area (limited height visually) |
| 127 |
el('div', { |
| 128 |
className: 'bkbg-ufd-content-body', |
| 129 |
style: { |
| 130 |
position: 'relative', |
| 131 |
maxHeight: (a.previewHeight || 200) + 'px', |
| 132 |
overflow: 'hidden', |
| 133 |
color: a.contentColor || '#374151' |
| 134 |
} |
| 135 |
}, |
| 136 |
el(RichText, { |
| 137 |
tagName: 'div', |
| 138 |
value: a.content, |
| 139 |
onChange: function (v) { set({ content: v }); }, |
| 140 |
placeholder: 'Write your expandable content here…', |
| 141 |
multiline: 'p' |
| 142 |
}), |
| 143 |
// Gradient overlay |
| 144 |
el('div', { |
| 145 |
style: { |
| 146 |
position: 'absolute', |
| 147 |
bottom: 0, left: 0, right: 0, |
| 148 |
height: (a.gradientHeight || 60) + 'px', |
| 149 |
background: 'linear-gradient(transparent, ' + (a.gradientTo || '#ffffff') + ')', |
| 150 |
pointerEvents: 'none' |
| 151 |
} |
| 152 |
}) |
| 153 |
), |
| 154 |
// Button row |
| 155 |
el('div', { |
| 156 |
style: { |
| 157 |
textAlign: a.buttonAlign || 'center', |
| 158 |
marginTop: 16 |
| 159 |
} |
| 160 |
}, |
| 161 |
el('span', { className: 'bkbg-ufd-btn', style: btnStyle }, a.expandText || 'Read More ↓') |
| 162 |
) |
| 163 |
) |
| 164 |
); |
| 165 |
}, |
| 166 |
|
| 167 |
save: function (props) { |
| 168 |
var a = props.attributes; |
| 169 |
var blockProps = useBlockProps.save((function () { var _tv = getTypoCssVars(a); var s = {}; Object.assign(s, _tv); return { style: s }; })()); |
| 170 |
var opts = { |
| 171 |
previewHeight: a.previewHeight || 200, |
| 172 |
expandText: a.expandText || 'Read More ↓', |
| 173 |
collapseText: a.collapseText || 'Show Less ↑', |
| 174 |
showCollapseBtn: a.showCollapseBtn !== false, |
| 175 |
gradientHeight: a.gradientHeight || 60, |
| 176 |
animationDuration: a.animationDuration || 400, |
| 177 |
buttonAlign: a.buttonAlign || 'center', |
| 178 |
buttonStyle: a.buttonStyle || 'filled', |
| 179 |
borderRadius: a.borderRadius || 8, |
| 180 |
sectionBg: a.sectionBg || '#ffffff', |
| 181 |
contentColor: a.contentColor || '#374151', |
| 182 |
gradientTo: a.gradientTo || '#ffffff', |
| 183 |
accentColor: a.accentColor || '#6366f1', |
| 184 |
buttonBg: a.buttonBg || '#6366f1', |
| 185 |
buttonColor: a.buttonColor || '#ffffff' |
| 186 |
}; |
| 187 |
return el('div', blockProps, |
| 188 |
el('div', { className: 'bkbg-ufd-app', 'data-opts': JSON.stringify(opts) }, |
| 189 |
el('div', { className: 'bkbg-ufd-content-src' }, |
| 190 |
el(RichText.Content, { tagName: 'div', value: a.content, multiline: 'p' }) |
| 191 |
) |
| 192 |
) |
| 193 |
); |
| 194 |
} |
| 195 |
}); |
| 196 |
}() ); |
| 197 |
|