Grapesjs: Is there a way to load blocks closed by default?

Created on 18 Sep 2017  路  4Comments  路  Source: artf/grapesjs

Hi guys,

Excited to play and explore this code. Is there a way to load blocks collapsed?

I noticed the style manager has properties for open = false, but I don't see it for blocks.

I was able to make them all collapsed by default by changing this code

src/block_manager/view/CategoryView.js

  updateVisibility() {
    if(this.model.get('open'))
      this.**close**(); //used to be open by default
    else
      this.**open**();
  },

Thanks!

outdated

Most helpful comment

Hi Dan, when you add a block you can indicate the category and its state if you want

editor.BlockManager.add('block-id', {
    ...
    label: 'Lable content',
    category: {
        id: 'some-cat', 
        label: 'Some cat', 
        open: true
    }
})

If you want to close all block categories opened by default just add this

editor.BlockManager.getCategories().each(ctg => ctg.set('open', false))

All 4 comments

It turns out there is a default value you can change in the model.

src/block_manager/model/Category.js

var Backbone = require('backbone');

module.exports = Backbone.Model.extend({

  defaults: {
    id: '',
    label: '',
    open: false,
    attributes: {},
  },

});

but I'm not able to set it when I'm loading a new block. Still looking will update soon.

Hi Dan, when you add a block you can indicate the category and its state if you want

editor.BlockManager.add('block-id', {
    ...
    label: 'Lable content',
    category: {
        id: 'some-cat', 
        label: 'Some cat', 
        open: true
    }
})

If you want to close all block categories opened by default just add this

editor.BlockManager.getCategories().each(ctg => ctg.set('open', false))

Thanks Artur!
Can;t wait to contribute once I get familiar with the code.
Dan

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

desilvaNSP picture desilvaNSP  路  3Comments

adam-gpc picture adam-gpc  路  3Comments

tribulant picture tribulant  路  3Comments

kosirm picture kosirm  路  3Comments

crazyxhz picture crazyxhz  路  3Comments