| 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 useBlockProps = wp.blockEditor.useBlockProps; |
| 8 |
var RichText = wp.blockEditor.RichText; |
| 9 |
var PanelBody = wp.components.PanelBody; |
| 10 |
var PanelColorSettings = wp.blockEditor.PanelColorSettings; |
| 11 |
var ToggleControl = wp.components.ToggleControl; |
| 12 |
var RangeControl = wp.components.RangeControl; |
| 13 |
var SelectControl = wp.components.SelectControl; |
| 14 |
|
| 15 |
function getTypographyControl() { return (window.bkbgTypographyControl || function () { return null; }); } |
| 16 |
function getTypoCssVars() { return (window.bkbgTypoCssVars || function () { return {}; }); } |
| 17 |
function _tv(typo, prefix) { var fn = getTypoCssVars(); return fn(typo || {}, prefix); } |
| 18 |
|
| 19 |
registerBlockType('blockenberg/chapter-intro', { |
| 20 |
edit: function (props) { |
| 21 |
var attr = props.attributes; |
| 22 |
var setAttr = props.setAttributes; |
| 23 |
var blockProps = useBlockProps({ className: 'bkbg-ci-editor' }); |
| 24 |
|
| 25 |
var isLeft = attr.layout === 'left'; |
| 26 |
|
| 27 |
/* Divider element */ |
| 28 |
function renderDivider() { |
| 29 |
if (!attr.showDivider) return null; |
| 30 |
if (attr.dividerStyle === 'dots') { |
| 31 |
return el('div', { className: 'bkbg-ci-divider bkbg-ci-divider-dots', style: { color: attr.dividerColor, textAlign: isLeft ? 'left' : 'center', margin: '24px 0' } }, '● ● ●'); |
| 32 |
} |
| 33 |
if (attr.dividerStyle === 'gradient') { |
| 34 |
return el('div', { className: 'bkbg-ci-divider bkbg-ci-divider-gradient', style: { |
| 35 |
height: 3, borderRadius: 2, margin: '24px ' + (isLeft ? '0' : 'auto'), |
| 36 |
width: 80, |
| 37 |
background: 'linear-gradient(90deg, ' + attr.accentColor + ', transparent)' |
| 38 |
} }); |
| 39 |
} |
| 40 |
/* default: line */ |
| 41 |
return el('hr', { className: 'bkbg-ci-divider', style: { border: 'none', borderTop: '2px solid ' + attr.dividerColor, margin: '24px ' + (isLeft ? '0' : 'auto'), width: 80 } }); |
| 42 |
} |
| 43 |
|
| 44 |
/* Big number behind/above */ |
| 45 |
var numberEl = attr.numberStyle === 'ghost' |
| 46 |
? el('div', { className: 'bkbg-ci-number bkbg-ci-number-ghost', style: { |
| 47 |
fontSize: attr.numberSize + 'px', |
| 48 |
color: 'transparent', |
| 49 |
WebkitTextStroke: '2px ' + attr.numberColor, |
| 50 |
textAlign: isLeft ? 'left' : 'center', |
| 51 |
fontWeight: 900, |
| 52 |
lineHeight: 0.9, |
| 53 |
marginBottom: 8 |
| 54 |
} }, attr.chapterNumber) |
| 55 |
: el('div', { className: 'bkbg-ci-number bkbg-ci-number-display', style: { |
| 56 |
fontSize: attr.numberSize + 'px', |
| 57 |
color: attr.numberColor, |
| 58 |
fontWeight: 900, |
| 59 |
lineHeight: 0.9, |
| 60 |
textAlign: isLeft ? 'left' : 'center', |
| 61 |
marginBottom: 8 |
| 62 |
} }, attr.chapterNumber); |
| 63 |
|
| 64 |
var wrapStyle = Object.assign({ |
| 65 |
background: attr.bgColor, |
| 66 |
paddingTop: attr.paddingTop + 'px', |
| 67 |
paddingBottom: attr.paddingBottom + 'px' |
| 68 |
}, _tv(attr.typoHeading, '--bkbg-ci-h-'), _tv(attr.typoText, '--bkbg-ci-t-'), _tv(attr.typoLabel, '--bkbg-ci-l-')); |
| 69 |
var innerStyle = { |
| 70 |
maxWidth: attr.maxWidth + 'px', |
| 71 |
margin: '0 auto', |
| 72 |
textAlign: isLeft ? 'left' : 'center' |
| 73 |
}; |
| 74 |
|
| 75 |
return el(Fragment, null, |
| 76 |
el(InspectorControls, null, |
| 77 |
el(PanelBody, { title: __('Layout & Style', 'blockenberg'), initialOpen: true }, |
| 78 |
el(SelectControl, { label: __('Layout', 'blockenberg'), __nextHasNoMarginBottom: true, value: attr.layout, |
| 79 |
options: [{ label: 'Centered', value: 'centered' }, { label: 'Left Aligned', value: 'left' }], |
| 80 |
onChange: function (v) { setAttr({ layout: v }); } }), |
| 81 |
el(SelectControl, { label: __('Number Style', 'blockenberg'), __nextHasNoMarginBottom: true, value: attr.numberStyle, |
| 82 |
options: [{ label: __('Solid (filled color)', 'blockenberg'), value: 'display' }, { label: __('Ghost (outline only)', 'blockenberg'), value: 'ghost' }], |
| 83 |
onChange: function (v) { setAttr({ numberStyle: v }); } }), |
| 84 |
el(ToggleControl, { label: __('Show Chapter Label', 'blockenberg'), __nextHasNoMarginBottom: true, checked: attr.showLabel, onChange: function (v) { setAttr({ showLabel: v }); } }), |
| 85 |
el(ToggleControl, { label: __('Show Divider', 'blockenberg'), __nextHasNoMarginBottom: true, checked: attr.showDivider, onChange: function (v) { setAttr({ showDivider: v }); } }), |
| 86 |
attr.showDivider && el(SelectControl, { label: __('Divider Style', 'blockenberg'), __nextHasNoMarginBottom: true, value: attr.dividerStyle, |
| 87 |
options: [{ label: 'Line', value: 'line' }, { label: 'Dots', value: 'dots' }, { label: 'Gradient', value: 'gradient' }], |
| 88 |
onChange: function (v) { setAttr({ dividerStyle: v }); } }) |
| 89 |
), |
| 90 |
el(PanelBody, { title: __('Sizing', 'blockenberg'), initialOpen: false }, |
| 91 |
el(RangeControl, { label: __('Max Width (px)', 'blockenberg'), __nextHasNoMarginBottom: true, value: attr.maxWidth, min: 400, max: 1400, step: 10, onChange: function (v) { setAttr({ maxWidth: v }); } }), |
| 92 |
el(RangeControl, { label: __('Padding Top (px)', 'blockenberg'), __nextHasNoMarginBottom: true, value: attr.paddingTop, min: 0, max: 200, onChange: function (v) { setAttr({ paddingTop: v }); } }), |
| 93 |
el(RangeControl, { label: __('Padding Bottom (px)', 'blockenberg'), __nextHasNoMarginBottom: true, value: attr.paddingBottom, min: 0, max: 200, onChange: function (v) { setAttr({ paddingBottom: v }); } }) |
| 94 |
), |
| 95 |
|
| 96 |
el( PanelBody, { title: __( 'Typography', 'blockenberg' ), initialOpen: false }, |
| 97 |
el(RangeControl, { label: __('Number Size (px)', 'blockenberg'), __nextHasNoMarginBottom: true, value: attr.numberSize, min: 48, max: 400, onChange: function (v) { setAttr({ numberSize: v }); } }), |
| 98 |
el(getTypographyControl(), { label: __('Heading', 'blockenberg'), value: attr.typoHeading, onChange: function (v) { setAttr({ typoHeading: v }); } }), |
| 99 |
el(getTypographyControl(), { label: __('Text', 'blockenberg'), value: attr.typoText, onChange: function (v) { setAttr({ typoText: v }); } }), |
| 100 |
el(getTypographyControl(), { label: __('Label', 'blockenberg'), value: attr.typoLabel, onChange: function (v) { setAttr({ typoLabel: v }); } }) |
| 101 |
), |
| 102 |
el(PanelColorSettings, { |
| 103 |
title: __('Colors', 'blockenberg'), initialOpen: false, |
| 104 |
colorSettings: [ |
| 105 |
{ value: attr.bgColor, onChange: function (v) { setAttr({ bgColor: v || '#ffffff' }); }, label: __('Background', 'blockenberg') }, |
| 106 |
{ value: attr.numberColor, onChange: function (v) { setAttr({ numberColor: v || '#f0eeff' }); }, label: __('Chapter Number', 'blockenberg') }, |
| 107 |
{ value: attr.labelColor, onChange: function (v) { setAttr({ labelColor: v || '#7c3aed' }); }, label: __('Chapter Label', 'blockenberg') }, |
| 108 |
{ value: attr.headingColor, onChange: function (v) { setAttr({ headingColor: v || '#111827' }); },label: __('Heading', 'blockenberg') }, |
| 109 |
{ value: attr.textColor, onChange: function (v) { setAttr({ textColor: v || '#4b5563' }); }, label: __('Intro Text', 'blockenberg') }, |
| 110 |
{ value: attr.dividerColor, onChange: function (v) { setAttr({ dividerColor: v || '#e5e7eb' }); },label: __('Divider', 'blockenberg') }, |
| 111 |
{ value: attr.accentColor, onChange: function (v) { setAttr({ accentColor: v || '#7c3aed' }); }, label: __('Accent (gradient divider)', 'blockenberg') } |
| 112 |
] |
| 113 |
}) |
| 114 |
), |
| 115 |
el('div', blockProps, |
| 116 |
el('div', { style: wrapStyle }, |
| 117 |
el('div', { style: innerStyle }, |
| 118 |
numberEl, |
| 119 |
attr.showLabel && el('div', { style: { display: 'flex', alignItems: 'center', justifyContent: isLeft ? 'flex-start' : 'center', gap: 8, marginBottom: 12 } }, |
| 120 |
el('span', { style: { display: 'inline-block', width: 24, height: 2, background: attr.labelColor, borderRadius: 1 } }), |
| 121 |
el(RichText, { tagName: 'span', value: attr.chapterLabel, onChange: function (v) { setAttr({ chapterLabel: v }); }, |
| 122 |
style: { color: attr.labelColor }, |
| 123 |
placeholder: 'Chapter' }), |
| 124 |
el('span', { style: { display: 'inline-block', width: 24, height: 2, background: attr.labelColor, borderRadius: 1 } }) |
| 125 |
), |
| 126 |
el(RichText, { tagName: 'h2', value: attr.heading, onChange: function (v) { setAttr({ heading: v }); }, |
| 127 |
className: 'bkbg-ci-heading', |
| 128 |
style: { color: attr.headingColor, margin: '0 0 16px' }, |
| 129 |
placeholder: __('Chapter heading…', 'blockenberg') }), |
| 130 |
renderDivider(), |
| 131 |
el(RichText, { tagName: 'p', value: attr.introText, onChange: function (v) { setAttr({ introText: v }); }, |
| 132 |
className: 'bkbg-ci-text', |
| 133 |
style: { color: attr.textColor, margin: '16px 0 0' }, |
| 134 |
placeholder: __('Write your intro paragraph…', 'blockenberg') }) |
| 135 |
) |
| 136 |
) |
| 137 |
) |
| 138 |
); |
| 139 |
}, |
| 140 |
save: function (props) { |
| 141 |
var attr = props.attributes; |
| 142 |
return el('div', useBlockProps.save(), |
| 143 |
el('div', { className: 'bkbg-chapter-intro-app', 'data-opts': JSON.stringify(attr) }) |
| 144 |
); |
| 145 |
} |
| 146 |
}); |
| 147 |
}() ); |
| 148 |
|