@ckeditor/ckeditor5-heading 38.0.1 → 38.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/heading.js +1 -1
- package/build/heading.js.map +1 -0
- package/package.json +2 -29
- package/src/augmentation.d.ts +30 -30
- package/src/augmentation.js +5 -5
- package/src/heading.d.ts +32 -32
- package/src/heading.js +36 -36
- package/src/headingbuttonsui.d.ts +51 -51
- package/src/headingbuttonsui.js +89 -89
- package/src/headingcommand.d.ts +48 -48
- package/src/headingcommand.js +65 -65
- package/src/headingconfig.d.ts +110 -110
- package/src/headingconfig.js +5 -5
- package/src/headingediting.d.ts +42 -42
- package/src/headingediting.js +101 -101
- package/src/headingui.d.ts +22 -22
- package/src/headingui.js +107 -107
- package/src/index.d.ts +16 -16
- package/src/index.js +13 -13
- package/src/title.d.ts +115 -115
- package/src/title.js +460 -426
- package/src/utils.d.ts +18 -18
- package/src/utils.js +31 -31
package/src/headingconfig.d.ts
CHANGED
|
@@ -1,110 +1,110 @@
|
|
|
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 heading/headingconfig
|
|
7
|
-
*/
|
|
8
|
-
import type { ViewElementDefinition } from 'ckeditor5/src/engine';
|
|
9
|
-
/**
|
|
10
|
-
* The configuration of the heading feature.
|
|
11
|
-
* The option is used by the {@link module:heading/headingediting~HeadingEditing} feature.
|
|
12
|
-
*
|
|
13
|
-
* ```ts
|
|
14
|
-
* ClassicEditor
|
|
15
|
-
* .create( {
|
|
16
|
-
* heading: ... // Heading feature config.
|
|
17
|
-
* } )
|
|
18
|
-
* .then( ... )
|
|
19
|
-
* .catch( ... );
|
|
20
|
-
* ```
|
|
21
|
-
*
|
|
22
|
-
* See {@link module:core/editor/editorconfig~EditorConfig all editor options}.
|
|
23
|
-
*/
|
|
24
|
-
export interface HeadingConfig {
|
|
25
|
-
/**
|
|
26
|
-
* The available heading options.
|
|
27
|
-
*
|
|
28
|
-
* The default value is:
|
|
29
|
-
* ```ts
|
|
30
|
-
* const headingConfig = {
|
|
31
|
-
* options: [
|
|
32
|
-
* { model: 'paragraph', title: 'Paragraph', class: 'ck-heading_paragraph' },
|
|
33
|
-
* { model: 'heading1', view: 'h2', title: 'Heading 1', class: 'ck-heading_heading1' },
|
|
34
|
-
* { model: 'heading2', view: 'h3', title: 'Heading 2', class: 'ck-heading_heading2' },
|
|
35
|
-
* { model: 'heading3', view: 'h4', title: 'Heading 3', class: 'ck-heading_heading3' }
|
|
36
|
-
* ]
|
|
37
|
-
* };
|
|
38
|
-
* ```
|
|
39
|
-
*
|
|
40
|
-
* It defines 3 levels of headings. In the editor model they will use `heading1`, `heading2`, and `heading3` elements.
|
|
41
|
-
* Their respective view elements (so the elements output by the editor) will be: `h2`, `h3`, and `h4`. This means that
|
|
42
|
-
* if you choose "Heading 1" in the headings dropdown the editor will turn the current block to `<heading1>` in the model
|
|
43
|
-
* which will result in rendering (and outputting to data) the `<h2>` element.
|
|
44
|
-
*
|
|
45
|
-
* The `title` and `class` properties will be used by the `headings` dropdown to render available options.
|
|
46
|
-
* Usually, the first option in the headings dropdown is the "Paragraph" option, hence it's also defined on the list.
|
|
47
|
-
* However, you don't need to define its view representation because it's handled by
|
|
48
|
-
* the {@link module:paragraph/paragraph~Paragraph} feature (which is required by
|
|
49
|
-
* the {@link module:heading/headingediting~HeadingEditing} feature).
|
|
50
|
-
*
|
|
51
|
-
* You can **read more** about configuring heading levels and **see more examples** in
|
|
52
|
-
* the {@glink features/headings Headings} guide.
|
|
53
|
-
*
|
|
54
|
-
* Note: In the model you should always start from `heading1`, regardless of how the headings are represented in the view.
|
|
55
|
-
* That's assumption is used by features like {@link module:autoformat/autoformat~Autoformat} to know which element
|
|
56
|
-
* they should use when applying the first level heading.
|
|
57
|
-
*
|
|
58
|
-
* The defined headings are also available as values passed to the `'heading'` command under their model names.
|
|
59
|
-
* For example, the below code will apply `<heading1>` to the current selection:
|
|
60
|
-
*
|
|
61
|
-
* ```ts
|
|
62
|
-
* editor.execute( 'heading', { value: 'heading1' } );
|
|
63
|
-
* ```
|
|
64
|
-
*/
|
|
65
|
-
options?: Array<HeadingOption>;
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* Heading option descriptor.
|
|
69
|
-
*/
|
|
70
|
-
export type HeadingOption = HeadingElementOption | HeadingParagraphOption;
|
|
71
|
-
export interface HeadingElementOption {
|
|
72
|
-
/**
|
|
73
|
-
* Name of the model element to convert.
|
|
74
|
-
*/
|
|
75
|
-
model: 'heading1' | 'heading2' | 'heading3' | 'heading4' | 'heading5' | 'heading6';
|
|
76
|
-
/**
|
|
77
|
-
* Definition of a view element to convert from/to.
|
|
78
|
-
*/
|
|
79
|
-
view: ViewElementDefinition;
|
|
80
|
-
/**
|
|
81
|
-
* The user-readable title of the option.
|
|
82
|
-
*/
|
|
83
|
-
title: string;
|
|
84
|
-
/**
|
|
85
|
-
* The class which will be added to the dropdown item representing this option.
|
|
86
|
-
*/
|
|
87
|
-
class: string;
|
|
88
|
-
/**
|
|
89
|
-
* Icon used by {@link module:heading/headingbuttonsui~HeadingButtonsUI}. It can be omitted when using the default configuration.
|
|
90
|
-
*/
|
|
91
|
-
icon?: string;
|
|
92
|
-
}
|
|
93
|
-
export interface HeadingParagraphOption {
|
|
94
|
-
/**
|
|
95
|
-
* Name of the model element to convert.
|
|
96
|
-
*/
|
|
97
|
-
model: 'paragraph';
|
|
98
|
-
/**
|
|
99
|
-
* The user-readable title of the option.
|
|
100
|
-
*/
|
|
101
|
-
title: string;
|
|
102
|
-
/**
|
|
103
|
-
* The class which will be added to the dropdown item representing this option.
|
|
104
|
-
* */
|
|
105
|
-
class: string;
|
|
106
|
-
/**
|
|
107
|
-
* Icon used by {@link module:heading/headingbuttonsui~HeadingButtonsUI}. It can be omitted when using the default configuration.
|
|
108
|
-
*/
|
|
109
|
-
icon?: string;
|
|
110
|
-
}
|
|
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 heading/headingconfig
|
|
7
|
+
*/
|
|
8
|
+
import type { ViewElementDefinition } from 'ckeditor5/src/engine';
|
|
9
|
+
/**
|
|
10
|
+
* The configuration of the heading feature.
|
|
11
|
+
* The option is used by the {@link module:heading/headingediting~HeadingEditing} feature.
|
|
12
|
+
*
|
|
13
|
+
* ```ts
|
|
14
|
+
* ClassicEditor
|
|
15
|
+
* .create( {
|
|
16
|
+
* heading: ... // Heading feature config.
|
|
17
|
+
* } )
|
|
18
|
+
* .then( ... )
|
|
19
|
+
* .catch( ... );
|
|
20
|
+
* ```
|
|
21
|
+
*
|
|
22
|
+
* See {@link module:core/editor/editorconfig~EditorConfig all editor options}.
|
|
23
|
+
*/
|
|
24
|
+
export interface HeadingConfig {
|
|
25
|
+
/**
|
|
26
|
+
* The available heading options.
|
|
27
|
+
*
|
|
28
|
+
* The default value is:
|
|
29
|
+
* ```ts
|
|
30
|
+
* const headingConfig = {
|
|
31
|
+
* options: [
|
|
32
|
+
* { model: 'paragraph', title: 'Paragraph', class: 'ck-heading_paragraph' },
|
|
33
|
+
* { model: 'heading1', view: 'h2', title: 'Heading 1', class: 'ck-heading_heading1' },
|
|
34
|
+
* { model: 'heading2', view: 'h3', title: 'Heading 2', class: 'ck-heading_heading2' },
|
|
35
|
+
* { model: 'heading3', view: 'h4', title: 'Heading 3', class: 'ck-heading_heading3' }
|
|
36
|
+
* ]
|
|
37
|
+
* };
|
|
38
|
+
* ```
|
|
39
|
+
*
|
|
40
|
+
* It defines 3 levels of headings. In the editor model they will use `heading1`, `heading2`, and `heading3` elements.
|
|
41
|
+
* Their respective view elements (so the elements output by the editor) will be: `h2`, `h3`, and `h4`. This means that
|
|
42
|
+
* if you choose "Heading 1" in the headings dropdown the editor will turn the current block to `<heading1>` in the model
|
|
43
|
+
* which will result in rendering (and outputting to data) the `<h2>` element.
|
|
44
|
+
*
|
|
45
|
+
* The `title` and `class` properties will be used by the `headings` dropdown to render available options.
|
|
46
|
+
* Usually, the first option in the headings dropdown is the "Paragraph" option, hence it's also defined on the list.
|
|
47
|
+
* However, you don't need to define its view representation because it's handled by
|
|
48
|
+
* the {@link module:paragraph/paragraph~Paragraph} feature (which is required by
|
|
49
|
+
* the {@link module:heading/headingediting~HeadingEditing} feature).
|
|
50
|
+
*
|
|
51
|
+
* You can **read more** about configuring heading levels and **see more examples** in
|
|
52
|
+
* the {@glink features/headings Headings} guide.
|
|
53
|
+
*
|
|
54
|
+
* Note: In the model you should always start from `heading1`, regardless of how the headings are represented in the view.
|
|
55
|
+
* That's assumption is used by features like {@link module:autoformat/autoformat~Autoformat} to know which element
|
|
56
|
+
* they should use when applying the first level heading.
|
|
57
|
+
*
|
|
58
|
+
* The defined headings are also available as values passed to the `'heading'` command under their model names.
|
|
59
|
+
* For example, the below code will apply `<heading1>` to the current selection:
|
|
60
|
+
*
|
|
61
|
+
* ```ts
|
|
62
|
+
* editor.execute( 'heading', { value: 'heading1' } );
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
options?: Array<HeadingOption>;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Heading option descriptor.
|
|
69
|
+
*/
|
|
70
|
+
export type HeadingOption = HeadingElementOption | HeadingParagraphOption;
|
|
71
|
+
export interface HeadingElementOption {
|
|
72
|
+
/**
|
|
73
|
+
* Name of the model element to convert.
|
|
74
|
+
*/
|
|
75
|
+
model: 'heading1' | 'heading2' | 'heading3' | 'heading4' | 'heading5' | 'heading6';
|
|
76
|
+
/**
|
|
77
|
+
* Definition of a view element to convert from/to.
|
|
78
|
+
*/
|
|
79
|
+
view: ViewElementDefinition;
|
|
80
|
+
/**
|
|
81
|
+
* The user-readable title of the option.
|
|
82
|
+
*/
|
|
83
|
+
title: string;
|
|
84
|
+
/**
|
|
85
|
+
* The class which will be added to the dropdown item representing this option.
|
|
86
|
+
*/
|
|
87
|
+
class: string;
|
|
88
|
+
/**
|
|
89
|
+
* Icon used by {@link module:heading/headingbuttonsui~HeadingButtonsUI}. It can be omitted when using the default configuration.
|
|
90
|
+
*/
|
|
91
|
+
icon?: string;
|
|
92
|
+
}
|
|
93
|
+
export interface HeadingParagraphOption {
|
|
94
|
+
/**
|
|
95
|
+
* Name of the model element to convert.
|
|
96
|
+
*/
|
|
97
|
+
model: 'paragraph';
|
|
98
|
+
/**
|
|
99
|
+
* The user-readable title of the option.
|
|
100
|
+
*/
|
|
101
|
+
title: string;
|
|
102
|
+
/**
|
|
103
|
+
* The class which will be added to the dropdown item representing this option.
|
|
104
|
+
* */
|
|
105
|
+
class: string;
|
|
106
|
+
/**
|
|
107
|
+
* Icon used by {@link module:heading/headingbuttonsui~HeadingButtonsUI}. It can be omitted when using the default configuration.
|
|
108
|
+
*/
|
|
109
|
+
icon?: string;
|
|
110
|
+
}
|
package/src/headingconfig.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
-
*/
|
|
5
|
-
export {};
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
+
*/
|
|
5
|
+
export {};
|
package/src/headingediting.d.ts
CHANGED
|
@@ -1,42 +1,42 @@
|
|
|
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 heading/headingediting
|
|
7
|
-
*/
|
|
8
|
-
import { Plugin, type Editor } from 'ckeditor5/src/core';
|
|
9
|
-
import { Paragraph } from 'ckeditor5/src/paragraph';
|
|
10
|
-
/**
|
|
11
|
-
* The headings engine feature. It handles switching between block formats – headings and paragraph.
|
|
12
|
-
* This class represents the engine part of the heading feature. See also {@link module:heading/heading~Heading}.
|
|
13
|
-
* It introduces `heading1`-`headingN` commands which allow to convert paragraphs into headings.
|
|
14
|
-
*/
|
|
15
|
-
export default class HeadingEditing extends Plugin {
|
|
16
|
-
/**
|
|
17
|
-
* @inheritDoc
|
|
18
|
-
*/
|
|
19
|
-
static get pluginName():
|
|
20
|
-
/**
|
|
21
|
-
* @inheritDoc
|
|
22
|
-
*/
|
|
23
|
-
constructor(editor: Editor);
|
|
24
|
-
/**
|
|
25
|
-
* @inheritDoc
|
|
26
|
-
*/
|
|
27
|
-
static get requires(): readonly [typeof Paragraph];
|
|
28
|
-
/**
|
|
29
|
-
* @inheritDoc
|
|
30
|
-
*/
|
|
31
|
-
init(): void;
|
|
32
|
-
/**
|
|
33
|
-
* @inheritDoc
|
|
34
|
-
*/
|
|
35
|
-
afterInit(): void;
|
|
36
|
-
/**
|
|
37
|
-
* Adds default conversion for `h1` -> `heading1` with a low priority.
|
|
38
|
-
*
|
|
39
|
-
* @param editor Editor instance on which to add the `h1` conversion.
|
|
40
|
-
*/
|
|
41
|
-
private _addDefaultH1Conversion;
|
|
42
|
-
}
|
|
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 heading/headingediting
|
|
7
|
+
*/
|
|
8
|
+
import { Plugin, type Editor } from 'ckeditor5/src/core';
|
|
9
|
+
import { Paragraph } from 'ckeditor5/src/paragraph';
|
|
10
|
+
/**
|
|
11
|
+
* The headings engine feature. It handles switching between block formats – headings and paragraph.
|
|
12
|
+
* This class represents the engine part of the heading feature. See also {@link module:heading/heading~Heading}.
|
|
13
|
+
* It introduces `heading1`-`headingN` commands which allow to convert paragraphs into headings.
|
|
14
|
+
*/
|
|
15
|
+
export default class HeadingEditing extends Plugin {
|
|
16
|
+
/**
|
|
17
|
+
* @inheritDoc
|
|
18
|
+
*/
|
|
19
|
+
static get pluginName(): "HeadingEditing";
|
|
20
|
+
/**
|
|
21
|
+
* @inheritDoc
|
|
22
|
+
*/
|
|
23
|
+
constructor(editor: Editor);
|
|
24
|
+
/**
|
|
25
|
+
* @inheritDoc
|
|
26
|
+
*/
|
|
27
|
+
static get requires(): readonly [typeof Paragraph];
|
|
28
|
+
/**
|
|
29
|
+
* @inheritDoc
|
|
30
|
+
*/
|
|
31
|
+
init(): void;
|
|
32
|
+
/**
|
|
33
|
+
* @inheritDoc
|
|
34
|
+
*/
|
|
35
|
+
afterInit(): void;
|
|
36
|
+
/**
|
|
37
|
+
* Adds default conversion for `h1` -> `heading1` with a low priority.
|
|
38
|
+
*
|
|
39
|
+
* @param editor Editor instance on which to add the `h1` conversion.
|
|
40
|
+
*/
|
|
41
|
+
private _addDefaultH1Conversion;
|
|
42
|
+
}
|
package/src/headingediting.js
CHANGED
|
@@ -1,101 +1,101 @@
|
|
|
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 heading/headingediting
|
|
7
|
-
*/
|
|
8
|
-
import { Plugin } from 'ckeditor5/src/core';
|
|
9
|
-
import { Paragraph } from 'ckeditor5/src/paragraph';
|
|
10
|
-
import { priorities } from 'ckeditor5/src/utils';
|
|
11
|
-
import HeadingCommand from './headingcommand';
|
|
12
|
-
const defaultModelElement = 'paragraph';
|
|
13
|
-
/**
|
|
14
|
-
* The headings engine feature. It handles switching between block formats – headings and paragraph.
|
|
15
|
-
* This class represents the engine part of the heading feature. See also {@link module:heading/heading~Heading}.
|
|
16
|
-
* It introduces `heading1`-`headingN` commands which allow to convert paragraphs into headings.
|
|
17
|
-
*/
|
|
18
|
-
export default class HeadingEditing extends Plugin {
|
|
19
|
-
/**
|
|
20
|
-
* @inheritDoc
|
|
21
|
-
*/
|
|
22
|
-
static get pluginName() {
|
|
23
|
-
return 'HeadingEditing';
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* @inheritDoc
|
|
27
|
-
*/
|
|
28
|
-
constructor(editor) {
|
|
29
|
-
super(editor);
|
|
30
|
-
editor.config.define('heading', {
|
|
31
|
-
options: [
|
|
32
|
-
{ model: 'paragraph', title: 'Paragraph', class: 'ck-heading_paragraph' },
|
|
33
|
-
{ model: 'heading1', view: 'h2', title: 'Heading 1', class: 'ck-heading_heading1' },
|
|
34
|
-
{ model: 'heading2', view: 'h3', title: 'Heading 2', class: 'ck-heading_heading2' },
|
|
35
|
-
{ model: 'heading3', view: 'h4', title: 'Heading 3', class: 'ck-heading_heading3' }
|
|
36
|
-
]
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* @inheritDoc
|
|
41
|
-
*/
|
|
42
|
-
static get requires() {
|
|
43
|
-
return [Paragraph];
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* @inheritDoc
|
|
47
|
-
*/
|
|
48
|
-
init() {
|
|
49
|
-
const editor = this.editor;
|
|
50
|
-
const options = editor.config.get('heading.options');
|
|
51
|
-
const modelElements = [];
|
|
52
|
-
for (const option of options) {
|
|
53
|
-
// Skip paragraph - it is defined in required Paragraph feature.
|
|
54
|
-
if (option.model === 'paragraph') {
|
|
55
|
-
continue;
|
|
56
|
-
}
|
|
57
|
-
// Schema.
|
|
58
|
-
editor.model.schema.register(option.model, {
|
|
59
|
-
inheritAllFrom: '$block'
|
|
60
|
-
});
|
|
61
|
-
editor.conversion.elementToElement(option);
|
|
62
|
-
modelElements.push(option.model);
|
|
63
|
-
}
|
|
64
|
-
this._addDefaultH1Conversion(editor);
|
|
65
|
-
// Register the heading command for this option.
|
|
66
|
-
editor.commands.add('heading', new HeadingCommand(editor, modelElements));
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* @inheritDoc
|
|
70
|
-
*/
|
|
71
|
-
afterInit() {
|
|
72
|
-
// If the enter command is added to the editor, alter its behavior.
|
|
73
|
-
// Enter at the end of a heading element should create a paragraph.
|
|
74
|
-
const editor = this.editor;
|
|
75
|
-
const enterCommand = editor.commands.get('enter');
|
|
76
|
-
const options = editor.config.get('heading.options');
|
|
77
|
-
if (enterCommand) {
|
|
78
|
-
this.listenTo(enterCommand, 'afterExecute', (evt, data) => {
|
|
79
|
-
const positionParent = editor.model.document.selection.getFirstPosition().parent;
|
|
80
|
-
const isHeading = options.some(option => positionParent.is('element', option.model));
|
|
81
|
-
if (isHeading && !positionParent.is('element', defaultModelElement) && positionParent.childCount === 0) {
|
|
82
|
-
data.writer.rename(positionParent, defaultModelElement);
|
|
83
|
-
}
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* Adds default conversion for `h1` -> `heading1` with a low priority.
|
|
89
|
-
*
|
|
90
|
-
* @param editor Editor instance on which to add the `h1` conversion.
|
|
91
|
-
*/
|
|
92
|
-
_addDefaultH1Conversion(editor) {
|
|
93
|
-
editor.conversion.for('upcast').elementToElement({
|
|
94
|
-
model: 'heading1',
|
|
95
|
-
view: 'h1',
|
|
96
|
-
// With a `low` priority, `paragraph` plugin autoparagraphing mechanism is executed. Make sure
|
|
97
|
-
// this listener is called before it. If not, `h1` will be transformed into a paragraph.
|
|
98
|
-
converterPriority: priorities.
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
}
|
|
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 heading/headingediting
|
|
7
|
+
*/
|
|
8
|
+
import { Plugin } from 'ckeditor5/src/core';
|
|
9
|
+
import { Paragraph } from 'ckeditor5/src/paragraph';
|
|
10
|
+
import { priorities } from 'ckeditor5/src/utils';
|
|
11
|
+
import HeadingCommand from './headingcommand';
|
|
12
|
+
const defaultModelElement = 'paragraph';
|
|
13
|
+
/**
|
|
14
|
+
* The headings engine feature. It handles switching between block formats – headings and paragraph.
|
|
15
|
+
* This class represents the engine part of the heading feature. See also {@link module:heading/heading~Heading}.
|
|
16
|
+
* It introduces `heading1`-`headingN` commands which allow to convert paragraphs into headings.
|
|
17
|
+
*/
|
|
18
|
+
export default class HeadingEditing extends Plugin {
|
|
19
|
+
/**
|
|
20
|
+
* @inheritDoc
|
|
21
|
+
*/
|
|
22
|
+
static get pluginName() {
|
|
23
|
+
return 'HeadingEditing';
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* @inheritDoc
|
|
27
|
+
*/
|
|
28
|
+
constructor(editor) {
|
|
29
|
+
super(editor);
|
|
30
|
+
editor.config.define('heading', {
|
|
31
|
+
options: [
|
|
32
|
+
{ model: 'paragraph', title: 'Paragraph', class: 'ck-heading_paragraph' },
|
|
33
|
+
{ model: 'heading1', view: 'h2', title: 'Heading 1', class: 'ck-heading_heading1' },
|
|
34
|
+
{ model: 'heading2', view: 'h3', title: 'Heading 2', class: 'ck-heading_heading2' },
|
|
35
|
+
{ model: 'heading3', view: 'h4', title: 'Heading 3', class: 'ck-heading_heading3' }
|
|
36
|
+
]
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* @inheritDoc
|
|
41
|
+
*/
|
|
42
|
+
static get requires() {
|
|
43
|
+
return [Paragraph];
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* @inheritDoc
|
|
47
|
+
*/
|
|
48
|
+
init() {
|
|
49
|
+
const editor = this.editor;
|
|
50
|
+
const options = editor.config.get('heading.options');
|
|
51
|
+
const modelElements = [];
|
|
52
|
+
for (const option of options) {
|
|
53
|
+
// Skip paragraph - it is defined in required Paragraph feature.
|
|
54
|
+
if (option.model === 'paragraph') {
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
// Schema.
|
|
58
|
+
editor.model.schema.register(option.model, {
|
|
59
|
+
inheritAllFrom: '$block'
|
|
60
|
+
});
|
|
61
|
+
editor.conversion.elementToElement(option);
|
|
62
|
+
modelElements.push(option.model);
|
|
63
|
+
}
|
|
64
|
+
this._addDefaultH1Conversion(editor);
|
|
65
|
+
// Register the heading command for this option.
|
|
66
|
+
editor.commands.add('heading', new HeadingCommand(editor, modelElements));
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* @inheritDoc
|
|
70
|
+
*/
|
|
71
|
+
afterInit() {
|
|
72
|
+
// If the enter command is added to the editor, alter its behavior.
|
|
73
|
+
// Enter at the end of a heading element should create a paragraph.
|
|
74
|
+
const editor = this.editor;
|
|
75
|
+
const enterCommand = editor.commands.get('enter');
|
|
76
|
+
const options = editor.config.get('heading.options');
|
|
77
|
+
if (enterCommand) {
|
|
78
|
+
this.listenTo(enterCommand, 'afterExecute', (evt, data) => {
|
|
79
|
+
const positionParent = editor.model.document.selection.getFirstPosition().parent;
|
|
80
|
+
const isHeading = options.some(option => positionParent.is('element', option.model));
|
|
81
|
+
if (isHeading && !positionParent.is('element', defaultModelElement) && positionParent.childCount === 0) {
|
|
82
|
+
data.writer.rename(positionParent, defaultModelElement);
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Adds default conversion for `h1` -> `heading1` with a low priority.
|
|
89
|
+
*
|
|
90
|
+
* @param editor Editor instance on which to add the `h1` conversion.
|
|
91
|
+
*/
|
|
92
|
+
_addDefaultH1Conversion(editor) {
|
|
93
|
+
editor.conversion.for('upcast').elementToElement({
|
|
94
|
+
model: 'heading1',
|
|
95
|
+
view: 'h1',
|
|
96
|
+
// With a `low` priority, `paragraph` plugin autoparagraphing mechanism is executed. Make sure
|
|
97
|
+
// this listener is called before it. If not, `h1` will be transformed into a paragraph.
|
|
98
|
+
converterPriority: priorities.low + 1
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
}
|
package/src/headingui.d.ts
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
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 heading/headingui
|
|
7
|
-
*/
|
|
8
|
-
import { Plugin } from 'ckeditor5/src/core';
|
|
9
|
-
import '../theme/heading.css';
|
|
10
|
-
/**
|
|
11
|
-
* The headings UI feature. It introduces the `headings` dropdown.
|
|
12
|
-
*/
|
|
13
|
-
export default class HeadingUI extends Plugin {
|
|
14
|
-
/**
|
|
15
|
-
* @inheritDoc
|
|
16
|
-
*/
|
|
17
|
-
static get pluginName():
|
|
18
|
-
/**
|
|
19
|
-
* @inheritDoc
|
|
20
|
-
*/
|
|
21
|
-
init(): void;
|
|
22
|
-
}
|
|
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 heading/headingui
|
|
7
|
+
*/
|
|
8
|
+
import { Plugin } from 'ckeditor5/src/core';
|
|
9
|
+
import '../theme/heading.css';
|
|
10
|
+
/**
|
|
11
|
+
* The headings UI feature. It introduces the `headings` dropdown.
|
|
12
|
+
*/
|
|
13
|
+
export default class HeadingUI extends Plugin {
|
|
14
|
+
/**
|
|
15
|
+
* @inheritDoc
|
|
16
|
+
*/
|
|
17
|
+
static get pluginName(): "HeadingUI";
|
|
18
|
+
/**
|
|
19
|
+
* @inheritDoc
|
|
20
|
+
*/
|
|
21
|
+
init(): void;
|
|
22
|
+
}
|