@ckeditor/ckeditor5-style 39.0.2 → 40.0.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/build/style.js.map +1 -0
- package/package.json +2 -2
- package/src/augmentation.d.ts +24 -24
- package/src/augmentation.js +5 -5
- package/src/index.d.ts +14 -14
- package/src/index.js +12 -12
- package/src/integrations/documentlist.d.ts +42 -42
- package/src/integrations/documentlist.js +141 -141
- package/src/integrations/link.d.ts +37 -37
- package/src/integrations/link.js +156 -156
- package/src/integrations/table.d.ts +49 -49
- package/src/integrations/table.js +115 -115
- package/src/style.d.ts +26 -26
- package/src/style.js +30 -30
- package/src/stylecommand.d.ts +82 -82
- package/src/stylecommand.js +200 -200
- package/src/styleconfig.d.ts +87 -87
- package/src/styleconfig.js +5 -5
- package/src/styleediting.d.ts +33 -33
- package/src/styleediting.js +46 -46
- package/src/styleui.d.ts +30 -30
- package/src/styleui.js +94 -94
- package/src/styleutils.d.ts +138 -138
- package/src/styleutils.js +268 -268
- package/src/ui/stylegridbuttonview.d.ts +34 -34
- package/src/ui/stylegridbuttonview.js +55 -55
- package/src/ui/stylegridview.d.ts +72 -72
- package/src/ui/stylegridview.js +89 -89
- package/src/ui/stylegroupview.d.ts +35 -35
- package/src/ui/stylegroupview.js +45 -45
- package/src/ui/stylepanelview.d.ts +89 -89
- package/src/ui/stylepanelview.js +95 -95
package/src/integrations/link.js
CHANGED
|
@@ -1,156 +1,156 @@
|
|
|
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 style/integrations/link
|
|
7
|
-
*/
|
|
8
|
-
import { Plugin } from 'ckeditor5/src/core';
|
|
9
|
-
import { findAttributeRange, findAttributeRangeBound } from 'ckeditor5/src/typing';
|
|
10
|
-
import StyleUtils from '../styleutils';
|
|
11
|
-
export default class LinkStyleSupport extends Plugin {
|
|
12
|
-
/**
|
|
13
|
-
* @inheritDoc
|
|
14
|
-
*/
|
|
15
|
-
static get pluginName() {
|
|
16
|
-
return 'LinkStyleSupport';
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* @inheritDoc
|
|
20
|
-
*/
|
|
21
|
-
static get requires() {
|
|
22
|
-
return [StyleUtils, 'GeneralHtmlSupport'];
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* @inheritDoc
|
|
26
|
-
*/
|
|
27
|
-
init() {
|
|
28
|
-
const editor = this.editor;
|
|
29
|
-
if (!editor.plugins.has('LinkEditing')) {
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
32
|
-
this._styleUtils = editor.plugins.get(StyleUtils);
|
|
33
|
-
this._htmlSupport = this.editor.plugins.get('GeneralHtmlSupport');
|
|
34
|
-
this.listenTo(this._styleUtils, 'isStyleEnabledForInlineSelection', (evt, [definition, selection]) => {
|
|
35
|
-
if (definition.element == 'a') {
|
|
36
|
-
evt.return = this._isStyleEnabled(definition, selection);
|
|
37
|
-
evt.stop();
|
|
38
|
-
}
|
|
39
|
-
}, { priority: 'high' });
|
|
40
|
-
this.listenTo(this._styleUtils, 'isStyleActiveForInlineSelection', (evt, [definition, selection]) => {
|
|
41
|
-
if (definition.element == 'a') {
|
|
42
|
-
evt.return = this._isStyleActive(definition, selection);
|
|
43
|
-
evt.stop();
|
|
44
|
-
}
|
|
45
|
-
}, { priority: 'high' });
|
|
46
|
-
this.listenTo(this._styleUtils, 'getAffectedInlineSelectable', (evt, [definition, selection]) => {
|
|
47
|
-
if (definition.element != 'a') {
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
const selectable = this._getAffectedSelectable(definition, selection);
|
|
51
|
-
if (selectable) {
|
|
52
|
-
evt.return = selectable;
|
|
53
|
-
evt.stop();
|
|
54
|
-
}
|
|
55
|
-
}, { priority: 'high' });
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Verifies if the given style is applicable to the provided document selection.
|
|
59
|
-
*/
|
|
60
|
-
_isStyleEnabled(definition, selection) {
|
|
61
|
-
const model = this.editor.model;
|
|
62
|
-
// Handle collapsed selection.
|
|
63
|
-
if (selection.isCollapsed) {
|
|
64
|
-
return selection.hasAttribute('linkHref');
|
|
65
|
-
}
|
|
66
|
-
// Non-collapsed selection.
|
|
67
|
-
for (const range of selection.getRanges()) {
|
|
68
|
-
for (const item of range.getItems()) {
|
|
69
|
-
if ((item.is('$textProxy') || model.schema.isInline(item)) && item.hasAttribute('linkHref')) {
|
|
70
|
-
return true;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
return false;
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
* Returns true if the given style is applied to the specified document selection.
|
|
78
|
-
*/
|
|
79
|
-
_isStyleActive(definition, selection) {
|
|
80
|
-
const model = this.editor.model;
|
|
81
|
-
const attributeName = this._htmlSupport.getGhsAttributeNameForElement(definition.element);
|
|
82
|
-
// Handle collapsed selection.
|
|
83
|
-
if (selection.isCollapsed) {
|
|
84
|
-
if (selection.hasAttribute('linkHref')) {
|
|
85
|
-
const ghsAttributeValue = selection.getAttribute(attributeName);
|
|
86
|
-
if (this._styleUtils.hasAllClasses(ghsAttributeValue, definition.classes)) {
|
|
87
|
-
return true;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
return false;
|
|
91
|
-
}
|
|
92
|
-
// Non-collapsed selection.
|
|
93
|
-
for (const range of selection.getRanges()) {
|
|
94
|
-
for (const item of range.getItems()) {
|
|
95
|
-
if ((item.is('$textProxy') || model.schema.isInline(item)) && item.hasAttribute('linkHref')) {
|
|
96
|
-
const ghsAttributeValue = item.getAttribute(attributeName);
|
|
97
|
-
return this._styleUtils.hasAllClasses(ghsAttributeValue, definition.classes);
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
return false;
|
|
102
|
-
}
|
|
103
|
-
/**
|
|
104
|
-
* Returns a selectable that given style should be applied to.
|
|
105
|
-
*/
|
|
106
|
-
_getAffectedSelectable(definition, selection) {
|
|
107
|
-
const model = this.editor.model;
|
|
108
|
-
// Handle collapsed selection.
|
|
109
|
-
if (selection.isCollapsed) {
|
|
110
|
-
const linkHref = selection.getAttribute('linkHref');
|
|
111
|
-
return findAttributeRange(selection.getFirstPosition(), 'linkHref', linkHref, model);
|
|
112
|
-
}
|
|
113
|
-
// Non-collapsed selection.
|
|
114
|
-
const ranges = [];
|
|
115
|
-
for (const range of selection.getRanges()) {
|
|
116
|
-
// First expand range to include the whole link.
|
|
117
|
-
const expandedRange = model.createRange(expandAttributePosition(range.start, 'linkHref', true, model), expandAttributePosition(range.end, 'linkHref', false, model));
|
|
118
|
-
// Pick only ranges on links.
|
|
119
|
-
for (const item of expandedRange.getItems()) {
|
|
120
|
-
if ((item.is('$textProxy') || model.schema.isInline(item)) && item.hasAttribute('linkHref')) {
|
|
121
|
-
ranges.push(this.editor.model.createRangeOn(item));
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
// Make sure that we have a continuous range on a link
|
|
126
|
-
// (not split between text nodes with mixed attributes like bold etc.)
|
|
127
|
-
return normalizeRanges(ranges);
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
/**
|
|
131
|
-
* Walks forward or backward (depends on the `lookBack` flag), node by node, as long as they have the same attribute value
|
|
132
|
-
* and returns a position just before or after (depends on the `lookBack` flag) the last matched node.
|
|
133
|
-
*/
|
|
134
|
-
function expandAttributePosition(position, attributeName, lookBack, model) {
|
|
135
|
-
const referenceNode = position.textNode || (lookBack ? position.nodeAfter : position.nodeBefore);
|
|
136
|
-
if (!referenceNode || !referenceNode.hasAttribute(attributeName)) {
|
|
137
|
-
return position;
|
|
138
|
-
}
|
|
139
|
-
const attributeValue = referenceNode.getAttribute(attributeName);
|
|
140
|
-
return findAttributeRangeBound(position, attributeName, attributeValue, lookBack, model);
|
|
141
|
-
}
|
|
142
|
-
/**
|
|
143
|
-
* Normalizes list of ranges by joining intersecting or "touching" ranges.
|
|
144
|
-
*
|
|
145
|
-
* Note: It assumes that ranges are sorted.
|
|
146
|
-
*/
|
|
147
|
-
function normalizeRanges(ranges) {
|
|
148
|
-
for (let i = 1; i < ranges.length; i++) {
|
|
149
|
-
const joinedRange = ranges[i - 1].getJoined(ranges[i]);
|
|
150
|
-
if (joinedRange) {
|
|
151
|
-
// Replace the ranges on the list with the new joined range.
|
|
152
|
-
ranges.splice(--i, 2, joinedRange);
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
return ranges;
|
|
156
|
-
}
|
|
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 style/integrations/link
|
|
7
|
+
*/
|
|
8
|
+
import { Plugin } from 'ckeditor5/src/core';
|
|
9
|
+
import { findAttributeRange, findAttributeRangeBound } from 'ckeditor5/src/typing';
|
|
10
|
+
import StyleUtils from '../styleutils';
|
|
11
|
+
export default class LinkStyleSupport extends Plugin {
|
|
12
|
+
/**
|
|
13
|
+
* @inheritDoc
|
|
14
|
+
*/
|
|
15
|
+
static get pluginName() {
|
|
16
|
+
return 'LinkStyleSupport';
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* @inheritDoc
|
|
20
|
+
*/
|
|
21
|
+
static get requires() {
|
|
22
|
+
return [StyleUtils, 'GeneralHtmlSupport'];
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* @inheritDoc
|
|
26
|
+
*/
|
|
27
|
+
init() {
|
|
28
|
+
const editor = this.editor;
|
|
29
|
+
if (!editor.plugins.has('LinkEditing')) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
this._styleUtils = editor.plugins.get(StyleUtils);
|
|
33
|
+
this._htmlSupport = this.editor.plugins.get('GeneralHtmlSupport');
|
|
34
|
+
this.listenTo(this._styleUtils, 'isStyleEnabledForInlineSelection', (evt, [definition, selection]) => {
|
|
35
|
+
if (definition.element == 'a') {
|
|
36
|
+
evt.return = this._isStyleEnabled(definition, selection);
|
|
37
|
+
evt.stop();
|
|
38
|
+
}
|
|
39
|
+
}, { priority: 'high' });
|
|
40
|
+
this.listenTo(this._styleUtils, 'isStyleActiveForInlineSelection', (evt, [definition, selection]) => {
|
|
41
|
+
if (definition.element == 'a') {
|
|
42
|
+
evt.return = this._isStyleActive(definition, selection);
|
|
43
|
+
evt.stop();
|
|
44
|
+
}
|
|
45
|
+
}, { priority: 'high' });
|
|
46
|
+
this.listenTo(this._styleUtils, 'getAffectedInlineSelectable', (evt, [definition, selection]) => {
|
|
47
|
+
if (definition.element != 'a') {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
const selectable = this._getAffectedSelectable(definition, selection);
|
|
51
|
+
if (selectable) {
|
|
52
|
+
evt.return = selectable;
|
|
53
|
+
evt.stop();
|
|
54
|
+
}
|
|
55
|
+
}, { priority: 'high' });
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Verifies if the given style is applicable to the provided document selection.
|
|
59
|
+
*/
|
|
60
|
+
_isStyleEnabled(definition, selection) {
|
|
61
|
+
const model = this.editor.model;
|
|
62
|
+
// Handle collapsed selection.
|
|
63
|
+
if (selection.isCollapsed) {
|
|
64
|
+
return selection.hasAttribute('linkHref');
|
|
65
|
+
}
|
|
66
|
+
// Non-collapsed selection.
|
|
67
|
+
for (const range of selection.getRanges()) {
|
|
68
|
+
for (const item of range.getItems()) {
|
|
69
|
+
if ((item.is('$textProxy') || model.schema.isInline(item)) && item.hasAttribute('linkHref')) {
|
|
70
|
+
return true;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Returns true if the given style is applied to the specified document selection.
|
|
78
|
+
*/
|
|
79
|
+
_isStyleActive(definition, selection) {
|
|
80
|
+
const model = this.editor.model;
|
|
81
|
+
const attributeName = this._htmlSupport.getGhsAttributeNameForElement(definition.element);
|
|
82
|
+
// Handle collapsed selection.
|
|
83
|
+
if (selection.isCollapsed) {
|
|
84
|
+
if (selection.hasAttribute('linkHref')) {
|
|
85
|
+
const ghsAttributeValue = selection.getAttribute(attributeName);
|
|
86
|
+
if (this._styleUtils.hasAllClasses(ghsAttributeValue, definition.classes)) {
|
|
87
|
+
return true;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
92
|
+
// Non-collapsed selection.
|
|
93
|
+
for (const range of selection.getRanges()) {
|
|
94
|
+
for (const item of range.getItems()) {
|
|
95
|
+
if ((item.is('$textProxy') || model.schema.isInline(item)) && item.hasAttribute('linkHref')) {
|
|
96
|
+
const ghsAttributeValue = item.getAttribute(attributeName);
|
|
97
|
+
return this._styleUtils.hasAllClasses(ghsAttributeValue, definition.classes);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return false;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Returns a selectable that given style should be applied to.
|
|
105
|
+
*/
|
|
106
|
+
_getAffectedSelectable(definition, selection) {
|
|
107
|
+
const model = this.editor.model;
|
|
108
|
+
// Handle collapsed selection.
|
|
109
|
+
if (selection.isCollapsed) {
|
|
110
|
+
const linkHref = selection.getAttribute('linkHref');
|
|
111
|
+
return findAttributeRange(selection.getFirstPosition(), 'linkHref', linkHref, model);
|
|
112
|
+
}
|
|
113
|
+
// Non-collapsed selection.
|
|
114
|
+
const ranges = [];
|
|
115
|
+
for (const range of selection.getRanges()) {
|
|
116
|
+
// First expand range to include the whole link.
|
|
117
|
+
const expandedRange = model.createRange(expandAttributePosition(range.start, 'linkHref', true, model), expandAttributePosition(range.end, 'linkHref', false, model));
|
|
118
|
+
// Pick only ranges on links.
|
|
119
|
+
for (const item of expandedRange.getItems()) {
|
|
120
|
+
if ((item.is('$textProxy') || model.schema.isInline(item)) && item.hasAttribute('linkHref')) {
|
|
121
|
+
ranges.push(this.editor.model.createRangeOn(item));
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
// Make sure that we have a continuous range on a link
|
|
126
|
+
// (not split between text nodes with mixed attributes like bold etc.)
|
|
127
|
+
return normalizeRanges(ranges);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Walks forward or backward (depends on the `lookBack` flag), node by node, as long as they have the same attribute value
|
|
132
|
+
* and returns a position just before or after (depends on the `lookBack` flag) the last matched node.
|
|
133
|
+
*/
|
|
134
|
+
function expandAttributePosition(position, attributeName, lookBack, model) {
|
|
135
|
+
const referenceNode = position.textNode || (lookBack ? position.nodeAfter : position.nodeBefore);
|
|
136
|
+
if (!referenceNode || !referenceNode.hasAttribute(attributeName)) {
|
|
137
|
+
return position;
|
|
138
|
+
}
|
|
139
|
+
const attributeValue = referenceNode.getAttribute(attributeName);
|
|
140
|
+
return findAttributeRangeBound(position, attributeName, attributeValue, lookBack, model);
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Normalizes list of ranges by joining intersecting or "touching" ranges.
|
|
144
|
+
*
|
|
145
|
+
* Note: It assumes that ranges are sorted.
|
|
146
|
+
*/
|
|
147
|
+
function normalizeRanges(ranges) {
|
|
148
|
+
for (let i = 1; i < ranges.length; i++) {
|
|
149
|
+
const joinedRange = ranges[i - 1].getJoined(ranges[i]);
|
|
150
|
+
if (joinedRange) {
|
|
151
|
+
// Replace the ranges on the list with the new joined range.
|
|
152
|
+
ranges.splice(--i, 2, joinedRange);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return ranges;
|
|
156
|
+
}
|
|
@@ -1,49 +1,49 @@
|
|
|
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 style/integrations/table
|
|
7
|
-
*/
|
|
8
|
-
import { Plugin } from 'ckeditor5/src/core';
|
|
9
|
-
import StyleUtils from '../styleutils';
|
|
10
|
-
export default class TableStyleSupport extends Plugin {
|
|
11
|
-
private _tableUtils;
|
|
12
|
-
private _styleUtils;
|
|
13
|
-
/**
|
|
14
|
-
* @inheritDoc
|
|
15
|
-
*/
|
|
16
|
-
static get pluginName(): "TableStyleSupport";
|
|
17
|
-
/**
|
|
18
|
-
* @inheritDoc
|
|
19
|
-
*/
|
|
20
|
-
static get requires(): readonly [typeof StyleUtils];
|
|
21
|
-
/**
|
|
22
|
-
* @inheritDoc
|
|
23
|
-
*/
|
|
24
|
-
init(): void;
|
|
25
|
-
/**
|
|
26
|
-
* Checks if this plugin's custom logic should be applied for defintion-block pair.
|
|
27
|
-
*
|
|
28
|
-
* @param definition Style definition that is being considered.
|
|
29
|
-
* @param block Block element to check if should be styled.
|
|
30
|
-
* @returns True if the defintion-block pair meet the plugin criteria, false otherwise.
|
|
31
|
-
*/
|
|
32
|
-
private _isApplicable;
|
|
33
|
-
/**
|
|
34
|
-
* Checks if the style definition should be applied to selected block.
|
|
35
|
-
*
|
|
36
|
-
* @param definition Style definition that is being considered.
|
|
37
|
-
* @param block Block element to check if should be styled.
|
|
38
|
-
* @returns True if the block should be style with the style description, false otherwise.
|
|
39
|
-
*/
|
|
40
|
-
private _isStyleEnabledForBlock;
|
|
41
|
-
/**
|
|
42
|
-
* Gets all blocks that the style should be applied to.
|
|
43
|
-
*
|
|
44
|
-
* @param definition Style definition that is being considered.
|
|
45
|
-
* @param block A block element from selection.
|
|
46
|
-
* @returns An array with the block that was passed as an argument if meets the criteria, null otherwise.
|
|
47
|
-
*/
|
|
48
|
-
private _getAffectedBlocks;
|
|
49
|
-
}
|
|
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 style/integrations/table
|
|
7
|
+
*/
|
|
8
|
+
import { Plugin } from 'ckeditor5/src/core';
|
|
9
|
+
import StyleUtils from '../styleutils';
|
|
10
|
+
export default class TableStyleSupport extends Plugin {
|
|
11
|
+
private _tableUtils;
|
|
12
|
+
private _styleUtils;
|
|
13
|
+
/**
|
|
14
|
+
* @inheritDoc
|
|
15
|
+
*/
|
|
16
|
+
static get pluginName(): "TableStyleSupport";
|
|
17
|
+
/**
|
|
18
|
+
* @inheritDoc
|
|
19
|
+
*/
|
|
20
|
+
static get requires(): readonly [typeof StyleUtils];
|
|
21
|
+
/**
|
|
22
|
+
* @inheritDoc
|
|
23
|
+
*/
|
|
24
|
+
init(): void;
|
|
25
|
+
/**
|
|
26
|
+
* Checks if this plugin's custom logic should be applied for defintion-block pair.
|
|
27
|
+
*
|
|
28
|
+
* @param definition Style definition that is being considered.
|
|
29
|
+
* @param block Block element to check if should be styled.
|
|
30
|
+
* @returns True if the defintion-block pair meet the plugin criteria, false otherwise.
|
|
31
|
+
*/
|
|
32
|
+
private _isApplicable;
|
|
33
|
+
/**
|
|
34
|
+
* Checks if the style definition should be applied to selected block.
|
|
35
|
+
*
|
|
36
|
+
* @param definition Style definition that is being considered.
|
|
37
|
+
* @param block Block element to check if should be styled.
|
|
38
|
+
* @returns True if the block should be style with the style description, false otherwise.
|
|
39
|
+
*/
|
|
40
|
+
private _isStyleEnabledForBlock;
|
|
41
|
+
/**
|
|
42
|
+
* Gets all blocks that the style should be applied to.
|
|
43
|
+
*
|
|
44
|
+
* @param definition Style definition that is being considered.
|
|
45
|
+
* @param block A block element from selection.
|
|
46
|
+
* @returns An array with the block that was passed as an argument if meets the criteria, null otherwise.
|
|
47
|
+
*/
|
|
48
|
+
private _getAffectedBlocks;
|
|
49
|
+
}
|
|
@@ -1,115 +1,115 @@
|
|
|
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 style/integrations/table
|
|
7
|
-
*/
|
|
8
|
-
import { Plugin } from 'ckeditor5/src/core';
|
|
9
|
-
import StyleUtils from '../styleutils';
|
|
10
|
-
export default class TableStyleSupport extends Plugin {
|
|
11
|
-
/**
|
|
12
|
-
* @inheritDoc
|
|
13
|
-
*/
|
|
14
|
-
static get pluginName() {
|
|
15
|
-
return 'TableStyleSupport';
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* @inheritDoc
|
|
19
|
-
*/
|
|
20
|
-
static get requires() {
|
|
21
|
-
return [StyleUtils];
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* @inheritDoc
|
|
25
|
-
*/
|
|
26
|
-
init() {
|
|
27
|
-
const editor = this.editor;
|
|
28
|
-
if (!editor.plugins.has('TableEditing')) {
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
31
|
-
this._styleUtils = editor.plugins.get(StyleUtils);
|
|
32
|
-
this._tableUtils = this.editor.plugins.get('TableUtils');
|
|
33
|
-
this.listenTo(this._styleUtils, 'isStyleEnabledForBlock', (evt, [definition, block]) => {
|
|
34
|
-
if (this._isApplicable(definition, block)) {
|
|
35
|
-
evt.return = this._isStyleEnabledForBlock(definition, block);
|
|
36
|
-
evt.stop();
|
|
37
|
-
}
|
|
38
|
-
}, { priority: 'high' });
|
|
39
|
-
this.listenTo(this._styleUtils, 'getAffectedBlocks', (evt, [definition, block]) => {
|
|
40
|
-
if (this._isApplicable(definition, block)) {
|
|
41
|
-
evt.return = this._getAffectedBlocks(definition, block);
|
|
42
|
-
evt.stop();
|
|
43
|
-
}
|
|
44
|
-
}, { priority: 'high' });
|
|
45
|
-
this.listenTo(this._styleUtils, 'configureGHSDataFilter', (evt, [{ block }]) => {
|
|
46
|
-
const ghsDataFilter = this.editor.plugins.get('DataFilter');
|
|
47
|
-
ghsDataFilter.loadAllowedConfig(block
|
|
48
|
-
.filter(definition => definition.element == 'figcaption')
|
|
49
|
-
.map(definition => ({ name: 'caption', classes: definition.classes })));
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Checks if this plugin's custom logic should be applied for defintion-block pair.
|
|
54
|
-
*
|
|
55
|
-
* @param definition Style definition that is being considered.
|
|
56
|
-
* @param block Block element to check if should be styled.
|
|
57
|
-
* @returns True if the defintion-block pair meet the plugin criteria, false otherwise.
|
|
58
|
-
*/
|
|
59
|
-
_isApplicable(definition, block) {
|
|
60
|
-
if (['td', 'th'].includes(definition.element)) {
|
|
61
|
-
return block.name == 'tableCell';
|
|
62
|
-
}
|
|
63
|
-
if (['thead', 'tbody'].includes(definition.element)) {
|
|
64
|
-
return block.name == 'table';
|
|
65
|
-
}
|
|
66
|
-
return false;
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* Checks if the style definition should be applied to selected block.
|
|
70
|
-
*
|
|
71
|
-
* @param definition Style definition that is being considered.
|
|
72
|
-
* @param block Block element to check if should be styled.
|
|
73
|
-
* @returns True if the block should be style with the style description, false otherwise.
|
|
74
|
-
*/
|
|
75
|
-
_isStyleEnabledForBlock(definition, block) {
|
|
76
|
-
if (['td', 'th'].includes(definition.element)) {
|
|
77
|
-
const location = this._tableUtils.getCellLocation(block);
|
|
78
|
-
const tableRow = block.parent;
|
|
79
|
-
const table = tableRow.parent;
|
|
80
|
-
const headingRows = table.getAttribute('headingRows') || 0;
|
|
81
|
-
const headingColumns = table.getAttribute('headingColumns') || 0;
|
|
82
|
-
const isHeadingCell = location.row < headingRows || location.column < headingColumns;
|
|
83
|
-
if (definition.element == 'th') {
|
|
84
|
-
return isHeadingCell;
|
|
85
|
-
}
|
|
86
|
-
else {
|
|
87
|
-
return !isHeadingCell;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
if (['thead', 'tbody'].includes(definition.element)) {
|
|
91
|
-
const headingRows = block.getAttribute('headingRows') || 0;
|
|
92
|
-
if (definition.element == 'thead') {
|
|
93
|
-
return headingRows > 0;
|
|
94
|
-
}
|
|
95
|
-
else {
|
|
96
|
-
return headingRows < this._tableUtils.getRows(block);
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
/* istanbul ignore next -- @preserve */
|
|
100
|
-
return false;
|
|
101
|
-
}
|
|
102
|
-
/**
|
|
103
|
-
* Gets all blocks that the style should be applied to.
|
|
104
|
-
*
|
|
105
|
-
* @param definition Style definition that is being considered.
|
|
106
|
-
* @param block A block element from selection.
|
|
107
|
-
* @returns An array with the block that was passed as an argument if meets the criteria, null otherwise.
|
|
108
|
-
*/
|
|
109
|
-
_getAffectedBlocks(definition, block) {
|
|
110
|
-
if (!this._isStyleEnabledForBlock(definition, block)) {
|
|
111
|
-
return null;
|
|
112
|
-
}
|
|
113
|
-
return [block];
|
|
114
|
-
}
|
|
115
|
-
}
|
|
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 style/integrations/table
|
|
7
|
+
*/
|
|
8
|
+
import { Plugin } from 'ckeditor5/src/core';
|
|
9
|
+
import StyleUtils from '../styleutils';
|
|
10
|
+
export default class TableStyleSupport extends Plugin {
|
|
11
|
+
/**
|
|
12
|
+
* @inheritDoc
|
|
13
|
+
*/
|
|
14
|
+
static get pluginName() {
|
|
15
|
+
return 'TableStyleSupport';
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* @inheritDoc
|
|
19
|
+
*/
|
|
20
|
+
static get requires() {
|
|
21
|
+
return [StyleUtils];
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* @inheritDoc
|
|
25
|
+
*/
|
|
26
|
+
init() {
|
|
27
|
+
const editor = this.editor;
|
|
28
|
+
if (!editor.plugins.has('TableEditing')) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
this._styleUtils = editor.plugins.get(StyleUtils);
|
|
32
|
+
this._tableUtils = this.editor.plugins.get('TableUtils');
|
|
33
|
+
this.listenTo(this._styleUtils, 'isStyleEnabledForBlock', (evt, [definition, block]) => {
|
|
34
|
+
if (this._isApplicable(definition, block)) {
|
|
35
|
+
evt.return = this._isStyleEnabledForBlock(definition, block);
|
|
36
|
+
evt.stop();
|
|
37
|
+
}
|
|
38
|
+
}, { priority: 'high' });
|
|
39
|
+
this.listenTo(this._styleUtils, 'getAffectedBlocks', (evt, [definition, block]) => {
|
|
40
|
+
if (this._isApplicable(definition, block)) {
|
|
41
|
+
evt.return = this._getAffectedBlocks(definition, block);
|
|
42
|
+
evt.stop();
|
|
43
|
+
}
|
|
44
|
+
}, { priority: 'high' });
|
|
45
|
+
this.listenTo(this._styleUtils, 'configureGHSDataFilter', (evt, [{ block }]) => {
|
|
46
|
+
const ghsDataFilter = this.editor.plugins.get('DataFilter');
|
|
47
|
+
ghsDataFilter.loadAllowedConfig(block
|
|
48
|
+
.filter(definition => definition.element == 'figcaption')
|
|
49
|
+
.map(definition => ({ name: 'caption', classes: definition.classes })));
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Checks if this plugin's custom logic should be applied for defintion-block pair.
|
|
54
|
+
*
|
|
55
|
+
* @param definition Style definition that is being considered.
|
|
56
|
+
* @param block Block element to check if should be styled.
|
|
57
|
+
* @returns True if the defintion-block pair meet the plugin criteria, false otherwise.
|
|
58
|
+
*/
|
|
59
|
+
_isApplicable(definition, block) {
|
|
60
|
+
if (['td', 'th'].includes(definition.element)) {
|
|
61
|
+
return block.name == 'tableCell';
|
|
62
|
+
}
|
|
63
|
+
if (['thead', 'tbody'].includes(definition.element)) {
|
|
64
|
+
return block.name == 'table';
|
|
65
|
+
}
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Checks if the style definition should be applied to selected block.
|
|
70
|
+
*
|
|
71
|
+
* @param definition Style definition that is being considered.
|
|
72
|
+
* @param block Block element to check if should be styled.
|
|
73
|
+
* @returns True if the block should be style with the style description, false otherwise.
|
|
74
|
+
*/
|
|
75
|
+
_isStyleEnabledForBlock(definition, block) {
|
|
76
|
+
if (['td', 'th'].includes(definition.element)) {
|
|
77
|
+
const location = this._tableUtils.getCellLocation(block);
|
|
78
|
+
const tableRow = block.parent;
|
|
79
|
+
const table = tableRow.parent;
|
|
80
|
+
const headingRows = table.getAttribute('headingRows') || 0;
|
|
81
|
+
const headingColumns = table.getAttribute('headingColumns') || 0;
|
|
82
|
+
const isHeadingCell = location.row < headingRows || location.column < headingColumns;
|
|
83
|
+
if (definition.element == 'th') {
|
|
84
|
+
return isHeadingCell;
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
return !isHeadingCell;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
if (['thead', 'tbody'].includes(definition.element)) {
|
|
91
|
+
const headingRows = block.getAttribute('headingRows') || 0;
|
|
92
|
+
if (definition.element == 'thead') {
|
|
93
|
+
return headingRows > 0;
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
return headingRows < this._tableUtils.getRows(block);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
/* istanbul ignore next -- @preserve */
|
|
100
|
+
return false;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Gets all blocks that the style should be applied to.
|
|
104
|
+
*
|
|
105
|
+
* @param definition Style definition that is being considered.
|
|
106
|
+
* @param block A block element from selection.
|
|
107
|
+
* @returns An array with the block that was passed as an argument if meets the criteria, null otherwise.
|
|
108
|
+
*/
|
|
109
|
+
_getAffectedBlocks(definition, block) {
|
|
110
|
+
if (!this._isStyleEnabledForBlock(definition, block)) {
|
|
111
|
+
return null;
|
|
112
|
+
}
|
|
113
|
+
return [block];
|
|
114
|
+
}
|
|
115
|
+
}
|