@ckeditor/ckeditor5-heading 47.4.0-alpha.3 → 47.4.0-alpha.5
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/heading.js +1 -1
- package/dist/index.js +21 -51
- package/dist/index.js.map +1 -1
- package/package.json +8 -8
- package/src/title.d.ts +4 -4
- package/src/title.js +21 -52
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ckeditor/ckeditor5-heading",
|
|
3
|
-
"version": "47.4.0-alpha.
|
|
3
|
+
"version": "47.4.0-alpha.5",
|
|
4
4
|
"description": "Headings feature for CKEditor 5.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ckeditor",
|
|
@@ -13,13 +13,13 @@
|
|
|
13
13
|
"type": "module",
|
|
14
14
|
"main": "src/index.js",
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@ckeditor/ckeditor5-core": "47.4.0-alpha.
|
|
17
|
-
"@ckeditor/ckeditor5-engine": "47.4.0-alpha.
|
|
18
|
-
"@ckeditor/ckeditor5-icons": "47.4.0-alpha.
|
|
19
|
-
"@ckeditor/ckeditor5-paragraph": "47.4.0-alpha.
|
|
20
|
-
"@ckeditor/ckeditor5-ui": "47.4.0-alpha.
|
|
21
|
-
"@ckeditor/ckeditor5-utils": "47.4.0-alpha.
|
|
22
|
-
"ckeditor5": "47.4.0-alpha.
|
|
16
|
+
"@ckeditor/ckeditor5-core": "47.4.0-alpha.5",
|
|
17
|
+
"@ckeditor/ckeditor5-engine": "47.4.0-alpha.5",
|
|
18
|
+
"@ckeditor/ckeditor5-icons": "47.4.0-alpha.5",
|
|
19
|
+
"@ckeditor/ckeditor5-paragraph": "47.4.0-alpha.5",
|
|
20
|
+
"@ckeditor/ckeditor5-ui": "47.4.0-alpha.5",
|
|
21
|
+
"@ckeditor/ckeditor5-utils": "47.4.0-alpha.5",
|
|
22
|
+
"ckeditor5": "47.4.0-alpha.5"
|
|
23
23
|
},
|
|
24
24
|
"author": "CKSource (http://cksource.com/)",
|
|
25
25
|
"license": "SEE LICENSE IN LICENSE.md",
|
package/src/title.d.ts
CHANGED
|
@@ -35,10 +35,10 @@ export declare class Title extends Plugin {
|
|
|
35
35
|
init(): void;
|
|
36
36
|
/**
|
|
37
37
|
* Returns the title of the document. Note that because this plugin does not allow any formatting inside
|
|
38
|
-
* the
|
|
38
|
+
* the title element, the output of this method will be a plain text, with no HTML tags.
|
|
39
39
|
*
|
|
40
40
|
* It is not recommended to use this method together with features that insert markers to the
|
|
41
|
-
* data output, like comments or track changes features. If such markers start in the
|
|
41
|
+
* data output, like comments or track changes features. If such markers start in the title and end in the
|
|
42
42
|
* body, the result of this method might be incorrect.
|
|
43
43
|
*
|
|
44
44
|
* @param options Additional configuration passed to the conversion process.
|
|
@@ -68,8 +68,8 @@ export declare class Title extends Plugin {
|
|
|
68
68
|
*/
|
|
69
69
|
private _fixTitleContent;
|
|
70
70
|
/**
|
|
71
|
-
* Model post-fixer callback that creates a
|
|
72
|
-
* takes care of the correct position of it and removes additional
|
|
71
|
+
* Model post-fixer callback that creates a title element when it is missing,
|
|
72
|
+
* takes care of the correct position of it and removes additional title elements.
|
|
73
73
|
*/
|
|
74
74
|
private _fixTitleElement;
|
|
75
75
|
/**
|
package/src/title.js
CHANGED
|
@@ -9,7 +9,7 @@ import { Plugin } from 'ckeditor5/src/core.js';
|
|
|
9
9
|
import { first } from 'ckeditor5/src/utils.js';
|
|
10
10
|
import { ViewDowncastWriter, enableViewPlaceholder, hideViewPlaceholder, needsViewPlaceholder, showViewPlaceholder } from 'ckeditor5/src/engine.js';
|
|
11
11
|
// A list of element names that should be treated by the Title plugin as title-like.
|
|
12
|
-
// This means that an element of a type from this list will be changed to a
|
|
12
|
+
// This means that an element of a type from this list will be changed to a title element
|
|
13
13
|
// when it is the first element in the root.
|
|
14
14
|
const titleLikeElements = new Set(['paragraph', 'heading1', 'heading2', 'heading3', 'heading4', 'heading5', 'heading6']);
|
|
15
15
|
/**
|
|
@@ -47,7 +47,7 @@ export class Title extends Plugin {
|
|
|
47
47
|
init() {
|
|
48
48
|
const editor = this.editor;
|
|
49
49
|
const model = editor.model;
|
|
50
|
-
// To use the schema for disabling some features when the selection is inside the
|
|
50
|
+
// To use the schema for disabling some features when the selection is inside the title element
|
|
51
51
|
// it is needed to create the following structure:
|
|
52
52
|
//
|
|
53
53
|
// <title>
|
|
@@ -58,13 +58,13 @@ export class Title extends Plugin {
|
|
|
58
58
|
model.schema.register('title', { isBlock: true, allowIn: '$root' });
|
|
59
59
|
model.schema.register('title-content', { isBlock: true, allowIn: 'title', allowAttributes: ['alignment'] });
|
|
60
60
|
model.schema.extend('$text', { allowIn: 'title-content' });
|
|
61
|
-
// Disallow all attributes in `title-content
|
|
61
|
+
// Disallow all attributes in `title-content`.
|
|
62
62
|
model.schema.addAttributeCheck(context => {
|
|
63
63
|
if (context.endsWith('title-content $text')) {
|
|
64
64
|
return false;
|
|
65
65
|
}
|
|
66
66
|
});
|
|
67
|
-
// Because `title` is represented by two elements
|
|
67
|
+
// Because `title` is represented by two elements in the model
|
|
68
68
|
// but only one in the view, it is needed to adjust Mapper.
|
|
69
69
|
editor.editing.mapper.on('modelToViewPosition', mapModelPositionToView(editor.editing.view));
|
|
70
70
|
editor.data.mapper.on('modelToViewPosition', mapModelPositionToView(editor.editing.view));
|
|
@@ -73,37 +73,6 @@ export class Title extends Plugin {
|
|
|
73
73
|
editor.conversion.for('downcast').add(dispatcher => dispatcher.on('insert:title', (evt, data, conversionApi) => {
|
|
74
74
|
conversionApi.consumable.consume(data.item, evt.name);
|
|
75
75
|
}));
|
|
76
|
-
// This converter intercepts attribute changes on `title` and redirects them to `title-content`.
|
|
77
|
-
//
|
|
78
|
-
// The `title` element in the model doesn't have a corresponding view element, only `title-content`
|
|
79
|
-
// is converted to `<h1>`. Setting an attribute on `title` would cause a downcast conversion error
|
|
80
|
-
// because there's no view element to apply it to.
|
|
81
|
-
editor.conversion.for('downcast').add(dispatcher => {
|
|
82
|
-
dispatcher.on('attribute', (evt, data, conversionApi) => {
|
|
83
|
-
// Only process if the attribute change is on a `title` element.
|
|
84
|
-
if (!data.item.is('element', 'title')) {
|
|
85
|
-
return;
|
|
86
|
-
}
|
|
87
|
-
const titleElement = data.item;
|
|
88
|
-
if (!conversionApi.consumable.consume(titleElement, evt.name)) {
|
|
89
|
-
return;
|
|
90
|
-
}
|
|
91
|
-
const titleContentElement = titleElement.getChild(0);
|
|
92
|
-
// Ensure the `title-content` element is converted to view first.
|
|
93
|
-
// This is needed because attribute conversion might run before insert conversion.
|
|
94
|
-
conversionApi.convertItem(titleContentElement);
|
|
95
|
-
const viewElement = conversionApi.mapper.toViewElement(titleContentElement);
|
|
96
|
-
const attributeKey = data.attributeKey;
|
|
97
|
-
const attributeNewValue = data.attributeNewValue;
|
|
98
|
-
// Apply the attribute to the view element.
|
|
99
|
-
if (attributeNewValue !== null) {
|
|
100
|
-
conversionApi.writer.setAttribute(attributeKey, attributeNewValue, viewElement);
|
|
101
|
-
}
|
|
102
|
-
else {
|
|
103
|
-
conversionApi.writer.removeAttribute(attributeKey, viewElement);
|
|
104
|
-
}
|
|
105
|
-
});
|
|
106
|
-
});
|
|
107
76
|
// Custom converter is used for data v -> m conversion to avoid calling post-fixer when setting data.
|
|
108
77
|
// See https://github.com/ckeditor/ckeditor5/issues/2036.
|
|
109
78
|
editor.data.upcastDispatcher.on('element:h1', dataViewModelH1Insertion, { priority: 'high' });
|
|
@@ -124,10 +93,10 @@ export class Title extends Plugin {
|
|
|
124
93
|
}
|
|
125
94
|
/**
|
|
126
95
|
* Returns the title of the document. Note that because this plugin does not allow any formatting inside
|
|
127
|
-
* the
|
|
96
|
+
* the title element, the output of this method will be a plain text, with no HTML tags.
|
|
128
97
|
*
|
|
129
98
|
* It is not recommended to use this method together with features that insert markers to the
|
|
130
|
-
* data output, like comments or track changes features. If such markers start in the
|
|
99
|
+
* data output, like comments or track changes features. If such markers start in the title and end in the
|
|
131
100
|
* body, the result of this method might be incorrect.
|
|
132
101
|
*
|
|
133
102
|
* @param options Additional configuration passed to the conversion process.
|
|
@@ -175,7 +144,7 @@ export class Title extends Plugin {
|
|
|
175
144
|
data.mapper.clearBindings();
|
|
176
145
|
data.mapper.bindElements(root, viewDocumentFragment);
|
|
177
146
|
data.downcastDispatcher.convert(rootRange, markers, viewWriter, options);
|
|
178
|
-
// Remove
|
|
147
|
+
// Remove title element from view.
|
|
179
148
|
viewWriter.remove(viewWriter.createRangeOn(viewDocumentFragment.getChild(0)));
|
|
180
149
|
// view -> data
|
|
181
150
|
return editor.data.processor.toData(viewDocumentFragment);
|
|
@@ -216,8 +185,8 @@ export class Title extends Plugin {
|
|
|
216
185
|
return changed;
|
|
217
186
|
}
|
|
218
187
|
/**
|
|
219
|
-
* Model post-fixer callback that creates a
|
|
220
|
-
* takes care of the correct position of it and removes additional
|
|
188
|
+
* Model post-fixer callback that creates a title element when it is missing,
|
|
189
|
+
* takes care of the correct position of it and removes additional title elements.
|
|
221
190
|
*/
|
|
222
191
|
_fixTitleElement(writer) {
|
|
223
192
|
let changed = false;
|
|
@@ -226,7 +195,7 @@ export class Title extends Plugin {
|
|
|
226
195
|
const titleElements = Array.from(modelRoot.getChildren()).filter(isTitle);
|
|
227
196
|
const firstTitleElement = titleElements[0];
|
|
228
197
|
const firstRootChild = modelRoot.getChild(0);
|
|
229
|
-
// When
|
|
198
|
+
// When title element is at the beginning of the document then try to fix additional title elements (if there are any).
|
|
230
199
|
if (firstRootChild.is('element', 'title')) {
|
|
231
200
|
if (titleElements.length > 1) {
|
|
232
201
|
fixAdditionalTitleElements(titleElements, writer, model);
|
|
@@ -244,11 +213,11 @@ export class Title extends Plugin {
|
|
|
244
213
|
continue;
|
|
245
214
|
}
|
|
246
215
|
if (titleLikeElements.has(firstRootChild.name)) {
|
|
247
|
-
// Change the first element in the document to the
|
|
216
|
+
// Change the first element in the document to the title if it can be changed (is title-like).
|
|
248
217
|
changeElementToTitle(firstRootChild, writer, model);
|
|
249
218
|
}
|
|
250
219
|
else {
|
|
251
|
-
// Otherwise, move the first occurrence of the
|
|
220
|
+
// Otherwise, move the first occurrence of the title element to the beginning of the document.
|
|
252
221
|
writer.move(writer.createRangeOn(firstTitleElement), modelRoot, 0);
|
|
253
222
|
}
|
|
254
223
|
fixAdditionalTitleElements(titleElements, writer, model);
|
|
@@ -302,7 +271,7 @@ export class Title extends Plugin {
|
|
|
302
271
|
const bodyPlaceholder = editor.config.get('placeholder') ||
|
|
303
272
|
sourceElement && sourceElement.tagName.toLowerCase() === 'textarea' && sourceElement.getAttribute('placeholder') ||
|
|
304
273
|
t('Type or paste your content here.');
|
|
305
|
-
// Attach placeholder to the view
|
|
274
|
+
// Attach placeholder to the view title element.
|
|
306
275
|
editor.editing.downcastDispatcher.on('insert:title-content', (evt, data, conversionApi) => {
|
|
307
276
|
const element = conversionApi.mapper.toViewElement(data.item);
|
|
308
277
|
element.placeholder = titlePlaceholder;
|
|
@@ -312,8 +281,8 @@ export class Title extends Plugin {
|
|
|
312
281
|
keepOnFocus: true
|
|
313
282
|
});
|
|
314
283
|
});
|
|
315
|
-
// Attach placeholder to first element after a
|
|
316
|
-
// First element after
|
|
284
|
+
// Attach placeholder to first element after a title element and remove it if it's not needed anymore.
|
|
285
|
+
// First element after title can change, so we need to observe all changes keep placeholder in sync.
|
|
317
286
|
const bodyViewElements = new Map();
|
|
318
287
|
// This post-fixer runs after the model post-fixer, so we can assume that the second child in view root will always exist.
|
|
319
288
|
view.document.registerPostFixer(writer => {
|
|
@@ -389,7 +358,7 @@ export class Title extends Plugin {
|
|
|
389
358
|
}
|
|
390
359
|
}
|
|
391
360
|
/**
|
|
392
|
-
* A view-to-model converter for the
|
|
361
|
+
* A view-to-model converter for the h1 that appears at the beginning of the document (a title element).
|
|
393
362
|
*
|
|
394
363
|
* @see module:engine/conversion/upcastdispatcher~UpcastDispatcher#event:element
|
|
395
364
|
* @param evt An object containing information about the fired event.
|
|
@@ -439,7 +408,7 @@ function isTitle(element) {
|
|
|
439
408
|
return element.is('element', 'title');
|
|
440
409
|
}
|
|
441
410
|
/**
|
|
442
|
-
* Changes the given element to the
|
|
411
|
+
* Changes the given element to the title element.
|
|
443
412
|
*/
|
|
444
413
|
function changeElementToTitle(element, writer, model) {
|
|
445
414
|
const title = writer.createElement('title');
|
|
@@ -449,7 +418,7 @@ function changeElementToTitle(element, writer, model) {
|
|
|
449
418
|
model.schema.removeDisallowedAttributes([element], writer);
|
|
450
419
|
}
|
|
451
420
|
/**
|
|
452
|
-
* Loops over the list of
|
|
421
|
+
* Loops over the list of title elements and fixes additional ones.
|
|
453
422
|
*
|
|
454
423
|
* @returns Returns true when there was any change. Returns false otherwise.
|
|
455
424
|
*/
|
|
@@ -464,12 +433,12 @@ function fixAdditionalTitleElements(titleElements, writer, model) {
|
|
|
464
433
|
return hasChanged;
|
|
465
434
|
}
|
|
466
435
|
/**
|
|
467
|
-
* Changes given
|
|
436
|
+
* Changes given title element to a paragraph or removes it when it is empty.
|
|
468
437
|
*/
|
|
469
438
|
function fixTitleElement(title, writer, model) {
|
|
470
439
|
const child = title.getChild(0);
|
|
471
|
-
// Empty
|
|
472
|
-
// It is created as a result of pasting to the
|
|
440
|
+
// Empty title should be removed.
|
|
441
|
+
// It is created as a result of pasting to the title element.
|
|
473
442
|
if (child.isEmpty) {
|
|
474
443
|
writer.remove(title);
|
|
475
444
|
return;
|