Fix GrapesJS panels: use default layout, add device buttons

This commit is contained in:
Richard Sauer 2026-04-08 17:08:16 +10:00
parent 1831759563
commit 73705bdad7

View File

@ -130,11 +130,7 @@ const editor = grapesjs.init({
{id: 'desktop', name: 'Desktop (Full)', width: ''},
]
},
panels: {defaults: []},
layerManager: {appendTo: '.gjs-pn-views-container'},
selectorManager: {appendTo: '.gjs-pn-views-container'},
styleManager: {
appendTo: '.gjs-pn-views-container',
sectors: [
{
name: 'Typography',
@ -199,51 +195,22 @@ const editor = grapesjs.init({
}
]
},
traitManager: {appendTo: '.gjs-pn-views-container'},
blockManager: {
appendTo: '.gjs-pn-views-container',
blocks: []
},
blockManager: {blocks: []},
canvas: {
styles: ['static/hmi-canvas.css'],
}
});
// ══════════════════════════════════════════════════════
// Panels: Views (Blocks, Styles, Layers, Traits)
// ══════════════════════════════════════════════════════
editor.Panels.addPanel({
id: 'views',
el: '.gjs-pn-views',
buttons: [
{id: 'open-blocks', command: 'open-blocks', active: true, label: 'Blocks', attributes: {title: 'HMI Components'}},
{id: 'open-sm', command: 'open-sm', label: 'Style', attributes: {title: 'Style Manager'}},
{id: 'open-layers', command: 'open-layers', label: 'Layers', attributes: {title: 'Layers'}},
{id: 'open-tm', command: 'open-tm', label: 'Traits', attributes: {title: 'Component Settings'}},
]
// Use GrapesJS default panels — they include blocks, styles, layers, traits
// Just add device switching buttons
editor.Panels.addButton('options', {
id: 'device-tab5', command: e => e.setDevice('tab5'), label: 'Tab5', attributes: {title: 'Tab5 1280x720'}
});
// Device buttons
editor.Panels.addPanel({
id: 'devices',
el: '.gjs-pn-devices-c',
buttons: [
{id: 'device-tab5', command: e => e.setDevice('tab5'), label: 'Tab5', active: true},
{id: 'device-schneider', command: e => e.setDevice('schneider'), label: 'Schneider'},
{id: 'device-desktop', command: e => e.setDevice('desktop'), label: 'Full'},
]
editor.Panels.addButton('options', {
id: 'device-schneider', command: e => e.setDevice('schneider'), label: 'HMIDT', attributes: {title: 'Schneider 1280x800'}
});
// Toolbar commands
editor.Panels.addPanel({
id: 'basic-actions',
el: '.gjs-pn-panel .gjs-pn-commands',
buttons: [
{id: 'undo', command: 'core:undo', label: 'Undo'},
{id: 'redo', command: 'core:redo', label: 'Redo'},
{id: 'preview', command: 'core:preview', label: 'Preview'},
{id: 'clear', command: 'core:canvas-clear', label: 'Clear'},
]
editor.Panels.addButton('options', {
id: 'device-full', command: e => e.setDevice('desktop'), label: 'Full', attributes: {title: 'Full width'}
});
// ══════════════════════════════════════════════════════