@ckeditor/ckeditor5-alignment 41.3.0 → 41.4.0-alpha.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.
Files changed (138) hide show
  1. package/dist/index-content.css +4 -0
  2. package/dist/index-editor.css +4 -0
  3. package/dist/index.css +4 -0
  4. package/dist/index.js +529 -0
  5. package/dist/index.js.map +1 -0
  6. package/dist/translations/af.d.ts +8 -0
  7. package/dist/translations/af.js +5 -0
  8. package/dist/translations/ar.d.ts +8 -0
  9. package/dist/translations/ar.js +5 -0
  10. package/dist/translations/az.d.ts +8 -0
  11. package/dist/translations/az.js +5 -0
  12. package/dist/translations/bg.d.ts +8 -0
  13. package/dist/translations/bg.js +5 -0
  14. package/dist/translations/bn.d.ts +8 -0
  15. package/dist/translations/bn.js +5 -0
  16. package/dist/translations/bs.d.ts +8 -0
  17. package/dist/translations/bs.js +5 -0
  18. package/dist/translations/ca.d.ts +8 -0
  19. package/dist/translations/ca.js +5 -0
  20. package/dist/translations/cs.d.ts +8 -0
  21. package/dist/translations/cs.js +5 -0
  22. package/dist/translations/da.d.ts +8 -0
  23. package/dist/translations/da.js +5 -0
  24. package/dist/translations/de-ch.d.ts +8 -0
  25. package/dist/translations/de-ch.js +5 -0
  26. package/dist/translations/de.d.ts +8 -0
  27. package/dist/translations/de.js +5 -0
  28. package/dist/translations/el.d.ts +8 -0
  29. package/dist/translations/el.js +5 -0
  30. package/dist/translations/en-au.d.ts +8 -0
  31. package/dist/translations/en-au.js +5 -0
  32. package/dist/translations/en-gb.d.ts +8 -0
  33. package/dist/translations/en-gb.js +5 -0
  34. package/dist/translations/en.d.ts +8 -0
  35. package/dist/translations/en.js +5 -0
  36. package/dist/translations/es-co.d.ts +8 -0
  37. package/dist/translations/es-co.js +5 -0
  38. package/dist/translations/es.d.ts +8 -0
  39. package/dist/translations/es.js +5 -0
  40. package/dist/translations/et.d.ts +8 -0
  41. package/dist/translations/et.js +5 -0
  42. package/dist/translations/fa.d.ts +8 -0
  43. package/dist/translations/fa.js +5 -0
  44. package/dist/translations/fi.d.ts +8 -0
  45. package/dist/translations/fi.js +5 -0
  46. package/dist/translations/fr.d.ts +8 -0
  47. package/dist/translations/fr.js +5 -0
  48. package/dist/translations/gl.d.ts +8 -0
  49. package/dist/translations/gl.js +5 -0
  50. package/dist/translations/he.d.ts +8 -0
  51. package/dist/translations/he.js +5 -0
  52. package/dist/translations/hi.d.ts +8 -0
  53. package/dist/translations/hi.js +5 -0
  54. package/dist/translations/hr.d.ts +8 -0
  55. package/dist/translations/hr.js +5 -0
  56. package/dist/translations/hu.d.ts +8 -0
  57. package/dist/translations/hu.js +5 -0
  58. package/dist/translations/id.d.ts +8 -0
  59. package/dist/translations/id.js +5 -0
  60. package/dist/translations/it.d.ts +8 -0
  61. package/dist/translations/it.js +5 -0
  62. package/dist/translations/ja.d.ts +8 -0
  63. package/dist/translations/ja.js +5 -0
  64. package/dist/translations/jv.d.ts +8 -0
  65. package/dist/translations/jv.js +5 -0
  66. package/dist/translations/kk.d.ts +8 -0
  67. package/dist/translations/kk.js +5 -0
  68. package/dist/translations/km.d.ts +8 -0
  69. package/dist/translations/km.js +5 -0
  70. package/dist/translations/ko.d.ts +8 -0
  71. package/dist/translations/ko.js +5 -0
  72. package/dist/translations/ku.d.ts +8 -0
  73. package/dist/translations/ku.js +5 -0
  74. package/dist/translations/lt.d.ts +8 -0
  75. package/dist/translations/lt.js +5 -0
  76. package/dist/translations/lv.d.ts +8 -0
  77. package/dist/translations/lv.js +5 -0
  78. package/dist/translations/ms.d.ts +8 -0
  79. package/dist/translations/ms.js +5 -0
  80. package/dist/translations/nb.d.ts +8 -0
  81. package/dist/translations/nb.js +5 -0
  82. package/dist/translations/ne.d.ts +8 -0
  83. package/dist/translations/ne.js +5 -0
  84. package/dist/translations/nl.d.ts +8 -0
  85. package/dist/translations/nl.js +5 -0
  86. package/dist/translations/no.d.ts +8 -0
  87. package/dist/translations/no.js +5 -0
  88. package/dist/translations/pl.d.ts +8 -0
  89. package/dist/translations/pl.js +5 -0
  90. package/dist/translations/pt-br.d.ts +8 -0
  91. package/dist/translations/pt-br.js +5 -0
  92. package/dist/translations/pt.d.ts +8 -0
  93. package/dist/translations/pt.js +5 -0
  94. package/dist/translations/ro.d.ts +8 -0
  95. package/dist/translations/ro.js +5 -0
  96. package/dist/translations/ru.d.ts +8 -0
  97. package/dist/translations/ru.js +5 -0
  98. package/dist/translations/sk.d.ts +8 -0
  99. package/dist/translations/sk.js +5 -0
  100. package/dist/translations/sl.d.ts +8 -0
  101. package/dist/translations/sl.js +5 -0
  102. package/dist/translations/sq.d.ts +8 -0
  103. package/dist/translations/sq.js +5 -0
  104. package/dist/translations/sr-latn.d.ts +8 -0
  105. package/dist/translations/sr-latn.js +5 -0
  106. package/dist/translations/sr.d.ts +8 -0
  107. package/dist/translations/sr.js +5 -0
  108. package/dist/translations/sv.d.ts +8 -0
  109. package/dist/translations/sv.js +5 -0
  110. package/dist/translations/th.d.ts +8 -0
  111. package/dist/translations/th.js +5 -0
  112. package/dist/translations/tk.d.ts +8 -0
  113. package/dist/translations/tk.js +5 -0
  114. package/dist/translations/tr.d.ts +8 -0
  115. package/dist/translations/tr.js +5 -0
  116. package/dist/translations/ug.d.ts +8 -0
  117. package/dist/translations/ug.js +5 -0
  118. package/dist/translations/uk.d.ts +8 -0
  119. package/dist/translations/uk.js +5 -0
  120. package/dist/translations/ur.d.ts +8 -0
  121. package/dist/translations/ur.js +5 -0
  122. package/dist/translations/uz.d.ts +8 -0
  123. package/dist/translations/uz.js +5 -0
  124. package/dist/translations/vi.d.ts +8 -0
  125. package/dist/translations/vi.js +5 -0
  126. package/dist/translations/zh-cn.d.ts +8 -0
  127. package/dist/translations/zh-cn.js +5 -0
  128. package/dist/translations/zh.d.ts +8 -0
  129. package/dist/translations/zh.js +5 -0
  130. package/dist/types/alignment.d.ts +33 -0
  131. package/dist/types/alignmentcommand.d.ts +47 -0
  132. package/dist/types/alignmentconfig.d.ts +76 -0
  133. package/dist/types/alignmentediting.d.ts +30 -0
  134. package/dist/types/alignmentui.d.ts +69 -0
  135. package/dist/types/augmentation.d.ts +27 -0
  136. package/dist/types/index.d.ts +17 -0
  137. package/dist/types/utils.d.ts +43 -0
  138. package/package.json +3 -2
