@ckeditor/ckeditor5-style 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 (286) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/LICENSE.md +17 -0
  3. package/README.md +26 -0
  4. package/build/style.js +5 -0
  5. package/build/translations/ar.js +1 -0
  6. package/build/translations/bg.js +1 -0
  7. package/build/translations/bn.js +1 -0
  8. package/build/translations/ca.js +1 -0
  9. package/build/translations/cs.js +1 -0
  10. package/build/translations/da.js +1 -0
  11. package/build/translations/de.js +1 -0
  12. package/build/translations/el.js +1 -0
  13. package/build/translations/en-au.js +1 -0
  14. package/build/translations/es.js +1 -0
  15. package/build/translations/et.js +1 -0
  16. package/build/translations/fi.js +1 -0
  17. package/build/translations/fr.js +1 -0
  18. package/build/translations/gl.js +1 -0
  19. package/build/translations/he.js +1 -0
  20. package/build/translations/hi.js +1 -0
  21. package/build/translations/hr.js +1 -0
  22. package/build/translations/hu.js +1 -0
  23. package/build/translations/id.js +1 -0
  24. package/build/translations/it.js +1 -0
  25. package/build/translations/ja.js +1 -0
  26. package/build/translations/ko.js +1 -0
  27. package/build/translations/lt.js +1 -0
  28. package/build/translations/lv.js +1 -0
  29. package/build/translations/ms.js +1 -0
  30. package/build/translations/nl.js +1 -0
  31. package/build/translations/no.js +1 -0
  32. package/build/translations/pl.js +1 -0
  33. package/build/translations/pt-br.js +1 -0
  34. package/build/translations/pt.js +1 -0
  35. package/build/translations/ro.js +1 -0
  36. package/build/translations/ru.js +1 -0
  37. package/build/translations/sk.js +1 -0
  38. package/build/translations/sr-latn.js +1 -0
  39. package/build/translations/sr.js +1 -0
  40. package/build/translations/sv.js +1 -0
  41. package/build/translations/th.js +1 -0
  42. package/build/translations/tr.js +1 -0
  43. package/build/translations/ug.js +1 -0
  44. package/build/translations/uk.js +1 -0
  45. package/build/translations/ur.js +1 -0
  46. package/build/translations/vi.js +1 -0
  47. package/build/translations/zh-cn.js +1 -0
  48. package/build/translations/zh.js +1 -0
  49. package/ckeditor5-metadata.json +28 -0
  50. package/dist/augmentation.d.ts +28 -0
  51. package/dist/index-content.css +4 -0
  52. package/dist/index-editor.css +28 -0
  53. package/dist/index.css +35 -0
  54. package/dist/index.css.map +1 -0
  55. package/dist/index.d.ts +18 -0
  56. package/dist/index.js +1336 -0
  57. package/dist/index.js.map +1 -0
  58. package/dist/integrations/link.d.ts +45 -0
  59. package/dist/integrations/list.d.ts +50 -0
  60. package/dist/integrations/table.d.ts +57 -0
  61. package/dist/style.d.ts +34 -0
  62. package/dist/stylecommand.d.ts +86 -0
  63. package/dist/styleconfig.d.ts +91 -0
  64. package/dist/styleediting.d.ts +41 -0
  65. package/dist/styleui.d.ts +38 -0
  66. package/dist/styleutils.d.ts +146 -0
  67. package/dist/translations/ar.d.ts +8 -0
  68. package/dist/translations/ar.js +5 -0
  69. package/dist/translations/ar.umd.js +11 -0
  70. package/dist/translations/bg.d.ts +8 -0
  71. package/dist/translations/bg.js +5 -0
  72. package/dist/translations/bg.umd.js +11 -0
  73. package/dist/translations/bn.d.ts +8 -0
  74. package/dist/translations/bn.js +5 -0
  75. package/dist/translations/bn.umd.js +11 -0
  76. package/dist/translations/ca.d.ts +8 -0
  77. package/dist/translations/ca.js +5 -0
  78. package/dist/translations/ca.umd.js +11 -0
  79. package/dist/translations/cs.d.ts +8 -0
  80. package/dist/translations/cs.js +5 -0
  81. package/dist/translations/cs.umd.js +11 -0
  82. package/dist/translations/da.d.ts +8 -0
  83. package/dist/translations/da.js +5 -0
  84. package/dist/translations/da.umd.js +11 -0
  85. package/dist/translations/de.d.ts +8 -0
  86. package/dist/translations/de.js +5 -0
  87. package/dist/translations/de.umd.js +11 -0
  88. package/dist/translations/el.d.ts +8 -0
  89. package/dist/translations/el.js +5 -0
  90. package/dist/translations/el.umd.js +11 -0
  91. package/dist/translations/en-au.d.ts +8 -0
  92. package/dist/translations/en-au.js +5 -0
  93. package/dist/translations/en-au.umd.js +11 -0
  94. package/dist/translations/en.d.ts +8 -0
  95. package/dist/translations/en.js +5 -0
  96. package/dist/translations/en.umd.js +11 -0
  97. package/dist/translations/es.d.ts +8 -0
  98. package/dist/translations/es.js +5 -0
  99. package/dist/translations/es.umd.js +11 -0
  100. package/dist/translations/et.d.ts +8 -0
  101. package/dist/translations/et.js +5 -0
  102. package/dist/translations/et.umd.js +11 -0
  103. package/dist/translations/fi.d.ts +8 -0
  104. package/dist/translations/fi.js +5 -0
  105. package/dist/translations/fi.umd.js +11 -0
  106. package/dist/translations/fr.d.ts +8 -0
  107. package/dist/translations/fr.js +5 -0
  108. package/dist/translations/fr.umd.js +11 -0
  109. package/dist/translations/gl.d.ts +8 -0
  110. package/dist/translations/gl.js +5 -0
  111. package/dist/translations/gl.umd.js +11 -0
  112. package/dist/translations/he.d.ts +8 -0
  113. package/dist/translations/he.js +5 -0
  114. package/dist/translations/he.umd.js +11 -0
  115. package/dist/translations/hi.d.ts +8 -0
  116. package/dist/translations/hi.js +5 -0
  117. package/dist/translations/hi.umd.js +11 -0
  118. package/dist/translations/hr.d.ts +8 -0
  119. package/dist/translations/hr.js +5 -0
  120. package/dist/translations/hr.umd.js +11 -0
  121. package/dist/translations/hu.d.ts +8 -0
  122. package/dist/translations/hu.js +5 -0
  123. package/dist/translations/hu.umd.js +11 -0
  124. package/dist/translations/id.d.ts +8 -0
  125. package/dist/translations/id.js +5 -0
  126. package/dist/translations/id.umd.js +11 -0
  127. package/dist/translations/it.d.ts +8 -0
  128. package/dist/translations/it.js +5 -0
  129. package/dist/translations/it.umd.js +11 -0
  130. package/dist/translations/ja.d.ts +8 -0
  131. package/dist/translations/ja.js +5 -0
  132. package/dist/translations/ja.umd.js +11 -0
  133. package/dist/translations/ko.d.ts +8 -0
  134. package/dist/translations/ko.js +5 -0
  135. package/dist/translations/ko.umd.js +11 -0
  136. package/dist/translations/lt.d.ts +8 -0
  137. package/dist/translations/lt.js +5 -0
  138. package/dist/translations/lt.umd.js +11 -0
  139. package/dist/translations/lv.d.ts +8 -0
  140. package/dist/translations/lv.js +5 -0
  141. package/dist/translations/lv.umd.js +11 -0
  142. package/dist/translations/ms.d.ts +8 -0
  143. package/dist/translations/ms.js +5 -0
  144. package/dist/translations/ms.umd.js +11 -0
  145. package/dist/translations/nl.d.ts +8 -0
  146. package/dist/translations/nl.js +5 -0
  147. package/dist/translations/nl.umd.js +11 -0
  148. package/dist/translations/no.d.ts +8 -0
  149. package/dist/translations/no.js +5 -0
  150. package/dist/translations/no.umd.js +11 -0
  151. package/dist/translations/pl.d.ts +8 -0
  152. package/dist/translations/pl.js +5 -0
  153. package/dist/translations/pl.umd.js +11 -0
  154. package/dist/translations/pt-br.d.ts +8 -0
  155. package/dist/translations/pt-br.js +5 -0
  156. package/dist/translations/pt-br.umd.js +11 -0
  157. package/dist/translations/pt.d.ts +8 -0
  158. package/dist/translations/pt.js +5 -0
  159. package/dist/translations/pt.umd.js +11 -0
  160. package/dist/translations/ro.d.ts +8 -0
  161. package/dist/translations/ro.js +5 -0
  162. package/dist/translations/ro.umd.js +11 -0
  163. package/dist/translations/ru.d.ts +8 -0
  164. package/dist/translations/ru.js +5 -0
  165. package/dist/translations/ru.umd.js +11 -0
  166. package/dist/translations/sk.d.ts +8 -0
  167. package/dist/translations/sk.js +5 -0
  168. package/dist/translations/sk.umd.js +11 -0
  169. package/dist/translations/sr-latn.d.ts +8 -0
  170. package/dist/translations/sr-latn.js +5 -0
  171. package/dist/translations/sr-latn.umd.js +11 -0
  172. package/dist/translations/sr.d.ts +8 -0
  173. package/dist/translations/sr.js +5 -0
  174. package/dist/translations/sr.umd.js +11 -0
  175. package/dist/translations/sv.d.ts +8 -0
  176. package/dist/translations/sv.js +5 -0
  177. package/dist/translations/sv.umd.js +11 -0
  178. package/dist/translations/th.d.ts +8 -0
  179. package/dist/translations/th.js +5 -0
  180. package/dist/translations/th.umd.js +11 -0
  181. package/dist/translations/tr.d.ts +8 -0
  182. package/dist/translations/tr.js +5 -0
  183. package/dist/translations/tr.umd.js +11 -0
  184. package/dist/translations/ug.d.ts +8 -0
  185. package/dist/translations/ug.js +5 -0
  186. package/dist/translations/ug.umd.js +11 -0
  187. package/dist/translations/uk.d.ts +8 -0
  188. package/dist/translations/uk.js +5 -0
  189. package/dist/translations/uk.umd.js +11 -0
  190. package/dist/translations/ur.d.ts +8 -0
  191. package/dist/translations/ur.js +5 -0
  192. package/dist/translations/ur.umd.js +11 -0
  193. package/dist/translations/vi.d.ts +8 -0
  194. package/dist/translations/vi.js +5 -0
  195. package/dist/translations/vi.umd.js +11 -0
  196. package/dist/translations/zh-cn.d.ts +8 -0
  197. package/dist/translations/zh-cn.js +5 -0
  198. package/dist/translations/zh-cn.umd.js +11 -0
  199. package/dist/translations/zh.d.ts +8 -0
  200. package/dist/translations/zh.js +5 -0
  201. package/dist/translations/zh.umd.js +11 -0
  202. package/dist/ui/stylegridbuttonview.d.ts +38 -0
  203. package/dist/ui/stylegridview.d.ts +76 -0
  204. package/dist/ui/stylegroupview.d.ts +39 -0
  205. package/dist/ui/stylepanelview.d.ts +93 -0
  206. package/lang/contexts.json +6 -0
  207. package/lang/translations/ar.po +34 -0
  208. package/lang/translations/bg.po +34 -0
  209. package/lang/translations/bn.po +34 -0
  210. package/lang/translations/ca.po +34 -0
  211. package/lang/translations/cs.po +34 -0
  212. package/lang/translations/da.po +34 -0
  213. package/lang/translations/de.po +34 -0
  214. package/lang/translations/el.po +34 -0
  215. package/lang/translations/en-au.po +34 -0
  216. package/lang/translations/en.po +34 -0
  217. package/lang/translations/es.po +34 -0
  218. package/lang/translations/et.po +34 -0
  219. package/lang/translations/fi.po +34 -0
  220. package/lang/translations/fr.po +34 -0
  221. package/lang/translations/gl.po +34 -0
  222. package/lang/translations/he.po +34 -0
  223. package/lang/translations/hi.po +34 -0
  224. package/lang/translations/hr.po +34 -0
  225. package/lang/translations/hu.po +34 -0
  226. package/lang/translations/id.po +34 -0
  227. package/lang/translations/it.po +34 -0
  228. package/lang/translations/ja.po +34 -0
  229. package/lang/translations/ko.po +34 -0
  230. package/lang/translations/lt.po +34 -0
  231. package/lang/translations/lv.po +34 -0
  232. package/lang/translations/ms.po +34 -0
  233. package/lang/translations/nl.po +34 -0
  234. package/lang/translations/no.po +34 -0
  235. package/lang/translations/pl.po +34 -0
  236. package/lang/translations/pt-br.po +34 -0
  237. package/lang/translations/pt.po +34 -0
  238. package/lang/translations/ro.po +34 -0
  239. package/lang/translations/ru.po +34 -0
  240. package/lang/translations/sk.po +34 -0
  241. package/lang/translations/sr-latn.po +34 -0
  242. package/lang/translations/sr.po +34 -0
  243. package/lang/translations/sv.po +34 -0
  244. package/lang/translations/th.po +34 -0
  245. package/lang/translations/tr.po +34 -0
  246. package/lang/translations/ug.po +34 -0
  247. package/lang/translations/uk.po +34 -0
  248. package/lang/translations/ur.po +34 -0
  249. package/lang/translations/vi.po +34 -0
  250. package/lang/translations/zh-cn.po +34 -0
  251. package/lang/translations/zh.po +34 -0
  252. package/package.json +43 -0
  253. package/src/augmentation.d.ts +24 -0
  254. package/src/augmentation.js +5 -0
  255. package/src/index.d.ts +14 -0
  256. package/src/index.js +12 -0
  257. package/src/integrations/link.d.ts +41 -0
  258. package/src/integrations/link.js +162 -0
  259. package/src/integrations/list.d.ts +46 -0
  260. package/src/integrations/list.js +148 -0
  261. package/src/integrations/table.d.ts +53 -0
  262. package/src/integrations/table.js +121 -0
  263. package/src/style.d.ts +30 -0
  264. package/src/style.js +36 -0
  265. package/src/stylecommand.d.ts +82 -0
  266. package/src/stylecommand.js +200 -0
  267. package/src/styleconfig.d.ts +87 -0
  268. package/src/styleconfig.js +5 -0
  269. package/src/styleediting.d.ts +37 -0
  270. package/src/styleediting.js +52 -0
  271. package/src/styleui.d.ts +34 -0
  272. package/src/styleui.js +100 -0
  273. package/src/styleutils.d.ts +142 -0
  274. package/src/styleutils.js +274 -0
  275. package/src/ui/stylegridbuttonview.d.ts +34 -0
  276. package/src/ui/stylegridbuttonview.js +55 -0
  277. package/src/ui/stylegridview.d.ts +72 -0
  278. package/src/ui/stylegridview.js +89 -0
  279. package/src/ui/stylegroupview.d.ts +35 -0
  280. package/src/ui/stylegroupview.js +45 -0
  281. package/src/ui/stylepanelview.d.ts +89 -0
  282. package/src/ui/stylepanelview.js +95 -0
  283. package/theme/style.css +4 -0
  284. package/theme/stylegrid.css +29 -0
  285. package/theme/stylegroup.css +4 -0
  286. package/theme/stylepanel.css +5 -0
