ckeditor5 1.0.5 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -29,18 +29,20 @@ module CKEditor5::Rails
29
29
 
30
30
  private
31
31
 
32
- def define_default_preset
32
+ def define_default_preset # rubocop:disable Metrics/MethodLength
33
33
  define :default do
34
- shape :classic
34
+ gpl
35
+
36
+ type :classic
35
37
 
36
38
  menubar
37
39
 
38
40
  toolbar :undo, :redo, :|, :heading, :|, :bold, :italic, :underline, :|,
39
- :link, :insertImage, :ckbox, :mediaEmbed, :insertTable, :blockQuote, :|,
41
+ :link, :insertImage, :mediaEmbed, :insertTable, :blockQuote, :|,
40
42
  :bulletedList, :numberedList, :todoList, :outdent, :indent
41
43
 
42
44
  plugins :AccessibilityHelp, :Autoformat, :AutoImage, :Autosave,
43
- :BlockQuote, :Bold, :CKBox, :CKBoxImageEdit, :CloudServices,
45
+ :BlockQuote, :Bold, :CloudServices,
44
46
  :Essentials, :Heading, :ImageBlock, :ImageCaption, :ImageInline,
45
47
  :ImageInsert, :ImageInsertViaUrl, :ImageResize, :ImageStyle,
46
48
  :ImageTextAlternative, :ImageToolbar, :ImageUpload, :Indent,
@@ -49,22 +51,88 @@ module CKEditor5::Rails
49
51
  :SelectAll, :Table, :TableCaption, :TableCellProperties,
50
52
  :TableColumnResize, :TableProperties, :TableToolbar,
51
53
  :TextTransformation, :TodoList, :Underline, :Undo, :Base64UploadAdapter
54
+
55
+ configure :image, {
56
+ toolbar: ['imageTextAlternative', 'imageStyle:inline', 'imageStyle:block', 'imageStyle:side']
57
+ }
52
58
  end
53
59
  end
54
60
  end
55
61
 
56
62
  class PresetBuilder
57
- attr_reader :type, :config
63
+ attr_reader :config
58
64
 
59
65
  def initialize
66
+ @version = nil
67
+ @premium = false
68
+ @cdn = :jsdelivr
69
+ @translations = []
70
+ @license_key = nil
60
71
  @type = :classic
72
+ @ckbox = nil
61
73
  @config = {
62
74
  plugins: [],
63
75
  toolbar: []
64
76
  }
65
77
  end
66
78
 
67
- def shape(type)
79
+ def to_h_with_overrides(**overrides)
80
+ {
81
+ version: overrides.fetch(:version, version),
82
+ premium: overrides.fetch(:premium, premium),
83
+ cdn: overrides.fetch(:cdn, cdn),
84
+ translations: overrides.fetch(:translations, translations),
85
+ license_key: overrides.fetch(:license_key, license_key),
86
+ type: overrides.fetch(:type, type),
87
+ ckbox: overrides.fetch(:ckbox, ckbox),
88
+ config: config.merge(overrides.fetch(:config, {}))
89
+ }
90
+ end
91
+
92
+ def ckbox(version = nil, theme: :lark)
93
+ return @ckbox if version.nil?
94
+
95
+ @ckbox = { version: version, theme: theme }
96
+ end
97
+
98
+ def license_key(license_key = nil)
99
+ return @license_key if license_key.nil?
100
+
101
+ @license_key = license_key
102
+ end
103
+
104
+ def gpl
105
+ license_key('GPL')
106
+ premium(false)
107
+ end
108
+
109
+ def premium(premium = nil)
110
+ return @premium if premium.nil?
111
+
112
+ @premium = premium
113
+ end
114
+
115
+ def translations(*translations)
116
+ return @translations if translations.empty?
117
+
118
+ @translations = translations
119
+ end
120
+
121
+ def version(version = nil)
122
+ return @version.to_s if version.nil?
123
+
124
+ @version = Semver.new(version)
125
+ end
126
+
127
+ def cdn(cdn = nil)
128
+ return @cdn if cdn.nil?
129
+
130
+ @cdn = cdn
131
+ end
132
+
133
+ def type(type = nil)
134
+ return @type if type.nil?
135
+
68
136
  raise ArgumentError, "Invalid editor type: #{type}" unless Editor::Props.valid_editor_type?(type)
