ckeditor5 1.12.0 → 1.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +46 -2
- data/lib/ckeditor5/rails/editor/props_inline_plugin.rb +2 -2
- data/lib/ckeditor5/rails/editor/props_plugin.rb +2 -4
- data/lib/ckeditor5/rails/engine.rb +1 -0
- data/lib/ckeditor5/rails/plugins/simple_upload_adapter.rb +80 -0
- data/lib/ckeditor5/rails/presets/manager.rb +2 -1
- data/lib/ckeditor5/rails/presets/plugins_builder.rb +49 -0
- data/lib/ckeditor5/rails/presets/preset_builder.rb +23 -4
- data/lib/ckeditor5/rails/presets/toolbar_builder.rb +5 -7
- data/lib/ckeditor5/rails/version.rb +1 -1
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6b4d6c95733dd5744553bb787f20f9efaf474086c6268d6842561905747ec10f
|
4
|
+
data.tar.gz: 17052fae7a4e0e88fcc7c0af8ab397c8fadb3421ce611c64a10fe597d15a9d82
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4dbaefb77863ceaeaad0805d430c86b90c7fbec675a7478fc55994a9706bfc3b8ec59c7791ce916389346da508f47a88ce2ff8c38a79d1c9189aa77405769f9f
|
7
|
+
data.tar.gz: 6b1d599bbfe28b35c81d037b052085c15fe55c1248f8e858efc77b7515c88b5ea2818187082f0db7810192b7d2cdfd3bb45d3dba57f7cf03cd0f53932dfbb202
|
data/README.md
CHANGED
@@ -85,9 +85,10 @@ Voilà! You have CKEditor 5 integrated with your Rails application. 🎉
|
|
85
85
|
- [`plugin(name, premium:, import_name:)` method](#pluginname-premium-import_name-method)
|
86
86
|
- [`plugins(*names, **kwargs)` method](#pluginsnames-kwargs-method)
|
87
87
|
- [`inline_plugin(name, code)` method](#inline_pluginname-code-method)
|
88
|
+
- [`simple_upload_adapter(url)` method](#simple_upload_adapterurl-method)
|
88
89
|
- [Controller / View helpers 📦](#controller--view-helpers-)
|
89
90
|
- [`ckeditor5_element_ref(selector)` method](#ckeditor5_element_refselector-method)
|
90
|
-
|
91
|
+
- [`ckeditor5_preset(&block)` method](#ckeditor5_presetblock-method)
|
91
92
|
- [Including CKEditor 5 assets 📦](#including-ckeditor-5-assets-)
|
92
93
|
- [Format 📝](#format-)
|
93
94
|
- [Using default preset](#using-default-preset)
|
@@ -534,6 +535,20 @@ CKEditor5::Rails.configure do
|
|
534
535
|
end
|
535
536
|
```
|
536
537
|
|
538
|
+
Methods such as `remove`, `append`, and `prepend` can be used to modify the plugins configuration. To remove a plugin, you can use the `remove` method with the plugin name as an argument:
|
539
|
+
|
540
|
+
```rb
|
541
|
+
# config/initializers/ckeditor5.rb
|
542
|
+
|
543
|
+
CKEditor5::Rails.configure do
|
544
|
+
# ... other configuration
|
545
|
+
|
546
|
+
plugins do
|
547
|
+
remove :Heading
|
548
|
+
end
|
549
|
+
end
|
550
|
+
```
|
551
|
+
|
537
552
|
#### `inline_plugin(name, code)` method
|
538
553
|
|
539
554
|
Use with caution as this is an inline definition of the plugin code, and you can define a custom class or function for the plugin here. The example below shows how to define a custom plugin that highlights the text:
|
@@ -560,6 +575,35 @@ CKEditor5::Rails.configure do
|
|
560
575
|
end
|
561
576
|
```
|
562
577
|
|
578
|
+
#### `simple_upload_adapter(url)` method
|
579
|
+
|
580
|
+
Defines the URL for the simple upload adapter. The default endpoint is `/uploads` and the method is `POST`. The example below shows how to set the URL to `/uploads`:
|
581
|
+
|
582
|
+
```rb
|
583
|
+
# config/initializers/ckeditor5.rb
|
584
|
+
|
585
|
+
CKEditor5::Rails.configure do
|
586
|
+
# ... other configuration
|
587
|
+
|
588
|
+
simple_upload_adapter
|
589
|
+
# or: simple_upload_adapter '/uploads'
|
590
|
+
end
|
591
|
+
```
|
592
|
+
|
593
|
+
Remember to remove the `Base64UploadAdapter` plugin from the plugins list if you want to use the simple upload adapter. It may cause issues.
|
594
|
+
|
595
|
+
```rb
|
596
|
+
# config/initializers/ckeditor5.rb
|
597
|
+
|
598
|
+
CKEditor5::Rails.configure do
|
599
|
+
# ... other configuration
|
600
|
+
|
601
|
+
plugins do
|
602
|
+
remove :Base64UploadAdapter
|
603
|
+
end
|
604
|
+
end
|
605
|
+
```
|
606
|
+
|
563
607
|
### Controller / View helpers 📦
|
564
608
|
|
565
609
|
#### `ckeditor5_element_ref(selector)` method
|
@@ -578,7 +622,7 @@ CKEditor5::Rails.configure do
|
|
578
622
|
end
|
579
623
|
```
|
580
624
|
|
581
|
-
|
625
|
+
#### `ckeditor5_preset(&block)` method
|
582
626
|
|
583
627
|
The `ckeditor5_preset` method allows you to define a custom preset in your application controller. It may be useful when you want to define a preset based on the current user or request.
|
584
628
|
|
@@ -2,6 +2,8 @@
|
|
2
2
|
|
3
3
|
module CKEditor5::Rails::Editor
|
4
4
|
class PropsInlinePlugin
|
5
|
+
attr_reader :name, :code
|
6
|
+
|
5
7
|
def initialize(name, code)
|
6
8
|
@name = name
|
7
9
|
@code = code
|
@@ -18,8 +20,6 @@ module CKEditor5::Rails::Editor
|
|
18
20
|
|
19
21
|
private
|
20
22
|
|
21
|
-
attr_reader :name, :code
|
22
|
-
|
23
23
|
def validate_code!
|
24
24
|
raise ArgumentError, 'Code must be a String' unless code.is_a?(String)
|
25
25
|
|
@@ -2,6 +2,8 @@
|
|
2
2
|
|
3
3
|
module CKEditor5::Rails::Editor
|
4
4
|
class PropsPlugin
|
5
|
+
attr_reader :name, :js_import_meta
|
6
|
+
|
5
7
|
delegate :to_h, to: :import_meta
|
6
8
|
|
7
9
|
def initialize(name, premium: false, **js_import_meta)
|
@@ -30,9 +32,5 @@ module CKEditor5::Rails::Editor
|
|
30
32
|
meta.merge!({ type: :external })
|
31
33
|
meta
|
32
34
|
end
|
33
|
-
|
34
|
-
private
|
35
|
-
|
36
|
-
attr_reader :name, :js_import_meta
|
37
35
|
end
|
38
36
|
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module CKEditor5::Rails::Plugins
|
4
|
+
class SimpleUploadAdapter < CKEditor5::Rails::Editor::PropsInlinePlugin
|
5
|
+
PLUGIN_CODE = <<~JAVASCRIPT
|
6
|
+
import { Plugin, FileRepository } from 'ckeditor5';
|
7
|
+
|
8
|
+
export default class SimpleUploadAdapter extends Plugin {
|
9
|
+
static get requires() {
|
10
|
+
return [FileRepository];
|
11
|
+
}
|
12
|
+
|
13
|
+
static get pluginName() {
|
14
|
+
return 'SimpleUploadAdapter';
|
15
|
+
}
|
16
|
+
|
17
|
+
init() {
|
18
|
+
const fileRepository = this.editor.plugins.get(FileRepository);
|
19
|
+
const config = this.editor.config.get('simpleUpload');
|
20
|
+
|
21
|
+
if (!config || !config.uploadUrl) {
|
22
|
+
console.warn('Upload URL is not configured');
|
23
|
+
return;
|
24
|
+
}
|
25
|
+
|
26
|
+
fileRepository.createUploadAdapter = (loader) => ({
|
27
|
+
async upload() {
|
28
|
+
try {
|
29
|
+
const file = await loader.file;
|
30
|
+
const formData = new FormData();
|
31
|
+
formData.append('upload', file);
|
32
|
+
|
33
|
+
return new Promise((resolve, reject) => {
|
34
|
+
const xhr = new XMLHttpRequest();
|
35
|
+
|
36
|
+
xhr.open('POST', config.uploadUrl, true);
|
37
|
+
xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
|
38
|
+
|
39
|
+
xhr.upload.onprogress = (evt) => {
|
40
|
+
if (evt.lengthComputable) {
|
41
|
+
loader.uploadTotal = evt.total;
|
42
|
+
loader.uploaded = evt.loaded;
|
43
|
+
}
|
44
|
+
};
|
45
|
+
|
46
|
+
xhr.onload = () => {
|
47
|
+
if (xhr.status >= 200 && xhr.status < 300) {
|
48
|
+
const data = JSON.parse(xhr.response);
|
49
|
+
resolve({ default: data.url });
|
50
|
+
} else {
|
51
|
+
reject(`Upload failed: ${xhr.statusText}`);
|
52
|
+
}
|
53
|
+
};
|
54
|
+
|
55
|
+
xhr.onerror = () => reject('Upload failed');
|
56
|
+
xhr.onabort = () => reject('Upload aborted');
|
57
|
+
|
58
|
+
xhr.send(formData);
|
59
|
+
this._xhr = xhr;
|
60
|
+
});
|
61
|
+
} catch (error) {
|
62
|
+
throw error;
|
63
|
+
}
|
64
|
+
},
|
65
|
+
|
66
|
+
abort() {
|
67
|
+
if (this._xhr) {
|
68
|
+
this._xhr.abort();
|
69
|
+
}
|
70
|
+
}
|
71
|
+
});
|
72
|
+
}
|
73
|
+
}
|
74
|
+
JAVASCRIPT
|
75
|
+
|
76
|
+
def initialize
|
77
|
+
super(:SimpleUpload, PLUGIN_CODE)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module CKEditor5::Rails
|
4
|
+
class Presets::PluginsBuilder
|
5
|
+
attr_reader :plugins
|
6
|
+
|
7
|
+
def initialize(plugins)
|
8
|
+
@plugins = plugins
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.create_plugin(name, **kwargs)
|
12
|
+
if name.is_a?(Editor::PropsInlinePlugin) || name.is_a?(Editor::PropsPlugin)
|
13
|
+
name
|
14
|
+
else
|
15
|
+
Editor::PropsPlugin.new(name, **kwargs)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def remove(*names)
|
20
|
+
names.each { |name| plugins.delete_if { |plugin| plugin.name == name } }
|
21
|
+
end
|
22
|
+
|
23
|
+
def prepend(*names, before: nil, **kwargs)
|
24
|
+
new_plugins = names.map { |name| self.class.create_plugin(name, **kwargs) }
|
25
|
+
|
26
|
+
if before
|
27
|
+
index = plugins.index { |p| p.name == before }
|
28
|
+
raise ArgumentError, "Plugin '#{before}' not found" unless index
|
29
|
+
|
30
|
+
plugins.insert(index, *new_plugins)
|
31
|
+
else
|
32
|
+
plugins.insert(0, *new_plugins)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def append(*names, after: nil, **kwargs)
|
37
|
+
new_plugins = names.map { |name| self.class.create_plugin(name, **kwargs) }
|
38
|
+
|
39
|
+
if after
|
40
|
+
index = plugins.index { |p| p.name == after }
|
41
|
+
raise ArgumentError, "Plugin '#{after}' not found" unless index
|
42
|
+
|
43
|
+
plugins.insert(index + 1, *new_plugins)
|
44
|
+
else
|
45
|
+
plugins.push(*new_plugins)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -137,7 +137,7 @@ module CKEditor5::Rails
|
|
137
137
|
|
138
138
|
return unless block
|
139
139
|
|
140
|
-
builder =
|
140
|
+
builder = ArrayBuilder.new(@config[:toolbar][:items])
|
141
141
|
builder.instance_eval(&block)
|
142
142
|
end
|
143
143
|
|
@@ -146,11 +146,21 @@ module CKEditor5::Rails
|
|
146
146
|
end
|
147
147
|
|
148
148
|
def plugin(name, **kwargs)
|
149
|
-
|
149
|
+
plugin_obj = PluginsBuilder.create_plugin(name, **kwargs)
|
150
|
+
|
151
|
+
@config[:plugins] << plugin_obj
|
152
|
+
plugin_obj
|
150
153
|
end
|
151
154
|
|
152
|
-
def plugins(*names, **kwargs)
|
153
|
-
|
155
|
+
def plugins(*names, **kwargs, &block)
|
156
|
+
@config[:plugins] ||= []
|
157
|
+
|
158
|
+
names.each { |name| plugin(name, **kwargs) } unless names.empty?
|
159
|
+
|
160
|
+
return unless block
|
161
|
+
|
162
|
+
builder = PluginsBuilder.new(@config[:plugins])
|
163
|
+
builder.instance_eval(&block)
|
154
164
|
end
|
155
165
|
|
156
166
|
def language(ui = nil, content: ui) # rubocop:disable Naming/MethodParameterName
|
@@ -161,6 +171,15 @@ module CKEditor5::Rails
|
|
161
171
|
content: content
|
162
172
|
}
|
163
173
|
end
|
174
|
+
|
175
|
+
def simple_upload_adapter(upload_url = '/uploads')
|
176
|
+
plugins do
|
177
|
+
remove :Base64UploadAdapter
|
178
|
+
end
|
179
|
+
|
180
|
+
plugin(Plugins::SimpleUploadAdapter.new)
|
181
|
+
configure(:simpleUpload, { uploadUrl: upload_url })
|
182
|
+
end
|
164
183
|
end
|
165
184
|
end
|
166
185
|
end
|
@@ -2,12 +2,10 @@
|
|
2
2
|
|
3
3
|
module CKEditor5::Rails::Presets
|
4
4
|
class ToolbarBuilder
|
5
|
-
|
6
|
-
@toolbar_config = toolbar_config
|
7
|
-
end
|
5
|
+
attr_reader :items
|
8
6
|
|
9
|
-
def items
|
10
|
-
@
|
7
|
+
def initialize(items)
|
8
|
+
@items = items
|
11
9
|
end
|
12
10
|
|
13
11
|
def remove(*removed_items)
|
@@ -17,7 +15,7 @@ module CKEditor5::Rails::Presets
|
|
17
15
|
def prepend(*prepended_items, before: nil)
|
18
16
|
if before
|
19
17
|
index = items.index(before)
|
20
|
-
raise ArgumentError, "Item '#{before}' not found in
|
18
|
+
raise ArgumentError, "Item '#{before}' not found in array" unless index
|
21
19
|
|
22
20
|
items.insert(index, *prepended_items)
|
23
21
|
else
|
@@ -28,7 +26,7 @@ module CKEditor5::Rails::Presets
|
|
28
26
|
def append(*appended_items, after: nil)
|
29
27
|
if after
|
30
28
|
index = items.index(after)
|
31
|
-
raise ArgumentError, "Item '#{after}' not found in
|
29
|
+
raise ArgumentError, "Item '#{after}' not found in array" unless index
|
32
30
|
|
33
31
|
items.insert(index + 1, *appended_items)
|
34
32
|
else
|
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.
|
4
|
+
version: 1.14.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mateusz Bagiński
|
@@ -67,7 +67,9 @@ files:
|
|
67
67
|
- lib/ckeditor5/rails/helpers.rb
|
68
68
|
- lib/ckeditor5/rails/hooks/form.rb
|
69
69
|
- lib/ckeditor5/rails/hooks/simple_form.rb
|
70
|
+
- lib/ckeditor5/rails/plugins/simple_upload_adapter.rb
|
70
71
|
- lib/ckeditor5/rails/presets/manager.rb
|
72
|
+
- lib/ckeditor5/rails/presets/plugins_builder.rb
|
71
73
|
- lib/ckeditor5/rails/presets/preset_builder.rb
|
72
74
|
- lib/ckeditor5/rails/presets/toolbar_builder.rb
|
73
75
|
- lib/ckeditor5/rails/semver.rb
|