Can't reset body background
I've found this
editor.CssComposer.getAll().reset();
here #351 but seems not to reset the body background...
Any other way to do this?
Hi @g41n,
Can you provide a jsfiddle (or equivalent) showing the issue? I just put this together which first sets the body background color to blue, and then clears that style 2 seconds later: https://jsfiddle.net/gn3jtahv/. That seems to work just fine for me (also tested using editor.CssComposer.getAll().reset() with the same result), so I'm guessing that you're doing something differently...
Hi @ryandeba, thanks for the reply.
After some digging here there is a fiddle https://jsfiddle.net/x118ks1v/ and steps to reproduce:
- click on the reset button, reset is successfull
- click on body and change background from the panel on the right
- click on the reset button, reset failed
The problem seems occour only after you change body background from grapesjs panel manually.
Hope it helps to find a solution... :/
Thanks for the additional details! I can confirm that I have been able to recreate the issue, but I'm not sure what the next steps need to be.
@artf - would you mind sharing your thoughts here? Is this a bug or are our expectations about editor.setStyle() (and/or editor.CssComposer.getAll().reset()) different from the intended use?
Yeah, the problem here is with the wrapper's style, it's inside its component and not in the Rule of CssComposer, so you have to use editor.DomComponents.getWrapper().setStyle('');
https://jsfiddle.net/y420c2pL/
editor.setStyle("body { background-color: blue}");
Unfortunately, this creates another body rule (you can see it in the exporter). Probably I have to find a better way to manage the wrapper/body style :/
Unfortunately, this creates another body rule (you can see it in the exporter).
I see it... and sadly if I use the export in a webpage I see the old background... :(
Hope to find a little hack while waiting for a fix.
I've found that when I try to edit the CSS directly with the code editor, following the instructions in #324, but just editing the CSS that these...
*{
box-sizing: border-box;
}
body{
margin:0;
}
... reappear all the time, sometimes duplicated.
I followed the instructions that I found in #488, but that did not help.
I'm saving the code like this:
btnSave.onclick = () => {
const code = codeViewer.editor.getValue();
editor.DomComponents.getWrapper().set('content', '');
editor.CssComposer.getAll().reset();
editor.setComponents(editor.getHtml());
editor.setStyle(code.trim());
modal.close();
};
Is this a symptom of the above bug(s) or should I open a different issue?
@duskhacker I'd say it's somehow related but not the same issue.
CSS you're mentioning it's generated from two different places and it's some kind of a basic CSS reset
*{box-sizing: border-box;} comes from https://github.com/artf/grapesjs/blob/dev/src/editor/config/config.js#L34
and body{margin:0;} from https://github.com/artf/grapesjs/blob/dev/src/dom_components/config/config.js#L10
Probably what I'll gonna do for the next release is to move the current wrapper style inside protectedCss option.
For those who are trying to achieve edit the CSS directly with the code editor should add a new view code command (current) and replace em.getCss() with em.getCss({ avoidProtected: 1 }) (not yet implemented)
@artf Thank you so much! I'm hopeful that the fix you just mentioned, the one @ryandeba fixed for the asset manager (#549), and a fix for the issue where having an anchor tag makes the rest of the text un-editable (#576) will all get rolled into the next release. I'm looking forward to it.
I wish I could do more to help out, I've tried to at least answer some of the other issues that I can to help out a little bit.
Should be fixed if you use avoidInlineStyle: true (probably one day or another this option will be true by default)
https://jsfiddle.net/gbqsxwtL
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.