-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Namespace CSS? #391
Comments
OK, thanks @artf |
do you think you could just prefix all class names generated by grapejs? if instead of .row you use .grape-row or whatever (i'd probably make the prefix a variable), you'll mostly get the effect that @tomichal is after. |
Adding a prefix per @danfitz36 suggestion sounds great from my POV. |
I think this should go further than just pre-fixing with |
Is there any ETA on this? I guess I have to parse the CSS in PHP and prefix each selector with a scope or similar for now. |
The templating could just have a top level class so you’d reference ‘.template .grapejs-button’. No need to add it to every component |
For anyone that are using PHP as a save handler you could do the following using this lib https://github.com/sabberworm/PHP-CSS-Parser. $prefix = '#scope-01';
$parsedCss = (new Sabberworm\CSS\Parser('.foobar { color: red; }'))->parse();
/** @var Sabberworm\CSS\RuleSet\DeclarationBlock[] $blocks */
$blocks = $parsedCss->getAllDeclarationBlocks();
foreach ($blocks as $block) {
/** @var Sabberworm\CSS\Property\Selector[] $selectors */
$selectors = $block->getSelectors();
foreach ($selectors as $selector) {
$selector->setSelector($prefix . ' ' . $selector->getSelector());
}
}
$output = $parsedCss->render(); |
Actually, you can add a listener on new selectors and add a prefix there const prefix = 'myprefix-';
editor.on('selector:add', selector => {
const name = selector.get('name');
if (selector.get('type') === editor.SelectorManager.Selector.TYPE_CLASS &&
name.indexOf(prefix) !== 0) {
selector.set('name', prefix + name);
}
}); |
I just wrap all css generated by grapes in a wrapper class then compile it to css with node-sass .wrapper-classname { |
How did you do the wrapping part? |
HI, To do so, I used sass.js (https://github.com/medialize/sass.js/) Steps:
This way you wont face the issue of conflicts. This answer was copied from another question. #2363 |
This is my current hack. It's ugly but seems to work:
|
@artf What if we add the prefix to all the pre-defined CSS names in the code itself. something like I can work on it and send a PR for this. |
@abalyan-quotient the namespacing feature should be applied (configurable) at the CssGenerator level |
Hi there,
Is there a way to setup the grapesjs editor such that the CSS generated for the HTML content is namespaced? In other words, how to avoid the style rules defined for the content created/edited in the editor to leak out to the rest of the website page?
In the case of my website the user can edit a large part of the page, but not all of it - the rest of the page HTML content and CSS is dynamically generated by the server (this is a Rails + Angular site).
I find that if e.g. I use a row with columns, the CSS generated by grapesjs editor will have a definition for a "row" class (i.e. ".row { ... }"). However, I use a CSS library that provides its own definitions for a "row" class, and so the grapesjs definition conflicts with my site-wide CSS.
Thanks for any help and tips to this issue!
The text was updated successfully, but these errors were encountered: