| 1 |
(function () { |
| 2 |
var el = wp.element.createElement; |
| 3 |
var Fragment = wp.element.Fragment; |
| 4 |
var registerBlockType = wp.blocks.registerBlockType; |
| 5 |
var __ = wp.i18n.__; |
| 6 |
var InspectorControls = wp.blockEditor.InspectorControls; |
| 7 |
var PanelColorSettings = wp.blockEditor.PanelColorSettings; |
| 8 |
var useBlockProps = wp.blockEditor.useBlockProps; |
| 9 |
var PanelBody = wp.components.PanelBody; |
| 10 |
var TextControl = wp.components.TextControl; |
| 11 |
var ToggleControl = wp.components.ToggleControl; |
| 12 |
var RangeControl = wp.components.RangeControl; |
| 13 |
var SelectControl = wp.components.SelectControl; |
| 14 |
var Button = wp.components.Button; |
| 15 |
var ColorPicker = wp.components.ColorPicker; |
| 16 |
var Popover = wp.components.Popover; |
| 17 |
var useState = wp.element.useState; |
| 18 |
|
| 19 |
// ── helpers ──────────────────────────────────────────────────── |
| 20 |
function upd(arr, idx, field, val) { |
| 21 |
return arr.map(function (e, i) { |
| 22 |
if (i !== idx) return e; |
| 23 |
var u = {}; u[field] = val; |
| 24 |
return Object.assign({}, e, u); |
| 25 |
}); |
| 26 |
} |
| 27 |
|
| 28 |
var SECTION_TYPES = [ |
| 29 |
{ value: 'nav', label: 'Nav bar' }, |
| 30 |
{ value: 'hero', label: 'Hero / Banner' }, |
| 31 |
{ value: 'feature', label: 'Feature grid' }, |
| 32 |
{ value: 'content', label: 'Content / Text' }, |
| 33 |
{ value: 'cta', label: 'CTA strip' }, |
| 34 |
{ value: 'footer', label: 'Footer' }, |
| 35 |
]; |
| 36 |
|
| 37 |
var BROWSER_STYLES = [ |
| 38 |
{ value: 'chrome', label: 'Chrome (light)' }, |
| 39 |
{ value: 'dark', label: 'Chrome (dark)' }, |
| 40 |
{ value: 'arc', label: 'Arc (sidebar)' }, |
| 41 |
{ value: 'minimal', label: 'Minimal' }, |
| 42 |
]; |
| 43 |
|
| 44 |
// Section icon by type |
| 45 |
function sectionIcon(type) { |
| 46 |
if (type === 'nav') return '☰'; |
| 47 |
if (type === 'hero') return '� |
| 48 |
'; |
| 49 |
if (type === 'feature') return '◈'; |
| 50 |
if (type === 'content') return '¶'; |
| 51 |
if (type === 'cta') return '▶'; |
| 52 |
if (type === 'footer') return '◻'; |
| 53 |
return '▪'; |
| 54 |
} |
| 55 |
|
| 56 |
// ── Render browser chrome + sections ────────────────────────── |
| 57 |
function renderBrowser(a) { |
| 58 |
var isDark = a.browserStyle === 'dark'; |
| 59 |
var isArc = a.browserStyle === 'arc'; |
| 60 |
var isMinimal = a.browserStyle === 'minimal'; |
| 61 |
|
| 62 |
var frameBg = isDark ? '#1e1e1e' : a.frameBg; |
| 63 |
var frameText = isDark ? '#d4d4d4' : a.frameText; |
| 64 |
|
| 65 |
// Traffic-light dots |
| 66 |
var dots = el('div', { style: { display: 'flex', gap: '6px', alignItems: 'center', flexShrink: '0' } }, |
| 67 |
el('span', { style: { width: '12px', height: '12px', borderRadius: '50%', background: '#ef4444', display: 'block' } }), |
| 68 |
el('span', { style: { width: '12px', height: '12px', borderRadius: '50%', background: '#f59e0b', display: 'block' } }), |
| 69 |
el('span', { style: { width: '12px', height: '12px', borderRadius: '50%', background: '#22c55e', display: 'block' } }) |
| 70 |
); |
| 71 |
|
| 72 |
// Active tab |
| 73 |
var activeTab = el('div', { |
| 74 |
style: { |
| 75 |
display: 'flex', alignItems: 'center', gap: '6px', |
| 76 |
background: a.tabActiveBg, color: a.tabActiveText, |
| 77 |
borderRadius: '6px 6px 0 0', padding: '6px 14px', |
| 78 |
fontSize: a.titleFontSize + 'px', fontWeight: '500', |
| 79 |
maxWidth: '160px', whiteSpace: 'nowrap', overflow: 'hidden' |
| 80 |
} |
| 81 |
}, |
| 82 |
el('span', { style: { fontSize: '10px' } }, '◉'), |
| 83 |
el('span', { style: { overflow: 'hidden', textOverflow: 'ellipsis' } }, a.tabTitle) |
| 84 |
); |
| 85 |
|
| 86 |
// Extra inactive tabs |
| 87 |
var tab2 = el('div', { |
| 88 |
style: { |
| 89 |
display: 'flex', alignItems: 'center', gap: '6px', |
| 90 |
background: a.tabInactiveBg, color: a.tabInactiveText, |
| 91 |
borderRadius: '6px 6px 0 0', padding: '6px 12px', |
| 92 |
fontSize: (a.titleFontSize - 1) + 'px' |
| 93 |
} |
| 94 |
}, 'New Tab'); |
| 95 |
var tab3 = el('div', { |
| 96 |
style: { |
| 97 |
display: 'flex', alignItems: 'center', gap: '6px', |
| 98 |
background: a.tabInactiveBg, color: a.tabInactiveText, |
| 99 |
borderRadius: '6px 6px 0 0', padding: '6px 10px', |
| 100 |
fontSize: (a.titleFontSize - 1) + 'px' |
| 101 |
} |
| 102 |
}, '+'); |
| 103 |
|
| 104 |
// Tab bar row (only in non-minimal) |
| 105 |
var tabBar = (!isMinimal && a.showTabs) ? el('div', { |
| 106 |
style: { |
| 107 |
display: 'flex', alignItems: 'flex-end', gap: '2px', |
| 108 |
padding: '8px 12px 0', background: frameBg |
| 109 |
} |
| 110 |
}, dots, el('div', { style: { width: '16px' } }), activeTab, tab2, tab3) |
| 111 |
: null; |
| 112 |
|
| 113 |
// Minimal dots-only header |
| 114 |
var minimalHeader = isMinimal ? el('div', { |
| 115 |
style: { display: 'flex', alignItems: 'center', gap: '6px', padding: '10px 14px', background: frameBg } |
| 116 |
}, dots) : null; |
| 117 |
|
| 118 |
// URL bar |
| 119 |
var urlBar = a.showURL ? el('div', { |
| 120 |
style: { |
| 121 |
display: 'flex', alignItems: 'center', gap: '8px', |
| 122 |
padding: isMinimal ? '0 14px 6px' : '8px 12px', |
| 123 |
background: frameBg |
| 124 |
} |
| 125 |
}, |
| 126 |
!a.showTabs && !isMinimal ? el('div', { style: { display: 'flex', gap: '6px', alignItems: 'center', marginRight: '8px' } }, |
| 127 |
el('span', { style: { width: '12px', height: '12px', borderRadius: '50%', background: '#ef4444', display: 'block' } }), |
| 128 |
el('span', { style: { width: '12px', height: '12px', borderRadius: '50%', background: '#f59e0b', display: 'block' } }), |
| 129 |
el('span', { style: { width: '12px', height: '12px', borderRadius: '50%', background: '#22c55e', display: 'block' } }) |
| 130 |
) : null, |
| 131 |
el('div', { style: { display: 'flex', alignItems: 'center', gap: '5px', color: frameText, fontSize: (a.fontSize - 1) + 'px', cursor: 'default', opacity: '.7' } }, |
| 132 |
'◀', ' ', '▶', ' ', '↻' |
| 133 |
), |
| 134 |
el('div', { |
| 135 |
style: { |
| 136 |
flex: '1', background: a.urlBarBg, border: '1px solid ' + a.urlBarBorder, |
| 137 |
borderRadius: '20px', padding: '4px 14px', |
| 138 |
display: 'flex', alignItems: 'center', gap: '6px' |
| 139 |
} |
| 140 |
}, |
| 141 |
el('span', { style: { fontSize: '10px', color: '#22c55e' } }, '🔒'), |
| 142 |
el('span', { style: { color: a.urlBarText, fontSize: a.fontSize + 'px', userSelect: 'none' } }, a.url) |
| 143 |
), |
| 144 |
el('div', { style: { display: 'flex', gap: '6px', color: frameText, fontSize: (a.fontSize - 1) + 'px', opacity: '.7' } }, |
| 145 |
'⋯', ' ☆', ' ⬇' |
| 146 |
) |
| 147 |
) : null; |
| 148 |
|
| 149 |
// Bookmarks bar |
| 150 |
var bookmarkBar = (a.showBookmarks && a.bookmarks && a.bookmarks.length) ? el('div', { |
| 151 |
style: { |
| 152 |
display: 'flex', alignItems: 'center', gap: '2px', |
| 153 |
padding: '4px 14px', background: frameBg, |
| 154 |
borderBottom: '1px solid ' + (isDark ? '#333' : '#d1d5db') |
| 155 |
} |
| 156 |
}, |
| 157 |
a.bookmarks.map(function (bk, idx) { |
| 158 |
return el('div', { |
| 159 |
key: idx, |
| 160 |
style: { |
| 161 |
padding: '2px 10px', borderRadius: '4px', cursor: 'default', |
| 162 |
color: frameText, fontSize: (a.fontSize - 1) + 'px', |
| 163 |
background: 'transparent', opacity: '.8' |
| 164 |
} |
| 165 |
}, '📄 ' + bk.label); |
| 166 |
}) |
| 167 |
) : null; |
| 168 |
|
| 169 |
// Page sections |
| 170 |
var pageContent = el('div', { style: { overflow: 'hidden' } }, |
| 171 |
a.sections.map(function (sec, idx) { |
| 172 |
return el('div', { |
| 173 |
key: idx, |
| 174 |
style: { |
| 175 |
height: sec.height + 'px', |
| 176 |
background: sec.bg, |
| 177 |
color: sec.textColor, |
| 178 |
display: 'flex', alignItems: 'center', justifyContent: 'center', |
| 179 |
fontSize: a.fontSize + 'px', fontWeight: sec.type === 'hero' ? '700' : '400', |
| 180 |
letterSpacing: sec.type === 'hero' ? '-0.01em' : '0', |
| 181 |
overflow: 'hidden', position: 'relative', |
| 182 |
gap: '10px' |
| 183 |
} |
| 184 |
}, |
| 185 |
el('span', { style: { fontSize: '18px', opacity: '.6' } }, sectionIcon(sec.type)), |
| 186 |
el('span', { style: { overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap', maxWidth: '80%' } }, sec.label) |
| 187 |
); |
| 188 |
}) |
| 189 |
); |
| 190 |
|
| 191 |
return el('div', { |
| 192 |
style: { |
| 193 |
borderRadius: a.borderRadius + 'px', |
| 194 |
overflow: 'hidden', |
| 195 |
boxShadow: '0 20px 60px ' + a.frameShadow + ', 0 4px 12px ' + a.frameShadow, |
| 196 |
border: '1px solid ' + (isDark ? '#444' : '#d1d5db') |
| 197 |
} |
| 198 |
}, tabBar, minimalHeader, urlBar, bookmarkBar, pageContent); |
| 199 |
} |
| 200 |
|
| 201 |
// ── edit ────────────────────────────────────────────────────── |
| 202 |
function Edit(props) { |
| 203 |
var a = props.attributes; |
| 204 |
var set = props.setAttributes; |
| 205 |
|
| 206 |
var colorSettings = [ |
| 207 |
{ label: __('Frame BG'), value: a.frameBg, onChange: function (v) { set({ frameBg: v || '#e8e8e8' }); } }, |
| 208 |
{ label: __('Frame Text'), value: a.frameText, onChange: function (v) { set({ frameText: v || '#3c3c3c' }); } }, |
| 209 |
{ label: __('URL Bar BG'), value: a.urlBarBg, onChange: function (v) { set({ urlBarBg: v || '#ffffff' }); } }, |
| 210 |
{ label: __('URL Bar Text'), value: a.urlBarText, onChange: function (v) { set({ urlBarText: v || '#374151' }); } }, |
| 211 |
{ label: __('URL Bar Border'), value: a.urlBarBorder, onChange: function (v) { set({ urlBarBorder: v || '#d1d5db' }); } }, |
| 212 |
{ label: __('Active Tab BG'), value: a.tabActiveBg, onChange: function (v) { set({ tabActiveBg: v || '#ffffff' }); } }, |
| 213 |
{ label: __('Active Tab Text'), value: a.tabActiveText, onChange: function (v) { set({ tabActiveText: v || '#111827' }); } }, |
| 214 |
{ label: __('Inactive Tab BG'), value: a.tabInactiveBg, onChange: function (v) { set({ tabInactiveBg: v || '#d1d5db' }); } }, |
| 215 |
{ label: __('Inactive Tab Text'), value: a.tabInactiveText, onChange: function (v) { set({ tabInactiveText: v || '#6b7280' }); } }, |
| 216 |
{ label: __('Shadow'), value: a.frameShadow, onChange: function (v) { set({ frameShadow: v || '#00000033' }); } }, |
| 217 |
]; |
| 218 |
|
| 219 |
var inspector = el(InspectorControls, {}, |
| 220 |
// Browser settings |
| 221 |
el(PanelBody, { title: __('Browser Frame'), initialOpen: true }, |
| 222 |
el(SelectControl, { |
| 223 |
label: __('Browser style'), value: a.browserStyle, options: BROWSER_STYLES, __nextHasNoMarginBottom: true, |
| 224 |
onChange: function (v) { set({ browserStyle: v }); } |
| 225 |
}), |
| 226 |
el(TextControl, { |
| 227 |
label: __('URL'), value: a.url, __nextHasNoMarginBottom: true, |
| 228 |
onChange: function (v) { set({ url: v }); } |
| 229 |
}), |
| 230 |
el(TextControl, { |
| 231 |
label: __('Tab title'), value: a.tabTitle, __nextHasNoMarginBottom: true, |
| 232 |
onChange: function (v) { set({ tabTitle: v }); } |
| 233 |
}), |
| 234 |
el(ToggleControl, { |
| 235 |
label: __('Show tabs'), checked: a.showTabs, __nextHasNoMarginBottom: true, |
| 236 |
onChange: function (v) { set({ showTabs: v }); } |
| 237 |
}), |
| 238 |
el(ToggleControl, { |
| 239 |
label: __('Show URL bar'), checked: a.showURL, __nextHasNoMarginBottom: true, |
| 240 |
onChange: function (v) { set({ showURL: v }); } |
| 241 |
}), |
| 242 |
el(ToggleControl, { |
| 243 |
label: __('Show bookmarks bar'), checked: a.showBookmarks, __nextHasNoMarginBottom: true, |
| 244 |
onChange: function (v) { set({ showBookmarks: v }); } |
| 245 |
}), |
| 246 |
el(RangeControl, { |
| 247 |
label: __('Corner radius'), value: a.borderRadius, min: 0, max: 28, __nextHasNoMarginBottom: true, |
| 248 |
onChange: function (v) { set({ borderRadius: v }); } |
| 249 |
}), |
| 250 |
), |
| 251 |
// Bookmarks |
| 252 |
a.showBookmarks ? el(PanelBody, { title: __('Bookmarks'), initialOpen: false }, |
| 253 |
a.bookmarks.map(function (bk, idx) { |
| 254 |
return el('div', { key: idx, style: { display: 'flex', gap: '8px', alignItems: 'center', marginBottom: '6px' } }, |
| 255 |
el(TextControl, { |
| 256 |
value: bk.label, __nextHasNoMarginBottom: true, |
| 257 |
onChange: function (v) { set({ bookmarks: upd(a.bookmarks, idx, 'label', v) }); } |
| 258 |
}), |
| 259 |
el(Button, { |
| 260 |
variant: 'secondary', isSmall: true, isDestructive: true, |
| 261 |
onClick: function () { var n = a.bookmarks.slice(); n.splice(idx, 1); set({ bookmarks: n }); } |
| 262 |
}, '✕') |
| 263 |
); |
| 264 |
}), |
| 265 |
a.bookmarks.length < 8 ? el(Button, { |
| 266 |
variant: 'secondary', isSmall: true, |
| 267 |
onClick: function () { set({ bookmarks: a.bookmarks.concat([{ label: 'Bookmark' }]) }); } |
| 268 |
}, '+ Add bookmark') : null |
| 269 |
) : null, |
| 270 |
// Page sections |
| 271 |
el(PanelBody, { title: __('Page Sections (' + a.sections.length + ')'), initialOpen: false }, |
| 272 |
a.sections.map(function (sec, idx) { |
| 273 |
return el(PanelBody, { |
| 274 |
key: idx, |
| 275 |
title: (idx + 1) + '. ' + sec.label.substring(0, 28) + (sec.label.length > 28 ? '…' : ''), |
| 276 |
initialOpen: false |
| 277 |
}, |
| 278 |
el(SelectControl, { |
| 279 |
label: __('Type'), value: sec.type, options: SECTION_TYPES, __nextHasNoMarginBottom: true, |
| 280 |
onChange: function (v) { set({ sections: upd(a.sections, idx, 'type', v) }); } |
| 281 |
}), |
| 282 |
el(TextControl, { |
| 283 |
label: __('Label / text'), value: sec.label, __nextHasNoMarginBottom: true, |
| 284 |
onChange: function (v) { set({ sections: upd(a.sections, idx, 'label', v) }); } |
| 285 |
}), |
| 286 |
el(RangeControl, { |
| 287 |
label: __('Height (px)'), value: sec.height, min: 32, max: 400, __nextHasNoMarginBottom: true, |
| 288 |
onChange: function (v) { set({ sections: upd(a.sections, idx, 'height', v) }); } |
| 289 |
}), |
| 290 |
el(BkbgColorSwatch, { label: __('Background color'), value: sec.bg, onChange: function (v) { set({ sections: upd(a.sections, idx, 'bg', v) }); } }), |
| 291 |
el(BkbgColorSwatch, { label: __('Text color'), value: sec.textColor, onChange: function (v) { set({ sections: upd(a.sections, idx, 'textColor', v) }); } }), |
| 292 |
el(Button, { |
| 293 |
variant: 'secondary', isDestructive: true, __nextHasNoMarginBottom: true, |
| 294 |
onClick: function () { var n = a.sections.slice(); n.splice(idx, 1); set({ sections: n }); } |
| 295 |
}, __('Remove section')) |
| 296 |
); |
| 297 |
}), |
| 298 |
el(Button, { |
| 299 |
variant: 'primary', __nextHasNoMarginBottom: true, |
| 300 |
onClick: function () { |
| 301 |
set({ sections: a.sections.concat([{ type: 'content', label: 'New section', height: 80, bg: '#ffffff', textColor: '#333333' }]) }); |
| 302 |
} |
| 303 |
}, __('+ Add section')) |
| 304 |
), |
| 305 |
|
| 306 |
el( PanelBody, { title: __( 'Typography', 'blockenberg' ), initialOpen: false }, |
| 307 |
el(RangeControl, { |
| 308 |
label: __('Font size'), value: a.fontSize, min: 10, max: 20, __nextHasNoMarginBottom: true, |
| 309 |
onChange: function (v) { set({ fontSize: v }); } |
| 310 |
}), |
| 311 |
el(RangeControl, { label: __('Title Font Size (px)', 'blockenberg'), value: a.titleFontSize, min: 10, max: 20, __nextHasNoMarginBottom: true, onChange: function (v) { set({ titleFontSize: v }); } }), |
| 312 |
el(SelectControl, { label: __('Title Font Weight', 'blockenberg'), value: a.titleFontWeight||500, options: [{label:'400',value:400},{label:'500',value:500},{label:'600',value:600},{label:'700',value:700}], __nextHasNoMarginBottom: true, onChange: function (v) { set({ titleFontWeight: parseInt(v,10) }); } }), |
| 313 |
el(RangeControl, { label: __('Title Line Height', 'blockenberg'), value: a.titleLineHeight||1.3, min: 0.8, max: 2.5, step: 0.1, __nextHasNoMarginBottom: true, onChange: function (v) { set({ titleLineHeight: v }); } }) |
| 314 |
), |
| 315 |
el(PanelColorSettings, { |
| 316 |
title: __('Frame Colors'), |
| 317 |
initialOpen: false, |
| 318 |
colorSettings: colorSettings |
| 319 |
}) |
| 320 |
); |
| 321 |
|
| 322 |
return el(Fragment, {}, |
| 323 |
inspector, |
| 324 |
el('div', Object.assign({}, useBlockProps(), { |
| 325 |
style: { fontFamily: '-apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif' } |
| 326 |
}), renderBrowser(a)) |
| 327 |
); |
| 328 |
} |
| 329 |
|
| 330 |
var BkbgColorSwatch = function (props) { |
| 331 |
var _st = useState(false); var isOpen = _st[0]; var setOpen = _st[1]; |
| 332 |
return el(Fragment, {}, |
| 333 |
el('div', { style: { display: 'flex', alignItems: 'center', gap: '8px', marginBottom: '8px' } }, |
| 334 |
el('span', { style: { fontSize: '11px', fontWeight: 500, textTransform: 'uppercase', color: '#1e1e1e' } }, props.label), |
| 335 |
el('button', { |
| 336 |
type: 'button', |
| 337 |
onClick: function () { setOpen(!isOpen); }, |
| 338 |
style: { width: '28px', height: '28px', borderRadius: '4px', border: '1px solid #ccc', background: props.value || '#ffffff', cursor: 'pointer', padding: 0 } |
| 339 |
}) |
| 340 |
), |
| 341 |
isOpen && el(Popover, { onClose: function () { setOpen(false); } }, |
| 342 |
el('div', { style: { padding: '8px' } }, |
| 343 |
el(ColorPicker, { color: props.value, onChangeComplete: function (c) { props.onChange(c.hex); }, enableAlpha: true }) |
| 344 |
) |
| 345 |
) |
| 346 |
); |
| 347 |
}; |
| 348 |
|
| 349 |
registerBlockType('blockenberg/browser-mockup', { |
| 350 |
edit: Edit, |
| 351 |
save: function (props) { |
| 352 |
return el('div', useBlockProps.save(), |
| 353 |
el('div', { className: 'bkbg-browser-mockup-app', 'data-opts': JSON.stringify(props.attributes) }) |
| 354 |
); |
| 355 |
} |
| 356 |
}); |
| 357 |
})(); |
| 358 |
|