ckeditor5 1.1.1 → 1.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ba0f56261f0c699d67fce659fe6cd4cbc3fc2f288ebedf0fd908f4f6d9555001
4
- data.tar.gz: 9c5b41693f3858a94841b7e6392bbd573a3bc83c3a936c7dd2fbdcfff42fda63
3
+ metadata.gz: a1a9231d02fc433d84940be1d9dff62a4a32a24101a0d383374dd5ce41789fdb
4
+ data.tar.gz: 58f7b1f2c6ebc373a80f8aacd1720f712f6b3b2df3501bfae8185c2f25ab6c9a
5
5
  SHA512:
6
- metadata.gz: e12b59365223eeeee6cccef5e771ae2df9e17e9500275a871c8f7b41b6a39abe0cec725848f887ead1a3235d2d50447fdb8b99ead940d1dc50c5f795369d9354
7
- data.tar.gz: b163824d28f9867b0bee31e273e5b0be6ad380891d43a1e48ed1fb4df0c38460a4cfddc5fcb7fdf1fa1430950b6cd3d47a6c4cbcf8c4067f5178660f6c991d15
6
+ metadata.gz: 660761eb62fcd75e55f59c4a4f06115ed7d523aefeedde9d78a288cfced67170bb8ddddeb8f0c18a0d61267a05882df2c01e5b6689a0f0109aca7ce5aed31565
7
+ data.tar.gz: acf7b3c7999b4524e096a49e70522cb029d7d54ebb470605c89552f6de35c89d5d828e34fa59c9f106d2ad041295a8ec019821ba84f23b89a6fc81c3e3e4d9ef
data/README.md CHANGED
@@ -74,23 +74,23 @@ Voilà! You have CKEditor 5 integrated with your Rails application. 🎉
74
74
  - [GPL usage 🆓](#gpl-usage-)
75
75
  - [Commercial usage 💰](#commercial-usage-)
76
76
  - [Editor placement 🏗️](#editor-placement-️)
77
+ - [Setting Initial Content 📝](#setting-initial-content-)
77
78
  - [Classic editor 📝](#classic-editor-)
78
79
  - [Multiroot editor 🌳](#multiroot-editor-)
79
80
  - [Inline editor 📝](#inline-editor-)
80
81
  - [Balloon editor 🎈](#balloon-editor-)
81
82
  - [Decoupled editor 🌐](#decoupled-editor-)
82
83
  - [How to access editor instance? 🤔](#how-to-access-editor-instance-)
83
- - [Events fired by the editor 🔊](#events-fired-by-the-editor-)
84
- - [`editor-ready` event](#editor-ready-event)
85
- - [`editor-error` event](#editor-error-event)
86
84
  - [Common Tasks and Solutions 💡](#common-tasks-and-solutions-)
87
- - [Setting Initial Content 📝](#setting-initial-content-)
88
85
  - [Setting Editor Language 🌐](#setting-editor-language-)
89
86
  - [Integrating with Forms 📋](#integrating-with-forms-)
90
87
  - [Rails form builder integration](#rails-form-builder-integration)
91
88
  - [Simple form integration](#simple-form-integration)
92
89
  - [Custom Styling 🎨](#custom-styling-)
93
90
  - [Custom plugins 🧩](#custom-plugins-)
91
+ - [Events fired by the editor 🔊](#events-fired-by-the-editor-)
92
+ - [`editor-ready` event](#editor-ready-event)
93
+ - [`editor-error` event](#editor-error-event)
94
94
  - [License 📜](#license-)
95
95
 
96
96
  ## Presets 🎨
@@ -583,6 +583,28 @@ In this scenario, the assets are included from the official CKEditor 5 CDN which
583
583
 
584
584
  The `ckeditor5_editor` helper renders CKEditor 5 instances in your views. Before using it, ensure you've included the necessary assets in your page's head section otherwise the editor won't work as there are no CKEditor 5 JavaScript and CSS files loaded.
585
585
 
586
+ ### Setting Initial Content 📝
587
+
588
+ You can set the initial content of the editor using the `initial_data` keyword argument or by passing the content directly to the `ckeditor5_editor` helper block.
589
+
590
+ The example below shows how to set the initial content of the editor using the `initial_data` keyword argument:
591
+
592
+ ```erb
593
+ <!-- app/views/demos/index.html.erb -->
594
+
595
+ <%= ckeditor5_editor initial_data: "<p>Initial content</p>" %>
596
+ ```
597
+
598
+ The example below shows how to set the initial content of the editor using the `ckeditor5_editor` helper block.
599
+
600
+ ```erb
601
+ <!-- app/views/demos/index.html.erb -->
602
+
603
+ <%= ckeditor5_editor do %>
604
+ <p>Initial content</p>
605
+ <% end %>
606
+ ```
607
+
586
608
  ### Classic editor 📝
587
609
 
588
610
  The classic editor is the most common type of editor. It provides a toolbar with various formatting options like bold, italic, underline, and link.
@@ -776,40 +798,14 @@ document.getElementById('editor').runAfterEditorReady(editor => {
776
798
  });
777
799
  ```
778
800
 
779
- ## Events fired by the editor 🔊
780
-
781
- ### `editor-ready` event
782
-
783
- The event is fired when the initialization of the editor is completed. You can listen to it using the `editor-ready` event.
784
-
785
- ```js
786
- document.getElementById('editor').addEventListener('editor-ready', () => {
787
- console.log('Editor is ready');
788
- });
789
- ```
790
-
791
- ### `editor-error` event
792
-
793
- The event is fired when the initialization of the editor fails. You can listen to it using the `editor-error` event.
794
-
795
- ```js
796
- document.getElementById('editor').addEventListener('editor-error', () => {
797
- console.log('Editor has an error');
798
- });
799
- ```
800
-
801
801
  ## Common Tasks and Solutions 💡
802
802
 
803
803
  This section covers frequent questions and scenarios when working with CKEditor 5 in Rails applications.
804
804
 
805
- ### Setting Initial Content 📝
806
-
807
- ```erb
808
- <%= ckeditor5_editor initial_data: "<p>Initial content</p>" %>
809
- ```
810
-
811
805
  ### Setting Editor Language 🌐
812
806
 
807
+ You can set the language of the editor using the `language` method in the `config/initializers/ckeditor5.rb` file. The `translations` method fetches the translations files, while the `language` method sets the default language of the editor.
808
+
813
809
  ```rb
814
810
  config.presets.override :default do
815
811
  translations :pl, :es
@@ -819,9 +815,13 @@ end
819
815
 
820
816
  ### Integrating with Forms 📋
821
817
 
818
+ You can integrate CKEditor 5 with Rails form builders like `form_for` or `simple_form`. The example below shows how to integrate CKEditor 5 with a Rails form using the `form_for` helper:
819
+
822
820
  #### Rails form builder integration
823
821
 
824
822
  ```erb
823
+ <!-- app/views/demos/index.html.erb -->
824
+
825
825
  <%= form_for @post do |f| %>
826
826
  <%= f.label :content %>
827
827
  <%= f.ckeditor5 :content, required: true, style: 'width: 700px', initial_data: 'Hello World!' %>
@@ -831,6 +831,8 @@ end
831
831
  #### Simple form integration
832
832
 
833
833
  ```erb
834
+ <!-- app/views/demos/index.html.erb -->
835
+
834
836
  <%= simple_form_for :demo, url: '/demos', html: { novalidate: false } do |f| %>
835
837
  <div class="form-group">
836
838
  <%= f.input :content, as: :ckeditor5, initial_data: 'Hello, World 12!', input_html: { style: 'width: 600px' }, required: true %>
@@ -844,8 +846,12 @@ end
844
846
 
845
847
  ### Custom Styling 🎨
846
848
 
849
+ You can pass the `style`, `class` and `id` keyword arguments to the `ckeditor5_editor` helper to define the styling of the editor. The example below shows how to set the height, margin, and CSS class of the editor:
850
+
847
851
  ```erb
848
- <%= ckeditor5_editor style: 'height: 400px; margin: 20px;' %>
852
+ <!-- app/views/demos/index.html.erb -->
853
+
854
+ <%= ckeditor5_editor style: 'height: 400px; margin: 20px;', class: 'your_css_class', id: 'your_id' %>
849
855
  ```
850
856
 
851
857
  ### Custom plugins 🧩
@@ -1018,6 +1024,28 @@ class HighlightCommand extends Command {
1018
1024
 
1019
1025
  </details>
1020
1026
 
1027
+ ## Events fired by the editor 🔊
1028
+
1029
+ ### `editor-ready` event
1030
+
1031
+ The event is fired when the initialization of the editor is completed. You can listen to it using the `editor-ready` event.
1032
+
1033
+ ```js
1034
+ document.getElementById('editor').addEventListener('editor-ready', () => {
1035
+ console.log('Editor is ready');
1036
+ });
1037
+ ```
1038
+
1039
+ ### `editor-error` event
1040
+
1041
+ The event is fired when the initialization of the editor fails. You can listen to it using the `editor-error` event.
1042
+
1043
+ ```js
1044
+ document.getElementById('editor').addEventListener('editor-error', () => {
1045
+ console.log('Editor has an error');
1046
+ });
1047
+ ```
1048
+
1021
1049
  ## License 📜
1022
1050
 
1023
1051
  The MIT License (MIT)
@@ -51,12 +51,17 @@ class CKEditorComponent extends HTMLElement {
51
51
  /** @type {Record<string, HTMLElement>} Map of editable elements by name */
52
52
  editables = {};
53
53
 
54
+ /** @type {String} Initial HTML passed to component */
55
+ #initialHTML = '';
56
+
54
57
  /**
55
58
  * Lifecycle callback when element is connected to DOM
56
59
  * Initializes the editor when DOM is ready
57
60
  * @protected
58
61
  */
59
62
  connectedCallback() {
63
+ this.#initialHTML = this.innerHTML;
64
+
60
65
  try {
61
66
  execIfDOMReady(() => this.#reinitializeEditor());
62
67
  } catch (error) {
@@ -179,7 +184,7 @@ class CKEditorComponent extends HTMLElement {
179
184
  this.style.display = 'block';
180
185
 
181
186
  if (!this.isMultiroot() && !this.isDecoupled()) {
182
- this.innerHTML = `<${this.#editorElementTag}></${this.#editorElementTag}>`;
187
+ this.innerHTML = `<${this.#editorElementTag}>${this.#initialHTML}</${this.#editorElementTag}>`;
183
188
  this.#assignInputAttributes();
184
189
  }
185
190
 
@@ -305,6 +310,7 @@ class CKEditorComponent extends HTMLElement {
305
310
  const syncInput = () => {
306
311
  this.style.position = 'relative';
307
312
 
313
+ textarea.innerHTML = '';
308
314
  textarea.value = this.instance.getData();
309
315
  textarea.tabIndex = -1;
310
316
 
@@ -24,14 +24,15 @@ module CKEditor5::Rails
24
24
  config = config.deep_merge(extra_config)
25
25
  config[:initialData] = initial_data if initial_data
26
26
 
27
+ raise ArgumentError, 'Cannot pass initial data and block at the same time.' if initial_data && block
28
+
27
29
  editor_props = build_editor_props(
28
30
  config: config,
29
31
  type: type,
30
32
  context: context
31
33
  )
32
34
 
33
- render_editor_component(editor_props, html_attributes,
34
- &(%i[multiroot decoupled].include?(type) ? block : nil))
35
+ render_editor_component(editor_props, html_attributes, &block)
35
36
  end
36
37
 
37
38
  def ckeditor5_editable(name = nil, **kwargs, &block)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CKEditor5::Rails
4
- VERSION = '1.1.1'
4
+ VERSION = '1.1.3'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ckeditor5
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mateusz Bagiński