@ckeditor/ckeditor5-highlight 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 (326) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/LICENSE.md +17 -0
  3. package/README.md +26 -0
  4. package/build/highlight.js +5 -0
  5. package/build/translations/ar.js +1 -0
  6. package/build/translations/az.js +1 -0
  7. package/build/translations/bg.js +1 -0
  8. package/build/translations/bn.js +1 -0
  9. package/build/translations/ca.js +1 -0
  10. package/build/translations/cs.js +1 -0
  11. package/build/translations/da.js +1 -0
  12. package/build/translations/de-ch.js +1 -0
  13. package/build/translations/de.js +1 -0
  14. package/build/translations/el.js +1 -0
  15. package/build/translations/en-au.js +1 -0
  16. package/build/translations/en-gb.js +1 -0
  17. package/build/translations/es-co.js +1 -0
  18. package/build/translations/es.js +1 -0
  19. package/build/translations/et.js +1 -0
  20. package/build/translations/fa.js +1 -0
  21. package/build/translations/fi.js +1 -0
  22. package/build/translations/fr.js +1 -0
  23. package/build/translations/gl.js +1 -0
  24. package/build/translations/he.js +1 -0
  25. package/build/translations/hi.js +1 -0
  26. package/build/translations/hr.js +1 -0
  27. package/build/translations/hu.js +1 -0
  28. package/build/translations/id.js +1 -0
  29. package/build/translations/it.js +1 -0
  30. package/build/translations/ja.js +1 -0
  31. package/build/translations/jv.js +1 -0
  32. package/build/translations/ko.js +1 -0
  33. package/build/translations/ku.js +1 -0
  34. package/build/translations/lt.js +1 -0
  35. package/build/translations/lv.js +1 -0
  36. package/build/translations/ms.js +1 -0
  37. package/build/translations/nb.js +1 -0
  38. package/build/translations/ne.js +1 -0
  39. package/build/translations/nl.js +1 -0
  40. package/build/translations/no.js +1 -0
  41. package/build/translations/pl.js +1 -0
  42. package/build/translations/pt-br.js +1 -0
  43. package/build/translations/pt.js +1 -0
  44. package/build/translations/ro.js +1 -0
  45. package/build/translations/ru.js +1 -0
  46. package/build/translations/sk.js +1 -0
  47. package/build/translations/sl.js +1 -0
  48. package/build/translations/sq.js +1 -0
  49. package/build/translations/sr-latn.js +1 -0
  50. package/build/translations/sr.js +1 -0
  51. package/build/translations/sv.js +1 -0
  52. package/build/translations/th.js +1 -0
  53. package/build/translations/tk.js +1 -0
  54. package/build/translations/tr.js +1 -0
  55. package/build/translations/ug.js +1 -0
  56. package/build/translations/uk.js +1 -0
  57. package/build/translations/ur.js +1 -0
  58. package/build/translations/uz.js +1 -0
  59. package/build/translations/vi.js +1 -0
  60. package/build/translations/zh-cn.js +1 -0
  61. package/build/translations/zh.js +1 -0
  62. package/ckeditor5-metadata.json +38 -0
  63. package/dist/augmentation.d.ts +27 -0
  64. package/dist/highlight.d.ts +36 -0
  65. package/dist/highlightcommand.d.ts +49 -0
  66. package/dist/highlightconfig.d.ts +175 -0
  67. package/dist/highlightediting.d.ts +36 -0
  68. package/dist/highlightui.d.ts +85 -0
  69. package/dist/index-content.css +34 -0
  70. package/dist/index-editor.css +12 -0
  71. package/dist/index.css +45 -0
  72. package/dist/index.css.map +1 -0
  73. package/dist/index.d.ts +17 -0
  74. package/dist/index.js +485 -0
  75. package/dist/index.js.map +1 -0
  76. package/dist/translations/ar.d.ts +8 -0
  77. package/dist/translations/ar.js +5 -0
  78. package/dist/translations/ar.umd.js +11 -0
  79. package/dist/translations/az.d.ts +8 -0
  80. package/dist/translations/az.js +5 -0
  81. package/dist/translations/az.umd.js +11 -0
  82. package/dist/translations/bg.d.ts +8 -0
  83. package/dist/translations/bg.js +5 -0
  84. package/dist/translations/bg.umd.js +11 -0
  85. package/dist/translations/bn.d.ts +8 -0
  86. package/dist/translations/bn.js +5 -0
  87. package/dist/translations/bn.umd.js +11 -0
  88. package/dist/translations/ca.d.ts +8 -0
  89. package/dist/translations/ca.js +5 -0
  90. package/dist/translations/ca.umd.js +11 -0
  91. package/dist/translations/cs.d.ts +8 -0
  92. package/dist/translations/cs.js +5 -0
  93. package/dist/translations/cs.umd.js +11 -0
  94. package/dist/translations/da.d.ts +8 -0
  95. package/dist/translations/da.js +5 -0
  96. package/dist/translations/da.umd.js +11 -0
  97. package/dist/translations/de-ch.d.ts +8 -0
  98. package/dist/translations/de-ch.js +5 -0
  99. package/dist/translations/de-ch.umd.js +11 -0
  100. package/dist/translations/de.d.ts +8 -0
  101. package/dist/translations/de.js +5 -0
  102. package/dist/translations/de.umd.js +11 -0
  103. package/dist/translations/el.d.ts +8 -0
  104. package/dist/translations/el.js +5 -0
  105. package/dist/translations/el.umd.js +11 -0
  106. package/dist/translations/en-au.d.ts +8 -0
  107. package/dist/translations/en-au.js +5 -0
  108. package/dist/translations/en-au.umd.js +11 -0
  109. package/dist/translations/en-gb.d.ts +8 -0
  110. package/dist/translations/en-gb.js +5 -0
  111. package/dist/translations/en-gb.umd.js +11 -0
  112. package/dist/translations/en.d.ts +8 -0
  113. package/dist/translations/en.js +5 -0
  114. package/dist/translations/en.umd.js +11 -0
  115. package/dist/translations/es-co.d.ts +8 -0
  116. package/dist/translations/es-co.js +5 -0
  117. package/dist/translations/es-co.umd.js +11 -0
  118. package/dist/translations/es.d.ts +8 -0
  119. package/dist/translations/es.js +5 -0
  120. package/dist/translations/es.umd.js +11 -0
  121. package/dist/translations/et.d.ts +8 -0
  122. package/dist/translations/et.js +5 -0
  123. package/dist/translations/et.umd.js +11 -0
  124. package/dist/translations/fa.d.ts +8 -0
  125. package/dist/translations/fa.js +5 -0
  126. package/dist/translations/fa.umd.js +11 -0
  127. package/dist/translations/fi.d.ts +8 -0
  128. package/dist/translations/fi.js +5 -0
  129. package/dist/translations/fi.umd.js +11 -0
  130. package/dist/translations/fr.d.ts +8 -0
  131. package/dist/translations/fr.js +5 -0
  132. package/dist/translations/fr.umd.js +11 -0
  133. package/dist/translations/gl.d.ts +8 -0
  134. package/dist/translations/gl.js +5 -0
  135. package/dist/translations/gl.umd.js +11 -0
  136. package/dist/translations/he.d.ts +8 -0
  137. package/dist/translations/he.js +5 -0
  138. package/dist/translations/he.umd.js +11 -0
  139. package/dist/translations/hi.d.ts +8 -0
  140. package/dist/translations/hi.js +5 -0
  141. package/dist/translations/hi.umd.js +11 -0
  142. package/dist/translations/hr.d.ts +8 -0
  143. package/dist/translations/hr.js +5 -0
  144. package/dist/translations/hr.umd.js +11 -0
  145. package/dist/translations/hu.d.ts +8 -0
  146. package/dist/translations/hu.js +5 -0
  147. package/dist/translations/hu.umd.js +11 -0
  148. package/dist/translations/id.d.ts +8 -0
  149. package/dist/translations/id.js +5 -0
  150. package/dist/translations/id.umd.js +11 -0
  151. package/dist/translations/it.d.ts +8 -0
  152. package/dist/translations/it.js +5 -0
  153. package/dist/translations/it.umd.js +11 -0
  154. package/dist/translations/ja.d.ts +8 -0
  155. package/dist/translations/ja.js +5 -0
  156. package/dist/translations/ja.umd.js +11 -0
  157. package/dist/translations/jv.d.ts +8 -0
  158. package/dist/translations/jv.js +5 -0
  159. package/dist/translations/jv.umd.js +11 -0
  160. package/dist/translations/ko.d.ts +8 -0
  161. package/dist/translations/ko.js +5 -0
  162. package/dist/translations/ko.umd.js +11 -0
  163. package/dist/translations/ku.d.ts +8 -0
  164. package/dist/translations/ku.js +5 -0
  165. package/dist/translations/ku.umd.js +11 -0
  166. package/dist/translations/lt.d.ts +8 -0
  167. package/dist/translations/lt.js +5 -0
  168. package/dist/translations/lt.umd.js +11 -0
  169. package/dist/translations/lv.d.ts +8 -0
  170. package/dist/translations/lv.js +5 -0
  171. package/dist/translations/lv.umd.js +11 -0
  172. package/dist/translations/ms.d.ts +8 -0
  173. package/dist/translations/ms.js +5 -0
  174. package/dist/translations/ms.umd.js +11 -0
  175. package/dist/translations/nb.d.ts +8 -0
  176. package/dist/translations/nb.js +5 -0
  177. package/dist/translations/nb.umd.js +11 -0
  178. package/dist/translations/ne.d.ts +8 -0
  179. package/dist/translations/ne.js +5 -0
  180. package/dist/translations/ne.umd.js +11 -0
  181. package/dist/translations/nl.d.ts +8 -0
  182. package/dist/translations/nl.js +5 -0
  183. package/dist/translations/nl.umd.js +11 -0
  184. package/dist/translations/no.d.ts +8 -0
  185. package/dist/translations/no.js +5 -0
  186. package/dist/translations/no.umd.js +11 -0
  187. package/dist/translations/pl.d.ts +8 -0
  188. package/dist/translations/pl.js +5 -0
  189. package/dist/translations/pl.umd.js +11 -0
  190. package/dist/translations/pt-br.d.ts +8 -0
  191. package/dist/translations/pt-br.js +5 -0
  192. package/dist/translations/pt-br.umd.js +11 -0
  193. package/dist/translations/pt.d.ts +8 -0
  194. package/dist/translations/pt.js +5 -0
  195. package/dist/translations/pt.umd.js +11 -0
  196. package/dist/translations/ro.d.ts +8 -0
  197. package/dist/translations/ro.js +5 -0
  198. package/dist/translations/ro.umd.js +11 -0
  199. package/dist/translations/ru.d.ts +8 -0
  200. package/dist/translations/ru.js +5 -0
  201. package/dist/translations/ru.umd.js +11 -0
  202. package/dist/translations/sk.d.ts +8 -0
  203. package/dist/translations/sk.js +5 -0
  204. package/dist/translations/sk.umd.js +11 -0
  205. package/dist/translations/sl.d.ts +8 -0
  206. package/dist/translations/sl.js +5 -0
  207. package/dist/translations/sl.umd.js +11 -0
  208. package/dist/translations/sq.d.ts +8 -0
  209. package/dist/translations/sq.js +5 -0
  210. package/dist/translations/sq.umd.js +11 -0
  211. package/dist/translations/sr-latn.d.ts +8 -0
  212. package/dist/translations/sr-latn.js +5 -0
  213. package/dist/translations/sr-latn.umd.js +11 -0
  214. package/dist/translations/sr.d.ts +8 -0
  215. package/dist/translations/sr.js +5 -0
  216. package/dist/translations/sr.umd.js +11 -0
  217. package/dist/translations/sv.d.ts +8 -0
  218. package/dist/translations/sv.js +5 -0
  219. package/dist/translations/sv.umd.js +11 -0
  220. package/dist/translations/th.d.ts +8 -0
  221. package/dist/translations/th.js +5 -0
  222. package/dist/translations/th.umd.js +11 -0
  223. package/dist/translations/tk.d.ts +8 -0
  224. package/dist/translations/tk.js +5 -0
  225. package/dist/translations/tk.umd.js +11 -0
  226. package/dist/translations/tr.d.ts +8 -0
  227. package/dist/translations/tr.js +5 -0
  228. package/dist/translations/tr.umd.js +11 -0
  229. package/dist/translations/ug.d.ts +8 -0
  230. package/dist/translations/ug.js +5 -0
  231. package/dist/translations/ug.umd.js +11 -0
  232. package/dist/translations/uk.d.ts +8 -0
  233. package/dist/translations/uk.js +5 -0
  234. package/dist/translations/uk.umd.js +11 -0
  235. package/dist/translations/ur.d.ts +8 -0
  236. package/dist/translations/ur.js +5 -0
  237. package/dist/translations/ur.umd.js +11 -0
  238. package/dist/translations/uz.d.ts +8 -0
  239. package/dist/translations/uz.js +5 -0
  240. package/dist/translations/uz.umd.js +11 -0
  241. package/dist/translations/vi.d.ts +8 -0
  242. package/dist/translations/vi.js +5 -0
  243. package/dist/translations/vi.umd.js +11 -0
  244. package/dist/translations/zh-cn.d.ts +8 -0
  245. package/dist/translations/zh-cn.js +5 -0
  246. package/dist/translations/zh-cn.umd.js +11 -0
  247. package/dist/translations/zh.d.ts +8 -0
  248. package/dist/translations/zh.js +5 -0
  249. package/dist/translations/zh.umd.js +11 -0
  250. package/lang/contexts.json +11 -0
  251. package/lang/translations/ar.po +54 -0
  252. package/lang/translations/az.po +54 -0
  253. package/lang/translations/bg.po +54 -0
  254. package/lang/translations/bn.po +54 -0
  255. package/lang/translations/ca.po +54 -0
  256. package/lang/translations/cs.po +54 -0
  257. package/lang/translations/da.po +54 -0
  258. package/lang/translations/de-ch.po +54 -0
  259. package/lang/translations/de.po +54 -0
  260. package/lang/translations/el.po +54 -0
  261. package/lang/translations/en-au.po +54 -0
  262. package/lang/translations/en-gb.po +54 -0
  263. package/lang/translations/en.po +54 -0
  264. package/lang/translations/es-co.po +54 -0
  265. package/lang/translations/es.po +54 -0
  266. package/lang/translations/et.po +54 -0
  267. package/lang/translations/fa.po +54 -0
  268. package/lang/translations/fi.po +54 -0
  269. package/lang/translations/fr.po +54 -0
  270. package/lang/translations/gl.po +54 -0
  271. package/lang/translations/he.po +54 -0
  272. package/lang/translations/hi.po +54 -0
  273. package/lang/translations/hr.po +54 -0
  274. package/lang/translations/hu.po +54 -0
  275. package/lang/translations/id.po +54 -0
  276. package/lang/translations/it.po +54 -0
  277. package/lang/translations/ja.po +54 -0
  278. package/lang/translations/jv.po +54 -0
  279. package/lang/translations/ko.po +54 -0
  280. package/lang/translations/ku.po +54 -0
  281. package/lang/translations/lt.po +54 -0
  282. package/lang/translations/lv.po +54 -0
  283. package/lang/translations/ms.po +54 -0
  284. package/lang/translations/nb.po +54 -0
  285. package/lang/translations/ne.po +54 -0
  286. package/lang/translations/nl.po +54 -0
  287. package/lang/translations/no.po +54 -0
  288. package/lang/translations/pl.po +54 -0
  289. package/lang/translations/pt-br.po +54 -0
  290. package/lang/translations/pt.po +54 -0
  291. package/lang/translations/ro.po +54 -0
  292. package/lang/translations/ru.po +54 -0
  293. package/lang/translations/sk.po +54 -0
  294. package/lang/translations/sl.po +54 -0
  295. package/lang/translations/sq.po +54 -0
  296. package/lang/translations/sr-latn.po +54 -0
  297. package/lang/translations/sr.po +54 -0
  298. package/lang/translations/sv.po +54 -0
  299. package/lang/translations/th.po +54 -0
  300. package/lang/translations/tk.po +54 -0
  301. package/lang/translations/tr.po +54 -0
  302. package/lang/translations/ug.po +54 -0
  303. package/lang/translations/uk.po +54 -0
  304. package/lang/translations/ur.po +54 -0
  305. package/lang/translations/uz.po +54 -0
  306. package/lang/translations/vi.po +54 -0
  307. package/lang/translations/zh-cn.po +54 -0
  308. package/lang/translations/zh.po +54 -0
  309. package/package.json +40 -0
  310. package/src/augmentation.d.ts +23 -0
  311. package/src/augmentation.js +5 -0
  312. package/src/highlight.d.ts +32 -0
  313. package/src/highlight.js +38 -0
  314. package/src/highlightcommand.d.ts +45 -0
  315. package/src/highlightcommand.js +91 -0
  316. package/src/highlightconfig.d.ts +171 -0
  317. package/src/highlightconfig.js +5 -0
  318. package/src/highlightediting.d.ts +32 -0
  319. package/src/highlightediting.js +115 -0
  320. package/src/highlightui.d.ts +81 -0
  321. package/src/highlightui.js +277 -0
  322. package/src/index.d.ts +13 -0
  323. package/src/index.js +11 -0
  324. package/theme/highlight.css +36 -0
  325. package/theme/icons/marker.svg +1 -0
  326. package/theme/icons/pen.svg +1 -0
