Răsfoiți Sursa

Extract TableCellPropertiesEditing.

Maciej Gołaszewski 6 ani în urmă
părinte
comite
5e7a80fdb3

+ 4 - 98
packages/ckeditor5-table/src/tablecellproperties.js

@@ -8,10 +8,8 @@
  */
 
 import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
-import { downcastToStyle, upcastAttribute, upcastBorderStyles } from './tableproperties/utils';
-import { addBorderRules } from '@ckeditor/ckeditor5-engine/src/view/styles/border';
-import { addPaddingRules } from '@ckeditor/ckeditor5-engine/src/view/styles/padding';
-import { addBackgroundRules } from '@ckeditor/ckeditor5-engine/src/view/styles/background';
+
+import TableCellPropertiesEditing from './tablecellpropertiesediting';
 
 /**
  * The table cell properties feature.
@@ -26,99 +24,7 @@ export default class TableCellProperties extends Plugin {
 		return 'TableCellProperties';
 	}
 
-	/**
-	 * @inheritDoc
-	 */
-	afterInit() {
-		const editor = this.editor;
-		const schema = editor.model.schema;
-		const conversion = editor.conversion;
-		const viewDoc = editor.editing.view.document;
-
-		viewDoc.addStyleProcessorRules( addBorderRules );
-		viewDoc.addStyleProcessorRules( addPaddingRules );
-		viewDoc.addStyleProcessorRules( addBackgroundRules );
-
-		this.enableBorderProperties( schema, conversion );
-		this.enableBackgroundColorProperty( schema, conversion );
-		this.enablePaddingProperty( schema, conversion );
-		this.enableVerticalAlignmentProperty( schema, conversion );
-		this.enableHorizontalAlignmentProperty( schema, conversion );
-	}
-
-	enableBorderProperties( schema, conversion ) {
-		schema.extend( 'tableCell', {
-			allowAttributes: [ 'borderWidth', 'borderColor', 'borderStyle' ]
-		} );
-		upcastBorderStyles( conversion, 'td' );
-		upcastBorderStyles( conversion, 'th' );
-		downcastToStyle( conversion, 'tableCell', 'borderStyle', 'border-style' );
-		downcastToStyle( conversion, 'tableCell', 'borderColor', 'border-color' );
-		downcastToStyle( conversion, 'tableCell', 'borderWidth', 'border-width' );
-	}
-
-	enableBackgroundColorProperty( schema, conversion ) {
-		schema.extend( 'tableCell', {
-			allowAttributes: [ 'backgroundColor' ]
-		} );
-		upcastAttribute( conversion, 'tableCell', 'backgroundColor', 'background-color' );
-		downcastToStyle( conversion, 'tableCell', 'backgroundColor', 'background-color' );
-	}
-
-	enablePaddingProperty( schema, conversion ) {
-		schema.extend( 'tableCell', {
-			allowAttributes: [ 'padding' ]
-		} );
-		upcastAttribute( conversion, 'tableCell', 'padding', 'padding' );
-		downcastToStyle( conversion, 'tableCell', 'padding', 'padding' );
-	}
-
-	enableVerticalAlignmentProperty( schema, conversion ) {
-		schema.extend( 'tableCell', {
-			allowAttributes: [ 'verticalAlignment' ]
-		} );
-		upcastAttribute( conversion, 'tableCell', 'verticalAlignment', 'vertical-align' );
-		downcastToStyle( conversion, 'tableCell', 'verticalAlignment', 'vertical-align' );
-	}
-
-	enableHorizontalAlignmentProperty( schema, conversion ) {
-		schema.extend( 'tableCell', {
-			allowAttributes: [ 'horizontalAlignment' ]
-		} );
-
-		conversion.attributeToAttribute( {
-			model: {
-				name: 'tableCell',
-				key: 'horizontalAlignment',
-				values: [ 'left', 'right', 'center', 'justify' ]
-			},
-			view: {
-				// TODO: controversial one but I don't know if we want "default".
-				left: {
-					key: 'style',
-					value: {
-						'text-align': 'left'
-					}
-				},
-				right: {
-					key: 'style',
-					value: {
-						'text-align': 'right'
-					}
-				},
-				center: {
-					key: 'style',
-					value: {
-						'text-align': 'center'
-					}
-				},
-				justify: {
-					key: 'style',
-					value: {
-						'text-align': 'justify'
-					}
-				}
-			}
-		} );
+	static get requires() {
+		return [ TableCellPropertiesEditing ];
 	}
 }

