Maciej Gołaszewski пре 6 година
родитељ
комит
71379786e4

+ 62 - 0
packages/ckeditor5-indent/src/indentblock.js

@@ -0,0 +1,62 @@
+/**
+ * @license Copyright (c) 2003-2019, CKSource - Frederico Knabben. All rights reserved.
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
+ */
+
+/**
+ * @module indent-block/indentblock
+ */
+
+import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
+
+/**
+ * The block indentation feature.
+ *
+ * @extends module:core/plugin~Plugin
+ */
+export default class IndentBlock extends Plugin {
+	/**
+	 * @inheritDoc
+	 */
+	static get pluginName() {
+		return 'IndentBlock';
+	}
+
+	/**
+	 * @inheritDoc
+	 */
+	init() {
+		const schema = this.editor.model.schema;
+		const conversion = this.editor.conversion;
+
+		// TODO: better features inclusion
+		schema.extend( 'paragraph', { allowAttributes: 'indent' } );
+		schema.extend( 'heading1', { allowAttributes: 'indent' } );
+
+		conversion.for( 'upcast' ).attributeToAttribute( {
+			view: {
+				styles: {
+					'margin-left': /[\s\S]+/
+				}
+			},
+			model: {
+				key: 'indent',
+				value: viewElement => {
+					return viewElement.getStyle( 'margin-left' );
+				}
+			}
+		} );
+
+		conversion.for( 'downcast' ).attributeToAttribute( {
+			model: 'indent',
+			view: modelAttributeValue => {
+				return {
+					key: 'style',
+					value: {
+						'margin-left': modelAttributeValue
+					}
+				};
+			}
+		} );
+	}
+}

+ 1 - 37
packages/ckeditor5-indent/tests/manual/indent-block.js

@@ -14,6 +14,7 @@ import Command from '@ckeditor/ckeditor5-core/src/command';
 import first from '@ckeditor/ckeditor5-utils/src/first';
 
 import ArticlePluginSet from '@ckeditor/ckeditor5-core/tests/_utils/articlepluginset';
+import IndentBlock from '../../src/indentblock';
 
 class IndentBlockCommand extends Command {
 	/**
@@ -117,43 +118,6 @@ class IndentOutdent extends Plugin {
 		editor.commands.add( 'outdent', outdentCommand );
 	}
 }
-
-class IndentBlock extends Plugin {
-	init() {
-		const schema = this.editor.model.schema;
-		const conversion = this.editor.conversion;
-
-		schema.extend( 'paragraph', { allowAttributes: 'indent' } );
-		schema.extend( 'heading1', { allowAttributes: 'indent' } );
-
-		conversion.for( 'upcast' ).attributeToAttribute( {
-			view: {
-				styles: {
-					'margin-left': /[\s\S]+/
-				}
-			},
-			model: {
-				key: 'indent',
-				value: viewElement => {
-					return viewElement.getStyle( 'margin-left' );
-				}
-			}
-		} );
-
-		conversion.for( 'downcast' ).attributeToAttribute( {
-			model: 'indent',
-			view: modelAttributeValue => {
-				return {
-					key: 'style',
-					value: {
-						'margin-left': modelAttributeValue
-					}
-				};
-			}
-		} );
-	}
-}
-
 ClassicEditor
 	.create( document.querySelector( '#editor' ), {
 		plugins: [ ArticlePluginSet, IndentOutdent, IndentBlock ],