8
0
Просмотр исходного кода

Split indent block feature initialization to init and afterInit.

The schema extending rules must be done in afterInit and
all core indent block behavior should be done during
the init phase.
Maciej Gołaszewski 6 лет назад
Родитель
Сommit
0e06819c23
1 измененных файлов с 19 добавлено и 11 удалено
  1. 19 11
      packages/ckeditor5-indent/src/indentblock.js

+ 19 - 11
packages/ckeditor5-indent/src/indentblock.js

@@ -46,20 +46,10 @@ export default class IndentBlock extends Plugin {
 	/**
 	/**
 	 * @inheritDoc
 	 * @inheritDoc
 	 */
 	 */
-	afterInit() {
+	init() {
 		const editor = this.editor;
 		const editor = this.editor;
-		const schema = editor.model.schema;
 		const configuration = editor.config.get( 'indentBlock' );
 		const configuration = editor.config.get( 'indentBlock' );
 
 
-		// Enable block indentation by default in paragraph and default headings.
-		const knownElements = [ 'paragraph', 'heading1', 'heading2', 'heading3', 'heading4', 'heading5', 'heading6' ];
-
-		knownElements.forEach( elementName => {
-			if ( schema.isRegistered( elementName ) ) {
-				schema.extend( elementName, { allowAttributes: 'blockIndent' } );
-			}
-		} );
-
 		const useOffsetConfig = !configuration.classes || !configuration.classes.length;
 		const useOffsetConfig = !configuration.classes || !configuration.classes.length;
 
 
 		const indentConfig = Object.assign( { direction: 'forward' }, configuration );
 		const indentConfig = Object.assign( { direction: 'forward' }, configuration );
@@ -67,6 +57,7 @@ export default class IndentBlock extends Plugin {
 
 
 		if ( useOffsetConfig ) {
 		if ( useOffsetConfig ) {
 			this._setupConversionUsingOffset( editor.conversion );
 			this._setupConversionUsingOffset( editor.conversion );
+
 			editor.commands.add( 'indentBlock', new IndentBlockCommand( editor, new IndentUsingOffset( indentConfig ) ) );
 			editor.commands.add( 'indentBlock', new IndentBlockCommand( editor, new IndentUsingOffset( indentConfig ) ) );
 			editor.commands.add( 'outdentBlock', new IndentBlockCommand( editor, new IndentUsingOffset( outdentConfig ) ) );
 			editor.commands.add( 'outdentBlock', new IndentBlockCommand( editor, new IndentUsingOffset( outdentConfig ) ) );
 		} else {
 		} else {
@@ -74,10 +65,27 @@ export default class IndentBlock extends Plugin {
 			editor.commands.add( 'indentBlock', new IndentBlockCommand( editor, new IndentUsingClasses( indentConfig ) ) );
 			editor.commands.add( 'indentBlock', new IndentBlockCommand( editor, new IndentUsingClasses( indentConfig ) ) );
 			editor.commands.add( 'outdentBlock', new IndentBlockCommand( editor, new IndentUsingClasses( outdentConfig ) ) );
 			editor.commands.add( 'outdentBlock', new IndentBlockCommand( editor, new IndentUsingClasses( outdentConfig ) ) );
 		}
 		}
+	}
+
+	/**
+	 * @inheritDoc
+	 */
+	afterInit() {
+		const editor = this.editor;
+		const schema = editor.model.schema;
 
 
 		const indentCommand = editor.commands.get( 'indent' );
 		const indentCommand = editor.commands.get( 'indent' );
 		const outdentCommand = editor.commands.get( 'outdent' );
 		const outdentCommand = editor.commands.get( 'outdent' );
 
 
+		// Enable block indentation by default in paragraph and default headings.
+		const knownElements = [ 'paragraph', 'heading1', 'heading2', 'heading3', 'heading4', 'heading5', 'heading6' ];
+
+		knownElements.forEach( elementName => {
+			if ( schema.isRegistered( elementName ) ) {
+				schema.extend( elementName, { allowAttributes: 'blockIndent' } );
+			}
+		} );
+
 		indentCommand.registerChildCommand( editor.commands.get( 'indentBlock' ) );
 		indentCommand.registerChildCommand( editor.commands.get( 'indentBlock' ) );
 		outdentCommand.registerChildCommand( editor.commands.get( 'outdentBlock' ) );
 		outdentCommand.registerChildCommand( editor.commands.get( 'outdentBlock' ) );
 	}
 	}