| 1 |
( function () { |
| 2 |
var el = wp.element.createElement; |
| 3 |
var Fragment = wp.element.Fragment; |
| 4 |
var PanelColorSettings = wp.blockEditor.PanelColorSettings; |
| 5 |
var useBlockProps = wp.blockEditor.useBlockProps; |
| 6 |
var InspectorControls = wp.blockEditor.InspectorControls; |
| 7 |
var TextControl = wp.components.TextControl; |
| 8 |
var TextareaControl = wp.components.TextareaControl; |
| 9 |
var ToggleControl = wp.components.ToggleControl; |
| 10 |
var RangeControl = wp.components.RangeControl; |
| 11 |
var SelectControl = wp.components.SelectControl; |
| 12 |
var PanelBody = wp.components.PanelBody; |
| 13 |
var Button = wp.components.Button; |
| 14 |
var __ = wp.i18n.__; |
| 15 |
|
| 16 |
var _tc; function getTypoControl() { return _tc || (_tc = window.bkbgTypographyControl); } |
| 17 |
var _tv; function getTypoCssVars() { return _tv || (_tv = window.bkbgTypoCssVars); } |
| 18 |
|
| 19 |
var ringOptions = [ |
| 20 |
{ label: 'Adopt', value: 'adopt' }, |
| 21 |
{ label: 'Trial', value: 'trial' }, |
| 22 |
{ label: 'Assess', value: 'assess' }, |
| 23 |
{ label: 'Hold', value: 'hold' } |
| 24 |
]; |
| 25 |
var quadrantOptions = [ |
| 26 |
{ label: 'Languages & Frameworks', value: 'Languages & Frameworks' }, |
| 27 |
{ label: 'Platforms', value: 'Platforms' }, |
| 28 |
{ label: 'Tools', value: 'Tools' }, |
| 29 |
{ label: 'Techniques', value: 'Techniques' } |
| 30 |
]; |
| 31 |
var ringOrder = ['adopt', 'trial', 'assess', 'hold']; |
| 32 |
|
| 33 |
function upd(arr, idx, field, val) { |
| 34 |
return arr.map(function (e, i) { |
| 35 |
if (i !== idx) return e; |
| 36 |
var u = {}; u[field] = val; |
| 37 |
return Object.assign({}, e, u); |
| 38 |
}); |
| 39 |
} |
| 40 |
|
| 41 |
function ringInfo(r, a) { |
| 42 |
var map = { |
| 43 |
adopt: { label: 'Adopt', bg: a.adoptBg, color: a.adoptColor, border: a.adoptBorder }, |
| 44 |
trial: { label: 'Trial', bg: a.trialBg, color: a.trialColor, border: a.trialBorder }, |
| 45 |
assess: { label: 'Assess', bg: a.assessBg, color: a.assessColor, border: a.assessBorder }, |
| 46 |
hold: { label: 'Hold', bg: a.holdBg, color: a.holdColor, border: a.holdBorder } |
| 47 |
}; |
| 48 |
return map[r] || map.adopt; |
| 49 |
} |
| 50 |
|
| 51 |
function renderRingSection(ring, blips, a) { |
| 52 |
var ri = ringInfo(ring, a); |
| 53 |
return el('div', { className: 'bkbg-tr-ring-section', key: ring, style: { borderLeft: '4px solid ' + ri.border, background: a.bgColor } }, |
| 54 |
el('div', { className: 'bkbg-tr-ring-head', style: { background: ri.bg } }, |
| 55 |
el('span', { className: 'bkbg-tr-ring-label', style: { color: ri.color, fontSize: a.ringLabelSize + 'px' } }, ri.label.toUpperCase()), |
| 56 |
el('span', { className: 'bkbg-tr-ring-count', style: { color: ri.color } }, blips.length + ' ' + (blips.length === 1 ? 'entry' : 'entries')) |
| 57 |
), |
| 58 |
el('div', { className: 'bkbg-tr-blip-list' }, |
| 59 |
blips.map(function (blip, i) { |
| 60 |
return el('div', { className: 'bkbg-tr-blip', key: i, style: { borderTopColor: a.borderColor } }, |
| 61 |
el('div', { className: 'bkbg-tr-blip-top' }, |
| 62 |
el('span', { className: 'bkbg-tr-blip-name', style: { color: a.blipNameColor, fontSize: a.blipNameSize + 'px' } }, blip.name), |
| 63 |
a.showIsNew && blip.isNew && el('span', { className: 'bkbg-tr-new-badge', style: { background: a.newBadgeBg, color: a.newBadgeColor } }, 'NEW') |
| 64 |
), |
| 65 |
blip.description && el('div', { className: 'bkbg-tr-blip-desc', style: { color: a.blipDescColor } }, blip.description) |
| 66 |
); |
| 67 |
}) |
| 68 |
) |
| 69 |
); |
| 70 |
} |
| 71 |
|
| 72 |
function getGrouped(blips) { |
| 73 |
var groups = {}; |
| 74 |
ringOrder.forEach(function (r) { groups[r] = []; }); |
| 75 |
blips.forEach(function (b) { if (groups[b.ring]) groups[b.ring].push(b); }); |
| 76 |
return groups; |
| 77 |
} |
| 78 |
|
| 79 |
function getByQuadrant(blips) { |
| 80 |
var quads = {}; |
| 81 |
quadrantOptions.forEach(function (q) { quads[q.value] = []; }); |
| 82 |
blips.forEach(function (b) { if (quads[b.quadrant] !== undefined) quads[b.quadrant].push(b); }); |
| 83 |
return quads; |
| 84 |
} |
| 85 |
|
| 86 |
wp.blocks.registerBlockType('blockenberg/tech-radar', { |
| 87 |
edit: function (props) { |
| 88 |
var a = props.attributes; |
| 89 |
var setAttr = props.setAttributes; |
| 90 |
var lh = (a.lineHeight / 100).toFixed(2); |
| 91 |
|
| 92 |
var grouped = getGrouped(a.blips); |
| 93 |
|
| 94 |
var preview; |
| 95 |
if (a.groupByQuadrant) { |
| 96 |
var byQuad = getByQuadrant(a.blips); |
| 97 |
preview = el('div', { className: 'bkbg-tr-quadrants' }, |
| 98 |
quadrantOptions.map(function (q) { |
| 99 |
var qBlips = byQuad[q.value]; |
| 100 |
if (!qBlips || !qBlips.length) return null; |
| 101 |
var qGrouped = getGrouped(qBlips); |
| 102 |
return el('div', { className: 'bkbg-tr-quadrant', key: q.value, style: { border: '1px solid ' + a.borderColor, borderRadius: 8 } }, |
| 103 |
el('div', { className: 'bkbg-tr-quadrant-head', style: { color: a.quadrantHeadColor, borderBottomColor: a.borderColor } }, q.value), |
| 104 |
ringOrder.map(function (ring) { |
| 105 |
var rb = qGrouped[ring]; |
| 106 |
if (!rb || !rb.length) return null; |
| 107 |
return renderRingSection(ring, rb, a); |
| 108 |
}) |
| 109 |
); |
| 110 |
}) |
| 111 |
); |
| 112 |
} else { |
| 113 |
preview = el('div', { className: 'bkbg-tr-rings' }, |
| 114 |
ringOrder.map(function (ring) { |
| 115 |
var rb = grouped[ring]; |
| 116 |
if (!rb || !rb.length) return null; |
| 117 |
return renderRingSection(ring, rb, a); |
| 118 |
}) |
| 119 |
); |
| 120 |
} |
| 121 |
|
| 122 |
return el(Fragment, null, |
| 123 |
el(InspectorControls, null, |
| 124 |
el(PanelBody, { title: __('Radar Settings'), initialOpen: true }, |
| 125 |
el(TextControl, { label: __('Radar Title'), value: a.radarTitle, onChange: function (v) { setAttr({ radarTitle: v }); }, __nextHasNoMarginBottom: true }), |
| 126 |
el(TextareaControl, { label: __('Description'), value: a.description, onChange: function (v) { setAttr({ description: v }); }, __nextHasNoMarginBottom: true }), |
| 127 |
el(ToggleControl, { label: __('Show Description'), checked: a.showDescription, onChange: function (v) { setAttr({ showDescription: v }); }, __nextHasNoMarginBottom: true }), |
| 128 |
el(ToggleControl, { label: __('Group by Quadrant'), checked: a.groupByQuadrant, onChange: function (v) { setAttr({ groupByQuadrant: v }); }, __nextHasNoMarginBottom: true }), |
| 129 |
el(ToggleControl, { label: __('Show NEW badge'), checked: a.showIsNew, onChange: function (v) { setAttr({ showIsNew: v }); }, __nextHasNoMarginBottom: true }) |
| 130 |
), |
| 131 |
el(PanelBody, { title: __('Blips'), initialOpen: false }, |
| 132 |
a.blips.map(function (blip, i) { |
| 133 |
return el('div', { key: i, style: { border: '1px solid #e2e8f0', borderRadius: 8, padding: 12, marginBottom: 12, background: '#fafafa' } }, |
| 134 |
el('strong', { style: { display: 'block', marginBottom: 6 } }, blip.name || ('Blip ' + (i + 1))), |
| 135 |
el(TextControl, { label: __('Name'), value: blip.name, onChange: function (v) { setAttr({ blips: upd(a.blips, i, 'name', v) }); }, __nextHasNoMarginBottom: true }), |
| 136 |
el(SelectControl, { label: __('Ring'), value: blip.ring, options: ringOptions, onChange: function (v) { setAttr({ blips: upd(a.blips, i, 'ring', v) }); }, __nextHasNoMarginBottom: true }), |
| 137 |
el(SelectControl, { label: __('Quadrant'), value: blip.quadrant, options: quadrantOptions, onChange: function (v) { setAttr({ blips: upd(a.blips, i, 'quadrant', v) }); }, __nextHasNoMarginBottom: true }), |
| 138 |
el(TextareaControl, { label: __('Description'), value: blip.description, onChange: function (v) { setAttr({ blips: upd(a.blips, i, 'description', v) }); }, __nextHasNoMarginBottom: true }), |
| 139 |
el(ToggleControl, { label: __('Mark as NEW'), checked: blip.isNew, onChange: function (v) { setAttr({ blips: upd(a.blips, i, 'isNew', v) }); }, __nextHasNoMarginBottom: true }), |
| 140 |
el(Button, { isDestructive: true, variant: 'secondary', onClick: function () { setAttr({ blips: a.blips.filter(function (_, j) { return j !== i; }) }); } }, __('Remove')) |
| 141 |
); |
| 142 |
}), |
| 143 |
el(Button, { variant: 'primary', onClick: function () { setAttr({ blips: a.blips.concat([{ name: 'New Technology', ring: 'assess', quadrant: 'Tools', description: '', isNew: true }]) }); } }, __('+ Add Blip')) |
| 144 |
), |
| 145 |
el(PanelBody, { title: __('Typography'), initialOpen: false }, |
| 146 |
getTypoControl()({ label: __('Title'), value: a.titleTypo, onChange: function (v) { setAttr({ titleTypo: v }); } }), |
| 147 |
el(RangeControl, { label: __('Base Font Size'), value: a.fontSize, min: 10, max: 22, onChange: function (v) { setAttr({ fontSize: v }); }, __nextHasNoMarginBottom: true }), |
| 148 |
el(RangeControl, { label: __('Ring Label Size'), value: a.ringLabelSize, min: 8, max: 18, onChange: function (v) { setAttr({ ringLabelSize: v }); }, __nextHasNoMarginBottom: true }), |
| 149 |
el(RangeControl, { label: __('Blip Name Size'), value: a.blipNameSize, min: 10, max: 20, onChange: function (v) { setAttr({ blipNameSize: v }); }, __nextHasNoMarginBottom: true }), |
| 150 |
el(RangeControl, { label: __('Line Height (%)'), value: a.lineHeight, min: 120, max: 220, onChange: function (v) { setAttr({ lineHeight: v }); }, __nextHasNoMarginBottom: true }), |
| 151 |
el(SelectControl, { label: __('Font Weight'), value: a.fontWeight, options: [{label:'400 Regular',value:'400'},{label:'500 Medium',value:'500'},{label:'600 Semi-bold',value:'600'},{label:'700 Bold',value:'700'},{label:'800 Extra Bold',value:'800'}], __nextHasNoMarginBottom: true, onChange: function (v) { setAttr({ fontWeight: v }); } }), |
| 152 |
el(RangeControl, { label: __('Border Radius'), value: a.borderRadius, min: 0, max: 32, onChange: function (v) { setAttr({ borderRadius: v }); }, __nextHasNoMarginBottom: true }) |
| 153 |
), |
| 154 |
el(PanelColorSettings, { |
| 155 |
title: __('Layout Colors'), |
| 156 |
initialOpen: false, |
| 157 |
colorSettings: [ |
| 158 |
{ label: __('Background'), value: a.bgColor, onChange: function (v) { setAttr({ bgColor: v || '#ffffff' }); } }, |
| 159 |
{ label: __('Border'), value: a.borderColor, onChange: function (v) { setAttr({ borderColor: v || '#e5e7eb' }); } }, |
| 160 |
{ label: __('Title'), value: a.titleColor, onChange: function (v) { setAttr({ titleColor: v || '#111827' }); } }, |
| 161 |
{ label: __('Description'), value: a.descColor, onChange: function (v) { setAttr({ descColor: v || '#6b7280' }); } }, |
| 162 |
{ label: __('Blip Name'), value: a.blipNameColor, onChange: function (v) { setAttr({ blipNameColor: v || '#1f2937' }); } }, |
| 163 |
{ label: __('Blip Desc'), value: a.blipDescColor, onChange: function (v) { setAttr({ blipDescColor: v || '#6b7280' }); } }, |
| 164 |
{ label: __('Quadrant Heading'), value: a.quadrantHeadColor, onChange: function (v) { setAttr({ quadrantHeadColor: v || '#374151' }); } }, |
| 165 |
{ label: __('NEW Badge BG'), value: a.newBadgeBg, onChange: function (v) { setAttr({ newBadgeBg: v || '#fef9c3' }); } }, |
| 166 |
{ label: __('NEW Badge Text'), value: a.newBadgeColor, onChange: function (v) { setAttr({ newBadgeColor: v || '#713f12' }); } } |
| 167 |
] |
| 168 |
}), |
| 169 |
el(PanelColorSettings, { |
| 170 |
title: __('Ring Colors'), |
| 171 |
initialOpen: false, |
| 172 |
colorSettings: [ |
| 173 |
{ label: __('Adopt BG'), value: a.adoptBg, onChange: function (v) { setAttr({ adoptBg: v || '#dcfce7' }); } }, |
| 174 |
{ label: __('Adopt Text'), value: a.adoptColor, onChange: function (v) { setAttr({ adoptColor: v || '#14532d' }); } }, |
| 175 |
{ label: __('Adopt Border'), value: a.adoptBorder, onChange: function (v) { setAttr({ adoptBorder: v || '#16a34a' }); } }, |
| 176 |
{ label: __('Trial BG'), value: a.trialBg, onChange: function (v) { setAttr({ trialBg: v || '#dbeafe' }); } }, |
| 177 |
{ label: __('Trial Text'), value: a.trialColor, onChange: function (v) { setAttr({ trialColor: v || '#1e40af' }); } }, |
| 178 |
{ label: __('Trial Border'), value: a.trialBorder, onChange: function (v) { setAttr({ trialBorder: v || '#2563eb' }); } }, |
| 179 |
{ label: __('Assess BG'), value: a.assessBg, onChange: function (v) { setAttr({ assessBg: v || '#fef9c3' }); } }, |
| 180 |
{ label: __('Assess Text'), value: a.assessColor, onChange: function (v) { setAttr({ assessColor: v || '#713f12' }); } }, |
| 181 |
{ label: __('Assess Border'), value: a.assessBorder, onChange: function (v) { setAttr({ assessBorder: v || '#d97706' }); } }, |
| 182 |
{ label: __('Hold BG'), value: a.holdBg, onChange: function (v) { setAttr({ holdBg: v || '#f3f4f6' }); } }, |
| 183 |
{ label: __('Hold Text'), value: a.holdColor, onChange: function (v) { setAttr({ holdColor: v || '#374151' }); } }, |
| 184 |
{ label: __('Hold Border'), value: a.holdBorder, onChange: function (v) { setAttr({ holdBorder: v || '#9ca3af' }); } } |
| 185 |
] |
| 186 |
}) |
| 187 |
), |
| 188 |
el('div', useBlockProps((function () { |
| 189 |
var _tvf = getTypoCssVars(); |
| 190 |
var s = { background: a.bgColor, borderRadius: a.borderRadius + 'px', border: '1px solid ' + a.borderColor, padding: 32, fontSize: a.fontSize + 'px', lineHeight: (a.lineHeight / 100).toFixed(2) }; |
| 191 |
if (_tvf) { Object.assign(s, _tvf(a.titleTypo, '--bktr-tt-')); } |
| 192 |
return { className: 'bkbg-tr-wrap', style: s }; |
| 193 |
})()), |
| 194 |
el('div', { className: 'bkbg-tr-header' }, |
| 195 |
el('h2', { className: 'bkbg-tr-title', style: { color: a.titleColor } }, a.radarTitle), |
| 196 |
a.showDescription && el('p', { className: 'bkbg-tr-desc', style: { color: a.descColor } }, a.description) |
| 197 |
), |
| 198 |
preview |
| 199 |
) |
| 200 |
); |
| 201 |
}, |
| 202 |
save: function (props) { |
| 203 |
var useBlockProps = wp.blockEditor.useBlockProps; |
| 204 |
var _tvf = getTypoCssVars(); |
| 205 |
var s = {}; |
| 206 |
if (_tvf) { Object.assign(s, _tvf(props.attributes.titleTypo, '--bktr-tt-')); } |
| 207 |
return el('div', useBlockProps.save({ style: Object.keys(s).length ? s : undefined }), |
| 208 |
el('div', { className: 'bkbg-tech-radar-app', 'data-opts': JSON.stringify(props.attributes) }) |
| 209 |
); |
| 210 |
} |
| 211 |
}); |
| 212 |
}() ); |
| 213 |
|