+ 137 - 0
packages/ckeditor5-table/src/tablecellpropertiesediting.js

@@ -0,0 +1,137 @@
+/**
+ * @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 table/tablecellpropertiesediting
+ */
+
+import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
+import { downcastToStyle, upcastAttribute, upcastBorderStyles } from './tableproperties/utils';
+import { addBorderRules } from '@ckeditor/ckeditor5-engine/src/view/styles/border';
+import { addPaddingRules } from '@ckeditor/ckeditor5-engine/src/view/styles/padding';
+import { addBackgroundRules } from '@ckeditor/ckeditor5-engine/src/view/styles/background';
+
+/**
+ * The table column row properties feature.
+ *
+ * @extends module:core/plugin~Plugin
+ */
+export default class TableCellPropertiesEditing extends Plugin {
+	/**
+	 * @inheritDoc
+	 */
+	static get pluginName() {
+		return 'TableCellPropertiesEditing';
+	}
+
+	/**
+	 * @inheritDoc
+	 */
+	afterInit() {
+		const editor = this.editor;
+		const schema = editor.model.schema;
+		const conversion = editor.conversion;
+
+		const viewDoc = editor.editing.view.document;
+
+		viewDoc.addStyleProcessorRules( addBorderRules );
+		viewDoc.addStyleProcessorRules( addPaddingRules );
+		viewDoc.addStyleProcessorRules( addBackgroundRules );
+
+		schema.extend( 'tableCell', {
+			allowAttributes: [ 'height' ]
+		} );
+		upcastAttribute( conversion, 'tableCell', 'height', 'height' );
+		downcastToStyle( conversion, 'tableCell', 'height', 'height' );
+
+		schema.extend( 'tableCell', {
+			allowAttributes: [ 'width' ]
+		} );
+		upcastAttribute( conversion, 'tableCell', 'width', 'width' );
+		downcastToStyle( conversion, 'tableCell', 'width', 'width' );
+
+		this.enableBorderProperties( schema, conversion );
+		this.enableBackgroundColorProperty( schema, conversion );
+		this.enablePaddingProperty( schema, conversion );
+		this.enableVerticalAlignmentProperty( schema, conversion );
+		this.enableHorizontalAlignmentProperty( schema, conversion );
+	}
+
+	enableBorderProperties( schema, conversion ) {
+		schema.extend( 'tableCell', {
+			allowAttributes: [ 'borderWidth', 'borderColor', 'borderStyle' ]
+		} );
+		upcastBorderStyles( conversion, 'td' );
+		upcastBorderStyles( conversion, 'th' );
+		downcastToStyle( conversion, 'tableCell', 'borderStyle', 'border-style' );
+		downcastToStyle( conversion, 'tableCell', 'borderColor', 'border-color' );
+		downcastToStyle( conversion, 'tableCell', 'borderWidth', 'border-width' );
+	}
+
+	enableBackgroundColorProperty( schema, conversion ) {
+		schema.extend( 'tableCell', {
+			allowAttributes: [ 'backgroundColor' ]
+		} );
+		upcastAttribute( conversion, 'tableCell', 'backgroundColor', 'background-color' );
+		downcastToStyle( conversion, 'tableCell', 'backgroundColor', 'background-color' );
+	}
+
+	enablePaddingProperty( schema, conversion ) {
+		schema.extend( 'tableCell', {
+			allowAttributes: [ 'padding' ]
+		} );
+		upcastAttribute( conversion, 'tableCell', 'padding', 'padding' );
+		downcastToStyle( conversion, 'tableCell', 'padding', 'padding' );
+	}
+
+	enableVerticalAlignmentProperty( schema, conversion ) {
+		schema.extend( 'tableCell', {
+			allowAttributes: [ 'verticalAlignment' ]
+		} );
+		upcastAttribute( conversion, 'tableCell', 'verticalAlignment', 'vertical-align' );
+		downcastToStyle( conversion, 'tableCell', 'verticalAlignment', 'vertical-align' );
+	}
+
+	enableHorizontalAlignmentProperty( schema, conversion ) {
+		schema.extend( 'tableCell', {
+			allowAttributes: [ 'horizontalAlignment' ]
+		} );
+
+		conversion.attributeToAttribute( {
+			model: {
+				name: 'tableCell',
+				key: 'horizontalAlignment',
+				values: [ 'left', 'right', 'center', 'justify' ]
+			},
+			view: {
+				// TODO: controversial one but I don't know if we want "default".
+				left: {
+					key: 'style',
+					value: {
+						'text-align': 'left'
+					}
+				},
+				right: {
+					key: 'style',
+					value: {
+						'text-align': 'right'
+					}
+				},
+				center: {
+					key: 'style',
+					value: {
+						'text-align': 'center'
+					}
+				},
+				justify: {
+					key: 'style',
+					value: {
+						'text-align': 'justify'
+					}
+				}
+			}
+		} );
+	}
+}

