@ckeditor/ckeditor5-style 39.0.1 → 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/LICENSE.md +1 -1
- package/README.md +4 -4
- package/build/style.js.map +1 -0
- package/lang/translations/ar.po +1 -0
- package/lang/translations/bg.po +1 -0
- package/lang/translations/bn.po +1 -0
- package/lang/translations/ca.po +1 -0
- package/lang/translations/cs.po +1 -0
- package/lang/translations/da.po +1 -0
- package/lang/translations/de.po +1 -0
- package/lang/translations/el.po +1 -0
- package/lang/translations/en-au.po +1 -0
- package/lang/translations/en.po +1 -0
- package/lang/translations/es.po +1 -0
- package/lang/translations/et.po +1 -0
- package/lang/translations/fi.po +1 -0
- package/lang/translations/fr.po +1 -0
- package/lang/translations/gl.po +1 -0
- package/lang/translations/he.po +1 -0
- package/lang/translations/hi.po +1 -0
- package/lang/translations/hr.po +1 -0
- package/lang/translations/hu.po +1 -0
- package/lang/translations/id.po +1 -0
- package/lang/translations/it.po +1 -0
- package/lang/translations/ja.po +1 -0
- package/lang/translations/ko.po +1 -0
- package/lang/translations/lt.po +1 -0
- package/lang/translations/lv.po +1 -0
- package/lang/translations/ms.po +1 -0
- package/lang/translations/nl.po +1 -0
- package/lang/translations/no.po +1 -0
- package/lang/translations/pl.po +1 -0
- package/lang/translations/pt-br.po +1 -0
- package/lang/translations/pt.po +1 -0
- package/lang/translations/ro.po +1 -0
- package/lang/translations/ru.po +1 -0
- package/lang/translations/sk.po +1 -0
- package/lang/translations/sr-latn.po +1 -0
- package/lang/translations/sr.po +1 -0
- package/lang/translations/sv.po +1 -0
- package/lang/translations/th.po +1 -0
- package/lang/translations/tr.po +1 -0
- package/lang/translations/ug.po +1 -0
- package/lang/translations/uk.po +1 -0
- package/lang/translations/ur.po +1 -0
- package/lang/translations/vi.po +1 -0
- package/lang/translations/zh-cn.po +1 -0
- package/lang/translations/zh.po +1 -0
- package/package.json +2 -6
- 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/styleutils.js
CHANGED
|
@@ -1,268 +1,268 @@
|
|
|
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/styleutils
|
|
7
|
-
*/
|
|
8
|
-
import { Plugin } from 'ckeditor5/src/core';
|
|
9
|
-
import { isObject } from 'lodash-es';
|
|
10
|
-
// These are intermediate element names that can't be rendered as style preview because they don't make sense standalone.
|
|
11
|
-
const NON_PREVIEWABLE_ELEMENT_NAMES = [
|
|
12
|
-
'caption', 'colgroup', 'dd', 'dt', 'figcaption', 'legend', 'li', 'optgroup', 'option', 'rp',
|
|
13
|
-
'rt', 'summary', 'tbody', 'td', 'tfoot', 'th', 'thead', 'tr'
|
|
14
|
-
];
|
|
15
|
-
export default class StyleUtils extends Plugin {
|
|
16
|
-
/**
|
|
17
|
-
* @inheritDoc
|
|
18
|
-
*/
|
|
19
|
-
static get pluginName() {
|
|
20
|
-
return 'StyleUtils';
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* @inheritDoc
|
|
24
|
-
*/
|
|
25
|
-
constructor(editor) {
|
|
26
|
-
super(editor);
|
|
27
|
-
this.decorate('isStyleEnabledForBlock');
|
|
28
|
-
this.decorate('isStyleActiveForBlock');
|
|
29
|
-
this.decorate('getAffectedBlocks');
|
|
30
|
-
this.decorate('isStyleEnabledForInlineSelection');
|
|
31
|
-
this.decorate('isStyleActiveForInlineSelection');
|
|
32
|
-
this.decorate('getAffectedInlineSelectable');
|
|
33
|
-
this.decorate('getStylePreview');
|
|
34
|
-
this.decorate('configureGHSDataFilter');
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* @inheritDoc
|
|
38
|
-
*/
|
|
39
|
-
init() {
|
|
40
|
-
this._htmlSupport = this.editor.plugins.get('GeneralHtmlSupport');
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Normalizes {@link module:style/styleconfig~StyleConfig#definitions} in the configuration of the styles feature.
|
|
44
|
-
* The structure of normalized styles looks as follows:
|
|
45
|
-
*
|
|
46
|
-
* ```ts
|
|
47
|
-
* {
|
|
48
|
-
* block: [
|
|
49
|
-
* <module:style/style~StyleDefinition>,
|
|
50
|
-
* <module:style/style~StyleDefinition>,
|
|
51
|
-
* ...
|
|
52
|
-
* ],
|
|
53
|
-
* inline: [
|
|
54
|
-
* <module:style/style~StyleDefinition>,
|
|
55
|
-
* <module:style/style~StyleDefinition>,
|
|
56
|
-
* ...
|
|
57
|
-
* ]
|
|
58
|
-
* }
|
|
59
|
-
* ```
|
|
60
|
-
*
|
|
61
|
-
* @returns An object with normalized style definitions grouped into `block` and `inline` categories (arrays).
|
|
62
|
-
*/
|
|
63
|
-
normalizeConfig(dataSchema, styleDefinitions = []) {
|
|
64
|
-
const normalizedDefinitions = {
|
|
65
|
-
block: [],
|
|
66
|
-
inline: []
|
|
67
|
-
};
|
|
68
|
-
for (const definition of styleDefinitions) {
|
|
69
|
-
const modelElements = [];
|
|
70
|
-
const ghsAttributes = [];
|
|
71
|
-
for (const ghsDefinition of dataSchema.getDefinitionsForView(definition.element)) {
|
|
72
|
-
const appliesToBlock = 'appliesToBlock' in ghsDefinition ? ghsDefinition.appliesToBlock : false;
|
|
73
|
-
if (ghsDefinition.isBlock || appliesToBlock) {
|
|
74
|
-
if (typeof appliesToBlock == 'string') {
|
|
75
|
-
modelElements.push(appliesToBlock);
|
|
76
|
-
}
|
|
77
|
-
else if (ghsDefinition.isBlock) {
|
|
78
|
-
const ghsBlockDefinition = ghsDefinition;
|
|
79
|
-
modelElements.push(ghsDefinition.model);
|
|
80
|
-
if (ghsBlockDefinition.paragraphLikeModel) {
|
|
81
|
-
modelElements.push(ghsBlockDefinition.paragraphLikeModel);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
else {
|
|
86
|
-
ghsAttributes.push(ghsDefinition.model);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
const previewTemplate = this.getStylePreview(definition, [
|
|
90
|
-
{ text: 'AaBbCcDdEeFfGgHhIiJj' }
|
|
91
|
-
]);
|
|
92
|
-
if (modelElements.length) {
|
|
93
|
-
normalizedDefinitions.block.push({
|
|
94
|
-
...definition,
|
|
95
|
-
previewTemplate,
|
|
96
|
-
modelElements,
|
|
97
|
-
isBlock: true
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
else {
|
|
101
|
-
normalizedDefinitions.inline.push({
|
|
102
|
-
...definition,
|
|
103
|
-
previewTemplate,
|
|
104
|
-
ghsAttributes
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
return normalizedDefinitions;
|
|
109
|
-
}
|
|
110
|
-
/**
|
|
111
|
-
* Verifies if the given style is applicable to the provided block element.
|
|
112
|
-
*
|
|
113
|
-
* @internal
|
|
114
|
-
*/
|
|
115
|
-
isStyleEnabledForBlock(definition, block) {
|
|
116
|
-
const model = this.editor.model;
|
|
117
|
-
const attributeName = this._htmlSupport.getGhsAttributeNameForElement(definition.element);
|
|
118
|
-
if (!model.schema.checkAttribute(block, attributeName)) {
|
|
119
|
-
return false;
|
|
120
|
-
}
|
|
121
|
-
return definition.modelElements.includes(block.name);
|
|
122
|
-
}
|
|
123
|
-
/**
|
|
124
|
-
* Returns true if the given style is applied to the specified block element.
|
|
125
|
-
*
|
|
126
|
-
* @internal
|
|
127
|
-
*/
|
|
128
|
-
isStyleActiveForBlock(definition, block) {
|
|
129
|
-
const attributeName = this._htmlSupport.getGhsAttributeNameForElement(definition.element);
|
|
130
|
-
const ghsAttributeValue = block.getAttribute(attributeName);
|
|
131
|
-
return this.hasAllClasses(ghsAttributeValue, definition.classes);
|
|
132
|
-
}
|
|
133
|
-
/**
|
|
134
|
-
* Returns an array of block elements that style should be applied to.
|
|
135
|
-
*
|
|
136
|
-
* @internal
|
|
137
|
-
*/
|
|
138
|
-
getAffectedBlocks(definition, block) {
|
|
139
|
-
if (definition.modelElements.includes(block.name)) {
|
|
140
|
-
return [block];
|
|
141
|
-
}
|
|
142
|
-
return null;
|
|
143
|
-
}
|
|
144
|
-
/**
|
|
145
|
-
* Verifies if the given style is applicable to the provided document selection.
|
|
146
|
-
*
|
|
147
|
-
* @internal
|
|
148
|
-
*/
|
|
149
|
-
isStyleEnabledForInlineSelection(definition, selection) {
|
|
150
|
-
const model = this.editor.model;
|
|
151
|
-
for (const ghsAttributeName of definition.ghsAttributes) {
|
|
152
|
-
if (model.schema.checkAttributeInSelection(selection, ghsAttributeName)) {
|
|
153
|
-
return true;
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
return false;
|
|
157
|
-
}
|
|
158
|
-
/**
|
|
159
|
-
* Returns true if the given style is applied to the specified document selection.
|
|
160
|
-
*
|
|
161
|
-
* @internal
|
|
162
|
-
*/
|
|
163
|
-
isStyleActiveForInlineSelection(definition, selection) {
|
|
164
|
-
for (const ghsAttributeName of definition.ghsAttributes) {
|
|
165
|
-
const ghsAttributeValue = this._getValueFromFirstAllowedNode(selection, ghsAttributeName);
|
|
166
|
-
if (this.hasAllClasses(ghsAttributeValue, definition.classes)) {
|
|
167
|
-
return true;
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
return false;
|
|
171
|
-
}
|
|
172
|
-
/**
|
|
173
|
-
* Returns a selectable that given style should be applied to.
|
|
174
|
-
*
|
|
175
|
-
* @internal
|
|
176
|
-
*/
|
|
177
|
-
getAffectedInlineSelectable(definition, selection) {
|
|
178
|
-
return selection;
|
|
179
|
-
}
|
|
180
|
-
/**
|
|
181
|
-
* Returns the `TemplateDefinition` used by styles dropdown to render style preview.
|
|
182
|
-
*
|
|
183
|
-
* @internal
|
|
184
|
-
*/
|
|
185
|
-
getStylePreview(definition, children) {
|
|
186
|
-
const { element, classes } = definition;
|
|
187
|
-
return {
|
|
188
|
-
tag: isPreviewable(element) ? element : 'div',
|
|
189
|
-
attributes: {
|
|
190
|
-
class: classes
|
|
191
|
-
},
|
|
192
|
-
children
|
|
193
|
-
};
|
|
194
|
-
}
|
|
195
|
-
/**
|
|
196
|
-
* Verifies if all classes are present in the given GHS attribute.
|
|
197
|
-
*
|
|
198
|
-
* @internal
|
|
199
|
-
*/
|
|
200
|
-
hasAllClasses(ghsAttributeValue, classes) {
|
|
201
|
-
return isObject(ghsAttributeValue) &&
|
|
202
|
-
hasClassesProperty(ghsAttributeValue) &&
|
|
203
|
-
classes.every(className => ghsAttributeValue.classes.includes(className));
|
|
204
|
-
}
|
|
205
|
-
/**
|
|
206
|
-
* This is where the styles feature configures the GHS feature. This method translates normalized
|
|
207
|
-
* {@link module:style/styleconfig~StyleDefinition style definitions} to
|
|
208
|
-
* {@link module:engine/view/matcher~MatcherObjectPattern matcher patterns} and feeds them to the GHS
|
|
209
|
-
* {@link module:html-support/datafilter~DataFilter} plugin.
|
|
210
|
-
*
|
|
211
|
-
* @internal
|
|
212
|
-
*/
|
|
213
|
-
configureGHSDataFilter({ block, inline }) {
|
|
214
|
-
const ghsDataFilter = this.editor.plugins.get('DataFilter');
|
|
215
|
-
ghsDataFilter.loadAllowedConfig(block.map(normalizedStyleDefinitionToMatcherPattern));
|
|
216
|
-
ghsDataFilter.loadAllowedConfig(inline.map(normalizedStyleDefinitionToMatcherPattern));
|
|
217
|
-
}
|
|
218
|
-
/**
|
|
219
|
-
* Checks the attribute value of the first node in the selection that allows the attribute.
|
|
220
|
-
* For the collapsed selection, returns the selection attribute.
|
|
221
|
-
*
|
|
222
|
-
* @param selection The document selection.
|
|
223
|
-
* @param attributeName Name of the GHS attribute.
|
|
224
|
-
* @returns The attribute value.
|
|
225
|
-
*/
|
|
226
|
-
_getValueFromFirstAllowedNode(selection, attributeName) {
|
|
227
|
-
const model = this.editor.model;
|
|
228
|
-
const schema = model.schema;
|
|
229
|
-
if (selection.isCollapsed) {
|
|
230
|
-
return selection.getAttribute(attributeName);
|
|
231
|
-
}
|
|
232
|
-
for (const range of selection.getRanges()) {
|
|
233
|
-
for (const item of range.getItems()) {
|
|
234
|
-
if (schema.checkAttribute(item, attributeName)) {
|
|
235
|
-
return item.getAttribute(attributeName);
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
return null;
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
/**
|
|
243
|
-
* Checks if given object has `classes` property which is an array.
|
|
244
|
-
*
|
|
245
|
-
* @param obj Object to check.
|
|
246
|
-
*/
|
|
247
|
-
function hasClassesProperty(obj) {
|
|
248
|
-
return Boolean(obj.classes) && Array.isArray(obj.classes);
|
|
249
|
-
}
|
|
250
|
-
/**
|
|
251
|
-
* Decides whether an element should be created in the preview or a substitute `<div>` should
|
|
252
|
-
* be used instead. This avoids previewing a standalone `<td>`, `<li>`, etc. without a parent.
|
|
253
|
-
*
|
|
254
|
-
* @param elementName Name of the element
|
|
255
|
-
* @returns Boolean indicating whether the element can be rendered.
|
|
256
|
-
*/
|
|
257
|
-
function isPreviewable(elementName) {
|
|
258
|
-
return !NON_PREVIEWABLE_ELEMENT_NAMES.includes(elementName);
|
|
259
|
-
}
|
|
260
|
-
/**
|
|
261
|
-
* Translates a normalized style definition to a view matcher pattern.
|
|
262
|
-
*/
|
|
263
|
-
function normalizedStyleDefinitionToMatcherPattern({ element, classes }) {
|
|
264
|
-
return {
|
|
265
|
-
name: element,
|
|
266
|
-
classes
|
|
267
|
-
};
|
|
268
|
-
}
|
|
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/styleutils
|
|
7
|
+
*/
|
|
8
|
+
import { Plugin } from 'ckeditor5/src/core';
|
|
9
|
+
import { isObject } from 'lodash-es';
|
|
10
|
+
// These are intermediate element names that can't be rendered as style preview because they don't make sense standalone.
|
|
11
|
+
const NON_PREVIEWABLE_ELEMENT_NAMES = [
|
|
12
|
+
'caption', 'colgroup', 'dd', 'dt', 'figcaption', 'legend', 'li', 'optgroup', 'option', 'rp',
|
|
13
|
+
'rt', 'summary', 'tbody', 'td', 'tfoot', 'th', 'thead', 'tr'
|
|
14
|
+
];
|
|
15
|
+
export default class StyleUtils extends Plugin {
|
|
16
|
+
/**
|
|
17
|
+
* @inheritDoc
|
|
18
|
+
*/
|
|
19
|
+
static get pluginName() {
|
|
20
|
+
return 'StyleUtils';
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* @inheritDoc
|
|
24
|
+
*/
|
|
25
|
+
constructor(editor) {
|
|
26
|
+
super(editor);
|
|
27
|
+
this.decorate('isStyleEnabledForBlock');
|
|
28
|
+
this.decorate('isStyleActiveForBlock');
|
|
29
|
+
this.decorate('getAffectedBlocks');
|
|
30
|
+
this.decorate('isStyleEnabledForInlineSelection');
|
|
31
|
+
this.decorate('isStyleActiveForInlineSelection');
|
|
32
|
+
this.decorate('getAffectedInlineSelectable');
|
|
33
|
+
this.decorate('getStylePreview');
|
|
34
|
+
this.decorate('configureGHSDataFilter');
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* @inheritDoc
|
|
38
|
+
*/
|
|
39
|
+
init() {
|
|
40
|
+
this._htmlSupport = this.editor.plugins.get('GeneralHtmlSupport');
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Normalizes {@link module:style/styleconfig~StyleConfig#definitions} in the configuration of the styles feature.
|
|
44
|
+
* The structure of normalized styles looks as follows:
|
|
45
|
+
*
|
|
46
|
+
* ```ts
|
|
47
|
+
* {
|
|
48
|
+
* block: [
|
|
49
|
+
* <module:style/style~StyleDefinition>,
|
|
50
|
+
* <module:style/style~StyleDefinition>,
|
|
51
|
+
* ...
|
|
52
|
+
* ],
|
|
53
|
+
* inline: [
|
|
54
|
+
* <module:style/style~StyleDefinition>,
|
|
55
|
+
* <module:style/style~StyleDefinition>,
|
|
56
|
+
* ...
|
|
57
|
+
* ]
|
|
58
|
+
* }
|
|
59
|
+
* ```
|
|
60
|
+
*
|
|
61
|
+
* @returns An object with normalized style definitions grouped into `block` and `inline` categories (arrays).
|
|
62
|
+
*/
|
|
63
|
+
normalizeConfig(dataSchema, styleDefinitions = []) {
|
|
64
|
+
const normalizedDefinitions = {
|
|
65
|
+
block: [],
|
|
66
|
+
inline: []
|
|
67
|
+
};
|
|
68
|
+
for (const definition of styleDefinitions) {
|
|
69
|
+
const modelElements = [];
|
|
70
|
+
const ghsAttributes = [];
|
|
71
|
+
for (const ghsDefinition of dataSchema.getDefinitionsForView(definition.element)) {
|
|
72
|
+
const appliesToBlock = 'appliesToBlock' in ghsDefinition ? ghsDefinition.appliesToBlock : false;
|
|
73
|
+
if (ghsDefinition.isBlock || appliesToBlock) {
|
|
74
|
+
if (typeof appliesToBlock == 'string') {
|
|
75
|
+
modelElements.push(appliesToBlock);
|
|
76
|
+
}
|
|
77
|
+
else if (ghsDefinition.isBlock) {
|
|
78
|
+
const ghsBlockDefinition = ghsDefinition;
|
|
79
|
+
modelElements.push(ghsDefinition.model);
|
|
80
|
+
if (ghsBlockDefinition.paragraphLikeModel) {
|
|
81
|
+
modelElements.push(ghsBlockDefinition.paragraphLikeModel);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
ghsAttributes.push(ghsDefinition.model);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
const previewTemplate = this.getStylePreview(definition, [
|
|
90
|
+
{ text: 'AaBbCcDdEeFfGgHhIiJj' }
|
|
91
|
+
]);
|
|
92
|
+
if (modelElements.length) {
|
|
93
|
+
normalizedDefinitions.block.push({
|
|
94
|
+
...definition,
|
|
95
|
+
previewTemplate,
|
|
96
|
+
modelElements,
|
|
97
|
+
isBlock: true
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
normalizedDefinitions.inline.push({
|
|
102
|
+
...definition,
|
|
103
|
+
previewTemplate,
|
|
104
|
+
ghsAttributes
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return normalizedDefinitions;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Verifies if the given style is applicable to the provided block element.
|
|
112
|
+
*
|
|
113
|
+
* @internal
|
|
114
|
+
*/
|
|
115
|
+
isStyleEnabledForBlock(definition, block) {
|
|
116
|
+
const model = this.editor.model;
|
|
117
|
+
const attributeName = this._htmlSupport.getGhsAttributeNameForElement(definition.element);
|
|
118
|
+
if (!model.schema.checkAttribute(block, attributeName)) {
|
|
119
|
+
return false;
|
|
120
|
+
}
|
|
121
|
+
return definition.modelElements.includes(block.name);
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Returns true if the given style is applied to the specified block element.
|
|
125
|
+
*
|
|
126
|
+
* @internal
|
|
127
|
+
*/
|
|
128
|
+
isStyleActiveForBlock(definition, block) {
|
|
129
|
+
const attributeName = this._htmlSupport.getGhsAttributeNameForElement(definition.element);
|
|
130
|
+
const ghsAttributeValue = block.getAttribute(attributeName);
|
|
131
|
+
return this.hasAllClasses(ghsAttributeValue, definition.classes);
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Returns an array of block elements that style should be applied to.
|
|
135
|
+
*
|
|
136
|
+
* @internal
|
|
137
|
+
*/
|
|
138
|
+
getAffectedBlocks(definition, block) {
|
|
139
|
+
if (definition.modelElements.includes(block.name)) {
|
|
140
|
+
return [block];
|
|
141
|
+
}
|
|
142
|
+
return null;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Verifies if the given style is applicable to the provided document selection.
|
|
146
|
+
*
|
|
147
|
+
* @internal
|
|
148
|
+
*/
|
|
149
|
+
isStyleEnabledForInlineSelection(definition, selection) {
|
|
150
|
+
const model = this.editor.model;
|
|
151
|
+
for (const ghsAttributeName of definition.ghsAttributes) {
|
|
152
|
+
if (model.schema.checkAttributeInSelection(selection, ghsAttributeName)) {
|
|
153
|
+
return true;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
return false;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Returns true if the given style is applied to the specified document selection.
|
|
160
|
+
*
|
|
161
|
+
* @internal
|
|
162
|
+
*/
|
|
163
|
+
isStyleActiveForInlineSelection(definition, selection) {
|
|
164
|
+
for (const ghsAttributeName of definition.ghsAttributes) {
|
|
165
|
+
const ghsAttributeValue = this._getValueFromFirstAllowedNode(selection, ghsAttributeName);
|
|
166
|
+
if (this.hasAllClasses(ghsAttributeValue, definition.classes)) {
|
|
167
|
+
return true;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
return false;
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Returns a selectable that given style should be applied to.
|
|
174
|
+
*
|
|
175
|
+
* @internal
|
|
176
|
+
*/
|
|
177
|
+
getAffectedInlineSelectable(definition, selection) {
|
|
178
|
+
return selection;
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Returns the `TemplateDefinition` used by styles dropdown to render style preview.
|
|
182
|
+
*
|
|
183
|
+
* @internal
|
|
184
|
+
*/
|
|
185
|
+
getStylePreview(definition, children) {
|
|
186
|
+
const { element, classes } = definition;
|
|
187
|
+
return {
|
|
188
|
+
tag: isPreviewable(element) ? element : 'div',
|
|
189
|
+
attributes: {
|
|
190
|
+
class: classes
|
|
191
|
+
},
|
|
192
|
+
children
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Verifies if all classes are present in the given GHS attribute.
|
|
197
|
+
*
|
|
198
|
+
* @internal
|
|
199
|
+
*/
|
|
200
|
+
hasAllClasses(ghsAttributeValue, classes) {
|
|
201
|
+
return isObject(ghsAttributeValue) &&
|
|
202
|
+
hasClassesProperty(ghsAttributeValue) &&
|
|
203
|
+
classes.every(className => ghsAttributeValue.classes.includes(className));
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* This is where the styles feature configures the GHS feature. This method translates normalized
|
|
207
|
+
* {@link module:style/styleconfig~StyleDefinition style definitions} to
|
|
208
|
+
* {@link module:engine/view/matcher~MatcherObjectPattern matcher patterns} and feeds them to the GHS
|
|
209
|
+
* {@link module:html-support/datafilter~DataFilter} plugin.
|
|
210
|
+
*
|
|
211
|
+
* @internal
|
|
212
|
+
*/
|
|
213
|
+
configureGHSDataFilter({ block, inline }) {
|
|
214
|
+
const ghsDataFilter = this.editor.plugins.get('DataFilter');
|
|
215
|
+
ghsDataFilter.loadAllowedConfig(block.map(normalizedStyleDefinitionToMatcherPattern));
|
|
216
|
+
ghsDataFilter.loadAllowedConfig(inline.map(normalizedStyleDefinitionToMatcherPattern));
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Checks the attribute value of the first node in the selection that allows the attribute.
|
|
220
|
+
* For the collapsed selection, returns the selection attribute.
|
|
221
|
+
*
|
|
222
|
+
* @param selection The document selection.
|
|
223
|
+
* @param attributeName Name of the GHS attribute.
|
|
224
|
+
* @returns The attribute value.
|
|
225
|
+
*/
|
|
226
|
+
_getValueFromFirstAllowedNode(selection, attributeName) {
|
|
227
|
+
const model = this.editor.model;
|
|
228
|
+
const schema = model.schema;
|
|
229
|
+
if (selection.isCollapsed) {
|
|
230
|
+
return selection.getAttribute(attributeName);
|
|
231
|
+
}
|
|
232
|
+
for (const range of selection.getRanges()) {
|
|
233
|
+
for (const item of range.getItems()) {
|
|
234
|
+
if (schema.checkAttribute(item, attributeName)) {
|
|
235
|
+
return item.getAttribute(attributeName);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
return null;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* Checks if given object has `classes` property which is an array.
|
|
244
|
+
*
|
|
245
|
+
* @param obj Object to check.
|
|
246
|
+
*/
|
|
247
|
+
function hasClassesProperty(obj) {
|
|
248
|
+
return Boolean(obj.classes) && Array.isArray(obj.classes);
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Decides whether an element should be created in the preview or a substitute `<div>` should
|
|
252
|
+
* be used instead. This avoids previewing a standalone `<td>`, `<li>`, etc. without a parent.
|
|
253
|
+
*
|
|
254
|
+
* @param elementName Name of the element
|
|
255
|
+
* @returns Boolean indicating whether the element can be rendered.
|
|
256
|
+
*/
|
|
257
|
+
function isPreviewable(elementName) {
|
|
258
|
+
return !NON_PREVIEWABLE_ELEMENT_NAMES.includes(elementName);
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* Translates a normalized style definition to a view matcher pattern.
|
|
262
|
+
*/
|
|
263
|
+
function normalizedStyleDefinitionToMatcherPattern({ element, classes }) {
|
|
264
|
+
return {
|
|
265
|
+
name: element,
|
|
266
|
+
classes
|
|
267
|
+
};
|
|
268
|
+
}
|
|
@@ -1,34 +1,34 @@
|
|
|
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/ui/stylegridbuttonview
|
|
7
|
-
*/
|
|
8
|
-
import type { Locale } from 'ckeditor5/src/utils';
|
|
9
|
-
import { ButtonView, View } from 'ckeditor5/src/ui';
|
|
10
|
-
import type { NormalizedStyleDefinition } from '../styleutils';
|
|
11
|
-
/**
|
|
12
|
-
* A class representing an individual button (style) in the grid. Renders a rich preview of the style.
|
|
13
|
-
*/
|
|
14
|
-
export default class StyleGridButtonView extends ButtonView {
|
|
15
|
-
/**
|
|
16
|
-
* Definition of the style the button will apply when executed.
|
|
17
|
-
*/
|
|
18
|
-
readonly styleDefinition: NormalizedStyleDefinition;
|
|
19
|
-
/**
|
|
20
|
-
* The view rendering the preview of the style.
|
|
21
|
-
*/
|
|
22
|
-
readonly previewView: View;
|
|
23
|
-
/**
|
|
24
|
-
* Creates an instance of the {@link module:style/ui/stylegridbuttonview~StyleGridButtonView} class.
|
|
25
|
-
*
|
|
26
|
-
* @param locale The localization services instance.
|
|
27
|
-
* @param styleDefinition Definition of the style.
|
|
28
|
-
*/
|
|
29
|
-
constructor(locale: Locale, styleDefinition: NormalizedStyleDefinition);
|
|
30
|
-
/**
|
|
31
|
-
* Creates the view representing the preview of the style.
|
|
32
|
-
*/
|
|
33
|
-
private _createPreview;
|
|
34
|
-
}
|
|
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/ui/stylegridbuttonview
|
|
7
|
+
*/
|
|
8
|
+
import type { Locale } from 'ckeditor5/src/utils';
|
|
9
|
+
import { ButtonView, View } from 'ckeditor5/src/ui';
|
|
10
|
+
import type { NormalizedStyleDefinition } from '../styleutils';
|
|
11
|
+
/**
|
|
12
|
+
* A class representing an individual button (style) in the grid. Renders a rich preview of the style.
|
|
13
|
+
*/
|
|
14
|
+
export default class StyleGridButtonView extends ButtonView {
|
|
15
|
+
/**
|
|
16
|
+
* Definition of the style the button will apply when executed.
|
|
17
|
+
*/
|
|
18
|
+
readonly styleDefinition: NormalizedStyleDefinition;
|
|
19
|
+
/**
|
|
20
|
+
* The view rendering the preview of the style.
|
|
21
|
+
*/
|
|
22
|
+
readonly previewView: View;
|
|
23
|
+
/**
|
|
24
|
+
* Creates an instance of the {@link module:style/ui/stylegridbuttonview~StyleGridButtonView} class.
|
|
25
|
+
*
|
|
26
|
+
* @param locale The localization services instance.
|
|
27
|
+
* @param styleDefinition Definition of the style.
|
|
28
|
+
*/
|
|
29
|
+
constructor(locale: Locale, styleDefinition: NormalizedStyleDefinition);
|
|
30
|
+
/**
|
|
31
|
+
* Creates the view representing the preview of the style.
|
|
32
|
+
*/
|
|
33
|
+
private _createPreview;
|
|
34
|
+
}
|