Grapesjs: Block API remove function

Created on 26 Jul 2017  路  7Comments  路  Source: artf/grapesjs

I would assume that the remove() function would be required in such project, there's adding, getting, but not removing selected block, I would like to remove button block, and add my own - so I can make my own styles for it.

API enhancement

Most helpful comment

Agree, I'll add it soon, for the moment you can use this editor.BlockManager.getAll().remove('block-id')

All 7 comments

I second this, I ended up editing grapesjs and adding my own for the time being as it's pretty simple, I can make a merge request or if @artf can update it whenever possible to add the remove function :)

For the time being you can place this in your block_manager/index.js and re-compile grapesjs:

/** * Remove block by id * @param {string} id Block id */ remove(id) { return blocks.remove(id); },

Agree, I'll add it soon, for the moment you can use this editor.BlockManager.getAll().remove('block-id')

Awesome, thank you for the project :)

Any way to remove block by category?

@Geczy probably something like this

const bm = editor.BlockManager;
const blocks = bm.getAll();
const toRemove = blocks.filter(block => block.get('category') === ...);
toRemove.forEach(block => bm.remove(block.get('id')))

I believe the docs should also be updated regarding this change
https://github.com/artf/grapesjs/wiki/API-Block-Manager

@cmoutafidis you're looking in the wrong place https://grapesjs.com/docs/api/block_manager.html

Was this page helpful?
0 / 5 - 0 ratings

Related issues

andre2 picture andre2  路  3Comments

applibs picture applibs  路  3Comments

krunal039 picture krunal039  路  3Comments

adam-gpc picture adam-gpc  路  3Comments

ryandeba picture ryandeba  路  3Comments