@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,73 @@
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
+ * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
7
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
8
+ */
9
+ /**
10
+ * @module alignment/alignmentui
11
+ */
12
+ import { Plugin } from 'ckeditor5/src/core.js';
13
+ import type { SupportedOption } from './alignmentconfig.js';
14
+ /**
15
+ * The default alignment UI plugin.
16
+ *
17
+ * It introduces the `'alignment:left'`, `'alignment:right'`, `'alignment:center'` and `'alignment:justify'` buttons
18
+ * and the `'alignment'` dropdown.
19
+ */
20
+ export default class AlignmentUI extends Plugin {
21
+ /**
22
+ * Returns the localized option titles provided by the plugin.
23
+ *
24
+ * The following localized titles corresponding with
25
+ * {@link module:alignment/alignmentconfig~AlignmentConfig#options} are available:
26
+ *
27
+ * * `'left'`,
28
+ * * `'right'`,
29
+ * * `'center'`,
30
+ * * `'justify'`.
31
+ *
32
+ * @readonly
33
+ */
34
+ get localizedOptionTitles(): Record<SupportedOption, string>;
35
+ /**
36
+ * @inheritDoc
37
+ */
38
+ static get pluginName(): "AlignmentUI";
39
+ /**
40
+ * @inheritDoc
41
+ */
42
+ static get isOfficialPlugin(): true;
43
+ /**
44
+ * @inheritDoc
45
+ */
46
+ init(): void;
47
+ /**
48
+ * Helper method for initializing the button and linking it with an appropriate command.
49
+ *
50
+ * @param option The name of the alignment option for which the button is added.
51
+ */
52
+ private _addButton;
53
+ /**
54
+ * Helper method for creating the button view element.
55
+ *
56
+ * @param locale Editor locale.
57
+ * @param option The name of the alignment option for which the button is added.
58
+ * @param buttonAttrs Optional parameters passed to button view instance.
59
+ */
60
+ private _createButton;
61
+ /**
62
+ * Helper method for initializing the toolnar dropdown and linking it with an appropriate command.
63
+ *
64
+ * @param option The name of the alignment option for which the button is added.
65
+ */
66
+ private _addToolbarDropdown;
67
+ /**
68
+ * Creates a menu for all alignment options to use either in menu bar.
69
+ *
70
+ * @param options Normalized alignment options from config.
71
+ */
72
+ private _addMenuBarMenu;
73
+ }
@@ -0,0 +1,27 @@
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
+ * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
7
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
8
+ */
9
+ import type { Alignment, AlignmentEditing, AlignmentUI, AlignmentCommand, AlignmentConfig } from './index.js';
10
+ declare module '@ckeditor/ckeditor5-core' {
11
+ interface EditorConfig {
12
+ /**
13
+ * The configuration of the {@link module:alignment/alignment~Alignment alignment feature}.
14
+ *
15
+ * Read more in {@link module:alignment/alignmentconfig~AlignmentConfig}.
16
+ */
17
+ alignment?: AlignmentConfig;
18
+ }
19
+ interface PluginsMap {
20
+ [Alignment.pluginName]: Alignment;
21
+ [AlignmentUI.pluginName]: AlignmentUI;
22
+ [AlignmentEditing.pluginName]: AlignmentEditing;
23
+ }
24
+ interface CommandsMap {
25
+ alignment: AlignmentCommand;
26
+ }
27
+ }
@@ -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
+ */
@@ -0,0 +1,17 @@
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
+ * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
7
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
8
+ */
9
+ /**
10
+ * @module alignment
11
+ */
12
+ export { default as Alignment } from './alignment.js';
13
+ export { default as AlignmentEditing } from './alignmentediting.js';
14
+ export { default as AlignmentUI } from './alignmentui.js';
15
+ export type { default as AlignmentCommand } from './alignmentcommand.js';
16
+ export type { AlignmentConfig } from './alignmentconfig.js';
17
+ import './augmentation.js';
package/dist/index.js ADDED
@@ -0,0 +1,559 @@
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
+ /**
129
+ * The alignment command plugin.
130
+ */ class AlignmentCommand extends Command {
131
+ /**
132
+ * @inheritDoc
133
+ */ refresh() {
134
+ const editor = this.editor;
135
+ const locale = editor.locale;
136
+ const firstBlock = first(this.editor.model.document.selection.getSelectedBlocks());
137
+ // As first check whether to enable or disable the command as the value will always be false if the command cannot be enabled.
138
+ this.isEnabled = Boolean(firstBlock) && this._canBeAligned(firstBlock);
139
+ if (this.isEnabled && firstBlock.hasAttribute('alignment')) {
140
+ this.value = firstBlock.getAttribute('alignment');
141
+ } else {
142
+ this.value = locale.contentLanguageDirection === 'rtl' ? 'right' : 'left';
143
+ }
144
+ }
145
+ /**
146
+ * Executes the command. Applies the alignment `value` to the selected blocks.
147
+ * If no `value` is passed, the `value` is the default one or it is equal to the currently selected block's alignment attribute,
148
+ * the command will remove the attribute from the selected blocks.
149
+ *
150
+ * @param options Options for the executed command.
151
+ * @param options.value The value to apply.
152
+ * @fires execute
153
+ */ execute(options = {}) {
154
+ const editor = this.editor;
155
+ const locale = editor.locale;
156
+ const model = editor.model;
157
+ const doc = model.document;
158
+ const value = options.value;
159
+ model.change((writer)=>{
160
+ // Get only those blocks from selected that can have alignment set
161
+ const blocks = Array.from(doc.selection.getSelectedBlocks()).filter((block)=>this._canBeAligned(block));
162
+ const currentAlignment = blocks[0].getAttribute('alignment');
163
+ // Remove alignment attribute if current alignment is:
164
+ // - default (should not be stored in model as it will bloat model data)
165
+ // - equal to currently set
166
+ // - or no value is passed - denotes default alignment.
167
+ const removeAlignment = isDefault(value, locale) || currentAlignment === value || !value;
168
+ if (removeAlignment) {
169
+ removeAlignmentFromSelection(blocks, writer);
170
+ } else {
171
+ setAlignmentOnSelection(blocks, writer, value);
172
+ }
173
+ });
174
+ }
175
+ /**
176
+ * Checks whether a block can have alignment set.
177
+ *
178
+ * @param block The block to be checked.
179
+ */ _canBeAligned(block) {
180
+ return this.editor.model.schema.checkAttribute(block, ALIGNMENT);
181
+ }
182
+ }
183
+ /**
184
+ * Removes the alignment attribute from blocks.
185
+ */ function removeAlignmentFromSelection(blocks, writer) {
186
+ for (const block of blocks){
187
+ writer.removeAttribute(ALIGNMENT, block);
188
+ }
189
+ }
190
+ /**
191
+ * Sets the alignment attribute on blocks.
192
+ */ function setAlignmentOnSelection(blocks, writer, alignment) {
193
+ for (const block of blocks){
194
+ writer.setAttribute(ALIGNMENT, alignment, block);
195
+ }
196
+ }
197
+
198
+ /**
199
+ * The alignment editing feature. It introduces the {@link module:alignment/alignmentcommand~AlignmentCommand command} and adds
200
+ * the `alignment` attribute for block elements in the {@link module:engine/model/model~Model model}.
201
+ */ class AlignmentEditing extends Plugin {
202
+ /**
203
+ * @inheritDoc
204
+ */ static get pluginName() {
205
+ return 'AlignmentEditing';
206
+ }
207
+ /**
208
+ * @inheritDoc
209
+ */ static get isOfficialPlugin() {
210
+ return true;
211
+ }
212
+ /**
213
+ * @inheritDoc
214
+ */ constructor(editor){
215
+ super(editor);
216
+ editor.config.define('alignment', {
217
+ options: supportedOptions.map((option)=>({
218
+ name: option
219
+ }))
220
+ });
221
+ }
222
+ /**
223
+ * @inheritDoc
224
+ */ init() {
225
+ const editor = this.editor;
226
+ const locale = editor.locale;
227
+ const schema = editor.model.schema;
228
+ const options = normalizeAlignmentOptions(editor.config.get('alignment.options'));
229
+ // Filter out unsupported options and those that are redundant, e.g. `left` in LTR / `right` in RTL mode.
230
+ const optionsToConvert = options.filter((option)=>isSupported(option.name) && !isDefault(option.name, locale));
231
+ // Once there is at least one `className` defined, we switch to alignment with classes.
232
+ const shouldUseClasses = optionsToConvert.some((option)=>!!option.className);
233
+ // Allow alignment attribute on all blocks.
234
+ schema.extend('$block', {
235
+ allowAttributes: 'alignment'
236
+ });
237
+ editor.model.schema.setAttributeProperties('alignment', {
238
+ isFormatting: true
239
+ });
240
+ if (shouldUseClasses) {
241
+ editor.conversion.attributeToAttribute(buildClassDefinition(optionsToConvert));
242
+ } else {
243
+ // Downcast inline styles.
244
+ editor.conversion.for('downcast').attributeToAttribute(buildDowncastInlineDefinition(optionsToConvert));
245
+ }
246
+ const upcastInlineDefinitions = buildUpcastInlineDefinitions(optionsToConvert);
247
+ // Always upcast from inline styles.
248
+ for (const definition of upcastInlineDefinitions){
249
+ editor.conversion.for('upcast').attributeToAttribute(definition);
250
+ }
251
+ const upcastCompatibilityDefinitions = buildUpcastCompatibilityDefinitions(optionsToConvert);
252
+ // Always upcast from deprecated `align` attribute.
253
+ for (const definition of upcastCompatibilityDefinitions){
254
+ editor.conversion.for('upcast').attributeToAttribute(definition);
255
+ }
256
+ editor.commands.add('alignment', new AlignmentCommand(editor));
257
+ }
258
+ }
259
+ /**
260
+ * Prepare downcast conversion definition for inline alignment styling.
261
+ */ function buildDowncastInlineDefinition(options) {
262
+ const view = {};
263
+ for (const { name } of options){
264
+ view[name] = {
265
+ key: 'style',
266
+ value: {
267
+ 'text-align': name
268
+ }
269
+ };
270
+ }
271
+ const definition = {
272
+ model: {
273
+ key: 'alignment',
274
+ values: options.map((option)=>option.name)
275
+ },
276
+ view
277
+ };
278
+ return definition;
279
+ }
280
+ /**
281
+ * Prepare upcast definitions for inline alignment styles.
282
+ */ function buildUpcastInlineDefinitions(options) {
283
+ const definitions = [];
284
+ for (const { name } of options){
285
+ definitions.push({
286
+ view: {
287
+ key: 'style',
288
+ value: {
289
+ 'text-align': name
290
+ }
291
+ },
292
+ model: {
293
+ key: 'alignment',
294
+ value: name
295
+ }
296
+ });
297
+ }
298
+ return definitions;
299
+ }
300
+ /**
301
+ * Prepare upcast definitions for deprecated `align` attribute.
302
+ */ function buildUpcastCompatibilityDefinitions(options) {
303
+ const definitions = [];
304
+ for (const { name } of options){
305
+ definitions.push({
306
+ view: {
307
+ key: 'align',
308
+ value: name
309
+ },
310
+ model: {
311
+ key: 'alignment',
312
+ value: name
313
+ }
314
+ });
315
+ }
316
+ return definitions;
317
+ }
318
+ /**
319
+ * Prepare conversion definitions for upcast and downcast alignment with classes.
320
+ */ function buildClassDefinition(options) {
321
+ const view = {};
322
+ for (const option of options){
323
+ view[option.name] = {
324
+ key: 'class',
325
+ value: option.className
326
+ };
327
+ }
328
+ const definition = {
329
+ model: {
330
+ key: 'alignment',
331
+ values: options.map((option)=>option.name)
332
+ },
333
+ view
334
+ };
335
+ return definition;
336
+ }
337
+
338
+ const iconsMap = /* #__PURE__ */ (()=>new Map([
339
+ [
340
+ 'left',
341
+ icons.alignLeft
342
+ ],
343
+ [
344
+ 'right',
345
+ icons.alignRight
346
+ ],
347
+ [
348
+ 'center',
349
+ icons.alignCenter
350
+ ],
351
+ [
352
+ 'justify',
353
+ icons.alignJustify
354
+ ]
355
+ ]))();
356
+ /**
357
+ * The default alignment UI plugin.
358
+ *
359
+ * It introduces the `'alignment:left'`, `'alignment:right'`, `'alignment:center'` and `'alignment:justify'` buttons
360
+ * and the `'alignment'` dropdown.
361
+ */ class AlignmentUI extends Plugin {
362
+ /**
363
+ * Returns the localized option titles provided by the plugin.
364
+ *
365
+ * The following localized titles corresponding with
366
+ * {@link module:alignment/alignmentconfig~AlignmentConfig#options} are available:
367
+ *
368
+ * * `'left'`,
369
+ * * `'right'`,
370
+ * * `'center'`,
371
+ * * `'justify'`.
372
+ *
373
+ * @readonly
374
+ */ get localizedOptionTitles() {
375
+ const t = this.editor.t;
376
+ return {
377
+ 'left': t('Align left'),
378
+ 'right': t('Align right'),
379
+ 'center': t('Align center'),
380
+ 'justify': t('Justify')
381
+ };
382
+ }
383
+ /**
384
+ * @inheritDoc
385
+ */ static get pluginName() {
386
+ return 'AlignmentUI';
387
+ }
388
+ /**
389
+ * @inheritDoc
390
+ */ static get isOfficialPlugin() {
391
+ return true;
392
+ }
393
+ /**
394
+ * @inheritDoc
395
+ */ init() {
396
+ const editor = this.editor;
397
+ const options = normalizeAlignmentOptions(editor.config.get('alignment.options'));
398
+ options.map((option)=>option.name).filter(isSupported).forEach((option)=>this._addButton(option));
399
+ this._addToolbarDropdown(options);
400
+ this._addMenuBarMenu(options);
401
+ }
402
+ /**
403
+ * Helper method for initializing the button and linking it with an appropriate command.
404
+ *
405
+ * @param option The name of the alignment option for which the button is added.
406
+ */ _addButton(option) {
407
+ const editor = this.editor;
408
+ editor.ui.componentFactory.add(`alignment:${option}`, (locale)=>this._createButton(locale, option));
409
+ }
410
+ /**
411
+ * Helper method for creating the button view element.
412
+ *
413
+ * @param locale Editor locale.
414
+ * @param option The name of the alignment option for which the button is added.
415
+ * @param buttonAttrs Optional parameters passed to button view instance.
416
+ */ _createButton(locale, option, buttonAttrs = {}) {
417
+ const editor = this.editor;
418
+ const command = editor.commands.get('alignment');
419
+ const buttonView = new ButtonView(locale);
420
+ buttonView.set({
421
+ label: this.localizedOptionTitles[option],
422
+ icon: iconsMap.get(option),
423
+ tooltip: true,
424
+ isToggleable: true,
425
+ ...buttonAttrs
426
+ });
427
+ // Bind button model to command.
428
+ buttonView.bind('isEnabled').to(command);
429
+ buttonView.bind('isOn').to(command, 'value', (value)=>value === option);
430
+ // Execute command.
431
+ this.listenTo(buttonView, 'execute', ()=>{
432
+ editor.execute('alignment', {
433
+ value: option
434
+ });
435
+ editor.editing.view.focus();
436
+ });
437
+ return buttonView;
438
+ }
439
+ /**
440
+ * Helper method for initializing the toolnar dropdown and linking it with an appropriate command.
441
+ *
442
+ * @param option The name of the alignment option for which the button is added.
443
+ */ _addToolbarDropdown(options) {
444
+ const editor = this.editor;
445
+ const factory = editor.ui.componentFactory;
446
+ factory.add('alignment', (locale)=>{
447
+ const dropdownView = createDropdown(locale);
448
+ const tooltipPosition = locale.uiLanguageDirection === 'rtl' ? 'w' : 'e';
449
+ const t = locale.t;
450
+ // Add existing alignment buttons to dropdown's toolbar.
451
+ addToolbarToDropdown(dropdownView, ()=>options.map((option)=>this._createButton(locale, option.name, {
452
+ tooltipPosition
453
+ })), {
454
+ enableActiveItemFocusOnDropdownOpen: true,
455
+ isVertical: true,
456
+ ariaLabel: t('Text alignment toolbar')
457
+ });
458
+ // Configure dropdown properties an behavior.
459
+ dropdownView.buttonView.set({
460
+ label: t('Text alignment'),
461
+ tooltip: true
462
+ });
463
+ dropdownView.extendTemplate({
464
+ attributes: {
465
+ class: 'ck-alignment-dropdown'
466
+ }
467
+ });
468
+ // The default icon depends on the direction of the content.
469
+ const defaultIcon = locale.contentLanguageDirection === 'rtl' ? iconsMap.get('right') : iconsMap.get('left');
470
+ const command = editor.commands.get('alignment');
471
+ // Change icon to reflect current selection's alignment.
472
+ dropdownView.buttonView.bind('icon').to(command, 'value', (value)=>iconsMap.get(value) || defaultIcon);
473
+ // Enable button if any of the buttons is enabled.
474
+ dropdownView.bind('isEnabled').to(command, 'isEnabled');
475
+ // Focus the editable after executing the command.
476
+ // Overrides a default behaviour where the focus is moved to the dropdown button (#12125).
477
+ this.listenTo(dropdownView, 'execute', ()=>{
478
+ editor.editing.view.focus();
479
+ });
480
+ return dropdownView;
481
+ });
482
+ }
483
+ /**
484
+ * Creates a menu for all alignment options to use either in menu bar.
485
+ *
486
+ * @param options Normalized alignment options from config.
487
+ */ _addMenuBarMenu(options) {
488
+ const editor = this.editor;
489
+ editor.ui.componentFactory.add('menuBar:alignment', (locale)=>{
490
+ const command = editor.commands.get('alignment');
491
+ const t = locale.t;
492
+ const menuView = new MenuBarMenuView(locale);
493
+ const listView = new MenuBarMenuListView(locale);
494
+ menuView.bind('isEnabled').to(command);
495
+ listView.set({
496
+ ariaLabel: t('Text alignment'),
497
+ role: 'menu'
498
+ });
499
+ menuView.buttonView.set({
500
+ label: t('Text alignment')
501
+ });
502
+ for (const option of options){
503
+ const listItemView = new MenuBarMenuListItemView(locale, menuView);
504
+ const buttonView = new MenuBarMenuListItemButtonView(locale);
505
+ buttonView.delegate('execute').to(menuView);
506
+ buttonView.set({
507
+ label: this.localizedOptionTitles[option.name],
508
+ icon: iconsMap.get(option.name),
509
+ role: 'menuitemcheckbox',
510
+ isToggleable: true
511
+ });
512
+ buttonView.on('execute', ()=>{
513
+ editor.execute('alignment', {
514
+ value: option.name
515
+ });
516
+ editor.editing.view.focus();
517
+ });
518
+ buttonView.bind('isOn').to(command, 'value', (value)=>value === option.name);
519
+ buttonView.bind('isEnabled').to(command, 'isEnabled');
520
+ listItemView.children.add(buttonView);
521
+ listView.items.add(listItemView);
522
+ }
523
+ menuView.panelView.children.add(listView);
524
+ return menuView;
525
+ });
526
+ }
527
+ }
528
+
529
+ /**
530
+ * The text alignment plugin.
531
+ *
532
+ * For a detailed overview, check the {@glink features/text-alignment Text alignment} feature guide
533
+ * and the {@glink api/alignment package page}.
534
+ *
535
+ * This is a "glue" plugin which loads the {@link module:alignment/alignmentediting~AlignmentEditing} and
536
+ * {@link module:alignment/alignmentui~AlignmentUI} plugins.
537
+ */ class Alignment extends Plugin {
538
+ /**
539
+ * @inheritDoc
540
+ */ static get requires() {
541
+ return [
542
+ AlignmentEditing,
543
+ AlignmentUI
544
+ ];
545
+ }
546
+ /**
547
+ * @inheritDoc
548
+ */ static get pluginName() {
549
+ return 'Alignment';
550
+ }
551
+ /**
552
+ * @inheritDoc
553
+ */ static get isOfficialPlugin() {
554
+ return true;
555
+ }
556
+ }
557
+
558
+ export { Alignment, AlignmentEditing, AlignmentUI };
559
+ //# sourceMappingURL=index.js.map