@@ -0,0 +1,4 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
3
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
+ */
@@ -0,0 +1,4 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
3
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
+ */
package/dist/index.css ADDED
@@ -0,0 +1,4 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
3
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
+ */
package/dist/index.js ADDED
@@ -0,0 +1,529 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
3
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
+ */
5
+ import { Command, Plugin, icons } from '@ckeditor/ckeditor5-core/dist/index.js';
6
+ import { logWarning, CKEditorError, first } from '@ckeditor/ckeditor5-utils/dist/index.js';
7
+ import { ButtonView, createDropdown, addToolbarToDropdown, MenuBarMenuView, MenuBarMenuListView, MenuBarMenuListItemView, MenuBarMenuListItemButtonView } from '@ckeditor/ckeditor5-ui/dist/index.js';
8
+
9
+ /**
10
+ * @module alignment/utils
11
+ */ /**
12
+ * The list of supported alignment options:
13
+ *
14
+ * * `'left'`,
15
+ * * `'right'`,
16
+ * * `'center'`,
17
+ * * `'justify'`
18
+ */ const supportedOptions = [
19
+ 'left',
20
+ 'right',
21
+ 'center',
22
+ 'justify'
23
+ ];
24
+ /**
25
+ * Checks whether the passed option is supported by {@link module:alignment/alignmentediting~AlignmentEditing}.
26
+ *
27
+ * @param option The option value to check.
28
+ */ function isSupported(option) {
29
+ return supportedOptions.includes(option);
30
+ }
31
+ /**
32
+ * Checks whether alignment is the default one considering the direction
33
+ * of the editor content.
34
+ *
35
+ * @param alignment The name of the alignment to check.
36
+ * @param locale The {@link module:core/editor/editor~Editor#locale} instance.
37
+ */ function isDefault(alignment, locale) {
38
+ // Right now only LTR is supported so the 'left' value is always the default one.
39
+ if (locale.contentLanguageDirection == 'rtl') {
40
+ return alignment === 'right';
41
+ } else {
42
+ return alignment === 'left';
43
+ }
44
+ }
45
+ /**
46
+ * Brings the configuration to the common form, an array of objects.
47
+ *
48
+ * @param configuredOptions Alignment plugin configuration.
49
+ * @returns Normalized object holding the configuration.
50
+ */ function normalizeAlignmentOptions(configuredOptions) {
51
+ const normalizedOptions = configuredOptions.map((option)=>{
52
+ let result;
53
+ if (typeof option == 'string') {
54
+ result = {
55
+ name: option
56
+ };
57
+ } else {
58
+ result = option;
59
+ }
60
+ return result;
61
+ })// Remove all unknown options.
62
+ .filter((option)=>{
63
+ const isNameValid = supportedOptions.includes(option.name);
64
+ if (!isNameValid) {
65
+ /**
66
+ * The `name` in one of the `alignment.options` is not recognized.
67
+ * The available options are: `'left'`, `'right'`, `'center'` and `'justify'`.
68
+ *
69
+ * @error alignment-config-name-not-recognized
70
+ * @param option Options with unknown value of the `name` property.
71
+ */ logWarning('alignment-config-name-not-recognized', {
72
+ option
73
+ });
74
+ }
75
+ return isNameValid;
76
+ });
77
+ const classNameCount = normalizedOptions.filter((option)=>Boolean(option.className)).length;
78
+ // We either use classes for all styling options or for none.
79
+ if (classNameCount && classNameCount < normalizedOptions.length) {
80
+ /**
81
+ * The `className` property has to be defined for all options once at least one option declares `className`.
82
+ *
83
+ * @error alignment-config-classnames-are-missing
84
+ * @param configuredOptions Contents of `alignment.options`.
85
+ */ throw new CKEditorError('alignment-config-classnames-are-missing', {
86
+ configuredOptions
87
+ });
88
+ }
89
+ // Validate resulting config.
90
+ normalizedOptions.forEach((option, index, allOptions)=>{
91
+ const succeedingOptions = allOptions.slice(index + 1);
92
+ const nameAlreadyExists = succeedingOptions.some((item)=>item.name == option.name);
93
+ if (nameAlreadyExists) {
94
+ /**
95
+ * The same `name` in one of the `alignment.options` was already declared.
96
+ * Each `name` representing one alignment option can be set exactly once.
97
+ *
98
+ * @error alignment-config-name-already-defined
99
+ * @param option First option that declares given `name`.
100
+ * @param configuredOptions Contents of `alignment.options`.
101
+ */ throw new CKEditorError('alignment-config-name-already-defined', {
102
+ option,
103
+ configuredOptions
104
+ });
105
+ }
106
+ // The `className` property is present. Check for duplicates then.
107
+ if (option.className) {
108
+ const classNameAlreadyExists = succeedingOptions.some((item)=>item.className == option.className);
109
+ if (classNameAlreadyExists) {
110
+ /**
111
+ * The same `className` in one of the `alignment.options` was already declared.
112
+ *
113
+ * @error alignment-config-classname-already-defined
114
+ * @param option First option that declares given `className`.
115
+ * @param configuredOptions
116
+ * Contents of `alignment.options`.
117
+ */ throw new CKEditorError('alignment-config-classname-already-defined', {
118
+ option,
119
+ configuredOptions
120
+ });
121
+ }
122
+ }
123
+ });
124
+ return normalizedOptions;
125
+ }
126
+
127
+ const ALIGNMENT = 'alignment';
128
+ class AlignmentCommand extends Command {
129
+ /**
130
+ * @inheritDoc
131
+ */ refresh() {
132
+ const editor = this.editor;
133
+ const locale = editor.locale;
134
+ const firstBlock = first(this.editor.model.document.selection.getSelectedBlocks());
135
+ // As first check whether to enable or disable the command as the value will always be false if the command cannot be enabled.
136
+ this.isEnabled = Boolean(firstBlock) && this._canBeAligned(firstBlock);
137
+ if (this.isEnabled && firstBlock.hasAttribute('alignment')) {
138
+ this.value = firstBlock.getAttribute('alignment');
139
+ } else {
140
+ this.value = locale.contentLanguageDirection === 'rtl' ? 'right' : 'left';
141
+ }
142
+ }
143
+ /**
144
+ * Executes the command. Applies the alignment `value` to the selected blocks.
145
+ * If no `value` is passed, the `value` is the default one or it is equal to the currently selected block's alignment attribute,
146
+ * the command will remove the attribute from the selected blocks.
147
+ *
148
+ * @param options Options for the executed command.
149
+ * @param options.value The value to apply.
150
+ * @fires execute
151
+ */ execute(options = {}) {
152
+ const editor = this.editor;
153
+ const locale = editor.locale;
154
+ const model = editor.model;
155
+ const doc = model.document;
156
+ const value = options.value;
157
+ model.change((writer)=>{
158
+ // Get only those blocks from selected that can have alignment set
159
+ const blocks = Array.from(doc.selection.getSelectedBlocks()).filter((block)=>this._canBeAligned(block));
160
+ const currentAlignment = blocks[0].getAttribute('alignment');
161
+ // Remove alignment attribute if current alignment is:
162
+ // - default (should not be stored in model as it will bloat model data)
163
+ // - equal to currently set
164
+ // - or no value is passed - denotes default alignment.
165
+ const removeAlignment = isDefault(value, locale) || currentAlignment === value || !value;
166
+ if (removeAlignment) {
167
+ removeAlignmentFromSelection(blocks, writer);
168
+ } else {
169
+ setAlignmentOnSelection(blocks, writer, value);
170
+ }
171
+ });
172
+ }
173
+ /**
174
+ * Checks whether a block can have alignment set.
175
+ *
176
+ * @param block The block to be checked.
177
+ */ _canBeAligned(block) {
178
+ return this.editor.model.schema.checkAttribute(block, ALIGNMENT);
179
+ }
180
+ }
181
+ /**
182
+ * Removes the alignment attribute from blocks.
183
+ */ function removeAlignmentFromSelection(blocks, writer) {
184
+ for (const block of blocks){
185
+ writer.removeAttribute(ALIGNMENT, block);
186
+ }
187
+ }
188
+ /**
189
+ * Sets the alignment attribute on blocks.
190
+ */ function setAlignmentOnSelection(blocks, writer, alignment) {
191
+ for (const block of blocks){
192
+ writer.setAttribute(ALIGNMENT, alignment, block);
193
+ }
194
+ }
195
+
196
+ class AlignmentEditing extends Plugin {
197
+ /**
198
+ * @inheritDoc
199
+ */ static get pluginName() {
200
+ return 'AlignmentEditing';
201
+ }
202
+ /**
203
+ * @inheritDoc
204
+ */ init() {
205
+ const editor = this.editor;
206
+ const locale = editor.locale;
207
+ const schema = editor.model.schema;
208
+ const options = normalizeAlignmentOptions(editor.config.get('alignment.options'));
209
+ // Filter out unsupported options and those that are redundant, e.g. `left` in LTR / `right` in RTL mode.
210
+ const optionsToConvert = options.filter((option)=>isSupported(option.name) && !isDefault(option.name, locale));
211
+ // Once there is at least one `className` defined, we switch to alignment with classes.
212
+ const shouldUseClasses = optionsToConvert.some((option)=>!!option.className);
213
+ // Allow alignment attribute on all blocks.
214
+ schema.extend('$block', {
215
+ allowAttributes: 'alignment'
216
+ });
217
+ editor.model.schema.setAttributeProperties('alignment', {
218
+ isFormatting: true
219
+ });
220
+ if (shouldUseClasses) {
221
+ editor.conversion.attributeToAttribute(buildClassDefinition(optionsToConvert));
222
+ } else {
223
+ // Downcast inline styles.
224
+ editor.conversion.for('downcast').attributeToAttribute(buildDowncastInlineDefinition(optionsToConvert));
225
+ }
226
+ const upcastInlineDefinitions = buildUpcastInlineDefinitions(optionsToConvert);
227
+ // Always upcast from inline styles.
228
+ for (const definition of upcastInlineDefinitions){
229
+ editor.conversion.for('upcast').attributeToAttribute(definition);
230
+ }
231
+ const upcastCompatibilityDefinitions = buildUpcastCompatibilityDefinitions(optionsToConvert);
232
+ // Always upcast from deprecated `align` attribute.
233
+ for (const definition of upcastCompatibilityDefinitions){
234
+ editor.conversion.for('upcast').attributeToAttribute(definition);
235
+ }
236
+ editor.commands.add('alignment', new AlignmentCommand(editor));
237
+ }
238
+ /**
239
+ * @inheritDoc
240
+ */ constructor(editor){
241
+ super(editor);
242
+ editor.config.define('alignment', {
243
+ options: supportedOptions.map((option)=>({
244
+ name: option
245
+ }))
246
+ });
247
+ }
248
+ }
249
+ /**
250
+ * Prepare downcast conversion definition for inline alignment styling.
251
+ */ function buildDowncastInlineDefinition(options) {
252
+ const view = {};
253
+ for (const { name } of options){
254
+ view[name] = {
255
+ key: 'style',
256
+ value: {
257
+ 'text-align': name
258
+ }
259
+ };
260
+ }
261
+ const definition = {
262
+ model: {
263
+ key: 'alignment',
264
+ values: options.map((option)=>option.name)
265
+ },
266
+ view
267
+ };
268
+ return definition;
269
+ }
270
+ /**
271
+ * Prepare upcast definitions for inline alignment styles.
272
+ */ function buildUpcastInlineDefinitions(options) {
273
+ const definitions = [];
274
+ for (const { name } of options){
275
+ definitions.push({
276
+ view: {
277
+ key: 'style',
278
+ value: {
279
+ 'text-align': name
280
+ }
281
+ },
282
+ model: {
283
+ key: 'alignment',
284
+ value: name
285
+ }
286
+ });
287
+ }
288
+ return definitions;
289
+ }
290
+ /**
291
+ * Prepare upcast definitions for deprecated `align` attribute.
292
+ */ function buildUpcastCompatibilityDefinitions(options) {
293
+ const definitions = [];
294
+ for (const { name } of options){
295
+ definitions.push({
296
+ view: {
297
+ key: 'align',
298
+ value: name
299
+ },
300
+ model: {
301
+ key: 'alignment',
302
+ value: name
303
+ }
304
+ });
305
+ }
306
+ return definitions;
307
+ }
308
+ /**
309
+ * Prepare conversion definitions for upcast and downcast alignment with classes.
310
+ */ function buildClassDefinition(options) {
311
+ const view = {};
312
+ for (const option of options){
313
+ view[option.name] = {
314
+ key: 'class',
315
+ value: option.className
316
+ };
317
+ }
318
+ const definition = {
319
+ model: {
320
+ key: 'alignment',
321
+ values: options.map((option)=>option.name)
322
+ },
323
+ view
324
+ };
325
+ return definition;
326
+ }
327
+
328
+ const iconsMap = new Map([
329
+ [
330
+ 'left',
331
+ icons.alignLeft
332
+ ],
333
+ [
334
+ 'right',
335
+ icons.alignRight
336
+ ],
337
+ [
338
+ 'center',
339
+ icons.alignCenter
340
+ ],
341
+ [
342
+ 'justify',
343
+ icons.alignJustify
344
+ ]
345
+ ]);
346
+ class AlignmentUI extends Plugin {
347
+ /**
348
+ * Returns the localized option titles provided by the plugin.
349
+ *
350
+ * The following localized titles corresponding with
351
+ * {@link module:alignment/alignmentconfig~AlignmentConfig#options} are available:
352
+ *
353
+ * * `'left'`,
354
+ * * `'right'`,
355
+ * * `'center'`,
356
+ * * `'justify'`.
357
+ *
358
+ * @readonly
359
+ */ get localizedOptionTitles() {
360
+ const t = this.editor.t;
361
+ return {
362
+ 'left': t('Align left'),
363
+ 'right': t('Align right'),
364
+ 'center': t('Align center'),
365
+ 'justify': t('Justify')
366
+ };
367
+ }
368
+ /**
369
+ * @inheritDoc
370
+ */ static get pluginName() {
371
+ return 'AlignmentUI';
372
+ }
373
+ /**
374
+ * @inheritDoc
375
+ */ init() {
376
+ const editor = this.editor;
377
+ const options = normalizeAlignmentOptions(editor.config.get('alignment.options'));
378
+ options.map((option)=>option.name).filter(isSupported).forEach((option)=>this._addButton(option));
379
+ this._addToolbarDropdown(options);
380
+ this._addMenuBarMenu(options);
381
+ }
382
+ /**
383
+ * Helper method for initializing the button and linking it with an appropriate command.
384
+ *
385
+ * @param option The name of the alignment option for which the button is added.
386
+ */ _addButton(option) {
387
+ const editor = this.editor;
388
+ editor.ui.componentFactory.add(`alignment:${option}`, (locale)=>this._createButton(locale, option));
389
+ }
390
+ /**
391
+ * Helper method for creating the button view element.
392
+ *
393
+ * @param locale Editor locale.
394
+ * @param option The name of the alignment option for which the button is added.
395
+ * @param buttonAttrs Optional parameters passed to button view instance.
396
+ */ _createButton(locale, option, buttonAttrs = {}) {
397
+ const editor = this.editor;
398
+ const command = editor.commands.get('alignment');
399
+ const buttonView = new ButtonView(locale);
400
+ buttonView.set({
401
+ label: this.localizedOptionTitles[option],
402
+ icon: iconsMap.get(option),
403
+ tooltip: true,
404
+ isToggleable: true,
405
+ ...buttonAttrs
406
+ });
407
+ // Bind button model to command.
408
+ buttonView.bind('isEnabled').to(command);
409
+ buttonView.bind('isOn').to(command, 'value', (value)=>value === option);
410
+ // Execute command.
411
+ this.listenTo(buttonView, 'execute', ()=>{
412
+ editor.execute('alignment', {
413
+ value: option
414
+ });
415
+ editor.editing.view.focus();
416
+ });
417
+ return buttonView;
418
+ }
419
+ /**
420
+ * Helper method for initializing the toolnar dropdown and linking it with an appropriate command.
421
+ *
422
+ * @param option The name of the alignment option for which the button is added.
423
+ */ _addToolbarDropdown(options) {
424
+ const editor = this.editor;
425
+ const factory = editor.ui.componentFactory;
426
+ factory.add('alignment', (locale)=>{
427
+ const dropdownView = createDropdown(locale);
428
+ const tooltipPosition = locale.uiLanguageDirection === 'rtl' ? 'w' : 'e';
429
+ const t = locale.t;
430
+ // Add existing alignment buttons to dropdown's toolbar.
431
+ addToolbarToDropdown(dropdownView, ()=>options.map((option)=>this._createButton(locale, option.name, {
432
+ tooltipPosition
433
+ })), {
434
+ enableActiveItemFocusOnDropdownOpen: true,
435
+ isVertical: true,
436
+ ariaLabel: t('Text alignment toolbar')
437
+ });
438
+ // Configure dropdown properties an behavior.
439
+ dropdownView.buttonView.set({
440
+ label: t('Text alignment'),
441
+ tooltip: true
442
+ });
443
+ dropdownView.extendTemplate({
444
+ attributes: {
445
+ class: 'ck-alignment-dropdown'
446
+ }
447
+ });
448
+ // The default icon depends on the direction of the content.
449
+ const defaultIcon = locale.contentLanguageDirection === 'rtl' ? iconsMap.get('right') : iconsMap.get('left');
450
+ const command = editor.commands.get('alignment');
451
+ // Change icon to reflect current selection's alignment.
452
+ dropdownView.buttonView.bind('icon').to(command, 'value', (value)=>iconsMap.get(value) || defaultIcon);
453
+ // Enable button if any of the buttons is enabled.
454
+ dropdownView.bind('isEnabled').to(command, 'isEnabled');
455
+ // Focus the editable after executing the command.
456
+ // Overrides a default behaviour where the focus is moved to the dropdown button (#12125).
457
+ this.listenTo(dropdownView, 'execute', ()=>{
458
+ editor.editing.view.focus();
459
+ });
460
+ return dropdownView;
461
+ });
462
+ }
463
+ /**
464
+ * Creates a menu for all alignment options to use either in menu bar.
465
+ *
466
+ * @param options Normalized alignment options from config.
467
+ */ _addMenuBarMenu(options) {
468
+ const editor = this.editor;
469
+ editor.ui.componentFactory.add('menuBar:alignment', (locale)=>{
470
+ const command = editor.commands.get('alignment');
471
+ const t = locale.t;
472
+ const menuView = new MenuBarMenuView(locale);
473
+ const listView = new MenuBarMenuListView(locale);
474
+ menuView.bind('isEnabled').to(command);
475
+ listView.set({
476
+ ariaLabel: t('Text alignment'),
477
+ role: 'menu'
478
+ });
479
+ menuView.buttonView.set({
480
+ label: t('Text alignment')
481
+ });
482
+ for (const option of options){
483
+ const listItemView = new MenuBarMenuListItemView(locale, menuView);
484
+ const buttonView = new MenuBarMenuListItemButtonView(locale);
485
+ buttonView.extendTemplate({
486
+ attributes: {
487
+ 'aria-checked': buttonView.bindTemplate.to('isOn')
488
+ }
489
+ });
490
+ buttonView.delegate('execute').to(menuView);
491
+ buttonView.set({
492
+ label: this.localizedOptionTitles[option.name],
493
+ icon: iconsMap.get(option.name)
494
+ });
495
+ buttonView.on('execute', ()=>{
496
+ editor.execute('alignment', {
497
+ value: option.name
498
+ });
499
+ editor.editing.view.focus();
500
+ });
501
+ buttonView.bind('isOn').to(command, 'value', (value)=>value === option.name);
502
+ buttonView.bind('isEnabled').to(command, 'isEnabled');
503
+ listItemView.children.add(buttonView);
504
+ listView.items.add(listItemView);
505
+ }
506
+ menuView.panelView.children.add(listView);
507
+ return menuView;
508
+ });
509
+ }
510
+ }
511
+
512
+ class Alignment extends Plugin {
513
+ /**
514
+ * @inheritDoc
515
+ */ static get requires() {
516
+ return [
517
+ AlignmentEditing,
518
+ AlignmentUI
519
+ ];
520
+ }
521
+ /**
522
+ * @inheritDoc
523
+ */ static get pluginName() {
524
+ return 'Alignment';
525
+ }
526
+ }
527
+
528
+ export { Alignment, AlignmentEditing, AlignmentUI };
529
+ //# sourceMappingURL=index.js.map