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

Internal: Removing leftovers after multiple resizing strategies.

Marek Lewandowski 6 лет назад
Родитель
Сommit
2ece8dc111

+ 0 - 96
packages/ckeditor5-widget/src/resizercentral.js

@@ -1,96 +0,0 @@
-import {
-	getAbsoluteBoundaryPoint
-} from './utils';
-
-import ObservableMixin from '@ckeditor/ckeditor5-utils/src/observablemixin';
-import mix from '@ckeditor/ckeditor5-utils/src/mix';
-import global from '@ckeditor/ckeditor5-utils/src/dom/global';
-
-/**
- * Implements a resizer that enlarges/shrinks in all directions.
- *
- * @class ResizerCentral
- */
-export default class ResizerCentral {
-	constructor( context, options ) {
-		this.context = context;
-		this.options = options || {};
-	}
-
-	attach() {}
-
-	begin() {
-		const resizeHost = this.context._getResizeHost();
-		this.closestReferencePoint = getAbsoluteBoundaryPoint( resizeHost, this.context.referenceHandlerPosition );
-	}
-
-	commit() {}
-
-	cancel() {}
-
-	destroy() {}
-
-	updateSize( domEventData ) {
-		const context = this.context;
-		const currentCoordinates = context._extractCoordinates( domEventData );
-
-		const enlargement = {
-			x: ( currentCoordinates.x - this.closestReferencePoint.x ) * 2,
-			y: ( currentCoordinates.y - this.closestReferencePoint.y ) * 2
-		};
-
-		const originalSize = this.context.originalSize;
-
-		const proposedSize = {
-			x: Math.abs( this.closestReferencePoint.x - context.referenceCoordinates.x + enlargement.x ),
-			y: Math.abs( this.closestReferencePoint.y - context.referenceCoordinates.y + enlargement.y )
-		};
-
-		// Dominant determination must take the ratio into account.
-		proposedSize.dominant = proposedSize.x / context.aspectRatio > proposedSize.y ? 'x' : 'y';
-		proposedSize.max = proposedSize[ proposedSize.dominant ];
-
-		const drawnSize = {
-			x: proposedSize.x,
-			y: proposedSize.y
-		};
-
-		if ( proposedSize.dominant == 'x' ) {
-			drawnSize.y = drawnSize.x / context.aspectRatio;
-		} else {
-			drawnSize.x = drawnSize.y * context.aspectRatio;
-		}
-
-		// Reset shadow bounding.
-		context.domResizeShadow.style.top = 'auto';
-		context.domResizeShadow.style.left = 'auto';
-		context.domResizeShadow.style.bottom = 'auto';
-		context.domResizeShadow.style.right = 'auto';
-
-		const invertedPosition = this.context._invertPosition( context.referenceHandlerPosition );
-
-		const resizeUsingImage = global.window.pocResizeUsingImage !== false;
-
-		if ( !resizeUsingImage ) {
-			context.domResizeShadow.style[ invertedPosition.split( '-' )[ 0 ] ] = `${ ( originalSize.y - drawnSize.y ) / 2 }px`;
-			context.domResizeShadow.style[ invertedPosition.split( '-' )[ 1 ] ] = `${ ( originalSize.x - drawnSize.x ) / 2 }px`;
-		} else {
-			const resizingHost = this.context._getResizeHost();
-
-			resizingHost.style.width = `${ drawnSize.x }px`;
-			resizingHost.style.height = `${ drawnSize.y }px`;
-		}
-
-		// Apply the actual shadow dimensions.
-		context.domResizeShadow.style.width = `${ drawnSize.x }px`;
-		context.domResizeShadow.style.height = `${ drawnSize.y }px`;
-
-		return drawnSize; // @todo decide what size should actually be returned, drawn or intended.
-	}
-
-	redraw() {}
-
-	_getResizeHost() {}
-}
-
-mix( ResizerCentral, ObservableMixin );

+ 0 - 74
packages/ckeditor5-widget/src/resizerside.js

@@ -1,74 +0,0 @@
-import ObservableMixin from '@ckeditor/ckeditor5-utils/src/observablemixin';
-import mix from '@ckeditor/ckeditor5-utils/src/mix';
-
-/**
- * @module widget/resizecontext
- */
-
-/**
- * Implements a resizer that enlarges to the dragged side.
- *
- * @class ResizerSide
- */
-export default class ResizerSide {
-	constructor( context, options ) {
-		this.context = context;
-		this.options = options || {};
-	}
-
-	attach() {}
-
-	begin() {}
-
-	commit() {}
-
-	cancel() {}
-
-	destroy() {}
-
-	updateSize( domEventData ) {
-		const context = this.context;
-		const currentCoordinates = context._extractCoordinates( domEventData );
-
-		const proposedSize = {
-			x: Math.abs( currentCoordinates.x - context.referenceCoordinates.x ),
-			y: Math.abs( currentCoordinates.y - context.referenceCoordinates.y )
-		};
-
-		// Dominant determination must take the ratio into account.
-		proposedSize.dominant = proposedSize.x / context.aspectRatio > proposedSize.y ? 'x' : 'y';
-		proposedSize.max = proposedSize[ proposedSize.dominant ];
-
-		const drawnSize = {
-			x: proposedSize.x,
-			y: proposedSize.y
-		};
-
-		if ( proposedSize.dominant == 'x' ) {
-			drawnSize.y = drawnSize.x / context.aspectRatio;
-		} else {
-			drawnSize.x = drawnSize.y * context.aspectRatio;
-		}
-
-		// Reset shadow bounding.
-		context.domResizeShadow.style.top = 0;
-		context.domResizeShadow.style.left = 0;
-		context.domResizeShadow.style.bottom = 0;
-		context.domResizeShadow.style.right = 0;
-
-		context.domResizeShadow.style[ context.referenceHandlerPosition.split( '-' )[ 0 ] ] = 'auto';
-		context.domResizeShadow.style[ context.referenceHandlerPosition.split( '-' )[ 1 ] ] = 'auto';
-
-		// Apply the actual shadow dimensions.
-		context.domResizeShadow.style.width = `${ drawnSize.x }px`;
-		context.domResizeShadow.style.height = `${ drawnSize.y }px`;
-
-		return drawnSize; // @todo decide what size should actually be returned.
-	}
-
-	redraw() {}
-
-	_getResizeHost() {}
-}
-
-mix( ResizerSide, ObservableMixin );

