@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/package.json ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "@ckeditor/ckeditor5-style",
3
+ "version": "0.0.0-internal-20241017.0",
4
+ "description": "Style feature for CKEditor 5.",
5
+ "keywords": [
6
+ "ckeditor",
7
+ "ckeditor5",
8
+ "ckeditor 5",
9
+ "ckeditor5-feature",
10
+ "ckeditor5-plugin",
11
+ "ckeditor5-dll"
12
+ ],
13
+ "type": "module",
14
+ "main": "src/index.js",
15
+ "dependencies": {
16
+ "@ckeditor/ckeditor5-core": "0.0.0-internal-20241017.0",
17
+ "@ckeditor/ckeditor5-typing": "0.0.0-internal-20241017.0",
18
+ "@ckeditor/ckeditor5-ui": "0.0.0-internal-20241017.0",
19
+ "@ckeditor/ckeditor5-utils": "0.0.0-internal-20241017.0",
20
+ "ckeditor5": "0.0.0-internal-20241017.0",
21
+ "lodash-es": "4.17.21"
22
+ },
23
+ "author": "CKSource (http://cksource.com/)",
24
+ "license": "GPL-2.0-or-later",
25
+ "homepage": "https://ckeditor.com/ckeditor-5",
26
+ "bugs": "https://github.com/ckeditor/ckeditor5/issues",
27
+ "repository": {
28
+ "type": "git",
29
+ "url": "https://github.com/ckeditor/ckeditor5.git",
30
+ "directory": "packages/ckeditor5-style"
31
+ },
32
+ "files": [
33
+ "dist",
34
+ "lang",
35
+ "src/**/*.js",
36
+ "src/**/*.d.ts",
37
+ "theme",
38
+ "build",
39
+ "ckeditor5-metadata.json",
40
+ "CHANGELOG.md"
41
+ ],
42
+ "types": "src/index.d.ts"
43
+ }
@@ -0,0 +1,24 @@
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 { StyleConfig, StyleCommand, Style, StyleEditing, StyleUI, StyleUtils } from './index.js';
6
+ declare module '@ckeditor/ckeditor5-core' {
7
+ interface PluginsMap {
8
+ [Style.pluginName]: Style;
9
+ [StyleEditing.pluginName]: StyleEditing;
10
+ [StyleUI.pluginName]: StyleUI;
11
+ [StyleUtils.pluginName]: StyleUtils;
12
+ }
13
+ interface CommandsMap {
14
+ style: StyleCommand;
15
+ }
16
+ interface EditorConfig {
17
+ /**
18
+ * The configuration of the {@link module:style/style~Style} feature.
19
+ *
20
+ * Read more in {@link module:style/styleconfig~StyleConfig}.
21
+ */
22
+ style?: StyleConfig;
23
+ }
24
+ }
@@ -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,14 @@
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
7
+ */
8
+ export { default as Style } from './style.js';
9
+ export { default as StyleEditing } from './styleediting.js';
10
+ export { default as StyleUI } from './styleui.js';
11
+ export { default as StyleUtils } from './styleutils.js';
12
+ export type { StyleConfig, StyleDefinition } from './styleconfig.js';
13
+ export type { default as StyleCommand } from './stylecommand.js';
14
+ import './augmentation.js';
package/src/index.js ADDED
@@ -0,0 +1,12 @@
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
7
+ */
8
+ export { default as Style } from './style.js';
9
+ export { default as StyleEditing } from './styleediting.js';
10
+ export { default as StyleUI } from './styleui.js';
11
+ export { default as StyleUtils } from './styleutils.js';
12
+ import './augmentation.js';
@@ -0,0 +1,41 @@
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/integrations/link
7
+ */
8
+ import { Plugin } from 'ckeditor5/src/core.js';
9
+ import StyleUtils from '../styleutils.js';
10
+ export default class LinkStyleSupport extends Plugin {
11
+ private _styleUtils;
12
+ private _htmlSupport;
13
+ /**
14
+ * @inheritDoc
15
+ */
16
+ static get pluginName(): "LinkStyleSupport";
17
+ /**
18
+ * @inheritDoc
19
+ */
20
+ static get isOfficialPlugin(): true;
21
+ /**
22
+ * @inheritDoc
23
+ */
24
+ static get requires(): readonly [typeof StyleUtils, "GeneralHtmlSupport"];
25
+ /**
26
+ * @inheritDoc
27
+ */
28
+ init(): void;
29
+ /**
30
+ * Verifies if the given style is applicable to the provided document selection.
31
+ */
32
+ private _isStyleEnabled;
33
+ /**
34
+ * Returns true if the given style is applied to the specified document selection.
35
+ */
36
+ private _isStyleActive;
37
+ /**
38
+ * Returns a selectable that given style should be applied to.
39
+ */
40
+ private _getAffectedSelectable;
41
+ }
@@ -0,0 +1,162 @@
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/integrations/link
7
+ */
8
+ import { Plugin } from 'ckeditor5/src/core.js';
9
+ import { findAttributeRange, findAttributeRangeBound } from 'ckeditor5/src/typing.js';
10
+ import StyleUtils from '../styleutils.js';
11
+ export default class LinkStyleSupport extends Plugin {
12
+ /**
13
+ * @inheritDoc
14
+ */
15
+ static get pluginName() {
16
+ return 'LinkStyleSupport';
17
+ }
18
+ /**
19
+ * @inheritDoc
20
+ */
21
+ static get isOfficialPlugin() {
22
+ return true;
23
+ }
24
+ /**
25
+ * @inheritDoc
26
+ */
27
+ static get requires() {
28
+ return [StyleUtils, 'GeneralHtmlSupport'];
29
+ }
30
+ /**
31
+ * @inheritDoc
32
+ */
33
+ init() {
34
+ const editor = this.editor;
35
+ if (!editor.plugins.has('LinkEditing')) {
36
+ return;
37
+ }
38
+ this._styleUtils = editor.plugins.get(StyleUtils);
39
+ this._htmlSupport = this.editor.plugins.get('GeneralHtmlSupport');
40
+ this.listenTo(this._styleUtils, 'isStyleEnabledForInlineSelection', (evt, [definition, selection]) => {
41
+ if (definition.element == 'a') {
42
+ evt.return = this._isStyleEnabled(definition, selection);
43
+ evt.stop();
44
+ }
45
+ }, { priority: 'high' });
46
+ this.listenTo(this._styleUtils, 'isStyleActiveForInlineSelection', (evt, [definition, selection]) => {
47
+ if (definition.element == 'a') {
48
+ evt.return = this._isStyleActive(definition, selection);
49
+ evt.stop();
50
+ }
51
+ }, { priority: 'high' });
52
+ this.listenTo(this._styleUtils, 'getAffectedInlineSelectable', (evt, [definition, selection]) => {
53
+ if (definition.element != 'a') {
54
+ return;
55
+ }
56
+ const selectable = this._getAffectedSelectable(definition, selection);
57
+ if (selectable) {
58
+ evt.return = selectable;
59
+ evt.stop();
60
+ }
61
+ }, { priority: 'high' });
62
+ }
63
+ /**
64
+ * Verifies if the given style is applicable to the provided document selection.
65
+ */
66
+ _isStyleEnabled(definition, selection) {
67
+ const model = this.editor.model;
68
+ // Handle collapsed selection.
69
+ if (selection.isCollapsed) {
70
+ return selection.hasAttribute('linkHref');
71
+ }
72
+ // Non-collapsed selection.
73
+ for (const range of selection.getRanges()) {
74
+ for (const item of range.getItems()) {
75
+ if ((item.is('$textProxy') || model.schema.isInline(item)) && item.hasAttribute('linkHref')) {
76
+ return true;
77
+ }
78
+ }
79
+ }
80
+ return false;
81
+ }
82
+ /**
83
+ * Returns true if the given style is applied to the specified document selection.
84
+ */
85
+ _isStyleActive(definition, selection) {
86
+ const model = this.editor.model;
87
+ const attributeName = this._htmlSupport.getGhsAttributeNameForElement(definition.element);
88
+ // Handle collapsed selection.
89
+ if (selection.isCollapsed) {
90
+ if (selection.hasAttribute('linkHref')) {
91
+ const ghsAttributeValue = selection.getAttribute(attributeName);
92
+ if (this._styleUtils.hasAllClasses(ghsAttributeValue, definition.classes)) {
93
+ return true;
94
+ }
95
+ }
96
+ return false;
97
+ }
98
+ // Non-collapsed selection.
99
+ for (const range of selection.getRanges()) {
100
+ for (const item of range.getItems()) {
101
+ if ((item.is('$textProxy') || model.schema.isInline(item)) && item.hasAttribute('linkHref')) {
102
+ const ghsAttributeValue = item.getAttribute(attributeName);
103
+ return this._styleUtils.hasAllClasses(ghsAttributeValue, definition.classes);
104
+ }
105
+ }
106
+ }
107
+ return false;
108
+ }
109
+ /**
110
+ * Returns a selectable that given style should be applied to.
111
+ */
112
+ _getAffectedSelectable(definition, selection) {
113
+ const model = this.editor.model;
114
+ // Handle collapsed selection.
115
+ if (selection.isCollapsed) {
116
+ const linkHref = selection.getAttribute('linkHref');
117
+ return findAttributeRange(selection.getFirstPosition(), 'linkHref', linkHref, model);
118
+ }
119
+ // Non-collapsed selection.
120
+ const ranges = [];
121
+ for (const range of selection.getRanges()) {
122
+ // First expand range to include the whole link.
123
+ const expandedRange = model.createRange(expandAttributePosition(range.start, 'linkHref', true, model), expandAttributePosition(range.end, 'linkHref', false, model));
124
+ // Pick only ranges on links.
125
+ for (const item of expandedRange.getItems()) {
126
+ if ((item.is('$textProxy') || model.schema.isInline(item)) && item.hasAttribute('linkHref')) {
127
+ ranges.push(this.editor.model.createRangeOn(item));
128
+ }
129
+ }
130
+ }
131
+ // Make sure that we have a continuous range on a link
132
+ // (not split between text nodes with mixed attributes like bold etc.)
133
+ return normalizeRanges(ranges);
134
+ }
135
+ }
136
+ /**
137
+ * Walks forward or backward (depends on the `lookBack` flag), node by node, as long as they have the same attribute value
138
+ * and returns a position just before or after (depends on the `lookBack` flag) the last matched node.
139
+ */
140
+ function expandAttributePosition(position, attributeName, lookBack, model) {
141
+ const referenceNode = position.textNode || (lookBack ? position.nodeAfter : position.nodeBefore);
142
+ if (!referenceNode || !referenceNode.hasAttribute(attributeName)) {
143
+ return position;
144
+ }
145
+ const attributeValue = referenceNode.getAttribute(attributeName);
146
+ return findAttributeRangeBound(position, attributeName, attributeValue, lookBack, model);
147
+ }
148
+ /**
149
+ * Normalizes list of ranges by joining intersecting or "touching" ranges.
150
+ *
151
+ * Note: It assumes that ranges are sorted.
152
+ */
153
+ function normalizeRanges(ranges) {
154
+ for (let i = 1; i < ranges.length; i++) {
155
+ const joinedRange = ranges[i - 1].getJoined(ranges[i]);
156
+ if (joinedRange) {
157
+ // Replace the ranges on the list with the new joined range.
158
+ ranges.splice(--i, 2, joinedRange);
159
+ }
160
+ }
161
+ return ranges;
162
+ }
@@ -0,0 +1,46 @@
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/integrations/list
7
+ */
8
+ import { Plugin } from 'ckeditor5/src/core.js';
9
+ import StyleUtils from '../styleutils.js';
10
+ export default class ListStyleSupport extends Plugin {
11
+ private _listUtils;
12
+ private _styleUtils;
13
+ private _htmlSupport;
14
+ /**
15
+ * @inheritDoc
16
+ */
17
+ static get pluginName(): "ListStyleSupport";
18
+ /**
19
+ * @inheritDoc
20
+ */
21
+ static get isOfficialPlugin(): true;
22
+ /**
23
+ * @inheritDoc
24
+ */
25
+ static get requires(): readonly [typeof StyleUtils, "GeneralHtmlSupport"];
26
+ /**
27
+ * @inheritDoc
28
+ */
29
+ init(): void;
30
+ /**
31
+ * Verifies if the given style is applicable to the provided block element.
32
+ */
33
+ private _isStyleEnabledForBlock;
34
+ /**
35
+ * Returns true if the given style is applied to the specified block element.
36
+ */
37
+ private _isStyleActiveForBlock;
38
+ /**
39
+ * Returns an array of block elements that style should be applied to.
40
+ */
41
+ private _getAffectedBlocks;
42
+ /**
43
+ * Returns a view template definition for the style preview.
44
+ */
45
+ private _getStylePreview;
46
+ }
@@ -0,0 +1,148 @@
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/integrations/list
7
+ */
8
+ import { Plugin } from 'ckeditor5/src/core.js';
9
+ import StyleUtils from '../styleutils.js';
10
+ export default class ListStyleSupport extends Plugin {
11
+ /**
12
+ * @inheritDoc
13
+ */
14
+ static get pluginName() {
15
+ return 'ListStyleSupport';
16
+ }
17
+ /**
18
+ * @inheritDoc
19
+ */
20
+ static get isOfficialPlugin() {
21
+ return true;
22
+ }
23
+ /**
24
+ * @inheritDoc
25
+ */
26
+ static get requires() {
27
+ return [StyleUtils, 'GeneralHtmlSupport'];
28
+ }
29
+ /**
30
+ * @inheritDoc
31
+ */
32
+ init() {
33
+ const editor = this.editor;
34
+ if (!editor.plugins.has('ListEditing')) {
35
+ return;
36
+ }
37
+ this._styleUtils = editor.plugins.get(StyleUtils);
38
+ this._listUtils = this.editor.plugins.get('ListUtils');
39
+ this._htmlSupport = this.editor.plugins.get('GeneralHtmlSupport');
40
+ this.listenTo(this._styleUtils, 'isStyleEnabledForBlock', (evt, [definition, block]) => {
41
+ if (this._isStyleEnabledForBlock(definition, block)) {
42
+ evt.return = true;
43
+ evt.stop();
44
+ }
45
+ }, { priority: 'high' });
46
+ this.listenTo(this._styleUtils, 'isStyleActiveForBlock', (evt, [definition, block]) => {
47
+ if (this._isStyleActiveForBlock(definition, block)) {
48
+ evt.return = true;
49
+ evt.stop();
50
+ }
51
+ }, { priority: 'high' });
52
+ this.listenTo(this._styleUtils, 'getAffectedBlocks', (evt, [definition, block]) => {
53
+ const blocks = this._getAffectedBlocks(definition, block);
54
+ if (blocks) {
55
+ evt.return = blocks;
56
+ evt.stop();
57
+ }
58
+ }, { priority: 'high' });
59
+ this.listenTo(this._styleUtils, 'getStylePreview', (evt, [definition, children]) => {
60
+ const templateDefinition = this._getStylePreview(definition, children);
61
+ if (templateDefinition) {
62
+ evt.return = templateDefinition;
63
+ evt.stop();
64
+ }
65
+ }, { priority: 'high' });
66
+ }
67
+ /**
68
+ * Verifies if the given style is applicable to the provided block element.
69
+ */
70
+ _isStyleEnabledForBlock(definition, block) {
71
+ const model = this.editor.model;
72
+ if (!['ol', 'ul', 'li'].includes(definition.element)) {
73
+ return false;
74
+ }
75
+ if (!this._listUtils.isListItemBlock(block)) {
76
+ return false;
77
+ }
78
+ const attributeName = this._htmlSupport.getGhsAttributeNameForElement(definition.element);
79
+ if (definition.element == 'ol' || definition.element == 'ul') {
80
+ if (!model.schema.checkAttribute(block, attributeName)) {
81
+ return false;
82
+ }
83
+ const isNumbered = this._listUtils.isNumberedListType(block.getAttribute('listType'));
84
+ const viewElementName = isNumbered ? 'ol' : 'ul';
85
+ return definition.element == viewElementName;
86
+ }
87
+ else {
88
+ return model.schema.checkAttribute(block, attributeName);
89
+ }
90
+ }
91
+ /**
92
+ * Returns true if the given style is applied to the specified block element.
93
+ */
94
+ _isStyleActiveForBlock(definition, block) {
95
+ const attributeName = this._htmlSupport.getGhsAttributeNameForElement(definition.element);
96
+ const ghsAttributeValue = block.getAttribute(attributeName);
97
+ return this._styleUtils.hasAllClasses(ghsAttributeValue, definition.classes);
98
+ }
99
+ /**
100
+ * Returns an array of block elements that style should be applied to.
101
+ */
102
+ _getAffectedBlocks(definition, block) {
103
+ if (!this._isStyleEnabledForBlock(definition, block)) {
104
+ return null;
105
+ }
106
+ if (definition.element == 'li') {
107
+ return this._listUtils.expandListBlocksToCompleteItems(block, { withNested: false });
108
+ }
109
+ else {
110
+ return this._listUtils.expandListBlocksToCompleteList(block);
111
+ }
112
+ }
113
+ /**
114
+ * Returns a view template definition for the style preview.
115
+ */
116
+ _getStylePreview(definition, children) {
117
+ const { element, classes } = definition;
118
+ if (element == 'ol' || element == 'ul') {
119
+ return {
120
+ tag: element,
121
+ attributes: {
122
+ class: classes
123
+ },
124
+ children: [
125
+ {
126
+ tag: 'li',
127
+ children
128
+ }
129
+ ]
130
+ };
131
+ }
132
+ else if (element == 'li') {
133
+ return {
134
+ tag: 'ol',
135
+ children: [
136
+ {
137
+ tag: element,
138
+ attributes: {
139
+ class: classes
140
+ },
141
+ children
142
+ }
143
+ ]
144
+ };
145
+ }
146
+ return null;
147
+ }
148
+ }
@@ -0,0 +1,53 @@
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/integrations/table
7
+ */
8
+ import { Plugin } from 'ckeditor5/src/core.js';
9
+ import StyleUtils from '../styleutils.js';
10
+ export default class TableStyleSupport extends Plugin {
11
+ private _tableUtils;
12
+ private _styleUtils;
13
+ /**
14
+ * @inheritDoc
15
+ */
16
+ static get pluginName(): "TableStyleSupport";
17
+ /**
18
+ * @inheritDoc
19
+ */
20
+ static get isOfficialPlugin(): true;
21
+ /**
22
+ * @inheritDoc
23
+ */
24
+ static get requires(): readonly [typeof StyleUtils];
25
+ /**
26
+ * @inheritDoc
27
+ */
28
+ init(): void;
29
+ /**
30
+ * Checks if this plugin's custom logic should be applied for defintion-block pair.
31
+ *
32
+ * @param definition Style definition that is being considered.
33
+ * @param block Block element to check if should be styled.
34
+ * @returns True if the defintion-block pair meet the plugin criteria, false otherwise.
35
+ */
36
+ private _isApplicable;
37
+ /**
38
+ * Checks if the style definition should be applied to selected block.
39
+ *
40
+ * @param definition Style definition that is being considered.
41
+ * @param block Block element to check if should be styled.
42
+ * @returns True if the block should be style with the style description, false otherwise.
43
+ */
44
+ private _isStyleEnabledForBlock;
45
+ /**
46
+ * Gets all blocks that the style should be applied to.
47
+ *
48
+ * @param definition Style definition that is being considered.
49
+ * @param block A block element from selection.
50
+ * @returns An array with the block that was passed as an argument if meets the criteria, null otherwise.
51
+ */
52
+ private _getAffectedBlocks;
53
+ }
@@ -0,0 +1,121 @@
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/integrations/table
7
+ */
8
+ import { Plugin } from 'ckeditor5/src/core.js';
9
+ import StyleUtils from '../styleutils.js';
10
+ export default class TableStyleSupport extends Plugin {
11
+ /**
12
+ * @inheritDoc
13
+ */
14
+ static get pluginName() {
15
+ return 'TableStyleSupport';
16
+ }
17
+ /**
18
+ * @inheritDoc
19
+ */
20
+ static get isOfficialPlugin() {
21
+ return true;
22
+ }
23
+ /**
24
+ * @inheritDoc
25
+ */
26
+ static get requires() {
27
+ return [StyleUtils];
28
+ }
29
+ /**
30
+ * @inheritDoc
31
+ */
32
+ init() {
33
+ const editor = this.editor;
34
+ if (!editor.plugins.has('TableEditing')) {
35
+ return;
36
+ }
37
+ this._styleUtils = editor.plugins.get(StyleUtils);
38
+ this._tableUtils = this.editor.plugins.get('TableUtils');
39
+ this.listenTo(this._styleUtils, 'isStyleEnabledForBlock', (evt, [definition, block]) => {
40
+ if (this._isApplicable(definition, block)) {
41
+ evt.return = this._isStyleEnabledForBlock(definition, block);
42
+ evt.stop();
43
+ }
44
+ }, { priority: 'high' });
45
+ this.listenTo(this._styleUtils, 'getAffectedBlocks', (evt, [definition, block]) => {
46
+ if (this._isApplicable(definition, block)) {
47
+ evt.return = this._getAffectedBlocks(definition, block);
48
+ evt.stop();
49
+ }
50
+ }, { priority: 'high' });
51
+ this.listenTo(this._styleUtils, 'configureGHSDataFilter', (evt, [{ block }]) => {
52
+ const ghsDataFilter = this.editor.plugins.get('DataFilter');
53
+ ghsDataFilter.loadAllowedConfig(block
54
+ .filter(definition => definition.element == 'figcaption')
55
+ .map(definition => ({ name: 'caption', classes: definition.classes })));
56
+ });
57
+ }
58
+ /**
59
+ * Checks if this plugin's custom logic should be applied for defintion-block pair.
60
+ *
61
+ * @param definition Style definition that is being considered.
62
+ * @param block Block element to check if should be styled.
63
+ * @returns True if the defintion-block pair meet the plugin criteria, false otherwise.
64
+ */
65
+ _isApplicable(definition, block) {
66
+ if (['td', 'th'].includes(definition.element)) {
67
+ return block.name == 'tableCell';
68
+ }
69
+ if (['thead', 'tbody'].includes(definition.element)) {
70
+ return block.name == 'table';
71
+ }
72
+ return false;
73
+ }
74
+ /**
75
+ * Checks if the style definition should be applied to selected block.
76
+ *
77
+ * @param definition Style definition that is being considered.
78
+ * @param block Block element to check if should be styled.
79
+ * @returns True if the block should be style with the style description, false otherwise.
80
+ */
81
+ _isStyleEnabledForBlock(definition, block) {
82
+ if (['td', 'th'].includes(definition.element)) {
83
+ const location = this._tableUtils.getCellLocation(block);
84
+ const tableRow = block.parent;
85
+ const table = tableRow.parent;
86
+ const headingRows = table.getAttribute('headingRows') || 0;
87
+ const headingColumns = table.getAttribute('headingColumns') || 0;
88
+ const isHeadingCell = location.row < headingRows || location.column < headingColumns;
89
+ if (definition.element == 'th') {
90
+ return isHeadingCell;
91
+ }
92
+ else {
93
+ return !isHeadingCell;
94
+ }
95
+ }
96
+ if (['thead', 'tbody'].includes(definition.element)) {
97
+ const headingRows = block.getAttribute('headingRows') || 0;
98
+ if (definition.element == 'thead') {
99
+ return headingRows > 0;
100
+ }
101
+ else {
102
+ return headingRows < this._tableUtils.getRows(block);
103
+ }
104
+ }
105
+ /* istanbul ignore next -- @preserve */
106
+ return false;
107
+ }
108
+ /**
109
+ * Gets all blocks that the style should be applied to.
110
+ *
111
+ * @param definition Style definition that is being considered.
112
+ * @param block A block element from selection.
113
+ * @returns An array with the block that was passed as an argument if meets the criteria, null otherwise.
114
+ */
115
+ _getAffectedBlocks(definition, block) {
116
+ if (!this._isStyleEnabledForBlock(definition, block)) {
117
+ return null;
118
+ }
119
+ return [block];
120
+ }
121
+ }