Config: bodyClass & selectorMethod #4720
Replies: 3 comments
-
Hello there, Just to add that I would be willing to sponsor this feature if you think it is a good idea. |
Beta Was this translation helpful? Give feedback.
-
What do you think of this @artf ? |
Beta Was this translation helpful? Give feedback.
-
Hi @LukeTOBrien thanks for your suggestions, about the BodyClass, the proper way to do it would be to extend the editor.Components.addType('wrapper', {
model: {
defaults: {
attributes: { class: 'my-class' },
},
},
}); that would guarantee for all wrappers to be have the exact definition when they are created (eg. added a new page). Regarding the SelectorMethod, at first I'd not expect the editor to create a class but rather moving those styles to the |
Beta Was this translation helpful? Give feedback.
-
Hello there,
I want to use GrapesJS in my project to replace my own WYSIWYG because I think what you have done is exactly what I need.
But I have two suggestions that I would like to mention here:
BodyClass
I wondered what you think about specifing the body (wrapper) class in the editor config?
I can achieve the desired result with
editor.getWrapper().addClass("my-class")
but what about in the config?SelectorMethod
Currently, when the user modifies styles, the selected element is assigned a random ID and a CSS rule is created using that ID.
In my current editor, I don't assign elements random IDs, instead I generate a CSS selector from the ancestors of that element (until the root) concatenate with the nth-of-type rule to identify the position of the element.
So this way the DOM is unobtrusive and it doesn't have elements with random IDs.
You could specify the selector method in the config like this:
Also a
getSelector
method should be added to the Component API.This should return the CSS selector, ie:
#id
orbody > div > p:nth-of-type(2)
.For eg, given the following HTML and setting the 'this'
<p>
element'scolor
:With the ID selector mode a random ID is generated:
With 'ancestor' selector mode a selector is generated using the ancestors and :nth-of-type():
What do you think?
Beta Was this translation helpful? Give feedback.
All reactions