8
0
Maciej Gołaszewski 6 лет назад
Родитель
Сommit
42573f7283

+ 15 - 6
packages/ckeditor5-indent/src/indentblock.js

@@ -53,12 +53,21 @@ export default class IndentBlock extends Plugin {
 		const conversion = editor.conversion;
 		const configuration = editor.config.get( 'indentBlock' );
 
-		// TODO: better features inclusion
-		// CKE4: context: { div: 1, dl: 1, h1: 1, h2: 1, h3: 1, h4: 1, h5: 1, h6: 1, ul: 1, ol: 1, p: 1, pre: 1, table: 1 },
-		schema.extend( 'paragraph', { allowAttributes: 'indent' } );
-		schema.extend( 'heading1', { allowAttributes: 'indent' } );
-		schema.extend( 'heading2', { allowAttributes: 'indent' } );
-		schema.extend( 'heading3', { allowAttributes: 'indent' } );
+		// TODO: supported in CKE4:
+		//  - p,
+		//  - h1, h2, h3, h4, h5, h6,
+		//  - ul, ol,
+		//  - div,
+		//  - dl,
+		//  - pre,
+		//  - table
+		const knownElements = [ 'paragraph', 'heading1', 'heading2', 'heading3', 'heading4', 'heading5', 'heading6' ];
+
+		knownElements.forEach( elementName => {
+			if ( schema.isRegistered( elementName ) ) {
+				schema.extend( elementName, { allowAttributes: 'indent' } );
+			}
+		} );
 
 		const useOffsetConfig = !configuration.classes || !configuration.classes.length;
 

+ 91 - 0
packages/ckeditor5-indent/tests/indentblock-integration.js

@@ -0,0 +1,91 @@
+/**
+ * @license Copyright (c) 2003-2019, CKSource - Frederico Knabben. All rights reserved.
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
+ */
+
+/* global document */
+
+import ClassicTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/classictesteditor';
+import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
+import { getData as getViewData } from '@ckeditor/ckeditor5-engine/src/dev-utils/view';
+import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
+import Indent from '@ckeditor/ckeditor5-core/src/indent';
+import Heading from '@ckeditor/ckeditor5-heading/src/heading';
+
+import IndentBlock from '../src/indentblock';
+
+describe( 'IndentBlock - integration', () => {
+	let editor, element, model, doc;
+
+	testUtils.createSinonSandbox();
+
+	beforeEach( () => {
+		element = document.createElement( 'div' );
+		document.body.appendChild( element );
+	} );
+
+	afterEach( () => {
+		element.remove();
+
+		if ( editor ) {
+			return editor.destroy();
+		}
+	} );
+
+	describe( 'with paragraph', () => {
+		beforeEach( () => {
+			return createTestEditor( { indentBlock: { offset: 50, unit: 'px' } } )
+				.then( newEditor => {
+					editor = newEditor;
+					model = editor.model;
+					doc = model.document;
+				} );
+		} );
+
+		it( 'should work with paragraph set', () => {
+			editor.setData( '<p style="margin-left:50px">foo</p>' );
+
+			const paragraph = doc.getRoot().getChild( 0 );
+
+			expect( paragraph.hasAttribute( 'indent' ) ).to.be.true;
+			expect( paragraph.getAttribute( 'indent' ) ).to.equal( '50px' );
+
+			expect( editor.getData() ).to.equal( '<p style="margin-left:50px;">foo</p>' );
+			expect( getViewData( editor.editing.view, { withoutSelection: true } ) )
+				.to.equal( '<p style="margin-left:50px">foo</p>' );
+		} );
+	} );
+
+	describe( 'with heading', () => {
+		beforeEach( () => {
+			return createTestEditor( {
+				plugins: [ Paragraph, Heading, Indent, IndentBlock ],
+				indentBlock: { offset: 50, unit: 'px' }
+			} ).then( newEditor => {
+				editor = newEditor;
+				model = editor.model;
+				doc = model.document;
+			} );
+		} );
+
+		it( 'should work with default headings set', () => {
+			editor.setData( '<p style="margin-left:50px">foo</p>' );
+
+			const paragraph = doc.getRoot().getChild( 0 );
+
+			expect( paragraph.hasAttribute( 'indent' ) ).to.be.true;
+			expect( paragraph.getAttribute( 'indent' ) ).to.equal( '50px' );
+
+			expect( editor.getData() ).to.equal( '<p style="margin-left:50px;">foo</p>' );
+			expect( getViewData( editor.editing.view, { withoutSelection: true } ) )
+				.to.equal( '<p style="margin-left:50px">foo</p>' );
+		} );
+	} );
+
+	function createTestEditor( extraConfig = {} ) {
+		return ClassicTestEditor
+			.create( element, Object.assign( {
+				plugins: [ Paragraph, Indent, IndentBlock ]
+			}, extraConfig ) );
+	}
+} );

+ 15 - 15
packages/ckeditor5-indent/tests/indentblock.js

@@ -3,33 +3,33 @@
  * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
  */
 
-import VirtualTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/virtualtesteditor';
+/* global document */
+
+import ClassicTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/classictesteditor';
 import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
 import { getData as getViewData } from '@ckeditor/ckeditor5-engine/src/dev-utils/view';
 import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
 import HeadingEditing from '@ckeditor/ckeditor5-heading/src/headingediting';
-import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
-import MultiCommand from '@ckeditor/ckeditor5-core/src/multicommand';
+
 import { getCode } from '@ckeditor/ckeditor5-utils/src/keyboard';
+import Indent from '@ckeditor/ckeditor5-core/src/indent';
 
 import IndentBlock from '../src/indentblock';
 import IndentBlockCommand from '../src/indentblockcommand';
 
-class Indent extends Plugin {
-	init() {
-		const editor = this.editor;
-
-		editor.commands.add( 'indent', new MultiCommand( editor ) );
-		editor.commands.add( 'outdent', new MultiCommand( editor ) );
-	}
-}
-
 describe( 'IndentBlock', () => {
-	let editor, model, doc;
+	let editor, element, model, doc;
 
 	testUtils.createSinonSandbox();
 
+	beforeEach( () => {
+		element = document.createElement( 'div' );
+		document.body.appendChild( element );
+	} );
+
 	afterEach( () => {
+		element.remove();
+
 		if ( editor ) {
 			return editor.destroy();
 		}
@@ -257,8 +257,8 @@ describe( 'IndentBlock', () => {
 	} );
 
 	function createTestEditor( extraConfig = {} ) {
-		return VirtualTestEditor
-			.create( Object.assign( {
+		return ClassicTestEditor
+			.create( element, Object.assign( {
 				plugins: [ Paragraph, HeadingEditing, Indent, IndentBlock ]
 			}, extraConfig ) );
 	}