@ckeditor/ckeditor5-highlight 48.2.0 → 48.3.0-alpha.1
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.
- package/dist/augmentation.d.ts +21 -21
- package/dist/highlight.d.ts +27 -27
- package/dist/highlightcommand.d.ts +40 -40
- package/dist/highlightconfig.d.ts +163 -163
- package/dist/highlightediting.d.ts +27 -27
- package/dist/highlightui.d.ts +76 -76
- package/dist/index.css.map +1 -1
- package/dist/index.d.ts +11 -11
- package/dist/index.js +470 -472
- package/dist/index.js.map +1 -1
- package/package.json +6 -6
package/dist/index.js
CHANGED
|
@@ -2,491 +2,489 @@
|
|
|
2
2
|
* @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
3
|
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
|
|
4
4
|
*/
|
|
5
|
-
import { Command, Plugin } from
|
|
6
|
-
import { ModelDocumentSelection } from
|
|
7
|
-
import { IconEraser, IconMarker, IconPen } from
|
|
8
|
-
import { ButtonView,
|
|
5
|
+
import { Command, Plugin } from "@ckeditor/ckeditor5-core";
|
|
6
|
+
import { ModelDocumentSelection } from "@ckeditor/ckeditor5-engine";
|
|
7
|
+
import { IconEraser, IconMarker, IconPen } from "@ckeditor/ckeditor5-icons";
|
|
8
|
+
import { ButtonView, ListSeparatorView, MenuBarMenuListItemButtonView, MenuBarMenuListItemView, MenuBarMenuListView, MenuBarMenuView, SplitButtonView, ToolbarSeparatorView, addToolbarToDropdown, createDropdown } from "@ckeditor/ckeditor5-ui";
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
}
|
|
86
|
-
if (highlighter) {
|
|
87
|
-
writer.setAttribute(attributeKey, highlighter, itemOrRange);
|
|
88
|
-
} else {
|
|
89
|
-
writer.removeAttribute(attributeKey, itemOrRange);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
}
|
|
11
|
+
* @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
|
|
12
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* @module highlight/highlightcommand
|
|
16
|
+
*/
|
|
17
|
+
/**
|
|
18
|
+
* The highlight command. It is used by the {@link module:highlight/highlightediting~HighlightEditing highlight feature}
|
|
19
|
+
* to apply the text highlighting.
|
|
20
|
+
*
|
|
21
|
+
* ```ts
|
|
22
|
+
* editor.execute( 'highlight', { value: 'greenMarker' } );
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* **Note**: Executing the command without a value removes the attribute from the model. If the selection is collapsed
|
|
26
|
+
* inside a text with the highlight attribute, the command will remove the attribute from the entire range
|
|
27
|
+
* of that text.
|
|
28
|
+
*/
|
|
29
|
+
var HighlightCommand = class extends Command {
|
|
30
|
+
/**
|
|
31
|
+
* @inheritDoc
|
|
32
|
+
*/
|
|
33
|
+
refresh() {
|
|
34
|
+
const model = this.editor.model;
|
|
35
|
+
const doc = model.document;
|
|
36
|
+
this.value = doc.selection.getAttribute("highlight");
|
|
37
|
+
this.isEnabled = model.schema.checkAttributeInSelection(doc.selection, "highlight");
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Executes the command.
|
|
41
|
+
*
|
|
42
|
+
* @param options Options for the executed command.
|
|
43
|
+
* @param options.value The value to apply.
|
|
44
|
+
*
|
|
45
|
+
* @fires execute
|
|
46
|
+
*/
|
|
47
|
+
execute(options = {}) {
|
|
48
|
+
const model = this.editor.model;
|
|
49
|
+
const selection = model.document.selection;
|
|
50
|
+
const highlighter = options.value;
|
|
51
|
+
model.change((writer) => {
|
|
52
|
+
if (selection.isCollapsed) {
|
|
53
|
+
const position = selection.getFirstPosition();
|
|
54
|
+
if (selection.hasAttribute("highlight")) {
|
|
55
|
+
const isSameHighlight = (value) => {
|
|
56
|
+
return value.item.hasAttribute("highlight") && value.item.getAttribute("highlight") === this.value;
|
|
57
|
+
};
|
|
58
|
+
const highlightStart = position.getLastMatchingPosition(isSameHighlight, { direction: "backward" });
|
|
59
|
+
const highlightEnd = position.getLastMatchingPosition(isSameHighlight);
|
|
60
|
+
const highlightRange = writer.createRange(highlightStart, highlightEnd);
|
|
61
|
+
if (!highlighter || this.value === highlighter) {
|
|
62
|
+
if (!position.isEqual(highlightEnd)) writer.removeAttribute("highlight", highlightRange);
|
|
63
|
+
writer.removeSelectionAttribute("highlight");
|
|
64
|
+
} else {
|
|
65
|
+
if (!position.isEqual(highlightEnd)) writer.setAttribute("highlight", highlighter, highlightRange);
|
|
66
|
+
writer.setSelectionAttribute("highlight", highlighter);
|
|
67
|
+
}
|
|
68
|
+
} else if (highlighter) writer.setSelectionAttribute("highlight", highlighter);
|
|
69
|
+
} else {
|
|
70
|
+
const ranges = model.schema.getValidRanges(selection.getRanges(), "highlight", { includeEmptyRanges: true });
|
|
71
|
+
for (const range of ranges) {
|
|
72
|
+
let itemOrRange = range;
|
|
73
|
+
let attributeKey = "highlight";
|
|
74
|
+
if (range.isCollapsed) {
|
|
75
|
+
itemOrRange = range.start.parent;
|
|
76
|
+
attributeKey = ModelDocumentSelection._getStoreAttributeKey("highlight");
|
|
77
|
+
}
|
|
78
|
+
if (highlighter) writer.setAttribute(attributeKey, highlighter, itemOrRange);
|
|
79
|
+
else writer.removeAttribute(attributeKey, itemOrRange);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
};
|
|
96
85
|
|
|
97
86
|
/**
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
* on the {@link module:highlight/highlightconfig~HighlightConfig configuration}.
|
|
102
|
-
*/ class HighlightEditing extends Plugin {
|
|
103
|
-
/**
|
|
104
|
-
* @inheritDoc
|
|
105
|
-
*/ static get pluginName() {
|
|
106
|
-
return 'HighlightEditing';
|
|
107
|
-
}
|
|
108
|
-
/**
|
|
109
|
-
* @inheritDoc
|
|
110
|
-
*/ static get isOfficialPlugin() {
|
|
111
|
-
return true;
|
|
112
|
-
}
|
|
113
|
-
/**
|
|
114
|
-
* @inheritDoc
|
|
115
|
-
*/ constructor(editor){
|
|
116
|
-
super(editor);
|
|
117
|
-
editor.config.define('highlight', {
|
|
118
|
-
options: [
|
|
119
|
-
{
|
|
120
|
-
model: 'yellowMarker',
|
|
121
|
-
class: 'marker-yellow',
|
|
122
|
-
title: 'Yellow marker',
|
|
123
|
-
color: 'var(--ck-content-highlight-marker-yellow)',
|
|
124
|
-
type: 'marker'
|
|
125
|
-
},
|
|
126
|
-
{
|
|
127
|
-
model: 'greenMarker',
|
|
128
|
-
class: 'marker-green',
|
|
129
|
-
title: 'Green marker',
|
|
130
|
-
color: 'var(--ck-content-highlight-marker-green)',
|
|
131
|
-
type: 'marker'
|
|
132
|
-
},
|
|
133
|
-
{
|
|
134
|
-
model: 'pinkMarker',
|
|
135
|
-
class: 'marker-pink',
|
|
136
|
-
title: 'Pink marker',
|
|
137
|
-
color: 'var(--ck-content-highlight-marker-pink)',
|
|
138
|
-
type: 'marker'
|
|
139
|
-
},
|
|
140
|
-
{
|
|
141
|
-
model: 'blueMarker',
|
|
142
|
-
class: 'marker-blue',
|
|
143
|
-
title: 'Blue marker',
|
|
144
|
-
color: 'var(--ck-content-highlight-marker-blue)',
|
|
145
|
-
type: 'marker'
|
|
146
|
-
},
|
|
147
|
-
{
|
|
148
|
-
model: 'redPen',
|
|
149
|
-
class: 'pen-red',
|
|
150
|
-
title: 'Red pen',
|
|
151
|
-
color: 'var(--ck-content-highlight-pen-red)',
|
|
152
|
-
type: 'pen'
|
|
153
|
-
},
|
|
154
|
-
{
|
|
155
|
-
model: 'greenPen',
|
|
156
|
-
class: 'pen-green',
|
|
157
|
-
title: 'Green pen',
|
|
158
|
-
color: 'var(--ck-content-highlight-pen-green)',
|
|
159
|
-
type: 'pen'
|
|
160
|
-
}
|
|
161
|
-
]
|
|
162
|
-
});
|
|
163
|
-
}
|
|
164
|
-
/**
|
|
165
|
-
* @inheritDoc
|
|
166
|
-
*/ init() {
|
|
167
|
-
const editor = this.editor;
|
|
168
|
-
// Allow highlight attribute on text nodes.
|
|
169
|
-
editor.model.schema.extend('$text', {
|
|
170
|
-
allowAttributes: 'highlight'
|
|
171
|
-
});
|
|
172
|
-
const options = editor.config.get('highlight.options');
|
|
173
|
-
// Set-up the two-way conversion.
|
|
174
|
-
editor.conversion.attributeToElement(_buildDefinition(options));
|
|
175
|
-
editor.commands.add('highlight', new HighlightCommand(editor));
|
|
176
|
-
}
|
|
177
|
-
}
|
|
87
|
+
* @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
|
|
88
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
|
|
89
|
+
*/
|
|
178
90
|
/**
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
91
|
+
* @module highlight/highlightediting
|
|
92
|
+
*/
|
|
93
|
+
/**
|
|
94
|
+
* The highlight editing feature. It introduces the {@link module:highlight/highlightcommand~HighlightCommand command} and the `highlight`
|
|
95
|
+
* attribute in the {@link module:engine/model/model~Model model} which renders in the {@link module:engine/view/view view}
|
|
96
|
+
* as a `<mark>` element with a `class` attribute (`<mark class="marker-green">...</mark>`) depending
|
|
97
|
+
* on the {@link module:highlight/highlightconfig~HighlightConfig configuration}.
|
|
98
|
+
*/
|
|
99
|
+
var HighlightEditing = class extends Plugin {
|
|
100
|
+
/**
|
|
101
|
+
* @inheritDoc
|
|
102
|
+
*/
|
|
103
|
+
static get pluginName() {
|
|
104
|
+
return "HighlightEditing";
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* @inheritDoc
|
|
108
|
+
*/
|
|
109
|
+
static get isOfficialPlugin() {
|
|
110
|
+
return true;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* @inheritDoc
|
|
114
|
+
*/
|
|
115
|
+
constructor(editor) {
|
|
116
|
+
super(editor);
|
|
117
|
+
editor.config.define("highlight", { options: [
|
|
118
|
+
{
|
|
119
|
+
model: "yellowMarker",
|
|
120
|
+
class: "marker-yellow",
|
|
121
|
+
title: "Yellow marker",
|
|
122
|
+
color: "var(--ck-content-highlight-marker-yellow)",
|
|
123
|
+
type: "marker"
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
model: "greenMarker",
|
|
127
|
+
class: "marker-green",
|
|
128
|
+
title: "Green marker",
|
|
129
|
+
color: "var(--ck-content-highlight-marker-green)",
|
|
130
|
+
type: "marker"
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
model: "pinkMarker",
|
|
134
|
+
class: "marker-pink",
|
|
135
|
+
title: "Pink marker",
|
|
136
|
+
color: "var(--ck-content-highlight-marker-pink)",
|
|
137
|
+
type: "marker"
|
|
138
|
+
},
|
|
139
|
+
{
|
|
140
|
+
model: "blueMarker",
|
|
141
|
+
class: "marker-blue",
|
|
142
|
+
title: "Blue marker",
|
|
143
|
+
color: "var(--ck-content-highlight-marker-blue)",
|
|
144
|
+
type: "marker"
|
|
145
|
+
},
|
|
146
|
+
{
|
|
147
|
+
model: "redPen",
|
|
148
|
+
class: "pen-red",
|
|
149
|
+
title: "Red pen",
|
|
150
|
+
color: "var(--ck-content-highlight-pen-red)",
|
|
151
|
+
type: "pen"
|
|
152
|
+
},
|
|
153
|
+
{
|
|
154
|
+
model: "greenPen",
|
|
155
|
+
class: "pen-green",
|
|
156
|
+
title: "Green pen",
|
|
157
|
+
color: "var(--ck-content-highlight-pen-green)",
|
|
158
|
+
type: "pen"
|
|
159
|
+
}
|
|
160
|
+
] });
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* @inheritDoc
|
|
164
|
+
*/
|
|
165
|
+
init() {
|
|
166
|
+
const editor = this.editor;
|
|
167
|
+
editor.model.schema.extend("$text", { allowAttributes: "highlight" });
|
|
168
|
+
const options = editor.config.get("highlight.options");
|
|
169
|
+
editor.conversion.attributeToElement(_buildDefinition(options));
|
|
170
|
+
editor.commands.add("highlight", new HighlightCommand(editor));
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
/**
|
|
174
|
+
* Converts the options array to a converter definition.
|
|
175
|
+
*
|
|
176
|
+
* @param options An array with configured options.
|
|
177
|
+
*/
|
|
178
|
+
function _buildDefinition(options) {
|
|
179
|
+
const definition = {
|
|
180
|
+
model: {
|
|
181
|
+
key: "highlight",
|
|
182
|
+
values: []
|
|
183
|
+
},
|
|
184
|
+
view: {}
|
|
185
|
+
};
|
|
186
|
+
for (const option of options) {
|
|
187
|
+
definition.model.values.push(option.model);
|
|
188
|
+
definition.view[option.model] = {
|
|
189
|
+
name: "mark",
|
|
190
|
+
classes: option.class
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
return definition;
|
|
198
194
|
}
|
|
199
195
|
|
|
200
196
|
/**
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
* * The `'removeHighlight'` and `'highlight:*'` buttons.
|
|
205
|
-
*
|
|
206
|
-
* The default configuration includes the following buttons:
|
|
207
|
-
*
|
|
208
|
-
* * `'highlight:yellowMarker'`
|
|
209
|
-
* * `'highlight:greenMarker'`
|
|
210
|
-
* * `'highlight:pinkMarker'`
|
|
211
|
-
* * `'highlight:blueMarker'`
|
|
212
|
-
* * `'highlight:redPen'`
|
|
213
|
-
* * `'highlight:greenPen'`
|
|
214
|
-
*
|
|
215
|
-
* See the {@link module:highlight/highlightconfig~HighlightConfig#options configuration} to learn more
|
|
216
|
-
* about the defaults.
|
|
217
|
-
*/ class HighlightUI extends Plugin {
|
|
218
|
-
/**
|
|
219
|
-
* Returns the localized option titles provided by the plugin.
|
|
220
|
-
*
|
|
221
|
-
* The following localized titles corresponding with default
|
|
222
|
-
* {@link module:highlight/highlightconfig~HighlightConfig#options} are available:
|
|
223
|
-
*
|
|
224
|
-
* * `'Yellow marker'`,
|
|
225
|
-
* * `'Green marker'`,
|
|
226
|
-
* * `'Pink marker'`,
|
|
227
|
-
* * `'Blue marker'`,
|
|
228
|
-
* * `'Red pen'`,
|
|
229
|
-
* * `'Green pen'`.
|
|
230
|
-
*/ get localizedOptionTitles() {
|
|
231
|
-
const t = this.editor.t;
|
|
232
|
-
return {
|
|
233
|
-
'Yellow marker': t('Yellow marker'),
|
|
234
|
-
'Green marker': t('Green marker'),
|
|
235
|
-
'Pink marker': t('Pink marker'),
|
|
236
|
-
'Blue marker': t('Blue marker'),
|
|
237
|
-
'Red pen': t('Red pen'),
|
|
238
|
-
'Green pen': t('Green pen')
|
|
239
|
-
};
|
|
240
|
-
}
|
|
241
|
-
/**
|
|
242
|
-
* @inheritDoc
|
|
243
|
-
*/ static get pluginName() {
|
|
244
|
-
return 'HighlightUI';
|
|
245
|
-
}
|
|
246
|
-
/**
|
|
247
|
-
* @inheritDoc
|
|
248
|
-
*/ static get isOfficialPlugin() {
|
|
249
|
-
return true;
|
|
250
|
-
}
|
|
251
|
-
/**
|
|
252
|
-
* @inheritDoc
|
|
253
|
-
*/ init() {
|
|
254
|
-
const options = this.editor.config.get('highlight.options');
|
|
255
|
-
for (const option of options){
|
|
256
|
-
this._addHighlighterButton(option);
|
|
257
|
-
}
|
|
258
|
-
this._addRemoveHighlightButton();
|
|
259
|
-
this._addDropdown(options);
|
|
260
|
-
this._addMenuBarButton(options);
|
|
261
|
-
}
|
|
262
|
-
/**
|
|
263
|
-
* Creates the "Remove highlight" button.
|
|
264
|
-
*/ _addRemoveHighlightButton() {
|
|
265
|
-
const t = this.editor.t;
|
|
266
|
-
const command = this.editor.commands.get('highlight');
|
|
267
|
-
this._addButton('removeHighlight', t('Remove highlight'), IconEraser, null, (button)=>{
|
|
268
|
-
button.bind('isEnabled').to(command, 'isEnabled');
|
|
269
|
-
});
|
|
270
|
-
}
|
|
271
|
-
/**
|
|
272
|
-
* Creates a toolbar button from the provided highlight option.
|
|
273
|
-
*/ _addHighlighterButton(option) {
|
|
274
|
-
const command = this.editor.commands.get('highlight');
|
|
275
|
-
// TODO: change naming
|
|
276
|
-
this._addButton('highlight:' + option.model, option.title, getIconForType(option.type), option.model, decorateHighlightButton);
|
|
277
|
-
function decorateHighlightButton(button) {
|
|
278
|
-
button.bind('isEnabled').to(command, 'isEnabled');
|
|
279
|
-
button.bind('isOn').to(command, 'value', (value)=>value === option.model);
|
|
280
|
-
button.iconView.fillColor = option.color;
|
|
281
|
-
button.isToggleable = true;
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
/**
|
|
285
|
-
* Internal method for creating highlight buttons.
|
|
286
|
-
*
|
|
287
|
-
* @param name The name of the button.
|
|
288
|
-
* @param label The label for the button.
|
|
289
|
-
* @param icon The button icon.
|
|
290
|
-
* @param value The `value` property passed to the executed command.
|
|
291
|
-
* @param decorateButton A callback getting ButtonView instance so that it can be further customized.
|
|
292
|
-
*/ _addButton(name, label, icon, value, decorateButton) {
|
|
293
|
-
const editor = this.editor;
|
|
294
|
-
editor.ui.componentFactory.add(name, (locale)=>{
|
|
295
|
-
const buttonView = new ButtonView(locale);
|
|
296
|
-
const localized = this.localizedOptionTitles[label] ? this.localizedOptionTitles[label] : label;
|
|
297
|
-
buttonView.set({
|
|
298
|
-
label: localized,
|
|
299
|
-
icon,
|
|
300
|
-
tooltip: true
|
|
301
|
-
});
|
|
302
|
-
buttonView.on('execute', ()=>{
|
|
303
|
-
editor.execute('highlight', {
|
|
304
|
-
value
|
|
305
|
-
});
|
|
306
|
-
editor.editing.view.focus();
|
|
307
|
-
});
|
|
308
|
-
// Add additional behavior for buttonView.
|
|
309
|
-
decorateButton(buttonView);
|
|
310
|
-
return buttonView;
|
|
311
|
-
});
|
|
312
|
-
}
|
|
313
|
-
/**
|
|
314
|
-
* Creates the split button dropdown UI from the provided highlight options.
|
|
315
|
-
*/ _addDropdown(options) {
|
|
316
|
-
const editor = this.editor;
|
|
317
|
-
const t = editor.t;
|
|
318
|
-
const componentFactory = editor.ui.componentFactory;
|
|
319
|
-
const startingHighlighter = options[0];
|
|
320
|
-
const optionsMap = options.reduce((retVal, option)=>{
|
|
321
|
-
retVal[option.model] = option;
|
|
322
|
-
return retVal;
|
|
323
|
-
}, {});
|
|
324
|
-
componentFactory.add('highlight', (locale)=>{
|
|
325
|
-
const command = editor.commands.get('highlight');
|
|
326
|
-
const dropdownView = createDropdown(locale, SplitButtonView);
|
|
327
|
-
const splitButtonView = dropdownView.buttonView;
|
|
328
|
-
splitButtonView.set({
|
|
329
|
-
label: t('Highlight'),
|
|
330
|
-
tooltip: true,
|
|
331
|
-
// Holds last executed highlighter.
|
|
332
|
-
lastExecuted: startingHighlighter.model,
|
|
333
|
-
// Holds current highlighter to execute (might be different then last used).
|
|
334
|
-
commandValue: startingHighlighter.model,
|
|
335
|
-
isToggleable: true
|
|
336
|
-
});
|
|
337
|
-
// Dropdown button changes to selection (command.value):
|
|
338
|
-
// - If selection is in highlight it get active highlight appearance (icon, color) and is activated.
|
|
339
|
-
// - Otherwise it gets appearance (icon, color) of last executed highlight.
|
|
340
|
-
splitButtonView.bind('icon').to(command, 'value', (value)=>getIconForType(getActiveOption(value, 'type')));
|
|
341
|
-
splitButtonView.bind('color').to(command, 'value', (value)=>getActiveOption(value, 'color'));
|
|
342
|
-
splitButtonView.bind('commandValue').to(command, 'value', (value)=>getActiveOption(value, 'model'));
|
|
343
|
-
splitButtonView.bind('isOn').to(command, 'value', (value)=>!!value);
|
|
344
|
-
splitButtonView.delegate('execute').to(dropdownView);
|
|
345
|
-
// Create buttons array.
|
|
346
|
-
const buttonsCreator = ()=>{
|
|
347
|
-
const buttons = options.map((option)=>{
|
|
348
|
-
// Get existing highlighter button.
|
|
349
|
-
const buttonView = componentFactory.create('highlight:' + option.model);
|
|
350
|
-
// Update lastExecutedHighlight on execute.
|
|
351
|
-
this.listenTo(buttonView, 'execute', ()=>{
|
|
352
|
-
dropdownView.buttonView.set({
|
|
353
|
-
lastExecuted: option.model
|
|
354
|
-
});
|
|
355
|
-
});
|
|
356
|
-
return buttonView;
|
|
357
|
-
});
|
|
358
|
-
// Add separator and eraser buttons to dropdown.
|
|
359
|
-
buttons.push(new ToolbarSeparatorView());
|
|
360
|
-
buttons.push(componentFactory.create('removeHighlight'));
|
|
361
|
-
return buttons;
|
|
362
|
-
};
|
|
363
|
-
// Make toolbar button enabled when any button in dropdown is enabled before adding separator and eraser.
|
|
364
|
-
dropdownView.bind('isEnabled').to(command, 'isEnabled');
|
|
365
|
-
addToolbarToDropdown(dropdownView, buttonsCreator, {
|
|
366
|
-
enableActiveItemFocusOnDropdownOpen: true,
|
|
367
|
-
ariaLabel: t('Text highlight toolbar')
|
|
368
|
-
});
|
|
369
|
-
bindToolbarIconStyleToActiveColor(dropdownView);
|
|
370
|
-
// Execute current action from dropdown's split button action button.
|
|
371
|
-
splitButtonView.on('execute', ()=>{
|
|
372
|
-
editor.execute('highlight', {
|
|
373
|
-
value: splitButtonView.commandValue
|
|
374
|
-
});
|
|
375
|
-
});
|
|
376
|
-
// Focus the editable after executing the command.
|
|
377
|
-
// It overrides a default behaviour where the focus is moved to the dropdown button.
|
|
378
|
-
// See https://github.com/ckeditor/ckeditor5/issues/12125.
|
|
379
|
-
this.listenTo(dropdownView, 'execute', ()=>{
|
|
380
|
-
editor.editing.view.focus();
|
|
381
|
-
});
|
|
382
|
-
/**
|
|
383
|
-
* Returns active highlighter option depending on current command value.
|
|
384
|
-
* If current is not set or it is the same as last execute this method will return the option key (like icon or color)
|
|
385
|
-
* of last executed highlighter. Otherwise it will return option key for current one.
|
|
386
|
-
*/ function getActiveOption(current, key) {
|
|
387
|
-
const whichHighlighter = !current || current === splitButtonView.lastExecuted ? splitButtonView.lastExecuted : current;
|
|
388
|
-
return optionsMap[whichHighlighter][key];
|
|
389
|
-
}
|
|
390
|
-
return dropdownView;
|
|
391
|
-
});
|
|
392
|
-
}
|
|
393
|
-
/**
|
|
394
|
-
* Creates the menu bar button for highlight including submenu with available options.
|
|
395
|
-
*/ _addMenuBarButton(options) {
|
|
396
|
-
const editor = this.editor;
|
|
397
|
-
const t = editor.t;
|
|
398
|
-
const command = editor.commands.get('highlight');
|
|
399
|
-
editor.ui.componentFactory.add('menuBar:highlight', (locale)=>{
|
|
400
|
-
const menuView = new MenuBarMenuView(locale);
|
|
401
|
-
menuView.buttonView.set({
|
|
402
|
-
label: t('Highlight'),
|
|
403
|
-
icon: getIconForType('marker')
|
|
404
|
-
});
|
|
405
|
-
menuView.bind('isEnabled').to(command);
|
|
406
|
-
menuView.buttonView.iconView.fillColor = 'transparent';
|
|
407
|
-
const listView = new MenuBarMenuListView(locale);
|
|
408
|
-
for (const option of options){
|
|
409
|
-
const listItemView = new MenuBarMenuListItemView(locale, menuView);
|
|
410
|
-
const buttonView = new MenuBarMenuListItemButtonView(locale);
|
|
411
|
-
buttonView.set({
|
|
412
|
-
label: option.title,
|
|
413
|
-
icon: getIconForType(option.type),
|
|
414
|
-
role: 'menuitemradio',
|
|
415
|
-
isToggleable: true
|
|
416
|
-
});
|
|
417
|
-
buttonView.iconView.fillColor = option.color;
|
|
418
|
-
buttonView.delegate('execute').to(menuView);
|
|
419
|
-
buttonView.bind('isOn').to(command, 'value', (value)=>value === option.model);
|
|
420
|
-
buttonView.on('execute', ()=>{
|
|
421
|
-
editor.execute('highlight', {
|
|
422
|
-
value: option.model
|
|
423
|
-
});
|
|
424
|
-
editor.editing.view.focus();
|
|
425
|
-
});
|
|
426
|
-
listItemView.children.add(buttonView);
|
|
427
|
-
listView.items.add(listItemView);
|
|
428
|
-
}
|
|
429
|
-
// Add remove highlight button
|
|
430
|
-
listView.items.add(new ListSeparatorView(locale));
|
|
431
|
-
const listItemView = new MenuBarMenuListItemView(locale, menuView);
|
|
432
|
-
const buttonView = new MenuBarMenuListItemButtonView(locale);
|
|
433
|
-
buttonView.set({
|
|
434
|
-
label: t('Remove highlight'),
|
|
435
|
-
icon: IconEraser
|
|
436
|
-
});
|
|
437
|
-
buttonView.delegate('execute').to(menuView);
|
|
438
|
-
buttonView.on('execute', ()=>{
|
|
439
|
-
editor.execute('highlight', {
|
|
440
|
-
value: null
|
|
441
|
-
});
|
|
442
|
-
editor.editing.view.focus();
|
|
443
|
-
});
|
|
444
|
-
listItemView.children.add(buttonView);
|
|
445
|
-
listView.items.add(listItemView);
|
|
446
|
-
menuView.panelView.children.add(listView);
|
|
447
|
-
return menuView;
|
|
448
|
-
});
|
|
449
|
-
}
|
|
450
|
-
}
|
|
197
|
+
* @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
|
|
198
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
|
|
199
|
+
*/
|
|
451
200
|
/**
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
201
|
+
* @module highlight/highlightui
|
|
202
|
+
*/
|
|
203
|
+
/**
|
|
204
|
+
* The default highlight UI plugin. It introduces:
|
|
205
|
+
*
|
|
206
|
+
* * The `'highlight'` dropdown,
|
|
207
|
+
* * The `'removeHighlight'` and `'highlight:*'` buttons.
|
|
208
|
+
*
|
|
209
|
+
* The default configuration includes the following buttons:
|
|
210
|
+
*
|
|
211
|
+
* * `'highlight:yellowMarker'`
|
|
212
|
+
* * `'highlight:greenMarker'`
|
|
213
|
+
* * `'highlight:pinkMarker'`
|
|
214
|
+
* * `'highlight:blueMarker'`
|
|
215
|
+
* * `'highlight:redPen'`
|
|
216
|
+
* * `'highlight:greenPen'`
|
|
217
|
+
*
|
|
218
|
+
* See the {@link module:highlight/highlightconfig~HighlightConfig#options configuration} to learn more
|
|
219
|
+
* about the defaults.
|
|
220
|
+
*/
|
|
221
|
+
var HighlightUI = class extends Plugin {
|
|
222
|
+
/**
|
|
223
|
+
* Returns the localized option titles provided by the plugin.
|
|
224
|
+
*
|
|
225
|
+
* The following localized titles corresponding with default
|
|
226
|
+
* {@link module:highlight/highlightconfig~HighlightConfig#options} are available:
|
|
227
|
+
*
|
|
228
|
+
* * `'Yellow marker'`,
|
|
229
|
+
* * `'Green marker'`,
|
|
230
|
+
* * `'Pink marker'`,
|
|
231
|
+
* * `'Blue marker'`,
|
|
232
|
+
* * `'Red pen'`,
|
|
233
|
+
* * `'Green pen'`.
|
|
234
|
+
*/
|
|
235
|
+
get localizedOptionTitles() {
|
|
236
|
+
const t = this.editor.t;
|
|
237
|
+
return {
|
|
238
|
+
"Yellow marker": t("Yellow marker"),
|
|
239
|
+
"Green marker": t("Green marker"),
|
|
240
|
+
"Pink marker": t("Pink marker"),
|
|
241
|
+
"Blue marker": t("Blue marker"),
|
|
242
|
+
"Red pen": t("Red pen"),
|
|
243
|
+
"Green pen": t("Green pen")
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* @inheritDoc
|
|
248
|
+
*/
|
|
249
|
+
static get pluginName() {
|
|
250
|
+
return "HighlightUI";
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* @inheritDoc
|
|
254
|
+
*/
|
|
255
|
+
static get isOfficialPlugin() {
|
|
256
|
+
return true;
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* @inheritDoc
|
|
260
|
+
*/
|
|
261
|
+
init() {
|
|
262
|
+
const options = this.editor.config.get("highlight.options");
|
|
263
|
+
for (const option of options) this._addHighlighterButton(option);
|
|
264
|
+
this._addRemoveHighlightButton();
|
|
265
|
+
this._addDropdown(options);
|
|
266
|
+
this._addMenuBarButton(options);
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* Creates the "Remove highlight" button.
|
|
270
|
+
*/
|
|
271
|
+
_addRemoveHighlightButton() {
|
|
272
|
+
const t = this.editor.t;
|
|
273
|
+
const command = this.editor.commands.get("highlight");
|
|
274
|
+
this._addButton("removeHighlight", t("Remove highlight"), IconEraser, null, (button) => {
|
|
275
|
+
button.bind("isEnabled").to(command, "isEnabled");
|
|
276
|
+
});
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* Creates a toolbar button from the provided highlight option.
|
|
280
|
+
*/
|
|
281
|
+
_addHighlighterButton(option) {
|
|
282
|
+
const command = this.editor.commands.get("highlight");
|
|
283
|
+
this._addButton("highlight:" + option.model, option.title, getIconForType(option.type), option.model, decorateHighlightButton);
|
|
284
|
+
function decorateHighlightButton(button) {
|
|
285
|
+
button.bind("isEnabled").to(command, "isEnabled");
|
|
286
|
+
button.bind("isOn").to(command, "value", (value) => value === option.model);
|
|
287
|
+
button.iconView.fillColor = option.color;
|
|
288
|
+
button.isToggleable = true;
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
/**
|
|
292
|
+
* Internal method for creating highlight buttons.
|
|
293
|
+
*
|
|
294
|
+
* @param name The name of the button.
|
|
295
|
+
* @param label The label for the button.
|
|
296
|
+
* @param icon The button icon.
|
|
297
|
+
* @param value The `value` property passed to the executed command.
|
|
298
|
+
* @param decorateButton A callback getting ButtonView instance so that it can be further customized.
|
|
299
|
+
*/
|
|
300
|
+
_addButton(name, label, icon, value, decorateButton) {
|
|
301
|
+
const editor = this.editor;
|
|
302
|
+
editor.ui.componentFactory.add(name, (locale) => {
|
|
303
|
+
const buttonView = new ButtonView(locale);
|
|
304
|
+
const localized = this.localizedOptionTitles[label] ? this.localizedOptionTitles[label] : label;
|
|
305
|
+
buttonView.set({
|
|
306
|
+
label: localized,
|
|
307
|
+
icon,
|
|
308
|
+
tooltip: true
|
|
309
|
+
});
|
|
310
|
+
buttonView.on("execute", () => {
|
|
311
|
+
editor.execute("highlight", { value });
|
|
312
|
+
editor.editing.view.focus();
|
|
313
|
+
});
|
|
314
|
+
decorateButton(buttonView);
|
|
315
|
+
return buttonView;
|
|
316
|
+
});
|
|
317
|
+
}
|
|
318
|
+
/**
|
|
319
|
+
* Creates the split button dropdown UI from the provided highlight options.
|
|
320
|
+
*/
|
|
321
|
+
_addDropdown(options) {
|
|
322
|
+
const editor = this.editor;
|
|
323
|
+
const t = editor.t;
|
|
324
|
+
const componentFactory = editor.ui.componentFactory;
|
|
325
|
+
const startingHighlighter = options[0];
|
|
326
|
+
const optionsMap = options.reduce((retVal, option) => {
|
|
327
|
+
retVal[option.model] = option;
|
|
328
|
+
return retVal;
|
|
329
|
+
}, {});
|
|
330
|
+
componentFactory.add("highlight", (locale) => {
|
|
331
|
+
const command = editor.commands.get("highlight");
|
|
332
|
+
const dropdownView = createDropdown(locale, SplitButtonView);
|
|
333
|
+
const splitButtonView = dropdownView.buttonView;
|
|
334
|
+
splitButtonView.set({
|
|
335
|
+
label: t("Highlight"),
|
|
336
|
+
tooltip: true,
|
|
337
|
+
lastExecuted: startingHighlighter.model,
|
|
338
|
+
commandValue: startingHighlighter.model,
|
|
339
|
+
isToggleable: true
|
|
340
|
+
});
|
|
341
|
+
splitButtonView.bind("icon").to(command, "value", (value) => getIconForType(getActiveOption(value, "type")));
|
|
342
|
+
splitButtonView.bind("color").to(command, "value", (value) => getActiveOption(value, "color"));
|
|
343
|
+
splitButtonView.bind("commandValue").to(command, "value", (value) => getActiveOption(value, "model"));
|
|
344
|
+
splitButtonView.bind("isOn").to(command, "value", (value) => !!value);
|
|
345
|
+
splitButtonView.delegate("execute").to(dropdownView);
|
|
346
|
+
const buttonsCreator = () => {
|
|
347
|
+
const buttons = options.map((option) => {
|
|
348
|
+
const buttonView = componentFactory.create("highlight:" + option.model);
|
|
349
|
+
this.listenTo(buttonView, "execute", () => {
|
|
350
|
+
dropdownView.buttonView.set({ lastExecuted: option.model });
|
|
351
|
+
});
|
|
352
|
+
return buttonView;
|
|
353
|
+
});
|
|
354
|
+
buttons.push(new ToolbarSeparatorView());
|
|
355
|
+
buttons.push(componentFactory.create("removeHighlight"));
|
|
356
|
+
return buttons;
|
|
357
|
+
};
|
|
358
|
+
dropdownView.bind("isEnabled").to(command, "isEnabled");
|
|
359
|
+
addToolbarToDropdown(dropdownView, buttonsCreator, {
|
|
360
|
+
enableActiveItemFocusOnDropdownOpen: true,
|
|
361
|
+
ariaLabel: t("Text highlight toolbar")
|
|
362
|
+
});
|
|
363
|
+
bindToolbarIconStyleToActiveColor(dropdownView);
|
|
364
|
+
splitButtonView.on("execute", () => {
|
|
365
|
+
editor.execute("highlight", { value: splitButtonView.commandValue });
|
|
366
|
+
});
|
|
367
|
+
this.listenTo(dropdownView, "execute", () => {
|
|
368
|
+
editor.editing.view.focus();
|
|
369
|
+
});
|
|
370
|
+
/**
|
|
371
|
+
* Returns active highlighter option depending on current command value.
|
|
372
|
+
* If current is not set or it is the same as last execute this method will return the option key (like icon or color)
|
|
373
|
+
* of last executed highlighter. Otherwise it will return option key for current one.
|
|
374
|
+
*/
|
|
375
|
+
function getActiveOption(current, key) {
|
|
376
|
+
return optionsMap[!current || current === splitButtonView.lastExecuted ? splitButtonView.lastExecuted : current][key];
|
|
377
|
+
}
|
|
378
|
+
return dropdownView;
|
|
379
|
+
});
|
|
380
|
+
}
|
|
381
|
+
/**
|
|
382
|
+
* Creates the menu bar button for highlight including submenu with available options.
|
|
383
|
+
*/
|
|
384
|
+
_addMenuBarButton(options) {
|
|
385
|
+
const editor = this.editor;
|
|
386
|
+
const t = editor.t;
|
|
387
|
+
const command = editor.commands.get("highlight");
|
|
388
|
+
editor.ui.componentFactory.add("menuBar:highlight", (locale) => {
|
|
389
|
+
const menuView = new MenuBarMenuView(locale);
|
|
390
|
+
menuView.buttonView.set({
|
|
391
|
+
label: t("Highlight"),
|
|
392
|
+
icon: getIconForType("marker")
|
|
393
|
+
});
|
|
394
|
+
menuView.bind("isEnabled").to(command);
|
|
395
|
+
menuView.buttonView.iconView.fillColor = "transparent";
|
|
396
|
+
const listView = new MenuBarMenuListView(locale);
|
|
397
|
+
for (const option of options) {
|
|
398
|
+
const listItemView = new MenuBarMenuListItemView(locale, menuView);
|
|
399
|
+
const buttonView = new MenuBarMenuListItemButtonView(locale);
|
|
400
|
+
buttonView.set({
|
|
401
|
+
label: option.title,
|
|
402
|
+
icon: getIconForType(option.type),
|
|
403
|
+
role: "menuitemradio",
|
|
404
|
+
isToggleable: true
|
|
405
|
+
});
|
|
406
|
+
buttonView.iconView.fillColor = option.color;
|
|
407
|
+
buttonView.delegate("execute").to(menuView);
|
|
408
|
+
buttonView.bind("isOn").to(command, "value", (value) => value === option.model);
|
|
409
|
+
buttonView.on("execute", () => {
|
|
410
|
+
editor.execute("highlight", { value: option.model });
|
|
411
|
+
editor.editing.view.focus();
|
|
412
|
+
});
|
|
413
|
+
listItemView.children.add(buttonView);
|
|
414
|
+
listView.items.add(listItemView);
|
|
415
|
+
}
|
|
416
|
+
listView.items.add(new ListSeparatorView(locale));
|
|
417
|
+
const listItemView = new MenuBarMenuListItemView(locale, menuView);
|
|
418
|
+
const buttonView = new MenuBarMenuListItemButtonView(locale);
|
|
419
|
+
buttonView.set({
|
|
420
|
+
label: t("Remove highlight"),
|
|
421
|
+
icon: IconEraser
|
|
422
|
+
});
|
|
423
|
+
buttonView.delegate("execute").to(menuView);
|
|
424
|
+
buttonView.on("execute", () => {
|
|
425
|
+
editor.execute("highlight", { value: null });
|
|
426
|
+
editor.editing.view.focus();
|
|
427
|
+
});
|
|
428
|
+
listItemView.children.add(buttonView);
|
|
429
|
+
listView.items.add(listItemView);
|
|
430
|
+
menuView.panelView.children.add(listView);
|
|
431
|
+
return menuView;
|
|
432
|
+
});
|
|
433
|
+
}
|
|
434
|
+
};
|
|
435
|
+
/**
|
|
436
|
+
* Extends split button icon style to reflect last used button style.
|
|
437
|
+
*/
|
|
438
|
+
function bindToolbarIconStyleToActiveColor(dropdownView) {
|
|
439
|
+
dropdownView.buttonView.actionView.iconView.bind("fillColor").to(dropdownView.buttonView, "color");
|
|
456
440
|
}
|
|
457
441
|
/**
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
442
|
+
* Returns icon for given highlighter type.
|
|
443
|
+
*/
|
|
444
|
+
function getIconForType(type) {
|
|
445
|
+
return type === "marker" ? IconMarker : IconPen;
|
|
461
446
|
}
|
|
462
447
|
|
|
463
448
|
/**
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
449
|
+
* @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
|
|
450
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
|
|
451
|
+
*/
|
|
452
|
+
/**
|
|
453
|
+
* @module highlight/highlight
|
|
454
|
+
*/
|
|
455
|
+
/**
|
|
456
|
+
* The highlight plugin.
|
|
457
|
+
*
|
|
458
|
+
* For a detailed overview, check the {@glink features/highlight Highlight feature} documentation.
|
|
459
|
+
*
|
|
460
|
+
* This is a "glue" plugin which loads the {@link module:highlight/highlightediting~HighlightEditing} and
|
|
461
|
+
* {@link module:highlight/highlightui~HighlightUI} plugins.
|
|
462
|
+
*/
|
|
463
|
+
var Highlight = class extends Plugin {
|
|
464
|
+
/**
|
|
465
|
+
* @inheritDoc
|
|
466
|
+
*/
|
|
467
|
+
static get requires() {
|
|
468
|
+
return [HighlightEditing, HighlightUI];
|
|
469
|
+
}
|
|
470
|
+
/**
|
|
471
|
+
* @inheritDoc
|
|
472
|
+
*/
|
|
473
|
+
static get pluginName() {
|
|
474
|
+
return "Highlight";
|
|
475
|
+
}
|
|
476
|
+
/**
|
|
477
|
+
* @inheritDoc
|
|
478
|
+
*/
|
|
479
|
+
static get isOfficialPlugin() {
|
|
480
|
+
return true;
|
|
481
|
+
}
|
|
482
|
+
};
|
|
483
|
+
|
|
484
|
+
/**
|
|
485
|
+
* @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
|
|
486
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
|
|
487
|
+
*/
|
|
490
488
|
|
|
491
489
|
export { Highlight, HighlightCommand, HighlightEditing, HighlightUI };
|
|
492
|
-
//# sourceMappingURL=index.js.map
|
|
490
|
+
//# sourceMappingURL=index.js.map
|