ckeditor5 icon indicating copy to clipboard operation
ckeditor5 copied to clipboard

Is having `definitions.xxx.classes` mandatory by intention?

Open garvinhicking opened this issue 1 year ago • 7 comments

📝 Ask a question

Having a configuration like this (asking for the context of a default TYPO3 implementation):

editor:
  config:
    style:
      definitions:
        # block level styles
        - { name: 'Orange title H2', element: 'h2', classes: ['orange'] }
        - { name: 'Orange title H3', element: 'h3', classes: ['orange'] }
        - { name: 'Quote / Citation', element: 'blockquote', classes: [''] }
        - { name: 'Code block', element: 'code', classes: ['']  }
        # Inline styles
        - { name: 'Yellow marker', element: 'span', classes: ['yellow-marker'] }

it seems that classes is a required attribute. Also https://ckeditor.com/docs/ckeditor5/latest/api/module_style_styleconfig-StyleDefinition.html does not really mention it as being optional. Leaving such an attribute out leads to the dropdown for styles not getting opened.

If the attribute is required, I wonder how one could implement an empty <code> element. Currently, always <code class=""> is emitted.

Also, when using classes: [] to indicate an empty array, the element is not choosable at all. Using classes: false|null|true only leads to having <code class="false|null|true">.

So I wonder, am I missing something here, or would it classify as a bug?

garvinhicking avatar Jul 16 '24 15:07 garvinhicking

For now Style dropdown doesn't insert elements, it just adds classes to existing elements. Most likely, you would want it to insert as well, +1 the following ticket #14372.

Witoso avatar Sep 19 '24 06:09 Witoso

The issue lacks the feedback we asked for two weeks. Hence, we've marked it as stale and will close it in 30 days. We understand it may still be relevant, so if you're interested in the solution, leave a comment or reaction under this issue.

CKEditorBot avatar Oct 03 '24 23:10 CKEditorBot

Which feedback did you ask?! Happy to provide any.

garvinhicking avatar Oct 04 '24 05:10 garvinhicking

Just let us know if the ticket we sent is something that covers your need, and we will close this one as a duplicate :)

Witoso avatar Oct 04 '24 06:10 Witoso

Ah I see! I just saw this as related, not a duplicate.

If I understand correctly, the other issue is about properly getting the "context" of the style dropdown and allowing to insert new elements when inside the context of another?

My issue here is about the ability to insert "pure" elements, without requiring an (empty) class selector.

IMO those two are distinct issues, but then again I'm not deep into the code 😇

garvinhicking avatar Oct 04 '24 07:10 garvinhicking

Then I wonder why not use a proper button of the feature like code? Multiple access points to insert the same thing could be confusing, and I'm curious what's the use case and your thoughts here.

Witoso avatar Oct 07 '24 07:10 Witoso

The reason is to group style-related custom choices in a single "point of truth", which would be the style dropdown.

Also, emitting <div class=""> as it is currently really looks odd and more like a bug than intention.

garvinhicking avatar Oct 07 '24 08:10 garvinhicking

There has been no activity on this issue for the past year. We've marked it as stale and will close it in 30 days. We understand it may still be relevant, so if you're interested in the solution, leave a comment or reaction under this issue.

CKEditorBot avatar Oct 07 '25 23:10 CKEditorBot

Yes I still think there is a use case for it and an empty class (=no class attribute) would be beneficial. Happy to hear feedback on my last post/comment.

I'm trying to maintain CKEditor foe the TYPO3 Core so I would need a more "final" say for this to be able to communicate to our community, because every now and the I need to point people to this issue. Thanks!

garvinhicking avatar Oct 08 '25 05:10 garvinhicking

There are a couple of things here that we’re considering for next year’s plan (cc @Reinmar).

The current Style feature needs a rethink. It’s based on the GHS compatibility layer, and this coupling makes it difficult to evolve. The entire premise of inserting new elements wasn’t part of the original design. At the same time, we want to improve HTML interoperability, e.g. div support (#6462), and possibly extend it in other directions.

I believe @niegowski once proposed flipping the architecture, where editor features would register themselves with the Style feature to define what attributes to apply, and in turn, the Style feature would know what to insert.

All in all, the topic is in our head, but no precise plan yet.

Witoso avatar Oct 08 '25 07:10 Witoso

Thank you, that helps me a lot. Feel free to close this issue then if it's part of something else to address. I'll notice it then :-)

garvinhicking avatar Oct 08 '25 08:10 garvinhicking