@ckeditor/ckeditor5-alignment 0.0.0-internal-20241017.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 (355) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/LICENSE.md +17 -0
  3. package/README.md +26 -0
  4. package/build/alignment.js +5 -0
  5. package/build/translations/af.js +1 -0
  6. package/build/translations/ar.js +1 -0
  7. package/build/translations/az.js +1 -0
  8. package/build/translations/bg.js +1 -0
  9. package/build/translations/bn.js +1 -0
  10. package/build/translations/bs.js +1 -0
  11. package/build/translations/ca.js +1 -0
  12. package/build/translations/cs.js +1 -0
  13. package/build/translations/da.js +1 -0
  14. package/build/translations/de-ch.js +1 -0
  15. package/build/translations/de.js +1 -0
  16. package/build/translations/el.js +1 -0
  17. package/build/translations/en-au.js +1 -0
  18. package/build/translations/en-gb.js +1 -0
  19. package/build/translations/es-co.js +1 -0
  20. package/build/translations/es.js +1 -0
  21. package/build/translations/et.js +1 -0
  22. package/build/translations/fa.js +1 -0
  23. package/build/translations/fi.js +1 -0
  24. package/build/translations/fr.js +1 -0
  25. package/build/translations/gl.js +1 -0
  26. package/build/translations/he.js +1 -0
  27. package/build/translations/hi.js +1 -0
  28. package/build/translations/hr.js +1 -0
  29. package/build/translations/hu.js +1 -0
  30. package/build/translations/id.js +1 -0
  31. package/build/translations/it.js +1 -0
  32. package/build/translations/ja.js +1 -0
  33. package/build/translations/jv.js +1 -0
  34. package/build/translations/kk.js +1 -0
  35. package/build/translations/km.js +1 -0
  36. package/build/translations/ko.js +1 -0
  37. package/build/translations/ku.js +1 -0
  38. package/build/translations/lt.js +1 -0
  39. package/build/translations/lv.js +1 -0
  40. package/build/translations/ms.js +1 -0
  41. package/build/translations/nb.js +1 -0
  42. package/build/translations/ne.js +1 -0
  43. package/build/translations/nl.js +1 -0
  44. package/build/translations/no.js +1 -0
  45. package/build/translations/pl.js +1 -0
  46. package/build/translations/pt-br.js +1 -0
  47. package/build/translations/pt.js +1 -0
  48. package/build/translations/ro.js +1 -0
  49. package/build/translations/ru.js +1 -0
  50. package/build/translations/sk.js +1 -0
  51. package/build/translations/sl.js +1 -0
  52. package/build/translations/sq.js +1 -0
  53. package/build/translations/sr-latn.js +1 -0
  54. package/build/translations/sr.js +1 -0
  55. package/build/translations/sv.js +1 -0
  56. package/build/translations/th.js +1 -0
  57. package/build/translations/ti.js +1 -0
  58. package/build/translations/tk.js +1 -0
  59. package/build/translations/tr.js +1 -0
  60. package/build/translations/tt.js +1 -0
  61. package/build/translations/ug.js +1 -0
  62. package/build/translations/uk.js +1 -0
  63. package/build/translations/ur.js +1 -0
  64. package/build/translations/uz.js +1 -0
  65. package/build/translations/vi.js +1 -0
  66. package/build/translations/zh-cn.js +1 -0
  67. package/build/translations/zh.js +1 -0
  68. package/ckeditor5-metadata.json +31 -0
  69. package/dist/alignment.d.ts +37 -0
  70. package/dist/alignmentcommand.d.ts +47 -0
  71. package/dist/alignmentconfig.d.ts +76 -0
  72. package/dist/alignmentediting.d.ts +34 -0
  73. package/dist/alignmentui.d.ts +73 -0
  74. package/dist/augmentation.d.ts +27 -0
  75. package/dist/index-content.css +4 -0
  76. package/dist/index-editor.css +4 -0
  77. package/dist/index.css +4 -0
  78. package/dist/index.d.ts +17 -0
  79. package/dist/index.js +559 -0
  80. package/dist/index.js.map +1 -0
  81. package/dist/translations/af.d.ts +8 -0
  82. package/dist/translations/af.js +5 -0
  83. package/dist/translations/af.umd.js +11 -0
  84. package/dist/translations/ar.d.ts +8 -0
  85. package/dist/translations/ar.js +5 -0
  86. package/dist/translations/ar.umd.js +11 -0
  87. package/dist/translations/az.d.ts +8 -0
  88. package/dist/translations/az.js +5 -0
  89. package/dist/translations/az.umd.js +11 -0
  90. package/dist/translations/bg.d.ts +8 -0
  91. package/dist/translations/bg.js +5 -0
  92. package/dist/translations/bg.umd.js +11 -0
  93. package/dist/translations/bn.d.ts +8 -0
  94. package/dist/translations/bn.js +5 -0
  95. package/dist/translations/bn.umd.js +11 -0
  96. package/dist/translations/bs.d.ts +8 -0
  97. package/dist/translations/bs.js +5 -0
  98. package/dist/translations/bs.umd.js +11 -0
  99. package/dist/translations/ca.d.ts +8 -0
  100. package/dist/translations/ca.js +5 -0
  101. package/dist/translations/ca.umd.js +11 -0
  102. package/dist/translations/cs.d.ts +8 -0
  103. package/dist/translations/cs.js +5 -0
  104. package/dist/translations/cs.umd.js +11 -0
  105. package/dist/translations/da.d.ts +8 -0
  106. package/dist/translations/da.js +5 -0
  107. package/dist/translations/da.umd.js +11 -0
  108. package/dist/translations/de-ch.d.ts +8 -0
  109. package/dist/translations/de-ch.js +5 -0
  110. package/dist/translations/de-ch.umd.js +11 -0
  111. package/dist/translations/de.d.ts +8 -0
  112. package/dist/translations/de.js +5 -0
  113. package/dist/translations/de.umd.js +11 -0
  114. package/dist/translations/el.d.ts +8 -0
  115. package/dist/translations/el.js +5 -0
  116. package/dist/translations/el.umd.js +11 -0
  117. package/dist/translations/en-au.d.ts +8 -0
  118. package/dist/translations/en-au.js +5 -0
  119. package/dist/translations/en-au.umd.js +11 -0
  120. package/dist/translations/en-gb.d.ts +8 -0
  121. package/dist/translations/en-gb.js +5 -0
  122. package/dist/translations/en-gb.umd.js +11 -0
  123. package/dist/translations/en.d.ts +8 -0
  124. package/dist/translations/en.js +5 -0
  125. package/dist/translations/en.umd.js +11 -0
  126. package/dist/translations/es-co.d.ts +8 -0
  127. package/dist/translations/es-co.js +5 -0
  128. package/dist/translations/es-co.umd.js +11 -0
  129. package/dist/translations/es.d.ts +8 -0
  130. package/dist/translations/es.js +5 -0
  131. package/dist/translations/es.umd.js +11 -0
  132. package/dist/translations/et.d.ts +8 -0
  133. package/dist/translations/et.js +5 -0
  134. package/dist/translations/et.umd.js +11 -0
  135. package/dist/translations/fa.d.ts +8 -0
  136. package/dist/translations/fa.js +5 -0
  137. package/dist/translations/fa.umd.js +11 -0
  138. package/dist/translations/fi.d.ts +8 -0
  139. package/dist/translations/fi.js +5 -0
  140. package/dist/translations/fi.umd.js +11 -0
  141. package/dist/translations/fr.d.ts +8 -0
  142. package/dist/translations/fr.js +5 -0
  143. package/dist/translations/fr.umd.js +11 -0
  144. package/dist/translations/gl.d.ts +8 -0
  145. package/dist/translations/gl.js +5 -0
  146. package/dist/translations/gl.umd.js +11 -0
  147. package/dist/translations/he.d.ts +8 -0
  148. package/dist/translations/he.js +5 -0
  149. package/dist/translations/he.umd.js +11 -0
  150. package/dist/translations/hi.d.ts +8 -0
  151. package/dist/translations/hi.js +5 -0
  152. package/dist/translations/hi.umd.js +11 -0
  153. package/dist/translations/hr.d.ts +8 -0
  154. package/dist/translations/hr.js +5 -0
  155. package/dist/translations/hr.umd.js +11 -0
  156. package/dist/translations/hu.d.ts +8 -0
  157. package/dist/translations/hu.js +5 -0
  158. package/dist/translations/hu.umd.js +11 -0
  159. package/dist/translations/id.d.ts +8 -0
  160. package/dist/translations/id.js +5 -0
  161. package/dist/translations/id.umd.js +11 -0
  162. package/dist/translations/it.d.ts +8 -0
  163. package/dist/translations/it.js +5 -0
  164. package/dist/translations/it.umd.js +11 -0
  165. package/dist/translations/ja.d.ts +8 -0
  166. package/dist/translations/ja.js +5 -0
  167. package/dist/translations/ja.umd.js +11 -0
  168. package/dist/translations/jv.d.ts +8 -0
  169. package/dist/translations/jv.js +5 -0
  170. package/dist/translations/jv.umd.js +11 -0
  171. package/dist/translations/kk.d.ts +8 -0
  172. package/dist/translations/kk.js +5 -0
  173. package/dist/translations/kk.umd.js +11 -0
  174. package/dist/translations/km.d.ts +8 -0
  175. package/dist/translations/km.js +5 -0
  176. package/dist/translations/km.umd.js +11 -0
  177. package/dist/translations/ko.d.ts +8 -0
  178. package/dist/translations/ko.js +5 -0
  179. package/dist/translations/ko.umd.js +11 -0
  180. package/dist/translations/ku.d.ts +8 -0
  181. package/dist/translations/ku.js +5 -0
  182. package/dist/translations/ku.umd.js +11 -0
  183. package/dist/translations/lt.d.ts +8 -0
  184. package/dist/translations/lt.js +5 -0
  185. package/dist/translations/lt.umd.js +11 -0
  186. package/dist/translations/lv.d.ts +8 -0
  187. package/dist/translations/lv.js +5 -0
  188. package/dist/translations/lv.umd.js +11 -0
  189. package/dist/translations/ms.d.ts +8 -0
  190. package/dist/translations/ms.js +5 -0
  191. package/dist/translations/ms.umd.js +11 -0
  192. package/dist/translations/nb.d.ts +8 -0
  193. package/dist/translations/nb.js +5 -0
  194. package/dist/translations/nb.umd.js +11 -0
  195. package/dist/translations/ne.d.ts +8 -0
  196. package/dist/translations/ne.js +5 -0
  197. package/dist/translations/ne.umd.js +11 -0
  198. package/dist/translations/nl.d.ts +8 -0
  199. package/dist/translations/nl.js +5 -0
  200. package/dist/translations/nl.umd.js +11 -0
  201. package/dist/translations/no.d.ts +8 -0
  202. package/dist/translations/no.js +5 -0
  203. package/dist/translations/no.umd.js +11 -0
  204. package/dist/translations/pl.d.ts +8 -0
  205. package/dist/translations/pl.js +5 -0
  206. package/dist/translations/pl.umd.js +11 -0
  207. package/dist/translations/pt-br.d.ts +8 -0
  208. package/dist/translations/pt-br.js +5 -0
  209. package/dist/translations/pt-br.umd.js +11 -0
  210. package/dist/translations/pt.d.ts +8 -0
  211. package/dist/translations/pt.js +5 -0
  212. package/dist/translations/pt.umd.js +11 -0
  213. package/dist/translations/ro.d.ts +8 -0
  214. package/dist/translations/ro.js +5 -0
  215. package/dist/translations/ro.umd.js +11 -0
  216. package/dist/translations/ru.d.ts +8 -0
  217. package/dist/translations/ru.js +5 -0
  218. package/dist/translations/ru.umd.js +11 -0
  219. package/dist/translations/sk.d.ts +8 -0
  220. package/dist/translations/sk.js +5 -0
  221. package/dist/translations/sk.umd.js +11 -0
  222. package/dist/translations/sl.d.ts +8 -0
  223. package/dist/translations/sl.js +5 -0
  224. package/dist/translations/sl.umd.js +11 -0
  225. package/dist/translations/sq.d.ts +8 -0
  226. package/dist/translations/sq.js +5 -0
  227. package/dist/translations/sq.umd.js +11 -0
  228. package/dist/translations/sr-latn.d.ts +8 -0
  229. package/dist/translations/sr-latn.js +5 -0
  230. package/dist/translations/sr-latn.umd.js +11 -0
  231. package/dist/translations/sr.d.ts +8 -0
  232. package/dist/translations/sr.js +5 -0
  233. package/dist/translations/sr.umd.js +11 -0
  234. package/dist/translations/sv.d.ts +8 -0
  235. package/dist/translations/sv.js +5 -0
  236. package/dist/translations/sv.umd.js +11 -0
  237. package/dist/translations/th.d.ts +8 -0
  238. package/dist/translations/th.js +5 -0
  239. package/dist/translations/th.umd.js +11 -0
  240. package/dist/translations/ti.d.ts +8 -0
  241. package/dist/translations/ti.js +5 -0
  242. package/dist/translations/ti.umd.js +11 -0
  243. package/dist/translations/tk.d.ts +8 -0
  244. package/dist/translations/tk.js +5 -0
  245. package/dist/translations/tk.umd.js +11 -0
  246. package/dist/translations/tr.d.ts +8 -0
  247. package/dist/translations/tr.js +5 -0
  248. package/dist/translations/tr.umd.js +11 -0
  249. package/dist/translations/tt.d.ts +8 -0
  250. package/dist/translations/tt.js +5 -0
  251. package/dist/translations/tt.umd.js +11 -0
  252. package/dist/translations/ug.d.ts +8 -0
  253. package/dist/translations/ug.js +5 -0
  254. package/dist/translations/ug.umd.js +11 -0
  255. package/dist/translations/uk.d.ts +8 -0
  256. package/dist/translations/uk.js +5 -0
  257. package/dist/translations/uk.umd.js +11 -0
  258. package/dist/translations/ur.d.ts +8 -0
  259. package/dist/translations/ur.js +5 -0
  260. package/dist/translations/ur.umd.js +11 -0
  261. package/dist/translations/uz.d.ts +8 -0
  262. package/dist/translations/uz.js +5 -0
  263. package/dist/translations/uz.umd.js +11 -0
  264. package/dist/translations/vi.d.ts +8 -0
  265. package/dist/translations/vi.js +5 -0
  266. package/dist/translations/vi.umd.js +11 -0
  267. package/dist/translations/zh-cn.d.ts +8 -0
  268. package/dist/translations/zh-cn.js +5 -0
  269. package/dist/translations/zh-cn.umd.js +11 -0
  270. package/dist/translations/zh.d.ts +8 -0
  271. package/dist/translations/zh.js +5 -0
  272. package/dist/translations/zh.umd.js +11 -0
  273. package/dist/utils.d.ts +43 -0
  274. package/lang/contexts.json +8 -0
  275. package/lang/translations/af.po +42 -0
  276. package/lang/translations/ar.po +42 -0
  277. package/lang/translations/az.po +42 -0
  278. package/lang/translations/bg.po +42 -0
  279. package/lang/translations/bn.po +42 -0
  280. package/lang/translations/bs.po +42 -0
  281. package/lang/translations/ca.po +42 -0
  282. package/lang/translations/cs.po +42 -0
  283. package/lang/translations/da.po +42 -0
  284. package/lang/translations/de-ch.po +42 -0
  285. package/lang/translations/de.po +42 -0
  286. package/lang/translations/el.po +42 -0
  287. package/lang/translations/en-au.po +42 -0
  288. package/lang/translations/en-gb.po +42 -0
  289. package/lang/translations/en.po +42 -0
  290. package/lang/translations/es-co.po +42 -0
  291. package/lang/translations/es.po +42 -0
  292. package/lang/translations/et.po +42 -0
  293. package/lang/translations/fa.po +42 -0
  294. package/lang/translations/fi.po +42 -0
  295. package/lang/translations/fr.po +42 -0
  296. package/lang/translations/gl.po +42 -0
  297. package/lang/translations/he.po +42 -0
  298. package/lang/translations/hi.po +42 -0
  299. package/lang/translations/hr.po +42 -0
  300. package/lang/translations/hu.po +42 -0
  301. package/lang/translations/id.po +42 -0
  302. package/lang/translations/it.po +42 -0
  303. package/lang/translations/ja.po +42 -0
  304. package/lang/translations/jv.po +42 -0
  305. package/lang/translations/kk.po +42 -0
  306. package/lang/translations/km.po +42 -0
  307. package/lang/translations/ko.po +42 -0
  308. package/lang/translations/ku.po +42 -0
  309. package/lang/translations/lt.po +42 -0
  310. package/lang/translations/lv.po +42 -0
  311. package/lang/translations/ms.po +42 -0
  312. package/lang/translations/nb.po +42 -0
  313. package/lang/translations/ne.po +42 -0
  314. package/lang/translations/nl.po +42 -0
  315. package/lang/translations/no.po +42 -0
  316. package/lang/translations/pl.po +42 -0
  317. package/lang/translations/pt-br.po +42 -0
  318. package/lang/translations/pt.po +42 -0
  319. package/lang/translations/ro.po +42 -0
  320. package/lang/translations/ru.po +42 -0
  321. package/lang/translations/sk.po +42 -0
  322. package/lang/translations/sl.po +42 -0
  323. package/lang/translations/sq.po +42 -0
  324. package/lang/translations/sr-latn.po +42 -0
  325. package/lang/translations/sr.po +42 -0
  326. package/lang/translations/sv.po +42 -0
  327. package/lang/translations/th.po +42 -0
  328. package/lang/translations/ti.po +42 -0
  329. package/lang/translations/tk.po +42 -0
  330. package/lang/translations/tr.po +42 -0
  331. package/lang/translations/tt.po +42 -0
  332. package/lang/translations/ug.po +42 -0
  333. package/lang/translations/uk.po +42 -0
  334. package/lang/translations/ur.po +42 -0
  335. package/lang/translations/uz.po +42 -0
  336. package/lang/translations/vi.po +42 -0
  337. package/lang/translations/zh-cn.po +42 -0
  338. package/lang/translations/zh.po +42 -0
  339. package/package.json +41 -0
  340. package/src/alignment.d.ts +33 -0
  341. package/src/alignment.js +39 -0
  342. package/src/alignmentcommand.d.ts +43 -0
  343. package/src/alignmentcommand.js +88 -0
  344. package/src/alignmentconfig.d.ts +72 -0
  345. package/src/alignmentconfig.js +5 -0
  346. package/src/alignmentediting.d.ts +30 -0
  347. package/src/alignmentediting.js +153 -0
  348. package/src/alignmentui.d.ts +69 -0
  349. package/src/alignmentui.js +194 -0
  350. package/src/augmentation.d.ts +23 -0
  351. package/src/augmentation.js +5 -0
  352. package/src/index.d.ts +13 -0
  353. package/src/index.js +11 -0
  354. package/src/utils.d.ts +39 -0
  355. package/src/utils.js +118 -0