package/src/style.d.ts ADDED
@@ -0,0 +1,30 @@
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 style/style
7
+ */
8
+ import { Plugin } from 'ckeditor5/src/core.js';
9
+ import StyleUI from './styleui.js';
10
+ import StyleEditing from './styleediting.js';
11
+ /**
12
+ * The style plugin.
13
+ *
14
+ * This is a "glue" plugin that loads the {@link module:style/styleediting~StyleEditing style editing feature}
15
+ * and {@link module:style/styleui~StyleUI style UI feature}.
16
+ */
17
+ export default class Style extends Plugin {
18
+ /**
19
+ * @inheritDoc
20
+ */
21
+ static get pluginName(): "Style";
22
+ /**
23
+ * @inheritDoc
24
+ */
25
+ static get isOfficialPlugin(): true;
26
+ /**
27
+ * @inheritDoc
28
+ */
29
+ static get requires(): readonly [typeof StyleEditing, typeof StyleUI];
30
+ }
package/src/style.js ADDED
@@ -0,0 +1,36 @@
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 style/style
7
+ */
8
+ import { Plugin } from 'ckeditor5/src/core.js';
9
+ import StyleUI from './styleui.js';
10
+ import StyleEditing from './styleediting.js';
11
+ /**
12
+ * The style plugin.
13
+ *
14
+ * This is a "glue" plugin that loads the {@link module:style/styleediting~StyleEditing style editing feature}
15
+ * and {@link module:style/styleui~StyleUI style UI feature}.
16
+ */
17
+ export default class Style extends Plugin {
18
+ /**
19
+ * @inheritDoc
20
+ */
21
+ static get pluginName() {
22
+ return 'Style';
23
+ }
24
+ /**
25
+ * @inheritDoc
26
+ */
27
+ static get isOfficialPlugin() {
28
+ return true;
29
+ }
30
+ /**
31
+ * @inheritDoc
32
+ */
33
+ static get requires() {
34
+ return [StyleEditing, StyleUI];
35
+ }
36
+ }
@@ -0,0 +1,82 @@
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, type Editor } from 'ckeditor5/src/core.js';
6
+ import { type NormalizedStyleDefinitions } from './styleutils.js';
7
+ /**
8
+ * Style command.
9
+ *
10
+ * Applies and removes styles from selection and elements.
11
+ */
12
+ export default class StyleCommand extends Command {
13
+ /**
14
+ * Set of currently applied styles on the current selection.
15
+ *
16
+ * Names of styles correspond to the `name` property of
17
+ * {@link module:style/styleconfig~StyleDefinition configured definitions}.
18
+ *
19
+ * @observable
20
+ */
21
+ value: Array<string>;
22
+ /**
23
+ * Names of enabled styles (styles that can be applied to the current selection).
24
+ *
25
+ * Names of enabled styles correspond to the `name` property of
26
+ * {@link module:style/styleconfig~StyleDefinition configured definitions}.
27
+ *
28
+ * @observable
29
+ */
30
+ enabledStyles: Array<string>;
31
+ /**
32
+ * Normalized definitions of the styles.
33
+ */
34
+ private readonly _styleDefinitions;
35
+ /**
36
+ * The StyleUtils plugin.
37
+ */
38
+ private _styleUtils;
39
+ /**
40
+ * Creates an instance of the command.
41
+ *
42
+ * @param editor Editor on which this command will be used.
43
+ * @param styleDefinitions Normalized definitions of the styles.
44
+ */
45
+ constructor(editor: Editor, styleDefinitions: NormalizedStyleDefinitions);
46
+ /**
47
+ * @inheritDoc
48
+ */
49
+ refresh(): void;
50
+ /**
51
+ * Executes the command &ndash; applies the style classes to the selection or removes it from the selection.
52
+ *
53
+ * If the command value already contains the requested style, it will remove the style classes. Otherwise, it will set it.
54
+ *
55
+ * The execution result differs, depending on the {@link module:engine/model/document~Document#selection} and the
56
+ * style type (inline or block):
57
+ *
58
+ * * When applying inline styles:
59
+ * * If the selection is on a range, the command applies the style classes to all nodes in that range.
60
+ * * If the selection is collapsed in a non-empty node, the command applies the style classes to the
61
+ * {@link module:engine/model/document~Document#selection}.
62
+ *
63
+ * * When applying block styles:
64
+ * * If the selection is on a range, the command applies the style classes to the nearest block parent element.
65
+ *
66
+ * @fires execute
67
+ * @param options Command options.
68
+ * @param options.styleName Style name matching the one defined in the
69
+ * {@link module:style/styleconfig~StyleConfig#definitions configuration}.
70
+ * @param options.forceValue Whether the command should add given style (`true`) or remove it (`false`) from the selection.
71
+ * If not set (default), the command will toggle the style basing on the first selected node. Note, that this will not force
72
+ * setting a style on an element that cannot receive given style.
73
+ */
74
+ execute({ styleName, forceValue }: {
75
+ styleName: string;
76
+ forceValue?: boolean;
77
+ }): void;
78
+ /**
79
+ * Returns a set of elements that should be affected by the block-style change.
80
+ */
81
+ private _findAffectedBlocks;
82
+ }
@@ -0,0 +1,200 @@
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 } from 'ckeditor5/src/core.js';
6
+ import { logWarning, first } from 'ckeditor5/src/utils.js';
7
+ import StyleUtils from './styleutils.js';
8
+ /**
9
+ * Style command.
10
+ *
11
+ * Applies and removes styles from selection and elements.
12
+ */
13
+ export default class StyleCommand extends Command {
14
+ /**
15
+ * Creates an instance of the command.
16
+ *
17
+ * @param editor Editor on which this command will be used.
18
+ * @param styleDefinitions Normalized definitions of the styles.
19
+ */
20
+ constructor(editor, styleDefinitions) {
21
+ super(editor);
22
+ this.set('value', []);
23
+ this.set('enabledStyles', []);
24
+ this._styleDefinitions = styleDefinitions;
25
+ this._styleUtils = this.editor.plugins.get(StyleUtils);
26
+ }
27
+ /**
28
+ * @inheritDoc
29
+ */
30
+ refresh() {
31
+ const model = this.editor.model;
32
+ const selection = model.document.selection;
33
+ const value = new Set();
34
+ const enabledStyles = new Set();
35
+ // Inline styles.
36
+ for (const definition of this._styleDefinitions.inline) {
37
+ // Check if this inline style is enabled.
38
+ if (this._styleUtils.isStyleEnabledForInlineSelection(definition, selection)) {
39
+ enabledStyles.add(definition.name);
40
+ }
41
+ // Check if this inline style is active.
42
+ if (this._styleUtils.isStyleActiveForInlineSelection(definition, selection)) {
43
+ value.add(definition.name);
44
+ }
45
+ }
46
+ // Block styles.
47
+ const firstBlock = first(selection.getSelectedBlocks()) || selection.getFirstPosition().parent;
48
+ if (firstBlock) {
49
+ const ancestorBlocks = firstBlock.getAncestors({ includeSelf: true, parentFirst: true });
50
+ for (const block of ancestorBlocks) {
51
+ if (block.is('rootElement')) {
52
+ break;
53
+ }
54
+ for (const definition of this._styleDefinitions.block) {
55
+ // Check if this block style is enabled.
56
+ if (!this._styleUtils.isStyleEnabledForBlock(definition, block)) {
57
+ continue;
58
+ }
59
+ enabledStyles.add(definition.name);
60
+ // Check if this block style is active.
61
+ if (this._styleUtils.isStyleActiveForBlock(definition, block)) {
62
+ value.add(definition.name);
63
+ }
64
+ }
65
+ // E.g. reached a model table when the selection is in a cell. The command should not modify
66
+ // ancestors of a table.
67
+ if (model.schema.isObject(block)) {
68
+ break;
69
+ }
70
+ }
71
+ }
72
+ this.enabledStyles = Array.from(enabledStyles).sort();
73
+ this.isEnabled = this.enabledStyles.length > 0;
74
+ this.value = this.isEnabled ? Array.from(value).sort() : [];
75
+ }
76
+ /**
77
+ * Executes the command &ndash; applies the style classes to the selection or removes it from the selection.
78
+ *
79
+ * If the command value already contains the requested style, it will remove the style classes. Otherwise, it will set it.
80
+ *
81
+ * The execution result differs, depending on the {@link module:engine/model/document~Document#selection} and the
82
+ * style type (inline or block):
83
+ *
84
+ * * When applying inline styles:
85
+ * * If the selection is on a range, the command applies the style classes to all nodes in that range.
86
+ * * If the selection is collapsed in a non-empty node, the command applies the style classes to the
87
+ * {@link module:engine/model/document~Document#selection}.
88
+ *
89
+ * * When applying block styles:
90
+ * * If the selection is on a range, the command applies the style classes to the nearest block parent element.
91
+ *
92
+ * @fires execute
93
+ * @param options Command options.
94
+ * @param options.styleName Style name matching the one defined in the
95
+ * {@link module:style/styleconfig~StyleConfig#definitions configuration}.
96
+ * @param options.forceValue Whether the command should add given style (`true`) or remove it (`false`) from the selection.
97
+ * If not set (default), the command will toggle the style basing on the first selected node. Note, that this will not force
98
+ * setting a style on an element that cannot receive given style.
99
+ */
100
+ execute({ styleName, forceValue }) {
101
+ if (!this.enabledStyles.includes(styleName)) {
102
+ /**
103
+ * Style command can be executed only with a correct style name.
104
+ *
105
+ * This warning may be caused by:
106
+ *
107
+ * * passing a name that is not specified in the {@link module:style/styleconfig~StyleConfig#definitions configuration}
108
+ * (e.g. a CSS class name),
109
+ * * when trying to apply a style that is not allowed on a given element.
110
+ *
111
+ * @error style-command-executed-with-incorrect-style-name
112
+ */
113
+ logWarning('style-command-executed-with-incorrect-style-name');
114
+ return;
115
+ }
116
+ const model = this.editor.model;
117
+ const selection = model.document.selection;
118
+ const htmlSupport = this.editor.plugins.get('GeneralHtmlSupport');
119
+ const allDefinitions = [
120
+ ...this._styleDefinitions.inline,
121
+ ...this._styleDefinitions.block
122
+ ];
123
+ const activeDefinitions = allDefinitions.filter(({ name }) => this.value.includes(name));
124
+ const definition = allDefinitions.find(({ name }) => name == styleName);
125
+ const shouldAddStyle = forceValue === undefined ? !this.value.includes(definition.name) : forceValue;
126
+ model.change(() => {
127
+ let selectables;
128
+ if (isBlockStyleDefinition(definition)) {
129
+ selectables = this._findAffectedBlocks(getBlocksFromSelection(selection), definition);
130
+ }
131
+ else {
132
+ selectables = [this._styleUtils.getAffectedInlineSelectable(definition, selection)];
133
+ }
134
+ for (const selectable of selectables) {
135
+ if (shouldAddStyle) {
136
+ htmlSupport.addModelHtmlClass(definition.element, definition.classes, selectable);
137
+ }
138
+ else {
139
+ htmlSupport.removeModelHtmlClass(definition.element, getDefinitionExclusiveClasses(activeDefinitions, definition), selectable);
140
+ }
141
+ }
142
+ });
143
+ }
144
+ /**
145
+ * Returns a set of elements that should be affected by the block-style change.
146
+ */
147
+ _findAffectedBlocks(selectedBlocks, definition) {
148
+ const blocks = new Set();
149
+ for (const selectedBlock of selectedBlocks) {
150
+ const ancestorBlocks = selectedBlock.getAncestors({ includeSelf: true, parentFirst: true });
151
+ for (const block of ancestorBlocks) {
152
+ if (block.is('rootElement')) {
153
+ break;
154
+ }
155
+ const affectedBlocks = this._styleUtils.getAffectedBlocks(definition, block);
156
+ if (affectedBlocks) {
157
+ for (const affectedBlock of affectedBlocks) {
158
+ blocks.add(affectedBlock);
159
+ }
160
+ break;
161
+ }
162
+ }
163
+ }
164
+ return blocks;
165
+ }
166
+ }
167
+ /**
168
+ * Returns classes that are defined only in the supplied definition and not in any other active definition. It's used
169
+ * to ensure that classes used by other definitions are preserved when a style is removed. See #11748.
170
+ *
171
+ * @param activeDefinitions All currently active definitions affecting selected element(s).
172
+ * @param definition Definition whose classes will be compared with all other active definition classes.
173
+ * @returns Array of classes exclusive to the supplied definition.
174
+ */
175
+ function getDefinitionExclusiveClasses(activeDefinitions, definition) {
176
+ return activeDefinitions.reduce((classes, currentDefinition) => {
177
+ if (currentDefinition.name === definition.name) {
178
+ return classes;
179
+ }
180
+ return classes.filter(className => !currentDefinition.classes.includes(className));
181
+ }, definition.classes);
182
+ }
183
+ /**
184
+ * Checks if provided style definition is of type block.
185
+ */
186
+ function isBlockStyleDefinition(definition) {
187
+ return 'isBlock' in definition;
188
+ }
189
+ /**
190
+ * Gets block elements from selection. If there are none, returns first selected element.
191
+ * @param selection Current document's selection.
192
+ * @returns Selected blocks if there are any, first selected element otherwise.
193
+ */
194
+ function getBlocksFromSelection(selection) {
195
+ const blocks = Array.from(selection.getSelectedBlocks());
196
+ if (blocks.length) {
197
+ return blocks;
198
+ }
199
+ return [selection.getFirstPosition().parent];
200
+ }
@@ -0,0 +1,87 @@
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 style/styleconfig
7
+ */
8
+ /**
9
+ * The configuration of the style feature.
10
+ *
11
+ * ```ts
12
+ * ClassicEditor
13
+ * .create( {
14
+ * style: ... // Style feature config.
15
+ * } )
16
+ * .then( ... )
17
+ * .catch( ... );
18
+ * ```
19
+ *
20
+ * See {@link module:core/editor/editorconfig~EditorConfig all editor options}.
21
+ */
22
+ export interface StyleConfig {
23
+ /**
24
+ * The available style definitions.
25
+ *
26
+ * Style definitions are displayed in the `'style'` UI dropdown and get applied by the
27
+ * {@link module:style/stylecommand~StyleCommand style command} to the content of the document.
28
+ *
29
+ * In the `'style'` UI dropdown, definitions are automatically grouped into two categories based on the of the `element` property:
30
+ *
31
+ * * **Block styles**: Can be applied to entire {@link module:html-support/dataschema~DataSchema#registerBlockElement block elements}
32
+ * only (e.g. headings, paragraphs, divs).
33
+ * * **Text styles**: Can by applied to any {@link module:html-support/dataschema~DataSchema#registerInlineElement text} in any element
34
+ * in the document.
35
+ *
36
+ * An example configuration:
37
+ *
38
+ * ```ts
39
+ * [
40
+ * // Definitions of block styles.
41
+ * {
42
+ * name: 'Red heading',
43
+ * element: 'h2',
44
+ * classes: [ 'red-heading' ]
45
+ * },
46
+ * {
47
+ * name: 'Vibrant code',
48
+ * element: 'pre',
49
+ * classes: [ 'vibrant-code' ]
50
+ * },
51
+ *
52
+ * // Definitions of text (inline) styles.
53
+ * {
54
+ * name: 'Marker',
55
+ * element: 'span',
56
+ * classes: [ 'marker' ]
57
+ * },
58
+ *
59
+ * // ...
60
+ * ]
61
+ * ```
62
+ *
63
+ * **Note**: Configuring style definitions will automatically configure the
64
+ * {@glink features/html/general-html-support General HTML Support feature}. **You do not need to repeat the configuration in
65
+ * {@link module:html-support/generalhtmlsupportconfig~GeneralHtmlSupportConfig}**.
66
+ */
67
+ definitions?: Array<StyleDefinition>;
68
+ }
69
+ /**
70
+ * Style definition.
71
+ *
72
+ * An object describing a style definition. It contains the style `name`, `element` name and an array of CSS `classes`.
73
+ *
74
+ * ```ts
75
+ * // This style will create <h2 class="foo">...</h2> in the document data.
76
+ * {
77
+ * name: 'Example style',
78
+ * element: 'h2',
79
+ * classes: [ 'foo' ]
80
+ * }
81
+ * ```
82
+ */
83
+ export interface StyleDefinition {
84
+ name: string;
85
+ element: string;
86
+ classes: Array<string>;
87
+ }
@@ -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 {};
@@ -0,0 +1,37 @@
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 style/styleediting
7
+ */
8
+ import { Plugin } from 'ckeditor5/src/core.js';
9
+ import StyleUtils from './styleutils.js';
10
+ import ListStyleSupport from './integrations/list.js';
11
+ import TableStyleSupport from './integrations/table.js';
12
+ import LinkStyleSupport from './integrations/link.js';
13
+ /**
14
+ * The style engine feature.
15
+ *
16
+ * It configures the {@glink features/html/general-html-support General HTML Support feature} based on
17
+ * {@link module:style/styleconfig~StyleConfig#definitions configured style definitions} and introduces the
18
+ * {@link module:style/stylecommand~StyleCommand style command} that applies styles to the content of the document.
19
+ */
20
+ export default class StyleEditing extends Plugin {
21
+ /**
22
+ * @inheritDoc
23
+ */
24
+ static get pluginName(): "StyleEditing";
25
+ /**
26
+ * @inheritDoc
27
+ */
28
+ static get isOfficialPlugin(): true;
29
+ /**
30
+ * @inheritDoc
31
+ */
32
+ static get requires(): readonly ["GeneralHtmlSupport", typeof StyleUtils, typeof ListStyleSupport, typeof TableStyleSupport, typeof LinkStyleSupport];
33
+ /**
34
+ * @inheritDoc
35
+ */
36
+ init(): void;
37
+ }
@@ -0,0 +1,52 @@
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 style/styleediting
7
+ */
8
+ import { Plugin } from 'ckeditor5/src/core.js';
9
+ import StyleCommand from './stylecommand.js';
10
+ import StyleUtils from './styleutils.js';
11
+ import ListStyleSupport from './integrations/list.js';
12
+ import TableStyleSupport from './integrations/table.js';
13
+ import LinkStyleSupport from './integrations/link.js';
14
+ /**
15
+ * The style engine feature.
16
+ *
17
+ * It configures the {@glink features/html/general-html-support General HTML Support feature} based on
18
+ * {@link module:style/styleconfig~StyleConfig#definitions configured style definitions} and introduces the
19
+ * {@link module:style/stylecommand~StyleCommand style command} that applies styles to the content of the document.
20
+ */
21
+ export default class StyleEditing extends Plugin {
22
+ /**
23
+ * @inheritDoc
24
+ */
25
+ static get pluginName() {
26
+ return 'StyleEditing';
27
+ }
28
+ /**
29
+ * @inheritDoc
30
+ */
31
+ static get isOfficialPlugin() {
32
+ return true;
33
+ }
34
+ /**
35
+ * @inheritDoc
36
+ */
37
+ static get requires() {
38
+ return ['GeneralHtmlSupport', StyleUtils, ListStyleSupport, TableStyleSupport, LinkStyleSupport];
39
+ }
40
+ /**
41
+ * @inheritDoc
42
+ */
43
+ init() {
44
+ const editor = this.editor;
45
+ const dataSchema = editor.plugins.get('DataSchema');
46
+ const styleUtils = editor.plugins.get('StyleUtils');
47
+ const styleDefinitions = editor.config.get('style.definitions');
48
+ const normalizedStyleDefinitions = styleUtils.normalizeConfig(dataSchema, styleDefinitions);
49
+ editor.commands.add('style', new StyleCommand(editor, normalizedStyleDefinitions));
50
+ styleUtils.configureGHSDataFilter(normalizedStyleDefinitions);
51
+ }
52
+ }
@@ -0,0 +1,34 @@
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 style/styleui
7
+ */
8
+ import { Plugin } from 'ckeditor5/src/core.js';
9
+ import StyleUtils from './styleutils.js';
10
+ import '../theme/style.css';
11
+ /**
12
+ * The UI plugin of the style feature .
13
+ *
14
+ * It registers the `'style'` UI dropdown in the editor's {@link module:ui/componentfactory~ComponentFactory component factory}
15
+ * that displays a grid of styles and allows changing styles of the content.
16
+ */
17
+ export default class StyleUI extends Plugin {
18
+ /**
19
+ * @inheritDoc
20
+ */
21
+ static get pluginName(): "StyleUI";
22
+ /**
23
+ * @inheritDoc
24
+ */
25
+ static get isOfficialPlugin(): true;
26
+ /**
27
+ * @inheritDoc
28
+ */
29
+ static get requires(): readonly [typeof StyleUtils];
30
+ /**
31
+ * @inheritDoc
32
+ */
33
+ init(): void;
34
+ }
package/src/styleui.js ADDED
@@ -0,0 +1,100 @@
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 style/styleui
7
+ */
8
+ import { Plugin } from 'ckeditor5/src/core.js';
9
+ import { createDropdown } from 'ckeditor5/src/ui.js';
10
+ import StylePanelView from './ui/stylepanelview.js';
11
+ import StyleUtils from './styleutils.js';
12
+ import '../theme/style.css';
13
+ /**
14
+ * The UI plugin of the style feature .
15
+ *
16
+ * It registers the `'style'` UI dropdown in the editor's {@link module:ui/componentfactory~ComponentFactory component factory}
17
+ * that displays a grid of styles and allows changing styles of the content.
18
+ */
19
+ export default class StyleUI extends Plugin {
20
+ /**
21
+ * @inheritDoc
22
+ */
23
+ static get pluginName() {
24
+ return 'StyleUI';
25
+ }
26
+ /**
27
+ * @inheritDoc
28
+ */
29
+ static get isOfficialPlugin() {
30
+ return true;
31
+ }
32
+ /**
33
+ * @inheritDoc
34
+ */
35
+ static get requires() {
36
+ return [StyleUtils];
37
+ }
38
+ /**
39
+ * @inheritDoc
40
+ */
41
+ init() {
42
+ const editor = this.editor;
43
+ const dataSchema = editor.plugins.get('DataSchema');
44
+ const styleUtils = editor.plugins.get('StyleUtils');
45
+ const styleDefinitions = editor.config.get('style.definitions');
46
+ const normalizedStyleDefinitions = styleUtils.normalizeConfig(dataSchema, styleDefinitions);
47
+ // Add the dropdown to the component factory.
48
+ editor.ui.componentFactory.add('style', locale => {
49
+ const t = locale.t;
50
+ const dropdown = createDropdown(locale);
51
+ const styleCommand = editor.commands.get('style');
52
+ dropdown.once('change:isOpen', () => {
53
+ const panelView = new StylePanelView(locale, normalizedStyleDefinitions);
54
+ // Put the styles panel is the dropdown.
55
+ dropdown.panelView.children.add(panelView);
56
+ // Close the dropdown when a style is selected in the styles panel.
57
+ panelView.delegate('execute').to(dropdown);
58
+ // Bind the state of the styles panel to the command.
59
+ panelView.bind('activeStyles').to(styleCommand, 'value');
60
+ panelView.bind('enabledStyles').to(styleCommand, 'enabledStyles');
61
+ });
62
+ // The entire dropdown will be disabled together with the command (e.g. when the editor goes read-only).
63
+ dropdown.bind('isEnabled').to(styleCommand);
64
+ // This dropdown has no icon. It displays text label depending on the selection.
65
+ dropdown.buttonView.withText = true;
66
+ // The label of the dropdown is dynamic and depends on how many styles are active at a time.
67
+ dropdown.buttonView.bind('label').to(styleCommand, 'value', value => {
68
+ if (value.length > 1) {
69
+ return t('Multiple styles');
70
+ }
71
+ else if (value.length === 1) {
72
+ return value[0];
73
+ }
74
+ else {
75
+ return t('Styles');
76
+ }
77
+ });
78
+ // The dropdown has a static CSS class for easy customization. There's another CSS class
79
+ // that gets displayed when multiple styles are active at a time allowing visual customization of
80
+ // the label.
81
+ dropdown.bind('class').to(styleCommand, 'value', value => {
82
+ const classes = [
83
+ 'ck-style-dropdown'
84
+ ];
85
+ if (value.length > 1) {
86
+ classes.push('ck-style-dropdown_multiple-active');
87
+ }
88
+ return classes.join(' ');
89
+ });
90
+ // Execute the command when a style is selected in the styles panel.
91
+ // Also focus the editable after executing the command.
92
+ // It overrides a default behaviour where the focus is moved to the dropdown button (#12125).
93
+ dropdown.on('execute', evt => {
94
+ editor.execute('style', { styleName: evt.source.styleDefinition.name });
95
+ editor.editing.view.focus();
96
+ });
97
+ return dropdown;
98
+ });
99
+ }
100
+ }