@ckeditor/ckeditor5-highlight 41.3.0 → 41.4.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.
- package/dist/index-content.css +32 -0
- package/dist/index-editor.css +4 -0
- package/dist/index.css +45 -0
- package/dist/index.css.map +1 -0
- package/dist/index.js +429 -0
- package/dist/index.js.map +1 -0
- package/dist/translations/ar.d.ts +8 -0
- package/dist/translations/ar.js +5 -0
- package/dist/translations/az.d.ts +8 -0
- package/dist/translations/az.js +5 -0
- package/dist/translations/bg.d.ts +8 -0
- package/dist/translations/bg.js +5 -0
- package/dist/translations/bn.d.ts +8 -0
- package/dist/translations/bn.js +5 -0
- package/dist/translations/ca.d.ts +8 -0
- package/dist/translations/ca.js +5 -0
- package/dist/translations/cs.d.ts +8 -0
- package/dist/translations/cs.js +5 -0
- package/dist/translations/da.d.ts +8 -0
- package/dist/translations/da.js +5 -0
- package/dist/translations/de-ch.d.ts +8 -0
- package/dist/translations/de-ch.js +5 -0
- package/dist/translations/de.d.ts +8 -0
- package/dist/translations/de.js +5 -0
- package/dist/translations/el.d.ts +8 -0
- package/dist/translations/el.js +5 -0
- package/dist/translations/en-au.d.ts +8 -0
- package/dist/translations/en-au.js +5 -0
- package/dist/translations/en-gb.d.ts +8 -0
- package/dist/translations/en-gb.js +5 -0
- package/dist/translations/en.d.ts +8 -0
- package/dist/translations/en.js +5 -0
- package/dist/translations/es-co.d.ts +8 -0
- package/dist/translations/es-co.js +5 -0
- package/dist/translations/es.d.ts +8 -0
- package/dist/translations/es.js +5 -0
- package/dist/translations/et.d.ts +8 -0
- package/dist/translations/et.js +5 -0
- package/dist/translations/fa.d.ts +8 -0
- package/dist/translations/fa.js +5 -0
- package/dist/translations/fi.d.ts +8 -0
- package/dist/translations/fi.js +5 -0
- package/dist/translations/fr.d.ts +8 -0
- package/dist/translations/fr.js +5 -0
- package/dist/translations/gl.d.ts +8 -0
- package/dist/translations/gl.js +5 -0
- package/dist/translations/he.d.ts +8 -0
- package/dist/translations/he.js +5 -0
- package/dist/translations/hi.d.ts +8 -0
- package/dist/translations/hi.js +5 -0
- package/dist/translations/hr.d.ts +8 -0
- package/dist/translations/hr.js +5 -0
- package/dist/translations/hu.d.ts +8 -0
- package/dist/translations/hu.js +5 -0
- package/dist/translations/id.d.ts +8 -0
- package/dist/translations/id.js +5 -0
- package/dist/translations/it.d.ts +8 -0
- package/dist/translations/it.js +5 -0
- package/dist/translations/ja.d.ts +8 -0
- package/dist/translations/ja.js +5 -0
- package/dist/translations/jv.d.ts +8 -0
- package/dist/translations/jv.js +5 -0
- package/dist/translations/ko.d.ts +8 -0
- package/dist/translations/ko.js +5 -0
- package/dist/translations/ku.d.ts +8 -0
- package/dist/translations/ku.js +5 -0
- package/dist/translations/lt.d.ts +8 -0
- package/dist/translations/lt.js +5 -0
- package/dist/translations/lv.d.ts +8 -0
- package/dist/translations/lv.js +5 -0
- package/dist/translations/ms.d.ts +8 -0
- package/dist/translations/ms.js +5 -0
- package/dist/translations/nb.d.ts +8 -0
- package/dist/translations/nb.js +5 -0
- package/dist/translations/ne.d.ts +8 -0
- package/dist/translations/ne.js +5 -0
- package/dist/translations/nl.d.ts +8 -0
- package/dist/translations/nl.js +5 -0
- package/dist/translations/no.d.ts +8 -0
- package/dist/translations/no.js +5 -0
- package/dist/translations/pl.d.ts +8 -0
- package/dist/translations/pl.js +5 -0
- package/dist/translations/pt-br.d.ts +8 -0
- package/dist/translations/pt-br.js +5 -0
- package/dist/translations/pt.d.ts +8 -0
- package/dist/translations/pt.js +5 -0
- package/dist/translations/ro.d.ts +8 -0
- package/dist/translations/ro.js +5 -0
- package/dist/translations/ru.d.ts +8 -0
- package/dist/translations/ru.js +5 -0
- package/dist/translations/sk.d.ts +8 -0
- package/dist/translations/sk.js +5 -0
- package/dist/translations/sl.d.ts +8 -0
- package/dist/translations/sl.js +5 -0
- package/dist/translations/sq.d.ts +8 -0
- package/dist/translations/sq.js +5 -0
- package/dist/translations/sr-latn.d.ts +8 -0
- package/dist/translations/sr-latn.js +5 -0
- package/dist/translations/sr.d.ts +8 -0
- package/dist/translations/sr.js +5 -0
- package/dist/translations/sv.d.ts +8 -0
- package/dist/translations/sv.js +5 -0
- package/dist/translations/th.d.ts +8 -0
- package/dist/translations/th.js +5 -0
- package/dist/translations/tk.d.ts +8 -0
- package/dist/translations/tk.js +5 -0
- package/dist/translations/tr.d.ts +8 -0
- package/dist/translations/tr.js +5 -0
- package/dist/translations/uk.d.ts +8 -0
- package/dist/translations/uk.js +5 -0
- package/dist/translations/ur.d.ts +8 -0
- package/dist/translations/ur.js +5 -0
- package/dist/translations/uz.d.ts +8 -0
- package/dist/translations/uz.js +5 -0
- package/dist/translations/vi.d.ts +8 -0
- package/dist/translations/vi.js +5 -0
- package/dist/translations/zh-cn.d.ts +8 -0
- package/dist/translations/zh-cn.js +5 -0
- package/dist/translations/zh.d.ts +8 -0
- package/dist/translations/zh.js +5 -0
- package/dist/types/augmentation.d.ts +27 -0
- package/dist/types/highlight.d.ts +32 -0
- package/dist/types/highlightcommand.d.ts +49 -0
- package/dist/types/highlightconfig.d.ts +175 -0
- package/dist/types/highlightediting.d.ts +32 -0
- package/dist/types/highlightui.d.ts +81 -0
- package/dist/types/index.d.ts +17 -0
- package/package.json +3 -2
@@ -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
|
+
:root {
|
6
|
+
--ck-highlight-marker-yellow: hsl(60, 97%, 73%);
|
7
|
+
--ck-highlight-marker-green: hsl(120, 93%, 68%);
|
8
|
+
--ck-highlight-marker-pink: hsl(345, 96%, 73%);
|
9
|
+
--ck-highlight-marker-blue: hsl(201, 97%, 72%);
|
10
|
+
--ck-highlight-pen-red: hsl(0, 85%, 49%);
|
11
|
+
--ck-highlight-pen-green: hsl(112, 100%, 27%);
|
12
|
+
}
|
13
|
+
.ck-content .marker-yellow {
|
14
|
+
background-color: var(--ck-highlight-marker-yellow);
|
15
|
+
}
|
16
|
+
.ck-content .marker-green {
|
17
|
+
background-color: var(--ck-highlight-marker-green);
|
18
|
+
}
|
19
|
+
.ck-content .marker-pink {
|
20
|
+
background-color: var(--ck-highlight-marker-pink);
|
21
|
+
}
|
22
|
+
.ck-content .marker-blue {
|
23
|
+
background-color: var(--ck-highlight-marker-blue);
|
24
|
+
}
|
25
|
+
.ck-content .pen-red {
|
26
|
+
color: var(--ck-highlight-pen-red);
|
27
|
+
background-color: transparent;
|
28
|
+
}
|
29
|
+
.ck-content .pen-green {
|
30
|
+
color: var(--ck-highlight-pen-green);
|
31
|
+
background-color: transparent;
|
32
|
+
}
|
package/dist/index.css
ADDED
@@ -0,0 +1,45 @@
|
|
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
|
+
* Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
|
7
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
8
|
+
*/
|
9
|
+
|
10
|
+
:root {
|
11
|
+
--ck-highlight-marker-yellow: hsl(60, 97%, 73%);
|
12
|
+
--ck-highlight-marker-green: hsl(120, 93%, 68%);
|
13
|
+
--ck-highlight-marker-pink: hsl(345, 96%, 73%);
|
14
|
+
--ck-highlight-marker-blue: hsl(201, 97%, 72%);
|
15
|
+
--ck-highlight-pen-red: hsl(0, 85%, 49%);
|
16
|
+
--ck-highlight-pen-green: hsl(112, 100%, 27%);
|
17
|
+
}
|
18
|
+
|
19
|
+
.ck-content .marker-yellow {
|
20
|
+
background-color: var(--ck-highlight-marker-yellow);
|
21
|
+
}
|
22
|
+
.ck-content .marker-green {
|
23
|
+
background-color: var(--ck-highlight-marker-green);
|
24
|
+
}
|
25
|
+
.ck-content .marker-pink {
|
26
|
+
background-color: var(--ck-highlight-marker-pink);
|
27
|
+
}
|
28
|
+
.ck-content .marker-blue {
|
29
|
+
background-color: var(--ck-highlight-marker-blue);
|
30
|
+
}
|
31
|
+
|
32
|
+
.ck-content .pen-red {
|
33
|
+
color: var(--ck-highlight-pen-red);
|
34
|
+
|
35
|
+
/* Override default yellow background of `<mark>` from user agent stylesheet */
|
36
|
+
background-color: transparent;
|
37
|
+
}
|
38
|
+
.ck-content .pen-green {
|
39
|
+
color: var(--ck-highlight-pen-green);
|
40
|
+
|
41
|
+
/* Override default yellow background of `<mark>` from user agent stylesheet */
|
42
|
+
background-color: transparent;
|
43
|
+
}
|
44
|
+
|
45
|
+
/*# sourceMappingURL=index.css.map */
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../theme/highlight.css","index.css"],"names":[],"mappings":";;;;AAAA,CAAA,CAAA;ACCA,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC;AAC5E,CAAC,CAAC,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,OAAO;AACnF,CAAC,CDAC,CAAA;ACCF;ADCA,CAAA,IAAA,CAAA,CAAA;ACCA,CDAC,CAAA,CAAA,EAAA,CAAA,SAAA,CAAA,MAAA,CAAA,MAAA,CAAA,CAAA,GAAA,CAAA,EAAA,CAAA,CAAA,EAAA,CAAA,CAAA,CAAA,EAAA,CAAA,CAA+C,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A,IAAA,CAAA,CAAA,CAAA,IAAA,CAAA,IAAA,CAAA,KAAA,CAAA,UAAA,CAAA,CAA8E,CAAA;ACahF,CAAC,CDZC,UAAA,CAAA,KAAA,CAAA,CAAA,WAA6B,CAAA;ACa/B,CDZC,CAAA;ACaD;AACA,CAAC,CAAC,CAAC,CAAC,gBAAgB,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC","file":"index.css.map","sourcesContent":["/*\n * Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.\n * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license\n */\n\n:root {\n\t--ck-highlight-marker-yellow: hsl(60, 97%, 73%);\n\t--ck-highlight-marker-green: hsl(120, 93%, 68%);\n\t--ck-highlight-marker-pink: hsl(345, 96%, 73%);\n\t--ck-highlight-marker-blue: hsl(201, 97%, 72%);\n\t--ck-highlight-pen-red: hsl(0, 85%, 49%);\n\t--ck-highlight-pen-green: hsl(112, 100%, 27%);\n}\n\n@define-mixin highlight-marker-color $color {\n\t.ck-content .marker-$color {\n\t\tbackground-color: var(--ck-highlight-marker-$color);\n\t}\n}\n\n@define-mixin highlight-pen-color $color {\n\t.ck-content .pen-$color {\n\t\tcolor: var(--ck-highlight-pen-$color);\n\n\t\t/* Override default yellow background of `<mark>` from user agent stylesheet */\n\t\tbackground-color: transparent;\n\t}\n}\n\n@mixin highlight-marker-color yellow;\n@mixin highlight-marker-color green;\n@mixin highlight-marker-color pink;\n@mixin highlight-marker-color blue;\n\n@mixin highlight-pen-color red;\n@mixin highlight-pen-color green;\n","/*\n * Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.\n * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license\n */\n\n:root {\n\t--ck-highlight-marker-yellow: hsl(60, 97%, 73%);\n\t--ck-highlight-marker-green: hsl(120, 93%, 68%);\n\t--ck-highlight-marker-pink: hsl(345, 96%, 73%);\n\t--ck-highlight-marker-blue: hsl(201, 97%, 72%);\n\t--ck-highlight-pen-red: hsl(0, 85%, 49%);\n\t--ck-highlight-pen-green: hsl(112, 100%, 27%);\n}\n\n.ck-content .marker-yellow {\n\t\tbackground-color: var(--ck-highlight-marker-yellow);\n\t}\n.ck-content .marker-green {\n\t\tbackground-color: var(--ck-highlight-marker-green);\n\t}\n.ck-content .marker-pink {\n\t\tbackground-color: var(--ck-highlight-marker-pink);\n\t}\n.ck-content .marker-blue {\n\t\tbackground-color: var(--ck-highlight-marker-blue);\n\t}\n\n.ck-content .pen-red {\n\t\tcolor: var(--ck-highlight-pen-red);\n\n\t\t/* Override default yellow background of `<mark>` from user agent stylesheet */\n\t\tbackground-color: transparent;\n\t}\n.ck-content .pen-green {\n\t\tcolor: var(--ck-highlight-pen-green);\n\n\t\t/* Override default yellow background of `<mark>` from user agent stylesheet */\n\t\tbackground-color: transparent;\n\t}\n\n/*# sourceMappingURL=index.css.map */"]}
|
package/dist/index.js
ADDED
@@ -0,0 +1,429 @@
|
|
1
|
+
/**
|
2
|
+
* @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
4
|
+
*/
|
5
|
+
import { Command, Plugin, icons } from '@ckeditor/ckeditor5-core/dist/index.js';
|
6
|
+
import { ButtonView, createDropdown, SplitButtonView, addToolbarToDropdown, MenuBarMenuView, MenuBarMenuListView, MenuBarMenuListItemView, MenuBarMenuListItemButtonView, ListSeparatorView, ToolbarSeparatorView } from '@ckeditor/ckeditor5-ui/dist/index.js';
|
7
|
+
|
8
|
+
class HighlightCommand extends Command {
|
9
|
+
/**
|
10
|
+
* @inheritDoc
|
11
|
+
*/ refresh() {
|
12
|
+
const model = this.editor.model;
|
13
|
+
const doc = model.document;
|
14
|
+
this.value = doc.selection.getAttribute('highlight');
|
15
|
+
this.isEnabled = model.schema.checkAttributeInSelection(doc.selection, 'highlight');
|
16
|
+
}
|
17
|
+
/**
|
18
|
+
* Executes the command.
|
19
|
+
*
|
20
|
+
* @param options Options for the executed command.
|
21
|
+
* @param options.value The value to apply.
|
22
|
+
*
|
23
|
+
* @fires execute
|
24
|
+
*/ execute(options = {}) {
|
25
|
+
const model = this.editor.model;
|
26
|
+
const document = model.document;
|
27
|
+
const selection = document.selection;
|
28
|
+
const highlighter = options.value;
|
29
|
+
model.change((writer)=>{
|
30
|
+
if (selection.isCollapsed) {
|
31
|
+
const position = selection.getFirstPosition();
|
32
|
+
// When selection is inside text with `highlight` attribute.
|
33
|
+
if (selection.hasAttribute('highlight')) {
|
34
|
+
// Find the full highlighted range.
|
35
|
+
const isSameHighlight = (value)=>{
|
36
|
+
return value.item.hasAttribute('highlight') && value.item.getAttribute('highlight') === this.value;
|
37
|
+
};
|
38
|
+
const highlightStart = position.getLastMatchingPosition(isSameHighlight, {
|
39
|
+
direction: 'backward'
|
40
|
+
});
|
41
|
+
const highlightEnd = position.getLastMatchingPosition(isSameHighlight);
|
42
|
+
const highlightRange = writer.createRange(highlightStart, highlightEnd);
|
43
|
+
// Then depending on current value...
|
44
|
+
if (!highlighter || this.value === highlighter) {
|
45
|
+
// ...remove attribute when passing highlighter different then current or executing "eraser".
|
46
|
+
// If we're at the end of the highlighted range, we don't want to remove highlight of the range.
|
47
|
+
if (!position.isEqual(highlightEnd)) {
|
48
|
+
writer.removeAttribute('highlight', highlightRange);
|
49
|
+
}
|
50
|
+
writer.removeSelectionAttribute('highlight');
|
51
|
+
} else {
|
52
|
+
// ...update `highlight` value.
|
53
|
+
// If we're at the end of the highlighted range, we don't want to change the highlight of the range.
|
54
|
+
if (!position.isEqual(highlightEnd)) {
|
55
|
+
writer.setAttribute('highlight', highlighter, highlightRange);
|
56
|
+
}
|
57
|
+
writer.setSelectionAttribute('highlight', highlighter);
|
58
|
+
}
|
59
|
+
} else if (highlighter) {
|
60
|
+
writer.setSelectionAttribute('highlight', highlighter);
|
61
|
+
}
|
62
|
+
} else {
|
63
|
+
const ranges = model.schema.getValidRanges(selection.getRanges(), 'highlight');
|
64
|
+
for (const range of ranges){
|
65
|
+
if (highlighter) {
|
66
|
+
writer.setAttribute('highlight', highlighter, range);
|
67
|
+
} else {
|
68
|
+
writer.removeAttribute('highlight', range);
|
69
|
+
}
|
70
|
+
}
|
71
|
+
}
|
72
|
+
});
|
73
|
+
}
|
74
|
+
}
|
75
|
+
|
76
|
+
class HighlightEditing extends Plugin {
|
77
|
+
/**
|
78
|
+
* @inheritDoc
|
79
|
+
*/ static get pluginName() {
|
80
|
+
return 'HighlightEditing';
|
81
|
+
}
|
82
|
+
/**
|
83
|
+
* @inheritDoc
|
84
|
+
*/ init() {
|
85
|
+
const editor = this.editor;
|
86
|
+
// Allow highlight attribute on text nodes.
|
87
|
+
editor.model.schema.extend('$text', {
|
88
|
+
allowAttributes: 'highlight'
|
89
|
+
});
|
90
|
+
const options = editor.config.get('highlight.options');
|
91
|
+
// Set-up the two-way conversion.
|
92
|
+
editor.conversion.attributeToElement(_buildDefinition(options));
|
93
|
+
editor.commands.add('highlight', new HighlightCommand(editor));
|
94
|
+
}
|
95
|
+
/**
|
96
|
+
* @inheritDoc
|
97
|
+
*/ constructor(editor){
|
98
|
+
super(editor);
|
99
|
+
editor.config.define('highlight', {
|
100
|
+
options: [
|
101
|
+
{
|
102
|
+
model: 'yellowMarker',
|
103
|
+
class: 'marker-yellow',
|
104
|
+
title: 'Yellow marker',
|
105
|
+
color: 'var(--ck-highlight-marker-yellow)',
|
106
|
+
type: 'marker'
|
107
|
+
},
|
108
|
+
{
|
109
|
+
model: 'greenMarker',
|
110
|
+
class: 'marker-green',
|
111
|
+
title: 'Green marker',
|
112
|
+
color: 'var(--ck-highlight-marker-green)',
|
113
|
+
type: 'marker'
|
114
|
+
},
|
115
|
+
{
|
116
|
+
model: 'pinkMarker',
|
117
|
+
class: 'marker-pink',
|
118
|
+
title: 'Pink marker',
|
119
|
+
color: 'var(--ck-highlight-marker-pink)',
|
120
|
+
type: 'marker'
|
121
|
+
},
|
122
|
+
{
|
123
|
+
model: 'blueMarker',
|
124
|
+
class: 'marker-blue',
|
125
|
+
title: 'Blue marker',
|
126
|
+
color: 'var(--ck-highlight-marker-blue)',
|
127
|
+
type: 'marker'
|
128
|
+
},
|
129
|
+
{
|
130
|
+
model: 'redPen',
|
131
|
+
class: 'pen-red',
|
132
|
+
title: 'Red pen',
|
133
|
+
color: 'var(--ck-highlight-pen-red)',
|
134
|
+
type: 'pen'
|
135
|
+
},
|
136
|
+
{
|
137
|
+
model: 'greenPen',
|
138
|
+
class: 'pen-green',
|
139
|
+
title: 'Green pen',
|
140
|
+
color: 'var(--ck-highlight-pen-green)',
|
141
|
+
type: 'pen'
|
142
|
+
}
|
143
|
+
]
|
144
|
+
});
|
145
|
+
}
|
146
|
+
}
|
147
|
+
/**
|
148
|
+
* Converts the options array to a converter definition.
|
149
|
+
*
|
150
|
+
* @param options An array with configured options.
|
151
|
+
*/ function _buildDefinition(options) {
|
152
|
+
const definition = {
|
153
|
+
model: {
|
154
|
+
key: 'highlight',
|
155
|
+
values: []
|
156
|
+
},
|
157
|
+
view: {}
|
158
|
+
};
|
159
|
+
for (const option of options){
|
160
|
+
definition.model.values.push(option.model);
|
161
|
+
definition.view[option.model] = {
|
162
|
+
name: 'mark',
|
163
|
+
classes: option.class
|
164
|
+
};
|
165
|
+
}
|
166
|
+
return definition;
|
167
|
+
}
|
168
|
+
|
169
|
+
var markerIcon = "<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>";
|
170
|
+
|
171
|
+
var penIcon = "<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>";
|
172
|
+
|
173
|
+
class HighlightUI extends Plugin {
|
174
|
+
/**
|
175
|
+
* Returns the localized option titles provided by the plugin.
|
176
|
+
*
|
177
|
+
* The following localized titles corresponding with default
|
178
|
+
* {@link module:highlight/highlightconfig~HighlightConfig#options} are available:
|
179
|
+
*
|
180
|
+
* * `'Yellow marker'`,
|
181
|
+
* * `'Green marker'`,
|
182
|
+
* * `'Pink marker'`,
|
183
|
+
* * `'Blue marker'`,
|
184
|
+
* * `'Red pen'`,
|
185
|
+
* * `'Green pen'`.
|
186
|
+
*/ get localizedOptionTitles() {
|
187
|
+
const t = this.editor.t;
|
188
|
+
return {
|
189
|
+
'Yellow marker': t('Yellow marker'),
|
190
|
+
'Green marker': t('Green marker'),
|
191
|
+
'Pink marker': t('Pink marker'),
|
192
|
+
'Blue marker': t('Blue marker'),
|
193
|
+
'Red pen': t('Red pen'),
|
194
|
+
'Green pen': t('Green pen')
|
195
|
+
};
|
196
|
+
}
|
197
|
+
/**
|
198
|
+
* @inheritDoc
|
199
|
+
*/ static get pluginName() {
|
200
|
+
return 'HighlightUI';
|
201
|
+
}
|
202
|
+
/**
|
203
|
+
* @inheritDoc
|
204
|
+
*/ init() {
|
205
|
+
const options = this.editor.config.get('highlight.options');
|
206
|
+
for (const option of options){
|
207
|
+
this._addHighlighterButton(option);
|
208
|
+
}
|
209
|
+
this._addRemoveHighlightButton();
|
210
|
+
this._addDropdown(options);
|
211
|
+
this._addMenuBarButton(options);
|
212
|
+
}
|
213
|
+
/**
|
214
|
+
* Creates the "Remove highlight" button.
|
215
|
+
*/ _addRemoveHighlightButton() {
|
216
|
+
const t = this.editor.t;
|
217
|
+
const command = this.editor.commands.get('highlight');
|
218
|
+
this._addButton('removeHighlight', t('Remove highlight'), icons.eraser, null, (button)=>{
|
219
|
+
button.bind('isEnabled').to(command, 'isEnabled');
|
220
|
+
});
|
221
|
+
}
|
222
|
+
/**
|
223
|
+
* Creates a toolbar button from the provided highlight option.
|
224
|
+
*/ _addHighlighterButton(option) {
|
225
|
+
const command = this.editor.commands.get('highlight');
|
226
|
+
// TODO: change naming
|
227
|
+
this._addButton('highlight:' + option.model, option.title, getIconForType(option.type), option.model, decorateHighlightButton);
|
228
|
+
function decorateHighlightButton(button) {
|
229
|
+
button.bind('isEnabled').to(command, 'isEnabled');
|
230
|
+
button.bind('isOn').to(command, 'value', (value)=>value === option.model);
|
231
|
+
button.iconView.fillColor = option.color;
|
232
|
+
button.isToggleable = true;
|
233
|
+
}
|
234
|
+
}
|
235
|
+
/**
|
236
|
+
* Internal method for creating highlight buttons.
|
237
|
+
*
|
238
|
+
* @param name The name of the button.
|
239
|
+
* @param label The label for the button.
|
240
|
+
* @param icon The button icon.
|
241
|
+
* @param value The `value` property passed to the executed command.
|
242
|
+
* @param decorateButton A callback getting ButtonView instance so that it can be further customized.
|
243
|
+
*/ _addButton(name, label, icon, value, decorateButton) {
|
244
|
+
const editor = this.editor;
|
245
|
+
editor.ui.componentFactory.add(name, (locale)=>{
|
246
|
+
const buttonView = new ButtonView(locale);
|
247
|
+
const localized = this.localizedOptionTitles[label] ? this.localizedOptionTitles[label] : label;
|
248
|
+
buttonView.set({
|
249
|
+
label: localized,
|
250
|
+
icon,
|
251
|
+
tooltip: true
|
252
|
+
});
|
253
|
+
buttonView.on('execute', ()=>{
|
254
|
+
editor.execute('highlight', {
|
255
|
+
value
|
256
|
+
});
|
257
|
+
editor.editing.view.focus();
|
258
|
+
});
|
259
|
+
// Add additional behavior for buttonView.
|
260
|
+
decorateButton(buttonView);
|
261
|
+
return buttonView;
|
262
|
+
});
|
263
|
+
}
|
264
|
+
/**
|
265
|
+
* Creates the split button dropdown UI from the provided highlight options.
|
266
|
+
*/ _addDropdown(options) {
|
267
|
+
const editor = this.editor;
|
268
|
+
const t = editor.t;
|
269
|
+
const componentFactory = editor.ui.componentFactory;
|
270
|
+
const startingHighlighter = options[0];
|
271
|
+
const optionsMap = options.reduce((retVal, option)=>{
|
272
|
+
retVal[option.model] = option;
|
273
|
+
return retVal;
|
274
|
+
}, {});
|
275
|
+
componentFactory.add('highlight', (locale)=>{
|
276
|
+
const command = editor.commands.get('highlight');
|
277
|
+
const dropdownView = createDropdown(locale, SplitButtonView);
|
278
|
+
const splitButtonView = dropdownView.buttonView;
|
279
|
+
splitButtonView.set({
|
280
|
+
label: t('Highlight'),
|
281
|
+
tooltip: true,
|
282
|
+
// Holds last executed highlighter.
|
283
|
+
lastExecuted: startingHighlighter.model,
|
284
|
+
// Holds current highlighter to execute (might be different then last used).
|
285
|
+
commandValue: startingHighlighter.model,
|
286
|
+
isToggleable: true
|
287
|
+
});
|
288
|
+
// Dropdown button changes to selection (command.value):
|
289
|
+
// - If selection is in highlight it get active highlight appearance (icon, color) and is activated.
|
290
|
+
// - Otherwise it gets appearance (icon, color) of last executed highlight.
|
291
|
+
splitButtonView.bind('icon').to(command, 'value', (value)=>getIconForType(getActiveOption(value, 'type')));
|
292
|
+
splitButtonView.bind('color').to(command, 'value', (value)=>getActiveOption(value, 'color'));
|
293
|
+
splitButtonView.bind('commandValue').to(command, 'value', (value)=>getActiveOption(value, 'model'));
|
294
|
+
splitButtonView.bind('isOn').to(command, 'value', (value)=>!!value);
|
295
|
+
splitButtonView.delegate('execute').to(dropdownView);
|
296
|
+
// Create buttons array.
|
297
|
+
const buttonsCreator = ()=>{
|
298
|
+
const buttons = options.map((option)=>{
|
299
|
+
// Get existing highlighter button.
|
300
|
+
const buttonView = componentFactory.create('highlight:' + option.model);
|
301
|
+
// Update lastExecutedHighlight on execute.
|
302
|
+
this.listenTo(buttonView, 'execute', ()=>{
|
303
|
+
dropdownView.buttonView.set({
|
304
|
+
lastExecuted: option.model
|
305
|
+
});
|
306
|
+
});
|
307
|
+
return buttonView;
|
308
|
+
});
|
309
|
+
// Add separator and eraser buttons to dropdown.
|
310
|
+
buttons.push(new ToolbarSeparatorView());
|
311
|
+
buttons.push(componentFactory.create('removeHighlight'));
|
312
|
+
return buttons;
|
313
|
+
};
|
314
|
+
// Make toolbar button enabled when any button in dropdown is enabled before adding separator and eraser.
|
315
|
+
dropdownView.bind('isEnabled').to(command, 'isEnabled');
|
316
|
+
addToolbarToDropdown(dropdownView, buttonsCreator, {
|
317
|
+
enableActiveItemFocusOnDropdownOpen: true,
|
318
|
+
ariaLabel: t('Text highlight toolbar')
|
319
|
+
});
|
320
|
+
bindToolbarIconStyleToActiveColor(dropdownView);
|
321
|
+
// Execute current action from dropdown's split button action button.
|
322
|
+
splitButtonView.on('execute', ()=>{
|
323
|
+
editor.execute('highlight', {
|
324
|
+
value: splitButtonView.commandValue
|
325
|
+
});
|
326
|
+
});
|
327
|
+
// Focus the editable after executing the command.
|
328
|
+
// It overrides a default behaviour where the focus is moved to the dropdown button (#12125).
|
329
|
+
this.listenTo(dropdownView, 'execute', ()=>{
|
330
|
+
editor.editing.view.focus();
|
331
|
+
});
|
332
|
+
/**
|
333
|
+
* Returns active highlighter option depending on current command value.
|
334
|
+
* If current is not set or it is the same as last execute this method will return the option key (like icon or color)
|
335
|
+
* of last executed highlighter. Otherwise it will return option key for current one.
|
336
|
+
*/ function getActiveOption(current, key) {
|
337
|
+
const whichHighlighter = !current || current === splitButtonView.lastExecuted ? splitButtonView.lastExecuted : current;
|
338
|
+
return optionsMap[whichHighlighter][key];
|
339
|
+
}
|
340
|
+
return dropdownView;
|
341
|
+
});
|
342
|
+
}
|
343
|
+
/**
|
344
|
+
* Creates the menu bar button for highlight including submenu with available options.
|
345
|
+
*/ _addMenuBarButton(options) {
|
346
|
+
const editor = this.editor;
|
347
|
+
const t = editor.t;
|
348
|
+
editor.ui.componentFactory.add('menuBar:highlight', (locale)=>{
|
349
|
+
const command = editor.commands.get('highlight');
|
350
|
+
const menuView = new MenuBarMenuView(locale);
|
351
|
+
menuView.buttonView.set({
|
352
|
+
label: t('Highlight'),
|
353
|
+
icon: getIconForType('marker')
|
354
|
+
});
|
355
|
+
menuView.bind('isEnabled').to(command);
|
356
|
+
menuView.buttonView.iconView.fillColor = 'transparent';
|
357
|
+
const listView = new MenuBarMenuListView(locale);
|
358
|
+
for (const option of options){
|
359
|
+
const listItemView = new MenuBarMenuListItemView(locale, menuView);
|
360
|
+
const buttonView = new MenuBarMenuListItemButtonView(locale);
|
361
|
+
buttonView.set({
|
362
|
+
label: option.title,
|
363
|
+
icon: getIconForType(option.type)
|
364
|
+
});
|
365
|
+
buttonView.delegate('execute').to(menuView);
|
366
|
+
buttonView.bind('isOn').to(command, 'value', (value)=>value === option.model);
|
367
|
+
buttonView.bind('ariaChecked').to(buttonView, 'isOn');
|
368
|
+
buttonView.iconView.bind('fillColor').to(buttonView, 'isOn', (value)=>value ? 'transparent' : option.color);
|
369
|
+
buttonView.on('execute', ()=>{
|
370
|
+
editor.execute('highlight', {
|
371
|
+
value: option.model
|
372
|
+
});
|
373
|
+
editor.editing.view.focus();
|
374
|
+
});
|
375
|
+
listItemView.children.add(buttonView);
|
376
|
+
listView.items.add(listItemView);
|
377
|
+
}
|
378
|
+
// Add remove highlight button
|
379
|
+
listView.items.add(new ListSeparatorView(locale));
|
380
|
+
const listItemView = new MenuBarMenuListItemView(locale, menuView);
|
381
|
+
const buttonView = new MenuBarMenuListItemButtonView(locale);
|
382
|
+
buttonView.set({
|
383
|
+
label: t('Remove highlight'),
|
384
|
+
icon: icons.eraser
|
385
|
+
});
|
386
|
+
buttonView.delegate('execute').to(menuView);
|
387
|
+
buttonView.on('execute', ()=>{
|
388
|
+
editor.execute('highlight', {
|
389
|
+
value: null
|
390
|
+
});
|
391
|
+
editor.editing.view.focus();
|
392
|
+
});
|
393
|
+
listItemView.children.add(buttonView);
|
394
|
+
listView.items.add(listItemView);
|
395
|
+
menuView.panelView.children.add(listView);
|
396
|
+
return menuView;
|
397
|
+
});
|
398
|
+
}
|
399
|
+
}
|
400
|
+
/**
|
401
|
+
* Extends split button icon style to reflect last used button style.
|
402
|
+
*/ function bindToolbarIconStyleToActiveColor(dropdownView) {
|
403
|
+
const actionView = dropdownView.buttonView.actionView;
|
404
|
+
actionView.iconView.bind('fillColor').to(dropdownView.buttonView, 'color');
|
405
|
+
}
|
406
|
+
/**
|
407
|
+
* Returns icon for given highlighter type.
|
408
|
+
*/ function getIconForType(type) {
|
409
|
+
return type === 'marker' ? markerIcon : penIcon;
|
410
|
+
}
|
411
|
+
|
412
|
+
class Highlight extends Plugin {
|
413
|
+
/**
|
414
|
+
* @inheritDoc
|
415
|
+
*/ static get requires() {
|
416
|
+
return [
|
417
|
+
HighlightEditing,
|
418
|
+
HighlightUI
|
419
|
+
];
|
420
|
+
}
|
421
|
+
/**
|
422
|
+
* @inheritDoc
|
423
|
+
*/ static get pluginName() {
|
424
|
+
return 'Highlight';
|
425
|
+
}
|
426
|
+
}
|
427
|
+
|
428
|
+
export { Highlight, HighlightEditing, HighlightUI };
|
429
|
+
//# sourceMappingURL=index.js.map
|