grapesjs icon indicating copy to clipboard operation
grapesjs copied to clipboard

Can't reset body background

Open g41n opened this issue 9 years ago • 10 comments

I've found this

editor.CssComposer.getAll().reset();

here #351 but seems not to reset the body background...

Any other way to do this?

g41n avatar Nov 21 '17 16:11 g41n

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...

ryandeba avatar Nov 22 '17 00:11 ryandeba

Hi @ryandeba, thanks for the reply.

After some digging here there is a fiddle https://jsfiddle.net/x118ks1v/ and steps to reproduce:

  1. click on the reset button, reset is successfull
  2. click on body and change background from the panel on the right
  3. 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... :/

g41n avatar Nov 22 '17 07:11 g41n

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?

ryandeba avatar Nov 22 '17 23:11 ryandeba

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 :/

artf avatar Nov 23 '17 00:11 artf

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.

g41n avatar Nov 23 '17 07:11 g41n

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 avatar Nov 26 '17 18:11 duskhacker

@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 avatar Nov 29 '17 19:11 artf

@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.

duskhacker avatar Nov 29 '17 22:11 duskhacker

Should be fixed if you use avoidInlineStyle: true (probably one day or another this option will be true by default) https://jsfiddle.net/gbqsxwtL

artf avatar Nov 08 '18 23:11 artf

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.

lock[bot] avatar Nov 09 '19 00:11 lock[bot]