Mati365 / ckeditor5-rails

πŸš€ CKEditor 5 Ruby gem - seamless integration with Rails through web components and helper methods. πŸ’Ž Supports both GPL and commercial licenses with flexible CDN options and translations. 🎨 Easy configuration with presets, extensive plugin system, and modern async loading.
https://ckeditor.com/
GNU General Public License v2.0
21 stars 1 forks source link

Presets with inherit: false Not Working as Expected #4

Closed dil-bparihar closed 2 weeks ago

dil-bparihar commented 2 weeks ago

πŸ› Bug Report

Presets with inherit: false Not Working as Expected

πŸ” Bug Description

I am encountering an issue when defining multiple CKEditor 5 presets with different toolbars and plugins. Specifically, when I define presets with inherit: false, only the first preset (which doesn't use inherit: false) is being applied correctly, and all other presets are ignored, regardless of the preset name used in the HTML for ckeditor5_assets.

The presets are not being loaded or rendered as configured when inherit: false is specified, even though the rest of the code seems correct. Here’s the sample code I am using for the presets configuration:

CKEditor5::Rails.configure do
  version '43.3.0'

  presets.define :custom do
     # Define the toolbar items
     toolbar :sourceEditing, :undo, :redo, :|, :bold, :italic, :underline, :strikethrough, :subscript, :superscript, :removeFormat, :|, 
     :findAndReplace, :selectAll, :|, :heading, :|, :bulletedList, :numberedList, :todoList, :outdent, :indent, :|, 
     :alignment, :blockQuote, :link, :insertTable, :imageUpload, :horizontalLine, :mediaEmbed, :|, 
     :fontFamily, :fontSize, :fontColor, :fontBackgroundColor
     plugins :Essentials, :Paragraph, :Heading, :FindAndReplace, :SelectAll, :Bold, :Italic, :Underline, :Strikethrough, :RemoveFormat, :Subscript, 
            :Superscript, :Alignment, :Link, :LinkImage, :BlockQuote, :Image, :ImageUpload, :ImageToolbar, :ImageInsert, 
            :ImageInsertViaUrl, :ImageBlock, :ImageCaption, :ImageInline, :ImageResize, :HorizontalLine, :Table, :TableToolbar, 
            :TableCaption, :TableProperties, :TableCellProperties, :TableColumnResize, :List, :ListProperties, :TodoList, 
            :MediaEmbed, :Font, :FontFamily, :FontSize, :FontColor, :FontBackgroundColor, :Indent, :IndentBlock, 
            :PasteFromOffice, :AutoImage, :Autosave, :CloudServices, :SourceEditing, :TextTransformation
  end

  presets.define :basic, inherit: false do
    version '43.3.0'

    toolbar :sourceEditing, :|, :cut, :copy, :|, :undo, :redo, :|,
            :findAndReplace, :selectAll, :|, :bold, :italic, :underline, :strikethrough, 
            :subscript, :superscript, :removeFormat, :|, :bulletedList, :numberedList, 
            :outdent, :indent, :blockQuote, :|, :alignment, :link, :anchor, :|, 
            :insertTable, :horizontalLine, :|, :fontFamily, :fontSize, :heading, :|, :fontColor, :fontBackgroundColor

    plugins :Essentials, :Paragraph, :Heading, :Bold, :Italic, :Underline, :Strikethrough, 
            :Subscript, :Superscript, :RemoveFormat, :FindAndReplace, :SelectAll, :Alignment, 
            :List, :Indent, :BlockQuote, :Link, :Table, :TableToolbar, :HorizontalLine, 
            :Font, :FontFamily, :FontSize, :FontColor, :FontBackgroundColor, :SourceEditing
  end

  presets.define :ultrabasic, inherit: false do
    version '43.3.0'

    toolbar :sourceEditing, :|, :bold, :italic, :underline, :strikethrough, 
            :subscript, :superscript, :removeFormat, :|, :bulletedList, :numberedList, 
            :fontFamily, :fontSize, :|, :link, :anchor, :|, 
            :fontColor, :fontBackgroundColor

    plugins :Essentials, :Paragraph, :Bold, :Italic, :Underline, :Strikethrough, 
            :Subscript, :Superscript, :RemoveFormat, :List, :Link, :Font, 
            :FontFamily, :FontSize, :FontColor, :FontBackgroundColor, :SourceEditing, :Essentials, :Paragraph
  end
end

πŸ“ Steps to Reproduce

  1. Define multiple presets with different configurations, including inherit: false.
  2. In the HTML file for ckeditor5_assets, change the preset name to reference any of the presets that use inherit: false.
  3. Observe that only the first preset works and the rest are ignored.

βœ… Expected Behavior

A clear and concise description of what you expected to happen.

  1. All the presets defined should be accessible and load properly when referenced in the HTML.
  2. Each preset should apply its specific toolbar and plugin configuration.

❌ Actual Behavior

  1. Only the first preset (without inherit: false) works as expected.
  2. Any preset defined with inherit: false does not render or apply the expected toolbar and plugin configuration.

πŸ“Έ Screenshots

If applicable, add screenshots to help explain your problem.

πŸ“‹ Additional Context

Mati365 commented 2 weeks ago

Thanks for report, I'll check that.

Mati365 commented 2 weeks ago

@dil-bparihar It looks like it works correctly, maybe I have to update docs. The problem is that you have to specify preset in ckeditor5_editor instead of ckeditor5_assets. ckeditor5_assets uses presets only to determine if ckbox or premium features need to be loaded, other configuration of preset is ignored in resource loader, and preset is no longer forwarded to ckeditor5_editor. In other words:

:x: Bad

- content_for :head
  = ckeditor5_assets preset: :basic

= ckeditor5_editor do
  | Hello World

This ckeditor5_editor will use default preset, but ckeditor5_assets will try to determine if premium assets should be loaded based on basic preset.

:heavy_check_mark: Good

- content_for :head
  = ckeditor5_assets preset: :basic

= ckeditor5_editor preset: :basic do
  | Hello World

or even

- content_for :head
  = ckeditor5_assets premium: <set proper flag to true if any of the editors use premium features>

= ckeditor5_editor preset: :basic do
  | Hello World

= ckeditor5_editor preset: :advanced do
  | Hello World

I changed this behavior in 1.6.1 version, please see comment below.

Mati365 commented 2 weeks ago

@dil-bparihar I updated this behavior, now preset should be inherited from ckeditor5_assets if it's used in nested editors. It can be overridden, though. Please install 1.6.1 version.

βœ… So now this behavior is correct:

- content_for :head
  = ckeditor5_assets preset: :basic

# This one will use `:basic` preset
= ckeditor5_editor do
  | Hello World
dil-bparihar commented 2 weeks ago

Thanks it is working now