69
137
 
70
138
  @type = type
@@ -80,11 +148,22 @@ module CKEditor5::Rails
80
148
  }
81
149
  end
82
150
 
83
- def toolbar(*items, should_group_when_full: true)
84
- @config[:toolbar] = {
85
- items: items,
86
- shouldNotGroupWhenFull: !should_group_when_full
87
- }
151
+ def toolbar(*items, should_group_when_full: true, &block)
152
+ if @config[:toolbar].blank? || !items.empty?
153
+ @config[:toolbar] = {
154
+ items: items,
155
+ shouldNotGroupWhenFull: !should_group_when_full
156
+ }
157
+ end
158
+
159
+ return unless block
160
+
161
+ builder = ToolbarBuilder.new(@config[:toolbar])
162
+ builder.instance_eval(&block)
163
+ end
164
+
165
+ def inline_plugin(name, code)
166
+ @config[:plugins] << Editor::PropsInlinePlugin.new(name, code)
88
167
  end
89
168
 
90
169
  def plugin(name, **kwargs)
@@ -102,4 +181,36 @@ module CKEditor5::Rails
102
181
  }
103
182
  end
104
183
  end
184
+
185
+ class ToolbarBuilder
186
+ def initialize(toolbar_config)
187
+ @toolbar_config = toolbar_config
188
+ end
189
+
190
+ def prepend(*items, before: nil)
191
+ toolbar_items = @toolbar_config[:items]
192
+
193
+ if before
194
+ index = toolbar_items.index(before)
195
+ raise ArgumentError, "Item '#{before}' not found in toolbar" unless index
196
+
197
+ toolbar_items.insert(index, *items)
198
+ else
199
+ toolbar_items.insert(0, *items)
200
+ end
201
+ end
202
+
203
+ def append(*items, after: nil)
204
+ toolbar_items = @toolbar_config[:items]
205
+
206
+ if after
207
+ index = toolbar_items.index(after)
208
+ raise ArgumentError, "Item '#{after}' not found in toolbar" unless index
209
+
210
+ toolbar_items.insert(index + 1, *items)
211
+ else
212
+ toolbar_items.push(*items)
213
+ end
214
+ end
215
+ end
105
216
  end
@@ -6,7 +6,7 @@ class CKEditor5::Rails::Semver
6
6
  alias to_s :version
7
7
 
8
8
  def initialize(version)
9
- @version = version
9
+ @version = version.to_s
10
10
  validate!
11
11
  end
12
12
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CKEditor5::Rails
4
- VERSION = '1.0.5'
4
+ VERSION = '1.1.0'
5
5
  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.0.5
4
+ version: 1.1.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: 2024-10-31 00:00:00.000000000 Z
12
+ date: 2024-11-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -53,9 +53,12 @@ files:
53
53
  - lib/ckeditor5/rails/cloud/helpers.rb
54
54
  - lib/ckeditor5/rails/editor/helpers.rb
55
55
  - lib/ckeditor5/rails/editor/props.rb
56
+ - lib/ckeditor5/rails/editor/props_inline_plugin.rb
56
57
  - lib/ckeditor5/rails/editor/props_plugin.rb
57
58
  - lib/ckeditor5/rails/engine.rb
58
59
  - lib/ckeditor5/rails/helpers.rb
60
+ - lib/ckeditor5/rails/hooks/form.rb
61
+ - lib/ckeditor5/rails/hooks/simple_form.rb
59
62
  - lib/ckeditor5/rails/presets.rb
60
63
  - lib/ckeditor5/rails/semver.rb
61
64
  - lib/ckeditor5/rails/version.rb