| 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 PanelBody = wp.components.PanelBody; |
| 7 |
var PanelColorSettings = wp.blockEditor.PanelColorSettings; |
| 8 |
var RangeControl = wp.components.RangeControl; |
| 9 |
var TextControl = wp.components.TextControl; |
| 10 |
var SelectControl = wp.components.SelectControl; |
| 11 |
var Button = wp.components.Button; |
| 12 |
var useBlockProps = wp.blockEditor.useBlockProps; |
| 13 |
var _tc, _tv; |
| 14 |
function getTypoControl() { return _tc || (_tc = window.bkbgTypographyControl); } |
| 15 |
function getTypoCssVars() { return _tv || (_tv = window.bkbgTypoCssVars); } |
| 16 |
|
| 17 |
var STATUS_LABELS = { done: 'Done', progress: 'In Progress', planned: 'Planned' }; |
| 18 |
|
| 19 |
function buildItems( items, setAttr ) { |
| 20 |
return items.map( function ( item, i ) { |
| 21 |
return el( 'div', { key: i, style: { border: '1px solid #e5e7eb', borderRadius: 6, padding: 10, marginBottom: 8 } }, |
| 22 |
el( TextControl, { label: __('Label','blockenberg'), value: item.label, onChange: function(v){ var n=items.slice(); n[i]=Object.assign({},item,{label:v}); setAttr({items:n}); } } ), |
| 23 |
el( TextControl, { label: __('Title','blockenberg'), value: item.title, onChange: function(v){ var n=items.slice(); n[i]=Object.assign({},item,{title:v}); setAttr({items:n}); } } ), |
| 24 |
el( TextControl, { label: __('Description','blockenberg'), value: item.desc, onChange: function(v){ var n=items.slice(); n[i]=Object.assign({},item,{desc:v}); setAttr({items:n}); } } ), |
| 25 |
el( SelectControl, { label: __('Status','blockenberg'), value: item.status, |
| 26 |
options: [ |
| 27 |
{label:'Done', value:'done'}, |
| 28 |
{label:'In Progress',value:'progress'}, |
| 29 |
{label:'Planned', value:'planned'} |
| 30 |
], |
| 31 |
onChange: function(v){ var n=items.slice(); n[i]=Object.assign({},item,{status:v}); setAttr({items:n}); } |
| 32 |
} ), |
| 33 |
el( Button, { isSmall:true, isDestructive:true, onClick: function(){ |
| 34 |
setAttr({ items: items.filter(function(_,j){return j!==i;}) }); |
| 35 |
} }, '✕ Remove' ) |
| 36 |
); |
| 37 |
} ); |
| 38 |
} |
| 39 |
|
| 40 |
/* v1 renderRoadmap — preserved for deprecated save */ |
| 41 |
function v1RenderRoadmap( attrs ) { |
| 42 |
var wrapStyle = { |
| 43 |
'--bkrm-done': attrs.doneColor, |
| 44 |
'--bkrm-prog': attrs.progressColor, |
| 45 |
'--bkrm-plan': attrs.plannedColor, |
| 46 |
'--bkrm-conn': attrs.connectorColor, |
| 47 |
'--bkrm-cW': attrs.cardWidth + 'px', |
| 48 |
'--bkrm-gap': attrs.cardGap + 'px', |
| 49 |
'--bkrm-cBg': attrs.cardBg, |
| 50 |
'--bkrm-cBrd': attrs.cardBorder, |
| 51 |
'--bkrm-cR': attrs.cardRadius + 'px', |
| 52 |
'--bkrm-title-fs': (attrs.titleFontSize || 15) + 'px', |
| 53 |
'--bkrm-title-fw': attrs.titleFontWeight || 600, |
| 54 |
'--bkrm-title-lh': attrs.titleLineHeight || 1.4, |
| 55 |
'--bkrm-desc-fs': (attrs.descFontSize || 13) + 'px', |
| 56 |
'--bkrm-desc-fw': attrs.descFontWeight || 400, |
| 57 |
'--bkrm-desc-lh': attrs.descLineHeight || 1.5 |
| 58 |
}; |
| 59 |
return el( 'div', { className: 'bkrm-wrap', style: wrapStyle }, |
| 60 |
el( 'div', { className: 'bkrm-track' }, |
| 61 |
attrs.items.map( function ( item, i ) { |
| 62 |
return [ |
| 63 |
el( 'div', { key: 'c-' + i, className: 'bkrm-card bkrm-status-' + item.status }, |
| 64 |
el( 'div', { className: 'bkrm-label-tag' }, item.label ), |
| 65 |
el( 'h4', { className: 'bkrm-title', style: { fontSize: (attrs.titleFontSize || 15) + 'px', fontWeight: attrs.titleFontWeight || 600, lineHeight: attrs.titleLineHeight || 1.4 } }, item.title ), |
| 66 |
el( 'p', { className: 'bkrm-desc', style: { fontSize: (attrs.descFontSize || 13) + 'px', fontWeight: attrs.descFontWeight || 400, lineHeight: attrs.descLineHeight || 1.5 } }, item.desc ), |
| 67 |
el( 'span', { className: 'bkrm-badge bkrm-badge-' + item.status }, |
| 68 |
STATUS_LABELS[ item.status ] || item.status |
| 69 |
) |
| 70 |
), |
| 71 |
i < attrs.items.length - 1 ? el( 'div', { key: 'arr-' + i, className: 'bkrm-arrow' }, |
| 72 |
el( 'svg', { viewBox:'0 0 24 24', fill:'currentColor', width:20, height:20 }, |
| 73 |
el('path', { d:'M8.59 16.59L13.17 12 8.59 7.41 10 6l6 6-6 6z' }) |
| 74 |
) |
| 75 |
) : null |
| 76 |
]; |
| 77 |
} ) |
| 78 |
) |
| 79 |
); |
| 80 |
} |
| 81 |
|
| 82 |
function renderRoadmap( attrs ) { |
| 83 |
var tv = getTypoCssVars(); |
| 84 |
var wrapStyle = { |
| 85 |
'--bkrm-done': attrs.doneColor, |
| 86 |
'--bkrm-prog': attrs.progressColor, |
| 87 |
'--bkrm-plan': attrs.plannedColor, |
| 88 |
'--bkrm-conn': attrs.connectorColor, |
| 89 |
'--bkrm-cW': attrs.cardWidth + 'px', |
| 90 |
'--bkrm-gap': attrs.cardGap + 'px', |
| 91 |
'--bkrm-cBg': attrs.cardBg, |
| 92 |
'--bkrm-cBrd': attrs.cardBorder, |
| 93 |
'--bkrm-cR': attrs.cardRadius + 'px' |
| 94 |
}; |
| 95 |
if (tv) { |
| 96 |
Object.assign(wrapStyle, tv(attrs.titleTypo, '--bkrm-tt-')); |
| 97 |
Object.assign(wrapStyle, tv(attrs.descTypo, '--bkrm-dt-')); |
| 98 |
} |
| 99 |
return el( 'div', { className: 'bkrm-wrap', style: wrapStyle }, |
| 100 |
el( 'div', { className: 'bkrm-track' }, |
| 101 |
attrs.items.map( function ( item, i ) { |
| 102 |
return [ |
| 103 |
el( 'div', { key: 'c-' + i, className: 'bkrm-card bkrm-status-' + item.status }, |
| 104 |
el( 'div', { className: 'bkrm-label-tag' }, item.label ), |
| 105 |
el( 'h4', { className: 'bkrm-title' }, item.title ), |
| 106 |
el( 'p', { className: 'bkrm-desc' }, item.desc ), |
| 107 |
el( 'span', { className: 'bkrm-badge bkrm-badge-' + item.status }, |
| 108 |
STATUS_LABELS[ item.status ] || item.status |
| 109 |
) |
| 110 |
), |
| 111 |
i < attrs.items.length - 1 ? el( 'div', { key: 'arr-' + i, className: 'bkrm-arrow' }, |
| 112 |
el( 'svg', { viewBox:'0 0 24 24', fill:'currentColor', width:20, height:20 }, |
| 113 |
el('path', { d:'M8.59 16.59L13.17 12 8.59 7.41 10 6l6 6-6 6z' }) |
| 114 |
) |
| 115 |
) : null |
| 116 |
]; |
| 117 |
} ) |
| 118 |
) |
| 119 |
); |
| 120 |
} |
| 121 |
|
| 122 |
registerBlockType( 'blockenberg/roadmap', { |
| 123 |
deprecated: [{ |
| 124 |
attributes: { |
| 125 |
items: { type: 'array', default: [] }, |
| 126 |
cardWidth: { type: 'number', default: 200 }, |
| 127 |
cardGap: { type: 'number', default: 24 }, |
| 128 |
cardBg: { type: 'string', default: '#ffffff' }, |
| 129 |
cardBorder: { type: 'string', default: '#e5e7eb' }, |
| 130 |
cardRadius: { type: 'number', default: 10 }, |
| 131 |
doneColor: { type: 'string', default: '#22c55e' }, |
| 132 |
progressColor: { type: 'string', default: '#f59e0b' }, |
| 133 |
plannedColor: { type: 'string', default: '#94a3b8' }, |
| 134 |
connectorColor: { type: 'string', default: '#d1d5db' }, |
| 135 |
titleFontSize: { type: 'number', default: 15 }, |
| 136 |
titleFontWeight:{ type: 'number', default: 600 }, |
| 137 |
titleLineHeight:{ type: 'number', default: 1.4 }, |
| 138 |
descFontSize: { type: 'number', default: 13 }, |
| 139 |
descFontWeight: { type: 'number', default: 400 }, |
| 140 |
descLineHeight: { type: 'number', default: 1.5 }, |
| 141 |
titleTypo: { type: 'object', default: {} }, |
| 142 |
descTypo: { type: 'object', default: {} } |
| 143 |
}, |
| 144 |
save: function (props) { |
| 145 |
return v1RenderRoadmap(props.attributes); |
| 146 |
} |
| 147 |
}], |
| 148 |
edit: function ( props ) { |
| 149 |
var attrs = props.attributes; |
| 150 |
var setAttr = props.setAttributes; |
| 151 |
var blockProps = useBlockProps(); |
| 152 |
return el( 'div', blockProps, |
| 153 |
el( InspectorControls, null, |
| 154 |
el( PanelBody, { title: __('Items','blockenberg'), initialOpen: true }, |
| 155 |
buildItems( attrs.items, setAttr ), |
| 156 |
el( Button, { variant:'secondary', style:{marginTop:8}, onClick: function(){ |
| 157 |
setAttr({ items: attrs.items.concat([{ label:'Q?', title:'New Milestone', desc:'Description.', status:'planned' }]) }); |
| 158 |
} }, __('+ Add Milestone','blockenberg') ) |
| 159 |
), |
| 160 |
el( PanelBody, { title: __('Style','blockenberg'), initialOpen: false }, |
| 161 |
el( RangeControl, { label:__('Card Width (px)','blockenberg'), value:attrs.cardWidth, min:140, max:320, onChange:function(v){setAttr({cardWidth:v});} } ), |
| 162 |
el( RangeControl, { label:__('Card Gap (px)','blockenberg'), value:attrs.cardGap, min:8, max:60, onChange:function(v){setAttr({cardGap:v});} } ), |
| 163 |
el( RangeControl, { label:__('Border Radius (px)','blockenberg'), value:attrs.cardRadius, min:0, max:24, onChange:function(v){setAttr({cardRadius:v});} } ) |
| 164 |
), |
| 165 |
el( PanelBody, { title: __('Typography','blockenberg'), initialOpen: false }, |
| 166 |
(function () { var TC = getTypoControl(); return TC ? [ |
| 167 |
el(TC, { key: 'tt', label: __('Title','blockenberg'), value: attrs.titleTypo, onChange: function (v) { setAttr({ titleTypo: v }); } }), |
| 168 |
el(TC, { key: 'dt', label: __('Description','blockenberg'), value: attrs.descTypo, onChange: function (v) { setAttr({ descTypo: v }); } }) |
| 169 |
] : null; })() |
| 170 |
), |
| 171 |
el( PanelBody, { title: __('Colors','blockenberg'), initialOpen: false }, |
| 172 |
el( PanelColorSettings, { title:__('Colors','blockenberg'), colorSettings:[ |
| 173 |
{ value:attrs.doneColor, onChange:function(v){setAttr({doneColor:v||'#22c55e'});}, label:__('Done') }, |
| 174 |
{ value:attrs.progressColor, onChange:function(v){setAttr({progressColor:v||'#f59e0b'});}, label:__('In Progress') }, |
| 175 |
{ value:attrs.plannedColor, onChange:function(v){setAttr({plannedColor:v||'#94a3b8'});}, label:__('Planned') }, |
| 176 |
{ value:attrs.cardBg, onChange:function(v){setAttr({cardBg:v||'#fff'});}, label:__('Card Background') }, |
| 177 |
{ value:attrs.cardBorder, onChange:function(v){setAttr({cardBorder:v||'#e5e7eb'});}, label:__('Card Border') }, |
| 178 |
{ value:attrs.connectorColor, onChange:function(v){setAttr({connectorColor:v||'#d1d5db'});},label:__('Connector') } |
| 179 |
] } ) |
| 180 |
) |
| 181 |
), |
| 182 |
renderRoadmap( attrs ) |
| 183 |
); |
| 184 |
}, |
| 185 |
save: function ( props ) { |
| 186 |
return renderRoadmap( props.attributes ); |
| 187 |
} |
| 188 |
} ); |
| 189 |
} )(); |
| 190 |
|