ckeditor5 1.26.0 → 1.26.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ae47ab2c50827fd1a0716bc093475ce4e55a237ad3a9f4c35ba0b66d8ea46f7c
4
- data.tar.gz: 13e648a1a348203b84f7220b7160c9d98e25753a97a207e4c5260d8d4d598571
3
+ metadata.gz: 8e46c611bc11950481442cb335ae063943043937c9792b6eeedd731e030cdf1c
4
+ data.tar.gz: d16b561470173168c325457a00f5e83d5ca8689b0644f0d96533c05b7075193f
5
5
  SHA512:
6
- metadata.gz: c311294593a9de01ba525eab43d6dbf0418f454e6c7754a8c2a607464539ca82ed39f61a66d58f5c3a977f89a39c591adfb60b63711c47f3c2657e6c3442c49e
7
- data.tar.gz: 64f021c1316971588676e9819d422b09d83bea982d74e94544ccbcc703ffb381778dc08aa308620559701a030d88423c20b5b3a678abfc1854daebb33f9fccc1
6
+ metadata.gz: 6769430ee90f270077c474bf1999e7d5fc4d2ec5c62918063e6503c39956e63a9f0bfb948de3dd376bc2bcb7212fc505a61e94cf04e46a1c2e85867d8e037e9a
7
+ data.tar.gz: 93071afc776e615781cc9ff845b631bc823653f229ee9dbba22ccc2f9e9b2c5b9813c4cfaf6d672dfc9764a8db6d205631cf992b2d94a16fe8aba9df230681ad
data/README.md CHANGED
@@ -8,7 +8,10 @@
8
8
  ![GitHub code size in bytes](https://img.shields.io/github/languages/code-size/mati365/ckeditor5-rails?style=flat-square)
9
9
  [![GitHub issues](https://img.shields.io/github/issues/mati365/ckeditor5-rails?style=flat-square)](https://github.com/Mati365/ckeditor5-rails/issues)
10
10
 
11
- Unofficial CKEditor 5 Ruby on Rails integration gem. Provides seamless integration of CKEditor 5 with Rails applications through web components and helper methods.
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
+
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 integration, please report them on the [GitHub repository](https://github.com/Mati365/ckeditor5-rails/issues).
12
15
 
13
16
  <p align="center">
14
17
  <img src="docs/intro-classic-editor.png" alt="CKEditor 5 Classic Editor in Ruby on Rails application">
@@ -22,6 +25,10 @@ Add this line to your application's Gemfile:
22
25
  gem 'ckeditor5'
23
26
  ```
24
27
 
28
+ > [!NOTE]
29
+ > This gem uses importmaps and does not require Webpacker or any other JavaScript bundler. It's compatible with Rails 6.0+ and `importmap-rails` gem.
30
+ > While installation is simplified, it's recommended to check if jsdelivr or unpkg CDN is accessible in your environment, otherwise, you may need to configure a custom CDN (or use a commercial one).
31
+
25
32
  In your layout:
26
33
 
27
34
  ```erb
@@ -80,7 +87,7 @@ CKEditor5::Rails.configure do
80
87
 
81
88
  # Optionally, you can specify version of CKEditor 5 to use.
82
89
  # If it's not specified the default version specified in the gem will be used.
83
- # version '44.1.0'
90
+ # version '44.2.0'
84
91
 
85
92
  # Upload images to the server using the simple upload adapter, instead of Base64 encoding.
86
93
  # simple_upload_adapter
@@ -201,7 +208,7 @@ You can create your own by defining it in the `config/initializers/ckeditor5.rb`
201
208
 
202
209
  CKEditor5::Rails.configure do
203
210
  # It's possible to override the default preset right in the initializer.
204
- version '44.1.0'
211
+ version '44.2.0'
205
212
 
206
213
  # New presets inherit properties from the default preset defined in the initializer.
207
214
  # In this example, the custom preset inherits everything from default but disables the menubar:
@@ -211,7 +218,7 @@ CKEditor5::Rails.configure do
211
218
 
212
219
  # In order to define preset from scratch, you can use the `inherit: false` option.
213
220
  presets.define :blank_preset, inherit: false do
214
- version '44.1.0'
221
+ version '44.2.0'
215
222
 
216
223
  # It tells the integration to fetch the newest security patches and bug fixes.
217
224
  # It may be disabled, but it's highly recommended to keep it enabled to avoid
@@ -333,7 +340,7 @@ Defines the version of CKEditor 5 to be used. The example below shows how to set
333
340
  CKEditor5::Rails.configure do
334
341
  # ... other configuration
335
342
 
336
- version '44.1.0'
343
+ version '44.2.0'
337
344
  end
338
345
  ```
339
346
 
@@ -345,7 +352,7 @@ In order to disable default patches, you can pass the `apply_patches: false` key
345
352
  CKEditor5::Rails.configure do
346
353
  # ... other configuration
347
354
 
348
- version '44.1.0', apply_patches: false
355
+ version '44.2.0', apply_patches: false
349
356
  end
350
357
  ```
351
358
 
@@ -1229,7 +1236,7 @@ It may be useful when you want to define a preset based on the current user or r
1229
1236
  class ApplicationController < ActionController::Base
1230
1237
  def show
1231
1238
  @preset = ckeditor5_preset do
1232
- version '44.1.0'
1239
+ version '44.2.0'
1233
1240
 
1234
1241
  toolbar :sourceEditing, :|, :bold, :italic, :underline, :strikethrough,
1235
1242
  :subscript, :superscript, :removeFormat, :|, :bulletedList, :numberedList,
@@ -1264,7 +1271,7 @@ If you want to override the preset defined in the initializer, you can search fo
1264
1271
  class ApplicationController < ActionController::Base
1265
1272
  def show
1266
1273
  @preset = ckeditor5_preset(:default).override do
1267
- version '44.1.0'
1274
+ version '44.2.0'
1268
1275
 
1269
1276
  toolbar :sourceEditing, :|, :bold, :italic, :underline, :strikethrough,
1270
1277
  :subscript, :superscript, :removeFormat, :|, :bulletedList, :numberedList,
@@ -1437,7 +1444,7 @@ In that scenario it's recommended to add `gpl` method to the initializer along w
1437
1444
 
1438
1445
  CKEditor5::Rails.configure do
1439
1446
  gpl
1440
- version '44.1.0'
1447
+ version '44.2.0'
1441
1448
  end
1442
1449
  ```
1443
1450
 
@@ -50,10 +50,7 @@ module CKEditor5::Rails::Editor::Helpers
50
50
 
51
51
  raise ArgumentError, 'Configuration block is required for preset definition' unless block_given?
52
52
 
53
- CKEditor5::Rails::Presets::PresetBuilder.new(
54
- disallow_inline_plugins: true,
55
- &block
56
- )
53
+ CKEditor5::Rails::Presets::PresetBuilder.new(&block)
57
54
  end
58
55
  end
59
56
  end
@@ -73,7 +73,7 @@ module CKEditor5::Rails
73
73
  type ||= preset.type
74
74
 
75
75
  # Add some fallbacks
76
- config[:licenseKey] ||= context[:license_key]
76
+ config[:licenseKey] ||= context[:license_key] || preset.license_key
77
77
  config[:language] = { ui: language } if language
78
78
 
79
79
  editor_props = Editor::Props.new(
@@ -44,7 +44,7 @@ module CKEditor5::Rails::Plugins::Patches
44
44
  JS
45
45
 
46
46
  def initialize
47
- super(:FixColorPickerRaceCondition, PLUGIN_CODE)
47
+ super(:FixColorPickerRaceCondition, PLUGIN_CODE, max_version: '44.4.0')
48
48
  compress!
49
49
  end
50
50
  end
@@ -9,13 +9,12 @@ module CKEditor5::Rails
9
9
  module PluginMethods
10
10
  extend ActiveSupport::Concern
11
11
 
12
- class DisallowedInlinePluginError < ArgumentError; end
13
12
  class MissingInlinePluginError < StandardError; end
14
13
  class UnsupportedESModuleError < StandardError; end
15
14
  class InvalidPatchPluginError < ArgumentError; end
16
15
 
17
16
  included do
18
- attr_reader :disallow_inline_plugins, :disallow_inline_plugin_compression
17
+ attr_reader :disallow_inline_plugin_compression
19
18
  end
20
19
 
21
20
  # Registers an external plugin loaded from a URL
@@ -80,7 +79,7 @@ module CKEditor5::Rails
80
79
  raise InvalidPatchPluginError, 'Provided plugin must be a PropsPatchPlugin instance'
81
80
  end
82
81
 
83
- return unless plugin.applicable_for_version?(config[:version])
82
+ return unless !@version || plugin.applicable_for_version?(@version)
84
83
 
85
84
  register_plugin(plugin)
86
85
  end
@@ -124,26 +123,11 @@ module CKEditor5::Rails
124
123
 
125
124
  private
126
125
 
127
- # Check if the plugin looks like an inline plugin
128
- # @param plugin [Editor::PropsBasePlugin] Plugin instance
129
- # @return [Boolean] True if the plugin is an inline plugin
130
- def looks_like_inline_plugin?(plugin)
131
- plugin.respond_to?(:code) && plugin.code.present?
132
- end
133
-
134
126
  # Register a plugin in the editor configuration.
135
127
  #
136
- # It will raise an error if inline plugins are not allowed and the plugin is an inline plugin.
137
- # Most likely, this is being thrown when you use inline_plugin definition in a place where
138
- # it's not allowed (e.g. in a preset definition placed in controller).
139
- #
140
128
  # @param plugin_obj [Editor::PropsBasePlugin] Plugin instance to register
141
129
  # @return [Editor::PropsBasePlugin] The registered plugin
142
130
  def register_plugin(plugin_obj)
143
- if disallow_inline_plugins && looks_like_inline_plugin?(plugin_obj)
144
- raise DisallowedInlinePluginError, 'Inline plugins are not allowed here.'
145
- end
146
-
147
131
  config[:plugins] ||= []
148
132
  config[:plugins] << plugin_obj
149
133
  plugin_obj
@@ -17,8 +17,7 @@ module CKEditor5::Rails
17
17
  # gpl
18
18
  # type :classic
19
19
  # end
20
- def initialize(disallow_inline_plugins: false, &block)
21
- @disallow_inline_plugins = disallow_inline_plugins
20
+ def initialize(&block)
22
21
  @version = nil
23
22
  @premium = false
24
23
  @cdn = :jsdelivr
@@ -191,6 +190,9 @@ module CKEditor5::Rails
191
190
  @version = Semver.new(version)
192
191
  end
193
192
 
193
+ # If there is no license key set, and the version if newer than 44.0.0, switch to GPL
194
+ # as the license key is now required in all versions
195
+ gpl if license_key.nil? && @version.major >= 44
194
196
  apply_integration_patches if apply_patches
195
197
  end
196
198
 
@@ -10,6 +10,13 @@ module CKEditor5
10
10
  include Comparable
11
11
 
12
12
  def initialize(version_string)
13
+ if version_string.is_a?(Semver)
14
+ @major = version_string.major
15
+ @minor = version_string.minor
16
+ @patch = version_string.patch
17
+ return
18
+ end
19
+
13
20
  validate!(version_string)
14
21
  @major, @minor, @patch = version_string.split('.').map(&:to_i)
15
22
  end
@@ -2,8 +2,8 @@
2
2
 
3
3
  module CKEditor5
4
4
  module Rails
5
- VERSION = '1.26.0'
5
+ VERSION = '1.26.2'
6
6
 
7
- DEFAULT_CKEDITOR_VERSION = '44.1.0'
7
+ DEFAULT_CKEDITOR_VERSION = '44.2.0'
8
8
  end
9
9
  end
@@ -38,23 +38,6 @@ RSpec.describe CKEditor5::Rails::Editor::Helpers::Config do
38
38
  it 'yields the block to PresetBuilder' do
39
39
  expect { |b| helper.ckeditor5_preset(&b) }.to yield_control
40
40
  end
41
-
42
- it 'does not allow inline plugins definition' do
43
- expect do
44
- helper.ckeditor5_preset do
45
- inline_plugin :CustomPlugin, <<~JS
46
- const { Plugin } = await import( 'ckeditor5' );
47
-
48
- return class CustomPlugin extends Plugin {
49
- static get pluginName() { return 'CustomPlugin'; }
50
- }
51
- JS
52
- end
53
- end.to raise_error(
54
- CKEditor5::Rails::Presets::Concerns::PluginMethods::DisallowedInlinePluginError,
55
- 'Inline plugins are not allowed here.'
56
- )
57
- end
58
41
  end
59
42
 
60
43
  context 'when neither name nor block is provided' do
@@ -24,6 +24,7 @@ RSpec.describe CKEditor5::Rails::Editor::Helpers::Editor do
24
24
  allow(preset).to receive(:config).and_return({})
25
25
  allow(preset).to receive(:automatic_upgrades?).and_return(false)
26
26
  allow(preset).to receive(:editable_height).and_return(nil)
27
+ allow(preset).to receive(:license_key).and_return(nil)
27
28
  end
28
29
 
29
30
  before do
@@ -225,6 +226,18 @@ RSpec.describe CKEditor5::Rails::Editor::Helpers::Editor do
225
226
  expect(helper.ckeditor5_editor(editable_height: 600)).to include('editable-height="600px"')
226
227
  end
227
228
  end
229
+
230
+ context 'when using license key' do
231
+ it 'uses license key from preset when no other license key is provided' do
232
+ custom_context = { preset: :default, bundle: 'custom-bundle' }
233
+ allow(helper).to receive(:ckeditor5_context_or_fallback).and_return(custom_context)
234
+
235
+ allow(preset).to receive(:license_key).and_return('preset-license-key')
236
+
237
+ result = helper.ckeditor5_editor
238
+ expect(result).to include('preset-license-key')
239
+ end
240
+ end
228
241
  end
229
242
 
230
243
  describe '#ckeditor5_editable' do
@@ -36,6 +36,62 @@ RSpec.describe CKEditor5::Rails::Editor::PropsPatchPlugin do
36
36
  expect(result).to be true
37
37
  end
38
38
 
39
+ it 'returns true when version is equal to min constraint' do
40
+ result = described_class.applicable_for_version?(
41
+ '29.0.0',
42
+ min_version: '29.0.0'
43
+ )
44
+ expect(result).to be true
45
+ end
46
+
47
+ it 'returns true when version is equal to max constraint' do
48
+ result = described_class.applicable_for_version?(
49
+ '30.0.0',
50
+ max_version: '30.0.0'
51
+ )
52
+ expect(result).to be true
53
+ end
54
+
55
+ it 'returns true when version is higher than min constraint (patch)' do
56
+ result = described_class.applicable_for_version?(
57
+ '29.0.1',
58
+ min_version: '29.0.0'
59
+ )
60
+ expect(result).to be true
61
+ end
62
+
63
+ it 'returns true when version is higher than min constraint (minor)' do
64
+ result = described_class.applicable_for_version?(
65
+ '29.1.0',
66
+ min_version: '29.0.0'
67
+ )
68
+ expect(result).to be true
69
+ end
70
+
71
+ it 'returns true when version is higher than min constraint (major)' do
72
+ result = described_class.applicable_for_version?(
73
+ '30.0.0',
74
+ min_version: '29.0.0'
75
+ )
76
+ expect(result).to be true
77
+ end
78
+
79
+ it 'returns false when version is not equal to max constraint (patch)' do
80
+ result = described_class.applicable_for_version?(
81
+ '30.0.1',
82
+ max_version: '30.0.0'
83
+ )
84
+ expect(result).to be false
85
+ end
86
+
87
+ it 'returns false when version is not equal to min constraint (minor)' do
88
+ result = described_class.applicable_for_version?(
89
+ '29.1.0',
90
+ max_version: '29.0.0'
91
+ )
92
+ expect(result).to be false
93
+ end
94
+
39
95
  it 'returns false when version is too low' do
40
96
  result = described_class.applicable_for_version?(
41
97
  '28.9.9',
@@ -56,16 +112,46 @@ RSpec.describe CKEditor5::Rails::Editor::PropsPatchPlugin do
56
112
  end
57
113
 
58
114
  describe '#applicable_for_version?' do
59
- let(:plugin) do
60
- described_class.new(plugin_name, plugin_code, min_version: '29.0.0', max_version: '30.0.0')
115
+ context 'with both version constraints' do
116
+ let(:plugin) do
117
+ described_class.new(plugin_name, plugin_code, min_version: '29.0.0', max_version: '30.0.0')
118
+ end
119
+
120
+ it 'returns true for version within constraints' do
121
+ expect(plugin.applicable_for_version?('29.1.0')).to be true
122
+ end
123
+
124
+ it 'returns false for version outside constraints' do
125
+ expect(plugin.applicable_for_version?('28.9.9')).to be false
126
+ end
61
127
  end
62
128
 
63
- it 'returns true for version within constraints' do
64
- expect(plugin.applicable_for_version?('29.1.0')).to be true
129
+ context 'with only min_version constraint' do
130
+ let(:plugin) do
131
+ described_class.new(plugin_name, plugin_code, min_version: '29.0.0')
132
+ end
133
+
134
+ it 'returns true for version above min_version' do
135
+ expect(plugin.applicable_for_version?('30.0.0')).to be true
136
+ end
137
+
138
+ it 'returns false for version below min_version' do
139
+ expect(plugin.applicable_for_version?('28.9.9')).to be false
140
+ end
65
141
  end
66
142
 
67
- it 'returns false for version outside constraints' do
68
- expect(plugin.applicable_for_version?('28.9.9')).to be false
143
+ context 'with only max_version constraint' do
144
+ let(:plugin) do
145
+ described_class.new(plugin_name, plugin_code, max_version: '30.0.0')
146
+ end
147
+
148
+ it 'returns true for version below max_version' do
149
+ expect(plugin.applicable_for_version?('29.0.0')).to be true
150
+ end
151
+
152
+ it 'returns false for version above max_version' do
153
+ expect(plugin.applicable_for_version?('30.0.1')).to be false
154
+ end
69
155
  end
70
156
  end
71
157
  end
@@ -31,6 +31,34 @@ RSpec.describe CKEditor5::Rails::Presets::PresetBuilder do
31
31
  end
32
32
  end
33
33
 
34
+ describe '#version' do
35
+ it 'sets version' do
36
+ builder.version '35.0.0'
37
+ expect(builder.version).to eq('35.0.0')
38
+ end
39
+
40
+ context 'with version >= 44.0.0' do
41
+ it 'sets GPL license when no license key is set' do
42
+ builder.version('44.0.0')
43
+ expect(builder.license_key).to eq('GPL')
44
+ expect(builder.premium?).to be false
45
+ end
46
+
47
+ it 'does not change license when license key is already set' do
48
+ builder.license_key('commercial-key')
49
+ builder.version('44.0.0')
50
+ expect(builder.license_key).to eq('commercial-key')
51
+ end
52
+ end
53
+
54
+ context 'with version < 44.0.0' do
55
+ it 'does not set GPL license automatically' do
56
+ builder.version('43.0.0')
57
+ expect(builder.license_key).to be_nil
58
+ end
59
+ end
60
+ end
61
+
34
62
  describe '#initialize_copy' do
35
63
  let(:original) do
36
64
  described_class.new do
@@ -520,6 +548,10 @@ RSpec.describe CKEditor5::Rails::Presets::PresetBuilder do
520
548
  end
521
549
 
522
550
  describe '#special_characters' do
551
+ it 'should not crash if block is not provided' do
552
+ expect { builder.special_characters }.not_to raise_error
553
+ end
554
+
523
555
  it 'configures special characters with groups and items' do # rubocop:disable Metrics/BlockLength
524
556
  builder.special_characters do
525
557
  group 'Emoji', label: 'Emoticons' do
@@ -542,36 +574,38 @@ RSpec.describe CKEditor5::Rails::Presets::PresetBuilder do
542
574
  order :Text, :Arrows, :Emoji, :Mixed
543
575
  end
544
576
 
545
- expect(builder.config[:specialCharactersBootstrap]).to eq({
546
- groups: [
547
- {
548
- name: 'Emoji',
549
- items: [
550
- { title: 'smiley', character: '😊' },
551
- { title: 'heart', character: '❤️' }
552
- ],
553
- options: { label: 'Emoticons' }
554
- },
555
- {
556
- name: 'Arrows',
557
- items: [
558
- { title: 'right', character: '→' },
559
- { title: 'left', character: '←' }
560
- ],
561
- options: {}
562
- },
563
- {
564
- name: 'Mixed',
565
- items: [
566
- { title: 'star', character: '⭐' },
567
- { title: 'heart', character: '❤️' }
568
- ],
569
- options: { label: 'Mixed Characters' }
570
- }
571
- ],
572
- order: %w[Text Arrows Emoji Mixed],
573
- packs: []
574
- })
577
+ data = {
578
+ groups: [
579
+ {
580
+ name: 'Emoji',
581
+ items: [
582
+ { title: 'smiley', character: '😊' },
583
+ { title: 'heart', character: '❤️' }
584
+ ],
585
+ options: { label: 'Emoticons' }
586
+ },
587
+ {
588
+ name: 'Arrows',
589
+ items: [
590
+ { title: 'right', character: '→' },
591
+ { title: 'left', character: '←' }
592
+ ],
593
+ options: {}
594
+ },
595
+ {
596
+ name: 'Mixed',
597
+ items: [
598
+ { title: 'star', character: '⭐' },
599
+ { title: 'heart', character: '❤️' }
600
+ ],
601
+ options: { label: 'Mixed Characters' }
602
+ }
603
+ ],
604
+ order: %w[Text Arrows Emoji Mixed],
605
+ packs: []
606
+ }
607
+
608
+ expect(builder.config[:specialCharactersBootstrap]).to eq(data)
575
609
 
576
610
  plugin_names = builder.config[:plugins].map(&:name)
577
611
  expect(plugin_names).to include(:SpecialCharacters)
@@ -8,6 +8,15 @@ RSpec.describe CKEditor5::Rails::Semver do
8
8
  it 'accepts version in x.y.z format' do
9
9
  expect { described_class.new('1.2.3') }.not_to raise_error
10
10
  end
11
+
12
+ it 'accepts Semver object' do
13
+ original = described_class.new('1.2.3')
14
+ copied = described_class.new(original)
15
+
16
+ expect(copied.major).to eq(1)
17
+ expect(copied.minor).to eq(2)
18
+ expect(copied.patch).to eq(3)
19
+ end
11
20
  end
12
21
 
13
22
  context 'with invalid version' do
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.26.0
4
+ version: 1.26.2
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-02-10 00:00:00.000000000 Z
12
+ date: 2025-02-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails