@ckeditor/ckeditor5-highlight 47.6.1 → 48.0.0-alpha.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 (169) hide show
  1. package/ckeditor5-metadata.json +2 -2
  2. package/{src → dist}/highlight.d.ts +1 -1
  3. package/{src → dist}/highlightcommand.d.ts +1 -1
  4. package/{src → dist}/highlightediting.d.ts +1 -1
  5. package/{src → dist}/highlightui.d.ts +1 -1
  6. package/dist/index-content.css +24 -20
  7. package/dist/index-editor.css +6 -6
  8. package/dist/index.css +23 -28
  9. package/dist/index.css.map +1 -1
  10. package/dist/index.js.map +1 -1
  11. package/package.json +23 -47
  12. package/build/highlight.js +0 -5
  13. package/build/translations/af.js +0 -1
  14. package/build/translations/ar.js +0 -1
  15. package/build/translations/ast.js +0 -1
  16. package/build/translations/az.js +0 -1
  17. package/build/translations/be.js +0 -1
  18. package/build/translations/bg.js +0 -1
  19. package/build/translations/bn.js +0 -1
  20. package/build/translations/bs.js +0 -1
  21. package/build/translations/ca.js +0 -1
  22. package/build/translations/cs.js +0 -1
  23. package/build/translations/da.js +0 -1
  24. package/build/translations/de-ch.js +0 -1
  25. package/build/translations/de.js +0 -1
  26. package/build/translations/el.js +0 -1
  27. package/build/translations/en-au.js +0 -1
  28. package/build/translations/en-gb.js +0 -1
  29. package/build/translations/eo.js +0 -1
  30. package/build/translations/es-co.js +0 -1
  31. package/build/translations/es.js +0 -1
  32. package/build/translations/et.js +0 -1
  33. package/build/translations/eu.js +0 -1
  34. package/build/translations/fa.js +0 -1
  35. package/build/translations/fi.js +0 -1
  36. package/build/translations/fr.js +0 -1
  37. package/build/translations/gl.js +0 -1
  38. package/build/translations/gu.js +0 -1
  39. package/build/translations/he.js +0 -1
  40. package/build/translations/hi.js +0 -1
  41. package/build/translations/hr.js +0 -1
  42. package/build/translations/hu.js +0 -1
  43. package/build/translations/hy.js +0 -1
  44. package/build/translations/id.js +0 -1
  45. package/build/translations/it.js +0 -1
  46. package/build/translations/ja.js +0 -1
  47. package/build/translations/jv.js +0 -1
  48. package/build/translations/kk.js +0 -1
  49. package/build/translations/km.js +0 -1
  50. package/build/translations/kn.js +0 -1
  51. package/build/translations/ko.js +0 -1
  52. package/build/translations/ku.js +0 -1
  53. package/build/translations/lt.js +0 -1
  54. package/build/translations/lv.js +0 -1
  55. package/build/translations/ms.js +0 -1
  56. package/build/translations/nb.js +0 -1
  57. package/build/translations/ne.js +0 -1
  58. package/build/translations/nl.js +0 -1
  59. package/build/translations/no.js +0 -1
  60. package/build/translations/oc.js +0 -1
  61. package/build/translations/pl.js +0 -1
  62. package/build/translations/pt-br.js +0 -1
  63. package/build/translations/pt.js +0 -1
  64. package/build/translations/ro.js +0 -1
  65. package/build/translations/ru.js +0 -1
  66. package/build/translations/si.js +0 -1
  67. package/build/translations/sk.js +0 -1
  68. package/build/translations/sl.js +0 -1
  69. package/build/translations/sq.js +0 -1
  70. package/build/translations/sr-latn.js +0 -1
  71. package/build/translations/sr.js +0 -1
  72. package/build/translations/sv.js +0 -1
  73. package/build/translations/th.js +0 -1
  74. package/build/translations/ti.js +0 -1
  75. package/build/translations/tk.js +0 -1
  76. package/build/translations/tr.js +0 -1
  77. package/build/translations/tt.js +0 -1
  78. package/build/translations/ug.js +0 -1
  79. package/build/translations/uk.js +0 -1
  80. package/build/translations/ur.js +0 -1
  81. package/build/translations/uz.js +0 -1
  82. package/build/translations/vi.js +0 -1
  83. package/build/translations/zh-cn.js +0 -1
  84. package/build/translations/zh.js +0 -1
  85. package/lang/contexts.json +0 -11
  86. package/lang/translations/af.po +0 -48
  87. package/lang/translations/ar.po +0 -48
  88. package/lang/translations/ast.po +0 -48
  89. package/lang/translations/az.po +0 -48
  90. package/lang/translations/be.po +0 -48
  91. package/lang/translations/bg.po +0 -48
  92. package/lang/translations/bn.po +0 -48
  93. package/lang/translations/bs.po +0 -48
  94. package/lang/translations/ca.po +0 -48
  95. package/lang/translations/cs.po +0 -48
  96. package/lang/translations/da.po +0 -48
  97. package/lang/translations/de-ch.po +0 -48
  98. package/lang/translations/de.po +0 -48
  99. package/lang/translations/el.po +0 -48
  100. package/lang/translations/en-au.po +0 -48
  101. package/lang/translations/en-gb.po +0 -48
  102. package/lang/translations/en.po +0 -48
  103. package/lang/translations/eo.po +0 -48
  104. package/lang/translations/es-co.po +0 -48
  105. package/lang/translations/es.po +0 -48
  106. package/lang/translations/et.po +0 -48
  107. package/lang/translations/eu.po +0 -48
  108. package/lang/translations/fa.po +0 -48
  109. package/lang/translations/fi.po +0 -48
  110. package/lang/translations/fr.po +0 -48
  111. package/lang/translations/gl.po +0 -48
  112. package/lang/translations/gu.po +0 -48
  113. package/lang/translations/he.po +0 -48
  114. package/lang/translations/hi.po +0 -48
  115. package/lang/translations/hr.po +0 -48
  116. package/lang/translations/hu.po +0 -48
  117. package/lang/translations/hy.po +0 -48
  118. package/lang/translations/id.po +0 -48
  119. package/lang/translations/it.po +0 -48
  120. package/lang/translations/ja.po +0 -48
  121. package/lang/translations/jv.po +0 -48
  122. package/lang/translations/kk.po +0 -48
  123. package/lang/translations/km.po +0 -48
  124. package/lang/translations/kn.po +0 -48
  125. package/lang/translations/ko.po +0 -48
  126. package/lang/translations/ku.po +0 -48
  127. package/lang/translations/lt.po +0 -48
  128. package/lang/translations/lv.po +0 -48
  129. package/lang/translations/ms.po +0 -48
  130. package/lang/translations/nb.po +0 -48
  131. package/lang/translations/ne.po +0 -48
  132. package/lang/translations/nl.po +0 -48
  133. package/lang/translations/no.po +0 -48
  134. package/lang/translations/oc.po +0 -48
  135. package/lang/translations/pl.po +0 -48
  136. package/lang/translations/pt-br.po +0 -48
  137. package/lang/translations/pt.po +0 -48
  138. package/lang/translations/ro.po +0 -48
  139. package/lang/translations/ru.po +0 -48
  140. package/lang/translations/si.po +0 -48
  141. package/lang/translations/sk.po +0 -48
  142. package/lang/translations/sl.po +0 -48
  143. package/lang/translations/sq.po +0 -48
  144. package/lang/translations/sr-latn.po +0 -48
  145. package/lang/translations/sr.po +0 -48
  146. package/lang/translations/sv.po +0 -48
  147. package/lang/translations/th.po +0 -48
  148. package/lang/translations/ti.po +0 -48
  149. package/lang/translations/tk.po +0 -48
  150. package/lang/translations/tr.po +0 -48
  151. package/lang/translations/tt.po +0 -48
  152. package/lang/translations/ug.po +0 -48
  153. package/lang/translations/uk.po +0 -48
  154. package/lang/translations/ur.po +0 -48
  155. package/lang/translations/uz.po +0 -48
  156. package/lang/translations/vi.po +0 -48
  157. package/lang/translations/zh-cn.po +0 -48
  158. package/lang/translations/zh.po +0 -48
  159. package/src/augmentation.js +0 -5
  160. package/src/highlight.js +0 -38
  161. package/src/highlightcommand.js +0 -100
  162. package/src/highlightconfig.js +0 -5
  163. package/src/highlightediting.js +0 -115
  164. package/src/highlightui.js +0 -276
  165. package/src/index.js +0 -12
  166. package/theme/highlight.css +0 -36
  167. /package/{src → dist}/augmentation.d.ts +0 -0
  168. /package/{src → dist}/highlightconfig.d.ts +0 -0
  169. /package/{src → dist}/index.d.ts +0 -0
@@ -1,48 +0,0 @@
1
- # Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
2
- #
3
- # Want to contribute to this file? Submit your changes via a GitHub Pull Request.
4
- #
5
- # Check out the official contributor's guide:
6
- # https://ckeditor.com/docs/ckeditor5/latest/framework/guides/contributing/contributing.html
7
- #
8
- msgid ""
9
- msgstr ""
10
- "Language: zh_CN\n"
11
- "Plural-Forms: nplurals=1; plural=0;\n"
12
- "Content-Type: text/plain; charset=UTF-8\n"
13
-
14
- msgctxt "Toolbar button tooltip for applying yellow marker (text highlight)."
15
- msgid "Yellow marker"
16
- msgstr "黄色标记"
17
-
18
- msgctxt "Toolbar button tooltip for applying green marker (text highlight)."
19
- msgid "Green marker"
20
- msgstr "绿色标记"
21
-
22
- msgctxt "Toolbar button tooltip for applying pink marker (text highlight)."
23
- msgid "Pink marker"
24
- msgstr "粉色标记"
25
-
26
- msgctxt "Toolbar button tooltip for applying blue marker (text highlight)."
27
- msgid "Blue marker"
28
- msgstr "蓝色标记"
29
-
30
- msgctxt "Toolbar button tooltip for applying red pen (text color)."
31
- msgid "Red pen"
32
- msgstr "红色笔"
33
-
34
- msgctxt "Toolbar button tooltip for applying green pen (text color)."
35
- msgid "Green pen"
36
- msgstr "绿色笔"
37
-
38
- msgctxt "Toolbar button tooltip for removing text highlight."
39
- msgid "Remove highlight"
40
- msgstr "清除高亮"
41
-
42
- msgctxt "Toolbar button tooltip for the text highlight feature."
43
- msgid "Highlight"
44
- msgstr "高亮"
45
-
46
- msgctxt "Label used by assistive technologies describing the highlight feature toolbar."
47
- msgid "Text highlight toolbar"
48
- msgstr "文本高亮工具栏"
@@ -1,48 +0,0 @@
1
- # Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
2
- #
3
- # Want to contribute to this file? Submit your changes via a GitHub Pull Request.
4
- #
5
- # Check out the official contributor's guide:
6
- # https://ckeditor.com/docs/ckeditor5/latest/framework/guides/contributing/contributing.html
7
- #
8
- msgid ""
9
- msgstr ""
10
- "Language: zh_TW\n"
11
- "Plural-Forms: nplurals=1; plural=0;\n"
12
- "Content-Type: text/plain; charset=UTF-8\n"
13
-
14
- msgctxt "Toolbar button tooltip for applying yellow marker (text highlight)."
15
- msgid "Yellow marker"
16
- msgstr "黃色標記"
17
-
18
- msgctxt "Toolbar button tooltip for applying green marker (text highlight)."
19
- msgid "Green marker"
20
- msgstr "綠色標記"
21
-
22
- msgctxt "Toolbar button tooltip for applying pink marker (text highlight)."
23
- msgid "Pink marker"
24
- msgstr "粉色標記"
25
-
26
- msgctxt "Toolbar button tooltip for applying blue marker (text highlight)."
27
- msgid "Blue marker"
28
- msgstr "藍色標記"
29
-
30
- msgctxt "Toolbar button tooltip for applying red pen (text color)."
31
- msgid "Red pen"
32
- msgstr "紅色筆"
33
-
34
- msgctxt "Toolbar button tooltip for applying green pen (text color)."
35
- msgid "Green pen"
36
- msgstr "綠色筆"
37
-
38
- msgctxt "Toolbar button tooltip for removing text highlight."
39
- msgid "Remove highlight"
40
- msgstr "清除高亮"
41
-
42
- msgctxt "Toolbar button tooltip for the text highlight feature."
43
- msgid "Highlight"
44
- msgstr "高亮"
45
-
46
- msgctxt "Label used by assistive technologies describing the highlight feature toolbar."
47
- msgid "Text highlight toolbar"
48
- msgstr "高亮"
@@ -1,5 +0,0 @@
1
- /**
2
- * @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
3
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
4
- */
5
- export {};
package/src/highlight.js DELETED
@@ -1,38 +0,0 @@
1
- /**
2
- * @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
3
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
4
- */
5
- /**
6
- * @module highlight/highlight
7
- */
8
- import { Plugin } from 'ckeditor5/src/core.js';
9
- import { HighlightEditing } from './highlightediting.js';
10
- import { HighlightUI } from './highlightui.js';
11
- /**
12
- * The highlight plugin.
13
- *
14
- * For a detailed overview, check the {@glink features/highlight Highlight feature} documentation.
15
- *
16
- * This is a "glue" plugin which loads the {@link module:highlight/highlightediting~HighlightEditing} and
17
- * {@link module:highlight/highlightui~HighlightUI} plugins.
18
- */
19
- export class Highlight extends Plugin {
20
- /**
21
- * @inheritDoc
22
- */
23
- static get requires() {
24
- return [HighlightEditing, HighlightUI];
25
- }
26
- /**
27
- * @inheritDoc
28
- */
29
- static get pluginName() {
30
- return 'Highlight';
31
- }
32
- /**
33
- * @inheritDoc
34
- */
35
- static get isOfficialPlugin() {
36
- return true;
37
- }
38
- }
@@ -1,100 +0,0 @@
1
- /**
2
- * @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
3
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
4
- */
5
- /**
6
- * @module highlight/highlightcommand
7
- */
8
- import { Command } from 'ckeditor5/src/core.js';
9
- import { ModelDocumentSelection } from 'ckeditor5/src/engine.js';
10
- /**
11
- * The highlight command. It is used by the {@link module:highlight/highlightediting~HighlightEditing highlight feature}
12
- * to apply the text highlighting.
13
- *
14
- * ```ts
15
- * editor.execute( 'highlight', { value: 'greenMarker' } );
16
- * ```
17
- *
18
- * **Note**: Executing the command without a value removes the attribute from the model. If the selection is collapsed
19
- * inside a text with the highlight attribute, the command will remove the attribute from the entire range
20
- * of that text.
21
- */
22
- export class HighlightCommand extends Command {
23
- /**
24
- * @inheritDoc
25
- */
26
- refresh() {
27
- const model = this.editor.model;
28
- const doc = model.document;
29
- this.value = doc.selection.getAttribute('highlight');
30
- this.isEnabled = model.schema.checkAttributeInSelection(doc.selection, 'highlight');
31
- }
32
- /**
33
- * Executes the command.
34
- *
35
- * @param options Options for the executed command.
36
- * @param options.value The value to apply.
37
- *
38
- * @fires execute
39
- */
40
- execute(options = {}) {
41
- const model = this.editor.model;
42
- const document = model.document;
43
- const selection = document.selection;
44
- const highlighter = options.value;
45
- model.change(writer => {
46
- if (selection.isCollapsed) {
47
- const position = selection.getFirstPosition();
48
- // When selection is inside text with `highlight` attribute.
49
- if (selection.hasAttribute('highlight')) {
50
- // Find the full highlighted range.
51
- const isSameHighlight = (value) => {
52
- return value.item.hasAttribute('highlight') && value.item.getAttribute('highlight') === this.value;
53
- };
54
- const highlightStart = position.getLastMatchingPosition(isSameHighlight, { direction: 'backward' });
55
- const highlightEnd = position.getLastMatchingPosition(isSameHighlight);
56
- const highlightRange = writer.createRange(highlightStart, highlightEnd);
57
- // Then depending on current value...
58
- if (!highlighter || this.value === highlighter) {
59
- // ...remove attribute when passing highlighter different then current or executing "eraser".
60
- // If we're at the end of the highlighted range, we don't want to remove highlight of the range.
61
- if (!position.isEqual(highlightEnd)) {
62
- writer.removeAttribute('highlight', highlightRange);
63
- }
64
- writer.removeSelectionAttribute('highlight');
65
- }
66
- else {
67
- // ...update `highlight` value.
68
- // If we're at the end of the highlighted range, we don't want to change the highlight of the range.
69
- if (!position.isEqual(highlightEnd)) {
70
- writer.setAttribute('highlight', highlighter, highlightRange);
71
- }
72
- writer.setSelectionAttribute('highlight', highlighter);
73
- }
74
- }
75
- else if (highlighter) {
76
- writer.setSelectionAttribute('highlight', highlighter);
77
- }
78
- }
79
- else {
80
- const ranges = model.schema.getValidRanges(selection.getRanges(), 'highlight', {
81
- includeEmptyRanges: true
82
- });
83
- for (const range of ranges) {
84
- let itemOrRange = range;
85
- let attributeKey = 'highlight';
86
- if (range.isCollapsed) {
87
- itemOrRange = range.start.parent;
88
- attributeKey = ModelDocumentSelection._getStoreAttributeKey('highlight');
89
- }
90
- if (highlighter) {
91
- writer.setAttribute(attributeKey, highlighter, itemOrRange);
92
- }
93
- else {
94
- writer.removeAttribute(attributeKey, itemOrRange);
95
- }
96
- }
97
- }
98
- });
99
- }
100
- }
@@ -1,5 +0,0 @@
1
- /**
2
- * @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
3
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
4
- */
5
- export {};
@@ -1,115 +0,0 @@
1
- /**
2
- * @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
3
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
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 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-content-highlight-marker-yellow)',
41
- type: 'marker'
42
- },
43
- {
44
- model: 'greenMarker',
45
- class: 'marker-green',
46
- title: 'Green marker',
47
- color: 'var(--ck-content-highlight-marker-green)',
48
- type: 'marker'
49
- },
50
- {
51
- model: 'pinkMarker',
52
- class: 'marker-pink',
53
- title: 'Pink marker',
54
- color: 'var(--ck-content-highlight-marker-pink)',
55
- type: 'marker'
56
- },
57
- {
58
- model: 'blueMarker',
59
- class: 'marker-blue',
60
- title: 'Blue marker',
61
- color: 'var(--ck-content-highlight-marker-blue)',
62
- type: 'marker'
63
- },
64
- {
65
- model: 'redPen',
66
- class: 'pen-red',
67
- title: 'Red pen',
68
- color: 'var(--ck-content-highlight-pen-red)',
69
- type: 'pen'
70
- },
71
- {
72
- model: 'greenPen',
73
- class: 'pen-green',
74
- title: 'Green pen',
75
- color: 'var(--ck-content-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
- }
@@ -1,276 +0,0 @@
1
- /**
2
- * @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
3
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
4
- */
5
- /**
6
- * @module highlight/highlightui
7
- */
8
- import { Plugin } from 'ckeditor5/src/core.js';
9
- import { IconEraser, IconMarker, IconPen } from 'ckeditor5/src/icons.js';
10
- import { addToolbarToDropdown, createDropdown, ButtonView, ListSeparatorView, MenuBarMenuView, MenuBarMenuListView, MenuBarMenuListItemView, MenuBarMenuListItemButtonView, SplitButtonView, ToolbarSeparatorView } from 'ckeditor5/src/ui.js';
11
- import './../theme/highlight.css';
12
- /**
13
- * The default highlight UI plugin. It introduces:
14
- *
15
- * * The `'highlight'` dropdown,
16
- * * The `'removeHighlight'` and `'highlight:*'` buttons.
17
- *
18
- * The default configuration includes the following buttons:
19
- *
20
- * * `'highlight:yellowMarker'`
21
- * * `'highlight:greenMarker'`
22
- * * `'highlight:pinkMarker'`
23
- * * `'highlight:blueMarker'`
24
- * * `'highlight:redPen'`
25
- * * `'highlight:greenPen'`
26
- *
27
- * See the {@link module:highlight/highlightconfig~HighlightConfig#options configuration} to learn more
28
- * about the defaults.
29
- */
30
- export class HighlightUI extends Plugin {
31
- /**
32
- * Returns the localized option titles provided by the plugin.
33
- *
34
- * The following localized titles corresponding with default
35
- * {@link module:highlight/highlightconfig~HighlightConfig#options} are available:
36
- *
37
- * * `'Yellow marker'`,
38
- * * `'Green marker'`,
39
- * * `'Pink marker'`,
40
- * * `'Blue marker'`,
41
- * * `'Red pen'`,
42
- * * `'Green pen'`.
43
- */
44
- get localizedOptionTitles() {
45
- const t = this.editor.t;
46
- return {
47
- 'Yellow marker': t('Yellow marker'),
48
- 'Green marker': t('Green marker'),
49
- 'Pink marker': t('Pink marker'),
50
- 'Blue marker': t('Blue marker'),
51
- 'Red pen': t('Red pen'),
52
- 'Green pen': t('Green pen')
53
- };
54
- }
55
- /**
56
- * @inheritDoc
57
- */
58
- static get pluginName() {
59
- return 'HighlightUI';
60
- }
61
- /**
62
- * @inheritDoc
63
- */
64
- static get isOfficialPlugin() {
65
- return true;
66
- }
67
- /**
68
- * @inheritDoc
69
- */
70
- init() {
71
- const options = this.editor.config.get('highlight.options');
72
- for (const option of options) {
73
- this._addHighlighterButton(option);
74
- }
75
- this._addRemoveHighlightButton();
76
- this._addDropdown(options);
77
- this._addMenuBarButton(options);
78
- }
79
- /**
80
- * Creates the "Remove highlight" button.
81
- */
82
- _addRemoveHighlightButton() {
83
- const t = this.editor.t;
84
- const command = this.editor.commands.get('highlight');
85
- this._addButton('removeHighlight', t('Remove highlight'), IconEraser, null, button => {
86
- button.bind('isEnabled').to(command, 'isEnabled');
87
- });
88
- }
89
- /**
90
- * Creates a toolbar button from the provided highlight option.
91
- */
92
- _addHighlighterButton(option) {
93
- const command = this.editor.commands.get('highlight');
94
- // TODO: change naming
95
- this._addButton('highlight:' + option.model, option.title, getIconForType(option.type), option.model, decorateHighlightButton);
96
- function decorateHighlightButton(button) {
97
- button.bind('isEnabled').to(command, 'isEnabled');
98
- button.bind('isOn').to(command, 'value', value => value === option.model);
99
- button.iconView.fillColor = option.color;
100
- button.isToggleable = true;
101
- }
102
- }
103
- /**
104
- * Internal method for creating highlight buttons.
105
- *
106
- * @param name The name of the button.
107
- * @param label The label for the button.
108
- * @param icon The button icon.
109
- * @param value The `value` property passed to the executed command.
110
- * @param decorateButton A callback getting ButtonView instance so that it can be further customized.
111
- */
112
- _addButton(name, label, icon, value, decorateButton) {
113
- const editor = this.editor;
114
- editor.ui.componentFactory.add(name, locale => {
115
- const buttonView = new ButtonView(locale);
116
- const localized = this.localizedOptionTitles[label] ? this.localizedOptionTitles[label] : label;
117
- buttonView.set({
118
- label: localized,
119
- icon,
120
- tooltip: true
121
- });
122
- buttonView.on('execute', () => {
123
- editor.execute('highlight', { value });
124
- editor.editing.view.focus();
125
- });
126
- // Add additional behavior for buttonView.
127
- decorateButton(buttonView);
128
- return buttonView;
129
- });
130
- }
131
- /**
132
- * Creates the split button dropdown UI from the provided highlight options.
133
- */
134
- _addDropdown(options) {
135
- const editor = this.editor;
136
- const t = editor.t;
137
- const componentFactory = editor.ui.componentFactory;
138
- const startingHighlighter = options[0];
139
- const optionsMap = options.reduce((retVal, option) => {
140
- retVal[option.model] = option;
141
- return retVal;
142
- }, {});
143
- componentFactory.add('highlight', locale => {
144
- const command = editor.commands.get('highlight');
145
- const dropdownView = createDropdown(locale, SplitButtonView);
146
- const splitButtonView = dropdownView.buttonView;
147
- splitButtonView.set({
148
- label: t('Highlight'),
149
- tooltip: true,
150
- // Holds last executed highlighter.
151
- lastExecuted: startingHighlighter.model,
152
- // Holds current highlighter to execute (might be different then last used).
153
- commandValue: startingHighlighter.model,
154
- isToggleable: true
155
- });
156
- // Dropdown button changes to selection (command.value):
157
- // - If selection is in highlight it get active highlight appearance (icon, color) and is activated.
158
- // - Otherwise it gets appearance (icon, color) of last executed highlight.
159
- splitButtonView.bind('icon').to(command, 'value', value => getIconForType(getActiveOption(value, 'type')));
160
- splitButtonView.bind('color').to(command, 'value', value => getActiveOption(value, 'color'));
161
- splitButtonView.bind('commandValue').to(command, 'value', value => getActiveOption(value, 'model'));
162
- splitButtonView.bind('isOn').to(command, 'value', value => !!value);
163
- splitButtonView.delegate('execute').to(dropdownView);
164
- // Create buttons array.
165
- const buttonsCreator = () => {
166
- const buttons = options.map(option => {
167
- // Get existing highlighter button.
168
- const buttonView = componentFactory.create('highlight:' + option.model);
169
- // Update lastExecutedHighlight on execute.
170
- this.listenTo(buttonView, 'execute', () => {
171
- dropdownView.buttonView.set({ lastExecuted: option.model });
172
- });
173
- return buttonView;
174
- });
175
- // Add separator and eraser buttons to dropdown.
176
- buttons.push(new ToolbarSeparatorView());
177
- buttons.push(componentFactory.create('removeHighlight'));
178
- return buttons;
179
- };
180
- // Make toolbar button enabled when any button in dropdown is enabled before adding separator and eraser.
181
- dropdownView.bind('isEnabled').to(command, 'isEnabled');
182
- addToolbarToDropdown(dropdownView, buttonsCreator, {
183
- enableActiveItemFocusOnDropdownOpen: true,
184
- ariaLabel: t('Text highlight toolbar')
185
- });
186
- bindToolbarIconStyleToActiveColor(dropdownView);
187
- // Execute current action from dropdown's split button action button.
188
- splitButtonView.on('execute', () => {
189
- editor.execute('highlight', { value: splitButtonView.commandValue });
190
- });
191
- // Focus the editable after executing the command.
192
- // It overrides a default behaviour where the focus is moved to the dropdown button (#12125).
193
- this.listenTo(dropdownView, 'execute', () => {
194
- editor.editing.view.focus();
195
- });
196
- /**
197
- * Returns active highlighter option depending on current command value.
198
- * If current is not set or it is the same as last execute this method will return the option key (like icon or color)
199
- * of last executed highlighter. Otherwise it will return option key for current one.
200
- */
201
- function getActiveOption(current, key) {
202
- const whichHighlighter = !current ||
203
- current === splitButtonView.lastExecuted ? splitButtonView.lastExecuted : current;
204
- return optionsMap[whichHighlighter][key];
205
- }
206
- return dropdownView;
207
- });
208
- }
209
- /**
210
- * Creates the menu bar button for highlight including submenu with available options.
211
- */
212
- _addMenuBarButton(options) {
213
- const editor = this.editor;
214
- const t = editor.t;
215
- const command = editor.commands.get('highlight');
216
- editor.ui.componentFactory.add('menuBar:highlight', locale => {
217
- const menuView = new MenuBarMenuView(locale);
218
- menuView.buttonView.set({
219
- label: t('Highlight'),
220
- icon: getIconForType('marker')
221
- });
222
- menuView.bind('isEnabled').to(command);
223
- menuView.buttonView.iconView.fillColor = 'transparent';
224
- const listView = new MenuBarMenuListView(locale);
225
- for (const option of options) {
226
- const listItemView = new MenuBarMenuListItemView(locale, menuView);
227
- const buttonView = new MenuBarMenuListItemButtonView(locale);
228
- buttonView.set({
229
- label: option.title,
230
- icon: getIconForType(option.type),
231
- role: 'menuitemradio',
232
- isToggleable: true
233
- });
234
- buttonView.iconView.fillColor = option.color;
235
- buttonView.delegate('execute').to(menuView);
236
- buttonView.bind('isOn').to(command, 'value', value => value === option.model);
237
- buttonView.on('execute', () => {
238
- editor.execute('highlight', { value: option.model });
239
- editor.editing.view.focus();
240
- });
241
- listItemView.children.add(buttonView);
242
- listView.items.add(listItemView);
243
- }
244
- // Add remove highlight button
245
- listView.items.add(new ListSeparatorView(locale));
246
- const listItemView = new MenuBarMenuListItemView(locale, menuView);
247
- const buttonView = new MenuBarMenuListItemButtonView(locale);
248
- buttonView.set({
249
- label: t('Remove highlight'),
250
- icon: IconEraser
251
- });
252
- buttonView.delegate('execute').to(menuView);
253
- buttonView.on('execute', () => {
254
- editor.execute('highlight', { value: null });
255
- editor.editing.view.focus();
256
- });
257
- listItemView.children.add(buttonView);
258
- listView.items.add(listItemView);
259
- menuView.panelView.children.add(listView);
260
- return menuView;
261
- });
262
- }
263
- }
264
- /**
265
- * Extends split button icon style to reflect last used button style.
266
- */
267
- function bindToolbarIconStyleToActiveColor(dropdownView) {
268
- const actionView = dropdownView.buttonView.actionView;
269
- actionView.iconView.bind('fillColor').to(dropdownView.buttonView, 'color');
270
- }
271
- /**
272
- * Returns icon for given highlighter type.
273
- */
274
- function getIconForType(type) {
275
- return type === 'marker' ? IconMarker : IconPen;
276
- }
package/src/index.js DELETED
@@ -1,12 +0,0 @@
1
- /**
2
- * @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
3
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
4
- */
5
- /**
6
- * @module highlight
7
- */
8
- export { Highlight } from './highlight.js';
9
- export { HighlightEditing } from './highlightediting.js';
10
- export { HighlightUI } from './highlightui.js';
11
- export { HighlightCommand } from './highlightcommand.js';
12
- import './augmentation.js';