+ 0 - 46
packages/ckeditor5-table/src/tablecolumnrowproperties.js

@@ -1,46 +0,0 @@
-/**
- * @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 table/tablecolumnrowproperties
- */
-
-import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
-import { downcastToStyle, upcastAttribute } from './tableproperties/utils';
-
-/**
- * The table column row properties feature.
- *
- * @extends module:core/plugin~Plugin
- */
-export default class TableColumnRowProperties extends Plugin {
-	/**
-	 * @inheritDoc
-	 */
-	static get pluginName() {
-		return 'TableColumnRowProperties';
-	}
-
-	/**
-	 * @inheritDoc
-	 */
-	afterInit() {
-		const editor = this.editor;
-		const schema = editor.model.schema;
-		const conversion = editor.conversion;
-
-		schema.extend( 'tableCell', {
-			allowAttributes: [ 'height' ]
-		} );
-		upcastAttribute( conversion, 'tableCell', 'height', 'height' );
-		downcastToStyle( conversion, 'tableCell', 'height', 'height' );
-
-		schema.extend( 'tableCell', {
-			allowAttributes: [ 'width' ]
-		} );
-		upcastAttribute( conversion, 'tableCell', 'width', 'width' );
-		downcastToStyle( conversion, 'tableCell', 'width', 'width' );
-	}
-}

+ 1 - 2
packages/ckeditor5-table/tests/manual/tableproperties.js

@@ -13,7 +13,6 @@ import Indent from '@ckeditor/ckeditor5-indent/src/indent';
 
 import TableProperties from '../../src/tableproperties';
 import TableCellProperties from '../../src/tablecellproperties';
-import TableColumnRowProperties from '../../src/tablecolumnrowproperties';
 
 const sourceElement = document.querySelector( '#editor' );
 const clonedSource = sourceElement.cloneNode( true );
@@ -22,7 +21,7 @@ document.querySelector( '#cloned-source' ).append( ...clonedSource.childNodes );
 
 ClassicEditor
 	.create( sourceElement, {
-		plugins: [ ArticlePluginSet, Alignment, Indent, IndentBlock, TableProperties, TableColumnRowProperties, TableCellProperties ],
+		plugins: [ ArticlePluginSet, Alignment, Indent, IndentBlock, TableProperties, TableCellProperties ],
 		toolbar: [
 			'heading', '|', 'insertTable', '|', 'bold', 'italic', 'bulletedList', 'numberedList', 'blockQuote', 'undo', 'redo'
 		],

+ 4 - 4
packages/ckeditor5-table/tests/tablecolumnrowproperties.js → packages/ckeditor5-table/tests/tablecellpropertiesediting.js

@@ -7,18 +7,18 @@ import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
 import VirtualTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/virtualtesteditor';
 
 import TableEditing from '../src/tableediting';
-import TableColumnRowProperties from '../src/tablecolumnrowproperties';
+import TableCellPropertiesEditing from '../src/tablecellpropertiesediting';
 
 import { setData as setModelData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
 import { assertEqualMarkup } from '@ckeditor/ckeditor5-utils/tests/_utils/utils';
 
-describe( 'TableColumnRowProperties', () => {
+describe( 'TableCellPropertiesEditing', () => {
 	let editor, model;
 
 	beforeEach( () => {
 		return VirtualTestEditor
 			.create( {
-				plugins: [ TableColumnRowProperties, Paragraph, TableEditing ]
+				plugins: [ TableCellPropertiesEditing, Paragraph, TableEditing ]
 			} )
 			.then( newEditor => {
 				editor = newEditor;
@@ -32,7 +32,7 @@ describe( 'TableColumnRowProperties', () => {
 	} );
 
 	it( 'should have pluginName', () => {
-		expect( TableColumnRowProperties.pluginName ).to.equal( 'TableColumnRowProperties' );
+		expect( TableCellPropertiesEditing.pluginName ).to.equal( 'TableCellPropertiesEditing' );
 	} );
 
 	describe( 'column width', () => {