+ 3 - 3
packages/ckeditor5-widget/src/resizertopbound.js

@@ -18,9 +18,9 @@ import global from '@ckeditor/ckeditor5-utils/src/dom/global';
 /**
  * Implements a resizer that enlarges/shrinks in all directions.
  *
- * @class ResizerCentral
+ * @class ResizerTopBound
  */
-export default class ResizerCentral {
+export default class ResizerTopBound {
 	constructor( context, options ) {
 		this.context = context;
 		this.options = options || {};
@@ -152,4 +152,4 @@ export default class ResizerCentral {
 	redraw() {}
 }
 
-mix( ResizerCentral, ObservableMixin );
+mix( ResizerTopBound, ObservableMixin );

+ 0 - 10
packages/ckeditor5-widget/src/utils.js

@@ -108,10 +108,6 @@ export function toWidget( element, writer, options = {} ) {
 		addSelectionHandler( element, writer );
 	}
 
-	if ( options.features ) {
-		addWidgetFeatures( element, writer, options.features );
-	}
-
 	setHighlightHandling(
 		element,
 		writer,
@@ -406,9 +402,3 @@ function addSelectionHandler( widgetElement, writer ) {
 	writer.insert( writer.createPositionAt( widgetElement, 0 ), selectionHandler );
 	writer.addClass( [ 'ck-widget_with-selection-handler' ], widgetElement );
 }
-
-function addWidgetFeatures( element, writer, features ) {
-	for ( const currentFeature of features ) {
-		currentFeature.apply( element, writer );
-	}
-}

+ 3 - 46
packages/ckeditor5-widget/src/widgetresizer.js

@@ -9,7 +9,7 @@
 
 import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
 import getAncestors from '@ckeditor/ckeditor5-utils/src/dom/getancestors';
-import ResizeContext2 from './resizecontext';
+import ResizeContext from './resizecontext';
 import ResizerTopBound from './resizertopbound';
 import DomEmitterMixin from '@ckeditor/ckeditor5-utils/src/dom/emittermixin';
 import global from '@ckeditor/ckeditor5-utils/src/dom/global';
@@ -54,7 +54,6 @@ export default class WidgetResizer extends Plugin {
 		this.activeContext = null;
 
 		this._registerSchema();
-		this._registerConverters();
 
 		const mouseObserverHost = global.window.document;
 
@@ -169,7 +168,7 @@ export default class WidgetResizer extends Plugin {
 	 * @param {module:widget/widgetresizer~ResizerOptions} [options] Resizer options.
 	 */
 	apply( widgetElement, writer, options ) {
-		const context = new ResizeContext2( options );
+		const context = new ResizeContext( options );
 		context.attach( widgetElement, writer );
 
 		this.editor.editing.view.once( 'render', () => context.redraw() );
@@ -196,50 +195,8 @@ export default class WidgetResizer extends Plugin {
 	}
 
 	_registerSchema() {
-		const editor = this.editor;
-
-		editor.model.schema.extend( 'image', {
-			allowAttributes: WIDTH_ATTRIBUTE_NAME
-		} );
-
-		editor.model.schema.setAttributeProperties( WIDTH_ATTRIBUTE_NAME, {
+		this.editor.model.schema.setAttributeProperties( WIDTH_ATTRIBUTE_NAME, {
 			isFormatting: true
 		} );
 	}
-
-	_registerConverters() {
-		const editor = this.editor;
-
-		// Dedicated converter to propagate image's attribute to the img tag.
-		editor.conversion.for( 'downcast' ).add( dispatcher =>
-			dispatcher.on( 'attribute:width:image', ( evt, data, conversionApi ) => {
-				if ( !conversionApi.consumable.consume( data.item, evt.name ) ) {
-					return;
-				}
-
-				const viewWriter = conversionApi.writer;
-				const img = conversionApi.mapper.toViewElement( data.item ).getChild( 0 );
-
-				if ( data.attributeNewValue !== null ) {
-					viewWriter.setStyle( WIDTH_ATTRIBUTE_NAME, data.attributeNewValue + 'px', img );
-				} else {
-					viewWriter.removeStyle( WIDTH_ATTRIBUTE_NAME, img );
-				}
-			} )
-		);
-
-		editor.conversion.for( 'upcast' )
-			.attributeToAttribute( {
-				view: {
-					name: 'img',
-					styles: {
-						'width': /[\d.]+(px)?/
-					}
-				},
-				model: {
-					key: WIDTH_ATTRIBUTE_NAME,
-					value: viewElement => viewElement.getStyle( 'width' ).replace( 'px', '' )
-				}
-			} );
-	}
 }