ckeditor5 1.29.2 → 1.31.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 +74 -1
- data/lib/ckeditor5/rails/assets/assets_bundle_html_serializer.rb +2 -2
- data/lib/ckeditor5/rails/cdn/ckeditor_bundle.rb +2 -2
- data/lib/ckeditor5/rails/cdn/concerns/bundle_builder.rb +5 -7
- data/lib/ckeditor5/rails/cdn/helpers.rb +1 -1
- data/lib/ckeditor5/rails/context/preset_builder.rb +2 -2
- data/lib/ckeditor5/rails/editor/helpers/config_helpers.rb +1 -1
- data/lib/ckeditor5/rails/editor/props.rb +2 -2
- data/lib/ckeditor5/rails/editor/props_patch_plugin.rb +2 -2
- data/lib/ckeditor5/rails/engine.rb +3 -5
- data/lib/ckeditor5/rails/plugins/custom_translations_loader.rb +1 -1
- data/lib/ckeditor5/rails/plugins/patches/fix_color_picker_race_condition.rb +50 -0
- data/lib/ckeditor5/rails/plugins.rb +15 -0
- data/lib/ckeditor5/rails/presets/concerns/plugin_methods.rb +19 -2
- data/lib/ckeditor5/rails/presets/manager.rb +4 -4
- data/lib/ckeditor5/rails/presets/preset_builder.rb +20 -14
- data/lib/ckeditor5/rails/presets/special_characters_builder.rb +1 -2
- data/lib/ckeditor5/rails/semver.rb +1 -1
- data/lib/ckeditor5/rails/version.rb +1 -1
- data/spec/e2e/spec_helper.rb +1 -1
- data/spec/lib/ckeditor5/rails/cdn/helpers_spec.rb +2 -13
- data/spec/lib/ckeditor5/rails/presets/manager_spec.rb +58 -2
- data/spec/lib/ckeditor5/rails/presets/preset_builder_spec.rb +24 -1
- data/spec/spec_helper.rb +1 -1
- metadata +7 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a7597c46553e634d89338c3a5ef6a28ff03541645a9eab898e32f09b59a0f7cf
|
4
|
+
data.tar.gz: 8ce954837b5b75472270ccc33672e02a04c0ab82db80498ed077f5cd9d8acde9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0c67de9f38b698d7010c4db93791d775cec8878324ddf029e91bb4cc04b7b4ce8660eb8841c027eb65b835be9f25443d52632d064d07854b14e153743167d941
|
7
|
+
data.tar.gz: 9eb071ef2de50204b5f4e1122a5a0639a60a1dec02681bc772f21da49caa9eb3c16a947b366ec9462aa7d48912ecccf4fe681536024b52123eda29b5b4db35d5
|
data/README.md
CHANGED
@@ -11,7 +11,7 @@
|
|
11
11
|
CKEditor 5 Ruby on Rails integration gem. Provides seamless integration of CKEditor 5 with Rails applications through web components and helper methods. This gem supports various editor types, including classic, inline, balloon, and decoupled editors. It also includes support for custom plugins, translations, and configuration options.
|
12
12
|
|
13
13
|
> [!IMPORTANT]
|
14
|
-
> This gem is unofficial and not maintained by CKSource. For official CKEditor 5 documentation, visit [ckeditor.com](https://ckeditor.com/docs/ckeditor5/latest/). If you encounter any issues in
|
14
|
+
> This gem is unofficial and not maintained by CKSource. For official CKEditor 5 documentation, visit [ckeditor.com](https://ckeditor.com/docs/ckeditor5/latest/). If you encounter any issues in editor, please report them on the [GitHub repository](https://github.com/ckeditor/ckeditor5/issues).
|
15
15
|
|
16
16
|
<p align="center">
|
17
17
|
<img src="docs/intro-classic-editor.png" alt="CKEditor 5 Classic Editor in Ruby on Rails application">
|
@@ -146,10 +146,12 @@ For extending CKEditor's functionality, refer to the [plugins directory](https:/
|
|
146
146
|
- [`inline_plugin(name, code)` method](#inline_pluginname-code-method)
|
147
147
|
- [`external_plugin(name, script:, import_as: nil, window_name: nil, stylesheets: [])` method](#external_pluginname-script-import_as-nil-window_name-nil-stylesheets--method)
|
148
148
|
- [`patch_plugin(plugin)`](#patch_pluginplugin)
|
149
|
+
- [`apply_integration_patches(compress: false)` method](#apply_integration_patchescompress-false-method)
|
149
150
|
- [`simple_upload_adapter(url, compress: true)` method](#simple_upload_adapterurl-compress-true-method)
|
150
151
|
- [`special_characters(compress: true, &block)` method](#special_characterscompress-true-block-method)
|
151
152
|
- [`wproofreader(version: nil, cdn: nil, compress: true, **config)` method](#wproofreaderversion-nil-cdn-nil-compress-true-config-method)
|
152
153
|
- [`custom_translations(lang_code = nil, translations = {}, compress: true)` method](#custom_translationslang_code--nil-translations---compress-true-method)
|
154
|
+
- [`compression(enabled: true)` method](#compressionenabled-true-method)
|
153
155
|
- [Controller / View helpers 📦](#controller--view-helpers-)
|
154
156
|
- [`ckeditor5_translation_ref(key)` method](#ckeditor5_translation_refkey-method)
|
155
157
|
- [`ckeditor5_element_ref(selector)` method](#ckeditor5_element_refselector-method)
|
@@ -346,6 +348,20 @@ CKEditor5::Rails.configure do
|
|
346
348
|
end
|
347
349
|
```
|
348
350
|
|
351
|
+
In order to disable default patches, you can pass the `apply_patches: false` keyword argument to the `version` method.
|
352
|
+
|
353
|
+
```rb
|
354
|
+
# config/initializers/ckeditor5.rb
|
355
|
+
|
356
|
+
CKEditor5::Rails.configure do
|
357
|
+
# ... other configuration
|
358
|
+
|
359
|
+
version '44.3.0', apply_patches: false
|
360
|
+
end
|
361
|
+
```
|
362
|
+
|
363
|
+
The patches are defined in the `lib/ckeditor5/rails/plugins/patches` directory. If you want to apply custom patches, you can use the `patch_plugin` method.
|
364
|
+
|
349
365
|
</details>
|
350
366
|
|
351
367
|
#### `automatic_upgrades(enabled: true)` method
|
@@ -1038,6 +1054,29 @@ end
|
|
1038
1054
|
```
|
1039
1055
|
</details>
|
1040
1056
|
|
1057
|
+
#### `apply_integration_patches(compress: false)` method
|
1058
|
+
|
1059
|
+
<details>
|
1060
|
+
<summary>Apply patches to the specific versions of CKEditor 5</summary>
|
1061
|
+
|
1062
|
+
<br />
|
1063
|
+
|
1064
|
+
Defines a method that applies patches to the specific versions of CKEditor 5. The example below shows how to apply patches to the `44.1.0` version:
|
1065
|
+
|
1066
|
+
```rb
|
1067
|
+
# config/initializers/ckeditor5.rb
|
1068
|
+
|
1069
|
+
CKEditor5::Rails.configure do
|
1070
|
+
# ... other configuration
|
1071
|
+
|
1072
|
+
apply_integration_patches
|
1073
|
+
end
|
1074
|
+
```
|
1075
|
+
|
1076
|
+
It's useful when you want to apply patches to the specific versions of CKEditor 5. The patches are defined in the `lib/ckeditor5/rails/plugins/patches` directory.
|
1077
|
+
|
1078
|
+
</details>
|
1079
|
+
|
1041
1080
|
#### `simple_upload_adapter(url, compress: true)` method
|
1042
1081
|
|
1043
1082
|
<details>
|
@@ -1194,6 +1233,40 @@ end
|
|
1194
1233
|
|
1195
1234
|
</details>
|
1196
1235
|
|
1236
|
+
#### `compression(enabled: true)` method
|
1237
|
+
|
1238
|
+
<details>
|
1239
|
+
<summary>Enable or disable compression of the inline plugins or patches</summary>
|
1240
|
+
|
1241
|
+
<br />
|
1242
|
+
|
1243
|
+
Defines whether the inline plugins should be compressed. It **must** be called before the `inline_plugin` and `version` methods. The example below shows how to disable compression:
|
1244
|
+
|
1245
|
+
```rb
|
1246
|
+
# config/initializers/ckeditor5.rb
|
1247
|
+
|
1248
|
+
CKEditor5::Rails.configure do
|
1249
|
+
compression enabled: false
|
1250
|
+
|
1251
|
+
# ... other configuration
|
1252
|
+
end
|
1253
|
+
```
|
1254
|
+
|
1255
|
+
:warning: Compression is enabled by default, and it's recommended to keep it enabled for production environments. It reduces the size of the inline plugins and patches, which improves the loading time of the editor.
|
1256
|
+
If you want to disable compression for a specific plugin, you can pass the `compress: false` keyword argument to the `inline_plugin` method:
|
1257
|
+
|
1258
|
+
```rb
|
1259
|
+
# config/initializers/ckeditor5.rb
|
1260
|
+
|
1261
|
+
CKEditor5::Rails.configure do
|
1262
|
+
# ... other configuration
|
1263
|
+
|
1264
|
+
inline_plugin :MyCustomPlugin, plugin_code, compress: false
|
1265
|
+
end
|
1266
|
+
```
|
1267
|
+
|
1268
|
+
</details>
|
1269
|
+
|
1197
1270
|
### Controller / View helpers 📦
|
1198
1271
|
|
1199
1272
|
#### `ckeditor5_translation_ref(key)` method
|
@@ -52,9 +52,9 @@ module CKEditor5::Rails::Assets
|
|
52
52
|
private
|
53
53
|
|
54
54
|
def window_scripts_tags(nonce: nil)
|
55
|
-
scripts = bundle.scripts.
|
55
|
+
scripts = bundle.scripts.map do |script|
|
56
56
|
tag.script(src: script.url, nonce: nonce, crossorigin: 'anonymous') if script.window?
|
57
|
-
end
|
57
|
+
end.compact
|
58
58
|
|
59
59
|
safe_join(scripts)
|
60
60
|
end
|
@@ -43,7 +43,7 @@ module CKEditor5::Rails
|
|
43
43
|
end
|
44
44
|
|
45
45
|
def translations_js_url_imports
|
46
|
-
translations.
|
46
|
+
translations.map do |lang|
|
47
47
|
next if lang == :en
|
48
48
|
|
49
49
|
url = create_cdn_url(import_name, version, "translations/#{lang}.js")
|
@@ -53,7 +53,7 @@ module CKEditor5::Rails
|
|
53
53
|
import_name: "#{import_name}/translations/#{lang}.js",
|
54
54
|
translation: true
|
55
55
|
)
|
56
|
-
end
|
56
|
+
end.compact
|
57
57
|
end
|
58
58
|
end
|
59
59
|
end
|
@@ -4,13 +4,11 @@ module CKEditor5::Rails
|
|
4
4
|
module Cdn::Concerns
|
5
5
|
module BundleBuilder
|
6
6
|
def create_preset_bundle(preset)
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
premium:
|
13
|
-
}
|
7
|
+
cdn = preset.cdn
|
8
|
+
version = preset.version
|
9
|
+
translations = preset.translations
|
10
|
+
ckbox = preset.ckbox
|
11
|
+
premium = preset.premium
|
14
12
|
|
15
13
|
bundle = build_base_cdn_bundle(cdn, version, translations)
|
16
14
|
bundle << build_premium_cdn_bundle(cdn, version, translations) if premium
|
@@ -12,7 +12,7 @@ module CKEditor5::Rails
|
|
12
12
|
#
|
13
13
|
# @example Basic preset definition
|
14
14
|
# preset = PresetBuilder.new do
|
15
|
-
# version '
|
15
|
+
# version '43.3.1'
|
16
16
|
# gpl
|
17
17
|
# type :classic
|
18
18
|
# toolbar :bold, :italic
|
@@ -35,7 +35,7 @@ module CKEditor5::Rails
|
|
35
35
|
# @param block [Proc] Optional configuration block
|
36
36
|
# @example Initialize with block
|
37
37
|
# PresetBuilder.new do
|
38
|
-
# version '
|
38
|
+
# version '43.3.1'
|
39
39
|
# toolbar :bold, :italic
|
40
40
|
# end
|
41
41
|
def initialize(&block)
|
@@ -44,7 +44,7 @@ module CKEditor5::Rails::Editor::Helpers
|
|
44
44
|
#
|
45
45
|
# @example Creating a custom preset in controller
|
46
46
|
# @preset = ckeditor5_preset do
|
47
|
-
# version '
|
47
|
+
# version '43.3.1'
|
48
48
|
# toolbar :sourceEditing, :|, :bold, :italic
|
49
49
|
# plugins :Essentials, :Paragraph, :Bold, :Italic
|
50
50
|
# end
|
@@ -7,8 +7,8 @@ module CKEditor5::Rails::Editor
|
|
7
7
|
class PropsPatchPlugin < PropsInlinePlugin
|
8
8
|
attr_reader :min_version, :max_version
|
9
9
|
|
10
|
-
def initialize(name, code, min_version: nil, max_version: nil)
|
11
|
-
super(name, code)
|
10
|
+
def initialize(name, code, min_version: nil, max_version: nil, compress: true)
|
11
|
+
super(name, code, compress: compress)
|
12
12
|
|
13
13
|
@min_version = min_version && CKEditor5::Rails::Semver.new(min_version)
|
14
14
|
@max_version = max_version && CKEditor5::Rails::Semver.new(max_version)
|
@@ -3,10 +3,7 @@
|
|
3
3
|
require 'rails/engine'
|
4
4
|
|
5
5
|
require_relative 'presets/manager'
|
6
|
-
require_relative 'plugins
|
7
|
-
require_relative 'plugins/wproofreader'
|
8
|
-
require_relative 'plugins/special_characters_bootstrap'
|
9
|
-
require_relative 'plugins/custom_translations_loader'
|
6
|
+
require_relative 'plugins'
|
10
7
|
|
11
8
|
module CKEditor5::Rails
|
12
9
|
class PresetNotFoundError < ArgumentError; end
|
@@ -84,7 +81,8 @@ module CKEditor5::Rails
|
|
84
81
|
:type, :menubar, :plugins, :plugin, :inline_plugin,
|
85
82
|
:toolbar, :block_toolbar, :balloon_toolbar,
|
86
83
|
:language, :ckbox, :configure, :automatic_upgrades, :simple_upload_adapter,
|
87
|
-
:editable_height, :wproofreader, :custom_translations,
|
84
|
+
:editable_height, :wproofreader, :custom_translations, :apply_integration_patches,
|
85
|
+
:compression, :compression?, to: :default_preset
|
88
86
|
|
89
87
|
def initialize(configuration)
|
90
88
|
@configuration = configuration
|
@@ -5,7 +5,7 @@ require_relative '../editor/props_inline_plugin'
|
|
5
5
|
module CKEditor5::Rails::Plugins
|
6
6
|
class CustomTranslationsLoader < CKEditor5::Rails::Editor::PropsInlinePlugin
|
7
7
|
def initialize(translations, **kwargs) # rubocop:disable Metrics/MethodLength
|
8
|
-
code = <<~JS
|
8
|
+
code = <<~JS
|
9
9
|
const { Plugin } = await import('ckeditor5');
|
10
10
|
|
11
11
|
function resolveTranslationReferences(uiLanguage, config, visited = new WeakSet()) {
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../../editor/props_patch_plugin'
|
4
|
+
|
5
|
+
module CKEditor5::Rails::Plugins::Patches
|
6
|
+
# Fixes focus management issues in the CKEditor5 color picker component
|
7
|
+
# by ensuring proper focus handling when the color picker is opened.
|
8
|
+
#
|
9
|
+
# The patch modifies the ColorPickerView's focus behavior to properly
|
10
|
+
# focus either the hex input field (when visible) or the first slider.
|
11
|
+
#
|
12
|
+
# @see https://github.com/ckeditor/ckeditor5/issues/17069
|
13
|
+
class FixColorPickerRaceCondition < CKEditor5::Rails::Editor::PropsPatchPlugin
|
14
|
+
PLUGIN_CODE = <<~JS
|
15
|
+
const { Plugin, ColorPickerView, debounce } = await import( 'ckeditor5' );
|
16
|
+
|
17
|
+
return class FixColorPickerRaceCondition extends Plugin {
|
18
|
+
static get pluginName() {
|
19
|
+
return 'FixColorPickerRaceCondition';
|
20
|
+
}
|
21
|
+
|
22
|
+
constructor(editor) {
|
23
|
+
super(editor);
|
24
|
+
this.editor = editor;
|
25
|
+
this.#applyPatch();
|
26
|
+
}
|
27
|
+
|
28
|
+
#applyPatch() {
|
29
|
+
const { focus } = ColorPickerView.prototype;
|
30
|
+
|
31
|
+
ColorPickerView.prototype.focus = function() {
|
32
|
+
try {
|
33
|
+
if (!this._config.hideInput) {
|
34
|
+
this.hexInputRow.children.get( 1 ).focus();
|
35
|
+
}
|
36
|
+
|
37
|
+
this.slidersView.first.focus();
|
38
|
+
} catch (error) {
|
39
|
+
focus.apply(this, arguments);
|
40
|
+
}
|
41
|
+
}
|
42
|
+
}
|
43
|
+
}
|
44
|
+
JS
|
45
|
+
|
46
|
+
def initialize(**kwargs)
|
47
|
+
super(:FixColorPickerRaceCondition, PLUGIN_CODE, max_version: '44.4.0', **kwargs)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module CKEditor5::Rails::Plugins
|
4
|
+
module Patches
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
# Core plugins
|
9
|
+
require_relative 'plugins/simple_upload_adapter'
|
10
|
+
require_relative 'plugins/wproofreader'
|
11
|
+
require_relative 'plugins/special_characters_bootstrap'
|
12
|
+
require_relative 'plugins/custom_translations_loader'
|
13
|
+
|
14
|
+
# Plugin patches and fixes
|
15
|
+
require_relative 'plugins/patches/fix_color_picker_race_condition'
|
@@ -18,6 +18,24 @@ module CKEditor5::Rails
|
|
18
18
|
attr_reader :disallow_inline_plugin_compression
|
19
19
|
end
|
20
20
|
|
21
|
+
# Sets compression of inline plugin code. Make sure that it is called before setting the version
|
22
|
+
# or adding plugins.
|
23
|
+
# @example Disable compression
|
24
|
+
# compression(enabled: false)
|
25
|
+
# @return [void]
|
26
|
+
# @note This method is useful for debugging purposes, as it allows you to see the uncompressed code.
|
27
|
+
def compression(enabled: false)
|
28
|
+
@disallow_inline_plugin_compression = !enabled
|
29
|
+
end
|
30
|
+
|
31
|
+
# Check if compression is enabled
|
32
|
+
# @return [Boolean] True if compression is enabled, false otherwise
|
33
|
+
# @example Check if compression is enabled
|
34
|
+
# compression? # => true
|
35
|
+
def compression?
|
36
|
+
!@disallow_inline_plugin_compression
|
37
|
+
end
|
38
|
+
|
21
39
|
# Registers an external plugin loaded from a URL
|
22
40
|
#
|
23
41
|
# @param name [Symbol] Plugin name
|
@@ -51,7 +69,7 @@ module CKEditor5::Rails
|
|
51
69
|
# }
|
52
70
|
# }
|
53
71
|
# JS
|
54
|
-
def inline_plugin(name, code, compress:
|
72
|
+
def inline_plugin(name, code, compress: !@disallow_inline_plugin_compression)
|
55
73
|
if code.match?(/export default/)
|
56
74
|
raise UnsupportedESModuleError,
|
57
75
|
'Inline plugins must not use ES module syntax!' \
|
@@ -63,7 +81,6 @@ module CKEditor5::Rails
|
|
63
81
|
'Plugin code must return a class that extends Plugin!'
|
64
82
|
end
|
65
83
|
|
66
|
-
compress = false if @disallow_inline_plugin_compression
|
67
84
|
plugin = Editor::PropsInlinePlugin.new(name, code, compress: compress)
|
68
85
|
|
69
86
|
register_plugin(plugin)
|
@@ -27,7 +27,7 @@ module CKEditor5::Rails::Presets
|
|
27
27
|
# end
|
28
28
|
# @example Define preset from scratch
|
29
29
|
# presets.define :blank, inherit: false do
|
30
|
-
# version '
|
30
|
+
# version '43.3.1'
|
31
31
|
# gpl
|
32
32
|
# type :classic
|
33
33
|
# end
|
@@ -40,7 +40,7 @@ module CKEditor5::Rails::Presets
|
|
40
40
|
end
|
41
41
|
|
42
42
|
preset.instance_eval(&block)
|
43
|
-
preset.try_compress_inline_plugins!
|
43
|
+
preset.try_compress_inline_plugins! if preset.compression?
|
44
44
|
|
45
45
|
@presets[name] = preset
|
46
46
|
end
|
@@ -59,7 +59,7 @@ module CKEditor5::Rails::Presets
|
|
59
59
|
preset = @presets[name]
|
60
60
|
|
61
61
|
preset.instance_eval(&block)
|
62
|
-
preset.try_compress_inline_plugins!
|
62
|
+
preset.try_compress_inline_plugins! if preset.compression?
|
63
63
|
end
|
64
64
|
|
65
65
|
alias extend override
|
@@ -83,7 +83,7 @@ module CKEditor5::Rails::Presets
|
|
83
83
|
# @example Basic configuration
|
84
84
|
# CKEditor5::Rails.configure do
|
85
85
|
# presets.define :default do
|
86
|
-
# version '
|
86
|
+
# version '43.3.1'
|
87
87
|
# gpl
|
88
88
|
# type :classic
|
89
89
|
# menubar
|
@@ -6,14 +6,14 @@ require_relative 'special_characters_builder'
|
|
6
6
|
|
7
7
|
module CKEditor5::Rails
|
8
8
|
module Presets
|
9
|
-
class PresetBuilder
|
9
|
+
class PresetBuilder # rubocop:disable Metrics/ClassLength
|
10
10
|
include Editor::Helpers::Config
|
11
11
|
include Concerns::ConfigurationMethods
|
12
12
|
include Concerns::PluginMethods
|
13
13
|
|
14
14
|
# @example Basic initialization
|
15
15
|
# PresetBuilder.new do
|
16
|
-
# version '
|
16
|
+
# version '43.3.1'
|
17
17
|
# gpl
|
18
18
|
# type :classic
|
19
19
|
# end
|
@@ -27,6 +27,7 @@ module CKEditor5::Rails
|
|
27
27
|
@ckbox = nil
|
28
28
|
@editable_height = nil
|
29
29
|
@automatic_upgrades = false
|
30
|
+
@disallow_inline_plugin_compression = false
|
30
31
|
@custom_translations = {}
|
31
32
|
@config = {
|
32
33
|
plugins: [],
|
@@ -36,12 +37,6 @@ module CKEditor5::Rails
|
|
36
37
|
instance_eval(&block) if block_given?
|
37
38
|
end
|
38
39
|
|
39
|
-
def deconstruct_keys(keys)
|
40
|
-
keys.index_with do |key|
|
41
|
-
public_send(key)
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
40
|
# @example Copy preset and modify it
|
46
41
|
# original = PresetBuilder.new
|
47
42
|
# copied = original.initialize_copy(original)
|
@@ -174,12 +169,15 @@ module CKEditor5::Rails
|
|
174
169
|
|
175
170
|
# Set or get editor version
|
176
171
|
# @param version [String, nil] Editor version to set
|
172
|
+
# @param apply_patches [Boolean] Whether to apply integration patches after setting version
|
177
173
|
# @example Set specific version
|
178
|
-
# version '
|
174
|
+
# version '43.3.1'
|
175
|
+
# @example Set version without applying patches
|
176
|
+
# version '43.3.1', apply_patches: false
|
179
177
|
# @example Get current version
|
180
178
|
# version # => "43.3.1"
|
181
179
|
# @return [String, nil] Current version string or nil if not set
|
182
|
-
def version(version = nil)
|
180
|
+
def version(version = nil, apply_patches: true)
|
183
181
|
return @version&.to_s if version.nil?
|
184
182
|
|
185
183
|
if @automatic_upgrades && version
|
@@ -192,6 +190,13 @@ module CKEditor5::Rails
|
|
192
190
|
# If there is no license key set, and the version if newer than 44.0.0, switch to GPL
|
193
191
|
# as the license key is now required in all versions
|
194
192
|
gpl if license_key.nil? && @version.major >= 44
|
193
|
+
apply_integration_patches if apply_patches
|
194
|
+
end
|
195
|
+
|
196
|
+
# Apply integration patches for the current version
|
197
|
+
# @return [void]
|
198
|
+
def apply_integration_patches(compress: !@disallow_inline_plugin_compression)
|
199
|
+
patch_plugin(Plugins::Patches::FixColorPickerRaceCondition.new(compress: compress))
|
195
200
|
end
|
196
201
|
|
197
202
|
# Enable or disable automatic version upgrades
|
@@ -347,7 +352,8 @@ module CKEditor5::Rails
|
|
347
352
|
# ]
|
348
353
|
# }
|
349
354
|
# @return [void]
|
350
|
-
def custom_translations(lang_code = nil, translations = {},
|
355
|
+
def custom_translations(lang_code = nil, translations = {},
|
356
|
+
compress: !@disallow_inline_plugin_compression)
|
351
357
|
return @custom_translations if lang_code.blank?
|
352
358
|
|
353
359
|
@custom_translations[lang_code.to_sym] ||= {}
|
@@ -385,7 +391,7 @@ module CKEditor5::Rails
|
|
385
391
|
# @param compress [Boolean] Enable compression
|
386
392
|
# @example Enable upload adapter
|
387
393
|
# simple_upload_adapter '/uploads'
|
388
|
-
def simple_upload_adapter(upload_url = '/uploads', compress:
|
394
|
+
def simple_upload_adapter(upload_url = '/uploads', compress: !@disallow_inline_plugin_compression)
|
389
395
|
plugins do
|
390
396
|
remove(:Base64UploadAdapter)
|
391
397
|
end
|
@@ -402,7 +408,7 @@ module CKEditor5::Rails
|
|
402
408
|
# @example Basic configuration
|
403
409
|
# wproofreader serviceId: 'your-service-ID',
|
404
410
|
# srcUrl: 'https://svc.webspellchecker.net/spellcheck31/wscbundle/wscbundle.js'
|
405
|
-
def wproofreader(version: nil, cdn: nil, compress:
|
411
|
+
def wproofreader(version: nil, cdn: nil, compress: !@disallow_inline_plugin_compression, **config)
|
406
412
|
configure :wproofreader, config
|
407
413
|
plugins do
|
408
414
|
prepend(Plugins::WProofreaderSync.new(compress: compress))
|
@@ -438,7 +444,7 @@ module CKEditor5::Rails
|
|
438
444
|
# item 'heart', '❤️'
|
439
445
|
# end
|
440
446
|
# end
|
441
|
-
def special_characters(compress:
|
447
|
+
def special_characters(compress: !@disallow_inline_plugin_compression, &block)
|
442
448
|
builder = SpecialCharactersBuilder.new
|
443
449
|
builder.instance_eval(&block) if block_given?
|
444
450
|
|
@@ -20,8 +20,7 @@ module CKEditor5::Rails::Presets
|
|
20
20
|
# group = Group.new('Emoji', label: 'Emoticons')
|
21
21
|
# group.item('smiley', '😊')
|
22
22
|
class Group
|
23
|
-
attr_reader :name, :label
|
24
|
-
private attr_reader :items
|
23
|
+
attr_reader :name, :label, :items
|
25
24
|
|
26
25
|
# Initialize a new special characters group
|
27
26
|
#
|
data/spec/e2e/spec_helper.rb
CHANGED
@@ -20,7 +20,7 @@ RSpec.describe CKEditor5::Rails::Cdn::Helpers do
|
|
20
20
|
let(:helper) { test_class.new }
|
21
21
|
let(:preset) do
|
22
22
|
CKEditor5::Rails::Presets::PresetBuilder.new do
|
23
|
-
version '34.1.0'
|
23
|
+
version '34.1.0', apply_patches: false
|
24
24
|
type :classic
|
25
25
|
translations :pl
|
26
26
|
cdn :cloud
|
@@ -151,7 +151,7 @@ RSpec.describe CKEditor5::Rails::Cdn::Helpers do
|
|
151
151
|
context 'when overriding preset values' do
|
152
152
|
let(:preset) do
|
153
153
|
CKEditor5::Rails::Presets::PresetBuilder.new do
|
154
|
-
version '34.1.0'
|
154
|
+
version '34.1.0', apply_patches: false
|
155
155
|
type :classic
|
156
156
|
language :pl
|
157
157
|
cdn :cloud
|
@@ -202,17 +202,6 @@ RSpec.describe CKEditor5::Rails::Cdn::Helpers do
|
|
202
202
|
end
|
203
203
|
end
|
204
204
|
|
205
|
-
context 'with missing required parameters' do
|
206
|
-
before do
|
207
|
-
allow(helper).to receive(:merge_with_editor_preset).and_return({})
|
208
|
-
end
|
209
|
-
|
210
|
-
it 'raises error about missing required parameters' do
|
211
|
-
expect { helper.ckeditor5_assets(preset: :default) }
|
212
|
-
.to raise_error(NoMatchingPatternKeyError)
|
213
|
-
end
|
214
|
-
end
|
215
|
-
|
216
205
|
context 'destructure non-matching preset override' do
|
217
206
|
before do
|
218
207
|
RSpec::Mocks.space.proxy_for(CKEditor5::Rails::Engine).reset
|
@@ -20,7 +20,7 @@ RSpec.describe CKEditor5::Rails::Presets::Manager do
|
|
20
20
|
it 'creates new preset based on default' do
|
21
21
|
manager.define(:custom) do
|
22
22
|
automatic_upgrades enabled: false
|
23
|
-
version '36.0.0'
|
23
|
+
version '36.0.0', apply_patches: false
|
24
24
|
end
|
25
25
|
|
26
26
|
expect(manager[:custom].version).to eq('36.0.0')
|
@@ -32,13 +32,42 @@ RSpec.describe CKEditor5::Rails::Presets::Manager do
|
|
32
32
|
it 'creates completely new preset' do
|
33
33
|
manager.define(:custom, inherit: false) do
|
34
34
|
automatic_upgrades enabled: false
|
35
|
-
version '36.0.0'
|
35
|
+
version '36.0.0', apply_patches: false
|
36
36
|
end
|
37
37
|
|
38
38
|
expect(manager[:custom].version).to eq('36.0.0')
|
39
39
|
expect(manager[:custom].config).to eq({ plugins: [], toolbar: [] })
|
40
40
|
end
|
41
41
|
end
|
42
|
+
|
43
|
+
context 'with compression settings' do
|
44
|
+
it 'attempts compression when compression? returns true' do
|
45
|
+
preset = manager.define(:with_compression, inherit: false) do
|
46
|
+
version '36.0.0', apply_patches: true
|
47
|
+
inline_plugin 'Test', <<~JAVASCRIPT
|
48
|
+
const { Plugin } = await import( 'ckeditor5' );
|
49
|
+
|
50
|
+
return class Abc extends Plugin {}
|
51
|
+
JAVASCRIPT
|
52
|
+
end
|
53
|
+
|
54
|
+
expect(preset.config[:plugins].first.code).to include('const{Plugin:t,ColorPickerView:i,debounce:o}=')
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'does not attempt compression when compression? returns false' do
|
58
|
+
preset = manager.define(:without_compression, inherit: false) do
|
59
|
+
compression enabled: false
|
60
|
+
version '36.0.0', apply_patches: true
|
61
|
+
inline_plugin 'Test', <<~JAVASCRIPT
|
62
|
+
const { Plugin } = await import( 'ckeditor5' );
|
63
|
+
|
64
|
+
return class Abc extends Plugin {}
|
65
|
+
JAVASCRIPT
|
66
|
+
end
|
67
|
+
|
68
|
+
expect(preset.config[:plugins].first.code).to include('const { Plugin, ColorPickerView, debounce }')
|
69
|
+
end
|
70
|
+
end
|
42
71
|
end
|
43
72
|
|
44
73
|
describe '#override/#extend' do
|
@@ -69,6 +98,33 @@ RSpec.describe CKEditor5::Rails::Presets::Manager do
|
|
69
98
|
|
70
99
|
expect(manager[:custom].version).to eq('36.0.0')
|
71
100
|
end
|
101
|
+
|
102
|
+
context 'with compression settings' do
|
103
|
+
let(:preset_builder) { instance_double(CKEditor5::Rails::Presets::PresetBuilder) }
|
104
|
+
|
105
|
+
before do
|
106
|
+
allow(preset_builder).to receive(:instance_eval)
|
107
|
+
manager.instance_variable_set(:@presets, { custom: preset_builder })
|
108
|
+
end
|
109
|
+
|
110
|
+
it 'attempts compression when compression? returns true' do
|
111
|
+
allow(preset_builder).to receive(:compression?).and_return(true)
|
112
|
+
allow(preset_builder).to receive(:try_compress_inline_plugins!)
|
113
|
+
|
114
|
+
manager.override(:custom) {}
|
115
|
+
|
116
|
+
expect(preset_builder).to have_received(:try_compress_inline_plugins!).once
|
117
|
+
end
|
118
|
+
|
119
|
+
it 'does not attempt compression when compression? returns false' do
|
120
|
+
allow(preset_builder).to receive(:compression?).and_return(false)
|
121
|
+
allow(preset_builder).to receive(:try_compress_inline_plugins!)
|
122
|
+
|
123
|
+
manager.override(:custom) {}
|
124
|
+
|
125
|
+
expect(preset_builder).not_to have_received(:try_compress_inline_plugins!)
|
126
|
+
end
|
127
|
+
end
|
72
128
|
end
|
73
129
|
|
74
130
|
describe '#[]' do
|
@@ -332,6 +332,14 @@ RSpec.describe CKEditor5::Rails::Presets::PresetBuilder do
|
|
332
332
|
end
|
333
333
|
end
|
334
334
|
|
335
|
+
describe '#disable_compression' do
|
336
|
+
it 'disables compression for inline plugins' do
|
337
|
+
builder.compression(enabled: false)
|
338
|
+
expect(builder.compression?).to be false
|
339
|
+
expect(builder.disallow_inline_plugin_compression).to be true
|
340
|
+
end
|
341
|
+
end
|
342
|
+
|
335
343
|
describe '#external_plugin' do
|
336
344
|
it 'adds external plugin to config' do
|
337
345
|
plugin = builder.external_plugin('Test', script: 'https://example.org/script.js')
|
@@ -710,7 +718,7 @@ RSpec.describe CKEditor5::Rails::Presets::PresetBuilder do
|
|
710
718
|
it 'applies patch when applicable' do
|
711
719
|
allow(patch_plugin).to receive(:applicable_for_version?).and_return(true)
|
712
720
|
|
713
|
-
builder.version('35.0.0')
|
721
|
+
builder.version('35.0.0', apply_patches: false)
|
714
722
|
builder.patch_plugin(patch_plugin)
|
715
723
|
|
716
724
|
plugin_names = builder.config[:plugins].map(&:name)
|
@@ -734,4 +742,19 @@ RSpec.describe CKEditor5::Rails::Presets::PresetBuilder do
|
|
734
742
|
expect(plugin_names).to include(:TestPatch)
|
735
743
|
end
|
736
744
|
end
|
745
|
+
|
746
|
+
describe '#apply_integration_patches' do
|
747
|
+
it 'applies known integration patches' do
|
748
|
+
builder.version('35.0.0', apply_patches: false)
|
749
|
+
expect { builder.apply_integration_patches }
|
750
|
+
.to change { builder.config[:plugins].count }
|
751
|
+
.by(1)
|
752
|
+
end
|
753
|
+
|
754
|
+
it 'apply patches when version is not set' do
|
755
|
+
expect { builder.apply_integration_patches }
|
756
|
+
.to change { builder.config[:plugins].count }
|
757
|
+
.by(1)
|
758
|
+
end
|
759
|
+
end
|
737
760
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -34,7 +34,7 @@ require 'rspec/rails'
|
|
34
34
|
require 'rspec/expectations'
|
35
35
|
require 'rspec-html-matchers'
|
36
36
|
|
37
|
-
Dir[File.expand_path('support/**/*.rb', __dir__)].each { |f| require f }
|
37
|
+
Dir[File.expand_path('support/**/*.rb', __dir__)].sort.each { |f| require f }
|
38
38
|
|
39
39
|
Rails.application.initialize! unless Rails.application.initialized?
|
40
40
|
|
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.31.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mateusz Bagiński
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2025-
|
12
|
+
date: 2025-05-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -17,7 +17,7 @@ dependencies:
|
|
17
17
|
requirements:
|
18
18
|
- - ">="
|
19
19
|
- !ruby/object:Gem::Version
|
20
|
-
version: '
|
20
|
+
version: '5.2'
|
21
21
|
- - "<"
|
22
22
|
- !ruby/object:Gem::Version
|
23
23
|
version: '9.0'
|
@@ -27,7 +27,7 @@ dependencies:
|
|
27
27
|
requirements:
|
28
28
|
- - ">="
|
29
29
|
- !ruby/object:Gem::Version
|
30
|
-
version: '
|
30
|
+
version: '5.2'
|
31
31
|
- - "<"
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '9.0'
|
@@ -89,7 +89,9 @@ files:
|
|
89
89
|
- lib/ckeditor5/rails/hooks/form.rb
|
90
90
|
- lib/ckeditor5/rails/hooks/importmap.rb
|
91
91
|
- lib/ckeditor5/rails/hooks/simple_form.rb
|
92
|
+
- lib/ckeditor5/rails/plugins.rb
|
92
93
|
- lib/ckeditor5/rails/plugins/custom_translations_loader.rb
|
94
|
+
- lib/ckeditor5/rails/plugins/patches/fix_color_picker_race_condition.rb
|
93
95
|
- lib/ckeditor5/rails/plugins/simple_upload_adapter.rb
|
94
96
|
- lib/ckeditor5/rails/plugins/special_characters_bootstrap.rb
|
95
97
|
- lib/ckeditor5/rails/plugins/wproofreader.rb
|
@@ -161,7 +163,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
161
163
|
requirements:
|
162
164
|
- - ">="
|
163
165
|
- !ruby/object:Gem::Version
|
164
|
-
version:
|
166
|
+
version: 2.5.0
|
165
167
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
166
168
|
requirements:
|
167
169
|
- - ">="
|