[Question] why do layers not have element tag name?
I'm playing around with grapes' internals because I would like to contribute in the future. Most of my interest is in making it worth with generic HTML sites, regardless of the style/structure of CSS and HTML used (including doctype, body support etc).
I expected the layers hierarchy to represent the DOM tree. While this seems to be true so far, the naming of the elements seems off. For example with this HTML:
Would be displayed like so:
Whereas I had expect this tree:
- body
- h1
- text node
- div
- p
- text node
- p
- h1
Is this desired behavior?
GrapesJS is component based. So, I think it displays component names instead of tag names in this case. I think adding tag names and/or customizing layers tree rendering would be a nice enhancement.
Actually, GrapesJS component may consist of multiple DOM elements, so it may not make sense to display tag names in this case because you style a component and not individual elements within it.
@maxtacco what's the difference between a Component and a HTML element / tag? From my understanding of the source code, each Component maps 1:1 to a HTML element (tag).
@tommedema If you talk about pure HTML, then yes, that's the case I think. But, I work on some custom Angular components that encapsulate a number of HTML elements but should be viewed as a single unit. This may also apply to some React components (may be web components one day) as well.
@maxtacco browsers only read HTML + CSS; if you use angular, react.js, etc., they will ultimately write html elements to the document. Are you sure that GrapeJS tries to accommodate for Angular/react components? They way I understand it from reading the source code it doesn't do this. Also doesn't seem very reasonable to me; since it's not manageable to support every popular javascript framework, but it is manageable to support HTML / browser standards.
Also, from looking at the source it seems relatively simple to change the behavior to display the element's tag name by default rather than its type. Question therefore remains if this is preferred. I could create a PR to accommodate for this. Alternative is something like tagname (type), e.g. span (text) or div (box)
@tommedema The beauty of GrapesJS is that it can support any type of templates. They don't have to be limited to pure HTML/CSS. Out of the box it doesn't provide any integration with Angular/React - in fact it would be a mistake to do so. Instead it has a nice layer of abstractions, such as Component for example, that allow one to build templates in any desired format. Also, it is up to the implementor to do so. @artf has a number of examples though that can give one idea of how other formats can be supported by use of plugins. Here is MJML example - https://github.com/artf/grapesjs-mjml and here is one for Bootstrap - https://github.com/z1lk/grapesjs-blocks-bootstrap4. Again, you are looking at GrapesGS as HTML/CSS only solution, but it can be used to design templates in many other formats using any number of custom components. Note: I don't have any affiliation with GrapesJS, this is just my personal opinion.
@maxtacco I see, that does make sense. I will keep this in mind; perhaps I can write a plugin for "html output"?
My goal is indeed to have a HTML/CSS WYSIWYG editor. I wonder if I could write a plugin that would set the layer names as tag names.
Just take a look at other @artf's repos. For example, https://github.com/artf/grapesjs-preset-webpage is a good starting point for HTML/CSS solution. These plugins are really useful too for HTML/CSS: https://github.com/artf/grapesjs-plugin-ckeditor, https://github.com/artf/grapesjs-blocks-basic and https://github.com/artf/grapesjs-plugin-forms.
I'm not sure if you will be able to modify Layer Manager to display tags in the format you want without making changes to GrapesJS core. But, I think it could be a nice enhancement to provide a way to customize Layer Manager's tree node display using some kind of config hook.
Thanks but these are mostly related to adding more kinds of html blocks, which is not a problem I am facing at the moment. It would be better for the core to be flexible enough through plugins such that it is not necessary to add additional configuration to it to customize the tree node display. I will close this for now and come back to it once I have figured out a solution.
Btw, it looks like Layer Manager uses Component's https://github.com/artf/grapesjs/blob/49100b2f63411fb08d438d21a5f7ff9131773a75/src/dom_components/model/Component.js#L35 property when rendering tree node in https://github.com/artf/grapesjs/blob/49100b2f63411fb08d438d21a5f7ff9131773a75/src/navigator/view/ItemView.js#L28. I would create a config option in https://github.com/artf/grapesjs/blob/dev/src/navigator/config/config.js that could be set to 'name' by default and then use that option when getting tree node value from component's model. Hope this helps.
@maxtacco thanks I will use that when I create a PR
@maxtacco thanks I will use that when I create a PR
Can we have any update on this ? How we should rename the layer manager blocks ?
Thanks Suresh.N
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.