Skip to content

Commit

Permalink
Add default device option. Closes GrapesJS#3679
Browse files Browse the repository at this point in the history
  • Loading branch information
artf authored and felixx-kreebox committed Feb 28, 2022
1 parent ddd4f90 commit 966e715
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
15 changes: 6 additions & 9 deletions src/canvas/model/Canvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,10 @@ export default class Canvas extends Model {

init() {
const { em } = this;
this.set(
'frames',
em
.get('PageManager')
.getMain()
.getFrames()
);
const mainPage = em.get('PageManager').getMain();
const frame = mainPage.getMainFrame();
this.set('frames', mainPage.getFrames());
this.updateDevice({ frame });
}

_pageUpdated(page, prev) {
Expand All @@ -45,10 +42,10 @@ export default class Canvas extends Model {
this.set('frames', page.getFrames());
}

updateDevice() {
updateDevice(opts = {}) {
const { em } = this;
const device = em.getDeviceModel();
const model = em.getCurrentFrameModel();
const model = opts.frame || em.getCurrentFrameModel();

if (model && device) {
const { width, height } = device.attributes;
Expand Down
4 changes: 4 additions & 0 deletions src/device_manager/config/config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
export default {
// The device `id` to select on start, if not indicated, the first available from `devices` will be used.
default: null,

// Default devices
devices: [
{
id: 'desktop',
Expand Down
3 changes: 2 additions & 1 deletion src/device_manager/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,10 @@ export default () => {
const { em } = c;

devices = new Devices();
(c.devices || []).forEach(dv => this.add(dv.id || dv.name, dv.width, dv));
c.devices.forEach(dv => this.add(dv));
this.em = em;
this.all = devices;
this.select(c.default || devices.at(0));
this.__initListen();
em.on(chnSel, this._onSelect, this);

Expand Down

0 comments on commit 966e715

Please sign in to comment.