[Bug] Changing layerable in an an event at runtime doesn't immediately update
Question
When I change the layerable option of a custom component in an event, it still shows up in the layers until you drag it once. Is there some way to get around this by forcing the layers to update? Or can we get a bug fix for this, thanks.
import grapesjs from 'grapesjs';
import 'grapesjs-blocks-basic';
const editor = grapesjs.init({
container: '#gjs',
fromElement: 1,
storageManager: { type: 0 },
plugins: ['gjs-blocks-basic']
});
var comps = editor.DomComponents;
var defaultType = comps.getType('default');
var defaultModel = defaultType.model;
comps.addType('test', {
model: defaultModel.extend({
init: function() {
this.on("change:attributes:id", () => {
let attributes = this.getAttributes();
this.set({'layerable': attributes.id === 'layerable'});
});
}
})
});
editor.BlockManager.add('test', {
label: 'test',
category: 'something',
content: '<div data-gjs-type="test" style="height: 20px; background-color: blue;" id="layerable"></div>'
});
Video: Grapesjs layerable.zip
Answers (3)
The same thing is happening when I try to add/remove a toolbar button in an event - the toolbar doesn't update until I unselect the component and reselect it:
this.on("change:attributes:id", () => {
let tb = model.get('toolbar');
if (attributes.id === 'layerable') {
if (tb.filter(b => b.attributes.class === 'fa fa-plus').length > 0)
tb.pop();
}
else {
if (tb.filter(b => b.attributes.class === 'fa fa-plus').length === 0)
tb.push({
attributes: { class: 'fa fa-plus' },
command: () => {
model.components().add('<div>test</div');
}
});
}
});
Also, if you set 'removable' to false in the same place as where 'layerable' is being set in my post, the toolbar doesn't update to remove the delete button until you save and reload.
Try to trigger this event after your updates editor.trigger('component:toggled')
Related Questions and Answers
Continue research with similar issue discussions.
Issue #2404
Question: how to observe children changes in component
Is there an easy way to subscribe/listen to changes in the components/children of my custom component type? Perhaps an event I can subscrib...
Issue #2654
How to get the changed property from StyleManager
Hi, Is there a way to find out which property was changed in the StyleManager? For eg. If I select a Text component and change its backgrou...
Issue #639
Re-render Component on Canvas when tagName has changed
I'm trying to build a basic Header component that lets you select H1 to H6 with a trait. But when an option is selected, the canvas doesn't...
Issue #463
Is the video component on the webpage demo working?
I wanted to study how to use the video component but the one on the demo website (http://grapesjs.com/demo.html) doesn't seem to be working...
Paid Plugins That Match This Issue
Curated by issue keywords and label relevance to help you ship faster.
Loading paid plugin recommendations...
Browse Plugin Categories
Jump directly to plugin category pages on the marketplace.