| 1 |
( function () { |
| 2 |
var el = wp.element.createElement; |
| 3 |
var __ = wp.i18n.__; |
| 4 |
var registerBlockType = wp.blocks.registerBlockType; |
| 5 |
var InspectorControls = wp.blockEditor.InspectorControls; |
| 6 |
var useBlockProps = wp.blockEditor.useBlockProps; |
| 7 |
var RichText = wp.blockEditor.RichText; |
| 8 |
var PanelColorSettings = wp.blockEditor.PanelColorSettings; |
| 9 |
var PanelBody = wp.components.PanelBody; |
| 10 |
var ToggleControl = wp.components.ToggleControl; |
| 11 |
var RangeControl = wp.components.RangeControl; |
| 12 |
var TextControl = wp.components.TextControl; |
| 13 |
var TextareaControl = wp.components.TextareaControl; |
| 14 |
var SelectControl = wp.components.SelectControl; |
| 15 |
var Button = wp.components.Button; |
| 16 |
var ColorPicker = wp.components.ColorPicker; |
| 17 |
var Popover = wp.components.Popover; |
| 18 |
var Fragment = wp.element.Fragment; |
| 19 |
var useState = wp.element.useState; |
| 20 |
var _tc; function getTypoControl() { return _tc || (_tc = window.bkbgTypographyControl); } |
| 21 |
var _tv; function getTypoCssVars() { return _tv || (_tv = window.bkbgTypoCssVars); } |
| 22 |
|
| 23 |
/* Asset type icons */ |
| 24 |
var typeIcons = { logo: '🎨', document: '📄', photo: '📷', other: '📦' }; |
| 25 |
|
| 26 |
function BkbgColorSwatch(props) { |
| 27 |
var st = useState(false); var isOpen = st[0]; var setIsOpen = st[1]; |
| 28 |
return el(Fragment, null, |
| 29 |
el('div', { style: { display: 'flex', alignItems: 'center', gap: '8px', marginBottom: '6px' } }, |
| 30 |
el('span', { style: { fontSize: '11px', fontWeight: 500, textTransform: 'uppercase' } }, props.label), |
| 31 |
el('button', { type: 'button', style: { width: 28, height: 28, borderRadius: 4, border: '1px solid #ccc', background: props.value || '#fff', cursor: 'pointer', padding: 0 }, onClick: function () { setIsOpen(!isOpen); } }) |
| 32 |
), |
| 33 |
isOpen && el(Popover, { onClose: function () { setIsOpen(false); } }, el('div', { style: { padding: '8px' } }, el(ColorPicker, { color: props.value, enableAlpha: true, onChange: props.onChange }))) |
| 34 |
); |
| 35 |
} |
| 36 |
|
| 37 |
registerBlockType('blockenberg/press-kit', { |
| 38 |
edit: function (props) { |
| 39 |
var attr = props.attributes; |
| 40 |
var setAttr = props.setAttributes; |
| 41 |
|
| 42 |
function updateAsset(idx, key, val) { |
| 43 |
var assets = (attr.assets || []).map(function (a, i) { |
| 44 |
return i === idx ? Object.assign({}, a, {[key]: val}) : a; |
| 45 |
}); |
| 46 |
setAttr({ assets: assets }); |
| 47 |
} |
| 48 |
|
| 49 |
function updateColor(idx, key, val) { |
| 50 |
var brandColors = (attr.brandColors || []).map(function (c, i) { |
| 51 |
return i === idx ? Object.assign({}, c, {[key]: val}) : c; |
| 52 |
}); |
| 53 |
setAttr({ brandColors: brandColors }); |
| 54 |
} |
| 55 |
|
| 56 |
var inspector = el(InspectorControls, null, |
| 57 |
el(PanelBody, { title: __('Layout', 'blockenberg'), initialOpen: true }, |
| 58 |
el(RangeControl, { __nextHasNoMarginBottom: true, label: __('Max Width (px)', 'blockenberg'), value: attr.maxWidth, min: 600, max: 1400, onChange: function (v) { setAttr({ maxWidth: v }); } }), |
| 59 |
el(RangeControl, { __nextHasNoMarginBottom: true, label: __('Padding Top (px)', 'blockenberg'), value: attr.paddingTop, min: 0, max: 200, onChange: function (v) { setAttr({ paddingTop: v }); } }), |
| 60 |
el(RangeControl, { __nextHasNoMarginBottom: true, label: __('Padding Bottom (px)', 'blockenberg'), value: attr.paddingBottom, min: 0, max: 200, onChange: function (v) { setAttr({ paddingBottom: v }); } }) |
| 61 |
), |
| 62 |
el(PanelBody, { title: __('Company Info', 'blockenberg'), initialOpen: false }, |
| 63 |
el(TextControl, { __nextHasNoMarginBottom: true, label: __('Company Name', 'blockenberg'), value: attr.companyName, onChange: function (v) { setAttr({ companyName: v }); } }), |
| 64 |
el(TextareaControl, { __nextHasNoMarginBottom: true, label: __('Company Blurb', 'blockenberg'), value: attr.companyBlurb, onChange: function (v) { setAttr({ companyBlurb: v }); } }), |
| 65 |
el(ToggleControl, { __nextHasNoMarginBottom: true, label: __('Show Press Contact', 'blockenberg'), checked: attr.showPressContact, onChange: function (v) { setAttr({ showPressContact: v }); } }), |
| 66 |
attr.showPressContact && el(TextControl, { __nextHasNoMarginBottom: true, label: __('Press Email', 'blockenberg'), value: attr.pressEmail, onChange: function (v) { setAttr({ pressEmail: v }); } }) |
| 67 |
), |
| 68 |
el(PanelBody, { title: __('Download All', 'blockenberg'), initialOpen: false }, |
| 69 |
el(ToggleControl, { __nextHasNoMarginBottom: true, label: __('Show Download All Button', 'blockenberg'), checked: attr.showDownloadAll, onChange: function (v) { setAttr({ showDownloadAll: v }); } }), |
| 70 |
attr.showDownloadAll && el(TextControl, { __nextHasNoMarginBottom: true, label: __('Button Label', 'blockenberg'), value: attr.downloadAllLabel, onChange: function (v) { setAttr({ downloadAllLabel: v }); } }), |
| 71 |
attr.showDownloadAll && el(TextControl, { __nextHasNoMarginBottom: true, label: __('Button URL', 'blockenberg'), value: attr.downloadAllUrl, onChange: function (v) { setAttr({ downloadAllUrl: v }); } }) |
| 72 |
), |
| 73 |
el(PanelBody, { title: __('Brand Colors', 'blockenberg'), initialOpen: false }, |
| 74 |
el(ToggleControl, { __nextHasNoMarginBottom: true, label: __('Show Brand Colors Section', 'blockenberg'), checked: attr.showBrandColors, onChange: function (v) { setAttr({ showBrandColors: v }); } }), |
| 75 |
(attr.brandColors || []).map(function (c, idx) { |
| 76 |
return el('div', { key: idx, style: { display: 'flex', gap: '8px', marginBottom: '8px', alignItems: 'center' } }, |
| 77 |
el('div', { style: { width: '28px', height: '28px', borderRadius: '4px', background: c.hex, border: '1px solid #eee', flexShrink: 0 } }), |
| 78 |
el(TextControl, { __nextHasNoMarginBottom: true, label: __('Name', 'blockenberg'), value: c.name, onChange: function (v) { updateColor(idx, 'name', v); } }), |
| 79 |
el(BkbgColorSwatch, { label: __('Hex', 'blockenberg'), value: c.hex, onChange: function (v) { updateColor(idx, 'hex', v); } }), |
| 80 |
el(Button, { isDestructive: true, isSmall: true, onClick: function () { setAttr({ brandColors: (attr.brandColors || []).filter(function (_, i) { return i !== idx; }) }); } }, '✕') |
| 81 |
); |
| 82 |
}), |
| 83 |
el(Button, { variant: 'secondary', onClick: function () { setAttr({ brandColors: (attr.brandColors || []).concat([{ name: 'Color', hex: '#000000' }]) }); } }, __('+ Add Color', 'blockenberg')) |
| 84 |
), |
| 85 |
el(PanelBody, { title: __('Assets', 'blockenberg'), initialOpen: false }, |
| 86 |
(attr.assets || []).map(function (asset, idx) { |
| 87 |
return el(PanelBody, { key: idx, title: (asset.label || 'Asset ' + (idx + 1)), initialOpen: false }, |
| 88 |
el(TextControl, { __nextHasNoMarginBottom: true, label: __('Label', 'blockenberg'), value: asset.label, onChange: function (v) { updateAsset(idx, 'label', v); } }), |
| 89 |
el(TextControl, { __nextHasNoMarginBottom: true, label: __('Description', 'blockenberg'), value: asset.description, onChange: function (v) { updateAsset(idx, 'description', v); } }), |
| 90 |
el(TextControl, { __nextHasNoMarginBottom: true, label: __('File URL', 'blockenberg'), value: asset.fileUrl, onChange: function (v) { updateAsset(idx, 'fileUrl', v); } }), |
| 91 |
el(TextControl, { __nextHasNoMarginBottom: true, label: __('Preview Image URL (optional)', 'blockenberg'), value: asset.previewUrl, onChange: function (v) { updateAsset(idx, 'previewUrl', v); } }), |
| 92 |
el(SelectControl, { __nextHasNoMarginBottom: true, label: __('Type', 'blockenberg'), value: asset.type, options: [{ label: 'Logo', value: 'logo' }, { label: 'Document', value: 'document' }, { label: 'Photo', value: 'photo' }, { label: 'Other', value: 'other' }], onChange: function (v) { updateAsset(idx, 'type', v); } }), |
| 93 |
el(Button, { isDestructive: true, variant: 'secondary', onClick: function () { setAttr({ assets: (attr.assets || []).filter(function (_, i) { return i !== idx; }) }); } }, __('Remove Asset', 'blockenberg')) |
| 94 |
); |
| 95 |
}), |
| 96 |
el(Button, { isPrimary: true, variant: 'primary', onClick: function () { setAttr({ assets: (attr.assets || []).concat([{ label: 'New Asset', description: '', fileUrl: '#', previewUrl: '', type: 'other' }]) }); } }, __('+ Add Asset', 'blockenberg')) |
| 97 |
), |
| 98 |
el(PanelBody, { title: __('Typography', 'blockenberg'), initialOpen: false }, |
| 99 |
(function () { |
| 100 |
var TC = getTypoControl(); |
| 101 |
if (!TC) return el('p', null, 'Loading…'); |
| 102 |
return el(Fragment, null, |
| 103 |
el(TC, { label: __('Heading', 'blockenberg'), value: attr.headingTypo, onChange: function (v) { setAttr({ headingTypo: v }); } }), |
| 104 |
el(TC, { label: __('Eyebrow', 'blockenberg'), value: attr.eyebrowTypo, onChange: function (v) { setAttr({ eyebrowTypo: v }); } }), |
| 105 |
el(TC, { label: __('Subtext', 'blockenberg'), value: attr.subtextTypo, onChange: function (v) { setAttr({ subtextTypo: v }); } }), |
| 106 |
el(TC, { label: __('Body Text', 'blockenberg'), value: attr.bodyTypo, onChange: function (v) { setAttr({ bodyTypo: v }); } }), |
| 107 |
el(TC, { label: __('Asset Label', 'blockenberg'), value: attr.assetLabelTypo, onChange: function (v) { setAttr({ assetLabelTypo: v }); } }), |
| 108 |
el(TC, { label: __('Asset Description', 'blockenberg'), value: attr.assetDescTypo, onChange: function (v) { setAttr({ assetDescTypo: v }); } }) |
| 109 |
); |
| 110 |
})() |
| 111 |
), |
| 112 |
el(PanelColorSettings, { |
| 113 |
title: __('Colors', 'blockenberg'), |
| 114 |
initialOpen: false, |
| 115 |
colorSettings: [ |
| 116 |
{ label: __('Background', 'blockenberg'), value: attr.bgColor, onChange: function (v) { setAttr({ bgColor: v || '#ffffff' }); } }, |
| 117 |
{ label: __('Heading', 'blockenberg'), value: attr.headingColor, onChange: function (v) { setAttr({ headingColor: v || '#111827' }); } }, |
| 118 |
{ label: __('Subtext', 'blockenberg'), value: attr.subColor, onChange: function (v) { setAttr({ subColor: v || '#6b7280' }); } }, |
| 119 |
{ label: __('Eyebrow', 'blockenberg'), value: attr.eyebrowColor, onChange: function (v) { setAttr({ eyebrowColor: v || '#6366f1' }); } }, |
| 120 |
{ label: __('Card BG', 'blockenberg'), value: attr.cardBg, onChange: function (v) { setAttr({ cardBg: v || '#f8fafc' }); } }, |
| 121 |
{ label: __('Card Border', 'blockenberg'), value: attr.cardBorder, onChange: function (v) { setAttr({ cardBorder: v || '#e2e8f0' }); } }, |
| 122 |
{ label: __('Download Button BG', 'blockenberg'), value: attr.downloadBg, onChange: function (v) { setAttr({ downloadBg: v || '#6366f1' }); } }, |
| 123 |
{ label: __('Download Button Text', 'blockenberg'), value: attr.downloadColor, onChange: function (v) { setAttr({ downloadColor: v || '#ffffff' }); } }, |
| 124 |
{ label: __('Company Blurb Text', 'blockenberg'), value: attr.blurbColor, onChange: function (v) { setAttr({ blurbColor: v || '#374151' }); } } |
| 125 |
] |
| 126 |
}) |
| 127 |
); |
| 128 |
|
| 129 |
var blockProps = useBlockProps((function () { |
| 130 |
var _tvFn = getTypoCssVars(); |
| 131 |
var s = {}; |
| 132 |
if (_tvFn) { |
| 133 |
Object.assign(s, _tvFn(attr.headingTypo, '--bkbg-prk-h-')); |
| 134 |
Object.assign(s, _tvFn(attr.subtextTypo, '--bkbg-prk-st-')); |
| 135 |
Object.assign(s, _tvFn(attr.eyebrowTypo, '--bkbg-prk-ey-')); |
| 136 |
Object.assign(s, _tvFn(attr.bodyTypo, '--bkbg-prk-bd-')); |
| 137 |
Object.assign(s, _tvFn(attr.assetLabelTypo, '--bkbg-prk-al-')); |
| 138 |
Object.assign(s, _tvFn(attr.assetDescTypo, '--bkbg-prk-ad-')); |
| 139 |
} |
| 140 |
return { className: 'bkbg-prk-editor', style: s }; |
| 141 |
})()); |
| 142 |
|
| 143 |
return el('div', blockProps, |
| 144 |
inspector, |
| 145 |
el('div', { style: { background: attr.bgColor, padding: '40px', borderRadius: '8px', fontFamily: 'sans-serif' } }, |
| 146 |
/* Header */ |
| 147 |
el('div', { className: 'bkbg-prk-header', style: { textAlign: 'center', marginBottom: '48px' } }, |
| 148 |
el(RichText, { tagName: 'p', className: 'bkbg-prk-eyebrow', value: attr.eyebrow, onChange: function (v) { setAttr({ eyebrow: v }); }, placeholder: __('Eyebrow…', 'blockenberg'), style: { color: attr.eyebrowColor, margin: '0 0 8px' } }), |
| 149 |
el(RichText, { tagName: 'h2', className: 'bkbg-prk-heading', value: attr.heading, onChange: function (v) { setAttr({ heading: v }); }, placeholder: __('Heading…', 'blockenberg'), style: { color: attr.headingColor, margin: '0 0 12px' } }), |
| 150 |
el(RichText, { tagName: 'p', className: 'bkbg-prk-sub', value: attr.subtext, onChange: function (v) { setAttr({ subtext: v }); }, placeholder: __('Subtext…', 'blockenberg'), style: { color: attr.subColor, maxWidth: '600px', margin: '0 auto' } }) |
| 151 |
), |
| 152 |
/* Company blurb */ |
| 153 |
el('div', { style: { background: attr.cardBg, border: '1px solid ' + attr.cardBorder, borderRadius: '12px', padding: '24px', marginBottom: '32px' } }, |
| 154 |
el('div', { style: { fontWeight: 700, color: attr.headingColor, fontSize: '16px', marginBottom: '8px' } }, 'About ' + attr.companyName), |
| 155 |
el(RichText, { tagName: 'p', className: 'bkbg-prk-blurb-text', value: attr.companyBlurb, onChange: function (v) { setAttr({ companyBlurb: v }); }, placeholder: __('Company blurb…', 'blockenberg'), style: { color: attr.blurbColor, margin: 0 } }) |
| 156 |
), |
| 157 |
/* Assets grid */ |
| 158 |
el('div', { style: { display: 'grid', gridTemplateColumns: 'repeat(2,1fr)', gap: '16px', marginBottom: '32px' } }, |
| 159 |
(attr.assets || []).map(function (asset, i) { |
| 160 |
return el('div', { key: i, style: { background: attr.cardBg, border: '1px solid ' + attr.cardBorder, borderRadius: '10px', padding: '20px', display: 'flex', gap: '16px', alignItems: 'center' } }, |
| 161 |
el('div', { style: { fontSize: '36px', flexShrink: 0 } }, typeIcons[asset.type] || '📦'), |
| 162 |
el('div', { style: { flex: 1 } }, |
| 163 |
el('div', { className: 'bkbg-prk-asset-label', style: { color: attr.assetLabelColor } }, asset.label), |
| 164 |
el('div', { className: 'bkbg-prk-asset-desc', style: { color: attr.assetDescColor, marginTop: '2px' } }, asset.description) |
| 165 |
), |
| 166 |
el('a', { href: asset.fileUrl, style: { background: attr.downloadBg, color: attr.downloadColor, borderRadius: '6px', padding: '6px 14px', fontSize: '13px', fontWeight: 600, textDecoration: 'none', whiteSpace: 'nowrap' } }, '⬇ Download') |
| 167 |
); |
| 168 |
}) |
| 169 |
), |
| 170 |
/* Brand colors */ |
| 171 |
attr.showBrandColors && (attr.brandColors || []).length > 0 && el('div', { style: { marginBottom: '32px' } }, |
| 172 |
el('div', { style: { fontWeight: 700, color: attr.headingColor, fontSize: '16px', marginBottom: '12px' } }, 'Brand Colors'), |
| 173 |
el('div', { style: { display: 'flex', gap: '12px', flexWrap: 'wrap' } }, |
| 174 |
(attr.brandColors || []).map(function (c, i) { |
| 175 |
return el('div', { key: i, style: { textAlign: 'center' } }, |
| 176 |
el('div', { style: { width: '64px', height: '64px', borderRadius: '10px', background: c.hex, border: '1px solid rgba(0,0,0,0.1)', marginBottom: '4px' } }), |
| 177 |
el('div', { style: { fontSize: '12px', color: attr.headingColor, fontWeight: 600 } }, c.name), |
| 178 |
el('div', { style: { fontSize: '11px', color: attr.subColor, fontFamily: 'monospace' } }, c.hex) |
| 179 |
); |
| 180 |
}) |
| 181 |
) |
| 182 |
), |
| 183 |
/* Download all + contact */ |
| 184 |
el('div', { style: { textAlign: 'center', display: 'flex', gap: '16px', justifyContent: 'center', flexWrap: 'wrap' } }, |
| 185 |
attr.showDownloadAll && el('a', { href: attr.downloadAllUrl, style: { background: attr.downloadBg, color: attr.downloadColor, borderRadius: '8px', padding: '12px 28px', fontWeight: 700, textDecoration: 'none', fontSize: '15px' } }, '📦 ' + attr.downloadAllLabel), |
| 186 |
attr.showPressContact && el('a', { href: 'mailto:' + attr.pressEmail, style: { color: attr.accentColor, borderRadius: '8px', padding: '12px 28px', fontWeight: 600, textDecoration: 'none', fontSize: '15px', border: '2px solid ' + attr.accentColor } }, '✉️ ' + attr.pressEmail) |
| 187 |
) |
| 188 |
) |
| 189 |
); |
| 190 |
}, |
| 191 |
|
| 192 |
save: function (props) { |
| 193 |
var attr = props.attributes; |
| 194 |
var useBlockProps = wp.blockEditor.useBlockProps; |
| 195 |
return el('div', useBlockProps.save(), |
| 196 |
el('div', { className: 'bkbg-prk-app', 'data-opts': JSON.stringify(attr) }) |
| 197 |
); |
| 198 |
} |
| 199 |
}); |
| 200 |
}() ); |
| 201 |
|