ckeditor5 1.1.0 → 1.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +37 -0
- data/lib/ckeditor5/rails/assets/webcomponent.mjs +6 -1
- data/lib/ckeditor5/rails/editor/helpers.rb +3 -2
- data/lib/ckeditor5/rails/presets.rb +15 -11
- data/lib/ckeditor5/rails/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0aee8586159157d2581cefe62cc87ea58d822db618c0f0dd9ceee5c0d3fdba46
|
4
|
+
data.tar.gz: 550633bd1bb74e54909f19447f7ced3bff0f6bd10324b44c9076641eb65e08e7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ba63dc4631e0703b8d719b7b2c21efc97183455550e6eb6406f96f8e789baaf1ed7dd202d0711ca100f39e906b386c026ef8515042d6441bce465baf6de8b10a
|
7
|
+
data.tar.gz: 15a0df8fd18291bc5d47e9a15df2d0192316512b38a85ec07c4bc047895d1111a6bd92afa2c09bdab639f31485a039538d7390048e39d66ea22bf51373e22e38
|
data/README.md
CHANGED
@@ -138,6 +138,13 @@ In order to override existing presets, you can use the `config.presets.override`
|
|
138
138
|
CKEditor5::Rails::Engine.configure do |config|
|
139
139
|
config.presets.override :default do
|
140
140
|
menubar visible: false
|
141
|
+
|
142
|
+
toolbar do
|
143
|
+
remove :underline, :heading
|
144
|
+
|
145
|
+
# prepend :underline
|
146
|
+
# append :heading
|
147
|
+
end
|
141
148
|
end
|
142
149
|
end
|
143
150
|
```
|
@@ -305,6 +312,20 @@ config.presets.override :default do
|
|
305
312
|
end
|
306
313
|
```
|
307
314
|
|
315
|
+
If you want to remove items from the toolbar, you can use the `remove` method:
|
316
|
+
|
317
|
+
```rb
|
318
|
+
# config/initializers/ckeditor5.rb
|
319
|
+
|
320
|
+
config.presets.override :default do
|
321
|
+
# ... other configuration
|
322
|
+
|
323
|
+
toolbar do
|
324
|
+
remove :selectAll, :heading #, ...
|
325
|
+
end
|
326
|
+
end
|
327
|
+
```
|
328
|
+
|
308
329
|
#### `menubar(visible: true)` method
|
309
330
|
|
310
331
|
Defines the visibility of the menubar. By default, it's set to `true`.
|
@@ -783,12 +804,26 @@ This section covers frequent questions and scenarios when working with CKEditor
|
|
783
804
|
|
784
805
|
### Setting Initial Content 📝
|
785
806
|
|
807
|
+
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.
|
808
|
+
|
809
|
+
The example below shows how to set the initial content of the editor using the `initial_data` keyword argument:
|
810
|
+
|
786
811
|
```erb
|
787
812
|
<%= ckeditor5_editor initial_data: "<p>Initial content</p>" %>
|
788
813
|
```
|
789
814
|
|
815
|
+
The example below shows how to set the initial content of the editor using the `ckeditor5_editor` helper block.
|
816
|
+
|
817
|
+
```erb
|
818
|
+
<%= ckeditor5_editor do %>
|
819
|
+
<p>Initial content</p>
|
820
|
+
<% end %>
|
821
|
+
```
|
822
|
+
|
790
823
|
### Setting Editor Language 🌐
|
791
824
|
|
825
|
+
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.
|
826
|
+
|
792
827
|
```rb
|
793
828
|
config.presets.override :default do
|
794
829
|
translations :pl, :es
|
@@ -798,6 +833,8 @@ end
|
|
798
833
|
|
799
834
|
### Integrating with Forms 📋
|
800
835
|
|
836
|
+
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:
|
837
|
+
|
801
838
|
#### Rails form builder integration
|
802
839
|
|
803
840
|
```erb
|
@@ -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}
|
187
|
+
this.innerHTML = `<${this.#editorElementTag}>${this.#initialHTML}</${this.#editorElementTag}>`;
|
183
188
|
this.#assignInputAttributes();
|
184
189
|
}
|
185
190
|
|
@@ -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)
|
@@ -187,29 +187,33 @@ module CKEditor5::Rails
|
|
187
187
|
@toolbar_config = toolbar_config
|
188
188
|
end
|
189
189
|
|
190
|
-
def
|
191
|
-
|
190
|
+
def items
|
191
|
+
@toolbar_config[:items]
|
192
|
+
end
|
193
|
+
|
194
|
+
def remove(*removed_items)
|
195
|
+
removed_items.each { |item| items.delete(item) }
|
196
|
+
end
|
192
197
|
|
198
|
+
def prepend(*prepended_items, before: nil)
|
193
199
|
if before
|
194
|
-
index =
|
200
|
+
index = items.index(before)
|
195
201
|
raise ArgumentError, "Item '#{before}' not found in toolbar" unless index
|
196
202
|
|
197
|
-
|
203
|
+
items.insert(index, *prepended_items)
|
198
204
|
else
|
199
|
-
|
205
|
+
items.insert(0, *prepended_items)
|
200
206
|
end
|
201
207
|
end
|
202
208
|
|
203
|
-
def append(*
|
204
|
-
toolbar_items = @toolbar_config[:items]
|
205
|
-
|
209
|
+
def append(*appended_items, after: nil)
|
206
210
|
if after
|
207
|
-
index =
|
211
|
+
index = items.index(after)
|
208
212
|
raise ArgumentError, "Item '#{after}' not found in toolbar" unless index
|
209
213
|
|
210
|
-
|
214
|
+
items.insert(index + 1, *appended_items)
|
211
215
|
else
|
212
|
-
|
216
|
+
items.push(*appended_items)
|
213
217
|
end
|
214
218
|
end
|
215
219
|
end
|