grapesjs icon indicating copy to clipboard operation
grapesjs copied to clipboard

Code manager set code

Open froderf opened this issue 8 years ago • 2 comments

Hi @artf. Is there something similar to this editor.CodeManager.setCode(component, 'css', {cssc: editor.CssComposer}

to update the css rule of the selected block returned from editor.CodeManager.getCode(component, 'css', {cssc: editor.CssComposer});

For example: This is the returned css rule collection from using
editor.CodeManager.getCode(component, 'css', {cssc: editor.CssComposer});

Returned:

.c1234 {
  color: 'white';
}

.classx .c1234{
 background: black;
}

What I need is to save and update it to like

.c1234 {
   color: 'yellow';
}

.classx .c1234{
 background: #222222;
}

I tried the cc.setClassRule('c1234', { background: #222222 }); but this csscomposer function is limited for 1 class only I need a dynamic function that can update the content returned by editor.CodeManager.getCode(component, 'css', {cssc: editor.CssComposer});

Thank you !

froderf avatar Nov 02 '18 12:11 froderf

Hi @froderf, for now, the only way to get that rule is to use CssComposer.get method. In your case, .classx .c1234 is stored inside selectorsAdd as not being a single level class selector (eg. .class1.class2)

editor.CssComposer.get([], null, null, { selectorsAdd: '.classx .c1234' })

artf avatar Nov 03 '18 11: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 03 '19 12:11 lock[bot]