|
@@ -8,7 +8,6 @@
|
|
|
*/
|
|
*/
|
|
|
|
|
|
|
|
import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
|
|
import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
|
|
|
-import Collection from '@ckeditor/ckeditor5-utils/src/collection';
|
|
|
|
|
import buildModelConverter from '@ckeditor/ckeditor5-engine/src/conversion/buildmodelconverter';
|
|
import buildModelConverter from '@ckeditor/ckeditor5-engine/src/conversion/buildmodelconverter';
|
|
|
import buildViewConverter from '@ckeditor/ckeditor5-engine/src/conversion/buildviewconverter';
|
|
import buildViewConverter from '@ckeditor/ckeditor5-engine/src/conversion/buildviewconverter';
|
|
|
import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
|
|
import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
|
|
@@ -29,14 +28,6 @@ export default class HeadingEngine extends Plugin {
|
|
|
constructor( editor ) {
|
|
constructor( editor ) {
|
|
|
super( editor );
|
|
super( editor );
|
|
|
|
|
|
|
|
- /**
|
|
|
|
|
- * A collection of heading commands associated with heading engine.
|
|
|
|
|
- *
|
|
|
|
|
- * @readonly
|
|
|
|
|
- * @member {module:utils/collection~Collection.<module:heading/headingcommand~HeadingCommand>}
|
|
|
|
|
- */
|
|
|
|
|
- this.commands = new Collection( { idProperty: 'modelElement' } );
|
|
|
|
|
-
|
|
|
|
|
// TODO: This needs proper documentation, i.e. why paragraph entry does not need
|
|
// TODO: This needs proper documentation, i.e. why paragraph entry does not need
|
|
|
// more properties (https://github.com/ckeditor/ckeditor5/issues/403).
|
|
// more properties (https://github.com/ckeditor/ckeditor5/issues/403).
|
|
|
editor.config.define( 'heading', {
|
|
editor.config.define( 'heading', {
|
|
@@ -63,7 +54,7 @@ export default class HeadingEngine extends Plugin {
|
|
|
const editor = this.editor;
|
|
const editor = this.editor;
|
|
|
const data = editor.data;
|
|
const data = editor.data;
|
|
|
const editing = editor.editing;
|
|
const editing = editor.editing;
|
|
|
- const options = this._getLocalizedOptions();
|
|
|
|
|
|
|
+ const options = editor.config.get( 'heading.options' );
|
|
|
let command;
|
|
let command;
|
|
|
|
|
|
|
|
for ( let option of options ) {
|
|
for ( let option of options ) {
|
|
@@ -85,11 +76,7 @@ export default class HeadingEngine extends Plugin {
|
|
|
// Register the heading command for this option.
|
|
// Register the heading command for this option.
|
|
|
command = new HeadingCommand( editor, option );
|
|
command = new HeadingCommand( editor, option );
|
|
|
editor.commands.set( command.modelElement, command );
|
|
editor.commands.set( command.modelElement, command );
|
|
|
- } else {
|
|
|
|
|
- command = editor.commands.get( defaultModelElement );
|
|
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- this.commands.add( command );
|
|
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -101,7 +88,7 @@ export default class HeadingEngine extends Plugin {
|
|
|
// Enter at the end of a heading element should create a paragraph.
|
|
// Enter at the end of a heading element should create a paragraph.
|
|
|
const editor = this.editor;
|
|
const editor = this.editor;
|
|
|
const enterCommand = editor.commands.get( 'enter' );
|
|
const enterCommand = editor.commands.get( 'enter' );
|
|
|
- const options = this._getLocalizedOptions();
|
|
|
|
|
|
|
+ const options = editor.config.get( 'heading.options' );
|
|
|
|
|
|
|
|
if ( enterCommand ) {
|
|
if ( enterCommand ) {
|
|
|
this.listenTo( enterCommand, 'afterExecute', ( evt, data ) => {
|
|
this.listenTo( enterCommand, 'afterExecute', ( evt, data ) => {
|
|
@@ -115,52 +102,4 @@ export default class HeadingEngine extends Plugin {
|
|
|
} );
|
|
} );
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * Returns heading options as defined in `config.heading.options` but processed to consider
|
|
|
|
|
- * editor localization, i.e. to display {@link module:heading/headingcommand~HeadingOption}
|
|
|
|
|
- * in the correct language.
|
|
|
|
|
- *
|
|
|
|
|
- * Note: The reason behind this method is that there's no way to use {@link module:utils/locale~Locale#t}
|
|
|
|
|
- * when the user config is defined because the editor does not exist yet.
|
|
|
|
|
- *
|
|
|
|
|
- * @private
|
|
|
|
|
- * @returns {Array.<module:heading/headingcommand~HeadingOption>}.
|
|
|
|
|
- */
|
|
|
|
|
- _getLocalizedOptions() {
|
|
|
|
|
- if ( this._cachedLocalizedOptions ) {
|
|
|
|
|
- return this._cachedLocalizedOptions;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- const editor = this.editor;
|
|
|
|
|
- const t = editor.t;
|
|
|
|
|
- const localizedLabels = {
|
|
|
|
|
- Paragraph: t( 'Paragraph' ),
|
|
|
|
|
- 'Heading 1': t( 'Heading 1' ),
|
|
|
|
|
- 'Heading 2': t( 'Heading 2' ),
|
|
|
|
|
- 'Heading 3': t( 'Heading 3' )
|
|
|
|
|
- };
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * Cached localized version of `config.heading.options` generated by
|
|
|
|
|
- * {@link module:heading/headingengine~HeadingEngine#_getLocalizedOptions}.
|
|
|
|
|
- *
|
|
|
|
|
- * @private
|
|
|
|
|
- * @readonly
|
|
|
|
|
- * @member {Array.<module:heading/headingcommand~HeadingOption>} #_cachedLocalizedOptions
|
|
|
|
|
- */
|
|
|
|
|
- this._cachedLocalizedOptions = editor.config.get( 'heading.options' )
|
|
|
|
|
- .map( option => {
|
|
|
|
|
- if ( localizedLabels[ option.title ] ) {
|
|
|
|
|
- // Clone the option to avoid altering the original `config.heading.options`.
|
|
|
|
|
- option = Object.assign( {}, option, {
|
|
|
|
|
- title: localizedLabels[ option.title ]
|
|
|
|
|
- } );
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- return option;
|
|
|
|
|
- } );
|
|
|
|
|
-
|
|
|
|
|
- return this._cachedLocalizedOptions;
|
|
|
|
|
- }
|
|
|
|
|
}
|
|
}
|