@ckeditor/ckeditor5-style 41.4.2 → 42.0.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/README.md +6 -0
- package/dist/index.js +379 -291
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -8,10 +8,39 @@ import { FocusTracker, KeystrokeHandler, first, logWarning } from '@ckeditor/cke
|
|
|
8
8
|
import { isObject } from 'lodash-es';
|
|
9
9
|
import { findAttributeRange, findAttributeRangeBound } from '@ckeditor/ckeditor5-typing/dist/index.js';
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
/**
|
|
12
|
+
* A class representing an individual button (style) in the grid. Renders a rich preview of the style.
|
|
13
|
+
*/ class StyleGridButtonView extends ButtonView {
|
|
14
|
+
/**
|
|
15
|
+
* Definition of the style the button will apply when executed.
|
|
16
|
+
*/ styleDefinition;
|
|
17
|
+
/**
|
|
18
|
+
* The view rendering the preview of the style.
|
|
19
|
+
*/ previewView;
|
|
12
20
|
/**
|
|
13
|
-
|
|
14
|
-
|
|
21
|
+
* Creates an instance of the {@link module:style/ui/stylegridbuttonview~StyleGridButtonView} class.
|
|
22
|
+
*
|
|
23
|
+
* @param locale The localization services instance.
|
|
24
|
+
* @param styleDefinition Definition of the style.
|
|
25
|
+
*/ constructor(locale, styleDefinition){
|
|
26
|
+
super(locale);
|
|
27
|
+
this.styleDefinition = styleDefinition;
|
|
28
|
+
this.previewView = this._createPreview();
|
|
29
|
+
this.set({
|
|
30
|
+
label: styleDefinition.name,
|
|
31
|
+
class: 'ck-style-grid__button',
|
|
32
|
+
withText: true
|
|
33
|
+
});
|
|
34
|
+
this.extendTemplate({
|
|
35
|
+
attributes: {
|
|
36
|
+
role: 'option'
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
this.children.add(this.previewView, 0);
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Creates the view representing the preview of the style.
|
|
43
|
+
*/ _createPreview() {
|
|
15
44
|
const previewView = new View(this.locale);
|
|
16
45
|
previewView.setTemplate({
|
|
17
46
|
tag: 'div',
|
|
@@ -31,65 +60,27 @@ class StyleGridButtonView extends ButtonView {
|
|
|
31
60
|
});
|
|
32
61
|
return previewView;
|
|
33
62
|
}
|
|
34
|
-
/**
|
|
35
|
-
* Creates an instance of the {@link module:style/ui/stylegridbuttonview~StyleGridButtonView} class.
|
|
36
|
-
*
|
|
37
|
-
* @param locale The localization services instance.
|
|
38
|
-
* @param styleDefinition Definition of the style.
|
|
39
|
-
*/ constructor(locale, styleDefinition){
|
|
40
|
-
super(locale);
|
|
41
|
-
this.styleDefinition = styleDefinition;
|
|
42
|
-
this.previewView = this._createPreview();
|
|
43
|
-
this.set({
|
|
44
|
-
label: styleDefinition.name,
|
|
45
|
-
class: 'ck-style-grid__button',
|
|
46
|
-
withText: true
|
|
47
|
-
});
|
|
48
|
-
this.extendTemplate({
|
|
49
|
-
attributes: {
|
|
50
|
-
role: 'option'
|
|
51
|
-
}
|
|
52
|
-
});
|
|
53
|
-
this.children.add(this.previewView, 0);
|
|
54
|
-
}
|
|
55
63
|
}
|
|
56
64
|
|
|
57
|
-
|
|
65
|
+
/**
|
|
66
|
+
* A class representing a grid of styles ({@link module:style/ui/stylegridbuttonview~StyleGridButtonView buttons}).
|
|
67
|
+
* Allows users to select a style.
|
|
68
|
+
*/ class StyleGridView extends View {
|
|
58
69
|
/**
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
super.render();
|
|
62
|
-
for (const child of this.children){
|
|
63
|
-
this.focusTracker.add(child.element);
|
|
64
|
-
}
|
|
65
|
-
addKeyboardHandlingForGrid({
|
|
66
|
-
keystrokeHandler: this.keystrokes,
|
|
67
|
-
focusTracker: this.focusTracker,
|
|
68
|
-
gridItems: this.children,
|
|
69
|
-
numberOfColumns: 3,
|
|
70
|
-
uiLanguageDirection: this.locale && this.locale.uiLanguageDirection
|
|
71
|
-
});
|
|
72
|
-
// Start listening for the keystrokes coming from the grid view.
|
|
73
|
-
this.keystrokes.listenTo(this.element);
|
|
74
|
-
}
|
|
70
|
+
* Tracks information about the DOM focus in the view.
|
|
71
|
+
*/ focusTracker;
|
|
75
72
|
/**
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
this.children.first.focus();
|
|
79
|
-
}
|
|
73
|
+
* An instance of the {@link module:utils/keystrokehandler~KeystrokeHandler}.
|
|
74
|
+
*/ keystrokes;
|
|
80
75
|
/**
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
super.destroy();
|
|
84
|
-
this.focusTracker.destroy();
|
|
85
|
-
this.keystrokes.destroy();
|
|
86
|
-
}
|
|
76
|
+
* A collection of style {@link module:style/ui/stylegridbuttonview~StyleGridButtonView buttons}.
|
|
77
|
+
*/ children;
|
|
87
78
|
/**
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
79
|
+
* Creates an instance of the {@link module:style/ui/stylegridview~StyleGridView} class.
|
|
80
|
+
*
|
|
81
|
+
* @param locale The localization services instance.
|
|
82
|
+
* @param styleDefinitions Definitions of the styles.
|
|
83
|
+
*/ constructor(locale, styleDefinitions){
|
|
93
84
|
super(locale);
|
|
94
85
|
this.focusTracker = new FocusTracker();
|
|
95
86
|
this.keystrokes = new KeystrokeHandler();
|
|
@@ -123,16 +114,55 @@ class StyleGridView extends View {
|
|
|
123
114
|
children: this.children
|
|
124
115
|
});
|
|
125
116
|
}
|
|
117
|
+
/**
|
|
118
|
+
* @inheritDoc
|
|
119
|
+
*/ render() {
|
|
120
|
+
super.render();
|
|
121
|
+
for (const child of this.children){
|
|
122
|
+
this.focusTracker.add(child.element);
|
|
123
|
+
}
|
|
124
|
+
addKeyboardHandlingForGrid({
|
|
125
|
+
keystrokeHandler: this.keystrokes,
|
|
126
|
+
focusTracker: this.focusTracker,
|
|
127
|
+
gridItems: this.children,
|
|
128
|
+
numberOfColumns: 3,
|
|
129
|
+
uiLanguageDirection: this.locale && this.locale.uiLanguageDirection
|
|
130
|
+
});
|
|
131
|
+
// Start listening for the keystrokes coming from the grid view.
|
|
132
|
+
this.keystrokes.listenTo(this.element);
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Focuses the first style button in the grid.
|
|
136
|
+
*/ focus() {
|
|
137
|
+
this.children.first.focus();
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* @inheritDoc
|
|
141
|
+
*/ destroy() {
|
|
142
|
+
super.destroy();
|
|
143
|
+
this.focusTracker.destroy();
|
|
144
|
+
this.keystrokes.destroy();
|
|
145
|
+
}
|
|
126
146
|
}
|
|
127
147
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
148
|
+
/**
|
|
149
|
+
* A class representing a group of styles (e.g. "block" or "inline").
|
|
150
|
+
*
|
|
151
|
+
* Renders a {@link module:style/ui/stylegridview~StyleGridView style grid} and a label.
|
|
152
|
+
*/ class StyleGroupView extends View {
|
|
153
|
+
/**
|
|
154
|
+
* The styles grid of the group.
|
|
155
|
+
*/ gridView;
|
|
156
|
+
/**
|
|
157
|
+
* The label of the group.
|
|
158
|
+
*/ labelView;
|
|
159
|
+
/**
|
|
160
|
+
* Creates an instance of the {@link module:style/ui/stylegroupview~StyleGroupView} class.
|
|
161
|
+
*
|
|
162
|
+
* @param locale The localization services instance.
|
|
163
|
+
* @param label The localized label of the group.
|
|
164
|
+
* @param styleDefinitions Definitions of the styles in the group.
|
|
165
|
+
*/ constructor(locale, label, styleDefinitions){
|
|
136
166
|
super(locale);
|
|
137
167
|
this.labelView = new LabelView(locale);
|
|
138
168
|
this.labelView.text = label;
|
|
@@ -155,35 +185,37 @@ class StyleGroupView extends View {
|
|
|
155
185
|
}
|
|
156
186
|
}
|
|
157
187
|
|
|
158
|
-
|
|
188
|
+
/**
|
|
189
|
+
* A class representing a panel with available content styles. It renders styles in button grids, grouped
|
|
190
|
+
* in categories.
|
|
191
|
+
*/ class StylePanelView extends View {
|
|
159
192
|
/**
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
super.render();
|
|
163
|
-
// Register the views as focusable.
|
|
164
|
-
this._focusables.add(this.blockStylesGroupView.gridView);
|
|
165
|
-
this._focusables.add(this.inlineStylesGroupView.gridView);
|
|
166
|
-
// Register the views in the focus tracker.
|
|
167
|
-
this.focusTracker.add(this.blockStylesGroupView.gridView.element);
|
|
168
|
-
this.focusTracker.add(this.inlineStylesGroupView.gridView.element);
|
|
169
|
-
this.keystrokes.listenTo(this.element);
|
|
170
|
-
}
|
|
193
|
+
* Tracks information about DOM focus in the panel.
|
|
194
|
+
*/ focusTracker;
|
|
171
195
|
/**
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
this._focusCycler.focusFirst();
|
|
175
|
-
}
|
|
196
|
+
* An instance of the {@link module:utils/keystrokehandler~KeystrokeHandler}.
|
|
197
|
+
*/ keystrokes;
|
|
176
198
|
/**
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
this._focusCycler.focusLast();
|
|
180
|
-
}
|
|
199
|
+
* A collection of panel children.
|
|
200
|
+
*/ children;
|
|
181
201
|
/**
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
202
|
+
* A view representing block styles group.
|
|
203
|
+
*/ blockStylesGroupView;
|
|
204
|
+
/**
|
|
205
|
+
* A view representing inline styles group
|
|
206
|
+
*/ inlineStylesGroupView;
|
|
207
|
+
/**
|
|
208
|
+
* A collection of views that can be focused in the panel.
|
|
209
|
+
*/ _focusables;
|
|
210
|
+
/**
|
|
211
|
+
* Helps cycling over {@link #_focusables} in the panel.
|
|
212
|
+
*/ _focusCycler;
|
|
213
|
+
/**
|
|
214
|
+
* Creates an instance of the {@link module:style/ui/stylegroupview~StyleGroupView} class.
|
|
215
|
+
*
|
|
216
|
+
* @param locale The localization services instance.
|
|
217
|
+
* @param styleDefinitions Normalized definitions of the styles.
|
|
218
|
+
*/ constructor(locale, styleDefinitions){
|
|
187
219
|
super(locale);
|
|
188
220
|
const t = locale.t;
|
|
189
221
|
this.focusTracker = new FocusTracker();
|
|
@@ -230,6 +262,28 @@ class StylePanelView extends View {
|
|
|
230
262
|
children: this.children
|
|
231
263
|
});
|
|
232
264
|
}
|
|
265
|
+
/**
|
|
266
|
+
* @inheritDoc
|
|
267
|
+
*/ render() {
|
|
268
|
+
super.render();
|
|
269
|
+
// Register the views as focusable.
|
|
270
|
+
this._focusables.add(this.blockStylesGroupView.gridView);
|
|
271
|
+
this._focusables.add(this.inlineStylesGroupView.gridView);
|
|
272
|
+
// Register the views in the focus tracker.
|
|
273
|
+
this.focusTracker.add(this.blockStylesGroupView.gridView.element);
|
|
274
|
+
this.focusTracker.add(this.inlineStylesGroupView.gridView.element);
|
|
275
|
+
this.keystrokes.listenTo(this.element);
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* Focuses the first focusable element in the panel.
|
|
279
|
+
*/ focus() {
|
|
280
|
+
this._focusCycler.focusFirst();
|
|
281
|
+
}
|
|
282
|
+
/**
|
|
283
|
+
* Focuses the last focusable element in the panel.
|
|
284
|
+
*/ focusLast() {
|
|
285
|
+
this._focusCycler.focusLast();
|
|
286
|
+
}
|
|
233
287
|
}
|
|
234
288
|
|
|
235
289
|
// These are intermediate element names that can't be rendered as style preview because they don't make sense standalone.
|
|
@@ -254,37 +308,51 @@ const NON_PREVIEWABLE_ELEMENT_NAMES = [
|
|
|
254
308
|
'tr'
|
|
255
309
|
];
|
|
256
310
|
class StyleUtils extends Plugin {
|
|
311
|
+
_htmlSupport;
|
|
257
312
|
/**
|
|
258
|
-
|
|
259
|
-
|
|
313
|
+
* @inheritDoc
|
|
314
|
+
*/ static get pluginName() {
|
|
260
315
|
return 'StyleUtils';
|
|
261
316
|
}
|
|
262
317
|
/**
|
|
263
|
-
|
|
264
|
-
|
|
318
|
+
* @inheritDoc
|
|
319
|
+
*/ constructor(editor){
|
|
320
|
+
super(editor);
|
|
321
|
+
this.decorate('isStyleEnabledForBlock');
|
|
322
|
+
this.decorate('isStyleActiveForBlock');
|
|
323
|
+
this.decorate('getAffectedBlocks');
|
|
324
|
+
this.decorate('isStyleEnabledForInlineSelection');
|
|
325
|
+
this.decorate('isStyleActiveForInlineSelection');
|
|
326
|
+
this.decorate('getAffectedInlineSelectable');
|
|
327
|
+
this.decorate('getStylePreview');
|
|
328
|
+
this.decorate('configureGHSDataFilter');
|
|
329
|
+
}
|
|
330
|
+
/**
|
|
331
|
+
* @inheritDoc
|
|
332
|
+
*/ init() {
|
|
265
333
|
this._htmlSupport = this.editor.plugins.get('GeneralHtmlSupport');
|
|
266
334
|
}
|
|
267
335
|
/**
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
336
|
+
* Normalizes {@link module:style/styleconfig~StyleConfig#definitions} in the configuration of the styles feature.
|
|
337
|
+
* The structure of normalized styles looks as follows:
|
|
338
|
+
*
|
|
339
|
+
* ```ts
|
|
340
|
+
* {
|
|
341
|
+
* block: [
|
|
342
|
+
* <module:style/style~StyleDefinition>,
|
|
343
|
+
* <module:style/style~StyleDefinition>,
|
|
344
|
+
* ...
|
|
345
|
+
* ],
|
|
346
|
+
* inline: [
|
|
347
|
+
* <module:style/style~StyleDefinition>,
|
|
348
|
+
* <module:style/style~StyleDefinition>,
|
|
349
|
+
* ...
|
|
350
|
+
* ]
|
|
351
|
+
* }
|
|
352
|
+
* ```
|
|
353
|
+
*
|
|
354
|
+
* @returns An object with normalized style definitions grouped into `block` and `inline` categories (arrays).
|
|
355
|
+
*/ normalizeConfig(dataSchema, styleDefinitions = []) {
|
|
288
356
|
const normalizedDefinitions = {
|
|
289
357
|
block: [],
|
|
290
358
|
inline: []
|
|
@@ -331,10 +399,10 @@ class StyleUtils extends Plugin {
|
|
|
331
399
|
return normalizedDefinitions;
|
|
332
400
|
}
|
|
333
401
|
/**
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
402
|
+
* Verifies if the given style is applicable to the provided block element.
|
|
403
|
+
*
|
|
404
|
+
* @internal
|
|
405
|
+
*/ isStyleEnabledForBlock(definition, block) {
|
|
338
406
|
const model = this.editor.model;
|
|
339
407
|
const attributeName = this._htmlSupport.getGhsAttributeNameForElement(definition.element);
|
|
340
408
|
if (!model.schema.checkAttribute(block, attributeName)) {
|
|
@@ -343,19 +411,19 @@ class StyleUtils extends Plugin {
|
|
|
343
411
|
return definition.modelElements.includes(block.name);
|
|
344
412
|
}
|
|
345
413
|
/**
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
414
|
+
* Returns true if the given style is applied to the specified block element.
|
|
415
|
+
*
|
|
416
|
+
* @internal
|
|
417
|
+
*/ isStyleActiveForBlock(definition, block) {
|
|
350
418
|
const attributeName = this._htmlSupport.getGhsAttributeNameForElement(definition.element);
|
|
351
419
|
const ghsAttributeValue = block.getAttribute(attributeName);
|
|
352
420
|
return this.hasAllClasses(ghsAttributeValue, definition.classes);
|
|
353
421
|
}
|
|
354
422
|
/**
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
423
|
+
* Returns an array of block elements that style should be applied to.
|
|
424
|
+
*
|
|
425
|
+
* @internal
|
|
426
|
+
*/ getAffectedBlocks(definition, block) {
|
|
359
427
|
if (definition.modelElements.includes(block.name)) {
|
|
360
428
|
return [
|
|
361
429
|
block
|
|
@@ -364,10 +432,10 @@ class StyleUtils extends Plugin {
|
|
|
364
432
|
return null;
|
|
365
433
|
}
|
|
366
434
|
/**
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
435
|
+
* Verifies if the given style is applicable to the provided document selection.
|
|
436
|
+
*
|
|
437
|
+
* @internal
|
|
438
|
+
*/ isStyleEnabledForInlineSelection(definition, selection) {
|
|
371
439
|
const model = this.editor.model;
|
|
372
440
|
for (const ghsAttributeName of definition.ghsAttributes){
|
|
373
441
|
if (model.schema.checkAttributeInSelection(selection, ghsAttributeName)) {
|
|
@@ -377,10 +445,10 @@ class StyleUtils extends Plugin {
|
|
|
377
445
|
return false;
|
|
378
446
|
}
|
|
379
447
|
/**
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
448
|
+
* Returns true if the given style is applied to the specified document selection.
|
|
449
|
+
*
|
|
450
|
+
* @internal
|
|
451
|
+
*/ isStyleActiveForInlineSelection(definition, selection) {
|
|
384
452
|
for (const ghsAttributeName of definition.ghsAttributes){
|
|
385
453
|
const ghsAttributeValue = this._getValueFromFirstAllowedNode(selection, ghsAttributeName);
|
|
386
454
|
if (this.hasAllClasses(ghsAttributeValue, definition.classes)) {
|
|
@@ -390,17 +458,17 @@ class StyleUtils extends Plugin {
|
|
|
390
458
|
return false;
|
|
391
459
|
}
|
|
392
460
|
/**
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
461
|
+
* Returns a selectable that given style should be applied to.
|
|
462
|
+
*
|
|
463
|
+
* @internal
|
|
464
|
+
*/ getAffectedInlineSelectable(definition, selection) {
|
|
397
465
|
return selection;
|
|
398
466
|
}
|
|
399
467
|
/**
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
468
|
+
* Returns the `TemplateDefinition` used by styles dropdown to render style preview.
|
|
469
|
+
*
|
|
470
|
+
* @internal
|
|
471
|
+
*/ getStylePreview(definition, children) {
|
|
404
472
|
const { element, classes } = definition;
|
|
405
473
|
return {
|
|
406
474
|
tag: isPreviewable(element) ? element : 'div',
|
|
@@ -411,32 +479,32 @@ class StyleUtils extends Plugin {
|
|
|
411
479
|
};
|
|
412
480
|
}
|
|
413
481
|
/**
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
482
|
+
* Verifies if all classes are present in the given GHS attribute.
|
|
483
|
+
*
|
|
484
|
+
* @internal
|
|
485
|
+
*/ hasAllClasses(ghsAttributeValue, classes) {
|
|
418
486
|
return isObject(ghsAttributeValue) && hasClassesProperty(ghsAttributeValue) && classes.every((className)=>ghsAttributeValue.classes.includes(className));
|
|
419
487
|
}
|
|
420
488
|
/**
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
489
|
+
* This is where the styles feature configures the GHS feature. This method translates normalized
|
|
490
|
+
* {@link module:style/styleconfig~StyleDefinition style definitions} to
|
|
491
|
+
* {@link module:engine/view/matcher~MatcherObjectPattern matcher patterns} and feeds them to the GHS
|
|
492
|
+
* {@link module:html-support/datafilter~DataFilter} plugin.
|
|
493
|
+
*
|
|
494
|
+
* @internal
|
|
495
|
+
*/ configureGHSDataFilter({ block, inline }) {
|
|
428
496
|
const ghsDataFilter = this.editor.plugins.get('DataFilter');
|
|
429
497
|
ghsDataFilter.loadAllowedConfig(block.map(normalizedStyleDefinitionToMatcherPattern));
|
|
430
498
|
ghsDataFilter.loadAllowedConfig(inline.map(normalizedStyleDefinitionToMatcherPattern));
|
|
431
499
|
}
|
|
432
500
|
/**
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
501
|
+
* Checks the attribute value of the first node in the selection that allows the attribute.
|
|
502
|
+
* For the collapsed selection, returns the selection attribute.
|
|
503
|
+
*
|
|
504
|
+
* @param selection The document selection.
|
|
505
|
+
* @param attributeName Name of the GHS attribute.
|
|
506
|
+
* @returns The attribute value.
|
|
507
|
+
*/ _getValueFromFirstAllowedNode(selection, attributeName) {
|
|
440
508
|
const model = this.editor.model;
|
|
441
509
|
const schema = model.schema;
|
|
442
510
|
if (selection.isCollapsed) {
|
|
@@ -451,19 +519,6 @@ class StyleUtils extends Plugin {
|
|
|
451
519
|
}
|
|
452
520
|
return null;
|
|
453
521
|
}
|
|
454
|
-
/**
|
|
455
|
-
* @inheritDoc
|
|
456
|
-
*/ constructor(editor){
|
|
457
|
-
super(editor);
|
|
458
|
-
this.decorate('isStyleEnabledForBlock');
|
|
459
|
-
this.decorate('isStyleActiveForBlock');
|
|
460
|
-
this.decorate('getAffectedBlocks');
|
|
461
|
-
this.decorate('isStyleEnabledForInlineSelection');
|
|
462
|
-
this.decorate('isStyleActiveForInlineSelection');
|
|
463
|
-
this.decorate('getAffectedInlineSelectable');
|
|
464
|
-
this.decorate('getStylePreview');
|
|
465
|
-
this.decorate('configureGHSDataFilter');
|
|
466
|
-
}
|
|
467
522
|
}
|
|
468
523
|
/**
|
|
469
524
|
* Checks if given object has `classes` property which is an array.
|
|
@@ -490,22 +545,27 @@ class StyleUtils extends Plugin {
|
|
|
490
545
|
};
|
|
491
546
|
}
|
|
492
547
|
|
|
493
|
-
|
|
548
|
+
/**
|
|
549
|
+
* The UI plugin of the style feature .
|
|
550
|
+
*
|
|
551
|
+
* It registers the `'style'` UI dropdown in the editor's {@link module:ui/componentfactory~ComponentFactory component factory}
|
|
552
|
+
* that displays a grid of styles and allows changing styles of the content.
|
|
553
|
+
*/ class StyleUI extends Plugin {
|
|
494
554
|
/**
|
|
495
|
-
|
|
496
|
-
|
|
555
|
+
* @inheritDoc
|
|
556
|
+
*/ static get pluginName() {
|
|
497
557
|
return 'StyleUI';
|
|
498
558
|
}
|
|
499
559
|
/**
|
|
500
|
-
|
|
501
|
-
|
|
560
|
+
* @inheritDoc
|
|
561
|
+
*/ static get requires() {
|
|
502
562
|
return [
|
|
503
563
|
StyleUtils
|
|
504
564
|
];
|
|
505
565
|
}
|
|
506
566
|
/**
|
|
507
|
-
|
|
508
|
-
|
|
567
|
+
* @inheritDoc
|
|
568
|
+
*/ init() {
|
|
509
569
|
const editor = this.editor;
|
|
510
570
|
const dataSchema = editor.plugins.get('DataSchema');
|
|
511
571
|
const styleUtils = editor.plugins.get('StyleUtils');
|
|
@@ -566,10 +626,32 @@ class StyleUI extends Plugin {
|
|
|
566
626
|
}
|
|
567
627
|
}
|
|
568
628
|
|
|
569
|
-
|
|
629
|
+
/**
|
|
630
|
+
* Style command.
|
|
631
|
+
*
|
|
632
|
+
* Applies and removes styles from selection and elements.
|
|
633
|
+
*/ class StyleCommand extends Command {
|
|
570
634
|
/**
|
|
571
|
-
|
|
572
|
-
|
|
635
|
+
* Normalized definitions of the styles.
|
|
636
|
+
*/ _styleDefinitions;
|
|
637
|
+
/**
|
|
638
|
+
* The StyleUtils plugin.
|
|
639
|
+
*/ _styleUtils;
|
|
640
|
+
/**
|
|
641
|
+
* Creates an instance of the command.
|
|
642
|
+
*
|
|
643
|
+
* @param editor Editor on which this command will be used.
|
|
644
|
+
* @param styleDefinitions Normalized definitions of the styles.
|
|
645
|
+
*/ constructor(editor, styleDefinitions){
|
|
646
|
+
super(editor);
|
|
647
|
+
this.set('value', []);
|
|
648
|
+
this.set('enabledStyles', []);
|
|
649
|
+
this._styleDefinitions = styleDefinitions;
|
|
650
|
+
this._styleUtils = this.editor.plugins.get(StyleUtils);
|
|
651
|
+
}
|
|
652
|
+
/**
|
|
653
|
+
* @inheritDoc
|
|
654
|
+
*/ refresh() {
|
|
573
655
|
const model = this.editor.model;
|
|
574
656
|
const selection = model.document.selection;
|
|
575
657
|
const value = new Set();
|
|
@@ -619,41 +701,41 @@ class StyleCommand extends Command {
|
|
|
619
701
|
this.value = this.isEnabled ? Array.from(value).sort() : [];
|
|
620
702
|
}
|
|
621
703
|
/**
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
704
|
+
* Executes the command – applies the style classes to the selection or removes it from the selection.
|
|
705
|
+
*
|
|
706
|
+
* If the command value already contains the requested style, it will remove the style classes. Otherwise, it will set it.
|
|
707
|
+
*
|
|
708
|
+
* The execution result differs, depending on the {@link module:engine/model/document~Document#selection} and the
|
|
709
|
+
* style type (inline or block):
|
|
710
|
+
*
|
|
711
|
+
* * When applying inline styles:
|
|
712
|
+
* * If the selection is on a range, the command applies the style classes to all nodes in that range.
|
|
713
|
+
* * If the selection is collapsed in a non-empty node, the command applies the style classes to the
|
|
714
|
+
* {@link module:engine/model/document~Document#selection}.
|
|
715
|
+
*
|
|
716
|
+
* * When applying block styles:
|
|
717
|
+
* * If the selection is on a range, the command applies the style classes to the nearest block parent element.
|
|
718
|
+
*
|
|
719
|
+
* @fires execute
|
|
720
|
+
* @param options Command options.
|
|
721
|
+
* @param options.styleName Style name matching the one defined in the
|
|
722
|
+
* {@link module:style/styleconfig~StyleConfig#definitions configuration}.
|
|
723
|
+
* @param options.forceValue Whether the command should add given style (`true`) or remove it (`false`) from the selection.
|
|
724
|
+
* If not set (default), the command will toggle the style basing on the first selected node. Note, that this will not force
|
|
725
|
+
* setting a style on an element that cannot receive given style.
|
|
726
|
+
*/ execute({ styleName, forceValue }) {
|
|
645
727
|
if (!this.enabledStyles.includes(styleName)) {
|
|
646
728
|
/**
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
729
|
+
* Style command can be executed only with a correct style name.
|
|
730
|
+
*
|
|
731
|
+
* This warning may be caused by:
|
|
732
|
+
*
|
|
733
|
+
* * passing a name that is not specified in the {@link module:style/styleconfig~StyleConfig#definitions configuration}
|
|
734
|
+
* (e.g. a CSS class name),
|
|
735
|
+
* * when trying to apply a style that is not allowed on a given element.
|
|
736
|
+
*
|
|
737
|
+
* @error style-command-executed-with-incorrect-style-name
|
|
738
|
+
*/ logWarning('style-command-executed-with-incorrect-style-name');
|
|
657
739
|
return;
|
|
658
740
|
}
|
|
659
741
|
const model = this.editor.model;
|
|
@@ -685,8 +767,8 @@ class StyleCommand extends Command {
|
|
|
685
767
|
});
|
|
686
768
|
}
|
|
687
769
|
/**
|
|
688
|
-
|
|
689
|
-
|
|
770
|
+
* Returns a set of elements that should be affected by the block-style change.
|
|
771
|
+
*/ _findAffectedBlocks(selectedBlocks, definition) {
|
|
690
772
|
const blocks = new Set();
|
|
691
773
|
for (const selectedBlock of selectedBlocks){
|
|
692
774
|
const ancestorBlocks = selectedBlock.getAncestors({
|
|
@@ -708,18 +790,6 @@ class StyleCommand extends Command {
|
|
|
708
790
|
}
|
|
709
791
|
return blocks;
|
|
710
792
|
}
|
|
711
|
-
/**
|
|
712
|
-
* Creates an instance of the command.
|
|
713
|
-
*
|
|
714
|
-
* @param editor Editor on which this command will be used.
|
|
715
|
-
* @param styleDefinitions Normalized definitions of the styles.
|
|
716
|
-
*/ constructor(editor, styleDefinitions){
|
|
717
|
-
super(editor);
|
|
718
|
-
this.set('value', []);
|
|
719
|
-
this.set('enabledStyles', []);
|
|
720
|
-
this._styleDefinitions = styleDefinitions;
|
|
721
|
-
this._styleUtils = this.editor.plugins.get(StyleUtils);
|
|
722
|
-
}
|
|
723
793
|
}
|
|
724
794
|
/**
|
|
725
795
|
* Returns classes that are defined only in the supplied definition and not in any other active definition. It's used
|
|
@@ -756,22 +826,25 @@ class StyleCommand extends Command {
|
|
|
756
826
|
}
|
|
757
827
|
|
|
758
828
|
class ListStyleSupport extends Plugin {
|
|
829
|
+
_listUtils;
|
|
830
|
+
_styleUtils;
|
|
831
|
+
_htmlSupport;
|
|
759
832
|
/**
|
|
760
|
-
|
|
761
|
-
|
|
833
|
+
* @inheritDoc
|
|
834
|
+
*/ static get pluginName() {
|
|
762
835
|
return 'ListStyleSupport';
|
|
763
836
|
}
|
|
764
837
|
/**
|
|
765
|
-
|
|
766
|
-
|
|
838
|
+
* @inheritDoc
|
|
839
|
+
*/ static get requires() {
|
|
767
840
|
return [
|
|
768
841
|
StyleUtils,
|
|
769
842
|
'GeneralHtmlSupport'
|
|
770
843
|
];
|
|
771
844
|
}
|
|
772
845
|
/**
|
|
773
|
-
|
|
774
|
-
|
|
846
|
+
* @inheritDoc
|
|
847
|
+
*/ init() {
|
|
775
848
|
const editor = this.editor;
|
|
776
849
|
if (!editor.plugins.has('ListEditing')) {
|
|
777
850
|
return;
|
|
@@ -815,8 +888,8 @@ class ListStyleSupport extends Plugin {
|
|
|
815
888
|
});
|
|
816
889
|
}
|
|
817
890
|
/**
|
|
818
|
-
|
|
819
|
-
|
|
891
|
+
* Verifies if the given style is applicable to the provided block element.
|
|
892
|
+
*/ _isStyleEnabledForBlock(definition, block) {
|
|
820
893
|
const model = this.editor.model;
|
|
821
894
|
if (![
|
|
822
895
|
'ol',
|
|
@@ -841,15 +914,15 @@ class ListStyleSupport extends Plugin {
|
|
|
841
914
|
}
|
|
842
915
|
}
|
|
843
916
|
/**
|
|
844
|
-
|
|
845
|
-
|
|
917
|
+
* Returns true if the given style is applied to the specified block element.
|
|
918
|
+
*/ _isStyleActiveForBlock(definition, block) {
|
|
846
919
|
const attributeName = this._htmlSupport.getGhsAttributeNameForElement(definition.element);
|
|
847
920
|
const ghsAttributeValue = block.getAttribute(attributeName);
|
|
848
921
|
return this._styleUtils.hasAllClasses(ghsAttributeValue, definition.classes);
|
|
849
922
|
}
|
|
850
923
|
/**
|
|
851
|
-
|
|
852
|
-
|
|
924
|
+
* Returns an array of block elements that style should be applied to.
|
|
925
|
+
*/ _getAffectedBlocks(definition, block) {
|
|
853
926
|
if (!this._isStyleEnabledForBlock(definition, block)) {
|
|
854
927
|
return null;
|
|
855
928
|
}
|
|
@@ -862,8 +935,8 @@ class ListStyleSupport extends Plugin {
|
|
|
862
935
|
}
|
|
863
936
|
}
|
|
864
937
|
/**
|
|
865
|
-
|
|
866
|
-
|
|
938
|
+
* Returns a view template definition for the style preview.
|
|
939
|
+
*/ _getStylePreview(definition, children) {
|
|
867
940
|
const { element, classes } = definition;
|
|
868
941
|
if (element == 'ol' || element == 'ul') {
|
|
869
942
|
return {
|
|
@@ -897,21 +970,23 @@ class ListStyleSupport extends Plugin {
|
|
|
897
970
|
}
|
|
898
971
|
|
|
899
972
|
class TableStyleSupport extends Plugin {
|
|
973
|
+
_tableUtils;
|
|
974
|
+
_styleUtils;
|
|
900
975
|
/**
|
|
901
|
-
|
|
902
|
-
|
|
976
|
+
* @inheritDoc
|
|
977
|
+
*/ static get pluginName() {
|
|
903
978
|
return 'TableStyleSupport';
|
|
904
979
|
}
|
|
905
980
|
/**
|
|
906
|
-
|
|
907
|
-
|
|
981
|
+
* @inheritDoc
|
|
982
|
+
*/ static get requires() {
|
|
908
983
|
return [
|
|
909
984
|
StyleUtils
|
|
910
985
|
];
|
|
911
986
|
}
|
|
912
987
|
/**
|
|
913
|
-
|
|
914
|
-
|
|
988
|
+
* @inheritDoc
|
|
989
|
+
*/ init() {
|
|
915
990
|
const editor = this.editor;
|
|
916
991
|
if (!editor.plugins.has('TableEditing')) {
|
|
917
992
|
return;
|
|
@@ -943,12 +1018,12 @@ class TableStyleSupport extends Plugin {
|
|
|
943
1018
|
});
|
|
944
1019
|
}
|
|
945
1020
|
/**
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
1021
|
+
* Checks if this plugin's custom logic should be applied for defintion-block pair.
|
|
1022
|
+
*
|
|
1023
|
+
* @param definition Style definition that is being considered.
|
|
1024
|
+
* @param block Block element to check if should be styled.
|
|
1025
|
+
* @returns True if the defintion-block pair meet the plugin criteria, false otherwise.
|
|
1026
|
+
*/ _isApplicable(definition, block) {
|
|
952
1027
|
if ([
|
|
953
1028
|
'td',
|
|
954
1029
|
'th'
|
|
@@ -964,12 +1039,12 @@ class TableStyleSupport extends Plugin {
|
|
|
964
1039
|
return false;
|
|
965
1040
|
}
|
|
966
1041
|
/**
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
1042
|
+
* Checks if the style definition should be applied to selected block.
|
|
1043
|
+
*
|
|
1044
|
+
* @param definition Style definition that is being considered.
|
|
1045
|
+
* @param block Block element to check if should be styled.
|
|
1046
|
+
* @returns True if the block should be style with the style description, false otherwise.
|
|
1047
|
+
*/ _isStyleEnabledForBlock(definition, block) {
|
|
973
1048
|
if ([
|
|
974
1049
|
'td',
|
|
975
1050
|
'th'
|
|
@@ -1000,12 +1075,12 @@ class TableStyleSupport extends Plugin {
|
|
|
1000
1075
|
/* istanbul ignore next -- @preserve */ return false;
|
|
1001
1076
|
}
|
|
1002
1077
|
/**
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1078
|
+
* Gets all blocks that the style should be applied to.
|
|
1079
|
+
*
|
|
1080
|
+
* @param definition Style definition that is being considered.
|
|
1081
|
+
* @param block A block element from selection.
|
|
1082
|
+
* @returns An array with the block that was passed as an argument if meets the criteria, null otherwise.
|
|
1083
|
+
*/ _getAffectedBlocks(definition, block) {
|
|
1009
1084
|
if (!this._isStyleEnabledForBlock(definition, block)) {
|
|
1010
1085
|
return null;
|
|
1011
1086
|
}
|
|
@@ -1016,22 +1091,24 @@ class TableStyleSupport extends Plugin {
|
|
|
1016
1091
|
}
|
|
1017
1092
|
|
|
1018
1093
|
class LinkStyleSupport extends Plugin {
|
|
1094
|
+
_styleUtils;
|
|
1095
|
+
_htmlSupport;
|
|
1019
1096
|
/**
|
|
1020
|
-
|
|
1021
|
-
|
|
1097
|
+
* @inheritDoc
|
|
1098
|
+
*/ static get pluginName() {
|
|
1022
1099
|
return 'LinkStyleSupport';
|
|
1023
1100
|
}
|
|
1024
1101
|
/**
|
|
1025
|
-
|
|
1026
|
-
|
|
1102
|
+
* @inheritDoc
|
|
1103
|
+
*/ static get requires() {
|
|
1027
1104
|
return [
|
|
1028
1105
|
StyleUtils,
|
|
1029
1106
|
'GeneralHtmlSupport'
|
|
1030
1107
|
];
|
|
1031
1108
|
}
|
|
1032
1109
|
/**
|
|
1033
|
-
|
|
1034
|
-
|
|
1110
|
+
* @inheritDoc
|
|
1111
|
+
*/ init() {
|
|
1035
1112
|
const editor = this.editor;
|
|
1036
1113
|
if (!editor.plugins.has('LinkEditing')) {
|
|
1037
1114
|
return;
|
|
@@ -1068,8 +1145,8 @@ class LinkStyleSupport extends Plugin {
|
|
|
1068
1145
|
});
|
|
1069
1146
|
}
|
|
1070
1147
|
/**
|
|
1071
|
-
|
|
1072
|
-
|
|
1148
|
+
* Verifies if the given style is applicable to the provided document selection.
|
|
1149
|
+
*/ _isStyleEnabled(definition, selection) {
|
|
1073
1150
|
const model = this.editor.model;
|
|
1074
1151
|
// Handle collapsed selection.
|
|
1075
1152
|
if (selection.isCollapsed) {
|
|
@@ -1086,8 +1163,8 @@ class LinkStyleSupport extends Plugin {
|
|
|
1086
1163
|
return false;
|
|
1087
1164
|
}
|
|
1088
1165
|
/**
|
|
1089
|
-
|
|
1090
|
-
|
|
1166
|
+
* Returns true if the given style is applied to the specified document selection.
|
|
1167
|
+
*/ _isStyleActive(definition, selection) {
|
|
1091
1168
|
const model = this.editor.model;
|
|
1092
1169
|
const attributeName = this._htmlSupport.getGhsAttributeNameForElement(definition.element);
|
|
1093
1170
|
// Handle collapsed selection.
|
|
@@ -1112,8 +1189,8 @@ class LinkStyleSupport extends Plugin {
|
|
|
1112
1189
|
return false;
|
|
1113
1190
|
}
|
|
1114
1191
|
/**
|
|
1115
|
-
|
|
1116
|
-
|
|
1192
|
+
* Returns a selectable that given style should be applied to.
|
|
1193
|
+
*/ _getAffectedSelectable(definition, selection) {
|
|
1117
1194
|
const model = this.editor.model;
|
|
1118
1195
|
// Handle collapsed selection.
|
|
1119
1196
|
if (selection.isCollapsed) {
|
|
@@ -1163,15 +1240,21 @@ class LinkStyleSupport extends Plugin {
|
|
|
1163
1240
|
return ranges;
|
|
1164
1241
|
}
|
|
1165
1242
|
|
|
1166
|
-
|
|
1243
|
+
/**
|
|
1244
|
+
* The style engine feature.
|
|
1245
|
+
*
|
|
1246
|
+
* It configures the {@glink features/html/general-html-support General HTML Support feature} based on
|
|
1247
|
+
* {@link module:style/styleconfig~StyleConfig#definitions configured style definitions} and introduces the
|
|
1248
|
+
* {@link module:style/stylecommand~StyleCommand style command} that applies styles to the content of the document.
|
|
1249
|
+
*/ class StyleEditing extends Plugin {
|
|
1167
1250
|
/**
|
|
1168
|
-
|
|
1169
|
-
|
|
1251
|
+
* @inheritDoc
|
|
1252
|
+
*/ static get pluginName() {
|
|
1170
1253
|
return 'StyleEditing';
|
|
1171
1254
|
}
|
|
1172
1255
|
/**
|
|
1173
|
-
|
|
1174
|
-
|
|
1256
|
+
* @inheritDoc
|
|
1257
|
+
*/ static get requires() {
|
|
1175
1258
|
return [
|
|
1176
1259
|
'GeneralHtmlSupport',
|
|
1177
1260
|
StyleUtils,
|
|
@@ -1181,8 +1264,8 @@ class StyleEditing extends Plugin {
|
|
|
1181
1264
|
];
|
|
1182
1265
|
}
|
|
1183
1266
|
/**
|
|
1184
|
-
|
|
1185
|
-
|
|
1267
|
+
* @inheritDoc
|
|
1268
|
+
*/ init() {
|
|
1186
1269
|
const editor = this.editor;
|
|
1187
1270
|
const dataSchema = editor.plugins.get('DataSchema');
|
|
1188
1271
|
const styleUtils = editor.plugins.get('StyleUtils');
|
|
@@ -1193,15 +1276,20 @@ class StyleEditing extends Plugin {
|
|
|
1193
1276
|
}
|
|
1194
1277
|
}
|
|
1195
1278
|
|
|
1196
|
-
|
|
1279
|
+
/**
|
|
1280
|
+
* The style plugin.
|
|
1281
|
+
*
|
|
1282
|
+
* This is a "glue" plugin that loads the {@link module:style/styleediting~StyleEditing style editing feature}
|
|
1283
|
+
* and {@link module:style/styleui~StyleUI style UI feature}.
|
|
1284
|
+
*/ class Style extends Plugin {
|
|
1197
1285
|
/**
|
|
1198
|
-
|
|
1199
|
-
|
|
1286
|
+
* @inheritDoc
|
|
1287
|
+
*/ static get pluginName() {
|
|
1200
1288
|
return 'Style';
|
|
1201
1289
|
}
|
|
1202
1290
|
/**
|
|
1203
|
-
|
|
1204
|
-
|
|
1291
|
+
* @inheritDoc
|
|
1292
|
+
*/ static get requires() {
|
|
1205
1293
|
return [
|
|
1206
1294
|
StyleEditing,
|
|
1207
1295
|
StyleUI
|