@@ -0,0 +1,32 @@
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 highlight/highlightediting
7
+ */
8
+ import { Plugin, type Editor } from 'ckeditor5/src/core.js';
9
+ /**
10
+ * The highlight editing feature. It introduces the {@link module:highlight/highlightcommand~HighlightCommand command} and the `highlight`
11
+ * attribute in the {@link module:engine/model/model~Model model} which renders in the {@link module:engine/view/view view}
12
+ * as a `<mark>` element with a `class` attribute (`<mark class="marker-green">...</mark>`) depending
13
+ * on the {@link module:highlight/highlightconfig~HighlightConfig configuration}.
14
+ */
15
+ export default class HighlightEditing extends Plugin {
16
+ /**
17
+ * @inheritDoc
18
+ */
19
+ static get pluginName(): "HighlightEditing";
20
+ /**
21
+ * @inheritDoc
22
+ */
23
+ static get isOfficialPlugin(): true;
24
+ /**
25
+ * @inheritDoc
26
+ */
27
+ constructor(editor: Editor);
28
+ /**
29
+ * @inheritDoc
30
+ */
31
+ init(): void;
32
+ }
@@ -0,0 +1,115 @@
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 highlight/highlightediting
7
+ */
8
+ import { Plugin } from 'ckeditor5/src/core.js';
9
+ import HighlightCommand from './highlightcommand.js';
10
+ /**
11
+ * The highlight editing feature. It introduces the {@link module:highlight/highlightcommand~HighlightCommand command} and the `highlight`
12
+ * attribute in the {@link module:engine/model/model~Model model} which renders in the {@link module:engine/view/view view}
13
+ * as a `<mark>` element with a `class` attribute (`<mark class="marker-green">...</mark>`) depending
14
+ * on the {@link module:highlight/highlightconfig~HighlightConfig configuration}.
15
+ */
16
+ export default class HighlightEditing extends Plugin {
17
+ /**
18
+ * @inheritDoc
19
+ */
20
+ static get pluginName() {
21
+ return 'HighlightEditing';
22
+ }
23
+ /**
24
+ * @inheritDoc
25
+ */
26
+ static get isOfficialPlugin() {
27
+ return true;
28
+ }
29
+ /**
30
+ * @inheritDoc
31
+ */
32
+ constructor(editor) {
33
+ super(editor);
34
+ editor.config.define('highlight', {
35
+ options: [
36
+ {
37
+ model: 'yellowMarker',
38
+ class: 'marker-yellow',
39
+ title: 'Yellow marker',
40
+ color: 'var(--ck-highlight-marker-yellow)',
41
+ type: 'marker'
42
+ },
43
+ {
44
+ model: 'greenMarker',
45
+ class: 'marker-green',
46
+ title: 'Green marker',
47
+ color: 'var(--ck-highlight-marker-green)',
48
+ type: 'marker'
49
+ },
50
+ {
51
+ model: 'pinkMarker',
52
+ class: 'marker-pink',
53
+ title: 'Pink marker',
54
+ color: 'var(--ck-highlight-marker-pink)',
55
+ type: 'marker'
56
+ },
57
+ {
58
+ model: 'blueMarker',
59
+ class: 'marker-blue',
60
+ title: 'Blue marker',
61
+ color: 'var(--ck-highlight-marker-blue)',
62
+ type: 'marker'
63
+ },
64
+ {
65
+ model: 'redPen',
66
+ class: 'pen-red',
67
+ title: 'Red pen',
68
+ color: 'var(--ck-highlight-pen-red)',
69
+ type: 'pen'
70
+ },
71
+ {
72
+ model: 'greenPen',
73
+ class: 'pen-green',
74
+ title: 'Green pen',
75
+ color: 'var(--ck-highlight-pen-green)',
76
+ type: 'pen'
77
+ }
78
+ ]
79
+ });
80
+ }
81
+ /**
82
+ * @inheritDoc
83
+ */
84
+ init() {
85
+ const editor = this.editor;
86
+ // Allow highlight attribute on text nodes.
87
+ editor.model.schema.extend('$text', { allowAttributes: 'highlight' });
88
+ const options = editor.config.get('highlight.options');
89
+ // Set-up the two-way conversion.
90
+ editor.conversion.attributeToElement(_buildDefinition(options));
91
+ editor.commands.add('highlight', new HighlightCommand(editor));
92
+ }
93
+ }
94
+ /**
95
+ * Converts the options array to a converter definition.
96
+ *
97
+ * @param options An array with configured options.
98
+ */
99
+ function _buildDefinition(options) {
100
+ const definition = {
101
+ model: {
102
+ key: 'highlight',
103
+ values: []
104
+ },
105
+ view: {}
106
+ };
107
+ for (const option of options) {
108
+ definition.model.values.push(option.model);
109
+ definition.view[option.model] = {
110
+ name: 'mark',
111
+ classes: option.class
112
+ };
113
+ }
114
+ return definition;
115
+ }
@@ -0,0 +1,81 @@
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 highlight/highlightui
7
+ */
8
+ import { Plugin } from 'ckeditor5/src/core.js';
9
+ import './../theme/highlight.css';
10
+ /**
11
+ * The default highlight UI plugin. It introduces:
12
+ *
13
+ * * The `'highlight'` dropdown,
14
+ * * The `'removeHighlight'` and `'highlight:*'` buttons.
15
+ *
16
+ * The default configuration includes the following buttons:
17
+ *
18
+ * * `'highlight:yellowMarker'`
19
+ * * `'highlight:greenMarker'`
20
+ * * `'highlight:pinkMarker'`
21
+ * * `'highlight:blueMarker'`
22
+ * * `'highlight:redPen'`
23
+ * * `'highlight:greenPen'`
24
+ *
25
+ * See the {@link module:highlight/highlightconfig~HighlightConfig#options configuration} to learn more
26
+ * about the defaults.
27
+ */
28
+ export default class HighlightUI extends Plugin {
29
+ /**
30
+ * Returns the localized option titles provided by the plugin.
31
+ *
32
+ * The following localized titles corresponding with default
33
+ * {@link module:highlight/highlightconfig~HighlightConfig#options} are available:
34
+ *
35
+ * * `'Yellow marker'`,
36
+ * * `'Green marker'`,
37
+ * * `'Pink marker'`,
38
+ * * `'Blue marker'`,
39
+ * * `'Red pen'`,
40
+ * * `'Green pen'`.
41
+ */
42
+ get localizedOptionTitles(): Record<string, string>;
43
+ /**
44
+ * @inheritDoc
45
+ */
46
+ static get pluginName(): "HighlightUI";
47
+ /**
48
+ * @inheritDoc
49
+ */
50
+ static get isOfficialPlugin(): true;
51
+ /**
52
+ * @inheritDoc
53
+ */
54
+ init(): void;
55
+ /**
56
+ * Creates the "Remove highlight" button.
57
+ */
58
+ private _addRemoveHighlightButton;
59
+ /**
60
+ * Creates a toolbar button from the provided highlight option.
61
+ */
62
+ private _addHighlighterButton;
63
+ /**
64
+ * Internal method for creating highlight buttons.
65
+ *
66
+ * @param name The name of the button.
67
+ * @param label The label for the button.
68
+ * @param icon The button icon.
69
+ * @param value The `value` property passed to the executed command.
70
+ * @param decorateButton A callback getting ButtonView instance so that it can be further customized.
71
+ */
72
+ private _addButton;
73
+ /**
74
+ * Creates the split button dropdown UI from the provided highlight options.
75
+ */
76
+ private _addDropdown;
77
+ /**
78
+ * Creates the menu bar button for highlight including submenu with available options.
79
+ */
80
+ private _addMenuBarButton;
81
+ }
@@ -0,0 +1,277 @@
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 highlight/highlightui
7
+ */
8
+ import { Plugin, icons } from 'ckeditor5/src/core.js';
9
+ import { addToolbarToDropdown, createDropdown, ButtonView, ListSeparatorView, MenuBarMenuView, MenuBarMenuListView, MenuBarMenuListItemView, MenuBarMenuListItemButtonView, SplitButtonView, ToolbarSeparatorView } from 'ckeditor5/src/ui.js';
10
+ import markerIcon from './../theme/icons/marker.svg';
11
+ import penIcon from './../theme/icons/pen.svg';
12
+ import './../theme/highlight.css';
13
+ /**
14
+ * The default highlight UI plugin. It introduces:
15
+ *
16
+ * * The `'highlight'` dropdown,
17
+ * * The `'removeHighlight'` and `'highlight:*'` buttons.
18
+ *
19
+ * The default configuration includes the following buttons:
20
+ *
21
+ * * `'highlight:yellowMarker'`
22
+ * * `'highlight:greenMarker'`
23
+ * * `'highlight:pinkMarker'`
24
+ * * `'highlight:blueMarker'`
25
+ * * `'highlight:redPen'`
26
+ * * `'highlight:greenPen'`
27
+ *
28
+ * See the {@link module:highlight/highlightconfig~HighlightConfig#options configuration} to learn more
29
+ * about the defaults.
30
+ */
31
+ export default class HighlightUI extends Plugin {
32
+ /**
33
+ * Returns the localized option titles provided by the plugin.
34
+ *
35
+ * The following localized titles corresponding with default
36
+ * {@link module:highlight/highlightconfig~HighlightConfig#options} are available:
37
+ *
38
+ * * `'Yellow marker'`,
39
+ * * `'Green marker'`,
40
+ * * `'Pink marker'`,
41
+ * * `'Blue marker'`,
42
+ * * `'Red pen'`,
43
+ * * `'Green pen'`.
44
+ */
45
+ get localizedOptionTitles() {
46
+ const t = this.editor.t;
47
+ return {
48
+ 'Yellow marker': t('Yellow marker'),
49
+ 'Green marker': t('Green marker'),
50
+ 'Pink marker': t('Pink marker'),
51
+ 'Blue marker': t('Blue marker'),
52
+ 'Red pen': t('Red pen'),
53
+ 'Green pen': t('Green pen')
54
+ };
55
+ }
56
+ /**
57
+ * @inheritDoc
58
+ */
59
+ static get pluginName() {
60
+ return 'HighlightUI';
61
+ }
62
+ /**
63
+ * @inheritDoc
64
+ */
65
+ static get isOfficialPlugin() {
66
+ return true;
67
+ }
68
+ /**
69
+ * @inheritDoc
70
+ */
71
+ init() {
72
+ const options = this.editor.config.get('highlight.options');
73
+ for (const option of options) {
74
+ this._addHighlighterButton(option);
75
+ }
76
+ this._addRemoveHighlightButton();
77
+ this._addDropdown(options);
78
+ this._addMenuBarButton(options);
79
+ }
80
+ /**
81
+ * Creates the "Remove highlight" button.
82
+ */
83
+ _addRemoveHighlightButton() {
84
+ const t = this.editor.t;
85
+ const command = this.editor.commands.get('highlight');
86
+ this._addButton('removeHighlight', t('Remove highlight'), icons.eraser, null, button => {
87
+ button.bind('isEnabled').to(command, 'isEnabled');
88
+ });
89
+ }
90
+ /**
91
+ * Creates a toolbar button from the provided highlight option.
92
+ */
93
+ _addHighlighterButton(option) {
94
+ const command = this.editor.commands.get('highlight');
95
+ // TODO: change naming
96
+ this._addButton('highlight:' + option.model, option.title, getIconForType(option.type), option.model, decorateHighlightButton);
97
+ function decorateHighlightButton(button) {
98
+ button.bind('isEnabled').to(command, 'isEnabled');
99
+ button.bind('isOn').to(command, 'value', value => value === option.model);
100
+ button.iconView.fillColor = option.color;
101
+ button.isToggleable = true;
102
+ }
103
+ }
104
+ /**
105
+ * Internal method for creating highlight buttons.
106
+ *
107
+ * @param name The name of the button.
108
+ * @param label The label for the button.
109
+ * @param icon The button icon.
110
+ * @param value The `value` property passed to the executed command.
111
+ * @param decorateButton A callback getting ButtonView instance so that it can be further customized.
112
+ */
113
+ _addButton(name, label, icon, value, decorateButton) {
114
+ const editor = this.editor;
115
+ editor.ui.componentFactory.add(name, locale => {
116
+ const buttonView = new ButtonView(locale);
117
+ const localized = this.localizedOptionTitles[label] ? this.localizedOptionTitles[label] : label;
118
+ buttonView.set({
119
+ label: localized,
120
+ icon,
121
+ tooltip: true
122
+ });
123
+ buttonView.on('execute', () => {
124
+ editor.execute('highlight', { value });
125
+ editor.editing.view.focus();
126
+ });
127
+ // Add additional behavior for buttonView.
128
+ decorateButton(buttonView);
129
+ return buttonView;
130
+ });
131
+ }
132
+ /**
133
+ * Creates the split button dropdown UI from the provided highlight options.
134
+ */
135
+ _addDropdown(options) {
136
+ const editor = this.editor;
137
+ const t = editor.t;
138
+ const componentFactory = editor.ui.componentFactory;
139
+ const startingHighlighter = options[0];
140
+ const optionsMap = options.reduce((retVal, option) => {
141
+ retVal[option.model] = option;
142
+ return retVal;
143
+ }, {});
144
+ componentFactory.add('highlight', locale => {
145
+ const command = editor.commands.get('highlight');
146
+ const dropdownView = createDropdown(locale, SplitButtonView);
147
+ const splitButtonView = dropdownView.buttonView;
148
+ splitButtonView.set({
149
+ label: t('Highlight'),
150
+ tooltip: true,
151
+ // Holds last executed highlighter.
152
+ lastExecuted: startingHighlighter.model,
153
+ // Holds current highlighter to execute (might be different then last used).
154
+ commandValue: startingHighlighter.model,
155
+ isToggleable: true
156
+ });
157
+ // Dropdown button changes to selection (command.value):
158
+ // - If selection is in highlight it get active highlight appearance (icon, color) and is activated.
159
+ // - Otherwise it gets appearance (icon, color) of last executed highlight.
160
+ splitButtonView.bind('icon').to(command, 'value', value => getIconForType(getActiveOption(value, 'type')));
161
+ splitButtonView.bind('color').to(command, 'value', value => getActiveOption(value, 'color'));
162
+ splitButtonView.bind('commandValue').to(command, 'value', value => getActiveOption(value, 'model'));
163
+ splitButtonView.bind('isOn').to(command, 'value', value => !!value);
164
+ splitButtonView.delegate('execute').to(dropdownView);
165
+ // Create buttons array.
166
+ const buttonsCreator = () => {
167
+ const buttons = options.map(option => {
168
+ // Get existing highlighter button.
169
+ const buttonView = componentFactory.create('highlight:' + option.model);
170
+ // Update lastExecutedHighlight on execute.
171
+ this.listenTo(buttonView, 'execute', () => {
172
+ dropdownView.buttonView.set({ lastExecuted: option.model });
173
+ });
174
+ return buttonView;
175
+ });
176
+ // Add separator and eraser buttons to dropdown.
177
+ buttons.push(new ToolbarSeparatorView());
178
+ buttons.push(componentFactory.create('removeHighlight'));
179
+ return buttons;
180
+ };
181
+ // Make toolbar button enabled when any button in dropdown is enabled before adding separator and eraser.
182
+ dropdownView.bind('isEnabled').to(command, 'isEnabled');
183
+ addToolbarToDropdown(dropdownView, buttonsCreator, {
184
+ enableActiveItemFocusOnDropdownOpen: true,
185
+ ariaLabel: t('Text highlight toolbar')
186
+ });
187
+ bindToolbarIconStyleToActiveColor(dropdownView);
188
+ // Execute current action from dropdown's split button action button.
189
+ splitButtonView.on('execute', () => {
190
+ editor.execute('highlight', { value: splitButtonView.commandValue });
191
+ });
192
+ // Focus the editable after executing the command.
193
+ // It overrides a default behaviour where the focus is moved to the dropdown button (#12125).
194
+ this.listenTo(dropdownView, 'execute', () => {
195
+ editor.editing.view.focus();
196
+ });
197
+ /**
198
+ * Returns active highlighter option depending on current command value.
199
+ * If current is not set or it is the same as last execute this method will return the option key (like icon or color)
200
+ * of last executed highlighter. Otherwise it will return option key for current one.
201
+ */
202
+ function getActiveOption(current, key) {
203
+ const whichHighlighter = !current ||
204
+ current === splitButtonView.lastExecuted ? splitButtonView.lastExecuted : current;
205
+ return optionsMap[whichHighlighter][key];
206
+ }
207
+ return dropdownView;
208
+ });
209
+ }
210
+ /**
211
+ * Creates the menu bar button for highlight including submenu with available options.
212
+ */
213
+ _addMenuBarButton(options) {
214
+ const editor = this.editor;
215
+ const t = editor.t;
216
+ const command = editor.commands.get('highlight');
217
+ editor.ui.componentFactory.add('menuBar:highlight', locale => {
218
+ const menuView = new MenuBarMenuView(locale);
219
+ menuView.buttonView.set({
220
+ label: t('Highlight'),
221
+ icon: getIconForType('marker')
222
+ });
223
+ menuView.bind('isEnabled').to(command);
224
+ menuView.buttonView.iconView.fillColor = 'transparent';
225
+ const listView = new MenuBarMenuListView(locale);
226
+ for (const option of options) {
227
+ const listItemView = new MenuBarMenuListItemView(locale, menuView);
228
+ const buttonView = new MenuBarMenuListItemButtonView(locale);
229
+ buttonView.set({
230
+ label: option.title,
231
+ icon: getIconForType(option.type),
232
+ role: 'menuitemradio',
233
+ isToggleable: true
234
+ });
235
+ buttonView.iconView.fillColor = option.color;
236
+ buttonView.delegate('execute').to(menuView);
237
+ buttonView.bind('isOn').to(command, 'value', value => value === option.model);
238
+ buttonView.on('execute', () => {
239
+ editor.execute('highlight', { value: option.model });
240
+ editor.editing.view.focus();
241
+ });
242
+ listItemView.children.add(buttonView);
243
+ listView.items.add(listItemView);
244
+ }
245
+ // Add remove highlight button
246
+ listView.items.add(new ListSeparatorView(locale));
247
+ const listItemView = new MenuBarMenuListItemView(locale, menuView);
248
+ const buttonView = new MenuBarMenuListItemButtonView(locale);
249
+ buttonView.set({
250
+ label: t('Remove highlight'),
251
+ icon: icons.eraser
252
+ });
253
+ buttonView.delegate('execute').to(menuView);
254
+ buttonView.on('execute', () => {
255
+ editor.execute('highlight', { value: null });
256
+ editor.editing.view.focus();
257
+ });
258
+ listItemView.children.add(buttonView);
259
+ listView.items.add(listItemView);
260
+ menuView.panelView.children.add(listView);
261
+ return menuView;
262
+ });
263
+ }
264
+ }
265
+ /**
266
+ * Extends split button icon style to reflect last used button style.
267
+ */
268
+ function bindToolbarIconStyleToActiveColor(dropdownView) {
269
+ const actionView = dropdownView.buttonView.actionView;
270
+ actionView.iconView.bind('fillColor').to(dropdownView.buttonView, 'color');
271
+ }
272
+ /**
273
+ * Returns icon for given highlighter type.
274
+ */
275
+ function getIconForType(type) {
276
+ return type === 'marker' ? markerIcon : penIcon;
277
+ }
package/src/index.d.ts ADDED
@@ -0,0 +1,13 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
3
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
+ */
5
+ /**
6
+ * @module highlight
7
+ */
8
+ export { default as Highlight } from './highlight.js';
9
+ export { default as HighlightEditing } from './highlightediting.js';
10
+ export { default as HighlightUI } from './highlightui.js';
11
+ export type { default as HighlightCommand } from './highlightcommand.js';
12
+ export type { HighlightOption, HighlightConfig } from './highlightconfig.js';
13
+ import './augmentation.js';
package/src/index.js ADDED
@@ -0,0 +1,11 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
3
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
+ */
5
+ /**
6
+ * @module highlight
7
+ */
8
+ export { default as Highlight } from './highlight.js';
9
+ export { default as HighlightEditing } from './highlightediting.js';
10
+ export { default as HighlightUI } from './highlightui.js';
11
+ import './augmentation.js';
@@ -0,0 +1,36 @@
1
+ /*
2
+ * 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
+ :root {
7
+ --ck-highlight-marker-yellow: hsl(60, 97%, 73%);
8
+ --ck-highlight-marker-green: hsl(120, 93%, 68%);
9
+ --ck-highlight-marker-pink: hsl(345, 96%, 73%);
10
+ --ck-highlight-marker-blue: hsl(201, 97%, 72%);
11
+ --ck-highlight-pen-red: hsl(0, 85%, 49%);
12
+ --ck-highlight-pen-green: hsl(112, 100%, 27%);
13
+ }
14
+
15
+ @define-mixin highlight-marker-color $color {
16
+ .ck-content .marker-$color {
17
+ background-color: var(--ck-highlight-marker-$color);
18
+ }
19
+ }
20
+
21
+ @define-mixin highlight-pen-color $color {
22
+ .ck-content .pen-$color {
23
+ color: var(--ck-highlight-pen-$color);
24
+
25
+ /* Override default yellow background of `<mark>` from user agent stylesheet */
26
+ background-color: transparent;
27
+ }
28
+ }
29
+
30
+ @mixin highlight-marker-color yellow;
31
+ @mixin highlight-marker-color green;
32
+ @mixin highlight-marker-color pink;
33
+ @mixin highlight-marker-color blue;
34
+
35
+ @mixin highlight-pen-color red;
36
+ @mixin highlight-pen-color green;
@@ -0,0 +1 @@
1
+ <svg viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"><path class="ck-icon__fill" d="M10.798 1.59 3.002 12.875l1.895 1.852 2.521 1.402 6.997-12.194z"/><path d="m2.556 16.727.234-.348c-.297-.151-.462-.293-.498-.426-.036-.137.002-.416.115-.837.094-.25.15-.449.169-.595a4.495 4.495 0 0 0 0-.725c-.209-.621-.303-1.041-.284-1.26.02-.218.178-.506.475-.862l6.77-9.414c.539-.91 1.605-.85 3.199.18 1.594 1.032 2.188 1.928 1.784 2.686l-5.877 10.36c-.158.412-.333.673-.526.782-.193.108-.604.179-1.232.21-.362.131-.608.237-.738.318-.13.081-.305.238-.526.47-.293.265-.504.397-.632.397-.096 0-.27-.075-.524-.226l-.31.41-1.6-1.12zm-.279.415 1.575 1.103-.392.515H1.19l1.087-1.618zm8.1-13.656-4.953 6.9L8.75 12.57l4.247-7.574c.175-.25-.188-.647-1.092-1.192-.903-.546-1.412-.652-1.528-.32zM8.244 18.5 9.59 17h9.406v1.5H8.245z"/></svg>
@@ -0,0 +1 @@
1
+ <svg viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"><path class="ck-icon__fill" d="M10.126 2.268 2.002 13.874l1.895 1.852 2.521 1.402L14.47 5.481l-1.543-2.568-2.801-.645z"/><path d="m4.5 18.088-2.645-1.852-.04-2.95-.006-.005.006-.008v-.025l.011.008L8.73 2.97c.165-.233.356-.417.567-.557l-1.212.308L4.604 7.9l-.83-.558 3.694-5.495 2.708-.69 1.65 1.145.046.018.85-1.216 2.16 1.512-.856 1.222c.828.967 1.144 2.141.432 3.158L7.55 17.286l.006.005-3.055.797H4.5zm-.634.166-1.976.516-.026-1.918 2.002 1.402zM9.968 3.817l-.006-.004-6.123 9.184 3.277 2.294 6.108-9.162.005.003c.317-.452-.16-1.332-1.064-1.966-.891-.624-1.865-.776-2.197-.349zM8.245 18.5 9.59 17h9.406v1.5H8.245z"/></svg>