@@ -0,0 +1,194 @@
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
+ /**
6
+ * @module alignment/alignmentui
7
+ */
8
+ import { Plugin, icons } from 'ckeditor5/src/core.js';
9
+ import { ButtonView, createDropdown, addToolbarToDropdown, MenuBarMenuListItemView, MenuBarMenuListItemButtonView, MenuBarMenuView, MenuBarMenuListView } from 'ckeditor5/src/ui.js';
10
+ import { isSupported, normalizeAlignmentOptions } from './utils.js';
11
+ const iconsMap = /* #__PURE__ */ (() => new Map([
12
+ ['left', icons.alignLeft],
13
+ ['right', icons.alignRight],
14
+ ['center', icons.alignCenter],
15
+ ['justify', icons.alignJustify]
16
+ ]))();
17
+ /**
18
+ * The default alignment UI plugin.
19
+ *
20
+ * It introduces the `'alignment:left'`, `'alignment:right'`, `'alignment:center'` and `'alignment:justify'` buttons
21
+ * and the `'alignment'` dropdown.
22
+ */
23
+ export default class AlignmentUI extends Plugin {
24
+ /**
25
+ * Returns the localized option titles provided by the plugin.
26
+ *
27
+ * The following localized titles corresponding with
28
+ * {@link module:alignment/alignmentconfig~AlignmentConfig#options} are available:
29
+ *
30
+ * * `'left'`,
31
+ * * `'right'`,
32
+ * * `'center'`,
33
+ * * `'justify'`.
34
+ *
35
+ * @readonly
36
+ */
37
+ get localizedOptionTitles() {
38
+ const t = this.editor.t;
39
+ return {
40
+ 'left': t('Align left'),
41
+ 'right': t('Align right'),
42
+ 'center': t('Align center'),
43
+ 'justify': t('Justify')
44
+ };
45
+ }
46
+ /**
47
+ * @inheritDoc
48
+ */
49
+ static get pluginName() {
50
+ return 'AlignmentUI';
51
+ }
52
+ /**
53
+ * @inheritDoc
54
+ */
55
+ static get isOfficialPlugin() {
56
+ return true;
57
+ }
58
+ /**
59
+ * @inheritDoc
60
+ */
61
+ init() {
62
+ const editor = this.editor;
63
+ const options = normalizeAlignmentOptions(editor.config.get('alignment.options'));
64
+ options
65
+ .map(option => option.name)
66
+ .filter(isSupported)
67
+ .forEach(option => this._addButton(option));
68
+ this._addToolbarDropdown(options);
69
+ this._addMenuBarMenu(options);
70
+ }
71
+ /**
72
+ * Helper method for initializing the button and linking it with an appropriate command.
73
+ *
74
+ * @param option The name of the alignment option for which the button is added.
75
+ */
76
+ _addButton(option) {
77
+ const editor = this.editor;
78
+ editor.ui.componentFactory.add(`alignment:${option}`, locale => this._createButton(locale, option));
79
+ }
80
+ /**
81
+ * Helper method for creating the button view element.
82
+ *
83
+ * @param locale Editor locale.
84
+ * @param option The name of the alignment option for which the button is added.
85
+ * @param buttonAttrs Optional parameters passed to button view instance.
86
+ */
87
+ _createButton(locale, option, buttonAttrs = {}) {
88
+ const editor = this.editor;
89
+ const command = editor.commands.get('alignment');
90
+ const buttonView = new ButtonView(locale);
91
+ buttonView.set({
92
+ label: this.localizedOptionTitles[option],
93
+ icon: iconsMap.get(option),
94
+ tooltip: true,
95
+ isToggleable: true,
96
+ ...buttonAttrs
97
+ });
98
+ // Bind button model to command.
99
+ buttonView.bind('isEnabled').to(command);
100
+ buttonView.bind('isOn').to(command, 'value', value => value === option);
101
+ // Execute command.
102
+ this.listenTo(buttonView, 'execute', () => {
103
+ editor.execute('alignment', { value: option });
104
+ editor.editing.view.focus();
105
+ });
106
+ return buttonView;
107
+ }
108
+ /**
109
+ * Helper method for initializing the toolnar dropdown and linking it with an appropriate command.
110
+ *
111
+ * @param option The name of the alignment option for which the button is added.
112
+ */
113
+ _addToolbarDropdown(options) {
114
+ const editor = this.editor;
115
+ const factory = editor.ui.componentFactory;
116
+ factory.add('alignment', locale => {
117
+ const dropdownView = createDropdown(locale);
118
+ const tooltipPosition = locale.uiLanguageDirection === 'rtl' ? 'w' : 'e';
119
+ const t = locale.t;
120
+ // Add existing alignment buttons to dropdown's toolbar.
121
+ addToolbarToDropdown(dropdownView, () => options.map(option => this._createButton(locale, option.name, { tooltipPosition })), {
122
+ enableActiveItemFocusOnDropdownOpen: true,
123
+ isVertical: true,
124
+ ariaLabel: t('Text alignment toolbar')
125
+ });
126
+ // Configure dropdown properties an behavior.
127
+ dropdownView.buttonView.set({
128
+ label: t('Text alignment'),
129
+ tooltip: true
130
+ });
131
+ dropdownView.extendTemplate({
132
+ attributes: {
133
+ class: 'ck-alignment-dropdown'
134
+ }
135
+ });
136
+ // The default icon depends on the direction of the content.
137
+ const defaultIcon = locale.contentLanguageDirection === 'rtl' ? iconsMap.get('right') : iconsMap.get('left');
138
+ const command = editor.commands.get('alignment');
139
+ // Change icon to reflect current selection's alignment.
140
+ dropdownView.buttonView.bind('icon').to(command, 'value', value => iconsMap.get(value) || defaultIcon);
141
+ // Enable button if any of the buttons is enabled.
142
+ dropdownView.bind('isEnabled').to(command, 'isEnabled');
143
+ // Focus the editable after executing the command.
144
+ // Overrides a default behaviour where the focus is moved to the dropdown button (#12125).
145
+ this.listenTo(dropdownView, 'execute', () => {
146
+ editor.editing.view.focus();
147
+ });
148
+ return dropdownView;
149
+ });
150
+ }
151
+ /**
152
+ * Creates a menu for all alignment options to use either in menu bar.
153
+ *
154
+ * @param options Normalized alignment options from config.
155
+ */
156
+ _addMenuBarMenu(options) {
157
+ const editor = this.editor;
158
+ editor.ui.componentFactory.add('menuBar:alignment', locale => {
159
+ const command = editor.commands.get('alignment');
160
+ const t = locale.t;
161
+ const menuView = new MenuBarMenuView(locale);
162
+ const listView = new MenuBarMenuListView(locale);
163
+ menuView.bind('isEnabled').to(command);
164
+ listView.set({
165
+ ariaLabel: t('Text alignment'),
166
+ role: 'menu'
167
+ });
168
+ menuView.buttonView.set({
169
+ label: t('Text alignment')
170
+ });
171
+ for (const option of options) {
172
+ const listItemView = new MenuBarMenuListItemView(locale, menuView);
173
+ const buttonView = new MenuBarMenuListItemButtonView(locale);
174
+ buttonView.delegate('execute').to(menuView);
175
+ buttonView.set({
176
+ label: this.localizedOptionTitles[option.name],
177
+ icon: iconsMap.get(option.name),
178
+ role: 'menuitemcheckbox',
179
+ isToggleable: true
180
+ });
181
+ buttonView.on('execute', () => {
182
+ editor.execute('alignment', { value: option.name });
183
+ editor.editing.view.focus();
184
+ });
185
+ buttonView.bind('isOn').to(command, 'value', value => value === option.name);
186
+ buttonView.bind('isEnabled').to(command, 'isEnabled');
187
+ listItemView.children.add(buttonView);
188
+ listView.items.add(listItemView);
189
+ }
190
+ menuView.panelView.children.add(listView);
191
+ return menuView;
192
+ });
193
+ }
194
+ }
@@ -0,0 +1,23 @@
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 type { Alignment, AlignmentEditing, AlignmentUI, AlignmentCommand, AlignmentConfig } from './index.js';
6
+ declare module '@ckeditor/ckeditor5-core' {
7
+ interface EditorConfig {
8
+ /**
9
+ * The configuration of the {@link module:alignment/alignment~Alignment alignment feature}.
10
+ *
11
+ * Read more in {@link module:alignment/alignmentconfig~AlignmentConfig}.
12
+ */
13
+ alignment?: AlignmentConfig;
14
+ }
15
+ interface PluginsMap {
16
+ [Alignment.pluginName]: Alignment;
17
+ [AlignmentUI.pluginName]: AlignmentUI;
18
+ [AlignmentEditing.pluginName]: AlignmentEditing;
19
+ }
20
+ interface CommandsMap {
21
+ alignment: AlignmentCommand;
22
+ }
23
+ }
@@ -0,0 +1,5 @@
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
+ export {};
package/src/index.d.ts ADDED
@@ -0,0 +1,13 @@
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
+ /**
6
+ * @module alignment
7
+ */
8
+ export { default as Alignment } from './alignment.js';
9
+ export { default as AlignmentEditing } from './alignmentediting.js';
10
+ export { default as AlignmentUI } from './alignmentui.js';
11
+ export type { default as AlignmentCommand } from './alignmentcommand.js';
12
+ export type { AlignmentConfig } from './alignmentconfig.js';
13
+ import './augmentation.js';
package/src/index.js ADDED
@@ -0,0 +1,11 @@
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
+ /**
6
+ * @module alignment
7
+ */
8
+ export { default as Alignment } from './alignment.js';
9
+ export { default as AlignmentEditing } from './alignmentediting.js';
10
+ export { default as AlignmentUI } from './alignmentui.js';
11
+ import './augmentation.js';
package/src/utils.d.ts ADDED
@@ -0,0 +1,39 @@
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 { type Locale } from 'ckeditor5/src/utils.js';
6
+ import type { AlignmentFormat, SupportedOption } from './alignmentconfig.js';
7
+ /**
8
+ * @module alignment/utils
9
+ */
10
+ /**
11
+ * The list of supported alignment options:
12
+ *
13
+ * * `'left'`,
14
+ * * `'right'`,
15
+ * * `'center'`,
16
+ * * `'justify'`
17
+ */
18
+ export declare const supportedOptions: ReadonlyArray<SupportedOption>;
19
+ /**
20
+ * Checks whether the passed option is supported by {@link module:alignment/alignmentediting~AlignmentEditing}.
21
+ *
22
+ * @param option The option value to check.
23
+ */
24
+ export declare function isSupported(option: string): boolean;
25
+ /**
26
+ * Checks whether alignment is the default one considering the direction
27
+ * of the editor content.
28
+ *
29
+ * @param alignment The name of the alignment to check.
30
+ * @param locale The {@link module:core/editor/editor~Editor#locale} instance.
31
+ */
32
+ export declare function isDefault(alignment: string, locale: Locale): boolean;
33
+ /**
34
+ * Brings the configuration to the common form, an array of objects.
35
+ *
36
+ * @param configuredOptions Alignment plugin configuration.
37
+ * @returns Normalized object holding the configuration.
38
+ */
39
+ export declare function normalizeAlignmentOptions(configuredOptions: Array<string | AlignmentFormat>): Array<AlignmentFormat>;
package/src/utils.js ADDED
@@ -0,0 +1,118 @@
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 { CKEditorError, logWarning } from 'ckeditor5/src/utils.js';
6
+ /**
7
+ * @module alignment/utils
8
+ */
9
+ /**
10
+ * The list of supported alignment options:
11
+ *
12
+ * * `'left'`,
13
+ * * `'right'`,
14
+ * * `'center'`,
15
+ * * `'justify'`
16
+ */
17
+ export const supportedOptions = ['left', 'right', 'center', 'justify'];
18
+ /**
19
+ * Checks whether the passed option is supported by {@link module:alignment/alignmentediting~AlignmentEditing}.
20
+ *
21
+ * @param option The option value to check.
22
+ */
23
+ export function isSupported(option) {
24
+ return supportedOptions.includes(option);
25
+ }
26
+ /**
27
+ * Checks whether alignment is the default one considering the direction
28
+ * of the editor content.
29
+ *
30
+ * @param alignment The name of the alignment to check.
31
+ * @param locale The {@link module:core/editor/editor~Editor#locale} instance.
32
+ */
33
+ export function isDefault(alignment, locale) {
34
+ // Right now only LTR is supported so the 'left' value is always the default one.
35
+ if (locale.contentLanguageDirection == 'rtl') {
36
+ return alignment === 'right';
37
+ }
38
+ else {
39
+ return alignment === 'left';
40
+ }
41
+ }
42
+ /**
43
+ * Brings the configuration to the common form, an array of objects.
44
+ *
45
+ * @param configuredOptions Alignment plugin configuration.
46
+ * @returns Normalized object holding the configuration.
47
+ */
48
+ export function normalizeAlignmentOptions(configuredOptions) {
49
+ const normalizedOptions = configuredOptions
50
+ .map(option => {
51
+ let result;
52
+ if (typeof option == 'string') {
53
+ result = { name: option };
54
+ }
55
+ else {
56
+ result = option;
57
+ }
58
+ return result;
59
+ })
60
+ // Remove all unknown options.
61
+ .filter(option => {
62
+ const isNameValid = supportedOptions.includes(option.name);
63
+ if (!isNameValid) {
64
+ /**
65
+ * The `name` in one of the `alignment.options` is not recognized.
66
+ * The available options are: `'left'`, `'right'`, `'center'` and `'justify'`.
67
+ *
68
+ * @error alignment-config-name-not-recognized
69
+ * @param option Options with unknown value of the `name` property.
70
+ */
71
+ logWarning('alignment-config-name-not-recognized', { option });
72
+ }
73
+ return isNameValid;
74
+ });
75
+ const classNameCount = normalizedOptions.filter(option => Boolean(option.className)).length;
76
+ // We either use classes for all styling options or for none.
77
+ if (classNameCount && classNameCount < normalizedOptions.length) {
78
+ /**
79
+ * The `className` property has to be defined for all options once at least one option declares `className`.
80
+ *
81
+ * @error alignment-config-classnames-are-missing
82
+ * @param configuredOptions Contents of `alignment.options`.
83
+ */
84
+ throw new CKEditorError('alignment-config-classnames-are-missing', { configuredOptions });
85
+ }
86
+ // Validate resulting config.
87
+ normalizedOptions.forEach((option, index, allOptions) => {
88
+ const succeedingOptions = allOptions.slice(index + 1);
89
+ const nameAlreadyExists = succeedingOptions.some(item => item.name == option.name);
90
+ if (nameAlreadyExists) {
91
+ /**
92
+ * The same `name` in one of the `alignment.options` was already declared.
93
+ * Each `name` representing one alignment option can be set exactly once.
94
+ *
95
+ * @error alignment-config-name-already-defined
96
+ * @param option First option that declares given `name`.
97
+ * @param configuredOptions Contents of `alignment.options`.
98
+ */
99
+ throw new CKEditorError('alignment-config-name-already-defined', { option, configuredOptions });
100
+ }
101
+ // The `className` property is present. Check for duplicates then.
102
+ if (option.className) {
103
+ const classNameAlreadyExists = succeedingOptions.some(item => item.className == option.className);
104
+ if (classNameAlreadyExists) {
105
+ /**
106
+ * The same `className` in one of the `alignment.options` was already declared.
107
+ *
108
+ * @error alignment-config-classname-already-defined
109
+ * @param option First option that declares given `className`.
110
+ * @param configuredOptions
111
+ * Contents of `alignment.options`.
112
+ */
113
+ throw new CKEditorError('alignment-config-classname-already-defined', { option, configuredOptions });
114
+ }
115
+ }
116
+ });
117
+ return normalizedOptions;
118
+ }