@ckeditor/ckeditor5-highlight 38.1.0 → 38.1.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.
@@ -1,91 +1,91 @@
1
- /**
2
- * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
- */
5
- /**
6
- * @module highlight/highlightcommand
7
- */
8
- import { Command } from 'ckeditor5/src/core';
9
- /**
10
- * The highlight command. It is used by the {@link module:highlight/highlightediting~HighlightEditing highlight feature}
11
- * to apply the text highlighting.
12
- *
13
- * ```ts
14
- * editor.execute( 'highlight', { value: 'greenMarker' } );
15
- * ```
16
- *
17
- * **Note**: Executing the command without a value removes the attribute from the model. If the selection is collapsed
18
- * inside a text with the highlight attribute, the command will remove the attribute from the entire range
19
- * of that text.
20
- */
21
- export default class HighlightCommand extends Command {
22
- /**
23
- * @inheritDoc
24
- */
25
- refresh() {
26
- const model = this.editor.model;
27
- const doc = model.document;
28
- this.value = doc.selection.getAttribute('highlight');
29
- this.isEnabled = model.schema.checkAttributeInSelection(doc.selection, 'highlight');
30
- }
31
- /**
32
- * Executes the command.
33
- *
34
- * @param options Options for the executed command.
35
- * @param options.value The value to apply.
36
- *
37
- * @fires execute
38
- */
39
- execute(options = {}) {
40
- const model = this.editor.model;
41
- const document = model.document;
42
- const selection = document.selection;
43
- const highlighter = options.value;
44
- model.change(writer => {
45
- if (selection.isCollapsed) {
46
- const position = selection.getFirstPosition();
47
- // When selection is inside text with `highlight` attribute.
48
- if (selection.hasAttribute('highlight')) {
49
- // Find the full highlighted range.
50
- const isSameHighlight = (value) => {
51
- return value.item.hasAttribute('highlight') && value.item.getAttribute('highlight') === this.value;
52
- };
53
- const highlightStart = position.getLastMatchingPosition(isSameHighlight, { direction: 'backward' });
54
- const highlightEnd = position.getLastMatchingPosition(isSameHighlight);
55
- const highlightRange = writer.createRange(highlightStart, highlightEnd);
56
- // Then depending on current value...
57
- if (!highlighter || this.value === highlighter) {
58
- // ...remove attribute when passing highlighter different then current or executing "eraser".
59
- // If we're at the end of the highlighted range, we don't want to remove highlight of the range.
60
- if (!position.isEqual(highlightEnd)) {
61
- writer.removeAttribute('highlight', highlightRange);
62
- }
63
- writer.removeSelectionAttribute('highlight');
64
- }
65
- else {
66
- // ...update `highlight` value.
67
- // If we're at the end of the highlighted range, we don't want to change the highlight of the range.
68
- if (!position.isEqual(highlightEnd)) {
69
- writer.setAttribute('highlight', highlighter, highlightRange);
70
- }
71
- writer.setSelectionAttribute('highlight', highlighter);
72
- }
73
- }
74
- else if (highlighter) {
75
- writer.setSelectionAttribute('highlight', highlighter);
76
- }
77
- }
78
- else {
79
- const ranges = model.schema.getValidRanges(selection.getRanges(), 'highlight');
80
- for (const range of ranges) {
81
- if (highlighter) {
82
- writer.setAttribute('highlight', highlighter, range);
83
- }
84
- else {
85
- writer.removeAttribute('highlight', range);
86
- }
87
- }
88
- }
89
- });
90
- }
91
- }
1
+ /**
2
+ * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
+ */
5
+ /**
6
+ * @module highlight/highlightcommand
7
+ */
8
+ import { Command } from 'ckeditor5/src/core';
9
+ /**
10
+ * The highlight command. It is used by the {@link module:highlight/highlightediting~HighlightEditing highlight feature}
11
+ * to apply the text highlighting.
12
+ *
13
+ * ```ts
14
+ * editor.execute( 'highlight', { value: 'greenMarker' } );
15
+ * ```
16
+ *
17
+ * **Note**: Executing the command without a value removes the attribute from the model. If the selection is collapsed
18
+ * inside a text with the highlight attribute, the command will remove the attribute from the entire range
19
+ * of that text.
20
+ */
21
+ export default class HighlightCommand extends Command {
22
+ /**
23
+ * @inheritDoc
24
+ */
25
+ refresh() {
26
+ const model = this.editor.model;
27
+ const doc = model.document;
28
+ this.value = doc.selection.getAttribute('highlight');
29
+ this.isEnabled = model.schema.checkAttributeInSelection(doc.selection, 'highlight');
30
+ }
31
+ /**
32
+ * Executes the command.
33
+ *
34
+ * @param options Options for the executed command.
35
+ * @param options.value The value to apply.
36
+ *
37
+ * @fires execute
38
+ */
39
+ execute(options = {}) {
40
+ const model = this.editor.model;
41
+ const document = model.document;
42
+ const selection = document.selection;
43
+ const highlighter = options.value;
44
+ model.change(writer => {
45
+ if (selection.isCollapsed) {
46
+ const position = selection.getFirstPosition();
47
+ // When selection is inside text with `highlight` attribute.
48
+ if (selection.hasAttribute('highlight')) {
49
+ // Find the full highlighted range.
50
+ const isSameHighlight = (value) => {
51
+ return value.item.hasAttribute('highlight') && value.item.getAttribute('highlight') === this.value;
52
+ };
53
+ const highlightStart = position.getLastMatchingPosition(isSameHighlight, { direction: 'backward' });
54
+ const highlightEnd = position.getLastMatchingPosition(isSameHighlight);
55
+ const highlightRange = writer.createRange(highlightStart, highlightEnd);
56
+ // Then depending on current value...
57
+ if (!highlighter || this.value === highlighter) {
58
+ // ...remove attribute when passing highlighter different then current or executing "eraser".
59
+ // If we're at the end of the highlighted range, we don't want to remove highlight of the range.
60
+ if (!position.isEqual(highlightEnd)) {
61
+ writer.removeAttribute('highlight', highlightRange);
62
+ }
63
+ writer.removeSelectionAttribute('highlight');
64
+ }
65
+ else {
66
+ // ...update `highlight` value.
67
+ // If we're at the end of the highlighted range, we don't want to change the highlight of the range.
68
+ if (!position.isEqual(highlightEnd)) {
69
+ writer.setAttribute('highlight', highlighter, highlightRange);
70
+ }
71
+ writer.setSelectionAttribute('highlight', highlighter);
72
+ }
73
+ }
74
+ else if (highlighter) {
75
+ writer.setSelectionAttribute('highlight', highlighter);
76
+ }
77
+ }
78
+ else {
79
+ const ranges = model.schema.getValidRanges(selection.getRanges(), 'highlight');
80
+ for (const range of ranges) {
81
+ if (highlighter) {
82
+ writer.setAttribute('highlight', highlighter, range);
83
+ }
84
+ else {
85
+ writer.removeAttribute('highlight', range);
86
+ }
87
+ }
88
+ }
89
+ });
90
+ }
91
+ }
@@ -1,171 +1,171 @@
1
- /**
2
- * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
- */
5
- /**
6
- * @module highlight/highlightconfig
7
- */
8
- /**
9
- * The highlight option descriptor. See {@link module:highlight/highlightconfig~HighlightConfig} to learn more.
10
- *
11
- * ```ts
12
- * {
13
- * model: 'pinkMarker',
14
- * class: 'marker-pink',
15
- * title: 'Pink Marker',
16
- * color: 'var(--ck-highlight-marker-pink)',
17
- * type: 'marker'
18
- * }
19
- * ```
20
- */
21
- export interface HighlightOption {
22
- /**
23
- * The user-readable title of the option.
24
- */
25
- title: string;
26
- /**
27
- * The unique attribute value in the model.
28
- */
29
- model: string;
30
- /**
31
- * The CSS `var()` used for the highlighter. The color is used in the user interface to represent the highlighter.
32
- * There is a possibility to use the default color format like rgb, hex or hsl, but you need to care about the color of `<mark>`
33
- * by adding CSS classes definition.
34
- */
35
- color: string;
36
- /**
37
- * The CSS class used on the `<mark>` element in the view. It should match the `color` setting.
38
- */
39
- class: string;
40
- /**
41
- * The type of highlighter:
42
- *
43
- * * `'marker'` &ndash; Uses the `color` as the `background-color` style,
44
- * * `'pen'` &ndash; Uses the `color` as the font `color` style.
45
- */
46
- type: 'marker' | 'pen';
47
- }
48
- /**
49
- * The configuration of the {@link module:highlight/highlight~Highlight highlight feature}.
50
- * ```ts
51
- * ClassicEditor
52
- * .create( editorElement, {
53
- * highlight: ... // Highlight feature configuration.
54
- * } )
55
- * .then( ... )
56
- * .catch( ... );
57
- * ```
58
- * See {@link module:core/editor/editorconfig~EditorConfig all editor options}.
59
- */
60
- export interface HighlightConfig {
61
- /**
62
- * The available highlight options. The default value is:
63
- * ```ts
64
- * options: [
65
- * {
66
- * model: 'yellowMarker',
67
- * class: 'marker-yellow',
68
- * title: 'Yellow marker',
69
- * color: 'var(--ck-highlight-marker-yellow)',
70
- * type: 'marker'
71
- * },
72
- * {
73
- * model: 'greenMarker',
74
- * class: 'marker-green',
75
- * title: 'Green marker',
76
- * color: 'var(--ck-highlight-marker-green)',
77
- * type: 'marker'
78
- * },
79
- * {
80
- * model: 'pinkMarker',
81
- * class: 'marker-pink',
82
- * title: 'Pink marker',
83
- * color: 'var(--ck-highlight-marker-pink)',
84
- * type: 'marker'
85
- * },
86
- * {
87
- * model: 'blueMarker',
88
- * class: 'marker-blue',
89
- * title: 'Blue marker',
90
- * color: 'var(--ck-highlight-marker-blue)',
91
- * type: 'marker'
92
- * },
93
- * {
94
- * model: 'redPen',
95
- * class: 'pen-red',
96
- * title: 'Red pen',
97
- * color: 'var(--ck-highlight-pen-red)',
98
- * type: 'pen'
99
- * },
100
- * {
101
- * model: 'greenPen',
102
- * class: 'pen-green',
103
- * title: 'Green pen',
104
- * color: 'var(--ck-highlight-pen-green)',
105
- * type: 'pen'
106
- * }
107
- * ]
108
- * ```
109
- *
110
- * There are two types of highlighters available:
111
- *
112
- * * `'marker'` &ndash; Rendered as a `<mark>` element, styled with the `background-color`.
113
- * * `'pen'` &ndash; Rendered as a `<mark>` element, styled with the font `color`.
114
- *
115
- * **Note**: The highlight feature provides a stylesheet with the CSS classes and corresponding colors defined
116
- * as CSS variables.
117
- *
118
- * ```css
119
- * :root {
120
- * --ck-highlight-marker-yellow: #fdfd77;
121
- * --ck-highlight-marker-green: #63f963;
122
- * --ck-highlight-marker-pink: #fc7999;
123
- * --ck-highlight-marker-blue: #72cdfd;
124
- * --ck-highlight-pen-red: #e91313;
125
- * --ck-highlight-pen-green: #118800;
126
- * }
127
- *
128
- * .marker-yellow { ... }
129
- * .marker-green { ... }
130
- * .marker-pink { ... }
131
- * .marker-blue { ... }
132
- * .pen-red { ... }
133
- * .pen-green { ... }
134
- * ```
135
- *
136
- * It is possible to define the `color` property directly as `rgba(R, G, B, A)`,
137
- * `#RRGGBB[AA]` or `hsla(H, S, L, A)`. In such situation, the color will **only** apply to the UI of
138
- * the editor and the `<mark>` elements in the content must be styled by custom classes provided by
139
- * a dedicated stylesheet.
140
- *
141
- * **Note**: It is recommended for the `color` property to correspond to the class in the content
142
- * stylesheet because it represents the highlighter in the user interface of the editor.
143
- *
144
- * ```ts
145
- * ClassicEditor
146
- * .create( editorElement, {
147
- * highlight: {
148
- * options: [
149
- * {
150
- * model: 'pinkMarker',
151
- * class: 'marker-pink',
152
- * title: 'Pink Marker',
153
- * color: 'var(--ck-highlight-marker-pink)',
154
- * type: 'marker'
155
- * },
156
- * {
157
- * model: 'redPen',
158
- * class: 'pen-red',
159
- * title: 'Red Pen',
160
- * color: 'var(--ck-highlight-pen-red)',
161
- * type: 'pen'
162
- * },
163
- * ]
164
- * }
165
- * } )
166
- * .then( ... )
167
- * .catch( ... );
168
- * ```
169
- */
170
- options: Array<HighlightOption>;
171
- }
1
+ /**
2
+ * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
+ */
5
+ /**
6
+ * @module highlight/highlightconfig
7
+ */
8
+ /**
9
+ * The highlight option descriptor. See {@link module:highlight/highlightconfig~HighlightConfig} to learn more.
10
+ *
11
+ * ```ts
12
+ * {
13
+ * model: 'pinkMarker',
14
+ * class: 'marker-pink',
15
+ * title: 'Pink Marker',
16
+ * color: 'var(--ck-highlight-marker-pink)',
17
+ * type: 'marker'
18
+ * }
19
+ * ```
20
+ */
21
+ export interface HighlightOption {
22
+ /**
23
+ * The user-readable title of the option.
24
+ */
25
+ title: string;
26
+ /**
27
+ * The unique attribute value in the model.
28
+ */
29
+ model: string;
30
+ /**
31
+ * The CSS `var()` used for the highlighter. The color is used in the user interface to represent the highlighter.
32
+ * There is a possibility to use the default color format like rgb, hex or hsl, but you need to care about the color of `<mark>`
33
+ * by adding CSS classes definition.
34
+ */
35
+ color: string;
36
+ /**
37
+ * The CSS class used on the `<mark>` element in the view. It should match the `color` setting.
38
+ */
39
+ class: string;
40
+ /**
41
+ * The type of highlighter:
42
+ *
43
+ * * `'marker'` &ndash; Uses the `color` as the `background-color` style,
44
+ * * `'pen'` &ndash; Uses the `color` as the font `color` style.
45
+ */
46
+ type: 'marker' | 'pen';
47
+ }
48
+ /**
49
+ * The configuration of the {@link module:highlight/highlight~Highlight highlight feature}.
50
+ * ```ts
51
+ * ClassicEditor
52
+ * .create( editorElement, {
53
+ * highlight: ... // Highlight feature configuration.
54
+ * } )
55
+ * .then( ... )
56
+ * .catch( ... );
57
+ * ```
58
+ * See {@link module:core/editor/editorconfig~EditorConfig all editor options}.
59
+ */
60
+ export interface HighlightConfig {
61
+ /**
62
+ * The available highlight options. The default value is:
63
+ * ```ts
64
+ * options: [
65
+ * {
66
+ * model: 'yellowMarker',
67
+ * class: 'marker-yellow',
68
+ * title: 'Yellow marker',
69
+ * color: 'var(--ck-highlight-marker-yellow)',
70
+ * type: 'marker'
71
+ * },
72
+ * {
73
+ * model: 'greenMarker',
74
+ * class: 'marker-green',
75
+ * title: 'Green marker',
76
+ * color: 'var(--ck-highlight-marker-green)',
77
+ * type: 'marker'
78
+ * },
79
+ * {
80
+ * model: 'pinkMarker',
81
+ * class: 'marker-pink',
82
+ * title: 'Pink marker',
83
+ * color: 'var(--ck-highlight-marker-pink)',
84
+ * type: 'marker'
85
+ * },
86
+ * {
87
+ * model: 'blueMarker',
88
+ * class: 'marker-blue',
89
+ * title: 'Blue marker',
90
+ * color: 'var(--ck-highlight-marker-blue)',
91
+ * type: 'marker'
92
+ * },
93
+ * {
94
+ * model: 'redPen',
95
+ * class: 'pen-red',
96
+ * title: 'Red pen',
97
+ * color: 'var(--ck-highlight-pen-red)',
98
+ * type: 'pen'
99
+ * },
100
+ * {
101
+ * model: 'greenPen',
102
+ * class: 'pen-green',
103
+ * title: 'Green pen',
104
+ * color: 'var(--ck-highlight-pen-green)',
105
+ * type: 'pen'
106
+ * }
107
+ * ]
108
+ * ```
109
+ *
110
+ * There are two types of highlighters available:
111
+ *
112
+ * * `'marker'` &ndash; Rendered as a `<mark>` element, styled with the `background-color`.
113
+ * * `'pen'` &ndash; Rendered as a `<mark>` element, styled with the font `color`.
114
+ *
115
+ * **Note**: The highlight feature provides a stylesheet with the CSS classes and corresponding colors defined
116
+ * as CSS variables.
117
+ *
118
+ * ```css
119
+ * :root {
120
+ * --ck-highlight-marker-yellow: #fdfd77;
121
+ * --ck-highlight-marker-green: #63f963;
122
+ * --ck-highlight-marker-pink: #fc7999;
123
+ * --ck-highlight-marker-blue: #72cdfd;
124
+ * --ck-highlight-pen-red: #e91313;
125
+ * --ck-highlight-pen-green: #118800;
126
+ * }
127
+ *
128
+ * .marker-yellow { ... }
129
+ * .marker-green { ... }
130
+ * .marker-pink { ... }
131
+ * .marker-blue { ... }
132
+ * .pen-red { ... }
133
+ * .pen-green { ... }
134
+ * ```
135
+ *
136
+ * It is possible to define the `color` property directly as `rgba(R, G, B, A)`,
137
+ * `#RRGGBB[AA]` or `hsla(H, S, L, A)`. In such situation, the color will **only** apply to the UI of
138
+ * the editor and the `<mark>` elements in the content must be styled by custom classes provided by
139
+ * a dedicated stylesheet.
140
+ *
141
+ * **Note**: It is recommended for the `color` property to correspond to the class in the content
142
+ * stylesheet because it represents the highlighter in the user interface of the editor.
143
+ *
144
+ * ```ts
145
+ * ClassicEditor
146
+ * .create( editorElement, {
147
+ * highlight: {
148
+ * options: [
149
+ * {
150
+ * model: 'pinkMarker',
151
+ * class: 'marker-pink',
152
+ * title: 'Pink Marker',
153
+ * color: 'var(--ck-highlight-marker-pink)',
154
+ * type: 'marker'
155
+ * },
156
+ * {
157
+ * model: 'redPen',
158
+ * class: 'pen-red',
159
+ * title: 'Red Pen',
160
+ * color: 'var(--ck-highlight-pen-red)',
161
+ * type: 'pen'
162
+ * },
163
+ * ]
164
+ * }
165
+ * } )
166
+ * .then( ... )
167
+ * .catch( ... );
168
+ * ```
169
+ */
170
+ options: Array<HighlightOption>;
171
+ }
@@ -1,5 +1,5 @@
1
- /**
2
- * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
- */
5
- export {};
1
+ /**
2
+ * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
+ */
5
+ export {};
@@ -1,28 +1,28 @@
1
- /**
2
- * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
- */
5
- /**
6
- * @module highlight/highlightediting
7
- */
8
- import { Plugin, type Editor } from 'ckeditor5/src/core';
9
- /**
10
- * The highlight editing feature. It introduces the {@link module:highlight/highlightcommand~HighlightCommand command} and the `highlight`
11
- * attribute in the {@link module:engine/model/model~Model model} which renders in the {@link module:engine/view/view view}
12
- * as a `<mark>` element with a `class` attribute (`<mark class="marker-green">...</mark>`) depending
13
- * on the {@link module:highlight/highlightconfig~HighlightConfig configuration}.
14
- */
15
- export default class HighlightEditing extends Plugin {
16
- /**
17
- * @inheritDoc
18
- */
19
- static get pluginName(): "HighlightEditing";
20
- /**
21
- * @inheritDoc
22
- */
23
- constructor(editor: Editor);
24
- /**
25
- * @inheritDoc
26
- */
27
- init(): void;
28
- }
1
+ /**
2
+ * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
+ */
5
+ /**
6
+ * @module highlight/highlightediting
7
+ */
8
+ import { Plugin, type Editor } from 'ckeditor5/src/core';
9
+ /**
10
+ * The highlight editing feature. It introduces the {@link module:highlight/highlightcommand~HighlightCommand command} and the `highlight`
11
+ * attribute in the {@link module:engine/model/model~Model model} which renders in the {@link module:engine/view/view view}
12
+ * as a `<mark>` element with a `class` attribute (`<mark class="marker-green">...</mark>`) depending
13
+ * on the {@link module:highlight/highlightconfig~HighlightConfig configuration}.
14
+ */
15
+ export default class HighlightEditing extends Plugin {
16
+ /**
17
+ * @inheritDoc
18
+ */
19
+ static get pluginName(): "HighlightEditing";
20
+ /**
21
+ * @inheritDoc
22
+ */
23
+ constructor(editor: Editor);
24
+ /**
25
+ * @inheritDoc
26
+ */
27
+ init(): void;
28
+ }