7
7
* @module heading/heading
8
8
*/
9
9
10
- import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph ' ;
11
- import HeadingEngine from './headingengine ' ;
10
+ import HeadingEditing from './headingediting ' ;
11
+ import HeadingUI from './headingui ' ;
12
12
import Plugin from '@ckeditor/ckeditor5-core/src/plugin' ;
13
- import Model from '@ckeditor/ckeditor5-ui/src/model' ;
14
-
15
- import { createDropdown , addListToDropdown } from '@ckeditor/ckeditor5-ui/src/dropdown/utils' ;
16
-
17
- import Collection from '@ckeditor/ckeditor5-utils/src/collection' ;
18
13
19
14
import '../theme/heading.css' ;
20
15
21
16
/**
22
- * The headings feature. It introduces the `headings` drop-down and the `heading1`-`headingN` commands which allow
23
- * to convert paragraphs into headings.
17
+ * The headings feature.
18
+ *
19
+ * It loads the {@link module:heading/headingediting~HeadingEditing heading editing feature}
20
+ * and {@link module:heading/headingui~HeadingUI heading UI feature}.
24
21
*
25
22
* For a detailed overview, check the {@glink features/headings Headings feature documentation}.
26
23
*
@@ -31,7 +28,7 @@ export default class Heading extends Plugin {
31
28
* @inheritDoc
32
29
*/
33
30
static get requires ( ) {
34
- return [ Paragraph , HeadingEngine ] ;
31
+ return [ HeadingEditing , HeadingUI ] ;
35
32
}
36
33
37
34
/**
@@ -40,112 +37,10 @@ export default class Heading extends Plugin {
40
37
static get pluginName ( ) {
41
38
return 'Heading' ;
42
39
}
43
-
44
- /**
45
- * @inheritDoc
46
- */
47
- init ( ) {
48
- const editor = this . editor ;
49
- const t = editor . t ;
50
- const options = this . _getLocalizedOptions ( ) ;
51
- const defaultTitle = t ( 'Choose heading' ) ;
52
- const dropdownTooltip = t ( 'Heading' ) ;
53
-
54
- // Register UI component.
55
- editor . ui . componentFactory . add ( 'headings' , locale => {
56
- const commands = [ ] ;
57
- const dropdownItems = new Collection ( ) ;
58
-
59
- for ( const option of options ) {
60
- const command = editor . commands . get ( option . model ) ;
61
- const itemModel = new Model ( {
62
- commandName : option . model ,
63
- label : option . title ,
64
- class : option . class
65
- } ) ;
66
-
67
- itemModel . bind ( 'isActive' ) . to ( command , 'value' ) ;
68
-
69
- // Add the option to the collection.
70
- dropdownItems . add ( itemModel ) ;
71
-
72
- commands . push ( command ) ;
73
- }
74
-
75
- const dropdownView = createDropdown ( locale ) ;
76
- addListToDropdown ( dropdownView , dropdownItems ) ;
77
-
78
- dropdownView . buttonView . set ( {
79
- isOn : false ,
80
- withText : true ,
81
- tooltip : dropdownTooltip
82
- } ) ;
83
-
84
- dropdownView . extendTemplate ( {
85
- attributes : {
86
- class : [
87
- 'ck-heading-dropdown'
88
- ]
89
- }
90
- } ) ;
91
-
92
- dropdownView . bind ( 'isEnabled' ) . toMany ( commands , 'isEnabled' , ( ...areEnabled ) => {
93
- return areEnabled . some ( isEnabled => isEnabled ) ;
94
- } ) ;
95
-
96
- dropdownView . buttonView . bind ( 'label' ) . toMany ( commands , 'value' , ( ...areActive ) => {
97
- const index = areActive . findIndex ( value => value ) ;
98
-
99
- // If none of the commands is active, display default title.
100
- return options [ index ] ? options [ index ] . title : defaultTitle ;
101
- } ) ;
102
-
103
- // Execute command when an item from the dropdown is selected.
104
- this . listenTo ( dropdownView , 'execute' , evt => {
105
- editor . execute ( evt . source . commandName ) ;
106
- editor . editing . view . focus ( ) ;
107
- } ) ;
108
-
109
- return dropdownView ;
110
- } ) ;
111
- }
112
-
113
- /**
114
- * Returns heading options as defined in `config.heading.options` but processed to consider
115
- * editor localization, i.e. to display {@link module:heading/heading~HeadingOption}
116
- * in the correct language.
117
- *
118
- * Note: The reason behind this method is that there's no way to use {@link module:utils/locale~Locale#t}
119
- * when the user config is defined because the editor does not exist yet.
120
- *
121
- * @private
122
- * @returns {Array.<module:heading/heading~HeadingOption> }.
123
- */
124
- _getLocalizedOptions ( ) {
125
- const editor = this . editor ;
126
- const t = editor . t ;
127
- const localizedTitles = {
128
- Paragraph : t ( 'Paragraph' ) ,
129
- 'Heading 1' : t ( 'Heading 1' ) ,
130
- 'Heading 2' : t ( 'Heading 2' ) ,
131
- 'Heading 3' : t ( 'Heading 3' )
132
- } ;
133
-
134
- return editor . config . get ( 'heading.options' ) . map ( option => {
135
- const title = localizedTitles [ option . title ] ;
136
-
137
- if ( title && title != option . title ) {
138
- // Clone the option to avoid altering the original `config.heading.options`.
139
- option = Object . assign ( { } , option , { title } ) ;
140
- }
141
-
142
- return option ;
143
- } ) ;
144
- }
145
40
}
146
41
147
42
/**
148
- * The configuration of the heading feature. Introduced by the {@link module:heading/headingengine~HeadingEngine } feature.
43
+ * The configuration of the heading feature. Introduced by the {@link module:heading/headingediting~HeadingEditing } feature.
149
44
*
150
45
* Read more in {@link module:heading/heading~HeadingConfig}.
151
46
*
@@ -154,7 +49,7 @@ export default class Heading extends Plugin {
154
49
155
50
/**
156
51
* The configuration of the heading feature.
157
- * The option is used by the {@link module:heading/headingengine~HeadingEngine } feature.
52
+ * The option is used by the {@link module:heading/headingediting~HeadingEditing } feature.
158
53
*
159
54
* ClassicEditor
160
55
* .create( {
@@ -191,7 +86,7 @@ export default class Heading extends Plugin {
191
86
* Usually, the first option in the headings dropdown is the "Paragraph" option, hence it's also defined on the list.
192
87
* However, you don't need to define its view representation because it's handled by
193
88
* the {@link module:paragraph/paragraph~Paragraph} feature (which is required by
194
- * the {@link module:heading/headingengine~HeadingEngine } feature).
89
+ * the {@link module:heading/headingediting~HeadingEditing } feature).
195
90
*
196
91
* You can **read more** about configuring heading levels and **see more examples** in
197
92
* the {@glink features/headings Headings} guide.
0 commit comments