ckeditor5 1.24.0 → 1.24.2

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: 0ee1985934d17921821b5d298275a64b71154309e0492f8da8aaae33c7dab2bd
4
- data.tar.gz: 880ec9989cd23462c889b35e68c7b49bdc9842c826b19326095d6380550220b8
3
+ metadata.gz: afb2870df1641fcf9fc15b9a7951c80e887991808078d56cc9ec67febad405c3
4
+ data.tar.gz: 725cb66917c42b51c48ecbc41161359ff73e81de17c0a0f95e6ddcc3b58bb7bc
5
5
  SHA512:
6
- metadata.gz: d7b01be500143a77b4457b50115daea67bc64351cb58b37e7f8cfe50f2c28cd0b8007633b85697ca90878a09b0c3a37df00fcae4d3927aff7bad57e27d21ca92
7
- data.tar.gz: 202ed9359e0b7b57d260f391c46bcd6a985eda11fb91df409bc345470c879a587487f8f7a23382d440b5963a797411dc6c58a60ddfe43e2ab24dc70b642a7fb0
6
+ metadata.gz: 5c8729eb7e323a8f240d4877171d64e27a5dab46567921c1372f57b9be635b4eac0d4e9492fd6693b0ef448533ca56a233498fe570866f734f2da5377c4140b3
7
+ data.tar.gz: 3ed9851296ad8cce6282a0c9262120436118552c7166490059bafd29ad82e83f8930c93a3464a780672b4c38aa9468b34a36cf1e8e613cfc34114b8523c22942
@@ -39,6 +39,7 @@ module CKEditor5::Rails
39
39
  # toolbar :bold, :italic
40
40
  # end
41
41
  def initialize(&block)
42
+ @disallow_inline_plugin_compression = true
42
43
  @config = {
43
44
  plugins: []
44
45
  }
@@ -46,7 +46,7 @@ module CKEditor5::Rails::Editor
46
46
  <<~JS
47
47
  window.addEventListener('ckeditor:request-cjs-plugin:#{@plugin.name}', () => {
48
48
  window['#{@plugin.name}'] = #{code.html_safe};
49
- });
49
+ }, { once: true });
50
50
  JS
51
51
  end
52
52
  end
@@ -14,7 +14,7 @@ module CKEditor5::Rails
14
14
  class UnsupportedESModuleError < StandardError; end
15
15
 
16
16
  included do
17
- attr_reader :disallow_inline_plugins
17
+ attr_reader :disallow_inline_plugins, :disallow_inline_plugin_compression
18
18
  end
19
19
 
20
20
  # Registers an external plugin loaded from a URL
@@ -62,7 +62,11 @@ module CKEditor5::Rails
62
62
  end
63
63
 
64
64
  wrapped_code = "(async () => { #{code} })();"
65
- minified_code = Terser.new(compress: false, mangle: true).compile(wrapped_code)
65
+ minified_code = wrapped_code
66
+
67
+ unless disallow_inline_plugin_compression
68
+ minified_code = Terser.new(compress: false, mangle: true).compile(minified_code)
69
+ end
66
70
 
67
71
  register_plugin(Editor::PropsInlinePlugin.new(name, minified_code))
68
72
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  module CKEditor5
4
4
  module Rails
5
- VERSION = '1.24.0'
5
+ VERSION = '1.24.2'
6
6
 
7
7
  DEFAULT_CKEDITOR_VERSION = '44.1.0'
8
8
  end
@@ -427,6 +427,29 @@ RSpec.describe CKEditor5::Rails::Cdn::Helpers do
427
427
  expect(result).to have_tag('script', with: { nonce: 'test-nonce' })
428
428
  end
429
429
 
430
+ context 'event listener' do
431
+ it 'adds event listeners for ckeditor:request-cjs-plugin' do
432
+ result = helper.ckeditor5_inline_plugins_tags(preset)
433
+
434
+ expect(result).to include("window.addEventListener('ckeditor:request-cjs-plugin:Plugin1'")
435
+ expect(result).to include("window.addEventListener('ckeditor:request-cjs-plugin:Plugin2'")
436
+ end
437
+
438
+ it 'adds event listeners only once' do
439
+ result = helper.ckeditor5_inline_plugins_tags(preset)
440
+
441
+ expect(result.scan("window.addEventListener('ckeditor:request-cjs-plugin:Plugin1'").count).to eq(1)
442
+ expect(result.scan("window.addEventListener('ckeditor:request-cjs-plugin:Plugin2'").count).to eq(1)
443
+ end
444
+
445
+ it('each event listener has once option') do
446
+ result = helper.ckeditor5_inline_plugins_tags(preset)
447
+
448
+ expect(result).to include('{ once: true }')
449
+ expect(result.scan('{ once: true }').length).to eq(2)
450
+ end
451
+ end
452
+
430
453
  context 'with preset having no inline plugins' do
431
454
  let(:empty_preset) do
432
455
  CKEditor5::Rails::Presets::PresetBuilder.new do
@@ -102,9 +102,7 @@ RSpec.describe CKEditor5::Rails::Context::PresetBuilder do
102
102
  it 'accepts plugin options' do
103
103
  plugin = builder.inline_plugin('Test', plugin_code)
104
104
 
105
- expect(plugin.code).to eq(
106
- '(async()=>{const{Plugin:t}=await import("ckeditor5");return class n extends t{}})();'
107
- )
105
+ expect(plugin.code).to eq("(async () => { #{plugin_code} })();")
108
106
  end
109
107
  end
110
108
 
@@ -36,3 +36,35 @@ RSpec.describe CKEditor5::Rails::Editor::PropsInlinePlugin do
36
36
  end
37
37
  end
38
38
  end
39
+
40
+ RSpec.describe CKEditor5::Rails::Editor::InlinePluginWindowInitializer do
41
+ let(:plugin) do
42
+ CKEditor5::Rails::Editor::PropsInlinePlugin.new(:CustomPlugin, 'const plugin = {}')
43
+ end
44
+
45
+ subject(:initializer) { described_class.new(plugin) }
46
+
47
+ describe '#to_html' do
48
+ it 'generates script tag with event listener' do
49
+ result = initializer.to_html
50
+
51
+ expect(result).to be_html_safe
52
+ expect(result).to include('script')
53
+ expect(result).to include("window.addEventListener('ckeditor:request-cjs-plugin:CustomPlugin'")
54
+ expect(result).to include("window['CustomPlugin']")
55
+ end
56
+
57
+ it 'adds nonce attribute when provided' do
58
+ result = initializer.to_html(nonce: 'test-nonce')
59
+
60
+ expect(result).to include('nonce="test-nonce"')
61
+ end
62
+
63
+ it 'wraps plugin code in event handler' do
64
+ result = initializer.to_html
65
+
66
+ expect(result).to include('const plugin = {}')
67
+ expect(result).to include('{ once: true }')
68
+ end
69
+ end
70
+ 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.24.0
4
+ version: 1.24.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: 2024-12-20 00:00:00.000000000 Z
12
+ date: 2024-12-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails