| 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 |
var TextControl = wp.components.TextControl; |
| 15 |
var Button = wp.components.Button; |
| 16 |
var ColorPicker = wp.components.ColorPicker; |
| 17 |
var Popover = wp.components.Popover; |
| 18 |
var useState = wp.element.useState; |
| 19 |
|
| 20 |
var _TypographyControl, _typoCssVars; |
| 21 |
function getTypographyControl() { return _TypographyControl || (_TypographyControl = window.bkbgTypographyControl); } |
| 22 |
function getTypoCssVars() { return _typoCssVars || (_typoCssVars = window.bkbgTypoCssVars); } |
| 23 |
|
| 24 |
var IP = function () { return window.bkbgIconPicker; }; |
| 25 |
|
| 26 |
var BkbgColorSwatch = function (props) { |
| 27 |
var _st = useState(false); var isOpen = _st[0]; var setOpen = _st[1]; |
| 28 |
return el(Fragment, {}, |
| 29 |
el('div', { style: { display: 'flex', alignItems: 'center', gap: '8px', marginBottom: '8px' } }, |
| 30 |
el('span', { style: { fontSize: '11px', fontWeight: 500, textTransform: 'uppercase', color: '#1e1e1e' } }, props.label), |
| 31 |
el('button', { |
| 32 |
type: 'button', |
| 33 |
onClick: function () { setOpen(!isOpen); }, |
| 34 |
style: { width: '28px', height: '28px', borderRadius: '4px', border: '1px solid #ccc', background: props.value || '#ffffff', cursor: 'pointer', padding: 0 } |
| 35 |
}) |
| 36 |
), |
| 37 |
isOpen && el(Popover, { onClose: function () { setOpen(false); } }, |
| 38 |
el('div', { style: { padding: '8px' } }, |
| 39 |
el(ColorPicker, { color: props.value, onChangeComplete: function (c) { props.onChange(c.hex); }, enableAlpha: true }) |
| 40 |
) |
| 41 |
) |
| 42 |
); |
| 43 |
}; |
| 44 |
|
| 45 |
registerBlockType('blockenberg/icon-list', { |
| 46 |
edit: function (props) { |
| 47 |
var attr = props.attributes; |
| 48 |
var setAttr = props.setAttributes; |
| 49 |
var blockProps = useBlockProps({ className: 'bkbg-il-editor' }); |
| 50 |
|
| 51 |
function updateItem(i, key, val) { |
| 52 |
var next = attr.items.map(function (item, j) { |
| 53 |
return j === i ? Object.assign({}, item, { [key]: val }) : item; |
| 54 |
}); |
| 55 |
setAttr({ items: next }); |
| 56 |
} |
| 57 |
|
| 58 |
function removeItem(i) { |
| 59 |
setAttr({ items: attr.items.filter(function (_, j) { return j !== i; }) }); |
| 60 |
} |
| 61 |
|
| 62 |
var isGrid = attr.layout === 'grid'; |
| 63 |
var listStyle = isGrid |
| 64 |
? { display: 'grid', gridTemplateColumns: 'repeat(' + attr.columns + ', 1fr)', gap: attr.gap + 'px' } |
| 65 |
: { display: 'flex', flexDirection: 'column', gap: attr.gap + 'px' }; |
| 66 |
|
| 67 |
function itemEl(item, i) { |
| 68 |
var isBoxed = attr.itemStyle === 'boxed'; |
| 69 |
var isBordered = attr.itemStyle === 'bordered'; |
| 70 |
var itemStyle = { |
| 71 |
display: 'flex', |
| 72 |
alignItems: 'flex-start', |
| 73 |
gap: 14, |
| 74 |
padding: isBoxed || isBordered ? '16px 20px' : '8px 0', |
| 75 |
background: isBoxed ? attr.itemBg : 'transparent', |
| 76 |
borderRadius: isBoxed ? attr.borderRadius + 'px' : 0, |
| 77 |
border: isBordered ? ('1px solid ' + attr.borderColor) : (isBoxed ? '1px solid ' + attr.borderColor : (attr.showDivider && i < attr.items.length - 1 ? ('0 0 1px 0 solid ' + attr.dividerColor) : 'none')), |
| 78 |
borderBottom: attr.showDivider && !isGrid && !isBoxed && !isBordered && i < attr.items.length - 1 ? ('1px solid ' + attr.dividerColor) : undefined |
| 79 |
}; |
| 80 |
var iconStyle = { |
| 81 |
fontSize: attr.iconSize + 'px', |
| 82 |
lineHeight: 1, |
| 83 |
flexShrink: 0, |
| 84 |
color: item.iconColor || attr.iconColor, |
| 85 |
marginTop: 2 |
| 86 |
}; |
| 87 |
return el('div', { key: i, style: itemStyle }, |
| 88 |
el('span', { style: iconStyle }, |
| 89 |
(item.iconType || 'custom-char') !== 'custom-char' ? IP().buildEditorIcon(item.iconType, item.icon, item.iconDashicon, item.iconImageUrl, item.iconDashiconColor) : item.icon |
| 90 |
), |
| 91 |
el('div', { style: { flex: 1, minWidth: 0 } }, |
| 92 |
el('div', { style: { display: 'flex', alignItems: 'center', gap: 8, flexWrap: 'wrap', marginBottom: 4 } }, |
| 93 |
el(RichText, { tagName: 'strong', className: 'bkbg-il-title', value: item.title, onChange: function (v) { updateItem(i, 'title', v); }, |
| 94 |
style: { color: attr.titleColor }, |
| 95 |
placeholder: __('Feature title…', 'blockenberg') }), |
| 96 |
attr.showBadge && item.badge && el('span', { style: { background: attr.badgeBg, color: attr.badgeColor, borderRadius: 4, padding: '2px 8px', fontSize: 11, fontWeight: 600 } }, item.badge) |
| 97 |
), |
| 98 |
attr.showDesc && el(RichText, { tagName: 'p', className: 'bkbg-il-desc', value: item.description, onChange: function (v) { updateItem(i, 'description', v); }, |
| 99 |
style: { color: attr.descColor, margin: 0 }, |
| 100 |
placeholder: __('Description…', 'blockenberg') }) |
| 101 |
) |
| 102 |
); |
| 103 |
} |
| 104 |
|
| 105 |
var wrapStyle = { |
| 106 |
background: attr.bgColor, |
| 107 |
paddingTop: attr.paddingTop + 'px', |
| 108 |
paddingBottom: attr.paddingBottom + 'px', |
| 109 |
'--bkbg-il-heading-sz': (attr.headingSize || 32) + 'px', |
| 110 |
'--bkbg-il-title-sz': (attr.titleSize || 17) + 'px', |
| 111 |
'--bkbg-il-desc-sz': (attr.descSize || 14) + 'px' |
| 112 |
}; |
| 113 |
var _tv = getTypoCssVars(); |
| 114 |
if (_tv) { |
| 115 |
Object.assign(wrapStyle, _tv(attr.headingTypo, '--bkbg-il-hd-')); |
| 116 |
Object.assign(wrapStyle, _tv(attr.titleTypo, '--bkbg-il-tt-')); |
| 117 |
Object.assign(wrapStyle, _tv(attr.descTypo, '--bkbg-il-ds-')); |
| 118 |
} |
| 119 |
var innerStyle = { maxWidth: attr.maxWidth + 'px', margin: '0 auto', padding: '0 20px' }; |
| 120 |
|
| 121 |
return el(Fragment, null, |
| 122 |
el(InspectorControls, null, |
| 123 |
el(PanelBody, { title: __('Layout', 'blockenberg'), initialOpen: true }, |
| 124 |
el(SelectControl, { label: __('Layout', 'blockenberg'), __nextHasNoMarginBottom: true, value: attr.layout, |
| 125 |
options: [{ label: __('List (vertical)', 'blockenberg'), value: 'list' }, { label: __('Grid', 'blockenberg'), value: 'grid' }], |
| 126 |
onChange: function (v) { setAttr({ layout: v }); } }), |
| 127 |
isGrid && el(RangeControl, { label: __('Columns', 'blockenberg'), __nextHasNoMarginBottom: true, value: attr.columns, min: 1, max: 4, onChange: function (v) { setAttr({ columns: v }); } }), |
| 128 |
el(SelectControl, { label: __('Item Style', 'blockenberg'), __nextHasNoMarginBottom: true, value: attr.itemStyle, |
| 129 |
options: [{ label: __('Boxed (card)', 'blockenberg'), value: 'boxed' }, { label: __('Bordered', 'blockenberg'), value: 'bordered' }, { label: __('Plain', 'blockenberg'), value: 'plain' }], |
| 130 |
onChange: function (v) { setAttr({ itemStyle: v }); } }), |
| 131 |
el(ToggleControl, { label: __('Show Heading', 'blockenberg'), __nextHasNoMarginBottom: true, checked: attr.showHeading, onChange: function (v) { setAttr({ showHeading: v }); } }), |
| 132 |
el(ToggleControl, { label: __('Show Subtext', 'blockenberg'), __nextHasNoMarginBottom: true, checked: attr.showSubtext, onChange: function (v) { setAttr({ showSubtext: v }); } }), |
| 133 |
el(ToggleControl, { label: __('Show Badges', 'blockenberg'), __nextHasNoMarginBottom: true, checked: attr.showBadge, onChange: function (v) { setAttr({ showBadge: v }); } }), |
| 134 |
el(ToggleControl, { label: __('Show Descriptions', 'blockenberg'), __nextHasNoMarginBottom: true, checked: attr.showDesc, onChange: function (v) { setAttr({ showDesc: v }); } }), |
| 135 |
!isGrid && attr.itemStyle === 'plain' && el(ToggleControl, { label: __('Dividers Between Items', 'blockenberg'), __nextHasNoMarginBottom: true, checked: attr.showDivider, onChange: function (v) { setAttr({ showDivider: v }); } }) |
| 136 |
), |
| 137 |
el(PanelBody, { title: __('Items', 'blockenberg'), initialOpen: false }, |
| 138 |
attr.items.map(function (item, i) { |
| 139 |
return el('div', { key: i, style: { borderLeft: '3px solid ' + attr.iconColor, paddingLeft: 8, marginBottom: 12 } }, |
| 140 |
el(IP().IconPickerControl, { iconType: item.iconType || 'custom-char', customChar: item.icon, dashicon: item.iconDashicon || '', imageUrl: item.iconImageUrl || '', |
| 141 |
onChangeType: function (v) { updateItem(i, 'iconType', v); }, onChangeChar: function (v) { updateItem(i, 'icon', v); }, |
| 142 |
onChangeDashicon: function (v) { updateItem(i, 'iconDashicon', v); }, onChangeImageUrl: function (v) { updateItem(i, 'iconImageUrl', v); } }), |
| 143 |
el(TextControl, { label: __('Title'), __nextHasNoMarginBottom: true, value: item.title, onChange: function (v) { updateItem(i, 'title', v); } }), |
| 144 |
el(TextControl, { label: __('Description'), __nextHasNoMarginBottom: true, value: item.description, onChange: function (v) { updateItem(i, 'description', v); } }), |
| 145 |
el(TextControl, { label: __('Badge/Tag'), __nextHasNoMarginBottom: true, value: item.badge, onChange: function (v) { updateItem(i, 'badge', v); } }), |
| 146 |
el(BkbgColorSwatch, { label: __('Custom Icon Color (hex)'), value: item.iconColor, onChange: function (v) { updateItem(i, 'iconColor', v); } }), |
| 147 |
attr.items.length > 1 && el(Button, { onClick: function () { removeItem(i); }, variant: 'link', isDestructive: true, __nextHasNoMarginBottom: true }, __('Remove', 'blockenberg')) |
| 148 |
); |
| 149 |
}), |
| 150 |
el(Button, { onClick: function () { setAttr({ items: attr.items.concat([{ icon: '✨', iconType: 'custom-char', iconDashicon: '', iconImageUrl: '', title: 'New Feature', description: 'Describe this feature here.', badge: 'New', iconColor: '' }]) }); }, variant: 'secondary', __nextHasNoMarginBottom: true }, __('+ Add Item', 'blockenberg')) |
| 151 |
), |
| 152 |
el(PanelBody, { title: __('Sizing', 'blockenberg'), initialOpen: false }, |
| 153 |
el(RangeControl, { label: __('Icon Size (px)', 'blockenberg'), __nextHasNoMarginBottom: true, value: attr.iconSize, min: 14, max: 56, onChange: function (v) { setAttr({ iconSize: v }); } }), |
| 154 |
el(RangeControl, { label: __('Item Gap (px)', 'blockenberg'), __nextHasNoMarginBottom: true, value: attr.gap, min: 0, max: 48, onChange: function (v) { setAttr({ gap: v }); } }), |
| 155 |
el(RangeControl, { label: __('Card Radius (px)', 'blockenberg'), __nextHasNoMarginBottom: true, value: attr.borderRadius, min: 0, max: 24, onChange: function (v) { setAttr({ borderRadius: v }); } }), |
| 156 |
el(RangeControl, { label: __('Max Width (px)', 'blockenberg'), __nextHasNoMarginBottom: true, value: attr.maxWidth, min: 400, max: 1400, step: 10, onChange: function (v) { setAttr({ maxWidth: v }); } }), |
| 157 |
el(RangeControl, { label: __('Padding Top (px)', 'blockenberg'), __nextHasNoMarginBottom: true, value: attr.paddingTop, min: 0, max: 200, onChange: function (v) { setAttr({ paddingTop: v }); } }), |
| 158 |
el(RangeControl, { label: __('Padding Bottom (px)', 'blockenberg'), __nextHasNoMarginBottom: true, value: attr.paddingBottom, min: 0, max: 200, onChange: function (v) { setAttr({ paddingBottom: v }); } }) |
| 159 |
), |
| 160 |
|
| 161 |
el( PanelBody, { title: __( 'Typography', 'blockenberg' ), initialOpen: false }, |
| 162 |
getTypographyControl() && el(getTypographyControl(), { label: __('Heading', 'blockenberg'), typo: attr.headingTypo || {}, onChange: function (v) { setAttr({ headingTypo: v }); } }), |
| 163 |
getTypographyControl() && el(getTypographyControl(), { label: __('Title', 'blockenberg'), typo: attr.titleTypo || {}, onChange: function (v) { setAttr({ titleTypo: v }); } }), |
| 164 |
getTypographyControl() && el(getTypographyControl(), { label: __('Description', 'blockenberg'), typo: attr.descTypo || {}, onChange: function (v) { setAttr({ descTypo: v }); } }) |
| 165 |
), |
| 166 |
el(PanelColorSettings, { |
| 167 |
title: __('Colors', 'blockenberg'), initialOpen: false, |
| 168 |
colorSettings: [ |
| 169 |
{ value: attr.bgColor, onChange: function (v) { setAttr({ bgColor: v || '#ffffff' }); }, label: __('Background', 'blockenberg') }, |
| 170 |
{ value: attr.itemBg, onChange: function (v) { setAttr({ itemBg: v || '#f9fafb' }); }, label: __('Item Background', 'blockenberg') }, |
| 171 |
{ value: attr.borderColor, onChange: function (v) { setAttr({ borderColor: v || '#e5e7eb' }); }, label: __('Border', 'blockenberg') }, |
| 172 |
{ value: attr.headingColor, onChange: function (v) { setAttr({ headingColor: v || '#111827' }); }, label: __('Section Heading', 'blockenberg') }, |
| 173 |
{ value: attr.subtextColor, onChange: function (v) { setAttr({ subtextColor: v || '#6b7280' }); }, label: __('Section Subtext', 'blockenberg') }, |
| 174 |
{ value: attr.titleColor, onChange: function (v) { setAttr({ titleColor: v || '#111827' }); }, label: __('Item Title', 'blockenberg') }, |
| 175 |
{ value: attr.descColor, onChange: function (v) { setAttr({ descColor: v || '#6b7280' }); }, label: __('Item Description', 'blockenberg') }, |
| 176 |
{ value: attr.iconColor, onChange: function (v) { setAttr({ iconColor: v || '#7c3aed' }); }, label: __('Icon (default)', 'blockenberg') }, |
| 177 |
{ value: attr.badgeBg, onChange: function (v) { setAttr({ badgeBg: v || '#ede9fe' }); }, label: __('Badge Background', 'blockenberg') }, |
| 178 |
{ value: attr.badgeColor, onChange: function (v) { setAttr({ badgeColor: v || '#7c3aed' }); }, label: __('Badge Text', 'blockenberg') }, |
| 179 |
{ value: attr.dividerColor, onChange: function (v) { setAttr({ dividerColor: v || '#e5e7eb' }); }, label: __('Divider', 'blockenberg') } |
| 180 |
] |
| 181 |
}) |
| 182 |
), |
| 183 |
el('div', blockProps, |
| 184 |
el('div', { className: 'bkbg-il-wrap', style: wrapStyle }, |
| 185 |
el('div', { style: innerStyle }, |
| 186 |
attr.showHeading && el(RichText, { tagName: 'h2', className: 'bkbg-il-heading', value: attr.heading, onChange: function (v) { setAttr({ heading: v }); }, |
| 187 |
style: { color: attr.headingColor, margin: '0 0 8px' }, |
| 188 |
placeholder: __('Section heading…', 'blockenberg') }), |
| 189 |
attr.showSubtext && el(RichText, { tagName: 'p', value: attr.subtext, onChange: function (v) { setAttr({ subtext: v }); }, |
| 190 |
style: { fontSize: 16 + 'px', color: attr.subtextColor, margin: '0 0 32px', lineHeight: 1.6 }, |
| 191 |
placeholder: __('Subtitle…', 'blockenberg') }), |
| 192 |
el('div', { style: listStyle }, |
| 193 |
attr.items.map(function (item, i) { return itemEl(item, i); }) |
| 194 |
) |
| 195 |
) |
| 196 |
) |
| 197 |
) |
| 198 |
); |
| 199 |
}, |
| 200 |
save: function (props) { |
| 201 |
var attr = props.attributes; |
| 202 |
return el('div', useBlockProps.save(), |
| 203 |
el('div', { className: 'bkbg-icon-list-app', 'data-opts': JSON.stringify(attr) }) |
| 204 |
); |
| 205 |
} |
| 206 |
}); |
| 207 |
}() ); |
| 208 |
|